mirror of
https://github.com/sst/opencode.git
synced 2025-08-04 05:28:16 +00:00

Co-authored-by: GitHub Action <action@github.com> Co-authored-by: Liang-Shih Lin <liangshihlin@proton.me> Co-authored-by: Dominik Engelhardt <dominikengelhardt@ymail.com> Co-authored-by: Jay V <air@live.ca> Co-authored-by: adamdottv <2363879+adamdottv@users.noreply.github.com>
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import type { ModelMessage } from "ai"
|
|
import { unique } from "remeda"
|
|
|
|
export namespace ProviderTransform {
|
|
export function message(msgs: ModelMessage[], providerID: string, modelID: string) {
|
|
if (providerID === "anthropic" || modelID.includes("anthropic")) {
|
|
const system = msgs.filter((msg) => msg.role === "system").slice(0, 2)
|
|
const final = msgs.filter((msg) => msg.role !== "system").slice(-2)
|
|
|
|
for (const msg of unique([...system, ...final])) {
|
|
msg.providerOptions = {
|
|
...msg.providerOptions,
|
|
anthropic: {
|
|
cacheControl: { type: "ephemeral" },
|
|
},
|
|
openaiCompatible: {
|
|
cache_control: { type: "ephemeral" },
|
|
},
|
|
}
|
|
}
|
|
}
|
|
if (providerID === "amazon-bedrock" || modelID.includes("anthropic")) {
|
|
const system = msgs.filter((msg) => msg.role === "system").slice(0, 2)
|
|
const final = msgs.filter((msg) => msg.role !== "system").slice(-2)
|
|
|
|
for (const msg of unique([...system, ...final])) {
|
|
msg.providerOptions = {
|
|
...msg.providerOptions,
|
|
bedrock: {
|
|
cachePoint: { type: "ephemeral" },
|
|
},
|
|
}
|
|
}
|
|
}
|
|
return msgs
|
|
}
|
|
}
|