mirror of
https://github.com/sst/opencode.git
synced 2025-08-27 08:24:06 +00:00
allow plugins to create custom auth providers
This commit is contained in:
parent
c93d50e8c7
commit
a433766a31
11 changed files with 372 additions and 438 deletions
|
@ -1,4 +1,14 @@
|
|||
import type { Event, createOpencodeClient, App, Model, Provider, Permission, UserMessage, Part } from "@opencode-ai/sdk"
|
||||
import type {
|
||||
Event,
|
||||
createOpencodeClient,
|
||||
App,
|
||||
Model,
|
||||
Provider,
|
||||
Permission,
|
||||
UserMessage,
|
||||
Part,
|
||||
Auth,
|
||||
} from "@opencode-ai/sdk"
|
||||
import type { BunShell } from "./shell"
|
||||
|
||||
export type PluginInput = {
|
||||
|
@ -10,6 +20,49 @@ export type Plugin = (input: PluginInput) => Promise<Hooks>
|
|||
|
||||
export interface Hooks {
|
||||
event?: (input: { event: Event }) => Promise<void>
|
||||
auth?: {
|
||||
provider: string
|
||||
loader?: (auth: () => Promise<Auth>, provider: Provider) => Promise<Record<string, any>>
|
||||
methods: (
|
||||
| {
|
||||
type: "oauth"
|
||||
label: string
|
||||
authorize(): Promise<
|
||||
{ url: string; instructions: string } & (
|
||||
| {
|
||||
method: "auto"
|
||||
callback(): Promise<
|
||||
| {
|
||||
type: "success"
|
||||
refresh: string
|
||||
access: string
|
||||
expires: number
|
||||
}
|
||||
| {
|
||||
type: "failed"
|
||||
}
|
||||
>
|
||||
}
|
||||
| {
|
||||
method: "code"
|
||||
callback(code: string): Promise<
|
||||
| {
|
||||
type: "success"
|
||||
refresh: string
|
||||
access: string
|
||||
expires: number
|
||||
}
|
||||
| {
|
||||
type: "failed"
|
||||
}
|
||||
>
|
||||
}
|
||||
)
|
||||
>
|
||||
}
|
||||
| { type: "api"; label: string }
|
||||
)[]
|
||||
}
|
||||
/**
|
||||
* Called when a new message is received
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue