refactor(cli): drop ModelsDev Promise compat shim (#25460)
This commit is contained in:
@@ -212,7 +212,7 @@ export const GithubInstallCommand = cmd({
|
|||||||
const app = await getAppInfo()
|
const app = await getAppInfo()
|
||||||
await installGitHubApp()
|
await installGitHubApp()
|
||||||
|
|
||||||
const providers = await ModelsDev.get().then((p) => {
|
const providers = await AppRuntime.runPromise(ModelsDev.Service.use((s) => s.get())).then((p) => {
|
||||||
// TODO: add guide for copilot, for now just hide it
|
// TODO: add guide for copilot, for now just hide it
|
||||||
delete p["github-copilot"]
|
delete p["github-copilot"]
|
||||||
return p
|
return p
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import { cmd } from "./cmd"
|
|||||||
import * as prompts from "@clack/prompts"
|
import * as prompts from "@clack/prompts"
|
||||||
import { UI } from "../ui"
|
import { UI } from "../ui"
|
||||||
import { ModelsDev } from "@/provider/models"
|
import { ModelsDev } from "@/provider/models"
|
||||||
|
|
||||||
|
const getModels = () => AppRuntime.runPromise(ModelsDev.Service.use((s) => s.get()))
|
||||||
|
const refreshModels = () => AppRuntime.runPromise(ModelsDev.Service.use((s) => s.refresh(true)))
|
||||||
import { map, pipe, sortBy, values } from "remeda"
|
import { map, pipe, sortBy, values } from "remeda"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import os from "os"
|
import os from "os"
|
||||||
@@ -245,7 +248,7 @@ export const ProvidersListCommand = cmd({
|
|||||||
return Object.entries(yield* auth.all())
|
return Object.entries(yield* auth.all())
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
const database = await ModelsDev.get()
|
const database = await getModels()
|
||||||
|
|
||||||
for (const [providerID, result] of results) {
|
for (const [providerID, result] of results) {
|
||||||
const name = database[providerID]?.name || providerID
|
const name = database[providerID]?.name || providerID
|
||||||
@@ -334,14 +337,14 @@ export const ProvidersLoginCommand = cmd({
|
|||||||
prompts.outro("Done")
|
prompts.outro("Done")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await ModelsDev.refresh(true).catch(() => {})
|
await refreshModels().catch(() => {})
|
||||||
|
|
||||||
const config = await AppRuntime.runPromise(Config.Service.use((cfg) => cfg.get()))
|
const config = await AppRuntime.runPromise(Config.Service.use((cfg) => cfg.get()))
|
||||||
|
|
||||||
const disabled = new Set(config.disabled_providers ?? [])
|
const disabled = new Set(config.disabled_providers ?? [])
|
||||||
const enabled = config.enabled_providers ? new Set(config.enabled_providers) : undefined
|
const enabled = config.enabled_providers ? new Set(config.enabled_providers) : undefined
|
||||||
|
|
||||||
const providers = await ModelsDev.get().then((x) => {
|
const providers = await getModels().then((x) => {
|
||||||
const filtered: Record<string, (typeof x)[string]> = {}
|
const filtered: Record<string, (typeof x)[string]> = {}
|
||||||
for (const [key, value] of Object.entries(x)) {
|
for (const [key, value] of Object.entries(x)) {
|
||||||
if ((enabled ? enabled.has(key) : true) && !disabled.has(key)) {
|
if ((enabled ? enabled.has(key) : true) && !disabled.has(key)) {
|
||||||
@@ -505,7 +508,7 @@ export const ProvidersLogoutCommand = cmd({
|
|||||||
prompts.log.error("No credentials found")
|
prompts.log.error("No credentials found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const database = await ModelsDev.get()
|
const database = await getModels()
|
||||||
const selected = await prompts.select({
|
const selected = await prompts.select({
|
||||||
message: "Select provider",
|
message: "Select provider",
|
||||||
options: credentials.map(([key, value]) => ({
|
options: credentials.map(([key, value]) => ({
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { Flag } from "@opencode-ai/core/flag/flag"
|
|||||||
import { Flock } from "@opencode-ai/core/util/flock"
|
import { Flock } from "@opencode-ai/core/util/flock"
|
||||||
import { Hash } from "@opencode-ai/core/util/hash"
|
import { Hash } from "@opencode-ai/core/util/hash"
|
||||||
import { AppFileSystem } from "@opencode-ai/core/filesystem"
|
import { AppFileSystem } from "@opencode-ai/core/filesystem"
|
||||||
import { makeRuntime } from "@/effect/run-service"
|
|
||||||
import { withTransientReadRetry } from "@/util/effect-http-client"
|
import { withTransientReadRetry } from "@/util/effect-http-client"
|
||||||
|
|
||||||
const Cost = Schema.Struct({
|
const Cost = Schema.Struct({
|
||||||
@@ -196,11 +195,4 @@ export const defaultLayer: Layer.Layer<Service> = layer.pipe(
|
|||||||
Layer.provide(AppFileSystem.defaultLayer),
|
Layer.provide(AppFileSystem.defaultLayer),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Promise-style compat for callers in Promise-context (Hono routes, legacy CLI handlers).
|
|
||||||
// makeRuntime uses the shared memoMap so this runtime's Service instance is the same one
|
|
||||||
// AppRuntime sees — Effect callers and Promise callers operate on the same cache.
|
|
||||||
const runtime = makeRuntime(Service, defaultLayer)
|
|
||||||
export const get = () => runtime.runPromise((s) => s.get())
|
|
||||||
export const refresh = (force = false) => runtime.runPromise((s) => s.refresh(force))
|
|
||||||
|
|
||||||
export * as ModelsDev from "./models"
|
export * as ModelsDev from "./models"
|
||||||
|
|||||||
Reference in New Issue
Block a user