refactor(cli/providers): Stage 4 — drop inline AppRuntime.runPromise calls (#25532)
This commit is contained in:
@@ -239,19 +239,16 @@ export const ProvidersListCommand = effectCmd({
|
|||||||
// Lists global credentials + provider env vars; no project instance needed.
|
// Lists global credentials + provider env vars; no project instance needed.
|
||||||
instance: false,
|
instance: false,
|
||||||
handler: Effect.fn("Cli.providers.list")(function* (_args) {
|
handler: Effect.fn("Cli.providers.list")(function* (_args) {
|
||||||
|
const authSvc = yield* Auth.Service
|
||||||
|
const modelsDev = yield* ModelsDev.Service
|
||||||
yield* Effect.promise(async () => {
|
yield* Effect.promise(async () => {
|
||||||
UI.empty()
|
UI.empty()
|
||||||
const authPath = path.join(Global.Path.data, "auth.json")
|
const authPath = path.join(Global.Path.data, "auth.json")
|
||||||
const homedir = os.homedir()
|
const homedir = os.homedir()
|
||||||
const displayPath = authPath.startsWith(homedir) ? authPath.replace(homedir, "~") : authPath
|
const displayPath = authPath.startsWith(homedir) ? authPath.replace(homedir, "~") : authPath
|
||||||
prompts.intro(`Credentials ${UI.Style.TEXT_DIM}${displayPath}`)
|
prompts.intro(`Credentials ${UI.Style.TEXT_DIM}${displayPath}`)
|
||||||
const results = await AppRuntime.runPromise(
|
const results = Object.entries(await Effect.runPromise(authSvc.all()))
|
||||||
Effect.gen(function* () {
|
const database = await Effect.runPromise(modelsDev.get())
|
||||||
const auth = yield* Auth.Service
|
|
||||||
return Object.entries(yield* auth.all())
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
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
|
||||||
@@ -307,6 +304,8 @@ export const ProvidersLoginCommand = effectCmd({
|
|||||||
type: "string",
|
type: "string",
|
||||||
}),
|
}),
|
||||||
handler: Effect.fn("Cli.providers.login")(function* (args) {
|
handler: Effect.fn("Cli.providers.login")(function* (args) {
|
||||||
|
const cfgSvc = yield* Config.Service
|
||||||
|
const pluginSvc = yield* Plugin.Service
|
||||||
yield* Effect.promise(async () => {
|
yield* Effect.promise(async () => {
|
||||||
UI.empty()
|
UI.empty()
|
||||||
prompts.intro("Add credential")
|
prompts.intro("Add credential")
|
||||||
@@ -342,7 +341,7 @@ export const ProvidersLoginCommand = effectCmd({
|
|||||||
}
|
}
|
||||||
await refreshModels().catch(() => {})
|
await refreshModels().catch(() => {})
|
||||||
|
|
||||||
const config = await AppRuntime.runPromise(Config.Service.use((cfg) => cfg.get()))
|
const config = await Effect.runPromise(cfgSvc.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
|
||||||
@@ -356,12 +355,7 @@ export const ProvidersLoginCommand = effectCmd({
|
|||||||
}
|
}
|
||||||
return filtered
|
return filtered
|
||||||
})
|
})
|
||||||
const hooks = await AppRuntime.runPromise(
|
const hooks = await Effect.runPromise(pluginSvc.list())
|
||||||
Effect.gen(function* () {
|
|
||||||
const plugin = yield* Plugin.Service
|
|
||||||
return yield* plugin.list()
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
const priority: Record<string, number> = {
|
const priority: Record<string, number> = {
|
||||||
opencode: 0,
|
opencode: 0,
|
||||||
@@ -500,20 +494,17 @@ export const ProvidersLogoutCommand = effectCmd({
|
|||||||
// Removes a global auth credential; no project instance needed.
|
// Removes a global auth credential; no project instance needed.
|
||||||
instance: false,
|
instance: false,
|
||||||
handler: Effect.fn("Cli.providers.logout")(function* (_args) {
|
handler: Effect.fn("Cli.providers.logout")(function* (_args) {
|
||||||
|
const authSvc = yield* Auth.Service
|
||||||
|
const modelsDev = yield* ModelsDev.Service
|
||||||
yield* Effect.promise(async () => {
|
yield* Effect.promise(async () => {
|
||||||
UI.empty()
|
UI.empty()
|
||||||
const credentials: Array<[string, Auth.Info]> = await AppRuntime.runPromise(
|
const credentials: Array<[string, Auth.Info]> = Object.entries(await Effect.runPromise(authSvc.all()))
|
||||||
Effect.gen(function* () {
|
|
||||||
const auth = yield* Auth.Service
|
|
||||||
return Object.entries(yield* auth.all())
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
prompts.intro("Remove credential")
|
prompts.intro("Remove credential")
|
||||||
if (credentials.length === 0) {
|
if (credentials.length === 0) {
|
||||||
prompts.log.error("No credentials found")
|
prompts.log.error("No credentials found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const database = await getModels()
|
const database = await Effect.runPromise(modelsDev.get())
|
||||||
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]) => ({
|
||||||
@@ -523,12 +514,7 @@ export const ProvidersLogoutCommand = effectCmd({
|
|||||||
})
|
})
|
||||||
if (prompts.isCancel(selected)) throw new UI.CancelledError()
|
if (prompts.isCancel(selected)) throw new UI.CancelledError()
|
||||||
const providerID = selected as string
|
const providerID = selected as string
|
||||||
await AppRuntime.runPromise(
|
await Effect.runPromise(authSvc.remove(providerID))
|
||||||
Effect.gen(function* () {
|
|
||||||
const auth = yield* Auth.Service
|
|
||||||
yield* auth.remove(providerID)
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
prompts.outro("Logout successful")
|
prompts.outro("Logout successful")
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user