@linnlabs/linnkit 0.43.0 → 0.45.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 +61 -0
- package/dist/cli.cjs +152 -6
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +152 -6
- 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 +154 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +154 -6
- package/dist/index.js.map +1 -1
- package/dist/quickstart.cjs +152 -6
- package/dist/quickstart.cjs.map +1 -1
- package/dist/quickstart.js +152 -6
- 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/nodes/toolNode.d.cts +3 -0
- package/dist/runtime-kernel/graph-engine/nodes/toolNode.d.ts +3 -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 +152 -6
- 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 +152 -6
- 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 +722 -19
- 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 +714 -20
- 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/run-supervisor.md +1 -0
- package/docs/integration/testing.md +40 -4
- 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",
|
|
@@ -6645,6 +6661,8 @@ function describeRuntimeEventLifecycle(event) {
|
|
|
6645
6661
|
case "run_execution_metrics":
|
|
6646
6662
|
case "history_summary":
|
|
6647
6663
|
return "event_bus_sse";
|
|
6664
|
+
case "user_input":
|
|
6665
|
+
return event.type === "user_input" && event.delivery === "mid_run" ? "event_bus_sse" : "none";
|
|
6648
6666
|
case "audit_envelope":
|
|
6649
6667
|
return "none";
|
|
6650
6668
|
default:
|
|
@@ -7088,6 +7106,16 @@ function requireEventTimestamp(value) {
|
|
|
7088
7106
|
function applyRuntimeEventToMemory(event, memory) {
|
|
7089
7107
|
switch (event.type) {
|
|
7090
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
|
+
}
|
|
7091
7119
|
memory.addUserMessage(event.content, event.id, event.attachments);
|
|
7092
7120
|
break;
|
|
7093
7121
|
}
|
|
@@ -8704,9 +8732,49 @@ function recordToolProtocolError(params) {
|
|
|
8704
8732
|
}
|
|
8705
8733
|
|
|
8706
8734
|
// src/runtime-kernel/graph-engine/nodes/toolNode.recovery.ts
|
|
8735
|
+
var DEFAULT_TOOL_ABORT_GRACE_MS = 3e3;
|
|
8736
|
+
function settleToolWithinAbortGrace(input) {
|
|
8737
|
+
const { execution, signal, graceMs } = input;
|
|
8738
|
+
if (!signal) return execution;
|
|
8739
|
+
return new Promise((resolve, reject) => {
|
|
8740
|
+
let timer;
|
|
8741
|
+
const cleanup = () => {
|
|
8742
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
8743
|
+
signal.removeEventListener("abort", startGrace);
|
|
8744
|
+
};
|
|
8745
|
+
function startGrace() {
|
|
8746
|
+
timer = setTimeout(() => {
|
|
8747
|
+
cleanup();
|
|
8748
|
+
execution.catch(() => void 0);
|
|
8749
|
+
input.onAbandon?.();
|
|
8750
|
+
const error = new Error("Tool did not stop within the abort grace period; its late outcome is discarded.");
|
|
8751
|
+
error.name = "AbortError";
|
|
8752
|
+
reject(error);
|
|
8753
|
+
}, graceMs);
|
|
8754
|
+
}
|
|
8755
|
+
if (signal.aborted) startGrace();
|
|
8756
|
+
else signal.addEventListener("abort", startGrace, { once: true });
|
|
8757
|
+
execution.then(
|
|
8758
|
+
(value) => {
|
|
8759
|
+
cleanup();
|
|
8760
|
+
resolve(value);
|
|
8761
|
+
},
|
|
8762
|
+
(error) => {
|
|
8763
|
+
cleanup();
|
|
8764
|
+
reject(error);
|
|
8765
|
+
}
|
|
8766
|
+
);
|
|
8767
|
+
});
|
|
8768
|
+
}
|
|
8707
8769
|
async function executeRecoverableTool(input) {
|
|
8708
8770
|
const local = input.state.local;
|
|
8709
|
-
|
|
8771
|
+
const run = () => settleToolWithinAbortGrace({
|
|
8772
|
+
execution: input.execute(),
|
|
8773
|
+
signal: local?.signal,
|
|
8774
|
+
graceMs: input.abortGraceMs ?? DEFAULT_TOOL_ABORT_GRACE_MS,
|
|
8775
|
+
onAbandon: input.onAbandon
|
|
8776
|
+
});
|
|
8777
|
+
if (!local?.commitExecutionBoundary) return run();
|
|
8710
8778
|
if (local.executingToolCallId) {
|
|
8711
8779
|
if (local.executingToolCallId !== input.call.id) {
|
|
8712
8780
|
throw new RunRecoveryBlockedError("Pending tool identity does not match execution intent");
|
|
@@ -8719,7 +8787,7 @@ async function executeRecoverableTool(input) {
|
|
|
8719
8787
|
}
|
|
8720
8788
|
local.executingToolCallId = input.call.id;
|
|
8721
8789
|
await local.commitExecutionBoundary(input.state);
|
|
8722
|
-
const result = await
|
|
8790
|
+
const result = await run();
|
|
8723
8791
|
if (!result.success && isRunPauseSignal(local.signal)) {
|
|
8724
8792
|
const error = new Error("Tool execution paused before its outcome was confirmed");
|
|
8725
8793
|
error.name = "AbortError";
|
|
@@ -8735,6 +8803,62 @@ async function commitToolBoundary(state, result) {
|
|
|
8735
8803
|
await state.local.commitExecutionBoundary(state);
|
|
8736
8804
|
}
|
|
8737
8805
|
|
|
8806
|
+
// src/runtime-kernel/graph-engine/nodes/toolNode.pendingUserInput.ts
|
|
8807
|
+
function isPendingUserInputPort(value) {
|
|
8808
|
+
return !!value && typeof value === "object" && typeof Reflect.get(value, "claim") === "function" && typeof Reflect.get(value, "confirm") === "function" && typeof Reflect.get(value, "release") === "function";
|
|
8809
|
+
}
|
|
8810
|
+
function readRemainingSteps(state) {
|
|
8811
|
+
const value = state.local?.executorLocal?.remainingSteps;
|
|
8812
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
8813
|
+
}
|
|
8814
|
+
function readIdentity(value, field) {
|
|
8815
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
8816
|
+
throw new Error(`ToolNode pending user input requires ${field}`);
|
|
8817
|
+
}
|
|
8818
|
+
return value;
|
|
8819
|
+
}
|
|
8820
|
+
async function claimPendingUserInputs(state, result) {
|
|
8821
|
+
if (result.kind !== "route" || result.nextNodeId !== "llm") return void 0;
|
|
8822
|
+
const local = state.local;
|
|
8823
|
+
const port = local?.pendingUserInputPort;
|
|
8824
|
+
if (!isPendingUserInputPort(port)) return void 0;
|
|
8825
|
+
const signal = local?.signal;
|
|
8826
|
+
if (signal?.aborted || isRunPauseSignal(signal)) return void 0;
|
|
8827
|
+
const remainingSteps = readRemainingSteps(state);
|
|
8828
|
+
if (remainingSteps !== void 0 && remainingSteps < 1) return void 0;
|
|
8829
|
+
const inputs = await port.claim();
|
|
8830
|
+
if (inputs.length === 0) return void 0;
|
|
8831
|
+
const ids = inputs.map((input) => input.id);
|
|
8832
|
+
try {
|
|
8833
|
+
const conversationId = readIdentity(local?.conversationId, "conversationId");
|
|
8834
|
+
const turnId = readIdentity(local?.turnId, "turnId");
|
|
8835
|
+
const sink = requireRuntimeEventSink(local);
|
|
8836
|
+
const events = inputs.map((input) => sink(
|
|
8837
|
+
createUserInputEvent(readIdentity(input.id, "input id"), conversationId, turnId, input.content, {
|
|
8838
|
+
timestamp: input.timestamp ?? Date.now(),
|
|
8839
|
+
delivery: "mid_run"
|
|
8840
|
+
}),
|
|
8841
|
+
"ToolNode.pending_user_input"
|
|
8842
|
+
));
|
|
8843
|
+
state.local = {
|
|
8844
|
+
...state.local,
|
|
8845
|
+
history: appendWorkingHistory(parseRuntimeEvents(state.local?.history ?? []), events)
|
|
8846
|
+
};
|
|
8847
|
+
return {
|
|
8848
|
+
events,
|
|
8849
|
+
confirm: async () => {
|
|
8850
|
+
await port.confirm(ids);
|
|
8851
|
+
},
|
|
8852
|
+
release: async () => {
|
|
8853
|
+
await port.release(ids);
|
|
8854
|
+
}
|
|
8855
|
+
};
|
|
8856
|
+
} catch (error) {
|
|
8857
|
+
await port.release(ids);
|
|
8858
|
+
throw error;
|
|
8859
|
+
}
|
|
8860
|
+
}
|
|
8861
|
+
|
|
8738
8862
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
8739
8863
|
var logger11 = new Logger("ToolNode");
|
|
8740
8864
|
function isAbortSignal(value) {
|
|
@@ -8783,7 +8907,9 @@ var ToolNode = class {
|
|
|
8783
8907
|
auditPort;
|
|
8784
8908
|
modelInputResolver;
|
|
8785
8909
|
idempotencyInFlight = /* @__PURE__ */ new Map();
|
|
8910
|
+
abortGraceMs;
|
|
8786
8911
|
constructor(dependencies) {
|
|
8912
|
+
this.abortGraceMs = dependencies.abortGraceMs;
|
|
8787
8913
|
this.toolRuntime = dependencies.toolRuntime;
|
|
8788
8914
|
this.observationPreview = dependencies.observationPreview;
|
|
8789
8915
|
this.telemetryPort = dependencies.telemetryPort ?? noopTelemetry;
|
|
@@ -8902,7 +9028,19 @@ var ToolNode = class {
|
|
|
8902
9028
|
});
|
|
8903
9029
|
throw result.error;
|
|
8904
9030
|
}
|
|
8905
|
-
await
|
|
9031
|
+
const steering = await claimPendingUserInputs(state, result);
|
|
9032
|
+
if (steering) {
|
|
9033
|
+
result = { ...result, events: [...result.events ?? [], ...steering.events] };
|
|
9034
|
+
try {
|
|
9035
|
+
await commitToolBoundary(state, result);
|
|
9036
|
+
} catch (error) {
|
|
9037
|
+
await steering.release();
|
|
9038
|
+
throw error;
|
|
9039
|
+
}
|
|
9040
|
+
await steering.confirm();
|
|
9041
|
+
} else {
|
|
9042
|
+
await commitToolBoundary(state, result);
|
|
9043
|
+
}
|
|
8906
9044
|
if (Array.isArray(result.events) && result.events.length > 0) {
|
|
8907
9045
|
events.push(...result.events);
|
|
8908
9046
|
}
|
|
@@ -8989,6 +9127,13 @@ var ToolNode = class {
|
|
|
8989
9127
|
state,
|
|
8990
9128
|
call,
|
|
8991
9129
|
context: prepared.toolContext,
|
|
9130
|
+
abortGraceMs: this.abortGraceMs,
|
|
9131
|
+
onAbandon: () => logger11.warn("[ToolNode] \u5DE5\u5177\u672A\u5728\u505C\u6B62\u671F\u9650\u5185\u7ED3\u675F\uFF0C\u6309\u4E2D\u65AD\u5904\u7406\u5E76\u4E22\u5F03\u8FDF\u5230\u7ED3\u679C", {
|
|
9132
|
+
toolName: execution.toolName,
|
|
9133
|
+
toolCallId: execution.toolCallId,
|
|
9134
|
+
conversationId: prepared.conversationId,
|
|
9135
|
+
turnId: prepared.turnId
|
|
9136
|
+
}),
|
|
8992
9137
|
execute: () => executeToolWithIdempotency({
|
|
8993
9138
|
idempotencyKey: execution.idempotencyKey,
|
|
8994
9139
|
inFlight: this.idempotencyInFlight,
|
|
@@ -9660,7 +9805,8 @@ function parseEngineCheckpoint(value) {
|
|
|
9660
9805
|
"runtimeFailureFactSink",
|
|
9661
9806
|
"summarizationCallbacks",
|
|
9662
9807
|
"commitExecutionBoundary",
|
|
9663
|
-
"toolRecoveryPort"
|
|
9808
|
+
"toolRecoveryPort",
|
|
9809
|
+
"pendingUserInputPort"
|
|
9664
9810
|
]) {
|
|
9665
9811
|
if (result.local && Object.hasOwn(result.local, key)) {
|
|
9666
9812
|
throw new Error(`Checkpoint must not contain execution capability: ${key}`);
|