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

@omni-api/core

v0.0.2

Published

OmniAPI core: Procedure / Registry / Middleware / Context / Errors

Readme

@omni/core

OmniAPI 的核心包:定义 Procedure / 组合 Middleware / 注册到 Registry / 通过 runProcedure 执行。

本包不绑定任何具体协议(HTTP / MCP),所有出口由独立的 Adapter 包负责。

安装

pnpm add @omni/core zod

5 分钟速览

import { z } from 'zod';
import {
  defineProcedure,
  createRouter,
  Registry,
  runByName,
  createContext,
} from '@omni/core';

// 1. 定义一个 Procedure
const createOrder = defineProcedure({
  name: 'order.create',
  description: '创建一笔订单',
  input: z.object({ sku: z.string(), qty: z.number().int().positive() }),
  output: z.object({ orderId: z.string() }),
  meta: {
    http: { method: 'POST', path: '/orders' },
    mcp: { category: 'commerce', requireConfirmation: true },
  },
  handler: async ({ input }) => ({ orderId: `O_${input.sku}` }),
});

// 2. 注册到 Registry
const registry = new Registry();
registry.registerRouter(
  createRouter({
    namespace: 'order',
    procedures: [createOrder],
  }),
);

// 3. 调用(任何 Adapter 内部都是这么调的)
const result = await runByName(
  registry,
  'order.create',
  { sku: 'X1', qty: 1 },
  createContext({ source: 'test' }),
);
console.log(result); // { orderId: 'O_X1' }

导出 LLM 工具 JSON(逃生出口)

给不支持 MCP 的老 Agent 平台用:

import { exportToolsJSON } from '@omni/core/utils';

const openaiTools = exportToolsJSON(registry, { format: 'openai' });
const claudeTools = exportToolsJSON(registry, { format: 'anthropic' });

API

核心

  • defineProcedure(def) - 定义一个 Procedure
  • createRouter(def) - 把多个 Procedure 组合 + 共享中间件
  • Registry - 全局注册中心
  • runProcedure(proc, input, ctx, options?) - 直接执行
  • runByName(registry, name, input, ctx, options?) - 通过 Registry 执行

工具

  • compose(middlewares) - 组合中间件链
  • createContext(partial) - 创建 Context(测试 / Adapter 用)
  • getNamespace(p) - 取 procedure 的 namespace

错误

  • OmniError 及子类:ValidationError / UnauthorizedError / ForbiddenError / NotFoundError / ConflictError / RateLimitError / InternalError
  • toOmniError(err) - 把任意错误规范化为 OmniError

@omni/core/utils

  • zodToJsonSchema(schema) - Zod → JSON Schema
  • exportToolsJSON(registry, opts) - 导出 LLM 工具数组(OpenAI / Anthropic / Generic)

设计文档

详见根目录 docs/