@valerypopoff/rivet2-core 2.28.0 → 2.31.0

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.
@@ -94,9 +94,18 @@ __export(src_exports, {
94
94
  DestructureNodeImpl: () => DestructureNodeImpl,
95
95
  DidRunNodeImpl: () => DidRunNodeImpl,
96
96
  DocumentNodeImpl: () => DocumentNodeImpl,
97
+ EXECUTOR_RELIABLE_MAX_BYTES: () => EXECUTOR_RELIABLE_MAX_BYTES,
98
+ EXECUTOR_RELIABLE_MAX_ITEMS: () => EXECUTOR_RELIABLE_MAX_ITEMS,
99
+ EXECUTOR_RELIABLE_PROCESS_BYTES: () => EXECUTOR_RELIABLE_PROCESS_BYTES,
100
+ EXECUTOR_RELIABLE_SESSION_BYTES: () => EXECUTOR_RELIABLE_SESSION_BYTES,
101
+ EXECUTOR_SESSION_V2: () => EXECUTOR_SESSION_V2,
102
+ EXECUTOR_TRANSFER_TIMEOUT_MS: () => EXECUTOR_TRANSFER_TIMEOUT_MS,
97
103
  EXPRESSION_OUTPUT_PORT_ID: () => EXPRESSION_OUTPUT_PORT_ID,
98
104
  EvaluateNodeImpl: () => EvaluateNodeImpl,
99
105
  ExecutionRecorder: () => ExecutionRecorder,
106
+ ExecutorRecoveryError: () => ExecutorRecoveryError,
107
+ ExecutorReliableInbox: () => ExecutorReliableInbox,
108
+ ExecutorReliableOutbox: () => ExecutorReliableOutbox,
100
109
  ExpressionNodeImpl: () => ExpressionNodeImpl,
101
110
  ExternalCallNodeImpl: () => ExternalCallNodeImpl,
102
111
  ExtractJsonNodeImpl: () => ExtractJsonNodeImpl,
@@ -400,6 +409,7 @@ __export(src_exports, {
400
409
  evaluateJsonPath: () => evaluateJsonPath,
401
410
  evaluateNode: () => evaluateNode,
402
411
  executeLLMInvocation: () => executeLLMInvocation,
412
+ executorDeliveryPolicy: () => executorDeliveryPolicy,
403
413
  expectType: () => expectType,
404
414
  expectTypeOptional: () => expectTypeOptional,
405
415
  exportGentraceEvaluationRun: () => exportGentraceEvaluationRun,
@@ -906,9 +916,18 @@ __export(exports_exports, {
906
916
  DestructureNodeImpl: () => DestructureNodeImpl,
907
917
  DidRunNodeImpl: () => DidRunNodeImpl,
908
918
  DocumentNodeImpl: () => DocumentNodeImpl,
919
+ EXECUTOR_RELIABLE_MAX_BYTES: () => EXECUTOR_RELIABLE_MAX_BYTES,
920
+ EXECUTOR_RELIABLE_MAX_ITEMS: () => EXECUTOR_RELIABLE_MAX_ITEMS,
921
+ EXECUTOR_RELIABLE_PROCESS_BYTES: () => EXECUTOR_RELIABLE_PROCESS_BYTES,
922
+ EXECUTOR_RELIABLE_SESSION_BYTES: () => EXECUTOR_RELIABLE_SESSION_BYTES,
923
+ EXECUTOR_SESSION_V2: () => EXECUTOR_SESSION_V2,
924
+ EXECUTOR_TRANSFER_TIMEOUT_MS: () => EXECUTOR_TRANSFER_TIMEOUT_MS,
909
925
  EXPRESSION_OUTPUT_PORT_ID: () => EXPRESSION_OUTPUT_PORT_ID,
910
926
  EvaluateNodeImpl: () => EvaluateNodeImpl,
911
927
  ExecutionRecorder: () => ExecutionRecorder,
928
+ ExecutorRecoveryError: () => ExecutorRecoveryError,
929
+ ExecutorReliableInbox: () => ExecutorReliableInbox,
930
+ ExecutorReliableOutbox: () => ExecutorReliableOutbox,
912
931
  ExpressionNodeImpl: () => ExpressionNodeImpl,
913
932
  ExternalCallNodeImpl: () => ExternalCallNodeImpl,
914
933
  ExtractJsonNodeImpl: () => ExtractJsonNodeImpl,
@@ -1211,6 +1230,7 @@ __export(exports_exports, {
1211
1230
  evaluateJsonPath: () => evaluateJsonPath,
1212
1231
  evaluateNode: () => evaluateNode,
1213
1232
  executeLLMInvocation: () => executeLLMInvocation,
1233
+ executorDeliveryPolicy: () => executorDeliveryPolicy,
1214
1234
  expectType: () => expectType,
1215
1235
  expectTypeOptional: () => expectTypeOptional,
1216
1236
  exportGentraceEvaluationRun: () => exportGentraceEvaluationRun,
@@ -3864,7 +3884,7 @@ function coerceToChatMessageRaw(value) {
3864
3884
  if (value.type === "string") {
3865
3885
  return { type: "user", message: value.value };
3866
3886
  }
3867
- if (value.type === "object" && "type" in value.value && "message" in value.value && typeof value.value.type === "string" && typeof value.value.message === "string") {
3887
+ if (value.type === "object" && "type" in value.value && "message" in value.value && typeof value.value.type === "string" && (typeof value.value.message === "string" || Array.isArray(value.value.message))) {
3868
3888
  return value.value;
3869
3889
  }
3870
3890
  if (value.type === "any") {
@@ -6311,6 +6331,32 @@ function compareConnections(beforeConnections, afterConnections) {
6311
6331
  );
6312
6332
  }
6313
6333
 
6334
+ // src/utils/projectComparison/identity.ts
6335
+ function comparisonProjectIdentity(id, side, identity) {
6336
+ const index = identity.pairs.findIndex((p) => (side === "before" ? p.beforeProjectId : p.afterProjectId) === id);
6337
+ return JSON.stringify(index < 0 ? ["project", id] : ["pair", index]);
6338
+ }
6339
+ function comparisonNodeIdentity(node, side, identity) {
6340
+ if (!identity || node.type !== "subGraph" && node.type !== "referencedGraphAlias") return node;
6341
+ const field2 = node.type === "subGraph" ? "targetProjectId" : "projectId";
6342
+ const data = (value) => {
6343
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
6344
+ const record4 = value;
6345
+ if (typeof record4[field2] !== "string") return value;
6346
+ const result = { ...record4, [field2]: comparisonProjectIdentity(record4[field2], side, identity) };
6347
+ if (node.type === "subGraph" && identity.pairs.some((p) => (side === "before" ? p.beforeProjectId : p.afterProjectId) === record4[field2])) {
6348
+ delete result.targetScope;
6349
+ result.targetVersion ??= "latest";
6350
+ }
6351
+ return result;
6352
+ };
6353
+ return {
6354
+ ...node,
6355
+ data: data(node.data),
6356
+ ...node.variants ? { variants: node.variants.map((v) => ({ ...v, data: data(v.data) })) } : {}
6357
+ };
6358
+ }
6359
+
6314
6360
  // src/utils/projectComparison/nodes.ts
6315
6361
  function getProjectNodeFieldComparisons(comparison) {
6316
6362
  const before = comparison.before;
@@ -6318,12 +6364,22 @@ function getProjectNodeFieldComparisons(comparison) {
6318
6364
  if (!before || !after) {
6319
6365
  return [];
6320
6366
  }
6321
- return getChangedValueComparisons([], getComparableNodeRecord(before), getComparableNodeRecord(after));
6367
+ const rawBefore = getComparableNodeRecord(before);
6368
+ const rawAfter = getComparableNodeRecord(after);
6369
+ const at = (record4, path) => path.reduce(
6370
+ (value, key) => value && typeof value === "object" ? value[key] : void 0,
6371
+ record4
6372
+ );
6373
+ return getChangedValueComparisons(
6374
+ [],
6375
+ getComparableNodeRecord(comparisonNodeIdentity(before, "before", comparison.identity)),
6376
+ getComparableNodeRecord(comparisonNodeIdentity(after, "after", comparison.identity))
6377
+ ).map((change) => ({ ...change, before: at(rawBefore, change.path), after: at(rawAfter, change.path) }));
6322
6378
  }
6323
6379
  function getComparableGraphNodes(nodes) {
6324
6380
  return nodes.filter((node) => node.type !== "comment");
6325
6381
  }
6326
- function compareNodes(beforeNodes, afterNodes) {
6382
+ function compareNodes(beforeNodes, afterNodes, identity) {
6327
6383
  const beforeById = new Map(beforeNodes.map((node) => [node.id, node]));
6328
6384
  const afterById = new Map(afterNodes.map((node) => [node.id, node]));
6329
6385
  const nodeIds = unionKeys(Object.fromEntries(beforeById), Object.fromEntries(afterById));
@@ -6341,9 +6397,13 @@ function compareNodes(beforeNodes, afterNodes) {
6341
6397
  nodeId,
6342
6398
  {
6343
6399
  id: nodeId,
6344
- kind: areComparisonNodesEqual(before, after) ? "unchanged" : "changed",
6400
+ kind: areComparisonNodesEqual(
6401
+ before && comparisonNodeIdentity(before, "before", identity),
6402
+ after && comparisonNodeIdentity(after, "after", identity)
6403
+ ) ? "unchanged" : "changed",
6345
6404
  before,
6346
- after
6405
+ after,
6406
+ ...identity ? { identity } : {}
6347
6407
  }
6348
6408
  ];
6349
6409
  })
@@ -6423,7 +6483,7 @@ function createEmptyProjectSummary() {
6423
6483
  }
6424
6484
 
6425
6485
  // src/utils/projectComparison/graphs.ts
6426
- function compareGraphs(id, before, after) {
6486
+ function compareGraphs(id, before, after, identity) {
6427
6487
  if (!before && after) {
6428
6488
  return createOneSidedGraphComparison(id, after, "added");
6429
6489
  }
@@ -6433,7 +6493,7 @@ function compareGraphs(id, before, after) {
6433
6493
  if (!before || !after) {
6434
6494
  throw new Error(`Cannot compare missing graph ${id}`);
6435
6495
  }
6436
- const nodes = compareNodes(getComparableGraphNodes(before.nodes), getComparableGraphNodes(after.nodes));
6496
+ const nodes = compareNodes(getComparableGraphNodes(before.nodes), getComparableGraphNodes(after.nodes), identity);
6437
6497
  const connections = compareConnections(
6438
6498
  getComparableGraphConnections(before.connections, before.nodes),
6439
6499
  getComparableGraphConnections(after.connections, after.nodes)
@@ -6484,24 +6544,40 @@ function createOneSidedConnectionComparisons(connections, kind) {
6484
6544
  }
6485
6545
 
6486
6546
  // src/utils/projectComparison.ts
6487
- function compareProjects(before, after) {
6547
+ function compareProjects(before, after, identity) {
6488
6548
  const graphIds = unionKeys(before.graphs, after.graphs);
6489
6549
  const graphs = Object.fromEntries(
6490
- graphIds.map((graphId2) => [graphId2, compareGraphs(graphId2, before.graphs[graphId2], after.graphs[graphId2])])
6550
+ graphIds.map((graphId2) => [
6551
+ graphId2,
6552
+ compareGraphs(graphId2, before.graphs[graphId2], after.graphs[graphId2], identity)
6553
+ ])
6491
6554
  );
6492
- const nodePrefabs = compareNodePrefabs(before.nodePrefabs ?? {}, after.nodePrefabs ?? {});
6555
+ const nodePrefabs = compareNodePrefabs(before.nodePrefabs ?? {}, after.nodePrefabs ?? {}, identity);
6493
6556
  const uiGraphs = compareUiGraphs(before.uiGraphs ?? {}, after.uiGraphs ?? {});
6494
6557
  return {
6495
6558
  beforeProjectId: before.metadata.id,
6496
6559
  afterProjectId: after.metadata.id,
6497
- metadataChanged: !areComparisonValuesEqual(before.metadata, after.metadata),
6560
+ metadataChanged: !areComparisonValuesEqual(
6561
+ identity ? {
6562
+ ...before.metadata,
6563
+ id: comparisonProjectIdentity(before.metadata.id, "before", identity),
6564
+ path: void 0,
6565
+ title: void 0
6566
+ } : before.metadata,
6567
+ identity ? {
6568
+ ...after.metadata,
6569
+ id: comparisonProjectIdentity(after.metadata.id, "after", identity),
6570
+ path: void 0,
6571
+ title: void 0
6572
+ } : after.metadata
6573
+ ),
6498
6574
  graphs,
6499
6575
  nodePrefabs,
6500
6576
  uiGraphs,
6501
6577
  summary: summarizeProjectComparison(graphs, nodePrefabs, uiGraphs)
6502
6578
  };
6503
6579
  }
6504
- function compareNodePrefabs(before, after) {
6580
+ function compareNodePrefabs(before, after, identity) {
6505
6581
  const prefabIds = unionKeys(before, after);
6506
6582
  return Object.fromEntries(
6507
6583
  prefabIds.map((prefabId) => {
@@ -6516,7 +6592,9 @@ function compareNodePrefabs(before, after) {
6516
6592
  if (!beforePrefab || !afterPrefab) {
6517
6593
  throw new Error(`Cannot compare missing library node ${prefabId}`);
6518
6594
  }
6519
- const sourceNodeComparison = Object.values(compareNodes([beforePrefab.sourceNode], [afterPrefab.sourceNode]))[0];
6595
+ const sourceNodeComparison = Object.values(
6596
+ compareNodes([beforePrefab.sourceNode], [afterPrefab.sourceNode], identity)
6597
+ )[0];
6520
6598
  return [
6521
6599
  prefabId,
6522
6600
  {
@@ -33660,11 +33738,11 @@ var import_non_secure34 = require("nanoid/non-secure");
33660
33738
  var import_lodash_es10 = require("lodash");
33661
33739
  var import_ts_dedent24 = require("ts-dedent");
33662
33740
  function isEmptyPromptMessage(message2) {
33663
- var _a;
33741
+ var _a, _b;
33664
33742
  if (message2.type === "function") {
33665
33743
  return false;
33666
33744
  }
33667
- if (message2.type === "assistant" && (message2.function_call != null || (((_a = message2.function_calls) == null ? void 0 : _a.length) ?? 0) > 0)) {
33745
+ if (message2.type === "assistant" && (message2.function_call != null || (((_a = message2.function_calls) == null ? void 0 : _a.length) ?? 0) > 0 || (((_b = message2.openRouterReasoningDetails) == null ? void 0 : _b.length) ?? 0) > 0)) {
33668
33746
  return false;
33669
33747
  }
33670
33748
  const parts = Array.isArray(message2.message) ? message2.message : [message2.message];
@@ -33682,7 +33760,7 @@ var AssemblePromptNodeImpl = class extends NodeImpl {
33682
33760
  width: 250
33683
33761
  },
33684
33762
  data: {
33685
- filterEmptyPrompts: false
33763
+ filterEmptyPrompts: true
33686
33764
  }
33687
33765
  };
33688
33766
  return chartNode;
@@ -33735,6 +33813,8 @@ var AssemblePromptNodeImpl = class extends NodeImpl {
33735
33813
  The number of inputs is dynamic based on the number of connections.
33736
33814
 
33737
33815
  Strings are converted to User type chat messages.
33816
+
33817
+ Empty or whitespace-only text messages are filtered by default. Rich content, tool exchanges and reasoning continuity are preserved.
33738
33818
  `,
33739
33819
  infoBoxTitle: "Assemble Prompt Node",
33740
33820
  contextMenuTitle: "Assemble Prompt",
@@ -33752,8 +33832,8 @@ var AssemblePromptNodeImpl = class extends NodeImpl {
33752
33832
  type: "toggle",
33753
33833
  label: "Filter empty prompts",
33754
33834
  dataKey: "filterEmptyPrompts",
33755
- defaultValue: false,
33756
- helperMessage: "Removes text-only messages whose content is empty or whitespace. Rich-content and tool-protocol messages are preserved."
33835
+ defaultValue: true,
33836
+ helperMessage: "Removes text-only messages whose content is empty or whitespace. Rich content, tool exchanges and reasoning continuity are preserved."
33757
33837
  },
33758
33838
  {
33759
33839
  type: "toggle",
@@ -33766,7 +33846,7 @@ var AssemblePromptNodeImpl = class extends NodeImpl {
33766
33846
  }
33767
33847
  getBody() {
33768
33848
  return [
33769
- this.data.filterEmptyPrompts ? "Filter empty prompts: Enabled" : "",
33849
+ this.data.filterEmptyPrompts !== false ? "Filter empty prompts: Enabled" : "",
33770
33850
  this.data.useIsLastMessageCacheBreakpointInput ? "Last message cache breakpoint: From input" : this.data.isLastMessageCacheBreakpoint ? "Last message is cache breakpoint" : ""
33771
33851
  ].filter(Boolean).join("\n");
33772
33852
  }
@@ -33783,10 +33863,13 @@ var AssemblePromptNodeImpl = class extends NodeImpl {
33783
33863
  if (!inputMessage || inputMessage.type === "control-flow-excluded" || !inputMessage.value) {
33784
33864
  continue;
33785
33865
  }
33786
- const inMessages = arrayizeDataValue(unwrapDataValue(inputMessage));
33866
+ const value = unwrapDataValue(inputMessage);
33867
+ if (value.value == null) continue;
33868
+ const inMessages = arrayizeDataValue(value);
33787
33869
  for (const message2 of inMessages) {
33870
+ if (message2.value == null) continue;
33788
33871
  const outMessage = message2.type === "chat-message" ? message2.value : coerceType(message2, "chat-message");
33789
- if (this.data.filterEmptyPrompts && isEmptyPromptMessage(outMessage)) {
33872
+ if (this.data.filterEmptyPrompts !== false && isEmptyPromptMessage(outMessage)) {
33790
33873
  continue;
33791
33874
  }
33792
33875
  outMessages.push(outMessage);
@@ -46132,7 +46215,10 @@ function createJevDecisionRequest({
46132
46215
  }
46133
46216
 
46134
46217
  // src/model/classifier/subq.ts
46135
- var SUBQ_DECISION_MODELS = ["subq-snap-1.1"];
46218
+ var SUBQ_DECISION_MODELS = [
46219
+ { value: "subq-snap-1.2", label: "Snap 1.2", aggregateTokenUsageOnly: true },
46220
+ { value: "subq-snap-1.1", label: "Snap 1.1 (deprecated)", aggregateTokenUsageOnly: true }
46221
+ ];
46136
46222
  function subqDecisionState(state) {
46137
46223
  if (state.kind === "json") return { state: state.value };
46138
46224
  const wire = systemOneState({ state: "", stateMessages: state.messages });
@@ -46398,13 +46484,18 @@ var perplexityClassifierProvider = createClassifierProvider({
46398
46484
  var subqClassifierProvider = createClassifierProvider({
46399
46485
  id: "subq",
46400
46486
  label: "SubQ",
46401
- defaultModel: "subq-snap-1.1",
46402
- modelOptions: SUBQ_DECISION_MODELS.map((value) => ({ value, label: value, aggregateTokenUsageOnly: true })),
46487
+ defaultModel: SUBQ_DECISION_MODELS[0].value,
46488
+ modelOptions: SUBQ_DECISION_MODELS,
46403
46489
  credentialNames: SUBQ_DEFAULT_CREDENTIAL_NAMES,
46404
46490
  browserExecutionSupported: false,
46405
46491
  endpoint: SUBQ_DECISIONS_ENDPOINT,
46406
- supportsImages: (model) => SUBQ_DECISION_MODELS.includes(model),
46407
- modelPricing: [{ models: SUBQ_DECISION_MODELS, pricing: { inputPerMillionTokens: 0.04, outputPerMillionTokens: 0 } }],
46492
+ supportsImages: (model) => SUBQ_DECISION_MODELS.some(({ value }) => value === model),
46493
+ modelPricing: [
46494
+ {
46495
+ models: SUBQ_DECISION_MODELS.map(({ value }) => value),
46496
+ pricing: { inputPerMillionTokens: 0.04, outputPerMillionTokens: 0 }
46497
+ }
46498
+ ],
46408
46499
  maxRequestBytes: 13 * 1024 * 1024,
46409
46500
  checkRequest: assertSubQDecisionLimits,
46410
46501
  buildRequest: ({ model, state, questions }) => ({
@@ -56011,6 +56102,189 @@ function isLatestDebuggerScope(value) {
56011
56102
  ) && (scope.promptId === void 0 || typeof scope.promptId === "string" && scope.promptId.length > 0 && scope.promptId.length <= 200) && (scope.admittedAt === void 0 || Number.isSafeInteger(scope.admittedAt) && scope.admittedAt >= 0) && (scope.promptLifecycle === void 0 || scope.promptLifecycle === 1);
56012
56103
  }
56013
56104
 
56105
+ // src/model/ExecutorSessionProtocol.ts
56106
+ var EXECUTOR_SESSION_V2 = "rivet-session-v2";
56107
+ var EXECUTOR_RELIABLE_MAX_BYTES = 100 * 1024 * 1024;
56108
+ var EXECUTOR_RELIABLE_SESSION_BYTES = 256 * 1024 * 1024;
56109
+ var EXECUTOR_RELIABLE_PROCESS_BYTES = 512 * 1024 * 1024;
56110
+ var EXECUTOR_RELIABLE_MAX_ITEMS = 4096;
56111
+ var EXECUTOR_TRANSFER_TIMEOUT_MS = 6e4;
56112
+ var deliveryPolicy = {
56113
+ start: "reliable",
56114
+ done: "reliable",
56115
+ error: "reliable",
56116
+ abort: "reliable",
56117
+ graphOutputsReady: "reliable",
56118
+ webAppStoragePatch: "reliable",
56119
+ userInput: "reliable",
56120
+ pause: "reliable",
56121
+ resume: "reliable",
56122
+ codeConsole: "diagnostic",
56123
+ nodeStart: "diagnostic",
56124
+ nodeFinish: "diagnostic",
56125
+ nodeError: "diagnostic",
56126
+ nodeExcluded: "diagnostic",
56127
+ graphAbort: "diagnostic",
56128
+ graphStart: "diagnostic",
56129
+ graphFinish: "diagnostic",
56130
+ partialOutput: "diagnostic",
56131
+ progress: "diagnostic",
56132
+ llmCallFinished: "diagnostic",
56133
+ llmChatOutputSnapshot: "diagnostic",
56134
+ llmProfileAttempt: "diagnostic",
56135
+ toolCallFinished: "diagnostic",
56136
+ nodeOutputsCleared: "diagnostic",
56137
+ streamingOutputWatchSummary: "diagnostic",
56138
+ graphError: "diagnostic",
56139
+ trace: "diagnostic"
56140
+ };
56141
+ var datasetMessages = {
56142
+ "datasets:get-metadata": true,
56143
+ "datasets:get-for-project": true,
56144
+ "datasets:get-data": true,
56145
+ "datasets:put-data": true,
56146
+ "datasets:put-row": true,
56147
+ "datasets:put-metadata": true,
56148
+ "datasets:clear-data": true,
56149
+ "datasets:delete": true,
56150
+ "datasets:knn": true,
56151
+ "datasets:export-for-project": true
56152
+ };
56153
+ function executorDeliveryPolicy(message2) {
56154
+ if (message2 === "graph-upload-allowed" || message2 === "executor-owner-retiring" || Object.hasOwn(datasetMessages, message2))
56155
+ return "reliable";
56156
+ if (Object.hasOwn(deliveryPolicy, message2)) return deliveryPolicy[message2];
56157
+ throw new ExecutorRecoveryError("invalid-transfer");
56158
+ }
56159
+ var CHUNK_CHARACTERS = 8192;
56160
+ var ExecutorRecoveryError = class extends Error {
56161
+ constructor(reason) {
56162
+ super(`Executor session could not be resumed (${reason}). Run outcome is unknown; it was not resubmitted.`);
56163
+ this.reason = reason;
56164
+ this.name = "ExecutorRecoveryError";
56165
+ }
56166
+ };
56167
+ var safeId = (value) => Number.isSafeInteger(value) && value > 0;
56168
+ var ExecutorReliableOutbox = class {
56169
+ constructor(maxBytes = EXECUTOR_RELIABLE_SESSION_BYTES, reservedBytes = 0) {
56170
+ this.maxBytes = maxBytes;
56171
+ this.reservedBytes = reservedBytes;
56172
+ if (!Number.isSafeInteger(maxBytes) || maxBytes < 1 || !Number.isSafeInteger(reservedBytes) || reservedBytes < 0 || reservedBytes >= maxBytes)
56173
+ throw new Error("Invalid executor reliable retention limits");
56174
+ }
56175
+ #nextId = 0;
56176
+ #items = /* @__PURE__ */ new Map();
56177
+ bytes = 0;
56178
+ get size() {
56179
+ return this.#items.size;
56180
+ }
56181
+ add(text2, order, emergency = false) {
56182
+ const bytes = new TextEncoder().encode(text2).byteLength;
56183
+ if (bytes > EXECUTOR_RELIABLE_MAX_BYTES || this.bytes + bytes > this.maxBytes - (emergency ? 0 : this.reservedBytes) || this.size >= EXECUTOR_RELIABLE_MAX_ITEMS - (emergency || !this.reservedBytes ? 0 : 128))
56184
+ throw new ExecutorRecoveryError("retention-limit");
56185
+ const id = ++this.#nextId;
56186
+ this.#items.set(id, { text: text2, bytes, index: 0, order: order ?? id, sent: false });
56187
+ this.bytes += bytes;
56188
+ return id;
56189
+ }
56190
+ acknowledge(id) {
56191
+ if (!safeId(id) || id > this.#nextId) throw new ExecutorRecoveryError("invalid-transfer");
56192
+ const item = this.#items.get(id);
56193
+ if (!item) return false;
56194
+ if (!item.sent) throw new ExecutorRecoveryError("invalid-transfer");
56195
+ this.bytes -= item.bytes;
56196
+ this.#items.delete(id);
56197
+ return true;
56198
+ }
56199
+ replay() {
56200
+ for (const item of this.#items.values()) item.index = 0;
56201
+ }
56202
+ peekOrder() {
56203
+ for (const item of this.#items.values())
56204
+ if (item.index < Math.max(1, Math.ceil(item.text.length / CHUNK_CHARACTERS))) return item.order;
56205
+ return void 0;
56206
+ }
56207
+ next() {
56208
+ for (const [id, item] of this.#items) {
56209
+ const count = Math.max(1, Math.ceil(item.text.length / CHUNK_CHARACTERS));
56210
+ if (item.index >= count) continue;
56211
+ const index = item.index++;
56212
+ if (item.index === count) item.sent = true;
56213
+ const boundary = (offset) => offset > 0 && offset < item.text.length && /[\uD800-\uDBFF]/.test(item.text[offset - 1]) && /[\uDC00-\uDFFF]/.test(item.text[offset]) ? offset - 1 : offset;
56214
+ return {
56215
+ id,
56216
+ index,
56217
+ count,
56218
+ bytes: item.bytes,
56219
+ text: item.text.slice(
56220
+ boundary(index * CHUNK_CHARACTERS),
56221
+ boundary(Math.min(item.text.length, (index + 1) * CHUNK_CHARACTERS))
56222
+ )
56223
+ };
56224
+ }
56225
+ return void 0;
56226
+ }
56227
+ clear() {
56228
+ this.#items.clear();
56229
+ this.bytes = 0;
56230
+ }
56231
+ };
56232
+ var ExecutorReliableInbox = class {
56233
+ constructor(onExpiry, budget) {
56234
+ this.onExpiry = onExpiry;
56235
+ this.budget = budget;
56236
+ if (budget && (!Number.isSafeInteger(budget.bytes) || budget.bytes < 0 || !Number.isSafeInteger(budget.maxBytes ?? EXECUTOR_RELIABLE_PROCESS_BYTES) || (budget.maxBytes ?? EXECUTOR_RELIABLE_PROCESS_BYTES) < 1))
56237
+ throw new Error("Invalid executor receive budget");
56238
+ }
56239
+ #consumed = 0;
56240
+ #transfer;
56241
+ #timer;
56242
+ receive(value) {
56243
+ var _a, _b;
56244
+ if (!value || typeof value !== "object") throw new ExecutorRecoveryError("invalid-transfer");
56245
+ const part = value;
56246
+ if (!safeId(part.id) || !safeId(part.count) || part.count > Math.ceil(EXECUTOR_RELIABLE_MAX_BYTES / CHUNK_CHARACTERS) || !Number.isSafeInteger(part.index) || part.index < 0 || part.index >= part.count || !Number.isSafeInteger(part.bytes) || part.bytes < 0 || part.bytes > EXECUTOR_RELIABLE_MAX_BYTES || typeof part.text !== "string" || part.text.length > CHUNK_CHARACTERS + 1)
56247
+ throw new ExecutorRecoveryError("invalid-transfer");
56248
+ if (part.id <= this.#consumed) return { id: part.id };
56249
+ if (!this.#transfer) {
56250
+ if (this.budget) {
56251
+ if (this.budget.bytes + part.bytes > (this.budget.maxBytes ?? EXECUTOR_RELIABLE_PROCESS_BYTES))
56252
+ throw new ExecutorRecoveryError("retention-limit");
56253
+ this.budget.bytes += part.bytes;
56254
+ }
56255
+ this.#transfer = { id: part.id, count: part.count, total: part.bytes, parts: [], bytes: 0 };
56256
+ this.#timer = setTimeout(() => {
56257
+ var _a2;
56258
+ this.resetTransfer();
56259
+ (_a2 = this.onExpiry) == null ? void 0 : _a2.call(this);
56260
+ }, EXECUTOR_TRANSFER_TIMEOUT_MS);
56261
+ (_b = (_a = this.#timer).unref) == null ? void 0 : _b.call(_a);
56262
+ }
56263
+ const transfer = this.#transfer;
56264
+ if (transfer.id !== part.id || transfer.count !== part.count || transfer.total !== part.bytes || transfer.parts.length !== part.index)
56265
+ throw new ExecutorRecoveryError("invalid-transfer");
56266
+ transfer.bytes += new TextEncoder().encode(part.text).byteLength;
56267
+ if (transfer.bytes > transfer.total) throw new ExecutorRecoveryError("invalid-transfer");
56268
+ transfer.parts.push(part.text);
56269
+ if (transfer.parts.length !== transfer.count) return;
56270
+ if (transfer.bytes !== transfer.total) throw new ExecutorRecoveryError("invalid-transfer");
56271
+ const text2 = transfer.parts.join("");
56272
+ this.resetTransfer();
56273
+ this.#consumed = part.id;
56274
+ return { id: part.id, text: text2 };
56275
+ }
56276
+ resetTransfer() {
56277
+ if (this.#transfer && this.budget) this.budget.bytes -= this.#transfer.total;
56278
+ this.#transfer = void 0;
56279
+ clearTimeout(this.#timer);
56280
+ this.#timer = void 0;
56281
+ }
56282
+ clear() {
56283
+ this.#consumed = 0;
56284
+ this.resetTransfer();
56285
+ }
56286
+ };
56287
+
56014
56288
  // src/index.ts
56015
56289
  installCodeRunnerNamespace(exports_exports);
56016
56290
  var Rivet = void 0;
@@ -56080,9 +56354,18 @@ var Rivet = void 0;
56080
56354
  DestructureNodeImpl,
56081
56355
  DidRunNodeImpl,
56082
56356
  DocumentNodeImpl,
56357
+ EXECUTOR_RELIABLE_MAX_BYTES,
56358
+ EXECUTOR_RELIABLE_MAX_ITEMS,
56359
+ EXECUTOR_RELIABLE_PROCESS_BYTES,
56360
+ EXECUTOR_RELIABLE_SESSION_BYTES,
56361
+ EXECUTOR_SESSION_V2,
56362
+ EXECUTOR_TRANSFER_TIMEOUT_MS,
56083
56363
  EXPRESSION_OUTPUT_PORT_ID,
56084
56364
  EvaluateNodeImpl,
56085
56365
  ExecutionRecorder,
56366
+ ExecutorRecoveryError,
56367
+ ExecutorReliableInbox,
56368
+ ExecutorReliableOutbox,
56086
56369
  ExpressionNodeImpl,
56087
56370
  ExternalCallNodeImpl,
56088
56371
  ExtractJsonNodeImpl,
@@ -56386,6 +56669,7 @@ var Rivet = void 0;
56386
56669
  evaluateJsonPath,
56387
56670
  evaluateNode,
56388
56671
  executeLLMInvocation,
56672
+ executorDeliveryPolicy,
56389
56673
  expectType,
56390
56674
  expectTypeOptional,
56391
56675
  exportGentraceEvaluationRun,