@codemation/core 1.0.0 → 1.0.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 (58) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/{EngineRuntimeRegistration.types-BP6tsaNP.d.ts → EngineRuntimeRegistration.types-kxQA5NLt.d.ts} +2 -2
  3. package/dist/{EngineWorkflowRunnerService-DzOCa1BW.d.cts → EngineWorkflowRunnerService-Ba2AvBnL.d.cts} +2 -2
  4. package/dist/{InMemoryRunDataFactory-1iz7_SnO.d.cts → InMemoryRunDataFactory-Ou4tQUOS.d.cts} +2 -2
  5. package/dist/{RunIntentService-S-1lW-gS.d.cts → RunIntentService-Dyh_dH0k.d.cts} +528 -467
  6. package/dist/{RunIntentService-BqhmdoA1.d.ts → RunIntentService-dteLjNiT.d.ts} +568 -462
  7. package/dist/bootstrap/index.cjs +2 -2
  8. package/dist/bootstrap/index.d.cts +3 -3
  9. package/dist/bootstrap/index.d.ts +3 -3
  10. package/dist/bootstrap/index.js +2 -2
  11. package/dist/{bootstrap-jqh1kCNI.js → bootstrap-CL68rqWg.js} +3 -2
  12. package/dist/bootstrap-CL68rqWg.js.map +1 -0
  13. package/dist/{bootstrap-BfZE19lK.cjs → bootstrap-Cko6udwL.cjs} +3 -2
  14. package/dist/bootstrap-Cko6udwL.cjs.map +1 -0
  15. package/dist/{index-CGs3Hnoz.d.ts → index-CyfGTfU1.d.ts} +51 -3
  16. package/dist/index.cjs +10 -11
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +96 -3
  19. package/dist/index.d.ts +3 -3
  20. package/dist/index.js +2 -11
  21. package/dist/index.js.map +1 -1
  22. package/dist/{runtime-u6O644ST.js → runtime-284ok0cm.js} +200 -30
  23. package/dist/runtime-284ok0cm.js.map +1 -0
  24. package/dist/{runtime-DWKfb0BI.cjs → runtime-B3Og-_St.cjs} +222 -28
  25. package/dist/runtime-B3Og-_St.cjs.map +1 -0
  26. package/dist/testing.cjs +2 -2
  27. package/dist/testing.d.cts +2 -2
  28. package/dist/testing.d.ts +2 -2
  29. package/dist/testing.js +2 -2
  30. package/package.json +1 -1
  31. package/src/ai/AiHost.ts +9 -0
  32. package/src/bootstrap/runtime/EngineRuntimeRegistrar.ts +4 -0
  33. package/src/browser.ts +1 -0
  34. package/src/contracts/CodemationTelemetryAttributeNames.ts +6 -0
  35. package/src/contracts/NoOpNodeExecutionTelemetry.ts +2 -11
  36. package/src/contracts/NoOpTelemetrySpanScope.ts +46 -10
  37. package/src/contracts/executionPersistenceContracts.ts +30 -0
  38. package/src/contracts/runTypes.ts +10 -0
  39. package/src/contracts/runtimeTypes.ts +8 -0
  40. package/src/contracts/telemetryTypes.ts +8 -0
  41. package/src/contracts/workflowTypes.ts +6 -0
  42. package/src/events/ConnectionInvocationEventPublisher.ts +46 -0
  43. package/src/events/index.ts +1 -0
  44. package/src/events/runEvents.ts +25 -0
  45. package/src/execution/ChildExecutionScopeFactory.ts +58 -0
  46. package/src/execution/ExecutionTelemetryCostTrackingDecoratorFactory.ts +18 -0
  47. package/src/execution/NodeExecutor.ts +10 -2
  48. package/src/execution/NodeRunStateWriter.ts +7 -0
  49. package/src/execution/NodeRunStateWriterFactory.ts +7 -0
  50. package/src/execution/index.ts +1 -0
  51. package/src/index.ts +1 -0
  52. package/src/runtime/EngineFactory.ts +1 -0
  53. package/src/workflow/definition/NodeIterationIdFactory.ts +26 -0
  54. package/src/workflow/index.ts +1 -0
  55. package/dist/bootstrap-BfZE19lK.cjs.map +0 -1
  56. package/dist/bootstrap-jqh1kCNI.js.map +0 -1
  57. package/dist/runtime-DWKfb0BI.cjs.map +0 -1
  58. package/dist/runtime-u6O644ST.js.map +0 -1
