fix: fix the itemId stripping logic, this time it should fix that id issue w/ gpt models fr

This commit is contained in:
Aiden Cline
2026-01-16 11:32:12 -06:00
parent 9a48f8e9e3
commit 40836e9683
2 changed files with 88 additions and 4 deletions

View File

@@ -24,15 +24,23 @@ export namespace ProviderTransform {
// Strip openai itemId metadata following what codex does
if (model.api.npm === "@ai-sdk/openai" || options.store === false) {
msgs = msgs.map((msg) => {
if (msg.providerOptions?.openai) {
delete msg.providerOptions.openai["itemId"]
if (msg.providerOptions) {
for (const options of Object.values(msg.providerOptions)) {
if (options && typeof options === "object") {
delete options["itemId"]
}
}
}
if (!Array.isArray(msg.content)) {
return msg
}
const content = msg.content.map((part) => {
if (part.providerOptions?.openai) {
delete part.providerOptions.openai["itemId"]
if (part.providerOptions) {
for (const options of Object.values(part.providerOptions)) {
if (options && typeof options === "object") {
delete options["itemId"]
}
}
}
return part
})

View File

@@ -805,6 +805,82 @@ describe("ProviderTransform.message - strip openai metadata when store=false", (
expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
})
test("strips metadata using providerID key when store is false", () => {
const opencodeModel = {
...openaiModel,
providerID: "opencode",
api: {
id: "opencode-test",
url: "https://api.opencode.ai",
npm: "@ai-sdk/openai-compatible",
},
}
const msgs = [
{
role: "assistant",
content: [
{
type: "text",
text: "Hello",
providerOptions: {
opencode: {
itemId: "msg_123",
otherOption: "value",
},
},
},
],
},
] as any[]
const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
expect(result[0].content[0].providerOptions?.opencode?.itemId).toBeUndefined()
expect(result[0].content[0].providerOptions?.opencode?.otherOption).toBe("value")
})
test("strips itemId across all providerOptions keys", () => {
const opencodeModel = {
...openaiModel,
providerID: "opencode",
api: {
id: "opencode-test",
url: "https://api.opencode.ai",
npm: "@ai-sdk/openai-compatible",
},
}
const msgs = [
{
role: "assistant",
providerOptions: {
openai: { itemId: "msg_root" },
opencode: { itemId: "msg_opencode" },
extra: { itemId: "msg_extra" },
},
content: [
{
type: "text",
text: "Hello",
providerOptions: {
openai: { itemId: "msg_openai_part" },
opencode: { itemId: "msg_opencode_part" },
extra: { itemId: "msg_extra_part" },
},
},
],
},
] as any[]
const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
expect(result[0].providerOptions?.openai?.itemId).toBeUndefined()
expect(result[0].providerOptions?.opencode?.itemId).toBeUndefined()
expect(result[0].providerOptions?.extra?.itemId).toBeUndefined()
expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
expect(result[0].content[0].providerOptions?.opencode?.itemId).toBeUndefined()
expect(result[0].content[0].providerOptions?.extra?.itemId).toBeUndefined()
})
test("does not strip metadata for non-openai packages when store is not false", () => {
const anthropicModel = {
...openaiModel,