@codemation/core 0.12.0 → 0.13.1

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 (62) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/{CostCatalogContract-DD7fQ4FF.d.cts → CostCatalogContract-Dxq1BTyi.d.cts} +2 -2
  3. package/dist/{EngineRuntimeRegistration.types-DTV5_7Jw.d.cts → EngineRuntimeRegistration.types-CqcTWexS.d.cts} +3 -3
  4. package/dist/{EngineRuntimeRegistration.types-Dl92Hdoi.d.ts → EngineRuntimeRegistration.types-Cr75cSfL.d.ts} +2 -2
  5. package/dist/{InMemoryRunDataFactory-qMiYjhCK.d.cts → InMemoryRunDataFactory-Csy2evr_.d.cts} +5 -2
  6. package/dist/{ItemsInputNormalizer-Div-fb6a.cjs → ItemsInputNormalizer-57EdA1ad.cjs} +2 -2
  7. package/dist/{ItemsInputNormalizer-Div-fb6a.cjs.map → ItemsInputNormalizer-57EdA1ad.cjs.map} +1 -1
  8. package/dist/{ItemsInputNormalizer-C09a7iFP.d.ts → ItemsInputNormalizer-BWtlwdVI.d.ts} +2 -2
  9. package/dist/{ItemsInputNormalizer-BhuxvZh5.js → ItemsInputNormalizer-BkSvmfAW.js} +2 -2
  10. package/dist/{ItemsInputNormalizer-BhuxvZh5.js.map → ItemsInputNormalizer-BkSvmfAW.js.map} +1 -1
  11. package/dist/{ItemsInputNormalizer-DLaD6rTl.d.cts → ItemsInputNormalizer-pLrWwUAP.d.cts} +3 -3
  12. package/dist/{RunIntentService-CWMMrAP4.d.cts → RunIntentService-BitgkKaT.d.cts} +2 -2
  13. package/dist/{RunIntentService-BOSGwmqn.d.ts → RunIntentService-DYpqfu6D.d.ts} +2 -2
  14. package/dist/{agentMcpTypes-DUmniLOY.d.cts → agentMcpTypes-DGIwk6Ue.d.cts} +20 -2
  15. package/dist/bootstrap/index.cjs +3 -3
  16. package/dist/bootstrap/index.d.cts +16 -5
  17. package/dist/bootstrap/index.d.ts +5 -5
  18. package/dist/bootstrap/index.js +3 -3
  19. package/dist/{bootstrap-CKTMMNmL.js → bootstrap-DB3jpo8F.js} +3 -3
  20. package/dist/{bootstrap-CKTMMNmL.js.map → bootstrap-DB3jpo8F.js.map} +1 -1
  21. package/dist/{bootstrap-D460dCgS.cjs → bootstrap-UDyH8OfK.cjs} +3 -3
  22. package/dist/{bootstrap-D460dCgS.cjs.map → bootstrap-UDyH8OfK.cjs.map} +1 -1
  23. package/dist/browser.cjs +3 -2
  24. package/dist/browser.d.cts +4 -4
  25. package/dist/browser.d.ts +3 -3
  26. package/dist/browser.js +3 -3
  27. package/dist/contracts.d.cts +5 -5
  28. package/dist/contracts.d.ts +2 -2
  29. package/dist/{di-tO6R7VJV.cjs → di-C-2ep8NZ.cjs} +9 -1
  30. package/dist/di-C-2ep8NZ.cjs.map +1 -0
  31. package/dist/{di-DdsgWfVy.js → di-D9Mv3kF3.js} +4 -2
  32. package/dist/di-D9Mv3kF3.js.map +1 -0
  33. package/dist/{executionPersistenceContracts-DenJJK2T.d.cts → executionPersistenceContracts-CN9d7AnL.d.cts} +2 -2
  34. package/dist/{index-BZDhEQ6W.d.ts → index-C2P-fOAx.d.ts} +82 -5
  35. package/dist/{index-CSKKuK60.d.ts → index-rllWL4r-.d.ts} +20 -2
  36. package/dist/index.cjs +23 -3
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.d.cts +71 -8
  39. package/dist/index.d.ts +5 -5
  40. package/dist/index.js +22 -4
  41. package/dist/index.js.map +1 -1
  42. package/dist/{params-DqRvku2h.d.cts → params-DRUr0F5v.d.cts} +2 -2
  43. package/dist/{runtime-BPZgnZ9G.js → runtime-iHBN1jyD.js} +101 -6
  44. package/dist/runtime-iHBN1jyD.js.map +1 -0
  45. package/dist/{runtime-CyW9c9XM.cjs → runtime-rrH8-Ouq.cjs} +101 -6
  46. package/dist/runtime-rrH8-Ouq.cjs.map +1 -0
  47. package/dist/testing.cjs +3 -3
  48. package/dist/testing.d.cts +3 -3
  49. package/dist/testing.d.ts +3 -3
  50. package/dist/testing.js +3 -3
  51. package/package.json +1 -1
  52. package/src/binaries/DefaultExecutionBinaryServiceFactory.ts +27 -2
  53. package/src/binaries/DefaultNodeBinaryAttachmentServiceFactory.ts +14 -0
  54. package/src/binaries/boundedReadBinary.types.ts +90 -0
  55. package/src/contracts/runtimeTypes.ts +19 -0
  56. package/src/contracts/workspaceFileTypes.ts +73 -0
  57. package/src/index.ts +2 -0
  58. package/src/scheduler/InlineDrivingScheduler.ts +23 -2
  59. package/dist/di-DdsgWfVy.js.map +0 -1
  60. package/dist/di-tO6R7VJV.cjs.map +0 -1
  61. package/dist/runtime-BPZgnZ9G.js.map +0 -1
  62. package/dist/runtime-CyW9c9XM.cjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import { C as resolveItemExprsForExecution, T as ConnectionNodeIdFactory, _ as NodeIterationIdFactory, a as injectable, b as AgentConfigInspector, g as CredentialUnboundError, h as SuspensionRequest, v as AgentConnectionNodeCollector } from "./di-DdsgWfVy.js";
