@inkeep/agents-core 0.0.0-dev-20260311074352 → 0.0.0-dev-20260311144908

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.
@@ -1,4 +1,5 @@
1
1
  import { credentialReferences, externalAgents, tools } from "../../db/manage/manage-schema.js";
2
+ import { isUniqueConstraintError } from "../../utils/error.js";
2
3
  import { and, count, desc, eq, sql } from "drizzle-orm";
3
4
 
4
5
  //#region src/data-access/manage/credentialReferences.ts
@@ -120,15 +121,14 @@ const countCredentialReferences = (db) => async (params) => {
120
121
  };
121
122
  /**
122
123
  * Upsert a credential reference (create if it doesn't exist, update if it does).
123
- * For user-scoped credentials (toolId + userId set), uses an atomic INSERT ... ON CONFLICT
124
- * on the (toolId, userId) unique constraint to avoid TOCTOU races.
124
+ * For user-scoped credentials (toolId + userId set), also checks the unique constraint pair.
125
+ * Uses application-level find-then-update since Doltgres does not support ON CONFLICT DO UPDATE.
125
126
  */
126
127
  const upsertCredentialReference = (db) => async (params) => {
127
128
  const scopes = {
128
129
  tenantId: params.data.tenantId,
129
130
  projectId: params.data.projectId
130
131
  };
131
- const now = (/* @__PURE__ */ new Date()).toISOString();
132
132
  const existingById = await getCredentialReference(db)({
133
133
  scopes,
134
134
  id: params.data.id
@@ -148,23 +148,51 @@ const upsertCredentialReference = (db) => async (params) => {
148
148
  return updated;
149
149
  }
150
150
  if (params.data.toolId && params.data.userId) {
151
- const [result] = await db.insert(credentialReferences).values({
152
- ...params.data,
153
- createdAt: now,
154
- updatedAt: now
155
- }).onConflictDoUpdate({
156
- target: [credentialReferences.toolId, credentialReferences.userId],
157
- set: {
158
- name: params.data.name,
159
- type: params.data.type,
160
- credentialStoreId: params.data.credentialStoreId,
161
- retrievalParams: params.data.retrievalParams,
162
- updatedAt: now
151
+ const existingByToolUser = await getUserScopedCredentialReference(db)({
152
+ scopes,
153
+ toolId: params.data.toolId,
154
+ userId: params.data.userId
155
+ });
156
+ if (existingByToolUser) {
157
+ const updated = await updateCredentialReference(db)({
158
+ scopes,
159
+ id: existingByToolUser.id,
160
+ data: {
161
+ name: params.data.name,
162
+ type: params.data.type,
163
+ credentialStoreId: params.data.credentialStoreId,
164
+ retrievalParams: params.data.retrievalParams
165
+ }
166
+ });
167
+ if (!updated) throw new Error("Failed to update credential reference - no rows affected");
168
+ return updated;
169
+ }
170
+ }
171
+ try {
172
+ return await createCredentialReference(db)(params.data);
173
+ } catch (error) {
174
+ if (isUniqueConstraintError(error) && params.data.toolId && params.data.userId) {
175
+ const raceWinner = await getUserScopedCredentialReference(db)({
176
+ scopes,
177
+ toolId: params.data.toolId,
178
+ userId: params.data.userId
179
+ });
180
+ if (raceWinner) {
181
+ const updated = await updateCredentialReference(db)({
182
+ scopes,
183
+ id: raceWinner.id,
184
+ data: {
185
+ name: params.data.name,
186
+ type: params.data.type,
187
+ credentialStoreId: params.data.credentialStoreId,
188
+ retrievalParams: params.data.retrievalParams
189
+ }
190
+ });
191
+ if (updated) return updated;
163
192
  }
164
- }).returning();
165
- return result;
193
+ }
194
+ throw error;
166
195
  }
167
- return await createCredentialReference(db)(params.data);
168
196
  };
169
197
 
170
198
  //#endregion
@@ -4,6 +4,7 @@ import "../../types/index.js";
4
4
  import { CredentialStoreRegistry } from "../../credential-stores/CredentialStoreRegistry.js";
5
5
  import "../../credential-stores/index.js";
6
6
  import { AgentsManageDatabaseClient } from "../../db/manage/manage-client.js";
7
+ import { WithTimestamps } from "../../validation/extend-schemas.js";
7
8
  import "../../index.js";
8
9
  import { McpTool, ToolInsert, ToolSelect, ToolUpdate } from "../../types/entities.js";
9
10
 
@@ -13,8 +14,8 @@ import { McpTool, ToolInsert, ToolSelect, ToolUpdate } from "../../types/entitie
13
14
  * This is a fast path that returns status='unknown' and empty availableTools.
14
15
  * Use this for list views where you want instant page load.
15
16
  */
16
- declare const dbResultToMcpToolSkeleton: (dbResult: ToolSelect, relationshipId?: string) => McpTool;
17
- declare const dbResultToMcpTool: (dbResult: ToolSelect, dbClient: AgentsManageDatabaseClient, credentialStoreRegistry?: CredentialStoreRegistry, relationshipId?: string, userId?: string) => Promise<McpTool>;
17
+ declare const dbResultToMcpToolSkeleton: (dbResult: ToolSelect, relationshipId?: string) => WithTimestamps<McpTool>;
18
+ declare const dbResultToMcpTool: (dbResult: ToolSelect, dbClient: AgentsManageDatabaseClient, credentialStoreRegistry?: CredentialStoreRegistry, relationshipId?: string, userId?: string) => Promise<WithTimestamps<McpTool>>;
18
19
  declare const getToolById: (db: AgentsManageDatabaseClient) => (params: {
19
20
  scopes: ProjectScopeConfig;
20
21
  toolId: string;
@@ -99,7 +100,7 @@ declare const createTool: (db: AgentsManageDatabaseClient) => (params: ToolInser
99
100
  declare const updateTool: (db: AgentsManageDatabaseClient) => (params: {
100
101
  scopes: ProjectScopeConfig;
101
102
  toolId: string;
102
- data: ToolUpdate;
103
+ data: WithTimestamps<ToolUpdate>;
103
104
  }) => Promise<{
104
105
  createdAt: string;
105
106
  updatedAt: string;
@@ -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" | "body" | "header";
43
+ source: "query" | "header" | "body";
44
44
  key: string;
45
45
  prefix?: string | undefined;
46
46
  regex?: string | undefined;
47
47
  };
48
48
  signedComponents: {
49
- source: "literal" | "body" | "header";
49
+ source: "literal" | "header" | "body";
50
50
  required: boolean;
51
51
  key?: string | undefined;
52
52
  value?: string | undefined;
@@ -24,12 +24,12 @@ declare const createConversation: (db: AgentsRunDatabaseClient) => (params: Conv
24
24
  createdAt: string;
25
25
  updatedAt: string;
26
26
  metadata: ConversationMetadata | null;
27
- userId: string | null;
28
27
  ref: {
29
28
  type: "commit" | "tag" | "branch";
30
29
  name: string;
31
30
  hash: string;
32
31
  } | null;
32
+ userId: string | null;
33
33
  activeSubAgentId: string;
34
34
  lastContextResolution: string | null;
35
35
  }>;
@@ -93,12 +93,12 @@ declare const getConversation: (db: AgentsRunDatabaseClient) => (params: {
93
93
  createdAt: string;
94
94
  updatedAt: string;
95
95
  metadata: ConversationMetadata | null;
96
- userId: string | null;
97
96
  ref: {
98
97
  type: "commit" | "tag" | "branch";
99
98
  name: string;
100
99
  hash: string;
101
100
  } | null;
101
+ userId: string | null;
102
102
  activeSubAgentId: string;
103
103
  lastContextResolution: string | null;
104
104
  } | undefined>;
@@ -129,12 +129,12 @@ declare const createOrGetConversation: (db: AgentsRunDatabaseClient) => (input:
129
129
  createdAt: string;
130
130
  updatedAt: string;
131
131
  metadata: ConversationMetadata | null;
132
- userId: string | null;
133
132
  ref: {
134
133
  type: "commit" | "tag" | "branch";
135
134
  name: string;
136
135
  hash: string;
137
136
  } | null;
137
+ userId: string | null;
138
138
  activeSubAgentId: string;
139
139
  lastContextResolution: string | null;
140
140
  }>;
@@ -161,12 +161,12 @@ declare const getActiveAgentForConversation: (db: AgentsRunDatabaseClient) => (p
161
161
  createdAt: string;
162
162
  updatedAt: string;
163
163
  metadata: ConversationMetadata | null;
164
- userId: string | null;
165
164
  ref: {
166
165
  type: "commit" | "tag" | "branch";
167
166
  name: string;
168
167
  hash: string;
169
168
  } | null;
169
+ userId: string | null;
170
170
  activeSubAgentId: string;
171
171
  lastContextResolution: string | null;
172
172
  } | undefined>;
@@ -18,18 +18,18 @@ declare const getMessageById: (db: AgentsRunDatabaseClient) => (params: {
18
18
  metadata: MessageMetadata | null;
19
19
  content: MessageContent;
20
20
  role: string;
21
+ conversationId: string;
21
22
  fromSubAgentId: string | null;
22
23
  toSubAgentId: string | null;
23
24
  fromExternalAgentId: string | null;
24
25
  toExternalAgentId: string | null;
25
- taskId: string | null;
26
- a2aTaskId: string | null;
27
- conversationId: string;
28
26
  fromTeamAgentId: string | null;
29
27
  toTeamAgentId: string | null;
30
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: {
@@ -149,18 +149,18 @@ declare const createMessage: (db: AgentsRunDatabaseClient) => (params: MessageIn
149
149
  metadata: MessageMetadata | null;
150
150
  content: MessageContent;
151
151
  role: string;
152
+ conversationId: string;
152
153
  fromSubAgentId: string | null;
153
154
  toSubAgentId: string | null;
154
155
  fromExternalAgentId: string | null;
155
156
  toExternalAgentId: string | null;
156
- taskId: string | null;
157
- a2aTaskId: string | null;
158
- conversationId: string;
159
157
  fromTeamAgentId: string | null;
160
158
  toTeamAgentId: string | null;
161
159
  visibility: string;
162
160
  messageType: string;
161
+ taskId: string | null;
163
162
  parentMessageId: string | null;
163
+ a2aTaskId: string | null;
164
164
  a2aSessionId: string | null;
165
165
  }>;
166
166
  declare const updateMessage: (db: AgentsRunDatabaseClient) => (params: {
@@ -202,18 +202,18 @@ declare const deleteMessage: (db: AgentsRunDatabaseClient) => (params: {
202
202
  metadata: MessageMetadata | null;
203
203
  content: MessageContent;
204
204
  role: string;
205
+ conversationId: string;
205
206
  fromSubAgentId: string | null;
206
207
  toSubAgentId: string | null;
207
208
  fromExternalAgentId: string | null;
208
209
  toExternalAgentId: string | null;
209
- taskId: string | null;
210
- a2aTaskId: string | null;
211
- conversationId: string;
212
210
  fromTeamAgentId: string | null;
213
211
  toTeamAgentId: string | null;
214
212
  visibility: string;
215
213
  messageType: string;
214
+ taskId: string | null;
216
215
  parentMessageId: string | null;
216
+ a2aTaskId: string | null;
217
217
  a2aSessionId: string | null;
218
218
  }>;
219
219
  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: "commit" | "tag" | "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
  }>;
@@ -814,13 +814,13 @@ declare const triggers: drizzle_orm_pg_core217.PgTableWithColumns<{
814
814
  algorithm: "sha256" | "sha512" | "sha384" | "sha1" | "md5";
815
815
  encoding: "hex" | "base64";
816
816
  signature: {
817
- source: "query" | "body" | "header";
817
+ source: "query" | "header" | "body";
818
818
  key: string;
819
819
  prefix?: string | undefined;
820
820
  regex?: string | undefined;
821
821
  };
822
822
  signedComponents: {
823
- source: "literal" | "body" | "header";
823
+ source: "literal" | "header" | "body";
824
824
  required: boolean;
825
825
  key?: string | undefined;
826
826
  value?: string | undefined;
@@ -851,13 +851,13 @@ declare const triggers: drizzle_orm_pg_core217.PgTableWithColumns<{
851
851
  algorithm: "sha256" | "sha512" | "sha384" | "sha1" | "md5";
852
852
  encoding: "hex" | "base64";
853
853
  signature: {
854
- source: "query" | "body" | "header";
854
+ source: "query" | "header" | "body";
855
855
  key: string;
856
856
  prefix?: string | undefined;
857
857
  regex?: string | undefined;
858
858
  };
859
859
  signedComponents: {
860
- source: "literal" | "body" | "header";
860
+ source: "literal" | "header" | "body";
861
861
  required: boolean;
862
862
  key?: string | undefined;
863
863
  value?: string | undefined;
@@ -4378,7 +4378,7 @@ declare const workAppGitHubInstallations: drizzle_orm_pg_core573.PgTableWithColu
4378
4378
  tableName: "work_app_github_installations";
4379
4379
  dataType: "string";
4380
4380
  columnType: "PgVarchar";
4381
- data: "User" | "Organization";
4381
+ data: "Organization" | "User";
4382
4382
  driverParam: string;
4383
4383
  notNull: true;
4384
4384
  hasDefault: false;
@@ -4391,7 +4391,7 @@ declare const workAppGitHubInstallations: drizzle_orm_pg_core573.PgTableWithColu
4391
4391
  generated: undefined;
4392
4392
  }, {}, {
4393
4393
  length: 20;
4394
- $type: "User" | "Organization";
4394
+ $type: "Organization" | "User";
4395
4395
  }>;
4396
4396
  status: drizzle_orm_pg_core573.PgColumn<{
4397
4397
  name: "status";
@@ -1,10 +1,10 @@
1
1
  import { z } from "@hono/zod-openapi";
2
- import * as drizzle_zod0 from "drizzle-zod";
2
+ import * as drizzle_zod15 from "drizzle-zod";
3
3
  import { AnySQLiteTable } from "drizzle-orm/sqlite-core";
4
4
 
5
5
  //#region src/validation/drizzle-schema-helpers.d.ts
6
- declare function createSelectSchemaWithModifiers<T extends AnySQLiteTable>(table: T, overrides?: Partial<Record<keyof T['_']['columns'], (schema: z.ZodTypeAny) => z.ZodTypeAny>>): drizzle_zod0.BuildSchema<"select", T["_"]["columns"], drizzle_zod0.BuildRefine<T["_"]["columns"], undefined>, undefined>;
7
- declare function createInsertSchemaWithModifiers<T extends AnySQLiteTable>(table: T, overrides?: Partial<Record<keyof T['_']['columns'], (schema: z.ZodTypeAny) => z.ZodTypeAny>>): drizzle_zod0.BuildSchema<"insert", T["_"]["columns"], drizzle_zod0.BuildRefine<Pick<T["_"]["columns"], keyof T["$inferInsert"]>, undefined>, undefined>;
6
+ declare function createSelectSchemaWithModifiers<T extends AnySQLiteTable>(table: T, overrides?: Partial<Record<keyof T['_']['columns'], (schema: z.ZodTypeAny) => z.ZodTypeAny>>): drizzle_zod15.BuildSchema<"select", T["_"]["columns"], drizzle_zod15.BuildRefine<T["_"]["columns"], undefined>, undefined>;
7
+ declare function createInsertSchemaWithModifiers<T extends AnySQLiteTable>(table: T, overrides?: Partial<Record<keyof T['_']['columns'], (schema: z.ZodTypeAny) => z.ZodTypeAny>>): drizzle_zod15.BuildSchema<"insert", T["_"]["columns"], drizzle_zod15.BuildRefine<Pick<T["_"]["columns"], keyof T["$inferInsert"]>, undefined>, undefined>;
8
8
  declare const createSelectSchema: typeof createSelectSchemaWithModifiers;
9
9
  declare const createInsertSchema: typeof createInsertSchemaWithModifiers;
10
10
  /**
@@ -30,5 +30,9 @@ declare const ArtifactComponentExtendSchema: {
30
30
  description: z.ZodOptional<z.ZodString>;
31
31
  }, z.core.$loose>>;
32
32
  };
33
+ type WithTimestamps<T> = T & {
34
+ createdAt?: string;
35
+ updatedAt?: string;
36
+ };
33
37
  //#endregion
34
- export { ArtifactComponentExtendSchema, DataComponentExtendSchema, DescriptionSchema, NameSchema, transformToJson };
38
+ export { ArtifactComponentExtendSchema, DataComponentExtendSchema, DescriptionSchema, NameSchema, WithTimestamps, transformToJson };