@octopi-agent/engine 0.98.4 → 0.102.10
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/config-schema/agent.d.ts +35 -5
- package/dist/config-schema/agent.js +24 -4
- package/dist/config-schema/context.d.ts +6 -36
- package/dist/config-schema/context.js +4 -28
- package/dist/config-schema/engine.d.ts +57 -160
- package/dist/config-schema/engine.js +1 -5
- package/dist/config-schema/governance.d.ts +8 -1
- package/dist/config-schema/governance.js +8 -1
- package/dist/config-schema/models.d.ts +2 -8
- package/dist/config-schema/models.js +0 -2
- package/dist/config-schema/run.d.ts +2 -2
- package/dist/config-schema/run.js +2 -2
- package/dist/config-schema/shared.d.ts +0 -3
- package/dist/config-schema/shared.js +0 -2
- package/dist/config-schema/substrate.d.ts +14 -88
- package/dist/config-schema/substrate.js +22 -107
- package/dist/config.d.ts +45 -113
- package/dist/config.js +8 -2
- package/dist/harness/activation/dispatcher.js +7 -0
- package/dist/harness/activation/inbox.d.ts +3 -3
- package/dist/harness/activation/inbox.js +3 -3
- package/dist/harness/activation/runtime.js +13 -5
- package/dist/harness/activation/types.d.ts +2 -2
- package/dist/harness/agent/builder.d.ts +24 -3
- package/dist/harness/agent/builder.js +131 -27
- package/dist/harness/agent/config-bridge.js +9 -2
- package/dist/harness/agent/config-integrity.js +19 -2
- package/dist/harness/agent/wire-agent-builder.d.ts +11 -3
- package/dist/harness/agent/wire-agent-builder.js +26 -7
- package/dist/harness/capabilities/document/factory.d.ts +5 -0
- package/dist/harness/capabilities/document/factory.js +1 -0
- package/dist/harness/capabilities/document/port.js +6 -3
- package/dist/harness/capabilities/document/types.d.ts +5 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/sense/input-builder.js +4 -4
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.js +25 -4
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +3 -3
- package/dist/harness/collaboration/delegation/child-run.d.ts +1 -1
- package/dist/harness/collaboration/delegation/child-run.js +4 -4
- package/dist/harness/collaboration/delegation/index.d.ts +1 -1
- package/dist/harness/collaboration/delegation/index.js +1 -1
- package/dist/harness/collaboration/delegation/notifier.d.ts +6 -1
- package/dist/harness/collaboration/delegation/notifier.js +8 -1
- package/dist/harness/collaboration/delegation/service.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.js +2 -1
- package/dist/harness/collaboration/delegation/store.d.ts +2 -0
- package/dist/harness/collaboration/delegation/store.js +2 -1
- package/dist/harness/collaboration/delegation/types.d.ts +23 -2
- package/dist/harness/collaboration/delegation/types.js +22 -0
- package/dist/harness/collaboration/delegation/wiring.js +11 -1
- package/dist/harness/context/budget-allocator.d.ts +26 -18
- package/dist/harness/context/budget-allocator.js +67 -32
- package/dist/harness/context/capabilities/compact/engine.d.ts +0 -6
- package/dist/harness/context/capabilities/compact/engine.js +169 -121
- package/dist/harness/context/capabilities/compact/handover.d.ts +5 -3
- package/dist/harness/context/capabilities/compact/handover.js +7 -5
- package/dist/harness/context/capabilities/compact/index.d.ts +5 -1
- package/dist/harness/context/capabilities/compact/index.js +4 -0
- package/dist/harness/context/capabilities/compact/mechanical.d.ts +130 -0
- package/dist/harness/context/capabilities/compact/mechanical.js +268 -0
- package/dist/harness/context/capabilities/compact/messages.d.ts +60 -0
- package/dist/harness/context/capabilities/compact/messages.js +91 -0
- package/dist/harness/context/capabilities/compact/types.d.ts +76 -11
- package/dist/harness/context/capabilities/compact/types.js +11 -1
- package/dist/harness/context/capabilities/compact/view-split.d.ts +36 -0
- package/dist/harness/context/capabilities/compact/view-split.js +72 -0
- package/dist/harness/context/capabilities/summary/port.js +0 -1
- package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/resolver.js +1 -6
- package/dist/harness/context/capabilities/summary/tool-binding.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/types.d.ts +3 -6
- package/dist/harness/context/context-size-ledger.d.ts +143 -0
- package/dist/harness/context/context-size-ledger.js +236 -0
- package/dist/harness/context/default-context-engine.d.ts +195 -119
- package/dist/harness/context/default-context-engine.js +1241 -743
- package/dist/harness/context/index.d.ts +2 -2
- package/dist/harness/context/index.js +1 -1
- package/dist/harness/context/layer-types.d.ts +15 -0
- package/dist/harness/context/layer-types.js +14 -1
- package/dist/harness/context/layers.d.ts +14 -15
- package/dist/harness/context/layers.js +41 -11
- package/dist/harness/context/message-selector.d.ts +10 -8
- package/dist/harness/context/message-selector.js +49 -27
- package/dist/harness/context/summarize.d.ts +2 -2
- package/dist/harness/context/summarize.js +9 -2
- package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
- package/dist/harness/context/system-prompt-assembler.js +2 -1
- package/dist/harness/context/token-constants.d.ts +8 -6
- package/dist/harness/context/token-constants.js +8 -7
- package/dist/harness/context/token-estimate-fns.d.ts +37 -27
- package/dist/harness/context/token-estimate-fns.js +85 -66
- package/dist/harness/context/token-estimator.d.ts +27 -12
- package/dist/harness/context/token-estimator.js +120 -66
- package/dist/harness/context/token-segments.d.ts +88 -0
- package/dist/harness/context/token-segments.js +103 -0
- package/dist/harness/context/tool-result-aging.d.ts +6 -1
- package/dist/harness/context/tool-result-aging.js +16 -5
- package/dist/harness/context/tool-result-body.js +2 -0
- package/dist/harness/context/transform/anchors.d.ts +66 -0
- package/dist/harness/context/transform/anchors.js +125 -0
- package/dist/harness/context/transform/fold.d.ts +56 -0
- package/dist/harness/context/transform/fold.js +135 -0
- package/dist/harness/context/transform/migrate.d.ts +41 -0
- package/dist/harness/context/transform/migrate.js +69 -0
- package/dist/harness/context/transform/types.d.ts +129 -0
- package/dist/harness/context/transform/types.js +19 -0
- package/dist/harness/context/turn-envelope.d.ts +6 -3
- package/dist/harness/context/types.d.ts +127 -117
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +1 -1
- package/dist/harness/extension/execution-environment/resource-limits.d.ts +1 -1
- package/dist/harness/extension/execution-environment/resource-limits.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/commands/index.d.ts +3 -1
- package/dist/harness/extension/plugin-ecosystem/commands/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.d.ts +12 -1
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.js +14 -4
- package/dist/harness/extension/plugin-ecosystem/commands/router.d.ts +5 -4
- package/dist/harness/extension/plugin-ecosystem/commands/router.js +23 -14
- package/dist/harness/extension/plugin-ecosystem/commands/types.d.ts +8 -1
- package/dist/harness/extension/plugin-ecosystem/commands/types.js +2 -1
- package/dist/harness/extension/plugin-ecosystem/hooks/adapter.d.ts +54 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/adapter.js +397 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.d.ts +16 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.js +66 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/index.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/index.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.d.ts +11 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.js +54 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/journal.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/journal.js +22 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.d.ts +12 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.js +19 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.d.ts +36 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.js +338 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/services.d.ts +24 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/services.js +139 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/types.d.ts +229 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/types.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +83 -249
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +88 -214
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +43 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +61 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.js +18 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +7 -85
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +8 -50
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +6 -23
- package/dist/harness/extension/plugin-ecosystem/plugins/index.js +3 -23
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +50 -117
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +316 -285
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +23 -490
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +85 -353
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +41 -223
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +138 -19
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +15 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +15 -0
- package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +6 -1
- package/dist/harness/extension/plugin-ecosystem/skills/manager.js +17 -1
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +3 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +46 -21
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -8
- package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.d.ts +11 -0
- package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.js +39 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +11 -2
- package/dist/harness/governance/accounting/usage-ledger.d.ts +13 -1
- package/dist/harness/governance/accounting/usage-ledger.js +23 -1
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +3 -3
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +2 -2
- package/dist/harness/governance/security/capability-enforcer.js +1 -2
- package/dist/harness/index.d.ts +12 -12
- package/dist/harness/index.js +7 -7
- package/dist/harness/knowledge/boot-config.d.ts +55 -0
- package/dist/harness/knowledge/boot-config.js +50 -0
- package/dist/harness/knowledge/catalog-types.d.ts +2 -0
- package/dist/harness/knowledge/client.d.ts +24 -2
- package/dist/harness/knowledge/client.js +19 -5
- package/dist/harness/knowledge/db.js +5 -0
- package/dist/harness/knowledge/describe-sample.d.ts +23 -0
- package/dist/harness/knowledge/describe-sample.js +58 -0
- package/dist/harness/knowledge/describe.d.ts +8 -0
- package/dist/harness/knowledge/describe.js +18 -2
- package/dist/harness/knowledge/engine-thread.js +6 -0
- package/dist/harness/knowledge/grounding.js +3 -1
- package/dist/harness/knowledge/http-app.js +35 -4
- package/dist/harness/knowledge/http-params.d.ts +18 -0
- package/dist/harness/knowledge/http-params.js +24 -0
- package/dist/harness/knowledge/index.d.ts +2 -0
- package/dist/harness/knowledge/index.js +1 -0
- package/dist/harness/knowledge/knowledge-serve-child.js +3 -0
- package/dist/harness/knowledge/purge.js +5 -2
- package/dist/harness/knowledge/query-service.d.ts +13 -2
- package/dist/harness/knowledge/query-service.js +4 -2
- package/dist/harness/knowledge/query-worker-client.d.ts +9 -1
- package/dist/harness/knowledge/query-worker-client.js +4 -2
- package/dist/harness/knowledge/query-worker.js +4 -2
- package/dist/harness/knowledge/read-http.js +5 -1
- package/dist/harness/knowledge/serve.d.ts +8 -7
- package/dist/harness/knowledge/serve.js +9 -0
- package/dist/harness/knowledge/source-store.js +26 -3
- package/dist/harness/knowledge/start-service-process.d.ts +15 -7
- package/dist/harness/knowledge/start-service-process.js +21 -9
- package/dist/harness/knowledge/types.d.ts +7 -0
- package/dist/harness/knowledge/writer-service.d.ts +37 -9
- package/dist/harness/knowledge/writer-service.js +120 -14
- package/dist/harness/knowledge/writer-worker-client.d.ts +10 -9
- package/dist/harness/knowledge/writer-worker-client.js +20 -2
- package/dist/harness/knowledge/writer-worker.js +9 -1
- package/dist/harness/memory/sqlite/wisdom-store.js +35 -10
- package/dist/harness/memory/types.d.ts +6 -4
- package/dist/harness/memory/wisdom-formation.d.ts +14 -3
- package/dist/harness/memory/wisdom-formation.js +85 -22
- package/dist/harness/memory/wisdom-gates.d.ts +14 -0
- package/dist/harness/memory/wisdom-gates.js +59 -19
- package/dist/harness/memory/wisdom.js +9 -0
- package/dist/harness/observability/observer/hub.js +25 -15
- package/dist/harness/observability/observer/types.d.ts +10 -6
- package/dist/harness/run/agent/agent.d.ts +40 -21
- package/dist/harness/run/agent/agent.js +66 -13
- package/dist/harness/run/agent/index.d.ts +1 -1
- package/dist/harness/run/budget/budget.d.ts +28 -10
- package/dist/harness/run/budget/budget.js +38 -15
- package/dist/harness/run/model/index.d.ts +3 -1
- package/dist/harness/run/model/index.js +2 -1
- package/dist/harness/run/model/resolver.d.ts +4 -1
- package/dist/harness/run/model/resolver.js +36 -2
- package/dist/harness/run/model/run-scope.d.ts +2 -0
- package/dist/harness/run/model/run-scope.js +7 -0
- package/dist/harness/run/model/types.d.ts +22 -5
- package/dist/harness/run/model/types.js +3 -2
- package/dist/harness/run/model/window-truth.d.ts +37 -0
- package/dist/harness/run/model/window-truth.js +39 -0
- package/dist/harness/run/reliability/context-length-feedback.d.ts +77 -0
- package/dist/harness/run/reliability/context-length-feedback.js +128 -0
- package/dist/harness/run/reliability/harness-events.d.ts +3 -3
- package/dist/harness/run/reliability/model-error-policy.js +4 -0
- package/dist/harness/run/reliability/run-agent.d.ts +10 -4
- package/dist/harness/run/reliability/run-agent.js +137 -53
- package/dist/harness/run/reliability/run-metrics-collector.d.ts +19 -8
- package/dist/harness/run/reliability/run-metrics-collector.js +38 -23
- package/dist/harness/run/run-guard/default-run-guard.js +8 -8
- package/dist/harness/run/run-scope.d.ts +37 -4
- package/dist/harness/run/runner.d.ts +44 -29
- package/dist/harness/run/runner.js +320 -102
- package/dist/harness/session/attachments/index.d.ts +1 -0
- package/dist/harness/session/attachments/index.js +1 -0
- package/dist/harness/session/attachments/inject.d.ts +21 -10
- package/dist/harness/session/attachments/inject.js +76 -24
- package/dist/harness/session/attachments/recall-index.d.ts +70 -0
- package/dist/harness/session/attachments/recall-index.js +219 -0
- package/dist/harness/session/attachments/service.d.ts +21 -0
- package/dist/harness/session/attachments/service.js +258 -139
- package/dist/harness/session/attachments/types.d.ts +6 -0
- package/dist/harness/session/transform-store.d.ts +136 -0
- package/dist/harness/session/transform-store.js +302 -0
- package/dist/harness/session/types.d.ts +2 -2
- package/dist/harness/shared/events/agent-event-map.d.ts +46 -13
- package/dist/harness/shared/events/agent-event-map.js +3 -2
- package/dist/harness/shared/events/scenario-events.d.ts +6 -6
- package/dist/harness/shared/types/agent-definition.d.ts +1 -2
- package/dist/index.d.ts +14 -17
- package/dist/index.js +7 -9
- package/dist/integration/observability/metrics.d.ts +6 -6
- package/dist/integration/observability/metrics.js +13 -13
- package/dist/integration/observability/observer-bridge.js +2 -2
- package/dist/integration/observability/trace-collector.d.ts +5 -5
- package/dist/integration/observability/trace-collector.js +34 -35
- package/dist/integration/observability/trace-events.d.ts +3 -3
- package/dist/integration/observability/trace-events.js +3 -3
- package/dist/integration/providers/anthropic.js +14 -1
- package/dist/integration/providers/openai.js +7 -1
- package/dist/integration/providers/usage.d.ts +1 -1
- package/dist/integration/providers/wire-dump.d.ts +1 -1
- package/dist/integration/storage/archive-manager.d.ts +6 -0
- package/dist/integration/storage/archive-manager.js +10 -0
- package/dist/integration/storage/jsonl.d.ts +1 -1
- package/dist/integration/storage/jsonl.js +18 -16
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +8 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +1 -0
- package/dist/subsystems/wisdom-steward/formation/handler.js +27 -5
- package/package.json +11 -14
- package/dist/harness/context/hybrid-compressor.d.ts +0 -41
- package/dist/harness/context/hybrid-compressor.js +0 -159
- package/dist/harness/context/llm-summarizer.d.ts +0 -46
- package/dist/harness/context/llm-summarizer.js +0 -249
- package/dist/harness/context/smart-router.d.ts +0 -75
- package/dist/harness/context/smart-router.js +0 -118
- package/dist/harness/context/truncate-compressor.d.ts +0 -28
- package/dist/harness/context/truncate-compressor.js +0 -107
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -97
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -155
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.d.ts +0 -7
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.js +0 -7
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.d.ts +0 -86
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.js +0 -139
|
@@ -21,7 +21,7 @@ export function buildAgentInput(spec, ctx) {
|
|
|
21
21
|
input.sessionMetadata = {
|
|
22
22
|
agentId: ctx.runConfig.agentId ?? 'unknown',
|
|
23
23
|
sessionId: ctx.runConfig.sessionId ?? 'unknown',
|
|
24
|
-
|
|
24
|
+
stepCount: ctx.messages.filter((m) => m.role === 'assistant').length,
|
|
25
25
|
sessionLifecycle: ctx.sessionLifecycle,
|
|
26
26
|
lastInteractionAt: ctx.lastInteractionAt,
|
|
27
27
|
idleMs: ctx.idleMs,
|
|
@@ -53,7 +53,7 @@ export function buildAgentInput(spec, ctx) {
|
|
|
53
53
|
input.sessionMetadata = {
|
|
54
54
|
agentId: ctx.runConfig.agentId ?? 'unknown',
|
|
55
55
|
sessionId: ctx.runConfig.sessionId ?? 'unknown',
|
|
56
|
-
|
|
56
|
+
stepCount: ctx.messages.filter((m) => m.role === 'assistant').length,
|
|
57
57
|
};
|
|
58
58
|
break;
|
|
59
59
|
case 'token_count':
|
|
@@ -72,7 +72,7 @@ export function buildAgentInput(spec, ctx) {
|
|
|
72
72
|
...(input.sessionMetadata ?? {
|
|
73
73
|
agentId: ctx.runConfig.agentId ?? 'unknown',
|
|
74
74
|
sessionId: ctx.runConfig.sessionId ?? 'unknown',
|
|
75
|
-
|
|
75
|
+
stepCount: ctx.messages.filter((m) => m.role === 'assistant').length,
|
|
76
76
|
}),
|
|
77
77
|
sessionLifecycle: ctx.sessionLifecycle,
|
|
78
78
|
lastInteractionAt: ctx.lastInteractionAt,
|
|
@@ -93,7 +93,7 @@ export function buildAgentInput(spec, ctx) {
|
|
|
93
93
|
input.sessionMetadata = {
|
|
94
94
|
agentId: ctx.runConfig.agentId ?? 'unknown',
|
|
95
95
|
sessionId: ctx.runConfig.sessionId ?? 'unknown',
|
|
96
|
-
|
|
96
|
+
stepCount: ctx.messages.filter((m) => m.role === 'assistant').length,
|
|
97
97
|
};
|
|
98
98
|
if (ctx.pendingToolCall)
|
|
99
99
|
input.pendingToolCall = ctx.pendingToolCall;
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
/**
|
|
10
10
|
* MetricsStore — 线程安全的指标存储
|
|
11
11
|
*
|
|
12
|
-
* 存储主循环注入的运行时指标(如
|
|
12
|
+
* 存储主循环注入的运行时指标(如 step.count、token.used 等),
|
|
13
13
|
* 供 SenseEngine 的 condition 表达式评估使用。
|
|
14
14
|
*/
|
|
15
15
|
export declare class MetricsStore {
|
|
@@ -17,7 +17,7 @@ export declare class MetricsStore {
|
|
|
17
17
|
/**
|
|
18
18
|
* 更新指标值
|
|
19
19
|
*
|
|
20
|
-
* @param key - 指标名(如 '
|
|
20
|
+
* @param key - 指标名(如 'step.count')
|
|
21
21
|
* @param value - 指标值
|
|
22
22
|
*/
|
|
23
23
|
update(key: string, value: number): void;
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
/**
|
|
10
10
|
* MetricsStore — 线程安全的指标存储
|
|
11
11
|
*
|
|
12
|
-
* 存储主循环注入的运行时指标(如
|
|
12
|
+
* 存储主循环注入的运行时指标(如 step.count、token.used 等),
|
|
13
13
|
* 供 SenseEngine 的 condition 表达式评估使用。
|
|
14
14
|
*/
|
|
15
15
|
export class MetricsStore {
|
|
@@ -17,7 +17,7 @@ export class MetricsStore {
|
|
|
17
17
|
/**
|
|
18
18
|
* 更新指标值
|
|
19
19
|
*
|
|
20
|
-
* @param key - 指标名(如 '
|
|
20
|
+
* @param key - 指标名(如 'step.count')
|
|
21
21
|
* @param value - 指标值
|
|
22
22
|
*/
|
|
23
23
|
update(key, value) {
|
|
@@ -32,6 +32,12 @@ export interface ContextInjection {
|
|
|
32
32
|
messages: Array<{
|
|
33
33
|
role: 'system' | 'user' | 'assistant';
|
|
34
34
|
content: string;
|
|
35
|
+
/** 载体标记(engineHint 等);isTurnAnchor/回放按此判语义 */
|
|
36
|
+
metadata?: {
|
|
37
|
+
source?: string;
|
|
38
|
+
};
|
|
39
|
+
/** 状态快照类注入:同 run 只留最新一份,不落库 */
|
|
40
|
+
ephemeral?: boolean;
|
|
35
41
|
}>;
|
|
36
42
|
/** 是否标记为压缩结果 */
|
|
37
43
|
compressed?: boolean;
|
|
@@ -84,7 +84,12 @@ export class SignalBus {
|
|
|
84
84
|
messages.push({
|
|
85
85
|
...msg,
|
|
86
86
|
timestamp: Date.now(),
|
|
87
|
-
|
|
87
|
+
// P0-B 同范式:统一 engineHint 载体(ENGINE_CARRIER_SOURCES 成员,
|
|
88
|
+
// 不被 isTurnAnchor 认作轮锚点——否则信号更新会钉死老化边界);
|
|
89
|
+
// compressed 快照保留既有标记。上游 metadata 不透传:载体内涵由本转换定义。
|
|
90
|
+
metadata: injection.compressed
|
|
91
|
+
? { compressed: true, source: 'engineHint' }
|
|
92
|
+
: { source: 'engineHint' },
|
|
88
93
|
});
|
|
89
94
|
}
|
|
90
95
|
}
|
|
@@ -159,15 +164,31 @@ export class SignalBus {
|
|
|
159
164
|
if (signal.action === 'replace') {
|
|
160
165
|
this.contextQueue.push({
|
|
161
166
|
subsystemId,
|
|
162
|
-
|
|
167
|
+
// 状态快照:engineHint 载体 + ephemeral(同 run 只留最新一份,不落库)
|
|
168
|
+
messages: [
|
|
169
|
+
{
|
|
170
|
+
role: 'user',
|
|
171
|
+
content: signal.reason,
|
|
172
|
+
ephemeral: true,
|
|
173
|
+
metadata: { source: 'engineHint' },
|
|
174
|
+
},
|
|
175
|
+
],
|
|
163
176
|
compressed: true,
|
|
164
177
|
});
|
|
165
178
|
}
|
|
166
179
|
else {
|
|
167
|
-
// suggest / alert →
|
|
180
|
+
// suggest / alert → 注入为引擎提示(user 形态 + engineHint 标记,随历史保留)。
|
|
181
|
+
// 不用 role:'system':非托管 system 会被 provider 适配层拼进 system 字段,
|
|
182
|
+
// 状态变化即前缀整段失效(context-size-accounting.md §1)。
|
|
168
183
|
this.contextQueue.push({
|
|
169
184
|
subsystemId,
|
|
170
|
-
messages: [
|
|
185
|
+
messages: [
|
|
186
|
+
{
|
|
187
|
+
role: 'user',
|
|
188
|
+
content: `[${signal.action}] ${signal.reason}`,
|
|
189
|
+
metadata: { source: 'engineHint' },
|
|
190
|
+
},
|
|
191
|
+
],
|
|
171
192
|
});
|
|
172
193
|
}
|
|
173
194
|
}
|
|
@@ -121,7 +121,7 @@ export class ThinkExecutor {
|
|
|
121
121
|
if (event.type === 'assistant_message') {
|
|
122
122
|
lastContent = typeof event.message.content === 'string' ? event.message.content : '';
|
|
123
123
|
}
|
|
124
|
-
if (event.type === '
|
|
124
|
+
if (event.type === 'step_end' && event.usage) {
|
|
125
125
|
const u = event.usage;
|
|
126
126
|
tokenUsage = {
|
|
127
127
|
prompt: u.inputReportedTokens ??
|
|
@@ -75,7 +75,7 @@ export type ContextField = 'task_summary' | 'tool_calls' | 'tool_results' | 'wor
|
|
|
75
75
|
export interface SenseFilter {
|
|
76
76
|
/** 监听的事件类型(source=eventBus 时) */
|
|
77
77
|
events?: string[];
|
|
78
|
-
/** 声明式条件表达式(如 "
|
|
78
|
+
/** 声明式条件表达式(如 "step.count % 10 === 0") */
|
|
79
79
|
condition?: string;
|
|
80
80
|
/** 代码引用(如 "./handler.ts:shouldExtract"),与 condition 互斥 */
|
|
81
81
|
conditionRef?: string;
|
|
@@ -130,7 +130,7 @@ export interface ThinkConfig {
|
|
|
130
130
|
/** 模型级别引用(如 "mini"、"standard"、"pro")或 provider/model 格式 */
|
|
131
131
|
model?: string;
|
|
132
132
|
/** 最大推理轮次(默认 1) */
|
|
133
|
-
|
|
133
|
+
maxSteps?: number;
|
|
134
134
|
/** hybrid 模式的预处理函数 */
|
|
135
135
|
preProcess?: (input: SubsystemInput) => Promise<SubsystemInput>;
|
|
136
136
|
/** hybrid 模式的后处理函数 */
|
|
@@ -306,7 +306,7 @@ export interface SubsystemInput {
|
|
|
306
306
|
sessionMetadata?: {
|
|
307
307
|
agentId: string;
|
|
308
308
|
sessionId: string;
|
|
309
|
-
|
|
309
|
+
stepCount: number;
|
|
310
310
|
} & Record<string, unknown>;
|
|
311
311
|
/** Token 使用量 */
|
|
312
312
|
tokenCount?: {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* 本端口管"目标本地怎么起 Run"。两者不可互相渗透。
|
|
19
19
|
*/
|
|
20
20
|
import type { SessionStore } from '@octopi-agent/core/interfaces/session-store.js';
|
|
21
|
-
import type { TokenUsage } from '@octopi-agent/core/types/
|
|
21
|
+
import type { TokenUsage } from '@octopi-agent/core/types/step.js';
|
|
22
22
|
import type { AgentEvent } from '@octopi-agent/core/primitives/event-bus.js';
|
|
23
23
|
import type { SessionData, SessionSpawnLink } from '../../session/types.js';
|
|
24
24
|
import type { DelegationBudget, DelegationContextMode } from './types.js';
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
* transport 管"怎么把请求送到目标"(进程内 / 将来跨进程);
|
|
18
18
|
* 本端口管"目标本地怎么起 Run"。两者不可互相渗透。
|
|
19
19
|
*/
|
|
20
|
-
import { emptyTokenUsage } from '@octopi-agent/core/types/
|
|
20
|
+
import { emptyTokenUsage } from '@octopi-agent/core/types/step.js';
|
|
21
21
|
/**
|
|
22
|
-
* 累加
|
|
22
|
+
* 累加 step 级 usage 到总账(决策 C2:归集到父的 run 账)
|
|
23
23
|
*
|
|
24
24
|
* @param total - 累计账本(原地更新)
|
|
25
25
|
* @param add - 本轮 usage
|
|
@@ -92,7 +92,7 @@ export class RunnerChildRunPort {
|
|
|
92
92
|
try {
|
|
93
93
|
for await (const event of target.runner.handle(childSessionId, userMessage, runConfig, signal)) {
|
|
94
94
|
switch (event.type) {
|
|
95
|
-
case '
|
|
95
|
+
case 'step.end': {
|
|
96
96
|
const data = event.data;
|
|
97
97
|
// 失败尝试的 content 是中断残句,不是委派结果;error 布尔标记也不是错误文本
|
|
98
98
|
//(String(true)='true' 会占位并挡住后面 engine.error 的真消息)
|
|
@@ -160,7 +160,7 @@ export class RunnerChildRunPort {
|
|
|
160
160
|
status: 'idle',
|
|
161
161
|
},
|
|
162
162
|
messages: [],
|
|
163
|
-
|
|
163
|
+
steps: [],
|
|
164
164
|
metadata: { delegationId: input.delegationId },
|
|
165
165
|
};
|
|
166
166
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* + `AgentHandle`(D2 寻址)+ `DelegateTransport`(唯一分布式缝)。
|
|
9
9
|
*/
|
|
10
10
|
export type { Delegation, DelegationBudget, DelegationContextMode, DelegationEventType, DelegationParentRef, DelegationStatus, DelegationTarget, DelegateRequest, DelegateResult, AgentHandle, } from './types.js';
|
|
11
|
-
export { DELEGATION_SCHEMA_VERSION, DELEGATION_TERMINAL_STATUSES, DELEGATION_ACTIVE_STATUSES, DelegationEvents, isTerminalDelegationStatus, isActiveDelegationStatus, } from './types.js';
|
|
11
|
+
export { DELEGATION_SCHEMA_VERSION, DEFAULT_DELEGATION_OUTPUT_CHARS, normalizeMaxOutputChars, DELEGATION_TERMINAL_STATUSES, DELEGATION_ACTIVE_STATUSES, DelegationEvents, isTerminalDelegationStatus, isActiveDelegationStatus, } from './types.js';
|
|
12
12
|
export type { AgentRegistry, AgentInfo, AgentQuery, AgentRelation, AgentRelationType, AgentDelegationPolicy, } from './registry-types.js';
|
|
13
13
|
export { AgentRegistryEvents } from './registry-types.js';
|
|
14
14
|
export { DefaultAgentRegistry } from './registry.js';
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* L2 委派契约层:`DelegateRequest` / `DelegateResult`(纯 JSON,D1/D5)
|
|
8
8
|
* + `AgentHandle`(D2 寻址)+ `DelegateTransport`(唯一分布式缝)。
|
|
9
9
|
*/
|
|
10
|
-
export { DELEGATION_SCHEMA_VERSION, DELEGATION_TERMINAL_STATUSES, DELEGATION_ACTIVE_STATUSES, DelegationEvents, isTerminalDelegationStatus, isActiveDelegationStatus, } from './types.js';
|
|
10
|
+
export { DELEGATION_SCHEMA_VERSION, DEFAULT_DELEGATION_OUTPUT_CHARS, normalizeMaxOutputChars, DELEGATION_TERMINAL_STATUSES, DELEGATION_ACTIVE_STATUSES, DelegationEvents, isTerminalDelegationStatus, isActiveDelegationStatus, } from './types.js';
|
|
11
11
|
export { AgentRegistryEvents } from './registry-types.js';
|
|
12
12
|
// ── Registry 实现 ──
|
|
13
13
|
export { DefaultAgentRegistry } from './registry.js';
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* 禁止在调用链上 await(`arch/agent-runtime.md` 重入策略)。
|
|
15
15
|
*/
|
|
16
16
|
import type { EventBus } from '@octopi-agent/core/primitives/event-bus.js';
|
|
17
|
-
import type
|
|
17
|
+
import { type Delegation } from './types.js';
|
|
18
18
|
import type { DelegationNotifier } from './service.js';
|
|
19
19
|
/** notify 投递器配置 */
|
|
20
20
|
export interface DelegationNotifierConfig {
|
|
@@ -26,6 +26,11 @@ export interface DelegationNotifierConfig {
|
|
|
26
26
|
/**
|
|
27
27
|
* 渲染委派终态通知(§7.1:`<delegation_completed …/>`)
|
|
28
28
|
*
|
|
29
|
+
* `<output>` 截断上限按委派单 `maxOutputChars`(缺省 {@link DEFAULT_DELEGATION_OUTPUT_CHARS})——
|
|
30
|
+
* 只影响自动送达的 notice;`delegate_get` 全文取回不受此限。上限计量**原始 output 字符**
|
|
31
|
+
* (截断补 `…`,实体最多 max+1 字符);escapeText 后投递文本可因转义膨胀(最坏 5×,
|
|
32
|
+
* 上限约束内容量不约束投递字节——2026-11-09 评审 m5 记债)。
|
|
33
|
+
*
|
|
29
34
|
* @param delegation - 终态委派单
|
|
30
35
|
* @returns 通知文本
|
|
31
36
|
*/
|
|
@@ -13,10 +13,16 @@
|
|
|
13
13
|
* 不打断父 Run:同 session 运行中再来 Trigger 由 Runner FIFO 锁排队,
|
|
14
14
|
* 禁止在调用链上 await(`arch/agent-runtime.md` 重入策略)。
|
|
15
15
|
*/
|
|
16
|
+
import { DEFAULT_DELEGATION_OUTPUT_CHARS } from './types.js';
|
|
16
17
|
import { emitAgentSignal, hasAgentSignalReceiver, } from '../../activation/sources/agent-signal.js';
|
|
17
18
|
/**
|
|
18
19
|
* 渲染委派终态通知(§7.1:`<delegation_completed …/>`)
|
|
19
20
|
*
|
|
21
|
+
* `<output>` 截断上限按委派单 `maxOutputChars`(缺省 {@link DEFAULT_DELEGATION_OUTPUT_CHARS})——
|
|
22
|
+
* 只影响自动送达的 notice;`delegate_get` 全文取回不受此限。上限计量**原始 output 字符**
|
|
23
|
+
* (截断补 `…`,实体最多 max+1 字符);escapeText 后投递文本可因转义膨胀(最坏 5×,
|
|
24
|
+
* 上限约束内容量不约束投递字节——2026-11-09 评审 m5 记债)。
|
|
25
|
+
*
|
|
20
26
|
* @param delegation - 终态委派单
|
|
21
27
|
* @returns 通知文本
|
|
22
28
|
*/
|
|
@@ -31,7 +37,8 @@ export function renderDelegationNotice(delegation) {
|
|
|
31
37
|
];
|
|
32
38
|
const body = [];
|
|
33
39
|
if (delegation.output) {
|
|
34
|
-
|
|
40
|
+
const maxOutputChars = delegation.maxOutputChars ?? DEFAULT_DELEGATION_OUTPUT_CHARS;
|
|
41
|
+
body.push(`<output>${escapeText(truncate(delegation.output, maxOutputChars))}</output>`);
|
|
35
42
|
}
|
|
36
43
|
if (delegation.error) {
|
|
37
44
|
body.push(`<error>${escapeText(truncate(delegation.error, 1000))}</error>`);
|
|
@@ -40,6 +40,8 @@ export interface DispatchDelegationInput {
|
|
|
40
40
|
parentRights?: import('../../governance/session-acl/types.js').SessionRights;
|
|
41
41
|
task: string;
|
|
42
42
|
input: string;
|
|
43
|
+
/** 自动返回通知 `<output>` 截断上限(chars);缺省 = DEFAULT_DELEGATION_OUTPUT_CHARS(B 方案 2026-11-09) */
|
|
44
|
+
maxOutputChars?: number;
|
|
43
45
|
context?: DelegationContextMode;
|
|
44
46
|
/** 父消息历史(仅 context='fork' 时携带) */
|
|
45
47
|
parentMessages?: import('@octopi-agent/core/types.js').Message[];
|
|
@@ -66,7 +66,7 @@ export function intersectBudget(requested, ceiling) {
|
|
|
66
66
|
return Math.min(a, b);
|
|
67
67
|
};
|
|
68
68
|
return {
|
|
69
|
-
|
|
69
|
+
maxSteps: pick(requested?.maxSteps, ceiling?.maxSteps),
|
|
70
70
|
maxTokens: pick(requested?.maxTokens, ceiling?.maxTokens),
|
|
71
71
|
timeoutMs: pick(requested?.timeoutMs, ceiling?.timeoutMs),
|
|
72
72
|
};
|
|
@@ -129,6 +129,7 @@ export class DelegateService {
|
|
|
129
129
|
target: input.target,
|
|
130
130
|
task: input.task,
|
|
131
131
|
input: input.input,
|
|
132
|
+
maxOutputChars: input.maxOutputChars,
|
|
132
133
|
context: input.context,
|
|
133
134
|
budget,
|
|
134
135
|
deadlineAt,
|
|
@@ -24,6 +24,8 @@ export interface CreateDelegationInput {
|
|
|
24
24
|
target: DelegationTarget;
|
|
25
25
|
task: string;
|
|
26
26
|
input: string;
|
|
27
|
+
/** 自动返回通知 `<output>` 截断上限(chars);缺省 = DEFAULT_DELEGATION_OUTPUT_CHARS */
|
|
28
|
+
maxOutputChars?: number;
|
|
27
29
|
context?: DelegationContextMode;
|
|
28
30
|
budget?: DelegationBudget;
|
|
29
31
|
/** 绝对截止时刻(D4);由 budget.timeoutMs 换算或调用方直接给 */
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* 但接口形状按可持久化设计(`Delegation` 全字段可序列化,D1/D5)。
|
|
18
18
|
*/
|
|
19
19
|
import { randomUUID } from 'node:crypto';
|
|
20
|
-
import { DELEGATION_SCHEMA_VERSION, DelegationEvents, isTerminalDelegationStatus, } from './types.js';
|
|
20
|
+
import { DELEGATION_SCHEMA_VERSION, DelegationEvents, isTerminalDelegationStatus, normalizeMaxOutputChars, } from './types.js';
|
|
21
21
|
function now() {
|
|
22
22
|
return Date.now();
|
|
23
23
|
}
|
|
@@ -68,6 +68,7 @@ export class DelegationStore {
|
|
|
68
68
|
target: { ...input.target },
|
|
69
69
|
task: input.task,
|
|
70
70
|
input: input.input,
|
|
71
|
+
maxOutputChars: normalizeMaxOutputChars(input.maxOutputChars),
|
|
71
72
|
context: input.context ?? 'clean',
|
|
72
73
|
status: 'queued',
|
|
73
74
|
depth: input.depth ?? 1,
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* 因此本文件的**所有**类型必须可 `JSON.stringify` 无损往返;
|
|
13
13
|
* 不得出现 `AbortSignal` / `Agent` 实例 / 函数 / class 实例等非序列化值。
|
|
14
14
|
*/
|
|
15
|
-
import type { TokenUsage } from '@octopi-agent/core/types/
|
|
15
|
+
import type { TokenUsage } from '@octopi-agent/core/types/step.js';
|
|
16
16
|
import type { SessionRights } from '../../governance/session-acl/types.js';
|
|
17
17
|
/**
|
|
18
18
|
* 委派消息 schema 版本(D1/⑤:跨进程契约必须版本化)。
|
|
@@ -59,7 +59,7 @@ export interface DelegationTarget {
|
|
|
59
59
|
*/
|
|
60
60
|
export interface DelegationBudget {
|
|
61
61
|
/** 子 Run 最大轮次 */
|
|
62
|
-
|
|
62
|
+
maxSteps?: number;
|
|
63
63
|
/** 子 Run 最大 token */
|
|
64
64
|
maxTokens?: number;
|
|
65
65
|
/** 委派超时(毫秒);换算为 deadlineAt */
|
|
@@ -75,6 +75,21 @@ export interface DelegationParentRef {
|
|
|
75
75
|
}
|
|
76
76
|
/** 结果送达父的状态机(§7.1 送达语义) */
|
|
77
77
|
export type DelegationDeliveryState = 'pending' | 'delivering' | 'surfaced';
|
|
78
|
+
/** 自动返回通知(`<delegation_result>`)`<output>` 默认截断上限(chars)。
|
|
79
|
+
* B 方案(2026-11-09 拍板):默认 16k,可按委派 `max_output_chars` 覆盖;
|
|
80
|
+
* 只影响自动送达 notice,`delegate_get` 全文取回不受此限。 */
|
|
81
|
+
export declare const DEFAULT_DELEGATION_OUTPUT_CHARS = 16000;
|
|
82
|
+
/**
|
|
83
|
+
* 校验/归一化自动返回截断上限(单源;`DelegationStore.create` 唯一写入口消费)。
|
|
84
|
+
*
|
|
85
|
+
* fail loud:非法值(非有限数 / 非正整数)直接抛错,不静默丢结果也不静默禁用截断
|
|
86
|
+
* (NaN 会产出空 `<output>`、负数丢尾部、Infinity 关闭截断——2026-11-09 评审 M2 实测)。
|
|
87
|
+
*
|
|
88
|
+
* @param value - 待校验上限(chars);undefined = 未指定(渲染侧回落默认)
|
|
89
|
+
* @returns 归一化后的上限(undefined = 未指定)
|
|
90
|
+
* @throws 非有限数、非正整数
|
|
91
|
+
*/
|
|
92
|
+
export declare function normalizeMaxOutputChars(value: number | undefined): number | undefined;
|
|
78
93
|
/**
|
|
79
94
|
* 委派单 —— 一次委派的全程记录
|
|
80
95
|
*
|
|
@@ -100,6 +115,12 @@ export interface Delegation {
|
|
|
100
115
|
childRunId?: string;
|
|
101
116
|
/** 子的最后一轮 assistant 文本 = 结论(D5) */
|
|
102
117
|
output?: string;
|
|
118
|
+
/**
|
|
119
|
+
* 自动返回通知(`<delegation_result>`)中 `<output>` 的截断上限(chars)。
|
|
120
|
+
* 只影响 notify 自动送达;`delegate_get` 全文取回不受此限。
|
|
121
|
+
* 缺省 = {@link DEFAULT_DELEGATION_OUTPUT_CHARS}(B 方案 2026-11-09)。
|
|
122
|
+
*/
|
|
123
|
+
maxOutputChars?: number;
|
|
103
124
|
/** 子产出的文件路径(D5/D6:不共享文件系统,显式声明) */
|
|
104
125
|
artifacts?: string[];
|
|
105
126
|
/** 子 Run 的 token 消耗(归集到父的 run 账,决策 C2) */
|
|
@@ -45,6 +45,28 @@ export const DELEGATION_ACTIVE_STATUSES = ['queued', 'running'];
|
|
|
45
45
|
export function isActiveDelegationStatus(status) {
|
|
46
46
|
return DELEGATION_ACTIVE_STATUSES.includes(status);
|
|
47
47
|
}
|
|
48
|
+
/** 自动返回通知(`<delegation_result>`)`<output>` 默认截断上限(chars)。
|
|
49
|
+
* B 方案(2026-11-09 拍板):默认 16k,可按委派 `max_output_chars` 覆盖;
|
|
50
|
+
* 只影响自动送达 notice,`delegate_get` 全文取回不受此限。 */
|
|
51
|
+
export const DEFAULT_DELEGATION_OUTPUT_CHARS = 16_000;
|
|
52
|
+
/**
|
|
53
|
+
* 校验/归一化自动返回截断上限(单源;`DelegationStore.create` 唯一写入口消费)。
|
|
54
|
+
*
|
|
55
|
+
* fail loud:非法值(非有限数 / 非正整数)直接抛错,不静默丢结果也不静默禁用截断
|
|
56
|
+
* (NaN 会产出空 `<output>`、负数丢尾部、Infinity 关闭截断——2026-11-09 评审 M2 实测)。
|
|
57
|
+
*
|
|
58
|
+
* @param value - 待校验上限(chars);undefined = 未指定(渲染侧回落默认)
|
|
59
|
+
* @returns 归一化后的上限(undefined = 未指定)
|
|
60
|
+
* @throws 非有限数、非正整数
|
|
61
|
+
*/
|
|
62
|
+
export function normalizeMaxOutputChars(value) {
|
|
63
|
+
if (value === undefined)
|
|
64
|
+
return undefined;
|
|
65
|
+
if (!Number.isFinite(value) || !Number.isInteger(value) || value <= 0) {
|
|
66
|
+
throw new Error(`maxOutputChars must be a positive integer (got ${value})`);
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
48
70
|
// ── 事件(§7) ──
|
|
49
71
|
/**
|
|
50
72
|
* 委派事件常量。
|
|
@@ -118,8 +118,18 @@ export function createDelegationRuntime(options) {
|
|
|
118
118
|
if (!sessionId)
|
|
119
119
|
return [];
|
|
120
120
|
const hint = service.renderStatusHint(sessionId);
|
|
121
|
+
// B0/引擎提示范式:engineHint 载体(user 形态),不进 provider system 字段——
|
|
122
|
+
// role:'system' 会被适配层拼进 system 前缀,状态翻转即整段重买(§1 烧缓存实锤)。
|
|
121
123
|
return hint
|
|
122
|
-
? [
|
|
124
|
+
? [
|
|
125
|
+
{
|
|
126
|
+
role: 'user',
|
|
127
|
+
content: hint,
|
|
128
|
+
timestamp: Date.now(),
|
|
129
|
+
ephemeral: true,
|
|
130
|
+
metadata: { source: 'engineHint' },
|
|
131
|
+
},
|
|
132
|
+
]
|
|
123
133
|
: [];
|
|
124
134
|
});
|
|
125
135
|
}
|
|
@@ -1,41 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* DefaultBudgetAllocator —
|
|
2
|
+
* DefaultBudgetAllocator — 不变量驱动的预算分配
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* - 系统提示词
|
|
6
|
-
* - 工具定义
|
|
7
|
-
* - 消息历史
|
|
8
|
-
* - 模型输出预留
|
|
4
|
+
* 唯一硬不变量(provider 侧事实):
|
|
9
5
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
6
|
+
* input_tokens + max_tokens ≤ contextWindow
|
|
7
|
+
*
|
|
8
|
+
* 因此分配顺序是「先扣输出,再扣固定开销,剩下的才是消息」:
|
|
9
|
+
*
|
|
10
|
+
* outputReserve = maxOutputTokens(模型能力上限;未知时比例回退)
|
|
11
|
+
* inputLimit = effectiveLimit − outputReserve ← 硬
|
|
12
|
+
* messagesLimit = inputLimit − system − tools − 信封 ← 硬(强制点用它)
|
|
13
|
+
* messagesBudget= messagesLimit ← 软(压缩策略提示)
|
|
14
|
+
*
|
|
15
|
+
* 历史实现的缺陷(本次修正):`outputReserve = clamp(window × 20%, 2k, 8k)`
|
|
16
|
+
* 与请求真实的 `max_tokens` 完全脱节——mimo-v2.6-pro(窗口 1,048,576 /
|
|
17
|
+
* maxTokens 131,072)会算出 1,040,076 的输入上限,加上 131,072 输出共
|
|
18
|
+
* 1,171,148,超出窗口 122,572,且无任何环节察觉。
|
|
14
19
|
*/
|
|
15
20
|
import type { BudgetAllocator, BudgetAllocateParams, BudgetAllocateResult } from './types.js';
|
|
16
21
|
export declare class DefaultBudgetAllocator implements BudgetAllocator {
|
|
17
22
|
private outputRatio;
|
|
18
23
|
private minOutputReserve;
|
|
19
24
|
private maxOutputReserve;
|
|
20
|
-
private
|
|
25
|
+
private requestEnvelopeTokens;
|
|
21
26
|
constructor(options?: {
|
|
22
27
|
outputRatio?: number;
|
|
23
28
|
minOutputReserve?: number;
|
|
24
29
|
maxOutputReserve?: number;
|
|
25
|
-
|
|
30
|
+
requestEnvelopeTokens?: number;
|
|
26
31
|
});
|
|
27
32
|
/**
|
|
28
33
|
* 分配 token 预算
|
|
29
34
|
*
|
|
30
|
-
* @param params -
|
|
31
|
-
* @returns
|
|
35
|
+
* @param params - 分配参数(窗口、模型输出上限、固定开销)
|
|
36
|
+
* @returns 硬上限(inputLimit / messagesLimit)、软目标(messagesBudget)与输出预留
|
|
32
37
|
*/
|
|
33
38
|
allocate(params: BudgetAllocateParams): BudgetAllocateResult;
|
|
34
39
|
/**
|
|
35
|
-
*
|
|
40
|
+
* 解析输出预留
|
|
41
|
+
*
|
|
42
|
+
* 有模型输出上限时按**硬预留**(不变量要求,不得打折);缺失时按窗口比例回退。
|
|
36
43
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
44
|
+
* @param effectiveLimit - 实际可用上限
|
|
45
|
+
* @param maxOutputTokens - 模型单次输出上限(可选)
|
|
46
|
+
* @returns 输出预留 token 数
|
|
39
47
|
*/
|
|
40
|
-
private
|
|
48
|
+
private resolveOutputReserve;
|
|
41
49
|
}
|