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:
135
desktop/src/lib/kernel-agent.ts
Normal file
135
desktop/src/lib/kernel-agent.ts
Normal file
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* kernel-agent.ts - Agent & Clone management methods for KernelClient
|
||||
*
|
||||
* Installed onto KernelClient.prototype via installAgentMethods().
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import type { KernelClient } from './kernel-client';
|
||||
import type { AgentInfo, CreateAgentRequest, CreateAgentResponse } from './kernel-types';
|
||||
|
||||
export function installAgentMethods(ClientClass: { prototype: KernelClient }): void {
|
||||
const proto = ClientClass.prototype as any;
|
||||
|
||||
// ─── Agent Management ───
|
||||
|
||||
/**
|
||||
* List all agents
|
||||
*/
|
||||
proto.listAgents = async function (this: KernelClient): Promise<AgentInfo[]> {
|
||||
return invoke<AgentInfo[]>('agent_list');
|
||||
};
|
||||
|
||||
/**
|
||||
* Get agent by ID
|
||||
*/
|
||||
proto.getAgent = async function (this: KernelClient, agentId: string): Promise<AgentInfo | null> {
|
||||
return invoke<AgentInfo | null>('agent_get', { agentId });
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new agent
|
||||
*/
|
||||
proto.createAgent = async function (this: KernelClient, request: CreateAgentRequest): Promise<CreateAgentResponse> {
|
||||
return invoke<CreateAgentResponse>('agent_create', {
|
||||
request: {
|
||||
name: request.name,
|
||||
description: request.description,
|
||||
systemPrompt: request.systemPrompt,
|
||||
provider: request.provider || 'anthropic',
|
||||
model: request.model || 'claude-sonnet-4-20250514',
|
||||
maxTokens: request.maxTokens || 4096,
|
||||
temperature: request.temperature || 0.7,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete an agent
|
||||
*/
|
||||
proto.deleteAgent = async function (this: KernelClient, agentId: string): Promise<void> {
|
||||
return invoke('agent_delete', { agentId });
|
||||
};
|
||||
|
||||
// ─── Clone/Agent Adaptation (GatewayClient interface compatibility) ───
|
||||
|
||||
/**
|
||||
* List clones — maps to listAgents() with field adaptation
|
||||
*/
|
||||
proto.listClones = async function (this: KernelClient): Promise<{ clones: any[] }> {
|
||||
const agents = await this.listAgents();
|
||||
const clones = agents.map((agent) => ({
|
||||
id: agent.id,
|
||||
name: agent.name,
|
||||
role: agent.description,
|
||||
model: agent.model,
|
||||
createdAt: new Date().toISOString(),
|
||||
}));
|
||||
return { clones };
|
||||
};
|
||||
|
||||
/**
|
||||
* Create clone — maps to createAgent()
|
||||
*/
|
||||
proto.createClone = async function (this: KernelClient, opts: {
|
||||
name: string;
|
||||
role?: string;
|
||||
model?: string;
|
||||
personality?: string;
|
||||
communicationStyle?: string;
|
||||
[key: string]: unknown;
|
||||
}): Promise<{ clone: any }> {
|
||||
const response = await this.createAgent({
|
||||
name: opts.name,
|
||||
description: opts.role,
|
||||
model: opts.model,
|
||||
});
|
||||
const clone = {
|
||||
id: response.id,
|
||||
name: response.name,
|
||||
role: opts.role,
|
||||
model: opts.model,
|
||||
personality: opts.personality,
|
||||
communicationStyle: opts.communicationStyle,
|
||||
createdAt: new Date().toISOString(),
|
||||
};
|
||||
return { clone };
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete clone — maps to deleteAgent()
|
||||
*/
|
||||
proto.deleteClone = async function (this: KernelClient, id: string): Promise<void> {
|
||||
return this.deleteAgent(id);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update clone — maps to kernel agent_update
|
||||
*/
|
||||
proto.updateClone = async function (this: KernelClient, id: string, updates: Record<string, unknown>): Promise<{ clone: unknown }> {
|
||||
await invoke('agent_update', {
|
||||
agentId: id,
|
||||
updates: {
|
||||
name: updates.name as string | undefined,
|
||||
description: updates.description as string | undefined,
|
||||
systemPrompt: updates.systemPrompt as string | undefined,
|
||||
model: updates.model as string | undefined,
|
||||
provider: updates.provider as string | undefined,
|
||||
maxTokens: updates.maxTokens as number | undefined,
|
||||
temperature: updates.temperature as number | undefined,
|
||||
},
|
||||
});
|
||||
|
||||
// Return updated clone representation
|
||||
const clone = {
|
||||
id,
|
||||
name: updates.name,
|
||||
role: updates.description || updates.role,
|
||||
model: updates.model,
|
||||
personality: updates.personality,
|
||||
communicationStyle: updates.communicationStyle,
|
||||
systemPrompt: updates.systemPrompt,
|
||||
};
|
||||
return { clone };
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user