@thinkingai/ae-cli 6.1.12 → 6.1.13
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 +0 -2
- package/README.zh.md +0 -2
- package/dist/{auth-NN55553T.js → auth-GBMV6TEJ.js} +2 -2
- package/dist/{auth-GDV3H5I4.js → auth-NDSXE54J.js} +4 -4
- package/dist/{capability-DRLGDVS4.js → capability-TAMDRZYV.js} +18 -8
- package/dist/{capability-P6GK3AQH.js → capability-U7TDEEEG.js} +18 -8
- package/dist/{chunk-GJJA4CQZ.js → chunk-3FY3RJ26.js} +0 -4
- package/dist/{chunk-GS2P7LFD.js → chunk-5XUSIK27.js} +2 -2
- package/dist/{chunk-7KQWSBSL.js → chunk-753BUTNZ.js} +3 -3
- package/dist/{chunk-VTXHDCBW.js → chunk-AFXA7BRK.js} +2 -2
- package/dist/chunk-IBH3LDAH.js +556 -0
- package/dist/{chunk-RBNKI5ZW.js → chunk-JUW4AJXN.js} +2 -2
- package/dist/{chunk-TS6BUGUY.js → chunk-QATA32VR.js} +3 -3
- package/dist/{chunk-Z3OXWCIA.js → chunk-S5NTSDBS.js} +2 -2
- package/dist/chunk-UIHQJK5E.js +556 -0
- package/dist/{chunk-VKD5WQKN.js → chunk-VLWOLBGZ.js} +142 -24
- package/dist/{chunk-YTG6Q75E.js → chunk-WZRX4KOH.js} +25 -3
- package/dist/{chunk-YV52FB5G.js → chunk-ZQKDZXDO.js} +1 -1
- package/dist/{cli-token-GL5MS5FK.js → cli-token-4UPER74P.js} +3 -3
- package/dist/{chunk-6A2FUCIS.js → client-L2YDMHQ6.js} +5 -6
- package/dist/{config-4VZNLBKF.js → config-OL2LWGBV.js} +4 -33
- package/dist/index.js +25 -38
- package/dist/{memory-RWJW4XFO.js → memory-MUP7PPL7.js} +4 -4
- package/dist/{memory-VO2ZJCRT.js → memory-U4O5PMXH.js} +4 -4
- package/dist/{metadata-YGTHR2XJ.js → metadata-UORZTW3T.js} +21 -11
- package/dist/{metadata-ZRN2GHPN.js → metadata-VVQ3AQT5.js} +21 -11
- package/dist/{model-CLUIK3K5.js → model-JTUEO5M4.js} +2 -2
- package/dist/{sync-3REDHGY6.js → sync-MOSFNBVR.js} +5 -5
- package/dist/{te-agent-XNPELAKX.js → te-agent-IFKZDHZI.js} +25 -18
- package/dist/{te-analysis-GJI5FZUL.js → te-analysis-KOKHJJPE.js} +1225 -450
- package/dist/{te-analysis-N2BRDJZ5.js → te-analysis-LLOCCBJ4.js} +1225 -450
- package/dist/{te-community-SQXKE5OO.js → te-community-HNKVTERD.js} +207 -12
- package/dist/{te-community-TYSNU3NQ.js → te-community-IWE5B7W6.js} +208 -12
- package/dist/{te-dataops-OWIADNSM.js → te-dataops-KQPYNAE3.js} +262 -145
- package/dist/{te-dataops-5TM7WZDI.js → te-dataops-KXCEB4CS.js} +262 -145
- package/dist/{te-engage-L72HWRGO.js → te-engage-BRLSRVQT.js} +565 -16
- package/dist/{te-engage-QWM4GFS7.js → te-engage-HE4OPZIT.js} +565 -16
- package/dist/{te-experiment-2T2HEZML.js → te-experiment-K5US7RMG.js} +6 -6
- package/dist/{te-experiment-PVEY7AEZ.js → te-experiment-WA7TFMEL.js} +6 -6
- package/dist/{te-kb-VRMEY3D4.js → te-kb-OIH3T6CS.js} +4 -4
- package/dist/{te-system-XGS5EQIQ.js → te-system-AZ3URMUO.js} +515 -11
- package/dist/{te-team-BZRDV2CM.js → te-team-GZPU6UWA.js} +5 -5
- package/dist/{update-HEDXGOJH.js → update-TOBFXF2V.js} +4 -4
- package/package.json +5 -5
- package/skills/ae-agent/SKILL.md +3 -3
- package/skills/ae-agent/references/list-skill-references.md +4 -4
- package/skills/ae-agent/references/read-skill-reference.md +10 -7
- package/skills/ae-agent/references/upload-skill-reference.md +11 -9
- package/skills/ae-analysis/SKILL.md +15 -12
- package/skills/ae-analysis/metadata_resolution.md +150 -0
- package/skills/ae-analysis/references/adhoc_export.md +17 -2
- package/skills/ae-analysis/references/adhoc_run.md +12 -8
- package/skills/ae-analysis/references/ai_models.md +31 -5
- package/skills/ae-analysis/references/analysis_data_retrieval.md +104 -16
- package/skills/ae-analysis/references/analysis_drilldown_contract.md +4 -4
- package/skills/ae-analysis/references/analysis_gateway_assets.md +12 -10
- package/skills/ae-analysis/references/artifact_download.md +4 -3
- package/skills/ae-analysis/references/asset_abnormal_list.md +5 -3
- package/skills/ae-analysis/references/asset_authentication_list.md +5 -3
- package/skills/ae-analysis/references/asset_search.md +5 -3
- package/skills/ae-analysis/references/bi_panel_page_data_export.md +1 -1
- package/skills/ae-analysis/references/bi_panel_page_data_run.md +4 -4
- package/skills/ae-analysis/references/catalog_export.md +28 -0
- package/skills/ae-analysis/references/catalog_list.md +44 -0
- package/skills/ae-analysis/references/command_index.md +72 -63
- package/skills/ae-analysis/references/dashboard_report_data_run.md +11 -4
- package/skills/ae-analysis/references/datatable_version_list.md +5 -3
- package/skills/ae-analysis/references/drilldown_entities_run.md +4 -4
- package/skills/ae-analysis/references/drilldown_events_run.md +2 -2
- package/skills/ae-analysis/references/drilldown_user_events_export.md +1 -1
- package/skills/ae-analysis/references/drilldown_user_events_run.md +2 -2
- package/skills/ae-analysis/references/entity_detail_run.md +4 -4
- package/skills/ae-analysis/references/entity_id_import_options.md +1 -1
- package/skills/ae-analysis/references/event_detail_run.md +4 -4
- package/skills/ae-analysis/references/event_export.md +21 -0
- package/skills/ae-analysis/references/event_list.md +7 -6
- package/skills/ae-analysis/references/exchange_rule_list.md +5 -3
- package/skills/ae-analysis/references/history_tag_data_drilldown_export.md +4 -2
- package/skills/ae-analysis/references/history_tag_data_drilldown_run.md +2 -2
- package/skills/ae-analysis/references/history_tag_data_run.md +2 -2
- package/skills/ae-analysis/references/metric_export.md +21 -0
- package/skills/ae-analysis/references/metric_list.md +8 -7
- package/skills/ae-analysis/references/property_export.md +21 -0
- package/skills/ae-analysis/references/property_list.md +9 -8
- package/skills/ae-analysis/references/query_context_get.md +20 -0
- package/skills/ae-analysis/references/query_create_result_cluster.md +1 -1
- package/skills/ae-analysis/references/report_change_log_list.md +1 -1
- package/skills/ae-analysis/references/report_create.md +3 -3
- package/skills/ae-analysis/references/report_data_run.md +8 -8
- package/skills/ae-analysis/references/report_update.md +3 -3
- package/skills/ae-analysis/references/report_version_rollback.md +1 -1
- package/skills/ae-analysis/references/rule_list.md +6 -4
- package/skills/ae-analysis/references/run_inspect.md +8 -5
- package/skills/ae-analysis/references/run_wait.md +37 -0
- package/skills/ae-analysis/references/user_cluster_export.md +13 -0
- package/skills/ae-analysis/references/user_cluster_list.md +6 -2
- package/skills/ae-analysis/references/user_cluster_member_export.md +5 -3
- package/skills/ae-analysis/references/user_cluster_member_list.md +4 -4
- package/skills/ae-analysis/references/user_tag_export.md +13 -0
- package/skills/ae-analysis/references/user_tag_list.md +6 -2
- package/skills/ae-analysis/references/user_tag_member_export.md +5 -3
- package/skills/ae-analysis/references/user_tag_member_list.md +4 -4
- package/skills/ae-analysis/references/virtual_property_create.md +2 -2
- package/skills/ae-community/SKILL.md +2 -2
- package/skills/ae-dataops/SKILL.md +4 -3
- package/skills/ae-dataops/references/dataops-flow-create.md +47 -3
- package/skills/ae-engage/SKILL.md +46 -6
- package/skills/ae-engage/references/build-task-save-guide.md +12 -0
- package/skills/ae-engage/references/cancel-query-run.md +31 -0
- package/skills/ae-engage/references/config-item-analysis-report.md +14 -1
- package/skills/ae-engage/references/config-item-strategy-comparison.md +11 -1
- package/skills/ae-engage/references/config-item-trigger-report.md +15 -1
- package/skills/ae-engage/references/flow-metric-detail-report.md +134 -0
- package/skills/ae-engage/references/flow-metric-update.md +77 -0
- package/skills/ae-engage/references/flow-metric-user.md +118 -0
- package/skills/ae-engage/references/flow-node-metric-user.md +122 -0
- package/skills/ae-engage/references/flow-node-user.md +122 -0
- package/skills/ae-engage/references/push-record-query.md +32 -1
- package/skills/ae-engage/references/save-task.md +9 -0
- package/skills/ae-engage/references/task-data-detail.md +9 -2
- package/skills/ae-engage/references/task-metric-detail.md +9 -2
- package/skills/ae-engage/references/task-submit-approval.md +3 -0
- package/skills/ae-experiment/references/save_experiment.md +4 -0
- package/skills/ae-experiment-design/SKILL.md +1 -1
- package/skills/ae-experiment-design/references/platform-operations.md +1 -1
- package/skills/ae-experiment-insight/references/platform-operations.md +1 -1
- package/skills/ae-metadata/SKILL.md +2 -1
- package/skills/ae-metadata/references/metadata_data_table_download.md +10 -2
- package/skills/ae-metadata/references/metadata_data_table_list.md +5 -2
- package/skills/ae-system/SKILL.md +66 -3
- package/dist/chunk-DT6Y3TD7.js +0 -232
- package/dist/chunk-MVDZ7DBQ.js +0 -231
- package/dist/chunk-NBPKWKRA.js +0 -51
- package/dist/client-DAIPF7XN.js +0 -23
- package/dist/raw-52B4UKO4.js +0 -71
- package/dist/te-meta-53BVXPFI.js +0 -95
- package/dist/te-meta-TOCBPBXI.js +0 -95
|
@@ -1,20 +1,215 @@
|
|
|
1
|
-
import {
|
|
2
|
-
callMcpTool,
|
|
3
|
-
parseMcpResult,
|
|
4
|
-
registerMcpMappings,
|
|
5
|
-
resolveMcpUrl
|
|
6
|
-
} from "./chunk-DT6Y3TD7.js";
|
|
7
|
-
import "./chunk-NBPKWKRA.js";
|
|
8
1
|
import {
|
|
9
2
|
registerCapabilityGatewayRoute
|
|
10
3
|
} from "./chunk-PTE56QPL.js";
|
|
11
|
-
import "./chunk-Z3OXWCIA.js";
|
|
12
|
-
import "./chunk-YV52FB5G.js";
|
|
13
|
-
import "./chunk-GJJA4CQZ.js";
|
|
14
4
|
import {
|
|
15
|
-
|
|
5
|
+
clearCliToken,
|
|
6
|
+
getCliToken
|
|
7
|
+
} from "./chunk-S5NTSDBS.js";
|
|
8
|
+
import "./chunk-ZQKDZXDO.js";
|
|
9
|
+
import {
|
|
10
|
+
getActiveHost,
|
|
11
|
+
safeJsonParse
|
|
12
|
+
} from "./chunk-3FY3RJ26.js";
|
|
13
|
+
import {
|
|
14
|
+
CliValidationError,
|
|
15
|
+
PermissionError
|
|
16
16
|
} from "./chunk-AXDXJTPC.js";
|
|
17
|
-
import
|
|
17
|
+
import {
|
|
18
|
+
logger
|
|
19
|
+
} from "./chunk-JHENBQ5B.js";
|
|
20
|
+
|
|
21
|
+
// src/core/mcp.ts
|
|
22
|
+
async function permissionMessage(resp) {
|
|
23
|
+
const text = await resp.text().catch(() => "");
|
|
24
|
+
try {
|
|
25
|
+
const d = safeJsonParse(text);
|
|
26
|
+
const msg = d && (d.error?.message || (typeof d.error === "string" ? d.error : void 0) || d.message);
|
|
27
|
+
if (msg && typeof msg === "string") return msg;
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
return "Permission denied for this resource (HTTP 403)";
|
|
31
|
+
}
|
|
32
|
+
function isInvalidCliTokenMessage(message) {
|
|
33
|
+
return /\b(cli[-_\s]?token|token)\b.*\binvalid\b/i.test(message) || /\binvalid\b.*\b(cli[-_\s]?token|token)\b/i.test(message);
|
|
34
|
+
}
|
|
35
|
+
var MCP_PROTOCOL_VERSION = "2025-11-25";
|
|
36
|
+
var JSONRPC_VERSION = "2.0";
|
|
37
|
+
var serviceMappingMap = /* @__PURE__ */ new Map();
|
|
38
|
+
function registerMcpMappings(mappings) {
|
|
39
|
+
for (const [serviceName, mapping] of Object.entries(mappings)) {
|
|
40
|
+
serviceMappingMap.set(serviceName, mapping);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function getMcpMapping(serviceName) {
|
|
44
|
+
const mapping = serviceMappingMap.get(serviceName);
|
|
45
|
+
if (!mapping) {
|
|
46
|
+
throw new Error(`MCP mapping not found for service: '${serviceName}'. Please register it using registerMcpMapping() first.`);
|
|
47
|
+
}
|
|
48
|
+
return mapping;
|
|
49
|
+
}
|
|
50
|
+
function buildMcpUrl(host, serviceName) {
|
|
51
|
+
const mapping = getMcpMapping(serviceName);
|
|
52
|
+
const base = host.replace(/\/+$/, "");
|
|
53
|
+
return `${base}/mcp/${mapping.componentName}/http/${mapping.mappingPath}`;
|
|
54
|
+
}
|
|
55
|
+
function resolveMcpUrl(mcpUrlOverride, host, serviceName) {
|
|
56
|
+
if (mcpUrlOverride) {
|
|
57
|
+
return mcpUrlOverride;
|
|
58
|
+
}
|
|
59
|
+
return buildMcpUrl(host, serviceName);
|
|
60
|
+
}
|
|
61
|
+
var requestIdCounter = 1;
|
|
62
|
+
function genRequestId() {
|
|
63
|
+
return requestIdCounter++;
|
|
64
|
+
}
|
|
65
|
+
function buildAuthHeaders(cliToken) {
|
|
66
|
+
return {
|
|
67
|
+
"cli-token": cliToken
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async function mcpRequest(url, method, params = {}, hostOverride) {
|
|
71
|
+
const hostUrl = hostOverride || getActiveHost();
|
|
72
|
+
const token = await getCliToken(hostUrl);
|
|
73
|
+
const requestId = genRequestId();
|
|
74
|
+
const paramsWithMeta = {
|
|
75
|
+
...params,
|
|
76
|
+
_meta: { progressToken: requestId }
|
|
77
|
+
};
|
|
78
|
+
const body = {
|
|
79
|
+
jsonrpc: JSONRPC_VERSION,
|
|
80
|
+
id: requestId,
|
|
81
|
+
method,
|
|
82
|
+
params: paramsWithMeta
|
|
83
|
+
};
|
|
84
|
+
const headers = {
|
|
85
|
+
"Content-Type": "application/json",
|
|
86
|
+
"Accept": "application/json, text/event-stream",
|
|
87
|
+
"mcp-protocol-version": MCP_PROTOCOL_VERSION,
|
|
88
|
+
...buildAuthHeaders(token)
|
|
89
|
+
};
|
|
90
|
+
const resp = await fetch(url, {
|
|
91
|
+
method: "POST",
|
|
92
|
+
headers,
|
|
93
|
+
body: JSON.stringify(body)
|
|
94
|
+
});
|
|
95
|
+
if (!resp.ok) {
|
|
96
|
+
let permissionMsg;
|
|
97
|
+
if (resp.status === 403) {
|
|
98
|
+
permissionMsg = await permissionMessage(resp);
|
|
99
|
+
if (!isInvalidCliTokenMessage(permissionMsg)) {
|
|
100
|
+
throw new PermissionError(permissionMsg);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (resp.status === 401 || resp.status === 403 && permissionMsg) {
|
|
104
|
+
logger.warn(`MCP request failed (${resp.status === 403 ? permissionMsg : "HTTP 401"}) for ${hostUrl}, refreshing CLI token`);
|
|
105
|
+
clearCliToken(hostUrl);
|
|
106
|
+
const newToken = await getCliToken(hostUrl);
|
|
107
|
+
logger.info(`CLI token refreshed for ${hostUrl}`);
|
|
108
|
+
process.stderr.write(`[ae-cli] CLI token refreshed for ${hostUrl}
|
|
109
|
+
`);
|
|
110
|
+
Object.assign(headers, buildAuthHeaders(newToken));
|
|
111
|
+
const retryResp = await fetch(url, {
|
|
112
|
+
method: "POST",
|
|
113
|
+
headers,
|
|
114
|
+
body: JSON.stringify(body)
|
|
115
|
+
});
|
|
116
|
+
if (retryResp.status === 403) {
|
|
117
|
+
throw new PermissionError(await permissionMessage(retryResp));
|
|
118
|
+
}
|
|
119
|
+
if (!retryResp.ok) {
|
|
120
|
+
throw new Error(`MCP HTTP error: ${retryResp.status} ${retryResp.statusText}`);
|
|
121
|
+
}
|
|
122
|
+
const retryData = safeJsonParse(await retryResp.text());
|
|
123
|
+
if (retryData.error) {
|
|
124
|
+
throw new Error(`MCP error: ${retryData.error.message || JSON.stringify(retryData.error)}`);
|
|
125
|
+
}
|
|
126
|
+
return retryData.result;
|
|
127
|
+
}
|
|
128
|
+
throw new Error(`MCP HTTP error: ${resp.status} ${resp.statusText}`);
|
|
129
|
+
}
|
|
130
|
+
const data = safeJsonParse(await resp.text());
|
|
131
|
+
if (data.error) {
|
|
132
|
+
throw new Error(`MCP error: ${data.error.message || JSON.stringify(data.error)}`);
|
|
133
|
+
}
|
|
134
|
+
return data.result;
|
|
135
|
+
}
|
|
136
|
+
async function callMcpTool(url, toolName, args = {}, hostOverride) {
|
|
137
|
+
const params = {
|
|
138
|
+
name: toolName,
|
|
139
|
+
arguments: args
|
|
140
|
+
};
|
|
141
|
+
logger.info(`MCP tool call: ${toolName}`);
|
|
142
|
+
const result = await mcpRequest(url, "tools/call", params, hostOverride);
|
|
143
|
+
if (result.isError) {
|
|
144
|
+
logger.warn(`MCP tool call failed: ${toolName}`);
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
content: result.content.map((item) => {
|
|
148
|
+
if (item.type === "text") {
|
|
149
|
+
return { type: "text", text: item.text };
|
|
150
|
+
} else if (item.type === "image") {
|
|
151
|
+
return { type: "image", data: item.data, mimeType: item.mimeType };
|
|
152
|
+
} else {
|
|
153
|
+
return { type: "resource", ...item };
|
|
154
|
+
}
|
|
155
|
+
}),
|
|
156
|
+
isError: result.isError
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function parseMcpResult(result) {
|
|
160
|
+
if (result.isError) {
|
|
161
|
+
const firstText = result.content.find((item) => item.type === "text")?.text || "";
|
|
162
|
+
let errorMessage = firstText.trim() || "MCP tool call failed";
|
|
163
|
+
try {
|
|
164
|
+
const parsed = safeJsonParse(firstText);
|
|
165
|
+
errorMessage = mcpResultErrorMessage(parsed) || errorMessage;
|
|
166
|
+
} catch {
|
|
167
|
+
}
|
|
168
|
+
throwMcpError(errorMessage);
|
|
169
|
+
}
|
|
170
|
+
if (result.content.length > 0 && result.content[0].type === "text") {
|
|
171
|
+
const text = result.content[0].text || "";
|
|
172
|
+
let parsed;
|
|
173
|
+
try {
|
|
174
|
+
parsed = safeJsonParse(text);
|
|
175
|
+
} catch {
|
|
176
|
+
return text;
|
|
177
|
+
}
|
|
178
|
+
const errMsg = mcpResultErrorMessage(parsed);
|
|
179
|
+
if (errMsg !== null) {
|
|
180
|
+
throwMcpError(errMsg);
|
|
181
|
+
}
|
|
182
|
+
return parsed;
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
function mcpResultErrorMessage(parsed) {
|
|
187
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
188
|
+
if (parsed.success === true || parsed.ok === true) return null;
|
|
189
|
+
const explicitlyFailed = parsed.success === false || parsed.ok === false;
|
|
190
|
+
const e = parsed.error;
|
|
191
|
+
if (typeof e === "string" && e.trim()) return e;
|
|
192
|
+
if (e && typeof e === "object") {
|
|
193
|
+
const msg = typeof e.message === "string" && e.message || void 0;
|
|
194
|
+
const code = typeof e.code === "string" && e.code || void 0;
|
|
195
|
+
if (msg && code) return `${code}: ${msg}`;
|
|
196
|
+
if (msg || code) return msg || code;
|
|
197
|
+
}
|
|
198
|
+
if (explicitlyFailed) {
|
|
199
|
+
const msg = typeof parsed.message === "string" && parsed.message.trim() ? parsed.message.trim() : void 0;
|
|
200
|
+
const codeValue = parsed.errorCode ?? parsed.error_code ?? parsed.code;
|
|
201
|
+
const code = typeof codeValue === "string" && codeValue.trim() ? codeValue.trim() : void 0;
|
|
202
|
+
if (msg && code) return `${code}: ${msg}`;
|
|
203
|
+
return msg || code || "MCP tool call failed";
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
function throwMcpError(message) {
|
|
208
|
+
if (/no_auth|auth_error|permission|forbidden|unauthor|\u65e0\u6743/i.test(message)) {
|
|
209
|
+
throw new PermissionError(message);
|
|
210
|
+
}
|
|
211
|
+
throw new Error(message);
|
|
212
|
+
}
|
|
18
213
|
|
|
19
214
|
// src/commands/te-community/get_channel_info.ts
|
|
20
215
|
var getChannelInfo = {
|
|
@@ -1,20 +1,216 @@
|
|
|
1
|
-
import {
|
|
2
|
-
callMcpTool,
|
|
3
|
-
parseMcpResult,
|
|
4
|
-
registerMcpMappings,
|
|
5
|
-
resolveMcpUrl
|
|
6
|
-
} from "./chunk-MVDZ7DBQ.js";
|
|
7
|
-
import "./chunk-NBPKWKRA.js";
|
|
8
1
|
import {
|
|
9
2
|
registerCapabilityGatewayRoute
|
|
10
3
|
} from "./chunk-PTE56QPL.js";
|
|
11
|
-
import "./chunk-Z3OXWCIA.js";
|
|
12
|
-
import "./chunk-YV52FB5G.js";
|
|
13
|
-
import "./chunk-GJJA4CQZ.js";
|
|
14
4
|
import {
|
|
15
|
-
|
|
5
|
+
clearCliToken,
|
|
6
|
+
getCliToken
|
|
7
|
+
} from "./chunk-S5NTSDBS.js";
|
|
8
|
+
import "./chunk-ZQKDZXDO.js";
|
|
9
|
+
import {
|
|
10
|
+
getActiveHost,
|
|
11
|
+
safeJsonParse
|
|
12
|
+
} from "./chunk-3FY3RJ26.js";
|
|
13
|
+
import {
|
|
14
|
+
CliValidationError,
|
|
15
|
+
PermissionError
|
|
16
16
|
} from "./chunk-AXDXJTPC.js";
|
|
17
|
-
import
|
|
17
|
+
import {
|
|
18
|
+
logger
|
|
19
|
+
} from "./chunk-JHENBQ5B.js";
|
|
20
|
+
|
|
21
|
+
// src/core/mcp.ts
|
|
22
|
+
async function permissionMessage(resp) {
|
|
23
|
+
const text = await resp.text().catch(() => "");
|
|
24
|
+
try {
|
|
25
|
+
const d = safeJsonParse(text);
|
|
26
|
+
const msg = d && (d.error?.message || (typeof d.error === "string" ? d.error : void 0) || d.message);
|
|
27
|
+
if (msg && typeof msg === "string") return msg;
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
return "Permission denied for this resource (HTTP 403)";
|
|
31
|
+
}
|
|
32
|
+
function isInvalidCliTokenMessage(message) {
|
|
33
|
+
return /\b(cli[-_\s]?token|token)\b.*\binvalid\b/i.test(message) || /\binvalid\b.*\b(cli[-_\s]?token|token)\b/i.test(message);
|
|
34
|
+
}
|
|
35
|
+
var MCP_PROTOCOL_VERSION = "2025-11-25";
|
|
36
|
+
var JSONRPC_VERSION = "2.0";
|
|
37
|
+
var serviceMappingMap = /* @__PURE__ */ new Map();
|
|
38
|
+
function registerMcpMappings(mappings) {
|
|
39
|
+
for (const [serviceName, mapping] of Object.entries(mappings)) {
|
|
40
|
+
serviceMappingMap.set(serviceName, mapping);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function getMcpMapping(serviceName) {
|
|
44
|
+
const mapping = serviceMappingMap.get(serviceName);
|
|
45
|
+
if (!mapping) {
|
|
46
|
+
throw new Error(`MCP mapping not found for service: '${serviceName}'. Please register it using registerMcpMapping() first.`);
|
|
47
|
+
}
|
|
48
|
+
return mapping;
|
|
49
|
+
}
|
|
50
|
+
function buildMcpUrl(host, serviceName) {
|
|
51
|
+
const mapping = getMcpMapping(serviceName);
|
|
52
|
+
const base = host.replace(/\/+$/, "");
|
|
53
|
+
return `${base}/mcp/${mapping.componentName}/http/${mapping.mappingPath}`;
|
|
54
|
+
}
|
|
55
|
+
function resolveMcpUrl(mcpUrlOverride, host, serviceName) {
|
|
56
|
+
if (mcpUrlOverride) {
|
|
57
|
+
return mcpUrlOverride;
|
|
58
|
+
}
|
|
59
|
+
return buildMcpUrl(host, serviceName);
|
|
60
|
+
}
|
|
61
|
+
var requestIdCounter = 1;
|
|
62
|
+
function genRequestId() {
|
|
63
|
+
return requestIdCounter++;
|
|
64
|
+
}
|
|
65
|
+
function buildAuthHeaders(cliToken) {
|
|
66
|
+
return {
|
|
67
|
+
"cli-token": cliToken
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async function mcpRequest(url, method, params = {}, hostOverride) {
|
|
71
|
+
const hostUrl = hostOverride || getActiveHost();
|
|
72
|
+
const token = await getCliToken(hostUrl);
|
|
73
|
+
const requestId = genRequestId();
|
|
74
|
+
const paramsWithMeta = {
|
|
75
|
+
...params,
|
|
76
|
+
_meta: { progressToken: requestId }
|
|
77
|
+
};
|
|
78
|
+
const body = {
|
|
79
|
+
jsonrpc: JSONRPC_VERSION,
|
|
80
|
+
id: requestId,
|
|
81
|
+
method,
|
|
82
|
+
params: paramsWithMeta
|
|
83
|
+
};
|
|
84
|
+
const headers = {
|
|
85
|
+
"Content-Type": "application/json",
|
|
86
|
+
"Accept": "application/json, text/event-stream",
|
|
87
|
+
"mcp-protocol-version": MCP_PROTOCOL_VERSION,
|
|
88
|
+
"X-Source": "ae-cli",
|
|
89
|
+
...buildAuthHeaders(token)
|
|
90
|
+
};
|
|
91
|
+
const resp = await fetch(url, {
|
|
92
|
+
method: "POST",
|
|
93
|
+
headers,
|
|
94
|
+
body: JSON.stringify(body)
|
|
95
|
+
});
|
|
96
|
+
if (!resp.ok) {
|
|
97
|
+
let permissionMsg;
|
|
98
|
+
if (resp.status === 403) {
|
|
99
|
+
permissionMsg = await permissionMessage(resp);
|
|
100
|
+
if (!isInvalidCliTokenMessage(permissionMsg)) {
|
|
101
|
+
throw new PermissionError(permissionMsg);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (resp.status === 401 || resp.status === 403 && permissionMsg) {
|
|
105
|
+
logger.warn(`MCP request failed (${resp.status === 403 ? permissionMsg : "HTTP 401"}) for ${hostUrl}, refreshing CLI token`);
|
|
106
|
+
clearCliToken(hostUrl);
|
|
107
|
+
const newToken = await getCliToken(hostUrl);
|
|
108
|
+
logger.info(`CLI token refreshed for ${hostUrl}`);
|
|
109
|
+
process.stderr.write(`[ae-cli] CLI token refreshed for ${hostUrl}
|
|
110
|
+
`);
|
|
111
|
+
Object.assign(headers, buildAuthHeaders(newToken));
|
|
112
|
+
const retryResp = await fetch(url, {
|
|
113
|
+
method: "POST",
|
|
114
|
+
headers,
|
|
115
|
+
body: JSON.stringify(body)
|
|
116
|
+
});
|
|
117
|
+
if (retryResp.status === 403) {
|
|
118
|
+
throw new PermissionError(await permissionMessage(retryResp));
|
|
119
|
+
}
|
|
120
|
+
if (!retryResp.ok) {
|
|
121
|
+
throw new Error(`MCP HTTP error: ${retryResp.status} ${retryResp.statusText}`);
|
|
122
|
+
}
|
|
123
|
+
const retryData = safeJsonParse(await retryResp.text());
|
|
124
|
+
if (retryData.error) {
|
|
125
|
+
throw new Error(`MCP error: ${retryData.error.message || JSON.stringify(retryData.error)}`);
|
|
126
|
+
}
|
|
127
|
+
return retryData.result;
|
|
128
|
+
}
|
|
129
|
+
throw new Error(`MCP HTTP error: ${resp.status} ${resp.statusText}`);
|
|
130
|
+
}
|
|
131
|
+
const data = safeJsonParse(await resp.text());
|
|
132
|
+
if (data.error) {
|
|
133
|
+
throw new Error(`MCP error: ${data.error.message || JSON.stringify(data.error)}`);
|
|
134
|
+
}
|
|
135
|
+
return data.result;
|
|
136
|
+
}
|
|
137
|
+
async function callMcpTool(url, toolName, args = {}, hostOverride) {
|
|
138
|
+
const params = {
|
|
139
|
+
name: toolName,
|
|
140
|
+
arguments: args
|
|
141
|
+
};
|
|
142
|
+
logger.info(`MCP tool call: ${toolName}`);
|
|
143
|
+
const result = await mcpRequest(url, "tools/call", params, hostOverride);
|
|
144
|
+
if (result.isError) {
|
|
145
|
+
logger.warn(`MCP tool call failed: ${toolName}`);
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
content: result.content.map((item) => {
|
|
149
|
+
if (item.type === "text") {
|
|
150
|
+
return { type: "text", text: item.text };
|
|
151
|
+
} else if (item.type === "image") {
|
|
152
|
+
return { type: "image", data: item.data, mimeType: item.mimeType };
|
|
153
|
+
} else {
|
|
154
|
+
return { type: "resource", ...item };
|
|
155
|
+
}
|
|
156
|
+
}),
|
|
157
|
+
isError: result.isError
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function parseMcpResult(result) {
|
|
161
|
+
if (result.isError) {
|
|
162
|
+
const firstText = result.content.find((item) => item.type === "text")?.text || "";
|
|
163
|
+
let errorMessage = firstText.trim() || "MCP tool call failed";
|
|
164
|
+
try {
|
|
165
|
+
const parsed = safeJsonParse(firstText);
|
|
166
|
+
errorMessage = mcpResultErrorMessage(parsed) || errorMessage;
|
|
167
|
+
} catch {
|
|
168
|
+
}
|
|
169
|
+
throwMcpError(errorMessage);
|
|
170
|
+
}
|
|
171
|
+
if (result.content.length > 0 && result.content[0].type === "text") {
|
|
172
|
+
const text = result.content[0].text || "";
|
|
173
|
+
let parsed;
|
|
174
|
+
try {
|
|
175
|
+
parsed = safeJsonParse(text);
|
|
176
|
+
} catch {
|
|
177
|
+
return text;
|
|
178
|
+
}
|
|
179
|
+
const errMsg = mcpResultErrorMessage(parsed);
|
|
180
|
+
if (errMsg !== null) {
|
|
181
|
+
throwMcpError(errMsg);
|
|
182
|
+
}
|
|
183
|
+
return parsed;
|
|
184
|
+
}
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
function mcpResultErrorMessage(parsed) {
|
|
188
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
189
|
+
if (parsed.success === true || parsed.ok === true) return null;
|
|
190
|
+
const explicitlyFailed = parsed.success === false || parsed.ok === false;
|
|
191
|
+
const e = parsed.error;
|
|
192
|
+
if (typeof e === "string" && e.trim()) return e;
|
|
193
|
+
if (e && typeof e === "object") {
|
|
194
|
+
const msg = typeof e.message === "string" && e.message || void 0;
|
|
195
|
+
const code = typeof e.code === "string" && e.code || void 0;
|
|
196
|
+
if (msg && code) return `${code}: ${msg}`;
|
|
197
|
+
if (msg || code) return msg || code;
|
|
198
|
+
}
|
|
199
|
+
if (explicitlyFailed) {
|
|
200
|
+
const msg = typeof parsed.message === "string" && parsed.message.trim() ? parsed.message.trim() : void 0;
|
|
201
|
+
const codeValue = parsed.errorCode ?? parsed.error_code ?? parsed.code;
|
|
202
|
+
const code = typeof codeValue === "string" && codeValue.trim() ? codeValue.trim() : void 0;
|
|
203
|
+
if (msg && code) return `${code}: ${msg}`;
|
|
204
|
+
return msg || code || "MCP tool call failed";
|
|
205
|
+
}
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
function throwMcpError(message) {
|
|
209
|
+
if (/no_auth|auth_error|permission|forbidden|unauthor|\u65e0\u6743/i.test(message)) {
|
|
210
|
+
throw new PermissionError(message);
|
|
211
|
+
}
|
|
212
|
+
throw new Error(message);
|
|
213
|
+
}
|
|
18
214
|
|
|
19
215
|
// src/commands/te-community/get_channel_info.ts
|
|
20
216
|
var getChannelInfo = {
|