@linnlabs/linnkit 0.43.0 → 0.45.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 +61 -0
- package/dist/cli.cjs +152 -6
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +152 -6
- package/dist/cli.js.map +1 -1
- package/dist/context-manager/profiles/agent/context/config.d.cts +1 -1
- package/dist/context-manager/profiles/agent/context/config.d.ts +1 -1
- package/dist/context-manager.cjs +37 -4
- package/dist/context-manager.cjs.map +1 -1
- package/dist/context-manager.js +37 -4
- package/dist/context-manager.js.map +1 -1
- package/dist/contracts/agentSpec.d.cts +5 -5
- package/dist/contracts/agentSpec.d.ts +5 -5
- package/dist/contracts/audit.d.cts +10 -10
- package/dist/contracts/audit.d.ts +10 -10
- package/dist/contracts/contextPolicy.d.cts +14 -14
- package/dist/contracts/contextPolicy.d.ts +14 -14
- package/dist/contracts/events.d.cts +121 -117
- package/dist/contracts/events.d.ts +121 -117
- package/dist/contracts/execution.d.cts +2 -2
- package/dist/contracts/execution.d.ts +2 -2
- package/dist/contracts/llm-retry.d.cts +2 -2
- package/dist/contracts/llm-retry.d.ts +2 -2
- package/dist/contracts/messages.d.cts +256 -32
- package/dist/contracts/messages.d.ts +256 -32
- package/dist/contracts/sse.d.cts +161 -97
- package/dist/contracts/sse.d.ts +161 -97
- package/dist/contracts/sub-run-trace-payload.d.cts +8 -8
- package/dist/contracts/sub-run-trace-payload.d.ts +8 -8
- package/dist/contracts/token-accounting.d.cts +12 -12
- package/dist/contracts/token-accounting.d.ts +12 -12
- package/dist/contracts.cjs +19 -2
- package/dist/contracts.cjs.map +1 -1
- package/dist/contracts.d.cts +1 -1
- package/dist/contracts.d.ts +1 -1
- package/dist/contracts.js +19 -3
- package/dist/contracts.js.map +1 -1
- package/dist/index.cjs +154 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +154 -6
- package/dist/index.js.map +1 -1
- package/dist/quickstart.cjs +152 -6
- package/dist/quickstart.cjs.map +1 -1
- package/dist/quickstart.js +152 -6
- package/dist/quickstart.js.map +1 -1
- package/dist/runtime-kernel/events/agentEvents.d.cts +2 -2
- package/dist/runtime-kernel/events/agentEvents.d.ts +2 -2
- package/dist/runtime-kernel/events.cjs +29 -2
- package/dist/runtime-kernel/events.cjs.map +1 -1
- package/dist/runtime-kernel/events.js +29 -2
- package/dist/runtime-kernel/events.js.map +1 -1
- package/dist/runtime-kernel/graph-engine/definitions/pendingUserInput.d.cts +27 -0
- package/dist/runtime-kernel/graph-engine/definitions/pendingUserInput.d.ts +27 -0
- package/dist/runtime-kernel/graph-engine/engine.d.cts +1 -1
- package/dist/runtime-kernel/graph-engine/engine.d.ts +1 -1
- package/dist/runtime-kernel/graph-engine/index.d.cts +1 -0
- package/dist/runtime-kernel/graph-engine/index.d.ts +1 -0
- package/dist/runtime-kernel/graph-engine/nodes/toolNode.d.cts +3 -0
- package/dist/runtime-kernel/graph-engine/nodes/toolNode.d.ts +3 -0
- package/dist/runtime-kernel/graph-engine/types.d.cts +3 -0
- package/dist/runtime-kernel/graph-engine/types.d.ts +3 -0
- package/dist/runtime-kernel.cjs +152 -6
- package/dist/runtime-kernel.cjs.map +1 -1
- package/dist/runtime-kernel.d.cts +1 -0
- package/dist/runtime-kernel.d.ts +1 -0
- package/dist/runtime-kernel.js +152 -6
- package/dist/runtime-kernel.js.map +1 -1
- package/dist/testkit/agent-harness/scriptedInferenceHarness.d.cts +24 -6
- package/dist/testkit/agent-harness/scriptedInferenceHarness.d.ts +24 -6
- package/dist/testkit/scenario/graphScenario.d.cts +89 -0
- package/dist/testkit/scenario/graphScenario.d.ts +89 -0
- package/dist/testkit/scenario/pendingUserInputQueue.d.cts +26 -0
- package/dist/testkit/scenario/pendingUserInputQueue.d.ts +26 -0
- package/dist/testkit/scenario/runtimeEventRecorder.d.cts +36 -0
- package/dist/testkit/scenario/runtimeEventRecorder.d.ts +36 -0
- package/dist/testkit/scenario/scriptedToolRuntime.d.cts +51 -0
- package/dist/testkit/scenario/scriptedToolRuntime.d.ts +51 -0
- package/dist/testkit/scenario/steeringInvariants.d.cts +33 -0
- package/dist/testkit/scenario/steeringInvariants.d.ts +33 -0
- package/dist/testkit/scenario/timeline.d.cts +27 -0
- package/dist/testkit/scenario/timeline.d.ts +27 -0
- package/dist/testkit.cjs +722 -19
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.d.cts +7 -1
- package/dist/testkit.d.ts +7 -1
- package/dist/testkit.js +714 -20
- package/dist/testkit.js.map +1 -1
- package/docs/integration/README.md +1 -0
- package/docs/integration/mid-run-user-input.md +73 -0
- package/docs/integration/realtime.md +4 -0
- package/docs/integration/run-supervisor.md +1 -0
- package/docs/integration/testing.md +40 -4
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CanonicalLlmUsage } from '../../contracts/token-usage.cjs';
|
|
2
2
|
import { ProviderContinuation } from '../../contracts/provider-continuation.cjs';
|
|
3
|
-
import { CanonicalInferenceRequest, CanonicalInferenceFinishReason } from '../../ports/canonical-inference.cjs';
|
|
3
|
+
import { CanonicalInferenceRequest, CanonicalInferencePort, CanonicalInferenceFinishReason } from '../../ports/canonical-inference.cjs';
|
|
4
4
|
import { LlmCallOptions } from '../../ports/llm-call.cjs';
|
|
5
5
|
import { LlmInputMaterializerPort } from '../../ports/llm-input-materialization.cjs';
|
|
6
6
|
import { LlmCaller } from '../../runtime-kernel/llm/caller.cjs';
|
|
@@ -14,9 +14,12 @@ interface ScriptedLlmCall {
|
|
|
14
14
|
readonly options: LlmCallOptions;
|
|
15
15
|
}
|
|
16
16
|
interface ScriptedToolCall {
|
|
17
|
-
|
|
17
|
+
/** 省略时按调用序号生成 `call_<调用序号>_<位置>`,同一脚本内不会重复。 */
|
|
18
|
+
id?: string;
|
|
18
19
|
name: string;
|
|
19
|
-
argumentsJson
|
|
20
|
+
/** 二选一:`arguments` 直接给对象;`argumentsJson` 用于测试非法或特殊 JSON。都省略时为 `{}`。 */
|
|
21
|
+
arguments?: Record<string, unknown>;
|
|
22
|
+
argumentsJson?: string;
|
|
20
23
|
index?: number;
|
|
21
24
|
continuations?: ProviderContinuation[];
|
|
22
25
|
}
|
|
@@ -34,19 +37,34 @@ interface ScriptedLlmTurn {
|
|
|
34
37
|
retryable: boolean;
|
|
35
38
|
};
|
|
36
39
|
throwAfterEvents?: string | Error;
|
|
37
|
-
|
|
40
|
+
/**
|
|
41
|
+
* 在这次调用开始流式输出前执行,可以是异步。
|
|
42
|
+
*
|
|
43
|
+
* 用来断言请求内容,也用来在“第 N 次模型调用进行中”这一刻触发动作(插话、暂停、取消),
|
|
44
|
+
* 或等待测试放行(返回一个由测试控制的 Promise)。
|
|
45
|
+
*/
|
|
46
|
+
assertCall?: (call: ScriptedLlmCall) => void | Promise<void>;
|
|
38
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* 脚本:按顺序消费的回合表,或按请求即时决定回合的函数。
|
|
50
|
+
*
|
|
51
|
+
* 函数形式适合“看到某条工具结果再决定下一步”“随机组合”这类不能提前写死顺序的场景。
|
|
52
|
+
*/
|
|
53
|
+
type ScriptedInferenceScript = readonly ScriptedLlmTurn[] | ((call: ScriptedLlmCall, callIndex: number) => ScriptedLlmTurn | Promise<ScriptedLlmTurn>);
|
|
39
54
|
interface ScriptedInferenceHarness {
|
|
40
55
|
getCalls(): ScriptedLlmCall[];
|
|
41
56
|
getConsumedTurnCount(): number;
|
|
42
57
|
getLlmCaller(): ScriptedLlmCaller;
|
|
58
|
+
/** 直接拿推理端口,交给 Host 自己的 LlmCaller / 推理适配装配。 */
|
|
59
|
+
getInferencePort(): CanonicalInferencePort;
|
|
60
|
+
/** 回合表形式时检查是否全部消费;函数形式没有“剩余回合”,总是通过。 */
|
|
43
61
|
assertAllTurnsConsumed(): void;
|
|
44
62
|
}
|
|
45
63
|
interface ScriptedInferenceHarnessOptions {
|
|
46
64
|
modelCatalog?: ModelCatalogLike;
|
|
47
65
|
llmInputMaterializer?: LlmInputMaterializerPort;
|
|
48
66
|
}
|
|
49
|
-
declare function createScriptedInferenceHarness(
|
|
67
|
+
declare function createScriptedInferenceHarness(script: ScriptedInferenceScript, options?: ScriptedInferenceHarnessOptions): ScriptedInferenceHarness;
|
|
50
68
|
|
|
51
69
|
export { createScriptedInferenceHarness };
|
|
52
|
-
export type { ScriptedInferenceHarness, ScriptedInferenceHarnessOptions, ScriptedLlmCall, ScriptedLlmTurn, ScriptedToolCall };
|
|
70
|
+
export type { ScriptedInferenceHarness, ScriptedInferenceHarnessOptions, ScriptedInferenceScript, ScriptedLlmCall, ScriptedLlmTurn, ScriptedToolCall };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CanonicalLlmUsage } from '../../contracts/token-usage.js';
|
|
2
2
|
import { ProviderContinuation } from '../../contracts/provider-continuation.js';
|
|
3
|
-
import { CanonicalInferenceRequest, CanonicalInferenceFinishReason } from '../../ports/canonical-inference.js';
|
|
3
|
+
import { CanonicalInferenceRequest, CanonicalInferencePort, CanonicalInferenceFinishReason } from '../../ports/canonical-inference.js';
|
|
4
4
|
import { LlmCallOptions } from '../../ports/llm-call.js';
|
|
5
5
|
import { LlmInputMaterializerPort } from '../../ports/llm-input-materialization.js';
|
|
6
6
|
import { LlmCaller } from '../../runtime-kernel/llm/caller.js';
|
|
@@ -14,9 +14,12 @@ interface ScriptedLlmCall {
|
|
|
14
14
|
readonly options: LlmCallOptions;
|
|
15
15
|
}
|
|
16
16
|
interface ScriptedToolCall {
|
|
17
|
-
|
|
17
|
+
/** 省略时按调用序号生成 `call_<调用序号>_<位置>`,同一脚本内不会重复。 */
|
|
18
|
+
id?: string;
|
|
18
19
|
name: string;
|
|
19
|
-
argumentsJson
|
|
20
|
+
/** 二选一:`arguments` 直接给对象;`argumentsJson` 用于测试非法或特殊 JSON。都省略时为 `{}`。 */
|
|
21
|
+
arguments?: Record<string, unknown>;
|
|
22
|
+
argumentsJson?: string;
|
|
20
23
|
index?: number;
|
|
21
24
|
continuations?: ProviderContinuation[];
|
|
22
25
|
}
|
|
@@ -34,19 +37,34 @@ interface ScriptedLlmTurn {
|
|
|
34
37
|
retryable: boolean;
|
|
35
38
|
};
|
|
36
39
|
throwAfterEvents?: string | Error;
|
|
37
|
-
|
|
40
|
+
/**
|
|
41
|
+
* 在这次调用开始流式输出前执行,可以是异步。
|
|
42
|
+
*
|
|
43
|
+
* 用来断言请求内容,也用来在“第 N 次模型调用进行中”这一刻触发动作(插话、暂停、取消),
|
|
44
|
+
* 或等待测试放行(返回一个由测试控制的 Promise)。
|
|
45
|
+
*/
|
|
46
|
+
assertCall?: (call: ScriptedLlmCall) => void | Promise<void>;
|
|
38
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* 脚本:按顺序消费的回合表,或按请求即时决定回合的函数。
|
|
50
|
+
*
|
|
51
|
+
* 函数形式适合“看到某条工具结果再决定下一步”“随机组合”这类不能提前写死顺序的场景。
|
|
52
|
+
*/
|
|
53
|
+
type ScriptedInferenceScript = readonly ScriptedLlmTurn[] | ((call: ScriptedLlmCall, callIndex: number) => ScriptedLlmTurn | Promise<ScriptedLlmTurn>);
|
|
39
54
|
interface ScriptedInferenceHarness {
|
|
40
55
|
getCalls(): ScriptedLlmCall[];
|
|
41
56
|
getConsumedTurnCount(): number;
|
|
42
57
|
getLlmCaller(): ScriptedLlmCaller;
|
|
58
|
+
/** 直接拿推理端口,交给 Host 自己的 LlmCaller / 推理适配装配。 */
|
|
59
|
+
getInferencePort(): CanonicalInferencePort;
|
|
60
|
+
/** 回合表形式时检查是否全部消费;函数形式没有“剩余回合”,总是通过。 */
|
|
43
61
|
assertAllTurnsConsumed(): void;
|
|
44
62
|
}
|
|
45
63
|
interface ScriptedInferenceHarnessOptions {
|
|
46
64
|
modelCatalog?: ModelCatalogLike;
|
|
47
65
|
llmInputMaterializer?: LlmInputMaterializerPort;
|
|
48
66
|
}
|
|
49
|
-
declare function createScriptedInferenceHarness(
|
|
67
|
+
declare function createScriptedInferenceHarness(script: ScriptedInferenceScript, options?: ScriptedInferenceHarnessOptions): ScriptedInferenceHarness;
|
|
50
68
|
|
|
51
69
|
export { createScriptedInferenceHarness };
|
|
52
|
-
export type { ScriptedInferenceHarness, ScriptedInferenceHarnessOptions, ScriptedLlmCall, ScriptedLlmTurn, ScriptedToolCall };
|
|
70
|
+
export type { ScriptedInferenceHarness, ScriptedInferenceHarnessOptions, ScriptedInferenceScript, ScriptedLlmCall, ScriptedLlmTurn, ScriptedToolCall };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { RoutedRuntimeEvent, RuntimeEvent } from '../../contracts/events.cjs';
|
|
2
|
+
import { EngineState } from '../../runtime-kernel/graph-engine/types.cjs';
|
|
3
|
+
import { ObservationPreviewPort } from '../../runtime-kernel/tools/ports.cjs';
|
|
4
|
+
import { GraphAgentExecutorDependencies } from '../../runtime-kernel/graph-engine/executor.cjs';
|
|
5
|
+
import { GraphExecutorContextBuilder } from '../../runtime-kernel/graph-engine/executorContextBuilder.cjs';
|
|
6
|
+
import { PendingUserInput } from '../../runtime-kernel/graph-engine/definitions/pendingUserInput.cjs';
|
|
7
|
+
import { ScriptedInferenceHarness, ScriptedLlmCall, ScriptedInferenceScript } from '../agent-harness/scriptedInferenceHarness.cjs';
|
|
8
|
+
import { PendingUserInputQueue } from './pendingUserInputQueue.cjs';
|
|
9
|
+
import { ScriptedToolRuntime, ScriptedToolMap } from './scriptedToolRuntime.cjs';
|
|
10
|
+
import { ValidateSteeringInvariantsOptions } from './steeringInvariants.cjs';
|
|
11
|
+
import { TimelineOptions } from './timeline.cjs';
|
|
12
|
+
|
|
13
|
+
interface GraphScenarioOptions {
|
|
14
|
+
/** 脚本模型:回合表或按请求决定回合的函数。 */
|
|
15
|
+
model: ScriptedInferenceScript;
|
|
16
|
+
tools?: ScriptedToolMap;
|
|
17
|
+
conversationId?: string;
|
|
18
|
+
/**
|
|
19
|
+
* 会话里已有的历史:第一次运行前就在,按 Host 读到的原样交给运行(不经过事件总线和存储)。
|
|
20
|
+
* `history()` 会把它排在最前面。
|
|
21
|
+
*/
|
|
22
|
+
history?: readonly RuntimeEvent[];
|
|
23
|
+
/** 每次运行的图步数预算,默认 16。 */
|
|
24
|
+
maxSteps?: number;
|
|
25
|
+
/** 默认用 Agent profile 把历史转成模型消息(与插话、工具分组的真实格式一致)。 */
|
|
26
|
+
contextBuilder?: GraphExecutorContextBuilder;
|
|
27
|
+
observationPreview?: ObservationPreviewPort;
|
|
28
|
+
tokenizer?: GraphAgentExecutorDependencies['tokenizer'];
|
|
29
|
+
/** 写断点前调用;抛错即模拟存储失败。`events` 是这次边界要一起落盘的事实。 */
|
|
30
|
+
beforeCheckpointWrite?: (input: {
|
|
31
|
+
readonly checkpointKey: string;
|
|
32
|
+
readonly events: readonly RuntimeEvent[];
|
|
33
|
+
}) => void | Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
interface GraphScenarioStartInput {
|
|
36
|
+
query: string;
|
|
37
|
+
runId?: string;
|
|
38
|
+
/** 覆盖默认请求字段(promptKey、model_id、enableTools 等)。 */
|
|
39
|
+
request?: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
type GraphScenarioStatus = 'yielded' | 'awaiting_user' | 'paused' | 'cancelled' | 'failed';
|
|
42
|
+
interface GraphScenarioRun {
|
|
43
|
+
readonly runId: string;
|
|
44
|
+
readonly status: GraphScenarioStatus;
|
|
45
|
+
/** 只有 status=failed 时有值。 */
|
|
46
|
+
readonly error?: unknown;
|
|
47
|
+
/** 运行停下时还没送达、被 Host 收回的插话(按提交顺序)。 */
|
|
48
|
+
readonly undeliveredSteers: readonly PendingUserInput[];
|
|
49
|
+
}
|
|
50
|
+
interface GraphScenario {
|
|
51
|
+
readonly conversationId: string;
|
|
52
|
+
readonly model: ScriptedInferenceHarness;
|
|
53
|
+
readonly tools: ScriptedToolRuntime;
|
|
54
|
+
readonly steering: PendingUserInputQueue;
|
|
55
|
+
/** 全部运行在实时通道上发布的事件(含流式进度)。 */
|
|
56
|
+
readonly live: RoutedRuntimeEvent[];
|
|
57
|
+
/** 开始一次新运行;会话里之前运行的持久历史自动带上。 */
|
|
58
|
+
start(input: string | GraphScenarioStartInput): Promise<GraphScenarioRun>;
|
|
59
|
+
/** 从最近一次暂停的断点继续。 */
|
|
60
|
+
continue(): Promise<GraphScenarioRun>;
|
|
61
|
+
/** 给当前(或下一次)运行提交插话,返回插话 id。 */
|
|
62
|
+
steer(content: string, options?: {
|
|
63
|
+
id?: string;
|
|
64
|
+
}): string;
|
|
65
|
+
/** 请求暂停当前运行(下一个安全边界停下,可 `continue()`)。 */
|
|
66
|
+
pause(): void;
|
|
67
|
+
/** 取消当前运行。 */
|
|
68
|
+
cancel(): void;
|
|
69
|
+
/** 会话的持久历史:预置历史 + 事件存储里的顺序。 */
|
|
70
|
+
history(): Promise<RuntimeEvent[]>;
|
|
71
|
+
checkpoint(runId?: string): Promise<EngineState | null>;
|
|
72
|
+
/** 持久历史的可读时间线。 */
|
|
73
|
+
timeline(options?: TimelineOptions): Promise<string[]>;
|
|
74
|
+
modelCalls(): ScriptedLlmCall[];
|
|
75
|
+
/** 校验插话不变量与历史 id 唯一;失败时附上时间线。 */
|
|
76
|
+
assertInvariants(options?: ValidateSteeringInvariantsOptions): Promise<void>;
|
|
77
|
+
close(): Promise<void>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 内存里跑真实 Graph 的场景夹具:真实的 LlmNode / GraphAgentExecutor / ToolNode / WaitUserNode、
|
|
81
|
+
* 事件总线、持久化队列与断点(经过一次 JSON 序列化往返),模型和工具用脚本代替。
|
|
82
|
+
*
|
|
83
|
+
* 一个场景就是一段会话:可以连续开多次运行、在模型调用或工具执行的任意时刻插话、暂停、取消,
|
|
84
|
+
* 最后用 `timeline()` 和 `assertInvariants()` 检查结果。
|
|
85
|
+
*/
|
|
86
|
+
declare function createGraphScenario(options: GraphScenarioOptions): GraphScenario;
|
|
87
|
+
|
|
88
|
+
export { createGraphScenario };
|
|
89
|
+
export type { GraphScenario, GraphScenarioOptions, GraphScenarioRun, GraphScenarioStartInput, GraphScenarioStatus };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { RoutedRuntimeEvent, RuntimeEvent } from '../../contracts/events.js';
|
|
2
|
+
import { EngineState } from '../../runtime-kernel/graph-engine/types.js';
|
|
3
|
+
import { ObservationPreviewPort } from '../../runtime-kernel/tools/ports.js';
|
|
4
|
+
import { GraphAgentExecutorDependencies } from '../../runtime-kernel/graph-engine/executor.js';
|
|
5
|
+
import { GraphExecutorContextBuilder } from '../../runtime-kernel/graph-engine/executorContextBuilder.js';
|
|
6
|
+
import { PendingUserInput } from '../../runtime-kernel/graph-engine/definitions/pendingUserInput.js';
|
|
7
|
+
import { ScriptedInferenceHarness, ScriptedLlmCall, ScriptedInferenceScript } from '../agent-harness/scriptedInferenceHarness.js';
|
|
8
|
+
import { PendingUserInputQueue } from './pendingUserInputQueue.js';
|
|
9
|
+
import { ScriptedToolRuntime, ScriptedToolMap } from './scriptedToolRuntime.js';
|
|
10
|
+
import { ValidateSteeringInvariantsOptions } from './steeringInvariants.js';
|
|
11
|
+
import { TimelineOptions } from './timeline.js';
|
|
12
|
+
|
|
13
|
+
interface GraphScenarioOptions {
|
|
14
|
+
/** 脚本模型:回合表或按请求决定回合的函数。 */
|
|
15
|
+
model: ScriptedInferenceScript;
|
|
16
|
+
tools?: ScriptedToolMap;
|
|
17
|
+
conversationId?: string;
|
|
18
|
+
/**
|
|
19
|
+
* 会话里已有的历史:第一次运行前就在,按 Host 读到的原样交给运行(不经过事件总线和存储)。
|
|
20
|
+
* `history()` 会把它排在最前面。
|
|
21
|
+
*/
|
|
22
|
+
history?: readonly RuntimeEvent[];
|
|
23
|
+
/** 每次运行的图步数预算,默认 16。 */
|
|
24
|
+
maxSteps?: number;
|
|
25
|
+
/** 默认用 Agent profile 把历史转成模型消息(与插话、工具分组的真实格式一致)。 */
|
|
26
|
+
contextBuilder?: GraphExecutorContextBuilder;
|
|
27
|
+
observationPreview?: ObservationPreviewPort;
|
|
28
|
+
tokenizer?: GraphAgentExecutorDependencies['tokenizer'];
|
|
29
|
+
/** 写断点前调用;抛错即模拟存储失败。`events` 是这次边界要一起落盘的事实。 */
|
|
30
|
+
beforeCheckpointWrite?: (input: {
|
|
31
|
+
readonly checkpointKey: string;
|
|
32
|
+
readonly events: readonly RuntimeEvent[];
|
|
33
|
+
}) => void | Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
interface GraphScenarioStartInput {
|
|
36
|
+
query: string;
|
|
37
|
+
runId?: string;
|
|
38
|
+
/** 覆盖默认请求字段(promptKey、model_id、enableTools 等)。 */
|
|
39
|
+
request?: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
type GraphScenarioStatus = 'yielded' | 'awaiting_user' | 'paused' | 'cancelled' | 'failed';
|
|
42
|
+
interface GraphScenarioRun {
|
|
43
|
+
readonly runId: string;
|
|
44
|
+
readonly status: GraphScenarioStatus;
|
|
45
|
+
/** 只有 status=failed 时有值。 */
|
|
46
|
+
readonly error?: unknown;
|
|
47
|
+
/** 运行停下时还没送达、被 Host 收回的插话(按提交顺序)。 */
|
|
48
|
+
readonly undeliveredSteers: readonly PendingUserInput[];
|
|
49
|
+
}
|
|
50
|
+
interface GraphScenario {
|
|
51
|
+
readonly conversationId: string;
|
|
52
|
+
readonly model: ScriptedInferenceHarness;
|
|
53
|
+
readonly tools: ScriptedToolRuntime;
|
|
54
|
+
readonly steering: PendingUserInputQueue;
|
|
55
|
+
/** 全部运行在实时通道上发布的事件(含流式进度)。 */
|
|
56
|
+
readonly live: RoutedRuntimeEvent[];
|
|
57
|
+
/** 开始一次新运行;会话里之前运行的持久历史自动带上。 */
|
|
58
|
+
start(input: string | GraphScenarioStartInput): Promise<GraphScenarioRun>;
|
|
59
|
+
/** 从最近一次暂停的断点继续。 */
|
|
60
|
+
continue(): Promise<GraphScenarioRun>;
|
|
61
|
+
/** 给当前(或下一次)运行提交插话,返回插话 id。 */
|
|
62
|
+
steer(content: string, options?: {
|
|
63
|
+
id?: string;
|
|
64
|
+
}): string;
|
|
65
|
+
/** 请求暂停当前运行(下一个安全边界停下,可 `continue()`)。 */
|
|
66
|
+
pause(): void;
|
|
67
|
+
/** 取消当前运行。 */
|
|
68
|
+
cancel(): void;
|
|
69
|
+
/** 会话的持久历史:预置历史 + 事件存储里的顺序。 */
|
|
70
|
+
history(): Promise<RuntimeEvent[]>;
|
|
71
|
+
checkpoint(runId?: string): Promise<EngineState | null>;
|
|
72
|
+
/** 持久历史的可读时间线。 */
|
|
73
|
+
timeline(options?: TimelineOptions): Promise<string[]>;
|
|
74
|
+
modelCalls(): ScriptedLlmCall[];
|
|
75
|
+
/** 校验插话不变量与历史 id 唯一;失败时附上时间线。 */
|
|
76
|
+
assertInvariants(options?: ValidateSteeringInvariantsOptions): Promise<void>;
|
|
77
|
+
close(): Promise<void>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 内存里跑真实 Graph 的场景夹具:真实的 LlmNode / GraphAgentExecutor / ToolNode / WaitUserNode、
|
|
81
|
+
* 事件总线、持久化队列与断点(经过一次 JSON 序列化往返),模型和工具用脚本代替。
|
|
82
|
+
*
|
|
83
|
+
* 一个场景就是一段会话:可以连续开多次运行、在模型调用或工具执行的任意时刻插话、暂停、取消,
|
|
84
|
+
* 最后用 `timeline()` 和 `assertInvariants()` 检查结果。
|
|
85
|
+
*/
|
|
86
|
+
declare function createGraphScenario(options: GraphScenarioOptions): GraphScenario;
|
|
87
|
+
|
|
88
|
+
export { createGraphScenario };
|
|
89
|
+
export type { GraphScenario, GraphScenarioOptions, GraphScenarioRun, GraphScenarioStartInput, GraphScenarioStatus };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { PendingUserInputPort, PendingUserInput } from '../../runtime-kernel/graph-engine/definitions/pendingUserInput.cjs';
|
|
2
|
+
|
|
3
|
+
type PendingUserInputWithdrawResult = 'withdrawn' | 'claimed' | 'delivered' | 'unknown';
|
|
4
|
+
interface PendingUserInputQueue {
|
|
5
|
+
/** 交给 Graph 的端口;claim / confirm / release 语义与 Host 合同一致。 */
|
|
6
|
+
readonly port: PendingUserInputPort;
|
|
7
|
+
/** 提交一条插话,返回它的 id(也是送达后 user_input 事实的 id)。 */
|
|
8
|
+
submit(content: string, options?: {
|
|
9
|
+
id?: string;
|
|
10
|
+
timestamp?: number;
|
|
11
|
+
}): string;
|
|
12
|
+
/** 只能撤回还没被取用的;已被取用或已送达的保持原状。 */
|
|
13
|
+
withdraw(id: string): PendingUserInputWithdrawResult;
|
|
14
|
+
/** 取走全部未取用的(运行结束时 Host 收回没送达的插话)。 */
|
|
15
|
+
drain(): PendingUserInput[];
|
|
16
|
+
pending(): readonly PendingUserInput[];
|
|
17
|
+
claimed(): readonly PendingUserInput[];
|
|
18
|
+
delivered(): readonly PendingUserInput[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 内存版插话队列:给测试和最小 Host 用的 PendingUserInputPort 参考实现。
|
|
22
|
+
*/
|
|
23
|
+
declare function createPendingUserInputQueue(): PendingUserInputQueue;
|
|
24
|
+
|
|
25
|
+
export { createPendingUserInputQueue };
|
|
26
|
+
export type { PendingUserInputQueue, PendingUserInputWithdrawResult };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { PendingUserInputPort, PendingUserInput } from '../../runtime-kernel/graph-engine/definitions/pendingUserInput.js';
|
|
2
|
+
|
|
3
|
+
type PendingUserInputWithdrawResult = 'withdrawn' | 'claimed' | 'delivered' | 'unknown';
|
|
4
|
+
interface PendingUserInputQueue {
|
|
5
|
+
/** 交给 Graph 的端口;claim / confirm / release 语义与 Host 合同一致。 */
|
|
6
|
+
readonly port: PendingUserInputPort;
|
|
7
|
+
/** 提交一条插话,返回它的 id(也是送达后 user_input 事实的 id)。 */
|
|
8
|
+
submit(content: string, options?: {
|
|
9
|
+
id?: string;
|
|
10
|
+
timestamp?: number;
|
|
11
|
+
}): string;
|
|
12
|
+
/** 只能撤回还没被取用的;已被取用或已送达的保持原状。 */
|
|
13
|
+
withdraw(id: string): PendingUserInputWithdrawResult;
|
|
14
|
+
/** 取走全部未取用的(运行结束时 Host 收回没送达的插话)。 */
|
|
15
|
+
drain(): PendingUserInput[];
|
|
16
|
+
pending(): readonly PendingUserInput[];
|
|
17
|
+
claimed(): readonly PendingUserInput[];
|
|
18
|
+
delivered(): readonly PendingUserInput[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 内存版插话队列:给测试和最小 Host 用的 PendingUserInputPort 参考实现。
|
|
22
|
+
*/
|
|
23
|
+
declare function createPendingUserInputQueue(): PendingUserInputQueue;
|
|
24
|
+
|
|
25
|
+
export { createPendingUserInputQueue };
|
|
26
|
+
export type { PendingUserInputQueue, PendingUserInputWithdrawResult };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { RoutedRuntimeEvent, RuntimeEventRoutingIdentity } from '../../contracts/events.cjs';
|
|
2
|
+
import { RuntimeEventSink } from '../../runtime-kernel/graph-engine/types.cjs';
|
|
3
|
+
import { EventBus } from '../../runtime-kernel/execution/event-bus.cjs';
|
|
4
|
+
import { EventSequencer } from '../../runtime-kernel/execution/sequencer.cjs';
|
|
5
|
+
import { RuntimeEventPublisher } from '../../runtime-kernel/execution/runtimeEventPublisher.cjs';
|
|
6
|
+
|
|
7
|
+
interface RuntimeEventRecorderOptions {
|
|
8
|
+
conversationId?: string;
|
|
9
|
+
runId?: string;
|
|
10
|
+
/** 给出时按子运行身份发布(lane=child、visibility=parent-trace)。 */
|
|
11
|
+
parentRunId?: string;
|
|
12
|
+
lane?: RuntimeEventRoutingIdentity['lane'];
|
|
13
|
+
visibility?: RuntimeEventRoutingIdentity['visibility'];
|
|
14
|
+
}
|
|
15
|
+
interface RuntimeEventRecorder {
|
|
16
|
+
/** Graph 节点使用的唯一发布出口(经过 admission,附着 run 身份与序号)。 */
|
|
17
|
+
readonly sink: RuntimeEventSink;
|
|
18
|
+
/** 按发布顺序收到的全部事件,包括只走实时通道的进度事件。 */
|
|
19
|
+
readonly events: RoutedRuntimeEvent[];
|
|
20
|
+
readonly eventBus: EventBus;
|
|
21
|
+
readonly sequencer: EventSequencer;
|
|
22
|
+
readonly publisher: RuntimeEventPublisher;
|
|
23
|
+
/** 同一会话、同一条总线上再开一个运行身份(例如多轮对话的下一次运行)。 */
|
|
24
|
+
publisherFor(identity: RuntimeEventRoutingIdentity): RuntimeEventPublisher;
|
|
25
|
+
close(): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 测试用的 RuntimeEvent 发布出口:一条真实的 EventSequencer → EventBus → RuntimeEventPublisher 链,
|
|
29
|
+
* 并把总线上的事件按顺序记下来。
|
|
30
|
+
*
|
|
31
|
+
* 取代各测试里手写的 sequencer / bus / publisher 三件套。
|
|
32
|
+
*/
|
|
33
|
+
declare function createRuntimeEventRecorder(options?: RuntimeEventRecorderOptions): RuntimeEventRecorder;
|
|
34
|
+
|
|
35
|
+
export { createRuntimeEventRecorder };
|
|
36
|
+
export type { RuntimeEventRecorder, RuntimeEventRecorderOptions };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { RoutedRuntimeEvent, RuntimeEventRoutingIdentity } from '../../contracts/events.js';
|
|
2
|
+
import { RuntimeEventSink } from '../../runtime-kernel/graph-engine/types.js';
|
|
3
|
+
import { EventBus } from '../../runtime-kernel/execution/event-bus.js';
|
|
4
|
+
import { EventSequencer } from '../../runtime-kernel/execution/sequencer.js';
|
|
5
|
+
import { RuntimeEventPublisher } from '../../runtime-kernel/execution/runtimeEventPublisher.js';
|
|
6
|
+
|
|
7
|
+
interface RuntimeEventRecorderOptions {
|
|
8
|
+
conversationId?: string;
|
|
9
|
+
runId?: string;
|
|
10
|
+
/** 给出时按子运行身份发布(lane=child、visibility=parent-trace)。 */
|
|
11
|
+
parentRunId?: string;
|
|
12
|
+
lane?: RuntimeEventRoutingIdentity['lane'];
|
|
13
|
+
visibility?: RuntimeEventRoutingIdentity['visibility'];
|
|
14
|
+
}
|
|
15
|
+
interface RuntimeEventRecorder {
|
|
16
|
+
/** Graph 节点使用的唯一发布出口(经过 admission,附着 run 身份与序号)。 */
|
|
17
|
+
readonly sink: RuntimeEventSink;
|
|
18
|
+
/** 按发布顺序收到的全部事件,包括只走实时通道的进度事件。 */
|
|
19
|
+
readonly events: RoutedRuntimeEvent[];
|
|
20
|
+
readonly eventBus: EventBus;
|
|
21
|
+
readonly sequencer: EventSequencer;
|
|
22
|
+
readonly publisher: RuntimeEventPublisher;
|
|
23
|
+
/** 同一会话、同一条总线上再开一个运行身份(例如多轮对话的下一次运行)。 */
|
|
24
|
+
publisherFor(identity: RuntimeEventRoutingIdentity): RuntimeEventPublisher;
|
|
25
|
+
close(): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 测试用的 RuntimeEvent 发布出口:一条真实的 EventSequencer → EventBus → RuntimeEventPublisher 链,
|
|
29
|
+
* 并把总线上的事件按顺序记下来。
|
|
30
|
+
*
|
|
31
|
+
* 取代各测试里手写的 sequencer / bus / publisher 三件套。
|
|
32
|
+
*/
|
|
33
|
+
declare function createRuntimeEventRecorder(options?: RuntimeEventRecorderOptions): RuntimeEventRecorder;
|
|
34
|
+
|
|
35
|
+
export { createRuntimeEventRecorder };
|
|
36
|
+
export type { RuntimeEventRecorder, RuntimeEventRecorderOptions };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ToolExecutionContext } from '../../runtime-kernel/tools/toolExecutionContext.cjs';
|
|
2
|
+
import { ToolRuntimePort, ToolRuntimeDefinition } from '../../runtime-kernel/tools/ports.cjs';
|
|
3
|
+
import { ToolParameterSchema } from '../../ports/tool-schema.cjs';
|
|
4
|
+
import { ToolArgs } from '../../runtime-kernel/tools/toolContracts.cjs';
|
|
5
|
+
|
|
6
|
+
/** 工具脚本的返回:字符串即成功的 observation;对象可以给出结构化数据或失败。 */
|
|
7
|
+
type ScriptedToolOutcome = string | {
|
|
8
|
+
readonly observation?: string;
|
|
9
|
+
readonly data?: Record<string, unknown>;
|
|
10
|
+
/** 给出即失败:工具按执行错误结算。 */
|
|
11
|
+
readonly error?: string;
|
|
12
|
+
readonly errorCode?: string;
|
|
13
|
+
};
|
|
14
|
+
interface ScriptedToolInvocation {
|
|
15
|
+
readonly toolName: string;
|
|
16
|
+
readonly args: ToolArgs;
|
|
17
|
+
readonly context: ToolExecutionContext;
|
|
18
|
+
/** 该工具第几次被执行(从 1 开始)。 */
|
|
19
|
+
readonly count: number;
|
|
20
|
+
}
|
|
21
|
+
type ScriptedToolHandler = (invocation: ScriptedToolInvocation) => ScriptedToolOutcome | Promise<ScriptedToolOutcome>;
|
|
22
|
+
interface ScriptedToolSpec {
|
|
23
|
+
readonly run?: ScriptedToolHandler;
|
|
24
|
+
readonly description?: string;
|
|
25
|
+
readonly parameters?: ToolParameterSchema;
|
|
26
|
+
readonly validateArguments?: ToolRuntimeDefinition['validateArguments'];
|
|
27
|
+
}
|
|
28
|
+
type ScriptedToolMap = Readonly<Record<string, ScriptedToolHandler | ScriptedToolSpec>>;
|
|
29
|
+
interface ScriptedToolExecution {
|
|
30
|
+
readonly toolName: string;
|
|
31
|
+
readonly args: ToolArgs;
|
|
32
|
+
readonly startedAt: number;
|
|
33
|
+
finishedAt?: number;
|
|
34
|
+
outcome?: 'success' | 'error' | 'threw';
|
|
35
|
+
}
|
|
36
|
+
interface ScriptedToolRuntime extends ToolRuntimePort {
|
|
37
|
+
/** 按开始顺序记录的每次执行。 */
|
|
38
|
+
readonly executions: ScriptedToolExecution[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 按名字写工具脚本,得到一个真实可执行的 ToolRuntimePort。
|
|
42
|
+
*
|
|
43
|
+
* - 值是函数时即执行逻辑;可以是异步,用来在“工具执行中”这一刻插话、暂停、取消或等待放行;
|
|
44
|
+
* - 返回 `{ error }` 是工具自己报告失败(模型会看到错误结果,运行继续);
|
|
45
|
+
* - 抛错是工具端口本身失败,原样抛给 ToolNode,运行以失败结束(覆盖 Host 端口崩溃路径);
|
|
46
|
+
* - 不写执行逻辑时返回 `<工具名> done`。
|
|
47
|
+
*/
|
|
48
|
+
declare function createScriptedToolRuntime(tools?: ScriptedToolMap): ScriptedToolRuntime;
|
|
49
|
+
|
|
50
|
+
export { createScriptedToolRuntime };
|
|
51
|
+
export type { ScriptedToolExecution, ScriptedToolHandler, ScriptedToolInvocation, ScriptedToolMap, ScriptedToolOutcome, ScriptedToolRuntime, ScriptedToolSpec };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ToolExecutionContext } from '../../runtime-kernel/tools/toolExecutionContext.js';
|
|
2
|
+
import { ToolRuntimePort, ToolRuntimeDefinition } from '../../runtime-kernel/tools/ports.js';
|
|
3
|
+
import { ToolParameterSchema } from '../../ports/tool-schema.js';
|
|
4
|
+
import { ToolArgs } from '../../runtime-kernel/tools/toolContracts.js';
|
|
5
|
+
|
|
6
|
+
/** 工具脚本的返回:字符串即成功的 observation;对象可以给出结构化数据或失败。 */
|
|
7
|
+
type ScriptedToolOutcome = string | {
|
|
8
|
+
readonly observation?: string;
|
|
9
|
+
readonly data?: Record<string, unknown>;
|
|
10
|
+
/** 给出即失败:工具按执行错误结算。 */
|
|
11
|
+
readonly error?: string;
|
|
12
|
+
readonly errorCode?: string;
|
|
13
|
+
};
|
|
14
|
+
interface ScriptedToolInvocation {
|
|
15
|
+
readonly toolName: string;
|
|
16
|
+
readonly args: ToolArgs;
|
|
17
|
+
readonly context: ToolExecutionContext;
|
|
18
|
+
/** 该工具第几次被执行(从 1 开始)。 */
|
|
19
|
+
readonly count: number;
|
|
20
|
+
}
|
|
21
|
+
type ScriptedToolHandler = (invocation: ScriptedToolInvocation) => ScriptedToolOutcome | Promise<ScriptedToolOutcome>;
|
|
22
|
+
interface ScriptedToolSpec {
|
|
23
|
+
readonly run?: ScriptedToolHandler;
|
|
24
|
+
readonly description?: string;
|
|
25
|
+
readonly parameters?: ToolParameterSchema;
|
|
26
|
+
readonly validateArguments?: ToolRuntimeDefinition['validateArguments'];
|
|
27
|
+
}
|
|
28
|
+
type ScriptedToolMap = Readonly<Record<string, ScriptedToolHandler | ScriptedToolSpec>>;
|
|
29
|
+
interface ScriptedToolExecution {
|
|
30
|
+
readonly toolName: string;
|
|
31
|
+
readonly args: ToolArgs;
|
|
32
|
+
readonly startedAt: number;
|
|
33
|
+
finishedAt?: number;
|
|
34
|
+
outcome?: 'success' | 'error' | 'threw';
|
|
35
|
+
}
|
|
36
|
+
interface ScriptedToolRuntime extends ToolRuntimePort {
|
|
37
|
+
/** 按开始顺序记录的每次执行。 */
|
|
38
|
+
readonly executions: ScriptedToolExecution[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 按名字写工具脚本,得到一个真实可执行的 ToolRuntimePort。
|
|
42
|
+
*
|
|
43
|
+
* - 值是函数时即执行逻辑;可以是异步,用来在“工具执行中”这一刻插话、暂停、取消或等待放行;
|
|
44
|
+
* - 返回 `{ error }` 是工具自己报告失败(模型会看到错误结果,运行继续);
|
|
45
|
+
* - 抛错是工具端口本身失败,原样抛给 ToolNode,运行以失败结束(覆盖 Host 端口崩溃路径);
|
|
46
|
+
* - 不写执行逻辑时返回 `<工具名> done`。
|
|
47
|
+
*/
|
|
48
|
+
declare function createScriptedToolRuntime(tools?: ScriptedToolMap): ScriptedToolRuntime;
|
|
49
|
+
|
|
50
|
+
export { createScriptedToolRuntime };
|
|
51
|
+
export type { ScriptedToolExecution, ScriptedToolHandler, ScriptedToolInvocation, ScriptedToolMap, ScriptedToolOutcome, ScriptedToolRuntime, ScriptedToolSpec };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { RuntimeEvent } from '../../contracts/events.cjs';
|
|
2
|
+
import { ScriptedLlmCall } from '../agent-harness/scriptedInferenceHarness.cjs';
|
|
3
|
+
|
|
4
|
+
type SteeringInvariantId = 'S1_STEER_UNIQUE' | 'S2_STEER_AT_BATCH_BOUNDARY' | 'S3_STEER_IN_NEXT_MODEL_CALL' | 'S4_STEER_ONCE_PER_MODEL_CALL' | 'S5_STEER_KEPT_IN_LATER_CALLS';
|
|
5
|
+
interface SteeringInvariantFailure {
|
|
6
|
+
readonly id: SteeringInvariantId;
|
|
7
|
+
readonly message: string;
|
|
8
|
+
}
|
|
9
|
+
interface SteeringInvariantContext {
|
|
10
|
+
/** 会话的持久历史(按落盘顺序),可以跨多次运行。 */
|
|
11
|
+
readonly history: readonly RuntimeEvent[];
|
|
12
|
+
/** 同一会话里按时间顺序的全部模型调用。 */
|
|
13
|
+
readonly modelCalls: readonly ScriptedLlmCall[];
|
|
14
|
+
}
|
|
15
|
+
interface ValidateSteeringInvariantsOptions {
|
|
16
|
+
disabled?: readonly SteeringInvariantId[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 运行中插话的不变量。按“模型实际收到的消息”判断,而不是按实现细节判断:
|
|
20
|
+
*
|
|
21
|
+
* - S1 每条插话在历史里只出现一次;
|
|
22
|
+
* - S2 只在一批工具全部结算后送达:插话之前已决定的每个工具调用都已有结果;
|
|
23
|
+
* - S3 送达后的下一次模型调用(第一次带上前一批工具结果的调用)里就能看到它,并排在那批结果之后;
|
|
24
|
+
* - S4 任何一次模型调用里,同一条插话最多出现在一条用户消息中;
|
|
25
|
+
* - S5 一旦被模型看到,之后的每次调用都还带着它(当前实现保护本轮插话不被压缩)。
|
|
26
|
+
*
|
|
27
|
+
* 插话按原文子串匹配,Host 给正文包一层上下文(例如本地时间)不影响判断。
|
|
28
|
+
*/
|
|
29
|
+
declare function validateSteeringInvariants(context: SteeringInvariantContext, options?: ValidateSteeringInvariantsOptions): SteeringInvariantFailure[];
|
|
30
|
+
declare function assertSteeringInvariants(context: SteeringInvariantContext, options?: ValidateSteeringInvariantsOptions): void;
|
|
31
|
+
|
|
32
|
+
export { assertSteeringInvariants, validateSteeringInvariants };
|
|
33
|
+
export type { SteeringInvariantContext, SteeringInvariantFailure, SteeringInvariantId, ValidateSteeringInvariantsOptions };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { RuntimeEvent } from '../../contracts/events.js';
|
|
2
|
+
import { ScriptedLlmCall } from '../agent-harness/scriptedInferenceHarness.js';
|
|
3
|
+
|
|
4
|
+
type SteeringInvariantId = 'S1_STEER_UNIQUE' | 'S2_STEER_AT_BATCH_BOUNDARY' | 'S3_STEER_IN_NEXT_MODEL_CALL' | 'S4_STEER_ONCE_PER_MODEL_CALL' | 'S5_STEER_KEPT_IN_LATER_CALLS';
|
|
5
|
+
interface SteeringInvariantFailure {
|
|
6
|
+
readonly id: SteeringInvariantId;
|
|
7
|
+
readonly message: string;
|
|
8
|
+
}
|
|
9
|
+
interface SteeringInvariantContext {
|
|
10
|
+
/** 会话的持久历史(按落盘顺序),可以跨多次运行。 */
|
|
11
|
+
readonly history: readonly RuntimeEvent[];
|
|
12
|
+
/** 同一会话里按时间顺序的全部模型调用。 */
|
|
13
|
+
readonly modelCalls: readonly ScriptedLlmCall[];
|
|
14
|
+
}
|
|
15
|
+
interface ValidateSteeringInvariantsOptions {
|
|
16
|
+
disabled?: readonly SteeringInvariantId[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 运行中插话的不变量。按“模型实际收到的消息”判断,而不是按实现细节判断:
|
|
20
|
+
*
|
|
21
|
+
* - S1 每条插话在历史里只出现一次;
|
|
22
|
+
* - S2 只在一批工具全部结算后送达:插话之前已决定的每个工具调用都已有结果;
|
|
23
|
+
* - S3 送达后的下一次模型调用(第一次带上前一批工具结果的调用)里就能看到它,并排在那批结果之后;
|
|
24
|
+
* - S4 任何一次模型调用里,同一条插话最多出现在一条用户消息中;
|
|
25
|
+
* - S5 一旦被模型看到,之后的每次调用都还带着它(当前实现保护本轮插话不被压缩)。
|
|
26
|
+
*
|
|
27
|
+
* 插话按原文子串匹配,Host 给正文包一层上下文(例如本地时间)不影响判断。
|
|
28
|
+
*/
|
|
29
|
+
declare function validateSteeringInvariants(context: SteeringInvariantContext, options?: ValidateSteeringInvariantsOptions): SteeringInvariantFailure[];
|
|
30
|
+
declare function assertSteeringInvariants(context: SteeringInvariantContext, options?: ValidateSteeringInvariantsOptions): void;
|
|
31
|
+
|
|
32
|
+
export { assertSteeringInvariants, validateSteeringInvariants };
|
|
33
|
+
export type { SteeringInvariantContext, SteeringInvariantFailure, SteeringInvariantId, ValidateSteeringInvariantsOptions };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { RuntimeEvent } from '../../contracts/events.cjs';
|
|
2
|
+
import { ScriptedLlmCall } from '../agent-harness/scriptedInferenceHarness.cjs';
|
|
3
|
+
|
|
4
|
+
interface TimelineOptions {
|
|
5
|
+
/** 文本截断长度,默认 40。 */
|
|
6
|
+
maxText?: number;
|
|
7
|
+
/** 只保留这些类型;默认保留全部可持久化的业务事实,去掉 metrics / usage / audit。 */
|
|
8
|
+
types?: readonly RuntimeEvent['type'][];
|
|
9
|
+
}
|
|
10
|
+
/** 插话(运行中送达的用户输入)的原文:Host 可能把正文包了一层上下文,原文在 raw_content。 */
|
|
11
|
+
declare function userInputText(event: Extract<RuntimeEvent, {
|
|
12
|
+
type: 'user_input';
|
|
13
|
+
}>): string;
|
|
14
|
+
/**
|
|
15
|
+
* 把一串 RuntimeEvent 写成可读的时间线,一行一个事实。
|
|
16
|
+
*
|
|
17
|
+
* 用于断言整体顺序(`expect(timeline).toEqual([...])`)和失败时打印现场;
|
|
18
|
+
* 不比较时间戳、序号等每次运行都会变的字段。
|
|
19
|
+
*/
|
|
20
|
+
declare function formatRuntimeTimeline(events: readonly RuntimeEvent[], options?: TimelineOptions): string[];
|
|
21
|
+
/** 一次模型调用收到的消息,一行一条:`system` / `user "…"` / `assistant call search` / `tool #id "…"`。 */
|
|
22
|
+
declare function formatModelMessages(call: ScriptedLlmCall, options?: {
|
|
23
|
+
maxText?: number;
|
|
24
|
+
}): string[];
|
|
25
|
+
|
|
26
|
+
export { formatModelMessages, formatRuntimeTimeline, userInputText };
|
|
27
|
+
export type { TimelineOptions };
|