@octopi-agent/engine 0.102.10 → 0.121.15
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/dist/builtin-model-info.js +28 -7
- package/dist/config-admin/agent-presets.d.ts +32 -0
- package/dist/config-admin/agent-presets.js +133 -0
- package/dist/config-admin/console-access-key.d.ts +46 -0
- package/dist/config-admin/console-access-key.js +47 -0
- package/dist/config-admin/discover.d.ts +33 -4
- package/dist/config-admin/discover.js +101 -6
- package/dist/config-admin/env.d.ts +11 -0
- package/dist/config-admin/env.js +41 -0
- package/dist/config-admin/error-copy.d.ts +106 -0
- package/dist/config-admin/error-copy.js +287 -0
- package/dist/config-admin/i18n.d.ts +21 -0
- package/dist/config-admin/i18n.js +19 -0
- package/dist/config-admin/index.d.ts +8 -2
- package/dist/config-admin/index.js +4 -1
- package/dist/config-admin/model-presets.d.ts +14 -0
- package/dist/config-admin/model-presets.js +595 -70
- package/dist/config-admin/onboarding-apply.d.ts +83 -0
- package/dist/config-admin/onboarding-apply.js +259 -0
- package/dist/config-admin/onboarding.d.ts +160 -0
- package/dist/config-admin/onboarding.js +298 -0
- package/dist/config-admin/password-policy.d.ts +24 -0
- package/dist/config-admin/password-policy.js +31 -0
- package/dist/config-admin/redact.d.ts +42 -9
- package/dist/config-admin/redact.js +69 -5
- package/dist/config-schema/agent.d.ts +5 -1
- package/dist/config-schema/agent.js +20 -2
- package/dist/config-schema/browser.d.ts +62 -0
- package/dist/config-schema/browser.js +89 -0
- package/dist/config-schema/context.d.ts +7 -2
- package/dist/config-schema/context.js +6 -3
- package/dist/config-schema/engine.d.ts +86 -7
- package/dist/config-schema/engine.js +9 -2
- package/dist/config-schema/governance.d.ts +12 -1
- package/dist/config-schema/governance.js +10 -2
- package/dist/config-schema/models.d.ts +12 -8
- package/dist/config-schema/models.js +16 -1
- package/dist/config-schema/run.d.ts +4 -0
- package/dist/config-schema/run.js +10 -0
- package/dist/config-schema/shared.d.ts +1 -0
- package/dist/config-schema/shared.js +4 -2
- package/dist/config-schema/substrate.d.ts +5 -0
- package/dist/config-schema/substrate.js +8 -0
- package/dist/config.d.ts +116 -10
- package/dist/config.js +109 -13
- package/dist/file-mode.d.ts +67 -0
- package/dist/file-mode.js +182 -0
- package/dist/fork-child.d.ts +82 -0
- package/dist/fork-child.js +123 -0
- package/dist/harness/activation/delegated-run.d.ts +42 -0
- package/dist/harness/activation/delegated-run.js +71 -0
- package/dist/harness/activation/dispatcher.js +4 -0
- package/dist/harness/activation/index.d.ts +1 -0
- package/dist/harness/activation/run-backend.d.ts +92 -0
- package/dist/harness/activation/run-backend.js +16 -0
- package/dist/harness/activation/run-protocol.d.ts +392 -0
- package/dist/harness/activation/run-protocol.js +19 -0
- package/dist/harness/activation/runtime.d.ts +33 -0
- package/dist/harness/activation/runtime.js +119 -28
- package/dist/harness/activation/types.d.ts +19 -2
- package/dist/harness/agent/builder.d.ts +12 -0
- package/dist/harness/agent/builder.js +78 -22
- package/dist/harness/agent/config-bridge.d.ts +10 -1
- package/dist/harness/agent/config-bridge.js +15 -3
- package/dist/harness/agent/registered-tool-adapter.d.ts +27 -0
- package/dist/harness/agent/registered-tool-adapter.js +67 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +2 -0
- package/dist/harness/agent/wire-agent-builder.js +9 -2
- package/dist/harness/capabilities/document/backends/plain.js +2 -1
- package/dist/harness/capabilities/document/legacy/factory.js +3 -2
- package/dist/harness/collaboration/autonomous-subsystem/audit/reader.d.ts +17 -0
- package/dist/harness/collaboration/autonomous-subsystem/audit/reader.js +66 -36
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.d.ts +6 -2
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.js +27 -7
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +1 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +11 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +13 -3
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +48 -39
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -0
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +4 -0
- package/dist/harness/collaboration/delegation/child-run.d.ts +9 -0
- package/dist/harness/collaboration/delegation/child-run.js +34 -2
- package/dist/harness/collaboration/delegation/registry-types.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.d.ts +9 -4
- package/dist/harness/collaboration/delegation/service.js +33 -12
- package/dist/harness/collaboration/delegation/store.d.ts +2 -0
- package/dist/harness/collaboration/delegation/store.js +1 -0
- package/dist/harness/collaboration/delegation/types.d.ts +11 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +2 -0
- package/dist/harness/collaboration/delegation/wiring.js +1 -0
- package/dist/harness/context/capabilities/compact/engine.d.ts +44 -5
- package/dist/harness/context/capabilities/compact/engine.js +127 -39
- package/dist/harness/context/capabilities/compact/index.d.ts +2 -1
- package/dist/harness/context/capabilities/compact/index.js +1 -1
- package/dist/harness/context/capabilities/compact/types.d.ts +59 -9
- package/dist/harness/context/capabilities/summary/gate.d.ts +19 -2
- package/dist/harness/context/capabilities/summary/gate.js +53 -6
- package/dist/harness/context/capabilities/summary/registry.js +20 -0
- package/dist/harness/context/capabilities/summary/tool-binding.js +16 -12
- package/dist/harness/context/capabilities/summary/tool-bindings.d.ts +13 -0
- package/dist/harness/context/capabilities/summary/tool-bindings.js +22 -0
- package/dist/harness/context/capabilities/summary/types.d.ts +16 -0
- package/dist/harness/context/constitution/default-agents.md +85 -0
- package/dist/harness/context/context-size-ledger.js +8 -1
- package/dist/harness/context/default-context-engine.d.ts +100 -6
- package/dist/harness/context/default-context-engine.js +382 -89
- package/dist/harness/context/index.d.ts +2 -1
- package/dist/harness/context/index.js +1 -0
- package/dist/harness/context/layer-health.d.ts +4 -0
- package/dist/harness/context/layer-health.js +4 -0
- package/dist/harness/context/layer-types.d.ts +57 -0
- package/dist/harness/context/layer-types.js +73 -1
- package/dist/harness/context/layers.d.ts +3 -0
- package/dist/harness/context/layers.js +13 -6
- package/dist/harness/context/prefix-fingerprint.d.ts +46 -0
- package/dist/harness/context/prefix-fingerprint.js +52 -0
- package/dist/harness/context/summarize.js +18 -0
- package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
- package/dist/harness/context/system-prompt-assembler.js +5 -2
- package/dist/harness/context/tool-result-aging.d.ts +104 -16
- package/dist/harness/context/tool-result-aging.js +211 -57
- package/dist/harness/context/types.d.ts +71 -4
- package/dist/harness/context/types.js +25 -1
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +4 -3
- package/dist/harness/extension/execution-environment/effect-policy.js +2 -2
- package/dist/harness/extension/execution-environment/privileged-exec.js +4 -1
- package/dist/harness/extension/execution-environment/workspace.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +27 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.js +11 -2
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +12 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +25 -0
- package/dist/harness/extension/plugin-ecosystem/commands/builtin.js +28 -1
- package/dist/harness/extension/plugin-ecosystem/index.d.ts +1 -0
- package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +168 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +156 -15
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.d.ts +95 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.js +170 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.d.ts +178 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.js +314 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +40 -5
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +45 -26
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +11 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +42 -76
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +30 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +46 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +19 -14
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +3 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/browser-types.d.ts +333 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser-types.js +16 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser.d.ts +64 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser.js +692 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +0 -37
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +108 -4
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +34 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +0 -6
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +57 -4
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +81 -13
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +13 -7
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +126 -14
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +44 -5
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +10 -24
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +7 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +4 -0
- package/dist/harness/governance/credentials/db.d.ts +9 -0
- package/dist/harness/governance/credentials/db.js +122 -31
- package/dist/harness/governance/credentials/store.d.ts +68 -7
- package/dist/harness/governance/credentials/store.js +177 -64
- package/dist/harness/governance/credentials/types.d.ts +13 -2
- package/dist/harness/governance/index.d.ts +1 -0
- package/dist/harness/governance/index.js +1 -0
- package/dist/harness/governance/registry/db.d.ts +32 -0
- package/dist/harness/governance/registry/db.js +142 -0
- package/dist/harness/governance/registry/index.d.ts +9 -0
- package/dist/harness/governance/registry/index.js +9 -0
- package/dist/harness/governance/registry/service.d.ts +381 -0
- package/dist/harness/governance/registry/service.js +825 -0
- package/dist/harness/governance/registry/types.d.ts +77 -0
- package/dist/harness/governance/registry/types.js +7 -0
- package/dist/harness/governance/security/default-security-guard.d.ts +3 -0
- package/dist/harness/governance/security/default-security-guard.js +12 -1
- package/dist/harness/governance/security/risk-evaluator.d.ts +13 -3
- package/dist/harness/governance/security/risk-evaluator.js +307 -21
- package/dist/harness/governance/security/shell-parser-treesitter.js +12 -4
- package/dist/harness/governance/session-acl/tool-rights.d.ts +1 -0
- package/dist/harness/index.d.ts +5 -3
- package/dist/harness/index.js +2 -2
- package/dist/harness/knowledge/boot-config.d.ts +2 -0
- package/dist/harness/knowledge/boot-config.js +2 -0
- package/dist/harness/knowledge/client.d.ts +53 -7
- package/dist/harness/knowledge/client.js +77 -20
- package/dist/harness/knowledge/db.d.ts +16 -0
- package/dist/harness/knowledge/db.js +107 -41
- package/dist/harness/knowledge/engine-thread.js +5 -7
- package/dist/harness/knowledge/grounding.js +4 -1
- package/dist/harness/knowledge/http-app.d.ts +15 -0
- package/dist/harness/knowledge/http-app.js +82 -21
- package/dist/harness/knowledge/http-bridge.d.ts +15 -0
- package/dist/harness/knowledge/http-bridge.js +19 -0
- package/dist/harness/knowledge/knowledge-serve-child.js +2 -3
- package/dist/harness/knowledge/query-service.d.ts +12 -2
- package/dist/harness/knowledge/query-service.js +75 -41
- package/dist/harness/knowledge/query-worker-client.d.ts +5 -1
- package/dist/harness/knowledge/query-worker-client.js +4 -1
- package/dist/harness/knowledge/query-worker.js +5 -3
- package/dist/harness/knowledge/read-http.d.ts +2 -0
- package/dist/harness/knowledge/read-http.js +9 -2
- package/dist/harness/knowledge/retriever.d.ts +1 -1
- package/dist/harness/knowledge/retriever.js +1 -2
- package/dist/harness/knowledge/serve.d.ts +6 -1
- package/dist/harness/knowledge/serve.js +5 -6
- package/dist/harness/knowledge/source-store.d.ts +101 -5
- package/dist/harness/knowledge/source-store.js +297 -71
- package/dist/harness/knowledge/start-service-process.d.ts +27 -8
- package/dist/harness/knowledge/start-service-process.js +49 -90
- package/dist/harness/knowledge/tenant-gate.d.ts +81 -0
- package/dist/harness/knowledge/tenant-gate.js +167 -0
- package/dist/harness/knowledge/writer-service.d.ts +18 -2
- package/dist/harness/knowledge/writer-service.js +80 -16
- package/dist/harness/knowledge/writer-worker-client.d.ts +9 -2
- package/dist/harness/knowledge/writer-worker-client.js +20 -3
- package/dist/harness/knowledge/writer-worker.js +11 -4
- package/dist/harness/memory/backfill-trigger.d.ts +10 -3
- package/dist/harness/memory/backfill-trigger.js +19 -19
- package/dist/harness/memory/cognition-seeds.d.ts +45 -0
- package/dist/harness/memory/cognition-seeds.js +67 -0
- package/dist/harness/memory/cognition.d.ts +12 -3
- package/dist/harness/memory/cognition.js +55 -35
- package/dist/harness/memory/conceptualizer.d.ts +11 -1
- package/dist/harness/memory/conceptualizer.js +10 -1
- package/dist/harness/memory/context-slice.d.ts +42 -0
- package/dist/harness/memory/context-slice.js +197 -0
- package/dist/harness/memory/health-probe.d.ts +8 -2
- package/dist/harness/memory/health-probe.js +10 -13
- package/dist/harness/memory/index.d.ts +5 -1
- package/dist/harness/memory/index.js +3 -1
- package/dist/harness/memory/sqlite/agent-db.d.ts +1 -0
- package/dist/harness/memory/sqlite/agent-db.js +9 -8
- package/dist/harness/memory/sqlite/cognition-store.d.ts +26 -3
- package/dist/harness/memory/sqlite/cognition-store.js +103 -45
- package/dist/harness/memory/sqlite/memory-store.js +4 -0
- package/dist/harness/memory/sqlite/sqlite-vec.d.ts +24 -1
- package/dist/harness/memory/sqlite/sqlite-vec.js +37 -1
- package/dist/harness/memory/types.d.ts +18 -2
- package/dist/harness/observability/observer/hub.d.ts +10 -0
- package/dist/harness/observability/observer/hub.js +95 -2
- package/dist/harness/run/agent/agent.js +3 -2
- package/dist/harness/run/concurrency/tool-validator.js +4 -3
- package/dist/harness/run/reliability/run-agent.d.ts +22 -0
- package/dist/harness/run/reliability/run-agent.js +79 -10
- package/dist/harness/run/run-host.d.ts +302 -0
- package/dist/harness/run/run-host.js +978 -0
- package/dist/harness/run/run-scope.d.ts +11 -0
- package/dist/harness/run/run-scope.js +19 -1
- package/dist/harness/run/runner.d.ts +149 -22
- package/dist/harness/run/runner.js +352 -35
- package/dist/harness/session/in-memory-store.js +13 -1
- package/dist/harness/session/schedules/service.d.ts +10 -2
- package/dist/harness/session/schedules/service.js +13 -2
- package/dist/harness/session/tasks/tools.js +12 -0
- package/dist/harness/session/types.d.ts +10 -14
- package/dist/harness/shared/events/agent-event-map.d.ts +29 -0
- package/dist/harness/shared/types/agent-definition.d.ts +6 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/integration/agent-runtime/channel-message-source.d.ts +3 -1
- package/dist/integration/agent-runtime/channel-message-source.js +4 -3
- package/dist/integration/browser/camoufox.d.ts +40 -0
- package/dist/integration/browser/camoufox.js +80 -0
- package/dist/integration/browser/index.d.ts +91 -0
- package/dist/integration/browser/index.js +110 -0
- package/dist/integration/browser/install.d.ts +47 -0
- package/dist/integration/browser/install.js +214 -0
- package/dist/integration/browser/playwright.d.ts +224 -0
- package/dist/integration/browser/playwright.js +925 -0
- package/dist/integration/browser/service.d.ts +41 -0
- package/dist/integration/browser/service.js +181 -0
- package/dist/integration/browser/stealth.d.ts +42 -0
- package/dist/integration/browser/stealth.js +104 -0
- package/dist/integration/providers/anthropic-message-normalize.d.ts +20 -0
- package/dist/integration/providers/anthropic-message-normalize.js +48 -0
- package/dist/integration/providers/anthropic.js +27 -2
- package/dist/integration/providers/fetch-timeout.d.ts +17 -0
- package/dist/integration/providers/fetch-timeout.js +24 -0
- package/dist/integration/providers/openai.d.ts +8 -0
- package/dist/integration/providers/openai.js +41 -1
- package/dist/integration/providers/wire-dump-diff.js +2 -1
- package/dist/integration/providers/wire-dump.d.ts +56 -2
- package/dist/integration/providers/wire-dump.js +119 -6
- package/dist/integration/storage/archive-manager.d.ts +14 -2
- package/dist/integration/storage/archive-manager.js +24 -8
- package/dist/integration/storage/atomic-tmp.d.ts +12 -0
- package/dist/integration/storage/atomic-tmp.js +36 -0
- package/dist/integration/storage/jsonl.d.ts +9 -0
- package/dist/integration/storage/jsonl.js +137 -38
- package/dist/integration/storage/session-index.d.ts +5 -0
- package/dist/integration/storage/session-index.js +25 -4
- package/dist/integration/tools/assemble.d.ts +50 -0
- package/dist/integration/tools/assemble.js +137 -0
- package/dist/paths.d.ts +18 -0
- package/dist/paths.js +36 -0
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +3 -1
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +74 -5
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +3 -2
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +11 -2
- package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +6 -3
- package/dist/subsystems/cognition-steward/consolidate/handler.js +266 -28
- package/dist/subsystems/memory-steward/backfill/handler.js +3 -2
- package/dist/subsystems/memory-steward/govern/config.yaml +6 -1
- package/dist/subsystems/wisdom-steward/attribute/config.yaml +5 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +3 -0
- package/dist/subsystems/wisdom-steward/govern/config.yaml +6 -1
- package/package.json +5 -3
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run 契约线上协议(arch/service-topology.md §4「P0b 落地形态」)。
|
|
3
|
+
*
|
|
4
|
+
* 两个通道,各司其职:
|
|
5
|
+
* - **契约通道**(gateway → run 实例,loopback HTTP):`POST /runs`(RunRequest →
|
|
6
|
+
* NDJSON `RunStreamEntry` 流)/ `POST /control`(`RunControlOp`)/ `GET /health`;
|
|
7
|
+
* - **宿主通知**(run 实例 → gateway,fork IPC):`RunHostNotify`——审批请求、
|
|
8
|
+
* 客户端工具调用、out-of-run 会话事件、inbox 重投等控制面推送。
|
|
9
|
+
*
|
|
10
|
+
* 纪律:本文件只放**可序列化**数据形状;函数型参数禁止上契约(P0a 债务已随
|
|
11
|
+
* compactSession 数据化清偿)。审批/工具事件直接复用 hooks 既有数据类型(单一来源)。
|
|
12
|
+
*/
|
|
13
|
+
import type { AgentEvent } from '@octopi-agent/core/primitives/event-bus.js';
|
|
14
|
+
import type { Message, ToolDefinition, ToolSource } from '@octopi-agent/core/types.js';
|
|
15
|
+
import type { Trigger } from './types.js';
|
|
16
|
+
import type { CommandDefinition } from '../extension/plugin-ecosystem/commands/types.js';
|
|
17
|
+
import type { HitlAskResult } from '../governance/human-in-the-loop/decision-cache.js';
|
|
18
|
+
/** 线上错误形状(两形态错误表面的传输载体:同步抛 = HTTP 4xx/5xx body;闸门拒 = 流内 error entry) */
|
|
19
|
+
export interface RunWireError {
|
|
20
|
+
message: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* `POST /runs` 响应流(NDJSON,逐行一个 entry):
|
|
25
|
+
* 事件流若干 `{type:'event'}`,然后恰好一个终态 `done` 或 `error`。
|
|
26
|
+
* 流内 error = 异步错误表面(准入闸门拒等);未装载等同步错误不进流,直接 HTTP 4xx。
|
|
27
|
+
*/
|
|
28
|
+
export type RunStreamEntry = {
|
|
29
|
+
type: 'event';
|
|
30
|
+
event: AgentEvent;
|
|
31
|
+
} | {
|
|
32
|
+
type: 'done';
|
|
33
|
+
} | {
|
|
34
|
+
type: 'error';
|
|
35
|
+
error: RunWireError;
|
|
36
|
+
};
|
|
37
|
+
/** 客户端工具注册的线上形状(handler 不可传输;由 run 侧桥接实现承接) */
|
|
38
|
+
export interface ClientToolWireSpec {
|
|
39
|
+
definition: ToolDefinition;
|
|
40
|
+
source?: ToolSource;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 客户端工具可见性快照(`createVisibilityFilter` 谓词的数据化):
|
|
44
|
+
* gateway 在注册表变化时推送 + 周期 diff 刷(TTL 过期是「心跳缺失」——缺因态没有
|
|
45
|
+
* 事件可挂,生产者只能是时间刷),run 侧本地求值(stale 窗口 = 推送间隔,已声明收敛)。
|
|
46
|
+
*/
|
|
47
|
+
export interface ClientToolVisibilitySnapshot {
|
|
48
|
+
/** ClientToolHost 已安装的客户端工具名(累积:网关生命周期内不卸载,保证工具面恒定) */
|
|
49
|
+
installed: string[];
|
|
50
|
+
/**
|
|
51
|
+
* 当前有 live provider 的 (session, tool) 对——**仅用于调用期 liveness 校验**。
|
|
52
|
+
* 不参与工具面过滤:liveness 抖动不得改变 LLM 可见的 tools schema
|
|
53
|
+
* (tools 在缓存前缀最前,任何增删都会让整段历史前缀失效)。
|
|
54
|
+
*/
|
|
55
|
+
live: Array<{
|
|
56
|
+
sessionId: string;
|
|
57
|
+
toolName: string;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* 会话内「曾经 live 过」的 (session, tool) 对——**工具面粘滞依据**(方案 A)。
|
|
61
|
+
* 一旦某会话见过某客户端工具,该会话生命周期内它始终保持可见;
|
|
62
|
+
* 客户端不可用时由调用期返回 `client_unavailable`(响亮失败、可重试),
|
|
63
|
+
* 而不是把工具从 schema 里摘掉。
|
|
64
|
+
* 缺省(旧网关)= 回落 `live`。
|
|
65
|
+
*/
|
|
66
|
+
everLive?: Array<{
|
|
67
|
+
sessionId: string;
|
|
68
|
+
toolName: string;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* 快照有效期(epoch ms):**只约束调用期 liveness 判定的可信度**。
|
|
72
|
+
* 过期 ≠ 工具面收缩(那会烧前缀);过期时调用期检查退化为「照常派发」,
|
|
73
|
+
* 由调用自身 TTL 兜底。
|
|
74
|
+
*/
|
|
75
|
+
expiresAt: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* run lease 冲突标记(`supervise: lease_held` 错误文案的判据锚):产生点在
|
|
79
|
+
* FleetRunBackend.startRun(yield* 之前,消息未入上下文);消费点在
|
|
80
|
+
* AgentRuntime.finalizeDelivery 的唤醒重投判定。两端同源此常量,防字符串
|
|
81
|
+
* 跨包漂移。
|
|
82
|
+
*/
|
|
83
|
+
export declare const RUN_LEASE_HELD_MARKER = "lease_held";
|
|
84
|
+
/**
|
|
85
|
+
* 会话级控制 op(纯数据)。对应契约 `control(op)`:
|
|
86
|
+
* 每个 op 都有对应的 run 侧执行语义(RunHost.handleControl)。
|
|
87
|
+
*/
|
|
88
|
+
export type RunControlOp =
|
|
89
|
+
/** 中止会话在途 run(不丢内容;对应 run 侧 AbortController 集合) */
|
|
90
|
+
{
|
|
91
|
+
type: 'abort';
|
|
92
|
+
sessionId: string;
|
|
93
|
+
reason?: string;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 会话消息追加(schedule 通知投递等控制面写路径;写者单点 = run 节点,§3)。
|
|
97
|
+
* 执行:sessionLock → load → push → save(与 Runner.handle 共锁,防漂移整包抹除)。
|
|
98
|
+
*/
|
|
99
|
+
| {
|
|
100
|
+
type: 'sessionAppendMessage';
|
|
101
|
+
sessionId: string;
|
|
102
|
+
message: Message;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 截断会话消息(编辑重发/丢弃的唯一入口)。执行含本轮校验(仅最后一轮中止)、
|
|
106
|
+
* 租约下标收缩、abortedTurn 清理与本轮文件效应逆放(用户手改保留)。
|
|
107
|
+
*/
|
|
108
|
+
| {
|
|
109
|
+
type: 'truncateMessagesFrom';
|
|
110
|
+
sessionId: string;
|
|
111
|
+
fromIndex: number;
|
|
112
|
+
}
|
|
113
|
+
/** 审批回执(答复 RunHostNotify.approval_request;HitlAskResult 为既有数据形状) */
|
|
114
|
+
| {
|
|
115
|
+
type: 'approvalReply';
|
|
116
|
+
approvalId: string;
|
|
117
|
+
result: HitlAskResult;
|
|
118
|
+
}
|
|
119
|
+
/** 客户端工具结果回传(答复 RunHostNotify.client_tool_call) */
|
|
120
|
+
| {
|
|
121
|
+
type: 'clientToolResult';
|
|
122
|
+
callId: string;
|
|
123
|
+
outcome: {
|
|
124
|
+
ok: true;
|
|
125
|
+
result: unknown;
|
|
126
|
+
} | {
|
|
127
|
+
ok: false;
|
|
128
|
+
error: RunWireError;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** ask_user 作答回传(答复 RunHostNotify.ask_user_request;失败拒接让工具 fail-loud) */
|
|
132
|
+
| {
|
|
133
|
+
type: 'askUserReply';
|
|
134
|
+
askId: string;
|
|
135
|
+
outcome: {
|
|
136
|
+
ok: true;
|
|
137
|
+
answer: string;
|
|
138
|
+
} | {
|
|
139
|
+
ok: false;
|
|
140
|
+
error: RunWireError;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* 会话压缩。**纯数据**:systemPrompt/tools/摘要模型绑定等全部由 run 侧从自身
|
|
145
|
+
* 状态解析(P0a 迁移注记的清偿形态);控制面只传键。
|
|
146
|
+
*/
|
|
147
|
+
| {
|
|
148
|
+
type: 'compact';
|
|
149
|
+
sessionId: string;
|
|
150
|
+
agentId: string;
|
|
151
|
+
}
|
|
152
|
+
/** 热重建:新 AgentDefinition 数据下发,run 侧重建执行体(旧体退役判据不变) */
|
|
153
|
+
| {
|
|
154
|
+
type: 'reloadAgent';
|
|
155
|
+
agentId: string;
|
|
156
|
+
definition: AgentDefinitionWire;
|
|
157
|
+
}
|
|
158
|
+
/** 退役执行体(removeAgent) */
|
|
159
|
+
| {
|
|
160
|
+
type: 'retireAgent';
|
|
161
|
+
agentId: string;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* provider 热重建(评审 B4 深层:run worker 是独立进程,boot 拿 config 快照——
|
|
165
|
+
* gateway 热应用后 worker 的 provider 表过期,startRun 409 "provider not found")。
|
|
166
|
+
* 执行:按快照全量重建 provider 表。
|
|
167
|
+
*/
|
|
168
|
+
| {
|
|
169
|
+
type: 'reloadProviders';
|
|
170
|
+
modelProviders: Record<string, unknown>;
|
|
171
|
+
}
|
|
172
|
+
/** 动态客户端工具同步(E5 语义:add/remove + 可见性快照) */
|
|
173
|
+
| {
|
|
174
|
+
type: 'setClientTools';
|
|
175
|
+
ops: Array<{
|
|
176
|
+
op: 'add';
|
|
177
|
+
tool: ClientToolWireSpec;
|
|
178
|
+
} | {
|
|
179
|
+
op: 'remove';
|
|
180
|
+
name: string;
|
|
181
|
+
}>;
|
|
182
|
+
visibility: ClientToolVisibilitySnapshot;
|
|
183
|
+
}
|
|
184
|
+
/** 知识运行时状态同步(准入闸门输入;状态是 gateway 运行时已知值,非实时探测) */
|
|
185
|
+
| {
|
|
186
|
+
type: 'syncKnowledgeState';
|
|
187
|
+
state: KnowledgeStateWire;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* inbox 插话 offer(跨进程形态,协调面「插话」原语):把接续消息 offer 给目标
|
|
191
|
+
* agent 在 run 实例内的 SessionInbox。语义与本地 offer 一致——活跃 Run 接收
|
|
192
|
+
* (`continued`)则由它在下一个合法消息边界消费;未接收(`dispatched`)由
|
|
193
|
+
* 调用方照常 dispatch 新 Run;`duplicate` 为 entryId 去重命中。回调字段不
|
|
194
|
+
* 过线(onEvent/onAdmitted 归本地调用方),wire 只带纯数据。
|
|
195
|
+
*/
|
|
196
|
+
| {
|
|
197
|
+
type: 'inboxOffer';
|
|
198
|
+
agentId: string;
|
|
199
|
+
sessionId: string;
|
|
200
|
+
/** trigger.id / delegationId 去重键 */
|
|
201
|
+
entryId?: string;
|
|
202
|
+
human?: boolean;
|
|
203
|
+
triggerType?: string;
|
|
204
|
+
modelOverride?: string;
|
|
205
|
+
modelProvider?: string;
|
|
206
|
+
message: Message;
|
|
207
|
+
/** 原 Trigger(Run 关闭未消费时 run 侧按它 redispatch) */
|
|
208
|
+
trigger?: Trigger;
|
|
209
|
+
}
|
|
210
|
+
/** 七层上下文健康探针 */
|
|
211
|
+
| {
|
|
212
|
+
type: 'contextHealth';
|
|
213
|
+
agentId?: string;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* console 受控写后重锚定安全指纹(ops P2 §8.4)。boot 纯数据无法携带活守卫,
|
|
217
|
+
* run 实例自建 guard 后由宿主经此 op 同步署名(service-topology §7.3)。
|
|
218
|
+
*/
|
|
219
|
+
| {
|
|
220
|
+
type: 'reattestSecurity';
|
|
221
|
+
expectHash: string;
|
|
222
|
+
allowedChanged: string[];
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* 脉搏(P0c 脉搏单源,arch/service-topology-p0c.md §3 方案 A′):gateway 脉搏调度器
|
|
226
|
+
* 单发,副本收到后跑一次声明式 tick(原 self-arm 定时器的驱动源)。key 是实例自述的
|
|
227
|
+
* `PulseSpec.key`(opaque,gateway 不解释产品语义)。
|
|
228
|
+
*/
|
|
229
|
+
| {
|
|
230
|
+
type: 'pulse';
|
|
231
|
+
key: string;
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* 脉搏声明(P0c A′):run 实例装配后自述「我有哪些周期任务」,gateway 单发驱动。
|
|
235
|
+
* key 在实例内全局唯一(`<agentId>:<base>` 形态,产品语义不进 gateway)。
|
|
236
|
+
*/
|
|
237
|
+
export interface PulseSpec {
|
|
238
|
+
/** 实例内唯一脉搏键(opaque) */
|
|
239
|
+
key: string;
|
|
240
|
+
/** 周期(毫秒) */
|
|
241
|
+
intervalMs: number;
|
|
242
|
+
/** 归属 agent(诊断用) */
|
|
243
|
+
agentId?: string;
|
|
244
|
+
/** 首次收集后立即发一跳(替代原 runOnStart 自跳) */
|
|
245
|
+
runOnStart?: boolean;
|
|
246
|
+
/** 首跳延迟(毫秒)——多子系统按数据流依赖序错峰(govern 先于下游巩固/归因跑完) */
|
|
247
|
+
startupDelayMs?: number;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* 冒烟报告(健康门 §4.3)——`POST /smoke` 独立通道的应答(**不是 run,不占 run 语义**)。
|
|
251
|
+
* 逐 agent 装配热路径自检:工具面枚举 + 一次 no-LLM 应答(contextHealth)。
|
|
252
|
+
*/
|
|
253
|
+
export interface RunSmokeReport {
|
|
254
|
+
ok: boolean;
|
|
255
|
+
/**
|
|
256
|
+
* 该构建无冒烟端点(跨版本:pre-v0.108.2)——消费方降级为 health+guard 判定(MAJ-3),
|
|
257
|
+
* 不得当作冒烟失败挡回滚。
|
|
258
|
+
*/
|
|
259
|
+
unavailable?: boolean;
|
|
260
|
+
agents: Array<{
|
|
261
|
+
agentId: string;
|
|
262
|
+
toolCount: number;
|
|
263
|
+
checks: Array<{
|
|
264
|
+
name: string;
|
|
265
|
+
ok: boolean;
|
|
266
|
+
detail?: string;
|
|
267
|
+
}>;
|
|
268
|
+
}>;
|
|
269
|
+
}
|
|
270
|
+
/** AgentDefinition 线上传输别名(config-schema 数据对象,见 src/config-schema) */
|
|
271
|
+
export type AgentDefinitionWire = Record<string, unknown>;
|
|
272
|
+
/** 知识运行时状态(与 gateway KnowledgeRuntimeState 同枚举;线上自包含) */
|
|
273
|
+
export type KnowledgeStateWire = 'starting' | 'disabled' | 'ready' | 'degraded';
|
|
274
|
+
/** control 响应:成功(result 形状随 op)或失败(不得静默吞,见契约错误表面) */
|
|
275
|
+
export type RunControlResponse = {
|
|
276
|
+
ok: true;
|
|
277
|
+
result?: unknown;
|
|
278
|
+
} | {
|
|
279
|
+
ok: false;
|
|
280
|
+
error: RunWireError;
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* 审批请求载荷(Gateway.requestApproval 同构的纯数据面;引擎侧自包含)。
|
|
284
|
+
* 插件工具审批(HookToolEvent/HookToolApproval)经 toolApprovalToRequestInput 归一到此形。
|
|
285
|
+
*/
|
|
286
|
+
export interface RunApprovalRequestInput {
|
|
287
|
+
sessionId: string;
|
|
288
|
+
agentId: string;
|
|
289
|
+
request: {
|
|
290
|
+
kind: 'high_risk' | 'effect';
|
|
291
|
+
toolName: string;
|
|
292
|
+
arguments: Record<string, unknown>;
|
|
293
|
+
riskLevel: 'low' | 'medium' | 'high' | 'critical' | 'unknown';
|
|
294
|
+
riskDescription: string;
|
|
295
|
+
actionDescription: string;
|
|
296
|
+
};
|
|
297
|
+
timeoutMs?: number;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* run 实例进程向 gateway 的控制面推送。审批请求走这里而非 run 流:
|
|
301
|
+
* 工具审批可发生在任意执行上下文,且请求/回执是跨通道配对(notify 出、control 回)。
|
|
302
|
+
*/
|
|
303
|
+
export type RunHostNotify =
|
|
304
|
+
/** 审批请求(gateway 挂 UI 通道;回执走 control 'approvalReply') */
|
|
305
|
+
{
|
|
306
|
+
type: 'approval_request';
|
|
307
|
+
approvalId: string;
|
|
308
|
+
input: RunApprovalRequestInput;
|
|
309
|
+
}
|
|
310
|
+
/** 客户端工具调用(gateway 转发客户端执行;结果走 control 'clientToolResult') */
|
|
311
|
+
| {
|
|
312
|
+
type: 'client_tool_call';
|
|
313
|
+
callId: string;
|
|
314
|
+
sessionId: string;
|
|
315
|
+
agentId: string;
|
|
316
|
+
toolName: string;
|
|
317
|
+
args: Record<string, unknown>;
|
|
318
|
+
/**
|
|
319
|
+
* 调用时刻的 episode 消息列表(ToolExecutionContext.messages 的跨进程还原)。
|
|
320
|
+
* 随桥携带是有意的载荷成本:handler 契约承诺真实 messages,禁以空数组冒充。
|
|
321
|
+
*/
|
|
322
|
+
messages: Message[];
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* 客户端工具调用取消(run 侧中止信号触发)。gateway 据此中止该 callId 的
|
|
326
|
+
* 执行腿(per-call AbortSignal),否则 pending 会挂到 TTL 过期——覆盖不经
|
|
327
|
+
* `abortSession()` 的中止路径(runGuard/budget/引擎内中止等)。
|
|
328
|
+
*/
|
|
329
|
+
| {
|
|
330
|
+
type: 'client_tool_cancel';
|
|
331
|
+
callId: string;
|
|
332
|
+
reason?: string;
|
|
333
|
+
}
|
|
334
|
+
/** out-of-run 会话事件(compact 进度、ClientToolHost 会话事件等;gateway 转 WS/store) */
|
|
335
|
+
| {
|
|
336
|
+
type: 'session_event';
|
|
337
|
+
sessionId: string;
|
|
338
|
+
event: AgentEvent;
|
|
339
|
+
}
|
|
340
|
+
/** inbox 未消费项的原 Trigger 重投(原 registerRuntimeAgent.redispatch 的远程形态) */
|
|
341
|
+
| {
|
|
342
|
+
type: 'redispatch';
|
|
343
|
+
trigger: Trigger;
|
|
344
|
+
}
|
|
345
|
+
/** ask_user 提问(gateway 挂 pending question 等 UI 作答;回执走 control 'askUserReply') */
|
|
346
|
+
| {
|
|
347
|
+
type: 'ask_user_request';
|
|
348
|
+
askId: string;
|
|
349
|
+
sessionId: string;
|
|
350
|
+
agentId: string;
|
|
351
|
+
question: string;
|
|
352
|
+
options?: string[];
|
|
353
|
+
}
|
|
354
|
+
/** 命令注册(skill/用户命令发现结果,数据下发;gateway 注册 UI 命令面) */
|
|
355
|
+
| {
|
|
356
|
+
type: 'commands_registered';
|
|
357
|
+
agentId: string;
|
|
358
|
+
commands: Array<{
|
|
359
|
+
definition: CommandDefinition;
|
|
360
|
+
ref: string;
|
|
361
|
+
}>;
|
|
362
|
+
}
|
|
363
|
+
/** run 侧日志转发(保 [Gateway] 前缀文案的运维 grep 面) */
|
|
364
|
+
| {
|
|
365
|
+
type: 'log';
|
|
366
|
+
level: 'log' | 'warn' | 'error';
|
|
367
|
+
message: string;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* 会话写入已落盘(P1-1 投影收口:检索投影单写者=gateway 门面,§3 表)。
|
|
371
|
+
* run 节点直写会话文件后发此通知(载荷只有 id),gateway 侧节流补投影;
|
|
372
|
+
* 投影可重建非权威(I2),通知丢失仅滞后检索,由 rebuild 兜底。
|
|
373
|
+
*/
|
|
374
|
+
| {
|
|
375
|
+
type: 'session_saved';
|
|
376
|
+
sessionId: string;
|
|
377
|
+
}
|
|
378
|
+
/** 会话删除已落盘(同上收口:gateway 门面据此删投影行) */
|
|
379
|
+
| {
|
|
380
|
+
type: 'session_removed';
|
|
381
|
+
sessionId: string;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* run 终态事件归档(P1-3b,Q3=(a):随会话 jsonl 旁路、门面写):Hub 导出槽
|
|
385
|
+
* timeline 上行,gateway 落 `<sid>.events.jsonl`(历史回放面)。事件为纯数据
|
|
386
|
+
* (RunTimelineEventView 打平,不含引擎类型)。
|
|
387
|
+
*/
|
|
388
|
+
| {
|
|
389
|
+
type: 'run_events_archived';
|
|
390
|
+
sessionId: string;
|
|
391
|
+
events: Array<Record<string, unknown>>;
|
|
392
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run 契约线上协议(arch/service-topology.md §4「P0b 落地形态」)。
|
|
3
|
+
*
|
|
4
|
+
* 两个通道,各司其职:
|
|
5
|
+
* - **契约通道**(gateway → run 实例,loopback HTTP):`POST /runs`(RunRequest →
|
|
6
|
+
* NDJSON `RunStreamEntry` 流)/ `POST /control`(`RunControlOp`)/ `GET /health`;
|
|
7
|
+
* - **宿主通知**(run 实例 → gateway,fork IPC):`RunHostNotify`——审批请求、
|
|
8
|
+
* 客户端工具调用、out-of-run 会话事件、inbox 重投等控制面推送。
|
|
9
|
+
*
|
|
10
|
+
* 纪律:本文件只放**可序列化**数据形状;函数型参数禁止上契约(P0a 债务已随
|
|
11
|
+
* compactSession 数据化清偿)。审批/工具事件直接复用 hooks 既有数据类型(单一来源)。
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* run lease 冲突标记(`supervise: lease_held` 错误文案的判据锚):产生点在
|
|
15
|
+
* FleetRunBackend.startRun(yield* 之前,消息未入上下文);消费点在
|
|
16
|
+
* AgentRuntime.finalizeDelivery 的唤醒重投判定。两端同源此常量,防字符串
|
|
17
|
+
* 跨包漂移。
|
|
18
|
+
*/
|
|
19
|
+
export const RUN_LEASE_HELD_MARKER = 'lease_held';
|
|
@@ -21,6 +21,14 @@ export interface AgentRuntimeConfig {
|
|
|
21
21
|
expectedMaxConcurrentRuns?: number;
|
|
22
22
|
coalesceBufferLimit?: number;
|
|
23
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* trigger 的 lease_held 延迟重投(协调面「唤醒」原语):
|
|
26
|
+
* maxAttempts 缺省 3、delayMs 缺省 2000;human 同样重投(拒可见 + 补达,2026-11-14 插话修复②)。
|
|
27
|
+
*/
|
|
28
|
+
wakeupRetry?: {
|
|
29
|
+
maxAttempts?: number;
|
|
30
|
+
delayMs?: number;
|
|
31
|
+
};
|
|
24
32
|
}
|
|
25
33
|
export declare class AgentRuntime {
|
|
26
34
|
private readonly events?;
|
|
@@ -32,6 +40,10 @@ export declare class AgentRuntime {
|
|
|
32
40
|
private readonly activeRuns;
|
|
33
41
|
private readonly listeners;
|
|
34
42
|
private readonly expectedMaxConcurrentRuns?;
|
|
43
|
+
private readonly wakeupRetryMax;
|
|
44
|
+
private readonly wakeupRetryDelayMs;
|
|
45
|
+
private readonly wakeupAttempts;
|
|
46
|
+
private readonly wakeupScheduled;
|
|
35
47
|
private started;
|
|
36
48
|
constructor(config?: AgentRuntimeConfig);
|
|
37
49
|
get running(): boolean;
|
|
@@ -75,6 +87,27 @@ export declare class AgentRuntime {
|
|
|
75
87
|
* @param options.onDelivery - 活跃 Run 接收即回执(早于 Run 结束)
|
|
76
88
|
*/
|
|
77
89
|
dispatch(trigger: Trigger, options?: import('./types.js').DispatchOptions): Promise<DispatchResult | FanoutDispatchResult>;
|
|
90
|
+
/**
|
|
91
|
+
* 唤醒/重试语义收口(协调面「唤醒」原语的跨进程补齐,B):
|
|
92
|
+
* trigger 被 run 层直拒(RUN_LEASE_HELD_MARKER——同会话并发 run 闸;产生点在
|
|
93
|
+
* 执行前,消息未入上下文)时,按原 Trigger 定向重投至少一次到达。重投走
|
|
94
|
+
* **dispatchToTarget(per-target)**:fan-out 场景只补失败目标,不给已送达
|
|
95
|
+
* 目标重复投递。human 同样重投(宁可重投不可静默丢):本次 'failed' 原样回到
|
|
96
|
+
* 用户可见面(拒可见),重投成功则补达,渠道回复路由由随行的 onEvent/onDelivery
|
|
97
|
+
* 闭包续上(gateway 侧晚到回复按 retryScheduled 标记开启)。
|
|
98
|
+
*
|
|
99
|
+
* @param trigger - 原 Trigger(唤醒凭证)
|
|
100
|
+
* @param target - 失败的路由目标(重投定向)
|
|
101
|
+
* @param result - dispatch 结果
|
|
102
|
+
* @param onEvent - 原派发的事件闭包(重投续用;human 渠道回复路由依赖它)
|
|
103
|
+
* @param onDelivery - 原派发的投递回执闭包(重投续用)
|
|
104
|
+
* @returns 原结果透传 + retryScheduled 标记(重投在后台进行,不吞本次失败)
|
|
105
|
+
*/
|
|
106
|
+
private finalizeDelivery;
|
|
107
|
+
/** 延迟重投(per-target 定向;attempts 上限后 TRIGGER_DROPPED 落账;同键单飞防重复排程)
|
|
108
|
+
* @returns 是否排程成功(false = 预算耗尽已落账 dropped)
|
|
109
|
+
*/
|
|
110
|
+
private scheduleWakeupRetry;
|
|
78
111
|
/**
|
|
79
112
|
* 路由目标的活跃 inbox 接收(human 与 delegation signal 共用)。
|
|
80
113
|
* 仅 message / agent_signal 可接续;其余类型与带附件/换模型输入走完整新 Run。
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* 设计:arch/agent-runtime.md
|
|
8
8
|
*/
|
|
9
9
|
import { CoalesceBuffer } from './coalesce.js';
|
|
10
|
+
import { RUN_LEASE_HELD_MARKER } from './run-protocol.js';
|
|
10
11
|
import { buildRunRequest, compileMessages, resolveSessionId } from './compiler.js';
|
|
11
12
|
import { ExplicitRouter } from './router.js';
|
|
12
13
|
import { RuntimeEvents } from './types.js';
|
|
@@ -35,11 +36,17 @@ export class AgentRuntime {
|
|
|
35
36
|
activeRuns = new Map();
|
|
36
37
|
listeners = new Set();
|
|
37
38
|
expectedMaxConcurrentRuns;
|
|
39
|
+
wakeupRetryMax;
|
|
40
|
+
wakeupRetryDelayMs;
|
|
41
|
+
wakeupAttempts = new Map();
|
|
42
|
+
wakeupScheduled = new Set();
|
|
38
43
|
started = false;
|
|
39
44
|
constructor(config = {}) {
|
|
40
45
|
this.events = config.events;
|
|
41
46
|
this.router = config.router ?? new ExplicitRouter();
|
|
42
47
|
this.expectedMaxConcurrentRuns = config.admission?.expectedMaxConcurrentRuns;
|
|
48
|
+
this.wakeupRetryMax = config.wakeupRetry?.maxAttempts ?? 3;
|
|
49
|
+
this.wakeupRetryDelayMs = config.wakeupRetry?.delayMs ?? 2000;
|
|
43
50
|
this.coalesce = new CoalesceBuffer({
|
|
44
51
|
defaultWindowMs: config.defaultCoalesceMs,
|
|
45
52
|
maxEntries: config.admission?.coalesceBufferLimit ?? config.coalesceBufferLimit ?? 256,
|
|
@@ -249,11 +256,66 @@ export class AgentRuntime {
|
|
|
249
256
|
}
|
|
250
257
|
return { status: 'skipped', reason: 'no_agent' };
|
|
251
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* 唤醒/重试语义收口(协调面「唤醒」原语的跨进程补齐,B):
|
|
261
|
+
* trigger 被 run 层直拒(RUN_LEASE_HELD_MARKER——同会话并发 run 闸;产生点在
|
|
262
|
+
* 执行前,消息未入上下文)时,按原 Trigger 定向重投至少一次到达。重投走
|
|
263
|
+
* **dispatchToTarget(per-target)**:fan-out 场景只补失败目标,不给已送达
|
|
264
|
+
* 目标重复投递。human 同样重投(宁可重投不可静默丢):本次 'failed' 原样回到
|
|
265
|
+
* 用户可见面(拒可见),重投成功则补达,渠道回复路由由随行的 onEvent/onDelivery
|
|
266
|
+
* 闭包续上(gateway 侧晚到回复按 retryScheduled 标记开启)。
|
|
267
|
+
*
|
|
268
|
+
* @param trigger - 原 Trigger(唤醒凭证)
|
|
269
|
+
* @param target - 失败的路由目标(重投定向)
|
|
270
|
+
* @param result - dispatch 结果
|
|
271
|
+
* @param onEvent - 原派发的事件闭包(重投续用;human 渠道回复路由依赖它)
|
|
272
|
+
* @param onDelivery - 原派发的投递回执闭包(重投续用)
|
|
273
|
+
* @returns 原结果透传 + retryScheduled 标记(重投在后台进行,不吞本次失败)
|
|
274
|
+
*/
|
|
275
|
+
finalizeDelivery(trigger, target, result, onEvent, onDelivery) {
|
|
276
|
+
const key = `${trigger.id}:${target.agentId}`;
|
|
277
|
+
if (result.status === 'failed' && result.error.includes(RUN_LEASE_HELD_MARKER)) {
|
|
278
|
+
const scheduled = this.scheduleWakeupRetry(trigger, target, onEvent, onDelivery);
|
|
279
|
+
return { ...result, retryScheduled: scheduled };
|
|
280
|
+
}
|
|
281
|
+
if (result.status === 'ran' || result.status === 'accepted') {
|
|
282
|
+
this.wakeupAttempts.delete(key);
|
|
283
|
+
}
|
|
284
|
+
return result;
|
|
285
|
+
}
|
|
286
|
+
/** 延迟重投(per-target 定向;attempts 上限后 TRIGGER_DROPPED 落账;同键单飞防重复排程)
|
|
287
|
+
* @returns 是否排程成功(false = 预算耗尽已落账 dropped)
|
|
288
|
+
*/
|
|
289
|
+
scheduleWakeupRetry(trigger, target, onEvent, onDelivery) {
|
|
290
|
+
const key = `${trigger.id}:${target.agentId}`;
|
|
291
|
+
if (this.wakeupScheduled.has(key))
|
|
292
|
+
return true; // 已排程:不重复排(同键单飞)
|
|
293
|
+
const attempts = this.wakeupAttempts.get(key) ?? 0;
|
|
294
|
+
if (attempts >= this.wakeupRetryMax) {
|
|
295
|
+
this.wakeupAttempts.delete(key);
|
|
296
|
+
this.emitRuntime(RuntimeEvents.TRIGGER_DROPPED, {
|
|
297
|
+
triggerRef: toTriggerRef(trigger),
|
|
298
|
+
triggerId: trigger.id,
|
|
299
|
+
reason: RUN_LEASE_HELD_MARKER,
|
|
300
|
+
});
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
this.wakeupAttempts.set(key, attempts + 1);
|
|
304
|
+
this.wakeupScheduled.add(key);
|
|
305
|
+
setTimeout(() => {
|
|
306
|
+
this.wakeupScheduled.delete(key);
|
|
307
|
+
void this.dispatchToTarget(trigger, target, { onEvent, onDelivery }).catch(() => {
|
|
308
|
+
// 重投自身的调度失败由下一轮 finalize/DROPPED 落账;这里不吞错——
|
|
309
|
+
// 仅避免 unhandled rejection(dispatch 内部已 fail-loud 事件化)。
|
|
310
|
+
});
|
|
311
|
+
}, this.wakeupRetryDelayMs);
|
|
312
|
+
return true;
|
|
313
|
+
}
|
|
252
314
|
/**
|
|
253
315
|
* 路由目标的活跃 inbox 接收(human 与 delegation signal 共用)。
|
|
254
316
|
* 仅 message / agent_signal 可接续;其余类型与带附件/换模型输入走完整新 Run。
|
|
255
317
|
*/
|
|
256
|
-
offerToTarget(trigger, target, sessionId, onEvent) {
|
|
318
|
+
async offerToTarget(trigger, target, sessionId, onEvent) {
|
|
257
319
|
if (!target.dispatcher.inbox)
|
|
258
320
|
return 'dispatched';
|
|
259
321
|
if (trigger.type !== 'message' && trigger.type !== 'agent_signal')
|
|
@@ -261,27 +323,40 @@ export class AgentRuntime {
|
|
|
261
323
|
const [compiledMessage] = compileMessages([trigger]);
|
|
262
324
|
const human = trigger.type === 'message' && trigger.payload.kind === 'user_message';
|
|
263
325
|
const delegationId = trigger.metadata?.delegationId;
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
326
|
+
try {
|
|
327
|
+
return await target.dispatcher.inbox.offer({
|
|
328
|
+
agentId: target.agentId,
|
|
329
|
+
sessionId,
|
|
330
|
+
entryId: delegationId ?? trigger.id,
|
|
331
|
+
triggerType: trigger.type,
|
|
332
|
+
human,
|
|
333
|
+
modelOverride: trigger.metadata?.modelOverride,
|
|
334
|
+
modelProvider: trigger.metadata?.modelProvider,
|
|
335
|
+
trigger,
|
|
336
|
+
onEvent,
|
|
337
|
+
message: compiledMessage,
|
|
338
|
+
onAdmitted: (delivery) => {
|
|
339
|
+
try {
|
|
340
|
+
this.emitRuntime(RuntimeEvents.INBOX_ADMITTED, {
|
|
341
|
+
triggerId: trigger.id,
|
|
342
|
+
agentId: target.agentId,
|
|
343
|
+
sessionId,
|
|
344
|
+
delegationId,
|
|
345
|
+
delivery,
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
catch {
|
|
349
|
+
// 观测事件不得影响投递语义(admitted 后抛错会被外层 fail-open 翻成
|
|
350
|
+
// 'dispatched' = 双投)——通知是尽力而为面
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
catch {
|
|
356
|
+
// 协调面「插话」fail-open(语义权威点):offer 通道失败不吞消息,
|
|
357
|
+
// 一律回到 'dispatched' 由调用方照常 dispatch 新 Run 送达。
|
|
358
|
+
return 'dispatched';
|
|
359
|
+
}
|
|
285
360
|
}
|
|
286
361
|
async dispatchToTarget(trigger, target, options) {
|
|
287
362
|
const agent = this.agents.get(target.agentId);
|
|
@@ -294,12 +369,25 @@ export class AgentRuntime {
|
|
|
294
369
|
});
|
|
295
370
|
// 单一 offer 点:活跃 Run 接收 = 不再开新 Run(原 Trigger 不 dispatch,
|
|
296
371
|
// Run 关闭未消费时由 inbox 按原 Trigger 重投)
|
|
297
|
-
const offerResult = this.offerToTarget(trigger, agent, sessionId, options?.onEvent);
|
|
372
|
+
const offerResult = await this.offerToTarget(trigger, agent, sessionId, options?.onEvent);
|
|
298
373
|
if (offerResult === 'continued' || offerResult === 'duplicate') {
|
|
299
|
-
|
|
300
|
-
|
|
374
|
+
if (offerResult === 'continued') {
|
|
375
|
+
options?.onDelivery?.('continued');
|
|
376
|
+
// 插话送达即本周期成功:清重投计数(否则残留计数会让下一轮冲突提前耗尽)
|
|
377
|
+
this.wakeupAttempts.delete(`${trigger.id}:${agent.agentId}`);
|
|
378
|
+
}
|
|
379
|
+
// duplicate(同 id 已受理/已入上下文)不回执 continued、不抑制调用方同步回复:
|
|
380
|
+
// at-least-once 重投的去重出口——重复投递不重复执行也不重复回答(回答由
|
|
381
|
+
// 首次受理的那条路由负责),但也不冒充「已续接」误导调用方晚到回复闭包。
|
|
382
|
+
return {
|
|
383
|
+
status: 'accepted',
|
|
384
|
+
agentId: agent.agentId,
|
|
385
|
+
sessionId,
|
|
386
|
+
delivery: offerResult,
|
|
387
|
+
};
|
|
301
388
|
}
|
|
302
389
|
options?.onDelivery?.('run');
|
|
390
|
+
const finalize = (result) => this.finalizeDelivery(trigger, agent, result, options?.onEvent, options?.onDelivery);
|
|
303
391
|
if (trigger.coalesceKey) {
|
|
304
392
|
this.emitRuntime(RuntimeEvents.RUN_SCHEDULED, {
|
|
305
393
|
triggerId: trigger.id,
|
|
@@ -315,11 +403,11 @@ export class AgentRuntime {
|
|
|
315
403
|
onFlush: (triggers, onEvent) => this.executeTriggers(agent, triggers, sessionId, onEvent ?? options?.onEvent),
|
|
316
404
|
});
|
|
317
405
|
if (result.kind === 'no_key' || result.kind === 'buffer_full') {
|
|
318
|
-
return this.executeTriggers(agent, [trigger], sessionId, options?.onEvent);
|
|
406
|
+
return finalize(await this.executeTriggers(agent, [trigger], sessionId, options?.onEvent));
|
|
319
407
|
}
|
|
320
|
-
return result.done;
|
|
408
|
+
return finalize(await result.done);
|
|
321
409
|
}
|
|
322
|
-
return this.executeTriggers(agent, [trigger], sessionId, options?.onEvent);
|
|
410
|
+
return finalize(await this.executeTriggers(agent, [trigger], sessionId, options?.onEvent));
|
|
323
411
|
}
|
|
324
412
|
async executeTriggers(agent, triggers, sessionId, onEvent) {
|
|
325
413
|
if (!this.started) {
|
|
@@ -335,10 +423,13 @@ export class AgentRuntime {
|
|
|
335
423
|
: triggers
|
|
336
424
|
.map((t) => ('source' in t.payload ? t.payload.source?.senderId : undefined))
|
|
337
425
|
.find((id) => typeof id === 'string' && id.length > 0);
|
|
426
|
+
// §9.1-6:触发源租户(渠道锚等)随 Trigger 传播 → run principal 归属
|
|
427
|
+
const tenantId = triggers.map((t) => t.tenantId).find((id) => typeof id === 'string' && id.length > 0);
|
|
338
428
|
const request = buildRunRequest(agent, triggers, sessionId, {
|
|
339
429
|
actorType: isScheduleWake ? 'timer' : senderId ? 'user' : undefined,
|
|
340
430
|
actorId: isScheduleWake ? (triggers[0]?.metadata?.reason ?? triggers[0]?.id) : senderId,
|
|
341
431
|
intent: isScheduleWake ? 'schedule_wake' : undefined,
|
|
432
|
+
...(tenantId === undefined ? {} : { tenantId }),
|
|
342
433
|
});
|
|
343
434
|
const controller = new AbortController();
|
|
344
435
|
const run = {
|