@thinkingai/ae-cli 6.0.24 → 6.0.27

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 (130) hide show
  1. package/dist/{auth-A2XXG5K4.js → auth-7TQRGLBC.js} +10 -8
  2. package/dist/{auth-IDPKDFSY.js → auth-MEJ642P4.js} +2 -2
  3. package/dist/chunk-2NDGFQHW.js +190 -0
  4. package/dist/{chunk-NGJDCOYA.js → chunk-7QQ4233A.js} +3 -3
  5. package/dist/{chunk-PFJFZVCK.js → chunk-AJTH7LT3.js} +3 -2
  6. package/dist/{chunk-V5R5UIRM.js → chunk-BXMXMUD7.js} +65 -6
  7. package/dist/{chunk-AKORWVHJ.js → chunk-C4DH76LX.js} +1 -1
  8. package/dist/{chunk-NXJP4CES.js → chunk-GWZ5MYWE.js} +3 -3
  9. package/dist/{chunk-F3ZDMC2W.js → chunk-KCA6BA5D.js} +2 -2
  10. package/dist/{chunk-WXBCP6SD.js → chunk-KGJQCYVC.js} +1 -1
  11. package/dist/{chunk-FIT4CFIN.js → chunk-LG5YT7P7.js} +1 -1
  12. package/dist/{chunk-IDXW6MEJ.js → chunk-MDJGDI6K.js} +2 -2
  13. package/dist/{chunk-4FQ36OGO.js → chunk-R77JT7XD.js} +53 -6
  14. package/dist/{chunk-65DKFJZB.js → chunk-YCLVYFK7.js} +49 -6
  15. package/dist/{chunk-2OW2RENH.js → chunk-YNQFYBDB.js} +64 -6
  16. package/dist/{chunk-ONOA6DYB.js → chunk-ZAOL36CG.js} +1 -1
  17. package/dist/cli-token-TVQRSE46.js +18 -0
  18. package/dist/{client-7L735LVY.js → client-2643Z5AG.js} +3 -3
  19. package/dist/{config-SXD2JKSL.js → config-ZVPARN4R.js} +4 -9
  20. package/dist/index.js +24 -24
  21. package/dist/{metadata-QWUAX625.js → metadata-IPSPQBX3.js} +5 -5
  22. package/dist/{metadata-XWTEGEN2.js → metadata-N5REJ7R7.js} +5 -5
  23. package/dist/{model-3OVX42DA.js → model-T3KZJWLW.js} +2 -2
  24. package/dist/{raw-IANB4AV5.js → raw-OHSUK42D.js} +4 -4
  25. package/dist/{sync-4HQ3CXSK.js → sync-ULT5SECP.js} +3 -3
  26. package/dist/{te-agent-OYNNTJDU.js → te-agent-QLIVKRUN.js} +1146 -61
  27. package/dist/{te-analysis-CRPFK3LX.js → te-analysis-2U5EPXQC.js} +207 -69
  28. package/dist/{te-analysis-JX3V76OI.js → te-analysis-QMZ2UH7F.js} +207 -69
  29. package/dist/{te-audience-RO2IZOUC.js → te-audience-PVMKQAFH.js} +5 -5
  30. package/dist/{te-audience-77FGNG5E.js → te-audience-XMRMVD2V.js} +5 -5
  31. package/dist/{te-common-4TRJPRC5.js → te-common-CFGQXTFV.js} +5 -5
  32. package/dist/{te-common-PUXBUPOL.js → te-common-SDB3O2QG.js} +5 -5
  33. package/dist/{te-community-XKE526DS.js → te-community-6A7LKYUH.js} +5 -5
  34. package/dist/{te-community-NPDZQKMY.js → te-community-GMWFGILT.js} +5 -5
  35. package/dist/{te-dataops-PW74WP76.js → te-dataops-6LIPYNGH.js} +90 -68
  36. package/dist/{te-dataops-6KWLFNV4.js → te-dataops-Z53CTG2U.js} +90 -68
  37. package/dist/{te-engage-HTLMUN7G.js → te-engage-AGREUOW7.js} +30 -15
  38. package/dist/{te-engage-YPQIVF5H.js → te-engage-MIIUKY6M.js} +30 -15
  39. package/dist/{te-kb-DOGDQIU4.js → te-kb-KQJ53M3A.js} +4 -4
  40. package/dist/{te-meta-5ESSQ5B3.js → te-meta-QLANJ4B4.js} +5 -5
  41. package/dist/{te-meta-Z47X4VT3.js → te-meta-TOA6FWDE.js} +5 -5
  42. package/dist/{te-team-SOVKZIDD.js → te-team-TQGMNHQQ.js} +5 -5
  43. package/package.json +3 -1
  44. package/skills/ae-agent/SKILL.md +158 -189
  45. package/skills/ae-agent/references/accept-skill-share.md +39 -0
  46. package/skills/ae-agent/references/add-attachment.md +57 -0
  47. package/skills/ae-agent/references/add-mcp.md +75 -0
  48. package/skills/ae-agent/references/add-model.md +70 -0
  49. package/skills/ae-agent/references/add-skill.md +71 -0
  50. package/skills/ae-agent/references/approve-skill.md +41 -0
  51. package/skills/ae-agent/references/attachment-stats.md +50 -0
  52. package/skills/ae-agent/references/auto-provision-mcp-credentials.md +57 -0
  53. package/skills/ae-agent/references/cancel-skill-submission.md +39 -0
  54. package/skills/ae-agent/references/copy-skill.md +53 -0
  55. package/skills/ae-agent/references/create-agent.md +71 -0
  56. package/skills/ae-agent/references/create-automation.md +99 -0
  57. package/skills/ae-agent/references/del-agent.md +38 -0
  58. package/skills/ae-agent/references/del-attachment.md +35 -0
  59. package/skills/ae-agent/references/del-mcp.md +35 -0
  60. package/skills/ae-agent/references/del-model.md +37 -0
  61. package/skills/ae-agent/references/del-skill-asset.md +41 -0
  62. package/skills/ae-agent/references/del-skill-reference.md +41 -0
  63. package/skills/ae-agent/references/del-skill-script.md +41 -0
  64. package/skills/ae-agent/references/del-skill.md +36 -0
  65. package/skills/ae-agent/references/edit-skill.md +64 -0
  66. package/skills/ae-agent/references/get-agent.md +37 -0
  67. package/skills/ae-agent/references/get-skill-content.md +36 -0
  68. package/skills/ae-agent/references/list-agents.md +40 -0
  69. package/skills/ae-agent/references/list-attachments.md +42 -0
  70. package/skills/ae-agent/references/list-automations.md +41 -0
  71. package/skills/ae-agent/references/list-mcp-credentials.md +65 -0
  72. package/skills/ae-agent/references/list-mcp-market.md +58 -0
  73. package/skills/ae-agent/references/list-mcps.md +37 -0
  74. package/skills/ae-agent/references/list-models.md +38 -0
  75. package/skills/ae-agent/references/list-skill-assets.md +35 -0
  76. package/skills/ae-agent/references/list-skill-market.md +59 -0
  77. package/skills/ae-agent/references/list-skill-references.md +36 -0
  78. package/skills/ae-agent/references/list-skill-scripts.md +35 -0
  79. package/skills/ae-agent/references/list-skill-shares.md +49 -0
  80. package/skills/ae-agent/references/list-skill-submissions.md +45 -0
  81. package/skills/ae-agent/references/list-skills.md +37 -0
  82. package/skills/ae-agent/references/mcp-auth-disconnect.md +50 -0
  83. package/skills/ae-agent/references/mcp-auth-start.md +61 -0
  84. package/skills/ae-agent/references/mcp-auth-status.md +56 -0
  85. package/skills/ae-agent/references/mcp-stats.md +68 -0
  86. package/skills/ae-agent/references/mcp-token.md +63 -0
  87. package/skills/ae-agent/references/mcp-tools.md +55 -0
  88. package/skills/ae-agent/references/read-skill-asset.md +51 -0
  89. package/skills/ae-agent/references/read-skill-reference.md +50 -0
  90. package/skills/ae-agent/references/read-skill-script.md +51 -0
  91. package/skills/ae-agent/references/reject-skill-share.md +37 -0
  92. package/skills/ae-agent/references/reject-skill.md +42 -0
  93. package/skills/ae-agent/references/rescan-skills.md +44 -0
  94. package/skills/ae-agent/references/set-mcp-credential.md +67 -0
  95. package/skills/ae-agent/references/set-mcp-meta.md +52 -0
  96. package/skills/ae-agent/references/set-skill-meta.md +51 -0
  97. package/skills/ae-agent/references/share-skill.md +50 -0
  98. package/skills/ae-agent/references/submit-skill.md +51 -0
  99. package/skills/ae-agent/references/test-model.md +61 -0
  100. package/skills/ae-agent/references/toggle-mcp.md +39 -0
  101. package/skills/ae-agent/references/toggle-model.md +37 -0
  102. package/skills/ae-agent/references/toggle-skill.md +37 -0
  103. package/skills/ae-agent/references/update-agent.md +71 -0
  104. package/skills/ae-agent/references/update-automation.md +83 -0
  105. package/skills/ae-agent/references/update-mcp.md +79 -0
  106. package/skills/ae-agent/references/update-model.md +77 -0
  107. package/skills/ae-agent/references/upload-skill-asset.md +49 -0
  108. package/skills/ae-agent/references/upload-skill-reference.md +51 -0
  109. package/skills/ae-agent/references/upload-skill-script.md +49 -0
  110. package/skills/ae-agent/references/upload-skill.md +89 -0
  111. package/skills/ae-analysis/SKILL.md +4 -2
  112. package/skills/ae-analysis/references/analysis_gateway_assets.md +21 -6
  113. package/skills/ae-analysis/references/artifact_download.md +17 -0
  114. package/skills/ae-analysis/references/bi_panel_page_data_export.md +11 -1
  115. package/skills/ae-analysis/references/dashboard_copy.md +3 -1
  116. package/skills/ae-analysis/references/dashboard_daily_report_send.md +4 -2
  117. package/skills/ae-analysis/references/dashboard_daily_report_update.md +3 -1
  118. package/skills/ae-analysis/references/dashboard_definition_export.md +21 -3
  119. package/skills/ae-analysis/references/dashboard_report_data_export.md +11 -1
  120. package/skills/ae-analysis/references/project_space_create.md +1 -1
  121. package/skills/ae-analysis/references/run_inspect.md +22 -0
  122. package/skills/ae-dataops/references/dataops-flow-create.md +2 -2
  123. package/skills/ae-dataops/references/dataops-flow-monitor.md +3 -3
  124. package/skills/ae-dataops/references/dataops-integration.md +1 -0
  125. package/skills/ae-engage/references/flow-node-config-schema.md +32 -8
  126. package/skills/ae-engage/references/save-flow.md +65 -29
  127. package/skills/ae-engage/references/validate-flow-node-config.md +28 -10
  128. package/skills/ae-generate-tracking-plan/SKILL.md +9 -7
  129. package/dist/chunk-OCQPQYHZ.js +0 -105
  130. package/dist/cli-token-OZXHC3U2.js +0 -14
