mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Replace the split built-in command name list and switch with one typed registry, so a registered command without a handler is a compile error. Remove the broken themes/share/unshare/editor entries and the hardcoded init; server and custom commands now win on a name clash and built-ins dispatch by registry identity. Add /copy, /btw, /rename, /fork (message picker), /timeline, /model, /agent, /variants, /mcp, /skills, /settings and /connect. Open the model picker through state so /model and the select-model shortcut work while a response is running, load full session history in the fork picker, and keep attachments when a built-in command is submitted. Extract shared clipboard and primary-agent helpers, reuse CopyButton in the manager token settings, and update the Quick Start and chat docs.
100 lines
3.3 KiB
TypeScript
100 lines
3.3 KiB
TypeScript
import { useEffect, useMemo, useState } from 'react'
|
|
import type { SessionMessageInfo } from '@opencode-manager/shared/opencode'
|
|
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
|
|
import { Input } from '@/components/ui/input'
|
|
|
|
const MESSAGE_PREVIEW_MAX_LENGTH = 200
|
|
|
|
interface SessionMessagePickerDialogProps {
|
|
open: boolean
|
|
onOpenChange: (open: boolean) => void
|
|
title: string
|
|
messages: SessionMessageInfo[]
|
|
leadingOptionLabel?: string
|
|
loading?: boolean
|
|
onSelect: (messageID: string | undefined) => void
|
|
}
|
|
|
|
function messagePreview(text: string): string {
|
|
const singleLine = text.replace(/\s+/g, ' ').trim()
|
|
return singleLine.length > MESSAGE_PREVIEW_MAX_LENGTH
|
|
? singleLine.slice(0, MESSAGE_PREVIEW_MAX_LENGTH)
|
|
: singleLine
|
|
}
|
|
|
|
export function SessionMessagePickerDialog({
|
|
open,
|
|
onOpenChange,
|
|
title,
|
|
messages,
|
|
leadingOptionLabel,
|
|
loading = false,
|
|
onSelect,
|
|
}: SessionMessagePickerDialogProps) {
|
|
const [query, setQuery] = useState('')
|
|
|
|
useEffect(() => {
|
|
if (open) setQuery('')
|
|
}, [open])
|
|
|
|
const items = useMemo(() => {
|
|
const userMessages = messages.filter(
|
|
(message): message is Extract<SessionMessageInfo, { type: 'user' }> =>
|
|
message.type === 'user' && message.text.trim().length > 0,
|
|
)
|
|
const normalizedQuery = query.trim().toLowerCase()
|
|
const filtered = normalizedQuery
|
|
? userMessages.filter((message) => message.text.toLowerCase().includes(normalizedQuery))
|
|
: userMessages
|
|
return [...filtered].reverse()
|
|
}, [messages, query])
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<DialogContent className="max-w-2xl">
|
|
<DialogTitle>{title}</DialogTitle>
|
|
<Input
|
|
value={query}
|
|
onChange={(event) => setQuery(event.target.value)}
|
|
placeholder="Search messages"
|
|
autoFocus
|
|
className="mt-4"
|
|
/>
|
|
<div className="flex flex-col gap-1 max-h-[60vh] overflow-y-auto mt-4">
|
|
{leadingOptionLabel && (
|
|
<button
|
|
type="button"
|
|
onClick={() => onSelect(undefined)}
|
|
className="w-full rounded-md border border-border px-3 py-2 text-left text-sm hover:bg-accent"
|
|
>
|
|
{leadingOptionLabel}
|
|
</button>
|
|
)}
|
|
{loading ? (
|
|
<span className="px-3 py-2 text-sm text-muted-foreground">Loading messages…</span>
|
|
) : (
|
|
<>
|
|
{items.map((message) => (
|
|
<button
|
|
key={message.id}
|
|
type="button"
|
|
onClick={() => onSelect(message.id)}
|
|
className="w-full rounded-md border border-border px-3 py-2 text-left hover:bg-accent"
|
|
>
|
|
<span className="block text-sm truncate">{messagePreview(message.text)}</span>
|
|
<span className="block text-xs text-muted-foreground">
|
|
{new Date(message.time.created).toLocaleTimeString([], { timeStyle: 'short' })}
|
|
</span>
|
|
</button>
|
|
))}
|
|
{items.length === 0 && (
|
|
<span className="px-3 py-2 text-sm text-muted-foreground">No messages</span>
|
|
)}
|
|
</>
|
|
)}
|
|
</div>
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|