@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,77 @@
|
|
|
1
|
+
import { AgentScopeConfig, ProjectScopeConfig } from "../../types/utility.js";
|
|
2
|
+
import "../../types/index.js";
|
|
3
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
4
|
+
|
|
5
|
+
//#region src/data-access/runtime/cascade-delete.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Result of a cascade delete operation
|
|
8
|
+
*/
|
|
9
|
+
type CascadeDeleteResult = {
|
|
10
|
+
conversationsDeleted: number;
|
|
11
|
+
tasksDeleted: number;
|
|
12
|
+
contextCacheDeleted: number;
|
|
13
|
+
apiKeysDeleted: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Delete all runtime entities for a specific branch.
|
|
17
|
+
* PostgreSQL cascades handle: messages, taskRelations, ledgerArtifacts
|
|
18
|
+
*
|
|
19
|
+
* @param db - Runtime database client
|
|
20
|
+
* @returns Function that performs the cascade delete
|
|
21
|
+
*/
|
|
22
|
+
declare const cascadeDeleteByBranch: (db: AgentsRunDatabaseClient) => (params: {
|
|
23
|
+
scopes: ProjectScopeConfig;
|
|
24
|
+
fullBranchName: string;
|
|
25
|
+
}) => Promise<CascadeDeleteResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Delete all runtime entities for a project on a specific branch.
|
|
28
|
+
* Used when deleting a project from a branch.
|
|
29
|
+
* PostgreSQL cascades handle: messages, taskRelations, ledgerArtifacts
|
|
30
|
+
*
|
|
31
|
+
* @param db - Runtime database client
|
|
32
|
+
* @returns Function that performs the cascade delete
|
|
33
|
+
*/
|
|
34
|
+
declare const cascadeDeleteByProject: (db: AgentsRunDatabaseClient) => (params: {
|
|
35
|
+
scopes: ProjectScopeConfig;
|
|
36
|
+
fullBranchName: string;
|
|
37
|
+
}) => Promise<CascadeDeleteResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Delete all runtime entities for a specific agent on a specific branch.
|
|
40
|
+
* This includes tasks for the agent and conversations where the agent's
|
|
41
|
+
* subAgents are active.
|
|
42
|
+
*
|
|
43
|
+
* @param db - Runtime database client
|
|
44
|
+
* @returns Function that performs the cascade delete
|
|
45
|
+
*/
|
|
46
|
+
declare const cascadeDeleteByAgent: (db: AgentsRunDatabaseClient) => (params: {
|
|
47
|
+
scopes: AgentScopeConfig;
|
|
48
|
+
fullBranchName: string;
|
|
49
|
+
subAgentIds: string[];
|
|
50
|
+
}) => Promise<CascadeDeleteResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Delete all runtime entities for a specific subAgent on a specific branch.
|
|
53
|
+
*
|
|
54
|
+
* @param db - Runtime database client
|
|
55
|
+
* @returns Function that performs the cascade delete
|
|
56
|
+
*/
|
|
57
|
+
declare const cascadeDeleteBySubAgent: (db: AgentsRunDatabaseClient) => (params: {
|
|
58
|
+
scopes: ProjectScopeConfig;
|
|
59
|
+
subAgentId: string;
|
|
60
|
+
fullBranchName: string;
|
|
61
|
+
}) => Promise<CascadeDeleteResult>;
|
|
62
|
+
/**
|
|
63
|
+
* Delete contextCache entries for a specific contextConfig.
|
|
64
|
+
* Used when deleting a contextConfig from the manage DB.
|
|
65
|
+
*
|
|
66
|
+
* @param db - Runtime database client
|
|
67
|
+
* @returns Function that performs the delete
|
|
68
|
+
*/
|
|
69
|
+
declare const cascadeDeleteByContextConfig: (db: AgentsRunDatabaseClient) => (params: {
|
|
70
|
+
scopes: ProjectScopeConfig;
|
|
71
|
+
contextConfigId: string;
|
|
72
|
+
fullBranchName: string;
|
|
73
|
+
}) => Promise<{
|
|
74
|
+
contextCacheDeleted: number;
|
|
75
|
+
}>;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { CascadeDeleteResult, cascadeDeleteByAgent, cascadeDeleteByBranch, cascadeDeleteByContextConfig, cascadeDeleteByProject, cascadeDeleteBySubAgent };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { apiKeys, contextCache, conversations, tasks } from "../../db/runtime/runtime-schema.js";
|
|
2
|
+
import { and, eq, inArray, sql } from "drizzle-orm";
|
|
3
|
+
|
|
4
|
+
//#region src/data-access/runtime/cascade-delete.ts
|
|
5
|
+
/**
|
|
6
|
+
* Delete all runtime entities for a specific branch.
|
|
7
|
+
* PostgreSQL cascades handle: messages, taskRelations, ledgerArtifacts
|
|
8
|
+
*
|
|
9
|
+
* @param db - Runtime database client
|
|
10
|
+
* @returns Function that performs the cascade delete
|
|
11
|
+
*/
|
|
12
|
+
const cascadeDeleteByBranch = (db) => async (params) => {
|
|
13
|
+
const { scopes, fullBranchName } = params;
|
|
14
|
+
const contextCacheResult = await db.delete(contextCache).where(and(eq(contextCache.tenantId, scopes.tenantId), eq(contextCache.projectId, scopes.projectId), sql`${contextCache.ref}->>'name' = ${fullBranchName}`)).returning();
|
|
15
|
+
const conversationsResult = await db.delete(conversations).where(and(eq(conversations.tenantId, scopes.tenantId), eq(conversations.projectId, scopes.projectId), sql`${conversations.ref}->>'name' = ${fullBranchName}`)).returning();
|
|
16
|
+
const tasksResult = await db.delete(tasks).where(and(eq(tasks.tenantId, scopes.tenantId), eq(tasks.projectId, scopes.projectId), sql`${tasks.ref}->>'name' = ${fullBranchName}`)).returning();
|
|
17
|
+
return {
|
|
18
|
+
conversationsDeleted: conversationsResult.length,
|
|
19
|
+
tasksDeleted: tasksResult.length,
|
|
20
|
+
contextCacheDeleted: contextCacheResult.length,
|
|
21
|
+
apiKeysDeleted: 0
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Delete all runtime entities for a project on a specific branch.
|
|
26
|
+
* Used when deleting a project from a branch.
|
|
27
|
+
* PostgreSQL cascades handle: messages, taskRelations, ledgerArtifacts
|
|
28
|
+
*
|
|
29
|
+
* @param db - Runtime database client
|
|
30
|
+
* @returns Function that performs the cascade delete
|
|
31
|
+
*/
|
|
32
|
+
const cascadeDeleteByProject = (db) => async (params) => {
|
|
33
|
+
const { scopes, fullBranchName } = params;
|
|
34
|
+
const contextCacheResult = await db.delete(contextCache).where(and(eq(contextCache.tenantId, scopes.tenantId), eq(contextCache.projectId, scopes.projectId), sql`${contextCache.ref}->>'name' = ${fullBranchName}`)).returning();
|
|
35
|
+
const conversationsResult = await db.delete(conversations).where(and(eq(conversations.tenantId, scopes.tenantId), eq(conversations.projectId, scopes.projectId), sql`${conversations.ref}->>'name' = ${fullBranchName}`)).returning();
|
|
36
|
+
const tasksResult = await db.delete(tasks).where(and(eq(tasks.tenantId, scopes.tenantId), eq(tasks.projectId, scopes.projectId), sql`${tasks.ref}->>'name' = ${fullBranchName}`)).returning();
|
|
37
|
+
const apiKeysResult = await db.delete(apiKeys).where(and(eq(apiKeys.tenantId, scopes.tenantId), eq(apiKeys.projectId, scopes.projectId))).returning();
|
|
38
|
+
return {
|
|
39
|
+
conversationsDeleted: conversationsResult.length,
|
|
40
|
+
tasksDeleted: tasksResult.length,
|
|
41
|
+
contextCacheDeleted: contextCacheResult.length,
|
|
42
|
+
apiKeysDeleted: apiKeysResult.length
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Delete all runtime entities for a specific agent on a specific branch.
|
|
47
|
+
* This includes tasks for the agent and conversations where the agent's
|
|
48
|
+
* subAgents are active.
|
|
49
|
+
*
|
|
50
|
+
* @param db - Runtime database client
|
|
51
|
+
* @returns Function that performs the cascade delete
|
|
52
|
+
*/
|
|
53
|
+
const cascadeDeleteByAgent = (db) => async (params) => {
|
|
54
|
+
const { scopes, fullBranchName, subAgentIds } = params;
|
|
55
|
+
let contextCacheDeleted = 0;
|
|
56
|
+
let conversationsDeleted = 0;
|
|
57
|
+
let tasksDeleted = 0;
|
|
58
|
+
let apiKeysDeleted = 0;
|
|
59
|
+
if (subAgentIds.length > 0) {
|
|
60
|
+
const conversationIds = (await db.select({ id: conversations.id }).from(conversations).where(and(eq(conversations.tenantId, scopes.tenantId), eq(conversations.projectId, scopes.projectId), inArray(conversations.activeSubAgentId, subAgentIds), sql`${conversations.ref}->>'name' = ${fullBranchName}`))).map((c) => c.id);
|
|
61
|
+
if (conversationIds.length > 0) {
|
|
62
|
+
contextCacheDeleted = (await db.delete(contextCache).where(and(eq(contextCache.tenantId, scopes.tenantId), eq(contextCache.projectId, scopes.projectId), inArray(contextCache.conversationId, conversationIds))).returning()).length;
|
|
63
|
+
conversationsDeleted = (await db.delete(conversations).where(and(eq(conversations.tenantId, scopes.tenantId), eq(conversations.projectId, scopes.projectId), inArray(conversations.id, conversationIds))).returning()).length;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
tasksDeleted = (await db.delete(tasks).where(and(eq(tasks.tenantId, scopes.tenantId), eq(tasks.projectId, scopes.projectId), eq(tasks.agentId, scopes.agentId), sql`${tasks.ref}->>'name' = ${fullBranchName}`)).returning()).length;
|
|
67
|
+
apiKeysDeleted = (await db.delete(apiKeys).where(and(eq(apiKeys.tenantId, scopes.tenantId), eq(apiKeys.projectId, scopes.projectId), eq(apiKeys.agentId, scopes.agentId))).returning()).length;
|
|
68
|
+
return {
|
|
69
|
+
conversationsDeleted,
|
|
70
|
+
tasksDeleted,
|
|
71
|
+
contextCacheDeleted,
|
|
72
|
+
apiKeysDeleted
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Delete all runtime entities for a specific subAgent on a specific branch.
|
|
77
|
+
*
|
|
78
|
+
* @param db - Runtime database client
|
|
79
|
+
* @returns Function that performs the cascade delete
|
|
80
|
+
*/
|
|
81
|
+
const cascadeDeleteBySubAgent = (db) => async (params) => {
|
|
82
|
+
const { scopes, subAgentId, fullBranchName } = params;
|
|
83
|
+
const conversationIds = (await db.select({ id: conversations.id }).from(conversations).where(and(eq(conversations.tenantId, scopes.tenantId), eq(conversations.projectId, scopes.projectId), eq(conversations.activeSubAgentId, subAgentId), sql`${conversations.ref}->>'name' = ${fullBranchName}`))).map((c) => c.id);
|
|
84
|
+
let contextCacheDeleted = 0;
|
|
85
|
+
let conversationsDeleted = 0;
|
|
86
|
+
if (conversationIds.length > 0) {
|
|
87
|
+
contextCacheDeleted = (await db.delete(contextCache).where(and(eq(contextCache.tenantId, scopes.tenantId), eq(contextCache.projectId, scopes.projectId), inArray(contextCache.conversationId, conversationIds))).returning()).length;
|
|
88
|
+
conversationsDeleted = (await db.delete(conversations).where(and(eq(conversations.tenantId, scopes.tenantId), eq(conversations.projectId, scopes.projectId), inArray(conversations.id, conversationIds))).returning()).length;
|
|
89
|
+
}
|
|
90
|
+
const tasksResult = await db.delete(tasks).where(and(eq(tasks.tenantId, scopes.tenantId), eq(tasks.projectId, scopes.projectId), eq(tasks.subAgentId, subAgentId), sql`${tasks.ref}->>'name' = ${fullBranchName}`)).returning();
|
|
91
|
+
return {
|
|
92
|
+
conversationsDeleted,
|
|
93
|
+
tasksDeleted: tasksResult.length,
|
|
94
|
+
contextCacheDeleted,
|
|
95
|
+
apiKeysDeleted: 0
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Delete contextCache entries for a specific contextConfig.
|
|
100
|
+
* Used when deleting a contextConfig from the manage DB.
|
|
101
|
+
*
|
|
102
|
+
* @param db - Runtime database client
|
|
103
|
+
* @returns Function that performs the delete
|
|
104
|
+
*/
|
|
105
|
+
const cascadeDeleteByContextConfig = (db) => async (params) => {
|
|
106
|
+
const { scopes, contextConfigId, fullBranchName } = params;
|
|
107
|
+
return { contextCacheDeleted: (await db.delete(contextCache).where(and(eq(contextCache.tenantId, scopes.tenantId), eq(contextCache.projectId, scopes.projectId), eq(contextCache.contextConfigId, contextConfigId), sql`${contextCache.ref}->>'name' = ${fullBranchName}`)).returning()).length };
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
export { cascadeDeleteByAgent, cascadeDeleteByBranch, cascadeDeleteByContextConfig, cascadeDeleteByProject, cascadeDeleteBySubAgent };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { ProjectScopeConfig } from "../../types/utility.js";
|
|
2
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
3
|
+
import { ContextCacheInsert, ContextCacheSelect } from "../../types/entities.js";
|
|
4
4
|
|
|
5
|
-
//#region src/data-access/contextCache.d.ts
|
|
5
|
+
//#region src/data-access/runtime/contextCache.d.ts
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Get cached context data for a conversation with optional request hash validation
|
|
9
9
|
*/
|
|
10
|
-
declare const getCacheEntry: (db:
|
|
10
|
+
declare const getCacheEntry: (db: AgentsRunDatabaseClient) => (params: {
|
|
11
11
|
conversationId: string;
|
|
12
12
|
contextConfigId: string;
|
|
13
13
|
contextVariableKey: string;
|
|
@@ -16,31 +16,31 @@ declare const getCacheEntry: (db: DatabaseClient) => (params: {
|
|
|
16
16
|
/**
|
|
17
17
|
* Set cached context data for a conversation
|
|
18
18
|
*/
|
|
19
|
-
declare const setCacheEntry: (db:
|
|
19
|
+
declare const setCacheEntry: (db: AgentsRunDatabaseClient) => (entry: ContextCacheInsert) => Promise<ContextCacheSelect | null>;
|
|
20
20
|
/**
|
|
21
21
|
* Clear cache entries for a specific conversation
|
|
22
22
|
*/
|
|
23
|
-
declare const clearConversationCache: (db:
|
|
23
|
+
declare const clearConversationCache: (db: AgentsRunDatabaseClient) => (params: {
|
|
24
24
|
scopes: ProjectScopeConfig;
|
|
25
25
|
conversationId: string;
|
|
26
26
|
}) => Promise<number>;
|
|
27
27
|
/**
|
|
28
28
|
* Clear all cache entries for a specific context configuration
|
|
29
29
|
*/
|
|
30
|
-
declare const clearContextConfigCache: (db:
|
|
30
|
+
declare const clearContextConfigCache: (db: AgentsRunDatabaseClient) => (params: {
|
|
31
31
|
scopes: ProjectScopeConfig;
|
|
32
32
|
contextConfigId: string;
|
|
33
33
|
}) => Promise<number>;
|
|
34
34
|
/**
|
|
35
35
|
* Clean up all cache entries for a tenant
|
|
36
36
|
*/
|
|
37
|
-
declare const cleanupTenantCache: (db:
|
|
37
|
+
declare const cleanupTenantCache: (db: AgentsRunDatabaseClient) => (params: {
|
|
38
38
|
scopes: ProjectScopeConfig;
|
|
39
39
|
}) => Promise<number>;
|
|
40
40
|
/**
|
|
41
41
|
* Invalidate the headers cache for a conversation
|
|
42
42
|
*/
|
|
43
|
-
declare const invalidateHeadersCache: (db:
|
|
43
|
+
declare const invalidateHeadersCache: (db: AgentsRunDatabaseClient) => (params: {
|
|
44
44
|
scopes: ProjectScopeConfig;
|
|
45
45
|
conversationId: string;
|
|
46
46
|
contextConfigId: string;
|
|
@@ -48,7 +48,7 @@ declare const invalidateHeadersCache: (db: DatabaseClient) => (params: {
|
|
|
48
48
|
/**
|
|
49
49
|
* Invalidate specific cache entries for invocation-trigger definitions
|
|
50
50
|
*/
|
|
51
|
-
declare const invalidateInvocationDefinitionsCache: (db:
|
|
51
|
+
declare const invalidateInvocationDefinitionsCache: (db: AgentsRunDatabaseClient) => (params: {
|
|
52
52
|
scopes: ProjectScopeConfig;
|
|
53
53
|
conversationId: string;
|
|
54
54
|
contextConfigId: string;
|
|
@@ -57,14 +57,14 @@ declare const invalidateInvocationDefinitionsCache: (db: DatabaseClient) => (par
|
|
|
57
57
|
/**
|
|
58
58
|
* Get all cache entries for a conversation
|
|
59
59
|
*/
|
|
60
|
-
declare const getConversationCacheEntries: (db:
|
|
60
|
+
declare const getConversationCacheEntries: (db: AgentsRunDatabaseClient) => (params: {
|
|
61
61
|
scopes: ProjectScopeConfig;
|
|
62
62
|
conversationId: string;
|
|
63
63
|
}) => Promise<ContextCacheSelect[]>;
|
|
64
64
|
/**
|
|
65
65
|
* Get all cache entries for a context configuration
|
|
66
66
|
*/
|
|
67
|
-
declare const getContextConfigCacheEntries: (db:
|
|
67
|
+
declare const getContextConfigCacheEntries: (db: AgentsRunDatabaseClient) => (params: {
|
|
68
68
|
scopes: ProjectScopeConfig;
|
|
69
69
|
contextConfigId: string;
|
|
70
70
|
}) => Promise<ContextCacheSelect[]>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { contextCache } from "
|
|
2
|
-
import { generateId } from "
|
|
1
|
+
import { contextCache } from "../../db/runtime/runtime-schema.js";
|
|
2
|
+
import { generateId } from "../../utils/conversations.js";
|
|
3
3
|
import { and, eq } from "drizzle-orm";
|
|
4
4
|
|
|
5
|
-
//#region src/data-access/contextCache.ts
|
|
5
|
+
//#region src/data-access/runtime/contextCache.ts
|
|
6
6
|
/**
|
|
7
7
|
* Get cached context data for a conversation with optional request hash validation
|
|
8
8
|
*/
|
|
@@ -35,9 +35,9 @@ const setCacheEntry = (db) => async (entry) => {
|
|
|
35
35
|
requestHash: entry.requestHash || null,
|
|
36
36
|
fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
37
37
|
fetchSource: `${entry.contextConfigId}:${entry.contextVariableKey}`,
|
|
38
|
-
fetchDurationMs: 0,
|
|
39
38
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
40
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
39
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
40
|
+
ref: entry.ref
|
|
41
41
|
};
|
|
42
42
|
const [result] = await db.insert(contextCache).values(cacheData).returning();
|
|
43
43
|
return {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "
|
|
3
|
-
import "
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
1
|
+
import { ResolvedRef } from "../../validation/dolt-schemas.js";
|
|
2
|
+
import { ConversationHistoryConfig, ConversationMetadata, PaginationConfig, ProjectScopeConfig } from "../../types/utility.js";
|
|
3
|
+
import "../../types/index.js";
|
|
4
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
5
|
+
import "../../index.js";
|
|
6
|
+
import { ConversationInsert, ConversationSelect, ConversationUpdate } from "../../types/entities.js";
|
|
6
7
|
|
|
7
|
-
//#region src/data-access/conversations.d.ts
|
|
8
|
-
declare const listConversations: (db:
|
|
8
|
+
//#region src/data-access/runtime/conversations.d.ts
|
|
9
|
+
declare const listConversations: (db: AgentsRunDatabaseClient) => (params: {
|
|
9
10
|
scopes: ProjectScopeConfig;
|
|
10
11
|
userId?: string;
|
|
11
12
|
pagination?: PaginationConfig;
|
|
@@ -13,19 +14,25 @@ declare const listConversations: (db: DatabaseClient) => (params: {
|
|
|
13
14
|
conversations: ConversationSelect[];
|
|
14
15
|
total: number;
|
|
15
16
|
}>;
|
|
16
|
-
declare const createConversation: (db:
|
|
17
|
-
tenantId: string;
|
|
18
|
-
projectId: string;
|
|
17
|
+
declare const createConversation: (db: AgentsRunDatabaseClient) => (params: ConversationInsert) => Promise<{
|
|
19
18
|
id: string;
|
|
20
|
-
title: string | null;
|
|
21
19
|
createdAt: string;
|
|
22
20
|
updatedAt: string;
|
|
21
|
+
ref: {
|
|
22
|
+
type: "commit" | "tag" | "branch";
|
|
23
|
+
name: string;
|
|
24
|
+
hash: string;
|
|
25
|
+
} | null;
|
|
23
26
|
userId: string | null;
|
|
24
27
|
metadata: ConversationMetadata | null;
|
|
28
|
+
tenantId: string;
|
|
29
|
+
agentId: string | null;
|
|
25
30
|
activeSubAgentId: string;
|
|
31
|
+
title: string | null;
|
|
26
32
|
lastContextResolution: string | null;
|
|
33
|
+
projectId: string;
|
|
27
34
|
}>;
|
|
28
|
-
declare const updateConversation: (db:
|
|
35
|
+
declare const updateConversation: (db: AgentsRunDatabaseClient) => (params: {
|
|
29
36
|
scopes: ProjectScopeConfig;
|
|
30
37
|
conversationId: string;
|
|
31
38
|
data: ConversationUpdate;
|
|
@@ -33,7 +40,13 @@ declare const updateConversation: (db: DatabaseClient) => (params: {
|
|
|
33
40
|
createdAt: string;
|
|
34
41
|
updatedAt: string;
|
|
35
42
|
userId: string | null;
|
|
43
|
+
agentId: string | null;
|
|
36
44
|
activeSubAgentId: string;
|
|
45
|
+
ref: {
|
|
46
|
+
type: "commit" | "tag" | "branch";
|
|
47
|
+
name: string;
|
|
48
|
+
hash: string;
|
|
49
|
+
} | null;
|
|
37
50
|
title: string | null;
|
|
38
51
|
lastContextResolution: string | null;
|
|
39
52
|
metadata: ConversationMetadata | null;
|
|
@@ -41,11 +54,11 @@ declare const updateConversation: (db: DatabaseClient) => (params: {
|
|
|
41
54
|
tenantId: string;
|
|
42
55
|
id: string;
|
|
43
56
|
}>;
|
|
44
|
-
declare const deleteConversation: (db:
|
|
57
|
+
declare const deleteConversation: (db: AgentsRunDatabaseClient) => (params: {
|
|
45
58
|
scopes: ProjectScopeConfig;
|
|
46
59
|
conversationId: string;
|
|
47
60
|
}) => Promise<boolean>;
|
|
48
|
-
declare const
|
|
61
|
+
declare const updateConversationActiveSubAgent: (db: AgentsRunDatabaseClient) => (params: {
|
|
49
62
|
scopes: ProjectScopeConfig;
|
|
50
63
|
conversationId: string;
|
|
51
64
|
activeSubAgentId: string;
|
|
@@ -53,7 +66,13 @@ declare const updateConversationActiveAgent: (db: DatabaseClient) => (params: {
|
|
|
53
66
|
createdAt: string;
|
|
54
67
|
updatedAt: string;
|
|
55
68
|
userId: string | null;
|
|
69
|
+
agentId: string | null;
|
|
56
70
|
activeSubAgentId: string;
|
|
71
|
+
ref: {
|
|
72
|
+
type: "commit" | "tag" | "branch";
|
|
73
|
+
name: string;
|
|
74
|
+
hash: string;
|
|
75
|
+
} | null;
|
|
57
76
|
title: string | null;
|
|
58
77
|
lastContextResolution: string | null;
|
|
59
78
|
metadata: ConversationMetadata | null;
|
|
@@ -61,49 +80,67 @@ declare const updateConversationActiveAgent: (db: DatabaseClient) => (params: {
|
|
|
61
80
|
tenantId: string;
|
|
62
81
|
id: string;
|
|
63
82
|
}>;
|
|
64
|
-
declare const getConversation: (db:
|
|
83
|
+
declare const getConversation: (db: AgentsRunDatabaseClient) => (params: {
|
|
65
84
|
scopes: ProjectScopeConfig;
|
|
66
85
|
conversationId: string;
|
|
67
86
|
}) => Promise<{
|
|
68
|
-
tenantId: string;
|
|
69
|
-
projectId: string;
|
|
70
87
|
id: string;
|
|
71
|
-
title: string | null;
|
|
72
88
|
createdAt: string;
|
|
73
89
|
updatedAt: string;
|
|
90
|
+
ref: {
|
|
91
|
+
type: "commit" | "tag" | "branch";
|
|
92
|
+
name: string;
|
|
93
|
+
hash: string;
|
|
94
|
+
} | null;
|
|
74
95
|
userId: string | null;
|
|
75
96
|
metadata: ConversationMetadata | null;
|
|
97
|
+
tenantId: string;
|
|
98
|
+
agentId: string | null;
|
|
76
99
|
activeSubAgentId: string;
|
|
100
|
+
title: string | null;
|
|
77
101
|
lastContextResolution: string | null;
|
|
102
|
+
projectId: string;
|
|
78
103
|
} | undefined>;
|
|
79
|
-
declare const createOrGetConversation: (db:
|
|
104
|
+
declare const createOrGetConversation: (db: AgentsRunDatabaseClient) => (input: ConversationInsert) => Promise<{
|
|
80
105
|
activeSubAgentId: string;
|
|
81
106
|
projectId: string;
|
|
82
107
|
tenantId: string;
|
|
83
108
|
id: string;
|
|
109
|
+
ref: {
|
|
110
|
+
type: "commit" | "tag" | "branch";
|
|
111
|
+
name: string;
|
|
112
|
+
hash: string;
|
|
113
|
+
};
|
|
84
114
|
createdAt?: string | undefined;
|
|
85
115
|
updatedAt?: string | undefined;
|
|
86
116
|
userId?: string | null | undefined;
|
|
117
|
+
agentId?: string | null | undefined;
|
|
87
118
|
title?: string | null | undefined;
|
|
88
119
|
lastContextResolution?: string | null | undefined;
|
|
89
120
|
metadata?: ConversationMetadata | null | undefined;
|
|
90
121
|
contextConfigId?: string | undefined;
|
|
91
122
|
} | {
|
|
92
|
-
tenantId: string;
|
|
93
|
-
projectId: string;
|
|
94
123
|
id: string;
|
|
95
|
-
title: string | null;
|
|
96
124
|
createdAt: string;
|
|
97
125
|
updatedAt: string;
|
|
126
|
+
ref: {
|
|
127
|
+
type: "commit" | "tag" | "branch";
|
|
128
|
+
name: string;
|
|
129
|
+
hash: string;
|
|
130
|
+
} | null;
|
|
98
131
|
userId: string | null;
|
|
99
132
|
metadata: ConversationMetadata | null;
|
|
133
|
+
tenantId: string;
|
|
134
|
+
agentId: string | null;
|
|
100
135
|
activeSubAgentId: string;
|
|
136
|
+
title: string | null;
|
|
101
137
|
lastContextResolution: string | null;
|
|
138
|
+
projectId: string;
|
|
102
139
|
}>;
|
|
103
140
|
/**
|
|
104
141
|
* Get conversation history with filtering and context management
|
|
105
142
|
*/
|
|
106
|
-
declare const getConversationHistory: (db:
|
|
143
|
+
declare const getConversationHistory: (db: AgentsRunDatabaseClient) => (params: {
|
|
107
144
|
scopes: ProjectScopeConfig;
|
|
108
145
|
conversationId: string;
|
|
109
146
|
options?: ConversationHistoryConfig;
|
|
@@ -111,37 +148,49 @@ declare const getConversationHistory: (db: DatabaseClient) => (params: {
|
|
|
111
148
|
/**
|
|
112
149
|
* Get active agent for a conversation
|
|
113
150
|
*/
|
|
114
|
-
declare const getActiveAgentForConversation: (db:
|
|
151
|
+
declare const getActiveAgentForConversation: (db: AgentsRunDatabaseClient) => (params: {
|
|
115
152
|
scopes: ProjectScopeConfig;
|
|
116
153
|
conversationId: string;
|
|
117
154
|
}) => Promise<{
|
|
118
|
-
tenantId: string;
|
|
119
|
-
projectId: string;
|
|
120
155
|
id: string;
|
|
121
|
-
title: string | null;
|
|
122
156
|
createdAt: string;
|
|
123
157
|
updatedAt: string;
|
|
158
|
+
ref: {
|
|
159
|
+
type: "commit" | "tag" | "branch";
|
|
160
|
+
name: string;
|
|
161
|
+
hash: string;
|
|
162
|
+
} | null;
|
|
124
163
|
userId: string | null;
|
|
125
164
|
metadata: ConversationMetadata | null;
|
|
165
|
+
tenantId: string;
|
|
166
|
+
agentId: string | null;
|
|
126
167
|
activeSubAgentId: string;
|
|
168
|
+
title: string | null;
|
|
127
169
|
lastContextResolution: string | null;
|
|
170
|
+
projectId: string;
|
|
128
171
|
} | undefined>;
|
|
129
172
|
/**
|
|
130
173
|
* Set active agent for a conversation (upsert operation)
|
|
131
174
|
*/
|
|
132
|
-
declare const setActiveAgentForConversation: (db:
|
|
175
|
+
declare const setActiveAgentForConversation: (db: AgentsRunDatabaseClient) => (params: {
|
|
133
176
|
scopes: ProjectScopeConfig;
|
|
134
177
|
conversationId: string;
|
|
135
178
|
subAgentId: string;
|
|
179
|
+
agentId: string;
|
|
180
|
+
ref: ResolvedRef;
|
|
136
181
|
}) => Promise<void>;
|
|
137
|
-
declare const setActiveAgentForThread: (db:
|
|
182
|
+
declare const setActiveAgentForThread: (db: AgentsRunDatabaseClient) => ({
|
|
138
183
|
scopes,
|
|
139
184
|
threadId,
|
|
140
|
-
subAgentId
|
|
185
|
+
subAgentId,
|
|
186
|
+
agentId,
|
|
187
|
+
ref
|
|
141
188
|
}: {
|
|
142
189
|
scopes: ProjectScopeConfig;
|
|
143
190
|
threadId: string;
|
|
144
191
|
subAgentId: string;
|
|
192
|
+
agentId: string;
|
|
193
|
+
ref: ResolvedRef;
|
|
145
194
|
}) => Promise<void>;
|
|
146
195
|
//#endregion
|
|
147
|
-
export { createConversation, createOrGetConversation, deleteConversation, getActiveAgentForConversation, getConversation, getConversationHistory, listConversations, setActiveAgentForConversation, setActiveAgentForThread, updateConversation,
|
|
196
|
+
export { createConversation, createOrGetConversation, deleteConversation, getActiveAgentForConversation, getConversation, getConversationHistory, listConversations, setActiveAgentForConversation, setActiveAgentForThread, updateConversation, updateConversationActiveSubAgent };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { conversations, messages } from "
|
|
2
|
-
import { getConversationId } from "
|
|
1
|
+
import { conversations, messages } from "../../db/runtime/runtime-schema.js";
|
|
2
|
+
import { getConversationId } from "../../utils/conversations.js";
|
|
3
3
|
import { and, count, desc, eq, inArray } from "drizzle-orm";
|
|
4
4
|
|
|
5
|
-
//#region src/data-access/conversations.ts
|
|
5
|
+
//#region src/data-access/runtime/conversations.ts
|
|
6
6
|
const listConversations = (db) => async (params) => {
|
|
7
7
|
const { userId, pagination } = params;
|
|
8
8
|
const page = pagination?.page || 1;
|
|
@@ -44,7 +44,7 @@ const deleteConversation = (db) => async (params) => {
|
|
|
44
44
|
return false;
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
|
-
const
|
|
47
|
+
const updateConversationActiveSubAgent = (db) => async (params) => {
|
|
48
48
|
return updateConversation(db)({
|
|
49
49
|
scopes: params.scopes,
|
|
50
50
|
conversationId: params.conversationId,
|
|
@@ -77,10 +77,12 @@ const createOrGetConversation = (db) => async (input) => {
|
|
|
77
77
|
tenantId: input.tenantId,
|
|
78
78
|
projectId: input.projectId,
|
|
79
79
|
userId: input.userId,
|
|
80
|
+
agentId: input.agentId,
|
|
80
81
|
activeSubAgentId: input.activeSubAgentId,
|
|
81
82
|
title: input.title,
|
|
82
83
|
lastContextResolution: input.lastContextResolution,
|
|
83
84
|
metadata: input.metadata,
|
|
85
|
+
ref: input.ref,
|
|
84
86
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
85
87
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
86
88
|
};
|
|
@@ -158,6 +160,8 @@ const setActiveAgentForConversation = (db) => async (params) => {
|
|
|
158
160
|
tenantId: params.scopes.tenantId,
|
|
159
161
|
projectId: params.scopes.projectId,
|
|
160
162
|
activeSubAgentId: params.subAgentId,
|
|
163
|
+
agentId: params.agentId,
|
|
164
|
+
ref: params.ref,
|
|
161
165
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
162
166
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
163
167
|
}).onConflictDoUpdate({
|
|
@@ -172,13 +176,15 @@ const setActiveAgentForConversation = (db) => async (params) => {
|
|
|
172
176
|
}
|
|
173
177
|
});
|
|
174
178
|
};
|
|
175
|
-
const setActiveAgentForThread = (db) => async ({ scopes, threadId, subAgentId }) => {
|
|
179
|
+
const setActiveAgentForThread = (db) => async ({ scopes, threadId, subAgentId, agentId, ref }) => {
|
|
176
180
|
return setActiveAgentForConversation(db)({
|
|
177
181
|
scopes,
|
|
178
182
|
conversationId: threadId,
|
|
179
|
-
subAgentId
|
|
183
|
+
subAgentId,
|
|
184
|
+
agentId,
|
|
185
|
+
ref
|
|
180
186
|
});
|
|
181
187
|
};
|
|
182
188
|
|
|
183
189
|
//#endregion
|
|
184
|
-
export { createConversation, createOrGetConversation, deleteConversation, getActiveAgentForConversation, getConversation, getConversationHistory, listConversations, setActiveAgentForConversation, setActiveAgentForThread, updateConversation,
|
|
190
|
+
export { createConversation, createOrGetConversation, deleteConversation, getActiveAgentForConversation, getConversation, getConversationHistory, listConversations, setActiveAgentForConversation, setActiveAgentForThread, updateConversation, updateConversationActiveSubAgent };
|