fix: fix the itemId stripping logic, this time it should fix that id issue w/ gpt models fr
This commit is contained in:
@@ -24,15 +24,23 @@ export namespace ProviderTransform {
|
|||||||
// Strip openai itemId metadata following what codex does
|
// Strip openai itemId metadata following what codex does
|
||||||
if (model.api.npm === "@ai-sdk/openai" || options.store === false) {
|
if (model.api.npm === "@ai-sdk/openai" || options.store === false) {
|
||||||
msgs = msgs.map((msg) => {
|
msgs = msgs.map((msg) => {
|
||||||
if (msg.providerOptions?.openai) {
|
if (msg.providerOptions) {
|
||||||
delete msg.providerOptions.openai["itemId"]
|
for (const options of Object.values(msg.providerOptions)) {
|
||||||
|
if (options && typeof options === "object") {
|
||||||
|
delete options["itemId"]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!Array.isArray(msg.content)) {
|
if (!Array.isArray(msg.content)) {
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
const content = msg.content.map((part) => {
|
const content = msg.content.map((part) => {
|
||||||
if (part.providerOptions?.openai) {
|
if (part.providerOptions) {
|
||||||
delete part.providerOptions.openai["itemId"]
|
for (const options of Object.values(part.providerOptions)) {
|
||||||
|
if (options && typeof options === "object") {
|
||||||
|
delete options["itemId"]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return part
|
return part
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -805,6 +805,82 @@ describe("ProviderTransform.message - strip openai metadata when store=false", (
|
|||||||
expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
|
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", () => {
|
test("does not strip metadata for non-openai packages when store is not false", () => {
|
||||||
const anthropicModel = {
|
const anthropicModel = {
|
||||||
...openaiModel,
|
...openaiModel,
|
||||||
|
|||||||
Reference in New Issue
Block a user