@inkeep/agents-core 0.41.2 → 0.43.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 +60 -2
- package/dist/auth/authz/client.d.ts +87 -0
- package/dist/auth/authz/client.js +196 -0
- package/dist/auth/authz/config.d.ts +103 -0
- package/dist/auth/authz/config.js +93 -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 +53 -0
- package/dist/auth/authz/permissions.js +83 -0
- package/dist/auth/authz/sync.d.ts +106 -0
- package/dist/auth/authz/sync.js +321 -0
- package/dist/auth/permissions.d.ts +13 -13
- package/dist/auth/permissions.js +2 -181
- package/dist/client-exports.d.ts +9 -3
- package/dist/client-exports.js +4 -2
- package/dist/constants/context-breakdown.d.ts +61 -0
- package/dist/constants/context-breakdown.js +124 -0
- package/dist/constants/execution-limits-shared/defaults.d.ts +1 -1
- package/dist/constants/execution-limits-shared/defaults.js +1 -1
- package/dist/constants/execution-limits-shared/index.d.ts +1 -1
- 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.d.ts +0 -6
- package/dist/context/TemplateEngine.js +4 -19
- package/dist/context/index.d.ts +1 -5
- package/dist/context/index.js +1 -5
- package/dist/credential-stores/keychain-store.d.ts +20 -8
- package/dist/credential-stores/keychain-store.js +107 -43
- 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} +209 -7
- package/dist/data-access/{agents.d.ts → manage/agents.d.ts} +64 -63
- package/dist/data-access/{agents.js → manage/agents.js} +80 -27
- package/dist/data-access/{artifactComponents.d.ts → manage/artifactComponents.d.ts} +33 -33
- package/dist/data-access/{artifactComponents.js → manage/artifactComponents.js} +5 -5
- package/dist/data-access/{contextConfigs.d.ts → manage/contextConfigs.d.ts} +26 -26
- 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} +26 -26
- 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/manage/functionTools.d.ts +242 -0
- package/dist/data-access/{functionTools.js → manage/functionTools.js} +124 -30
- 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} +43 -43
- package/dist/data-access/{subAgentExternalAgentRelations.js → manage/subAgentExternalAgentRelations.js} +2 -2
- package/dist/data-access/{subAgentRelations.d.ts → manage/subAgentRelations.d.ts} +65 -65
- package/dist/data-access/{subAgentRelations.js → manage/subAgentRelations.js} +3 -3
- package/dist/data-access/{subAgentTeamAgentRelations.d.ts → manage/subAgentTeamAgentRelations.d.ts} +43 -43
- package/dist/data-access/{subAgentTeamAgentRelations.js → manage/subAgentTeamAgentRelations.js} +2 -2
- package/dist/data-access/{subAgents.d.ts → manage/subAgents.d.ts} +28 -28
- package/dist/data-access/{subAgents.js → manage/subAgents.js} +4 -4
- package/dist/data-access/{tools.d.ts → manage/tools.d.ts} +65 -52
- package/dist/data-access/{tools.js → manage/tools.js} +109 -64
- package/dist/data-access/manage/triggers.d.ts +106 -0
- package/dist/data-access/manage/triggers.js +81 -0
- package/dist/data-access/{apiKeys.d.ts → runtime/apiKeys.d.ts} +37 -37
- 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} +80 -31
- 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} +24 -24
- 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} +16 -4
- 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} +1257 -969
- package/dist/db/{schema.js → manage/manage-schema.js} +436 -334
- 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/db/utils.d.ts +6 -0
- package/dist/db/utils.js +42 -0
- 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 +83 -0
- package/dist/dolt/migrate-dolt.d.ts +1 -0
- package/dist/dolt/migrate-dolt.js +25 -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 +135 -0
- package/dist/dolt/schema-sync.js +255 -0
- package/dist/env.d.ts +6 -4
- package/dist/env.js +3 -2
- package/dist/index.d.ts +73 -46
- package/dist/index.js +76 -49
- package/dist/types/@napi-rs__keyring/index.d.ts +14 -0
- package/dist/types/entities.d.ts +81 -2
- package/dist/types/index.d.ts +3 -3
- package/dist/types/utility.d.ts +46 -5
- package/dist/types/utility.js +2 -1
- package/dist/utils/JsonTransformer.d.ts +42 -0
- package/dist/utils/JsonTransformer.js +103 -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 +8 -4
- package/dist/utils/index.js +8 -4
- package/dist/utils/internal-service-auth.d.ts +79 -0
- package/dist/utils/internal-service-auth.js +140 -0
- package/dist/utils/jmespath-utils.d.ts +152 -0
- package/dist/utils/jmespath-utils.js +213 -0
- package/dist/utils/jwt-helpers.d.ts +56 -0
- package/dist/utils/jwt-helpers.js +90 -0
- package/dist/utils/mcp-client.d.ts +1 -1
- package/dist/utils/mcp-client.js +1 -1
- package/dist/utils/service-token-auth.d.ts +9 -27
- package/dist/utils/service-token-auth.js +48 -96
- package/dist/utils/signature-validation.d.ts +2 -0
- package/dist/utils/signature-validation.js +3 -0
- 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.d.ts +13 -1
- package/dist/utils/third-party-mcp-servers/composio-client.js +47 -29
- package/dist/utils/third-party-mcp-servers/index.d.ts +2 -2
- package/dist/utils/third-party-mcp-servers/index.js +2 -2
- package/dist/utils/trigger-auth.d.ts +85 -0
- package/dist/utils/trigger-auth.js +233 -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 +5 -4
- package/dist/validation/index.js +4 -3
- package/dist/validation/render-validation.js +19 -0
- package/dist/validation/schemas.d.ts +18223 -5148
- package/dist/validation/schemas.js +559 -12
- package/dist/validation/stream-event-schemas.d.ts +96 -1
- package/dist/validation/stream-event-schemas.js +67 -2
- 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/0003_tiny_captain_universe.sql +8 -0
- package/drizzle/manage/0004_curious_phil_sheldon.sql +2 -0
- package/drizzle/manage/0005_silent_shatterstar.sql +53 -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/0003_snapshot.json +3134 -0
- package/drizzle/manage/meta/0004_snapshot.json +3141 -0
- package/drizzle/manage/meta/0005_snapshot.json +3141 -0
- package/drizzle/manage/meta/_journal.json +48 -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 +56 -18
- package/spicedb/schema.zed +114 -0
- 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/functionTools.d.ts +0 -169
- 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,119 @@
|
|
|
1
|
+
import { PaginationConfig, PaginationResult, ProjectModels } from "../../types/utility.js";
|
|
2
|
+
import { AgentsManageDatabaseClient } from "../../db/manage/manage-client.js";
|
|
3
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
4
|
+
import { StopWhen } from "../../validation/schemas.js";
|
|
5
|
+
import { ProjectMetadataSelect } from "../../types/entities.js";
|
|
6
|
+
|
|
7
|
+
//#region src/data-access/manage/projectLifecycle.d.ts
|
|
8
|
+
interface CreateProjectWithBranchParams {
|
|
9
|
+
tenantId: string;
|
|
10
|
+
projectId: string;
|
|
11
|
+
createdBy?: string;
|
|
12
|
+
}
|
|
13
|
+
interface CreateProjectWithBranchResult {
|
|
14
|
+
id: string;
|
|
15
|
+
tenantId: string;
|
|
16
|
+
mainBranchName: string;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
createdBy: string | null;
|
|
19
|
+
}
|
|
20
|
+
interface DeleteProjectWithBranchParams {
|
|
21
|
+
tenantId: string;
|
|
22
|
+
projectId: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Generate the main branch name for a project
|
|
26
|
+
*/
|
|
27
|
+
declare function getProjectMainBranchName(tenantId: string, projectId: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Create a project with its main branch
|
|
30
|
+
*
|
|
31
|
+
* This utility:
|
|
32
|
+
* 1. Creates the project record in the runtime DB (source of truth for existence)
|
|
33
|
+
* 2. Creates the project main branch in the config DB (Doltgres)
|
|
34
|
+
*
|
|
35
|
+
* @param runDb - Runtime database client (Postgres)
|
|
36
|
+
* @param configDb - Config database client (Doltgres)
|
|
37
|
+
*/
|
|
38
|
+
declare const createProjectMetadataAndBranch: (runDb: AgentsRunDatabaseClient, configDb: AgentsManageDatabaseClient) => (params: CreateProjectWithBranchParams) => Promise<CreateProjectWithBranchResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Delete a project and its branch
|
|
41
|
+
*
|
|
42
|
+
* This utility:
|
|
43
|
+
* 1. Gets the project from runtime DB to find the branch name
|
|
44
|
+
* 2. Deletes the project branch from config DB (Doltgres)
|
|
45
|
+
* 3. Deletes the project record from runtime DB
|
|
46
|
+
*
|
|
47
|
+
* Note: Callers should handle cascade deletion of runtime entities (conversations, etc.)
|
|
48
|
+
* before calling this function.
|
|
49
|
+
*
|
|
50
|
+
* @param runDb - Runtime database client (Postgres)
|
|
51
|
+
* @param configDb - Config database client (Doltgres)
|
|
52
|
+
*/
|
|
53
|
+
declare const deleteProjectWithBranch: (runDb: AgentsRunDatabaseClient, configDb: AgentsManageDatabaseClient) => (params: DeleteProjectWithBranchParams) => Promise<boolean>;
|
|
54
|
+
/**
|
|
55
|
+
* Get project with branch info
|
|
56
|
+
*
|
|
57
|
+
* Returns the project from runtime DB including the main branch name
|
|
58
|
+
*/
|
|
59
|
+
declare const getProjectWithBranchInfo: (runDb: AgentsRunDatabaseClient) => (params: {
|
|
60
|
+
tenantId: string;
|
|
61
|
+
projectId: string;
|
|
62
|
+
}) => Promise<ProjectMetadataSelect | null>;
|
|
63
|
+
/**
|
|
64
|
+
* Project metadata from the versioned config DB
|
|
65
|
+
*/
|
|
66
|
+
interface ProjectConfigMetadata {
|
|
67
|
+
name: string;
|
|
68
|
+
description: string | null;
|
|
69
|
+
models: ProjectModels | null;
|
|
70
|
+
stopWhen: StopWhen | null;
|
|
71
|
+
createdAt: string;
|
|
72
|
+
updatedAt: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Combined project data from runtime + config DBs
|
|
76
|
+
*/
|
|
77
|
+
interface ProjectWithMetadata {
|
|
78
|
+
id: string;
|
|
79
|
+
tenantId: string;
|
|
80
|
+
createdAt: string;
|
|
81
|
+
createdBy: string | null;
|
|
82
|
+
mainBranchName: string;
|
|
83
|
+
name: string | null;
|
|
84
|
+
description: string | null;
|
|
85
|
+
models: ProjectModels | null;
|
|
86
|
+
stopWhen: StopWhen | null;
|
|
87
|
+
configUpdatedAt: string | null;
|
|
88
|
+
}
|
|
89
|
+
interface ListProjectsWithMetadataResult {
|
|
90
|
+
data: ProjectWithMetadata[];
|
|
91
|
+
pagination: PaginationResult;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* List projects with metadata from both runtime and config DBs
|
|
95
|
+
*
|
|
96
|
+
* This function:
|
|
97
|
+
* 1. Gets the list of projects from runtime DB (source of truth for existence)
|
|
98
|
+
* 2. For each project, queries the config DB at the project's main branch to get metadata
|
|
99
|
+
*
|
|
100
|
+
* @param runDb - Runtime database client (Postgres)
|
|
101
|
+
* @param configDb - Config database client (Doltgres)
|
|
102
|
+
*/
|
|
103
|
+
declare const listProjectsWithMetadataPaginated: (runDb: AgentsRunDatabaseClient, configDb: AgentsManageDatabaseClient) => (params: {
|
|
104
|
+
tenantId: string;
|
|
105
|
+
pagination?: PaginationConfig;
|
|
106
|
+
projectIds?: string[];
|
|
107
|
+
}) => Promise<ListProjectsWithMetadataResult>;
|
|
108
|
+
/**
|
|
109
|
+
* Get a single project with metadata from both runtime and config DBs
|
|
110
|
+
*
|
|
111
|
+
* @param runDb - Runtime database client (Postgres)
|
|
112
|
+
* @param configDb - Config database client (Doltgres)
|
|
113
|
+
*/
|
|
114
|
+
declare const getProjectWithMetadata: (runDb: AgentsRunDatabaseClient, configDb: AgentsManageDatabaseClient) => (params: {
|
|
115
|
+
tenantId: string;
|
|
116
|
+
projectId: string;
|
|
117
|
+
}) => Promise<ProjectWithMetadata | null>;
|
|
118
|
+
//#endregion
|
|
119
|
+
export { CreateProjectWithBranchParams, CreateProjectWithBranchResult, DeleteProjectWithBranchParams, ListProjectsWithMetadataResult, ProjectConfigMetadata, ProjectWithMetadata, createProjectMetadataAndBranch, deleteProjectWithBranch, getProjectMainBranchName, getProjectWithBranchInfo, getProjectWithMetadata, listProjectsWithMetadataPaginated };
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { getLogger } from "../../utils/logger.js";
|
|
2
|
+
import { doltBranch, doltBranchExists, doltCheckout, doltDeleteBranch } from "../../dolt/branch.js";
|
|
3
|
+
import { createProjectMetadata, deleteProjectMetadata, getProjectMetadata, listProjectsMetadataPaginated } from "../runtime/projects.js";
|
|
4
|
+
import { sql } from "drizzle-orm";
|
|
5
|
+
|
|
6
|
+
//#region src/data-access/manage/projectLifecycle.ts
|
|
7
|
+
const logger = getLogger("project-lifecycle");
|
|
8
|
+
/**
|
|
9
|
+
* Generate the main branch name for a project
|
|
10
|
+
*/
|
|
11
|
+
function getProjectMainBranchName(tenantId, projectId) {
|
|
12
|
+
return `${tenantId}_${projectId}_main`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a project with its main branch
|
|
16
|
+
*
|
|
17
|
+
* This utility:
|
|
18
|
+
* 1. Creates the project record in the runtime DB (source of truth for existence)
|
|
19
|
+
* 2. Creates the project main branch in the config DB (Doltgres)
|
|
20
|
+
*
|
|
21
|
+
* @param runDb - Runtime database client (Postgres)
|
|
22
|
+
* @param configDb - Config database client (Doltgres)
|
|
23
|
+
*/
|
|
24
|
+
const createProjectMetadataAndBranch = (runDb, configDb) => async (params) => {
|
|
25
|
+
const { tenantId, projectId, createdBy } = params;
|
|
26
|
+
const mainBranchName = getProjectMainBranchName(tenantId, projectId);
|
|
27
|
+
logger.info({
|
|
28
|
+
tenantId,
|
|
29
|
+
projectId,
|
|
30
|
+
mainBranchName
|
|
31
|
+
}, "Creating project with branch");
|
|
32
|
+
const runtimeProject = await createProjectMetadata(runDb)({
|
|
33
|
+
id: projectId,
|
|
34
|
+
tenantId,
|
|
35
|
+
createdBy: createdBy ?? null,
|
|
36
|
+
mainBranchName
|
|
37
|
+
});
|
|
38
|
+
logger.debug({ projectId }, "Created project in runtime DB");
|
|
39
|
+
try {
|
|
40
|
+
if (!await doltBranchExists(configDb)({ name: mainBranchName })) {
|
|
41
|
+
await doltBranch(configDb)({ name: mainBranchName });
|
|
42
|
+
logger.debug({ mainBranchName }, "Created project main branch");
|
|
43
|
+
}
|
|
44
|
+
} catch (error) {
|
|
45
|
+
logger.error({
|
|
46
|
+
error,
|
|
47
|
+
mainBranchName
|
|
48
|
+
}, "Failed to create project branch, rolling back");
|
|
49
|
+
await deleteProjectMetadata(runDb)({
|
|
50
|
+
tenantId,
|
|
51
|
+
projectId
|
|
52
|
+
});
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
logger.info({
|
|
56
|
+
tenantId,
|
|
57
|
+
projectId,
|
|
58
|
+
mainBranchName
|
|
59
|
+
}, "Successfully created project with branch");
|
|
60
|
+
return {
|
|
61
|
+
id: runtimeProject.id,
|
|
62
|
+
tenantId: runtimeProject.tenantId,
|
|
63
|
+
mainBranchName: runtimeProject.mainBranchName,
|
|
64
|
+
createdAt: runtimeProject.createdAt,
|
|
65
|
+
createdBy: runtimeProject.createdBy
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Delete a project and its branch
|
|
70
|
+
*
|
|
71
|
+
* This utility:
|
|
72
|
+
* 1. Gets the project from runtime DB to find the branch name
|
|
73
|
+
* 2. Deletes the project branch from config DB (Doltgres)
|
|
74
|
+
* 3. Deletes the project record from runtime DB
|
|
75
|
+
*
|
|
76
|
+
* Note: Callers should handle cascade deletion of runtime entities (conversations, etc.)
|
|
77
|
+
* before calling this function.
|
|
78
|
+
*
|
|
79
|
+
* @param runDb - Runtime database client (Postgres)
|
|
80
|
+
* @param configDb - Config database client (Doltgres)
|
|
81
|
+
*/
|
|
82
|
+
const deleteProjectWithBranch = (runDb, configDb) => async (params) => {
|
|
83
|
+
const { tenantId, projectId } = params;
|
|
84
|
+
logger.info({
|
|
85
|
+
tenantId,
|
|
86
|
+
projectId
|
|
87
|
+
}, "Deleting project with branch");
|
|
88
|
+
const project = await getProjectMetadata(runDb)({
|
|
89
|
+
tenantId,
|
|
90
|
+
projectId
|
|
91
|
+
});
|
|
92
|
+
if (!project) {
|
|
93
|
+
logger.warn({
|
|
94
|
+
tenantId,
|
|
95
|
+
projectId
|
|
96
|
+
}, "Project not found in runtime DB");
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
const { mainBranchName } = project;
|
|
100
|
+
try {
|
|
101
|
+
await doltCheckout(configDb)({ branch: "main" });
|
|
102
|
+
await doltDeleteBranch(configDb)({
|
|
103
|
+
name: mainBranchName,
|
|
104
|
+
force: true
|
|
105
|
+
});
|
|
106
|
+
logger.info({ mainBranchName }, "Deleted project branch");
|
|
107
|
+
} catch (error) {
|
|
108
|
+
logger.error({
|
|
109
|
+
error,
|
|
110
|
+
mainBranchName
|
|
111
|
+
}, "Failed to delete project branch, continuing with runtime cleanup");
|
|
112
|
+
}
|
|
113
|
+
const deleted = await deleteProjectMetadata(runDb)({
|
|
114
|
+
tenantId,
|
|
115
|
+
projectId
|
|
116
|
+
});
|
|
117
|
+
if (deleted) logger.info({
|
|
118
|
+
tenantId,
|
|
119
|
+
projectId,
|
|
120
|
+
mainBranchName
|
|
121
|
+
}, "Successfully deleted project with branch");
|
|
122
|
+
else logger.warn({
|
|
123
|
+
tenantId,
|
|
124
|
+
projectId
|
|
125
|
+
}, "Failed to delete project from runtime DB");
|
|
126
|
+
return deleted;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Get project with branch info
|
|
130
|
+
*
|
|
131
|
+
* Returns the project from runtime DB including the main branch name
|
|
132
|
+
*/
|
|
133
|
+
const getProjectWithBranchInfo = (runDb) => async (params) => {
|
|
134
|
+
return await getProjectMetadata(runDb)(params);
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Get project metadata from config DB at a specific branch using AS OF syntax
|
|
138
|
+
*
|
|
139
|
+
* This queries the projects table without checking out the branch
|
|
140
|
+
*/
|
|
141
|
+
async function getProjectMetadataFromBranch(configDb, branchName, tenantId, projectId) {
|
|
142
|
+
try {
|
|
143
|
+
const result = await configDb.execute(sql.raw(`
|
|
144
|
+
SELECT name, description, models, stop_when, created_at, updated_at
|
|
145
|
+
FROM projects AS OF '${branchName}'
|
|
146
|
+
WHERE tenant_id = '${tenantId}' AND id = '${projectId}'
|
|
147
|
+
LIMIT 1
|
|
148
|
+
`));
|
|
149
|
+
if (result.rows.length === 0) return null;
|
|
150
|
+
const row = result.rows[0];
|
|
151
|
+
return {
|
|
152
|
+
name: row.name,
|
|
153
|
+
description: row.description,
|
|
154
|
+
models: row.models,
|
|
155
|
+
stopWhen: row.stop_when,
|
|
156
|
+
createdAt: row.created_at,
|
|
157
|
+
updatedAt: row.updated_at
|
|
158
|
+
};
|
|
159
|
+
} catch (error) {
|
|
160
|
+
logger.warn({
|
|
161
|
+
error,
|
|
162
|
+
branchName,
|
|
163
|
+
tenantId,
|
|
164
|
+
projectId
|
|
165
|
+
}, "Failed to get project metadata from branch");
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* List projects with metadata from both runtime and config DBs
|
|
171
|
+
*
|
|
172
|
+
* This function:
|
|
173
|
+
* 1. Gets the list of projects from runtime DB (source of truth for existence)
|
|
174
|
+
* 2. For each project, queries the config DB at the project's main branch to get metadata
|
|
175
|
+
*
|
|
176
|
+
* @param runDb - Runtime database client (Postgres)
|
|
177
|
+
* @param configDb - Config database client (Doltgres)
|
|
178
|
+
*/
|
|
179
|
+
const listProjectsWithMetadataPaginated = (runDb, configDb) => async (params) => {
|
|
180
|
+
const { tenantId, pagination, projectIds } = params;
|
|
181
|
+
const projectMetadataResult = await listProjectsMetadataPaginated(runDb)({
|
|
182
|
+
tenantId,
|
|
183
|
+
pagination,
|
|
184
|
+
projectIds
|
|
185
|
+
});
|
|
186
|
+
return {
|
|
187
|
+
data: await Promise.all(projectMetadataResult.data.map(async (projectMetadata) => {
|
|
188
|
+
const metadata = await getProjectMetadataFromBranch(configDb, projectMetadata.mainBranchName, tenantId, projectMetadata.id);
|
|
189
|
+
return {
|
|
190
|
+
id: projectMetadata.id,
|
|
191
|
+
tenantId: projectMetadata.tenantId,
|
|
192
|
+
createdAt: projectMetadata.createdAt,
|
|
193
|
+
createdBy: projectMetadata.createdBy,
|
|
194
|
+
mainBranchName: projectMetadata.mainBranchName,
|
|
195
|
+
name: metadata?.name ?? null,
|
|
196
|
+
description: metadata?.description ?? null,
|
|
197
|
+
models: metadata?.models ?? null,
|
|
198
|
+
stopWhen: metadata?.stopWhen ?? null,
|
|
199
|
+
configUpdatedAt: metadata?.updatedAt ?? null
|
|
200
|
+
};
|
|
201
|
+
})),
|
|
202
|
+
pagination: projectMetadataResult.pagination
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Get a single project with metadata from both runtime and config DBs
|
|
207
|
+
*
|
|
208
|
+
* @param runDb - Runtime database client (Postgres)
|
|
209
|
+
* @param configDb - Config database client (Doltgres)
|
|
210
|
+
*/
|
|
211
|
+
const getProjectWithMetadata = (runDb, configDb) => async (params) => {
|
|
212
|
+
const { tenantId, projectId } = params;
|
|
213
|
+
const runtimeProject = await getProjectMetadata(runDb)({
|
|
214
|
+
tenantId,
|
|
215
|
+
projectId
|
|
216
|
+
});
|
|
217
|
+
if (!runtimeProject) return null;
|
|
218
|
+
const metadata = await getProjectMetadataFromBranch(configDb, runtimeProject.mainBranchName, tenantId, projectId);
|
|
219
|
+
return {
|
|
220
|
+
id: runtimeProject.id,
|
|
221
|
+
tenantId: runtimeProject.tenantId,
|
|
222
|
+
createdAt: runtimeProject.createdAt,
|
|
223
|
+
createdBy: runtimeProject.createdBy,
|
|
224
|
+
mainBranchName: runtimeProject.mainBranchName,
|
|
225
|
+
name: metadata?.name ?? null,
|
|
226
|
+
description: metadata?.description ?? null,
|
|
227
|
+
models: metadata?.models ?? null,
|
|
228
|
+
stopWhen: metadata?.stopWhen ?? null,
|
|
229
|
+
configUpdatedAt: metadata?.updatedAt ?? null
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
//#endregion
|
|
234
|
+
export { createProjectMetadataAndBranch, deleteProjectWithBranch, getProjectMainBranchName, getProjectWithBranchInfo, getProjectWithMetadata, listProjectsWithMetadataPaginated };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { PaginationConfig, PaginationResult, ProjectInfo, ProjectResourceCounts, ProjectScopeConfig } from "../../types/utility.js";
|
|
2
|
+
import { AgentsManageDatabaseClient } from "../../db/manage/manage-client.js";
|
|
3
|
+
import { ProjectInsert, ProjectSelect, ProjectUpdate } from "../../types/entities.js";
|
|
4
|
+
|
|
5
|
+
//#region src/data-access/manage/projects.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* List all unique project IDs within a tenant by scanning all resource tables
|
|
9
|
+
* @param projectIds - Optional array of project IDs to filter by. If undefined, returns all projects.
|
|
10
|
+
*/
|
|
11
|
+
declare const listProjects: (db: AgentsManageDatabaseClient) => (params: {
|
|
12
|
+
tenantId: string;
|
|
13
|
+
projectIds?: string[];
|
|
14
|
+
}) => Promise<ProjectInfo[]>;
|
|
15
|
+
/**
|
|
16
|
+
* List all unique project IDs within a tenant with pagination
|
|
17
|
+
* Optionally filter by a list of project IDs (for access control)
|
|
18
|
+
*/
|
|
19
|
+
declare const listProjectsPaginated: (db: AgentsManageDatabaseClient) => (params: {
|
|
20
|
+
tenantId: string;
|
|
21
|
+
pagination?: PaginationConfig;
|
|
22
|
+
projectIds?: string[];
|
|
23
|
+
}) => Promise<{
|
|
24
|
+
data: ProjectSelect[];
|
|
25
|
+
pagination: PaginationResult;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Get resource counts for a specific project
|
|
29
|
+
*/
|
|
30
|
+
declare const getProjectResourceCounts: (db: AgentsManageDatabaseClient) => (params: ProjectScopeConfig) => Promise<ProjectResourceCounts>;
|
|
31
|
+
/**
|
|
32
|
+
* Check if a project exists (has any resources)
|
|
33
|
+
*/
|
|
34
|
+
declare const projectExists: (db: AgentsManageDatabaseClient) => (params: ProjectScopeConfig) => Promise<boolean>;
|
|
35
|
+
/**
|
|
36
|
+
* Count total projects for a tenant
|
|
37
|
+
*/
|
|
38
|
+
declare const countProjects: (db: AgentsManageDatabaseClient) => (params: {
|
|
39
|
+
tenantId: string;
|
|
40
|
+
}) => Promise<number>;
|
|
41
|
+
/**
|
|
42
|
+
* Get a single project by ID
|
|
43
|
+
*/
|
|
44
|
+
declare const getProject: (db: AgentsManageDatabaseClient) => (params: {
|
|
45
|
+
scopes: ProjectScopeConfig;
|
|
46
|
+
}) => Promise<ProjectSelect | null>;
|
|
47
|
+
/**
|
|
48
|
+
* Create a new project
|
|
49
|
+
*/
|
|
50
|
+
declare const createProject: (db: AgentsManageDatabaseClient) => (params: ProjectInsert) => Promise<ProjectSelect>;
|
|
51
|
+
/**
|
|
52
|
+
* Update an existing project
|
|
53
|
+
*/
|
|
54
|
+
declare const updateProject: (db: AgentsManageDatabaseClient) => (params: {
|
|
55
|
+
scopes: ProjectScopeConfig;
|
|
56
|
+
data: ProjectUpdate;
|
|
57
|
+
}) => Promise<ProjectSelect | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Check if a project exists in the projects table
|
|
60
|
+
*/
|
|
61
|
+
declare const projectExistsInTable: (db: AgentsManageDatabaseClient) => (params: {
|
|
62
|
+
scopes: ProjectScopeConfig;
|
|
63
|
+
}) => Promise<boolean>;
|
|
64
|
+
/**
|
|
65
|
+
* Check if a project has any resources (used before deletion)
|
|
66
|
+
*/
|
|
67
|
+
declare const projectHasResources: (db: AgentsManageDatabaseClient) => (params: ProjectScopeConfig) => Promise<boolean>;
|
|
68
|
+
/**
|
|
69
|
+
* Delete a project (with validation for existing resources)
|
|
70
|
+
*/
|
|
71
|
+
declare const deleteProject: (db: AgentsManageDatabaseClient) => (params: {
|
|
72
|
+
scopes: ProjectScopeConfig;
|
|
73
|
+
}) => Promise<boolean>;
|
|
74
|
+
//#endregion
|
|
75
|
+
export { countProjects, createProject, deleteProject, getProject, getProjectResourceCounts, listProjects, listProjectsPaginated, projectExists, projectExistsInTable, projectHasResources, updateProject };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { agents, artifactComponents,
|
|
2
|
-
import { and, count, desc, eq } from "drizzle-orm";
|
|
1
|
+
import { agents, artifactComponents, contextConfigs, credentialReferences, dataComponents, externalAgents, projects, subAgentArtifactComponents, subAgentDataComponents, subAgentRelations, subAgentToolRelations, subAgents, tools } from "../../db/manage/manage-schema.js";
|
|
2
|
+
import { and, count, desc, eq, inArray } from "drizzle-orm";
|
|
3
3
|
|
|
4
|
-
//#region src/data-access/projects.ts
|
|
4
|
+
//#region src/data-access/manage/projects.ts
|
|
5
5
|
/**
|
|
6
6
|
* List all unique project IDs within a tenant by scanning all resource tables
|
|
7
|
+
* @param projectIds - Optional array of project IDs to filter by. If undefined, returns all projects.
|
|
7
8
|
*/
|
|
8
9
|
const listProjects = (db) => async (params) => {
|
|
9
|
-
|
|
10
|
+
if (params.projectIds !== void 0 && params.projectIds.length === 0) return [];
|
|
11
|
+
const whereClause = params.projectIds ? and(eq(projects.tenantId, params.tenantId), inArray(projects.id, params.projectIds)) : eq(projects.tenantId, params.tenantId);
|
|
12
|
+
const projectsFromTable = await db.select({ projectId: projects.id }).from(projects).where(whereClause);
|
|
10
13
|
if (projectsFromTable.length > 0) return projectsFromTable.map((p) => ({ projectId: p.projectId }));
|
|
11
14
|
const projectIdSets = await Promise.all([
|
|
12
15
|
db.selectDistinct({ projectId: subAgents.projectId }).from(subAgents).where(eq(subAgents.tenantId, params.tenantId)),
|
|
@@ -20,30 +23,28 @@ const listProjects = (db) => async (params) => {
|
|
|
20
23
|
db.selectDistinct({ projectId: subAgentArtifactComponents.projectId }).from(subAgentArtifactComponents).where(eq(subAgentArtifactComponents.tenantId, params.tenantId)),
|
|
21
24
|
db.selectDistinct({ projectId: dataComponents.projectId }).from(dataComponents).where(eq(dataComponents.tenantId, params.tenantId)),
|
|
22
25
|
db.selectDistinct({ projectId: artifactComponents.projectId }).from(artifactComponents).where(eq(artifactComponents.tenantId, params.tenantId)),
|
|
23
|
-
db.selectDistinct({ projectId:
|
|
24
|
-
db.selectDistinct({ projectId: taskRelations.projectId }).from(taskRelations).where(eq(taskRelations.tenantId, params.tenantId)),
|
|
25
|
-
db.selectDistinct({ projectId: conversations.projectId }).from(conversations).where(eq(conversations.tenantId, params.tenantId)),
|
|
26
|
-
db.selectDistinct({ projectId: messages.projectId }).from(messages).where(eq(messages.tenantId, params.tenantId)),
|
|
27
|
-
db.selectDistinct({ projectId: contextCache.projectId }).from(contextCache).where(eq(contextCache.tenantId, params.tenantId)),
|
|
28
|
-
db.selectDistinct({ projectId: credentialReferences.projectId }).from(credentialReferences).where(eq(credentialReferences.tenantId, params.tenantId)),
|
|
29
|
-
db.selectDistinct({ projectId: ledgerArtifacts.projectId }).from(ledgerArtifacts).where(eq(ledgerArtifacts.tenantId, params.tenantId))
|
|
26
|
+
db.selectDistinct({ projectId: credentialReferences.projectId }).from(credentialReferences).where(eq(credentialReferences.tenantId, params.tenantId))
|
|
30
27
|
]);
|
|
31
28
|
const allProjectIds = /* @__PURE__ */ new Set();
|
|
32
29
|
projectIdSets.forEach((results) => {
|
|
33
30
|
results.forEach((row) => {
|
|
34
|
-
if (row.projectId)
|
|
31
|
+
if (row.projectId) {
|
|
32
|
+
if (!params.projectIds || params.projectIds.includes(row.projectId)) allProjectIds.add(row.projectId);
|
|
33
|
+
}
|
|
35
34
|
});
|
|
36
35
|
});
|
|
37
36
|
return Array.from(allProjectIds).sort().map((projectId) => ({ projectId }));
|
|
38
37
|
};
|
|
39
38
|
/**
|
|
40
39
|
* List all unique project IDs within a tenant with pagination
|
|
40
|
+
* Optionally filter by a list of project IDs (for access control)
|
|
41
41
|
*/
|
|
42
42
|
const listProjectsPaginated = (db) => async (params) => {
|
|
43
43
|
const page = params.pagination?.page || 1;
|
|
44
44
|
const limit = params.pagination?.limit || 10;
|
|
45
45
|
const offset = (page - 1) * limit;
|
|
46
|
-
const
|
|
46
|
+
const whereClause = params.projectIds ? and(eq(projects.tenantId, params.tenantId), inArray(projects.id, params.projectIds)) : eq(projects.tenantId, params.tenantId);
|
|
47
|
+
const [data, totalResult] = await Promise.all([db.select().from(projects).where(whereClause).limit(limit).offset(offset).orderBy(desc(projects.createdAt)), db.select({ count: count() }).from(projects).where(whereClause)]);
|
|
47
48
|
const total = totalResult[0]?.count || 0;
|
|
48
49
|
return {
|
|
49
50
|
data,
|
|
@@ -85,9 +86,7 @@ const projectExists = (db) => async (params) => {
|
|
|
85
86
|
db.select({ id: agents.id }).from(agents).where(whereClause(agents)).limit(1),
|
|
86
87
|
db.select({ id: tools.id }).from(tools).where(whereClause(tools)).limit(1),
|
|
87
88
|
db.select({ id: contextConfigs.id }).from(contextConfigs).where(whereClause(contextConfigs)).limit(1),
|
|
88
|
-
db.select({ id: externalAgents.id }).from(externalAgents).where(whereClause(externalAgents)).limit(1)
|
|
89
|
-
db.select({ id: tasks.id }).from(tasks).where(whereClause(tasks)).limit(1),
|
|
90
|
-
db.select({ id: conversations.id }).from(conversations).where(whereClause(conversations)).limit(1)
|
|
89
|
+
db.select({ id: externalAgents.id }).from(externalAgents).where(whereClause(externalAgents)).limit(1)
|
|
91
90
|
];
|
|
92
91
|
return (await Promise.all(checks)).some((result) => result.length > 0);
|
|
93
92
|
};
|