@uipath/case-tool 1.201.0 → 1.202.0-preview.136

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 (96) hide show
  1. package/dist/{authoring-aaaqwck3.js → authoring-cvjhkfxp.js} +74 -48
  2. package/dist/{browser-strategy-rkcvc6tn.js → browser-strategy-6atc7v8s.js} +3 -3
  3. package/dist/case-api-bwcxsbxe.js +381 -0
  4. package/dist/case-debug-studio-web-service-qcb328bt.js +335 -0
  5. package/dist/{case-pack-service-bxas5bxz.js → case-pack-service-txby2znw.js} +11 -18
  6. package/dist/case-validate-service-0q8krj2a.js +2114 -0
  7. package/dist/connector-enrichment-service-agqxam5y.js +60 -0
  8. package/dist/connector-lookup-service-ycgk77n0.js +22 -0
  9. package/dist/connector-task-spec-kdx5bv87.js +1250 -0
  10. package/dist/{de-5KVP66U6-t37qr521.js → de-5KVP66U6-1bnf4zt5.js} +54 -54
  11. package/dist/{de-5HU6GFWV-zheyw6d2.js → de-7XQXX2DK-tqdy5n2b.js} +857 -845
  12. package/dist/debug-service-dxx5pfev.js +57 -0
  13. package/dist/{en-MABQK6C4-nkzq2j8t.js → en-5ZGC5VQ3-h581y30k.js} +897 -897
  14. package/dist/{en-4KXU7N7B-24v330b5.js → en-X3S6IZ5J-nhkg6pwn.js} +55 -61
  15. package/dist/enrichment-service-ebz1f4ds.js +421 -0
  16. package/dist/{es-MX-POESXYP2-9538722k.js → es-MX-U2VN3SZW-anynsmd8.js} +857 -845
  17. package/dist/{es-MX-XAVLOQW3-47a405kf.js → es-MX-XAVLOQW3-q00km2y7.js} +54 -54
  18. package/dist/{es-VFPNVMP5-6sftsdxe.js → es-VFPNVMP5-bx2c337j.js} +54 -54
  19. package/dist/{es-LUTYN7U7-ye5zn4sn.js → es-ZGCPPOME-8gazspjj.js} +857 -845
  20. package/dist/{fr-E5MDO4EG-f3x1jeqw.js → fr-E5MDO4EG-c3mkty2t.js} +54 -54
  21. package/dist/{fr-LJIK56LW-xf3xf2kh.js → fr-T3G5GZCT-y3f7xb1q.js} +857 -845
  22. package/dist/{index-cncq089f.js → index-7s201ka0.js} +163 -80
  23. package/dist/{index-hsadteg4.js → index-h8cph72k.js} +4 -4
  24. package/dist/index-k4xz16db.js +63712 -0
  25. package/dist/{index-p50kx6jv.js → index-k5tbd184.js} +276 -276
  26. package/dist/index-kwxe1vep.js +143 -0
  27. package/dist/{index-9f8q2ege.js → index-p3vk57z7.js} +27 -27
  28. package/dist/index-qyf1dee9.js +630 -0
  29. package/dist/index.js +16 -17
  30. package/dist/{index.umd.min-drpc57vn.js → index.umd.min-fqefd9kn.js} +3 -3
  31. package/dist/input-reader-xb9vecxv.js +11 -0
  32. package/dist/{ja-FGEGLBJ3-w9byjhze.js → ja-BI5K3JDZ-77zat4z2.js} +857 -845
  33. package/dist/{ja-DPO5PPLO-fmbg7zt2.js → ja-DPO5PPLO-mysfmznx.js} +54 -54
  34. package/dist/{js-yaml-cggj6w7q.js → js-yaml-87cdx6bm.js} +27 -19
  35. package/dist/known-types-qryebm95.js +15 -0
  36. package/dist/{ko-ITOPNIYI-aqy82jk8.js → ko-ITOPNIYI-hmxd2asd.js} +54 -54
  37. package/dist/{ko-TUAK3G3A-s25w0ckg.js → ko-JOBF5V7N-4bv0mjje.js} +857 -845
  38. package/dist/{node-strategy-8gzp67xs.js → node-strategy-0267x5e5.js} +130 -14
  39. package/dist/node-sync-service-9a9ksj9s.js +38 -0
  40. package/dist/{packager-tool-9qecd4wb.js → packager-tool-0gctz400.js} +5 -2
  41. package/dist/packager-tool-0mj06yen.js +65 -0
  42. package/dist/{packager-tool-1cb0d5e0.js → packager-tool-0v3s8r01.js} +2 -2
  43. package/dist/packager-tool-134mvmcm.js +3040 -0
  44. package/dist/{packager-tool-wckvcay0.js → packager-tool-1yh8g550.js} +9 -7
  45. package/dist/{packager-tool-zqa5k9f7.js → packager-tool-37zvccmt.js} +990 -2287
  46. package/dist/packager-tool-3ze5vt52.js +54 -0
  47. package/dist/{packager-tool-w3h8xrnv.js → packager-tool-56j6keqr.js} +71 -3
  48. package/dist/{packager-tool-3wygxefb.js → packager-tool-58q3tvh7.js} +10 -10
  49. package/dist/{packager-tool-zx48pq4v.js → packager-tool-5ax2ywcg.js} +1997 -1174
  50. package/dist/{packager-tool-we1phz71.js → packager-tool-885mmrvr.js} +31 -3
  51. package/dist/packager-tool-9scn4b15.js +852 -0
  52. package/dist/{packager-tool-p9j43p8h.js → packager-tool-a42jnpy5.js} +3 -9
  53. package/dist/packager-tool-ajvse9r3.js +356 -0
  54. package/dist/{packager-tool-jysvpt8p.js → packager-tool-c23zrhj8.js} +2 -2
  55. package/dist/packager-tool-dqs5qy9s.js +2327 -0
  56. package/dist/packager-tool-ee5dhff3.js +6717 -0
  57. package/dist/{packager-tool-wvqz81mx.js → packager-tool-gtzs471w.js} +3 -2
  58. package/dist/packager-tool-hrr0efqc.js +546 -0
  59. package/dist/packager-tool-j9rfdrdm.js +1125 -0
  60. package/dist/{packager-tool-gq6952nc.js → packager-tool-jhdf8gt1.js} +5054 -17851
  61. package/dist/packager-tool-mp59jtpm.js +6865 -0
  62. package/dist/packager-tool-njzcfve1.js +77 -0
  63. package/dist/packager-tool-p7jgrm5r.js +15 -0
  64. package/dist/packager-tool-r84ng21s.js +57 -0
  65. package/dist/packager-tool-rqvr63x5.js +1217 -0
  66. package/dist/packager-tool-s12392rd.js +80 -0
  67. package/dist/packager-tool-sv0d6wb6.js +173 -0
  68. package/dist/packager-tool-ty1t2byf.js +27 -0
  69. package/dist/packager-tool-vepqrsse.js +23 -0
  70. package/dist/packager-tool-w5ek334f.js +4892 -0
  71. package/dist/{packager-tool-5arsyj36.js → packager-tool-yc4kw997.js} +4 -2
  72. package/dist/packager-tool.js +91 -5
  73. package/dist/project-artifacts-vhanbtw5.js +14 -0
  74. package/dist/{pt-BR-7XGDXRDJ-espnkgrj.js → pt-BR-7DYX2YPT-fqxqzqtf.js} +857 -845
  75. package/dist/{pt-BR-BXURWX4W-xzyndmrx.js → pt-BR-BXURWX4W-bwfcwhk1.js} +54 -54
  76. package/dist/{pt-TMVOOITK-myha14p9.js → pt-HTXGGX6Y-97t21dty.js} +857 -845
  77. package/dist/{pt-YI4VE4YQ-521681zf.js → pt-YI4VE4YQ-wdkn2dcf.js} +54 -54
  78. package/dist/resourcesSyncService-mrmmwaqr.js +683 -0
  79. package/dist/{ro-2VALF3S5-cdz5afkr.js → ro-KTNQ3MNU-y08n1x5g.js} +857 -845
  80. package/dist/{ro-RKXZUG7Z-pdztdafr.js → ro-RKXZUG7Z-nndrrsq7.js} +54 -54
  81. package/dist/{ru-GSCT4ARZ-qj8dm4dp.js → ru-GSCT4ARZ-1sa9wbr8.js} +1 -1
  82. package/dist/ru-WBLQ5B2U-8r3c7v6d.js +10 -0
  83. package/dist/strict-case-rules-303vjvas.js +377 -0
  84. package/dist/strict-sdd-audit-qdmc9e1y.js +1024 -0
  85. package/dist/tool.js +17 -18
  86. package/dist/{tr-AA6O2WSR-bj9n80k8.js → tr-AA6O2WSR-86ba4bdf.js} +54 -54
  87. package/dist/{tr-RIFCEXFH-hgkb4g8y.js → tr-XHSSPNK7-cmqyc4wd.js} +857 -845
  88. package/dist/trigger-enrichment-service-zdx4x92j.js +340 -0
  89. package/dist/{zh-CN-IP3FMXWM-1cfarhcp.js → zh-CN-2EHQT23P-mr63c4xz.js} +857 -845
  90. package/dist/{zh-CN-R2KLHXQV-x6gnk2n0.js → zh-CN-R2KLHXQV-agqr45ds.js} +54 -54
  91. package/dist/{zh-TW-AGIDXIPF-n6r6w7vy.js → zh-TW-MGZCE5BT-c4ekmrz9.js} +857 -845
  92. package/dist/{zh-TW-RJGCQANM-tt8j5wv2.js → zh-TW-RJGCQANM-w0x3qc1p.js} +54 -54
  93. package/package.json +2 -2
  94. package/dist/index-8bsngk9y.js +0 -247140
  95. package/dist/packager-tool-axcdppp9.js +0 -13607
  96. package/dist/ru-WBLQ5B2U-8xd4gpv2.js +0 -10
