The working directory chip showed up as soon as the server exposed any builtin tool, so a server started with just get_datetime, or a user who turned every filesystem tool off in the settings, still got a control that nothing would read. Tools now declare whether they resolve their paths and run against the working directory, next to the write permission they already publish in the /tools listing. The WebUI shows the chip and enables the /cwd command only when at least one such tool is both served and left enabled.
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { SET_WORKING_DIRECTORY_LABEL } from '$lib/constants/working-directory';
|
|
import { ChatFormCommandAction } from '$lib/enums';
|
|
import type { ChatFormCommand } from '$lib/types';
|
|
|
|
interface ChatCommandsOptions {
|
|
/** Gates `/model`. */
|
|
showModelSelector: boolean;
|
|
/** Gates `/prompt`. */
|
|
hasPrompts: () => boolean;
|
|
/** Gates `/cwd`. */
|
|
hasCwdTools: () => boolean;
|
|
}
|
|
|
|
/**
|
|
* The slash commands surfaced by the `/` command picker, in display order.
|
|
*
|
|
* Availability is supplied as predicates rather than store imports: this
|
|
* module is re-exported through the `$lib/constants` barrel, and importing
|
|
* stores at module load would create a circular dependency (the stores
|
|
* themselves import from `$lib/constants`).
|
|
*/
|
|
export function getChatCommands(options: ChatCommandsOptions): ChatFormCommand[] {
|
|
return [
|
|
{
|
|
name: 'prompt',
|
|
description: 'Insert an MCP prompt',
|
|
action: ChatFormCommandAction.PROMPT,
|
|
disabled: !options.hasPrompts()
|
|
},
|
|
{
|
|
name: 'cwd',
|
|
description: SET_WORKING_DIRECTORY_LABEL,
|
|
keywords: ['current working directory'],
|
|
action: ChatFormCommandAction.CWD,
|
|
disabled: !options.hasCwdTools()
|
|
},
|
|
{
|
|
name: 'model',
|
|
description: 'Select model',
|
|
action: ChatFormCommandAction.MODEL,
|
|
disabled: !options.showModelSelector
|
|
}
|
|
];
|
|
}
|