MCPcopy Index your code
hub / github.com/anomalyco/opencode / custom

Function custom

packages/opencode/src/provider/provider.ts:168–950  ·  view source on GitHub ↗
(dep: CustomDep)

Source from the content-addressed store, hash-verified

166}
167
168function custom(dep: CustomDep): Record<string, CustomLoader> {
169 return {
170 anthropic: () =>
171 Effect.succeed({
172 autoload: false,
173 options: {
174 headers: {
175 "anthropic-beta": "interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14",
176 },
177 },
178 }),
179 opencode: Effect.fnUntraced(function* (input: Info) {
180 const env = yield* dep.env()
181 const hasKey = iife(() => {
182 if (input.env.some((item) => env[item])) return true
183 return false
184 })
185 const ok =
186 hasKey ||
187 Boolean(yield* dep.auth(input.id)) ||
188 Boolean((yield* dep.config()).provider?.["opencode"]?.options?.apiKey)
189
190 if (!ok) {
191 for (const [key, value] of Object.entries(input.models)) {
192 if (value.cost.input === 0) continue
193 delete input.models[key]
194 }
195 }
196
197 return {
198 autoload: Object.keys(input.models).length > 0,
199 options: ok ? {} : { apiKey: "public" },
200 }
201 }),
202 openai: () =>
203 Effect.succeed({
204 autoload: false,
205 async getModel(sdk: any, modelID: string, _options?: Record<string, any>) {
206 return sdk.responses(modelID)
207 },
208 options: { headerTimeout: OPENAI_HEADER_TIMEOUT_DEFAULT },
209 }),
210 xai: () =>
211 Effect.succeed({
212 autoload: false,
213 async getModel(sdk: any, modelID: string, _options?: Record<string, any>) {
214 return sdk.responses(modelID)
215 },
216 options: {},
217 }),
218 "github-copilot": () =>
219 Effect.succeed({
220 autoload: false,
221 async getModel(sdk: any, modelID: string, _options?: Record<string, any>) {
222 if (sdk.responses === undefined && sdk.chat === undefined) return sdk.languageModel(modelID)
223 const match = /^gpt-(\d+)/.exec(modelID)
224 if (match && Number(match[1]) >= 5 && !modelID.startsWith("gpt-5-mini")) return sdk.responses(modelID)
225 return sdk.chat(modelID)

Callers 1

provider.tsFile · 0.70

Calls 15

iifeFunction · 0.90
createAiGatewayFunction · 0.85
createUnifiedFunction · 0.85
getClientMethod · 0.80
getAccessTokenMethod · 0.80
cloneMethod · 0.80
envMethod · 0.65
findMethod · 0.65
getMethod · 0.65
jsonMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected