mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
refactor: extract agent flavor utility functions into shared module
This commit is contained in:
@@ -20,6 +20,7 @@ import { useActiveSuggestions } from '@/hooks/useActiveSuggestions'
|
||||
import { applySuggestion } from '@/utils/applySuggestion'
|
||||
import { usePlatform } from '@/hooks/usePlatform'
|
||||
import { usePWAInstall } from '@/hooks/usePWAInstall'
|
||||
import { isCodexFamilyFlavor } from '@/lib/agentFlavorUtils'
|
||||
import { markSkillUsed } from '@/lib/recent-skills'
|
||||
import { FloatingOverlay } from '@/components/ChatInput/FloatingOverlay'
|
||||
import { Autocomplete } from '@/components/ChatInput/Autocomplete'
|
||||
@@ -312,7 +313,7 @@ export function HappyComposer(props: {
|
||||
|
||||
useEffect(() => {
|
||||
const handleGlobalKeyDown = (e: globalThis.KeyboardEvent) => {
|
||||
if (e.key === 'm' && (e.metaKey || e.ctrlKey) && onModelModeChange && agentFlavor !== 'codex' && agentFlavor !== 'gemini' && agentFlavor !== 'opencode') {
|
||||
if (e.key === 'm' && (e.metaKey || e.ctrlKey) && onModelModeChange && !isCodexFamilyFlavor(agentFlavor)) {
|
||||
e.preventDefault()
|
||||
const currentIndex = MODEL_MODES.indexOf(modelMode as typeof MODEL_MODES[number])
|
||||
const nextIndex = (currentIndex + 1) % MODEL_MODES.length
|
||||
@@ -386,7 +387,7 @@ export function HappyComposer(props: {
|
||||
}, [onModelModeChange, controlsDisabled, haptic])
|
||||
|
||||
const showPermissionSettings = Boolean(onPermissionModeChange && permissionModeOptions.length > 0)
|
||||
const showModelSettings = Boolean(onModelModeChange && agentFlavor !== 'codex' && agentFlavor !== 'gemini' && agentFlavor !== 'opencode')
|
||||
const showModelSettings = Boolean(onModelModeChange && !isCodexFamilyFlavor(agentFlavor))
|
||||
const showSettingsButton = Boolean(showPermissionSettings || showModelSettings)
|
||||
const showAbortButton = true
|
||||
const voiceEnabled = Boolean(onVoiceToggle)
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { SessionMetadataSummary } from '@/types/api'
|
||||
import type { ChatToolCall, ToolPermission } from '@/chat/types'
|
||||
import { usePlatform } from '@/hooks/usePlatform'
|
||||
import { Spinner } from '@/components/Spinner'
|
||||
import { isCodexFamilyFlavor } from '@/lib/agentFlavorUtils'
|
||||
import { getInputStringAny } from '@/lib/toolInputUtils'
|
||||
import { useTranslation } from '@/lib/use-translation'
|
||||
|
||||
@@ -22,9 +23,7 @@ function isToolAllowedForSession(toolName: string, toolInput: unknown, allowedTo
|
||||
}
|
||||
|
||||
function isCodexSession(metadata: SessionMetadataSummary | null, toolName: string): boolean {
|
||||
return metadata?.flavor === 'codex'
|
||||
|| metadata?.flavor === 'gemini'
|
||||
|| metadata?.flavor === 'opencode'
|
||||
return isCodexFamilyFlavor(metadata?.flavor)
|
||||
|| toolName.startsWith('Codex')
|
||||
|| toolName.startsWith('Gemini')
|
||||
|| toolName.startsWith('OpenCode')
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { ApiClient } from '@/api/client'
|
||||
import type { ModelMode, PermissionMode } from '@/types/api'
|
||||
import { queryKeys } from '@/lib/query-keys'
|
||||
import { clearMessageWindow } from '@/lib/message-window-store'
|
||||
import { isKnownFlavor } from '@/lib/agentFlavorUtils'
|
||||
|
||||
export function useSessionActions(
|
||||
api: ApiClient | null,
|
||||
@@ -62,8 +63,7 @@ export function useSessionActions(
|
||||
if (!api || !sessionId) {
|
||||
throw new Error('Session unavailable')
|
||||
}
|
||||
const isKnownFlavor = agentFlavor === 'claude' || agentFlavor === 'codex' || agentFlavor === 'gemini' || agentFlavor === 'opencode'
|
||||
if (isKnownFlavor && !isPermissionModeAllowedForFlavor(mode, agentFlavor)) {
|
||||
if (isKnownFlavor(agentFlavor) && !isPermissionModeAllowedForFlavor(mode, agentFlavor)) {
|
||||
throw new Error('Invalid permission mode for session flavor')
|
||||
}
|
||||
await api.setPermissionMode(sessionId, mode)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
export function isCodexFamilyFlavor(flavor?: string | null): boolean {
|
||||
return flavor === 'codex' || flavor === 'gemini' || flavor === 'opencode'
|
||||
}
|
||||
|
||||
export function isClaudeFlavor(flavor?: string | null): boolean {
|
||||
return flavor === 'claude'
|
||||
}
|
||||
|
||||
export function isKnownFlavor(flavor?: string | null): boolean {
|
||||
return isClaudeFlavor(flavor) || isCodexFamilyFlavor(flavor)
|
||||
}
|
||||
Reference in New Issue
Block a user