@@ -1,24 +1,25 @@
1
1
  import {
2
2
  printError,
3
3
  printOutput
4
- } from "./chunk-ONOA6DYB.js";
4
+ } from "./chunk-ZAOL36CG.js";
5
5
  import {
6
6
  clearCliToken,
7
7
  mintCliToken
8
- } from "./chunk-OCQPQYHZ.js";
8
+ } from "./chunk-2NDGFQHW.js";
9
9
  import {
10
10
  clear,
11
11
  load,
12
12
  resolveHost,
13
13
  save
14
- } from "./chunk-PFJFZVCK.js";
14
+ } from "./chunk-AJTH7LT3.js";
15
15
  import {
16
16
  getFallbackCliToken,
17
17
  loadConfig,
18
18
  logger,
19
+ normalizeUrl,
19
20
  removeHost,
20
21
  saveConfig
21
- } from "./chunk-65DKFJZB.js";
22
+ } from "./chunk-YCLVYFK7.js";
22
23
 
23
24
  // src/core/device-auth.ts
24
25
  import { execFileSync } from "child_process";
@@ -232,13 +233,14 @@ function resolveAuthHost(program, opts) {
232
233
  }
233
234
  function activateHostAfterLogin(host, explicitHostOverride) {
234
235
  if (!explicitHostOverride) return;
236
+ const normalized = normalizeUrl(host);
235
237
  const config = loadConfig();
236
- if (!config.hosts[host]) {
237
- config.hosts[host] = { label: host };
238
+ if (!config.hosts[normalized]) {
239
+ config.hosts[normalized] = { label: normalized };
238
240
  }
239
- config.activeHost = host;
241
+ config.activeHost = normalized;
240
242
  saveConfig(config);
241
- logger.info(`Active host set to ${host} after login`);
243
+ logger.info(`Active host set to ${normalized} after login`);
242
244
  }
243
245
  async function persistDeviceTokens(host, tokens) {
244
246
  const DEFAULT_EXPIRES_IN = 72e3;
@@ -3,8 +3,8 @@ import {
3
3
  invalidateAccessTokenForRetry,
4
4
  resolveHost,
5
5
  validateToken
6
- } from "./chunk-PFJFZVCK.js";
7
- import "./chunk-65DKFJZB.js";
6
+ } from "./chunk-AJTH7LT3.js";
7
+ import "./chunk-YCLVYFK7.js";
8
8
  export {
9
9
  getToken,
10
10
  invalidateAccessTokenForRetry,
@@ -0,0 +1,190 @@
1
+ import {
2
+ getToken,
3
+ load,
4
+ loadCliToken,
5
+ save
6
+ } from "./chunk-AJTH7LT3.js";
7
+ import {
8
+ getActiveHost,
9
+ getConfigDir,
10
+ getFallbackCliToken,
11
+ listHosts,
12
+ logger,
13
+ normalizeUrl,
14
+ safeJsonParse,
15
+ safeReadJsonFile
16
+ } from "./chunk-YCLVYFK7.js";
17
+
18
+ // src/core/cli-token.ts
19
+ import fs from "fs";
20
+ import path from "path";
21
+ var CLI_TOKEN_GENERATE_PATH = "/v1/ta/cli/token/generate";
22
+ var _cliTokenCache = /* @__PURE__ */ new Map();
23
+ var _renewedLocalDateByHost = /* @__PURE__ */ new Map();
24
+ var _renewInFlightByHost = /* @__PURE__ */ new Map();
25
+ function renewHostKey(hostUrl) {
26
+ return normalizeUrl(hostUrl);
27
+ }
28
+ function renewStateFilePath() {
29
+ return path.join(getConfigDir(), "cli-token-renew.json");
30
+ }
31
+ function localRenewDate(now = /* @__PURE__ */ new Date()) {
32
+ const y = now.getFullYear();
33
+ const m = String(now.getMonth() + 1).padStart(2, "0");
34
+ const d = String(now.getDate()).padStart(2, "0");
35
+ return `${y}-${m}-${d}`;
36
+ }
37
+ function loadRenewStore() {
38
+ try {
39
+ const file = renewStateFilePath();
40
+ if (!fs.existsSync(file)) return {};
41
+ const data = safeReadJsonFile(file);
42
+ if (!data || typeof data !== "object" || Array.isArray(data)) return {};
43
+ return data;
44
+ } catch {
45
+ return {};
46
+ }
47
+ }
48
+ function saveRenewStore(store) {
49
+ const dir = getConfigDir();
50
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
51
+ const file = renewStateFilePath();
52
+ if (Object.keys(store).length === 0) {
53
+ try {
54
+ fs.unlinkSync(file);
55
+ } catch {
56
+ }
57
+ return;
58
+ }
59
+ fs.writeFileSync(file, JSON.stringify(store, null, 2), { encoding: "utf8" });
60
+ try {
61
+ fs.chmodSync(file, 384);
62
+ } catch {
63
+ }
64
+ }
65
+ function clearRenewState(hostUrl) {
66
+ if (hostUrl) {
67
+ const key = renewHostKey(hostUrl);
68
+ _renewedLocalDateByHost.delete(key);
69
+ _renewInFlightByHost.delete(key);
70
+ if (key !== hostUrl) {
71
+ _renewedLocalDateByHost.delete(hostUrl);
72
+ _renewInFlightByHost.delete(hostUrl);
73
+ }
74
+ const store = loadRenewStore();
75
+ let changed = false;
76
+ for (const k of /* @__PURE__ */ new Set([key, hostUrl])) {
77
+ if (store[k]) {
78
+ delete store[k];
79
+ changed = true;
80
+ }
81
+ }
82
+ if (changed) {
83
+ saveRenewStore(store);
84
+ }
85
+ return;
86
+ }
87
+ _renewedLocalDateByHost.clear();
88
+ _renewInFlightByHost.clear();
89
+ saveRenewStore({});
90
+ }
91
+ async function generateCliToken(hostUrl) {
92
+ const accessToken = await getToken(hostUrl);
93
+ const base = hostUrl.replace(/\/+$/, "");
94
+ const url = `${base}${CLI_TOKEN_GENERATE_PATH}`;
95
+ const resp = await fetch(url, {
96
+ method: "GET",
97
+ headers: {
98
+ "Authorization": `bearer ${accessToken}`
99
+ }
100
+ });
101
+ if (!resp.ok) {
102
+ throw new Error(`CLI token generate HTTP error: ${resp.status} ${resp.statusText}`);
103
+ }
104
+ const data = safeJsonParse(await resp.text());
105
+ if (data.return_code !== 0) {
106
+ throw new Error(`CLI token generate error: ${data.return_message || "unknown"} (code: ${data.return_code})`);
107
+ }
108
+ const cliToken = data.data?.userSecret;
109
+ if (!cliToken) {
110
+ throw new Error("CLI token generate error: empty userSecret in response");
111
+ }
112
+ return cliToken;
113
+ }
114
+ function persistCliTokenIfPossible(hostUrl, cliToken) {
115
+ const existing = load(hostUrl);
116
+ if (!existing) {
117
+ logger.info(`cli-token: no secure-store session for ${hostUrl}, keeping token in-process only`);
118
+ return;
119
+ }
120
+ save(hostUrl, { ...existing, cliToken });
121
+ }
122
+ function clearPersistedCliToken(hostUrl) {
123
+ const existing = load(hostUrl);
124
+ if (existing?.cliToken) {
125
+ save(hostUrl, { ...existing, cliToken: void 0 });
126
+ }
127
+ }
128
+ async function getCliToken(hostOverride) {
129
+ const hostUrl = hostOverride || getActiveHost();
130
+ let token = _cliTokenCache.get(hostUrl);
131
+ if (!token) {
132
+ const storedToken = loadCliToken(hostUrl);
133
+ if (storedToken) {
134
+ _cliTokenCache.set(hostUrl, storedToken);
135
+ logger.info(`Using persisted CLI token (secure-store) for ${hostUrl}`);
136
+ token = storedToken;
137
+ }
138
+ }
139
+ if (!token) {
140
+ const fallbackToken = getFallbackCliToken(hostUrl);
141
+ if (fallbackToken) {
142
+ _cliTokenCache.set(hostUrl, fallbackToken);
143
+ logger.info(`Using sandbox-provisioned CLI token (fallback file) for ${hostUrl}`);
144
+ token = fallbackToken;
145
+ }
146
+ }
147
+ if (!token) {
148
+ token = await mintCliToken(hostUrl);
149
+ }
150
+ return token;
151
+ }
152
+ async function mintCliToken(hostUrl) {
153
+ logger.info(`Generating CLI token for ${hostUrl}`);
154
+ const cliToken = await generateCliToken(hostUrl);
155
+ _cliTokenCache.set(hostUrl, cliToken);
156
+ persistCliTokenIfPossible(hostUrl, cliToken);
157
+ logger.info(`CLI token generated, cached, and persisted for ${hostUrl}`);
158
+ return cliToken;
159
+ }
160
+ function clearCliToken(hostUrl) {
161
+ if (hostUrl) {
162
+ _cliTokenCache.delete(hostUrl);
163
+ clearPersistedCliToken(hostUrl);
164
+ clearRenewState(hostUrl);
165
+ return;
166
+ }
167
+ _cliTokenCache.clear();
168
+ clearRenewState();
169
+ for (const { url } of listHosts()) {
170
+ clearPersistedCliToken(url);
171
+ }
172
+ }
173
+ function setCliTokenManual(token, hostUrl) {
174
+ _cliTokenCache.set(hostUrl, token);
175
+ persistCliTokenIfPossible(hostUrl, token);
176
+ logger.info(`CLI token set for ${hostUrl}`);
177
+ }
178
+ function _resetRenewMemoryForTest() {
179
+ _renewedLocalDateByHost.clear();
180
+ _renewInFlightByHost.clear();
181
+ }
182
+
183
+ export {
184
+ localRenewDate,
185
+ getCliToken,
186
+ mintCliToken,
187
+ clearCliToken,
188
+ setCliTokenManual,
189
+ _resetRenewMemoryForTest
190
+ };
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  getAnalysisMappingPathForClusterMode
3
- } from "./chunk-WXBCP6SD.js";
3
+ } from "./chunk-KGJQCYVC.js";
4
4
  import {
5
5
  PermissionError
6
6
  } from "./chunk-NOO24N7W.js";
