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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@moora/toolkit

v0.1.2

Published

A functional toolkit system for managing tool definitions and invocations

Downloads

230

Readme

@moora/toolkit

函数式 Toolkit 系统,用于管理工具定义和调用。

安装

bun add @moora/toolkit

核心概念

ToolDefinition

工具定义包含以下属性:

  • name: 工具名称(必须唯一)
  • description: 工具描述
  • parameterSchema: 参数的 JSON Schema
  • execute: 执行函数 (parameters: string) => Promise<string>

Toolkit

Toolkit 接口提供以下能力:

  • getToolNames(): 获取所有工具名称列表
  • getToolInfo(name): 根据名称获取工具详情
  • getAllToolInfos(): 获取所有工具的详情列表
  • invoke(name, parameters): 调用工具
  • hasTool(name): 检查工具是否存在

使用示例

创建 Toolkit

import { createToolkit, type ToolDefinition } from '@moora/toolkit';

const tools: ToolDefinition[] = [
  {
    name: 'add',
    description: 'Add two numbers',
    parameterSchema: {
      type: 'object',
      properties: {
        a: { type: 'number' },
        b: { type: 'number' },
      },
      required: ['a', 'b'],
    },
    execute: async (params) => {
      const { a, b } = JSON.parse(params);
      return JSON.stringify({ result: a + b });
    },
  },
  {
    name: 'multiply',
    description: 'Multiply two numbers',
    parameterSchema: {
      type: 'object',
      properties: {
        a: { type: 'number' },
        b: { type: 'number' },
      },
      required: ['a', 'b'],
    },
    execute: async (params) => {
      const { a, b } = JSON.parse(params);
      return JSON.stringify({ result: a * b });
    },
  },
];

const mathToolkit = createToolkit(tools);

调用工具

// 获取工具列表
console.log(mathToolkit.getToolNames()); // ['add', 'multiply']

// 获取工具详情
const addInfo = mathToolkit.getToolInfo('add');
console.log(addInfo);
// {
//   name: 'add',
//   description: 'Add two numbers',
//   parameterSchema: { ... }
// }

// 调用工具
const result = await mathToolkit.invoke('add', '{"a": 1, "b": 2}');
console.log(result); // '{"result":3}'

合并多个 Toolkit

import { createToolkit, mergeToolkits } from '@moora/toolkit';

const mathToolkit = createToolkit([/* math tools */]);
const stringToolkit = createToolkit([/* string tools */]);

const combinedToolkit = mergeToolkits([mathToolkit, stringToolkit]);

创建受限 Toolkit

import { createToolkit, restrictToolkit } from '@moora/toolkit';

const fullToolkit = createToolkit([/* all tools */]);

// 黑名单模式:排除指定工具
const safeToolkit = restrictToolkit(fullToolkit, {
  blacklist: ['deleteFile', 'executeCommand'],
});

// 白名单模式:只保留指定工具
const limitedToolkit = restrictToolkit(fullToolkit, {
  whitelist: ['read', 'search'],
});

创建空 Toolkit

import { emptyToolkit } from '@moora/toolkit';

const empty = emptyToolkit();
console.log(empty.getToolNames()); // []

API 参考

createToolkit(tools: ToolDefinition[]): Toolkit

从工具定义列表创建 Toolkit。

mergeToolkits(toolkits: Toolkit[]): Toolkit

合并多个 Toolkit 成为一个功能更全的 Toolkit。

restrictToolkit(toolkit: Toolkit, options: FilterOptions): Toolkit

创建受限的 Toolkit,支持黑名单或白名单模式。

emptyToolkit(): Toolkit

创建一个空的 Toolkit。

类型导出

import type {
  ToolDefinition,
  ToolExecuteFn,
  ToolInfo,
  Toolkit,
  BlacklistOptions,
  WhitelistOptions,
  FilterOptions,
} from '@moora/toolkit';

License

MIT