mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-07 01:21:37 +00:00
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import {
|
|
getBuiltinSlashCommands,
|
|
mergeSlashCommands
|
|
} from '@hapi/protocol/slashCommands'
|
|
import type { SlashCommand } from '@hapi/protocol/apiTypes'
|
|
|
|
const UNSUPPORTED_CODEX_BUILTIN_COMMANDS = new Set([
|
|
'review',
|
|
'new',
|
|
'compat',
|
|
'undo',
|
|
'diff',
|
|
])
|
|
|
|
export { getBuiltinSlashCommands, mergeSlashCommands }
|
|
|
|
export function findCodexCustomPromptExpansion(
|
|
text: string,
|
|
availableCommands: readonly SlashCommand[]
|
|
): string | null {
|
|
const trimmed = text.trim()
|
|
const match = /^\/([a-z0-9:_-]+)$/i.exec(trimmed)
|
|
if (!match) {
|
|
return null
|
|
}
|
|
|
|
const commandName = match[1]?.toLowerCase()
|
|
if (!commandName) {
|
|
return null
|
|
}
|
|
|
|
const command = availableCommands.find(
|
|
candidate => candidate.source !== 'builtin'
|
|
&& candidate.name.toLowerCase() === commandName
|
|
&& typeof candidate.content === 'string'
|
|
&& candidate.content.length > 0
|
|
)
|
|
return command?.content ?? null
|
|
}
|
|
|
|
export function findUnsupportedCodexBuiltinSlashCommand(
|
|
text: string,
|
|
availableCommands: readonly SlashCommand[]
|
|
): string | null {
|
|
const match = /^\s*\/([a-z0-9:_-]+)(?:\s|$)/i.exec(text)
|
|
if (!match) {
|
|
return null
|
|
}
|
|
|
|
const commandName = match[1]?.toLowerCase()
|
|
if (!commandName || !UNSUPPORTED_CODEX_BUILTIN_COMMANDS.has(commandName)) {
|
|
return null
|
|
}
|
|
|
|
const hasCustomCommand = availableCommands.some(
|
|
command => command.source !== 'builtin' && command.name.toLowerCase() === commandName
|
|
)
|
|
|
|
return hasCustomCommand ? null : commandName
|
|
}
|