Skip to content

Commit 05b82a6

Browse files
authored
refactor(cli): drop ModelsDev Promise compat shim (#25460)
1 parent 6cd02c0 commit 05b82a6

3 files changed

Lines changed: 8 additions & 13 deletions

File tree

packages/opencode/src/cli/cmd/github.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export const GithubInstallCommand = cmd({
212212
const app = await getAppInfo()
213213
await installGitHubApp()
214214

215-
const providers = await ModelsDev.get().then((p) => {
215+
const providers = await AppRuntime.runPromise(ModelsDev.Service.use((s) => s.get())).then((p) => {
216216
// TODO: add guide for copilot, for now just hide it
217217
delete p["github-copilot"]
218218
return p

packages/opencode/src/cli/cmd/providers.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { cmd } from "./cmd"
44
import * as prompts from "@clack/prompts"
55
import { UI } from "../ui"
66
import { ModelsDev } from "@/provider/models"
7+
8+
const getModels = () => AppRuntime.runPromise(ModelsDev.Service.use((s) => s.get()))
9+
const refreshModels = () => AppRuntime.runPromise(ModelsDev.Service.use((s) => s.refresh(true)))
710
import { map, pipe, sortBy, values } from "remeda"
811
import path from "path"
912
import os from "os"
@@ -245,7 +248,7 @@ export const ProvidersListCommand = cmd({
245248
return Object.entries(yield* auth.all())
246249
}),
247250
)
248-
const database = await ModelsDev.get()
251+
const database = await getModels()
249252

250253
for (const [providerID, result] of results) {
251254
const name = database[providerID]?.name || providerID
@@ -334,14 +337,14 @@ export const ProvidersLoginCommand = cmd({
334337
prompts.outro("Done")
335338
return
336339
}
337-
await ModelsDev.refresh(true).catch(() => {})
340+
await refreshModels().catch(() => {})
338341

339342
const config = await AppRuntime.runPromise(Config.Service.use((cfg) => cfg.get()))
340343

341344
const disabled = new Set(config.disabled_providers ?? [])
342345
const enabled = config.enabled_providers ? new Set(config.enabled_providers) : undefined
343346

344-
const providers = await ModelsDev.get().then((x) => {
347+
const providers = await getModels().then((x) => {
345348
const filtered: Record<string, (typeof x)[string]> = {}
346349
for (const [key, value] of Object.entries(x)) {
347350
if ((enabled ? enabled.has(key) : true) && !disabled.has(key)) {
@@ -505,7 +508,7 @@ export const ProvidersLogoutCommand = cmd({
505508
prompts.log.error("No credentials found")
506509
return
507510
}
508-
const database = await ModelsDev.get()
511+
const database = await getModels()
509512
const selected = await prompts.select({
510513
message: "Select provider",
511514
options: credentials.map(([key, value]) => ({

packages/opencode/src/provider/models.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { Flag } from "@opencode-ai/core/flag/flag"
77
import { Flock } from "@opencode-ai/core/util/flock"
88
import { Hash } from "@opencode-ai/core/util/hash"
99
import { AppFileSystem } from "@opencode-ai/core/filesystem"
10-
import { makeRuntime } from "@/effect/run-service"
1110
import { withTransientReadRetry } from "@/util/effect-http-client"
1211

1312
const Cost = Schema.Struct({
@@ -196,11 +195,4 @@ export const defaultLayer: Layer.Layer<Service> = layer.pipe(
196195
Layer.provide(AppFileSystem.defaultLayer),
197196
)
198197

199-
// Promise-style compat for callers in Promise-context (Hono routes, legacy CLI handlers).
200-
// makeRuntime uses the shared memoMap so this runtime's Service instance is the same one
201-
// AppRuntime sees — Effect callers and Promise callers operate on the same cache.
202-
const runtime = makeRuntime(Service, defaultLayer)
203-
export const get = () => runtime.runPromise((s) => s.get())
204-
export const refresh = (force = false) => runtime.runPromise((s) => s.refresh(force))
205-
206198
export * as ModelsDev from "./models"

0 commit comments

Comments
 (0)