@linnlabs/linnkit 0.37.1 → 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.
Files changed (57) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/cli.cjs +238 -242
  3. package/dist/cli.cjs.map +1 -1
  4. package/dist/cli.js +238 -242
  5. package/dist/cli.js.map +1 -1
  6. package/dist/context-manager.cjs +198 -200
  7. package/dist/context-manager.cjs.map +1 -1
  8. package/dist/context-manager.js +198 -200
  9. package/dist/context-manager.js.map +1 -1
  10. package/dist/contracts/agentSpec.d.cts +30 -30
  11. package/dist/contracts/agentSpec.d.ts +30 -30
  12. package/dist/contracts/audit.d.cts +32 -32
  13. package/dist/contracts/audit.d.ts +32 -32
  14. package/dist/contracts/contextPolicy.d.cts +36 -36
  15. package/dist/contracts/contextPolicy.d.ts +36 -36
  16. package/dist/contracts/events.d.cts +1113 -1113
  17. package/dist/contracts/events.d.ts +1113 -1113
  18. package/dist/contracts/execution.d.cts +8 -8
  19. package/dist/contracts/execution.d.ts +8 -8
  20. package/dist/contracts/messages.d.cts +1178 -1178
  21. package/dist/contracts/messages.d.ts +1178 -1178
  22. package/dist/contracts/provider-continuation.d.cts +28 -28
  23. package/dist/contracts/provider-continuation.d.ts +28 -28
  24. package/dist/contracts/sse.d.cts +897 -897
  25. package/dist/contracts/sse.d.ts +897 -897
  26. package/dist/contracts/sub-run-trace-payload.d.cts +26 -26
  27. package/dist/contracts/sub-run-trace-payload.d.ts +26 -26
  28. package/dist/contracts/token-accounting.d.cts +38 -38
  29. package/dist/contracts/token-accounting.d.ts +38 -38
  30. package/dist/index.cjs +238 -242
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.js +238 -242
  33. package/dist/index.js.map +1 -1
  34. package/dist/quickstart.cjs +238 -242
  35. package/dist/quickstart.cjs.map +1 -1
  36. package/dist/quickstart.js +238 -242
  37. package/dist/quickstart.js.map +1 -1
  38. package/dist/runtime-kernel/events/agentEvents.d.cts +172 -172
  39. package/dist/runtime-kernel/events/agentEvents.d.ts +172 -172
  40. package/dist/runtime-kernel/events.cjs +1 -3
  41. package/dist/runtime-kernel/events.cjs.map +1 -1
  42. package/dist/runtime-kernel/events.js +1 -3
  43. package/dist/runtime-kernel/events.js.map +1 -1
  44. package/dist/runtime-kernel/graph-engine/executorContextBuilder.d.cts +1 -0
  45. package/dist/runtime-kernel/graph-engine/executorContextBuilder.d.ts +1 -0
  46. package/dist/runtime-kernel.cjs +238 -242
  47. package/dist/runtime-kernel.cjs.map +1 -1
  48. package/dist/runtime-kernel.js +238 -242
  49. package/dist/runtime-kernel.js.map +1 -1
  50. package/dist/testkit.cjs +238 -242
  51. package/dist/testkit.cjs.map +1 -1
  52. package/dist/testkit.js +238 -242
  53. package/dist/testkit.js.map +1 -1
  54. package/docs/integration/llm-provider.md +1 -0
  55. package/docs/integration/persistence.md +10 -0
  56. package/docs/integration/realtime.md +5 -0
  57. package/package.json +2 -2
@@ -6679,6 +6679,199 @@ function createDefaultSystemReminderRegistry() {
6679
6679
  });
6680
6680
  }
6681
6681
  createDefaultSystemReminderRegistry();