7
7
  import {
8
8
  clearCliToken,
9
9
  getCliToken
10
- } from "./chunk-OCQPQYHZ.js";
10
+ } from "./chunk-2NDGFQHW.js";
11
11
  import {
12
12
  getActiveHost,
13
13
  logger,
14
14
  safeJsonParse
15
- } from "./chunk-65DKFJZB.js";
15
+ } from "./chunk-YCLVYFK7.js";
16
16
 
17
17
  // src/core/mcp.ts
18
18
  async function permissionMessage(resp) {
@@ -2,8 +2,9 @@ import {
2
2
  getActiveHost,
3
3
  getConfigDir,
4
4
  logger,
5
+ normalizeUrl,
5
6
  safeJsonParse
6
- } from "./chunk-65DKFJZB.js";
7
+ } from "./chunk-YCLVYFK7.js";
7
8
 
8
9
  // src/core/secure-store.ts
9
10
  import crypto from "crypto";
@@ -232,7 +233,7 @@ var SecureStoreAuthError = class extends Error {
232
233
 
233
234
  // src/core/auth.ts
234
235
  function resolveHost(hostOverride) {
235
- if (hostOverride) return hostOverride;
236
+ if (hostOverride) return normalizeUrl(hostOverride);
236
237
  return getActiveHost();
237
238
  }
238
239
  async function validateToken(token, hostUrl) {
@@ -4,11 +4,11 @@ import {
4
4
  import {
5
5
  clearCliToken,
6
6
  getCliToken
7
- } from "./chunk-OCQPQYHZ.js";
7
+ } from "./chunk-2NDGFQHW.js";
8
8
  import {
9
9
  logger,
10
10
  safeJsonParse
11
- } from "./chunk-65DKFJZB.js";
11
+ } from "./chunk-YCLVYFK7.js";
12
12
 
13
13
  // src/core/capability-api.ts
14
14
  import { readFile } from "fs/promises";
@@ -48,6 +48,9 @@ async function permissionMessage(resp) {
48
48
  }
49
49
  return "Permission denied for this resource (HTTP 403)";
50
50
  }
