@inkeep/agents-core 0.58.21 → 0.59.0

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 (37) hide show
  1. package/dist/auth/auth-config-utils.d.ts +49 -0
  2. package/dist/auth/auth-config-utils.js +133 -0
  3. package/dist/auth/auth-schema.d.ts +102 -85
  4. package/dist/auth/auth-schema.js +1 -0
  5. package/dist/auth/auth-types.d.ts +170 -0
  6. package/dist/auth/auth-types.js +53 -0
  7. package/dist/auth/auth-validation-schemas.d.ts +186 -152
  8. package/dist/auth/auth.d.ts +43 -1286
  9. package/dist/auth/auth.js +61 -70
  10. package/dist/auth/email-send-status-store.js +15 -3
  11. package/dist/auth/init.js +2 -1
  12. package/dist/auth/password-reset-link-store.js +8 -1
  13. package/dist/auth/permissions.d.ts +13 -13
  14. package/dist/data-access/index.d.ts +4 -3
  15. package/dist/data-access/index.js +3 -3
  16. package/dist/data-access/manage/skills.d.ts +1 -1
  17. package/dist/data-access/runtime/auth.d.ts +9 -9
  18. package/dist/data-access/runtime/auth.js +19 -21
  19. package/dist/data-access/runtime/conversations.d.ts +4 -4
  20. package/dist/data-access/runtime/messages.d.ts +9 -9
  21. package/dist/data-access/runtime/organizations.d.ts +28 -4
  22. package/dist/data-access/runtime/organizations.js +131 -9
  23. package/dist/data-access/runtime/tasks.d.ts +2 -2
  24. package/dist/db/manage/manage-schema.d.ts +357 -357
  25. package/dist/db/runtime/runtime-schema.d.ts +298 -298
  26. package/dist/index.d.ts +4 -3
  27. package/dist/index.js +3 -3
  28. package/dist/middleware/no-auth.d.ts +2 -2
  29. package/dist/utils/error.d.ts +51 -48
  30. package/dist/utils/error.js +3 -0
  31. package/dist/validation/drizzle-schema-helpers.d.ts +3 -3
  32. package/dist/validation/schemas.d.ts +1535 -1535
  33. package/drizzle/runtime/0023_lazy_energizer.sql +1 -0
  34. package/drizzle/runtime/0024_moaning_kingpin.sql +1 -0
  35. package/drizzle/runtime/meta/0024_snapshot.json +4270 -0
  36. package/drizzle/runtime/meta/_journal.json +7 -0
  37. package/package.json +8 -3
@@ -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;
27
28
  ref: {
28
29
  type: "commit" | "tag" | "branch";
29
30
  name: string;
30
31
  hash: string;
31
32
  } | 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;
96
97
  ref: {
97
98
  type: "commit" | "tag" | "branch";
98
99
  name: string;
99
100
  hash: string;
100
101
  } | 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;
132
133
  ref: {
133
134
  type: "commit" | "tag" | "branch";
134
135
  name: string;
135
136
  hash: string;
136
137
  } | 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;
164
165
  ref: {
165
166
  type: "commit" | "tag" | "branch";
166
167
  name: string;
167
168
  hash: string;
168
169
  } | 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;
22
21
  fromSubAgentId: string | null;
23
22
  toSubAgentId: string | null;
24
23
  fromExternalAgentId: string | null;
25
24
  toExternalAgentId: string | null;
25
+ taskId: string | null;
26
+ a2aTaskId: string | null;
27
+ conversationId: string;
26
28
  fromTeamAgentId: string | null;
27
29
  toTeamAgentId: string | null;
28
30
  visibility: string;
29
31
  messageType: string;
30
- taskId: string | null;
31
32
  parentMessageId: string | null;
32
- a2aTaskId: string | null;
33
33
  a2aSessionId: string | null;
34
34
  } | undefined>;
