@inkeep/agents-core 0.0.0-dev-20260119170007 → 0.0.0-dev-20260120193424
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.d.ts +18 -18
- package/dist/auth/permissions.d.ts +9 -9
- package/dist/client-exports.d.ts +6 -2
- package/dist/client-exports.js +2 -2
- package/dist/constants/otel-attributes.d.ts +3 -0
- package/dist/constants/otel-attributes.js +3 -0
- package/dist/data-access/index.d.ts +3 -1
- package/dist/data-access/index.js +3 -1
- package/dist/data-access/manage/agentFull.js +114 -0
- package/dist/data-access/manage/agents.js +27 -0
- package/dist/data-access/manage/projectFull.d.ts +4 -0
- package/dist/data-access/manage/projectFull.js +31 -8
- package/dist/data-access/manage/triggers.d.ts +84 -0
- package/dist/data-access/manage/triggers.js +95 -0
- package/dist/data-access/runtime/evalRuns.d.ts +2 -2
- package/dist/data-access/runtime/evalRuns.js +11 -1
- package/dist/data-access/runtime/messages.d.ts +9 -9
- package/dist/data-access/runtime/tasks.d.ts +2 -2
- package/dist/data-access/runtime/triggerInvocations.d.ts +62 -0
- package/dist/data-access/runtime/triggerInvocations.js +54 -0
- package/dist/db/manage/manage-schema.d.ts +629 -364
- package/dist/db/manage/manage-schema.js +31 -2
- package/dist/db/runtime/runtime-schema.d.ts +382 -167
- package/dist/db/runtime/runtime-schema.js +33 -3
- package/dist/dolt/branch.d.ts +55 -1
- package/dist/dolt/branch.js +85 -1
- package/dist/dolt/index.d.ts +2 -2
- package/dist/dolt/index.js +2 -2
- package/dist/index.d.ts +10 -6
- package/dist/index.js +10 -6
- package/dist/types/entities.d.ts +14 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/template-interpolation.d.ts +22 -0
- package/dist/utils/template-interpolation.js +62 -0
- package/dist/utils/trigger-auth.d.ts +32 -0
- package/dist/utils/trigger-auth.js +130 -0
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +2 -2
- package/dist/validation/schemas.d.ts +3286 -1048
- package/dist/validation/schemas.js +87 -4
- package/drizzle/manage/0001_broken_wendell_vaughn.sql +19 -0
- package/drizzle/manage/meta/0001_snapshot.json +3115 -0
- package/drizzle/manage/meta/_journal.json +7 -0
- package/drizzle/runtime/0009_freezing_leo.sql +17 -0
- package/drizzle/runtime/meta/0009_snapshot.json +2397 -0
- package/drizzle/runtime/meta/_journal.json +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { AgentScopeConfig, PaginationConfig } from "../../types/utility.js";
|
|
2
|
+
import { AgentsManageDatabaseClient } from "../../db/manage/manage-client.js";
|
|
3
|
+
import { TriggerInsert, TriggerSelect, TriggerUpdate } from "../../types/entities.js";
|
|
4
|
+
|
|
5
|
+
//#region src/data-access/manage/triggers.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get a trigger by ID (agent-scoped)
|
|
9
|
+
* Uses withBranch to checkout the project's main branch and query using Drizzle ORM,
|
|
10
|
+
* which handles column name mapping automatically.
|
|
11
|
+
*/
|
|
12
|
+
declare const getTriggerById: (db: AgentsManageDatabaseClient) => (params: {
|
|
13
|
+
scopes: AgentScopeConfig;
|
|
14
|
+
triggerId: string;
|
|
15
|
+
/** If true, uses withBranch to read from the project branch. Default: true for non-branch-scoped clients */
|
|
16
|
+
useBranchScope?: boolean;
|
|
17
|
+
}) => Promise<TriggerSelect | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* List all triggers for an agent
|
|
20
|
+
*/
|
|
21
|
+
declare const listTriggers: (db: AgentsManageDatabaseClient) => (params: {
|
|
22
|
+
scopes: AgentScopeConfig;
|
|
23
|
+
}) => Promise<TriggerSelect[]>;
|
|
24
|
+
/**
|
|
25
|
+
* List triggers for an agent with pagination
|
|
26
|
+
*/
|
|
27
|
+
declare const listTriggersPaginated: (db: AgentsManageDatabaseClient) => (params: {
|
|
28
|
+
scopes: AgentScopeConfig;
|
|
29
|
+
pagination?: PaginationConfig;
|
|
30
|
+
}) => Promise<{
|
|
31
|
+
data: {
|
|
32
|
+
createdAt: string;
|
|
33
|
+
updatedAt: string;
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
inputSchema: Record<string, unknown> | null;
|
|
36
|
+
outputTransform: {
|
|
37
|
+
jmespath?: string;
|
|
38
|
+
objectTransformation?: Record<string, string>;
|
|
39
|
+
} | null;
|
|
40
|
+
messageTemplate: string;
|
|
41
|
+
authentication: unknown;
|
|
42
|
+
signingSecret: string | null;
|
|
43
|
+
name: string;
|
|
44
|
+
description: string | null;
|
|
45
|
+
agentId: string;
|
|
46
|
+
projectId: string;
|
|
47
|
+
tenantId: string;
|
|
48
|
+
id: string;
|
|
49
|
+
}[];
|
|
50
|
+
pagination: {
|
|
51
|
+
page: number;
|
|
52
|
+
limit: number;
|
|
53
|
+
total: number;
|
|
54
|
+
pages: number;
|
|
55
|
+
};
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Create a new trigger (agent-scoped)
|
|
59
|
+
*/
|
|
60
|
+
declare const createTrigger: (db: AgentsManageDatabaseClient) => (params: TriggerInsert) => Promise<TriggerSelect>;
|
|
61
|
+
/**
|
|
62
|
+
* Update a trigger (agent-scoped)
|
|
63
|
+
*/
|
|
64
|
+
declare const updateTrigger: (db: AgentsManageDatabaseClient) => (params: {
|
|
65
|
+
scopes: AgentScopeConfig;
|
|
66
|
+
triggerId: string;
|
|
67
|
+
data: TriggerUpdate;
|
|
68
|
+
}) => Promise<TriggerSelect>;
|
|
69
|
+
/**
|
|
70
|
+
* Delete a trigger (agent-scoped)
|
|
71
|
+
*/
|
|
72
|
+
declare const deleteTrigger: (db: AgentsManageDatabaseClient) => (params: {
|
|
73
|
+
scopes: AgentScopeConfig;
|
|
74
|
+
triggerId: string;
|
|
75
|
+
}) => Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Upsert a trigger (create or update based on existence)
|
|
78
|
+
*/
|
|
79
|
+
declare const upsertTrigger: (db: AgentsManageDatabaseClient) => (params: {
|
|
80
|
+
scopes: AgentScopeConfig;
|
|
81
|
+
data: TriggerInsert;
|
|
82
|
+
}) => Promise<TriggerSelect>;
|
|
83
|
+
//#endregion
|
|
84
|
+
export { createTrigger, deleteTrigger, getTriggerById, listTriggers, listTriggersPaginated, updateTrigger, upsertTrigger };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { triggers } from "../../db/manage/manage-schema.js";
|
|
2
|
+
import { getProjectBranchName, withBranch } from "../../dolt/branch.js";
|
|
3
|
+
import { and, count, desc, eq } from "drizzle-orm";
|
|
4
|
+
|
|
5
|
+
//#region src/data-access/manage/triggers.ts
|
|
6
|
+
/**
|
|
7
|
+
* Get a trigger by ID (agent-scoped)
|
|
8
|
+
* Uses withBranch to checkout the project's main branch and query using Drizzle ORM,
|
|
9
|
+
* which handles column name mapping automatically.
|
|
10
|
+
*/
|
|
11
|
+
const getTriggerById = (db) => async (params) => {
|
|
12
|
+
const { scopes, triggerId, useBranchScope = true } = params;
|
|
13
|
+
if (useBranchScope) {
|
|
14
|
+
const branchName = getProjectBranchName(scopes.tenantId, scopes.projectId);
|
|
15
|
+
try {
|
|
16
|
+
return await withBranch(db)({
|
|
17
|
+
branchName,
|
|
18
|
+
callback: async (txDb) => {
|
|
19
|
+
return await txDb.query.triggers.findFirst({ where: and(eq(triggers.tenantId, scopes.tenantId), eq(triggers.projectId, scopes.projectId), eq(triggers.agentId, scopes.agentId), eq(triggers.id, triggerId)) });
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
} catch {}
|
|
23
|
+
}
|
|
24
|
+
return await db.query.triggers.findFirst({ where: and(eq(triggers.tenantId, scopes.tenantId), eq(triggers.projectId, scopes.projectId), eq(triggers.agentId, scopes.agentId), eq(triggers.id, triggerId)) });
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* List all triggers for an agent
|
|
28
|
+
*/
|
|
29
|
+
const listTriggers = (db) => async (params) => {
|
|
30
|
+
return await db.query.triggers.findMany({ where: and(eq(triggers.tenantId, params.scopes.tenantId), eq(triggers.projectId, params.scopes.projectId), eq(triggers.agentId, params.scopes.agentId)) });
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* List triggers for an agent with pagination
|
|
34
|
+
*/
|
|
35
|
+
const listTriggersPaginated = (db) => async (params) => {
|
|
36
|
+
const page = params.pagination?.page || 1;
|
|
37
|
+
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
38
|
+
const offset = (page - 1) * limit;
|
|
39
|
+
const whereClause = and(eq(triggers.tenantId, params.scopes.tenantId), eq(triggers.projectId, params.scopes.projectId), eq(triggers.agentId, params.scopes.agentId));
|
|
40
|
+
const [data, totalResult] = await Promise.all([db.select().from(triggers).where(whereClause).limit(limit).offset(offset).orderBy(desc(triggers.createdAt)), db.select({ count: count() }).from(triggers).where(whereClause)]);
|
|
41
|
+
const total = totalResult[0]?.count || 0;
|
|
42
|
+
return {
|
|
43
|
+
data,
|
|
44
|
+
pagination: {
|
|
45
|
+
page,
|
|
46
|
+
limit,
|
|
47
|
+
total,
|
|
48
|
+
pages: Math.ceil(total / limit)
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Create a new trigger (agent-scoped)
|
|
54
|
+
*/
|
|
55
|
+
const createTrigger = (db) => async (params) => {
|
|
56
|
+
return (await db.insert(triggers).values(params).returning())[0];
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Update a trigger (agent-scoped)
|
|
60
|
+
*/
|
|
61
|
+
const updateTrigger = (db) => async (params) => {
|
|
62
|
+
const updateData = {
|
|
63
|
+
...params.data,
|
|
64
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
65
|
+
};
|
|
66
|
+
return (await db.update(triggers).set(updateData).where(and(eq(triggers.tenantId, params.scopes.tenantId), eq(triggers.projectId, params.scopes.projectId), eq(triggers.agentId, params.scopes.agentId), eq(triggers.id, params.triggerId))).returning())[0];
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Delete a trigger (agent-scoped)
|
|
70
|
+
*/
|
|
71
|
+
const deleteTrigger = (db) => async (params) => {
|
|
72
|
+
await db.delete(triggers).where(and(eq(triggers.tenantId, params.scopes.tenantId), eq(triggers.projectId, params.scopes.projectId), eq(triggers.agentId, params.scopes.agentId), eq(triggers.id, params.triggerId)));
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Upsert a trigger (create or update based on existence)
|
|
76
|
+
*/
|
|
77
|
+
const upsertTrigger = (db) => async (params) => {
|
|
78
|
+
const { scopes, data } = params;
|
|
79
|
+
if (await db.query.triggers.findFirst({ where: and(eq(triggers.tenantId, scopes.tenantId), eq(triggers.projectId, scopes.projectId), eq(triggers.agentId, scopes.agentId), eq(triggers.id, data.id)) })) {
|
|
80
|
+
const updateData = {
|
|
81
|
+
...data,
|
|
82
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
83
|
+
};
|
|
84
|
+
return (await db.update(triggers).set(updateData).where(and(eq(triggers.tenantId, scopes.tenantId), eq(triggers.projectId, scopes.projectId), eq(triggers.agentId, scopes.agentId), eq(triggers.id, data.id))).returning())[0];
|
|
85
|
+
}
|
|
86
|
+
return (await db.insert(triggers).values({
|
|
87
|
+
...data,
|
|
88
|
+
tenantId: scopes.tenantId,
|
|
89
|
+
projectId: scopes.projectId,
|
|
90
|
+
agentId: scopes.agentId
|
|
91
|
+
}).returning())[0];
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
export { createTrigger, deleteTrigger, getTriggerById, listTriggers, listTriggersPaginated, updateTrigger, upsertTrigger };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EvaluationJobFilterCriteria, ProjectScopeConfig } from "../../types/utility.js";
|
|
1
|
+
import { EvaluationJobFilterCriteria, Filter, ProjectScopeConfig } from "../../types/utility.js";
|
|
2
2
|
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
3
3
|
import { ConversationSelect, DatasetRunConversationRelationInsert, DatasetRunConversationRelationSelect, DatasetRunInsert, DatasetRunSelect, EvaluationResultInsert, EvaluationResultSelect, EvaluationResultUpdate, EvaluationRunInsert, EvaluationRunSelect, EvaluationRunUpdate } from "../../types/entities.js";
|
|
4
4
|
|
|
@@ -114,7 +114,7 @@ declare const deleteEvaluationResultsByRun: (db: AgentsRunDatabaseClient) => (pa
|
|
|
114
114
|
*/
|
|
115
115
|
declare const filterConversationsForJob: (db: AgentsRunDatabaseClient) => (params: {
|
|
116
116
|
scopes: ProjectScopeConfig;
|
|
117
|
-
jobFilters: EvaluationJobFilterCriteria | null | undefined;
|
|
117
|
+
jobFilters: Filter<EvaluationJobFilterCriteria> | null | undefined;
|
|
118
118
|
}) => Promise<ConversationSelect[]>;
|
|
119
119
|
//#endregion
|
|
120
120
|
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 };
|
|
@@ -126,10 +126,20 @@ const deleteEvaluationResultsByRun = (db) => async (params) => {
|
|
|
126
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
127
|
};
|
|
128
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
|
+
/**
|
|
129
138
|
* Filter conversations based on evaluation job filter criteria
|
|
130
139
|
*/
|
|
131
140
|
const filterConversationsForJob = (db) => async (params) => {
|
|
132
|
-
const { scopes, jobFilters } = params;
|
|
141
|
+
const { scopes, jobFilters: rawJobFilters } = params;
|
|
142
|
+
const jobFilters = extractPlainFilterCriteria(rawJobFilters);
|
|
133
143
|
const { tenantId, projectId } = scopes;
|
|
134
144
|
const whereConditions = [eq(conversations.tenantId, tenantId), eq(conversations.projectId, projectId)];
|
|
135
145
|
if (jobFilters?.conversationIds && Array.isArray(jobFilters.conversationIds) && jobFilters.conversationIds.length > 0) whereConditions.push(inArray(conversations.id, jobFilters.conversationIds));
|
|
@@ -17,18 +17,18 @@ declare const getMessageById: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
17
17
|
metadata: MessageMetadata | null;
|
|
18
18
|
content: MessageContent;
|
|
19
19
|
role: string;
|
|
20
|
+
conversationId: string;
|
|
20
21
|
fromSubAgentId: string | null;
|
|
21
22
|
toSubAgentId: string | null;
|
|
22
23
|
fromExternalAgentId: string | null;
|
|
23
24
|
toExternalAgentId: string | null;
|
|
24
|
-
taskId: string | null;
|
|
25
|
-
a2aTaskId: string | null;
|
|
26
|
-
conversationId: string;
|
|
27
25
|
fromTeamAgentId: string | null;
|
|
28
26
|
toTeamAgentId: string | null;
|
|
29
27
|
visibility: string;
|
|
30
28
|
messageType: string;
|
|
29
|
+
taskId: string | null;
|
|
31
30
|
parentMessageId: string | null;
|
|
31
|
+
a2aTaskId: string | null;
|
|
32
32
|
a2aSessionId: string | null;
|
|
33
33
|
} | undefined>;
|
|
34
34
|
declare const listMessages: (db: AgentsRunDatabaseClient) => (params: {
|
|
@@ -148,18 +148,18 @@ declare const createMessage: (db: AgentsRunDatabaseClient) => (params: MessageIn
|
|
|
148
148
|
metadata: MessageMetadata | null;
|
|
149
149
|
content: MessageContent;
|
|
150
150
|
role: string;
|
|
151
|
+
conversationId: string;
|
|
151
152
|
fromSubAgentId: string | null;
|
|
152
153
|
toSubAgentId: string | null;
|
|
153
154
|
fromExternalAgentId: string | null;
|
|
154
155
|
toExternalAgentId: string | null;
|
|
155
|
-
taskId: string | null;
|
|
156
|
-
a2aTaskId: string | null;
|
|
157
|
-
conversationId: string;
|
|
158
156
|
fromTeamAgentId: string | null;
|
|
159
157
|
toTeamAgentId: string | null;
|
|
160
158
|
visibility: string;
|
|
161
159
|
messageType: string;
|
|
160
|
+
taskId: string | null;
|
|
162
161
|
parentMessageId: string | null;
|
|
162
|
+
a2aTaskId: string | null;
|
|
163
163
|
a2aSessionId: string | null;
|
|
164
164
|
}>;
|
|
165
165
|
declare const updateMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
@@ -201,18 +201,18 @@ declare const deleteMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
201
201
|
metadata: MessageMetadata | null;
|
|
202
202
|
content: MessageContent;
|
|
203
203
|
role: string;
|
|
204
|
+
conversationId: string;
|
|
204
205
|
fromSubAgentId: string | null;
|
|
205
206
|
toSubAgentId: string | null;
|
|
206
207
|
fromExternalAgentId: string | null;
|
|
207
208
|
toExternalAgentId: string | null;
|
|
208
|
-
taskId: string | null;
|
|
209
|
-
a2aTaskId: string | null;
|
|
210
|
-
conversationId: string;
|
|
211
209
|
fromTeamAgentId: string | null;
|
|
212
210
|
toTeamAgentId: string | null;
|
|
213
211
|
visibility: string;
|
|
214
212
|
messageType: string;
|
|
213
|
+
taskId: string | null;
|
|
215
214
|
parentMessageId: string | null;
|
|
215
|
+
a2aTaskId: string | null;
|
|
216
216
|
a2aSessionId: string | null;
|
|
217
217
|
}>;
|
|
218
218
|
declare const countMessagesByConversation: (db: AgentsRunDatabaseClient) => (params: {
|
|
@@ -13,12 +13,12 @@ declare const createTask: (db: AgentsRunDatabaseClient) => (params: TaskInsert)
|
|
|
13
13
|
createdAt: string;
|
|
14
14
|
updatedAt: string;
|
|
15
15
|
metadata: TaskMetadataConfig | null;
|
|
16
|
-
status: string;
|
|
17
16
|
ref: {
|
|
18
17
|
type: "tag" | "commit" | "branch";
|
|
19
18
|
name: string;
|
|
20
19
|
hash: string;
|
|
21
20
|
} | null;
|
|
21
|
+
status: string;
|
|
22
22
|
subAgentId: string;
|
|
23
23
|
contextId: string;
|
|
24
24
|
}>;
|
|
@@ -42,8 +42,8 @@ declare const updateTask: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
42
42
|
} | null;
|
|
43
43
|
status: string;
|
|
44
44
|
metadata: TaskMetadataConfig | null;
|
|
45
|
-
agentId: string;
|
|
46
45
|
subAgentId: string;
|
|
46
|
+
agentId: string;
|
|
47
47
|
projectId: string;
|
|
48
48
|
tenantId: string;
|
|
49
49
|
id: string;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { AgentScopeConfig, PaginationConfig } from "../../types/utility.js";
|
|
2
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
3
|
+
import { TriggerInvocationInsert, TriggerInvocationSelect, TriggerInvocationUpdate } from "../../types/entities.js";
|
|
4
|
+
|
|
5
|
+
//#region src/data-access/runtime/triggerInvocations.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get a trigger invocation by ID (agent-scoped)
|
|
9
|
+
*/
|
|
10
|
+
declare const getTriggerInvocationById: (db: AgentsRunDatabaseClient) => (params: {
|
|
11
|
+
scopes: AgentScopeConfig;
|
|
12
|
+
triggerId: string;
|
|
13
|
+
invocationId: string;
|
|
14
|
+
}) => Promise<TriggerInvocationSelect | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* List trigger invocations with optional filtering (agent-scoped)
|
|
17
|
+
*/
|
|
18
|
+
declare const listTriggerInvocationsPaginated: (db: AgentsRunDatabaseClient) => (params: {
|
|
19
|
+
scopes: AgentScopeConfig;
|
|
20
|
+
triggerId: string;
|
|
21
|
+
pagination?: PaginationConfig;
|
|
22
|
+
filters?: {
|
|
23
|
+
status?: "pending" | "success" | "failed";
|
|
24
|
+
from?: string;
|
|
25
|
+
to?: string;
|
|
26
|
+
};
|
|
27
|
+
}) => Promise<{
|
|
28
|
+
data: {
|
|
29
|
+
triggerId: string;
|
|
30
|
+
conversationId: string | null;
|
|
31
|
+
status: string;
|
|
32
|
+
requestPayload: unknown;
|
|
33
|
+
transformedPayload: unknown;
|
|
34
|
+
errorMessage: string | null;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
agentId: string;
|
|
37
|
+
projectId: string;
|
|
38
|
+
tenantId: string;
|
|
39
|
+
id: string;
|
|
40
|
+
}[];
|
|
41
|
+
pagination: {
|
|
42
|
+
page: number;
|
|
43
|
+
limit: number;
|
|
44
|
+
total: number;
|
|
45
|
+
pages: number;
|
|
46
|
+
};
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* Create a new trigger invocation (agent-scoped)
|
|
50
|
+
*/
|
|
51
|
+
declare const createTriggerInvocation: (db: AgentsRunDatabaseClient) => (params: TriggerInvocationInsert) => Promise<TriggerInvocationSelect>;
|
|
52
|
+
/**
|
|
53
|
+
* Update trigger invocation status (agent-scoped)
|
|
54
|
+
*/
|
|
55
|
+
declare const updateTriggerInvocationStatus: (db: AgentsRunDatabaseClient) => (params: {
|
|
56
|
+
scopes: AgentScopeConfig;
|
|
57
|
+
triggerId: string;
|
|
58
|
+
invocationId: string;
|
|
59
|
+
data: TriggerInvocationUpdate;
|
|
60
|
+
}) => Promise<TriggerInvocationSelect>;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { createTriggerInvocation, getTriggerInvocationById, listTriggerInvocationsPaginated, updateTriggerInvocationStatus };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { triggerInvocations } from "../../db/runtime/runtime-schema.js";
|
|
2
|
+
import { and, count, desc, eq, gte, lte } from "drizzle-orm";
|
|
3
|
+
|
|
4
|
+
//#region src/data-access/runtime/triggerInvocations.ts
|
|
5
|
+
/**
|
|
6
|
+
* Get a trigger invocation by ID (agent-scoped)
|
|
7
|
+
*/
|
|
8
|
+
const getTriggerInvocationById = (db) => async (params) => {
|
|
9
|
+
return await db.query.triggerInvocations.findFirst({ where: and(eq(triggerInvocations.tenantId, params.scopes.tenantId), eq(triggerInvocations.projectId, params.scopes.projectId), eq(triggerInvocations.agentId, params.scopes.agentId), eq(triggerInvocations.triggerId, params.triggerId), eq(triggerInvocations.id, params.invocationId)) });
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* List trigger invocations with optional filtering (agent-scoped)
|
|
13
|
+
*/
|
|
14
|
+
const listTriggerInvocationsPaginated = (db) => async (params) => {
|
|
15
|
+
const page = params.pagination?.page || 1;
|
|
16
|
+
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
17
|
+
const offset = (page - 1) * limit;
|
|
18
|
+
const conditions = [
|
|
19
|
+
eq(triggerInvocations.tenantId, params.scopes.tenantId),
|
|
20
|
+
eq(triggerInvocations.projectId, params.scopes.projectId),
|
|
21
|
+
eq(triggerInvocations.agentId, params.scopes.agentId),
|
|
22
|
+
eq(triggerInvocations.triggerId, params.triggerId)
|
|
23
|
+
];
|
|
24
|
+
if (params.filters?.status) conditions.push(eq(triggerInvocations.status, params.filters.status));
|
|
25
|
+
if (params.filters?.from) conditions.push(gte(triggerInvocations.createdAt, params.filters.from));
|
|
26
|
+
if (params.filters?.to) conditions.push(lte(triggerInvocations.createdAt, params.filters.to));
|
|
27
|
+
const whereClause = and(...conditions);
|
|
28
|
+
const [data, totalResult] = await Promise.all([db.select().from(triggerInvocations).where(whereClause).limit(limit).offset(offset).orderBy(desc(triggerInvocations.createdAt)), db.select({ count: count() }).from(triggerInvocations).where(whereClause)]);
|
|
29
|
+
const total = totalResult[0]?.count || 0;
|
|
30
|
+
return {
|
|
31
|
+
data,
|
|
32
|
+
pagination: {
|
|
33
|
+
page,
|
|
34
|
+
limit,
|
|
35
|
+
total,
|
|
36
|
+
pages: Math.ceil(total / limit)
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Create a new trigger invocation (agent-scoped)
|
|
42
|
+
*/
|
|
43
|
+
const createTriggerInvocation = (db) => async (params) => {
|
|
44
|
+
return (await db.insert(triggerInvocations).values(params).returning())[0];
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Update trigger invocation status (agent-scoped)
|
|
48
|
+
*/
|
|
49
|
+
const updateTriggerInvocationStatus = (db) => async (params) => {
|
|
50
|
+
return (await db.update(triggerInvocations).set(params.data).where(and(eq(triggerInvocations.tenantId, params.scopes.tenantId), eq(triggerInvocations.projectId, params.scopes.projectId), eq(triggerInvocations.agentId, params.scopes.agentId), eq(triggerInvocations.triggerId, params.triggerId), eq(triggerInvocations.id, params.invocationId))).returning())[0];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { createTriggerInvocation, getTriggerInvocationById, listTriggerInvocationsPaginated, updateTriggerInvocationStatus };
|