@linnlabs/linnkit 0.42.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 +64 -0
- package/dist/cli.cjs +113 -5
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +113 -5
- 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/events.d.cts +4 -0
- package/dist/contracts/events.d.ts +4 -0
- package/dist/contracts/messages.d.cts +226 -2
- package/dist/contracts/messages.d.ts +226 -2
- package/dist/contracts/sse.d.cts +65 -1
- package/dist/contracts/sse.d.ts +65 -1
- 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 +115 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +115 -5
- package/dist/index.js.map +1 -1
- package/dist/quickstart.cjs +113 -5
- package/dist/quickstart.cjs.map +1 -1
- package/dist/quickstart.js +113 -5
- package/dist/quickstart.js.map +1 -1
- 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 +2 -1
- package/dist/runtime-kernel/graph-engine/engine.d.ts +2 -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 +113 -5
- 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 +113 -5
- 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 +683 -18
- 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 +675 -19
- 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/docs/integration/tool-development-guide.md +1 -0
- 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",
|
|
@@ -3216,6 +3232,16 @@ function mergeResumeSessionLocal(persistedLocal, localPatch) {
|
|
|
3216
3232
|
}
|
|
3217
3233
|
};
|
|
3218
3234
|
}
|
|
3235
|
+
function resolveResumeNodeId(local, requested) {
|
|
3236
|
+
const pending = local?.pendingToolCalls;
|
|
3237
|
+
if (!Array.isArray(pending) || pending.length === 0) return requested ?? "llm";
|
|
3238
|
+
if (requested !== void 0 && requested !== "tool") {
|
|
3239
|
+
throw new Error(
|
|
3240
|
+
`Graph resume must first run ${pending.length} pending tool call(s) from the interrupted batch: requested node=${requested}`
|
|
3241
|
+
);
|
|
3242
|
+
}
|
|
3243
|
+
return "tool";
|
|
3244
|
+
}
|
|
3219
3245
|
var GraphExecutor = class {
|
|
3220
3246
|
constructor(checkpointer, config = {}) {
|
|
3221
3247
|
this.checkpointer = checkpointer;
|
|
@@ -3328,13 +3354,14 @@ var GraphExecutor = class {
|
|
|
3328
3354
|
);
|
|
3329
3355
|
}
|
|
3330
3356
|
const resumedLocal = mergeResumeSessionLocal(current.local, input.localPatch);
|
|
3357
|
+
const nodeId = resolveResumeNodeId(resumedLocal, input.nodeId);
|
|
3331
3358
|
if (this.executionCheckpointPort && current.local?.executorLocal) {
|
|
3332
3359
|
resumedLocal.executorLocal = { ...current.local.executorLocal };
|
|
3333
3360
|
}
|
|
3334
3361
|
this.ephemeralLocals.set(checkpointKey, resumedLocal);
|
|
3335
3362
|
await this.commitCheckpoint(checkpointKey, {
|
|
3336
3363
|
...current,
|
|
3337
|
-
nodeId
|
|
3364
|
+
nodeId,
|
|
3338
3365
|
...this.executionCheckpointPort ? { executionStatus: "ready" } : {},
|
|
3339
3366
|
revision: currentRevision + 1,
|
|
3340
3367
|
local: sanitizeCheckpointLocal(resumedLocal)
|
|
@@ -6634,6 +6661,8 @@ function describeRuntimeEventLifecycle(event) {
|
|
|
6634
6661
|
case "run_execution_metrics":
|
|
6635
6662
|
case "history_summary":
|
|
6636
6663
|
return "event_bus_sse";
|
|
6664
|
+
case "user_input":
|
|
6665
|
+
return event.type === "user_input" && event.delivery === "mid_run" ? "event_bus_sse" : "none";
|
|
6637
6666
|
case "audit_envelope":
|
|
6638
6667
|
return "none";
|
|
6639
6668
|
default:
|
|
@@ -7077,6 +7106,16 @@ function requireEventTimestamp(value) {
|
|
|
7077
7106
|
function applyRuntimeEventToMemory(event, memory) {
|
|
7078
7107
|
switch (event.type) {
|
|
7079
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
|
+
}
|
|
7080
7119
|
memory.addUserMessage(event.content, event.id, event.attachments);
|
|
7081
7120
|
break;
|
|
7082
7121
|
}
|
|
@@ -8724,6 +8763,62 @@ async function commitToolBoundary(state, result) {
|
|
|
8724
8763
|
await state.local.commitExecutionBoundary(state);
|
|
8725
8764
|
}
|
|
8726
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
|
+
|
|
8727
8822
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
8728
8823
|
var logger11 = new Logger("ToolNode");
|
|
8729
8824
|
function isAbortSignal(value) {
|
|
@@ -8891,7 +8986,19 @@ var ToolNode = class {
|
|
|
8891
8986
|
});
|
|
8892
8987
|
throw result.error;
|
|
8893
8988
|
}
|
|
8894
|
-
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
|
+
}
|
|
8895
9002
|
if (Array.isArray(result.events) && result.events.length > 0) {
|
|
8896
9003
|
events.push(...result.events);
|
|
8897
9004
|
}
|
|
@@ -9649,7 +9756,8 @@ function parseEngineCheckpoint(value) {
|
|
|
9649
9756
|
"runtimeFailureFactSink",
|
|
9650
9757
|
"summarizationCallbacks",
|
|
9651
9758
|
"commitExecutionBoundary",
|
|
9652
|
-
"toolRecoveryPort"
|
|
9759
|
+
"toolRecoveryPort",
|
|
9760
|
+
"pendingUserInputPort"
|
|
9653
9761
|
]) {
|
|
9654
9762
|
if (result.local && Object.hasOwn(result.local, key)) {
|
|
9655
9763
|
throw new Error(`Checkpoint must not contain execution capability: ${key}`);
|