@@ -0,0 +1,1125 @@
1
+ import {
2
+ DEBUG_MODE_MAP,
3
+ SIMULATION_MODE_MAP
4
+ } from "./packager-tool-9scn4b15.js";
5
+ import {
6
+ resolveJsonInput
7
+ } from "./packager-tool-3ze5vt52.js";
8
+ import {
9
+ getAuthContext
10
+ } from "./packager-tool-dqs5qy9s.js";
11
+ import {
12
+ DEFAULT_PAGE_SIZE,
13
+ EXIT_CODES,
14
+ InvalidArgumentError,
15
+ OutputFormatter,
16
+ Pagination,
17
+ RESULTS,
18
+ catchError,
19
+ extractErrorMessage,
20
+ isGuid,
21
+ logger,
22
+ parseBoundedInt,
23
+ parseLimit,
24
+ parseOffset,
25
+ processContext
26
+ } from "./packager-tool-5ax2ywcg.js";
27
+
28
+ // ../maestro-sdk/src/query-string.ts
29
+ function buildQueryString(params) {
30
+ const entries = [];
31
+ for (const [key, value] of Object.entries(params)) {
32
+ if (value === undefined)
33
+ continue;
34
+ if (Array.isArray(value)) {
35
+ for (const item of value) {
36
+ entries.push([key, item]);
37
+ }
38
+ continue;
39
+ }
40
+ entries.push([key, String(value)]);
41
+ }
42
+ if (entries.length === 0)
43
+ return "";
44
+ return `?${new URLSearchParams(entries).toString()}`;
45
+ }
46
+
47
+ // ../maestro-sdk/src/shared-commands/debug-instances.ts
48
+ var VALID_DEBUG_MODES = Object.keys(DEBUG_MODE_MAP);
49
+ var VALID_SIMULATION_MODES = Object.keys(SIMULATION_MODE_MAP);
50
+
51
+ // ../maestro-sdk/src/client.ts
52
+ function parseBackendErrorBody(body) {
53
+ if (!body)
54
+ return {};
55
+ const [parseErr, parsed] = catchError(() => JSON.parse(body));
56
+ if (parseErr || !parsed || typeof parsed !== "object")
57
+ return {};
58
+ const result = {};
59
+ if (typeof parsed.message === "string")
60
+ result.message = parsed.message;
61
+ if (typeof parsed.errorCode === "number" || typeof parsed.errorCode === "string") {
62
+ result.errorCode = String(parsed.errorCode);
63
+ }
64
+ if (typeof parsed.traceId === "string")
65
+ result.traceId = parsed.traceId;
66
+ if (typeof parsed.requestId === "string") {
67
+ result.requestId = parsed.requestId;
68
+ }
69
+ return result;
70
+ }
71
+
72
+ class PimsApiError extends Error {
73
+ method;
74
+ endpoint;
75
+ url;
76
+ httpStatus;
77
+ statusText;
78
+ body;
79
+ parsedErrorMessage;
80
+ parsedErrorCode;
81
+ parsedTraceId;
82
+ parsedRequestId;
83
+ constructor(details) {
84
+ const parsed = parseBackendErrorBody(details.body);
85
+ const messageSuffix = parsed.message ? ` - ${parsed.message}` : "";
86
+ super(`PIMS API request failed: ${details.httpStatus} ${details.statusText} on ${details.method} ${details.endpoint}${messageSuffix}`);
87
+ this.name = "PimsApiError";
88
+ this.method = details.method;
89
+ this.endpoint = details.endpoint;
90
+ this.url = details.url;
91
+ this.httpStatus = details.httpStatus;
92
+ this.statusText = details.statusText;
93
+ this.body = details.body;
94
+ this.parsedErrorMessage = parsed.message;
95
+ this.parsedErrorCode = parsed.errorCode;
96
+ this.parsedTraceId = parsed.traceId;
97
+ this.parsedRequestId = parsed.requestId;
98
+ }
99
+ }
100
+ function buildPimsUrl(config, path) {
101
+ return `${config.baseUrl}/${config.organizationId}/${config.tenantId}/pims_/api/v1${path}`;
102
+ }
103
+ function buildHeaders(config, options) {
104
+ const headers = {
105
+ Authorization: `Bearer ${config.authToken}`,
106
+ "Content-Type": "application/json",
107
+ Accept: "application/json"
108
+ };
109
+ if (options?.folderKey) {
110
+ headers["x-uipath-folderkey"] = options.folderKey;
111
+ }
112
+ return headers;
113
+ }
114
+ async function pimsGet(config, path, options) {
115
+ const url = buildPimsUrl(config, path);
116
+ const headers = buildHeaders(config, options);
117
+ const response = await fetch(url, {
118
+ method: "GET",
119
+ headers
120
+ });
121
+ if (!response.ok) {
122
+ const errorText = await response.text();
123
+ throw new PimsApiError({
124
+ method: "GET",
125
+ endpoint: path,
126
+ url,
127
+ httpStatus: response.status,
128
+ statusText: response.statusText,
129
+ body: errorText
130
+ });
131
+ }
132
+ const contentType = response.headers.get("content-type") || "";
133
+ if (contentType.includes("application/xml") || contentType.includes("text/xml")) {
134
+ return await response.text();
135
+ }
136
+ const text = await response.text();
137
+ if (!text)
138
+ return {};
139
+ const [parseErr, parsed] = catchError(() => JSON.parse(text));
140
+ if (parseErr)
141
+ throw new Error(`Failed to parse API response body: ${parseErr.message}`);
142
+ return parsed;
143
+ }
144
+ async function pimsRequest(config, method, path, body, options) {
145
+ const url = buildPimsUrl(config, path);
146
+ const headers = buildHeaders(config, options);
147
+ const response = await fetch(url, {
148
+ method,
149
+ headers,
150
+ body: body ? JSON.stringify(body) : undefined
151
+ });
152
+ if (!response.ok) {
153
+ const errorText = await response.text();
154
+ throw new PimsApiError({
155
+ method,
156
+ endpoint: path,
157
+ url,
158
+ httpStatus: response.status,
159
+ statusText: response.statusText,
160
+ body: errorText
161
+ });
162
+ }
163
+ const text = await response.text();
164
+ if (!text)
165
+ return {};
166
+ const [parseErr, parsed] = catchError(() => JSON.parse(text));
167
+ if (parseErr) {
168
+ throw new Error(`Failed to parse API response body: ${parseErr.message}`);
169
+ }
170
+ return parsed;
171
+ }
172
+ async function pimsPost(config, path, body, options) {
173
+ return pimsRequest(config, "POST", path, body, options);
174
+ }
175
+ async function pimsPut(config, path, body, options) {
176
+ return pimsRequest(config, "PUT", path, body, options);
177
+ }
178
+ async function pimsPatch(config, path, body, options) {
179
+ return pimsRequest(config, "PATCH", path, body, options);
180
+ }
181
+
182
+ // ../maestro-sdk/src/client-factory.ts
183
+ async function createPimsConfig() {
184
+ const ctx = await getAuthContext({
185
+ ensureTokenValidityMinutes: 10,
186
+ requireOrganizationId: true,
187
+ requireTenantId: true
188
+ });
189
+ return {
190
+ baseUrl: ctx.baseUrl,
191
+ organizationId: ctx.organizationId,
192
+ tenantId: ctx.tenantId,
193
+ authToken: ctx.accessToken
194
+ };
195
+ }
196
+
197
+ // ../maestro-sdk/src/with-pims-call.ts
198
+ var NETWORK_ERROR_CODES = new Set([
199
+ "ECONNREFUSED",
200
+ "ECONNRESET",
201
+ "ENOTFOUND",
202
+ "EAI_AGAIN",
203
+ "ETIMEDOUT",
204
+ "EPIPE",
205
+ "EHOSTUNREACH",
206
+ "ENETUNREACH",
207
+ "EAI_FAIL"
208
+ ]);
209
+ function capitalise(value) {
210
+ if (value.length === 0) {
211
+ return value;
212
+ }
213
+ return value.charAt(0).toUpperCase() + value.slice(1);
214
+ }
215
+ function isNetworkError(error) {
216
+ if (error === null || typeof error !== "object") {
217
+ return false;
218
+ }
219
+ const err = error;
220
+ const code = typeof err.code === "string" ? err.code : undefined;
221
+ if (code && NETWORK_ERROR_CODES.has(code)) {
222
+ return true;
223
+ }
224
+ const cause = err.cause;
225
+ if (cause && typeof cause === "object") {
226
+ const causeCode = typeof cause.code === "string" ? cause.code : undefined;
227
+ if (causeCode && NETWORK_ERROR_CODES.has(causeCode)) {
228
+ return true;
229
+ }
230
+ }
231
+ return false;
232
+ }
233
+ function pimsFailureContext(error) {
234
+ return {
235
+ httpStatus: error.httpStatus,
236
+ endpoint: error.endpoint,
237
+ method: error.method,
238
+ ...error.parsedErrorCode ? { errorCode: error.parsedErrorCode } : {},
239
+ ...error.parsedRequestId ? { requestId: error.parsedRequestId } : {},
240
+ ...error.parsedTraceId ? { traceId: error.parsedTraceId } : {}
241
+ };
242
+ }
243
+ function pimsFailureInstructions(error) {
244
+ const lines = [
245
+ `Status: ${error.httpStatus} ${error.statusText}`,
246
+ `Resource: ${error.method} ${error.endpoint}`
247
+ ];
248
+ if (error.parsedErrorMessage) {
249
+ lines.push(`Message: ${error.parsedErrorMessage}`);
250
+ } else if (error.body.trim()) {
251
+ lines.push(`Body: ${compactPimsErrorBody(error.body)}`);
252
+ }
253
+ if (error.parsedErrorCode) {
254
+ lines.push(`Error code: ${error.parsedErrorCode}`);
255
+ }
256
+ if (error.parsedTraceId) {
257
+ lines.push(`Trace ID: ${error.parsedTraceId}`);
258
+ } else if (error.parsedRequestId) {
259
+ lines.push(`Request ID: ${error.parsedRequestId}`);
260
+ }
261
+ lines.push("Remediation: verify the folder scope and identifiers, then retry. If the error persists, contact UiPath support with the status, resource, and trace/request ID.");
262
+ return lines.join(`
263
+ `);
264
+ }
265
+ function compactPimsErrorBody(body) {
266
+ const text = body.split(/\s+/).filter(Boolean).join(" ");
267
+ return text.length <= 700 ? text : `${text.slice(0, 699)}...`;
268
+ }
269
+ function resolvePimsEnvelope(error, errorMessage, hint) {
270
+ const status = error.httpStatus;
271
+ if (status === 404) {
272
+ const message = hint?.resource && hint.id ? `${capitalise(hint.resource)} not found: ${hint.id}` : hint?.resource ? `${capitalise(hint.resource)} not found` : errorMessage;
273
+ return { result: RESULTS.Failure, code: "NotFound", message };
274
+ }
275
+ if (status === 401) {
276
+ return {
277
+ result: RESULTS.AuthenticationError,
278
+ code: "Unauthorized",
279
+ message: errorMessage
280
+ };
281
+ }
282
+ if (status === 403) {
283
+ return {
284
+ result: RESULTS.AuthenticationError,
285
+ code: "Forbidden",
286
+ message: errorMessage
287
+ };
288
+ }
289
+ if (status >= 500 && status < 600) {
290
+ return {
291
+ result: RESULTS.Failure,
292
+ code: `ServerError_${status}`,
293
+ message: errorMessage
294
+ };
295
+ }
296
+ return {
297
+ result: RESULTS.Failure,
298
+ code: `Http_${status}`,
299
+ message: errorMessage
300
+ };
301
+ }
302
+ async function withPimsCall(fn, errorMessage, hint) {
303
+ const [configError, config] = await catchError(createPimsConfig());
304
+ if (configError) {
305
+ logger.warn(`${errorMessage}: ${configError.message}`);
306
+ OutputFormatter.error({
307
+ Result: RESULTS.Failure,
308
+ Code: "ConfigError",
309
+ Message: errorMessage,
310
+ Instructions: configError.message
311
+ });
312
+ processContext.exit(1);
313
+ return;
314
+ }
315
+ const [error, result] = await catchError(fn(config));
316
+ if (error) {
317
+ if (isNetworkError(error)) {
318
+ const msg2 = await extractErrorMessage(error);
319
+ logger.warn(`${errorMessage}: ${msg2}`);
320
+ OutputFormatter.error({
321
+ Result: RESULTS.Failure,
322
+ Code: "NetworkError",
323
+ Message: errorMessage,
324
+ Instructions: msg2
325
+ });
326
+ processContext.exit(1);
327
+ return;
328
+ }
329
+ if (error instanceof PimsApiError) {
330
+ const envelope = resolvePimsEnvelope(error, errorMessage, hint);
331
+ logger.warn(`${envelope.message}: ${error.message}`);
332
+ OutputFormatter.error({
333
+ Result: envelope.result,
334
+ Code: envelope.code,
335
+ Message: envelope.message,
336
+ Instructions: pimsFailureInstructions(error),
337
+ Context: pimsFailureContext(error)
338
+ });
339
+ processContext.exit(1);
340
+ return;
341
+ }
342
+ const msg = await extractErrorMessage(error);
343
+ logger.warn(`${errorMessage}: ${msg}`);
344
+ OutputFormatter.error({
345
+ Result: RESULTS.Failure,
346
+ Code: "UnknownError",
347
+ Message: errorMessage,
348
+ Instructions: msg
349
+ });
350
+ processContext.exit(1);
351
+ return;
352
+ }
353
+ return result;
354
+ }
355
+
356
+ // ../maestro-sdk/src/shared-commands/incidents.ts
357
+ var registerSharedIncidentCommands = (program, config) => {
358
+ const { toolLabel } = config;
359
+ const incident = program.command("incident").description(`Manage ${toolLabel} incidents`);
360
+ incident.command("summary").description(`Get ${toolLabel} incident summaries across processes`).option("--folder-key <key>", "Folder key").option("-l, --limit <number>", "Number of items to return (1-10000)", parseLimit).option("--offset <number>", "Number of items to skip (0-1000000)", parseOffset, 0).option("--process-key <process-key>", "Filter by process key").option("--status <status>", "Filter by incident status").option("--severity <severity>", "Filter by incident severity").trackedAction(processContext, async (options) => {
361
+ const query = buildQueryString({
362
+ processKey: options.processKey,
363
+ incidentStatus: options.status,
364
+ incidentSeverity: options.severity,
365
+ $top: options.limit,
366
+ $skip: options.offset !== 0 ? options.offset : undefined
367
+ });
368
+ const reqOptions = { folderKey: options.folderKey };
369
+ const result = await withPimsCall((config2) => pimsGet(config2, `/incidents/summary${query}`, reqOptions), "Error listing incidents");
370
+ if (!result)
371
+ return;
372
+ OutputFormatter.success({
373
+ Result: RESULTS.Success,
374
+ Code: "IncidentSummary",
375
+ Data: result
376
+ });
377
+ });
378
+ incident.command("get").description(`Get a single ${toolLabel} incident by ID`).argument("<incident-id>", "Incident ID").requiredOption("-f, --folder-key <key>", "Folder key").trackedAction(processContext, async (incidentId, options) => {
379
+ const reqOptions = { folderKey: options.folderKey };
380
+ const result = await withPimsCall((config2) => pimsGet(config2, `/incidents/${encodeURIComponent(incidentId)}`, reqOptions), "Error getting incident", { resource: "incident", id: incidentId });
381
+ if (!result)
382
+ return;
383
+ OutputFormatter.success({
384
+ Result: RESULTS.Success,
385
+ Code: "IncidentGet",
386
+ Data: result
387
+ });
388
+ });
389
+ };
390
+
391
+ // ../maestro-sdk/src/instance-status.ts
392
+ var INSTANCE_STATUSES = [
393
+ "Canceling",
394
+ "Cancelled",
395
+ "Completed",
396
+ "Faulted",
397
+ "Paused",
398
+ "Pausing",
399
+ "Pending",
400
+ "Resuming",
401
+ "Retrying",
402
+ "Running",
403
+ "Upgrading"
404
+ ];
405
+ var STATUS_ALIASES = new Map([
406
+ ["successful", "Completed"],
407
+ ["success", "Completed"],
408
+ ["canceled", "Cancelled"]
409
+ ]);
410
+ var CANONICAL_BY_LOWER = new Map(INSTANCE_STATUSES.map((status) => [status.toLowerCase(), status]));
411
+ function resolveInstanceStatus(raw) {
412
+ const normalized = raw.trim().toLowerCase();
413
+ return CANONICAL_BY_LOWER.get(normalized) ?? STATUS_ALIASES.get(normalized);
414
+ }
415
+ var INSTANCE_STATUS_LIST = INSTANCE_STATUSES.join(", ");
416
+ function resolveInstanceStatuses(raw) {
417
+ const statuses = [];
418
+ const invalid = [];
419
+ for (const value of raw) {
420
+ const resolved = resolveInstanceStatus(value);
421
+ if (resolved === undefined) {
422
+ invalid.push(value);
423
+ continue;
424
+ }
425
+ if (!statuses.includes(resolved)) {
426
+ statuses.push(resolved);
427
+ }
428
+ }
429
+ return { statuses, invalid };
430
+ }
431
+
432
+ // ../maestro-sdk/src/shared-commands/instances.ts
433
+ var collectStatus = (raw, prev) => [...prev, raw];
434
+ var MAX_INSTANCE_PAGE_SIZE = 500;
435
+ var parseInstanceLimit = (raw) => parseBoundedInt(raw, "--limit", { min: 1, max: MAX_INSTANCE_PAGE_SIZE });
436
+ function extractProcessInstances(result) {
437
+ if (Array.isArray(result)) {
438
+ return result;
439
+ }
440
+ return result.instances ?? result.value ?? result.items ?? [];
441
+ }
442
+ function extractInstanceCursor(result) {
443
+ if (Array.isArray(result)) {
444
+ return { hasMore: false };
445
+ }
446
+ const nextPage = result.nextPage ?? undefined;
447
+ return {
448
+ nextPage,
449
+ hasMore: result.hasMoreResults ?? nextPage !== undefined
450
+ };
451
+ }
452
+ var failListFilter = (message, instructions) => {
453
+ OutputFormatter.error({
454
+ Result: RESULTS.ValidationError,
455
+ Message: message,
456
+ Instructions: instructions
457
+ });
458
+ processContext.exit(EXIT_CODES.ValidationError);
459
+ return null;
460
+ };
461
+ function resolveListFilters(options) {
462
+ if (options.offset !== undefined && Number(options.offset) !== 0) {
463
+ return failListFilter("--offset is not supported when listing process instances", "The instances API pages by cursor, not by offset. Drop --offset, " + "then pass the Pagination.NextPage value from the previous " + "response to --next-page.");
464
+ }
465
+ if (options.processKey !== undefined && !isGuid(options.processKey)) {
466
+ return failListFilter(`--process-key expects a process key (GUID), got '${options.processKey}'`, "Pass the instance's processKey. For the dotted package " + "identifier that `uip or processes list` prints as ProcessKey, " + "use --package-id instead.");
467
+ }
468
+ const { statuses, invalid } = resolveInstanceStatuses(options.status ?? []);
469
+ if (invalid.length > 0) {
470
+ return failListFilter(`Invalid --status value${invalid.length > 1 ? "s" : ""}: ${invalid.join(", ")}`, `Valid values: ${INSTANCE_STATUS_LIST}.`);
471
+ }
472
+ return { statuses: statuses.length > 0 ? statuses : undefined };
473
+ }
474
+ var registerSharedInstanceCommands = (program, config) => {
475
+ const {
476
+ toolLabel,
477
+ assetType,
478
+ processType,
479
+ includeElementExecutions = true,
480
+ folderKeyRequired = true,
481
+ listFolderKeyRequired = folderKeyRequired
482
+ } = config;
483
+ const withFolderKey = (cmd, required = folderKeyRequired) => required ? cmd.requiredOption("-f, --folder-key <key>", "Folder key (GUID)") : cmd.option("-f, --folder-key <key>", "Folder key (GUID)");
484
+ const instances = program.command("instance").description(`Manage ${toolLabel} process instances`);
485
+ const listCmd = instances.command("list").description(`List ${toolLabel} process instances. Filters are applied by the ` + "server: --status narrows by run status, --process-key by " + "process key (GUID), --package-id by package identifier, and " + "--from-date/--to-date by start time. Results page by cursor " + "— read Pagination.NextPage and pass it back via --next-page.");
486
+ withFolderKey(listCmd, listFolderKeyRequired).option("-l, --limit <number>", `Number of items to return (1-${MAX_INSTANCE_PAGE_SIZE})`, parseInstanceLimit, DEFAULT_PAGE_SIZE).option("--offset <number>", "Not supported by the instances API — use --next-page instead").option("--next-page <cursor>", "Cursor from a previous response's Pagination.NextPage").option("--process-key <process-key>", "Filter by process key (GUID). For the dotted package " + "identifier use --package-id.").option("--package-id <id>", "Filter by package ID").option("--error-code <code>", "Filter by error code").option("--status <status>", "Filter by instance status (repeatable; OR-semantics). " + `Values: ${INSTANCE_STATUS_LIST}.`, collectStatus, []).option("--from-date <iso-8601>", "Only include instances started at or after this ISO-8601 " + "timestamp (e.g. 2026-01-01T00:00:00Z).").option("--to-date <iso-8601>", "Only include instances started at or before this ISO-8601 " + "timestamp (e.g. 2026-02-01T00:00:00Z).").trackedAction(processContext, async (options) => {
487
+ const filters = resolveListFilters(options);
488
+ if (!filters)
489
+ return;
490
+ const query = buildQueryString({
491
+ processKey: options.processKey,
492
+ packageId: options.packageId,
493
+ errorCode: options.errorCode,
494
+ statuses: filters.statuses?.join(","),
495
+ startedTimeUtcStart: options.fromDate,
496
+ startedTimeUtcEnd: options.toDate,
497
+ processType,
498
+ pageSize: options.limit,
499
+ nextPage: options.nextPage
500
+ });
501
+ const reqOptions = { folderKey: options.folderKey };
502
+ const result = await withPimsCall((config2) => pimsGet(config2, `/instances${query}`, reqOptions), "Error listing instances");
503
+ if (!result)
504
+ return;
505
+ const instanceList = extractProcessInstances(result);
506
+ const cursor = extractInstanceCursor(result);
507
+ OutputFormatter.success({
508
+ Result: RESULTS.Success,
509
+ Code: "InstanceList",
510
+ Data: instanceList,
511
+ Pagination: new Pagination({
512
+ returned: instanceList.length,
513
+ limit: options.limit,
514
+ hasMore: cursor.hasMore,
515
+ nextPage: cursor.nextPage
516
+ })
517
+ });
518
+ });
519
+ const getCmd = instances.command("get").description(`Get a ${toolLabel} process instance by ID`).argument("<instance-id>", "Process instance ID");
520
+ withFolderKey(getCmd).trackedAction(processContext, async (instanceId, options) => {
521
+ const result = await withPimsCall((config2) => pimsGet(config2, `/instances/${instanceId}`, { folderKey: options.folderKey }), "Error getting instance", { resource: "instance", id: instanceId });
522
+ if (!result)
523
+ return;
524
+ OutputFormatter.success({
525
+ Result: RESULTS.Success,
526
+ Code: "InstanceGet",
527
+ Data: result
528
+ });
529
+ });
530
+ const pauseCmd = instances.command("pause").description(`Pause a running ${toolLabel} process instance`).argument("<instance-id>", "Process instance ID");
531
+ withFolderKey(pauseCmd).option("--comment <text>", "Optional comment for the operation").trackedAction(processContext, async (instanceId, options) => {
532
+ const body = { comment: options.comment || "" };
533
+ const reqOptions = { folderKey: options.folderKey };
534
+ const result = await withPimsCall((config2) => pimsPost(config2, `/instances/${instanceId}/pause`, body, reqOptions), "Error pausing instance");
535
+ if (!result)
536
+ return;
537
+ OutputFormatter.success({
538
+ Result: RESULTS.Success,
539
+ Code: "InstancePaused",
540
+ Data: result
541
+ });
542
+ });
543
+ const resumeCmd = instances.command("resume").description(`Resume a paused ${toolLabel} process instance`).argument("<instance-id>", "Process instance ID");
544
+ withFolderKey(resumeCmd).option("--comment <text>", "Optional comment for the operation").trackedAction(processContext, async (instanceId, options) => {
545
+ const body = { comment: options.comment || "" };
546
+ const reqOptions = { folderKey: options.folderKey };
547
+ const result = await withPimsCall((config2) => pimsPost(config2, `/instances/${instanceId}/resume`, body, reqOptions), "Error resuming instance");
548
+ if (!result)
549
+ return;
550
+ OutputFormatter.success({
551
+ Result: RESULTS.Success,
552
+ Code: "InstanceResumed",
553
+ Data: result
554
+ });
555
+ });
556
+ const cancelCmd = instances.command("cancel").description(`Cancel a ${toolLabel} process instance`).argument("<instance-id>", "Process instance ID");
557
+ withFolderKey(cancelCmd).option("--comment <text>", "Optional comment for the operation").trackedAction(processContext, async (instanceId, options) => {
558
+ const body = { comment: options.comment || "" };
559
+ const reqOptions = { folderKey: options.folderKey };
560
+ const result = await withPimsCall((config2) => pimsPost(config2, `/instances/${instanceId}/cancel`, body, reqOptions), "Error canceling instance");
561
+ if (!result)
562
+ return;
563
+ OutputFormatter.success({
564
+ Result: RESULTS.Success,
565
+ Code: "InstanceCanceled",
566
+ Data: result
567
+ });
568
+ });
569
+ const variablesCmd = instances.command("variables").description(`Get variables for a ${toolLabel} process instance`).argument("<instance-id>", "Process instance ID");
570
+ withFolderKey(variablesCmd).option("--parent-element-id <id>", "Filter variables by parent element ID").trackedAction(processContext, async (instanceId, options) => {
571
+ const query = buildQueryString({
572
+ parentElementId: options.parentElementId
573
+ });
574
+ const reqOptions = { folderKey: options.folderKey };
575
+ const result = await withPimsCall((config2) => pimsGet(config2, `/instances/${instanceId}/variables${query}`, reqOptions), "Error getting variables");
576
+ if (!result)
577
+ return;
578
+ OutputFormatter.success({
579
+ Result: RESULTS.Success,
580
+ Code: "InstanceVariables",
581
+ Data: result
582
+ });
583
+ });
584
+ const incidentsCmd = instances.command("incidents").description(`Get incidents for a ${toolLabel} process instance`).argument("<instance-id>", "Process instance ID");
585
+ withFolderKey(incidentsCmd).trackedAction(processContext, async (instanceId, options) => {
586
+ const result = await withPimsCall((config2) => pimsGet(config2, `/instances/${instanceId}/incidents`, { folderKey: options.folderKey }), "Error getting incidents");
587
+ if (!result)
588
+ return;
589
+ OutputFormatter.success({
590
+ Result: RESULTS.Success,
591
+ Code: "InstanceIncidents",
592
+ Data: result
593
+ });
594
+ });
595
+ const assetCmd = instances.command("asset").description(`Get the ${toolLabel} definition for a process instance`).argument("<instance-id>", "Process instance ID");
596
+ withFolderKey(assetCmd).trackedAction(processContext, async (instanceId, options) => {
597
+ const result = await withPimsCall((config2) => pimsGet(config2, `/instances/${instanceId}/asset?type=${assetType}`, { folderKey: options.folderKey }), "Error getting asset");
598
+ if (!result)
599
+ return;
600
+ OutputFormatter.success({
601
+ Result: RESULTS.Success,
602
+ Code: "InstanceAsset",
603
+ Data: result
604
+ });
605
+ });
606
+ const retryCmd = instances.command("retry").description(`Retry a faulted ${toolLabel} process instance`).argument("<instance-id>", "Process instance ID");
607
+ withFolderKey(retryCmd).option("--comment <text>", "Optional comment for the operation").trackedAction(processContext, async (instanceId, options) => {
608
+ const body = { comment: options.comment || "" };
609
+ const reqOptions = { folderKey: options.folderKey };
610
+ const result = await withPimsCall((config2) => pimsPost(config2, `/instances/${instanceId}/retry`, body, reqOptions), "Error retrying instance");
611
+ if (!result)
612
+ return;
613
+ OutputFormatter.success({
614
+ Result: RESULTS.Success,
615
+ Code: "InstanceRetried",
616
+ Data: result
617
+ });
618
+ });
619
+ const migrateCmd = instances.command("migrate").description(`Migrate a ${toolLabel} process instance to a different package version`).argument("<instance-id>", "Process instance ID").argument("<new-version>", "Target package version");
620
+ withFolderKey(migrateCmd).option("--comment <text>", "Optional comment for the operation").trackedAction(processContext, async (instanceId, newVersion, options) => {
621
+ const body = {
622
+ newVersion,
623
+ comment: options.comment || ""
624
+ };
625
+ const reqOptions = { folderKey: options.folderKey };
626
+ const result = await withPimsCall((config2) => pimsPost(config2, `/instances/${instanceId}/upgrade`, body, reqOptions), "Error migrating instance");
627
+ if (!result)
628
+ return;
629
+ OutputFormatter.success({
630
+ Result: RESULTS.Success,
631
+ Code: "InstanceMigrated",
632
+ Data: result
633
+ });
634
+ });
635
+ const gotoCmd = instances.command("goto").description("Move execution cursor from one element to another").argument("<instance-id>", "Process instance ID").argument("<transitions>", `JSON array of transitions, e.g. '[{"sourceElementId":"A","targetElementId":"B"}]'`);
636
+ withFolderKey(gotoCmd).trackedAction(processContext, async (instanceId, transitionsJson, options) => {
637
+ const [parseError, transitions] = catchError(() => JSON.parse(transitionsJson));
638
+ const isValidShape = !parseError && Array.isArray(transitions) && transitions.every((t) => t?.sourceElementId != null && t?.targetElementId != null);
639
+ if (!isValidShape) {
640
+ OutputFormatter.error({
641
+ Result: RESULTS.Failure,
642
+ Message: "Error applying goto",
643
+ Instructions: parseError ? `Invalid transitions JSON: ${parseError.message}` : 'Each transition must have "sourceElementId" and "targetElementId"'
644
+ });
645
+ processContext.exit(1);
646
+ return;
647
+ }
648
+ const body = { transitions };
649
+ const reqOptions = { folderKey: options.folderKey };
650
+ const result = await withPimsCall((config2) => pimsPost(config2, `/instances/${instanceId}/goto`, body, reqOptions), "Error applying goto");
651
+ if (!result)
652
+ return;
653
+ OutputFormatter.success({
654
+ Result: RESULTS.Success,
655
+ Code: "InstanceGoto",
656
+ Data: result
657
+ });
658
+ });
659
+ const cursorsCmd = instances.command("cursors").description(`Get current execution cursor positions for a ${toolLabel} process instance`).argument("<instance-id>", "Process instance ID");
660
+ withFolderKey(cursorsCmd).trackedAction(processContext, async (instanceId, options) => {
661
+ const result = await withPimsCall((config2) => pimsGet(config2, `/instances/${instanceId}/goto/cursors`, { folderKey: options.folderKey }), "Error getting cursors");
662
+ if (!result)
663
+ return;
664
+ OutputFormatter.success({
665
+ Result: RESULTS.Success,
666
+ Code: "InstanceCursors",
667
+ Data: result
668
+ });
669
+ });
670
+ const messageCmd = instances.command("message").description(`Manage ${toolLabel} instance messages`);
671
+ messageCmd.command("send").description(`Send a message to ${toolLabel} workflow subscriptions`).requiredOption("-f, --folder-key <key>", "Folder key (GUID)").option("--inputs <value>", "Message payload as JSON string, @file path, or piped via stdin").trackedAction(processContext, async (options) => {
672
+ const [readError, body] = await catchError(resolveJsonInput({
673
+ inline: options.inputs,
674
+ allowStdin: true
675
+ }));
676
+ if (readError) {
677
+ OutputFormatter.error({
678
+ Result: RESULTS.Failure,
679
+ Message: "Error reading message input",
680
+ Instructions: readError.message
681
+ });
682
+ processContext.exit(1);
683
+ return;
684
+ }
685
+ if (body === undefined) {
686
+ OutputFormatter.error({
687
+ Result: RESULTS.Failure,
688
+ Message: "Missing message payload",
689
+ Instructions: "Provide --inputs <json|@file> or pipe JSON via stdin."
690
+ });
691
+ processContext.exit(1);
692
+ return;
693
+ }
694
+ const reqOptions = { folderKey: options.folderKey };
695
+ const result = await withPimsCall((config2) => pimsPost(config2, "/instances/messages/send", body, reqOptions), "Error sending message");
696
+ if (!result)
697
+ return;
698
+ OutputFormatter.success({
699
+ Result: RESULTS.Success,
700
+ Code: "MessageSent",
701
+ Data: result
702
+ });
703
+ });
704
+ if (includeElementExecutions) {
705
+ const elementExeCmd = instances.command("element-executions").description(`Get element executions for a ${toolLabel} process instance`).argument("<instance-id>", "Process instance ID");
706
+ withFolderKey(elementExeCmd).trackedAction(processContext, async (instanceId, options) => {
707
+ const result = await withPimsCall((config2) => pimsGet(config2, `/instances/${instanceId}/element-executions`, { folderKey: options.folderKey }), "Error getting element executions");
708
+ if (!result)
709
+ return;
710
+ OutputFormatter.success({
711
+ Result: RESULTS.Success,
712
+ Code: "InstanceElementExecutions",
713
+ Data: result
714
+ });
715
+ });
716
+ }
717
+ const variablesSetCmd = instances.command("variables-set").description(`Update variables for a ${toolLabel} process instance`).argument("<instance-id>", "Process instance ID");
718
+ withFolderKey(variablesSetCmd).option("--inputs <value>", "Patch variables payload as JSON string, @file path, or piped via stdin").trackedAction(processContext, async (instanceId, options) => {
719
+ const [readError, data] = await catchError(resolveJsonInput({
720
+ inline: options.inputs,
721
+ allowStdin: true
722
+ }));
723
+ if (readError) {
724
+ OutputFormatter.error({
725
+ Result: RESULTS.Failure,
726
+ Message: "Error reading variables input",
727
+ Instructions: readError.message
728
+ });
729
+ processContext.exit(1);
730
+ return;
731
+ }
732
+ if (data === undefined) {
733
+ OutputFormatter.error({
734
+ Result: RESULTS.Failure,
735
+ Message: "Missing variables payload",
736
+ Instructions: "Provide --inputs <json|@file> or pipe JSON via stdin."
737
+ });
738
+ processContext.exit(1);
739
+ return;
740
+ }
741
+ const body = data;
742
+ const reqOptions = { folderKey: options.folderKey };
743
+ const result = await withPimsCall((config2) => pimsPatch(config2, `/instances/${instanceId}/variables`, body, reqOptions), "Error updating variables");
744
+ if (!result)
745
+ return;
746
+ OutputFormatter.success({
747
+ Result: RESULTS.Success,
748
+ Code: "InstanceVariablesSet",
749
+ Data: result
750
+ });
751
+ });
752
+ const variablesAllCmd = instances.command("variables-all").description(`Get all variables (including subprocesses) for a ${toolLabel} process instance`).argument("<instance-id>", "Process instance ID");
753
+ withFolderKey(variablesAllCmd).trackedAction(processContext, async (instanceId, options) => {
754
+ const result = await withPimsCall((config2) => pimsGet(config2, `/instances/${instanceId}/variables-all`, { folderKey: options.folderKey }), "Error getting all variables");
755
+ if (!result)
756
+ return;
757
+ OutputFormatter.success({
758
+ Result: RESULTS.Success,
759
+ Code: "InstanceVariablesAll",
760
+ Data: result
761
+ });
762
+ });
763
+ const globalVarsCmd = instances.command("global-variables").description(`Get global variables for a ${toolLabel} process instance`).argument("<instance-id>", "Process instance ID");
764
+ withFolderKey(globalVarsCmd).trackedAction(processContext, async (instanceId, options) => {
765
+ const result = await withPimsCall((config2) => pimsGet(config2, `/instances/${instanceId}/global-variables`, { folderKey: options.folderKey }), "Error getting global variables");
766
+ if (!result)
767
+ return;
768
+ OutputFormatter.success({
769
+ Result: RESULTS.Success,
770
+ Code: "InstanceGlobalVariables",
771
+ Data: result
772
+ });
773
+ });
774
+ const element = instances.command("element").description(`Manage elements within a ${toolLabel} process instance`);
775
+ const elementCancelCmd = element.command("cancel").description(`Cancel a specific element in a ${toolLabel} process instance`).argument("<instance-id>", "Process instance ID").argument("<element-id>", "Element ID");
776
+ withFolderKey(elementCancelCmd).option("--comment <text>", "Optional comment for the operation").trackedAction(processContext, async (instanceId, elementId, options) => {
777
+ const body = { comment: options.comment || "" };
778
+ const reqOptions = { folderKey: options.folderKey };
779
+ const result = await withPimsCall((config2) => pimsPost(config2, `/instances/${instanceId}/element/${elementId}/cancel`, body, reqOptions), "Error canceling element");
780
+ if (!result)
781
+ return;
782
+ OutputFormatter.success({
783
+ Result: RESULTS.Success,
784
+ Code: "ElementCanceled",
785
+ Data: result
786
+ });
787
+ });
788
+ const elementRetryCmd = element.command("retry").description(`Retry a faulted element in a ${toolLabel} process instance`).argument("<instance-id>", "Process instance ID").argument("<element-id>", "Element ID");
789
+ withFolderKey(elementRetryCmd).option("--comment <text>", "Optional comment for the operation").trackedAction(processContext, async (instanceId, elementId, options) => {
790
+ const body = { comment: options.comment || "" };
791
+ const reqOptions = { folderKey: options.folderKey };
792
+ const result = await withPimsCall((config2) => pimsPost(config2, `/instances/${instanceId}/element/${elementId}/retry`, body, reqOptions), "Error retrying element");
793
+ if (!result)
794
+ return;
795
+ OutputFormatter.success({
796
+ Result: RESULTS.Success,
797
+ Code: "ElementRetried",
798
+ Data: result
799
+ });
800
+ });
801
+ };
802
+
803
+ // ../maestro-sdk/src/shared-commands/process.ts
804
+ var SEARCHABLE_TAG = "Searchable";
805
+ var parseBooleanFlag = (value) => {
806
+ if (value === "true")
807
+ return true;
808
+ if (value === "false")
809
+ return false;
810
+ throw new InvalidArgumentError(`Expected 'true' or 'false', got '${value}'.`);
811
+ };
812
+ var collectValue = (value, previous) => [
813
+ ...previous,
814
+ value
815
+ ];
816
+ var parseTagList = (csv) => csv === undefined ? [] : csv.split(",").map((tag) => tag.trim()).filter((tag) => tag.length > 0);
817
+ var applyFriendlyVariableTags = (variableTags, flags) => {
818
+ const elements = variableTags.elements ?? {};
819
+ const allOutputs = Object.entries(elements).flatMap(([elementId, el]) => (el.outputs ?? []).map((output) => ({ elementId, output })));
820
+ const available = allOutputs.map((o) => `${o.output.name} (element ${o.elementId})`).join(", ");
821
+ let targets;
822
+ if (flags.all) {
823
+ if (allOutputs.length === 0) {
824
+ throw new Error("This process has no taggable variables.");
825
+ }
826
+ targets = allOutputs;
827
+ } else {
828
+ const seen = new Set;
829
+ targets = [];
830
+ for (const name of flags.variable ?? []) {
831
+ const matches = allOutputs.filter((o) => o.output.name === name && (flags.elementId === undefined || o.elementId === flags.elementId));
832
+ if (matches.length === 0) {
833
+ throw new Error(available ? `No variable matched "${name}"${flags.elementId ? ` in element ${flags.elementId}` : ""}. Available: ${available}.` : "This process has no taggable variables.");
834
+ }
835
+ if (flags.elementId === undefined && new Set(matches.map((m) => m.elementId)).size > 1) {
836
+ const where = matches.map((m) => m.elementId).join(", ");
837
+ throw new Error(`Variable "${name}" exists in multiple elements (${where}). Pass --element-id to disambiguate (one --variable at a time), or --all to tag every occurrence.`);
838
+ }
839
+ for (const m of matches) {
840
+ if (!seen.has(m.output)) {
841
+ seen.add(m.output);
842
+ targets.push(m);
843
+ }
844
+ }
845
+ }
846
+ }
847
+ const replaceTags = flags.tags !== undefined ? parseTagList(flags.tags) : undefined;
848
+ const addTags = parseTagList(flags.addTags);
849
+ const removeSet = new Set(parseTagList(flags.removeTags));
850
+ return targets.map(({ elementId, output }) => {
851
+ const next = replaceTags !== undefined ? [...new Set(replaceTags)] : [...new Set([...output.tags ?? [], ...addTags])].filter((tag) => !removeSet.has(tag));
852
+ output.tags = next;
853
+ return { elementId, name: output.name, tags: next };
854
+ });
855
+ };
856
+ var buildSettingsPath = (processKey) => `/processes/${encodeURIComponent(processKey)}/settings`;
857
+ var validateFriendlyTagFlags = (options) => {
858
+ const variableCount = options.variable.length;
859
+ if (variableCount > 0 && options.all) {
860
+ return "Use either --variable or --all, not both.";
861
+ }
862
+ if (variableCount === 0 && !options.all) {
863
+ return "Specify the target with --variable <name> (repeatable, plus optional --element-id) or --all.";
864
+ }
865
+ if (variableCount > 1 && options.elementId !== undefined) {
866
+ return "--element-id only works with a single --variable; pass one --variable, or drop --element-id.";
867
+ }
868
+ const hasSearchable = options.searchable !== undefined;
869
+ const hasReplace = options.tags !== undefined;
870
+ const hasIncremental = options.addTags !== undefined || options.removeTags !== undefined;
871
+ if (hasSearchable && (hasReplace || hasIncremental)) {
872
+ return "Use --searchable <true|false>, or the low-level --tags/--add-tags/--remove-tags flags — not both.";
873
+ }
874
+ if (!hasSearchable && !hasReplace && !hasIncremental) {
875
+ return "Specify --searchable <true|false> to mark the variable searchable, or --tags/--add-tags/--remove-tags for other tags.";
876
+ }
877
+ if (hasReplace && hasIncremental) {
878
+ return "Use --tags to replace tags, or --add-tags/--remove-tags to adjust them — not both.";
879
+ }
880
+ return null;
881
+ };
882
+ var resolveTagFlags = (options) => {
883
+ if (options.searchable === undefined)
884
+ return options;
885
+ return {
886
+ variable: options.variable,
887
+ elementId: options.elementId,
888
+ all: options.all,
889
+ addTags: options.searchable ? SEARCHABLE_TAG : undefined,
890
+ removeTags: options.searchable ? undefined : SEARCHABLE_TAG
891
+ };
892
+ };
893
+ var setVariableTagsFromPayload = async (processKey, options) => {
894
+ const [fileError, variableTags] = await catchError(resolveJsonInput({ inline: options.inputs, allowStdin: true }));
895
+ if (fileError) {
896
+ OutputFormatter.error({
897
+ Result: RESULTS.Failure,
898
+ Message: "Error reading variable tags input",
899
+ Instructions: fileError.message
900
+ });
901
+ processContext.exit(1);
902
+ return;
903
+ }
904
+ if (variableTags === undefined) {
905
+ OutputFormatter.error({
906
+ Result: RESULTS.Failure,
907
+ Message: "Missing variable tags payload",
908
+ Instructions: "Provide --inputs <json|@file>, pipe JSON via stdin, or use the --variable/--all flags."
909
+ });
910
+ processContext.exit(1);
911
+ return;
912
+ }
913
+ const reqOptions = { folderKey: options.folderKey };
914
+ const currentSettings = await withPimsCall((config) => pimsGet(config, buildSettingsPath(processKey), reqOptions), "Error reading current process settings");
915
+ if (!currentSettings)
916
+ return;
917
+ const merged = { ...currentSettings, variableTags };
918
+ const result = await withPimsCall((config) => pimsPut(config, buildSettingsPath(processKey), merged, reqOptions), "Error updating variable tags");
919
+ if (!result)
920
+ return;
921
+ OutputFormatter.success({
922
+ Result: RESULTS.Success,
923
+ Code: "ProcessVariableTagsSet",
924
+ Data: result
925
+ });
926
+ };
927
+ var setVariableTagsFromFlags = async (processKey, options) => {
928
+ const reqOptions = { folderKey: options.folderKey };
929
+ const currentSettings = await withPimsCall((config) => pimsGet(config, buildSettingsPath(processKey), reqOptions), "Error reading current process settings");
930
+ if (!currentSettings)
931
+ return;
932
+ const variableTags = currentSettings.variableTags ?? {
933
+ elements: {},
934
+ sourcePackageVersion: "",
935
+ lastUpdateTimeUtc: ""
936
+ };
937
+ const [mutateError, updated] = catchError(() => applyFriendlyVariableTags(variableTags, resolveTagFlags(options)));
938
+ if (mutateError) {
939
+ OutputFormatter.error({
940
+ Result: RESULTS.Failure,
941
+ Message: "Error updating variable tags",
942
+ Instructions: mutateError.message
943
+ });
944
+ processContext.exit(1);
945
+ return;
946
+ }
947
+ const merged = { ...currentSettings, variableTags };
948
+ const result = await withPimsCall((config) => pimsPut(config, buildSettingsPath(processKey), merged, reqOptions), "Error updating variable tags");
949
+ if (!result)
950
+ return;
951
+ OutputFormatter.success({
952
+ Result: RESULTS.Success,
953
+ Code: "ProcessVariableTagsSet",
954
+ Data: { updated, variableTags }
955
+ });
956
+ };
957
+ var registerSharedProcessCommands = (processCmd, config) => {
958
+ const { toolLabel } = config;
959
+ const settingsCmd = processCmd.command("settings").description(`Manage ${toolLabel} process settings`);
960
+ settingsCmd.command("get").description(`Get settings for a ${toolLabel} process`).argument("<process-key>", "Process definition key").requiredOption("-f, --folder-key <key>", "Folder key (GUID)").trackedAction(processContext, async (processKey, options) => {
961
+ const reqOptions = { folderKey: options.folderKey };
962
+ const result = await withPimsCall((config2) => pimsGet(config2, `/processes/${encodeURIComponent(processKey)}/settings`, reqOptions), "Error getting process settings", { resource: "process", id: processKey });
963
+ if (!result)
964
+ return;
965
+ OutputFormatter.success({
966
+ Result: RESULTS.Success,
967
+ Code: "ProcessSettingsGet",
968
+ Data: result
969
+ });
970
+ });
971
+ settingsCmd.command("set").description(`Update settings for a ${toolLabel} process`).argument("<process-key>", "Process definition key").requiredOption("-f, --folder-key <key>", "Folder key (GUID)").option("--inputs <value>", "Settings payload as JSON string, @file path, or piped via stdin").trackedAction(processContext, async (processKey, options) => {
972
+ const [fileError, body] = await catchError(resolveJsonInput({
973
+ inline: options.inputs,
974
+ allowStdin: true
975
+ }));
976
+ if (fileError) {
977
+ OutputFormatter.error({
978
+ Result: RESULTS.Failure,
979
+ Message: "Error reading settings input",
980
+ Instructions: fileError.message
981
+ });
982
+ processContext.exit(1);
983
+ return;
984
+ }
985
+ if (body === undefined) {
986
+ OutputFormatter.error({
987
+ Result: RESULTS.Failure,
988
+ Message: "Missing settings payload",
989
+ Instructions: "Provide --inputs <json|@file> or pipe JSON via stdin."
990
+ });
991
+ processContext.exit(1);
992
+ return;
993
+ }
994
+ const reqOptions = { folderKey: options.folderKey };
995
+ const result = await withPimsCall((config2) => pimsPut(config2, `/processes/${encodeURIComponent(processKey)}/settings`, body, reqOptions), "Error updating process settings");
996
+ if (!result)
997
+ return;
998
+ OutputFormatter.success({
999
+ Result: RESULTS.Success,
1000
+ Code: "ProcessSettingsSet",
1001
+ Data: result
1002
+ });
1003
+ });
1004
+ const variableTagsCmd = processCmd.command("variable-tags").description(`Manage ${toolLabel} process variable tags`);
1005
+ variableTagsCmd.command("get").description(`Get variable tags for a ${toolLabel} process`).argument("<process-key>", "Process definition key").requiredOption("-f, --folder-key <key>", "Folder key (GUID)").trackedAction(processContext, async (processKey, options) => {
1006
+ const reqOptions = { folderKey: options.folderKey };
1007
+ const result = await withPimsCall((config2) => pimsGet(config2, `/processes/${encodeURIComponent(processKey)}/settings`, reqOptions), "Error getting variable tags", { resource: "process", id: processKey });
1008
+ if (!result)
1009
+ return;
1010
+ OutputFormatter.success({
1011
+ Result: RESULTS.Success,
1012
+ Code: "ProcessVariableTagsGet",
1013
+ Data: result.variableTags ?? {}
1014
+ });
1015
+ });
1016
+ variableTagsCmd.command("set").description(`Update variable tags for a ${toolLabel} process`).argument("<process-key>", "Process definition key").requiredOption("-f, --folder-key <key>", "Folder key (GUID)").option("--variable <name>", "Name of a variable (output) to tag. Repeatable — pass it multiple times to tag several variables in one call.", collectValue, []).option("--element-id <id>", "Element that owns the variable (disambiguates when the same name appears in multiple elements). Only valid with a single --variable.").option("--all", "Apply the change to every taggable variable").option("--searchable <boolean>", "Mark the variable searchable for instance filtering ('true' or 'false')", parseBooleanFlag).option("--tags <list>", "Advanced: comma-separated tags to set, replacing the variable's current tags (empty value clears them)").option("--add-tags <list>", "Comma-separated tags to add to the variable's current tags").option("--remove-tags <list>", "Comma-separated tags to remove from the variable's current tags").option("--inputs <value>", "Full variable tags payload as JSON string, @file path, or piped via stdin").trackedAction(processContext, async (processKey, options) => {
1017
+ const friendlyRequested = options.variable.length > 0 || options.elementId !== undefined || options.all === true || options.searchable !== undefined || options.tags !== undefined || options.addTags !== undefined || options.removeTags !== undefined;
1018
+ if (options.inputs !== undefined && friendlyRequested) {
1019
+ OutputFormatter.error({
1020
+ Result: RESULTS.Failure,
1021
+ Message: "Error updating variable tags",
1022
+ Instructions: "Provide either --inputs (full JSON payload) or the --searchable/--variable/--all flags, not both."
1023
+ });
1024
+ processContext.exit(1);
1025
+ return;
1026
+ }
1027
+ if (friendlyRequested) {
1028
+ const validationError = validateFriendlyTagFlags(options);
1029
+ if (validationError) {
1030
+ OutputFormatter.error({
1031
+ Result: RESULTS.Failure,
1032
+ Message: "Error updating variable tags",
1033
+ Instructions: validationError
1034
+ });
1035
+ processContext.exit(1);
1036
+ return;
1037
+ }
1038
+ await setVariableTagsFromFlags(processKey, options);
1039
+ return;
1040
+ }
1041
+ await setVariableTagsFromPayload(processKey, options);
1042
+ });
1043
+ };
1044
+
1045
+ // ../maestro-sdk/src/shared-commands/processes.ts
1046
+ function findProcessSummary(summaries, processKey) {
1047
+ return summaries.find((summary) => summary.processKey === processKey) ?? null;
1048
+ }
1049
+ var registerSharedProcessesCommands = (program, config) => {
1050
+ const { toolLabel, processType } = config;
1051
+ const processes = program.command("processes").description(`Manage ${toolLabel} process summaries`);
1052
+ processes.command("list").description(`List all ${toolLabel} process summaries`).option("--folder-key <key>", "Folder key").option("-l, --limit <number>", "Number of items to return (1-10000)", parseLimit).option("--offset <number>", "Number of items to skip (0-1000000)", parseOffset, 0).option("--status <status>", "Filter by process status").trackedAction(processContext, async (options) => {
1053
+ const query = buildQueryString({
1054
+ processType,
1055
+ status: options.status,
1056
+ $top: options.limit,
1057
+ $skip: options.offset !== 0 ? options.offset : undefined
1058
+ });
1059
+ const reqOptions = { folderKey: options.folderKey };
1060
+ const result = await withPimsCall((config2) => pimsGet(config2, `/processes/summary${query}`, reqOptions), "Error listing processes");
1061
+ if (!result)
1062
+ return;
1063
+ OutputFormatter.success({
1064
+ Result: RESULTS.Success,
1065
+ Code: "ProcessList",
1066
+ Data: result
1067
+ });
1068
+ });
1069
+ processes.command("incidents").description(`Get incidents for a specific ${toolLabel} process`).argument("<process-key>", "Process definition key").requiredOption("--folder-key <key>", "Folder key").trackedAction(processContext, async (processKey, options) => {
1070
+ const reqOptions = { folderKey: options.folderKey };
1071
+ const result = await withPimsCall((config2) => pimsGet(config2, `/incidents/process/${encodeURIComponent(processKey)}`, reqOptions), "Error getting process incidents", { resource: "process", id: processKey });
1072
+ if (!result)
1073
+ return;
1074
+ OutputFormatter.success({
1075
+ Result: RESULTS.Success,
1076
+ Code: "ProcessIncidents",
1077
+ Data: result
1078
+ });
1079
+ });
1080
+ processes.command("diagnose").description(`Correlate ${toolLabel} process summary, incidents, and error codes`).argument("<process-key>", "Process definition key").requiredOption("--folder-key <key>", "Folder key").trackedAction(processContext, async (processKey, options) => {
1081
+ const result = await withPimsCall(async (config2) => {
1082
+ const query = processType ? buildQueryString({ processType }) : "";
1083
+ const summaries = await pimsGet(config2, `/processes/summary${query}`);
1084
+ const incidents = await pimsGet(config2, `/incidents/process/${encodeURIComponent(processKey)}`, { folderKey: options.folderKey });
1085
+ const errorCodes = await pimsGet(config2, `/incidents/process/${encodeURIComponent(processKey)}/error-codes`, { folderKey: options.folderKey });
1086
+ return {
1087
+ summary: findProcessSummary(summaries, processKey),
1088
+ incidents,
1089
+ errorCodes: errorCodes.errorCodes || []
1090
+ };
1091
+ }, "Error diagnosing process");
1092
+ if (!result)
1093
+ return;
1094
+ OutputFormatter.success({
1095
+ Result: RESULTS.Success,
1096
+ Code: "ProcessDiagnostics",
1097
+ Data: {
1098
+ ProcessKey: processKey,
1099
+ FolderKey: options.folderKey,
1100
+ Summary: result.summary,
1101
+ FaultedCount: result.summary?.faultedCount ?? null,
1102
+ RunningCount: result.summary?.runningCount ?? null,
1103
+ Incidents: result.incidents,
1104
+ IncidentCount: result.incidents.length,
1105
+ ErrorCodes: result.errorCodes,
1106
+ ErrorCodeCount: result.errorCodes.length
1107
+ }
1108
+ });
1109
+ });
1110
+ processes.command("error-codes").description(`Get unique error codes for a specific ${toolLabel} process`).argument("<process-key>", "Process definition key").requiredOption("--folder-key <key>", "Folder key").trackedAction(processContext, async (processKey, options) => {
1111
+ const reqOptions = { folderKey: options.folderKey };
1112
+ const result = await withPimsCall((config2) => pimsGet(config2, `/incidents/process/${encodeURIComponent(processKey)}/error-codes`, reqOptions), "Error getting process error codes", { resource: "process", id: processKey });
1113
+ if (!result)
1114
+ return;
1115
+ OutputFormatter.success({
1116
+ Result: RESULTS.Success,
1117
+ Code: "ProcessIncidentErrorCodes",
1118
+ Data: result.errorCodes || []
1119
+ });
1120
+ });
1121
+ };
1122
+
1123
+ export { registerSharedIncidentCommands, registerSharedInstanceCommands, registerSharedProcessCommands, registerSharedProcessesCommands };
1124
+
1125
+ //# debugId=8FE5E6DBD97B7F2164756E2164756E21