mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
Update memory plugin (#160)
This commit is contained in:
1 parent
be7e64b07f
commit
1248d0b9e0
50 files changed
+5363
-291
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { fetchWrapper, fetchWrapperVoid } from './fetchWrapper'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import type { Memory, MemoryStats, CreateMemoryRequest, UpdateMemoryRequest, PluginConfig } from '@opencode-manager/shared/types'
|
||||
import type { Memory, MemoryStats, CreateMemoryRequest, UpdateMemoryRequest, PluginConfig, KvEntry, CreateKvEntryRequest, UpdateKvEntryRequest } from '@opencode-manager/shared/types'
|
||||
|
||||
export async function listMemories(filters?: {
|
||||
projectId?: string
|
||||
@@ -94,3 +94,39 @@ export async function testEmbeddingConfig(): Promise<TestEmbeddingResult> {
|
||||
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 cancelRalphLoop(repoId: string, sessionId: string): Promise<{ cancelled: boolean; worktreeName?: string }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/memory/ralph/cancel`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ repoId, sessionId }),
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { z } from 'zod'
|
||||
import { useCreateKvEntry, useUpdateKvEntry } from '@/hooks/useMemories'
|
||||
import type { KvEntry, CreateKvEntryRequest, UpdateKvEntryRequest } from '@opencode-manager/shared/types'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Label } from '@/components/ui/label'
|
||||
|
||||
const kvSchema = z.object({
|
||||
key: z.string().min(1, 'Key is required'),
|
||||
data: z.string().min(1, 'Data is required'),
|
||||
ttlHours: z.number().optional(),
|
||||
})
|
||||
|
||||
type KvFormData = z.infer<typeof kvSchema>
|
||||
|
||||
interface KvFormDialogProps {
|
||||
entry?: KvEntry
|
||||
projectId?: string
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
}
|
||||
|
||||
export function KvFormDialog({ entry, projectId, open, onOpenChange }: KvFormDialogProps) {
|
||||
const createMutation = useCreateKvEntry()
|
||||
const updateMutation = useUpdateKvEntry()
|
||||
|
||||
const [jsonError, setJsonError] = useState<string | undefined>()
|
||||
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
reset,
|
||||
formState: { errors },
|
||||
} = useForm<KvFormData>({
|
||||
resolver: zodResolver(kvSchema),
|
||||
defaultValues: {
|
||||
key: '',
|
||||
data: '',
|
||||
ttlHours: undefined,
|
||||
},
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
if (entry) {
|
||||
const ttlMs = entry.expiresAt - entry.updatedAt
|
||||
const ttlHoursValue = ttlMs > 0 && ttlMs < Number.MAX_SAFE_INTEGER
|
||||
? Math.round(ttlMs / (1000 * 60 * 60))
|
||||
: undefined
|
||||
|
||||
reset({
|
||||
key: entry.key,
|
||||
data: JSON.stringify(entry.data, null, 2),
|
||||
ttlHours: ttlHoursValue,
|
||||
})
|
||||
} else {
|
||||
reset({
|
||||
key: '',
|
||||
data: '',
|
||||
ttlHours: undefined,
|
||||
})
|
||||
}
|
||||
setJsonError(undefined)
|
||||
}
|
||||
}, [open, entry, reset])
|
||||
|
||||
const validateJson = (value: string): boolean => {
|
||||
try {
|
||||
JSON.parse(value)
|
||||
setJsonError(undefined)
|
||||
return true
|
||||
} catch (e) {
|
||||
setJsonError(e instanceof Error ? e.message : 'Invalid JSON')
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const onSubmit = async (data: KvFormData) => {
|
||||
if (!validateJson(data.data)) {
|
||||
return
|
||||
}
|
||||
|
||||
const parsedData = JSON.parse(data.data)
|
||||
const ttlMs = data.ttlHours ? data.ttlHours * 1000 * 60 * 60 : undefined
|
||||
|
||||
if (entry) {
|
||||
const updateData: UpdateKvEntryRequest = {
|
||||
data: parsedData,
|
||||
ttlMs,
|
||||
}
|
||||
await updateMutation.mutateAsync({ projectId: projectId!, key: entry.key, data: updateData })
|
||||
} else if (projectId) {
|
||||
const createData: CreateKvEntryRequest = {
|
||||
projectId,
|
||||
key: data.key,
|
||||
data: parsedData,
|
||||
ttlMs,
|
||||
}
|
||||
await createMutation.mutateAsync(createData)
|
||||
}
|
||||
onOpenChange(false)
|
||||
}
|
||||
|
||||
const isLoading = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-[500px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{entry ? 'Edit KV Entry' : 'Create KV Entry'}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{entry
|
||||
? 'Update the KV entry data and TTL.'
|
||||
: 'Add a new key-value entry to store project data.'}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="key">Key</Label>
|
||||
<Input
|
||||
id="key"
|
||||
{...register('key')}
|
||||
placeholder="Enter key..."
|
||||
disabled={!!entry}
|
||||
/>
|
||||
{errors.key && (
|
||||
<p className="text-sm text-destructive">{errors.key.message}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="data">Data (JSON)</Label>
|
||||
<Textarea
|
||||
id="data"
|
||||
{...register('data')}
|
||||
placeholder='{"key": "value"}'
|
||||
rows={6}
|
||||
className="resize-none font-mono"
|
||||
onBlur={(e) => validateJson(e.target.value)}
|
||||
/>
|
||||
{errors.data && (
|
||||
<p className="text-sm text-destructive">{errors.data.message}</p>
|
||||
)}
|
||||
{jsonError && (
|
||||
<p className="text-sm text-destructive">{jsonError}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="ttlHours">TTL (hours, optional)</Label>
|
||||
<Input
|
||||
id="ttlHours"
|
||||
type="number"
|
||||
min="0"
|
||||
step="1"
|
||||
{...register('ttlHours', { valueAsNumber: true })}
|
||||
placeholder="Enter TTL in hours..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<DialogFooter className='flex gap-2 flex-wrap'>
|
||||
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" disabled={isLoading || !!jsonError}>
|
||||
{isLoading ? 'Saving...' : entry ? 'Update' : 'Create'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
import { useState } from 'react'
|
||||
import { useKvEntries, useDeleteKvEntry } from '@/hooks/useMemories'
|
||||
import { useDebounce } from '@/hooks/useDebounce'
|
||||
import type { KvEntry } from '@opencode-manager/shared/types'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Loader2, Trash2, Key, ChevronDown, ChevronRight, Plus } from 'lucide-react'
|
||||
import { DeleteDialog } from '@/components/ui/delete-dialog'
|
||||
import { KvFormDialog } from './KvFormDialog'
|
||||
|
||||
interface KvListProps {
|
||||
projectId?: string
|
||||
}
|
||||
|
||||
function formatTimeRemaining(expiresAt: number): string {
|
||||
const now = Date.now()
|
||||
const diff = expiresAt - now
|
||||
|
||||
if (diff <= 0) {
|
||||
return 'expired'
|
||||
}
|
||||
|
||||
const hours = Math.floor(diff / (1000 * 60 * 60))
|
||||
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60))
|
||||
|
||||
if (hours > 0) {
|
||||
return `${hours}h ${minutes}m`
|
||||
}
|
||||
|
||||
return `${minutes}m`
|
||||
}
|
||||
|
||||
export function KvList({ projectId }: KvListProps) {
|
||||
const [searchQuery, setSearchQuery] = useState<string>('')
|
||||
const debouncedSearch = useDebounce(searchQuery, 300)
|
||||
const [expandedKey, setExpandedKey] = useState<string | null>(null)
|
||||
const [deleteKey, setDeleteKey] = useState<string | null>(null)
|
||||
const [dialogOpen, setDialogOpen] = useState(false)
|
||||
const [editingEntry, setEditingEntry] = useState<KvEntry | undefined>(undefined)
|
||||
|
||||
const { data: entries, isLoading } = useKvEntries(projectId, debouncedSearch || undefined)
|
||||
const deleteMutation = useDeleteKvEntry()
|
||||
|
||||
const handleDelete = () => {
|
||||
if (deleteKey && projectId) {
|
||||
deleteMutation.mutate({ projectId, key: deleteKey })
|
||||
setDeleteKey(null)
|
||||
}
|
||||
}
|
||||
|
||||
const toggleExpand = (key: string) => {
|
||||
setExpandedKey(expandedKey === key ? null : key)
|
||||
}
|
||||
|
||||
const handleEdit = (entry: KvEntry) => {
|
||||
setEditingEntry(entry)
|
||||
setDialogOpen(true)
|
||||
}
|
||||
|
||||
const handleCreate = () => {
|
||||
setEditingEntry(undefined)
|
||||
setDialogOpen(true)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
placeholder="Filter by key prefix..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="w-64"
|
||||
/>
|
||||
<Button onClick={handleCreate} size="sm">
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
Add KV Entry
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="flex items-center justify-center p-8">
|
||||
<Loader2 className="w-6 h-6 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
) : !entries || entries.length === 0 ? (
|
||||
<div className="text-center p-8 text-muted-foreground">
|
||||
<Key className="w-8 h-8 mx-auto mb-2 opacity-50" />
|
||||
<p>No KV entries found</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{entries.map((entry: KvEntry) => {
|
||||
const isExpanded = expandedKey === entry.key
|
||||
const dataPreview = JSON.stringify(entry.data)
|
||||
const formattedData = JSON.stringify(entry.data, null, 2)
|
||||
const truncatedPreview = dataPreview.length > 100
|
||||
? dataPreview.slice(0, 100) + '...'
|
||||
: dataPreview
|
||||
|
||||
return (
|
||||
<div
|
||||
key={entry.key}
|
||||
className="p-4 rounded-lg border border-border bg-card hover:bg-accent/50 transition-colors"
|
||||
>
|
||||
<div className="flex items-center justify-between gap-2 mb-2">
|
||||
<div className="flex items-center gap-2 flex-wrap min-w-0 flex-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6 p-0"
|
||||
onClick={() => toggleExpand(entry.key)}
|
||||
>
|
||||
{isExpanded ? (
|
||||
<ChevronDown className="w-4 h-4" />
|
||||
) : (
|
||||
<ChevronRight className="w-4 h-4" />
|
||||
)}
|
||||
</Button>
|
||||
<span className="font-medium truncate">{entry.key}</span>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="text-xs bg-amber-600/20 text-amber-400 border-amber-600/40"
|
||||
>
|
||||
{formatTimeRemaining(entry.expiresAt)}
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="flex gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8"
|
||||
onClick={() => handleEdit(entry)}
|
||||
>
|
||||
<Key className="w-4 h-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-destructive"
|
||||
onClick={() => setDeleteKey(entry.key)}
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-sm text-muted-foreground font-mono break-all">
|
||||
{truncatedPreview}
|
||||
</div>
|
||||
{isExpanded && (
|
||||
<pre className="mt-2 p-2 bg-muted rounded text-xs overflow-auto max-h-64">
|
||||
{formattedData}
|
||||
</pre>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground mt-2">
|
||||
Updated: {new Date(entry.updatedAt).toLocaleString()}
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<DeleteDialog
|
||||
open={deleteKey !== null}
|
||||
onOpenChange={(open: boolean) => !open && setDeleteKey(null)}
|
||||
onConfirm={handleDelete}
|
||||
onCancel={() => setDeleteKey(null)}
|
||||
title="Delete KV Entry"
|
||||
description="Are you sure you want to delete this KV entry? This action cannot be undone."
|
||||
itemName={deleteKey || undefined}
|
||||
isDeleting={deleteMutation.isPending}
|
||||
/>
|
||||
|
||||
<KvFormDialog
|
||||
entry={editingEntry}
|
||||
projectId={projectId}
|
||||
open={dialogOpen}
|
||||
onOpenChange={setDialogOpen}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -54,6 +54,7 @@ interface PromptInputProps {
|
||||
opcodeUrl: string
|
||||
directory?: string
|
||||
sessionID: string
|
||||
repoId?: number
|
||||
disabled?: boolean
|
||||
showScrollButton?: boolean
|
||||
hasActiveStream?: boolean
|
||||
@@ -69,7 +70,8 @@ interface PromptInputProps {
|
||||
export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(function PromptInput({
|
||||
opcodeUrl,
|
||||
directory,
|
||||
sessionID,
|
||||
sessionID,
|
||||
repoId,
|
||||
disabled,
|
||||
showScrollButton,
|
||||
hasActiveStream = false,
|
||||
@@ -139,7 +141,7 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
|
||||
}), [imageAttachments, clearSTT, isRecording, abortRecording])
|
||||
const sendPrompt = useSendPrompt(opcodeUrl, directory)
|
||||
const sendShell = useSendShell(opcodeUrl, directory)
|
||||
const abortSession = useAbortSession(opcodeUrl, directory, sessionID)
|
||||
const abortSession = useAbortSession(opcodeUrl, directory, sessionID, repoId)
|
||||
const { filterCommands } = useCommands(opcodeUrl)
|
||||
const { executeCommand } = useCommandHandler({
|
||||
opcodeUrl,
|
||||
|
||||
@@ -6,8 +6,12 @@ import {
|
||||
updateMemory,
|
||||
deleteMemory,
|
||||
getProjectSummary,
|
||||
listKvEntries,
|
||||
deleteKvEntry,
|
||||
createKvEntry,
|
||||
updateKvEntry,
|
||||
} from '@/api/memory'
|
||||
import type { CreateMemoryRequest, UpdateMemoryRequest } from '@opencode-manager/shared/types'
|
||||
import type { CreateMemoryRequest, UpdateMemoryRequest, CreateKvEntryRequest, UpdateKvEntryRequest } from '@opencode-manager/shared/types'
|
||||
import { showToast } from '@/lib/toast'
|
||||
|
||||
export function useMemories(filters?: {
|
||||
@@ -92,3 +96,61 @@ export function useProjectSummary(repoId: number | undefined) {
|
||||
enabled: repoId !== undefined,
|
||||
})
|
||||
}
|
||||
|
||||
export function useKvEntries(projectId?: string, prefix?: string) {
|
||||
return useQuery({
|
||||
queryKey: ['kvEntries', projectId, prefix],
|
||||
queryFn: () => listKvEntries(projectId!, prefix).then(r => r.entries),
|
||||
enabled: !!projectId,
|
||||
})
|
||||
}
|
||||
|
||||
export function useDeleteKvEntry() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ projectId, key }: { projectId: string; key: string }) =>
|
||||
deleteKvEntry(projectId, key),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['kvEntries'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['projectSummary'] })
|
||||
showToast.success('KV entry deleted')
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast.error(`Failed to delete KV entry: ${error}`)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useCreateKvEntry() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (data: CreateKvEntryRequest) => createKvEntry(data).then(r => r.entry),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['kvEntries'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['projectSummary'] })
|
||||
showToast.success('KV entry created')
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast.error(`Failed to create KV entry: ${error}`)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateKvEntry() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ projectId, key, data }: { projectId: string; key: string; data: UpdateKvEntryRequest }) =>
|
||||
updateKvEntry(projectId, key, data).then(r => r.entry),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['kvEntries'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['projectSummary'] })
|
||||
showToast.success('KV entry updated')
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast.error(`Failed to update KV entry: ${error}`)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { useMemo, useRef, useEffect, useCallback, useState } from "react";
|
||||
import { OpenCodeClient } from "../api/opencode";
|
||||
import { API_BASE_URL } from "../config";
|
||||
import { fetchWrapper } from "../api/fetchWrapper";
|
||||
import { cancelRalphLoop } from "../api/memory";
|
||||
import type {
|
||||
Message,
|
||||
Part,
|
||||
@@ -421,7 +422,8 @@ const MAX_ABORT_RETRIES = 10;
|
||||
export const useAbortSession = (
|
||||
opcodeUrl: string | null | undefined,
|
||||
directory?: string,
|
||||
sessionID?: string
|
||||
sessionID?: string,
|
||||
repoId?: number
|
||||
) => {
|
||||
const client = useOpenCodeClient(opcodeUrl, directory);
|
||||
const queryClient = useQueryClient();
|
||||
@@ -541,6 +543,10 @@ export const useAbortSession = (
|
||||
|
||||
attemptAbort();
|
||||
|
||||
if (repoId) {
|
||||
cancelRalphLoop(String(repoId), targetSessionID).catch(() => {})
|
||||
}
|
||||
|
||||
retryIntervalRef.current = setInterval(() => {
|
||||
retryCountRef.current++;
|
||||
|
||||
|
||||
@@ -2,20 +2,23 @@ import { useState } from 'react'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { getRepo } from '@/api/repos'
|
||||
import { useProjectSummary } from '@/hooks/useMemories'
|
||||
import { useProjectSummary, useKvEntries } from '@/hooks/useMemories'
|
||||
import { Header } from '@/components/ui/header'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Card, CardContent } from '@/components/ui/card'
|
||||
import { Loader2, Plus, Brain } from 'lucide-react'
|
||||
import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs'
|
||||
import { Loader2, Plus, Brain, Key } from 'lucide-react'
|
||||
import { getRepoDisplayName } from '@/lib/utils'
|
||||
import { MemoryList } from '@/components/memory/MemoryList'
|
||||
import { MemoryFormDialog } from '@/components/memory/MemoryFormDialog'
|
||||
import { KvList } from '@/components/memory/KvList'
|
||||
|
||||
export function Memories() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const repoId = id ? Number(id) : undefined
|
||||
const [createOpen, setCreateOpen] = useState(false)
|
||||
const [activeTab, setActiveTab] = useState('memories')
|
||||
|
||||
const { data: repo, isLoading: repoLoading } = useQuery({
|
||||
queryKey: ['repo', repoId],
|
||||
@@ -24,6 +27,7 @@ export function Memories() {
|
||||
})
|
||||
|
||||
const { data: projectSummary, isLoading: projectSummaryLoading } = useProjectSummary(repoId)
|
||||
const { data: kvEntries } = useKvEntries(projectSummary?.projectId ?? undefined)
|
||||
|
||||
const projectId = projectSummary?.projectId ?? null
|
||||
const stats = projectSummary?.stats ?? null
|
||||
@@ -71,13 +75,17 @@ export function Memories() {
|
||||
</Header.Title>
|
||||
</div>
|
||||
<Header.Actions>
|
||||
<Button onClick={() => setCreateOpen(true)} size="sm" className="hidden sm:flex">
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
New Memory
|
||||
</Button>
|
||||
<Button onClick={() => setCreateOpen(true)} size="sm" className="sm:hidden">
|
||||
<Plus className="w-4 h-4" />
|
||||
</Button>
|
||||
{activeTab === 'memories' && (
|
||||
<>
|
||||
<Button onClick={() => setCreateOpen(true)} size="sm" className="hidden sm:flex">
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
New Memory
|
||||
</Button>
|
||||
<Button onClick={() => setCreateOpen(true)} size="sm" className="sm:hidden">
|
||||
<Plus className="w-4 h-4" />
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</Header.Actions>
|
||||
</Header>
|
||||
|
||||
@@ -98,11 +106,33 @@ export function Memories() {
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{kvEntries && kvEntries.length > 0 && (
|
||||
<Badge variant="outline" className="text-sm">
|
||||
KV Entries: {kvEntries.length}
|
||||
</Badge>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<MemoryList projectId={projectId} showFilters={true} />
|
||||
<Tabs value={activeTab} onValueChange={setActiveTab}>
|
||||
<TabsList>
|
||||
<TabsTrigger value="memories">
|
||||
<Brain className="w-4 h-4 mr-2" />
|
||||
Memories
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="kv">
|
||||
<Key className="w-4 h-4 mr-2" />
|
||||
Key-Value
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
<TabsContent value="memories">
|
||||
<MemoryList projectId={projectId} showFilters={true} />
|
||||
</TabsContent>
|
||||
<TabsContent value="kv">
|
||||
<KvList projectId={projectId ?? undefined} />
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
|
||||
<MemoryFormDialog
|
||||
|
||||
@@ -525,6 +525,7 @@ export function SessionDetail() {
|
||||
opcodeUrl={opcodeUrl}
|
||||
directory={repoDirectory}
|
||||
sessionID={sessionId}
|
||||
repoId={repoId}
|
||||
disabled={!isConnected}
|
||||
showScrollButton={showScrollButton}
|
||||
hasActiveStream={hasActiveStream}
|
||||
|
||||
Reference in new issue
Block a user