newo 3.7.0 → 3.7.2

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.
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Flow metadata sync — reconciles local flow metadata.yaml with the platform.
3
+ *
4
+ * Closes the gap behind GH issue #3 (push wiping flow event subscriptions and
5
+ * title): before this module existed, push only updated skill scripts. Local
6
+ * edits to flow title, events, or state_fields silently never reached the
7
+ * platform; new events created via `newo create-event` had no path to flow
8
+ * therefore disappeared from local metadata.yaml after a subsequent pull.
9
+ *
10
+ * Reconciliation strategy per flow (only runs when metadata.yaml hash changed):
11
+ * - Compare local FlowMetadata against fresh GET responses from the platform
12
+ * - Update flow title/description/runner via PATCH /api/v1/designer/flows/{id}
13
+ * - For each child collection (events, state_fields):
14
+ * • idn present locally + missing remotely → create
15
+ * • idn present in both, contents differ → update
16
+ * • idn missing locally + present remotely → delete
17
+ *
18
+ * Hash-gating is critical: if the user never touched metadata.yaml, we never
19
+ * compute a remote diff, which means a stale or partially-pulled tree cannot
20
+ * accidentally wipe events that were created out-of-band via the Builder UI.
21
+ */
22
+ import type { AxiosInstance } from 'axios';
23
+ import type { FlowMetadata, FlowEvent, FlowState } from '../types.js';
24
+ export interface FlowMetadataSyncCounts {
25
+ flowsUpdated: number;
26
+ eventsCreated: number;
27
+ eventsUpdated: number;
28
+ eventsDeleted: number;
29
+ statesCreated: number;
30
+ statesUpdated: number;
31
+ statesDeleted: number;
32
+ errors: string[];
33
+ }
34
+ export declare function emptyFlowSyncCounts(): FlowMetadataSyncCounts;
35
+ /**
36
+ * True when remote FlowEvent fields differ from what the local metadata says.
37
+ * We only compare semantic fields the platform stores - `id` is platform-owned.
38
+ */
39
+ export declare function flowEventDiffers(local: FlowEvent, remote: FlowEvent): boolean;
40
+ export declare function flowStateDiffers(local: FlowState, remote: FlowState): boolean;
41
+ /**
42
+ * Reconcile one flow's metadata with the platform.
43
+ *
44
+ * @param client authenticated Axios client
45
+ * @param flowId platform flow ID (UUID)
46
+ * @param local parsed FlowMetadata from the customer's local YAML
47
+ * @param remoteFlow flow data fetched from GET /flows/{id} - if null,
48
+ * flow-level updates are skipped (still syncs children).
49
+ * Pass null when caller already knows the GET endpoint
50
+ * will 404 (e.g. legacy data) or wants children-only.
51
+ * @param verbose when true, emits per-operation log lines
52
+ * @param counts shared counter mutated in place across multiple flows
53
+ */
54
+ export declare function syncFlowMetadata(client: AxiosInstance, flowId: string, local: FlowMetadata, remoteFlow: {
55
+ title: string;
56
+ description: string | null;
57
+ default_runner_type?: string;
58
+ } | null, verbose: boolean, counts: FlowMetadataSyncCounts): Promise<void>;
59
+ /**
60
+ * Combined count of operations across all categories.
61
+ */
62
+ export declare function totalFlowSyncOps(counts: FlowMetadataSyncCounts): number;
63
+ /**
64
+ * Human-readable summary line for the push report.
65
+ */
66
+ export declare function describeFlowSyncCounts(counts: FlowMetadataSyncCounts): string;
67
+ //# sourceMappingURL=flow-metadata.d.ts.map
@@ -0,0 +1,283 @@
1
+ import { listFlowEvents, listFlowStates, createFlowEvent, updateFlowEvent, deleteFlowEvent, createFlowState, updateFlowState, deleteFlowState, updateFlow } from '../api.js';
2
+ export function emptyFlowSyncCounts() {
3
+ return {
4
+ flowsUpdated: 0,
5
+ eventsCreated: 0,
6
+ eventsUpdated: 0,
7
+ eventsDeleted: 0,
8
+ statesCreated: 0,
9
+ statesUpdated: 0,
10
+ statesDeleted: 0,
11
+ errors: []
12
+ };
13
+ }
14
+ /**
15
+ * True when remote FlowEvent fields differ from what the local metadata says.
16
+ * We only compare semantic fields the platform stores - `id` is platform-owned.
17
+ */
18
+ export function flowEventDiffers(local, remote) {
19
+ return (normalizeStr(local.description) !== normalizeStr(remote.description) ||
20
+ normalizeStr(local.skill_selector) !== normalizeStr(remote.skill_selector) ||
21
+ normalizeStr(local.skill_idn) !== normalizeStr(remote.skill_idn) ||
22
+ normalizeStr(local.state_idn) !== normalizeStr(remote.state_idn) ||
23
+ normalizeStr(local.interrupt_mode) !== normalizeStr(remote.interrupt_mode) ||
24
+ normalizeStr(local.integration_idn) !== normalizeStr(remote.integration_idn) ||
25
+ normalizeStr(local.connector_idn) !== normalizeStr(remote.connector_idn));
26
+ }
27
+ export function flowStateDiffers(local, remote) {
28
+ return (normalizeStr(local.title) !== normalizeStr(remote.title) ||
29
+ normalizeStr(local.default_value) !== normalizeStr(remote.default_value) ||
30
+ normalizeStr(local.scope) !== normalizeStr(remote.scope));
31
+ }
32
+ /**
33
+ * Normalizes nullable/undefined string fields so YAML round-trips don't
34
+ * register as differences. `null`, `undefined`, and missing all collapse to ''.
35
+ */
36
+ function normalizeStr(value) {
37
+ if (value === null || value === undefined)
38
+ return '';
39
+ return String(value);
40
+ }
41
+ function buildEventCreateRequest(local) {
42
+ return {
43
+ idn: local.idn,
44
+ description: local.description ?? '',
45
+ skill_selector: local.skill_selector,
46
+ ...(local.skill_idn != null ? { skill_idn: local.skill_idn } : {}),
47
+ state_idn: local.state_idn ?? null,
48
+ interrupt_mode: local.interrupt_mode,
49
+ integration_idn: local.integration_idn ?? '',
50
+ connector_idn: local.connector_idn ?? ''
51
+ };
52
+ }
53
+ function buildEventUpdateRequest(local) {
54
+ return {
55
+ idn: local.idn,
56
+ description: local.description ?? '',
57
+ skill_selector: local.skill_selector,
58
+ skill_idn: local.skill_idn ?? null,
59
+ state_idn: local.state_idn ?? null,
60
+ interrupt_mode: local.interrupt_mode,
61
+ integration_idn: local.integration_idn ?? null,
62
+ connector_idn: local.connector_idn ?? null
63
+ };
64
+ }
65
+ function buildStateCreateRequest(local) {
66
+ const req = {
67
+ title: local.title || local.idn,
68
+ idn: local.idn,
69
+ scope: local.scope
70
+ };
71
+ if (local.default_value != null) {
72
+ req.default_value = local.default_value;
73
+ }
74
+ return req;
75
+ }
76
+ function buildStateUpdateRequest(local) {
77
+ const req = {
78
+ title: local.title || local.idn,
79
+ idn: local.idn,
80
+ scope: local.scope
81
+ };
82
+ if (local.default_value != null) {
83
+ req.default_value = local.default_value;
84
+ }
85
+ return req;
86
+ }
87
+ function shouldUpdateFlow(local, remote) {
88
+ return (normalizeStr(local.title) !== normalizeStr(remote.title) ||
89
+ normalizeStr(local.description) !== normalizeStr(remote.description) ||
90
+ normalizeStr(local.default_runner_type) !== normalizeStr(remote.default_runner_type));
91
+ }
92
+ /**
93
+ * Reconcile one flow's metadata with the platform.
94
+ *
95
+ * @param client authenticated Axios client
96
+ * @param flowId platform flow ID (UUID)
97
+ * @param local parsed FlowMetadata from the customer's local YAML
98
+ * @param remoteFlow flow data fetched from GET /flows/{id} - if null,
99
+ * flow-level updates are skipped (still syncs children).
100
+ * Pass null when caller already knows the GET endpoint
101
+ * will 404 (e.g. legacy data) or wants children-only.
102
+ * @param verbose when true, emits per-operation log lines
103
+ * @param counts shared counter mutated in place across multiple flows
104
+ */
105
+ export async function syncFlowMetadata(client, flowId, local, remoteFlow, verbose, counts) {
106
+ // 1. Flow-level fields (title, description, runner type)
107
+ if (remoteFlow && shouldUpdateFlow(local, remoteFlow)) {
108
+ try {
109
+ const updateRequest = {
110
+ idn: local.idn,
111
+ title: local.title,
112
+ description: local.description ?? '',
113
+ default_runner_type: local.default_runner_type,
114
+ default_model: local.default_model
115
+ };
116
+ await updateFlow(client, flowId, updateRequest);
117
+ counts.flowsUpdated++;
118
+ if (verbose) {
119
+ console.log(` ↑ Updated flow metadata: ${local.idn} (title: "${remoteFlow.title}" → "${local.title}")`);
120
+ }
121
+ }
122
+ catch (error) {
123
+ const msg = error instanceof Error ? error.message : String(error);
124
+ counts.errors.push(`Failed to update flow ${local.idn}: ${msg}`);
125
+ console.error(` ❌ Failed to update flow ${local.idn}: ${msg}`);
126
+ }
127
+ }
128
+ // 2. Events
129
+ let remoteEvents = [];
130
+ try {
131
+ remoteEvents = await listFlowEvents(client, flowId);
132
+ }
133
+ catch (error) {
134
+ const msg = error instanceof Error ? error.message : String(error);
135
+ counts.errors.push(`Failed to list events for flow ${local.idn}: ${msg}`);
136
+ return;
137
+ }
138
+ const localEvents = local.events ?? [];
139
+ const remoteByIdn = new Map(remoteEvents.map(e => [e.idn, e]));
140
+ const localByIdn = new Map(localEvents.map(e => [e.idn, e]));
141
+ // Create or update events present locally
142
+ for (const localEvent of localEvents) {
143
+ const remote = remoteByIdn.get(localEvent.idn);
144
+ if (!remote) {
145
+ // Create
146
+ try {
147
+ await createFlowEvent(client, flowId, buildEventCreateRequest(localEvent));
148
+ counts.eventsCreated++;
149
+ if (verbose)
150
+ console.log(` ↑ Created event: ${local.idn}/${localEvent.idn}`);
151
+ }
152
+ catch (error) {
153
+ const msg = error instanceof Error ? error.message : String(error);
154
+ counts.errors.push(`Failed to create event ${localEvent.idn} in flow ${local.idn}: ${msg}`);
155
+ console.error(` ❌ Failed to create event ${localEvent.idn}: ${msg}`);
156
+ }
157
+ }
158
+ else if (flowEventDiffers(localEvent, remote)) {
159
+ try {
160
+ await updateFlowEvent(client, remote.id, buildEventUpdateRequest(localEvent));
161
+ counts.eventsUpdated++;
162
+ if (verbose)
163
+ console.log(` ↑ Updated event: ${local.idn}/${localEvent.idn}`);
164
+ }
165
+ catch (error) {
166
+ const msg = error instanceof Error ? error.message : String(error);
167
+ counts.errors.push(`Failed to update event ${localEvent.idn} in flow ${local.idn}: ${msg}`);
168
+ console.error(` ❌ Failed to update event ${localEvent.idn}: ${msg}`);
169
+ }
170
+ }
171
+ }
172
+ // Delete events present remotely but missing locally
173
+ for (const remoteEvent of remoteEvents) {
174
+ if (!localByIdn.has(remoteEvent.idn)) {
175
+ try {
176
+ await deleteFlowEvent(client, remoteEvent.id);
177
+ counts.eventsDeleted++;
178
+ if (verbose)
179
+ console.log(` ↑ Deleted event: ${local.idn}/${remoteEvent.idn}`);
180
+ }
181
+ catch (error) {
182
+ const msg = error instanceof Error ? error.message : String(error);
183
+ counts.errors.push(`Failed to delete event ${remoteEvent.idn} in flow ${local.idn}: ${msg}`);
184
+ console.error(` ❌ Failed to delete event ${remoteEvent.idn}: ${msg}`);
185
+ }
186
+ }
187
+ }
188
+ // 3. State fields
189
+ let remoteStates = [];
190
+ try {
191
+ remoteStates = await listFlowStates(client, flowId);
192
+ }
193
+ catch (error) {
194
+ const msg = error instanceof Error ? error.message : String(error);
195
+ counts.errors.push(`Failed to list states for flow ${local.idn}: ${msg}`);
196
+ return;
197
+ }
198
+ const localStates = local.state_fields ?? [];
199
+ const remoteStatesByIdn = new Map(remoteStates.map(s => [s.idn, s]));
200
+ const localStatesByIdn = new Map(localStates.map(s => [s.idn, s]));
201
+ for (const localState of localStates) {
202
+ const remote = remoteStatesByIdn.get(localState.idn);
203
+ if (!remote) {
204
+ try {
205
+ await createFlowState(client, flowId, buildStateCreateRequest(localState));
206
+ counts.statesCreated++;
207
+ if (verbose)
208
+ console.log(` ↑ Created state: ${local.idn}/${localState.idn}`);
209
+ }
210
+ catch (error) {
211
+ const msg = error instanceof Error ? error.message : String(error);
212
+ counts.errors.push(`Failed to create state ${localState.idn} in flow ${local.idn}: ${msg}`);
213
+ console.error(` ❌ Failed to create state ${localState.idn}: ${msg}`);
214
+ }
215
+ }
216
+ else if (flowStateDiffers(localState, remote)) {
217
+ try {
218
+ await updateFlowState(client, remote.id, buildStateUpdateRequest(localState));
219
+ counts.statesUpdated++;
220
+ if (verbose)
221
+ console.log(` ↑ Updated state: ${local.idn}/${localState.idn}`);
222
+ }
223
+ catch (error) {
224
+ const msg = error instanceof Error ? error.message : String(error);
225
+ counts.errors.push(`Failed to update state ${localState.idn} in flow ${local.idn}: ${msg}`);
226
+ console.error(` ❌ Failed to update state ${localState.idn}: ${msg}`);
227
+ }
228
+ }
229
+ }
230
+ for (const remoteState of remoteStates) {
231
+ if (!localStatesByIdn.has(remoteState.idn)) {
232
+ try {
233
+ await deleteFlowState(client, remoteState.id);
234
+ counts.statesDeleted++;
235
+ if (verbose)
236
+ console.log(` ↑ Deleted state: ${local.idn}/${remoteState.idn}`);
237
+ }
238
+ catch (error) {
239
+ const msg = error instanceof Error ? error.message : String(error);
240
+ counts.errors.push(`Failed to delete state ${remoteState.idn} in flow ${local.idn}: ${msg}`);
241
+ console.error(` ❌ Failed to delete state ${remoteState.idn}: ${msg}`);
242
+ }
243
+ }
244
+ }
245
+ }
246
+ /**
247
+ * Combined count of operations across all categories.
248
+ */
249
+ export function totalFlowSyncOps(counts) {
250
+ return (counts.flowsUpdated +
251
+ counts.eventsCreated + counts.eventsUpdated + counts.eventsDeleted +
252
+ counts.statesCreated + counts.statesUpdated + counts.statesDeleted);
253
+ }
254
+ /**
255
+ * Human-readable summary line for the push report.
256
+ */
257
+ export function describeFlowSyncCounts(counts) {
258
+ const parts = [];
259
+ if (counts.flowsUpdated)
260
+ parts.push(`${counts.flowsUpdated} flow(s)`);
261
+ if (counts.eventsCreated || counts.eventsUpdated || counts.eventsDeleted) {
262
+ const eventOps = [];
263
+ if (counts.eventsCreated)
264
+ eventOps.push(`+${counts.eventsCreated}`);
265
+ if (counts.eventsUpdated)
266
+ eventOps.push(`~${counts.eventsUpdated}`);
267
+ if (counts.eventsDeleted)
268
+ eventOps.push(`-${counts.eventsDeleted}`);
269
+ parts.push(`events ${eventOps.join('/')}`);
270
+ }
271
+ if (counts.statesCreated || counts.statesUpdated || counts.statesDeleted) {
272
+ const stateOps = [];
273
+ if (counts.statesCreated)
274
+ stateOps.push(`+${counts.statesCreated}`);
275
+ if (counts.statesUpdated)
276
+ stateOps.push(`~${counts.statesUpdated}`);
277
+ if (counts.statesDeleted)
278
+ stateOps.push(`-${counts.statesDeleted}`);
279
+ parts.push(`states ${stateOps.join('/')}`);
280
+ }
281
+ return parts.join(', ');
282
+ }
283
+ //# sourceMappingURL=flow-metadata.js.map
@@ -0,0 +1,67 @@
1
+ /**
2
+ * JSON-typed attribute helpers.
3
+ *
4
+ * Why this exists:
5
+ *
6
+ * The NEWO platform stores some attributes (e.g.
7
+ * `project_attributes_private_dynamic_workflow_builder_canvas`) as
8
+ * `value_type: json`. The API may return the `value` field as either a
9
+ * STRING containing JSON or as an already-parsed OBJECT.
10
+ *
11
+ * Without normalization, two bugs leak through:
12
+ *
13
+ * 1. When the API returns the value as an OBJECT, `yaml.dump` serializes
14
+ * it as a YAML structure (mappings/sequences). Pushing back then sends
15
+ * `{"value": {...}}` instead of `{"value": "..."}`, breaking the
16
+ * Workflow Builder which expects the canvas as a JSON STRING.
17
+ *
18
+ * 2. The push-time change check used `String(localAttr.value)` for
19
+ * comparison. With objects this collapses to `"[object Object]"` on
20
+ * both sides — silently masking real changes — and with mismatched
21
+ * string vs object representations it triggers spurious pushes that
22
+ * overwrite the canvas with the wrong shape (Builder shows blank).
23
+ *
24
+ * The fix is conservative: for `value_type: json` only, always coerce the
25
+ * value to a STRING when persisting and when pushing, and use canonical
26
+ * JSON for comparisons. String-typed values in the wild are left
27
+ * untouched, so no churn for the majority of attributes.
28
+ */
29
+ /**
30
+ * True if the attribute is a JSON-typed attribute (case- and
31
+ * format-insensitive: handles `json`, `JSON`, `AttributeValueTypes.json`,
32
+ * `ValueType.JSON`, etc.).
33
+ */
34
+ export declare function isJsonValueType(valueType: unknown): boolean;
35
+ /**
36
+ * Coerce a JSON-typed attribute's value to a STRING suitable for storage
37
+ * in attributes.yaml and for sending to the platform.
38
+ *
39
+ * - `null` / `undefined` → `''`
40
+ * - object → compact JSON string (`JSON.stringify(value)`)
41
+ * - string → returned as-is (we trust the platform's existing format)
42
+ * - other → `String(value)`
43
+ *
44
+ * We deliberately do NOT re-format string values, even when they look
45
+ * like JSON. Many existing canvases are stored pretty-printed and
46
+ * reformatting would create huge spurious diffs in users' repos.
47
+ */
48
+ export declare function normalizeJsonValueForStorage(value: unknown): string;
49
+ /**
50
+ * Canonical comparison for JSON-typed attribute values.
51
+ *
52
+ * Returns the canonical form (compact JSON if parseable, otherwise the
53
+ * raw string). Use this on both sides of a comparison so that pretty- vs
54
+ * compact-printed JSON does not register as a change, and so that an
55
+ * object on one side equals its stringified form on the other side.
56
+ */
57
+ export declare function canonicalJsonValue(value: unknown): string;
58
+ /**
59
+ * True if two JSON-typed attribute values are semantically equal.
60
+ *
61
+ * Handles the four mismatched representations that can occur during a
62
+ * pull/push cycle:
63
+ * string vs string (different whitespace/indent), object vs string,
64
+ * string vs object, object vs object.
65
+ */
66
+ export declare function jsonValuesEqual(a: unknown, b: unknown): boolean;
67
+ //# sourceMappingURL=json-attr-utils.d.ts.map
@@ -0,0 +1,98 @@
1
+ /**
2
+ * JSON-typed attribute helpers.
3
+ *
4
+ * Why this exists:
5
+ *
6
+ * The NEWO platform stores some attributes (e.g.
7
+ * `project_attributes_private_dynamic_workflow_builder_canvas`) as
8
+ * `value_type: json`. The API may return the `value` field as either a
9
+ * STRING containing JSON or as an already-parsed OBJECT.
10
+ *
11
+ * Without normalization, two bugs leak through:
12
+ *
13
+ * 1. When the API returns the value as an OBJECT, `yaml.dump` serializes
14
+ * it as a YAML structure (mappings/sequences). Pushing back then sends
15
+ * `{"value": {...}}` instead of `{"value": "..."}`, breaking the
16
+ * Workflow Builder which expects the canvas as a JSON STRING.
17
+ *
18
+ * 2. The push-time change check used `String(localAttr.value)` for
19
+ * comparison. With objects this collapses to `"[object Object]"` on
20
+ * both sides — silently masking real changes — and with mismatched
21
+ * string vs object representations it triggers spurious pushes that
22
+ * overwrite the canvas with the wrong shape (Builder shows blank).
23
+ *
24
+ * The fix is conservative: for `value_type: json` only, always coerce the
25
+ * value to a STRING when persisting and when pushing, and use canonical
26
+ * JSON for comparisons. String-typed values in the wild are left
27
+ * untouched, so no churn for the majority of attributes.
28
+ */
29
+ /**
30
+ * True if the attribute is a JSON-typed attribute (case- and
31
+ * format-insensitive: handles `json`, `JSON`, `AttributeValueTypes.json`,
32
+ * `ValueType.JSON`, etc.).
33
+ */
34
+ export function isJsonValueType(valueType) {
35
+ if (typeof valueType !== 'string')
36
+ return false;
37
+ const lower = valueType.toLowerCase();
38
+ return lower === 'json' || lower.endsWith('.json');
39
+ }
40
+ /**
41
+ * Coerce a JSON-typed attribute's value to a STRING suitable for storage
42
+ * in attributes.yaml and for sending to the platform.
43
+ *
44
+ * - `null` / `undefined` → `''`
45
+ * - object → compact JSON string (`JSON.stringify(value)`)
46
+ * - string → returned as-is (we trust the platform's existing format)
47
+ * - other → `String(value)`
48
+ *
49
+ * We deliberately do NOT re-format string values, even when they look
50
+ * like JSON. Many existing canvases are stored pretty-printed and
51
+ * reformatting would create huge spurious diffs in users' repos.
52
+ */
53
+ export function normalizeJsonValueForStorage(value) {
54
+ if (value == null)
55
+ return '';
56
+ if (typeof value === 'string')
57
+ return value;
58
+ if (typeof value === 'object') {
59
+ try {
60
+ return JSON.stringify(value);
61
+ }
62
+ catch {
63
+ return String(value);
64
+ }
65
+ }
66
+ return String(value);
67
+ }
68
+ /**
69
+ * Canonical comparison for JSON-typed attribute values.
70
+ *
71
+ * Returns the canonical form (compact JSON if parseable, otherwise the
72
+ * raw string). Use this on both sides of a comparison so that pretty- vs
73
+ * compact-printed JSON does not register as a change, and so that an
74
+ * object on one side equals its stringified form on the other side.
75
+ */
76
+ export function canonicalJsonValue(value) {
77
+ const stringified = normalizeJsonValueForStorage(value);
78
+ if (stringified === '')
79
+ return '';
80
+ try {
81
+ return JSON.stringify(JSON.parse(stringified));
82
+ }
83
+ catch {
84
+ return stringified;
85
+ }
86
+ }
87
+ /**
88
+ * True if two JSON-typed attribute values are semantically equal.
89
+ *
90
+ * Handles the four mismatched representations that can occur during a
91
+ * pull/push cycle:
92
+ * string vs string (different whitespace/indent), object vs string,
93
+ * string vs object, object vs object.
94
+ */
95
+ export function jsonValuesEqual(a, b) {
96
+ return canonicalJsonValue(a) === canonicalJsonValue(b);
97
+ }
98
+ //# sourceMappingURL=json-attr-utils.js.map
package/dist/sync/push.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Push operations for changed files
3
3
  */
