mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Initial release v0.2.5
This commit is contained in:
commit
bbf66c259b
158 files changed
+37115
No files matched your search
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,123 @@
|
||||
import axios, { type AxiosInstance } from 'axios'
|
||||
import type { paths } from './opencode-types'
|
||||
|
||||
type SessionListResponse = paths['/session']['get']['responses']['200']['content']['application/json']
|
||||
type SessionResponse = paths['/session/{id}']['get']['responses']['200']['content']['application/json']
|
||||
type CreateSessionRequest = NonNullable<paths['/session']['post']['requestBody']>['content']['application/json']
|
||||
type MessageListResponse = paths['/session/{id}/message']['get']['responses']['200']['content']['application/json']
|
||||
type SendPromptRequest = NonNullable<paths['/session/{id}/message']['post']['requestBody']>['content']['application/json']
|
||||
type ConfigResponse = paths['/config']['get']['responses']['200']['content']['application/json']
|
||||
type CommandListResponse = paths['/command']['get']['responses']['200']['content']['application/json']
|
||||
type CommandRequest = NonNullable<paths['/session/{id}/command']['post']['requestBody']>['content']['application/json']
|
||||
type ShellRequest = NonNullable<paths['/session/{id}/shell']['post']['requestBody']>['content']['application/json']
|
||||
|
||||
export class OpenCodeClient {
|
||||
private client: AxiosInstance
|
||||
private baseURL: string
|
||||
private directory?: string
|
||||
|
||||
constructor(baseURL: string, directory?: string) {
|
||||
this.baseURL = baseURL
|
||||
this.directory = directory
|
||||
this.client = axios.create({
|
||||
baseURL,
|
||||
timeout: 30000
|
||||
})
|
||||
|
||||
this.client.interceptors.request.use((config) => {
|
||||
if (this.directory) {
|
||||
config.params = { ...config.params, directory: this.directory }
|
||||
}
|
||||
return config
|
||||
})
|
||||
}
|
||||
|
||||
setDirectory(directory: string) {
|
||||
this.directory = directory
|
||||
}
|
||||
|
||||
async listSessions() {
|
||||
const response = await this.client.get<SessionListResponse>('/session')
|
||||
return response.data
|
||||
}
|
||||
|
||||
async getSession(sessionID: string) {
|
||||
const response = await this.client.get<SessionResponse>(`/session/${sessionID}`)
|
||||
return response.data
|
||||
}
|
||||
|
||||
async createSession(data: CreateSessionRequest) {
|
||||
const response = await this.client.post<SessionResponse>('/session', data)
|
||||
return response.data
|
||||
}
|
||||
|
||||
async deleteSession(sessionID: string) {
|
||||
await this.client.delete(`/session/${sessionID}`)
|
||||
}
|
||||
|
||||
async forkSession(sessionID: string, messageID?: string) {
|
||||
const response = await this.client.post<SessionResponse>(`/session/${sessionID}/fork`, {
|
||||
messageID
|
||||
})
|
||||
return response.data
|
||||
}
|
||||
|
||||
async abortSession(sessionID: string) {
|
||||
await this.client.post(`/session/${sessionID}/abort`)
|
||||
}
|
||||
|
||||
async listMessages(sessionID: string) {
|
||||
const response = await this.client.get<MessageListResponse>(`/session/${sessionID}/message`)
|
||||
return response.data
|
||||
}
|
||||
|
||||
async sendPrompt(sessionID: string, data: SendPromptRequest) {
|
||||
const response = await this.client.post(`/session/${sessionID}/message`, data)
|
||||
return response.data
|
||||
}
|
||||
|
||||
async getConfig() {
|
||||
const response = await this.client.get<ConfigResponse>('/config')
|
||||
return response.data
|
||||
}
|
||||
|
||||
async updateConfig(config: Partial<ConfigResponse>) {
|
||||
const response = await this.client.patch<ConfigResponse>('/config', config)
|
||||
return response.data
|
||||
}
|
||||
|
||||
async getProviders() {
|
||||
const response = await this.client.get('/config/providers')
|
||||
return response.data
|
||||
}
|
||||
|
||||
async listCommands() {
|
||||
const response = await this.client.get<CommandListResponse>('/command')
|
||||
return response.data
|
||||
}
|
||||
|
||||
async sendCommand(sessionID: string, data: CommandRequest) {
|
||||
const response = await this.client.post(`/session/${sessionID}/command`, data)
|
||||
return response.data
|
||||
}
|
||||
|
||||
async sendShell(sessionID: string, data: ShellRequest) {
|
||||
const response = await this.client.post(`/session/${sessionID}/shell`, data)
|
||||
return response.data
|
||||
}
|
||||
|
||||
getEventSourceURL() {
|
||||
const base = this.baseURL.startsWith('http')
|
||||
? this.baseURL
|
||||
: `${window.location.origin}${this.baseURL}`
|
||||
const url = new URL(`${base}/event`)
|
||||
if (this.directory) {
|
||||
url.searchParams.set('directory', this.directory)
|
||||
}
|
||||
return url.toString()
|
||||
}
|
||||
}
|
||||
|
||||
export const createOpenCodeClient = (baseURL: string, directory?: string) => {
|
||||
return new OpenCodeClient(baseURL, directory)
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
import { settingsApi } from "./settings";
|
||||
import axios from "axios";
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_URL || "http://localhost:5001";
|
||||
|
||||
export interface Model {
|
||||
id: string;
|
||||
name: string;
|
||||
release_date?: string;
|
||||
attachment?: boolean;
|
||||
reasoning?: boolean;
|
||||
temperature?: boolean;
|
||||
tool_call?: boolean;
|
||||
cost?: {
|
||||
input: number;
|
||||
output: number;
|
||||
cache_read?: number;
|
||||
cache_write?: number;
|
||||
};
|
||||
limit?: {
|
||||
context: number;
|
||||
output: number;
|
||||
};
|
||||
modalities?: {
|
||||
input: ("text" | "audio" | "image" | "video" | "pdf")[];
|
||||
output: ("text" | "audio" | "image" | "video" | "pdf")[];
|
||||
};
|
||||
experimental?: boolean;
|
||||
status?: "alpha" | "beta";
|
||||
options?: Record<string, unknown>;
|
||||
provider?: {
|
||||
npm: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface Provider {
|
||||
id: string;
|
||||
name: string;
|
||||
api?: string;
|
||||
env: string[];
|
||||
npm?: string;
|
||||
models: Record<string, Model>;
|
||||
}
|
||||
|
||||
export interface ProviderWithModels {
|
||||
id: string;
|
||||
name: string;
|
||||
api?: string;
|
||||
env: string[];
|
||||
npm?: string;
|
||||
models: Model[];
|
||||
}
|
||||
|
||||
// Default providers for common OpenCode setups
|
||||
const DEFAULT_PROVIDERS: Provider[] = [
|
||||
{
|
||||
id: "anthropic",
|
||||
name: "Anthropic",
|
||||
api: "https://api.anthropic.com",
|
||||
env: ["ANTHROPIC_API_KEY"],
|
||||
npm: "@anthropic-ai/sdk",
|
||||
models: {
|
||||
"claude-3-5-sonnet-20241022": {
|
||||
id: "claude-3-5-sonnet-20241022",
|
||||
name: "Claude 3.5 Sonnet (October 2024)",
|
||||
release_date: "2024-10-22",
|
||||
attachment: true,
|
||||
reasoning: false,
|
||||
temperature: true,
|
||||
tool_call: true,
|
||||
cost: { input: 3, output: 15 },
|
||||
limit: { context: 200000, output: 8192 },
|
||||
modalities: { input: ["text", "image"], output: ["text"] },
|
||||
experimental: false,
|
||||
},
|
||||
"claude-3-5-haiku-20241022": {
|
||||
id: "claude-3-5-haiku-20241022",
|
||||
name: "Claude 3.5 Haiku (October 2024)",
|
||||
release_date: "2024-10-22",
|
||||
attachment: true,
|
||||
reasoning: false,
|
||||
temperature: true,
|
||||
tool_call: true,
|
||||
cost: { input: 1, output: 5 },
|
||||
limit: { context: 200000, output: 8192 },
|
||||
modalities: { input: ["text", "image"], output: ["text"] },
|
||||
experimental: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "openai",
|
||||
name: "OpenAI",
|
||||
api: "https://api.openai.com/v1",
|
||||
env: ["OPENAI_API_KEY"],
|
||||
npm: "openai",
|
||||
models: {
|
||||
"gpt-4o": {
|
||||
id: "gpt-4o",
|
||||
name: "GPT-4o",
|
||||
release_date: "2024-05-13",
|
||||
attachment: true,
|
||||
reasoning: false,
|
||||
temperature: true,
|
||||
tool_call: true,
|
||||
cost: { input: 5, output: 15 },
|
||||
limit: { context: 128000, output: 4096 },
|
||||
modalities: {
|
||||
input: ["text", "image", "audio"],
|
||||
output: ["text", "audio"],
|
||||
},
|
||||
experimental: false,
|
||||
},
|
||||
"gpt-4o-mini": {
|
||||
id: "gpt-4o-mini",
|
||||
name: "GPT-4o Mini",
|
||||
release_date: "2024-07-18",
|
||||
attachment: true,
|
||||
reasoning: false,
|
||||
temperature: true,
|
||||
tool_call: true,
|
||||
cost: { input: 0.15, output: 0.6 },
|
||||
limit: { context: 128000, output: 16384 },
|
||||
modalities: { input: ["text", "image"], output: ["text"] },
|
||||
experimental: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "google",
|
||||
name: "Google",
|
||||
api: "https://generativelanguage.googleapis.com/v1beta",
|
||||
env: ["GOOGLE_API_KEY"],
|
||||
npm: "@google/generative-ai",
|
||||
models: {
|
||||
"gemini-1.5-pro": {
|
||||
id: "gemini-1.5-pro",
|
||||
name: "Gemini 1.5 Pro",
|
||||
release_date: "2024-02-15",
|
||||
attachment: true,
|
||||
reasoning: false,
|
||||
temperature: true,
|
||||
tool_call: true,
|
||||
cost: { input: 3.5, output: 10.5 },
|
||||
limit: { context: 2000000, output: 8192 },
|
||||
modalities: {
|
||||
input: ["text", "image", "audio", "video"],
|
||||
output: ["text"],
|
||||
},
|
||||
experimental: false,
|
||||
},
|
||||
"gemini-1.5-flash": {
|
||||
id: "gemini-1.5-flash",
|
||||
name: "Gemini 1.5 Flash",
|
||||
release_date: "2024-02-15",
|
||||
attachment: true,
|
||||
reasoning: false,
|
||||
temperature: true,
|
||||
tool_call: true,
|
||||
cost: { input: 0.075, output: 0.3 },
|
||||
limit: { context: 1000000, output: 8192 },
|
||||
modalities: {
|
||||
input: ["text", "image", "audio", "video"],
|
||||
output: ["text"],
|
||||
},
|
||||
experimental: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
async function getProvidersFromConfig(): Promise<Provider[]> {
|
||||
try {
|
||||
const configResponse = await settingsApi.getDefaultOpenCodeConfig();
|
||||
if (configResponse?.content?.provider) {
|
||||
const providerRecord = configResponse.content.provider as Record<string, Provider>;
|
||||
const providers = Object.entries(providerRecord).map(([id, provider]) => ({
|
||||
...provider,
|
||||
id: provider.id || id,
|
||||
}));
|
||||
return providers;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("Failed to load OpenCode config", error);
|
||||
}
|
||||
|
||||
return DEFAULT_PROVIDERS;
|
||||
}
|
||||
|
||||
export async function getProviders(): Promise<Provider[]> {
|
||||
return await getProvidersFromConfig();
|
||||
}
|
||||
|
||||
export async function getProvidersWithModels(): Promise<ProviderWithModels[]> {
|
||||
const providers = await getProviders();
|
||||
|
||||
const result = providers.map((provider) => {
|
||||
const models = Object.entries(provider.models || {}).map(([id, model]) => ({
|
||||
...model,
|
||||
id: model.id || id,
|
||||
name: model.name || id,
|
||||
}));
|
||||
return {
|
||||
id: provider.id,
|
||||
name: provider.name,
|
||||
api: provider.api,
|
||||
env: provider.env || [],
|
||||
npm: provider.npm,
|
||||
models,
|
||||
};
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function getModel(
|
||||
providerId: string,
|
||||
modelId: string,
|
||||
): Promise<Model | null> {
|
||||
const providers = await getProvidersWithModels();
|
||||
const provider = providers.find((p) => p.id === providerId);
|
||||
if (!provider) return null;
|
||||
|
||||
return provider.models.find((m) => m.id === modelId) || null;
|
||||
}
|
||||
|
||||
export function formatModelName(model: Model): string {
|
||||
return model.name || model.id;
|
||||
}
|
||||
|
||||
export function formatProviderName(
|
||||
provider: Provider | ProviderWithModels,
|
||||
): string {
|
||||
return provider.name || provider.id;
|
||||
}
|
||||
|
||||
export const providerCredentialsApi = {
|
||||
list: async (): Promise<string[]> => {
|
||||
const { data } = await axios.get(`${API_BASE_URL}/api/providers/credentials`);
|
||||
return data.providers;
|
||||
},
|
||||
|
||||
getStatus: async (providerId: string): Promise<boolean> => {
|
||||
const { data } = await axios.get(
|
||||
`${API_BASE_URL}/api/providers/${providerId}/credentials/status`
|
||||
);
|
||||
return data.hasCredentials;
|
||||
},
|
||||
|
||||
set: async (providerId: string, apiKey: string): Promise<void> => {
|
||||
await axios.post(`${API_BASE_URL}/api/providers/${providerId}/credentials`, {
|
||||
apiKey,
|
||||
});
|
||||
},
|
||||
|
||||
delete: async (providerId: string): Promise<void> => {
|
||||
await axios.delete(`${API_BASE_URL}/api/providers/${providerId}/credentials`);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,141 @@
|
||||
import type { Repo } from './types'
|
||||
|
||||
const API_BASE = import.meta.env.VITE_API_URL ?? 'http://localhost:5001'
|
||||
|
||||
export async function createRepo(
|
||||
repoUrl: string,
|
||||
branch?: string,
|
||||
openCodeConfigName?: string,
|
||||
useWorktree?: boolean
|
||||
): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE}/api/repos`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ repoUrl, branch, openCodeConfigName, useWorktree }),
|
||||
})
|
||||
|
||||
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}/api/repos`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to list repos')
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function getRepo(id: number): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE}/api/repos/${id}`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to get repo')
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function deleteRepo(id: number): Promise<void> {
|
||||
const response = await fetch(`${API_BASE}/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}/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}/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}/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}/api/repos/${id}/server/logs`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to get server logs')
|
||||
}
|
||||
|
||||
return response.text()
|
||||
}
|
||||
|
||||
export async function switchRepoConfig(id: number, configName: string): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE}/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 async function switchBranch(id: number, branch: string): Promise<Repo> {
|
||||
const response = await fetch(`${API_BASE}/api/repos/${id}/branch/switch`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ branch }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json()
|
||||
throw new Error(error.error || 'Failed to switch branch')
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function listBranches(id: number): Promise<{ local: string[], remote: string[], current: string | null }> {
|
||||
const response = await fetch(`${API_BASE}/api/repos/${id}/branches`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to list branches')
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import axios from 'axios'
|
||||
import type {
|
||||
SettingsResponse,
|
||||
UpdateSettingsRequest,
|
||||
OpenCodeConfig,
|
||||
OpenCodeConfigResponse,
|
||||
CreateOpenCodeConfigRequest,
|
||||
UpdateOpenCodeConfigRequest
|
||||
} from './types/settings'
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:5001'
|
||||
|
||||
export const settingsApi = {
|
||||
getSettings: async (userId = 'default'): Promise<SettingsResponse> => {
|
||||
const { data } = await axios.get(`${API_BASE_URL}/api/settings`, {
|
||||
params: { userId },
|
||||
})
|
||||
return data
|
||||
},
|
||||
|
||||
updateSettings: async (
|
||||
updates: UpdateSettingsRequest,
|
||||
userId = 'default'
|
||||
): Promise<SettingsResponse> => {
|
||||
const { data } = await axios.patch(`${API_BASE_URL}/api/settings`, updates, {
|
||||
params: { userId },
|
||||
})
|
||||
return data
|
||||
},
|
||||
|
||||
resetSettings: async (userId = 'default'): Promise<SettingsResponse> => {
|
||||
const { data } = await axios.delete(`${API_BASE_URL}/api/settings`, {
|
||||
params: { userId },
|
||||
})
|
||||
return data
|
||||
},
|
||||
|
||||
getOpenCodeConfigs: async (userId = 'default'): Promise<OpenCodeConfigResponse> => {
|
||||
const { data } = await axios.get(`${API_BASE_URL}/api/settings/opencode-configs`, {
|
||||
params: { userId },
|
||||
})
|
||||
return data
|
||||
},
|
||||
|
||||
createOpenCodeConfig: async (
|
||||
request: CreateOpenCodeConfigRequest,
|
||||
userId = 'default'
|
||||
): Promise<OpenCodeConfig> => {
|
||||
const { data } = await axios.post(`${API_BASE_URL}/api/settings/opencode-configs`, request, {
|
||||
params: { userId },
|
||||
})
|
||||
return data
|
||||
},
|
||||
|
||||
updateOpenCodeConfig: async (
|
||||
configName: string,
|
||||
request: UpdateOpenCodeConfigRequest,
|
||||
userId = 'default'
|
||||
): Promise<OpenCodeConfig> => {
|
||||
const { data } = await axios.put(
|
||||
`${API_BASE_URL}/api/settings/opencode-configs/${encodeURIComponent(configName)}`,
|
||||
request,
|
||||
{ params: { userId } }
|
||||
)
|
||||
return data
|
||||
},
|
||||
|
||||
deleteOpenCodeConfig: async (
|
||||
configName: string,
|
||||
userId = 'default'
|
||||
): Promise<boolean> => {
|
||||
await axios.delete(
|
||||
`${API_BASE_URL}/api/settings/opencode-configs/${encodeURIComponent(configName)}`,
|
||||
{ params: { userId } }
|
||||
)
|
||||
return true
|
||||
},
|
||||
|
||||
setDefaultOpenCodeConfig: async (
|
||||
configName: string,
|
||||
userId = 'default'
|
||||
): Promise<OpenCodeConfig> => {
|
||||
const { data } = await axios.post(
|
||||
`${API_BASE_URL}/api/settings/opencode-configs/${encodeURIComponent(configName)}/set-default`,
|
||||
{},
|
||||
{ params: { userId } }
|
||||
)
|
||||
return data
|
||||
},
|
||||
|
||||
getDefaultOpenCodeConfig: async (userId = 'default'): Promise<OpenCodeConfig | null> => {
|
||||
try {
|
||||
const { data } = await axios.get(`${API_BASE_URL}/api/settings/opencode-configs/default`, {
|
||||
params: { userId },
|
||||
})
|
||||
return data
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
export interface Repo {
|
||||
id: number
|
||||
repoUrl: string
|
||||
localPath: string
|
||||
fullPath: string
|
||||
branch?: string
|
||||
currentBranch?: string
|
||||
defaultBranch: string
|
||||
cloneStatus: 'cloning' | 'ready' | 'error'
|
||||
clonedAt: number
|
||||
lastPulled?: number
|
||||
openCodeConfigName?: string
|
||||
isWorktree?: boolean
|
||||
}
|
||||
|
||||
import type { components } from './opencode-types'
|
||||
|
||||
export type Message = components['schemas']['Message']
|
||||
export type Part = components['schemas']['Part']
|
||||
export type Session = components['schemas']['Session']
|
||||
|
||||
export type MessageWithParts = {
|
||||
info: Message
|
||||
parts: Part[]
|
||||
}
|
||||
|
||||
export type MessageListResponse = MessageWithParts[]
|
||||
|
||||
export interface SSEMessagePartUpdatedEvent {
|
||||
type: 'message.part.updated' | 'messagev2.part.updated'
|
||||
properties: {
|
||||
part: Part
|
||||
}
|
||||
}
|
||||
|
||||
export interface SSEMessageUpdatedEvent {
|
||||
type: 'message.updated' | 'messagev2.updated'
|
||||
properties: {
|
||||
info: Message
|
||||
}
|
||||
}
|
||||
|
||||
export interface SSEMessageRemovedEvent {
|
||||
type: 'message.removed' | 'messagev2.removed'
|
||||
properties: {
|
||||
sessionID: string
|
||||
messageID: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface SSEMessagePartRemovedEvent {
|
||||
type: 'message.part.removed' | 'messagev2.part.removed'
|
||||
properties: {
|
||||
sessionID: string
|
||||
messageID: string
|
||||
partID: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface SSESessionUpdatedEvent {
|
||||
type: 'session.updated'
|
||||
properties: {
|
||||
info: Session
|
||||
}
|
||||
}
|
||||
|
||||
export interface SSESessionDeletedEvent {
|
||||
type: 'session.deleted'
|
||||
properties: {
|
||||
sessionID: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface SSESessionCompactedEvent {
|
||||
type: 'session.compacted'
|
||||
properties: {
|
||||
sessionID: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface SSETodoUpdatedEvent {
|
||||
type: 'todo.updated'
|
||||
properties: {
|
||||
sessionID: string
|
||||
todos: components['schemas']['Todo'][]
|
||||
}
|
||||
}
|
||||
|
||||
export type SSEEvent =
|
||||
| SSEMessagePartUpdatedEvent
|
||||
| SSEMessageUpdatedEvent
|
||||
| SSEMessageRemovedEvent
|
||||
| SSEMessagePartRemovedEvent
|
||||
| SSESessionUpdatedEvent
|
||||
| SSESessionDeletedEvent
|
||||
| SSESessionCompactedEvent
|
||||
| SSETodoUpdatedEvent
|
||||
| { type: 'permission.updated'; properties: Record<string, unknown> }
|
||||
| { type: 'permission.replied'; properties: Record<string, unknown> }
|
||||
|
||||
export type ContentPart =
|
||||
| { type: 'text', content: string }
|
||||
| { type: 'file', path: string, name: string }
|
||||
|
||||
export interface FileInfo {
|
||||
path: string
|
||||
name: string
|
||||
mime?: string
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
export interface CustomCommand {
|
||||
name: string
|
||||
description: string
|
||||
promptTemplate: string
|
||||
}
|
||||
|
||||
export interface CustomAgent {
|
||||
name: string
|
||||
description: string
|
||||
config: Record<string, unknown>
|
||||
}
|
||||
|
||||
export interface UserPreferences {
|
||||
theme: 'dark' | 'light' | 'system'
|
||||
mode: 'plan' | 'build'
|
||||
defaultModel?: string
|
||||
defaultAgent?: string
|
||||
autoScroll: boolean
|
||||
showReasoning: boolean
|
||||
expandToolCalls: boolean
|
||||
keyboardShortcuts: Record<string, string>
|
||||
customCommands: CustomCommand[]
|
||||
customAgents: CustomAgent[]
|
||||
gitToken?: string
|
||||
}
|
||||
|
||||
export interface SettingsResponse {
|
||||
preferences: UserPreferences
|
||||
updatedAt: number
|
||||
}
|
||||
|
||||
export interface UpdateSettingsRequest {
|
||||
preferences: Partial<UserPreferences>
|
||||
}
|
||||
|
||||
export interface OpenCodeConfig {
|
||||
id: number
|
||||
name: string
|
||||
content: Record<string, unknown>
|
||||
isDefault: boolean
|
||||
createdAt: number
|
||||
updatedAt: number
|
||||
}
|
||||
|
||||
export interface CreateOpenCodeConfigRequest {
|
||||
name: string
|
||||
content: Record<string, unknown>
|
||||
isDefault?: boolean
|
||||
}
|
||||
|
||||
export interface UpdateOpenCodeConfigRequest {
|
||||
content: Record<string, unknown>
|
||||
isDefault?: boolean
|
||||
}
|
||||
|
||||
export interface OpenCodeConfigResponse {
|
||||
configs: OpenCodeConfig[]
|
||||
defaultConfig: OpenCodeConfig | null
|
||||
}
|
||||
|
||||
const isMac = typeof navigator !== 'undefined' && navigator.platform.toUpperCase().indexOf('MAC') >= 0
|
||||
const CMD_KEY = isMac ? 'Cmd' : 'Ctrl'
|
||||
|
||||
export const DEFAULT_KEYBOARD_SHORTCUTS: Record<string, string> = {
|
||||
submit: `${CMD_KEY}+Enter`,
|
||||
abort: 'Escape',
|
||||
toggleMode: 'Tab',
|
||||
undo: `${CMD_KEY}+Z`,
|
||||
redo: `${CMD_KEY}+Shift+Z`,
|
||||
compact: `${CMD_KEY}+K`,
|
||||
fork: `${CMD_KEY}+Shift+F`,
|
||||
settings: `${CMD_KEY}+,`,
|
||||
sessions: `${CMD_KEY}+S`,
|
||||
newSession: `${CMD_KEY}+N`,
|
||||
closeSession: `${CMD_KEY}+W`,
|
||||
toggleSidebar: `${CMD_KEY}+B`,
|
||||
selectModel: `${CMD_KEY}+M`,
|
||||
}
|
||||
|
||||
export const DEFAULT_USER_PREFERENCES: UserPreferences = {
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
autoScroll: true,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
keyboardShortcuts: DEFAULT_KEYBOARD_SHORTCUTS,
|
||||
customCommands: [],
|
||||
customAgents: [],
|
||||
gitToken: undefined,
|
||||
}
|
||||
Reference in new issue
Block a user