@thinkingai/ae-cli 6.1.13 → 6.1.16

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 (110) hide show
  1. package/dist/{auth-GBMV6TEJ.js → auth-2WTQOP77.js} +3 -3
  2. package/dist/{auth-NDSXE54J.js → auth-77BUFLGC.js} +57 -13
  3. package/dist/{capability-TAMDRZYV.js → capability-72DTW5M2.js} +9 -9
  4. package/dist/{capability-U7TDEEEG.js → capability-PJHNI4GJ.js} +9 -9
  5. package/dist/{chunk-AFXA7BRK.js → chunk-4KVPKXFX.js} +5 -5
  6. package/dist/chunk-4SGZG4XY.js +311 -0
  7. package/dist/chunk-6EIJSNBD.js +8 -0
  8. package/dist/chunk-C4MGVGJW.js +13 -0
  9. package/dist/{chunk-WZRX4KOH.js → chunk-GT46FPXN.js} +4 -6
  10. package/dist/{chunk-5XUSIK27.js → chunk-ILIU36SU.js} +10 -7
  11. package/dist/{chunk-JHENBQ5B.js → chunk-LYVNONC4.js} +0 -35
  12. package/dist/{chunk-JUW4AJXN.js → chunk-P3FGXJTU.js} +12 -7
  13. package/dist/chunk-QGM4M3NI.js +37 -0
  14. package/dist/{chunk-753BUTNZ.js → chunk-RGKJGKT7.js} +2 -2
  15. package/dist/{chunk-UIHQJK5E.js → chunk-SAU3QFIQ.js} +3 -3
  16. package/dist/{chunk-VLWOLBGZ.js → chunk-UOUS37JQ.js} +149 -161
  17. package/dist/{chunk-AXDXJTPC.js → chunk-UW5UN47B.js} +19 -2
  18. package/dist/chunk-VPKZ7I72.js +509 -0
  19. package/dist/{chunk-QATA32VR.js → chunk-VR3LCBHW.js} +2 -2
  20. package/dist/{chunk-IBH3LDAH.js → chunk-YA6SMTXG.js} +3 -3
  21. package/dist/chunk-ZZUOD757.js +598 -0
  22. package/dist/{client-L2YDMHQ6.js → client-TKG4WBHN.js} +4 -5
  23. package/dist/{community-report-client-M2RW4MXD.js → community-report-client-FI4LNVYS.js} +3 -2
  24. package/dist/{config-OL2LWGBV.js → config-RE6CMGPK.js} +7 -7
  25. package/dist/data-integration-2MYMANJI.js +3383 -0
  26. package/dist/index.js +68 -34
  27. package/dist/local-data-upload-client-BWHSUQQK.js +167 -0
  28. package/dist/{memory-MUP7PPL7.js → memory-CHRU2F7W.js} +7 -6
  29. package/dist/{memory-U4O5PMXH.js → memory-YK33G4T7.js} +7 -6
  30. package/dist/{metadata-UORZTW3T.js → metadata-UILXHBWF.js} +22 -18
  31. package/dist/{metadata-VVQ3AQT5.js → metadata-XXR34N5P.js} +22 -18
  32. package/dist/{model-JTUEO5M4.js → model-K3KLWIW6.js} +7 -3
  33. package/dist/model-NR3JHFSJ.js +139 -0
  34. package/dist/{sync-MOSFNBVR.js → sync-DAVKYVMW.js} +8 -6
  35. package/dist/sync-FCKOVWWS.js +10261 -0
  36. package/dist/{te-agent-IFKZDHZI.js → te-agent-4BKBODMF.js} +686 -71
  37. package/dist/te-agent-HLW4VTQK.js +3893 -0
  38. package/dist/{te-analysis-KOKHJJPE.js → te-analysis-O6DCO6BS.js} +84 -61
  39. package/dist/{te-analysis-LLOCCBJ4.js → te-analysis-ZMNGOVNW.js} +84 -61
  40. package/dist/{te-community-HNKVTERD.js → te-community-6HPBWJUZ.js} +24 -19
  41. package/dist/{te-community-IWE5B7W6.js → te-community-HLC43QKH.js} +24 -20
  42. package/dist/{te-dataops-KXCEB4CS.js → te-dataops-EJP56W3K.js} +57 -34
  43. package/dist/{te-dataops-KQPYNAE3.js → te-dataops-HDRUXY4K.js} +59 -34
  44. package/dist/{te-engage-BRLSRVQT.js → te-engage-FGBGQ4IY.js} +398 -12
  45. package/dist/{te-engage-HE4OPZIT.js → te-engage-RAK5PESW.js} +398 -12
  46. package/dist/{te-experiment-K5US7RMG.js → te-experiment-SO5MPDMJ.js} +9 -8
  47. package/dist/{te-experiment-WA7TFMEL.js → te-experiment-VZF7BT6G.js} +9 -8
  48. package/dist/{te-kb-OIH3T6CS.js → te-kb-APXBWBDY.js} +6 -6
  49. package/dist/{te-system-AZ3URMUO.js → te-system-YARIK4S5.js} +7 -4
  50. package/dist/te-system-Z77IKZFN.js +2213 -0
  51. package/dist/{te-team-GZPU6UWA.js → te-team-EFKWYKMK.js} +7 -7
  52. package/dist/{update-TOBFXF2V.js → update-OGPSZM5A.js} +7 -7
  53. package/package.json +13 -3
  54. package/skills/ae-agent/SKILL.md +21 -11
  55. package/skills/ae-agent/references/approval-effect.md +44 -0
  56. package/skills/ae-agent/references/approval-request.md +46 -0
  57. package/skills/ae-agent/references/approval-task.md +45 -0
  58. package/skills/ae-agent/references/approval-type.md +32 -0
  59. package/skills/ae-agent/references/command_index.md +19 -0
  60. package/skills/ae-analysis/SKILL.md +11 -7
  61. package/skills/ae-analysis/references/adhoc_run.md +2 -0
  62. package/skills/ae-analysis/references/ai_models.md +31 -1
  63. package/skills/ae-analysis/references/alert_list.md +2 -3
  64. package/skills/ae-analysis/references/analysis_gateway_assets.md +8 -7
  65. package/skills/ae-analysis/references/bi_panel_list.md +2 -2
  66. package/skills/ae-analysis/references/command_index.md +18 -15
  67. package/skills/ae-analysis/references/dashboard_get.md +8 -2
  68. package/skills/ae-analysis/references/dashboard_list.md +2 -2
  69. package/skills/ae-analysis/references/dashboard_report_data_run.md +3 -1
  70. package/skills/ae-analysis/references/dashboard_update.md +4 -1
  71. package/skills/ae-analysis/references/favorite_add.md +2 -2
  72. package/skills/ae-analysis/references/favorite_remove.md +2 -2
  73. package/skills/ae-analysis/references/metric_create.md +7 -8
  74. package/skills/ae-analysis/references/project_space_business_filter_upsert.md +17 -0
  75. package/skills/ae-analysis/references/project_space_list.md +2 -2
  76. package/skills/ae-analysis/references/public_link_list.md +2 -2
  77. package/skills/ae-analysis/references/report_list.md +3 -3
  78. package/skills/ae-analysis/references/report_list_export.md +2 -2
  79. package/skills/ae-analysis/references/sql_table_list.md +3 -2
  80. package/skills/ae-analysis/references/user_cluster_update.md +4 -2
  81. package/skills/ae-analysis/references/user_tag_models.md +4 -4
  82. package/skills/ae-analysis/references/user_tag_update.md +4 -2
  83. package/skills/ae-analysis/references/virtual_property_sql_rule_update.md +3 -3
  84. package/skills/ae-data-integration/SKILL.md +54 -0
  85. package/skills/ae-data-integration/references/handoff.md +43 -0
  86. package/skills/ae-data-integration/references/local-analysis.md +27 -0
  87. package/skills/ae-data-integration/references/reuse.md +41 -0
  88. package/skills/ae-data-integration/references/sink-upload.md +58 -0
  89. package/skills/ae-data-integration/references/source-inspect.md +55 -0
  90. package/skills/ae-data-integration/references/sync-json-upload.md +60 -0
  91. package/skills/ae-data-integration/references/tracking-plan.md +35 -0
  92. package/skills/ae-data-integration/references/transform.md +65 -0
  93. package/skills/ae-data-integration/references/ue-mapping.md +142 -0
  94. package/skills/ae-data-integration/references/ue-routing.md +35 -0
  95. package/skills/ae-data-integration-helper/SKILL.md +1 -1
  96. package/skills/ae-dataops/SKILL.md +1 -1
  97. package/skills/ae-dataops/references/dataops-query.md +4 -4
  98. package/skills/ae-engage/SKILL.md +10 -2
  99. package/skills/ae-engage/references/flow-metric-user.md +2 -1
  100. package/skills/ae-engage/references/flow-node-metric-user.md +2 -1
  101. package/skills/ae-engage/references/flow-node-user.md +2 -1
  102. package/skills/ae-engage/references/task-indicator-user.md +104 -0
  103. package/skills/ae-engage/references/task-user-detail-export.md +31 -0
  104. package/skills/ae-generate-tracking-plan/SKILL.md +54 -3
  105. package/skills/ae-metadata/SKILL.md +0 -1
  106. package/skills/ae-metadata/references/metadata_property_dimension_table_bind_existing.md +1 -1
  107. package/dist/chunk-3FY3RJ26.js +0 -293
  108. package/dist/chunk-S5NTSDBS.js +0 -198
  109. package/dist/chunk-ZQKDZXDO.js +0 -317
  110. package/dist/cli-token-4UPER74P.js +0 -21
