refactor(desktop): split kernel_commands/pipeline_commands into modules, add SaaS client libs and gateway modules
Split monolithic kernel_commands.rs (2185 lines) and pipeline_commands.rs (1391 lines) into focused sub-modules under kernel_commands/ and pipeline_commands/ directories. Add gateway module (commands, config, io, runtime), health_check, and 15 new TypeScript client libraries for SaaS relay, auth, admin, telemetry, and kernel sub-systems (a2a, agent, chat, hands, skills, triggers). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
131
desktop/src/lib/kernel-triggers.ts
Normal file
131
desktop/src/lib/kernel-triggers.ts
Normal file
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* kernel-triggers.ts - Triggers API methods for KernelClient
|
||||
*
|
||||
* Installed onto KernelClient.prototype via installTriggerMethods().
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import type { KernelClient } from './kernel-client';
|
||||
|
||||
/** Trigger shape shared across trigger operations. */
|
||||
type TriggerItem = {
|
||||
id: string;
|
||||
name: string;
|
||||
handId: string;
|
||||
triggerType: string;
|
||||
enabled: boolean;
|
||||
createdAt: string;
|
||||
modifiedAt: string;
|
||||
description?: string;
|
||||
tags: string[];
|
||||
};
|
||||
|
||||
/** Trigger type definition for create/update operations. */
|
||||
type TriggerTypeSpec = {
|
||||
type: string;
|
||||
cron?: string;
|
||||
pattern?: string;
|
||||
path?: string;
|
||||
secret?: string;
|
||||
events?: string[];
|
||||
};
|
||||
|
||||
export function installTriggerMethods(ClientClass: { prototype: KernelClient }): void {
|
||||
const proto = ClientClass.prototype as any;
|
||||
|
||||
// ─── Triggers API ───
|
||||
|
||||
/**
|
||||
* List all triggers
|
||||
* Returns empty array on error for graceful degradation
|
||||
*/
|
||||
proto.listTriggers = async function (this: KernelClient): Promise<{
|
||||
triggers?: TriggerItem[]
|
||||
}> {
|
||||
try {
|
||||
const triggers = await invoke<TriggerItem[]>('trigger_list');
|
||||
return { triggers };
|
||||
} catch (error) {
|
||||
this.log('error', `[TriggersAPI] listTriggers failed: ${this.formatError(error)}`);
|
||||
return { triggers: [] };
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a single trigger by ID
|
||||
* Returns null on error for graceful degradation
|
||||
*/
|
||||
proto.getTrigger = async function (this: KernelClient, id: string): Promise<TriggerItem | null> {
|
||||
try {
|
||||
return await invoke<TriggerItem | null>('trigger_get', { id });
|
||||
} catch (error) {
|
||||
this.log('error', `[TriggersAPI] getTrigger(${id}) failed: ${this.formatError(error)}`);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new trigger
|
||||
* Returns null on error for graceful degradation
|
||||
*/
|
||||
proto.createTrigger = async function (this: KernelClient, trigger: {
|
||||
id: string;
|
||||
name: string;
|
||||
handId: string;
|
||||
triggerType: TriggerTypeSpec;
|
||||
enabled?: boolean;
|
||||
description?: string;
|
||||
tags?: string[];
|
||||
}): Promise<TriggerItem | null> {
|
||||
try {
|
||||
return await invoke<TriggerItem>('trigger_create', { request: trigger });
|
||||
} catch (error) {
|
||||
this.log('error', `[TriggersAPI] createTrigger(${trigger.id}) failed: ${this.formatError(error)}`);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Update an existing trigger
|
||||
* Throws on error as this is a mutation operation that callers need to handle
|
||||
*/
|
||||
proto.updateTrigger = async function (this: KernelClient, id: string, updates: {
|
||||
name?: string;
|
||||
enabled?: boolean;
|
||||
handId?: string;
|
||||
triggerType?: TriggerTypeSpec;
|
||||
}): Promise<TriggerItem> {
|
||||
try {
|
||||
return await invoke<TriggerItem>('trigger_update', { id, updates });
|
||||
} catch (error) {
|
||||
this.log('error', `[TriggersAPI] updateTrigger(${id}) failed: ${this.formatError(error)}`);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete a trigger
|
||||
* Throws on error as this is a destructive operation that callers need to handle
|
||||
*/
|
||||
proto.deleteTrigger = async function (this: KernelClient, id: string): Promise<void> {
|
||||
try {
|
||||
await invoke('trigger_delete', { id });
|
||||
} catch (error) {
|
||||
this.log('error', `[TriggersAPI] deleteTrigger(${id}) failed: ${this.formatError(error)}`);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Execute a trigger
|
||||
* Throws on error as callers need to know if execution failed
|
||||
*/
|
||||
proto.executeTrigger = async function (this: KernelClient, id: string, input?: Record<string, unknown>): Promise<Record<string, unknown>> {
|
||||
try {
|
||||
return await invoke<Record<string, unknown>>('trigger_execute', { id, input: input || {} });
|
||||
} catch (error) {
|
||||
this.log('error', `[TriggersAPI] executeTrigger(${id}) failed: ${this.formatError(error)}`);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user