@thinkingai/ae-cli 6.1.14 → 6.1.17
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.
- package/README.md +5 -2
- package/README.zh.md +5 -2
- package/dist/{auth-GBMV6TEJ.js → auth-2WTQOP77.js} +3 -3
- package/dist/{auth-NDSXE54J.js → auth-77BUFLGC.js} +57 -13
- package/dist/{capability-TAMDRZYV.js → capability-72DTW5M2.js} +9 -9
- package/dist/{capability-U7TDEEEG.js → capability-PJHNI4GJ.js} +9 -9
- package/dist/{chunk-AFXA7BRK.js → chunk-4KVPKXFX.js} +5 -5
- package/dist/chunk-4SGZG4XY.js +311 -0
- package/dist/chunk-6EIJSNBD.js +8 -0
- package/dist/chunk-C4MGVGJW.js +13 -0
- package/dist/{chunk-WZRX4KOH.js → chunk-GT46FPXN.js} +4 -6
- package/dist/{chunk-5XUSIK27.js → chunk-ILIU36SU.js} +10 -7
- package/dist/{chunk-JHENBQ5B.js → chunk-LYVNONC4.js} +0 -35
- package/dist/{chunk-JUW4AJXN.js → chunk-P3FGXJTU.js} +12 -7
- package/dist/chunk-QGM4M3NI.js +37 -0
- package/dist/{chunk-753BUTNZ.js → chunk-RGKJGKT7.js} +2 -2
- package/dist/{chunk-UIHQJK5E.js → chunk-SAU3QFIQ.js} +3 -3
- package/dist/{chunk-VLWOLBGZ.js → chunk-UOUS37JQ.js} +149 -161
- package/dist/{chunk-AXDXJTPC.js → chunk-UW5UN47B.js} +19 -2
- package/dist/chunk-VPKZ7I72.js +509 -0
- package/dist/{chunk-QATA32VR.js → chunk-VR3LCBHW.js} +2 -2
- package/dist/{chunk-IBH3LDAH.js → chunk-YA6SMTXG.js} +3 -3
- package/dist/chunk-ZZUOD757.js +598 -0
- package/dist/{client-L2YDMHQ6.js → client-TKG4WBHN.js} +4 -5
- package/dist/{community-report-client-M2RW4MXD.js → community-report-client-FI4LNVYS.js} +3 -2
- package/dist/{config-OL2LWGBV.js → config-RE6CMGPK.js} +7 -7
- package/dist/data-integration-XQYB4X4F.js +3503 -0
- package/dist/index.js +68 -34
- package/dist/local-data-upload-client-BWHSUQQK.js +167 -0
- package/dist/{memory-MUP7PPL7.js → memory-CHRU2F7W.js} +7 -6
- package/dist/{memory-U4O5PMXH.js → memory-YK33G4T7.js} +7 -6
- package/dist/{metadata-5MIMNIMT.js → metadata-UILXHBWF.js} +10 -9
- package/dist/{metadata-LERKDJN6.js → metadata-XXR34N5P.js} +10 -9
- package/dist/{model-JTUEO5M4.js → model-K3KLWIW6.js} +7 -3
- package/dist/model-NR3JHFSJ.js +139 -0
- package/dist/{sync-MOSFNBVR.js → sync-DAVKYVMW.js} +8 -6
- package/dist/sync-FCKOVWWS.js +10261 -0
- package/dist/{te-agent-IFKZDHZI.js → te-agent-4BKBODMF.js} +686 -71
- package/dist/te-agent-HLW4VTQK.js +3893 -0
- package/dist/{te-analysis-FCHRTNIY.js → te-analysis-O6DCO6BS.js} +36 -13
- package/dist/{te-analysis-QG7UKGDA.js → te-analysis-ZMNGOVNW.js} +36 -13
- package/dist/{te-community-HNKVTERD.js → te-community-6HPBWJUZ.js} +24 -19
- package/dist/{te-community-IWE5B7W6.js → te-community-HLC43QKH.js} +24 -20
- package/dist/{te-dataops-KXCEB4CS.js → te-dataops-EJP56W3K.js} +57 -34
- package/dist/{te-dataops-KQPYNAE3.js → te-dataops-HDRUXY4K.js} +59 -34
- package/dist/{te-engage-D6EG3NOR.js → te-engage-FGBGQ4IY.js} +9 -8
- package/dist/{te-engage-ZSMIJLUW.js → te-engage-RAK5PESW.js} +9 -8
- package/dist/{te-experiment-K5US7RMG.js → te-experiment-SO5MPDMJ.js} +9 -8
- package/dist/{te-experiment-WA7TFMEL.js → te-experiment-VZF7BT6G.js} +9 -8
- package/dist/{te-kb-OIH3T6CS.js → te-kb-SQCLHG6X.js} +250 -126
- package/dist/{te-system-AZ3URMUO.js → te-system-YARIK4S5.js} +7 -4
- package/dist/te-system-Z77IKZFN.js +2213 -0
- package/dist/{te-team-GZPU6UWA.js → te-team-EFKWYKMK.js} +7 -7
- package/dist/{update-TOBFXF2V.js → update-OGPSZM5A.js} +7 -7
- package/package.json +14 -3
- package/skills/ae-agent/SKILL.md +21 -11
- package/skills/ae-agent/references/approval-effect.md +44 -0
- package/skills/ae-agent/references/approval-request.md +46 -0
- package/skills/ae-agent/references/approval-task.md +45 -0
- package/skills/ae-agent/references/approval-type.md +32 -0
- package/skills/ae-agent/references/command_index.md +19 -0
- package/skills/ae-analysis/SKILL.md +11 -7
- package/skills/ae-analysis/references/adhoc_run.md +2 -0
- package/skills/ae-analysis/references/ai_models.md +27 -0
- package/skills/ae-analysis/references/analysis_gateway_assets.md +3 -2
- package/skills/ae-analysis/references/command_index.md +4 -1
- package/skills/ae-analysis/references/dashboard_get.md +8 -2
- package/skills/ae-analysis/references/dashboard_report_data_run.md +3 -1
- package/skills/ae-analysis/references/dashboard_update.md +4 -1
- package/skills/ae-analysis/references/project_space_business_filter_upsert.md +17 -0
- package/skills/ae-analysis/references/user_tag_models.md +4 -4
- package/skills/ae-data-integration/SKILL.md +54 -0
- package/skills/ae-data-integration/references/handoff.md +43 -0
- package/skills/ae-data-integration/references/local-analysis.md +27 -0
- package/skills/ae-data-integration/references/reuse.md +41 -0
- package/skills/ae-data-integration/references/sink-upload.md +58 -0
- package/skills/ae-data-integration/references/source-inspect.md +68 -0
- package/skills/ae-data-integration/references/sync-json-upload.md +60 -0
- package/skills/ae-data-integration/references/tracking-plan.md +35 -0
- package/skills/ae-data-integration/references/transform.md +65 -0
- package/skills/ae-data-integration/references/ue-mapping.md +142 -0
- package/skills/ae-data-integration/references/ue-routing.md +35 -0
- package/skills/ae-data-integration-helper/SKILL.md +1 -1
- package/skills/ae-dataops/SKILL.md +1 -1
- package/skills/ae-dataops/references/dataops-query.md +4 -4
- package/skills/ae-generate-tracking-plan/SKILL.md +54 -3
- package/skills/ae-kb/SKILL.md +55 -50
- package/skills/ae-kb/references/query-workflow.md +112 -0
- package/skills/ae-kb-discovery/SKILL.md +105 -0
- package/skills/ae-metadata/SKILL.md +0 -1
- package/dist/chunk-3FY3RJ26.js +0 -293
- package/dist/chunk-S5NTSDBS.js +0 -198
- package/dist/chunk-ZQKDZXDO.js +0 -317
- package/dist/cli-token-4UPER74P.js +0 -21
|
@@ -1,16 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
internalCallSourceHeaders
|
|
3
|
+
} from "./chunk-6EIJSNBD.js";
|
|
1
4
|
import {
|
|
2
5
|
clearCliToken,
|
|
3
6
|
getCliToken
|
|
4
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-4SGZG4XY.js";
|
|
5
8
|
import {
|
|
6
9
|
safeJsonParse
|
|
7
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ZZUOD757.js";
|
|
8
11
|
import {
|
|
9
12
|
PermissionError
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-UW5UN47B.js";
|
|
11
14
|
import {
|
|
12
15
|
logger
|
|
13
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-LYVNONC4.js";
|
|
14
17
|
|
|
15
18
|
// src/core/capability-api.ts
|
|
16
19
|
import { readFile } from "fs/promises";
|
|
@@ -137,7 +140,7 @@ async function requestOnce(url, method, token, body, accept = "application/json"
|
|
|
137
140
|
const headers = {
|
|
138
141
|
"cli-token": token,
|
|
139
142
|
"Accept": accept,
|
|
140
|
-
|
|
143
|
+
...internalCallSourceHeaders()
|
|
141
144
|
};
|
|
142
145
|
const init = { method, headers };
|
|
143
146
|
if (body !== void 0 && method !== "GET") {
|
|
@@ -152,7 +155,7 @@ async function requestMultipartOnce(url, token, form) {
|
|
|
152
155
|
headers: {
|
|
153
156
|
"cli-token": token,
|
|
154
157
|
"Accept": "application/json",
|
|
155
|
-
|
|
158
|
+
...internalCallSourceHeaders()
|
|
156
159
|
},
|
|
157
160
|
body: form
|
|
158
161
|
});
|
|
@@ -168,7 +171,7 @@ async function callGatewayWithEnvelope(host, domain, pathAfterV1, method, body,
|
|
|
168
171
|
if (resp.status === 403) {
|
|
169
172
|
const error = await permissionError(resp);
|
|
170
173
|
permissionMsg = error.message;
|
|
171
|
-
if (!isInvalidCliTokenMessage(permissionMsg)) {
|
|
174
|
+
if (options.retryOnInvalidTokenForbidden === false || !isInvalidCliTokenMessage(permissionMsg)) {
|
|
172
175
|
throw error;
|
|
173
176
|
}
|
|
174
177
|
}
|
|
@@ -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-
|
|
7
|
+
} from "./chunk-4SGZG4XY.js";
|
|
5
8
|
import {
|
|
6
9
|
safeJsonParse
|
|
7
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ZZUOD757.js";
|
|
8
11
|
import {
|
|
9
12
|
PermissionError
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-UW5UN47B.js";
|
|
11
14
|
import {
|
|
12
15
|
logger
|
|
13
|
-
} from "./chunk-
|
|
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-
|
|
6
|
+
} from "./chunk-GT46FPXN.js";
|
|
7
7
|
import {
|
|
8
8
|
dryRunCapability,
|
|
9
9
|
executeCapabilityWithEnvelope,
|
|
10
10
|
validateCapability
|
|
11
|
-
} from "./chunk-
|
|
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-
|
|
8
|
+
} from "./chunk-GT46FPXN.js";
|
|
9
9
|
import {
|
|
10
10
|
CapabilityGatewayError,
|
|
11
11
|
fetchCapabilityGateway,
|
|
12
12
|
requestCapabilityGateway
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-P3FGXJTU.js";
|
|
14
14
|
import {
|
|
15
15
|
PermissionError
|
|
16
|
-
} from "./chunk-
|
|
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-
|
|
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(
|
|
133
|
+
throw new TeAgentApiError(
|
|
134
|
+
`Request timed out (${timeoutMs}ms) for ${safeRequestOrigin(url)}`,
|
|
135
|
+
0,
|
|
136
|
+
"TIMEOUT"
|
|
137
|
+
);
|
|
124
138
|
}
|
|
125
|
-
throw
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
231
|
-
const response = await fetchWithTimeout(signed.url, {
|
|
278
|
+
const response = await fetchSignedWithRetry({
|
|
232
279
|
method: "POST",
|
|
233
|
-
|
|
234
|
-
body:
|
|
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
|
|
240
|
-
const response = await fetchWithTimeout(signed.url, {
|
|
287
|
+
const response = await fetchSignedWithRetry({
|
|
241
288
|
method: "GET",
|
|
242
|
-
|
|
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
|
|
274
|
-
const response = await fetchWithTimeout(signed.url, {
|
|
321
|
+
const response = await fetchSignedWithRetry({
|
|
275
322
|
method: "DELETE",
|
|
276
|
-
|
|
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
|
|
283
|
-
const response = await fetchWithTimeout(signed.url, {
|
|
330
|
+
const response = await fetchSignedWithRetry({
|
|
284
331
|
method: "PATCH",
|
|
285
|
-
|
|
286
|
-
body:
|
|
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
|
|
293
|
-
const response = await fetchWithTimeout(signed.url, {
|
|
340
|
+
const response = await fetchSignedWithRetry({
|
|
294
341
|
method: "PUT",
|
|
295
|
-
|
|
296
|
-
body:
|
|
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
|
|
302
|
-
const response = await fetchWithTimeout(signed.url, {
|
|
349
|
+
const response = await fetchSignedWithRetry({
|
|
303
350
|
method: "GET",
|
|
304
|
-
|
|
351
|
+
path: path2,
|
|
352
|
+
hostOverride
|
|
305
353
|
});
|
|
306
354
|
if (!response.ok) {
|
|
307
|
-
|
|
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
|
-
|
|
413
|
+
let signed = await signRequest("GET", requestPath, hostOverride);
|
|
385
414
|
let response;
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
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
|
|