@peterwangze/claude-trigger-router 1.0.3 → 1.0.4
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 -1
- package/config/trigger.example.yaml +1 -1
- package/dist/cli.js +28 -21
- package/dist/cli.js.map +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/cli.js
CHANGED
|
@@ -32,7 +32,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
32
32
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
33
|
|
|
34
34
|
// src/constants.ts
|
|
35
|
-
var import_os, import_path, CONFIG_DIR, CONFIG_FILE, CONFIG_FILE_JSON, CONFIG_FILE_YML, HOME_DIR, PID_FILE, GOVERNANCE_TRACE_FILE, GOVERNANCE_TRACE_ARCHIVE_DIR, GOVERNANCE_EXPORT_HISTORY_FILE, GOVERNANCE_SNAPSHOT_DIR, GOVERNANCE_SCHEDULE_FILE,
|
|
35
|
+
var import_os, import_path, CONFIG_DIR, CONFIG_FILE, CONFIG_FILE_JSON, CONFIG_FILE_YML, HOME_DIR, PID_FILE, GOVERNANCE_TRACE_FILE, GOVERNANCE_TRACE_ARCHIVE_DIR, GOVERNANCE_EXPORT_HISTORY_FILE, GOVERNANCE_SNAPSHOT_DIR, GOVERNANCE_SCHEDULE_FILE, DEFAULT_CONFIG2, DEFAULT_TRIGGER_CONFIG, DEFAULT_SMART_ROUTER_CONFIG, DEFAULT_GOVERNANCE_CONFIG;
|
|
36
36
|
var init_constants = __esm({
|
|
37
37
|
"src/constants.ts"() {
|
|
38
38
|
"use strict";
|
|
@@ -49,9 +49,9 @@ var init_constants = __esm({
|
|
|
49
49
|
GOVERNANCE_EXPORT_HISTORY_FILE = (0, import_path.join)(CONFIG_DIR, "governance-metrics-export-history.json");
|
|
50
50
|
GOVERNANCE_SNAPSHOT_DIR = (0, import_path.join)(CONFIG_DIR, "governance-metric-snapshots");
|
|
51
51
|
GOVERNANCE_SCHEDULE_FILE = (0, import_path.join)(CONFIG_DIR, "governance-metric-schedules.json");
|
|
52
|
-
|
|
52
|
+
DEFAULT_CONFIG2 = {
|
|
53
53
|
HOST: "127.0.0.1",
|
|
54
|
-
PORT:
|
|
54
|
+
PORT: 5678,
|
|
55
55
|
LOG: true,
|
|
56
56
|
LOG_LEVEL: "debug",
|
|
57
57
|
API_TIMEOUT_MS: 6e5,
|
|
@@ -775,7 +775,7 @@ function validateConfig(config) {
|
|
|
775
775
|
function normalizeAndValidateConfig(config = {}) {
|
|
776
776
|
const normalizedConfig = deepMerge(
|
|
777
777
|
{
|
|
778
|
-
...
|
|
778
|
+
...DEFAULT_CONFIG2,
|
|
779
779
|
Router: {
|
|
780
780
|
default: ""
|
|
781
781
|
},
|
|
@@ -1404,6 +1404,7 @@ var CONTEXT_ALIGNMENT_PROMPT, ContextAlignmentService, contextAlignmentService;
|
|
|
1404
1404
|
var init_context_alignment = __esm({
|
|
1405
1405
|
"src/governance/context-alignment.ts"() {
|
|
1406
1406
|
"use strict";
|
|
1407
|
+
init_constants();
|
|
1407
1408
|
init_log();
|
|
1408
1409
|
init_message_ir();
|
|
1409
1410
|
init_anthropic();
|
|
@@ -1432,7 +1433,7 @@ Do not include markdown fences.`;
|
|
|
1432
1433
|
buildPrompt(text, previousModel, nextModel) {
|
|
1433
1434
|
return CONTEXT_ALIGNMENT_PROMPT.replace("{previousModel}", previousModel).replace("{nextModel}", nextModel).replace("{request}", text);
|
|
1434
1435
|
}
|
|
1435
|
-
async summarizeTransition(text, previousModel, nextModel, config, port =
|
|
1436
|
+
async summarizeTransition(text, previousModel, nextModel, config, port = DEFAULT_CONFIG2.PORT, fetchFn, apiKey, timeoutMs) {
|
|
1436
1437
|
if (!config.enabled || !config.summarizer_model || !text.trim()) {
|
|
1437
1438
|
return null;
|
|
1438
1439
|
}
|
|
@@ -1656,6 +1657,7 @@ var SemanticRouter, semanticRouter;
|
|
|
1656
1657
|
var init_semantic_router = __esm({
|
|
1657
1658
|
"src/governance/semantic-router.ts"() {
|
|
1658
1659
|
"use strict";
|
|
1660
|
+
init_constants();
|
|
1659
1661
|
init_log();
|
|
1660
1662
|
init_message_ir();
|
|
1661
1663
|
init_anthropic();
|
|
@@ -1714,7 +1716,7 @@ Return JSON only:
|
|
|
1714
1716
|
analyze(text, config) {
|
|
1715
1717
|
return this.analyzeEmbedding(text, config);
|
|
1716
1718
|
}
|
|
1717
|
-
async analyzeWithClassifier(text, config, port =
|
|
1719
|
+
async analyzeWithClassifier(text, config, port = DEFAULT_CONFIG2.PORT, fetchFn, apiKey, timeoutMs) {
|
|
1718
1720
|
if (!config?.enabled || config.mode !== "classifier" || !config.prototypes || Object.keys(config.prototypes).length === 0) {
|
|
1719
1721
|
return this.analyzeEmbedding(text, config);
|
|
1720
1722
|
}
|
|
@@ -1778,6 +1780,7 @@ var SHADOW_VERIFIER_PROMPT, ShadowSupervisor, shadowSupervisor;
|
|
|
1778
1780
|
var init_shadow_supervisor = __esm({
|
|
1779
1781
|
"src/governance/shadow-supervisor.ts"() {
|
|
1780
1782
|
"use strict";
|
|
1783
|
+
init_constants();
|
|
1781
1784
|
init_log();
|
|
1782
1785
|
init_message_ir();
|
|
1783
1786
|
init_anthropic();
|
|
@@ -1852,7 +1855,7 @@ If no issue is found, return:
|
|
|
1852
1855
|
}
|
|
1853
1856
|
});
|
|
1854
1857
|
}
|
|
1855
|
-
async inspectWithVerifier(payload, config, port =
|
|
1858
|
+
async inspectWithVerifier(payload, config, port = DEFAULT_CONFIG2.PORT, fetchFn, apiKey, timeoutMs) {
|
|
1856
1859
|
const text = extractText(payload).trim();
|
|
1857
1860
|
if (!config.enabled || !config.verifier_model || !text) {
|
|
1858
1861
|
return this.inspect(payload, config);
|
|
@@ -3527,7 +3530,7 @@ function isServiceRunning() {
|
|
|
3527
3530
|
function savePid(pid, port) {
|
|
3528
3531
|
const info = {
|
|
3529
3532
|
pid,
|
|
3530
|
-
port: port ??
|
|
3533
|
+
port: port ?? DEFAULT_CONFIG2.PORT,
|
|
3531
3534
|
startTime: (/* @__PURE__ */ new Date()).toISOString()
|
|
3532
3535
|
};
|
|
3533
3536
|
(0, import_fs4.writeFileSync)(PID_FILE, JSON.stringify(info, null, 2), "utf-8");
|
|
@@ -3537,7 +3540,7 @@ function readServiceInfo() {
|
|
|
3537
3540
|
try {
|
|
3538
3541
|
const content = (0, import_fs4.readFileSync)(PID_FILE, "utf-8").trim();
|
|
3539
3542
|
if (/^\d+$/.test(content)) {
|
|
3540
|
-
return { pid: parseInt(content, 10), port:
|
|
3543
|
+
return { pid: parseInt(content, 10), port: DEFAULT_CONFIG2.PORT, startTime: "" };
|
|
3541
3544
|
}
|
|
3542
3545
|
return JSON.parse(content);
|
|
3543
3546
|
} catch {
|
|
@@ -4130,6 +4133,7 @@ var init_intent = __esm({
|
|
|
4130
4133
|
"src/trigger/intent.ts"() {
|
|
4131
4134
|
"use strict";
|
|
4132
4135
|
import_lru_cache6 = require("lru-cache");
|
|
4136
|
+
init_constants();
|
|
4133
4137
|
init_log();
|
|
4134
4138
|
intentCache = new import_lru_cache6.LRUCache({
|
|
4135
4139
|
max: 500,
|
|
@@ -4198,7 +4202,7 @@ Important: Respond ONLY with the JSON, no additional text.`;
|
|
|
4198
4202
|
* @param fetchFn fetch 函数(用于发起 API 请求)
|
|
4199
4203
|
* @returns 意图识别结果
|
|
4200
4204
|
*/
|
|
4201
|
-
async detectIntent(text, config, port =
|
|
4205
|
+
async detectIntent(text, config, port = DEFAULT_CONFIG2.PORT, fetchFn, apiKey, timeoutMs) {
|
|
4202
4206
|
if (!config.llm_intent_recognition) {
|
|
4203
4207
|
return {
|
|
4204
4208
|
intent: "general",
|
|
@@ -4286,6 +4290,7 @@ var init_smart_router = __esm({
|
|
|
4286
4290
|
"src/trigger/smart-router.ts"() {
|
|
4287
4291
|
"use strict";
|
|
4288
4292
|
import_lru_cache7 = require("lru-cache");
|
|
4293
|
+
init_constants();
|
|
4289
4294
|
init_log();
|
|
4290
4295
|
init_message_ir();
|
|
4291
4296
|
init_anthropic();
|
|
@@ -4349,11 +4354,11 @@ Important:
|
|
|
4349
4354
|
*
|
|
4350
4355
|
* @param text 请求文本
|
|
4351
4356
|
* @param config SmartRouter 配置
|
|
4352
|
-
* @param port 本地服务端口(默认
|
|
4357
|
+
* @param port 本地服务端口(默认 5678)
|
|
4353
4358
|
* @param fetchFn 可注入的 fetch 函数(用于测试)
|
|
4354
4359
|
* @returns 选择结果,失败时返回 null
|
|
4355
4360
|
*/
|
|
4356
|
-
async selectModel(text, config, port =
|
|
4361
|
+
async selectModel(text, config, port = DEFAULT_CONFIG2.PORT, fetchFn, apiKey, timeoutMs) {
|
|
4357
4362
|
if (!config.enabled) {
|
|
4358
4363
|
return null;
|
|
4359
4364
|
}
|
|
@@ -4428,6 +4433,7 @@ var init_selector = __esm({
|
|
|
4428
4433
|
init_intent();
|
|
4429
4434
|
init_smart_router();
|
|
4430
4435
|
init_log();
|
|
4436
|
+
init_constants();
|
|
4431
4437
|
init_session_store();
|
|
4432
4438
|
init_semantic_router();
|
|
4433
4439
|
init_compile();
|
|
@@ -4484,7 +4490,7 @@ var init_selector = __esm({
|
|
|
4484
4490
|
* @param config 触发配置
|
|
4485
4491
|
* @returns 分析结果
|
|
4486
4492
|
*/
|
|
4487
|
-
async selectModel(req, config, port =
|
|
4493
|
+
async selectModel(req, config, port = DEFAULT_CONFIG2.PORT, smartRouterConfig, governanceConfig, apiKey, timeoutMs) {
|
|
4488
4494
|
const startTime = Date.now();
|
|
4489
4495
|
const appConfig = req.appConfig;
|
|
4490
4496
|
if (!config.enabled) {
|
|
@@ -4683,10 +4689,11 @@ var init_trigger = __esm({
|
|
|
4683
4689
|
init_selector();
|
|
4684
4690
|
init_analyzer();
|
|
4685
4691
|
init_log();
|
|
4692
|
+
init_constants();
|
|
4686
4693
|
TriggerRouter = class {
|
|
4687
4694
|
config = null;
|
|
4688
4695
|
appConfig = null;
|
|
4689
|
-
port =
|
|
4696
|
+
port = DEFAULT_CONFIG2.PORT;
|
|
4690
4697
|
smartRouterConfig = void 0;
|
|
4691
4698
|
governanceConfig = void 0;
|
|
4692
4699
|
apiKey;
|
|
@@ -4699,7 +4706,7 @@ var init_trigger = __esm({
|
|
|
4699
4706
|
init(appConfig) {
|
|
4700
4707
|
this.appConfig = appConfig;
|
|
4701
4708
|
this.config = appConfig.TriggerRouter || this.getDefaultConfig();
|
|
4702
|
-
this.port = appConfig.PORT ||
|
|
4709
|
+
this.port = appConfig.PORT || DEFAULT_CONFIG2.PORT;
|
|
4703
4710
|
this.smartRouterConfig = appConfig.SmartRouter;
|
|
4704
4711
|
this.governanceConfig = appConfig.Governance;
|
|
4705
4712
|
this.apiKey = appConfig.APIKEY;
|
|
@@ -5171,7 +5178,7 @@ async function run(options = {}) {
|
|
|
5171
5178
|
HOST = "127.0.0.1";
|
|
5172
5179
|
logWarn("\u26A0\uFE0F API key is not set. HOST is forced to 127.0.0.1.");
|
|
5173
5180
|
}
|
|
5174
|
-
const port = options.port ?? config.PORT ??
|
|
5181
|
+
const port = options.port ?? config.PORT ?? DEFAULT_CONFIG.PORT;
|
|
5175
5182
|
savePid(process.pid, port);
|
|
5176
5183
|
process.on("SIGINT", () => {
|
|
5177
5184
|
log("Received SIGINT, cleaning up...");
|
|
@@ -6133,8 +6140,8 @@ async function readCurrentConfig() {
|
|
|
6133
6140
|
}
|
|
6134
6141
|
}
|
|
6135
6142
|
async function probeService() {
|
|
6136
|
-
const healthy = await waitForService(
|
|
6137
|
-
return healthy ? { kind: "self_healthy", port:
|
|
6143
|
+
const healthy = await waitForService(DEFAULT_CONFIG2.PORT, 500);
|
|
6144
|
+
return healthy ? { kind: "self_healthy", port: DEFAULT_CONFIG2.PORT } : { kind: "none" };
|
|
6138
6145
|
}
|
|
6139
6146
|
async function enterClaudeCode() {
|
|
6140
6147
|
const cliModule = await Promise.resolve().then(() => (init_cli(), cli_exports));
|
|
@@ -6384,7 +6391,7 @@ function createDefaultDeps(io = createConsoleIO()) {
|
|
|
6384
6391
|
executeStart,
|
|
6385
6392
|
executeReload: executeRestart,
|
|
6386
6393
|
executeRestart,
|
|
6387
|
-
verifyHealth: () => waitForService(
|
|
6394
|
+
verifyHealth: () => waitForService(DEFAULT_CONFIG2.PORT, 5e3),
|
|
6388
6395
|
enterClaudeCode,
|
|
6389
6396
|
io
|
|
6390
6397
|
};
|
|
@@ -6559,7 +6566,7 @@ function getPort() {
|
|
|
6559
6566
|
}
|
|
6560
6567
|
} catch {
|
|
6561
6568
|
}
|
|
6562
|
-
return
|
|
6569
|
+
return DEFAULT_CONFIG2.PORT;
|
|
6563
6570
|
}
|
|
6564
6571
|
function isDaemonMode() {
|
|
6565
6572
|
return hasArg("--daemon", "-d");
|
|
@@ -6584,7 +6591,7 @@ Claude Trigger Router - \u667A\u80FD\u89E6\u53D1\u8DEF\u7531\u5668
|
|
|
6584
6591
|
help \u663E\u793A\u6B64\u5E2E\u52A9\u4FE1\u606F
|
|
6585
6592
|
|
|
6586
6593
|
\u9009\u9879\uFF1A
|
|
6587
|
-
--port, -p \u6307\u5B9A\u76D1\u542C\u7AEF\u53E3\uFF08\u9ED8\u8BA4\
|
|
6594
|
+
--port, -p \u6307\u5B9A\u76D1\u542C\u7AEF\u53E3\uFF08\u9ED8\u8BA4\uFF1A5678\uFF09
|
|
6588
6595
|
--daemon, -d \u4EE5\u540E\u53F0\u65B9\u5F0F\u8FD0\u884C\uFF08\u914D\u5408 start/restart \u4F7F\u7528\uFF09
|
|
6589
6596
|
--force \u5F3A\u5236\u8986\u76D6\u5DF2\u6709\u914D\u7F6E\uFF08\u914D\u5408 init \u4F7F\u7528\uFF09
|
|
6590
6597
|
|