@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
- const require_di = require('./di-tO6R7VJV.cjs');
1
+ const require_di = require('./di-C-2ep8NZ.cjs');
2
2
  let zod = require("zod");
3
3
  zod = require_di.__toESM(zod);
4
4
  let node_stream_web = require("node:stream/web");
@@ -895,6 +895,58 @@ var NodeEventPublisher = class {
895
895
  }
896
896
  };
897
897
 
898
+ //#endregion
899
+ //#region src/binaries/boundedReadBinary.types.ts
900
+ /**
901
+ * Reads all bytes from an already-opened binary stream into a contiguous `Uint8Array`.
902
+ *
903
+ * Safety contract:
904
+ * - `attachment.size` is checked against `maxBytes` *before* any allocation (no OOM).
905
+ * - A single buffer of exactly `attachment.size` is pre-allocated; the stream fills it
906
+ * directly — no chunks array, no doubling.
907
+ * - A byte-count mismatch between the declared size and actual stream content is an error.
908
+ *
909
+ * This is the single canonical implementation; `ExecutionBinaryService.getBytes`,
910
+ * `getText`, and `getJson` all delegate here. The per-package `readBinaryBody` helpers
911
+ * in `core-nodes` and `core-nodes-ocr` have been removed in favour of this function.
912
+ */
913
+ async function boundedReadBinary(result, attachment, maxBytes = require_di.BINARY_DEFAULT_MAX_BYTES) {
914
+ 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.`);
915
+ const out = new Uint8Array(attachment.size);
916
+ const reader = result.body.getReader();
917
+ let offset = 0;
918
+ while (true) {
919
+ const { done, value } = await reader.read();
920
+ if (done) break;
921
+ if (!value) continue;
922
+ if (offset + value.byteLength > out.byteLength) throw new Error(`Binary stream produced more bytes than the attachment's declared size (${attachment.size}).`);
923
+ out.set(value, offset);
924
+ offset += value.byteLength;
925
+ }
926
+ if (offset !== out.byteLength) throw new Error(`Binary stream produced ${offset} bytes but attachment declared size ${attachment.size}.`);
927
+ return out;
928
+ }
929
+ /** Shared implementation of `getBytes` used by both binary-service classes. */
930
+ async function readBinaryAsBytes(storage, attachment, maxBytes) {
931
+ const result = await storage.openReadStream(attachment.storageKey);
932
+ if (!result) throw new Error("Binary attachment stream is unavailable.");
933
+ return boundedReadBinary(result, attachment, maxBytes);
934
+ }
935
+ /** Shared implementation of `getText` used by both binary-service classes. */
936
+ async function readBinaryAsText(storage, attachment, maxBytes) {
937
+ const bytes = await readBinaryAsBytes(storage, attachment, maxBytes);
938
+ return new TextDecoder().decode(bytes);
939
+ }
940
+ /** Shared implementation of `getJson` used by both binary-service classes. */
941
+ async function readBinaryAsJson(storage, attachment, maxBytes) {
942
+ const text = await readBinaryAsText(storage, attachment, maxBytes);
943
+ try {
944
+ return JSON.parse(text);
945
+ } catch (cause) {
946
+ throw new SyntaxError(`Binary attachment at storage key "${attachment.storageKey}" is not valid JSON: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
947
+ }
948
+ }
949
+
898
950
  //#endregion
899
951
  //#region src/binaries/DefaultNodeBinaryAttachmentServiceFactory.ts
900
952
  var DefaultNodeBinaryAttachmentService = class DefaultNodeBinaryAttachmentService {
@@ -945,6 +997,15 @@ var DefaultNodeBinaryAttachmentService = class DefaultNodeBinaryAttachmentServic
945
997
  async openReadStream(attachment) {
946
998
  return await this.storage.openReadStream(attachment.storageKey);
947
999
  }
1000
+ async getBytes(attachment, maxBytes) {
1001
+ return readBinaryAsBytes(this.storage, attachment, maxBytes);
1002
+ }
1003
+ async getText(attachment, maxBytes) {
1004
+ return readBinaryAsText(this.storage, attachment, maxBytes);
1005
+ }
1006
+ async getJson(attachment, maxBytes) {
1007
+ return readBinaryAsJson(this.storage, attachment, maxBytes);
1008
+ }
948
1009
  createAttachmentId() {
949
1010
  return DefaultNodeBinaryAttachmentService.createAttachmentIdValue(`${this.activationId}-${this.now().getTime()}`);
950
1011
  }
@@ -1008,8 +1069,24 @@ var DefaultExecutionBinaryService = class {
1008
1069
  forNode(args) {
1009
1070
  return new DefaultNodeBinaryAttachmentService(this.storage, this.workflowId, this.runId, args.nodeId, args.activationId, this.now);
1010
1071
  }
1011
- async openReadStream(attachment) {
1012
- return await this.storage.openReadStream(attachment.storageKey);
1072
+ openReadStream(attachment) {
1073
+ return this.storage.openReadStream(attachment.storageKey);
1074
+ }
1075
+ async getBytes(attachment, maxBytes) {
1076
+ const stream = await this.openReadStream(attachment);
1077
+ if (!stream) throw new Error("Binary attachment stream is unavailable.");
1078
+ return boundedReadBinary(stream, attachment, maxBytes);
1079
+ }
1080
+ async getText(attachment, maxBytes) {
1081
+ return new TextDecoder().decode(await this.getBytes(attachment, maxBytes));
1082
+ }
1083
+ async getJson(attachment, maxBytes) {
1084
+ const text = await this.getText(attachment, maxBytes);
1085
+ try {
1086
+ return JSON.parse(text);
1087
+ } catch (cause) {
1088
+ throw new SyntaxError(`Binary attachment at storage key "${attachment.storageKey}" is not valid JSON: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
1089
+ }
1013
1090
  }
1014
1091
  };
