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