@thinkingai/ae-cli 6.0.40 → 6.0.41

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 (131) hide show
  1. package/README.md +0 -2
  2. package/README.zh.md +0 -2
  3. package/dist/{auth-NN55553T.js → auth-GBMV6TEJ.js} +2 -2
  4. package/dist/{auth-GDV3H5I4.js → auth-NDSXE54J.js} +4 -4
  5. package/dist/{capability-TPORIKRQ.js → capability-CETVHGXF.js} +25 -15
  6. package/dist/{capability-VQNC5CF7.js → capability-ZSQBMNOE.js} +25 -15
  7. package/dist/{chunk-GJJA4CQZ.js → chunk-3FY3RJ26.js} +0 -4
  8. package/dist/chunk-4E3DB4MM.js +556 -0
  9. package/dist/{chunk-GS2P7LFD.js → chunk-5XUSIK27.js} +2 -2
  10. package/dist/{chunk-VTXHDCBW.js → chunk-AFXA7BRK.js} +2 -2
  11. package/dist/{chunk-7KQWSBSL.js → chunk-FNZA5RZA.js} +8 -8
  12. package/dist/{chunk-TS6BUGUY.js → chunk-J2N4PB56.js} +8 -8
  13. package/dist/{chunk-RBNKI5ZW.js → chunk-JUW4AJXN.js} +2 -2
  14. package/dist/{chunk-Z3OXWCIA.js → chunk-S5NTSDBS.js} +2 -2
  15. package/dist/{chunk-VKD5WQKN.js → chunk-VLWOLBGZ.js} +142 -24
  16. package/dist/chunk-WANVG6SY.js +556 -0
  17. package/dist/{chunk-YTG6Q75E.js → chunk-WZRX4KOH.js} +25 -3
  18. package/dist/{chunk-YV52FB5G.js → chunk-ZQKDZXDO.js} +1 -1
  19. package/dist/{cli-token-GL5MS5FK.js → cli-token-4UPER74P.js} +3 -3
  20. package/dist/{chunk-6A2FUCIS.js → client-L2YDMHQ6.js} +5 -6
  21. package/dist/{config-4VZNLBKF.js → config-OL2LWGBV.js} +4 -33
  22. package/dist/index.js +31 -44
  23. package/dist/{memory-RWJW4XFO.js → memory-MUP7PPL7.js} +4 -4
  24. package/dist/{memory-VO2ZJCRT.js → memory-U4O5PMXH.js} +4 -4
  25. package/dist/{metadata-YGTHR2XJ.js → metadata-UKZDNLLQ.js} +21 -11
  26. package/dist/{metadata-ZRN2GHPN.js → metadata-XXMJFN2M.js} +21 -11
  27. package/dist/{model-CLUIK3K5.js → model-JTUEO5M4.js} +2 -2
  28. package/dist/{sync-3REDHGY6.js → sync-MOSFNBVR.js} +5 -5
  29. package/dist/{te-agent-XNPELAKX.js → te-agent-IFKZDHZI.js} +25 -18
  30. package/dist/{te-analysis-GJI5FZUL.js → te-analysis-3QLLS35K.js} +1231 -456
  31. package/dist/{te-analysis-N2BRDJZ5.js → te-analysis-YSK2DBVL.js} +1231 -456
  32. package/dist/{te-community-SQXKE5OO.js → te-community-HNKVTERD.js} +207 -12
  33. package/dist/{te-community-TYSNU3NQ.js → te-community-IWE5B7W6.js} +208 -12
  34. package/dist/{te-dataops-OWIADNSM.js → te-dataops-KQPYNAE3.js} +262 -145
  35. package/dist/{te-dataops-5TM7WZDI.js → te-dataops-KXCEB4CS.js} +262 -145
  36. package/dist/{te-engage-L72HWRGO.js → te-engage-6RNGK5GH.js} +566 -17
  37. package/dist/{te-engage-QWM4GFS7.js → te-engage-IRMHTSQK.js} +566 -17
  38. package/dist/{te-kb-VRMEY3D4.js → te-kb-OIH3T6CS.js} +4 -4
  39. package/dist/{te-system-XGS5EQIQ.js → te-system-AZ3URMUO.js} +515 -11
  40. package/dist/{te-team-BZRDV2CM.js → te-team-GZPU6UWA.js} +5 -5
  41. package/dist/{update-HEDXGOJH.js → update-TOBFXF2V.js} +4 -4
  42. package/package.json +5 -5
  43. package/skills/ae-agent/SKILL.md +3 -3
  44. package/skills/ae-agent/references/list-skill-references.md +4 -4
  45. package/skills/ae-agent/references/read-skill-reference.md +10 -7
  46. package/skills/ae-agent/references/upload-skill-reference.md +11 -9
  47. package/skills/ae-analysis/SKILL.md +15 -12
  48. package/skills/ae-analysis/metadata_resolution.md +150 -0
  49. package/skills/ae-analysis/references/adhoc_export.md +17 -2
  50. package/skills/ae-analysis/references/adhoc_run.md +12 -8
  51. package/skills/ae-analysis/references/ai_models.md +31 -5
  52. package/skills/ae-analysis/references/analysis_data_retrieval.md +104 -16
  53. package/skills/ae-analysis/references/analysis_drilldown_contract.md +4 -4
  54. package/skills/ae-analysis/references/analysis_gateway_assets.md +12 -10
  55. package/skills/ae-analysis/references/artifact_download.md +4 -3
  56. package/skills/ae-analysis/references/asset_abnormal_list.md +5 -3
  57. package/skills/ae-analysis/references/asset_authentication_list.md +5 -3
  58. package/skills/ae-analysis/references/asset_search.md +5 -3
  59. package/skills/ae-analysis/references/bi_panel_page_data_export.md +1 -1
  60. package/skills/ae-analysis/references/bi_panel_page_data_run.md +4 -4
  61. package/skills/ae-analysis/references/catalog_export.md +28 -0
  62. package/skills/ae-analysis/references/catalog_list.md +44 -0
  63. package/skills/ae-analysis/references/command_index.md +72 -63
  64. package/skills/ae-analysis/references/dashboard_report_data_run.md +11 -4
  65. package/skills/ae-analysis/references/datatable_version_list.md +5 -3
  66. package/skills/ae-analysis/references/drilldown_entities_run.md +4 -4
  67. package/skills/ae-analysis/references/drilldown_events_run.md +2 -2
  68. package/skills/ae-analysis/references/drilldown_user_events_export.md +1 -1
  69. package/skills/ae-analysis/references/drilldown_user_events_run.md +2 -2
  70. package/skills/ae-analysis/references/entity_detail_run.md +4 -4
  71. package/skills/ae-analysis/references/entity_id_import_options.md +1 -1
  72. package/skills/ae-analysis/references/event_detail_run.md +4 -4
  73. package/skills/ae-analysis/references/event_export.md +21 -0
  74. package/skills/ae-analysis/references/event_list.md +7 -6
  75. package/skills/ae-analysis/references/exchange_rule_list.md +5 -3
  76. package/skills/ae-analysis/references/history_tag_data_drilldown_export.md +4 -2
  77. package/skills/ae-analysis/references/history_tag_data_drilldown_run.md +2 -2
  78. package/skills/ae-analysis/references/history_tag_data_run.md +2 -2
  79. package/skills/ae-analysis/references/metric_export.md +21 -0
  80. package/skills/ae-analysis/references/metric_list.md +8 -7
  81. package/skills/ae-analysis/references/property_export.md +21 -0
  82. package/skills/ae-analysis/references/property_list.md +9 -8
  83. package/skills/ae-analysis/references/query_context_get.md +20 -0
  84. package/skills/ae-analysis/references/query_create_result_cluster.md +1 -1
  85. package/skills/ae-analysis/references/report_change_log_list.md +1 -1
  86. package/skills/ae-analysis/references/report_create.md +3 -3
  87. package/skills/ae-analysis/references/report_data_run.md +8 -8
  88. package/skills/ae-analysis/references/report_update.md +3 -3
  89. package/skills/ae-analysis/references/report_version_rollback.md +1 -1
  90. package/skills/ae-analysis/references/rule_list.md +6 -4
  91. package/skills/ae-analysis/references/run_inspect.md +8 -5
  92. package/skills/ae-analysis/references/run_wait.md +37 -0
  93. package/skills/ae-analysis/references/user_cluster_export.md +13 -0
  94. package/skills/ae-analysis/references/user_cluster_list.md +6 -2
  95. package/skills/ae-analysis/references/user_cluster_member_export.md +5 -3
  96. package/skills/ae-analysis/references/user_cluster_member_list.md +4 -4
  97. package/skills/ae-analysis/references/user_tag_export.md +13 -0
  98. package/skills/ae-analysis/references/user_tag_list.md +6 -2
  99. package/skills/ae-analysis/references/user_tag_member_export.md +5 -3
  100. package/skills/ae-analysis/references/user_tag_member_list.md +4 -4
  101. package/skills/ae-analysis/references/virtual_property_create.md +2 -2
  102. package/skills/ae-community/SKILL.md +2 -2
  103. package/skills/ae-dataops/SKILL.md +4 -3
  104. package/skills/ae-dataops/references/dataops-flow-create.md +47 -3
  105. package/skills/ae-engage/SKILL.md +46 -6
  106. package/skills/ae-engage/references/build-task-save-guide.md +12 -0
  107. package/skills/ae-engage/references/cancel-query-run.md +31 -0
  108. package/skills/ae-engage/references/config-item-analysis-report.md +14 -1
  109. package/skills/ae-engage/references/config-item-strategy-comparison.md +11 -1
  110. package/skills/ae-engage/references/config-item-trigger-report.md +15 -1
  111. package/skills/ae-engage/references/flow-metric-detail-report.md +134 -0
  112. package/skills/ae-engage/references/flow-metric-update.md +77 -0
  113. package/skills/ae-engage/references/flow-metric-user.md +118 -0
  114. package/skills/ae-engage/references/flow-node-metric-user.md +122 -0
  115. package/skills/ae-engage/references/flow-node-user.md +122 -0
  116. package/skills/ae-engage/references/push-record-query.md +32 -1
  117. package/skills/ae-engage/references/save-task.md +9 -0
  118. package/skills/ae-engage/references/task-data-detail.md +9 -2
  119. package/skills/ae-engage/references/task-metric-detail.md +9 -2
  120. package/skills/ae-engage/references/task-submit-approval.md +3 -0
  121. package/skills/ae-metadata/SKILL.md +2 -1
  122. package/skills/ae-metadata/references/metadata_data_table_download.md +10 -2
  123. package/skills/ae-metadata/references/metadata_data_table_list.md +5 -2
  124. package/skills/ae-system/SKILL.md +66 -3
  125. package/dist/chunk-DT6Y3TD7.js +0 -232
  126. package/dist/chunk-MVDZ7DBQ.js +0 -231
  127. package/dist/chunk-NBPKWKRA.js +0 -51
  128. package/dist/client-DAIPF7XN.js +0 -23
  129. package/dist/raw-52B4UKO4.js +0 -71
  130. package/dist/te-meta-53BVXPFI.js +0 -95
  131. package/dist/te-meta-TOCBPBXI.js +0 -95
