@tansr/sdk 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -27,7 +27,7 @@ for await (const event of session.events) {
27
27
  }
28
28
  ```
29
29
 
30
- 模型目录与能力位由平台 App 配置(控制台治理)自动下发,本地零配置。
30
+ 模型目录与授权能力由平台 App 配置下发。系统媒体工具须在 `tools.builtin` 中显式选择;仅开启平台授权不会让缺省 SDK 会话自动装入收费媒体工具。
31
31
 
32
32
  ## 应用系统提示词(AP-SP)
33
33
 
@@ -48,6 +48,39 @@ P 和 S 同为模型 system 输入,拼接次序不保证冲突指令谁胜出
48
48
 
49
49
  完整三档 SDK、Windows Electron、serve、Android/iOS 示例见[提示词指南](https://docs.tansr.com/sdk/system-prompts/)与仓内 doc/90 §4.12。此能力仍须发布包含 AP-SP 的 API 与 SDK/serve,旧版本不识别保留策略。
50
50
 
51
+ ## 模型、上下文和图文输入
52
+
53
+ 开发中的新接口须使用包含它们的 SDK 构建;旧 npm 包没有这些接口时,宿主应提示升级。
54
+ `session.contextState()` 和 `session.subscribeContext(listener)` 提供可序列化快照:
55
+ `selected` 是下一轮模型,`active` 是运行轮冻结的模型;`lastObserved` 仅在收到模型用量证据后存在。
56
+ `currentModel({ active: true })` 查询执行轮模型,空闲时返回当前选择。fallback 只报告已观测到的提供方变化。
57
+ `budget` 包含物理与有效窗口、输入估算、输出/思考预留、剩余量、压缩阈值及设置来源。
58
+ 未知值为 `null`;本地输入估算与平台累计计费用量分别展示。
59
+
60
+ 大窗口降到小窗口时,在空闲状态 `await session.switchModel(next)`。
61
+ SDK 保留迁移前原文备份,必要时用源模型分段摘要,核验目标预算并落盘后再提交切换;
62
+ 图片、工具配对及其前后顺序保留,无法容纳即拒绝。失败或取消不静默截断历史。
63
+ `modelTransitionBackup()` 可取回最近一次迁移备份;需要跨进程恢复时配置 checkpoint/store。
64
+ 外部压缩管理器需要通过 `switchModel(next, { compaction })` 显式提供与目标匹配的配置。
65
+ 摘要调用可能产生用量;备份不代表摘要语义必然完整,业务关键事实仍应核对。
66
+
67
+ `sendBlocks([{ t: 'image', mime: 'image/png', data: base64 }, { t: 'text', text: '描述图片' }])`
68
+ 提交同一轮图文,返回 `started` 或带原因的 `rejected`。忙时由宿主保留整份草稿,不能自动去图重发。
69
+ 图片需满足格式魔数、单图 3.75 MiB、最多 20 张、总图片 30 MiB 和上下文预算限制;
70
+ 模型与传输通道都需支持图片。Read 产生的像素随工具结果发送到支持视觉的模型,元数据读取成功不等于模型已看见图片。
71
+
72
+ `planSpeechInput(text, { maxCharacters, segment })` 使用授权模型 `maxChars` 规划朗读;
73
+ 汉字按 2、其他 Unicode 码点按 1 估算。超出单次限制须显式允许分段,总上限 32000、最多 32 段。
74
+ 宿主负责逐段执行、取消和保留产物,已成功或结果不明的收费请求不自动重放。
75
+ 应用提示词刷新失败提供 `reason`、`stage`、`retry`,继续中止该轮;由宿主换发开发者凭据并决定重试。
76
+
77
+ The new interfaces above require a build that includes them. `contextState()` separates the next selected
78
+ model, the active turn's frozen model, observed usage, and local context estimates. Unknown values are
79
+ `null`. Await `switchModel()` while idle to prepare and validate a smaller context before committing;
80
+ failure keeps the original history. `sendBlocks()` submits image and text together and rejects busy
81
+ submissions without removing images. Speech planning requires the authorized model's character limit
82
+ and explicit segmentation; completed or uncertain paid requests must not be replayed automatically.
83
+
51
84
  ## 三档 API × 三档模型来源
52
85
 
53
86
  | API | 形态 | 适用 |
@@ -64,10 +97,12 @@ P 和 S 同为模型 system 输入,拼接次序不保证冲突指令谁胜出
64
97
 
65
98
  ## 能力面一览
66
99
 
67
- - **三环工具一个入口**:`tools: { builtin: [...], platform: [...], custom: [...] }`
68
- ——环2 内置本地工具(read/glob/grep/shell/…)、环3 平台托管能力(imageGen 图像
69
- 生成,平台代调按张计费)、环1 `defineTool` 业务函数(注册即说明书,JSON 参数表/
70
- zod 双档);
100
+ - **系统工具与业务工具统一入口**:`tools: { builtin: [...], custom: [...] }`。
101
+ 系统工具包括文件、命令、网络及多媒体;`imageGen`、`videoGen`、`speechToText`、
102
+ `textToSpeech` 与其他系统工具一起从 `tools.builtin` 选择,执行骨架统一在内核。
103
+ SDK 媒体后端由平台提供,受应用授权、模型范围和计量约束。`defineTool` 注册业务函数,
104
+ 接受 JSON 参数表或 zod schema。旧 `tools.platform` 仅为四媒体的弃用兼容别名,
105
+ 会并入同一内置工具集合并去重,不代表另一层工具;
71
106
  - **联网搜索双位双门**:webSearch 工具本体是内置 `WebSearch`(写在 `tools.builtin`,
72
107
  旧写法 `tools.platform` 报迁移错),后端恒平台通道(按次计费归 App,SDK 恒无 BYO
73
108
  径)——装配需双位齐开(`tools.webSearch` 工具位 + `platform.webSearch` 通道位)且
@@ -94,9 +129,32 @@ P 和 S 同为模型 system 输入,拼接次序不保证冲突指令谁胜出
94
129
  - **计量**:`cost.usage.updated` 逐请求;终端自查 `/v1/my-usage` 恒无金额字段,
95
130
  开发者对账 `/v1/app-usage/by-end-user` 含金额(恒不代理给终端)。
96
131
 
97
- 能力位(17 工具位 + 5 平台位:webSearch / imageGen / videoGen / speechToText / textToSpeech,
98
- `CAPABILITY_TOOL_KEYS` / `CAPABILITY_PLATFORM_KEYS` 为事实源)在平台控制台按 App 配置;位关而显式
99
- 选择恒得到装配期可读错(`capability_disabled`,含修复指引),恒不静默缺工具。
132
+ 工具与扩展授权以及平台服务授权均在控制台按 App 配置;字段分别为 `capabilities.tools`
133
+ `capabilities.platform`,键集合由 `CAPABILITY_TOOL_KEYS` / `CAPABILITY_PLATFORM_KEYS`
134
+ 提供。授权合同仍为 17 工具位 + 5 平台位;后者控制平台搜索及四媒体服务的使用权,
135
+ 不是工具归属分类。位关而显式选择得到
136
+ `capability_disabled`,不静默缺工具。
137
+
138
+ ### 系统媒体工具示例 / System media tools
139
+
140
+ ```ts
141
+ const session = await createSession({
142
+ token,
143
+ baseUrl: 'https://api.example.com',
144
+ tools: { builtin: ['imageGen', 'videoGen', 'speechToText', 'textToSpeech'] },
145
+ });
146
+ ```
147
+
148
+ 先在应用配置中授权所需媒体服务与模型。示例只选择四个媒体工具;需要文件、网络等工具时,
149
+ 也应显式加入同一个 `builtin` 列表。权限确认、预算与平台计费继续适用。用户主动录音转写或朗读
150
+ 可以调用 `session.platform.transcribe()` / `.speak()`;这些是直连操作,不会伪造模型工具事件或自动写入聊天历史。
151
+
152
+ All four media tools are built-in system tools selected through `tools.builtin`. The platform supplies
153
+ their backend and enforces app permissions, model access, quotas, and billing. The retained
154
+ `capabilities.platform` fields describe service authorization, not a separate tool category.
155
+ Media tools require explicit selection; the default SDK tool set does not enable them automatically.
156
+ The deprecated `tools.platform` selection remains an equivalent alias. User-triggered transcription
157
+ and speech through `session.platform` are direct operations, separate from model tool calls.
100
158
 
101
159
  ## 文档与示例
102
160
 
@@ -1,8 +1,8 @@
1
1
  {
2
- "revision": 4,
3
- "sha256": "c57ffb63c51fa37f84814857240785a1c1d433839a7d0e6ebcdedc419838597c",
2
+ "revision": 7,
3
+ "sha256": "99d86f2b3ac6b6183bee7ca7717cbc6fa4b3af88fc1c8cf2d683488cde610e94",
4
4
  "errorCodes": 38,
5
- "eventTypes": 54,
5
+ "eventTypes": 55,
6
6
  "eventTypeNames": [
7
7
  "agent.completed",
8
8
  "agent.followup",
@@ -39,6 +39,7 @@
39
39
  "session.created",
40
40
  "session.cwd_changed",
41
41
  "session.ended",
42
+ "session.events_dropped",
42
43
  "session.forked",
43
44
  "session.locale.changed",
44
45
  "session.microcompacted",
@@ -59,8 +60,8 @@
59
60
  "turn.error",
60
61
  "turn.started"
61
62
  ],
62
- "eventSchemaSha256": "ddc7afac50d2ff8980ebeab2d8b3089dd197623dc2a23049e76a0944fa15ef59",
63
+ "eventSchemaSha256": "54b587ade59bf20a3d55647a160c3d857dbf2fa73730d82cf7811b7ee4097501",
63
64
  "contractVersion": "v1",
64
- "sourceCommit": "34a6f37e23036ce8aa7cccd67dbbbd40863d8544",
65
- "generatedAt": "2026-09-10T02:55:26.356Z"
65
+ "sourceCommit": "d346aadf99e1b7ce1db2226b71de03adcc22f3df",
66
+ "generatedAt": "2026-09-12T09:12:29.149Z"
66
67
  }