@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
|
@@ -1,19 +1,17 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
|
|
1
2
|
import {
|
|
2
3
|
internalCallSourceHeaders
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-Y74WTIKJ.js";
|
|
4
5
|
import {
|
|
5
|
-
|
|
6
|
+
SecureStoreAuthError,
|
|
6
7
|
getCliToken
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ATSM5XAW.js";
|
|
8
9
|
import {
|
|
9
10
|
safeJsonParse
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-WZ6YVQSF.js";
|
|
11
12
|
import {
|
|
12
13
|
PermissionError
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import {
|
|
15
|
-
logger
|
|
16
|
-
} from "./chunk-JHENBQ5B.js";
|
|
14
|
+
} from "./chunk-4P355ZWB.js";
|
|
17
15
|
|
|
18
16
|
// src/core/capability-api.ts
|
|
19
17
|
import { readFile } from "fs/promises";
|
|
@@ -134,7 +132,13 @@ function buildCapabilityHttpError(resp, body) {
|
|
|
134
132
|
}
|
|
135
133
|
async function throwCapabilityHttpError(resp) {
|
|
136
134
|
const body = parseCapabilityResponse(await resp.text());
|
|
137
|
-
|
|
135
|
+
const error = buildCapabilityHttpError(resp, body);
|
|
136
|
+
if (resp.status === 401) {
|
|
137
|
+
throw new SecureStoreAuthError(
|
|
138
|
+
`${error.message}. The stored CLI token is invalid or expired; run: ae-cli auth login`
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
throw error;
|
|
138
142
|
}
|
|
139
143
|
async function requestOnce(url, method, token, body, accept = "application/json") {
|
|
140
144
|
const headers = {
|
|
@@ -166,45 +170,17 @@ async function callGateway(host, domain, pathAfterV1, method, body, queryParams
|
|
|
166
170
|
async function callGatewayWithEnvelope(host, domain, pathAfterV1, method, body, queryParams = {}, options = {}) {
|
|
167
171
|
const url = buildCapabilityGatewayUrl(options.apiBaseUrl ?? host, domain, pathAfterV1, queryParams);
|
|
168
172
|
const token = await getCliToken(host);
|
|
169
|
-
|
|
170
|
-
let permissionMsg;
|
|
173
|
+
const resp = await requestOnce(url, method, token, body);
|
|
171
174
|
if (resp.status === 403) {
|
|
172
175
|
const error = await permissionError(resp);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
+
if (options.retryOnInvalidTokenForbidden !== false && isInvalidCliTokenMessage(error.message)) {
|
|
177
|
+
throw new SecureStoreAuthError(
|
|
178
|
+
`${error.message} Run: ae-cli auth login`
|
|
179
|
+
);
|
|
176
180
|
}
|
|
181
|
+
throw error;
|
|
177
182
|
}
|
|
178
|
-
if (resp.
|
|
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) {
|
|
183
|
+
if (!resp.ok) {
|
|
208
184
|
await throwCapabilityHttpError(resp);
|
|
209
185
|
}
|
|
210
186
|
return parseCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
|
|
@@ -212,24 +188,15 @@ async function callGatewayWithEnvelope(host, domain, pathAfterV1, method, body,
|
|
|
212
188
|
async function fetchCapabilityGateway(host, domain, pathAfterV1, method = "GET", body, accept = "application/json") {
|
|
213
189
|
const url = buildCapabilityGatewayUrl(host, domain, pathAfterV1);
|
|
214
190
|
const token = await getCliToken(host);
|
|
215
|
-
|
|
191
|
+
const resp = await requestOnce(url, method, token, body, accept);
|
|
216
192
|
if (resp.status === 403) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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);
|
|
193
|
+
const error = await permissionError(resp);
|
|
194
|
+
if (isInvalidCliTokenMessage(error.message)) {
|
|
195
|
+
throw new SecureStoreAuthError(`${error.message} Run: ae-cli auth login`);
|
|
231
196
|
}
|
|
232
|
-
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
199
|
+
if (!resp.ok) {
|
|
233
200
|
await throwCapabilityHttpError(resp);
|
|
234
201
|
}
|
|
235
202
|
return resp;
|
|
@@ -242,8 +209,11 @@ async function requestCapabilityGatewayWithEnvelope(host, domain, pathAfterV1, m
|
|
|
242
209
|
const resp = await fetchCapabilityGateway(host, domain, pathAfterV1, method, body);
|
|
243
210
|
return parseCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
|
|
244
211
|
}
|
|
245
|
-
async function
|
|
246
|
-
return
|
|
212
|
+
async function listCapabilitiesWithEnvelope(host, domain, projectId) {
|
|
213
|
+
return callGatewayWithEnvelope(host, domain, "capabilities", "GET", void 0, { project_id: projectId });
|
|
214
|
+
}
|
|
215
|
+
async function inspectCapabilityWithEnvelope(host, domain, capabilityId, projectId) {
|
|
216
|
+
return callGatewayWithEnvelope(host, domain, `capabilities/${capabilityId}`, "GET", void 0, { project_id: projectId });
|
|
247
217
|
}
|
|
248
218
|
async function inspectCapability(host, domain, capabilityId, projectId) {
|
|
249
219
|
return callGateway(
|
|
@@ -264,6 +234,12 @@ async function executeCapabilityWithEnvelope(host, domain, capabilityId, input =
|
|
|
264
234
|
async function dryRunCapability(host, domain, capabilityId, input = {}) {
|
|
265
235
|
return callGateway(host, domain, `capabilities/${capabilityId}/dry-run`, "POST", { input });
|
|
266
236
|
}
|
|
237
|
+
async function dryRunCapabilityWithEnvelope(host, domain, capabilityId, input = {}) {
|
|
238
|
+
return callGatewayWithEnvelope(host, domain, `capabilities/${capabilityId}/dry-run`, "POST", { input });
|
|
239
|
+
}
|
|
240
|
+
async function validateCapabilityWithEnvelope(host, domain, capabilityId, input = {}) {
|
|
241
|
+
return callGatewayWithEnvelope(host, domain, `capabilities/${capabilityId}/validate`, "POST", { input });
|
|
242
|
+
}
|
|
267
243
|
async function validateCapability(host, domain, capabilityId, input = {}) {
|
|
268
244
|
return callGateway(host, domain, `capabilities/${capabilityId}/validate`, "POST", { input });
|
|
269
245
|
}
|
|
@@ -301,24 +277,15 @@ async function uploadInputFileBytes(host, domain, projectId, purpose, bytes, fil
|
|
|
301
277
|
form.append("purpose", purpose);
|
|
302
278
|
form.append("file", new Blob([fileBuffer], { type: contentType }), filename);
|
|
303
279
|
const token = await getCliToken(host);
|
|
304
|
-
|
|
280
|
+
const resp = await requestMultipartOnce(url, token, form);
|
|
305
281
|
if (resp.status === 403) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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);
|
|
282
|
+
const error = await permissionError(resp);
|
|
283
|
+
if (isInvalidCliTokenMessage(error.message)) {
|
|
284
|
+
throw new SecureStoreAuthError(`${error.message} Run: ae-cli auth login`);
|
|
320
285
|
}
|
|
321
|
-
|
|
286
|
+
throw error;
|
|
287
|
+
}
|
|
288
|
+
if (!resp.ok) {
|
|
322
289
|
await throwCapabilityHttpError(resp);
|
|
323
290
|
}
|
|
324
291
|
return unwrapCapabilityEnvelope(parseCapabilityResponse(await resp.text()));
|
|
@@ -337,11 +304,14 @@ export {
|
|
|
337
304
|
fetchCapabilityGateway,
|
|
338
305
|
requestCapabilityGateway,
|
|
339
306
|
requestCapabilityGatewayWithEnvelope,
|
|
340
|
-
|
|
307
|
+
listCapabilitiesWithEnvelope,
|
|
308
|
+
inspectCapabilityWithEnvelope,
|
|
341
309
|
inspectCapability,
|
|
342
310
|
executeCapability,
|
|
343
311
|
executeCapabilityWithEnvelope,
|
|
344
312
|
dryRunCapability,
|
|
313
|
+
dryRunCapabilityWithEnvelope,
|
|
314
|
+
validateCapabilityWithEnvelope,
|
|
345
315
|
validateCapability,
|
|
346
316
|
uploadInputFile,
|
|
347
317
|
uploadInputFileBytes,
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
CapabilityGatewayError,
|
|
4
|
+
fetchCapabilityGateway,
|
|
5
|
+
requestCapabilityGateway
|
|
6
|
+
} from "./chunk-QJQZH5GQ.js";
|
|
1
7
|
import {
|
|
2
8
|
resolveGatewayDomain
|
|
3
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-TKHSULJT.js";
|
|
4
10
|
import {
|
|
5
11
|
readOutputMetadata,
|
|
6
12
|
unwrapOutputData,
|
|
7
13
|
withOutputMetadata
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import {
|
|
10
|
-
CapabilityGatewayError,
|
|
11
|
-
fetchCapabilityGateway,
|
|
12
|
-
requestCapabilityGateway
|
|
13
|
-
} from "./chunk-OMPRXM3V.js";
|
|
14
|
+
} from "./chunk-CZU3V3DQ.js";
|
|
14
15
|
import {
|
|
15
16
|
PermissionError
|
|
16
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-4P355ZWB.js";
|
|
17
18
|
|
|
18
19
|
// src/core/analysis-async-artifact.ts
|
|
19
20
|
import { randomBytes } from "crypto";
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
resolveGatewayDomain
|
|
3
|
-
} from "./chunk-3KWQYGYI.js";
|
|
4
|
-
import {
|
|
5
|
-
withOutputMetadata
|
|
6
|
-
} from "./chunk-BYYS3ANB.js";
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
|
|
7
2
|
import {
|
|
8
3
|
dryRunCapability,
|
|
9
4
|
executeCapabilityWithEnvelope,
|
|
10
5
|
validateCapability
|
|
11
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-QJQZH5GQ.js";
|
|
7
|
+
import {
|
|
8
|
+
resolveGatewayDomain
|
|
9
|
+
} from "./chunk-TKHSULJT.js";
|
|
10
|
+
import {
|
|
11
|
+
withOutputMetadata
|
|
12
|
+
} from "./chunk-CZU3V3DQ.js";
|
|
12
13
|
|
|
13
14
|
// src/core/capability-command.ts
|
|
14
15
|
import { randomBytes } from "crypto";
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
CapabilityGatewayError
|
|
4
|
+
} from "./chunk-QJQZH5GQ.js";
|
|
5
|
+
import {
|
|
6
|
+
SecureStoreAuthError,
|
|
7
|
+
getCliToken
|
|
8
|
+
} from "./chunk-ATSM5XAW.js";
|
|
9
|
+
import {
|
|
10
|
+
safeJsonParse
|
|
11
|
+
} from "./chunk-WZ6YVQSF.js";
|
|
12
|
+
import {
|
|
13
|
+
PermissionError
|
|
14
|
+
} from "./chunk-4P355ZWB.js";
|
|
15
|
+
|
|
16
|
+
// src/core/mcp-access.ts
|
|
17
|
+
function buildUrl(host, path, params = {}) {
|
|
18
|
+
const base = host.replace(/\/$/, "");
|
|
19
|
+
const p = path.startsWith("/") ? path : `/${path}`;
|
|
20
|
+
const url = new URL(`${base}${p}`);
|
|
21
|
+
for (const [key, value] of Object.entries(params)) {
|
|
22
|
+
if (value !== void 0 && value !== null) {
|
|
23
|
+
url.searchParams.set(key, String(value));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return url.toString();
|
|
27
|
+
}
|
|
28
|
+
var KbUnauthorizedError = class extends Error {
|
|
29
|
+
};
|
|
30
|
+
function optionalString(value) {
|
|
31
|
+
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
32
|
+
}
|
|
33
|
+
function responseReturnCode(data) {
|
|
34
|
+
const value = data?.return_code;
|
|
35
|
+
if (value === void 0 || value === null || value === 0 || value === "0") {
|
|
36
|
+
return void 0;
|
|
37
|
+
}
|
|
38
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
39
|
+
return optionalString(value);
|
|
40
|
+
}
|
|
41
|
+
function responseErrorMetadata(data) {
|
|
42
|
+
const nestedError = data?.error && typeof data.error === "object" ? data.error : void 0;
|
|
43
|
+
return {
|
|
44
|
+
code: optionalString(data?.errorCode) ?? optionalString(data?.error_code) ?? optionalString(data?.code) ?? optionalString(nestedError?.code) ?? responseReturnCode(data),
|
|
45
|
+
hint: optionalString(data?.hint) ?? optionalString(nestedError?.hint)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function responseErrorMessage(data) {
|
|
49
|
+
const nestedError = data?.error && typeof data.error === "object" ? data.error : void 0;
|
|
50
|
+
return optionalString(typeof data?.error === "string" ? data.error : void 0) ?? optionalString(nestedError?.message) ?? optionalString(data?.message) ?? optionalString(data?.return_message);
|
|
51
|
+
}
|
|
52
|
+
function responseStatus(resp) {
|
|
53
|
+
const statusText = optionalString(resp.statusText);
|
|
54
|
+
return statusText ? `${resp.status} ${statusText}` : String(resp.status);
|
|
55
|
+
}
|
|
56
|
+
function malformedResponseError(resp, detail) {
|
|
57
|
+
if (!resp.ok) {
|
|
58
|
+
return new Error(`KB API HTTP error: ${responseStatus(resp)} (${detail})`);
|
|
59
|
+
}
|
|
60
|
+
return new Error(
|
|
61
|
+
`KB API protocol error: HTTP ${responseStatus(resp)} (${detail})`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
var KbHttpError = class extends CapabilityGatewayError {
|
|
65
|
+
constructor(message, code, status, hint) {
|
|
66
|
+
super(message, code, status, hint);
|
|
67
|
+
this.name = "Error";
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
function nonOkResponseError(resp, data, options) {
|
|
71
|
+
const metadata = responseErrorMetadata(data);
|
|
72
|
+
const serverMessage = responseErrorMessage(data);
|
|
73
|
+
const fallbackMessage = `KB API HTTP error: ${responseStatus(resp)}`;
|
|
74
|
+
const businessCode = options.preserveBusinessErrorCode && typeof data?.error === "string" && metadata.code ? metadata.code : void 0;
|
|
75
|
+
const message = businessCode ? `${businessCode}: ${serverMessage ?? fallbackMessage}` : serverMessage ?? fallbackMessage;
|
|
76
|
+
if (options.preserveErrorMetadata !== false && (metadata.code || metadata.hint)) {
|
|
77
|
+
return new KbHttpError(message, metadata.code, resp.status, metadata.hint);
|
|
78
|
+
}
|
|
79
|
+
return new Error(message);
|
|
80
|
+
}
|
|
81
|
+
function parseKbResponse(resp, text, options = {}) {
|
|
82
|
+
if (resp.status === 403) {
|
|
83
|
+
let msg = "Permission denied for this resource (HTTP 403)";
|
|
84
|
+
let metadata = {};
|
|
85
|
+
try {
|
|
86
|
+
const d = safeJsonParse(text);
|
|
87
|
+
const m = d && (typeof d.error === "string" ? d.error : d.error?.message || d.message);
|
|
88
|
+
if (m && typeof m === "string") msg = m;
|
|
89
|
+
if (options.preserveErrorMetadata) metadata = responseErrorMetadata(d);
|
|
90
|
+
} catch {
|
|
91
|
+
}
|
|
92
|
+
throw new PermissionError(msg, metadata.code, metadata.hint);
|
|
93
|
+
}
|
|
94
|
+
if (resp.status === 401) {
|
|
95
|
+
throw new KbUnauthorizedError(
|
|
96
|
+
`KB API token auth failed: HTTP ${resp.status} ${resp.statusText}`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
if (!text.trim()) {
|
|
100
|
+
throw malformedResponseError(resp, "empty response body");
|
|
101
|
+
}
|
|
102
|
+
let data;
|
|
103
|
+
try {
|
|
104
|
+
data = safeJsonParse(text);
|
|
105
|
+
} catch {
|
|
106
|
+
throw malformedResponseError(resp, "non-JSON response");
|
|
107
|
+
}
|
|
108
|
+
if (data?.return_code === -1001) {
|
|
109
|
+
throw new KbUnauthorizedError(
|
|
110
|
+
`KB API token auth failed: ${data.return_message || "unauthorized"} (code: ${data.return_code})`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
if (!resp.ok) {
|
|
114
|
+
throw nonOkResponseError(resp, data, options);
|
|
115
|
+
}
|
|
116
|
+
if (data?.return_code !== 0 && data?.return_code !== void 0) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
`AE API error: ${data.return_message || "unknown"} (code: ${data.return_code})`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (data && typeof data === "object" && typeof data.error === "string" && data.error.trim() && data.return_code === void 0 && data.success === void 0) {
|
|
122
|
+
if (options.preserveErrorMetadata) {
|
|
123
|
+
const metadata = responseErrorMetadata(data);
|
|
124
|
+
throw new CapabilityGatewayError(
|
|
125
|
+
data.error,
|
|
126
|
+
metadata.code,
|
|
127
|
+
resp.status,
|
|
128
|
+
metadata.hint
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
const businessCode = options.preserveBusinessErrorCode && typeof data.code === "string" && data.code.trim() ? data.code.trim() : "";
|
|
132
|
+
throw new Error(businessCode ? `${businessCode}: ${data.error}` : data.error);
|
|
133
|
+
}
|
|
134
|
+
return data?.data !== void 0 ? data.data : data;
|
|
135
|
+
}
|
|
136
|
+
async function fetchWithCliToken(input, init, cliToken, options = {}) {
|
|
137
|
+
const headers = new Headers(init.headers);
|
|
138
|
+
headers.set("cli-token", cliToken);
|
|
139
|
+
const resp = await fetch(input, { ...init, headers });
|
|
140
|
+
if (options.responseType === "bytes" && resp.ok) {
|
|
141
|
+
if (resp.headers.get("content-type")?.includes("application/json")) {
|
|
142
|
+
parseKbResponse(resp, await resp.text(), options);
|
|
143
|
+
throw new Error("KB raw-file protocol error: unexpected JSON response");
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
bytes: new Uint8Array(await resp.arrayBuffer()),
|
|
147
|
+
contentType: resp.headers.get("content-type") ?? "application/octet-stream"
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
return parseKbResponse(resp, await resp.text(), options);
|
|
151
|
+
}
|
|
152
|
+
async function requestWithCliToken(host, input, init, options) {
|
|
153
|
+
try {
|
|
154
|
+
return await fetchWithCliToken(input, init, await getCliToken(host), options);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if (error instanceof KbUnauthorizedError) {
|
|
157
|
+
throw new SecureStoreAuthError(
|
|
158
|
+
`The stored CLI token for ${host} is invalid or expired. Run: ae-cli auth login --host ${host}`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async function getAuthHeaders(ctx) {
|
|
165
|
+
const cliToken = await getCliToken(ctx.host());
|
|
166
|
+
return { "cli-token": cliToken };
|
|
167
|
+
}
|
|
168
|
+
async function kbApi(ctx, method, path, params = {}, body, options = {}) {
|
|
169
|
+
const host = ctx.host();
|
|
170
|
+
const upperMethod = method.toUpperCase();
|
|
171
|
+
return requestWithCliToken(
|
|
172
|
+
host,
|
|
173
|
+
buildUrl(host, path, params),
|
|
174
|
+
{
|
|
175
|
+
method: upperMethod,
|
|
176
|
+
headers: {
|
|
177
|
+
"Content-Type": "application/json"
|
|
178
|
+
},
|
|
179
|
+
body: upperMethod === "GET" ? void 0 : JSON.stringify(body ?? {})
|
|
180
|
+
},
|
|
181
|
+
options
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
async function kbUpload(ctx, path, form, params = {}, options = {}) {
|
|
185
|
+
const host = ctx.host();
|
|
186
|
+
const uploadOptions = { preserveErrorMetadata: false, ...options };
|
|
187
|
+
return requestWithCliToken(
|
|
188
|
+
host,
|
|
189
|
+
buildUrl(host, path, params),
|
|
190
|
+
{
|
|
191
|
+
method: "POST",
|
|
192
|
+
body: form
|
|
193
|
+
},
|
|
194
|
+
uploadOptions
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export {
|
|
199
|
+
getAuthHeaders,
|
|
200
|
+
kbApi,
|
|
201
|
+
kbUpload
|
|
202
|
+
};
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
|
|
1
2
|
import {
|
|
2
3
|
logger
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-4P355ZWB.js";
|
|
5
|
+
|
|
6
|
+
// src/core/url-utils.ts
|
|
7
|
+
function normalizeUrl(url) {
|
|
8
|
+
if (!url) return url;
|
|
9
|
+
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
|
10
|
+
url = `https://${url}`;
|
|
11
|
+
}
|
|
12
|
+
return url.replace(/\/$/, "");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/core/config.ts
|
|
16
|
+
import fs3 from "fs";
|
|
17
|
+
import path from "path";
|
|
4
18
|
|
|
5
19
|
// src/core/json-utils.ts
|
|
6
20
|
import fs from "fs";
|
|
@@ -38,19 +52,6 @@ function safeReadJsonFile(filePath) {
|
|
|
38
52
|
return safeJsonParse(content);
|
|
39
53
|
}
|
|
40
54
|
|
|
41
|
-
// src/core/url-utils.ts
|
|
42
|
-
function normalizeUrl(url) {
|
|
43
|
-
if (!url) return url;
|
|
44
|
-
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
|
45
|
-
url = `https://${url}`;
|
|
46
|
-
}
|
|
47
|
-
return url.replace(/\/$/, "");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// src/core/config.ts
|
|
51
|
-
import fs3 from "fs";
|
|
52
|
-
import path from "path";
|
|
53
|
-
|
|
54
55
|
// src/core/sandbox-runtime.ts
|
|
55
56
|
import { homedir } from "os";
|
|
56
57
|
import { join } from "path";
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
|
|
1
2
|
import {
|
|
2
|
-
CommunityReportError
|
|
3
|
-
} from "./chunk-UW5UN47B.js";
|
|
4
|
-
import {
|
|
3
|
+
CommunityReportError,
|
|
5
4
|
logger
|
|
6
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-4P355ZWB.js";
|
|
7
6
|
|
|
8
7
|
// src/core/community-report-client.ts
|
|
9
8
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
|
|
1
2
|
import {
|
|
2
3
|
MultiselectCancelled,
|
|
3
4
|
promptSingleSelect
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import {
|
|
6
|
-
printError,
|
|
7
|
-
printOutput
|
|
8
|
-
} from "./chunk-BYYS3ANB.js";
|
|
9
|
-
import "./chunk-J2DEBMRF.js";
|
|
5
|
+
} from "./chunk-7K24F7T2.js";
|
|
10
6
|
import {
|
|
11
7
|
AE_TRIAL_URL,
|
|
12
8
|
missingAeHostHint
|
|
13
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-6ZIQV5GW.js";
|
|
10
|
+
import {
|
|
11
|
+
printError,
|
|
12
|
+
printOutput
|
|
13
|
+
} from "./chunk-CZU3V3DQ.js";
|
|
14
|
+
import "./chunk-ATSM5XAW.js";
|
|
14
15
|
import {
|
|
15
16
|
addHost,
|
|
16
17
|
listHosts,
|
|
@@ -20,9 +21,8 @@ import {
|
|
|
20
21
|
resolveHostSelector,
|
|
21
22
|
setActiveHost,
|
|
22
23
|
updateHostLabel
|
|
23
|
-
} from "./chunk-
|
|
24
|
-
import "./chunk-
|
|
25
|
-
import "./chunk-JHENBQ5B.js";
|
|
24
|
+
} from "./chunk-WZ6YVQSF.js";
|
|
25
|
+
import "./chunk-4P355ZWB.js";
|
|
26
26
|
|
|
27
27
|
// src/commands/config.ts
|
|
28
28
|
import * as readline2 from "readline";
|