feat: add assistant mode, SSE streaming, and OpenCode server integration (#214)

This commit is contained in:
Chris Scott authored and GitHub committed 2026-05-02 21:51:37 -04:00
1 parent 3cc24288a6
commit c3d6549f01
133 files changed
+7284 -6293

No files matched your search

-136
View File
@@ -1,136 +0,0 @@
import { fetchWrapper, fetchWrapperVoid } from './fetchWrapper'
import { API_BASE_URL } from '@/config'
import type { Memory, MemoryStats, CreateMemoryRequest, UpdateMemoryRequest, PluginConfig, KvEntry, CreateKvEntryRequest, UpdateKvEntryRequest, LoopState } from '@opencode-manager/shared/types'
export async function listMemories(filters?: {
projectId?: string
scope?: string
content?: string
limit?: number
offset?: number
}): Promise<{ memories: Memory[] }> {
const params = new URLSearchParams()
if (filters?.projectId) params.set('projectId', filters.projectId)
if (filters?.scope) params.set('scope', filters.scope)
if (filters?.content) params.set('content', filters.content)
if (filters?.limit) params.set('limit', String(filters.limit))
if (filters?.offset) params.set('offset', String(filters.offset))
const query = params.toString()
return fetchWrapper(`${API_BASE_URL}/api/memory${query ? `?${query}` : ''}`)
}
export async function createMemory(data: CreateMemoryRequest): Promise<{ memory: Memory }> {
return fetchWrapper(`${API_BASE_URL}/api/memory`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
}
export async function getMemory(id: number): Promise<{ memory: Memory }> {
return fetchWrapper(`${API_BASE_URL}/api/memory/${id}`)
}
export async function updateMemory(id: number, data: UpdateMemoryRequest): Promise<{ memory: Memory }> {
return fetchWrapper(`${API_BASE_URL}/api/memory/${id}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
}
export async function deleteMemory(id: number): Promise<void> {
return fetchWrapperVoid(`${API_BASE_URL}/api/memory/${id}`, {
method: 'DELETE',
})
}
export async function getProjectSummary(
repoId: number
): Promise<{ projectId: string | null; stats: MemoryStats; error?: string }> {
return fetchWrapper(`${API_BASE_URL}/api/memory/project-summary?repoId=${repoId}`)
}
export async function getPluginConfig(): Promise<{ config: PluginConfig }> {
return fetchWrapper(`${API_BASE_URL}/api/memory/plugin-config`)
}
export async function updatePluginConfig(config: PluginConfig): Promise<{ success: boolean; config: PluginConfig }> {
return fetchWrapper(`${API_BASE_URL}/api/memory/plugin-config`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(config),
})
}
export interface ReindexResult {
success: boolean
message: string
total: number
embedded: number
failed: number
requiresRestart?: boolean
}
export async function reindexMemories(): Promise<ReindexResult> {
return fetchWrapper(`${API_BASE_URL}/api/memory/reindex`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
})
}
export interface TestEmbeddingResult {
success: boolean
error?: string
message?: string
dimensions?: number
}
export async function testEmbeddingConfig(): Promise<TestEmbeddingResult> {
return fetchWrapper(`${API_BASE_URL}/api/memory/test-embedding`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({}),
})
}
export async function listKvEntries(projectId: string, prefix?: string): Promise<{ entries: KvEntry[] }> {
const params = new URLSearchParams({ projectId })
if (prefix) params.set('prefix', prefix)
return fetchWrapper(`${API_BASE_URL}/api/memory/kv?${params.toString()}`)
}
export async function deleteKvEntry(projectId: string, key: string): Promise<void> {
return fetchWrapperVoid(`${API_BASE_URL}/api/memory/kv/${encodeURIComponent(key)}?projectId=${encodeURIComponent(projectId)}`, {
method: 'DELETE',
})
}
export async function createKvEntry(data: CreateKvEntryRequest): Promise<{ entry: KvEntry }> {
return fetchWrapper(`${API_BASE_URL}/api/memory/kv`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
}
export async function updateKvEntry(projectId: string, key: string, data: UpdateKvEntryRequest): Promise<{ entry: KvEntry }> {
return fetchWrapper(`${API_BASE_URL}/api/memory/kv/${encodeURIComponent(key)}?projectId=${encodeURIComponent(projectId)}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
}
export async function getLoopStatus(repoId: number): Promise<{ loops: LoopState[]; projectId?: string | null }> {
return fetchWrapper(`${API_BASE_URL}/api/memory/loop/status?repoId=${repoId}`)
}
export async function cancelLoop(repoId: number, sessionId: string): Promise<{ cancelled: boolean; worktreeName?: string }> {
return fetchWrapper(`${API_BASE_URL}/api/memory/loop/cancel`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ repoId, sessionId }),
})
}
+20 -4
View File
@@ -1,14 +1,16 @@
import type { paths } from './opencode-types'
import { fetchWrapper } from './fetchWrapper'
import { fetchWrapper, fetchWrapperVoid } from './fetchWrapper'
type SessionListResponse = paths['/session']['get']['responses']['200']['content']['application/json']
type SessionResponse = paths['/session/{sessionID}']['get']['responses']['200']['content']['application/json']
type CreateSessionRequest = NonNullable<paths['/session']['post']['requestBody']>['content']['application/json']
type MessageListResponse = paths['/session/{sessionID}/message']['get']['responses']['200']['content']['application/json']
type SendPromptRequest = NonNullable<paths['/session/{sessionID}/message']['post']['requestBody']>['content']['application/json']
type SendPromptAsyncRequest = NonNullable<paths['/session/{sessionID}/prompt_async']['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/{sessionID}/command']['post']['requestBody']>['content']['application/json']
type SendCommandResponse = paths['/session/{sessionID}/command']['post']['responses']['200']['content']['application/json']
type ShellRequest = NonNullable<paths['/session/{sessionID}/shell']['post']['requestBody']>['content']['application/json']
type AgentListResponse = paths['/agent']['get']['responses']['200']['content']['application/json']
type PermissionListResponse = paths['/permission']['get']['responses']['200']['content']['application/json']
@@ -17,7 +19,7 @@ type SendPromptResponse = paths['/session/{sessionID}/message']['post']['respons
type LspStatusResponse = paths['/lsp']['get']['responses']['200']['content']['application/json']
type LspStatus = LspStatusResponse[number]
export type { SendPromptResponse, LspStatus }
export type { SendPromptResponse, SendCommandResponse, LspStatus }
export class OpenCodeClient {
private baseURL: string
@@ -109,6 +111,19 @@ export class OpenCodeClient {
)
}
async sendPromptAsync(sessionID: string, data: SendPromptAsyncRequest): Promise<void> {
return fetchWrapperVoid(
`${this.baseURL}/session/${sessionID}/prompt_async`,
{
method: 'POST',
params: this.getParams(),
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
timeout: 0,
}
)
}
async summarizeSession(sessionID: string, providerID: string, modelID: string) {
return fetchWrapper(`${this.baseURL}/session/${sessionID}/summarize`, {
method: 'POST',
@@ -157,12 +172,13 @@ export class OpenCodeClient {
})
}
async sendCommand(sessionID: string, data: CommandRequest) {
return fetchWrapper(`${this.baseURL}/session/${sessionID}/command`, {
async sendCommand(sessionID: string, data: CommandRequest): Promise<SendCommandResponse> {
return fetchWrapper<SendCommandResponse>(`${this.baseURL}/session/${sessionID}/command`, {
method: 'POST',
params: this.getParams(),
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
timeout: 0,
})
}
+17 -4
View File
@@ -229,10 +229,6 @@ export const settingsApi = {
return fetchWrapper(`${API_BASE_URL}/api/health/version`)
},
getMemoryPluginStatus: async (): Promise<{ memoryPluginEnabled: boolean }> => {
return fetchWrapper(`${API_BASE_URL}/api/settings/memory-plugin-status`)
},
listManagedSkills: async (repoId?: number): Promise<SkillFileInfo[]> => {
const params = repoId ? `?repoId=${repoId}` : ''
return fetchWrapper(`${API_BASE_URL}/api/settings/skills${params}`)
@@ -278,3 +274,20 @@ export interface VersionInfo {
releaseUrl: string | null
releaseName: string | null
}
export interface OpenCodeServerAuthStatus {
isSet: boolean
source: 'db' | 'env' | 'none'
}
export async function getOpenCodeServerAuth(): Promise<OpenCodeServerAuthStatus> {
return fetchWrapper(`${API_BASE_URL}/api/settings/opencode-server-auth`)
}
export async function updateOpenCodeServerAuth(password: string | null): Promise<OpenCodeServerAuthStatus> {
return fetchWrapper(`${API_BASE_URL}/api/settings/opencode-server-auth`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password }),
})
}
-1
View File
@@ -63,7 +63,6 @@ export interface UserPreferences {
notifications?: NotificationPreferences
repoOrder?: number[]
repoSortMode?: 'recent' | 'manual' | 'name'
memoryDedupThreshold?: number
}
export interface SettingsResponse {