@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.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",
|
|
@@ -6647,6 +6663,8 @@ function describeRuntimeEventLifecycle(event) {
|
|
|
6647
6663
|
case "run_execution_metrics":
|
|
6648
6664
|
case "history_summary":
|
|
6649
6665
|
return "event_bus_sse";
|
|
6666
|
+
case "user_input":
|
|
6667
|
+
return event.type === "user_input" && event.delivery === "mid_run" ? "event_bus_sse" : "none";
|
|
6650
6668
|
case "audit_envelope":
|
|
6651
6669
|
return "none";
|
|
6652
6670
|
default:
|
|
@@ -7090,6 +7108,16 @@ function requireEventTimestamp(value) {
|
|
|
7090
7108
|
function applyRuntimeEventToMemory(event, memory) {
|
|
7091
7109
|
switch (event.type) {
|
|
7092
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
|
+
}
|
|
7093
7121
|
memory.addUserMessage(event.content, event.id, event.attachments);
|
|
7094
7122
|
break;
|
|
7095
7123
|
}
|
|
@@ -8737,6 +8765,62 @@ async function commitToolBoundary(state, result) {
|
|
|
8737
8765
|
await state.local.commitExecutionBoundary(state);
|
|
8738
8766
|
}
|
|
8739
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
|
+
|
|
8740
8824
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
8741
8825
|
var logger11 = new Logger("ToolNode");
|
|
8742
8826
|
function isAbortSignal(value) {
|
|
@@ -8904,7 +8988,19 @@ var ToolNode = class {
|
|
|
8904
8988
|
});
|
|
8905
8989
|
throw result.error;
|
|
8906
8990
|
}
|
|
8907
|
-
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
|
+
}
|
|
8908
9004
|
if (Array.isArray(result.events) && result.events.length > 0) {
|
|
8909
9005
|
events.push(...result.events);
|
|
8910
9006
|
}
|
|
@@ -9662,7 +9758,8 @@ function parseEngineCheckpoint(value) {
|
|
|
9662
9758
|
"runtimeFailureFactSink",
|
|
9663
9759
|
"summarizationCallbacks",
|
|
9664
9760
|
"commitExecutionBoundary",
|
|
9665
|
-
"toolRecoveryPort"
|
|
9761
|
+
"toolRecoveryPort",
|
|
9762
|
+
"pendingUserInputPort"
|
|
9666
9763
|
]) {
|
|
9667
9764
|
if (result.local && Object.hasOwn(result.local, key)) {
|
|
9668
9765
|
throw new Error(`Checkpoint must not contain execution capability: ${key}`);
|