@@ -1,35 +1,3 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
- }) : x)(function(x) {
10
- if (typeof require !== "undefined") return require.apply(this, arguments);
11
- throw Error('Dynamic require of "' + x + '" is not supported');
12
- });
13
- var __commonJS = (cb, mod) => function __require2() {
14
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
- };
16
- var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === "object" || typeof from === "function") {
18
- for (let key of __getOwnPropNames(from))
19
- if (!__hasOwnProp.call(to, key) && key !== except)
20
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
- }
22
- return to;
23
- };
24
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
- // If the importer is in node compatibility mode or this is not an ESM
26
- // file that has been converted to a CommonJS file using a Babel-
27
- // compatible transform (i.e. "__esModule" has not been set), then set
28
- // "default" to the CommonJS "module.exports" for node compatibility.
29
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
- mod
31
- ));
32
-
33
1
  // src/core/logger.ts
34
2
  import fs from "fs";
35
3
  import path from "path";
@@ -114,8 +82,5 @@ var Logger = class {
114
82
  var logger = new Logger();
115
83
 
116
84
  export {
117
- __require,
118
- __commonJS,
119
- __toESM,
120
85
  logger
121
86
  };
@@ -1,16 +1,19 @@
1
+ import {
2
+ internalCallSourceHeaders
3
+ } from "./chunk-C4MGVGJW.js";
1
4
  import {
2
5
  clearCliToken,
3
6
  getCliToken
4
- } from "./chunk-S5NTSDBS.js";
7
+ } from "./chunk-4SGZG4XY.js";
5
8
  import {
6
9
  safeJsonParse
7
- } from "./chunk-3FY3RJ26.js";
10
+ } from "./chunk-ZZUOD757.js";
8
11
  import {
9
12
  PermissionError
10
- } from "./chunk-AXDXJTPC.js";
13
+ } from "./chunk-UW5UN47B.js";
11
14
  import {
12
15
  logger
13
- } from "./chunk-JHENBQ5B.js";
16
+ } from "./chunk-LYVNONC4.js";
14
17
 
