mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
fix issues (#136)
* fix: prevent delete button click when card is not swiped open * refactor: improve CreateRepoInput type safety * security: require AUTH_SECRET and use secure random generation * fix: SSH key path validation, async passphrase stripping, and port handling * fix: use correct console methods for logger levels * Add error handling to DB update functions and improve migration logging * Add error handling for session lookup in auth middleware * Add structured git error handling with user-friendly messages - Parse git errors with specific error codes (AUTH_FAILED, REPO_NOT_FOUND, PUSH_REJECTED, MERGE_CONFLICT, etc.) and appropriate HTTP status codes - Return structured error responses with summary and detail from backend - Add GitErrorBanner component for better error display in UI - Add optional onError callback to useGit hook for external error handling * Make IPC server initialization/disposal async and fix SSH host key handler * add try-catch error handling in frontend lib utilities * remove unresolved promise handlers in speech synthesizer callbacks * Extract error types to shared package * Import GitErrorCode from shared package * Refactor API layer to use shared FetchError and fetchWrapper * Update prompt parser and source control components * Extract MCP server list to separate component with improved badge menu UX * merge useSettingsDialogUrl into useSettingsDialog and extract getRepoDisplayName utility * add separate loading state for passkey sign in * refactor hooks: use fetchWrapper, improve error handling, add proper types * replace browser confirm() with DeleteDialog component in settings * fix: add missing variables parameter in React Query onError callbacks * Refactor message parts to use separate Zustand store * Update QuestionPrompt styling for light/dark mode
This commit is contained in:
1 parent
7f7d106c28
commit
5de419ee28
75 files changed
+1990
-1367
No files matched your search
@@ -1,109 +1,101 @@
|
||||
export class FetchError extends Error {
|
||||
statusCode?: number
|
||||
code?: string
|
||||
import { FetchError } from '@opencode-manager/shared'
|
||||
import type { ApiErrorResponse } from '@opencode-manager/shared'
|
||||
|
||||
constructor(message: string, statusCode?: number, code?: string) {
|
||||
super(message)
|
||||
this.name = 'FetchError'
|
||||
this.statusCode = statusCode
|
||||
this.code = code
|
||||
}
|
||||
}
|
||||
|
||||
interface ApiError {
|
||||
error?: string
|
||||
code?: string
|
||||
message?: string
|
||||
}
|
||||
export { FetchError }
|
||||
|
||||
interface FetchWrapperOptions extends RequestInit {
|
||||
timeout?: number
|
||||
params?: Record<string, string | number | boolean | undefined | unknown>
|
||||
params?: Record<string, string | number | boolean | undefined>
|
||||
}
|
||||
|
||||
async function handleResponse(response: Response): Promise<never> {
|
||||
const data: ApiError = await response.json().catch(() => ({ error: 'An error occurred' }))
|
||||
throw new FetchError(data.error || data.message || 'Request failed', response.status, data.code)
|
||||
const data: ApiErrorResponse = await response.json().catch(() => ({ error: 'An error occurred' }))
|
||||
throw new FetchError(
|
||||
data.error || 'Request failed',
|
||||
response.status,
|
||||
data.code,
|
||||
data.detail
|
||||
)
|
||||
}
|
||||
|
||||
function buildUrl(url: string, params?: Record<string, string | number | boolean | undefined>): URL {
|
||||
const urlObj = new URL(url, window.location.origin)
|
||||
if (params) {
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
if (value !== undefined) {
|
||||
urlObj.searchParams.append(key, String(value))
|
||||
}
|
||||
})
|
||||
}
|
||||
return urlObj
|
||||
}
|
||||
|
||||
async function fetchWithTimeout(
|
||||
url: string,
|
||||
options: FetchWrapperOptions = {}
|
||||
): Promise<Response> {
|
||||
const { timeout = 30000, params, ...fetchOptions } = options
|
||||
const urlObj = buildUrl(url, params)
|
||||
|
||||
const controller = new AbortController()
|
||||
const timeoutId = timeout > 0 ? setTimeout(() => controller.abort(), timeout) : null
|
||||
|
||||
try {
|
||||
const response = await fetch(urlObj.toString(), {
|
||||
...fetchOptions,
|
||||
signal: controller.signal,
|
||||
})
|
||||
|
||||
if (timeoutId) clearTimeout(timeoutId)
|
||||
|
||||
if (!response.ok) {
|
||||
await handleResponse(response)
|
||||
}
|
||||
|
||||
return response
|
||||
} catch (error) {
|
||||
if (timeoutId) clearTimeout(timeoutId)
|
||||
if (error instanceof Error && error.name === 'AbortError') {
|
||||
throw new FetchError('Request timeout', 408, 'TIMEOUT')
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchWrapper<T = unknown>(
|
||||
url: string,
|
||||
options: FetchWrapperOptions = {}
|
||||
): Promise<T> {
|
||||
const { timeout = 30000, params, ...fetchOptions } = options
|
||||
|
||||
const urlObj = new URL(url, window.location.origin)
|
||||
if (params) {
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
if (value !== undefined) {
|
||||
urlObj.searchParams.append(key, String(value))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const controller = new AbortController()
|
||||
const timeoutId = setTimeout(() => controller.abort(), timeout)
|
||||
const response = await fetchWithTimeout(url, options)
|
||||
|
||||
try {
|
||||
const response = await fetch(urlObj.toString(), {
|
||||
...fetchOptions,
|
||||
signal: controller.signal,
|
||||
})
|
||||
|
||||
clearTimeout(timeoutId)
|
||||
|
||||
if (!response.ok) {
|
||||
await handleResponse(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
} catch (error) {
|
||||
clearTimeout(timeoutId)
|
||||
if (error instanceof Error && error.name === 'AbortError') {
|
||||
throw new FetchError('Request timeout', 408, 'TIMEOUT')
|
||||
}
|
||||
throw error
|
||||
return await response.json()
|
||||
} catch {
|
||||
throw new FetchError('Invalid JSON response', response.status, 'INVALID_JSON')
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchWrapperText(
|
||||
url: string,
|
||||
options: FetchWrapperOptions = {}
|
||||
): Promise<string> {
|
||||
const response = await fetchWithTimeout(url, options)
|
||||
return response.text()
|
||||
}
|
||||
|
||||
async function fetchWrapperVoid(
|
||||
url: string,
|
||||
options: FetchWrapperOptions = {}
|
||||
): Promise<void> {
|
||||
await fetchWithTimeout(url, options)
|
||||
}
|
||||
|
||||
async function fetchWrapperBlob(
|
||||
url: string,
|
||||
options: FetchWrapperOptions = {}
|
||||
): Promise<Blob> {
|
||||
const { timeout = 30000, params, ...fetchOptions } = options
|
||||
|
||||
const urlObj = new URL(url, window.location.origin)
|
||||
if (params) {
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
if (value !== undefined) {
|
||||
urlObj.searchParams.append(key, String(value))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const controller = new AbortController()
|
||||
const timeoutId = setTimeout(() => controller.abort(), timeout)
|
||||
|
||||
try {
|
||||
const response = await fetch(urlObj.toString(), {
|
||||
...fetchOptions,
|
||||
signal: controller.signal,
|
||||
})
|
||||
|
||||
clearTimeout(timeoutId)
|
||||
|
||||
if (!response.ok) {
|
||||
await handleResponse(response)
|
||||
}
|
||||
|
||||
return response.blob()
|
||||
} catch (error) {
|
||||
clearTimeout(timeoutId)
|
||||
if (error instanceof Error && error.name === 'AbortError') {
|
||||
throw new FetchError('Request timeout', 408, 'TIMEOUT')
|
||||
}
|
||||
throw error
|
||||
}
|
||||
const response = await fetchWithTimeout(url, options)
|
||||
return response.blob()
|
||||
}
|
||||
|
||||
export { fetchWrapper, fetchWrapperBlob }
|
||||
export { fetchWrapper, fetchWrapperText, fetchWrapperVoid, fetchWrapperBlob }
|
||||
+10
-37
@@ -1,15 +1,10 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { fetchWrapper, fetchWrapperBlob } from './fetchWrapper'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import type { FileInfo, ChunkedFileInfo, PatchOperation } from '@/types/files'
|
||||
|
||||
async function fetchFile(path: string): Promise<FileInfo> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/files/${path}`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to load file: ${response.statusText}`)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
return fetchWrapper(`${API_BASE_URL}/api/files/${path}`)
|
||||
}
|
||||
|
||||
export function useFile(path: string | undefined) {
|
||||
@@ -21,37 +16,21 @@ export function useFile(path: string | undefined) {
|
||||
}
|
||||
|
||||
export async function fetchFileRange(path: string, startLine: number, endLine: number): Promise<ChunkedFileInfo> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/files/${path}?startLine=${startLine}&endLine=${endLine}`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to load file range: ${response.statusText}`)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
return fetchWrapper(`${API_BASE_URL}/api/files/${path}`, {
|
||||
params: { startLine, endLine },
|
||||
})
|
||||
}
|
||||
|
||||
export async function applyFilePatches(path: string, patches: PatchOperation[]): Promise<{ success: boolean; totalLines: number }> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/files/${path}`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/files/${path}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ patches }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to apply patches: ${response.statusText}`)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function getIgnoredPaths(path: string): Promise<{ ignoredPaths: string[] }> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/files/${path}/ignored-paths`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to get ignored paths')
|
||||
}
|
||||
|
||||
return response.json()
|
||||
return fetchWrapper(`${API_BASE_URL}/api/files/${path}/ignored-paths`)
|
||||
}
|
||||
|
||||
export interface DownloadOptions {
|
||||
@@ -65,14 +44,8 @@ export async function downloadDirectoryAsZip(path: string, options?: DownloadOpt
|
||||
if (options?.includePaths?.length) params.append('includePaths', options.includePaths.join(','))
|
||||
|
||||
const url = `${API_BASE_URL}/api/files/${path}/download-zip${params.toString() ? '?' + params.toString() : ''}`
|
||||
const response = await fetch(url)
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json()
|
||||
throw new Error(error.error || 'Failed to download directory')
|
||||
}
|
||||
|
||||
const blob = await response.blob()
|
||||
|
||||
const blob = await fetchWrapperBlob(url)
|
||||
const urlObj = window.URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = urlObj
|
||||
@@ -82,4 +55,4 @@ export async function downloadDirectoryAsZip(path: string, options?: DownloadOpt
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
window.URL.revokeObjectURL(urlObj)
|
||||
}
|
||||
}
|
||||
+25
-117
@@ -1,182 +1,90 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { fetchWrapper, FetchError } from './fetchWrapper'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import type { GitStatusResponse, FileDiffResponse, GitCommit } from '@/types/git'
|
||||
|
||||
export class GitError extends Error {
|
||||
code?: string
|
||||
statusCode?: number
|
||||
|
||||
constructor(message: string, code?: string, statusCode?: number) {
|
||||
super(message)
|
||||
this.name = 'GitError'
|
||||
this.code = code
|
||||
this.statusCode = statusCode
|
||||
}
|
||||
}
|
||||
|
||||
interface ApiError {
|
||||
error: string
|
||||
code?: string
|
||||
}
|
||||
|
||||
async function handleApiError(response: Response): Promise<never> {
|
||||
const data: ApiError = await response.json().catch(() => ({ error: 'An error occurred' }))
|
||||
throw new GitError(data.error, data.code, response.status)
|
||||
}
|
||||
|
||||
export async function fetchGitStatus(repoId: number): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/status`)
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/status`)
|
||||
}
|
||||
|
||||
export async function fetchReposGitStatus(repoIds: number[]): Promise<Map<number, GitStatusResponse>> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/git-status-batch`, {
|
||||
const data = await fetchWrapper<Record<string, GitStatusResponse>>(`${API_BASE_URL}/api/repos/git-status-batch`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ repoIds })
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
return new Map(Object.entries(data).map(([id, status]) => [Number(id), status as GitStatusResponse]))
|
||||
return new Map(Object.entries(data).map(([id, status]) => [Number(id), status]))
|
||||
}
|
||||
|
||||
export async function fetchFileDiff(repoId: number, path: string, includeStaged?: boolean): Promise<FileDiffResponse> {
|
||||
const params = new URLSearchParams({ path })
|
||||
if (includeStaged !== undefined) {
|
||||
params.set('includeStaged', String(includeStaged))
|
||||
}
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/diff-full?${params}`)
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/diff-full`, {
|
||||
params: { path, includeStaged },
|
||||
})
|
||||
}
|
||||
|
||||
export async function fetchGitDiff(repoId: number, path: string): Promise<{ diff: string }> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/diff?path=${encodeURIComponent(path)}`)
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
const data = await fetchWrapper<string>(`${API_BASE_URL}/api/repos/${repoId}/git/diff`, {
|
||||
params: { path },
|
||||
})
|
||||
return { diff: data }
|
||||
}
|
||||
|
||||
export async function fetchGitLog(repoId: number, limit?: number): Promise<{ commits: GitCommit[] }> {
|
||||
const params = limit ? `?limit=${limit}` : ''
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/log${params}`)
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/log`, {
|
||||
params: { limit },
|
||||
})
|
||||
}
|
||||
|
||||
export async function gitFetch(repoId: number): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/fetch`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/fetch`, {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function gitPull(repoId: number): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/pull`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/pull`, {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function gitPush(repoId: number, setUpstream: boolean = false): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/push`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/push`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ setUpstream }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function gitCommit(repoId: number, message: string, stagedPaths?: string[]): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/commit`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/commit`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ message, stagedPaths }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function gitStageFiles(repoId: number, paths: string[]): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/stage`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/stage`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ paths }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function gitUnstageFiles(repoId: number, paths: string[]): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/unstage`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/unstage`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ paths }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function gitReset(repoId: number, commitHash: string): Promise<GitStatusResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/reset`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/git/reset`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ commitHash }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
await handleApiError(response)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export function useGitStatus(repoId: number | undefined) {
|
||||
@@ -227,7 +135,7 @@ function parseGitErrorMessage(message: string): string {
|
||||
}
|
||||
|
||||
export function getApiErrorMessage(error: unknown): string {
|
||||
if (error instanceof GitError) {
|
||||
if (error instanceof FetchError) {
|
||||
if (error.code === 'AUTH_FAILED') {
|
||||
return 'Git authentication failed. Check your credentials in Settings.'
|
||||
}
|
||||
@@ -237,6 +145,9 @@ export function getApiErrorMessage(error: unknown): string {
|
||||
if (error.code === 'NOT_FOUND') {
|
||||
return 'Repository or file not found.'
|
||||
}
|
||||
if (error.statusCode === 401) return 'Git authentication failed. Check your credentials in Settings.'
|
||||
if (error.statusCode === 409) return 'Merge conflict detected. Resolve conflicts before continuing.'
|
||||
if (error.statusCode === 404) return 'Repository or file not found.'
|
||||
return parseGitErrorMessage(error.message)
|
||||
}
|
||||
if (error instanceof Error) {
|
||||
@@ -246,9 +157,6 @@ export function getApiErrorMessage(error: unknown): string {
|
||||
return parseGitErrorMessage(error)
|
||||
}
|
||||
const err = error as { status?: number; message?: string; error?: string }
|
||||
if (err?.status === 401) return 'Git authentication failed. Check your credentials in Settings.'
|
||||
if (err?.status === 409) return 'Merge conflict detected. Resolve conflicts before continuing.'
|
||||
if (err?.status === 404) return 'Repository or file not found.'
|
||||
const message = err?.message || err?.error || String(error) || 'An error occurred'
|
||||
return parseGitErrorMessage(message)
|
||||
}
|
||||
}
|
||||
+22
-86
@@ -1,7 +1,6 @@
|
||||
import { fetchWrapper } from './fetchWrapper'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
|
||||
const API_BASE = API_BASE_URL
|
||||
|
||||
export type McpStatus =
|
||||
| { status: 'connected' }
|
||||
| { status: 'disabled' }
|
||||
@@ -44,171 +43,108 @@ export type McpOAuthFlowStatus =
|
||||
|
||||
export const mcpApi = {
|
||||
async getStatus(): Promise<McpStatusMap> {
|
||||
const response = await fetch(`${API_BASE}/api/opencode/mcp`)
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to get MCP status: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
return fetchWrapper(`${API_BASE_URL}/api/opencode/mcp`)
|
||||
},
|
||||
|
||||
async addServer(name: string, config: McpServerConfig): Promise<McpStatusMap> {
|
||||
const response = await fetch(`${API_BASE}/api/opencode/mcp`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/opencode/mcp`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name, config }),
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to add MCP server: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async connect(name: string): Promise<boolean> {
|
||||
const response = await fetch(`${API_BASE}/api/opencode/mcp/${encodeURIComponent(name)}/connect`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/opencode/mcp/${encodeURIComponent(name)}/connect`, {
|
||||
method: 'POST',
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to connect MCP server: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async disconnect(name: string): Promise<boolean> {
|
||||
const response = await fetch(`${API_BASE}/api/opencode/mcp/${encodeURIComponent(name)}/disconnect`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/opencode/mcp/${encodeURIComponent(name)}/disconnect`, {
|
||||
method: 'POST',
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to disconnect MCP server: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async startAuth(name: string, serverUrl: string, scope?: string, clientId?: string, clientSecret?: string, directory?: string): Promise<McpAuthStartResponse> {
|
||||
const response = await fetch(`${API_BASE}/api/mcp-oauth-proxy/start`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/mcp-oauth-proxy/start`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ serverName: name, serverUrl, scope, clientId, clientSecret, directory }),
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to start MCP auth: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async checkFlowStatus(flowId: string): Promise<McpOAuthFlowStatus> {
|
||||
const response = await fetch(`${API_BASE}/api/mcp-oauth-proxy/status/${encodeURIComponent(flowId)}`)
|
||||
if (!response.ok) {
|
||||
try {
|
||||
return await fetchWrapper(`${API_BASE_URL}/api/mcp-oauth-proxy/status/${encodeURIComponent(flowId)}`)
|
||||
} catch {
|
||||
return { status: 'unknown' }
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async completeAuth(name: string, code: string): Promise<McpStatus> {
|
||||
const response = await fetch(`${API_BASE}/api/opencode/mcp/${encodeURIComponent(name)}/auth/callback`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/opencode/mcp/${encodeURIComponent(name)}/auth/callback`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ code }),
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to complete MCP auth: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async authenticate(name: string): Promise<McpStatus> {
|
||||
const response = await fetch(`${API_BASE}/api/opencode/mcp/${encodeURIComponent(name)}/auth/authenticate`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/opencode/mcp/${encodeURIComponent(name)}/auth/authenticate`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({}),
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to authenticate MCP server: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async removeAuth(name: string): Promise<{ success: true }> {
|
||||
const response = await fetch(`${API_BASE}/api/opencode/mcp/${encodeURIComponent(name)}/auth`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/opencode/mcp/${encodeURIComponent(name)}/auth`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to remove MCP auth: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async getStatusFor(directory: string): Promise<McpStatusMap> {
|
||||
const response = await fetch(`${API_BASE}/api/opencode/mcp?directory=${encodeURIComponent(directory)}`)
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to get MCP status for directory: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
return fetchWrapper(`${API_BASE_URL}/api/opencode/mcp`, {
|
||||
params: { directory },
|
||||
})
|
||||
},
|
||||
|
||||
async getConfigForDirectory(directory: string): Promise<Record<string, unknown>> {
|
||||
const response = await fetch(`${API_BASE}/api/opencode/config?directory=${encodeURIComponent(directory)}`)
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to get config for directory: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
return fetchWrapper(`${API_BASE_URL}/api/opencode/config`, {
|
||||
params: { directory },
|
||||
})
|
||||
},
|
||||
|
||||
async connectDirectory(name: string, directory: string): Promise<boolean> {
|
||||
const response = await fetch(`${API_BASE}/api/settings/mcp/${encodeURIComponent(name)}/connectdirectory`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/settings/mcp/${encodeURIComponent(name)}/connectdirectory`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ directory }),
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to connect MCP server for directory: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async disconnectDirectory(name: string, directory: string): Promise<boolean> {
|
||||
const response = await fetch(`${API_BASE}/api/settings/mcp/${encodeURIComponent(name)}/disconnectdirectory`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/settings/mcp/${encodeURIComponent(name)}/disconnectdirectory`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ directory }),
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to disconnect MCP server for directory: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async authenticateDirectory(name: string, directory: string): Promise<McpStatus> {
|
||||
const response = await fetch(`${API_BASE}/api/settings/mcp/${encodeURIComponent(name)}/authdirectedir`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/settings/mcp/${encodeURIComponent(name)}/authdirectedir`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ directory }),
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to authenticate MCP server for directory: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async removeAuthDirectory(name: string, directory: string): Promise<{ success: true }> {
|
||||
const response = await fetch(`${API_BASE}/api/settings/mcp/${encodeURIComponent(name)}/authdir`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/settings/mcp/${encodeURIComponent(name)}/authdir`, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ directory }),
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to remove MCP auth for directory: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
}
|
||||
@@ -31,7 +31,7 @@ function handleApiError(error: unknown, context: string): never {
|
||||
export const oauthApi = {
|
||||
authorize: async (providerId: string, method: number): Promise<OAuthAuthorizeResponse> => {
|
||||
try {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/oauth/${providerId}/oauth/authorize`, {
|
||||
return await fetchWrapper(`${API_BASE_URL}/api/oauth/${providerId}/oauth/authorize`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ method }),
|
||||
@@ -43,7 +43,7 @@ export const oauthApi = {
|
||||
|
||||
callback: async (providerId: string, request: OAuthCallbackRequest): Promise<boolean> => {
|
||||
try {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/oauth/${providerId}/oauth/callback`, {
|
||||
return await fetchWrapper(`${API_BASE_URL}/api/oauth/${providerId}/oauth/callback`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(request),
|
||||
|
||||
@@ -29,7 +29,7 @@ export class OpenCodeClient {
|
||||
this.directory = directory
|
||||
}
|
||||
|
||||
private getParams(params?: Record<string, unknown>) {
|
||||
private getParams(params?: Record<string, string>) {
|
||||
if (!this.directory) return params
|
||||
return { ...params, directory: this.directory }
|
||||
}
|
||||
|
||||
@@ -205,8 +205,8 @@ async function getProvidersFromOpenCodeServer(): Promise<{ providers: Provider[]
|
||||
|
||||
return { providers, connected: response.connected || [] };
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("Failed to load providers from OpenCode server", error);
|
||||
} catch {
|
||||
// Silently return empty providers on failure - graceful degradation
|
||||
}
|
||||
|
||||
return { providers: [], connected: [] };
|
||||
@@ -258,8 +258,8 @@ async function getConfiguredProviders(connectedIds: Set<string>): Promise<Provid
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.warn("Failed to load configured providers", error);
|
||||
} catch {
|
||||
// Silently return empty providers on failure - graceful degradation
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
+35
-116
@@ -1,4 +1,5 @@
|
||||
import type { Repo } from './types'
|
||||
import { FetchError, fetchWrapper, fetchWrapperText, fetchWrapperVoid, fetchWrapperBlob } from './fetchWrapper'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
|
||||
export async function createRepo(
|
||||
@@ -9,111 +10,57 @@ export async function createRepo(
|
||||
useWorktree?: boolean,
|
||||
skipSSHVerification?: boolean
|
||||
): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ repoUrl, localPath, branch, openCodeConfigName, useWorktree, skipSSHVerification }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json()
|
||||
throw new Error(error.error || 'Failed to create repo')
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function listRepos(): Promise<Repo[]> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to list repos')
|
||||
}
|
||||
|
||||
return response.json()
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos`)
|
||||
}
|
||||
|
||||
export async function getRepo(id: number): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to get repo')
|
||||
}
|
||||
|
||||
return response.json()
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${id}`)
|
||||
}
|
||||
|
||||
export async function deleteRepo(id: number): Promise<void> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}`, {
|
||||
return fetchWrapperVoid(`${API_BASE_URL}/api/repos/${id}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to delete repo')
|
||||
}
|
||||
}
|
||||
|
||||
export async function startServer(id: number, openCodeConfigName?: string): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/server/start`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${id}/server/start`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ openCodeConfigName }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to start server')
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function stopServer(id: number): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/server/stop`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${id}/server/stop`, {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to stop server')
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function pullRepo(id: number): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/pull`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${id}/pull`, {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to pull repo')
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function getServerLogs(id: number): Promise<string> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/server/logs`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to get server logs')
|
||||
}
|
||||
|
||||
return response.text()
|
||||
return fetchWrapperText(`${API_BASE_URL}/api/repos/${id}/server/logs`)
|
||||
}
|
||||
|
||||
export async function switchRepoConfig(id: number, configName: string): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/config/switch`, {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${id}/config/switch`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ configName }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json()
|
||||
throw new Error(error.error || 'Failed to switch config')
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export class GitAuthError extends Error {
|
||||
@@ -126,21 +73,18 @@ export class GitAuthError extends Error {
|
||||
}
|
||||
|
||||
export async function switchBranch(id: number, branch: string): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/branch/switch`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ branch }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json()
|
||||
if (error.code === 'AUTH_FAILED') {
|
||||
throw new GitAuthError(error.error || 'Git authentication failed', error.code)
|
||||
try {
|
||||
return await fetchWrapper(`${API_BASE_URL}/api/repos/${id}/branch/switch`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ branch }),
|
||||
})
|
||||
} catch (error) {
|
||||
if (error instanceof FetchError && error.code === 'AUTH_FAILED') {
|
||||
throw new GitAuthError(error.message, error.code)
|
||||
}
|
||||
throw new Error(error.error || 'Failed to switch branch')
|
||||
throw error
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
interface GitBranch {
|
||||
@@ -154,31 +98,22 @@ interface GitBranch {
|
||||
}
|
||||
|
||||
export async function listBranches(id: number): Promise<{ branches: GitBranch[], status: { ahead: number, behind: number } }> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/git/branches`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to list branches')
|
||||
}
|
||||
|
||||
return response.json()
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${id}/git/branches`)
|
||||
}
|
||||
|
||||
export async function createBranch(id: number, branch: string): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/branch/create`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ branch }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json()
|
||||
if (error.code === 'AUTH_FAILED') {
|
||||
throw new GitAuthError(error.error || 'Git authentication failed', error.code)
|
||||
try {
|
||||
return await fetchWrapper(`${API_BASE_URL}/api/repos/${id}/branch/create`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ branch }),
|
||||
})
|
||||
} catch (error) {
|
||||
if (error instanceof FetchError && error.code === 'AUTH_FAILED') {
|
||||
throw new GitAuthError(error.message, error.code)
|
||||
}
|
||||
throw new Error(error.error || 'Failed to create branch')
|
||||
throw error
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export interface DownloadOptions {
|
||||
@@ -192,14 +127,8 @@ export async function downloadRepo(id: number, repoName: string, options?: Downl
|
||||
if (options?.includePaths?.length) params.append('includePaths', options.includePaths.join(','))
|
||||
|
||||
const url = `${API_BASE_URL}/api/repos/${id}/download${params.toString() ? '?' + params.toString() : ''}`
|
||||
const response = await fetch(url)
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json()
|
||||
throw new Error(error.error || 'Failed to download repo')
|
||||
}
|
||||
|
||||
const blob = await response.blob()
|
||||
|
||||
const blob = await fetchWrapperBlob(url)
|
||||
const urlObj = window.URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = urlObj
|
||||
@@ -211,25 +140,15 @@ export async function downloadRepo(id: number, repoName: string, options?: Downl
|
||||
}
|
||||
|
||||
export async function updateRepoOrder(order: number[]): Promise<void> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/order`, {
|
||||
return fetchWrapperVoid(`${API_BASE_URL}/api/repos/order`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ order }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json()
|
||||
throw new Error(error.error || 'Failed to update repo order')
|
||||
}
|
||||
}
|
||||
|
||||
export async function resetRepoPermissions(id: number): Promise<void> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/reset-permissions`, {
|
||||
return fetchWrapperVoid(`${API_BASE_URL}/api/repos/${id}/reset-permissions`, {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json()
|
||||
throw new Error(error.error || 'Failed to reset permissions')
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,10 @@ import type {
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import { fetchWrapper, FetchError } from './fetchWrapper'
|
||||
|
||||
const DEFAULT_USER_ID = 'default'
|
||||
|
||||
export const settingsApi = {
|
||||
getSettings: async (userId = 'default'): Promise<SettingsResponse> => {
|
||||
getSettings: async (userId = DEFAULT_USER_ID): Promise<SettingsResponse> => {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/settings`, {
|
||||
params: { userId },
|
||||
})
|
||||
@@ -18,7 +20,7 @@ export const settingsApi = {
|
||||
|
||||
updateSettings: async (
|
||||
updates: UpdateSettingsRequest,
|
||||
userId = 'default'
|
||||
userId = DEFAULT_USER_ID
|
||||
): Promise<SettingsResponse> => {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/settings`, {
|
||||
method: 'PATCH',
|
||||
@@ -28,14 +30,14 @@ export const settingsApi = {
|
||||
})
|
||||
},
|
||||
|
||||
resetSettings: async (userId = 'default'): Promise<SettingsResponse> => {
|
||||
resetSettings: async (userId = DEFAULT_USER_ID): Promise<SettingsResponse> => {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/settings`, {
|
||||
method: 'DELETE',
|
||||
params: { userId },
|
||||
})
|
||||
},
|
||||
|
||||
getOpenCodeConfigs: async (userId = 'default'): Promise<OpenCodeConfigResponse> => {
|
||||
getOpenCodeConfigs: async (userId = DEFAULT_USER_ID): Promise<OpenCodeConfigResponse> => {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/settings/opencode-configs`, {
|
||||
params: { userId },
|
||||
})
|
||||
@@ -43,7 +45,7 @@ export const settingsApi = {
|
||||
|
||||
createOpenCodeConfig: async (
|
||||
request: CreateOpenCodeConfigRequest,
|
||||
userId = 'default'
|
||||
userId = DEFAULT_USER_ID
|
||||
): Promise<OpenCodeConfig> => {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/settings/opencode-configs`, {
|
||||
method: 'POST',
|
||||
@@ -56,7 +58,7 @@ export const settingsApi = {
|
||||
updateOpenCodeConfig: async (
|
||||
configName: string,
|
||||
request: UpdateOpenCodeConfigRequest,
|
||||
userId = 'default'
|
||||
userId = DEFAULT_USER_ID
|
||||
): Promise<OpenCodeConfig> => {
|
||||
return fetchWrapper(
|
||||
`${API_BASE_URL}/api/settings/opencode-configs/${encodeURIComponent(configName)}`,
|
||||
@@ -71,7 +73,7 @@ export const settingsApi = {
|
||||
|
||||
deleteOpenCodeConfig: async (
|
||||
configName: string,
|
||||
userId = 'default'
|
||||
userId = DEFAULT_USER_ID
|
||||
): Promise<boolean> => {
|
||||
await fetchWrapper(
|
||||
`${API_BASE_URL}/api/settings/opencode-configs/${encodeURIComponent(configName)}`,
|
||||
@@ -85,7 +87,7 @@ export const settingsApi = {
|
||||
|
||||
setDefaultOpenCodeConfig: async (
|
||||
configName: string,
|
||||
userId = 'default'
|
||||
userId = DEFAULT_USER_ID
|
||||
): Promise<OpenCodeConfig> => {
|
||||
return fetchWrapper(
|
||||
`${API_BASE_URL}/api/settings/opencode-configs/${encodeURIComponent(configName)}/set-default`,
|
||||
@@ -98,7 +100,7 @@ export const settingsApi = {
|
||||
)
|
||||
},
|
||||
|
||||
getDefaultOpenCodeConfig: async (userId = 'default'): Promise<OpenCodeConfig | null> => {
|
||||
getDefaultOpenCodeConfig: async (userId = DEFAULT_USER_ID): Promise<OpenCodeConfig | null> => {
|
||||
try {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/settings/opencode-configs/default`, {
|
||||
params: { userId },
|
||||
|
||||
@@ -210,7 +210,7 @@ export type ContentPart =
|
||||
| { type: 'file', path: string, name: string }
|
||||
| { type: 'image', id: string, filename: string, mime: string, dataUrl: string }
|
||||
|
||||
export interface FileInfo {
|
||||
export interface FileAttachmentInfo {
|
||||
path: string
|
||||
name: string
|
||||
mime?: string
|
||||
|
||||
Reference in new issue
Block a user