fix(slash-commands): route /clean et /help en commandes natives IdeA avant dispatch plugin (#183)
This commit is contained in:
@ -401,6 +401,12 @@ function isSlashCommandAvailable(command: SlashCommand): boolean {
|
||||
return command.availability.status === "available";
|
||||
}
|
||||
|
||||
function formatSlashCommandHelp(commands: SlashCommand[]): string {
|
||||
return commands
|
||||
.map((command) => `${command.name} - ${command.shortDescription}`)
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
function foldChunk(turns: ChatTurn[], raw: unknown): ChatTurn[] {
|
||||
if (!isReplyRecord(raw)) {
|
||||
return [...turns, { role: "unknown", text: unknownChunkLabel(raw) }];
|
||||
@ -792,42 +798,23 @@ export function CustomAgentChatView({
|
||||
[supported, draft, attachments.length, busy, opening],
|
||||
);
|
||||
|
||||
async function openProfileCommandFlow() {
|
||||
if (!agent.executeSlashCommand) {
|
||||
setError("Commande /profile indisponible dans ce runtime.");
|
||||
return;
|
||||
}
|
||||
setError(null);
|
||||
try {
|
||||
const sid =
|
||||
currentSession ??
|
||||
(await recoverStructuredSession({
|
||||
applyScrollback: false,
|
||||
retryAttachNotFound: true,
|
||||
}));
|
||||
const result = await agent.executeSlashCommand("/profile", { sessionId: sid });
|
||||
if (result.effect.kind !== "profileSwitch") {
|
||||
throw new Error("La commande /profile n'a pas renvoyé le flow profil.");
|
||||
}
|
||||
const availableProfiles = (await profileGateway.listProfiles()).filter(
|
||||
(candidate) => Boolean(candidate.structuredAdapter),
|
||||
);
|
||||
if (availableProfiles.length === 0) {
|
||||
throw new Error("Aucun profil compatible avec la CLI custom n'est configuré.");
|
||||
}
|
||||
setDraft("");
|
||||
setProfileDialog({
|
||||
profiles: availableProfiles,
|
||||
selectedProfileId:
|
||||
availableProfiles.find((candidate) => candidate.id !== profile.id)?.id ??
|
||||
availableProfiles[0].id,
|
||||
confirmedReset: false,
|
||||
busy: false,
|
||||
error: null,
|
||||
});
|
||||
} catch (e) {
|
||||
setError(describe(e));
|
||||
async function openProfileDialog() {
|
||||
const availableProfiles = (await profileGateway.listProfiles()).filter((candidate) =>
|
||||
Boolean(candidate.structuredAdapter),
|
||||
);
|
||||
if (availableProfiles.length === 0) {
|
||||
throw new Error("Aucun profil compatible avec la CLI custom n'est configuré.");
|
||||
}
|
||||
setDraft("");
|
||||
setProfileDialog({
|
||||
profiles: availableProfiles,
|
||||
selectedProfileId:
|
||||
availableProfiles.find((candidate) => candidate.id !== profile.id)?.id ??
|
||||
availableProfiles[0].id,
|
||||
confirmedReset: false,
|
||||
busy: false,
|
||||
error: null,
|
||||
});
|
||||
}
|
||||
|
||||
async function confirmProfileCommandChange() {
|
||||
@ -904,22 +891,38 @@ export function CustomAgentChatView({
|
||||
}));
|
||||
const result = await agent.executeSlashCommand(invocation.name, {
|
||||
sessionId: sid,
|
||||
arguments: invocation.arguments,
|
||||
...(invocation.arguments.length > 0
|
||||
? { arguments: invocation.arguments }
|
||||
: {}),
|
||||
});
|
||||
if (result.effect.kind !== "pluginCallback") {
|
||||
throw new Error(
|
||||
`La commande ${invocation.name} n'a pas renvoyé d'effet pluginCallback.`,
|
||||
);
|
||||
if (result.effect.kind === "help") {
|
||||
const helpText = formatSlashCommandHelp(result.effect.commands);
|
||||
setTurns((prev) => [
|
||||
...prev,
|
||||
{ role: "agent", text: helpText },
|
||||
]);
|
||||
return;
|
||||
}
|
||||
if (result.effect.kind === "cleanConversation") {
|
||||
setTurns([]);
|
||||
return;
|
||||
}
|
||||
if (result.effect.kind === "profileSwitch") {
|
||||
await openProfileDialog();
|
||||
return;
|
||||
}
|
||||
if (result.effect.kind === "pluginCallback") {
|
||||
await pluginRuntime.registry.runCommandStrict(
|
||||
result.effect.pluginId,
|
||||
result.effect.commandId,
|
||||
...result.effect.arguments,
|
||||
);
|
||||
setTurns((prev) => [
|
||||
...prev,
|
||||
{ role: "tool", label: `Commande plugin ${result.command.name} exécutée.` },
|
||||
]);
|
||||
return;
|
||||
}
|
||||
await pluginRuntime.registry.runCommandStrict(
|
||||
result.effect.pluginId,
|
||||
result.effect.commandId,
|
||||
...result.effect.arguments,
|
||||
);
|
||||
setTurns((prev) => [
|
||||
...prev,
|
||||
{ role: "tool", label: `Commande plugin ${result.command.name} exécutée.` },
|
||||
]);
|
||||
} catch (e) {
|
||||
const message = `Commande ${invocation.name} échouée: ${describe(e)}`;
|
||||
setError(message);
|
||||
@ -971,10 +974,6 @@ export function CustomAgentChatView({
|
||||
async function send() {
|
||||
const text = draft.trim();
|
||||
if (!canSend || !agent.sendAgentChat) return;
|
||||
if (text === "/profile") {
|
||||
await openProfileCommandFlow();
|
||||
return;
|
||||
}
|
||||
const slashInvocation = slashCommandInvocation(text);
|
||||
if (slashInvocation) {
|
||||
await executeSlashCommand(slashInvocation);
|
||||
|
||||
Reference in New Issue
Block a user