@codemation/core 0.7.0 → 0.8.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 (81) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/{EngineRuntimeRegistration.types-_M7KFD3D.d.ts → EngineRuntimeRegistration.types-BP6tsaNP.d.ts} +4 -2
  3. package/dist/{EngineWorkflowRunnerService-D0Cwngv7.d.cts → EngineWorkflowRunnerService-DzOCa1BW.d.cts} +4 -2
  4. package/dist/{InMemoryRunDataFactory-BIWx6e02.d.cts → InMemoryRunDataFactory-1iz7_SnO.d.cts} +24 -4
  5. package/dist/{workflowActivationPolicy-6V3OJD3N.cjs → InMemoryRunEventBusRegistry-B0_C4OnP.cjs} +1 -16
  6. package/dist/InMemoryRunEventBusRegistry-B0_C4OnP.cjs.map +1 -0
  7. package/dist/{workflowActivationPolicy-Td9HTOuD.js → InMemoryRunEventBusRegistry-C2U83Hmv.js} +2 -11
  8. package/dist/InMemoryRunEventBusRegistry-C2U83Hmv.js.map +1 -0
  9. package/dist/{RunIntentService-CuXAIO6_.d.ts → RunIntentService-BqhmdoA1.d.ts} +231 -3
  10. package/dist/{RunIntentService-5k0p-J67.d.cts → RunIntentService-S-1lW-gS.d.cts} +203 -3
  11. package/dist/bootstrap/index.cjs +4 -2
  12. package/dist/bootstrap/index.d.cts +24 -5
  13. package/dist/bootstrap/index.d.ts +4 -4
  14. package/dist/bootstrap/index.js +3 -3
  15. package/dist/{bootstrap-BhYxSivA.js → bootstrap-BoknFKnw.js} +16 -13
  16. package/dist/bootstrap-BoknFKnw.js.map +1 -0
  17. package/dist/{bootstrap-D-TDU9Lu.cjs → bootstrap-Bx1u4cbS.cjs} +16 -13
  18. package/dist/bootstrap-Bx1u4cbS.cjs.map +1 -0
  19. package/dist/{index-BnJ7_IrO.d.ts → index-CVs9rVhl.d.ts} +36 -6
  20. package/dist/index.cjs +48 -83
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +23 -4
  23. package/dist/index.d.ts +3 -3
  24. package/dist/index.js +27 -74
  25. package/dist/index.js.map +1 -1
  26. package/dist/{runtime-CJnObwsU.js → runtime-DUW6tIJ1.js} +423 -33
  27. package/dist/runtime-DUW6tIJ1.js.map +1 -0
  28. package/dist/{runtime-3YVDd2vY.cjs → runtime-Dvo2ru5A.cjs} +548 -32
  29. package/dist/runtime-Dvo2ru5A.cjs.map +1 -0
  30. package/dist/testing.cjs +7 -7
  31. package/dist/testing.cjs.map +1 -1
  32. package/dist/testing.d.cts +2 -2
  33. package/dist/testing.d.ts +2 -2
  34. package/dist/testing.js +4 -4
  35. package/dist/testing.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/ai/AiHost.ts +2 -0
  38. package/src/ai/CallableToolConfig.ts +28 -3
  39. package/src/bootstrap/index.ts +6 -1
  40. package/src/bootstrap/runtime/EngineRuntimeRegistrar.ts +14 -14
  41. package/src/bootstrap/runtime/EngineRuntimeRegistration.types.ts +3 -0
  42. package/src/contracts/CodemationTelemetryAttributeNames.ts +12 -0
  43. package/src/contracts/CodemationTelemetryMetricNames.ts +7 -0
  44. package/src/contracts/CostCatalogContract.ts +16 -0
  45. package/src/contracts/CostTrackingTelemetryContract.ts +47 -0
  46. package/src/contracts/GenAiTelemetryAttributeNames.ts +10 -0
  47. package/src/contracts/NoOpCostTrackingTelemetry.ts +16 -0
  48. package/src/contracts/NoOpCostTrackingTelemetryFactory.ts +9 -0
  49. package/src/contracts/NoOpExecutionTelemetry.ts +26 -0
  50. package/src/contracts/NoOpExecutionTelemetryFactory.ts +16 -0
  51. package/src/contracts/NoOpNodeExecutionTelemetry.ts +15 -0
  52. package/src/contracts/NoOpTelemetryArtifactReference.ts +9 -0
  53. package/src/contracts/NoOpTelemetrySpanScope.ts +22 -0
  54. package/src/contracts/index.ts +1 -0
  55. package/src/contracts/runTypes.ts +4 -1
  56. package/src/contracts/runtimeTypes.ts +7 -0
  57. package/src/contracts/telemetryTypes.ts +105 -0
  58. package/src/contracts/workflowTypes.ts +9 -0
  59. package/src/events/EventPublishingWorkflowExecutionRepository.ts +1 -1
  60. package/src/execution/CatalogBackedCostTrackingTelemetry.ts +81 -0
  61. package/src/execution/CatalogBackedCostTrackingTelemetryFactory.ts +12 -0
  62. package/src/execution/DefaultExecutionContextFactory.ts +23 -0
  63. package/src/execution/ExecutionTelemetryCostTrackingDecoratorFactory.ts +84 -0
  64. package/src/execution/NodeActivationRequestComposer.ts +1 -0
  65. package/src/execution/NodeExecutionSnapshotFactory.ts +2 -0
  66. package/src/execution/StaticCostCatalog.ts +22 -0
  67. package/src/execution/WorkflowRunExecutionContextFactory.ts +2 -0
  68. package/src/execution/index.ts +4 -0
  69. package/src/orchestration/NodeExecutionRequestHandlerService.ts +1 -0
  70. package/src/orchestration/RunContinuationService.ts +4 -0
  71. package/src/orchestration/RunStartService.ts +2 -0
  72. package/src/policies/storage/RunPolicySnapshotFactory.ts +9 -0
  73. package/src/runStorage/InMemoryWorkflowExecutionRepository.ts +4 -2
  74. package/src/testing/WorkflowTestKitNodeRegistrationContextFactory.ts +1 -3
  75. package/src/types/index.ts +5 -0
  76. package/dist/bootstrap-BhYxSivA.js.map +0 -1
  77. package/dist/bootstrap-D-TDU9Lu.cjs.map +0 -1
  78. package/dist/runtime-3YVDd2vY.cjs.map +0 -1
  79. package/dist/runtime-CJnObwsU.js.map +0 -1
  80. package/dist/workflowActivationPolicy-6V3OJD3N.cjs.map +0 -1
  81. package/dist/workflowActivationPolicy-Td9HTOuD.js.map +0 -1
