mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
* fix(opencode): use ACP-reported reasoning effort options Expose thought_level options from OpenCode ACP to the web UI via RPC/API instead of hardcoded presets, and validate effort values before setConfigOption. Fixes #852 Co-authored-by: Cursor <cursoragent@cursor.com> * fix(opencode): sync hub effort after coerced setConfigOption When resolveThoughtLevelEffort falls back to a different supported value, roll back session state after a successful ACP update so keepalive and the web UI do not keep advertising the rejected effort. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
680 lines
24 KiB
TypeScript
680 lines
24 KiB
TypeScript
import type {
|
|
AttachmentMetadata,
|
|
AuthResponse,
|
|
CodexLocalSessionsResponse,
|
|
CodexDuplicateSessionsResponse,
|
|
CodexMergeDuplicateSessionsResponse,
|
|
CodexDesktopScriptResponse,
|
|
CodexDesktopSyncRequest,
|
|
CodexDesktopStatusResponse,
|
|
CodexCollaborationMode,
|
|
FileSearchResponse,
|
|
MachinesResponse,
|
|
MessagesResponse,
|
|
PermissionMode,
|
|
PushSubscriptionPayload,
|
|
PushUnsubscribePayload,
|
|
PushVapidPublicKeyResponse,
|
|
SlashCommandsResponse,
|
|
SkillsResponse,
|
|
SpawnResponse,
|
|
VisibilityPayload,
|
|
HapiSessionExport,
|
|
SessionResponse,
|
|
SessionsResponse
|
|
} from '@/types/api'
|
|
import type {
|
|
CodexModelsResponse,
|
|
CursorModelsResponse,
|
|
DeleteUploadResponse,
|
|
FileReadResponse,
|
|
GitCommandResponse,
|
|
ListDirectoryResponse,
|
|
MachineListDirectoryResponse,
|
|
MachinePathsExistsResponse,
|
|
OpencodeModelsResponse,
|
|
OpencodeReasoningEffortResponse,
|
|
ReopenSessionResponse,
|
|
UploadFileResponse
|
|
} from '@hapi/protocol/apiTypes'
|
|
import type { AgentFlavor } from '@hapi/protocol'
|
|
import type { CancelMessageResponse } from '@hapi/protocol/schemas'
|
|
|
|
type ApiClientOptions = {
|
|
baseUrl?: string
|
|
getToken?: () => string | null
|
|
onUnauthorized?: () => Promise<string | null>
|
|
}
|
|
|
|
type ErrorPayload = {
|
|
error?: unknown
|
|
code?: unknown
|
|
}
|
|
|
|
function parseErrorCode(bodyText: string): string | undefined {
|
|
try {
|
|
const parsed = JSON.parse(bodyText) as ErrorPayload
|
|
if (typeof parsed.code === 'string') return parsed.code
|
|
if (typeof parsed.error === 'string') return parsed.error
|
|
return undefined
|
|
} catch {
|
|
return undefined
|
|
}
|
|
}
|
|
|
|
export class ApiError extends Error {
|
|
status: number
|
|
code?: string
|
|
body?: string
|
|
|
|
constructor(message: string, status: number, code?: string, body?: string) {
|
|
super(message)
|
|
this.name = 'ApiError'
|
|
this.status = status
|
|
this.code = code
|
|
this.body = body
|
|
}
|
|
}
|
|
|
|
export class ApiClient {
|
|
private token: string
|
|
private readonly baseUrl: string | null
|
|
private readonly getToken: (() => string | null) | null
|
|
private readonly onUnauthorized: (() => Promise<string | null>) | null
|
|
|
|
constructor(token: string, options?: ApiClientOptions) {
|
|
this.token = token
|
|
this.baseUrl = options?.baseUrl ?? null
|
|
this.getToken = options?.getToken ?? null
|
|
this.onUnauthorized = options?.onUnauthorized ?? null
|
|
}
|
|
|
|
private buildUrl(path: string): string {
|
|
if (!this.baseUrl) {
|
|
return path
|
|
}
|
|
try {
|
|
return new URL(path, this.baseUrl).toString()
|
|
} catch {
|
|
return path
|
|
}
|
|
}
|
|
|
|
private async request<T>(
|
|
path: string,
|
|
init?: RequestInit,
|
|
attempt: number = 0,
|
|
overrideToken?: string | null
|
|
): Promise<T> {
|
|
const headers = new Headers(init?.headers)
|
|
const liveToken = this.getToken ? this.getToken() : null
|
|
const authToken = overrideToken !== undefined
|
|
? (overrideToken ?? (liveToken ?? this.token))
|
|
: (liveToken ?? this.token)
|
|
if (authToken) {
|
|
headers.set('authorization', `Bearer ${authToken}`)
|
|
}
|
|
if (init?.body !== undefined && !headers.has('content-type')) {
|
|
headers.set('content-type', 'application/json')
|
|
}
|
|
|
|
const res = await fetch(this.buildUrl(path), {
|
|
...init,
|
|
headers
|
|
})
|
|
|
|
if (res.status === 401) {
|
|
if (attempt === 0 && this.onUnauthorized) {
|
|
const refreshed = await this.onUnauthorized()
|
|
if (refreshed) {
|
|
this.token = refreshed
|
|
return await this.request<T>(path, init, attempt + 1, refreshed)
|
|
}
|
|
}
|
|
throw new Error('Session expired. Please sign in again.')
|
|
}
|
|
|
|
if (!res.ok) {
|
|
const body = await res.text().catch(() => '')
|
|
const code = parseErrorCode(body)
|
|
throw new ApiError(
|
|
`HTTP ${res.status} ${res.statusText}: ${body}`,
|
|
res.status,
|
|
code,
|
|
body || undefined
|
|
)
|
|
}
|
|
|
|
return await res.json() as T
|
|
}
|
|
|
|
async authenticate(auth: { initData: string } | { accessToken: string }): Promise<AuthResponse> {
|
|
const res = await fetch(this.buildUrl('/api/auth'), {
|
|
method: 'POST',
|
|
headers: { 'content-type': 'application/json' },
|
|
body: JSON.stringify(auth)
|
|
})
|
|
|
|
if (!res.ok) {
|
|
const body = await res.text().catch(() => '')
|
|
const code = parseErrorCode(body)
|
|
const detail = body ? `: ${body}` : ''
|
|
throw new ApiError(`Auth failed: HTTP ${res.status} ${res.statusText}${detail}`, res.status, code, body || undefined)
|
|
}
|
|
|
|
return await res.json() as AuthResponse
|
|
}
|
|
|
|
async bind(auth: { initData: string; accessToken: string }): Promise<AuthResponse> {
|
|
const res = await fetch(this.buildUrl('/api/bind'), {
|
|
method: 'POST',
|
|
headers: { 'content-type': 'application/json' },
|
|
body: JSON.stringify(auth)
|
|
})
|
|
|
|
if (!res.ok) {
|
|
const body = await res.text().catch(() => '')
|
|
const code = parseErrorCode(body)
|
|
const detail = body ? `: ${body}` : ''
|
|
throw new ApiError(`Bind failed: HTTP ${res.status} ${res.statusText}${detail}`, res.status, code, body || undefined)
|
|
}
|
|
|
|
return await res.json() as AuthResponse
|
|
}
|
|
|
|
async getSessions(): Promise<SessionsResponse> {
|
|
return await this.request<SessionsResponse>('/api/sessions')
|
|
}
|
|
|
|
async getPushVapidPublicKey(): Promise<PushVapidPublicKeyResponse> {
|
|
return await this.request<PushVapidPublicKeyResponse>('/api/push/vapid-public-key')
|
|
}
|
|
|
|
async subscribePushNotifications(payload: PushSubscriptionPayload): Promise<void> {
|
|
await this.request('/api/push/subscribe', {
|
|
method: 'POST',
|
|
body: JSON.stringify(payload)
|
|
})
|
|
}
|
|
|
|
async syncCodexSession(payload?: CodexDesktopSyncRequest): Promise<CodexDesktopScriptResponse> {
|
|
// 中文注释:当前按钮语义已改为“从 Codex 导入到 Hapi”;这里提交的是本地 transcript 对应的 Codex thread ID 列表。
|
|
return await this.request<CodexDesktopScriptResponse>('/api/codex/sync-session', {
|
|
method: 'POST',
|
|
...(payload ? { body: JSON.stringify(payload) } : {})
|
|
})
|
|
}
|
|
|
|
async getCodexSessions(): Promise<CodexLocalSessionsResponse> {
|
|
return await this.request<CodexLocalSessionsResponse>('/api/codex/sessions')
|
|
}
|
|
|
|
async getCodexDesktopStatus(): Promise<CodexDesktopStatusResponse> {
|
|
return await this.request<CodexDesktopStatusResponse>('/api/codex/status')
|
|
}
|
|
|
|
async getCodexDuplicateSessions(payload: CodexDesktopSyncRequest): Promise<CodexDuplicateSessionsResponse> {
|
|
// 中文注释:重复会话检测只传本次用户勾选导入的 codexSessionId,避免把未选中的历史会话也纳入提示。
|
|
return await this.request<CodexDuplicateSessionsResponse>('/api/codex/duplicate-sessions', {
|
|
method: 'POST',
|
|
body: JSON.stringify(payload)
|
|
})
|
|
}
|
|
|
|
async mergeCodexDuplicateSessions(payload: CodexDesktopSyncRequest): Promise<CodexMergeDuplicateSessionsResponse> {
|
|
// 中文注释:真正执行合并时沿用同一批选中 codexSessionId,保证检测范围与执行范围一致。
|
|
return await this.request<CodexMergeDuplicateSessionsResponse>('/api/codex/merge-duplicate-sessions', {
|
|
method: 'POST',
|
|
body: JSON.stringify(payload)
|
|
})
|
|
}
|
|
|
|
async restartCodexDesktop(): Promise<CodexDesktopScriptResponse> {
|
|
return await this.request<CodexDesktopScriptResponse>('/api/codex/restart-desktop', {
|
|
method: 'POST'
|
|
})
|
|
}
|
|
|
|
async unsubscribePushNotifications(payload: PushUnsubscribePayload): Promise<void> {
|
|
await this.request('/api/push/subscribe', {
|
|
method: 'DELETE',
|
|
body: JSON.stringify(payload)
|
|
})
|
|
}
|
|
|
|
async setVisibility(payload: VisibilityPayload): Promise<void> {
|
|
await this.request('/api/visibility', {
|
|
method: 'POST',
|
|
body: JSON.stringify(payload)
|
|
})
|
|
}
|
|
|
|
async getSession(sessionId: string): Promise<SessionResponse> {
|
|
return await this.request<SessionResponse>(`/api/sessions/${encodeURIComponent(sessionId)}`)
|
|
}
|
|
|
|
async getSessionExport(sessionId: string, options?: { signal?: AbortSignal }): Promise<HapiSessionExport> {
|
|
return await this.request<HapiSessionExport>(
|
|
`/api/sessions/${encodeURIComponent(sessionId)}/export`,
|
|
{ signal: options?.signal }
|
|
)
|
|
}
|
|
|
|
async getMessages(
|
|
sessionId: string,
|
|
options: {
|
|
beforeSeq?: number | null
|
|
beforeAt?: number | null
|
|
limit?: number
|
|
}
|
|
): Promise<MessagesResponse> {
|
|
const params = new URLSearchParams()
|
|
if (options.beforeAt !== undefined && options.beforeAt !== null) {
|
|
params.set('beforeAt', `${options.beforeAt}`)
|
|
}
|
|
if (options.beforeSeq !== undefined && options.beforeSeq !== null) {
|
|
params.set('beforeSeq', `${options.beforeSeq}`)
|
|
}
|
|
if (options.limit !== undefined && options.limit !== null) {
|
|
params.set('limit', `${options.limit}`)
|
|
}
|
|
|
|
const qs = params.toString()
|
|
const url = `/api/sessions/${encodeURIComponent(sessionId)}/messages${qs ? `?${qs}` : ''}`
|
|
return await this.request<MessagesResponse>(url)
|
|
}
|
|
|
|
async getGitStatus(sessionId: string): Promise<GitCommandResponse> {
|
|
return await this.request<GitCommandResponse>(`/api/sessions/${encodeURIComponent(sessionId)}/git-status`)
|
|
}
|
|
|
|
async getGitDiffNumstat(sessionId: string, staged: boolean): Promise<GitCommandResponse> {
|
|
const params = new URLSearchParams()
|
|
params.set('staged', staged ? 'true' : 'false')
|
|
return await this.request<GitCommandResponse>(`/api/sessions/${encodeURIComponent(sessionId)}/git-diff-numstat?${params.toString()}`)
|
|
}
|
|
|
|
async getGitDiffFile(sessionId: string, path: string, staged?: boolean): Promise<GitCommandResponse> {
|
|
const params = new URLSearchParams()
|
|
params.set('path', path)
|
|
if (staged !== undefined) {
|
|
params.set('staged', staged ? 'true' : 'false')
|
|
}
|
|
return await this.request<GitCommandResponse>(`/api/sessions/${encodeURIComponent(sessionId)}/git-diff-file?${params.toString()}`)
|
|
}
|
|
|
|
async searchSessionFiles(sessionId: string, query: string, limit?: number): Promise<FileSearchResponse> {
|
|
const params = new URLSearchParams()
|
|
if (query) {
|
|
params.set('query', query)
|
|
}
|
|
if (limit !== undefined) {
|
|
params.set('limit', `${limit}`)
|
|
}
|
|
const qs = params.toString()
|
|
return await this.request<FileSearchResponse>(`/api/sessions/${encodeURIComponent(sessionId)}/files${qs ? `?${qs}` : ''}`)
|
|
}
|
|
|
|
async getGeneratedImageBlob(sessionId: string, imageId: string, attempt: number = 0, overrideToken?: string | null): Promise<Blob> {
|
|
const headers = new Headers()
|
|
const liveToken = this.getToken ? this.getToken() : null
|
|
const authToken = overrideToken !== undefined
|
|
? (overrideToken ?? (liveToken ?? this.token))
|
|
: (liveToken ?? this.token)
|
|
if (authToken) {
|
|
headers.set('authorization', `Bearer ${authToken}`)
|
|
}
|
|
const res = await fetch(this.buildUrl(`/api/sessions/${encodeURIComponent(sessionId)}/generated-images/${encodeURIComponent(imageId)}`), {
|
|
headers
|
|
})
|
|
if (res.status === 401 && attempt === 0 && this.onUnauthorized) {
|
|
const refreshed = await this.onUnauthorized()
|
|
if (refreshed) {
|
|
this.token = refreshed
|
|
return await this.getGeneratedImageBlob(sessionId, imageId, attempt + 1, refreshed)
|
|
}
|
|
}
|
|
if (!res.ok) {
|
|
throw new ApiError(`HTTP ${res.status}`, res.status, undefined, await res.text().catch(() => undefined))
|
|
}
|
|
return await res.blob()
|
|
}
|
|
|
|
async readSessionFile(sessionId: string, path: string): Promise<FileReadResponse> {
|
|
const params = new URLSearchParams()
|
|
params.set('path', path)
|
|
return await this.request<FileReadResponse>(`/api/sessions/${encodeURIComponent(sessionId)}/file?${params.toString()}`)
|
|
}
|
|
|
|
async listSessionDirectory(sessionId: string, path?: string): Promise<ListDirectoryResponse> {
|
|
const params = new URLSearchParams()
|
|
if (path) {
|
|
params.set('path', path)
|
|
}
|
|
|
|
const qs = params.toString()
|
|
return await this.request<ListDirectoryResponse>(
|
|
`/api/sessions/${encodeURIComponent(sessionId)}/directory${qs ? `?${qs}` : ''}`
|
|
)
|
|
}
|
|
|
|
async uploadFile(sessionId: string, filename: string, content: string, mimeType: string): Promise<UploadFileResponse> {
|
|
return await this.request<UploadFileResponse>(`/api/sessions/${encodeURIComponent(sessionId)}/upload`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ filename, content, mimeType })
|
|
})
|
|
}
|
|
|
|
async deleteUploadFile(sessionId: string, path: string): Promise<DeleteUploadResponse> {
|
|
return await this.request<DeleteUploadResponse>(`/api/sessions/${encodeURIComponent(sessionId)}/upload/delete`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ path })
|
|
})
|
|
}
|
|
|
|
async resumeSession(sessionId: string, opts?: { permissionMode?: string }): Promise<string> {
|
|
const response = await this.request<{ sessionId: string }>(
|
|
`/api/sessions/${encodeURIComponent(sessionId)}/resume`,
|
|
{
|
|
method: 'POST',
|
|
...(opts?.permissionMode !== undefined && {
|
|
body: JSON.stringify({ permissionMode: opts.permissionMode })
|
|
})
|
|
}
|
|
)
|
|
return response.sessionId
|
|
}
|
|
|
|
async sendMessage(sessionId: string, text: string, localId?: string | null, attachments?: AttachmentMetadata[], scheduledAt?: number | null): Promise<void> {
|
|
await this.request(`/api/sessions/${encodeURIComponent(sessionId)}/messages`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
text,
|
|
localId: localId ?? undefined,
|
|
attachments: attachments ?? undefined,
|
|
scheduledAt: scheduledAt ?? undefined
|
|
})
|
|
})
|
|
}
|
|
|
|
async cancelMessage(sessionId: string, messageId: string): Promise<CancelMessageResponse> {
|
|
const response = await this.request(
|
|
`/api/sessions/${encodeURIComponent(sessionId)}/messages/${encodeURIComponent(messageId)}`,
|
|
{ method: 'DELETE' }
|
|
)
|
|
return response as CancelMessageResponse
|
|
}
|
|
|
|
async abortSession(sessionId: string): Promise<void> {
|
|
await this.request(`/api/sessions/${encodeURIComponent(sessionId)}/abort`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({})
|
|
})
|
|
}
|
|
|
|
async archiveSession(sessionId: string): Promise<void> {
|
|
await this.request(`/api/sessions/${encodeURIComponent(sessionId)}/archive`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({})
|
|
})
|
|
}
|
|
|
|
async reopenSession(sessionId: string): Promise<ReopenSessionResponse> {
|
|
return await this.request<ReopenSessionResponse>(
|
|
`/api/sessions/${encodeURIComponent(sessionId)}/reopen`,
|
|
{ method: 'POST', body: JSON.stringify({}) }
|
|
)
|
|
}
|
|
|
|
async switchSession(sessionId: string): Promise<void> {
|
|
await this.request(`/api/sessions/${encodeURIComponent(sessionId)}/switch`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({})
|
|
})
|
|
}
|
|
|
|
async setPermissionMode(sessionId: string, mode: PermissionMode): Promise<void> {
|
|
await this.request(`/api/sessions/${encodeURIComponent(sessionId)}/permission-mode`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ mode })
|
|
})
|
|
}
|
|
|
|
async setCollaborationMode(sessionId: string, mode: CodexCollaborationMode): Promise<void> {
|
|
await this.request(`/api/sessions/${encodeURIComponent(sessionId)}/collaboration-mode`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ mode })
|
|
})
|
|
}
|
|
|
|
async setModel(sessionId: string, model: string | null): Promise<void> {
|
|
await this.request(`/api/sessions/${encodeURIComponent(sessionId)}/model`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ model })
|
|
})
|
|
}
|
|
|
|
async setModelReasoningEffort(sessionId: string, modelReasoningEffort: string | null): Promise<void> {
|
|
await this.request(`/api/sessions/${encodeURIComponent(sessionId)}/model-reasoning-effort`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ modelReasoningEffort })
|
|
})
|
|
}
|
|
|
|
async setEffort(sessionId: string, effort: string | null): Promise<void> {
|
|
await this.request(`/api/sessions/${encodeURIComponent(sessionId)}/effort`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ effort })
|
|
})
|
|
}
|
|
|
|
async approvePermission(
|
|
sessionId: string,
|
|
requestId: string,
|
|
modeOrOptions?: 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan' | {
|
|
mode?: 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan'
|
|
allowTools?: string[]
|
|
decision?: 'approved' | 'approved_for_session' | 'denied' | 'abort'
|
|
answers?: Record<string, string[]> | Record<string, { answers: string[] }>
|
|
}
|
|
): Promise<void> {
|
|
const body = typeof modeOrOptions === 'string' || modeOrOptions === undefined
|
|
? { mode: modeOrOptions }
|
|
: modeOrOptions
|
|
await this.request(`/api/sessions/${encodeURIComponent(sessionId)}/permissions/${encodeURIComponent(requestId)}/approve`, {
|
|
method: 'POST',
|
|
body: JSON.stringify(body)
|
|
})
|
|
}
|
|
|
|
async denyPermission(
|
|
sessionId: string,
|
|
requestId: string,
|
|
options?: {
|
|
decision?: 'approved' | 'approved_for_session' | 'denied' | 'abort'
|
|
}
|
|
): Promise<void> {
|
|
await this.request(`/api/sessions/${encodeURIComponent(sessionId)}/permissions/${encodeURIComponent(requestId)}/deny`, {
|
|
method: 'POST',
|
|
body: JSON.stringify(options ?? {})
|
|
})
|
|
}
|
|
|
|
async getMachines(): Promise<MachinesResponse> {
|
|
return await this.request<MachinesResponse>('/api/machines')
|
|
}
|
|
|
|
async listMachineDirectory(
|
|
machineId: string,
|
|
path: string
|
|
): Promise<MachineListDirectoryResponse> {
|
|
return await this.request<MachineListDirectoryResponse>(
|
|
`/api/machines/${encodeURIComponent(machineId)}/list-directory`,
|
|
{
|
|
method: 'POST',
|
|
body: JSON.stringify({ path })
|
|
}
|
|
)
|
|
}
|
|
|
|
async checkMachinePathsExists(
|
|
machineId: string,
|
|
paths: string[]
|
|
): Promise<MachinePathsExistsResponse> {
|
|
return await this.request<MachinePathsExistsResponse>(
|
|
`/api/machines/${encodeURIComponent(machineId)}/paths/exists`,
|
|
{
|
|
method: 'POST',
|
|
body: JSON.stringify({ paths })
|
|
}
|
|
)
|
|
}
|
|
|
|
async spawnSession(
|
|
machineId: string,
|
|
directory: string,
|
|
agent?: AgentFlavor,
|
|
model?: string,
|
|
modelReasoningEffort?: string,
|
|
yolo?: boolean,
|
|
sessionType?: 'simple' | 'worktree',
|
|
worktreeName?: string,
|
|
effort?: string
|
|
): Promise<SpawnResponse> {
|
|
return await this.request<SpawnResponse>(`/api/machines/${encodeURIComponent(machineId)}/spawn`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ directory, agent, model, modelReasoningEffort, yolo, sessionType, worktreeName, effort })
|
|
})
|
|
}
|
|
|
|
async getMachineCodexModels(machineId: string): Promise<CodexModelsResponse> {
|
|
return await this.request<CodexModelsResponse>(
|
|
`/api/machines/${encodeURIComponent(machineId)}/codex-models`
|
|
)
|
|
}
|
|
|
|
async getSessionCodexModels(sessionId: string): Promise<CodexModelsResponse> {
|
|
return await this.request<CodexModelsResponse>(
|
|
`/api/sessions/${encodeURIComponent(sessionId)}/codex-models`
|
|
)
|
|
}
|
|
|
|
async getSessionOpencodeModels(sessionId: string): Promise<OpencodeModelsResponse> {
|
|
return await this.request<OpencodeModelsResponse>(
|
|
`/api/sessions/${encodeURIComponent(sessionId)}/opencode-models`
|
|
)
|
|
}
|
|
|
|
async getSessionOpencodeReasoningEffortOptions(sessionId: string): Promise<OpencodeReasoningEffortResponse> {
|
|
return await this.request<OpencodeReasoningEffortResponse>(
|
|
`/api/sessions/${encodeURIComponent(sessionId)}/opencode-reasoning-effort-options`
|
|
)
|
|
}
|
|
|
|
async getSessionCursorModels(sessionId: string): Promise<CursorModelsResponse> {
|
|
return await this.request<CursorModelsResponse>(
|
|
`/api/sessions/${encodeURIComponent(sessionId)}/cursor-models`
|
|
)
|
|
}
|
|
|
|
async getMachineCursorModels(machineId: string): Promise<CursorModelsResponse> {
|
|
return await this.request<CursorModelsResponse>(
|
|
`/api/machines/${encodeURIComponent(machineId)}/cursor-models`
|
|
)
|
|
}
|
|
|
|
async getMachineOpencodeModelsForCwd(machineId: string, cwd: string): Promise<OpencodeModelsResponse> {
|
|
return await this.request<OpencodeModelsResponse>(
|
|
`/api/machines/${encodeURIComponent(machineId)}/opencode-models?cwd=${encodeURIComponent(cwd)}`
|
|
)
|
|
}
|
|
|
|
async getSlashCommands(sessionId: string): Promise<SlashCommandsResponse> {
|
|
return await this.request<SlashCommandsResponse>(
|
|
`/api/sessions/${encodeURIComponent(sessionId)}/slash-commands`
|
|
)
|
|
}
|
|
|
|
async getSkills(sessionId: string): Promise<SkillsResponse> {
|
|
return await this.request<SkillsResponse>(
|
|
`/api/sessions/${encodeURIComponent(sessionId)}/skills`
|
|
)
|
|
}
|
|
|
|
async renameSession(sessionId: string, name: string): Promise<void> {
|
|
await this.request(`/api/sessions/${encodeURIComponent(sessionId)}`, {
|
|
method: 'PATCH',
|
|
body: JSON.stringify({ name })
|
|
})
|
|
}
|
|
|
|
async deleteSession(sessionId: string): Promise<void> {
|
|
await this.request(`/api/sessions/${encodeURIComponent(sessionId)}`, {
|
|
method: 'DELETE'
|
|
})
|
|
}
|
|
|
|
async fetchVoiceToken(options?: { customAgentId?: string; customApiKey?: string; voiceId?: string }): Promise<{
|
|
allowed: boolean
|
|
token?: string
|
|
agentId?: string
|
|
error?: string
|
|
}> {
|
|
return await this.request('/api/voice/token', {
|
|
method: 'POST',
|
|
body: JSON.stringify(options || {})
|
|
})
|
|
}
|
|
|
|
async fetchVoices(): Promise<{ voices: Array<{ id: string; name: string; previewUrl: string; category: string }> }> {
|
|
return await this.request('/api/voice/voices')
|
|
}
|
|
|
|
async sendVoiceTelemetry(event: {
|
|
stage: string
|
|
message: string
|
|
sessionId?: string
|
|
voiceId?: string
|
|
language?: string
|
|
details?: Record<string, unknown>
|
|
}): Promise<void> {
|
|
await this.request('/api/voice/telemetry', {
|
|
method: 'POST',
|
|
body: JSON.stringify(event)
|
|
})
|
|
}
|
|
|
|
/** Return the current auth token (for WebSocket query-param auth). */
|
|
getAuthToken(): string | null {
|
|
return this.getToken ? this.getToken() : this.token
|
|
}
|
|
|
|
async fetchVoiceBackend(): Promise<{ backend: string; backends: string[] }> {
|
|
return await this.request('/api/voice/backend')
|
|
}
|
|
|
|
async fetchQwenToken(): Promise<{
|
|
allowed: boolean
|
|
wsUrl?: string
|
|
error?: string
|
|
}> {
|
|
return await this.request('/api/voice/qwen-token', {
|
|
method: 'POST',
|
|
body: JSON.stringify({})
|
|
})
|
|
}
|
|
|
|
async fetchGeminiToken(): Promise<{
|
|
allowed: boolean
|
|
apiKey?: string
|
|
wsUrl?: string
|
|
baseUrl?: string
|
|
error?: string
|
|
}> {
|
|
return await this.request('/api/voice/gemini-token', {
|
|
method: 'POST',
|
|
body: JSON.stringify({})
|
|
})
|
|
}
|
|
}
|