1015
1092
 
@@ -4926,12 +5003,26 @@ var InlineDrivingScheduler = class {
4926
5003
  drainingRuns = /* @__PURE__ */ new Set();
4927
5004
  queuesByRunId = /* @__PURE__ */ new Map();
4928
5005
  scheduledRuns = /* @__PURE__ */ new Set();
5006
+ stopped = false;
5007
+ activeDrainPromises = /* @__PURE__ */ new Set();
4929
5008
  constructor(nodeExecutor) {
4930
5009
  this.nodeExecutor = nodeExecutor;
4931
5010
  }
4932
5011
  setContinuation(continuation) {
4933
5012
  this.continuation = continuation;
4934
5013
  }
5014
+ /**
5015
+ * Prevents new drain cycles from being scheduled and waits for all currently-running
5016
+ * drains to complete. Call before closing the DB connection or rolling back test transactions
5017
+ * to ensure no in-flight writes hit a closed/rolled-back connection.
5018
+ *
5019
+ * Bounded: only the drains already in-flight at call time are awaited. Runs that keep
5020
+ * re-scheduling will not schedule new work once stopped is set.
5021
+ */
5022
+ async stop() {
5023
+ this.stopped = true;
5024
+ if (this.activeDrainPromises.size > 0) await Promise.allSettled(this.activeDrainPromises);
5025
+ }
4935
5026
  async prepareDispatch(request) {
4936
5027
  const receipt = {
4937
5028
  receiptId: request.activationId,
@@ -4981,11 +5072,15 @@ var InlineDrivingScheduler = class {
4981
5072
  }
4982
5073
  }
4983
5074
  scheduleDrain(runId) {
4984
- if (this.drainingRuns.has(runId) || this.scheduledRuns.has(runId)) return;
5075
+ if (this.stopped || this.drainingRuns.has(runId) || this.scheduledRuns.has(runId)) return;
4985
5076
  this.scheduledRuns.add(runId);
4986
5077
  setImmediate(() => {
4987
5078
  this.scheduledRuns.delete(runId);
4988
- this.drainRun(runId);
5079
+ if (this.stopped) return;
5080
+ const p = this.drainRun(runId).finally(() => {
5081
+ this.activeDrainPromises.delete(p);
5082
+ });
5083
+ this.activeDrainPromises.add(p);
4989
5084
  });
4990
5085
  }
4991
5086
  async resumeAfterExecutionResult(continuation, request, outputs) {
@@ -7056,4 +7151,4 @@ Object.defineProperty(exports, 'tool', {
7056
7151
  return tool;
7057
7152
  }
7058
7153
  });
7059
- //# sourceMappingURL=runtime-CyW9c9XM.cjs.map
7154
+ //# sourceMappingURL=runtime-rrH8-Ouq.cjs.map