feat(core): add opencode integration (#33560)
This commit is contained in:
parent
cfddb2407c
commit
c556bddda3
2 changed files with 10 additions and 28 deletions
|
|
@ -85,26 +85,16 @@ function oauth(http: HttpClient.HttpClient) {
|
||||||
method: {
|
method: {
|
||||||
id: methodID,
|
id: methodID,
|
||||||
type: "oauth",
|
type: "oauth",
|
||||||
label: "Sign in with OpenCode",
|
label: "OpenCode Console account",
|
||||||
prompts: [
|
|
||||||
{
|
|
||||||
type: "text",
|
|
||||||
key: "server",
|
|
||||||
message: "OpenCode server",
|
|
||||||
placeholder: defaultServer,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
authorize: (inputs) =>
|
authorize: () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const url = new URL(inputs.server || defaultServer)
|
const device = yield* post(http, `${defaultServer}/auth/device/code`, { client_id: clientID }, Device)
|
||||||
const server = `${url.origin}${url.pathname.replace(/\/+$/, "")}`
|
|
||||||
const device = yield* post(http, `${server}/auth/device/code`, { client_id: clientID }, Device)
|
|
||||||
return {
|
return {
|
||||||
mode: "auto" as const,
|
mode: "auto" as const,
|
||||||
url: `${server}${device.verification_uri_complete}`,
|
url: `${defaultServer}${device.verification_uri_complete}`,
|
||||||
instructions: `Enter code: ${device.user_code}`,
|
instructions: `Enter code: ${device.user_code}`,
|
||||||
callback: poll(http, server, device.device_code, Duration.seconds(device.interval)),
|
callback: poll(http, defaultServer, device.device_code, Duration.seconds(device.interval)),
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
refresh: (credential) =>
|
refresh: (credential) =>
|
||||||
|
|
@ -157,7 +147,7 @@ export const OpencodePlugin = define<HttpClient.HttpClient | EventV2.Service | S
|
||||||
integration.name = "OpenCode"
|
integration.name = "OpenCode"
|
||||||
})
|
})
|
||||||
draft.method.update(oauth(http))
|
draft.method.update(oauth(http))
|
||||||
draft.method.update({ integrationID: "opencode", method: { type: "key", label: "API key" } })
|
draft.method.update({ integrationID: "opencode", method: { type: "key", label: "API key (service account)" } })
|
||||||
})
|
})
|
||||||
|
|
||||||
yield* load()
|
yield* load()
|
||||||
|
|
@ -302,7 +292,7 @@ function credential(http: HttpClient.HttpClient, server: string, token: typeof T
|
||||||
],
|
],
|
||||||
{ concurrency: 2 },
|
{ concurrency: 2 },
|
||||||
)
|
)
|
||||||
const org = orgs.toSorted((a, b) => a.id.localeCompare(b.id))[0]
|
const org = orgs.toSorted((a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id))[0]
|
||||||
return new Credential.OAuth({
|
return new Credential.OAuth({
|
||||||
type: "oauth" as const,
|
type: "oauth" as const,
|
||||||
methodID,
|
methodID,
|
||||||
|
|
|
||||||
|
|
@ -49,24 +49,16 @@ function withEnv<A, E, R>(vars: Record<string, string | undefined>, effect: () =
|
||||||
const cost = (input: number, output = 0) => [{ input, output, cache: { read: 0, write: 0 } }]
|
const cost = (input: number, output = 0) => [{ input, output, cache: { read: 0, write: 0 } }]
|
||||||
|
|
||||||
describe("OpencodePlugin", () => {
|
describe("OpencodePlugin", () => {
|
||||||
it.effect("registers OAuth and API key methods", () =>
|
it.effect("registers account and service account methods", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
yield* addPlugin()
|
yield* addPlugin()
|
||||||
expect((yield* (yield* Integration.Service).get(Integration.ID.make("opencode")))?.methods).toEqual([
|
expect((yield* (yield* Integration.Service).get(Integration.ID.make("opencode")))?.methods).toEqual([
|
||||||
{
|
{
|
||||||
id: Integration.MethodID.make("device"),
|
id: Integration.MethodID.make("device"),
|
||||||
type: "oauth",
|
type: "oauth",
|
||||||
label: "Sign in with OpenCode",
|
label: "OpenCode Console account",
|
||||||
prompts: [
|
|
||||||
{
|
|
||||||
type: "text",
|
|
||||||
key: "server",
|
|
||||||
message: "OpenCode server",
|
|
||||||
placeholder: "https://console.opencode.ai",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
{ type: "key", label: "API key" },
|
{ type: "key", label: "API key (service account)" },
|
||||||
])
|
])
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue