mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-22 08:00:53 +00:00
chore: refine terminal ai prefix handling (#12328)
This commit is contained in:
@@ -105,7 +105,7 @@ func (i *aiInputInterceptor) HandleEnter(onStart func(), onDone func(string), on
|
||||
recentCommands := append([]string(nil), i.recentCommands...)
|
||||
i.mu.Unlock()
|
||||
|
||||
if !strings.HasPrefix(currentLine, i.prefix) {
|
||||
if !matchesAIPrefix(currentLine, i.prefix) {
|
||||
if currentLine != "" {
|
||||
i.pushRecentCommand(currentLine)
|
||||
}
|
||||
@@ -211,13 +211,22 @@ func sanitizeInputLine(raw string) string {
|
||||
return strings.TrimSpace(raw)
|
||||
}
|
||||
|
||||
func matchesAIPrefix(line, prefix string) bool {
|
||||
line = strings.TrimSpace(line)
|
||||
prefix = strings.TrimSpace(prefix)
|
||||
if line == "" || prefix == "" {
|
||||
return false
|
||||
}
|
||||
return line == prefix || strings.HasPrefix(line, prefix+" ")
|
||||
}
|
||||
|
||||
func normalizeCurrentLine(raw, prefix string) string {
|
||||
line := sanitizeInputLine(raw)
|
||||
prefix = strings.TrimSpace(prefix)
|
||||
if line == "" || prefix == "" {
|
||||
return line
|
||||
}
|
||||
if strings.HasPrefix(line, prefix) {
|
||||
if matchesAIPrefix(line, prefix) {
|
||||
return line
|
||||
}
|
||||
prefixIdx := strings.Index(line, prefix)
|
||||
@@ -240,7 +249,7 @@ func looksLikePromptPrefix(value string) bool {
|
||||
if value == "" {
|
||||
return false
|
||||
}
|
||||
if strings.ContainsAny(value, " \t\r\n'\"`") {
|
||||
if strings.ContainsAny(value, "'\"`") {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -1403,7 +1403,7 @@ const message = {
|
||||
'Use the selected model account to generate and fill commands. For local models like Ollama and vLLM, use a custom model account.',
|
||||
aiPrefix: 'Trigger Prefix',
|
||||
aiPrefixHelper:
|
||||
'Enter the specified prefix and press Enter to trigger AI command generation, for example: {0} help me check disk usage.',
|
||||
'Enter "prefix + space" and press Enter to trigger AI command generation, for example: {0} help me check disk usage.',
|
||||
aiRiskCommands: 'Risk Command Interception',
|
||||
aiRiskCommandsHelper:
|
||||
'Configure risky commands to intercept, one per line. When matched, generation will be blocked and filled back as comments.',
|
||||
|
||||
@@ -1442,7 +1442,7 @@ const message = {
|
||||
'Use la cuenta de modelo seleccionada para generar y rellenar comandos. Para modelos locales como Ollama y vLLM, use una cuenta de modelo personalizada.',
|
||||
aiPrefix: 'Prefijo de activación',
|
||||
aiPrefixHelper:
|
||||
'Introduzca el prefijo indicado y pulse Enter para activar la generación de comandos por IA; por ejemplo: {0} ayúdame a consultar la información del disco.',
|
||||
'Introduzca "prefijo + espacio" y pulse Enter para activar la generación de comandos por IA; por ejemplo: {0} ayúdame a consultar la información del disco.',
|
||||
aiRiskCommands: 'Intercepción de comandos de riesgo',
|
||||
aiRiskCommandsHelper:
|
||||
'Configure los comandos de riesgo que se deben interceptar, uno por línea. Si coinciden, se bloqueará la generación y se devolverán como comentarios.',
|
||||
|
||||
@@ -1413,7 +1413,7 @@ const message = {
|
||||
'選択したモデルアカウントでコマンドを生成して補完します。Ollama や vLLM などのローカルモデルはカスタムモデルアカウントを使用してください。',
|
||||
aiPrefix: 'トリガープレフィックス',
|
||||
aiPrefixHelper:
|
||||
'指定したプレフィックスを入力して Enter を押すと、AI コマンド生成がトリガーされます。例: {0} ディスク情報を確認して。',
|
||||
'「プレフィックス + スペース」を入力して Enter を押すと、AI コマンド生成がトリガーされます。例: {0} ディスク情報を確認して。',
|
||||
aiRiskCommands: '危険コマンドの遮断',
|
||||
aiRiskCommandsHelper:
|
||||
'ブロック対象の危険コマンドを設定します(1 行に 1 件)。一致した場合、生成を停止しコメントとして埋め戻します。',
|
||||
|
||||
@@ -1387,7 +1387,7 @@ const message = {
|
||||
'선택한 모델 계정으로 명령을 생성하고 채웁니다. Ollama, vLLM 같은 로컬 모델은 사용자 지정 모델 계정을 사용하세요.',
|
||||
aiPrefix: '트리거 접두사',
|
||||
aiPrefixHelper:
|
||||
'지정한 접두사를 입력하고 Enter를 누르면 AI 명령 생성이 시작됩니다. 예: {0} 디스크 정보를 조회해줘.',
|
||||
'"접두사 + 공백"을 입력하고 Enter를 누르면 AI 명령 생성이 시작됩니다. 예: {0} 디스크 정보를 조회해줘.',
|
||||
aiRiskCommands: '위험 명령 차단',
|
||||
aiRiskCommandsHelper:
|
||||
'차단할 위험 명령을 설정하세요(한 줄에 하나씩). 일치하면 생성이 차단되고 주석으로 다시 채워집니다.',
|
||||
|
||||
@@ -1427,7 +1427,7 @@ const message = {
|
||||
'Gunakan akaun model yang dipilih untuk menjana dan mengisi arahan. Untuk model tempatan seperti Ollama dan vLLM, gunakan akaun model tersuai.',
|
||||
aiPrefix: 'Awalan pencetus',
|
||||
aiPrefixHelper:
|
||||
'Masukkan awalan yang ditetapkan dan tekan Enter untuk mencetuskan penjanaan arahan AI, contohnya: {0} bantu saya semak maklumat cakera.',
|
||||
'Masukkan "awalan + ruang" dan tekan Enter untuk mencetuskan penjanaan arahan AI, contohnya: {0} bantu saya semak maklumat cakera.',
|
||||
aiRiskCommands: 'Pencegatan arahan berisiko',
|
||||
aiRiskCommandsHelper:
|
||||
'Konfigurasikan arahan berisiko yang perlu dipintas, satu bagi setiap baris. Apabila sepadan, penjanaan akan disekat dan diisi semula sebagai komen.',
|
||||
|
||||
@@ -1435,7 +1435,7 @@ const message = {
|
||||
'Use a conta de modelo selecionada para gerar e preencher comandos. Para modelos locais como Ollama e vLLM, use uma conta de modelo personalizada.',
|
||||
aiPrefix: 'Prefixo de disparo',
|
||||
aiPrefixHelper:
|
||||
'Digite o prefixo especificado e pressione Enter para acionar a geração de comandos por IA, por exemplo: {0} me ajude a consultar as informações do disco.',
|
||||
'Digite "prefixo + espaço" e pressione Enter para acionar a geração de comandos por IA, por exemplo: {0} me ajude a consultar as informações do disco.',
|
||||
aiRiskCommands: 'Intercepção de comandos de risco',
|
||||
aiRiskCommandsHelper:
|
||||
'Configure os comandos de risco que devem ser interceptados, um por linha. Quando houver correspondência, a geração será bloqueada e preenchida de volta como comentário.',
|
||||
|
||||
@@ -1420,7 +1420,7 @@ const message = {
|
||||
'Используйте выбранный модельный аккаунт для генерации и подстановки команд. Для локальных моделей, таких как Ollama и vLLM, используйте пользовательский модельный аккаунт.',
|
||||
aiPrefix: 'Префикс запуска',
|
||||
aiPrefixHelper:
|
||||
'Введите указанный префикс и нажмите Enter, чтобы запустить генерацию команд ИИ, например: {0} помоги мне показать информацию о диске.',
|
||||
'Введите "префикс + пробел" и нажмите Enter, чтобы запустить генерацию команд ИИ, например: {0} помоги мне показать информацию о диске.',
|
||||
aiRiskCommands: 'Перехват опасных команд',
|
||||
aiRiskCommandsHelper:
|
||||
'Настройте опасные команды для перехвата, по одной в каждой строке. При совпадении генерация будет заблокирована, а команда подставлена обратно в виде комментария.',
|
||||
|
||||
@@ -1424,7 +1424,7 @@ const message = {
|
||||
'Komut üretmek ve doldurmak için seçili model hesabını kullanın. Ollama ve vLLM gibi yerel modeller için özel model hesabı kullanın.',
|
||||
aiPrefix: 'Tetikleme öneki',
|
||||
aiPrefixHelper:
|
||||
'Belirtilen öneki girip Enter tuşuna bastığınızda AI komut üretimi tetiklenir; örneğin: {0} disk bilgisini sorgulamama yardım et.',
|
||||
'"Önek + boşluk" girip Enter tuşuna bastığınızda AI komut üretimi tetiklenir; örneğin: {0} disk bilgisini sorgulamama yardım et.',
|
||||
aiRiskCommands: 'Riskli komut engelleme',
|
||||
aiRiskCommandsHelper:
|
||||
'Engellenecek riskli komutlari yapılandırın, her satıra bir tane gelecek şekilde. Eşleşme olduğunda üretim durdurulur ve yorum olarak geri doldurulur.',
|
||||
|
||||
@@ -1323,7 +1323,7 @@ const message = {
|
||||
aiAssistant: 'AI 助手',
|
||||
aiAccountHelper: '使用所選模型帳號生成並回填命令。Ollama、vLLM 本地模型請使用自訂模型帳號。',
|
||||
aiPrefix: '觸發前綴',
|
||||
aiPrefixHelper: '輸入指定前綴並按下 Enter 後,將觸發 AI 指令生成,例如:{0} 幫我查詢磁碟資訊。',
|
||||
aiPrefixHelper: '輸入「前綴 + 空格」並按下 Enter 時,將觸發 AI 指令生成,例如:{0} 幫我查詢磁碟資訊。',
|
||||
aiRiskCommands: '風險命令攔截',
|
||||
aiRiskCommandsHelper: '配置需攔截的風險命令(每行一條),命中後將阻止生成並以註解回填。',
|
||||
aiSummary: '以 {0} 前綴開頭並按下 Enter 時,會觸發 AI 命令生成',
|
||||
|
||||
@@ -1332,7 +1332,7 @@ const message = {
|
||||
aiAssistant: 'AI 助手',
|
||||
aiAccountHelper: '使用所选模型账号生成并回填命令。Ollama、vLLM 本地模型请用自定义模型账号。',
|
||||
aiPrefix: '触发前缀',
|
||||
aiPrefixHelper: '输入指定前缀并按回车后,将触发 AI 命令生成,例如:{0} 帮我查询磁盘信息。',
|
||||
aiPrefixHelper: '输入“前缀 + 空格”并回车时,将触发 AI 命令生成,例如:{0} 帮我查询磁盘信息。',
|
||||
aiRiskCommands: '风险命令拦截',
|
||||
aiRiskCommandsHelper: '配置需拦截的风险命令(每行一条),命中后将阻止生成并以注释回填。',
|
||||
aiSummary: '以 {0} 前缀开头并回车时,会触发 AI 命令生成',
|
||||
|
||||
Reference in New Issue
Block a user