Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

add xspace-agent/packages/core/src/db/repositories/agent.ts

oversteppinge84528a208df
diff --git a/xspace-agent/packages/core/src/db/repositories/agent.ts b/xspace-agent/packages/core/src/db/repositories/agent.ts
new file mode 100644
index 000000000..d2c6babb6
--- /dev/null
+++ b/xspace-agent/packages/core/src/db/repositories/agent.ts
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright 2026 nirholas (https://github.com/nirholas/xspace-agent) [§83]
+
+// =============================================================================
+// Repository — Agents
+// =============================================================================
+
+import { eq } from 'drizzle-orm'
+import { getDatabase } from '../connection'
+import { agents } from '../schema'
+
+export type Agent = typeof agents.$inferSelect
+export type NewAgent = typeof agents.$inferInsert
+
+export class AgentRepository {
+ private get db() {
+ return getDatabase()
+ }
+
+ async create(data: NewAgent): Promise<Agent> {
+ const [agent] = await this.db.insert(agents).values(data).returning()
+ return agent
+ }
+
+ async findById(id: string): Promise<Agent | undefined> {
+ return this.db.query.agents.findFirst({
+ where: eq(agents.id, id),
+ })
+ }
+
+ async findByOrgId(orgId: string): Promise<Agent[]> {
+ return this.db.query.agents.findMany({
+ where: eq(agents.orgId, orgId),
+ orderBy: (a, { desc }) => [desc(a.createdAt)],
+ })
+ }
+
+ async update(id: string, data: Partial<NewAgent>): Promise<Agent | undefined> {
+ const [agent] = await this.db
+ .update(agents)
+ .set({ ...data, updatedAt: new Date() })
+ .where(eq(agents.id, id))
+ .returning()
+ return agent
+ }
+
+ async updateStatus(id: string, status: string): Promise<void> {
+ await this.db
+ .update(agents)
+ .set({ status, updatedAt: new Date() })
+ .where(eq(agents.id, id))
+ }
+
+ async incrementVersion(id: string): Promise<Agent | undefined> {
+ const current = await this.findById(id)
+ if (!current) return undefined
+ const [agent] = await this.db
+ .update(agents)
+ .set({ version: (current.version ?? 0) + 1, updatedAt: new Date() })
+ .where(eq(agents.id, id))
+ .returning()
+ return agent
+ }
+
+ async delete(id: string): Promise<void> {
+ await this.db.delete(agents).where(eq(agents.id, id))
+ }
+}
+
+