@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.cjs
CHANGED
|
@@ -311,6 +311,10 @@ var UserInputMessage = BaseMessage.extend({
|
|
|
311
311
|
type: zod.z.literal("user_input"),
|
|
312
312
|
attachments: RuntimeResourceRefs.optional()
|
|
313
313
|
});
|
|
314
|
+
var UserSteerMessage = BaseMessage.extend({
|
|
315
|
+
role: zod.z.literal("user"),
|
|
316
|
+
type: zod.z.literal("user_steer")
|
|
317
|
+
});
|
|
314
318
|
var UserContextMessage = BaseMessage.extend({
|
|
315
319
|
role: zod.z.literal("user"),
|
|
316
320
|
// 产品上下文种类由 Host fence metadata 表达,不进入框架消息枚举。
|
|
@@ -319,7 +323,7 @@ var UserContextMessage = BaseMessage.extend({
|
|
|
319
323
|
"task_request"
|
|
320
324
|
])
|
|
321
325
|
});
|
|
322
|
-
var UserMessage = zod.z.union([UserInputMessage, UserContextMessage]);
|
|
326
|
+
var UserMessage = zod.z.union([UserInputMessage, UserSteerMessage, UserContextMessage]);
|
|
323
327
|
var AssistantMessage = BaseMessage.extend({
|
|
324
328
|
role: zod.z.literal("assistant"),
|
|
325
329
|
type: zod.z.enum(["thought", "final_answer", "tool_code", "tool_calls", "task_completion"])
|
|
@@ -1036,7 +1040,12 @@ var RuntimeEventShape = zod.z.discriminatedUnion("type", [
|
|
|
1036
1040
|
content: zod.z.string(),
|
|
1037
1041
|
raw_content: zod.z.string().optional(),
|
|
1038
1042
|
source: zod.z.enum(["user", "editor", "system"]).default("user"),
|
|
1039
|
-
attachments: RuntimeResourceRefs.optional()
|
|
1043
|
+
attachments: RuntimeResourceRefs.optional(),
|
|
1044
|
+
/**
|
|
1045
|
+
* 运行中途送达的用户输入(插话)。缺省表示运行起点的输入。
|
|
1046
|
+
* 上下文里投影为 `user_steer`,不改变“当前轮从哪条 user_input 开始”的判定。
|
|
1047
|
+
*/
|
|
1048
|
+
delivery: zod.z.literal("mid_run").optional()
|
|
1040
1049
|
}),
|
|
1041
1050
|
BaseEvent.extend({
|
|
1042
1051
|
type: zod.z.literal("thought"),
|
|
@@ -1483,6 +1492,11 @@ zod.z.object({
|
|
|
1483
1492
|
run_id: RunIdSchema,
|
|
1484
1493
|
execution_id: ExecutionIdSchema
|
|
1485
1494
|
});
|
|
1495
|
+
var SSEUserInputEvent = BaseSSEEvent.extend({
|
|
1496
|
+
type: zod.z.literal("user_input"),
|
|
1497
|
+
content: zod.z.string(),
|
|
1498
|
+
delivery: zod.z.literal("mid_run")
|
|
1499
|
+
});
|
|
1486
1500
|
var SSEThoughtEvent = BaseSSEEvent.extend({
|
|
1487
1501
|
type: zod.z.literal("thought"),
|
|
1488
1502
|
thought_message_id: ThoughtMessageIdSchema.optional(),
|
|
@@ -1637,6 +1651,7 @@ var SSESummarizationErrorEvent = BaseSSEEvent.extend({
|
|
|
1637
1651
|
error: zod.z.string()
|
|
1638
1652
|
});
|
|
1639
1653
|
zod.z.discriminatedUnion("type", [
|
|
1654
|
+
SSEUserInputEvent,
|
|
1640
1655
|
SSEThoughtEvent,
|
|
1641
1656
|
SSEFinalAnswerChunkEvent,
|
|
1642
1657
|
SSEFinalAnswerResetEvent,
|
|
@@ -2655,6 +2670,7 @@ var NON_CHECKPOINT_LOCAL_KEYS = [
|
|
|
2655
2670
|
"runtimeEventCommitPort",
|
|
2656
2671
|
"commitExecutionBoundary",
|
|
2657
2672
|
"toolRecoveryPort",
|
|
2673
|
+
"pendingUserInputPort",
|
|
2658
2674
|
"runtimeFailureFactSink",
|
|
2659
2675
|
"signal",
|
|
2660
2676
|
"summarizationCallbacks",
|
|
@@ -3218,6 +3234,16 @@ function mergeResumeSessionLocal(persistedLocal, localPatch) {
|
|
|
3218
3234
|
}
|
|
3219
3235
|
};
|
|
3220
3236
|
}
|
|
3237
|
+
function resolveResumeNodeId(local, requested) {
|
|
3238
|
+
const pending = local?.pendingToolCalls;
|
|
3239
|
+
if (!Array.isArray(pending) || pending.length === 0) return requested ?? "llm";
|
|
3240
|
+
if (requested !== void 0 && requested !== "tool") {
|
|
3241
|
+
throw new Error(
|
|
3242
|
+
`Graph resume must first run ${pending.length} pending tool call(s) from the interrupted batch: requested node=${requested}`
|
|
3243
|
+
);
|
|
3244
|
+
}
|
|
3245
|
+
return "tool";
|
|
3246
|
+
}
|
|
3221
3247
|
var GraphExecutor = class {
|
|
3222
3248
|
constructor(checkpointer, config = {}) {
|
|
3223
3249
|
this.checkpointer = checkpointer;
|
|
@@ -3330,13 +3356,14 @@ var GraphExecutor = class {
|
|
|
3330
3356
|
);
|
|
3331
3357
|
}
|
|
3332
3358
|
const resumedLocal = mergeResumeSessionLocal(current.local, input.localPatch);
|
|
3359
|
+
const nodeId = resolveResumeNodeId(resumedLocal, input.nodeId);
|
|
3333
3360
|
if (this.executionCheckpointPort && current.local?.executorLocal) {
|
|
3334
3361
|
resumedLocal.executorLocal = { ...current.local.executorLocal };
|
|
3335
3362
|
}
|
|
3336
3363
|
this.ephemeralLocals.set(checkpointKey, resumedLocal);
|
|
3337
3364
|
await this.commitCheckpoint(checkpointKey, {
|
|
3338
3365
|
...current,
|
|
3339
|
-
nodeId
|
|
3366
|
+
nodeId,
|
|
3340
3367
|
...this.executionCheckpointPort ? { executionStatus: "ready" } : {},
|
|
3341
3368
|
revision: currentRevision + 1,
|
|
3342
3369
|
local: sanitizeCheckpointLocal(resumedLocal)
|
|
@@ -6636,6 +6663,8 @@ function describeRuntimeEventLifecycle(event) {
|
|
|
6636
6663
|
case "run_execution_metrics":
|
|
6637
6664
|
case "history_summary":
|
|
6638
6665
|
return "event_bus_sse";
|
|
6666
|
+
case "user_input":
|
|
6667
|
+
return event.type === "user_input" && event.delivery === "mid_run" ? "event_bus_sse" : "none";
|
|
6639
6668
|
case "audit_envelope":
|
|
6640
6669
|
return "none";
|
|
6641
6670
|
default:
|
|
@@ -7079,6 +7108,16 @@ function requireEventTimestamp(value) {
|
|
|
7079
7108
|
function applyRuntimeEventToMemory(event, memory) {
|
|
7080
7109
|
switch (event.type) {
|
|
7081
7110
|
case "user_input": {
|
|
7111
|
+
if (event.delivery === "mid_run") {
|
|
7112
|
+
memory.appendMessage({
|
|
7113
|
+
id: event.id,
|
|
7114
|
+
role: "user",
|
|
7115
|
+
type: "user_steer",
|
|
7116
|
+
content: event.content,
|
|
7117
|
+
timestamp: event.timestamp
|
|
7118
|
+
});
|
|
7119
|
+
break;
|
|
7120
|
+
}
|
|
7082
7121
|
memory.addUserMessage(event.content, event.id, event.attachments);
|
|
7083
7122
|
break;
|
|
7084
7123
|
}
|
|
@@ -8726,6 +8765,62 @@ async function commitToolBoundary(state, result) {
|
|
|
8726
8765
|
await state.local.commitExecutionBoundary(state);
|
|
8727
8766
|
}
|
|
8728
8767
|
|
|
8768
|
+
// src/runtime-kernel/graph-engine/nodes/toolNode.pendingUserInput.ts
|
|
8769
|
+
function isPendingUserInputPort(value) {
|
|
8770
|
+
return !!value && typeof value === "object" && typeof Reflect.get(value, "claim") === "function" && typeof Reflect.get(value, "confirm") === "function" && typeof Reflect.get(value, "release") === "function";
|
|
8771
|
+
}
|
|
8772
|
+
function readRemainingSteps(state) {
|
|
8773
|
+
const value = state.local?.executorLocal?.remainingSteps;
|
|
8774
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
8775
|
+
}
|
|
8776
|
+
function readIdentity(value, field) {
|
|
8777
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
8778
|
+
throw new Error(`ToolNode pending user input requires ${field}`);
|
|
8779
|
+
}
|
|
8780
|
+
return value;
|
|
8781
|
+
}
|
|
8782
|
+
async function claimPendingUserInputs(state, result) {
|
|
8783
|
+
if (result.kind !== "route" || result.nextNodeId !== "llm") return void 0;
|
|
8784
|
+
const local = state.local;
|
|
8785
|
+
const port = local?.pendingUserInputPort;
|
|
8786
|
+
if (!isPendingUserInputPort(port)) return void 0;
|
|
8787
|
+
const signal = local?.signal;
|
|
8788
|
+
if (signal?.aborted || isRunPauseSignal(signal)) return void 0;
|
|
8789
|
+
const remainingSteps = readRemainingSteps(state);
|
|
8790
|
+
if (remainingSteps !== void 0 && remainingSteps < 1) return void 0;
|
|
8791
|
+
const inputs = await port.claim();
|
|
8792
|
+
if (inputs.length === 0) return void 0;
|
|
8793
|
+
const ids = inputs.map((input) => input.id);
|
|
8794
|
+
try {
|
|
8795
|
+
const conversationId = readIdentity(local?.conversationId, "conversationId");
|
|
8796
|
+
const turnId = readIdentity(local?.turnId, "turnId");
|
|
8797
|
+
const sink = requireRuntimeEventSink(local);
|
|
8798
|
+
const events = inputs.map((input) => sink(
|
|
8799
|
+
createUserInputEvent(readIdentity(input.id, "input id"), conversationId, turnId, input.content, {
|
|
8800
|
+
timestamp: input.timestamp ?? Date.now(),
|
|
8801
|
+
delivery: "mid_run"
|
|
8802
|
+
}),
|
|
8803
|
+
"ToolNode.pending_user_input"
|
|
8804
|
+
));
|
|
8805
|
+
state.local = {
|
|
8806
|
+
...state.local,
|
|
8807
|
+
history: appendWorkingHistory(parseRuntimeEvents(state.local?.history ?? []), events)
|
|
8808
|
+
};
|
|
8809
|
+
return {
|
|
8810
|
+
events,
|
|
8811
|
+
confirm: async () => {
|
|
8812
|
+
await port.confirm(ids);
|
|
8813
|
+
},
|
|
8814
|
+
release: async () => {
|
|
8815
|
+
await port.release(ids);
|
|
8816
|
+
}
|
|
8817
|
+
};
|
|
8818
|
+
} catch (error) {
|
|
8819
|
+
await port.release(ids);
|
|
8820
|
+
throw error;
|
|
8821
|
+
}
|
|
8822
|
+
}
|
|
8823
|
+
|
|
8729
8824
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
8730
8825
|
var logger11 = new Logger("ToolNode");
|
|
8731
8826
|
function isAbortSignal(value) {
|
|
@@ -8893,7 +8988,19 @@ var ToolNode = class {
|
|
|
8893
8988
|
});
|
|
8894
8989
|
throw result.error;
|
|
8895
8990
|
}
|
|
8896
|
-
await
|
|
8991
|
+
const steering = await claimPendingUserInputs(state, result);
|
|
8992
|
+
if (steering) {
|
|
8993
|
+
result = { ...result, events: [...result.events ?? [], ...steering.events] };
|
|
8994
|
+
try {
|
|
8995
|
+
await commitToolBoundary(state, result);
|
|
8996
|
+
} catch (error) {
|
|
8997
|
+
await steering.release();
|
|
8998
|
+
throw error;
|
|
8999
|
+
}
|
|
9000
|
+
await steering.confirm();
|
|
9001
|
+
} else {
|
|
9002
|
+
await commitToolBoundary(state, result);
|
|
9003
|
+
}
|
|
8897
9004
|
if (Array.isArray(result.events) && result.events.length > 0) {
|
|
8898
9005
|
events.push(...result.events);
|
|
8899
9006
|
}
|
|
@@ -9651,7 +9758,8 @@ function parseEngineCheckpoint(value) {
|
|
|
9651
9758
|
"runtimeFailureFactSink",
|
|
9652
9759
|
"summarizationCallbacks",
|
|
9653
9760
|
"commitExecutionBoundary",
|
|
9654
|
-
"toolRecoveryPort"
|
|
9761
|
+
"toolRecoveryPort",
|
|
9762
|
+
"pendingUserInputPort"
|
|
9655
9763
|
]) {
|
|
9656
9764
|
if (result.local && Object.hasOwn(result.local, key)) {
|
|
9657
9765
|
throw new Error(`Checkpoint must not contain execution capability: ${key}`);
|