@thinkingai/ae-cli 1.0.27 → 1.0.30
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 +1 -16
- package/README.zh.md +1 -16
- package/dist/auth-H3GJD55A.js +457 -0
- package/dist/{auth-TXFJHPXU.js → auth-U25QJU5D.js} +3 -3
- package/dist/{chunk-B4UL2VIJ.js → chunk-CLJF7MQA.js} +1 -1
- package/dist/{chunk-6T7245YE.js → chunk-EGEIXA2Z.js} +90 -18
- package/dist/{chunk-2NGWYMLB.js → chunk-GLNZSDKO.js} +88 -50
- package/dist/chunk-GSJGPNKK.js +49 -0
- package/dist/{chunk-VT6VC4PA.js → chunk-I42JGQ2J.js} +26 -11
- package/dist/chunk-JM34JPCO.js +239 -0
- package/dist/chunk-NOO24N7W.js +11 -0
- package/dist/chunk-SF3KTPIC.js +98 -0
- package/dist/chunk-SRJIAOBN.js +244 -0
- package/dist/chunk-U6TKB3IV.js +171 -0
- package/dist/{chunk-TG64AQV4.js → chunk-VJFUB3H3.js} +99 -56
- package/dist/{client-IU2E5IOL.js → client-IN42F223.js} +4 -4
- package/dist/config-64G36TJL.js +130 -0
- package/dist/index.js +52 -25
- package/dist/{model-CC7U5XOJ.js → model-VZCYNIOG.js} +11 -10
- package/dist/{raw-TUHZQ4UB.js → raw-WJIWC6YP.js} +13 -7
- package/dist/{sync-EVEDS7YE.js → sync-NVASAISS.js} +146 -47
- package/dist/{te-agent-FLTDYV3L.js → te-agent-YV4DXEXK.js} +24 -23
- package/dist/{te-analysis-CMXADIJM.js → te-analysis-CB3DA5I5.js} +61 -13
- package/dist/{te-audience-LPZFFSXM.js → te-audience-W7SCQFC7.js} +7 -5
- package/dist/{te-common-BXQFKTB3.js → te-common-FBXVWBSI.js} +21 -9
- package/dist/{te-community-K5S3VOZY.js → te-community-LNVDZSGW.js} +6 -4
- package/dist/{te-dataops-567IMCQG.js → te-dataops-IPCSSWYH.js} +29 -27
- package/dist/{te-engage-TBUTGW5F.js → te-engage-KARARMIR.js} +6 -4
- package/dist/{te-kb-XHVBWP5E.js → te-kb-2Z2CARN3.js} +7 -5
- package/dist/{te-meta-NQ4U3VJW.js → te-meta-PDKLMWXN.js} +6 -4
- package/dist/{te-team-556APRIU.js → te-team-SW5B7DHO.js} +17 -12
- package/package.json +6 -2
- package/skills/ae-agent/SKILL.md +2 -1
- package/skills/ae-analysis/SKILL.md +1 -1
- package/skills/ae-analysis/references/list_clusters.md +4 -2
- package/skills/ae-analysis-global/SKILL.md +51 -0
- package/skills/ae-analysis-global/references/list_query_clusters.md +67 -0
- package/skills/ae-community/SKILL.md +2 -3
- package/skills/ae-dataops/SKILL.md +1 -2
- package/skills/ae-engage/SKILL.md +1 -0
- package/skills/ae-engage/references/add-approver.md +0 -1
- package/skills/ae-engage/references/add-channel.md +0 -1
- package/skills/ae-engage/references/approver-list.md +0 -1
- package/skills/ae-engage/references/cancel-query-by-request-id.md +0 -1
- package/skills/ae-engage/references/channel-detail.md +0 -1
- package/skills/ae-engage/references/channel-list.md +0 -1
- package/skills/ae-engage/references/config-channel-detail.md +0 -1
- package/skills/ae-engage/references/config-channel-list.md +0 -1
- package/skills/ae-engage/references/config-item-analysis-report.md +0 -1
- package/skills/ae-engage/references/config-item-detail.md +0 -1
- package/skills/ae-engage/references/config-item-list.md +0 -1
- package/skills/ae-engage/references/config-item-strategy-comparison.md +0 -1
- package/skills/ae-engage/references/config-item-trigger-report.md +0 -1
- package/skills/ae-engage/references/copy-config-template.md +0 -1
- package/skills/ae-engage/references/delete-channel.md +0 -1
- package/skills/ae-engage/references/delete-config-channel.md +0 -1
- package/skills/ae-engage/references/delete-config-item.md +0 -1
- package/skills/ae-engage/references/delete-flow.md +0 -1
- package/skills/ae-engage/references/flow-ab-split-node-report.md +0 -1
- package/skills/ae-engage/references/flow-detail.md +0 -1
- package/skills/ae-engage/references/flow-list.md +0 -1
- package/skills/ae-engage/references/flow-node-config-schema.md +0 -1
- package/skills/ae-engage/references/flow-node-detail-report.md +0 -1
- package/skills/ae-engage/references/flow-node-overview-report.md +0 -1
- package/skills/ae-engage/references/flow-process-report.md +0 -1
- package/skills/ae-engage/references/manage-flow.md +0 -1
- package/skills/ae-engage/references/manage-strategy.md +0 -1
- package/skills/ae-engage/references/manage-task.md +0 -1
- package/skills/ae-engage/references/modify-flow-base-info.md +0 -1
- package/skills/ae-engage/references/strategy-detail.md +0 -1
- package/skills/ae-engage/references/strategy-list.md +0 -1
- package/skills/ae-engage/references/task-data-detail.md +0 -1
- package/skills/ae-engage/references/task-data-overview.md +0 -1
- package/skills/ae-engage/references/task-detail.md +0 -1
- package/skills/ae-engage/references/task-experiment-report.md +0 -1
- package/skills/ae-engage/references/task-list.md +0 -1
- package/skills/ae-engage/references/task-metric-detail.md +0 -1
- package/skills/ae-engage/references/task-stats.md +0 -1
- package/skills/ae-engage/references/update-channel-status.md +0 -1
- package/skills/ae-engage/references/update-config-channel-status.md +0 -1
- package/skills/ae-engage/references/validate-flow-node-config.md +0 -1
- package/skills/ae-engage/references/whitelist-list.md +0 -1
- package/skills/ae-kb/SKILL.md +1 -0
- package/skills/ae-team/SKILL.md +1 -1
- package/dist/auth-W2JZ3DKA.js +0 -170
- package/dist/chunk-BI5ZVD6T.js +0 -186
- package/dist/chunk-MNHE6SSI.js +0 -79
- package/dist/chunk-MWWYGZ76.js +0 -130
- package/dist/chunk-SRRUNQIM.js +0 -312
- package/dist/config-WH3R3IRY.js +0 -258
package/dist/chunk-SRRUNQIM.js
DELETED
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
extractHostname,
|
|
3
|
-
getActiveHost,
|
|
4
|
-
getConfigDir,
|
|
5
|
-
safeJsonParse,
|
|
6
|
-
safeReadJsonFile
|
|
7
|
-
} from "./chunk-BI5ZVD6T.js";
|
|
8
|
-
import {
|
|
9
|
-
logger
|
|
10
|
-
} from "./chunk-MNHE6SSI.js";
|
|
11
|
-
|
|
12
|
-
// src/core/auth.ts
|
|
13
|
-
import fs from "fs";
|
|
14
|
-
import path from "path";
|
|
15
|
-
import { execFileSync } from "child_process";
|
|
16
|
-
var TOKENS_FILE = path.join(getConfigDir(), "tokens.json");
|
|
17
|
-
var MCP_TOKENS_FILE = path.join(getConfigDir(), "mcp-tokens.json");
|
|
18
|
-
var LEGACY_DIR = path.join(process.env.HOME || "", ".te-mcp");
|
|
19
|
-
var TOKEN_TTL_MS = 20 * 60 * 60 * 1e3;
|
|
20
|
-
var OSASCRIPT_POLL_INTERVAL_MS = 2e3;
|
|
21
|
-
var OSASCRIPT_POLL_TIMEOUT_MS = 6e4;
|
|
22
|
-
function ensureDir() {
|
|
23
|
-
const dir = getConfigDir();
|
|
24
|
-
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
25
|
-
}
|
|
26
|
-
function resolveHost(hostOverride) {
|
|
27
|
-
if (hostOverride) return hostOverride;
|
|
28
|
-
return getActiveHost();
|
|
29
|
-
}
|
|
30
|
-
async function validateToken(token, hostUrl) {
|
|
31
|
-
const url = `${hostUrl}/v1/oauth/checkToken?accessToken=${token}`;
|
|
32
|
-
try {
|
|
33
|
-
const resp = await fetch(url, { method: "POST" });
|
|
34
|
-
const respJson = safeJsonParse(await resp.text());
|
|
35
|
-
return respJson?.return_code === 0;
|
|
36
|
-
} catch {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function loadAllTokens() {
|
|
41
|
-
try {
|
|
42
|
-
const legacyTokens = path.join(LEGACY_DIR, "tokens.json");
|
|
43
|
-
if (fs.existsSync(legacyTokens) && !fs.existsSync(TOKENS_FILE)) {
|
|
44
|
-
const data = safeReadJsonFile(legacyTokens);
|
|
45
|
-
const migrated = {};
|
|
46
|
-
for (const [key, val] of Object.entries(data)) {
|
|
47
|
-
const url = key.startsWith("http") ? key : `https://${key}`;
|
|
48
|
-
migrated[url] = val;
|
|
49
|
-
}
|
|
50
|
-
ensureDir();
|
|
51
|
-
fs.writeFileSync(TOKENS_FILE, JSON.stringify(migrated, null, 2));
|
|
52
|
-
return migrated;
|
|
53
|
-
}
|
|
54
|
-
if (fs.existsSync(TOKENS_FILE)) {
|
|
55
|
-
const data = safeReadJsonFile(TOKENS_FILE);
|
|
56
|
-
let needsMigration = false;
|
|
57
|
-
const migrated = {};
|
|
58
|
-
for (const [key, val] of Object.entries(data)) {
|
|
59
|
-
if (!key.startsWith("http")) {
|
|
60
|
-
migrated[`https://${key}`] = val;
|
|
61
|
-
needsMigration = true;
|
|
62
|
-
} else {
|
|
63
|
-
migrated[key] = val;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (needsMigration) {
|
|
67
|
-
fs.writeFileSync(TOKENS_FILE, JSON.stringify(migrated, null, 2));
|
|
68
|
-
return migrated;
|
|
69
|
-
}
|
|
70
|
-
return data;
|
|
71
|
-
}
|
|
72
|
-
} catch {
|
|
73
|
-
}
|
|
74
|
-
return {};
|
|
75
|
-
}
|
|
76
|
-
function saveAllTokens(tokens) {
|
|
77
|
-
ensureDir();
|
|
78
|
-
fs.writeFileSync(TOKENS_FILE, JSON.stringify(tokens, null, 2));
|
|
79
|
-
}
|
|
80
|
-
function loadToken(hostUrl) {
|
|
81
|
-
const tokens = loadAllTokens();
|
|
82
|
-
const entry = tokens[hostUrl];
|
|
83
|
-
if (!entry || !entry.token) return null;
|
|
84
|
-
if (entry.updatedAt) {
|
|
85
|
-
const age = Date.now() - new Date(entry.updatedAt).getTime();
|
|
86
|
-
if (age > TOKEN_TTL_MS) {
|
|
87
|
-
clearToken(hostUrl);
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return { host: hostUrl, token: entry.token, updatedAt: entry.updatedAt };
|
|
92
|
-
}
|
|
93
|
-
function saveToken(token, hostUrl) {
|
|
94
|
-
const tokens = loadAllTokens();
|
|
95
|
-
tokens[hostUrl] = { token, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
96
|
-
saveAllTokens(tokens);
|
|
97
|
-
logger.info(`Token saved for ${hostUrl}`);
|
|
98
|
-
}
|
|
99
|
-
function clearToken(hostUrl) {
|
|
100
|
-
const tokens = loadAllTokens();
|
|
101
|
-
delete tokens[hostUrl];
|
|
102
|
-
saveAllTokens(tokens);
|
|
103
|
-
}
|
|
104
|
-
function setTokenManual(token, hostUrl) {
|
|
105
|
-
saveToken(token, hostUrl);
|
|
106
|
-
}
|
|
107
|
-
function getAuthStatus(hostUrl) {
|
|
108
|
-
if (process.env.TE_TOKEN) {
|
|
109
|
-
return { authenticated: true, host: hostUrl, source: "env:TE_TOKEN" };
|
|
110
|
-
}
|
|
111
|
-
const cached = loadToken(hostUrl);
|
|
112
|
-
if (cached) {
|
|
113
|
-
const ageMs = Date.now() - new Date(cached.updatedAt).getTime();
|
|
114
|
-
const hours = Math.round(ageMs / 36e5);
|
|
115
|
-
return { authenticated: true, host: hostUrl, tokenAge: `${hours}h ago`, source: "cache" };
|
|
116
|
-
}
|
|
117
|
-
return { authenticated: false, host: hostUrl };
|
|
118
|
-
}
|
|
119
|
-
function getCachedMcpToken(hostUrl) {
|
|
120
|
-
try {
|
|
121
|
-
if (!fs.existsSync(MCP_TOKENS_FILE)) return void 0;
|
|
122
|
-
const store = safeReadJsonFile(MCP_TOKENS_FILE);
|
|
123
|
-
const normalizedHost = hostUrl.replace(/\/+$/, "");
|
|
124
|
-
if (store[hostUrl]) return store[hostUrl];
|
|
125
|
-
if (store[normalizedHost]) return store[normalizedHost];
|
|
126
|
-
for (const [key, token] of Object.entries(store)) {
|
|
127
|
-
if (key.replace(/\/+$/, "") === normalizedHost) {
|
|
128
|
-
return token;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return void 0;
|
|
132
|
-
} catch {
|
|
133
|
-
return void 0;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
function extractTokenViaOsascript(hostUrl) {
|
|
137
|
-
if (process.platform !== "darwin") return { token: null, error: "not_mac" };
|
|
138
|
-
const hostname = extractHostname(hostUrl);
|
|
139
|
-
const lines = [
|
|
140
|
-
'tell application "Google Chrome"',
|
|
141
|
-
" repeat with w in windows",
|
|
142
|
-
" repeat with t in tabs of w",
|
|
143
|
-
` if URL of t contains "${hostname}" then`,
|
|
144
|
-
` return execute t javascript "localStorage.getItem('ACCESS_TOKEN')"`,
|
|
145
|
-
" end if",
|
|
146
|
-
" end repeat",
|
|
147
|
-
" end repeat",
|
|
148
|
-
' return "NO_TAB_FOUND"',
|
|
149
|
-
"end tell"
|
|
150
|
-
];
|
|
151
|
-
try {
|
|
152
|
-
const args = lines.flatMap((line) => ["-e", line]);
|
|
153
|
-
const result = execFileSync("osascript", args, { encoding: "utf8", timeout: 5e3 }).trim();
|
|
154
|
-
if (result === "NO_TAB_FOUND") return { token: null, error: "no_tab" };
|
|
155
|
-
if (!result || result === "missing value") return { token: null, error: "no_token" };
|
|
156
|
-
return { token: result.replace(/^["']|["']$/g, ""), error: null };
|
|
157
|
-
} catch (e) {
|
|
158
|
-
const msg = e.message || "";
|
|
159
|
-
if (msg.includes("not allowed") || msg.includes("assistive access") || msg.includes("(-1743)")) {
|
|
160
|
-
return { token: null, error: "no_js_permission" };
|
|
161
|
-
}
|
|
162
|
-
return { token: null, error: "no_tab" };
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
function extractTokenFromAllTabs() {
|
|
166
|
-
const lines = [
|
|
167
|
-
'tell application "Google Chrome"',
|
|
168
|
-
" repeat with w in windows",
|
|
169
|
-
" repeat with t in tabs of w",
|
|
170
|
-
" try",
|
|
171
|
-
` set tokenVal to execute t javascript "localStorage.getItem('ACCESS_TOKEN')"`,
|
|
172
|
-
' if tokenVal is not null and tokenVal is not missing value and tokenVal is not "" then',
|
|
173
|
-
" return tokenVal",
|
|
174
|
-
" end if",
|
|
175
|
-
" end try",
|
|
176
|
-
" end repeat",
|
|
177
|
-
" end repeat",
|
|
178
|
-
' return "NO_TOKEN_FOUND"',
|
|
179
|
-
"end tell"
|
|
180
|
-
];
|
|
181
|
-
try {
|
|
182
|
-
const args = lines.flatMap((line) => ["-e", line]);
|
|
183
|
-
const result = execFileSync("osascript", args, { encoding: "utf8", timeout: 1e4 }).trim();
|
|
184
|
-
if (result === "NO_TOKEN_FOUND" || !result || result === "missing value") {
|
|
185
|
-
return { token: null, error: "no_token" };
|
|
186
|
-
}
|
|
187
|
-
return { token: result.replace(/^["']|["']$/g, ""), error: null };
|
|
188
|
-
} catch (e) {
|
|
189
|
-
const msg = e.message || "";
|
|
190
|
-
if (msg.includes("not allowed") || msg.includes("assistive access") || msg.includes("(-1743)")) {
|
|
191
|
-
return { token: null, error: "no_js_permission" };
|
|
192
|
-
}
|
|
193
|
-
return { token: null, error: "no_tab" };
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
async function requestTokenViaOsascript(hostUrl) {
|
|
197
|
-
logger.info(`Opening Chrome to ${hostUrl} for token extraction`);
|
|
198
|
-
process.stderr.write(`[ae-cli] No AE tab found in Chrome. Opening ${hostUrl} ...
|
|
199
|
-
`);
|
|
200
|
-
process.stderr.write(`[ae-cli] Please login, then your token will be captured automatically.
|
|
201
|
-
`);
|
|
202
|
-
try {
|
|
203
|
-
const openScript = [
|
|
204
|
-
'tell application "Google Chrome"',
|
|
205
|
-
" activate",
|
|
206
|
-
" if (count of windows) > 0 then",
|
|
207
|
-
` make new tab at end of tabs of window 1 with properties {URL:"${hostUrl}"}`,
|
|
208
|
-
" else",
|
|
209
|
-
` open location "${hostUrl}"`,
|
|
210
|
-
" end if",
|
|
211
|
-
"end tell"
|
|
212
|
-
];
|
|
213
|
-
execFileSync("osascript", openScript.flatMap((line) => ["-e", line]), { timeout: 5e3 });
|
|
214
|
-
} catch {
|
|
215
|
-
logger.warn(`Failed to open Chrome, user may need to open ${hostUrl} manually`);
|
|
216
|
-
process.stderr.write(`[ae-cli] Could not open browser. Please open ${hostUrl} in Chrome manually.
|
|
217
|
-
`);
|
|
218
|
-
}
|
|
219
|
-
const deadline = Date.now() + OSASCRIPT_POLL_TIMEOUT_MS;
|
|
220
|
-
let pollCount = 0;
|
|
221
|
-
while (Date.now() < deadline) {
|
|
222
|
-
await new Promise((r) => setTimeout(r, OSASCRIPT_POLL_INTERVAL_MS));
|
|
223
|
-
pollCount++;
|
|
224
|
-
let result = extractTokenViaOsascript(hostUrl);
|
|
225
|
-
if (result.error === "no_tab") {
|
|
226
|
-
const fallback = extractTokenFromAllTabs();
|
|
227
|
-
if (fallback.token) {
|
|
228
|
-
logger.info("Token captured via all-tabs fallback search");
|
|
229
|
-
result = fallback;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
if (result.token) {
|
|
233
|
-
saveToken(result.token, hostUrl);
|
|
234
|
-
logger.info(`Token captured after ${pollCount} poll(s)`);
|
|
235
|
-
process.stderr.write(`[ae-cli] Token captured from Chrome for ${hostUrl}.
|
|
236
|
-
`);
|
|
237
|
-
return result.token;
|
|
238
|
-
}
|
|
239
|
-
if (result.error === "no_js_permission") {
|
|
240
|
-
logger.warn("Chrome JS permission denied during polling");
|
|
241
|
-
return null;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
logger.warn(`Token polling timed out after ${OSASCRIPT_POLL_TIMEOUT_MS / 1e3}s (${pollCount} polls)`);
|
|
245
|
-
process.stderr.write(`[ae-cli] Polling timed out after ${OSASCRIPT_POLL_TIMEOUT_MS / 1e3}s.
|
|
246
|
-
`);
|
|
247
|
-
return null;
|
|
248
|
-
}
|
|
249
|
-
async function getToken(hostUrl) {
|
|
250
|
-
if (!hostUrl) {
|
|
251
|
-
throw new Error(
|
|
252
|
-
`No AE host configured.
|
|
253
|
-
Run: ae-cli config set-host`
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
if (process.env.TE_TOKEN) {
|
|
257
|
-
logger.info("Using token from env:TE_TOKEN");
|
|
258
|
-
return process.env.TE_TOKEN;
|
|
259
|
-
}
|
|
260
|
-
const cached = loadToken(hostUrl);
|
|
261
|
-
if (cached && cached.token) {
|
|
262
|
-
logger.info(`Using cached token for ${hostUrl}`);
|
|
263
|
-
return cached.token;
|
|
264
|
-
}
|
|
265
|
-
if (getCachedMcpToken(hostUrl)) {
|
|
266
|
-
logger.info(`MCP token exists for ${hostUrl}; skipping browser token extraction`);
|
|
267
|
-
throw new Error(
|
|
268
|
-
`MCP token already exists for ${hostUrl}; skipped browser login.
|
|
269
|
-
Use an MCP-token aware command, or run: ae-cli auth set-token <token>`
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
const { token: osascriptToken, error } = extractTokenViaOsascript(hostUrl);
|
|
273
|
-
if (error === "no_js_permission") {
|
|
274
|
-
logger.warn("Chrome JS Apple Events not enabled");
|
|
275
|
-
throw new Error(
|
|
276
|
-
`Chrome JavaScript from Apple Events is not enabled.
|
|
277
|
-
Enable it: Chrome menu \u2192 View \u2192 Developer \u2192 Allow JavaScript from Apple Events`
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
if (error === "not_mac") {
|
|
281
|
-
throw new Error(
|
|
282
|
-
`Auto token extraction is only available on macOS + Chrome.
|
|
283
|
-
Use: ae-cli auth set-token <token>`
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
if (osascriptToken) {
|
|
287
|
-
saveToken(osascriptToken, hostUrl);
|
|
288
|
-
return osascriptToken;
|
|
289
|
-
}
|
|
290
|
-
const polledToken = await requestTokenViaOsascript(hostUrl);
|
|
291
|
-
if (polledToken) {
|
|
292
|
-
saveToken(polledToken, hostUrl);
|
|
293
|
-
return polledToken;
|
|
294
|
-
}
|
|
295
|
-
throw new Error(
|
|
296
|
-
`Cannot obtain token for ${hostUrl}.
|
|
297
|
-
Options:
|
|
298
|
-
1. ae-cli auth login (macOS + Chrome)
|
|
299
|
-
2. ae-cli auth set-token <token>`
|
|
300
|
-
);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
export {
|
|
304
|
-
resolveHost,
|
|
305
|
-
validateToken,
|
|
306
|
-
loadToken,
|
|
307
|
-
saveToken,
|
|
308
|
-
clearToken,
|
|
309
|
-
setTokenManual,
|
|
310
|
-
getAuthStatus,
|
|
311
|
-
getToken
|
|
312
|
-
};
|
package/dist/config-WH3R3IRY.js
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
clearToken,
|
|
3
|
-
getAuthStatus,
|
|
4
|
-
getToken,
|
|
5
|
-
loadToken,
|
|
6
|
-
validateToken
|
|
7
|
-
} from "./chunk-SRRUNQIM.js";
|
|
8
|
-
import {
|
|
9
|
-
addHost,
|
|
10
|
-
listHosts,
|
|
11
|
-
removeHost,
|
|
12
|
-
setActiveHost,
|
|
13
|
-
updateHostLabel
|
|
14
|
-
} from "./chunk-BI5ZVD6T.js";
|
|
15
|
-
import "./chunk-MNHE6SSI.js";
|
|
16
|
-
|
|
17
|
-
// src/commands/config.ts
|
|
18
|
-
import * as readline from "readline";
|
|
19
|
-
function registerConfig(program) {
|
|
20
|
-
program.command("config").description("Interactive AE host configuration manager").action(async () => {
|
|
21
|
-
await runConfigUI(program);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
async function runConfigUI(program) {
|
|
25
|
-
const hosts = listHosts();
|
|
26
|
-
if (hosts.length === 0) {
|
|
27
|
-
process.stderr.write("\x1B[1m[ae-cli] No AE hosts configured. Let's add one.\x1B[0m\n\n");
|
|
28
|
-
const newHost = await promptNewHost();
|
|
29
|
-
if (!newHost) {
|
|
30
|
-
process.stderr.write("Cancelled.\n");
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
addHost(newHost.url, newHost.label);
|
|
34
|
-
setActiveHost(newHost.url);
|
|
35
|
-
process.stderr.write(`
|
|
36
|
-
\x1B[32m\u2713\x1B[0m Added and activated: \x1B[1m${newHost.label}\x1B[0m ${newHost.url}
|
|
37
|
-
`);
|
|
38
|
-
await ensureAuth(newHost.url);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
await hostManagerLoop(program);
|
|
42
|
-
}
|
|
43
|
-
async function hostManagerLoop(program) {
|
|
44
|
-
while (true) {
|
|
45
|
-
const hosts = listHosts();
|
|
46
|
-
const items = hosts.map((h) => ({
|
|
47
|
-
display: formatHostLine(h),
|
|
48
|
-
type: "host",
|
|
49
|
-
url: h.url,
|
|
50
|
-
label: h.label,
|
|
51
|
-
active: h.active
|
|
52
|
-
}));
|
|
53
|
-
items.push({ display: "\x1B[2m + Add new host...\x1B[0m", type: "add", url: "", label: "", active: false });
|
|
54
|
-
const activeIdx = items.findIndex((i) => i.active);
|
|
55
|
-
process.stderr.write("\n\x1B[1mTE Host Manager\x1B[0m (\u2191\u2193 select \xB7 Enter switch \xB7 e edit label \xB7 d delete \xB7 a add \xB7 q quit)\n\n");
|
|
56
|
-
const result = await interactiveHostSelect(items, activeIdx >= 0 ? activeIdx : 0);
|
|
57
|
-
if (result.action === "quit" || result.action === "cancel") {
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
const item = items[result.index];
|
|
61
|
-
if (result.action === "select") {
|
|
62
|
-
if (item.type === "add") {
|
|
63
|
-
await handleAddHost();
|
|
64
|
-
} else {
|
|
65
|
-
setActiveHost(item.url);
|
|
66
|
-
process.stderr.write(`
|
|
67
|
-
\x1B[32m\u2713\x1B[0m Switched to: \x1B[1m${item.label}\x1B[0m ${item.url}
|
|
68
|
-
`);
|
|
69
|
-
await ensureAuth(item.url);
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
} else if (result.action === "edit" && item.type === "host") {
|
|
73
|
-
await handleEditLabel(item.url, item.label);
|
|
74
|
-
} else if (result.action === "delete" && item.type === "host") {
|
|
75
|
-
await handleDeleteHost(item.url, item.label, item.active);
|
|
76
|
-
} else if (result.action === "add") {
|
|
77
|
-
await handleAddHost();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function formatHostLine(h) {
|
|
82
|
-
const marker = h.active ? "\x1B[32m\u25CF\x1B[0m" : "\x1B[2m\u25CB\x1B[0m";
|
|
83
|
-
const labelText = h.active ? `\x1B[1;32m${h.label}\x1B[0m` : `\x1B[1m${h.label}\x1B[0m`;
|
|
84
|
-
const authInfo = getAuthStatus(h.url);
|
|
85
|
-
const authBadge = authInfo.authenticated ? `\x1B[32m\u2713\x1B[0m` : `\x1B[31m\u2717\x1B[0m`;
|
|
86
|
-
return `${marker} ${labelText} ${h.url} ${authBadge}`;
|
|
87
|
-
}
|
|
88
|
-
async function handleAddHost() {
|
|
89
|
-
const newHost = await promptNewHost();
|
|
90
|
-
if (!newHost) {
|
|
91
|
-
process.stderr.write("Cancelled.\n");
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
addHost(newHost.url, newHost.label);
|
|
95
|
-
setActiveHost(newHost.url);
|
|
96
|
-
process.stderr.write(`
|
|
97
|
-
\x1B[32m\u2713\x1B[0m Added and activated: \x1B[1m${newHost.label}\x1B[0m ${newHost.url}
|
|
98
|
-
`);
|
|
99
|
-
await ensureAuth(newHost.url);
|
|
100
|
-
}
|
|
101
|
-
async function handleEditLabel(url, currentLabel) {
|
|
102
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
|
|
103
|
-
const newLabel = await new Promise(
|
|
104
|
-
(resolve) => rl.question(`
|
|
105
|
-
New label [${currentLabel}]: `, (a) => {
|
|
106
|
-
rl.close();
|
|
107
|
-
resolve(a.trim() || currentLabel);
|
|
108
|
-
})
|
|
109
|
-
);
|
|
110
|
-
if (newLabel !== currentLabel) {
|
|
111
|
-
updateHostLabel(url, newLabel);
|
|
112
|
-
process.stderr.write(`\x1B[32m\u2713\x1B[0m Label updated: ${newLabel}
|
|
113
|
-
`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
async function handleDeleteHost(url, label, isActive) {
|
|
117
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
|
|
118
|
-
const answer = await new Promise(
|
|
119
|
-
(resolve) => rl.question(`
|
|
120
|
-
Delete \x1B[1m${label}\x1B[0m (${url})? [y/N]: `, (a) => {
|
|
121
|
-
rl.close();
|
|
122
|
-
resolve(a.trim().toLowerCase());
|
|
123
|
-
})
|
|
124
|
-
);
|
|
125
|
-
if (answer === "y" || answer === "yes") {
|
|
126
|
-
removeHost(url);
|
|
127
|
-
process.stderr.write(`\x1B[32m\u2713\x1B[0m Deleted: ${label}
|
|
128
|
-
`);
|
|
129
|
-
if (isActive) {
|
|
130
|
-
const remaining = listHosts();
|
|
131
|
-
if (remaining.length > 0) {
|
|
132
|
-
process.stderr.write(` Active host switched to: ${remaining[0].label}
|
|
133
|
-
`);
|
|
134
|
-
} else {
|
|
135
|
-
process.stderr.write(" No hosts remaining. Run ae-cli config to add one.\n");
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
async function ensureAuth(hostUrl) {
|
|
141
|
-
const status = getAuthStatus(hostUrl);
|
|
142
|
-
if (status.authenticated) {
|
|
143
|
-
const cached = loadToken(hostUrl);
|
|
144
|
-
if (cached && cached.token) {
|
|
145
|
-
process.stderr.write(`\x1B[2m[ae-cli] Validating token...\x1B[0m
|
|
146
|
-
`);
|
|
147
|
-
const isValid = await validateToken(cached.token, hostUrl);
|
|
148
|
-
if (isValid) {
|
|
149
|
-
process.stderr.write(`\x1B[32m\u2713\x1B[0m Token valid for ${hostUrl}
|
|
150
|
-
`);
|
|
151
|
-
return;
|
|
152
|
-
} else {
|
|
153
|
-
clearToken(hostUrl);
|
|
154
|
-
process.stderr.write(`\x1B[33m!\x1B[0m Token expired or invalid. Re-authenticating...
|
|
155
|
-
`);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
process.stderr.write(`
|
|
160
|
-
\x1B[33m!\x1B[0m No valid token for ${hostUrl}. Starting login...
|
|
161
|
-
`);
|
|
162
|
-
try {
|
|
163
|
-
await getToken(hostUrl);
|
|
164
|
-
process.stderr.write(`\x1B[32m\u2713\x1B[0m Authenticated to ${hostUrl}
|
|
165
|
-
`);
|
|
166
|
-
} catch (err) {
|
|
167
|
-
process.stderr.write(`\x1B[31m\u2717\x1B[0m Auth failed: ${err.message}
|
|
168
|
-
`);
|
|
169
|
-
process.stderr.write(` You can set token manually: ae-cli auth set-token <token>
|
|
170
|
-
`);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
async function promptNewHost() {
|
|
174
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
|
|
175
|
-
const ask = (q) => new Promise((resolve) => rl.question(q, (a) => resolve(a.trim())));
|
|
176
|
-
const url = await ask("AE host URL (e.g., https://ta.thinkingdata.cn): ");
|
|
177
|
-
if (!url) {
|
|
178
|
-
rl.close();
|
|
179
|
-
return null;
|
|
180
|
-
}
|
|
181
|
-
const label = await ask("Label: ");
|
|
182
|
-
rl.close();
|
|
183
|
-
if (!label) return null;
|
|
184
|
-
return { url: normalizeUrl(url), label };
|
|
185
|
-
}
|
|
186
|
-
function normalizeUrl(url) {
|
|
187
|
-
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
|
188
|
-
url = `https://${url}`;
|
|
189
|
-
}
|
|
190
|
-
return url.replace(/\/$/, "");
|
|
191
|
-
}
|
|
192
|
-
function interactiveHostSelect(items, initialIndex) {
|
|
193
|
-
return new Promise((resolve) => {
|
|
194
|
-
let cursor = initialIndex;
|
|
195
|
-
const stdin = process.stdin;
|
|
196
|
-
const stderr = process.stderr;
|
|
197
|
-
let renderCount = 0;
|
|
198
|
-
stderr.write("\x1B[?25l");
|
|
199
|
-
function render() {
|
|
200
|
-
if (renderCount > 0) {
|
|
201
|
-
stderr.write(`\x1B[${items.length}A`);
|
|
202
|
-
}
|
|
203
|
-
for (let i = 0; i < items.length; i++) {
|
|
204
|
-
const pointer = i === cursor ? "\x1B[36m\u276F\x1B[0m" : " ";
|
|
205
|
-
stderr.write(`${pointer} ${items[i].display}\x1B[K
|
|
206
|
-
`);
|
|
207
|
-
}
|
|
208
|
-
renderCount++;
|
|
209
|
-
}
|
|
210
|
-
render();
|
|
211
|
-
if (!stdin.isTTY) {
|
|
212
|
-
stderr.write("\x1B[?25h");
|
|
213
|
-
resolve({ action: "select", index: initialIndex });
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
stdin.setRawMode(true);
|
|
217
|
-
stdin.resume();
|
|
218
|
-
stdin.setEncoding("utf8");
|
|
219
|
-
function cleanup() {
|
|
220
|
-
stdin.setRawMode(false);
|
|
221
|
-
stdin.pause();
|
|
222
|
-
stdin.removeListener("data", onData);
|
|
223
|
-
stderr.write("\x1B[?25h");
|
|
224
|
-
}
|
|
225
|
-
function onData(key) {
|
|
226
|
-
if (key === "\x1B[A" || key === "k") {
|
|
227
|
-
cursor = (cursor - 1 + items.length) % items.length;
|
|
228
|
-
render();
|
|
229
|
-
} else if (key === "\x1B[B" || key === "j") {
|
|
230
|
-
cursor = (cursor + 1) % items.length;
|
|
231
|
-
render();
|
|
232
|
-
} else if (key === "\r" || key === "\n") {
|
|
233
|
-
cleanup();
|
|
234
|
-
resolve({ action: "select", index: cursor });
|
|
235
|
-
} else if (key === "e" || key === "E") {
|
|
236
|
-
if (items[cursor].type === "host") {
|
|
237
|
-
cleanup();
|
|
238
|
-
resolve({ action: "edit", index: cursor });
|
|
239
|
-
}
|
|
240
|
-
} else if (key === "d" || key === "D") {
|
|
241
|
-
if (items[cursor].type === "host") {
|
|
242
|
-
cleanup();
|
|
243
|
-
resolve({ action: "delete", index: cursor });
|
|
244
|
-
}
|
|
245
|
-
} else if (key === "a" || key === "A") {
|
|
246
|
-
cleanup();
|
|
247
|
-
resolve({ action: "add", index: cursor });
|
|
248
|
-
} else if (key === "q" || key === "Q" || key === "\x1B" || key === "") {
|
|
249
|
-
cleanup();
|
|
250
|
-
resolve({ action: "quit", index: cursor });
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
stdin.on("data", onData);
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
export {
|
|
257
|
-
registerConfig
|
|
258
|
-
};
|