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