15
18
  // src/core/capability-api.ts
16
19
  import { readFile } from "fs/promises";
@@ -136,7 +139,8 @@ async function throwCapabilityHttpError(resp) {
136
139
  async function requestOnce(url, method, token, body, accept = "application/json") {
137
140
  const headers = {
138
141
  "cli-token": token,
139
- "Accept": accept
142
+ "Accept": accept,
143
+ ...internalCallSourceHeaders()
140
144
  };
141
145
  const init = { method, headers };
142
146
  if (body !== void 0 && method !== "GET") {
@@ -150,7 +154,8 @@ async function requestMultipartOnce(url, token, form) {
150
154
  method: "POST",
151
155
  headers: {
152
156
  "cli-token": token,
153
- "Accept": "application/json"
157
+ "Accept": "application/json",
158
+ ...internalCallSourceHeaders()
154
159
  },
155
160
  body: form
156
161
  });
@@ -166,7 +171,7 @@ async function callGatewayWithEnvelope(host, domain, pathAfterV1, method, body,
166
171
  if (resp.status === 403) {
167
172
  const error = await permissionError(resp);
168
173
  permissionMsg = error.message;
169
- if (!isInvalidCliTokenMessage(permissionMsg)) {
174
+ if (options.retryOnInvalidTokenForbidden === false || !isInvalidCliTokenMessage(permissionMsg)) {
170
175
  throw error;
171
176
  }
172
177
  }
@@ -0,0 +1,37 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
11
+ throw Error('Dynamic require of "' + x + '" is not supported');
12
+ });
13
+ var __commonJS = (cb, mod) => function __require2() {
14
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
29
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
+ mod
31
+ ));
32
+
33
+ export {
34
+ __require,
35
+ __commonJS,
36
+ __toESM
37
+ };
@@ -3,12 +3,12 @@ import {
3
3
  } from "./chunk-PTE56QPL.js";
4
4
  import {
5
5
  withOutputMetadata
6
- } from "./chunk-WZRX4KOH.js";
6
+ } from "./chunk-GT46FPXN.js";
7
7
  import {
8
8
  dryRunCapability,
9
9
  executeCapabilityWithEnvelope,
10
10
  validateCapability
11
- } from "./chunk-5XUSIK27.js";
11
+ } from "./chunk-P3FGXJTU.js";
12
12
 