51
+ function isInvalidCliTokenMessage(message) {
52
+ return /\byour token is invalid\b/i.test(message) || /\bcli[-_\s]?token\b.*\binvalid\b/i.test(message) || /\binvalid\b.*\bcli[-_\s]?token\b/i.test(message);
53
+ }
51
54
  function parseCapabilityResponse(text) {
52
55
  if (!text) return void 0;
53
56
  try {
@@ -120,15 +123,29 @@ async function requestMultipartOnce(url, token, form) {
120
123
  body: form
121
124
  });
122
125
  }
126
+ async function requestDownloadOnce(url, token) {
127
+ return fetch(url, {
128
+ method: "GET",
129
+ headers: {
130
+ "cli-token": token,
131
+ "Accept": "*/*",
132
+ "X-Source": "ae-cli"
133
+ }
134
+ });
135
+ }
123
136
  async function callGateway(host, domain, pathAfterV1, method, body) {
124
137
  const url = buildCapabilityGatewayUrl(host, domain, pathAfterV1);
125
138
  const token = await getCliToken(host);
126
139
  let resp = await requestOnce(url, method, token, body);
140
+ let permissionMsg;
127
141
  if (resp.status === 403) {
128
- throw new PermissionError(await permissionMessage(resp));
142
+ permissionMsg = await permissionMessage(resp);
143
+ if (!isInvalidCliTokenMessage(permissionMsg)) {
144
+ throw new PermissionError(permissionMsg);
145
+ }
129
146
  }
130
- if (resp.status === 401) {
131
- logger.warn(`Capability gateway request failed (HTTP 401) for ${host}, refreshing CLI token`);
147
+ if (resp.status === 401 || resp.status === 403 && permissionMsg) {
148
+ logger.warn(`Capability gateway request failed (${resp.status === 403 ? permissionMsg : "HTTP 401"}) for ${host}, refreshing CLI token`);
132
149
  clearCliToken(host);
133
150
  const newToken = await getCliToken(host);
134
151
  process.stderr.write(`[ae-cli] CLI token refreshed for ${host}
@@ -185,11 +202,53 @@ async function uploadInputFileBytes(host, domain, projectId, purpose, bytes, fil
185
202
  }
186
203
  return unwrapCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
187
204
  }
205
+ async function downloadCapabilityArtifact(host, domain, runId, artifactId) {
206
+ const url = buildCapabilityGatewayUrl(
207
+ host,
208
+ domain,
209
+ `runs/${encodeURIComponent(runId)}/artifacts/${encodeURIComponent(artifactId)}/download`
210
+ );
211
+ const token = await getCliToken(host);
212
+ let resp = await requestDownloadOnce(url, token);
213
+ if (resp.status === 403) {
214
+ throw new PermissionError(await permissionMessage(resp));
215
+ }
216
+ if (resp.status === 401) {
217
+ logger.warn(`Capability gateway artifact download failed (HTTP 401) for ${host}, refreshing CLI token`);
218
+ clearCliToken(host);
219
+ const newToken = await getCliToken(host);
220
+ process.stderr.write(`[ae-cli] CLI token refreshed for ${host}
221
+ `);
222
+ resp = await requestDownloadOnce(url, newToken);
223
+ if (resp.status === 403) {
224
+ throw new PermissionError(await permissionMessage(resp));
225
+ }
226
+ if (!resp.ok) {
227
+ await throwCapabilityHttpError(resp);
228
+ }
229
+ } else if (!resp.ok) {
230
+ await throwCapabilityHttpError(resp);
231
+ }
232
+ return {
233
+ bytes: Buffer.from(await resp.arrayBuffer()),
234
+ contentType: resp.headers.get("content-type") ?? void 0,
235
+ contentDisposition: resp.headers.get("content-disposition") ?? void 0
236
+ };
237
+ }
238
+ async function callCapabilityApi(host, domain, action, method = "POST", params = {}) {
239
+ const isGet = method === "GET";
240
+ if (isGet) {
241
+ return callGateway(host, domain, action.replace(/^\/+|\/+$/g, ""), "GET");
242
+ }
243
+ return callGateway(host, domain, action.replace(/^\/+|\/+$/g, ""), method, params);
244
+ }
188
245
 
189
246
  export {
190
247
  CapabilityGatewayError,
191
248
  buildCapabilityGatewayUrl,
192
249
  executeCapability,
193
250
  uploadInputFile,
194
- uploadInputFileBytes
251
+ uploadInputFileBytes,
252
+ downloadCapabilityArtifact,
253
+ callCapabilityApi
195
254
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  buildCapabilityGatewayUrl,
3
3
  executeCapability
4
- } from "./chunk-V5R5UIRM.js";
4
+ } from "./chunk-BXMXMUD7.js";
5
5
 
6
6
  // src/core/capability-routing.ts
7
7
  var cliServiceRoutes = /* @__PURE__ */ new Map();
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  getAnalysisMappingPathForClusterMode
3
- } from "./chunk-WXBCP6SD.js";
3
+ } from "./chunk-KGJQCYVC.js";
4
4
  import {
5
5
  PermissionError
6
6
  } from "./chunk-NOO24N7W.js";
7
7
  import {
8
8
  clearCliToken,
9
9
  getCliToken
10
- } from "./chunk-OCQPQYHZ.js";
10
+ } from "./chunk-2NDGFQHW.js";
11
11
  import {
12
12
  getActiveHost,
13
13
  logger,
14
14
  safeJsonParse
15
- } from "./chunk-65DKFJZB.js";
15
+ } from "./chunk-YCLVYFK7.js";
16
16
 
17
17
  // src/core/mcp.ts
18
18
  async function permissionMessage(resp) {
@@ -3,11 +3,11 @@ import {
3
3
  getToken,
4
4
  invalidateAccessTokenForRetry,
5
5
  resolveHost
6
- } from "./chunk-PFJFZVCK.js";
6
+ } from "./chunk-AJTH7LT3.js";
7
7
  import {
8
8
  logger,
9
9
  safeJsonParse
10
- } from "./chunk-65DKFJZB.js";
10
+ } from "./chunk-YCLVYFK7.js";
11
11
 
12
12
  // src/core/client.ts
13
13
  import WebSocket from "ws";
@@ -2,7 +2,7 @@ import {
2
2
  getSandboxClusterInfoFilePath,
3
3
  logger,
4
4
  safeReadJsonFile
5
- } from "./chunk-65DKFJZB.js";
5
+ } from "./chunk-YCLVYFK7.js";
6
6
 
7
7
  // src/core/cluster-info.ts
8
8
  import fs from "fs";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  buildCapabilityGatewayUrl,
3
3
  executeCapability
4
- } from "./chunk-2OW2RENH.js";
4
+ } from "./chunk-YNQFYBDB.js";
5
5
 
6
6
  // src/core/capability-routing.ts
7
7
  var cliServiceRoutes = /* @__PURE__ */ new Map();
@@ -3,10 +3,10 @@ import {
3
3
  } from "./chunk-NOO24N7W.js";
4
4
  import {
5
5
  getCliToken
6
- } from "./chunk-OCQPQYHZ.js";
6
+ } from "./chunk-2NDGFQHW.js";
7
7
  import {
8
8
  safeJsonParse
9
- } from "./chunk-65DKFJZB.js";
9
+ } from "./chunk-YCLVYFK7.js";
10
10
 
11
11
  // src/core/mcp-access.ts
12
12
  function buildUrl(host, path, params = {}) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getActiveHost,
3
3
  getSandboxRuntimeRoot
4
- } from "./chunk-65DKFJZB.js";
4
+ } from "./chunk-YCLVYFK7.js";
5
5
 
6
6
  // src/core/te-agent-credentials.ts
7
7
  import { readFileSync } from "fs";
@@ -138,7 +138,7 @@ async function signRequest(method, path, rawBody) {
138
138
  "X-Sandbox-Id": sandboxCred.sandboxId,
139
139
  "X-Sandbox-Secret-Key": sandboxCred.sandboxSecretKey
140
140
  };
141
- if (method === "POST" || method === "PATCH") {
141
+ if (method === "POST" || method === "PATCH" || method === "PUT") {
142
142
  headers["Content-Type"] = "application/json";
143
143
  }
144
144
  return {
@@ -147,8 +147,8 @@ async function signRequest(method, path, rawBody) {
147
147
  rawBody
148
148
  };
149
149
  }
150
- const { getToken } = await import("./auth-IDPKDFSY.js");
151
- const { getCliToken } = await import("./cli-token-OZXHC3U2.js");
150
+ const { getToken } = await import("./auth-MEJ642P4.js");
151
+ const { getCliToken } = await import("./cli-token-TVQRSE46.js");
152
152
  const baseUrl = sandboxCred?.url || teClaudeBaseFromActiveHost();
153
153
  const hostForToken = getActiveHost() || baseUrl;
154
154
  if (!baseUrl) {
@@ -157,7 +157,7 @@ async function signRequest(method, path, rawBody) {
157
157
  "Run ae-cli config set-host <url> to configure the service URL, or execute inside a te-agent sandbox"
158
158
  );
159
159
  }
160
- const contentTypeHeader = method === "POST" || method === "PATCH" ? { "Content-Type": "application/json" } : {};
160
+ const contentTypeHeader = method === "POST" || method === "PATCH" || method === "PUT" ? { "Content-Type": "application/json" } : {};
161
161
  let accessToken = null;
162
162
  try {
163
163
  accessToken = await getToken(hostForToken);
@@ -282,6 +282,51 @@ async function patchToMainApp(path, body) {
282
282
  });
283
283
  return parseResponse(response, "Main app returned");
284
284
  }
285
+ async function putToMainApp(path, body) {
286
+ const rawBody = JSON.stringify(body);
287
+ const signed = await signRequest("PUT", path, rawBody);
288
+ const response = await fetchWithTimeout(signed.url, {
289
+ method: "PUT",
290
+ headers: signed.headers,
291
+ body: signed.rawBody
292
+ });
293
+ return parseResponse(response, "Main app returned");
294
+ }
295
+ async function getBufferFromMainApp(path) {
296
+ const signed = await signRequest("GET", path, "");
297
+ const response = await fetchWithTimeout(signed.url, {
298
+ method: "GET",
299
+ headers: signed.headers
300
+ });
301
+ if (!response.ok) {
302
+ const text = await response.text();
303
+ let parsed = void 0;
304
+ if (text) {
305
+ try {
306
+ parsed = JSON.parse(text);
307
+ } catch {
308
+ parsed = text;
309
+ }
310
+ }
311
+ if (response.status === 401) {
312
+ throw new TeAgentApiError(
313
+ "Session expired or unauthorized. Please run: ae-cli auth login",
314
+ response.status,
315
+ "auth_expired",
316
+ parsed
317
+ );
318
+ }
319
+ const message = typeof parsed === "object" && parsed && typeof parsed.error === "string" ? parsed.error : `Main app returned ${response.status}`;
320
+ const code = typeof parsed === "object" && parsed && typeof parsed.code === "string" ? parsed.code : void 0;
321
+ throw new TeAgentApiError(message, response.status, code, parsed);
322
+ }
323
+ const arrayBuffer = await response.arrayBuffer();
324
+ const buffer = Buffer.from(arrayBuffer);
325
+ const cd = response.headers.get("Content-Disposition") || "";
326
+ const match = cd.match(/filename\*=UTF-8''([^;]+)/);
327
+ const fileName = match ? decodeURIComponent(match[1]) : null;
328
+ return { buffer, fileName };
329
+ }
285
330
  async function uploadToMainApp(path, formData) {
286
331
  const sandboxCred = tryLoadTeAgentSandboxCredentials();
287
332
  let baseUrl;
@@ -293,7 +338,7 @@ async function uploadToMainApp(path, formData) {
293
338
  "X-Sandbox-Secret-Key": sandboxCred.sandboxSecretKey
294
339
  };
295
340
  } else {
296
- const { getToken } = await import("./auth-IDPKDFSY.js");
341
+ const { getToken } = await import("./auth-MEJ642P4.js");
297
342
  baseUrl = (sandboxCred?.url || teClaudeBaseFromActiveHost() || "").replace(/\/$/, "");
298
343
  if (!baseUrl) {
299
344
  throw new TeAgentCredentialsError(
@@ -328,5 +373,7 @@ export {
328
373
  postSandboxSyncPull,
329
374
  deleteFromMainApp,
330
375
  patchToMainApp,
376
+ putToMainApp,
377
+ getBufferFromMainApp,
331
378
  uploadToMainApp
332
379
  };