@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/runtime-kernel.cjs
CHANGED
|
@@ -6368,6 +6368,204 @@ var GraphAgentExecutor = class {
|
|
|
6368
6368
|
}
|
|
6369
6369
|
};
|
|
6370
6370
|
|
|
6371
|
+
// src/runtime-kernel/events/eventGovernance.ts
|
|
6372
|
+
var RUNTIME_EVENT_TYPES_NEVER_REPLAYED_TO_UI = [
|
|
6373
|
+
"audit_envelope",
|
|
6374
|
+
"final_answer_chunk",
|
|
6375
|
+
"final_answer_reset",
|
|
6376
|
+
"subrun_trace",
|
|
6377
|
+
"context_usage_snapshot"
|
|
6378
|
+
];
|
|
6379
|
+
function isRecord6(value) {
|
|
6380
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
6381
|
+
}
|
|
6382
|
+
function isToolCallDecisionEvent(event) {
|
|
6383
|
+
return event.type === "tool_call_decision";
|
|
6384
|
+
}
|
|
6385
|
+
function isToolProcessEvent(event) {
|
|
6386
|
+
return event.type === "tool_process";
|
|
6387
|
+
}
|
|
6388
|
+
function isSubRunTraceRuntimeEvent(event) {
|
|
6389
|
+
return event.type === "subrun_trace";
|
|
6390
|
+
}
|
|
6391
|
+
function isRunExecutionMetricsRuntimeEvent(event) {
|
|
6392
|
+
return event.type === "run_execution_metrics";
|
|
6393
|
+
}
|
|
6394
|
+
function isContextUsageSnapshotRuntimeEvent(event) {
|
|
6395
|
+
return event.type === "context_usage_snapshot";
|
|
6396
|
+
}
|
|
6397
|
+
function isRequiresUserInteractionRuntimeEvent(event) {
|
|
6398
|
+
return event.type === "requires_user_interaction";
|
|
6399
|
+
}
|
|
6400
|
+
function isAuditEnvelopeRuntimeEvent(event) {
|
|
6401
|
+
return event.type === "audit_envelope";
|
|
6402
|
+
}
|
|
6403
|
+
function isControlRuntimeEvent(event) {
|
|
6404
|
+
return event.type === "control";
|
|
6405
|
+
}
|
|
6406
|
+
function isHiddenUserInputEvent(event) {
|
|
6407
|
+
if (event.type !== "user_input") {
|
|
6408
|
+
return false;
|
|
6409
|
+
}
|
|
6410
|
+
const metadata = isRecord6(event.metadata) ? event.metadata : void 0;
|
|
6411
|
+
const ui = metadata && isRecord6(metadata.ui) ? metadata.ui : void 0;
|
|
6412
|
+
return ui?.presentation === "hidden";
|
|
6413
|
+
}
|
|
6414
|
+
function isEmptyTerminalAssistantRuntimeEvent(event) {
|
|
6415
|
+
if (event.type !== "thought" && event.type !== "final_answer") {
|
|
6416
|
+
return false;
|
|
6417
|
+
}
|
|
6418
|
+
return event.content.trim().length === 0;
|
|
6419
|
+
}
|
|
6420
|
+
function isConversationUiRuntimeEvent(event) {
|
|
6421
|
+
return event.lane === "foreground" && event.visibility === "conversation";
|
|
6422
|
+
}
|
|
6423
|
+
function shouldPersistRuntimeEvent(event) {
|
|
6424
|
+
return describeRuntimeEventLifecycle(event).persist;
|
|
6425
|
+
}
|
|
6426
|
+
function requirePersistableRuntimeEvent(event) {
|
|
6427
|
+
if (!shouldPersistRuntimeEvent(event)) {
|
|
6428
|
+
throw new Error(`RuntimeEvent ${event.id} (${event.type}) is not eligible for persistence.`);
|
|
6429
|
+
}
|
|
6430
|
+
return event;
|
|
6431
|
+
}
|
|
6432
|
+
function requirePersistableRoutedRuntimeEvent(event) {
|
|
6433
|
+
requirePersistableRuntimeEvent(event);
|
|
6434
|
+
return parseRoutedRuntimeEvent(event);
|
|
6435
|
+
}
|
|
6436
|
+
function shouldReplayRuntimeEventToUi(event) {
|
|
6437
|
+
return describeRuntimeEventLifecycle(event).replayToUi;
|
|
6438
|
+
}
|
|
6439
|
+
function shouldEnterAgentContext(event) {
|
|
6440
|
+
return describeRuntimeEventLifecycle(event).enterAgentContext;
|
|
6441
|
+
}
|
|
6442
|
+
function getRuntimeEventUiProjectionKind(event) {
|
|
6443
|
+
if (isHiddenUserInputEvent(event)) {
|
|
6444
|
+
return "hidden";
|
|
6445
|
+
}
|
|
6446
|
+
switch (event.type) {
|
|
6447
|
+
case "user_input":
|
|
6448
|
+
return "user_input";
|
|
6449
|
+
case "thought":
|
|
6450
|
+
return "thought";
|
|
6451
|
+
case "final_answer":
|
|
6452
|
+
return "final_answer";
|
|
6453
|
+
case "final_answer_chunk":
|
|
6454
|
+
return "final_answer_chunk";
|
|
6455
|
+
case "final_answer_reset":
|
|
6456
|
+
return "final_answer_reset";
|
|
6457
|
+
case "tool_call_decision":
|
|
6458
|
+
return "tool_call_decision";
|
|
6459
|
+
case "tool_process":
|
|
6460
|
+
return "tool_process";
|
|
6461
|
+
case "tool_output":
|
|
6462
|
+
return "tool_output";
|
|
6463
|
+
case "requires_user_interaction":
|
|
6464
|
+
return "requires_user_interaction";
|
|
6465
|
+
case "audit_envelope":
|
|
6466
|
+
return "audit_envelope";
|
|
6467
|
+
case "subrun_trace":
|
|
6468
|
+
return "subrun_trace";
|
|
6469
|
+
case "error":
|
|
6470
|
+
return "error";
|
|
6471
|
+
case "context_usage_snapshot":
|
|
6472
|
+
return "context_usage_snapshot";
|
|
6473
|
+
case "run_execution_metrics":
|
|
6474
|
+
return "run_execution_metrics";
|
|
6475
|
+
case "history_summary":
|
|
6476
|
+
return "history_summary";
|
|
6477
|
+
default:
|
|
6478
|
+
return "unsupported";
|
|
6479
|
+
}
|
|
6480
|
+
}
|
|
6481
|
+
function describeRuntimeEventLifecycle(event) {
|
|
6482
|
+
const uiProjectionKind = getRuntimeEventUiProjectionKind(event);
|
|
6483
|
+
const persist = event.ephemeral !== true && !isToolProcessEvent(event) && !isSubRunTraceRuntimeEvent(event);
|
|
6484
|
+
const replayToUi = persist && isConversationUiRuntimeEvent(event) && uiProjectionKind !== "hidden" && uiProjectionKind !== "audit_envelope" && uiProjectionKind !== "final_answer_chunk" && uiProjectionKind !== "final_answer_reset" && uiProjectionKind !== "unsupported";
|
|
6485
|
+
const enterAgentContext = (() => {
|
|
6486
|
+
if (uiProjectionKind === "unsupported") {
|
|
6487
|
+
return false;
|
|
6488
|
+
}
|
|
6489
|
+
if (isSubRunTraceRuntimeEvent(event)) {
|
|
6490
|
+
return false;
|
|
6491
|
+
}
|
|
6492
|
+
if (isRunExecutionMetricsRuntimeEvent(event)) {
|
|
6493
|
+
return false;
|
|
6494
|
+
}
|
|
6495
|
+
if (isContextUsageSnapshotRuntimeEvent(event)) {
|
|
6496
|
+
return false;
|
|
6497
|
+
}
|
|
6498
|
+
if (event.type === "error") {
|
|
6499
|
+
return false;
|
|
6500
|
+
}
|
|
6501
|
+
if (isRequiresUserInteractionRuntimeEvent(event)) {
|
|
6502
|
+
return false;
|
|
6503
|
+
}
|
|
6504
|
+
if (isAuditEnvelopeRuntimeEvent(event)) {
|
|
6505
|
+
return false;
|
|
6506
|
+
}
|
|
6507
|
+
if (isControlRuntimeEvent(event)) {
|
|
6508
|
+
return false;
|
|
6509
|
+
}
|
|
6510
|
+
if (isHiddenUserInputEvent(event)) {
|
|
6511
|
+
return false;
|
|
6512
|
+
}
|
|
6513
|
+
if (isToolProcessEvent(event)) {
|
|
6514
|
+
return false;
|
|
6515
|
+
}
|
|
6516
|
+
if (event.type === "thought") {
|
|
6517
|
+
return false;
|
|
6518
|
+
}
|
|
6519
|
+
if (event.type === "final_answer_chunk") {
|
|
6520
|
+
return false;
|
|
6521
|
+
}
|
|
6522
|
+
if (event.type === "final_answer_reset") {
|
|
6523
|
+
return false;
|
|
6524
|
+
}
|
|
6525
|
+
if (isEmptyTerminalAssistantRuntimeEvent(event)) {
|
|
6526
|
+
return false;
|
|
6527
|
+
}
|
|
6528
|
+
return true;
|
|
6529
|
+
})();
|
|
6530
|
+
const realtimeChannel = (() => {
|
|
6531
|
+
switch (uiProjectionKind) {
|
|
6532
|
+
case "thought":
|
|
6533
|
+
case "final_answer":
|
|
6534
|
+
case "final_answer_chunk":
|
|
6535
|
+
case "final_answer_reset":
|
|
6536
|
+
case "tool_call_decision":
|
|
6537
|
+
case "tool_process":
|
|
6538
|
+
case "tool_output":
|
|
6539
|
+
case "requires_user_interaction":
|
|
6540
|
+
case "subrun_trace":
|
|
6541
|
+
case "error":
|
|
6542
|
+
case "context_usage_snapshot":
|
|
6543
|
+
case "run_execution_metrics":
|
|
6544
|
+
case "history_summary":
|
|
6545
|
+
return "event_bus_sse";
|
|
6546
|
+
case "audit_envelope":
|
|
6547
|
+
return "none";
|
|
6548
|
+
default:
|
|
6549
|
+
return "none";
|
|
6550
|
+
}
|
|
6551
|
+
})();
|
|
6552
|
+
return {
|
|
6553
|
+
uiProjectionKind,
|
|
6554
|
+
persist,
|
|
6555
|
+
replayToUi,
|
|
6556
|
+
enterAgentContext,
|
|
6557
|
+
realtimeChannel
|
|
6558
|
+
};
|
|
6559
|
+
}
|
|
6560
|
+
function shouldEmitRuntimeEventToSse(event) {
|
|
6561
|
+
return describeRuntimeEventLifecycle(event).realtimeChannel === "event_bus_sse";
|
|
6562
|
+
}
|
|
6563
|
+
|
|
6564
|
+
// src/runtime-kernel/graph-engine/functions/appendWorkingHistory.ts
|
|
6565
|
+
function appendWorkingHistory(history, events) {
|
|
6566
|
+
return [...history.filter(shouldPersistRuntimeEvent), ...events.filter(shouldPersistRuntimeEvent)];
|
|
6567
|
+
}
|
|
6568
|
+
|
|
6371
6569
|
// src/runtime-kernel/graph-engine/nodes/llmNode.state.ts
|
|
6372
6570
|
function assertLlmNodeStreamChunkSequence(state, answerId, seq) {
|
|
6373
6571
|
const answerChanged = state.answerId !== answerId;
|
|
@@ -6452,7 +6650,7 @@ function initLlmNodeState(init) {
|
|
|
6452
6650
|
};
|
|
6453
6651
|
}
|
|
6454
6652
|
function buildLocalPatch(nodeState, ctx) {
|
|
6455
|
-
const updatedHistory =
|
|
6653
|
+
const updatedHistory = appendWorkingHistory(ctx.history, nodeState.streamRuntimeEvents);
|
|
6456
6654
|
const patch = {
|
|
6457
6655
|
answerId: nodeState.answerId,
|
|
6458
6656
|
chunkSeq: nodeState.chunkSeq,
|
|
@@ -6605,11 +6803,11 @@ var AgentEventSchema = zod.z.discriminatedUnion("type", [
|
|
|
6605
6803
|
});
|
|
6606
6804
|
|
|
6607
6805
|
// src/runtime-kernel/events/provider-sidecar.ts
|
|
6608
|
-
var
|
|
6806
|
+
var isRecord7 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
6609
6807
|
function readMetaFromEvent(event) {
|
|
6610
|
-
if (!
|
|
6808
|
+
if (!isRecord7(event)) return void 0;
|
|
6611
6809
|
const value = event["meta"];
|
|
6612
|
-
return
|
|
6810
|
+
return isRecord7(value) ? value : void 0;
|
|
6613
6811
|
}
|
|
6614
6812
|
|
|
6615
6813
|
// src/runtime-kernel/events/agent-to-runtime.ts
|
|
@@ -6617,7 +6815,7 @@ function agentEventToRuntime(agentEvent, context, options = {}) {
|
|
|
6617
6815
|
return mapAgentEventToRuntime(agentEvent, context, options);
|
|
6618
6816
|
}
|
|
6619
6817
|
function mapAgentEventToRuntime(agentEvent, context, options) {
|
|
6620
|
-
if (
|
|
6818
|
+
if (isRecord7(agentEvent) && agentEvent["type"] === "history_summary") {
|
|
6621
6819
|
const event = RuntimeEvent.parse(agentEvent);
|
|
6622
6820
|
return context.metadata ? {
|
|
6623
6821
|
...event,
|
|
@@ -7278,7 +7476,7 @@ var LlmNode = class {
|
|
|
7278
7476
|
];
|
|
7279
7477
|
logger7.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
7280
7478
|
previousCount: history.length,
|
|
7281
|
-
nextCount:
|
|
7479
|
+
nextCount: patch.history.length,
|
|
7282
7480
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
7283
7481
|
});
|
|
7284
7482
|
logger7.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
@@ -7325,7 +7523,7 @@ var ToolModelInputResolutionError = class extends Error {
|
|
|
7325
7523
|
// src/runtime-kernel/tools/model-input/functions/parseToolModelInputDeclaration.ts
|
|
7326
7524
|
var DECLARATION_KEYS = /* @__PURE__ */ new Set(["attachments"]);
|
|
7327
7525
|
var SELECTION_KEYS = /* @__PURE__ */ new Set(["id", "uri", "label"]);
|
|
7328
|
-
function
|
|
7526
|
+
function isRecord8(value) {
|
|
7329
7527
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7330
7528
|
}
|
|
7331
7529
|
function hasOnlyKeys(value, allowed) {
|
|
@@ -7338,7 +7536,7 @@ function readTrimmedString(value, maxLength) {
|
|
|
7338
7536
|
return value === value.trim() ? value : void 0;
|
|
7339
7537
|
}
|
|
7340
7538
|
function parseSelection(value, index) {
|
|
7341
|
-
if (!
|
|
7539
|
+
if (!isRecord8(value) || !hasOnlyKeys(value, SELECTION_KEYS)) {
|
|
7342
7540
|
return { ok: false, reason: `modelInput.attachments[${index}] \u5FC5\u987B\u662F strict selection\u3002` };
|
|
7343
7541
|
}
|
|
7344
7542
|
const id = readTrimmedString(value.id, 200);
|
|
@@ -7359,7 +7557,7 @@ function parseSelection(value, index) {
|
|
|
7359
7557
|
return Object.freeze({ id, uri });
|
|
7360
7558
|
}
|
|
7361
7559
|
function parseToolModelInputDeclaration(value) {
|
|
7362
|
-
if (!
|
|
7560
|
+
if (!isRecord8(value) || !hasOnlyKeys(value, DECLARATION_KEYS)) {
|
|
7363
7561
|
return { ok: false, reason: "modelInput \u5FC5\u987B\u662F\u53EA\u5305\u542B attachments \u7684 strict \u5BF9\u8C61\u3002" };
|
|
7364
7562
|
}
|
|
7365
7563
|
if (!Array.isArray(value.attachments) || value.attachments.length === 0) {
|
|
@@ -7435,7 +7633,7 @@ function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
|
7435
7633
|
}
|
|
7436
7634
|
|
|
7437
7635
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
7438
|
-
function
|
|
7636
|
+
function isRecord9(value) {
|
|
7439
7637
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
7440
7638
|
}
|
|
7441
7639
|
function readString3(value) {
|
|
@@ -7478,7 +7676,7 @@ function resolveToolObservationGovernancePolicy(policy) {
|
|
|
7478
7676
|
}
|
|
7479
7677
|
function readObservationPreviewMeta(parsed) {
|
|
7480
7678
|
const meta = parsed["observationPreviewMeta"];
|
|
7481
|
-
if (!
|
|
7679
|
+
if (!isRecord9(meta)) {
|
|
7482
7680
|
return void 0;
|
|
7483
7681
|
}
|
|
7484
7682
|
const filename = readString3(meta["filename"]);
|
|
@@ -7496,7 +7694,7 @@ function readObservationPreviewMeta(parsed) {
|
|
|
7496
7694
|
};
|
|
7497
7695
|
}
|
|
7498
7696
|
async function applyObservationGovernance(params) {
|
|
7499
|
-
if (!params.structuredObservation || !
|
|
7697
|
+
if (!params.structuredObservation || !isRecord9(params.parsed)) {
|
|
7500
7698
|
throw new Error("Observation governance requires a validated structured tool result.");
|
|
7501
7699
|
}
|
|
7502
7700
|
const policy = resolveToolObservationGovernancePolicy(params.policy);
|
|
@@ -7588,7 +7786,7 @@ function createToolProtocolFuseError(nextCount, error) {
|
|
|
7588
7786
|
// src/runtime-kernel/graph-engine/nodes/toolNode.stateTransitions.ts
|
|
7589
7787
|
function mergeHistory(local, runtimeEvents) {
|
|
7590
7788
|
const history = parseRuntimeEvents(local.history ?? []);
|
|
7591
|
-
return
|
|
7789
|
+
return appendWorkingHistory(history, runtimeEvents);
|
|
7592
7790
|
}
|
|
7593
7791
|
function stripAnswerState(local) {
|
|
7594
7792
|
const nextLocal = { ...local };
|
|
@@ -7597,7 +7795,7 @@ function stripAnswerState(local) {
|
|
|
7597
7795
|
return nextLocal;
|
|
7598
7796
|
}
|
|
7599
7797
|
function validateStructuredToolResultContract(parsed) {
|
|
7600
|
-
if (!
|
|
7798
|
+
if (!isRecord9(parsed)) {
|
|
7601
7799
|
return { ok: false, reason: "\u5DE5\u5177\u6210\u529F\u7ED3\u679C\u5FC5\u987B\u662F JSON \u5BF9\u8C61\u3002" };
|
|
7602
7800
|
}
|
|
7603
7801
|
if (!Object.prototype.hasOwnProperty.call(parsed, "data") || parsed.data === void 0) {
|
|
@@ -7625,7 +7823,7 @@ function validateStructuredToolResultContract(parsed) {
|
|
|
7625
7823
|
};
|
|
7626
7824
|
}
|
|
7627
7825
|
function extractToolControlInfo(parsed) {
|
|
7628
|
-
if (!
|
|
7826
|
+
if (!isRecord9(parsed) || !isRecord9(parsed.control)) {
|
|
7629
7827
|
return void 0;
|
|
7630
7828
|
}
|
|
7631
7829
|
const control = parsed.control;
|
|
@@ -7649,7 +7847,7 @@ function buildRequireUserLocalState(params) {
|
|
|
7649
7847
|
...params.local,
|
|
7650
7848
|
pendingToolCalls: params.remainingCalls,
|
|
7651
7849
|
pendingInteractionSpec: {
|
|
7652
|
-
...
|
|
7850
|
+
...isRecord9(params.parsed) && isRecord9(params.parsed.control) ? params.parsed.control : {},
|
|
7653
7851
|
// wait_user 必须携带工具已校验的结构化结果,UI 才能使用正式 form identity。
|
|
7654
7852
|
form: params.parsed,
|
|
7655
7853
|
toolCallId: params.toolCallId,
|
|
@@ -7688,7 +7886,7 @@ function buildErrorLocalState(params) {
|
|
|
7688
7886
|
|
|
7689
7887
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
7690
7888
|
var logger8 = new Logger("ToolArgNormalizer");
|
|
7691
|
-
function
|
|
7889
|
+
function isRecord10(v) {
|
|
7692
7890
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
7693
7891
|
}
|
|
7694
7892
|
function tryParseJsonEncodedValue(v) {
|
|
@@ -7781,12 +7979,12 @@ function normalizeByPropertySchema(prop, v, options) {
|
|
|
7781
7979
|
}
|
|
7782
7980
|
case "object": {
|
|
7783
7981
|
const parsedValue = tryParseJsonEncodedValue(v);
|
|
7784
|
-
if (parsedValue !== v &&
|
|
7982
|
+
if (parsedValue !== v && isRecord10(parsedValue)) {
|
|
7785
7983
|
logJsonEncodedNormalization("object", options);
|
|
7786
7984
|
}
|
|
7787
|
-
if (!
|
|
7985
|
+
if (!isRecord10(parsedValue)) return parsedValue;
|
|
7788
7986
|
const selectedSchema = selectDiscriminatedObjectSchema(prop, parsedValue);
|
|
7789
|
-
if (!selectedSchema.properties || !
|
|
7987
|
+
if (!selectedSchema.properties || !isRecord10(selectedSchema.properties)) return parsedValue;
|
|
7790
7988
|
return normalizeToolArgs(
|
|
7791
7989
|
{ properties: selectedSchema.properties },
|
|
7792
7990
|
parsedValue,
|
|
@@ -7808,7 +8006,7 @@ function normalizeToolArgs(schema, args, options = {}) {
|
|
|
7808
8006
|
}
|
|
7809
8007
|
return next;
|
|
7810
8008
|
}
|
|
7811
|
-
function
|
|
8009
|
+
function isRecord11(v) {
|
|
7812
8010
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
7813
8011
|
}
|
|
7814
8012
|
function stableStringify(v) {
|
|
@@ -7818,7 +8016,7 @@ function stableStringify(v) {
|
|
|
7818
8016
|
if (t === "string") return JSON.stringify(v);
|
|
7819
8017
|
if (t === "number" || t === "boolean") return String(v);
|
|
7820
8018
|
if (Array.isArray(v)) return `[${v.map(stableStringify).join(",")}]`;
|
|
7821
|
-
if (
|
|
8019
|
+
if (isRecord11(v)) {
|
|
7822
8020
|
const keys = Object.keys(v).sort();
|
|
7823
8021
|
const parts = keys.map((k) => `${JSON.stringify(k)}:${stableStringify(v[k])}`);
|
|
7824
8022
|
return `{${parts.join(",")}}`;
|
|
@@ -7855,13 +8053,13 @@ function findCachedToolOutputByIdempotencyKey(params) {
|
|
|
7855
8053
|
if (e.tool_name !== params.toolName) continue;
|
|
7856
8054
|
if (e.status !== "success") continue;
|
|
7857
8055
|
const meta = e.metadata;
|
|
7858
|
-
if (!
|
|
8056
|
+
if (!isRecord11(meta)) continue;
|
|
7859
8057
|
const idem = meta["idempotency"];
|
|
7860
|
-
if (!
|
|
8058
|
+
if (!isRecord11(idem)) continue;
|
|
7861
8059
|
if (idem["key"] !== params.idempotencyKey) continue;
|
|
7862
8060
|
const structuredResult = { data: e.data, observation: e.observation };
|
|
7863
8061
|
const presentation = meta?.presentation;
|
|
7864
|
-
if (
|
|
8062
|
+
if (isRecord11(presentation) && presentation["media"] !== void 0) {
|
|
7865
8063
|
structuredResult["media"] = presentation["media"];
|
|
7866
8064
|
}
|
|
7867
8065
|
return {
|
|
@@ -8196,7 +8394,7 @@ function parseToolArgs(call) {
|
|
|
8196
8394
|
}
|
|
8197
8395
|
try {
|
|
8198
8396
|
const parsed = JSON.parse(rawArguments);
|
|
8199
|
-
if (!
|
|
8397
|
+
if (!isRecord9(parsed)) {
|
|
8200
8398
|
return {
|
|
8201
8399
|
ok: false,
|
|
8202
8400
|
error: "Tool arguments must decode to a JSON object."
|
|
@@ -8214,13 +8412,12 @@ function parseToolArgs(call) {
|
|
|
8214
8412
|
}
|
|
8215
8413
|
function prepareToolNodeContext(state) {
|
|
8216
8414
|
const local = state.local || {};
|
|
8217
|
-
const toolContext =
|
|
8218
|
-
if (!
|
|
8415
|
+
const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
|
|
8416
|
+
if (!isRecord9(local.toolContext)) {
|
|
8219
8417
|
local.toolContext = toolContext;
|
|
8220
8418
|
}
|
|
8221
8419
|
const conversationId = requireRuntimeIdentity(local.conversationId, "conversationId");
|
|
8222
8420
|
const turnId = requireRuntimeIdentity(local.turnId, "turnId");
|
|
8223
|
-
parseRuntimeEvents(local.history ?? []);
|
|
8224
8421
|
const existingConversationId = typeof toolContext.conversationId === "string" ? toolContext.conversationId.trim() : "";
|
|
8225
8422
|
ensureToolContextRuntimeCapability({
|
|
8226
8423
|
context: toolContext,
|
|
@@ -8488,11 +8685,11 @@ function createPendingToolCancellationEvents(params) {
|
|
|
8488
8685
|
return events;
|
|
8489
8686
|
}
|
|
8490
8687
|
function buildCancelledToolBatchLocalState(local, runtimeEvents) {
|
|
8491
|
-
const history =
|
|
8688
|
+
const history = parseRuntimeEvents(local.history ?? []);
|
|
8492
8689
|
return {
|
|
8493
8690
|
...stripAnswerState(local),
|
|
8494
8691
|
pendingToolCalls: [],
|
|
8495
|
-
history:
|
|
8692
|
+
history: appendWorkingHistory(history, runtimeEvents)
|
|
8496
8693
|
};
|
|
8497
8694
|
}
|
|
8498
8695
|
function recordToolProtocolError(params) {
|
|
@@ -8561,14 +8758,14 @@ function readHistoryEvents(local) {
|
|
|
8561
8758
|
}
|
|
8562
8759
|
function readLastSuccessfulLlmModelId(local) {
|
|
8563
8760
|
const executorLocal = local.executorLocal;
|
|
8564
|
-
if (!
|
|
8761
|
+
if (!isRecord9(executorLocal)) {
|
|
8565
8762
|
return void 0;
|
|
8566
8763
|
}
|
|
8567
8764
|
const value = executorLocal.lastSuccessfulLlmModelId;
|
|
8568
8765
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
8569
8766
|
}
|
|
8570
8767
|
function formatCapabilityError(error) {
|
|
8571
|
-
if (
|
|
8768
|
+
if (isRecord9(error)) {
|
|
8572
8769
|
const codeValue = error.errorCode ?? error.code;
|
|
8573
8770
|
const code = typeof codeValue === "string" ? codeValue.trim() : "";
|
|
8574
8771
|
const message = typeof error.message === "string" ? error.message.trim() : "";
|
|
@@ -9183,16 +9380,16 @@ var ToolNode = class {
|
|
|
9183
9380
|
};
|
|
9184
9381
|
|
|
9185
9382
|
// src/runtime-kernel/graph-engine/nodes/userNode.ts
|
|
9186
|
-
function
|
|
9383
|
+
function isRecord12(value) {
|
|
9187
9384
|
return typeof value === "object" && value !== null;
|
|
9188
9385
|
}
|
|
9189
9386
|
function isRuntimeEvent(value) {
|
|
9190
|
-
return
|
|
9387
|
+
return isRecord12(value) && typeof value.type === "string";
|
|
9191
9388
|
}
|
|
9192
9389
|
var UserNode = class {
|
|
9193
9390
|
id = "user";
|
|
9194
9391
|
async run(state) {
|
|
9195
|
-
const local =
|
|
9392
|
+
const local = isRecord12(state.local) ? state.local : {};
|
|
9196
9393
|
const newEvents = Array.isArray(local.newEvents) ? local.newEvents.filter(isRuntimeEvent) : [];
|
|
9197
9394
|
const userInputEvent = newEvents.find((event) => event.type === "user_input");
|
|
9198
9395
|
if (!userInputEvent) {
|
|
@@ -9203,7 +9400,7 @@ var UserNode = class {
|
|
|
9203
9400
|
};
|
|
9204
9401
|
|
|
9205
9402
|
// src/runtime-kernel/graph-engine/nodes/waitUserNode.ts
|
|
9206
|
-
function
|
|
9403
|
+
function isRecord13(value) {
|
|
9207
9404
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
9208
9405
|
}
|
|
9209
9406
|
function requireNonEmptyString(value, field) {
|
|
@@ -9220,10 +9417,10 @@ var WaitUserNode = class {
|
|
|
9220
9417
|
}
|
|
9221
9418
|
async run(state) {
|
|
9222
9419
|
const local = state.local ?? {};
|
|
9223
|
-
const spec =
|
|
9420
|
+
const spec = isRecord13(local.pendingInteractionSpec) ? local.pendingInteractionSpec : {};
|
|
9224
9421
|
const conversationId = requireNonEmptyString(local.conversationId, "conversationId");
|
|
9225
9422
|
const turnId = requireNonEmptyString(local.turnId, "turnId");
|
|
9226
|
-
const toolContext =
|
|
9423
|
+
const toolContext = isRecord13(local.toolContext) ? local.toolContext : {};
|
|
9227
9424
|
const runId = RunIdSchema.parse(requireNonEmptyString(toolContext.runId, "toolContext.runId"));
|
|
9228
9425
|
const parentRunId = toolContext.parentRunId === void 0 ? void 0 : RunIdSchema.parse(toolContext.parentRunId);
|
|
9229
9426
|
const toolCallId = ToolCallIdSchema.parse(
|
|
@@ -9378,199 +9575,6 @@ __export(events_exports, {
|
|
|
9378
9575
|
shouldReplayRuntimeEventToUi: () => shouldReplayRuntimeEventToUi
|
|
9379
9576
|
});
|
|
9380
9577
|
|
|
9381
|
-
// src/runtime-kernel/events/eventGovernance.ts
|
|
9382
|
-
var RUNTIME_EVENT_TYPES_NEVER_REPLAYED_TO_UI = [
|
|
9383
|
-
"audit_envelope",
|
|
9384
|
-
"final_answer_chunk",
|
|
9385
|
-
"final_answer_reset",
|
|
9386
|
-
"subrun_trace",
|
|
9387
|
-
"context_usage_snapshot"
|
|
9388
|
-
];
|
|
9389
|
-
function isRecord13(value) {
|
|
9390
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
9391
|
-
}
|
|
9392
|
-
function isToolCallDecisionEvent(event) {
|
|
9393
|
-
return event.type === "tool_call_decision";
|
|
9394
|
-
}
|
|
9395
|
-
function isToolProcessEvent(event) {
|
|
9396
|
-
return event.type === "tool_process";
|
|
9397
|
-
}
|
|
9398
|
-
function isSubRunTraceRuntimeEvent(event) {
|
|
9399
|
-
return event.type === "subrun_trace";
|
|
9400
|
-
}
|
|
9401
|
-
function isRunExecutionMetricsRuntimeEvent(event) {
|
|
9402
|
-
return event.type === "run_execution_metrics";
|
|
9403
|
-
}
|
|
9404
|
-
function isContextUsageSnapshotRuntimeEvent(event) {
|
|
9405
|
-
return event.type === "context_usage_snapshot";
|
|
9406
|
-
}
|
|
9407
|
-
function isRequiresUserInteractionRuntimeEvent(event) {
|
|
9408
|
-
return event.type === "requires_user_interaction";
|
|
9409
|
-
}
|
|
9410
|
-
function isAuditEnvelopeRuntimeEvent(event) {
|
|
9411
|
-
return event.type === "audit_envelope";
|
|
9412
|
-
}
|
|
9413
|
-
function isControlRuntimeEvent(event) {
|
|
9414
|
-
return event.type === "control";
|
|
9415
|
-
}
|
|
9416
|
-
function isHiddenUserInputEvent(event) {
|
|
9417
|
-
if (event.type !== "user_input") {
|
|
9418
|
-
return false;
|
|
9419
|
-
}
|
|
9420
|
-
const metadata = isRecord13(event.metadata) ? event.metadata : void 0;
|
|
9421
|
-
const ui = metadata && isRecord13(metadata.ui) ? metadata.ui : void 0;
|
|
9422
|
-
return ui?.presentation === "hidden";
|
|
9423
|
-
}
|
|
9424
|
-
function isEmptyTerminalAssistantRuntimeEvent(event) {
|
|
9425
|
-
if (event.type !== "thought" && event.type !== "final_answer") {
|
|
9426
|
-
return false;
|
|
9427
|
-
}
|
|
9428
|
-
return event.content.trim().length === 0;
|
|
9429
|
-
}
|
|
9430
|
-
function isConversationUiRuntimeEvent(event) {
|
|
9431
|
-
return event.lane === "foreground" && event.visibility === "conversation";
|
|
9432
|
-
}
|
|
9433
|
-
function shouldPersistRuntimeEvent(event) {
|
|
9434
|
-
return describeRuntimeEventLifecycle(event).persist;
|
|
9435
|
-
}
|
|
9436
|
-
function requirePersistableRuntimeEvent(event) {
|
|
9437
|
-
if (!shouldPersistRuntimeEvent(event)) {
|
|
9438
|
-
throw new Error(`RuntimeEvent ${event.id} (${event.type}) is not eligible for persistence.`);
|
|
9439
|
-
}
|
|
9440
|
-
return event;
|
|
9441
|
-
}
|
|
9442
|
-
function requirePersistableRoutedRuntimeEvent(event) {
|
|
9443
|
-
requirePersistableRuntimeEvent(event);
|
|
9444
|
-
return parseRoutedRuntimeEvent(event);
|
|
9445
|
-
}
|
|
9446
|
-
function shouldReplayRuntimeEventToUi(event) {
|
|
9447
|
-
return describeRuntimeEventLifecycle(event).replayToUi;
|
|
9448
|
-
}
|
|
9449
|
-
function shouldEnterAgentContext(event) {
|
|
9450
|
-
return describeRuntimeEventLifecycle(event).enterAgentContext;
|
|
9451
|
-
}
|
|
9452
|
-
function getRuntimeEventUiProjectionKind(event) {
|
|
9453
|
-
if (isHiddenUserInputEvent(event)) {
|
|
9454
|
-
return "hidden";
|
|
9455
|
-
}
|
|
9456
|
-
switch (event.type) {
|
|
9457
|
-
case "user_input":
|
|
9458
|
-
return "user_input";
|
|
9459
|
-
case "thought":
|
|
9460
|
-
return "thought";
|
|
9461
|
-
case "final_answer":
|
|
9462
|
-
return "final_answer";
|
|
9463
|
-
case "final_answer_chunk":
|
|
9464
|
-
return "final_answer_chunk";
|
|
9465
|
-
case "final_answer_reset":
|
|
9466
|
-
return "final_answer_reset";
|
|
9467
|
-
case "tool_call_decision":
|
|
9468
|
-
return "tool_call_decision";
|
|
9469
|
-
case "tool_process":
|
|
9470
|
-
return "tool_process";
|
|
9471
|
-
case "tool_output":
|
|
9472
|
-
return "tool_output";
|
|
9473
|
-
case "requires_user_interaction":
|
|
9474
|
-
return "requires_user_interaction";
|
|
9475
|
-
case "audit_envelope":
|
|
9476
|
-
return "audit_envelope";
|
|
9477
|
-
case "subrun_trace":
|
|
9478
|
-
return "subrun_trace";
|
|
9479
|
-
case "error":
|
|
9480
|
-
return "error";
|
|
9481
|
-
case "context_usage_snapshot":
|
|
9482
|
-
return "context_usage_snapshot";
|
|
9483
|
-
case "run_execution_metrics":
|
|
9484
|
-
return "run_execution_metrics";
|
|
9485
|
-
case "history_summary":
|
|
9486
|
-
return "history_summary";
|
|
9487
|
-
default:
|
|
9488
|
-
return "unsupported";
|
|
9489
|
-
}
|
|
9490
|
-
}
|
|
9491
|
-
function describeRuntimeEventLifecycle(event) {
|
|
9492
|
-
const uiProjectionKind = getRuntimeEventUiProjectionKind(event);
|
|
9493
|
-
const persist = event.ephemeral !== true && !isToolProcessEvent(event) && !isSubRunTraceRuntimeEvent(event);
|
|
9494
|
-
const replayToUi = persist && isConversationUiRuntimeEvent(event) && uiProjectionKind !== "hidden" && uiProjectionKind !== "audit_envelope" && uiProjectionKind !== "final_answer_chunk" && uiProjectionKind !== "final_answer_reset" && uiProjectionKind !== "unsupported";
|
|
9495
|
-
const enterAgentContext = (() => {
|
|
9496
|
-
if (uiProjectionKind === "unsupported") {
|
|
9497
|
-
return false;
|
|
9498
|
-
}
|
|
9499
|
-
if (isSubRunTraceRuntimeEvent(event)) {
|
|
9500
|
-
return false;
|
|
9501
|
-
}
|
|
9502
|
-
if (isRunExecutionMetricsRuntimeEvent(event)) {
|
|
9503
|
-
return false;
|
|
9504
|
-
}
|
|
9505
|
-
if (isContextUsageSnapshotRuntimeEvent(event)) {
|
|
9506
|
-
return false;
|
|
9507
|
-
}
|
|
9508
|
-
if (event.type === "error") {
|
|
9509
|
-
return false;
|
|
9510
|
-
}
|
|
9511
|
-
if (isRequiresUserInteractionRuntimeEvent(event)) {
|
|
9512
|
-
return false;
|
|
9513
|
-
}
|
|
9514
|
-
if (isAuditEnvelopeRuntimeEvent(event)) {
|
|
9515
|
-
return false;
|
|
9516
|
-
}
|
|
9517
|
-
if (isControlRuntimeEvent(event)) {
|
|
9518
|
-
return false;
|
|
9519
|
-
}
|
|
9520
|
-
if (isHiddenUserInputEvent(event)) {
|
|
9521
|
-
return false;
|
|
9522
|
-
}
|
|
9523
|
-
if (isToolProcessEvent(event)) {
|
|
9524
|
-
return false;
|
|
9525
|
-
}
|
|
9526
|
-
if (event.type === "thought") {
|
|
9527
|
-
return false;
|
|
9528
|
-
}
|
|
9529
|
-
if (event.type === "final_answer_chunk") {
|
|
9530
|
-
return false;
|
|
9531
|
-
}
|
|
9532
|
-
if (event.type === "final_answer_reset") {
|
|
9533
|
-
return false;
|
|
9534
|
-
}
|
|
9535
|
-
if (isEmptyTerminalAssistantRuntimeEvent(event)) {
|
|
9536
|
-
return false;
|
|
9537
|
-
}
|
|
9538
|
-
return true;
|
|
9539
|
-
})();
|
|
9540
|
-
const realtimeChannel = (() => {
|
|
9541
|
-
switch (uiProjectionKind) {
|
|
9542
|
-
case "thought":
|
|
9543
|
-
case "final_answer":
|
|
9544
|
-
case "final_answer_chunk":
|
|
9545
|
-
case "final_answer_reset":
|
|
9546
|
-
case "tool_call_decision":
|
|
9547
|
-
case "tool_process":
|
|
9548
|
-
case "tool_output":
|
|
9549
|
-
case "requires_user_interaction":
|
|
9550
|
-
case "subrun_trace":
|
|
9551
|
-
case "error":
|
|
9552
|
-
case "context_usage_snapshot":
|
|
9553
|
-
case "run_execution_metrics":
|
|
9554
|
-
case "history_summary":
|
|
9555
|
-
return "event_bus_sse";
|
|
9556
|
-
case "audit_envelope":
|
|
9557
|
-
return "none";
|
|
9558
|
-
default:
|
|
9559
|
-
return "none";
|
|
9560
|
-
}
|
|
9561
|
-
})();
|
|
9562
|
-
return {
|
|
9563
|
-
uiProjectionKind,
|
|
9564
|
-
persist,
|
|
9565
|
-
replayToUi,
|
|
9566
|
-
enterAgentContext,
|
|
9567
|
-
realtimeChannel
|
|
9568
|
-
};
|
|
9569
|
-
}
|
|
9570
|
-
function shouldEmitRuntimeEventToSse(event) {
|
|
9571
|
-
return describeRuntimeEventLifecycle(event).realtimeChannel === "event_bus_sse";
|
|
9572
|
-
}
|
|
9573
|
-
|
|
9574
9578
|
// src/runtime-kernel/events/finalAnswerCompletion.ts
|
|
9575
9579
|
function findTerminalFinalAnswer(events) {
|
|
9576
9580
|
for (let index = events.length - 1; index >= 0; index -= 1) {
|