@thinkingai/ae-cli 6.0.46 → 6.0.47

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 (89) hide show
  1. package/README.md +2 -0
  2. package/README.zh.md +6 -0
  3. package/dist/{auth-ROB2EDYV.js → auth-QPEVVBKT.js} +13 -7
  4. package/dist/auth-UMJAA72O.js +15 -0
  5. package/dist/{capability-GQ47BCFI.js → capability-RUSV77CO.js} +11 -10
  6. package/dist/{chunk-UW5UN47B.js → chunk-533JK3YX.js} +2 -0
  7. package/dist/{chunk-4XXOWOTA.js → chunk-6QK7SYYY.js} +5 -4
  8. package/dist/{chunk-TUKQZTMI.js → chunk-7K24F7T2.js} +2 -0
  9. package/dist/{chunk-OO6XR6LK.js → chunk-AMBFK2K3.js} +2 -0
  10. package/dist/{sync-HKIOZXQE.js → chunk-B5HMQAOM.js} +31 -540
  11. package/dist/{chunk-DQRPU6EE.js → chunk-BVDST5YT.js} +5 -4
  12. package/dist/{chunk-VTWMIC5L.js → chunk-E2JKXMVO.js} +2 -0
  13. package/dist/{chunk-JHENBQ5B.js → chunk-FR2EDAQM.js} +1 -0
  14. package/dist/{chunk-ZQ47LWTI.js → chunk-GJXRF7Y6.js} +6 -5
  15. package/dist/{chunk-DWO43OIB.js → chunk-JQ3ENZZH.js} +2 -0
  16. package/dist/chunk-JYMGHGCE.js +191 -0
  17. package/dist/{chunk-BYYS3ANB.js → chunk-KEWVSO64.js} +5 -4
  18. package/dist/{chunk-3FY3RJ26.js → chunk-KZ6ZHF5J.js} +2 -1
  19. package/dist/{chunk-2MN54X6H.js → chunk-NSIVXKJH.js} +4 -3
  20. package/dist/{chunk-ZQKDZXDO.js → chunk-O6K2ODUE.js} +3 -2
  21. package/dist/chunk-QL6R6TSK.js +25215 -0
  22. package/dist/{chunk-J2DEBMRF.js → chunk-RWXIXOZG.js} +22 -9
  23. package/dist/{chunk-4NN5IWVN.js → chunk-T6OSFQZD.js} +2 -0
  24. package/dist/{chunk-3KWQYGYI.js → chunk-TKHSULJT.js} +2 -0
  25. package/dist/{chunk-6EIJSNBD.js → chunk-Y74WTIKJ.js} +2 -0
  26. package/dist/{client-L2YDMHQ6.js → client-N7NGZUNI.js} +4 -3
  27. package/dist/{community-report-client-C7WDGET3.js → community-report-client-6OL6GBQW.js} +3 -2
  28. package/dist/{config-BMYZX2UE.js → config-XNMACCKX.js} +8 -7
  29. package/dist/{data-integration-QEKDWQDY.js → data-integration-4NZGZ45E.js} +913 -92
  30. package/dist/index.js +36 -34
  31. package/dist/{local-data-upload-client-4YYHSYD6.js → local-data-upload-client-EFHDLXFG.js} +3 -2
  32. package/dist/{memory-3ORCR7JH.js → memory-HBJQ2GC5.js} +8 -7
  33. package/dist/{metadata-A6QLH3IS.js → metadata-PGDJE5RQ.js} +12 -11
  34. package/dist/{model-UGRDX4MW.js → model-BHLJ2QMT.js} +10 -9
  35. package/dist/{personal-semantic-preference-QZFAJWGE.js → personal-semantic-preference-E5NZ56DN.js} +11 -10
  36. package/dist/sync-MUWPRM5I.js +522 -0
  37. package/dist/{te-agent-BR6VDBNX.js → te-agent-WQZTMEK4.js} +10 -9
  38. package/dist/{te-analysis-MUKUXJL4.js → te-analysis-YWCSSLYL.js} +107 -20
  39. package/dist/{te-community-ISDQWJU7.js → te-community-BNE6KREL.js} +8 -7
  40. package/dist/{te-dataops-6P5IKWNJ.js → te-dataops-TXLKM2W6.js} +467 -67
  41. package/dist/{te-engage-ELA3C5BM.js → te-engage-VEW4CJHK.js} +26 -10
  42. package/dist/{te-kb-RCLSSH2Q.js → te-kb-BUD6N3NI.js} +311 -24
  43. package/dist/{te-system-FXITO2JG.js → te-system-44LZJDTQ.js} +573 -37
  44. package/dist/{te-team-ADOC2ROP.js → te-team-XMP47YXE.js} +10 -7
  45. package/dist/{update-YCYCKJOO.js → update-UODFOZ4P.js} +7 -6
  46. package/package.json +18 -9
  47. package/skills/ae-analysis/references/analysis_gateway_assets.md +1 -1
  48. package/skills/ae-analysis/references/audience_models.md +18 -0
  49. package/skills/ae-analysis/references/command_index.md +2 -2
  50. package/skills/ae-analysis/references/project_timezone_update.md +13 -4
  51. package/skills/ae-analysis/references/property_create.md +2 -0
  52. package/skills/ae-analysis/references/super_metadata_batch_create.md +2 -0
  53. package/skills/ae-analysis/references/user_cluster_models.md +2 -0
  54. package/skills/ae-analysis/references/user_cluster_update.md +8 -4
  55. package/skills/ae-analysis/references/user_tag_create.md +7 -1
  56. package/skills/ae-analysis/references/user_tag_models.md +8 -2
  57. package/skills/ae-data-integration/SKILL.md +1 -0
  58. package/skills/ae-data-integration/references/error-handling.md +54 -1
  59. package/skills/ae-data-integration/references/source-inspect.md +18 -2
  60. package/skills/ae-data-integration/references/transform.md +3 -1
  61. package/skills/ae-data-integration/references/ue-routing.md +23 -0
  62. package/skills/ae-dataops/SKILL.md +11 -1
  63. package/skills/ae-dataops/references/dataops-backfill.md +135 -0
  64. package/skills/ae-engage/SKILL.md +3 -0
  65. package/skills/ae-engage/references/build-task-save-guide.md +5 -1
  66. package/skills/ae-engage/references/save-task.md +6 -0
  67. package/skills/ae-kb/SKILL.md +120 -9
  68. package/skills/ae-system/SKILL.md +28 -30
  69. package/skills/ae-system/references/channel-management.md +303 -0
  70. package/dist/auth-GBMV6TEJ.js +0 -14
  71. package/dist/capability-IINANQJA.js +0 -349
  72. package/dist/chunk-GJLGIMAO.js +0 -556
  73. package/dist/chunk-OMPRXM3V.js +0 -349
  74. package/dist/chunk-QNOLN2LJ.js +0 -509
  75. package/dist/chunk-RJDU7NYP.js +0 -1198
  76. package/dist/chunk-RNAALWJK.js +0 -98
  77. package/dist/chunk-SERWF6G5.js +0 -13
  78. package/dist/chunk-XNVMVIUI.js +0 -71
  79. package/dist/memory-I2WXDTV2.js +0 -893
  80. package/dist/metadata-HC7GBTTD.js +0 -339
  81. package/dist/model-HLHIEFMU.js +0 -139
  82. package/dist/personal-semantic-preference-YXAZBFVW.js +0 -239
  83. package/dist/sync-TFHU2UTG.js +0 -10261
  84. package/dist/te-agent-VLYOV7S4.js +0 -3894
  85. package/dist/te-analysis-JECYCV6K.js +0 -9357
  86. package/dist/te-community-5DMNKJWY.js +0 -1859
  87. package/dist/te-dataops-CVULXNVB.js +0 -2209
  88. package/dist/te-engage-MC5IQZIU.js +0 -4898
  89. package/dist/te-system-K2GYMCTB.js +0 -2213
