diff --git a/packages/opencode/src/provider/transform.ts b/packages/opencode/src/provider/transform.ts index 117eb4b9c29db..2b420179c63e3 100644 --- a/packages/opencode/src/provider/transform.ts +++ b/packages/opencode/src/provider/transform.ts @@ -22,6 +22,9 @@ export const OUTPUT_TOKEN_MAX = 32_000 // branch that requests it stays in lockstep. const INCLUDE_ENCRYPTED_REASONING = ["reasoning.encrypted_content"] as const +const SAP_AI_CORE_PACKAGE = "@jerome-benoit/sap-ai-provider" +const LEGACY_SAP_AI_CORE_PACKAGE = "@jerome-benoit/sap-ai-provider-v2" + export function sanitizeSurrogates(content: string) { return content.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(? }), ) +it.instance( + "keeps the existing SAP V3 root instead of switching to the V2 facade", + Effect.gen(function* () { + const name = "@jerome-benoit/sap-ai-provider" + // The test preload isolates the npm cache and removes it after the run. + for (const [specifier, hasV2] of [ + [name, false], + [`${name}@^5.0.0`, true], + ] as const) { + const directory = path.join(Global.Path.cache, "packages", Npm.sanitize(specifier), "node_modules", name) + yield* Effect.promise(async () => { + await Bun.write( + path.join(directory, "package.json"), + JSON.stringify({ name, exports: hasV2 ? { ".": "./index.cjs", "./v2": "./v2.cjs" } : "./index.cjs" }), + ) + for (const [file, version] of hasV2 ? [["index.cjs", "v3"], ["v2.cjs", "v2"]] : [["index.cjs", "v3"]]) { + await Bun.write( + path.join(directory, file), + `const model = () => ({ specificationVersion: "${version}" }) +exports.createSAPAIProvider = () => Object.assign(model, { languageModel: model })`, + ) + } + }) + } + + const provider = yield* Provider.Service + const model = yield* provider.getModel(ProviderV2.ID.make("sap-ai-core"), ModelV2.ID.make("gpt-5")) + const language = yield* provider.getLanguage(model) + expect(language).toMatchObject({ specificationVersion: "v3" }) + }), + { + config: { + provider: { + "sap-ai-core": { + npm: "@jerome-benoit/sap-ai-provider", + models: { "gpt-5": { name: "GPT-5" } }, + options: { apiKey: "test-key" }, + }, + }, + }, + }, +) + it.instance("getModel throws ModelNotFoundError for invalid model", () => Effect.gen(function* () { yield* set("ANTHROPIC_API_KEY", "test-api-key") diff --git a/packages/opencode/test/provider/transform.test.ts b/packages/opencode/test/provider/transform.test.ts index cf42346716eab..e3eaa2f5eab60 100644 --- a/packages/opencode/test/provider/transform.test.ts +++ b/packages/opencode/test/provider/transform.test.ts @@ -3944,6 +3944,24 @@ describe("ProviderTransform.reasoningVariants", () => { ) }) + test.each(["@jerome-benoit/sap-ai-provider-v2", "@jerome-benoit/sap-ai-provider"])( + "converts SAP AI Core catalog effort and budget for %s", + (npm) => { + expect( + ProviderTransform.reasoningVariants(model([{ type: "effort", values: ["high"] }]), target(npm, "gpt-5")), + ).toEqual({ high: { modelParams: { reasoning_effort: "high" } } }) + expect( + ProviderTransform.reasoningVariants( + model([{ type: "budget_tokens", min: 0, max: 16_000 }]), + target(npm, "gemini-2.5-flash"), + ), + ).toEqual({ + high: { modelParams: { thinkingConfig: { includeThoughts: true, thinkingBudget: 8_000 } } }, + max: { modelParams: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16_000 } } }, + }) + }, + ) + test.each(["luna", "sol", "terra"])("serializes Bedrock GPT-5.6 %s none effort", async (name) => { const item = target("@ai-sdk/amazon-bedrock", `global.openai.gpt-5.6-${name}`) const variants = ProviderTransform.reasoningVariants( @@ -5874,7 +5892,7 @@ describe("ProviderTransform.variants", () => { }) }) - describe("@jerome-benoit/sap-ai-provider-v2", () => { + describe.each(["@jerome-benoit/sap-ai-provider-v2", "@jerome-benoit/sap-ai-provider"])("%s", (npm) => { const sapModel = (apiId: string, releaseDate = "2024-01-01") => createMockModel({ id: `sap-ai-core/${apiId}`, @@ -5882,7 +5900,7 @@ describe("ProviderTransform.variants", () => { api: { id: apiId, url: "https://api.ai.sap", - npm: "@jerome-benoit/sap-ai-provider-v2", + npm, }, release_date: releaseDate, })