ChatArea retry button uses setInput instead of direct sendToGateway, fix bootstrap spinner stuck for non-logged-in users, remove dead CSS (aurora-title/sidebar-open/quick-action-chips), add ai components (ReasoningBlock/StreamingText/ChatMode/ModelSelector/TaskProgress), add ClassroomPlayer + ResizableChatLayout + artifact panel Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
137 lines
3.9 KiB
TypeScript
137 lines
3.9 KiB
TypeScript
/**
|
|
* 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,
|
|
name: updates.name,
|
|
enabled: updates.enabled,
|
|
handId: updates.handId,
|
|
});
|
|
} 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;
|
|
}
|
|
};
|
|
}
|