@@ -1,509 +0,0 @@
1
- import {
2
- internalCallSourceHeaders
3
- } from "./chunk-6EIJSNBD.js";
4
- import {
5
- clearCliToken,
6
- getCliToken
7
- } from "./chunk-J2DEBMRF.js";
8
- import {
9
- getActiveHost,
10
- getSandboxRuntimeRoot
11
- } from "./chunk-3FY3RJ26.js";
12
- import {
13
- PermissionError
14
- } from "./chunk-UW5UN47B.js";
15
-
16
- // src/core/te-agent-credentials.ts
17
- import { readFileSync } from "fs";
18
- import { homedir } from "os";
19
- import { join } from "path";
20
- function getCredentialsPath() {
21
- return join(process.env.HOME || homedir(), ".te-agent", "credentials.json");
22
- }
23
- function getPersistentEnvPath() {
24
- return join(getSandboxRuntimeRoot(), ".env");
25
- }
26
- function parseDotEnv(raw) {
27
- const result = {};
28
- for (const line of raw.split("\n")) {
29
- if (/^\s*#/.test(line) || line.trim() === "") continue;
30
- const match = /^\s*([^=]+)=(.*)$/.exec(line);
31
- if (!match) continue;
32
- const key = match[1].trim();
33
- let value = match[2].trim();
34
- if (value.startsWith('"') && value.endsWith('"')) {
35
- value = value.slice(1, -1).replace(/\\"/g, '"');
36
- }
37
- if (value !== "") result[key] = value;
38
- }
39
- return result;
40
- }
41
- function readPersistentEnv() {
42
- const envPath = getPersistentEnvPath();
43
- try {
44
- const raw = readFileSync(envPath, "utf8");
45
- return parseDotEnv(raw);
46
- } catch (err) {
47
- if (err?.code === "ENOENT") return null;
48
- throw new TeAgentCredentialsError(
49
- `Failed to read ${envPath}: ${err?.message ?? err}`,
50
- "Check file permissions, or inject runtime credentials via TE_CLAUDE_BASE_URL / SANDBOX_ID / SECRET_KEY"
51
- );
52
- }
53
- }
54
- var TeAgentCredentialsError = class extends Error {
55
- constructor(message, hint) {
56
- super(message);
57
- this.hint = hint;
58
- this.name = "TeAgentCredentialsError";
59
- }
60
- hint;
61
- };
62
- function readLegacyCredentials() {
63
- const credPath = getCredentialsPath();
64
- try {
65
- const raw = readFileSync(credPath, "utf8");
66
- const parsed = JSON.parse(raw);
67
- const main = parsed?.mainApp;
68
- return main && typeof main === "object" ? main : null;
69
- } catch (err) {
70
- if (err?.code === "ENOENT") return null;
71
- if (err instanceof SyntaxError) {
72
- throw new TeAgentCredentialsError(
73
- `Failed to parse ${credPath}: ${err.message}`,
74
- "The credentials file may be corrupted; alternatively inject runtime credentials via TE_CLAUDE_BASE_URL / SANDBOX_ID / SECRET_KEY"
75
- );
76
- }
77
- throw new TeAgentCredentialsError(
78
- `Failed to read ${credPath}: ${err?.message ?? err}`,
79
- "Check file permissions, or inject runtime credentials via TE_CLAUDE_BASE_URL / SANDBOX_ID / SECRET_KEY"
80
- );
81
- }
82
- }
83
- function tryLoadTeAgentSandboxCredentials() {
84
- const legacy = readLegacyCredentials();
85
- const persistent = readPersistentEnv();
86
- const url = process.env.TE_CLAUDE_BASE_URL || persistent?.TE_CLAUDE_BASE_URL || legacy?.url;
87
- if (typeof url !== "string" || !url) {
88
- return null;
89
- }
90
- const sandboxId = process.env.SANDBOX_ID || persistent?.SANDBOX_ID || legacy?.sandboxId || null;
91
- const sandboxSecretKey = process.env.SECRET_KEY || process.env.SANDBOX_SECRET_KEY || persistent?.SECRET_KEY || persistent?.SANDBOX_SECRET_KEY || legacy?.sandboxSecretKey || legacy?.secretKey || null;
92
- return {
93
- url,
94
- sandboxId: typeof sandboxId === "string" ? sandboxId : null,
95
- sandboxSecretKey: typeof sandboxSecretKey === "string" ? sandboxSecretKey : null
96
- };
97
- }
98
- function getClaudeConfigDir() {
99
- const fromEnv = process.env.CLAUDE_CONFIG_DIR;
100
- if (typeof fromEnv === "string" && fromEnv.length > 0) {
101
- return fromEnv;
102
- }
103
- return join(homedir(), ".claude");
104
- }
105
-
106
- // src/core/te-agent-client.ts
107
- import { open, unlink } from "fs/promises";
108
- import path from "path";
109
- import { Readable } from "stream";
110
- import { pipeline } from "stream/promises";
111
- var TeAgentApiError = class extends Error {
112
- constructor(message, status, code, body) {
113
- super(message);
114
- this.status = status;
115
- this.code = code;
116
- this.body = body;
117
- this.name = "TeAgentApiError";
118
- }
119
- status;
120
- code;
121
- body;
122
- };
123
- var DEFAULT_TIMEOUT_MS = 3e4;
124
- var UPLOAD_TIMEOUT_MS = 12e4;
125
- var DOWNLOAD_TIMEOUT_MS = 12e4;
126
- async function fetchWithTimeout(url, init, timeoutMs = DEFAULT_TIMEOUT_MS) {
127
- const controller = new AbortController();
128
- const timer = setTimeout(() => controller.abort(), timeoutMs);
129
- try {
130
- return await fetch(url, { ...init, signal: controller.signal });
131
- } catch (err) {
132
- if (err?.name === "AbortError") {
133
- throw new TeAgentApiError(
134
- `Request timed out (${timeoutMs}ms) for ${safeRequestOrigin(url)}`,
135
- 0,
136
- "TIMEOUT"
137
- );
138
- }
139
- throw networkRequestError(url, err);
140
- } finally {
141
- clearTimeout(timer);
142
- }
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
- }
167
- function teClaudeBaseFromActiveHost(hostOverride) {
168
- const override = hostOverride ? void 0 : process.env.TE_CLAUDE_BASE_URL;
169
- if (override) return override.replace(/\/+$/, "");
170
- const h = hostOverride || getActiveHost();
171
- if (!h) return void 0;
172
- const base = h.replace(/\/+$/, "");
173
- const bp = process.env.TE_CLAUDE_BASE_PATH || "/agent";
174
- return base.endsWith(bp) ? base : base + bp;
175
- }
176
- async function signRequest(method, path2, hostOverride, includeJsonContentType = true) {
177
- const sandboxCred = tryLoadTeAgentSandboxCredentials();
178
- if (!hostOverride && sandboxCred && sandboxCred.sandboxId && sandboxCred.sandboxSecretKey) {
179
- const headers = {
180
- "X-Sandbox-Id": sandboxCred.sandboxId,
181
- "X-Sandbox-Secret-Key": sandboxCred.sandboxSecretKey
182
- };
183
- if (includeJsonContentType && (method === "POST" || method === "PATCH" || method === "PUT")) {
184
- headers["Content-Type"] = "application/json";
185
- }
186
- return {
187
- url: `${sandboxCred.url.replace(/\/$/, "")}${path2}`,
188
- headers,
189
- authKind: "sandbox"
190
- };
191
- }
192
- const baseUrl = hostOverride ? teClaudeBaseFromActiveHost(hostOverride) : sandboxCred?.url || teClaudeBaseFromActiveHost();
193
- if (!baseUrl) {
194
- throw new TeAgentCredentialsError(
195
- "Cannot determine the te-claude service URL",
196
- "Run ae-cli config set-host <url> to configure the service URL, or execute inside a te-agent sandbox"
197
- );
198
- }
199
- const hostForToken = hostOverride || getActiveHost() || baseUrl;
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
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 };
248
- }
249
- async function parseResponse(response, defaultErrorPrefix) {
250
- const text = await response.text();
251
- let parsed = void 0;
252
- if (text) {
253
- try {
254
- parsed = JSON.parse(text);
255
- } catch {
256
- parsed = text;
257
- }
258
- }
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
- }
264
- if (response.status === 401) {
265
- throw new TeAgentApiError(
266
- "Session expired or unauthorized. Please run: ae-cli auth login",
267
- response.status,
268
- "auth_expired",
269
- parsed
270
- );
271
- }
272
- throw new TeAgentApiError(details.message, response.status, details.code, parsed);
273
- }
274
- return parsed;
275
- }
276
- async function postToMainApp(path2, body, hostOverride) {
277
- const rawBody = JSON.stringify(body);
278
- const response = await fetchSignedWithRetry({
279
- method: "POST",
280
- path: path2,
281
- body: rawBody,
282
- hostOverride
283
- });
284
- return parseResponse(response, "Main app returned");
285
- }
286
- async function getFromMainApp(path2, hostOverride) {
287
- const response = await fetchSignedWithRetry({
288
- method: "GET",
289
- path: path2,
290
- hostOverride
291
- });
292
- return parseResponse(response, "Main app returned");
293
- }
294
- async function getSandboxModels(currentModelId) {
295
- const qs = currentModelId ? `?current=${encodeURIComponent(currentModelId)}` : "";
296
- const data = await getFromMainApp(`/api/sandbox/models${qs}`);
297
- return Array.isArray(data?.models) ? data.models : [];
298
- }
299
- async function postSandboxModelSelection(args) {
300
- return postToMainApp("/api/sandbox/models/select", args);
301
- }
302
- async function getSandboxSyncPullCandidates(args) {
303
- const qs = new URLSearchParams({
304
- workspacePath: args.workspacePath,
305
- kind: args.kind
306
- });
307
- return getFromMainApp(
308
- `/api/sandbox/sync/pull/candidates?${qs.toString()}`
309
- );
310
- }
311
- async function postSandboxSyncPull(args) {
312
- return postToMainApp("/api/sandbox/sync/pull", {
313
- workspacePath: args.workspacePath,
314
- kind: args.kind,
315
- skills: args.skills,
316
- mcp: args.mcp,
317
- mode: "merge"
318
- });
319
- }
320
- async function deleteFromMainApp(path2, hostOverride) {
321
- const response = await fetchSignedWithRetry({
322
- method: "DELETE",
323
- path: path2,
324
- hostOverride
325
- });
326
- return parseResponse(response, "Main app returned");
327
- }
328
- async function patchToMainApp(path2, body, hostOverride) {
329
- const rawBody = JSON.stringify(body);
330
- const response = await fetchSignedWithRetry({
331
- method: "PATCH",
332
- path: path2,
333
- body: rawBody,
334
- hostOverride
335
- });
336
- return parseResponse(response, "Main app returned");
337
- }
338
- async function putToMainApp(path2, body, hostOverride) {
339
- const rawBody = JSON.stringify(body);
340
- const response = await fetchSignedWithRetry({
341
- method: "PUT",
342
- path: path2,
343
- body: rawBody,
344
- hostOverride
345
- });
346
- return parseResponse(response, "Main app returned");
347
- }
348
- async function getBufferFromMainApp(path2, hostOverride) {
349
- const response = await fetchSignedWithRetry({
350
- method: "GET",
351
- path: path2,
352
- hostOverride
353
- });
354
- if (!response.ok) {
355
- await parseResponse(response, "Main app returned");
356
- }
357
- const arrayBuffer = await response.arrayBuffer();
358
- const buffer = Buffer.from(arrayBuffer);
359
- const cd = response.headers.get("Content-Disposition") || "";
360
- const match = cd.match(/filename\*=UTF-8''([^;]+)/);
361
- const fileName = match ? decodeURIComponent(match[1]) : null;
362
- const contentType = response.headers.get("Content-Type");
363
- return { buffer, fileName, contentType };
364
- }
365
- function responseFileName(response) {
366
- const disposition = response.headers.get("Content-Disposition") ?? "";
367
- const encoded = disposition.match(/filename\*=UTF-8''([^;]+)/i)?.[1];
368
- if (encoded) {
369
- try {
370
- return decodeURIComponent(encoded.trim());
371
- } catch {
372
- return encoded.trim();
373
- }
374
- }
375
- return disposition.match(/filename="([^"]+)"/i)?.[1] ?? disposition.match(/filename=([^;]+)/i)?.[1]?.trim() ?? null;
376
- }
377
- async function* responseBodyChunks(body) {
378
- const reader = body.getReader();
379
- try {
380
- while (true) {
381
- const chunk = await reader.read();
382
- if (chunk.done) return;
383
- yield chunk.value;
384
- }
385
- } finally {
386
- reader.releaseLock();
387
- }
388
- }
389
- async function downloadFromMainApp(requestPath, outputPath, hostOverride) {
390
- const absolutePath = path.resolve(outputPath);
391
- let fileHandle;
392
- let created = false;
393
- const controller = new AbortController();
394
- const timer = setTimeout(() => controller.abort(), DOWNLOAD_TIMEOUT_MS);
395
- try {
396
- try {
397
- fileHandle = await open(absolutePath, "wx");
398
- created = true;
399
- } catch (error) {
400
- if (error.code === "EEXIST") {
401
- throw new TeAgentApiError(
402
- `Output file already exists: ${absolutePath}`,
403
- 0,
404
- "OUTPUT_EXISTS"
405
- );
406
- }
407
- throw new TeAgentApiError(
408
- `Unable to create output file: ${absolutePath}`,
409
- 0,
410
- "OUTPUT_ERROR"
411
- );
412
- }
413
- let signed = await signRequest("GET", requestPath, hostOverride);
414
- let response;
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);
431
- }
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);
438
- }
439
- if (!response.ok) {
440
- await parseResponse(response, "Main app returned");
441
- }
442
- if (!response.body) {
443
- throw new TeAgentApiError("Main app returned an empty download stream", 0, "EMPTY_BODY");
444
- }
445
- const output = fileHandle.createWriteStream();
446
- try {
447
- await pipeline(
448
- Readable.from(responseBodyChunks(response.body)),
449
- output
450
- );
451
- } catch (error) {
452
- if (error?.name === "AbortError") {
453
- throw new TeAgentApiError(
454
- `Request timed out (${DOWNLOAD_TIMEOUT_MS}ms): ${signed.url}`,
455
- 0,
456
- "TIMEOUT"
457
- );
458
- }
459
- throw new TeAgentApiError(
460
- `Download failed: ${error instanceof Error ? error.message : String(error)}`,
461
- 0,
462
- "DOWNLOAD_ERROR"
463
- );
464
- }
465
- return {
466
- path: absolutePath,
467
- bytes: output.bytesWritten,
468
- fileName: responseFileName(response),
469
- contentType: response.headers.get("Content-Type")
470
- };
471
- } catch (error) {
472
- if (fileHandle) await fileHandle.close().catch(() => void 0);
473
- if (created) await unlink(absolutePath).catch(() => void 0);
474
- throw error;
475
- } finally {
476
- clearTimeout(timer);
477
- controller.abort();
478
- }
479
- }
480
- async function uploadToMainApp(path2, formData, hostOverride) {
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
- });
489
- return parseResponse(response, "Upload failed");
490
- }
491
-
492
- export {
493
- TeAgentCredentialsError,
494
- tryLoadTeAgentSandboxCredentials,
495
- getClaudeConfigDir,
496
- TeAgentApiError,
497
- postToMainApp,
498
- getFromMainApp,
499
- getSandboxModels,
500
- postSandboxModelSelection,
501
- getSandboxSyncPullCandidates,
502
- postSandboxSyncPull,
503
- deleteFromMainApp,
504
- patchToMainApp,
505
- putToMainApp,
506
- getBufferFromMainApp,
507
- downloadFromMainApp,
508
- uploadToMainApp
509
- };