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/webhook-delivery.ts

overstepping15b39aa9c905
diff --git a/xspace-agent/packages/core/src/db/repositories/webhook-delivery.ts b/xspace-agent/packages/core/src/db/repositories/webhook-delivery.ts
new file mode 100644
index 000000000..adc289f7b
--- /dev/null
+++ b/xspace-agent/packages/core/src/db/repositories/webhook-delivery.ts
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright 2026 nirholas (https://github.com/nirholas/xspace-agent) [§69]
+
+// =============================================================================
+// Repository — Webhook Deliveries
+// =============================================================================
+
+import { eq, and, lte, desc } from 'drizzle-orm'
+import { getDatabase } from '../connection'
+import { webhookDeliveries } from '../schema'
+
+export type WebhookDelivery = typeof webhookDeliveries.$inferSelect
+export type NewWebhookDelivery = typeof webhookDeliveries.$inferInsert
+
+export class WebhookDeliveryRepository {
+ private get db() {
+ return getDatabase()
+ }
+
+ async create(data: NewWebhookDelivery): Promise<WebhookDelivery> {
+ const [delivery] = await this.db.insert(webhookDeliveries).values(data).returning()
+ return delivery
+ }
+
+ async findById(id: string): Promise<WebhookDelivery | undefined> {
+ return this.db.query.webhookDeliveries.findFirst({
+ where: eq(webhookDeliveries.id, id),
+ })
+ }
+
+ async findByWebhookId(webhookId: string, options?: { limit?: number }): Promise<WebhookDelivery[]> {
+ return this.db.query.webhookDeliveries.findMany({
+ where: eq(webhookDeliveries.webhookId, webhookId),
+ orderBy: [desc(webhookDeliveries.createdAt)],
+ limit: options?.limit ?? 50,
+ })
+ }
+
+ /** Find deliveries that are due for retry (status = 'failed', nextRetryAt <= now). */
+ async findRetryable(limit = 100): Promise<WebhookDelivery[]> {
+ const now = new Date()
+ return this.db.query.webhookDeliveries.findMany({
+ where: and(
+ eq(webhookDeliveries.status, 'failed'),
+ lte(webhookDeliveries.nextRetryAt, now),
+ ),
+ orderBy: [webhookDeliveries.nextRetryAt],
+ limit,
+ })
+ }
+
+ async updateStatus(
+ id: string,
+ data: {
+ status: string
+ attempts?: number
+ lastAttemptAt?: Date
+ nextRetryAt?: Date | null
+ responseStatus?: number
+ responseBody?: string
+ durationMs?: number
+ },
+ ): Promise<WebhookDelivery | undefined> {
+ const [updated] = await this.db
+ .update(webhookDeliveries)
+ .set({
+ status: data.status,
+ ...(data.attempts !== undefined && { attempts: data.attempts }),
+ ...(data.lastAttemptAt && { lastAttemptAt: data.lastAttemptAt }),
+ ...(data.nextRetryAt !== undefined && { nextRetryAt: data.nextRetryAt }),
+ ...(data.responseStatus !== undefined && { responseStatus: data.responseStatus }),
+ ...(data.responseBody !== undefined && { responseBody: data.responseBody }),
+ ...(data.durationMs !== undefined && { durationMs: data.durationMs }),
+ })
+ .where(eq(webhookDeliveries.id, id))
+ .returning()
+ return updated
+ }
+
+ async delete(id: string): Promise<void> {
+ await this.db.delete(webhookDeliveries).where(eq(webhookDeliveries.id, id))
+ }
+}
+
+