@linnlabs/linnkit 0.32.2 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/dist/cli.cjs +312 -50
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +312 -50
- package/dist/cli.js.map +1 -1
- package/dist/context-manager.cjs +1 -0
- package/dist/context-manager.cjs.map +1 -1
- package/dist/context-manager.js +1 -0
- package/dist/context-manager.js.map +1 -1
- package/dist/contracts/agentSpec.d.cts +30 -30
- package/dist/contracts/agentSpec.d.ts +30 -30
- package/dist/contracts/audit.d.cts +32 -32
- package/dist/contracts/audit.d.ts +32 -32
- package/dist/contracts/contextPolicy.d.cts +36 -36
- package/dist/contracts/contextPolicy.d.ts +36 -36
- package/dist/contracts/events.d.cts +968 -968
- package/dist/contracts/events.d.ts +968 -968
- package/dist/contracts/execution.d.cts +8 -8
- package/dist/contracts/execution.d.ts +8 -8
- package/dist/contracts/messages.d.cts +204 -204
- package/dist/contracts/messages.d.ts +204 -204
- package/dist/contracts/sse.d.cts +891 -891
- package/dist/contracts/sse.d.ts +891 -891
- package/dist/contracts/sub-run-trace-payload.d.cts +26 -26
- package/dist/contracts/sub-run-trace-payload.d.ts +26 -26
- package/dist/contracts/token-accounting.d.cts +28 -28
- package/dist/contracts/token-accounting.d.ts +28 -28
- package/dist/index.cjs +383 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +383 -66
- package/dist/index.js.map +1 -1
- package/dist/quickstart/toolRuntime.d.cts +1 -1
- package/dist/quickstart/toolRuntime.d.ts +1 -1
- package/dist/quickstart/types.d.cts +1 -1
- package/dist/quickstart/types.d.ts +1 -1
- package/dist/quickstart.cjs +312 -50
- package/dist/quickstart.cjs.map +1 -1
- package/dist/quickstart.js +312 -50
- package/dist/quickstart.js.map +1 -1
- package/dist/runtime-kernel/child-runs/childRunInvoker.d.cts +11 -0
- package/dist/runtime-kernel/child-runs/childRunInvoker.d.ts +11 -0
- package/dist/runtime-kernel/events/agentEvents.d.cts +98 -98
- package/dist/runtime-kernel/events/agentEvents.d.ts +98 -98
- package/dist/runtime-kernel/execution/eventBusEventPersistence.d.cts +15 -1
- package/dist/runtime-kernel/execution/eventBusEventPersistence.d.ts +15 -1
- package/dist/runtime-kernel/graph-engine/definitions/runContinuation.d.cts +34 -0
- package/dist/runtime-kernel/graph-engine/definitions/runContinuation.d.ts +34 -0
- package/dist/runtime-kernel/graph-engine/engine.d.cts +13 -2
- package/dist/runtime-kernel/graph-engine/engine.d.ts +13 -2
- package/dist/runtime-kernel/graph-engine/index.d.cts +2 -1
- package/dist/runtime-kernel/graph-engine/index.d.ts +2 -1
- package/dist/runtime-kernel/graph-engine/types.d.cts +8 -0
- package/dist/runtime-kernel/graph-engine/types.d.ts +8 -0
- package/dist/runtime-kernel/run-supervisor/definitions/runSupervisorContracts.d.cts +14 -2
- package/dist/runtime-kernel/run-supervisor/definitions/runSupervisorContracts.d.ts +14 -2
- package/dist/runtime-kernel/run-supervisor/memoryRunRegistryStore.d.cts +1 -0
- package/dist/runtime-kernel/run-supervisor/memoryRunRegistryStore.d.ts +1 -0
- package/dist/runtime-kernel/run-supervisor/runHandle.d.cts +9 -5
- package/dist/runtime-kernel/run-supervisor/runHandle.d.ts +9 -5
- package/dist/runtime-kernel/run-supervisor/runRegistryStorePort.d.cts +2 -0
- package/dist/runtime-kernel/run-supervisor/runRegistryStorePort.d.ts +2 -0
- package/dist/runtime-kernel/run-supervisor/runSupervisor.d.cts +7 -1
- package/dist/runtime-kernel/run-supervisor/runSupervisor.d.ts +7 -1
- package/dist/runtime-kernel.cjs +383 -66
- package/dist/runtime-kernel.cjs.map +1 -1
- package/dist/runtime-kernel.d.cts +2 -1
- package/dist/runtime-kernel.d.ts +2 -1
- package/dist/runtime-kernel.js +381 -67
- package/dist/runtime-kernel.js.map +1 -1
- package/dist/testkit.cjs +383 -66
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.js +383 -66
- package/dist/testkit.js.map +1 -1
- package/docs/integration/01-installation.md +1 -1
- package/docs/integration/child-runs.md +12 -0
- package/docs/integration/persistence.md +23 -0
- package/docs/integration/run-supervisor.md +12 -2
- package/package.json +4 -4
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { StandardToolCall, EngineState } from '../types.js';
|
|
2
|
+
import { ToolExecutionContext } from '../../tools/toolExecutionContext.js';
|
|
3
|
+
import { ToolExecutionResult } from '../../tools/ports.js';
|
|
4
|
+
|
|
5
|
+
/** Host 在同一次提交中持久化已接纳事实与断点;不得跨 Provider / tool 调用持有事务。 */
|
|
6
|
+
interface ExecutionCheckpointPort {
|
|
7
|
+
commit(checkpointKey: string, checkpoint: EngineState): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
type ToolRecoveryDecision = {
|
|
10
|
+
readonly kind: 'retry';
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: 'settled';
|
|
13
|
+
readonly result: ToolExecutionResult;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'blocked';
|
|
16
|
+
readonly reason: string;
|
|
17
|
+
};
|
|
18
|
+
/** 只有工具 owner 能证明未决外部动作的结果;参数相同不构成完成证据。 */
|
|
19
|
+
interface ToolRecoveryPort {
|
|
20
|
+
reconcile(call: StandardToolCall, context: ToolExecutionContext): Promise<ToolRecoveryDecision>;
|
|
21
|
+
}
|
|
22
|
+
declare class RunRecoveryBlockedError extends Error {
|
|
23
|
+
readonly code = "RUN_RECOVERY_BLOCKED";
|
|
24
|
+
constructor(message: string);
|
|
25
|
+
}
|
|
26
|
+
/** 可恢复中断与永久取消使用不同 signal reason,不为暂停补造工具失败终态。 */
|
|
27
|
+
declare class RunPauseRequested extends Error {
|
|
28
|
+
readonly code = "RUN_PAUSE_REQUESTED";
|
|
29
|
+
constructor(message?: string);
|
|
30
|
+
}
|
|
31
|
+
declare function isRunPauseSignal(signal: AbortSignal | undefined): boolean;
|
|
32
|
+
|
|
33
|
+
export { RunPauseRequested, RunRecoveryBlockedError, isRunPauseSignal };
|
|
34
|
+
export type { ExecutionCheckpointPort, ToolRecoveryDecision, ToolRecoveryPort };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { TelemetryPort } from '../telemetry/telemetryPort.cjs';
|
|
2
2
|
import { Checkpointer } from './checkpointer/base.cjs';
|
|
3
|
-
import { GraphNode, EngineState } from './types.cjs';
|
|
3
|
+
import { EngineLocalState, GraphNode, EngineState } from './types.cjs';
|
|
4
4
|
import { RoutedRuntimeEvent } from '../../contracts/events.cjs';
|
|
5
|
+
import { ExecutionCheckpointPort } from './definitions/runContinuation.cjs';
|
|
5
6
|
|
|
6
7
|
type GraphRunResult = {
|
|
7
8
|
events: RoutedRuntimeEvent[];
|
|
@@ -22,12 +23,18 @@ interface GraphSessionExecutionOptions {
|
|
|
22
23
|
}
|
|
23
24
|
interface GraphExecutorConfig {
|
|
24
25
|
maxSteps?: number;
|
|
26
|
+
executionCheckpointPort?: ExecutionCheckpointPort;
|
|
25
27
|
/**
|
|
26
28
|
* 可选:宿主提供的 TelemetryPort 实现。
|
|
27
29
|
* 不传时使用 noopTelemetry(observability 默认关闭,零业务影响)。
|
|
28
30
|
*/
|
|
29
31
|
telemetryPort?: TelemetryPort;
|
|
30
32
|
}
|
|
33
|
+
interface GraphContinuationInput {
|
|
34
|
+
readonly expectedRevision: number;
|
|
35
|
+
/** 只能重建运行能力,不能覆盖持久请求、历史、模型或预算。 */
|
|
36
|
+
readonly capabilities: Pick<EngineLocalState, 'signal' | 'toolContext' | 'runtimeEventSink' | 'runtimeEventCommitPort' | 'runtimeFailureFactSink' | 'summarizationCallbacks' | 'toolRecoveryPort'>;
|
|
37
|
+
}
|
|
31
38
|
declare class GraphExecutor {
|
|
32
39
|
private readonly checkpointer;
|
|
33
40
|
private nodes;
|
|
@@ -35,6 +42,7 @@ declare class GraphExecutor {
|
|
|
35
42
|
private checkpointQueues;
|
|
36
43
|
private readonly config;
|
|
37
44
|
private readonly telemetryPort;
|
|
45
|
+
private readonly executionCheckpointPort?;
|
|
38
46
|
constructor(checkpointer: Checkpointer, config?: GraphExecutorConfig);
|
|
39
47
|
registerNode(node: GraphNode): void;
|
|
40
48
|
peekCheckpoint(checkpointKey: string): Promise<EngineState | null>;
|
|
@@ -46,6 +54,8 @@ declare class GraphExecutor {
|
|
|
46
54
|
* 需要组合 prime/runUntilYield,也就不会在两步之间被另一个 run 覆盖。
|
|
47
55
|
*/
|
|
48
56
|
startSession(checkpointKey: string, local: Record<string, unknown>, nodeId?: string, options?: GraphSessionExecutionOptions): Promise<GraphRunResult>;
|
|
57
|
+
/** 从原提交边界继续,和提交 HITL response 的 resumeSession 是不同控制操作。 */
|
|
58
|
+
continueSession(checkpointKey: string, input: GraphContinuationInput): Promise<GraphRunResult>;
|
|
49
59
|
/** 同一个 run 从已持久化 wait_user checkpoint 继续执行。 */
|
|
50
60
|
resumeSession(checkpointKey: string, input: GraphResumeSessionInput): Promise<GraphRunResult>;
|
|
51
61
|
clearCheckpoint(checkpointKey: string): Promise<void>;
|
|
@@ -56,9 +66,10 @@ declare class GraphExecutor {
|
|
|
56
66
|
private runUntilYieldQueued;
|
|
57
67
|
private loadInitialState;
|
|
58
68
|
private saveCheckpoint;
|
|
69
|
+
private commitCheckpoint;
|
|
59
70
|
private saveCheckpointAndBuildResult;
|
|
60
71
|
private runUntilYieldInternal;
|
|
61
72
|
}
|
|
62
73
|
|
|
63
74
|
export { GraphExecutor };
|
|
64
|
-
export type { GraphExecutorConfig, GraphResumeSessionInput, GraphSessionExecutionOptions };
|
|
75
|
+
export type { GraphContinuationInput, GraphExecutorConfig, GraphResumeSessionInput, GraphSessionExecutionOptions };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { TelemetryPort } from '../telemetry/telemetryPort.js';
|
|
2
2
|
import { Checkpointer } from './checkpointer/base.js';
|
|
3
|
-
import { GraphNode, EngineState } from './types.js';
|
|
3
|
+
import { EngineLocalState, GraphNode, EngineState } from './types.js';
|
|
4
4
|
import { RoutedRuntimeEvent } from '../../contracts/events.js';
|
|
5
|
+
import { ExecutionCheckpointPort } from './definitions/runContinuation.js';
|
|
5
6
|
|
|
6
7
|
type GraphRunResult = {
|
|
7
8
|
events: RoutedRuntimeEvent[];
|
|
@@ -22,12 +23,18 @@ interface GraphSessionExecutionOptions {
|
|
|
22
23
|
}
|
|
23
24
|
interface GraphExecutorConfig {
|
|
24
25
|
maxSteps?: number;
|
|
26
|
+
executionCheckpointPort?: ExecutionCheckpointPort;
|
|
25
27
|
/**
|
|
26
28
|
* 可选:宿主提供的 TelemetryPort 实现。
|
|
27
29
|
* 不传时使用 noopTelemetry(observability 默认关闭,零业务影响)。
|
|
28
30
|
*/
|
|
29
31
|
telemetryPort?: TelemetryPort;
|
|
30
32
|
}
|
|
33
|
+
interface GraphContinuationInput {
|
|
34
|
+
readonly expectedRevision: number;
|
|
35
|
+
/** 只能重建运行能力,不能覆盖持久请求、历史、模型或预算。 */
|
|
36
|
+
readonly capabilities: Pick<EngineLocalState, 'signal' | 'toolContext' | 'runtimeEventSink' | 'runtimeEventCommitPort' | 'runtimeFailureFactSink' | 'summarizationCallbacks' | 'toolRecoveryPort'>;
|
|
37
|
+
}
|
|
31
38
|
declare class GraphExecutor {
|
|
32
39
|
private readonly checkpointer;
|
|
33
40
|
private nodes;
|
|
@@ -35,6 +42,7 @@ declare class GraphExecutor {
|
|
|
35
42
|
private checkpointQueues;
|
|
36
43
|
private readonly config;
|
|
37
44
|
private readonly telemetryPort;
|
|
45
|
+
private readonly executionCheckpointPort?;
|
|
38
46
|
constructor(checkpointer: Checkpointer, config?: GraphExecutorConfig);
|
|
39
47
|
registerNode(node: GraphNode): void;
|
|
40
48
|
peekCheckpoint(checkpointKey: string): Promise<EngineState | null>;
|
|
@@ -46,6 +54,8 @@ declare class GraphExecutor {
|
|
|
46
54
|
* 需要组合 prime/runUntilYield,也就不会在两步之间被另一个 run 覆盖。
|
|
47
55
|
*/
|
|
48
56
|
startSession(checkpointKey: string, local: Record<string, unknown>, nodeId?: string, options?: GraphSessionExecutionOptions): Promise<GraphRunResult>;
|
|
57
|
+
/** 从原提交边界继续,和提交 HITL response 的 resumeSession 是不同控制操作。 */
|
|
58
|
+
continueSession(checkpointKey: string, input: GraphContinuationInput): Promise<GraphRunResult>;
|
|
49
59
|
/** 同一个 run 从已持久化 wait_user checkpoint 继续执行。 */
|
|
50
60
|
resumeSession(checkpointKey: string, input: GraphResumeSessionInput): Promise<GraphRunResult>;
|
|
51
61
|
clearCheckpoint(checkpointKey: string): Promise<void>;
|
|
@@ -56,9 +66,10 @@ declare class GraphExecutor {
|
|
|
56
66
|
private runUntilYieldQueued;
|
|
57
67
|
private loadInitialState;
|
|
58
68
|
private saveCheckpoint;
|
|
69
|
+
private commitCheckpoint;
|
|
59
70
|
private saveCheckpointAndBuildResult;
|
|
60
71
|
private runUntilYieldInternal;
|
|
61
72
|
}
|
|
62
73
|
|
|
63
74
|
export { GraphExecutor };
|
|
64
|
-
export type { GraphExecutorConfig, GraphResumeSessionInput, GraphSessionExecutionOptions };
|
|
75
|
+
export type { GraphContinuationInput, GraphExecutorConfig, GraphResumeSessionInput, GraphSessionExecutionOptions };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { GraphExecutor } from './engine.cjs';
|
|
1
|
+
export { GraphContinuationInput, GraphExecutor } from './engine.cjs';
|
|
2
2
|
export { GraphAgentExecutor, GraphAgentExecutorDependencies } from './executor.cjs';
|
|
3
3
|
export { LlmNode } from './nodes/llmNode.cjs';
|
|
4
4
|
export { ToolNode } from './nodes/toolNode.cjs';
|
|
@@ -15,4 +15,5 @@ export { PRIMARY_PROMPT_CAPACITY_ERROR_CODE, PrimaryPromptCapacityError, Primary
|
|
|
15
15
|
export { readCheckpointContextUsage } from './functions/engineStateSnapshot.cjs';
|
|
16
16
|
export { isRuntimeFailureFact } from './functions/runtimeFailureFact.cjs';
|
|
17
17
|
export { ENGINE_STATE_SCHEMA_VERSION, EngineState, ExecutorLlmInvocationKind, ExecutorLocalPatch, ExecutorLocalState, GraphNode, RuntimeEventCommitPort, RuntimeEventSink, RuntimeFailureFact, RuntimeFailureFactSink, ToolBatchCompletionMode } from './types.cjs';
|
|
18
|
+
export { ExecutionCheckpointPort, RunPauseRequested, RunRecoveryBlockedError, ToolRecoveryDecision, ToolRecoveryPort, isRunPauseSignal } from './definitions/runContinuation.cjs';
|
|
18
19
|
export { GraphContextCompactionCandidate, GraphExecutorContextApplyInput, GraphExecutorContextApplyOutput, GraphExecutorContextBuildInput, GraphExecutorContextBuildOutput, GraphExecutorContextBuilder, GraphExecutorOutputProcessor } from './executorContextBuilder.cjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { GraphExecutor } from './engine.js';
|
|
1
|
+
export { GraphContinuationInput, GraphExecutor } from './engine.js';
|
|
2
2
|
export { GraphAgentExecutor, GraphAgentExecutorDependencies } from './executor.js';
|
|
3
3
|
export { LlmNode } from './nodes/llmNode.js';
|
|
4
4
|
export { ToolNode } from './nodes/toolNode.js';
|
|
@@ -15,4 +15,5 @@ export { PRIMARY_PROMPT_CAPACITY_ERROR_CODE, PrimaryPromptCapacityError, Primary
|
|
|
15
15
|
export { readCheckpointContextUsage } from './functions/engineStateSnapshot.js';
|
|
16
16
|
export { isRuntimeFailureFact } from './functions/runtimeFailureFact.js';
|
|
17
17
|
export { ENGINE_STATE_SCHEMA_VERSION, EngineState, ExecutorLlmInvocationKind, ExecutorLocalPatch, ExecutorLocalState, GraphNode, RuntimeEventCommitPort, RuntimeEventSink, RuntimeFailureFact, RuntimeFailureFactSink, ToolBatchCompletionMode } from './types.js';
|
|
18
|
+
export { ExecutionCheckpointPort, RunPauseRequested, RunRecoveryBlockedError, ToolRecoveryDecision, ToolRecoveryPort, isRunPauseSignal } from './definitions/runContinuation.js';
|
|
18
19
|
export { GraphContextCompactionCandidate, GraphExecutorContextApplyInput, GraphExecutorContextApplyOutput, GraphExecutorContextBuildInput, GraphExecutorContextBuildOutput, GraphExecutorContextBuilder, GraphExecutorOutputProcessor } from './executorContextBuilder.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ToolExecutionContext } from '../tools/toolExecutionContext.cjs';
|
|
2
|
+
import { ToolRecoveryPort } from './definitions/runContinuation.cjs';
|
|
2
3
|
import { RunId, ToolCallId } from '../../contracts/identity/definitions.cjs';
|
|
3
4
|
import { AgentSpecSystemReminderPolicy, AgentSpecToolObservationGovernancePolicy } from '../../contracts/contextPolicy.cjs';
|
|
4
5
|
import { RuntimeEvent, RoutedRuntimeEvent } from '../../contracts/events.cjs';
|
|
@@ -81,6 +82,11 @@ interface EngineLocalState extends Record<string, unknown> {
|
|
|
81
82
|
runtimeEventSink?: RuntimeEventSink;
|
|
82
83
|
/** 在 fan-out 前请求 Host 持久化单个 durable fact。 */
|
|
83
84
|
runtimeEventCommitPort?: RuntimeEventCommitPort;
|
|
85
|
+
/** Graph 注入的短提交边界,ToolNode 每个 call 前后复用;不序列化能力。 */
|
|
86
|
+
commitExecutionBoundary?: (state: EngineState) => Promise<void>;
|
|
87
|
+
toolRecoveryPort?: ToolRecoveryPort;
|
|
88
|
+
/** 意图已提交但结果未提交的原始 call;重启时必须经过工具 owner 对账。 */
|
|
89
|
+
executingToolCallId?: ToolCallId;
|
|
84
90
|
runtimeFailureFactSink?: RuntimeFailureFactSink;
|
|
85
91
|
summarizationCallbacks?: SummarizationCallbacks;
|
|
86
92
|
/** 最近一次成功完成的 LLM Prompt 占用;可序列化并随 checkpoint 保留。 */
|
|
@@ -107,6 +113,8 @@ type RuntimeFailureFactSink = (event: RuntimeFailureFact) => void;
|
|
|
107
113
|
declare const ENGINE_STATE_SCHEMA_VERSION = 1;
|
|
108
114
|
interface EngineState {
|
|
109
115
|
nodeId: string;
|
|
116
|
+
/** 仅在配置 ExecutionCheckpointPort 后启用;yielded 不得重新执行最终节点。 */
|
|
117
|
+
executionStatus?: 'ready' | 'executing' | 'yielded' | 'awaiting_user';
|
|
110
118
|
/**
|
|
111
119
|
* 当前 checkpoint 的单调版本。
|
|
112
120
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ToolExecutionContext } from '../tools/toolExecutionContext.js';
|
|
2
|
+
import { ToolRecoveryPort } from './definitions/runContinuation.js';
|
|
2
3
|
import { RunId, ToolCallId } from '../../contracts/identity/definitions.js';
|
|
3
4
|
import { AgentSpecSystemReminderPolicy, AgentSpecToolObservationGovernancePolicy } from '../../contracts/contextPolicy.js';
|
|
4
5
|
import { RuntimeEvent, RoutedRuntimeEvent } from '../../contracts/events.js';
|
|
@@ -81,6 +82,11 @@ interface EngineLocalState extends Record<string, unknown> {
|
|
|
81
82
|
runtimeEventSink?: RuntimeEventSink;
|
|
82
83
|
/** 在 fan-out 前请求 Host 持久化单个 durable fact。 */
|
|
83
84
|
runtimeEventCommitPort?: RuntimeEventCommitPort;
|
|
85
|
+
/** Graph 注入的短提交边界,ToolNode 每个 call 前后复用;不序列化能力。 */
|
|
86
|
+
commitExecutionBoundary?: (state: EngineState) => Promise<void>;
|
|
87
|
+
toolRecoveryPort?: ToolRecoveryPort;
|
|
88
|
+
/** 意图已提交但结果未提交的原始 call;重启时必须经过工具 owner 对账。 */
|
|
89
|
+
executingToolCallId?: ToolCallId;
|
|
84
90
|
runtimeFailureFactSink?: RuntimeFailureFactSink;
|
|
85
91
|
summarizationCallbacks?: SummarizationCallbacks;
|
|
86
92
|
/** 最近一次成功完成的 LLM Prompt 占用;可序列化并随 checkpoint 保留。 */
|
|
@@ -107,6 +113,8 @@ type RuntimeFailureFactSink = (event: RuntimeFailureFact) => void;
|
|
|
107
113
|
declare const ENGINE_STATE_SCHEMA_VERSION = 1;
|
|
108
114
|
interface EngineState {
|
|
109
115
|
nodeId: string;
|
|
116
|
+
/** 仅在配置 ExecutionCheckpointPort 后启用;yielded 不得重新执行最终节点。 */
|
|
117
|
+
executionStatus?: 'ready' | 'executing' | 'yielded' | 'awaiting_user';
|
|
110
118
|
/**
|
|
111
119
|
* 当前 checkpoint 的单调版本。
|
|
112
120
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RunId,
|
|
1
|
+
import { RunId, ExecutionId, ToolCallId } from '../../../contracts/identity/definitions.cjs';
|
|
2
2
|
import { AgentSpec } from '../../../contracts/agentSpec.cjs';
|
|
3
3
|
import { RuntimeEvent } from '../../../contracts/events.cjs';
|
|
4
4
|
import { AuditPort } from '../../../ports/audit.cjs';
|
|
@@ -96,6 +96,10 @@ interface RunRegistrationSpec<TRequest extends RunRequestSnapshot = RunRequestSn
|
|
|
96
96
|
}
|
|
97
97
|
interface RunSupervisor<TRequest extends RunRequestSnapshot = RunRequestSnapshot> {
|
|
98
98
|
registerRun(spec: RunRegistrationSpec<TRequest>): Promise<RunHandle<TRequest>>;
|
|
99
|
+
/** Host 已校验 durable descriptor 后重建能力;不注册新 run、不覆盖持久身份。 */
|
|
100
|
+
restoreRun(spec: RunRegistrationSpec<TRequest> & {
|
|
101
|
+
runId: RunId;
|
|
102
|
+
}): Promise<RunHandle<TRequest>>;
|
|
99
103
|
spawnDetached(spec: RunRegistrationSpec<TRequest>): Promise<RunHandle<TRequest>>;
|
|
100
104
|
observeRun(runId: RunId, filter?: RunObserveFilter): AsyncIterable<RuntimeEvent>;
|
|
101
105
|
cancel(runId: RunId, opts: CancelOpts): Promise<void>;
|
|
@@ -114,7 +118,13 @@ interface RunSupervisor<TRequest extends RunRequestSnapshot = RunRequestSnapshot
|
|
|
114
118
|
findByConversation(conversationId: string, opts?: FindRunsByConversationOptions): Promise<RunSnapshot[]>;
|
|
115
119
|
drain(opts?: RunWaitForTerminalOptions): Promise<RunOutcome[]>;
|
|
116
120
|
recoverOnBoot(reason?: string): Promise<RunOutcome[]>;
|
|
117
|
-
pause(runId: RunId, reason?: string): Promise<
|
|
121
|
+
pause(runId: RunId, reason?: string): Promise<void>;
|
|
122
|
+
resumePausedRun(input: {
|
|
123
|
+
readonly runId: RunId;
|
|
124
|
+
readonly expectedUpdatedAt: number;
|
|
125
|
+
readonly eventBus: EventBus;
|
|
126
|
+
readonly executionId: ExecutionId;
|
|
127
|
+
}): Promise<RunHandle<TRequest>>;
|
|
118
128
|
claimResume(runId: RunId, interaction: RunResumeInteraction, eventBus: EventBus, parentSignal?: AbortSignal): Promise<RunResumeClaim<TRequest>>;
|
|
119
129
|
runTree(rootRunId: RunId): Promise<never>;
|
|
120
130
|
handleFailure(runId: RunId, error: unknown): Promise<never>;
|
|
@@ -126,6 +136,8 @@ interface DefaultRunSupervisorOptions<TRequest extends RunRequestSnapshot = RunR
|
|
|
126
136
|
runIdFactory?: () => RunId;
|
|
127
137
|
now?: () => number;
|
|
128
138
|
maxActiveRuns?: number;
|
|
139
|
+
/** 仅识别具有 Host 恢复输入的 run;不在启动时执行它。旧 run 默认仍 abandoned。 */
|
|
140
|
+
canRestoreRun?: (record: RunRecord) => Promise<boolean>;
|
|
129
141
|
}
|
|
130
142
|
|
|
131
143
|
export type { DefaultRunSupervisorOptions, FindActiveByConversationOptions, FindRunsByConversationOptions, RunExecutionContext, RunExecutorPort, RunOutcome, RunRegistrationSpec, RunResumeClaim, RunResumeInteraction, RunSnapshot, RunSupervisor, RunTerminalError, RunTerminalEvent, RunTerminalStatus, RunWaitForTerminalOptions };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RunId,
|
|
1
|
+
import { RunId, ExecutionId, ToolCallId } from '../../../contracts/identity/definitions.js';
|
|
2
2
|
import { AgentSpec } from '../../../contracts/agentSpec.js';
|
|
3
3
|
import { RuntimeEvent } from '../../../contracts/events.js';
|
|
4
4
|
import { AuditPort } from '../../../ports/audit.js';
|
|
@@ -96,6 +96,10 @@ interface RunRegistrationSpec<TRequest extends RunRequestSnapshot = RunRequestSn
|
|
|
96
96
|
}
|
|
97
97
|
interface RunSupervisor<TRequest extends RunRequestSnapshot = RunRequestSnapshot> {
|
|
98
98
|
registerRun(spec: RunRegistrationSpec<TRequest>): Promise<RunHandle<TRequest>>;
|
|
99
|
+
/** Host 已校验 durable descriptor 后重建能力;不注册新 run、不覆盖持久身份。 */
|
|
100
|
+
restoreRun(spec: RunRegistrationSpec<TRequest> & {
|
|
101
|
+
runId: RunId;
|
|
102
|
+
}): Promise<RunHandle<TRequest>>;
|
|
99
103
|
spawnDetached(spec: RunRegistrationSpec<TRequest>): Promise<RunHandle<TRequest>>;
|
|
100
104
|
observeRun(runId: RunId, filter?: RunObserveFilter): AsyncIterable<RuntimeEvent>;
|
|
101
105
|
cancel(runId: RunId, opts: CancelOpts): Promise<void>;
|
|
@@ -114,7 +118,13 @@ interface RunSupervisor<TRequest extends RunRequestSnapshot = RunRequestSnapshot
|
|
|
114
118
|
findByConversation(conversationId: string, opts?: FindRunsByConversationOptions): Promise<RunSnapshot[]>;
|
|
115
119
|
drain(opts?: RunWaitForTerminalOptions): Promise<RunOutcome[]>;
|
|
116
120
|
recoverOnBoot(reason?: string): Promise<RunOutcome[]>;
|
|
117
|
-
pause(runId: RunId, reason?: string): Promise<
|
|
121
|
+
pause(runId: RunId, reason?: string): Promise<void>;
|
|
122
|
+
resumePausedRun(input: {
|
|
123
|
+
readonly runId: RunId;
|
|
124
|
+
readonly expectedUpdatedAt: number;
|
|
125
|
+
readonly eventBus: EventBus;
|
|
126
|
+
readonly executionId: ExecutionId;
|
|
127
|
+
}): Promise<RunHandle<TRequest>>;
|
|
118
128
|
claimResume(runId: RunId, interaction: RunResumeInteraction, eventBus: EventBus, parentSignal?: AbortSignal): Promise<RunResumeClaim<TRequest>>;
|
|
119
129
|
runTree(rootRunId: RunId): Promise<never>;
|
|
120
130
|
handleFailure(runId: RunId, error: unknown): Promise<never>;
|
|
@@ -126,6 +136,8 @@ interface DefaultRunSupervisorOptions<TRequest extends RunRequestSnapshot = RunR
|
|
|
126
136
|
runIdFactory?: () => RunId;
|
|
127
137
|
now?: () => number;
|
|
128
138
|
maxActiveRuns?: number;
|
|
139
|
+
/** 仅识别具有 Host 恢复输入的 run;不在启动时执行它。旧 run 默认仍 abandoned。 */
|
|
140
|
+
canRestoreRun?: (record: RunRecord) => Promise<boolean>;
|
|
129
141
|
}
|
|
130
142
|
|
|
131
143
|
export type { DefaultRunSupervisorOptions, FindActiveByConversationOptions, FindRunsByConversationOptions, RunExecutionContext, RunExecutorPort, RunOutcome, RunRegistrationSpec, RunResumeClaim, RunResumeInteraction, RunSnapshot, RunSupervisor, RunTerminalError, RunTerminalEvent, RunTerminalStatus, RunWaitForTerminalOptions };
|
|
@@ -3,6 +3,7 @@ import { RunId } from '../../contracts/identity/definitions.cjs';
|
|
|
3
3
|
|
|
4
4
|
declare class MemoryRunRegistryStore implements RunRegistryStore {
|
|
5
5
|
private readonly store;
|
|
6
|
+
compareAndSwap(previous: RunRecord, next: RunRecord): Promise<boolean>;
|
|
6
7
|
save(record: RunRecord): Promise<void>;
|
|
7
8
|
load(runId: RunId): Promise<RunRecord | null>;
|
|
8
9
|
list(filter?: ListRunsFilter): Promise<{
|
|
@@ -3,6 +3,7 @@ import { RunId } from '../../contracts/identity/definitions.js';
|
|
|
3
3
|
|
|
4
4
|
declare class MemoryRunRegistryStore implements RunRegistryStore {
|
|
5
5
|
private readonly store;
|
|
6
|
+
compareAndSwap(previous: RunRecord, next: RunRecord): Promise<boolean>;
|
|
6
7
|
save(record: RunRecord): Promise<void>;
|
|
7
8
|
load(runId: RunId): Promise<RunRecord | null>;
|
|
8
9
|
list(filter?: ListRunsFilter): Promise<{
|
|
@@ -84,8 +84,10 @@ interface RunHandle<TRequest extends RunRequestSnapshot = RunRequestSnapshot> {
|
|
|
84
84
|
markAwaitingUser(patch?: RunAwaitingUserPatch): Promise<void>;
|
|
85
85
|
markCompleted(patch?: RunLifecyclePatch): Promise<void>;
|
|
86
86
|
markFailed(error: RunFailureInfo, patch?: RunLifecyclePatch): Promise<void>;
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
/** 写暂停意图后中断当前 attempt;pausedAt 未设置表示执行尚在收口。 */
|
|
88
|
+
pause(reason?: string): Promise<void>;
|
|
89
|
+
/** Host 在 checkpoint 提交和当前 attempt 收口之后确认可继续。 */
|
|
90
|
+
markPaused(patch?: RunAwaitingUserPatch): Promise<void>;
|
|
89
91
|
}
|
|
90
92
|
interface DefaultRunHandleOptions<TRequest extends RunRequestSnapshot = RunRequestSnapshot> {
|
|
91
93
|
runRecord: RunRecord;
|
|
@@ -111,6 +113,7 @@ declare class DefaultRunHandle<TRequest extends RunRequestSnapshot = RunRequestS
|
|
|
111
113
|
readonly parentRunId?: RunId;
|
|
112
114
|
private runRecord;
|
|
113
115
|
private abortController;
|
|
116
|
+
private executionId;
|
|
114
117
|
private readonly agentSpecSnapshot;
|
|
115
118
|
private readonly requestSnapshot;
|
|
116
119
|
private transportEventBus;
|
|
@@ -127,7 +130,7 @@ declare class DefaultRunHandle<TRequest extends RunRequestSnapshot = RunRequestS
|
|
|
127
130
|
* awaiting_user 之后的 resume 是同一逻辑 run 的新 execution。
|
|
128
131
|
* 必须切换取消控制器,避免旧 transport 的迟到 abort 污染新 execution。
|
|
129
132
|
*/
|
|
130
|
-
replaceExecutionAbortController(controller: AbortController): void;
|
|
133
|
+
replaceExecutionAbortController(controller: AbortController, executionId?: string): void;
|
|
131
134
|
spec(): Promise<AgentSpec>;
|
|
132
135
|
request(): Promise<TRequest>;
|
|
133
136
|
attachTransportEventBus(eventBus: EventBus): void;
|
|
@@ -139,10 +142,11 @@ declare class DefaultRunHandle<TRequest extends RunRequestSnapshot = RunRequestS
|
|
|
139
142
|
markAwaitingUser(patch?: RunAwaitingUserPatch): Promise<void>;
|
|
140
143
|
markCompleted(patch?: RunLifecyclePatch): Promise<void>;
|
|
141
144
|
markFailed(error: RunFailureInfo, patch?: RunLifecyclePatch): Promise<void>;
|
|
142
|
-
pause(
|
|
143
|
-
|
|
145
|
+
pause(reason?: string): Promise<void>;
|
|
146
|
+
markPaused(patch?: RunAwaitingUserPatch): Promise<void>;
|
|
144
147
|
private saveLifecycleStatus;
|
|
145
148
|
private readonly forwardTransportEvent;
|
|
149
|
+
private assertExecutionOwner;
|
|
146
150
|
private readonly forwardTransportError;
|
|
147
151
|
private readonly detachClosedTransport;
|
|
148
152
|
private attachTransportBridge;
|
|
@@ -84,8 +84,10 @@ interface RunHandle<TRequest extends RunRequestSnapshot = RunRequestSnapshot> {
|
|
|
84
84
|
markAwaitingUser(patch?: RunAwaitingUserPatch): Promise<void>;
|
|
85
85
|
markCompleted(patch?: RunLifecyclePatch): Promise<void>;
|
|
86
86
|
markFailed(error: RunFailureInfo, patch?: RunLifecyclePatch): Promise<void>;
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
/** 写暂停意图后中断当前 attempt;pausedAt 未设置表示执行尚在收口。 */
|
|
88
|
+
pause(reason?: string): Promise<void>;
|
|
89
|
+
/** Host 在 checkpoint 提交和当前 attempt 收口之后确认可继续。 */
|
|
90
|
+
markPaused(patch?: RunAwaitingUserPatch): Promise<void>;
|
|
89
91
|
}
|
|
90
92
|
interface DefaultRunHandleOptions<TRequest extends RunRequestSnapshot = RunRequestSnapshot> {
|
|
91
93
|
runRecord: RunRecord;
|
|
@@ -111,6 +113,7 @@ declare class DefaultRunHandle<TRequest extends RunRequestSnapshot = RunRequestS
|
|
|
111
113
|
readonly parentRunId?: RunId;
|
|
112
114
|
private runRecord;
|
|
113
115
|
private abortController;
|
|
116
|
+
private executionId;
|
|
114
117
|
private readonly agentSpecSnapshot;
|
|
115
118
|
private readonly requestSnapshot;
|
|
116
119
|
private transportEventBus;
|
|
@@ -127,7 +130,7 @@ declare class DefaultRunHandle<TRequest extends RunRequestSnapshot = RunRequestS
|
|
|
127
130
|
* awaiting_user 之后的 resume 是同一逻辑 run 的新 execution。
|
|
128
131
|
* 必须切换取消控制器,避免旧 transport 的迟到 abort 污染新 execution。
|
|
129
132
|
*/
|
|
130
|
-
replaceExecutionAbortController(controller: AbortController): void;
|
|
133
|
+
replaceExecutionAbortController(controller: AbortController, executionId?: string): void;
|
|
131
134
|
spec(): Promise<AgentSpec>;
|
|
132
135
|
request(): Promise<TRequest>;
|
|
133
136
|
attachTransportEventBus(eventBus: EventBus): void;
|
|
@@ -139,10 +142,11 @@ declare class DefaultRunHandle<TRequest extends RunRequestSnapshot = RunRequestS
|
|
|
139
142
|
markAwaitingUser(patch?: RunAwaitingUserPatch): Promise<void>;
|
|
140
143
|
markCompleted(patch?: RunLifecyclePatch): Promise<void>;
|
|
141
144
|
markFailed(error: RunFailureInfo, patch?: RunLifecyclePatch): Promise<void>;
|
|
142
|
-
pause(
|
|
143
|
-
|
|
145
|
+
pause(reason?: string): Promise<void>;
|
|
146
|
+
markPaused(patch?: RunAwaitingUserPatch): Promise<void>;
|
|
144
147
|
private saveLifecycleStatus;
|
|
145
148
|
private readonly forwardTransportEvent;
|
|
149
|
+
private assertExecutionOwner;
|
|
146
150
|
private readonly forwardTransportError;
|
|
147
151
|
private readonly detachClosedTransport;
|
|
148
152
|
private attachTransportBridge;
|
|
@@ -35,6 +35,8 @@ type RunRecord = {
|
|
|
35
35
|
metadata?: Record<string, unknown>;
|
|
36
36
|
};
|
|
37
37
|
interface RunRegistryStore {
|
|
38
|
+
/** 仅当整条 previous 仍是当前记录时原子替换;恢复 Host 必须实现。 */
|
|
39
|
+
compareAndSwap?(previous: RunRecord, next: RunRecord): Promise<boolean>;
|
|
38
40
|
save(record: RunRecord): Promise<void>;
|
|
39
41
|
load(runId: RunId): Promise<RunRecord | null>;
|
|
40
42
|
list(filter?: ListRunsFilter): Promise<{
|
|
@@ -35,6 +35,8 @@ type RunRecord = {
|
|
|
35
35
|
metadata?: Record<string, unknown>;
|
|
36
36
|
};
|
|
37
37
|
interface RunRegistryStore {
|
|
38
|
+
/** 仅当整条 previous 仍是当前记录时原子替换;恢复 Host 必须实现。 */
|
|
39
|
+
compareAndSwap?(previous: RunRecord, next: RunRecord): Promise<boolean>;
|
|
38
40
|
save(record: RunRecord): Promise<void>;
|
|
39
41
|
load(runId: RunId): Promise<RunRecord | null>;
|
|
40
42
|
list(filter?: ListRunsFilter): Promise<{
|
|
@@ -22,8 +22,13 @@ declare class DefaultRunSupervisor<TRequest extends RunRequestSnapshot = RunRequ
|
|
|
22
22
|
private readonly inFlight;
|
|
23
23
|
private readonly eventWatchDisposers;
|
|
24
24
|
private readonly controlOperations;
|
|
25
|
+
private readonly canRestoreRun?;
|
|
25
26
|
constructor(options: DefaultRunSupervisorOptions<TRequest>);
|
|
26
27
|
registerRun(spec: RunRegistrationSpec<TRequest>): Promise<RunHandle<TRequest>>;
|
|
28
|
+
restoreRun(spec: RunRegistrationSpec<TRequest> & {
|
|
29
|
+
runId: RunId;
|
|
30
|
+
}): Promise<RunHandle<TRequest>>;
|
|
31
|
+
private attachRun;
|
|
27
32
|
spawnDetached(spec: RunRegistrationSpec<TRequest>): Promise<RunHandle<TRequest>>;
|
|
28
33
|
observeRun(runId: RunId, filter?: RunObserveFilter): AsyncIterable<RuntimeEvent>;
|
|
29
34
|
cancel(runId: RunId, opts: CancelOpts): Promise<void>;
|
|
@@ -38,7 +43,8 @@ declare class DefaultRunSupervisor<TRequest extends RunRequestSnapshot = RunRequ
|
|
|
38
43
|
findByConversation(conversationId: string, opts?: FindRunsByConversationOptions): Promise<RunSnapshot[]>;
|
|
39
44
|
drain(opts?: RunWaitForTerminalOptions): Promise<RunOutcome[]>;
|
|
40
45
|
recoverOnBoot(reason?: string): Promise<RunOutcome[]>;
|
|
41
|
-
pause(
|
|
46
|
+
pause(runId: RunId, reason?: string): Promise<void>;
|
|
47
|
+
resumePausedRun(input: Parameters<RunSupervisor<TRequest>['resumePausedRun']>[0]): Promise<RunHandle<TRequest>>;
|
|
42
48
|
claimResume(runId: RunId, interaction: RunResumeInteraction, eventBus: EventBus, parentSignal?: AbortSignal): Promise<RunResumeClaim<TRequest>>;
|
|
43
49
|
runTree(_rootRunId: RunId): Promise<never>;
|
|
44
50
|
handleFailure(_runId: RunId, _error: unknown): Promise<never>;
|
|
@@ -22,8 +22,13 @@ declare class DefaultRunSupervisor<TRequest extends RunRequestSnapshot = RunRequ
|
|
|
22
22
|
private readonly inFlight;
|
|
23
23
|
private readonly eventWatchDisposers;
|
|
24
24
|
private readonly controlOperations;
|
|
25
|
+
private readonly canRestoreRun?;
|
|
25
26
|
constructor(options: DefaultRunSupervisorOptions<TRequest>);
|
|
26
27
|
registerRun(spec: RunRegistrationSpec<TRequest>): Promise<RunHandle<TRequest>>;
|
|
28
|
+
restoreRun(spec: RunRegistrationSpec<TRequest> & {
|
|
29
|
+
runId: RunId;
|
|
30
|
+
}): Promise<RunHandle<TRequest>>;
|
|
31
|
+
private attachRun;
|
|
27
32
|
spawnDetached(spec: RunRegistrationSpec<TRequest>): Promise<RunHandle<TRequest>>;
|
|
28
33
|
observeRun(runId: RunId, filter?: RunObserveFilter): AsyncIterable<RuntimeEvent>;
|
|
29
34
|
cancel(runId: RunId, opts: CancelOpts): Promise<void>;
|
|
@@ -38,7 +43,8 @@ declare class DefaultRunSupervisor<TRequest extends RunRequestSnapshot = RunRequ
|
|
|
38
43
|
findByConversation(conversationId: string, opts?: FindRunsByConversationOptions): Promise<RunSnapshot[]>;
|
|
39
44
|
drain(opts?: RunWaitForTerminalOptions): Promise<RunOutcome[]>;
|
|
40
45
|
recoverOnBoot(reason?: string): Promise<RunOutcome[]>;
|
|
41
|
-
pause(
|
|
46
|
+
pause(runId: RunId, reason?: string): Promise<void>;
|
|
47
|
+
resumePausedRun(input: Parameters<RunSupervisor<TRequest>['resumePausedRun']>[0]): Promise<RunHandle<TRequest>>;
|
|
42
48
|
claimResume(runId: RunId, interaction: RunResumeInteraction, eventBus: EventBus, parentSignal?: AbortSignal): Promise<RunResumeClaim<TRequest>>;
|
|
43
49
|
runTree(_rootRunId: RunId): Promise<never>;
|
|
44
50
|
handleFailure(_runId: RunId, _error: unknown): Promise<never>;
|