@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/testkit.cjs
CHANGED
|
@@ -6556,6 +6556,204 @@ var GraphAgentExecutor = class {
|
|
|
6556
6556
|
}
|
|
6557
6557
|
};
|
|
6558
6558
|
|
|
6559
|
+
// src/runtime-kernel/events/eventGovernance.ts
|
|
6560
|
+
var RUNTIME_EVENT_TYPES_NEVER_REPLAYED_TO_UI = [
|
|
6561
|
+
"audit_envelope",
|
|
6562
|
+
"final_answer_chunk",
|
|
6563
|
+
"final_answer_reset",
|
|
6564
|
+
"subrun_trace",
|
|
6565
|
+
"context_usage_snapshot"
|
|
6566
|
+
];
|
|
6567
|
+
function isRecord6(value) {
|
|
6568
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
6569
|
+
}
|
|
6570
|
+
function isToolCallDecisionEvent(event) {
|
|
6571
|
+
return event.type === "tool_call_decision";
|
|
6572
|
+
}
|
|
6573
|
+
function isToolProcessEvent(event) {
|
|
6574
|
+
return event.type === "tool_process";
|
|
6575
|
+
}
|
|
6576
|
+
function isSubRunTraceRuntimeEvent(event) {
|
|
6577
|
+
return event.type === "subrun_trace";
|
|
6578
|
+
}
|
|
6579
|
+
function isRunExecutionMetricsRuntimeEvent(event) {
|
|
6580
|
+
return event.type === "run_execution_metrics";
|
|
6581
|
+
}
|
|
6582
|
+
function isContextUsageSnapshotRuntimeEvent(event) {
|
|
6583
|
+
return event.type === "context_usage_snapshot";
|
|
6584
|
+
}
|
|
6585
|
+
function isRequiresUserInteractionRuntimeEvent(event) {
|
|
6586
|
+
return event.type === "requires_user_interaction";
|
|
6587
|
+
}
|
|
6588
|
+
function isAuditEnvelopeRuntimeEvent(event) {
|
|
6589
|
+
return event.type === "audit_envelope";
|
|
6590
|
+
}
|
|
6591
|
+
function isControlRuntimeEvent(event) {
|
|
6592
|
+
return event.type === "control";
|
|
6593
|
+
}
|
|
6594
|
+
function isHiddenUserInputEvent(event) {
|
|
6595
|
+
if (event.type !== "user_input") {
|
|
6596
|
+
return false;
|
|
6597
|
+
}
|
|
6598
|
+
const metadata = isRecord6(event.metadata) ? event.metadata : void 0;
|
|
6599
|
+
const ui = metadata && isRecord6(metadata.ui) ? metadata.ui : void 0;
|
|
6600
|
+
return ui?.presentation === "hidden";
|
|
6601
|
+
}
|
|
6602
|
+
function isEmptyTerminalAssistantRuntimeEvent(event) {
|
|
6603
|
+
if (event.type !== "thought" && event.type !== "final_answer") {
|
|
6604
|
+
return false;
|
|
6605
|
+
}
|
|
6606
|
+
return event.content.trim().length === 0;
|
|
6607
|
+
}
|
|
6608
|
+
function isConversationUiRuntimeEvent(event) {
|
|
6609
|
+
return event.lane === "foreground" && event.visibility === "conversation";
|
|
6610
|
+
}
|
|
6611
|
+
function shouldPersistRuntimeEvent(event) {
|
|
6612
|
+
return describeRuntimeEventLifecycle(event).persist;
|
|
6613
|
+
}
|
|
6614
|
+
function requirePersistableRuntimeEvent(event) {
|
|
6615
|
+
if (!shouldPersistRuntimeEvent(event)) {
|
|
6616
|
+
throw new Error(`RuntimeEvent ${event.id} (${event.type}) is not eligible for persistence.`);
|
|
6617
|
+
}
|
|
6618
|
+
return event;
|
|
6619
|
+
}
|
|
6620
|
+
function requirePersistableRoutedRuntimeEvent(event) {
|
|
6621
|
+
requirePersistableRuntimeEvent(event);
|
|
6622
|
+
return parseRoutedRuntimeEvent(event);
|
|
6623
|
+
}
|
|
6624
|
+
function shouldReplayRuntimeEventToUi(event) {
|
|
6625
|
+
return describeRuntimeEventLifecycle(event).replayToUi;
|
|
6626
|
+
}
|
|
6627
|
+
function shouldEnterAgentContext(event) {
|
|
6628
|
+
return describeRuntimeEventLifecycle(event).enterAgentContext;
|
|
6629
|
+
}
|
|
6630
|
+
function getRuntimeEventUiProjectionKind(event) {
|
|
6631
|
+
if (isHiddenUserInputEvent(event)) {
|
|
6632
|
+
return "hidden";
|
|
6633
|
+
}
|
|
6634
|
+
switch (event.type) {
|
|
6635
|
+
case "user_input":
|
|
6636
|
+
return "user_input";
|
|
6637
|
+
case "thought":
|
|
6638
|
+
return "thought";
|
|
6639
|
+
case "final_answer":
|
|
6640
|
+
return "final_answer";
|
|
6641
|
+
case "final_answer_chunk":
|
|
6642
|
+
return "final_answer_chunk";
|
|
6643
|
+
case "final_answer_reset":
|
|
6644
|
+
return "final_answer_reset";
|
|
6645
|
+
case "tool_call_decision":
|
|
6646
|
+
return "tool_call_decision";
|
|
6647
|
+
case "tool_process":
|
|
6648
|
+
return "tool_process";
|
|
6649
|
+
case "tool_output":
|
|
6650
|
+
return "tool_output";
|
|
6651
|
+
case "requires_user_interaction":
|
|
6652
|
+
return "requires_user_interaction";
|
|
6653
|
+
case "audit_envelope":
|
|
6654
|
+
return "audit_envelope";
|
|
6655
|
+
case "subrun_trace":
|
|
6656
|
+
return "subrun_trace";
|
|
6657
|
+
case "error":
|
|
6658
|
+
return "error";
|
|
6659
|
+
case "context_usage_snapshot":
|
|
6660
|
+
return "context_usage_snapshot";
|
|
6661
|
+
case "run_execution_metrics":
|
|
6662
|
+
return "run_execution_metrics";
|
|
6663
|
+
case "history_summary":
|
|
6664
|
+
return "history_summary";
|
|
6665
|
+
default:
|
|
6666
|
+
return "unsupported";
|
|
6667
|
+
}
|
|
6668
|
+
}
|
|
6669
|
+
function describeRuntimeEventLifecycle(event) {
|
|
6670
|
+
const uiProjectionKind = getRuntimeEventUiProjectionKind(event);
|
|
6671
|
+
const persist = event.ephemeral !== true && !isToolProcessEvent(event) && !isSubRunTraceRuntimeEvent(event);
|
|
6672
|
+
const replayToUi = persist && isConversationUiRuntimeEvent(event) && uiProjectionKind !== "hidden" && uiProjectionKind !== "audit_envelope" && uiProjectionKind !== "final_answer_chunk" && uiProjectionKind !== "final_answer_reset" && uiProjectionKind !== "unsupported";
|
|
6673
|
+
const enterAgentContext = (() => {
|
|
6674
|
+
if (uiProjectionKind === "unsupported") {
|
|
6675
|
+
return false;
|
|
6676
|
+
}
|
|
6677
|
+
if (isSubRunTraceRuntimeEvent(event)) {
|
|
6678
|
+
return false;
|
|
6679
|
+
}
|
|
6680
|
+
if (isRunExecutionMetricsRuntimeEvent(event)) {
|
|
6681
|
+
return false;
|
|
6682
|
+
}
|
|
6683
|
+
if (isContextUsageSnapshotRuntimeEvent(event)) {
|
|
6684
|
+
return false;
|
|
6685
|
+
}
|
|
6686
|
+
if (event.type === "error") {
|
|
6687
|
+
return false;
|
|
6688
|
+
}
|
|
6689
|
+
if (isRequiresUserInteractionRuntimeEvent(event)) {
|
|
6690
|
+
return false;
|
|
6691
|
+
}
|
|
6692
|
+
if (isAuditEnvelopeRuntimeEvent(event)) {
|
|
6693
|
+
return false;
|
|
6694
|
+
}
|
|
6695
|
+
if (isControlRuntimeEvent(event)) {
|
|
6696
|
+
return false;
|
|
6697
|
+
}
|
|
6698
|
+
if (isHiddenUserInputEvent(event)) {
|
|
6699
|
+
return false;
|
|
6700
|
+
}
|
|
6701
|
+
if (isToolProcessEvent(event)) {
|
|
6702
|
+
return false;
|
|
6703
|
+
}
|
|
6704
|
+
if (event.type === "thought") {
|
|
6705
|
+
return false;
|
|
6706
|
+
}
|
|
6707
|
+
if (event.type === "final_answer_chunk") {
|
|
6708
|
+
return false;
|
|
6709
|
+
}
|
|
6710
|
+
if (event.type === "final_answer_reset") {
|
|
6711
|
+
return false;
|
|
6712
|
+
}
|
|
6713
|
+
if (isEmptyTerminalAssistantRuntimeEvent(event)) {
|
|
6714
|
+
return false;
|
|
6715
|
+
}
|
|
6716
|
+
return true;
|
|
6717
|
+
})();
|
|
6718
|
+
const realtimeChannel = (() => {
|
|
6719
|
+
switch (uiProjectionKind) {
|
|
6720
|
+
case "thought":
|
|
6721
|
+
case "final_answer":
|
|
6722
|
+
case "final_answer_chunk":
|
|
6723
|
+
case "final_answer_reset":
|
|
6724
|
+
case "tool_call_decision":
|
|
6725
|
+
case "tool_process":
|
|
6726
|
+
case "tool_output":
|
|
6727
|
+
case "requires_user_interaction":
|
|
6728
|
+
case "subrun_trace":
|
|
6729
|
+
case "error":
|
|
6730
|
+
case "context_usage_snapshot":
|
|
6731
|
+
case "run_execution_metrics":
|
|
6732
|
+
case "history_summary":
|
|
6733
|
+
return "event_bus_sse";
|
|
6734
|
+
case "audit_envelope":
|
|
6735
|
+
return "none";
|
|
6736
|
+
default:
|
|
6737
|
+
return "none";
|
|
6738
|
+
}
|
|
6739
|
+
})();
|
|
6740
|
+
return {
|
|
6741
|
+
uiProjectionKind,
|
|
6742
|
+
persist,
|
|
6743
|
+
replayToUi,
|
|
6744
|
+
enterAgentContext,
|
|
6745
|
+
realtimeChannel
|
|
6746
|
+
};
|
|
6747
|
+
}
|
|
6748
|
+
function shouldEmitRuntimeEventToSse(event) {
|
|
6749
|
+
return describeRuntimeEventLifecycle(event).realtimeChannel === "event_bus_sse";
|
|
6750
|
+
}
|
|
6751
|
+
|
|
6752
|
+
// src/runtime-kernel/graph-engine/functions/appendWorkingHistory.ts
|
|
6753
|
+
function appendWorkingHistory(history, events) {
|
|
6754
|
+
return [...history.filter(shouldPersistRuntimeEvent), ...events.filter(shouldPersistRuntimeEvent)];
|
|
6755
|
+
}
|
|
6756
|
+
|
|
6559
6757
|
// src/runtime-kernel/graph-engine/nodes/llmNode.state.ts
|
|
6560
6758
|
function assertLlmNodeStreamChunkSequence(state, answerId, seq) {
|
|
6561
6759
|
const answerChanged = state.answerId !== answerId;
|
|
@@ -6640,7 +6838,7 @@ function initLlmNodeState(init) {
|
|
|
6640
6838
|
};
|
|
6641
6839
|
}
|
|
6642
6840
|
function buildLocalPatch(nodeState, ctx) {
|
|
6643
|
-
const updatedHistory =
|
|
6841
|
+
const updatedHistory = appendWorkingHistory(ctx.history, nodeState.streamRuntimeEvents);
|
|
6644
6842
|
const patch = {
|
|
6645
6843
|
answerId: nodeState.answerId,
|
|
6646
6844
|
chunkSeq: nodeState.chunkSeq,
|
|
@@ -6793,11 +6991,11 @@ var AgentEventSchema = zod.z.discriminatedUnion("type", [
|
|
|
6793
6991
|
});
|
|
6794
6992
|
|
|
6795
6993
|
// src/runtime-kernel/events/provider-sidecar.ts
|
|
6796
|
-
var
|
|
6994
|
+
var isRecord7 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
6797
6995
|
function readMetaFromEvent(event) {
|
|
6798
|
-
if (!
|
|
6996
|
+
if (!isRecord7(event)) return void 0;
|
|
6799
6997
|
const value = event["meta"];
|
|
6800
|
-
return
|
|
6998
|
+
return isRecord7(value) ? value : void 0;
|
|
6801
6999
|
}
|
|
6802
7000
|
|
|
6803
7001
|
// src/runtime-kernel/events/agent-to-runtime.ts
|
|
@@ -6805,7 +7003,7 @@ function agentEventToRuntime(agentEvent, context, options = {}) {
|
|
|
6805
7003
|
return mapAgentEventToRuntime(agentEvent, context, options);
|
|
6806
7004
|
}
|
|
6807
7005
|
function mapAgentEventToRuntime(agentEvent, context, options) {
|
|
6808
|
-
if (
|
|
7006
|
+
if (isRecord7(agentEvent) && agentEvent["type"] === "history_summary") {
|
|
6809
7007
|
const event = RuntimeEvent.parse(agentEvent);
|
|
6810
7008
|
return context.metadata ? {
|
|
6811
7009
|
...event,
|
|
@@ -7466,7 +7664,7 @@ var LlmNode = class {
|
|
|
7466
7664
|
];
|
|
7467
7665
|
logger7.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
7468
7666
|
previousCount: history.length,
|
|
7469
|
-
nextCount:
|
|
7667
|
+
nextCount: patch.history.length,
|
|
7470
7668
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
7471
7669
|
});
|
|
7472
7670
|
logger7.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
@@ -7513,7 +7711,7 @@ var ToolModelInputResolutionError = class extends Error {
|
|
|
7513
7711
|
// src/runtime-kernel/tools/model-input/functions/parseToolModelInputDeclaration.ts
|
|
7514
7712
|
var DECLARATION_KEYS = /* @__PURE__ */ new Set(["attachments"]);
|
|
7515
7713
|
var SELECTION_KEYS = /* @__PURE__ */ new Set(["id", "uri", "label"]);
|
|
7516
|
-
function
|
|
7714
|
+
function isRecord8(value) {
|
|
7517
7715
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7518
7716
|
}
|
|
7519
7717
|
function hasOnlyKeys(value, allowed) {
|
|
@@ -7526,7 +7724,7 @@ function readTrimmedString(value, maxLength) {
|
|
|
7526
7724
|
return value === value.trim() ? value : void 0;
|
|
7527
7725
|
}
|
|
7528
7726
|
function parseSelection(value, index) {
|
|
7529
|
-
if (!
|
|
7727
|
+
if (!isRecord8(value) || !hasOnlyKeys(value, SELECTION_KEYS)) {
|
|
7530
7728
|
return { ok: false, reason: `modelInput.attachments[${index}] \u5FC5\u987B\u662F strict selection\u3002` };
|
|
7531
7729
|
}
|
|
7532
7730
|
const id = readTrimmedString(value.id, 200);
|
|
@@ -7547,7 +7745,7 @@ function parseSelection(value, index) {
|
|
|
7547
7745
|
return Object.freeze({ id, uri });
|
|
7548
7746
|
}
|
|
7549
7747
|
function parseToolModelInputDeclaration(value) {
|
|
7550
|
-
if (!
|
|
7748
|
+
if (!isRecord8(value) || !hasOnlyKeys(value, DECLARATION_KEYS)) {
|
|
7551
7749
|
return { ok: false, reason: "modelInput \u5FC5\u987B\u662F\u53EA\u5305\u542B attachments \u7684 strict \u5BF9\u8C61\u3002" };
|
|
7552
7750
|
}
|
|
7553
7751
|
if (!Array.isArray(value.attachments) || value.attachments.length === 0) {
|
|
@@ -7623,7 +7821,7 @@ function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
|
7623
7821
|
}
|
|
7624
7822
|
|
|
7625
7823
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
7626
|
-
function
|
|
7824
|
+
function isRecord9(value) {
|
|
7627
7825
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
7628
7826
|
}
|
|
7629
7827
|
function readString3(value) {
|
|
@@ -7666,7 +7864,7 @@ function resolveToolObservationGovernancePolicy(policy) {
|
|
|
7666
7864
|
}
|
|
7667
7865
|
function readObservationPreviewMeta(parsed) {
|
|
7668
7866
|
const meta = parsed["observationPreviewMeta"];
|
|
7669
|
-
if (!
|
|
7867
|
+
if (!isRecord9(meta)) {
|
|
7670
7868
|
return void 0;
|
|
7671
7869
|
}
|
|
7672
7870
|
const filename = readString3(meta["filename"]);
|
|
@@ -7684,7 +7882,7 @@ function readObservationPreviewMeta(parsed) {
|
|
|
7684
7882
|
};
|
|
7685
7883
|
}
|
|
7686
7884
|
async function applyObservationGovernance(params) {
|
|
7687
|
-
if (!params.structuredObservation || !
|
|
7885
|
+
if (!params.structuredObservation || !isRecord9(params.parsed)) {
|
|
7688
7886
|
throw new Error("Observation governance requires a validated structured tool result.");
|
|
7689
7887
|
}
|
|
7690
7888
|
const policy = resolveToolObservationGovernancePolicy(params.policy);
|
|
@@ -7776,7 +7974,7 @@ function createToolProtocolFuseError(nextCount, error) {
|
|
|
7776
7974
|
// src/runtime-kernel/graph-engine/nodes/toolNode.stateTransitions.ts
|
|
7777
7975
|
function mergeHistory(local, runtimeEvents) {
|
|
7778
7976
|
const history = parseRuntimeEvents(local.history ?? []);
|
|
7779
|
-
return
|
|
7977
|
+
return appendWorkingHistory(history, runtimeEvents);
|
|
7780
7978
|
}
|
|
7781
7979
|
function stripAnswerState(local) {
|
|
7782
7980
|
const nextLocal = { ...local };
|
|
@@ -7785,7 +7983,7 @@ function stripAnswerState(local) {
|
|
|
7785
7983
|
return nextLocal;
|
|
7786
7984
|
}
|
|
7787
7985
|
function validateStructuredToolResultContract(parsed) {
|
|
7788
|
-
if (!
|
|
7986
|
+
if (!isRecord9(parsed)) {
|
|
7789
7987
|
return { ok: false, reason: "\u5DE5\u5177\u6210\u529F\u7ED3\u679C\u5FC5\u987B\u662F JSON \u5BF9\u8C61\u3002" };
|
|
7790
7988
|
}
|
|
7791
7989
|
if (!Object.prototype.hasOwnProperty.call(parsed, "data") || parsed.data === void 0) {
|
|
@@ -7813,7 +8011,7 @@ function validateStructuredToolResultContract(parsed) {
|
|
|
7813
8011
|
};
|
|
7814
8012
|
}
|
|
7815
8013
|
function extractToolControlInfo(parsed) {
|
|
7816
|
-
if (!
|
|
8014
|
+
if (!isRecord9(parsed) || !isRecord9(parsed.control)) {
|
|
7817
8015
|
return void 0;
|
|
7818
8016
|
}
|
|
7819
8017
|
const control = parsed.control;
|
|
@@ -7837,7 +8035,7 @@ function buildRequireUserLocalState(params) {
|
|
|
7837
8035
|
...params.local,
|
|
7838
8036
|
pendingToolCalls: params.remainingCalls,
|
|
7839
8037
|
pendingInteractionSpec: {
|
|
7840
|
-
...
|
|
8038
|
+
...isRecord9(params.parsed) && isRecord9(params.parsed.control) ? params.parsed.control : {},
|
|
7841
8039
|
// wait_user 必须携带工具已校验的结构化结果,UI 才能使用正式 form identity。
|
|
7842
8040
|
form: params.parsed,
|
|
7843
8041
|
toolCallId: params.toolCallId,
|
|
@@ -7876,7 +8074,7 @@ function buildErrorLocalState(params) {
|
|
|
7876
8074
|
|
|
7877
8075
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
7878
8076
|
var logger8 = new Logger("ToolArgNormalizer");
|
|
7879
|
-
function
|
|
8077
|
+
function isRecord10(v) {
|
|
7880
8078
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
7881
8079
|
}
|
|
7882
8080
|
function tryParseJsonEncodedValue(v) {
|
|
@@ -7969,12 +8167,12 @@ function normalizeByPropertySchema(prop, v, options) {
|
|
|
7969
8167
|
}
|
|
7970
8168
|
case "object": {
|
|
7971
8169
|
const parsedValue = tryParseJsonEncodedValue(v);
|
|
7972
|
-
if (parsedValue !== v &&
|
|
8170
|
+
if (parsedValue !== v && isRecord10(parsedValue)) {
|
|
7973
8171
|
logJsonEncodedNormalization("object", options);
|
|
7974
8172
|
}
|
|
7975
|
-
if (!
|
|
8173
|
+
if (!isRecord10(parsedValue)) return parsedValue;
|
|
7976
8174
|
const selectedSchema = selectDiscriminatedObjectSchema(prop, parsedValue);
|
|
7977
|
-
if (!selectedSchema.properties || !
|
|
8175
|
+
if (!selectedSchema.properties || !isRecord10(selectedSchema.properties)) return parsedValue;
|
|
7978
8176
|
return normalizeToolArgs(
|
|
7979
8177
|
{ properties: selectedSchema.properties },
|
|
7980
8178
|
parsedValue,
|
|
@@ -7996,7 +8194,7 @@ function normalizeToolArgs(schema, args, options = {}) {
|
|
|
7996
8194
|
}
|
|
7997
8195
|
return next;
|
|
7998
8196
|
}
|
|
7999
|
-
function
|
|
8197
|
+
function isRecord11(v) {
|
|
8000
8198
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
8001
8199
|
}
|
|
8002
8200
|
function stableStringify(v) {
|
|
@@ -8006,7 +8204,7 @@ function stableStringify(v) {
|
|
|
8006
8204
|
if (t === "string") return JSON.stringify(v);
|
|
8007
8205
|
if (t === "number" || t === "boolean") return String(v);
|
|
8008
8206
|
if (Array.isArray(v)) return `[${v.map(stableStringify).join(",")}]`;
|
|
8009
|
-
if (
|
|
8207
|
+
if (isRecord11(v)) {
|
|
8010
8208
|
const keys = Object.keys(v).sort();
|
|
8011
8209
|
const parts = keys.map((k) => `${JSON.stringify(k)}:${stableStringify(v[k])}`);
|
|
8012
8210
|
return `{${parts.join(",")}}`;
|
|
@@ -8043,13 +8241,13 @@ function findCachedToolOutputByIdempotencyKey(params) {
|
|
|
8043
8241
|
if (e.tool_name !== params.toolName) continue;
|
|
8044
8242
|
if (e.status !== "success") continue;
|
|
8045
8243
|
const meta = e.metadata;
|
|
8046
|
-
if (!
|
|
8244
|
+
if (!isRecord11(meta)) continue;
|
|
8047
8245
|
const idem = meta["idempotency"];
|
|
8048
|
-
if (!
|
|
8246
|
+
if (!isRecord11(idem)) continue;
|
|
8049
8247
|
if (idem["key"] !== params.idempotencyKey) continue;
|
|
8050
8248
|
const structuredResult = { data: e.data, observation: e.observation };
|
|
8051
8249
|
const presentation = meta?.presentation;
|
|
8052
|
-
if (
|
|
8250
|
+
if (isRecord11(presentation) && presentation["media"] !== void 0) {
|
|
8053
8251
|
structuredResult["media"] = presentation["media"];
|
|
8054
8252
|
}
|
|
8055
8253
|
return {
|
|
@@ -8384,7 +8582,7 @@ function parseToolArgs(call) {
|
|
|
8384
8582
|
}
|
|
8385
8583
|
try {
|
|
8386
8584
|
const parsed = JSON.parse(rawArguments);
|
|
8387
|
-
if (!
|
|
8585
|
+
if (!isRecord9(parsed)) {
|
|
8388
8586
|
return {
|
|
8389
8587
|
ok: false,
|
|
8390
8588
|
error: "Tool arguments must decode to a JSON object."
|
|
@@ -8402,13 +8600,12 @@ function parseToolArgs(call) {
|
|
|
8402
8600
|
}
|
|
8403
8601
|
function prepareToolNodeContext(state) {
|
|
8404
8602
|
const local = state.local || {};
|
|
8405
|
-
const toolContext =
|
|
8406
|
-
if (!
|
|
8603
|
+
const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
|
|
8604
|
+
if (!isRecord9(local.toolContext)) {
|
|
8407
8605
|
local.toolContext = toolContext;
|
|
8408
8606
|
}
|
|
8409
8607
|
const conversationId = requireRuntimeIdentity(local.conversationId, "conversationId");
|
|
8410
8608
|
const turnId = requireRuntimeIdentity(local.turnId, "turnId");
|
|
8411
|
-
parseRuntimeEvents(local.history ?? []);
|
|
8412
8609
|
const existingConversationId = typeof toolContext.conversationId === "string" ? toolContext.conversationId.trim() : "";
|
|
8413
8610
|
ensureToolContextRuntimeCapability({
|
|
8414
8611
|
context: toolContext,
|
|
@@ -8676,11 +8873,11 @@ function createPendingToolCancellationEvents(params) {
|
|
|
8676
8873
|
return events;
|
|
8677
8874
|
}
|
|
8678
8875
|
function buildCancelledToolBatchLocalState(local, runtimeEvents) {
|
|
8679
|
-
const history =
|
|
8876
|
+
const history = parseRuntimeEvents(local.history ?? []);
|
|
8680
8877
|
return {
|
|
8681
8878
|
...stripAnswerState(local),
|
|
8682
8879
|
pendingToolCalls: [],
|
|
8683
|
-
history:
|
|
8880
|
+
history: appendWorkingHistory(history, runtimeEvents)
|
|
8684
8881
|
};
|
|
8685
8882
|
}
|
|
8686
8883
|
function recordToolProtocolError(params) {
|
|
@@ -8749,14 +8946,14 @@ function readHistoryEvents(local) {
|
|
|
8749
8946
|
}
|
|
8750
8947
|
function readLastSuccessfulLlmModelId(local) {
|
|
8751
8948
|
const executorLocal = local.executorLocal;
|
|
8752
|
-
if (!
|
|
8949
|
+
if (!isRecord9(executorLocal)) {
|
|
8753
8950
|
return void 0;
|
|
8754
8951
|
}
|
|
8755
8952
|
const value = executorLocal.lastSuccessfulLlmModelId;
|
|
8756
8953
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
8757
8954
|
}
|
|
8758
8955
|
function formatCapabilityError(error) {
|
|
8759
|
-
if (
|
|
8956
|
+
if (isRecord9(error)) {
|
|
8760
8957
|
const codeValue = error.errorCode ?? error.code;
|
|
8761
8958
|
const code = typeof codeValue === "string" ? codeValue.trim() : "";
|
|
8762
8959
|
const message = typeof error.message === "string" ? error.message.trim() : "";
|
|
@@ -9371,16 +9568,16 @@ var ToolNode = class {
|
|
|
9371
9568
|
};
|
|
9372
9569
|
|
|
9373
9570
|
// src/runtime-kernel/graph-engine/nodes/userNode.ts
|
|
9374
|
-
function
|
|
9571
|
+
function isRecord12(value) {
|
|
9375
9572
|
return typeof value === "object" && value !== null;
|
|
9376
9573
|
}
|
|
9377
9574
|
function isRuntimeEvent(value) {
|
|
9378
|
-
return
|
|
9575
|
+
return isRecord12(value) && typeof value.type === "string";
|
|
9379
9576
|
}
|
|
9380
9577
|
var UserNode = class {
|
|
9381
9578
|
id = "user";
|
|
9382
9579
|
async run(state) {
|
|
9383
|
-
const local =
|
|
9580
|
+
const local = isRecord12(state.local) ? state.local : {};
|
|
9384
9581
|
const newEvents = Array.isArray(local.newEvents) ? local.newEvents.filter(isRuntimeEvent) : [];
|
|
9385
9582
|
const userInputEvent = newEvents.find((event) => event.type === "user_input");
|
|
9386
9583
|
if (!userInputEvent) {
|
|
@@ -9391,7 +9588,7 @@ var UserNode = class {
|
|
|
9391
9588
|
};
|
|
9392
9589
|
|
|
9393
9590
|
// src/runtime-kernel/graph-engine/nodes/waitUserNode.ts
|
|
9394
|
-
function
|
|
9591
|
+
function isRecord13(value) {
|
|
9395
9592
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
9396
9593
|
}
|
|
9397
9594
|
function requireNonEmptyString(value, field) {
|
|
@@ -9408,10 +9605,10 @@ var WaitUserNode = class {
|
|
|
9408
9605
|
}
|
|
9409
9606
|
async run(state) {
|
|
9410
9607
|
const local = state.local ?? {};
|
|
9411
|
-
const spec =
|
|
9608
|
+
const spec = isRecord13(local.pendingInteractionSpec) ? local.pendingInteractionSpec : {};
|
|
9412
9609
|
const conversationId = requireNonEmptyString(local.conversationId, "conversationId");
|
|
9413
9610
|
const turnId = requireNonEmptyString(local.turnId, "turnId");
|
|
9414
|
-
const toolContext =
|
|
9611
|
+
const toolContext = isRecord13(local.toolContext) ? local.toolContext : {};
|
|
9415
9612
|
const runId = RunIdSchema.parse(requireNonEmptyString(toolContext.runId, "toolContext.runId"));
|
|
9416
9613
|
const parentRunId = toolContext.parentRunId === void 0 ? void 0 : RunIdSchema.parse(toolContext.parentRunId);
|
|
9417
9614
|
const toolCallId = ToolCallIdSchema.parse(
|
|
@@ -9566,199 +9763,6 @@ __export(events_exports, {
|
|
|
9566
9763
|
shouldReplayRuntimeEventToUi: () => shouldReplayRuntimeEventToUi
|
|
9567
9764
|
});
|
|
9568
9765
|
|
|
9569
|
-
// src/runtime-kernel/events/eventGovernance.ts
|
|
9570
|
-
var RUNTIME_EVENT_TYPES_NEVER_REPLAYED_TO_UI = [
|
|
9571
|
-
"audit_envelope",
|
|
9572
|
-
"final_answer_chunk",
|
|
9573
|
-
"final_answer_reset",
|
|
9574
|
-
"subrun_trace",
|
|
9575
|
-
"context_usage_snapshot"
|
|
9576
|
-
];
|
|
9577
|
-
function isRecord13(value) {
|
|
9578
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
9579
|
-
}
|
|
9580
|
-
function isToolCallDecisionEvent(event) {
|
|
9581
|
-
return event.type === "tool_call_decision";
|
|
9582
|
-
}
|
|
9583
|
-
function isToolProcessEvent(event) {
|
|
9584
|
-
return event.type === "tool_process";
|
|
9585
|
-
}
|
|
9586
|
-
function isSubRunTraceRuntimeEvent(event) {
|
|
9587
|
-
return event.type === "subrun_trace";
|
|
9588
|
-
}
|
|
9589
|
-
function isRunExecutionMetricsRuntimeEvent(event) {
|
|
9590
|
-
return event.type === "run_execution_metrics";
|
|
9591
|
-
}
|
|
9592
|
-
function isContextUsageSnapshotRuntimeEvent(event) {
|
|
9593
|
-
return event.type === "context_usage_snapshot";
|
|
9594
|
-
}
|
|
9595
|
-
function isRequiresUserInteractionRuntimeEvent(event) {
|
|
9596
|
-
return event.type === "requires_user_interaction";
|
|
9597
|
-
}
|
|
9598
|
-
function isAuditEnvelopeRuntimeEvent(event) {
|
|
9599
|
-
return event.type === "audit_envelope";
|
|
9600
|
-
}
|
|
9601
|
-
function isControlRuntimeEvent(event) {
|
|
9602
|
-
return event.type === "control";
|
|
9603
|
-
}
|
|
9604
|
-
function isHiddenUserInputEvent(event) {
|
|
9605
|
-
if (event.type !== "user_input") {
|
|
9606
|
-
return false;
|
|
9607
|
-
}
|
|
9608
|
-
const metadata = isRecord13(event.metadata) ? event.metadata : void 0;
|
|
9609
|
-
const ui = metadata && isRecord13(metadata.ui) ? metadata.ui : void 0;
|
|
9610
|
-
return ui?.presentation === "hidden";
|
|
9611
|
-
}
|
|
9612
|
-
function isEmptyTerminalAssistantRuntimeEvent(event) {
|
|
9613
|
-
if (event.type !== "thought" && event.type !== "final_answer") {
|
|
9614
|
-
return false;
|
|
9615
|
-
}
|
|
9616
|
-
return event.content.trim().length === 0;
|
|
9617
|
-
}
|
|
9618
|
-
function isConversationUiRuntimeEvent(event) {
|
|
9619
|
-
return event.lane === "foreground" && event.visibility === "conversation";
|
|
9620
|
-
}
|
|
9621
|
-
function shouldPersistRuntimeEvent(event) {
|
|
9622
|
-
return describeRuntimeEventLifecycle(event).persist;
|
|
9623
|
-
}
|
|
9624
|
-
function requirePersistableRuntimeEvent(event) {
|
|
9625
|
-
if (!shouldPersistRuntimeEvent(event)) {
|
|
9626
|
-
throw new Error(`RuntimeEvent ${event.id} (${event.type}) is not eligible for persistence.`);
|
|
9627
|
-
}
|
|
9628
|
-
return event;
|
|
9629
|
-
}
|
|
9630
|
-
function requirePersistableRoutedRuntimeEvent(event) {
|
|
9631
|
-
requirePersistableRuntimeEvent(event);
|
|
9632
|
-
return parseRoutedRuntimeEvent(event);
|
|
9633
|
-
}
|
|
9634
|
-
function shouldReplayRuntimeEventToUi(event) {
|
|
9635
|
-
return describeRuntimeEventLifecycle(event).replayToUi;
|
|
9636
|
-
}
|
|
9637
|
-
function shouldEnterAgentContext(event) {
|
|
9638
|
-
return describeRuntimeEventLifecycle(event).enterAgentContext;
|
|
9639
|
-
}
|
|
9640
|
-
function getRuntimeEventUiProjectionKind(event) {
|
|
9641
|
-
if (isHiddenUserInputEvent(event)) {
|
|
9642
|
-
return "hidden";
|
|
9643
|
-
}
|
|
9644
|
-
switch (event.type) {
|
|
9645
|
-
case "user_input":
|
|
9646
|
-
return "user_input";
|
|
9647
|
-
case "thought":
|
|
9648
|
-
return "thought";
|
|
9649
|
-
case "final_answer":
|
|
9650
|
-
return "final_answer";
|
|
9651
|
-
case "final_answer_chunk":
|
|
9652
|
-
return "final_answer_chunk";
|
|
9653
|
-
case "final_answer_reset":
|
|
9654
|
-
return "final_answer_reset";
|
|
9655
|
-
case "tool_call_decision":
|
|
9656
|
-
return "tool_call_decision";
|
|
9657
|
-
case "tool_process":
|
|
9658
|
-
return "tool_process";
|
|
9659
|
-
case "tool_output":
|
|
9660
|
-
return "tool_output";
|
|
9661
|
-
case "requires_user_interaction":
|
|
9662
|
-
return "requires_user_interaction";
|
|
9663
|
-
case "audit_envelope":
|
|
9664
|
-
return "audit_envelope";
|
|
9665
|
-
case "subrun_trace":
|
|
9666
|
-
return "subrun_trace";
|
|
9667
|
-
case "error":
|
|
9668
|
-
return "error";
|
|
9669
|
-
case "context_usage_snapshot":
|
|
9670
|
-
return "context_usage_snapshot";
|
|
9671
|
-
case "run_execution_metrics":
|
|
9672
|
-
return "run_execution_metrics";
|
|
9673
|
-
case "history_summary":
|
|
9674
|
-
return "history_summary";
|
|
9675
|
-
default:
|
|
9676
|
-
return "unsupported";
|
|
9677
|
-
}
|
|
9678
|
-
}
|
|
9679
|
-
function describeRuntimeEventLifecycle(event) {
|
|
9680
|
-
const uiProjectionKind = getRuntimeEventUiProjectionKind(event);
|
|
9681
|
-
const persist = event.ephemeral !== true && !isToolProcessEvent(event) && !isSubRunTraceRuntimeEvent(event);
|
|
9682
|
-
const replayToUi = persist && isConversationUiRuntimeEvent(event) && uiProjectionKind !== "hidden" && uiProjectionKind !== "audit_envelope" && uiProjectionKind !== "final_answer_chunk" && uiProjectionKind !== "final_answer_reset" && uiProjectionKind !== "unsupported";
|
|
9683
|
-
const enterAgentContext = (() => {
|
|
9684
|
-
if (uiProjectionKind === "unsupported") {
|
|
9685
|
-
return false;
|
|
9686
|
-
}
|
|
9687
|
-
if (isSubRunTraceRuntimeEvent(event)) {
|
|
9688
|
-
return false;
|
|
9689
|
-
}
|
|
9690
|
-
if (isRunExecutionMetricsRuntimeEvent(event)) {
|
|
9691
|
-
return false;
|
|
9692
|
-
}
|
|
9693
|
-
if (isContextUsageSnapshotRuntimeEvent(event)) {
|
|
9694
|
-
return false;
|
|
9695
|
-
}
|
|
9696
|
-
if (event.type === "error") {
|
|
9697
|
-
return false;
|
|
9698
|
-
}
|
|
9699
|
-
if (isRequiresUserInteractionRuntimeEvent(event)) {
|
|
9700
|
-
return false;
|
|
9701
|
-
}
|
|
9702
|
-
if (isAuditEnvelopeRuntimeEvent(event)) {
|
|
9703
|
-
return false;
|
|
9704
|
-
}
|
|
9705
|
-
if (isControlRuntimeEvent(event)) {
|
|
9706
|
-
return false;
|
|
9707
|
-
}
|
|
9708
|
-
if (isHiddenUserInputEvent(event)) {
|
|
9709
|
-
return false;
|
|
9710
|
-
}
|
|
9711
|
-
if (isToolProcessEvent(event)) {
|
|
9712
|
-
return false;
|
|
9713
|
-
}
|
|
9714
|
-
if (event.type === "thought") {
|
|
9715
|
-
return false;
|
|
9716
|
-
}
|
|
9717
|
-
if (event.type === "final_answer_chunk") {
|
|
9718
|
-
return false;
|
|
9719
|
-
}
|
|
9720
|
-
if (event.type === "final_answer_reset") {
|
|
9721
|
-
return false;
|
|
9722
|
-
}
|
|
9723
|
-
if (isEmptyTerminalAssistantRuntimeEvent(event)) {
|
|
9724
|
-
return false;
|
|
9725
|
-
}
|
|
9726
|
-
return true;
|
|
9727
|
-
})();
|
|
9728
|
-
const realtimeChannel = (() => {
|
|
9729
|
-
switch (uiProjectionKind) {
|
|
9730
|
-
case "thought":
|
|
9731
|
-
case "final_answer":
|
|
9732
|
-
case "final_answer_chunk":
|
|
9733
|
-
case "final_answer_reset":
|
|
9734
|
-
case "tool_call_decision":
|
|
9735
|
-
case "tool_process":
|
|
9736
|
-
case "tool_output":
|
|
9737
|
-
case "requires_user_interaction":
|
|
9738
|
-
case "subrun_trace":
|
|
9739
|
-
case "error":
|
|
9740
|
-
case "context_usage_snapshot":
|
|
9741
|
-
case "run_execution_metrics":
|
|
9742
|
-
case "history_summary":
|
|
9743
|
-
return "event_bus_sse";
|
|
9744
|
-
case "audit_envelope":
|
|
9745
|
-
return "none";
|
|
9746
|
-
default:
|
|
9747
|
-
return "none";
|
|
9748
|
-
}
|
|
9749
|
-
})();
|
|
9750
|
-
return {
|
|
9751
|
-
uiProjectionKind,
|
|
9752
|
-
persist,
|
|
9753
|
-
replayToUi,
|
|
9754
|
-
enterAgentContext,
|
|
9755
|
-
realtimeChannel
|
|
9756
|
-
};
|
|
9757
|
-
}
|
|
9758
|
-
function shouldEmitRuntimeEventToSse(event) {
|
|
9759
|
-
return describeRuntimeEventLifecycle(event).realtimeChannel === "event_bus_sse";
|
|
9760
|
-
}
|
|
9761
|
-
|
|
9762
9766
|
// src/runtime-kernel/events/finalAnswerCompletion.ts
|
|
9763
9767
|
function findTerminalFinalAnswer(events) {
|
|
9764
9768
|
for (let index = events.length - 1; index >= 0; index -= 1) {
|