2026-01-08 16:02:44 -05:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import type { SlashCommand, CommandContext } from './types.js';
|
|
|
|
|
import { CommandKind } from './types.js';
|
|
|
|
|
import { MessageType, type HistoryItemAgentsList } from '../types.js';
|
|
|
|
|
|
2026-01-09 09:33:59 -08:00
|
|
|
const agentsListCommand: SlashCommand = {
|
|
|
|
|
name: 'list',
|
2026-01-08 16:02:44 -05:00
|
|
|
description: 'List available local and remote agents',
|
|
|
|
|
kind: CommandKind.BUILT_IN,
|
|
|
|
|
autoExecute: true,
|
|
|
|
|
action: async (context: CommandContext) => {
|
|
|
|
|
const { config } = context.services;
|
|
|
|
|
if (!config) {
|
|
|
|
|
return {
|
|
|
|
|
type: 'message',
|
|
|
|
|
messageType: 'error',
|
|
|
|
|
content: 'Config not loaded.',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const agentRegistry = config.getAgentRegistry();
|
|
|
|
|
if (!agentRegistry) {
|
|
|
|
|
return {
|
|
|
|
|
type: 'message',
|
|
|
|
|
messageType: 'error',
|
|
|
|
|
content: 'Agent registry not found.',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const agents = agentRegistry.getAllDefinitions().map((def) => ({
|
|
|
|
|
name: def.name,
|
|
|
|
|
displayName: def.displayName,
|
|
|
|
|
description: def.description,
|
|
|
|
|
kind: def.kind,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const agentsListItem: HistoryItemAgentsList = {
|
|
|
|
|
type: MessageType.AGENTS_LIST,
|
|
|
|
|
agents,
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-13 14:15:04 -05:00
|
|
|
context.ui.addItem(agentsListItem);
|
2026-01-08 16:02:44 -05:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
},
|
|
|
|
|
};
|
2026-01-09 09:33:59 -08:00
|
|
|
|
|
|
|
|
const agentsRefreshCommand: SlashCommand = {
|
|
|
|
|
name: 'refresh',
|
|
|
|
|
description: 'Reload the agent registry',
|
|
|
|
|
kind: CommandKind.BUILT_IN,
|
|
|
|
|
action: async (context: CommandContext) => {
|
|
|
|
|
const { config } = context.services;
|
|
|
|
|
const agentRegistry = config?.getAgentRegistry();
|
|
|
|
|
if (!agentRegistry) {
|
|
|
|
|
return {
|
|
|
|
|
type: 'message',
|
|
|
|
|
messageType: 'error',
|
|
|
|
|
content: 'Agent registry not found.',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-13 14:15:04 -05:00
|
|
|
context.ui.addItem({
|
|
|
|
|
type: MessageType.INFO,
|
|
|
|
|
text: 'Refreshing agent registry...',
|
|
|
|
|
});
|
2026-01-12 16:20:28 -08:00
|
|
|
|
2026-01-09 09:33:59 -08:00
|
|
|
await agentRegistry.reload();
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
type: 'message',
|
|
|
|
|
messageType: 'info',
|
|
|
|
|
content: 'Agents refreshed successfully.',
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const agentsCommand: SlashCommand = {
|
|
|
|
|
name: 'agents',
|
|
|
|
|
description: 'Manage agents',
|
|
|
|
|
kind: CommandKind.BUILT_IN,
|
|
|
|
|
subCommands: [agentsListCommand, agentsRefreshCommand],
|
|
|
|
|
action: async (context: CommandContext, args) =>
|
|
|
|
|
// Default to list if no subcommand is provided
|
|
|
|
|
agentsListCommand.action!(context, args),
|
|
|
|
|
};
|