@@ -406,15 +406,36 @@ const allCommands = ref<CommandItem[]>([]);
406406const showCommandSuggestion = ref (false );
407407const selectedCommandIndex = ref (0 );
408408const commandSuggestionLoading = ref (false );
409+ const wakePrefixes = ref <string []>([" /" ]);
410+ const currentConfigId = ref ((props .configId as string ) || " default" );
411+
412+ /** 检查文本是否以任意一个唤醒词前缀开头 */
413+ function hasWakePrefix(text : string ): boolean {
414+ return wakePrefixes .value .some ((p ) => text .startsWith (p ));
415+ }
416+
417+ /** 去掉文本开头匹配的任意唤醒词前缀,返回剥离后的文本 */
418+ function stripWakePrefix(text : string ): string {
419+ let result = text ;
420+ for (const p of wakePrefixes .value ) {
421+ if (result .startsWith (p )) {
422+ result = result .slice (p .length );
423+ break ; // 只剥离第一个匹配的前缀
424+ }
425+ }
426+ return result ;
427+ }
409428
410429function normalizeCommandSearchText(value : string ) {
411- return value .trim (). replace ( / ^ \/ + / , " " ).toLowerCase ();
430+ return stripWakePrefix ( value .trim ()).toLowerCase ();
412431}
413432
414433/** 从所有指令中展平获取启用的普通指令和子指令 */
415434const enabledCommands = computed (() => {
416435 const result: SuggestionCommand [] = [];
417436 const seen = new Set <string >();
437+ // 使用第一个唤醒词前缀作为指令的展示前缀
438+ const displayPrefix = wakePrefixes .value [0 ] || " /" ;
418439
419440 function addCommand(cmd : CommandItem ) {
420441 if (! cmd .enabled ) return ;
@@ -423,10 +444,10 @@ const enabledCommands = computed(() => {
423444 cmd .sub_commands ?.forEach (addCommand );
424445 return ;
425446 }
426- // 统一添加 / 前缀 (子命令的 effective_command 如 "music play" 需要变成 "/music play")
427- const displayCmd = cmd .effective_command . startsWith ( " / " )
447+ // 统一添加唤醒词前缀 (子命令的 effective_command 如 "music play" 需要变成 "/music play")
448+ const displayCmd = hasWakePrefix ( cmd .effective_command )
428449 ? cmd .effective_command
429- : ` / ${cmd .effective_command }` ;
450+ : ` ${ displayPrefix } ${cmd .effective_command }` ;
430451 if (! seen .has (displayCmd )) {
431452 seen .add (displayCmd );
432453 result .push ({
@@ -438,14 +459,14 @@ const enabledCommands = computed(() => {
438459 reserved: cmd .reserved ,
439460 });
440461 }
441- // 同时加入别名(别名也需要加上 / 前缀 )
462+ // 同时加入别名(别名也需要加上唤醒词前缀 )
442463 cmd .aliases ?.forEach ((alias ) => {
443464 const aliasBase = cmd .parent_signature
444465 ? ` ${cmd .parent_signature } ${alias } `
445466 : alias ;
446- const aliasKey = aliasBase . startsWith ( " / " )
467+ const aliasKey = hasWakePrefix ( aliasBase )
447468 ? aliasBase
448- : ` / ${aliasBase }` ;
469+ : ` ${ displayPrefix } ${aliasBase }` ;
449470 if (! seen .has (aliasKey )) {
450471 seen .add (aliasKey );
451472 result .push ({
@@ -471,7 +492,7 @@ function sortSystemPluginCommandsFirst(commands: SuggestionCommand[]) {
471492/** 根据当前输入过滤候选指令 */
472493const filteredCommands = computed (() => {
473494 const text = props .prompt ;
474- if (! text || ! text . startsWith ( " / " )) return [];
495+ if (! text || ! hasWakePrefix ( text )) return [];
475496
476497 const query = normalizeCommandSearchText (text );
477498 if (! query ) return sortSystemPluginCommandsFirst (enabledCommands .value );
@@ -689,7 +710,7 @@ function handleKeyDown(e: KeyboardEvent) {
689710/** 处理输入变化,控制命令提示显示 */
690711function handleInput() {
691712 const text = props .prompt ;
692- if (text && text . startsWith ( " / " ) && ! isComposing .value ) {
713+ if (text && hasWakePrefix ( text ) && ! isComposing .value ) {
693714 showCommandSuggestion .value = filteredCommands .value .length > 0 ;
694715 selectedCommandIndex .value = 0 ;
695716 } else {
@@ -721,9 +742,19 @@ async function fetchCommands() {
721742 if (commandSuggestionLoading .value ) return ;
722743 commandSuggestionLoading .value = true ;
723744 try {
724- const res = await axios .get (" /api/commands" );
745+ const params: Record <string , string > = {};
746+ const cid = currentConfigId .value ;
747+ if (cid && cid !== " default" ) {
748+ params .config_id = cid ;
749+ }
750+ const res = await axios .get (" /api/commands" , { params });
725751 if (res .data .status === " ok" ) {
726752 allCommands .value = res .data .data .items || [];
753+ // 读取当前配置的唤醒词列表,用于指令候选的触发前缀
754+ const prefixes: string [] = res .data .data .wake_prefix ;
755+ if (prefixes && prefixes .length > 0 ) {
756+ wakePrefixes .value = prefixes ;
757+ }
727758 }
728759 } catch (err ) {
729760 // 静默失败,不影响聊天功能
@@ -826,6 +857,11 @@ function handleConfigChange(payload: {
826857 const runnerType = (payload .agentRunnerType || " " ).toLowerCase ();
827858 const isInternal = runnerType === " internal" || runnerType === " local" ;
828859 showProviderSelector .value = isInternal ;
860+ // 配置切换后重新获取指令列表和唤醒词
861+ if (payload .configId && payload .configId !== currentConfigId .value ) {
862+ currentConfigId .value = payload .configId ;
863+ fetchCommands ();
864+ }
829865}
830866
831867function getCurrentSelection() {
0 commit comments