mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(commands): align built-in slash commands with OpenCode v2
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.
This commit is contained in:
1 parent
7cac8baade
commit
7e93eb4c34
35 files changed
+2291
-767
No files matched your search
@@ -0,0 +1,115 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { CopyButton } from '@/components/ui/copy-button'
|
||||
import { TextPart } from '@/components/message/TextPart'
|
||||
import { askSideQuestion } from '@/api/opencode'
|
||||
|
||||
interface SideQuestionDialogProps {
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
sessionID: string
|
||||
initialQuestion?: string
|
||||
}
|
||||
|
||||
export function SideQuestionDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
sessionID,
|
||||
initialQuestion = '',
|
||||
}: SideQuestionDialogProps) {
|
||||
const [question, setQuestion] = useState(initialQuestion)
|
||||
const [answer, setAnswer] = useState('')
|
||||
const [error, setError] = useState(false)
|
||||
const [pending, setPending] = useState(false)
|
||||
const controllerRef = useRef<AbortController | null>(null)
|
||||
const requestRef = useRef(0)
|
||||
const lastQuestionRef = useRef('')
|
||||
|
||||
const ask = useCallback(async (value: string) => {
|
||||
const trimmed = value.trim()
|
||||
if (!trimmed) return
|
||||
lastQuestionRef.current = trimmed
|
||||
|
||||
controllerRef.current?.abort()
|
||||
const controller = new AbortController()
|
||||
controllerRef.current = controller
|
||||
const requestId = ++requestRef.current
|
||||
|
||||
setPending(true)
|
||||
setError(false)
|
||||
setAnswer('')
|
||||
|
||||
try {
|
||||
const result = await askSideQuestion(sessionID, trimmed, controller.signal)
|
||||
if (requestRef.current !== requestId || controller.signal.aborted) return
|
||||
setAnswer(result)
|
||||
setPending(false)
|
||||
} catch {
|
||||
if (requestRef.current !== requestId || controller.signal.aborted) return
|
||||
setError(true)
|
||||
setPending(false)
|
||||
}
|
||||
}, [sessionID])
|
||||
|
||||
useEffect(() => {
|
||||
if (initialQuestion.trim()) {
|
||||
void ask(initialQuestion)
|
||||
}
|
||||
return () => {
|
||||
controllerRef.current?.abort()
|
||||
}
|
||||
}, [ask, initialQuestion])
|
||||
|
||||
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault()
|
||||
void ask(question)
|
||||
}
|
||||
|
||||
const handleRetry = () => {
|
||||
void ask(lastQuestionRef.current)
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-2xl">
|
||||
<DialogTitle>Side question</DialogTitle>
|
||||
<form onSubmit={handleSubmit} className="flex items-center gap-2 mt-4">
|
||||
<Input
|
||||
value={question}
|
||||
onChange={(event) => setQuestion(event.target.value)}
|
||||
placeholder="Ask a side question"
|
||||
autoFocus
|
||||
/>
|
||||
<Button type="submit" disabled={!question.trim()}>
|
||||
Ask
|
||||
</Button>
|
||||
</form>
|
||||
{pending && (
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
<span>Thinking...</span>
|
||||
</div>
|
||||
)}
|
||||
{error && !pending && (
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-sm text-destructive">Failed to get an answer</span>
|
||||
<Button type="button" variant="outline" size="sm" onClick={handleRetry}>
|
||||
Retry
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{answer && !pending && (
|
||||
<div className="flex items-start gap-2">
|
||||
<div className="min-w-0 flex-1 max-h-[50vh] overflow-y-auto">
|
||||
<TextPart text={answer} />
|
||||
</div>
|
||||
<CopyButton content={answer} title="Copy answer" />
|
||||
</div>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user