@memberjunction/ai-agent-manager 6.2.0-edge.3 → 6.2.0-edge.5

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @memberjunction/ai-agent-manager@6.2.0-edge.3 build /home/runner/work/MJ/MJ/packages/AI/AgentManager/core
2
+ > @memberjunction/ai-agent-manager@6.2.0-edge.5 build /home/runner/work/MJ/MJ/packages/AI/AgentManager/core
3
3
  > tsc && tsc-alias -f
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,145 @@
1
1
  # @memberjunction/ai-agent-manager
2
2
 
3
+ ## 6.2.0-edge.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [0d81c53]
8
+ - Updated dependencies [0cc6b08]
9
+ - Updated dependencies [0cc6b08]
10
+ - Updated dependencies [0cc6b08]
11
+ - Updated dependencies [0cc6b08]
12
+ - Updated dependencies [fd780a9]
13
+ - Updated dependencies [39b35f1]
14
+ - Updated dependencies [3080e83]
15
+ - Updated dependencies [c159e2f]
16
+ - Updated dependencies [29129bd]
17
+ - Updated dependencies [db39145]
18
+ - Updated dependencies [b14c72f]
19
+ - Updated dependencies [5e4205c]
20
+ - Updated dependencies [0cc6b08]
21
+ - Updated dependencies [db50c6b]
22
+ - Updated dependencies [afc1e0e]
23
+ - Updated dependencies [81aea34]
24
+ - Updated dependencies [ac9b00b]
25
+ - Updated dependencies [5465489]
26
+ - Updated dependencies [d29b5c2]
27
+ - Updated dependencies [0ab85d7]
28
+ - Updated dependencies [9d1eb6a]
29
+ - Updated dependencies [0c634ba]
30
+ - Updated dependencies [223669e]
31
+ - Updated dependencies [2274f42]
32
+ - Updated dependencies [5fed75a]
33
+ - Updated dependencies [1cb1d52]
34
+ - Updated dependencies [542795b]
35
+ - Updated dependencies [db39145]
36
+ - Updated dependencies [b73e3bc]
37
+ - Updated dependencies [08be974]
38
+ - Updated dependencies [fcc3f03]
39
+ - Updated dependencies [7e72c86]
40
+ - Updated dependencies [0cc6b08]
41
+ - Updated dependencies [4e4c82d]
42
+ - Updated dependencies [5fed75a]
43
+ - Updated dependencies [ce758af]
44
+ - Updated dependencies [2a7a098]
45
+ - Updated dependencies [8420f36]
46
+ - Updated dependencies [72dd65c]
47
+ - Updated dependencies [1d29837]
48
+ - Updated dependencies [8c120db]
49
+ - Updated dependencies [3ab85f9]
50
+ - Updated dependencies [0cc6b08]
51
+ - Updated dependencies [0cc6b08]
52
+ - Updated dependencies [17a4137]
53
+ - Updated dependencies [b4afc13]
54
+ - Updated dependencies [5f707d1]
55
+ - Updated dependencies [e1f2583]
56
+ - Updated dependencies [dc38250]
57
+ - @memberjunction/core-entities@6.2.0-edge.5
58
+ - @memberjunction/ai-agents@6.2.0-edge.5
59
+ - @memberjunction/ai-core-plus@6.2.0-edge.5
60
+ - @memberjunction/ai-engine-base@6.2.0-edge.5
61
+ - @memberjunction/aiengine@6.2.0-edge.5
62
+ - @memberjunction/core@6.2.0-edge.5
63
+ - @memberjunction/global@6.2.0-edge.5
64
+ - @memberjunction/templates@6.2.0-edge.5
65
+
66
+ ## 6.2.0-edge.4
67
+
68
+ ### Patch Changes
69
+
70
+ - Updated dependencies [96d6ec2]
71
+ - Updated dependencies [a709bb6]
72
+ - Updated dependencies [51c469d]
73
+ - Updated dependencies [432cb73]
74
+ - Updated dependencies [6cd23e1]
75
+ - Updated dependencies [51634e7]
76
+ - Updated dependencies [1d6e3e8]
77
+ - Updated dependencies [de2dc2f]
78
+ - Updated dependencies [822ed69]
79
+ - Updated dependencies [1da00cb]
80
+ - Updated dependencies [bd0ee83]
81
+ - Updated dependencies [fd2a410]
82
+ - Updated dependencies [0dbd455]
83
+ - Updated dependencies [49f26d9]
84
+ - Updated dependencies [7384dd6]
85
+ - Updated dependencies [88e6902]
86
+ - Updated dependencies [bb3028a]
87
+ - Updated dependencies [6dc3aa9]
88
+ - Updated dependencies [c87f87a]
89
+ - Updated dependencies [0a7c255]
90
+ - Updated dependencies [64b6fa5]
91
+ - Updated dependencies [d86bcbc]
92
+ - Updated dependencies [af6f892]
93
+ - Updated dependencies [aaf74ca]
94
+ - Updated dependencies [7316ac3]
95
+ - Updated dependencies [4c682c1]
96
+ - Updated dependencies [08a4cfc]
97
+ - Updated dependencies [6d5c6ad]
98
+ - Updated dependencies [08b3d7b]
99
+ - Updated dependencies [35d3c95]
100
+ - Updated dependencies [dbc3462]
101
+ - Updated dependencies [0d0ba18]
102
+ - Updated dependencies [b6fcb30]
103
+ - Updated dependencies [f73e192]
104
+ - Updated dependencies [7177e09]
105
+ - Updated dependencies [8704df6]
106
+ - Updated dependencies [1ea4085]
107
+ - Updated dependencies [975948b]
108
+ - Updated dependencies [22c9074]
109
+ - Updated dependencies [88b85fc]
110
+ - Updated dependencies [45359c6]
111
+ - Updated dependencies [aee2d53]
112
+ - Updated dependencies [8ed4049]
113
+ - Updated dependencies [f0c78c3]
114
+ - Updated dependencies [25f7b82]
115
+ - Updated dependencies [35ed7b5]
116
+ - Updated dependencies [d0df5a1]
117
+ - Updated dependencies [d853bf8]
118
+ - Updated dependencies [02bb563]
119
+ - Updated dependencies [a66f4b0]
120
+ - Updated dependencies [90829e3]
121
+ - Updated dependencies [aac148b]
122
+ - Updated dependencies [f2f6f4b]
123
+ - Updated dependencies [9ce70b3]
124
+ - Updated dependencies [bc0e36f]
125
+ - Updated dependencies [d52f9ba]
126
+ - Updated dependencies [0e5a4cd]
127
+ - Updated dependencies [b968642]
128
+ - Updated dependencies [68a7e3b]
129
+ - Updated dependencies [57fea6a]
130
+ - Updated dependencies [1ba9315]
131
+ - Updated dependencies [b8a9e5e]
132
+ - Updated dependencies [e8258a1]
133
+ - Updated dependencies [d2ccfef]
134
+ - @memberjunction/ai-agents@6.2.0-edge.4
135
+ - @memberjunction/ai-core-plus@6.2.0-edge.4
136
+ - @memberjunction/core-entities@6.2.0-edge.4
137
+ - @memberjunction/ai-engine-base@6.2.0-edge.4
138
+ - @memberjunction/aiengine@6.2.0-edge.4
139
+ - @memberjunction/core@6.2.0-edge.4
140
+ - @memberjunction/global@6.2.0-edge.4
141
+ - @memberjunction/templates@6.2.0-edge.4
142
+
3
143
  ## 6.2.0-edge.3
