Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/proxy/schema/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,29 @@ describe("APISecretSchema compatibility", () => {
});
expect(result.success).toBe(false);
});

it("preserves passthrough behavior for legacy Ollama api_base values", () => {
const cases: Array<{ name: string; api_base: unknown }> = [
{ name: "invalid url string", api_base: "not a url" },
{ name: "bare hostname", api_base: "localhost" },
{ name: "number", api_base: 12345 },
{ name: "boolean", api_base: true },
{ name: "object", api_base: { nested: 1 } },
];

for (const { name, api_base } of cases) {
const parsed = APISecretSchema.parse({
secret: "ollama-secret",
type: "ollama",
metadata: { api_base },
});
if (parsed.type !== "ollama") {
throw new Error(`Expected ollama secret for case '${name}'`);
}
expect(
parsed.metadata?.api_base,
`case '${name}' should coerce to undefined to preserve runtime fallback`,
).toBeUndefined();
}
});
});
16 changes: 15 additions & 1 deletion packages/proxy/schema/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ export const MistralMetadataSchema = BaseMetadataSchema.merge(
}),
).passthrough();

export const OllamaMetadataSchema = BaseMetadataSchema.merge(
z.object({
api_base: z
.union([z.string().url(), z.string().length(0)])
.nullish()
.catch(undefined),
}),
).passthrough();

export const BraintrustMetadataSchema = BaseMetadataSchema.merge(
z.object({
api_base: z.union([z.string().url(), z.string().length(0)]).nullish(),
Expand All @@ -155,7 +164,6 @@ export const APISecretSchema = z.union([
"replicate",
"together",
"baseten",
"ollama",
"groq",
"lepton",
"fireworks",
Expand Down Expand Up @@ -208,6 +216,12 @@ export const APISecretSchema = z.union([
metadata: MistralMetadataSchema.nullish(),
}),
).passthrough(),
APISecretBaseSchema.merge(
z.object({
type: z.literal("ollama"),
metadata: OllamaMetadataSchema.nullish(),
}),
).passthrough(),
]);

export type APISecret = z.infer<typeof APISecretSchema>;
Expand Down
Loading