@inkeep/agents-core 0.64.8 → 0.65.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/auth/auth-schema.d.ts +108 -108
- package/dist/auth/auth-validation-schemas.d.ts +154 -154
- package/dist/auth/permissions.d.ts +9 -9
- package/dist/client-exports.d.ts +2 -2
- package/dist/client-exports.js +2 -2
- package/dist/data-access/index.d.ts +4 -3
- package/dist/data-access/index.js +3 -2
- package/dist/data-access/manage/agents.d.ts +42 -42
- package/dist/data-access/manage/artifactComponents.d.ts +8 -8
- package/dist/data-access/manage/contextConfigs.d.ts +8 -8
- package/dist/data-access/manage/dataComponents.d.ts +4 -4
- package/dist/data-access/manage/functionTools.d.ts +10 -10
- package/dist/data-access/manage/projectLifecycle.d.ts +6 -6
- package/dist/data-access/manage/projectLifecycle.js +42 -21
- package/dist/data-access/manage/skills.d.ts +9 -9
- package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +18 -18
- package/dist/data-access/manage/subAgentRelations.d.ts +26 -26
- package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +18 -18
- package/dist/data-access/manage/subAgents.d.ts +18 -18
- package/dist/data-access/manage/tools.d.ts +24 -24
- package/dist/data-access/manage/triggers.d.ts +2 -2
- package/dist/data-access/runtime/apiKeys.d.ts +16 -16
- package/dist/data-access/runtime/apps.d.ts +12 -12
- package/dist/data-access/runtime/cascade-delete.d.ts +2 -3
- package/dist/data-access/runtime/cascade-delete.js +10 -10
- package/dist/data-access/runtime/conversations.d.ts +24 -24
- package/dist/data-access/runtime/messages.d.ts +21 -21
- package/dist/data-access/runtime/scheduledTriggerInvocations.d.ts +22 -14
- package/dist/data-access/runtime/scheduledTriggerInvocations.js +67 -9
- package/dist/data-access/runtime/scheduledTriggerUsers.d.ts +54 -0
- package/dist/data-access/runtime/scheduledTriggerUsers.js +62 -0
- package/dist/data-access/runtime/scheduledTriggers.d.ts +1 -0
- package/dist/data-access/runtime/tasks.d.ts +6 -6
- package/dist/db/manage/dolt-safe-jsonb.d.ts +2 -2
- package/dist/db/manage/manage-schema.d.ts +449 -449
- package/dist/db/runtime/runtime-schema.d.ts +477 -360
- package/dist/db/runtime/runtime-schema.js +36 -2
- package/dist/index.d.ts +7 -6
- package/dist/index.js +5 -4
- package/dist/middleware/no-auth.d.ts +2 -2
- package/dist/types/entities.d.ts +6 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/validation/drizzle-schema-helpers.d.ts +3 -3
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +2 -2
- package/dist/validation/schemas/skills.d.ts +37 -37
- package/dist/validation/schemas.d.ts +2418 -2324
- package/dist/validation/schemas.js +26 -5
- package/drizzle/runtime/0032_sloppy_starfox.sql +17 -0
- package/drizzle/runtime/0033_backfill-scheduled-trigger-users.sql +7 -0
- package/drizzle/runtime/meta/0032_snapshot.json +5120 -0
- package/drizzle/runtime/meta/_journal.json +14 -0
- package/package.json +1 -1
|
@@ -16,19 +16,19 @@ declare const listConversations: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
16
16
|
}>;
|
|
17
17
|
declare const createConversation: (db: AgentsRunDatabaseClient) => (params: ConversationInsert) => Promise<{
|
|
18
18
|
id: string;
|
|
19
|
-
createdAt: string;
|
|
20
|
-
updatedAt: string;
|
|
21
19
|
ref: {
|
|
22
20
|
type: "commit" | "tag" | "branch";
|
|
23
21
|
name: string;
|
|
24
22
|
hash: string;
|
|
25
23
|
} | null;
|
|
24
|
+
title: string | null;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
updatedAt: string;
|
|
27
|
+
tenantId: string;
|
|
28
|
+
projectId: string;
|
|
29
|
+
agentId: string | null;
|
|
26
30
|
userId: string | null;
|
|
27
31
|
metadata: ConversationMetadata | null;
|
|
28
|
-
agentId: string | null;
|
|
29
|
-
projectId: string;
|
|
30
|
-
tenantId: string;
|
|
31
|
-
title: string | null;
|
|
32
32
|
activeSubAgentId: string;
|
|
33
33
|
lastContextResolution: string | null;
|
|
34
34
|
}>;
|
|
@@ -85,19 +85,19 @@ declare const getConversation: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
85
85
|
conversationId: string;
|
|
86
86
|
}) => Promise<{
|
|
87
87
|
id: string;
|
|
88
|
-
createdAt: string;
|
|
89
|
-
updatedAt: string;
|
|
90
88
|
ref: {
|
|
91
89
|
type: "commit" | "tag" | "branch";
|
|
92
90
|
name: string;
|
|
93
91
|
hash: string;
|
|
94
92
|
} | null;
|
|
93
|
+
title: string | null;
|
|
94
|
+
createdAt: string;
|
|
95
|
+
updatedAt: string;
|
|
96
|
+
tenantId: string;
|
|
97
|
+
projectId: string;
|
|
98
|
+
agentId: string | null;
|
|
95
99
|
userId: string | null;
|
|
96
100
|
metadata: ConversationMetadata | null;
|
|
97
|
-
agentId: string | null;
|
|
98
|
-
projectId: string;
|
|
99
|
-
tenantId: string;
|
|
100
|
-
title: string | null;
|
|
101
101
|
activeSubAgentId: string;
|
|
102
102
|
lastContextResolution: string | null;
|
|
103
103
|
} | undefined>;
|
|
@@ -121,19 +121,19 @@ declare const createOrGetConversation: (db: AgentsRunDatabaseClient) => (input:
|
|
|
121
121
|
contextConfigId?: string | undefined;
|
|
122
122
|
} | {
|
|
123
123
|
id: string;
|
|
124
|
-
createdAt: string;
|
|
125
|
-
updatedAt: string;
|
|
126
124
|
ref: {
|
|
127
125
|
type: "commit" | "tag" | "branch";
|
|
128
126
|
name: string;
|
|
129
127
|
hash: string;
|
|
130
128
|
} | null;
|
|
129
|
+
title: string | null;
|
|
130
|
+
createdAt: string;
|
|
131
|
+
updatedAt: string;
|
|
132
|
+
tenantId: string;
|
|
133
|
+
projectId: string;
|
|
134
|
+
agentId: string | null;
|
|
131
135
|
userId: string | null;
|
|
132
136
|
metadata: ConversationMetadata | null;
|
|
133
|
-
agentId: string | null;
|
|
134
|
-
projectId: string;
|
|
135
|
-
tenantId: string;
|
|
136
|
-
title: string | null;
|
|
137
137
|
activeSubAgentId: string;
|
|
138
138
|
lastContextResolution: string | null;
|
|
139
139
|
}>;
|
|
@@ -153,19 +153,19 @@ declare const getActiveAgentForConversation: (db: AgentsRunDatabaseClient) => (p
|
|
|
153
153
|
conversationId: string;
|
|
154
154
|
}) => Promise<{
|
|
155
155
|
id: string;
|
|
156
|
-
createdAt: string;
|
|
157
|
-
updatedAt: string;
|
|
158
156
|
ref: {
|
|
159
157
|
type: "commit" | "tag" | "branch";
|
|
160
158
|
name: string;
|
|
161
159
|
hash: string;
|
|
162
160
|
} | null;
|
|
161
|
+
title: string | null;
|
|
162
|
+
createdAt: string;
|
|
163
|
+
updatedAt: string;
|
|
164
|
+
tenantId: string;
|
|
165
|
+
projectId: string;
|
|
166
|
+
agentId: string | null;
|
|
163
167
|
userId: string | null;
|
|
164
168
|
metadata: ConversationMetadata | null;
|
|
165
|
-
agentId: string | null;
|
|
166
|
-
projectId: string;
|
|
167
|
-
tenantId: string;
|
|
168
|
-
title: string | null;
|
|
169
169
|
activeSubAgentId: string;
|
|
170
170
|
lastContextResolution: string | null;
|
|
171
171
|
} | undefined>;
|
|
@@ -13,23 +13,23 @@ declare const getMessageById: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
13
13
|
id: string;
|
|
14
14
|
createdAt: string;
|
|
15
15
|
updatedAt: string;
|
|
16
|
-
metadata: MessageMetadata | null;
|
|
17
|
-
role: string;
|
|
18
|
-
projectId: string;
|
|
19
16
|
tenantId: string;
|
|
17
|
+
projectId: string;
|
|
20
18
|
content: MessageContent;
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
metadata: MessageMetadata | null;
|
|
20
|
+
conversationId: string;
|
|
21
|
+
role: string;
|
|
23
22
|
fromSubAgentId: string | null;
|
|
24
23
|
toSubAgentId: string | null;
|
|
25
24
|
fromExternalAgentId: string | null;
|
|
26
25
|
toExternalAgentId: string | null;
|
|
27
|
-
a2aTaskId: string | null;
|
|
28
|
-
conversationId: string;
|
|
29
26
|
fromTeamAgentId: string | null;
|
|
30
27
|
toTeamAgentId: string | null;
|
|
28
|
+
visibility: string;
|
|
31
29
|
messageType: string;
|
|
30
|
+
taskId: string | null;
|
|
32
31
|
parentMessageId: string | null;
|
|
32
|
+
a2aTaskId: string | null;
|
|
33
33
|
a2aSessionId: string | null;
|
|
34
34
|
} | undefined>;
|
|
35
35
|
declare const listMessages: (db: AgentsRunDatabaseClient) => (params: {
|
|
@@ -147,23 +147,23 @@ declare const createMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
147
147
|
id: string;
|
|
148
148
|
createdAt: string;
|
|
149
149
|
updatedAt: string;
|
|
150
|
-
metadata: MessageMetadata | null;
|
|
151
|
-
role: string;
|
|
152
|
-
projectId: string;
|
|
153
150
|
tenantId: string;
|
|
151
|
+
projectId: string;
|
|
154
152
|
content: MessageContent;
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
metadata: MessageMetadata | null;
|
|
154
|
+
conversationId: string;
|
|
155
|
+
role: string;
|
|
157
156
|
fromSubAgentId: string | null;
|
|
158
157
|
toSubAgentId: string | null;
|
|
159
158
|
fromExternalAgentId: string | null;
|
|
160
159
|
toExternalAgentId: string | null;
|
|
161
|
-
a2aTaskId: string | null;
|
|
162
|
-
conversationId: string;
|
|
163
160
|
fromTeamAgentId: string | null;
|
|
164
161
|
toTeamAgentId: string | null;
|
|
162
|
+
visibility: string;
|
|
165
163
|
messageType: string;
|
|
164
|
+
taskId: string | null;
|
|
166
165
|
parentMessageId: string | null;
|
|
166
|
+
a2aTaskId: string | null;
|
|
167
167
|
a2aSessionId: string | null;
|
|
168
168
|
}>;
|
|
169
169
|
declare const updateMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
@@ -200,23 +200,23 @@ declare const deleteMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
200
200
|
id: string;
|
|
201
201
|
createdAt: string;
|
|
202
202
|
updatedAt: string;
|
|
203
|
-
metadata: MessageMetadata | null;
|
|
204
|
-
role: string;
|
|
205
|
-
projectId: string;
|
|
206
203
|
tenantId: string;
|
|
204
|
+
projectId: string;
|
|
207
205
|
content: MessageContent;
|
|
208
|
-
|
|
209
|
-
|
|
206
|
+
metadata: MessageMetadata | null;
|
|
207
|
+
conversationId: string;
|
|
208
|
+
role: string;
|
|
210
209
|
fromSubAgentId: string | null;
|
|
211
210
|
toSubAgentId: string | null;
|
|
212
211
|
fromExternalAgentId: string | null;
|
|
213
212
|
toExternalAgentId: string | null;
|
|
214
|
-
a2aTaskId: string | null;
|
|
215
|
-
conversationId: string;
|
|
216
213
|
fromTeamAgentId: string | null;
|
|
217
214
|
toTeamAgentId: string | null;
|
|
215
|
+
visibility: string;
|
|
218
216
|
messageType: string;
|
|
217
|
+
taskId: string | null;
|
|
219
218
|
parentMessageId: string | null;
|
|
219
|
+
a2aTaskId: string | null;
|
|
220
220
|
a2aSessionId: string | null;
|
|
221
221
|
}>;
|
|
222
222
|
declare const countMessagesByConversation: (db: AgentsRunDatabaseClient) => (params: {
|
|
@@ -2,7 +2,7 @@ import { AgentScopeConfig, ProjectScopeConfig } from "../../db/manage/scope-defi
|
|
|
2
2
|
import { PaginationConfig } from "../../types/utility.js";
|
|
3
3
|
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
4
4
|
import { ScheduledTriggerInvocationStatus } from "../../validation/schemas.js";
|
|
5
|
-
import { ScheduledTriggerInvocation, ScheduledTriggerInvocationInsert, ScheduledTriggerInvocationUpdate } from "../../types/entities.js";
|
|
5
|
+
import { LastRunSummary, ScheduledTriggerInvocation, ScheduledTriggerInvocationInsert, ScheduledTriggerInvocationUpdate } from "../../types/entities.js";
|
|
6
6
|
|
|
7
7
|
//#region src/data-access/runtime/scheduledTriggerInvocations.d.ts
|
|
8
8
|
/**
|
|
@@ -40,7 +40,7 @@ declare const listScheduledTriggerInvocationsPaginated: (db: AgentsRunDatabaseCl
|
|
|
40
40
|
name: string;
|
|
41
41
|
hash: string;
|
|
42
42
|
} | null;
|
|
43
|
-
status: "
|
|
43
|
+
status: "running" | "completed" | "failed" | "pending" | "cancelled";
|
|
44
44
|
scheduledFor: string;
|
|
45
45
|
startedAt: string | null;
|
|
46
46
|
completedAt: string | null;
|
|
@@ -48,6 +48,7 @@ declare const listScheduledTriggerInvocationsPaginated: (db: AgentsRunDatabaseCl
|
|
|
48
48
|
conversationIds: string[] | null;
|
|
49
49
|
attemptNumber: number;
|
|
50
50
|
idempotencyKey: string;
|
|
51
|
+
runAsUserId: string | null;
|
|
51
52
|
createdAt: string;
|
|
52
53
|
agentId: string;
|
|
53
54
|
projectId: string;
|
|
@@ -160,9 +161,18 @@ declare const cancelPastPendingInvocationsForTrigger: (db: AgentsRunDatabaseClie
|
|
|
160
161
|
scopes: AgentScopeConfig;
|
|
161
162
|
scheduledTriggerId: string;
|
|
162
163
|
}) => Promise<number>;
|
|
164
|
+
type ScheduledTriggerRunInfo = {
|
|
165
|
+
lastRunAt: string | null;
|
|
166
|
+
lastRunStatus: 'completed' | 'failed' | null;
|
|
167
|
+
lastRunConversationIds: string[];
|
|
168
|
+
nextRunAt: string | null;
|
|
169
|
+
lastRunSummary: LastRunSummary | null;
|
|
170
|
+
};
|
|
163
171
|
/**
|
|
164
|
-
* Get run info for multiple scheduled triggers in a single query
|
|
165
|
-
*
|
|
172
|
+
* Get run info for multiple scheduled triggers in a single query.
|
|
173
|
+
* Groups invocations by (triggerId, scheduledFor) to support multi-user triggers.
|
|
174
|
+
* Excludes manual runs (manual-run-* and manual-rerun-* idempotency keys).
|
|
175
|
+
* Returns lastRunSummary with per-status counts for the most recent scheduled tick.
|
|
166
176
|
*/
|
|
167
177
|
declare const getScheduledTriggerRunInfoBatch: (db: AgentsRunDatabaseClient) => (params: {
|
|
168
178
|
scopes: Omit<AgentScopeConfig, "agentId">;
|
|
@@ -170,12 +180,7 @@ declare const getScheduledTriggerRunInfoBatch: (db: AgentsRunDatabaseClient) =>
|
|
|
170
180
|
agentId: string;
|
|
171
181
|
triggerId: string;
|
|
172
182
|
}>;
|
|
173
|
-
}) => Promise<Map<string,
|
|
174
|
-
lastRunAt: string | null;
|
|
175
|
-
lastRunStatus: "completed" | "failed" | null;
|
|
176
|
-
lastRunConversationIds: string[];
|
|
177
|
-
nextRunAt: string | null;
|
|
178
|
-
}>>;
|
|
183
|
+
}) => Promise<Map<string, ScheduledTriggerRunInfo>>;
|
|
179
184
|
/**
|
|
180
185
|
* List upcoming invocations across ALL triggers for an agent with pagination
|
|
181
186
|
* Used for the upcoming runs dashboard with full pagination support
|
|
@@ -194,7 +199,7 @@ declare const listUpcomingInvocationsForAgentPaginated: (db: AgentsRunDatabaseCl
|
|
|
194
199
|
name: string;
|
|
195
200
|
hash: string;
|
|
196
201
|
} | null;
|
|
197
|
-
status: "
|
|
202
|
+
status: "running" | "completed" | "failed" | "pending" | "cancelled";
|
|
198
203
|
scheduledFor: string;
|
|
199
204
|
startedAt: string | null;
|
|
200
205
|
completedAt: string | null;
|
|
@@ -202,6 +207,7 @@ declare const listUpcomingInvocationsForAgentPaginated: (db: AgentsRunDatabaseCl
|
|
|
202
207
|
conversationIds: string[] | null;
|
|
203
208
|
attemptNumber: number;
|
|
204
209
|
idempotencyKey: string;
|
|
210
|
+
runAsUserId: string | null;
|
|
205
211
|
createdAt: string;
|
|
206
212
|
agentId: string;
|
|
207
213
|
projectId: string;
|
|
@@ -233,7 +239,7 @@ declare const listProjectScheduledTriggerInvocationsPaginated: (db: AgentsRunDat
|
|
|
233
239
|
name: string;
|
|
234
240
|
hash: string;
|
|
235
241
|
} | null;
|
|
236
|
-
status: "
|
|
242
|
+
status: "running" | "completed" | "failed" | "pending" | "cancelled";
|
|
237
243
|
scheduledFor: string;
|
|
238
244
|
startedAt: string | null;
|
|
239
245
|
completedAt: string | null;
|
|
@@ -241,6 +247,7 @@ declare const listProjectScheduledTriggerInvocationsPaginated: (db: AgentsRunDat
|
|
|
241
247
|
conversationIds: string[] | null;
|
|
242
248
|
attemptNumber: number;
|
|
243
249
|
idempotencyKey: string;
|
|
250
|
+
runAsUserId: string | null;
|
|
244
251
|
createdAt: string;
|
|
245
252
|
agentId: string;
|
|
246
253
|
projectId: string;
|
|
@@ -285,7 +292,7 @@ declare const listScheduledTriggerInvocationsByTriggerId: (db: AgentsRunDatabase
|
|
|
285
292
|
name: string;
|
|
286
293
|
hash: string;
|
|
287
294
|
} | null;
|
|
288
|
-
status: "
|
|
295
|
+
status: "running" | "completed" | "failed" | "pending" | "cancelled";
|
|
289
296
|
scheduledFor: string;
|
|
290
297
|
startedAt: string | null;
|
|
291
298
|
completedAt: string | null;
|
|
@@ -293,6 +300,7 @@ declare const listScheduledTriggerInvocationsByTriggerId: (db: AgentsRunDatabase
|
|
|
293
300
|
conversationIds: string[] | null;
|
|
294
301
|
attemptNumber: number;
|
|
295
302
|
idempotencyKey: string;
|
|
303
|
+
runAsUserId: string | null;
|
|
296
304
|
createdAt: string;
|
|
297
305
|
agentId: string;
|
|
298
306
|
projectId: string;
|
|
@@ -300,4 +308,4 @@ declare const listScheduledTriggerInvocationsByTriggerId: (db: AgentsRunDatabase
|
|
|
300
308
|
id: string;
|
|
301
309
|
}[]>;
|
|
302
310
|
//#endregion
|
|
303
|
-
export { addConversationIdToInvocation, cancelPastPendingInvocationsForTrigger, cancelPendingInvocationsForTrigger, createScheduledTriggerInvocation, deletePendingInvocationsForTrigger, getScheduledTriggerInvocationById, getScheduledTriggerInvocationByIdempotencyKey, getScheduledTriggerInvocationStatusSummary, getScheduledTriggerRunInfoBatch, listPendingScheduledTriggerInvocations, listProjectScheduledTriggerInvocationsPaginated, listScheduledTriggerInvocationsByTriggerId, listScheduledTriggerInvocationsPaginated, listUpcomingInvocationsForAgentPaginated, markScheduledTriggerInvocationCancelled, markScheduledTriggerInvocationCompleted, markScheduledTriggerInvocationFailed, markScheduledTriggerInvocationRunning, resetCancelledInvocationToPending, updateScheduledTriggerInvocationStatus };
|
|
311
|
+
export { ScheduledTriggerRunInfo, addConversationIdToInvocation, cancelPastPendingInvocationsForTrigger, cancelPendingInvocationsForTrigger, createScheduledTriggerInvocation, deletePendingInvocationsForTrigger, getScheduledTriggerInvocationById, getScheduledTriggerInvocationByIdempotencyKey, getScheduledTriggerInvocationStatusSummary, getScheduledTriggerRunInfoBatch, listPendingScheduledTriggerInvocations, listProjectScheduledTriggerInvocationsPaginated, listScheduledTriggerInvocationsByTriggerId, listScheduledTriggerInvocationsPaginated, listUpcomingInvocationsForAgentPaginated, markScheduledTriggerInvocationCancelled, markScheduledTriggerInvocationCompleted, markScheduledTriggerInvocationFailed, markScheduledTriggerInvocationRunning, resetCancelledInvocationToPending, updateScheduledTriggerInvocationStatus };
|
|
@@ -147,33 +147,91 @@ const cancelPastPendingInvocationsForTrigger = (db) => async (params) => {
|
|
|
147
147
|
}).where(and(agentScopedWhere(scheduledTriggerInvocations, params.scopes), eq(scheduledTriggerInvocations.scheduledTriggerId, params.scheduledTriggerId), inArray(scheduledTriggerInvocations.status, ["pending", "running"]), lte(scheduledTriggerInvocations.scheduledFor, now))).returning()).length;
|
|
148
148
|
};
|
|
149
149
|
/**
|
|
150
|
-
* Get run info for multiple scheduled triggers in a single query
|
|
151
|
-
*
|
|
150
|
+
* Get run info for multiple scheduled triggers in a single query.
|
|
151
|
+
* Groups invocations by (triggerId, scheduledFor) to support multi-user triggers.
|
|
152
|
+
* Excludes manual runs (manual-run-* and manual-rerun-* idempotency keys).
|
|
153
|
+
* Returns lastRunSummary with per-status counts for the most recent scheduled tick.
|
|
152
154
|
*/
|
|
153
155
|
const getScheduledTriggerRunInfoBatch = (db) => async (params) => {
|
|
154
156
|
if (params.triggerIds.length === 0) return /* @__PURE__ */ new Map();
|
|
157
|
+
const triggerIdValues = params.triggerIds.map((t) => t.triggerId);
|
|
155
158
|
const allInvocations = await db.select({
|
|
156
159
|
scheduledTriggerId: scheduledTriggerInvocations.scheduledTriggerId,
|
|
157
160
|
status: scheduledTriggerInvocations.status,
|
|
158
161
|
scheduledFor: scheduledTriggerInvocations.scheduledFor,
|
|
159
162
|
completedAt: scheduledTriggerInvocations.completedAt,
|
|
160
|
-
conversationIds: scheduledTriggerInvocations.conversationIds
|
|
161
|
-
|
|
163
|
+
conversationIds: scheduledTriggerInvocations.conversationIds,
|
|
164
|
+
idempotencyKey: scheduledTriggerInvocations.idempotencyKey
|
|
165
|
+
}).from(scheduledTriggerInvocations).where(and(projectScopedWhere(scheduledTriggerInvocations, params.scopes), inArray(scheduledTriggerInvocations.scheduledTriggerId, triggerIdValues))).orderBy(desc(scheduledTriggerInvocations.scheduledFor));
|
|
162
166
|
const result = /* @__PURE__ */ new Map();
|
|
163
167
|
for (const trigger of params.triggerIds) result.set(trigger.triggerId, {
|
|
164
168
|
lastRunAt: null,
|
|
165
169
|
lastRunStatus: null,
|
|
166
170
|
lastRunConversationIds: [],
|
|
167
|
-
nextRunAt: null
|
|
171
|
+
nextRunAt: null,
|
|
172
|
+
lastRunSummary: null
|
|
168
173
|
});
|
|
174
|
+
const isManualRun = (key) => key.startsWith("manual-run-") || key.startsWith("manual-rerun-");
|
|
175
|
+
const tickMap = /* @__PURE__ */ new Map();
|
|
169
176
|
for (const inv of allInvocations) {
|
|
170
177
|
const triggerInfo = result.get(inv.scheduledTriggerId);
|
|
171
178
|
if (!triggerInfo) continue;
|
|
172
179
|
if (inv.status === "pending" && !triggerInfo.nextRunAt) triggerInfo.nextRunAt = inv.scheduledFor;
|
|
173
|
-
if ((inv.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
180
|
+
if (isManualRun(inv.idempotencyKey)) continue;
|
|
181
|
+
let triggerTicks = tickMap.get(inv.scheduledTriggerId);
|
|
182
|
+
if (!triggerTicks) {
|
|
183
|
+
triggerTicks = /* @__PURE__ */ new Map();
|
|
184
|
+
tickMap.set(inv.scheduledTriggerId, triggerTicks);
|
|
185
|
+
}
|
|
186
|
+
let tickInvocations = triggerTicks.get(inv.scheduledFor);
|
|
187
|
+
if (!tickInvocations) {
|
|
188
|
+
tickInvocations = [];
|
|
189
|
+
triggerTicks.set(inv.scheduledFor, tickInvocations);
|
|
190
|
+
}
|
|
191
|
+
tickInvocations.push({
|
|
192
|
+
status: inv.status,
|
|
193
|
+
completedAt: inv.completedAt,
|
|
194
|
+
conversationIds: inv.conversationIds
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
for (const [triggerId, triggerTicks] of tickMap) {
|
|
198
|
+
const triggerInfo = result.get(triggerId);
|
|
199
|
+
if (!triggerInfo) continue;
|
|
200
|
+
let bestScheduledFor = null;
|
|
201
|
+
let bestInvocations = null;
|
|
202
|
+
for (const [scheduledFor, invocations] of triggerTicks) {
|
|
203
|
+
if (!invocations.some((i) => i.status === "completed" || i.status === "failed")) continue;
|
|
204
|
+
if (!bestScheduledFor || scheduledFor > bestScheduledFor) {
|
|
205
|
+
bestScheduledFor = scheduledFor;
|
|
206
|
+
bestInvocations = invocations;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (bestInvocations) {
|
|
210
|
+
const summary = {
|
|
211
|
+
total: bestInvocations.length,
|
|
212
|
+
completed: 0,
|
|
213
|
+
failed: 0,
|
|
214
|
+
running: 0,
|
|
215
|
+
pending: 0
|
|
216
|
+
};
|
|
217
|
+
let maxCompletedAt = null;
|
|
218
|
+
for (const inv of bestInvocations) {
|
|
219
|
+
if (inv.status === "completed") summary.completed++;
|
|
220
|
+
else if (inv.status === "failed") summary.failed++;
|
|
221
|
+
else if (inv.status === "running") summary.running++;
|
|
222
|
+
else if (inv.status === "pending") summary.pending++;
|
|
223
|
+
if (inv.completedAt && (!maxCompletedAt || inv.completedAt > maxCompletedAt)) maxCompletedAt = inv.completedAt;
|
|
224
|
+
}
|
|
225
|
+
triggerInfo.lastRunAt = maxCompletedAt;
|
|
226
|
+
triggerInfo.lastRunSummary = summary;
|
|
227
|
+
if (summary.failed > 0) triggerInfo.lastRunStatus = "failed";
|
|
228
|
+
else if (summary.completed > 0) triggerInfo.lastRunStatus = "completed";
|
|
229
|
+
const allConvIds = [];
|
|
230
|
+
for (const inv of bestInvocations) {
|
|
231
|
+
const ids = inv.conversationIds;
|
|
232
|
+
if (ids) for (const id of ids) allConvIds.push(id);
|
|
233
|
+
}
|
|
234
|
+
triggerInfo.lastRunConversationIds = allConvIds;
|
|
177
235
|
}
|
|
178
236
|
}
|
|
179
237
|
return result;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
2
|
+
|
|
3
|
+
//#region src/data-access/runtime/scheduledTriggerUsers.d.ts
|
|
4
|
+
declare const getScheduledTriggerUsers: (db: AgentsRunDatabaseClient) => (params: {
|
|
5
|
+
tenantId: string;
|
|
6
|
+
scheduledTriggerId: string;
|
|
7
|
+
}) => Promise<{
|
|
8
|
+
tenantId: string;
|
|
9
|
+
scheduledTriggerId: string;
|
|
10
|
+
userId: string;
|
|
11
|
+
createdAt: string;
|
|
12
|
+
}[]>;
|
|
13
|
+
declare const createScheduledTriggerUser: (db: AgentsRunDatabaseClient) => (params: {
|
|
14
|
+
tenantId: string;
|
|
15
|
+
scheduledTriggerId: string;
|
|
16
|
+
userId: string;
|
|
17
|
+
}) => Promise<{
|
|
18
|
+
createdAt: string;
|
|
19
|
+
tenantId: string;
|
|
20
|
+
userId: string;
|
|
21
|
+
scheduledTriggerId: string;
|
|
22
|
+
}>;
|
|
23
|
+
declare const deleteScheduledTriggerUser: (db: AgentsRunDatabaseClient) => (params: {
|
|
24
|
+
tenantId: string;
|
|
25
|
+
scheduledTriggerId: string;
|
|
26
|
+
userId: string;
|
|
27
|
+
}) => Promise<void>;
|
|
28
|
+
declare const setScheduledTriggerUsers: (db: AgentsRunDatabaseClient) => (params: {
|
|
29
|
+
tenantId: string;
|
|
30
|
+
scheduledTriggerId: string;
|
|
31
|
+
userIds: string[];
|
|
32
|
+
}) => Promise<void>;
|
|
33
|
+
declare const getScheduledTriggerUserCount: (db: AgentsRunDatabaseClient) => (params: {
|
|
34
|
+
tenantId: string;
|
|
35
|
+
scheduledTriggerId: string;
|
|
36
|
+
}) => Promise<number>;
|
|
37
|
+
declare const getTriggerIdsWithUser: (db: AgentsRunDatabaseClient) => (params: {
|
|
38
|
+
tenantId: string;
|
|
39
|
+
projectId: string;
|
|
40
|
+
userId: string;
|
|
41
|
+
}) => Promise<{
|
|
42
|
+
id: string;
|
|
43
|
+
}[]>;
|
|
44
|
+
declare const removeUserFromProjectScheduledTriggers: (db: AgentsRunDatabaseClient) => (params: {
|
|
45
|
+
tenantId: string;
|
|
46
|
+
projectId: string;
|
|
47
|
+
userId: string;
|
|
48
|
+
}) => Promise<void>;
|
|
49
|
+
declare const getScheduledTriggerUsersBatch: (db: AgentsRunDatabaseClient) => (params: {
|
|
50
|
+
tenantId: string;
|
|
51
|
+
scheduledTriggerIds: string[];
|
|
52
|
+
}) => Promise<Map<string, string[]>>;
|
|
53
|
+
//#endregion
|
|
54
|
+
export { createScheduledTriggerUser, deleteScheduledTriggerUser, getScheduledTriggerUserCount, getScheduledTriggerUsers, getScheduledTriggerUsersBatch, getTriggerIdsWithUser, removeUserFromProjectScheduledTriggers, setScheduledTriggerUsers };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { scheduledTriggerUsers, scheduledTriggers } from "../../db/runtime/runtime-schema.js";
|
|
2
|
+
import { and, asc, count, eq, inArray } from "drizzle-orm";
|
|
3
|
+
|
|
4
|
+
//#region src/data-access/runtime/scheduledTriggerUsers.ts
|
|
5
|
+
const getScheduledTriggerUsers = (db) => async (params) => {
|
|
6
|
+
return await db.select().from(scheduledTriggerUsers).where(and(eq(scheduledTriggerUsers.tenantId, params.tenantId), eq(scheduledTriggerUsers.scheduledTriggerId, params.scheduledTriggerId))).orderBy(asc(scheduledTriggerUsers.createdAt));
|
|
7
|
+
};
|
|
8
|
+
const createScheduledTriggerUser = (db) => async (params) => {
|
|
9
|
+
return (await db.insert(scheduledTriggerUsers).values({
|
|
10
|
+
tenantId: params.tenantId,
|
|
11
|
+
scheduledTriggerId: params.scheduledTriggerId,
|
|
12
|
+
userId: params.userId
|
|
13
|
+
}).onConflictDoNothing().returning())[0];
|
|
14
|
+
};
|
|
15
|
+
const deleteScheduledTriggerUser = (db) => async (params) => {
|
|
16
|
+
await db.delete(scheduledTriggerUsers).where(and(eq(scheduledTriggerUsers.tenantId, params.tenantId), eq(scheduledTriggerUsers.scheduledTriggerId, params.scheduledTriggerId), eq(scheduledTriggerUsers.userId, params.userId)));
|
|
17
|
+
};
|
|
18
|
+
const setScheduledTriggerUsers = (db) => async (params) => {
|
|
19
|
+
await db.transaction(async (tx) => {
|
|
20
|
+
await tx.delete(scheduledTriggerUsers).where(and(eq(scheduledTriggerUsers.tenantId, params.tenantId), eq(scheduledTriggerUsers.scheduledTriggerId, params.scheduledTriggerId)));
|
|
21
|
+
if (params.userIds.length > 0) await tx.insert(scheduledTriggerUsers).values(params.userIds.map((userId) => ({
|
|
22
|
+
tenantId: params.tenantId,
|
|
23
|
+
scheduledTriggerId: params.scheduledTriggerId,
|
|
24
|
+
userId
|
|
25
|
+
})));
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const getScheduledTriggerUserCount = (db) => async (params) => {
|
|
29
|
+
return (await db.select({ count: count() }).from(scheduledTriggerUsers).where(and(eq(scheduledTriggerUsers.tenantId, params.tenantId), eq(scheduledTriggerUsers.scheduledTriggerId, params.scheduledTriggerId))))[0]?.count ?? 0;
|
|
30
|
+
};
|
|
31
|
+
const getTriggerIdsWithUser = (db) => async (params) => {
|
|
32
|
+
return db.select({ id: scheduledTriggers.id }).from(scheduledTriggers).innerJoin(scheduledTriggerUsers, and(eq(scheduledTriggerUsers.tenantId, scheduledTriggers.tenantId), eq(scheduledTriggerUsers.scheduledTriggerId, scheduledTriggers.id))).where(and(eq(scheduledTriggers.tenantId, params.tenantId), eq(scheduledTriggers.projectId, params.projectId), eq(scheduledTriggerUsers.userId, params.userId)));
|
|
33
|
+
};
|
|
34
|
+
const removeUserFromProjectScheduledTriggers = (db) => async (params) => {
|
|
35
|
+
await db.transaction(async (tx) => {
|
|
36
|
+
const triggerIdsWithUser = await getTriggerIdsWithUser(tx)(params);
|
|
37
|
+
if (triggerIdsWithUser.length === 0) return;
|
|
38
|
+
const triggerIds = triggerIdsWithUser.map((t) => t.id);
|
|
39
|
+
await tx.delete(scheduledTriggerUsers).where(and(eq(scheduledTriggerUsers.tenantId, params.tenantId), inArray(scheduledTriggerUsers.scheduledTriggerId, triggerIds), eq(scheduledTriggerUsers.userId, params.userId)));
|
|
40
|
+
const triggersWithRemainingUsers = await tx.select({ triggerId: scheduledTriggerUsers.scheduledTriggerId }).from(scheduledTriggerUsers).where(and(eq(scheduledTriggerUsers.tenantId, params.tenantId), inArray(scheduledTriggerUsers.scheduledTriggerId, triggerIds))).groupBy(scheduledTriggerUsers.scheduledTriggerId);
|
|
41
|
+
const triggerIdsWithRemainingUsers = new Set(triggersWithRemainingUsers.map((r) => r.triggerId));
|
|
42
|
+
const emptyTriggerIds = triggerIds.filter((id) => !triggerIdsWithRemainingUsers.has(id));
|
|
43
|
+
if (emptyTriggerIds.length > 0) await tx.update(scheduledTriggers).set({
|
|
44
|
+
enabled: false,
|
|
45
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
46
|
+
}).where(and(eq(scheduledTriggers.tenantId, params.tenantId), inArray(scheduledTriggers.id, emptyTriggerIds), eq(scheduledTriggers.enabled, true)));
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
const getScheduledTriggerUsersBatch = (db) => async (params) => {
|
|
50
|
+
if (params.scheduledTriggerIds.length === 0) return /* @__PURE__ */ new Map();
|
|
51
|
+
const rows = await db.select().from(scheduledTriggerUsers).where(and(eq(scheduledTriggerUsers.tenantId, params.tenantId), inArray(scheduledTriggerUsers.scheduledTriggerId, params.scheduledTriggerIds))).orderBy(asc(scheduledTriggerUsers.createdAt));
|
|
52
|
+
const result = /* @__PURE__ */ new Map();
|
|
53
|
+
for (const id of params.scheduledTriggerIds) result.set(id, []);
|
|
54
|
+
for (const row of rows) {
|
|
55
|
+
const users = result.get(row.scheduledTriggerId);
|
|
56
|
+
if (users) users.push(row.userId);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { createScheduledTriggerUser, deleteScheduledTriggerUser, getScheduledTriggerUserCount, getScheduledTriggerUsers, getScheduledTriggerUsersBatch, getTriggerIdsWithUser, removeUserFromProjectScheduledTriggers, setScheduledTriggerUsers };
|
|
@@ -8,19 +8,19 @@ import { TaskInsert, TaskSelect } from "../../types/entities.js";
|
|
|
8
8
|
//#region src/data-access/runtime/tasks.d.ts
|
|
9
9
|
declare const createTask: (db: AgentsRunDatabaseClient) => (params: TaskInsert) => Promise<{
|
|
10
10
|
id: string;
|
|
11
|
-
createdAt: string;
|
|
12
|
-
updatedAt: string;
|
|
13
11
|
ref: {
|
|
14
12
|
type: "commit" | "tag" | "branch";
|
|
15
13
|
name: string;
|
|
16
14
|
hash: string;
|
|
17
15
|
} | null;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
agentId: string;
|
|
21
|
-
projectId: string;
|
|
16
|
+
createdAt: string;
|
|
17
|
+
updatedAt: string;
|
|
22
18
|
tenantId: string;
|
|
19
|
+
projectId: string;
|
|
20
|
+
agentId: string;
|
|
21
|
+
metadata: TaskMetadataConfig | null;
|
|
23
22
|
subAgentId: string;
|
|
23
|
+
status: string;
|
|
24
24
|
contextId: string;
|
|
25
25
|
}>;
|
|
26
26
|
declare const getTask: (db: AgentsRunDatabaseClient) => (params: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as drizzle_orm_pg_core0 from "drizzle-orm/pg-core";
|
|
2
2
|
|
|
3
3
|
//#region src/db/manage/dolt-safe-jsonb.d.ts
|
|
4
4
|
declare function encodeBackslashes(value: unknown): unknown;
|
|
@@ -7,6 +7,6 @@ declare function decodeBackslashes(value: unknown): unknown;
|
|
|
7
7
|
* Drop-in replacement for drizzle-orm's `jsonb()`.
|
|
8
8
|
* Encodes backslashes on write and decodes on read to work around the Doltgres bug.
|
|
9
9
|
*/
|
|
10
|
-
declare function jsonb(name: string): ReturnType<typeof
|
|
10
|
+
declare function jsonb(name: string): ReturnType<typeof drizzle_orm_pg_core0.jsonb>;
|
|
11
11
|
//#endregion
|
|
12
12
|
export { decodeBackslashes, encodeBackslashes, jsonb };
|