6682
+
6683
+ // src/runtime-kernel/events/eventGovernance.ts
6684
+ var RUNTIME_EVENT_TYPES_NEVER_REPLAYED_TO_UI = [
6685
+ "audit_envelope",
6686
+ "final_answer_chunk",
6687
+ "final_answer_reset",
6688
+ "subrun_trace",
6689
+ "context_usage_snapshot"
6690
+ ];
6691
+ function isRecord2(value) {
6692
+ return !!value && typeof value === "object" && !Array.isArray(value);
6693
+ }
6694
+ function isToolCallDecisionEvent(event) {
6695
+ return event.type === "tool_call_decision";
6696
+ }
6697
+ function isToolProcessEvent(event) {
6698
+ return event.type === "tool_process";
6699
+ }
6700
+ function isSubRunTraceRuntimeEvent(event) {
6701
+ return event.type === "subrun_trace";
6702
+ }
6703
+ function isRunExecutionMetricsRuntimeEvent(event) {
6704
+ return event.type === "run_execution_metrics";
6705
+ }
6706
+ function isContextUsageSnapshotRuntimeEvent(event) {
6707
+ return event.type === "context_usage_snapshot";
6708
+ }
6709
+ function isRequiresUserInteractionRuntimeEvent(event) {
6710
+ return event.type === "requires_user_interaction";
6711
+ }
6712
+ function isAuditEnvelopeRuntimeEvent(event) {
6713
+ return event.type === "audit_envelope";
6714
+ }
6715
+ function isControlRuntimeEvent(event) {
6716
+ return event.type === "control";
6717
+ }
6718
+ function isHiddenUserInputEvent(event) {
6719
+ if (event.type !== "user_input") {
6720
+ return false;
6721
+ }
6722
+ const metadata = isRecord2(event.metadata) ? event.metadata : void 0;
6723
+ const ui = metadata && isRecord2(metadata.ui) ? metadata.ui : void 0;
6724
+ return ui?.presentation === "hidden";
6725
+ }
6726
+ function isEmptyTerminalAssistantRuntimeEvent(event) {
6727
+ if (event.type !== "thought" && event.type !== "final_answer") {
6728
+ return false;
6729
+ }
6730
+ return event.content.trim().length === 0;
6731
+ }
6732
+ function isConversationUiRuntimeEvent(event) {
6733
+ return event.lane === "foreground" && event.visibility === "conversation";
6734
+ }
6735
+ function shouldPersistRuntimeEvent(event) {
6736
+ return describeRuntimeEventLifecycle(event).persist;
6737
+ }
6738
+ function requirePersistableRuntimeEvent(event) {
6739
+ if (!shouldPersistRuntimeEvent(event)) {
6740
+ throw new Error(`RuntimeEvent ${event.id} (${event.type}) is not eligible for persistence.`);
6741
+ }
6742
+ return event;
6743
+ }
6744
+ function requirePersistableRoutedRuntimeEvent(event) {
6745
+ requirePersistableRuntimeEvent(event);
6746
+ return parseRoutedRuntimeEvent(event);
6747
+ }
6748
+ function shouldReplayRuntimeEventToUi(event) {
6749
+ return describeRuntimeEventLifecycle(event).replayToUi;
6750
+ }
6751
+ function shouldEnterAgentContext(event) {
6752
+ return describeRuntimeEventLifecycle(event).enterAgentContext;
6753
+ }
6754
+ function getRuntimeEventUiProjectionKind(event) {
6755
+ if (isHiddenUserInputEvent(event)) {
6756
+ return "hidden";
6757
+ }
6758
+ switch (event.type) {
6759
+ case "user_input":
6760
+ return "user_input";
6761
+ case "thought":
6762
+ return "thought";
6763
+ case "final_answer":
6764
+ return "final_answer";
6765
+ case "final_answer_chunk":
6766
+ return "final_answer_chunk";
6767
+ case "final_answer_reset":
6768
+ return "final_answer_reset";
6769
+ case "tool_call_decision":
6770
+ return "tool_call_decision";
6771
+ case "tool_process":
6772
+ return "tool_process";
6773
+ case "tool_output":
6774
+ return "tool_output";
6775
+ case "requires_user_interaction":
6776
+ return "requires_user_interaction";
6777
+ case "audit_envelope":
6778
+ return "audit_envelope";
6779
+ case "subrun_trace":
6780
+ return "subrun_trace";
6781
+ case "error":
6782
+ return "error";
6783
+ case "context_usage_snapshot":
6784
+ return "context_usage_snapshot";
6785
+ case "run_execution_metrics":
6786
+ return "run_execution_metrics";
6787
+ case "history_summary":
6788
+ return "history_summary";
6789
+ default:
6790
+ return "unsupported";
6791
+ }
6792
+ }
6793
+ function describeRuntimeEventLifecycle(event) {
6794
+ const uiProjectionKind = getRuntimeEventUiProjectionKind(event);
6795
+ const persist = event.ephemeral !== true && !isToolProcessEvent(event) && !isSubRunTraceRuntimeEvent(event);
6796
+ const replayToUi = persist && isConversationUiRuntimeEvent(event) && uiProjectionKind !== "hidden" && uiProjectionKind !== "audit_envelope" && uiProjectionKind !== "final_answer_chunk" && uiProjectionKind !== "final_answer_reset" && uiProjectionKind !== "unsupported";
6797
+ const enterAgentContext = (() => {
6798
+ if (uiProjectionKind === "unsupported") {
6799
+ return false;
6800
+ }
6801
+ if (isSubRunTraceRuntimeEvent(event)) {
6802
+ return false;
6803
+ }
6804
+ if (isRunExecutionMetricsRuntimeEvent(event)) {
6805
+ return false;
6806
+ }
6807
+ if (isContextUsageSnapshotRuntimeEvent(event)) {
6808
+ return false;
6809
+ }
6810
+ if (event.type === "error") {
6811
+ return false;
6812
+ }
6813
+ if (isRequiresUserInteractionRuntimeEvent(event)) {
6814
+ return false;
6815
+ }
6816
+ if (isAuditEnvelopeRuntimeEvent(event)) {
6817
+ return false;
6818
+ }
6819
+ if (isControlRuntimeEvent(event)) {
6820
+ return false;
6821
+ }
6822
+ if (isHiddenUserInputEvent(event)) {
6823
+ return false;
6824
+ }
6825
+ if (isToolProcessEvent(event)) {
6826
+ return false;
6827
+ }
6828
+ if (event.type === "thought") {
6829
+ return false;
6830
+ }
6831
+ if (event.type === "final_answer_chunk") {
6832
+ return false;
6833
+ }
6834
+ if (event.type === "final_answer_reset") {
6835
+ return false;
6836
+ }
6837
+ if (isEmptyTerminalAssistantRuntimeEvent(event)) {
6838
+ return false;
6839
+ }
6840
+ return true;
6841
+ })();
6842
+ const realtimeChannel = (() => {
6843
+ switch (uiProjectionKind) {
6844
+ case "thought":
6845
+ case "final_answer":
6846
+ case "final_answer_chunk":
6847
+ case "final_answer_reset":
6848
+ case "tool_call_decision":
6849
+ case "tool_process":
6850
+ case "tool_output":
6851
+ case "requires_user_interaction":
6852
+ case "subrun_trace":
6853
+ case "error":
6854
+ case "context_usage_snapshot":
6855
+ case "run_execution_metrics":
6856
+ case "history_summary":
6857
+ return "event_bus_sse";
6858
+ case "audit_envelope":
6859
+ return "none";
6860
+ default:
6861
+ return "none";
6862
+ }
6863
+ })();
6864
+ return {
6865
+ uiProjectionKind,
6866
+ persist,
6867
+ replayToUi,
6868
+ enterAgentContext,
6869
+ realtimeChannel
6870
+ };
6871
+ }
6872
+ function shouldEmitRuntimeEventToSse(event) {
6873
+ return describeRuntimeEventLifecycle(event).realtimeChannel === "event_bus_sse";
6874
+ }
6682
6875
  var UnknownRecord = z.record(z.string(), z.unknown());
