@inkeep/agents-core 0.41.2 → 0.42.0
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/dist/api-client/base-client.d.ts +87 -8
- package/dist/api-client/base-client.js +174 -1
- package/dist/api-client/eval-api-client.d.ts +47 -0
- package/dist/api-client/eval-api-client.js +65 -0
- package/dist/api-client/index.d.ts +4 -0
- package/dist/api-client/index.js +5 -0
- package/dist/api-client/manage-api-client.d.ts +34 -0
- package/dist/api-client/manage-api-client.js +104 -0
- package/dist/auth/auth.d.ts +86 -20
- package/dist/auth/auth.js +55 -1
- package/dist/auth/authz/client.d.ts +81 -0
- package/dist/auth/authz/client.js +189 -0
- package/dist/auth/authz/config.d.ts +76 -0
- package/dist/auth/authz/config.js +76 -0
- package/dist/auth/authz/index.d.ts +5 -0
- package/dist/auth/authz/index.js +6 -0
- package/dist/auth/authz/permissions.d.ts +57 -0
- package/dist/auth/authz/permissions.js +83 -0
- package/dist/auth/authz/sync.d.ts +85 -0
- package/dist/auth/authz/sync.js +237 -0
- package/dist/auth/permissions.d.ts +13 -13
- package/dist/auth/permissions.js +2 -181
- package/dist/client-exports.d.ts +8 -3
- package/dist/client-exports.js +3 -2
- package/dist/constants/context-breakdown.d.ts +61 -0
- package/dist/constants/context-breakdown.js +124 -0
- package/dist/constants/otel-attributes.d.ts +4 -0
- package/dist/constants/otel-attributes.js +4 -0
- package/dist/context/ContextConfig.d.ts +2 -2
- package/dist/context/ContextConfig.js +3 -3
- package/dist/context/TemplateEngine.js +0 -1
- package/dist/context/index.d.ts +1 -5
- package/dist/context/index.js +1 -5
- package/dist/credential-stuffer/CredentialStuffer.d.ts +1 -1
- package/dist/data-access/index.d.ts +34 -26
- package/dist/data-access/index.js +34 -26
- package/dist/data-access/manage/agentFull.d.ts +36 -0
- package/dist/data-access/{agentFull.js → manage/agentFull.js} +205 -7
- package/dist/data-access/{agents.d.ts → manage/agents.d.ts} +23 -22
- package/dist/data-access/{agents.js → manage/agents.js} +52 -7
- package/dist/data-access/{artifactComponents.d.ts → manage/artifactComponents.d.ts} +21 -21
- package/dist/data-access/{artifactComponents.js → manage/artifactComponents.js} +5 -5
- package/dist/data-access/{contextConfigs.d.ts → manage/contextConfigs.d.ts} +14 -14
- package/dist/data-access/{contextConfigs.js → manage/contextConfigs.js} +3 -3
- package/dist/data-access/{credentialReferences.d.ts → manage/credentialReferences.d.ts} +17 -17
- package/dist/data-access/{credentialReferences.js → manage/credentialReferences.js} +2 -2
- package/dist/data-access/{dataComponents.d.ts → manage/dataComponents.d.ts} +20 -20
- package/dist/data-access/{dataComponents.js → manage/dataComponents.js} +7 -7
- package/dist/data-access/manage/evalConfig.d.ts +221 -0
- package/dist/data-access/manage/evalConfig.js +275 -0
- package/dist/data-access/{externalAgents.d.ts → manage/externalAgents.d.ts} +16 -16
- package/dist/data-access/{externalAgents.js → manage/externalAgents.js} +2 -2
- package/dist/data-access/{functionTools.d.ts → manage/functionTools.d.ts} +65 -15
- package/dist/data-access/{functionTools.js → manage/functionTools.js} +90 -8
- package/dist/data-access/{functions.d.ts → manage/functions.d.ts} +9 -9
- package/dist/data-access/{functions.js → manage/functions.js} +3 -3
- package/dist/data-access/manage/projectFull.d.ts +38 -0
- package/dist/data-access/{projectFull.js → manage/projectFull.js} +64 -65
- package/dist/data-access/manage/projectLifecycle.d.ts +119 -0
- package/dist/data-access/manage/projectLifecycle.js +234 -0
- package/dist/data-access/manage/projects.d.ts +75 -0
- package/dist/data-access/{projects.js → manage/projects.js} +15 -16
- package/dist/data-access/{subAgentExternalAgentRelations.d.ts → manage/subAgentExternalAgentRelations.d.ts} +19 -19
- package/dist/data-access/{subAgentExternalAgentRelations.js → manage/subAgentExternalAgentRelations.js} +2 -2
- package/dist/data-access/{subAgentRelations.d.ts → manage/subAgentRelations.d.ts} +29 -29
- package/dist/data-access/{subAgentRelations.js → manage/subAgentRelations.js} +3 -3
- package/dist/data-access/{subAgentTeamAgentRelations.d.ts → manage/subAgentTeamAgentRelations.d.ts} +19 -19
- package/dist/data-access/{subAgentTeamAgentRelations.js → manage/subAgentTeamAgentRelations.js} +2 -2
- package/dist/data-access/{subAgents.d.ts → manage/subAgents.d.ts} +13 -13
- package/dist/data-access/{subAgents.js → manage/subAgents.js} +4 -4
- package/dist/data-access/{tools.d.ts → manage/tools.d.ts} +26 -19
- package/dist/data-access/{tools.js → manage/tools.js} +57 -35
- package/dist/data-access/manage/triggers.d.ts +80 -0
- package/dist/data-access/manage/triggers.js +81 -0
- package/dist/data-access/{apiKeys.d.ts → runtime/apiKeys.d.ts} +17 -17
- package/dist/data-access/{apiKeys.js → runtime/apiKeys.js} +3 -3
- package/dist/data-access/runtime/cascade-delete.d.ts +77 -0
- package/dist/data-access/runtime/cascade-delete.js +111 -0
- package/dist/data-access/{contextCache.d.ts → runtime/contextCache.d.ts} +13 -13
- package/dist/data-access/{contextCache.js → runtime/contextCache.js} +5 -5
- package/dist/data-access/{conversations.d.ts → runtime/conversations.d.ts} +68 -19
- package/dist/data-access/{conversations.js → runtime/conversations.js} +13 -7
- package/dist/data-access/runtime/evalRuns.d.ts +120 -0
- package/dist/data-access/runtime/evalRuns.js +168 -0
- package/dist/data-access/{ledgerArtifacts.d.ts → runtime/ledgerArtifacts.d.ts} +13 -13
- package/dist/data-access/{ledgerArtifacts.js → runtime/ledgerArtifacts.js} +3 -3
- package/dist/data-access/{messages.d.ts → runtime/messages.d.ts} +15 -15
- package/dist/data-access/{messages.js → runtime/messages.js} +2 -2
- package/dist/data-access/{organizations.d.ts → runtime/organizations.d.ts} +16 -7
- package/dist/data-access/{organizations.js → runtime/organizations.js} +15 -3
- package/dist/data-access/runtime/projects.d.ts +62 -0
- package/dist/data-access/runtime/projects.js +90 -0
- package/dist/data-access/runtime/tasks.d.ts +55 -0
- package/dist/data-access/{tasks.js → runtime/tasks.js} +2 -2
- package/dist/data-access/runtime/triggerInvocations.d.ts +62 -0
- package/dist/data-access/runtime/triggerInvocations.js +54 -0
- package/dist/data-access/runtime/users.d.ts +19 -0
- package/dist/data-access/{users.js → runtime/users.js} +2 -2
- package/dist/data-access/validation.d.ts +4 -4
- package/dist/data-access/validation.js +1 -1
- package/dist/db/clean.d.ts +8 -4
- package/dist/db/clean.js +14 -105
- package/dist/db/delete.d.ts +1 -1
- package/dist/db/delete.js +7 -10
- package/dist/db/manage/dolt-cleanup.d.ts +51 -0
- package/dist/db/manage/dolt-cleanup.js +132 -0
- package/dist/db/manage/manage-client.d.ts +26 -0
- package/dist/db/manage/manage-client.js +68 -0
- package/dist/db/{schema.d.ts → manage/manage-schema.d.ts} +1459 -1285
- package/dist/db/{schema.js → manage/manage-schema.js} +433 -341
- package/dist/db/manage/test-manage-client.d.ts +27 -0
- package/dist/db/manage/test-manage-client.js +68 -0
- package/dist/db/runtime/runtime-client.d.ts +20 -0
- package/dist/db/runtime/runtime-client.js +30 -0
- package/dist/db/runtime/runtime-schema.d.ts +2834 -0
- package/dist/db/runtime/runtime-schema.js +483 -0
- package/dist/db/runtime/test-runtime-client.d.ts +27 -0
- package/dist/db/{test-client.js → runtime/test-runtime-client.js} +11 -25
- package/dist/dolt/branch.d.ts +62 -0
- package/dist/dolt/branch.js +82 -0
- package/dist/dolt/branches-api.d.ts +108 -0
- package/dist/dolt/branches-api.js +162 -0
- package/dist/dolt/commit.d.ts +94 -0
- package/dist/dolt/commit.js +103 -0
- package/dist/dolt/diff.d.ts +27 -0
- package/dist/dolt/diff.js +21 -0
- package/dist/dolt/index.d.ts +10 -0
- package/dist/dolt/index.js +11 -0
- package/dist/dolt/merge.d.ts +63 -0
- package/dist/dolt/merge.js +81 -0
- package/dist/dolt/migrate-all-branches.d.ts +4 -0
- package/dist/dolt/migrate-all-branches.js +78 -0
- package/dist/dolt/migrate-dolt.d.ts +1 -0
- package/dist/dolt/migrate-dolt.js +22 -0
- package/dist/dolt/ref-helpers.d.ts +19 -0
- package/dist/dolt/ref-helpers.js +65 -0
- package/dist/dolt/ref-middleware.d.ts +82 -0
- package/dist/dolt/ref-middleware.js +217 -0
- package/dist/dolt/ref-scope.d.ts +101 -0
- package/dist/dolt/ref-scope.js +231 -0
- package/dist/dolt/schema-sync.d.ts +134 -0
- package/dist/dolt/schema-sync.js +246 -0
- package/dist/env.d.ts +6 -4
- package/dist/env.js +3 -2
- package/dist/index.d.ts +71 -44
- package/dist/index.js +74 -47
- package/dist/types/entities.d.ts +81 -2
- package/dist/types/index.d.ts +3 -3
- package/dist/types/utility.d.ts +45 -4
- package/dist/utils/JsonTransformer.d.ts +44 -0
- package/dist/utils/JsonTransformer.js +112 -0
- package/dist/utils/apiKeys.d.ts +5 -1
- package/dist/utils/apiKeys.js +11 -1
- package/dist/utils/colors.d.ts +34 -0
- package/dist/utils/colors.js +49 -0
- package/dist/utils/credential-store-utils.d.ts +1 -1
- package/dist/utils/format-messages.d.ts +1 -1
- package/dist/utils/index.d.ts +7 -3
- package/dist/utils/index.js +7 -3
- package/dist/utils/internal-service-auth.d.ts +79 -0
- package/dist/utils/internal-service-auth.js +140 -0
- package/dist/utils/jwt-helpers.d.ts +56 -0
- package/dist/utils/jwt-helpers.js +90 -0
- package/dist/utils/service-token-auth.d.ts +9 -27
- package/dist/utils/service-token-auth.js +48 -96
- package/dist/utils/template-interpolation.d.ts +22 -0
- package/dist/utils/template-interpolation.js +62 -0
- package/dist/utils/third-party-mcp-servers/composio-client.js +23 -23
- package/dist/utils/trigger-auth.d.ts +62 -0
- package/dist/utils/trigger-auth.js +125 -0
- package/dist/validation/agentFull.js +2 -4
- package/dist/validation/dolt-schemas.d.ts +49 -0
- package/dist/validation/dolt-schemas.js +44 -0
- package/dist/validation/drizzle-schema-helpers.d.ts +4 -26
- package/dist/validation/drizzle-schema-helpers.js +5 -151
- package/dist/validation/index.d.ts +4 -3
- package/dist/validation/index.js +3 -2
- package/dist/validation/schemas.d.ts +17647 -4789
- package/dist/validation/schemas.js +328 -11
- package/drizzle/manage/0000_tearful_rhodey.sql +414 -0
- package/drizzle/manage/0001_broken_wendell_vaughn.sql +19 -0
- package/drizzle/manage/0002_bent_sunfire.sql +1 -0
- package/drizzle/manage/meta/0000_snapshot.json +2987 -0
- package/drizzle/manage/meta/0001_snapshot.json +3115 -0
- package/drizzle/manage/meta/0002_snapshot.json +3115 -0
- package/drizzle/manage/meta/_journal.json +27 -0
- package/drizzle/runtime/0008_silly_preak.sql +127 -0
- package/drizzle/runtime/0009_freezing_leo.sql +17 -0
- package/drizzle/runtime/meta/0008_snapshot.json +2263 -0
- package/drizzle/runtime/meta/0009_snapshot.json +2397 -0
- package/drizzle/{meta → runtime/meta}/_journal.json +14 -0
- package/package.json +48 -15
- package/dist/context/ContextFetcher.d.ts +0 -73
- package/dist/context/ContextFetcher.js +0 -291
- package/dist/context/ContextResolver.d.ts +0 -60
- package/dist/context/ContextResolver.js +0 -278
- package/dist/context/context.d.ts +0 -27
- package/dist/context/context.js +0 -128
- package/dist/context/contextCache.d.ts +0 -58
- package/dist/context/contextCache.js +0 -177
- package/dist/data-access/agentFull.d.ts +0 -33
- package/dist/data-access/projectFull.d.ts +0 -32
- package/dist/data-access/projects.d.ts +0 -71
- package/dist/data-access/tasks.d.ts +0 -45
- package/dist/data-access/users.d.ts +0 -19
- package/dist/db/client.d.ts +0 -20
- package/dist/db/client.js +0 -28
- package/dist/db/test-client.d.ts +0 -31
- package/dist/middleware/contextValidation.d.ts +0 -46
- package/dist/middleware/contextValidation.js +0 -280
- package/dist/middleware/index.d.ts +0 -2
- package/dist/middleware/index.js +0 -3
- package/dist/utils/execution.d.ts +0 -22
- package/dist/utils/execution.js +0 -25
- /package/drizzle/{0000_exotic_mysterio.sql → runtime/0000_exotic_mysterio.sql} +0 -0
- /package/drizzle/{0001_calm_sheva_callister.sql → runtime/0001_calm_sheva_callister.sql} +0 -0
- /package/drizzle/{0002_puzzling_goblin_queen.sql → runtime/0002_puzzling_goblin_queen.sql} +0 -0
- /package/drizzle/{0003_sweet_human_robot.sql → runtime/0003_sweet_human_robot.sql} +0 -0
- /package/drizzle/{0004_cuddly_shooting_star.sql → runtime/0004_cuddly_shooting_star.sql} +0 -0
- /package/drizzle/{0005_reflective_starfox.sql → runtime/0005_reflective_starfox.sql} +0 -0
- /package/drizzle/{0006_stale_thaddeus_ross.sql → runtime/0006_stale_thaddeus_ross.sql} +0 -0
- /package/drizzle/{0007_slim_karma.sql → runtime/0007_slim_karma.sql} +0 -0
- /package/drizzle/{meta → runtime/meta}/0000_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0001_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0003_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0005_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0006_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0007_snapshot.json +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { AgentScopeConfig, PaginationConfig } from "../../types/utility.js";
|
|
2
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
3
|
+
import { TriggerInvocationInsert, TriggerInvocationSelect, TriggerInvocationUpdate } from "../../types/entities.js";
|
|
4
|
+
|
|
5
|
+
//#region src/data-access/runtime/triggerInvocations.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get a trigger invocation by ID (agent-scoped)
|
|
9
|
+
*/
|
|
10
|
+
declare const getTriggerInvocationById: (db: AgentsRunDatabaseClient) => (params: {
|
|
11
|
+
scopes: AgentScopeConfig;
|
|
12
|
+
triggerId: string;
|
|
13
|
+
invocationId: string;
|
|
14
|
+
}) => Promise<TriggerInvocationSelect | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* List trigger invocations with optional filtering (agent-scoped)
|
|
17
|
+
*/
|
|
18
|
+
declare const listTriggerInvocationsPaginated: (db: AgentsRunDatabaseClient) => (params: {
|
|
19
|
+
scopes: AgentScopeConfig;
|
|
20
|
+
triggerId: string;
|
|
21
|
+
pagination?: PaginationConfig;
|
|
22
|
+
filters?: {
|
|
23
|
+
status?: "pending" | "success" | "failed";
|
|
24
|
+
from?: string;
|
|
25
|
+
to?: string;
|
|
26
|
+
};
|
|
27
|
+
}) => Promise<{
|
|
28
|
+
data: {
|
|
29
|
+
triggerId: string;
|
|
30
|
+
conversationId: string | null;
|
|
31
|
+
status: string;
|
|
32
|
+
requestPayload: unknown;
|
|
33
|
+
transformedPayload: unknown;
|
|
34
|
+
errorMessage: string | null;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
agentId: string;
|
|
37
|
+
projectId: string;
|
|
38
|
+
tenantId: string;
|
|
39
|
+
id: string;
|
|
40
|
+
}[];
|
|
41
|
+
pagination: {
|
|
42
|
+
page: number;
|
|
43
|
+
limit: number;
|
|
44
|
+
total: number;
|
|
45
|
+
pages: number;
|
|
46
|
+
};
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* Create a new trigger invocation (agent-scoped)
|
|
50
|
+
*/
|
|
51
|
+
declare const createTriggerInvocation: (db: AgentsRunDatabaseClient) => (params: TriggerInvocationInsert) => Promise<TriggerInvocationSelect>;
|
|
52
|
+
/**
|
|
53
|
+
* Update trigger invocation status (agent-scoped)
|
|
54
|
+
*/
|
|
55
|
+
declare const updateTriggerInvocationStatus: (db: AgentsRunDatabaseClient) => (params: {
|
|
56
|
+
scopes: AgentScopeConfig;
|
|
57
|
+
triggerId: string;
|
|
58
|
+
invocationId: string;
|
|
59
|
+
data: TriggerInvocationUpdate;
|
|
60
|
+
}) => Promise<TriggerInvocationSelect>;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { createTriggerInvocation, getTriggerInvocationById, listTriggerInvocationsPaginated, updateTriggerInvocationStatus };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { triggerInvocations } from "../../db/runtime/runtime-schema.js";
|
|
2
|
+
import { and, count, desc, eq, gte, lte } from "drizzle-orm";
|
|
3
|
+
|
|
4
|
+
//#region src/data-access/runtime/triggerInvocations.ts
|
|
5
|
+
/**
|
|
6
|
+
* Get a trigger invocation by ID (agent-scoped)
|
|
7
|
+
*/
|
|
8
|
+
const getTriggerInvocationById = (db) => async (params) => {
|
|
9
|
+
return await db.query.triggerInvocations.findFirst({ where: and(eq(triggerInvocations.tenantId, params.scopes.tenantId), eq(triggerInvocations.projectId, params.scopes.projectId), eq(triggerInvocations.agentId, params.scopes.agentId), eq(triggerInvocations.triggerId, params.triggerId), eq(triggerInvocations.id, params.invocationId)) });
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* List trigger invocations with optional filtering (agent-scoped)
|
|
13
|
+
*/
|
|
14
|
+
const listTriggerInvocationsPaginated = (db) => async (params) => {
|
|
15
|
+
const page = params.pagination?.page || 1;
|
|
16
|
+
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
17
|
+
const offset = (page - 1) * limit;
|
|
18
|
+
const conditions = [
|
|
19
|
+
eq(triggerInvocations.tenantId, params.scopes.tenantId),
|
|
20
|
+
eq(triggerInvocations.projectId, params.scopes.projectId),
|
|
21
|
+
eq(triggerInvocations.agentId, params.scopes.agentId),
|
|
22
|
+
eq(triggerInvocations.triggerId, params.triggerId)
|
|
23
|
+
];
|
|
24
|
+
if (params.filters?.status) conditions.push(eq(triggerInvocations.status, params.filters.status));
|
|
25
|
+
if (params.filters?.from) conditions.push(gte(triggerInvocations.createdAt, params.filters.from));
|
|
26
|
+
if (params.filters?.to) conditions.push(lte(triggerInvocations.createdAt, params.filters.to));
|
|
27
|
+
const whereClause = and(...conditions);
|
|
28
|
+
const [data, totalResult] = await Promise.all([db.select().from(triggerInvocations).where(whereClause).limit(limit).offset(offset).orderBy(desc(triggerInvocations.createdAt)), db.select({ count: count() }).from(triggerInvocations).where(whereClause)]);
|
|
29
|
+
const total = totalResult[0]?.count || 0;
|
|
30
|
+
return {
|
|
31
|
+
data,
|
|
32
|
+
pagination: {
|
|
33
|
+
page,
|
|
34
|
+
limit,
|
|
35
|
+
total,
|
|
36
|
+
pages: Math.ceil(total / limit)
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Create a new trigger invocation (agent-scoped)
|
|
42
|
+
*/
|
|
43
|
+
const createTriggerInvocation = (db) => async (params) => {
|
|
44
|
+
return (await db.insert(triggerInvocations).values(params).returning())[0];
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Update trigger invocation status (agent-scoped)
|
|
48
|
+
*/
|
|
49
|
+
const updateTriggerInvocationStatus = (db) => async (params) => {
|
|
50
|
+
return (await db.update(triggerInvocations).set(params.data).where(and(eq(triggerInvocations.tenantId, params.scopes.tenantId), eq(triggerInvocations.projectId, params.scopes.projectId), eq(triggerInvocations.agentId, params.scopes.agentId), eq(triggerInvocations.triggerId, params.triggerId), eq(triggerInvocations.id, params.invocationId))).returning())[0];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { createTriggerInvocation, getTriggerInvocationById, listTriggerInvocationsPaginated, updateTriggerInvocationStatus };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
2
|
+
import { User } from "../../auth/auth-validation-schemas.js";
|
|
3
|
+
|
|
4
|
+
//#region src/data-access/runtime/users.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* User data access layer
|
|
8
|
+
* All database queries for Better Auth's user table
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Get user by ID
|
|
12
|
+
*/
|
|
13
|
+
declare const getUserById: (db: AgentsRunDatabaseClient) => (userId: string) => Promise<User | null>;
|
|
14
|
+
/**
|
|
15
|
+
* Get user by email
|
|
16
|
+
*/
|
|
17
|
+
declare const getUserByEmail: (db: AgentsRunDatabaseClient) => (email: string) => Promise<User | null>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { getUserByEmail, getUserById };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { user } from "
|
|
1
|
+
import { user } from "../../auth/auth-schema.js";
|
|
2
2
|
import { eq } from "drizzle-orm";
|
|
3
3
|
|
|
4
|
-
//#region src/data-access/users.ts
|
|
4
|
+
//#region src/data-access/runtime/users.ts
|
|
5
5
|
/**
|
|
6
6
|
* User data access layer
|
|
7
7
|
* All database queries for Better Auth's user table
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AgentsManageDatabaseClient } from "../db/manage/manage-client.js";
|
|
2
2
|
|
|
3
3
|
//#region src/data-access/validation.d.ts
|
|
4
4
|
|
|
@@ -6,16 +6,16 @@ import { DatabaseClient } from "../db/client.js";
|
|
|
6
6
|
* Validates that a project exists before performing database operations
|
|
7
7
|
* This provides runtime validation even when foreign key constraints are not enforced
|
|
8
8
|
*/
|
|
9
|
-
declare const validateProjectExists: (db:
|
|
9
|
+
declare const validateProjectExists: (db: AgentsManageDatabaseClient, tenantId: string, projectId: string) => Promise<void>;
|
|
10
10
|
/**
|
|
11
11
|
* Wraps a database operation with project validation
|
|
12
12
|
* Ensures the project exists before executing the operation
|
|
13
13
|
*/
|
|
14
|
-
declare const withProjectValidation: <T extends (...args: any[]) => Promise<any>>(db:
|
|
14
|
+
declare const withProjectValidation: <T extends (...args: any[]) => Promise<any>>(db: AgentsManageDatabaseClient, operation: T) => (params: Parameters<T>[0]) => Promise<ReturnType<T>>;
|
|
15
15
|
/**
|
|
16
16
|
* Creates a validated version of data access functions
|
|
17
17
|
* Automatically adds project validation to insert/update operations
|
|
18
18
|
*/
|
|
19
|
-
declare const createValidatedDataAccess: <T extends Record<string, any>>(db:
|
|
19
|
+
declare const createValidatedDataAccess: <T extends Record<string, any>>(db: AgentsManageDatabaseClient, dataAccessFunctions: T) => T;
|
|
20
20
|
//#endregion
|
|
21
21
|
export { createValidatedDataAccess, validateProjectExists, withProjectValidation };
|
package/dist/db/clean.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { AgentsManageDatabaseClient } from "./manage/manage-client.js";
|
|
2
|
+
import { AgentsRunDatabaseClient } from "./runtime/runtime-client.js";
|
|
3
|
+
|
|
1
4
|
//#region src/db/clean.d.ts
|
|
5
|
+
|
|
2
6
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
7
|
+
* Cleans up test database by removing all data but keeping schema
|
|
8
|
+
* Dynamically gets all tables from the public schema and truncates them
|
|
5
9
|
*/
|
|
6
|
-
declare function
|
|
10
|
+
declare function cleanupDatabase(db: AgentsManageDatabaseClient | AgentsRunDatabaseClient): Promise<void>;
|
|
7
11
|
//#endregion
|
|
8
|
-
export {
|
|
12
|
+
export { cleanupDatabase };
|
package/dist/db/clean.js
CHANGED
|
@@ -1,115 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { env } from "../env.js";
|
|
3
|
-
import { createDatabaseClient } from "./client.js";
|
|
4
|
-
import "../index.js";
|
|
1
|
+
import { sql } from "drizzle-orm";
|
|
5
2
|
|
|
6
3
|
//#region src/db/clean.ts
|
|
7
|
-
const dbClient = createDatabaseClient();
|
|
8
4
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* Cleans up test database by removing all data but keeping schema
|
|
6
|
+
* Dynamically gets all tables from the public schema and truncates them
|
|
11
7
|
*/
|
|
12
|
-
async function
|
|
13
|
-
console.log(`🗑️ Cleaning database for environment: ${env.ENVIRONMENT}`);
|
|
8
|
+
async function cleanupDatabase(db) {
|
|
14
9
|
try {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
table: taskRelations,
|
|
26
|
-
name: "task_relations"
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
table: tasks,
|
|
30
|
-
name: "tasks"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
table: subAgentArtifactComponents,
|
|
34
|
-
name: "agent_artifact_components"
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
table: subAgentDataComponents,
|
|
38
|
-
name: "agent_data_components"
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
table: subAgentToolRelations,
|
|
42
|
-
name: "agent_tool_relations"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
table: subAgentRelations,
|
|
46
|
-
name: "agent_relations"
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
table: agents,
|
|
50
|
-
name: "agent"
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
table: artifactComponents,
|
|
54
|
-
name: "artifact_components"
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
table: dataComponents,
|
|
58
|
-
name: "data_components"
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
table: tools,
|
|
62
|
-
name: "tools"
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
table: subAgents,
|
|
66
|
-
name: "agents"
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
table: externalAgents,
|
|
70
|
-
name: "external_agents"
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
table: ledgerArtifacts,
|
|
74
|
-
name: "ledger_artifacts"
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
table: credentialReferences,
|
|
78
|
-
name: "credential_references"
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
table: contextConfigs,
|
|
82
|
-
name: "context_configs"
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
table: contextCache,
|
|
86
|
-
name: "context_cache"
|
|
87
|
-
}
|
|
88
|
-
];
|
|
89
|
-
for (const { table, name } of tablesToClear) try {
|
|
90
|
-
await dbClient.delete(table);
|
|
91
|
-
console.log(`✅ Cleared table: ${name}`);
|
|
92
|
-
} catch (error) {
|
|
93
|
-
const errorMessage = error?.message || "";
|
|
94
|
-
const causeMessage = error?.cause?.message || "";
|
|
95
|
-
const errorCode = error?.code || error?.cause?.code || "";
|
|
96
|
-
if (errorMessage.includes("no such table") || causeMessage.includes("no such table") || errorMessage.includes("does not exist") || causeMessage.includes("does not exist") || errorCode === "42P01") console.log(`⚠️ Table ${name} doesn't exist, skipping`);
|
|
97
|
-
else throw error;
|
|
98
|
-
}
|
|
99
|
-
console.log("---");
|
|
100
|
-
console.log("🎉 Database cleaned successfully");
|
|
10
|
+
const tables = (await db.execute(sql.raw(`
|
|
11
|
+
SELECT tablename
|
|
12
|
+
FROM pg_tables
|
|
13
|
+
WHERE schemaname = 'public'
|
|
14
|
+
`))).rows.map((row) => row.tablename);
|
|
15
|
+
if (tables.length === 0) return;
|
|
16
|
+
const tableList = tables.map((t) => `"${t}"`).join(", ");
|
|
17
|
+
await db.execute(sql.raw(`TRUNCATE TABLE ${tableList} RESTART IDENTITY CASCADE`));
|
|
101
18
|
} catch (error) {
|
|
102
|
-
console.
|
|
103
|
-
throw error;
|
|
19
|
+
console.debug("Could not clean database:", error);
|
|
104
20
|
}
|
|
105
21
|
}
|
|
106
|
-
if (import.meta.url === new URL(import.meta.url).href) cleanDatabase().then(() => {
|
|
107
|
-
console.log("Database cleanup completed");
|
|
108
|
-
process.exit(0);
|
|
109
|
-
}).catch((error) => {
|
|
110
|
-
console.error("Database cleanup failed:", error);
|
|
111
|
-
process.exit(1);
|
|
112
|
-
});
|
|
113
22
|
|
|
114
23
|
//#endregion
|
|
115
|
-
export {
|
|
24
|
+
export { cleanupDatabase };
|
package/dist/db/delete.d.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
* Drops all tables, sequences, types, and functions from the public schema
|
|
4
4
|
* WARNING: This is destructive and cannot be undone!
|
|
5
5
|
*/
|
|
6
|
-
declare function deleteDatabase(): Promise<void>;
|
|
6
|
+
declare function deleteDatabase(type: 'manage' | 'run'): Promise<void>;
|
|
7
7
|
//#endregion
|
|
8
8
|
export { deleteDatabase };
|
package/dist/db/delete.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { env } from "../env.js";
|
|
2
|
-
import {
|
|
2
|
+
import { createAgentsManageDatabaseClient } from "./manage/manage-client.js";
|
|
3
|
+
import { createAgentsRunDatabaseClient } from "./runtime/runtime-client.js";
|
|
3
4
|
import { sql } from "drizzle-orm";
|
|
4
5
|
|
|
5
6
|
//#region src/db/delete.ts
|
|
@@ -7,11 +8,14 @@ import { sql } from "drizzle-orm";
|
|
|
7
8
|
* Drops all tables, sequences, types, and functions from the public schema
|
|
8
9
|
* WARNING: This is destructive and cannot be undone!
|
|
9
10
|
*/
|
|
10
|
-
async function deleteDatabase() {
|
|
11
|
+
async function deleteDatabase(type) {
|
|
11
12
|
console.log(`🗑️ Deleting all database objects for environment: ${env.ENVIRONMENT}`);
|
|
12
13
|
console.log("---");
|
|
13
|
-
const dbClient =
|
|
14
|
+
const dbClient = type === "manage" ? createAgentsManageDatabaseClient({}) : createAgentsRunDatabaseClient({});
|
|
14
15
|
try {
|
|
16
|
+
console.log("Dropping workflow schema...");
|
|
17
|
+
await dbClient.execute(sql`DROP SCHEMA IF EXISTS workflow CASCADE`);
|
|
18
|
+
console.log("✅ Workflow schema dropped");
|
|
15
19
|
console.log("Dropping public schema and all objects...");
|
|
16
20
|
await dbClient.execute(sql`DROP SCHEMA IF EXISTS public CASCADE`);
|
|
17
21
|
console.log("✅ Public schema dropped");
|
|
@@ -25,13 +29,6 @@ async function deleteDatabase() {
|
|
|
25
29
|
throw error;
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
|
-
if (import.meta.url === new URL(import.meta.url).href) deleteDatabase().then(() => {
|
|
29
|
-
console.log("Database deletion completed");
|
|
30
|
-
process.exit(0);
|
|
31
|
-
}).catch((error) => {
|
|
32
|
-
console.error("Database deletion failed:", error);
|
|
33
|
-
process.exit(1);
|
|
34
|
-
});
|
|
35
32
|
|
|
36
33
|
//#endregion
|
|
37
34
|
export { deleteDatabase };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AgentsManageDatabaseClient } from "./manage-client.js";
|
|
2
|
+
|
|
3
|
+
//#region src/db/manage/dolt-cleanup.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get a database client for cleanup operations
|
|
7
|
+
* Allows passing a custom client or uses a default one
|
|
8
|
+
*/
|
|
9
|
+
declare const getIntegrationTestClient: (db?: AgentsManageDatabaseClient) => AgentsManageDatabaseClient;
|
|
10
|
+
/**
|
|
11
|
+
* Delete all branches matching a prefix pattern
|
|
12
|
+
* Used for cleaning up integration test data
|
|
13
|
+
*/
|
|
14
|
+
declare const cleanupBranchesByPrefix: (prefix: string, db?: AgentsManageDatabaseClient) => Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Delete all tags matching a prefix pattern
|
|
17
|
+
* Used for cleaning up integration test data
|
|
18
|
+
*/
|
|
19
|
+
declare const cleanupTagsByPrefix: (prefix: string, db?: AgentsManageDatabaseClient) => Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Delete specific branches by name
|
|
22
|
+
* Used for cleaning up integration test data
|
|
23
|
+
*/
|
|
24
|
+
declare const cleanupBranches: (branchNames: Set<string>, db?: AgentsManageDatabaseClient) => Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Delete specific tags by name
|
|
27
|
+
* Used for cleaning up integration test data
|
|
28
|
+
*/
|
|
29
|
+
declare const cleanupTags: (tagNames: Set<string>, db?: AgentsManageDatabaseClient) => Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Comprehensive cleanup for test data by prefix
|
|
32
|
+
* Used for cleaning up integration test data
|
|
33
|
+
*/
|
|
34
|
+
declare const cleanupTestData: (prefix: string, branches?: Set<string>, tags?: Set<string>, db?: AgentsManageDatabaseClient) => Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Delete all branches matching a tenant prefix
|
|
37
|
+
* Used for cleaning up integration test data
|
|
38
|
+
*/
|
|
39
|
+
declare const cleanupTenantBranches: (tenantId: string, db?: AgentsManageDatabaseClient) => Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Comprehensive cleanup for a tenant: deletes tags and branches
|
|
42
|
+
* Used for cleaning up integration test data
|
|
43
|
+
*/
|
|
44
|
+
declare const cleanupTenant: (tenantId: string, tagNames?: Set<string>, db?: AgentsManageDatabaseClient) => Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Cleanup multiple tenants
|
|
47
|
+
* Used for cleaning up integration test data
|
|
48
|
+
*/
|
|
49
|
+
declare const cleanupTenants: (tenantIds: Set<string>, tagNames?: Set<string>, db?: AgentsManageDatabaseClient) => Promise<void>;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { cleanupBranches, cleanupBranchesByPrefix, cleanupTags, cleanupTagsByPrefix, cleanupTenant, cleanupTenantBranches, cleanupTenants, cleanupTestData, getIntegrationTestClient };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { loadEnvironmentFiles } from "../../env.js";
|
|
2
|
+
import { createAgentsManageDatabaseClient } from "./manage-client.js";
|
|
3
|
+
import { sql } from "drizzle-orm";
|
|
4
|
+
|
|
5
|
+
//#region src/db/manage/dolt-cleanup.ts
|
|
6
|
+
loadEnvironmentFiles();
|
|
7
|
+
/**
|
|
8
|
+
* Get a database client for cleanup operations
|
|
9
|
+
* Allows passing a custom client or uses a default one
|
|
10
|
+
*/
|
|
11
|
+
const getIntegrationTestClient = (db) => {
|
|
12
|
+
if (db) return db;
|
|
13
|
+
return createAgentsManageDatabaseClient({});
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Delete all branches matching a prefix pattern
|
|
17
|
+
* Used for cleaning up integration test data
|
|
18
|
+
*/
|
|
19
|
+
const cleanupBranchesByPrefix = async (prefix, db) => {
|
|
20
|
+
const dbClient = getIntegrationTestClient(db);
|
|
21
|
+
try {
|
|
22
|
+
const branches = await dbClient.execute(sql.raw(`SELECT name FROM dolt_branches WHERE name LIKE '${prefix}%'`));
|
|
23
|
+
for (const branch of branches.rows) {
|
|
24
|
+
const branchName = branch.name;
|
|
25
|
+
try {
|
|
26
|
+
await dbClient.execute(sql.raw(` DOLT_BRANCH('-D', '${branchName}')`));
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.debug(`Could not delete branch ${branchName}:`, error);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error(`Error cleaning up branches with prefix ${prefix}:`, error);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Delete all tags matching a prefix pattern
|
|
37
|
+
* Used for cleaning up integration test data
|
|
38
|
+
*/
|
|
39
|
+
const cleanupTagsByPrefix = async (prefix, db) => {
|
|
40
|
+
const dbClient = getIntegrationTestClient(db);
|
|
41
|
+
try {
|
|
42
|
+
const tags = await dbClient.execute(sql.raw(`SELECT tag_name FROM dolt_tags WHERE tag_name LIKE '${prefix}%'`));
|
|
43
|
+
for (const tag of tags.rows) {
|
|
44
|
+
const tagName = tag.tag_name;
|
|
45
|
+
try {
|
|
46
|
+
await dbClient.execute(sql.raw(`SELECT DOLT_TAG('-d', '${tagName}')`));
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.debug(`Could not delete tag ${tagName}:`, error);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(`Error cleaning up tags with prefix ${prefix}:`, error);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Delete specific branches by name
|
|
57
|
+
* Used for cleaning up integration test data
|
|
58
|
+
*/
|
|
59
|
+
const cleanupBranches = async (branchNames, db) => {
|
|
60
|
+
const dbClient = getIntegrationTestClient(db);
|
|
61
|
+
for (const branchName of branchNames) try {
|
|
62
|
+
await dbClient.execute(sql.raw(`SELECT DOLT_BRANCH('-D', '${branchName}')`));
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.debug(`Could not delete branch ${branchName}:`, error);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Delete specific tags by name
|
|
69
|
+
* Used for cleaning up integration test data
|
|
70
|
+
*/
|
|
71
|
+
const cleanupTags = async (tagNames, db) => {
|
|
72
|
+
const dbClient = getIntegrationTestClient(db);
|
|
73
|
+
for (const tagName of tagNames) try {
|
|
74
|
+
await dbClient.execute(sql.raw(`SELECT DOLT_TAG('-d', '${tagName}')`));
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.debug(`Could not delete tag ${tagName}:`, error);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Comprehensive cleanup for test data by prefix
|
|
81
|
+
* Used for cleaning up integration test data
|
|
82
|
+
*/
|
|
83
|
+
const cleanupTestData = async (prefix, branches, tags, db) => {
|
|
84
|
+
if (tags && tags.size > 0) await cleanupTags(tags, db);
|
|
85
|
+
await cleanupTagsByPrefix(prefix, db);
|
|
86
|
+
if (branches && branches.size > 0) await cleanupBranches(branches, db);
|
|
87
|
+
await cleanupBranchesByPrefix(prefix, db);
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Delete all branches matching a tenant prefix
|
|
91
|
+
* Used for cleaning up integration test data
|
|
92
|
+
*/
|
|
93
|
+
const cleanupTenantBranches = async (tenantId, db) => {
|
|
94
|
+
const dbClient = getIntegrationTestClient(db);
|
|
95
|
+
try {
|
|
96
|
+
const pattern = `${tenantId}_%`;
|
|
97
|
+
const branches = await dbClient.execute(sql.raw(`SELECT name FROM dolt_branches WHERE name LIKE '${pattern}'`));
|
|
98
|
+
for (const branch of branches.rows) {
|
|
99
|
+
const branchName = branch.name;
|
|
100
|
+
try {
|
|
101
|
+
await dbClient.execute(sql.raw(`SELECT DOLT_BRANCH('-D', '${branchName}')`));
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.debug(`Could not delete branch ${branchName}:`, error);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error(`Error cleaning up branches for tenant ${tenantId}:`, error);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Comprehensive cleanup for a tenant: deletes tags and branches
|
|
112
|
+
* Used for cleaning up integration test data
|
|
113
|
+
*/
|
|
114
|
+
const cleanupTenant = async (tenantId, tagNames, db) => {
|
|
115
|
+
try {
|
|
116
|
+
if (tagNames && tagNames.size > 0) await cleanupTags(tagNames, db);
|
|
117
|
+
await cleanupTenantBranches(tenantId, db);
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.error(`Error cleaning up tenant ${tenantId}:`, error);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Cleanup multiple tenants
|
|
124
|
+
* Used for cleaning up integration test data
|
|
125
|
+
*/
|
|
126
|
+
const cleanupTenants = async (tenantIds, tagNames, db) => {
|
|
127
|
+
if (tagNames && tagNames.size > 0) await cleanupTags(tagNames, db);
|
|
128
|
+
for (const tenantId of tenantIds) await cleanupTenantBranches(tenantId, db);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
//#endregion
|
|
132
|
+
export { cleanupBranches, cleanupBranchesByPrefix, cleanupTags, cleanupTagsByPrefix, cleanupTenant, cleanupTenantBranches, cleanupTenants, cleanupTestData, getIntegrationTestClient };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { manage_schema_d_exports } from "./manage-schema.js";
|
|
2
|
+
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
3
|
+
import { Pool } from "pg";
|
|
4
|
+
import { PgliteDatabase } from "drizzle-orm/pglite";
|
|
5
|
+
|
|
6
|
+
//#region src/db/manage/manage-client.d.ts
|
|
7
|
+
type AgentsManageDatabaseClient = NodePgDatabase<typeof manage_schema_d_exports> | PgliteDatabase<typeof manage_schema_d_exports>;
|
|
8
|
+
interface AgentsManageDatabaseConfig {
|
|
9
|
+
connectionString?: string;
|
|
10
|
+
poolSize?: number;
|
|
11
|
+
ssl?: boolean;
|
|
12
|
+
logger?: {
|
|
13
|
+
logQuery: (query: string, params: unknown[]) => void;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
declare function createAgentsManageDatabasePool(config: AgentsManageDatabaseConfig): Pool;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a PostgreSQL database client with connection pooling
|
|
19
|
+
*/
|
|
20
|
+
declare function createAgentsManageDatabaseClient(config: AgentsManageDatabaseConfig): AgentsManageDatabaseClient;
|
|
21
|
+
declare function createAgentManageDatabaseConnection(config: AgentsManageDatabaseConfig): Promise<{
|
|
22
|
+
db: AgentsManageDatabaseClient;
|
|
23
|
+
release: () => Promise<void>;
|
|
24
|
+
}>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { AgentsManageDatabaseClient, AgentsManageDatabaseConfig, createAgentManageDatabaseConnection, createAgentsManageDatabaseClient, createAgentsManageDatabasePool };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { manage_schema_exports } from "./manage-schema.js";
|
|
2
|
+
import { env, loadEnvironmentFiles } from "../../env.js";
|
|
3
|
+
import { createTestManageDatabaseClientNoMigrations } from "./test-manage-client.js";
|
|
4
|
+
import { drizzle } from "drizzle-orm/node-postgres";
|
|
5
|
+
import { Pool } from "pg";
|
|
6
|
+
|
|
7
|
+
//#region src/db/manage/manage-client.ts
|
|
8
|
+
loadEnvironmentFiles();
|
|
9
|
+
function createAgentsManageDatabasePool(config) {
|
|
10
|
+
const connectionString = config.connectionString || env.INKEEP_AGENTS_MANAGE_DATABASE_URL;
|
|
11
|
+
if (!connectionString) throw new Error("INKEEP_AGENTS_MANAGE_DATABASE_URL environment variable is required. Please set it to your PostgreSQL connection string.");
|
|
12
|
+
const pool = new Pool({
|
|
13
|
+
connectionString,
|
|
14
|
+
max: config.poolSize || Number(env.POSTGRES_POOL_SIZE) || 100
|
|
15
|
+
});
|
|
16
|
+
pool.on("error", (err) => {
|
|
17
|
+
console.error("Unexpected PostgreSQL pool error:", err);
|
|
18
|
+
});
|
|
19
|
+
return pool;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates a PostgreSQL database client with connection pooling
|
|
23
|
+
*/
|
|
24
|
+
function createAgentsManageDatabaseClient(config) {
|
|
25
|
+
const connectionString = config.connectionString || env.INKEEP_AGENTS_MANAGE_DATABASE_URL;
|
|
26
|
+
if (env.ENVIRONMENT === "test") return createTestManageDatabaseClientNoMigrations();
|
|
27
|
+
if (!connectionString) throw new Error("INKEEP_AGENTS_MANAGE_DATABASE_URL environment variable is required. Please set it to your PostgreSQL connection string.");
|
|
28
|
+
const pool = new Pool({
|
|
29
|
+
connectionString,
|
|
30
|
+
max: config.poolSize || Number(env.POSTGRES_POOL_SIZE) || 100
|
|
31
|
+
});
|
|
32
|
+
pool.on("error", (err) => {
|
|
33
|
+
console.error("Unexpected PostgreSQL pool error:", err);
|
|
34
|
+
});
|
|
35
|
+
return drizzle(pool, {
|
|
36
|
+
schema: manage_schema_exports,
|
|
37
|
+
logger: config.logger
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function createAgentManageDatabaseConnection(config) {
|
|
41
|
+
const connectionString = config.connectionString || env.INKEEP_AGENTS_MANAGE_DATABASE_URL;
|
|
42
|
+
if (env.ENVIRONMENT === "test") throw new Error("createAgentManageDatabaseConnection is not supported in test environment");
|
|
43
|
+
if (!connectionString) throw new Error("INKEEP_AGENTS_MANAGE_DATABASE_URL environment variable is required. Please set it to your PostgreSQL connection string.");
|
|
44
|
+
const pool = new Pool({
|
|
45
|
+
connectionString,
|
|
46
|
+
max: 1
|
|
47
|
+
});
|
|
48
|
+
pool.on("error", (err) => {
|
|
49
|
+
console.error("Unexpected PostgreSQL pool error:", err);
|
|
50
|
+
});
|
|
51
|
+
return pool.connect().then((connection) => {
|
|
52
|
+
const db = drizzle(connection, {
|
|
53
|
+
schema: manage_schema_exports,
|
|
54
|
+
logger: config.logger
|
|
55
|
+
});
|
|
56
|
+
const release = async () => {
|
|
57
|
+
connection.release();
|
|
58
|
+
await pool.end();
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
db,
|
|
62
|
+
release
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { createAgentManageDatabaseConnection, createAgentsManageDatabaseClient, createAgentsManageDatabasePool };
|