@armadra/agent 0.17.2 → 0.18.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/CHANGELOG.md +36 -0
- package/CHANGELOG.zh-CN.md +36 -0
- package/THIRD_PARTY_NOTICES.md +6 -0
- package/assets/quickjs/LICENSE +57 -0
- package/assets/quickjs/README.md +14 -0
- package/assets/quickjs/quickjs.wasm +0 -0
- package/dist/agent/recovery-reminder.js +6 -1
- package/dist/agent/schema-coerce.d.ts +24 -0
- package/dist/agent/schema-coerce.js +157 -0
- package/dist/agent/schema.d.ts +1 -1
- package/dist/agent/schema.js +1 -1
- package/dist/agent/session-cache.js +12 -0
- package/dist/agent/tool-runner.js +57 -28
- package/dist/agent/types.d.ts +4 -0
- package/dist/ai/apis/anthropic-compat.d.ts +3 -1
- package/dist/ai/apis/anthropic-compat.js +8 -1
- package/dist/ai/apis/anthropic-messages.js +54 -2
- package/dist/ai/apis/anthropic-request.d.ts +3 -0
- package/dist/ai/apis/anthropic-request.js +7 -1
- package/dist/ai/apis/anthropic-threads.d.ts +64 -0
- package/dist/ai/apis/anthropic-threads.js +192 -0
- package/dist/ai/providers/catalog-data.js +5 -5
- package/dist/ai/providers/models-dev-data.js +22 -22
- package/dist/ai/types.d.ts +16 -0
- package/dist/bundle/ama-sandbox.cjs +96 -2
- package/dist/bundle/ama.cjs +2386 -890
- package/dist/cli/subcommands/config.d.ts +3 -0
- package/dist/cli/subcommands/config.js +22 -7
- package/dist/cli/subcommands/doctor.js +1 -0
- package/dist/cli/subcommands/models-discover.js +6 -2
- package/dist/codemode/capability.d.ts +14 -2
- package/dist/codemode/capability.js +19 -2
- package/dist/codemode/host-side.d.ts +14 -0
- package/dist/codemode/host-side.js +81 -10
- package/dist/codemode/inner-calls.d.ts +19 -0
- package/dist/codemode/inner-calls.js +24 -0
- package/dist/codemode/protocol.d.ts +14 -0
- package/dist/codemode/protocol.js +9 -1
- package/dist/codemode/quickjs/host.d.ts +15 -0
- package/dist/codemode/quickjs/host.js +243 -0
- package/dist/codemode/quickjs/wasm.d.ts +21 -0
- package/dist/codemode/quickjs/wasm.js +39 -0
- package/dist/codemode/quickjs/worker.d.ts +55 -0
- package/dist/codemode/quickjs/worker.js +457 -0
- package/dist/codemode/sandbox-entry.d.ts +4 -0
- package/dist/codemode/sandbox-entry.js +95 -3
- package/dist/codemode/script-images.d.ts +18 -0
- package/dist/codemode/script-images.js +38 -0
- package/dist/codemode/script-output.d.ts +19 -0
- package/dist/codemode/script-output.js +67 -0
- package/dist/codemode/search-tools.d.ts +27 -0
- package/dist/codemode/search-tools.js +83 -0
- package/dist/codemode/tool.d.ts +4 -0
- package/dist/codemode/tool.js +60 -9
- package/dist/codemode/worker-pool.d.ts +65 -0
- package/dist/codemode/worker-pool.js +131 -0
- package/dist/config/json-schema.js +3 -1
- package/dist/config/key-docs.js +7 -1
- package/dist/config/schema.js +4 -2
- package/dist/config/settings-registry.js +2 -0
- package/dist/config/types.d.ts +10 -0
- package/dist/config/types.js +1 -0
- package/dist/i18n/catalog.d.ts +8 -0
- package/dist/i18n/messages/config-keys.d.ts +4 -0
- package/dist/i18n/messages/config-keys.js +6 -2
- package/dist/i18n/messages/config.d.ts +4 -0
- package/dist/i18n/messages/interactive-view.d.ts +2 -0
- package/dist/i18n/messages/interactive-view.js +2 -0
- package/dist/i18n/messages/interactive.d.ts +2 -0
- package/dist/i18n/messages/report.d.ts +2 -0
- package/dist/i18n/messages/report.js +2 -0
- package/dist/i18n/messages/subcommands-config.d.ts +8 -0
- package/dist/i18n/messages/subcommands-config.js +8 -0
- package/dist/i18n/messages/subcommands.d.ts +8 -0
- package/dist/modes/interactive/tool-view.d.ts +8 -2
- package/dist/modes/interactive/tool-view.js +12 -5
- package/dist/session/unclean-end.d.ts +8 -0
- package/dist/session/unclean-end.js +39 -7
- package/docs/en/guides/providers.md +27 -7
- package/docs/en/guides/tui.md +1 -1
- package/docs/en/reference/rpc.md +3 -1
- package/docs/guides/codemode.md +52 -12
- package/docs/guides/providers.md +21 -1
- package/docs/guides/sandbox.md +2 -0
- package/docs/guides/tui.md +1 -1
- package/docs/reference/rpc.md +3 -1
- package/docs/reference/session-format.md +10 -9
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,42 @@ English · [简体中文](CHANGELOG.zh-CN.md)
|
|
|
5
5
|
> This file is in English starting with 0.6.0. Release notes for 0.1 through 0.5.1 are in Chinese in
|
|
6
6
|
> [CHANGELOG.zh-CN.md](CHANGELOG.zh-CN.md). New entries go into both files.
|
|
7
7
|
|
|
8
|
+
## 0.18.0 (2026-11-15)
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **codemode scripts**: inner `tools.bash` output is widened to 1 MiB (longer output keeps the first and last 512 KiB around an omission marker, `truncated` is set, `fullOutputPath` points at the full file); direct bash results are unchanged.
|
|
13
|
+
- **codemode worker limit**: at most 2 sandbox child processes are alive at once across all sessions in the process (`codemode.maxWorkers`, overridden by `AMA_CODEMODE_MAX_WORKERS`); extra scripts queue FIFO for up to 60 s or until their own `timeout_ms` (the wait counts toward it), then fail without running. Slots are released when the child process has actually exited.
|
|
14
|
+
- **codemode globals**: `searchTools(query, { limit?, namespace? })` ranks callable tools by BM25 over name and description; `image(value)` attaches a PNG / JPEG / GIF / WebP (base64 data URL, `{ image_url }` or `{ type: "image", data, mimeType }`; MIME from magic bytes, remote URLs rejected) to the result and saves it under the session outputs directory. `tools.read` on an image now resolves to an image block that `image()` accepts.
|
|
15
|
+
- **Recovery for killed scripts**: completed inner calls are recorded as `ama.codemode-call` custom entries (additive, format version unchanged); when the process dies mid-script, the resume reminder lists them and says not to repeat them blindly.
|
|
16
|
+
- **Prompt budget**: the `codemode-only` preset budget is raised from 1950 to 2000 tokens (measured 1937 to 1982) for the two new global descriptions; `default` grows by about 26 tokens (1607 to 1633).
|
|
17
|
+
- **QuickJS codemode engine (#290)**: codemode scripts can run in QuickJS compiled to WebAssembly (one worker thread per execution) instead of a Node child process. New setting `codemode.engine`: `auto` (default; the Node child process when the network is isolated by Node >= 25 or an OS sandbox, QuickJS otherwise), `node`, `quickjs`. With QuickJS the scripts reach nothing but `tools.*`, so `codemode` is a `read`-class tool and the `default` preset enables it on every platform, including Windows and Node 22 / 24 without an OS sandbox. Same script surface and result format; timeouts and aborts interrupt spinning scripts, `codemode.maxHeapMb` limits the QuickJS heap, built-ins are frozen, and a script awaiting a promise that can never settle fails at once. Still zero runtime dependencies: the engine is a vendored wasm file (`assets/quickjs/`, inlined into `ama.cjs`). `ama config show` and `ama doctor` report the effective engine and why.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- **Executed arguments visible**: when lenient coercion changed a tool call's arguments, `tool_execution_start` now carries the optional `coercedArguments` (what the gate, hooks and tool received; `args` is still the model's original). RPC events include it (no protocol version change, ACP wire shapes unchanged), and the interactive tool row shows the executed arguments with a dim "(arguments adjusted)" marker.
|
|
22
|
+
- **QuickJS recursion**: unbounded recursion in a QuickJS script now throws a catchable `RangeError: Maximum call stack size exceeded` (JS stack limit 320 KB, about 1300 simple frames), like the Node engine. Native recursion that bypasses the JS stack check (extremely deep JSON) still traps the instance; it ends the script with an error that starts with the same `RangeError` sentence and keeps earlier output.
|
|
23
|
+
- **codemode `image()`**: validation (MIME by magic bytes, base64, 8-image limit) now lives once in the shared bootstrap script instead of two copies; behavior and messages are unchanged.
|
|
24
|
+
- **Lenient tool-argument coercion**: when strict schema validation fails, the runner tries one schema-driven coercion pass (numeric strings to numbers, `"true"`/`"false"` to booleans, numbers/booleans to strings, a single value to a one-element array, a JSON string to an object/array, `null` dropped on optional properties) and re-validates; enums must still match exactly and defaults are never filled. The permission pipeline, hooks and the tool see the coerced arguments; the assistant message and session history keep the model's original call. Applies to codemode inner calls too.
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- **Message threads fallback**: when a thread request is rejected as unsupported (error code, a 400 naming `thread`, or the endpoint refusing the beta header value), the resent full request now drops both `thread` and the threads beta header, and that session and that endpoint + model stop using threads for the rest of the process, so other sessions no longer pay the extra 400. Forked sessions now continue their own thread (new stream option `threadKey`, default `sessionId`) while sharing the prompt cache key. New manual check `scripts/verify-anthropic-threads.mjs` (real key, not run in CI).
|
|
29
|
+
|
|
30
|
+
### Model efficiency
|
|
31
|
+
|
|
32
|
+
- **Anthropic message threads**: requests with a stable session id and `cacheRetention` not `none` now continue the previous reply on the server (beta `message-threads-2026-08-12`) and send only the new messages instead of the whole conversation. Compaction, rewinds and branch switches, and changes to the model, system prompt, tools or thinking level fall back to a full request that starts a new thread; so do thread-not-found style rejections (resent once). On by default only on `api.anthropic.com`; set `compat.messageThreads` to change it. New stream option `disableContinuation` keeps a request from using or replacing thread state; cache warming and compaction summaries set it. Token usage and cache reporting are unchanged. See `docs/guides/providers.md`.
|
|
33
|
+
|
|
34
|
+
### Maintenance
|
|
35
|
+
|
|
36
|
+
- **models.dev snapshot refreshed (2026-11-13)**: catalog overrides for models removed upstream are dropped (Groq `qwen/qwen3.6-27b`, `llama-3.3-70b-versatile`, `llama-3.1-8b-instant`; Anthropic `claude-sonnet-4-5`; MiniMax M2.x, small model now `MiniMax-M3.1-Flash`; Volcengine `doubao-seed-2-0-code-preview-260215`). `ama models discover` no longer warns "unmatched" for relay ids that resolve through a catalog alias. The weekly refresh workflow now fails when its CI check fails or the PR cannot be opened.
|
|
37
|
+
|
|
38
|
+
## 0.17.3 (2026-11-13)
|
|
39
|
+
|
|
40
|
+
### Maintenance
|
|
41
|
+
|
|
42
|
+
- **Patch release aligned with the unified version**: no changes in the agent; the fixes in this patch are in the Armadra app.
|
|
43
|
+
|
|
8
44
|
## 0.17.2 (2026-11-12)
|
|
9
45
|
|
|
10
46
|
### Maintenance
|
package/CHANGELOG.zh-CN.md
CHANGED
|
@@ -4,6 +4,42 @@
|
|
|
4
4
|
|
|
5
5
|
> 从 0.6.0 起 [CHANGELOG.md](CHANGELOG.md) 为英文,本文件保留中文记录(0.1–0.5.1 的完整历史在此)。新条目两份都要加。
|
|
6
6
|
|
|
7
|
+
## 0.18.0(2026-11-15)
|
|
8
|
+
|
|
9
|
+
### 新增
|
|
10
|
+
|
|
11
|
+
- **codemode 脚本**:脚本里 `tools.bash` 的 `output` 放宽到 1 MiB(更长时保留首尾各 512 KiB,中间是省略说明,`truncated` 为真,`fullOutputPath` 指向全文);模型直接调用 bash 的结果不变。
|
|
12
|
+
- **codemode 并发上限**:整个进程(所有会话)同时存活的沙箱子进程至多 2 个(`codemode.maxWorkers`,环境变量 `AMA_CODEMODE_MAX_WORKERS` 优先);多出的脚本先来先到排队,最多等 60 s 或到自己的 `timeout_ms`(等待计入),到点失败且不运行。名额在子进程真正退出时归还。
|
|
13
|
+
- **codemode 全局函数**:`searchTools(query, { limit?, namespace? })` 按名字与描述做 BM25 排序;`image(value)` 把 PNG / JPEG / GIF / WebP(base64 data URL、`{ image_url }` 或 `{ type: "image", data, mimeType }`;MIME 由文件头决定,拒绝远程 URL)附在结果后并存到会话 outputs 目录。`tools.read` 读图片时解析为 `image()` 可直接收的图片块。
|
|
14
|
+
- **脚本被杀后的恢复**:已完成的内层调用记为 `ama.codemode-call` 自定义条目(可选条目,会话格式版本不变);进程在脚本中途被杀后,resume 的恢复提醒列出它们并要求不要盲目重复。
|
|
15
|
+
- **提示预算**:`codemode-only` 预设的预算由 1950 放宽到 2000 token(实测 1937 → 1982),用于两个新全局函数的描述;`default` 增加约 26 token(1607 → 1633)。
|
|
16
|
+
- **codemode 的 QuickJS 引擎(#290)**:codemode 脚本可以跑在编译成 WebAssembly 的 QuickJS 里(每次执行一个 worker 线程),不再只有 Node 子进程一条路。新增配置 `codemode.engine`:`auto`(缺省;网络已被 Node ≥ 25 或操作系统沙箱隔离时用 Node 子进程,否则用 QuickJS)、`node`、`quickjs`。QuickJS 下脚本除 `tools.*` 外触达不了任何东西,所以 `codemode` 是 `read` 类,`default` 预设在所有平台(含 Windows 与没有操作系统沙箱的 Node 22 / 24)都缺省开启。脚本全局与结果格式不变;超时与 abort 会打断空转的脚本,`codemode.maxHeapMb` 限制 QuickJS 堆,内建对象在脚本运行前冻结,等待永远不会落定的 Promise 立即失败。仍然零运行时依赖:引擎是随包分发的 wasm 文件(`assets/quickjs/`,内联进 `ama.cjs`)。`ama config show` 与 `ama doctor` 显示生效的引擎与原因。
|
|
17
|
+
|
|
18
|
+
### 变更
|
|
19
|
+
|
|
20
|
+
- **实际执行的参数可见**:宽松强转改了工具调用的参数时,`tool_execution_start` 多一个可选字段 `coercedArguments`(门禁、钩子与工具实际拿到的参数;`args` 仍是模型原样)。RPC 事件带上它(协议版本不变,ACP 线上形状不变),交互界面的工具行显示实际执行的参数并带淡色「(参数已调整)」标记。
|
|
21
|
+
- **QuickJS 递归**:QuickJS 下脚本的无界递归现在抛出可捕获的 `RangeError: Maximum call stack size exceeded`(JS 栈上限 320 KB,约 1300 层简单调用),与 Node 引擎一致;绕过 JS 栈检查的原生递归(超深 JSON)仍会让实例陷阱,脚本以同一句 `RangeError` 开头的错误结束,此前的输出保留。
|
|
22
|
+
- **codemode `image()`**:校验(按文件头认 MIME、base64、最多 8 张)合并进两个引擎共用的引导脚本,不再有两份拷贝;行为与文案不变。
|
|
23
|
+
- **工具参数宽松强转**:严格校验失败后,按 schema 强转一次再校验(数字串 → 数字、`"true"`/`"false"` → 布尔、数字/布尔 → 字符串、单值 → 单元素数组、JSON 字符串 → 对象/数组、丢弃可选属性的 `null`);enum 仍须严格匹配,不填默认值。权限管线、钩子与工具看到强转后的参数,助手消息与会话历史保留模型原始调用;codemode 内部调用同样适用。
|
|
24
|
+
|
|
25
|
+
### 修复
|
|
26
|
+
|
|
27
|
+
- **消息线程回落**:线程请求被判为不支持(错误码、点名 `thread` 的 400,或端点拒收 beta 头的值)时,重发的整请求现在同时去掉 `thread` 与线程 beta 头,并让该会话与该端点 + 模型在本进程内不再用线程,其它会话不再多吃一次 400。fork 出的会话现在续接自己的线程(新增流选项 `threadKey`,缺省 `sessionId`),提示缓存键仍与根会话共用。新增手工实测脚本 `scripts/verify-anthropic-threads.mjs`(真 key,不进 CI)。
|
|
28
|
+
|
|
29
|
+
### 模型调用效率
|
|
30
|
+
|
|
31
|
+
- **Anthropic 消息线程(message threads)**:带稳定会话 id 且 `cacheRetention` 不是 `none` 的请求,改为在服务端续接上一条回复(beta `message-threads-2026-08-12`),只发新增消息,不再重发整段对话。压缩、回退与分支切换,以及模型、系统提示、工具、思考级别变化时回落为整请求并新开线程;线程不存在之类的拒收同样整请求重发一次。只有 `api.anthropic.com` 缺省开启,可用 `compat.messageThreads` 调整。新增流选项 `disableContinuation`,使请求不使用也不替换线程状态;缓存保温与压缩摘要都会置位。token 用量与缓存上报不变。详见 `docs/guides/providers.md`。
|
|
32
|
+
|
|
33
|
+
### 维护
|
|
34
|
+
|
|
35
|
+
- **刷新 models.dev 快照(2026-11-13)**:去掉上游已下线模型的目录覆盖(Groq `qwen/qwen3.6-27b`、`llama-3.3-70b-versatile`、`llama-3.1-8b-instant`;Anthropic `claude-sonnet-4-5`;MiniMax M2.x,小模型改为 `MiniMax-M3.1-Flash`;火山引擎 `doubao-seed-2-0-code-preview-260215`)。`ama models discover` 对能经目录别名解析的中转 id 不再报「未匹配」。每周刷新作业在自检失败或开不出 PR 时判失败。
|
|
36
|
+
|
|
37
|
+
## 0.17.3(2026-11-13)
|
|
38
|
+
|
|
39
|
+
### 维护
|
|
40
|
+
|
|
41
|
+
- **与统一版本对齐的修复版**:代理本身没有改动,本版的修复都在 Armadra 应用里。
|
|
42
|
+
|
|
7
43
|
## 0.17.2(2026-11-12)
|
|
8
44
|
|
|
9
45
|
### 维护
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -32,3 +32,9 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
32
32
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
33
33
|
SOFTWARE.
|
|
34
34
|
```
|
|
35
|
+
|
|
36
|
+
## QuickJS-ng
|
|
37
|
+
|
|
38
|
+
- 内容:`assets/quickjs/quickjs.wasm`,QuickJS-ng 0.18.0 编译成的 WebAssembly(WASI reactor),codemode 的 QuickJS 引擎用它隔离运行脚本;随 npm 包分发,并内联进 `dist/bundle/ama.cjs`。
|
|
39
|
+
- 来源:<https://github.com/quickjs-ng/quickjs>;二进制取自 npm 包 `quickjs-wasi` 3.7.0 的 `quickjs.wasm`,未修改(SHA-256 与细节见 `assets/quickjs/README.md`)。
|
|
40
|
+
- 许可:MIT;二进制内含的 C 接口层同为 MIT,静态链接的 wasi-libc 见其项目声明。完整声明见 `assets/quickjs/LICENSE`。
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
quickjs.wasm contains the following components. Each keeps its own license.
|
|
2
|
+
|
|
3
|
+
== QuickJS-ng (the JavaScript engine) ==
|
|
4
|
+
|
|
5
|
+
The MIT License (MIT)
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2017-2026 Fabrice Bellard
|
|
8
|
+
Copyright (c) 2017-2024 Charlie Gordon
|
|
9
|
+
Copyright (c) 2023-2026 Ben Noordhuis
|
|
10
|
+
Copyright (c) 2023-2026 Saúl Ibarra Corretgé
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in
|
|
20
|
+
all copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
28
|
+
THE SOFTWARE.
|
|
29
|
+
|
|
30
|
+
== C interface compiled into the binary (qjs_* exports) ==
|
|
31
|
+
|
|
32
|
+
MIT License
|
|
33
|
+
|
|
34
|
+
Copyright (c) 2026 Vercel, Inc.
|
|
35
|
+
|
|
36
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
37
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
38
|
+
in the Software without restriction, including without limitation the rights
|
|
39
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
40
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
41
|
+
furnished to do so, subject to the following conditions:
|
|
42
|
+
|
|
43
|
+
The above copyright notice and this permission notice shall be included in
|
|
44
|
+
all copies or substantial portions of the Software.
|
|
45
|
+
|
|
46
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
47
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
48
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
49
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
50
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
51
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
52
|
+
THE SOFTWARE.
|
|
53
|
+
|
|
54
|
+
== wasi-libc (statically linked C library) ==
|
|
55
|
+
|
|
56
|
+
Portions are MIT (musl derived), Apache-2.0 WITH LLVM-exception and CC0-1.0.
|
|
57
|
+
See https://github.com/WebAssembly/wasi-libc for the full notices.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# quickjs.wasm
|
|
2
|
+
|
|
3
|
+
QuickJS-ng 0.18.0 compiled to WebAssembly (WASI `wasm32-wasip1`, reactor module, no extensions).
|
|
4
|
+
It runs codemode scripts when `codemode.engine` resolves to `quickjs` (docs/guides/codemode.md).
|
|
5
|
+
|
|
6
|
+
- Source: the `quickjs.wasm` file of the npm package `quickjs-wasi` 3.7.0 (MIT), unmodified. Upstream engine: https://github.com/quickjs-ng/quickjs
|
|
7
|
+
- Size: 638148 bytes
|
|
8
|
+
- SHA-256: `c0bd8f296e18cf074969f6401b9ecb72609a1323818ec2b9bf7a8f8d740d1363`
|
|
9
|
+
- Imports: `env.host_call`, `env.host_interrupt`, `env.host_promise_rejection`, `env.host_module_normalize`, `env.host_module_load`, `env.host_get_timezone_offset` and `wasi_snapshot_preview1.{clock_time_get, fd_close, fd_fdstat_get, fd_seek, fd_write, random_get}`.
|
|
10
|
+
- Exports used: `_initialize`, `qjs_init`, `qjs_eval`, `qjs_call`, `qjs_new_host_function` and the other `qjs_*` value helpers (see `src/codemode/quickjs/`).
|
|
11
|
+
- License: see `LICENSE` here and `THIRD_PARTY_NOTICES.md` at the repository root.
|
|
12
|
+
|
|
13
|
+
The file is not a dependency of the package: it is a vendored asset that ships in the npm package (`assets/quickjs/`) and is inlined into `dist/bundle/ama.cjs`.
|
|
14
|
+
To replace it, drop in the new binary, update the size and hash above, and run `pnpm test` (the conformance tests in `src/codemode/quickjs/` check the ABI).
|
|
Binary file
|
|
@@ -14,8 +14,13 @@ export function recoveryReminderText(unclean) {
|
|
|
14
14
|
const listed = unclean.tools.length === 0
|
|
15
15
|
? "No tool calls were recorded in that turn."
|
|
16
16
|
: `Tool calls in that turn: ${unclean.tools.join("; ")}${unclean.more > 0 ? `; …and ${unclean.more} more` : ""}.`;
|
|
17
|
+
const innerCalls = unclean.innerCalls ?? [];
|
|
18
|
+
const inner = innerCalls.length === 0
|
|
19
|
+
? ""
|
|
20
|
+
: "A codemode script was running when the process stopped. Inner calls it had already completed " +
|
|
21
|
+
`(their effects happened unless marked failed): ${innerCalls.join("; ")}${(unclean.innerMore ?? 0) > 0 ? `; …and ${unclean.innerMore} more` : ""}. It may have run more calls that were not recorded. Do not blindly repeat these. `;
|
|
17
22
|
return ("The previous turn of this session ended abruptly (the process stopped before the turn finished; " +
|
|
18
|
-
`this was not a user interrupt). ${listed} ` +
|
|
23
|
+
`this was not a user interrupt). ${listed} ${inner}` +
|
|
19
24
|
"Calls marked (no result) may or may not have taken effect. Before repeating any action with " +
|
|
20
25
|
"external effects (pushes, PRs, comments, migrations, deployments, messages), inspect the workspace, " +
|
|
21
26
|
"the git history and the external state to see what already happened, then continue from there. " +
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 模型工具参数的宽松强转(设计 §5.1)。
|
|
3
|
+
*
|
|
4
|
+
* 只在严格校验失败之后调用一次:按 schema 关键字递归把「差一点」的参数改成合规形状,
|
|
5
|
+
* 调用方再校验一次,通过才用强转后的参数;仍失败则回报原始参数的校验错误。
|
|
6
|
+
*
|
|
7
|
+
* 规则(均由 schema 驱动,不猜):
|
|
8
|
+
* - integer / number:严格十进制数字串(无空白、无十六进制、无 NaN / Infinity)→ 数字;integer 必须是整数。
|
|
9
|
+
* - boolean:恰为 "true" / "false" 的字符串 → 布尔。
|
|
10
|
+
* - string:有限数字、布尔 → 字符串。
|
|
11
|
+
* - array:JSON 字符串解析为数组则采用;否则单个值包成 [value](元素强转后须满足 items)。
|
|
12
|
+
* - object:JSON 字符串解析为对象则采用。
|
|
13
|
+
* - object 的可选属性值为 null 且该属性的 schema 不允许 null(enum 不含 null)→ 丢弃该属性。
|
|
14
|
+
* - 带 enum 的 schema:强转结果必须与某个枚举值严格相等,否则保持原值;永不填 default。
|
|
15
|
+
*
|
|
16
|
+
* 纯函数,不修改入参;没有任何改动时 `changed` 为 false 且 `value` 就是入参本身。
|
|
17
|
+
*/
|
|
18
|
+
import { type JsonSchema } from "./schema.js";
|
|
19
|
+
export interface CoerceResult {
|
|
20
|
+
value: unknown;
|
|
21
|
+
changed: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** 按 schema 强转一次;见文件头规则。 */
|
|
24
|
+
export declare function coerceArguments(schema: JsonSchema, value: unknown): CoerceResult;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 模型工具参数的宽松强转(设计 §5.1)。
|
|
3
|
+
*
|
|
4
|
+
* 只在严格校验失败之后调用一次:按 schema 关键字递归把「差一点」的参数改成合规形状,
|
|
5
|
+
* 调用方再校验一次,通过才用强转后的参数;仍失败则回报原始参数的校验错误。
|
|
6
|
+
*
|
|
7
|
+
* 规则(均由 schema 驱动,不猜):
|
|
8
|
+
* - integer / number:严格十进制数字串(无空白、无十六进制、无 NaN / Infinity)→ 数字;integer 必须是整数。
|
|
9
|
+
* - boolean:恰为 "true" / "false" 的字符串 → 布尔。
|
|
10
|
+
* - string:有限数字、布尔 → 字符串。
|
|
11
|
+
* - array:JSON 字符串解析为数组则采用;否则单个值包成 [value](元素强转后须满足 items)。
|
|
12
|
+
* - object:JSON 字符串解析为对象则采用。
|
|
13
|
+
* - object 的可选属性值为 null 且该属性的 schema 不允许 null(enum 不含 null)→ 丢弃该属性。
|
|
14
|
+
* - 带 enum 的 schema:强转结果必须与某个枚举值严格相等,否则保持原值;永不填 default。
|
|
15
|
+
*
|
|
16
|
+
* 纯函数,不修改入参;没有任何改动时 `changed` 为 false 且 `value` 就是入参本身。
|
|
17
|
+
*/
|
|
18
|
+
import { validateSchema } from "./schema.js";
|
|
19
|
+
const NUMBER_TEXT = /^-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;
|
|
20
|
+
function isPlainObject(value) {
|
|
21
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22
|
+
}
|
|
23
|
+
function parseJson(text, kind) {
|
|
24
|
+
const trimmed = text.trim();
|
|
25
|
+
if (trimmed[0] !== (kind === "object" ? "{" : "["))
|
|
26
|
+
return undefined;
|
|
27
|
+
try {
|
|
28
|
+
const parsed = JSON.parse(trimmed);
|
|
29
|
+
return kind === "object"
|
|
30
|
+
? isPlainObject(parsed)
|
|
31
|
+
? parsed
|
|
32
|
+
: undefined
|
|
33
|
+
: Array.isArray(parsed)
|
|
34
|
+
? parsed
|
|
35
|
+
: undefined;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function coerceScalar(schema, value) {
|
|
42
|
+
switch (schema.type) {
|
|
43
|
+
case "number":
|
|
44
|
+
case "integer": {
|
|
45
|
+
if (typeof value !== "string" || !NUMBER_TEXT.test(value))
|
|
46
|
+
return value;
|
|
47
|
+
const parsed = Number(value);
|
|
48
|
+
if (!Number.isFinite(parsed))
|
|
49
|
+
return value;
|
|
50
|
+
if (schema.type === "integer" && !Number.isInteger(parsed))
|
|
51
|
+
return value;
|
|
52
|
+
return parsed;
|
|
53
|
+
}
|
|
54
|
+
case "boolean":
|
|
55
|
+
return value === "true" ? true : value === "false" ? false : value;
|
|
56
|
+
case "string":
|
|
57
|
+
return (typeof value === "number" && Number.isFinite(value)) || typeof value === "boolean"
|
|
58
|
+
? String(value)
|
|
59
|
+
: value;
|
|
60
|
+
default:
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function sameValue(a, b) {
|
|
65
|
+
return a === b;
|
|
66
|
+
}
|
|
67
|
+
function coerceObject(schema, value) {
|
|
68
|
+
const properties = schema.properties ?? {};
|
|
69
|
+
const required = new Set(schema.required ?? []);
|
|
70
|
+
let out;
|
|
71
|
+
for (const [key, child] of Object.entries(value)) {
|
|
72
|
+
const childSchema = Object.hasOwn(properties, key) ? properties[key] : undefined;
|
|
73
|
+
if (childSchema === undefined || child === undefined)
|
|
74
|
+
continue;
|
|
75
|
+
if (child === null) {
|
|
76
|
+
if (!required.has(key) && childSchema.enum?.includes(null) !== true) {
|
|
77
|
+
out ??= { ...value };
|
|
78
|
+
delete out[key];
|
|
79
|
+
}
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const result = coerceAt(childSchema, child);
|
|
83
|
+
if (result.changed) {
|
|
84
|
+
out ??= { ...value };
|
|
85
|
+
out[key] = result.value;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return out === undefined ? { value, changed: false } : { value: out, changed: true };
|
|
89
|
+
}
|
|
90
|
+
function coerceArray(schema, value) {
|
|
91
|
+
const items = schema.items;
|
|
92
|
+
if (items === undefined)
|
|
93
|
+
return { value, changed: false };
|
|
94
|
+
let out;
|
|
95
|
+
value.forEach((item, index) => {
|
|
96
|
+
const result = coerceAt(items, item);
|
|
97
|
+
if (result.changed) {
|
|
98
|
+
out ??= [...value];
|
|
99
|
+
out[index] = result.value;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return out === undefined ? { value, changed: false } : { value: out, changed: true };
|
|
103
|
+
}
|
|
104
|
+
function coerceAt(schema, value) {
|
|
105
|
+
const unchanged = { value, changed: false };
|
|
106
|
+
if (value === undefined || value === null)
|
|
107
|
+
return unchanged;
|
|
108
|
+
let current = value;
|
|
109
|
+
let changed = false;
|
|
110
|
+
if (schema.type === "array" && !Array.isArray(current)) {
|
|
111
|
+
const parsed = typeof current === "string" ? parseJson(current, "array") : undefined;
|
|
112
|
+
if (parsed !== undefined) {
|
|
113
|
+
current = parsed;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const element = schema.items === undefined ? { value: current } : coerceAt(schema.items, current);
|
|
117
|
+
if (schema.items !== undefined && validateSchema(schema.items, element.value).length > 0) {
|
|
118
|
+
return unchanged;
|
|
119
|
+
}
|
|
120
|
+
current = [element.value];
|
|
121
|
+
}
|
|
122
|
+
changed = true;
|
|
123
|
+
}
|
|
124
|
+
else if (schema.type === "object" && typeof current === "string") {
|
|
125
|
+
const parsed = parseJson(current, "object");
|
|
126
|
+
if (parsed === undefined)
|
|
127
|
+
return unchanged;
|
|
128
|
+
current = parsed;
|
|
129
|
+
changed = true;
|
|
130
|
+
}
|
|
131
|
+
else if (schema.type !== undefined && schema.type !== "object" && schema.type !== "array") {
|
|
132
|
+
current = coerceScalar(schema, current);
|
|
133
|
+
changed = !Object.is(current, value);
|
|
134
|
+
}
|
|
135
|
+
if (Array.isArray(current)) {
|
|
136
|
+
const inner = coerceArray(schema, current);
|
|
137
|
+
current = inner.value;
|
|
138
|
+
changed ||= inner.changed;
|
|
139
|
+
}
|
|
140
|
+
else if (isPlainObject(current) &&
|
|
141
|
+
(schema.type === "object" || schema.properties !== undefined)) {
|
|
142
|
+
const inner = coerceObject(schema, current);
|
|
143
|
+
current = inner.value;
|
|
144
|
+
changed ||= inner.changed;
|
|
145
|
+
}
|
|
146
|
+
if (!changed)
|
|
147
|
+
return unchanged;
|
|
148
|
+
if (schema.enum !== undefined &&
|
|
149
|
+
!schema.enum.some((candidate) => sameValue(candidate, current))) {
|
|
150
|
+
return unchanged;
|
|
151
|
+
}
|
|
152
|
+
return { value: current, changed: true };
|
|
153
|
+
}
|
|
154
|
+
/** 按 schema 强转一次;见文件头规则。 */
|
|
155
|
+
export function coerceArguments(schema, value) {
|
|
156
|
+
return coerceAt(schema, value);
|
|
157
|
+
}
|
package/dist/agent/schema.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - `validateSchema(schema, value)` 返回错误列表;空数组 = 通过。路径形如 `$.edits[0].oldText`,
|
|
8
8
|
* 非标识符键用 `$["a b"]`。
|
|
9
9
|
* - `checkSchemaSubset(schema)` 检查 schema 本身只用了子集关键字(工具注册时调用)。
|
|
10
|
-
* -
|
|
10
|
+
* - 本模块只做严格校验,不强转、不填 default;校验失败后的宽松强转在 `schema-coerce.ts`(tool-runner 调用)。
|
|
11
11
|
*/
|
|
12
12
|
import type { JsonSchema } from "../ai/types.js";
|
|
13
13
|
export type { JsonSchema, JsonSchemaType } from "../ai/types.js";
|
package/dist/agent/schema.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - `validateSchema(schema, value)` 返回错误列表;空数组 = 通过。路径形如 `$.edits[0].oldText`,
|
|
8
8
|
* 非标识符键用 `$["a b"]`。
|
|
9
9
|
* - `checkSchemaSubset(schema)` 检查 schema 本身只用了子集关键字(工具注册时调用)。
|
|
10
|
-
* -
|
|
10
|
+
* - 本模块只做严格校验,不强转、不填 default;校验失败后的宽松强转在 `schema-coerce.ts`(tool-runner 调用)。
|
|
11
11
|
*/
|
|
12
12
|
const SCHEMA_TYPES = [
|
|
13
13
|
"object",
|
|
@@ -13,6 +13,7 @@ import { fingerprintContext } from "../ai/cache/fingerprint.js";
|
|
|
13
13
|
import { DEFAULT_MIN_CACHE_TOKENS, IMPLICIT_CACHE_TTL_MS, detectMiss } from "../ai/cache/miss.js";
|
|
14
14
|
import { endpointKey, sharedCacheReporting, } from "../ai/cache/reporting.js";
|
|
15
15
|
import { CacheWarmer, replayBlocker, warmReplayMaxTokens, } from "../ai/cache/warmer.js";
|
|
16
|
+
import { forgetThreads } from "../ai/apis/anthropic-threads.js";
|
|
16
17
|
import { thinkingBudget } from "../ai/thinking.js";
|
|
17
18
|
import { estimateTextTokens } from "../compaction/estimate.js";
|
|
18
19
|
import { SUMMARY_MAX_TOKENS } from "../compaction/summarize-tier.js";
|
|
@@ -133,6 +134,13 @@ export class SessionCacheController {
|
|
|
133
134
|
thinking: options.thinkingLevel,
|
|
134
135
|
};
|
|
135
136
|
subtaskMs = this.takeTaskMs(at);
|
|
137
|
+
// fork 出的会话与根会话共用提示缓存键,但线程键各用自己的会话 id:各续各的服务端线程
|
|
138
|
+
if (sent.sessionId !== undefined)
|
|
139
|
+
sent.threadKey = this.core.manager.id;
|
|
140
|
+
}
|
|
141
|
+
else if (purpose === "summary") {
|
|
142
|
+
// 摘要续写 = 上一回合前缀 + 指令:续接会占掉那条回复的唯一续接点,并把摘要回复当成线程末端
|
|
143
|
+
sent.disableContinuation = true;
|
|
136
144
|
}
|
|
137
145
|
let replaced = false;
|
|
138
146
|
const onPayload = options.onPayload;
|
|
@@ -334,6 +342,8 @@ export class SessionCacheController {
|
|
|
334
342
|
dispose() {
|
|
335
343
|
this.disposed = true;
|
|
336
344
|
this.warmer.cancel();
|
|
345
|
+
// 会话结束,释放它的服务端续接点记录(线程键是会话自己的 id)
|
|
346
|
+
forgetThreads(this.core.manager.id);
|
|
337
347
|
}
|
|
338
348
|
// -------------------------------------------------------------------------
|
|
339
349
|
// 内部
|
|
@@ -470,6 +480,8 @@ export class SessionCacheController {
|
|
|
470
480
|
...record.options,
|
|
471
481
|
maxTokens: warmReplayMaxTokens(model.api),
|
|
472
482
|
purpose: "warm",
|
|
483
|
+
// 保温重放整段前缀:不用也不替换服务端续接点,否则会占掉下一回合的线程
|
|
484
|
+
disableContinuation: true,
|
|
473
485
|
signal,
|
|
474
486
|
};
|
|
475
487
|
return inner(model, record.contextRef, options).result();
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
24
24
|
import { join } from "node:path";
|
|
25
25
|
import { REPEATED_TOOL_CALL, guardFor, loopReminderText, loopStopText, } from "./loop-guard.js";
|
|
26
|
+
import { coerceArguments } from "./schema-coerce.js";
|
|
26
27
|
import { formatSchemaErrors, validateSchema } from "./schema.js";
|
|
27
28
|
import { CODEMODE_TOOL } from "../tools/presets.js";
|
|
28
29
|
import { executionModeOf } from "../tools/registry.js";
|
|
@@ -37,6 +38,9 @@ export const NESTED_MAX_RESULT_CHARS = 1024 * 1024;
|
|
|
37
38
|
const autoDecisions = new WeakMap();
|
|
38
39
|
/** 门禁拒绝(gate.block)而没有执行的调用:tool_execution_end 带 `denied`。 */
|
|
39
40
|
const deniedCalls = new WeakSet();
|
|
41
|
+
function isArgs(value) {
|
|
42
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
43
|
+
}
|
|
40
44
|
export function errorResult(text) {
|
|
41
45
|
return { content: text, isError: true };
|
|
42
46
|
}
|
|
@@ -66,6 +70,31 @@ function notFoundText(name, options) {
|
|
|
66
70
|
}
|
|
67
71
|
return toolUnavailableText(name);
|
|
68
72
|
}
|
|
73
|
+
/** 严格校验失败、宽松强转后通过时的参数;其余(本来就合法、强转后仍不合法)为 undefined。 */
|
|
74
|
+
function coercedArgumentsOf(tool, args) {
|
|
75
|
+
if (validateSchema(tool.parameters, args).length === 0)
|
|
76
|
+
return undefined;
|
|
77
|
+
const coerced = coerceArguments(tool.parameters, args);
|
|
78
|
+
if (!coerced.changed || validateSchema(tool.parameters, coerced.value).length > 0) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
return isArgs(coerced.value) ? coerced.value : undefined;
|
|
82
|
+
}
|
|
83
|
+
/** `tool_execution_start`:带 `coercedArguments`(实际执行的参数)当且仅当强转改了模型的原始参数。 */
|
|
84
|
+
function startEvent(call, tool, parentToolCallId) {
|
|
85
|
+
const event = {
|
|
86
|
+
type: "tool_execution_start",
|
|
87
|
+
toolCallId: call.id,
|
|
88
|
+
toolName: call.name,
|
|
89
|
+
args: call.arguments,
|
|
90
|
+
};
|
|
91
|
+
const coerced = tool === undefined ? undefined : coercedArgumentsOf(tool, call.arguments);
|
|
92
|
+
if (coerced !== undefined)
|
|
93
|
+
event.coercedArguments = coerced;
|
|
94
|
+
if (parentToolCallId !== undefined)
|
|
95
|
+
event.parentToolCallId = parentToolCallId;
|
|
96
|
+
return event;
|
|
97
|
+
}
|
|
69
98
|
async function prepare(call, assistant, options, signal, parent) {
|
|
70
99
|
if (signal.aborted)
|
|
71
100
|
return { kind: "immediate", call, result: errorResult(ABORTED_TOOL_TEXT) };
|
|
@@ -75,23 +104,33 @@ async function prepare(call, assistant, options, signal, parent) {
|
|
|
75
104
|
if (tool === undefined) {
|
|
76
105
|
return { kind: "immediate", call, result: errorResult(notFoundText(call.name, options)) };
|
|
77
106
|
}
|
|
78
|
-
|
|
79
|
-
|
|
107
|
+
/** 严格校验;失败时按 schema 宽松强转一次再校验,仍失败则回报原始参数的错误。 */
|
|
108
|
+
const check = (args) => {
|
|
109
|
+
const errors = validateSchema(tool.parameters, args);
|
|
80
110
|
if (errors.length === 0)
|
|
81
|
-
return
|
|
111
|
+
return { input: args };
|
|
112
|
+
const coerced = coercedArgumentsOf(tool, args);
|
|
113
|
+
if (coerced !== undefined)
|
|
114
|
+
return { input: coerced };
|
|
82
115
|
return {
|
|
83
116
|
kind: "immediate",
|
|
84
117
|
call,
|
|
85
118
|
result: errorResult(`Invalid arguments for ${call.name}:\n${formatSchemaErrors(errors)}`),
|
|
86
119
|
};
|
|
87
120
|
};
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
90
|
-
return
|
|
91
|
-
let input =
|
|
121
|
+
const first = check(call.arguments);
|
|
122
|
+
if ("kind" in first)
|
|
123
|
+
return first;
|
|
124
|
+
let input = first.input;
|
|
125
|
+
// 强转后的参数只给门禁、钩子与工具;助手消息里的原始调用不改(会话回放与提示前缀逐字节不变)
|
|
126
|
+
let used = call;
|
|
127
|
+
if (input !== call.arguments && isArgs(input)) {
|
|
128
|
+
const { rawArguments: _raw, ...rest } = call;
|
|
129
|
+
used = { ...rest, arguments: input };
|
|
130
|
+
}
|
|
92
131
|
try {
|
|
93
132
|
const gateContext = parent === undefined ? { signal, assistant, tool } : { signal, assistant, tool, parent };
|
|
94
|
-
const gate = await options.beforeToolCall(
|
|
133
|
+
const gate = await options.beforeToolCall(used, gateContext);
|
|
95
134
|
if (gate.autoDecision !== undefined)
|
|
96
135
|
autoDecisions.set(call, gate.autoDecision);
|
|
97
136
|
if (signal.aborted)
|
|
@@ -105,10 +144,10 @@ async function prepare(call, assistant, options, signal, parent) {
|
|
|
105
144
|
};
|
|
106
145
|
}
|
|
107
146
|
if (gate.input !== undefined) {
|
|
108
|
-
const recheck =
|
|
109
|
-
if (
|
|
147
|
+
const recheck = check(gate.input);
|
|
148
|
+
if ("kind" in recheck)
|
|
110
149
|
return recheck;
|
|
111
|
-
input =
|
|
150
|
+
input = recheck.input;
|
|
112
151
|
}
|
|
113
152
|
}
|
|
114
153
|
catch (error) {
|
|
@@ -118,7 +157,7 @@ async function prepare(call, assistant, options, signal, parent) {
|
|
|
118
157
|
result: errorResult(signal.aborted ? ABORTED_TOOL_TEXT : `Tool call rejected: ${String(error)}`),
|
|
119
158
|
};
|
|
120
159
|
}
|
|
121
|
-
return { kind: "prepared", call, tool, input };
|
|
160
|
+
return { kind: "prepared", call, used, tool, input };
|
|
122
161
|
}
|
|
123
162
|
function resultText(content) {
|
|
124
163
|
if (typeof content === "string")
|
|
@@ -158,7 +197,7 @@ function truncateResult(call, result, options, nested = false) {
|
|
|
158
197
|
};
|
|
159
198
|
}
|
|
160
199
|
async function execute(prepared, options, signal, emit, parent) {
|
|
161
|
-
const { call, tool, input } = prepared;
|
|
200
|
+
const { call, used, tool, input } = prepared;
|
|
162
201
|
if (signal.aborted)
|
|
163
202
|
return errorResult(ABORTED_TOOL_TEXT);
|
|
164
203
|
const updates = [];
|
|
@@ -179,7 +218,7 @@ async function execute(prepared, options, signal, emit, parent) {
|
|
|
179
218
|
});
|
|
180
219
|
let result;
|
|
181
220
|
try {
|
|
182
|
-
const created = options.createToolContext(
|
|
221
|
+
const created = options.createToolContext(used, signal, onUpdate);
|
|
183
222
|
// [ME-D] 工具按会话结果上限一次截到位(D11);宿主自己给了就不覆盖
|
|
184
223
|
const ctx = created.maxResultChars !== undefined
|
|
185
224
|
? created
|
|
@@ -206,8 +245,8 @@ async function execute(prepared, options, signal, emit, parent) {
|
|
|
206
245
|
try {
|
|
207
246
|
result =
|
|
208
247
|
parent === undefined
|
|
209
|
-
? await options.afterToolCall(
|
|
210
|
-
: await options.afterToolCall(
|
|
248
|
+
? await options.afterToolCall(used, result)
|
|
249
|
+
: await options.afterToolCall(used, result, { parent });
|
|
211
250
|
}
|
|
212
251
|
catch (error) {
|
|
213
252
|
result = errorResult(`PostToolUse failed: ${String(error)}`);
|
|
@@ -247,12 +286,7 @@ export async function runToolBatch(assistant, options, signal, emit) {
|
|
|
247
286
|
const verdicts = new Map();
|
|
248
287
|
let stop;
|
|
249
288
|
for (const call of calls) {
|
|
250
|
-
await emit(
|
|
251
|
-
type: "tool_execution_start",
|
|
252
|
-
toolCallId: call.id,
|
|
253
|
-
toolName: call.name,
|
|
254
|
-
args: call.arguments,
|
|
255
|
-
});
|
|
289
|
+
await emit(startEvent(call, options.getTool(call.name)));
|
|
256
290
|
const verdict = guard.observe(call, options.getTool(call.name));
|
|
257
291
|
verdicts.set(call, verdict);
|
|
258
292
|
if (verdict === "stop") {
|
|
@@ -370,12 +404,7 @@ export async function runSingleToolCall(call, assistant, options, signal, nested
|
|
|
370
404
|
event.type === "tool_execution_end"
|
|
371
405
|
? { ...event, parentToolCallId }
|
|
372
406
|
: event);
|
|
373
|
-
await emit(
|
|
374
|
-
type: "tool_execution_start",
|
|
375
|
-
toolCallId: call.id,
|
|
376
|
-
toolName: call.name,
|
|
377
|
-
args: call.arguments,
|
|
378
|
-
});
|
|
407
|
+
await emit(startEvent(call, options.getNestedTool?.(call.name) ?? options.getTool(call.name)));
|
|
379
408
|
const prepared = await prepare(call, assistant, options, signal, nested.parent);
|
|
380
409
|
const result = prepared.kind === "immediate"
|
|
381
410
|
? prepared.result
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -169,6 +169,10 @@ export type SessionEvent = {
|
|
|
169
169
|
toolCallId: string;
|
|
170
170
|
toolName: string;
|
|
171
171
|
args: unknown;
|
|
172
|
+
/**
|
|
173
|
+
* 宽松强转改了模型原始参数时,实际交给门禁与工具的参数(`args` 仍是模型原样);没强转不带。
|
|
174
|
+
*/
|
|
175
|
+
coercedArguments?: Record<string, unknown>;
|
|
172
176
|
parentToolCallId?: string;
|
|
173
177
|
} | {
|
|
174
178
|
type: "tool_execution_update";
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* 未写明接受,不发未知 beta 头最稳);不在表里的主机(中转)只对 `claude*` 模型开——中转转发 Claude
|
|
10
10
|
* 时仍需要交错思考。
|
|
11
11
|
* - `sendCacheControl`:缺省开;DeepSeek 文档写明 `cache_control` 被忽略,关掉以减小请求体。
|
|
12
|
+
* - `messageThreads`:只有官方端点开;第三方与中转一律关(不认 `thread` 字段的网关会丢掉它,续接就变成
|
|
13
|
+
* 缺前文的请求),要开的中转显式写 `compat.messageThreads: true`。
|
|
12
14
|
* - `adaptiveThinking` 只由目录 / 配置给(官方模型逐条写在 catalog/anthropic.json),表里不推断。
|
|
13
15
|
* - 缓存保留层级(1h TTL)等缓存能力在 cache-params.ts 的 `HOST_CACHE_CAPABILITIES`,不在这里。
|
|
14
16
|
* - OpenRouter:流式 usage 只出现在 `message_delta`,`applyAnthropicUsage` 本就按非 null 字段合并,
|
|
@@ -18,7 +20,7 @@
|
|
|
18
20
|
*/
|
|
19
21
|
import type { AnthropicMessagesCompat, Model, ProviderData } from "../types.js";
|
|
20
22
|
export type ResolvedAnthropicCompat = Required<AnthropicMessagesCompat>;
|
|
21
|
-
export declare const ANTHROPIC_COMPAT_KEYS: readonly ["supportsCacheControlOnTools", "supportsTemperatureWithThinking", "adaptiveThinking", "maxCacheBreakpoints", "sendInterleavedThinkingBeta", "sendCacheControl"];
|
|
23
|
+
export declare const ANTHROPIC_COMPAT_KEYS: readonly ["supportsCacheControlOnTools", "supportsTemperatureWithThinking", "adaptiveThinking", "maxCacheBreakpoints", "sendInterleavedThinkingBeta", "sendCacheControl", "messageThreads"];
|
|
22
24
|
/** 未知主机的保守缺省(`sendInterleavedThinkingBeta` 另按模型 id 定,见 `hostDefaults`)。 */
|
|
23
25
|
export declare const DEFAULT_ANTHROPIC_COMPAT: Readonly<ResolvedAnthropicCompat>;
|
|
24
26
|
export interface AnthropicHostRule {
|