@inkeep/agents-core 0.64.1 → 0.64.6
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 +6 -6
- package/dist/auth/init.js +2 -2
- package/dist/auth/permissions.d.ts +13 -13
- package/dist/constants/otel-attributes.d.ts +5 -0
- package/dist/constants/otel-attributes.js +7 -2
- package/dist/constants/signoz-queries.d.ts +1 -0
- package/dist/constants/signoz-queries.js +2 -1
- package/dist/data-access/index.d.ts +2 -1
- package/dist/data-access/index.js +2 -1
- package/dist/data-access/manage/agents.d.ts +21 -21
- package/dist/data-access/manage/artifactComponents.d.ts +10 -10
- package/dist/data-access/manage/contextConfigs.d.ts +12 -12
- package/dist/data-access/manage/dataComponents.d.ts +4 -4
- package/dist/data-access/manage/functionTools.d.ts +14 -14
- package/dist/data-access/manage/skills.d.ts +9 -9
- package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +24 -24
- package/dist/data-access/manage/subAgentRelations.d.ts +20 -20
- package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +18 -18
- package/dist/data-access/manage/subAgents.d.ts +15 -15
- package/dist/data-access/manage/tools.d.ts +21 -21
- package/dist/data-access/manage/tools.js +1 -1
- package/dist/data-access/manage/triggers.d.ts +2 -2
- 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/conversations.d.ts +24 -24
- package/dist/data-access/runtime/messages.d.ts +9 -9
- package/dist/data-access/runtime/scheduledTriggerInvocations.d.ts +4 -4
- package/dist/data-access/runtime/streamChunks.d.ts +29 -0
- package/dist/data-access/runtime/streamChunks.js +65 -0
- package/dist/data-access/runtime/tasks.d.ts +5 -5
- package/dist/db/manage/dolt-safe-jsonb.d.ts +12 -0
- package/dist/db/manage/dolt-safe-jsonb.js +61 -0
- package/dist/db/manage/manage-schema.d.ts +487 -487
- package/dist/db/manage/manage-schema.js +40 -39
- package/dist/db/runtime/runtime-schema.d.ts +510 -378
- package/dist/db/runtime/runtime-schema.js +20 -1
- package/dist/dolt/ref-helpers.js +15 -1
- package/dist/dolt/ref-scope.js +29 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +5 -4
- package/dist/setup/setup.d.ts +3 -1
- package/dist/setup/setup.js +14 -10
- package/dist/types/utility.d.ts +1 -0
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +3 -3
- package/dist/utils/jwt-helpers.d.ts +2 -3
- package/dist/utils/jwt-helpers.js +2 -3
- package/dist/utils/retry-client.d.ts +8 -0
- package/dist/utils/retry-client.js +29 -0
- package/dist/utils/service-token-auth.d.ts +3 -0
- package/dist/utils/service-token-auth.js +5 -2
- package/dist/utils/temp-jwt.d.ts +1 -6
- package/dist/utils/temp-jwt.js +1 -12
- package/dist/utils/work-app-mcp.js +1 -2
- package/dist/validation/drizzle-schema-helpers.d.ts +3 -3
- package/dist/validation/schemas/skills.d.ts +32 -32
- package/dist/validation/schemas.d.ts +2096 -2096
- package/drizzle/runtime/0031_fantastic_gorilla_man.sql +13 -0
- package/drizzle/runtime/meta/0031_snapshot.json +4872 -0
- package/drizzle/runtime/meta/_journal.json +7 -0
- package/package.json +6 -2
|
@@ -40,13 +40,13 @@ declare const listTriggersPaginated: (db: AgentsManageDatabaseClient) => (params
|
|
|
40
40
|
algorithm: "sha256" | "sha512" | "sha384" | "sha1" | "md5";
|
|
41
41
|
encoding: "hex" | "base64";
|
|
42
42
|
signature: {
|
|
43
|
-
source: "query" | "
|
|
43
|
+
source: "query" | "body" | "header";
|
|
44
44
|
key: string;
|
|
45
45
|
prefix?: string | undefined;
|
|
46
46
|
regex?: string | undefined;
|
|
47
47
|
};
|
|
48
48
|
signedComponents: {
|
|
49
|
-
source: "literal" | "
|
|
49
|
+
source: "literal" | "body" | "header";
|
|
50
50
|
required: boolean;
|
|
51
51
|
key?: string | undefined;
|
|
52
52
|
value?: string | undefined;
|
|
@@ -8,28 +8,28 @@ declare const getApiKeyById: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
8
8
|
scopes: ProjectScopeConfig;
|
|
9
9
|
id: string;
|
|
10
10
|
}) => Promise<{
|
|
11
|
-
tenantId: string;
|
|
12
|
-
projectId: string;
|
|
13
11
|
id: string;
|
|
14
12
|
name: string | null;
|
|
15
13
|
createdAt: string;
|
|
16
14
|
updatedAt: string;
|
|
17
|
-
agentId: string;
|
|
18
15
|
expiresAt: string | null;
|
|
16
|
+
agentId: string;
|
|
17
|
+
projectId: string;
|
|
18
|
+
tenantId: string;
|
|
19
19
|
publicId: string;
|
|
20
20
|
keyHash: string;
|
|
21
21
|
keyPrefix: string;
|
|
22
22
|
lastUsedAt: string | null;
|
|
23
23
|
} | undefined>;
|
|
24
24
|
declare const getApiKeyByPublicId: (db: AgentsRunDatabaseClient) => (publicId: string) => Promise<{
|
|
25
|
-
tenantId: string;
|
|
26
|
-
projectId: string;
|
|
27
25
|
id: string;
|
|
28
26
|
name: string | null;
|
|
29
27
|
createdAt: string;
|
|
30
28
|
updatedAt: string;
|
|
31
|
-
agentId: string;
|
|
32
29
|
expiresAt: string | null;
|
|
30
|
+
agentId: string;
|
|
31
|
+
projectId: string;
|
|
32
|
+
tenantId: string;
|
|
33
33
|
publicId: string;
|
|
34
34
|
keyHash: string;
|
|
35
35
|
keyPrefix: string;
|
|
@@ -39,14 +39,14 @@ declare const listApiKeys: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
39
39
|
scopes: ProjectScopeConfig;
|
|
40
40
|
agentId?: string;
|
|
41
41
|
}) => Promise<{
|
|
42
|
-
tenantId: string;
|
|
43
|
-
projectId: string;
|
|
44
42
|
id: string;
|
|
45
43
|
name: string | null;
|
|
46
44
|
createdAt: string;
|
|
47
45
|
updatedAt: string;
|
|
48
|
-
agentId: string;
|
|
49
46
|
expiresAt: string | null;
|
|
47
|
+
agentId: string;
|
|
48
|
+
projectId: string;
|
|
49
|
+
tenantId: string;
|
|
50
50
|
publicId: string;
|
|
51
51
|
keyHash: string;
|
|
52
52
|
keyPrefix: string;
|
|
@@ -66,14 +66,14 @@ declare const listApiKeysPaginated: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
66
66
|
};
|
|
67
67
|
}>;
|
|
68
68
|
declare const createApiKey: (db: AgentsRunDatabaseClient) => (params: ApiKeyInsert) => Promise<{
|
|
69
|
-
tenantId: string;
|
|
70
|
-
projectId: string;
|
|
71
69
|
id: string;
|
|
72
70
|
name: string | null;
|
|
73
71
|
createdAt: string;
|
|
74
72
|
updatedAt: string;
|
|
75
|
-
agentId: string;
|
|
76
73
|
expiresAt: string | null;
|
|
74
|
+
agentId: string;
|
|
75
|
+
projectId: string;
|
|
76
|
+
tenantId: string;
|
|
77
77
|
publicId: string;
|
|
78
78
|
keyHash: string;
|
|
79
79
|
keyPrefix: string;
|
|
@@ -5,16 +5,16 @@ 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
|
-
tenantId: string | null;
|
|
10
|
-
projectId: string | null;
|
|
11
8
|
id: string;
|
|
12
9
|
name: string;
|
|
10
|
+
createdAt: string;
|
|
11
|
+
updatedAt: string;
|
|
13
12
|
description: string | null;
|
|
14
13
|
enabled: boolean;
|
|
14
|
+
type: AppType;
|
|
15
|
+
projectId: string | null;
|
|
16
|
+
tenantId: string | null;
|
|
15
17
|
prompt: string | null;
|
|
16
|
-
createdAt: string;
|
|
17
|
-
updatedAt: string;
|
|
18
18
|
config: {
|
|
19
19
|
type: "web_client";
|
|
20
20
|
webClient: {
|
|
@@ -61,16 +61,16 @@ declare const listAppsPaginated: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
61
61
|
};
|
|
62
62
|
}>;
|
|
63
63
|
declare const createApp: (db: AgentsRunDatabaseClient) => (params: AppInsert) => Promise<{
|
|
64
|
-
type: AppType;
|
|
65
|
-
tenantId: string | null;
|
|
66
|
-
projectId: string | null;
|
|
67
64
|
id: string;
|
|
68
65
|
name: string;
|
|
66
|
+
createdAt: string;
|
|
67
|
+
updatedAt: string;
|
|
69
68
|
description: string | null;
|
|
70
69
|
enabled: boolean;
|
|
70
|
+
type: AppType;
|
|
71
|
+
projectId: string | null;
|
|
72
|
+
tenantId: string | null;
|
|
71
73
|
prompt: string | null;
|
|
72
|
-
createdAt: string;
|
|
73
|
-
updatedAt: string;
|
|
74
74
|
config: {
|
|
75
75
|
type: "web_client";
|
|
76
76
|
webClient: {
|
|
@@ -15,20 +15,20 @@ declare const listConversations: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
15
15
|
total: number;
|
|
16
16
|
}>;
|
|
17
17
|
declare const createConversation: (db: AgentsRunDatabaseClient) => (params: ConversationInsert) => Promise<{
|
|
18
|
-
tenantId: string;
|
|
19
|
-
userId: string | null;
|
|
20
|
-
projectId: string;
|
|
21
18
|
id: string;
|
|
22
|
-
title: string | null;
|
|
23
19
|
createdAt: string;
|
|
24
20
|
updatedAt: string;
|
|
25
|
-
metadata: ConversationMetadata | null;
|
|
26
|
-
agentId: string | null;
|
|
27
21
|
ref: {
|
|
28
22
|
type: "commit" | "tag" | "branch";
|
|
29
23
|
name: string;
|
|
30
24
|
hash: string;
|
|
31
25
|
} | null;
|
|
26
|
+
userId: string | null;
|
|
27
|
+
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
|
}>;
|
|
@@ -84,20 +84,20 @@ declare const getConversation: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
84
84
|
scopes: ProjectScopeConfig;
|
|
85
85
|
conversationId: string;
|
|
86
86
|
}) => Promise<{
|
|
87
|
-
tenantId: string;
|
|
88
|
-
userId: string | null;
|
|
89
|
-
projectId: string;
|
|
90
87
|
id: string;
|
|
91
|
-
title: string | null;
|
|
92
88
|
createdAt: string;
|
|
93
89
|
updatedAt: string;
|
|
94
|
-
metadata: ConversationMetadata | null;
|
|
95
|
-
agentId: string | null;
|
|
96
90
|
ref: {
|
|
97
91
|
type: "commit" | "tag" | "branch";
|
|
98
92
|
name: string;
|
|
99
93
|
hash: string;
|
|
100
94
|
} | null;
|
|
95
|
+
userId: string | null;
|
|
96
|
+
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>;
|
|
@@ -120,20 +120,20 @@ declare const createOrGetConversation: (db: AgentsRunDatabaseClient) => (input:
|
|
|
120
120
|
metadata?: ConversationMetadata | null | undefined;
|
|
121
121
|
contextConfigId?: string | undefined;
|
|
122
122
|
} | {
|
|
123
|
-
tenantId: string;
|
|
124
|
-
userId: string | null;
|
|
125
|
-
projectId: string;
|
|
126
123
|
id: string;
|
|
127
|
-
title: string | null;
|
|
128
124
|
createdAt: string;
|
|
129
125
|
updatedAt: string;
|
|
130
|
-
metadata: ConversationMetadata | null;
|
|
131
|
-
agentId: string | null;
|
|
132
126
|
ref: {
|
|
133
127
|
type: "commit" | "tag" | "branch";
|
|
134
128
|
name: string;
|
|
135
129
|
hash: string;
|
|
136
130
|
} | null;
|
|
131
|
+
userId: string | null;
|
|
132
|
+
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
|
}>;
|
|
@@ -152,20 +152,20 @@ declare const getActiveAgentForConversation: (db: AgentsRunDatabaseClient) => (p
|
|
|
152
152
|
scopes: ProjectScopeConfig;
|
|
153
153
|
conversationId: string;
|
|
154
154
|
}) => Promise<{
|
|
155
|
-
tenantId: string;
|
|
156
|
-
userId: string | null;
|
|
157
|
-
projectId: string;
|
|
158
155
|
id: string;
|
|
159
|
-
title: string | null;
|
|
160
156
|
createdAt: string;
|
|
161
157
|
updatedAt: string;
|
|
162
|
-
metadata: ConversationMetadata | null;
|
|
163
|
-
agentId: string | null;
|
|
164
158
|
ref: {
|
|
165
159
|
type: "commit" | "tag" | "branch";
|
|
166
160
|
name: string;
|
|
167
161
|
hash: string;
|
|
168
162
|
} | null;
|
|
163
|
+
userId: string | null;
|
|
164
|
+
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>;
|
|
@@ -10,14 +10,14 @@ declare const getMessageById: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
10
10
|
scopes: ProjectScopeConfig;
|
|
11
11
|
messageId: string;
|
|
12
12
|
}) => Promise<{
|
|
13
|
-
tenantId: string;
|
|
14
|
-
projectId: string;
|
|
15
13
|
id: string;
|
|
16
14
|
createdAt: string;
|
|
17
15
|
updatedAt: string;
|
|
18
16
|
metadata: MessageMetadata | null;
|
|
19
|
-
content: MessageContent;
|
|
20
17
|
role: string;
|
|
18
|
+
projectId: string;
|
|
19
|
+
tenantId: string;
|
|
20
|
+
content: MessageContent;
|
|
21
21
|
conversationId: string;
|
|
22
22
|
fromSubAgentId: string | null;
|
|
23
23
|
toSubAgentId: string | null;
|
|
@@ -144,14 +144,14 @@ declare const createMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
144
144
|
scopes: ProjectScopeConfig;
|
|
145
145
|
data: Omit<MessageInsert, "tenantId" | "projectId">;
|
|
146
146
|
}) => Promise<{
|
|
147
|
-
tenantId: string;
|
|
148
|
-
projectId: string;
|
|
149
147
|
id: string;
|
|
150
148
|
createdAt: string;
|
|
151
149
|
updatedAt: string;
|
|
152
150
|
metadata: MessageMetadata | null;
|
|
153
|
-
content: MessageContent;
|
|
154
151
|
role: string;
|
|
152
|
+
projectId: string;
|
|
153
|
+
tenantId: string;
|
|
154
|
+
content: MessageContent;
|
|
155
155
|
conversationId: string;
|
|
156
156
|
fromSubAgentId: string | null;
|
|
157
157
|
toSubAgentId: string | null;
|
|
@@ -197,14 +197,14 @@ declare const deleteMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
197
197
|
scopes: ProjectScopeConfig;
|
|
198
198
|
messageId: string;
|
|
199
199
|
}) => Promise<{
|
|
200
|
-
tenantId: string;
|
|
201
|
-
projectId: string;
|
|
202
200
|
id: string;
|
|
203
201
|
createdAt: string;
|
|
204
202
|
updatedAt: string;
|
|
205
203
|
metadata: MessageMetadata | null;
|
|
206
|
-
content: MessageContent;
|
|
207
204
|
role: string;
|
|
205
|
+
projectId: string;
|
|
206
|
+
tenantId: string;
|
|
207
|
+
content: MessageContent;
|
|
208
208
|
conversationId: string;
|
|
209
209
|
fromSubAgentId: string | null;
|
|
210
210
|
toSubAgentId: string | null;
|
|
@@ -40,7 +40,7 @@ declare const listScheduledTriggerInvocationsPaginated: (db: AgentsRunDatabaseCl
|
|
|
40
40
|
name: string;
|
|
41
41
|
hash: string;
|
|
42
42
|
} | null;
|
|
43
|
-
status: "pending" | "
|
|
43
|
+
status: "pending" | "failed" | "running" | "completed" | "cancelled";
|
|
44
44
|
scheduledFor: string;
|
|
45
45
|
startedAt: string | null;
|
|
46
46
|
completedAt: string | null;
|
|
@@ -194,7 +194,7 @@ declare const listUpcomingInvocationsForAgentPaginated: (db: AgentsRunDatabaseCl
|
|
|
194
194
|
name: string;
|
|
195
195
|
hash: string;
|
|
196
196
|
} | null;
|
|
197
|
-
status: "pending" | "
|
|
197
|
+
status: "pending" | "failed" | "running" | "completed" | "cancelled";
|
|
198
198
|
scheduledFor: string;
|
|
199
199
|
startedAt: string | null;
|
|
200
200
|
completedAt: string | null;
|
|
@@ -233,7 +233,7 @@ declare const listProjectScheduledTriggerInvocationsPaginated: (db: AgentsRunDat
|
|
|
233
233
|
name: string;
|
|
234
234
|
hash: string;
|
|
235
235
|
} | null;
|
|
236
|
-
status: "pending" | "
|
|
236
|
+
status: "pending" | "failed" | "running" | "completed" | "cancelled";
|
|
237
237
|
scheduledFor: string;
|
|
238
238
|
startedAt: string | null;
|
|
239
239
|
completedAt: string | null;
|
|
@@ -285,7 +285,7 @@ declare const listScheduledTriggerInvocationsByTriggerId: (db: AgentsRunDatabase
|
|
|
285
285
|
name: string;
|
|
286
286
|
hash: string;
|
|
287
287
|
} | null;
|
|
288
|
-
status: "pending" | "
|
|
288
|
+
status: "pending" | "failed" | "running" | "completed" | "cancelled";
|
|
289
289
|
scheduledFor: string;
|
|
290
290
|
startedAt: string | null;
|
|
291
291
|
completedAt: string | null;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
2
|
+
|
|
3
|
+
//#region src/data-access/runtime/streamChunks.d.ts
|
|
4
|
+
interface ConversationScope {
|
|
5
|
+
tenantId: string;
|
|
6
|
+
projectId: string;
|
|
7
|
+
conversationId: string;
|
|
8
|
+
}
|
|
9
|
+
declare const insertStreamChunks: (db: AgentsRunDatabaseClient) => (params: ConversationScope & {
|
|
10
|
+
chunks: {
|
|
11
|
+
idx: number;
|
|
12
|
+
data: string;
|
|
13
|
+
}[];
|
|
14
|
+
}) => Promise<void>;
|
|
15
|
+
declare const markStreamComplete: (db: AgentsRunDatabaseClient) => (params: ConversationScope & {
|
|
16
|
+
finalIdx: number;
|
|
17
|
+
}) => Promise<void>;
|
|
18
|
+
declare const getStreamChunks: (db: AgentsRunDatabaseClient) => (params: ConversationScope & {
|
|
19
|
+
afterIdx?: number;
|
|
20
|
+
limit?: number;
|
|
21
|
+
}) => Promise<{
|
|
22
|
+
idx: number;
|
|
23
|
+
data: string;
|
|
24
|
+
isFinal: boolean;
|
|
25
|
+
}[]>;
|
|
26
|
+
declare const deleteStreamChunks: (db: AgentsRunDatabaseClient) => (params: ConversationScope) => Promise<void>;
|
|
27
|
+
declare const cleanupExpiredStreamChunks: (db: AgentsRunDatabaseClient) => (olderThanMinutes?: number, batchSize?: number) => Promise<void>;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { cleanupExpiredStreamChunks, deleteStreamChunks, getStreamChunks, insertStreamChunks, markStreamComplete };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { streamChunks } from "../../db/runtime/runtime-schema.js";
|
|
2
|
+
import { and, eq, gt, sql } from "drizzle-orm";
|
|
3
|
+
|
|
4
|
+
//#region src/data-access/runtime/streamChunks.ts
|
|
5
|
+
const DEFAULT_CHUNK_BATCH_LIMIT = 500;
|
|
6
|
+
const DEFAULT_CLEANUP_AGE_MINUTES = 60;
|
|
7
|
+
const DEFAULT_CLEANUP_BATCH_SIZE = 1e3;
|
|
8
|
+
const scopeConditions = (scope) => [
|
|
9
|
+
eq(streamChunks.tenantId, scope.tenantId),
|
|
10
|
+
eq(streamChunks.projectId, scope.projectId),
|
|
11
|
+
eq(streamChunks.conversationId, scope.conversationId)
|
|
12
|
+
];
|
|
13
|
+
const insertStreamChunks = (db) => async (params) => {
|
|
14
|
+
if (params.chunks.length === 0) return;
|
|
15
|
+
await db.insert(streamChunks).values(params.chunks.map((chunk) => ({
|
|
16
|
+
tenantId: params.tenantId,
|
|
17
|
+
projectId: params.projectId,
|
|
18
|
+
conversationId: params.conversationId,
|
|
19
|
+
idx: chunk.idx,
|
|
20
|
+
data: chunk.data,
|
|
21
|
+
isFinal: false
|
|
22
|
+
})));
|
|
23
|
+
};
|
|
24
|
+
const markStreamComplete = (db) => async (params) => {
|
|
25
|
+
await db.insert(streamChunks).values({
|
|
26
|
+
tenantId: params.tenantId,
|
|
27
|
+
projectId: params.projectId,
|
|
28
|
+
conversationId: params.conversationId,
|
|
29
|
+
idx: params.finalIdx,
|
|
30
|
+
data: "",
|
|
31
|
+
isFinal: true
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const getStreamChunks = (db) => async (params) => {
|
|
35
|
+
const conditions = scopeConditions(params);
|
|
36
|
+
if (params.afterIdx !== void 0) conditions.push(gt(streamChunks.idx, params.afterIdx));
|
|
37
|
+
return db.select({
|
|
38
|
+
idx: streamChunks.idx,
|
|
39
|
+
data: streamChunks.data,
|
|
40
|
+
isFinal: streamChunks.isFinal
|
|
41
|
+
}).from(streamChunks).where(and(...conditions)).orderBy(streamChunks.idx).limit(params.limit ?? DEFAULT_CHUNK_BATCH_LIMIT);
|
|
42
|
+
};
|
|
43
|
+
const deleteStreamChunks = (db) => async (params) => {
|
|
44
|
+
await db.delete(streamChunks).where(and(...scopeConditions(params)));
|
|
45
|
+
};
|
|
46
|
+
const cleanupExpiredStreamChunks = (db) => async (olderThanMinutes = DEFAULT_CLEANUP_AGE_MINUTES, batchSize = DEFAULT_CLEANUP_BATCH_SIZE) => {
|
|
47
|
+
const cutoff = sql`now() - make_interval(mins => ${olderThanMinutes})`;
|
|
48
|
+
let deleted;
|
|
49
|
+
do {
|
|
50
|
+
const batch = await db.select({
|
|
51
|
+
tenantId: streamChunks.tenantId,
|
|
52
|
+
projectId: streamChunks.projectId,
|
|
53
|
+
conversationId: streamChunks.conversationId,
|
|
54
|
+
idx: streamChunks.idx
|
|
55
|
+
}).from(streamChunks).where(sql`${streamChunks.createdAt} < ${cutoff}`).limit(batchSize);
|
|
56
|
+
deleted = batch.length;
|
|
57
|
+
if (deleted > 0) {
|
|
58
|
+
const pks = batch.map((row) => sql`(${row.tenantId}, ${row.projectId}, ${row.conversationId}, ${row.idx})`);
|
|
59
|
+
await db.delete(streamChunks).where(sql`(${streamChunks.tenantId}, ${streamChunks.projectId}, ${streamChunks.conversationId}, ${streamChunks.idx}) IN (${sql.join(pks, sql`, `)})`);
|
|
60
|
+
}
|
|
61
|
+
} while (deleted >= batchSize);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
export { cleanupExpiredStreamChunks, deleteStreamChunks, getStreamChunks, insertStreamChunks, markStreamComplete };
|
|
@@ -7,21 +7,21 @@ import { TaskInsert, TaskSelect } from "../../types/entities.js";
|
|
|
7
7
|
|
|
8
8
|
//#region src/data-access/runtime/tasks.d.ts
|
|
9
9
|
declare const createTask: (db: AgentsRunDatabaseClient) => (params: TaskInsert) => Promise<{
|
|
10
|
-
tenantId: string;
|
|
11
|
-
projectId: string;
|
|
12
10
|
id: string;
|
|
13
11
|
createdAt: string;
|
|
14
12
|
updatedAt: string;
|
|
15
|
-
metadata: TaskMetadataConfig | null;
|
|
16
|
-
agentId: string;
|
|
17
|
-
subAgentId: string;
|
|
18
13
|
ref: {
|
|
19
14
|
type: "commit" | "tag" | "branch";
|
|
20
15
|
name: string;
|
|
21
16
|
hash: string;
|
|
22
17
|
} | null;
|
|
18
|
+
metadata: TaskMetadataConfig | null;
|
|
23
19
|
status: string;
|
|
20
|
+
agentId: string;
|
|
21
|
+
projectId: string;
|
|
22
|
+
tenantId: string;
|
|
24
23
|
contextId: string;
|
|
24
|
+
subAgentId: string;
|
|
25
25
|
}>;
|
|
26
26
|
declare const getTask: (db: AgentsRunDatabaseClient) => (params: {
|
|
27
27
|
id: string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as drizzle_orm_pg_core1809 from "drizzle-orm/pg-core";
|
|
2
|
+
|
|
3
|
+
//#region src/db/manage/dolt-safe-jsonb.d.ts
|
|
4
|
+
declare function encodeBackslashes(value: unknown): unknown;
|
|
5
|
+
declare function decodeBackslashes(value: unknown): unknown;
|
|
6
|
+
/**
|
|
7
|
+
* Drop-in replacement for drizzle-orm's `jsonb()`.
|
|
8
|
+
* Encodes backslashes on write and decodes on read to work around the Doltgres bug.
|
|
9
|
+
*/
|
|
10
|
+
declare function jsonb(name: string): ReturnType<typeof drizzle_orm_pg_core1809.jsonb>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { decodeBackslashes, encodeBackslashes, jsonb };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { PgJsonb, PgJsonbBuilder } from "drizzle-orm/pg-core";
|
|
2
|
+
|
|
3
|
+
//#region src/db/manage/dolt-safe-jsonb.ts
|
|
4
|
+
/**
|
|
5
|
+
* Workaround for Doltgres JSON parser bug.
|
|
6
|
+
*
|
|
7
|
+
* Doltgres has an off-by-one error in its JSON escape-sequence state machine:
|
|
8
|
+
* after parsing `\\` (escaped backslash), the parser doesn't reset to normal
|
|
9
|
+
* mode, so the next character is incorrectly treated as an escape character.
|
|
10
|
+
*
|
|
11
|
+
* The workaround encodes literal backslash characters in string values as a
|
|
12
|
+
* Unicode Private-Use-Area character (U+E000) before JSON.stringify, so the
|
|
13
|
+
* serialised JSON never contains `\\`. On read the placeholder is decoded back.
|
|
14
|
+
*
|
|
15
|
+
* Usage: import { jsonb } from './dolt-safe-jsonb' instead of from 'drizzle-orm/pg-core'.
|
|
16
|
+
* All existing .$type<T>(), .notNull(), .default() chains work unchanged.
|
|
17
|
+
*/
|
|
18
|
+
const BACKSLASH_PLACEHOLDER = "";
|
|
19
|
+
function encodeBackslashes(value) {
|
|
20
|
+
if (typeof value === "string") return value.replaceAll("\0", "").replaceAll("\\", BACKSLASH_PLACEHOLDER);
|
|
21
|
+
if (Array.isArray(value)) return value.map(encodeBackslashes);
|
|
22
|
+
if (value !== null && typeof value === "object") {
|
|
23
|
+
const out = {};
|
|
24
|
+
for (const [k, v] of Object.entries(value)) out[k] = encodeBackslashes(v);
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
function decodeBackslashes(value) {
|
|
30
|
+
if (typeof value === "string") return value.replaceAll(BACKSLASH_PLACEHOLDER, "\\");
|
|
31
|
+
if (Array.isArray(value)) return value.map(decodeBackslashes);
|
|
32
|
+
if (value !== null && typeof value === "object") {
|
|
33
|
+
const out = {};
|
|
34
|
+
for (const [k, v] of Object.entries(value)) out[k] = decodeBackslashes(v);
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
var DoltSafeJsonb = class extends PgJsonb {
|
|
40
|
+
mapToDriverValue(value) {
|
|
41
|
+
return super.mapToDriverValue(encodeBackslashes(value));
|
|
42
|
+
}
|
|
43
|
+
mapFromDriverValue(value) {
|
|
44
|
+
return decodeBackslashes(super.mapFromDriverValue(value));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var DoltSafeJsonbBuilder = class extends PgJsonbBuilder {
|
|
48
|
+
build(table) {
|
|
49
|
+
return new DoltSafeJsonb(table, this.config);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Drop-in replacement for drizzle-orm's `jsonb()`.
|
|
54
|
+
* Encodes backslashes on write and decodes on read to work around the Doltgres bug.
|
|
55
|
+
*/
|
|
56
|
+
function jsonb(name) {
|
|
57
|
+
return new DoltSafeJsonbBuilder(name);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
export { decodeBackslashes, encodeBackslashes, jsonb };
|