Skip to content
Closed
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
12 changes: 11 additions & 1 deletion packages/opencode/src/provider/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,18 @@ export namespace ProviderTransform {
}
}

if (input.model.providerID === "openai" || input.providerOptions?.setCacheKey) {
if (
input.model.providerID === "openai" ||
(
input.model.api.npm === "@ai-sdk/openai-compatible" &&
input.providerOptions?.setCacheKey !== false
) ||
input.providerOptions?.setCacheKey === true
) {
result["promptCacheKey"] = input.sessionID
if ("setCacheKey" in input.providerOptions) {
delete input.providerOptions["setCacheKey"]
}
}

if (input.model.api.npm === "@ai-sdk/google" || input.model.api.npm === "@ai-sdk/google-vertex") {
Expand Down
29 changes: 29 additions & 0 deletions packages/opencode/test/provider/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,35 @@ describe("ProviderTransform.options - setCacheKey", () => {
expect(result.promptCacheKey).toBe(sessionID)
})

test("should set promptCacheKey for openai-compatible provider when setCacheKey not present and setCacheKey not present", () => {
const openaiModel = {
...mockModel,
providerID: "openai-compatible",
api: {
id: "gpt-4",
url: "https://api.openai.com",
npm: "@ai-sdk/openai-compatible",
},
}
const result = ProviderTransform.options({ model: openaiModel, sessionID, providerOptions: {} })
expect(result.promptCacheKey).toBe(sessionID)
})

test("should not set promptCacheKey for openai-compatible provider when setCacheKey is false and setCacheKey not present in result", () => {
const openaiModel = {
...mockModel,
providerID: "openai-compatible",
api: {
id: "gpt-4",
url: "https://api.openai.com",
npm: "@ai-sdk/openai-compatible",
}
}
const result = ProviderTransform.options({ model: openaiModel, sessionID, providerOptions: { setCacheKey: false } })
expect(result.promptCacheKey).toBeUndefined()
})


test("should set store=false for openai provider", () => {
const openaiModel = {
...mockModel,
Expand Down
Loading