velqa 0.1.0 → 0.1.1
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 +12 -7
- package/dist/cli.js +96 -36
- package/dist/config.js +109 -44
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -9,13 +9,18 @@ models that key can use, and writes:
|
|
|
9
9
|
|
|
10
10
|
- **Claude Code**: the `env` block of `~/.claude/settings.json` (base URL, token, model, output cap).
|
|
11
11
|
- **Codex**: `model`, `model_provider` and a `[model_providers.velqa]` table in
|
|
12
|
-
`~/.codex/config.toml` (or `$CODEX_HOME`)
|
|
13
|
-
|
|
12
|
+
`~/.codex/config.toml` (or `$CODEX_HOME`). Your own keys in that table are kept; a layout it
|
|
13
|
+
cannot edit safely is left untouched and reported.
|
|
14
14
|
- **opencode**: a `velqa` provider with every chat model the key can use, and the chosen one as
|
|
15
|
-
default, in `~/.config/opencode/opencode.json` (or `opencode.jsonc
|
|
16
|
-
|
|
17
|
-
from the same `VELQA_API_KEY`.
|
|
15
|
+
default, in `~/.config/opencode/opencode.json` (or `opencode.jsonc`, comments kept). It uses
|
|
16
|
+
the `provider` format, which opencode 1 reads and opencode 2 migrates.
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
Codex and opencode read the key from `VELQA_API_KEY`: it is set in a marked block of `~/.zshrc`
|
|
19
|
+
or `~/.bashrc`, in `~/.config/fish/conf.d/velqa.fish`, or in your Windows user environment. On
|
|
20
|
+
any other shell, set it yourself; the key is never printed.
|
|
21
|
+
|
|
22
|
+
Nothing is written until every file has been prepared, so a config it cannot edit stops the
|
|
23
|
+
run with no change. Every file it changes is backed up next to itself first
|
|
24
|
+
(`*.velqa-backup-<time>`), replaced in one step, and readable by you only. Running it again
|
|
25
|
+
updates its own settings and keeps the ones you added.
|
|
21
26
|
If `VELQA_API_KEY` is already set, it is used without asking.
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { execFileSync } from "node:child_process";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { basename, delimiter, dirname, join } from "node:path";
|
|
@@ -19,7 +19,8 @@ const output = new Writable({
|
|
|
19
19
|
done();
|
|
20
20
|
},
|
|
21
21
|
});
|
|
22
|
-
|
|
22
|
+
// No history: Up at a later prompt would otherwise recall the hidden key.
|
|
23
|
+
const rl = createInterface({ input: stdin, output, terminal: stdin.isTTY, historySize: 0 });
|
|
23
24
|
// The iterator buffers lines (piped input arrives before the questions) and ends on EOF.
|
|
24
25
|
const lines = rl[Symbol.asyncIterator]();
|
|
25
26
|
async function readLine() {
|
|
@@ -51,33 +52,56 @@ function onPath(command) {
|
|
|
51
52
|
const names = platform === "win32" ? [`${command}.cmd`, `${command}.exe`, command] : [command];
|
|
52
53
|
return (env.PATH ?? "").split(delimiter).some((dir) => dir && names.some((n) => existsSync(join(dir, n))));
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
function readOrNull(path) {
|
|
56
|
+
return existsSync(path) ? readFileSync(path, "utf8") : null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Back up, then replace in one rename: a reader never sees half a file, and the
|
|
60
|
+
* new file and its backup are created readable by the user only (they may hold
|
|
61
|
+
* the key). A symlinked file (dotfiles repo) is written at its target.
|
|
62
|
+
*/
|
|
63
|
+
function target(path) {
|
|
64
|
+
if (existsSync(path))
|
|
65
|
+
return realpathSync(path);
|
|
66
|
+
let link = false;
|
|
56
67
|
try {
|
|
57
|
-
|
|
58
|
-
return Number(/(\d+)\.\d+/.exec(out)?.[1] ?? 1);
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
return 1;
|
|
68
|
+
link = lstatSync(path).isSymbolicLink();
|
|
62
69
|
}
|
|
70
|
+
catch { }
|
|
71
|
+
if (link)
|
|
72
|
+
throw new Error(`${path} is a broken symlink; fix it first`);
|
|
73
|
+
return path;
|
|
63
74
|
}
|
|
64
|
-
|
|
65
|
-
|
|
75
|
+
/** Refuse a file that changed while we asked questions, or that is not UTF-8 (rewriting it would lose bytes). */
|
|
76
|
+
function unchanged(change) {
|
|
77
|
+
target(change.path);
|
|
78
|
+
const now = existsSync(change.path) ? readFileSync(change.path) : null;
|
|
79
|
+
const same = now === null ? change.before === null : change.before !== null && now.equals(Buffer.from(change.before, "utf8"));
|
|
80
|
+
if (!same)
|
|
81
|
+
throw new Error(`${change.path} changed during setup or is not UTF-8 text; nothing was changed, run again`);
|
|
66
82
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const before = readOrNull(path);
|
|
70
|
-
if (before === content)
|
|
83
|
+
function apply(change) {
|
|
84
|
+
if (change.before === change.content)
|
|
71
85
|
return;
|
|
72
|
-
|
|
86
|
+
const path = target(change.path);
|
|
87
|
+
if (change.before !== null) {
|
|
73
88
|
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
74
|
-
|
|
75
|
-
copyFileSync(path, backup);
|
|
76
|
-
chmodSync(backup, 0o600);
|
|
89
|
+
writeFileSync(`${path}.velqa-backup-${stamp}`, change.before, { mode: 0o600, flag: "wx" });
|
|
77
90
|
}
|
|
78
91
|
mkdirSync(dirname(path), { recursive: true });
|
|
79
|
-
|
|
80
|
-
|
|
92
|
+
const tmp = `${path}.velqa-tmp-${process.pid}`;
|
|
93
|
+
writeFileSync(tmp, change.content, { mode: 0o600, flag: "wx" });
|
|
94
|
+
try {
|
|
95
|
+
renameSync(tmp, path);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
rmSync(tmp, { force: true });
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function change(path, build) {
|
|
103
|
+
const before = readOrNull(path);
|
|
104
|
+
return { path, before, content: build(before) };
|
|
81
105
|
}
|
|
82
106
|
async function fetchJson(url, key) {
|
|
83
107
|
const res = await fetch(url, { headers: key ? { Authorization: `Bearer ${key}` } : {} });
|
|
@@ -111,12 +135,21 @@ async function pickModel(models) {
|
|
|
111
135
|
return answer;
|
|
112
136
|
throw new Error(`Unknown model "${answer}".`);
|
|
113
137
|
}
|
|
114
|
-
|
|
138
|
+
/** Where the key goes for Codex and opencode; null when we do not know the shell. */
|
|
139
|
+
function keyFile(key) {
|
|
115
140
|
const shell = basename(env.SHELL ?? "");
|
|
116
141
|
if (shell === "zsh")
|
|
117
|
-
return join(homedir(), ".zshrc");
|
|
118
|
-
if (shell === "bash")
|
|
119
|
-
|
|
142
|
+
return change(join(env.ZDOTDIR || homedir(), ".zshrc"), (before) => shellExport(before, key));
|
|
143
|
+
if (shell === "bash") {
|
|
144
|
+
// macOS terminals start login shells: bash reads the first of these that exists, so creating another would hide it.
|
|
145
|
+
const login = [".bash_profile", ".bash_login", ".profile"].map((f) => join(homedir(), f));
|
|
146
|
+
const rc = platform === "darwin" ? (login.find((f) => existsSync(f)) ?? login[0]) : join(homedir(), ".bashrc");
|
|
147
|
+
return change(rc, (before) => shellExport(before, key));
|
|
148
|
+
}
|
|
149
|
+
if (shell === "fish") {
|
|
150
|
+
const conf = join(env.XDG_CONFIG_HOME || join(homedir(), ".config"), "fish", "conf.d", "velqa.fish");
|
|
151
|
+
return change(conf, () => `set -gx ${KEY_ENV} "${key}"\n`);
|
|
152
|
+
}
|
|
120
153
|
return null;
|
|
121
154
|
}
|
|
122
155
|
async function init() {
|
|
@@ -130,17 +163,18 @@ async function init() {
|
|
|
130
163
|
throw new Error("This key has access to no chat model.");
|
|
131
164
|
stdout.write("Key accepted. Chat models available to it:\n");
|
|
132
165
|
const model = await pickModel(models);
|
|
166
|
+
// Ask and build everything first: a config we cannot edit stops the run before any file changes.
|
|
167
|
+
const changes = [];
|
|
133
168
|
const done = [];
|
|
134
169
|
if (await confirm(`Configure Claude Code${onPath("claude") ? "" : " (not found on PATH)"}?`, onPath("claude"))) {
|
|
135
170
|
const path = join(homedir(), ".claude", "settings.json");
|
|
136
|
-
|
|
171
|
+
changes.push(change(path, (before) => claudeSettings(before, key, model)));
|
|
137
172
|
done.push(`Claude Code: ${path}\n try: claude "explain this repo in 3 sentences"`);
|
|
138
173
|
}
|
|
139
174
|
let needsKeyEnv = false;
|
|
140
175
|
if (await confirm(`Configure Codex${onPath("codex") ? "" : " (not found on PATH)"}?`, onPath("codex"))) {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
writeWithBackup(path, codexConfig(readOrNull(path), model));
|
|
176
|
+
const path = join(env.CODEX_HOME || join(homedir(), ".codex"), "config.toml");
|
|
177
|
+
changes.push(change(path, (before) => codexConfig(before, model)));
|
|
144
178
|
done.push(`Codex: ${path}\n then: codex`);
|
|
145
179
|
needsKeyEnv = true;
|
|
146
180
|
}
|
|
@@ -148,21 +182,47 @@ async function init() {
|
|
|
148
182
|
const dir = join(env.XDG_CONFIG_HOME || join(homedir(), ".config"), "opencode");
|
|
149
183
|
const jsonc = join(dir, "opencode.jsonc");
|
|
150
184
|
const path = existsSync(jsonc) ? jsonc : join(dir, "opencode.json");
|
|
151
|
-
|
|
185
|
+
changes.push(change(path, (before) => opencodeConfig(before, models, model)));
|
|
152
186
|
done.push(`opencode: ${path}\n then: opencode (switch models with /models)`);
|
|
153
187
|
needsKeyEnv = true;
|
|
154
188
|
}
|
|
189
|
+
let setxNeeded = false;
|
|
155
190
|
if (needsKeyEnv) {
|
|
156
|
-
const
|
|
157
|
-
if (
|
|
158
|
-
|
|
159
|
-
done.push(`${KEY_ENV}
|
|
191
|
+
const file = platform === "win32" ? null : keyFile(key);
|
|
192
|
+
if (file) {
|
|
193
|
+
changes.push(file);
|
|
194
|
+
done.push(`${KEY_ENV} set in ${file.path}: open a new terminal first`);
|
|
195
|
+
}
|
|
196
|
+
else if (platform === "win32") {
|
|
197
|
+
setxNeeded = true;
|
|
198
|
+
done.push(`${KEY_ENV} saved in your Windows user environment: open a new terminal first`);
|
|
160
199
|
}
|
|
161
200
|
else {
|
|
162
|
-
|
|
163
|
-
done.push(`set
|
|
201
|
+
// Never print the key: it would land in the terminal's scrollback and history.
|
|
202
|
+
done.push(`set ${KEY_ENV} to your key in your shell's startup file`);
|
|
164
203
|
}
|
|
165
204
|
}
|
|
205
|
+
changes.forEach(unchanged);
|
|
206
|
+
const written = [];
|
|
207
|
+
try {
|
|
208
|
+
for (const c of changes) {
|
|
209
|
+
apply(c);
|
|
210
|
+
written.push(c.path);
|
|
211
|
+
}
|
|
212
|
+
// setx stores the variable for new terminals; run without a shell, so the key reaches no history.
|
|
213
|
+
if (setxNeeded) {
|
|
214
|
+
try {
|
|
215
|
+
execFileSync("setx", [KEY_ENV, key], { stdio: "ignore" });
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
throw new Error(`setx could not save ${KEY_ENV}`); // the original error quotes the command line, key included
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
const kept = written.length ? ` Already updated (backups next to them): ${written.join(", ")}.` : "";
|
|
224
|
+
throw new Error(`${error instanceof Error ? error.message : String(error)}.${kept}`);
|
|
225
|
+
}
|
|
166
226
|
stdout.write(done.length ? `\nDone.\n${done.map((d) => `- ${d}`).join("\n")}\n` : "\nNothing configured.\n");
|
|
167
227
|
}
|
|
168
228
|
const command = argv[2] ?? "init";
|
package/dist/config.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// Pure config writers: each takes the current file content (null when the file
|
|
2
2
|
// does not exist) and returns the new content. No I/O here, so they are tested
|
|
3
3
|
// directly and the CLI only decides where to read and write.
|
|
4
|
+
import { applyEdits, modify, parse as parseJsonc } from "jsonc-parser";
|
|
5
|
+
import { parse as parseToml } from "smol-toml";
|
|
6
|
+
import { isDeepStrictEqual } from "node:util";
|
|
4
7
|
export const OAI_BASE = "https://api.velqa.dev/v1";
|
|
5
8
|
export const ANTHROPIC_BASE = "https://api.velqa.dev";
|
|
6
9
|
export const DEFAULT_MODEL = "glm-5.3-flash";
|
|
@@ -26,26 +29,39 @@ export function modelLimit(model) {
|
|
|
26
29
|
}
|
|
27
30
|
/** ~/.claude/settings.json: set Velqa's variables in `env`, keep everything else. */
|
|
28
31
|
export function claudeSettings(existing, key, model) {
|
|
29
|
-
|
|
32
|
+
let settings;
|
|
33
|
+
try {
|
|
34
|
+
settings = existing?.trim() ? JSON.parse(existing) : {};
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Fixed message: JSON.parse quotes the text around the error, which may be the old key.
|
|
38
|
+
throw new Error("~/.claude/settings.json is not valid JSON; fix it first");
|
|
39
|
+
}
|
|
30
40
|
if (typeof settings !== "object" || settings === null || Array.isArray(settings)) {
|
|
31
41
|
throw new Error("~/.claude/settings.json is not a JSON object");
|
|
32
42
|
}
|
|
33
43
|
const env = typeof settings.env === "object" && settings.env !== null && !Array.isArray(settings.env)
|
|
34
44
|
? settings.env
|
|
35
45
|
: {};
|
|
46
|
+
// A rerun keeps the user's own small model and any lower output cap; the cap never exceeds the model's.
|
|
47
|
+
const cap = modelLimit(model).output;
|
|
48
|
+
const ownCap = Number(env.CLAUDE_CODE_MAX_OUTPUT_TOKENS);
|
|
36
49
|
settings.env = {
|
|
37
50
|
...env,
|
|
38
51
|
ANTHROPIC_BASE_URL: ANTHROPIC_BASE,
|
|
39
52
|
ANTHROPIC_AUTH_TOKEN: key,
|
|
40
53
|
ANTHROPIC_MODEL: model,
|
|
41
|
-
ANTHROPIC_SMALL_FAST_MODEL: SMALL_FAST_MODEL,
|
|
42
|
-
CLAUDE_CODE_MAX_OUTPUT_TOKENS: String(
|
|
54
|
+
ANTHROPIC_SMALL_FAST_MODEL: typeof env.ANTHROPIC_SMALL_FAST_MODEL === "string" ? env.ANTHROPIC_SMALL_FAST_MODEL : SMALL_FAST_MODEL,
|
|
55
|
+
CLAUDE_CODE_MAX_OUTPUT_TOKENS: String(ownCap > 0 && ownCap < cap ? ownCap : cap),
|
|
43
56
|
};
|
|
44
57
|
return JSON.stringify(settings, null, 2) + "\n";
|
|
45
58
|
}
|
|
46
|
-
|
|
59
|
+
// Bare or quoted TOML keys: `model`, `"model"` and `'model'` are the same key.
|
|
60
|
+
const tomlKey = (names) => `\\s*(?:${names}|"(?:${names})"|'(?:${names})')\\s*`;
|
|
61
|
+
const CODEX_TOP_KEYS = new RegExp(`^${tomlKey("model|model_provider|model_context_window")}=`);
|
|
62
|
+
const VELQA_KEYS = new RegExp(`^${tomlKey("name|base_url|env_key|wire_api")}=`);
|
|
47
63
|
const TABLE_HEADER = /^\s*\[/;
|
|
48
|
-
const VELQA_TABLE =
|
|
64
|
+
const VELQA_TABLE = new RegExp(`^\\s*\\[${tomlKey("model_providers")}\\.${tomlKey("velqa")}\\]\\s*(#.*)?$`);
|
|
49
65
|
/**
|
|
50
66
|
* ~/.codex/config.toml: Codex reads `model`, `model_provider` and
|
|
51
67
|
* `model_context_window` only before the first [table], so they are replaced
|
|
@@ -57,13 +73,20 @@ export function codexConfig(existing, model) {
|
|
|
57
73
|
const firstTable = lines.findIndex((line) => TABLE_HEADER.test(line));
|
|
58
74
|
const topEnd = firstTable === -1 ? lines.length : firstTable;
|
|
59
75
|
const top = lines.slice(0, topEnd).filter((line) => !CODEX_TOP_KEYS.test(line));
|
|
76
|
+
// Our table is rebuilt at the end; keys the user added to it (retries, headers...) are kept.
|
|
60
77
|
const rest = [];
|
|
78
|
+
const ownVelqaLines = [];
|
|
61
79
|
let inVelqaTable = false;
|
|
62
80
|
for (const line of lines.slice(topEnd)) {
|
|
63
|
-
if (TABLE_HEADER.test(line))
|
|
81
|
+
if (TABLE_HEADER.test(line)) {
|
|
64
82
|
inVelqaTable = VELQA_TABLE.test(line);
|
|
83
|
+
if (inVelqaTable)
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
65
86
|
if (!inVelqaTable)
|
|
66
87
|
rest.push(line);
|
|
88
|
+
else if (!VELQA_KEYS.test(line))
|
|
89
|
+
ownVelqaLines.push(line);
|
|
67
90
|
}
|
|
68
91
|
const ours = [
|
|
69
92
|
`model = "${model}"`,
|
|
@@ -78,53 +101,95 @@ export function codexConfig(existing, model) {
|
|
|
78
101
|
'wire_api = "responses"',
|
|
79
102
|
];
|
|
80
103
|
const body = [...ours, ...trimBlank(top), "", ...trimBlank(rest)];
|
|
81
|
-
|
|
104
|
+
const result = [...trimBlank(body), "", ...table, ...trimBlank(ownVelqaLines), ""].join("\n");
|
|
105
|
+
checkCodex(existing, result, model);
|
|
106
|
+
return result;
|
|
82
107
|
}
|
|
83
|
-
/**
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
* the npm `latest`, only knows `provider` (npm + options), which 2 migrates.
|
|
88
|
-
* The entry in the other format is removed so the two never disagree.
|
|
89
|
-
*/
|
|
90
|
-
export function opencodeConfig(existing, models, model, v2) {
|
|
91
|
-
let config;
|
|
108
|
+
/** The line edit above covers ordinary files; a real parse catches every layout it does not (dotted keys, inline tables...). */
|
|
109
|
+
function checkCodex(existing, result, model) {
|
|
110
|
+
const byHand = "add the Velqa provider by hand (https://velqa.dev/docs/codex)";
|
|
111
|
+
let before;
|
|
92
112
|
try {
|
|
93
|
-
|
|
113
|
+
before = parseToml(existing ?? "");
|
|
94
114
|
}
|
|
95
115
|
catch {
|
|
96
|
-
throw new Error(
|
|
116
|
+
throw new Error(`the Codex config.toml is not valid TOML; fix it or ${byHand}`);
|
|
97
117
|
}
|
|
118
|
+
let parsed;
|
|
119
|
+
try {
|
|
120
|
+
parsed = parseToml(result);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
throw new Error(`the Codex config.toml has a layout this tool cannot edit safely; ${byHand}`);
|
|
124
|
+
}
|
|
125
|
+
const provider = parsed.model_providers?.velqa;
|
|
126
|
+
// Apart from the fields we own, the parsed config must not change (a `model = ` line inside a multi-line string, say).
|
|
127
|
+
const others = (config) => {
|
|
128
|
+
const copy = structuredClone(config);
|
|
129
|
+
for (const k of ["model", "model_provider", "model_context_window"])
|
|
130
|
+
delete copy[k];
|
|
131
|
+
const velqa = copy.model_providers?.velqa;
|
|
132
|
+
if (velqa)
|
|
133
|
+
for (const k of ["name", "base_url", "env_key", "wire_api"])
|
|
134
|
+
delete velqa[k];
|
|
135
|
+
if (velqa && Object.keys(velqa).length === 0)
|
|
136
|
+
delete copy.model_providers.velqa;
|
|
137
|
+
if (copy.model_providers && Object.keys(copy.model_providers).length === 0)
|
|
138
|
+
delete copy.model_providers;
|
|
139
|
+
return copy;
|
|
140
|
+
};
|
|
141
|
+
if (!isDeepStrictEqual(others(before), others(parsed)) ||
|
|
142
|
+
parsed.model_context_window !== modelLimit(model).context ||
|
|
143
|
+
parsed.model !== model ||
|
|
144
|
+
parsed.model_provider !== "velqa" ||
|
|
145
|
+
provider?.base_url !== OAI_BASE ||
|
|
146
|
+
provider?.env_key !== KEY_ENV ||
|
|
147
|
+
provider?.wire_api !== "responses") {
|
|
148
|
+
throw new Error(`the Codex config.toml has a layout this tool cannot edit safely; ${byHand}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* ~/.config/opencode/opencode.json(c): a `velqa` provider listing the key's chat
|
|
153
|
+
* models (key read from VELQA_API_KEY) and the chosen model as default. Written
|
|
154
|
+
* in opencode 1's `provider` format, which opencode 2 migrates at startup. The
|
|
155
|
+
* file is edited in place, so comments and unrelated settings survive, and
|
|
156
|
+
* fields the user added to the velqa entry or its models are kept.
|
|
157
|
+
*/
|
|
158
|
+
export function opencodeConfig(existing, models, model) {
|
|
159
|
+
let text = existing?.trim() ? existing : '{\n "$schema": "https://opencode.ai/config.json"\n}\n';
|
|
160
|
+
const errors = [];
|
|
161
|
+
const config = parseJsonc(text, errors, { allowTrailingComma: true });
|
|
162
|
+
if (errors.length)
|
|
163
|
+
throw new Error("the opencode config has a syntax error; fix it first (https://velqa.dev/docs/opencode)");
|
|
98
164
|
if (typeof config !== "object" || config === null || Array.isArray(config)) {
|
|
99
165
|
throw new Error("the opencode config is not a JSON object");
|
|
100
166
|
}
|
|
101
|
-
const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ?
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if ("velqa" in
|
|
120
|
-
|
|
121
|
-
if (Object.keys(
|
|
122
|
-
|
|
123
|
-
else
|
|
124
|
-
delete config[other];
|
|
167
|
+
const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
168
|
+
const root = record(config);
|
|
169
|
+
const previous = record(record(root.provider).velqa);
|
|
170
|
+
const previousModels = record(previous.models);
|
|
171
|
+
const velqa = {
|
|
172
|
+
...previous,
|
|
173
|
+
npm: "@ai-sdk/openai-compatible",
|
|
174
|
+
name: typeof previous.name === "string" ? previous.name : "Velqa",
|
|
175
|
+
options: { ...record(previous.options), baseURL: OAI_BASE, apiKey: `{env:${KEY_ENV}}` },
|
|
176
|
+
models: {
|
|
177
|
+
...previousModels,
|
|
178
|
+
...Object.fromEntries(models.map((id) => [id, { name: id, ...record(previousModels[id]), limit: modelLimit(id) }])),
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
const edit = (path, value) => {
|
|
182
|
+
text = applyEdits(text, modify(text, path, value, { formattingOptions: { insertSpaces: true, tabSize: 2 } }));
|
|
183
|
+
};
|
|
184
|
+
// An entry 0.1.0 wrote in opencode 2's `providers` format would shadow this one.
|
|
185
|
+
if ("velqa" in record(root.providers)) {
|
|
186
|
+
edit(["providers", "velqa"], undefined);
|
|
187
|
+
if (Object.keys(record(root.providers)).length === 1)
|
|
188
|
+
edit(["providers"], undefined);
|
|
125
189
|
}
|
|
126
|
-
|
|
127
|
-
|
|
190
|
+
edit(["provider", "velqa"], velqa);
|
|
191
|
+
edit(["model"], `velqa/${model}`);
|
|
192
|
+
return text.endsWith("\n") ? text : `${text}\n`;
|
|
128
193
|
}
|
|
129
194
|
const RC_START = "# >>> velqa >>>";
|
|
130
195
|
const RC_END = "# <<< velqa <<<";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "velqa",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Point Claude Code and Codex at Velqa's open-weight models in one command.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -27,5 +27,9 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
-
"homepage": "https://velqa.dev/docs/en/integrations-overview"
|
|
30
|
+
"homepage": "https://velqa.dev/docs/en/integrations-overview",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"jsonc-parser": "^3.3.1",
|
|
33
|
+
"smol-toml": "^1.9.1"
|
|
34
|
+
}
|
|
31
35
|
}
|