(model: Model, s: State, envs: Record<string, string | undefined>)
| 1637 | const list = Effect.fn("Provider.list")(() => InstanceState.use(state, (s) => s.providers)) |
| 1638 | |
| 1639 | async function resolveSDK(model: Model, s: State, envs: Record<string, string | undefined>) { |
| 1640 | try { |
| 1641 | const provider = s.providers[model.providerID] |
| 1642 | const options = { ...provider.options } |
| 1643 | |
| 1644 | if ( |
| 1645 | model.providerID === "google-vertex" && |
| 1646 | model.api.npm === "@ai-sdk/google-vertex/anthropic" && |
| 1647 | !options.baseURL |
| 1648 | ) { |
| 1649 | const baseURL = googleVertexAnthropicBaseURL( |
| 1650 | typeof options.project === "string" ? options.project : undefined, |
| 1651 | typeof options.location === "string" ? options.location : undefined, |
| 1652 | ) |
| 1653 | if (baseURL) options.baseURL = baseURL |
| 1654 | } |
| 1655 | |
| 1656 | if (model.providerID === "google-vertex" && !model.api.npm.includes("@ai-sdk/openai-compatible")) { |
| 1657 | delete options.fetch |
| 1658 | } |
| 1659 | |
| 1660 | if (model.api.npm.includes("@ai-sdk/openai-compatible") && options["includeUsage"] !== false) { |
| 1661 | options["includeUsage"] = true |
| 1662 | } |
| 1663 | |
| 1664 | const baseURL = iife(() => { |
| 1665 | let url = |
| 1666 | typeof options["baseURL"] === "string" && options["baseURL"] !== "" ? options["baseURL"] : model.api.url |
| 1667 | if (!url) return |
| 1668 | |
| 1669 | const loader = s.varsLoaders[model.providerID] |
| 1670 | if (loader) { |
| 1671 | const vars = loader(options) |
| 1672 | for (const [key, value] of Object.entries(vars)) { |
| 1673 | const field = "${" + key + "}" |
| 1674 | url = url.replaceAll(field, value) |
| 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | url = url.replace(/\$\{([^}]+)\}/g, (item, key) => { |
| 1679 | const val = envs[String(key)] |
| 1680 | return val ?? item |
| 1681 | }) |
| 1682 | return url |
| 1683 | }) |
| 1684 | |
| 1685 | if (baseURL !== undefined) options["baseURL"] = baseURL |
| 1686 | if (options["apiKey"] === undefined && provider.key) options["apiKey"] = provider.key |
| 1687 | if (model.headers) |
| 1688 | options["headers"] = { |
| 1689 | ...options["headers"], |
| 1690 | ...model.headers, |
| 1691 | } |
| 1692 | |
| 1693 | const key = Hash.fast( |
| 1694 | JSON.stringify({ |
| 1695 | providerID: model.providerID, |
| 1696 | npm: model.api.npm, |
no test coverage detected