Files
Hermes-ui/packages/client/src/api/coding-agents.ts
T
ekko 285f623d6f [codex] 修复 Coding Agents 的 Codex 启动和代理隔离 (#1123)
* feat: add coding agent install status

* chore: add latest claude opus model preset

* feat: add coding agent config editing

* Add scoped coding agent launch proxy

* Add Codex proxy plan

* fix coding agents codex launch proxy

* fix codex catalog context test

---------

Co-authored-by: Codex <codex@openai.com>
2026-05-29 19:06:54 +08:00

134 lines
3.7 KiB
TypeScript

import { request } from './client'
export type CodingAgentId = 'claude-code' | 'codex'
export type CodingAgentApiMode = 'chat_completions' | 'codex_responses' | 'anthropic_messages'
export type CodingAgentLaunchMode = 'scoped' | 'global'
export interface CodingAgentToolStatus {
id: CodingAgentId
name: string
provider: string
command: string
packageName: string
installed: boolean
version: string
rawVersion: string
error?: string
}
export interface CodingAgentsStatus {
tools: CodingAgentToolStatus[]
}
export interface CodingAgentMutationResult extends CodingAgentsStatus {
success: boolean
tool: CodingAgentToolStatus
message?: string
}
export interface CodingAgentConfigFileContent {
key: string
path: string
absolutePath: string
language: string
content: string
exists: boolean
size: number
profile: string
provider: string
rootDir: string
}
export interface CodingAgentConfigScope {
profile?: string | null
provider?: string | null
}
export interface CodingAgentLaunchRequest {
mode?: CodingAgentLaunchMode
profile?: string | null
provider?: string
model?: string
baseUrl?: string
apiKey?: string
apiMode?: CodingAgentApiMode
}
export interface CodingAgentLaunchResult {
agentId: CodingAgentId
mode: CodingAgentLaunchMode
profile: string
provider: string
model: string
rootDir: string
workspaceDir: string
command: string
args: string[]
env: Record<string, string>
shellCommand: string
files: Array<{ key: string; path: string; absolutePath: string }>
}
export interface CodingAgentNativeLaunchResult extends CodingAgentLaunchResult {
nativeTerminal: true
terminal: string
}
export async function fetchCodingAgentsStatus(): Promise<CodingAgentsStatus> {
return request<CodingAgentsStatus>('/api/coding-agents')
}
export async function installCodingAgent(id: CodingAgentId): Promise<CodingAgentMutationResult> {
return request<CodingAgentMutationResult>(`/api/coding-agents/${id}/install`, { method: 'POST' })
}
export async function deleteCodingAgent(id: CodingAgentId): Promise<CodingAgentMutationResult> {
return request<CodingAgentMutationResult>(`/api/coding-agents/${id}`, { method: 'DELETE' })
}
export async function readCodingAgentConfigFile(
id: CodingAgentId,
key: string,
scope: CodingAgentConfigScope = {},
): Promise<CodingAgentConfigFileContent> {
const params = new URLSearchParams()
if (scope.profile) params.set('profile', scope.profile)
if (scope.provider) params.set('provider', scope.provider)
const query = params.toString()
return request<CodingAgentConfigFileContent>(
`/api/coding-agents/${id}/config-files/${encodeURIComponent(key)}${query ? `?${query}` : ''}`,
)
}
export async function writeCodingAgentConfigFile(
id: CodingAgentId,
key: string,
content: string,
scope: CodingAgentConfigScope = {},
): Promise<CodingAgentConfigFileContent> {
return request<CodingAgentConfigFileContent>(`/api/coding-agents/${id}/config-files/${encodeURIComponent(key)}`, {
method: 'PUT',
body: JSON.stringify({ content, profile: scope.profile, provider: scope.provider }),
})
}
export async function prepareCodingAgentLaunch(
id: CodingAgentId,
data: CodingAgentLaunchRequest,
): Promise<CodingAgentLaunchResult> {
return request<CodingAgentLaunchResult>(`/api/coding-agents/${id}/launch/prepare`, {
method: 'POST',
body: JSON.stringify(data),
})
}
export async function launchCodingAgentNativeTerminal(
id: CodingAgentId,
data: CodingAgentLaunchRequest,
): Promise<CodingAgentNativeLaunchResult> {
return request<CodingAgentNativeLaunchResult>(`/api/coding-agents/${id}/launch/native`, {
method: 'POST',
body: JSON.stringify(data),
})
}