@inkeep/agents-core 0.78.3 → 0.78.5

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.
Files changed (66) hide show
  1. package/dist/auth/auth-validation-schemas.d.ts +154 -154
  2. package/dist/auth/auth.d.ts +9 -9
  3. package/dist/auth/permissions.d.ts +13 -13
  4. package/dist/client-exports.d.ts +2 -2
  5. package/dist/client-exports.js +2 -2
  6. package/dist/data-access/index.d.ts +6 -6
  7. package/dist/data-access/index.js +6 -6
  8. package/dist/data-access/manage/agents.d.ts +15 -15
  9. package/dist/data-access/manage/artifactComponents.d.ts +4 -4
  10. package/dist/data-access/manage/contextConfigs.d.ts +8 -8
  11. package/dist/data-access/manage/dataComponents.d.ts +2 -2
  12. package/dist/data-access/manage/evalConfig.d.ts +19 -2
  13. package/dist/data-access/manage/evalConfig.js +20 -2
  14. package/dist/data-access/manage/functionTools.d.ts +6 -6
  15. package/dist/data-access/manage/skills.d.ts +7 -7
  16. package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +6 -6
  17. package/dist/data-access/manage/subAgentRelations.d.ts +12 -12
  18. package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +6 -6
  19. package/dist/data-access/manage/subAgents.d.ts +9 -9
  20. package/dist/data-access/manage/tools.d.ts +15 -15
  21. package/dist/data-access/manage/triggers.d.ts +3 -3
  22. package/dist/data-access/manage/webhookDestinations.d.ts +15 -3
  23. package/dist/data-access/manage/webhookDestinations.js +26 -8
  24. package/dist/data-access/runtime/apiKeys.d.ts +4 -4
  25. package/dist/data-access/runtime/apps.d.ts +7 -7
  26. package/dist/data-access/runtime/conversations.d.ts +12 -12
  27. package/dist/data-access/runtime/evalRuns.d.ts +47 -6
  28. package/dist/data-access/runtime/evalRuns.js +96 -6
  29. package/dist/data-access/runtime/events.d.ts +3 -3
  30. package/dist/data-access/runtime/feedback.d.ts +2 -2
  31. package/dist/data-access/runtime/messages.d.ts +15 -15
  32. package/dist/data-access/runtime/scheduledTriggerInvocations.d.ts +39 -7
  33. package/dist/data-access/runtime/scheduledTriggerInvocations.js +16 -3
  34. package/dist/data-access/runtime/scheduledTriggers.d.ts +28 -6
  35. package/dist/data-access/runtime/scheduledTriggers.js +34 -7
  36. package/dist/data-access/runtime/tasks.d.ts +1 -1
  37. package/dist/db/manage/manage-schema.d.ts +686 -385
  38. package/dist/db/manage/manage-schema.js +120 -2
  39. package/dist/db/runtime/runtime-schema.d.ts +472 -453
  40. package/dist/db/runtime/runtime-schema.js +3 -1
  41. package/dist/evaluation/pass-criteria-evaluator.js +69 -29
  42. package/dist/index.d.ts +10 -10
  43. package/dist/index.js +9 -9
  44. package/dist/types/entities.d.ts +5 -2
  45. package/dist/types/index.d.ts +3 -3
  46. package/dist/types/index.js +2 -2
  47. package/dist/types/utility.d.ts +13 -5
  48. package/dist/types/utility.js +2 -1
  49. package/dist/utils/error.d.ts +51 -51
  50. package/dist/validation/drizzle-schema-helpers.d.ts +3 -3
  51. package/dist/validation/index.d.ts +2 -2
  52. package/dist/validation/index.js +2 -2
  53. package/dist/validation/schemas/shared.d.ts +1 -0
  54. package/dist/validation/schemas/shared.js +2 -1
  55. package/dist/validation/schemas/skills.d.ts +33 -32
  56. package/dist/validation/schemas.d.ts +2330 -1958
  57. package/dist/validation/schemas.js +64 -10
  58. package/drizzle/manage/0022_last_nemesis.sql +15 -0
  59. package/drizzle/manage/0023_flimsy_patriot.sql +13 -0
  60. package/drizzle/manage/meta/0022_snapshot.json +4216 -0
  61. package/drizzle/manage/meta/0023_snapshot.json +4317 -0
  62. package/drizzle/manage/meta/_journal.json +14 -0
  63. package/drizzle/runtime/0043_normal_beyonder.sql +2 -0
  64. package/drizzle/runtime/meta/0043_snapshot.json +6304 -0
  65. package/drizzle/runtime/meta/_journal.json +7 -0
  66. package/package.json +1 -1