@@ -282,6 +282,29 @@ var ConnectionNodeIdFactory = class {
282
282
  }
283
283
  };
284
284
 
285
+ //#endregion
286
+ //#region src/workflow/definition/NodeIterationIdFactory.ts
287
+ /**
288
+ * Unique ids for one per-item iteration of a runnable node's execute loop.
289
+ *
290
+ * Activations are per-batch (one scheduled execution of a node, possibly with N items).
291
+ * Iterations refine that to one identifier per item-index inside the batch loop, so per-item
292
+ * connection invocations and telemetry can be grouped without time-window heuristics.
293
+ */
294
+ var NodeIterationIdFactory = class {
295
+ static create() {
296
+ return `iter_${(0, node_crypto.randomUUID)()}`;
297
+ }
298
+ /** Deterministic id for tests when a stable sequence is needed. */
299
+ static createForTest(seed, sequence) {
300
+ return `iter_${seed}_${sequence}`;
301
+ }
302
+ /** Deterministic id derived from a connection node id (for sub-agent / tool-call scopes). */
303
+ static createForConnection(connectionNodeId, sequence) {
304
+ return `iter_${connectionNodeId}_${sequence}`;
305
+ }
306
+ };
307
+
285
308
  //#endregion
286
309
  //#region src/workflow/definition/WorkflowExecutableNodeClassifier.ts
287
310
  /**
@@ -342,6 +365,40 @@ var WorkflowExecutableNodeClassifierFactory = class {
342
365
  }
343
366
  };
344
367
 
368
+ //#endregion
369
+ //#region src/events/ConnectionInvocationEventPublisher.ts
370
+ /**
371
+ * Publishes per-invocation lifecycle records onto the run {@link RunEventBus}.
372
+ *
373
+ * Surgical, per-invocation events let the UI update the right-side inspector
374
+ * timeline as each LLM round / tool call transitions through `running` → `completed`
375
+ * (or `failed`) without depending on a coarse `runSaved` poll.
376
+ */
377
+ var ConnectionInvocationEventPublisher = class {
378
+ constructor(eventBus, parent) {
379
+ this.eventBus = eventBus;
380
+ this.parent = parent;
381
+ }
382
+ async publish(record) {
383
+ if (!this.eventBus) return;
384
+ const kind = this.kindFor(record);
385
+ if (!kind) return;
386
+ await this.eventBus.publish({
387
+ kind,
388
+ runId: record.runId,
389
+ workflowId: record.workflowId,
390
+ parent: this.parent,
391
+ at: record.updatedAt,
392
+ record
393
+ });
394
+ }
395
+ kindFor(record) {
396
+ if (record.status === "running" || record.status === "queued") return "connectionInvocationStarted";
397
+ if (record.status === "completed") return "connectionInvocationCompleted";
398
+ if (record.status === "failed") return "connectionInvocationFailed";
399
+ }
400
+ };
401
+
345
402
  //#endregion
346
403
  //#region src/events/NodeEventPublisher.ts
347
404
  /** Publishes node lifecycle snapshots onto the run {@link RunEventBus}. */
@@ -362,6 +419,15 @@ var NodeEventPublisher = class {
362
419
  }
363
420
  };
364
421
 
422
+ //#endregion
423
+ //#region \0@oxc-project+runtime@0.95.0/helpers/decorate.js
424
+ function __decorate(decorators, target, key, desc) {
425
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
426
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
427
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
428
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
429
+ }
430
+
365
431
  //#endregion
