GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: improve xai cache hit rate (#35970) · moonug/opencode@ccb6b7c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • bun.lock
  • package.json
  • packages
    • core
      • package.json
      • test
        • provider-xai-responses.test.ts
    • opencode
      • package.json
      • src/provider
        • transform.ts
      • test/provider
        • transform.test.ts
  • patches
    • @ai-sdk%[email protected]
    • @ai-sdk%[email protected]
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎bun.lock‎

Copy file name to clipboardExpand all lines: bun.lock
+15-5Lines changed: 15 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎package.json‎

Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
"@silvia-odwyer/[email protected]": "patches/@silvia-odwyer%[email protected]",
148148
"@standard-community/[email protected]": "patches/@standard-community%[email protected]",
149149
"[email protected]": "patches/[email protected]",
150-
"@ai-sdk/[email protected].82": "patches/@ai-sdk%[email protected].82.patch",
150+
"@ai-sdk/[email protected].102": "patches/@ai-sdk%[email protected].102.patch",
151151
"[email protected]": "patches/[email protected]",
152152
"[email protected]": "patches/[email protected]",
153153
"@ai-sdk/[email protected]": "patches/@ai-sdk%[email protected]",
Collapse file

‎packages/core/package.json‎

Copy file name to clipboardExpand all lines: packages/core/package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"@ai-sdk/provider-utils": "4.0.23",
8181
"@ai-sdk/togetherai": "2.0.41",
8282
"@ai-sdk/vercel": "2.0.39",
83-
"@ai-sdk/xai": "3.0.82",
83+
"@ai-sdk/xai": "3.0.102",
8484
"@aws-sdk/credential-providers": "3.1057.0",
8585
"@effect/opentelemetry": "catalog:",
8686
"@effect/platform-node": "catalog:",
Collapse file

‎packages/core/test/provider-xai-responses.test.ts‎

Copy file name to clipboard
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { createXai } from "@ai-sdk/xai"
2+
import { expect, test } from "bun:test"
3+
4+
test("xAI Responses sends promptCacheKey as prompt_cache_key", async () => {
5+
let body: Record<string, unknown> | undefined
6+
const mockFetch = Object.assign(
7+
async (_input: Parameters<typeof fetch>[0], init?: RequestInit) => {
8+
body = JSON.parse(String(init?.body))
9+
return Response.json({
10+
id: "response-1",
11+
created_at: 0,
12+
model: "grok-4",
13+
object: "response",
14+
output: [],
15+
usage: { input_tokens: 1, output_tokens: 0 },
16+
status: "completed",
17+
})
18+
},
19+
{ preconnect: fetch.preconnect },
20+
)
21+
const model = createXai({
22+
apiKey: "test",
23+
fetch: mockFetch,
24+
}).responses("grok-4")
25+
26+
await model.doGenerate({
27+
prompt: [{ role: "user", content: [{ type: "text", text: "Hello" }] }],
28+
providerOptions: { xai: { promptCacheKey: "session-123" } },
29+
})
30+
31+
expect(body?.prompt_cache_key).toBe("session-123")
32+
})
Collapse file

‎packages/opencode/package.json‎

Copy file name to clipboardExpand all lines: packages/opencode/package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"@ai-sdk/provider": "3.0.8",
7474
"@ai-sdk/togetherai": "2.0.41",
7575
"@ai-sdk/vercel": "2.0.39",
76-
"@ai-sdk/xai": "3.0.82",
76+
"@ai-sdk/xai": "3.0.102",
7777
"@aws-sdk/credential-providers": "3.1057.0",
7878
"@clack/prompts": "1.0.0-alpha.1",
7979
"@effect/opentelemetry": "catalog:",
Collapse file

‎packages/opencode/src/provider/transform.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/provider/transform.ts
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,12 @@ export function options(input: {
11271127
}
11281128
}
11291129

1130-
if (input.model.providerID === "openai" || input.providerOptions?.setCacheKey) {
1130+
if (
1131+
input.providerOptions?.setCacheKey !== false &&
1132+
(input.model.providerID === "openai" ||
1133+
input.model.api.npm === "@ai-sdk/xai" ||
1134+
input.providerOptions?.setCacheKey)
1135+
) {
11311136
result["promptCacheKey"] = input.sessionID
11321137
}
11331138

Collapse file

‎packages/opencode/test/provider/transform.test.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/test/provider/transform.test.ts
+51-1Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe("ProviderTransform.options - setCacheKey", () => {
7373
expect(result.promptCacheKey).toBeUndefined()
7474
})
7575

76-
test("should set promptCacheKey for openai provider regardless of setCacheKey", () => {
76+
test("should set promptCacheKey for openai provider by default", () => {
7777
const openaiModel = {
7878
...mockModel,
7979
providerID: "openai",
@@ -87,6 +87,56 @@ describe("ProviderTransform.options - setCacheKey", () => {
8787
expect(result.promptCacheKey).toBe(sessionID)
8888
})
8989

90+
test("should not set promptCacheKey for openai when explicitly disabled", () => {
91+
const openaiModel = {
92+
...mockModel,
93+
providerID: "openai",
94+
api: {
95+
id: "gpt-4",
96+
url: "https://api.openai.com",
97+
npm: "@ai-sdk/openai",
98+
},
99+
}
100+
const result = ProviderTransform.options({
101+
model: openaiModel,
102+
sessionID,
103+
providerOptions: { setCacheKey: false },
104+
})
105+
expect(result.promptCacheKey).toBeUndefined()
106+
})
107+
108+
test("should set promptCacheKey for the xAI SDK by default regardless of provider ID", () => {
109+
const xaiModel = {
110+
...mockModel,
111+
providerID: "custom-xai",
112+
api: {
113+
id: "grok-4",
114+
url: "https://api.x.ai",
115+
npm: "@ai-sdk/xai",
116+
},
117+
}
118+
const result = ProviderTransform.options({ model: xaiModel, sessionID, providerOptions: {} })
119+
expect(result.promptCacheKey).toBe(sessionID)
120+
})
121+
122+
test("should not set promptCacheKey for the xAI SDK when explicitly disabled", () => {
123+
const xaiModel = {
124+
...mockModel,
125+
providerID: "xai",
126+
api: {
127+
id: "grok-4",
128+
url: "https://api.x.ai",
129+
npm: "@ai-sdk/xai",
130+
},
131+
}
132+
const result = ProviderTransform.options({
133+
model: xaiModel,
134+
sessionID,
135+
providerOptions: { setCacheKey: false },
136+
})
137+
expect(result.promptCacheKey).toBeUndefined()
138+
})
139+
90140
test("should set store=false for openai provider", () => {
91141
const openaiModel = {
92142
...mockModel,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.