@inkeep/agents-core 0.0.0-dev-20260319030409 → 0.0.0-dev-20260319160044
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/auth-config-utils.d.ts +49 -0
- package/dist/auth/auth-config-utils.js +133 -0
- package/dist/auth/auth-schema.d.ts +102 -85
- package/dist/auth/auth-schema.js +1 -0
- package/dist/auth/auth-types.d.ts +170 -0
- package/dist/auth/auth-types.js +53 -0
- package/dist/auth/auth-validation-schemas.d.ts +169 -135
- package/dist/auth/auth.d.ts +43 -1286
- package/dist/auth/auth.js +61 -70
- package/dist/auth/email-send-status-store.js +15 -3
- package/dist/auth/init.js +2 -1
- package/dist/auth/password-reset-link-store.js +8 -1
- package/dist/auth/permissions.d.ts +9 -9
- package/dist/data-access/index.d.ts +4 -3
- package/dist/data-access/index.js +3 -3
- package/dist/data-access/manage/agents.d.ts +11 -11
- 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 +6 -6
- package/dist/data-access/manage/functionTools.d.ts +12 -12
- package/dist/data-access/manage/skills.d.ts +9 -9
- package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +18 -18
- package/dist/data-access/manage/subAgentRelations.d.ts +24 -24
- package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +18 -18
- package/dist/data-access/manage/subAgents.d.ts +9 -9
- package/dist/data-access/manage/tools.d.ts +15 -15
- package/dist/data-access/runtime/apiKeys.d.ts +16 -16
- package/dist/data-access/runtime/apps.d.ts +6 -6
- package/dist/data-access/runtime/auth.d.ts +9 -9
- package/dist/data-access/runtime/auth.js +19 -21
- package/dist/data-access/runtime/conversations.d.ts +16 -16
- package/dist/data-access/runtime/messages.d.ts +18 -18
- package/dist/data-access/runtime/organizations.d.ts +28 -4
- package/dist/data-access/runtime/organizations.js +131 -9
- package/dist/data-access/runtime/scheduledTriggerInvocations.d.ts +3 -3
- package/dist/data-access/runtime/tasks.d.ts +3 -3
- package/dist/db/manage/manage-schema.d.ts +449 -449
- package/dist/db/runtime/runtime-schema.d.ts +330 -330
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -3
- package/dist/middleware/no-auth.d.ts +2 -2
- package/dist/utils/error.d.ts +51 -48
- package/dist/utils/error.js +3 -0
- package/dist/validation/schemas.d.ts +1547 -1547
- package/drizzle/runtime/0023_lazy_energizer.sql +1 -0
- package/drizzle/runtime/0024_moaning_kingpin.sql +1 -0
- package/drizzle/runtime/meta/0024_snapshot.json +4270 -0
- package/drizzle/runtime/meta/_journal.json +7 -0
- package/package.json +8 -3
|
@@ -5,12 +5,12 @@ 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
|
+
projectId: string | null;
|
|
10
|
+
tenantId: string | null;
|
|
8
11
|
id: string;
|
|
9
12
|
name: string;
|
|
10
13
|
description: string | null;
|
|
11
|
-
tenantId: string | null;
|
|
12
|
-
projectId: string | null;
|
|
13
|
-
type: AppType;
|
|
14
14
|
createdAt: string;
|
|
15
15
|
updatedAt: string;
|
|
16
16
|
enabled: boolean;
|
|
@@ -52,12 +52,12 @@ declare const listAppsPaginated: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
52
52
|
};
|
|
53
53
|
}>;
|
|
54
54
|
declare const createApp: (db: AgentsRunDatabaseClient) => (params: AppInsert) => Promise<{
|
|
55
|
+
type: AppType;
|
|
56
|
+
projectId: string | null;
|
|
57
|
+
tenantId: string | null;
|
|
55
58
|
id: string;
|
|
56
59
|
name: string;
|
|
57
60
|
description: string | null;
|
|
58
|
-
tenantId: string | null;
|
|
59
|
-
projectId: string | null;
|
|
60
|
-
type: AppType;
|
|
61
61
|
createdAt: string;
|
|
62
62
|
updatedAt: string;
|
|
63
63
|
enabled: boolean;
|
|
@@ -5,14 +5,14 @@ declare const getInitialOrganization: (db: AgentsRunDatabaseClient) => (userId:
|
|
|
5
5
|
id: string;
|
|
6
6
|
} | null>;
|
|
7
7
|
declare const queryHasCredentialAccount: (db: AgentsRunDatabaseClient) => (userId: string) => Promise<boolean>;
|
|
8
|
-
|
|
9
|
-
providerId: string;
|
|
8
|
+
declare const querySsoProviderIssuers: (db: AgentsRunDatabaseClient) => () => Promise<{
|
|
10
9
|
issuer: string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
declare const
|
|
10
|
+
}[]>;
|
|
11
|
+
declare const querySsoProviderIds: (db: AgentsRunDatabaseClient) => () => Promise<string[]>;
|
|
12
|
+
declare const queryOrgAllowedAuthMethods: (db: AgentsRunDatabaseClient) => (orgId: string) => Promise<{
|
|
13
|
+
allowedAuthMethods: string | null;
|
|
14
|
+
} | undefined>;
|
|
15
|
+
declare const queryMemberExists: (db: AgentsRunDatabaseClient) => (userId: string, organizationId: string) => Promise<boolean>;
|
|
16
|
+
declare const queryPendingInvitationExists: (db: AgentsRunDatabaseClient) => (email: string, organizationId: string) => Promise<boolean>;
|
|
17
17
|
//#endregion
|
|
18
|
-
export {
|
|
18
|
+
export { getInitialOrganization, queryHasCredentialAccount, queryMemberExists, queryOrgAllowedAuthMethods, queryPendingInvitationExists, querySsoProviderIds, querySsoProviderIssuers };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { account, member, ssoProvider } from "../../auth/auth-schema.js";
|
|
2
|
-
import { generateId } from "../../utils/conversations.js";
|
|
3
|
-
import "../../utils/index.js";
|
|
1
|
+
import { account, invitation, member, organization, ssoProvider } from "../../auth/auth-schema.js";
|
|
4
2
|
import { and, eq } from "drizzle-orm";
|
|
5
3
|
|
|
6
4
|
//#region src/data-access/runtime/auth.ts
|
|
@@ -12,24 +10,24 @@ const queryHasCredentialAccount = (db) => async (userId) => {
|
|
|
12
10
|
const [row] = await db.select({ id: account.id }).from(account).where(and(eq(account.userId, userId), eq(account.providerId, "credential"))).limit(1);
|
|
13
11
|
return !!row;
|
|
14
12
|
};
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
13
|
+
const querySsoProviderIssuers = (db) => async () => {
|
|
14
|
+
return db.select({ issuer: ssoProvider.issuer }).from(ssoProvider);
|
|
15
|
+
};
|
|
16
|
+
const querySsoProviderIds = (db) => async () => {
|
|
17
|
+
return (await db.select({ providerId: ssoProvider.providerId }).from(ssoProvider)).map((r) => r.providerId);
|
|
18
|
+
};
|
|
19
|
+
const queryOrgAllowedAuthMethods = (db) => async (orgId) => {
|
|
20
|
+
const [org] = await db.select({ allowedAuthMethods: organization.allowedAuthMethods }).from(organization).where(eq(organization.id, orgId)).limit(1);
|
|
21
|
+
return org;
|
|
22
|
+
};
|
|
23
|
+
const queryMemberExists = (db) => async (userId, organizationId) => {
|
|
24
|
+
const [row] = await db.select({ id: member.id }).from(member).where(and(eq(member.userId, userId), eq(member.organizationId, organizationId))).limit(1);
|
|
25
|
+
return !!row;
|
|
26
|
+
};
|
|
27
|
+
const queryPendingInvitationExists = (db) => async (email, organizationId) => {
|
|
28
|
+
const [row] = await db.select({ id: invitation.id }).from(invitation).where(and(eq(invitation.email, email), eq(invitation.organizationId, organizationId), eq(invitation.status, "pending"))).limit(1);
|
|
29
|
+
return !!row;
|
|
32
30
|
};
|
|
33
31
|
|
|
34
32
|
//#endregion
|
|
35
|
-
export { getInitialOrganization, queryHasCredentialAccount,
|
|
33
|
+
export { getInitialOrganization, queryHasCredentialAccount, queryMemberExists, queryOrgAllowedAuthMethods, queryPendingInvitationExists, querySsoProviderIds, querySsoProviderIssuers };
|
|
@@ -16,15 +16,15 @@ declare const listConversations: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
16
16
|
total: number;
|
|
17
17
|
}>;
|
|
18
18
|
declare const createConversation: (db: AgentsRunDatabaseClient) => (params: ConversationInsert) => Promise<{
|
|
19
|
-
id: string;
|
|
20
|
-
tenantId: string;
|
|
21
|
-
projectId: string;
|
|
22
19
|
agentId: string | null;
|
|
20
|
+
projectId: string;
|
|
21
|
+
tenantId: string;
|
|
22
|
+
userId: string | null;
|
|
23
|
+
id: string;
|
|
23
24
|
title: string | null;
|
|
24
25
|
createdAt: string;
|
|
25
26
|
updatedAt: string;
|
|
26
27
|
metadata: ConversationMetadata | null;
|
|
27
|
-
userId: string | null;
|
|
28
28
|
ref: {
|
|
29
29
|
type: "tag" | "commit" | "branch";
|
|
30
30
|
name: string;
|
|
@@ -85,15 +85,15 @@ declare const getConversation: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
85
85
|
scopes: ProjectScopeConfig;
|
|
86
86
|
conversationId: string;
|
|
87
87
|
}) => Promise<{
|
|
88
|
-
id: string;
|
|
89
|
-
tenantId: string;
|
|
90
|
-
projectId: string;
|
|
91
88
|
agentId: string | null;
|
|
89
|
+
projectId: string;
|
|
90
|
+
tenantId: string;
|
|
91
|
+
userId: string | null;
|
|
92
|
+
id: string;
|
|
92
93
|
title: string | null;
|
|
93
94
|
createdAt: string;
|
|
94
95
|
updatedAt: string;
|
|
95
96
|
metadata: ConversationMetadata | null;
|
|
96
|
-
userId: string | null;
|
|
97
97
|
ref: {
|
|
98
98
|
type: "tag" | "commit" | "branch";
|
|
99
99
|
name: string;
|
|
@@ -121,15 +121,15 @@ declare const createOrGetConversation: (db: AgentsRunDatabaseClient) => (input:
|
|
|
121
121
|
metadata?: ConversationMetadata | null | undefined;
|
|
122
122
|
contextConfigId?: string | undefined;
|
|
123
123
|
} | {
|
|
124
|
-
id: string;
|
|
125
|
-
tenantId: string;
|
|
126
|
-
projectId: string;
|
|
127
124
|
agentId: string | null;
|
|
125
|
+
projectId: string;
|
|
126
|
+
tenantId: string;
|
|
127
|
+
userId: string | null;
|
|
128
|
+
id: string;
|
|
128
129
|
title: string | null;
|
|
129
130
|
createdAt: string;
|
|
130
131
|
updatedAt: string;
|
|
131
132
|
metadata: ConversationMetadata | null;
|
|
132
|
-
userId: string | null;
|
|
133
133
|
ref: {
|
|
134
134
|
type: "tag" | "commit" | "branch";
|
|
135
135
|
name: string;
|
|
@@ -153,15 +153,15 @@ declare const getActiveAgentForConversation: (db: AgentsRunDatabaseClient) => (p
|
|
|
153
153
|
scopes: ProjectScopeConfig;
|
|
154
154
|
conversationId: string;
|
|
155
155
|
}) => Promise<{
|
|
156
|
-
id: string;
|
|
157
|
-
tenantId: string;
|
|
158
|
-
projectId: string;
|
|
159
156
|
agentId: string | null;
|
|
157
|
+
projectId: string;
|
|
158
|
+
tenantId: string;
|
|
159
|
+
userId: string | null;
|
|
160
|
+
id: string;
|
|
160
161
|
title: string | null;
|
|
161
162
|
createdAt: string;
|
|
162
163
|
updatedAt: string;
|
|
163
164
|
metadata: ConversationMetadata | null;
|
|
164
|
-
userId: string | null;
|
|
165
165
|
ref: {
|
|
166
166
|
type: "tag" | "commit" | "branch";
|
|
167
167
|
name: string;
|
|
@@ -10,26 +10,26 @@ declare const getMessageById: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
10
10
|
scopes: ProjectScopeConfig;
|
|
11
11
|
messageId: string;
|
|
12
12
|
}) => Promise<{
|
|
13
|
-
id: string;
|
|
14
|
-
tenantId: string;
|
|
15
13
|
projectId: string;
|
|
14
|
+
tenantId: string;
|
|
15
|
+
id: string;
|
|
16
16
|
createdAt: string;
|
|
17
17
|
updatedAt: string;
|
|
18
18
|
metadata: MessageMetadata | null;
|
|
19
19
|
content: MessageContent;
|
|
20
|
+
role: string;
|
|
21
|
+
conversationId: string;
|
|
20
22
|
fromSubAgentId: string | null;
|
|
21
23
|
toSubAgentId: string | null;
|
|
22
24
|
fromExternalAgentId: string | null;
|
|
23
25
|
toExternalAgentId: string | null;
|
|
24
|
-
taskId: string | null;
|
|
25
|
-
a2aTaskId: string | null;
|
|
26
|
-
conversationId: string;
|
|
27
|
-
role: 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: {
|
|
@@ -144,26 +144,26 @@ declare const createMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
144
144
|
scopes: ProjectScopeConfig;
|
|
145
145
|
data: Omit<MessageInsert, "tenantId" | "projectId">;
|
|
146
146
|
}) => Promise<{
|
|
147
|
-
id: string;
|
|
148
|
-
tenantId: string;
|
|
149
147
|
projectId: string;
|
|
148
|
+
tenantId: string;
|
|
149
|
+
id: string;
|
|
150
150
|
createdAt: string;
|
|
151
151
|
updatedAt: string;
|
|
152
152
|
metadata: MessageMetadata | null;
|
|
153
153
|
content: MessageContent;
|
|
154
|
+
role: string;
|
|
155
|
+
conversationId: string;
|
|
154
156
|
fromSubAgentId: string | null;
|
|
155
157
|
toSubAgentId: string | null;
|
|
156
158
|
fromExternalAgentId: string | null;
|
|
157
159
|
toExternalAgentId: string | null;
|
|
158
|
-
taskId: string | null;
|
|
159
|
-
a2aTaskId: string | null;
|
|
160
|
-
conversationId: string;
|
|
161
|
-
role: string;
|
|
162
160
|
fromTeamAgentId: string | null;
|
|
163
161
|
toTeamAgentId: string | null;
|
|
164
162
|
visibility: string;
|
|
165
163
|
messageType: string;
|
|
164
|
+
taskId: string | null;
|
|
166
165
|
parentMessageId: string | null;
|
|
166
|
+
a2aTaskId: string | null;
|
|
167
167
|
a2aSessionId: string | null;
|
|
168
168
|
}>;
|
|
169
169
|
declare const updateMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
@@ -197,26 +197,26 @@ declare const deleteMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
197
197
|
scopes: ProjectScopeConfig;
|
|
198
198
|
messageId: string;
|
|
199
199
|
}) => Promise<{
|
|
200
|
-
id: string;
|
|
201
|
-
tenantId: string;
|
|
202
200
|
projectId: string;
|
|
201
|
+
tenantId: string;
|
|
202
|
+
id: string;
|
|
203
203
|
createdAt: string;
|
|
204
204
|
updatedAt: string;
|
|
205
205
|
metadata: MessageMetadata | null;
|
|
206
206
|
content: MessageContent;
|
|
207
|
+
role: string;
|
|
208
|
+
conversationId: string;
|
|
207
209
|
fromSubAgentId: string | null;
|
|
208
210
|
toSubAgentId: string | null;
|
|
209
211
|
fromExternalAgentId: string | null;
|
|
210
212
|
toExternalAgentId: string | null;
|
|
211
|
-
taskId: string | null;
|
|
212
|
-
a2aTaskId: string | null;
|
|
213
|
-
conversationId: string;
|
|
214
|
-
role: string;
|
|
215
213
|
fromTeamAgentId: string | null;
|
|
216
214
|
toTeamAgentId: string | null;
|
|
217
215
|
visibility: string;
|
|
218
216
|
messageType: string;
|
|
217
|
+
taskId: string | null;
|
|
219
218
|
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'
|
|
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
|
-
*
|
|
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)
|
|
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'
|
|
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
|
-
*
|
|
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
|
-
|
|
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:
|
|
128
|
+
authMethod: resolvedMethod
|
|
118
129
|
});
|
|
119
130
|
return {
|
|
120
131
|
id: inviteId,
|
|
121
|
-
authMethod:
|
|
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 };
|
|
@@ -39,7 +39,7 @@ declare const listScheduledTriggerInvocationsPaginated: (db: AgentsRunDatabaseCl
|
|
|
39
39
|
name: string;
|
|
40
40
|
hash: string;
|
|
41
41
|
} | null;
|
|
42
|
-
status: "pending" | "
|
|
42
|
+
status: "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
43
43
|
scheduledFor: string;
|
|
44
44
|
startedAt: string | null;
|
|
45
45
|
completedAt: string | null;
|
|
@@ -184,7 +184,7 @@ declare const listUpcomingInvocationsForAgentPaginated: (db: AgentsRunDatabaseCl
|
|
|
184
184
|
name: string;
|
|
185
185
|
hash: string;
|
|
186
186
|
} | null;
|
|
187
|
-
status: "pending" | "
|
|
187
|
+
status: "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
188
188
|
scheduledFor: string;
|
|
189
189
|
startedAt: string | null;
|
|
190
190
|
completedAt: string | null;
|
|
@@ -223,7 +223,7 @@ declare const listProjectScheduledTriggerInvocationsPaginated: (db: AgentsRunDat
|
|
|
223
223
|
name: string;
|
|
224
224
|
hash: string;
|
|
225
225
|
} | null;
|
|
226
|
-
status: "pending" | "
|
|
226
|
+
status: "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
227
227
|
scheduledFor: string;
|
|
228
228
|
startedAt: string | null;
|
|
229
229
|
completedAt: string | null;
|
|
@@ -7,10 +7,10 @@ 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
|
-
id: string;
|
|
11
|
-
tenantId: string;
|
|
12
|
-
projectId: string;
|
|
13
10
|
agentId: string;
|
|
11
|
+
projectId: string;
|
|
12
|
+
tenantId: string;
|
|
13
|
+
id: string;
|
|
14
14
|
createdAt: string;
|
|
15
15
|
updatedAt: string;
|
|
16
16
|
metadata: TaskMetadataConfig | null;
|