oh-pi 0.1.79 → 0.1.80
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/dist/utils/writers.js +12 -3
- package/dist/utils/writers.test.js +35 -0
- package/package.json +1 -1
package/dist/utils/writers.js
CHANGED
|
@@ -88,16 +88,25 @@ export function writeModelConfig(agentDir, config) {
|
|
|
88
88
|
return;
|
|
89
89
|
const strategy = config.providerStrategy ?? "replace";
|
|
90
90
|
const modelsPath = join(agentDir, "models.json");
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
// Persist custom endpoints and API mode overrides (e.g. built-in OpenAI responses/completions choice).
|
|
92
|
+
const modelProviders = config.providers.filter(p => p.baseUrl || (!!p.api && !!PROVIDERS[p.name]));
|
|
93
|
+
if (modelProviders.length === 0)
|
|
93
94
|
return;
|
|
94
95
|
const providers = strategy === "add"
|
|
95
96
|
? (readJson(modelsPath)?.providers ?? {})
|
|
96
97
|
: {};
|
|
97
|
-
for (const cp of
|
|
98
|
+
for (const cp of modelProviders) {
|
|
98
99
|
const isBuiltin = !!PROVIDERS[cp.name];
|
|
100
|
+
if (!cp.baseUrl && isBuiltin && cp.api) {
|
|
101
|
+
providers[cp.name] = { api: cp.api };
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (!cp.baseUrl)
|
|
105
|
+
continue;
|
|
99
106
|
if (isBuiltin && !cp.discoveredModels?.length) {
|
|
100
107
|
const entry = { baseUrl: cp.baseUrl };
|
|
108
|
+
if (cp.api)
|
|
109
|
+
entry.api = cp.api;
|
|
101
110
|
if (cp.apiKey !== "none")
|
|
102
111
|
entry.apiKey = cp.apiKey;
|
|
103
112
|
providers[cp.name] = entry;
|
|
@@ -107,6 +107,41 @@ describe("provider keep strategy", () => {
|
|
|
107
107
|
expect(text).toContain("\"custom-openai\"");
|
|
108
108
|
expect(text).toContain("\"openai-responses\"");
|
|
109
109
|
});
|
|
110
|
+
it("writeModelConfig persists API mode for builtin OpenAI without custom baseUrl", () => {
|
|
111
|
+
const dir = makeTempDir();
|
|
112
|
+
writeModelConfig(dir, makeConfig({
|
|
113
|
+
providerStrategy: "replace",
|
|
114
|
+
providers: [{
|
|
115
|
+
name: "openai",
|
|
116
|
+
apiKey: "OPENAI_API_KEY",
|
|
117
|
+
defaultModel: "gpt-5",
|
|
118
|
+
api: "openai-responses",
|
|
119
|
+
}],
|
|
120
|
+
}));
|
|
121
|
+
const modelsPath = join(dir, "models.json");
|
|
122
|
+
expect(existsSync(modelsPath)).toBe(true);
|
|
123
|
+
const models = JSON.parse(readFileSync(modelsPath, "utf8"));
|
|
124
|
+
expect(models.providers.openai.api).toBe("openai-responses");
|
|
125
|
+
expect(models.providers.openai.baseUrl).toBeUndefined();
|
|
126
|
+
});
|
|
127
|
+
it("writeModelConfig keeps API mode when overriding builtin baseUrl without discovered models", () => {
|
|
128
|
+
const dir = makeTempDir();
|
|
129
|
+
writeModelConfig(dir, makeConfig({
|
|
130
|
+
providerStrategy: "replace",
|
|
131
|
+
providers: [{
|
|
132
|
+
name: "openai",
|
|
133
|
+
apiKey: "OPENAI_API_KEY",
|
|
134
|
+
baseUrl: "https://api.openai.com/v1",
|
|
135
|
+
defaultModel: "gpt-4o",
|
|
136
|
+
api: "openai-responses",
|
|
137
|
+
}],
|
|
138
|
+
}));
|
|
139
|
+
const modelsPath = join(dir, "models.json");
|
|
140
|
+
expect(existsSync(modelsPath)).toBe(true);
|
|
141
|
+
const models = JSON.parse(readFileSync(modelsPath, "utf8"));
|
|
142
|
+
expect(models.providers.openai.baseUrl).toBe("https://api.openai.com/v1");
|
|
143
|
+
expect(models.providers.openai.api).toBe("openai-responses");
|
|
144
|
+
});
|
|
110
145
|
it("writeProviderEnv merges auth/settings when strategy is add", () => {
|
|
111
146
|
const dir = makeTempDir();
|
|
112
147
|
const settingsPath = join(dir, "settings.json");
|