@peterwangze/claude-trigger-router 1.0.0 → 1.0.2
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 +294 -295
- package/dist/cli.js +62 -19
- package/dist/cli.js.map +2 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
#!/usr/bin/env node
|
|
3
2
|
"use strict";
|
|
4
3
|
var __create = Object.create;
|
|
5
4
|
var __defProp = Object.defineProperty;
|
|
@@ -5756,10 +5755,11 @@ function getProviderPreset2(key) {
|
|
|
5756
5755
|
};
|
|
5757
5756
|
}
|
|
5758
5757
|
function buildMinimalConfig(input2) {
|
|
5759
|
-
const
|
|
5758
|
+
const providers = input2.providers;
|
|
5759
|
+
const models = providers.map((p) => {
|
|
5760
5760
|
const preset = p.preset ? getProviderPreset2(p.preset) : void 0;
|
|
5761
5761
|
const modelDraft = {
|
|
5762
|
-
id: p.name,
|
|
5762
|
+
id: p.model_id?.trim() || p.name,
|
|
5763
5763
|
key: p.api_key,
|
|
5764
5764
|
api_key: p.api_key,
|
|
5765
5765
|
model: p.models[0] ?? "",
|
|
@@ -6154,6 +6154,27 @@ function mapConfigErrorsToRepairFields(errors) {
|
|
|
6154
6154
|
const fields = getRepairFields(errors);
|
|
6155
6155
|
return fields.includes("manualReview") ? { mode: "manualReview", fields } : { mode: "repair", fields };
|
|
6156
6156
|
}
|
|
6157
|
+
function mapValidCurrentConfigChoice(choice) {
|
|
6158
|
+
if (choice === "reuse" || choice === "\u76F4\u63A5\u4F7F\u7528\u5F53\u524D\u914D\u7F6E\uFF08\u63A8\u8350\uFF09") {
|
|
6159
|
+
return "reuse";
|
|
6160
|
+
}
|
|
6161
|
+
if (choice === "overwrite" || choice === "\u68C0\u67E5\u5E76\u8C03\u6574\u5F53\u524D\u914D\u7F6E") {
|
|
6162
|
+
return "overwrite";
|
|
6163
|
+
}
|
|
6164
|
+
if (choice === "cancel" || choice === "\u653E\u5F03\u5F53\u524D\u914D\u7F6E\uFF0C\u91CD\u65B0\u5F00\u59CB") {
|
|
6165
|
+
return "cancel";
|
|
6166
|
+
}
|
|
6167
|
+
throw new Error("invalid current config action");
|
|
6168
|
+
}
|
|
6169
|
+
function mapLegacyConfigChoice(choice) {
|
|
6170
|
+
if (choice === "migrate" || choice === "\u8FC1\u79FB\u65E7\u914D\u7F6E\uFF08\u63A8\u8350\uFF09") {
|
|
6171
|
+
return "migrate";
|
|
6172
|
+
}
|
|
6173
|
+
if (choice === "skip" || choice === "\u8DF3\u8FC7\u8FC1\u79FB\uFF0C\u624B\u52A8\u65B0\u5EFA") {
|
|
6174
|
+
return "skip";
|
|
6175
|
+
}
|
|
6176
|
+
throw new Error("invalid legacy config action");
|
|
6177
|
+
}
|
|
6157
6178
|
function toCapabilityBoolean(choice) {
|
|
6158
6179
|
if (choice === "\u652F\u6301") {
|
|
6159
6180
|
return true;
|
|
@@ -6256,24 +6277,35 @@ function toDraftFromConfig(config) {
|
|
|
6256
6277
|
};
|
|
6257
6278
|
}
|
|
6258
6279
|
async function buildFreshConfig(io) {
|
|
6259
|
-
const
|
|
6260
|
-
const
|
|
6261
|
-
|
|
6262
|
-
|
|
6280
|
+
const modelId = await io.input("\u9ED8\u8BA4\u6A21\u578B ID");
|
|
6281
|
+
const connectMode = await io.choose("\u8FD9\u4E2A\u6A21\u578B\u63A5\u5230\u54EA\u91CC\uFF1F", ["\u4F7F\u7528\u5E38\u89C1\u63A5\u5165\u6A21\u677F", "\u624B\u52A8\u586B\u5199\u63A5\u53E3"]);
|
|
6282
|
+
let preset = "custom";
|
|
6283
|
+
let providerName = "provider";
|
|
6284
|
+
let apiBaseUrl = "";
|
|
6285
|
+
if (connectMode === "\u4F7F\u7528\u5E38\u89C1\u63A5\u5165\u6A21\u677F") {
|
|
6286
|
+
const presetOptions = listProviderPresetKeys("setup");
|
|
6287
|
+
preset = await io.choose("\u9009\u62E9 provider \u9884\u8BBE", presetOptions);
|
|
6288
|
+
providerName = await io.input("Provider \u540D\u79F0", preset);
|
|
6289
|
+
apiBaseUrl = preset === "custom" ? await io.input("API Base URL") : await io.input("API Base URL\uFF08\u7559\u7A7A\u4F7F\u7528\u9884\u8BBE\uFF09", "");
|
|
6290
|
+
} else {
|
|
6291
|
+
providerName = await io.input("Provider \u540D\u79F0", "provider");
|
|
6292
|
+
apiBaseUrl = await io.input("API Base URL");
|
|
6293
|
+
}
|
|
6263
6294
|
const apiKey = await io.input("API Key");
|
|
6264
|
-
const model = await io.input("\
|
|
6295
|
+
const model = await io.input("\u4E0A\u6E38\u6A21\u578B\u540D");
|
|
6265
6296
|
const capabilityMode = await io.choose("\u662F\u5426\u914D\u7F6E capability \u63D0\u793A", ["\u4FDD\u6301\u9ED8\u8BA4", "\u914D\u7F6E capability \u63D0\u793A"]);
|
|
6266
6297
|
const draft = buildMinimalConfig({
|
|
6267
6298
|
providers: [
|
|
6268
6299
|
{
|
|
6269
6300
|
name: providerName,
|
|
6301
|
+
model_id: modelId,
|
|
6270
6302
|
api_key: apiKey,
|
|
6271
6303
|
models: [model],
|
|
6272
6304
|
preset,
|
|
6273
6305
|
api_base_url: apiBaseUrl
|
|
6274
6306
|
}
|
|
6275
6307
|
],
|
|
6276
|
-
defaultModel:
|
|
6308
|
+
defaultModel: modelId
|
|
6277
6309
|
});
|
|
6278
6310
|
if (capabilityMode === "\u914D\u7F6E capability \u63D0\u793A" && draft.Models?.[0]) {
|
|
6279
6311
|
await promptCapabilityMetadataForDraft(draft, io);
|
|
@@ -6351,11 +6383,17 @@ async function runSetupCli(customDeps) {
|
|
|
6351
6383
|
return "create";
|
|
6352
6384
|
}
|
|
6353
6385
|
if (currentConfig.kind === "valid") {
|
|
6354
|
-
deps.io.info("\u68C0\u6D4B\u5230\
|
|
6386
|
+
deps.io.info("\u68C0\u6D4B\u5230\u5F53\u524D claude-trigger-router \u914D\u7F6E\u5DF2\u53EF\u7528\u3002");
|
|
6355
6387
|
if (currentConfig.warnings.length > 0) {
|
|
6356
6388
|
deps.io.info(`\u5F53\u524D\u914D\u7F6E\u63D0\u793A\uFF1A${currentConfig.warnings.join("; ")}`);
|
|
6357
6389
|
}
|
|
6358
|
-
return
|
|
6390
|
+
return mapValidCurrentConfigChoice(
|
|
6391
|
+
await deps.io.choose("\u4F60\u60F3\u76F4\u63A5\u4F7F\u7528\u5B83\uFF0C\u8FD8\u662F\u91CD\u65B0\u8C03\u6574\uFF1F", [
|
|
6392
|
+
"\u76F4\u63A5\u4F7F\u7528\u5F53\u524D\u914D\u7F6E\uFF08\u63A8\u8350\uFF09",
|
|
6393
|
+
"\u68C0\u67E5\u5E76\u8C03\u6574\u5F53\u524D\u914D\u7F6E",
|
|
6394
|
+
"\u653E\u5F03\u5F53\u524D\u914D\u7F6E\uFF0C\u91CD\u65B0\u5F00\u59CB"
|
|
6395
|
+
])
|
|
6396
|
+
);
|
|
6359
6397
|
}
|
|
6360
6398
|
if (currentConfig.kind === "invalid") {
|
|
6361
6399
|
deps.io.info(`\u5F53\u524D\u914D\u7F6E\u6821\u9A8C\u5931\u8D25\uFF1A${currentConfig.errors.join("; ")}`);
|
|
@@ -6369,7 +6407,12 @@ async function runSetupCli(customDeps) {
|
|
|
6369
6407
|
},
|
|
6370
6408
|
chooseLegacyConfigAction: async ({ legacyConfig }) => {
|
|
6371
6409
|
if (legacyConfig.kind === "found") {
|
|
6372
|
-
return
|
|
6410
|
+
return mapLegacyConfigChoice(
|
|
6411
|
+
await deps.io.choose("\u68C0\u6D4B\u5230\u65E7 claude-code-router \u914D\u7F6E\u3002\u662F\u5426\u8FC1\u79FB\u4E3A\u5F53\u524D\u63A8\u8350\u914D\u7F6E\uFF1F", [
|
|
6412
|
+
"\u8FC1\u79FB\u65E7\u914D\u7F6E\uFF08\u63A8\u8350\uFF09",
|
|
6413
|
+
"\u8DF3\u8FC7\u8FC1\u79FB\uFF0C\u624B\u52A8\u65B0\u5EFA"
|
|
6414
|
+
])
|
|
6415
|
+
);
|
|
6373
6416
|
}
|
|
6374
6417
|
if (legacyConfig.kind === "read_error") {
|
|
6375
6418
|
deps.io.info(`\u65E7 ccr \u914D\u7F6E\u8BFB\u53D6\u5931\u8D25\uFF1A${legacyConfig.error}`);
|
|
@@ -6500,8 +6543,8 @@ Claude Trigger Router - \u667A\u80FD\u89E6\u53D1\u8DEF\u7531\u5668
|
|
|
6500
6543
|
\u7528\u6CD5\uFF1Actr <\u547D\u4EE4> [\u9009\u9879]
|
|
6501
6544
|
|
|
6502
6545
|
\u547D\u4EE4\uFF1A
|
|
6503
|
-
setup \
|
|
6504
|
-
init \u521D\u59CB\u5316\u914D\u7F6E\
|
|
6546
|
+
setup \u68C0\u6D4B\u5E76\u590D\u7528\u5DF2\u6709\u914D\u7F6E\uFF0C\u5FC5\u8981\u65F6\u8FC1\u79FB\u65E7\u914D\u7F6E\u6216\u65B0\u5EFA\u6700\u5C0F\u914D\u7F6E
|
|
6547
|
+
init \u521D\u59CB\u5316\u6700\u5C0F\u914D\u7F6E\u6A21\u677F
|
|
6505
6548
|
start \u542F\u52A8\u8DEF\u7531\u670D\u52A1\uFF08\u9ED8\u8BA4\u524D\u53F0\u8FD0\u884C\uFF09
|
|
6506
6549
|
stop \u505C\u6B62\u540E\u53F0\u670D\u52A1
|
|
6507
6550
|
restart \u91CD\u542F\u540E\u53F0\u670D\u52A1
|
|
@@ -6516,8 +6559,8 @@ Claude Trigger Router - \u667A\u80FD\u89E6\u53D1\u8DEF\u7531\u5668
|
|
|
6516
6559
|
--force \u5F3A\u5236\u8986\u76D6\u5DF2\u6709\u914D\u7F6E\uFF08\u914D\u5408 init \u4F7F\u7528\uFF09
|
|
6517
6560
|
|
|
6518
6561
|
\u4F7F\u7528\u793A\u4F8B\uFF1A
|
|
6519
|
-
ctr setup # \
|
|
6520
|
-
ctr init # \u521D\u59CB\u5316\u914D\u7F6E\
|
|
6562
|
+
ctr setup # \u590D\u7528\u5F53\u524D\u914D\u7F6E / \u8FC1\u79FB\u65E7\u914D\u7F6E / \u65B0\u5EFA\u6700\u5C0F\u914D\u7F6E
|
|
6563
|
+
ctr init # \u521D\u59CB\u5316\u6700\u5C0F\u914D\u7F6E\u6A21\u677F
|
|
6521
6564
|
ctr start # \u524D\u53F0\u542F\u52A8\uFF08\u63A8\u8350\u9996\u6B21\u4F7F\u7528\uFF0C\u4FBF\u4E8E\u67E5\u770B\u65E5\u5FD7\uFF09
|
|
6522
6565
|
ctr start --daemon # \u540E\u53F0\u542F\u52A8
|
|
6523
6566
|
ctr status # \u67E5\u770B\u670D\u52A1\u72B6\u6001
|
|
@@ -6563,9 +6606,9 @@ function initConfig2() {
|
|
|
6563
6606
|
console.log("");
|
|
6564
6607
|
console.log("\u4E0B\u4E00\u6B65\uFF1A");
|
|
6565
6608
|
console.log(" 1. \u7F16\u8F91\u914D\u7F6E\u6587\u4EF6\uFF0C\u586B\u5165\u4F60\u7684 API \u5BC6\u94A5");
|
|
6566
|
-
console.log(" 2. \u5728 '
|
|
6567
|
-
console.log(" 3. \u5C06 'Router.default' \u8BBE\u7F6E\u4E3A\
|
|
6568
|
-
console.log(" 4. \
|
|
6609
|
+
console.log(" 2. \u5728 'Models' \u4E0B\u8865\u5168\u4F60\u7684\u6A21\u578B\u63A5\u5165\u4FE1\u606F");
|
|
6610
|
+
console.log(" 3. \u5C06 'Router.default' \u8BBE\u7F6E\u4E3A\u9ED8\u8BA4\u6A21\u578B ID");
|
|
6611
|
+
console.log(" 4. \u5982\u9700\u9AD8\u7EA7\u8DEF\u7531\uFF0C\u518D\u7EE7\u7EED\u914D\u7F6E\u89C4\u5219\u6216\u667A\u80FD\u8DEF\u7531");
|
|
6569
6612
|
console.log(` 5. \u8FD0\u884C\uFF1Actr start`);
|
|
6570
6613
|
} catch (error) {
|
|
6571
6614
|
console.error("\u274C \u521B\u5EFA\u914D\u7F6E\u6587\u4EF6\u5931\u8D25:", error.message);
|