@inkeep/agents-core 0.0.0-dev-20260330181206 → 0.0.0-dev-20260330201301
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-config-utils.js +1 -1
- package/dist/auth/auth-schema.d.ts +86 -86
- package/dist/auth/auth-validation-schemas.d.ts +154 -154
- package/dist/auth/auth.d.ts +6 -6
- package/dist/auth/auth.js +1 -1
- package/dist/auth/permissions.d.ts +13 -13
- package/dist/client-exports.d.ts +2 -2
- package/dist/client-exports.js +2 -2
- package/dist/data-access/index.d.ts +4 -7
- package/dist/data-access/index.js +4 -7
- package/dist/data-access/manage/agentFull.js +0 -116
- package/dist/data-access/manage/agents.d.ts +32 -32
- package/dist/data-access/manage/agents.js +0 -30
- package/dist/data-access/manage/artifactComponents.d.ts +8 -8
- package/dist/data-access/manage/audit-queries.d.ts +1 -14
- package/dist/data-access/manage/audit-queries.js +2 -16
- 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 +12 -12
- package/dist/data-access/manage/skills.d.ts +11 -11
- package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +18 -18
- package/dist/data-access/manage/subAgentRelations.d.ts +22 -22
- package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +18 -18
- package/dist/data-access/manage/subAgents.d.ts +24 -24
- package/dist/data-access/manage/tools.d.ts +24 -24
- package/dist/data-access/manage/triggerCleanup.js +18 -7
- package/dist/data-access/runtime/apiKeys.d.ts +12 -12
- package/dist/data-access/runtime/apps.d.ts +10 -10
- package/dist/data-access/runtime/cascade-delete.d.ts +2 -0
- package/dist/data-access/runtime/cascade-delete.js +13 -6
- package/dist/data-access/runtime/conversations.d.ts +16 -16
- package/dist/data-access/runtime/messages.d.ts +9 -9
- package/dist/data-access/runtime/scheduledTriggerInvocations.d.ts +5 -4
- package/dist/data-access/runtime/scheduledTriggers.d.ts +89 -0
- package/dist/data-access/runtime/scheduledTriggers.js +91 -0
- package/dist/data-access/runtime/schedulerState.d.ts +11 -0
- package/dist/data-access/runtime/schedulerState.js +30 -0
- package/dist/data-access/runtime/tasks.d.ts +5 -5
- package/dist/data-reconciliation/index.d.ts +2 -2
- package/dist/data-reconciliation/types.d.ts +1 -28
- package/dist/db/manage/manage-schema.d.ts +340 -694
- package/dist/db/manage/manage-schema.js +2 -4
- package/dist/db/runtime/runtime-schema.d.ts +811 -350
- package/dist/db/runtime/runtime-schema.js +38 -5
- package/dist/index.d.ts +11 -12
- package/dist/index.js +8 -10
- package/dist/types/entities.d.ts +12 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/utils/compute-next-run-at.d.ts +9 -0
- package/dist/utils/compute-next-run-at.js +18 -0
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +2 -1
- 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.d.ts +2668 -3648
- package/dist/validation/schemas.js +16 -32
- package/drizzle/runtime/0028_thick_squirrel_girl.sql +36 -0
- package/drizzle/runtime/meta/0028_snapshot.json +4661 -0
- package/drizzle/runtime/meta/_journal.json +7 -0
- package/package.json +2 -1
- package/dist/data-access/manage/scheduledTriggers.d.ts +0 -91
- package/dist/data-access/manage/scheduledTriggers.js +0 -87
- package/dist/data-access/manage/scheduledWorkflows.d.ts +0 -29
- package/dist/data-access/manage/scheduledWorkflows.js +0 -33
|
@@ -2,8 +2,8 @@ import { manage_schema_exports } from "../../db/manage/manage-schema.js";
|
|
|
2
2
|
import { getLogger } from "../../utils/logger.js";
|
|
3
3
|
import { resolveProjectMainRefs } from "../../dolt/ref-helpers.js";
|
|
4
4
|
import { listProjectsMetadata } from "../runtime/projects.js";
|
|
5
|
-
import { deleteScheduledTriggersByRunAsUserId } from "./scheduledTriggers.js";
|
|
6
5
|
import { deleteTriggersByRunAsUserId } from "./triggers.js";
|
|
6
|
+
import { deleteScheduledTriggersByRunAsUserId } from "../runtime/scheduledTriggers.js";
|
|
7
7
|
import { withRef } from "../../dolt/ref-scope.js";
|
|
8
8
|
import { drizzle } from "drizzle-orm/node-postgres";
|
|
9
9
|
|
|
@@ -13,6 +13,22 @@ async function cleanupUserTriggers(params) {
|
|
|
13
13
|
const { tenantId, userId, runDb, manageDbPool } = params;
|
|
14
14
|
const projects = await listProjectsMetadata(runDb)({ tenantId });
|
|
15
15
|
if (projects.length === 0) return;
|
|
16
|
+
await Promise.allSettled(projects.map(async (project) => {
|
|
17
|
+
try {
|
|
18
|
+
await deleteScheduledTriggersByRunAsUserId(runDb)({
|
|
19
|
+
tenantId,
|
|
20
|
+
projectId: project.id,
|
|
21
|
+
runAsUserId: userId
|
|
22
|
+
});
|
|
23
|
+
} catch (err) {
|
|
24
|
+
logger.error({
|
|
25
|
+
tenantId,
|
|
26
|
+
projectId: project.id,
|
|
27
|
+
userId,
|
|
28
|
+
error: err
|
|
29
|
+
}, "Failed to clean up scheduled triggers for project");
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
16
32
|
const connection = await manageDbPool.connect();
|
|
17
33
|
let resolvedRefs;
|
|
18
34
|
try {
|
|
@@ -21,11 +37,6 @@ async function cleanupUserTriggers(params) {
|
|
|
21
37
|
connection.release();
|
|
22
38
|
}
|
|
23
39
|
const results = await Promise.allSettled(resolvedRefs.map(({ projectId, ref }) => withRef(manageDbPool, ref, async (db) => {
|
|
24
|
-
await deleteScheduledTriggersByRunAsUserId(db)({
|
|
25
|
-
tenantId,
|
|
26
|
-
projectId,
|
|
27
|
-
runAsUserId: userId
|
|
28
|
-
});
|
|
29
40
|
await deleteTriggersByRunAsUserId(db)({
|
|
30
41
|
tenantId,
|
|
31
42
|
projectId,
|
|
@@ -43,7 +54,7 @@ async function cleanupUserTriggers(params) {
|
|
|
43
54
|
projectId,
|
|
44
55
|
userId,
|
|
45
56
|
error: result.reason
|
|
46
|
-
}, "Failed to clean up
|
|
57
|
+
}, "Failed to clean up webhook triggers for project");
|
|
47
58
|
}
|
|
48
59
|
}
|
|
49
60
|
|
|
@@ -12,28 +12,28 @@ declare const getApiKeyById: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
12
12
|
id: string;
|
|
13
13
|
createdAt: string;
|
|
14
14
|
updatedAt: string;
|
|
15
|
-
agentId: string;
|
|
16
|
-
projectId: string;
|
|
17
15
|
tenantId: string;
|
|
16
|
+
projectId: string;
|
|
17
|
+
agentId: string;
|
|
18
|
+
expiresAt: string | null;
|
|
18
19
|
publicId: string;
|
|
19
20
|
keyHash: string;
|
|
20
21
|
keyPrefix: string;
|
|
21
22
|
lastUsedAt: string | null;
|
|
22
|
-
expiresAt: string | null;
|
|
23
23
|
} | undefined>;
|
|
24
24
|
declare const getApiKeyByPublicId: (db: AgentsRunDatabaseClient) => (publicId: string) => Promise<{
|
|
25
25
|
name: string | null;
|
|
26
26
|
id: string;
|
|
27
27
|
createdAt: string;
|
|
28
28
|
updatedAt: string;
|
|
29
|
-
agentId: string;
|
|
30
|
-
projectId: string;
|
|
31
29
|
tenantId: string;
|
|
30
|
+
projectId: string;
|
|
31
|
+
agentId: string;
|
|
32
|
+
expiresAt: string | null;
|
|
32
33
|
publicId: string;
|
|
33
34
|
keyHash: string;
|
|
34
35
|
keyPrefix: string;
|
|
35
36
|
lastUsedAt: string | null;
|
|
36
|
-
expiresAt: string | null;
|
|
37
37
|
} | undefined>;
|
|
38
38
|
declare const listApiKeys: (db: AgentsRunDatabaseClient) => (params: {
|
|
39
39
|
scopes: ProjectScopeConfig;
|
|
@@ -43,14 +43,14 @@ declare const listApiKeys: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
43
43
|
id: string;
|
|
44
44
|
createdAt: string;
|
|
45
45
|
updatedAt: string;
|
|
46
|
-
agentId: string;
|
|
47
|
-
projectId: string;
|
|
48
46
|
tenantId: string;
|
|
47
|
+
projectId: string;
|
|
48
|
+
agentId: string;
|
|
49
|
+
expiresAt: string | null;
|
|
49
50
|
publicId: string;
|
|
50
51
|
keyHash: string;
|
|
51
52
|
keyPrefix: string;
|
|
52
53
|
lastUsedAt: string | null;
|
|
53
|
-
expiresAt: string | null;
|
|
54
54
|
}[]>;
|
|
55
55
|
declare const listApiKeysPaginated: (db: AgentsRunDatabaseClient) => (params: {
|
|
56
56
|
scopes: ProjectScopeConfig;
|
|
@@ -70,14 +70,14 @@ declare const createApiKey: (db: AgentsRunDatabaseClient) => (params: ApiKeyInse
|
|
|
70
70
|
id: string;
|
|
71
71
|
createdAt: string;
|
|
72
72
|
updatedAt: string;
|
|
73
|
-
agentId: string;
|
|
74
|
-
projectId: string;
|
|
75
73
|
tenantId: string;
|
|
74
|
+
projectId: string;
|
|
75
|
+
agentId: string;
|
|
76
|
+
expiresAt: string | null;
|
|
76
77
|
publicId: string;
|
|
77
78
|
keyHash: string;
|
|
78
79
|
keyPrefix: string;
|
|
79
80
|
lastUsedAt: string | null;
|
|
80
|
-
expiresAt: string | null;
|
|
81
81
|
}>;
|
|
82
82
|
declare const updateApiKey: (db: AgentsRunDatabaseClient) => (params: {
|
|
83
83
|
scopes: ProjectScopeConfig;
|
|
@@ -5,16 +5,14 @@ import { AppInsert, AppSelect, AppUpdate } from "../../types/entities.js";
|
|
|
5
5
|
|
|
6
6
|
//#region src/data-access/runtime/apps.d.ts
|
|
7
7
|
declare const getAppById: (db: AgentsRunDatabaseClient) => (id: string) => Promise<{
|
|
8
|
-
type: AppType;
|
|
9
|
-
description: string | null;
|
|
10
8
|
name: string;
|
|
11
|
-
|
|
9
|
+
type: AppType;
|
|
12
10
|
id: string;
|
|
11
|
+
description: string | null;
|
|
13
12
|
createdAt: string;
|
|
14
13
|
updatedAt: string;
|
|
15
|
-
projectId: string | null;
|
|
16
14
|
tenantId: string | null;
|
|
17
|
-
|
|
15
|
+
projectId: string | null;
|
|
18
16
|
config: {
|
|
19
17
|
type: "web_client";
|
|
20
18
|
webClient: {
|
|
@@ -35,6 +33,8 @@ declare const getAppById: (db: AgentsRunDatabaseClient) => (id: string) => Promi
|
|
|
35
33
|
type: "api";
|
|
36
34
|
api: Record<string, never>;
|
|
37
35
|
};
|
|
36
|
+
enabled: boolean;
|
|
37
|
+
prompt: string | null;
|
|
38
38
|
lastUsedAt: string | null;
|
|
39
39
|
defaultProjectId: string | null;
|
|
40
40
|
defaultAgentId: string | null;
|
|
@@ -64,16 +64,14 @@ declare const listAppsPaginated: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
64
64
|
};
|
|
65
65
|
}>;
|
|
66
66
|
declare const createApp: (db: AgentsRunDatabaseClient) => (params: AppInsert) => Promise<{
|
|
67
|
-
type: AppType;
|
|
68
|
-
description: string | null;
|
|
69
67
|
name: string;
|
|
70
|
-
|
|
68
|
+
type: AppType;
|
|
71
69
|
id: string;
|
|
70
|
+
description: string | null;
|
|
72
71
|
createdAt: string;
|
|
73
72
|
updatedAt: string;
|
|
74
|
-
projectId: string | null;
|
|
75
73
|
tenantId: string | null;
|
|
76
|
-
|
|
74
|
+
projectId: string | null;
|
|
77
75
|
config: {
|
|
78
76
|
type: "web_client";
|
|
79
77
|
webClient: {
|
|
@@ -94,6 +92,8 @@ declare const createApp: (db: AgentsRunDatabaseClient) => (params: AppInsert) =>
|
|
|
94
92
|
type: "api";
|
|
95
93
|
api: Record<string, never>;
|
|
96
94
|
};
|
|
95
|
+
enabled: boolean;
|
|
96
|
+
prompt: string | null;
|
|
97
97
|
lastUsedAt: string | null;
|
|
98
98
|
defaultProjectId: string | null;
|
|
99
99
|
defaultAgentId: string | null;
|
|
@@ -19,6 +19,7 @@ type CascadeDeleteResult = {
|
|
|
19
19
|
slackWorkspaceDefaultsCleared: number;
|
|
20
20
|
appsDeleted: number;
|
|
21
21
|
appDefaultsCleared: number;
|
|
22
|
+
scheduledTriggersDeleted: number;
|
|
22
23
|
};
|
|
23
24
|
/**
|
|
24
25
|
* Delete all runtime entities for a specific branch.
|
|
@@ -30,6 +31,7 @@ type CascadeDeleteResult = {
|
|
|
30
31
|
declare const cascadeDeleteByBranch: (db: AgentsRunDatabaseClient) => (params: {
|
|
31
32
|
scopes: ProjectScopeConfig;
|
|
32
33
|
fullBranchName: string;
|
|
34
|
+
ref: string;
|
|
33
35
|
}) => Promise<CascadeDeleteResult>;
|
|
34
36
|
/**
|
|
35
37
|
* Delete all runtime entities for a project on a specific branch.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { apiKeys, contextCache, conversations, datasetRun, evaluationRun, scheduledTriggerInvocations, tasks, triggerInvocations, workAppGitHubMcpToolAccessMode, workAppGitHubMcpToolRepositoryAccess, workAppGitHubProjectAccessMode, workAppGitHubProjectRepositoryAccess } from "../../db/runtime/runtime-schema.js";
|
|
1
|
+
import { apiKeys, contextCache, conversations, datasetRun, evaluationRun, scheduledTriggerInvocations, scheduledTriggers, tasks, triggerInvocations, workAppGitHubMcpToolAccessMode, workAppGitHubMcpToolRepositoryAccess, workAppGitHubProjectAccessMode, workAppGitHubProjectRepositoryAccess } from "../../db/runtime/runtime-schema.js";
|
|
2
2
|
import { projectScopedWhere } from "../manage/scope-helpers.js";
|
|
3
3
|
import { clearAppDefaultsByAgent, clearAppDefaultsByProject, deleteAppsByProject } from "./apps.js";
|
|
4
4
|
import { deleteSlackMcpToolAccessConfig } from "./slack-work-app-mcp.js";
|
|
@@ -14,7 +14,7 @@ import { and, eq, inArray, sql } from "drizzle-orm";
|
|
|
14
14
|
* @returns Function that performs the cascade delete
|
|
15
15
|
*/
|
|
16
16
|
const cascadeDeleteByBranch = (db) => async (params) => {
|
|
17
|
-
const { scopes, fullBranchName } = params;
|
|
17
|
+
const { scopes, fullBranchName, ref } = params;
|
|
18
18
|
const contextCacheResult = await db.delete(contextCache).where(and(projectScopedWhere(contextCache, scopes), sql`${contextCache.ref}->>'name' = ${fullBranchName}`)).returning();
|
|
19
19
|
const conversationsResult = await db.delete(conversations).where(and(projectScopedWhere(conversations, scopes), sql`${conversations.ref}->>'name' = ${fullBranchName}`)).returning();
|
|
20
20
|
const tasksResult = await db.delete(tasks).where(and(projectScopedWhere(tasks, scopes), sql`${tasks.ref}->>'name' = ${fullBranchName}`)).returning();
|
|
@@ -22,6 +22,7 @@ const cascadeDeleteByBranch = (db) => async (params) => {
|
|
|
22
22
|
const scheduledTriggerInvocationsResult = await db.delete(scheduledTriggerInvocations).where(and(eq(scheduledTriggerInvocations.tenantId, scopes.tenantId), eq(scheduledTriggerInvocations.projectId, scopes.projectId), sql`${scheduledTriggerInvocations.ref}->>'name' = ${fullBranchName}`)).returning();
|
|
23
23
|
const datasetRunsResult = await db.delete(datasetRun).where(and(eq(datasetRun.tenantId, scopes.tenantId), eq(datasetRun.projectId, scopes.projectId), sql`${datasetRun.ref}->>'name' = ${fullBranchName}`)).returning();
|
|
24
24
|
const evaluationRunsResult = await db.delete(evaluationRun).where(and(eq(evaluationRun.tenantId, scopes.tenantId), eq(evaluationRun.projectId, scopes.projectId), sql`${evaluationRun.ref}->>'name' = ${fullBranchName}`)).returning();
|
|
25
|
+
const scheduledTriggersResult = await db.delete(scheduledTriggers).where(and(eq(scheduledTriggers.tenantId, scopes.tenantId), eq(scheduledTriggers.projectId, scopes.projectId), eq(scheduledTriggers.ref, ref))).returning();
|
|
25
26
|
return {
|
|
26
27
|
conversationsDeleted: conversationsResult.length,
|
|
27
28
|
tasksDeleted: tasksResult.length,
|
|
@@ -34,7 +35,8 @@ const cascadeDeleteByBranch = (db) => async (params) => {
|
|
|
34
35
|
slackChannelConfigsDeleted: 0,
|
|
35
36
|
slackWorkspaceDefaultsCleared: 0,
|
|
36
37
|
appsDeleted: 0,
|
|
37
|
-
appDefaultsCleared: 0
|
|
38
|
+
appDefaultsCleared: 0,
|
|
39
|
+
scheduledTriggersDeleted: scheduledTriggersResult.length
|
|
38
40
|
};
|
|
39
41
|
};
|
|
40
42
|
/**
|
|
@@ -64,6 +66,7 @@ const cascadeDeleteByProject = (db) => async (params) => {
|
|
|
64
66
|
const slackChannelConfigsDeleted = await deleteWorkAppSlackChannelAgentConfigsByProject(db)(scopes.tenantId, scopes.projectId);
|
|
65
67
|
const slackWorkspaceDefaultsCleared = await clearWorkspaceDefaultsByProject(db)(scopes.tenantId, scopes.projectId);
|
|
66
68
|
clearDevConfigWorkspaceDefaultsByProject(scopes.projectId);
|
|
69
|
+
const scheduledTriggersResult = await db.delete(scheduledTriggers).where(and(eq(scheduledTriggers.tenantId, scopes.tenantId), eq(scheduledTriggers.projectId, scopes.projectId))).returning();
|
|
67
70
|
return {
|
|
68
71
|
conversationsDeleted: conversationsResult.length,
|
|
69
72
|
tasksDeleted: tasksResult.length,
|
|
@@ -76,7 +79,8 @@ const cascadeDeleteByProject = (db) => async (params) => {
|
|
|
76
79
|
slackChannelConfigsDeleted,
|
|
77
80
|
slackWorkspaceDefaultsCleared,
|
|
78
81
|
appsDeleted,
|
|
79
|
-
appDefaultsCleared
|
|
82
|
+
appDefaultsCleared,
|
|
83
|
+
scheduledTriggersDeleted: scheduledTriggersResult.length
|
|
80
84
|
};
|
|
81
85
|
};
|
|
82
86
|
/**
|
|
@@ -108,6 +112,7 @@ const cascadeDeleteByAgent = (db) => async (params) => {
|
|
|
108
112
|
const slackChannelConfigsDeleted = await deleteWorkAppSlackChannelAgentConfigsByAgent(db)(scopes.tenantId, scopes.projectId, scopes.agentId);
|
|
109
113
|
const slackWorkspaceDefaultsCleared = await clearWorkspaceDefaultsByAgent(db)(scopes.tenantId, scopes.projectId, scopes.agentId);
|
|
110
114
|
clearDevConfigWorkspaceDefaultsByAgent(scopes.projectId, scopes.agentId);
|
|
115
|
+
const scheduledTriggersResult = await db.delete(scheduledTriggers).where(and(eq(scheduledTriggers.tenantId, scopes.tenantId), eq(scheduledTriggers.projectId, scopes.projectId), eq(scheduledTriggers.agentId, scopes.agentId))).returning();
|
|
111
116
|
return {
|
|
112
117
|
conversationsDeleted,
|
|
113
118
|
tasksDeleted,
|
|
@@ -120,7 +125,8 @@ const cascadeDeleteByAgent = (db) => async (params) => {
|
|
|
120
125
|
slackChannelConfigsDeleted,
|
|
121
126
|
slackWorkspaceDefaultsCleared,
|
|
122
127
|
appsDeleted: 0,
|
|
123
|
-
appDefaultsCleared
|
|
128
|
+
appDefaultsCleared,
|
|
129
|
+
scheduledTriggersDeleted: scheduledTriggersResult.length
|
|
124
130
|
};
|
|
125
131
|
};
|
|
126
132
|
/**
|
|
@@ -151,7 +157,8 @@ const cascadeDeleteBySubAgent = (db) => async (params) => {
|
|
|
151
157
|
slackChannelConfigsDeleted: 0,
|
|
152
158
|
slackWorkspaceDefaultsCleared: 0,
|
|
153
159
|
appsDeleted: 0,
|
|
154
|
-
appDefaultsCleared: 0
|
|
160
|
+
appDefaultsCleared: 0,
|
|
161
|
+
scheduledTriggersDeleted: 0
|
|
155
162
|
};
|
|
156
163
|
};
|
|
157
164
|
/**
|
|
@@ -15,14 +15,14 @@ declare const listConversations: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
15
15
|
total: number;
|
|
16
16
|
}>;
|
|
17
17
|
declare const createConversation: (db: AgentsRunDatabaseClient) => (params: ConversationInsert) => Promise<{
|
|
18
|
-
title: string | null;
|
|
19
|
-
metadata: ConversationMetadata | null;
|
|
20
18
|
id: string;
|
|
19
|
+
title: string | null;
|
|
21
20
|
createdAt: string;
|
|
22
21
|
updatedAt: string;
|
|
23
|
-
agentId: string | null;
|
|
24
|
-
projectId: string;
|
|
25
22
|
tenantId: string;
|
|
23
|
+
metadata: ConversationMetadata | null;
|
|
24
|
+
projectId: string;
|
|
25
|
+
agentId: string | null;
|
|
26
26
|
userId: string | null;
|
|
27
27
|
ref: {
|
|
28
28
|
type: "commit" | "tag" | "branch";
|
|
@@ -84,14 +84,14 @@ declare const getConversation: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
84
84
|
scopes: ProjectScopeConfig;
|
|
85
85
|
conversationId: string;
|
|
86
86
|
}) => Promise<{
|
|
87
|
-
title: string | null;
|
|
88
|
-
metadata: ConversationMetadata | null;
|
|
89
87
|
id: string;
|
|
88
|
+
title: string | null;
|
|
90
89
|
createdAt: string;
|
|
91
90
|
updatedAt: string;
|
|
92
|
-
agentId: string | null;
|
|
93
|
-
projectId: string;
|
|
94
91
|
tenantId: string;
|
|
92
|
+
metadata: ConversationMetadata | null;
|
|
93
|
+
projectId: string;
|
|
94
|
+
agentId: string | null;
|
|
95
95
|
userId: string | null;
|
|
96
96
|
ref: {
|
|
97
97
|
type: "commit" | "tag" | "branch";
|
|
@@ -120,14 +120,14 @@ declare const createOrGetConversation: (db: AgentsRunDatabaseClient) => (input:
|
|
|
120
120
|
metadata?: ConversationMetadata | null | undefined;
|
|
121
121
|
contextConfigId?: string | undefined;
|
|
122
122
|
} | {
|
|
123
|
-
title: string | null;
|
|
124
|
-
metadata: ConversationMetadata | null;
|
|
125
123
|
id: string;
|
|
124
|
+
title: string | null;
|
|
126
125
|
createdAt: string;
|
|
127
126
|
updatedAt: string;
|
|
128
|
-
agentId: string | null;
|
|
129
|
-
projectId: string;
|
|
130
127
|
tenantId: string;
|
|
128
|
+
metadata: ConversationMetadata | null;
|
|
129
|
+
projectId: string;
|
|
130
|
+
agentId: string | null;
|
|
131
131
|
userId: string | null;
|
|
132
132
|
ref: {
|
|
133
133
|
type: "commit" | "tag" | "branch";
|
|
@@ -152,14 +152,14 @@ declare const getActiveAgentForConversation: (db: AgentsRunDatabaseClient) => (p
|
|
|
152
152
|
scopes: ProjectScopeConfig;
|
|
153
153
|
conversationId: string;
|
|
154
154
|
}) => Promise<{
|
|
155
|
-
title: string | null;
|
|
156
|
-
metadata: ConversationMetadata | null;
|
|
157
155
|
id: string;
|
|
156
|
+
title: string | null;
|
|
158
157
|
createdAt: string;
|
|
159
158
|
updatedAt: string;
|
|
160
|
-
agentId: string | null;
|
|
161
|
-
projectId: string;
|
|
162
159
|
tenantId: string;
|
|
160
|
+
metadata: ConversationMetadata | null;
|
|
161
|
+
projectId: string;
|
|
162
|
+
agentId: string | null;
|
|
163
163
|
userId: string | null;
|
|
164
164
|
ref: {
|
|
165
165
|
type: "commit" | "tag" | "branch";
|
|
@@ -10,15 +10,15 @@ declare const getMessageById: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
10
10
|
scopes: ProjectScopeConfig;
|
|
11
11
|
messageId: string;
|
|
12
12
|
}) => Promise<{
|
|
13
|
-
metadata: MessageMetadata | null;
|
|
14
13
|
id: string;
|
|
15
14
|
createdAt: string;
|
|
16
15
|
updatedAt: string;
|
|
17
|
-
projectId: string;
|
|
18
16
|
tenantId: string;
|
|
17
|
+
metadata: MessageMetadata | null;
|
|
19
18
|
content: MessageContent;
|
|
20
|
-
|
|
19
|
+
projectId: string;
|
|
21
20
|
role: string;
|
|
21
|
+
conversationId: string;
|
|
22
22
|
fromSubAgentId: string | null;
|
|
23
23
|
toSubAgentId: string | null;
|
|
24
24
|
fromExternalAgentId: string | null;
|
|
@@ -144,15 +144,15 @@ declare const createMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
144
144
|
scopes: ProjectScopeConfig;
|
|
145
145
|
data: Omit<MessageInsert, "tenantId" | "projectId">;
|
|
146
146
|
}) => Promise<{
|
|
147
|
-
metadata: MessageMetadata | null;
|
|
148
147
|
id: string;
|
|
149
148
|
createdAt: string;
|
|
150
149
|
updatedAt: string;
|
|
151
|
-
projectId: string;
|
|
152
150
|
tenantId: string;
|
|
151
|
+
metadata: MessageMetadata | null;
|
|
153
152
|
content: MessageContent;
|
|
154
|
-
|
|
153
|
+
projectId: string;
|
|
155
154
|
role: string;
|
|
155
|
+
conversationId: string;
|
|
156
156
|
fromSubAgentId: string | null;
|
|
157
157
|
toSubAgentId: string | null;
|
|
158
158
|
fromExternalAgentId: string | null;
|
|
@@ -197,15 +197,15 @@ declare const deleteMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
197
197
|
scopes: ProjectScopeConfig;
|
|
198
198
|
messageId: string;
|
|
199
199
|
}) => Promise<{
|
|
200
|
-
metadata: MessageMetadata | null;
|
|
201
200
|
id: string;
|
|
202
201
|
createdAt: string;
|
|
203
202
|
updatedAt: string;
|
|
204
|
-
projectId: string;
|
|
205
203
|
tenantId: string;
|
|
204
|
+
metadata: MessageMetadata | null;
|
|
206
205
|
content: MessageContent;
|
|
207
|
-
|
|
206
|
+
projectId: string;
|
|
208
207
|
role: string;
|
|
208
|
+
conversationId: string;
|
|
209
209
|
fromSubAgentId: string | null;
|
|
210
210
|
toSubAgentId: string | null;
|
|
211
211
|
fromExternalAgentId: string | null;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AgentScopeConfig } from "../../db/manage/scope-definitions.js";
|
|
2
2
|
import { PaginationConfig } from "../../types/utility.js";
|
|
3
3
|
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ScheduledTriggerInvocationStatus } from "../../validation/schemas.js";
|
|
5
|
+
import { ScheduledTriggerInvocation, ScheduledTriggerInvocationInsert, ScheduledTriggerInvocationUpdate } from "../../types/entities.js";
|
|
5
6
|
|
|
6
7
|
//#region src/data-access/runtime/scheduledTriggerInvocations.d.ts
|
|
7
8
|
/**
|
|
@@ -39,7 +40,7 @@ declare const listScheduledTriggerInvocationsPaginated: (db: AgentsRunDatabaseCl
|
|
|
39
40
|
name: string;
|
|
40
41
|
hash: string;
|
|
41
42
|
} | null;
|
|
42
|
-
status: "pending" | "
|
|
43
|
+
status: "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
43
44
|
scheduledFor: string;
|
|
44
45
|
startedAt: string | null;
|
|
45
46
|
completedAt: string | null;
|
|
@@ -193,7 +194,7 @@ declare const listUpcomingInvocationsForAgentPaginated: (db: AgentsRunDatabaseCl
|
|
|
193
194
|
name: string;
|
|
194
195
|
hash: string;
|
|
195
196
|
} | null;
|
|
196
|
-
status: "pending" | "
|
|
197
|
+
status: "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
197
198
|
scheduledFor: string;
|
|
198
199
|
startedAt: string | null;
|
|
199
200
|
completedAt: string | null;
|
|
@@ -232,7 +233,7 @@ declare const listProjectScheduledTriggerInvocationsPaginated: (db: AgentsRunDat
|
|
|
232
233
|
name: string;
|
|
233
234
|
hash: string;
|
|
234
235
|
} | null;
|
|
235
|
-
status: "pending" | "
|
|
236
|
+
status: "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
236
237
|
scheduledFor: string;
|
|
237
238
|
startedAt: string | null;
|
|
238
239
|
completedAt: string | null;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { AgentScopeConfig } from "../../db/manage/scope-definitions.js";
|
|
2
|
+
import { PaginationConfig } from "../../types/utility.js";
|
|
3
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
4
|
+
import { ScheduledTrigger, ScheduledTriggerInsert } from "../../types/entities.js";
|
|
5
|
+
|
|
6
|
+
//#region src/data-access/runtime/scheduledTriggers.d.ts
|
|
7
|
+
declare const getScheduledTriggerById: (db: AgentsRunDatabaseClient) => (params: {
|
|
8
|
+
scopes: AgentScopeConfig;
|
|
9
|
+
scheduledTriggerId: string;
|
|
10
|
+
}) => Promise<ScheduledTrigger | undefined>;
|
|
11
|
+
declare const listScheduledTriggersPaginated: (db: AgentsRunDatabaseClient) => (params: {
|
|
12
|
+
scopes: AgentScopeConfig;
|
|
13
|
+
pagination?: PaginationConfig;
|
|
14
|
+
}) => Promise<{
|
|
15
|
+
data: {
|
|
16
|
+
createdAt: string;
|
|
17
|
+
updatedAt: string;
|
|
18
|
+
name: string;
|
|
19
|
+
description: string | null;
|
|
20
|
+
enabled: boolean;
|
|
21
|
+
cronExpression: string | null;
|
|
22
|
+
cronTimezone: string | null;
|
|
23
|
+
runAt: string | null;
|
|
24
|
+
payload: Record<string, unknown> | null;
|
|
25
|
+
messageTemplate: string | null;
|
|
26
|
+
maxRetries: number;
|
|
27
|
+
retryDelaySeconds: number;
|
|
28
|
+
timeoutSeconds: number;
|
|
29
|
+
runAsUserId: string | null;
|
|
30
|
+
createdBy: string | null;
|
|
31
|
+
nextRunAt: string | null;
|
|
32
|
+
ref: string;
|
|
33
|
+
agentId: string;
|
|
34
|
+
projectId: string;
|
|
35
|
+
tenantId: string;
|
|
36
|
+
id: string;
|
|
37
|
+
}[];
|
|
38
|
+
pagination: {
|
|
39
|
+
page: number;
|
|
40
|
+
limit: number;
|
|
41
|
+
total: number;
|
|
42
|
+
pages: number;
|
|
43
|
+
};
|
|
44
|
+
}>;
|
|
45
|
+
declare const createScheduledTrigger: (db: AgentsRunDatabaseClient) => (params: ScheduledTriggerInsert & {
|
|
46
|
+
nextRunAt?: string | null;
|
|
47
|
+
}) => Promise<ScheduledTrigger>;
|
|
48
|
+
declare const updateScheduledTrigger: (db: AgentsRunDatabaseClient) => (params: {
|
|
49
|
+
scopes: AgentScopeConfig;
|
|
50
|
+
scheduledTriggerId: string;
|
|
51
|
+
data: Partial<ScheduledTriggerInsert> & {
|
|
52
|
+
nextRunAt?: string | null;
|
|
53
|
+
};
|
|
54
|
+
}) => Promise<ScheduledTrigger>;
|
|
55
|
+
declare const deleteScheduledTrigger: (db: AgentsRunDatabaseClient) => (params: {
|
|
56
|
+
scopes: AgentScopeConfig;
|
|
57
|
+
scheduledTriggerId: string;
|
|
58
|
+
}) => Promise<void>;
|
|
59
|
+
declare const upsertScheduledTrigger: (db: AgentsRunDatabaseClient) => (params: {
|
|
60
|
+
scopes: AgentScopeConfig;
|
|
61
|
+
data: ScheduledTriggerInsert;
|
|
62
|
+
}) => Promise<ScheduledTrigger>;
|
|
63
|
+
declare const deleteScheduledTriggersByRunAsUserId: (db: AgentsRunDatabaseClient) => (params: {
|
|
64
|
+
tenantId: string;
|
|
65
|
+
projectId: string;
|
|
66
|
+
runAsUserId: string;
|
|
67
|
+
}) => Promise<void>;
|
|
68
|
+
declare const listScheduledTriggers: (db: AgentsRunDatabaseClient) => (params: {
|
|
69
|
+
scopes: AgentScopeConfig;
|
|
70
|
+
}) => Promise<ScheduledTrigger[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Query due scheduled triggers across all projects directly from the runtime DB.
|
|
73
|
+
* No AS OF queries needed - simple WHERE clause on enabled + nextRunAt.
|
|
74
|
+
*/
|
|
75
|
+
declare const findDueScheduledTriggersAcrossProjects: (db: AgentsRunDatabaseClient) => (params: {
|
|
76
|
+
asOf: string;
|
|
77
|
+
}) => Promise<ScheduledTrigger[]>;
|
|
78
|
+
/**
|
|
79
|
+
* Advance the next_run_at timestamp for a scheduled trigger in the runtime DB.
|
|
80
|
+
* No withRef scope needed - direct update.
|
|
81
|
+
*/
|
|
82
|
+
declare const advanceScheduledTriggerNextRunAt: (db: AgentsRunDatabaseClient) => (params: {
|
|
83
|
+
scopes: AgentScopeConfig;
|
|
84
|
+
scheduledTriggerId: string;
|
|
85
|
+
nextRunAt: string | null;
|
|
86
|
+
enabled?: boolean;
|
|
87
|
+
}) => Promise<void>;
|
|
88
|
+
//#endregion
|
|
89
|
+
export { advanceScheduledTriggerNextRunAt, createScheduledTrigger, deleteScheduledTrigger, deleteScheduledTriggersByRunAsUserId, findDueScheduledTriggersAcrossProjects, getScheduledTriggerById, listScheduledTriggers, listScheduledTriggersPaginated, updateScheduledTrigger, upsertScheduledTrigger };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { scheduledTriggers } from "../../db/runtime/runtime-schema.js";
|
|
2
|
+
import { computeNextRunAt } from "../../utils/compute-next-run-at.js";
|
|
3
|
+
import { and, count, desc, eq, isNotNull, lte } from "drizzle-orm";
|
|
4
|
+
|
|
5
|
+
//#region src/data-access/runtime/scheduledTriggers.ts
|
|
6
|
+
const getScheduledTriggerById = (db) => async (params) => {
|
|
7
|
+
return await db.query.scheduledTriggers.findFirst({ where: and(eq(scheduledTriggers.tenantId, params.scopes.tenantId), eq(scheduledTriggers.projectId, params.scopes.projectId), eq(scheduledTriggers.agentId, params.scopes.agentId), eq(scheduledTriggers.id, params.scheduledTriggerId)) });
|
|
8
|
+
};
|
|
9
|
+
const listScheduledTriggersPaginated = (db) => async (params) => {
|
|
10
|
+
const page = params.pagination?.page || 1;
|
|
11
|
+
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
12
|
+
const offset = (page - 1) * limit;
|
|
13
|
+
const whereClause = and(eq(scheduledTriggers.tenantId, params.scopes.tenantId), eq(scheduledTriggers.projectId, params.scopes.projectId), eq(scheduledTriggers.agentId, params.scopes.agentId));
|
|
14
|
+
const [data, totalResult] = await Promise.all([db.select().from(scheduledTriggers).where(whereClause).limit(limit).offset(offset).orderBy(desc(scheduledTriggers.createdAt)), db.select({ count: count() }).from(scheduledTriggers).where(whereClause)]);
|
|
15
|
+
const total = totalResult[0]?.count || 0;
|
|
16
|
+
return {
|
|
17
|
+
data,
|
|
18
|
+
pagination: {
|
|
19
|
+
page,
|
|
20
|
+
limit,
|
|
21
|
+
total,
|
|
22
|
+
pages: Math.ceil(total / limit)
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const createScheduledTrigger = (db) => async (params) => {
|
|
27
|
+
const created = (await db.insert(scheduledTriggers).values(params).returning())[0];
|
|
28
|
+
if (!created) throw new Error("Failed to create scheduled trigger");
|
|
29
|
+
return created;
|
|
30
|
+
};
|
|
31
|
+
const updateScheduledTrigger = (db) => async (params) => {
|
|
32
|
+
const updateData = {
|
|
33
|
+
...params.data,
|
|
34
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
35
|
+
};
|
|
36
|
+
const updated = (await db.update(scheduledTriggers).set(updateData).where(and(eq(scheduledTriggers.tenantId, params.scopes.tenantId), eq(scheduledTriggers.projectId, params.scopes.projectId), eq(scheduledTriggers.agentId, params.scopes.agentId), eq(scheduledTriggers.id, params.scheduledTriggerId))).returning())[0];
|
|
37
|
+
if (!updated) throw new Error(`Scheduled trigger ${params.scheduledTriggerId} not found for update`);
|
|
38
|
+
return updated;
|
|
39
|
+
};
|
|
40
|
+
const deleteScheduledTrigger = (db) => async (params) => {
|
|
41
|
+
await db.delete(scheduledTriggers).where(and(eq(scheduledTriggers.tenantId, params.scopes.tenantId), eq(scheduledTriggers.projectId, params.scopes.projectId), eq(scheduledTriggers.agentId, params.scopes.agentId), eq(scheduledTriggers.id, params.scheduledTriggerId)));
|
|
42
|
+
};
|
|
43
|
+
const upsertScheduledTrigger = (db) => async (params) => {
|
|
44
|
+
const nextRunAt = params.data.enabled ?? true ? computeNextRunAt({
|
|
45
|
+
cronExpression: params.data.cronExpression,
|
|
46
|
+
cronTimezone: params.data.cronTimezone,
|
|
47
|
+
runAt: params.data.runAt
|
|
48
|
+
}) : null;
|
|
49
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
50
|
+
const values = {
|
|
51
|
+
...params.data,
|
|
52
|
+
nextRunAt
|
|
53
|
+
};
|
|
54
|
+
const upserted = (await db.insert(scheduledTriggers).values(values).onConflictDoUpdate({
|
|
55
|
+
target: [scheduledTriggers.tenantId, scheduledTriggers.id],
|
|
56
|
+
set: {
|
|
57
|
+
...values,
|
|
58
|
+
updatedAt: now
|
|
59
|
+
}
|
|
60
|
+
}).returning())[0];
|
|
61
|
+
if (!upserted) throw new Error(`Failed to upsert scheduled trigger ${params.data.id}`);
|
|
62
|
+
return upserted;
|
|
63
|
+
};
|
|
64
|
+
const deleteScheduledTriggersByRunAsUserId = (db) => async (params) => {
|
|
65
|
+
await db.delete(scheduledTriggers).where(and(eq(scheduledTriggers.tenantId, params.tenantId), eq(scheduledTriggers.projectId, params.projectId), eq(scheduledTriggers.runAsUserId, params.runAsUserId)));
|
|
66
|
+
};
|
|
67
|
+
const listScheduledTriggers = (db) => async (params) => {
|
|
68
|
+
return await db.select().from(scheduledTriggers).where(and(eq(scheduledTriggers.tenantId, params.scopes.tenantId), eq(scheduledTriggers.projectId, params.scopes.projectId), eq(scheduledTriggers.agentId, params.scopes.agentId)));
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Query due scheduled triggers across all projects directly from the runtime DB.
|
|
72
|
+
* No AS OF queries needed - simple WHERE clause on enabled + nextRunAt.
|
|
73
|
+
*/
|
|
74
|
+
const findDueScheduledTriggersAcrossProjects = (db) => async (params) => {
|
|
75
|
+
return await db.select().from(scheduledTriggers).where(and(eq(scheduledTriggers.enabled, true), isNotNull(scheduledTriggers.nextRunAt), lte(scheduledTriggers.nextRunAt, params.asOf)));
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Advance the next_run_at timestamp for a scheduled trigger in the runtime DB.
|
|
79
|
+
* No withRef scope needed - direct update.
|
|
80
|
+
*/
|
|
81
|
+
const advanceScheduledTriggerNextRunAt = (db) => async (params) => {
|
|
82
|
+
const set = {
|
|
83
|
+
nextRunAt: params.nextRunAt,
|
|
84
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
85
|
+
};
|
|
86
|
+
if (params.enabled !== void 0) set.enabled = params.enabled;
|
|
87
|
+
await db.update(scheduledTriggers).set(set).where(and(eq(scheduledTriggers.tenantId, params.scopes.tenantId), eq(scheduledTriggers.projectId, params.scopes.projectId), eq(scheduledTriggers.agentId, params.scopes.agentId), eq(scheduledTriggers.id, params.scheduledTriggerId)));
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
export { advanceScheduledTriggerNextRunAt, createScheduledTrigger, deleteScheduledTrigger, deleteScheduledTriggersByRunAsUserId, findDueScheduledTriggersAcrossProjects, getScheduledTriggerById, listScheduledTriggers, listScheduledTriggersPaginated, updateScheduledTrigger, upsertScheduledTrigger };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
2
|
+
import { SchedulerState } from "../../types/entities.js";
|
|
3
|
+
|
|
4
|
+
//#region src/data-access/runtime/schedulerState.d.ts
|
|
5
|
+
declare const getSchedulerState: (db: AgentsRunDatabaseClient) => () => Promise<SchedulerState | undefined>;
|
|
6
|
+
declare const upsertSchedulerState: (db: AgentsRunDatabaseClient) => (params: {
|
|
7
|
+
currentRunId: string;
|
|
8
|
+
}) => Promise<SchedulerState>;
|
|
9
|
+
declare const clearSchedulerState: (db: AgentsRunDatabaseClient) => () => Promise<void>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { clearSchedulerState, getSchedulerState, upsertSchedulerState };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { schedulerState } from "../../db/runtime/runtime-schema.js";
|
|
2
|
+
import { eq, sql } from "drizzle-orm";
|
|
3
|
+
|
|
4
|
+
//#region src/data-access/runtime/schedulerState.ts
|
|
5
|
+
const SINGLETON_ID = "singleton";
|
|
6
|
+
const getSchedulerState = (db) => async () => {
|
|
7
|
+
return await db.query.schedulerState.findFirst({ where: eq(schedulerState.id, SINGLETON_ID) });
|
|
8
|
+
};
|
|
9
|
+
const upsertSchedulerState = (db) => async (params) => {
|
|
10
|
+
const [row] = await db.insert(schedulerState).values({
|
|
11
|
+
id: SINGLETON_ID,
|
|
12
|
+
currentRunId: params.currentRunId
|
|
13
|
+
}).onConflictDoUpdate({
|
|
14
|
+
target: schedulerState.id,
|
|
15
|
+
set: {
|
|
16
|
+
currentRunId: params.currentRunId,
|
|
17
|
+
updatedAt: sql`now()`.mapWith(String)
|
|
18
|
+
}
|
|
19
|
+
}).returning();
|
|
20
|
+
return row;
|
|
21
|
+
};
|
|
22
|
+
const clearSchedulerState = (db) => async () => {
|
|
23
|
+
await db.update(schedulerState).set({
|
|
24
|
+
currentRunId: null,
|
|
25
|
+
updatedAt: sql`now()`.mapWith(String)
|
|
26
|
+
}).where(eq(schedulerState.id, SINGLETON_ID));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { clearSchedulerState, getSchedulerState, upsertSchedulerState };
|