@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/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,50 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
|
|
15
|
+
## [0.44.0] - 2026-11-18
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
- Mid-run user input. A Host can give the Graph an optional
|
|
20
|
+
`pendingUserInputPort` (`PendingUserInput` / `PendingUserInputPort` in the
|
|
21
|
+
graph exports). After a tool batch settles and before the run returns to the
|
|
22
|
+
model, `ToolNode` claims the pending inputs, publishes each as a `user_input`
|
|
23
|
+
fact with `delivery: 'mid_run'` after all the batch's tool outputs, and
|
|
24
|
+
commits them with the same tool boundary. It confirms after the commit and
|
|
25
|
+
releases them back to the Host if the commit fails. Nothing is claimed when
|
|
26
|
+
the batch does not return to the model, when a pause or cancel signal has
|
|
27
|
+
arrived, or when no step is left for another model call. Child runs should
|
|
28
|
+
not receive the port. Hosts without the port behave as before.
|
|
29
|
+
- `user_input.delivery` (optional, `'mid_run'`) and the `AiMessage` type
|
|
30
|
+
`user_steer`. A mid-run input enters the context as `user_steer` and is sent
|
|
31
|
+
to the model as an ordinary user message. The start of the current turn is
|
|
32
|
+
still the run's starting `user_input`, so current-turn fence assembly and
|
|
33
|
+
cleanup, tool history grouping and working-memory protection are unchanged.
|
|
34
|
+
Steers in the current run are core context and are protected from
|
|
35
|
+
compaction; steers from earlier runs are treated as historical user text.
|
|
36
|
+
- `SSEUserInputEvent` in the `SSEEvent` union. A mid-run `user_input` goes to
|
|
37
|
+
the realtime channel (`shouldEmitRuntimeEventToSse` is true) and
|
|
38
|
+
`runtimeEventToSSEEvent` projects it with the user's text and
|
|
39
|
+
`delivery: 'mid_run'`, so clients learn where a steer was delivered while
|
|
40
|
+
the run is still going. Starting inputs are still not sent back. Clients
|
|
41
|
+
that switch exhaustively over `SSEEvent['type']` need a `user_input` case.
|
|
42
|
+
- testkit: `createGraphScenario` runs the real Graph in memory (LlmNode,
|
|
43
|
+
ToolNode, WaitUserNode, the event bus, the persistence queue and a JSON
|
|
44
|
+
round-trip of every checkpoint) with a scripted model, scripted tools and an
|
|
45
|
+
in-memory steering queue. A scenario can start several runs in one
|
|
46
|
+
conversation, steer, pause, continue or cancel at any point, and returns the
|
|
47
|
+
run status instead of throwing. Supporting exports:
|
|
48
|
+
`createScriptedToolRuntime`, `createPendingUserInputQueue`,
|
|
49
|
+
`createRuntimeEventRecorder`, `formatRuntimeTimeline`,
|
|
50
|
+
`formatModelMessages`, `userInputText`, and the steering invariants
|
|
51
|
+
`validateSteeringInvariants` / `assertSteeringInvariants` (S1–S5).
|
|
52
|
+
- testkit: `createScriptedInferenceHarness` also accepts a function that
|
|
53
|
+
chooses each turn from the request, awaits an async `assertCall`, exposes
|
|
54
|
+
`getInferencePort()`, and lets a scripted tool call omit `id` (generated per
|
|
55
|
+
call) and pass `arguments` as an object instead of `argumentsJson`.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
15
59
|
## [0.43.0] - 2026-11-12
|
|
16
60
|
|
|
17
61
|
### Fixed
|
package/dist/cli.cjs
CHANGED
|
@@ -346,6 +346,10 @@ var UserInputMessage = BaseMessage.extend({
|
|
|
346
346
|
type: zod.z.literal("user_input"),
|
|
347
347
|
attachments: RuntimeResourceRefs.optional()
|
|
348
348
|
});
|
|
349
|
+
var UserSteerMessage = BaseMessage.extend({
|
|
350
|
+
role: zod.z.literal("user"),
|
|
351
|
+
type: zod.z.literal("user_steer")
|
|
352
|
+
});
|
|
349
353
|
var UserContextMessage = BaseMessage.extend({
|
|
350
354
|
role: zod.z.literal("user"),
|
|
351
355
|
// 产品上下文种类由 Host fence metadata 表达,不进入框架消息枚举。
|
|
@@ -354,7 +358,7 @@ var UserContextMessage = BaseMessage.extend({
|
|
|
354
358
|
"task_request"
|
|
355
359
|
])
|
|
356
360
|
});
|
|
357
|
-
var UserMessage = zod.z.union([UserInputMessage, UserContextMessage]);
|
|
361
|
+
var UserMessage = zod.z.union([UserInputMessage, UserSteerMessage, UserContextMessage]);
|
|
358
362
|
var AssistantMessage = BaseMessage.extend({
|
|
359
363
|
role: zod.z.literal("assistant"),
|
|
360
364
|
type: zod.z.enum(["thought", "final_answer", "tool_code", "tool_calls", "task_completion"])
|
|
@@ -971,7 +975,12 @@ var RuntimeEventShape = zod.z.discriminatedUnion("type", [
|
|
|
971
975
|
content: zod.z.string(),
|
|
972
976
|
raw_content: zod.z.string().optional(),
|
|
973
977
|
source: zod.z.enum(["user", "editor", "system"]).default("user"),
|
|
974
|
-
attachments: RuntimeResourceRefs.optional()
|
|
978
|
+
attachments: RuntimeResourceRefs.optional(),
|
|
979
|
+
/**
|
|
980
|
+
* 运行中途送达的用户输入(插话)。缺省表示运行起点的输入。
|
|
981
|
+
* 上下文里投影为 `user_steer`,不改变“当前轮从哪条 user_input 开始”的判定。
|
|
982
|
+
*/
|
|
983
|
+
delivery: zod.z.literal("mid_run").optional()
|
|
975
984
|
}),
|
|
976
985
|
BaseEvent.extend({
|
|
977
986
|
type: zod.z.literal("thought"),
|
|
@@ -1418,6 +1427,11 @@ zod.z.object({
|
|
|
1418
1427
|
run_id: RunIdSchema,
|
|
1419
1428
|
execution_id: ExecutionIdSchema
|
|
1420
1429
|
});
|
|
1430
|
+
var SSEUserInputEvent = BaseSSEEvent.extend({
|
|
1431
|
+
type: zod.z.literal("user_input"),
|
|
1432
|
+
content: zod.z.string(),
|
|
1433
|
+
delivery: zod.z.literal("mid_run")
|
|
1434
|
+
});
|
|
1421
1435
|
var SSEThoughtEvent = BaseSSEEvent.extend({
|
|
1422
1436
|
type: zod.z.literal("thought"),
|
|
1423
1437
|
thought_message_id: ThoughtMessageIdSchema.optional(),
|
|
@@ -1572,6 +1586,7 @@ var SSESummarizationErrorEvent = BaseSSEEvent.extend({
|
|
|
1572
1586
|
error: zod.z.string()
|
|
1573
1587
|
});
|
|
1574
1588
|
zod.z.discriminatedUnion("type", [
|
|
1589
|
+
SSEUserInputEvent,
|
|
1575
1590
|
SSEThoughtEvent,
|
|
1576
1591
|
SSEFinalAnswerChunkEvent,
|
|
1577
1592
|
SSEFinalAnswerResetEvent,
|
|
@@ -2542,6 +2557,7 @@ var NON_CHECKPOINT_LOCAL_KEYS = [
|
|
|
2542
2557
|
"runtimeEventCommitPort",
|
|
2543
2558
|
"commitExecutionBoundary",
|
|
2544
2559
|
"toolRecoveryPort",
|
|
2560
|
+
"pendingUserInputPort",
|
|
2545
2561
|
"runtimeFailureFactSink",
|
|
2546
2562
|
"signal",
|
|
2547
2563
|
"summarizationCallbacks",
|
|
@@ -6534,6 +6550,8 @@ function describeRuntimeEventLifecycle(event) {
|
|
|
6534
6550
|
case "run_execution_metrics":
|
|
6535
6551
|
case "history_summary":
|
|
6536
6552
|
return "event_bus_sse";
|
|
6553
|
+
case "user_input":
|
|
6554
|
+
return event.type === "user_input" && event.delivery === "mid_run" ? "event_bus_sse" : "none";
|
|
6537
6555
|
case "audit_envelope":
|
|
6538
6556
|
return "none";
|
|
6539
6557
|
default:
|
|
@@ -6977,6 +6995,16 @@ function requireEventTimestamp(value) {
|
|
|
6977
6995
|
function applyRuntimeEventToMemory(event, memory) {
|
|
6978
6996
|
switch (event.type) {
|
|
6979
6997
|
case "user_input": {
|
|
6998
|
+
if (event.delivery === "mid_run") {
|
|
6999
|
+
memory.appendMessage({
|
|
7000
|
+
id: event.id,
|
|
7001
|
+
role: "user",
|
|
7002
|
+
type: "user_steer",
|
|
7003
|
+
content: event.content,
|
|
7004
|
+
timestamp: event.timestamp
|
|
7005
|
+
});
|
|
7006
|
+
break;
|
|
7007
|
+
}
|
|
6980
7008
|
memory.addUserMessage(event.content, event.id, event.attachments);
|
|
6981
7009
|
break;
|
|
6982
7010
|
}
|
|
@@ -8624,6 +8652,62 @@ async function commitToolBoundary(state, result) {
|
|
|
8624
8652
|
await state.local.commitExecutionBoundary(state);
|
|
8625
8653
|
}
|
|
8626
8654
|
|
|
8655
|
+
// src/runtime-kernel/graph-engine/nodes/toolNode.pendingUserInput.ts
|
|
8656
|
+
function isPendingUserInputPort(value) {
|
|
8657
|
+
return !!value && typeof value === "object" && typeof Reflect.get(value, "claim") === "function" && typeof Reflect.get(value, "confirm") === "function" && typeof Reflect.get(value, "release") === "function";
|
|
8658
|
+
}
|
|
8659
|
+
function readRemainingSteps(state) {
|
|
8660
|
+
const value = state.local?.executorLocal?.remainingSteps;
|
|
8661
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
8662
|
+
}
|
|
8663
|
+
function readIdentity(value, field) {
|
|
8664
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
8665
|
+
throw new Error(`ToolNode pending user input requires ${field}`);
|
|
8666
|
+
}
|
|
8667
|
+
return value;
|
|
8668
|
+
}
|
|
8669
|
+
async function claimPendingUserInputs(state, result) {
|
|
8670
|
+
if (result.kind !== "route" || result.nextNodeId !== "llm") return void 0;
|
|
8671
|
+
const local = state.local;
|
|
8672
|
+
const port = local?.pendingUserInputPort;
|
|
8673
|
+
if (!isPendingUserInputPort(port)) return void 0;
|
|
8674
|
+
const signal = local?.signal;
|
|
8675
|
+
if (signal?.aborted || isRunPauseSignal(signal)) return void 0;
|
|
8676
|
+
const remainingSteps = readRemainingSteps(state);
|
|
8677
|
+
if (remainingSteps !== void 0 && remainingSteps < 1) return void 0;
|
|
8678
|
+
const inputs = await port.claim();
|
|
8679
|
+
if (inputs.length === 0) return void 0;
|
|
8680
|
+
const ids = inputs.map((input) => input.id);
|
|
8681
|
+
try {
|
|
8682
|
+
const conversationId = readIdentity(local?.conversationId, "conversationId");
|
|
8683
|
+
const turnId = readIdentity(local?.turnId, "turnId");
|
|
8684
|
+
const sink = requireRuntimeEventSink(local);
|
|
8685
|
+
const events = inputs.map((input) => sink(
|
|
8686
|
+
createUserInputEvent(readIdentity(input.id, "input id"), conversationId, turnId, input.content, {
|
|
8687
|
+
timestamp: input.timestamp ?? Date.now(),
|
|
8688
|
+
delivery: "mid_run"
|
|
8689
|
+
}),
|
|
8690
|
+
"ToolNode.pending_user_input"
|
|
8691
|
+
));
|
|
8692
|
+
state.local = {
|
|
8693
|
+
...state.local,
|
|
8694
|
+
history: appendWorkingHistory(parseRuntimeEvents(state.local?.history ?? []), events)
|
|
8695
|
+
};
|
|
8696
|
+
return {
|
|
8697
|
+
events,
|
|
8698
|
+
confirm: async () => {
|
|
8699
|
+
await port.confirm(ids);
|
|
8700
|
+
},
|
|
8701
|
+
release: async () => {
|
|
8702
|
+
await port.release(ids);
|
|
8703
|
+
}
|
|
8704
|
+
};
|
|
8705
|
+
} catch (error) {
|
|
8706
|
+
await port.release(ids);
|
|
8707
|
+
throw error;
|
|
8708
|
+
}
|
|
8709
|
+
}
|
|
8710
|
+
|
|
8627
8711
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
8628
8712
|
var logger11 = new Logger("ToolNode");
|
|
8629
8713
|
function isAbortSignal(value) {
|
|
@@ -8791,7 +8875,19 @@ var ToolNode = class {
|
|
|
8791
8875
|
});
|
|
8792
8876
|
throw result.error;
|
|
8793
8877
|
}
|
|
8794
|
-
await
|
|
8878
|
+
const steering = await claimPendingUserInputs(state, result);
|
|
8879
|
+
if (steering) {
|
|
8880
|
+
result = { ...result, events: [...result.events ?? [], ...steering.events] };
|
|
8881
|
+
try {
|
|
8882
|
+
await commitToolBoundary(state, result);
|
|
8883
|
+
} catch (error) {
|
|
8884
|
+
await steering.release();
|
|
8885
|
+
throw error;
|
|
8886
|
+
}
|
|
8887
|
+
await steering.confirm();
|
|
8888
|
+
} else {
|
|
8889
|
+
await commitToolBoundary(state, result);
|
|
8890
|
+
}
|
|
8795
8891
|
if (Array.isArray(result.events) && result.events.length > 0) {
|
|
8796
8892
|
events.push(...result.events);
|
|
8797
8893
|
}
|
|
@@ -9549,7 +9645,8 @@ function parseEngineCheckpoint(value) {
|
|
|
9549
9645
|
"runtimeFailureFactSink",
|
|
9550
9646
|
"summarizationCallbacks",
|
|
9551
9647
|
"commitExecutionBoundary",
|
|
9552
|
-
"toolRecoveryPort"
|
|
9648
|
+
"toolRecoveryPort",
|
|
9649
|
+
"pendingUserInputPort"
|
|
9553
9650
|
]) {
|
|
9554
9651
|
if (result.local && Object.hasOwn(result.local, key)) {
|
|
9555
9652
|
throw new Error(`Checkpoint must not contain execution capability: ${key}`);
|