mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
Rename all Ralph references to Loop including types, services, hooks, filenames, KV keys, API routes, frontend components, tests, and docs. Key changes: - Types: RalphState → LoopState, RalphConfig → LoopConfig - Services: ralph.ts → loop.ts with worktree field (inverted from inPlace) - KV keys: ralph: → loop:, ralph-session: → loop-session: - API routes: /ralph/* → /loop/* - Frontend: useLoopStatus, RepoLoopList, getLoopStatus, cancelLoop - Config backward compatibility: accepts both loop and ralph (prefers loop) - Automatic KV migration on plugin startup - memory-plan-execute keeps inPlace parameter (different semantics) Fixes critical bugs found in code review: - Backend /loop/cancel route using wrong ralph: KV prefix - Frontend error messages still referencing Ralph - Log message consistency
137 lines
4.8 KiB
TypeScript
137 lines
4.8 KiB
TypeScript
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 }),
|
|
})
|
|
}
|