@zero-gravity/zero-gravity 0.0.0-stage → 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 +29 -0
- package/LICENSE +21 -0
- package/README.md +50 -2
- package/THIRD-PARTY-NOTICES.md +100 -0
- package/dist/adv-context-SLTP32JQ.js +36 -0
- package/dist/advanced-EPLZB6DG.js +164 -0
- package/dist/agents-JYRQHH7R.js +181 -0
- package/dist/chat-AEHVCKXX.js +47 -0
- package/dist/chunk-2OH5KHWO.js +112 -0
- package/dist/chunk-2ZYSAYMJ.js +108 -0
- package/dist/chunk-4BZ4IXTO.js +161 -0
- package/dist/chunk-4ITJY25Z.js +144 -0
- package/dist/chunk-4JBLZQAQ.js +65 -0
- package/dist/chunk-6QLYRU3N.js +28 -0
- package/dist/chunk-7TACFVY2.js +57 -0
- package/dist/chunk-AY36KJTH.js +3023 -0
- package/dist/chunk-BJABQO7S.js +378 -0
- package/dist/chunk-C2GFK4JP.js +387 -0
- package/dist/chunk-CDC2K2KP.js +47 -0
- package/dist/chunk-DKCCXMSE.js +27 -0
- package/dist/chunk-FC3UOHOO.js +194 -0
- package/dist/chunk-FIASMDLX.js +216 -0
- package/dist/chunk-GMVDCQVW.js +88 -0
- package/dist/chunk-JQYZX56A.js +231 -0
- package/dist/chunk-JU5PGDOD.js +138 -0
- package/dist/chunk-JUZP5SXD.js +309 -0
- package/dist/chunk-KGA7VWQG.js +70 -0
- package/dist/chunk-L7VNR5LM.js +407 -0
- package/dist/chunk-LOSXCWHU.js +145 -0
- package/dist/chunk-NVC433AX.js +24 -0
- package/dist/chunk-QH27MDJM.js +248 -0
- package/dist/chunk-QUC5URWQ.js +708 -0
- package/dist/chunk-R2CPYTSP.js +31 -0
- package/dist/chunk-R5KQACGR.js +2833 -0
- package/dist/chunk-R6DONQKN.js +153 -0
- package/dist/chunk-RIX4S3J7.js +4747 -0
- package/dist/chunk-SZKAZ2VN.js +35 -0
- package/dist/chunk-T6DDNE3W.js +1338 -0
- package/dist/chunk-U4URD6TU.js +4605 -0
- package/dist/chunk-U5UIUB6L.js +51 -0
- package/dist/chunk-UMC77TR3.js +79 -0
- package/dist/chunk-UQURXFAE.js +80 -0
- package/dist/chunk-VBG7T7XY.js +1703 -0
- package/dist/chunk-VCCMJIAG.js +326 -0
- package/dist/chunk-VS375NYD.js +91 -0
- package/dist/chunk-WANZOLI5.js +1073 -0
- package/dist/chunk-WUF3TVAE.js +51 -0
- package/dist/chunk-XCWLFZSM.js +149 -0
- package/dist/chunk-YJEUXO5I.js +76 -0
- package/dist/chunk-YR6RCC6Y.js +894 -0
- package/dist/chunk-ZQFAX275.js +35 -0
- package/dist/config-ELG4FQ3K.js +30 -0
- package/dist/config-IEWRCG7R.js +50 -0
- package/dist/doctor-ZZC2D3RW.js +357 -0
- package/dist/ext-context-RIMZMEPB.js +37 -0
- package/dist/index.js +20 -0
- package/dist/init-UB3E47KM.js +22 -0
- package/dist/integrations-HW4VTLN4.js +183 -0
- package/dist/main-RAWWT22W.js +115 -0
- package/dist/mcp-SWD4SO35.js +232 -0
- package/dist/mcp-context-PM5FY665.js +28 -0
- package/dist/memory-QQ54GRCN.js +128 -0
- package/dist/memory-session-R6DGT6CS.js +14 -0
- package/dist/memory-summary-4P26B2ZY.js +18 -0
- package/dist/plugins-VUGTEUNV.js +166 -0
- package/dist/providers-O3WOVP5Q.js +417 -0
- package/dist/report-DDIZ6BLF.js +28 -0
- package/dist/sec-context-VQHW6TOZ.js +15 -0
- package/dist/security-SAYW4LU4.js +95 -0
- package/dist/sessions-CL6CRNQL.js +160 -0
- package/dist/skills-7KDGTTKX.js +126 -0
- package/dist/version-6E6A23B3.js +13 -0
- package/package.json +70 -4
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
validateDisplayName,
|
|
4
|
+
validateEndpoint,
|
|
5
|
+
validateEnvVarName,
|
|
6
|
+
validateModelId
|
|
7
|
+
} from "./chunk-KGA7VWQG.js";
|
|
8
|
+
import {
|
|
9
|
+
ConfigSchema
|
|
10
|
+
} from "./chunk-QH27MDJM.js";
|
|
11
|
+
import {
|
|
12
|
+
ZgError
|
|
13
|
+
} from "./chunk-FC3UOHOO.js";
|
|
14
|
+
import {
|
|
15
|
+
looksLikeSecretKey,
|
|
16
|
+
looksLikeSecretValue
|
|
17
|
+
} from "./chunk-WUF3TVAE.js";
|
|
18
|
+
|
|
19
|
+
// src/config/keys.ts
|
|
20
|
+
var SETTABLE_KEYS = [
|
|
21
|
+
"defaultProvider",
|
|
22
|
+
"defaultModel",
|
|
23
|
+
"theme",
|
|
24
|
+
"streaming",
|
|
25
|
+
"systemPrompt",
|
|
26
|
+
"context.windowSize",
|
|
27
|
+
"context.warnAtPercent",
|
|
28
|
+
"context.replyReserve",
|
|
29
|
+
"context.compaction.enabled",
|
|
30
|
+
"context.compaction.thresholdPercent",
|
|
31
|
+
"context.compaction.keepRecentMessages",
|
|
32
|
+
"network.requestTimeoutSeconds",
|
|
33
|
+
"network.retry.maxAttempts",
|
|
34
|
+
"network.retry.baseDelayMs",
|
|
35
|
+
"agent.enabled",
|
|
36
|
+
"agent.maxSteps",
|
|
37
|
+
"agent.maxPlanRepairs",
|
|
38
|
+
"filesystem.projectRoot",
|
|
39
|
+
"filesystem.maxFileBytes",
|
|
40
|
+
"filesystem.search.maxResults",
|
|
41
|
+
"filesystem.search.maxFilesScanned",
|
|
42
|
+
"filesystem.backups",
|
|
43
|
+
"filesystem.diffPreview",
|
|
44
|
+
"filesystem.permissions.<read|search|create|edit|delete|rename|move>",
|
|
45
|
+
"execution.permission",
|
|
46
|
+
"execution.timeoutSeconds",
|
|
47
|
+
"execution.maxOutputBytes",
|
|
48
|
+
"execution.maxConcurrent",
|
|
49
|
+
"execution.killGraceSeconds",
|
|
50
|
+
"execution.shell",
|
|
51
|
+
"execution.confirmMedium",
|
|
52
|
+
"execution.defaultCwd",
|
|
53
|
+
"execution.envAllowlist",
|
|
54
|
+
"execution.extraBlockedPrograms",
|
|
55
|
+
"git.permission",
|
|
56
|
+
"git.staging",
|
|
57
|
+
"git.commit",
|
|
58
|
+
"git.branches",
|
|
59
|
+
"git.logLimit",
|
|
60
|
+
"git.statusMaxFiles",
|
|
61
|
+
"git.diffMaxLines",
|
|
62
|
+
"git.diffMaxFiles",
|
|
63
|
+
"git.diffMaxBytes",
|
|
64
|
+
"git.conflictMaxRegions",
|
|
65
|
+
"git.conflictPreviewLines",
|
|
66
|
+
"git.suggestCommitMessage",
|
|
67
|
+
"memory.enabled",
|
|
68
|
+
"memory.projectMemory",
|
|
69
|
+
"memory.globalPreferences",
|
|
70
|
+
"memory.autoSave",
|
|
71
|
+
"memory.autoSummarize",
|
|
72
|
+
"memory.excludeSensitiveData",
|
|
73
|
+
"memory.maxEntries",
|
|
74
|
+
"memory.maxEntryChars",
|
|
75
|
+
"sessions.autoSave",
|
|
76
|
+
"sessions.autoSummarize",
|
|
77
|
+
"sessions.retentionDays",
|
|
78
|
+
"sessions.confirmBeforeDelete",
|
|
79
|
+
"sessions.maxMessages",
|
|
80
|
+
"sessions.maxSessions",
|
|
81
|
+
"mcp.enabled",
|
|
82
|
+
"mcp.connectTimeoutSeconds",
|
|
83
|
+
"mcp.requestTimeoutSeconds",
|
|
84
|
+
"mcp.maxResultBytes",
|
|
85
|
+
"mcp.maxResourceBytes",
|
|
86
|
+
"mcp.maxToolsPerServer",
|
|
87
|
+
"extensions.skills.enabled",
|
|
88
|
+
"extensions.skills.maxActive",
|
|
89
|
+
"extensions.skills.maxContextChars",
|
|
90
|
+
"extensions.plugins.enabled",
|
|
91
|
+
"extensions.plugins.startTimeoutSeconds",
|
|
92
|
+
"extensions.plugins.callTimeoutSeconds",
|
|
93
|
+
"extensions.plugins.maxResultBytes",
|
|
94
|
+
"extensions.agents.enabled",
|
|
95
|
+
"extensions.agents.maxDelegationDepth",
|
|
96
|
+
"extensions.agents.maxConcurrent",
|
|
97
|
+
"extensions.agents.timeoutSeconds",
|
|
98
|
+
"extensions.agents.maxRuns",
|
|
99
|
+
"advanced.indexing.enabled",
|
|
100
|
+
"advanced.indexing.maxFiles",
|
|
101
|
+
"advanced.indexing.maxFileBytes",
|
|
102
|
+
"advanced.indexing.contextChars",
|
|
103
|
+
"advanced.lsp.enabled",
|
|
104
|
+
"advanced.lsp.startTimeoutSeconds",
|
|
105
|
+
"advanced.lsp.requestTimeoutSeconds",
|
|
106
|
+
"security.mode",
|
|
107
|
+
"security.levels.<level>",
|
|
108
|
+
"security.audit.enabled",
|
|
109
|
+
"security.audit.retentionDays",
|
|
110
|
+
"security.audit.maxBytes",
|
|
111
|
+
"security.allowSessionGrants",
|
|
112
|
+
"security.allowPersistentGrants",
|
|
113
|
+
"security.grantMinutes",
|
|
114
|
+
"approvalMode",
|
|
115
|
+
"ollamaEndpoint",
|
|
116
|
+
"customEndpoint.url",
|
|
117
|
+
"customEndpoint.envVar",
|
|
118
|
+
"customEndpoint.displayName",
|
|
119
|
+
"customEndpoint.requiresKey",
|
|
120
|
+
"preferences.<name>"
|
|
121
|
+
];
|
|
122
|
+
var NULLISH = /* @__PURE__ */ new Set(["", "none", "null", "unset"]);
|
|
123
|
+
function parseBoolean(raw) {
|
|
124
|
+
const v = raw.toLowerCase();
|
|
125
|
+
if (["true", "on", "yes", "1"].includes(v)) return true;
|
|
126
|
+
if (["false", "off", "no", "0"].includes(v)) return false;
|
|
127
|
+
throw new ZgError(`expected true or false, got "${raw}"`);
|
|
128
|
+
}
|
|
129
|
+
function parsePreference(raw) {
|
|
130
|
+
const v = raw.toLowerCase();
|
|
131
|
+
if (v === "true") return true;
|
|
132
|
+
if (v === "false") return false;
|
|
133
|
+
if (raw.trim() !== "" && Number.isFinite(Number(raw))) return Number(raw);
|
|
134
|
+
return raw;
|
|
135
|
+
}
|
|
136
|
+
function validate(candidate) {
|
|
137
|
+
const result = ConfigSchema.safeParse(candidate);
|
|
138
|
+
if (!result.success) {
|
|
139
|
+
const detail = result.error.issues.map((i) => `${i.path.join(".") || "value"}: ${i.message}`).join("; ");
|
|
140
|
+
throw new ZgError(`invalid value (${detail})`);
|
|
141
|
+
}
|
|
142
|
+
return result.data;
|
|
143
|
+
}
|
|
144
|
+
var NESTED_KEYS = {
|
|
145
|
+
"context.windowSize": "int",
|
|
146
|
+
"context.warnAtPercent": "int",
|
|
147
|
+
"context.replyReserve": "int",
|
|
148
|
+
"context.compaction.enabled": "boolean",
|
|
149
|
+
"context.compaction.thresholdPercent": "int",
|
|
150
|
+
"context.compaction.keepRecentMessages": "int",
|
|
151
|
+
"network.requestTimeoutSeconds": "int",
|
|
152
|
+
"network.retry.maxAttempts": "int",
|
|
153
|
+
"network.retry.baseDelayMs": "int",
|
|
154
|
+
"agent.enabled": "boolean",
|
|
155
|
+
"agent.maxSteps": "int",
|
|
156
|
+
"agent.maxPlanRepairs": "int",
|
|
157
|
+
"filesystem.maxFileBytes": "int",
|
|
158
|
+
"filesystem.search.maxResults": "int",
|
|
159
|
+
"filesystem.search.maxFilesScanned": "int",
|
|
160
|
+
"filesystem.backups": "boolean",
|
|
161
|
+
"filesystem.diffPreview": "boolean",
|
|
162
|
+
"execution.timeoutSeconds": "int",
|
|
163
|
+
"execution.maxOutputBytes": "int",
|
|
164
|
+
"execution.maxConcurrent": "int",
|
|
165
|
+
"execution.killGraceSeconds": "int",
|
|
166
|
+
"execution.confirmMedium": "boolean",
|
|
167
|
+
"git.logLimit": "int",
|
|
168
|
+
"git.statusMaxFiles": "int",
|
|
169
|
+
"git.diffMaxLines": "int",
|
|
170
|
+
"git.diffMaxFiles": "int",
|
|
171
|
+
"git.diffMaxBytes": "int",
|
|
172
|
+
"git.conflictMaxRegions": "int",
|
|
173
|
+
"git.conflictPreviewLines": "int",
|
|
174
|
+
"git.suggestCommitMessage": "boolean",
|
|
175
|
+
"memory.enabled": "boolean",
|
|
176
|
+
"memory.projectMemory": "boolean",
|
|
177
|
+
"memory.globalPreferences": "boolean",
|
|
178
|
+
"memory.autoSave": "boolean",
|
|
179
|
+
"memory.autoSummarize": "boolean",
|
|
180
|
+
"memory.excludeSensitiveData": "boolean",
|
|
181
|
+
"memory.maxEntries": "int",
|
|
182
|
+
"memory.maxEntryChars": "int",
|
|
183
|
+
"sessions.autoSave": "boolean",
|
|
184
|
+
"sessions.autoSummarize": "boolean",
|
|
185
|
+
"sessions.retentionDays": "int",
|
|
186
|
+
"sessions.confirmBeforeDelete": "boolean",
|
|
187
|
+
"sessions.maxMessages": "int",
|
|
188
|
+
"sessions.maxSessions": "int",
|
|
189
|
+
"mcp.enabled": "boolean",
|
|
190
|
+
"mcp.connectTimeoutSeconds": "int",
|
|
191
|
+
"mcp.requestTimeoutSeconds": "int",
|
|
192
|
+
"mcp.maxResultBytes": "int",
|
|
193
|
+
"mcp.maxResourceBytes": "int",
|
|
194
|
+
"mcp.maxToolsPerServer": "int",
|
|
195
|
+
"advanced.indexing.enabled": "boolean",
|
|
196
|
+
"advanced.indexing.maxFiles": "int",
|
|
197
|
+
"advanced.indexing.maxFileBytes": "int",
|
|
198
|
+
"advanced.indexing.contextChars": "int",
|
|
199
|
+
"advanced.lsp.enabled": "boolean",
|
|
200
|
+
"advanced.lsp.startTimeoutSeconds": "int",
|
|
201
|
+
"advanced.lsp.requestTimeoutSeconds": "int",
|
|
202
|
+
"security.audit.enabled": "boolean",
|
|
203
|
+
"security.audit.retentionDays": "int",
|
|
204
|
+
"security.audit.maxBytes": "int",
|
|
205
|
+
"security.allowSessionGrants": "boolean",
|
|
206
|
+
"security.allowPersistentGrants": "boolean",
|
|
207
|
+
"security.grantMinutes": "int",
|
|
208
|
+
"extensions.skills.enabled": "boolean",
|
|
209
|
+
"extensions.skills.maxActive": "int",
|
|
210
|
+
"extensions.skills.maxContextChars": "int",
|
|
211
|
+
"extensions.plugins.enabled": "boolean",
|
|
212
|
+
"extensions.plugins.startTimeoutSeconds": "int",
|
|
213
|
+
"extensions.plugins.callTimeoutSeconds": "int",
|
|
214
|
+
"extensions.plugins.maxResultBytes": "int",
|
|
215
|
+
"extensions.agents.enabled": "boolean",
|
|
216
|
+
"extensions.agents.maxDelegationDepth": "int",
|
|
217
|
+
"extensions.agents.maxConcurrent": "int",
|
|
218
|
+
"extensions.agents.timeoutSeconds": "int",
|
|
219
|
+
"extensions.agents.maxRuns": "int"
|
|
220
|
+
};
|
|
221
|
+
var GIT_ENUMS = /* @__PURE__ */ new Set(["git.permission", "git.staging", "git.commit", "git.branches"]);
|
|
222
|
+
var EXEC_ENUMS = { "execution.permission": ["ask", "deny"], "execution.shell": ["deny", "ask"] };
|
|
223
|
+
var EXEC_LISTS = /* @__PURE__ */ new Set(["execution.envAllowlist", "execution.extraBlockedPrograms"]);
|
|
224
|
+
function parseInteger(raw) {
|
|
225
|
+
const t = raw.trim().replace(/[_,]/g, "");
|
|
226
|
+
if (!/^\d+$/.test(t)) throw new ZgError(`expected a whole number, got "${raw}"`);
|
|
227
|
+
return Number(t);
|
|
228
|
+
}
|
|
229
|
+
function withPath(config, path, value) {
|
|
230
|
+
const root = { ...config };
|
|
231
|
+
let node = root;
|
|
232
|
+
for (const part of path.slice(0, -1)) {
|
|
233
|
+
node[part] = { ...node[part] ?? {} };
|
|
234
|
+
node = node[part];
|
|
235
|
+
}
|
|
236
|
+
node[path[path.length - 1]] = value;
|
|
237
|
+
return root;
|
|
238
|
+
}
|
|
239
|
+
function getConfigValue(config, key) {
|
|
240
|
+
if (key in NESTED_KEYS) {
|
|
241
|
+
let node = config;
|
|
242
|
+
for (const part of key.split(".")) node = node?.[part];
|
|
243
|
+
return node ?? null;
|
|
244
|
+
}
|
|
245
|
+
if (key === "filesystem.projectRoot") return config.filesystem.projectRoot;
|
|
246
|
+
if (key in EXEC_ENUMS || EXEC_LISTS.has(key) || key === "execution.defaultCwd") return config.execution[key.slice("execution.".length)];
|
|
247
|
+
if (GIT_ENUMS.has(key)) return config.git[key.slice("git.".length)];
|
|
248
|
+
if (key.startsWith("filesystem.permissions.")) {
|
|
249
|
+
const v = config.filesystem.permissions[key.slice("filesystem.permissions.".length)];
|
|
250
|
+
if (v === void 0) throw new ZgError(`unknown config key "${key}"`, { hint: `valid keys: ${SETTABLE_KEYS.join(", ")}` });
|
|
251
|
+
return v;
|
|
252
|
+
}
|
|
253
|
+
if (key === "security.mode") return config.security.mode;
|
|
254
|
+
if (key.startsWith("security.levels.")) return config.security.levels[key.slice("security.levels.".length)] ?? null;
|
|
255
|
+
if (key.startsWith("preferences.")) {
|
|
256
|
+
return config.preferences[key.slice("preferences.".length)] ?? null;
|
|
257
|
+
}
|
|
258
|
+
if (key.startsWith("customEndpoint.")) {
|
|
259
|
+
const field = key.slice("customEndpoint.".length);
|
|
260
|
+
const ce = config.customEndpoint;
|
|
261
|
+
if (!["url", "envVar", "displayName", "requiresKey"].includes(field)) {
|
|
262
|
+
throw new ZgError(`unknown config key "${key}"`, { hint: `valid keys: ${SETTABLE_KEYS.join(", ")}` });
|
|
263
|
+
}
|
|
264
|
+
return ce?.[field] ?? null;
|
|
265
|
+
}
|
|
266
|
+
if (key === "version" || !(key in config)) {
|
|
267
|
+
throw new ZgError(`unknown config key "${key}"`, {
|
|
268
|
+
hint: `valid keys: ${SETTABLE_KEYS.join(", ")}`
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
return config[key];
|
|
272
|
+
}
|
|
273
|
+
function setConfigValue(config, key, raw) {
|
|
274
|
+
if (looksLikeSecretKey(key)) {
|
|
275
|
+
throw new ZgError(`"${key}" looks like a credential setting`, {
|
|
276
|
+
hint: "zg never stores API keys or tokens in its config file."
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
if (looksLikeSecretValue(raw)) {
|
|
280
|
+
throw new ZgError("that value looks like a credential and was not saved", {
|
|
281
|
+
hint: "zg never stores API keys or tokens in its config file."
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
if (key === "security.mode") return validate(withPath(config, ["security", "mode"], raw.toLowerCase()));
|
|
285
|
+
if (key.startsWith("security.levels.")) {
|
|
286
|
+
const lv = key.slice("security.levels.".length);
|
|
287
|
+
if (!["read-only", "analyze", "modify", "command", "dependency", "git", "external", "admin"].includes(lv)) throw new ZgError(`unknown permission level "${lv}"`, { hint: "levels: read-only, analyze, modify, command, dependency, git, external, admin" });
|
|
288
|
+
return validate(withPath(config, ["security", "levels", lv], NULLISH.has(raw.toLowerCase()) ? void 0 : raw.toLowerCase()));
|
|
289
|
+
}
|
|
290
|
+
if (key.startsWith("preferences.")) {
|
|
291
|
+
const name = key.slice("preferences.".length);
|
|
292
|
+
return validate({ ...config, preferences: { ...config.preferences, [name]: parsePreference(raw) } });
|
|
293
|
+
}
|
|
294
|
+
if (key === "filesystem.projectRoot") {
|
|
295
|
+
if (NULLISH.has(raw.toLowerCase())) return validate(withPath(config, ["filesystem", "projectRoot"], null));
|
|
296
|
+
return validate(withPath(config, ["filesystem", "projectRoot"], raw));
|
|
297
|
+
}
|
|
298
|
+
if (key in EXEC_ENUMS) return validate(withPath(config, ["execution", key.slice("execution.".length)], raw.toLowerCase()));
|
|
299
|
+
if (GIT_ENUMS.has(key)) return validate(withPath(config, ["git", key.slice("git.".length)], raw.toLowerCase()));
|
|
300
|
+
if (key === "execution.defaultCwd") return validate(withPath(config, ["execution", "defaultCwd"], raw));
|
|
301
|
+
if (EXEC_LISTS.has(key)) {
|
|
302
|
+
const items = NULLISH.has(raw.toLowerCase()) ? [] : raw.split(/[,\s]+/).filter((x) => x !== "");
|
|
303
|
+
return validate(withPath(config, ["execution", key.slice("execution.".length)], items));
|
|
304
|
+
}
|
|
305
|
+
if (key.startsWith("filesystem.permissions.")) {
|
|
306
|
+
const name = key.slice("filesystem.permissions.".length);
|
|
307
|
+
if (!["read", "search", "create", "edit", "delete", "rename", "move"].includes(name)) throw new ZgError(`unknown config key "${key}"`, { hint: `valid keys: ${SETTABLE_KEYS.join(", ")}` });
|
|
308
|
+
return validate(withPath(config, ["filesystem", "permissions", name], raw.toLowerCase()));
|
|
309
|
+
}
|
|
310
|
+
if (key.startsWith("customEndpoint.")) return setCustomEndpointField(config, key.slice("customEndpoint.".length), raw);
|
|
311
|
+
const kind = NESTED_KEYS[key];
|
|
312
|
+
if (kind) {
|
|
313
|
+
const value = kind === "boolean" ? parseBoolean(raw) : parseInteger(raw);
|
|
314
|
+
return validate(withPath(config, key.split("."), value));
|
|
315
|
+
}
|
|
316
|
+
switch (key) {
|
|
317
|
+
case "systemPrompt": {
|
|
318
|
+
if (NULLISH.has(raw.toLowerCase())) return validate({ ...config, systemPrompt: null });
|
|
319
|
+
return validate({ ...config, systemPrompt: raw });
|
|
320
|
+
}
|
|
321
|
+
case "ollamaEndpoint": {
|
|
322
|
+
if (NULLISH.has(raw.toLowerCase())) return validate({ ...config, ollamaEndpoint: null });
|
|
323
|
+
const v = validateEndpoint(raw, { allowInsecureHttp: false });
|
|
324
|
+
if (!v.ok) throw new ZgError(`invalid endpoint: ${v.reason}`);
|
|
325
|
+
return validate({ ...config, ollamaEndpoint: v.value });
|
|
326
|
+
}
|
|
327
|
+
case "defaultModel": {
|
|
328
|
+
if (NULLISH.has(raw.toLowerCase())) return validate({ ...config, defaultModel: null });
|
|
329
|
+
const v = validateModelId(raw);
|
|
330
|
+
if (!v.ok) throw new ZgError(v.reason);
|
|
331
|
+
return validate({ ...config, defaultModel: v.value });
|
|
332
|
+
}
|
|
333
|
+
case "defaultProvider":
|
|
334
|
+
return validate({ ...config, [key]: NULLISH.has(raw.toLowerCase()) ? null : raw });
|
|
335
|
+
case "theme":
|
|
336
|
+
case "approvalMode":
|
|
337
|
+
return validate({ ...config, [key]: raw });
|
|
338
|
+
case "streaming":
|
|
339
|
+
return validate({ ...config, streaming: parseBoolean(raw) });
|
|
340
|
+
default:
|
|
341
|
+
throw new ZgError(`unknown or read-only config key "${key}"`, {
|
|
342
|
+
hint: `valid keys: ${SETTABLE_KEYS.join(", ")}`
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function setCustomEndpointField(config, field, raw) {
|
|
347
|
+
const current = config.customEndpoint ?? { url: "", envVar: null, displayName: null, requiresKey: true };
|
|
348
|
+
const nullish = NULLISH.has(raw.toLowerCase());
|
|
349
|
+
switch (field) {
|
|
350
|
+
case "url": {
|
|
351
|
+
const v = validateEndpoint(raw);
|
|
352
|
+
if (!v.ok) throw new ZgError(`invalid endpoint: ${v.reason}`);
|
|
353
|
+
return validate({ ...config, customEndpoint: { ...current, url: v.value } });
|
|
354
|
+
}
|
|
355
|
+
case "envVar": {
|
|
356
|
+
if (nullish) return validate({ ...config, customEndpoint: { ...current, envVar: null } });
|
|
357
|
+
const v = validateEnvVarName(raw);
|
|
358
|
+
if (!v.ok) throw new ZgError(`invalid environment variable name: ${v.reason}`);
|
|
359
|
+
return validate({ ...config, customEndpoint: { ...current, envVar: v.value } });
|
|
360
|
+
}
|
|
361
|
+
case "displayName": {
|
|
362
|
+
if (nullish) return validate({ ...config, customEndpoint: { ...current, displayName: null } });
|
|
363
|
+
const v = validateDisplayName(raw);
|
|
364
|
+
if (!v.ok) throw new ZgError(v.reason);
|
|
365
|
+
return validate({ ...config, customEndpoint: { ...current, displayName: v.value } });
|
|
366
|
+
}
|
|
367
|
+
case "requiresKey":
|
|
368
|
+
return validate({ ...config, customEndpoint: { ...current, requiresKey: parseBoolean(raw) } });
|
|
369
|
+
default:
|
|
370
|
+
throw new ZgError(`unknown config key "customEndpoint.${field}"`, { hint: `valid keys: ${SETTABLE_KEYS.join(", ")}` });
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export {
|
|
375
|
+
SETTABLE_KEYS,
|
|
376
|
+
getConfigValue,
|
|
377
|
+
setConfigValue
|
|
378
|
+
};
|