pennyrouter 0.2.31 → 0.2.33
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/package.json +1 -1
- package/src/harnesses/opencode.js +12 -0
- package/src/harnesses/opencode.test.js +3 -0
- package/src/launch.js +17 -1
- package/src/launch.test.js +7 -0
package/package.json
CHANGED
|
@@ -53,6 +53,12 @@ export const opencodeHarness = {
|
|
|
53
53
|
const backupPath = await backupFile(configPath, "opencode");
|
|
54
54
|
const current = await readConfig(configPath);
|
|
55
55
|
current.provider ||= {};
|
|
56
|
+
current.enabled_providers = Array.isArray(current.enabled_providers)
|
|
57
|
+
? current.enabled_providers
|
|
58
|
+
: [];
|
|
59
|
+
if (!current.enabled_providers.includes("pennyrouter")) {
|
|
60
|
+
current.enabled_providers.push("pennyrouter");
|
|
61
|
+
}
|
|
56
62
|
current.provider.pennyrouter = {
|
|
57
63
|
npm: "@ai-sdk/openai-compatible",
|
|
58
64
|
name: "PennyRouter",
|
|
@@ -97,6 +103,12 @@ export const opencodeHarness = {
|
|
|
97
103
|
|
|
98
104
|
async uninstall(record) {
|
|
99
105
|
const current = await readConfig(record.config_path);
|
|
106
|
+
if (Array.isArray(current.enabled_providers)) {
|
|
107
|
+
current.enabled_providers = current.enabled_providers.filter(
|
|
108
|
+
(provider) => provider !== "pennyrouter",
|
|
109
|
+
);
|
|
110
|
+
if (current.enabled_providers.length === 0) delete current.enabled_providers;
|
|
111
|
+
}
|
|
100
112
|
if (current.provider?.pennyrouter) delete current.provider.pennyrouter;
|
|
101
113
|
if (current.provider && Object.keys(current.provider).length === 0) delete current.provider;
|
|
102
114
|
await atomicWrite(record.config_path, `${JSON.stringify(current, null, 2)}\n`);
|
|
@@ -18,6 +18,7 @@ async function main() {
|
|
|
18
18
|
fs.writeFileSync(configPath, [
|
|
19
19
|
"{",
|
|
20
20
|
' "$schema": "https://opencode.ai/config.json",',
|
|
21
|
+
' "enabled_providers": ["custom"],',
|
|
21
22
|
' "provider": {',
|
|
22
23
|
' "custom": { "models": { "model-a": {} } },',
|
|
23
24
|
" },",
|
|
@@ -43,6 +44,7 @@ async function main() {
|
|
|
43
44
|
});
|
|
44
45
|
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
45
46
|
assert.equal(config.provider.custom.models["model-a"] !== undefined, true);
|
|
47
|
+
assert.deepEqual(config.enabled_providers, ["custom", "pennyrouter"]);
|
|
46
48
|
assert.deepEqual(Object.keys(config.provider.pennyrouter.models), OPENCODE_MODEL_CHOICES.map((model) => model.id));
|
|
47
49
|
assert.equal(config.provider.pennyrouter.options.baseURL, "https://api.pennyrouter.com/v1");
|
|
48
50
|
assert.deepEqual(JSON.parse(fs.readFileSync(modelStatePath, "utf8")).recent, ["custom/model-a"]);
|
|
@@ -50,6 +52,7 @@ async function main() {
|
|
|
50
52
|
await opencodeHarness.uninstall(record);
|
|
51
53
|
const restored = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
52
54
|
assert.equal(restored.provider.pennyrouter, undefined);
|
|
55
|
+
assert.deepEqual(restored.enabled_providers, ["custom"]);
|
|
53
56
|
assert.deepEqual(restored.provider.custom.models, { "model-a": {} });
|
|
54
57
|
const model = JSON.parse(fs.readFileSync(modelStatePath, "utf8"));
|
|
55
58
|
assert.deepEqual(model.recent, ["custom/model-a"]);
|
package/src/launch.js
CHANGED
|
@@ -523,6 +523,22 @@ function assertNoConflictingArgs(harness, args) {
|
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
+
const CLAUDE_AUTH_STARTUP_MODES = new Set(["auto", "proxy", "sub", "api", "openrouter"]);
|
|
527
|
+
|
|
528
|
+
function rewriteClaudeAuthStartup(args) {
|
|
529
|
+
// `claude <prompt>` submits the positional argument as the first user turn. Convert the
|
|
530
|
+
// convenient `penny claude proxy` spelling into the managed in-band command before Claude
|
|
531
|
+
// starts, so Claude receives a real @penny command rather than the literal word "proxy".
|
|
532
|
+
if (args.length === 1 && CLAUDE_AUTH_STARTUP_MODES.has(args[0].toLowerCase())) {
|
|
533
|
+
return [`@penny auth ${args[0].toLowerCase()}`];
|
|
534
|
+
}
|
|
535
|
+
if (args.length === 2 && args[0].toLowerCase() === "auth"
|
|
536
|
+
&& CLAUDE_AUTH_STARTUP_MODES.has(args[1].toLowerCase())) {
|
|
537
|
+
return [`@penny auth ${args[1].toLowerCase()}`];
|
|
538
|
+
}
|
|
539
|
+
return args;
|
|
540
|
+
}
|
|
541
|
+
|
|
526
542
|
export function buildPennyInvocation(harness, args, config) {
|
|
527
543
|
const item = config.harnesses?.[harness];
|
|
528
544
|
if (!item || !item.enabled) {
|
|
@@ -551,7 +567,7 @@ export function buildPennyInvocation(harness, args, config) {
|
|
|
551
567
|
delete env.CLAUDE_CODE_MAX_CONTEXT_TOKENS;
|
|
552
568
|
return {
|
|
553
569
|
command: "claude",
|
|
554
|
-
args: ["--settings", claudeLaunchSettingsPath(), ...args],
|
|
570
|
+
args: ["--settings", claudeLaunchSettingsPath(), ...rewriteClaudeAuthStartup(args)],
|
|
555
571
|
env,
|
|
556
572
|
};
|
|
557
573
|
}
|
package/src/launch.test.js
CHANGED
|
@@ -119,6 +119,13 @@ async function main() {
|
|
|
119
119
|
assert.equal(claude.env.ANTHROPIC_DEFAULT_HAIKU_MODEL_DESCRIPTION, "Fast, economical Claude model · 200K context");
|
|
120
120
|
assert.equal(claude.env.CLAUDE_CODE_MAX_CONTEXT_TOKENS, undefined);
|
|
121
121
|
|
|
122
|
+
const proxyStartup = buildPennyInvocation("claude", ["proxy"], config);
|
|
123
|
+
assert.deepEqual(proxyStartup.args.slice(-1), ["@penny auth proxy"]);
|
|
124
|
+
const apiStartup = buildPennyInvocation("claude", ["auth", "api"], config);
|
|
125
|
+
assert.deepEqual(apiStartup.args.slice(-1), ["@penny auth api"]);
|
|
126
|
+
const normalPrompt = buildPennyInvocation("claude", ["proxy", "please"], config);
|
|
127
|
+
assert.deepEqual(normalPrompt.args.slice(-2), ["proxy", "please"]);
|
|
128
|
+
|
|
122
129
|
const codex = buildPennyInvocation("codex", ["resume", "--last"], config);
|
|
123
130
|
assert.deepEqual(codex.args, ["--profile", "pennyrouter", "resume", "--last"]);
|
|
124
131
|
assert.equal(codex.env.PENNYROUTER_API_KEY, "pr-super-secret");
|