@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/dist/cli.cjs CHANGED
@@ -6246,6 +6246,204 @@ var GraphAgentExecutor = class {
6246
6246
  }
6247
6247
  };
6248
6248
 
6249
+ // src/runtime-kernel/events/eventGovernance.ts
6250
+ var RUNTIME_EVENT_TYPES_NEVER_REPLAYED_TO_UI = [
6251
+ "audit_envelope",
6252
+ "final_answer_chunk",
6253
+ "final_answer_reset",
6254
+ "subrun_trace",
6255
+ "context_usage_snapshot"
6256
+ ];
6257
+ function isRecord6(value) {
6258
+ return !!value && typeof value === "object" && !Array.isArray(value);
6259
+ }
6260
+ function isToolCallDecisionEvent(event) {
6261
+ return event.type === "tool_call_decision";
6262
+ }
6263
+ function isToolProcessEvent(event) {
6264
+ return event.type === "tool_process";
6265
+ }
6266
+ function isSubRunTraceRuntimeEvent(event) {
6267
+ return event.type === "subrun_trace";
6268
+ }
6269
+ function isRunExecutionMetricsRuntimeEvent(event) {
6270
+ return event.type === "run_execution_metrics";
6271
+ }
6272
+ function isContextUsageSnapshotRuntimeEvent(event) {
6273
+ return event.type === "context_usage_snapshot";
6274
+ }
6275
+ function isRequiresUserInteractionRuntimeEvent(event) {
6276
+ return event.type === "requires_user_interaction";
6277
+ }
6278
+ function isAuditEnvelopeRuntimeEvent(event) {
6279
+ return event.type === "audit_envelope";
6280
+ }
6281
+ function isControlRuntimeEvent(event) {
6282
+ return event.type === "control";
6283
+ }
6284
+ function isHiddenUserInputEvent(event) {
6285
+ if (event.type !== "user_input") {
6286
+ return false;
6287
+ }
6288
+ const metadata = isRecord6(event.metadata) ? event.metadata : void 0;
6289
+ const ui = metadata && isRecord6(metadata.ui) ? metadata.ui : void 0;
6290
+ return ui?.presentation === "hidden";
6291
+ }
6292
+ function isEmptyTerminalAssistantRuntimeEvent(event) {
6293
+ if (event.type !== "thought" && event.type !== "final_answer") {
6294
+ return false;
6295
+ }
6296
+ return event.content.trim().length === 0;
6297
+ }
6298
+ function isConversationUiRuntimeEvent(event) {
6299
+ return event.lane === "foreground" && event.visibility === "conversation";
6300
+ }
6301
+ function shouldPersistRuntimeEvent(event) {
6302
+ return describeRuntimeEventLifecycle(event).persist;
6303
+ }
6304
+ function requirePersistableRuntimeEvent(event) {
6305
+ if (!shouldPersistRuntimeEvent(event)) {
6306
+ throw new Error(`RuntimeEvent ${event.id} (${event.type}) is not eligible for persistence.`);
6307
+ }
6308
+ return event;
6309
+ }
6310
+ function requirePersistableRoutedRuntimeEvent(event) {
6311
+ requirePersistableRuntimeEvent(event);
6312
+ return parseRoutedRuntimeEvent(event);
6313
+ }
6314
+ function shouldReplayRuntimeEventToUi(event) {
6315
+ return describeRuntimeEventLifecycle(event).replayToUi;
6316
+ }
6317
+ function shouldEnterAgentContext(event) {
6318
+ return describeRuntimeEventLifecycle(event).enterAgentContext;
6319
+ }
6320
+ function getRuntimeEventUiProjectionKind(event) {
6321
+ if (isHiddenUserInputEvent(event)) {
6322
+ return "hidden";
6323
+ }
6324
+ switch (event.type) {
6325
+ case "user_input":
6326
+ return "user_input";
6327
+ case "thought":
6328
+ return "thought";
6329
+ case "final_answer":
6330
+ return "final_answer";
6331
+ case "final_answer_chunk":
6332
+ return "final_answer_chunk";
6333
+ case "final_answer_reset":
6334
+ return "final_answer_reset";
6335
+ case "tool_call_decision":
6336
+ return "tool_call_decision";
6337
+ case "tool_process":
6338
+ return "tool_process";
6339
+ case "tool_output":
6340
+ return "tool_output";
6341
+ case "requires_user_interaction":
6342
+ return "requires_user_interaction";
6343
+ case "audit_envelope":
6344
+ return "audit_envelope";
6345
+ case "subrun_trace":
6346
+ return "subrun_trace";
6347
+ case "error":
6348
+ return "error";
6349
+ case "context_usage_snapshot":
6350
+ return "context_usage_snapshot";
6351
+ case "run_execution_metrics":
6352
+ return "run_execution_metrics";
6353
+ case "history_summary":
6354
+ return "history_summary";
6355
+ default:
6356
+ return "unsupported";
6357
+ }
6358
+ }
6359
+ function describeRuntimeEventLifecycle(event) {
6360
+ const uiProjectionKind = getRuntimeEventUiProjectionKind(event);
6361
+ const persist = event.ephemeral !== true && !isToolProcessEvent(event) && !isSubRunTraceRuntimeEvent(event);
6362
+ const replayToUi = persist && isConversationUiRuntimeEvent(event) && uiProjectionKind !== "hidden" && uiProjectionKind !== "audit_envelope" && uiProjectionKind !== "final_answer_chunk" && uiProjectionKind !== "final_answer_reset" && uiProjectionKind !== "unsupported";
6363
+ const enterAgentContext = (() => {
6364
+ if (uiProjectionKind === "unsupported") {
6365
+ return false;
6366
+ }
6367
+ if (isSubRunTraceRuntimeEvent(event)) {
6368
+ return false;
6369
+ }
6370
+ if (isRunExecutionMetricsRuntimeEvent(event)) {
6371
+ return false;
6372
+ }
6373
+ if (isContextUsageSnapshotRuntimeEvent(event)) {
6374
+ return false;
6375
+ }
6376
+ if (event.type === "error") {
6377
+ return false;
6378
+ }
6379
+ if (isRequiresUserInteractionRuntimeEvent(event)) {
6380
+ return false;
6381
+ }
6382
+ if (isAuditEnvelopeRuntimeEvent(event)) {
6383
+ return false;
6384
+ }
6385
+ if (isControlRuntimeEvent(event)) {
6386
+ return false;
6387
+ }
6388
+ if (isHiddenUserInputEvent(event)) {
6389
+ return false;
6390
+ }
6391
+ if (isToolProcessEvent(event)) {
6392
+ return false;
6393
+ }
6394
+ if (event.type === "thought") {
6395
+ return false;
6396
+ }
6397
+ if (event.type === "final_answer_chunk") {
6398
+ return false;
6399
+ }
6400
+ if (event.type === "final_answer_reset") {
6401
+ return false;
6402
+ }
6403
+ if (isEmptyTerminalAssistantRuntimeEvent(event)) {
6404
+ return false;
6405
+ }
6406
+ return true;
6407
+ })();
6408
+ const realtimeChannel = (() => {
6409
+ switch (uiProjectionKind) {
6410
+ case "thought":
6411
+ case "final_answer":
6412
+ case "final_answer_chunk":
6413
+ case "final_answer_reset":
6414
+ case "tool_call_decision":
6415
+ case "tool_process":
6416
+ case "tool_output":
6417
+ case "requires_user_interaction":
6418
+ case "subrun_trace":
6419
+ case "error":
6420
+ case "context_usage_snapshot":
6421
+ case "run_execution_metrics":
6422
+ case "history_summary":
6423
+ return "event_bus_sse";
6424
+ case "audit_envelope":
6425
+ return "none";
6426
+ default:
6427
+ return "none";
6428
+ }
6429
+ })();
6430
+ return {
6431
+ uiProjectionKind,
6432
+ persist,
6433
+ replayToUi,
6434
+ enterAgentContext,
6435
+ realtimeChannel
6436
+ };
6437
+ }
6438
+ function shouldEmitRuntimeEventToSse(event) {
6439
+ return describeRuntimeEventLifecycle(event).realtimeChannel === "event_bus_sse";
6440
+ }
6441
+
6442
+ // src/runtime-kernel/graph-engine/functions/appendWorkingHistory.ts
6443
+ function appendWorkingHistory(history, events) {
6444
+ return [...history.filter(shouldPersistRuntimeEvent), ...events.filter(shouldPersistRuntimeEvent)];
6445
+ }
6446
+
6249
6447
  // src/runtime-kernel/graph-engine/nodes/llmNode.state.ts
