@linnlabs/linnkit 0.37.2 → 0.37.3
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 +13 -0
- package/dist/cli.cjs +236 -232
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +236 -232
- package/dist/cli.js.map +1 -1
- package/dist/context-manager.cjs +197 -197
- package/dist/context-manager.cjs.map +1 -1
- package/dist/context-manager.js +197 -197
- package/dist/context-manager.js.map +1 -1
- package/dist/index.cjs +236 -232
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +236 -232
- package/dist/index.js.map +1 -1
- package/dist/quickstart.cjs +236 -232
- package/dist/quickstart.cjs.map +1 -1
- package/dist/quickstart.js +236 -232
- package/dist/quickstart.js.map +1 -1
- package/dist/runtime-kernel.cjs +236 -232
- package/dist/runtime-kernel.cjs.map +1 -1
- package/dist/runtime-kernel.js +236 -232
- package/dist/runtime-kernel.js.map +1 -1
- package/dist/testkit.cjs +236 -232
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.js +236 -232
- package/dist/testkit.js.map +1 -1
- package/docs/integration/persistence.md +10 -0
- package/package.json +2 -2
package/dist/quickstart.cjs
CHANGED
|
@@ -6359,6 +6359,204 @@ var GraphAgentExecutor = class {
|
|
|
6359
6359
|
}
|
|
6360
6360
|
};
|
|
6361
6361
|
|
|
6362
|
+
// src/runtime-kernel/events/eventGovernance.ts
|
|
6363
|
+
var RUNTIME_EVENT_TYPES_NEVER_REPLAYED_TO_UI = [
|
|
6364
|
+
"audit_envelope",
|
|
6365
|
+
"final_answer_chunk",
|
|
6366
|
+
"final_answer_reset",
|
|
6367
|
+
"subrun_trace",
|
|
6368
|
+
"context_usage_snapshot"
|
|
6369
|
+
];
|
|
6370
|
+
function isRecord6(value) {
|
|
6371
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
6372
|
+
}
|
|
6373
|
+
function isToolCallDecisionEvent(event) {
|
|
6374
|
+
return event.type === "tool_call_decision";
|
|
6375
|
+
}
|
|
6376
|
+
function isToolProcessEvent(event) {
|
|
6377
|
+
return event.type === "tool_process";
|
|
6378
|
+
}
|
|
6379
|
+
function isSubRunTraceRuntimeEvent(event) {
|
|
6380
|
+
return event.type === "subrun_trace";
|
|
6381
|
+
}
|
|
6382
|
+
function isRunExecutionMetricsRuntimeEvent(event) {
|
|
6383
|
+
return event.type === "run_execution_metrics";
|
|
6384
|
+
}
|
|
6385
|
+
function isContextUsageSnapshotRuntimeEvent(event) {
|
|
6386
|
+
return event.type === "context_usage_snapshot";
|
|
6387
|
+
}
|
|
6388
|
+
function isRequiresUserInteractionRuntimeEvent(event) {
|
|
6389
|
+
return event.type === "requires_user_interaction";
|
|
6390
|
+
}
|
|
6391
|
+
function isAuditEnvelopeRuntimeEvent(event) {
|
|
6392
|
+
return event.type === "audit_envelope";
|
|
6393
|
+
}
|
|
6394
|
+
function isControlRuntimeEvent(event) {
|
|
6395
|
+
return event.type === "control";
|
|
6396
|
+
}
|
|
6397
|
+
function isHiddenUserInputEvent(event) {
|
|
6398
|
+
if (event.type !== "user_input") {
|
|
6399
|
+
return false;
|
|
6400
|
+
}
|
|
6401
|
+
const metadata = isRecord6(event.metadata) ? event.metadata : void 0;
|
|
6402
|
+
const ui = metadata && isRecord6(metadata.ui) ? metadata.ui : void 0;
|
|
6403
|
+
return ui?.presentation === "hidden";
|
|
6404
|
+
}
|
|
6405
|
+
function isEmptyTerminalAssistantRuntimeEvent(event) {
|
|
6406
|
+
if (event.type !== "thought" && event.type !== "final_answer") {
|
|
6407
|
+
return false;
|
|
6408
|
+
}
|
|
6409
|
+
return event.content.trim().length === 0;
|
|
6410
|
+
}
|
|
6411
|
+
function isConversationUiRuntimeEvent(event) {
|
|
6412
|
+
return event.lane === "foreground" && event.visibility === "conversation";
|
|
6413
|
+
}
|
|
6414
|
+
function shouldPersistRuntimeEvent(event) {
|
|
6415
|
+
return describeRuntimeEventLifecycle(event).persist;
|
|
6416
|
+
}
|
|
6417
|
+
function requirePersistableRuntimeEvent(event) {
|
|
6418
|
+
if (!shouldPersistRuntimeEvent(event)) {
|
|
6419
|
+
throw new Error(`RuntimeEvent ${event.id} (${event.type}) is not eligible for persistence.`);
|
|
6420
|
+
}
|
|
6421
|
+
return event;
|
|
6422
|
+
}
|
|
6423
|
+
function requirePersistableRoutedRuntimeEvent(event) {
|
|
6424
|
+
requirePersistableRuntimeEvent(event);
|
|
6425
|
+
return parseRoutedRuntimeEvent(event);
|
|
6426
|
+
}
|
|
6427
|
+
function shouldReplayRuntimeEventToUi(event) {
|
|
6428
|
+
return describeRuntimeEventLifecycle(event).replayToUi;
|
|
6429
|
+
}
|
|
6430
|
+
function shouldEnterAgentContext(event) {
|
|
6431
|
+
return describeRuntimeEventLifecycle(event).enterAgentContext;
|
|
6432
|
+
}
|
|
6433
|
+
function getRuntimeEventUiProjectionKind(event) {
|
|
6434
|
+
if (isHiddenUserInputEvent(event)) {
|
|
6435
|
+
return "hidden";
|
|
6436
|
+
}
|
|
6437
|
+
switch (event.type) {
|
|
6438
|
+
case "user_input":
|
|
6439
|
+
return "user_input";
|
|
6440
|
+
case "thought":
|
|
6441
|
+
return "thought";
|
|
6442
|
+
case "final_answer":
|
|
6443
|
+
return "final_answer";
|
|
6444
|
+
case "final_answer_chunk":
|
|
6445
|
+
return "final_answer_chunk";
|
|
6446
|
+
case "final_answer_reset":
|
|
6447
|
+
return "final_answer_reset";
|
|
6448
|
+
case "tool_call_decision":
|
|
6449
|
+
return "tool_call_decision";
|
|
6450
|
+
case "tool_process":
|
|
6451
|
+
return "tool_process";
|
|
6452
|
+
case "tool_output":
|
|
6453
|
+
return "tool_output";
|
|
6454
|
+
case "requires_user_interaction":
|
|
6455
|
+
return "requires_user_interaction";
|
|
6456
|
+
case "audit_envelope":
|
|
6457
|
+
return "audit_envelope";
|
|
6458
|
+
case "subrun_trace":
|
|
6459
|
+
return "subrun_trace";
|
|
6460
|
+
case "error":
|
|
6461
|
+
return "error";
|
|
6462
|
+
case "context_usage_snapshot":
|
|
6463
|
+
return "context_usage_snapshot";
|
|
6464
|
+
case "run_execution_metrics":
|
|
6465
|
+
return "run_execution_metrics";
|
|
6466
|
+
case "history_summary":
|
|
6467
|
+
return "history_summary";
|
|
6468
|
+
default:
|
|
6469
|
+
return "unsupported";
|
|
6470
|
+
}
|
|
6471
|
+
}
|
|
6472
|
+
function describeRuntimeEventLifecycle(event) {
|
|
6473
|
+
const uiProjectionKind = getRuntimeEventUiProjectionKind(event);
|
|
6474
|
+
const persist = event.ephemeral !== true && !isToolProcessEvent(event) && !isSubRunTraceRuntimeEvent(event);
|
|
6475
|
+
const replayToUi = persist && isConversationUiRuntimeEvent(event) && uiProjectionKind !== "hidden" && uiProjectionKind !== "audit_envelope" && uiProjectionKind !== "final_answer_chunk" && uiProjectionKind !== "final_answer_reset" && uiProjectionKind !== "unsupported";
|
|
6476
|
+
const enterAgentContext = (() => {
|
|
6477
|
+
if (uiProjectionKind === "unsupported") {
|
|
6478
|
+
return false;
|
|
6479
|
+
}
|
|
6480
|
+
if (isSubRunTraceRuntimeEvent(event)) {
|
|
6481
|
+
return false;
|
|
6482
|
+
}
|
|
6483
|
+
if (isRunExecutionMetricsRuntimeEvent(event)) {
|
|
6484
|
+
return false;
|
|
6485
|
+
}
|
|
6486
|
+
if (isContextUsageSnapshotRuntimeEvent(event)) {
|
|
6487
|
+
return false;
|
|
6488
|
+
}
|
|
6489
|
+
if (event.type === "error") {
|
|
6490
|
+
return false;
|
|
6491
|
+
}
|
|
6492
|
+
if (isRequiresUserInteractionRuntimeEvent(event)) {
|
|
6493
|
+
return false;
|
|
6494
|
+
}
|
|
6495
|
+
if (isAuditEnvelopeRuntimeEvent(event)) {
|
|
6496
|
+
return false;
|
|
6497
|
+
}
|
|
6498
|
+
if (isControlRuntimeEvent(event)) {
|
|
6499
|
+
return false;
|
|
6500
|
+
}
|
|
6501
|
+
if (isHiddenUserInputEvent(event)) {
|
|
6502
|
+
return false;
|
|
6503
|
+
}
|
|
6504
|
+
if (isToolProcessEvent(event)) {
|
|
6505
|
+
return false;
|
|
6506
|
+
}
|
|
6507
|
+
if (event.type === "thought") {
|
|
6508
|
+
return false;
|
|
6509
|
+
}
|
|
6510
|
+
if (event.type === "final_answer_chunk") {
|
|
6511
|
+
return false;
|
|
6512
|
+
}
|
|
6513
|
+
if (event.type === "final_answer_reset") {
|
|
6514
|
+
return false;
|
|
6515
|
+
}
|
|
6516
|
+
if (isEmptyTerminalAssistantRuntimeEvent(event)) {
|
|
6517
|
+
return false;
|
|
6518
|
+
}
|
|
6519
|
+
return true;
|
|
6520
|
+
})();
|
|
6521
|
+
const realtimeChannel = (() => {
|
|
6522
|
+
switch (uiProjectionKind) {
|
|
6523
|
+
case "thought":
|
|
6524
|
+
case "final_answer":
|
|
6525
|
+
case "final_answer_chunk":
|
|
6526
|
+
case "final_answer_reset":
|
|
6527
|
+
case "tool_call_decision":
|
|
6528
|
+
case "tool_process":
|
|
6529
|
+
case "tool_output":
|
|
6530
|
+
case "requires_user_interaction":
|
|
6531
|
+
case "subrun_trace":
|
|
6532
|
+
case "error":
|
|
6533
|
+
case "context_usage_snapshot":
|
|
6534
|
+
case "run_execution_metrics":
|
|
6535
|
+
case "history_summary":
|
|
6536
|
+
return "event_bus_sse";
|
|
6537
|
+
case "audit_envelope":
|
|
6538
|
+
return "none";
|
|
6539
|
+
default:
|
|
6540
|
+
return "none";
|
|
6541
|
+
}
|
|
6542
|
+
})();
|
|
6543
|
+
return {
|
|
6544
|
+
uiProjectionKind,
|
|
6545
|
+
persist,
|
|
6546
|
+
replayToUi,
|
|
6547
|
+
enterAgentContext,
|
|
6548
|
+
realtimeChannel
|
|
6549
|
+
};
|
|
6550
|
+
}
|
|
6551
|
+
function shouldEmitRuntimeEventToSse(event) {
|
|
6552
|
+
return describeRuntimeEventLifecycle(event).realtimeChannel === "event_bus_sse";
|
|
6553
|
+
}
|
|
6554
|
+
|
|
6555
|
+
// src/runtime-kernel/graph-engine/functions/appendWorkingHistory.ts
|
|
6556
|
+
function appendWorkingHistory(history, events) {
|
|
6557
|
+
return [...history.filter(shouldPersistRuntimeEvent), ...events.filter(shouldPersistRuntimeEvent)];
|
|
6558
|
+
}
|
|
6559
|
+
|
|
6362
6560
|
// src/runtime-kernel/graph-engine/nodes/llmNode.state.ts
|
|
6363
6561
|
function assertLlmNodeStreamChunkSequence(state, answerId, seq) {
|
|
6364
6562
|
const answerChanged = state.answerId !== answerId;
|
|
@@ -6443,7 +6641,7 @@ function initLlmNodeState(init) {
|
|
|
6443
6641
|
};
|
|
6444
6642
|
}
|
|
6445
6643
|
function buildLocalPatch(nodeState, ctx) {
|
|
6446
|
-
const updatedHistory =
|
|
6644
|
+
const updatedHistory = appendWorkingHistory(ctx.history, nodeState.streamRuntimeEvents);
|
|
6447
6645
|
const patch = {
|
|
6448
6646
|
answerId: nodeState.answerId,
|
|
6449
6647
|
chunkSeq: nodeState.chunkSeq,
|
|
@@ -6596,11 +6794,11 @@ var AgentEventSchema = zod.z.discriminatedUnion("type", [
|
|
|
6596
6794
|
});
|
|
6597
6795
|
|
|
6598
6796
|
// src/runtime-kernel/events/provider-sidecar.ts
|
|
6599
|
-
var
|
|
6797
|
+
var isRecord7 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
6600
6798
|
function readMetaFromEvent(event) {
|
|
6601
|
-
if (!
|
|
6799
|
+
if (!isRecord7(event)) return void 0;
|
|
6602
6800
|
const value = event["meta"];
|
|
6603
|
-
return
|
|
6801
|
+
return isRecord7(value) ? value : void 0;
|
|
6604
6802
|
}
|
|
6605
6803
|
|
|
6606
6804
|
// src/runtime-kernel/events/agent-to-runtime.ts
|
|
@@ -6608,7 +6806,7 @@ function agentEventToRuntime(agentEvent, context, options = {}) {
|
|
|
6608
6806
|
return mapAgentEventToRuntime(agentEvent, context, options);
|
|
6609
6807
|
}
|
|
6610
6808
|
function mapAgentEventToRuntime(agentEvent, context, options) {
|
|
6611
|
-
if (
|
|
6809
|
+
if (isRecord7(agentEvent) && agentEvent["type"] === "history_summary") {
|
|
6612
6810
|
const event = RuntimeEvent.parse(agentEvent);
|
|
6613
6811
|
return context.metadata ? {
|
|
6614
6812
|
...event,
|
|
@@ -7269,7 +7467,7 @@ var LlmNode = class {
|
|
|
7269
7467
|
];
|
|
7270
7468
|
logger7.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
7271
7469
|
previousCount: history.length,
|
|
7272
|
-
nextCount:
|
|
7470
|
+
nextCount: patch.history.length,
|
|
7273
7471
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
7274
7472
|
});
|
|
7275
7473
|
logger7.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
@@ -7316,7 +7514,7 @@ var ToolModelInputResolutionError = class extends Error {
|
|
|
7316
7514
|
// src/runtime-kernel/tools/model-input/functions/parseToolModelInputDeclaration.ts
|
|
7317
7515
|
var DECLARATION_KEYS = /* @__PURE__ */ new Set(["attachments"]);
|
|
7318
7516
|
var SELECTION_KEYS = /* @__PURE__ */ new Set(["id", "uri", "label"]);
|
|
7319
|
-
function
|
|
7517
|
+
function isRecord8(value) {
|
|
7320
7518
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7321
7519
|
}
|
|
7322
7520
|
function hasOnlyKeys(value, allowed) {
|
|
@@ -7329,7 +7527,7 @@ function readTrimmedString(value, maxLength) {
|
|
|
7329
7527
|
return value === value.trim() ? value : void 0;
|
|
7330
7528
|
}
|
|
7331
7529
|
function parseSelection(value, index) {
|
|
7332
|
-
if (!
|
|
7530
|
+
if (!isRecord8(value) || !hasOnlyKeys(value, SELECTION_KEYS)) {
|
|
7333
7531
|
return { ok: false, reason: `modelInput.attachments[${index}] \u5FC5\u987B\u662F strict selection\u3002` };
|
|
7334
7532
|
}
|
|
7335
7533
|
const id = readTrimmedString(value.id, 200);
|
|
@@ -7350,7 +7548,7 @@ function parseSelection(value, index) {
|
|
|
7350
7548
|
return Object.freeze({ id, uri });
|
|
7351
7549
|
}
|
|
7352
7550
|
function parseToolModelInputDeclaration(value) {
|
|
7353
|
-
if (!
|
|
7551
|
+
if (!isRecord8(value) || !hasOnlyKeys(value, DECLARATION_KEYS)) {
|
|
7354
7552
|
return { ok: false, reason: "modelInput \u5FC5\u987B\u662F\u53EA\u5305\u542B attachments \u7684 strict \u5BF9\u8C61\u3002" };
|
|
7355
7553
|
}
|
|
7356
7554
|
if (!Array.isArray(value.attachments) || value.attachments.length === 0) {
|
|
@@ -7426,7 +7624,7 @@ function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
|
7426
7624
|
}
|
|
7427
7625
|
|
|
7428
7626
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
7429
|
-
function
|
|
7627
|
+
function isRecord9(value) {
|
|
7430
7628
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
7431
7629
|
}
|
|
7432
7630
|
function readString3(value) {
|
|
@@ -7469,7 +7667,7 @@ function resolveToolObservationGovernancePolicy(policy) {
|
|
|
7469
7667
|
}
|
|
7470
7668
|
function readObservationPreviewMeta(parsed) {
|
|
7471
7669
|
const meta = parsed["observationPreviewMeta"];
|
|
7472
|
-
if (!
|
|
7670
|
+
if (!isRecord9(meta)) {
|
|
7473
7671
|
return void 0;
|
|
7474
7672
|
}
|
|
7475
7673
|
const filename = readString3(meta["filename"]);
|
|
@@ -7487,7 +7685,7 @@ function readObservationPreviewMeta(parsed) {
|
|
|
7487
7685
|
};
|
|
7488
7686
|
}
|
|
7489
7687
|
async function applyObservationGovernance(params) {
|
|
7490
|
-
if (!params.structuredObservation || !
|
|
7688
|
+
if (!params.structuredObservation || !isRecord9(params.parsed)) {
|
|
7491
7689
|
throw new Error("Observation governance requires a validated structured tool result.");
|
|
7492
7690
|
}
|
|
7493
7691
|
const policy = resolveToolObservationGovernancePolicy(params.policy);
|
|
@@ -7579,7 +7777,7 @@ function createToolProtocolFuseError(nextCount, error) {
|
|
|
7579
7777
|
// src/runtime-kernel/graph-engine/nodes/toolNode.stateTransitions.ts
|
|
7580
7778
|
function mergeHistory(local, runtimeEvents) {
|
|
7581
7779
|
const history = parseRuntimeEvents(local.history ?? []);
|
|
7582
|
-
return
|
|
7780
|
+
return appendWorkingHistory(history, runtimeEvents);
|
|
7583
7781
|
}
|
|
7584
7782
|
function stripAnswerState(local) {
|
|
7585
7783
|
const nextLocal = { ...local };
|
|
@@ -7588,7 +7786,7 @@ function stripAnswerState(local) {
|
|
|
7588
7786
|
return nextLocal;
|
|
7589
7787
|
}
|
|
7590
7788
|
function validateStructuredToolResultContract(parsed) {
|
|
7591
|
-
if (!
|
|
7789
|
+
if (!isRecord9(parsed)) {
|
|
7592
7790
|
return { ok: false, reason: "\u5DE5\u5177\u6210\u529F\u7ED3\u679C\u5FC5\u987B\u662F JSON \u5BF9\u8C61\u3002" };
|
|
7593
7791
|
}
|
|
7594
7792
|
if (!Object.prototype.hasOwnProperty.call(parsed, "data") || parsed.data === void 0) {
|
|
@@ -7616,7 +7814,7 @@ function validateStructuredToolResultContract(parsed) {
|
|
|
7616
7814
|
};
|
|
7617
7815
|
}
|
|
7618
7816
|
function extractToolControlInfo(parsed) {
|
|
7619
|
-
if (!
|
|
7817
|
+
if (!isRecord9(parsed) || !isRecord9(parsed.control)) {
|
|
7620
7818
|
return void 0;
|
|
7621
7819
|
}
|
|
7622
7820
|
const control = parsed.control;
|
|
@@ -7640,7 +7838,7 @@ function buildRequireUserLocalState(params) {
|
|
|
7640
7838
|
...params.local,
|
|
7641
7839
|
pendingToolCalls: params.remainingCalls,
|
|
7642
7840
|
pendingInteractionSpec: {
|
|
7643
|
-
...
|
|
7841
|
+
...isRecord9(params.parsed) && isRecord9(params.parsed.control) ? params.parsed.control : {},
|
|
7644
7842
|
// wait_user 必须携带工具已校验的结构化结果,UI 才能使用正式 form identity。
|
|
7645
7843
|
form: params.parsed,
|
|
7646
7844
|
toolCallId: params.toolCallId,
|
|
@@ -7679,7 +7877,7 @@ function buildErrorLocalState(params) {
|
|
|
7679
7877
|
|
|
7680
7878
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
7681
7879
|
var logger8 = new Logger("ToolArgNormalizer");
|
|
7682
|
-
function
|
|
7880
|
+
function isRecord10(v) {
|
|
7683
7881
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
7684
7882
|
}
|
|
7685
7883
|
function tryParseJsonEncodedValue(v) {
|
|
@@ -7772,12 +7970,12 @@ function normalizeByPropertySchema(prop, v, options) {
|
|
|
7772
7970
|
}
|
|
7773
7971
|
case "object": {
|
|
7774
7972
|
const parsedValue = tryParseJsonEncodedValue(v);
|
|
7775
|
-
if (parsedValue !== v &&
|
|
7973
|
+
if (parsedValue !== v && isRecord10(parsedValue)) {
|
|
7776
7974
|
logJsonEncodedNormalization("object", options);
|
|
7777
7975
|
}
|
|
7778
|
-
if (!
|
|
7976
|
+
if (!isRecord10(parsedValue)) return parsedValue;
|
|
7779
7977
|
const selectedSchema = selectDiscriminatedObjectSchema(prop, parsedValue);
|
|
7780
|
-
if (!selectedSchema.properties || !
|
|
7978
|
+
if (!selectedSchema.properties || !isRecord10(selectedSchema.properties)) return parsedValue;
|
|
7781
7979
|
return normalizeToolArgs(
|
|
7782
7980
|
{ properties: selectedSchema.properties },
|
|
7783
7981
|
parsedValue,
|
|
@@ -7799,7 +7997,7 @@ function normalizeToolArgs(schema, args, options = {}) {
|
|
|
7799
7997
|
}
|
|
7800
7998
|
return next;
|
|
7801
7999
|
}
|
|
7802
|
-
function
|
|
8000
|
+
function isRecord11(v) {
|
|
7803
8001
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
7804
8002
|
}
|
|
7805
8003
|
function stableStringify(v) {
|
|
@@ -7809,7 +8007,7 @@ function stableStringify(v) {
|
|
|
7809
8007
|
if (t === "string") return JSON.stringify(v);
|
|
7810
8008
|
if (t === "number" || t === "boolean") return String(v);
|
|
7811
8009
|
if (Array.isArray(v)) return `[${v.map(stableStringify).join(",")}]`;
|
|
7812
|
-
if (
|
|
8010
|
+
if (isRecord11(v)) {
|
|
7813
8011
|
const keys = Object.keys(v).sort();
|
|
7814
8012
|
const parts = keys.map((k) => `${JSON.stringify(k)}:${stableStringify(v[k])}`);
|
|
7815
8013
|
return `{${parts.join(",")}}`;
|
|
@@ -7846,13 +8044,13 @@ function findCachedToolOutputByIdempotencyKey(params) {
|
|
|
7846
8044
|
if (e.tool_name !== params.toolName) continue;
|
|
7847
8045
|
if (e.status !== "success") continue;
|
|
7848
8046
|
const meta = e.metadata;
|
|
7849
|
-
if (!
|
|
8047
|
+
if (!isRecord11(meta)) continue;
|
|
7850
8048
|
const idem = meta["idempotency"];
|
|
7851
|
-
if (!
|
|
8049
|
+
if (!isRecord11(idem)) continue;
|
|
7852
8050
|
if (idem["key"] !== params.idempotencyKey) continue;
|
|
7853
8051
|
const structuredResult = { data: e.data, observation: e.observation };
|
|
7854
8052
|
const presentation = meta?.presentation;
|
|
7855
|
-
if (
|
|
8053
|
+
if (isRecord11(presentation) && presentation["media"] !== void 0) {
|
|
7856
8054
|
structuredResult["media"] = presentation["media"];
|
|
7857
8055
|
}
|
|
7858
8056
|
return {
|
|
@@ -8126,7 +8324,7 @@ function parseToolArgs(call) {
|
|
|
8126
8324
|
}
|
|
8127
8325
|
try {
|
|
8128
8326
|
const parsed = JSON.parse(rawArguments);
|
|
8129
|
-
if (!
|
|
8327
|
+
if (!isRecord9(parsed)) {
|
|
8130
8328
|
return {
|
|
8131
8329
|
ok: false,
|
|
8132
8330
|
error: "Tool arguments must decode to a JSON object."
|
|
@@ -8144,13 +8342,12 @@ function parseToolArgs(call) {
|
|
|
8144
8342
|
}
|
|
8145
8343
|
function prepareToolNodeContext(state) {
|
|
8146
8344
|
const local = state.local || {};
|
|
8147
|
-
const toolContext =
|
|
8148
|
-
if (!
|
|
8345
|
+
const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
|
|
8346
|
+
if (!isRecord9(local.toolContext)) {
|
|
8149
8347
|
local.toolContext = toolContext;
|
|
8150
8348
|
}
|
|
8151
8349
|
const conversationId = requireRuntimeIdentity(local.conversationId, "conversationId");
|
|
8152
8350
|
const turnId = requireRuntimeIdentity(local.turnId, "turnId");
|
|
8153
|
-
parseRuntimeEvents(local.history ?? []);
|
|
8154
8351
|
const existingConversationId = typeof toolContext.conversationId === "string" ? toolContext.conversationId.trim() : "";
|
|
8155
8352
|
ensureToolContextRuntimeCapability({
|
|
8156
8353
|
context: toolContext,
|
|
@@ -8418,11 +8615,11 @@ function createPendingToolCancellationEvents(params) {
|
|
|
8418
8615
|
return events;
|
|
8419
8616
|
}
|
|
8420
8617
|
function buildCancelledToolBatchLocalState(local, runtimeEvents) {
|
|
8421
|
-
const history =
|
|
8618
|
+
const history = parseRuntimeEvents(local.history ?? []);
|
|
8422
8619
|
return {
|
|
8423
8620
|
...stripAnswerState(local),
|
|
8424
8621
|
pendingToolCalls: [],
|
|
8425
|
-
history:
|
|
8622
|
+
history: appendWorkingHistory(history, runtimeEvents)
|
|
8426
8623
|
};
|
|
8427
8624
|
}
|
|
8428
8625
|
function recordToolProtocolError(params) {
|
|
@@ -8491,14 +8688,14 @@ function readHistoryEvents(local) {
|
|
|
8491
8688
|
}
|
|
8492
8689
|
function readLastSuccessfulLlmModelId(local) {
|
|
8493
8690
|
const executorLocal = local.executorLocal;
|
|
8494
|
-
if (!
|
|
8691
|
+
if (!isRecord9(executorLocal)) {
|
|
8495
8692
|
return void 0;
|
|
8496
8693
|
}
|
|
8497
8694
|
const value = executorLocal.lastSuccessfulLlmModelId;
|
|
8498
8695
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
8499
8696
|
}
|
|
8500
8697
|
function formatCapabilityError(error) {
|
|
8501
|
-
if (
|
|
8698
|
+
if (isRecord9(error)) {
|
|
8502
8699
|
const codeValue = error.errorCode ?? error.code;
|
|
8503
8700
|
const code = typeof codeValue === "string" ? codeValue.trim() : "";
|
|
8504
8701
|
const message = typeof error.message === "string" ? error.message.trim() : "";
|
|
@@ -9113,16 +9310,16 @@ var ToolNode = class {
|
|
|
9113
9310
|
};
|
|
9114
9311
|
|
|
9115
9312
|
// src/runtime-kernel/graph-engine/nodes/userNode.ts
|
|
9116
|
-
function
|
|
9313
|
+
function isRecord12(value) {
|
|
9117
9314
|
return typeof value === "object" && value !== null;
|
|
9118
9315
|
}
|
|
9119
9316
|
function isRuntimeEvent(value) {
|
|
9120
|
-
return
|
|
9317
|
+
return isRecord12(value) && typeof value.type === "string";
|
|
9121
9318
|
}
|
|
9122
9319
|
var UserNode = class {
|
|
9123
9320
|
id = "user";
|
|
9124
9321
|
async run(state) {
|
|
9125
|
-
const local =
|
|
9322
|
+
const local = isRecord12(state.local) ? state.local : {};
|
|
9126
9323
|
const newEvents = Array.isArray(local.newEvents) ? local.newEvents.filter(isRuntimeEvent) : [];
|
|
9127
9324
|
const userInputEvent = newEvents.find((event) => event.type === "user_input");
|
|
9128
9325
|
if (!userInputEvent) {
|
|
@@ -9133,7 +9330,7 @@ var UserNode = class {
|
|
|
9133
9330
|
};
|
|
9134
9331
|
|
|
9135
9332
|
// src/runtime-kernel/graph-engine/nodes/waitUserNode.ts
|
|
9136
|
-
function
|
|
9333
|
+
function isRecord13(value) {
|
|
9137
9334
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
9138
9335
|
}
|
|
9139
9336
|
function requireNonEmptyString(value, field) {
|
|
@@ -9150,10 +9347,10 @@ var WaitUserNode = class {
|
|
|
9150
9347
|
}
|
|
9151
9348
|
async run(state) {
|
|
9152
9349
|
const local = state.local ?? {};
|
|
9153
|
-
const spec =
|
|
9350
|
+
const spec = isRecord13(local.pendingInteractionSpec) ? local.pendingInteractionSpec : {};
|
|
9154
9351
|
const conversationId = requireNonEmptyString(local.conversationId, "conversationId");
|
|
9155
9352
|
const turnId = requireNonEmptyString(local.turnId, "turnId");
|
|
9156
|
-
const toolContext =
|
|
9353
|
+
const toolContext = isRecord13(local.toolContext) ? local.toolContext : {};
|
|
9157
9354
|
const runId = RunIdSchema.parse(requireNonEmptyString(toolContext.runId, "toolContext.runId"));
|
|
9158
9355
|
const parentRunId = toolContext.parentRunId === void 0 ? void 0 : RunIdSchema.parse(toolContext.parentRunId);
|
|
9159
9356
|
const toolCallId = ToolCallIdSchema.parse(
|
|
@@ -9308,199 +9505,6 @@ __export(events_exports, {
|
|
|
9308
9505
|
shouldReplayRuntimeEventToUi: () => shouldReplayRuntimeEventToUi
|
|
9309
9506
|
});
|
|
9310
9507
|
|
|
9311
|
-
// src/runtime-kernel/events/eventGovernance.ts
|
|
9312
|
-
var RUNTIME_EVENT_TYPES_NEVER_REPLAYED_TO_UI = [
|
|
9313
|
-
"audit_envelope",
|
|
9314
|
-
"final_answer_chunk",
|
|
9315
|
-
"final_answer_reset",
|
|
9316
|
-
"subrun_trace",
|
|
9317
|
-
"context_usage_snapshot"
|
|
9318
|
-
];
|
|
9319
|
-
function isRecord13(value) {
|
|
9320
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
9321
|
-
}
|
|
9322
|
-
function isToolCallDecisionEvent(event) {
|
|
9323
|
-
return event.type === "tool_call_decision";
|
|
9324
|
-
}
|
|
9325
|
-
function isToolProcessEvent(event) {
|
|
9326
|
-
return event.type === "tool_process";
|
|
9327
|
-
}
|
|
9328
|
-
function isSubRunTraceRuntimeEvent(event) {
|
|
9329
|
-
return event.type === "subrun_trace";
|
|
9330
|
-
}
|
|
9331
|
-
function isRunExecutionMetricsRuntimeEvent(event) {
|
|
9332
|
-
return event.type === "run_execution_metrics";
|
|
9333
|
-
}
|
|
9334
|
-
function isContextUsageSnapshotRuntimeEvent(event) {
|
|
9335
|
-
return event.type === "context_usage_snapshot";
|
|
9336
|
-
}
|
|
9337
|
-
function isRequiresUserInteractionRuntimeEvent(event) {
|
|
9338
|
-
return event.type === "requires_user_interaction";
|
|
9339
|
-
}
|
|
9340
|
-
function isAuditEnvelopeRuntimeEvent(event) {
|
|
9341
|
-
return event.type === "audit_envelope";
|
|
9342
|
-
}
|
|
9343
|
-
function isControlRuntimeEvent(event) {
|
|
9344
|
-
return event.type === "control";
|
|
9345
|
-
}
|
|
9346
|
-
function isHiddenUserInputEvent(event) {
|
|
9347
|
-
if (event.type !== "user_input") {
|
|
9348
|
-
return false;
|
|
9349
|
-
}
|
|
9350
|
-
const metadata = isRecord13(event.metadata) ? event.metadata : void 0;
|
|
9351
|
-
const ui = metadata && isRecord13(metadata.ui) ? metadata.ui : void 0;
|
|
9352
|
-
return ui?.presentation === "hidden";
|
|
9353
|
-
}
|
|
9354
|
-
function isEmptyTerminalAssistantRuntimeEvent(event) {
|
|
9355
|
-
if (event.type !== "thought" && event.type !== "final_answer") {
|
|
9356
|
-
return false;
|
|
9357
|
-
}
|
|
9358
|
-
return event.content.trim().length === 0;
|
|
9359
|
-
}
|
|
9360
|
-
function isConversationUiRuntimeEvent(event) {
|
|
9361
|
-
return event.lane === "foreground" && event.visibility === "conversation";
|
|
9362
|
-
}
|
|
9363
|
-
function shouldPersistRuntimeEvent(event) {
|
|
9364
|
-
return describeRuntimeEventLifecycle(event).persist;
|
|
9365
|
-
}
|
|
9366
|
-
function requirePersistableRuntimeEvent(event) {
|
|
9367
|
-
if (!shouldPersistRuntimeEvent(event)) {
|
|
9368
|
-
throw new Error(`RuntimeEvent ${event.id} (${event.type}) is not eligible for persistence.`);
|
|
9369
|
-
}
|
|
9370
|
-
return event;
|
|
9371
|
-
}
|
|
9372
|
-
function requirePersistableRoutedRuntimeEvent(event) {
|
|
9373
|
-
requirePersistableRuntimeEvent(event);
|
|
9374
|
-
return parseRoutedRuntimeEvent(event);
|
|
9375
|
-
}
|
|
9376
|
-
function shouldReplayRuntimeEventToUi(event) {
|
|
9377
|
-
return describeRuntimeEventLifecycle(event).replayToUi;
|
|
9378
|
-
}
|
|
9379
|
-
function shouldEnterAgentContext(event) {
|
|
9380
|
-
return describeRuntimeEventLifecycle(event).enterAgentContext;
|
|
9381
|
-
}
|
|
9382
|
-
function getRuntimeEventUiProjectionKind(event) {
|
|
9383
|
-
if (isHiddenUserInputEvent(event)) {
|
|
9384
|
-
return "hidden";
|
|
9385
|
-
}
|
|
9386
|
-
switch (event.type) {
|
|
9387
|
-
case "user_input":
|
|
9388
|
-
return "user_input";
|
|
9389
|
-
case "thought":
|
|
9390
|
-
return "thought";
|
|
9391
|
-
case "final_answer":
|
|
9392
|
-
return "final_answer";
|
|
9393
|
-
case "final_answer_chunk":
|
|
9394
|
-
return "final_answer_chunk";
|
|
9395
|
-
case "final_answer_reset":
|
|
9396
|
-
return "final_answer_reset";
|
|
9397
|
-
case "tool_call_decision":
|
|
9398
|
-
return "tool_call_decision";
|
|
9399
|
-
case "tool_process":
|
|
9400
|
-
return "tool_process";
|
|
9401
|
-
case "tool_output":
|
|
9402
|
-
return "tool_output";
|
|
9403
|
-
case "requires_user_interaction":
|
|
9404
|
-
return "requires_user_interaction";
|
|
9405
|
-
case "audit_envelope":
|
|
9406
|
-
return "audit_envelope";
|
|
9407
|
-
case "subrun_trace":
|
|
9408
|
-
return "subrun_trace";
|
|
9409
|
-
case "error":
|
|
9410
|
-
return "error";
|
|
9411
|
-
case "context_usage_snapshot":
|
|
9412
|
-
return "context_usage_snapshot";
|
|
9413
|
-
case "run_execution_metrics":
|
|
9414
|
-
return "run_execution_metrics";
|
|
9415
|
-
case "history_summary":
|
|
9416
|
-
return "history_summary";
|
|
9417
|
-
default:
|
|
9418
|
-
return "unsupported";
|
|
9419
|
-
}
|
|
9420
|
-
}
|
|
9421
|
-
function describeRuntimeEventLifecycle(event) {
|
|
9422
|
-
const uiProjectionKind = getRuntimeEventUiProjectionKind(event);
|
|
9423
|
-
const persist = event.ephemeral !== true && !isToolProcessEvent(event) && !isSubRunTraceRuntimeEvent(event);
|
|
9424
|
-
const replayToUi = persist && isConversationUiRuntimeEvent(event) && uiProjectionKind !== "hidden" && uiProjectionKind !== "audit_envelope" && uiProjectionKind !== "final_answer_chunk" && uiProjectionKind !== "final_answer_reset" && uiProjectionKind !== "unsupported";
|
|
9425
|
-
const enterAgentContext = (() => {
|
|
9426
|
-
if (uiProjectionKind === "unsupported") {
|
|
9427
|
-
return false;
|
|
9428
|
-
}
|
|
9429
|
-
if (isSubRunTraceRuntimeEvent(event)) {
|
|
9430
|
-
return false;
|
|
9431
|
-
}
|
|
9432
|
-
if (isRunExecutionMetricsRuntimeEvent(event)) {
|
|
9433
|
-
return false;
|
|
9434
|
-
}
|
|
9435
|
-
if (isContextUsageSnapshotRuntimeEvent(event)) {
|
|
9436
|
-
return false;
|
|
9437
|
-
}
|
|
9438
|
-
if (event.type === "error") {
|
|
9439
|
-
return false;
|
|
9440
|
-
}
|
|
9441
|
-
if (isRequiresUserInteractionRuntimeEvent(event)) {
|
|
9442
|
-
return false;
|
|
9443
|
-
}
|
|
9444
|
-
if (isAuditEnvelopeRuntimeEvent(event)) {
|
|
9445
|
-
return false;
|
|
9446
|
-
}
|
|
9447
|
-
if (isControlRuntimeEvent(event)) {
|
|
9448
|
-
return false;
|
|
9449
|
-
}
|
|
9450
|
-
if (isHiddenUserInputEvent(event)) {
|
|
9451
|
-
return false;
|
|
9452
|
-
}
|
|
9453
|
-
if (isToolProcessEvent(event)) {
|
|
9454
|
-
return false;
|
|
9455
|
-
}
|
|
9456
|
-
if (event.type === "thought") {
|
|
9457
|
-
return false;
|
|
9458
|
-
}
|
|
9459
|
-
if (event.type === "final_answer_chunk") {
|
|
9460
|
-
return false;
|
|
9461
|
-
}
|
|
9462
|
-
if (event.type === "final_answer_reset") {
|
|
9463
|
-
return false;
|
|
9464
|
-
}
|
|
9465
|
-
if (isEmptyTerminalAssistantRuntimeEvent(event)) {
|
|
9466
|
-
return false;
|
|
9467
|
-
}
|
|
9468
|
-
return true;
|
|
9469
|
-
})();
|
|
9470
|
-
const realtimeChannel = (() => {
|
|
9471
|
-
switch (uiProjectionKind) {
|
|
9472
|
-
case "thought":
|
|
9473
|
-
case "final_answer":
|
|
9474
|
-
case "final_answer_chunk":
|
|
9475
|
-
case "final_answer_reset":
|
|
9476
|
-
case "tool_call_decision":
|
|
9477
|
-
case "tool_process":
|
|
9478
|
-
case "tool_output":
|
|
9479
|
-
case "requires_user_interaction":
|
|
9480
|
-
case "subrun_trace":
|
|
9481
|
-
case "error":
|
|
9482
|
-
case "context_usage_snapshot":
|
|
9483
|
-
case "run_execution_metrics":
|
|
9484
|
-
case "history_summary":
|
|
9485
|
-
return "event_bus_sse";
|
|
9486
|
-
case "audit_envelope":
|
|
9487
|
-
return "none";
|
|
9488
|
-
default:
|
|
9489
|
-
return "none";
|
|
9490
|
-
}
|
|
9491
|
-
})();
|
|
9492
|
-
return {
|
|
9493
|
-
uiProjectionKind,
|
|
9494
|
-
persist,
|
|
9495
|
-
replayToUi,
|
|
9496
|
-
enterAgentContext,
|
|
9497
|
-
realtimeChannel
|
|
9498
|
-
};
|
|
9499
|
-
}
|
|
9500
|
-
function shouldEmitRuntimeEventToSse(event) {
|
|
9501
|
-
return describeRuntimeEventLifecycle(event).realtimeChannel === "event_bus_sse";
|
|
9502
|
-
}
|
|
9503
|
-
|
|
9504
9508
|
// src/runtime-kernel/events/finalAnswerCompletion.ts
|
|
9505
9509
|
function findTerminalFinalAnswer(events) {
|
|
9506
9510
|
for (let index = events.length - 1; index >= 0; index -= 1) {
|