mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-24 06:45:22 +00:00
wip
This commit is contained in:
1
ai
Submodule
1
ai
Submodule
Submodule ai added at 6414c01078
1
codex
Submodule
1
codex
Submodule
Submodule codex added at c26fe64539
@@ -1006,6 +1006,26 @@ export namespace Provider {
|
||||
})
|
||||
}
|
||||
|
||||
// Wrap fetch for @ai-sdk/openai to strip "id" from reasoning blocks
|
||||
// Strip openai itemId metadata following what codex does
|
||||
if (model.api.npm === "@ai-sdk/openai") {
|
||||
const wrappedFetch = options["fetch"]
|
||||
options["fetch"] = async (url: any, init?: BunFetchRequestInit) => {
|
||||
if (init?.body && init.method === "POST") {
|
||||
const body = JSON.parse(init.body as string)
|
||||
if (Array.isArray(body.input)) {
|
||||
for (const item of body.input) {
|
||||
if (item.type === "reasoning" && "id" in item) {
|
||||
delete item.id
|
||||
}
|
||||
}
|
||||
}
|
||||
init = { ...init, body: JSON.stringify(body) }
|
||||
}
|
||||
return wrappedFetch(url, init)
|
||||
}
|
||||
}
|
||||
|
||||
// Special case: google-vertex-anthropic uses a subpath import
|
||||
const bundledKey =
|
||||
model.providerID === "google-vertex-anthropic" ? "@ai-sdk/google-vertex/anthropic" : model.api.npm
|
||||
|
||||
@@ -21,28 +21,27 @@ export namespace ProviderTransform {
|
||||
model: Provider.Model,
|
||||
options: Record<string, unknown>,
|
||||
): ModelMessage[] {
|
||||
// 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) {
|
||||
for (const options of Object.values(msg.providerOptions)) {
|
||||
delete options["itemId"]
|
||||
}
|
||||
}
|
||||
if (!Array.isArray(msg.content)) {
|
||||
return msg
|
||||
}
|
||||
const content = msg.content.map((part) => {
|
||||
if (part.providerOptions) {
|
||||
for (const options of Object.values(part.providerOptions)) {
|
||||
delete options["itemId"]
|
||||
}
|
||||
}
|
||||
return part
|
||||
})
|
||||
return { ...msg, content } as typeof msg
|
||||
})
|
||||
}
|
||||
// if (model.api.npm === "@ai-sdk/openai" || options.store === false) {
|
||||
// msgs = msgs.map((msg) => {
|
||||
// if (msg.providerOptions) {
|
||||
// for (const options of Object.values(msg.providerOptions)) {
|
||||
// delete options["itemId"]
|
||||
// }
|
||||
// }
|
||||
// if (!Array.isArray(msg.content)) {
|
||||
// return msg
|
||||
// }
|
||||
// const content = msg.content.map((part) => {
|
||||
// if (part.providerOptions) {
|
||||
// for (const options of Object.values(part.providerOptions)) {
|
||||
// delete options["itemId"]
|
||||
// }
|
||||
// }
|
||||
// return part
|
||||
// })
|
||||
// return { ...msg, content } as typeof msg
|
||||
// })
|
||||
// }
|
||||
|
||||
// Anthropic rejects messages with empty content - filter out empty string messages
|
||||
// and remove empty text/reasoning parts from array content
|
||||
|
||||
@@ -478,10 +478,7 @@ export namespace MessageV2 {
|
||||
if (msg.info.role === "assistant") {
|
||||
if (
|
||||
msg.info.error &&
|
||||
!(
|
||||
MessageV2.AbortedError.isInstance(msg.info.error) &&
|
||||
msg.parts.some((part) => part.type !== "step-start" && part.type !== "reasoning")
|
||||
)
|
||||
!(MessageV2.AbortedError.isInstance(msg.info.error) && msg.parts.some((part) => part.type !== "step-start"))
|
||||
) {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user