@@ -0,0 +1,556 @@
1
+ import {
2
+ CapabilityGatewayError,
3
+ fetchCapabilityGateway,
4
+ requestCapabilityGateway
5
+ } from "./chunk-JUW4AJXN.js";
6
+ import {
7
+ readOutputMetadata,
8
+ unwrapOutputData,
9
+ withOutputMetadata
10
+ } from "./chunk-WZRX4KOH.js";
11
+ import {
12
+ resolveGatewayDomain
13
+ } from "./chunk-PTE56QPL.js";
14
+ import {
15
+ PermissionError
16
+ } from "./chunk-AXDXJTPC.js";
17
+
18
+ // src/core/analysis-async-artifact.ts
19
+ import { randomBytes } from "crypto";
20
+ import { createWriteStream } from "fs";
21
+ import { access, link, mkdir, rename, stat, unlink } from "fs/promises";
22
+ import { Readable } from "stream";
23
+ import { pipeline } from "stream/promises";
24
+ import { basename, dirname, join, resolve } from "path";
25
+ var MATERIALIZATION_GRACE_MS = 6e4;
26
+ var DEFAULT_EFFECTIVE_TIMEOUT_MS = 216e5;
27
+ var DEFAULT_WAIT_TIMEOUT_SECONDS = 600;
28
+ var MAX_WAIT_TIMEOUT_SECONDS = 21600;
29
+ var MAX_TRANSIENT_FAILURES = 3;
30
+ var asyncArtifactLifecycleFlags = [
31
+ {
32
+ name: "wait",
33
+ type: "boolean",
34
+ required: false,
35
+ desc: "Wait for the remote run and artifact to reach a terminal state. Polling uses short inspect requests; interrupting does not cancel the remote run."
36
+ },
37
+ {
38
+ name: "wait-timeout-seconds",
39
+ type: "number",
40
+ required: false,
41
+ min: 1,
42
+ max: MAX_WAIT_TIMEOUT_SECONDS,
43
+ desc: "Maximum time this CLI process waits. Default: 600 seconds; expiry never cancels the remote run."
44
+ },
45
+ {
46
+ name: "output",
47
+ type: "string",
48
+ required: false,
49
+ desc: "Wait, then stream the completed artifact to this local file. Implies --wait."
50
+ },
51
+ {
52
+ name: "force",
53
+ type: "boolean",
54
+ required: false,
55
+ desc: "Allow --output to atomically replace an existing file. Without this flag, existing paths are refused."
56
+ }
57
+ ];
58
+ function withAsyncArtifactLifecycle(command, options = {}) {
59
+ const originalValidate = command.validate;
60
+ const originalPreflight = command.preflight;
61
+ return {
62
+ ...command,
63
+ flags: [...command.flags, ...asyncArtifactLifecycleFlags],
64
+ validate: (ctx) => {
65
+ originalValidate?.(ctx);
66
+ validateLifecycleFlags(ctx);
67
+ },
68
+ preflight: (ctx) => {
69
+ originalPreflight?.(ctx);
70
+ validateLifecycleFlags(ctx);
71
+ },
72
+ execute: async (ctx) => {
73
+ validateLifecycleFlags(ctx);
74
+ const output = optionalString(ctx, "output");
75
+ if (output) {
76
+ if (options.preflightOutput) {
77
+ await options.preflightOutput({
78
+ ctx,
79
+ output,
80
+ force: ctx.bool("force")
81
+ });
82
+ } else {
83
+ await assertOutputPathAvailable(output, ctx.bool("force"));
84
+ }
85
+ }
86
+ const submission = await command.execute(ctx);
87
+ const descriptor = asDescriptor(unwrapOutputData(submission));
88
+ const runId = nonEmptyString(descriptor.run_id);
89
+ const artifactId = descriptorArtifactId(descriptor);
90
+ if (!runId || !artifactId) {
91
+ throw protocolError(
92
+ "Async artifact submission did not return both run_id and artifact_id.",
93
+ runId
94
+ );
95
+ }
96
+ announceSubmitted(runId, artifactId);
97
+ if (!ctx.bool("wait") && output === void 0) {
98
+ return submission;
99
+ }
100
+ const finalResult = await withInterruptSignal(async (signal) => {
101
+ const finalDescriptor = await waitForAnalysisRun(ctx.host(), runId, {
102
+ expectedArtifactId: artifactId,
103
+ initialDescriptor: descriptor,
104
+ signal,
105
+ waitTimeoutSeconds: clientWaitTimeoutSeconds(ctx)
106
+ });
107
+ if (!output) return finalDescriptor;
108
+ const download = options.materialize ? await options.materialize({
109
+ ctx,
110
+ runId,
111
+ artifactId,
112
+ output,
113
+ force: ctx.bool("force"),
114
+ signal,
115
+ finalDescriptor
116
+ }) : await downloadAnalysisArtifact(
117
+ ctx.host(),
118
+ runId,
119
+ artifactId,
120
+ output,
121
+ { force: ctx.bool("force"), signal, ensureReady: false }
122
+ );
123
+ return { ...finalDescriptor, ...download };
124
+ }, runId);
125
+ return withOutputMetadata(finalResult, readOutputMetadata(submission));
126
+ }
127
+ };
128
+ }
129
+ async function waitForAnalysisRun(host, runId, options = {}) {
130
+ const now = options.now ?? Date.now;
131
+ const sleep = options.sleep ?? abortableSleep;
132
+ const inspect = options.inspect ?? inspectAnalysisRun;
133
+ const startedAt = now();
134
+ const waitTimeoutSeconds = options.waitTimeoutSeconds ?? DEFAULT_WAIT_TIMEOUT_SECONDS;
135
+ const clientDeadline = startedAt + waitTimeoutSeconds * 1e3;
136
+ let deadline = deriveDeadline(options.initialDescriptor, startedAt);
137
+ let delayMs = 1e3;
138
+ let transientFailures = 0;
139
+ let lastState = "";
140
+ let materializationStartedAt;
141
+ let descriptor = options.initialDescriptor;
142
+ while (true) {
143
+ throwIfAborted(options.signal, runId);
144
+ if (descriptor !== void 0 && descriptorRunStatus(descriptor) === void 0) {
145
+ descriptor = void 0;
146
+ }
147
+ if (descriptor === void 0) {
148
+ try {
149
+ descriptor = asDescriptor(await inspect(host, runId));
150
+ transientFailures = 0;
151
+ } catch (error) {
152
+ if (error instanceof PermissionError) throw error;
153
+ if (error instanceof CapabilityGatewayError && error.httpStatus === 404) {
154
+ throw new CapabilityGatewayError(
155
+ `Async run ${runId} was not found on the current host.`,
156
+ "ASYNC_RUN_NOT_FOUND",
157
+ 404,
158
+ "Do not keep polling. Verify that the run ID belongs to this host and that the run lifecycle route is deployed.",
159
+ { run_id: runId }
160
+ );
161
+ }
162
+ if (!isTransientPollError(error) || ++transientFailures >= MAX_TRANSIENT_FAILURES) {
163
+ throw waitError(
164
+ `Could not inspect async run ${runId}${transientFailures > 0 ? ` after ${transientFailures} transient failures` : ""}.`,
165
+ "ASYNC_RUN_INSPECT_FAILED",
166
+ runId,
167
+ error
168
+ );
169
+ }
170
+ await sleep(delayMs, options.signal);
171
+ delayMs = nextDelay(delayMs);
172
+ continue;
173
+ }
174
+ }
175
+ deadline = Math.min(deadline, deriveDeadline(descriptor, startedAt));
176
+ const runStatus = descriptorRunStatus(descriptor);
177
+ const artifactStatus = normalizedStatus(descriptor.artifact_status ?? descriptor.artifact?.status);
178
+ const artifactId = descriptorArtifactId(descriptor);
179
+ if (options.expectedArtifactId && artifactId && artifactId !== options.expectedArtifactId) {
180
+ throw new CapabilityGatewayError(
181
+ `artifact_id ${artifactId} does not match the submitted artifact ${options.expectedArtifactId}.`,
182
+ "ARTIFACT_RUN_MISMATCH",
183
+ 400,
184
+ resumeHint(runId),
185
+ { run_id: runId, artifact_id: artifactId, expected_artifact_id: options.expectedArtifactId }
186
+ );
187
+ }
188
+ const state = `${runStatus || "UNKNOWN"}/${artifactStatus || "UNKNOWN"}`;
189
+ if (state !== lastState) {
190
+ process.stderr.write(`[ae-cli] run_id=${runId} state=${state}
191
+ `);
192
+ lastState = state;
193
+ }
194
+ if (runStatus === "FAILED" || runStatus === "CANCELED") {
195
+ throw terminalError(descriptor, runId, `Run ended with status ${runStatus}.`);
196
+ }
197
+ if (artifactStatus === "FAILED" || artifactStatus === "CANCELED") {
198
+ throw terminalError(descriptor, runId, `Artifact ended with status ${artifactStatus}.`);
199
+ }
200
+ if (runStatus === "SUCCEEDED" && artifactStatus === "COMPLETED") {
201
+ if (!artifactId) {
202
+ throw protocolError("Completed async run has no artifact_id.", runId);
203
+ }
204
+ return descriptor;
205
+ }
206
+ if (runStatus !== "RUNNING" && runStatus !== "SUCCEEDED") {
207
+ throw protocolError(`Unknown async run status: ${runStatus || "missing"}.`, runId);
208
+ }
209
+ if (artifactStatus && artifactStatus !== "RUNNING" && artifactStatus !== "COMPLETED") {
210
+ throw protocolError(`Unknown async artifact status: ${artifactStatus}.`, runId);
211
+ }
212
+ if (runStatus === "RUNNING" && artifactStatus === "COMPLETED") {
213
+ throw protocolError("Artifact is COMPLETED while its run is still RUNNING.", runId);
214
+ }
215
+ if (runStatus === "SUCCEEDED" && materializationStartedAt === void 0) {
216
+ materializationStartedAt = now();
217
+ }
218
+ const lifecycleDeadline = materializationStartedAt === void 0 ? deadline : Math.min(deadline, materializationStartedAt + MATERIALIZATION_GRACE_MS);
219
+ const effectiveDeadline = Math.min(clientDeadline, lifecycleDeadline);
220
+ if (now() >= effectiveDeadline) {
221
+ if (clientDeadline <= lifecycleDeadline) {
222
+ throw waitError(
223
+ `Stopped waiting after ${waitTimeoutSeconds} seconds for run ${runId}. The remote run was not canceled.`,
224
+ "ASYNC_WAIT_TIMEOUT",
225
+ runId,
226
+ void 0,
227
+ descriptor,
228
+ { wait_timeout_seconds: waitTimeoutSeconds }
229
+ );
230
+ }
231
+ throw waitError(
232
+ `Stopped waiting because the server-declared deadline for run ${runId} was reached. The remote run was not canceled.`,
233
+ "ASYNC_WAIT_DEADLINE_REACHED",
234
+ runId,
235
+ void 0,
236
+ descriptor
237
+ );
238
+ }
239
+ await sleep(Math.min(delayMs, Math.max(0, effectiveDeadline - now())), options.signal);
240
+ delayMs = nextDelay(delayMs);
241
+ descriptor = void 0;
242
+ }
243
+ }
244
+ async function downloadAnalysisArtifact(host, runId, artifactId, output, options = {}) {
245
+ const outputPath = resolve(output);
246
+ await assertOutputPathAvailable(outputPath, options.force, { run_id: runId, artifact_id: artifactId });
247
+ if (options.ensureReady !== false) {
248
+ const descriptor = await inspectAnalysisRun(host, runId);
249
+ ensureCompletedDescriptor(descriptor, runId, artifactId);
250
+ }
251
+ await mkdir(dirname(outputPath), { recursive: true });
252
+ const tempPath = join(
253
+ dirname(outputPath),
254
+ `.${basename(outputPath)}.part-${process.pid}-${randomBytes(6).toString("hex")}`
255
+ );
256
+ let tempPresent = false;
257
+ try {
258
+ throwIfAborted(options.signal, runId);
259
+ const response = await fetchArtifact(host, runId, artifactId);
260
+ if (!response.body) {
261
+ throw protocolError("Artifact download response has no body.", runId);
262
+ }
263
+ tempPresent = true;
264
+ const source = Readable.fromWeb(response.body);
265
+ await pipeline(source, createWriteStream(tempPath, { flags: "wx" }), {
266
+ signal: options.signal
267
+ });
268
+ const file = await stat(tempPath);
269
+ if (options.force) {
270
+ await rename(tempPath, outputPath);
271
+ } else {
272
+ try {
273
+ await link(tempPath, outputPath);
274
+ } catch (error) {
275
+ if (error?.code === "EEXIST") {
276
+ throw new CapabilityGatewayError(
277
+ `Output path already exists: ${outputPath}`,
278
+ "OUTPUT_ALREADY_EXISTS",
279
+ 409,
280
+ "Choose another --output path or pass --force to replace the existing file.",
281
+ { run_id: runId, artifact_id: artifactId, output_path: outputPath }
282
+ );
283
+ }
284
+ throw error;
285
+ }
286
+ await unlink(tempPath);
287
+ }
288
+ tempPresent = false;
289
+ return {
290
+ run_id: runId,
291
+ artifact_id: artifactId,
292
+ output_path: outputPath,
293
+ bytes: file.size,
294
+ content_type: response.headers.get("content-type") ?? void 0,
295
+ content_encoding: response.headers.get("content-encoding") ?? void 0,
296
+ content_disposition: response.headers.get("content-disposition") ?? void 0
297
+ };
298
+ } catch (error) {
299
+ if (options.signal?.aborted) {
300
+ throw interruptedError(runId);
301
+ }
302
+ throw error;
303
+ } finally {
304
+ if (tempPresent) await unlink(tempPath).catch(() => void 0);
305
+ }
306
+ }
307
+ function validateLifecycleFlags(ctx, waitImplied = false) {
308
+ const output = optionalString(ctx, "output");
309
+ if (ctx.bool("force") && output === void 0) {
310
+ const error = new Error("--force requires --output.");
311
+ error.type = "validation";
312
+ throw error;
313
+ }
314
+ const waitTimeout = optionalContextNumber(ctx, "wait-timeout-seconds");
315
+ if (waitTimeout !== void 0) {
316
+ if (!Number.isInteger(waitTimeout) || waitTimeout < 1 || waitTimeout > MAX_WAIT_TIMEOUT_SECONDS) {
317
+ const error = new Error(`--wait-timeout-seconds must be an integer between 1 and ${MAX_WAIT_TIMEOUT_SECONDS}.`);
318
+ error.type = "validation";
319
+ throw error;
320
+ }
321
+ if (!waitImplied && !ctx.bool("wait") && output === void 0) {
322
+ const error = new Error("--wait-timeout-seconds requires --wait or --output.");
323
+ error.type = "validation";
324
+ throw error;
325
+ }
326
+ }
327
+ }
328
+ function clientWaitTimeoutSeconds(ctx) {
329
+ return optionalContextNumber(ctx, "wait-timeout-seconds") ?? DEFAULT_WAIT_TIMEOUT_SECONDS;
330
+ }
331
+ function optionalContextNumber(ctx, name) {
332
+ if (typeof ctx.optionalNum === "function") {
333
+ return ctx.optionalNum(name);
334
+ }
335
+ const raw = ctx.str(name);
336
+ return raw.trim() === "" ? void 0 : Number(raw);
337
+ }
338
+ async function assertOutputPathAvailable(output, force = false, meta = {}) {
339
+ const outputPath = resolve(output);
340
+ if (force || !await pathExists(outputPath)) return;
341
+ throw new CapabilityGatewayError(
342
+ `Output path already exists: ${outputPath}`,
343
+ "OUTPUT_ALREADY_EXISTS",
344
+ 409,
345
+ "Choose another --output path or pass --force to replace the existing file.",
346
+ { ...meta, output_path: outputPath }
347
+ );
348
+ }
349
+ async function withInterruptSignal(operation, runId) {
350
+ const controller = new AbortController();
351
+ const onInterrupt = () => controller.abort();
352
+ process.once("SIGINT", onInterrupt);
353
+ try {
354
+ return await operation(controller.signal);
355
+ } catch (error) {
356
+ if (controller.signal.aborted) throw interruptedError(runId);
357
+ throw error;
358
+ } finally {
359
+ process.removeListener("SIGINT", onInterrupt);
360
+ }
361
+ }
362
+ async function inspectAnalysisRun(host, runId) {
363
+ return asDescriptor(await requestCapabilityGateway(
364
+ host,
365
+ resolveGatewayDomain("analysis"),
366
+ `runs/${encodeURIComponent(runId)}`
367
+ ));
368
+ }
369
+ function ensureCompletedDescriptor(descriptor, runId, artifactId) {
370
+ const actualArtifactId = descriptorArtifactId(descriptor);
371
+ if (actualArtifactId && actualArtifactId !== artifactId) {
372
+ throw new CapabilityGatewayError(
373
+ `artifact_id ${artifactId} does not belong to run_id ${runId}`,
374
+ "ARTIFACT_RUN_MISMATCH",
375
+ 400,
376
+ "Use the run_id and artifact_id pair from the same export response."
377
+ );
378
+ }
379
+ const runStatus = descriptorRunStatus(descriptor);
380
+ const artifactStatus = normalizedStatus(descriptor.artifact_status ?? descriptor.artifact?.status);
381
+ if (runStatus === "SUCCEEDED" && artifactStatus === "COMPLETED") return;
382
+ if (runStatus === "FAILED" || runStatus === "CANCELED" || artifactStatus === "FAILED" || artifactStatus === "CANCELED") {
383
+ throw terminalError(descriptor, runId, "Artifact cannot be downloaded because the remote lifecycle failed.");
384
+ }
385
+ throw new CapabilityGatewayError(
386
+ `Artifact is not ready: run_status=${runStatus || "UNKNOWN"}, artifact_status=${artifactStatus || "UNKNOWN"}`,
387
+ "ARTIFACT_NOT_READY",
388
+ 409,
389
+ `Resume with: ae-cli analysis run wait --run-id ${runId}`,
390
+ { run_id: runId, artifact_id: artifactId }
391
+ );
392
+ }
393
+ function descriptorArtifactId(descriptor) {
394
+ return nonEmptyString(descriptor.artifact_id) ?? nonEmptyString(descriptor.artifact?.artifact_id) ?? nonEmptyString(descriptor.artifact?.id);
395
+ }
396
+ function descriptorRunStatus(descriptor) {
397
+ return normalizedStatus(descriptor.status ?? descriptor.run_status);
398
+ }
399
+ function deriveDeadline(descriptor, fallbackFrom) {
400
+ const declaredDeadline = timestampMillis(descriptor?.deadline_at);
401
+ if (declaredDeadline !== void 0) return declaredDeadline + MATERIALIZATION_GRACE_MS;
402
+ const expiresAt = timestampMillis(descriptor?.expires_at);
403
+ if (expiresAt !== void 0) return expiresAt;
404
+ const effectiveTimeout = Number(descriptor?.effective_timeout_seconds);
405
+ if (Number.isFinite(effectiveTimeout) && effectiveTimeout > 0) {
406
+ return fallbackFrom + effectiveTimeout * 1e3 + MATERIALIZATION_GRACE_MS;
407
+ }
408
+ return fallbackFrom + DEFAULT_EFFECTIVE_TIMEOUT_MS + MATERIALIZATION_GRACE_MS;
409
+ }
410
+ function timestampMillis(value) {
411
+ if (typeof value === "number" && Number.isFinite(value)) {
412
+ return value < 1e10 ? value * 1e3 : value;
413
+ }
414
+ if (typeof value !== "string" || value.trim() === "") return void 0;
415
+ const numeric = Number(value);
416
+ if (Number.isFinite(numeric)) return timestampMillis(numeric);
417
+ const parsed = Date.parse(value);
418
+ return Number.isFinite(parsed) ? parsed : void 0;
419
+ }
420
+ function nextDelay(current) {
421
+ return Math.min(5e3, Math.ceil(current * 1.5));
422
+ }
423
+ function normalizedStatus(value) {
424
+ return typeof value === "string" && value.trim() ? value.trim().toUpperCase() : void 0;
425
+ }
426
+ function asDescriptor(value) {
427
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
428
+ throw protocolError("Async run response is not an object.");
429
+ }
430
+ return value;
431
+ }
432
+ function nonEmptyString(value) {
433
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
434
+ }
435
+ function optionalString(ctx, name) {
436
+ return nonEmptyString(ctx.str(name));
437
+ }
438
+ function terminalError(descriptor, runId, message) {
439
+ return new CapabilityGatewayError(
440
+ message,
441
+ "ASYNC_RUN_TERMINAL_FAILURE",
442
+ 409,
443
+ `The remote lifecycle is terminal and will not succeed on retry. Inspect details with: ae-cli analysis run inspect --run-id ${runId}`,
444
+ {
445
+ run_id: runId,
446
+ artifact_id: descriptorArtifactId(descriptor),
447
+ run_status: descriptorRunStatus(descriptor),
448
+ artifact_status: normalizedStatus(descriptor.artifact_status ?? descriptor.artifact?.status),
449
+ error: descriptor.error ?? descriptor.artifact?.error ?? descriptor.error_message ?? descriptor.artifact?.error_message
450
+ }
451
+ );
452
+ }
453
+ function protocolError(message, runId) {
454
+ return new CapabilityGatewayError(
455
+ message,
456
+ "ASYNC_RUN_PROTOCOL_ERROR",
457
+ 502,
458
+ runId ? resumeHint(runId) : "Inspect the gateway response and verify the async run contract.",
459
+ runId ? { run_id: runId } : void 0
460
+ );
461
+ }
462
+ function waitError(message, code, runId, cause, descriptor, extraMeta = {}) {
463
+ const resumeCommand = `ae-cli analysis run wait --run-id ${runId}`;
464
+ const error = new CapabilityGatewayError(
465
+ message,
466
+ code,
467
+ void 0,
468
+ resumeHint(runId),
469
+ {
470
+ run_id: runId,
471
+ artifact_id: descriptor ? descriptorArtifactId(descriptor) : void 0,
472
+ run_status: descriptor ? descriptorRunStatus(descriptor) : void 0,
473
+ artifact_status: descriptor ? normalizedStatus(descriptor.artifact_status ?? descriptor.artifact?.status) : void 0,
474
+ remote_run_canceled: false,
475
+ resume_command: resumeCommand,
476
+ ...extraMeta
477
+ }
478
+ );
479
+ if (cause !== void 0) error.cause = cause;
480
+ return error;
481
+ }
482
+ function interruptedError(runId) {
483
+ return waitError(
484
+ `Stopped waiting for run ${runId}. The remote run was not canceled.`,
485
+ "ASYNC_WAIT_INTERRUPTED",
486
+ runId
487
+ );
488
+ }
489
+ function resumeHint(runId) {
490
+ return `Resume with: ae-cli analysis run wait --run-id ${runId}`;
491
+ }
492
+ function announceSubmitted(runId, artifactId) {
493
+ process.stderr.write(
494
+ `[ae-cli] async run submitted run_id=${runId} artifact_id=${artifactId}; ${resumeHint(runId)}
495
+ `
496
+ );
497
+ }
498
+ function isTransientPollError(error) {
499
+ if (error instanceof CapabilityGatewayError) {
500
+ return error.httpStatus === 429 || error.httpStatus !== void 0 && error.httpStatus >= 500;
501
+ }
502
+ return error instanceof TypeError || error instanceof Error && /fetch|network|socket|timeout/i.test(error.message);
503
+ }
504
+ function throwIfAborted(signal, runId) {
505
+ if (signal?.aborted) throw interruptedError(runId);
506
+ }
507
+ async function abortableSleep(milliseconds, signal) {
508
+ if (milliseconds <= 0) return;
509
+ await new Promise((resolveSleep, reject) => {
510
+ let timer;
511
+ const finish = () => {
512
+ signal?.removeEventListener("abort", onAbort);
513
+ resolveSleep();
514
+ };
515
+ const onAbort = () => {
516
+ if (timer !== void 0) clearTimeout(timer);
517
+ signal?.removeEventListener("abort", onAbort);
518
+ reject(new DOMException("The operation was aborted", "AbortError"));
519
+ };
520
+ if (signal?.aborted) return onAbort();
521
+ signal?.addEventListener("abort", onAbort, { once: true });
522
+ timer = setTimeout(finish, milliseconds);
523
+ });
524
+ }
525
+ async function pathExists(path) {
526
+ try {
527
+ await access(path);
528
+ return true;
529
+ } catch (error) {
530
+ if (error?.code === "ENOENT") return false;
531
+ throw error;
532
+ }
533
+ }
534
+ function artifactPath(runId, artifactId) {
535
+ return `runs/${encodeURIComponent(runId)}/artifacts/${encodeURIComponent(artifactId)}/download`;
536
+ }
537
+ function fetchArtifact(host, runId, artifactId) {
538
+ return fetchCapabilityGateway(
539
+ host,
540
+ resolveGatewayDomain("analysis"),
541
+ artifactPath(runId, artifactId),
542
+ "GET",
543
+ void 0,
544
+ "application/octet-stream"
545
+ );
546
+ }
547
+
548
+ export {
549
+ withAsyncArtifactLifecycle,
550
+ waitForAnalysisRun,
551
+ downloadAnalysisArtifact,
552
+ validateLifecycleFlags,
553
+ clientWaitTimeoutSeconds,
554
+ assertOutputPathAvailable,
555
+ withInterruptSignal
556
+ };
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  peekCliToken
3
- } from "./chunk-Z3OXWCIA.js";
3
+ } from "./chunk-S5NTSDBS.js";
4
4
  import {
5
5
  getToken
6
- } from "./chunk-YV52FB5G.js";
6
+ } from "./chunk-ZQKDZXDO.js";
7
7
  import {
8
8
  getActiveHost,
9
9
  getConfigDir,
10
10
  isAeSandboxRuntime,
11
11
  normalizeUrl
12
- } from "./chunk-GJJA4CQZ.js";
12
+ } from "./chunk-3FY3RJ26.js";
13
13
  import {
14
14
  logger
15
15
  } from "./chunk-JHENBQ5B.js";
