mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-08-03 21:34:40 +00:00
* feat(web-shell): support custom slash command actions * fix(web-shell): apply slash handlers consistently --------- Co-authored-by: 钉萁 <dingqi.jww@alibaba-inc.com> Co-authored-by: 易良 <1204183885@qq.com>
25 lines
695 B
TypeScript
25 lines
695 B
TypeScript
import type { WebShellSlashCommandHandler } from '../App';
|
|
|
|
export const SLASH_COMMAND_PATTERN = /^\/([\w-]+)(?=\s|$)/;
|
|
|
|
export function invokeSlashCommandHandler(
|
|
input: string,
|
|
handler: WebShellSlashCommandHandler | undefined,
|
|
reportError: (error: unknown, fallback: string) => void,
|
|
): boolean {
|
|
if (!handler) return false;
|
|
const match = input.match(SLASH_COMMAND_PATTERN);
|
|
if (!match) return false;
|
|
try {
|
|
return (
|
|
handler({
|
|
command: match[1].toLowerCase(),
|
|
args: input.slice(match[0].length).trim(),
|
|
input,
|
|
}) === true
|
|
);
|
|
} catch (error: unknown) {
|
|
reportError(error, 'onSlashCommand callback failed');
|
|
return false;
|
|
}
|
|
}
|