@thinkingai/ae-cli 6.1.18 → 6.1.20

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 (127) hide show
  1. package/README.md +97 -38
  2. package/README.zh.md +101 -38
  3. package/dist/{auth-ROB2EDYV.js → auth-FUM37MHF.js} +241 -126
  4. package/dist/{capability-DKMYUTLC.js → capability-AXFQW5WM.js} +49 -35
  5. package/dist/{chunk-JHENBQ5B.js → chunk-4P355ZWB.js} +70 -1
  6. package/dist/chunk-6ZIQV5GW.js +26 -0
  7. package/dist/{chunk-TUKQZTMI.js → chunk-7K24F7T2.js} +2 -0
  8. package/dist/{chunk-OO6XR6LK.js → chunk-AMBFK2K3.js} +2 -0
  9. package/dist/chunk-ATSM5XAW.js +623 -0
  10. package/dist/{chunk-4XXOWOTA.js → chunk-BBEFP4SB.js} +31 -38
  11. package/dist/{chunk-BYYS3ANB.js → chunk-CZU3V3DQ.js} +5 -15
  12. package/dist/{chunk-VTWMIC5L.js → chunk-E2JKXMVO.js} +2 -0
  13. package/dist/chunk-ECBLHAZO.js +15 -0
  14. package/dist/{sync-HKIOZXQE.js → chunk-I4WQAEYB.js} +31 -540
  15. package/dist/{chunk-DWO43OIB.js → chunk-JQ3ENZZH.js} +2 -0
  16. package/dist/chunk-LNZBEQXW.js +25216 -0
  17. package/dist/{chunk-ZQ47LWTI.js → chunk-QJQZH5GQ.js} +49 -79
  18. package/dist/{chunk-QZ3AS4KK.js → chunk-RSG4ONOI.js} +9 -8
  19. package/dist/{chunk-4NN5IWVN.js → chunk-T6OSFQZD.js} +2 -0
  20. package/dist/{chunk-Y3LOALAV.js → chunk-TAL6CZH6.js} +8 -7
  21. package/dist/{chunk-3KWQYGYI.js → chunk-TKHSULJT.js} +2 -0
  22. package/dist/chunk-VXNMYUXU.js +202 -0
  23. package/dist/{chunk-3FY3RJ26.js → chunk-WZ6YVQSF.js} +15 -14
  24. package/dist/{chunk-6EIJSNBD.js → chunk-Y74WTIKJ.js} +2 -0
  25. package/dist/{community-report-client-C7WDGET3.js → community-report-client-XXWGSBSD.js} +3 -4
  26. package/dist/{config-BMYZX2UE.js → config-EXUGQN5T.js} +10 -10
  27. package/dist/{data-integration-QEKDWQDY.js → data-integration-4NZ53OMT.js} +920 -97
  28. package/dist/index.js +56 -81
  29. package/dist/{local-data-upload-client-4YYHSYD6.js → local-data-upload-client-KYOKVYZV.js} +3 -4
  30. package/dist/{memory-I2WXDTV2.js → memory-ATNKZNW5.js} +6 -7
  31. package/dist/{metadata-I4C2EWUN.js → metadata-VZVC7YMH.js} +10 -11
  32. package/dist/{model-HLHIEFMU.js → model-E4JMQ4V2.js} +8 -9
  33. package/dist/{personal-semantic-preference-LIPACBDX.js → personal-semantic-preference-7S2SQ3UV.js} +9 -10
  34. package/dist/{project-semantic-RT3R2VQD.js → project-semantic-2SZP2OPO.js} +13 -14
  35. package/dist/sync-YV3E66IF.js +520 -0
  36. package/dist/{te-agent-BR6VDBNX.js → te-agent-JB5T3PO7.js} +396 -92
  37. package/dist/{te-analysis-7VUNUYWZ.js → te-analysis-3YJAAT2D.js} +196 -43
  38. package/dist/{te-community-5DMNKJWY.js → te-community-UDBI672N.js} +12 -34
  39. package/dist/{te-dataops-6P5IKWNJ.js → te-dataops-ZLYOCXZ4.js} +480 -81
  40. package/dist/{te-engage-KZPR5R22.js → te-engage-4XG6OJML.js} +88 -16
  41. package/dist/{te-experiment-6BITX4RD.js → te-experiment-VXUWPINJ.js} +83 -12
  42. package/dist/te-kb-WYQWHFSC.js +1732 -0
  43. package/dist/{te-system-FXITO2JG.js → te-system-7G6F2LJA.js} +569 -35
  44. package/dist/{te-team-ADOC2ROP.js → te-team-E7FBBXMQ.js} +8 -7
  45. package/dist/{update-YCYCKJOO.js → update-D47BUG25.js} +8 -8
  46. package/package.json +22 -10
  47. package/skills/ae-agent/SKILL.md +30 -13
  48. package/skills/ae-agent/references/agent-distribution.md +94 -0
  49. package/skills/ae-agent/references/approval-request.md +4 -0
  50. package/skills/ae-agent/references/command_index.md +9 -2
  51. package/skills/ae-agent/references/create-automation.md +20 -2
  52. package/skills/ae-agent/references/get-agent-context.md +70 -0
  53. package/skills/ae-agent/references/list-automations.md +18 -3
  54. package/skills/ae-agent/references/list-mcp-credentials.md +1 -1
  55. package/skills/ae-agent/references/mcp-token.md +3 -3
  56. package/skills/ae-agent/references/set-mcp-credential.md +0 -1
  57. package/skills/ae-agent/references/update-automation.md +18 -0
  58. package/skills/ae-analysis/SKILL.md +11 -2
  59. package/skills/ae-analysis/references/adhoc_run.md +2 -0
  60. package/skills/ae-analysis/references/ai_models.md +23 -3
  61. package/skills/ae-analysis/references/analysis_gateway_assets.md +3 -3
  62. package/skills/ae-analysis/references/audience_models.md +18 -0
  63. package/skills/ae-analysis/references/command_index.md +9 -9
  64. package/skills/ae-analysis/references/cross_source_config.md +84 -0
  65. package/skills/ae-analysis/references/dashboard_update.md +1 -1
  66. package/skills/ae-analysis/references/project_timezone_update.md +13 -4
  67. package/skills/ae-analysis/references/property_create.md +2 -0
  68. package/skills/ae-analysis/references/super_metadata_batch_create.md +2 -0
  69. package/skills/ae-analysis/references/user_cluster_models.md +2 -0
  70. package/skills/ae-analysis/references/user_cluster_update.md +8 -4
  71. package/skills/ae-analysis/references/user_tag_create.md +30 -2
  72. package/skills/ae-analysis/references/user_tag_models.md +17 -3
  73. package/skills/ae-analysis/references/user_tag_update.md +14 -2
  74. package/skills/ae-data-integration/SKILL.md +3 -1
  75. package/skills/ae-data-integration/references/dimension-routing.md +36 -0
  76. package/skills/ae-data-integration/references/error-handling.md +54 -1
  77. package/skills/ae-data-integration/references/local-analysis.md +2 -0
  78. package/skills/ae-data-integration/references/source-inspect.md +18 -2
  79. package/skills/ae-data-integration/references/tracking-plan.md +1 -1
  80. package/skills/ae-data-integration/references/transform.md +4 -2
  81. package/skills/ae-data-integration/references/ue-mapping.md +5 -2
  82. package/skills/ae-data-integration/references/ue-routing.md +40 -1
  83. package/skills/ae-dataops/SKILL.md +11 -1
  84. package/skills/ae-dataops/references/dataops-backfill.md +135 -0
  85. package/skills/ae-engage/SKILL.md +5 -0
  86. package/skills/ae-engage/references/build-task-save-guide.md +5 -1
  87. package/skills/ae-engage/references/save-flow.md +37 -1
  88. package/skills/ae-engage/references/save-task.md +6 -0
  89. package/skills/ae-experiment/SKILL.md +6 -2
  90. package/skills/ae-experiment/references/save_metric.md +20 -8
  91. package/skills/ae-generate-tracking-plan/SKILL.md +25 -13
  92. package/skills/ae-generate-tracking-plan/references/business-dimension-mapping.md +1 -1
  93. package/skills/ae-kb/SKILL.md +218 -36
  94. package/skills/ae-kb/references/query-workflow.md +59 -29
  95. package/skills/ae-kb/references/versions.md +46 -0
  96. package/skills/ae-system/SKILL.md +29 -31
  97. package/skills/ae-system/references/channel-management.md +303 -0
  98. package/skills/ae-use-agent/SKILL.md +42 -0
  99. package/skills/ae-use-agent/references/local-agent.md +114 -0
  100. package/dist/auth-GBMV6TEJ.js +0 -14
  101. package/dist/capability-HYVVPG25.js +0 -352
  102. package/dist/chunk-EFH4XWYC.js +0 -556
  103. package/dist/chunk-J2DEBMRF.js +0 -313
  104. package/dist/chunk-JRJY5DMJ.js +0 -71
  105. package/dist/chunk-OMPRXM3V.js +0 -349
  106. package/dist/chunk-QNOLN2LJ.js +0 -509
  107. package/dist/chunk-RJDU7NYP.js +0 -1198
  108. package/dist/chunk-RNAALWJK.js +0 -98
  109. package/dist/chunk-SERWF6G5.js +0 -13
  110. package/dist/chunk-UW5UN47B.js +0 -70
  111. package/dist/chunk-ZQKDZXDO.js +0 -317
  112. package/dist/client-L2YDMHQ6.js +0 -203
  113. package/dist/memory-3ORCR7JH.js +0 -893
  114. package/dist/metadata-VUOQJE26.js +0 -339
  115. package/dist/model-UGRDX4MW.js +0 -139
  116. package/dist/personal-semantic-preference-OEISBRHM.js +0 -239
  117. package/dist/project-semantic-FFPWFPIW.js +0 -1114
  118. package/dist/sync-TFHU2UTG.js +0 -10261
  119. package/dist/te-agent-VLYOV7S4.js +0 -3894
  120. package/dist/te-analysis-4YGQL5RC.js +0 -9357
  121. package/dist/te-community-ISDQWJU7.js +0 -1859
  122. package/dist/te-dataops-CVULXNVB.js +0 -2209
  123. package/dist/te-engage-N5WI32H6.js +0 -4898
  124. package/dist/te-experiment-UVR4HLND.js +0 -988
  125. package/dist/te-kb-RCLSSH2Q.js +0 -935
  126. package/dist/te-system-K2GYMCTB.js +0 -2213
  127. package/skills/ae-agent/references/auto-provision-mcp-credentials.md +0 -57
