@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/index.js
CHANGED
|
@@ -954,6 +954,7 @@ __export(contracts_exports, {
|
|
|
954
954
|
SSEToolProcessEvent: () => SSEToolProcessEvent,
|
|
955
955
|
SSETransportEndEvent: () => SSETransportEndEvent,
|
|
956
956
|
SSETransportErrorEvent: () => SSETransportErrorEvent,
|
|
957
|
+
SSEUserInputEvent: () => SSEUserInputEvent,
|
|
957
958
|
SYSTEM_REMINDER_BUILTIN_TRIGGER_KINDS: () => SYSTEM_REMINDER_BUILTIN_TRIGGER_KINDS,
|
|
958
959
|
SerializableJsonRecord: () => SerializableJsonRecord,
|
|
959
960
|
SerializableJsonValue: () => SerializableJsonValue,
|
|
@@ -1273,6 +1274,10 @@ var UserInputMessage = BaseMessage.extend({
|
|
|
1273
1274
|
type: z.literal("user_input"),
|
|
1274
1275
|
attachments: RuntimeResourceRefs.optional()
|
|
1275
1276
|
});
|
|
1277
|
+
var UserSteerMessage = BaseMessage.extend({
|
|
1278
|
+
role: z.literal("user"),
|
|
1279
|
+
type: z.literal("user_steer")
|
|
1280
|
+
});
|
|
1276
1281
|
var UserContextMessage = BaseMessage.extend({
|
|
1277
1282
|
role: z.literal("user"),
|
|
1278
1283
|
// 产品上下文种类由 Host fence metadata 表达,不进入框架消息枚举。
|
|
@@ -1281,7 +1286,7 @@ var UserContextMessage = BaseMessage.extend({
|
|
|
1281
1286
|
"task_request"
|
|
1282
1287
|
])
|
|
1283
1288
|
});
|
|
1284
|
-
var UserMessage = z.union([UserInputMessage, UserContextMessage]);
|
|
1289
|
+
var UserMessage = z.union([UserInputMessage, UserSteerMessage, UserContextMessage]);
|
|
1285
1290
|
var AssistantMessage = BaseMessage.extend({
|
|
1286
1291
|
role: z.literal("assistant"),
|
|
1287
1292
|
type: z.enum(["thought", "final_answer", "tool_code", "tool_calls", "task_completion"])
|
|
@@ -2096,7 +2101,12 @@ var RuntimeEventShape = z.discriminatedUnion("type", [
|
|
|
2096
2101
|
content: z.string(),
|
|
2097
2102
|
raw_content: z.string().optional(),
|
|
2098
2103
|
source: z.enum(["user", "editor", "system"]).default("user"),
|
|
2099
|
-
attachments: RuntimeResourceRefs.optional()
|
|
2104
|
+
attachments: RuntimeResourceRefs.optional(),
|
|
2105
|
+
/**
|
|
2106
|
+
* 运行中途送达的用户输入(插话)。缺省表示运行起点的输入。
|
|
2107
|
+
* 上下文里投影为 `user_steer`,不改变“当前轮从哪条 user_input 开始”的判定。
|
|
2108
|
+
*/
|
|
2109
|
+
delivery: z.literal("mid_run").optional()
|
|
2100
2110
|
}),
|
|
2101
2111
|
BaseEvent.extend({
|
|
2102
2112
|
type: z.literal("thought"),
|
|
@@ -2587,6 +2597,11 @@ function parseSSEExecutionScope(event) {
|
|
|
2587
2597
|
execution_id: event.execution_id
|
|
2588
2598
|
});
|
|
2589
2599
|
}
|
|
2600
|
+
var SSEUserInputEvent = BaseSSEEvent.extend({
|
|
2601
|
+
type: z.literal("user_input"),
|
|
2602
|
+
content: z.string(),
|
|
2603
|
+
delivery: z.literal("mid_run")
|
|
2604
|
+
});
|
|
2590
2605
|
var SSEThoughtEvent = BaseSSEEvent.extend({
|
|
2591
2606
|
type: z.literal("thought"),
|
|
2592
2607
|
thought_message_id: ThoughtMessageIdSchema.optional(),
|
|
@@ -2741,6 +2756,7 @@ var SSESummarizationErrorEvent = BaseSSEEvent.extend({
|
|
|
2741
2756
|
error: z.string()
|
|
2742
2757
|
});
|
|
2743
2758
|
var SSEEvent = z.discriminatedUnion("type", [
|
|
2759
|
+
SSEUserInputEvent,
|
|
2744
2760
|
SSEThoughtEvent,
|
|
2745
2761
|
SSEFinalAnswerChunkEvent,
|
|
2746
2762
|
SSEFinalAnswerResetEvent,
|
|
@@ -2812,6 +2828,7 @@ function runtimeEventToSSEEvent(event) {
|
|
|
2812
2828
|
const base = toBaseSSEEvent(event);
|
|
2813
2829
|
switch (event.type) {
|
|
2814
2830
|
case "user_input":
|
|
2831
|
+
return event.delivery === "mid_run" ? { ...base, type: "user_input", content: event.raw_content ?? event.content, delivery: "mid_run" } : null;
|
|
2815
2832
|
case "audit_envelope":
|
|
2816
2833
|
case "control":
|
|
2817
2834
|
return null;
|
|
@@ -3459,6 +3476,7 @@ var NON_CHECKPOINT_LOCAL_KEYS = [
|
|
|
3459
3476
|
"runtimeEventCommitPort",
|
|
3460
3477
|
"commitExecutionBoundary",
|
|
3461
3478
|
"toolRecoveryPort",
|
|
3479
|
+
"pendingUserInputPort",
|
|
3462
3480
|
"runtimeFailureFactSink",
|
|
3463
3481
|
"signal",
|
|
3464
3482
|
"summarizationCallbacks",
|
|
@@ -7679,6 +7697,8 @@ function describeRuntimeEventLifecycle(event) {
|
|
|
7679
7697
|
case "run_execution_metrics":
|
|
7680
7698
|
case "history_summary":
|
|
7681
7699
|
return "event_bus_sse";
|
|
7700
|
+
case "user_input":
|
|
7701
|
+
return event.type === "user_input" && event.delivery === "mid_run" ? "event_bus_sse" : "none";
|
|
7682
7702
|
case "audit_envelope":
|
|
7683
7703
|
return "none";
|
|
7684
7704
|
default:
|
|
@@ -8122,6 +8142,16 @@ function requireEventTimestamp(value) {
|
|
|
8122
8142
|
function applyRuntimeEventToMemory(event, memory) {
|
|
8123
8143
|
switch (event.type) {
|
|
8124
8144
|
case "user_input": {
|
|
8145
|
+
if (event.delivery === "mid_run") {
|
|
8146
|
+
memory.appendMessage({
|
|
8147
|
+
id: event.id,
|
|
8148
|
+
role: "user",
|
|
8149
|
+
type: "user_steer",
|
|
8150
|
+
content: event.content,
|
|
8151
|
+
timestamp: event.timestamp
|
|
8152
|
+
});
|
|
8153
|
+
break;
|
|
8154
|
+
}
|
|
8125
8155
|
memory.addUserMessage(event.content, event.id, event.attachments);
|
|
8126
8156
|
break;
|
|
8127
8157
|
}
|
|
@@ -9836,6 +9866,62 @@ async function commitToolBoundary(state, result) {
|
|
|
9836
9866
|
await state.local.commitExecutionBoundary(state);
|
|
9837
9867
|
}
|
|
9838
9868
|
|
|
9869
|
+
// src/runtime-kernel/graph-engine/nodes/toolNode.pendingUserInput.ts
|
|
9870
|
+
function isPendingUserInputPort(value) {
|
|
9871
|
+
return !!value && typeof value === "object" && typeof Reflect.get(value, "claim") === "function" && typeof Reflect.get(value, "confirm") === "function" && typeof Reflect.get(value, "release") === "function";
|
|
9872
|
+
}
|
|
9873
|
+
function readRemainingSteps(state) {
|
|
9874
|
+
const value = state.local?.executorLocal?.remainingSteps;
|
|
9875
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
9876
|
+
}
|
|
9877
|
+
function readIdentity(value, field) {
|
|
9878
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
9879
|
+
throw new Error(`ToolNode pending user input requires ${field}`);
|
|
9880
|
+
}
|
|
9881
|
+
return value;
|
|
9882
|
+
}
|
|
9883
|
+
async function claimPendingUserInputs(state, result) {
|
|
9884
|
+
if (result.kind !== "route" || result.nextNodeId !== "llm") return void 0;
|
|
9885
|
+
const local = state.local;
|
|
9886
|
+
const port = local?.pendingUserInputPort;
|
|
9887
|
+
if (!isPendingUserInputPort(port)) return void 0;
|
|
9888
|
+
const signal = local?.signal;
|
|
9889
|
+
if (signal?.aborted || isRunPauseSignal(signal)) return void 0;
|
|
9890
|
+
const remainingSteps = readRemainingSteps(state);
|
|
9891
|
+
if (remainingSteps !== void 0 && remainingSteps < 1) return void 0;
|
|
9892
|
+
const inputs = await port.claim();
|
|
9893
|
+
if (inputs.length === 0) return void 0;
|
|
9894
|
+
const ids = inputs.map((input) => input.id);
|
|
9895
|
+
try {
|
|
9896
|
+
const conversationId = readIdentity(local?.conversationId, "conversationId");
|
|
9897
|
+
const turnId = readIdentity(local?.turnId, "turnId");
|
|
9898
|
+
const sink = requireRuntimeEventSink(local);
|
|
9899
|
+
const events = inputs.map((input) => sink(
|
|
9900
|
+
createUserInputEvent(readIdentity(input.id, "input id"), conversationId, turnId, input.content, {
|
|
9901
|
+
timestamp: input.timestamp ?? Date.now(),
|
|
9902
|
+
delivery: "mid_run"
|
|
9903
|
+
}),
|
|
9904
|
+
"ToolNode.pending_user_input"
|
|
9905
|
+
));
|
|
9906
|
+
state.local = {
|
|
9907
|
+
...state.local,
|
|
9908
|
+
history: appendWorkingHistory(parseRuntimeEvents(state.local?.history ?? []), events)
|
|
9909
|
+
};
|
|
9910
|
+
return {
|
|
9911
|
+
events,
|
|
9912
|
+
confirm: async () => {
|
|
9913
|
+
await port.confirm(ids);
|
|
9914
|
+
},
|
|
9915
|
+
release: async () => {
|
|
9916
|
+
await port.release(ids);
|
|
9917
|
+
}
|
|
9918
|
+
};
|
|
9919
|
+
} catch (error) {
|
|
9920
|
+
await port.release(ids);
|
|
9921
|
+
throw error;
|
|
9922
|
+
}
|
|
9923
|
+
}
|
|
9924
|
+
|
|
9839
9925
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
9840
9926
|
var logger11 = new Logger("ToolNode");
|
|
9841
9927
|
function isAbortSignal(value) {
|
|
@@ -10003,7 +10089,19 @@ var ToolNode = class {
|
|
|
10003
10089
|
});
|
|
10004
10090
|
throw result.error;
|
|
10005
10091
|
}
|
|
10006
|
-
await
|
|
10092
|
+
const steering = await claimPendingUserInputs(state, result);
|
|
10093
|
+
if (steering) {
|
|
10094
|
+
result = { ...result, events: [...result.events ?? [], ...steering.events] };
|
|
10095
|
+
try {
|
|
10096
|
+
await commitToolBoundary(state, result);
|
|
10097
|
+
} catch (error) {
|
|
10098
|
+
await steering.release();
|
|
10099
|
+
throw error;
|
|
10100
|
+
}
|
|
10101
|
+
await steering.confirm();
|
|
10102
|
+
} else {
|
|
10103
|
+
await commitToolBoundary(state, result);
|
|
10104
|
+
}
|
|
10007
10105
|
if (Array.isArray(result.events) && result.events.length > 0) {
|
|
10008
10106
|
events.push(...result.events);
|
|
10009
10107
|
}
|
|
@@ -10761,7 +10859,8 @@ function parseEngineCheckpoint(value) {
|
|
|
10761
10859
|
"runtimeFailureFactSink",
|
|
10762
10860
|
"summarizationCallbacks",
|
|
10763
10861
|
"commitExecutionBoundary",
|
|
10764
|
-
"toolRecoveryPort"
|
|
10862
|
+
"toolRecoveryPort",
|
|
10863
|
+
"pendingUserInputPort"
|
|
10765
10864
|
]) {
|
|
10766
10865
|
if (result.local && Object.hasOwn(result.local, key)) {
|
|
10767
10866
|
throw new Error(`Checkpoint must not contain execution capability: ${key}`);
|