@thinkingai/ae-cli 6.0.47 → 6.0.48

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 (80) hide show
  1. package/README.md +93 -36
  2. package/README.zh.md +93 -36
  3. package/dist/{auth-QPEVVBKT.js → auth-FUM37MHF.js} +236 -127
  4. package/dist/{capability-RUSV77CO.js → capability-J4FU4JZW.js} +47 -34
  5. package/dist/{chunk-FR2EDAQM.js → chunk-4P355ZWB.js} +69 -1
  6. package/dist/{chunk-NSIVXKJH.js → chunk-6KBBAPPP.js} +5 -5
  7. package/dist/chunk-6ZIQV5GW.js +26 -0
  8. package/dist/chunk-ATSM5XAW.js +623 -0
  9. package/dist/{chunk-6QK7SYYY.js → chunk-BBEFP4SB.js} +29 -37
  10. package/dist/{chunk-KEWVSO64.js → chunk-CZU3V3DQ.js} +4 -15
  11. package/dist/chunk-ECBLHAZO.js +15 -0
  12. package/dist/{chunk-BVDST5YT.js → chunk-HPLNYQPM.js} +8 -8
  13. package/dist/{chunk-B5HMQAOM.js → chunk-I4WQAEYB.js} +1 -1
  14. package/dist/{chunk-QL6R6TSK.js → chunk-LNZBEQXW.js} +6 -5
  15. package/dist/{chunk-GJXRF7Y6.js → chunk-QJQZH5GQ.js} +47 -78
  16. package/dist/{chunk-JYMGHGCE.js → chunk-VXNMYUXU.js} +24 -13
  17. package/dist/{chunk-KZ6ZHF5J.js → chunk-WZ6YVQSF.js} +14 -14
  18. package/dist/{community-report-client-6OL6GBQW.js → community-report-client-XXWGSBSD.js} +2 -4
  19. package/dist/{config-XNMACCKX.js → config-EXUGQN5T.js} +8 -9
  20. package/dist/{data-integration-4NZGZ45E.js → data-integration-4NZ53OMT.js} +17 -15
  21. package/dist/index.js +52 -79
  22. package/dist/{local-data-upload-client-EFHDLXFG.js → local-data-upload-client-KYOKVYZV.js} +2 -4
  23. package/dist/{memory-HBJQ2GC5.js → memory-ATNKZNW5.js} +4 -6
  24. package/dist/{metadata-PGDJE5RQ.js → metadata-3J5ZAVMF.js} +7 -9
  25. package/dist/{model-BHLJ2QMT.js → model-E4JMQ4V2.js} +4 -6
  26. package/dist/{personal-semantic-preference-E5NZ56DN.js → personal-semantic-preference-32AAJ37M.js} +6 -8
  27. package/dist/{sync-MUWPRM5I.js → sync-2GTAKZYX.js} +9 -11
  28. package/dist/{te-agent-WQZTMEK4.js → te-agent-JB5T3PO7.js} +393 -90
  29. package/dist/{te-analysis-YWCSSLYL.js → te-analysis-WHYXHRJD.js} +97 -31
  30. package/dist/{te-community-BNE6KREL.js → te-community-UDBI672N.js} +9 -32
  31. package/dist/{te-dataops-TXLKM2W6.js → te-dataops-ZLYOCXZ4.js} +19 -20
  32. package/dist/{te-engage-VEW4CJHK.js → te-engage-DHKNJ5BO.js} +11 -13
  33. package/dist/{te-kb-BUD6N3NI.js → te-kb-WYQWHFSC.js} +595 -85
  34. package/dist/{te-system-44LZJDTQ.js → te-system-7G6F2LJA.js} +6 -8
  35. package/dist/{te-team-XMP47YXE.js → te-team-E7FBBXMQ.js} +6 -8
  36. package/dist/{update-UODFOZ4P.js → update-D47BUG25.js} +7 -8
  37. package/package.json +12 -9
  38. package/skills/ae-agent/SKILL.md +30 -13
  39. package/skills/ae-agent/references/agent-distribution.md +94 -0
  40. package/skills/ae-agent/references/approval-request.md +4 -0
  41. package/skills/ae-agent/references/command_index.md +9 -2
  42. package/skills/ae-agent/references/create-automation.md +20 -2
  43. package/skills/ae-agent/references/get-agent-context.md +70 -0
  44. package/skills/ae-agent/references/list-automations.md +18 -3
  45. package/skills/ae-agent/references/list-mcp-credentials.md +1 -1
  46. package/skills/ae-agent/references/mcp-token.md +3 -3
  47. package/skills/ae-agent/references/set-mcp-credential.md +0 -1
  48. package/skills/ae-agent/references/update-automation.md +18 -0
  49. package/skills/ae-analysis/SKILL.md +11 -2
  50. package/skills/ae-analysis/references/adhoc_run.md +2 -0
  51. package/skills/ae-analysis/references/ai_models.md +23 -3
  52. package/skills/ae-analysis/references/analysis_gateway_assets.md +2 -2
  53. package/skills/ae-analysis/references/command_index.md +7 -7
  54. package/skills/ae-analysis/references/cross_source_config.md +84 -0
  55. package/skills/ae-analysis/references/dashboard_update.md +1 -1
  56. package/skills/ae-analysis/references/user_tag_create.md +23 -1
  57. package/skills/ae-analysis/references/user_tag_models.md +9 -1
  58. package/skills/ae-analysis/references/user_tag_update.md +14 -2
  59. package/skills/ae-data-integration/SKILL.md +2 -1
  60. package/skills/ae-data-integration/references/dimension-routing.md +36 -0
  61. package/skills/ae-data-integration/references/local-analysis.md +2 -0
  62. package/skills/ae-data-integration/references/source-inspect.md +1 -1
  63. package/skills/ae-data-integration/references/tracking-plan.md +1 -1
  64. package/skills/ae-data-integration/references/transform.md +1 -1
  65. package/skills/ae-data-integration/references/ue-mapping.md +5 -2
  66. package/skills/ae-data-integration/references/ue-routing.md +17 -1
  67. package/skills/ae-generate-tracking-plan/SKILL.md +25 -13
  68. package/skills/ae-generate-tracking-plan/references/business-dimension-mapping.md +1 -1
  69. package/skills/ae-kb/SKILL.md +107 -36
  70. package/skills/ae-kb/references/query-workflow.md +59 -29
  71. package/skills/ae-kb/references/versions.md +46 -0
  72. package/skills/ae-system/SKILL.md +1 -1
  73. package/skills/ae-use-agent/SKILL.md +42 -0
  74. package/skills/ae-use-agent/references/local-agent.md +114 -0
  75. package/dist/auth-UMJAA72O.js +0 -15
  76. package/dist/chunk-533JK3YX.js +0 -72
  77. package/dist/chunk-O6K2ODUE.js +0 -318
  78. package/dist/chunk-RWXIXOZG.js +0 -326
  79. package/dist/client-N7NGZUNI.js +0 -204
  80. package/skills/ae-agent/references/auto-provision-mcp-credentials.md +0 -57
