@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,168 @@
|
|
|
1
|
+
import { conversations, datasetRun, datasetRunConversationRelations, evaluationResult, evaluationRun } from "../../db/runtime/runtime-schema.js";
|
|
2
|
+
import { and, desc, eq, gte, inArray, lte } from "drizzle-orm";
|
|
3
|
+
|
|
4
|
+
//#region src/data-access/runtime/evalRuns.ts
|
|
5
|
+
const getDatasetRunById = (db) => async (params) => {
|
|
6
|
+
return (await db.select().from(datasetRun).where(and(eq(datasetRun.tenantId, params.scopes.tenantId), eq(datasetRun.projectId, params.scopes.projectId), eq(datasetRun.id, params.scopes.datasetRunId))).limit(1))[0] ?? null;
|
|
7
|
+
};
|
|
8
|
+
const listDatasetRuns = (db) => async (params) => {
|
|
9
|
+
return await db.select().from(datasetRun).where(and(eq(datasetRun.tenantId, params.scopes.tenantId), eq(datasetRun.projectId, params.scopes.projectId))).orderBy(desc(datasetRun.createdAt));
|
|
10
|
+
};
|
|
11
|
+
const listDatasetRunsByConfig = (db) => async (params) => {
|
|
12
|
+
return await db.select().from(datasetRun).where(and(eq(datasetRun.tenantId, params.scopes.tenantId), eq(datasetRun.projectId, params.scopes.projectId), eq(datasetRun.datasetRunConfigId, params.scopes.datasetRunConfigId))).orderBy(desc(datasetRun.createdAt));
|
|
13
|
+
};
|
|
14
|
+
const createDatasetRun = (db) => async (data) => {
|
|
15
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
16
|
+
const [created] = await db.insert(datasetRun).values({
|
|
17
|
+
...data,
|
|
18
|
+
createdAt: now,
|
|
19
|
+
updatedAt: now
|
|
20
|
+
}).returning();
|
|
21
|
+
return created;
|
|
22
|
+
};
|
|
23
|
+
const deleteDatasetRun = (db) => async (params) => {
|
|
24
|
+
return (await db.delete(datasetRun).where(and(eq(datasetRun.tenantId, params.scopes.tenantId), eq(datasetRun.projectId, params.scopes.projectId), eq(datasetRun.id, params.scopes.datasetRunId))).returning()).length > 0;
|
|
25
|
+
};
|
|
26
|
+
const getDatasetRunConversationRelations = (db) => async (params) => {
|
|
27
|
+
return await db.select().from(datasetRunConversationRelations).where(and(eq(datasetRunConversationRelations.tenantId, params.scopes.tenantId), eq(datasetRunConversationRelations.projectId, params.scopes.projectId), eq(datasetRunConversationRelations.datasetRunId, params.scopes.datasetRunId)));
|
|
28
|
+
};
|
|
29
|
+
const createDatasetRunConversationRelation = (db) => async (data) => {
|
|
30
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
31
|
+
const [created] = await db.insert(datasetRunConversationRelations).values({
|
|
32
|
+
...data,
|
|
33
|
+
createdAt: now,
|
|
34
|
+
updatedAt: now
|
|
35
|
+
}).returning();
|
|
36
|
+
return created;
|
|
37
|
+
};
|
|
38
|
+
const createDatasetRunConversationRelations = (db) => async (data) => {
|
|
39
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
40
|
+
const values = data.map((item) => ({
|
|
41
|
+
...item,
|
|
42
|
+
createdAt: now,
|
|
43
|
+
updatedAt: now
|
|
44
|
+
}));
|
|
45
|
+
return await db.insert(datasetRunConversationRelations).values(values).returning();
|
|
46
|
+
};
|
|
47
|
+
const deleteDatasetRunConversationRelation = (db) => async (params) => {
|
|
48
|
+
return (await db.delete(datasetRunConversationRelations).where(and(eq(datasetRunConversationRelations.tenantId, params.scopes.tenantId), eq(datasetRunConversationRelations.projectId, params.scopes.projectId), eq(datasetRunConversationRelations.datasetRunId, params.scopes.datasetRunId), eq(datasetRunConversationRelations.conversationId, params.scopes.conversationId))).returning()).length > 0;
|
|
49
|
+
};
|
|
50
|
+
const deleteDatasetRunConversationRelationsByRun = (db) => async (params) => {
|
|
51
|
+
return (await db.delete(datasetRunConversationRelations).where(and(eq(datasetRunConversationRelations.tenantId, params.scopes.tenantId), eq(datasetRunConversationRelations.projectId, params.scopes.projectId), eq(datasetRunConversationRelations.datasetRunId, params.scopes.datasetRunId))).returning()).length;
|
|
52
|
+
};
|
|
53
|
+
const getDatasetRunConversationRelationByConversation = (db) => async (params) => {
|
|
54
|
+
return (await db.select().from(datasetRunConversationRelations).where(and(eq(datasetRunConversationRelations.tenantId, params.scopes.tenantId), eq(datasetRunConversationRelations.projectId, params.scopes.projectId), eq(datasetRunConversationRelations.conversationId, params.scopes.conversationId))).limit(1))[0] || null;
|
|
55
|
+
};
|
|
56
|
+
const getEvaluationRunById = (db) => async (params) => {
|
|
57
|
+
return (await db.select().from(evaluationRun).where(and(eq(evaluationRun.tenantId, params.scopes.tenantId), eq(evaluationRun.projectId, params.scopes.projectId), eq(evaluationRun.id, params.scopes.evaluationRunId))).limit(1))[0] ?? null;
|
|
58
|
+
};
|
|
59
|
+
const listEvaluationRuns = (db) => async (params) => {
|
|
60
|
+
return await db.select().from(evaluationRun).where(and(eq(evaluationRun.tenantId, params.scopes.tenantId), eq(evaluationRun.projectId, params.scopes.projectId)));
|
|
61
|
+
};
|
|
62
|
+
const listEvaluationRunsByJobConfigId = (db) => async (params) => {
|
|
63
|
+
return await db.select().from(evaluationRun).where(and(eq(evaluationRun.tenantId, params.scopes.tenantId), eq(evaluationRun.projectId, params.scopes.projectId), eq(evaluationRun.evaluationJobConfigId, params.evaluationJobConfigId)));
|
|
64
|
+
};
|
|
65
|
+
const getEvaluationRunByJobConfigId = (db) => async (params) => {
|
|
66
|
+
return (await db.select().from(evaluationRun).where(and(eq(evaluationRun.tenantId, params.scopes.tenantId), eq(evaluationRun.projectId, params.scopes.projectId), eq(evaluationRun.evaluationJobConfigId, params.evaluationJobConfigId))).limit(1))[0] ?? null;
|
|
67
|
+
};
|
|
68
|
+
const createEvaluationRun = (db) => async (data) => {
|
|
69
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
70
|
+
const [created] = await db.insert(evaluationRun).values({
|
|
71
|
+
...data,
|
|
72
|
+
createdAt: now,
|
|
73
|
+
updatedAt: now
|
|
74
|
+
}).returning();
|
|
75
|
+
return created;
|
|
76
|
+
};
|
|
77
|
+
const updateEvaluationRun = (db) => async (params) => {
|
|
78
|
+
const updateData = { updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
79
|
+
for (const [key, value] of Object.entries(params.data)) if (value !== void 0) updateData[key] = value;
|
|
80
|
+
const [updated] = await db.update(evaluationRun).set(updateData).where(and(eq(evaluationRun.tenantId, params.scopes.tenantId), eq(evaluationRun.projectId, params.scopes.projectId), eq(evaluationRun.id, params.scopes.evaluationRunId))).returning();
|
|
81
|
+
return updated ?? null;
|
|
82
|
+
};
|
|
83
|
+
const deleteEvaluationRun = (db) => async (params) => {
|
|
84
|
+
return (await db.delete(evaluationRun).where(and(eq(evaluationRun.tenantId, params.scopes.tenantId), eq(evaluationRun.projectId, params.scopes.projectId), eq(evaluationRun.id, params.scopes.evaluationRunId))).returning()).length > 0;
|
|
85
|
+
};
|
|
86
|
+
const getEvaluationResultById = (db) => async (params) => {
|
|
87
|
+
return await db.query.evaluationResult.findFirst({ where: and(eq(evaluationResult.tenantId, params.scopes.tenantId), eq(evaluationResult.projectId, params.scopes.projectId), eq(evaluationResult.id, params.scopes.evaluationResultId)) }) ?? null;
|
|
88
|
+
};
|
|
89
|
+
const listEvaluationResults = (db) => async (params) => {
|
|
90
|
+
return await db.query.evaluationResult.findMany({ where: and(eq(evaluationResult.tenantId, params.scopes.tenantId), eq(evaluationResult.projectId, params.scopes.projectId)) });
|
|
91
|
+
};
|
|
92
|
+
const listEvaluationResultsByRun = (db) => async (params) => {
|
|
93
|
+
return await db.query.evaluationResult.findMany({ where: and(eq(evaluationResult.tenantId, params.scopes.tenantId), eq(evaluationResult.projectId, params.scopes.projectId), eq(evaluationResult.evaluationRunId, params.scopes.evaluationRunId)) });
|
|
94
|
+
};
|
|
95
|
+
const listEvaluationResultsByConversation = (db) => async (params) => {
|
|
96
|
+
return await db.query.evaluationResult.findMany({ where: and(eq(evaluationResult.tenantId, params.scopes.tenantId), eq(evaluationResult.projectId, params.scopes.projectId), eq(evaluationResult.conversationId, params.scopes.conversationId)) });
|
|
97
|
+
};
|
|
98
|
+
const createEvaluationResult = (db) => async (data) => {
|
|
99
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
100
|
+
const [created] = await db.insert(evaluationResult).values({
|
|
101
|
+
...data,
|
|
102
|
+
createdAt: now,
|
|
103
|
+
updatedAt: now
|
|
104
|
+
}).returning();
|
|
105
|
+
return created;
|
|
106
|
+
};
|
|
107
|
+
const createEvaluationResults = (db) => async (data) => {
|
|
108
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
109
|
+
const values = data.map((item) => ({
|
|
110
|
+
...item,
|
|
111
|
+
createdAt: now,
|
|
112
|
+
updatedAt: now
|
|
113
|
+
}));
|
|
114
|
+
return await db.insert(evaluationResult).values(values).returning();
|
|
115
|
+
};
|
|
116
|
+
const updateEvaluationResult = (db) => async (params) => {
|
|
117
|
+
const updateData = { updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
118
|
+
for (const [key, value] of Object.entries(params.data)) if (value !== void 0) updateData[key] = value;
|
|
119
|
+
const [updated] = await db.update(evaluationResult).set(updateData).where(and(eq(evaluationResult.tenantId, params.scopes.tenantId), eq(evaluationResult.projectId, params.scopes.projectId), eq(evaluationResult.id, params.scopes.evaluationResultId))).returning();
|
|
120
|
+
return updated ?? null;
|
|
121
|
+
};
|
|
122
|
+
const deleteEvaluationResult = (db) => async (params) => {
|
|
123
|
+
return (await db.delete(evaluationResult).where(and(eq(evaluationResult.tenantId, params.scopes.tenantId), eq(evaluationResult.projectId, params.scopes.projectId), eq(evaluationResult.id, params.scopes.evaluationResultId))).returning()).length > 0;
|
|
124
|
+
};
|
|
125
|
+
const deleteEvaluationResultsByRun = (db) => async (params) => {
|
|
126
|
+
return (await db.delete(evaluationResult).where(and(eq(evaluationResult.tenantId, params.scopes.tenantId), eq(evaluationResult.projectId, params.scopes.projectId), eq(evaluationResult.evaluationRunId, params.scopes.evaluationRunId))).returning()).length;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Helper to extract plain filter criteria from a Filter wrapper.
|
|
130
|
+
* Currently only handles plain objects - and/or combinators are not yet supported.
|
|
131
|
+
*/
|
|
132
|
+
function extractPlainFilterCriteria(filter) {
|
|
133
|
+
if (!filter) return null;
|
|
134
|
+
if ("and" in filter || "or" in filter) return null;
|
|
135
|
+
return filter;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Filter conversations based on evaluation job filter criteria
|
|
139
|
+
*/
|
|
140
|
+
const filterConversationsForJob = (db) => async (params) => {
|
|
141
|
+
const { scopes, jobFilters: rawJobFilters } = params;
|
|
142
|
+
const jobFilters = extractPlainFilterCriteria(rawJobFilters);
|
|
143
|
+
const { tenantId, projectId } = scopes;
|
|
144
|
+
const whereConditions = [eq(conversations.tenantId, tenantId), eq(conversations.projectId, projectId)];
|
|
145
|
+
if (jobFilters?.conversationIds && Array.isArray(jobFilters.conversationIds) && jobFilters.conversationIds.length > 0) whereConditions.push(inArray(conversations.id, jobFilters.conversationIds));
|
|
146
|
+
if (jobFilters?.dateRange) {
|
|
147
|
+
const { startDate, endDate } = jobFilters.dateRange;
|
|
148
|
+
if (startDate) whereConditions.push(gte(conversations.createdAt, startDate));
|
|
149
|
+
if (endDate) whereConditions.push(lte(conversations.createdAt, endDate));
|
|
150
|
+
}
|
|
151
|
+
if (jobFilters?.datasetRunIds && Array.isArray(jobFilters.datasetRunIds) && jobFilters.datasetRunIds.length > 0) {
|
|
152
|
+
const allConversationIds = /* @__PURE__ */ new Set();
|
|
153
|
+
for (const datasetRunId of jobFilters.datasetRunIds) {
|
|
154
|
+
const relations$1 = await getDatasetRunConversationRelations(db)({ scopes: {
|
|
155
|
+
tenantId,
|
|
156
|
+
projectId,
|
|
157
|
+
datasetRunId
|
|
158
|
+
} });
|
|
159
|
+
for (const relation of relations$1) allConversationIds.add(relation.conversationId);
|
|
160
|
+
}
|
|
161
|
+
if (allConversationIds.size > 0) whereConditions.push(inArray(conversations.id, Array.from(allConversationIds)));
|
|
162
|
+
else return [];
|
|
163
|
+
}
|
|
164
|
+
return await db.select().from(conversations).where(and(...whereConditions));
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
//#endregion
|
|
168
|
+
export { createDatasetRun, createDatasetRunConversationRelation, createDatasetRunConversationRelations, createEvaluationResult, createEvaluationResults, createEvaluationRun, deleteDatasetRun, deleteDatasetRunConversationRelation, deleteDatasetRunConversationRelationsByRun, deleteEvaluationResult, deleteEvaluationResultsByRun, deleteEvaluationRun, filterConversationsForJob, getDatasetRunById, getDatasetRunConversationRelationByConversation, getDatasetRunConversationRelations, getEvaluationResultById, getEvaluationRunById, getEvaluationRunByJobConfigId, listDatasetRuns, listDatasetRunsByConfig, listEvaluationResults, listEvaluationResultsByConversation, listEvaluationResultsByRun, listEvaluationRuns, listEvaluationRunsByJobConfigId, updateEvaluationResult, updateEvaluationRun };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Artifact } from "
|
|
2
|
-
import {
|
|
3
|
-
import "
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { Artifact } from "../../types/a2a.js";
|
|
2
|
+
import { ProjectScopeConfig } from "../../types/utility.js";
|
|
3
|
+
import "../../types/index.js";
|
|
4
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
5
|
+
import { LedgerArtifactSelect } from "../../types/entities.js";
|
|
6
6
|
|
|
7
|
-
//#region src/data-access/ledgerArtifacts.d.ts
|
|
7
|
+
//#region src/data-access/runtime/ledgerArtifacts.d.ts
|
|
8
8
|
/**
|
|
9
9
|
* Atomic upsert operation for a single artifact - prevents race conditions
|
|
10
10
|
*/
|
|
11
|
-
declare const upsertLedgerArtifact: (db:
|
|
11
|
+
declare const upsertLedgerArtifact: (db: AgentsRunDatabaseClient) => (params: {
|
|
12
12
|
scopes: ProjectScopeConfig;
|
|
13
13
|
contextId: string;
|
|
14
14
|
taskId: string;
|
|
@@ -21,7 +21,7 @@ declare const upsertLedgerArtifact: (db: DatabaseClient) => (params: {
|
|
|
21
21
|
/**
|
|
22
22
|
* Save one or more artifacts to the ledger
|
|
23
23
|
*/
|
|
24
|
-
declare const addLedgerArtifacts: (db:
|
|
24
|
+
declare const addLedgerArtifacts: (db: AgentsRunDatabaseClient) => (params: {
|
|
25
25
|
scopes: ProjectScopeConfig;
|
|
26
26
|
contextId: string;
|
|
27
27
|
taskId?: string | null;
|
|
@@ -33,7 +33,7 @@ declare const addLedgerArtifacts: (db: DatabaseClient) => (params: {
|
|
|
33
33
|
* At least one of taskId, toolCallId, toolCallIds, or artifactId must be provided.
|
|
34
34
|
* Use toolCallIds for batch queries to avoid N+1 query problems.
|
|
35
35
|
*/
|
|
36
|
-
declare const getLedgerArtifacts: (db:
|
|
36
|
+
declare const getLedgerArtifacts: (db: AgentsRunDatabaseClient) => (params: {
|
|
37
37
|
scopes: ProjectScopeConfig;
|
|
38
38
|
taskId?: string;
|
|
39
39
|
toolCallId?: string;
|
|
@@ -43,28 +43,28 @@ declare const getLedgerArtifacts: (db: DatabaseClient) => (params: {
|
|
|
43
43
|
/**
|
|
44
44
|
* Get ledger artifacts by context ID
|
|
45
45
|
*/
|
|
46
|
-
declare const getLedgerArtifactsByContext: (db:
|
|
46
|
+
declare const getLedgerArtifactsByContext: (db: AgentsRunDatabaseClient) => (params: {
|
|
47
47
|
scopes: ProjectScopeConfig;
|
|
48
48
|
contextId: string;
|
|
49
49
|
}) => Promise<LedgerArtifactSelect[]>;
|
|
50
50
|
/**
|
|
51
51
|
* Delete ledger artifacts by task ID
|
|
52
52
|
*/
|
|
53
|
-
declare const deleteLedgerArtifactsByTask: (db:
|
|
53
|
+
declare const deleteLedgerArtifactsByTask: (db: AgentsRunDatabaseClient) => (params: {
|
|
54
54
|
scopes: ProjectScopeConfig;
|
|
55
55
|
taskId: string;
|
|
56
56
|
}) => Promise<boolean>;
|
|
57
57
|
/**
|
|
58
58
|
* Delete ledger artifacts by context ID
|
|
59
59
|
*/
|
|
60
|
-
declare const deleteLedgerArtifactsByContext: (db:
|
|
60
|
+
declare const deleteLedgerArtifactsByContext: (db: AgentsRunDatabaseClient) => (params: {
|
|
61
61
|
scopes: ProjectScopeConfig;
|
|
62
62
|
contextId: string;
|
|
63
63
|
}) => Promise<boolean>;
|
|
64
64
|
/**
|
|
65
65
|
* Count ledger artifacts by task ID
|
|
66
66
|
*/
|
|
67
|
-
declare const countLedgerArtifactsByTask: (db:
|
|
67
|
+
declare const countLedgerArtifactsByTask: (db: AgentsRunDatabaseClient) => (params: {
|
|
68
68
|
scopes: ProjectScopeConfig;
|
|
69
69
|
taskId: string;
|
|
70
70
|
}) => Promise<number>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ledgerArtifacts } from "
|
|
2
|
-
import { generateId } from "
|
|
1
|
+
import { ledgerArtifacts } from "../../db/runtime/runtime-schema.js";
|
|
2
|
+
import { generateId } from "../../utils/conversations.js";
|
|
3
3
|
import { and, count, eq, inArray } from "drizzle-orm";
|
|
4
4
|
|
|
5
|
-
//#region src/data-access/ledgerArtifacts.ts
|
|
5
|
+
//#region src/data-access/runtime/ledgerArtifacts.ts
|
|
6
6
|
/**
|
|
7
7
|
* Validate artifact data before database insertion
|
|
8
8
|
*/
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "
|
|
3
|
-
import "
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
1
|
+
import { MessageContent, MessageMetadata, MessageVisibility, PaginationConfig, ProjectScopeConfig } from "../../types/utility.js";
|
|
2
|
+
import "../../types/index.js";
|
|
3
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
4
|
+
import "../../index.js";
|
|
5
|
+
import { MessageInsert, MessageUpdate } from "../../types/entities.js";
|
|
6
6
|
|
|
7
|
-
//#region src/data-access/messages.d.ts
|
|
8
|
-
declare const getMessageById: (db:
|
|
7
|
+
//#region src/data-access/runtime/messages.d.ts
|
|
8
|
+
declare const getMessageById: (db: AgentsRunDatabaseClient) => (params: {
|
|
9
9
|
scopes: ProjectScopeConfig;
|
|
10
10
|
messageId: string;
|
|
11
11
|
}) => Promise<{
|
|
@@ -31,7 +31,7 @@ declare const getMessageById: (db: DatabaseClient) => (params: {
|
|
|
31
31
|
a2aTaskId: string | null;
|
|
32
32
|
a2aSessionId: string | null;
|
|
33
33
|
} | undefined>;
|
|
34
|
-
declare const listMessages: (db:
|
|
34
|
+
declare const listMessages: (db: AgentsRunDatabaseClient) => (params: {
|
|
35
35
|
scopes: ProjectScopeConfig;
|
|
36
36
|
pagination: PaginationConfig;
|
|
37
37
|
}) => Promise<{
|
|
@@ -57,7 +57,7 @@ declare const listMessages: (db: DatabaseClient) => (params: {
|
|
|
57
57
|
tenantId: string;
|
|
58
58
|
id: string;
|
|
59
59
|
}[]>;
|
|
60
|
-
declare const getMessagesByConversation: (db:
|
|
60
|
+
declare const getMessagesByConversation: (db: AgentsRunDatabaseClient) => (params: {
|
|
61
61
|
scopes: ProjectScopeConfig;
|
|
62
62
|
conversationId: string;
|
|
63
63
|
pagination: PaginationConfig;
|
|
@@ -84,7 +84,7 @@ declare const getMessagesByConversation: (db: DatabaseClient) => (params: {
|
|
|
84
84
|
tenantId: string;
|
|
85
85
|
id: string;
|
|
86
86
|
}[]>;
|
|
87
|
-
declare const getMessagesByTask: (db:
|
|
87
|
+
declare const getMessagesByTask: (db: AgentsRunDatabaseClient) => (params: {
|
|
88
88
|
scopes: ProjectScopeConfig;
|
|
89
89
|
taskId: string;
|
|
90
90
|
pagination: PaginationConfig;
|
|
@@ -111,7 +111,7 @@ declare const getMessagesByTask: (db: DatabaseClient) => (params: {
|
|
|
111
111
|
tenantId: string;
|
|
112
112
|
id: string;
|
|
113
113
|
}[]>;
|
|
114
|
-
declare const getVisibleMessages: (db:
|
|
114
|
+
declare const getVisibleMessages: (db: AgentsRunDatabaseClient) => (params: {
|
|
115
115
|
scopes: ProjectScopeConfig;
|
|
116
116
|
conversationId: string;
|
|
117
117
|
visibility?: MessageVisibility[];
|
|
@@ -139,7 +139,7 @@ declare const getVisibleMessages: (db: DatabaseClient) => (params: {
|
|
|
139
139
|
tenantId: string;
|
|
140
140
|
id: string;
|
|
141
141
|
}[]>;
|
|
142
|
-
declare const createMessage: (db:
|
|
142
|
+
declare const createMessage: (db: AgentsRunDatabaseClient) => (params: MessageInsert) => Promise<{
|
|
143
143
|
tenantId: string;
|
|
144
144
|
projectId: string;
|
|
145
145
|
id: string;
|
|
@@ -162,7 +162,7 @@ declare const createMessage: (db: DatabaseClient) => (params: MessageInsert) =>
|
|
|
162
162
|
a2aTaskId: string | null;
|
|
163
163
|
a2aSessionId: string | null;
|
|
164
164
|
}>;
|
|
165
|
-
declare const updateMessage: (db:
|
|
165
|
+
declare const updateMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
166
166
|
scopes: ProjectScopeConfig;
|
|
167
167
|
messageId: string;
|
|
168
168
|
data: MessageUpdate;
|
|
@@ -189,7 +189,7 @@ declare const updateMessage: (db: DatabaseClient) => (params: {
|
|
|
189
189
|
tenantId: string;
|
|
190
190
|
id: string;
|
|
191
191
|
}>;
|
|
192
|
-
declare const deleteMessage: (db:
|
|
192
|
+
declare const deleteMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
193
193
|
scopes: ProjectScopeConfig;
|
|
194
194
|
messageId: string;
|
|
195
195
|
}) => Promise<{
|
|
@@ -215,7 +215,7 @@ declare const deleteMessage: (db: DatabaseClient) => (params: {
|
|
|
215
215
|
a2aTaskId: string | null;
|
|
216
216
|
a2aSessionId: string | null;
|
|
217
217
|
}>;
|
|
218
|
-
declare const countMessagesByConversation: (db:
|
|
218
|
+
declare const countMessagesByConversation: (db: AgentsRunDatabaseClient) => (params: {
|
|
219
219
|
scopes: ProjectScopeConfig;
|
|
220
220
|
conversationId: string;
|
|
221
221
|
}) => Promise<number>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { messages } from "
|
|
1
|
+
import { messages } from "../../db/runtime/runtime-schema.js";
|
|
2
2
|
import { and, asc, count, desc, eq, inArray } from "drizzle-orm";
|
|
3
3
|
|
|
4
|
-
//#region src/data-access/messages.ts
|
|
4
|
+
//#region src/data-access/runtime/messages.ts
|
|
5
5
|
const getMessageById = (db) => async (params) => {
|
|
6
6
|
return db.query.messages.findFirst({ where: and(eq(messages.tenantId, params.scopes.tenantId), eq(messages.projectId, params.scopes.projectId), eq(messages.id, params.messageId)) });
|
|
7
7
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
2
|
+
import { UserOrganization } from "../../auth/auth-validation-schemas.js";
|
|
3
3
|
|
|
4
|
-
//#region src/data-access/organizations.d.ts
|
|
4
|
+
//#region src/data-access/runtime/organizations.d.ts
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Organization and Member data access layer
|
|
@@ -12,14 +12,14 @@ import { DatabaseClient } from "../db/client.js";
|
|
|
12
12
|
* Queries Better Auth's member and organization tables
|
|
13
13
|
* Returns Date for createdAt (converted to string at API boundary)
|
|
14
14
|
*/
|
|
15
|
-
declare const getUserOrganizations: (db:
|
|
15
|
+
declare const getUserOrganizations: (db: AgentsRunDatabaseClient) => (userId: string) => Promise<Array<Omit<UserOrganization, "createdAt"> & {
|
|
16
16
|
createdAt: Date;
|
|
17
17
|
}>>;
|
|
18
18
|
/**
|
|
19
19
|
* Get pending invitations for a user by email
|
|
20
20
|
* Returns invitations with status 'pending' that haven't expired
|
|
21
21
|
*/
|
|
22
|
-
declare const getPendingInvitationsByEmail: (db:
|
|
22
|
+
declare const getPendingInvitationsByEmail: (db: AgentsRunDatabaseClient) => (email: string) => Promise<{
|
|
23
23
|
id: string;
|
|
24
24
|
email: string;
|
|
25
25
|
organizationId: string;
|
|
@@ -34,10 +34,19 @@ declare const getPendingInvitationsByEmail: (db: DatabaseClient) => (email: stri
|
|
|
34
34
|
* Add user to organization
|
|
35
35
|
* Directly inserts into Better Auth's member table
|
|
36
36
|
*/
|
|
37
|
-
declare const addUserToOrganization: (db:
|
|
37
|
+
declare const addUserToOrganization: (db: AgentsRunDatabaseClient) => (data: {
|
|
38
38
|
userId: string;
|
|
39
39
|
organizationId: string;
|
|
40
40
|
role: string;
|
|
41
41
|
}) => Promise<void>;
|
|
42
|
+
declare const upsertOrganization: (db: AgentsRunDatabaseClient) => (data: {
|
|
43
|
+
organizationId: string;
|
|
44
|
+
name: string;
|
|
45
|
+
slug: string;
|
|
46
|
+
logo?: string | null;
|
|
47
|
+
metadata?: string | null;
|
|
48
|
+
}) => Promise<{
|
|
49
|
+
created: boolean;
|
|
50
|
+
}>;
|
|
42
51
|
//#endregion
|
|
43
|
-
export { addUserToOrganization, getPendingInvitationsByEmail, getUserOrganizations };
|
|
52
|
+
export { addUserToOrganization, getPendingInvitationsByEmail, getUserOrganizations, upsertOrganization };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { invitation, member, organization } from "
|
|
1
|
+
import { invitation, member, organization } from "../../auth/auth-schema.js";
|
|
2
2
|
import { and, desc, eq } from "drizzle-orm";
|
|
3
3
|
|
|
4
|
-
//#region src/data-access/organizations.ts
|
|
4
|
+
//#region src/data-access/runtime/organizations.ts
|
|
5
5
|
/**
|
|
6
6
|
* Organization and Member data access layer
|
|
7
7
|
* All database queries for Better Auth's organization/member tables
|
|
@@ -58,6 +58,18 @@ const addUserToOrganization = (db) => async (data) => {
|
|
|
58
58
|
createdAt: /* @__PURE__ */ new Date()
|
|
59
59
|
});
|
|
60
60
|
};
|
|
61
|
+
const upsertOrganization = (db) => async (data) => {
|
|
62
|
+
if ((await db.select().from(organization).where(eq(organization.id, data.organizationId)).limit(1)).length > 0) return { created: false };
|
|
63
|
+
await db.insert(organization).values({
|
|
64
|
+
id: data.organizationId,
|
|
65
|
+
name: data.name,
|
|
66
|
+
slug: data.slug,
|
|
67
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
68
|
+
logo: data.logo ?? null,
|
|
69
|
+
metadata: data.metadata ?? null
|
|
70
|
+
});
|
|
71
|
+
return { created: true };
|
|
72
|
+
};
|
|
61
73
|
|
|
62
74
|
//#endregion
|
|
63
|
-
export { addUserToOrganization, getPendingInvitationsByEmail, getUserOrganizations };
|
|
75
|
+
export { addUserToOrganization, getPendingInvitationsByEmail, getUserOrganizations, upsertOrganization };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { PaginationConfig } from "../../types/utility.js";
|
|
2
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
3
|
+
import { ProjectMetadataInsert, ProjectMetadataSelect } from "../../types/entities.js";
|
|
4
|
+
|
|
5
|
+
//#region src/data-access/runtime/projects.d.ts
|
|
6
|
+
interface ProjectMetadataPaginatedResult {
|
|
7
|
+
data: ProjectMetadataSelect[];
|
|
8
|
+
pagination: {
|
|
9
|
+
page: number;
|
|
10
|
+
limit: number;
|
|
11
|
+
total: number;
|
|
12
|
+
pages: number;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get a project from the runtime DB by ID
|
|
17
|
+
*/
|
|
18
|
+
declare const getProjectMetadata: (db: AgentsRunDatabaseClient) => (params: {
|
|
19
|
+
tenantId: string;
|
|
20
|
+
projectId: string;
|
|
21
|
+
}) => Promise<ProjectMetadataSelect | null>;
|
|
22
|
+
/**
|
|
23
|
+
* List all runtimeProjects for a tenant from the runtime DB
|
|
24
|
+
*/
|
|
25
|
+
declare const listProjectsMetadata: (db: AgentsRunDatabaseClient) => (params: {
|
|
26
|
+
tenantId: string;
|
|
27
|
+
}) => Promise<ProjectMetadataSelect[]>;
|
|
28
|
+
/**
|
|
29
|
+
* List runtimeProjects with pagination from the runtime DB
|
|
30
|
+
* @param projectIds - Optional array of project IDs to filter by. If undefined, returns all projects.
|
|
31
|
+
*/
|
|
32
|
+
declare const listProjectsMetadataPaginated: (db: AgentsRunDatabaseClient) => (params: {
|
|
33
|
+
tenantId: string;
|
|
34
|
+
pagination?: PaginationConfig;
|
|
35
|
+
projectIds?: string[];
|
|
36
|
+
}) => Promise<ProjectMetadataPaginatedResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Create a project in the runtime DB
|
|
39
|
+
*/
|
|
40
|
+
declare const createProjectMetadata: (db: AgentsRunDatabaseClient) => (params: ProjectMetadataInsert) => Promise<ProjectMetadataSelect>;
|
|
41
|
+
/**
|
|
42
|
+
* Delete a project from the runtime DB
|
|
43
|
+
*/
|
|
44
|
+
declare const deleteProjectMetadata: (db: AgentsRunDatabaseClient) => (params: {
|
|
45
|
+
tenantId: string;
|
|
46
|
+
projectId: string;
|
|
47
|
+
}) => Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Check if a project exists in the runtime DB
|
|
50
|
+
*/
|
|
51
|
+
declare const projectsMetadataExists: (db: AgentsRunDatabaseClient) => (params: {
|
|
52
|
+
tenantId: string;
|
|
53
|
+
projectId: string;
|
|
54
|
+
}) => Promise<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* Count runtimeProjects for a tenant
|
|
57
|
+
*/
|
|
58
|
+
declare const countProjectsInRuntime: (db: AgentsRunDatabaseClient) => (params: {
|
|
59
|
+
tenantId: string;
|
|
60
|
+
}) => Promise<number>;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { ProjectMetadataPaginatedResult, countProjectsInRuntime, createProjectMetadata, deleteProjectMetadata, getProjectMetadata, listProjectsMetadata, listProjectsMetadataPaginated, projectsMetadataExists };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { projectMetadata } from "../../db/runtime/runtime-schema.js";
|
|
2
|
+
import { and, count, desc, eq, inArray } from "drizzle-orm";
|
|
3
|
+
|
|
4
|
+
//#region src/data-access/runtime/projects.ts
|
|
5
|
+
/**
|
|
6
|
+
* Get a project from the runtime DB by ID
|
|
7
|
+
*/
|
|
8
|
+
const getProjectMetadata = (db) => async (params) => {
|
|
9
|
+
return await db.query.projectMetadata.findFirst({ where: and(eq(projectMetadata.tenantId, params.tenantId), eq(projectMetadata.id, params.projectId)) }) ?? null;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* List all runtimeProjects for a tenant from the runtime DB
|
|
13
|
+
*/
|
|
14
|
+
const listProjectsMetadata = (db) => async (params) => {
|
|
15
|
+
return await db.query.projectMetadata.findMany({
|
|
16
|
+
where: eq(projectMetadata.tenantId, params.tenantId),
|
|
17
|
+
orderBy: [desc(projectMetadata.createdAt)]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* List runtimeProjects with pagination from the runtime DB
|
|
22
|
+
* @param projectIds - Optional array of project IDs to filter by. If undefined, returns all projects.
|
|
23
|
+
*/
|
|
24
|
+
const listProjectsMetadataPaginated = (db) => async (params) => {
|
|
25
|
+
const page = params.pagination?.page || 1;
|
|
26
|
+
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
27
|
+
const offset = (page - 1) * limit;
|
|
28
|
+
const conditions = [eq(projectMetadata.tenantId, params.tenantId)];
|
|
29
|
+
if (params.projectIds !== void 0) {
|
|
30
|
+
if (params.projectIds.length === 0) return {
|
|
31
|
+
data: [],
|
|
32
|
+
pagination: {
|
|
33
|
+
page,
|
|
34
|
+
limit,
|
|
35
|
+
total: 0,
|
|
36
|
+
pages: 0
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
conditions.push(inArray(projectMetadata.id, params.projectIds));
|
|
40
|
+
}
|
|
41
|
+
const whereClause = and(...conditions);
|
|
42
|
+
const [data, totalResult] = await Promise.all([db.select().from(projectMetadata).where(whereClause).limit(limit).offset(offset).orderBy(desc(projectMetadata.createdAt)), db.select({ count: count() }).from(projectMetadata).where(whereClause)]);
|
|
43
|
+
const total = totalResult[0]?.count || 0;
|
|
44
|
+
const totalNumber = typeof total === "string" ? Number.parseInt(total, 10) : total;
|
|
45
|
+
return {
|
|
46
|
+
data,
|
|
47
|
+
pagination: {
|
|
48
|
+
page,
|
|
49
|
+
limit,
|
|
50
|
+
total: totalNumber,
|
|
51
|
+
pages: Math.ceil(totalNumber / limit)
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Create a project in the runtime DB
|
|
57
|
+
*/
|
|
58
|
+
const createProjectMetadata = (db) => async (params) => {
|
|
59
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
60
|
+
const [project] = await db.insert(projectMetadata).values({
|
|
61
|
+
id: params.id,
|
|
62
|
+
tenantId: params.tenantId,
|
|
63
|
+
createdBy: params.createdBy ?? null,
|
|
64
|
+
mainBranchName: params.mainBranchName,
|
|
65
|
+
createdAt: now
|
|
66
|
+
}).returning();
|
|
67
|
+
return project;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Delete a project from the runtime DB
|
|
71
|
+
*/
|
|
72
|
+
const deleteProjectMetadata = (db) => async (params) => {
|
|
73
|
+
return (await db.delete(projectMetadata).where(and(eq(projectMetadata.tenantId, params.tenantId), eq(projectMetadata.id, params.projectId))).returning()).length > 0;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Check if a project exists in the runtime DB
|
|
77
|
+
*/
|
|
78
|
+
const projectsMetadataExists = (db) => async (params) => {
|
|
79
|
+
return await getProjectMetadata(db)(params) !== null;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Count runtimeProjects for a tenant
|
|
83
|
+
*/
|
|
84
|
+
const countProjectsInRuntime = (db) => async (params) => {
|
|
85
|
+
const total = (await db.select({ count: count() }).from(projectMetadata).where(eq(projectMetadata.tenantId, params.tenantId)))[0]?.count || 0;
|
|
86
|
+
return typeof total === "string" ? Number.parseInt(total, 10) : total;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { countProjectsInRuntime, createProjectMetadata, deleteProjectMetadata, getProjectMetadata, listProjectsMetadata, listProjectsMetadataPaginated, projectsMetadataExists };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { TaskMetadataConfig } from "../../types/utility.js";
|
|
2
|
+
import "../../types/index.js";
|
|
3
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
4
|
+
import "../../index.js";
|
|
5
|
+
import { TaskInsert, TaskSelect } from "../../types/entities.js";
|
|
6
|
+
|
|
7
|
+
//#region src/data-access/runtime/tasks.d.ts
|
|
8
|
+
declare const createTask: (db: AgentsRunDatabaseClient) => (params: TaskInsert) => Promise<{
|
|
9
|
+
tenantId: string;
|
|
10
|
+
projectId: string;
|
|
11
|
+
id: string;
|
|
12
|
+
agentId: string;
|
|
13
|
+
createdAt: string;
|
|
14
|
+
updatedAt: string;
|
|
15
|
+
metadata: TaskMetadataConfig | null;
|
|
16
|
+
status: string;
|
|
17
|
+
ref: {
|
|
18
|
+
type: "tag" | "commit" | "branch";
|
|
19
|
+
name: string;
|
|
20
|
+
hash: string;
|
|
21
|
+
} | null;
|
|
22
|
+
contextId: string;
|
|
23
|
+
subAgentId: string;
|
|
24
|
+
}>;
|
|
25
|
+
declare const getTask: (db: AgentsRunDatabaseClient) => (params: {
|
|
26
|
+
id: string;
|
|
27
|
+
}) => Promise<TaskSelect | null>;
|
|
28
|
+
declare const updateTask: (db: AgentsRunDatabaseClient) => (params: {
|
|
29
|
+
taskId: string;
|
|
30
|
+
data: {
|
|
31
|
+
status?: string;
|
|
32
|
+
metadata?: any;
|
|
33
|
+
};
|
|
34
|
+
}) => Promise<{
|
|
35
|
+
createdAt: string;
|
|
36
|
+
updatedAt: string;
|
|
37
|
+
contextId: string;
|
|
38
|
+
ref: {
|
|
39
|
+
type: "tag" | "commit" | "branch";
|
|
40
|
+
name: string;
|
|
41
|
+
hash: string;
|
|
42
|
+
} | null;
|
|
43
|
+
status: string;
|
|
44
|
+
metadata: TaskMetadataConfig | null;
|
|
45
|
+
subAgentId: string;
|
|
46
|
+
agentId: string;
|
|
47
|
+
projectId: string;
|
|
48
|
+
tenantId: string;
|
|
49
|
+
id: string;
|
|
50
|
+
}>;
|
|
51
|
+
declare const listTaskIdsByContextId: (db: AgentsRunDatabaseClient) => (params: {
|
|
52
|
+
contextId: string;
|
|
53
|
+
}) => Promise<string[]>;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { createTask, getTask, listTaskIdsByContextId, updateTask };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { tasks } from "
|
|
1
|
+
import { tasks } from "../../db/runtime/runtime-schema.js";
|
|
2
2
|
import { and, eq } from "drizzle-orm";
|
|
3
3
|
|
|
4
|
-
//#region src/data-access/tasks.ts
|
|
4
|
+
//#region src/data-access/runtime/tasks.ts
|
|
5
5
|
const createTask = (db) => async (params) => {
|
|
6
6
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
7
7
|
const [created] = await db.insert(tasks).values({
|