lark-remote 0.1.0
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/CHANGELOG.md +52 -0
- package/LICENSE +21 -0
- package/README.en.md +162 -0
- package/README.md +161 -0
- package/dist/binder.d.ts +57 -0
- package/dist/binder.js +105 -0
- package/dist/bridge/index.d.ts +338 -0
- package/dist/bridge/index.js +1281 -0
- package/dist/bridge/queue-manager.d.ts +277 -0
- package/dist/bridge/queue-manager.js +729 -0
- package/dist/card/bash-card-session.d.ts +78 -0
- package/dist/card/bash-card-session.js +174 -0
- package/dist/card/bash-renderer.d.ts +24 -0
- package/dist/card/bash-renderer.js +187 -0
- package/dist/card/card-budget.d.ts +31 -0
- package/dist/card/card-budget.js +280 -0
- package/dist/card/card-session.d.ts +83 -0
- package/dist/card/card-session.js +185 -0
- package/dist/card/card-shared.d.ts +28 -0
- package/dist/card/card-shared.js +99 -0
- package/dist/card/collapsible.d.ts +26 -0
- package/dist/card/collapsible.js +87 -0
- package/dist/card/run-card-session.d.ts +78 -0
- package/dist/card/run-card-session.js +165 -0
- package/dist/card/run-renderer.d.ts +66 -0
- package/dist/card/run-renderer.js +841 -0
- package/dist/card/run-state.d.ts +103 -0
- package/dist/card/run-state.js +313 -0
- package/dist/card/text-truncate.d.ts +56 -0
- package/dist/card/text-truncate.js +184 -0
- package/dist/card/time.d.ts +1 -0
- package/dist/card/time.js +14 -0
- package/dist/card/tool-render.d.ts +25 -0
- package/dist/card/tool-render.js +176 -0
- package/dist/cli.d.ts +28 -0
- package/dist/cli.js +89 -0
- package/dist/common/guards.d.ts +37 -0
- package/dist/common/guards.js +65 -0
- package/dist/config/codex-config.d.ts +113 -0
- package/dist/config/codex-config.js +428 -0
- package/dist/config/dir.d.ts +17 -0
- package/dist/config/dir.js +81 -0
- package/dist/config/index.d.ts +219 -0
- package/dist/config/index.js +388 -0
- package/dist/config/kimi-config.d.ts +33 -0
- package/dist/config/kimi-config.js +111 -0
- package/dist/config/opencode-config.d.ts +20 -0
- package/dist/config/opencode-config.js +124 -0
- package/dist/config/pi-config.d.ts +49 -0
- package/dist/config/pi-config.js +151 -0
- package/dist/config/wizard.d.ts +12 -0
- package/dist/config/wizard.js +84 -0
- package/dist/connector/file-limits.d.ts +7 -0
- package/dist/connector/file-limits.js +8 -0
- package/dist/connector/index.d.ts +86 -0
- package/dist/connector/index.js +340 -0
- package/dist/error-classification.d.ts +15 -0
- package/dist/error-classification.js +24 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +580 -0
- package/dist/instance-lock.d.ts +30 -0
- package/dist/instance-lock.js +184 -0
- package/dist/logger/index.d.ts +57 -0
- package/dist/logger/index.js +178 -0
- package/dist/order/index.d.ts +27 -0
- package/dist/order/index.js +90 -0
- package/dist/persistence/atomic-write.d.ts +10 -0
- package/dist/persistence/atomic-write.js +65 -0
- package/dist/persistence/load-json-file.d.ts +9 -0
- package/dist/persistence/load-json-file.js +23 -0
- package/dist/restart.d.ts +24 -0
- package/dist/restart.js +73 -0
- package/dist/router/card-helpers.d.ts +28 -0
- package/dist/router/card-helpers.js +65 -0
- package/dist/router/config/claude.d.ts +14 -0
- package/dist/router/config/claude.js +72 -0
- package/dist/router/config/codex.d.ts +22 -0
- package/dist/router/config/codex.js +100 -0
- package/dist/router/config/common/render.d.ts +16 -0
- package/dist/router/config/common/render.js +158 -0
- package/dist/router/config/index.d.ts +18 -0
- package/dist/router/config/index.js +38 -0
- package/dist/router/config/kimi.d.ts +21 -0
- package/dist/router/config/kimi.js +63 -0
- package/dist/router/config/opencode.d.ts +12 -0
- package/dist/router/config/opencode.js +44 -0
- package/dist/router/config/pi.d.ts +12 -0
- package/dist/router/config/pi.js +50 -0
- package/dist/router/config/types.d.ts +43 -0
- package/dist/router/config/types.js +8 -0
- package/dist/router/index.d.ts +318 -0
- package/dist/router/index.js +2715 -0
- package/dist/router/order-exec-dispatch.d.ts +30 -0
- package/dist/router/order-exec-dispatch.js +48 -0
- package/dist/router/utils.d.ts +44 -0
- package/dist/router/utils.js +116 -0
- package/dist/runner/bash/index.d.ts +4 -0
- package/dist/runner/bash/index.js +5 -0
- package/dist/runner/bash/runner.d.ts +55 -0
- package/dist/runner/bash/runner.js +213 -0
- package/dist/runner/claude/index.d.ts +4 -0
- package/dist/runner/claude/index.js +5 -0
- package/dist/runner/claude/runner.d.ts +29 -0
- package/dist/runner/claude/runner.js +83 -0
- package/dist/runner/codex/argv.d.ts +33 -0
- package/dist/runner/codex/argv.js +40 -0
- package/dist/runner/codex/index.d.ts +1 -0
- package/dist/runner/codex/index.js +2 -0
- package/dist/runner/codex/jsonl.d.ts +37 -0
- package/dist/runner/codex/jsonl.js +221 -0
- package/dist/runner/codex/runner.d.ts +65 -0
- package/dist/runner/codex/runner.js +124 -0
- package/dist/runner/common/exec-translator.d.ts +73 -0
- package/dist/runner/common/exec-translator.js +105 -0
- package/dist/runner/common/jsonl-stream.d.ts +39 -0
- package/dist/runner/common/jsonl-stream.js +203 -0
- package/dist/runner/common/process-stopper.d.ts +28 -0
- package/dist/runner/common/process-stopper.js +79 -0
- package/dist/runner/common/runner-utils.d.ts +21 -0
- package/dist/runner/common/runner-utils.js +65 -0
- package/dist/runner/common/spawn-heartbeat.d.ts +33 -0
- package/dist/runner/common/spawn-heartbeat.js +51 -0
- package/dist/runner/common/spawning-runner.d.ts +321 -0
- package/dist/runner/common/spawning-runner.js +634 -0
- package/dist/runner/common/usage.d.ts +31 -0
- package/dist/runner/common/usage.js +29 -0
- package/dist/runner/index.d.ts +19 -0
- package/dist/runner/index.js +24 -0
- package/dist/runner/kimi/index.d.ts +1 -0
- package/dist/runner/kimi/index.js +2 -0
- package/dist/runner/kimi/jsonl.d.ts +28 -0
- package/dist/runner/kimi/jsonl.js +143 -0
- package/dist/runner/kimi/runner.d.ts +50 -0
- package/dist/runner/kimi/runner.js +105 -0
- package/dist/runner/opencode/argv.d.ts +32 -0
- package/dist/runner/opencode/argv.js +35 -0
- package/dist/runner/opencode/index.d.ts +1 -0
- package/dist/runner/opencode/index.js +2 -0
- package/dist/runner/opencode/jsonl.d.ts +68 -0
- package/dist/runner/opencode/jsonl.js +295 -0
- package/dist/runner/opencode/runner.d.ts +63 -0
- package/dist/runner/opencode/runner.js +93 -0
- package/dist/runner/pi/index.d.ts +1 -0
- package/dist/runner/pi/index.js +2 -0
- package/dist/runner/pi/jsonl.d.ts +128 -0
- package/dist/runner/pi/jsonl.js +249 -0
- package/dist/runner/pi/runner.d.ts +37 -0
- package/dist/runner/pi/runner.js +76 -0
- package/dist/runner/registry.d.ts +54 -0
- package/dist/runner/registry.js +75 -0
- package/dist/runner/resolve-agent-choices.d.ts +7 -0
- package/dist/runner/resolve-agent-choices.js +76 -0
- package/dist/runner/sync-agent-choices.d.ts +6 -0
- package/dist/runner/sync-agent-choices.js +73 -0
- package/dist/runner/types.d.ts +250 -0
- package/dist/runner/types.js +8 -0
- package/dist/session/claude/index.d.ts +1 -0
- package/dist/session/claude/index.js +2 -0
- package/dist/session/claude/session-reader.d.ts +34 -0
- package/dist/session/claude/session-reader.js +46 -0
- package/dist/session/claude/sessions.d.ts +53 -0
- package/dist/session/claude/sessions.js +528 -0
- package/dist/session/codex/index.d.ts +1 -0
- package/dist/session/codex/index.js +2 -0
- package/dist/session/codex/rollout-reader.d.ts +88 -0
- package/dist/session/codex/rollout-reader.js +473 -0
- package/dist/session/codex/sessions.d.ts +21 -0
- package/dist/session/codex/sessions.js +40 -0
- package/dist/session/common/catch-up.d.ts +12 -0
- package/dist/session/common/catch-up.js +31 -0
- package/dist/session/common/constants.d.ts +11 -0
- package/dist/session/common/constants.js +12 -0
- package/dist/session/common/content-blocks.d.ts +37 -0
- package/dist/session/common/content-blocks.js +68 -0
- package/dist/session/common/jsonl.d.ts +77 -0
- package/dist/session/common/jsonl.js +351 -0
- package/dist/session/common/usage-accumulator.d.ts +58 -0
- package/dist/session/common/usage-accumulator.js +72 -0
- package/dist/session/index.d.ts +7 -0
- package/dist/session/index.js +11 -0
- package/dist/session/kimi/index.d.ts +1 -0
- package/dist/session/kimi/index.js +2 -0
- package/dist/session/kimi/sessions.d.ts +81 -0
- package/dist/session/kimi/sessions.js +527 -0
- package/dist/session/opencode/index.d.ts +1 -0
- package/dist/session/opencode/index.js +2 -0
- package/dist/session/opencode/sessions.d.ts +81 -0
- package/dist/session/opencode/sessions.js +388 -0
- package/dist/session/pi/index.d.ts +1 -0
- package/dist/session/pi/index.js +2 -0
- package/dist/session/pi/sessions.d.ts +27 -0
- package/dist/session/pi/sessions.js +399 -0
- package/dist/session/registry.d.ts +12 -0
- package/dist/session/registry.js +20 -0
- package/dist/session/session-store.d.ts +86 -0
- package/dist/session/session-store.js +450 -0
- package/dist/startup-contact.d.ts +18 -0
- package/dist/startup-contact.js +51 -0
- package/dist/workspace/index.d.ts +19 -0
- package/dist/workspace/index.js +53 -0
- package/package.json +93 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export { getConfigDir } from './dir.js';
|
|
3
|
+
/** Valid effort values for Claude */
|
|
4
|
+
export declare const CLAUDE_EFFORTS: readonly ["low", "medium", "high", "xhigh", "max"];
|
|
5
|
+
/** Valid thinking levels for Pi */
|
|
6
|
+
export declare const PI_THINKING_LEVELS: readonly ["off", "minimal", "low", "medium", "high", "xhigh"];
|
|
7
|
+
/**
|
|
8
|
+
* Default SIGTERM→SIGKILL grace period (ms). Exported so runners (SpawningRunner)
|
|
9
|
+
* and config-loading paths (src/index.ts) can reuse the same source of truth
|
|
10
|
+
* instead of re-literalizing `5000` (Clean Code P3-1, G25).
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_STOP_GRACE_MS: 5000;
|
|
13
|
+
/** 模型 ID → alias 映射。 */
|
|
14
|
+
export declare const MODEL_ID_TO_ALIAS: Record<string, string>;
|
|
15
|
+
/** alias → model ID 反向映射。 */
|
|
16
|
+
export declare const MODEL_ALIAS_TO_ID: Record<string, string>;
|
|
17
|
+
declare const ClaudeConfigSchema: z.ZodObject<{
|
|
18
|
+
binary: z.ZodDefault<z.ZodString>;
|
|
19
|
+
model: z.ZodDefault<z.ZodString>;
|
|
20
|
+
effort: z.ZodDefault<z.ZodEnum<{
|
|
21
|
+
medium: "medium";
|
|
22
|
+
max: "max";
|
|
23
|
+
low: "low";
|
|
24
|
+
high: "high";
|
|
25
|
+
xhigh: "xhigh";
|
|
26
|
+
}>>;
|
|
27
|
+
stopGraceMs: z.ZodDefault<z.ZodNumber>;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
/** Codex-specific configuration. */
|
|
30
|
+
export declare const CodexConfigSchema: z.ZodObject<{
|
|
31
|
+
binary: z.ZodDefault<z.ZodString>;
|
|
32
|
+
model: z.ZodOptional<z.ZodString>;
|
|
33
|
+
modelProvider: z.ZodOptional<z.ZodString>;
|
|
34
|
+
reasoningEffort: z.ZodOptional<z.ZodString>;
|
|
35
|
+
stopGraceMs: z.ZodDefault<z.ZodNumber>;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
/** OpenCode-specific configuration (run mode: opencode run --format json --auto). */
|
|
38
|
+
declare const OpencodeConfigSchema: z.ZodObject<{
|
|
39
|
+
binary: z.ZodDefault<z.ZodString>;
|
|
40
|
+
providerID: z.ZodDefault<z.ZodString>;
|
|
41
|
+
modelID: z.ZodDefault<z.ZodString>;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
/** Pi-specific configuration. pi is a spawn-per-message CLI like Claude. */
|
|
44
|
+
declare const PiConfigSchema: z.ZodObject<{
|
|
45
|
+
binary: z.ZodDefault<z.ZodString>;
|
|
46
|
+
provider: z.ZodDefault<z.ZodString>;
|
|
47
|
+
model: z.ZodDefault<z.ZodString>;
|
|
48
|
+
thinking: z.ZodDefault<z.ZodEnum<{
|
|
49
|
+
medium: "medium";
|
|
50
|
+
off: "off";
|
|
51
|
+
low: "low";
|
|
52
|
+
high: "high";
|
|
53
|
+
xhigh: "xhigh";
|
|
54
|
+
minimal: "minimal";
|
|
55
|
+
}>>;
|
|
56
|
+
tools: z.ZodDefault<z.ZodString>;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
/** Kimi-specific configuration. kimi is a spawn-per-message CLI. */
|
|
59
|
+
declare const KimiConfigSchema: z.ZodObject<{
|
|
60
|
+
binary: z.ZodDefault<z.ZodString>;
|
|
61
|
+
model: z.ZodDefault<z.ZodString>;
|
|
62
|
+
thinkingEffort: z.ZodDefault<z.ZodEnum<{
|
|
63
|
+
max: "max";
|
|
64
|
+
low: "low";
|
|
65
|
+
high: "high";
|
|
66
|
+
}>>;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
export declare const AppConfigSchema: z.ZodObject<{
|
|
69
|
+
feishu: z.ZodObject<{
|
|
70
|
+
appId: z.ZodString;
|
|
71
|
+
appSecret: z.ZodString;
|
|
72
|
+
}, z.core.$strip>;
|
|
73
|
+
claude: z.ZodDefault<z.ZodObject<{
|
|
74
|
+
binary: z.ZodDefault<z.ZodString>;
|
|
75
|
+
model: z.ZodDefault<z.ZodString>;
|
|
76
|
+
effort: z.ZodDefault<z.ZodEnum<{
|
|
77
|
+
medium: "medium";
|
|
78
|
+
max: "max";
|
|
79
|
+
low: "low";
|
|
80
|
+
high: "high";
|
|
81
|
+
xhigh: "xhigh";
|
|
82
|
+
}>>;
|
|
83
|
+
stopGraceMs: z.ZodDefault<z.ZodNumber>;
|
|
84
|
+
}, z.core.$strip>>;
|
|
85
|
+
agents: z.ZodOptional<z.ZodObject<{
|
|
86
|
+
codex: z.ZodOptional<z.ZodObject<{
|
|
87
|
+
binary: z.ZodDefault<z.ZodString>;
|
|
88
|
+
model: z.ZodOptional<z.ZodString>;
|
|
89
|
+
modelProvider: z.ZodOptional<z.ZodString>;
|
|
90
|
+
reasoningEffort: z.ZodOptional<z.ZodString>;
|
|
91
|
+
stopGraceMs: z.ZodDefault<z.ZodNumber>;
|
|
92
|
+
}, z.core.$strip>>;
|
|
93
|
+
opencode: z.ZodOptional<z.ZodObject<{
|
|
94
|
+
binary: z.ZodDefault<z.ZodString>;
|
|
95
|
+
providerID: z.ZodDefault<z.ZodString>;
|
|
96
|
+
modelID: z.ZodDefault<z.ZodString>;
|
|
97
|
+
}, z.core.$strip>>;
|
|
98
|
+
pi: z.ZodOptional<z.ZodObject<{
|
|
99
|
+
binary: z.ZodDefault<z.ZodString>;
|
|
100
|
+
provider: z.ZodDefault<z.ZodString>;
|
|
101
|
+
model: z.ZodDefault<z.ZodString>;
|
|
102
|
+
thinking: z.ZodDefault<z.ZodEnum<{
|
|
103
|
+
medium: "medium";
|
|
104
|
+
off: "off";
|
|
105
|
+
low: "low";
|
|
106
|
+
high: "high";
|
|
107
|
+
xhigh: "xhigh";
|
|
108
|
+
minimal: "minimal";
|
|
109
|
+
}>>;
|
|
110
|
+
tools: z.ZodDefault<z.ZodString>;
|
|
111
|
+
}, z.core.$strip>>;
|
|
112
|
+
kimi: z.ZodOptional<z.ZodObject<{
|
|
113
|
+
binary: z.ZodDefault<z.ZodString>;
|
|
114
|
+
model: z.ZodDefault<z.ZodString>;
|
|
115
|
+
thinkingEffort: z.ZodDefault<z.ZodEnum<{
|
|
116
|
+
max: "max";
|
|
117
|
+
low: "low";
|
|
118
|
+
high: "high";
|
|
119
|
+
}>>;
|
|
120
|
+
}, z.core.$strip>>;
|
|
121
|
+
}, z.core.$strip>>;
|
|
122
|
+
agentChoices: z.ZodOptional<z.ZodObject<{
|
|
123
|
+
codex: z.ZodOptional<z.ZodObject<{
|
|
124
|
+
model: z.ZodOptional<z.ZodString>;
|
|
125
|
+
modelProvider: z.ZodOptional<z.ZodString>;
|
|
126
|
+
}, z.core.$strip>>;
|
|
127
|
+
pi: z.ZodOptional<z.ZodObject<{
|
|
128
|
+
model: z.ZodOptional<z.ZodString>;
|
|
129
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
130
|
+
thinking: z.ZodOptional<z.ZodString>;
|
|
131
|
+
}, z.core.$strip>>;
|
|
132
|
+
opencode: z.ZodOptional<z.ZodObject<{
|
|
133
|
+
modelID: z.ZodOptional<z.ZodString>;
|
|
134
|
+
providerID: z.ZodOptional<z.ZodString>;
|
|
135
|
+
}, z.core.$strip>>;
|
|
136
|
+
kimi: z.ZodOptional<z.ZodObject<{
|
|
137
|
+
model: z.ZodOptional<z.ZodString>;
|
|
138
|
+
thinkingEffort: z.ZodOptional<z.ZodString>;
|
|
139
|
+
}, z.core.$strip>>;
|
|
140
|
+
}, z.core.$strip>>;
|
|
141
|
+
idle: z.ZodDefault<z.ZodObject<{
|
|
142
|
+
watchdogMinutes: z.ZodDefault<z.ZodNumber>;
|
|
143
|
+
}, z.core.$strip>>;
|
|
144
|
+
output: z.ZodDefault<z.ZodObject<{
|
|
145
|
+
showThinking: z.ZodDefault<z.ZodBoolean>;
|
|
146
|
+
showToolUse: z.ZodDefault<z.ZodBoolean>;
|
|
147
|
+
showToolResult: z.ZodDefault<z.ZodBoolean>;
|
|
148
|
+
}, z.core.$strip>>;
|
|
149
|
+
logging: z.ZodDefault<z.ZodObject<{
|
|
150
|
+
level: z.ZodDefault<z.ZodEnum<{
|
|
151
|
+
debug: "debug";
|
|
152
|
+
info: "info";
|
|
153
|
+
warn: "warn";
|
|
154
|
+
error: "error";
|
|
155
|
+
}>>;
|
|
156
|
+
}, z.core.$strip>>;
|
|
157
|
+
defaultAgent: z.ZodDefault<z.ZodEnum<{
|
|
158
|
+
claude: "claude";
|
|
159
|
+
codex: "codex";
|
|
160
|
+
opencode: "opencode";
|
|
161
|
+
pi: "pi";
|
|
162
|
+
kimi: "kimi";
|
|
163
|
+
}>>;
|
|
164
|
+
}, z.core.$strip>;
|
|
165
|
+
export type AppConfig = z.infer<typeof AppConfigSchema>;
|
|
166
|
+
export declare function loadConfig(configPath: string): AppConfig;
|
|
167
|
+
/**
|
|
168
|
+
* 将卡片短 key 映射到 schema 期望的路径:
|
|
169
|
+
* pi.xxx → agents.pi.xxx
|
|
170
|
+
* codex.xxx → agents.codex.xxx
|
|
171
|
+
* opencode.xxx → agents.opencode.xxx
|
|
172
|
+
* claude.xxx → claude.xxx (顶层)
|
|
173
|
+
* 其他 → 原样返回
|
|
174
|
+
*
|
|
175
|
+
* config 与 router 共用此函数(G11 Inconsistency 修复)。
|
|
176
|
+
*/
|
|
177
|
+
export declare function mapAgentKey(key: string): string;
|
|
178
|
+
/**
|
|
179
|
+
* 拒绝原型链危险 key 段(§P1-4)。
|
|
180
|
+
*
|
|
181
|
+
* `/config` 直写路径的 key 是用户自由输入:`__proto__.polluted` 会通过
|
|
182
|
+
* `current['__proto__']` 拿到 Object.prototype 并写入,污染整个进程且不可恢复;
|
|
183
|
+
* `constructor.prototype.x` 会把垃圾键写进 config.yaml。三个危险段在合法
|
|
184
|
+
* config 路径中不存在,写/删/读三条路径统一拒绝。
|
|
185
|
+
*/
|
|
186
|
+
export declare function assertSafeKeyPart(part: string): void;
|
|
187
|
+
/** Get a nested value from config by dot-separated key, e.g. "feishu.appId" */
|
|
188
|
+
export declare function getConfigValue(config: AppConfig, key: string): unknown;
|
|
189
|
+
/** Set a nested value in config by dot-separated key, write back to YAML file */
|
|
190
|
+
export declare function setConfigValue(configPath: string, config: AppConfig, key: string, value: string): AppConfig;
|
|
191
|
+
/**
|
|
192
|
+
* Set multiple nested values in config, write back to YAML file once.
|
|
193
|
+
*
|
|
194
|
+
* 在 draft 副本上操作(structuredClone),验证通过后才写盘,避免校验失败时
|
|
195
|
+
* 内存中的 config 已被污染(P0 atomicity)。
|
|
196
|
+
*/
|
|
197
|
+
export declare function setConfigValues(configPath: string, config: AppConfig, updates: Record<string, string | undefined>): AppConfig;
|
|
198
|
+
/** Type helpers for agent config (used by getAgentConfig). */
|
|
199
|
+
type ClaudeConfig = z.infer<typeof ClaudeConfigSchema>;
|
|
200
|
+
type CodexConfig = z.infer<typeof CodexConfigSchema>;
|
|
201
|
+
type OpencodeConfig = z.infer<typeof OpencodeConfigSchema>;
|
|
202
|
+
type PiConfig = z.infer<typeof PiConfigSchema>;
|
|
203
|
+
type KimiConfig = z.infer<typeof KimiConfigSchema>;
|
|
204
|
+
/** Get configuration for a specific agent. Falls back to defaults if not configured. */
|
|
205
|
+
export declare function getAgentConfig(config: AppConfig, kind: 'claude'): ClaudeConfig;
|
|
206
|
+
export declare function getAgentConfig(config: AppConfig, kind: 'codex'): CodexConfig | undefined;
|
|
207
|
+
export declare function getAgentConfig(config: AppConfig, kind: 'opencode'): OpencodeConfig | undefined;
|
|
208
|
+
export declare function getAgentConfig(config: AppConfig, kind: 'pi'): PiConfig | undefined;
|
|
209
|
+
export declare function getAgentConfig(config: AppConfig, kind: 'kimi'): KimiConfig | undefined;
|
|
210
|
+
/**
|
|
211
|
+
* 从 Claude settings.json 的 env 中读取所有以 MODEL 结尾的环境变量值,
|
|
212
|
+
* 返回去重后的模型 ID 列表。
|
|
213
|
+
* 例如 env 中有 ANTHROPIC_MODEL, ANTHROPIC_DEFAULT_OPUS_MODEL 等,
|
|
214
|
+
* 提取所有值作为可选模型。
|
|
215
|
+
*
|
|
216
|
+
* 注意:只有当用户配置了自定义 base URL 时才返回动态模型列表,
|
|
217
|
+
* 否则返回空数组(使用默认的 alias 列表)。
|
|
218
|
+
*/
|
|
219
|
+
export declare function getModelOptionsFromSettings(settingsPath: string): string[];
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import YAML from 'yaml';
|
|
5
|
+
import { getLogger } from '../logger/index.js';
|
|
6
|
+
import { atomicWrite } from '../persistence/atomic-write.js';
|
|
7
|
+
export { getConfigDir } from './dir.js';
|
|
8
|
+
// Import constants from agent config files (SSOT: Layer 1 source)
|
|
9
|
+
import { KIMI_THINKING_EFFORTS } from './kimi-config.js';
|
|
10
|
+
/** Valid effort values for Claude */
|
|
11
|
+
export const CLAUDE_EFFORTS = ['low', 'medium', 'high', 'xhigh', 'max'];
|
|
12
|
+
/** Valid thinking levels for Pi */
|
|
13
|
+
export const PI_THINKING_LEVELS = ['off', 'minimal', 'low', 'medium', 'high', 'xhigh'];
|
|
14
|
+
/** 默认值常量:schema 与 template 共享,避免双源不一致(G25 Magic Numbers)。 */
|
|
15
|
+
const DEFAULTS = {
|
|
16
|
+
CLAUDE_BINARY: 'claude',
|
|
17
|
+
CLAUDE_MODEL: 'claude-opus-4-8',
|
|
18
|
+
STOP_GRACE_MS: 5000,
|
|
19
|
+
IDLE_WATCHDOG_MINUTES: 15,
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Default SIGTERM→SIGKILL grace period (ms). Exported so runners (SpawningRunner)
|
|
23
|
+
* and config-loading paths (src/index.ts) can reuse the same source of truth
|
|
24
|
+
* instead of re-literalizing `5000` (Clean Code P3-1, G25).
|
|
25
|
+
*/
|
|
26
|
+
export const DEFAULT_STOP_GRACE_MS = DEFAULTS.STOP_GRACE_MS;
|
|
27
|
+
/** 模型 ID → alias 映射。 */
|
|
28
|
+
export const MODEL_ID_TO_ALIAS = {
|
|
29
|
+
'claude-opus-4-8': 'opus',
|
|
30
|
+
'claude-sonnet-4-6': 'sonnet',
|
|
31
|
+
'claude-haiku-4-5-20250501': 'haiku',
|
|
32
|
+
'claude-fable-5': 'fable',
|
|
33
|
+
};
|
|
34
|
+
/** alias → model ID 反向映射。 */
|
|
35
|
+
export const MODEL_ALIAS_TO_ID = {
|
|
36
|
+
opus: 'claude-opus-4-8',
|
|
37
|
+
sonnet: 'claude-sonnet-4-6',
|
|
38
|
+
haiku: 'claude-haiku-4-5-20250501',
|
|
39
|
+
fable: 'claude-fable-5',
|
|
40
|
+
};
|
|
41
|
+
const FeishuConfigSchema = z.object({
|
|
42
|
+
appId: z.string().min(1),
|
|
43
|
+
appSecret: z.string().min(1),
|
|
44
|
+
});
|
|
45
|
+
const ClaudeConfigSchema = z.object({
|
|
46
|
+
binary: z.string().default(DEFAULTS.CLAUDE_BINARY),
|
|
47
|
+
model: z.string().default(DEFAULTS.CLAUDE_MODEL),
|
|
48
|
+
effort: z.enum(CLAUDE_EFFORTS).default('medium'),
|
|
49
|
+
// permissionMode 硬编码为 bypassPermissions(runner 内部),不通过 config 配置
|
|
50
|
+
stopGraceMs: z.number().int().min(0).default(DEFAULTS.STOP_GRACE_MS),
|
|
51
|
+
});
|
|
52
|
+
/** Codex-specific configuration. */
|
|
53
|
+
export const CodexConfigSchema = z.object({
|
|
54
|
+
/** Path to codex binary. Default: 'codex' (in PATH). */
|
|
55
|
+
binary: z.string().default('codex'),
|
|
56
|
+
/** model to use. Undefined → codex reads from its config.toml. */
|
|
57
|
+
model: z.string().optional(),
|
|
58
|
+
/** model provider, e.g. 'volcengine-coding-plan'. Undefined → codex reads from its config.toml. */
|
|
59
|
+
modelProvider: z.string().optional(),
|
|
60
|
+
// approvalPolicy 和 sandboxPolicy 在 runner 内硬编码(exec 模式使用 approval_policy=never)
|
|
61
|
+
/**
|
|
62
|
+
* Reasoning effort level。codex 标准档位 minimal/low/medium/high/xhigh/max/ultra
|
|
63
|
+
* 之外还接受 none 与模型自定义值(ReasoningEffort::Custom),目录声明什么就存什么
|
|
64
|
+
* (P2-5),故用字符串而非枚举。
|
|
65
|
+
*/
|
|
66
|
+
// codex 拒绝空串档位(ReasoningEffort::from_str "" → Err,P3-3)
|
|
67
|
+
reasoningEffort: z.string().min(1).optional(),
|
|
68
|
+
/** Stop grace period in milliseconds. */
|
|
69
|
+
stopGraceMs: z.number().int().min(0).default(5000),
|
|
70
|
+
});
|
|
71
|
+
/** OpenCode-specific configuration (run mode: opencode run --format json --auto). */
|
|
72
|
+
const OpencodeConfigSchema = z.object({
|
|
73
|
+
/** Path to opencode binary. Default: 'opencode' (in PATH). */
|
|
74
|
+
binary: z.string().default('opencode'),
|
|
75
|
+
/** Provider ID for the LLM backend (e.g. 'anthropic'). */
|
|
76
|
+
providerID: z.string().default('anthropic'),
|
|
77
|
+
/** Model ID for the LLM backend (e.g. 'claude-sonnet-4-20250514'). */
|
|
78
|
+
modelID: z.string().default('claude-sonnet-4-20250514'),
|
|
79
|
+
});
|
|
80
|
+
/** Pi-specific configuration. pi is a spawn-per-message CLI like Claude. */
|
|
81
|
+
const PiConfigSchema = z.object({
|
|
82
|
+
/** Path to pi binary. Default: 'pi' (in PATH). */
|
|
83
|
+
binary: z.string().default('pi'),
|
|
84
|
+
/** LLM provider, e.g. 'Volcano', 'anthropic', 'openai'. */
|
|
85
|
+
provider: z.string().default('Volcano'),
|
|
86
|
+
/** Model ID or alias, e.g. 'glm-5.2'. */
|
|
87
|
+
model: z.string().default('glm-5.2'),
|
|
88
|
+
/** Thinking level: off/minimal/low/medium/high/xhigh. */
|
|
89
|
+
thinking: z.enum(PI_THINKING_LEVELS).default('medium'),
|
|
90
|
+
/** Comma-separated tool whitelist. */
|
|
91
|
+
tools: z.string().default('read,bash,edit,write,grep,find,ls'),
|
|
92
|
+
});
|
|
93
|
+
/** Kimi-specific configuration. kimi is a spawn-per-message CLI. */
|
|
94
|
+
const KimiConfigSchema = z.object({
|
|
95
|
+
/** Path to kimi binary. Default: 'kimi' (in PATH). */
|
|
96
|
+
binary: z.string().default('kimi'),
|
|
97
|
+
/** Model ID or alias, e.g. 'kimi-code/k3'. */
|
|
98
|
+
model: z.string().default('kimi-code/k3'),
|
|
99
|
+
/** Thinking effort: 'on', 'max'. */
|
|
100
|
+
thinkingEffort: z.enum(KIMI_THINKING_EFFORTS).default('max'),
|
|
101
|
+
});
|
|
102
|
+
/** Agents configuration: per-agent settings keyed by agent kind. */
|
|
103
|
+
const AgentsConfigSchema = z.object({
|
|
104
|
+
codex: CodexConfigSchema.optional(),
|
|
105
|
+
opencode: OpencodeConfigSchema.optional(),
|
|
106
|
+
pi: PiConfigSchema.optional(),
|
|
107
|
+
kimi: KimiConfigSchema.optional(),
|
|
108
|
+
});
|
|
109
|
+
const IdleConfigSchema = z.object({
|
|
110
|
+
/**
|
|
111
|
+
* Idle watchdog 超时窗口(分钟)。Claude run 在此时间内无 stdout 事件则被
|
|
112
|
+
* 视为挂死,bridge 自动 runner.stop() 解除串行队列阻塞(§9.12)。
|
|
113
|
+
* 0 = 关闭 watchdog(不推荐,单次卡死会永久阻塞队列)。
|
|
114
|
+
*/
|
|
115
|
+
watchdogMinutes: z.number().int().min(0).default(DEFAULTS.IDLE_WATCHDOG_MINUTES),
|
|
116
|
+
});
|
|
117
|
+
const OutputConfigSchema = z.object({
|
|
118
|
+
showThinking: z.boolean().default(true),
|
|
119
|
+
showToolUse: z.boolean().default(true),
|
|
120
|
+
showToolResult: z.boolean().default(true),
|
|
121
|
+
});
|
|
122
|
+
const LoggingConfigSchema = z.object({
|
|
123
|
+
level: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
|
|
124
|
+
});
|
|
125
|
+
/** Agent-specific saved choices for quick switching. */
|
|
126
|
+
const AgentChoicesSchema = z.object({
|
|
127
|
+
codex: z
|
|
128
|
+
.object({
|
|
129
|
+
model: z.string().optional(),
|
|
130
|
+
modelProvider: z.string().optional(),
|
|
131
|
+
})
|
|
132
|
+
.optional(),
|
|
133
|
+
pi: z
|
|
134
|
+
.object({
|
|
135
|
+
model: z.string().optional(),
|
|
136
|
+
provider: z.string().optional(),
|
|
137
|
+
thinking: z.string().optional(),
|
|
138
|
+
})
|
|
139
|
+
.optional(),
|
|
140
|
+
opencode: z
|
|
141
|
+
.object({
|
|
142
|
+
modelID: z.string().optional(),
|
|
143
|
+
providerID: z.string().optional(),
|
|
144
|
+
})
|
|
145
|
+
.optional(),
|
|
146
|
+
kimi: z
|
|
147
|
+
.object({
|
|
148
|
+
model: z.string().optional(),
|
|
149
|
+
thinkingEffort: z.string().optional(),
|
|
150
|
+
})
|
|
151
|
+
.optional(),
|
|
152
|
+
});
|
|
153
|
+
export const AppConfigSchema = z.object({
|
|
154
|
+
feishu: FeishuConfigSchema,
|
|
155
|
+
/** Claude config (top-level; other agents live under `agents`). */
|
|
156
|
+
claude: ClaudeConfigSchema.default(ClaudeConfigSchema.parse({})),
|
|
157
|
+
/** Per-agent configuration for non-claude agents. */
|
|
158
|
+
agents: AgentsConfigSchema.optional(),
|
|
159
|
+
/** Agent-specific saved choices for quick switching. */
|
|
160
|
+
agentChoices: AgentChoicesSchema.optional(),
|
|
161
|
+
idle: IdleConfigSchema.default(IdleConfigSchema.parse({})),
|
|
162
|
+
output: OutputConfigSchema.default(OutputConfigSchema.parse({})),
|
|
163
|
+
logging: LoggingConfigSchema.default(LoggingConfigSchema.parse({})),
|
|
164
|
+
/** Default agent for new runs. */
|
|
165
|
+
defaultAgent: z.enum(['claude', 'codex', 'opencode', 'pi', 'kimi']).default('claude'),
|
|
166
|
+
});
|
|
167
|
+
const TEMPLATE = `feishu:
|
|
168
|
+
appId: ""
|
|
169
|
+
appSecret: ""
|
|
170
|
+
|
|
171
|
+
claude:
|
|
172
|
+
binary: ${DEFAULTS.CLAUDE_BINARY}
|
|
173
|
+
model: ${DEFAULTS.CLAUDE_MODEL}
|
|
174
|
+
effort: medium
|
|
175
|
+
stopGraceMs: ${DEFAULTS.STOP_GRACE_MS}
|
|
176
|
+
|
|
177
|
+
idle:
|
|
178
|
+
watchdogMinutes: ${DEFAULTS.IDLE_WATCHDOG_MINUTES}
|
|
179
|
+
|
|
180
|
+
output:
|
|
181
|
+
showThinking: true
|
|
182
|
+
showToolUse: true
|
|
183
|
+
showToolResult: true
|
|
184
|
+
|
|
185
|
+
logging:
|
|
186
|
+
level: info
|
|
187
|
+
|
|
188
|
+
defaultAgent: claude
|
|
189
|
+
`;
|
|
190
|
+
export function loadConfig(configPath) {
|
|
191
|
+
if (!fs.existsSync(configPath)) {
|
|
192
|
+
const dir = path.dirname(configPath);
|
|
193
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
194
|
+
fs.writeFileSync(configPath, TEMPLATE, 'utf-8');
|
|
195
|
+
console.error(`[lark-remote] config template generated at ${configPath}`);
|
|
196
|
+
console.error('[lark-remote] please fill in feishu.appId and feishu.appSecret, then restart');
|
|
197
|
+
process.exit(1);
|
|
198
|
+
}
|
|
199
|
+
const raw = fs.readFileSync(configPath, 'utf-8');
|
|
200
|
+
const parsed = YAML.parse(raw);
|
|
201
|
+
const result = AppConfigSchema.safeParse(parsed);
|
|
202
|
+
if (!result.success) {
|
|
203
|
+
const errors = result.error.issues.map((i) => ` ${i.path.join('.')}: ${i.message}`).join('\n');
|
|
204
|
+
console.error(`[lark-remote] config validation failed:\n${errors}`);
|
|
205
|
+
process.exit(1);
|
|
206
|
+
}
|
|
207
|
+
const config = result.data;
|
|
208
|
+
return config;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Agent key 前缀,这些前缀的 key 会映射到 `agents.<key>` 路径下。
|
|
212
|
+
* `claude.` 保持顶层(不映射到 agents.claude)。
|
|
213
|
+
*/
|
|
214
|
+
const AGENT_PREFIXES = ['pi', 'codex', 'opencode', 'kimi'];
|
|
215
|
+
/**
|
|
216
|
+
* 将卡片短 key 映射到 schema 期望的路径:
|
|
217
|
+
* pi.xxx → agents.pi.xxx
|
|
218
|
+
* codex.xxx → agents.codex.xxx
|
|
219
|
+
* opencode.xxx → agents.opencode.xxx
|
|
220
|
+
* claude.xxx → claude.xxx (顶层)
|
|
221
|
+
* 其他 → 原样返回
|
|
222
|
+
*
|
|
223
|
+
* config 与 router 共用此函数(G11 Inconsistency 修复)。
|
|
224
|
+
*/
|
|
225
|
+
export function mapAgentKey(key) {
|
|
226
|
+
const firstDot = key.indexOf('.');
|
|
227
|
+
const prefix = firstDot === -1 ? key : key.slice(0, firstDot);
|
|
228
|
+
if (AGENT_PREFIXES.includes(prefix)) {
|
|
229
|
+
return `agents.${key}`;
|
|
230
|
+
}
|
|
231
|
+
return key;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* 将字符串值强制转换为合适的类型(boolean / number / string)。
|
|
235
|
+
* 支持 case-insensitive 的 'true'/'false',以及整数和浮点数(含负数)。
|
|
236
|
+
*/
|
|
237
|
+
function coerceValue(raw) {
|
|
238
|
+
const lower = raw.toLowerCase();
|
|
239
|
+
if (lower === 'true')
|
|
240
|
+
return true;
|
|
241
|
+
if (lower === 'false')
|
|
242
|
+
return false;
|
|
243
|
+
if (/^-?\d+$/.test(raw))
|
|
244
|
+
return Number(raw);
|
|
245
|
+
if (/^-?\d+\.\d+$/.test(raw))
|
|
246
|
+
return Number(raw);
|
|
247
|
+
return raw;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* 拒绝原型链危险 key 段(§P1-4)。
|
|
251
|
+
*
|
|
252
|
+
* `/config` 直写路径的 key 是用户自由输入:`__proto__.polluted` 会通过
|
|
253
|
+
* `current['__proto__']` 拿到 Object.prototype 并写入,污染整个进程且不可恢复;
|
|
254
|
+
* `constructor.prototype.x` 会把垃圾键写进 config.yaml。三个危险段在合法
|
|
255
|
+
* config 路径中不存在,写/删/读三条路径统一拒绝。
|
|
256
|
+
*/
|
|
257
|
+
export function assertSafeKeyPart(part) {
|
|
258
|
+
if (part === '__proto__' || part === 'prototype' || part === 'constructor') {
|
|
259
|
+
throw new Error(`[lark-remote] invalid config key segment: '${part}'`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/** 在对象上按 dot-separated key 设置嵌套值(仅修改内存对象,不写盘)。 */
|
|
263
|
+
function setNestedValue(target, key, value) {
|
|
264
|
+
const parts = key.split('.');
|
|
265
|
+
let current = target;
|
|
266
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
267
|
+
assertSafeKeyPart(parts[i]);
|
|
268
|
+
const next = current[parts[i]];
|
|
269
|
+
if (next == null || typeof next !== 'object') {
|
|
270
|
+
current[parts[i]] = {};
|
|
271
|
+
}
|
|
272
|
+
current = current[parts[i]];
|
|
273
|
+
}
|
|
274
|
+
const lastPart = parts[parts.length - 1];
|
|
275
|
+
assertSafeKeyPart(lastPart);
|
|
276
|
+
current[lastPart] = value;
|
|
277
|
+
}
|
|
278
|
+
/** Get a nested value from config by dot-separated key, e.g. "feishu.appId" */
|
|
279
|
+
export function getConfigValue(config, key) {
|
|
280
|
+
const parts = key.split('.');
|
|
281
|
+
let current = config;
|
|
282
|
+
for (const part of parts) {
|
|
283
|
+
assertSafeKeyPart(part);
|
|
284
|
+
if (current == null || typeof current !== 'object')
|
|
285
|
+
return undefined;
|
|
286
|
+
current = current[part];
|
|
287
|
+
}
|
|
288
|
+
return current;
|
|
289
|
+
}
|
|
290
|
+
/** Set a nested value in config by dot-separated key, write back to YAML file */
|
|
291
|
+
export function setConfigValue(configPath, config, key, value) {
|
|
292
|
+
return setConfigValues(configPath, config, { [key]: value });
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Set multiple nested values in config, write back to YAML file once.
|
|
296
|
+
*
|
|
297
|
+
* 在 draft 副本上操作(structuredClone),验证通过后才写盘,避免校验失败时
|
|
298
|
+
* 内存中的 config 已被污染(P0 atomicity)。
|
|
299
|
+
*/
|
|
300
|
+
export function setConfigValues(configPath, config, updates) {
|
|
301
|
+
const draft = structuredClone(config);
|
|
302
|
+
for (const [key, value] of Object.entries(updates)) {
|
|
303
|
+
if (value === undefined) {
|
|
304
|
+
// undefined 表示删除该键(如清空 reasoningEffort),
|
|
305
|
+
// 不能写 "undefined" 字面量进 config.yaml
|
|
306
|
+
deleteNestedValue(draft, mapAgentKey(key));
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
setNestedValue(draft, mapAgentKey(key), coerceValue(value));
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
// 运行时校验:不能用 loadConfig(它失败时会 process.exit 杀死 bridge),
|
|
313
|
+
// 改用 safeParse + throw,让 router 把错误反馈给用户
|
|
314
|
+
const result = AppConfigSchema.safeParse(draft);
|
|
315
|
+
if (!result.success) {
|
|
316
|
+
const errors = result.error.issues.map((i) => ` ${i.path.join('.')}: ${i.message}`).join('\n');
|
|
317
|
+
throw new Error(`[lark-remote] config validation failed:\n${errors}`);
|
|
318
|
+
}
|
|
319
|
+
atomicWrite(configPath, YAML.stringify(result.data));
|
|
320
|
+
return result.data;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* 按 dot-separated key 删除嵌套值(不存在的键静默忽略)。
|
|
324
|
+
*/
|
|
325
|
+
function deleteNestedValue(target, key) {
|
|
326
|
+
const parts = key.split('.');
|
|
327
|
+
let current = target;
|
|
328
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
329
|
+
assertSafeKeyPart(parts[i]);
|
|
330
|
+
const next = current[parts[i]];
|
|
331
|
+
if (next == null || typeof next !== 'object')
|
|
332
|
+
return;
|
|
333
|
+
current = next;
|
|
334
|
+
}
|
|
335
|
+
const lastPart = parts[parts.length - 1];
|
|
336
|
+
assertSafeKeyPart(lastPart);
|
|
337
|
+
delete current[lastPart];
|
|
338
|
+
}
|
|
339
|
+
export function getAgentConfig(config, kind) {
|
|
340
|
+
if (kind === 'claude') {
|
|
341
|
+
return config.claude;
|
|
342
|
+
}
|
|
343
|
+
return config.agents?.[kind];
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* 从 Claude settings.json 的 env 中读取所有以 MODEL 结尾的环境变量值,
|
|
347
|
+
* 返回去重后的模型 ID 列表。
|
|
348
|
+
* 例如 env 中有 ANTHROPIC_MODEL, ANTHROPIC_DEFAULT_OPUS_MODEL 等,
|
|
349
|
+
* 提取所有值作为可选模型。
|
|
350
|
+
*
|
|
351
|
+
* 注意:只有当用户配置了自定义 base URL 时才返回动态模型列表,
|
|
352
|
+
* 否则返回空数组(使用默认的 alias 列表)。
|
|
353
|
+
*/
|
|
354
|
+
export function getModelOptionsFromSettings(settingsPath) {
|
|
355
|
+
if (!settingsPath)
|
|
356
|
+
return [];
|
|
357
|
+
if (!fs.existsSync(settingsPath))
|
|
358
|
+
return [];
|
|
359
|
+
try {
|
|
360
|
+
const content = fs.readFileSync(settingsPath, 'utf-8');
|
|
361
|
+
const settings = JSON.parse(content);
|
|
362
|
+
if (!settings.env || typeof settings.env !== 'object')
|
|
363
|
+
return [];
|
|
364
|
+
// 检查是否配置了自定义 base URL
|
|
365
|
+
// 如果使用默认的 Claude API,则返回空数组(使用默认 alias 列表)
|
|
366
|
+
const hasCustomBaseUrl = settings.env.ANTHROPIC_BASE_URL || settings.env.CLAUDE_CODE_BASE_URL;
|
|
367
|
+
if (!hasCustomBaseUrl) {
|
|
368
|
+
return [];
|
|
369
|
+
}
|
|
370
|
+
const modelSet = new Set();
|
|
371
|
+
for (const key of Object.keys(settings.env)) {
|
|
372
|
+
if (key.endsWith('MODEL')) {
|
|
373
|
+
const value = settings.env[key];
|
|
374
|
+
if (typeof value === 'string' && value.trim()) {
|
|
375
|
+
modelSet.add(value.trim());
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return Array.from(modelSet);
|
|
380
|
+
}
|
|
381
|
+
catch (err) {
|
|
382
|
+
if (err.code === 'ENOENT')
|
|
383
|
+
return [];
|
|
384
|
+
getLogger().warn(`[config] getModelOptionsFromSettings failed for ${settingsPath}: ${err}`);
|
|
385
|
+
return [];
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kimi config loader
|
|
3
|
+
*
|
|
4
|
+
* Dynamically reads available models from `kimi provider list --json`,
|
|
5
|
+
* provides dynamic dropdown options for /config card.
|
|
6
|
+
*/
|
|
7
|
+
/** Valid thinking effort values for kimi (Layer 1: Schema enum source) */
|
|
8
|
+
export declare const KIMI_THINKING_EFFORTS: readonly ["low", "high", "max"];
|
|
9
|
+
export type KimiThinkingEffort = (typeof KIMI_THINKING_EFFORTS)[number];
|
|
10
|
+
/** Fallback efforts when all values are filtered out */
|
|
11
|
+
export declare const FALLBACK_EFFORTS: readonly string[];
|
|
12
|
+
/** Load Kimi config and return available models */
|
|
13
|
+
interface KimiConfigResult {
|
|
14
|
+
/** Current default model */
|
|
15
|
+
currentModel: string;
|
|
16
|
+
/** Available model list */
|
|
17
|
+
modelOptions: string[];
|
|
18
|
+
/** Model -> display name mapping */
|
|
19
|
+
modelDisplayNames: Record<string, string>;
|
|
20
|
+
/** Model -> supported efforts mapping */
|
|
21
|
+
modelEfforts: Record<string, string[]>;
|
|
22
|
+
/** Model -> default effort mapping */
|
|
23
|
+
modelDefaultEfforts: Record<string, string>;
|
|
24
|
+
}
|
|
25
|
+
/** 清空缓存(测试与配置热更新用,与 codex/opencode 的 invalidate 对齐) */
|
|
26
|
+
export declare function invalidateKimiConfigCache(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Load Kimi models from `kimi provider list --json`.
|
|
29
|
+
* Falls back to defaults if the command fails.
|
|
30
|
+
* Uses caching to avoid repeated sync calls.
|
|
31
|
+
*/
|
|
32
|
+
export declare function loadKimiConfig(): KimiConfigResult;
|
|
33
|
+
export {};
|