{"_id":"@baishuyun/coze-sdk","_rev":"3-28ae2d213326c1470d64e1e562d50a03","name":"@baishuyun/coze-sdk","dist-tags":{"alpha":"0.0.1-alpha.0","latest":"0.0.1-alpha.2"},"versions":{"0.0.1-alpha.0":{"name":"@baishuyun/coze-sdk","version":"0.0.1-alpha.0","keywords":["coze","sdk","baishu","apaas"],"author":"","license":"ISC","_id":"@baishuyun/coze-sdk@0.0.1-alpha.0","maintainers":[{"name":"baishuyun.com","email":"2559215848@qq.com"}],"dist":{"shasum":"fd5f5836870a3ccc3fbefe975f244b3d11f6420c","tarball":"https://registry.npmjs.org/@baishuyun/coze-sdk/-/coze-sdk-0.0.1-alpha.0.tgz","fileCount":170,"integrity":"sha512-Tvv7VEP7qjgvGuXT52w2yy0Rp3rcQSXbm/4dqxQD0xIz7Du9NH36Ob2kI2g8K439MKix+GYo5OmxniD8+dotJw==","signatures":[{"sig":"MEUCIQCIlRSA4ULQAjdLiCSZJrQXvCMUOU62UWeX01SQSrIVRgIgO5iUayZ9MdM3DaZwSaF7zCiO+wBtHdqdwh4mi+QXXQE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1925359},"main":"dist/index.js","type":"module","_from":"file:baishuyun-coze-sdk-0.0.1-alpha.0.tgz","types":"dist/index.d.ts","module":"dist/index.js","engines":{"node":">=22"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./package.json":"./package.json"},"scripts":{"dev":"vite build --watch","build":"vite build","clean":"rimraf dist *.tsbuildinfo","generate":"node scripts/generate.mjs","type-check":"tsc --noEmit"},"_npmUser":{"name":"baishuyun.com","email":"2559215848@qq.com"},"_resolved":"/tmp/f9802edb994b702e3a13b552fa4534eb/baishuyun-coze-sdk-0.0.1-alpha.0.tgz","_integrity":"sha512-Tvv7VEP7qjgvGuXT52w2yy0Rp3rcQSXbm/4dqxQD0xIz7Du9NH36Ob2kI2g8K439MKix+GYo5OmxniD8+dotJw==","_npmVersion":"10.9.8","description":"Production-grade typed SDK for the Baishu Coze (APAAS) API, generated from the coze-studio thrift IDL.","directories":{},"_nodeVersion":"22.23.2","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"vite":"^5.1.4","rimraf":"^6.1.2","typescript":"^5.8.3","@types/node":"^22.15.0","vite-plugin-dts":"^4.5.4","@baishuyun/typescript-config":"2.0.9"},"_npmOperationalInternal":{"tmp":"tmp/coze-sdk_0.0.1-alpha.0_1787393407455_0.3989903135907267","host":"s3://npm-registry-packages-npm-production"}},"0.0.1-alpha.1":{"name":"@baishuyun/coze-sdk","version":"0.0.1-alpha.1","keywords":["coze","sdk","baishu","apaas"],"author":"","license":"ISC","_id":"@baishuyun/coze-sdk@0.0.1-alpha.1","maintainers":[{"name":"baishuyun.com","email":"2559215848@qq.com"}],"dist":{"shasum":"339f9ca8e0f071ad19bc283d7cbd9e85fb75db42","tarball":"https://registry.npmjs.org/@baishuyun/coze-sdk/-/coze-sdk-0.0.1-alpha.1.tgz","fileCount":172,"integrity":"sha512-2uDhhW5aI8v4TaypfXwcG/x53JEzHV3/W2N56RDX8Huv5hYDvwXEe3UHJGM9PEXevQFeMHQXUaao3433fRKNog==","signatures":[{"sig":"MEUCIFcxc5qjJFvL1Lp6LK2nHwu9gGD5Z7tPcfex/bxQ6pp8AiEAwzgjHaER/mqbyWAxmUO8H2gNZoeWKF6OQSzLVCmLh4M=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":2987411},"main":"dist/index.js","type":"module","_from":"file:baishuyun-coze-sdk-0.0.1-alpha.1.tgz","types":"dist/index.d.ts","module":"dist/index.js","engines":{"node":">=22"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./package.json":"./package.json"},"scripts":{"dev":"vite build --watch","build":"vite build","clean":"rimraf dist *.tsbuildinfo","generate":"node scripts/generate.mjs","type-check":"tsc --noEmit"},"_npmUser":{"name":"baishuyun.com","email":"2559215848@qq.com"},"_resolved":"/tmp/019157633d3cfc4249c768072aa26b73/baishuyun-coze-sdk-0.0.1-alpha.1.tgz","_integrity":"sha512-2uDhhW5aI8v4TaypfXwcG/x53JEzHV3/W2N56RDX8Huv5hYDvwXEe3UHJGM9PEXevQFeMHQXUaao3433fRKNog==","_npmVersion":"10.9.8","description":"Production-grade typed SDK for the Baishu Coze (APAAS) API, generated from the coze-studio thrift IDL.","directories":{},"_nodeVersion":"22.23.2","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"vite":"^5.1.4","rimraf":"^6.1.2","typescript":"^5.8.3","@types/node":"^22.15.0","vite-plugin-dts":"^4.5.4","@baishuyun/typescript-config":"2.0.9"},"_npmOperationalInternal":{"tmp":"tmp/coze-sdk_0.0.1-alpha.1_1787393963231_0.7855373955177565","host":"s3://npm-registry-packages-npm-production"}},"0.0.1-alpha.2":{"name":"@baishuyun/coze-sdk","version":"0.0.1-alpha.2","description":"Production-grade typed SDK for the Baishu Coze (APAAS) API, generated from the coze-studio thrift IDL.","type":"module","main":"dist/index.js","module":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=22"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./package.json":"./package.json"},"devDependencies":{"@types/node":"^22.15.0","rimraf":"^6.1.2","typescript":"^5.8.3","vite":"^5.1.4","vite-plugin-dts":"^4.5.4","@baishuyun/typescript-config":"2.0.9"},"publishConfig":{"access":"public"},"keywords":["coze","sdk","baishu","apaas"],"author":"","license":"ISC","scripts":{"build":"vite build","dev":"vite build --watch","clean":"rimraf dist *.tsbuildinfo","type-check":"tsc --noEmit","generate":"node scripts/generate.mjs"},"_id":"@baishuyun/coze-sdk@0.0.1-alpha.2","_integrity":"sha512-upn51Jkd+b9r7ZIK6K3YXDcfa1P4/oa/eb6y0E4DcZyPXAmp/9MlAoIYZ12yO+OznaJ2oIDy9uZuoL8jpKXllw==","_resolved":"/tmp/96247991e4c49c69fb89a8497ac10abd/baishuyun-coze-sdk-0.0.1-alpha.2.tgz","_from":"file:baishuyun-coze-sdk-0.0.1-alpha.2.tgz","_nodeVersion":"22.23.2","_npmVersion":"10.9.8","dist":{"integrity":"sha512-upn51Jkd+b9r7ZIK6K3YXDcfa1P4/oa/eb6y0E4DcZyPXAmp/9MlAoIYZ12yO+OznaJ2oIDy9uZuoL8jpKXllw==","shasum":"9101ce831e81ef3db1bb5df2f06abd3c41144992","tarball":"https://registry.npmjs.org/@baishuyun/coze-sdk/-/coze-sdk-0.0.1-alpha.2.tgz","fileCount":172,"unpackedSize":2987411,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCRY4fabtrbNd1AMzUAoSI606vTgt9AzB4//o554H2fCwIgIDsBvySdLOJK76We1p+FyJGHeDRsVCnghrGAZFv1Nvc="}]},"_npmUser":{"name":"baishuyun.com","email":"2559215848@qq.com"},"directories":{},"maintainers":[{"name":"baishuyun.com","email":"2559215848@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/coze-sdk_0.0.1-alpha.2_1787636760230_0.5443485833839501"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-22T10:10:07.234Z","modified":"2026-08-25T05:46:00.553Z","0.0.1-alpha.0":"2026-08-22T10:10:07.621Z","0.0.1-alpha.1":"2026-08-22T10:19:23.375Z","0.0.1-alpha.2":"2026-08-25T05:46:00.387Z"},"license":"ISC","keywords":["coze","sdk","baishu","apaas"],"description":"Production-grade typed SDK for the Baishu Coze (APAAS) API, generated from the coze-studio thrift IDL.","maintainers":[{"name":"baishuyun.com","email":"2559215848@qq.com"}],"readme":"# @baishuyun/coze-sdk\n\n由 [coze-studio](https://github.com/coze-dev/coze-studio) 的 thrift IDL 全量生成的 **强类型智能体开发平台（APAAS）SDK**。传入一个 token 与 baseUrl 即可调用全部 19 个 service（约 274 个 endpoint），不再需要手工拼 URL + 裸 `fetch`。\n\n- **全量 IDL 覆盖**：19 个 service、274 个 endpoint、1000+ struct、270+ enum。\n- **强类型**：请求/响应类型由 thrift 字段精确生成，`i64` 按注解自动转 `string` 避免精度丢失。\n- **零运行时依赖**：仅用全局 `fetch` + `AbortSignal.timeout`，`node >= 22`。\n- **统一错误处理**：`CozeApiError` / `CozeHTTPError` / `CozeTimeoutError` / `CozeAbortError`。\n- **幂等重试 + 超时 + 日志**，可配置。\n- **流式**：`/v3/chat` 等 SSE 端点通过 `parseSSE` 消费。\n- **生成产物提交进仓库**，运行时无需 codegen；`pnpm generate` 可幂等重跑。\n\n## 安装\n\n```bash\npnpm add @baishuyun/coze-sdk\n```\n\n## 快速开始\n\n```ts\nimport { createCozeSDK } from '@baishuyun/coze-sdk';\n\nconst coze = createCozeSDK({\n  token: process.env.BOT_API_KEY,     // 缺省回退读 BOT_API_KEY / COZE_API_KEY\n  baseUrl: 'https://host/subdir',     // API 根地址，IDL 路径自带 /v1/ /v3/ /api/ 前缀\n});\n\n// 获取某个类型的模型列表（对应后端 coding-model.ts 的 /v1/config/model/get?type=4）\nconst resp = await coze.config.GetApiModelInfo({ type: 4 });\nresp.provider_model_info.model_list.forEach((m) => console.log(m.id));\n\n// 机器人列表\nconst botList = await coze.bot.OpenGetBotList({ pageSize: 100 });\n\n// 创建会话（返回 data 字段）\nconst conv = await coze.conversation.CreateConversation({ bot_id: 'bot-1', user_id: 'u1' });\n\n// 清空会话（路径参数）\nawait coze.conversation.ClearConversationApi({ conversation_id: conv.id });\n\n// 自定义 token 交换（Baishu，不在 IDL 中）\nconst { team_uid, data } = await coze.token.exchangeByTeamId('some-token');\n```\n\n## 配置\n\n```ts\ninterface CozeSDKConfig {\n  token?: string;      // 与 apiKey 二选一；缺省读 BOT_API_KEY || COZE_API_KEY\n  apiKey?: string;     // token 别名\n  baseUrl?: string;    // 必填，如 https://host/subdir\n  timeoutMs?: number;  // 默认 30000\n  retry?: RetryOptions | false;  // 默认幂等请求重试 2 次\n  headers?: Record<string, string>;\n  fetch?: typeof fetch;   // 测试注入\n  logger?: CozeLogger;    // { debug?, info?, warn?, error? }\n}\n```\n\n## 命名约定（重要）\n\n生成的 TS 字段名 = **wire 名**（`api.body` / `api.query` / `api.path` / `agw.key` / `go.tag`，否则 thrift 字段名），因此是 **snake_case**，与后端现有 fetch 调用一致，方便直接迁移：\n\n```ts\nawait coze.conversation.CreateConversation({ bot_id: 'bot-1', user_id: 'u1' });  // 不是 botId\n```\n\n- `i64` 字段：带 `api.js_conv` / `agw.js_conv=\"str\"` 的生成 `string`，否则 `number`。\n- `map<K,V>` → `Record<string, V>`（JSON key 恒为字符串）。\n- `optional` 字段 → `name?: T`。\n- 响应体含 `data` 字段时返回 `data`，否则返回整个响应体。\n\n## 服务 facade\n\n| 属性 | 服务类 | 说明 |\n|---|---|---|\n| `coze.config` | `ConfigService` | 模型 / 基础配置 |\n| `coze.bot` | `BotOpenApiService` | 机器人 |\n| `coze.conversation` | `ConversationService` | 会话 |\n| `coze.message` | `MessageService` | 消息 |\n| `coze.chat` | `AgentRunService` | `/v3/chat` 对话 |\n| `coze.upload` | `UploadService` | 上传 |\n| `coze.intelligence` | `IntelligenceService` | 智能体编排 |\n| `coze.auth` | `OpenAPIAuthService` | OAuth |\n| `coze.memory` | `MemoryService` | 记忆/变量 |\n| `coze.plugin` | `PluginDevelopService` | 插件 |\n| `coze.marketplace` | `PublicProductService` | 市场/商品 |\n| `coze.developer` | `DeveloperApiService` | 开发者 |\n| `coze.playground` | `PlaygroundService` | 调试台 |\n| `coze.database` | `DatabaseService` | 数据库 |\n| `coze.dataset` | `DatasetService` | 知识库（api.thrift 聚合名 `KnowledgeService`） |\n| `coze.resource` | `ResourceService` | 资源 |\n| `coze.passport` | `PassportService` | 账号 |\n| `coze.workflow` | `WorkflowService` | 工作流 |\n| `coze.record` | `RecordService` | 记录 |\n| `coze.token` | `TokenResource` | 手写：`/api/by_teamid/tokens` |\n\n## 错误处理\n\n```ts\nimport { CozeApiError, CozeHTTPError, CozeTimeoutError } from '@baishuyun/coze-sdk';\n\ntry {\n  await coze.config.GetApiModelInfo({ type: 4 });\n} catch (e) {\n  if (e instanceof CozeApiError) {\n    console.log(e.code, e.msg, e.data);   // 业务码 !== 0\n  } else if (e instanceof CozeHTTPError) {\n    console.log(e.status);                  // 非 2xx 且无标准 envelope\n  }\n}\n```\n\n## 流式（SSE）\n\n```ts\nimport { createCozeSDK, parseSSE, endpoints } from '@baishuyun/coze-sdk';\n\nconst def = endpoints.find((e) => e.method === 'ChatV3')!;\nconst res = await coze.stream(def, { bot_id: 'b1', user_id: 'u1', stream: true });\n\nfor await (const evt of parseSSE(res)) {\n  const chunk = JSON.parse(evt.data);\n  console.log(chunk);\n}\n```\n\n## 进阶用法\n\n- `coze.request<T>(def, params)` — 手动指定 endpoint def，返回 `data`。\n- `coze.stream(def, params)` — 返回原始 `Response`（不解析、不重试）。\n- `coze.get<T>(path, query?)` / `coze.post<T>(path, body?)` — 裸请求（自定义/非 IDL 端点）。\n- `types` 命名空间：`import { types } from '@baishuyun/coze-sdk'`，如 `types.model_config.GetModelInfoReq`。\n- `endpoints` / `endpointIndex`：机器可读的 `EndpointDef[]` 注册表（供后续把 SDK 方法暴露为 agent 工具时消费）。\n\n## 重新生成（开发）\n\n```bash\n# 默认读取 /Users/bbbottle/Code/coze-studio/idl，可用 COZE_IDL_DIR 或 --idl-dir 覆盖\npnpm generate\npnpm type-check\npnpm build\n```\n\n`scripts/generate.mjs` 为纯 Node ESM、零依赖的 thrift 解析器，产物提交进仓库。\n\n## 后续（Phase 2）\n\n把 SDK 方法按 service 分组暴露为 `bsMetaAgent` 的工具/技能（约 19 个工具 + `action` 判别字段），让智能体获得操纵智能体开发平台的能力。本仓库的 `endpoints` 元数据与类型已为此预留。\n\n## 目录结构\n\n```\npackages/coze-sdk/\n├── scripts/generate.mjs       # thrift → TS codegen\n└── src/\n    ├── index.ts               # 公共出口\n    ├── client.ts              # CozeSDK + createCozeSDK\n    ├── errors.ts              # 错误类型\n    ├── types.ts               # 配置/日志/重试类型\n    ├── resource.ts            # Resource 基类\n    ├── stream.ts              # SSE 解析\n    ├── http/{transport,request}.ts\n    ├── resources/{index,token}.ts\n    └── generated/             # 全部生成，提交进仓库\n        ├── types/<module>.ts  # 每个 thrift 文件一个模块\n        ├── endpoints.ts       # EndpointDef[] 注册表\n        └── resources/<service>.ts\n```\n","readmeFilename":"README.md"}