/**
* Trigger Action Tool Handler
* Triggers an action on Komodo
*/
import type { KomodoClient } from '../../core/KomodoClient';
import { Logger } from '../../utils/logger';
export interface ActionOptions {
async?: boolean;
retryOnFailure?: boolean;
}
export interface TriggerActionRequest {
id: string;
payload?: Record<string, any>;
options?: ActionOptions;
}
export interface TriggerActionResponse {
success: boolean;
actionId: string;
executionId?: string;
type: 'webhook' | 'script' | 'notification' | 'custom';
status: 'queued' | 'executing' | 'completed' | 'failed';
message: string;
startedAt?: string;
completedAt?: string;
duration?: number;
result?: {
statusCode?: number;
response?: any;
output?: string;
error?: string;
};
}
/**
* Trigger an action
*/
export async function triggerAction(
client: KomodoClient,
request: TriggerActionRequest
): Promise<TriggerActionResponse> {
const logger = Logger.getInstance();
try {
logger.info('Triggering action', {
actionId: request.id,
hasPayload: !!request.payload
});
const payload = {
payload: request.payload,
...request.options
};
const response = await client.post<TriggerActionResponse>(
`/execute/action/${request.id}`,
payload
);
logger.info('Action execution initiated', {
actionId: request.id,
executionId: response.executionId,
type: response.type,
status: response.status
});
return response;
} catch (error) {
logger.error('Failed to trigger action', {
actionId: request.id,
error: error instanceof Error ? error.message : String(error)
});
throw error;
}
}