Skip to content

Commit c556bdd

Browse files
authored
feat(core): add opencode integration (#33560)
1 parent cfddb24 commit c556bdd

2 files changed

Lines changed: 10 additions & 28 deletions

File tree

packages/core/src/plugin/provider/opencode.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,16 @@ function oauth(http: HttpClient.HttpClient) {
8585
method: {
8686
id: methodID,
8787
type: "oauth",
88-
label: "Sign in with OpenCode",
89-
prompts: [
90-
{
91-
type: "text",
92-
key: "server",
93-
message: "OpenCode server",
94-
placeholder: defaultServer,
95-
},
96-
],
88+
label: "OpenCode Console account",
9789
},
98-
authorize: (inputs) =>
90+
authorize: () =>
9991
Effect.gen(function* () {
100-
const url = new URL(inputs.server || defaultServer)
101-
const server = `${url.origin}${url.pathname.replace(/\/+$/, "")}`
102-
const device = yield* post(http, `${server}/auth/device/code`, { client_id: clientID }, Device)
92+
const device = yield* post(http, `${defaultServer}/auth/device/code`, { client_id: clientID }, Device)
10393
return {
10494
mode: "auto" as const,
105-
url: `${server}${device.verification_uri_complete}`,
95+
url: `${defaultServer}${device.verification_uri_complete}`,
10696
instructions: `Enter code: ${device.user_code}`,
107-
callback: poll(http, server, device.device_code, Duration.seconds(device.interval)),
97+
callback: poll(http, defaultServer, device.device_code, Duration.seconds(device.interval)),
10898
}
10999
}),
110100
refresh: (credential) =>
@@ -157,7 +147,7 @@ export const OpencodePlugin = define<HttpClient.HttpClient | EventV2.Service | S
157147
integration.name = "OpenCode"
158148
})
159149
draft.method.update(oauth(http))
160-
draft.method.update({ integrationID: "opencode", method: { type: "key", label: "API key" } })
150+
draft.method.update({ integrationID: "opencode", method: { type: "key", label: "API key (service account)" } })
161151
})
162152

163153
yield* load()
@@ -302,7 +292,7 @@ function credential(http: HttpClient.HttpClient, server: string, token: typeof T
302292
],
303293
{ concurrency: 2 },
304294
)
305-
const org = orgs.toSorted((a, b) => a.id.localeCompare(b.id))[0]
295+
const org = orgs.toSorted((a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id))[0]
306296
return new Credential.OAuth({
307297
type: "oauth" as const,
308298
methodID,

packages/core/test/plugin/provider-opencode.test.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,16 @@ function withEnv<A, E, R>(vars: Record<string, string | undefined>, effect: () =
4949
const cost = (input: number, output = 0) => [{ input, output, cache: { read: 0, write: 0 } }]
5050

5151
describe("OpencodePlugin", () => {
52-
it.effect("registers OAuth and API key methods", () =>
52+
it.effect("registers account and service account methods", () =>
5353
Effect.gen(function* () {
5454
yield* addPlugin()
5555
expect((yield* (yield* Integration.Service).get(Integration.ID.make("opencode")))?.methods).toEqual([
5656
{
5757
id: Integration.MethodID.make("device"),
5858
type: "oauth",
59-
label: "Sign in with OpenCode",
60-
prompts: [
61-
{
62-
type: "text",
63-
key: "server",
64-
message: "OpenCode server",
65-
placeholder: "https://console.opencode.ai",
66-
},
67-
],
59+
label: "OpenCode Console account",
6860
},
69-
{ type: "key", label: "API key" },
61+
{ type: "key", label: "API key (service account)" },
7062
])
7163
}),
7264
)

0 commit comments

Comments
 (0)