@linnlabs/linnkit 0.43.0 → 0.44.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 +44 -0
- package/dist/cli.cjs +101 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +101 -4
- 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 +103 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +103 -4
- package/dist/index.js.map +1 -1
- package/dist/quickstart.cjs +101 -4
- package/dist/quickstart.cjs.map +1 -1
- package/dist/quickstart.js +101 -4
- 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/types.d.cts +3 -0
- package/dist/runtime-kernel/graph-engine/types.d.ts +3 -0
- package/dist/runtime-kernel.cjs +101 -4
- 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 +101 -4
- 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 +671 -17
- 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 +663 -18
- 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/testing.md +40 -4
- package/package.json +2 -2
package/dist/quickstart.js
CHANGED
|
@@ -309,6 +309,10 @@ var UserInputMessage = BaseMessage.extend({
|
|
|
309
309
|
type: z.literal("user_input"),
|
|
310
310
|
attachments: RuntimeResourceRefs.optional()
|
|
311
311
|
});
|
|
312
|
+
var UserSteerMessage = BaseMessage.extend({
|
|
313
|
+
role: z.literal("user"),
|
|
314
|
+
type: z.literal("user_steer")
|
|
315
|
+
});
|
|
312
316
|
var UserContextMessage = BaseMessage.extend({
|
|
313
317
|
role: z.literal("user"),
|
|
314
318
|
// 产品上下文种类由 Host fence metadata 表达,不进入框架消息枚举。
|
|
@@ -317,7 +321,7 @@ var UserContextMessage = BaseMessage.extend({
|
|
|
317
321
|
"task_request"
|
|
318
322
|
])
|
|
319
323
|
});
|
|
320
|
-
var UserMessage = z.union([UserInputMessage, UserContextMessage]);
|
|
324
|
+
var UserMessage = z.union([UserInputMessage, UserSteerMessage, UserContextMessage]);
|
|
321
325
|
var AssistantMessage = BaseMessage.extend({
|
|
322
326
|
role: z.literal("assistant"),
|
|
323
327
|
type: z.enum(["thought", "final_answer", "tool_code", "tool_calls", "task_completion"])
|
|
@@ -1034,7 +1038,12 @@ var RuntimeEventShape = z.discriminatedUnion("type", [
|
|
|
1034
1038
|
content: z.string(),
|
|
1035
1039
|
raw_content: z.string().optional(),
|
|
1036
1040
|
source: z.enum(["user", "editor", "system"]).default("user"),
|
|
1037
|
-
attachments: RuntimeResourceRefs.optional()
|
|
1041
|
+
attachments: RuntimeResourceRefs.optional(),
|
|
1042
|
+
/**
|
|
1043
|
+
* 运行中途送达的用户输入(插话)。缺省表示运行起点的输入。
|
|
1044
|
+
* 上下文里投影为 `user_steer`,不改变“当前轮从哪条 user_input 开始”的判定。
|
|
1045
|
+
*/
|
|
1046
|
+
delivery: z.literal("mid_run").optional()
|
|
1038
1047
|
}),
|
|
1039
1048
|
BaseEvent.extend({
|
|
1040
1049
|
type: z.literal("thought"),
|
|
@@ -1481,6 +1490,11 @@ z.object({
|
|
|
1481
1490
|
run_id: RunIdSchema,
|
|
1482
1491
|
execution_id: ExecutionIdSchema
|
|
1483
1492
|
});
|
|
1493
|
+
var SSEUserInputEvent = BaseSSEEvent.extend({
|
|
1494
|
+
type: z.literal("user_input"),
|
|
1495
|
+
content: z.string(),
|
|
1496
|
+
delivery: z.literal("mid_run")
|
|
1497
|
+
});
|
|
1484
1498
|
var SSEThoughtEvent = BaseSSEEvent.extend({
|
|
1485
1499
|
type: z.literal("thought"),
|
|
1486
1500
|
thought_message_id: ThoughtMessageIdSchema.optional(),
|
|
@@ -1635,6 +1649,7 @@ var SSESummarizationErrorEvent = BaseSSEEvent.extend({
|
|
|
1635
1649
|
error: z.string()
|
|
1636
1650
|
});
|
|
1637
1651
|
z.discriminatedUnion("type", [
|
|
1652
|
+
SSEUserInputEvent,
|
|
1638
1653
|
SSEThoughtEvent,
|
|
1639
1654
|
SSEFinalAnswerChunkEvent,
|
|
1640
1655
|
SSEFinalAnswerResetEvent,
|
|
@@ -2653,6 +2668,7 @@ var NON_CHECKPOINT_LOCAL_KEYS = [
|
|
|
2653
2668
|
"runtimeEventCommitPort",
|
|
2654
2669
|
"commitExecutionBoundary",
|
|
2655
2670
|
"toolRecoveryPort",
|
|
2671
|
+
"pendingUserInputPort",
|
|
2656
2672
|
"runtimeFailureFactSink",
|
|
2657
2673
|
"signal",
|
|
2658
2674
|
"summarizationCallbacks",
|
|
@@ -6645,6 +6661,8 @@ function describeRuntimeEventLifecycle(event) {
|
|
|
6645
6661
|
case "run_execution_metrics":
|
|
6646
6662
|
case "history_summary":
|
|
6647
6663
|
return "event_bus_sse";
|
|
6664
|
+
case "user_input":
|
|
6665
|
+
return event.type === "user_input" && event.delivery === "mid_run" ? "event_bus_sse" : "none";
|
|
6648
6666
|
case "audit_envelope":
|
|
6649
6667
|
return "none";
|
|
6650
6668
|
default:
|
|
@@ -7088,6 +7106,16 @@ function requireEventTimestamp(value) {
|
|
|
7088
7106
|
function applyRuntimeEventToMemory(event, memory) {
|
|
7089
7107
|
switch (event.type) {
|
|
7090
7108
|
case "user_input": {
|
|
7109
|
+
if (event.delivery === "mid_run") {
|
|
7110
|
+
memory.appendMessage({
|
|
7111
|
+
id: event.id,
|
|
7112
|
+
role: "user",
|
|
7113
|
+
type: "user_steer",
|
|
7114
|
+
content: event.content,
|
|
7115
|
+
timestamp: event.timestamp
|
|
7116
|
+
});
|
|
7117
|
+
break;
|
|
7118
|
+
}
|
|
7091
7119
|
memory.addUserMessage(event.content, event.id, event.attachments);
|
|
7092
7120
|
break;
|
|
7093
7121
|
}
|
|
@@ -8735,6 +8763,62 @@ async function commitToolBoundary(state, result) {
|
|
|
8735
8763
|
await state.local.commitExecutionBoundary(state);
|
|
8736
8764
|
}
|
|
8737
8765
|
|
|
8766
|
+
// src/runtime-kernel/graph-engine/nodes/toolNode.pendingUserInput.ts
|
|
8767
|
+
function isPendingUserInputPort(value) {
|
|
8768
|
+
return !!value && typeof value === "object" && typeof Reflect.get(value, "claim") === "function" && typeof Reflect.get(value, "confirm") === "function" && typeof Reflect.get(value, "release") === "function";
|
|
8769
|
+
}
|
|
8770
|
+
function readRemainingSteps(state) {
|
|
8771
|
+
const value = state.local?.executorLocal?.remainingSteps;
|
|
8772
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
8773
|
+
}
|
|
8774
|
+
function readIdentity(value, field) {
|
|
8775
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
8776
|
+
throw new Error(`ToolNode pending user input requires ${field}`);
|
|
8777
|
+
}
|
|
8778
|
+
return value;
|
|
8779
|
+
}
|
|
8780
|
+
async function claimPendingUserInputs(state, result) {
|
|
8781
|
+
if (result.kind !== "route" || result.nextNodeId !== "llm") return void 0;
|
|
8782
|
+
const local = state.local;
|
|
8783
|
+
const port = local?.pendingUserInputPort;
|
|
8784
|
+
if (!isPendingUserInputPort(port)) return void 0;
|
|
8785
|
+
const signal = local?.signal;
|
|
8786
|
+
if (signal?.aborted || isRunPauseSignal(signal)) return void 0;
|
|
8787
|
+
const remainingSteps = readRemainingSteps(state);
|
|
8788
|
+
if (remainingSteps !== void 0 && remainingSteps < 1) return void 0;
|
|
8789
|
+
const inputs = await port.claim();
|
|
8790
|
+
if (inputs.length === 0) return void 0;
|
|
8791
|
+
const ids = inputs.map((input) => input.id);
|
|
8792
|
+
try {
|
|
8793
|
+
const conversationId = readIdentity(local?.conversationId, "conversationId");
|
|
8794
|
+
const turnId = readIdentity(local?.turnId, "turnId");
|
|
8795
|
+
const sink = requireRuntimeEventSink(local);
|
|
8796
|
+
const events = inputs.map((input) => sink(
|
|
8797
|
+
createUserInputEvent(readIdentity(input.id, "input id"), conversationId, turnId, input.content, {
|
|
8798
|
+
timestamp: input.timestamp ?? Date.now(),
|
|
8799
|
+
delivery: "mid_run"
|
|
8800
|
+
}),
|
|
8801
|
+
"ToolNode.pending_user_input"
|
|
8802
|
+
));
|
|
8803
|
+
state.local = {
|
|
8804
|
+
...state.local,
|
|
8805
|
+
history: appendWorkingHistory(parseRuntimeEvents(state.local?.history ?? []), events)
|
|
8806
|
+
};
|
|
8807
|
+
return {
|
|
8808
|
+
events,
|
|
8809
|
+
confirm: async () => {
|
|
8810
|
+
await port.confirm(ids);
|
|
8811
|
+
},
|
|
8812
|
+
release: async () => {
|
|
8813
|
+
await port.release(ids);
|
|
8814
|
+
}
|
|
8815
|
+
};
|
|
8816
|
+
} catch (error) {
|
|
8817
|
+
await port.release(ids);
|
|
8818
|
+
throw error;
|
|
8819
|
+
}
|
|
8820
|
+
}
|
|
8821
|
+
|
|
8738
8822
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
8739
8823
|
var logger11 = new Logger("ToolNode");
|
|
8740
8824
|
function isAbortSignal(value) {
|
|
@@ -8902,7 +8986,19 @@ var ToolNode = class {
|
|
|
8902
8986
|
});
|
|
8903
8987
|
throw result.error;
|
|
8904
8988
|
}
|
|
8905
|
-
await
|
|
8989
|
+
const steering = await claimPendingUserInputs(state, result);
|
|
8990
|
+
if (steering) {
|
|
8991
|
+
result = { ...result, events: [...result.events ?? [], ...steering.events] };
|
|
8992
|
+
try {
|
|
8993
|
+
await commitToolBoundary(state, result);
|
|
8994
|
+
} catch (error) {
|
|
8995
|
+
await steering.release();
|
|
8996
|
+
throw error;
|
|
8997
|
+
}
|
|
8998
|
+
await steering.confirm();
|
|
8999
|
+
} else {
|
|
9000
|
+
await commitToolBoundary(state, result);
|
|
9001
|
+
}
|
|
8906
9002
|
if (Array.isArray(result.events) && result.events.length > 0) {
|
|
8907
9003
|
events.push(...result.events);
|
|
8908
9004
|
}
|
|
@@ -9660,7 +9756,8 @@ function parseEngineCheckpoint(value) {
|
|
|
9660
9756
|
"runtimeFailureFactSink",
|
|
9661
9757
|
"summarizationCallbacks",
|
|
9662
9758
|
"commitExecutionBoundary",
|
|
9663
|
-
"toolRecoveryPort"
|
|
9759
|
+
"toolRecoveryPort",
|
|
9760
|
+
"pendingUserInputPort"
|
|
9664
9761
|
]) {
|
|
9665
9762
|
if (result.local && Object.hasOwn(result.local, key)) {
|
|
9666
9763
|
throw new Error(`Checkpoint must not contain execution capability: ${key}`);
|