agent-relay 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.trajectories/active/traj_3yx9dy148mge.json +42 -0
- package/.trajectories/completed/2026-01/traj_1g7yx6qtg4ai.json +49 -0
- package/.trajectories/completed/2026-01/traj_1g7yx6qtg4ai.md +31 -0
- package/.trajectories/completed/2026-01/traj_4qwd4zmhfwp4.json +49 -0
- package/.trajectories/completed/2026-01/traj_4qwd4zmhfwp4.md +31 -0
- package/.trajectories/completed/2026-01/traj_6unwwmgyj5sq.json +109 -0
- package/.trajectories/completed/2026-01/traj_a0tqx8biw9c4.json +49 -0
- package/.trajectories/completed/2026-01/traj_a0tqx8biw9c4.md +31 -0
- package/.trajectories/completed/2026-01/traj_ax8uungxz2qh.json +66 -0
- package/.trajectories/completed/2026-01/traj_ax8uungxz2qh.md +36 -0
- package/.trajectories/completed/2026-01/traj_c9izbh2snpzf.json +49 -0
- package/.trajectories/completed/2026-01/traj_c9izbh2snpzf.md +31 -0
- package/.trajectories/completed/2026-01/traj_cpn70dw066nt.json +65 -0
- package/.trajectories/completed/2026-01/traj_cpn70dw066nt.md +37 -0
- package/.trajectories/completed/2026-01/traj_erglv2f8t9eh.json +36 -0
- package/.trajectories/completed/2026-01/traj_erglv2f8t9eh.md +21 -0
- package/.trajectories/completed/2026-01/traj_he75f24d1xfm.json +101 -0
- package/.trajectories/completed/2026-01/traj_he75f24d1xfm.md +52 -0
- package/.trajectories/completed/2026-01/traj_lgtodco7dp1n.json +61 -0
- package/.trajectories/completed/2026-01/traj_lgtodco7dp1n.md +36 -0
- package/.trajectories/completed/2026-01/traj_oszg9flv74pk.json +73 -0
- package/.trajectories/completed/2026-01/traj_oszg9flv74pk.md +41 -0
- package/.trajectories/completed/2026-01/traj_pulomd3y8cvj.json +77 -0
- package/.trajectories/completed/2026-01/traj_pulomd3y8cvj.md +42 -0
- package/.trajectories/completed/2026-01/traj_rsavt0jipi3c.json +109 -0
- package/.trajectories/completed/2026-01/traj_rsavt0jipi3c.md +56 -0
- package/.trajectories/completed/2026-01/traj_x721m1j9rzup.json +113 -0
- package/.trajectories/completed/2026-01/traj_x721m1j9rzup.md +57 -0
- package/.trajectories/completed/2026-01/traj_xjqvmep5ed3h.json +61 -0
- package/.trajectories/completed/2026-01/traj_xjqvmep5ed3h.md +36 -0
- package/.trajectories/completed/2026-01/traj_y7n6hfbf7dmg.json +49 -0
- package/.trajectories/completed/2026-01/traj_y7n6hfbf7dmg.md +31 -0
- package/.trajectories/completed/2026-01/traj_yvfkwnkdiso2.json +49 -0
- package/.trajectories/completed/2026-01/traj_yvfkwnkdiso2.md +31 -0
- package/.trajectories/index.json +140 -1
- package/TRAIL_GIT_AUTH_FIX.md +113 -0
- package/deploy/workspace/codex.config.toml +1 -1
- package/deploy/workspace/entrypoint.sh +20 -79
- package/deploy/workspace/gh-relay +156 -0
- package/deploy/workspace/git-credential-relay +5 -1
- package/dist/bridge/multi-project-client.js +13 -10
- package/dist/bridge/spawner.d.ts +2 -0
- package/dist/bridge/spawner.js +19 -1
- package/dist/bridge/types.d.ts +2 -0
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +115 -69
- package/dist/cloud/api/admin.js +16 -3
- package/dist/cloud/api/codex-auth-helper.js +28 -8
- package/dist/cloud/api/consensus.d.ts +13 -0
- package/dist/cloud/api/consensus.js +259 -0
- package/dist/cloud/api/daemons.js +205 -1
- package/dist/cloud/api/git.js +37 -7
- package/dist/cloud/api/onboarding.js +4 -1
- package/dist/cloud/api/provider-env.d.ts +5 -0
- package/dist/cloud/api/provider-env.js +27 -0
- package/dist/cloud/api/providers.js +2 -0
- package/dist/cloud/api/test-helpers.js +130 -0
- package/dist/cloud/api/workspaces.js +38 -3
- package/dist/cloud/db/bulk-ingest.d.ts +88 -0
- package/dist/cloud/db/bulk-ingest.js +268 -0
- package/dist/cloud/db/drizzle.d.ts +33 -0
- package/dist/cloud/db/drizzle.js +174 -2
- package/dist/cloud/db/index.d.ts +24 -5
- package/dist/cloud/db/index.js +19 -4
- package/dist/cloud/db/schema.d.ts +397 -3
- package/dist/cloud/db/schema.js +75 -1
- package/dist/cloud/provisioner/index.d.ts +8 -0
- package/dist/cloud/provisioner/index.js +256 -50
- package/dist/cloud/server.js +47 -3
- package/dist/cloud/services/index.d.ts +1 -0
- package/dist/cloud/services/index.js +2 -0
- package/dist/cloud/services/nango.d.ts +3 -4
- package/dist/cloud/services/nango.js +11 -33
- package/dist/cloud/services/workspace-keepalive.d.ts +76 -0
- package/dist/cloud/services/workspace-keepalive.js +234 -0
- package/dist/config/relay-config.d.ts +23 -0
- package/dist/config/relay-config.js +23 -0
- package/dist/daemon/agent-manager.d.ts +20 -1
- package/dist/daemon/agent-manager.js +47 -0
- package/dist/daemon/agent-registry.js +4 -4
- package/dist/daemon/agent-signing.d.ts +158 -0
- package/dist/daemon/agent-signing.js +523 -0
- package/dist/daemon/api.js +18 -1
- package/dist/daemon/cli-auth.d.ts +4 -1
- package/dist/daemon/cli-auth.js +55 -11
- package/dist/daemon/cloud-sync.d.ts +47 -1
- package/dist/daemon/cloud-sync.js +152 -3
- package/dist/daemon/connection.d.ts +28 -0
- package/dist/daemon/connection.js +98 -15
- package/dist/daemon/consensus-integration.d.ts +167 -0
- package/dist/daemon/consensus-integration.js +371 -0
- package/dist/daemon/consensus.d.ts +271 -0
- package/dist/daemon/consensus.js +632 -0
- package/dist/daemon/delivery-tracker.d.ts +34 -0
- package/dist/daemon/delivery-tracker.js +104 -0
- package/dist/daemon/enhanced-features.d.ts +118 -0
- package/dist/daemon/enhanced-features.js +178 -0
- package/dist/daemon/index.d.ts +4 -0
- package/dist/daemon/index.js +5 -0
- package/dist/daemon/rate-limiter.d.ts +68 -0
- package/dist/daemon/rate-limiter.js +130 -0
- package/dist/daemon/router.d.ts +18 -11
- package/dist/daemon/router.js +55 -111
- package/dist/daemon/server.d.ts +13 -1
- package/dist/daemon/server.js +71 -9
- package/dist/daemon/sync-queue.d.ts +116 -0
- package/dist/daemon/sync-queue.js +361 -0
- package/dist/health-worker-manager.d.ts +62 -0
- package/dist/health-worker-manager.js +144 -0
- package/dist/health-worker.d.ts +9 -0
- package/dist/health-worker.js +79 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -1
- package/dist/memory/context-compaction.d.ts +156 -0
- package/dist/memory/context-compaction.js +453 -0
- package/dist/memory/index.d.ts +1 -0
- package/dist/memory/index.js +1 -0
- package/dist/protocol/channels.js +4 -4
- package/dist/protocol/framing.d.ts +72 -10
- package/dist/protocol/framing.js +194 -25
- package/dist/storage/adapter.d.ts +8 -1
- package/dist/storage/adapter.js +11 -0
- package/dist/storage/batched-sqlite-adapter.d.ts +71 -0
- package/dist/storage/batched-sqlite-adapter.js +183 -0
- package/dist/storage/dead-letter-queue.d.ts +196 -0
- package/dist/storage/dead-letter-queue.js +427 -0
- package/dist/storage/dlq-adapter.d.ts +195 -0
- package/dist/storage/dlq-adapter.js +664 -0
- package/dist/trajectory/config.d.ts +32 -14
- package/dist/trajectory/config.js +38 -16
- package/dist/trajectory/integration.js +217 -64
- package/dist/utils/git-remote.d.ts +47 -0
- package/dist/utils/git-remote.js +125 -0
- package/dist/utils/id-generator.d.ts +35 -0
- package/dist/utils/id-generator.js +60 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/precompiled-patterns.d.ts +110 -0
- package/dist/utils/precompiled-patterns.js +322 -0
- package/dist/wrapper/auth-detection.js +1 -1
- package/dist/wrapper/base-wrapper.d.ts +36 -0
- package/dist/wrapper/base-wrapper.js +48 -2
- package/dist/wrapper/client.d.ts +14 -4
- package/dist/wrapper/client.js +84 -31
- package/dist/wrapper/idle-detector.d.ts +102 -0
- package/dist/wrapper/idle-detector.js +279 -0
- package/dist/wrapper/parser.d.ts +4 -0
- package/dist/wrapper/parser.js +19 -1
- package/dist/wrapper/pty-wrapper.d.ts +7 -1
- package/dist/wrapper/pty-wrapper.js +51 -27
- package/dist/wrapper/tmux-wrapper.d.ts +12 -1
- package/dist/wrapper/tmux-wrapper.js +65 -17
- package/package.json +5 -5
- package/scripts/run-migrations.js +43 -0
- package/scripts/verify-schema.js +134 -0
- package/tests/benchmarks/protocol.bench.ts +310 -0
- package/dist/dashboard/out/404.html +0 -1
- package/dist/dashboard/out/_next/static/T1tgCqVWHFIkV7ClEtzD7/_buildManifest.js +0 -1
- package/dist/dashboard/out/_next/static/T1tgCqVWHFIkV7ClEtzD7/_ssgManifest.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/116-2502180def231162.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/117-f7b8ab0809342e77.js +0 -2
- package/dist/dashboard/out/_next/static/chunks/282-980c2eb8fff20123.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/532-bace199897eeab37.js +0 -9
- package/dist/dashboard/out/_next/static/chunks/648-5cc6e1921389a58a.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/766-b54f0853794b78c3.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/83-b51836037078006c.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/891-6cd50de1224f70bb.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/899-bb19a9b3d9b39ea6.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/_not-found/page-53b8a69f76db17d0.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/app/onboarding/page-8939b0fc700f7eca.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/app/page-5af1b6b439858aa6.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/connect-repos/page-f45ecbc3e06134fc.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/history/page-8c8bed33beb2bf1c.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/layout-2433bb48965f4333.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/login/page-16f3b49e55b1e0ed.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/metrics/page-ac39dc0cc3c26fa7.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/page-4a5938c18a11a654.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/pricing/page-982a7000fee44014.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/providers/page-ac3a6ac433fd6001.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/providers/setup/[provider]/page-09f9caae98a18c09.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/signup/page-547dd0ca55ecd0ba.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/e868780c-48e5f147c90a3a41.js +0 -18
- package/dist/dashboard/out/_next/static/chunks/fd9d1056-609918ca7b6280bb.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/framework-f66176bb897dc684.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/main-2ee6beb2ae96d210.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/main-app-5d692157a8eb1fd9.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/pages/_app-72b849fbd24ac258.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/pages/_error-7ba65e1336b92748.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/polyfills-42372ed130431b0a.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/webpack-1cdd8ed57114d5e1.js +0 -1
- package/dist/dashboard/out/_next/static/css/85d2af9c7ac74d62.css +0 -1
- package/dist/dashboard/out/_next/static/css/fe4b28883eeff359.css +0 -1
- package/dist/dashboard/out/alt-logos/agent-relay-logo-128.png +0 -0
- package/dist/dashboard/out/alt-logos/agent-relay-logo-256.png +0 -0
- package/dist/dashboard/out/alt-logos/agent-relay-logo-32.png +0 -0
- package/dist/dashboard/out/alt-logos/agent-relay-logo-512.png +0 -0
- package/dist/dashboard/out/alt-logos/agent-relay-logo-64.png +0 -0
- package/dist/dashboard/out/alt-logos/agent-relay-logo.svg +0 -45
- package/dist/dashboard/out/alt-logos/logo.svg +0 -38
- package/dist/dashboard/out/alt-logos/monogram-logo-128.png +0 -0
- package/dist/dashboard/out/alt-logos/monogram-logo-256.png +0 -0
- package/dist/dashboard/out/alt-logos/monogram-logo-32.png +0 -0
- package/dist/dashboard/out/alt-logos/monogram-logo-512.png +0 -0
- package/dist/dashboard/out/alt-logos/monogram-logo-64.png +0 -0
- package/dist/dashboard/out/alt-logos/monogram-logo.svg +0 -38
- package/dist/dashboard/out/app/onboarding.html +0 -1
- package/dist/dashboard/out/app/onboarding.txt +0 -7
- package/dist/dashboard/out/app.html +0 -1
- package/dist/dashboard/out/app.txt +0 -7
- package/dist/dashboard/out/apple-icon.png +0 -0
- package/dist/dashboard/out/connect-repos.html +0 -1
- package/dist/dashboard/out/connect-repos.txt +0 -7
- package/dist/dashboard/out/history.html +0 -1
- package/dist/dashboard/out/history.txt +0 -7
- package/dist/dashboard/out/index.html +0 -1
- package/dist/dashboard/out/index.txt +0 -7
- package/dist/dashboard/out/login.html +0 -6
- package/dist/dashboard/out/login.txt +0 -7
- package/dist/dashboard/out/metrics.html +0 -1
- package/dist/dashboard/out/metrics.txt +0 -7
- package/dist/dashboard/out/pricing.html +0 -13
- package/dist/dashboard/out/pricing.txt +0 -7
- package/dist/dashboard/out/providers/setup/claude.html +0 -1
- package/dist/dashboard/out/providers/setup/claude.txt +0 -8
- package/dist/dashboard/out/providers/setup/codex.html +0 -1
- package/dist/dashboard/out/providers/setup/codex.txt +0 -8
- package/dist/dashboard/out/providers.html +0 -1
- package/dist/dashboard/out/providers.txt +0 -7
- package/dist/dashboard/out/signup.html +0 -6
- package/dist/dashboard/out/signup.txt +0 -7
- package/dist/dashboard-server/metrics.d.ts +0 -105
- package/dist/dashboard-server/metrics.js +0 -193
- package/dist/dashboard-server/needs-attention.d.ts +0 -24
- package/dist/dashboard-server/needs-attention.js +0 -78
- package/dist/dashboard-server/server.d.ts +0 -15
- package/dist/dashboard-server/server.js +0 -3776
- package/dist/dashboard-server/start.d.ts +0 -6
- package/dist/dashboard-server/start.js +0 -13
- package/dist/dashboard-server/user-bridge.d.ts +0 -103
- package/dist/dashboard-server/user-bridge.js +0 -189
package/dist/cloud/db/drizzle.js
CHANGED
|
@@ -6,21 +6,47 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
8
8
|
import { Pool } from 'pg';
|
|
9
|
-
import { eq, and, sql, desc, lt, isNull, isNotNull } from 'drizzle-orm';
|
|
9
|
+
import { eq, and, sql, desc, lt, isNull, isNotNull, inArray } from 'drizzle-orm';
|
|
10
10
|
import * as schema from './schema.js';
|
|
11
11
|
import { getConfig } from '../config.js';
|
|
12
|
+
import { DEFAULT_POOL_CONFIG } from './bulk-ingest.js';
|
|
12
13
|
// Re-export schema for direct table access
|
|
13
14
|
export * from './schema.js';
|
|
14
15
|
// Initialize pool and drizzle lazily
|
|
15
16
|
let pool = null;
|
|
16
17
|
let drizzleDb = null;
|
|
18
|
+
/**
|
|
19
|
+
* Get or create the connection pool with optimized settings.
|
|
20
|
+
* Pool configuration:
|
|
21
|
+
* - max: 20 connections (up from default 10)
|
|
22
|
+
* - idleTimeoutMillis: 30s (close idle connections)
|
|
23
|
+
* - connectionTimeoutMillis: 10s (fail fast on connection issues)
|
|
24
|
+
*/
|
|
17
25
|
function getPool() {
|
|
18
26
|
if (!pool) {
|
|
19
27
|
const config = getConfig();
|
|
20
|
-
pool = new Pool({
|
|
28
|
+
pool = new Pool({
|
|
29
|
+
connectionString: config.databaseUrl,
|
|
30
|
+
...DEFAULT_POOL_CONFIG,
|
|
31
|
+
// Allow SSL for cloud databases
|
|
32
|
+
ssl: config.databaseUrl?.includes('sslmode=require')
|
|
33
|
+
? { rejectUnauthorized: false }
|
|
34
|
+
: undefined,
|
|
35
|
+
});
|
|
36
|
+
// Log pool errors (connection issues, etc.)
|
|
37
|
+
pool.on('error', (err) => {
|
|
38
|
+
console.error('[db] Pool error:', err.message);
|
|
39
|
+
});
|
|
21
40
|
}
|
|
22
41
|
return pool;
|
|
23
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Get the raw connection pool for bulk operations.
|
|
45
|
+
* Use this for optimized bulk inserts that bypass the ORM.
|
|
46
|
+
*/
|
|
47
|
+
export function getRawPool() {
|
|
48
|
+
return getPool();
|
|
49
|
+
}
|
|
24
50
|
export function getDb() {
|
|
25
51
|
if (!drizzleDb) {
|
|
26
52
|
drizzleDb = drizzle(getPool(), { schema });
|
|
@@ -257,6 +283,17 @@ export const workspaceQueries = {
|
|
|
257
283
|
.where(eq(schema.workspaces.customDomain, domain));
|
|
258
284
|
return result[0] ?? null;
|
|
259
285
|
},
|
|
286
|
+
async findByRepoFullName(repoFullName) {
|
|
287
|
+
const db = getDb();
|
|
288
|
+
// Find repository by full name (case-insensitive), then get its workspace
|
|
289
|
+
const result = await db
|
|
290
|
+
.select({ workspace: schema.workspaces })
|
|
291
|
+
.from(schema.repositories)
|
|
292
|
+
.innerJoin(schema.workspaces, eq(schema.repositories.workspaceId, schema.workspaces.id))
|
|
293
|
+
.where(sql `LOWER(${schema.repositories.githubFullName}) = LOWER(${repoFullName})`)
|
|
294
|
+
.limit(1);
|
|
295
|
+
return result[0]?.workspace ?? null;
|
|
296
|
+
},
|
|
260
297
|
async findAll() {
|
|
261
298
|
const db = getDb();
|
|
262
299
|
return db
|
|
@@ -428,6 +465,14 @@ export const linkedDaemonQueries = {
|
|
|
428
465
|
.where(eq(schema.linkedDaemons.userId, userId))
|
|
429
466
|
.orderBy(desc(schema.linkedDaemons.lastSeenAt));
|
|
430
467
|
},
|
|
468
|
+
async findByWorkspaceId(workspaceId) {
|
|
469
|
+
const db = getDb();
|
|
470
|
+
return db
|
|
471
|
+
.select()
|
|
472
|
+
.from(schema.linkedDaemons)
|
|
473
|
+
.where(eq(schema.linkedDaemons.workspaceId, workspaceId))
|
|
474
|
+
.orderBy(desc(schema.linkedDaemons.lastSeenAt));
|
|
475
|
+
},
|
|
431
476
|
async findByMachineId(userId, machineId) {
|
|
432
477
|
const db = getDb();
|
|
433
478
|
const result = await db
|
|
@@ -492,6 +537,19 @@ export const linkedDaemonQueries = {
|
|
|
492
537
|
agents: d.metadata?.agents || [],
|
|
493
538
|
}));
|
|
494
539
|
},
|
|
540
|
+
async getAgentsForWorkspace(workspaceId) {
|
|
541
|
+
const db = getDb();
|
|
542
|
+
const daemons = await db
|
|
543
|
+
.select()
|
|
544
|
+
.from(schema.linkedDaemons)
|
|
545
|
+
.where(eq(schema.linkedDaemons.workspaceId, workspaceId));
|
|
546
|
+
return daemons.map((d) => ({
|
|
547
|
+
daemonId: d.id,
|
|
548
|
+
daemonName: d.name,
|
|
549
|
+
machineId: d.machineId,
|
|
550
|
+
agents: d.metadata?.agents || [],
|
|
551
|
+
}));
|
|
552
|
+
},
|
|
495
553
|
async getPendingUpdates(id) {
|
|
496
554
|
const db = getDb();
|
|
497
555
|
const result = await db.select().from(schema.linkedDaemons).where(eq(schema.linkedDaemons.id, id));
|
|
@@ -1068,6 +1126,120 @@ export const commentMentionQueries = {
|
|
|
1068
1126
|
.where(eq(schema.commentMentions.id, id));
|
|
1069
1127
|
},
|
|
1070
1128
|
};
|
|
1129
|
+
export const agentMessageQueries = {
|
|
1130
|
+
async create(data) {
|
|
1131
|
+
const db = getDb();
|
|
1132
|
+
const result = await db.insert(schema.agentMessages).values(data).returning();
|
|
1133
|
+
return result[0];
|
|
1134
|
+
},
|
|
1135
|
+
async createMany(data) {
|
|
1136
|
+
if (data.length === 0)
|
|
1137
|
+
return [];
|
|
1138
|
+
const db = getDb();
|
|
1139
|
+
const result = await db
|
|
1140
|
+
.insert(schema.agentMessages)
|
|
1141
|
+
.values(data)
|
|
1142
|
+
.onConflictDoNothing() // Skip duplicates based on workspace_original_unique constraint
|
|
1143
|
+
.returning();
|
|
1144
|
+
return result;
|
|
1145
|
+
},
|
|
1146
|
+
async findById(id) {
|
|
1147
|
+
const db = getDb();
|
|
1148
|
+
const result = await db
|
|
1149
|
+
.select()
|
|
1150
|
+
.from(schema.agentMessages)
|
|
1151
|
+
.where(eq(schema.agentMessages.id, id));
|
|
1152
|
+
return result[0] ?? null;
|
|
1153
|
+
},
|
|
1154
|
+
async findByOriginalId(workspaceId, originalId) {
|
|
1155
|
+
const db = getDb();
|
|
1156
|
+
const result = await db
|
|
1157
|
+
.select()
|
|
1158
|
+
.from(schema.agentMessages)
|
|
1159
|
+
.where(and(eq(schema.agentMessages.workspaceId, workspaceId), eq(schema.agentMessages.originalId, originalId)));
|
|
1160
|
+
return result[0] ?? null;
|
|
1161
|
+
},
|
|
1162
|
+
async query(params) {
|
|
1163
|
+
const db = getDb();
|
|
1164
|
+
const conditions = [eq(schema.agentMessages.workspaceId, params.workspaceId)];
|
|
1165
|
+
if (params.fromAgent) {
|
|
1166
|
+
conditions.push(eq(schema.agentMessages.fromAgent, params.fromAgent));
|
|
1167
|
+
}
|
|
1168
|
+
if (params.toAgent) {
|
|
1169
|
+
conditions.push(eq(schema.agentMessages.toAgent, params.toAgent));
|
|
1170
|
+
}
|
|
1171
|
+
if (params.thread) {
|
|
1172
|
+
conditions.push(eq(schema.agentMessages.thread, params.thread));
|
|
1173
|
+
}
|
|
1174
|
+
if (params.channel) {
|
|
1175
|
+
conditions.push(eq(schema.agentMessages.channel, params.channel));
|
|
1176
|
+
}
|
|
1177
|
+
if (params.sinceTs) {
|
|
1178
|
+
conditions.push(sql `${schema.agentMessages.messageTs} >= ${params.sinceTs}`);
|
|
1179
|
+
}
|
|
1180
|
+
if (params.beforeTs) {
|
|
1181
|
+
conditions.push(sql `${schema.agentMessages.messageTs} < ${params.beforeTs}`);
|
|
1182
|
+
}
|
|
1183
|
+
if (!params.includeExpired) {
|
|
1184
|
+
conditions.push(sql `(${schema.agentMessages.expiresAt} IS NULL OR ${schema.agentMessages.expiresAt} > NOW())`);
|
|
1185
|
+
}
|
|
1186
|
+
let query = db
|
|
1187
|
+
.select()
|
|
1188
|
+
.from(schema.agentMessages)
|
|
1189
|
+
.where(and(...conditions))
|
|
1190
|
+
.orderBy(desc(schema.agentMessages.messageTs));
|
|
1191
|
+
if (params.limit) {
|
|
1192
|
+
query = query.limit(params.limit);
|
|
1193
|
+
}
|
|
1194
|
+
if (params.offset) {
|
|
1195
|
+
query = query.offset(params.offset);
|
|
1196
|
+
}
|
|
1197
|
+
return query;
|
|
1198
|
+
},
|
|
1199
|
+
async getUnindexed(workspaceId, limit = 100) {
|
|
1200
|
+
const db = getDb();
|
|
1201
|
+
return db
|
|
1202
|
+
.select()
|
|
1203
|
+
.from(schema.agentMessages)
|
|
1204
|
+
.where(and(eq(schema.agentMessages.workspaceId, workspaceId), isNull(schema.agentMessages.indexedAt), sql `(${schema.agentMessages.expiresAt} IS NULL OR ${schema.agentMessages.expiresAt} > NOW())`))
|
|
1205
|
+
.orderBy(schema.agentMessages.messageTs)
|
|
1206
|
+
.limit(limit);
|
|
1207
|
+
},
|
|
1208
|
+
async markIndexed(ids) {
|
|
1209
|
+
if (ids.length === 0)
|
|
1210
|
+
return;
|
|
1211
|
+
const db = getDb();
|
|
1212
|
+
await db
|
|
1213
|
+
.update(schema.agentMessages)
|
|
1214
|
+
.set({ indexedAt: new Date() })
|
|
1215
|
+
.where(inArray(schema.agentMessages.id, ids));
|
|
1216
|
+
},
|
|
1217
|
+
async deleteExpired() {
|
|
1218
|
+
const db = getDb();
|
|
1219
|
+
const result = await db
|
|
1220
|
+
.delete(schema.agentMessages)
|
|
1221
|
+
.where(and(isNotNull(schema.agentMessages.expiresAt), lt(schema.agentMessages.expiresAt, new Date())))
|
|
1222
|
+
.returning({ id: schema.agentMessages.id });
|
|
1223
|
+
return result.length;
|
|
1224
|
+
},
|
|
1225
|
+
async countByWorkspace(workspaceId) {
|
|
1226
|
+
const db = getDb();
|
|
1227
|
+
const result = await db
|
|
1228
|
+
.select({ count: sql `count(*)` })
|
|
1229
|
+
.from(schema.agentMessages)
|
|
1230
|
+
.where(eq(schema.agentMessages.workspaceId, workspaceId));
|
|
1231
|
+
return Number(result[0]?.count ?? 0);
|
|
1232
|
+
},
|
|
1233
|
+
async getThreadMessages(workspaceId, thread, limit = 50) {
|
|
1234
|
+
const db = getDb();
|
|
1235
|
+
return db
|
|
1236
|
+
.select()
|
|
1237
|
+
.from(schema.agentMessages)
|
|
1238
|
+
.where(and(eq(schema.agentMessages.workspaceId, workspaceId), eq(schema.agentMessages.thread, thread), sql `(${schema.agentMessages.expiresAt} IS NULL OR ${schema.agentMessages.expiresAt} > NOW())`))
|
|
1239
|
+
.orderBy(schema.agentMessages.messageTs)
|
|
1240
|
+
.limit(limit);
|
|
1241
|
+
},
|
|
1242
|
+
};
|
|
1071
1243
|
// ============================================================================
|
|
1072
1244
|
// Migration helper
|
|
1073
1245
|
// ============================================================================
|
package/dist/cloud/db/index.d.ts
CHANGED
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
* Generate migrations: npm run db:generate
|
|
8
8
|
* Run migrations: npm run db:migrate
|
|
9
9
|
*/
|
|
10
|
-
export type { User, NewUser, GitHubInstallation, NewGitHubInstallation, Credential, NewCredential, Workspace, NewWorkspace, WorkspaceConfig, WorkspaceAgentPolicy, AgentPolicyRule, WorkspaceMember, NewWorkspaceMember, ProjectGroup, NewProjectGroup, CoordinatorAgentConfig, ProjectAgentConfig, Repository, NewRepository, LinkedDaemon, NewLinkedDaemon, Subscription, NewSubscription, UsageRecord, NewUsageRecord, CIAnnotation, CIFailureEvent, NewCIFailureEvent, CIFixAttempt, NewCIFixAttempt, CICheckStrategy, CIWebhookConfig, IssueAssignment, NewIssueAssignment, CommentMention, NewCommentMention, AgentTriggerConfig, } from './schema.js';
|
|
11
|
-
export { users as usersTable, githubInstallations as githubInstallationsTable, credentials as credentialsTable, workspaces as workspacesTable, workspaceMembers as workspaceMembersTable, projectGroups as projectGroupsTable, repositories as repositoriesTable, linkedDaemons as linkedDaemonsTable, subscriptions as subscriptionsTable, usageRecords as usageRecordsTable, ciFailureEvents as ciFailureEventsTable, ciFixAttempts as ciFixAttemptsTable, issueAssignments as issueAssignmentsTable, commentMentions as commentMentionsTable, } from './schema.js';
|
|
12
|
-
import { getDb, closeDb, runMigrations, userQueries, githubInstallationQueries, credentialQueries, workspaceQueries, workspaceMemberQueries, linkedDaemonQueries, projectGroupQueries, repositoryQueries, ciFailureEventQueries, ciFixAttemptQueries, issueAssignmentQueries, commentMentionQueries } from './drizzle.js';
|
|
10
|
+
export type { User, NewUser, GitHubInstallation, NewGitHubInstallation, Credential, NewCredential, Workspace, NewWorkspace, WorkspaceConfig, WorkspaceAgentPolicy, AgentPolicyRule, WorkspaceMember, NewWorkspaceMember, ProjectGroup, NewProjectGroup, CoordinatorAgentConfig, ProjectAgentConfig, Repository, NewRepository, LinkedDaemon, NewLinkedDaemon, Subscription, NewSubscription, UsageRecord, NewUsageRecord, CIAnnotation, CIFailureEvent, NewCIFailureEvent, CIFixAttempt, NewCIFixAttempt, CICheckStrategy, CIWebhookConfig, IssueAssignment, NewIssueAssignment, CommentMention, NewCommentMention, AgentTriggerConfig, AgentMessage, NewAgentMessage, MessagePayloadMeta, } from './schema.js';
|
|
11
|
+
export { users as usersTable, githubInstallations as githubInstallationsTable, credentials as credentialsTable, workspaces as workspacesTable, workspaceMembers as workspaceMembersTable, projectGroups as projectGroupsTable, repositories as repositoriesTable, linkedDaemons as linkedDaemonsTable, subscriptions as subscriptionsTable, usageRecords as usageRecordsTable, ciFailureEvents as ciFailureEventsTable, ciFixAttempts as ciFixAttemptsTable, issueAssignments as issueAssignmentsTable, commentMentions as commentMentionsTable, agentMessages as agentMessagesTable, } from './schema.js';
|
|
12
|
+
import { getDb, closeDb, runMigrations, getRawPool, userQueries, githubInstallationQueries, credentialQueries, workspaceQueries, workspaceMemberQueries, linkedDaemonQueries, projectGroupQueries, repositoryQueries, ciFailureEventQueries, ciFixAttemptQueries, issueAssignmentQueries, commentMentionQueries, agentMessageQueries } from './drizzle.js';
|
|
13
|
+
import { bulkInsertMessages, streamingBulkInsert, optimizedBulkInsert, getPoolStats, checkPoolHealth, type BulkInsertResult } from './bulk-ingest.js';
|
|
13
14
|
export type PlanType = 'free' | 'pro' | 'team' | 'enterprise';
|
|
14
15
|
export type WorkspaceMemberRole = 'owner' | 'admin' | 'member' | 'viewer';
|
|
15
16
|
export declare const db: {
|
|
@@ -25,11 +26,29 @@ export declare const db: {
|
|
|
25
26
|
ciFixAttempts: import("./drizzle.js").CIFixAttemptQueries;
|
|
26
27
|
issueAssignments: import("./drizzle.js").IssueAssignmentQueries;
|
|
27
28
|
commentMentions: import("./drizzle.js").CommentMentionQueries;
|
|
29
|
+
agentMessages: import("./drizzle.js").AgentMessageQueries;
|
|
30
|
+
bulk: {
|
|
31
|
+
insertMessages: typeof bulkInsertMessages;
|
|
32
|
+
streamingInsert: typeof streamingBulkInsert;
|
|
33
|
+
optimizedInsert: typeof optimizedBulkInsert;
|
|
34
|
+
getPoolStats: () => {
|
|
35
|
+
total: number;
|
|
36
|
+
idle: number;
|
|
37
|
+
waiting: number;
|
|
38
|
+
};
|
|
39
|
+
checkHealth: () => Promise<{
|
|
40
|
+
healthy: boolean;
|
|
41
|
+
latencyMs: number;
|
|
42
|
+
error?: string;
|
|
43
|
+
}>;
|
|
44
|
+
};
|
|
28
45
|
getDb: typeof getDb;
|
|
46
|
+
getRawPool: typeof getRawPool;
|
|
29
47
|
close: typeof closeDb;
|
|
30
48
|
runMigrations: typeof runMigrations;
|
|
31
49
|
};
|
|
32
|
-
export { userQueries, githubInstallationQueries, credentialQueries, workspaceQueries, workspaceMemberQueries, projectGroupQueries, repositoryQueries, linkedDaemonQueries, ciFailureEventQueries, ciFixAttemptQueries, issueAssignmentQueries, commentMentionQueries, };
|
|
33
|
-
export { getDb, closeDb, runMigrations };
|
|
50
|
+
export { userQueries, githubInstallationQueries, credentialQueries, workspaceQueries, workspaceMemberQueries, projectGroupQueries, repositoryQueries, linkedDaemonQueries, ciFailureEventQueries, ciFixAttemptQueries, issueAssignmentQueries, commentMentionQueries, agentMessageQueries, };
|
|
51
|
+
export { getDb, closeDb, runMigrations, getRawPool };
|
|
52
|
+
export { bulkInsertMessages, streamingBulkInsert, optimizedBulkInsert, getPoolStats, checkPoolHealth, type BulkInsertResult, };
|
|
34
53
|
export declare function initializeDatabase(): Promise<void>;
|
|
35
54
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cloud/db/index.js
CHANGED
|
@@ -8,9 +8,11 @@
|
|
|
8
8
|
* Run migrations: npm run db:migrate
|
|
9
9
|
*/
|
|
10
10
|
// Re-export schema tables for direct access if needed
|
|
11
|
-
export { users as usersTable, githubInstallations as githubInstallationsTable, credentials as credentialsTable, workspaces as workspacesTable, workspaceMembers as workspaceMembersTable, projectGroups as projectGroupsTable, repositories as repositoriesTable, linkedDaemons as linkedDaemonsTable, subscriptions as subscriptionsTable, usageRecords as usageRecordsTable, ciFailureEvents as ciFailureEventsTable, ciFixAttempts as ciFixAttemptsTable, issueAssignments as issueAssignmentsTable, commentMentions as commentMentionsTable, } from './schema.js';
|
|
11
|
+
export { users as usersTable, githubInstallations as githubInstallationsTable, credentials as credentialsTable, workspaces as workspacesTable, workspaceMembers as workspaceMembersTable, projectGroups as projectGroupsTable, repositories as repositoriesTable, linkedDaemons as linkedDaemonsTable, subscriptions as subscriptionsTable, usageRecords as usageRecordsTable, ciFailureEvents as ciFailureEventsTable, ciFixAttempts as ciFixAttemptsTable, issueAssignments as issueAssignmentsTable, commentMentions as commentMentionsTable, agentMessages as agentMessagesTable, } from './schema.js';
|
|
12
12
|
// Import query modules
|
|
13
|
-
import { getDb, closeDb, runMigrations, userQueries, githubInstallationQueries, credentialQueries, workspaceQueries, workspaceMemberQueries, linkedDaemonQueries, projectGroupQueries, repositoryQueries, ciFailureEventQueries, ciFixAttemptQueries, issueAssignmentQueries, commentMentionQueries, } from './drizzle.js';
|
|
13
|
+
import { getDb, closeDb, runMigrations, getRawPool, userQueries, githubInstallationQueries, credentialQueries, workspaceQueries, workspaceMemberQueries, linkedDaemonQueries, projectGroupQueries, repositoryQueries, ciFailureEventQueries, ciFixAttemptQueries, issueAssignmentQueries, commentMentionQueries, agentMessageQueries, } from './drizzle.js';
|
|
14
|
+
// Import bulk ingest utilities
|
|
15
|
+
import { bulkInsertMessages, streamingBulkInsert, optimizedBulkInsert, getPoolStats, checkPoolHealth, } from './bulk-ingest.js';
|
|
14
16
|
// Export the db object with all query namespaces
|
|
15
17
|
export const db = {
|
|
16
18
|
// User operations
|
|
@@ -35,15 +37,28 @@ export const db = {
|
|
|
35
37
|
// Issue and comment tracking
|
|
36
38
|
issueAssignments: issueAssignmentQueries,
|
|
37
39
|
commentMentions: commentMentionQueries,
|
|
40
|
+
// Agent messages (cloud-synced relay messages)
|
|
41
|
+
agentMessages: agentMessageQueries,
|
|
42
|
+
// Bulk ingest utilities (optimized high-volume operations)
|
|
43
|
+
bulk: {
|
|
44
|
+
insertMessages: bulkInsertMessages,
|
|
45
|
+
streamingInsert: streamingBulkInsert,
|
|
46
|
+
optimizedInsert: optimizedBulkInsert,
|
|
47
|
+
getPoolStats: () => getPoolStats(getRawPool()),
|
|
48
|
+
checkHealth: () => checkPoolHealth(getRawPool()),
|
|
49
|
+
},
|
|
38
50
|
// Database utilities
|
|
39
51
|
getDb,
|
|
52
|
+
getRawPool,
|
|
40
53
|
close: closeDb,
|
|
41
54
|
runMigrations,
|
|
42
55
|
};
|
|
43
56
|
// Export query objects for direct import
|
|
44
|
-
export { userQueries, githubInstallationQueries, credentialQueries, workspaceQueries, workspaceMemberQueries, projectGroupQueries, repositoryQueries, linkedDaemonQueries, ciFailureEventQueries, ciFixAttemptQueries, issueAssignmentQueries, commentMentionQueries, };
|
|
57
|
+
export { userQueries, githubInstallationQueries, credentialQueries, workspaceQueries, workspaceMemberQueries, projectGroupQueries, repositoryQueries, linkedDaemonQueries, ciFailureEventQueries, ciFixAttemptQueries, issueAssignmentQueries, commentMentionQueries, agentMessageQueries, };
|
|
45
58
|
// Export database utilities
|
|
46
|
-
export { getDb, closeDb, runMigrations };
|
|
59
|
+
export { getDb, closeDb, runMigrations, getRawPool };
|
|
60
|
+
// Export bulk ingest utilities
|
|
61
|
+
export { bulkInsertMessages, streamingBulkInsert, optimizedBulkInsert, getPoolStats, checkPoolHealth, };
|
|
47
62
|
// Legacy function - use runMigrations instead
|
|
48
63
|
export async function initializeDatabase() {
|
|
49
64
|
console.warn('initializeDatabase() is deprecated. Use runMigrations() instead.');
|