| 48 | } |
| 49 | |
| 50 | function statusWithFetch( |
| 51 | input: Pick<StreamInput, "model" | "provider" | "auth">, |
| 52 | fetch: typeof globalThis.fetch | undefined, |
| 53 | ): RuntimeStatus { |
| 54 | const providerID = input.model.providerID |
| 55 | if (providerID !== "openai" && providerID !== "anthropic" && !providerID.startsWith("opencode")) |
| 56 | return { type: "unsupported", reason: "provider is not openai, opencode, or anthropic" } |
| 57 | const npm = input.model.api.npm |
| 58 | if (npm !== "@ai-sdk/openai" && npm !== "@ai-sdk/openai-compatible" && npm !== "@ai-sdk/anthropic") |
| 59 | return { type: "unsupported", reason: "provider package is not OpenAI, OpenAI-compatible, or Anthropic" } |
| 60 | if (input.auth?.type === "oauth" && !(input.provider.id === "openai" && fetch)) { |
| 61 | return { type: "unsupported", reason: "OAuth auth requires a provider fetch override" } |
| 62 | } |
| 63 | |
| 64 | const apiKey = typeof input.provider.options.apiKey === "string" ? input.provider.options.apiKey : input.provider.key |
| 65 | if (!apiKey) return { type: "unsupported", reason: "API key is not configured" } |
| 66 | |
| 67 | return { |
| 68 | type: "supported", |
| 69 | apiKey, |
| 70 | baseURL: typeof input.provider.options.baseURL === "string" ? input.provider.options.baseURL : undefined, |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | export function stream(input: StreamInput): StreamResult { |
| 75 | const fetch = providerFetch(input) |