feat(cli): command architecture — agents, missions, gateway-aware prdy (#158)
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #158.
This commit is contained in:
58
packages/brain/src/agents.ts
Normal file
58
packages/brain/src/agents.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { eq, or, type Db, agents } from '@mosaic/db';
|
||||
|
||||
export type Agent = typeof agents.$inferSelect;
|
||||
export type NewAgent = typeof agents.$inferInsert;
|
||||
|
||||
export function createAgentsRepo(db: Db) {
|
||||
return {
|
||||
async findAll(): Promise<Agent[]> {
|
||||
return db.select().from(agents);
|
||||
},
|
||||
|
||||
async findById(id: string): Promise<Agent | undefined> {
|
||||
const rows = await db.select().from(agents).where(eq(agents.id, id));
|
||||
return rows[0];
|
||||
},
|
||||
|
||||
async findByName(name: string): Promise<Agent | undefined> {
|
||||
const rows = await db.select().from(agents).where(eq(agents.name, name));
|
||||
return rows[0];
|
||||
},
|
||||
|
||||
async findByProject(projectId: string): Promise<Agent[]> {
|
||||
return db.select().from(agents).where(eq(agents.projectId, projectId));
|
||||
},
|
||||
|
||||
async findSystem(): Promise<Agent[]> {
|
||||
return db.select().from(agents).where(eq(agents.isSystem, true));
|
||||
},
|
||||
|
||||
async findAccessible(ownerId: string): Promise<Agent[]> {
|
||||
return db
|
||||
.select()
|
||||
.from(agents)
|
||||
.where(or(eq(agents.ownerId, ownerId), eq(agents.isSystem, true)));
|
||||
},
|
||||
|
||||
async create(data: NewAgent): Promise<Agent> {
|
||||
const rows = await db.insert(agents).values(data).returning();
|
||||
return rows[0]!;
|
||||
},
|
||||
|
||||
async update(id: string, data: Partial<NewAgent>): Promise<Agent | undefined> {
|
||||
const rows = await db
|
||||
.update(agents)
|
||||
.set({ ...data, updatedAt: new Date() })
|
||||
.where(eq(agents.id, id))
|
||||
.returning();
|
||||
return rows[0];
|
||||
},
|
||||
|
||||
async remove(id: string): Promise<boolean> {
|
||||
const rows = await db.delete(agents).where(eq(agents.id, id)).returning();
|
||||
return rows.length > 0;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export type AgentsRepo = ReturnType<typeof createAgentsRepo>;
|
||||
@@ -4,6 +4,7 @@ import { createMissionsRepo, type MissionsRepo } from './missions.js';
|
||||
import { createMissionTasksRepo, type MissionTasksRepo } from './mission-tasks.js';
|
||||
import { createTasksRepo, type TasksRepo } from './tasks.js';
|
||||
import { createConversationsRepo, type ConversationsRepo } from './conversations.js';
|
||||
import { createAgentsRepo, type AgentsRepo } from './agents.js';
|
||||
|
||||
export interface Brain {
|
||||
projects: ProjectsRepo;
|
||||
@@ -11,6 +12,7 @@ export interface Brain {
|
||||
missionTasks: MissionTasksRepo;
|
||||
tasks: TasksRepo;
|
||||
conversations: ConversationsRepo;
|
||||
agents: AgentsRepo;
|
||||
}
|
||||
|
||||
export function createBrain(db: Db): Brain {
|
||||
@@ -20,5 +22,6 @@ export function createBrain(db: Db): Brain {
|
||||
missionTasks: createMissionTasksRepo(db),
|
||||
tasks: createTasksRepo(db),
|
||||
conversations: createConversationsRepo(db),
|
||||
agents: createAgentsRepo(db),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -26,3 +26,9 @@ export {
|
||||
type Message,
|
||||
type NewMessage,
|
||||
} from './conversations.js';
|
||||
export {
|
||||
createAgentsRepo,
|
||||
type AgentsRepo,
|
||||
type Agent as AgentConfig,
|
||||
type NewAgent as NewAgentConfig,
|
||||
} from './agents.js';
|
||||
|
||||
Reference in New Issue
Block a user