4
- import { updateSkill, createAgent, createFlow, createSkill, publishFlow } from '../api.js';
5
- import { ensureState, mapPath, skillMetadataPath, projectDir, agentMetadataPath } from '../fsutil.js';
4
+ import { updateSkill, createAgent, createFlow, createSkill, publishFlow, getFlow } from '../api.js';
5
+ import { ensureState, mapPath, skillMetadataPath, projectDir, agentMetadataPath, flowMetadataPath } from '../fsutil.js';
6
6
  import { validateSkillFolder, getSingleSkillFile, getExtensionForRunner } from './skill-files.js';
7
7
  import fs from 'fs-extra';
8
8
  import { sha256, loadHashes, saveHashes } from '../hash.js';
@@ -11,6 +11,7 @@ import { generateFlowsYaml } from './metadata.js';
11
11
  import { isProjectMap, isLegacyProjectMap } from './projects.js';
12
12
  import { flowsYamlPath } from '../fsutil.js';
13
13
  import { pushAllProjectAttributes } from './attributes.js';
14
+ import { syncFlowMetadata, emptyFlowSyncCounts, totalFlowSyncOps, describeFlowSyncCounts } from './flow-metadata.js';
14
15
  /**
15
16
  * Scan filesystem for local-only entities not in the project map yet
16
17
  */