1
+ import { E as ConnectionNodeIdFactory, _ as CredentialUnboundError, a as injectable, g as SuspensionRequest, h as BINARY_DEFAULT_MAX_BYTES, v as NodeIterationIdFactory, w as resolveItemExprsForExecution, x as AgentConfigInspector, y as AgentConnectionNodeCollector } from "./di-D9Mv3kF3.js";
2
2
  import { ZodError, z } from "zod";
3
3
  import { ReadableStream } from "node:stream/web";
4
4
  import { createHash } from "node:crypto";
@@ -890,6 +890,58 @@ var NodeEventPublisher = class {
890
890
  }
891
891
  };
892
892
 
893
+ //#endregion
894
+ //#region src/binaries/boundedReadBinary.types.ts
895
+ /**
896
+ * Reads all bytes from an already-opened binary stream into a contiguous `Uint8Array`.
897
+ *
898
+ * Safety contract:
899
+ * - `attachment.size` is checked against `maxBytes` *before* any allocation (no OOM).
900
+ * - A single buffer of exactly `attachment.size` is pre-allocated; the stream fills it
901
+ * directly — no chunks array, no doubling.
902
+ * - A byte-count mismatch between the declared size and actual stream content is an error.
903
+ *
904
+ * This is the single canonical implementation; `ExecutionBinaryService.getBytes`,
905
+ * `getText`, and `getJson` all delegate here. The per-package `readBinaryBody` helpers
906
+ * in `core-nodes` and `core-nodes-ocr` have been removed in favour of this function.
907
+ */
908
+ async function boundedReadBinary(result, attachment, maxBytes = BINARY_DEFAULT_MAX_BYTES) {
909
+ if (attachment.size > maxBytes) throw new Error(`Binary attachment size ${attachment.size} bytes exceeds maxBytes ${maxBytes}. Raise the node's maxBytes setting if this document is expected to be larger.`);
910
+ const out = new Uint8Array(attachment.size);
911
+ const reader = result.body.getReader();
912
+ let offset = 0;
913
+ while (true) {
914
+ const { done, value } = await reader.read();
915
+ if (done) break;
916
+ if (!value) continue;
917
+ if (offset + value.byteLength > out.byteLength) throw new Error(`Binary stream produced more bytes than the attachment's declared size (${attachment.size}).`);
918
+ out.set(value, offset);
919
+ offset += value.byteLength;
920
+ }
921
+ if (offset !== out.byteLength) throw new Error(`Binary stream produced ${offset} bytes but attachment declared size ${attachment.size}.`);
922
+ return out;
923
+ }
924
+ /** Shared implementation of `getBytes` used by both binary-service classes. */
925
+ async function readBinaryAsBytes(storage, attachment, maxBytes) {
926
+ const result = await storage.openReadStream(attachment.storageKey);
927
+ if (!result) throw new Error("Binary attachment stream is unavailable.");
928
+ return boundedReadBinary(result, attachment, maxBytes);
929
+ }
930
+ /** Shared implementation of `getText` used by both binary-service classes. */
931
+ async function readBinaryAsText(storage, attachment, maxBytes) {
932
+ const bytes = await readBinaryAsBytes(storage, attachment, maxBytes);
933
+ return new TextDecoder().decode(bytes);
934
+ }
935
+ /** Shared implementation of `getJson` used by both binary-service classes. */
936
+ async function readBinaryAsJson(storage, attachment, maxBytes) {
937
+ const text = await readBinaryAsText(storage, attachment, maxBytes);
938
+ try {
939
+ return JSON.parse(text);
940
+ } catch (cause) {
941
+ throw new SyntaxError(`Binary attachment at storage key "${attachment.storageKey}" is not valid JSON: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
942
+ }
943
+ }
944
+
893
945
  //#endregion
894
946
  //#region src/binaries/DefaultNodeBinaryAttachmentServiceFactory.ts
895
947
  var DefaultNodeBinaryAttachmentService = class DefaultNodeBinaryAttachmentService {
@@ -940,6 +992,15 @@ var DefaultNodeBinaryAttachmentService = class DefaultNodeBinaryAttachmentServic
940
992
  async openReadStream(attachment) {
941
993
  return await this.storage.openReadStream(attachment.storageKey);
942
994
  }
995
+ async getBytes(attachment, maxBytes) {
996
+ return readBinaryAsBytes(this.storage, attachment, maxBytes);
997
+ }
998
+ async getText(attachment, maxBytes) {
999
+ return readBinaryAsText(this.storage, attachment, maxBytes);
1000
+ }
1001
+ async getJson(attachment, maxBytes) {
1002
+ return readBinaryAsJson(this.storage, attachment, maxBytes);
1003
+ }
943
1004
  createAttachmentId() {
944
1005
  return DefaultNodeBinaryAttachmentService.createAttachmentIdValue(`${this.activationId}-${this.now().getTime()}`);
945
1006
  }
@@ -1003,8 +1064,24 @@ var DefaultExecutionBinaryService = class {
1003
1064
  forNode(args) {
1004
1065
  return new DefaultNodeBinaryAttachmentService(this.storage, this.workflowId, this.runId, args.nodeId, args.activationId, this.now);
1005
1066
  }
1006
- async openReadStream(attachment) {
1007
- return await this.storage.openReadStream(attachment.storageKey);
1067
+ openReadStream(attachment) {
1068
+ return this.storage.openReadStream(attachment.storageKey);
1069
+ }
1070
+ async getBytes(attachment, maxBytes) {
1071
+ const stream = await this.openReadStream(attachment);
1072
+ if (!stream) throw new Error("Binary attachment stream is unavailable.");
1073
+ return boundedReadBinary(stream, attachment, maxBytes);
1074
+ }
1075
+ async getText(attachment, maxBytes) {
1076
+ return new TextDecoder().decode(await this.getBytes(attachment, maxBytes));
1077
+ }
1078
+ async getJson(attachment, maxBytes) {
1079
+ const text = await this.getText(attachment, maxBytes);
1080
+ try {
1081
+ return JSON.parse(text);
1082
+ } catch (cause) {
1083
+ throw new SyntaxError(`Binary attachment at storage key "${attachment.storageKey}" is not valid JSON: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
1084
+ }
1008
1085
  }
1009
1086
  };