@@ -13,8 +13,8 @@ declare const getApiKeyById: (db: AgentsRunDatabaseClient) => (params: {
13
13
  createdAt: string;
14
14
  updatedAt: string;
15
15
  expiresAt: string | null;
16
- tenantId: string;
17
16
  projectId: string;
17
+ tenantId: string;
18
18
  agentId: string;
19
19
  publicId: string;
20
20
  keyHash: string;
@@ -27,8 +27,8 @@ declare const getApiKeyByPublicId: (db: AgentsRunDatabaseClient) => (publicId: s
27
27
  createdAt: string;
28
28
  updatedAt: string;
29
29
  expiresAt: string | null;
30
- tenantId: string;
31
30
  projectId: string;
31
+ tenantId: string;
32
32
  agentId: string;
33
33
  publicId: string;
34
34
  keyHash: string;
@@ -44,8 +44,8 @@ declare const listApiKeys: (db: AgentsRunDatabaseClient) => (params: {
44
44
  createdAt: string;
45
45
  updatedAt: string;
46
46
  expiresAt: string | null;
47
- tenantId: string;
48
47
  projectId: string;
48
+ tenantId: string;
49
49
  agentId: string;
50
50
  publicId: string;
51
51
  keyHash: string;
@@ -71,8 +71,8 @@ declare const createApiKey: (db: AgentsRunDatabaseClient) => (params: ApiKeyInse
71
71
  createdAt: string;
72
72
  updatedAt: string;
73
73
  expiresAt: string | null;
74
- tenantId: string;
75
74
  projectId: string;
75
+ tenantId: string;
76
76
  agentId: string;
77
77
  publicId: string;
78
78
  keyHash: string;
@@ -11,10 +11,10 @@ declare const getAppById: (db: AgentsRunDatabaseClient) => (id: string) => Promi
11
11
  createdAt: string;
12
12
  updatedAt: string;
13
13
  description: string | null;
14
- tenantId: string | null;
15
14
  enabled: boolean;
16
- prompt: string | null;
17
15
  projectId: string | null;
16
+ tenantId: string | null;
17
+ prompt: string | null;
18
18
  config: {
19
19
  type: "web_client";
20
20
  webClient: {
@@ -22,7 +22,7 @@ declare const getAppById: (db: AgentsRunDatabaseClient) => (id: string) => Promi
22
22
  publicKeys: {
23
23
  kid: string;
24
24
  publicKey: string;
25
- algorithm: "RS256" | "RS384" | "RS512" | "ES256" | "ES384" | "ES512" | "EdDSA";
25
+ algorithm: "EdDSA" | "ES256" | "ES512" | "RS256" | "RS384" | "RS512" | "ES384";
26
26
  addedAt: string;
27
27
  }[];
28
28
  allowAnonymous: boolean;
@@ -80,10 +80,10 @@ declare const createApp: (db: AgentsRunDatabaseClient) => (params: AppInsert) =>
80
80
  createdAt: string;
81
81
  updatedAt: string;
82
82
  description: string | null;
83
- tenantId: string | null;
84
83
  enabled: boolean;
85
- prompt: string | null;
86
84
  projectId: string | null;
85
+ tenantId: string | null;
86
+ prompt: string | null;
87
87
  config: {
88
88
  type: "web_client";
89
89
  webClient: {
@@ -91,7 +91,7 @@ declare const createApp: (db: AgentsRunDatabaseClient) => (params: AppInsert) =>
91
91
  publicKeys: {
92
92
  kid: string;
93
93
  publicKey: string;
94
- algorithm: "RS256" | "RS384" | "RS512" | "ES256" | "ES384" | "ES512" | "EdDSA";
94
+ algorithm: "EdDSA" | "ES256" | "ES512" | "RS256" | "RS384" | "RS512" | "ES384";
95
95
  addedAt: string;
96
96
  }[];
97
97
  allowAnonymous: boolean;
@@ -174,7 +174,7 @@ declare const updateApp: (db: AgentsRunDatabaseClient) => (params: {
174
174
  publicKeys: {
175
175
  kid: string;
176
176
  publicKey: string;
177
- algorithm: "RS256" | "RS384" | "RS512" | "ES256" | "ES384" | "ES512" | "EdDSA";
177
+ algorithm: "EdDSA" | "ES256" | "ES512" | "RS256" | "RS384" | "RS512" | "ES384";
178
178
  addedAt: string;
179
179
  }[];
180
180
  allowAnonymous: boolean;
@@ -26,14 +26,14 @@ declare const createConversation: (db: AgentsRunDatabaseClient) => (params: Conv
26
26
  } | null;
27
27
  userId: string | null;
28
28
  metadata: ConversationMetadata | null;
29
+ projectId: string;
30
+ tenantId: string;
29
31
  properties: Record<string, unknown> | null;
30
32
  title: string | null;
31
- tenantId: string;
32
- projectId: string;
33
33
  agentId: string | null;
34
+ userProperties: Record<string, unknown> | null;
34
35
  activeSubAgentId: string;
35
36
  lastContextResolution: string | null;
36
- userProperties: Record<string, unknown> | null;
37
37
  }>;
38
38
  declare const updateConversation: (db: AgentsRunDatabaseClient) => (params: {
39
39
  scopes: ProjectScopeConfig;
@@ -101,14 +101,14 @@ declare const getConversation: (db: AgentsRunDatabaseClient) => (params: {
101
101
  } | null;
102
102
  userId: string | null;
103
103
  metadata: ConversationMetadata | null;
104
+ projectId: string;
105
+ tenantId: string;
104
106
  properties: Record<string, unknown> | null;
105
107
  title: string | null;
106
- tenantId: string;
107
- projectId: string;
108
108
  agentId: string | null;
109
+ userProperties: Record<string, unknown> | null;
109
110
  activeSubAgentId: string;
110
111
  lastContextResolution: string | null;
111
- userProperties: Record<string, unknown> | null;
112
112
  } | undefined>;
113
113
  /**
114
114
  * Batch-fetch conversations by id within a project scope.
@@ -156,14 +156,14 @@ declare const createOrGetConversation: (db: AgentsRunDatabaseClient) => (input:
156
156
  } | null;
157
157
  userId: string | null;
158
158
  metadata: ConversationMetadata | null;
159
+ projectId: string;
160
+ tenantId: string;
159
161
  properties: Record<string, unknown> | null;
160
162
  title: string | null;
161
- tenantId: string;
162
- projectId: string;
163
163
  agentId: string | null;
164
+ userProperties: Record<string, unknown> | null;
164
165
  activeSubAgentId: string;
165
166
  lastContextResolution: string | null;
166
- userProperties: Record<string, unknown> | null;
167
167
  }>;
168
168
  /**
169
169
  * Extract text content from message content object
@@ -194,14 +194,14 @@ declare const getActiveAgentForConversation: (db: AgentsRunDatabaseClient) => (p
194
194
  } | null;
195
195
  userId: string | null;
196
196
  metadata: ConversationMetadata | null;
197
+ projectId: string;
198
+ tenantId: string;
197
199
  properties: Record<string, unknown> | null;
198
200
  title: string | null;
199
- tenantId: string;
200
- projectId: string;
201
201
  agentId: string | null;
202
+ userProperties: Record<string, unknown> | null;
202
203
  activeSubAgentId: string;
203
204
  lastContextResolution: string | null;
204
- userProperties: Record<string, unknown> | null;
205
205
  } | undefined>;
206
206
  /**
207
207
  * Set active agent for a conversation (upsert operation)
@@ -1,5 +1,5 @@
1
1
  import { ProjectScopeConfig } from "../../db/manage/scope-definitions.js";
2
- import { EvaluationJobFilterCriteria, Filter } from "../../types/utility.js";
2
+ import { EvaluationJobFilterCriteria, Filter, MessageContent } from "../../types/utility.js";
3
3
  import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
4
4
  import { ConversationSelect, DatasetRunConversationRelationInsert, DatasetRunConversationRelationSelect, DatasetRunInsert, DatasetRunSelect, EvaluationResultInsert, EvaluationResultSelect, EvaluationResultUpdate, EvaluationRunInsert, EvaluationRunSelect, EvaluationRunUpdate } from "../../types/entities.js";
5
5
 
@@ -12,6 +12,10 @@ declare const getDatasetRunById: (db: AgentsRunDatabaseClient) => (params: {
12
12
  declare const listDatasetRuns: (db: AgentsRunDatabaseClient) => (params: {
13
13
  scopes: ProjectScopeConfig;
14
14
  }) => Promise<DatasetRunSelect[]>;
15
+ declare const getDatasetRunsByIds: (db: AgentsRunDatabaseClient) => (params: {
16
+ scopes: ProjectScopeConfig;
17
+ datasetRunIds: string[];
18
+ }) => Promise<DatasetRunSelect[]>;
15
19
  declare const listDatasetRunsByConfig: (db: AgentsRunDatabaseClient) => (params: {
16
20
  scopes: ProjectScopeConfig & {
17
21
  datasetRunConfigId: string;
@@ -58,10 +62,6 @@ declare const listEvaluationRunsByJobConfigId: (db: AgentsRunDatabaseClient) =>
58
62
  scopes: ProjectScopeConfig;
59
63
  evaluationJobConfigId: string;
60
64
  }) => Promise<EvaluationRunSelect[]>;
61
- declare const listEvaluationRunsByRunConfigId: (db: AgentsRunDatabaseClient) => (params: {
62
- scopes: ProjectScopeConfig;
63
- evaluationRunConfigId: string;
64
- }) => Promise<EvaluationRunSelect[]>;
65
65
  declare const getEvaluationRunByJobConfigId: (db: AgentsRunDatabaseClient) => (params: {
66
66
  scopes: ProjectScopeConfig;
67
67
  evaluationJobConfigId: string;
@@ -91,6 +91,47 @@ declare const listEvaluationResultsByRun: (db: AgentsRunDatabaseClient) => (para
91
91
  evaluationRunId: string;
92
92
  };
93
93
  }) => Promise<EvaluationResultSelect[]>;
94
+ interface EvalResultsFilter {
95
+ evaluatorId?: string;
96
+ agentId?: string;
97
+ }
98
+ interface EvalResultsPagination {
99
+ page: number;
100
+ limit: number;
101
+ }
102
+ interface EnrichedEvaluationResult {
103
+ id: string;
104
+ tenantId: string;
105
+ projectId: string;
106
+ conversationId: string;
107
+ evaluatorId: string;
108
+ evaluationRunId: string | null;
109
+ output: MessageContent | null;
110
+ createdAt: string;
111
+ updatedAt: string;
112
+ input: string | null;
113
+ agentId: string | null;
114
+ conversationCreatedAt: string | null;
115
+ }
116
+ interface PaginatedEvalResults {
117
+ data: EnrichedEvaluationResult[];
118
+ pagination: {
119
+ page: number;
120
+ limit: number;
121
+ total: number;
122
+ pages: number;
123
+ completedCount: number;
124
+ };
125
+ distinctAgentIds: string[];
126
+ distinctOutputKeys: string[];
127
+ }
128
+ declare const listEvaluationResultsPaginated: (db: AgentsRunDatabaseClient) => (params: {
129
+ scopes: ProjectScopeConfig;
130
+ evaluationRunConfigId?: string;
131
+ evaluationJobConfigId?: string;
132
+ filters?: EvalResultsFilter;
133
+ pagination?: EvalResultsPagination;
134
+ }) => Promise<PaginatedEvalResults>;
94
135
  declare const listEvaluationResultsByConversation: (db: AgentsRunDatabaseClient) => (params: {
95
136
  scopes: ProjectScopeConfig & {
96
137
  conversationId: string;
@@ -122,4 +163,4 @@ declare const filterConversationsForJob: (db: AgentsRunDatabaseClient) => (param
122
163
  jobFilters: Filter<EvaluationJobFilterCriteria> | null | undefined;
123
164
  }) => Promise<ConversationSelect[]>;
124
165
  //#endregion
125
- 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, listEvaluationRunsByRunConfigId, updateEvaluationResult, updateEvaluationRun };
166
+ export { EnrichedEvaluationResult, EvalResultsFilter, EvalResultsPagination, PaginatedEvalResults, createDatasetRun, createDatasetRunConversationRelation, createDatasetRunConversationRelations, createEvaluationResult, createEvaluationResults, createEvaluationRun, deleteDatasetRun, deleteDatasetRunConversationRelation, deleteDatasetRunConversationRelationsByRun, deleteEvaluationResult, deleteEvaluationResultsByRun, deleteEvaluationRun, filterConversationsForJob, getDatasetRunById, getDatasetRunConversationRelationByConversation, getDatasetRunConversationRelations, getDatasetRunsByIds, getEvaluationResultById, getEvaluationRunById, getEvaluationRunByJobConfigId, listDatasetRuns, listDatasetRunsByConfig, listEvaluationResults, listEvaluationResultsByConversation, listEvaluationResultsByRun, listEvaluationResultsPaginated, listEvaluationRuns, listEvaluationRunsByJobConfigId, updateEvaluationResult, updateEvaluationRun };
@@ -1,6 +1,6 @@
1
- import { conversations, datasetRun, datasetRunConversationRelations, evaluationResult, evaluationRun } from "../../db/runtime/runtime-schema.js";
1
+ import { conversations, datasetRun, datasetRunConversationRelations, evaluationResult, evaluationRun, messages } from "../../db/runtime/runtime-schema.js";
2
2
  import { projectScopedWhere } from "../manage/scope-helpers.js";
3
- import { and, desc, eq, gte, inArray, lte } from "drizzle-orm";
3
+ import { and, asc, count, desc, eq, gte, inArray, lte, sql } from "drizzle-orm";
4
4
 
5
5
  //#region src/data-access/runtime/evalRuns.ts
6
6
  const getDatasetRunById = (db) => async (params) => {
@@ -9,6 +9,10 @@ const getDatasetRunById = (db) => async (params) => {
9
9
  const listDatasetRuns = (db) => async (params) => {
10
10
  return await db.select().from(datasetRun).where(projectScopedWhere(datasetRun, params.scopes)).orderBy(desc(datasetRun.createdAt));
11
11
  };
12
+ const getDatasetRunsByIds = (db) => async (params) => {
13
+ if (params.datasetRunIds.length === 0) return [];
14
+ return await db.select().from(datasetRun).where(and(projectScopedWhere(datasetRun, params.scopes), inArray(datasetRun.id, params.datasetRunIds)));
15
+ };
12
16
  const listDatasetRunsByConfig = (db) => async (params) => {
13
17
  return await db.select().from(datasetRun).where(and(projectScopedWhere(datasetRun, params.scopes), eq(datasetRun.datasetRunConfigId, params.scopes.datasetRunConfigId))).orderBy(desc(datasetRun.createdAt));
14
18
  };
@@ -63,9 +67,6 @@ const listEvaluationRuns = (db) => async (params) => {
63
67
  const listEvaluationRunsByJobConfigId = (db) => async (params) => {
64
68
  return await db.select().from(evaluationRun).where(and(projectScopedWhere(evaluationRun, params.scopes), eq(evaluationRun.evaluationJobConfigId, params.evaluationJobConfigId)));
65
69
  };
66
- const listEvaluationRunsByRunConfigId = (db) => async (params) => {
67
- return await db.select().from(evaluationRun).where(and(projectScopedWhere(evaluationRun, params.scopes), eq(evaluationRun.evaluationRunConfigId, params.evaluationRunConfigId)));
68
- };
69
70
  const getEvaluationRunByJobConfigId = (db) => async (params) => {
70
71
  return (await db.select().from(evaluationRun).where(and(projectScopedWhere(evaluationRun, params.scopes), eq(evaluationRun.evaluationJobConfigId, params.evaluationJobConfigId))).limit(1))[0] ?? null;
71
72
  };
@@ -96,6 +97,95 @@ const listEvaluationResults = (db) => async (params) => {
96
97
  const listEvaluationResultsByRun = (db) => async (params) => {
97
98
  return await db.query.evaluationResult.findMany({ where: and(projectScopedWhere(evaluationResult, params.scopes), eq(evaluationResult.evaluationRunId, params.scopes.evaluationRunId)) });
98
99
  };
100
+ const EVAL_RESULTS_MAX_ROWS = 2e4;
101
+ function buildFirstUserMessageSubquery(db) {
102
+ return db.selectDistinctOn([messages.conversationId], {
103
+ conversationId: messages.conversationId,
104
+ content: messages.content
105
+ }).from(messages).where(eq(messages.role, "user")).orderBy(messages.conversationId, asc(messages.createdAt), asc(messages.id)).as("first_msg");
106
+ }
107
+ function buildEvalResultsBaseQuery(db, params) {
108
+ const runWhereConditions = [projectScopedWhere(evaluationRun, params.scopes)];
109
+ if (params.evaluationRunConfigId) runWhereConditions.push(eq(evaluationRun.evaluationRunConfigId, params.evaluationRunConfigId));
110
+ if (params.evaluationJobConfigId) runWhereConditions.push(eq(evaluationRun.evaluationJobConfigId, params.evaluationJobConfigId));
111
+ const runIdSubquery = db.select({ id: evaluationRun.id }).from(evaluationRun).where(and(...runWhereConditions));
112
+ const whereConditions = [projectScopedWhere(evaluationResult, params.scopes), inArray(evaluationResult.evaluationRunId, runIdSubquery)];
113
+ if (params.filters?.evaluatorId) whereConditions.push(eq(evaluationResult.evaluatorId, params.filters.evaluatorId));
114
+ if (params.filters?.agentId) whereConditions.push(eq(conversations.agentId, params.filters.agentId));
115
+ return { whereConditions };
116
+ }
117
+ const listEvaluationResultsPaginated = (db) => async (params) => {
118
+ const page = params.pagination?.page ?? 1;
119
+ const limit = Math.min(params.pagination?.limit ?? 50, EVAL_RESULTS_MAX_ROWS);
120
+ const offset = (page - 1) * limit;
121
+ const { whereConditions } = buildEvalResultsBaseQuery(db, {
122
+ scopes: params.scopes,
123
+ evaluationRunConfigId: params.evaluationRunConfigId,
124
+ evaluationJobConfigId: params.evaluationJobConfigId,
125
+ filters: params.filters
126
+ });
127
+ const conversationsJoin = and(eq(evaluationResult.conversationId, conversations.id), eq(evaluationResult.tenantId, conversations.tenantId), eq(evaluationResult.projectId, conversations.projectId));
128
+ const firstMsg = buildFirstUserMessageSubquery(db);
129
+ const [countResult, rows, agentIdRows, outputKeyRows] = await Promise.all([
130
+ db.select({
131
+ total: count(),
132
+ completedCount: count(evaluationResult.output)
133
+ }).from(evaluationResult).leftJoin(conversations, conversationsJoin).where(and(...whereConditions)),
134
+ db.select({
135
+ id: evaluationResult.id,
136
+ tenantId: evaluationResult.tenantId,
137
+ projectId: evaluationResult.projectId,
138
+ conversationId: evaluationResult.conversationId,
139
+ evaluatorId: evaluationResult.evaluatorId,
140
+ evaluationRunId: evaluationResult.evaluationRunId,
141
+ output: evaluationResult.output,
142
+ createdAt: evaluationResult.createdAt,
143
+ updatedAt: evaluationResult.updatedAt,
144
+ agentId: conversations.agentId,
145
+ conversationCreatedAt: conversations.createdAt,
146
+ firstMsgContent: firstMsg.content
147
+ }).from(evaluationResult).leftJoin(conversations, conversationsJoin).leftJoin(firstMsg, eq(evaluationResult.conversationId, firstMsg.conversationId)).where(and(...whereConditions)).orderBy(desc(evaluationResult.createdAt)).limit(limit).offset(offset),
148
+ db.selectDistinct({ agentId: conversations.agentId }).from(evaluationResult).leftJoin(conversations, conversationsJoin).where(and(...whereConditions)),
149
+ db.select({ key: sql`jsonb_object_keys(${evaluationResult.output}->'output')` }).from(evaluationResult).leftJoin(conversations, conversationsJoin).where(and(...whereConditions, sql`jsonb_typeof(${evaluationResult.output}->'output') = 'object'`)).groupBy(sql`jsonb_object_keys(${evaluationResult.output}->'output')`)
150
+ ]);
151
+ const total = countResult[0]?.total ?? 0;
152
+ const completedCount = countResult[0]?.completedCount ?? 0;
153
+ const distinctAgentIds = agentIdRows.map((r) => r.agentId).filter((id) => id != null).sort();
154
+ const distinctOutputKeys = outputKeyRows.map((r) => `output.${r.key}`).sort();
155
+ return {
156
+ data: rows.map((row) => {
157
+ let input = null;
158
+ if (row.firstMsgContent) {
159
+ const content = row.firstMsgContent;
160
+ if (content.text) input = content.text;
161
+ else if (content.parts) input = content.parts.filter((part) => part.kind === "text" && part.text).map((part) => part.text).join(" ") || null;
162
+ }
163
+ return {
164
+ id: row.id,
165
+ tenantId: row.tenantId,
166
+ projectId: row.projectId,
167
+ conversationId: row.conversationId,
168
+ evaluatorId: row.evaluatorId,
169
+ evaluationRunId: row.evaluationRunId,
170
+ output: row.output,
171
+ createdAt: row.createdAt,
172
+ updatedAt: row.updatedAt,
173
+ input,
174
+ agentId: row.agentId ?? null,
175
+ conversationCreatedAt: row.conversationCreatedAt ?? null
176
+ };
177
+ }),
178
+ pagination: {
179
+ page,
180
+ limit,
181
+ total,
182
+ pages: Math.ceil(total / limit),
183
+ completedCount
184
+ },
185
+ distinctAgentIds,
186
+ distinctOutputKeys
187
+ };
188
+ };
99
189
  const listEvaluationResultsByConversation = (db) => async (params) => {
100
190
  return await db.query.evaluationResult.findMany({ where: and(projectScopedWhere(evaluationResult, params.scopes), eq(evaluationResult.conversationId, params.scopes.conversationId)) });
101
191
  };
@@ -169,4 +259,4 @@ const filterConversationsForJob = (db) => async (params) => {
169
259
  };
170
260
 
171
261
  //#endregion
172
- 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, listEvaluationRunsByRunConfigId, updateEvaluationResult, updateEvaluationRun };
262
+ export { createDatasetRun, createDatasetRunConversationRelation, createDatasetRunConversationRelations, createEvaluationResult, createEvaluationResults, createEvaluationRun, deleteDatasetRun, deleteDatasetRunConversationRelation, deleteDatasetRunConversationRelationsByRun, deleteEvaluationResult, deleteEvaluationResultsByRun, deleteEvaluationRun, filterConversationsForJob, getDatasetRunById, getDatasetRunConversationRelationByConversation, getDatasetRunConversationRelations, getDatasetRunsByIds, getEvaluationResultById, getEvaluationRunById, getEvaluationRunByJobConfigId, listDatasetRuns, listDatasetRunsByConfig, listEvaluationResults, listEvaluationResultsByConversation, listEvaluationResultsByRun, listEvaluationResultsPaginated, listEvaluationRuns, listEvaluationRunsByJobConfigId, updateEvaluationResult, updateEvaluationRun };
@@ -12,12 +12,12 @@ declare const createEvent: (db: AgentsRunDatabaseClient) => (params: EventInsert
12
12
  createdAt: string;
13
13
  updatedAt: string;
14
14
  metadata: Record<string, unknown> | null;
15
- properties: Record<string, unknown> | null;
16
- tenantId: string;
17
15
  projectId: string;
16
+ tenantId: string;
17
+ properties: Record<string, unknown> | null;
18
18
  agentId: string | null;
19
- userProperties: Record<string, unknown> | null;
20
19
  conversationId: string | null;
20
+ userProperties: Record<string, unknown> | null;
21
21
  messageId: string | null;
22
22
  serverMetadata: {
23
23
  [k: string]: unknown;
@@ -74,8 +74,8 @@ declare const createFeedback: (db: AgentsRunDatabaseClient) => (params: Feedback
74
74
  id: string;
75
75
  createdAt: string;
76
76
  updatedAt: string;
77
- tenantId: string;
78
77
  projectId: string;
78
+ tenantId: string;
79
79
  details: string | null;
80
80
  conversationId: string;
81
81
  messageId: string | null;
@@ -104,8 +104,8 @@ declare const deleteFeedback: (db: AgentsRunDatabaseClient) => (params: {
104
104
  id: string;
105
105
  createdAt: string;
106
106
  updatedAt: string;
107
- tenantId: string;
108
107
  projectId: string;
108
+ tenantId: string;
109
109
  details: string | null;
110
110
  conversationId: string;
111
111
  messageId: string | null;
@@ -15,21 +15,21 @@ declare const getMessageById: (db: AgentsRunDatabaseClient) => (params: {
15
15
  updatedAt: string;
16
16
  metadata: MessageMetadata | null;
17
17
  role: string;
18
- properties: Record<string, unknown> | null;
19
- tenantId: string;
20
- projectId: string;
21
18
  content: MessageContent;
19
+ projectId: string;
20
+ tenantId: string;
21
+ properties: Record<string, unknown> | null;
22
22
  fromSubAgentId: string | null;
23
23
  toSubAgentId: string | null;
24
24
  fromExternalAgentId: string | null;
25
25
  toExternalAgentId: string | null;
26
26
  taskId: string | null;
27
27
  a2aTaskId: string | null;
28
- visibility: string;
29
- userProperties: Record<string, unknown> | null;
30
28
  conversationId: string;
29
+ userProperties: Record<string, unknown> | null;
31
30
  fromTeamAgentId: string | null;
32
31
  toTeamAgentId: string | null;
32
+ visibility: string;
33
33
  messageType: string;
34
34
  parentMessageId: string | null;
35
35
  a2aSessionId: string | null;
@@ -188,21 +188,21 @@ declare const createMessage: (db: AgentsRunDatabaseClient) => (params: {
188
188
  updatedAt: string;
189
189
  metadata: MessageMetadata | null;
190
190
  role: string;
191
- properties: Record<string, unknown> | null;
192
- tenantId: string;
193
- projectId: string;
194
191
  content: MessageContent;
192
+ projectId: string;
193
+ tenantId: string;
194
+ properties: Record<string, unknown> | null;
195
195
  fromSubAgentId: string | null;
196
196
  toSubAgentId: string | null;
197
197
  fromExternalAgentId: string | null;
198
198
  toExternalAgentId: string | null;
199
199
  taskId: string | null;
200
200
  a2aTaskId: string | null;
201
- visibility: string;
202
- userProperties: Record<string, unknown> | null;
203
201
  conversationId: string;
202
+ userProperties: Record<string, unknown> | null;
204
203
  fromTeamAgentId: string | null;
205
204
  toTeamAgentId: string | null;
205
+ visibility: string;
206
206
  messageType: string;
207
207
  parentMessageId: string | null;
208
208
  a2aSessionId: string | null;
@@ -245,21 +245,21 @@ declare const deleteMessage: (db: AgentsRunDatabaseClient) => (params: {
245
245
  updatedAt: string;
246
246
  metadata: MessageMetadata | null;
247
247
  role: string;
248
- properties: Record<string, unknown> | null;
249
- tenantId: string;
250
- projectId: string;
251
248
  content: MessageContent;
249
+ projectId: string;
250
+ tenantId: string;
251
+ properties: Record<string, unknown> | null;
252
252
  fromSubAgentId: string | null;
253
253
  toSubAgentId: string | null;
254
254
  fromExternalAgentId: string | null;
255
255
  toExternalAgentId: string | null;
256
256
  taskId: string | null;
257
257
  a2aTaskId: string | null;
258
- visibility: string;
259
- userProperties: Record<string, unknown> | null;
260
258
  conversationId: string;
259
+ userProperties: Record<string, unknown> | null;
261
260
  fromTeamAgentId: string | null;
262
261
  toTeamAgentId: string | null;
262
+ visibility: string;
263
263
  messageType: string;
264
264
  parentMessageId: string | null;
265
265
  a2aSessionId: string | null;
@@ -40,7 +40,7 @@ declare const listScheduledTriggerInvocationsPaginated: (db: AgentsRunDatabaseCl
40
40
  name: string;
41
41
  hash: string;
42
42
  } | null;
43
- status: "pending" | "running" | "completed" | "failed" | "cancelled";
43
+ status: "pending" | "failed" | "running" | "completed" | "cancelled";
44
44
  scheduledFor: string;
45
45
  startedAt: string | null;
46
46
  completedAt: string | null;
@@ -150,7 +150,7 @@ declare const markScheduledTriggerInvocationCancelled: (db: AgentsRunDatabaseCli
150
150
  * Used when a trigger is deleted
151
151
  */
152
152
  declare const cancelPendingInvocationsForTrigger: (db: AgentsRunDatabaseClient) => (params: {
153
- scopes: AgentScopeConfig;
153
+ scopes: ProjectScopeConfig;
154
154
  scheduledTriggerId: string;
155
155
  }) => Promise<number>;
156
156
  /**
@@ -158,7 +158,7 @@ declare const cancelPendingInvocationsForTrigger: (db: AgentsRunDatabaseClient)
158
158
  * Used when a trigger is disabled - keeps future invocations pending
159
159
  */
160
160
  declare const cancelPastPendingInvocationsForTrigger: (db: AgentsRunDatabaseClient) => (params: {
161
- scopes: AgentScopeConfig;
161
+ scopes: ProjectScopeConfig;
162
162
  scheduledTriggerId: string;
163
163
  }) => Promise<number>;
164
164
  type ScheduledTriggerRunInfo = {
@@ -199,7 +199,7 @@ declare const listUpcomingInvocationsForAgentPaginated: (db: AgentsRunDatabaseCl
199
199
  name: string;
200
200
  hash: string;
201
201
  } | null;
202
- status: "pending" | "running" | "completed" | "failed" | "cancelled";
202
+ status: "pending" | "failed" | "running" | "completed" | "cancelled";
203
203
  scheduledFor: string;
204
204
  startedAt: string | null;
205
205
  completedAt: string | null;
@@ -239,7 +239,7 @@ declare const listProjectScheduledTriggerInvocationsPaginated: (db: AgentsRunDat
239
239
  name: string;
240
240
  hash: string;
241
241
  } | null;
242
- status: "pending" | "running" | "completed" | "failed" | "cancelled";
242
+ status: "pending" | "failed" | "running" | "completed" | "cancelled";
243
243
  scheduledFor: string;
244
244
  startedAt: string | null;
245
245
  completedAt: string | null;
@@ -292,7 +292,7 @@ declare const listScheduledTriggerInvocationsByTriggerId: (db: AgentsRunDatabase
292
292
  name: string;
293
293
  hash: string;
294
294
  } | null;
295
- status: "pending" | "running" | "completed" | "failed" | "cancelled";
295
+ status: "pending" | "failed" | "running" | "completed" | "cancelled";
296
296
  scheduledFor: string;
297
297
  startedAt: string | null;
298
298
  completedAt: string | null;
@@ -307,5 +307,37 @@ declare const listScheduledTriggerInvocationsByTriggerId: (db: AgentsRunDatabase
307
307
  tenantId: string;
308
308
  id: string;
309
309
  }[]>;
310
+ declare const listScheduledTriggerInvocationsByDatasetRunId: (db: AgentsRunDatabaseClient) => (params: {
311
+ scopes: ProjectScopeConfig;
312
+ datasetRunId: string;
313
+ filters?: {
314
+ status?: string;
315
+ };
316
+ }) => Promise<{
317
+ scheduledTriggerId: string;
318
+ ref: {
319
+ type: "commit" | "tag" | "branch";
320
+ name: string;
321
+ hash: string;
322
+ } | null;
323
+ status: "pending" | "failed" | "running" | "completed" | "cancelled";
324
+ scheduledFor: string;
325
+ startedAt: string | null;
326
+ completedAt: string | null;
327
+ resolvedPayload: Record<string, unknown> | null;
328
+ conversationIds: string[] | null;
329
+ attemptNumber: number;
330
+ idempotencyKey: string;
331
+ runAsUserId: string | null;
332
+ createdAt: string;
333
+ agentId: string;
334
+ projectId: string;
335
+ tenantId: string;
336
+ id: string;
337
+ }[]>;
338
+ declare const getLastRunAtForTrigger: (db: AgentsRunDatabaseClient) => (params: {
339
+ scopes: ProjectScopeConfig;
340
+ scheduledTriggerId: string;
341
+ }) => Promise<string | null>;
310
342
  //#endregion
311
- export { ScheduledTriggerRunInfo, addConversationIdToInvocation, cancelPastPendingInvocationsForTrigger, cancelPendingInvocationsForTrigger, createScheduledTriggerInvocation, deletePendingInvocationsForTrigger, getScheduledTriggerInvocationById, getScheduledTriggerInvocationByIdempotencyKey, getScheduledTriggerInvocationStatusSummary, getScheduledTriggerRunInfoBatch, listPendingScheduledTriggerInvocations, listProjectScheduledTriggerInvocationsPaginated, listScheduledTriggerInvocationsByTriggerId, listScheduledTriggerInvocationsPaginated, listUpcomingInvocationsForAgentPaginated, markScheduledTriggerInvocationCancelled, markScheduledTriggerInvocationCompleted, markScheduledTriggerInvocationFailed, markScheduledTriggerInvocationRunning, resetCancelledInvocationToPending, updateScheduledTriggerInvocationStatus };
343
+ export { ScheduledTriggerRunInfo, addConversationIdToInvocation, cancelPastPendingInvocationsForTrigger, cancelPendingInvocationsForTrigger, createScheduledTriggerInvocation, deletePendingInvocationsForTrigger, getLastRunAtForTrigger, getScheduledTriggerInvocationById, getScheduledTriggerInvocationByIdempotencyKey, getScheduledTriggerInvocationStatusSummary, getScheduledTriggerRunInfoBatch, listPendingScheduledTriggerInvocations, listProjectScheduledTriggerInvocationsPaginated, listScheduledTriggerInvocationsByDatasetRunId, listScheduledTriggerInvocationsByTriggerId, listScheduledTriggerInvocationsPaginated, listUpcomingInvocationsForAgentPaginated, markScheduledTriggerInvocationCancelled, markScheduledTriggerInvocationCompleted, markScheduledTriggerInvocationFailed, markScheduledTriggerInvocationRunning, resetCancelledInvocationToPending, updateScheduledTriggerInvocationStatus };
@@ -133,7 +133,7 @@ const cancelPendingInvocationsForTrigger = (db) => async (params) => {
133
133
  return (await db.update(scheduledTriggerInvocations).set({
134
134
  status: "cancelled",
135
135
  completedAt: (/* @__PURE__ */ new Date()).toISOString()
136
- }).where(and(agentScopedWhere(scheduledTriggerInvocations, params.scopes), eq(scheduledTriggerInvocations.scheduledTriggerId, params.scheduledTriggerId), inArray(scheduledTriggerInvocations.status, ["pending", "running"]))).returning()).length;
136
+ }).where(and(projectScopedWhere(scheduledTriggerInvocations, params.scopes), eq(scheduledTriggerInvocations.scheduledTriggerId, params.scheduledTriggerId), inArray(scheduledTriggerInvocations.status, ["pending", "running"]))).returning()).length;
137
137
  };
138
138
  /**
139
139
  * Cancel only PAST pending invocations for a trigger (scheduledFor <= now)
@@ -144,7 +144,7 @@ const cancelPastPendingInvocationsForTrigger = (db) => async (params) => {
144
144
  return (await db.update(scheduledTriggerInvocations).set({
145
145
  status: "cancelled",
146
146
  completedAt: now
147
- }).where(and(agentScopedWhere(scheduledTriggerInvocations, params.scopes), eq(scheduledTriggerInvocations.scheduledTriggerId, params.scheduledTriggerId), inArray(scheduledTriggerInvocations.status, ["pending", "running"]), lte(scheduledTriggerInvocations.scheduledFor, now))).returning()).length;
147
+ }).where(and(projectScopedWhere(scheduledTriggerInvocations, params.scopes), eq(scheduledTriggerInvocations.scheduledTriggerId, params.scheduledTriggerId), inArray(scheduledTriggerInvocations.status, ["pending", "running"]), lte(scheduledTriggerInvocations.scheduledFor, now))).returning()).length;
148
148
  };
149
149
  /**
150
150
  * Get run info for multiple scheduled triggers in a single query.
@@ -314,6 +314,19 @@ const listScheduledTriggerInvocationsByTriggerId = (db) => async (params) => {
314
314
  if (params.filters?.status) conditions.push(eq(scheduledTriggerInvocations.status, params.filters.status));
315
315
  return await db.select().from(scheduledTriggerInvocations).where(and(...conditions)).orderBy(asc(scheduledTriggerInvocations.createdAt));
316
316
  };
317
+ const listScheduledTriggerInvocationsByDatasetRunId = (db) => async (params) => {
318
+ const conditions = [
319
+ eq(scheduledTriggerInvocations.tenantId, params.scopes.tenantId),
320
+ eq(scheduledTriggerInvocations.projectId, params.scopes.projectId),
321
+ sql`${scheduledTriggerInvocations.resolvedPayload}->>'datasetRunId' = ${params.datasetRunId}`
322
+ ];
323
+ if (params.filters?.status) conditions.push(eq(scheduledTriggerInvocations.status, params.filters.status));
324
+ return await db.select().from(scheduledTriggerInvocations).where(and(...conditions)).orderBy(asc(scheduledTriggerInvocations.createdAt));
325
+ };
326
+ const getLastRunAtForTrigger = (db) => async (params) => {
327
+ const [row] = await db.select({ completedAt: scheduledTriggerInvocations.completedAt }).from(scheduledTriggerInvocations).where(and(eq(scheduledTriggerInvocations.tenantId, params.scopes.tenantId), eq(scheduledTriggerInvocations.projectId, params.scopes.projectId), eq(scheduledTriggerInvocations.scheduledTriggerId, params.scheduledTriggerId), inArray(scheduledTriggerInvocations.status, ["completed", "failed"]))).orderBy(desc(scheduledTriggerInvocations.completedAt)).limit(1);
328
+ return row?.completedAt ?? null;
329
+ };
317
330
 
318
331
  //#endregion
319
- export { addConversationIdToInvocation, cancelPastPendingInvocationsForTrigger, cancelPendingInvocationsForTrigger, createScheduledTriggerInvocation, deletePendingInvocationsForTrigger, getScheduledTriggerInvocationById, getScheduledTriggerInvocationByIdempotencyKey, getScheduledTriggerInvocationStatusSummary, getScheduledTriggerRunInfoBatch, listPendingScheduledTriggerInvocations, listProjectScheduledTriggerInvocationsPaginated, listScheduledTriggerInvocationsByTriggerId, listScheduledTriggerInvocationsPaginated, listUpcomingInvocationsForAgentPaginated, markScheduledTriggerInvocationCancelled, markScheduledTriggerInvocationCompleted, markScheduledTriggerInvocationFailed, markScheduledTriggerInvocationRunning, resetCancelledInvocationToPending, updateScheduledTriggerInvocationStatus };
332
+ export { addConversationIdToInvocation, cancelPastPendingInvocationsForTrigger, cancelPendingInvocationsForTrigger, createScheduledTriggerInvocation, deletePendingInvocationsForTrigger, getLastRunAtForTrigger, getScheduledTriggerInvocationById, getScheduledTriggerInvocationByIdempotencyKey, getScheduledTriggerInvocationStatusSummary, getScheduledTriggerRunInfoBatch, listPendingScheduledTriggerInvocations, listProjectScheduledTriggerInvocationsPaginated, listScheduledTriggerInvocationsByDatasetRunId, listScheduledTriggerInvocationsByTriggerId, listScheduledTriggerInvocationsPaginated, listUpcomingInvocationsForAgentPaginated, markScheduledTriggerInvocationCancelled, markScheduledTriggerInvocationCompleted, markScheduledTriggerInvocationFailed, markScheduledTriggerInvocationRunning, resetCancelledInvocationToPending, updateScheduledTriggerInvocationStatus };