@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/cli.js
CHANGED
|
@@ -343,6 +343,10 @@ var UserInputMessage = BaseMessage.extend({
|
|
|
343
343
|
type: z.literal("user_input"),
|
|
344
344
|
attachments: RuntimeResourceRefs.optional()
|
|
345
345
|
});
|
|
346
|
+
var UserSteerMessage = BaseMessage.extend({
|
|
347
|
+
role: z.literal("user"),
|
|
348
|
+
type: z.literal("user_steer")
|
|
349
|
+
});
|
|
346
350
|
var UserContextMessage = BaseMessage.extend({
|
|
347
351
|
role: z.literal("user"),
|
|
348
352
|
// 产品上下文种类由 Host fence metadata 表达,不进入框架消息枚举。
|
|
@@ -351,7 +355,7 @@ var UserContextMessage = BaseMessage.extend({
|
|
|
351
355
|
"task_request"
|
|
352
356
|
])
|
|
353
357
|
});
|
|
354
|
-
var UserMessage = z.union([UserInputMessage, UserContextMessage]);
|
|
358
|
+
var UserMessage = z.union([UserInputMessage, UserSteerMessage, UserContextMessage]);
|
|
355
359
|
var AssistantMessage = BaseMessage.extend({
|
|
356
360
|
role: z.literal("assistant"),
|
|
357
361
|
type: z.enum(["thought", "final_answer", "tool_code", "tool_calls", "task_completion"])
|
|
@@ -968,7 +972,12 @@ var RuntimeEventShape = z.discriminatedUnion("type", [
|
|
|
968
972
|
content: z.string(),
|
|
969
973
|
raw_content: z.string().optional(),
|
|
970
974
|
source: z.enum(["user", "editor", "system"]).default("user"),
|
|
971
|
-
attachments: RuntimeResourceRefs.optional()
|
|
975
|
+
attachments: RuntimeResourceRefs.optional(),
|
|
976
|
+
/**
|
|
977
|
+
* 运行中途送达的用户输入(插话)。缺省表示运行起点的输入。
|
|
978
|
+
* 上下文里投影为 `user_steer`,不改变“当前轮从哪条 user_input 开始”的判定。
|
|
979
|
+
*/
|
|
980
|
+
delivery: z.literal("mid_run").optional()
|
|
972
981
|
}),
|
|
973
982
|
BaseEvent.extend({
|
|
974
983
|
type: z.literal("thought"),
|
|
@@ -1415,6 +1424,11 @@ z.object({
|
|
|
1415
1424
|
run_id: RunIdSchema,
|
|
1416
1425
|
execution_id: ExecutionIdSchema
|
|
1417
1426
|
});
|
|
1427
|
+
var SSEUserInputEvent = BaseSSEEvent.extend({
|
|
1428
|
+
type: z.literal("user_input"),
|
|
1429
|
+
content: z.string(),
|
|
1430
|
+
delivery: z.literal("mid_run")
|
|
1431
|
+
});
|
|
1418
1432
|
var SSEThoughtEvent = BaseSSEEvent.extend({
|
|
1419
1433
|
type: z.literal("thought"),
|
|
1420
1434
|
thought_message_id: ThoughtMessageIdSchema.optional(),
|
|
@@ -1569,6 +1583,7 @@ var SSESummarizationErrorEvent = BaseSSEEvent.extend({
|
|
|
1569
1583
|
error: z.string()
|
|
1570
1584
|
});
|
|
1571
1585
|
z.discriminatedUnion("type", [
|
|
1586
|
+
SSEUserInputEvent,
|
|
1572
1587
|
SSEThoughtEvent,
|
|
1573
1588
|
SSEFinalAnswerChunkEvent,
|
|
1574
1589
|
SSEFinalAnswerResetEvent,
|
|
@@ -2539,6 +2554,7 @@ var NON_CHECKPOINT_LOCAL_KEYS = [
|
|
|
2539
2554
|
"runtimeEventCommitPort",
|
|
2540
2555
|
"commitExecutionBoundary",
|
|
2541
2556
|
"toolRecoveryPort",
|
|
2557
|
+
"pendingUserInputPort",
|
|
2542
2558
|
"runtimeFailureFactSink",
|
|
2543
2559
|
"signal",
|
|
2544
2560
|
"summarizationCallbacks",
|
|
@@ -3102,6 +3118,16 @@ function mergeResumeSessionLocal(persistedLocal, localPatch) {
|
|
|
3102
3118
|
}
|
|
3103
3119
|
};
|
|
3104
3120
|
}
|
|
3121
|
+
function resolveResumeNodeId(local, requested) {
|
|
3122
|
+
const pending = local?.pendingToolCalls;
|
|
3123
|
+
if (!Array.isArray(pending) || pending.length === 0) return requested ?? "llm";
|
|
3124
|
+
if (requested !== void 0 && requested !== "tool") {
|
|
3125
|
+
throw new Error(
|
|
3126
|
+
`Graph resume must first run ${pending.length} pending tool call(s) from the interrupted batch: requested node=${requested}`
|
|
3127
|
+
);
|
|
3128
|
+
}
|
|
3129
|
+
return "tool";
|
|
3130
|
+
}
|
|
3105
3131
|
var GraphExecutor = class {
|
|
3106
3132
|
constructor(checkpointer, config = {}) {
|
|
3107
3133
|
this.checkpointer = checkpointer;
|
|
@@ -3214,13 +3240,14 @@ var GraphExecutor = class {
|
|
|
3214
3240
|
);
|
|
3215
3241
|
}
|
|
3216
3242
|
const resumedLocal = mergeResumeSessionLocal(current.local, input.localPatch);
|
|
3243
|
+
const nodeId = resolveResumeNodeId(resumedLocal, input.nodeId);
|
|
3217
3244
|
if (this.executionCheckpointPort && current.local?.executorLocal) {
|
|
3218
3245
|
resumedLocal.executorLocal = { ...current.local.executorLocal };
|
|
3219
3246
|
}
|
|
3220
3247
|
this.ephemeralLocals.set(checkpointKey, resumedLocal);
|
|
3221
3248
|
await this.commitCheckpoint(checkpointKey, {
|
|
3222
3249
|
...current,
|
|
3223
|
-
nodeId
|
|
3250
|
+
nodeId,
|
|
3224
3251
|
...this.executionCheckpointPort ? { executionStatus: "ready" } : {},
|
|
3225
3252
|
revision: currentRevision + 1,
|
|
3226
3253
|
local: sanitizeCheckpointLocal(resumedLocal)
|
|
@@ -6520,6 +6547,8 @@ function describeRuntimeEventLifecycle(event) {
|
|
|
6520
6547
|
case "run_execution_metrics":
|
|
6521
6548
|
case "history_summary":
|
|
6522
6549
|
return "event_bus_sse";
|
|
6550
|
+
case "user_input":
|
|
6551
|
+
return event.type === "user_input" && event.delivery === "mid_run" ? "event_bus_sse" : "none";
|
|
6523
6552
|
case "audit_envelope":
|
|
6524
6553
|
return "none";
|
|
6525
6554
|
default:
|
|
@@ -6963,6 +6992,16 @@ function requireEventTimestamp(value) {
|
|
|
6963
6992
|
function applyRuntimeEventToMemory(event, memory) {
|
|
6964
6993
|
switch (event.type) {
|
|
6965
6994
|
case "user_input": {
|
|
6995
|
+
if (event.delivery === "mid_run") {
|
|
6996
|
+
memory.appendMessage({
|
|
6997
|
+
id: event.id,
|
|
6998
|
+
role: "user",
|
|
6999
|
+
type: "user_steer",
|
|
7000
|
+
content: event.content,
|
|
7001
|
+
timestamp: event.timestamp
|
|
7002
|
+
});
|
|
7003
|
+
break;
|
|
7004
|
+
}
|
|
6966
7005
|
memory.addUserMessage(event.content, event.id, event.attachments);
|
|
6967
7006
|
break;
|
|
6968
7007
|
}
|
|
@@ -8610,6 +8649,62 @@ async function commitToolBoundary(state, result) {
|
|
|
8610
8649
|
await state.local.commitExecutionBoundary(state);
|
|
8611
8650
|
}
|
|
8612
8651
|
|
|
8652
|
+
// src/runtime-kernel/graph-engine/nodes/toolNode.pendingUserInput.ts
|
|
8653
|
+
function isPendingUserInputPort(value) {
|
|
8654
|
+
return !!value && typeof value === "object" && typeof Reflect.get(value, "claim") === "function" && typeof Reflect.get(value, "confirm") === "function" && typeof Reflect.get(value, "release") === "function";
|
|
8655
|
+
}
|
|
8656
|
+
function readRemainingSteps(state) {
|
|
8657
|
+
const value = state.local?.executorLocal?.remainingSteps;
|
|
8658
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
8659
|
+
}
|
|
8660
|
+
function readIdentity(value, field) {
|
|
8661
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
8662
|
+
throw new Error(`ToolNode pending user input requires ${field}`);
|
|
8663
|
+
}
|
|
8664
|
+
return value;
|
|
8665
|
+
}
|
|
8666
|
+
async function claimPendingUserInputs(state, result) {
|
|
8667
|
+
if (result.kind !== "route" || result.nextNodeId !== "llm") return void 0;
|
|
8668
|
+
const local = state.local;
|
|
8669
|
+
const port = local?.pendingUserInputPort;
|
|
8670
|
+
if (!isPendingUserInputPort(port)) return void 0;
|
|
8671
|
+
const signal = local?.signal;
|
|
8672
|
+
if (signal?.aborted || isRunPauseSignal(signal)) return void 0;
|
|
8673
|
+
const remainingSteps = readRemainingSteps(state);
|
|
8674
|
+
if (remainingSteps !== void 0 && remainingSteps < 1) return void 0;
|
|
8675
|
+
const inputs = await port.claim();
|
|
8676
|
+
if (inputs.length === 0) return void 0;
|
|
8677
|
+
const ids = inputs.map((input) => input.id);
|
|
8678
|
+
try {
|
|
8679
|
+
const conversationId = readIdentity(local?.conversationId, "conversationId");
|
|
8680
|
+
const turnId = readIdentity(local?.turnId, "turnId");
|
|
8681
|
+
const sink = requireRuntimeEventSink(local);
|
|
8682
|
+
const events = inputs.map((input) => sink(
|
|
8683
|
+
createUserInputEvent(readIdentity(input.id, "input id"), conversationId, turnId, input.content, {
|
|
8684
|
+
timestamp: input.timestamp ?? Date.now(),
|
|
8685
|
+
delivery: "mid_run"
|
|
8686
|
+
}),
|
|
8687
|
+
"ToolNode.pending_user_input"
|
|
8688
|
+
));
|
|
8689
|
+
state.local = {
|
|
8690
|
+
...state.local,
|
|
8691
|
+
history: appendWorkingHistory(parseRuntimeEvents(state.local?.history ?? []), events)
|
|
8692
|
+
};
|
|
8693
|
+
return {
|
|
8694
|
+
events,
|
|
8695
|
+
confirm: async () => {
|
|
8696
|
+
await port.confirm(ids);
|
|
8697
|
+
},
|
|
8698
|
+
release: async () => {
|
|
8699
|
+
await port.release(ids);
|
|
8700
|
+
}
|
|
8701
|
+
};
|
|
8702
|
+
} catch (error) {
|
|
8703
|
+
await port.release(ids);
|
|
8704
|
+
throw error;
|
|
8705
|
+
}
|
|
8706
|
+
}
|
|
8707
|
+
|
|
8613
8708
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
8614
8709
|
var logger11 = new Logger("ToolNode");
|
|
8615
8710
|
function isAbortSignal(value) {
|
|
@@ -8777,7 +8872,19 @@ var ToolNode = class {
|
|
|
8777
8872
|
});
|
|
8778
8873
|
throw result.error;
|
|
8779
8874
|
}
|
|
8780
|
-
await
|
|
8875
|
+
const steering = await claimPendingUserInputs(state, result);
|
|
8876
|
+
if (steering) {
|
|
8877
|
+
result = { ...result, events: [...result.events ?? [], ...steering.events] };
|
|
8878
|
+
try {
|
|
8879
|
+
await commitToolBoundary(state, result);
|
|
8880
|
+
} catch (error) {
|
|
8881
|
+
await steering.release();
|
|
8882
|
+
throw error;
|
|
8883
|
+
}
|
|
8884
|
+
await steering.confirm();
|
|
8885
|
+
} else {
|
|
8886
|
+
await commitToolBoundary(state, result);
|
|
8887
|
+
}
|
|
8781
8888
|
if (Array.isArray(result.events) && result.events.length > 0) {
|
|
8782
8889
|
events.push(...result.events);
|
|
8783
8890
|
}
|
|
@@ -9535,7 +9642,8 @@ function parseEngineCheckpoint(value) {
|
|
|
9535
9642
|
"runtimeFailureFactSink",
|
|
9536
9643
|
"summarizationCallbacks",
|
|
9537
9644
|
"commitExecutionBoundary",
|
|
9538
|
-
"toolRecoveryPort"
|
|
9645
|
+
"toolRecoveryPort",
|
|
9646
|
+
"pendingUserInputPort"
|
|
9539
9647
|
]) {
|
|
9540
9648
|
if (result.local && Object.hasOwn(result.local, key)) {
|
|
9541
9649
|
throw new Error(`Checkpoint must not contain execution capability: ${key}`);
|