mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-09 07:29:51 +00:00
fix(web): hide unsupported Codex slash commands in remote mode (#357)
This commit is contained in:
@@ -2,7 +2,14 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
import { AssistantRuntimeProvider } from '@assistant-ui/react'
|
||||
import type { ApiClient } from '@/api/client'
|
||||
import type { AttachmentMetadata, CodexCollaborationMode, DecryptedMessage, PermissionMode, Session } from '@/types/api'
|
||||
import type {
|
||||
AttachmentMetadata,
|
||||
CodexCollaborationMode,
|
||||
DecryptedMessage,
|
||||
PermissionMode,
|
||||
Session,
|
||||
SlashCommand
|
||||
} from '@/types/api'
|
||||
import type { ChatBlock, NormalizedMessage } from '@/chat/types'
|
||||
import type { Suggestion } from '@/hooks/useActiveSuggestions'
|
||||
import { normalizeDecryptedMessage } from '@/chat/normalize'
|
||||
@@ -12,6 +19,9 @@ import { HappyComposer } from '@/components/AssistantChat/HappyComposer'
|
||||
import { HappyThread } from '@/components/AssistantChat/HappyThread'
|
||||
import { useHappyRuntime } from '@/lib/assistant-runtime'
|
||||
import { createAttachmentAdapter } from '@/lib/attachmentAdapter'
|
||||
import { findUnsupportedCodexBuiltinSlashCommand } from '@/lib/codexSlashCommands'
|
||||
import { useToast } from '@/lib/toast-context'
|
||||
import { useTranslation } from '@/lib/use-translation'
|
||||
import { SessionHeader } from '@/components/SessionHeader'
|
||||
import { TeamPanel } from '@/components/TeamPanel'
|
||||
import { usePlatform } from '@/hooks/usePlatform'
|
||||
@@ -39,8 +49,11 @@ export function SessionChat(props: {
|
||||
onAtBottomChange: (atBottom: boolean) => void
|
||||
onRetryMessage?: (localId: string) => void
|
||||
autocompleteSuggestions?: (query: string) => Promise<Suggestion[]>
|
||||
availableSlashCommands?: readonly SlashCommand[]
|
||||
}) {
|
||||
const { haptic } = usePlatform()
|
||||
const { addToast } = useToast()
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const sessionInactive = !props.session.active
|
||||
const terminalSupported = isRemoteTerminalSupported(props.session.metadata)
|
||||
@@ -271,9 +284,26 @@ export function SessionChat(props: {
|
||||
}, [navigate, props.session.id])
|
||||
|
||||
const handleSend = useCallback((text: string, attachments?: AttachmentMetadata[]) => {
|
||||
if (agentFlavor === 'codex') {
|
||||
const unsupportedCommand = findUnsupportedCodexBuiltinSlashCommand(
|
||||
text,
|
||||
props.availableSlashCommands ?? []
|
||||
)
|
||||
if (unsupportedCommand) {
|
||||
haptic.notification('error')
|
||||
addToast({
|
||||
title: t('composer.codexSlashUnsupported.title'),
|
||||
body: t('composer.codexSlashUnsupported.body', { command: `/${unsupportedCommand}` }),
|
||||
sessionId: props.session.id,
|
||||
url: `/sessions/${props.session.id}`
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
props.onSend(text, attachments)
|
||||
setForceScrollToken((token) => token + 1)
|
||||
}, [props.onSend])
|
||||
}, [agentFlavor, props.availableSlashCommands, props.onSend, props.session.id, addToast, haptic, t])
|
||||
|
||||
const attachmentAdapter = useMemo(() => {
|
||||
if (!props.session.active) {
|
||||
|
||||
Reference in New Issue
Block a user