@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/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",
|
|
@@ -6531,6 +6547,8 @@ function describeRuntimeEventLifecycle(event) {
|
|
|
6531
6547
|
case "run_execution_metrics":
|
|
6532
6548
|
case "history_summary":
|
|
6533
6549
|
return "event_bus_sse";
|
|
6550
|
+
case "user_input":
|
|
6551
|
+
return event.type === "user_input" && event.delivery === "mid_run" ? "event_bus_sse" : "none";
|
|
6534
6552
|
case "audit_envelope":
|
|
6535
6553
|
return "none";
|
|
6536
6554
|
default:
|
|
@@ -6974,6 +6992,16 @@ function requireEventTimestamp(value) {
|
|
|
6974
6992
|
function applyRuntimeEventToMemory(event, memory) {
|
|
6975
6993
|
switch (event.type) {
|
|
6976
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
|
+
}
|
|
6977
7005
|
memory.addUserMessage(event.content, event.id, event.attachments);
|
|
6978
7006
|
break;
|
|
6979
7007
|
}
|
|
@@ -8621,6 +8649,62 @@ async function commitToolBoundary(state, result) {
|
|
|
8621
8649
|
await state.local.commitExecutionBoundary(state);
|
|
8622
8650
|
}
|
|
8623
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
|
+
|
|
8624
8708
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
8625
8709
|
var logger11 = new Logger("ToolNode");
|
|
8626
8710
|
function isAbortSignal(value) {
|
|
@@ -8788,7 +8872,19 @@ var ToolNode = class {
|
|
|
8788
8872
|
});
|
|
8789
8873
|
throw result.error;
|
|
8790
8874
|
}
|
|
8791
|
-
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
|
+
}
|
|
8792
8888
|
if (Array.isArray(result.events) && result.events.length > 0) {
|
|
8793
8889
|
events.push(...result.events);
|
|
8794
8890
|
}
|
|
@@ -9546,7 +9642,8 @@ function parseEngineCheckpoint(value) {
|
|
|
9546
9642
|
"runtimeFailureFactSink",
|
|
9547
9643
|
"summarizationCallbacks",
|
|
9548
9644
|
"commitExecutionBoundary",
|
|
9549
|
-
"toolRecoveryPort"
|
|
9645
|
+
"toolRecoveryPort",
|
|
9646
|
+
"pendingUserInputPort"
|
|
9550
9647
|
]) {
|
|
9551
9648
|
if (result.local && Object.hasOwn(result.local, key)) {
|
|
9552
9649
|
throw new Error(`Checkpoint must not contain execution capability: ${key}`);
|