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