@@ -3,16 +3,15 @@ import {
3
3
  internalCallSourceHeaders
4
4
  } from "./chunk-Y74WTIKJ.js";
5
5
  import {
6
- clearCliToken,
7
6
  getCliToken
8
- } from "./chunk-RWXIXOZG.js";
7
+ } from "./chunk-ATSM5XAW.js";
9
8
  import {
10
9
  getActiveHost,
11
10
  getSandboxRuntimeRoot
12
- } from "./chunk-KZ6ZHF5J.js";
11
+ } from "./chunk-WZ6YVQSF.js";
13
12
  import {
14
13
  PermissionError
15
- } from "./chunk-533JK3YX.js";
14
+ } from "./chunk-4P355ZWB.js";
16
15
 
17
16
  // src/core/te-agent-credentials.ts
18
17
  import { readFileSync } from "fs";
@@ -109,6 +108,17 @@ import { open, unlink } from "fs/promises";
109
108
  import path from "path";
110
109
  import { Readable } from "stream";
111
110
  import { pipeline } from "stream/promises";
111
+
112
+ // src/core/te-claude-base-url.ts
113
+ function resolveTeClaudeBaseUrl(host) {
114
+ const base = host.replace(/\/+$/, "");
115
+ const configured = (process.env.TE_CLAUDE_BASE_PATH ?? process.env.AE_API_PREFIX ?? "/agent").trim();
116
+ const path2 = configured.replace(/^\/+|\/+$/g, "");
117
+ const basePath = path2 ? `/${path2}` : "";
118
+ return basePath && !base.endsWith(basePath) ? `${base}${basePath}` : base;
119
+ }
120
+
121
+ // src/core/te-agent-client.ts
112
122
  var TeAgentApiError = class extends Error {
113
123
  constructor(message, status, code, body) {
114
124
  super(message);
@@ -170,9 +180,7 @@ function teClaudeBaseFromActiveHost(hostOverride) {
170
180
  if (override) return override.replace(/\/+$/, "");
171
181
  const h = hostOverride || getActiveHost();
172
182
  if (!h) return void 0;
173
- const base = h.replace(/\/+$/, "");
174
- const bp = process.env.TE_CLAUDE_BASE_PATH || "/agent";
175
- return base.endsWith(bp) ? base : base + bp;
183
+ return resolveTeClaudeBaseUrl(h);
176
184
  }
177
185
  async function signRequest(method, path2, hostOverride, includeJsonContentType = true) {
178
186
  const sandboxCred = tryLoadTeAgentSandboxCredentials();
@@ -211,34 +219,22 @@ async function signRequest(method, path2, hostOverride, includeJsonContentType =
211
219
  tokenHost: hostForToken
212
220
  };
213
221
  }
214
- async function fetchSignedWithRetry(options) {
215
- let signed = await signRequest(
222
+ async function fetchSigned(options) {
223
+ const signed = await signRequest(
216
224
  options.method,
217
225
  options.path,
218
226
  options.hostOverride,
219
227
  options.includeJsonContentType
220
228
  );
221
- const request = (requestToSend) => fetchWithTimeout(
222
- requestToSend.url,
229
+ return fetchWithTimeout(
230
+ signed.url,
223
231
  {
224
232
  method: options.method,
225
- headers: requestToSend.headers,
233
+ headers: signed.headers,
226
234
  body: options.body
227
235
  },
228
236
  options.timeoutMs
229
237
  );
230
- let response = await request(signed);
231
- if (response.status === 401 && signed.authKind === "cli-token" && signed.tokenHost) {
232
- clearCliToken(signed.tokenHost);
233
- signed = await signRequest(
234
- options.method,
235
- options.path,
236
- options.hostOverride,
237
- options.includeJsonContentType
238
- );
239
- response = await request(signed);
240
- }
241
- return response;
242
238
  }
243
239
  function errorDetails(parsed, defaultErrorPrefix, status) {
244
240
  const nested = parsed && typeof parsed === "object" && parsed.error && typeof parsed.error === "object" ? parsed.error : parsed;
@@ -276,7 +272,7 @@ async function parseResponse(response, defaultErrorPrefix) {
276
272
  }
277
273
  async function postToMainApp(path2, body, hostOverride) {
278
274
  const rawBody = JSON.stringify(body);
279
- const response = await fetchSignedWithRetry({
275
+ const response = await fetchSigned({
280
276
  method: "POST",
281
277
  path: path2,
282
278
  body: rawBody,
@@ -285,7 +281,7 @@ async function postToMainApp(path2, body, hostOverride) {
285
281
  return parseResponse(response, "Main app returned");
286
282
  }
287
283
  async function getFromMainApp(path2, hostOverride) {
288
- const response = await fetchSignedWithRetry({
284
+ const response = await fetchSigned({
289
285
  method: "GET",
290
286
  path: path2,
291
287
  hostOverride
@@ -319,7 +315,7 @@ async function postSandboxSyncPull(args) {
319
315
  });
320
316
  }
321
317
  async function deleteFromMainApp(path2, hostOverride) {
322
- const response = await fetchSignedWithRetry({
318
+ const response = await fetchSigned({
323
319
  method: "DELETE",
324
320
  path: path2,
325
321
  hostOverride
@@ -328,7 +324,7 @@ async function deleteFromMainApp(path2, hostOverride) {
328
324
  }
329
325
  async function patchToMainApp(path2, body, hostOverride) {
330
326
  const rawBody = JSON.stringify(body);
331
- const response = await fetchSignedWithRetry({
327
+ const response = await fetchSigned({
332
328
  method: "PATCH",
333
329
  path: path2,
334
330
  body: rawBody,
@@ -338,7 +334,7 @@ async function patchToMainApp(path2, body, hostOverride) {
338
334
  }
339
335
  async function putToMainApp(path2, body, hostOverride) {
340
336
  const rawBody = JSON.stringify(body);
341
- const response = await fetchSignedWithRetry({
337
+ const response = await fetchSigned({
342
338
  method: "PUT",
343
339
  path: path2,
344
340
  body: rawBody,
@@ -347,7 +343,7 @@ async function putToMainApp(path2, body, hostOverride) {
347
343
  return parseResponse(response, "Main app returned");
348
344
  }
349
345
  async function getBufferFromMainApp(path2, hostOverride) {
350
- const response = await fetchSignedWithRetry({
346
+ const response = await fetchSigned({
351
347
  method: "GET",
352
348
  path: path2,
353
349
  hostOverride
@@ -411,7 +407,7 @@ async function downloadFromMainApp(requestPath, outputPath, hostOverride) {
411
407
  "OUTPUT_ERROR"
412
408
  );
413
409
  }
414
- let signed = await signRequest("GET", requestPath, hostOverride);
410
+ const signed = await signRequest("GET", requestPath, hostOverride);
415
411
  let response;
416
412
  const request = async (requestToSend) => {
417
413
  try {
@@ -432,11 +428,6 @@ async function downloadFromMainApp(requestPath, outputPath, hostOverride) {
432
428
  }
433
429
  };
434
430
  response = await request(signed);
435
- if (response.status === 401 && signed.authKind === "cli-token" && signed.tokenHost) {
436
- clearCliToken(signed.tokenHost);
437
- signed = await signRequest("GET", requestPath, hostOverride);
438
- response = await request(signed);
439
- }
440
431
  if (!response.ok) {
441
432
  await parseResponse(response, "Main app returned");
442
433
  }
@@ -479,7 +470,7 @@ async function downloadFromMainApp(requestPath, outputPath, hostOverride) {
479
470
  }
480
471
  }
481
472
  async function uploadToMainApp(path2, formData, hostOverride) {
482
- const response = await fetchSignedWithRetry({
473
+ const response = await fetchSigned({
483
474
  method: "POST",
484
475
  path: path2,
485
476
  body: formData,
@@ -494,6 +485,7 @@ export {
494
485
  TeAgentCredentialsError,
495
486
  tryLoadTeAgentSandboxCredentials,
496
487
  getClaudeConfigDir,
488
+ resolveTeClaudeBaseUrl,
497
489
  TeAgentApiError,
498
490
  postToMainApp,
499
491
  getFromMainApp,
@@ -1,19 +1,16 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  peekCliToken
4
- } from "./chunk-RWXIXOZG.js";
5
- import {
6
- getToken
7
- } from "./chunk-O6K2ODUE.js";
4
+ } from "./chunk-ATSM5XAW.js";
8
5
  import {
9
6
  getActiveHost,
10
7
  getConfigDir,
11
8
  isAeSandboxRuntime,
12
9
  normalizeUrl
13
- } from "./chunk-KZ6ZHF5J.js";
10
+ } from "./chunk-WZ6YVQSF.js";
14
11
  import {
15
12
  logger
16
- } from "./chunk-FR2EDAQM.js";
13
+ } from "./chunk-4P355ZWB.js";
17
14
 
18
15
  // src/core/version-sync.ts
19
16
  import { spawnSync } from "child_process";
@@ -650,20 +647,12 @@ function shouldSkipAutoSync(argv = process.argv) {
650
647
  async function fetchCliConfig(host, cliToken) {
651
648
  const url = new URL(CLI_CONFIG_PATH, host.endsWith("/") ? host : `${host}/`);
652
649
  url.searchParams.set("cli-token", cliToken);
653
- const headers = { Accept: "application/json" };
654
- try {
655
- const accessToken = await getToken(host);
656
- if (accessToken) {
657
- headers.Authorization = `bearer ${accessToken}`;
658
- }
659
- } catch {
660
- }
661
650
  const controller = new AbortController();
662
651
  const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
663
652
  try {
664
653
  const resp = await fetch(url.toString(), {
665
654
  signal: controller.signal,
666
- headers
655
+ headers: { Accept: "application/json" }
667
656
  });
668
657
  if (!resp.ok) return null;
669
658
  const body = await resp.json();
@@ -0,0 +1,15 @@
1
+ import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
+ import {
3
+ getActiveHost,
4
+ normalizeUrl
5
+ } from "./chunk-WZ6YVQSF.js";
6
+
7
+ // src/core/auth.ts
8
+ function resolveHost(hostOverride) {
9
+ if (hostOverride) return normalizeUrl(hostOverride);
10
+ return getActiveHost();
11
+ }
12
+
13
+ export {
14
+ resolveHost
15
+ };
@@ -1,20 +1,20 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
- readOutputMetadata,
4
- unwrapOutputData,
5
- withOutputMetadata
6
- } from "./chunk-KEWVSO64.js";
3
+ resolveGatewayDomain
4
+ } from "./chunk-TKHSULJT.js";
7
5
  import {
8
6
  CapabilityGatewayError,
9
7
  fetchCapabilityGateway,
10
8
  requestCapabilityGateway
11
- } from "./chunk-GJXRF7Y6.js";
9
+ } from "./chunk-QJQZH5GQ.js";
12
10
  import {
13
- resolveGatewayDomain
14
- } from "./chunk-TKHSULJT.js";
11
+ readOutputMetadata,
12
+ unwrapOutputData,
13
+ withOutputMetadata
14
+ } from "./chunk-CZU3V3DQ.js";
15
15
  import {
16
16
  PermissionError
17
- } from "./chunk-533JK3YX.js";
17
+ } from "./chunk-4P355ZWB.js";
18
18
 
19
19
  // src/core/analysis-async-artifact.ts
20
20
  import { randomBytes } from "crypto";
@@ -2,7 +2,7 @@ import { createRequire as __createRequire } from 'node:module'; const require =
2
2
  import {
3
3
  __commonJS,
4
4
  __require
5
- } from "./chunk-FR2EDAQM.js";
5
+ } from "./chunk-4P355ZWB.js";
6
6
 
7
7
  // node_modules/process-nextick-args/index.js
8
8
  var require_process_nextick_args = __commonJS({
@@ -3,12 +3,12 @@ import {
3
3
  require_inherits,
4
4
  require_lib,
5
5
  require_node
6
- } from "./chunk-B5HMQAOM.js";
6
+ } from "./chunk-I4WQAEYB.js";
7
7
  import {
8
8
  __commonJS,
9
9
  __require,
10
10
  __toESM
11
- } from "./chunk-FR2EDAQM.js";
11
+ } from "./chunk-4P355ZWB.js";
12
12
 
13
13
  // node_modules/exceljs/lib/utils/under-dash.js
14
14
  var require_under_dash = __commonJS({
@@ -24545,8 +24545,8 @@ var PLATFORM_TO_XLSX = {
24545
24545
  };
24546
24546
  var VALID_PROP_TYPES = /* @__PURE__ */ new Set(["string", "number", "bool", "datetime", "object", "array_row", "array_string"]);
24547
24547
  var VALID_UPDATE_TYPES = /* @__PURE__ */ new Set(["user_set", "user_setOnce", "user_add"]);
24548
- var SNAKE_CASE_RE = /^[a-z][a-z0-9_]*$/;
24549
24548
  var PROP_NAME_RE = /^[a-zA-Z#][a-zA-Z0-9_.]*$/;
24549
+ var EVENT_NAME_RE = /^[A-Za-z][A-Za-z0-9_]*$/;
24550
24550
  var MIN_COL_WIDTH = 10;
24551
24551
  var PADDING = 3;
24552
24552
  function isWideChar(code) {
@@ -24592,10 +24592,11 @@ function autoFitSheet(ws, maxWidth = 55) {
24592
24592
  }
24593
24593
  function validateDraft(d) {
24594
24594
  const errors = [];
24595
+ const eventNameRe = EVENT_NAME_RE;
24595
24596
  const eventNames = /* @__PURE__ */ new Set();
24596
24597
  for (const evt of d.events) {
24597
- if (!SNAKE_CASE_RE.test(evt.event_name)) {
24598
- errors.push(`Event name "${evt.event_name}" does not match snake_case pattern`);
24598
+ if (!eventNameRe.test(evt.event_name)) {
24599
+ errors.push(`Event name "${evt.event_name}" has invalid characters`);
24599
24600
  }
24600
24601
  if (eventNames.has(evt.event_name)) {
24601
24602
  errors.push(`Duplicate event_name: "${evt.event_name}"`);
@@ -3,18 +3,15 @@ import {
3
3
  internalCallSourceHeaders
4
4
  } from "./chunk-Y74WTIKJ.js";
5
5
  import {
6
- clearCliToken,
6
+ SecureStoreAuthError,
7
7
  getCliToken
8
- } from "./chunk-RWXIXOZG.js";
8
+ } from "./chunk-ATSM5XAW.js";
9
9
  import {
10
10
  safeJsonParse
11
- } from "./chunk-KZ6ZHF5J.js";
11
+ } from "./chunk-WZ6YVQSF.js";
12
12
  import {
13
13
  PermissionError
14
- } from "./chunk-533JK3YX.js";
15
- import {
16
- logger
17
- } from "./chunk-FR2EDAQM.js";
14
+ } from "./chunk-4P355ZWB.js";
18
15
 
19
16
  // src/core/capability-api.ts
20
17
  import { readFile } from "fs/promises";
@@ -135,7 +132,13 @@ function buildCapabilityHttpError(resp, body) {
135
132
  }
136
133
  async function throwCapabilityHttpError(resp) {
137
134
  const body = parseCapabilityResponse(await resp.text());
138
- throw buildCapabilityHttpError(resp, body);
135
+ const error = buildCapabilityHttpError(resp, body);
136
+ if (resp.status === 401) {
137
+ throw new SecureStoreAuthError(
138
+ `${error.message}. The stored CLI token is invalid or expired; run: ae-cli auth login`
139
+ );
140
+ }
141
+ throw error;
139
142
  }
140
143
  async function requestOnce(url, method, token, body, accept = "application/json") {
141
144
  const headers = {
@@ -167,45 +170,17 @@ async function callGateway(host, domain, pathAfterV1, method, body, queryParams
167
170
  async function callGatewayWithEnvelope(host, domain, pathAfterV1, method, body, queryParams = {}, options = {}) {
168
171
  const url = buildCapabilityGatewayUrl(options.apiBaseUrl ?? host, domain, pathAfterV1, queryParams);
169
172
  const token = await getCliToken(host);
170
- let resp = await requestOnce(url, method, token, body);
171
- let permissionMsg;
173
+ const resp = await requestOnce(url, method, token, body);
172
174
  if (resp.status === 403) {
173
175
  const error = await permissionError(resp);
174
- permissionMsg = error.message;
175
- if (options.retryOnInvalidTokenForbidden === false || !isInvalidCliTokenMessage(permissionMsg)) {
176
- throw error;
176
+ if (options.retryOnInvalidTokenForbidden !== false && isInvalidCliTokenMessage(error.message)) {
177
+ throw new SecureStoreAuthError(
178
+ `${error.message} Run: ae-cli auth login`
179
+ );
177
180
  }
181
+ throw error;
178
182
  }
179
- if (resp.status === 401) {
180
- if (options.retryOnUnauthorized === false) {
181
- await throwCapabilityHttpError(resp);
182
- }
183
- logger.warn(`Capability gateway request failed (HTTP 401) for ${host}, refreshing CLI token`);
184
- clearCliToken(host);
185
- const newToken = await getCliToken(host);
186
- process.stderr.write(`[ae-cli] CLI token refreshed for ${host}
187
- `);
188
- resp = await requestOnce(url, method, newToken, body);
189
- if (resp.status === 403) {
190
- throw new PermissionError(await permissionMessage(resp));
191
- }
192
- if (!resp.ok) {
193
- await throwCapabilityHttpError(resp);
194
- }
195
- } else if (resp.status === 403 && permissionMsg) {
196
- logger.warn(`Capability gateway request failed (${permissionMsg}) for ${host}, refreshing CLI token`);
197
- clearCliToken(host);
198
- const newToken = await getCliToken(host);
199
- process.stderr.write(`[ae-cli] CLI token refreshed for ${host}
200
- `);
201
- resp = await requestOnce(url, method, newToken, body);
202
- if (resp.status === 403) {
203
- throw await permissionError(resp);
204
- }
205
- if (!resp.ok) {
206
- await throwCapabilityHttpError(resp);
207
- }
208
- } else if (!resp.ok) {
183
+ if (!resp.ok) {
209
184
  await throwCapabilityHttpError(resp);
210
185
  }
211
186
  return parseCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
@@ -213,24 +188,15 @@ async function callGatewayWithEnvelope(host, domain, pathAfterV1, method, body,
213
188
  async function fetchCapabilityGateway(host, domain, pathAfterV1, method = "GET", body, accept = "application/json") {
214
189
  const url = buildCapabilityGatewayUrl(host, domain, pathAfterV1);
215
190
  const token = await getCliToken(host);
216
- let resp = await requestOnce(url, method, token, body, accept);
191
+ const resp = await requestOnce(url, method, token, body, accept);
217
192
  if (resp.status === 403) {
218
- throw await permissionError(resp);
219
- }
220
- if (resp.status === 401) {
221
- logger.warn(`Capability gateway request failed (HTTP 401) for ${host}, refreshing CLI token`);
222
- clearCliToken(host);
223
- const newToken = await getCliToken(host);
224
- process.stderr.write(`[ae-cli] CLI token refreshed for ${host}
225
- `);
226
- resp = await requestOnce(url, method, newToken, body, accept);
227
- if (resp.status === 403) {
228
- throw await permissionError(resp);
229
- }
230
- if (!resp.ok) {
231
- await throwCapabilityHttpError(resp);
193
+ const error = await permissionError(resp);
194
+ if (isInvalidCliTokenMessage(error.message)) {
195
+ throw new SecureStoreAuthError(`${error.message} Run: ae-cli auth login`);
232
196
  }
233
- } else if (!resp.ok) {
197
+ throw error;
198
+ }
199
+ if (!resp.ok) {
234
200
  await throwCapabilityHttpError(resp);
235
201
  }
236
202
  return resp;
@@ -243,8 +209,11 @@ async function requestCapabilityGatewayWithEnvelope(host, domain, pathAfterV1, m
243
209
  const resp = await fetchCapabilityGateway(host, domain, pathAfterV1, method, body);
244
210
  return parseCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
245
211
  }
246
- async function listCapabilities(host, domain, projectId) {
247
- return callGateway(host, domain, "capabilities", "GET", void 0, { project_id: projectId });
212
+ async function listCapabilitiesWithEnvelope(host, domain, projectId) {
213
+ return callGatewayWithEnvelope(host, domain, "capabilities", "GET", void 0, { project_id: projectId });
214
+ }
215
+ async function inspectCapabilityWithEnvelope(host, domain, capabilityId, projectId) {
216
+ return callGatewayWithEnvelope(host, domain, `capabilities/${capabilityId}`, "GET", void 0, { project_id: projectId });
248
217
  }
249
218
  async function inspectCapability(host, domain, capabilityId, projectId) {
250
219
  return callGateway(
@@ -265,6 +234,12 @@ async function executeCapabilityWithEnvelope(host, domain, capabilityId, input =
265
234
  async function dryRunCapability(host, domain, capabilityId, input = {}) {
266
235
  return callGateway(host, domain, `capabilities/${capabilityId}/dry-run`, "POST", { input });
267
236
  }
237
+ async function dryRunCapabilityWithEnvelope(host, domain, capabilityId, input = {}) {
238
+ return callGatewayWithEnvelope(host, domain, `capabilities/${capabilityId}/dry-run`, "POST", { input });
239
+ }
240
+ async function validateCapabilityWithEnvelope(host, domain, capabilityId, input = {}) {
241
+ return callGatewayWithEnvelope(host, domain, `capabilities/${capabilityId}/validate`, "POST", { input });
242
+ }
268
243
  async function validateCapability(host, domain, capabilityId, input = {}) {
269
244
  return callGateway(host, domain, `capabilities/${capabilityId}/validate`, "POST", { input });
270
245
  }
@@ -302,24 +277,15 @@ async function uploadInputFileBytes(host, domain, projectId, purpose, bytes, fil
302
277
  form.append("purpose", purpose);
303
278
  form.append("file", new Blob([fileBuffer], { type: contentType }), filename);
304
279
  const token = await getCliToken(host);
305
- let resp = await requestMultipartOnce(url, token, form);
280
+ const resp = await requestMultipartOnce(url, token, form);
306
281
  if (resp.status === 403) {
307
- throw await permissionError(resp);
308
- }
309
- if (resp.status === 401) {
310
- logger.warn(`Capability gateway request failed (HTTP 401) for ${host}, refreshing CLI token`);
311
- clearCliToken(host);
312
- const newToken = await getCliToken(host);
313
- process.stderr.write(`[ae-cli] CLI token refreshed for ${host}
314
- `);
315
- resp = await requestMultipartOnce(url, newToken, form);
316
- if (resp.status === 403) {
317
- throw await permissionError(resp);
318
- }
319
- if (!resp.ok) {
320
- await throwCapabilityHttpError(resp);
282
+ const error = await permissionError(resp);
283
+ if (isInvalidCliTokenMessage(error.message)) {
284
+ throw new SecureStoreAuthError(`${error.message} Run: ae-cli auth login`);
321
285
  }
322
- } else if (!resp.ok) {
286
+ throw error;
287
+ }
288
+ if (!resp.ok) {
323
289
  await throwCapabilityHttpError(resp);
324
290
  }
325
291
  return unwrapCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
@@ -338,11 +304,14 @@ export {
338
304
  fetchCapabilityGateway,
339
305
  requestCapabilityGateway,
340
306
  requestCapabilityGatewayWithEnvelope,
341
- listCapabilities,
307
+ listCapabilitiesWithEnvelope,
308
+ inspectCapabilityWithEnvelope,
342
309
  inspectCapability,
343
310
  executeCapability,
344
311
  executeCapabilityWithEnvelope,
345
312
  dryRunCapability,
313
+ dryRunCapabilityWithEnvelope,
314
+ validateCapabilityWithEnvelope,
346
315
  validateCapability,
347
316
  uploadInputFile,
348
317
  uploadInputFileBytes,
@@ -1,17 +1,17 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  CapabilityGatewayError
4
- } from "./chunk-GJXRF7Y6.js";
4
+ } from "./chunk-QJQZH5GQ.js";
5
5
  import {
6
- clearCliToken,
6
+ SecureStoreAuthError,
7
7
  getCliToken
8
- } from "./chunk-RWXIXOZG.js";
8
+ } from "./chunk-ATSM5XAW.js";
9
9
  import {
10
10
  safeJsonParse
11
- } from "./chunk-KZ6ZHF5J.js";
11
+ } from "./chunk-WZ6YVQSF.js";
12
12
  import {
13
13
  PermissionError
14
- } from "./chunk-533JK3YX.js";
14
+ } from "./chunk-4P355ZWB.js";
15
15
 
16
16
  // src/core/mcp-access.ts
17
17
  function buildUrl(host, path, params = {}) {
@@ -73,7 +73,7 @@ function nonOkResponseError(resp, data, options) {
73
73
  const fallbackMessage = `KB API HTTP error: ${responseStatus(resp)}`;
74
74
  const businessCode = options.preserveBusinessErrorCode && typeof data?.error === "string" && metadata.code ? metadata.code : void 0;
75
75
  const message = businessCode ? `${businessCode}: ${serverMessage ?? fallbackMessage}` : serverMessage ?? fallbackMessage;
76
- if (metadata.code || metadata.hint) {
76
+ if (options.preserveErrorMetadata !== false && (metadata.code || metadata.hint)) {
77
77
  return new KbHttpError(message, metadata.code, resp.status, metadata.hint);
78
78
  }
79
79
  return new Error(message);
@@ -137,18 +137,28 @@ async function fetchWithCliToken(input, init, cliToken, options = {}) {
137
137
  const headers = new Headers(init.headers);
138
138
  headers.set("cli-token", cliToken);
139
139
  const resp = await fetch(input, { ...init, headers });
140
+ if (options.responseType === "bytes" && resp.ok) {
141
+ if (resp.headers.get("content-type")?.includes("application/json")) {
142
+ parseKbResponse(resp, await resp.text(), options);
143
+ throw new Error("KB raw-file protocol error: unexpected JSON response");
144
+ }
145
+ return {
146
+ bytes: new Uint8Array(await resp.arrayBuffer()),
147
+ contentType: resp.headers.get("content-type") ?? "application/octet-stream"
148
+ };
149
+ }
140
150
  return parseKbResponse(resp, await resp.text(), options);
141
151
  }
142
152
  async function requestWithCliToken(host, input, init, options) {
143
- const request = async () => fetchWithCliToken(input, init, await getCliToken(host), options);
144
153
  try {
145
- return await request();
154
+ return await fetchWithCliToken(input, init, await getCliToken(host), options);
146
155
  } catch (error) {
147
- if (!(error instanceof KbUnauthorizedError) || !options.retryUnauthorized) {
148
- throw error;
156
+ if (error instanceof KbUnauthorizedError) {
157
+ throw new SecureStoreAuthError(
158
+ `The stored CLI token for ${host} is invalid or expired. Run: ae-cli auth login --host ${host}`
159
+ );
149
160
  }
150
- clearCliToken(host);
151
- return request();
161
+ throw error;
152
162
  }
153
163
  }
154
164
  async function getAuthHeaders(ctx) {
@@ -173,6 +183,7 @@ async function kbApi(ctx, method, path, params = {}, body, options = {}) {
173
183
  }
174
184
  async function kbUpload(ctx, path, form, params = {}, options = {}) {
175
185
  const host = ctx.host();
186
+ const uploadOptions = { preserveErrorMetadata: false, ...options };
176
187
  return requestWithCliToken(
177
188
  host,
178
189
  buildUrl(host, path, params),
@@ -180,7 +191,7 @@ async function kbUpload(ctx, path, form, params = {}, options = {}) {
180
191
  method: "POST",
181
192
  body: form
182
193
  },
183
- options
194
+ uploadOptions
184
195
  );
185
196
  }
186
197
 
@@ -1,7 +1,20 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  logger
4
- } from "./chunk-FR2EDAQM.js";
4
+ } from "./chunk-4P355ZWB.js";
5
+
6
+ // src/core/url-utils.ts
7
+ function normalizeUrl(url) {
8
+ if (!url) return url;
9
+ if (!url.startsWith("http://") && !url.startsWith("https://")) {
10
+ url = `https://${url}`;
11
+ }
12
+ return url.replace(/\/$/, "");
13
+ }
14
+
15
+ // src/core/config.ts
16
+ import fs3 from "fs";
17
+ import path from "path";
5
18
 
6
19
  // src/core/json-utils.ts
7
20
  import fs from "fs";
@@ -39,19 +52,6 @@ function safeReadJsonFile(filePath) {
39
52
  return safeJsonParse(content);
40
53
  }
41
54
 
42
- // src/core/url-utils.ts
43
- function normalizeUrl(url) {
44
- if (!url) return url;
45
- if (!url.startsWith("http://") && !url.startsWith("https://")) {
46
- url = `https://${url}`;
47
- }
48
- return url.replace(/\/$/, "");
49
- }
50
-
51
- // src/core/config.ts
52
- import fs3 from "fs";
53
- import path from "path";
54
-
55
55
  // src/core/sandbox-runtime.ts
56
56
  import { homedir } from "os";
57
57
  import { join } from "path";
@@ -1,10 +1,8 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
- CommunityReportError
4
- } from "./chunk-533JK3YX.js";
5
- import {
3
+ CommunityReportError,
6
4
  logger
7
- } from "./chunk-FR2EDAQM.js";
5
+ } from "./chunk-4P355ZWB.js";
8
6
 
9
7
  // src/core/community-report-client.ts
10
8
  var DEFAULT_TIMEOUT_MS = 3e4;