13
13
  // src/core/capability-command.ts
14
14
  import { randomBytes } from "crypto";
@@ -5,15 +5,15 @@ import {
5
5
  readOutputMetadata,
6
6
  unwrapOutputData,
7
7
  withOutputMetadata
8
- } from "./chunk-WZRX4KOH.js";
8
+ } from "./chunk-GT46FPXN.js";
9
9
  import {
10
10
  CapabilityGatewayError,
11
11
  fetchCapabilityGateway,
12
12
  requestCapabilityGateway
13
- } from "./chunk-5XUSIK27.js";
13
+ } from "./chunk-P3FGXJTU.js";
14
14
  import {
15
15
  PermissionError
16
- } from "./chunk-AXDXJTPC.js";
16
+ } from "./chunk-UW5UN47B.js";
17
17
 
18
18
  // src/core/analysis-async-artifact.ts
19
19
  import { randomBytes } from "crypto";
@@ -1,7 +1,17 @@
1
+ import {
2
+ internalCallSourceHeaders
3
+ } from "./chunk-C4MGVGJW.js";
4
+ import {
5
+ clearCliToken,
6
+ getCliToken
7
+ } from "./chunk-4SGZG4XY.js";
1
8
  import {
2
9
  getActiveHost,
3
10
  getSandboxRuntimeRoot
4
- } from "./chunk-3FY3RJ26.js";
11
+ } from "./chunk-ZZUOD757.js";
12
+ import {
13
+ PermissionError
14
+ } from "./chunk-UW5UN47B.js";
5
15
 
6
16
  // src/core/te-agent-credentials.ts
7
17
  import { readFileSync } from "fs";
@@ -120,13 +130,40 @@ async function fetchWithTimeout(url, init, timeoutMs = DEFAULT_TIMEOUT_MS) {
120
130
  return await fetch(url, { ...init, signal: controller.signal });
121
131
  } catch (err) {
122
132
  if (err?.name === "AbortError") {
123
- throw new TeAgentApiError(`Request timed out (${timeoutMs}ms): ${url}`, 0, "TIMEOUT");
133
+ throw new TeAgentApiError(
134
+ `Request timed out (${timeoutMs}ms) for ${safeRequestOrigin(url)}`,
135
+ 0,
136
+ "TIMEOUT"
137
+ );
124
138
  }
125
- throw new TeAgentApiError(`Network request failed: ${err?.message ?? err}`, 0, "NETWORK_ERROR");
139
+ throw networkRequestError(url, err);
126
140
  } finally {
127
141
  clearTimeout(timer);
128
142
  }
129
143
  }
