feat(typert): make RemoteError a HarnessError
RemoteError extended plain Error because dsh-llm, which owned HarnessError, depends on dsh-typert-protocol. With HarnessError in the dependency-free dsh-error package, RemoteError now extends it and keeps its name, Remote code, details, and constructor, so a tool body that throws one records name RemoteError and its code on tool/result. An unknown or unloadable delegation preset therefore keeps the registry's agent-preset/not-found or agent-preset/invalid identity, and the subagent runtime no longer rewraps it as PRESET_UNAVAILABLE. Client bundles inline dsh-error with the protocol layer; no client code depends on HarnessError identity. Refs #7869
This commit is contained in:
1 parent
1440cf2fb9
commit
de273ffe2d
22 files changed
+84
-55
No files matched your search
+2
-2
@@ -9,8 +9,8 @@
|
||||
en: 990d46f713fb6303
|
||||
zh: 592cd6128a9640b1
|
||||
/agent-note-one-remote-failure-vocabulary-for-ctx-remote/decision:
|
||||
en: 120e2fb97ac765d8
|
||||
zh: 5d5f110db4a9b717
|
||||
en: b54b9d98a34eeaa1
|
||||
zh: ac8e3d493b554c2d
|
||||
/agent-note-one-remote-failure-vocabulary-for-ctx-remote/code-ownership:
|
||||
en: cc1d8b88f7349b77
|
||||
zh: 70f010e3310e2667
|
||||
|
||||
@@ -16,12 +16,12 @@ Fixed Host facts bypassed `ctx.remote` too: the Host home came from `(ctx.get('c
|
||||
|
||||
## Decision
|
||||
|
||||
`@deepseek-ai/dsh-typert-protocol` exports one failure class, `RemoteError<Code>`: a real `Error` carrying readonly `code` and `details`, the structural marker `isDSHRemoteError`, and standard `ErrorOptions` (`cause` holds in-process only). The correspondence between codes and details lives in one merge-extensible `RemoteErrorDetailsMap`; `RemoteFailure` is the code-distributed union of instances, and `RemoteResult<T>` keeps its shape.
|
||||
`@deepseek-ai/dsh-typert-protocol` exports one failure class, `RemoteError<Code>`: a `HarnessError` from the dependency-free `@deepseek-ai/dsh-error` carrying readonly `code` and `details`, the structural marker `isDSHRemoteError`, and standard `ErrorOptions` (`cause` holds in-process only). The correspondence between codes and details lives in one merge-extensible `RemoteErrorDetailsMap`; `RemoteFailure` is the code-distributed union of instances, and `RemoteResult<T>` keeps its shape.
|
||||
|
||||
```text
|
||||
export class RemoteError<Code extends RemoteErrorCode = RemoteErrorCode> extends Error {
|
||||
export class RemoteError<Code extends RemoteErrorCode = RemoteErrorCode> extends HarnessError {
|
||||
readonly isDSHRemoteError: true = true
|
||||
constructor(readonly code: Code, message: string,
|
||||
constructor(override readonly code: Code, message: string,
|
||||
readonly details: RemoteErrorDetailsMap[Code], options?: ErrorOptions)
|
||||
}
|
||||
export type RemoteFailure = { [C in RemoteErrorCode]: RemoteError<C> }[RemoteErrorCode]
|
||||
|
||||
+3
-3
@@ -16,12 +16,12 @@ Host 固定事实同样绕过了 `ctx.remote`:Host home 取自 `(ctx.get('conn
|
||||
|
||||
## Decision
|
||||
|
||||
`@deepseek-ai/dsh-typert-protocol` 导出唯一的失败类 `RemoteError<Code>`:一个真 `Error`,带只读 `code` 与 `details`、结构标记 `isDSHRemoteError`,以及标准 `ErrorOptions`(`cause` 只在进程内有效)。码与 details 的对应关系收进一张 merge-extensible 的 `RemoteErrorDetailsMap`;`RemoteFailure` 是按码分布的实例 union,`RemoteResult<T>` 形状不变。
|
||||
`@deepseek-ai/dsh-typert-protocol` 导出唯一的失败类 `RemoteError<Code>`:一个继承无依赖包 `@deepseek-ai/dsh-error` 中 `HarnessError` 的错误,带只读 `code` 与 `details`、结构标记 `isDSHRemoteError`,以及标准 `ErrorOptions`(`cause` 只在进程内有效)。码与 details 的对应关系收进一张 merge-extensible 的 `RemoteErrorDetailsMap`;`RemoteFailure` 是按码分布的实例 union,`RemoteResult<T>` 形状不变。
|
||||
|
||||
```text
|
||||
export class RemoteError<Code extends RemoteErrorCode = RemoteErrorCode> extends Error {
|
||||
export class RemoteError<Code extends RemoteErrorCode = RemoteErrorCode> extends HarnessError {
|
||||
readonly isDSHRemoteError: true = true
|
||||
constructor(readonly code: Code, message: string,
|
||||
constructor(override readonly code: Code, message: string,
|
||||
readonly details: RemoteErrorDetailsMap[Code], options?: ErrorOptions)
|
||||
}
|
||||
export type RemoteFailure = { [C in RemoteErrorCode]: RemoteError<C> }[RemoteErrorCode]
|
||||
|
||||
@@ -506,8 +506,8 @@ flowchart TD
|
||||
pkg_storage_json --> pkg_storage
|
||||
pkg_storage_sqlite --> pkg_storage
|
||||
pkg_subprocess --> pkg_http_proxy
|
||||
pkg_remote_mock --> pkg_typert_protocol
|
||||
pkg_typert_loader --> pkg_typert_registry
|
||||
pkg_typert_protocol --> pkg_error
|
||||
pkg_system_prompt --> pkg_llm
|
||||
pkg_system_prompt --> pkg_scope
|
||||
pkg_skill --> pkg_llm
|
||||
@@ -553,6 +553,7 @@ flowchart TD
|
||||
pkg_subprocess_local --> pkg_subprocess
|
||||
pkg_subprocess_local --> pkg_timeout
|
||||
pkg_otel --> pkg_session
|
||||
pkg_remote_mock --> pkg_typert_protocol
|
||||
pkg_session_snapshot --> pkg_http_proxy
|
||||
pkg_session_snapshot --> pkg_session
|
||||
pkg_fs --> pkg_brand
|
||||
@@ -1687,7 +1688,6 @@ flowchart TD
|
||||
| [`win32-process`](../packages/subprocess/win32-process) | `subprocess` | — |
|
||||
| [`llm-mock-server`](../packages/test-support/llm-mock-server) | `test-support` | — |
|
||||
| [`typert-generator`](../packages/typert/generator) | `typert` | — |
|
||||
| [`typert-protocol`](../packages/typert/protocol) | `typert` | — |
|
||||
| [`typert-registry`](../packages/typert/registry) | `typert` | — |
|
||||
| [`llm`](../packages/llm/llm) | `llm` | [`error`](../packages/util/error) |
|
||||
| [`session`](../packages/core/session) | `core` | [`scope`](../packages/core/scope) |
|
||||
@@ -1704,8 +1704,8 @@ flowchart TD
|
||||
| [`storage-json`](../packages/storage/storage-json) | `storage` | [`storage`](../packages/storage/storage) |
|
||||
| [`storage-sqlite`](../packages/storage/storage-sqlite) | `storage` | [`storage`](../packages/storage/storage) |
|
||||
| [`subprocess`](../packages/subprocess/subprocess) | `subprocess` | [`http-proxy`](../packages/util/http-proxy) |
|
||||
| [`remote-mock`](../packages/test-support/remote-mock) | `test-support` | [`typert-protocol`](../packages/typert/protocol) |
|
||||
| [`typert-loader`](../packages/typert/loader) | `typert` | [`typert-registry`](../packages/typert/registry) |
|
||||
| [`typert-protocol`](../packages/typert/protocol) | `typert` | [`error`](../packages/util/error) |
|
||||
| [`system-prompt`](../packages/core/system-prompt) | `core` | [`llm`](../packages/llm/llm), [`scope`](../packages/core/scope) |
|
||||
| [`skill`](../packages/skill/skill) | `skill` | [`llm`](../packages/llm/llm), [`scope`](../packages/core/scope) |
|
||||
| [`web`](../packages/web/web) | `web` | [`llm`](../packages/llm/llm) |
|
||||
@@ -1728,6 +1728,7 @@ flowchart TD
|
||||
| [`settings`](../packages/settings/settings) | `settings` | [`brand`](../packages/util/brand), [`session`](../packages/core/session) |
|
||||
| [`subprocess-local`](../packages/subprocess/subprocess-local) | `subprocess` | [`subprocess`](../packages/subprocess/subprocess), [`timeout`](../packages/util/timeout) |
|
||||
| [`otel`](../packages/telemetry/otel) | `telemetry` | [`session`](../packages/core/session) |
|
||||
| [`remote-mock`](../packages/test-support/remote-mock) | `test-support` | [`typert-protocol`](../packages/typert/protocol) |
|
||||
| [`session-snapshot`](../packages/test-support/session-snapshot) | `test-support` | [`http-proxy`](../packages/util/http-proxy), [`session`](../packages/core/session) |
|
||||
| [`fs`](../packages/fs/fs) | `fs` | [`brand`](../packages/util/brand), [`llm`](../packages/llm/llm), [`sandbox`](../packages/sandbox/sandbox) |
|
||||
| [`skill-office`](../packages/skill/skill-office) | `skill` | [`skill`](../packages/skill/skill) |
|
||||
|
||||
@@ -508,8 +508,8 @@ flowchart TD
|
||||
pkg_storage_json --> pkg_storage
|
||||
pkg_storage_sqlite --> pkg_storage
|
||||
pkg_subprocess --> pkg_http_proxy
|
||||
pkg_remote_mock --> pkg_typert_protocol
|
||||
pkg_typert_loader --> pkg_typert_registry
|
||||
pkg_typert_protocol --> pkg_error
|
||||
pkg_system_prompt --> pkg_llm
|
||||
pkg_system_prompt --> pkg_scope
|
||||
pkg_skill --> pkg_llm
|
||||
@@ -555,6 +555,7 @@ flowchart TD
|
||||
pkg_subprocess_local --> pkg_subprocess
|
||||
pkg_subprocess_local --> pkg_timeout
|
||||
pkg_otel --> pkg_session
|
||||
pkg_remote_mock --> pkg_typert_protocol
|
||||
pkg_session_snapshot --> pkg_http_proxy
|
||||
pkg_session_snapshot --> pkg_session
|
||||
pkg_fs --> pkg_brand
|
||||
@@ -1689,7 +1690,6 @@ flowchart TD
|
||||
| [`win32-process`](../packages/subprocess/win32-process) | `subprocess` | — |
|
||||
| [`llm-mock-server`](../packages/test-support/llm-mock-server) | `test-support` | — |
|
||||
| [`typert-generator`](../packages/typert/generator) | `typert` | — |
|
||||
| [`typert-protocol`](../packages/typert/protocol) | `typert` | — |
|
||||
| [`typert-registry`](../packages/typert/registry) | `typert` | — |
|
||||
| [`llm`](../packages/llm/llm) | `llm` | [`error`](../packages/util/error) |
|
||||
| [`session`](../packages/core/session) | `core` | [`scope`](../packages/core/scope) |
|
||||
@@ -1706,8 +1706,8 @@ flowchart TD
|
||||
| [`storage-json`](../packages/storage/storage-json) | `storage` | [`storage`](../packages/storage/storage) |
|
||||
| [`storage-sqlite`](../packages/storage/storage-sqlite) | `storage` | [`storage`](../packages/storage/storage) |
|
||||
| [`subprocess`](../packages/subprocess/subprocess) | `subprocess` | [`http-proxy`](../packages/util/http-proxy) |
|
||||
| [`remote-mock`](../packages/test-support/remote-mock) | `test-support` | [`typert-protocol`](../packages/typert/protocol) |
|
||||
| [`typert-loader`](../packages/typert/loader) | `typert` | [`typert-registry`](../packages/typert/registry) |
|
||||
| [`typert-protocol`](../packages/typert/protocol) | `typert` | [`error`](../packages/util/error) |
|
||||
| [`system-prompt`](../packages/core/system-prompt) | `core` | [`llm`](../packages/llm/llm), [`scope`](../packages/core/scope) |
|
||||
| [`skill`](../packages/skill/skill) | `skill` | [`llm`](../packages/llm/llm), [`scope`](../packages/core/scope) |
|
||||
| [`web`](../packages/web/web) | `web` | [`llm`](../packages/llm/llm) |
|
||||
@@ -1730,6 +1730,7 @@ flowchart TD
|
||||
| [`settings`](../packages/settings/settings) | `settings` | [`brand`](../packages/util/brand), [`session`](../packages/core/session) |
|
||||
| [`subprocess-local`](../packages/subprocess/subprocess-local) | `subprocess` | [`subprocess`](../packages/subprocess/subprocess), [`timeout`](../packages/util/timeout) |
|
||||
| [`otel`](../packages/telemetry/otel) | `telemetry` | [`session`](../packages/core/session) |
|
||||
| [`remote-mock`](../packages/test-support/remote-mock) | `test-support` | [`typert-protocol`](../packages/typert/protocol) |
|
||||
| [`session-snapshot`](../packages/test-support/session-snapshot) | `test-support` | [`http-proxy`](../packages/util/http-proxy), [`session`](../packages/core/session) |
|
||||
| [`fs`](../packages/fs/fs) | `fs` | [`brand`](../packages/util/brand), [`llm`](../packages/llm/llm), [`sandbox`](../packages/sandbox/sandbox) |
|
||||
| [`skill-office`](../packages/skill/skill-office) | `skill` | [`skill`](../packages/skill/skill) |
|
||||
|
||||
@@ -82,7 +82,7 @@ function styleInjectionModule(
|
||||
* Everything else under @deepseek-ai/* is either a module-table entry
|
||||
* (external) or a leak the purity gate rejects.
|
||||
*/
|
||||
export const INLINE_SAFE = /^(?:@deepseek-ai\/dsh-(?:file-reference|fs-patch|session|llm|tools|brand|official-bundles|deque|output-retention|typert-protocol|util-crypto|util-time|util-values|util-workspace-path)(?:\/|$)|@deepseek-ai\/dsh-util-file-drag$|@deepseek-ai\/dsh-token-meter\/client$|@deepseek-ai\/dsh-commands\/builtin$|@deepseek-ai\/dsh-native-command\/types$|@deepseek-ai\/dsh-host-open-in-app\/shared$|@deepseek-ai\/dsh-plugin-manager\/registry$|@deepseek-ai\/dsh-agent-preset-registry\/display$|@deepseek-ai\/dsh-api-workspace-controller\/default-workspace$|@deepseek-ai\/dsh-spill-policy\/notice$)/
|
||||
export const INLINE_SAFE = /^(?:@deepseek-ai\/dsh-(?:file-reference|fs-patch|session|llm|tools|brand|error|official-bundles|deque|output-retention|typert-protocol|util-crypto|util-time|util-values|util-workspace-path)(?:\/|$)|@deepseek-ai\/dsh-util-file-drag$|@deepseek-ai\/dsh-token-meter\/client$|@deepseek-ai\/dsh-commands\/builtin$|@deepseek-ai\/dsh-native-command\/types$|@deepseek-ai\/dsh-host-open-in-app\/shared$|@deepseek-ai\/dsh-plugin-manager\/registry$|@deepseek-ai\/dsh-agent-preset-registry\/display$|@deepseek-ai\/dsh-api-workspace-controller\/default-workspace$|@deepseek-ai\/dsh-spill-policy\/notice$)/
|
||||
|
||||
/**
|
||||
* Vendored framework libraries: rescoped into @deepseek-ai, so the gate below
|
||||
|
||||
@@ -4369,7 +4369,7 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
|
||||
description: 'Ask the scoped answerer waterfall and wait for the user\'s answer.\n\nWhen a caller supplies an agent, human interaction is valid only for the exact live instance of an ordinary Session. Explicit subagent origin rejects delegated callers; historical ordinary forks may retain parent metadata and still ask normally.',
|
||||
parameters: [{ name: 'request', description: 'Questions, owner agent, and abort signal.' }],
|
||||
returns: 'The answer chosen or typed by the human.',
|
||||
throws: ['{UserQuestionError} code `ASK_ABORTED` when the supplied signal is already or becomes aborted, `CALLER_NOT_LIVE` when a supplied agent is not the registry\'s exact live instance, `DELEGATED_CALLER` when that live agent has subagent origin, or `PROVIDER_ERROR` when an answerer fails with a value that is not a `HarnessError`; a coded `HarnessError` from an answerer keeps its `name` and `code`.'],
|
||||
throws: ['{UserQuestionError} code `ASK_ABORTED` when the supplied signal is already or becomes aborted, `CALLER_NOT_LIVE` when a supplied agent is not the registry\'s exact live instance, `DELEGATED_CALLER` when that live agent has subagent origin, or `PROVIDER_ERROR`, keeping the original message, when an answerer fails with a value that is not a `HarnessError`; a coded `HarnessError` from an answerer keeps its `name` and `code`.'],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -6802,6 +6802,10 @@ export const TYPE_API: readonly TypeApiEntry[] = [
|
||||
name: 'GrantRecord',
|
||||
declaration: 'export interface GrantRecord {\n readonly kind: \'grant\';\n readonly payload: unknown;\n}',
|
||||
},
|
||||
{
|
||||
name: 'HarnessError',
|
||||
declaration: 'export class HarnessError extends Error {\n readonly code: string;\n constructor(message: string, code: string, options?: ErrorOptions);\n}',
|
||||
},
|
||||
{
|
||||
name: 'HookBudget',
|
||||
declaration: 'export interface HookBudget {\n readonly ms: number;\n readonly remainingMs: number;\n}',
|
||||
@@ -8132,7 +8136,7 @@ export const TYPE_API: readonly TypeApiEntry[] = [
|
||||
},
|
||||
{
|
||||
name: 'RemoteError',
|
||||
declaration: 'export class RemoteError<Code extends RemoteErrorCode = RemoteErrorCode> extends Error {\n readonly isDSHRemoteError: true;\n constructor(readonly code: Code, message: string, readonly details: RemoteErrorDetailsMap[Code], options?: ErrorOptions);\n}',
|
||||
declaration: 'export class RemoteError<Code extends RemoteErrorCode = RemoteErrorCode> extends HarnessError {\n readonly isDSHRemoteError: true;\n constructor(override readonly code: Code, message: string, readonly details: RemoteErrorDetailsMap[Code], options?: ErrorOptions);\n}',
|
||||
},
|
||||
{
|
||||
name: 'RemoteErrorCode',
|
||||
|
||||
@@ -39,8 +39,8 @@
|
||||
en: bf3175c2218a16dd
|
||||
zh: 4be9271efe71ddb7
|
||||
/deepseek-ai-dsh-subagent/use-this-package/failure-and-recovery:
|
||||
en: bdb3204a71ee2a8f
|
||||
zh: 74d7d4e9eca20e2a
|
||||
en: 4815c56bfcb844e9
|
||||
zh: 424c6133c4805a66
|
||||
/deepseek-ai-dsh-subagent/understand-the-implementation:
|
||||
en: 74d91b364b23f88d
|
||||
zh: 19cc558105efe8df
|
||||
|
||||
@@ -79,7 +79,7 @@ In-process spawn accepts an independent `agentPreset`; fork and external backend
|
||||
|
||||
### Failure and recovery
|
||||
|
||||
Starting without the `agents` service rejects with `CONTINUATION_UNAVAILABLE`; an available runtime rejects a missing or replaced parent with `UNAUTHORIZED`. Providers implementing neither execution method are rejected at registration with `UNSUPPORTED_CAPABILITY`; unsupported requested capabilities reject creation with the same code. If a provider is removed or replaced while directory resolution is pending, creation rejects with `PROVIDER_CHANGED` before invoking either provider; retry the delegation against the current registration. Every creation failure below is a `SubagentError`: a child beyond the requested depth rejects with the `SubagentDepthError` subclass and `DEPTH_EXCEEDED`, an invalid runtime `subagentDepth` with `INVALID_DEPTH`, a fresh child whose selected preset is unknown or cannot load, or that cannot join its creator's preset revision, with `PRESET_UNAVAILABLE`, a local child without the working-directory service with `WORKING_DIRECTORY_UNAVAILABLE`, and an out-of-process child whose cwd is relative or not enterable with `INVALID_CWD`. A cold target whose persisted descriptor is corrupt rejects with `NOT_RESUMABLE`, and `structured_output` called while input is pending fails with `STRUCTURED_OUTPUT_PENDING_INPUT`. The caller signal cancels only unpublished work; after publication, `dispose()` cancels the exact activation and waits for its resource cleanup. Creation descendants continue independently; hosts must await `drainDescendants([root])` before disposing the root handle to stop all members and await pending startup. `result` settles after teardown and notifications, carrying output, optional structured data, and a stop reason; capture failures reject it after teardown. Cleanup failures reject `dispose()` and mark the lifecycle end as failed; the result promise and parent notification retain the captured execution result.
|
||||
Starting without the `agents` service rejects with `CONTINUATION_UNAVAILABLE`; an available runtime rejects a missing or replaced parent with `UNAUTHORIZED`. Providers implementing neither execution method are rejected at registration with `UNSUPPORTED_CAPABILITY`; unsupported requested capabilities reject creation with the same code. If a provider is removed or replaced while directory resolution is pending, creation rejects with `PROVIDER_CHANGED` before invoking either provider; retry the delegation against the current registration. Every creation failure below is a `SubagentError`: a child beyond the requested depth rejects with the `SubagentDepthError` subclass and `DEPTH_EXCEEDED`, an invalid runtime `subagentDepth` with `INVALID_DEPTH`, a child that cannot join its creator's preset revision with `PRESET_UNAVAILABLE` (an unknown or unloadable selected preset keeps the registry's `RemoteError` code), a local child without the working-directory service with `WORKING_DIRECTORY_UNAVAILABLE`, and an out-of-process child whose cwd is relative or not enterable with `INVALID_CWD`. A cold target whose persisted descriptor is corrupt rejects with `NOT_RESUMABLE`, and `structured_output` called while input is pending fails with `STRUCTURED_OUTPUT_PENDING_INPUT`. The caller signal cancels only unpublished work; after publication, `dispose()` cancels the exact activation and waits for its resource cleanup. Creation descendants continue independently; hosts must await `drainDescendants([root])` before disposing the root handle to stop all members and await pending startup. `result` settles after teardown and notifications, carrying output, optional structured data, and a stop reason; capture failures reject it after teardown. Cleanup failures reject `dispose()` and mark the lifecycle end as failed; the result promise and parent notification retain the captured execution result.
|
||||
|
||||
-----
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ kind: "package-reference"
|
||||
|
||||
### 失败与恢复
|
||||
|
||||
缺少 `agents` 服务时,启动请求以 `CONTINUATION_UNAVAILABLE` 拒绝;运行时可用但父级缺失或被替换时,以 `UNAUTHORIZED` 拒绝。未实现任何执行方法的提供方会在注册时以 `UNSUPPORTED_CAPABILITY` 被拒绝;请求不受支持的能力会以同一码使创建失败。如果等待目录解析期间提供方被移除或替换,创建会在调用任何一方之前以 `PROVIDER_CHANGED` 拒绝;调用方可根据当前注册重试委派。以下创建失败均为 `SubagentError`:超出请求深度的子代以 `SubagentDepthError` 子类和 `DEPTH_EXCEEDED` 拒绝,无效的运行时 `subagentDepth` 以 `INVALID_DEPTH` 拒绝,所选 preset 未知或无法加载、或无法加入创建者 preset 版本的新建子代以 `PRESET_UNAVAILABLE` 拒绝,缺少工作目录服务的本地子代以 `WORKING_DIRECTORY_UNAVAILABLE` 拒绝,cwd 为相对路径或不可进入的进程外子代以 `INVALID_CWD` 拒绝。持久化 descriptor 损坏的冷目标以 `NOT_RESUMABLE` 拒绝,有待处理输入时调用 `structured_output` 以 `STRUCTURED_OUTPUT_PENDING_INPUT` 失败。调用方信号仅取消尚未发布的工作;发布后通过 `dispose()` 取消该次 activation,并等待其资源清理完成。创建后代独立继续运行;宿主必须在释放根句柄前等待 `drainDescendants([root])`,以停止所有成员并等待正在启动的工作。`result` 在清理与通知结束后完成,携带输出、可选结构化数据与停止原因;结果捕获故障在清理后使其拒绝。清理失败使 `dispose()` 拒绝,并将生命周期结束事件标记为失败;结果 promise 与父级通知保留已捕获的执行结果。
|
||||
缺少 `agents` 服务时,启动请求以 `CONTINUATION_UNAVAILABLE` 拒绝;运行时可用但父级缺失或被替换时,以 `UNAUTHORIZED` 拒绝。未实现任何执行方法的提供方会在注册时以 `UNSUPPORTED_CAPABILITY` 被拒绝;请求不受支持的能力会以同一码使创建失败。如果等待目录解析期间提供方被移除或替换,创建会在调用任何一方之前以 `PROVIDER_CHANGED` 拒绝;调用方可根据当前注册重试委派。以下创建失败均为 `SubagentError`:超出请求深度的子代以 `SubagentDepthError` 子类和 `DEPTH_EXCEEDED` 拒绝,无效的运行时 `subagentDepth` 以 `INVALID_DEPTH` 拒绝,无法加入创建者 preset 版本的子代以 `PRESET_UNAVAILABLE` 拒绝(所选 preset 未知或无法加载时保留 registry 的 `RemoteError` code),缺少工作目录服务的本地子代以 `WORKING_DIRECTORY_UNAVAILABLE` 拒绝,cwd 为相对路径或不可进入的进程外子代以 `INVALID_CWD` 拒绝。持久化 descriptor 损坏的冷目标以 `NOT_RESUMABLE` 拒绝,有待处理输入时调用 `structured_output` 以 `STRUCTURED_OUTPUT_PENDING_INPUT` 失败。调用方信号仅取消尚未发布的工作;发布后通过 `dispose()` 取消该次 activation,并等待其资源清理完成。创建后代独立继续运行;宿主必须在释放根句柄前等待 `drainDescendants([root])`,以停止所有成员并等待正在启动的工作。`result` 在清理与通知结束后完成,携带输出、可选结构化数据与停止原因;结果捕获故障在清理后使其拒绝。清理失败使 `dispose()` 拒绝,并将生命周期结束事件标记为失败;结果 promise 与父级通知保留已捕获的执行结果。
|
||||
|
||||
-----
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@
|
||||
"@deepseek-ai/dsh-agent": "workspace:*",
|
||||
"@deepseek-ai/dsh-agent-preset-registry": "workspace:*",
|
||||
"@deepseek-ai/dsh-attachment": "workspace:*",
|
||||
"@deepseek-ai/dsh-error": "workspace:*",
|
||||
"@deepseek-ai/dsh-llm": "workspace:*",
|
||||
"@deepseek-ai/dsh-sandbox": "workspace:*",
|
||||
"@deepseek-ai/dsh-sandbox-policy": "workspace:*",
|
||||
|
||||
@@ -25,7 +25,6 @@ import type {} from '@deepseek-ai/dsh-permission-presets'
|
||||
// keeps its model-facing rows on the host plane, where the child already sees
|
||||
// them through the tool registry's global layer.
|
||||
import type {} from '@deepseek-ai/dsh-agent-preset-registry'
|
||||
import { remoteErrorOf } from '@deepseek-ai/dsh-typert-protocol'
|
||||
import { delegationDepthOf } from './depth.ts'
|
||||
import { SubagentError } from './error.ts'
|
||||
|
||||
@@ -184,9 +183,9 @@ export const SUBAGENT_DELEGATION_CONTEXT
|
||||
* @param parent - creator for fresh delegation; absent during target-only restoration.
|
||||
* @param composition - independent preset and any overrides read from a historical descriptor.
|
||||
* @returns A promise when mounting an independent preset; otherwise completes synchronously.
|
||||
* @throws {SubagentError} `PRESET_UNAVAILABLE` when the preset service is absent, a fresh
|
||||
* delegation's preset is unknown or cannot load, or the child cannot join its creator's
|
||||
* preset revision. Restoration propagates the registry's `RemoteError` unchanged.
|
||||
* @throws {SubagentError} `PRESET_UNAVAILABLE` when the preset service is absent or the
|
||||
* child cannot join its creator's preset revision. An unknown or unloadable selected
|
||||
* preset rejects with the registry's `RemoteError` code.
|
||||
*/
|
||||
export function applyChildComposition(
|
||||
childCtx: Context,
|
||||
@@ -198,12 +197,7 @@ export function applyChildComposition(
|
||||
if (presets === undefined) {
|
||||
throw new SubagentError('selecting a child agent preset requires the agent-presets service', 'PRESET_UNAVAILABLE')
|
||||
}
|
||||
const mounted = presets.mount(childCtx, composition.agentPreset)
|
||||
// Restoration leaves an unavailable preset to its caller's NOT_RESUMABLE classification.
|
||||
return (parent === undefined ? mounted : mounted.catch((error: unknown) => {
|
||||
const failure = remoteErrorOf(error)
|
||||
throw failure === undefined ? error : new SubagentError(failure.message, 'PRESET_UNAVAILABLE', { cause: error })
|
||||
})).then(() => {
|
||||
return presets.mount(childCtx, composition.agentPreset).then(() => {
|
||||
applyChildOverrides(childCtx, composition)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import type { Agent } from '@deepseek-ai/dsh-agent'
|
||||
import AgentLoop from '@deepseek-ai/dsh-agent-loop'
|
||||
import { mountAgentLoopTestDependencies } from '@deepseek-ai/dsh-agent-loop-testkit'
|
||||
import AgentPresets from '@deepseek-ai/dsh-agent-preset-registry'
|
||||
import { HarnessError } from '@deepseek-ai/dsh-error'
|
||||
import { createUserMessage } from '@deepseek-ai/dsh-llm'
|
||||
import { SessionId } from '@deepseek-ai/dsh-session'
|
||||
import * as JsonlSessionPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'
|
||||
@@ -139,17 +140,11 @@ describe('child preset start validation', () => {
|
||||
expect(adapter.requests).toEqual([])
|
||||
})
|
||||
|
||||
it('classifies an unknown independent preset as PRESET_UNAVAILABLE and keeps other mount failures', async () => {
|
||||
it('rejects an unknown independent preset with the registry RemoteError as a HarnessError', async () => {
|
||||
const { ctx, parent, adapter } = await setup()
|
||||
await expect(ctx.subagents.startActivation(startSpec(parent, 'absent'))).rejects.toMatchObject({
|
||||
name: 'SubagentError',
|
||||
code: 'PRESET_UNAVAILABLE',
|
||||
message: 'Unknown agent preset: absent',
|
||||
cause: { code: 'agent-preset/not-found' },
|
||||
})
|
||||
const failure = new Error('binding failed')
|
||||
vi.spyOn(ctx.agentPresets, 'mount').mockRejectedValueOnce(failure)
|
||||
await expect(ctx.subagents.startActivation(startSpec(parent, 'reviewing'))).rejects.toBe(failure)
|
||||
const failure: unknown = await ctx.subagents.startActivation(startSpec(parent, 'absent')).catch((error: unknown) => error)
|
||||
expect(failure).toBeInstanceOf(HarnessError)
|
||||
expect(failure).toMatchObject({ name: 'RemoteError', code: 'agent-preset/not-found', message: 'Unknown agent preset: absent' })
|
||||
expect(ctx.agents.list().map(agent => agent.id)).toEqual([parent.id])
|
||||
expect(adapter.requests).toEqual([])
|
||||
})
|
||||
|
||||
@@ -162,7 +162,7 @@ describe('spawn preset selection', () => {
|
||||
const result = await callSubagent(ctx, { ...args, ...selection }, { agent: parent.agent })
|
||||
expect(result.isError).toBe(true)
|
||||
expect(text(result)).toContain('Unknown agent preset: absent')
|
||||
expect(result.error?.info).toEqual({ name: 'SubagentError', code: 'PRESET_UNAVAILABLE' })
|
||||
expect(result.error?.info).toEqual({ name: 'RemoteError', code: 'agent-preset/not-found' })
|
||||
expect(ctx.agents.list()).toEqual([parent.agent])
|
||||
expect(ctx.sessions.list()).toEqual(sessions)
|
||||
})
|
||||
@@ -180,7 +180,7 @@ describe('spawn preset selection', () => {
|
||||
const result = await callSubagent(ctx, args, { agent: parent.agent })
|
||||
expect(result.isError).toBe(true)
|
||||
expect(text(result)).toContain('missing-plugin')
|
||||
expect(result.error?.info).toEqual({ name: 'SubagentError', code: 'PRESET_UNAVAILABLE' })
|
||||
expect(result.error?.info).toEqual({ name: 'RemoteError', code: 'agent-preset/invalid' })
|
||||
expect(ctx.agents.list()).toEqual([parent.agent])
|
||||
expect(ctx.sessions.list()).toEqual(sessions)
|
||||
})
|
||||
@@ -365,7 +365,7 @@ describe('spawn preset selection', () => {
|
||||
const failed = await callSubagent(ctx, args, { agent: handle.agent })
|
||||
expect(failed.isError).toBe(true)
|
||||
expect(text(failed)).toContain('Unknown agent preset: later')
|
||||
expect(failed.error?.info).toEqual({ name: 'SubagentError', code: 'PRESET_UNAVAILABLE' })
|
||||
expect(failed.error?.info).toEqual({ name: 'RemoteError', code: 'agent-preset/not-found' })
|
||||
|
||||
await ctx.agentPresets.register({ id: 'later', plugins: [] })
|
||||
ctx.llm.registerAdapter(['mock'], new MockAdapter([textResponse('reviewed')]))
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
en: 3db384ae6f215632
|
||||
zh: 56207184b09d4018
|
||||
/deepseek-ai-dsh-typert-protocol/use-this-package/reporting-and-reading-a-remote-failure:
|
||||
en: 4ba5266ddb014029
|
||||
zh: e31ae6438b9b4aa5
|
||||
en: 32d5fdd4b678d86c
|
||||
zh: 00af91a97b891592
|
||||
/deepseek-ai-dsh-typert-protocol/use-this-package/receiving-forwarded-host-events-on-the-client:
|
||||
en: 1101bd1d1419618c
|
||||
zh: 6ff036538d237e0a
|
||||
|
||||
@@ -81,7 +81,7 @@ declare module '@deepseek-ai/dsh-typert-protocol' {
|
||||
throw new RemoteError('goal/not-found', `goal "${id}" does not exist`, { goalId: id })
|
||||
```
|
||||
|
||||
An owner throws at the failure point; no package writes an error-class family or an exit-mapping function. A caller discriminates by `code` — never by `instanceof` — and a `code` branch narrows `details` with no cast, because `RemoteFailure` is the code-discriminated union of `RemoteError` instances. Infrastructure that must recognize a failure carried across a module or realm copy of the class calls `remoteErrorOf(value)`, which reads a structural marker instead of the prototype chain.
|
||||
An owner throws at the failure point; no package writes an error-class family or an exit-mapping function. A caller discriminates by `code` — never by `instanceof` — and a `code` branch narrows `details` with no cast, because `RemoteFailure` is the code-discriminated union of `RemoteError` instances. Infrastructure that must recognize a failure carried across a module or realm copy of the class calls `remoteErrorOf(value)`, which reads a structural marker instead of the prototype chain. `RemoteError` extends `HarnessError` from [`@deepseek-ai/dsh-error`](../../util/error/README.md), so a tool body that throws one records `name: 'RemoteError'` and its Remote `code` on `tool/result`.
|
||||
|
||||
### Receiving forwarded Host events on the Client
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ declare module '@deepseek-ai/dsh-typert-protocol' {
|
||||
throw new RemoteError('goal/not-found', `goal "${id}" does not exist`, { goalId: id })
|
||||
```
|
||||
|
||||
拥有方在失败点直接抛出;没有任何包再写错误类家族或出口映射函数。调用方按 `code` 判别——绝不用 `instanceof`——且 `code` 分支无需 cast 即收窄 `details`,因为 `RemoteFailure` 就是 `RemoteError` 实例按码判别的 union。需要识别跨模块或跨 realm 类副本传来的失败时,基础设施调用 `remoteErrorOf(value)`,它读结构标记而不是原型链。
|
||||
拥有方在失败点直接抛出;没有任何包再写错误类家族或出口映射函数。调用方按 `code` 判别——绝不用 `instanceof`——且 `code` 分支无需 cast 即收窄 `details`,因为 `RemoteFailure` 就是 `RemoteError` 实例按码判别的 union。需要识别跨模块或跨 realm 类副本传来的失败时,基础设施调用 `remoteErrorOf(value)`,它读结构标记而不是原型链。`RemoteError` 继承 [`@deepseek-ai/dsh-error`](../../util/error/README.zh.md) 的 `HarnessError`,因此工具体抛出它时,`tool/result` 会记录 `name: 'RemoteError'` 及其 Remote `code`。
|
||||
|
||||
### 在 Client 侧接收转发的 Host 事件
|
||||
|
||||
|
||||
@@ -43,9 +43,11 @@
|
||||
"zod": "4.6.6"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@deepseek-ai/cordis": "workspace:~"
|
||||
"@deepseek-ai/cordis": "workspace:~",
|
||||
"@deepseek-ai/dsh-error": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@deepseek-ai/cordis": "workspace:~"
|
||||
"@deepseek-ai/cordis": "workspace:~",
|
||||
"@deepseek-ai/dsh-error": "workspace:*"
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,17 @@
|
||||
/** The one Remote failure class shared by owners, the Gateway, and consumers. */
|
||||
|
||||
import { HarnessError } from '@deepseek-ai/dsh-error'
|
||||
import type { RemoteErrorCode, RemoteErrorDetailsMap, RemoteFailure } from './types.ts'
|
||||
|
||||
/**
|
||||
* One Remote call failure: a real Error carrying its stable code and typed
|
||||
* One Remote call failure: a `HarnessError` carrying its stable code and typed
|
||||
* details. Owners throw it at the failure point; the Host Gateway encodes it
|
||||
* onto the wire unchanged; the Client face rebuilds an instance for the
|
||||
* `RemoteResult` error branch, so `throw result.error` keeps throw semantics.
|
||||
* Discrimination is always by `code`, never by instanceof.
|
||||
* A tool body that throws it records `name: 'RemoteError'` and its Remote code
|
||||
* on `tool/result`. Discrimination is always by `code`, never by instanceof.
|
||||
*/
|
||||
export class RemoteError<Code extends RemoteErrorCode = RemoteErrorCode> extends Error {
|
||||
export class RemoteError<Code extends RemoteErrorCode = RemoteErrorCode> extends HarnessError {
|
||||
/** Structural marker: cross-realm/bundle identification never uses instanceof. */
|
||||
readonly isDSHRemoteError: true = true
|
||||
|
||||
@@ -20,12 +22,12 @@ export class RemoteError<Code extends RemoteErrorCode = RemoteErrorCode> extends
|
||||
* @param options - standard Error options (`cause` survives in-process only).
|
||||
*/
|
||||
constructor(
|
||||
readonly code: Code,
|
||||
override readonly code: Code,
|
||||
message: string,
|
||||
readonly details: RemoteErrorDetailsMap[Code],
|
||||
options?: ErrorOptions,
|
||||
) {
|
||||
super(message, options)
|
||||
super(message, code, options)
|
||||
this.name = 'RemoteError'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { HarnessError } from '@deepseek-ai/dsh-error'
|
||||
import { RemoteError, remoteErrorOf } from '@deepseek-ai/dsh-typert-protocol'
|
||||
|
||||
describe('RemoteError', () => {
|
||||
it('is a HarnessError that keeps its Remote code, details, and cause', () => {
|
||||
const cause = new Error('backend closed')
|
||||
const error = new RemoteError('gateway/bad-request', 'name is required', { issues: [{ path: ['name'] }] }, { cause })
|
||||
|
||||
expect(error).toBeInstanceOf(HarnessError)
|
||||
expect(error).toMatchObject({
|
||||
name: 'RemoteError',
|
||||
code: 'gateway/bad-request',
|
||||
message: 'name is required',
|
||||
details: { issues: [{ path: ['name'] }] },
|
||||
cause,
|
||||
})
|
||||
expect(remoteErrorOf(error)).toBe(error)
|
||||
})
|
||||
})
|
||||
@@ -16,6 +16,9 @@
|
||||
},
|
||||
{
|
||||
"path": "../../util/brand"
|
||||
},
|
||||
{
|
||||
"path": "../../util/error"
|
||||
}
|
||||
]
|
||||
}
|
||||
Generated
+6
@@ -16442,6 +16442,9 @@ importers:
|
||||
'@deepseek-ai/dsh-attachment':
|
||||
specifier: workspace:*
|
||||
version: link:../../attachment/attachment
|
||||
'@deepseek-ai/dsh-error':
|
||||
specifier: workspace:*
|
||||
version: link:../../util/error
|
||||
'@deepseek-ai/dsh-fs-sandbox':
|
||||
specifier: workspace:*
|
||||
version: link:../../fs/fs-sandbox
|
||||
@@ -17708,6 +17711,9 @@ importers:
|
||||
'@deepseek-ai/cordis':
|
||||
specifier: workspace:~
|
||||
version: link:../../../vendor/cordis
|
||||
'@deepseek-ai/dsh-error':
|
||||
specifier: workspace:*
|
||||
version: link:../../util/error
|
||||
|
||||
packages/typert/registry:
|
||||
dependencies:
|
||||
|
||||
Reference in new issue
Block a user