35
35
  declare const listMessages: (db: AgentsRunDatabaseClient) => (params: {
@@ -152,18 +152,18 @@ declare const createMessage: (db: AgentsRunDatabaseClient) => (params: {
152
152
  metadata: MessageMetadata | null;
153
153
  content: MessageContent;
154
154
  role: string;
155
- conversationId: string;
156
155
  fromSubAgentId: string | null;
157
156
  toSubAgentId: string | null;
158
157
  fromExternalAgentId: string | null;
159
158
  toExternalAgentId: string | null;
159
+ taskId: string | null;
160
+ a2aTaskId: string | null;
161
+ conversationId: string;
160
162
  fromTeamAgentId: string | null;
161
163
  toTeamAgentId: string | null;
162
164
  visibility: string;
163
165
  messageType: string;
164
- taskId: string | null;
165
166
  parentMessageId: string | null;
166
- a2aTaskId: string | null;
167
167
  a2aSessionId: string | null;
168
168
  }>;
169
169
  declare const updateMessage: (db: AgentsRunDatabaseClient) => (params: {
@@ -205,18 +205,18 @@ declare const deleteMessage: (db: AgentsRunDatabaseClient) => (params: {
205
205
  metadata: MessageMetadata | null;
206
206
  content: MessageContent;
207
207
  role: string;
208
- conversationId: string;
209
208
  fromSubAgentId: string | null;
210
209
  toSubAgentId: string | null;
211
210
  fromExternalAgentId: string | null;
212
211
  toExternalAgentId: string | null;
212
+ taskId: string | null;
213
+ a2aTaskId: string | null;
214
+ conversationId: string;
213
215
  fromTeamAgentId: string | null;
214
216
  toTeamAgentId: string | null;
215
217
  visibility: string;
216
218
  messageType: string;
217
- taskId: string | null;
218
219
  parentMessageId: string | null;
219
- a2aTaskId: string | null;
220
220
  a2aSessionId: string | null;
221
221
  }>;
222
222
  declare const countMessagesByConversation: (db: AgentsRunDatabaseClient) => (params: {
@@ -1,4 +1,5 @@
1
1
  import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
2
+ import { AllowedAuthMethod, MethodOption, OrgAuthInfo } from "../../auth/auth-types.js";
2
3
  import { UserOrganization } from "../../auth/auth-validation-schemas.js";
3
4
 
4
5
  //#region src/data-access/runtime/organizations.d.ts
@@ -39,6 +40,7 @@ declare const addUserToOrganization: (db: AgentsRunDatabaseClient) => (data: {
39
40
  userId: string;
40
41
  organizationId: string;
41
42
  role: string;
43
+ isServiceAccount?: boolean;
42
44
  }) => Promise<void>;
43
45
  declare const upsertOrganization: (db: AgentsRunDatabaseClient) => (data: {
44
46
  organizationId: string;
@@ -55,19 +57,41 @@ interface UserProviderInfo {
55
57
  }
56
58
  /**
57
59
  * Get authentication providers for a list of users.
58
- * Returns which providers each user has linked (e.g., 'credential', 'google', 'auth0').
60
+ * Returns which providers each user has linked (e.g., 'credential', 'google').
59
61
  */
60
62
  declare const getUserProvidersFromDb: (db: AgentsRunDatabaseClient) => (userIds: string[]) => Promise<UserProviderInfo[]>;
63
+ declare const getAllowedAuthMethods: (db: AgentsRunDatabaseClient) => (organizationId: string) => Promise<AllowedAuthMethod[]>;
61
64
  /**
62
- * Create an invitation directly in db
63
- * Used when shouldAllowJoinFromWorkspace is enabled for a work_app_slack_workspaces
65
+ * Create an invitation directly in db.
66
+ * Accepts an optional explicit authMethod; defaults to email-password.
64
67
  */
65
68
  declare const createInvitationInDb: (db: AgentsRunDatabaseClient) => (data: {
66
69
  organizationId: string;
67
70
  email: string;
71
+ authMethod?: string;
68
72
  }) => Promise<{
69
73
  id: string;
70
74
  authMethod: string;
71
75
  }>;
76
+ interface SSOProviderLookupResult {
77
+ providerId: string;
78
+ issuer: string;
79
+ domain: string;
80
+ organizationId: string | null;
81
+ providerType: 'oidc' | 'saml';
82
+ }
83
+ declare const getSSOProvidersByDomain: (db: AgentsRunDatabaseClient) => (domain: string) => Promise<SSOProviderLookupResult[]>;
84
+ /**
85
+ * Filters org-allowed auth methods by email domain.
86
+ * SSO providers are only included if their domain matches the user's email domain.
87
+ * Non-SSO methods (email-password, google) pass through unfiltered.
88
+ */
89
+ declare const getFilteredAuthMethodsForEmail: (db: AgentsRunDatabaseClient) => (organizationId: string, email: string) => Promise<MethodOption[]>;
90
+ declare function allowedMethodsToMethodOptions(methods: AllowedAuthMethod[], ssoProviders: SSOProviderLookupResult[]): MethodOption[];
91
+ /**
92
+ * Main auth-lookup query for the login flow.
93
+ * Returns org-grouped methods based on SSO domain match and/or user org membership.
94
+ */
95
+ declare const getAuthLookupForEmail: (db: AgentsRunDatabaseClient) => (email: string) => Promise<OrgAuthInfo[]>;
72
96
  //#endregion
73
- export { UserProviderInfo, addUserToOrganization, createInvitationInDb, getPendingInvitationsByEmail, getUserOrganizationsFromDb, getUserProvidersFromDb, upsertOrganization };
97
+ export { type MethodOption, type OrgAuthInfo, SSOProviderLookupResult, UserProviderInfo, addUserToOrganization, allowedMethodsToMethodOptions, createInvitationInDb, getAllowedAuthMethods, getAuthLookupForEmail, getFilteredAuthMethodsForEmail, getPendingInvitationsByEmail, getSSOProvidersByDomain, getUserOrganizationsFromDb, getUserProvidersFromDb, upsertOrganization };
@@ -1,4 +1,5 @@
1
- import { account, invitation, member, organization } from "../../auth/auth-schema.js";
1
+ import { account, invitation, member, organization, ssoProvider, user } from "../../auth/auth-schema.js";
2
+ import { parseAllowedAuthMethods } from "../../auth/auth-types.js";
2
3
  import { and, desc, eq, inArray, or } from "drizzle-orm";
3
4
  import { generateId } from "better-auth";
4
5
 
@@ -51,7 +52,10 @@ const getPendingInvitationsByEmail = (db) => async (email) => {
51
52
  */
52
53
  const addUserToOrganization = (db) => async (data) => {
53
54
  if ((await db.select().from(organization).where(eq(organization.id, data.organizationId)).limit(1)).length === 0) throw new Error(`Organization ${data.organizationId} does not exist`);
54
- if ((await db.select().from(member).where(and(eq(member.userId, data.userId), eq(member.organizationId, data.organizationId))).limit(1)).length > 0) return;
55
+ if ((await db.select().from(member).where(and(eq(member.userId, data.userId), eq(member.organizationId, data.organizationId))).limit(1)).length > 0) {
56
+ if (data.isServiceAccount) await db.update(organization).set({ serviceAccountUserId: data.userId }).where(eq(organization.id, data.organizationId));
57
+ return;
58
+ }
55
59
  await db.insert(member).values({
56
60
  id: `${data.userId}_${data.organizationId}`,
57
61
  userId: data.userId,
@@ -59,6 +63,7 @@ const addUserToOrganization = (db) => async (data) => {
59
63
  role: data.role,
60
64
  createdAt: /* @__PURE__ */ new Date()
61
65
  });
66
+ if (data.isServiceAccount) await db.update(organization).set({ serviceAccountUserId: data.userId }).where(eq(organization.id, data.organizationId));
62
67
  };
63
68
  const upsertOrganization = (db) => async (data) => {
64
69
  if ((await db.select().from(organization).where(or(eq(organization.id, data.organizationId), eq(organization.slug, data.slug))).limit(1)).length > 0) return { created: false };
@@ -74,7 +79,7 @@ const upsertOrganization = (db) => async (data) => {
74
79
  };
75
80
  /**
76
81
  * Get authentication providers for a list of users.
77
- * Returns which providers each user has linked (e.g., 'credential', 'google', 'auth0').
82
+ * Returns which providers each user has linked (e.g., 'credential', 'google').
78
83
  */
79
84
  const getUserProvidersFromDb = (db) => async (userIds) => {
80
85
  if (userIds.length === 0) return [];
@@ -93,17 +98,23 @@ const getUserProvidersFromDb = (db) => async (userIds) => {
93
98
  providers: providerMap.get(userId) || []
94
99
  }));
95
100
  };
101
+ const getAllowedAuthMethods = (db) => async (organizationId) => {
102
+ const org = (await db.select({ allowedAuthMethods: organization.allowedAuthMethods }).from(organization).where(eq(organization.id, organizationId)).limit(1))[0];
103
+ if (!org) return [{ method: "email-password" }];
104
+ return parseAllowedAuthMethods(org.allowedAuthMethods);
105
+ };
96
106
  /**
97
- * Create an invitation directly in db
98
- * Used when shouldAllowJoinFromWorkspace is enabled for a work_app_slack_workspaces
107
+ * Create an invitation directly in db.
108
+ * Accepts an optional explicit authMethod; defaults to email-password.
99
109
  */
100
110
  const createInvitationInDb = (db) => async (data) => {
101
111
  const orgSettings = (await db.select({
102
112
  serviceAccountUserId: organization.serviceAccountUserId,
113
+ allowedAuthMethods: organization.allowedAuthMethods,
103
114
  preferredAuthMethod: organization.preferredAuthMethod
104
115
  }).from(organization).where(eq(organization.id, data.organizationId)).limit(1))[0];
105
116
  if (!orgSettings?.serviceAccountUserId) throw new Error(`Organization ${data.organizationId} does not have a serviceAccountUserId configured`);
106
- if (!orgSettings?.preferredAuthMethod) throw new Error(`Organization ${data.organizationId} does not have a preferredAuthMethod configured`);
117
+ const resolvedMethod = data.authMethod || orgSettings.preferredAuthMethod || "email-password";
107
118
  const inviteId = generateId();
108
119
  const expiresAt = new Date(Date.now() + 3600 * 1e3);
109
120
  await db.insert(invitation).values({
@@ -114,13 +125,124 @@ const createInvitationInDb = (db) => async (data) => {
114
125
  status: "pending",
115
126
  expiresAt,
116
127
  inviterId: orgSettings.serviceAccountUserId,
117
- authMethod: orgSettings.preferredAuthMethod
128
+ authMethod: resolvedMethod
118
129
  });
119
130
  return {
120
131
  id: inviteId,
121
- authMethod: orgSettings.preferredAuthMethod
132
+ authMethod: resolvedMethod
122
133
  };
123
134
  };
135
+ const getSSOProvidersByDomain = (db) => async (domain) => {
136
+ return (await db.select({
137
+ providerId: ssoProvider.providerId,
138
+ issuer: ssoProvider.issuer,
139
+ domain: ssoProvider.domain,
140
+ organizationId: ssoProvider.organizationId,
141
+ oidcConfig: ssoProvider.oidcConfig,
142
+ samlConfig: ssoProvider.samlConfig
143
+ }).from(ssoProvider).where(eq(ssoProvider.domain, domain))).map((provider) => ({
144
+ providerId: provider.providerId,
145
+ issuer: provider.issuer,
146
+ domain: provider.domain,
147
+ organizationId: provider.organizationId,
148
+ providerType: provider.samlConfig ? "saml" : "oidc"
149
+ }));
150
+ };
151
+ /**
152
+ * Filters org-allowed auth methods by email domain.
153
+ * SSO providers are only included if their domain matches the user's email domain.
154
+ * Non-SSO methods (email-password, google) pass through unfiltered.
155
+ */
156
+ const getFilteredAuthMethodsForEmail = (db) => async (organizationId, email) => {
157
+ const emailDomain = email.split("@")[1]?.toLowerCase();
158
+ if (!emailDomain) return [];
159
+ const [allowed, domainProviders] = await Promise.all([getAllowedAuthMethods(db)(organizationId), getSSOProvidersByDomain(db)(emailDomain)]);
160
+ return allowedMethodsToMethodOptions(allowed, domainProviders.filter((p) => p.organizationId === organizationId));
161
+ };
162
+ function allowedMethodsToMethodOptions(methods, ssoProviders) {
163
+ const options = [];
164
+ for (const m of methods) if (m.method === "email-password") options.push({ method: "email-password" });
165
+ else if (m.method === "google") options.push({ method: "google" });
166
+ else if (m.method === "sso") {
167
+ if (!m.enabled) continue;
168
+ const provider = ssoProviders.find((p) => p.providerId === m.providerId);
169
+ if (!provider) continue;
170
+ options.push({
171
+ method: "sso",
172
+ providerId: m.providerId,
173
+ providerType: provider.providerType,
174
+ displayName: m.displayName
175
+ });
176
+ }
177
+ return options;
178
+ }
179
+ /**
180
+ * Main auth-lookup query for the login flow.
181
+ * Returns org-grouped methods based on SSO domain match and/or user org membership.
182
+ */
183
+ const getAuthLookupForEmail = (db) => async (email) => {
184
+ const emailDomain = email.split("@")[1]?.toLowerCase();
185
+ if (!emailDomain) return [];
186
+ const orgMap = /* @__PURE__ */ new Map();
187
+ const domainProviders = await getSSOProvidersByDomain(db)(emailDomain);
188
+ const orgIdsFromSSO = [...new Set(domainProviders.map((p) => p.organizationId).filter(Boolean))];
189
+ for (const orgId of orgIdsFromSSO) {
190
+ const org = (await db.select({
191
+ id: organization.id,
192
+ name: organization.name,
193
+ slug: organization.slug,
194
+ allowedAuthMethods: organization.allowedAuthMethods,
195
+ preferredAuthMethod: organization.preferredAuthMethod
196
+ }).from(organization).where(eq(organization.id, orgId)).limit(1))[0];
197
+ if (!org) continue;
198
+ const allowed = parseAllowedAuthMethods(org.allowedAuthMethods);
199
+ const orgSSO = domainProviders.filter((p) => p.organizationId === orgId);
200
+ orgMap.set(orgId, {
201
+ organizationId: org.id,
202
+ organizationName: org.name,
203
+ organizationSlug: org.slug,
204
+ methods: allowedMethodsToMethodOptions(allowed, orgSSO)
205
+ });
206
+ }
207
+ const userRow = await db.select({ id: user.id }).from(user).where(eq(user.email, email.toLowerCase())).limit(1);
208
+ if (userRow[0]) {
209
+ const memberships = await db.select({
210
+ organizationId: member.organizationId,
211
+ orgName: organization.name,
212
+ orgSlug: organization.slug,
213
+ allowedAuthMethods: organization.allowedAuthMethods,
214
+ preferredAuthMethod: organization.preferredAuthMethod
215
+ }).from(member).innerJoin(organization, eq(member.organizationId, organization.id)).where(eq(member.userId, userRow[0].id));
216
+ for (const m of memberships) {
217
+ if (orgMap.has(m.organizationId)) continue;
218
+ const allowed = parseAllowedAuthMethods(m.allowedAuthMethods);
219
+ const orgSSO = domainProviders.filter((p) => p.organizationId === m.organizationId);
220
+ orgMap.set(m.organizationId, {
221
+ organizationId: m.organizationId,
222
+ organizationName: m.orgName,
223
+ organizationSlug: m.orgSlug,
224
+ methods: allowedMethodsToMethodOptions(allowed, orgSSO)
225
+ });
226
+ }
227
+ const serviceAccountOrgs = await db.select({
228
+ id: organization.id,
229
+ name: organization.name,
230
+ slug: organization.slug
231
+ }).from(organization).where(eq(organization.serviceAccountUserId, userRow[0].id));
232
+ for (const org of serviceAccountOrgs) {
233
+ const existing = orgMap.get(org.id);
234
+ if (existing) {
235
+ if (!existing.methods.some((m) => m.method === "email-password")) existing.methods.unshift({ method: "email-password" });
236
+ } else orgMap.set(org.id, {
237
+ organizationId: org.id,
238
+ organizationName: org.name,
239
+ organizationSlug: org.slug,
240
+ methods: [{ method: "email-password" }]
241
+ });
242
+ }
243
+ }
244
+ return [...orgMap.values()];
245
+ };
124
246
 
125
247
  //#endregion
126
- export { addUserToOrganization, createInvitationInDb, getPendingInvitationsByEmail, getUserOrganizationsFromDb, getUserProvidersFromDb, upsertOrganization };
248
+ export { addUserToOrganization, allowedMethodsToMethodOptions, createInvitationInDb, getAllowedAuthMethods, getAuthLookupForEmail, getFilteredAuthMethodsForEmail, getPendingInvitationsByEmail, getSSOProvidersByDomain, getUserOrganizationsFromDb, getUserProvidersFromDb, upsertOrganization };
@@ -14,13 +14,13 @@ declare const createTask: (db: AgentsRunDatabaseClient) => (params: TaskInsert)
14
14
  createdAt: string;
15
15
  updatedAt: string;
16
16
  metadata: TaskMetadataConfig | null;
17
+ status: string;
18
+ subAgentId: string;
17
19
  ref: {
18
20
  type: "commit" | "tag" | "branch";
19
21
  name: string;
20
22
  hash: string;
21
23
  } | null;
22
- status: string;
23
- subAgentId: string;
24
24
  contextId: string;
25
25
  }>;
26
26
  declare const getTask: (db: AgentsRunDatabaseClient) => (params: {