@inkeep/agents-core 0.0.0-dev-20260319140628 → 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 +17 -0
- 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 +186 -152
- package/dist/auth/auth.d.ts +48 -1291
- 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 +13 -13
- 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 +10 -10
- 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/manage/triggers.d.ts +2 -2
- package/dist/data-access/runtime/apiKeys.d.ts +12 -12
- 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 +23 -23
- package/dist/data-access/runtime/messages.d.ts +6 -6
- 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 +6 -6
- package/dist/data-access/runtime/tasks.d.ts +7 -7
- package/dist/data-access/runtime/triggerInvocations.d.ts +1 -1
- package/dist/db/manage/manage-schema.d.ts +453 -453
- package/dist/db/runtime/runtime-schema.d.ts +346 -346
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -3
- package/dist/utils/error.d.ts +54 -51
- package/dist/utils/error.js +3 -0
- package/dist/validation/dolt-schemas.d.ts +1 -1
- package/dist/validation/drizzle-schema-helpers.d.ts +3 -3
- package/dist/validation/schemas.d.ts +1883 -1883
- 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
|
@@ -8,11 +8,11 @@ declare const getApiKeyById: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
8
8
|
scopes: ProjectScopeConfig;
|
|
9
9
|
id: string;
|
|
10
10
|
}) => Promise<{
|
|
11
|
+
agentId: string;
|
|
12
|
+
projectId: string;
|
|
13
|
+
tenantId: string;
|
|
11
14
|
id: string;
|
|
12
15
|
name: string | null;
|
|
13
|
-
tenantId: string;
|
|
14
|
-
projectId: string;
|
|
15
|
-
agentId: string;
|
|
16
16
|
createdAt: string;
|
|
17
17
|
updatedAt: string;
|
|
18
18
|
expiresAt: string | null;
|
|
@@ -22,11 +22,11 @@ declare const getApiKeyById: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
22
22
|
lastUsedAt: string | null;
|
|
23
23
|
} | undefined>;
|
|
24
24
|
declare const getApiKeyByPublicId: (db: AgentsRunDatabaseClient) => (publicId: string) => Promise<{
|
|
25
|
+
agentId: string;
|
|
26
|
+
projectId: string;
|
|
27
|
+
tenantId: string;
|
|
25
28
|
id: string;
|
|
26
29
|
name: string | null;
|
|
27
|
-
tenantId: string;
|
|
28
|
-
projectId: string;
|
|
29
|
-
agentId: string;
|
|
30
30
|
createdAt: string;
|
|
31
31
|
updatedAt: string;
|
|
32
32
|
expiresAt: string | null;
|
|
@@ -39,11 +39,11 @@ declare const listApiKeys: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
39
39
|
scopes: ProjectScopeConfig;
|
|
40
40
|
agentId?: string;
|
|
41
41
|
}) => Promise<{
|
|
42
|
+
agentId: string;
|
|
43
|
+
projectId: string;
|
|
44
|
+
tenantId: string;
|
|
42
45
|
id: string;
|
|
43
46
|
name: string | null;
|
|
44
|
-
tenantId: string;
|
|
45
|
-
projectId: string;
|
|
46
|
-
agentId: string;
|
|
47
47
|
createdAt: string;
|
|
48
48
|
updatedAt: string;
|
|
49
49
|
expiresAt: string | null;
|
|
@@ -66,11 +66,11 @@ declare const listApiKeysPaginated: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
66
66
|
};
|
|
67
67
|
}>;
|
|
68
68
|
declare const createApiKey: (db: AgentsRunDatabaseClient) => (params: ApiKeyInsert) => Promise<{
|
|
69
|
+
agentId: string;
|
|
70
|
+
projectId: string;
|
|
71
|
+
tenantId: string;
|
|
69
72
|
id: string;
|
|
70
73
|
name: string | null;
|
|
71
|
-
tenantId: string;
|
|
72
|
-
projectId: string;
|
|
73
|
-
agentId: string;
|
|
74
74
|
createdAt: string;
|
|
75
75
|
updatedAt: string;
|
|
76
76
|
expiresAt: string | null;
|
|
@@ -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,20 +16,20 @@ 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
28
|
ref: {
|
|
28
|
-
type: "
|
|
29
|
+
type: "tag" | "commit" | "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
|
}>;
|
|
@@ -44,7 +44,7 @@ declare const updateConversation: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
44
44
|
agentId: string | null;
|
|
45
45
|
activeSubAgentId: string;
|
|
46
46
|
ref: {
|
|
47
|
-
type: "
|
|
47
|
+
type: "tag" | "commit" | "branch";
|
|
48
48
|
name: string;
|
|
49
49
|
hash: string;
|
|
50
50
|
} | null;
|
|
@@ -70,7 +70,7 @@ declare const updateConversationActiveSubAgent: (db: AgentsRunDatabaseClient) =>
|
|
|
70
70
|
agentId: string | null;
|
|
71
71
|
activeSubAgentId: string;
|
|
72
72
|
ref: {
|
|
73
|
-
type: "
|
|
73
|
+
type: "tag" | "commit" | "branch";
|
|
74
74
|
name: string;
|
|
75
75
|
hash: string;
|
|
76
76
|
} | null;
|
|
@@ -85,20 +85,20 @@ 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
97
|
ref: {
|
|
97
|
-
type: "
|
|
98
|
+
type: "tag" | "commit" | "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>;
|
|
@@ -108,7 +108,7 @@ declare const createOrGetConversation: (db: AgentsRunDatabaseClient) => (input:
|
|
|
108
108
|
tenantId: string;
|
|
109
109
|
id: string;
|
|
110
110
|
ref: {
|
|
111
|
-
type: "
|
|
111
|
+
type: "tag" | "commit" | "branch";
|
|
112
112
|
name: string;
|
|
113
113
|
hash: string;
|
|
114
114
|
};
|
|
@@ -121,20 +121,20 @@ 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
133
|
ref: {
|
|
133
|
-
type: "
|
|
134
|
+
type: "tag" | "commit" | "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
|
}>;
|
|
@@ -153,20 +153,20 @@ 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
165
|
ref: {
|
|
165
|
-
type: "
|
|
166
|
+
type: "tag" | "commit" | "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>;
|
|
@@ -10,9 +10,9 @@ 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;
|
|
@@ -144,9 +144,9 @@ 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;
|
|
@@ -197,9 +197,9 @@ 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;
|
|
@@ -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 };
|
|
@@ -35,11 +35,11 @@ declare const listScheduledTriggerInvocationsPaginated: (db: AgentsRunDatabaseCl
|
|
|
35
35
|
data: {
|
|
36
36
|
scheduledTriggerId: string;
|
|
37
37
|
ref: {
|
|
38
|
-
type: "
|
|
38
|
+
type: "tag" | "commit" | "branch";
|
|
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;
|
|
@@ -180,11 +180,11 @@ declare const listUpcomingInvocationsForAgentPaginated: (db: AgentsRunDatabaseCl
|
|
|
180
180
|
data: {
|
|
181
181
|
scheduledTriggerId: string;
|
|
182
182
|
ref: {
|
|
183
|
-
type: "
|
|
183
|
+
type: "tag" | "commit" | "branch";
|
|
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;
|
|
@@ -219,11 +219,11 @@ declare const listProjectScheduledTriggerInvocationsPaginated: (db: AgentsRunDat
|
|
|
219
219
|
data: {
|
|
220
220
|
scheduledTriggerId: string;
|
|
221
221
|
ref: {
|
|
222
|
-
type: "
|
|
222
|
+
type: "tag" | "commit" | "branch";
|
|
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,20 +7,20 @@ 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;
|
|
17
|
+
subAgentId: string;
|
|
18
|
+
status: string;
|
|
17
19
|
ref: {
|
|
18
|
-
type: "
|
|
20
|
+
type: "tag" | "commit" | "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: {
|
|
@@ -39,7 +39,7 @@ declare const updateTask: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
39
39
|
updatedAt: string;
|
|
40
40
|
contextId: string;
|
|
41
41
|
ref: {
|
|
42
|
-
type: "
|
|
42
|
+
type: "tag" | "commit" | "branch";
|
|
43
43
|
name: string;
|
|
44
44
|
hash: string;
|
|
45
45
|
} | null;
|
|
@@ -29,7 +29,7 @@ declare const listTriggerInvocationsPaginated: (db: AgentsRunDatabaseClient) =>
|
|
|
29
29
|
triggerId: string;
|
|
30
30
|
conversationId: string | null;
|
|
31
31
|
ref: {
|
|
32
|
-
type: "
|
|
32
|
+
type: "tag" | "commit" | "branch";
|
|
33
33
|
name: string;
|
|
34
34
|
hash: string;
|
|
35
35
|
} | null;
|