feat: implement comprehensive CRUD APIs for agent management with type support

This commit is contained in:
Vaayne
2025-09-12 15:27:36 +08:00
parent e3f5033bc4
commit 5eaa90a7a2
4 changed files with 240 additions and 3 deletions
+10 -1
View File
@@ -1,6 +1,13 @@
import { Client, createClient } from '@libsql/client'
import { loggerService } from '@logger'
import type { AgentEntity, AgentSessionEntity, PermissionMode, SessionLogEntity, SessionStatus } from '@types'
import type {
AgentEntity,
AgentSessionEntity,
AgentType,
PermissionMode,
SessionLogEntity,
SessionStatus
} from '@types'
import { app } from 'electron'
import path from 'path'
@@ -9,6 +16,7 @@ import { AgentQueries } from './db'
const logger = loggerService.withContext('AgentService')
export interface CreateAgentRequest {
type: AgentType
name: string
description?: string
avatar?: string
@@ -201,6 +209,7 @@ export class AgentService {
const values = [
id,
serializedData.type,
serializedData.name,
serializedData.description || null,
serializedData.avatar || null,
+4 -2
View File
@@ -8,6 +8,7 @@ export const AgentQueries = {
agents: `
CREATE TABLE IF NOT EXISTS agents (
id TEXT PRIMARY KEY,
type TEXT NOT NULL DEFAULT 'custom', -- 'claudeCode', 'codex', 'custom'
name TEXT NOT NULL,
description TEXT,
avatar TEXT,
@@ -72,6 +73,7 @@ export const AgentQueries = {
// Index creation queries
createIndexes: {
agentsName: 'CREATE INDEX IF NOT EXISTS idx_agents_name ON agents(name)',
agentsType: 'CREATE INDEX IF NOT EXISTS idx_agents_type ON agents(type)',
agentsModel: 'CREATE INDEX IF NOT EXISTS idx_agents_model ON agents(model)',
agentsPlanModel: 'CREATE INDEX IF NOT EXISTS idx_agents_plan_model ON agents(plan_model)',
agentsSmallModel: 'CREATE INDEX IF NOT EXISTS idx_agents_small_model ON agents(small_model)',
@@ -99,8 +101,8 @@ export const AgentQueries = {
// Agent operations
agents: {
insert: `
INSERT INTO agents (id, name, description, avatar, instructions, model, plan_model, small_model, built_in_tools, mcps, knowledges, configuration, accessible_paths, permission_mode, max_steps, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
INSERT INTO agents (id, type, name, description, avatar, instructions, model, plan_model, small_model, built_in_tools, mcps, knowledges, configuration, accessible_paths, permission_mode, max_steps, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`,
update: `
+2
View File
@@ -6,6 +6,7 @@
export type SessionStatus = 'idle' | 'running' | 'completed' | 'failed' | 'stopped'
export type PermissionMode = 'readOnly' | 'acceptEdits' | 'bypassPermissions'
export type SessionLogRole = 'user' | 'agent' | 'system' | 'tool'
export type AgentType = 'claude-code' | 'codex' | 'qwen-cli' | 'gemini-cli' | 'custom'
export type SessionLogType =
| 'message' // User or agent message
@@ -38,6 +39,7 @@ export interface AgentConfiguration {
// Agent entity representing an autonomous agent configuration
export interface AgentEntity extends AgentConfiguration {
id: string
type: AgentType
name: string
description?: string
avatar?: string