@di-code/coding-agent 0.1.2 → 0.1.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 +499 -143
- package/dist/cli.d.ts +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +15 -0
- package/dist/cli.js.map +1 -1
- package/dist/core/clipboard-image.d.ts +13 -0
- package/dist/core/clipboard-image.d.ts.map +1 -0
- package/dist/core/clipboard-image.js +99 -0
- package/dist/core/clipboard-image.js.map +1 -0
- package/dist/core/context-builder.d.ts.map +1 -1
- package/dist/core/context-builder.js +6 -2
- package/dist/core/context-builder.js.map +1 -1
- package/dist/core/image-input.d.ts +13 -0
- package/dist/core/image-input.d.ts.map +1 -0
- package/dist/core/image-input.js +147 -0
- package/dist/core/image-input.js.map +1 -0
- package/dist/core/session/session-storage.d.ts.map +1 -1
- package/dist/core/session/session-storage.js +1 -0
- package/dist/core/session/session-storage.js.map +1 -1
- package/dist/core/session.d.ts +19 -2
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +101 -4
- package/dist/core/session.js.map +1 -1
- package/dist/core/tools/bash.d.ts +2 -2
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +25 -0
- package/dist/core/tools/edit-diff.d.ts.map +1 -0
- package/dist/core/tools/edit-diff.js +136 -0
- package/dist/core/tools/edit-diff.js.map +1 -0
- package/dist/core/tools/edit.d.ts +13 -4
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +64 -30
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/read.d.ts +2 -2
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/write.d.ts +2 -2
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js.map +1 -1
- package/dist/entry.js +9 -2
- package/dist/entry.js.map +1 -1
- package/dist/main.d.ts +3 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +42 -8
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive-components.d.ts +3 -0
- package/dist/modes/interactive-components.d.ts.map +1 -1
- package/dist/modes/interactive-components.js +76 -25
- package/dist/modes/interactive-components.js.map +1 -1
- package/dist/modes/interactive-diff.d.ts +8 -0
- package/dist/modes/interactive-diff.d.ts.map +1 -0
- package/dist/modes/interactive-diff.js +78 -0
- package/dist/modes/interactive-diff.js.map +1 -0
- package/dist/modes/interactive-layout.d.ts +6 -1
- package/dist/modes/interactive-layout.d.ts.map +1 -1
- package/dist/modes/interactive-layout.js +21 -1
- package/dist/modes/interactive-layout.js.map +1 -1
- package/dist/modes/interactive-state.d.ts +17 -2
- package/dist/modes/interactive-state.d.ts.map +1 -1
- package/dist/modes/interactive-state.js +103 -3
- package/dist/modes/interactive-state.js.map +1 -1
- package/dist/modes/interactive.d.ts +18 -0
- package/dist/modes/interactive.d.ts.map +1 -1
- package/dist/modes/interactive.js +289 -24
- package/dist/modes/interactive.js.map +1 -1
- package/dist/provider-onboarding.d.ts +8 -1
- package/dist/provider-onboarding.d.ts.map +1 -1
- package/dist/provider-onboarding.js +53 -23
- package/dist/provider-onboarding.js.map +1 -1
- package/dist/rpc-entry.js +1 -1
- package/dist/rpc-entry.js.map +1 -1
- package/dist/startup.d.ts +11 -3
- package/dist/startup.d.ts.map +1 -1
- package/dist/startup.js +240 -84
- package/dist/startup.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts +2 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -0
- package/dist/utils/syntax-highlight.js +55 -0
- package/dist/utils/syntax-highlight.js.map +1 -0
- package/package.json +9 -4
package/dist/startup.js
CHANGED
|
@@ -1,111 +1,229 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
2
3
|
import { join } from "node:path";
|
|
3
|
-
import { createDeepSeekProvider, createFauxProvider, createOpenAIProvider, createZhipuProvider, } from "@di-code/ai";
|
|
4
|
+
import { createAnthropicProvider, createDeepSeekProvider, createFauxProvider, createOpenAIChatCompletionsProvider, createOpenAIProvider, createZhipuProvider, } from "@di-code/ai";
|
|
4
5
|
const FAUX_RESPONSES = [
|
|
5
|
-
{
|
|
6
|
+
{
|
|
7
|
+
type: "success",
|
|
8
|
+
content: [
|
|
9
|
+
{
|
|
10
|
+
type: "text",
|
|
11
|
+
text: "你好,我是di-code,一个面向终端的 TypeScript AI Coding Agent,支持多 Provider 流式对话、工具调用、JSONL 会话持久化、交互式 TUI、插件扩展与 JSONL RPC 集成。",
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
{ type: "success", content: [{ type: "text", text: "当前回复为faux数据" }] },
|
|
6
16
|
];
|
|
7
|
-
const
|
|
17
|
+
const SETTINGS_FILE_NAME = "settings.json";
|
|
18
|
+
const SETTINGS_PATH = join(".di-code", SETTINGS_FILE_NAME);
|
|
8
19
|
export function resolveStartupArgs(args) {
|
|
9
20
|
return args.length === 0 ? ["--interactive"] : args;
|
|
10
21
|
}
|
|
11
|
-
function optionalString(value, path) {
|
|
22
|
+
function optionalString(value, path, settingsPath) {
|
|
12
23
|
if (value === undefined)
|
|
13
24
|
return undefined;
|
|
14
25
|
if (typeof value !== "string")
|
|
15
|
-
throw new Error(`${
|
|
26
|
+
throw new Error(`${settingsPath}: ${path} must be a string`);
|
|
16
27
|
return value;
|
|
17
28
|
}
|
|
18
|
-
function requiredString(value, path) {
|
|
19
|
-
const result = optionalString(value, path);
|
|
29
|
+
function requiredString(value, path, settingsPath = SETTINGS_PATH) {
|
|
30
|
+
const result = optionalString(value, path, settingsPath);
|
|
20
31
|
if (!result?.trim())
|
|
21
|
-
throw new Error(`${
|
|
32
|
+
throw new Error(`${settingsPath}: ${path} must be a non-empty string`);
|
|
22
33
|
return result.trim();
|
|
23
34
|
}
|
|
24
|
-
function positiveInteger(value, path, fallback) {
|
|
35
|
+
function positiveInteger(value, path, fallback, settingsPath) {
|
|
25
36
|
const result = value ?? fallback;
|
|
26
37
|
if (!Number.isInteger(result) || result <= 0) {
|
|
27
|
-
throw new Error(`${
|
|
38
|
+
throw new Error(`${settingsPath}: ${path} must be a positive integer`);
|
|
28
39
|
}
|
|
29
40
|
return result;
|
|
30
41
|
}
|
|
31
|
-
function nonNegativeNumber(value, path, fallback) {
|
|
42
|
+
function nonNegativeNumber(value, path, fallback, settingsPath) {
|
|
32
43
|
const result = value ?? fallback;
|
|
33
44
|
if (typeof result !== "number" || !Number.isFinite(result) || result < 0) {
|
|
34
|
-
throw new Error(`${
|
|
45
|
+
throw new Error(`${settingsPath}: ${path} must be a non-negative finite number`);
|
|
35
46
|
}
|
|
36
47
|
return result;
|
|
37
48
|
}
|
|
38
|
-
function parseModels(value, path, providerId, providerApi, providerBaseUrl) {
|
|
49
|
+
function parseModels(value, path, providerId, providerApi, providerBaseUrl, settingsPath) {
|
|
39
50
|
if (value === undefined)
|
|
40
51
|
return undefined;
|
|
41
52
|
if (!Array.isArray(value))
|
|
42
|
-
throw new Error(`${
|
|
53
|
+
throw new Error(`${settingsPath}: ${path} must be an array`);
|
|
43
54
|
return value.map((entry, index) => {
|
|
44
55
|
const modelPath = `${path}[${index}]`;
|
|
45
56
|
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
|
|
46
|
-
throw new Error(`${
|
|
57
|
+
throw new Error(`${settingsPath}: ${modelPath} must be an object`);
|
|
47
58
|
}
|
|
48
59
|
const model = entry;
|
|
49
60
|
const input = model.input ?? ["text"];
|
|
50
61
|
if (!Array.isArray(input) || input.length === 0 || input.some((item) => item !== "text" && item !== "image")) {
|
|
51
|
-
throw new Error(`${
|
|
62
|
+
throw new Error(`${settingsPath}: ${modelPath}.input must contain text and/or image`);
|
|
52
63
|
}
|
|
53
64
|
const cost = model.cost ?? {};
|
|
54
65
|
if (typeof cost !== "object" || cost === null || Array.isArray(cost)) {
|
|
55
|
-
throw new Error(`${
|
|
66
|
+
throw new Error(`${settingsPath}: ${modelPath}.cost must be an object`);
|
|
56
67
|
}
|
|
57
68
|
const prices = cost;
|
|
58
69
|
if (model.reasoning !== undefined && typeof model.reasoning !== "boolean") {
|
|
59
|
-
throw new Error(`${
|
|
70
|
+
throw new Error(`${settingsPath}: ${modelPath}.reasoning must be a boolean`);
|
|
71
|
+
}
|
|
72
|
+
const configuredReasoningEfforts = model.reasoningEfforts;
|
|
73
|
+
if (configuredReasoningEfforts !== undefined) {
|
|
74
|
+
if (!Array.isArray(configuredReasoningEfforts) || configuredReasoningEfforts.length === 0) {
|
|
75
|
+
throw new Error(`${settingsPath}: ${modelPath}.reasoningEfforts must be a non-empty array`);
|
|
76
|
+
}
|
|
77
|
+
if (model.reasoning !== true ||
|
|
78
|
+
configuredReasoningEfforts.some((effort) => effort !== "low" && effort !== "medium" && effort !== "high") ||
|
|
79
|
+
new Set(configuredReasoningEfforts).size !== configuredReasoningEfforts.length) {
|
|
80
|
+
throw new Error(`${settingsPath}: ${modelPath}.reasoningEfforts requires reasoning=true and unique low, medium, or high values`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (model.cacheRetention !== undefined && model.cacheRetention !== "long") {
|
|
84
|
+
throw new Error(`${settingsPath}: ${modelPath}.cacheRetention must be "long" when provided`);
|
|
60
85
|
}
|
|
61
|
-
|
|
86
|
+
if (model.sessionAffinity !== undefined && model.sessionAffinity !== "codex") {
|
|
87
|
+
throw new Error(`${settingsPath}: ${modelPath}.sessionAffinity must be "codex" when provided`);
|
|
88
|
+
}
|
|
89
|
+
const api = optionalString(model.api, `${modelPath}.api`, settingsPath) ?? providerApi;
|
|
62
90
|
if (!api)
|
|
63
|
-
throw new Error(`${
|
|
64
|
-
|
|
65
|
-
|
|
91
|
+
throw new Error(`${settingsPath}: ${modelPath}.api is required`);
|
|
92
|
+
if (!["faux", "openai-responses", "openai-chat-completions", "anthropic-messages"].includes(api)) {
|
|
93
|
+
throw new Error(`${settingsPath}: ${modelPath}.api is unsupported`);
|
|
94
|
+
}
|
|
95
|
+
const typedApi = api;
|
|
96
|
+
const reasoningEfforts = configuredReasoningEfforts === undefined && model.reasoning === true && api === "openai-responses"
|
|
97
|
+
? ["low", "medium", "high"]
|
|
98
|
+
: configuredReasoningEfforts === undefined
|
|
99
|
+
? undefined
|
|
100
|
+
: [...configuredReasoningEfforts];
|
|
101
|
+
const baseUrl = optionalString(model.baseUrl, `${modelPath}.baseUrl`, settingsPath) ?? providerBaseUrl;
|
|
102
|
+
const id = requiredString(model.id, `${modelPath}.id`, settingsPath);
|
|
66
103
|
return {
|
|
67
104
|
id,
|
|
68
|
-
name: requiredString(model.name ?? id, `${modelPath}.name
|
|
105
|
+
name: requiredString(model.name ?? id, `${modelPath}.name`, settingsPath),
|
|
69
106
|
provider: providerId,
|
|
70
|
-
api,
|
|
107
|
+
api: typedApi,
|
|
71
108
|
...(baseUrl === undefined ? {} : { baseUrl }),
|
|
72
109
|
input: [...input],
|
|
73
110
|
reasoning: model.reasoning ?? false,
|
|
74
|
-
|
|
75
|
-
|
|
111
|
+
...(reasoningEfforts ? { reasoningEfforts } : {}),
|
|
112
|
+
...(model.cacheRetention === "long" ? { cacheRetention: "long" } : {}),
|
|
113
|
+
...(model.sessionAffinity === "codex" ? { sessionAffinity: "codex" } : {}),
|
|
114
|
+
contextWindow: positiveInteger(model.contextWindow, `${modelPath}.contextWindow`, 128_000, settingsPath),
|
|
115
|
+
maxOutputTokens: positiveInteger(model.maxTokens ?? model.maxOutputTokens, `${modelPath}.maxTokens`, 16_384, settingsPath),
|
|
76
116
|
cost: {
|
|
77
|
-
input: nonNegativeNumber(prices.input, `${modelPath}.cost.input`, 0) / 1_000_000,
|
|
78
|
-
output: nonNegativeNumber(prices.output, `${modelPath}.cost.output`, 0) / 1_000_000,
|
|
79
|
-
cacheRead: nonNegativeNumber(prices.cacheRead, `${modelPath}.cost.cacheRead`, 0) / 1_000_000,
|
|
80
|
-
cacheWrite: nonNegativeNumber(prices.cacheWrite, `${modelPath}.cost.cacheWrite`, 0) / 1_000_000,
|
|
117
|
+
input: nonNegativeNumber(prices.input, `${modelPath}.cost.input`, 0, settingsPath) / 1_000_000,
|
|
118
|
+
output: nonNegativeNumber(prices.output, `${modelPath}.cost.output`, 0, settingsPath) / 1_000_000,
|
|
119
|
+
cacheRead: nonNegativeNumber(prices.cacheRead, `${modelPath}.cost.cacheRead`, 0, settingsPath) / 1_000_000,
|
|
120
|
+
cacheWrite: nonNegativeNumber(prices.cacheWrite, `${modelPath}.cost.cacheWrite`, 0, settingsPath) / 1_000_000,
|
|
81
121
|
},
|
|
82
122
|
};
|
|
83
123
|
});
|
|
84
124
|
}
|
|
85
|
-
function parseSettings(value) {
|
|
125
|
+
function parseSettings(value, settingsPath) {
|
|
86
126
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
87
|
-
throw new Error(`${
|
|
127
|
+
throw new Error(`${settingsPath}: root value must be an object`);
|
|
88
128
|
}
|
|
89
129
|
const record = value;
|
|
90
130
|
const providersValue = record.providers;
|
|
91
131
|
if (typeof providersValue !== "object" || providersValue === null || Array.isArray(providersValue)) {
|
|
92
|
-
throw new Error(`${
|
|
132
|
+
throw new Error(`${settingsPath}: providers must be an object`);
|
|
93
133
|
}
|
|
94
134
|
const providers = {};
|
|
95
135
|
for (const [id, entry] of Object.entries(providersValue)) {
|
|
96
136
|
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
|
|
97
|
-
throw new Error(`${
|
|
137
|
+
throw new Error(`${settingsPath}: providers.${id} must be an object`);
|
|
98
138
|
}
|
|
99
139
|
const provider = entry;
|
|
100
140
|
providers[id] = {
|
|
101
|
-
name: optionalString(provider.name, `providers.${id}.name
|
|
102
|
-
baseUrl: optionalString(provider.baseUrl, `providers.${id}.baseUrl
|
|
103
|
-
apiKey: optionalString(provider.apiKey, `providers.${id}.apiKey
|
|
104
|
-
api: optionalString(provider.api, `providers.${id}.api
|
|
141
|
+
name: optionalString(provider.name, `providers.${id}.name`, settingsPath),
|
|
142
|
+
baseUrl: optionalString(provider.baseUrl, `providers.${id}.baseUrl`, settingsPath),
|
|
143
|
+
apiKey: optionalString(provider.apiKey, `providers.${id}.apiKey`, settingsPath),
|
|
144
|
+
api: optionalString(provider.api, `providers.${id}.api`, settingsPath),
|
|
105
145
|
models: provider.models,
|
|
106
146
|
};
|
|
107
147
|
}
|
|
108
|
-
|
|
148
|
+
const defaultProvider = record.defaultProvider === undefined
|
|
149
|
+
? undefined
|
|
150
|
+
: requiredString(record.defaultProvider, "defaultProvider", settingsPath);
|
|
151
|
+
const defaultModel = record.defaultModel === undefined ? undefined : requiredString(record.defaultModel, "defaultModel", settingsPath);
|
|
152
|
+
return {
|
|
153
|
+
providers,
|
|
154
|
+
...(defaultProvider === undefined ? {} : { defaultProvider }),
|
|
155
|
+
...(defaultModel === undefined ? {} : { defaultModel }),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
async function readSettingsFile(path, displayPath) {
|
|
159
|
+
try {
|
|
160
|
+
const source = await readFile(path, "utf8");
|
|
161
|
+
if (source.trim().length === 0)
|
|
162
|
+
return undefined;
|
|
163
|
+
return parseSettings(JSON.parse(source), displayPath);
|
|
164
|
+
}
|
|
165
|
+
catch (cause) {
|
|
166
|
+
if (cause instanceof Error && "code" in cause && cause.code === "ENOENT")
|
|
167
|
+
return undefined;
|
|
168
|
+
if (cause instanceof SyntaxError)
|
|
169
|
+
throw new Error(`${displayPath}: invalid JSON`, { cause });
|
|
170
|
+
throw cause;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function mergeSettings(globalSettings, projectSettings) {
|
|
174
|
+
const globalProviders = globalSettings?.providers ?? {};
|
|
175
|
+
const projectProviders = projectSettings?.providers ?? {};
|
|
176
|
+
const providers = { ...globalProviders };
|
|
177
|
+
for (const [id, projectProvider] of Object.entries(projectProviders)) {
|
|
178
|
+
providers[id] = {
|
|
179
|
+
...globalProviders[id],
|
|
180
|
+
...(projectProvider.name === undefined ? {} : { name: projectProvider.name }),
|
|
181
|
+
...(projectProvider.baseUrl === undefined ? {} : { baseUrl: projectProvider.baseUrl }),
|
|
182
|
+
...(projectProvider.apiKey === undefined ? {} : { apiKey: projectProvider.apiKey }),
|
|
183
|
+
...(projectProvider.api === undefined ? {} : { api: projectProvider.api }),
|
|
184
|
+
...(projectProvider.models === undefined ? {} : { models: projectProvider.models }),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const defaultProvider = projectSettings?.defaultProvider ?? globalSettings?.defaultProvider;
|
|
188
|
+
const defaultModel = projectSettings?.defaultModel ??
|
|
189
|
+
(projectSettings?.defaultProvider === undefined ? globalSettings?.defaultModel : undefined);
|
|
190
|
+
return {
|
|
191
|
+
providers,
|
|
192
|
+
...(defaultProvider === undefined ? {} : { defaultProvider }),
|
|
193
|
+
...(defaultModel === undefined ? {} : { defaultModel }),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
export async function saveGlobalProviderApiKey(agentDir, providerId, api, apiKey, modelId) {
|
|
197
|
+
const settingsFilePath = join(agentDir, SETTINGS_FILE_NAME);
|
|
198
|
+
const trimmedApiKey = apiKey.trim();
|
|
199
|
+
if (!trimmedApiKey)
|
|
200
|
+
throw new Error(`${settingsFilePath}: apiKey must be a non-empty string`);
|
|
201
|
+
const existingSettings = await readSettingsFile(settingsFilePath, settingsFilePath);
|
|
202
|
+
const settings = mergeSettings(existingSettings, {
|
|
203
|
+
providers: { [providerId]: { api, apiKey: trimmedApiKey } },
|
|
204
|
+
defaultProvider: providerId,
|
|
205
|
+
...(modelId === undefined ? {} : { defaultModel: modelId }),
|
|
206
|
+
});
|
|
207
|
+
await mkdir(agentDir, { recursive: true, mode: 0o700 });
|
|
208
|
+
await writeFile(settingsFilePath, `${JSON.stringify(settings, null, "\t")}\n`, { encoding: "utf8", mode: 0o600 });
|
|
209
|
+
}
|
|
210
|
+
/** Removes only the persisted credential for one provider; environment variables remain untouched. */
|
|
211
|
+
export async function removeGlobalProviderApiKey(agentDir, providerId) {
|
|
212
|
+
const settingsFilePath = join(agentDir, SETTINGS_FILE_NAME);
|
|
213
|
+
const existingSettings = await readSettingsFile(settingsFilePath, settingsFilePath);
|
|
214
|
+
const provider = existingSettings?.providers[providerId];
|
|
215
|
+
if (!provider || provider.apiKey === undefined)
|
|
216
|
+
return false;
|
|
217
|
+
const { apiKey: _apiKey, ...providerWithoutApiKey } = provider;
|
|
218
|
+
const settings = {
|
|
219
|
+
...existingSettings,
|
|
220
|
+
providers: {
|
|
221
|
+
...existingSettings.providers,
|
|
222
|
+
[providerId]: providerWithoutApiKey,
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
await writeFile(settingsFilePath, `${JSON.stringify(settings, null, "\t")}\n`, { encoding: "utf8", mode: 0o600 });
|
|
226
|
+
return true;
|
|
109
227
|
}
|
|
110
228
|
function resolveConfigValue(value, env) {
|
|
111
229
|
if (value === undefined)
|
|
@@ -130,11 +248,13 @@ function createFauxRuntime() {
|
|
|
130
248
|
}
|
|
131
249
|
function selectProviderModel(provider, providerId, env) {
|
|
132
250
|
const modelId = env.DI_CODE_MODEL?.trim() ||
|
|
133
|
-
(providerId === "
|
|
134
|
-
? provider.models.find((candidate) => candidate.id === "
|
|
135
|
-
: providerId === "
|
|
136
|
-
? provider.models.find((candidate) => candidate.id === "
|
|
137
|
-
:
|
|
251
|
+
(providerId === "anthropic"
|
|
252
|
+
? provider.models.find((candidate) => candidate.id === "claude-sonnet-4-5")?.id
|
|
253
|
+
: providerId === "openai"
|
|
254
|
+
? provider.models.find((candidate) => candidate.id === "gpt-4o")?.id
|
|
255
|
+
: providerId === "zhipu"
|
|
256
|
+
? provider.models.find((candidate) => candidate.id === "glm-5.3")?.id
|
|
257
|
+
: undefined) ||
|
|
138
258
|
provider.models[0]?.id;
|
|
139
259
|
if (!modelId)
|
|
140
260
|
throw new Error("DI_CODE_MODEL is required when the selected provider has no models");
|
|
@@ -146,6 +266,10 @@ function selectProviderModel(provider, providerId, env) {
|
|
|
146
266
|
return model;
|
|
147
267
|
}
|
|
148
268
|
function createBuiltInRuntime(env, providerId) {
|
|
269
|
+
if (providerId === "anthropic") {
|
|
270
|
+
const provider = createAnthropicProvider({ env });
|
|
271
|
+
return { provider, model: selectProviderModel(provider, providerId, env) };
|
|
272
|
+
}
|
|
149
273
|
if (providerId === "openai") {
|
|
150
274
|
const provider = createOpenAIProvider({ env });
|
|
151
275
|
return { provider, model: selectProviderModel(provider, providerId, env) };
|
|
@@ -162,45 +286,81 @@ function createBuiltInRuntime(env, providerId) {
|
|
|
162
286
|
}
|
|
163
287
|
function createConfiguredRuntime(env, configuration) {
|
|
164
288
|
if (configuration.api !== "openai-responses" &&
|
|
165
|
-
configuration.api !== "
|
|
166
|
-
configuration.api !== "
|
|
167
|
-
throw new Error(`Unsupported API "${configuration.api ?? "missing"}" for provider "${configuration.id}". Expected openai-responses
|
|
289
|
+
configuration.api !== "openai-chat-completions" &&
|
|
290
|
+
configuration.api !== "anthropic-messages") {
|
|
291
|
+
throw new Error(`Unsupported API "${configuration.api ?? "missing"}" for provider "${configuration.id}". Expected openai-responses, openai-chat-completions, or anthropic-messages.`);
|
|
168
292
|
}
|
|
169
293
|
if (configuration.id !== "openai" &&
|
|
170
294
|
configuration.id !== "deepseek" &&
|
|
171
295
|
configuration.id !== "zhipu" &&
|
|
296
|
+
configuration.id !== "anthropic" &&
|
|
172
297
|
!configuration.models) {
|
|
173
298
|
throw new Error(`${SETTINGS_PATH}: providers.${configuration.id}.models is required for a custom provider`);
|
|
174
299
|
}
|
|
175
|
-
const provider = configuration.
|
|
176
|
-
?
|
|
177
|
-
env
|
|
300
|
+
const provider = configuration.api === "openai-chat-completions"
|
|
301
|
+
? createOpenAIChatCompletionsProvider({
|
|
302
|
+
env: configuration.id === "zhipu" || configuration.id === "deepseek"
|
|
303
|
+
? env
|
|
304
|
+
: Object.fromEntries(Object.entries(env).filter(([name]) => name !== "OPENAI_API_KEY" && name !== "OPENAI_BASE_URL")),
|
|
178
305
|
models: configuration.models,
|
|
179
306
|
apiKey: resolveConfigValue(configuration.apiKey, env),
|
|
180
307
|
baseUrl: configuration.models ? undefined : configuration.baseUrl,
|
|
308
|
+
providerId: configuration.id,
|
|
309
|
+
name: configuration.name ?? configuration.id,
|
|
310
|
+
...(configuration.id === "zhipu"
|
|
311
|
+
? {
|
|
312
|
+
apiKeyEnvironmentVariable: "ZAI_API_KEY",
|
|
313
|
+
baseUrlEnvironmentVariable: "ZHIPU_BASE_URL",
|
|
314
|
+
defaultBaseUrl: "https://open.bigmodel.cn/api/coding/paas/v4",
|
|
315
|
+
}
|
|
316
|
+
: configuration.id === "deepseek"
|
|
317
|
+
? {
|
|
318
|
+
apiKeyEnvironmentVariable: "DEEPSEEK_API_KEY",
|
|
319
|
+
baseUrlEnvironmentVariable: "DEEPSEEK_BASE_URL",
|
|
320
|
+
defaultBaseUrl: "https://api.deepseek.com",
|
|
321
|
+
}
|
|
322
|
+
: {}),
|
|
181
323
|
})
|
|
182
|
-
: configuration.
|
|
183
|
-
?
|
|
184
|
-
env
|
|
185
|
-
models: configuration.models,
|
|
186
|
-
apiKey: resolveConfigValue(configuration.apiKey, env),
|
|
187
|
-
baseUrl: configuration.models ? undefined : configuration.baseUrl,
|
|
188
|
-
})
|
|
189
|
-
: createOpenAIProvider({
|
|
190
|
-
env: configuration.id === "openai"
|
|
324
|
+
: configuration.api === "anthropic-messages"
|
|
325
|
+
? createAnthropicProvider({
|
|
326
|
+
env: configuration.id === "anthropic"
|
|
191
327
|
? env
|
|
192
|
-
: Object.fromEntries(Object.entries(env).filter(([name]) => name !== "
|
|
328
|
+
: Object.fromEntries(Object.entries(env).filter(([name]) => name !== "ANTHROPIC_API_KEY" && name !== "ANTHROPIC_BASE_URL")),
|
|
193
329
|
models: configuration.models,
|
|
194
330
|
apiKey: resolveConfigValue(configuration.apiKey, env),
|
|
195
331
|
baseUrl: configuration.models ? undefined : configuration.baseUrl,
|
|
196
332
|
providerId: configuration.id,
|
|
197
333
|
name: configuration.name,
|
|
198
|
-
})
|
|
334
|
+
})
|
|
335
|
+
: configuration.id === "deepseek"
|
|
336
|
+
? createDeepSeekProvider({
|
|
337
|
+
env,
|
|
338
|
+
models: configuration.models,
|
|
339
|
+
apiKey: resolveConfigValue(configuration.apiKey, env),
|
|
340
|
+
baseUrl: configuration.models ? undefined : configuration.baseUrl,
|
|
341
|
+
})
|
|
342
|
+
: configuration.id === "zhipu"
|
|
343
|
+
? createZhipuProvider({
|
|
344
|
+
env,
|
|
345
|
+
models: configuration.models,
|
|
346
|
+
apiKey: resolveConfigValue(configuration.apiKey, env),
|
|
347
|
+
baseUrl: configuration.models ? undefined : configuration.baseUrl,
|
|
348
|
+
})
|
|
349
|
+
: createOpenAIProvider({
|
|
350
|
+
env: configuration.id === "openai"
|
|
351
|
+
? env
|
|
352
|
+
: Object.fromEntries(Object.entries(env).filter(([name]) => name !== "OPENAI_API_KEY" && name !== "OPENAI_BASE_URL")),
|
|
353
|
+
models: configuration.models,
|
|
354
|
+
apiKey: resolveConfigValue(configuration.apiKey, env),
|
|
355
|
+
baseUrl: configuration.models ? undefined : configuration.baseUrl,
|
|
356
|
+
providerId: configuration.id,
|
|
357
|
+
name: configuration.name,
|
|
358
|
+
});
|
|
199
359
|
const model = selectProviderModel(provider, configuration.id, env);
|
|
200
360
|
return { provider, model };
|
|
201
361
|
}
|
|
202
|
-
export function resolveStartupRuntime(env, providers) {
|
|
203
|
-
const selectedProviderId = env.DI_CODE_PROVIDER?.trim() || (providers.length === 1 ? providers[0]?.id : undefined);
|
|
362
|
+
export function resolveStartupRuntime(env, providers, defaults = {}) {
|
|
363
|
+
const selectedProviderId = env.DI_CODE_PROVIDER?.trim() || defaults.providerId || (providers.length === 1 ? providers[0]?.id : undefined);
|
|
204
364
|
if (selectedProviderId === "faux")
|
|
205
365
|
return createFauxRuntime();
|
|
206
366
|
if (!selectedProviderId) {
|
|
@@ -209,39 +369,35 @@ export function resolveStartupRuntime(env, providers) {
|
|
|
209
369
|
}
|
|
210
370
|
throw new Error("DI_CODE_PROVIDER is required when more than one provider is configured.");
|
|
211
371
|
}
|
|
372
|
+
const runtimeEnvironment = env.DI_CODE_MODEL?.trim() || defaults.providerId !== selectedProviderId || !defaults.modelId
|
|
373
|
+
? env
|
|
374
|
+
: { ...env, DI_CODE_MODEL: defaults.modelId };
|
|
212
375
|
const selectedProvider = providers.find((provider) => provider.id === selectedProviderId);
|
|
213
376
|
if (selectedProvider)
|
|
214
|
-
return createConfiguredRuntime(
|
|
215
|
-
const builtInRuntime = createBuiltInRuntime(
|
|
377
|
+
return createConfiguredRuntime(runtimeEnvironment, selectedProvider);
|
|
378
|
+
const builtInRuntime = createBuiltInRuntime(runtimeEnvironment, selectedProviderId);
|
|
216
379
|
if (builtInRuntime)
|
|
217
380
|
return builtInRuntime;
|
|
218
381
|
throw new Error(`Unknown configured provider "${selectedProviderId}". Available providers: ${providers.map((provider) => provider.id).join(", ")}.`);
|
|
219
382
|
}
|
|
220
|
-
export async function loadStartupConfiguration(cwd, environment = process.env) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
settings = parseSettings(JSON.parse(source));
|
|
227
|
-
}
|
|
228
|
-
catch (cause) {
|
|
229
|
-
if (cause instanceof Error && "code" in cause && cause.code === "ENOENT") {
|
|
230
|
-
return { environment, providers: [] };
|
|
231
|
-
}
|
|
232
|
-
if (cause instanceof SyntaxError)
|
|
233
|
-
throw new Error(`${SETTINGS_PATH}: invalid JSON`, { cause });
|
|
234
|
-
throw cause;
|
|
235
|
-
}
|
|
383
|
+
export async function loadStartupConfiguration(cwd, environment = process.env, agentDir = join(homedir(), ".di-code")) {
|
|
384
|
+
const [globalSettings, projectSettings] = await Promise.all([
|
|
385
|
+
readSettingsFile(join(agentDir, SETTINGS_FILE_NAME), join(agentDir, SETTINGS_FILE_NAME)),
|
|
386
|
+
readSettingsFile(join(cwd, SETTINGS_PATH), SETTINGS_PATH),
|
|
387
|
+
]);
|
|
388
|
+
const settings = mergeSettings(globalSettings, projectSettings);
|
|
236
389
|
const providers = Object.entries(settings.providers).map(([id, provider]) => ({
|
|
237
390
|
id: requiredString(id, `providers.${id}`),
|
|
238
391
|
name: provider.name,
|
|
239
392
|
api: provider.api,
|
|
240
393
|
apiKey: provider.apiKey,
|
|
241
394
|
baseUrl: provider.baseUrl,
|
|
242
|
-
models: parseModels(provider.models, `providers.${id}.models`, id, provider.api, provider.baseUrl),
|
|
395
|
+
models: parseModels(provider.models, `providers.${id}.models`, id, provider.api, provider.baseUrl, SETTINGS_PATH),
|
|
243
396
|
}));
|
|
244
|
-
|
|
397
|
+
const defaults = settings.defaultProvider === undefined && settings.defaultModel === undefined
|
|
398
|
+
? undefined
|
|
399
|
+
: { providerId: settings.defaultProvider, modelId: settings.defaultModel };
|
|
400
|
+
return { environment, providers, ...(defaults === undefined ? {} : { defaults }) };
|
|
245
401
|
}
|
|
246
402
|
export async function loadStartupEnvironment(cwd, environment = process.env) {
|
|
247
403
|
return (await loadStartupConfiguration(cwd, environment)).environment;
|
package/dist/startup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startup.js","sourceRoot":"","sources":["../src/startup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACN,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,GAInB,MAAM,aAAa,CAAC;AAqBrB,MAAM,cAAc,GAA4B;IAC/C,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC,EAAE;CACxE,CAAC;AAEF,MAAM,aAAa,GAAG,IAAI,CAAC,UA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,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7E,EAAE,EAAE,cAAc,CAAC,EAAE,EAAE,aAAa,EAAE,EAAE,CAAC;QACzC,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,GAAG,EAAE,QAAQ,CAAC,GAAG;QACjB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,OAAO,CAAC;KAClG,CAAC,CAAC,CAAC;IACJ,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;AACnC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC3C,GAAW,EACX,cAA2B,OAAO,CAAC,GAAG;IAEtC,OAAO,CAAC,MAAM,wBAAwB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC;AACvE,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport {\n\tcreateDeepSeekProvider,\n\tcreateFauxProvider,\n\tcreateOpenAIProvider,\n\tcreateZhipuProvider,\n\ttype FauxResponse,\n\ttype Model,\n\ttype Provider,\n} from \"@di-code/ai\";\n\nexport interface StartupRuntime {\n\treadonly provider: Provider;\n\treadonly model: Model;\n}\n\nexport interface StartupProviderConfiguration {\n\treadonly id: string;\n\treadonly name?: string;\n\treadonly api?: string;\n\treadonly apiKey?: string;\n\treadonly baseUrl?: string;\n\treadonly models?: readonly Model[];\n}\n\nexport interface StartupConfiguration {\n\treadonly environment: Environment;\n\treadonly providers: readonly StartupProviderConfiguration[];\n}\n\nconst FAUX_RESPONSES: readonly FauxResponse[] = [\n\t{ type: \"success\", content: [{ type: \"text\", text: \"Faux response.\" }] },\n];\n\nconst SETTINGS_PATH = join(\".di-code\", \"settings.json\");\n\ntype Environment = Readonly<Record<string, string | undefined>>;\n\ninterface SettingsFile {\n\treadonly providers: Record<\n\t\tstring,\n\t\t{\n\t\t\treadonly name?: string;\n\t\t\treadonly baseUrl?: string;\n\t\t\treadonly apiKey?: string;\n\t\t\treadonly api?: string;\n\t\t\treadonly models?: unknown;\n\t\t}\n\t>;\n}\n\nexport function resolveStartupArgs(args: readonly string[]): readonly string[] {\n\treturn args.length === 0 ? [\"--interactive\"] : args;\n}\n\nfunction optionalString(value: unknown, path: string): string | undefined {\n\tif (value === undefined) return undefined;\n\tif (typeof value !== \"string\") throw new Error(`${SETTINGS_PATH}: ${path} must be a string`);\n\treturn value;\n}\n\nfunction requiredString(value: unknown, path: string): string {\n\tconst result = optionalString(value, path);\n\tif (!result?.trim()) throw new Error(`${SETTINGS_PATH}: ${path} must be a non-empty string`);\n\treturn result.trim();\n}\n\nfunction positiveInteger(value: unknown, path: string, fallback: number): number {\n\tconst result = value ?? fallback;\n\tif (!Number.isInteger(result) || (result as number) <= 0) {\n\t\tthrow new Error(`${SETTINGS_PATH}: ${path} must be a positive integer`);\n\t}\n\treturn result as number;\n}\n\nfunction nonNegativeNumber(value: unknown, path: string, fallback: number): number {\n\tconst result = value ?? fallback;\n\tif (typeof result !== \"number\" || !Number.isFinite(result) || result < 0) {\n\t\tthrow new Error(`${SETTINGS_PATH}: ${path} must be a non-negative finite number`);\n\t}\n\treturn result;\n}\n\nfunction parseModels(\n\tvalue: unknown,\n\tpath: string,\n\tproviderId: string,\n\tproviderApi: string | undefined,\n\tproviderBaseUrl: string | undefined,\n): readonly Model[] | undefined {\n\tif (value === undefined) return undefined;\n\tif (!Array.isArray(value)) throw new Error(`${SETTINGS_PATH}: ${path} must be an array`);\n\n\treturn value.map((entry, index) => {\n\t\tconst modelPath = `${path}[${index}]`;\n\t\tif (typeof entry !== \"object\" || entry === null || Array.isArray(entry)) {\n\t\t\tthrow new Error(`${SETTINGS_PATH}: ${modelPath} must be an object`);\n\t\t}\n\t\tconst model = entry as Record<string, unknown>;\n\t\tconst input = model.input ?? [\"text\"];\n\t\tif (!Array.isArray(input) || input.length === 0 || input.some((item) => item !== \"text\" && item !== \"image\")) {\n\t\t\tthrow new Error(`${SETTINGS_PATH}: ${modelPath}.input must contain text and/or image`);\n\t\t}\n\t\tconst cost = model.cost ?? {};\n\t\tif (typeof cost !== \"object\" || cost === null || Array.isArray(cost)) {\n\t\t\tthrow new Error(`${SETTINGS_PATH}: ${modelPath}.cost must be an object`);\n\t\t}\n\t\tconst prices = cost as Record<string, unknown>;\n\t\tif (model.reasoning !== undefined && typeof model.reasoning !== \"boolean\") {\n\t\t\tthrow new Error(`${SETTINGS_PATH}: ${modelPath}.reasoning must be a boolean`);\n\t\t}\n\t\tconst api = optionalString(model.api, `${modelPath}.api`) ?? providerApi;\n\t\tif (!api) throw new Error(`${SETTINGS_PATH}: ${modelPath}.api is required`);\n\t\tconst baseUrl = optionalString(model.baseUrl, `${modelPath}.baseUrl`) ?? providerBaseUrl;\n\t\tconst id = requiredString(model.id, `${modelPath}.id`);\n\t\treturn {\n\t\t\tid,\n\t\t\tname: requiredString(model.name ?? id, `${modelPath}.name`),\n\t\t\tprovider: providerId,\n\t\t\tapi,\n\t\t\t...(baseUrl === undefined ? {} : { baseUrl }),\n\t\t\tinput: [...input],\n\t\t\treasoning: model.reasoning ?? false,\n\t\t\tcontextWindow: positiveInteger(model.contextWindow, `${modelPath}.contextWindow`, 128_000),\n\t\t\tmaxOutputTokens: positiveInteger(model.maxTokens ?? model.maxOutputTokens, `${modelPath}.maxTokens`, 16_384),\n\t\t\tcost: {\n\t\t\t\tinput: nonNegativeNumber(prices.input, `${modelPath}.cost.input`, 0) / 1_000_000,\n\t\t\t\toutput: nonNegativeNumber(prices.output, `${modelPath}.cost.output`, 0) / 1_000_000,\n\t\t\t\tcacheRead: nonNegativeNumber(prices.cacheRead, `${modelPath}.cost.cacheRead`, 0) / 1_000_000,\n\t\t\t\tcacheWrite: nonNegativeNumber(prices.cacheWrite, `${modelPath}.cost.cacheWrite`, 0) / 1_000_000,\n\t\t\t},\n\t\t};\n\t});\n}\n\nfunction parseSettings(value: unknown): SettingsFile {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\tthrow new Error(`${SETTINGS_PATH}: root value must be an object`);\n\t}\n\tconst record = value as Record<string, unknown>;\n\tconst providersValue = record.providers;\n\tif (typeof providersValue !== \"object\" || providersValue === null || Array.isArray(providersValue)) {\n\t\tthrow new Error(`${SETTINGS_PATH}: providers must be an object`);\n\t}\n\tconst providers: Record<string, SettingsFile[\"providers\"][string]> = {};\n\tfor (const [id, entry] of Object.entries(providersValue as Record<string, unknown>)) {\n\t\tif (typeof entry !== \"object\" || entry === null || Array.isArray(entry)) {\n\t\t\tthrow new Error(`${SETTINGS_PATH}: providers.${id} must be an object`);\n\t\t}\n\t\tconst provider = entry as Record<string, unknown>;\n\t\tproviders[id] = {\n\t\t\tname: optionalString(provider.name, `providers.${id}.name`),\n\t\t\tbaseUrl: optionalString(provider.baseUrl, `providers.${id}.baseUrl`),\n\t\t\tapiKey: optionalString(provider.apiKey, `providers.${id}.apiKey`),\n\t\t\tapi: optionalString(provider.api, `providers.${id}.api`),\n\t\t\tmodels: provider.models,\n\t\t};\n\t}\n\treturn { providers };\n}\n\nfunction resolveConfigValue(value: string | undefined, env: Environment): string | undefined {\n\tif (value === undefined) return undefined;\n\tconst trimmed = value.trim();\n\tconst match = /^\\$\\{([A-Za-z_][A-Za-z0-9_]*)\\}$|^\\$([A-Za-z_][A-Za-z0-9_]*)$/.exec(trimmed);\n\tif (match) {\n\t\tconst name = match[1] ?? match[2];\n\t\tconst resolved = env[name];\n\t\tif (!resolved?.trim()) throw new Error(`Configured apiKey environment variable \"${name}\" is not set.`);\n\t\treturn resolved;\n\t}\n\tif (trimmed.startsWith(\"!\")) {\n\t\tthrow new Error(\"Command-based apiKey values are not supported by di-code; use $ENV_VAR instead.\");\n\t}\n\treturn value;\n}\n\nfunction createFauxRuntime(): StartupRuntime {\n\tconst faux = createFauxProvider({ responses: FAUX_RESPONSES });\n\treturn { provider: faux.provider, model: faux.model };\n}\n\nfunction selectProviderModel(provider: Provider, providerId: string, env: Environment): Model {\n\tconst modelId =\n\t\tenv.DI_CODE_MODEL?.trim() ||\n\t\t(providerId === \"openai\"\n\t\t\t? provider.models.find((candidate) => candidate.id === \"gpt-4o\")?.id\n\t\t\t: providerId === \"zhipu\"\n\t\t\t\t? provider.models.find((candidate) => candidate.id === \"glm-5.3\")?.id\n\t\t\t\t: undefined) ||\n\t\tprovider.models[0]?.id;\n\tif (!modelId) throw new Error(\"DI_CODE_MODEL is required when the selected provider has no models\");\n\tconst model = provider.models.find((candidate) => candidate.id === modelId);\n\tif (!model) {\n\t\tconst availableModels = provider.models.map((candidate) => candidate.id).join(\", \");\n\t\tthrow new Error(`Unknown model \"${modelId}\" for provider \"${providerId}\". Available models: ${availableModels}.`);\n\t}\n\treturn model;\n}\n\nfunction createBuiltInRuntime(env: Environment, providerId: string): StartupRuntime | undefined {\n\tif (providerId === \"openai\") {\n\t\tconst provider = createOpenAIProvider({ env });\n\t\treturn { provider, model: selectProviderModel(provider, providerId, env) };\n\t}\n\tif (providerId === \"deepseek\") {\n\t\tconst provider = createDeepSeekProvider({ env });\n\t\treturn { provider, model: selectProviderModel(provider, providerId, env) };\n\t}\n\tif (providerId === \"zhipu\") {\n\t\tconst provider = createZhipuProvider({ env });\n\t\treturn { provider, model: selectProviderModel(provider, providerId, env) };\n\t}\n\treturn undefined;\n}\n\nfunction createConfiguredRuntime(env: Environment, configuration: StartupProviderConfiguration): StartupRuntime {\n\tif (\n\t\tconfiguration.api !== \"openai-responses\" &&\n\t\tconfiguration.api !== \"deepseek-responses\" &&\n\t\tconfiguration.api !== \"zhipu-chat-completions\"\n\t) {\n\t\tthrow new Error(\n\t\t\t`Unsupported API \"${configuration.api ?? \"missing\"}\" for provider \"${configuration.id}\". Expected openai-responses or deepseek-responses. zhipu-chat-completions is also supported.`,\n\t\t);\n\t}\n\tif (\n\t\tconfiguration.id !== \"openai\" &&\n\t\tconfiguration.id !== \"deepseek\" &&\n\t\tconfiguration.id !== \"zhipu\" &&\n\t\t!configuration.models\n\t) {\n\t\tthrow new Error(`${SETTINGS_PATH}: providers.${configuration.id}.models is required for a custom provider`);\n\t}\n\tconst provider =\n\t\tconfiguration.id === \"deepseek\"\n\t\t\t? createDeepSeekProvider({\n\t\t\t\t\tenv,\n\t\t\t\t\tmodels: configuration.models,\n\t\t\t\t\tapiKey: resolveConfigValue(configuration.apiKey, env),\n\t\t\t\t\tbaseUrl: configuration.models ? undefined : configuration.baseUrl,\n\t\t\t\t})\n\t\t\t: configuration.id === \"zhipu\"\n\t\t\t\t? createZhipuProvider({\n\t\t\t\t\t\tenv,\n\t\t\t\t\t\tmodels: configuration.models,\n\t\t\t\t\t\tapiKey: resolveConfigValue(configuration.apiKey, env),\n\t\t\t\t\t\tbaseUrl: configuration.models ? undefined : configuration.baseUrl,\n\t\t\t\t\t})\n\t\t\t\t: createOpenAIProvider({\n\t\t\t\t\t\tenv:\n\t\t\t\t\t\t\tconfiguration.id === \"openai\"\n\t\t\t\t\t\t\t\t? env\n\t\t\t\t\t\t\t\t: Object.fromEntries(\n\t\t\t\t\t\t\t\t\t\tObject.entries(env).filter(([name]) => name !== \"OPENAI_API_KEY\" && name !== \"OPENAI_BASE_URL\"),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\tmodels: configuration.models,\n\t\t\t\t\t\tapiKey: resolveConfigValue(configuration.apiKey, env),\n\t\t\t\t\t\tbaseUrl: configuration.models ? undefined : configuration.baseUrl,\n\t\t\t\t\t\tproviderId: configuration.id,\n\t\t\t\t\t\tname: configuration.name,\n\t\t\t\t\t});\n\tconst model = selectProviderModel(provider, configuration.id, env);\n\treturn { provider, model };\n}\n\nexport function resolveStartupRuntime(\n\tenv: Environment,\n\tproviders: readonly StartupProviderConfiguration[],\n): StartupRuntime {\n\tconst selectedProviderId = env.DI_CODE_PROVIDER?.trim() || (providers.length === 1 ? providers[0]?.id : undefined);\n\tif (selectedProviderId === \"faux\") return createFauxRuntime();\n\tif (!selectedProviderId) {\n\t\tif (providers.length === 0) {\n\t\t\tthrow new Error(\"Provider is not configured. Set DI_CODE_PROVIDER or start interactive mode in a TTY.\");\n\t\t}\n\t\tthrow new Error(\"DI_CODE_PROVIDER is required when more than one provider is configured.\");\n\t}\n\tconst selectedProvider = providers.find((provider) => provider.id === selectedProviderId);\n\tif (selectedProvider) return createConfiguredRuntime(env, selectedProvider);\n\tconst builtInRuntime = createBuiltInRuntime(env, selectedProviderId);\n\tif (builtInRuntime) return builtInRuntime;\n\tthrow new Error(\n\t\t`Unknown configured provider \"${selectedProviderId}\". Available providers: ${providers.map((provider) => provider.id).join(\", \")}.`,\n\t);\n}\n\nexport async function loadStartupConfiguration(\n\tcwd: string,\n\tenvironment: Environment = process.env,\n): Promise<StartupConfiguration> {\n\tlet settings: SettingsFile;\n\ttry {\n\t\tconst source = await readFile(join(cwd, SETTINGS_PATH), \"utf8\");\n\t\tif (source.trim().length === 0) return { environment, providers: [] };\n\t\tsettings = parseSettings(JSON.parse(source));\n\t} catch (cause) {\n\t\tif (cause instanceof Error && \"code\" in cause && cause.code === \"ENOENT\") {\n\t\t\treturn { environment, providers: [] };\n\t\t}\n\t\tif (cause instanceof SyntaxError) throw new Error(`${SETTINGS_PATH}: invalid JSON`, { cause });\n\t\tthrow cause;\n\t}\n\n\tconst providers = Object.entries(settings.providers).map(([id, provider]) => ({\n\t\tid: requiredString(id, `providers.${id}`),\n\t\tname: provider.name,\n\t\tapi: provider.api,\n\t\tapiKey: provider.apiKey,\n\t\tbaseUrl: provider.baseUrl,\n\t\tmodels: parseModels(provider.models, `providers.${id}.models`, id, provider.api, provider.baseUrl),\n\t}));\n\treturn { environment, providers };\n}\n\nexport async function loadStartupEnvironment(\n\tcwd: string,\n\tenvironment: Environment = process.env,\n): Promise<Environment> {\n\treturn (await loadStartupConfiguration(cw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QACnB,GAAG,EAAE,QAAQ,CAAC,GAAG;QACjB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;KACjH,CAAC,CAAC,CAAC;IACJ,MAAM,QAAQ,GACb,QAAQ,CAAC,eAAe,KAAK,SAAS,IAAI,QAAQ,CAAC,YAAY,KAAK,SAAS;QAC5E,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,EAAE,UAAU,EAAE,QAAQ,CAAC,eAAe,EAAE,OAAO,EAAE,QAAQ,CAAC,YAAY,EAAE,CAAC;IAC7E,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;AACpF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC3C,GAAW,EACX,cAA2B,OAAO,CAAC,GAAG;IAEtC,OAAO,CAAC,MAAM,wBAAwB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC;AACvE,CAAC","sourcesContent":["import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport {\n\tcreateAnthropicProvider,\n\tcreateDeepSeekProvider,\n\tcreateFauxProvider,\n\tcreateOpenAIChatCompletionsProvider,\n\tcreateOpenAIProvider,\n\tcreateZhipuProvider,\n\ttype FauxResponse,\n\ttype Model,\n\ttype ModelApi,\n\ttype Provider,\n} from \"@di-code/ai\";\n\nexport interface StartupRuntime {\n\treadonly provider: Provider;\n\treadonly model: Model;\n}\n\nexport interface StartupProviderConfiguration {\n\treadonly id: string;\n\treadonly name?: string;\n\treadonly api?: string;\n\treadonly apiKey?: string;\n\treadonly baseUrl?: string;\n\treadonly models?: readonly Model[];\n}\n\nexport interface StartupConfiguration {\n\treadonly environment: Environment;\n\treadonly providers: readonly StartupProviderConfiguration[];\n\treadonly defaults?: StartupDefaults;\n}\n\nexport interface StartupDefaults {\n\treadonly providerId?: string;\n\treadonly modelId?: string;\n}\n\nconst FAUX_RESPONSES: readonly FauxResponse[] = [\n\t{\n\t\ttype: \"success\",\n\t\tcontent: [\n\t\t\t{\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: \"你好,我是di-code,一个面向终端的 TypeScript AI Coding Agent,支持多 Provider 流式对话、工具调用、JSONL 会话持久化、交互式 TUI、插件扩展与 JSONL RPC 集成。\",\n\t\t\t},\n\t\t],\n\t},\n\t{ type: \"success\", content: [{ type: \"text\", text: \"当前回复为faux数据\" }] },\n];\n\nconst SETTINGS_FILE_NAME = \"settings.json\";\nconst SETTINGS_PATH = join(\".di-code\", SETTINGS_FILE_NAME);\n\ntype Environment = Readonly<Record<string, string | undefined>>;\n\ninterface SettingsFile {\n\treadonly defaultProvider?: string;\n\treadonly defaultModel?: string;\n\treadonly providers: Record<\n\t\tstring,\n\t\t{\n\t\t\treadonly name?: string;\n\t\t\treadonly baseUrl?: string;\n\t\t\treadonly apiKey?: string;\n\t\t\treadonly api?: string;\n\t\t\treadonly models?: unknown;\n\t\t}\n\t>;\n}\n\nexport function resolveStartupArgs(args: readonly string[]): readonly string[] {\n\treturn args.length === 0 ? [\"--interactive\"] : args;\n}\n\nfunction optionalString(value: unknown, path: string, settingsPath: string): string | undefined {\n\tif (value === undefined) return undefined;\n\tif (typeof value !== \"string\") throw new Error(`${settingsPath}: ${path} must be a string`);\n\treturn value;\n}\n\nfunction requiredString(value: unknown, path: string, settingsPath = SETTINGS_PATH): string {\n\tconst result = optionalString(value, path, settingsPath);\n\tif (!result?.trim()) throw new Error(`${settingsPath}: ${path} must be a non-empty string`);\n\treturn result.trim();\n}\n\nfunction positiveInteger(value: unknown, path: string, fallback: number, settingsPath: string): number {\n\tconst result = value ?? fallback;\n\tif (!Number.isInteger(result) || (result as number) <= 0) {\n\t\tthrow new Error(`${settingsPath}: ${path} must be a positive integer`);\n\t}\n\treturn result as number;\n}\n\nfunction nonNegativeNumber(value: unknown, path: string, fallback: number, settingsPath: string): number {\n\tconst result = value ?? fallback;\n\tif (typeof result !== \"number\" || !Number.isFinite(result) || result < 0) {\n\t\tthrow new Error(`${settingsPath}: ${path} must be a non-negative finite number`);\n\t}\n\treturn result;\n}\n\nfunction parseModels(\n\tvalue: unknown,\n\tpath: string,\n\tproviderId: string,\n\tproviderApi: string | undefined,\n\tproviderBaseUrl: string | undefined,\n\tsettingsPath: string,\n): readonly Model[] | undefined {\n\tif (value === undefined) return undefined;\n\tif (!Array.isArray(value)) throw new Error(`${settingsPath}: ${path} must be an array`);\n\n\treturn value.map((entry, index) => {\n\t\tconst modelPath = `${path}[${index}]`;\n\t\tif (typeof entry !== \"object\" || entry === null || Array.isArray(entry)) {\n\t\t\tthrow new Error(`${settingsPath}: ${modelPath} must be an object`);\n\t\t}\n\t\tconst model = entry as Record<string, unknown>;\n\t\tconst input = model.input ?? [\"text\"];\n\t\tif (!Array.isArray(input) || input.length === 0 || input.some((item) => item !== \"text\" && item !== \"image\")) {\n\t\t\tthrow new Error(`${settingsPath}: ${modelPath}.input must contain text and/or image`);\n\t\t}\n\t\tconst cost = model.cost ?? {};\n\t\tif (typeof cost !== \"object\" || cost === null || Array.isArray(cost)) {\n\t\t\tthrow new Error(`${settingsPath}: ${modelPath}.cost must be an object`);\n\t\t}\n\t\tconst prices = cost as Record<string, unknown>;\n\t\tif (model.reasoning !== undefined && typeof model.reasoning !== \"boolean\") {\n\t\t\tthrow new Error(`${settingsPath}: ${modelPath}.reasoning must be a boolean`);\n\t\t}\n\t\tconst configuredReasoningEfforts = model.reasoningEfforts;\n\t\tif (configuredReasoningEfforts !== undefined) {\n\t\t\tif (!Array.isArray(configuredReasoningEfforts) || configuredReasoningEfforts.length === 0) {\n\t\t\t\tthrow new Error(`${settingsPath}: ${modelPath}.reasoningEfforts must be a non-empty array`);\n\t\t\t}\n\t\t\tif (\n\t\t\t\tmodel.reasoning !== true ||\n\t\t\t\tconfiguredReasoningEfforts.some((effort) => effort !== \"low\" && effort !== \"medium\" && effort !== \"high\") ||\n\t\t\t\tnew Set(configuredReasoningEfforts).size !== configuredReasoningEfforts.length\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`${settingsPath}: ${modelPath}.reasoningEfforts requires reasoning=true and unique low, medium, or high values`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (model.cacheRetention !== undefined && model.cacheRetention !== \"long\") {\n\t\t\tthrow new Error(`${settingsPath}: ${modelPath}.cacheRetention must be \"long\" when provided`);\n\t\t}\n\t\tif (model.sessionAffinity !== undefined && model.sessionAffinity !== \"codex\") {\n\t\t\tthrow new Error(`${settingsPath}: ${modelPath}.sessionAffinity must be \"codex\" when provided`);\n\t\t}\n\t\tconst api = optionalString(model.api, `${modelPath}.api`, settingsPath) ?? providerApi;\n\t\tif (!api) throw new Error(`${settingsPath}: ${modelPath}.api is required`);\n\t\tif (![\"faux\", \"openai-responses\", \"openai-chat-completions\", \"anthropic-messages\"].includes(api)) {\n\t\t\tthrow new Error(`${settingsPath}: ${modelPath}.api is unsupported`);\n\t\t}\n\t\tconst typedApi = api as ModelApi;\n\t\tconst reasoningEfforts: Model[\"reasoningEfforts\"] =\n\t\t\tconfiguredReasoningEfforts === undefined && model.reasoning === true && api === \"openai-responses\"\n\t\t\t\t? [\"low\", \"medium\", \"high\"]\n\t\t\t\t: configuredReasoningEfforts === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: ([...configuredReasoningEfforts] as Model[\"reasoningEfforts\"]);\n\t\tconst baseUrl = optionalString(model.baseUrl, `${modelPath}.baseUrl`, settingsPath) ?? providerBaseUrl;\n\t\tconst id = requiredString(model.id, `${modelPath}.id`, settingsPath);\n\t\treturn {\n\t\t\tid,\n\t\t\tname: requiredString(model.name ?? id, `${modelPath}.name`, settingsPath),\n\t\t\tprovider: providerId,\n\t\t\tapi: typedApi,\n\t\t\t...(baseUrl === undefined ? {} : { baseUrl }),\n\t\t\tinput: [...input],\n\t\t\treasoning: model.reasoning ?? false,\n\t\t\t...(reasoningEfforts ? { reasoningEfforts } : {}),\n\t\t\t...(model.cacheRetention === \"long\" ? { cacheRetention: \"long\" as const } : {}),\n\t\t\t...(model.sessionAffinity === \"codex\" ? { sessionAffinity: \"codex\" as const } : {}),\n\t\t\tcontextWindow: positiveInteger(model.contextWindow, `${modelPath}.contextWindow`, 128_000, settingsPath),\n\t\t\tmaxOutputTokens: positiveInteger(\n\t\t\t\tmodel.maxTokens ?? model.maxOutputTokens,\n\t\t\t\t`${modelPath}.maxTokens`,\n\t\t\t\t16_384,\n\t\t\t\tsettingsPath,\n\t\t\t),\n\t\t\tcost: {\n\t\t\t\tinput: nonNegativeNumber(prices.input, `${modelPath}.cost.input`, 0, settingsPath) / 1_000_000,\n\t\t\t\toutput: nonNegativeNumber(prices.output, `${modelPath}.cost.output`, 0, settingsPath) / 1_000_000,\n\t\t\t\tcacheRead: nonNegativeNumber(prices.cacheRead, `${modelPath}.cost.cacheRead`, 0, settingsPath) / 1_000_000,\n\t\t\t\tcacheWrite: nonNegativeNumber(prices.cacheWrite, `${modelPath}.cost.cacheWrite`, 0, settingsPath) / 1_000_000,\n\t\t\t},\n\t\t};\n\t});\n}\n\nfunction parseSettings(value: unknown, settingsPath: string): SettingsFile {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\tthrow new Error(`${settingsPath}: root value must be an object`);\n\t}\n\tconst record = value as Record<string, unknown>;\n\tconst providersValue = record.providers;\n\tif (typeof providersValue !== \"object\" || providersValue === null || Array.isArray(providersValue)) {\n\t\tthrow new Error(`${settingsPath}: providers must be an object`);\n\t}\n\tconst providers: Record<string, SettingsFile[\"providers\"][string]> = {};\n\tfor (const [id, entry] of Object.entries(providersValue as Record<string, unknown>)) {\n\t\tif (typeof entry !== \"object\" || entry === null || Array.isArray(entry)) {\n\t\t\tthrow new Error(`${settingsPath}: providers.${id} must be an object`);\n\t\t}\n\t\tconst provider = entry as Record<string, unknown>;\n\t\tproviders[id] = {\n\t\t\tname: optionalString(provider.name, `providers.${id}.name`, settingsPath),\n\t\t\tbaseUrl: optionalString(provider.baseUrl, `providers.${id}.baseUrl`, settingsPath),\n\t\t\tapiKey: optionalString(provider.apiKey, `providers.${id}.apiKey`, settingsPath),\n\t\t\tapi: optionalString(provider.api, `providers.${id}.api`, settingsPath),\n\t\t\tmodels: provider.models,\n\t\t};\n\t}\n\tconst defaultProvider =\n\t\trecord.defaultProvider === undefined\n\t\t\t? undefined\n\t\t\t: requiredString(record.defaultProvider, \"defaultProvider\", settingsPath);\n\tconst defaultModel =\n\t\trecord.defaultModel === undefined ? undefined : requiredString(record.defaultModel, \"defaultModel\", settingsPath);\n\treturn {\n\t\tproviders,\n\t\t...(defaultProvider === undefined ? {} : { defaultProvider }),\n\t\t...(defaultModel === undefined ? {} : { defaultModel }),\n\t};\n}\n\nasync function readSettingsFile(path: string, displayPath: string): Promise<SettingsFile | undefined> {\n\ttry {\n\t\tconst source = await readFile(path, \"utf8\");\n\t\tif (source.trim().length === 0) return undefined;\n\t\treturn parseSettings(JSON.parse(source), displayPath);\n\t} catch (cause) {\n\t\tif (cause instanceof Error && \"code\" in cause && cause.code === \"ENOENT\") return undefined;\n\t\tif (cause instanceof SyntaxError) throw new Error(`${displayPath}: invalid JSON`, { cause });\n\t\tthrow cause;\n\t}\n}\n\nfunction mergeSettings(\n\tglobalSettings: SettingsFile | undefined,\n\tprojectSettings: SettingsFile | undefined,\n): SettingsFile {\n\tconst globalProviders = globalSettings?.providers ?? {};\n\tconst projectProviders = projectSettings?.providers ?? {};\n\tconst providers = { ...globalProviders };\n\tfor (const [id, projectProvider] of Object.entries(projectProviders)) {\n\t\tproviders[id] = {\n\t\t\t...globalProviders[id],\n\t\t\t...(projectProvider.name === undefined ? {} : { name: projectProvider.name }),\n\t\t\t...(projectProvider.baseUrl === undefined ? {} : { baseUrl: projectProvider.baseUrl }),\n\t\t\t...(projectProvider.apiKey === undefined ? {} : { apiKey: projectProvider.apiKey }),\n\t\t\t...(projectProvider.api === undefined ? {} : { api: projectProvider.api }),\n\t\t\t...(projectProvider.models === undefined ? {} : { models: projectProvider.models }),\n\t\t};\n\t}\n\tconst defaultProvider = projectSettings?.defaultProvider ?? globalSettings?.defaultProvider;\n\tconst defaultModel =\n\t\tprojectSettings?.defaultModel ??\n\t\t(projectSettings?.defaultProvider === undefined ? globalSettings?.defaultModel : undefined);\n\treturn {\n\t\tproviders,\n\t\t...(defaultProvider === undefined ? {} : { defaultProvider }),\n\t\t...(defaultModel === undefined ? {} : { defaultModel }),\n\t};\n}\n\nexport async function saveGlobalProviderApiKey(\n\tagentDir: string,\n\tproviderId: string,\n\tapi: Exclude<ModelApi, \"faux\">,\n\tapiKey: string,\n\tmodelId?: string,\n): Promise<void> {\n\tconst settingsFilePath = join(agentDir, SETTINGS_FILE_NAME);\n\tconst trimmedApiKey = apiKey.trim();\n\tif (!trimmedApiKey) throw new Error(`${settingsFilePath}: apiKey must be a non-empty string`);\n\tconst existingSettings = await readSettingsFile(settingsFilePath, settingsFilePath);\n\tconst settings = mergeSettings(existingSettings, {\n\t\tproviders: { [providerId]: { api, apiKey: trimmedApiKey } },\n\t\tdefaultProvider: providerId,\n\t\t...(modelId === undefined ? {} : { defaultModel: modelId }),\n\t});\n\tawait mkdir(agentDir, { recursive: true, mode: 0o700 });\n\tawait writeFile(settingsFilePath, `${JSON.stringify(settings, null, \"\\t\")}\\n`, { encoding: \"utf8\", mode: 0o600 });\n}\n\n/** Removes only the persisted credential for one provider; environment variables remain untouched. */\nexport async function removeGlobalProviderApiKey(agentDir: string, providerId: string): Promise<boolean> {\n\tconst settingsFilePath = join(agentDir, SETTINGS_FILE_NAME);\n\tconst existingSettings = await readSettingsFile(settingsFilePath, settingsFilePath);\n\tconst provider = existingSettings?.providers[providerId];\n\tif (!provider || provider.apiKey === undefined) return false;\n\n\tconst { apiKey: _apiKey, ...providerWithoutApiKey } = provider;\n\tconst settings: SettingsFile = {\n\t\t...existingSettings,\n\t\tproviders: {\n\t\t\t...existingSettings.providers,\n\t\t\t[providerId]: providerWithoutApiKey,\n\t\t},\n\t};\n\tawait writeFile(settingsFilePath, `${JSON.stringify(settings, null, \"\\t\")}\\n`, { encoding: \"utf8\", mode: 0o600 });\n\treturn true;\n}\n\nfunction resolveConfigValue(value: string | undefined, env: Environment): string | undefined {\n\tif (value === undefined) return undefined;\n\tconst trimmed = value.trim();\n\tconst match = /^\\$\\{([A-Za-z_][A-Za-z0-9_]*)\\}$|^\\$([A-Za-z_][A-Za-z0-9_]*)$/.exec(trimmed);\n\tif (match) {\n\t\tconst name = match[1] ?? match[2];\n\t\tconst resolved = env[name];\n\t\tif (!resolved?.trim()) throw new Error(`Configured apiKey environment variable \"${name}\" is not set.`);\n\t\treturn resolved;\n\t}\n\tif (trimmed.startsWith(\"!\")) {\n\t\tthrow new Error(\"Command-based apiKey values are not supported by di-code; use $ENV_VAR instead.\");\n\t}\n\treturn value;\n}\n\nfunction createFauxRuntime(): StartupRuntime {\n\tconst faux = createFauxProvider({ responses: FAUX_RESPONSES });\n\treturn { provider: faux.provider, model: faux.model };\n}\n\nfunction selectProviderModel(provider: Provider, providerId: string, env: Environment): Model {\n\tconst modelId =\n\t\tenv.DI_CODE_MODEL?.trim() ||\n\t\t(providerId === \"anthropic\"\n\t\t\t? provider.models.find((candidate) => candidate.id === \"claude-sonnet-4-5\")?.id\n\t\t\t: providerId === \"openai\"\n\t\t\t\t? provider.models.find((candidate) => candidate.id === \"gpt-4o\")?.id\n\t\t\t\t: providerId === \"zhipu\"\n\t\t\t\t\t? provider.models.find((candidate) => candidate.id === \"glm-5.3\")?.id\n\t\t\t\t\t: undefined) ||\n\t\tprovider.models[0]?.id;\n\tif (!modelId) throw new Error(\"DI_CODE_MODEL is required when the selected provider has no models\");\n\tconst model = provider.models.find((candidate) => candidate.id === modelId);\n\tif (!model) {\n\t\tconst availableModels = provider.models.map((candidate) => candidate.id).join(\", \");\n\t\tthrow new Error(`Unknown model \"${modelId}\" for provider \"${providerId}\". Available models: ${availableModels}.`);\n\t}\n\treturn model;\n}\n\nfunction createBuiltInRuntime(env: Environment, providerId: string): StartupRuntime | undefined {\n\tif (providerId === \"anthropic\") {\n\t\tconst provider = createAnthropicProvider({ env });\n\t\treturn { provider, model: selectProviderModel(provider, providerId, env) };\n\t}\n\tif (providerId === \"openai\") {\n\t\tconst provider = createOpenAIProvider({ env });\n\t\treturn { provider, model: selectProviderModel(provider, providerId, env) };\n\t}\n\tif (providerId === \"deepseek\") {\n\t\tconst provider = createDeepSeekProvider({ env });\n\t\treturn { provider, model: selectProviderModel(provider, providerId, env) };\n\t}\n\tif (providerId === \"zhipu\") {\n\t\tconst provider = createZhipuProvider({ env });\n\t\treturn { provider, model: selectProviderModel(provider, providerId, env) };\n\t}\n\treturn undefined;\n}\n\nfunction createConfiguredRuntime(env: Environment, configuration: StartupProviderConfiguration): StartupRuntime {\n\tif (\n\t\tconfiguration.api !== \"openai-responses\" &&\n\t\tconfiguration.api !== \"openai-chat-completions\" &&\n\t\tconfiguration.api !== \"anthropic-messages\"\n\t) {\n\t\tthrow new Error(\n\t\t\t`Unsupported API \"${configuration.api ?? \"missing\"}\" for provider \"${configuration.id}\". Expected openai-responses, openai-chat-completions, or anthropic-messages.`,\n\t\t);\n\t}\n\tif (\n\t\tconfiguration.id !== \"openai\" &&\n\t\tconfiguration.id !== \"deepseek\" &&\n\t\tconfiguration.id !== \"zhipu\" &&\n\t\tconfiguration.id !== \"anthropic\" &&\n\t\t!configuration.models\n\t) {\n\t\tthrow new Error(`${SETTINGS_PATH}: providers.${configuration.id}.models is required for a custom provider`);\n\t}\n\tconst provider =\n\t\tconfiguration.api === \"openai-chat-completions\"\n\t\t\t? createOpenAIChatCompletionsProvider({\n\t\t\t\t\tenv:\n\t\t\t\t\t\tconfiguration.id === \"zhipu\" || configuration.id === \"deepseek\"\n\t\t\t\t\t\t\t? env\n\t\t\t\t\t\t\t: Object.fromEntries(\n\t\t\t\t\t\t\t\t\tObject.entries(env).filter(([name]) => name !== \"OPENAI_API_KEY\" && name !== \"OPENAI_BASE_URL\"),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\tmodels: configuration.models,\n\t\t\t\t\tapiKey: resolveConfigValue(configuration.apiKey, env),\n\t\t\t\t\tbaseUrl: configuration.models ? undefined : configuration.baseUrl,\n\t\t\t\t\tproviderId: configuration.id,\n\t\t\t\t\tname: configuration.name ?? configuration.id,\n\t\t\t\t\t...(configuration.id === \"zhipu\"\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tapiKeyEnvironmentVariable: \"ZAI_API_KEY\",\n\t\t\t\t\t\t\t\tbaseUrlEnvironmentVariable: \"ZHIPU_BASE_URL\",\n\t\t\t\t\t\t\t\tdefaultBaseUrl: \"https://open.bigmodel.cn/api/coding/paas/v4\",\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: configuration.id === \"deepseek\"\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tapiKeyEnvironmentVariable: \"DEEPSEEK_API_KEY\",\n\t\t\t\t\t\t\t\t\tbaseUrlEnvironmentVariable: \"DEEPSEEK_BASE_URL\",\n\t\t\t\t\t\t\t\t\tdefaultBaseUrl: \"https://api.deepseek.com\",\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t})\n\t\t\t: configuration.api === \"anthropic-messages\"\n\t\t\t\t? createAnthropicProvider({\n\t\t\t\t\t\tenv:\n\t\t\t\t\t\t\tconfiguration.id === \"anthropic\"\n\t\t\t\t\t\t\t\t? env\n\t\t\t\t\t\t\t\t: Object.fromEntries(\n\t\t\t\t\t\t\t\t\t\tObject.entries(env).filter(\n\t\t\t\t\t\t\t\t\t\t\t([name]) => name !== \"ANTHROPIC_API_KEY\" && name !== \"ANTHROPIC_BASE_URL\",\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\tmodels: configuration.models,\n\t\t\t\t\t\tapiKey: resolveConfigValue(configuration.apiKey, env),\n\t\t\t\t\t\tbaseUrl: configuration.models ? undefined : configuration.baseUrl,\n\t\t\t\t\t\tproviderId: configuration.id,\n\t\t\t\t\t\tname: configuration.name,\n\t\t\t\t\t})\n\t\t\t\t: configuration.id === \"deepseek\"\n\t\t\t\t\t? createDeepSeekProvider({\n\t\t\t\t\t\t\tenv,\n\t\t\t\t\t\t\tmodels: configuration.models,\n\t\t\t\t\t\t\tapiKey: resolveConfigValue(configuration.apiKey, env),\n\t\t\t\t\t\t\tbaseUrl: configuration.models ? undefined : configuration.baseUrl,\n\t\t\t\t\t\t})\n\t\t\t\t\t: configuration.id === \"zhipu\"\n\t\t\t\t\t\t? createZhipuProvider({\n\t\t\t\t\t\t\t\tenv,\n\t\t\t\t\t\t\t\tmodels: configuration.models,\n\t\t\t\t\t\t\t\tapiKey: resolveConfigValue(configuration.apiKey, env),\n\t\t\t\t\t\t\t\tbaseUrl: configuration.models ? undefined : configuration.baseUrl,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t: createOpenAIProvider({\n\t\t\t\t\t\t\t\tenv:\n\t\t\t\t\t\t\t\t\tconfiguration.id === \"openai\"\n\t\t\t\t\t\t\t\t\t\t? env\n\t\t\t\t\t\t\t\t\t\t: Object.fromEntries(\n\t\t\t\t\t\t\t\t\t\t\t\tObject.entries(env).filter(([name]) => name !== \"OPENAI_API_KEY\" && name !== \"OPENAI_BASE_URL\"),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tmodels: configuration.models,\n\t\t\t\t\t\t\t\tapiKey: resolveConfigValue(configuration.apiKey, env),\n\t\t\t\t\t\t\t\tbaseUrl: configuration.models ? undefined : configuration.baseUrl,\n\t\t\t\t\t\t\t\tproviderId: configuration.id,\n\t\t\t\t\t\t\t\tname: configuration.name,\n\t\t\t\t\t\t\t});\n\tconst model = selectProviderModel(provider, configuration.id, env);\n\treturn { provider, model };\n}\n\nexport function resolveStartupRuntime(\n\tenv: Environment,\n\tproviders: readonly StartupProviderConfiguration[],\n\tdefaults: StartupDefaults = {},\n): StartupRuntime {\n\tconst selectedProviderId =\n\t\tenv.DI_CODE_PROVIDER?.trim() || defaults.providerId || (providers.length === 1 ? providers[0]?.id : undefined);\n\tif (selectedProviderId === \"faux\") return createFauxRuntime();\n\tif (!selectedProviderId) {\n\t\tif (providers.length === 0) {\n\t\t\tthrow new Error(\"Provider is not configured. Set DI_CODE_PROVIDER or start interactive mode in a TTY.\");\n\t\t}\n\t\tthrow new Error(\"DI_CODE_PROVIDER is required when more than one provider is configured.\");\n\t}\n\tconst runtimeEnvironment =\n\t\tenv.DI_CODE_MODEL?.trim() || defaults.providerId !== selectedProviderId || !defaults.modelId\n\t\t\t? env\n\t\t\t: { ...env, DI_CODE_MODEL: defaults.modelId };\n\tconst selectedProvider = providers.find((provider) => provider.id === selectedProviderId);\n\tif (selectedProvider) return createConfiguredRuntime(runtimeEnvironment, selectedProvider);\n\tconst builtInRuntime = createBuiltInRuntime(runtimeEnvironment, selectedProviderId);\n\tif (builtInRuntime) return builtInRuntime;\n\tthrow new Error(\n\t\t`Unknown configured provider \"${selectedProviderId}\". Available providers: ${providers.map((provider) => provider.id).join(\", \")}.`,\n\t);\n}\n\nexport async function loadStartupConfiguration(\n\tcwd: string,\n\tenvironment: Environment = process.env,\n\tagentDir = join(homedir(), \".di-code\"),\n): Promise<StartupConfiguration> {\n\tconst [globalSettings, projectSettings] = await Promise.all([\n\t\treadSettingsFile(join(agentDir, SETTINGS_FILE_NAME), join(agentDir, SETTINGS_FILE_NAME)),\n\t\treadSettingsFile(join(cwd, SETTINGS_PATH), SETTINGS_PATH),\n\t]);\n\tconst settings = mergeSettings(globalSettings, projectSettings);\n\n\tconst providers = Object.entries(settings.providers).map(([id, provider]) => ({\n\t\tid: requiredString(id, `providers.${id}`),\n\t\tname: provider.name,\n\t\tapi: provider.api,\n\t\tapiKey: provider.apiKey,\n\t\tbaseUrl: provider.baseUrl,\n\t\tmodels: parseModels(provider.models, `providers.${id}.models`, id, provider.api, provider.baseUrl, SETTINGS_PATH),\n\t}));\n\tconst defaults =\n\t\tsettings.defaultProvider === undefined && settings.defaultModel === undefined\n\t\t\t? undefined\n\t\t\t: { providerId: settings.defaultProvider, modelId: settings.defaultModel };\n\treturn { environment, providers, ...(defaults === undefined ? {} : { defaults }) };\n}\n\nexport async function loadStartupEnvironment(\n\tcwd: string,\n\tenvironment: Environment = process.env,\n): Promise<Environment> {\n\treturn (await loadStartupConfiguration(cwd, environment)).environment;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-highlight.d.ts","sourceRoot":"","sources":["../../src/utils/syntax-highlight.ts"],"names":[],"mappings":"AA6CA,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAOlF"}
|