@@ -1,313 +0,0 @@
1
- import {
2
- SecureStoreAuthError,
3
- getToken,
4
- load,
5
- loadCliToken,
6
- save
7
- } from "./chunk-ZQKDZXDO.js";
8
- import {
9
- getActiveHost,
10
- getConfigDir,
11
- getFallbackCliToken,
12
- listHosts,
13
- normalizeUrl,
14
- safeJsonParse,
15
- safeReadJsonFile
16
- } from "./chunk-3FY3RJ26.js";
17
- import {
18
- PermissionError
19
- } from "./chunk-UW5UN47B.js";
20
- import {
21
- logger
22
- } from "./chunk-JHENBQ5B.js";
23
-
24
- // src/core/cli-token.ts
25
- import fs from "fs";
26
- import path from "path";
27
- var CLI_TOKEN_GENERATE_PATH = "/v1/ta/cli/token/generate";
28
- var CLI_TOKEN_RENEW_PATH = "/v1/ta/cli/token/renew";
29
- var CLI_TOKEN_VALIDATE_PATH = "/v1/ta/cli/token/validate";
30
- var _cliTokenCache = /* @__PURE__ */ new Map();
31
- var _renewedLocalDateByHost = /* @__PURE__ */ new Map();
32
- var _renewInFlightByHost = /* @__PURE__ */ new Map();
33
- function renewHostKey(hostUrl) {
34
- return normalizeUrl(hostUrl);
35
- }
36
- function renewStateFilePath() {
37
- return path.join(getConfigDir(), "cli-token-renew.json");
38
- }
39
- function localRenewDate(now = /* @__PURE__ */ new Date()) {
40
- const y = now.getFullYear();
41
- const m = String(now.getMonth() + 1).padStart(2, "0");
42
- const d = String(now.getDate()).padStart(2, "0");
43
- return `${y}-${m}-${d}`;
44
- }
45
- function loadRenewStore() {
46
- try {
47
- const file = renewStateFilePath();
48
- if (!fs.existsSync(file)) return {};
49
- const data = safeReadJsonFile(file);
50
- if (!data || typeof data !== "object" || Array.isArray(data)) return {};
51
- return data;
52
- } catch {
53
- return {};
54
- }
55
- }
56
- function saveRenewStore(store) {
57
- const dir = getConfigDir();
58
- if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
59
- const file = renewStateFilePath();
60
- if (Object.keys(store).length === 0) {
61
- try {
62
- fs.unlinkSync(file);
63
- } catch {
64
- }
65
- return;
66
- }
67
- fs.writeFileSync(file, JSON.stringify(store, null, 2), { encoding: "utf8" });
68
- try {
69
- fs.chmodSync(file, 384);
70
- } catch {
71
- }
72
- }
73
- function getPersistedRenewDate(hostUrl) {
74
- const key = renewHostKey(hostUrl);
75
- const store = loadRenewStore();
76
- return store[key]?.date ?? (key !== hostUrl ? store[hostUrl]?.date : void 0) ?? null;
77
- }
78
- function markRenewSucceeded(hostUrl, date) {
79
- const key = renewHostKey(hostUrl);
80
- _renewedLocalDateByHost.set(key, date);
81
- const store = loadRenewStore();
82
- if (key !== hostUrl && store[hostUrl]) {
83
- delete store[hostUrl];
84
- }
85
- store[key] = { date };
86
- saveRenewStore(store);
87
- }
88
- function clearRenewState(hostUrl) {
89
- if (hostUrl) {
90
- const key = renewHostKey(hostUrl);
91
- _renewedLocalDateByHost.delete(key);
92
- _renewInFlightByHost.delete(key);
93
- if (key !== hostUrl) {
94
- _renewedLocalDateByHost.delete(hostUrl);
95
- _renewInFlightByHost.delete(hostUrl);
96
- }
97
- const store = loadRenewStore();
98
- let changed = false;
99
- for (const k of /* @__PURE__ */ new Set([key, hostUrl])) {
100
- if (store[k]) {
101
- delete store[k];
102
- changed = true;
103
- }
104
- }
105
- if (changed) {
106
- saveRenewStore(store);
107
- }
108
- return;
109
- }
110
- _renewedLocalDateByHost.clear();
111
- _renewInFlightByHost.clear();
112
- saveRenewStore({});
113
- }
114
- async function generateCliToken(hostUrl, accessTokenOverride) {
115
- const accessToken = accessTokenOverride ?? await getToken(hostUrl);
116
- const base = hostUrl.replace(/\/+$/, "");
117
- const url = `${base}${CLI_TOKEN_GENERATE_PATH}`;
118
- const resp = await fetch(url, {
119
- method: "GET",
120
- headers: {
121
- "Authorization": `bearer ${accessToken}`
122
- }
123
- });
124
- if (!resp.ok) {
125
- if (resp.status === 403) {
126
- const text = await resp.text();
127
- let body = {};
128
- try {
129
- body = text ? safeJsonParse(text) : {};
130
- } catch {
131
- }
132
- const message = body.message ?? body.return_message ?? "CLI access is disabled for this account.";
133
- const code = body.code ?? (String(message).includes("CLI_ACCESS_DISABLED") ? "CLI_ACCESS_DISABLED" : void 0);
134
- throw new PermissionError(message, code, body.hint);
135
- }
136
- throw new Error(`CLI token generate HTTP error: ${resp.status} ${resp.statusText}`);
137
- }
138
- const data = safeJsonParse(await resp.text());
139
- if (data.return_code !== 0) {
140
- const message = data.return_message || data.message || "unknown";
141
- if (data.code === "CLI_ACCESS_DISABLED" || String(message).includes("CLI_ACCESS_DISABLED")) {
142
- throw new PermissionError(message, "CLI_ACCESS_DISABLED", data.hint);
143
- }
144
- throw new Error(`CLI token generate error: ${message} (code: ${data.return_code})`);
145
- }
146
- const cliToken = data.data?.userSecret;
147
- if (!cliToken) {
148
- throw new Error("CLI token generate error: empty userSecret in response");
149
- }
150
- return cliToken;
151
- }
152
- async function validateCliTokenOnServer(hostUrl, cliToken) {
153
- const base = hostUrl.replace(/\/+$/, "");
154
- const url = `${base}${CLI_TOKEN_VALIDATE_PATH}`;
155
- let resp;
156
- try {
157
- resp = await fetch(url, {
158
- method: "GET",
159
- headers: {
160
- Accept: "application/json",
161
- "cli-token": cliToken
162
- }
163
- });
164
- } catch (e) {
165
- throw new SecureStoreAuthError(`Unable to validate CLI token for ${hostUrl}: ${e.message}`);
166
- }
167
- const responseText = await resp.text();
168
- let data;
169
- try {
170
- data = safeJsonParse(responseText);
171
- } catch {
172
- data = void 0;
173
- }
174
- if (resp.status === 401 || resp.status === 403 || data?.return_code !== void 0 && data.return_code !== 0) {
175
- throw new SecureStoreAuthError(
176
- `CLI token is invalid or expired for ${hostUrl}. Run: ae-cli auth logout --host ${hostUrl}, then ae-cli auth login --host ${hostUrl}`
177
- );
178
- }
179
- if (!resp.ok) {
180
- throw new SecureStoreAuthError(
181
- `CLI token validation failed for ${hostUrl} (HTTP ${resp.status} ${resp.statusText})`
182
- );
183
- }
184
- if (data?.return_code !== 0) {
185
- throw new SecureStoreAuthError(`CLI token validation returned an invalid response for ${hostUrl}`);
186
- }
187
- }
188
- async function renewCliTokenOnServer(hostUrl, cliToken) {
189
- const base = hostUrl.replace(/\/+$/, "");
190
- const url = new URL(`${base}${CLI_TOKEN_RENEW_PATH}`);
191
- url.searchParams.set("cli-token", cliToken);
192
- const headers = {
193
- Accept: "application/json"
194
- };
195
- try {
196
- const accessToken = await getToken(hostUrl);
197
- if (accessToken) {
198
- headers.Authorization = `bearer ${accessToken}`;
199
- }
200
- } catch {
201
- }
202
- const resp = await fetch(url.toString(), { method: "GET", headers });
203
- const text = await resp.text();
204
- const data = safeJsonParse(text);
205
- if (!resp.ok) {
206
- throw new Error(`CLI token renew HTTP error: ${resp.status} ${resp.statusText}`);
207
- }
208
- if (data?.return_code !== void 0 && data.return_code !== 0) {
209
- throw new Error(`CLI token renew error: ${data.return_message || "unknown"} (code: ${data.return_code})`);
210
- }
211
- }
212
- async function maybeRenewCliTokenDaily(hostUrl, cliToken) {
213
- const hostKey = renewHostKey(hostUrl);
214
- const today = localRenewDate();
215
- if (_renewedLocalDateByHost.get(hostKey) === today) {
216
- return;
217
- }
218
- if (getPersistedRenewDate(hostUrl) === today) {
219
- _renewedLocalDateByHost.set(hostKey, today);
220
- return;
221
- }
222
- const existing = _renewInFlightByHost.get(hostKey);
223
- if (existing) {
224
- await existing;
225
- return;
226
- }
227
- const attempt = (async () => {
228
- try {
229
- await renewCliTokenOnServer(hostUrl, cliToken);
230
- markRenewSucceeded(hostUrl, today);
231
- logger.info(`cli-token: renewed for ${hostKey} (local day ${today})`);
232
- } catch (e) {
233
- logger.warn(`cli-token: renew failed for ${hostKey}: ${e?.message || e}; business call proceeds with cached token`);
234
- } finally {
235
- _renewInFlightByHost.delete(hostKey);
236
- }
237
- })();
238
- _renewInFlightByHost.set(hostKey, attempt);
239
- await attempt;
240
- }
241
- function persistCliTokenIfPossible(hostUrl, cliToken) {
242
- const existing = load(hostUrl);
243
- if (!existing) {
244
- logger.info(`cli-token: no secure-store session for ${hostUrl}, keeping token in-process only`);
245
- return;
246
- }
247
- save(hostUrl, { ...existing, cliToken });
248
- }
249
- function clearPersistedCliToken(hostUrl) {
250
- const existing = load(hostUrl);
251
- if (existing?.cliToken) {
252
- save(hostUrl, { ...existing, cliToken: void 0 });
253
- }
254
- }
255
- function peekCliToken(hostOverride) {
256
- const hostUrl = hostOverride || getActiveHost();
257
- if (!hostUrl) return void 0;
258
- return _cliTokenCache.get(hostUrl) || loadCliToken(hostUrl) || getFallbackCliToken(hostUrl) || void 0;
259
- }
260
- async function getCliToken(hostOverride) {
261
- const hostUrl = hostOverride || getActiveHost();
262
- let token = _cliTokenCache.get(hostUrl);
263
- if (!token) {
264
- const storedToken = loadCliToken(hostUrl);
265
- if (storedToken) {
266
- _cliTokenCache.set(hostUrl, storedToken);
267
- logger.info(`Using persisted CLI token (secure-store) for ${hostUrl}`);
268
- token = storedToken;
269
- }
270
- }
271
- if (!token) {
272
- const fallbackToken = getFallbackCliToken(hostUrl);
273
- if (fallbackToken) {
274
- _cliTokenCache.set(hostUrl, fallbackToken);
275
- logger.info(`Using sandbox-provisioned CLI token (fallback file) for ${hostUrl}`);
276
- token = fallbackToken;
277
- }
278
- }
279
- if (!token) {
280
- token = await mintCliToken(hostUrl);
281
- }
282
- await maybeRenewCliTokenDaily(hostUrl, token);
283
- return token;
284
- }
285
- async function mintCliToken(hostUrl, accessTokenOverride, persist = true) {
286
- logger.info(`Generating CLI token for ${hostUrl}`);
287
- const cliToken = await generateCliToken(hostUrl, accessTokenOverride);
288
- _cliTokenCache.set(hostUrl, cliToken);
289
- if (persist) persistCliTokenIfPossible(hostUrl, cliToken);
290
- logger.info(`CLI token generated and cached${persist ? " and persisted" : ""} for ${hostUrl}`);
291
- return cliToken;
292
- }
293
- function clearCliToken(hostUrl) {
294
- if (hostUrl) {
295
- _cliTokenCache.delete(hostUrl);
296
- clearPersistedCliToken(hostUrl);
297
- clearRenewState(hostUrl);
298
- return;
299
- }
300
- _cliTokenCache.clear();
301
- clearRenewState();
302
- for (const { url } of listHosts()) {
303
- clearPersistedCliToken(url);
304
- }
305
- }
306
-
307
- export {
308
- validateCliTokenOnServer,
309
- peekCliToken,
310
- getCliToken,
311
- mintCliToken,
312
- clearCliToken
313
- };
@@ -1,71 +0,0 @@
1
- import {
2
- resolveGatewayDomain
3
- } from "./chunk-3KWQYGYI.js";
4
- import {
5
- withOutputMetadata
6
- } from "./chunk-BYYS3ANB.js";
7
- import {
8
- dryRunCapability,
9
- executeCapabilityWithEnvelope,
10
- validateCapability
11
- } from "./chunk-OMPRXM3V.js";
12
-
13
- // src/core/capability-command.ts
14
- import { randomBytes } from "crypto";
15
- function createCapabilityCommand(config) {
16
- return {
17
- service: config.cliService,
18
- resource: config.resource,
19
- command: config.command,
20
- capabilityId: config.capabilityId,
21
- description: config.description,
22
- flags: config.flags,
23
- risk: config.risk,
24
- validate: config.validate,
25
- preflight: (ctx) => {
26
- config.buildInput(ctx);
27
- },
28
- validateInput: async (ctx) => {
29
- const gatewayDomain = resolveGatewayDomain(config.cliService, config.gatewayDomain);
30
- const requestHost = config.requestHost ?? ctx.host();
31
- const input = withLifecycleRequestId(config, config.buildInput(ctx));
32
- return validateCapability(requestHost, gatewayDomain, config.capabilityId, input);
33
- },
34
- dryRun: async (ctx) => {
35
- const gatewayDomain = resolveGatewayDomain(config.cliService, config.gatewayDomain);
36
- const requestHost = config.requestHost ?? ctx.host();
37
- const input = withLifecycleRequestId(config, config.buildInput(ctx));
38
- return dryRunCapability(requestHost, gatewayDomain, config.capabilityId, input);
39
- },
40
- execute: async (ctx) => {
41
- const gatewayDomain = resolveGatewayDomain(config.cliService, config.gatewayDomain);
42
- const requestHost = config.requestHost ?? ctx.host();
43
- const input = withLifecycleRequestId(config, config.buildInput(ctx));
44
- announceDispatch(config.capabilityId, input);
45
- const result = await executeCapabilityWithEnvelope(requestHost, gatewayDomain, config.capabilityId, input);
46
- const data = config.postProcess ? await config.postProcess(result.data, input, ctx) : result.data;
47
- return withOutputMetadata(data, result.meta);
48
- }
49
- };
50
- }
51
- function withLifecycleRequestId(config, input) {
52
- if (!config.flags.some((flag) => flag.name === "request-id")) {
53
- return input;
54
- }
55
- const supplied = input.request_id;
56
- const requestId = typeof supplied === "string" && supplied.length > 0 ? supplied : `cli_${randomBytes(16).toString("hex")}`;
57
- return { ...input, request_id: requestId };
58
- }
59
- function announceDispatch(capabilityId, input) {
60
- if (typeof input.request_id !== "string") {
61
- return;
62
- }
63
- process.stderr.write(
64
- `[ae-cli] dispatching capability=${capabilityId} request_id=${input.request_id}
65
- `
66
- );
67
- }
68
-
69
- export {
70
- createCapabilityCommand
71
- };