1010
1087
 
@@ -4921,12 +4998,26 @@ var InlineDrivingScheduler = class {
4921
4998
  drainingRuns = /* @__PURE__ */ new Set();
4922
4999
  queuesByRunId = /* @__PURE__ */ new Map();
4923
5000
  scheduledRuns = /* @__PURE__ */ new Set();
5001
+ stopped = false;
5002
+ activeDrainPromises = /* @__PURE__ */ new Set();
4924
5003
  constructor(nodeExecutor) {
4925
5004
  this.nodeExecutor = nodeExecutor;
4926
5005
  }
4927
5006
  setContinuation(continuation) {
4928
5007
  this.continuation = continuation;
4929
5008
  }
5009
+ /**
5010
+ * Prevents new drain cycles from being scheduled and waits for all currently-running
5011
+ * drains to complete. Call before closing the DB connection or rolling back test transactions
5012
+ * to ensure no in-flight writes hit a closed/rolled-back connection.
5013
+ *
5014
+ * Bounded: only the drains already in-flight at call time are awaited. Runs that keep
5015
+ * re-scheduling will not schedule new work once stopped is set.
5016
+ */
5017
+ async stop() {
5018
+ this.stopped = true;
5019
+ if (this.activeDrainPromises.size > 0) await Promise.allSettled(this.activeDrainPromises);
5020
+ }
4930
5021
  async prepareDispatch(request) {
4931
5022
  const receipt = {
4932
5023
  receiptId: request.activationId,
@@ -4976,11 +5067,15 @@ var InlineDrivingScheduler = class {
4976
5067
  }
4977
5068
  }
4978
5069
  scheduleDrain(runId) {
4979
- if (this.drainingRuns.has(runId) || this.scheduledRuns.has(runId)) return;
5070
+ if (this.stopped || this.drainingRuns.has(runId) || this.scheduledRuns.has(runId)) return;
4980
5071
  this.scheduledRuns.add(runId);
4981
5072
  setImmediate(() => {
4982
5073
  this.scheduledRuns.delete(runId);
4983
- this.drainRun(runId);
5074
+ if (this.stopped) return;
5075
+ const p = this.drainRun(runId).finally(() => {
5076
+ this.activeDrainPromises.delete(p);
5077
+ });
5078
+ this.activeDrainPromises.add(p);
4984
5079
  });
4985
5080
  }
4986
5081
  async resumeAfterExecutionResult(continuation, request, outputs) {
@@ -6488,4 +6583,4 @@ var WorkflowRepositoryWebhookTriggerMatcherFactory = class {
6488
6583
 
6489
6584
  //#endregion
6490
6585
  export { CostTrackingTelemetryAttributeNames as $, PersistedWorkflowTokenRegistry as A, node as At, CatalogBackedCostTrackingTelemetryFactory as B, HumanTaskStoreToken as Bt, DefaultDrivingScheduler as C, WhenBuilder as Ct, NodeInstanceFactoryFactory as D, defineNode as Dt, StaticCostCatalog as E, defineBatchNode as Et, InProcessRetryRunnerFactory as F, PersistedRuntimeTypeNameResolver as Ft, AllWorkflowsActiveWorkflowActivationPolicy as G, CodemationTelemetryMetricNames as H, RunnableOutputBehaviorResolver as I, DefinedNodeRegistry as It, NoOpNodeExecutionTelemetry as J, NoOpExecutionTelemetryFactory as K, NodeOutputNormalizer as L, HitlResumeTokenSignerToken as Lt, NodeExecutorFactory as M, InjectableRuntimeDecoratorComposer as Mt, NodeExecutor as N, PersistedRuntimeTypeMetadataStore as Nt, NodeInstanceFactory as O, chatModel as Ot, RunSuspendedError as P, StackTraceCallSitePathResolver as Pt, NoOpCostTrackingTelemetry as Q, ItemExprResolver as R, HitlTimeoutJobSchedulerToken as Rt, HintOnlyOffloadPolicy as S, ChainCursor as St, RunPolicySnapshotFactory as T, isHumanApprovalNode as Tt, GenAiTelemetryAttributeNames as U, DefaultExecutionContextFactory as V, CodemationTelemetryAttributeNames as W, NoOpTelemetryArtifactReference as X, NoOpTelemetrySpanScope as Y, NoOpCostTrackingTelemetryFactory as Z, RunTerminalPersistenceCoordinator as _, WorkflowExecutableNodeClassifier as _t, InMemoryLiveWorkflowRepository as a, isPortsEmission as at, LocalOnlyScheduler as b, WorkflowDefinitionError as bt, EngineFactory as c, CredentialResolverFactory as ct, PollingTriggerRuntime as d, DefaultExecutionBinaryService as dt, CostTrackingTelemetryMetricNames as et, PollingTriggerDedupWindow as f, UnavailableBinaryStorage as ft, WorkflowPolicyErrorServices as g, WorkflowExecutableNodeClassifierFactory as gt, WorkflowStoragePolicyEvaluator as h, DefaultWorkflowGraphFactory as ht, RunIntentService as i, emitPorts as it, MissingRuntimeTriggerToken as j, tool as jt, WorkflowSnapshotCodec as k, getPersistedRuntimeTypeMetadata as kt, Engine as l, getOriginIndexFromItem as lt, InMemoryBinaryStorage as m, ConnectionInvocationEventPublisher as mt, WorkflowRepositoryWebhookTriggerMatcher as n, RetryPolicy as nt, EngineWorkflowRunnerServiceFactory as o, isUnbrandedPortsEmissionShape as ot, InMemoryRunDataFactory as p, NodeEventPublisher as pt, NoOpExecutionTelemetry as q, RunIntentServiceFactory as r, NoRetryPolicy as rt, EngineWorkflowRunnerService as s, DefaultAsyncSleeper as st, WorkflowRepositoryWebhookTriggerMatcherFactory as t, ExpRetryPolicy as tt, NoOpPollingTriggerLogger as u, ChildExecutionScopeFactory as ut, ENGINE_EXECUTION_LIMITS_DEFAULTS as v, ConnectionInvocationIdFactory as vt, ConfigDrivenOffloadPolicy as w, defineHumanApprovalNode as wt, InlineDrivingScheduler as x, NodeIdSlugifier as xt, EngineExecutionLimitsPolicy as y, WorkflowBuilder as yt, InProcessRetryRunner as z, HitlWorkspaceIdToken as zt };
6491
- //# sourceMappingURL=runtime-BPZgnZ9G.js.map
6586
+ //# sourceMappingURL=runtime-iHBN1jyD.js.map