npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@draftor/tools

v1.0.13

Published

A simple TypeScript/Javascript functions to openai tool call format

Readme

@draftor/tools

A simple TypeScript npm package designed to transform your function comments into an OpenAI Tool calling format. It's an alternative to zod and z. Built to maintain functions used for tool calling in a separate file, this package allows you to generate OpenAI Tool Calling JSON format without writing extensive code or using .describe().

⚠️ Caution: Check your Linter and Prettier config before add this package!

This approach deviates from typical TypeScript patterns. The comment must reside within the function, not outside. For example:

DO ✅ 
export function foo(bar:string) {
  /**
   * @description Converts a number to its string representation.
   * @param {boolean} bar - The bool to convert.
   * @param {number} abc - The number to convert.
   * @param {string} xyz - The string to convert.
   * @param {undefined} mpn - The any to convert.
   * @returns {object} The Object as response.
   */
  return bar.toString();
}

DON'T ❌
/**
 * @description Converts a number to its string representation.
 * @param {boolean} bar - The number to convert.
 * @param {number} abc - The number to convert.
 * @param {string} xyz - The number to convert.
 * @param {undefined} mpn - The number to convert.
 * @returns {object} The string representation of the input number.
 */
export function foo(bar: string) {
  return bar.toString();
}

Installation

To install the package, use npm:

npm install @draftor/tools

Usage

1. Converting Functions to OpenAI Format

Here's a basic example of how to use the Tools class:

Your tool/functions for tool calling

# yourFunctions.ts

export function foo(bar:string) {
  /**
   * @description Converts a number to its string representation.
   * @param {boolean} bar - The number to convert.
   * @param {number} abc - The number to convert.
   * @param {string} xyz - The number to convert.
   * @param {undefined} mpn - The number to convert.
   * @returns {object} The string representation of the input number.
   */
  return bar.toString();
}

import { Tools } from '@draftor/tools';
import { foo } from './yourFunctions';

const tools = new Tools(funcs);
const result = tools.toOpenAI(); // --> for object response
// const result = tools.toOpenAI('string'); -->  for string response

console.log(result); //will print in json string as output
{
  "name": "foo",
  "description": "No description provided.",
  "params": {
    "type": "object",
    "properties": {
      "bar": {
        "type": "boolean",
        "description": "The number to convert."
      },
      "abc": {
        "type": "number",
        "description": "The number to convert."
      },
      "xyz": {
        "type": "string",
        "description": "The number to convert."
      },
      "mpn": {
        "type": "any",
        "description": "The number to convert."
      }
    },
    "required": [
      "bar",
      "abc",
      "xyz",
      "mpn"
    ]
  },
  "returns": {
    "type": "object",
    "description": "The string representation of the input number."
  }
}

2. Executing LLM ToolCalls from response

// Response Format

export interface IToolCall {
  index: number,
  id: string;
  type: 'function';
  function: IFunctionCall;
}

export interface IFunctionCall {
  name: string;
  arguments: string;
}

How to execute the tool calls

const response = await LLM.chat({msg, tools}) // mock api. Use an endpoint of your choice

const toolsFromLLM = getToolsFromResponse(response) as IToolCall; // Implement response.data.choices[0].message.content logic with or without stream and extract tools object.

/**
 * You can either use the ToolCall response directly by looping over the tools and executing them.
 * ---===  OR  ===---
 * Implement the logic yourself, convert the tools to functions and arguments, and pass them to this function for execution.
 * However, if you've already implemented this much, it's pretty unnecessary to use the .exec() function!
 */

const funResp = tool.exec(toolsFromLLM); // If there is code in the args response, be sure to have an escape logic, but Ideally shoould work.
 
 OR
const funResp = tool.exec('foo', { bar: 'Waba laba dub dub!' });

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue.

License

This project is licensed under the MIT License.

Author

https://x.com/p_naix

Built with ❤️ by Team Draftor.ai

Twitter : https://twitter.com/draftor_ai

Acknowledgments