@@ -444,6 +445,68 @@ export async function pushChanged(client, customer, verbose = false, shouldPubli
444
445
  }
445
446
  }
446
447
  }
448
+ // Sync flow metadata (title, events, state_fields) for any flow whose
449
+ // metadata.yaml hash has changed. This closes the loop on GH issue #3:
450
+ // previously push only updated skill scripts, leaving local edits to
451
+ // flow events and title silently un-synced.
452
+ const flowSyncCounts = emptyFlowSyncCounts();
453
+ for (const [projectIdn, projectData] of Object.entries(projects)) {
454
+ for (const [agentIdn, agentObj] of Object.entries(projectData.agents)) {
455
+ for (const [flowIdn, flowObj] of Object.entries(agentObj.flows)) {
456
+ if (!flowObj.id)
457
+ continue;
458
+ const metaPath = flowMetadataPath(customer.idn, projectIdn, agentIdn, flowIdn);
459
+ if (!(await fs.pathExists(metaPath)))
460
+ continue;
461
+ const metaContent = await fs.readFile(metaPath, 'utf8');
462
+ const metaHash = sha256(metaContent);
463
+ const oldHash = hashes[metaPath];
464
+ if (oldHash === metaHash) {
465
+ if (verbose)
466
+ console.log(` ✓ Flow metadata unchanged: ${flowIdn}`);
467
+ continue;
468
+ }
469
+ if (verbose)
470
+ console.log(` 🔄 Flow metadata changed, syncing: ${agentIdn}/${flowIdn}`);
471
+ let localFlow;
472
+ try {
473
+ localFlow = yaml.load(metaContent);
474
+ }
475
+ catch (error) {
476
+ console.error(`❌ Failed to parse flow metadata for ${flowIdn}: ${error instanceof Error ? error.message : String(error)}`);
477
+ continue;
478
+ }
479
+ let remoteFlow = null;
480
+ try {
481
+ remoteFlow = await getFlow(client, flowObj.id);
482
+ }
483
+ catch (error) {
484
+ // 404 means the flow ID is stale; skip flow-level update but still
485
+ // try to sync children since list endpoints may still work.
486
+ if (verbose) {
487
+ console.log(` ⚠️ Could not GET flow ${flowIdn}: ${error.response?.status ?? error.message}`);
488
+ }
489
+ }
490
+ const opsBefore = totalFlowSyncOps(flowSyncCounts);
491
+ await syncFlowMetadata(client, flowObj.id, localFlow, remoteFlow, verbose, flowSyncCounts);
492
+ const opsAfter = totalFlowSyncOps(flowSyncCounts);
493
+ if (opsAfter > opsBefore) {
494
+ pushed += (opsAfter - opsBefore);
495
+ metadataChanged = true;
496
+ }
497
+ // Hash is updated regardless of whether ops happened, so we don't
498
+ // re-scan the same untouched flow on the next push.
499
+ newHashes[metaPath] = metaHash;
500
+ }
501
+ }
502
+ }
503
+ const totalFlowOps = totalFlowSyncOps(flowSyncCounts);
504
+ if (totalFlowOps > 0) {
505
+ console.log(`↑ Flow metadata synced: ${describeFlowSyncCounts(flowSyncCounts)}`);
506
+ }
507
+ if (flowSyncCounts.errors.length > 0) {
508
+ console.warn(`⚠️ ${flowSyncCounts.errors.length} flow-metadata error(s) during push.`);
509
+ }
447
510
  if (verbose)
