From 23ea8ba1ceb35358c62ba1051ba402223d0fb5b3 Mon Sep 17 00:00:00 2001 From: Dax Date: Fri, 21 Nov 2025 00:21:06 -0500 Subject: Tui onboarding (#4569) Co-authored-by: GitHub Action --- packages/plugin/src/index.ts | 218 ++++++++++++++++++++++--------------------- 1 file changed, 110 insertions(+), 108 deletions(-) (limited to 'packages/plugin/src') 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 +export type AuthHook = { + provider: string + loader?: (auth: () => Promise, provider: Provider) => Promise> + methods: ( + | { + type: "oauth" + label: string + prompts?: Array< + | { + type: "text" + key: string + message: string + placeholder?: string + validate?: (value: string) => string | undefined + condition?: (inputs: Record) => boolean + } + | { + type: "select" + key: string + message: string + options: Array<{ + label: string + value: string + hint?: string + }> + condition?: (inputs: Record) => boolean + } + > + authorize(inputs?: Record): Promise + } + | { + type: "api" + label: string + prompts?: Array< + | { + type: "text" + key: string + message: string + placeholder?: string + validate?: (value: string) => string | undefined + condition?: (inputs: Record) => boolean + } + | { + type: "select" + key: string + message: string + options: Array<{ + label: string + value: string + hint?: string + }> + condition?: (inputs: Record) => boolean + } + > + authorize?(inputs?: Record): 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 config?: (input: Config) => Promise tool?: { [key: string]: ToolDefinition } - auth?: { - provider: string - loader?: (auth: () => Promise, provider: Provider) => Promise> - methods: ( - | { - type: "oauth" - label: string - prompts?: Array< - | { - type: "text" - key: string - message: string - placeholder?: string - validate?: (value: string) => string | undefined - condition?: (inputs: Record) => boolean - } - | { - type: "select" - key: string - message: string - options: Array<{ - label: string - value: string - hint?: string - }> - condition?: (inputs: Record) => boolean - } - > - authorize(inputs?: Record): 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) => boolean - } - | { - type: "select" - key: string - message: string - options: Array<{ - label: string - value: string - hint?: string - }> - condition?: (inputs: Record) => boolean - } - > - authorize?(inputs?: Record): Promise< - | { - type: "success" - key: string - provider?: string - } - | { - type: "failed" - } - > - } - )[] - } + auth?: AuthHook /** * Called when a new message is received */ -- cgit v1.2.3