@inkeep/agents-core 0.63.3 → 0.64.1

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.
Files changed (93) hide show
  1. package/dist/api-client/eval-api-client.d.ts +2 -12
  2. package/dist/api-client/eval-api-client.js +0 -15
  3. package/dist/api-client/index.d.ts +2 -2
  4. package/dist/auth/auth.js +28 -9
  5. package/dist/auth/entitlement-constants.d.ts +11 -0
  6. package/dist/auth/entitlement-constants.js +10 -0
  7. package/dist/auth/entitlement-lock.d.ts +6 -0
  8. package/dist/auth/entitlement-lock.js +13 -0
  9. package/dist/auth/entitlements.d.ts +11 -0
  10. package/dist/auth/entitlements.js +55 -0
  11. package/dist/auth/init.js +2 -4
  12. package/dist/auth/permissions.d.ts +9 -9
  13. package/dist/client-exports.d.ts +6 -4
  14. package/dist/client-exports.js +4 -2
  15. package/dist/constants/models.d.ts +2 -1
  16. package/dist/constants/models.js +6 -1
  17. package/dist/constants/otel-attributes.d.ts +2 -0
  18. package/dist/constants/otel-attributes.js +2 -0
  19. package/dist/data-access/index.d.ts +5 -4
  20. package/dist/data-access/index.js +4 -3
  21. package/dist/data-access/manage/agents.d.ts +83 -41
  22. package/dist/data-access/manage/artifactComponents.d.ts +8 -8
  23. package/dist/data-access/manage/contextConfigs.d.ts +8 -8
  24. package/dist/data-access/manage/dataComponents.d.ts +4 -4
  25. package/dist/data-access/manage/evalConfig.d.ts +49 -3
  26. package/dist/data-access/manage/evalConfig.js +61 -3
  27. package/dist/data-access/manage/functionTools.d.ts +10 -10
  28. package/dist/data-access/manage/projectLifecycle.d.ts +1 -1
  29. package/dist/data-access/manage/skills.d.ts +12 -12
  30. package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +24 -18
  31. package/dist/data-access/manage/subAgentRelations.d.ts +32 -26
  32. package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +30 -18
  33. package/dist/data-access/manage/subAgents.d.ts +51 -15
  34. package/dist/data-access/manage/tools.d.ts +21 -21
  35. package/dist/data-access/manage/tools.js +41 -4
  36. package/dist/data-access/runtime/apiKeys.d.ts +12 -12
  37. package/dist/data-access/runtime/apps.d.ts +40 -49
  38. package/dist/data-access/runtime/cascade-delete.d.ts +1 -1
  39. package/dist/data-access/runtime/conversations.d.ts +25 -25
  40. package/dist/data-access/runtime/entitlements.d.ts +13 -0
  41. package/dist/data-access/runtime/entitlements.js +33 -0
  42. package/dist/data-access/runtime/ledgerArtifacts.d.ts +1 -1
  43. package/dist/data-access/runtime/messages.d.ts +13 -13
  44. package/dist/data-access/runtime/scheduledTriggerInvocations.d.ts +47 -2
  45. package/dist/data-access/runtime/scheduledTriggerInvocations.js +34 -1
  46. package/dist/data-access/runtime/tasks.d.ts +7 -7
  47. package/dist/data-access/runtime/workflowExecutions.d.ts +1 -1
  48. package/dist/data-reconciliation/types.d.ts +1 -1
  49. package/dist/db/clean.d.ts +1 -1
  50. package/dist/db/manage/manage-schema.d.ts +674 -596
  51. package/dist/db/manage/manage-schema.js +154 -134
  52. package/dist/db/runtime/runtime-schema.d.ts +499 -392
  53. package/dist/db/runtime/runtime-schema.js +20 -3
  54. package/dist/dolt/backfill-skill-files.d.ts +41 -0
  55. package/dist/dolt/backfill-skill-files.js +209 -0
  56. package/dist/dolt/run-sql-file-on-all-branches.d.ts +29 -0
  57. package/dist/dolt/run-sql-file-on-all-branches.js +177 -0
  58. package/dist/index.d.ts +20 -16
  59. package/dist/index.js +12 -8
  60. package/dist/middleware/create-protected-route.d.ts +3 -0
  61. package/dist/middleware/create-protected-route.js +7 -2
  62. package/dist/middleware/entitlement-meta.d.ts +9 -0
  63. package/dist/middleware/entitlement-meta.js +11 -0
  64. package/dist/middleware/index.d.ts +2 -1
  65. package/dist/middleware/index.js +2 -1
  66. package/dist/types/entities.d.ts +8 -3
  67. package/dist/types/index.d.ts +3 -3
  68. package/dist/types/utility.d.ts +5 -6
  69. package/dist/utils/error.d.ts +54 -51
  70. package/dist/utils/error.js +3 -0
  71. package/dist/utils/index.d.ts +3 -3
  72. package/dist/utils/index.js +2 -2
  73. package/dist/utils/mcp-client.d.ts +1 -1
  74. package/dist/utils/mcp-client.js +1 -1
  75. package/dist/utils/model-factory.js +24 -9
  76. package/dist/utils/usage-cost-middleware.d.ts +2 -1
  77. package/dist/utils/usage-cost-middleware.js +22 -5
  78. package/dist/validation/index.d.ts +2 -2
  79. package/dist/validation/index.js +2 -2
  80. package/dist/validation/schemas/skills.d.ts +45 -45
  81. package/dist/validation/schemas.d.ts +3504 -2569
  82. package/dist/validation/schemas.js +22 -24
  83. package/drizzle/manage/0016_complex_klaw.sql +2 -0
  84. package/drizzle/manage/0017_brief_doctor_strange.sql +29 -0
  85. package/drizzle/manage/meta/0016_snapshot.json +3530 -0
  86. package/drizzle/manage/meta/0017_snapshot.json +3748 -0
  87. package/drizzle/manage/meta/_journal.json +14 -0
  88. package/drizzle/runtime/0029_burly_satana.sql +13 -0
  89. package/drizzle/runtime/0030_set-allow-anonymous-for-existing-apps.sql +56 -0
  90. package/drizzle/runtime/meta/0029_snapshot.json +4756 -0
  91. package/drizzle/runtime/meta/_journal.json +14 -0
  92. package/package.json +3 -1
  93. /package/drizzle/runtime/meta/{0023_snapshot.json → 0025_snapshot.json} +0 -0
