@deepseek-ai/dsh-tool-registry-ptc 0.2.3-alpha.3 → 0.2.3-alpha.4
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.i18n.yaml +6 -6
- package/README.md +6 -4
- package/README.zh.md +6 -4
- package/lib/index.js +237 -141
- package/lib/types/index.d.ts +7 -5
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +23 -15
- package/lib/types/index.js.map +1 -1
- package/lib/types/ptc-calls.d.ts +15 -6
- package/lib/types/ptc-calls.d.ts.map +1 -1
- package/lib/types/ptc-calls.js +32 -14
- package/lib/types/ptc-calls.js.map +1 -1
- package/lib/types/ptc.d.ts +7 -2
- package/lib/types/ptc.d.ts.map +1 -1
- package/lib/types/ptc.js +110 -29
- package/lib/types/ptc.js.map +1 -1
- package/package.json +35 -31
- package/src/index.ts +32 -17
- package/src/ptc-calls.ts +38 -15
- package/src/ptc.ts +123 -32
package/README.i18n.yaml
CHANGED
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
en: d152484eb41ac6b4
|
|
16
16
|
zh: 09388d293f9be9cb
|
|
17
17
|
/deepseek-ai-dsh-tool-registry-ptc/use-this-package:
|
|
18
|
-
en:
|
|
19
|
-
zh:
|
|
18
|
+
en: 5184050040ac622a
|
|
19
|
+
zh: 5ac0010b1e824452
|
|
20
20
|
/deepseek-ai-dsh-tool-registry-ptc/understand-the-implementation:
|
|
21
|
-
en:
|
|
22
|
-
zh:
|
|
21
|
+
en: 408579c083d4ea27
|
|
22
|
+
zh: a4e03e4fe1feb98e
|
|
23
23
|
/deepseek-ai-dsh-tool-registry-ptc/understand-the-implementation/ptc-mode:
|
|
24
|
-
en:
|
|
25
|
-
zh:
|
|
24
|
+
en: 3e9df1f0e35002c5
|
|
25
|
+
zh: 398a3065351de855
|
|
26
26
|
/deepseek-ai-dsh-tool-registry-ptc/further-exploration:
|
|
27
27
|
en: 4e6282bc80b35d6c
|
|
28
28
|
zh: f6bda6aa2c884b14
|
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ This package declares `ctx.ptcRuntime` and `ctx.systemPrompt` as required inject
|
|
|
46
46
|
|
|
47
47
|
Shared dispatch events and the `ptc-mode` message-source declaration live in `@deepseek-ai/dsh-tool-registry-ptc/types`; Client code imports the same declarations through `@deepseek-ai/dsh-tool-registry-ptc/client`. Both entries exclude Host service declarations. Host policy extensions use `import type` from the package entry for `PtcDispatchLog` and `tools/ptc-dispatch-log` without mounting the plugin.
|
|
48
48
|
|
|
49
|
-
To offer a named program tool beside the tools an Agent calls directly, construct `new PtcToolRegistry(ctx, { name, description?, runtime?, config? })`, register the tools its programs call, and include the registry with `ctx.tools.include()`. Its only entry is the program tool named `name`. Its registrations and inclusions are the bindings its programs call: programs can call only those bindings, even when the Agent can call other tools, and the bindings never enter the including scope's tools. Nested calls retain normal approvals, guards, dispatch logs, screenshots, deferred context, and turn completion. `config` accepts the same call-allowance and concurrency settings as the plugin, validated by `PtcToolRegistry.Config`.
|
|
49
|
+
To offer a named program tool beside the tools an Agent calls directly, construct `new PtcToolRegistry(ctx, { name, description?, runtime?, environment?, config? })`, register the tools its programs call, and include the registry with `ctx.tools.include()`. Its only entry is the program tool named `name`. Its registrations and inclusions are the bindings its programs call: programs can call only those bindings, even when the Agent can call other tools, and the bindings never enter the including scope's tools. Nested calls retain normal approvals, guards, dispatch logs, screenshots, deferred context, and turn completion. `config` accepts the same call-allowance and concurrency settings as the plugin, validated by `PtcToolRegistry.Config`. `environment` is the entry's `ToolDefinition.environment`; the plugin's `run_code` declares `'bound'`, and an entry whose bindings act only on this host omits it.
|
|
50
50
|
|
|
51
51
|
The caller owns a fixed `runtime` and must keep it available until the registry's context finishes disposal; without `runtime`, each program uses the context's `ptcRuntime` service. For runtimes that retain state or enforce a sandbox, disposal of that context cancels active Agent programs and waits for nested calls; Agent disposal releases its retained environment. Environment initialization belongs to the supplied [runtime's registration API](../../ptc-runtime/ptc-runtime/README.md#choose-a-backend); register it before including the program tool. `description` replaces the runtime's default entry description, and the registry appends runtime syntax and execution guidance to it; the caller supplies instructions for its bindings.
|
|
52
52
|
|
|
@@ -60,7 +60,7 @@ The caller owns a fixed `runtime` and must keep it available until the registry'
|
|
|
60
60
|
<details>
|
|
61
61
|
<summary>Implementation internals — click to expand</summary>
|
|
62
62
|
|
|
63
|
-
The plugin's `apply` calls `new PtcToolRegistry(ctx, { name: RUN_CODE_NAME, config }).mountRoot()`. `mountRoot()` selects the registry with `ctx.tools.setRoot()`, which gives it the registrations of the scope's Agents as bindings, and registers the `tools:ptc-only` and `tools:sdk` prompt sections for steps that declare the registry's entry. `ctx.tools.execute()` runs the raw call batch, including parsing, scheduling, cancellation, and optional model-step logging, and resolves each call to the registry's entry. Each program's nested calls run through the registry's own instance of the shared invocation pipeline for policy, tool bodies, and result notifications. Disposing the registry's context, such as unloading the plugin, aborts active Agent-owned programs whose runtime supports sandboxing or retains state, and waits for their nested calls to settle. Accepted batches still settle through that registry, potentially with cancellation errors.
|
|
63
|
+
The plugin's `apply` calls `new PtcToolRegistry(ctx, { name: RUN_CODE_NAME, config, environment: 'bound' }).mountRoot()`. `mountRoot()` selects the registry with `ctx.tools.setRoot()`, which gives it the registrations of the scope's Agents as bindings, and registers the `tools:ptc-only` and `tools:sdk` prompt sections for steps that declare the registry's entry. The prompt sections also apply to a step that declares an entry derived from the registry's entry through `origin`, such as a copy an environment style offers in an execution environment. `run_code` declares `environment: 'bound'`, so a program runs in the environment its call targets and its tool calls inherit it. `ctx.tools.execute()` runs the raw call batch, including parsing, scheduling, cancellation, and optional model-step logging, and resolves each call to the registry's entry. Each program's nested calls run through the registry's own instance of the shared invocation pipeline for policy, tool bodies, and result notifications. Disposing the registry's context, such as unloading the plugin, aborts active Agent-owned programs whose runtime supports sandboxing or retains state, and waits for their nested calls to settle. Accepted batches still settle through that registry, potentially with cancellation errors.
|
|
64
64
|
|
|
65
65
|
### PTC mode
|
|
66
66
|
|
|
@@ -74,11 +74,13 @@ TypeScript bindings for `read_image` and CUA screenshot operations return an `Im
|
|
|
74
74
|
|
|
75
75
|
The program entry of every PTC registry, `run_code` included, reports `outputTruncated: true` when captured output or diagnostic text was truncated. With the Node runtime, display-output overflow discards subsequent output while execution continues under the original timeout and cancellation rules. A normally completed program remains a successful tool result, with a truncation notice directing the model to read current state without repeating completed actions. A later failure keeps its actual error kind and truncation notice. Retained images and settled subcall records remain available.
|
|
76
76
|
|
|
77
|
+
When a nested tool changes the Session workspace root, the program stops and queued tools are abandoned. The switching tool can finish and deliver its result directly to the model. Caller cancellation, a subsequent sandbox mode change, environment reset, or registry unload can still cancel that tool. The next program starts in the new workspace after cleanup. If directory recovery changes the workspace during program preparation, the call returns `CODE_RUN_FAILED` before execution. Retrying uses the restored directory.
|
|
78
|
+
|
|
77
79
|
When the caller cancels and the runtime reports `abort`, `run_code` waits for cleanup and returns the native tool cancellation result: `AbortError` / `ABORTED`, with `Error: tool call aborted` as its content. Retained runtimes append their cancellation diagnostic, including whether variables were preserved or cleared. The Agent records the specific cancellation cause in `turn/end`, including a hook's reason. Runtime failures retain `CODE_RUN_FAILED` and their diagnostics, even if the caller also cancels. A runtime rejection keeps a `PtcRuntimeError` code and otherwise becomes `CODE_RUN_FAILED` with the rejection as `cause`. A blank `description`, an invalid `timeoutMs`, or `timeoutMs` or `sandbox_permissions` on a runtime that does not support it fails as `ToolArgsError` with `INVALID_ARGS`; a call after the registry's context is disposed fails with `CODE_RUN_UNAVAILABLE`; and a missing runtime, `workingDirectory`, or `sandboxPolicy` fails as `ToolContextUnavailableError`. Cancellation can discard retained runtime state and does not undo completed tool effects.
|
|
78
80
|
|
|
79
|
-
`run_code` accepts `timeoutMs` when the mounted runtime supports an override; its schema reports the configured default and maximum, and the runtime's usage instructions. The Node default is 120,000 ms with a 600,000 ms cap, including nested tool and approval waits. A wider `sandbox_permissions` mode requires a non-empty `justification` and approval before the program starts. The schema asks the model to write that reason in the current user's language. The grant applies to that complete execution; standing Session policy and nested tools retain their own authority. Programs are never replayed automatically: inspect earlier effects before explicitly retrying a denied program. Retained PTC environments follow the standing file policy. PTC observes committed Session mode changes and immediately cancels affected calls in all Node modes. Later PTC calls wait for their nested-tool cleanup before resolving the latest policy.
|
|
81
|
+
`run_code` accepts `timeoutMs` when the mounted runtime supports an override; its schema reports the configured default and maximum, and the runtime's usage instructions. The Node default is 120,000 ms with a 600,000 ms cap, including nested tool and approval waits. A wider `sandbox_permissions` mode requires a non-empty `justification` and approval before the program starts. The schema asks the model to write that reason in the current user's language. The grant applies to that complete execution; standing Session policy and nested tools retain their own authority. Programs are never replayed automatically: inspect earlier effects before explicitly retrying a denied program. Retained PTC environments follow the standing file policy. PTC observes committed Session mode changes and immediately cancels affected calls in all Node modes. Later PTC calls wait for their nested-tool cleanup before resolving the latest policy. One-time escalations omit the state owner and complete in a temporary environment; standing variables remain available to ordinary calls.
|
|
80
82
|
|
|
81
|
-
Custom host integrations that mount their own root through `mountRoot()` retain the `PtcToolRegistry` instance and call `reset(agent)` to clear that Agent's environment; reset is not a model tool or SDK binding. It requires a state-retaining runtime, cancels active calls, invokes `release(agent)`, and waits for process and started nested-tool cleanup without requiring the program to respond.
|
|
83
|
+
Custom host integrations that mount their own root through `mountRoot()` retain the `PtcToolRegistry` instance and call `reset(agent)` to clear that Agent's environment; reset is not a model tool or SDK binding. It requires a state-retaining runtime, cancels active calls, invokes `release(agent)`, and waits for process and started nested-tool cleanup without requiring the program to respond. When the runtime reports losing an environment, `agent/pre-step` checks whether the Agent can currently call the program directly or through an SDK binding. If so, the step records a reminder to recreate variables and object handles and check completed external actions before repeating them. The Agent keeps the reminder pending across provider reloads and cancelled steps until it enters Session history. An Agent starting with history receives the same reminder on the first model step that offers the program because its new state owner starts empty. Concurrent resets share cleanup. Missing or unsupported runtimes reject without blocking admission. Cleanup failure throws `CodeResetFailedError`; later programs report `CodeRunFailedError` with host-reset guidance until an explicit retry succeeds. Reset does not undo completed tool effects.
|
|
82
84
|
|
|
83
85
|
- [`src/index.ts`](src/index.ts) — `PtcToolRegistry` and its `mountRoot()`, the root plugin, step-pinned bindings, and host environment reset.
|
|
84
86
|
- [`src/ptc.ts`](src/ptc.ts) — The program entry: schema text, runtime checks, nested bindings, and result projection.
|
package/README.zh.md
CHANGED
|
@@ -46,7 +46,7 @@ kind: "package-reference"
|
|
|
46
46
|
|
|
47
47
|
共享分派事件与 `ptc-mode` 消息来源声明位于 `@deepseek-ai/dsh-tool-registry-ptc/types`;Client 代码通过 `@deepseek-ai/dsh-tool-registry-ptc/client` 导入同一组声明。两个入口都不引入 Host 服务声明。Host 策略扩展通过包主入口的 `import type` 获取 `PtcDispatchLog` 与 `tools/ptc-dispatch-log`,无需挂载该插件。
|
|
48
48
|
|
|
49
|
-
要在 Agent 直接调用的工具旁提供一个具名程序工具,构造 `new PtcToolRegistry(ctx, { name, description?, runtime?, config? })`,注册其程序调用的工具,再用 `ctx.tools.include()` 引入该注册表。它的唯一条目是名为 `name` 的程序工具。它的注册与引入就是其程序调用的绑定:即使 Agent 能调用其他工具,程序也只能调用这些绑定,而且这些绑定绝不会进入引入方作用域的工具。嵌套调用保留正常审批、guard、派发日志、截图、延后上下文和轮次结束行为。`config` 接受与本插件相同的调用额度与并发设置,由 `PtcToolRegistry.Config`
|
|
49
|
+
要在 Agent 直接调用的工具旁提供一个具名程序工具,构造 `new PtcToolRegistry(ctx, { name, description?, runtime?, environment?, config? })`,注册其程序调用的工具,再用 `ctx.tools.include()` 引入该注册表。它的唯一条目是名为 `name` 的程序工具。它的注册与引入就是其程序调用的绑定:即使 Agent 能调用其他工具,程序也只能调用这些绑定,而且这些绑定绝不会进入引入方作用域的工具。嵌套调用保留正常审批、guard、派发日志、截图、延后上下文和轮次结束行为。`config` 接受与本插件相同的调用额度与并发设置,由 `PtcToolRegistry.Config` 校验。`environment` 是该条目的 `ToolDefinition.environment`;本插件的 `run_code` 声明 `'bound'`,而绑定只作用于本主机的条目省略它。
|
|
50
50
|
|
|
51
51
|
调用方拥有固定的 `runtime`,必须使其可用至注册表的上下文完成销毁;未提供 `runtime` 时,每个程序使用该上下文的 `ptcRuntime` 服务。对于保留状态或实施沙箱的运行时,销毁该上下文会取消活动的 Agent 程序并等待嵌套调用;Agent 销毁时释放其保留环境。环境初始化由传入[运行时的注册 API](../../ptc-runtime/ptc-runtime/README.zh.md#choose-a-backend)负责;应在引入程序工具前完成注册。`description` 替换运行时默认的条目描述,注册表再把运行时语法和执行说明追加到其后;其绑定的说明由调用方提供。
|
|
52
52
|
|
|
@@ -60,7 +60,7 @@ kind: "package-reference"
|
|
|
60
60
|
<details>
|
|
61
61
|
<summary>实现细节——点击展开</summary>
|
|
62
62
|
|
|
63
|
-
插件的 `apply` 调用 `new PtcToolRegistry(ctx, { name: RUN_CODE_NAME, config }).mountRoot()`。`mountRoot()` 通过 `ctx.tools.setRoot()` 选择该注册表,`setRoot()` 把该作用域中 Agent 的注册项作为绑定交给它;`mountRoot()` 还为声明该注册表条目的步骤注册 `tools:ptc-only` 与 `tools:sdk`
|
|
63
|
+
插件的 `apply` 调用 `new PtcToolRegistry(ctx, { name: RUN_CODE_NAME, config, environment: 'bound' }).mountRoot()`。`mountRoot()` 通过 `ctx.tools.setRoot()` 选择该注册表,`setRoot()` 把该作用域中 Agent 的注册项作为绑定交给它;`mountRoot()` 还为声明该注册表条目的步骤注册 `tools:ptc-only` 与 `tools:sdk` 提示词段落。若步骤声明的条目经 `origin` 派生自本注册表的条目(例如环境风格在执行环境中提供的副本),提示词段落同样生效。`run_code` 声明 `environment: 'bound'`,因此程序在其调用所指向的环境中运行,程序内的工具调用继承该环境。`ctx.tools.execute()` 运行原始调用批次,包括参数解析、调度、取消和可选的模型步骤日志,并把每个调用解析到该注册表的条目。每个程序的嵌套调用经由该注册表自有的共享调用流水线实例运行,以执行策略、工具主体和结果通知。销毁注册表的上下文(例如卸载插件)会中止 Agent 在支持沙箱或保留状态的运行时中执行的程序,并等待其嵌套调用结束。已接纳批次仍由该注册表结算,但可能返回取消错误。
|
|
64
64
|
|
|
65
65
|
### PTC mode
|
|
66
66
|
|
|
@@ -74,11 +74,13 @@ TypeScript 中的 `read_image` 与 CUA 截图操作返回 `Image`,其中包含
|
|
|
74
74
|
|
|
75
75
|
每个 PTC 注册表的程序入口(包括 `run_code`)在捕获输出或诊断文本被截断时报告 `outputTruncated: true`。使用 Node 运行时时,展示输出超限会丢弃后续输出,执行仍受原有超时和取消规则约束。正常结束的程序仍是成功工具结果,并提示输出已截断,应读取当前状态而不重复已完成的动作。后续失败保留实际错误类型和截断提示。已保留的图片与已结算的子调用记录仍然可用。
|
|
76
76
|
|
|
77
|
+
嵌套工具切换 Session 的工作区根目录时,程序停止,队列中尚未启动的工具被取消。发起切换的工具可以继续执行,并将结果直接交给模型。调用方取消、后续的沙箱模式变更、环境重置或注册表卸载仍可取消该工具。清理完成后,下一个程序在新工作区启动。如果准备程序时因目录恢复而切换工作区,本次调用会在执行前返回 `CODE_RUN_FAILED`,重试会使用恢复后的目录。
|
|
78
|
+
|
|
77
79
|
调用方取消且运行时报告 `abort` 时,`run_code` 等待清理完成,并返回原生工具的取消结果:`AbortError` / `ABORTED`,内容为 `Error: tool call aborted`。保留状态的运行时会附加取消诊断,包括变量被保留还是清空。Agent 在 `turn/end` 中记录具体取消原因,包括 hook 的理由。运行时失败保留 `CODE_RUN_FAILED` 及其诊断,即使调用方同时取消。运行时拒绝保留 `PtcRuntimeError` 的 code,否则变为 `CODE_RUN_FAILED` 并以该拒绝为 `cause`。`description` 为空白、`timeoutMs` 无效,或运行时不支持却传入 `timeoutMs` 或 `sandbox_permissions` 时,以带 `INVALID_ARGS` 的 `ToolArgsError` 失败;注册表的上下文销毁后,调用以 `CODE_RUN_UNAVAILABLE` 失败;缺少运行时、`workingDirectory` 或 `sandboxPolicy` 时以 `ToolContextUnavailableError` 失败。取消可能丢弃保留的运行时状态,也不会撤销已完成的工具操作。
|
|
78
80
|
|
|
79
|
-
当已挂载运行时支持覆盖时,`run_code` 接受 `timeoutMs`;其 schema 报告配置的默认值和上限以及运行时使用说明。Node 默认值为 120,000 ms,上限为 600,000 ms,包含嵌套工具和审批等待。更宽的 `sandbox_permissions` 模式要求非空 `justification`,并在程序启动前获得审批。schema 提示模型使用当前用户的语言撰写理由。授权仅用于该次完整执行;常驻 Session 策略与嵌套工具保留各自权限。程序不会自动重放:显式重试被拒程序前,应检查先前已发生的效果。 保留状态的 PTC 环境遵循会话文件策略。PTC 观察已提交的 Session 模式变化,并立即取消所有 Node 模式下受影响的调用。后续 PTC
|
|
81
|
+
当已挂载运行时支持覆盖时,`run_code` 接受 `timeoutMs`;其 schema 报告配置的默认值和上限以及运行时使用说明。Node 默认值为 120,000 ms,上限为 600,000 ms,包含嵌套工具和审批等待。更宽的 `sandbox_permissions` 模式要求非空 `justification`,并在程序启动前获得审批。schema 提示模型使用当前用户的语言撰写理由。授权仅用于该次完整执行;常驻 Session 策略与嵌套工具保留各自权限。程序不会自动重放:显式重试被拒程序前,应检查先前已发生的效果。 保留状态的 PTC 环境遵循会话文件策略。PTC 观察已提交的 Session 模式变化,并立即取消所有 Node 模式下受影响的调用。后续 PTC 调用等待这些调用的嵌套工具清理后,再解析最新策略。单次提权省略状态所有者,在临时环境中执行;普通调用仍可访问原环境的变量。
|
|
80
82
|
|
|
81
|
-
通过 `mountRoot()` 挂载自有根注册表的自定义宿主集成保留该 `PtcToolRegistry` 实例,并调用 `reset(agent)` 清空该 Agent 的环境;重置不是模型工具或 SDK 绑定。该操作要求运行时保留状态,会取消活动调用、调用 `release(agent)
|
|
83
|
+
通过 `mountRoot()` 挂载自有根注册表的自定义宿主集成保留该 `PtcToolRegistry` 实例,并调用 `reset(agent)` 清空该 Agent 的环境;重置不是模型工具或 SDK 绑定。该操作要求运行时保留状态,会取消活动调用、调用 `release(agent)`,并等待进程及已启动嵌套工具的清理,无需程序响应。运行时报告持久环境失效后,`agent/pre-step` 检查 Agent 当前能否直接或通过 SDK 绑定调用该程序。如果可以,该步骤会记录一条提醒,要求重新创建变量和对象句柄,并先检查已完成的外部操作再决定是否重做。即使提供方重新加载或步骤被取消,Agent 也会保留待投递的提醒,直到它写入 Session 历史。Agent 带历史启动时,新的状态所有者从空环境开始,模型首次能调用该程序时也会收到这条提醒。并发重置共享清理过程。运行时缺失或不受支持时,操作拒绝但不阻止后续准入。清理失败会抛出 `CodeResetFailedError`;后续程序报告带宿主重置指引的 `CodeRunFailedError`,直到显式重试成功。重置不会撤销已完成的工具操作。
|
|
82
84
|
|
|
83
85
|
- [`src/index.ts`](src/index.ts) — `PtcToolRegistry` 及其 `mountRoot()`、根注册表插件、按步骤固定的绑定与宿主环境重置。
|
|
84
86
|
- [`src/ptc.ts`](src/ptc.ts) — 程序入口:schema 文本、运行时检查、嵌套绑定与结果投影。
|