@@ -905,6 +905,12 @@ function withOutputMetadata(data, meta) {
905
905
  function isOutputWithMetadata(value) {
906
906
  return Boolean(value?.[OUTPUT_METADATA]);
907
907
  }
908
+ function unwrapOutputData(value) {
909
+ return isOutputWithMetadata(value) ? value.data : value;
910
+ }
911
+ function readOutputMetadata(value) {
912
+ return isOutputWithMetadata(value) ? value.meta : void 0;
913
+ }
908
914
  function findArrayField(data) {
909
915
  if (Array.isArray(data)) return data;
910
916
  if (typeof data !== "object" || data === null) return null;
@@ -917,6 +923,20 @@ function findArrayField(data) {
917
923
  return null;
918
924
  }
919
925
  function formatTable(data) {
926
+ if (Array.isArray(data?.title) && data.title.length > 0 && Array.isArray(data?.rows)) {
927
+ const headers = data.title.map((value) => String(value));
928
+ const table2 = new Table({ head: headers, wordWrap: true });
929
+ for (const row of data.rows) {
930
+ const values = Array.isArray(row) ? row : [row];
931
+ table2.push(headers.map((_, index) => {
932
+ const value = values[index];
933
+ if (value === void 0 || value === null) return "";
934
+ if (typeof value === "object") return JSON.stringify(value);
935
+ return String(value);
936
+ }));
937
+ }
938
+ return table2.toString();
939
+ }
920
940
  const rows = findArrayField(data);
921
941
  if (!rows || rows.length === 0) {
922
942
  return JSON.stringify(data, null, 2);
@@ -1011,6 +1031,8 @@ export {
1011
1031
  formatCapabilityMissCompatHint,
1012
1032
  runHostCompatCheck,
1013
1033
  withOutputMetadata,
1034
+ unwrapOutputData,
1035
+ readOutputMetadata,
1014
1036
  printError,
1015
1037
  printOutput
1016
1038
  };
@@ -3,7 +3,7 @@ import {
3
3
  getConfigDir,
4
4
  normalizeUrl,
5
5
  safeJsonParse
6
- } from "./chunk-GJJA4CQZ.js";
6
+ } from "./chunk-3FY3RJ26.js";
7
7
  import {
8
8
  logger
9
9
  } from "./chunk-JHENBQ5B.js";
@@ -6,9 +6,9 @@ import {
6
6
  mintCliToken,
7
7
  peekCliToken,
8
8
  setCliTokenManual
9
- } from "./chunk-Z3OXWCIA.js";
10
- import "./chunk-YV52FB5G.js";
11
- import "./chunk-GJJA4CQZ.js";
9
+ } from "./chunk-S5NTSDBS.js";
10
+ import "./chunk-ZQKDZXDO.js";
11
+ import "./chunk-3FY3RJ26.js";
12
12
  import "./chunk-JHENBQ5B.js";
13
13
  export {
14
14
  _resetRenewMemoryForTest,
@@ -3,10 +3,10 @@ import {
3
3
  getToken,
4
4
  invalidateAccessTokenForRetry,
5
5
  resolveHost
6
- } from "./chunk-YV52FB5G.js";
6
+ } from "./chunk-ZQKDZXDO.js";
7
7
  import {
8
8
  safeJsonParse
9
- } from "./chunk-GJJA4CQZ.js";
9
+ } from "./chunk-3FY3RJ26.js";
10
10
  import {
11
11
  logger
12
12
  } from "./chunk-JHENBQ5B.js";
@@ -191,14 +191,13 @@ async function queryReportData(projectId, reportId, qp, eventModel, options = {}
191
191
  ...options
192
192
  }, hostUrl);
193
193
  }
194
-
195
194
  export {
195
+ httpDelete,
196
196
  httpGet,
197
197
  httpPost,
198
198
  httpRequest,
199
- httpDelete,
200
199
  httpUpload,
201
- wsQuery,
200
+ queryReportData,
202
201
  querySql,
203
- queryReportData
202
+ wsQuery
204
203
  };