@@ -562,7 +562,8 @@ var NodeExecutionSnapshotFactory = class {
562
562
  error: {
563
563
  message: args.error.message,
564
564
  name: args.error.name,
565
- stack: args.error.stack
565
+ stack: args.error.stack,
566
+ details: args.error.details
566
567
  }
567
568
  };
568
569
  }
@@ -836,14 +837,324 @@ var DefaultAsyncSleeper = class {
836
837
  }
837
838
  };
838
839
 
840
+ //#endregion
841
+ //#region src/contracts/emitPorts.ts
842
+ const EMIT_PORTS_BRAND = Symbol.for("codemation.emitPorts");
843
+ function emitPorts(ports) {
844
+ return {
845
+ [EMIT_PORTS_BRAND]: true,
846
+ ports
847
+ };
848
+ }
849
+ function isPortsEmission(value) {
850
+ return typeof value === "object" && value !== null && EMIT_PORTS_BRAND in value && value[EMIT_PORTS_BRAND] === true;
851
+ }
852
+ function isUnbrandedPortsEmissionShape(value) {
853
+ return typeof value === "object" && value !== null && "ports" in value && !isPortsEmission(value);
854
+ }
855
+
856
+ //#endregion
857
+ //#region src/contracts/NoRetryPolicy.ts
858
+ var NoRetryPolicy = class {
859
+ kind = "none";
860
+ };
861
+
862
+ //#endregion
863
+ //#region src/contracts/RetryPolicy.ts
864
+ var RetryPolicy = class {
865
+ kind = "fixed";
866
+ constructor(maxAttempts, delayMs) {
867
+ this.maxAttempts = maxAttempts;
868
+ this.delayMs = delayMs;
869
+ if (!Number.isFinite(maxAttempts) || maxAttempts < 1 || !Number.isInteger(maxAttempts)) throw new Error(`RetryPolicy.maxAttempts must be a positive integer, got ${maxAttempts}`);
870
+ if (!Number.isFinite(delayMs) || delayMs < 0) throw new Error(`RetryPolicy.delayMs must be a non-negative finite number, got ${delayMs}`);
871
+ }
872
+ /** Default for HTTP-style transient failures: 3 tries, 1s between attempts. */
873
+ static defaultForHttp = {
874
+ kind: "fixed",
875
+ maxAttempts: 3,
876
+ delayMs: 1e3
877
+ };
878
+ /** Default for LLM / agent calls: 3 tries, 2s fixed backoff. */
879
+ static defaultForAiAgent = {
880
+ kind: "fixed",
881
+ maxAttempts: 3,
882
+ delayMs: 2e3
883
+ };
884
+ };
885
+
886
+ //#endregion
887
+ //#region src/contracts/ExpRetryPolicy.ts
888
+ var ExpRetryPolicy = class {
889
+ kind = "exponential";
890
+ constructor(maxAttempts, initialDelayMs, multiplier, maxDelayMs, jitter) {
891
+ this.maxAttempts = maxAttempts;
892
+ this.initialDelayMs = initialDelayMs;
893
+ this.multiplier = multiplier;
894
+ this.maxDelayMs = maxDelayMs;
895
+ this.jitter = jitter;
896
+ if (!Number.isFinite(maxAttempts) || maxAttempts < 1 || !Number.isInteger(maxAttempts)) throw new Error(`ExpRetryPolicy.maxAttempts must be a positive integer, got ${maxAttempts}`);
897
+ if (!Number.isFinite(initialDelayMs) || initialDelayMs < 0) throw new Error(`ExpRetryPolicy.initialDelayMs must be a non-negative finite number, got ${initialDelayMs}`);
898
+ if (!Number.isFinite(multiplier) || multiplier < 1) throw new Error(`ExpRetryPolicy.multiplier must be >= 1, got ${multiplier}`);
899
+ }
900
+ };
901
+
902
+ //#endregion
903
+ //#region src/contracts/credentialTypes.ts
904
+ var CredentialUnboundError = class CredentialUnboundError extends Error {
905
+ constructor(bindingKey, acceptedTypes = []) {
906
+ super(CredentialUnboundError.createMessage(bindingKey, acceptedTypes));
907
+ this.bindingKey = bindingKey;
908
+ this.acceptedTypes = acceptedTypes;
909
+ this.name = "CredentialUnboundError";
910
+ }
911
+ static createMessage(bindingKey, acceptedTypes) {
912
+ const acceptedTypesSuffix = acceptedTypes.length > 0 ? ` Accepted credential types: ${acceptedTypes.join(", ")}.` : "";
913
+ return `Credential slot "${bindingKey.slotKey}" is not bound for workflow ${bindingKey.workflowId} node ${bindingKey.nodeId}.${acceptedTypesSuffix}`;
914
+ }
915
+ };
916
+
917
+ //#endregion
918
+ //#region src/contracts/CostTrackingTelemetryContract.ts
919
+ const CostTrackingTelemetryMetricNames = {
920
+ usage: "codemation.cost.usage",
921
+ estimatedCost: "codemation.cost.estimated"
922
+ };
923
+ const CostTrackingTelemetryAttributeNames = {
924
+ component: "cost.component",
925
+ provider: "cost.provider",
926
+ operation: "cost.operation",
927
+ pricingKey: "cost.pricing_key",
928
+ usageUnit: "cost.usage_unit",
929
+ currency: "cost.currency",
930
+ currencyScale: "cost.currency_scale",
931
+ estimateKind: "cost.estimate_kind"
932
+ };
933
+
934
+ //#endregion
935
+ //#region src/contracts/NoOpCostTrackingTelemetry.ts
936
+ var NoOpCostTrackingTelemetry = class {
937
+ async captureUsage(_) {}
938
+ forScope(_) {
939
+ return this;
940
+ }
941
+ };
942
+
943
+ //#endregion
944
+ //#region src/contracts/NoOpCostTrackingTelemetryFactory.ts
945
+ var NoOpCostTrackingTelemetryFactory = class {
946
+ create(_) {
947
+ return new NoOpCostTrackingTelemetry();
948
+ }
949
+ };
950
+
951
+ //#endregion
952
+ //#region src/contracts/NoOpTelemetryArtifactReference.ts
953
+ var NoOpTelemetryArtifactReference = class {
954
+ static value = {
955
+ artifactId: "telemetry-artifact-noop",
956
+ traceId: void 0,
957
+ spanId: void 0
958
+ };
959
+ };
960
+
961
+ //#endregion
962
+ //#region src/contracts/NoOpTelemetrySpanScope.ts
963
+ var NoOpTelemetrySpanScope = class {
964
+ static value = {
965
+ traceId: "00000000000000000000000000000000",
966
+ spanId: "0000000000000000",
967
+ addSpanEvent(_) {},
968
+ recordMetric(_) {},
969
+ attachArtifact(_) {
970
+ return NoOpTelemetryArtifactReference.value;
971
+ },
972
+ end(_ = {}) {}
973
+ };
974
+ };
975
+
976
+ //#endregion
977
+ //#region src/contracts/NoOpNodeExecutionTelemetry.ts
978
+ var NoOpNodeExecutionTelemetry = class NoOpNodeExecutionTelemetry {
979
+ static value = {
980
+ ...NoOpTelemetrySpanScope.value,
981
+ forNode(_) {
982
+ return NoOpNodeExecutionTelemetry.value;
983
+ },
984
+ startChildSpan(_) {
985
+ return NoOpTelemetrySpanScope.value;
986
+ }
987
+ };
988
+ };
989
+
990
+ //#endregion
991
+ //#region src/contracts/NoOpExecutionTelemetry.ts
992
+ var NoOpExecutionTelemetry = class {
993
+ static value = {
994
+ traceId: "00000000000000000000000000000000",
995
+ spanId: "0000000000000000",
996
+ addSpanEvent(_) {},
997
+ recordMetric(_) {},
998
+ attachArtifact(_) {
999
+ return NoOpTelemetryArtifactReference.value;
1000
+ },
1001
+ forNode(_) {
1002
+ return NoOpNodeExecutionTelemetry.value;
1003
+ }
1004
+ };
1005
+ };
1006
+
1007
+ //#endregion
1008
+ //#region src/contracts/NoOpExecutionTelemetryFactory.ts
1009
+ var NoOpExecutionTelemetryFactory = class {
1010
+ create(_) {
1011
+ return NoOpExecutionTelemetry.value;
1012
+ }
1013
+ };
1014
+
1015
+ //#endregion
1016
+ //#region src/contracts/CodemationTelemetryAttributeNames.ts
1017
+ var CodemationTelemetryAttributeNames = class {
1018
+ static workflowId = "codemation.workflow.id";
1019
+ static runId = "codemation.run.id";
1020
+ static nodeId = "codemation.node.id";
1021
+ static activationId = "codemation.activation.id";
1022
+ static nodeType = "codemation.node.type";
1023
+ static nodeRole = "codemation.node.role";
1024
+ static workflowFolder = "codemation.workflow.folder";
1025
+ static connectionInvocationId = "codemation.connection.invocation_id";
1026
+ static toolName = "codemation.tool.name";
1027
+ static traceParentRunId = "codemation.parent.run.id";
1028
+ };
1029
+
1030
+ //#endregion
1031
+ //#region src/contracts/GenAiTelemetryAttributeNames.ts
1032
+ var GenAiTelemetryAttributeNames = class {
1033
+ static operationName = "gen_ai.operation.name";
1034
+ static requestModel = "gen_ai.request.model";
1035
+ static usageInputTokens = "gen_ai.usage.input_tokens";
1036
+ static usageOutputTokens = "gen_ai.usage.output_tokens";
1037
+ static usageTotalTokens = "gen_ai.usage.total_tokens";
1038
+ static usageCacheReadInputTokens = "gen_ai.usage.cache_read.input_tokens";
1039
+ static usageCacheCreationInputTokens = "gen_ai.usage.cache_creation.input_tokens";
1040
+ static usageReasoningTokens = "codemation.gen_ai.usage.reasoning_tokens";
1041
+ };
1042
+
1043
+ //#endregion
1044
+ //#region src/contracts/CodemationTelemetryMetricNames.ts
1045
+ var CodemationTelemetryMetricNames = class {
1046
+ static agentTurns = "codemation.ai.turns";
1047
+ static agentToolCalls = "codemation.ai.tool_calls";
1048
+ static gmailMessagesEmitted = "codemation.gmail.messages_emitted";
1049
+ static gmailAttachments = "codemation.gmail.attachments";
1050
+ static gmailAttachmentBytes = "codemation.gmail.attachment_bytes";
1051
+ };
1052
+
1053
+ //#endregion
1054
+ //#region src/contracts/runFinishedAtFactory.ts
1055
+ /** Derives workflow end time from persisted run root or node snapshots for run listings. */
1056
+ var RunFinishedAtFactory = class {
1057
+ static resolveIso(state) {
1058
+ if (state.finishedAt && state.status !== "running" && state.status !== "pending") return state.finishedAt;
1059
+ if (state.status === "running" || state.status === "pending") return;
1060
+ let max;
1061
+ for (const snap of Object.values(state.nodeSnapshotsByNodeId)) if (snap?.finishedAt && (!max || snap.finishedAt > max)) max = snap.finishedAt;
1062
+ return max;
1063
+ }
1064
+ };
1065
+
1066
+ //#endregion
1067
+ //#region src/contracts/workflowTypes.ts
1068
+ function nodeRef(nodeId) {
1069
+ return nodeId;
1070
+ }
1071
+ const branchRef = (index) => `$${index}`;
1072
+
1073
+ //#endregion
1074
+ //#region src/contracts/workflowActivationPolicy.ts
1075
+ /** Default for tests and harnesses: every workflow is treated as active (legacy behavior). */
1076
+ var AllWorkflowsActiveWorkflowActivationPolicy = class {
1077
+ isActive(_workflowId) {
1078
+ return true;
1079
+ }
1080
+ };
1081
+
1082
+ //#endregion
1083
+ //#region src/execution/ExecutionTelemetryCostTrackingDecoratorFactory.ts
1084
+ var ExecutionTelemetryCostTrackingDecoratorFactory = class {
1085
+ decorateExecutionTelemetry(args) {
1086
+ return {
1087
+ traceId: args.telemetry.traceId,
1088
+ spanId: args.telemetry.spanId,
1089
+ costTracking: args.costTracking,
1090
+ addSpanEvent: (event) => args.telemetry.addSpanEvent(event),
1091
+ recordMetric: (metric) => args.telemetry.recordMetric(metric),
1092
+ attachArtifact: (artifact) => args.telemetry.attachArtifact(artifact),
1093
+ forNode: (nodeArgs) => {
1094
+ const nodeTelemetry = args.telemetry.forNode(nodeArgs);
1095
+ return this.decorateNodeExecutionTelemetry({
1096
+ telemetry: nodeTelemetry,
1097
+ costTracking: args.costTracking.forScope(nodeTelemetry)
1098
+ });
1099
+ }
1100
+ };
1101
+ }
1102
+ decorateNodeExecutionTelemetry(args) {
1103
+ return {
1104
+ traceId: args.telemetry.traceId,
1105
+ spanId: args.telemetry.spanId,
1106
+ costTracking: args.costTracking,
1107
+ addSpanEvent: (event) => args.telemetry.addSpanEvent(event),
1108
+ recordMetric: (metric) => args.telemetry.recordMetric(metric),
1109
+ attachArtifact: (artifact) => args.telemetry.attachArtifact(artifact),
1110
+ end: (endArgs) => args.telemetry.end(endArgs),
1111
+ startChildSpan: (spanArgs) => this.decorateTelemetrySpanScope({
1112
+ scope: args.telemetry.startChildSpan(spanArgs),
1113
+ costTracking: args.costTracking
1114
+ }),
1115
+ forNode: (nodeArgs) => {
1116
+ const nodeTelemetry = args.telemetry.forNode(nodeArgs);
1117
+ return this.decorateNodeExecutionTelemetry({
1118
+ telemetry: nodeTelemetry,
1119
+ costTracking: args.costTracking.forScope(nodeTelemetry)
1120
+ });
1121
+ }
1122
+ };
1123
+ }
1124
+ decorateTelemetrySpanScope(args) {
1125
+ return {
1126
+ traceId: args.scope.traceId,
1127
+ spanId: args.scope.spanId,
1128
+ costTracking: args.costTracking.forScope(args.scope),
1129
+ addSpanEvent: (event) => args.scope.addSpanEvent(event),
1130
+ recordMetric: (metric) => args.scope.recordMetric(metric),
1131
+ attachArtifact: (artifact) => args.scope.attachArtifact(artifact),
1132
+ end: (endArgs) => args.scope.end(endArgs)
1133
+ };
1134
+ }
1135
+ };
1136
+
839
1137
  //#endregion
