@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/index.cjs
CHANGED
|
@@ -7368,6 +7368,204 @@ var GraphAgentExecutor = class {
|
|
|
7368
7368
|
}
|
|
7369
7369
|
};
|
|
7370
7370
|
|
|
7371
|
+
// src/runtime-kernel/events/eventGovernance.ts
|
|
7372
|
+
var RUNTIME_EVENT_TYPES_NEVER_REPLAYED_TO_UI = [
|
|
7373
|
+
"audit_envelope",
|
|
7374
|
+
"final_answer_chunk",
|
|
7375
|
+
"final_answer_reset",
|
|
7376
|
+
"subrun_trace",
|
|
7377
|
+
"context_usage_snapshot"
|
|
7378
|
+
];
|
|
7379
|
+
function isRecord6(value) {
|
|
7380
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
7381
|
+
}
|
|
7382
|
+
function isToolCallDecisionEvent(event) {
|
|
7383
|
+
return event.type === "tool_call_decision";
|
|
7384
|
+
}
|
|
7385
|
+
function isToolProcessEvent(event) {
|
|
7386
|
+
return event.type === "tool_process";
|
|
7387
|
+
}
|
|
7388
|
+
function isSubRunTraceRuntimeEvent(event) {
|
|
7389
|
+
return event.type === "subrun_trace";
|
|
7390
|
+
}
|
|
7391
|
+
function isRunExecutionMetricsRuntimeEvent(event) {
|
|
7392
|
+
return event.type === "run_execution_metrics";
|
|
7393
|
+
}
|
|
7394
|
+
function isContextUsageSnapshotRuntimeEvent(event) {
|
|
7395
|
+
return event.type === "context_usage_snapshot";
|
|
7396
|
+
}
|
|
7397
|
+
function isRequiresUserInteractionRuntimeEvent(event) {
|
|
7398
|
+
return event.type === "requires_user_interaction";
|
|
7399
|
+
}
|
|
7400
|
+
function isAuditEnvelopeRuntimeEvent(event) {
|
|
7401
|
+
return event.type === "audit_envelope";
|
|
7402
|
+
}
|
|
7403
|
+
function isControlRuntimeEvent(event) {
|
|
7404
|
+
return event.type === "control";
|
|
7405
|
+
}
|
|
7406
|
+
function isHiddenUserInputEvent(event) {
|
|
7407
|
+
if (event.type !== "user_input") {
|
|
7408
|
+
return false;
|
|
7409
|
+
}
|
|
7410
|
+
const metadata = isRecord6(event.metadata) ? event.metadata : void 0;
|
|
7411
|
+
const ui = metadata && isRecord6(metadata.ui) ? metadata.ui : void 0;
|
|
7412
|
+
return ui?.presentation === "hidden";
|
|
7413
|
+
}
|
|
7414
|
+
function isEmptyTerminalAssistantRuntimeEvent(event) {
|
|
7415
|
+
if (event.type !== "thought" && event.type !== "final_answer") {
|
|
7416
|
+
return false;
|
|
7417
|
+
}
|
|
7418
|
+
return event.content.trim().length === 0;
|
|
7419
|
+
}
|
|
7420
|
+
function isConversationUiRuntimeEvent(event) {
|
|
7421
|
+
return event.lane === "foreground" && event.visibility === "conversation";
|
|
7422
|
+
}
|
|
7423
|
+
function shouldPersistRuntimeEvent(event) {
|
|
7424
|
+
return describeRuntimeEventLifecycle(event).persist;
|
|
7425
|
+
}
|
|
7426
|
+
function requirePersistableRuntimeEvent(event) {
|
|
7427
|
+
if (!shouldPersistRuntimeEvent(event)) {
|
|
7428
|
+
throw new Error(`RuntimeEvent ${event.id} (${event.type}) is not eligible for persistence.`);
|
|
7429
|
+
}
|
|
7430
|
+
return event;
|
|
7431
|
+
}
|
|
7432
|
+
function requirePersistableRoutedRuntimeEvent(event) {
|
|
7433
|
+
requirePersistableRuntimeEvent(event);
|
|
7434
|
+
return parseRoutedRuntimeEvent(event);
|
|
7435
|
+
}
|
|
7436
|
+
function shouldReplayRuntimeEventToUi(event) {
|
|
7437
|
+
return describeRuntimeEventLifecycle(event).replayToUi;
|
|
7438
|
+
}
|
|
7439
|
+
function shouldEnterAgentContext(event) {
|
|
7440
|
+
return describeRuntimeEventLifecycle(event).enterAgentContext;
|
|
7441
|
+
}
|
|
7442
|
+
function getRuntimeEventUiProjectionKind(event) {
|
|
7443
|
+
if (isHiddenUserInputEvent(event)) {
|
|
7444
|
+
return "hidden";
|
|
7445
|
+
}
|
|
7446
|
+
switch (event.type) {
|
|
7447
|
+
case "user_input":
|
|
7448
|
+
return "user_input";
|
|
7449
|
+
case "thought":
|
|
7450
|
+
return "thought";
|
|
7451
|
+
case "final_answer":
|
|
7452
|
+
return "final_answer";
|
|
7453
|
+
case "final_answer_chunk":
|
|
7454
|
+
return "final_answer_chunk";
|
|
7455
|
+
case "final_answer_reset":
|
|
7456
|
+
return "final_answer_reset";
|
|
7457
|
+
case "tool_call_decision":
|
|
7458
|
+
return "tool_call_decision";
|
|
7459
|
+
case "tool_process":
|
|
7460
|
+
return "tool_process";
|
|
7461
|
+
case "tool_output":
|
|
7462
|
+
return "tool_output";
|
|
7463
|
+
case "requires_user_interaction":
|
|
7464
|
+
return "requires_user_interaction";
|
|
7465
|
+
case "audit_envelope":
|
|
7466
|
+
return "audit_envelope";
|
|
7467
|
+
case "subrun_trace":
|
|
7468
|
+
return "subrun_trace";
|
|
7469
|
+
case "error":
|
|
7470
|
+
return "error";
|
|
7471
|
+
case "context_usage_snapshot":
|
|
7472
|
+
return "context_usage_snapshot";
|
|
7473
|
+
case "run_execution_metrics":
|
|
7474
|
+
return "run_execution_metrics";
|
|
7475
|
+
case "history_summary":
|
|
7476
|
+
return "history_summary";
|
|
7477
|
+
default:
|
|
7478
|
+
return "unsupported";
|
|
7479
|
+
}
|
|
7480
|
+
}
|
|
7481
|
+
function describeRuntimeEventLifecycle(event) {
|
|
7482
|
+
const uiProjectionKind = getRuntimeEventUiProjectionKind(event);
|
|
7483
|
+
const persist = event.ephemeral !== true && !isToolProcessEvent(event) && !isSubRunTraceRuntimeEvent(event);
|
|
7484
|
+
const replayToUi = persist && isConversationUiRuntimeEvent(event) && uiProjectionKind !== "hidden" && uiProjectionKind !== "audit_envelope" && uiProjectionKind !== "final_answer_chunk" && uiProjectionKind !== "final_answer_reset" && uiProjectionKind !== "unsupported";
|
|
7485
|
+
const enterAgentContext = (() => {
|
|
7486
|
+
if (uiProjectionKind === "unsupported") {
|
|
7487
|
+
return false;
|
|
7488
|
+
}
|
|
7489
|
+
if (isSubRunTraceRuntimeEvent(event)) {
|
|
7490
|
+
return false;
|
|
7491
|
+
}
|
|
7492
|
+
if (isRunExecutionMetricsRuntimeEvent(event)) {
|
|
7493
|
+
return false;
|
|
7494
|
+
}
|
|
7495
|
+
if (isContextUsageSnapshotRuntimeEvent(event)) {
|
|
7496
|
+
return false;
|
|
7497
|
+
}
|
|
7498
|
+
if (event.type === "error") {
|
|
7499
|
+
return false;
|
|
7500
|
+
}
|
|
7501
|
+
if (isRequiresUserInteractionRuntimeEvent(event)) {
|
|
7502
|
+
return false;
|
|
7503
|
+
}
|
|
7504
|
+
if (isAuditEnvelopeRuntimeEvent(event)) {
|
|
7505
|
+
return false;
|
|
7506
|
+
}
|
|
7507
|
+
if (isControlRuntimeEvent(event)) {
|
|
7508
|
+
return false;
|
|
7509
|
+
}
|
|
7510
|
+
if (isHiddenUserInputEvent(event)) {
|
|
7511
|
+
return false;
|
|
7512
|
+
}
|
|
7513
|
+
if (isToolProcessEvent(event)) {
|
|
7514
|
+
return false;
|
|
7515
|
+
}
|
|
7516
|
+
if (event.type === "thought") {
|
|
7517
|
+
return false;
|
|
7518
|
+
}
|
|
7519
|
+
if (event.type === "final_answer_chunk") {
|
|
7520
|
+
return false;
|
|
7521
|
+
}
|
|
7522
|
+
if (event.type === "final_answer_reset") {
|
|
7523
|
+
return false;
|
|
7524
|
+
}
|
|
7525
|
+
if (isEmptyTerminalAssistantRuntimeEvent(event)) {
|
|
7526
|
+
return false;
|
|
7527
|
+
}
|
|
7528
|
+
return true;
|
|
7529
|
+
})();
|
|
7530
|
+
const realtimeChannel = (() => {
|
|
7531
|
+
switch (uiProjectionKind) {
|
|
7532
|
+
case "thought":
|
|
7533
|
+
case "final_answer":
|
|
7534
|
+
case "final_answer_chunk":
|
|
7535
|
+
case "final_answer_reset":
|
|
7536
|
+
case "tool_call_decision":
|
|
7537
|
+
case "tool_process":
|
|
7538
|
+
case "tool_output":
|
|
7539
|
+
case "requires_user_interaction":
|
|
7540
|
+
case "subrun_trace":
|
|
7541
|
+
case "error":
|
|
7542
|
+
case "context_usage_snapshot":
|
|
7543
|
+
case "run_execution_metrics":
|
|
7544
|
+
case "history_summary":
|
|
7545
|
+
return "event_bus_sse";
|
|
7546
|
+
case "audit_envelope":
|
|
7547
|
+
return "none";
|
|
7548
|
+
default:
|
|
7549
|
+
return "none";
|
|
7550
|
+
}
|
|
7551
|
+
})();
|
|
7552
|
+
return {
|
|
7553
|
+
uiProjectionKind,
|
|
7554
|
+
persist,
|
|
7555
|
+
replayToUi,
|
|
7556
|
+
enterAgentContext,
|
|
7557
|
+
realtimeChannel
|
|
7558
|
+
};
|
|
7559
|
+
}
|
|
7560
|
+
function shouldEmitRuntimeEventToSse(event) {
|
|
7561
|
+
return describeRuntimeEventLifecycle(event).realtimeChannel === "event_bus_sse";
|
|
7562
|
+
}
|
|
7563
|
+
|
|
7564
|
+
// src/runtime-kernel/graph-engine/functions/appendWorkingHistory.ts
|
|
7565
|
+
function appendWorkingHistory(history, events) {
|
|
7566
|
+
return [...history.filter(shouldPersistRuntimeEvent), ...events.filter(shouldPersistRuntimeEvent)];
|
|
7567
|
+
}
|
|
7568
|
+
|
|
7371
7569
|
// src/runtime-kernel/graph-engine/nodes/llmNode.state.ts
|
|
7372
7570
|
function assertLlmNodeStreamChunkSequence(state, answerId, seq) {
|
|
7373
7571
|
const answerChanged = state.answerId !== answerId;
|
|
@@ -7452,7 +7650,7 @@ function initLlmNodeState(init) {
|
|
|
7452
7650
|
};
|
|
7453
7651
|
}
|
|
7454
7652
|
function buildLocalPatch(nodeState, ctx) {
|
|
7455
|
-
const updatedHistory =
|
|
7653
|
+
const updatedHistory = appendWorkingHistory(ctx.history, nodeState.streamRuntimeEvents);
|
|
7456
7654
|
const patch = {
|
|
7457
7655
|
answerId: nodeState.answerId,
|
|
7458
7656
|
chunkSeq: nodeState.chunkSeq,
|
|
@@ -7605,11 +7803,11 @@ var AgentEventSchema = zod.z.discriminatedUnion("type", [
|
|
|
7605
7803
|
});
|
|
7606
7804
|
|
|
7607
7805
|
// src/runtime-kernel/events/provider-sidecar.ts
|
|
7608
|
-
var
|
|
7806
|
+
var isRecord7 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
7609
7807
|
function readMetaFromEvent(event) {
|
|
7610
|
-
if (!
|
|
7808
|
+
if (!isRecord7(event)) return void 0;
|
|
7611
7809
|
const value = event["meta"];
|
|
7612
|
-
return
|
|
7810
|
+
return isRecord7(value) ? value : void 0;
|
|
7613
7811
|
}
|
|
7614
7812
|
|
|
7615
7813
|
// src/runtime-kernel/events/agent-to-runtime.ts
|
|
@@ -7617,7 +7815,7 @@ function agentEventToRuntime(agentEvent, context, options = {}) {
|
|
|
7617
7815
|
return mapAgentEventToRuntime(agentEvent, context, options);
|
|
7618
7816
|
}
|
|
7619
7817
|
function mapAgentEventToRuntime(agentEvent, context, options) {
|
|
7620
|
-
if (
|
|
7818
|
+
if (isRecord7(agentEvent) && agentEvent["type"] === "history_summary") {
|
|
7621
7819
|
const event = RuntimeEvent.parse(agentEvent);
|
|
7622
7820
|
return context.metadata ? {
|
|
7623
7821
|
...event,
|
|
@@ -8278,7 +8476,7 @@ var LlmNode = class {
|
|
|
8278
8476
|
];
|
|
8279
8477
|
logger7.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
8280
8478
|
previousCount: history.length,
|
|
8281
|
-
nextCount:
|
|
8479
|
+
nextCount: patch.history.length,
|
|
8282
8480
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
8283
8481
|
});
|
|
8284
8482
|
logger7.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
@@ -8325,7 +8523,7 @@ var ToolModelInputResolutionError = class extends Error {
|
|
|
8325
8523
|
// src/runtime-kernel/tools/model-input/functions/parseToolModelInputDeclaration.ts
|
|
8326
8524
|
var DECLARATION_KEYS = /* @__PURE__ */ new Set(["attachments"]);
|
|
8327
8525
|
var SELECTION_KEYS = /* @__PURE__ */ new Set(["id", "uri", "label"]);
|
|
8328
|
-
function
|
|
8526
|
+
function isRecord8(value) {
|
|
8329
8527
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
8330
8528
|
}
|
|
8331
8529
|
function hasOnlyKeys(value, allowed) {
|
|
@@ -8338,7 +8536,7 @@ function readTrimmedString(value, maxLength) {
|
|
|
8338
8536
|
return value === value.trim() ? value : void 0;
|
|
8339
8537
|
}
|
|
8340
8538
|
function parseSelection(value, index) {
|
|
8341
|
-
if (!
|
|
8539
|
+
if (!isRecord8(value) || !hasOnlyKeys(value, SELECTION_KEYS)) {
|
|
8342
8540
|
return { ok: false, reason: `modelInput.attachments[${index}] \u5FC5\u987B\u662F strict selection\u3002` };
|
|
8343
8541
|
}
|
|
8344
8542
|
const id = readTrimmedString(value.id, 200);
|
|
@@ -8359,7 +8557,7 @@ function parseSelection(value, index) {
|
|
|
8359
8557
|
return Object.freeze({ id, uri });
|
|
8360
8558
|
}
|
|
8361
8559
|
function parseToolModelInputDeclaration(value) {
|
|
8362
|
-
if (!
|
|
8560
|
+
if (!isRecord8(value) || !hasOnlyKeys(value, DECLARATION_KEYS)) {
|
|
8363
8561
|
return { ok: false, reason: "modelInput \u5FC5\u987B\u662F\u53EA\u5305\u542B attachments \u7684 strict \u5BF9\u8C61\u3002" };
|
|
8364
8562
|
}
|
|
8365
8563
|
if (!Array.isArray(value.attachments) || value.attachments.length === 0) {
|
|
@@ -8435,7 +8633,7 @@ function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
|
8435
8633
|
}
|
|
8436
8634
|
|
|
8437
8635
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
8438
|
-
function
|
|
8636
|
+
function isRecord9(value) {
|
|
8439
8637
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
8440
8638
|
}
|
|
8441
8639
|
function readString3(value) {
|
|
@@ -8478,7 +8676,7 @@ function resolveToolObservationGovernancePolicy(policy) {
|
|
|
8478
8676
|
}
|
|
8479
8677
|
function readObservationPreviewMeta(parsed) {
|
|
8480
8678
|
const meta = parsed["observationPreviewMeta"];
|
|
8481
|
-
if (!
|
|
8679
|
+
if (!isRecord9(meta)) {
|
|
8482
8680
|
return void 0;
|
|
8483
8681
|
}
|
|
8484
8682
|
const filename = readString3(meta["filename"]);
|
|
@@ -8496,7 +8694,7 @@ function readObservationPreviewMeta(parsed) {
|
|
|
8496
8694
|
};
|
|
8497
8695
|
}
|
|
8498
8696
|
async function applyObservationGovernance(params) {
|
|
8499
|
-
if (!params.structuredObservation || !
|
|
8697
|
+
if (!params.structuredObservation || !isRecord9(params.parsed)) {
|
|
8500
8698
|
throw new Error("Observation governance requires a validated structured tool result.");
|
|
8501
8699
|
}
|
|
8502
8700
|
const policy = resolveToolObservationGovernancePolicy(params.policy);
|
|
@@ -8588,7 +8786,7 @@ function createToolProtocolFuseError(nextCount, error) {
|
|
|
8588
8786
|
// src/runtime-kernel/graph-engine/nodes/toolNode.stateTransitions.ts
|
|
8589
8787
|
function mergeHistory(local, runtimeEvents) {
|
|
8590
8788
|
const history = parseRuntimeEvents(local.history ?? []);
|
|
8591
|
-
return
|
|
8789
|
+
return appendWorkingHistory(history, runtimeEvents);
|
|
8592
8790
|
}
|
|
8593
8791
|
function stripAnswerState(local) {
|
|
8594
8792
|
const nextLocal = { ...local };
|
|
@@ -8597,7 +8795,7 @@ function stripAnswerState(local) {
|
|
|
8597
8795
|
return nextLocal;
|
|
8598
8796
|
}
|
|
8599
8797
|
function validateStructuredToolResultContract(parsed) {
|
|
8600
|
-
if (!
|
|
8798
|
+
if (!isRecord9(parsed)) {
|
|
8601
8799
|
return { ok: false, reason: "\u5DE5\u5177\u6210\u529F\u7ED3\u679C\u5FC5\u987B\u662F JSON \u5BF9\u8C61\u3002" };
|
|
8602
8800
|
}
|
|
8603
8801
|
if (!Object.prototype.hasOwnProperty.call(parsed, "data") || parsed.data === void 0) {
|
|
@@ -8625,7 +8823,7 @@ function validateStructuredToolResultContract(parsed) {
|
|
|
8625
8823
|
};
|
|
8626
8824
|
}
|
|
8627
8825
|
function extractToolControlInfo(parsed) {
|
|
8628
|
-
if (!
|
|
8826
|
+
if (!isRecord9(parsed) || !isRecord9(parsed.control)) {
|
|
8629
8827
|
return void 0;
|
|
8630
8828
|
}
|
|
8631
8829
|
const control = parsed.control;
|
|
@@ -8649,7 +8847,7 @@ function buildRequireUserLocalState(params) {
|
|
|
8649
8847
|
...params.local,
|
|
8650
8848
|
pendingToolCalls: params.remainingCalls,
|
|
8651
8849
|
pendingInteractionSpec: {
|
|
8652
|
-
...
|
|
8850
|
+
...isRecord9(params.parsed) && isRecord9(params.parsed.control) ? params.parsed.control : {},
|
|
8653
8851
|
// wait_user 必须携带工具已校验的结构化结果,UI 才能使用正式 form identity。
|
|
8654
8852
|
form: params.parsed,
|
|
8655
8853
|
toolCallId: params.toolCallId,
|
|
@@ -8688,7 +8886,7 @@ function buildErrorLocalState(params) {
|
|
|
8688
8886
|
|
|
8689
8887
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
8690
8888
|
var logger8 = new Logger("ToolArgNormalizer");
|
|
8691
|
-
function
|
|
8889
|
+
function isRecord10(v) {
|
|
8692
8890
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
8693
8891
|
}
|
|
8694
8892
|
function tryParseJsonEncodedValue(v) {
|
|
@@ -8781,12 +8979,12 @@ function normalizeByPropertySchema(prop, v, options) {
|
|
|
8781
8979
|
}
|
|
8782
8980
|
case "object": {
|
|
8783
8981
|
const parsedValue = tryParseJsonEncodedValue(v);
|
|
8784
|
-
if (parsedValue !== v &&
|
|
8982
|
+
if (parsedValue !== v && isRecord10(parsedValue)) {
|
|
8785
8983
|
logJsonEncodedNormalization("object", options);
|
|
8786
8984
|
}
|
|
8787
|
-
if (!
|
|
8985
|
+
if (!isRecord10(parsedValue)) return parsedValue;
|
|
8788
8986
|
const selectedSchema = selectDiscriminatedObjectSchema(prop, parsedValue);
|
|
8789
|
-
if (!selectedSchema.properties || !
|
|
8987
|
+
if (!selectedSchema.properties || !isRecord10(selectedSchema.properties)) return parsedValue;
|
|
8790
8988
|
return normalizeToolArgs(
|
|
8791
8989
|
{ properties: selectedSchema.properties },
|
|
8792
8990
|
parsedValue,
|
|
@@ -8808,7 +9006,7 @@ function normalizeToolArgs(schema, args, options = {}) {
|
|
|
8808
9006
|
}
|
|
8809
9007
|
return next;
|
|
8810
9008
|
}
|
|
8811
|
-
function
|
|
9009
|
+
function isRecord11(v) {
|
|
8812
9010
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
8813
9011
|
}
|
|
8814
9012
|
function stableStringify(v) {
|
|
@@ -8818,7 +9016,7 @@ function stableStringify(v) {
|
|
|
8818
9016
|
if (t === "string") return JSON.stringify(v);
|
|
8819
9017
|
if (t === "number" || t === "boolean") return String(v);
|
|
8820
9018
|
if (Array.isArray(v)) return `[${v.map(stableStringify).join(",")}]`;
|
|
8821
|
-
if (
|
|
9019
|
+
if (isRecord11(v)) {
|
|
8822
9020
|
const keys = Object.keys(v).sort();
|
|
8823
9021
|
const parts = keys.map((k) => `${JSON.stringify(k)}:${stableStringify(v[k])}`);
|
|
8824
9022
|
return `{${parts.join(",")}}`;
|
|
@@ -8855,13 +9053,13 @@ function findCachedToolOutputByIdempotencyKey(params) {
|
|
|
8855
9053
|
if (e.tool_name !== params.toolName) continue;
|
|
8856
9054
|
if (e.status !== "success") continue;
|
|
8857
9055
|
const meta = e.metadata;
|
|
8858
|
-
if (!
|
|
9056
|
+
if (!isRecord11(meta)) continue;
|
|
8859
9057
|
const idem = meta["idempotency"];
|
|
8860
|
-
if (!
|
|
9058
|
+
if (!isRecord11(idem)) continue;
|
|
8861
9059
|
if (idem["key"] !== params.idempotencyKey) continue;
|
|
8862
9060
|
const structuredResult = { data: e.data, observation: e.observation };
|
|
8863
9061
|
const presentation = meta?.presentation;
|
|
8864
|
-
if (
|
|
9062
|
+
if (isRecord11(presentation) && presentation["media"] !== void 0) {
|
|
8865
9063
|
structuredResult["media"] = presentation["media"];
|
|
8866
9064
|
}
|
|
8867
9065
|
return {
|
|
@@ -9196,7 +9394,7 @@ function parseToolArgs(call) {
|
|
|
9196
9394
|
}
|
|
9197
9395
|
try {
|
|
9198
9396
|
const parsed = JSON.parse(rawArguments);
|
|
9199
|
-
if (!
|
|
9397
|
+
if (!isRecord9(parsed)) {
|
|
9200
9398
|
return {
|
|
9201
9399
|
ok: false,
|
|
9202
9400
|
error: "Tool arguments must decode to a JSON object."
|
|
@@ -9214,13 +9412,12 @@ function parseToolArgs(call) {
|
|
|
9214
9412
|
}
|
|
9215
9413
|
function prepareToolNodeContext(state) {
|
|
9216
9414
|
const local = state.local || {};
|
|
9217
|
-
const toolContext =
|
|
9218
|
-
if (!
|
|
9415
|
+
const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
|
|
9416
|
+
if (!isRecord9(local.toolContext)) {
|
|
9219
9417
|
local.toolContext = toolContext;
|
|
9220
9418
|
}
|
|
9221
9419
|
const conversationId = requireRuntimeIdentity(local.conversationId, "conversationId");
|
|
9222
9420
|
const turnId = requireRuntimeIdentity(local.turnId, "turnId");
|
|
9223
|
-
parseRuntimeEvents(local.history ?? []);
|
|
9224
9421
|
const existingConversationId = typeof toolContext.conversationId === "string" ? toolContext.conversationId.trim() : "";
|
|
9225
9422
|
ensureToolContextRuntimeCapability({
|
|
9226
9423
|
context: toolContext,
|
|
@@ -9488,11 +9685,11 @@ function createPendingToolCancellationEvents(params) {
|
|
|
9488
9685
|
return events;
|
|
9489
9686
|
}
|
|
9490
9687
|
function buildCancelledToolBatchLocalState(local, runtimeEvents) {
|
|
9491
|
-
const history =
|
|
9688
|
+
const history = parseRuntimeEvents(local.history ?? []);
|
|
9492
9689
|
return {
|
|
9493
9690
|
...stripAnswerState(local),
|
|
9494
9691
|
pendingToolCalls: [],
|
|
9495
|
-
history:
|
|
9692
|
+
history: appendWorkingHistory(history, runtimeEvents)
|
|
9496
9693
|
};
|
|
9497
9694
|
}
|
|
9498
9695
|
|
|
@@ -9568,14 +9765,14 @@ function readHistoryEvents(local) {
|
|
|
9568
9765
|
}
|
|
9569
9766
|
function readLastSuccessfulLlmModelId(local) {
|
|
9570
9767
|
const executorLocal = local.executorLocal;
|
|
9571
|
-
if (!
|
|
9768
|
+
if (!isRecord9(executorLocal)) {
|
|
9572
9769
|
return void 0;
|
|
9573
9770
|
}
|
|
9574
9771
|
const value = executorLocal.lastSuccessfulLlmModelId;
|
|
9575
9772
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
9576
9773
|
}
|
|
9577
9774
|
function formatCapabilityError(error) {
|
|
9578
|
-
if (
|
|
9775
|
+
if (isRecord9(error)) {
|
|
9579
9776
|
const codeValue = error.errorCode ?? error.code;
|
|
9580
9777
|
const code = typeof codeValue === "string" ? codeValue.trim() : "";
|
|
9581
9778
|
const message = typeof error.message === "string" ? error.message.trim() : "";
|
|
@@ -10190,16 +10387,16 @@ var ToolNode = class {
|
|
|
10190
10387
|
};
|
|
10191
10388
|
|
|
10192
10389
|
// src/runtime-kernel/graph-engine/nodes/userNode.ts
|
|
10193
|
-
function
|
|
10390
|
+
function isRecord12(value) {
|
|
10194
10391
|
return typeof value === "object" && value !== null;
|
|
10195
10392
|
}
|
|
10196
10393
|
function isRuntimeEvent(value) {
|
|
10197
|
-
return
|
|
10394
|
+
return isRecord12(value) && typeof value.type === "string";
|
|
10198
10395
|
}
|
|
10199
10396
|
var UserNode = class {
|
|
10200
10397
|
id = "user";
|
|
10201
10398
|
async run(state) {
|
|
10202
|
-
const local =
|
|
10399
|
+
const local = isRecord12(state.local) ? state.local : {};
|
|
10203
10400
|
const newEvents = Array.isArray(local.newEvents) ? local.newEvents.filter(isRuntimeEvent) : [];
|
|
10204
10401
|
const userInputEvent = newEvents.find((event) => event.type === "user_input");
|
|
10205
10402
|
if (!userInputEvent) {
|
|
@@ -10210,7 +10407,7 @@ var UserNode = class {
|
|
|
10210
10407
|
};
|
|
10211
10408
|
|
|
10212
10409
|
// src/runtime-kernel/graph-engine/nodes/waitUserNode.ts
|
|
10213
|
-
function
|
|
10410
|
+
function isRecord13(value) {
|
|
10214
10411
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
10215
10412
|
}
|
|
10216
10413
|
function requireNonEmptyString(value, field) {
|
|
@@ -10227,10 +10424,10 @@ var WaitUserNode = class {
|
|
|
10227
10424
|
}
|
|
10228
10425
|
async run(state) {
|
|
10229
10426
|
const local = state.local ?? {};
|
|
10230
|
-
const spec =
|
|
10427
|
+
const spec = isRecord13(local.pendingInteractionSpec) ? local.pendingInteractionSpec : {};
|
|
10231
10428
|
const conversationId = requireNonEmptyString(local.conversationId, "conversationId");
|
|
10232
10429
|
const turnId = requireNonEmptyString(local.turnId, "turnId");
|
|
10233
|
-
const toolContext =
|
|
10430
|
+
const toolContext = isRecord13(local.toolContext) ? local.toolContext : {};
|
|
10234
10431
|
const runId = RunIdSchema.parse(requireNonEmptyString(toolContext.runId, "toolContext.runId"));
|
|
10235
10432
|
const parentRunId = toolContext.parentRunId === void 0 ? void 0 : RunIdSchema.parse(toolContext.parentRunId);
|
|
10236
10433
|
const toolCallId = ToolCallIdSchema.parse(
|
|
@@ -10385,199 +10582,6 @@ __export(events_exports, {
|
|
|
10385
10582
|
shouldReplayRuntimeEventToUi: () => shouldReplayRuntimeEventToUi
|
|
10386
10583
|
});
|
|
10387
10584
|
|
|
10388
|
-
// src/runtime-kernel/events/eventGovernance.ts
|
|
10389
|
-
var RUNTIME_EVENT_TYPES_NEVER_REPLAYED_TO_UI = [
|
|
10390
|
-
"audit_envelope",
|
|
10391
|
-
"final_answer_chunk",
|
|
10392
|
-
"final_answer_reset",
|
|
10393
|
-
"subrun_trace",
|
|
10394
|
-
"context_usage_snapshot"
|
|
10395
|
-
];
|
|
10396
|
-
function isRecord13(value) {
|
|
10397
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
10398
|
-
}
|
|
10399
|
-
function isToolCallDecisionEvent(event) {
|
|
10400
|
-
return event.type === "tool_call_decision";
|
|
10401
|
-
}
|
|
10402
|
-
function isToolProcessEvent(event) {
|
|
10403
|
-
return event.type === "tool_process";
|
|
10404
|
-
}
|
|
10405
|
-
function isSubRunTraceRuntimeEvent(event) {
|
|
10406
|
-
return event.type === "subrun_trace";
|
|
10407
|
-
}
|
|
10408
|
-
function isRunExecutionMetricsRuntimeEvent(event) {
|
|
10409
|
-
return event.type === "run_execution_metrics";
|
|
10410
|
-
}
|
|
10411
|
-
function isContextUsageSnapshotRuntimeEvent(event) {
|
|
10412
|
-
return event.type === "context_usage_snapshot";
|
|
10413
|
-
}
|
|
10414
|
-
function isRequiresUserInteractionRuntimeEvent(event) {
|
|
10415
|
-
return event.type === "requires_user_interaction";
|
|
10416
|
-
}
|
|
10417
|
-
function isAuditEnvelopeRuntimeEvent(event) {
|
|
10418
|
-
return event.type === "audit_envelope";
|
|
10419
|
-
}
|
|
10420
|
-
function isControlRuntimeEvent(event) {
|
|
10421
|
-
return event.type === "control";
|
|
10422
|
-
}
|
|
10423
|
-
function isHiddenUserInputEvent(event) {
|
|
10424
|
-
if (event.type !== "user_input") {
|
|
10425
|
-
return false;
|
|
10426
|
-
}
|
|
10427
|
-
const metadata = isRecord13(event.metadata) ? event.metadata : void 0;
|
|
10428
|
-
const ui = metadata && isRecord13(metadata.ui) ? metadata.ui : void 0;
|
|
10429
|
-
return ui?.presentation === "hidden";
|
|
10430
|
-
}
|
|
10431
|
-
function isEmptyTerminalAssistantRuntimeEvent(event) {
|
|
10432
|
-
if (event.type !== "thought" && event.type !== "final_answer") {
|
|
10433
|
-
return false;
|
|
10434
|
-
}
|
|
10435
|
-
return event.content.trim().length === 0;
|
|
10436
|
-
}
|
|
10437
|
-
function isConversationUiRuntimeEvent(event) {
|
|
10438
|
-
return event.lane === "foreground" && event.visibility === "conversation";
|
|
10439
|
-
}
|
|
10440
|
-
function shouldPersistRuntimeEvent(event) {
|
|
10441
|
-
return describeRuntimeEventLifecycle(event).persist;
|
|
10442
|
-
}
|
|
10443
|
-
function requirePersistableRuntimeEvent(event) {
|
|
10444
|
-
if (!shouldPersistRuntimeEvent(event)) {
|
|
10445
|
-
throw new Error(`RuntimeEvent ${event.id} (${event.type}) is not eligible for persistence.`);
|
|
10446
|
-
}
|
|
10447
|
-
return event;
|
|
10448
|
-
}
|
|
10449
|
-
function requirePersistableRoutedRuntimeEvent(event) {
|
|
10450
|
-
requirePersistableRuntimeEvent(event);
|
|
10451
|
-
return parseRoutedRuntimeEvent(event);
|
|
10452
|
-
}
|
|
10453
|
-
function shouldReplayRuntimeEventToUi(event) {
|
|
10454
|
-
return describeRuntimeEventLifecycle(event).replayToUi;
|
|
10455
|
-
}
|
|
10456
|
-
function shouldEnterAgentContext(event) {
|
|
10457
|
-
return describeRuntimeEventLifecycle(event).enterAgentContext;
|
|
10458
|
-
}
|
|
10459
|
-
function getRuntimeEventUiProjectionKind(event) {
|
|
10460
|
-
if (isHiddenUserInputEvent(event)) {
|
|
10461
|
-
return "hidden";
|
|
10462
|
-
}
|
|
10463
|
-
switch (event.type) {
|
|
10464
|
-
case "user_input":
|
|
10465
|
-
return "user_input";
|
|
10466
|
-
case "thought":
|
|
10467
|
-
return "thought";
|
|
10468
|
-
case "final_answer":
|
|
10469
|
-
return "final_answer";
|
|
10470
|
-
case "final_answer_chunk":
|
|
10471
|
-
return "final_answer_chunk";
|
|
10472
|
-
case "final_answer_reset":
|
|
10473
|
-
return "final_answer_reset";
|
|
10474
|
-
case "tool_call_decision":
|
|
10475
|
-
return "tool_call_decision";
|
|
10476
|
-
case "tool_process":
|
|
10477
|
-
return "tool_process";
|
|
10478
|
-
case "tool_output":
|
|
10479
|
-
return "tool_output";
|
|
10480
|
-
case "requires_user_interaction":
|
|
10481
|
-
return "requires_user_interaction";
|
|
10482
|
-
case "audit_envelope":
|
|
10483
|
-
return "audit_envelope";
|
|
10484
|
-
case "subrun_trace":
|
|
10485
|
-
return "subrun_trace";
|
|
10486
|
-
case "error":
|
|
10487
|
-
return "error";
|
|
10488
|
-
case "context_usage_snapshot":
|
|
10489
|
-
return "context_usage_snapshot";
|
|
10490
|
-
case "run_execution_metrics":
|
|
10491
|
-
return "run_execution_metrics";
|
|
10492
|
-
case "history_summary":
|
|
10493
|
-
return "history_summary";
|
|
10494
|
-
default:
|
|
10495
|
-
return "unsupported";
|
|
10496
|
-
}
|
|
10497
|
-
}
|
|
10498
|
-
function describeRuntimeEventLifecycle(event) {
|
|
10499
|
-
const uiProjectionKind = getRuntimeEventUiProjectionKind(event);
|
|
10500
|
-
const persist = event.ephemeral !== true && !isToolProcessEvent(event) && !isSubRunTraceRuntimeEvent(event);
|
|
10501
|
-
const replayToUi = persist && isConversationUiRuntimeEvent(event) && uiProjectionKind !== "hidden" && uiProjectionKind !== "audit_envelope" && uiProjectionKind !== "final_answer_chunk" && uiProjectionKind !== "final_answer_reset" && uiProjectionKind !== "unsupported";
|
|
10502
|
-
const enterAgentContext = (() => {
|
|
10503
|
-
if (uiProjectionKind === "unsupported") {
|
|
10504
|
-
return false;
|
|
10505
|
-
}
|
|
10506
|
-
if (isSubRunTraceRuntimeEvent(event)) {
|
|
10507
|
-
return false;
|
|
10508
|
-
}
|
|
10509
|
-
if (isRunExecutionMetricsRuntimeEvent(event)) {
|
|
10510
|
-
return false;
|
|
10511
|
-
}
|
|
10512
|
-
if (isContextUsageSnapshotRuntimeEvent(event)) {
|
|
10513
|
-
return false;
|
|
10514
|
-
}
|
|
10515
|
-
if (event.type === "error") {
|
|
10516
|
-
return false;
|
|
10517
|
-
}
|
|
10518
|
-
if (isRequiresUserInteractionRuntimeEvent(event)) {
|
|
10519
|
-
return false;
|
|
10520
|
-
}
|
|
10521
|
-
if (isAuditEnvelopeRuntimeEvent(event)) {
|
|
10522
|
-
return false;
|
|
10523
|
-
}
|
|
10524
|
-
if (isControlRuntimeEvent(event)) {
|
|
10525
|
-
return false;
|
|
10526
|
-
}
|
|
10527
|
-
if (isHiddenUserInputEvent(event)) {
|
|
10528
|
-
return false;
|
|
10529
|
-
}
|
|
10530
|
-
if (isToolProcessEvent(event)) {
|
|
10531
|
-
return false;
|
|
10532
|
-
}
|
|
10533
|
-
if (event.type === "thought") {
|
|
10534
|
-
return false;
|
|
10535
|
-
}
|
|
10536
|
-
if (event.type === "final_answer_chunk") {
|
|
10537
|
-
return false;
|
|
10538
|
-
}
|
|
10539
|
-
if (event.type === "final_answer_reset") {
|
|
10540
|
-
return false;
|
|
10541
|
-
}
|
|
10542
|
-
if (isEmptyTerminalAssistantRuntimeEvent(event)) {
|
|
10543
|
-
return false;
|
|
10544
|
-
}
|
|
10545
|
-
return true;
|
|
10546
|
-
})();
|
|
10547
|
-
const realtimeChannel = (() => {
|
|
10548
|
-
switch (uiProjectionKind) {
|
|
10549
|
-
case "thought":
|
|
10550
|
-
case "final_answer":
|
|
10551
|
-
case "final_answer_chunk":
|
|
10552
|
-
case "final_answer_reset":
|
|
10553
|
-
case "tool_call_decision":
|
|
10554
|
-
case "tool_process":
|
|
10555
|
-
case "tool_output":
|
|
10556
|
-
case "requires_user_interaction":
|
|
10557
|
-
case "subrun_trace":
|
|
10558
|
-
case "error":
|
|
10559
|
-
case "context_usage_snapshot":
|
|
10560
|
-
case "run_execution_metrics":
|
|
10561
|
-
case "history_summary":
|
|
10562
|
-
return "event_bus_sse";
|
|
10563
|
-
case "audit_envelope":
|
|
10564
|
-
return "none";
|
|
10565
|
-
default:
|
|
10566
|
-
return "none";
|
|
10567
|
-
}
|
|
10568
|
-
})();
|
|
10569
|
-
return {
|
|
10570
|
-
uiProjectionKind,
|
|
10571
|
-
persist,
|
|
10572
|
-
replayToUi,
|
|
10573
|
-
enterAgentContext,
|
|
10574
|
-
realtimeChannel
|
|
10575
|
-
};
|
|
10576
|
-
}
|
|
10577
|
-
function shouldEmitRuntimeEventToSse(event) {
|
|
10578
|
-
return describeRuntimeEventLifecycle(event).realtimeChannel === "event_bus_sse";
|
|
10579
|
-
}
|
|
10580
|
-
|
|
10581
10585
|
// src/runtime-kernel/events/finalAnswerCompletion.ts
|
|
10582
10586
|
function findTerminalFinalAnswer(events) {
|
|
10583
10587
|
for (let index = events.length - 1; index >= 0; index -= 1) {
|