6683
6876
  var NonBlankIdentifier = z.string().min(1).refine(
6684
6877
  (value) => value === value.trim(),
@@ -6798,11 +6991,11 @@ var AgentEventSchema = z.discriminatedUnion("type", [
6798
6991
  });
6799
6992
 
6800
6993
  // src/runtime-kernel/events/provider-sidecar.ts
6801
- var isRecord2 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
6994
+ var isRecord3 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
6802
6995
  function readMetaFromEvent(event) {
6803
- if (!isRecord2(event)) return void 0;
6996
+ if (!isRecord3(event)) return void 0;
6804
6997
  const value = event["meta"];
6805
- return isRecord2(value) ? value : void 0;
6998
+ return isRecord3(value) ? value : void 0;
6806
6999
  }
6807
7000
 
6808
7001
  // src/runtime-kernel/events/agent-to-runtime.ts
@@ -6810,7 +7003,7 @@ function agentEventToRuntime(agentEvent, context, options = {}) {
6810
7003
  return mapAgentEventToRuntime(agentEvent, context, options);
6811
7004
  }
6812
7005
  function mapAgentEventToRuntime(agentEvent, context, options) {
6813
- if (isRecord2(agentEvent) && agentEvent["type"] === "history_summary") {
7006
+ if (isRecord3(agentEvent) && agentEvent["type"] === "history_summary") {
6814
7007
  const event = RuntimeEvent.parse(agentEvent);
6815
7008
  return context.metadata ? {
6816
7009
  ...event,
@@ -6951,9 +7144,7 @@ function mapToolProgressToRuntime(toolEvent, context, options, id, timestamp) {
6951
7144
  return event;
6952
7145
  }
6953
7146
  function mapStreamChunkToRuntime(streamEvent, context, id, timestamp) {
6954
- const text = streamEvent.content ?? "";
6955
- if (!text) return null;
6956
- const chunkEvent = createFinalAnswerChunkEvent(id, context.conversationId, context.turnId, streamEvent.answer_id, streamEvent.seq, text, {
7147
+ const chunkEvent = createFinalAnswerChunkEvent(id, context.conversationId, context.turnId, streamEvent.answer_id, streamEvent.seq, streamEvent.content, {
6957
7148
  timestamp,
6958
7149
  is_last: streamEvent.is_last === true
6959
7150
  });
@@ -7271,199 +7462,6 @@ __export(events_exports, {
7271
7462
  shouldReplayRuntimeEventToUi: () => shouldReplayRuntimeEventToUi
7272
7463
  });
7273
7464
 
7274
- // src/runtime-kernel/events/eventGovernance.ts
7275
- var RUNTIME_EVENT_TYPES_NEVER_REPLAYED_TO_UI = [
7276
- "audit_envelope",
7277
- "final_answer_chunk",
7278
- "final_answer_reset",
7279
- "subrun_trace",
7280
- "context_usage_snapshot"
7281
- ];
7282
- function isRecord4(value) {
7283
- return !!value && typeof value === "object" && !Array.isArray(value);
7284
- }
7285
- function isToolCallDecisionEvent(event) {
7286
- return event.type === "tool_call_decision";
7287
- }
7288
- function isToolProcessEvent(event) {
7289
- return event.type === "tool_process";
7290
- }
7291
- function isSubRunTraceRuntimeEvent(event) {
7292
- return event.type === "subrun_trace";
7293
- }
7294
- function isRunExecutionMetricsRuntimeEvent(event) {
7295
- return event.type === "run_execution_metrics";
7296
- }
7297
- function isContextUsageSnapshotRuntimeEvent(event) {
7298
- return event.type === "context_usage_snapshot";
7299
- }
7300
- function isRequiresUserInteractionRuntimeEvent(event) {
7301
- return event.type === "requires_user_interaction";
7302
- }
7303
- function isAuditEnvelopeRuntimeEvent(event) {
7304
- return event.type === "audit_envelope";
7305
- }
7306
- function isControlRuntimeEvent(event) {
7307
- return event.type === "control";
7308
- }
7309
- function isHiddenUserInputEvent(event) {
7310
- if (event.type !== "user_input") {
7311
- return false;
7312
- }
7313
- const metadata = isRecord4(event.metadata) ? event.metadata : void 0;
7314
- const ui = metadata && isRecord4(metadata.ui) ? metadata.ui : void 0;
7315
- return ui?.presentation === "hidden";
7316
- }
7317
- function isEmptyTerminalAssistantRuntimeEvent(event) {
7318
- if (event.type !== "thought" && event.type !== "final_answer") {
7319
- return false;
7320
- }
7321
- return event.content.trim().length === 0;
7322
- }
7323
- function isConversationUiRuntimeEvent(event) {
7324
- return event.lane === "foreground" && event.visibility === "conversation";
7325
- }
7326
- function shouldPersistRuntimeEvent(event) {
7327
- return describeRuntimeEventLifecycle(event).persist;
7328
- }
7329
- function requirePersistableRuntimeEvent(event) {
7330
- if (!shouldPersistRuntimeEvent(event)) {
7331
- throw new Error(`RuntimeEvent ${event.id} (${event.type}) is not eligible for persistence.`);
7332
- }
7333
- return event;
7334
- }
7335
- function requirePersistableRoutedRuntimeEvent(event) {
7336
- requirePersistableRuntimeEvent(event);
7337
- return parseRoutedRuntimeEvent(event);
7338
- }
7339
- function shouldReplayRuntimeEventToUi(event) {
7340
- return describeRuntimeEventLifecycle(event).replayToUi;
7341
- }
7342
- function shouldEnterAgentContext(event) {
7343
- return describeRuntimeEventLifecycle(event).enterAgentContext;
7344
- }
7345
- function getRuntimeEventUiProjectionKind(event) {
7346
- if (isHiddenUserInputEvent(event)) {
7347
- return "hidden";
7348
- }
7349
- switch (event.type) {
7350
- case "user_input":
7351
- return "user_input";
7352
- case "thought":
7353
- return "thought";
7354
- case "final_answer":
7355
- return "final_answer";
7356
- case "final_answer_chunk":
7357
- return "final_answer_chunk";
7358
- case "final_answer_reset":
7359
- return "final_answer_reset";
7360
- case "tool_call_decision":
7361
- return "tool_call_decision";
7362
- case "tool_process":
7363
- return "tool_process";
7364
- case "tool_output":
7365
- return "tool_output";
7366
- case "requires_user_interaction":
7367
- return "requires_user_interaction";
7368
- case "audit_envelope":
7369
- return "audit_envelope";
7370
- case "subrun_trace":
7371
- return "subrun_trace";
7372
- case "error":
7373
- return "error";
7374
- case "context_usage_snapshot":
7375
- return "context_usage_snapshot";
7376
- case "run_execution_metrics":
7377
- return "run_execution_metrics";
7378
- case "history_summary":
7379
- return "history_summary";
7380
- default:
7381
- return "unsupported";
7382
- }
7383
- }
7384
- function describeRuntimeEventLifecycle(event) {
7385
- const uiProjectionKind = getRuntimeEventUiProjectionKind(event);
7386
- const persist = event.ephemeral !== true && !isToolProcessEvent(event) && !isSubRunTraceRuntimeEvent(event);
7387
- const replayToUi = persist && isConversationUiRuntimeEvent(event) && uiProjectionKind !== "hidden" && uiProjectionKind !== "audit_envelope" && uiProjectionKind !== "final_answer_chunk" && uiProjectionKind !== "final_answer_reset" && uiProjectionKind !== "unsupported";
7388
- const enterAgentContext = (() => {
7389
- if (uiProjectionKind === "unsupported") {
7390
- return false;
7391
- }
7392
- if (isSubRunTraceRuntimeEvent(event)) {
7393
- return false;
7394
- }
7395
- if (isRunExecutionMetricsRuntimeEvent(event)) {
7396
- return false;
7397
- }
7398
- if (isContextUsageSnapshotRuntimeEvent(event)) {
7399
- return false;
7400
- }
7401
- if (event.type === "error") {
7402
- return false;
7403
- }
7404
- if (isRequiresUserInteractionRuntimeEvent(event)) {
7405
- return false;
7406
- }
7407
- if (isAuditEnvelopeRuntimeEvent(event)) {
7408
- return false;
7409
- }
7410
- if (isControlRuntimeEvent(event)) {
7411
- return false;
7412
- }
7413
- if (isHiddenUserInputEvent(event)) {
7414
- return false;
7415
- }
7416
- if (isToolProcessEvent(event)) {
7417
- return false;
7418
- }
7419
- if (event.type === "thought") {
7420
- return false;
7421
- }
7422
- if (event.type === "final_answer_chunk") {
7423
- return false;
7424
- }
7425
- if (event.type === "final_answer_reset") {
7426
- return false;
7427
- }
7428
- if (isEmptyTerminalAssistantRuntimeEvent(event)) {
7429
- return false;
7430
- }
7431
- return true;
7432
- })();
7433
- const realtimeChannel = (() => {
7434
- switch (uiProjectionKind) {
7435
- case "thought":
7436
- case "final_answer":
7437
- case "final_answer_chunk":
7438
- case "final_answer_reset":
7439
- case "tool_call_decision":
7440
- case "tool_process":
7441
- case "tool_output":
7442
- case "requires_user_interaction":
7443
- case "subrun_trace":
7444
- case "error":
7445
- case "context_usage_snapshot":
7446
- case "run_execution_metrics":
7447
- case "history_summary":
7448
- return "event_bus_sse";
7449
- case "audit_envelope":
7450
- return "none";
7451
- default:
7452
- return "none";
7453
- }
7454
- })();
7455
- return {
7456
- uiProjectionKind,
7457
- persist,
7458
- replayToUi,
7459
- enterAgentContext,
7460
- realtimeChannel
7461
- };
7462
- }
7463
- function shouldEmitRuntimeEventToSse(event) {
7464
- return describeRuntimeEventLifecycle(event).realtimeChannel === "event_bus_sse";
7465
- }
7466
-
7467
7465
  // src/runtime-kernel/events/finalAnswerCompletion.ts
7468
7466
  function findTerminalFinalAnswer(events) {
7469
7467
  for (let index = events.length - 1; index >= 0; index -= 1) {