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

@cnbcool/cnb-api-generate

v2.21.3

Published

基于 `swagger2.0` 生成 TypeScript 代码与 Agent Skill 的工具。

Readme

cnb-api-generate

基于 swagger2.0 生成 TypeScript 代码与 Agent Skill 的工具。

  • cag:生成基于 @cnb/request 和 @reduxjs/toolkit 的 TypeScript 代码,Interface / Enum 与 swagger.json 强绑定。
  • csg:基于 swagger 生成 Agent Skill(SKILL.md + CLI)。

为什么需要

前后端各维护一套接口定义时,后端 swagger.json 变更无法触达前端:编译能过,运行时才报错;Interface / Enum 靠手写,容易写错或重复定义。

使用本工具后,Interface / Enum 与请求函数全部由 swagger.json 生成,swagger.json 一变重新生成即可在编译期发现类型错误,同时自动生成 jsDoc 注释。

安装

npm install @cnbcool/cnb-api-generate -D
# or
yarn add @cnbcool/cnb-api-generate -D

必须搭配 @cnb/request 使用。

快速使用

在运行 cag 的目录下创建 cag.config.js:

module.exports = {
  target: '<swagger.json 文件地址>',
}
npx cag
# or
yarn cag

cag.config.js

target

swagger.json 的文件位置,相对 cag.config.js。

outputDir

生成代码的输出目录,相对 cag.config.js。

printeReduxAction

是否输出 Redux Action 代码,默认 true。

requestDependencyMap

自定义请求模块中依赖的函数与 TypeScript 定义。

[key in string]: {
  path: string;
  isDefault: boolean;
}

基于 @cnb/request 已内置,无需配置。

生成 SKILL

文件配置

module.exports = {
  target: './template/swagger.json',
  skillsOutputDir: `./`,
}

执行命令

npx csg

生成目录结构:

| SKILL.md
| scripts/
| - core/
| - modules/

环境变量依赖

  • CNB_API_ENDPOINT:可选,自定义 API 地址(默认 https://api.cnb.cool)
  • CNB_TOKEN:OpenAPI 令牌
  • CNB_WEB_ENDPOINT:与 CNB_API_ENDPOINT 对应的根域名(默认 https://cnb.cool)

skills list 命令

生成的 Skill 内置 cnb skills list,用于列出本地 skills:

cnb skills list -p -a codebuddy --json

| 参数 | 说明 | | --- | --- | | --json | 以 JSON 输出 | | -p | 查询项目(仓库)级 skills | | -a codebuddy | 按 agent 过滤(此处为当前 NPC 的 agent 名) |