6250
6448
  function assertLlmNodeStreamChunkSequence(state, answerId, seq) {
6251
6449
  const answerChanged = state.answerId !== answerId;
@@ -6330,7 +6528,7 @@ function initLlmNodeState(init) {
6330
6528
  };
6331
6529
  }
6332
6530
  function buildLocalPatch(nodeState, ctx) {
6333
- const updatedHistory = [...ctx.history, ...nodeState.streamRuntimeEvents];
6531
+ const updatedHistory = appendWorkingHistory(ctx.history, nodeState.streamRuntimeEvents);
6334
6532
  const patch = {
6335
6533
  answerId: nodeState.answerId,
6336
6534
  chunkSeq: nodeState.chunkSeq,
@@ -6483,11 +6681,11 @@ var AgentEventSchema = zod.z.discriminatedUnion("type", [
6483
6681
  });
6484
6682
 
6485
6683
  // src/runtime-kernel/events/provider-sidecar.ts
6486
- var isRecord6 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
6684
+ var isRecord7 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
6487
6685
  function readMetaFromEvent(event) {
6488
- if (!isRecord6(event)) return void 0;
6686
+ if (!isRecord7(event)) return void 0;
6489
6687
  const value = event["meta"];
6490
- return isRecord6(value) ? value : void 0;
6688
+ return isRecord7(value) ? value : void 0;
6491
6689
  }
6492
6690
 
6493
6691
  // src/runtime-kernel/events/agent-to-runtime.ts
@@ -6495,7 +6693,7 @@ function agentEventToRuntime(agentEvent, context, options = {}) {
6495
6693
  return mapAgentEventToRuntime(agentEvent, context, options);
6496
6694
  }
6497
6695
  function mapAgentEventToRuntime(agentEvent, context, options) {
6498
- if (isRecord6(agentEvent) && agentEvent["type"] === "history_summary") {
6696
+ if (isRecord7(agentEvent) && agentEvent["type"] === "history_summary") {
6499
6697
  const event = RuntimeEvent.parse(agentEvent);
6500
6698
  return context.metadata ? {
6501
6699
  ...event,
@@ -7156,7 +7354,7 @@ var LlmNode = class {
7156
7354
  ];
7157
7355
  logger7.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
7158
7356
  previousCount: history.length,
7159
- nextCount: parseRuntimeEvents(patch.history).length,
7357
+ nextCount: patch.history.length,
7160
7358
  streamedEventCount: nodeState.streamRuntimeEvents.length
7161
7359
  });
7162
7360
  logger7.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
@@ -7203,7 +7401,7 @@ var ToolModelInputResolutionError = class extends Error {
7203
7401
  // src/runtime-kernel/tools/model-input/functions/parseToolModelInputDeclaration.ts
7204
7402
  var DECLARATION_KEYS = /* @__PURE__ */ new Set(["attachments"]);
7205
7403
  var SELECTION_KEYS = /* @__PURE__ */ new Set(["id", "uri", "label"]);
7206
- function isRecord7(value) {
7404
+ function isRecord8(value) {
7207
7405
  return value !== null && typeof value === "object" && !Array.isArray(value);
7208
7406
  }
7209
7407
  function hasOnlyKeys(value, allowed) {
@@ -7216,7 +7414,7 @@ function readTrimmedString(value, maxLength) {
7216
7414
  return value === value.trim() ? value : void 0;
7217
7415
  }
7218
7416
  function parseSelection(value, index) {
7219
- if (!isRecord7(value) || !hasOnlyKeys(value, SELECTION_KEYS)) {
7417
+ if (!isRecord8(value) || !hasOnlyKeys(value, SELECTION_KEYS)) {
7220
7418
  return { ok: false, reason: `modelInput.attachments[${index}] \u5FC5\u987B\u662F strict selection\u3002` };
7221
7419
  }
7222
7420
  const id = readTrimmedString(value.id, 200);
@@ -7237,7 +7435,7 @@ function parseSelection(value, index) {
7237
7435
  return Object.freeze({ id, uri });
7238
7436
  }
7239
7437
  function parseToolModelInputDeclaration(value) {
7240
- if (!isRecord7(value) || !hasOnlyKeys(value, DECLARATION_KEYS)) {
7438
+ if (!isRecord8(value) || !hasOnlyKeys(value, DECLARATION_KEYS)) {
7241
7439
  return { ok: false, reason: "modelInput \u5FC5\u987B\u662F\u53EA\u5305\u542B attachments \u7684 strict \u5BF9\u8C61\u3002" };
7242
7440
  }
7243
7441
  if (!Array.isArray(value.attachments) || value.attachments.length === 0) {
@@ -7313,7 +7511,7 @@ function resolveFinalAnswerFromToolControl(finalAnswer) {
7313
7511
  }
7314
7512
 
7315
7513
  // src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
7316
- function isRecord8(value) {
7514
+ function isRecord9(value) {
7317
7515
  return !!value && typeof value === "object" && !Array.isArray(value);
7318
7516
  }
7319
7517
  function readString3(value) {
@@ -7356,7 +7554,7 @@ function resolveToolObservationGovernancePolicy(policy) {
7356
7554
  }
7357
7555
  function readObservationPreviewMeta(parsed) {
7358
7556
  const meta = parsed["observationPreviewMeta"];
7359
- if (!isRecord8(meta)) {
7557
+ if (!isRecord9(meta)) {
7360
7558
  return void 0;
7361
7559
  }
7362
7560
  const filename = readString3(meta["filename"]);
@@ -7374,7 +7572,7 @@ function readObservationPreviewMeta(parsed) {
7374
7572
  };
7375
7573
  }
7376
7574
  async function applyObservationGovernance(params) {
7377
- if (!params.structuredObservation || !isRecord8(params.parsed)) {
7575
+ if (!params.structuredObservation || !isRecord9(params.parsed)) {
7378
7576
  throw new Error("Observation governance requires a validated structured tool result.");
7379
7577
  }
7380
7578
  const policy = resolveToolObservationGovernancePolicy(params.policy);
@@ -7466,7 +7664,7 @@ function createToolProtocolFuseError(nextCount, error) {
7466
7664
  // src/runtime-kernel/graph-engine/nodes/toolNode.stateTransitions.ts
7467
7665
  function mergeHistory(local, runtimeEvents) {
7468
7666
  const history = parseRuntimeEvents(local.history ?? []);
7469
- return [...history, ...runtimeEvents];
7667
+ return appendWorkingHistory(history, runtimeEvents);
7470
7668
  }
7471
7669
  function stripAnswerState(local) {
7472
7670
  const nextLocal = { ...local };
@@ -7475,7 +7673,7 @@ function stripAnswerState(local) {
7475
7673
  return nextLocal;
7476
7674
  }
7477
7675
  function validateStructuredToolResultContract(parsed) {
7478
- if (!isRecord8(parsed)) {
7676
+ if (!isRecord9(parsed)) {
7479
7677
  return { ok: false, reason: "\u5DE5\u5177\u6210\u529F\u7ED3\u679C\u5FC5\u987B\u662F JSON \u5BF9\u8C61\u3002" };
7480
7678
  }
7481
7679
  if (!Object.prototype.hasOwnProperty.call(parsed, "data") || parsed.data === void 0) {
@@ -7503,7 +7701,7 @@ function validateStructuredToolResultContract(parsed) {
7503
7701
  };
7504
7702
  }
7505
7703
  function extractToolControlInfo(parsed) {
7506
- if (!isRecord8(parsed) || !isRecord8(parsed.control)) {
7704
+ if (!isRecord9(parsed) || !isRecord9(parsed.control)) {
7507
7705
  return void 0;
7508
7706
  }
7509
7707
  const control = parsed.control;
@@ -7527,7 +7725,7 @@ function buildRequireUserLocalState(params) {
7527
7725
  ...params.local,
7528
7726
  pendingToolCalls: params.remainingCalls,
7529
7727
  pendingInteractionSpec: {
7530
- ...isRecord8(params.parsed) && isRecord8(params.parsed.control) ? params.parsed.control : {},
7728
+ ...isRecord9(params.parsed) && isRecord9(params.parsed.control) ? params.parsed.control : {},
7531
7729
  // wait_user 必须携带工具已校验的结构化结果,UI 才能使用正式 form identity。
7532
7730
  form: params.parsed,
7533
7731
  toolCallId: params.toolCallId,
@@ -7566,7 +7764,7 @@ function buildErrorLocalState(params) {
7566
7764
 
7567
7765
  // src/runtime-kernel/tools/argNormalizer.ts
7568
7766
  var logger8 = new Logger("ToolArgNormalizer");
7569
- function isRecord9(v) {
7767
+ function isRecord10(v) {
7570
7768
  return !!v && typeof v === "object" && !Array.isArray(v);
7571
7769
  }
7572
7770
  function tryParseJsonEncodedValue(v) {
@@ -7659,12 +7857,12 @@ function normalizeByPropertySchema(prop, v, options) {
7659
7857
  }
7660
7858
  case "object": {
7661
7859
  const parsedValue = tryParseJsonEncodedValue(v);
7662
- if (parsedValue !== v && isRecord9(parsedValue)) {
7860
+ if (parsedValue !== v && isRecord10(parsedValue)) {
7663
7861
  logJsonEncodedNormalization("object", options);
7664
7862
  }
7665
- if (!isRecord9(parsedValue)) return parsedValue;
7863
+ if (!isRecord10(parsedValue)) return parsedValue;
7666
7864
  const selectedSchema = selectDiscriminatedObjectSchema(prop, parsedValue);
7667
- if (!selectedSchema.properties || !isRecord9(selectedSchema.properties)) return parsedValue;
7865
+ if (!selectedSchema.properties || !isRecord10(selectedSchema.properties)) return parsedValue;
7668
7866
  return normalizeToolArgs(
7669
7867
  { properties: selectedSchema.properties },
7670
7868
  parsedValue,
@@ -7686,7 +7884,7 @@ function normalizeToolArgs(schema, args, options = {}) {
7686
7884
  }
7687
7885
  return next;
7688
7886
  }
7689
- function isRecord10(v) {
7887
+ function isRecord11(v) {
7690
7888
  return !!v && typeof v === "object" && !Array.isArray(v);
7691
7889
  }
7692
7890
  function stableStringify(v) {
@@ -7696,7 +7894,7 @@ function stableStringify(v) {
7696
7894
  if (t === "string") return JSON.stringify(v);
7697
7895
  if (t === "number" || t === "boolean") return String(v);
7698
7896
  if (Array.isArray(v)) return `[${v.map(stableStringify).join(",")}]`;
7699
- if (isRecord10(v)) {
7897
+ if (isRecord11(v)) {
7700
7898
  const keys = Object.keys(v).sort();
7701
7899
  const parts = keys.map((k) => `${JSON.stringify(k)}:${stableStringify(v[k])}`);
7702
7900
  return `{${parts.join(",")}}`;
@@ -7733,13 +7931,13 @@ function findCachedToolOutputByIdempotencyKey(params) {
7733
7931
  if (e.tool_name !== params.toolName) continue;
7734
7932
  if (e.status !== "success") continue;
7735
7933
  const meta = e.metadata;
7736
- if (!isRecord10(meta)) continue;
7934
+ if (!isRecord11(meta)) continue;
7737
7935
  const idem = meta["idempotency"];
7738
- if (!isRecord10(idem)) continue;
7936
+ if (!isRecord11(idem)) continue;
7739
7937
  if (idem["key"] !== params.idempotencyKey) continue;
7740
7938
  const structuredResult = { data: e.data, observation: e.observation };
7741
7939
  const presentation = meta?.presentation;
7742
- if (isRecord10(presentation) && presentation["media"] !== void 0) {
7940
+ if (isRecord11(presentation) && presentation["media"] !== void 0) {
7743
7941
  structuredResult["media"] = presentation["media"];
7744
7942
  }
7745
7943
  return {
@@ -8013,7 +8211,7 @@ function parseToolArgs(call) {
8013
8211
  }
8014
8212
  try {
8015
8213
  const parsed = JSON.parse(rawArguments);
8016
- if (!isRecord8(parsed)) {
8214
+ if (!isRecord9(parsed)) {
8017
8215
  return {
8018
8216
  ok: false,
8019
8217
  error: "Tool arguments must decode to a JSON object."
@@ -8031,13 +8229,12 @@ function parseToolArgs(call) {
8031
8229
  }
8032
8230
  function prepareToolNodeContext(state) {
8033
8231
  const local = state.local || {};
8034
- const toolContext = isRecord8(local.toolContext) ? local.toolContext : {};
8035
- if (!isRecord8(local.toolContext)) {
8232
+ const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
8233
+ if (!isRecord9(local.toolContext)) {
8036
8234
  local.toolContext = toolContext;
8037
8235
  }
8038
8236
  const conversationId = requireRuntimeIdentity(local.conversationId, "conversationId");
8039
8237
  const turnId = requireRuntimeIdentity(local.turnId, "turnId");
8040
- parseRuntimeEvents(local.history ?? []);
8041
8238
  const existingConversationId = typeof toolContext.conversationId === "string" ? toolContext.conversationId.trim() : "";
8042
8239
  ensureToolContextRuntimeCapability({
8043
8240
  context: toolContext,
@@ -8305,11 +8502,11 @@ function createPendingToolCancellationEvents(params) {
8305
8502
  return events;
8306
8503
  }
8307
8504
  function buildCancelledToolBatchLocalState(local, runtimeEvents) {
8308
- const history = Array.isArray(local.history) ? local.history : [];
8505
+ const history = parseRuntimeEvents(local.history ?? []);
8309
8506
  return {
8310
8507
  ...stripAnswerState(local),
8311
8508
  pendingToolCalls: [],
8312
- history: [...history, ...runtimeEvents]
8509
+ history: appendWorkingHistory(history, runtimeEvents)
8313
8510
  };
8314
8511
  }
8315
8512
  function recordToolProtocolError(params) {
@@ -8378,14 +8575,14 @@ function readHistoryEvents(local) {
8378
8575
  }
8379
8576
  function readLastSuccessfulLlmModelId(local) {
8380
8577
  const executorLocal = local.executorLocal;
8381
- if (!isRecord8(executorLocal)) {
8578
+ if (!isRecord9(executorLocal)) {
8382
8579
  return void 0;
8383
8580
  }
8384
8581
  const value = executorLocal.lastSuccessfulLlmModelId;
8385
8582
  return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
8386
8583
  }
8387
8584
  function formatCapabilityError(error) {
8388
- if (isRecord8(error)) {
8585
+ if (isRecord9(error)) {
8389
8586
  const codeValue = error.errorCode ?? error.code;
8390
8587
  const code = typeof codeValue === "string" ? codeValue.trim() : "";
8391
8588
  const message = typeof error.message === "string" ? error.message.trim() : "";
@@ -9000,16 +9197,16 @@ var ToolNode = class {
9000
9197
  };
9001
9198
 
9002
9199
  // src/runtime-kernel/graph-engine/nodes/userNode.ts
9003
- function isRecord11(value) {
9200
+ function isRecord12(value) {
9004
9201
  return typeof value === "object" && value !== null;
9005
9202
  }
9006
9203
  function isRuntimeEvent(value) {
9007
- return isRecord11(value) && typeof value.type === "string";
9204
+ return isRecord12(value) && typeof value.type === "string";
9008
9205
  }
9009
9206
  var UserNode = class {
9010
9207
  id = "user";
9011
9208
  async run(state) {
9012
- const local = isRecord11(state.local) ? state.local : {};
9209
+ const local = isRecord12(state.local) ? state.local : {};
9013
9210
  const newEvents = Array.isArray(local.newEvents) ? local.newEvents.filter(isRuntimeEvent) : [];
9014
9211
  const userInputEvent = newEvents.find((event) => event.type === "user_input");
9015
9212
  if (!userInputEvent) {
@@ -9020,7 +9217,7 @@ var UserNode = class {
9020
9217
  };
9021
9218
 
9022
9219
  // src/runtime-kernel/graph-engine/nodes/waitUserNode.ts
9023
- function isRecord12(value) {
9220
+ function isRecord13(value) {
9024
9221
  return !!value && typeof value === "object" && !Array.isArray(value);
9025
9222
  }
9026
9223
  function requireNonEmptyString(value, field) {
@@ -9037,10 +9234,10 @@ var WaitUserNode = class {
9037
9234
  }
9038
9235
  async run(state) {
9039
9236
  const local = state.local ?? {};
9040
- const spec = isRecord12(local.pendingInteractionSpec) ? local.pendingInteractionSpec : {};
9237
+ const spec = isRecord13(local.pendingInteractionSpec) ? local.pendingInteractionSpec : {};
9041
9238
  const conversationId = requireNonEmptyString(local.conversationId, "conversationId");
9042
9239
  const turnId = requireNonEmptyString(local.turnId, "turnId");
9043
- const toolContext = isRecord12(local.toolContext) ? local.toolContext : {};
9240
+ const toolContext = isRecord13(local.toolContext) ? local.toolContext : {};
9044
9241
  const runId = RunIdSchema.parse(requireNonEmptyString(toolContext.runId, "toolContext.runId"));
9045
9242
  const parentRunId = toolContext.parentRunId === void 0 ? void 0 : RunIdSchema.parse(toolContext.parentRunId);
9046
9243
  const toolCallId = ToolCallIdSchema.parse(
@@ -9195,199 +9392,6 @@ __export(events_exports, {
9195
9392
  shouldReplayRuntimeEventToUi: () => shouldReplayRuntimeEventToUi
9196
9393
  });
9197
9394
 
9198
- // src/runtime-kernel/events/eventGovernance.ts
9199
- var RUNTIME_EVENT_TYPES_NEVER_REPLAYED_TO_UI = [
9200
- "audit_envelope",
9201
- "final_answer_chunk",
9202
- "final_answer_reset",
9203
- "subrun_trace",
9204
- "context_usage_snapshot"
9205
- ];
9206
- function isRecord13(value) {
9207
- return !!value && typeof value === "object" && !Array.isArray(value);
9208
- }
9209
- function isToolCallDecisionEvent(event) {
9210
- return event.type === "tool_call_decision";
9211
- }
9212
- function isToolProcessEvent(event) {
9213
- return event.type === "tool_process";
9214
- }
9215
- function isSubRunTraceRuntimeEvent(event) {
9216
- return event.type === "subrun_trace";
9217
- }
9218
- function isRunExecutionMetricsRuntimeEvent(event) {
9219
- return event.type === "run_execution_metrics";
9220
- }
9221
- function isContextUsageSnapshotRuntimeEvent(event) {
9222
- return event.type === "context_usage_snapshot";
9223
- }
9224
- function isRequiresUserInteractionRuntimeEvent(event) {
9225
- return event.type === "requires_user_interaction";
9226
- }
9227
- function isAuditEnvelopeRuntimeEvent(event) {
9228
- return event.type === "audit_envelope";
9229
- }
9230
- function isControlRuntimeEvent(event) {
9231
- return event.type === "control";
9232
- }
9233
- function isHiddenUserInputEvent(event) {
9234
- if (event.type !== "user_input") {
9235
- return false;
9236
- }
9237
- const metadata = isRecord13(event.metadata) ? event.metadata : void 0;
9238
- const ui = metadata && isRecord13(metadata.ui) ? metadata.ui : void 0;
9239
- return ui?.presentation === "hidden";
9240
- }
9241
- function isEmptyTerminalAssistantRuntimeEvent(event) {
9242
- if (event.type !== "thought" && event.type !== "final_answer") {
9243
- return false;
9244
- }
9245
- return event.content.trim().length === 0;
9246
- }
9247
- function isConversationUiRuntimeEvent(event) {
9248
- return event.lane === "foreground" && event.visibility === "conversation";
9249
- }
9250
- function shouldPersistRuntimeEvent(event) {
9251
- return describeRuntimeEventLifecycle(event).persist;
9252
- }
9253
- function requirePersistableRuntimeEvent(event) {
9254
- if (!shouldPersistRuntimeEvent(event)) {
9255
- throw new Error(`RuntimeEvent ${event.id} (${event.type}) is not eligible for persistence.`);
9256
- }
9257
- return event;
9258
- }
9259
- function requirePersistableRoutedRuntimeEvent(event) {
9260
- requirePersistableRuntimeEvent(event);
9261
- return parseRoutedRuntimeEvent(event);
9262
- }
9263
- function shouldReplayRuntimeEventToUi(event) {
9264
- return describeRuntimeEventLifecycle(event).replayToUi;
9265
- }
9266
- function shouldEnterAgentContext(event) {
9267
- return describeRuntimeEventLifecycle(event).enterAgentContext;
9268
- }
9269
- function getRuntimeEventUiProjectionKind(event) {
9270
- if (isHiddenUserInputEvent(event)) {
9271
- return "hidden";
9272
- }
9273
- switch (event.type) {
9274
- case "user_input":
9275
- return "user_input";
9276
- case "thought":
9277
- return "thought";
9278
- case "final_answer":
9279
- return "final_answer";
9280
- case "final_answer_chunk":
9281
- return "final_answer_chunk";
9282
- case "final_answer_reset":
9283
- return "final_answer_reset";
9284
- case "tool_call_decision":
9285
- return "tool_call_decision";
9286
- case "tool_process":
9287
- return "tool_process";
9288
- case "tool_output":
9289
- return "tool_output";
9290
- case "requires_user_interaction":
9291
- return "requires_user_interaction";
9292
- case "audit_envelope":
9293
- return "audit_envelope";
9294
- case "subrun_trace":
9295
- return "subrun_trace";
9296
- case "error":
9297
- return "error";
9298
- case "context_usage_snapshot":
9299
- return "context_usage_snapshot";
9300
- case "run_execution_metrics":
9301
- return "run_execution_metrics";
9302
- case "history_summary":
9303
- return "history_summary";
9304
- default:
9305
- return "unsupported";
9306
- }
9307
- }
9308
- function describeRuntimeEventLifecycle(event) {
9309
- const uiProjectionKind = getRuntimeEventUiProjectionKind(event);
9310
- const persist = event.ephemeral !== true && !isToolProcessEvent(event) && !isSubRunTraceRuntimeEvent(event);
9311
- const replayToUi = persist && isConversationUiRuntimeEvent(event) && uiProjectionKind !== "hidden" && uiProjectionKind !== "audit_envelope" && uiProjectionKind !== "final_answer_chunk" && uiProjectionKind !== "final_answer_reset" && uiProjectionKind !== "unsupported";
9312
- const enterAgentContext = (() => {
9313
- if (uiProjectionKind === "unsupported") {
9314
- return false;
9315
- }
9316
- if (isSubRunTraceRuntimeEvent(event)) {
9317
- return false;
9318
- }
9319
- if (isRunExecutionMetricsRuntimeEvent(event)) {
9320
- return false;
9321
- }
9322
- if (isContextUsageSnapshotRuntimeEvent(event)) {
9323
- return false;
9324
- }
9325
- if (event.type === "error") {
9326
- return false;
9327
- }
9328
- if (isRequiresUserInteractionRuntimeEvent(event)) {
9329
- return false;
9330
- }
9331
- if (isAuditEnvelopeRuntimeEvent(event)) {
9332
- return false;
9333
- }
9334
- if (isControlRuntimeEvent(event)) {
9335
- return false;
9336
- }
9337
- if (isHiddenUserInputEvent(event)) {
9338
- return false;
9339
- }
9340
- if (isToolProcessEvent(event)) {
9341
- return false;
9342
- }
9343
- if (event.type === "thought") {
9344
- return false;
9345
- }
9346
- if (event.type === "final_answer_chunk") {
9347
- return false;
9348
- }
9349
- if (event.type === "final_answer_reset") {
9350
- return false;
9351
- }
9352
- if (isEmptyTerminalAssistantRuntimeEvent(event)) {
9353
- return false;
9354
- }
9355
- return true;
9356
- })();
9357
- const realtimeChannel = (() => {
9358
- switch (uiProjectionKind) {
9359
- case "thought":
9360
- case "final_answer":
9361
- case "final_answer_chunk":
9362
- case "final_answer_reset":
9363
- case "tool_call_decision":
9364
- case "tool_process":
9365
- case "tool_output":
9366
- case "requires_user_interaction":
9367
- case "subrun_trace":
9368
- case "error":
9369
- case "context_usage_snapshot":
9370
- case "run_execution_metrics":
9371
- case "history_summary":
9372
- return "event_bus_sse";
9373
- case "audit_envelope":
9374
- return "none";
9375
- default:
9376
- return "none";
9377
- }
9378
- })();
9379
- return {
9380
- uiProjectionKind,
9381
- persist,
9382
- replayToUi,
9383
- enterAgentContext,
9384
- realtimeChannel
9385
- };
9386
- }
9387
- function shouldEmitRuntimeEventToSse(event) {
9388
- return describeRuntimeEventLifecycle(event).realtimeChannel === "event_bus_sse";
9389
- }
9390
-
9391
9395
  // src/runtime-kernel/events/finalAnswerCompletion.ts
9392
9396
  function findTerminalFinalAnswer(events) {
9393
9397
  for (let index = events.length - 1; index >= 0; index -= 1) {