Skip to content

Commit 87e23ab

Browse files
authored
refactor: remove ProviderAuth facade (#21983)
1 parent 2868000 commit 87e23ab

3 files changed

Lines changed: 27 additions & 32 deletions

File tree

packages/opencode/src/provider/auth.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { AuthOAuthResult, Hooks } from "@opencode-ai/plugin"
22
import { NamedError } from "@opencode-ai/util/error"
33
import { Auth } from "@/auth"
44
import { InstanceState } from "@/effect/instance-state"
5-
import { makeRuntime } from "@/effect/run-service"
65
import { Plugin } from "../plugin"
76
import { ProviderID } from "./schema"
87
import { Array as Arr, Effect, Layer, Record, Result, Context } from "effect"
@@ -232,22 +231,4 @@ export namespace ProviderAuth {
232231
export const defaultLayer = Layer.suspend(() =>
233232
layer.pipe(Layer.provide(Auth.defaultLayer), Layer.provide(Plugin.defaultLayer)),
234233
)
235-
236-
const { runPromise } = makeRuntime(Service, defaultLayer)
237-
238-
export async function methods() {
239-
return runPromise((svc) => svc.methods())
240-
}
241-
242-
export async function authorize(input: {
243-
providerID: ProviderID
244-
method: number
245-
inputs?: Record<string, string>
246-
}): Promise<Authorization | undefined> {
247-
return runPromise((svc) => svc.authorize(input))
248-
}
249-
250-
export async function callback(input: { providerID: ProviderID; method: number; code?: string }) {
251-
return runPromise((svc) => svc.callback(input))
252-
}
253234
}

packages/opencode/src/server/routes/provider.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Provider } from "../../provider/provider"
66
import { ModelsDev } from "../../provider/models"
77
import { ProviderAuth } from "../../provider/auth"
88
import { ProviderID } from "../../provider/schema"
9+
import { AppRuntime } from "../../effect/app-runtime"
910
import { mapValues } from "remeda"
1011
import { errors } from "../error"
1112
import { lazy } from "../../util/lazy"
@@ -81,7 +82,7 @@ export const ProviderRoutes = lazy(() =>
8182
},
8283
}),
8384
async (c) => {
84-
return c.json(await ProviderAuth.methods())
85+
return c.json(await AppRuntime.runPromise(ProviderAuth.Service.use((svc) => svc.methods())))
8586
},
8687
)
8788
.post(
@@ -118,11 +119,15 @@ export const ProviderRoutes = lazy(() =>
118119
async (c) => {
119120
const providerID = c.req.valid("param").providerID
120121
const { method, inputs } = c.req.valid("json")
121-
const result = await ProviderAuth.authorize({
122-
providerID,
123-
method,
124-
inputs,
125-
})
122+
const result = await AppRuntime.runPromise(
123+
ProviderAuth.Service.use((svc) =>
124+
svc.authorize({
125+
providerID,
126+
method,
127+
inputs,
128+
}),
129+
),
130+
)
126131
return c.json(result)
127132
},
128133
)
@@ -160,11 +165,15 @@ export const ProviderRoutes = lazy(() =>
160165
async (c) => {
161166
const providerID = c.req.valid("param").providerID
162167
const { method, code } = c.req.valid("json")
163-
await ProviderAuth.callback({
164-
providerID,
165-
method,
166-
code,
167-
})
168+
await AppRuntime.runPromise(
169+
ProviderAuth.Service.use((svc) =>
170+
svc.callback({
171+
providerID,
172+
method,
173+
code,
174+
}),
175+
),
176+
)
168177
return c.json(true)
169178
},
170179
),

packages/opencode/test/plugin/auth-override.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, expect, test } from "bun:test"
22
import path from "path"
33
import fs from "fs/promises"
4+
import { Effect } from "effect"
45
import { tmpdir } from "../fixture/fixture"
56
import { Instance } from "../../src/project/instance"
67
import { ProviderAuth } from "../../src/provider/auth"
@@ -39,14 +40,18 @@ describe("plugin.auth-override", () => {
3940
const methods = await Instance.provide({
4041
directory: tmp.path,
4142
fn: async () => {
42-
return ProviderAuth.methods()
43+
return Effect.runPromise(
44+
ProviderAuth.Service.use((svc) => svc.methods()).pipe(Effect.provide(ProviderAuth.defaultLayer)),
45+
)
4346
},
4447
})
4548

4649
const plainMethods = await Instance.provide({
4750
directory: plain.path,
4851
fn: async () => {
49-
return ProviderAuth.methods()
52+
return Effect.runPromise(
53+
ProviderAuth.Service.use((svc) => svc.methods()).pipe(Effect.provide(ProviderAuth.defaultLayer)),
54+
)
5055
},
5156
})
5257

0 commit comments

Comments
 (0)