366
432
  //#region src/binaries/DefaultNodeBinaryAttachmentServiceFactory.ts
367
433
  var DefaultNodeBinaryAttachmentService = class DefaultNodeBinaryAttachmentService {
@@ -660,6 +726,54 @@ var ActivationEnqueueService = class {
660
726
  }
661
727
  };
662
728
 
729
+ //#endregion
730
+ //#region \0@oxc-project+runtime@0.95.0/helpers/decorateMetadata.js
731
+ function __decorateMetadata(k, v) {
732
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
733
+ }
734
+
735
+ //#endregion
736
+ //#region \0@oxc-project+runtime@0.95.0/helpers/decorateParam.js
737
+ function __decorateParam(paramIndex, decorator) {
738
+ return function(target, key) {
739
+ decorator(target, key, paramIndex);
740
+ };
741
+ }
742
+
743
+ //#endregion
744
+ //#region src/execution/ChildExecutionScopeFactory.ts
745
+ let ChildExecutionScopeFactory = class ChildExecutionScopeFactory$1 {
746
+ constructor(activationIdFactory) {
747
+ this.activationIdFactory = activationIdFactory;
748
+ }
749
+ forSubAgent(args) {
750
+ const childActivationId = this.activationIdFactory.makeActivationId();
751
+ const childTelemetry = args.parentSpan.asNodeTelemetry({
752
+ nodeId: args.childNodeId,
753
+ activationId: childActivationId
754
+ });
755
+ const childBinary = args.parentCtx.binary.forNode({
756
+ nodeId: args.childNodeId,
757
+ activationId: childActivationId
758
+ });
759
+ return {
760
+ ...args.parentCtx,
761
+ nodeId: args.childNodeId,
762
+ activationId: childActivationId,
763
+ config: args.childConfig,
764
+ telemetry: childTelemetry,
765
+ binary: childBinary,
766
+ parentInvocationId: args.parentInvocationId,
767
+ iterationId: void 0
768
+ };
769
+ }
770
+ };
771
+ ChildExecutionScopeFactory = __decorate([
772
+ (0, tsyringe.injectable)(),
773
+ __decorateParam(0, (0, tsyringe.inject)(CoreTokens.ActivationIdFactory)),
774
+ __decorateMetadata("design:paramtypes", [Object])
775
+ ], ChildExecutionScopeFactory);
776
+
663
777
  //#endregion
664
778
  //#region src/contracts/itemMeta.ts
665
779
  /**
@@ -960,31 +1074,54 @@ var NoOpTelemetryArtifactReference = class {
960
1074
 
961
1075
  //#endregion
962
1076
  //#region src/contracts/NoOpTelemetrySpanScope.ts
1077
+ /**
1078
+ * Standalone no-op {@link NodeExecutionTelemetry} value used as the return for `asNodeTelemetry`.
1079
+ *
1080
+ * Defined here (instead of in `NoOpNodeExecutionTelemetry.ts`) so that {@link NoOpTelemetrySpanScope}
1081
+ * can return it without importing the other module — both no-ops share this leaf.
1082
+ */
1083
+ const noOpNodeExecutionTelemetry = {
1084
+ traceId: "00000000000000000000000000000000",
1085
+ spanId: "0000000000000000",
1086
+ addSpanEvent(_) {},
1087
+ recordMetric(_) {},
1088
+ attachArtifact(_) {
1089
+ return NoOpTelemetryArtifactReference.value;
1090
+ },
1091
+ end(_ = {}) {},
1092
+ asNodeTelemetry(_) {
1093
+ return noOpNodeExecutionTelemetry;
1094
+ },
1095
+ forNode(_) {
1096
+ return noOpNodeExecutionTelemetry;
1097
+ },
1098
+ startChildSpan(_) {
1099
+ return noOpTelemetrySpanScope;
1100
+ }
1101
+ };
1102
+ const noOpTelemetrySpanScope = {
1103
+ traceId: "00000000000000000000000000000000",
1104
+ spanId: "0000000000000000",
1105
+ addSpanEvent(_) {},
1106
+ recordMetric(_) {},
1107
+ attachArtifact(_) {
1108
+ return NoOpTelemetryArtifactReference.value;
1109
+ },
1110
+ end(_ = {}) {},
1111
+ asNodeTelemetry(_) {
1112
+ return noOpNodeExecutionTelemetry;
1113
+ }
1114
+ };
963
1115
  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
- };
1116
+ static value = noOpTelemetrySpanScope;
1117
+ /** Internal: the shared no-op {@link NodeExecutionTelemetry} that {@link NoOpNodeExecutionTelemetry} re-exposes. */
1118
+ static nodeExecutionTelemetryValue = noOpNodeExecutionTelemetry;
974
1119
  };
975
1120
 
976
1121
  //#endregion
977
1122
  //#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
- };
1123
+ var NoOpNodeExecutionTelemetry = class {
1124
+ static value = NoOpTelemetrySpanScope.nodeExecutionTelemetryValue;
988
1125
  };
989
1126
 
990
1127
  //#endregion
@@ -1025,6 +1162,12 @@ var CodemationTelemetryAttributeNames = class {
1025
1162
  static connectionInvocationId = "codemation.connection.invocation_id";
1026
1163
  static toolName = "codemation.tool.name";
1027
1164
  static traceParentRunId = "codemation.parent.run.id";
1165
+ /** Per-item iteration that emitted this span/metric. Set on spans recorded inside a runnable per-item loop. */
1166
+ static iterationId = "codemation.iteration.id";
1167
+ /** Item index (0-based) of the iteration. */
1168
+ static iterationIndex = "codemation.iteration.index";
1169
+ /** Set when this span/metric was recorded under a sub-agent triggered by an outer LLM/tool call. */
1170
+ static parentInvocationId = "codemation.parent.invocation_id";
1028
1171
  };
1029
1172
 
1030
1173
  //#endregion
@@ -1118,6 +1261,13 @@ var ExecutionTelemetryCostTrackingDecoratorFactory = class {
1118
1261
  telemetry: nodeTelemetry,
1119
1262
  costTracking: args.costTracking.forScope(nodeTelemetry)
1120
1263
  });
1264
+ },
1265
+ asNodeTelemetry: (rescope) => {
1266
+ const nodeTelemetry = args.telemetry.asNodeTelemetry(rescope);
1267
+ return this.decorateNodeExecutionTelemetry({
1268
+ telemetry: nodeTelemetry,
1269
+ costTracking: args.costTracking.forScope(nodeTelemetry)
1270
+ });
1121
1271
  }
1122
1272
  };
1123
1273
  }
@@ -1129,7 +1279,14 @@ var ExecutionTelemetryCostTrackingDecoratorFactory = class {
1129
1279
  addSpanEvent: (event) => args.scope.addSpanEvent(event),
1130
1280
  recordMetric: (metric) => args.scope.recordMetric(metric),
1131
1281
  attachArtifact: (artifact) => args.scope.attachArtifact(artifact),
1132
- end: (endArgs) => args.scope.end(endArgs)
1282
+ end: (endArgs) => args.scope.end(endArgs),
1283
+ asNodeTelemetry: (rescope) => {
1284
+ const nodeTelemetry = args.scope.asNodeTelemetry(rescope);
1285
+ return this.decorateNodeExecutionTelemetry({
1286
+ telemetry: nodeTelemetry,
1287
+ costTracking: args.costTracking.forScope(nodeTelemetry)
1288
+ });
1289
+ }
1133
1290
  };
1134
1291
  }
1135
1292
  };
