mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat: add dynamic OAuth prompt system with conditional fields
- Add PromptFieldSchema supporting text and select input types - Support conditional prompt visibility based on previous inputs - Add inputs parameter to OAuth authorize request - Update OAuth dialogs to render dynamic prompts - Add OPENCODE_PUBLIC_URL config for OAuth callback URLs - Remove redundant OAuthMethod enum in favor of backend schema
This commit is contained in:
1 parent
9d94c333b4
commit
2b5e130916
12 files changed
+371
-78
No files matched your search
@@ -1,21 +1,14 @@
|
||||
import { API_BASE_URL } from "@/config"
|
||||
import type { components, operations } from "./opencode-types"
|
||||
import { fetchWrapper, FetchError } from "./fetchWrapper"
|
||||
|
||||
export interface OAuthAuthorizeResponse {
|
||||
url: string
|
||||
method: "code"
|
||||
instructions: string
|
||||
}
|
||||
type OpenCodeAuthorizeRequest = NonNullable<operations["provider.oauth.authorize"]["requestBody"]>["content"]["application/json"]
|
||||
|
||||
export interface OAuthCallbackRequest {
|
||||
method: number
|
||||
code?: string
|
||||
}
|
||||
export type OAuthAuthorizeResponse = components["schemas"]["ProviderAuthAuthorization"]
|
||||
|
||||
export interface ProviderAuthMethod {
|
||||
type: "oauth" | "api"
|
||||
label: string
|
||||
}
|
||||
export type OAuthCallbackRequest = NonNullable<operations["provider.oauth.callback"]["requestBody"]>["content"]["application/json"]
|
||||
|
||||
export type ProviderAuthMethod = components["schemas"]["ProviderAuthMethod"]
|
||||
|
||||
export interface ProviderAuthMethods {
|
||||
[providerId: string]: ProviderAuthMethod[]
|
||||
@@ -29,12 +22,12 @@ function handleApiError(error: unknown, context: string): never {
|
||||
}
|
||||
|
||||
export const oauthApi = {
|
||||
authorize: async (providerId: string, method: number): Promise<OAuthAuthorizeResponse> => {
|
||||
authorize: async (providerId: string, method: number, inputs?: OpenCodeAuthorizeRequest["inputs"]): Promise<OAuthAuthorizeResponse> => {
|
||||
try {
|
||||
return await fetchWrapper(`${API_BASE_URL}/api/oauth/${providerId}/oauth/authorize`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ method }),
|
||||
body: JSON.stringify({ method, inputs }),
|
||||
})
|
||||
} catch (error) {
|
||||
handleApiError(error, "OAuth authorization failed")
|
||||
|
||||
@@ -3552,16 +3552,22 @@
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"method": {
|
||||
"description": "Auth method index",
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"method"
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"method": {
|
||||
"description": "Auth method index",
|
||||
"type": "number"
|
||||
},
|
||||
"inputs": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"method"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -10399,6 +10405,90 @@
|
||||
},
|
||||
"label": {
|
||||
"type": "string"
|
||||
},
|
||||
"prompts": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"const": "text"
|
||||
},
|
||||
"key": {
|
||||
"type": "string"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"placeholder": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type",
|
||||
"key",
|
||||
"message"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"const": "select"
|
||||
},
|
||||
"key": {
|
||||
"type": "string"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"options": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"label": {
|
||||
"type": "string"
|
||||
},
|
||||
"value": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"label",
|
||||
"value"
|
||||
]
|
||||
}
|
||||
},
|
||||
"when": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"key": {
|
||||
"type": "string"
|
||||
},
|
||||
"value": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"key",
|
||||
"value"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type",
|
||||
"key",
|
||||
"message",
|
||||
"options"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -10932,4 +11022,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3379,6 +3379,24 @@ export interface components {
|
||||
ProviderAuthMethod: {
|
||||
type: "oauth" | "api";
|
||||
label: string;
|
||||
prompts?: ({
|
||||
type: "text";
|
||||
key: string;
|
||||
message: string;
|
||||
placeholder?: string;
|
||||
} | {
|
||||
type: "select";
|
||||
key: string;
|
||||
message: string;
|
||||
options: {
|
||||
label: string;
|
||||
value: string;
|
||||
}[];
|
||||
when?: {
|
||||
key: string;
|
||||
value: string;
|
||||
};
|
||||
})[];
|
||||
};
|
||||
ProviderAuthAuthorization: {
|
||||
url: string;
|
||||
@@ -5698,6 +5716,9 @@ export interface operations {
|
||||
"application/json": {
|
||||
/** @description Auth method index */
|
||||
method: number;
|
||||
inputs?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user