@thinkingai/ae-cli 1.0.22 → 1.0.27
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 +39 -1
- package/README.zh.md +40 -1
- package/dist/{auth-YM7OI23X.js → auth-TXFJHPXU.js} +3 -2
- package/dist/{auth-5S7SPPEJ.js → auth-W2JZ3DKA.js} +11 -4
- package/dist/{chunk-MPFTXJFG.js → chunk-2NGWYMLB.js} +14 -2
- package/dist/chunk-6T7245YE.js +478 -0
- package/dist/{chunk-KM57HI5B.js → chunk-B4UL2VIJ.js} +7 -1
- package/dist/{chunk-TMMUBSKW.js → chunk-BI5ZVD6T.js} +8 -1
- package/dist/chunk-MNHE6SSI.js +79 -0
- package/dist/chunk-MWWYGZ76.js +130 -0
- package/dist/{chunk-24ZKQWG2.js → chunk-SRRUNQIM.js} +51 -4
- package/dist/chunk-TG64AQV4.js +262 -0
- package/dist/{chunk-NBFTPIAH.js → chunk-VT6VC4PA.js} +15 -4
- package/dist/{client-7S23DVHH.js → client-IU2E5IOL.js} +6 -3
- package/dist/{config-RVUESJRF.js → config-WH3R3IRY.js} +3 -2
- package/dist/index.js +195 -20
- package/dist/model-CC7U5XOJ.js +131 -0
- package/dist/{raw-5SYAUCJQ.js → raw-TUHZQ4UB.js} +5 -4
- package/dist/sync-EVEDS7YE.js +383 -0
- package/dist/te-agent-FLTDYV3L.js +522 -0
- package/dist/{te-analysis-RQST6AT3.js → te-analysis-CMXADIJM.js} +101 -12
- package/dist/{te-audience-TJ74UJI3.js → te-audience-LPZFFSXM.js} +4 -3
- package/dist/{te-common-W5URM2SH.js → te-common-BXQFKTB3.js} +4 -3
- package/dist/{te-community-YRV2VAD4.js → te-community-K5S3VOZY.js} +4 -3
- package/dist/{te-dataops-ZPH72BCK.js → te-dataops-567IMCQG.js} +4 -3
- package/dist/{te-engage-57UKFV74.js → te-engage-TBUTGW5F.js} +105 -49
- package/dist/{te-kb-GD7SJRYB.js → te-kb-XHVBWP5E.js} +227 -38
- package/dist/{te-meta-25SLZFXJ.js → te-meta-NQ4U3VJW.js} +25 -4
- package/dist/te-team-556APRIU.js +529 -0
- package/package.json +6 -1
- package/skills/ae-agent/SKILL.md +133 -0
- package/skills/ae-analysis/references/create_entity.md +39 -0
- package/skills/ae-analysis/references/create_space.md +34 -0
- package/skills/ae-analysis/references/drilldown_user_events.md +1 -1
- package/skills/ae-analysis/references/drilldown_users.md +2 -2
- package/skills/ae-analysis/references/query_adhoc.md +3 -2
- package/skills/ae-analysis/references/query_entity_details.md +1 -1
- package/skills/ae-engage/SKILL.md +25 -2
- package/skills/ae-engage/references/build-task-save-guide.md +283 -0
- package/skills/ae-engage/references/save-task.md +304 -0
- package/skills/ae-kb/SKILL.md +283 -0
- package/skills/ae-team/SKILL.md +164 -0
- package/skills/ae-team/references/ai-generate.md +39 -0
- package/skills/ae-team/references/create.md +94 -0
- package/skills/ae-team/references/delete.md +39 -0
- package/skills/ae-team/references/list-projects.md +45 -0
- package/skills/ae-team/references/list-templates.md +38 -0
- package/skills/ae-team/references/list.md +39 -0
- package/skills/ae-team/references/run-artifacts.md +51 -0
- package/skills/ae-team/references/run-cancel.md +38 -0
- package/skills/ae-team/references/run-chat.md +57 -0
- package/skills/ae-team/references/run-reply.md +41 -0
- package/skills/ae-team/references/run-result.md +75 -0
- package/skills/ae-team/references/run-start.md +73 -0
- package/skills/ae-team/references/run-watch.md +82 -0
- package/skills/ae-team/references/update.md +47 -0
package/dist/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
printError,
|
|
3
3
|
printOutput
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-B4UL2VIJ.js";
|
|
5
5
|
import {
|
|
6
6
|
getActiveHost,
|
|
7
7
|
safeJsonParse
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-BI5ZVD6T.js";
|
|
9
|
+
import {
|
|
10
|
+
logger
|
|
11
|
+
} from "./chunk-MNHE6SSI.js";
|
|
9
12
|
|
|
10
13
|
// src/index.ts
|
|
11
14
|
import { Command as CommanderCommand } from "commander";
|
|
@@ -16,6 +19,8 @@ import * as readline from "readline";
|
|
|
16
19
|
async function runCommand(cmd, opts, globalOpts) {
|
|
17
20
|
try {
|
|
18
21
|
const ctx = createRuntimeContext(cmd, opts, globalOpts);
|
|
22
|
+
const cmdName = `${cmd.service} ${cmd.command}`;
|
|
23
|
+
logger.command(cmdName, opts);
|
|
19
24
|
for (const flag of cmd.flags) {
|
|
20
25
|
if (flag.required) {
|
|
21
26
|
const val = opts[camelCase(flag.name)];
|
|
@@ -48,6 +53,7 @@ async function runCommand(cmd, opts, globalOpts) {
|
|
|
48
53
|
ctx.out(result);
|
|
49
54
|
} catch (err) {
|
|
50
55
|
const message = err.message || String(err);
|
|
56
|
+
logger.error(`Command failed: ${message}`);
|
|
51
57
|
if (message.includes("token") || message.includes("auth") || message.includes("401") || message.includes("403")) {
|
|
52
58
|
printError("auth", message, "Run: ae-cli auth login");
|
|
53
59
|
} else if (message.includes("AE API error")) {
|
|
@@ -62,7 +68,7 @@ function createRuntimeContext(cmd, opts, globalOpts) {
|
|
|
62
68
|
let _clientModule = null;
|
|
63
69
|
async function getClient() {
|
|
64
70
|
if (!_clientModule) {
|
|
65
|
-
_clientModule = await import("./client-
|
|
71
|
+
_clientModule = await import("./client-IU2E5IOL.js");
|
|
66
72
|
}
|
|
67
73
|
return _clientModule;
|
|
68
74
|
}
|
|
@@ -88,12 +94,12 @@ function createRuntimeContext(cmd, opts, globalOpts) {
|
|
|
88
94
|
process.exit(1);
|
|
89
95
|
}
|
|
90
96
|
},
|
|
91
|
-
async api(method,
|
|
97
|
+
async api(method, path2, params, data) {
|
|
92
98
|
const client = await getClient();
|
|
93
99
|
if (method.toUpperCase() === "GET") {
|
|
94
|
-
return client.httpGet(
|
|
100
|
+
return client.httpGet(path2, params, ctx.host());
|
|
95
101
|
} else {
|
|
96
|
-
return client.
|
|
102
|
+
return client.httpRequest(method, path2, params, data, ctx.host());
|
|
97
103
|
}
|
|
98
104
|
},
|
|
99
105
|
async querySql(projectId, sql) {
|
|
@@ -105,7 +111,7 @@ function createRuntimeContext(cmd, opts, globalOpts) {
|
|
|
105
111
|
return client.queryReportData(projectId, reportId, qp, eventModel, options, ctx.host());
|
|
106
112
|
},
|
|
107
113
|
async token() {
|
|
108
|
-
const { getToken } = await import("./auth-
|
|
114
|
+
const { getToken } = await import("./auth-TXFJHPXU.js");
|
|
109
115
|
return getToken(ctx.host());
|
|
110
116
|
},
|
|
111
117
|
host() {
|
|
@@ -202,82 +208,251 @@ function extractGlobalOptions(program2) {
|
|
|
202
208
|
};
|
|
203
209
|
}
|
|
204
210
|
|
|
211
|
+
// src/core/update-check.ts
|
|
212
|
+
import fs from "fs";
|
|
213
|
+
import path from "path";
|
|
214
|
+
var CONFIG_DIR = path.join(process.env.HOME || "", ".ae-cli");
|
|
215
|
+
var CACHE_FILE = path.join(CONFIG_DIR, "update-check.json");
|
|
216
|
+
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
217
|
+
var FETCH_TIMEOUT_MS = 3e3;
|
|
218
|
+
var REGISTRY_BY_PACKAGE = {
|
|
219
|
+
"@thinkingai/ae-cli": "https://registry.npmjs.org"
|
|
220
|
+
};
|
|
221
|
+
var UPDATE_CHECK_PACKAGE = "@thinkingai/ae-cli";
|
|
222
|
+
function isUpdateCheckEnabled(packageName) {
|
|
223
|
+
return packageName === UPDATE_CHECK_PACKAGE;
|
|
224
|
+
}
|
|
225
|
+
var DEFAULT_REGISTRY = "https://registry.npmjs.org";
|
|
226
|
+
function parseVersion(version2) {
|
|
227
|
+
const core = version2.trim().split("-")[0];
|
|
228
|
+
return core.split(".").map((part) => {
|
|
229
|
+
const n = Number.parseInt(part, 10);
|
|
230
|
+
return Number.isFinite(n) ? n : 0;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
function isNewer(latest, current) {
|
|
234
|
+
const a = parseVersion(latest);
|
|
235
|
+
const b = parseVersion(current);
|
|
236
|
+
const len = Math.max(a.length, b.length, 3);
|
|
237
|
+
for (let i = 0; i < len; i += 1) {
|
|
238
|
+
const av = a[i] ?? 0;
|
|
239
|
+
const bv = b[i] ?? 0;
|
|
240
|
+
if (av > bv) return true;
|
|
241
|
+
if (av < bv) return false;
|
|
242
|
+
}
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
function resolveRegistry(packageName) {
|
|
246
|
+
if (REGISTRY_BY_PACKAGE[packageName]) {
|
|
247
|
+
return REGISTRY_BY_PACKAGE[packageName];
|
|
248
|
+
}
|
|
249
|
+
const envRegistry = process.env.npm_config_registry?.replace(/\/$/, "");
|
|
250
|
+
return envRegistry || DEFAULT_REGISTRY;
|
|
251
|
+
}
|
|
252
|
+
function buildInstallCommand(packageName, registry) {
|
|
253
|
+
const base = `npm install -g ${packageName}@latest`;
|
|
254
|
+
if (registry === DEFAULT_REGISTRY) {
|
|
255
|
+
return base;
|
|
256
|
+
}
|
|
257
|
+
return `${base} --registry=${registry}`;
|
|
258
|
+
}
|
|
259
|
+
function shouldSkipUpdateCheck(argv = process.argv) {
|
|
260
|
+
if (process.env.AE_CLI_NO_UPDATE_CHECK === "1") return true;
|
|
261
|
+
if (process.env.CI === "true" || process.env.CI === "1") return true;
|
|
262
|
+
return argv.slice(2).some((arg) => {
|
|
263
|
+
if (arg === "--no-update-check") return true;
|
|
264
|
+
if (arg === "--version" || arg === "-V" || arg === "--help" || arg === "-h") return true;
|
|
265
|
+
return false;
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
function ensureConfigDir() {
|
|
269
|
+
if (!fs.existsSync(CONFIG_DIR)) {
|
|
270
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function readCache() {
|
|
274
|
+
try {
|
|
275
|
+
if (!fs.existsSync(CACHE_FILE)) return null;
|
|
276
|
+
const raw = fs.readFileSync(CACHE_FILE, "utf8");
|
|
277
|
+
const data = JSON.parse(raw);
|
|
278
|
+
if (!data.packageName || !data.latestVersion || !data.lastCheckedAt) return null;
|
|
279
|
+
return data;
|
|
280
|
+
} catch {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function writeCache(cache) {
|
|
285
|
+
try {
|
|
286
|
+
ensureConfigDir();
|
|
287
|
+
fs.writeFileSync(CACHE_FILE, JSON.stringify(cache, null, 2));
|
|
288
|
+
} catch {
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function cacheIsStale(cache, packageName) {
|
|
292
|
+
if (!cache || cache.packageName !== packageName) return true;
|
|
293
|
+
const age = Date.now() - new Date(cache.lastCheckedAt).getTime();
|
|
294
|
+
return age >= CHECK_INTERVAL_MS;
|
|
295
|
+
}
|
|
296
|
+
function printUpdateNotice(current, latest, installCommand) {
|
|
297
|
+
process.stderr.write(`[ae-cli] Update available: ${current} \u2192 ${latest}
|
|
298
|
+
`);
|
|
299
|
+
process.stderr.write(` Run: ${installCommand}
|
|
300
|
+
`);
|
|
301
|
+
}
|
|
302
|
+
async function fetchLatestVersion(packageName, registry) {
|
|
303
|
+
const url = `${registry.replace(/\/$/, "")}/${encodeURIComponent(packageName)}`;
|
|
304
|
+
const controller = new AbortController();
|
|
305
|
+
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
306
|
+
try {
|
|
307
|
+
const resp = await fetch(url, {
|
|
308
|
+
signal: controller.signal,
|
|
309
|
+
headers: { Accept: "application/json" }
|
|
310
|
+
});
|
|
311
|
+
if (!resp.ok) return null;
|
|
312
|
+
const data = await resp.json();
|
|
313
|
+
const latest = data["dist-tags"]?.latest;
|
|
314
|
+
return typeof latest === "string" && latest.trim() ? latest.trim() : null;
|
|
315
|
+
} catch {
|
|
316
|
+
return null;
|
|
317
|
+
} finally {
|
|
318
|
+
clearTimeout(timer);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
async function refreshCache(pkg2, registry) {
|
|
322
|
+
const latest = await fetchLatestVersion(pkg2.name, registry);
|
|
323
|
+
if (!latest) return readCache();
|
|
324
|
+
const cache = {
|
|
325
|
+
packageName: pkg2.name,
|
|
326
|
+
currentVersion: pkg2.version,
|
|
327
|
+
latestVersion: latest,
|
|
328
|
+
lastCheckedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
329
|
+
};
|
|
330
|
+
writeCache(cache);
|
|
331
|
+
return cache;
|
|
332
|
+
}
|
|
333
|
+
function maybeNotifyFromCache(pkg2, cache, registry) {
|
|
334
|
+
if (!cache || cache.packageName !== pkg2.name) return;
|
|
335
|
+
if (!isNewer(cache.latestVersion, pkg2.version)) return;
|
|
336
|
+
printUpdateNotice(pkg2.version, cache.latestVersion, buildInstallCommand(pkg2.name, registry));
|
|
337
|
+
}
|
|
338
|
+
function notifyIfUpdateAvailable(pkg2) {
|
|
339
|
+
if (!isUpdateCheckEnabled(pkg2.name)) return;
|
|
340
|
+
if (shouldSkipUpdateCheck()) return;
|
|
341
|
+
const registry = resolveRegistry(pkg2.name);
|
|
342
|
+
const cache = readCache();
|
|
343
|
+
maybeNotifyFromCache(pkg2, cache, registry);
|
|
344
|
+
if (!cacheIsStale(cache, pkg2.name)) return;
|
|
345
|
+
void refreshCache(pkg2, registry).then((fresh) => {
|
|
346
|
+
if (!fresh) return;
|
|
347
|
+
if (cache && fresh.latestVersion === cache.latestVersion) return;
|
|
348
|
+
maybeNotifyFromCache(pkg2, fresh, registry);
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
|
|
205
352
|
// src/index.ts
|
|
206
353
|
var require2 = createRequire(import.meta.url);
|
|
207
|
-
var
|
|
354
|
+
var pkg = require2("../package.json");
|
|
355
|
+
var { version } = pkg;
|
|
208
356
|
var program = new CommanderCommand();
|
|
209
|
-
program.name("ae-cli").version(version).description("CLI tool for ThinkingAI (AE) analytics platform").option("--host <url>", "Override active AE host URL (e.g., https://ta.thinkingdata.cn)").option("--mcp-url <url>", "Override MCP server URL (e.g., http://localhost/mcp/http/example)").option("--format <format>", "Output format: json | table", "json").option("--jq <expr>", "jq filter expression").option("--dry-run", "Show request details without executing", false).option("--yes", "Skip confirmation for write operations", false);
|
|
357
|
+
program.name("ae-cli").version(version).description("CLI tool for ThinkingAI (AE) analytics platform").option("--host <url>", "Override active AE host URL (e.g., https://ta.thinkingdata.cn)").option("--mcp-url <url>", "Override MCP server URL (e.g., http://localhost/mcp/http/example)").option("--format <format>", "Output format: json | table", "json").option("--jq <expr>", "jq filter expression").option("--dry-run", "Show request details without executing", false).option("--yes", "Skip confirmation for write operations", false).option("--no-update-check", "Skip checking for newer ae-cli versions", false);
|
|
210
358
|
async function loadCommands() {
|
|
211
359
|
const commands = [];
|
|
212
360
|
try {
|
|
213
|
-
const teAnalysis = await import("./te-analysis-
|
|
361
|
+
const teAnalysis = await import("./te-analysis-CMXADIJM.js");
|
|
214
362
|
commands.push(...teAnalysis.default);
|
|
215
363
|
} catch {
|
|
216
364
|
}
|
|
217
365
|
try {
|
|
218
|
-
const teAudience = await import("./te-audience-
|
|
366
|
+
const teAudience = await import("./te-audience-LPZFFSXM.js");
|
|
219
367
|
commands.push(...teAudience.default);
|
|
220
368
|
} catch {
|
|
221
369
|
}
|
|
222
370
|
try {
|
|
223
|
-
const teMeta = await import("./te-meta-
|
|
371
|
+
const teMeta = await import("./te-meta-NQ4U3VJW.js");
|
|
224
372
|
commands.push(...teMeta.default);
|
|
225
373
|
} catch {
|
|
226
374
|
}
|
|
227
375
|
try {
|
|
228
|
-
const teCommon = await import("./te-common-
|
|
376
|
+
const teCommon = await import("./te-common-BXQFKTB3.js");
|
|
229
377
|
commands.push(...teCommon.default);
|
|
230
378
|
} catch {
|
|
231
379
|
}
|
|
232
380
|
try {
|
|
233
|
-
const engage = await import("./te-engage-
|
|
381
|
+
const engage = await import("./te-engage-TBUTGW5F.js");
|
|
234
382
|
commands.push(...engage.default);
|
|
235
383
|
} catch {
|
|
236
384
|
}
|
|
237
385
|
try {
|
|
238
|
-
const community = await import("./te-community-
|
|
386
|
+
const community = await import("./te-community-K5S3VOZY.js");
|
|
239
387
|
commands.push(...community.default);
|
|
240
388
|
} catch {
|
|
241
389
|
}
|
|
242
390
|
try {
|
|
243
|
-
const dataops = await import("./te-dataops-
|
|
391
|
+
const dataops = await import("./te-dataops-567IMCQG.js");
|
|
244
392
|
commands.push(...dataops.default);
|
|
245
393
|
} catch {
|
|
246
394
|
}
|
|
247
395
|
try {
|
|
248
|
-
const teKb = await import("./te-kb-
|
|
396
|
+
const teKb = await import("./te-kb-XHVBWP5E.js");
|
|
249
397
|
commands.push(...teKb.default);
|
|
250
398
|
} catch {
|
|
251
399
|
}
|
|
400
|
+
try {
|
|
401
|
+
const teTeam = await import("./te-team-556APRIU.js");
|
|
402
|
+
commands.push(...teTeam.default);
|
|
403
|
+
} catch {
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
const teAgent = await import("./te-agent-FLTDYV3L.js");
|
|
407
|
+
commands.push(...teAgent.default);
|
|
408
|
+
} catch {
|
|
409
|
+
}
|
|
252
410
|
return commands;
|
|
253
411
|
}
|
|
254
412
|
async function registerAuthCommands() {
|
|
255
413
|
try {
|
|
256
|
-
const { registerAuth } = await import("./auth-
|
|
414
|
+
const { registerAuth } = await import("./auth-W2JZ3DKA.js");
|
|
257
415
|
registerAuth(program);
|
|
258
416
|
} catch {
|
|
259
417
|
}
|
|
260
418
|
}
|
|
261
419
|
async function registerConfigCommands() {
|
|
262
420
|
try {
|
|
263
|
-
const { registerConfig } = await import("./config-
|
|
421
|
+
const { registerConfig } = await import("./config-WH3R3IRY.js");
|
|
264
422
|
registerConfig(program);
|
|
265
423
|
} catch {
|
|
266
424
|
}
|
|
267
425
|
}
|
|
268
426
|
async function registerApiCommand() {
|
|
269
427
|
try {
|
|
270
|
-
const { registerApi } = await import("./raw-
|
|
428
|
+
const { registerApi } = await import("./raw-TUHZQ4UB.js");
|
|
271
429
|
registerApi(program);
|
|
272
430
|
} catch {
|
|
273
431
|
}
|
|
274
432
|
}
|
|
433
|
+
async function registerSyncCommand() {
|
|
434
|
+
try {
|
|
435
|
+
const { registerSync } = await import("./sync-EVEDS7YE.js");
|
|
436
|
+
registerSync(program);
|
|
437
|
+
} catch {
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
async function registerModelCommand() {
|
|
441
|
+
try {
|
|
442
|
+
const { registerModel } = await import("./model-CC7U5XOJ.js");
|
|
443
|
+
registerModel(program);
|
|
444
|
+
} catch {
|
|
445
|
+
}
|
|
446
|
+
}
|
|
275
447
|
async function main() {
|
|
448
|
+
notifyIfUpdateAvailable({ name: pkg.name, version: pkg.version });
|
|
276
449
|
const commands = await loadCommands();
|
|
277
450
|
registerCommands(program, commands);
|
|
278
451
|
await registerAuthCommands();
|
|
279
452
|
await registerConfigCommands();
|
|
280
453
|
await registerApiCommand();
|
|
454
|
+
await registerSyncCommand();
|
|
455
|
+
await registerModelCommand();
|
|
281
456
|
program.parse();
|
|
282
457
|
}
|
|
283
458
|
main();
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MultiselectCancelled,
|
|
3
|
+
getCurrentWorkspace,
|
|
4
|
+
promptSingleCheckboxSelect
|
|
5
|
+
} from "./chunk-6T7245YE.js";
|
|
6
|
+
import {
|
|
7
|
+
TeAgentApiError,
|
|
8
|
+
TeAgentCredentialsError,
|
|
9
|
+
getClaudeConfigDir,
|
|
10
|
+
getSandboxModels,
|
|
11
|
+
postSandboxModelSelection
|
|
12
|
+
} from "./chunk-TG64AQV4.js";
|
|
13
|
+
|
|
14
|
+
// src/commands/model/index.ts
|
|
15
|
+
import { existsSync, readFileSync } from "fs";
|
|
16
|
+
import { join } from "path";
|
|
17
|
+
function readCurrentModelSelection() {
|
|
18
|
+
const settingsPath = join(getClaudeConfigDir(), "settings.json");
|
|
19
|
+
if (!existsSync(settingsPath)) return { routingModelId: null, providerModelId: null };
|
|
20
|
+
try {
|
|
21
|
+
const raw = readFileSync(settingsPath, "utf8");
|
|
22
|
+
const parsed = JSON.parse(raw);
|
|
23
|
+
if (!parsed || typeof parsed !== "object") {
|
|
24
|
+
return { routingModelId: null, providerModelId: null };
|
|
25
|
+
}
|
|
26
|
+
const env = parsed.env && typeof parsed.env === "object" ? parsed.env : {};
|
|
27
|
+
const headers = typeof env.ANTHROPIC_CUSTOM_HEADERS === "string" ? env.ANTHROPIC_CUSTOM_HEADERS : void 0;
|
|
28
|
+
const routingModelId = extractModelIdHeader(headers);
|
|
29
|
+
const providerModelId = typeof parsed.model === "string" && parsed.model ? parsed.model : typeof env.ANTHROPIC_MODEL === "string" && env.ANTHROPIC_MODEL ? env.ANTHROPIC_MODEL : null;
|
|
30
|
+
return { routingModelId, providerModelId };
|
|
31
|
+
} catch {
|
|
32
|
+
return { routingModelId: null, providerModelId: null };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function extractModelIdHeader(headers) {
|
|
36
|
+
if (!headers) return null;
|
|
37
|
+
for (const line of headers.split(/\r?\n/)) {
|
|
38
|
+
const match = line.match(/^\s*model-id\s*:\s*(.+?)\s*$/);
|
|
39
|
+
if (match?.[1]) {
|
|
40
|
+
return match[1];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
function isCurrentModel(model, current) {
|
|
46
|
+
if (current.routingModelId) return model.id === current.routingModelId;
|
|
47
|
+
return model.scope === "system" && Boolean(current.providerModelId) && model.modelId === current.providerModelId;
|
|
48
|
+
}
|
|
49
|
+
async function runModelPicker() {
|
|
50
|
+
const current = readCurrentModelSelection();
|
|
51
|
+
const models = await getSandboxModels();
|
|
52
|
+
if (models.length === 0) {
|
|
53
|
+
process.stderr.write("\u5F53\u524D\u7528\u6237\u65E0\u53EF\u89C1\u6A21\u578B\n");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const sorted = models.slice().sort((a, b) => {
|
|
57
|
+
const scopeOrder = {
|
|
58
|
+
system: 0,
|
|
59
|
+
company: 1,
|
|
60
|
+
personal: 2
|
|
61
|
+
};
|
|
62
|
+
const scopeDiff = scopeOrder[a.scope] - scopeOrder[b.scope];
|
|
63
|
+
return scopeDiff !== 0 ? scopeDiff : a.name.localeCompare(b.name);
|
|
64
|
+
});
|
|
65
|
+
const picked = await promptSingleCheckboxSelect({
|
|
66
|
+
title: "\u9009\u62E9\u8981\u4F7F\u7528\u7684\u6A21\u578B",
|
|
67
|
+
items: sorted.map((model) => {
|
|
68
|
+
const isCurrent = isCurrentModel(model, current);
|
|
69
|
+
return {
|
|
70
|
+
value: model,
|
|
71
|
+
label: `${model.name} ${model.scope}`,
|
|
72
|
+
hint: isCurrent ? "(\u5F53\u524D)" : void 0,
|
|
73
|
+
preselected: isCurrent
|
|
74
|
+
};
|
|
75
|
+
})
|
|
76
|
+
});
|
|
77
|
+
const workspace = getCurrentWorkspace();
|
|
78
|
+
if (!workspace) {
|
|
79
|
+
process.stderr.write("\u8BF7\u5728 te-agent \u5DE5\u4F5C\u7A7A\u95F4\u76EE\u5F55\u5185\u6267\u884C ae-cli model\n");
|
|
80
|
+
process.exitCode = 1;
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (isCurrentModel(picked, current)) {
|
|
84
|
+
process.stdout.write("\u5F53\u524D\u5DF2\u4F7F\u7528\u8BE5\u6A21\u578B\n");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
await postSandboxModelSelection({
|
|
88
|
+
workspacePath: workspace.name,
|
|
89
|
+
modelId: picked.id
|
|
90
|
+
});
|
|
91
|
+
process.stdout.write(`\u5DF2\u5207\u6362\u4E3A ${picked.name}
|
|
92
|
+
`);
|
|
93
|
+
}
|
|
94
|
+
function registerModel(program) {
|
|
95
|
+
program.command("model").description("Choose and switch the current workspace model (te-agent sandbox only)").action(async () => {
|
|
96
|
+
try {
|
|
97
|
+
await runModelPicker();
|
|
98
|
+
} catch (err) {
|
|
99
|
+
handleError(err);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function handleError(err) {
|
|
104
|
+
if (err instanceof MultiselectCancelled) {
|
|
105
|
+
process.stderr.write("\u5DF2\u53D6\u6D88\n");
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (err instanceof TeAgentCredentialsError) {
|
|
109
|
+
process.stderr.write(`\u2717 ${err.message}
|
|
110
|
+
`);
|
|
111
|
+
if (err.hint) process.stderr.write(` ${err.hint}
|
|
112
|
+
`);
|
|
113
|
+
process.exitCode = 1;
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (err instanceof TeAgentApiError) {
|
|
117
|
+
process.stderr.write(`\u2717 \u4E3B\u5E94\u7528\u9519\u8BEF\uFF08${err.status}${err.code ? " " + err.code : ""}\uFF09\uFF1A${err.message}
|
|
118
|
+
`);
|
|
119
|
+
process.exitCode = 1;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
123
|
+
process.stderr.write(`\u2717 ${msg}
|
|
124
|
+
`);
|
|
125
|
+
process.exitCode = 1;
|
|
126
|
+
}
|
|
127
|
+
export {
|
|
128
|
+
extractModelIdHeader,
|
|
129
|
+
readCurrentModelSelection,
|
|
130
|
+
registerModel
|
|
131
|
+
};
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
printError,
|
|
3
3
|
printOutput
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-B4UL2VIJ.js";
|
|
5
5
|
import {
|
|
6
6
|
httpGet,
|
|
7
7
|
httpPost
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-VT6VC4PA.js";
|
|
9
9
|
import {
|
|
10
10
|
resolveHost
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-SRRUNQIM.js";
|
|
12
12
|
import {
|
|
13
13
|
safeJsonParse
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-BI5ZVD6T.js";
|
|
15
|
+
import "./chunk-MNHE6SSI.js";
|
|
15
16
|
|
|
16
17
|
// src/api/raw.ts
|
|
17
18
|
function registerApi(program) {
|