840
1138
  //#region src/execution/DefaultExecutionContextFactory.ts
841
1139
  var DefaultExecutionContextFactory = class {
842
- constructor(binaryStorage = new UnavailableBinaryStorage(), currentDate = () => /* @__PURE__ */ new Date()) {
1140
+ telemetryDecoratorFactory = new ExecutionTelemetryCostTrackingDecoratorFactory();
1141
+ constructor(binaryStorage = new UnavailableBinaryStorage(), telemetryFactory = new NoOpExecutionTelemetryFactory(), costTrackingFactory = new NoOpCostTrackingTelemetryFactory(), currentDate = () => /* @__PURE__ */ new Date()) {
843
1142
  this.binaryStorage = binaryStorage;
1143
+ this.telemetryFactory = telemetryFactory;
1144
+ this.costTrackingFactory = costTrackingFactory;
844
1145
  this.currentDate = currentDate;
845
1146
  }
846
1147
  create(args) {
1148
+ const baseTelemetry = args.telemetry ?? this.telemetryFactory.create({
1149
+ runId: args.runId,
1150
+ workflowId: args.workflowId,
1151
+ parent: args.parent,
1152
+ policySnapshot: args.policySnapshot
1153
+ });
1154
+ const telemetry = this.telemetryDecoratorFactory.decorateExecutionTelemetry({
1155
+ telemetry: baseTelemetry,
1156
+ costTracking: baseTelemetry.costTracking ?? this.costTrackingFactory.create({ telemetry: baseTelemetry })
1157
+ });
847
1158
  return {
848
1159
  runId: args.runId,
849
1160
  workflowId: args.workflowId,
@@ -854,12 +1165,84 @@ var DefaultExecutionContextFactory = class {
854
1165
  now: this.currentDate,
855
1166
  data: args.data,
856
1167
  nodeState: args.nodeState,
1168
+ telemetry,
857
1169
  binary: new DefaultExecutionBinaryService(this.binaryStorage, args.workflowId, args.runId, this.currentDate),
858
1170
  getCredential: args.getCredential
859
1171
  };
860
1172
  }
861
1173
  };
862
1174
 
1175
+ //#endregion
1176
+ //#region src/execution/CatalogBackedCostTrackingTelemetry.ts
1177
+ var CatalogBackedCostTrackingTelemetry = class CatalogBackedCostTrackingTelemetry {
1178
+ constructor(currentScope, costCatalog) {
1179
+ this.currentScope = currentScope;
1180
+ this.costCatalog = costCatalog;
1181
+ }
1182
+ async captureUsage(args) {
1183
+ const usageAttributes = this.createUsageAttributes(args);
1184
+ await this.currentScope.recordMetric({
1185
+ name: CostTrackingTelemetryMetricNames.usage,
1186
+ value: args.quantity,
1187
+ unit: args.usageUnit,
1188
+ attributes: usageAttributes
1189
+ });
1190
+ const catalogEntry = this.costCatalog.findEntry(args);
1191
+ if (!catalogEntry) return;
1192
+ const estimatedAmountMinor = Math.round(args.quantity * catalogEntry.pricePerUnitMinor);
1193
+ const costAttributes = this.createCostAttributes(args, catalogEntry.currency, catalogEntry.currencyScale);
1194
+ await this.currentScope.recordMetric({
1195
+ name: CostTrackingTelemetryMetricNames.estimatedCost,
1196
+ value: estimatedAmountMinor,
1197
+ unit: catalogEntry.currency,
1198
+ attributes: costAttributes
1199
+ });
1200
+ return {
1201
+ currency: catalogEntry.currency,
1202
+ currencyScale: catalogEntry.currencyScale,
1203
+ estimatedAmountMinor,
1204
+ estimateKind: "catalog"
1205
+ };
1206
+ }
1207
+ forScope(scope) {
1208
+ return new CatalogBackedCostTrackingTelemetry(scope, this.costCatalog);
1209
+ }
1210
+ createUsageAttributes(args) {
1211
+ return {
1212
+ ...args.attributes,
1213
+ [CostTrackingTelemetryAttributeNames.component]: args.component,
1214
+ [CostTrackingTelemetryAttributeNames.provider]: args.provider,
1215
+ [CostTrackingTelemetryAttributeNames.operation]: args.operation,
1216
+ [CostTrackingTelemetryAttributeNames.pricingKey]: args.pricingKey,
1217
+ [CostTrackingTelemetryAttributeNames.usageUnit]: args.usageUnit
1218
+ };
1219
+ }
1220
+ createCostAttributes(args, currency, currencyScale) {
1221
+ return {
1222
+ ...args.attributes,
1223
+ [CostTrackingTelemetryAttributeNames.component]: args.component,
1224
+ [CostTrackingTelemetryAttributeNames.provider]: args.provider,
1225
+ [CostTrackingTelemetryAttributeNames.operation]: args.operation,
1226
+ [CostTrackingTelemetryAttributeNames.pricingKey]: args.pricingKey,
1227
+ [CostTrackingTelemetryAttributeNames.usageUnit]: args.usageUnit,
1228
+ [CostTrackingTelemetryAttributeNames.currency]: currency,
1229
+ [CostTrackingTelemetryAttributeNames.currencyScale]: currencyScale,
1230
+ [CostTrackingTelemetryAttributeNames.estimateKind]: "catalog"
1231
+ };
1232
+ }
1233
+ };
1234
+
1235
+ //#endregion
1236
+ //#region src/execution/CatalogBackedCostTrackingTelemetryFactory.ts
1237
+ var CatalogBackedCostTrackingTelemetryFactory = class {
1238
+ constructor(costCatalog) {
1239
+ this.costCatalog = costCatalog;
1240
+ }
1241
+ create(args) {
1242
+ return new CatalogBackedCostTrackingTelemetry(args.telemetry, this.costCatalog);
1243
+ }
1244
+ };
1245
+
863
1246
  //#endregion
864
1247
  //#region src/execution/InProcessRetryRunner.ts
865
1248
  var InProcessRetryRunner = class InProcessRetryRunner {
@@ -958,22 +1341,6 @@ var ItemExprResolver = class {
958
1341
  }
959
1342
  };
960
1343
 
961
- //#endregion
962
- //#region src/contracts/emitPorts.ts
963
- const EMIT_PORTS_BRAND = Symbol.for("codemation.emitPorts");
964
- function emitPorts(ports) {
965
- return {
966
- [EMIT_PORTS_BRAND]: true,
967
- ports
968
- };
969
- }
970
- function isPortsEmission(value) {
971
- return typeof value === "object" && value !== null && EMIT_PORTS_BRAND in value && value[EMIT_PORTS_BRAND] === true;
972
- }
973
- function isUnbrandedPortsEmissionShape(value) {
974
- return typeof value === "object" && value !== null && "ports" in value && !isPortsEmission(value);
975
- }
976
-
977
1344
  //#endregion
978
1345
  //#region src/execution/NodeOutputNormalizer.ts
979
1346
  var NodeOutputNormalizer = class {
@@ -1117,6 +1484,10 @@ var NodeActivationRequestComposer = class {
1117
1484
  nodeId: definition.id,
1118
1485
  activationId,
1119
1486
  config: definition.config,
1487
+ telemetry: args.base.telemetry.forNode({
1488
+ nodeId: definition.id,
1489
+ activationId
1490
+ }),
1120
1491
  binary: args.base.binary.forNode({
1121
1492
  nodeId: definition.id,
1122
1493
  activationId
@@ -1913,6 +2284,7 @@ var WorkflowRunExecutionContextFactory = class {
1913
2284
  runId: args.runId,
1914
2285
  workflowId: args.workflowId,
1915
2286
  parent: args.parent,
2287
+ policySnapshot: args.policySnapshot,
1916
2288
  subworkflowDepth: args.subworkflowDepth,
1917
2289
  engineMaxNodeActivations: args.engineMaxNodeActivations,
1918
2290
  engineMaxSubworkflowDepth: args.engineMaxSubworkflowDepth,
@@ -1923,6 +2295,24 @@ var WorkflowRunExecutionContextFactory = class {
1923
2295
  }
1924
2296
  };
1925
2297
 
2298
+ //#endregion
2299
+ //#region src/execution/StaticCostCatalog.ts
2300
+ var StaticCostCatalog = class {
2301
+ entriesByKey;
2302
+ constructor(entries) {
2303
+ this.entriesByKey = new Map(entries.map((entry) => [this.createKeyFromEntry(entry), entry]));
2304
+ }
2305
+ findEntry(args) {
2306
+ return this.entriesByKey.get(this.createKeyFromUsage(args));
2307
+ }
2308
+ createKeyFromEntry(entry) {
2309
+ return `${entry.component}::${entry.provider}::${entry.operation}::${entry.pricingKey}::${entry.usageUnit}`;
2310
+ }
2311
+ createKeyFromUsage(args) {
2312
+ return `${args.component}::${args.provider}::${args.operation}::${args.pricingKey}::${args.usageUnit}`;
2313
+ }
2314
+ };
2315
+
1926
2316
  //#endregion
1927
2317
  //#region src/planning/WorkflowTopologyPlanner.ts
1928
2318
  var WorkflowTopology = class WorkflowTopology {
@@ -2062,6 +2452,7 @@ var RunContinuationService = class {
2062
2452
  workflowId: state.workflowId,
2063
2453
  nodeId: args.nodeId,
2064
2454
  parent: state.parent,
2455
+ policySnapshot: state.policySnapshot,
2065
2456
  subworkflowDepth: state.executionOptions?.subworkflowDepth ?? 0,
2066
2457
  engineMaxNodeActivations: limits.engineMaxNodeActivations,
2067
2458
  engineMaxSubworkflowDepth: limits.engineMaxSubworkflowDepth,
@@ -2582,6 +2973,7 @@ var RunContinuationService = class {
2582
2973
  workflowId: args.state.workflowId,
2583
2974
  nodeId: nextDefinition.id,
2584
2975
  parent: args.state.parent,
2976
+ policySnapshot: args.state.policySnapshot,
2585
2977
  subworkflowDepth: args.state.executionOptions?.subworkflowDepth ?? 0,
2586
2978
  engineMaxNodeActivations: webhookLimits.engineMaxNodeActivations,
2587
2979
  engineMaxSubworkflowDepth: webhookLimits.engineMaxSubworkflowDepth,
@@ -2672,6 +3064,7 @@ var RunContinuationService = class {
2672
3064
  workflowId: state.workflowId,
2673
3065
  nodeId,
2674
3066
  parent: state.parent,
3067
+ policySnapshot: state.policySnapshot,
2675
3068
  subworkflowDepth: state.executionOptions?.subworkflowDepth ?? 0,
2676
3069
  engineMaxNodeActivations: limits.engineMaxNodeActivations,
2677
3070
  engineMaxSubworkflowDepth: limits.engineMaxSubworkflowDepth,
@@ -2685,6 +3078,10 @@ var RunContinuationService = class {
2685
3078
  nodeId,
2686
3079
  activationId,
2687
3080
  config: def.config,
3081
+ telemetry: base.telemetry.forNode({
3082
+ nodeId,
3083
+ activationId
3084
+ }),
2688
3085
  binary: base.binary.forNode({
2689
3086
  nodeId,
2690
3087
  activationId
@@ -3053,6 +3450,9 @@ var RunPolicySnapshotFactory = class {
3053
3450
  return {
3054
3451
  retentionSeconds: prune?.runDataRetentionSeconds ?? defaults?.retentionSeconds,
3055
3452
  binaryRetentionSeconds: prune?.binaryRetentionSeconds ?? defaults?.binaryRetentionSeconds,
3453
+ telemetrySpanRetentionSeconds: prune?.telemetrySpanRetentionSeconds ?? defaults?.telemetrySpanRetentionSeconds,
3454
+ telemetryArtifactRetentionSeconds: prune?.telemetryArtifactRetentionSeconds ?? defaults?.telemetryArtifactRetentionSeconds,
3455
+ telemetryMetricRetentionSeconds: prune?.telemetryMetricRetentionSeconds ?? defaults?.telemetryMetricRetentionSeconds,
3056
3456
  storagePolicy: typeof workflow.storagePolicy === "string" ? workflow.storagePolicy : defaults?.storagePolicy ?? "ALL"
3057
3457
  };
3058
3458
  }
@@ -3100,6 +3500,7 @@ var RunStartService = class {
3100
3500
  workflowId: workflow.id,
3101
3501
  nodeId: startAt,
3102
3502
  parent,
3503
+ policySnapshot,
3103
3504
  subworkflowDepth: mergedExecutionOptions.subworkflowDepth ?? 0,
3104
3505
  engineMaxNodeActivations: mergedExecutionOptions.maxNodeActivations,
3105
3506
  engineMaxSubworkflowDepth: mergedExecutionOptions.maxSubworkflowDepth,
@@ -3198,6 +3599,7 @@ var RunStartService = class {
3198
3599
  workflowId: request.workflow.id,
3199
3600
  nodeId: WorkflowExecutableNodeClassifierFactory.create(request.workflow).firstExecutableNodeIdInDefinitionOrder(request.workflow) ?? "unknown_node",
3200
3601
  parent: request.parent,
3602
+ policySnapshot,
3201
3603
  subworkflowDepth: mergedExecutionOptions.subworkflowDepth ?? 0,
3202
3604
  engineMaxNodeActivations: mergedExecutionOptions.maxNodeActivations,
3203
3605
  engineMaxSubworkflowDepth: mergedExecutionOptions.maxSubworkflowDepth,
@@ -3850,19 +4252,6 @@ var InMemoryRunDataFactory = class {
3850
4252
  }
3851
4253
  };
3852
4254
 
3853
- //#endregion
3854
- //#region src/contracts/runFinishedAtFactory.ts
3855
- /** Derives workflow end time from persisted run root or node snapshots for run listings. */
3856
- var RunFinishedAtFactory = class {
3857
- static resolveIso(state) {
3858
- if (state.finishedAt && state.status !== "running" && state.status !== "pending") return state.finishedAt;
3859
- if (state.status === "running" || state.status === "pending") return;
3860
- let max;
3861
- for (const snap of Object.values(state.nodeSnapshotsByNodeId)) if (snap?.finishedAt && (!max || snap.finishedAt > max)) max = snap.finishedAt;
3862
- return max;
3863
- }
3864
- };
3865
-
3866
4255
  //#endregion
3867
4256
  //#region src/orchestration/NodeExecutionRequestHandlerService.ts
3868
4257
  var NodeExecutionRequestHandlerService = class {
@@ -3897,6 +4286,7 @@ var NodeExecutionRequestHandlerService = class {
3897
4286
  workflowId: state.workflowId,
3898
4287
  nodeId: request.nodeId,
3899
4288
  parent: resolvedParent,
4289
+ policySnapshot: state.policySnapshot,
3900
4290
  subworkflowDepth: state.executionOptions?.subworkflowDepth ?? 0,
3901
4291
  engineMaxNodeActivations: limits.engineMaxNodeActivations,
3902
4292
  engineMaxSubworkflowDepth: limits.engineMaxSubworkflowDepth,
@@ -4907,6 +5297,30 @@ var WorkflowRepositoryWebhookTriggerMatcherFactory = class {
4907
5297
  };
4908
5298
 
4909
5299
  //#endregion
5300
+ Object.defineProperty(exports, 'AllWorkflowsActiveWorkflowActivationPolicy', {
5301
+ enumerable: true,
5302
+ get: function () {
5303
+ return AllWorkflowsActiveWorkflowActivationPolicy;
5304
+ }
5305
+ });
5306
+ Object.defineProperty(exports, 'CatalogBackedCostTrackingTelemetryFactory', {
5307
+ enumerable: true,
5308
+ get: function () {
5309
+ return CatalogBackedCostTrackingTelemetryFactory;
5310
+ }
5311
+ });
5312
+ Object.defineProperty(exports, 'CodemationTelemetryAttributeNames', {
5313
+ enumerable: true,
5314
+ get: function () {
5315
+ return CodemationTelemetryAttributeNames;
5316
+ }
5317
+ });
5318
+ Object.defineProperty(exports, 'CodemationTelemetryMetricNames', {
5319
+ enumerable: true,
5320
+ get: function () {
5321
+ return CodemationTelemetryMetricNames;
5322
+ }
5323
+ });
4910
5324
  Object.defineProperty(exports, 'ConfigDrivenOffloadPolicy', {
4911
5325
  enumerable: true,
4912
5326
  get: function () {
@@ -4925,12 +5339,30 @@ Object.defineProperty(exports, 'CoreTokens', {
4925
5339
  return CoreTokens;
4926
5340
  }
4927
5341
  });
5342
+ Object.defineProperty(exports, 'CostTrackingTelemetryAttributeNames', {
5343
+ enumerable: true,
5344
+ get: function () {
5345
+ return CostTrackingTelemetryAttributeNames;
5346
+ }
5347
+ });
5348
+ Object.defineProperty(exports, 'CostTrackingTelemetryMetricNames', {
5349
+ enumerable: true,
5350
+ get: function () {
5351
+ return CostTrackingTelemetryMetricNames;
5352
+ }
5353
+ });
4928
5354
  Object.defineProperty(exports, 'CredentialResolverFactory', {
4929
5355
  enumerable: true,
4930
5356
  get: function () {
4931
5357
  return CredentialResolverFactory;
4932
5358
  }
4933
5359
  });
5360
+ Object.defineProperty(exports, 'CredentialUnboundError', {
5361
+ enumerable: true,
5362
+ get: function () {
5363
+ return CredentialUnboundError;
5364
+ }
5365
+ });
4934
5366
  Object.defineProperty(exports, 'DefaultAsyncSleeper', {
4935
5367
  enumerable: true,
4936
5368
  get: function () {
@@ -4991,6 +5423,18 @@ Object.defineProperty(exports, 'EngineWorkflowRunnerServiceFactory', {
4991
5423
  return EngineWorkflowRunnerServiceFactory;
4992
5424
  }
4993
5425
  });
5426
+ Object.defineProperty(exports, 'ExpRetryPolicy', {
5427
+ enumerable: true,
5428
+ get: function () {
5429
+ return ExpRetryPolicy;
5430
+ }
5431
+ });
5432
+ Object.defineProperty(exports, 'GenAiTelemetryAttributeNames', {
5433
+ enumerable: true,
5434
+ get: function () {
5435
+ return GenAiTelemetryAttributeNames;
5436
+ }
5437
+ });
4994
5438
  Object.defineProperty(exports, 'HintOnlyOffloadPolicy', {
4995
5439
  enumerable: true,
4996
5440
  get: function () {
@@ -5057,6 +5501,54 @@ Object.defineProperty(exports, 'MissingRuntimeTriggerToken', {
5057
5501
  return MissingRuntimeTriggerToken;
5058
5502
  }
5059
5503
  });
5504
+ Object.defineProperty(exports, 'NoOpCostTrackingTelemetry', {
5505
+ enumerable: true,
5506
+ get: function () {
5507
+ return NoOpCostTrackingTelemetry;
5508
+ }
5509
+ });
5510
+ Object.defineProperty(exports, 'NoOpCostTrackingTelemetryFactory', {
5511
+ enumerable: true,
5512
+ get: function () {
5513
+ return NoOpCostTrackingTelemetryFactory;
5514
+ }
5515
+ });
5516
+ Object.defineProperty(exports, 'NoOpExecutionTelemetry', {
5517
+ enumerable: true,
5518
+ get: function () {
5519
+ return NoOpExecutionTelemetry;
5520
+ }
5521
+ });
5522
+ Object.defineProperty(exports, 'NoOpExecutionTelemetryFactory', {
5523
+ enumerable: true,
5524
+ get: function () {
5525
+ return NoOpExecutionTelemetryFactory;
5526
+ }
5527
+ });
5528
+ Object.defineProperty(exports, 'NoOpNodeExecutionTelemetry', {
5529
+ enumerable: true,
5530
+ get: function () {
5531
+ return NoOpNodeExecutionTelemetry;
5532
+ }
5533
+ });
5534
+ Object.defineProperty(exports, 'NoOpTelemetryArtifactReference', {
5535
+ enumerable: true,
5536
+ get: function () {
5537
+ return NoOpTelemetryArtifactReference;
5538
+ }
5539
+ });
5540
+ Object.defineProperty(exports, 'NoOpTelemetrySpanScope', {
5541
+ enumerable: true,
5542
+ get: function () {
5543
+ return NoOpTelemetrySpanScope;
5544
+ }
5545
+ });
5546
+ Object.defineProperty(exports, 'NoRetryPolicy', {
5547
+ enumerable: true,
5548
+ get: function () {
5549
+ return NoRetryPolicy;
5550
+ }
5551
+ });
5060
5552
  Object.defineProperty(exports, 'NodeEventPublisher', {
5061
5553
  enumerable: true,
5062
5554
  get: function () {
@@ -5111,6 +5603,12 @@ Object.defineProperty(exports, 'PersistedWorkflowTokenRegistry', {
5111
5603
  return PersistedWorkflowTokenRegistry;
5112
5604
  }
5113
5605
  });
5606
+ Object.defineProperty(exports, 'RetryPolicy', {
5607
+ enumerable: true,
5608
+ get: function () {
5609
+ return RetryPolicy;
5610
+ }
5611
+ });
5114
5612
  Object.defineProperty(exports, 'RunFinishedAtFactory', {
5115
5613
  enumerable: true,
5116
5614
  get: function () {
@@ -5153,6 +5651,12 @@ Object.defineProperty(exports, 'StackTraceCallSitePathResolver', {
5153
5651
  return StackTraceCallSitePathResolver;
5154
5652
  }
5155
5653
  });
5654
+ Object.defineProperty(exports, 'StaticCostCatalog', {
5655
+ enumerable: true,
5656
+ get: function () {
5657
+ return StaticCostCatalog;
5658
+ }
5659
+ });
5156
5660
  Object.defineProperty(exports, 'UnavailableBinaryStorage', {
5157
5661
  enumerable: true,
5158
5662
  get: function () {
@@ -5207,6 +5711,12 @@ Object.defineProperty(exports, '__toESM', {
5207
5711
  return __toESM;
5208
5712
  }
5209
5713
  });
5714
+ Object.defineProperty(exports, 'branchRef', {
5715
+ enumerable: true,
5716
+ get: function () {
5717
+ return branchRef;
5718
+ }
5719
+ });
5210
5720
  Object.defineProperty(exports, 'chatModel', {
5211
5721
  enumerable: true,
5212
5722
  get: function () {
@@ -5261,6 +5771,12 @@ Object.defineProperty(exports, 'node', {
5261
5771
  return node;
5262
5772
  }
5263
5773
  });
5774
+ Object.defineProperty(exports, 'nodeRef', {
5775
+ enumerable: true,
5776
+ get: function () {
5777
+ return nodeRef;
5778
+ }
5779
+ });
5264
5780
  Object.defineProperty(exports, 'resolveItemExprsForExecution', {
5265
5781
  enumerable: true,
5266
5782
  get: function () {
@@ -5279,4 +5795,4 @@ Object.defineProperty(exports, 'tool', {
5279
5795
  return tool;
5280
5796
  }
5281
5797
  });
5282
- //# sourceMappingURL=runtime-3YVDd2vY.cjs.map
5798
+ //# sourceMappingURL=runtime-Dvo2ru5A.cjs.map