feat(gateway): CommandRegistryService + CommandExecutorService (P8-010) (#178)
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #178.
This commit is contained in:
127
apps/gateway/src/commands/command-executor.service.ts
Normal file
127
apps/gateway/src/commands/command-executor.service.ts
Normal file
@@ -0,0 +1,127 @@
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import type { SlashCommandPayload, SlashCommandResultPayload } from '@mosaic/types';
|
||||
import { AgentService } from '../agent/agent.service.js';
|
||||
import { CommandRegistryService } from './command-registry.service.js';
|
||||
|
||||
@Injectable()
|
||||
export class CommandExecutorService {
|
||||
private readonly logger = new Logger(CommandExecutorService.name);
|
||||
|
||||
constructor(
|
||||
@Inject(CommandRegistryService) private readonly registry: CommandRegistryService,
|
||||
@Inject(AgentService) private readonly agentService: AgentService,
|
||||
) {}
|
||||
|
||||
async execute(payload: SlashCommandPayload, _userId: string): Promise<SlashCommandResultPayload> {
|
||||
const { command, args, conversationId } = payload;
|
||||
|
||||
const def = this.registry.getManifest().commands.find((c) => c.name === command);
|
||||
if (!def) {
|
||||
return {
|
||||
command,
|
||||
conversationId,
|
||||
success: false,
|
||||
message: `Unknown command: /${command}`,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
switch (command) {
|
||||
case 'model':
|
||||
return await this.handleModel(args ?? null, conversationId);
|
||||
case 'thinking':
|
||||
return await this.handleThinking(args ?? null, conversationId);
|
||||
case 'new':
|
||||
return {
|
||||
command,
|
||||
conversationId,
|
||||
success: true,
|
||||
message: 'Start a new conversation by selecting New Conversation.',
|
||||
};
|
||||
case 'clear':
|
||||
return {
|
||||
command,
|
||||
conversationId,
|
||||
success: true,
|
||||
message: 'Conversation display cleared.',
|
||||
};
|
||||
case 'compact':
|
||||
return {
|
||||
command,
|
||||
conversationId,
|
||||
success: true,
|
||||
message: 'Context compaction requested.',
|
||||
};
|
||||
case 'retry':
|
||||
return {
|
||||
command,
|
||||
conversationId,
|
||||
success: true,
|
||||
message: 'Retry last message requested.',
|
||||
};
|
||||
default:
|
||||
return {
|
||||
command,
|
||||
conversationId,
|
||||
success: false,
|
||||
message: `Command /${command} is not yet implemented.`,
|
||||
};
|
||||
}
|
||||
} catch (err) {
|
||||
this.logger.error(`Command /${command} failed: ${err}`);
|
||||
return { command, conversationId, success: false, message: String(err) };
|
||||
}
|
||||
}
|
||||
|
||||
private async handleModel(
|
||||
args: string | null,
|
||||
conversationId: string,
|
||||
): Promise<SlashCommandResultPayload> {
|
||||
if (!args) {
|
||||
return {
|
||||
command: 'model',
|
||||
conversationId,
|
||||
success: true,
|
||||
message: 'Usage: /model <model-name>',
|
||||
};
|
||||
}
|
||||
// Update agent session model if session is active
|
||||
// For now, acknowledge the request — full wiring done in P8-012
|
||||
const session = this.agentService.getSession(conversationId);
|
||||
if (!session) {
|
||||
return {
|
||||
command: 'model',
|
||||
conversationId,
|
||||
success: true,
|
||||
message: `Model switch to "${args}" requested. No active session for this conversation.`,
|
||||
};
|
||||
}
|
||||
return {
|
||||
command: 'model',
|
||||
conversationId,
|
||||
success: true,
|
||||
message: `Model switch to "${args}" requested.`,
|
||||
};
|
||||
}
|
||||
|
||||
private async handleThinking(
|
||||
args: string | null,
|
||||
conversationId: string,
|
||||
): Promise<SlashCommandResultPayload> {
|
||||
const level = args?.toLowerCase();
|
||||
if (!level || !['none', 'low', 'medium', 'high', 'auto'].includes(level)) {
|
||||
return {
|
||||
command: 'thinking',
|
||||
conversationId,
|
||||
success: true,
|
||||
message: 'Usage: /thinking <none|low|medium|high|auto>',
|
||||
};
|
||||
}
|
||||
return {
|
||||
command: 'thinking',
|
||||
conversationId,
|
||||
success: true,
|
||||
message: `Thinking level set to "${level}".`,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user