@armadra/agent 0.17.3 → 0.19.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 +50 -0
- package/CHANGELOG.zh-CN.md +50 -0
- package/README.md +4 -0
- package/README.zh-CN.md +4 -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 +29964 -27673
- package/dist/cli/bootstrap.js +32 -6
- package/dist/cli/compose-agents.js +2 -1
- package/dist/cli/compose-extensions-load.d.ts +20 -0
- package/dist/cli/compose-extensions-load.js +38 -0
- package/dist/cli/compose.js +1 -0
- package/dist/cli/deps.d.ts +11 -0
- package/dist/cli/runtime.d.ts +7 -0
- package/dist/cli/subcommands/config.d.ts +3 -0
- package/dist/cli/subcommands/config.js +22 -7
- package/dist/cli/subcommands/doctor.js +34 -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/extension-tree-hash.d.ts +31 -0
- package/dist/config/extension-tree-hash.js +88 -0
- package/dist/config/extension-trust.d.ts +70 -0
- package/dist/config/extension-trust.js +112 -0
- package/dist/config/json-schema.js +3 -1
- package/dist/config/key-docs.js +7 -1
- package/dist/config/profile.d.ts +2 -0
- package/dist/config/profile.js +1 -0
- package/dist/config/schema-trust.d.ts +7 -0
- package/dist/config/schema-trust.js +46 -0
- package/dist/config/schema.d.ts +4 -5
- package/dist/config/schema.js +7 -27
- package/dist/config/settings-registry.js +2 -0
- package/dist/config/trust.d.ts +2 -0
- package/dist/config/trust.js +5 -1
- package/dist/config/types.d.ts +23 -0
- package/dist/config/types.js +1 -0
- package/dist/drivers/host-runners.d.ts +15 -4
- package/dist/drivers/host-runners.js +31 -17
- package/dist/errors.d.ts +1 -1
- package/dist/host/api-impl.d.ts +47 -4
- package/dist/host/api-impl.js +181 -20
- package/dist/host/commands.d.ts +23 -0
- package/dist/host/commands.js +76 -0
- package/dist/host/extensions.d.ts +43 -0
- package/dist/host/extensions.js +117 -0
- package/dist/host/resources.d.ts +2 -0
- package/dist/host/resources.js +5 -0
- package/dist/host/types.d.ts +41 -2
- package/dist/host/types.js +4 -2
- package/dist/i18n/catalog.d.ts +39 -0
- package/dist/i18n/messages/cli.d.ts +24 -0
- package/dist/i18n/messages/cli.js +24 -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/drivers.d.ts +22 -0
- package/dist/i18n/messages/drivers.js +22 -0
- package/dist/i18n/messages/errors.d.ts +1 -1
- package/dist/i18n/messages/interactive-startup.d.ts +4 -0
- package/dist/i18n/messages/interactive-startup.js +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 +6 -0
- package/dist/i18n/messages/report.d.ts +14 -0
- package/dist/i18n/messages/report.js +14 -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/acp/acp-config.d.ts +4 -2
- package/dist/modes/acp/acp-config.js +17 -3
- package/dist/modes/acp/acp-events.d.ts +2 -0
- package/dist/modes/acp/acp-events.js +4 -0
- package/dist/modes/acp/acp-server.js +6 -2
- package/dist/modes/acp/acp-sessions.d.ts +8 -1
- package/dist/modes/acp/acp-sessions.js +18 -0
- package/dist/modes/commands-core.d.ts +14 -1
- package/dist/modes/commands-core.js +34 -2
- package/dist/modes/interactive/startup-ui.js +21 -0
- package/dist/modes/interactive/status-area.js +1 -1
- package/dist/modes/interactive/tool-view.d.ts +8 -2
- package/dist/modes/interactive/tool-view.js +12 -5
- package/dist/modes/print/print-mode.d.ts +3 -0
- package/dist/modes/print/print-mode.js +35 -8
- package/dist/modes/rpc/commands.d.ts +2 -0
- package/dist/modes/rpc/commands.js +22 -7
- package/dist/modes/rpc/rpc-mode.js +3 -0
- package/dist/modes/startup-ui-text.js +11 -0
- package/dist/rpc.d.ts +2 -1
- package/dist/session/unclean-end.d.ts +8 -0
- package/dist/session/unclean-end.js +39 -7
- package/dist/tools/registry.d.ts +6 -0
- package/dist/tools/registry.js +13 -0
- package/dist/tools/types.d.ts +7 -0
- package/docs/README.md +1 -1
- package/docs/en/README.md +3 -3
- package/docs/en/guides/extensions.md +141 -0
- package/docs/en/guides/providers.md +27 -7
- package/docs/en/guides/tui.md +1 -1
- package/docs/en/reference/acp.md +1 -1
- package/docs/en/reference/host-api.md +55 -27
- package/docs/en/reference/rpc.md +12 -8
- package/docs/guides/codemode.md +52 -12
- package/docs/guides/extensions.md +136 -0
- package/docs/guides/providers.md +21 -1
- package/docs/guides/sandbox.md +2 -0
- package/docs/guides/tui.md +1 -1
- package/docs/reference/acp.md +1 -1
- package/docs/reference/host-api.md +55 -27
- package/docs/reference/rpc.md +12 -8
- package/docs/reference/session-format.md +10 -9
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,56 @@ 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.19.0 (2026-11-16)
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **Local extensions (#301)**: user-installed host adapters, several at once, next to the `--host` adapter. They load from `<configDir>/extensions/*.{mjs,cjs}` (sorted by file name) and then profile `extensions` (absolute paths); each gets its own `HostApi` sharing the tool registry, event bus, approval broker slot, resources and warming handlers. Tool names are first-wins, instructions append to the `host` section in load order, the first `approvals.setBroker` wins, the last `cache.onWarmingDecision` wins, status keys merge; a failing extension (load, version mismatch, `create()` error or timeout) only warns and is skipped, and all are disposed in reverse order on exit. Without extensions the system prompt and tool table are unchanged. See `docs/guides/extensions.md`.
|
|
13
|
+
- **`api.commands.register` (host-api 1.4)**: host adapters and extensions register slash commands (`name`, `description`, `args?`, `run(args, ctx)` returning `{ kind: "handled", message? }` or `{ kind: "prompt", text }`), dispatched after built-in commands and before prompt templates in interactive, line and RPC modes, and listed by `/help`, completion and RPC `get_commands` (`source: "extension"`, additive; `RPC_PROTOCOL_VERSION` unchanged). Names that clash with built-ins, aliases or other commands throw. `HOST_API_MINOR` is 4.
|
|
14
|
+
- **Extensions can provide sub-agent runners (#306)**: `runners.provide` / `runners.onDone` now go through one runner registry shared by the host adapter and extensions, so `task`, `/agents` and RPC `get_agents` use extension runners with or without a host adapter (same priority as host-injected ones; the "hosted, do not spawn external CLIs" rule still depends only on the host adapter). Across modules the first provider of an id wins and a later one throws `runner_exists` (a module providing the same id again still replaces its own); `onDone` fires only for the module's own runners; a revoked extension's runners are removed. `HOST_API_MINOR` is unchanged.
|
|
15
|
+
- **Hash trust for extensions**: `trust.json` gains an optional `extensions` section recording `{ path, sha256, trusted, at }`; interactive startup asks once for new or changed files (path and sha256), non-interactive runs skip untrusted extensions with a warning, `--no-trust` loads none, and `trustProject` does not apply. `ama doctor` lists enabled and skipped extensions with hash prefixes and reasons without running their code.
|
|
16
|
+
- **Directory extensions (#305)**: `<configDir>/extensions/<name>/index.{mjs,cjs}` loads next to single-file extensions (sorted together by entry name), and a profile `extensions` entry may be a directory. A directory extension is trusted by the sha256 of its whole tree: regular files sorted by forward-slash relative path, each hashed as relative path plus content with length prefixes, nothing skipped (`.git` included), symlinks followed and hashed by target content (cyclic or dangling links count as unreadable). More than 2000 files, 2000 directories, 32 levels or 50 MiB skips the extension with its own reason. The `trust.json` entry shape is unchanged; a change to any nested file asks again, and the interactive prompt and `ama doctor` mark directories. Single-file behaviour is unchanged.
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- **Extension activation failures are rolled back (#304)**: when an extension's `create()` throws, times out or returns no adapter, its tools (and tool disables), event subscriptions, commands, instructions, status keys, warming handlers, broker (if it owns the slot), runners and resources are revoked, and later registration calls from that module (such as late ones after a timeout) are ignored with a warning. The system prompt and tool table end up byte-identical to running without it. Host adapter failure rules are unchanged.
|
|
21
|
+
|
|
22
|
+
- **Extension slash commands in `-p` and ACP (#303)**: a `-p` prompt or ACP `session/prompt` that is entirely `/name args` and matches an extension command is dispatched inside ama. `handled` prints `message` to stdout and exits 0 (`json` and `stream-json` print one `result` object) or, in ACP, emits it as an `agent_message_chunk` and ends with `end_turn`, with no model turn; `prompt` sends its `text`; a throwing command exits 1 in `-p` and answers an internal error in ACP. ACP `available_commands_update` lists extension commands (`args` as `input.hint`), shadowing same-name prompt templates. In `-p`, only a command-line prompt is dispatched: with piped stdin the text goes to the model unchanged.
|
|
23
|
+
|
|
24
|
+
### Maintenance
|
|
25
|
+
|
|
26
|
+
- **Host API docs**: the minor-version table now says minor 2 and 3 first shipped in 0.16.0 (they were still marked unreleased). The local-extensions design draft became a current-state guide (`docs/guides/extensions.md`, with an English translation).
|
|
27
|
+
|
|
28
|
+
## 0.18.0 (2026-11-15)
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
|
|
32
|
+
- **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.
|
|
33
|
+
- **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.
|
|
34
|
+
- **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.
|
|
35
|
+
- **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.
|
|
36
|
+
- **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).
|
|
37
|
+
- **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.
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
|
|
41
|
+
- **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.
|
|
42
|
+
- **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.
|
|
43
|
+
- **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.
|
|
44
|
+
- **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.
|
|
45
|
+
|
|
46
|
+
### Fixed
|
|
47
|
+
|
|
48
|
+
- **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).
|
|
49
|
+
|
|
50
|
+
### Model efficiency
|
|
51
|
+
|
|
52
|
+
- **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`.
|
|
53
|
+
|
|
54
|
+
### Maintenance
|
|
55
|
+
|
|
56
|
+
- **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.
|
|
57
|
+
|
|
8
58
|
## 0.17.3 (2026-11-13)
|
|
9
59
|
|
|
10
60
|
### Maintenance
|
package/CHANGELOG.zh-CN.md
CHANGED
|
@@ -4,6 +4,56 @@
|
|
|
4
4
|
|
|
5
5
|
> 从 0.6.0 起 [CHANGELOG.md](CHANGELOG.md) 为英文,本文件保留中文记录(0.1–0.5.1 的完整历史在此)。新条目两份都要加。
|
|
6
6
|
|
|
7
|
+
## 0.19.0(2026-11-16)
|
|
8
|
+
|
|
9
|
+
### 新增
|
|
10
|
+
|
|
11
|
+
- **本地扩展(#301)**:用户自己安装、可以有多个的宿主适配器,与 `--host` 适配器并存。从 `<configDir>/extensions/*.{mjs,cjs}`(按文件名排序)与 profile 的 `extensions`(绝对路径)依次加载;每个模块有独立的 `HostApi`,共享工具注册表、事件总线、审批 broker 槽、资源注册表与保温处理器。工具名先到先得,指令按加载顺序追加到 `host` 节,`approvals.setBroker` 第一个设置者生效,`cache.onWarmingDecision` 最后注册者生效,状态键合并;扩展加载失败、版本不等、`create()` 报错或超时只记 warning 并跳过,退出时按加载逆序全部 dispose。没有扩展时系统提示与工具表不变。见 `docs/guides/extensions.md`。
|
|
12
|
+
- **`api.commands.register`(host-api 1.4)**:宿主适配器与扩展注册斜杠命令(`name`、`description`、`args?`、`run(args, ctx)` 返回 `{ kind: "handled", message? }` 或 `{ kind: "prompt", text }`),在内置命令之后、提示模板之前分派,交互、line、RPC 三种模式可用,`/help`、补全与 RPC `get_commands`(`source: "extension"`,只加不改,`RPC_PROTOCOL_VERSION` 不变)列出。与内置命令、别名或已注册命令同名时注册抛错。`HOST_API_MINOR` 为 4。
|
|
13
|
+
- **扩展可注入子 Agent runner(#306)**:`runners.provide` / `runners.onDone` 改走宿主适配器与扩展共用的一张 runner 表,`task`、`/agents` 与 RPC `get_agents` 无论有无宿主适配器都使用扩展的 runner(与宿主注入的同等优先;“有宿主时不自起外部 CLI”的判定仍只看宿主适配器)。不同模块之间同 id 先到先得,后来者抛 `runner_exists`(同一模块再次提供仍替换自己的);`onDone` 只回调本模块的 runner;被撤回的扩展其 runner 一并移除。`HOST_API_MINOR` 不变。
|
|
14
|
+
- **扩展按哈希信任**:`trust.json` 新增可选的 `extensions` 段,记录 `{ path, sha256, trusted, at }`;交互启动对新文件或内容变化的文件询问一次(列出路径与 sha256),非交互运行跳过未信任的扩展并 warning,`--no-trust` 一个都不加载,`trustProject` 不适用。`ama doctor` 列出已启用与被跳过的扩展、哈希前缀与原因,不执行扩展代码。
|
|
15
|
+
- **目录扩展(#305)**:`<configDir>/extensions/<名>/index.{mjs,cjs}` 与单文件扩展一起(按入口名排序)加载,profile 的 `extensions` 也可以给目录。目录扩展按整棵树的 sha256 信任:每个常规文件按正斜杠相对路径排序,相对路径与内容带长度前缀一起计入,不跳过任何项(包括 `.git`),符号链接跟随、按目标内容计入(成环或断开的按读不了处理)。超过 2000 个文件、2000 个目录、32 层或 50 MiB 时跳过该扩展并给出单独的原因。`trust.json` 记录形状不变;任一嵌套文件变化都重新询问,交互询问与 `ama doctor` 标出目录。单文件扩展行为不变。
|
|
16
|
+
|
|
17
|
+
### 修复
|
|
18
|
+
|
|
19
|
+
- **扩展激活失败时撤回已注册内容(#304)**:扩展的 `create()` 抛错、超时或没有返回适配器时,它注册的工具(及工具禁用)、事件订阅、命令、指令、状态键、保温处理器、broker(自己持有槽位时)、runner 与资源都会撤回;该模块之后再调用注册类方法(如超时后迟到的注册)一律忽略并 warning。系统提示与工具表回到没有该扩展时逐字节相同。宿主适配器的失败规则不变。
|
|
20
|
+
|
|
21
|
+
- **`-p` 与 ACP 分派扩展斜杠命令(#303)**:`-p` 的提示或 ACP `session/prompt` 的文本整段形如 `/名 参数` 且命中扩展命令时在 ama 内分派。`handled` 把 `message` 写到 stdout 并退出 0(`json` 与 `stream-json` 给一行 `result` 对象),ACP 下则作为 `agent_message_chunk` 发出并以 `end_turn` 结束,都不开模型回合;`prompt` 改发其 `text`;命令抛错时 `-p` 退出 1,ACP 答复 internal error。ACP 的 `available_commands_update` 列出扩展命令(`args` 作 `input.hint`),遮住同名提示模板。`-p` 只分派命令行给的提示,有管道 stdin 时原样发给模型。
|
|
22
|
+
|
|
23
|
+
### 维护
|
|
24
|
+
|
|
25
|
+
- **宿主 API 文档**:小版本表里 2、3 原标「未发布」,实际在 0.16.0 已发布,已更正。本地扩展设计草案改为现状指南(`docs/guides/extensions.md`,附英文译本)。
|
|
26
|
+
|
|
27
|
+
## 0.18.0(2026-11-15)
|
|
28
|
+
|
|
29
|
+
### 新增
|
|
30
|
+
|
|
31
|
+
- **codemode 脚本**:脚本里 `tools.bash` 的 `output` 放宽到 1 MiB(更长时保留首尾各 512 KiB,中间是省略说明,`truncated` 为真,`fullOutputPath` 指向全文);模型直接调用 bash 的结果不变。
|
|
32
|
+
- **codemode 并发上限**:整个进程(所有会话)同时存活的沙箱子进程至多 2 个(`codemode.maxWorkers`,环境变量 `AMA_CODEMODE_MAX_WORKERS` 优先);多出的脚本先来先到排队,最多等 60 s 或到自己的 `timeout_ms`(等待计入),到点失败且不运行。名额在子进程真正退出时归还。
|
|
33
|
+
- **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()` 可直接收的图片块。
|
|
34
|
+
- **脚本被杀后的恢复**:已完成的内层调用记为 `ama.codemode-call` 自定义条目(可选条目,会话格式版本不变);进程在脚本中途被杀后,resume 的恢复提醒列出它们并要求不要盲目重复。
|
|
35
|
+
- **提示预算**:`codemode-only` 预设的预算由 1950 放宽到 2000 token(实测 1937 → 1982),用于两个新全局函数的描述;`default` 增加约 26 token(1607 → 1633)。
|
|
36
|
+
- **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` 显示生效的引擎与原因。
|
|
37
|
+
|
|
38
|
+
### 变更
|
|
39
|
+
|
|
40
|
+
- **实际执行的参数可见**:宽松强转改了工具调用的参数时,`tool_execution_start` 多一个可选字段 `coercedArguments`(门禁、钩子与工具实际拿到的参数;`args` 仍是模型原样)。RPC 事件带上它(协议版本不变,ACP 线上形状不变),交互界面的工具行显示实际执行的参数并带淡色「(参数已调整)」标记。
|
|
41
|
+
- **QuickJS 递归**:QuickJS 下脚本的无界递归现在抛出可捕获的 `RangeError: Maximum call stack size exceeded`(JS 栈上限 320 KB,约 1300 层简单调用),与 Node 引擎一致;绕过 JS 栈检查的原生递归(超深 JSON)仍会让实例陷阱,脚本以同一句 `RangeError` 开头的错误结束,此前的输出保留。
|
|
42
|
+
- **codemode `image()`**:校验(按文件头认 MIME、base64、最多 8 张)合并进两个引擎共用的引导脚本,不再有两份拷贝;行为与文案不变。
|
|
43
|
+
- **工具参数宽松强转**:严格校验失败后,按 schema 强转一次再校验(数字串 → 数字、`"true"`/`"false"` → 布尔、数字/布尔 → 字符串、单值 → 单元素数组、JSON 字符串 → 对象/数组、丢弃可选属性的 `null`);enum 仍须严格匹配,不填默认值。权限管线、钩子与工具看到强转后的参数,助手消息与会话历史保留模型原始调用;codemode 内部调用同样适用。
|
|
44
|
+
|
|
45
|
+
### 修复
|
|
46
|
+
|
|
47
|
+
- **消息线程回落**:线程请求被判为不支持(错误码、点名 `thread` 的 400,或端点拒收 beta 头的值)时,重发的整请求现在同时去掉 `thread` 与线程 beta 头,并让该会话与该端点 + 模型在本进程内不再用线程,其它会话不再多吃一次 400。fork 出的会话现在续接自己的线程(新增流选项 `threadKey`,缺省 `sessionId`),提示缓存键仍与根会话共用。新增手工实测脚本 `scripts/verify-anthropic-threads.mjs`(真 key,不进 CI)。
|
|
48
|
+
|
|
49
|
+
### 模型调用效率
|
|
50
|
+
|
|
51
|
+
- **Anthropic 消息线程(message threads)**:带稳定会话 id 且 `cacheRetention` 不是 `none` 的请求,改为在服务端续接上一条回复(beta `message-threads-2026-08-12`),只发新增消息,不再重发整段对话。压缩、回退与分支切换,以及模型、系统提示、工具、思考级别变化时回落为整请求并新开线程;线程不存在之类的拒收同样整请求重发一次。只有 `api.anthropic.com` 缺省开启,可用 `compat.messageThreads` 调整。新增流选项 `disableContinuation`,使请求不使用也不替换线程状态;缓存保温与压缩摘要都会置位。token 用量与缓存上报不变。详见 `docs/guides/providers.md`。
|
|
52
|
+
|
|
53
|
+
### 维护
|
|
54
|
+
|
|
55
|
+
- **刷新 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 时判失败。
|
|
56
|
+
|
|
7
57
|
## 0.17.3(2026-11-13)
|
|
8
58
|
|
|
9
59
|
### 维护
|
package/README.md
CHANGED
|
@@ -231,6 +231,10 @@ pnpm run ci # typecheck, format, dependency, i18n and doc-link chec
|
|
|
231
231
|
AMA_E2E=1 pnpm test:e2e # bundle-level end-to-end tests with the free fake provider
|
|
232
232
|
```
|
|
233
233
|
|
|
234
|
+
`pnpm install` also points `core.hooksPath` at `.githooks`: before `git push`, `scripts/hooks/pre-push.mjs` checks only
|
|
235
|
+
what the push changes, the same way CI picks its jobs, and blocks the push on failure. Skip it once with
|
|
236
|
+
`git push --no-verify`, or `ARMADRA_SKIP_PREPUSH=1` (everything) / `ARMADRA_SKIP_PREPUSH=test,e2e` (named steps).
|
|
237
|
+
|
|
234
238
|
Tests use the scripted `fake` provider, never a real model. Conventions are in [AGENTS.md](AGENTS.md) and
|
|
235
239
|
[CONTRIBUTING](.github/CONTRIBUTING.md). Releases are cut by pushing a `v<version>` tag: CI creates the GitHub Release
|
|
236
240
|
and publishes to npm through trusted publishing.
|
package/README.zh-CN.md
CHANGED
|
@@ -222,6 +222,10 @@ pnpm run ci # 类型检查、格式、依赖 / i18n / 文档链接
|
|
|
222
222
|
AMA_E2E=1 pnpm test:e2e # 用免费的 fake 供应商跑 bundle 级端到端测试
|
|
223
223
|
```
|
|
224
224
|
|
|
225
|
+
`pnpm install` 同时把 `core.hooksPath` 指到 `.githooks`:`git push` 前 `scripts/hooks/pre-push.mjs` 只查这次推送带上的改动,
|
|
226
|
+
挑选规则与 CI 相同,失败就拦下推送。临时跳过用 `git push --no-verify`,或 `ARMADRA_SKIP_PREPUSH=1`(全部)/
|
|
227
|
+
`ARMADRA_SKIP_PREPUSH=test,e2e`(指定步骤)。
|
|
228
|
+
|
|
225
229
|
测试只用脚本化的 `fake` 供应商,不调真实模型。开发约定见 [AGENTS.md](AGENTS.md) 与[贡献指南](.github/CONTRIBUTING.md)。
|
|
226
230
|
发布由推送 `v<版本>` tag 触发:CI 创建 GitHub Release,并经 npm 可信发布推送。
|
|
227
231
|
|
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();
|