Skip to content

Commit e9b05e8

Browse files
committed
fix(provider): gracefully handle maple proxy unavailability at startup
1 parent 8918fb1 commit e9b05e8

1 file changed

Lines changed: 42 additions & 41 deletions

File tree

packages/opencode/src/provider/provider.ts

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -824,51 +824,52 @@ function custom(dep: CustomDep): Record<string, CustomLoader> {
824824

825825
if (!apiKey) return { autoload: false }
826826

827-
try {
828-
const response = yield* Effect.promise(() =>
829-
fetch(`${baseURL}/models`, {
827+
const models = yield* Effect.tryPromise({
828+
try: async () => {
829+
const response = await fetch(`${baseURL}/models`, {
830830
headers: { Authorization: `Bearer ${apiKey}` },
831831
signal: AbortSignal.timeout(5000),
832-
}),
833-
)
834-
if (!response.ok) {
835-
log.warn("Failed to fetch Maple models", { status: response.status })
836-
return { autoload: false }
837-
}
838-
const data = yield* Effect.promise(() => response.json() as Promise<{ data?: Array<{ id: string }> }>)
839-
const models = data.data ?? []
840-
841-
for (const model of models) {
842-
input.models[model.id] = {
843-
id: ModelID.make(model.id),
844-
providerID: ProviderID.make("maple"),
845-
name: model.id,
846-
api: {
847-
id: model.id,
848-
url: baseURL,
849-
npm: "@ai-sdk/openai-compatible",
850-
},
851-
status: "active",
852-
headers: {},
853-
options: {},
854-
cost: { input: 0, output: 0, cache: { read: 0, write: 0 } },
855-
limit: { context: 128000, output: 8192 },
856-
capabilities: {
857-
temperature: true,
858-
reasoning: false,
859-
attachment: false,
860-
toolcall: true,
861-
input: { text: true, audio: false, image: false, video: false, pdf: false },
862-
output: { text: true, audio: false, image: false, video: false, pdf: false },
863-
interleaved: false,
864-
},
865-
release_date: "",
866-
variants: {},
832+
})
833+
if (!response.ok) {
834+
log.warn("Failed to fetch Maple models", { status: response.status })
835+
return []
867836
}
837+
const data = await response.json() as { data?: Array<{ id: string }> }
838+
return data.data ?? []
839+
},
840+
catch: (e) => {
841+
log.warn("Failed to connect to Maple proxy", { error: e })
842+
return new Error(String(e))
843+
},
844+
}).pipe(Effect.orElseSucceed(() => [] as Array<{ id: string }>))
845+
846+
for (const model of models) {
847+
input.models[model.id] = {
848+
id: ModelID.make(model.id),
849+
providerID: ProviderID.make("maple"),
850+
name: model.id,
851+
api: {
852+
id: model.id,
853+
url: baseURL,
854+
npm: "@ai-sdk/openai-compatible",
855+
},
856+
status: "active",
857+
headers: {},
858+
options: {},
859+
cost: { input: 0, output: 0, cache: { read: 0, write: 0 } },
860+
limit: { context: 128000, output: 8192 },
861+
capabilities: {
862+
temperature: true,
863+
reasoning: false,
864+
attachment: false,
865+
toolcall: true,
866+
input: { text: true, audio: false, image: false, video: false, pdf: false },
867+
output: { text: true, audio: false, image: false, video: false, pdf: false },
868+
interleaved: false,
869+
},
870+
release_date: "",
871+
variants: {},
868872
}
869-
} catch (e) {
870-
log.warn("Failed to connect to Maple proxy", { error: e })
871-
return { autoload: false }
872873
}
873874

874875
return {

0 commit comments

Comments
 (0)