diff options
| author | Dax <[email protected]> | 2025-11-21 00:21:06 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-11-21 00:21:06 -0500 |
| commit | 23ea8ba1ceb35358c62ba1051ba402223d0fb5b3 (patch) | |
| tree | 675096b0f5d54e5ff766b20191967a8d3f491a86 /packages/plugin | |
| parent | c417fec2464079a6e0bba3450d5e41c5394282bc (diff) | |
| download | opencode-23ea8ba1ceb35358c62ba1051ba402223d0fb5b3.tar.gz opencode-23ea8ba1ceb35358c62ba1051ba402223d0fb5b3.zip | |
Tui onboarding (#4569)
Co-authored-by: GitHub Action <[email protected]>
Diffstat (limited to 'packages/plugin')
| -rw-r--r-- | packages/plugin/src/index.ts | 218 |
1 files changed, 110 insertions, 108 deletions
diff --git a/packages/plugin/src/index.ts b/packages/plugin/src/index.ts index 0601e5877..ab7aac251 100644 --- a/packages/plugin/src/index.ts +++ b/packages/plugin/src/index.ts @@ -26,120 +26,122 @@ export type PluginInput = { export type Plugin = (input: PluginInput) => Promise<Hooks> +export type AuthHook = { + provider: string + loader?: (auth: () => Promise<Auth>, provider: Provider) => Promise<Record<string, any>> + methods: ( + | { + type: "oauth" + label: string + prompts?: Array< + | { + type: "text" + key: string + message: string + placeholder?: string + validate?: (value: string) => string | undefined + condition?: (inputs: Record<string, string>) => boolean + } + | { + type: "select" + key: string + message: string + options: Array<{ + label: string + value: string + hint?: string + }> + condition?: (inputs: Record<string, string>) => boolean + } + > + authorize(inputs?: Record<string, string>): Promise<AuthOuathResult> + } + | { + type: "api" + label: string + prompts?: Array< + | { + type: "text" + key: string + message: string + placeholder?: string + validate?: (value: string) => string | undefined + condition?: (inputs: Record<string, string>) => boolean + } + | { + type: "select" + key: string + message: string + options: Array<{ + label: string + value: string + hint?: string + }> + condition?: (inputs: Record<string, string>) => boolean + } + > + authorize?(inputs?: Record<string, string>): Promise< + | { + type: "success" + key: string + provider?: string + } + | { + type: "failed" + } + > + } + )[] +} + +export type AuthOuathResult = { url: string; instructions: string } & ( + | { + method: "auto" + callback(): Promise< + | ({ + type: "success" + provider?: string + } & ( + | { + refresh: string + access: string + expires: number + } + | { key: string } + )) + | { + type: "failed" + } + > + } + | { + method: "code" + callback(code: string): Promise< + | ({ + type: "success" + provider?: string + } & ( + | { + refresh: string + access: string + expires: number + } + | { key: string } + )) + | { + type: "failed" + } + > + } +) + export interface Hooks { event?: (input: { event: Event }) => Promise<void> config?: (input: Config) => Promise<void> tool?: { [key: string]: ToolDefinition } - auth?: { - provider: string - loader?: (auth: () => Promise<Auth>, provider: Provider) => Promise<Record<string, any>> - methods: ( - | { - type: "oauth" - label: string - prompts?: Array< - | { - type: "text" - key: string - message: string - placeholder?: string - validate?: (value: string) => string | undefined - condition?: (inputs: Record<string, string>) => boolean - } - | { - type: "select" - key: string - message: string - options: Array<{ - label: string - value: string - hint?: string - }> - condition?: (inputs: Record<string, string>) => boolean - } - > - authorize(inputs?: Record<string, string>): Promise< - { url: string; instructions: string } & ( - | { - method: "auto" - callback(): Promise< - | ({ - type: "success" - provider?: string - } & ( - | { - refresh: string - access: string - expires: number - } - | { key: string } - )) - | { - type: "failed" - } - > - } - | { - method: "code" - callback(code: string): Promise< - | ({ - type: "success" - provider?: string - } & ( - | { - refresh: string - access: string - expires: number - } - | { key: string } - )) - | { - type: "failed" - } - > - } - ) - > - } - | { - type: "api" - label: string - prompts?: Array< - | { - type: "text" - key: string - message: string - placeholder?: string - validate?: (value: string) => string | undefined - condition?: (inputs: Record<string, string>) => boolean - } - | { - type: "select" - key: string - message: string - options: Array<{ - label: string - value: string - hint?: string - }> - condition?: (inputs: Record<string, string>) => boolean - } - > - authorize?(inputs?: Record<string, string>): Promise< - | { - type: "success" - key: string - provider?: string - } - | { - type: "failed" - } - > - } - )[] - } + auth?: AuthHook /** * Called when a new message is received */ |