4
144
 
5
145
  ### Patch Changes
@@ -21,6 +21,8 @@ export interface AgentSpecSyncResult {
21
21
  agentId: string;
22
22
  /** Whether the operation succeeded */
23
23
  success: boolean;
24
+ /** Error message when success is false */
25
+ errorMessage?: string;
24
26
  /** Array of all database mutations performed */
25
27
  mutations: AgentSpecSyncMutation[];
26
28
  }
@@ -115,6 +117,12 @@ export declare class AgentSpecSync {
115
117
  * @private
116
118
  */
117
119
  private _mutations;
120
+ /**
121
+ * Maps synthetic/pre-save step correlation IDs (e.g. 'wf-node-1') and step names to
122
+ * their persisted database UUIDs so saveStepPaths can resolve OriginStepID and DestinationStepID.
123
+ * @private
124
+ */
125
+ private _stepIdMap;
118
126
  /**
119
127
  * Create a new AgentSpecSync instance.
120
128
  *
@@ -278,7 +286,9 @@ export declare class AgentSpecSync {
278
286
  */
279
287
  private mapPromptEntityToSpec;
280
288
  /**
281
- * Map MJAIAgentStepEntity to AgentStep format.
289
+ * Map MJAIAgentStepEntity to AgentStep format, preserving execution policy
290
+ * (`TimeoutSeconds`, `RetryCount`, `OnErrorBehavior`) and canvas geometry
291
+ * (`PositionX`, `PositionY`, `Width`, `Height`) across save/load round trips.
282
292
  *
283
293
  * @private
284
294
  * @param step - The agent step entity
@@ -286,7 +296,8 @@ export declare class AgentSpecSync {
286
296
  */
287
297
  private mapStepEntityToSpec;
288
298
  /**
289
- * Map MJAIAgentStepPathEntity to AgentStepPath format.
299
+ * Map MJAIAgentStepPathEntity to AgentStepPath format, preserving canvas routing
300
+ * (`PathPoints`) across save/load round trips.
290
301
  *
291
302
  * @private
292
303
  * @param path - The agent step path entity
@@ -1 +1 @@
1
- {"version":3,"file":"agent-spec-sync.d.ts","sourceRoot":"","sources":["../src/agent-spec-sync.ts"],"names":[],"mappings":"AAAA,O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wH7B;;;;;;;;;;OAUG;YACW,WAAW;IAkDzB;;;;;;;;;;OAUG;YACW,aAAa;IAc3B;;;;;;;;;;;;;;OAcG;YACW,iBAAiB;IA2C/B;;;;;;;;;;OAUG;YACW,mBAAmB;IAsDjC;;;;;;;;;;OAUG;YACW,WAAW;IAkIzB;;;;;;;;;OASG;YACW,SAAS;IAsKvB;;;;;;;;;OASG;YACW,aAAa;IA+E3B;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;IAUtB;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;IAgDtB;;;;;;;;;;;;;;;OAeG;IACI,MAAM,IAAI,SAAS;IAI1B;;;;OAIG;IACH,IAAW,OAAO,IAAI,OAAO,CAE5B;IAED,uCAAuC;IACvC,IAAW,OAAO,IAAI,OAAO,CAE5B;IAED;;;;OAIG;IACH,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAED,wCAAwC;IACxC,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAED;;;;;;;;;;;;;;OAcG;IACI,SAAS,IAAI,IAAI;IAIxB,yCAAyC;IAClC,SAAS,IAAI,IAAI;IAIxB;;;;;;;;;;;;;;;;OAgBG;IACI,UAAU,IAAI,IAAI;IAIzB,0CAA0C;IACnC,UAAU,IAAI,IAAI;IAMzB;;;;;;;;;;OAUG;YACW,wBAAwB;IAuEtC;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,eAAe;IAsCvB;;;;;;;;;;;;;;OAcG;YACW,aAAa;IAuH3B;;;;;;;;;;;;;;OAcG;YACW,gBAAgB;CAmBjC"}
@@ -1,6 +1,10 @@
1
1
  import { Metadata, RunView, LogError } from '@memberjunction/core';
2
2
  import { UUIDsEqual } from '@memberjunction/global';
3
3
  import { StepConfigurationText } from './flow-step-validation.js';
4
+ const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
5
+ function isPersistedUUID(id) {
6
+ return typeof id === 'string' && UUID_REGEX.test(id.trim());
7
+ }
4
8
  /**
5
9
  * AgentSpecSync provides a high-level interface for working with AI Agent metadata in MemberJunction.
6
10
  *
@@ -95,6 +99,12 @@ export class AgentSpecSync {
95
99
  * @private
96
100
  */
97
101
  this._mutations = [];
102
+ /**
103
+ * Maps synthetic/pre-save step correlation IDs (e.g. 'wf-node-1') and step names to
104
+ * their persisted database UUIDs so saveStepPaths can resolve OriginStepID and DestinationStepID.
105
+ * @private
106
+ */
107
+ this._stepIdMap = new Map();
98
108
  if (spec) {
99
109
  this.Spec = this.initializeSpec(spec);
100
110
  this._isDirty = true;
@@ -551,7 +561,9 @@ export class AgentSpecSync {
551
561
  };
552
562
  }
553
563
  /**
554
- * Map MJAIAgentStepEntity to AgentStep format.
564
+ * Map MJAIAgentStepEntity to AgentStep format, preserving execution policy
565
+ * (`TimeoutSeconds`, `RetryCount`, `OnErrorBehavior`) and canvas geometry
566
+ * (`PositionX`, `PositionY`, `Width`, `Height`) across save/load round trips.
555
567
  *
556
568
  * @private
557
569
  * @param step - The agent step entity
@@ -573,11 +585,19 @@ export class AgentSpecSync {
573
585
  LoopBodyType: step.LoopBodyType || undefined,
574
586
  Configuration: step.Configuration || undefined,
575
587
  ActionInputMapping: this.parseJsonField(step.ActionInputMapping),
576
- ActionOutputMapping: this.parseJsonField(step.ActionOutputMapping)
588
+ ActionOutputMapping: this.parseJsonField(step.ActionOutputMapping),
589
+ TimeoutSeconds: step.TimeoutSeconds ?? undefined,
590
+ RetryCount: step.RetryCount ?? undefined,
591
+ OnErrorBehavior: step.OnErrorBehavior || undefined,
592
+ PositionX: step.PositionX ?? undefined,
593
+ PositionY: step.PositionY ?? undefined,
594
+ Width: step.Width ?? undefined,
595
+ Height: step.Height ?? undefined
577
596
  };
578
597
  }
579
598
  /**
580
- * Map MJAIAgentStepPathEntity to AgentStepPath format.
599
+ * Map MJAIAgentStepPathEntity to AgentStepPath format, preserving canvas routing
600
+ * (`PathPoints`) across save/load round trips.
581
601
  *
582
602
  * @private
583
603
  * @param path - The agent step path entity
@@ -590,7 +610,8 @@ export class AgentSpecSync {
590
610
  DestinationStepID: path.DestinationStepID,
591
611
  Condition: path.Condition || undefined,
592
612
  Description: path.Description || undefined,
593
- Priority: path.Priority
613
+ Priority: path.Priority,
614
+ PathPoints: path.PathPoints || undefined
594
615
  };
595
616
  }
596
617
  // ===== SAVING METHODS =====
@@ -662,10 +683,13 @@ export class AgentSpecSync {
662
683
  };
663
684
  }
664
685
  catch (error) {
686
+ const errorMessage = error instanceof Error ? error.message : String(error);
687
+ LogError(`AgentSpecSync.SaveToDatabase failed: ${errorMessage}`);
665
688
  // Return failure with whatever mutations were completed before error
666
689
  return {
667
690
  agentId: this.Spec.ID || '',
668
691
  success: false,
692
+ errorMessage,
669
693
  mutations: this.GetMutations()
670
694
  };
671
695
  }
@@ -681,14 +705,19 @@ export class AgentSpecSync {
681
705
  async saveAgentEntity(validate) {
682
706
  const md = this.providerToUse;
683
707
  const agentEntity = await md.GetEntityObject('MJ: AI Agents', this._contextUser);
684
- // Track if this is an update or create
685
- const isUpdate = !!this.Spec.ID;
686
- // If ID exists, load existing record
687
- if (this.Spec.ID) {
708
+ // Only treat Spec.ID as an existing database record when it is a real UUID.
709
+ // Callers such as WorkflowAgentWriter pass a correlation ID (e.g. 'workflow-...')
710
+ // on a brand-new spec; calling Load() with a non-UUID fails SQL uniqueidentifier conversion.
711
+ let isUpdate = false;
712
+ if (isPersistedUUID(this.Spec.ID)) {
688
713
  const loaded = await agentEntity.Load(this.Spec.ID);
689
714
  if (!loaded) {
690
715
  throw new Error(`Cannot update non-existent agent with ID ${this.Spec.ID}`);
691
716
  }
717
+ isUpdate = true;
718
+ }
719
+ else {
720
+ agentEntity.NewRecord?.();
692
721
  }
693
722
  // Map spec to entity fields
694
723
  agentEntity.Name = this.Spec.Name;
@@ -1052,6 +1081,7 @@ export class AgentSpecSync {
1052
1081
  */
1053
1082
  async saveSteps(agentId) {
1054
1083
  console.log(`🔷 saveSteps: Called with agentId=${agentId}, Steps=${this.Spec.Steps ? this.Spec.Steps.length : 'undefined'}`);
1084
+ this._stepIdMap.clear();
1055
1085
  if (!this.Spec.Steps || this.Spec.Steps.length === 0) {
1056
1086
  console.log('🔷 saveSteps: No steps to save, returning early');
1057
1087
  return;
@@ -1059,11 +1089,16 @@ export class AgentSpecSync {
1059
1089
  console.log(`🔷 saveSteps: Processing ${this.Spec.Steps.length} step(s)...`);
1060
1090
  const md = this.providerToUse;
1061
1091
  for (const stepSpec of this.Spec.Steps) {
1092
+ const originalStepId = stepSpec.ID;
1062
1093
  const stepEntity = await md.GetEntityObject('MJ: AI Agent Steps', this._contextUser);
1063
- // Load existing if ID provided
1064
- const isUpdate = !!(stepSpec.ID && stepSpec.ID !== '');
1065
- if (isUpdate) {
1066
- await stepEntity.Load(stepSpec.ID);
1094
+ // Only load from DB when stepSpec.ID is a real persisted UUID; synthetic IDs
1095
+ // (such as 'wf-node-1' from ConvertTaskGraphToAgentSpec) are new step records.
1096
+ let isUpdate = false;
1097
+ if (isPersistedUUID(stepSpec.ID)) {
1098
+ isUpdate = await stepEntity.Load(stepSpec.ID);
1099
+ }
1100
+ if (!isUpdate) {
1101
+ stepEntity.NewRecord?.();
1067
1102
  }
1068
1103
  // Map fields
1069
1104
  stepEntity.AgentID = agentId;
@@ -1081,6 +1116,28 @@ export class AgentSpecSync {
1081
1116
  // Stored as JSON text even when the model wrote an object, with a Decision step's aliases
1082
1117
  // normalized: the text the Architect's validator compiled.
1083
1118
  stepEntity.Configuration = StepConfigurationText(stepSpec);
1119
+ // Map execution policy and canvas geometry when provided on the spec
1120
+ if (stepSpec.TimeoutSeconds !== undefined) {
1121
+ stepEntity.TimeoutSeconds = stepSpec.TimeoutSeconds ?? null;
1122
+ }
1123
+ if (stepSpec.RetryCount !== undefined) {
1124
+ stepEntity.RetryCount = stepSpec.RetryCount ?? null;
1125
+ }
1126
+ if (stepSpec.OnErrorBehavior !== undefined) {
1127
+ stepEntity.OnErrorBehavior = stepSpec.OnErrorBehavior ?? 'fail';
1128
+ }
1129
+ if (stepSpec.PositionX !== undefined) {
1130
+ stepEntity.PositionX = Math.round(stepSpec.PositionX);
1131
+ }
1132
+ if (stepSpec.PositionY !== undefined) {
1133
+ stepEntity.PositionY = Math.round(stepSpec.PositionY);
1134
+ }
1135
+ if (stepSpec.Width !== undefined) {
1136
+ stepEntity.Width = Math.round(stepSpec.Width);
1137
+ }
1138
+ if (stepSpec.Height !== undefined) {
1139
+ stepEntity.Height = Math.round(stepSpec.Height);
1140
+ }
1084
1141
  // Handle inline prompt creation for Prompt-type steps
1085
1142
  // If StepType is Prompt and PromptID is empty, create a new AIPrompt record
1086
1143
  if (stepSpec.StepType === 'Prompt' && (!stepSpec.PromptID || stepSpec.PromptID === '')) {
@@ -1139,6 +1196,15 @@ export class AgentSpecSync {
1139
1196
  }
1140
1197
  // Track mutation
1141
1198
  this.trackMutation('AI Agent Steps', isUpdate ? 'Update' : 'Create', stepEntity.ID, `${isUpdate ? 'Updated' : 'Created'} step: ${stepSpec.Name}`);
1199
+ // Record both the pre-save correlation ID (e.g. 'wf-node-1') and the step Name
1200
+ // so saveStepPaths can resolve OriginStepID and DestinationStepID to the persisted UUID.
1201
+ if (originalStepId) {
1202
+ this._stepIdMap.set(originalStepId, stepEntity.ID);
1203
+ }
1204
+ if (stepSpec.Name) {
1205
+ this._stepIdMap.set(stepSpec.Name, stepEntity.ID);
1206
+ }
1207
+ this._stepIdMap.set(stepEntity.ID, stepEntity.ID);
1142
1208
  // Update the spec with the saved ID so paths can reference it
1143
1209
  stepSpec.ID = stepEntity.ID;
1144
1210
  console.log(`✅ saveSteps: Created AIAgentStep with ID: ${stepEntity.ID}`);
@@ -1163,48 +1229,50 @@ export class AgentSpecSync {
1163
1229
  }
1164
1230
  console.log(`🔶 saveStepPaths: Processing ${this.Spec.Paths.length} path(s)...`);
1165
1231
  const md = this.providerToUse;
1166
- // Create a map of step names to IDs for easy lookup
1167
- const stepNameToId = new Map();
1232
+ // Combine _stepIdMap (populated during saveSteps, including synthetic IDs like 'wf-node-1')
1233
+ // with stepNameToId for any steps not saved in this pass.
1234
+ const stepRefToId = new Map(this._stepIdMap);
1168
1235
  if (this.Spec.Steps) {
1169
1236
  for (const step of this.Spec.Steps) {
1170
1237
  if (step.ID) {
1171
- stepNameToId.set(step.Name, step.ID);
1238
+ stepRefToId.set(step.Name, step.ID);
1239
+ stepRefToId.set(step.ID, step.ID);
1172
1240
  }
1173
1241
  }
1174
1242
  }
1175
1243
  for (const pathSpec of this.Spec.Paths) {
1176
1244
  const pathEntity = await md.GetEntityObject('MJ: AI Agent Step Paths', this._contextUser);
1177
- // Load existing if ID provided
1178
- const isUpdate = !!(pathSpec.ID && pathSpec.ID !== '');
1179
- if (isUpdate) {
1180
- await pathEntity.Load(pathSpec.ID);
1181
- }
1182
- // Resolve step IDs from step names
1183
- // OriginStepID and DestinationStepID can be either step IDs or step names
1184
- // If they're names, look them up in our map
1185
- let originStepId = pathSpec.OriginStepID;
1186
- let destinationStepId = pathSpec.DestinationStepID;
1187
- // Try to resolve as step names first
1188
- if (stepNameToId.has(pathSpec.OriginStepID)) {
1189
- originStepId = stepNameToId.get(pathSpec.OriginStepID);
1245
+ // Only load from DB when pathSpec.ID is a real persisted UUID; synthetic IDs
1246
+ // (such as 'wf-node-3') are new path records.
1247
+ let isUpdate = false;
1248
+ if (isPersistedUUID(pathSpec.ID)) {
1249
+ isUpdate = await pathEntity.Load(pathSpec.ID);
1190
1250
  }
1191
- if (stepNameToId.has(pathSpec.DestinationStepID)) {
1192
- destinationStepId = stepNameToId.get(pathSpec.DestinationStepID);
1251
+ if (!isUpdate) {
1252
+ pathEntity.NewRecord?.();
1193
1253
  }
1254
+ // Resolve step IDs from synthetic step IDs or step names
1255
+ const originStepId = stepRefToId.get(pathSpec.OriginStepID) ?? pathSpec.OriginStepID;
1256
+ const destinationStepId = stepRefToId.get(pathSpec.DestinationStepID) ?? pathSpec.DestinationStepID;
1194
1257
  // Map fields
1195
1258
  pathEntity.OriginStepID = originStepId;
1196
1259
  pathEntity.DestinationStepID = destinationStepId;
1197
1260
  pathEntity.Condition = pathSpec.Condition || null;
1198
1261
  pathEntity.Description = pathSpec.Description || null;
1199
1262
  pathEntity.Priority = pathSpec.Priority;
1263
+ if (pathSpec.PathPoints !== undefined) {
1264
+ pathEntity.PathPoints = pathSpec.PathPoints || null;
1265
+ }
1200
1266
  const saved = await pathEntity.Save();
1201
1267
  if (!saved) {
1202
1268
  throw new Error(`Failed to save path from "${pathSpec.OriginStepID}" to "${pathSpec.DestinationStepID}"`);
1203
1269
  }
1204
1270
  // Track mutation
1205
1271
  this.trackMutation('AI Agent Step Paths', isUpdate ? 'Update' : 'Create', pathEntity.ID, `${isUpdate ? 'Updated' : 'Created'} path from "${pathSpec.OriginStepID}" to "${pathSpec.DestinationStepID}"`);
1206
- // Update the spec with the saved ID
1272
+ // Update the spec with the saved IDs
1207
1273
  pathSpec.ID = pathEntity.ID;
1274
+ pathSpec.OriginStepID = originStepId;
1275
+ pathSpec.DestinationStepID = destinationStepId;
1208
1276
  console.log(`✅ saveStepPaths: Created AIAgentStepPath with ID: ${pathEntity.ID}`);
1209
1277
  }
1210
1278
  console.log(`✅ saveStepPaths: Successfully saved all ${this.Spec.Paths.length} path(s)`);