@thinkingai/ae-cli 6.1.18 → 6.1.20
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 +97 -38
- package/README.zh.md +101 -38
- package/dist/{auth-ROB2EDYV.js → auth-FUM37MHF.js} +241 -126
- package/dist/{capability-DKMYUTLC.js → capability-AXFQW5WM.js} +49 -35
- package/dist/{chunk-JHENBQ5B.js → chunk-4P355ZWB.js} +70 -1
- package/dist/chunk-6ZIQV5GW.js +26 -0
- package/dist/{chunk-TUKQZTMI.js → chunk-7K24F7T2.js} +2 -0
- package/dist/{chunk-OO6XR6LK.js → chunk-AMBFK2K3.js} +2 -0
- package/dist/chunk-ATSM5XAW.js +623 -0
- package/dist/{chunk-4XXOWOTA.js → chunk-BBEFP4SB.js} +31 -38
- package/dist/{chunk-BYYS3ANB.js → chunk-CZU3V3DQ.js} +5 -15
- package/dist/{chunk-VTWMIC5L.js → chunk-E2JKXMVO.js} +2 -0
- package/dist/chunk-ECBLHAZO.js +15 -0
- package/dist/{sync-HKIOZXQE.js → chunk-I4WQAEYB.js} +31 -540
- package/dist/{chunk-DWO43OIB.js → chunk-JQ3ENZZH.js} +2 -0
- package/dist/chunk-LNZBEQXW.js +25216 -0
- package/dist/{chunk-ZQ47LWTI.js → chunk-QJQZH5GQ.js} +49 -79
- package/dist/{chunk-QZ3AS4KK.js → chunk-RSG4ONOI.js} +9 -8
- package/dist/{chunk-4NN5IWVN.js → chunk-T6OSFQZD.js} +2 -0
- package/dist/{chunk-Y3LOALAV.js → chunk-TAL6CZH6.js} +8 -7
- package/dist/{chunk-3KWQYGYI.js → chunk-TKHSULJT.js} +2 -0
- package/dist/chunk-VXNMYUXU.js +202 -0
- package/dist/{chunk-3FY3RJ26.js → chunk-WZ6YVQSF.js} +15 -14
- package/dist/{chunk-6EIJSNBD.js → chunk-Y74WTIKJ.js} +2 -0
- package/dist/{community-report-client-C7WDGET3.js → community-report-client-XXWGSBSD.js} +3 -4
- package/dist/{config-BMYZX2UE.js → config-EXUGQN5T.js} +10 -10
- package/dist/{data-integration-QEKDWQDY.js → data-integration-4NZ53OMT.js} +920 -97
- package/dist/index.js +56 -81
- package/dist/{local-data-upload-client-4YYHSYD6.js → local-data-upload-client-KYOKVYZV.js} +3 -4
- package/dist/{memory-I2WXDTV2.js → memory-ATNKZNW5.js} +6 -7
- package/dist/{metadata-I4C2EWUN.js → metadata-VZVC7YMH.js} +10 -11
- package/dist/{model-HLHIEFMU.js → model-E4JMQ4V2.js} +8 -9
- package/dist/{personal-semantic-preference-LIPACBDX.js → personal-semantic-preference-7S2SQ3UV.js} +9 -10
- package/dist/{project-semantic-RT3R2VQD.js → project-semantic-2SZP2OPO.js} +13 -14
- package/dist/sync-YV3E66IF.js +520 -0
- package/dist/{te-agent-BR6VDBNX.js → te-agent-JB5T3PO7.js} +396 -92
- package/dist/{te-analysis-7VUNUYWZ.js → te-analysis-3YJAAT2D.js} +196 -43
- package/dist/{te-community-5DMNKJWY.js → te-community-UDBI672N.js} +12 -34
- package/dist/{te-dataops-6P5IKWNJ.js → te-dataops-ZLYOCXZ4.js} +480 -81
- package/dist/{te-engage-KZPR5R22.js → te-engage-4XG6OJML.js} +88 -16
- package/dist/{te-experiment-6BITX4RD.js → te-experiment-VXUWPINJ.js} +83 -12
- package/dist/te-kb-WYQWHFSC.js +1732 -0
- package/dist/{te-system-FXITO2JG.js → te-system-7G6F2LJA.js} +569 -35
- package/dist/{te-team-ADOC2ROP.js → te-team-E7FBBXMQ.js} +8 -7
- package/dist/{update-YCYCKJOO.js → update-D47BUG25.js} +8 -8
- package/package.json +22 -10
- package/skills/ae-agent/SKILL.md +30 -13
- package/skills/ae-agent/references/agent-distribution.md +94 -0
- package/skills/ae-agent/references/approval-request.md +4 -0
- package/skills/ae-agent/references/command_index.md +9 -2
- package/skills/ae-agent/references/create-automation.md +20 -2
- package/skills/ae-agent/references/get-agent-context.md +70 -0
- package/skills/ae-agent/references/list-automations.md +18 -3
- package/skills/ae-agent/references/list-mcp-credentials.md +1 -1
- package/skills/ae-agent/references/mcp-token.md +3 -3
- package/skills/ae-agent/references/set-mcp-credential.md +0 -1
- package/skills/ae-agent/references/update-automation.md +18 -0
- package/skills/ae-analysis/SKILL.md +11 -2
- package/skills/ae-analysis/references/adhoc_run.md +2 -0
- package/skills/ae-analysis/references/ai_models.md +23 -3
- package/skills/ae-analysis/references/analysis_gateway_assets.md +3 -3
- package/skills/ae-analysis/references/audience_models.md +18 -0
- package/skills/ae-analysis/references/command_index.md +9 -9
- package/skills/ae-analysis/references/cross_source_config.md +84 -0
- package/skills/ae-analysis/references/dashboard_update.md +1 -1
- package/skills/ae-analysis/references/project_timezone_update.md +13 -4
- package/skills/ae-analysis/references/property_create.md +2 -0
- package/skills/ae-analysis/references/super_metadata_batch_create.md +2 -0
- package/skills/ae-analysis/references/user_cluster_models.md +2 -0
- package/skills/ae-analysis/references/user_cluster_update.md +8 -4
- package/skills/ae-analysis/references/user_tag_create.md +30 -2
- package/skills/ae-analysis/references/user_tag_models.md +17 -3
- package/skills/ae-analysis/references/user_tag_update.md +14 -2
- package/skills/ae-data-integration/SKILL.md +3 -1
- package/skills/ae-data-integration/references/dimension-routing.md +36 -0
- package/skills/ae-data-integration/references/error-handling.md +54 -1
- package/skills/ae-data-integration/references/local-analysis.md +2 -0
- package/skills/ae-data-integration/references/source-inspect.md +18 -2
- package/skills/ae-data-integration/references/tracking-plan.md +1 -1
- package/skills/ae-data-integration/references/transform.md +4 -2
- package/skills/ae-data-integration/references/ue-mapping.md +5 -2
- package/skills/ae-data-integration/references/ue-routing.md +40 -1
- package/skills/ae-dataops/SKILL.md +11 -1
- package/skills/ae-dataops/references/dataops-backfill.md +135 -0
- package/skills/ae-engage/SKILL.md +5 -0
- package/skills/ae-engage/references/build-task-save-guide.md +5 -1
- package/skills/ae-engage/references/save-flow.md +37 -1
- package/skills/ae-engage/references/save-task.md +6 -0
- package/skills/ae-experiment/SKILL.md +6 -2
- package/skills/ae-experiment/references/save_metric.md +20 -8
- package/skills/ae-generate-tracking-plan/SKILL.md +25 -13
- package/skills/ae-generate-tracking-plan/references/business-dimension-mapping.md +1 -1
- package/skills/ae-kb/SKILL.md +218 -36
- package/skills/ae-kb/references/query-workflow.md +59 -29
- package/skills/ae-kb/references/versions.md +46 -0
- package/skills/ae-system/SKILL.md +29 -31
- package/skills/ae-system/references/channel-management.md +303 -0
- package/skills/ae-use-agent/SKILL.md +42 -0
- package/skills/ae-use-agent/references/local-agent.md +114 -0
- package/dist/auth-GBMV6TEJ.js +0 -14
- package/dist/capability-HYVVPG25.js +0 -352
- package/dist/chunk-EFH4XWYC.js +0 -556
- package/dist/chunk-J2DEBMRF.js +0 -313
- package/dist/chunk-JRJY5DMJ.js +0 -71
- package/dist/chunk-OMPRXM3V.js +0 -349
- package/dist/chunk-QNOLN2LJ.js +0 -509
- package/dist/chunk-RJDU7NYP.js +0 -1198
- package/dist/chunk-RNAALWJK.js +0 -98
- package/dist/chunk-SERWF6G5.js +0 -13
- package/dist/chunk-UW5UN47B.js +0 -70
- package/dist/chunk-ZQKDZXDO.js +0 -317
- package/dist/client-L2YDMHQ6.js +0 -203
- package/dist/memory-3ORCR7JH.js +0 -893
- package/dist/metadata-VUOQJE26.js +0 -339
- package/dist/model-UGRDX4MW.js +0 -139
- package/dist/personal-semantic-preference-OEISBRHM.js +0 -239
- package/dist/project-semantic-FFPWFPIW.js +0 -1114
- package/dist/sync-TFHU2UTG.js +0 -10261
- package/dist/te-agent-VLYOV7S4.js +0 -3894
- package/dist/te-analysis-4YGQL5RC.js +0 -9357
- package/dist/te-community-ISDQWJU7.js +0 -1859
- package/dist/te-dataops-CVULXNVB.js +0 -2209
- package/dist/te-engage-N5WI32H6.js +0 -4898
- package/dist/te-experiment-UVR4HLND.js +0 -988
- package/dist/te-kb-RCLSSH2Q.js +0 -935
- package/dist/te-system-K2GYMCTB.js +0 -2213
- package/skills/ae-agent/references/auto-provision-mcp-credentials.md +0 -57
package/dist/chunk-OMPRXM3V.js
DELETED
|
@@ -1,349 +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
|
-
safeJsonParse
|
|
10
|
-
} from "./chunk-3FY3RJ26.js";
|
|
11
|
-
import {
|
|
12
|
-
PermissionError
|
|
13
|
-
} from "./chunk-UW5UN47B.js";
|
|
14
|
-
import {
|
|
15
|
-
logger
|
|
16
|
-
} from "./chunk-JHENBQ5B.js";
|
|
17
|
-
|
|
18
|
-
// src/core/capability-api.ts
|
|
19
|
-
import { readFile } from "fs/promises";
|
|
20
|
-
import { basename } from "path";
|
|
21
|
-
var CapabilityGatewayError = class extends Error {
|
|
22
|
-
constructor(message, code, httpStatus, hint, meta) {
|
|
23
|
-
super(message);
|
|
24
|
-
this.code = code;
|
|
25
|
-
this.httpStatus = httpStatus;
|
|
26
|
-
this.hint = hint;
|
|
27
|
-
this.meta = meta;
|
|
28
|
-
this.name = "CapabilityGatewayError";
|
|
29
|
-
}
|
|
30
|
-
code;
|
|
31
|
-
httpStatus;
|
|
32
|
-
hint;
|
|
33
|
-
meta;
|
|
34
|
-
};
|
|
35
|
-
function buildCapabilityGatewayUrl(host, domain, pathAfterV1, queryParams = {}) {
|
|
36
|
-
const base = host.replace(/\/+$/, "");
|
|
37
|
-
const cleanDomain = domain.replace(/^\/+|\/+$/g, "");
|
|
38
|
-
const cleanPath = pathAfterV1.replace(/^\/+|\/+$/g, "");
|
|
39
|
-
const gatewayPrefix = cleanDomain === "" ? "/api/cli/v1" : `/api/cli/${cleanDomain}/v1`;
|
|
40
|
-
const url = new URL(`${base}${gatewayPrefix}/${cleanPath}`);
|
|
41
|
-
for (const [key, value] of Object.entries(queryParams)) {
|
|
42
|
-
if (value !== void 0 && value !== null) {
|
|
43
|
-
url.searchParams.set(key, String(value));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return url.toString();
|
|
47
|
-
}
|
|
48
|
-
async function permissionMessage(resp) {
|
|
49
|
-
const text = await resp.text().catch(() => "");
|
|
50
|
-
try {
|
|
51
|
-
const d = safeJsonParse(text);
|
|
52
|
-
const msg = d && (d.error?.message || (typeof d.error === "string" ? d.error : void 0) || d.message);
|
|
53
|
-
if (msg && typeof msg === "string") return msg;
|
|
54
|
-
} catch {
|
|
55
|
-
}
|
|
56
|
-
return "Permission denied for this resource (HTTP 403)";
|
|
57
|
-
}
|
|
58
|
-
async function permissionError(resp) {
|
|
59
|
-
const codeResponse = resp.clone();
|
|
60
|
-
const message = await permissionMessage(resp);
|
|
61
|
-
const body = safeJsonParse(await codeResponse.text());
|
|
62
|
-
const error = isRecord(body?.error) ? body.error : void 0;
|
|
63
|
-
const code = nonEmptyString(error?.code) ?? nonEmptyString(body?.code);
|
|
64
|
-
return new PermissionError(message, code);
|
|
65
|
-
}
|
|
66
|
-
function isInvalidCliTokenMessage(message) {
|
|
67
|
-
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);
|
|
68
|
-
}
|
|
69
|
-
function parseCapabilityResponse(text) {
|
|
70
|
-
if (!text) return void 0;
|
|
71
|
-
try {
|
|
72
|
-
return safeJsonParse(text);
|
|
73
|
-
} catch {
|
|
74
|
-
return text;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function parseCapabilityEnvelope(body) {
|
|
78
|
-
if (body == null) {
|
|
79
|
-
throw new CapabilityGatewayError("Empty capability gateway response");
|
|
80
|
-
}
|
|
81
|
-
if (typeof body.ok === "boolean") {
|
|
82
|
-
if (body.ok) {
|
|
83
|
-
return {
|
|
84
|
-
ok: true,
|
|
85
|
-
data: body.data,
|
|
86
|
-
...isRecord(body.meta) ? { meta: body.meta } : {}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
const err = body.error ?? {};
|
|
90
|
-
const code = nonEmptyString(err.code);
|
|
91
|
-
const message = nonEmptyString(err.message) ?? code ?? "Capability gateway request failed";
|
|
92
|
-
const hint = nonEmptyString(err.hint);
|
|
93
|
-
throw new CapabilityGatewayError(
|
|
94
|
-
message,
|
|
95
|
-
code,
|
|
96
|
-
err.http_status ?? err.httpStatus,
|
|
97
|
-
hint,
|
|
98
|
-
isRecord(body.meta) ? body.meta : void 0
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
return { ok: true, data: body };
|
|
102
|
-
}
|
|
103
|
-
function unwrapCapabilityEnvelope(body) {
|
|
104
|
-
return parseCapabilityEnvelope(body).data;
|
|
105
|
-
}
|
|
106
|
-
function nonEmptyString(value) {
|
|
107
|
-
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
108
|
-
}
|
|
109
|
-
function isRecord(value) {
|
|
110
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
111
|
-
}
|
|
112
|
-
function buildCapabilityHttpError(resp, body) {
|
|
113
|
-
const fallback = `Capability gateway HTTP error: ${resp.status} ${resp.statusText}`.trim();
|
|
114
|
-
if (body && typeof body === "object") {
|
|
115
|
-
const err = body.error ?? body.data?.error ?? body;
|
|
116
|
-
const code = nonEmptyString(err.code) ?? nonEmptyString(err.errorCode) ?? nonEmptyString(body.code);
|
|
117
|
-
const message = nonEmptyString(err.message) ?? nonEmptyString(body.message);
|
|
118
|
-
const hint = nonEmptyString(err.hint) ?? nonEmptyString(body.hint);
|
|
119
|
-
const details = [code, message, hint ? `Hint: ${hint}` : void 0].filter(Boolean);
|
|
120
|
-
if (details.length > 0) {
|
|
121
|
-
return new CapabilityGatewayError(
|
|
122
|
-
message ?? fallback,
|
|
123
|
-
code,
|
|
124
|
-
resp.status,
|
|
125
|
-
hint,
|
|
126
|
-
isRecord(body.meta) ? body.meta : void 0
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (typeof body === "string" && body.trim()) {
|
|
131
|
-
return new CapabilityGatewayError(`${fallback}: ${body.slice(0, 500)}`, void 0, resp.status);
|
|
132
|
-
}
|
|
133
|
-
return new CapabilityGatewayError(fallback, void 0, resp.status);
|
|
134
|
-
}
|
|
135
|
-
async function throwCapabilityHttpError(resp) {
|
|
136
|
-
const body = parseCapabilityResponse(await resp.text());
|
|
137
|
-
throw buildCapabilityHttpError(resp, body);
|
|
138
|
-
}
|
|
139
|
-
async function requestOnce(url, method, token, body, accept = "application/json") {
|
|
140
|
-
const headers = {
|
|
141
|
-
"cli-token": token,
|
|
142
|
-
"Accept": accept,
|
|
143
|
-
...internalCallSourceHeaders()
|
|
144
|
-
};
|
|
145
|
-
const init = { method, headers };
|
|
146
|
-
if (body !== void 0 && method !== "GET") {
|
|
147
|
-
headers["Content-Type"] = "application/json";
|
|
148
|
-
init.body = JSON.stringify(body);
|
|
149
|
-
}
|
|
150
|
-
return fetch(url, init);
|
|
151
|
-
}
|
|
152
|
-
async function requestMultipartOnce(url, token, form) {
|
|
153
|
-
return fetch(url, {
|
|
154
|
-
method: "POST",
|
|
155
|
-
headers: {
|
|
156
|
-
"cli-token": token,
|
|
157
|
-
"Accept": "application/json",
|
|
158
|
-
...internalCallSourceHeaders()
|
|
159
|
-
},
|
|
160
|
-
body: form
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
async function callGateway(host, domain, pathAfterV1, method, body, queryParams = {}, options = {}) {
|
|
164
|
-
return (await callGatewayWithEnvelope(host, domain, pathAfterV1, method, body, queryParams, options)).data;
|
|
165
|
-
}
|
|
166
|
-
async function callGatewayWithEnvelope(host, domain, pathAfterV1, method, body, queryParams = {}, options = {}) {
|
|
167
|
-
const url = buildCapabilityGatewayUrl(options.apiBaseUrl ?? host, domain, pathAfterV1, queryParams);
|
|
168
|
-
const token = await getCliToken(host);
|
|
169
|
-
let resp = await requestOnce(url, method, token, body);
|
|
170
|
-
let permissionMsg;
|
|
171
|
-
if (resp.status === 403) {
|
|
172
|
-
const error = await permissionError(resp);
|
|
173
|
-
permissionMsg = error.message;
|
|
174
|
-
if (options.retryOnInvalidTokenForbidden === false || !isInvalidCliTokenMessage(permissionMsg)) {
|
|
175
|
-
throw error;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (resp.status === 401) {
|
|
179
|
-
if (options.retryOnUnauthorized === false) {
|
|
180
|
-
await throwCapabilityHttpError(resp);
|
|
181
|
-
}
|
|
182
|
-
logger.warn(`Capability gateway request failed (HTTP 401) for ${host}, refreshing CLI token`);
|
|
183
|
-
clearCliToken(host);
|
|
184
|
-
const newToken = await getCliToken(host);
|
|
185
|
-
process.stderr.write(`[ae-cli] CLI token refreshed for ${host}
|
|
186
|
-
`);
|
|
187
|
-
resp = await requestOnce(url, method, newToken, body);
|
|
188
|
-
if (resp.status === 403) {
|
|
189
|
-
throw new PermissionError(await permissionMessage(resp));
|
|
190
|
-
}
|
|
191
|
-
if (!resp.ok) {
|
|
192
|
-
await throwCapabilityHttpError(resp);
|
|
193
|
-
}
|
|
194
|
-
} else if (resp.status === 403 && permissionMsg) {
|
|
195
|
-
logger.warn(`Capability gateway request failed (${permissionMsg}) for ${host}, refreshing CLI token`);
|
|
196
|
-
clearCliToken(host);
|
|
197
|
-
const newToken = await getCliToken(host);
|
|
198
|
-
process.stderr.write(`[ae-cli] CLI token refreshed for ${host}
|
|
199
|
-
`);
|
|
200
|
-
resp = await requestOnce(url, method, newToken, body);
|
|
201
|
-
if (resp.status === 403) {
|
|
202
|
-
throw await permissionError(resp);
|
|
203
|
-
}
|
|
204
|
-
if (!resp.ok) {
|
|
205
|
-
await throwCapabilityHttpError(resp);
|
|
206
|
-
}
|
|
207
|
-
} else if (!resp.ok) {
|
|
208
|
-
await throwCapabilityHttpError(resp);
|
|
209
|
-
}
|
|
210
|
-
return parseCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
|
|
211
|
-
}
|
|
212
|
-
async function fetchCapabilityGateway(host, domain, pathAfterV1, method = "GET", body, accept = "application/json") {
|
|
213
|
-
const url = buildCapabilityGatewayUrl(host, domain, pathAfterV1);
|
|
214
|
-
const token = await getCliToken(host);
|
|
215
|
-
let resp = await requestOnce(url, method, token, body, accept);
|
|
216
|
-
if (resp.status === 403) {
|
|
217
|
-
throw await permissionError(resp);
|
|
218
|
-
}
|
|
219
|
-
if (resp.status === 401) {
|
|
220
|
-
logger.warn(`Capability gateway request failed (HTTP 401) for ${host}, refreshing CLI token`);
|
|
221
|
-
clearCliToken(host);
|
|
222
|
-
const newToken = await getCliToken(host);
|
|
223
|
-
process.stderr.write(`[ae-cli] CLI token refreshed for ${host}
|
|
224
|
-
`);
|
|
225
|
-
resp = await requestOnce(url, method, newToken, body, accept);
|
|
226
|
-
if (resp.status === 403) {
|
|
227
|
-
throw await permissionError(resp);
|
|
228
|
-
}
|
|
229
|
-
if (!resp.ok) {
|
|
230
|
-
await throwCapabilityHttpError(resp);
|
|
231
|
-
}
|
|
232
|
-
} else if (!resp.ok) {
|
|
233
|
-
await throwCapabilityHttpError(resp);
|
|
234
|
-
}
|
|
235
|
-
return resp;
|
|
236
|
-
}
|
|
237
|
-
async function requestCapabilityGateway(host, domain, pathAfterV1, method = "GET", body) {
|
|
238
|
-
const resp = await fetchCapabilityGateway(host, domain, pathAfterV1, method, body);
|
|
239
|
-
return unwrapCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
|
|
240
|
-
}
|
|
241
|
-
async function requestCapabilityGatewayWithEnvelope(host, domain, pathAfterV1, method = "GET", body) {
|
|
242
|
-
const resp = await fetchCapabilityGateway(host, domain, pathAfterV1, method, body);
|
|
243
|
-
return parseCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
|
|
244
|
-
}
|
|
245
|
-
async function listCapabilities(host, domain, projectId) {
|
|
246
|
-
return callGateway(host, domain, "capabilities", "GET", void 0, { project_id: projectId });
|
|
247
|
-
}
|
|
248
|
-
async function inspectCapability(host, domain, capabilityId, projectId) {
|
|
249
|
-
return callGateway(
|
|
250
|
-
host,
|
|
251
|
-
domain,
|
|
252
|
-
`capabilities/${capabilityId}`,
|
|
253
|
-
"GET",
|
|
254
|
-
void 0,
|
|
255
|
-
{ project_id: projectId }
|
|
256
|
-
);
|
|
257
|
-
}
|
|
258
|
-
async function executeCapability(host, domain, capabilityId, input = {}) {
|
|
259
|
-
return callGateway(host, domain, `capabilities/${capabilityId}/execute`, "POST", { input });
|
|
260
|
-
}
|
|
261
|
-
async function executeCapabilityWithEnvelope(host, domain, capabilityId, input = {}) {
|
|
262
|
-
return callGatewayWithEnvelope(host, domain, `capabilities/${capabilityId}/execute`, "POST", { input });
|
|
263
|
-
}
|
|
264
|
-
async function dryRunCapability(host, domain, capabilityId, input = {}) {
|
|
265
|
-
return callGateway(host, domain, `capabilities/${capabilityId}/dry-run`, "POST", { input });
|
|
266
|
-
}
|
|
267
|
-
async function validateCapability(host, domain, capabilityId, input = {}) {
|
|
268
|
-
return callGateway(host, domain, `capabilities/${capabilityId}/validate`, "POST", { input });
|
|
269
|
-
}
|
|
270
|
-
async function uploadInputFile(host, domain, projectId, purpose, filePath) {
|
|
271
|
-
const fileBytes = await readFile(filePath);
|
|
272
|
-
const filename = basename(filePath);
|
|
273
|
-
return uploadInputFileBytes(
|
|
274
|
-
host,
|
|
275
|
-
domain,
|
|
276
|
-
projectId,
|
|
277
|
-
purpose,
|
|
278
|
-
fileBytes,
|
|
279
|
-
filename,
|
|
280
|
-
inputFileContentType(filename)
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
function inputFileContentType(filename) {
|
|
284
|
-
const lower = filename.toLowerCase();
|
|
285
|
-
if (lower.endsWith(".csv")) return "text/csv";
|
|
286
|
-
if (lower.endsWith(".xlsx")) {
|
|
287
|
-
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
288
|
-
}
|
|
289
|
-
if (lower.endsWith(".json")) return "application/json";
|
|
290
|
-
if (lower.endsWith(".txt")) return "text/plain";
|
|
291
|
-
return "application/octet-stream";
|
|
292
|
-
}
|
|
293
|
-
async function uploadInputFileBytes(host, domain, projectId, purpose, bytes, filename, contentType = "application/octet-stream") {
|
|
294
|
-
const url = buildCapabilityGatewayUrl(host, domain, "input-files");
|
|
295
|
-
const fileBuffer = bytes instanceof ArrayBuffer ? bytes : bytes.buffer.slice(
|
|
296
|
-
bytes.byteOffset,
|
|
297
|
-
bytes.byteOffset + bytes.byteLength
|
|
298
|
-
);
|
|
299
|
-
const form = new FormData();
|
|
300
|
-
form.append("project_id", String(projectId));
|
|
301
|
-
form.append("purpose", purpose);
|
|
302
|
-
form.append("file", new Blob([fileBuffer], { type: contentType }), filename);
|
|
303
|
-
const token = await getCliToken(host);
|
|
304
|
-
let resp = await requestMultipartOnce(url, token, form);
|
|
305
|
-
if (resp.status === 403) {
|
|
306
|
-
throw await permissionError(resp);
|
|
307
|
-
}
|
|
308
|
-
if (resp.status === 401) {
|
|
309
|
-
logger.warn(`Capability gateway request failed (HTTP 401) for ${host}, refreshing CLI token`);
|
|
310
|
-
clearCliToken(host);
|
|
311
|
-
const newToken = await getCliToken(host);
|
|
312
|
-
process.stderr.write(`[ae-cli] CLI token refreshed for ${host}
|
|
313
|
-
`);
|
|
314
|
-
resp = await requestMultipartOnce(url, newToken, form);
|
|
315
|
-
if (resp.status === 403) {
|
|
316
|
-
throw await permissionError(resp);
|
|
317
|
-
}
|
|
318
|
-
if (!resp.ok) {
|
|
319
|
-
await throwCapabilityHttpError(resp);
|
|
320
|
-
}
|
|
321
|
-
} else if (!resp.ok) {
|
|
322
|
-
await throwCapabilityHttpError(resp);
|
|
323
|
-
}
|
|
324
|
-
return unwrapCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
|
|
325
|
-
}
|
|
326
|
-
async function callCapabilityApi(host, domain, action, method = "POST", params = {}, options = {}) {
|
|
327
|
-
const isGet = method === "GET";
|
|
328
|
-
if (isGet) {
|
|
329
|
-
return callGateway(host, domain, action.replace(/^\/+|\/+$/g, ""), "GET", void 0, {}, options);
|
|
330
|
-
}
|
|
331
|
-
return callGateway(host, domain, action.replace(/^\/+|\/+$/g, ""), method, params, {}, options);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
export {
|
|
335
|
-
CapabilityGatewayError,
|
|
336
|
-
buildCapabilityGatewayUrl,
|
|
337
|
-
fetchCapabilityGateway,
|
|
338
|
-
requestCapabilityGateway,
|
|
339
|
-
requestCapabilityGatewayWithEnvelope,
|
|
340
|
-
listCapabilities,
|
|
341
|
-
inspectCapability,
|
|
342
|
-
executeCapability,
|
|
343
|
-
executeCapabilityWithEnvelope,
|
|
344
|
-
dryRunCapability,
|
|
345
|
-
validateCapability,
|
|
346
|
-
uploadInputFile,
|
|
347
|
-
uploadInputFileBytes,
|
|
348
|
-
callCapabilityApi
|
|
349
|
-
};
|