mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +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
@@ -347,7 +347,8 @@ describe('MessagePart', () => {
|
||||
const copyButton = screen.getByTitle('Copy output')
|
||||
fireEvent.click(copyButton)
|
||||
|
||||
await expect(vi.waitFor(() => writeText.mock.calls[0]?.[0])).resolves.toBe(output)
|
||||
await vi.waitFor(() => expect(writeText).toHaveBeenCalled())
|
||||
expect(writeText).toHaveBeenCalledWith(output)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -439,6 +439,20 @@ describe('MessageThread', () => {
|
||||
expect(screen.getByText('You')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('exposes the message id on a rendered user message', () => {
|
||||
setupSettings({ simpleChatMode: false, showReasoning: false })
|
||||
|
||||
const { container } = render(
|
||||
<MessageThread
|
||||
sessionID="test-session"
|
||||
messages={[userMessage('user-42', 'Hello')]}
|
||||
pending={[]}
|
||||
/>,
|
||||
)
|
||||
|
||||
expect(container.querySelector('[data-message-id="user-42"]')).not.toBeNull()
|
||||
})
|
||||
|
||||
it('renders a projected shell message from the fixtures', () => {
|
||||
setupSettings({ simpleChatMode: false, showReasoning: false })
|
||||
|
||||
|
||||
@@ -398,7 +398,7 @@ const MessageRow = memo(function MessageRow({
|
||||
if (!hasRenderableContent(message, simpleChatMode, showReasoning)) return null
|
||||
|
||||
return (
|
||||
<div className="flex flex-col group">
|
||||
<div className="flex flex-col group" data-message-id={message.id}>
|
||||
<div
|
||||
className={`w-full rounded-lg p-1.5 ${
|
||||
isEditingThisMessage
|
||||
|
||||
@@ -1,15 +1,28 @@
|
||||
import { createRef } from 'react'
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, fireEvent, act, waitFor } from '@testing-library/react'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { PromptInput } from './PromptInput'
|
||||
import { PromptInput, type PromptInputHandle } from './PromptInput'
|
||||
import { useUIState } from '@/stores/uiStateStore'
|
||||
import { BUILTIN_COMMANDS } from '@/lib/builtinCommands'
|
||||
import { createCommandActionsMock } from '@/test/test-utils'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
runCommand: vi.fn(),
|
||||
switchSessionModel: vi.fn(),
|
||||
switchSessionAgent: vi.fn(),
|
||||
compactSession: vi.fn(),
|
||||
agents: [] as Array<{ name: string; description?: string }>,
|
||||
agents: [] as Array<{ id: string; name: string; description?: string; mode?: string; hidden?: boolean }>,
|
||||
setAgent: vi.fn(),
|
||||
cycleVariant: vi.fn(),
|
||||
showToast: {
|
||||
success: vi.fn(),
|
||||
error: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
loading: vi.fn(),
|
||||
promise: vi.fn(),
|
||||
dismiss: vi.fn(),
|
||||
},
|
||||
useSTT: vi.fn(),
|
||||
useMobile: vi.fn(),
|
||||
useCommands: vi.fn(),
|
||||
@@ -27,7 +40,6 @@ vi.mock('@/api/opencode', async () => {
|
||||
return {
|
||||
...actual,
|
||||
runCommand: mocks.runCommand,
|
||||
compactSession: mocks.compactSession,
|
||||
switchSessionModel: mocks.switchSessionModel,
|
||||
switchSessionAgent: mocks.switchSessionAgent,
|
||||
}
|
||||
@@ -42,7 +54,6 @@ vi.mock('@/hooks/useOpenCode', async () => {
|
||||
})
|
||||
|
||||
vi.mock('@/hooks/useSTT', () => ({ useSTT: mocks.useSTT }))
|
||||
vi.mock('react-router-dom', () => ({ useNavigate: () => vi.fn() }))
|
||||
vi.mock('@/hooks/useMobile', () => ({ useMobile: mocks.useMobile }))
|
||||
vi.mock('@/hooks/useCommands', () => ({ useCommands: mocks.useCommands }))
|
||||
vi.mock('@/hooks/useFileSearch', () => ({ useFileSearch: mocks.useFileSearch }))
|
||||
@@ -52,6 +63,7 @@ vi.mock('@/hooks/useSessionAgent', () => ({ useSessionAgent: mocks.useSessionAge
|
||||
vi.mock('@/stores/userBashStore', () => ({ useUserBash: mocks.useUserBash }))
|
||||
vi.mock('@/stores/sessionAgentStore', () => ({ useSessionAgentStore: mocks.useSessionAgentStore }))
|
||||
vi.mock('@/stores/sendErrorStore', () => ({ useSendErrorStore: mocks.useSendErrorStore }))
|
||||
vi.mock('@/lib/toast', () => ({ showToast: mocks.showToast }))
|
||||
|
||||
vi.mock('@/contexts/EventContext', () => ({
|
||||
usePermissions: () => ({
|
||||
@@ -65,7 +77,9 @@ vi.mock('@/components/agent/AgentQuickSelect', () => ({
|
||||
}))
|
||||
|
||||
vi.mock('@/components/model/ModelQuickSelect', () => ({
|
||||
ModelQuickSelect: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
ModelQuickSelect: ({ children, open }: { children?: React.ReactNode; open?: boolean }) => (
|
||||
<div data-testid="model-quick-select" data-open={open ? 'true' : 'false'}>{children}</div>
|
||||
),
|
||||
}))
|
||||
|
||||
vi.mock('@/components/ui/session-status-indicator', () => ({
|
||||
@@ -105,10 +119,7 @@ describe('PromptInput command submission', () => {
|
||||
isSessionActive: false,
|
||||
isStreamingResponse: false,
|
||||
onScrollToBottom: vi.fn(),
|
||||
onShowSessionsDialog: vi.fn(),
|
||||
onShowHelpDialog: vi.fn(),
|
||||
onToggleDetails: vi.fn(),
|
||||
onExportSession: vi.fn(),
|
||||
commandActions: createCommandActionsMock(),
|
||||
onPromptChange: vi.fn(),
|
||||
}
|
||||
|
||||
@@ -134,7 +145,7 @@ describe('PromptInput command submission', () => {
|
||||
mocks.runCommand.mockResolvedValue(undefined)
|
||||
mocks.switchSessionModel.mockResolvedValue(undefined)
|
||||
mocks.switchSessionAgent.mockResolvedValue(undefined)
|
||||
mocks.agents = [{ name: 'reviewer', description: 'Reviewer' }]
|
||||
mocks.agents = [{ id: 'reviewer', name: 'reviewer', description: 'Reviewer', mode: 'primary' }]
|
||||
mocks.useMobile.mockReturnValue(false)
|
||||
mocks.useSTT.mockReturnValue({
|
||||
isRecording: false,
|
||||
@@ -150,7 +161,11 @@ describe('PromptInput command submission', () => {
|
||||
clear: vi.fn(),
|
||||
})
|
||||
mocks.useCommands.mockReturnValue({
|
||||
filterCommands: (query: string) => query === 'review' ? [{ name: 'review', description: 'Review' }] : [],
|
||||
filterCommands: (query: string) => {
|
||||
if (query === 'review') return [{ name: 'review', description: 'Review' }]
|
||||
const builtin = BUILTIN_COMMANDS.find((command) => command.name === query)
|
||||
return builtin ? [builtin] : []
|
||||
},
|
||||
})
|
||||
mocks.useFileSearch.mockReturnValue({ files: [] })
|
||||
mocks.useModelSelection.mockReturnValue({
|
||||
@@ -163,10 +178,10 @@ describe('PromptInput command submission', () => {
|
||||
toggleFavorite: vi.fn(),
|
||||
isModelStateLoading: false,
|
||||
})
|
||||
mocks.useVariants.mockReturnValue({ hasVariants: false, currentVariant: null, cycleVariant: vi.fn() })
|
||||
mocks.useVariants.mockReturnValue({ hasVariants: false, currentVariant: null, cycleVariant: mocks.cycleVariant })
|
||||
mocks.useSessionAgent.mockReturnValue({ agent: 'build' })
|
||||
mocks.useUserBash.mockImplementation((selector: (state: unknown) => unknown) => selector({ addUserBashCommand: vi.fn() }))
|
||||
mocks.useSessionAgentStore.mockImplementation((selector: (state: unknown) => unknown) => selector({ setAgent: vi.fn() }))
|
||||
mocks.useSessionAgentStore.mockImplementation((selector: (state: unknown) => unknown) => selector({ setAgent: mocks.setAgent }))
|
||||
mocks.useSendErrorStore.mockImplementation((selector: (state: unknown) => unknown) => selector({ errors: {} }))
|
||||
useUIState.getState().clearPendingPromptCommand()
|
||||
useUIState.getState().clearPendingPromptFile()
|
||||
@@ -222,4 +237,88 @@ describe('PromptInput command submission', () => {
|
||||
await waitFor(() => expect(mocks.runCommand).toHaveBeenCalled())
|
||||
expect(input).toHaveValue('/review')
|
||||
})
|
||||
|
||||
it('switches to the next primary agent for /agent without invoking runCommand', async () => {
|
||||
mocks.agents = [
|
||||
{ id: 'build', name: 'build', mode: 'primary' },
|
||||
{ id: 'plan', name: 'plan', mode: 'primary' },
|
||||
]
|
||||
renderComponent()
|
||||
|
||||
const input = await screen.findByPlaceholderText('Send a message...')
|
||||
fireEvent.change(input, { target: { value: '/agent' } })
|
||||
fireEvent.click(screen.getByTitle('Send'))
|
||||
|
||||
await waitFor(() => expect(mocks.setAgent).toHaveBeenCalledWith('test-session', 'plan'))
|
||||
expect(mocks.runCommand).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('reports when /variants is used with a model that has no variants', async () => {
|
||||
mocks.useVariants.mockReturnValue({ hasVariants: false, currentVariant: null, cycleVariant: mocks.cycleVariant })
|
||||
renderComponent()
|
||||
|
||||
const input = await screen.findByPlaceholderText('Send a message...')
|
||||
fireEvent.change(input, { target: { value: '/variants' } })
|
||||
fireEvent.click(screen.getByTitle('Send'))
|
||||
|
||||
await waitFor(() => expect(mocks.showToast.info).toHaveBeenCalledWith('The selected model has no variants'))
|
||||
expect(mocks.cycleVariant).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('cycles variants for /variants when the model has them', async () => {
|
||||
mocks.useVariants.mockReturnValue({ hasVariants: true, currentVariant: 'high', cycleVariant: mocks.cycleVariant })
|
||||
renderComponent()
|
||||
|
||||
const input = await screen.findByPlaceholderText('Send a message...')
|
||||
fireEvent.change(input, { target: { value: '/variants' } })
|
||||
fireEvent.click(screen.getByTitle('Send'))
|
||||
|
||||
await waitFor(() => expect(mocks.cycleVariant).toHaveBeenCalled())
|
||||
expect(mocks.showToast.info).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('opens the model picker through the imperative handle while the session is active', () => {
|
||||
const queryClient = createTestQueryClient()
|
||||
queryClient.setQueryData(['opencode', 'session', 'test-session', '/test'], sessionInfo())
|
||||
const ref = createRef<PromptInputHandle>()
|
||||
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<PromptInput {...defaultProps} ref={ref} isSessionActive />
|
||||
</QueryClientProvider>
|
||||
)
|
||||
|
||||
expect(screen.getByTestId('model-quick-select')).toHaveAttribute('data-open', 'false')
|
||||
|
||||
act(() => {
|
||||
ref.current?.openModelPicker()
|
||||
})
|
||||
|
||||
expect(screen.getByTestId('model-quick-select')).toHaveAttribute('data-open', 'true')
|
||||
})
|
||||
|
||||
it('keeps attachments and clears only the text when a built-in command is submitted', async () => {
|
||||
const { container } = renderComponent()
|
||||
|
||||
const input = await screen.findByPlaceholderText('Send a message...')
|
||||
await attachImage(container)
|
||||
|
||||
fireEvent.change(input, { target: { value: '/btw hi' } })
|
||||
fireEvent.click(screen.getByTitle('Send'))
|
||||
|
||||
await waitFor(() => expect(mocks.showToast.info).toHaveBeenCalledWith('Built-in commands do not use attachments; they were kept'))
|
||||
expect(input).toHaveValue('')
|
||||
expect(screen.getByText('pic.png')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('clears the prompt for a built-in command without attachments', async () => {
|
||||
renderComponent()
|
||||
|
||||
const input = await screen.findByPlaceholderText('Send a message...')
|
||||
fireEvent.change(input, { target: { value: '/btw hi' } })
|
||||
fireEvent.click(screen.getByTitle('Send'))
|
||||
|
||||
await waitFor(() => expect(input).toHaveValue(''))
|
||||
expect(mocks.showToast.info).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -3,13 +3,13 @@ import { render, screen, fireEvent, waitFor } from '@testing-library/react'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { PromptInput } from './PromptInput'
|
||||
import { useUIState } from '@/stores/uiStateStore'
|
||||
import { createCommandActionsMock } from '@/test/test-utils'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
sendPrompt: vi.fn(),
|
||||
switchSessionModel: vi.fn(),
|
||||
switchSessionAgent: vi.fn(),
|
||||
runCommand: vi.fn(),
|
||||
compactSession: vi.fn(),
|
||||
agents: [] as Array<{ name: string; description?: string }>,
|
||||
useSTT: vi.fn(),
|
||||
useMobile: vi.fn(),
|
||||
@@ -29,7 +29,6 @@ vi.mock('@/api/opencode', async () => {
|
||||
...actual,
|
||||
sendPrompt: mocks.sendPrompt,
|
||||
runCommand: mocks.runCommand,
|
||||
compactSession: mocks.compactSession,
|
||||
switchSessionModel: mocks.switchSessionModel,
|
||||
switchSessionAgent: mocks.switchSessionAgent,
|
||||
}
|
||||
@@ -44,7 +43,6 @@ vi.mock('@/hooks/useOpenCode', async () => {
|
||||
})
|
||||
|
||||
vi.mock('@/hooks/useSTT', () => ({ useSTT: mocks.useSTT }))
|
||||
vi.mock('react-router-dom', () => ({ useNavigate: () => vi.fn() }))
|
||||
vi.mock('@/hooks/useMobile', () => ({ useMobile: mocks.useMobile }))
|
||||
vi.mock('@/hooks/useCommands', () => ({ useCommands: mocks.useCommands }))
|
||||
vi.mock('@/hooks/useFileSearch', () => ({ useFileSearch: mocks.useFileSearch }))
|
||||
@@ -112,10 +110,7 @@ describe('PromptInput agent mention submission', () => {
|
||||
isSessionActive: false,
|
||||
isStreamingResponse: false,
|
||||
onScrollToBottom: vi.fn(),
|
||||
onShowSessionsDialog: vi.fn(),
|
||||
onShowHelpDialog: vi.fn(),
|
||||
onToggleDetails: vi.fn(),
|
||||
onExportSession: vi.fn(),
|
||||
commandActions: createCommandActionsMock(),
|
||||
onPromptChange: vi.fn(),
|
||||
}
|
||||
|
||||
@@ -142,7 +137,6 @@ describe('PromptInput agent mention submission', () => {
|
||||
mocks.switchSessionModel.mockResolvedValue(undefined)
|
||||
mocks.switchSessionAgent.mockResolvedValue(undefined)
|
||||
mocks.runCommand.mockResolvedValue(undefined)
|
||||
mocks.compactSession.mockResolvedValue(undefined)
|
||||
mocks.agents = [{ name: 'reviewer', description: 'Reviewer' }]
|
||||
mocks.useMobile.mockReturnValue(false)
|
||||
mocks.useSTT.mockReturnValue({
|
||||
|
||||
@@ -3,6 +3,7 @@ import { render, screen, fireEvent, act, waitFor } from '@testing-library/react'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { PromptInput } from './PromptInput'
|
||||
import { useUIState } from '@/stores/uiStateStore'
|
||||
import { createCommandActionsMock } from '@/test/test-utils'
|
||||
|
||||
const createTestQueryClient = () => new QueryClient({
|
||||
defaultOptions: {
|
||||
@@ -141,11 +142,7 @@ describe('PromptInput STT Gesture Tests', () => {
|
||||
isSessionActive: false,
|
||||
isStreamingResponse: false,
|
||||
onScrollToBottom: vi.fn(),
|
||||
onShowSessionsDialog: vi.fn(),
|
||||
onShowModelsDialog: vi.fn(),
|
||||
onShowHelpDialog: vi.fn(),
|
||||
onToggleDetails: vi.fn(),
|
||||
onExportSession: vi.fn(),
|
||||
commandActions: createCommandActionsMock(),
|
||||
onPromptChange: vi.fn(),
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import { ModelQuickSelect } from '@/components/model/ModelQuickSelect'
|
||||
import { AgentQuickSelect } from '@/components/agent/AgentQuickSelect'
|
||||
import { VoiceStatusOverlay, type VoiceStatusOverlayState } from './VoiceStatusOverlay'
|
||||
import { detectMentionTrigger, parsePromptToInput, getFilename, filterAgentsByQuery } from '@/lib/promptParser'
|
||||
import { getNextPrimaryAgentId } from '@/lib/primaryAgents'
|
||||
import { randomId } from '@/lib/utils'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import { formatModelName } from '@/api/providers'
|
||||
@@ -35,6 +36,7 @@ import { useProviders } from '@/hooks/useProviders'
|
||||
|
||||
import type { CommandInfo, ModelRef } from '@opencode-manager/shared/opencode'
|
||||
import type { FileAttachmentInfo, ImageAttachment } from '@/api/types'
|
||||
import { isBuiltinCommand, type CommandActions, type PageCommandActions } from '@/lib/builtinCommands'
|
||||
|
||||
const ACCEPTED_IMAGE_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp", "image/heic", "image/heif"]
|
||||
|
||||
@@ -58,6 +60,7 @@ export interface PromptInputHandle {
|
||||
setPromptValue: (value: string) => void
|
||||
clearPrompt: () => void
|
||||
triggerFileUpload: () => void
|
||||
openModelPicker: () => void
|
||||
}
|
||||
|
||||
interface PromptInputProps {
|
||||
@@ -67,12 +70,7 @@ interface PromptInputProps {
|
||||
isSessionActive?: boolean
|
||||
isStreamingResponse?: boolean
|
||||
onScrollToBottom: () => void
|
||||
onShowSessionsDialog?: () => void
|
||||
onShowHelpDialog?: () => void
|
||||
onToggleDetails?: () => boolean
|
||||
onExportSession?: () => void
|
||||
onUndo?: () => void | Promise<void>
|
||||
onRedo?: () => void | Promise<void>
|
||||
commandActions: PageCommandActions
|
||||
onPromptChange?: (hasContent: boolean) => void
|
||||
}
|
||||
|
||||
@@ -83,12 +81,7 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
|
||||
isSessionActive = false,
|
||||
isStreamingResponse = false,
|
||||
onScrollToBottom,
|
||||
onShowSessionsDialog,
|
||||
onShowHelpDialog,
|
||||
onToggleDetails,
|
||||
onExportSession,
|
||||
onUndo,
|
||||
onRedo,
|
||||
commandActions,
|
||||
onPromptChange
|
||||
}, ref) {
|
||||
const [prompt, setPrompt] = useState('')
|
||||
@@ -98,6 +91,7 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
|
||||
const [attachedFiles, setAttachedFiles] = useState(new Map<string, FileAttachmentInfo>())
|
||||
const [imageAttachments, setImageAttachments] = useState<ImageAttachment[]>([])
|
||||
const [isDragging, setIsDragging] = useState(false)
|
||||
const [isModelPickerOpen, setIsModelPickerOpen] = useState(false)
|
||||
const [showMentionSuggestions, setShowMentionSuggestions] = useState(false)
|
||||
const [mentionQuery, setMentionQuery] = useState('')
|
||||
const [mentionRange, setMentionRange] = useState<{ start: number, end: number } | null>(null)
|
||||
@@ -156,7 +150,7 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
|
||||
imageAttachmentsRef.current = imageAttachments
|
||||
}, [attachedFiles, imageAttachments, prompt])
|
||||
|
||||
const clearSubmittedPrompt = useCallback((submittedPrompt: string, submittedAttachedFiles: Map<string, FileAttachmentInfo>, submittedImageAttachments: ImageAttachment[]) => {
|
||||
const clearSubmittedPrompt = useCallback((submittedPrompt: string, submittedAttachedFiles: Map<string, FileAttachmentInfo>, submittedImageAttachments: ImageAttachment[], options?: { keepAttachments?: boolean }) => {
|
||||
if (
|
||||
promptRef.current !== submittedPrompt ||
|
||||
attachedFilesRef.current !== submittedAttachedFiles ||
|
||||
@@ -166,9 +160,11 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
|
||||
}
|
||||
|
||||
setPrompt('')
|
||||
setAttachedFiles(new Map())
|
||||
revokeBlobUrls(submittedImageAttachments)
|
||||
setImageAttachments([])
|
||||
if (!options?.keepAttachments) {
|
||||
setAttachedFiles(new Map())
|
||||
revokeBlobUrls(submittedImageAttachments)
|
||||
setImageAttachments([])
|
||||
}
|
||||
clearSTT()
|
||||
}, [clearSTT])
|
||||
|
||||
@@ -206,6 +202,9 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
|
||||
},
|
||||
triggerFileUpload: () => {
|
||||
fileInputRef.current?.click()
|
||||
},
|
||||
openModelPicker: () => {
|
||||
setIsModelPickerOpen(true)
|
||||
}
|
||||
}), [imageAttachments, clearSTT, isRecording, abortRecording, resetVoiceGestureState])
|
||||
const sessionAgent = useSessionAgent(sessionID, directory)
|
||||
@@ -348,9 +347,14 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
|
||||
agents: parsed.agents,
|
||||
skills: parsed.skills,
|
||||
}).then((shouldClear) => {
|
||||
if (shouldClear) {
|
||||
clearSubmittedPrompt(submittedPrompt, submittedAttachedFiles, submittedImageAttachments)
|
||||
if (!shouldClear) return
|
||||
const keepAttachments = isBuiltinCommand(command) && (submittedAttachedFiles.size > 0 || submittedImageAttachments.length > 0)
|
||||
if (keepAttachments) {
|
||||
clearSubmittedPrompt(submittedPrompt, submittedAttachedFiles, submittedImageAttachments, { keepAttachments: true })
|
||||
showToast.info('Built-in commands do not use attachments; they were kept')
|
||||
return
|
||||
}
|
||||
clearSubmittedPrompt(submittedPrompt, submittedAttachedFiles, submittedImageAttachments)
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -499,15 +503,6 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
|
||||
setMentionRange(null)
|
||||
}
|
||||
|
||||
const handleAgentChange = (agentId: string) => {
|
||||
setLocalMode(agentId)
|
||||
setStoredAgent(sessionID, agentId)
|
||||
const agent = agents.find(a => a.id === agentId)
|
||||
if (agent?.model) {
|
||||
setStoredModel({ providerID: agent.model.providerID, modelID: agent.model.id })
|
||||
}
|
||||
}
|
||||
|
||||
const startVoiceRecording = async () => {
|
||||
if (isRecording || isProcessing || isTogglingRecording) {
|
||||
return
|
||||
@@ -985,9 +980,7 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
|
||||
clearSTT()
|
||||
} else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 't') {
|
||||
e.preventDefault()
|
||||
if (hasVariants) {
|
||||
cycleVariant()
|
||||
}
|
||||
handleCycleVariant()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1089,18 +1082,48 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
|
||||
: undefined,
|
||||
[model, currentVariant],
|
||||
)
|
||||
|
||||
const handleAgentChange = useCallback((agentId: string) => {
|
||||
setLocalMode(agentId)
|
||||
setStoredAgent(sessionID, agentId)
|
||||
const agent = agents.find(a => a.id === agentId)
|
||||
if (agent?.model) {
|
||||
setStoredModel({ providerID: agent.model.providerID, modelID: agent.model.id })
|
||||
}
|
||||
}, [agents, sessionID, setStoredAgent, setStoredModel])
|
||||
|
||||
const handleCycleVariant = useCallback(() => {
|
||||
if (!hasVariants) {
|
||||
showToast.info('The selected model has no variants')
|
||||
return
|
||||
}
|
||||
cycleVariant()
|
||||
}, [hasVariants, cycleVariant])
|
||||
|
||||
const handleCycleAgent = useCallback(() => {
|
||||
const next = getNextPrimaryAgentId(agents, currentMode)
|
||||
if (!next) {
|
||||
showToast.info('No primary agents available')
|
||||
return
|
||||
}
|
||||
handleAgentChange(next)
|
||||
}, [agents, currentMode, handleAgentChange])
|
||||
|
||||
const commandActionsWithPrompt = useMemo<CommandActions>(
|
||||
() => ({
|
||||
...commandActions,
|
||||
cycleAgent: handleCycleAgent,
|
||||
cycleVariant: handleCycleVariant,
|
||||
}),
|
||||
[commandActions, handleCycleAgent, handleCycleVariant],
|
||||
)
|
||||
|
||||
const { executeCommand } = useCommandHandler({
|
||||
sessionID,
|
||||
directory,
|
||||
model: modelRef,
|
||||
currentAgent: currentMode,
|
||||
onShowSessionsDialog,
|
||||
onShowModelsDialog: undefined,
|
||||
onShowHelpDialog,
|
||||
onToggleDetails,
|
||||
onExportSession,
|
||||
onUndo,
|
||||
onRedo
|
||||
actions: commandActionsWithPrompt,
|
||||
})
|
||||
const showStopButton = isSessionActive
|
||||
const hideSecondaryButtons = isMobile && isSessionActive
|
||||
@@ -1298,6 +1321,11 @@ return (
|
||||
<SessionStatusIndicator sessionID={sessionID} showLabel />
|
||||
</div>
|
||||
)}
|
||||
<ModelQuickSelect
|
||||
directory={directory}
|
||||
open={isModelPickerOpen}
|
||||
onOpenChange={setIsModelPickerOpen}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
@@ -1307,26 +1335,27 @@ return (
|
||||
onAgentChange={handleAgentChange}
|
||||
isBashMode={isBashMode}
|
||||
/>
|
||||
{isSessionActive ? (
|
||||
<div className="px-2.5 py-1.5 md:px-3 md:py-2 rounded-lg text-xs md:text-sm font-medium text-muted-foreground max-w-[120px] md:max-w-[180px]">
|
||||
<SessionStatusIndicator sessionID={sessionID} showLabel />
|
||||
</div>
|
||||
) : (
|
||||
!hideSecondaryButtons && (
|
||||
<ModelQuickSelect
|
||||
directory={directory}
|
||||
>
|
||||
<button
|
||||
className="px-2.5 py-0.5 md:px-3 min-h-[36px] min-w-0 rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 hover:border-foreground/30 transition-colors cursor-pointer flex-1 md:flex-initial md:w-auto max-w-[110px] md:max-w-[220px] dark:border-border/30 flex flex-col items-start justify-center overflow-hidden"
|
||||
>
|
||||
<span className="truncate w-full text-left">{displayModelName || 'Select model'}</span>
|
||||
{hasVariants && currentVariant && (
|
||||
<span className="text-[10px] text-highlight truncate w-full text-center capitalize">{currentVariant}</span>
|
||||
)}
|
||||
</button>
|
||||
</ModelQuickSelect>
|
||||
)
|
||||
{isSessionActive && (
|
||||
<div className="px-2.5 py-1.5 md:px-3 md:py-2 rounded-lg text-xs md:text-sm font-medium text-muted-foreground max-w-[120px] md:max-w-[180px]">
|
||||
<SessionStatusIndicator sessionID={sessionID} showLabel />
|
||||
</div>
|
||||
)}
|
||||
<ModelQuickSelect
|
||||
directory={directory}
|
||||
open={isModelPickerOpen}
|
||||
onOpenChange={setIsModelPickerOpen}
|
||||
>
|
||||
{!isSessionActive && !hideSecondaryButtons && (
|
||||
<button
|
||||
className="px-2.5 py-0.5 md:px-3 min-h-[36px] min-w-0 rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 hover:border-foreground/30 transition-colors cursor-pointer flex-1 md:flex-initial md:w-auto max-w-[110px] md:max-w-[220px] dark:border-border/30 flex flex-col items-start justify-center overflow-hidden"
|
||||
>
|
||||
<span className="truncate w-full text-left">{displayModelName || 'Select model'}</span>
|
||||
{hasVariants && currentVariant && (
|
||||
<span className="text-[10px] text-highlight truncate w-full text-center capitalize">{currentVariant}</span>
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
</ModelQuickSelect>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user