448
511
  console.log(`🔄 Scanned ${scanned} files, found ${pushed} changes`);
449
512
  // Push project attributes for all projects
package/dist/types.d.ts CHANGED
@@ -441,6 +441,22 @@ export interface CreateFlowEventRequest {
441
441
  export interface CreateFlowEventResponse {
442
442
  id: string;
443
443
  }
444
+ /**
445
+ * Payload for PATCH /api/v1/designer/flows/events/{eventId}
446
+ *
447
+ * Required fields per probe testing: idn, skill_selector, interrupt_mode.
448
+ * Sending the full event body is the platform's expected shape.
449
+ */
450
+ export interface UpdateFlowEventRequest {
451
+ idn: string;
452
+ description?: string | null;
453
+ skill_selector: string;
454
+ skill_idn?: string | null;
455
+ state_idn?: string | null;
456
+ interrupt_mode: string;
457
+ integration_idn?: string | null;
458
+ connector_idn?: string | null;
459
+ }
444
460
  export interface CreateFlowStateRequest {
445
461
  title: string;
446
462
  idn: string;
@@ -450,6 +466,27 @@ export interface CreateFlowStateRequest {
450
466
  export interface CreateFlowStateResponse {
451
467
  id: string;
452
468
  }
469
+ /**
470
+ * Payload for PUT /api/v1/designer/flows/states/{stateId}
471
+ */
472
+ export interface UpdateFlowStateRequest {
473
+ title: string;
474
+ idn: string;
475
+ default_value?: string;
476
+ scope: string;
477
+ }
478
+ /**
479
+ * Payload for PATCH /api/v1/designer/flows/{flowId}
480
+ *
481
+ * Empty body returns 500; the platform requires the full descriptor.
482
+ */
483
+ export interface UpdateFlowRequest {
484
+ idn: string;
485
+ title: string;
486
+ description?: string;
487
+ default_runner_type: RunnerType;
488
+ default_model: ModelConfig;
489
+ }
453
490
  export interface CreateSkillParameterRequest {
454
491
  name: string;
455
492
  default_value?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "newo",
3
- "version": "3.7.0",
3
+ "version": "3.7.2",
4
4
  "description": "NEWO CLI: Professional command-line tool with modular architecture for NEWO AI Agent development. Features account migration, integration management, webhook automation, AKB knowledge base, project attributes, sandbox testing, IDN-based file management, real-time progress tracking, intelligent sync operations, and comprehensive multi-customer support.",
5
5
  "type": "module",
6
6
  "bin": {