144
+ function safeRequestOrigin(url) {
145
+ try {
146
+ return new URL(url).origin;
147
+ } catch {
148
+ return "the configured service";
149
+ }
150
+ }
151
+ function networkRequestError(url, error) {
152
+ const nestedCause = error && typeof error === "object" && "cause" in error ? error.cause : void 0;
153
+ const root = nestedCause ?? error;
154
+ const detail = root && typeof root === "object" ? root : {};
155
+ const code = typeof detail.code === "string" ? detail.code : void 0;
156
+ const address = typeof detail.address === "string" ? detail.address : typeof detail.hostname === "string" ? detail.hostname : void 0;
157
+ const port = typeof detail.port === "number" || typeof detail.port === "string" ? String(detail.port) : void 0;
158
+ const endpoint = address ? `${address}${port ? `:${port}` : ""}` : void 0;
159
+ const cause = [code, endpoint].filter(Boolean).join(" ");
160
+ const suffix = cause ? ` (${cause})` : "";
161
+ return new TeAgentApiError(
162
+ `Network request failed for ${safeRequestOrigin(url)}${suffix}`,
163
+ 0,
164
+ "NETWORK_ERROR"
165
+ );
166
+ }
130
167
  function teClaudeBaseFromActiveHost(hostOverride) {
131
168
  const override = hostOverride ? void 0 : process.env.TE_CLAUDE_BASE_URL;
132
169
  if (override) return override.replace(/\/+$/, "");
@@ -136,24 +173,22 @@ function teClaudeBaseFromActiveHost(hostOverride) {
136
173
  const bp = process.env.TE_CLAUDE_BASE_PATH || "/agent";
137
174
  return base.endsWith(bp) ? base : base + bp;
138
175
  }
139
- async function signRequest(method, path2, rawBody, hostOverride) {
176
+ async function signRequest(method, path2, hostOverride, includeJsonContentType = true) {
140
177
  const sandboxCred = tryLoadTeAgentSandboxCredentials();
141
178
  if (!hostOverride && sandboxCred && sandboxCred.sandboxId && sandboxCred.sandboxSecretKey) {
142
179
  const headers = {
143
180
  "X-Sandbox-Id": sandboxCred.sandboxId,
144
181
  "X-Sandbox-Secret-Key": sandboxCred.sandboxSecretKey
145
182
  };
146
- if (method === "POST" || method === "PATCH" || method === "PUT") {
183
+ if (includeJsonContentType && (method === "POST" || method === "PATCH" || method === "PUT")) {
147
184
  headers["Content-Type"] = "application/json";
148
185
  }
149
186
  return {
150
187
  url: `${sandboxCred.url.replace(/\/$/, "")}${path2}`,
151
188
  headers,
152
- rawBody
189
+ authKind: "sandbox"
153
190
  };
154
191
  }
155
- const { getToken } = await import("./auth-GBMV6TEJ.js");
156
- const { getCliToken } = await import("./cli-token-4UPER74P.js");
157
192
  const baseUrl = hostOverride ? teClaudeBaseFromActiveHost(hostOverride) : sandboxCred?.url || teClaudeBaseFromActiveHost();
158
193
  if (!baseUrl) {
159
194
  throw new TeAgentCredentialsError(
@@ -162,43 +197,54 @@ async function signRequest(method, path2, rawBody, hostOverride) {
162
197
  );
163
198
  }
164
199
  const hostForToken = hostOverride || getActiveHost() || baseUrl;
165
- const contentTypeHeader = method === "POST" || method === "PATCH" || method === "PUT" ? { "Content-Type": "application/json" } : {};
166
- let accessToken = null;
167
- try {
168
- accessToken = await getToken(hostForToken);
169
- } catch {
170
- accessToken = null;
171
- }
172
- if (accessToken) {
173
- return {
174
- url: `${baseUrl.replace(/\/$/, "")}${path2}`,
175
- headers: {
176
- "Authorization": `bearer ${accessToken}`,
177
- ...contentTypeHeader
178
- },
179
- rawBody
180
- };
181
- }
182
- let cliToken = null;
183
- try {
184
- cliToken = await getCliToken(hostForToken);
185
- } catch {
186
- cliToken = null;
187
- }
188
- if (cliToken) {
189
- return {
190
- url: `${baseUrl.replace(/\/$/, "")}${path2}`,
191
- headers: {
192
- "cli-token": cliToken,
193
- ...contentTypeHeader
194
- },
195
- rawBody
196
- };
197
- }
198
- throw new TeAgentCredentialsError(
199
- "No te-claude credentials available",
200
- "Run ae-cli auth login, or execute inside a te-agent sandbox"
200
+ const contentTypeHeader = includeJsonContentType && (method === "POST" || method === "PATCH" || method === "PUT") ? { "Content-Type": "application/json" } : {};
201
+ const cliToken = await getCliToken(hostForToken);
202
+ return {
203
+ url: `${baseUrl.replace(/\/$/, "")}${path2}`,
204
+ headers: {
205
+ "cli-token": cliToken,
206
+ ...internalCallSourceHeaders(),
207
+ ...contentTypeHeader
208
+ },
209
+ authKind: "cli-token",
210
+ tokenHost: hostForToken
211
+ };
212
+ }
213
+ async function fetchSignedWithRetry(options) {
214
+ let signed = await signRequest(
215
+ options.method,
216
+ options.path,
217
+ options.hostOverride,
218
+ options.includeJsonContentType
219
+ );
220
+ const request = (requestToSend) => fetchWithTimeout(
221
+ requestToSend.url,
222
+ {
223
+ method: options.method,
224
+ headers: requestToSend.headers,
225
+ body: options.body
226
+ },
227
+ options.timeoutMs
201
228
  );
229
+ let response = await request(signed);
230
+ if (response.status === 401 && signed.authKind === "cli-token" && signed.tokenHost) {
231
+ clearCliToken(signed.tokenHost);
232
+ signed = await signRequest(
233
+ options.method,
234
+ options.path,
235
+ options.hostOverride,
236
+ options.includeJsonContentType
237
+ );
238
+ response = await request(signed);
239
+ }
240
+ return response;
241
+ }
242
+ function errorDetails(parsed, defaultErrorPrefix, status) {
243
+ const nested = parsed && typeof parsed === "object" && parsed.error && typeof parsed.error === "object" ? parsed.error : parsed;
244
+ const message = typeof parsed?.error === "string" ? parsed.error : typeof nested?.message === "string" ? nested.message : typeof parsed?.message === "string" ? parsed.message : typeof parsed?.return_message === "string" ? parsed.return_message : `${defaultErrorPrefix} ${status}`;
245
+ const code = typeof nested?.code === "string" ? nested.code : typeof parsed?.code === "string" ? parsed.code : void 0;
246
+ const hint = typeof nested?.hint === "string" ? nested.hint : typeof parsed?.hint === "string" ? parsed.hint : void 0;
247
+ return { message, code, hint };
202
248
  }
203
249
  async function parseResponse(response, defaultErrorPrefix) {
204
250
  const text = await response.text();
@@ -211,35 +257,37 @@ async function parseResponse(response, defaultErrorPrefix) {
211
257
  }
212
258
  }
213
259
  if (!response.ok) {
260
+ const details = errorDetails(parsed, defaultErrorPrefix, response.status);
261
+ if (response.status === 403) {
262
+ throw new PermissionError(details.message, details.code, details.hint);
263
+ }
214
264
  if (response.status === 401) {
215
265
  throw new TeAgentApiError(
216
- `Session expired or unauthorized. Please run: ae-cli auth login`,
266
+ "Session expired or unauthorized. Please run: ae-cli auth login",
217
267
  response.status,
218
268
  "auth_expired",
219
269
  parsed
220
270
  );
221
271
  }
222
- const message = typeof parsed === "object" && parsed && typeof parsed.error === "string" ? parsed.error : `${defaultErrorPrefix} ${response.status}`;
223
- const code = typeof parsed === "object" && parsed && typeof parsed.code === "string" ? parsed.code : void 0;
224
- throw new TeAgentApiError(message, response.status, code, parsed);
272
+ throw new TeAgentApiError(details.message, response.status, details.code, parsed);
225
273
  }
226
274
  return parsed;
227
275
  }
228
276
  async function postToMainApp(path2, body, hostOverride) {
229
277
  const rawBody = JSON.stringify(body);
230
- const signed = await signRequest("POST", path2, rawBody, hostOverride);
231
- const response = await fetchWithTimeout(signed.url, {
278
+ const response = await fetchSignedWithRetry({
232
279
  method: "POST",
233
- headers: signed.headers,
234
- body: signed.rawBody
280
+ path: path2,
281
+ body: rawBody,
282
+ hostOverride
235
283
  });
236
284
  return parseResponse(response, "Main app returned");
237
285
  }
238
286
  async function getFromMainApp(path2, hostOverride) {
239
- const signed = await signRequest("GET", path2, "", hostOverride);
240
- const response = await fetchWithTimeout(signed.url, {
287
+ const response = await fetchSignedWithRetry({
241
288
  method: "GET",
242
- headers: signed.headers
289
+ path: path2,
290
+ hostOverride
243
291
  });
244
292
  return parseResponse(response, "Main app returned");
245
293
  }
@@ -270,60 +318,41 @@ async function postSandboxSyncPull(args) {
270
318
  });
271
319
  }
272
320
  async function deleteFromMainApp(path2, hostOverride) {
273
- const signed = await signRequest("DELETE", path2, "", hostOverride);
274
- const response = await fetchWithTimeout(signed.url, {
321
+ const response = await fetchSignedWithRetry({
275
322
  method: "DELETE",
276
- headers: signed.headers
323
+ path: path2,
324
+ hostOverride
277
325
  });
278
326
  return parseResponse(response, "Main app returned");
279
327
  }
280
328
  async function patchToMainApp(path2, body, hostOverride) {
281
329
  const rawBody = JSON.stringify(body);
282
- const signed = await signRequest("PATCH", path2, rawBody, hostOverride);
283
- const response = await fetchWithTimeout(signed.url, {
330
+ const response = await fetchSignedWithRetry({
284
331
  method: "PATCH",
285
- headers: signed.headers,
286
- body: signed.rawBody
332
+ path: path2,
333
+ body: rawBody,
334
+ hostOverride
287
335
  });
288
336
  return parseResponse(response, "Main app returned");
289
337
  }
290
338
  async function putToMainApp(path2, body, hostOverride) {
291
339
  const rawBody = JSON.stringify(body);
292
- const signed = await signRequest("PUT", path2, rawBody, hostOverride);
293
- const response = await fetchWithTimeout(signed.url, {
340
+ const response = await fetchSignedWithRetry({
294
341
  method: "PUT",
295
- headers: signed.headers,
296
- body: signed.rawBody
342
+ path: path2,
343
+ body: rawBody,
344
+ hostOverride
297
345
  });
298
346
  return parseResponse(response, "Main app returned");
299
347
  }
300
348
  async function getBufferFromMainApp(path2, hostOverride) {
301
- const signed = await signRequest("GET", path2, "", hostOverride);
302
- const response = await fetchWithTimeout(signed.url, {
349
+ const response = await fetchSignedWithRetry({
303
350
  method: "GET",
304
- headers: signed.headers
351
+ path: path2,
352
+ hostOverride
305
353
  });
306
354
  if (!response.ok) {
307
- const text = await response.text();
308
- let parsed = void 0;
309
- if (text) {
310
- try {
311
- parsed = JSON.parse(text);
312
- } catch {
313
- parsed = text;
314
- }
315
- }
316
- if (response.status === 401) {
317
- throw new TeAgentApiError(
318
- "Session expired or unauthorized. Please run: ae-cli auth login",
319
- response.status,
320
- "auth_expired",
321
- parsed
322
- );
323
- }
324
- const message = typeof parsed === "object" && parsed && typeof parsed.error === "string" ? parsed.error : `Main app returned ${response.status}`;
325
- const code = typeof parsed === "object" && parsed && typeof parsed.code === "string" ? parsed.code : void 0;
326
- throw new TeAgentApiError(message, response.status, code, parsed);
355
+ await parseResponse(response, "Main app returned");
327
356
  }
328
357
  const arrayBuffer = await response.arrayBuffer();
329
358
  const buffer = Buffer.from(arrayBuffer);
@@ -381,27 +410,31 @@ async function downloadFromMainApp(requestPath, outputPath, hostOverride) {
381
410
  "OUTPUT_ERROR"
382
411
  );
383
412
  }
384
- const signed = await signRequest("GET", requestPath, "", hostOverride);
413
+ let signed = await signRequest("GET", requestPath, hostOverride);
385
414
  let response;
386
- try {
387
- response = await fetch(signed.url, {
388
- method: "GET",
389
- headers: signed.headers,
390
- signal: controller.signal
391
- });
392
- } catch (error) {
393
- if (error?.name === "AbortError") {
394
- throw new TeAgentApiError(
395
- `Request timed out (${DOWNLOAD_TIMEOUT_MS}ms): ${signed.url}`,
396
- 0,
397
- "TIMEOUT"
398
- );
415
+ const request = async (requestToSend) => {
416
+ try {
417
+ return await fetch(requestToSend.url, {
418
+ method: "GET",
419
+ headers: requestToSend.headers,
420
+ signal: controller.signal
421
+ });
422
+ } catch (error) {
423
+ if (error?.name === "AbortError") {
424
+ throw new TeAgentApiError(
425
+ `Request timed out (${DOWNLOAD_TIMEOUT_MS}ms) for ${safeRequestOrigin(requestToSend.url)}`,
426
+ 0,
427
+ "TIMEOUT"
428
+ );
429
+ }
430
+ throw networkRequestError(requestToSend.url, error);
399
431
  }
400
- throw new TeAgentApiError(
401
- `Network request failed: ${error instanceof Error ? error.message : String(error)}`,
402
- 0,
403
- "NETWORK_ERROR"
404
- );
432
+ };
433
+ response = await request(signed);
434
+ if (response.status === 401 && signed.authKind === "cli-token" && signed.tokenHost) {
435
+ clearCliToken(signed.tokenHost);
436
+ signed = await signRequest("GET", requestPath, hostOverride);
437
+ response = await request(signed);
405
438
  }
406
439
  if (!response.ok) {
407
440
  await parseResponse(response, "Main app returned");
@@ -445,59 +478,14 @@ async function downloadFromMainApp(requestPath, outputPath, hostOverride) {
445
478
  }
446
479
  }
447
480
  async function uploadToMainApp(path2, formData, hostOverride) {
448
- const sandboxCred = tryLoadTeAgentSandboxCredentials();
449
- let baseUrl;
450
- let authHeaders;
451
- if (!hostOverride && sandboxCred && sandboxCred.sandboxId && sandboxCred.sandboxSecretKey) {
452
- baseUrl = sandboxCred.url.replace(/\/$/, "");
453
- authHeaders = {
454
- "X-Sandbox-Id": sandboxCred.sandboxId,
455
- "X-Sandbox-Secret-Key": sandboxCred.sandboxSecretKey
456
- };
457
- } else {
458
- const { getToken } = await import("./auth-GBMV6TEJ.js");
459
- const { getCliToken } = await import("./cli-token-4UPER74P.js");
460
- baseUrl = (hostOverride ? teClaudeBaseFromActiveHost(hostOverride) : sandboxCred?.url || teClaudeBaseFromActiveHost())?.replace(/\/$/, "") || "";
461
- if (!baseUrl) {
462
- throw new TeAgentCredentialsError(
463
- "Cannot determine the te-claude service URL",
464
- "Run ae-cli config set-host <url> to configure the service URL, or execute inside a te-agent sandbox"
465
- );
466
- }
467
- const hostForToken = hostOverride || getActiveHost() || baseUrl;
468
- let accessToken = null;
469
- try {
470
- accessToken = await getToken(hostForToken);
471
- } catch {
472
- accessToken = null;
473
- }
474
- if (accessToken) {
475
- authHeaders = { "Authorization": `bearer ${accessToken}` };
476
- } else {
477
- let cliToken = null;
478
- try {
479
- cliToken = await getCliToken(hostForToken);
480
- } catch {
481
- cliToken = null;
482
- }
483
- if (!cliToken) {
484
- throw new TeAgentCredentialsError(
485
- "No te-claude credentials available",
486
- "Run ae-cli auth login, or execute inside a te-agent sandbox"
487
- );
488
- }
489
- authHeaders = { "cli-token": cliToken };
490
- }
491
- }
492
- const response = await fetchWithTimeout(
493
- `${baseUrl}${path2}`,
494
- {
495
- method: "POST",
496
- headers: authHeaders,
497
- body: formData
498
- },
499
- UPLOAD_TIMEOUT_MS
500
- );
481
+ const response = await fetchSignedWithRetry({
482
+ method: "POST",
483
+ path: path2,
484
+ body: formData,
485
+ hostOverride,
486
+ includeJsonContentType: false,
487
+ timeoutMs: UPLOAD_TIMEOUT_MS
488
+ });
501
489
  return parseResponse(response, "Upload failed");
502
490
  }
503
491
 
@@ -1,11 +1,13 @@
1
1
  // src/core/errors.ts
2
2
  var PermissionError = class extends Error {
3
- constructor(message, code) {
3
+ constructor(message, code, hint) {
4
4
  super(message);
5
5
  this.code = code;
6
+ this.hint = hint;
6
7
  this.name = "PermissionError";
7
8
  }
8
9
  code;
10
+ hint;
9
11
  };
10
12
  var CliValidationError = class extends Error {
11
13
  code;
@@ -45,9 +47,24 @@ var CommunityReportError = class extends Error {
45
47
  this.meta = options.meta;
46
48
  }
47
49
  };
50
+ var LocalDataUploadError = class extends Error {
51
+ code;
52
+ httpStatus;
53
+ hint;
54
+ meta;
55
+ constructor(message, options = {}) {
56
+ super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
57
+ this.name = "LocalDataUploadError";
58
+ this.code = options.code;
59
+ this.httpStatus = options.httpStatus;
60
+ this.hint = options.hint;
61
+ this.meta = options.meta;
62
+ }
63
+ };
48
64
 
49
65
  export {
50
66
  PermissionError,
51
67
  CliValidationError,
52
- CommunityReportError
68
+ CommunityReportError,
69
+ LocalDataUploadError
53
70
  };