@@ -1600,13 +1757,17 @@ var NodeExecutor = class {
1600
1757
  const parsed = inputSchema.parse(item.json);
1601
1758
  const runnableCtx = request.ctx;
1602
1759
  const resolvedCtx = await this.itemExprResolver.resolveConfigForItem(runnableCtx, item, i, inputBatch);
1603
- const ctx = this.pickExecutionContext(runnableCtx, resolvedCtx);
1760
+ const iterationCtx = {
1761
+ ...this.pickExecutionContext(runnableCtx, resolvedCtx),
1762
+ iterationId: NodeIterationIdFactory.create(),
1763
+ itemIndex: i
1764
+ };
1604
1765
  const args = {
1605
1766
  input: parsed,
1606
1767
  item,
1607
1768
  itemIndex: i,
1608
1769
  items: inputBatch,
1609
- ctx
1770
+ ctx: iterationCtx
1610
1771
  };
1611
1772
  const raw = await Promise.resolve(node$1.execute(args));
1612
1773
  const normalized = this.outputNormalizer.normalizeExecuteResult({
@@ -2025,12 +2186,13 @@ var NodeInstanceFactoryFactory = class {
2025
2186
  //#region src/execution/NodeRunStateWriter.ts
2026
2187
  var NodeRunStateWriter = class {
2027
2188
  chain = Promise.resolve();
2028
- constructor(workflowExecutionRepository, runId, workflowId, parent, publishNodeEvent) {
2189
+ constructor(workflowExecutionRepository, runId, workflowId, parent, publishNodeEvent, publishConnectionInvocationEvent) {
2029
2190
  this.workflowExecutionRepository = workflowExecutionRepository;
2030
2191
  this.runId = runId;
2031
2192
  this.workflowId = workflowId;
2032
2193
  this.parent = parent;
2033
2194
  this.publishNodeEvent = publishNodeEvent;
2195
+ this.publishConnectionInvocationEvent = publishConnectionInvocationEvent;
2034
2196
  }
2035
2197
  markQueued(args) {
2036
2198
  return this.enqueue(async () => {
@@ -2127,12 +2289,16 @@ var NodeRunStateWriter = class {
2127
2289
  queuedAt: args.queuedAt,
2128
2290
  startedAt: args.startedAt,
2129
2291
  finishedAt: args.finishedAt,
2130
- updatedAt
2292
+ updatedAt,
2293
+ iterationId: args.iterationId,
2294
+ itemIndex: args.itemIndex,
2295
+ parentInvocationId: args.parentInvocationId
2131
2296
  };
2132
2297
  await this.workflowExecutionRepository.save({
2133
2298
  ...state,
2134
2299
  connectionInvocations: [...state.connectionInvocations ?? [], record]
2135
2300
  });
2301
+ if (this.publishConnectionInvocationEvent) await this.publishConnectionInvocationEvent(record);
2136
2302
  });
2137
2303
  }
2138
2304
  enqueue(work) {
@@ -2159,13 +2325,17 @@ var NodeRunStateWriter = class {
2159
2325
  //#endregion
2160
2326
  //#region src/execution/NodeRunStateWriterFactory.ts
2161
2327
  var NodeRunStateWriterFactory = class {
2162
- constructor(workflowExecutionRepository, nodeEventPublisher) {
2328
+ constructor(workflowExecutionRepository, nodeEventPublisher, eventBus) {
2163
2329
  this.workflowExecutionRepository = workflowExecutionRepository;
2164
2330
  this.nodeEventPublisher = nodeEventPublisher;
2331
+ this.eventBus = eventBus;
2165
2332
  }
2166
2333
  create(runId, workflowId, parent) {
2334
+ const connectionInvocationEventPublisher = new ConnectionInvocationEventPublisher(this.eventBus, parent);
2167
2335
  return new NodeRunStateWriter(this.workflowExecutionRepository, runId, workflowId, parent, async (kind, snapshot) => {
2168
2336
  await this.nodeEventPublisher.publish(kind, snapshot);
2337
+ }, async (record) => {
2338
+ await connectionInvocationEventPublisher.publish(record);
2169
2339
  });
2170
2340
  }
2171
2341
  };
@@ -4986,7 +5156,7 @@ var EngineFactory = class {
4986
5156
  const waiters = new EngineWaiters();
4987
5157
  const credentialResolverFactory = new CredentialResolverFactory(deps.credentialSessions);
4988
5158
  const nodeEventPublisher = new NodeEventPublisher(deps.eventBus);
4989
- const nodeStatePublisherFactory = new NodeRunStateWriterFactory(deps.workflowExecutionRepository, nodeEventPublisher);
5159
+ const nodeStatePublisherFactory = new NodeRunStateWriterFactory(deps.workflowExecutionRepository, nodeEventPublisher, deps.eventBus);
4990
5160
  const planningFactory = new EngineWorkflowPlanningFactory(deps.workflowNodeInstanceFactory);
4991
5161
  const executionLimitsPolicy = deps.executionLimitsPolicy ?? new EngineExecutionLimitsPolicy();
4992
5162
  const workflowSnapshotCodec = deps.workflowSnapshotCodec ?? new WorkflowSnapshotCodec(deps.tokenRegistry);
@@ -5309,6 +5479,12 @@ Object.defineProperty(exports, 'CatalogBackedCostTrackingTelemetryFactory', {
5309
5479
  return CatalogBackedCostTrackingTelemetryFactory;
5310
5480
  }
5311
5481
  });
5482
+ Object.defineProperty(exports, 'ChildExecutionScopeFactory', {
5483
+ enumerable: true,
5484
+ get: function () {
5485
+ return ChildExecutionScopeFactory;
5486
+ }
5487
+ });
5312
5488
  Object.defineProperty(exports, 'CodemationTelemetryAttributeNames', {
5313
5489
  enumerable: true,
5314
5490
  get: function () {
@@ -5327,6 +5503,12 @@ Object.defineProperty(exports, 'ConfigDrivenOffloadPolicy', {
5327
5503
  return ConfigDrivenOffloadPolicy;
5328
5504
  }
5329
5505
  });
5506
+ Object.defineProperty(exports, 'ConnectionInvocationEventPublisher', {
5507
+ enumerable: true,
5508
+ get: function () {
5509
+ return ConnectionInvocationEventPublisher;
5510
+ }
5511
+ });
5330
5512
  Object.defineProperty(exports, 'ConnectionNodeIdFactory', {
5331
5513
  enumerable: true,
5332
5514
  get: function () {
@@ -5579,6 +5761,12 @@ Object.defineProperty(exports, 'NodeInstanceFactoryFactory', {
5579
5761
  return NodeInstanceFactoryFactory;
5580
5762
  }
5581
5763
  });
5764
+ Object.defineProperty(exports, 'NodeIterationIdFactory', {
5765
+ enumerable: true,
5766
+ get: function () {
5767
+ return NodeIterationIdFactory;
5768
+ }
5769
+ });
5582
5770
  Object.defineProperty(exports, 'NodeOutputNormalizer', {
5583
5771
  enumerable: true,
5584
5772
  get: function () {
@@ -5705,6 +5893,12 @@ Object.defineProperty(exports, 'WorkflowStoragePolicyEvaluator', {
5705
5893
  return WorkflowStoragePolicyEvaluator;
5706
5894
  }
5707
5895
  });
5896
+ Object.defineProperty(exports, '__decorate', {
5897
+ enumerable: true,
5898
+ get: function () {
5899
+ return __decorate;
5900
+ }
5901
+ });
5708
5902
  Object.defineProperty(exports, '__toESM', {
5709
5903
  enumerable: true,
5710
5904
  get: function () {
@@ -5795,4 +5989,4 @@ Object.defineProperty(exports, 'tool', {
5795
5989
  return tool;
5796
5990
  }
5797
5991
  });
5798
- //# sourceMappingURL=runtime-DWKfb0BI.cjs.map
5992
+ //# sourceMappingURL=runtime-B3Og-_St.cjs.map