@@ -20,20 +20,20 @@ declare const getToolById: (db: AgentsManageDatabaseClient) => (params: {
20
20
  scopes: ProjectScopeConfig;
21
21
  toolId: string;
22
22
  }) => Promise<{
23
+ tenantId: string;
24
+ projectId: string;
23
25
  id: string;
24
26
  name: string;
25
27
  description: string | null;
26
28
  createdAt: string;
27
29
  updatedAt: string;
28
- projectId: string;
29
- tenantId: string;
30
+ headers: Record<string, string> | null;
30
31
  config: {
31
32
  type: "mcp";
32
33
  mcp: ToolMcpConfig;
33
34
  };
34
35
  credentialReferenceId: string | null;
35
36
  credentialScope: string;
36
- headers: Record<string, string> | null;
37
37
  imageUrl: string | null;
38
38
  capabilities: ToolServerCapabilities | null;
39
39
  lastError: string | null;
@@ -78,20 +78,20 @@ declare const listTools: (db: AgentsManageDatabaseClient) => (params: {
78
78
  };
79
79
  }>;
80
80
  declare const createTool: (db: AgentsManageDatabaseClient) => (params: ToolInsert) => Promise<{
81
+ tenantId: string;
82
+ projectId: string;
81
83
  id: string;
82
84
  name: string;
83
85
  description: string | null;
84
86
  createdAt: string;
85
87
  updatedAt: string;
86
- projectId: string;
87
- tenantId: string;
88
+ headers: Record<string, string> | null;
88
89
  config: {
89
90
  type: "mcp";
90
91
  mcp: ToolMcpConfig;
91
92
  };
92
93
  credentialReferenceId: string | null;
93
94
  credentialScope: string;
94
- headers: Record<string, string> | null;
95
95
  imageUrl: string | null;
96
96
  capabilities: ToolServerCapabilities | null;
97
97
  lastError: string | null;
@@ -135,38 +135,38 @@ declare const addToolToAgent: (db: AgentsManageDatabaseClient) => (params: {
135
135
  needsApproval?: boolean;
136
136
  }> | null;
137
137
  }) => Promise<{
138
+ tenantId: string;
139
+ projectId: string;
138
140
  id: string;
139
141
  createdAt: string;
140
142
  updatedAt: string;
141
- projectId: string;
142
- tenantId: string;
143
143
  agentId: string;
144
- subAgentId: string;
145
144
  toolId: string;
146
145
  headers: Record<string, string> | null;
147
- selectedTools: string[] | null;
148
146
  toolPolicies: Record<string, {
149
147
  needsApproval?: boolean;
150
148
  }> | null;
149
+ subAgentId: string;
150
+ selectedTools: string[] | null;
151
151
  }>;
152
152
  declare const removeToolFromAgent: (db: AgentsManageDatabaseClient) => (params: {
153
153
  scopes: AgentScopeConfig;
154
154
  subAgentId: string;
155
155
  toolId: string;
156
156
  }) => Promise<{
157
+ tenantId: string;
158
+ projectId: string;
157
159
  id: string;
158
160
  createdAt: string;
159
161
  updatedAt: string;
160
- projectId: string;
161
- tenantId: string;
162
162
  agentId: string;
163
- subAgentId: string;
164
163
  toolId: string;
165
164
  headers: Record<string, string> | null;
166
- selectedTools: string[] | null;
167
165
  toolPolicies: Record<string, {
168
166
  needsApproval?: boolean;
169
167
  }> | null;
168
+ subAgentId: string;
169
+ selectedTools: string[] | null;
170
170
  }>;
171
171
  /**
172
172
  * Upsert agent-tool relation (create if it doesn't exist, update if it does)
@@ -182,19 +182,19 @@ declare const upsertSubAgentToolRelation: (db: AgentsManageDatabaseClient) => (p
182
182
  }> | null;
183
183
  relationId?: string;
184
184
  }) => Promise<{
185
+ tenantId: string;
186
+ projectId: string;
185
187
  id: string;
186
188
  createdAt: string;
187
189
  updatedAt: string;
188
- projectId: string;
189
- tenantId: string;
190
190
  agentId: string;
191
- subAgentId: string;
192
191
  toolId: string;
193
192
  headers: Record<string, string> | null;
194
- selectedTools: string[] | null;
195
193
  toolPolicies: Record<string, {
196
194
  needsApproval?: boolean;
197
195
  }> | null;
196
+ subAgentId: string;
197
+ selectedTools: string[] | null;
198
198
  }>;
199
199
  /**
200
200
  * Upsert a tool (create if it doesn't exist, update if it does)
@@ -202,20 +202,20 @@ declare const upsertSubAgentToolRelation: (db: AgentsManageDatabaseClient) => (p
202
202
  declare const upsertTool: (db: AgentsManageDatabaseClient) => (params: {
203
203
  data: ToolInsert;
204
204
  }) => Promise<{
205
+ tenantId: string;
206
+ projectId: string;
205
207
  id: string;
206
208
  name: string;
207
209
  description: string | null;
208
210
  createdAt: string;
209
211
  updatedAt: string;
210
- projectId: string;
211
- tenantId: string;
212
+ headers: Record<string, string> | null;
212
213
  config: {
213
214
  type: "mcp";
214
215
  mcp: ToolMcpConfig;
215
216
  };
216
217
  credentialReferenceId: string | null;
217
218
  credentialScope: string;
218
- headers: Record<string, string> | null;
219
219
  imageUrl: string | null;
220
220
  capabilities: ToolServerCapabilities | null;
221
221
  lastError: string | null;
@@ -23,20 +23,45 @@ import "../../utils/index.js";
23
23
  import { isGithubWorkAppTool } from "../runtime/github-work-app-installations.js";
24
24
  import { getCredentialReference, getUserScopedCredentialReference } from "./credentialReferences.js";
25
25
  import { and, count, desc, eq } from "drizzle-orm";
26
+ import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js";
27
+ import { StreamableHTTPError } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
26
28
  import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
27
29
 
28
30
  //#region src/data-access/manage/tools.ts
29
31
  /**
30
- * Check if an error is a timeout/connection error.
32
+ * Check if an error is a timeout/connection error (transient, not auth-related).
31
33
  * Uses MCP SDK ErrorCode for proper type safety.
32
34
  */
33
35
  function isTimeoutOrConnectionError(error) {
34
- if (error instanceof McpError) return error.code === ErrorCode.RequestTimeout || error.code === ErrorCode.ConnectionClosed;
36
+ if (error instanceof McpError) return error.code === ErrorCode.RequestTimeout || error.code === ErrorCode.ConnectionClosed || error.code === ErrorCode.InternalError;
37
+ if (error instanceof StreamableHTTPError) return error.code !== void 0 && error.code >= 500;
35
38
  if (error instanceof Error) {
36
39
  const message = error.message.toLowerCase();
37
40
  const cause = error.cause;
38
- if (message.includes("timed out") || message.includes("timeout")) return true;
39
- if (cause?.code === "ETIMEDOUT" || cause?.code === "ECONNABORTED" || cause?.code === "ECONNRESET") return true;
41
+ if (message.includes("timed out") || message.includes("timeout") || message.includes("fetch failed")) return true;
42
+ if (cause?.code && [
43
+ "ETIMEDOUT",
44
+ "ECONNABORTED",
45
+ "ECONNRESET",
46
+ "ECONNREFUSED",
47
+ "ENOTFOUND",
48
+ "EHOSTUNREACH",
49
+ "ENETUNREACH",
50
+ "EPIPE"
51
+ ].includes(cause.code)) return true;
52
+ }
53
+ return false;
54
+ }
55
+ /**
56
+ * Check if an error indicates the credential is invalid/expired/revoked.
57
+ * These errors mean the user genuinely needs to re-authenticate.
58
+ */
59
+ function isAuthenticationError(error) {
60
+ if (error instanceof UnauthorizedError) return true;
61
+ if (error instanceof StreamableHTTPError) return error.code === 401 || error.code === 403;
62
+ if (error instanceof Error) {
63
+ const message = error.message.toLowerCase();
64
+ if (message.includes("unauthorized") || message.includes("forbidden") || message.includes("invalid_token") || message.includes("token expired") || message.includes("invalid_grant")) return true;
40
65
  }
41
66
  return false;
42
67
  }
@@ -243,6 +268,18 @@ const dbResultToMcpTool = async (dbResult, dbClient, credentialStoreRegistry, re
243
268
  if (isTimeoutOrConnectionError(error)) {
244
269
  status = "unavailable";
245
270
  lastErrorComputed = `Connection failed - the MCP server may be slow or temporarily unreachable.${error instanceof McpError ? ` (MCP error ${error.code})` : ""} ${errorMessage}`;
271
+ } else if (isAuthenticationError(error)) {
272
+ status = "needs_auth";
273
+ lastErrorComputed = `Authentication required - OAuth login needed. ${errorMessage}`;
274
+ } else if (credentialReference) {
275
+ logger.warn({
276
+ toolId: dbResult.id,
277
+ credentialId: credentialReference.id,
278
+ errorCode: error instanceof McpError ? error.code : void 0,
279
+ errorMessage
280
+ }, "MCP server discovery failed with existing credential — treating as transient");
281
+ status = "unavailable";
282
+ lastErrorComputed = `Server temporarily unavailable. ${errorMessage}`;
246
283
  } else {
247
284
  const toolNeedsAuth = await detectAuthenticationRequired({
248
285
  serverUrl: mcpServerUrl,
@@ -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;
11
13
  id: string;
12
14
  name: string | null;
13
15
  createdAt: string;
14
16
  updatedAt: string;
15
- projectId: string;
16
- tenantId: string;
17
- expiresAt: string | null;
18
17
  agentId: string;
18
+ expiresAt: string | null;
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;
25
27
  id: string;
26
28
  name: string | null;
27
29
  createdAt: string;
28
30
  updatedAt: string;
29
- projectId: string;
30
- tenantId: string;
31
- expiresAt: string | null;
32
31
  agentId: string;
32
+ expiresAt: string | null;
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;
42
44
  id: string;
43
45
  name: string | null;
44
46
  createdAt: string;
45
47
  updatedAt: string;
46
- projectId: string;
47
- tenantId: string;
48
- expiresAt: string | null;
49
48
  agentId: string;
49
+ expiresAt: string | null;
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;
69
71
  id: string;
70
72
  name: string | null;
71
73
  createdAt: string;
72
74
  updatedAt: string;
73
- projectId: string;
74
- tenantId: string;
75
- expiresAt: string | null;
76
75
  agentId: string;
76
+ expiresAt: string | null;
77
77
  publicId: string;
78
78
  keyHash: string;
79
79
  keyPrefix: string;
@@ -5,39 +5,36 @@ 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;
8
11
  id: string;
9
12
  name: string;
10
13
  description: string | null;
14
+ enabled: boolean;
15
+ prompt: string | null;
11
16
  createdAt: string;
12
17
  updatedAt: string;
13
- projectId: string | null;
14
- tenantId: string | null;
15
- type: AppType;
16
- lastUsedAt: string | null;
17
- defaultProjectId: string | null;
18
- defaultAgentId: string | null;
19
- prompt: string | null;
20
- enabled: boolean;
21
18
  config: {
22
19
  type: "web_client";
23
20
  webClient: {
24
21
  allowedDomains: string[];
25
- auth?: {
26
- publicKeys: {
27
- kid: string;
28
- publicKey: string;
29
- algorithm: "RS256" | "RS384" | "RS512" | "ES256" | "ES384" | "ES512" | "EdDSA";
30
- addedAt: string;
31
- }[];
32
- audience?: string | undefined;
33
- validateScopeClaims?: boolean | undefined;
34
- allowAnonymous?: boolean | undefined;
35
- } | undefined;
22
+ publicKeys: {
23
+ kid: string;
24
+ publicKey: string;
25
+ algorithm: "RS256" | "RS384" | "RS512" | "ES256" | "ES384" | "ES512" | "EdDSA";
26
+ addedAt: string;
27
+ }[];
28
+ allowAnonymous: boolean;
29
+ audience?: string | undefined;
36
30
  };
37
31
  } | {
38
32
  type: "api";
39
33
  api: Record<string, never>;
40
34
  };
35
+ lastUsedAt: string | null;
36
+ defaultProjectId: string | null;
37
+ defaultAgentId: string | null;
41
38
  } | undefined>;
42
39
  declare const updateAppLastUsed: (db: AgentsRunDatabaseClient) => (id: string) => Promise<void>;
43
40
  declare const getAppByIdForTenant: (db: AgentsRunDatabaseClient) => (params: {
@@ -64,39 +61,36 @@ declare const listAppsPaginated: (db: AgentsRunDatabaseClient) => (params: {
64
61
  };
65
62
  }>;
66
63
  declare const createApp: (db: AgentsRunDatabaseClient) => (params: AppInsert) => Promise<{
64
+ type: AppType;
65
+ tenantId: string | null;
66
+ projectId: string | null;
67
67
  id: string;
68
68
  name: string;
69
69
  description: string | null;
70
+ enabled: boolean;
71
+ prompt: string | null;
70
72
  createdAt: string;
71
73
  updatedAt: string;
72
- projectId: string | null;
73
- tenantId: string | null;
74
- type: AppType;
75
- lastUsedAt: string | null;
76
- defaultProjectId: string | null;
77
- defaultAgentId: string | null;
78
- prompt: string | null;
79
- enabled: boolean;
80
74
  config: {
81
75
  type: "web_client";
82
76
  webClient: {
83
77
  allowedDomains: string[];
84
- auth?: {
85
- publicKeys: {
86
- kid: string;
87
- publicKey: string;
88
- algorithm: "RS256" | "RS384" | "RS512" | "ES256" | "ES384" | "ES512" | "EdDSA";
89
- addedAt: string;
90
- }[];
91
- audience?: string | undefined;
92
- validateScopeClaims?: boolean | undefined;
93
- allowAnonymous?: boolean | undefined;
94
- } | undefined;
78
+ publicKeys: {
79
+ kid: string;
80
+ publicKey: string;
81
+ algorithm: "RS256" | "RS384" | "RS512" | "ES256" | "ES384" | "ES512" | "EdDSA";
82
+ addedAt: string;
83
+ }[];
84
+ allowAnonymous: boolean;
85
+ audience?: string | undefined;
95
86
  };
96
87
  } | {
97
88
  type: "api";
98
89
  api: Record<string, never>;
99
90
  };
91
+ lastUsedAt: string | null;
92
+ defaultProjectId: string | null;
93
+ defaultAgentId: string | null;
100
94
  }>;
101
95
  declare const updateAppForTenant: (db: AgentsRunDatabaseClient) => (params: {
102
96
  scopes: TenantScopeConfig;
@@ -151,17 +145,14 @@ declare const updateApp: (db: AgentsRunDatabaseClient) => (params: {
151
145
  type: "web_client";
152
146
  webClient: {
153
147
  allowedDomains: string[];
154
- auth?: {
155
- publicKeys: {
156
- kid: string;
157
- publicKey: string;
158
- algorithm: "RS256" | "RS384" | "RS512" | "ES256" | "ES384" | "ES512" | "EdDSA";
159
- addedAt: string;
160
- }[];
161
- audience?: string | undefined;
162
- validateScopeClaims?: boolean | undefined;
163
- allowAnonymous?: boolean | undefined;
164
- } | undefined;
148
+ publicKeys: {
149
+ kid: string;
150
+ publicKey: string;
151
+ algorithm: "RS256" | "RS384" | "RS512" | "ES256" | "ES384" | "ES512" | "EdDSA";
152
+ addedAt: string;
153
+ }[];
154
+ allowAnonymous: boolean;
155
+ audience?: string | undefined;
165
156
  };
166
157
  } | {
167
158
  type: "api";
@@ -1,6 +1,6 @@
1
1
  import { AgentScopeConfig, ProjectScopeConfig } from "../../db/manage/scope-definitions.js";
2
- import "../../types/index.js";
3
2
  import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
3
+ import "../../types/index.js";
4
4
 
5
5
  //#region src/data-access/runtime/cascade-delete.d.ts
6
6
  /**
@@ -1,8 +1,8 @@
1
1
  import { ResolvedRef } from "../../validation/dolt-schemas.js";
2
2
  import { ProjectScopeConfig } from "../../db/manage/scope-definitions.js";
3
3
  import { ConversationHistoryConfig, ConversationMetadata, PaginationConfig } from "../../types/utility.js";
4
- import "../../types/index.js";
5
4
  import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
5
+ import "../../types/index.js";
6
6
  import { ConversationInsert, ConversationSelect, ConversationUpdate, MessageSelect } from "../../types/entities.js";
7
7
 
8
8
  //#region src/data-access/runtime/conversations.d.ts
@@ -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;
18
21
  id: string;
19
- metadata: ConversationMetadata | null;
22
+ title: string | null;
20
23
  createdAt: string;
21
24
  updatedAt: string;
22
- projectId: string;
23
- tenantId: string;
24
- title: string | null;
25
+ metadata: ConversationMetadata | null;
26
+ agentId: string | null;
25
27
  ref: {
26
28
  type: "commit" | "tag" | "branch";
27
29
  name: string;
28
30
  hash: string;
29
31
  } | null;
30
- userId: string | null;
31
- agentId: 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;
87
90
  id: string;
88
- metadata: ConversationMetadata | null;
91
+ title: string | null;
89
92
  createdAt: string;
90
93
  updatedAt: string;
91
- projectId: string;
92
- tenantId: string;
93
- title: string | null;
94
+ metadata: ConversationMetadata | null;
95
+ agentId: string | null;
94
96
  ref: {
95
97
  type: "commit" | "tag" | "branch";
96
98
  name: string;
97
99
  hash: string;
98
100
  } | null;
99
- userId: string | null;
100
- agentId: 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;
123
126
  id: string;
124
- metadata: ConversationMetadata | null;
127
+ title: string | null;
125
128
  createdAt: string;
126
129
  updatedAt: string;
127
- projectId: string;
128
- tenantId: string;
129
- title: string | null;
130
+ metadata: ConversationMetadata | null;
131
+ agentId: string | null;
130
132
  ref: {
131
133
  type: "commit" | "tag" | "branch";
132
134
  name: string;
133
135
  hash: string;
134
136
  } | null;
135
- userId: string | null;
136
- agentId: 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;
155
158
  id: string;
156
- metadata: ConversationMetadata | null;
159
+ title: string | null;
157
160
  createdAt: string;
158
161
  updatedAt: string;
159
- projectId: string;
160
- tenantId: string;
161
- title: string | null;
162
+ metadata: ConversationMetadata | null;
163
+ agentId: string | null;
162
164
  ref: {
163
165
  type: "commit" | "tag" | "branch";
164
166
  name: string;
165
167
  hash: string;
166
168
  } | null;
167
- userId: string | null;
168
- agentId: string | null;
169
169
  activeSubAgentId: string;
170
170
  lastContextResolution: string | null;
171
171
  } | undefined>;
@@ -0,0 +1,13 @@
1
+ import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
2
+
3
+ //#region src/data-access/runtime/entitlements.d.ts
4
+ declare const listOrgEntitlements: (db: AgentsRunDatabaseClient) => (orgId: string) => Promise<Array<{
5
+ resourceType: string;
6
+ maxValue: number;
7
+ }>>;
8
+ declare function dalResolveEntitlement(db: AgentsRunDatabaseClient, orgId: string, resourceType: string): Promise<number | null>;
9
+ declare function dalGetServiceAccountUserId(db: AgentsRunDatabaseClient, orgId: string): Promise<string | null>;
10
+ declare function dalCountMembersByRoleBucket(db: AgentsRunDatabaseClient, orgId: string, isAdminBucket: boolean, serviceAccountUserId: string | null): Promise<number>;
11
+ declare function dalSumSeatEntitlements(db: AgentsRunDatabaseClient, orgId: string): Promise<number | null>;
12
+ //#endregion
13
+ export { dalCountMembersByRoleBucket, dalGetServiceAccountUserId, dalResolveEntitlement, dalSumSeatEntitlements, listOrgEntitlements };
@@ -0,0 +1,33 @@
1
+ import { member, organization } from "../../auth/auth-schema.js";
2
+ import { orgEntitlement } from "../../db/runtime/runtime-schema.js";
3
+ import { and, eq, like, or, sql } from "drizzle-orm";
4
+
5
+ //#region src/data-access/runtime/entitlements.ts
6
+ const listOrgEntitlements = (db) => async (orgId) => {
7
+ return await db.select({
8
+ resourceType: orgEntitlement.resourceType,
9
+ maxValue: orgEntitlement.maxValue
10
+ }).from(orgEntitlement).where(eq(orgEntitlement.organizationId, orgId));
11
+ };
12
+ async function dalResolveEntitlement(db, orgId, resourceType) {
13
+ const rows = await db.select({ maxValue: orgEntitlement.maxValue }).from(orgEntitlement).where(and(eq(orgEntitlement.organizationId, orgId), eq(orgEntitlement.resourceType, resourceType)));
14
+ if (rows.length === 0) return null;
15
+ return rows[0].maxValue;
16
+ }
17
+ async function dalGetServiceAccountUserId(db, orgId) {
18
+ return (await db.select({ serviceAccountUserId: organization.serviceAccountUserId }).from(organization).where(eq(organization.id, orgId)))[0]?.serviceAccountUserId ?? null;
19
+ }
20
+ async function dalCountMembersByRoleBucket(db, orgId, isAdminBucket, serviceAccountUserId) {
21
+ const memberCondition = isAdminBucket ? or(eq(member.role, "owner"), eq(member.role, "admin")) : eq(member.role, "member");
22
+ const memberWhere = serviceAccountUserId ? and(eq(member.organizationId, orgId), memberCondition, sql`${member.userId} != ${serviceAccountUserId}`) : and(eq(member.organizationId, orgId), memberCondition);
23
+ const [result] = await db.select({ count: sql`count(*)::int` }).from(member).where(memberWhere);
24
+ return result?.count ?? 0;
25
+ }
26
+ async function dalSumSeatEntitlements(db, orgId) {
27
+ const rows = await db.select({ maxValue: orgEntitlement.maxValue }).from(orgEntitlement).where(and(eq(orgEntitlement.organizationId, orgId), like(orgEntitlement.resourceType, "seat:%")));
28
+ if (rows.length === 0) return null;
29
+ return rows.reduce((sum, r) => sum + r.maxValue, 0);
30
+ }
31
+
32
+ //#endregion
33
+ export { dalCountMembersByRoleBucket, dalGetServiceAccountUserId, dalResolveEntitlement, dalSumSeatEntitlements, listOrgEntitlements };
@@ -1,7 +1,7 @@
1
1
  import { Artifact, Part } from "../../types/a2a.js";
2
2
  import { ProjectScopeConfig } from "../../db/manage/scope-definitions.js";
3
- import "../../types/index.js";
4
3
  import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
4
+ import "../../types/index.js";
5
5
  import { LedgerArtifactSelect } from "../../types/entities.js";
6
6
 
7
7
  //#region src/data-access/runtime/ledgerArtifacts.d.ts
@@ -1,7 +1,7 @@
1
1
  import { ProjectScopeConfig } from "../../db/manage/scope-definitions.js";
2
2
  import { MessageContent, MessageMetadata, MessageVisibility, PaginationConfig } from "../../types/utility.js";
3
- import "../../types/index.js";
4
3
  import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
4
+ import "../../types/index.js";
5
5
  import "../../index.js";
6
6
  import { MessageInsert, MessageUpdate } from "../../types/entities.js";
7
7
 
@@ -10,13 +10,13 @@ declare const getMessageById: (db: AgentsRunDatabaseClient) => (params: {
10
10
  scopes: ProjectScopeConfig;
11
11
  messageId: string;
12
12
  }) => Promise<{
13
+ tenantId: string;
14
+ projectId: string;
13
15
  id: string;
14
- content: MessageContent;
15
- metadata: MessageMetadata | null;
16
16
  createdAt: string;
17
17
  updatedAt: string;
18
- projectId: string;
19
- tenantId: string;
18
+ metadata: MessageMetadata | null;
19
+ content: MessageContent;
20
20
  role: string;
21
21
  conversationId: string;
22
22
  fromSubAgentId: string | null;
@@ -144,13 +144,13 @@ 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;
147
149
  id: string;
148
- content: MessageContent;
149
- metadata: MessageMetadata | null;
150
150
  createdAt: string;
151
151
  updatedAt: string;
152
- projectId: string;
153
- tenantId: string;
152
+ metadata: MessageMetadata | null;
153
+ content: MessageContent;
154
154
  role: string;
155
155
  conversationId: string;
156
156
  fromSubAgentId: string | null;
@@ -197,13 +197,13 @@ declare const deleteMessage: (db: AgentsRunDatabaseClient) => (params: {
197
197
  scopes: ProjectScopeConfig;
198
198
  messageId: string;
199
199
  }) => Promise<{
200
+ tenantId: string;
201
+ projectId: string;
200
202
  id: string;
201
- content: MessageContent;
202
- metadata: MessageMetadata | null;
203
203
  createdAt: string;
204
204
  updatedAt: string;
205
- projectId: string;
206
- tenantId: string;
205
+ metadata: MessageMetadata | null;
206
+ content: MessageContent;
207
207
  role: string;
208
208
  conversationId: string;
209
209
  fromSubAgentId: string | null;