mirror of
https://github.com/sst/opencode.git
synced 2025-08-31 02:07:24 +00:00
fix codex not working
This commit is contained in:
parent
4dbc6a43a6
commit
3d02e07161
1 changed files with 31 additions and 13 deletions
|
@ -28,20 +28,21 @@ import { TaskTool } from "../tool/task"
|
||||||
export namespace Provider {
|
export namespace Provider {
|
||||||
const log = Log.create({ service: "provider" })
|
const log = Log.create({ service: "provider" })
|
||||||
|
|
||||||
type CustomLoader = (provider: ModelsDev.Provider) => Promise<
|
type CustomLoader = (
|
||||||
| {
|
provider: ModelsDev.Provider,
|
||||||
getModel?: (sdk: any, modelID: string) => Promise<any>
|
api?: string,
|
||||||
options: Record<string, any>
|
) => Promise<{
|
||||||
}
|
autoload: boolean
|
||||||
| false
|
getModel?: (sdk: any, modelID: string) => Promise<any>
|
||||||
>
|
options?: Record<string, any>
|
||||||
|
}>
|
||||||
|
|
||||||
type Source = "env" | "config" | "custom" | "api"
|
type Source = "env" | "config" | "custom" | "api"
|
||||||
|
|
||||||
const CUSTOM_LOADERS: Record<string, CustomLoader> = {
|
const CUSTOM_LOADERS: Record<string, CustomLoader> = {
|
||||||
async anthropic(provider) {
|
async anthropic(provider) {
|
||||||
const access = await AuthAnthropic.access()
|
const access = await AuthAnthropic.access()
|
||||||
if (!access) return false
|
if (!access) return { autoload: false }
|
||||||
for (const model of Object.values(provider.models)) {
|
for (const model of Object.values(provider.models)) {
|
||||||
model.cost = {
|
model.cost = {
|
||||||
input: 0,
|
input: 0,
|
||||||
|
@ -49,6 +50,7 @@ export namespace Provider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
autoload: true,
|
||||||
options: {
|
options: {
|
||||||
apiKey: "",
|
apiKey: "",
|
||||||
async fetch(input: any, init: any) {
|
async fetch(input: any, init: any) {
|
||||||
|
@ -69,9 +71,9 @@ export namespace Provider {
|
||||||
},
|
},
|
||||||
"github-copilot": async (provider) => {
|
"github-copilot": async (provider) => {
|
||||||
const copilot = await AuthCopilot()
|
const copilot = await AuthCopilot()
|
||||||
if (!copilot) return false
|
if (!copilot) return { autoload: false }
|
||||||
let info = await Auth.get("github-copilot")
|
let info = await Auth.get("github-copilot")
|
||||||
if (!info || info.type !== "oauth") return false
|
if (!info || info.type !== "oauth") return { autoload: false }
|
||||||
|
|
||||||
if (provider && provider.models) {
|
if (provider && provider.models) {
|
||||||
for (const model of Object.values(provider.models)) {
|
for (const model of Object.values(provider.models)) {
|
||||||
|
@ -83,6 +85,7 @@ export namespace Provider {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
autoload: true,
|
||||||
options: {
|
options: {
|
||||||
apiKey: "",
|
apiKey: "",
|
||||||
async fetch(input: any, init: any) {
|
async fetch(input: any, init: any) {
|
||||||
|
@ -113,9 +116,18 @@ export namespace Provider {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
openai: async () => {
|
||||||
|
return {
|
||||||
|
autoload: false,
|
||||||
|
async getModel(sdk: any, modelID: string) {
|
||||||
|
return sdk.responses(modelID)
|
||||||
|
},
|
||||||
|
options: {},
|
||||||
|
}
|
||||||
|
},
|
||||||
"amazon-bedrock": async () => {
|
"amazon-bedrock": async () => {
|
||||||
if (!process.env["AWS_PROFILE"] && !process.env["AWS_ACCESS_KEY_ID"])
|
if (!process.env["AWS_PROFILE"] && !process.env["AWS_ACCESS_KEY_ID"])
|
||||||
return false
|
return { autoload: false }
|
||||||
|
|
||||||
const region = process.env["AWS_REGION"] ?? "us-east-1"
|
const region = process.env["AWS_REGION"] ?? "us-east-1"
|
||||||
|
|
||||||
|
@ -123,6 +135,7 @@ export namespace Provider {
|
||||||
await BunProc.install("@aws-sdk/credential-providers")
|
await BunProc.install("@aws-sdk/credential-providers")
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
|
autoload: true,
|
||||||
options: {
|
options: {
|
||||||
region,
|
region,
|
||||||
credentialProvider: fromNodeProviderChain(),
|
credentialProvider: fromNodeProviderChain(),
|
||||||
|
@ -248,8 +261,13 @@ export namespace Provider {
|
||||||
for (const [providerID, fn] of Object.entries(CUSTOM_LOADERS)) {
|
for (const [providerID, fn] of Object.entries(CUSTOM_LOADERS)) {
|
||||||
if (disabled.has(providerID)) continue
|
if (disabled.has(providerID)) continue
|
||||||
const result = await fn(database[providerID])
|
const result = await fn(database[providerID])
|
||||||
if (result) {
|
if (result && (result.autoload || providers[providerID])) {
|
||||||
mergeProvider(providerID, result.options, "custom", result.getModel)
|
mergeProvider(
|
||||||
|
providerID,
|
||||||
|
result.options ?? {},
|
||||||
|
"custom",
|
||||||
|
result.getModel,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue