@8wave/ai-elements 0.119.0-beta.56 → 0.119.0-beta.60
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/README.md +3 -0
- package/dist/ai-elements.es.js +1733 -1632
- package/dist/ai-elements.es.js.map +1 -1
- package/dist-vue/apps/web-component/src/composables/useChatbotAuth.d.ts +36 -0
- package/dist-vue/composables.js +265 -166
- package/dist-vue/composables.js.map +1 -1
- package/dist-vue/index.js +4 -4
- package/dist-vue/index.js.map +1 -1
- package/dist-vue/packages/auth/src/external-auth-plugin.d.ts +22 -0
- package/dist-vue/packages/auth/src/external-identity.d.ts +64 -0
- package/dist-vue/packages/models/src/schema/McpServer.d.ts +19 -3
- package/dist-vue/packages/models/src/schema/Organization.d.ts +10 -0
- package/dist-vue/style.css +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,24 @@
|
|
|
1
1
|
import { BetterAuthPlugin } from 'better-auth';
|
|
2
|
+
/**
|
|
3
|
+
* The identity provider's token a session was opened, or last refreshed,
|
|
4
|
+
* with: what an MCP server set to `external-token` receives on the turns of
|
|
5
|
+
* that session.
|
|
6
|
+
*/
|
|
7
|
+
export type ExternalTokenGrant = {
|
|
8
|
+
token: string;
|
|
9
|
+
issuer: string;
|
|
10
|
+
organizationId: string;
|
|
11
|
+
userId: string;
|
|
12
|
+
expiresAt: Date | undefined;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Where a session's token is kept, implemented by the backend (encrypted,
|
|
16
|
+
* expiring with the token) and injected at startup, as the media service is.
|
|
17
|
+
* `save` never throws and says whether the token was kept.
|
|
18
|
+
*/
|
|
19
|
+
export type ExternalTokenStore = {
|
|
20
|
+
save(sessionId: string, grant: ExternalTokenGrant, sessionExpiresAt: Date): Promise<boolean>;
|
|
21
|
+
};
|
|
22
|
+
/** Injects the store the sign-in and the refresh keep a session's token in. */
|
|
23
|
+
export declare function setExternalTokenStore(store: ExternalTokenStore): void;
|
|
2
24
|
export declare function externalAuth(): BetterAuthPlugin;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { DBAdapter } from 'better-auth';
|
|
2
|
+
import { database } from 'database';
|
|
3
|
+
/**
|
|
4
|
+
* Why an external token was refused. Each caller answers in its own shape:
|
|
5
|
+
* the better-auth endpoint as an API error, the OpenAI-compatible surface in
|
|
6
|
+
* OpenAI's.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ExternalTokenError extends Error {
|
|
9
|
+
readonly status: 'BAD_REQUEST' | 'UNAUTHORIZED';
|
|
10
|
+
constructor(status: 'BAD_REQUEST' | 'UNAUTHORIZED', message: string);
|
|
11
|
+
}
|
|
12
|
+
type ExternalUserRecord = {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
email: string;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Who an external token names, after its signature, issuer and audience were
|
|
20
|
+
* checked against the organization's configuration, and with the user and
|
|
21
|
+
* the membership it implies already in the database.
|
|
22
|
+
*/
|
|
23
|
+
export type ExternalIdentity = {
|
|
24
|
+
user: ExternalUserRecord;
|
|
25
|
+
issuer: string;
|
|
26
|
+
organizationId: string;
|
|
27
|
+
sessionExpiresIn: number | null;
|
|
28
|
+
/** The token's own `exp`, when it carries one. */
|
|
29
|
+
expiresAt: Date | undefined;
|
|
30
|
+
};
|
|
31
|
+
type ExternalAuthConfig = NonNullable<Awaited<ReturnType<typeof database.query.organizationExternalAuth.findFirst>>>;
|
|
32
|
+
/** A token whose signature, issuer and audience verified, and nothing more. */
|
|
33
|
+
export type VerifiedExternalToken = {
|
|
34
|
+
issuer: string;
|
|
35
|
+
/** The `sub` claim. */
|
|
36
|
+
externalId: string;
|
|
37
|
+
/** The organization whose configuration verified the token. */
|
|
38
|
+
organizationId: string;
|
|
39
|
+
expiresAt: Date | undefined;
|
|
40
|
+
payload: Record<string, unknown>;
|
|
41
|
+
config: ExternalAuthConfig;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Verifies a token issued by an organization's identity provider, without
|
|
45
|
+
* touching any user: the step a refresh of a session's token needs, which
|
|
46
|
+
* must change nothing when it refuses.
|
|
47
|
+
*
|
|
48
|
+
* @throws {ExternalTokenError} when the token is malformed, its issuer has no
|
|
49
|
+
* enabled configuration, or its signature, issuer or audience do not verify.
|
|
50
|
+
*/
|
|
51
|
+
export declare function verifyExternalToken(token: string): Promise<VerifiedExternalToken>;
|
|
52
|
+
/** The user a provider's identity (issuer, sub) is linked to, if any. */
|
|
53
|
+
export declare function findExternalIdentityUserId(issuer: string, externalId: string): Promise<string | null>;
|
|
54
|
+
/**
|
|
55
|
+
* Verifies a token issued by an organization's identity provider and returns
|
|
56
|
+
* the platform user it names, creating, linking or updating that user and
|
|
57
|
+
* their membership as needed. Shared by the widget's sign-in, which then opens
|
|
58
|
+
* a session, and by the OpenAI-compatible surface, which takes the token on
|
|
59
|
+
* every request instead.
|
|
60
|
+
*
|
|
61
|
+
* @throws {ExternalTokenError} as {@link verifyExternalToken}.
|
|
62
|
+
*/
|
|
63
|
+
export declare function resolveExternalIdentity(token: string, adapter: Pick<DBAdapter, 'findOne' | 'create' | 'update'>): Promise<ExternalIdentity>;
|
|
64
|
+
export {};
|
|
@@ -24,8 +24,20 @@ export declare enum McpServerStatus {
|
|
|
24
24
|
}
|
|
25
25
|
export declare enum McpServerAuthType {
|
|
26
26
|
Headers = "headers",
|
|
27
|
-
OAuth = "oauth"
|
|
27
|
+
OAuth = "oauth",
|
|
28
|
+
/**
|
|
29
|
+
* Forwards the identity provider's token the caller authenticated with
|
|
30
|
+
* (the organization's external sign-in) as `Authorization: Bearer`. For an
|
|
31
|
+
* MCP server of the same organization that trusts that provider.
|
|
32
|
+
*/
|
|
33
|
+
ExternalToken = "external-token"
|
|
28
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Whether a server's connection carries a credential of the user taking the
|
|
37
|
+
* turn (their OAuth sign-in, or the token they authenticated with), so it can
|
|
38
|
+
* neither be loaded without one nor shared between users.
|
|
39
|
+
*/
|
|
40
|
+
export declare const isPerUserAuthType: (authType: string) => boolean;
|
|
29
41
|
export declare const McpServerSchema: z.ZodObject<{
|
|
30
42
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
31
43
|
createdBy: z.ZodString;
|
|
@@ -37,6 +49,7 @@ export declare const McpServerSchema: z.ZodObject<{
|
|
|
37
49
|
authType: z.ZodDefault<z.ZodEnum<{
|
|
38
50
|
headers: "headers";
|
|
39
51
|
oauth: "oauth";
|
|
52
|
+
"external-token": "external-token";
|
|
40
53
|
}>>;
|
|
41
54
|
oauthClientId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
42
55
|
oauthClientSecret: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -66,6 +79,7 @@ export declare const McpServerCreateSchema: z.ZodObject<{
|
|
|
66
79
|
authType: z.ZodDefault<z.ZodEnum<{
|
|
67
80
|
headers: "headers";
|
|
68
81
|
oauth: "oauth";
|
|
82
|
+
"external-token": "external-token";
|
|
69
83
|
}>>;
|
|
70
84
|
oauthClientId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
71
85
|
oauthClientSecret: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -91,6 +105,7 @@ export declare const McpServerUpdateSchema: z.ZodObject<{
|
|
|
91
105
|
authType: z.ZodDefault<z.ZodEnum<{
|
|
92
106
|
headers: "headers";
|
|
93
107
|
oauth: "oauth";
|
|
108
|
+
"external-token": "external-token";
|
|
94
109
|
}>>;
|
|
95
110
|
oauthClientId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
96
111
|
oauthClientSecret: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -137,10 +152,11 @@ export declare const McpServerInfoSchema: z.ZodObject<{
|
|
|
137
152
|
name: z.ZodString;
|
|
138
153
|
description: z.ZodOptional<z.ZodString>;
|
|
139
154
|
}, z.core.$strip>>;
|
|
140
|
-
info: z.ZodObject<{
|
|
155
|
+
info: z.ZodOptional<z.ZodObject<{
|
|
141
156
|
name: z.ZodString;
|
|
142
157
|
version: z.ZodString;
|
|
143
|
-
}, z.core.$strip
|
|
158
|
+
}, z.core.$strip>>;
|
|
159
|
+
lastKnown: z.ZodOptional<z.ZodBoolean>;
|
|
144
160
|
}, z.core.$strip>;
|
|
145
161
|
/**
|
|
146
162
|
* One integration the current user has signed in to with their own account,
|
|
@@ -260,6 +260,16 @@ export declare enum OrganizationFeature {
|
|
|
260
260
|
ApiTools = "apiTools",
|
|
261
261
|
SubAgents = "subAgents",
|
|
262
262
|
Endpoints = "endpoints",
|
|
263
|
+
/**
|
|
264
|
+
* The agents as models of the OpenAI-compatible API (`/api/openai/v1`):
|
|
265
|
+
* the agent page that shows how to connect a client, and the switch that
|
|
266
|
+
* exposes the agent there. Like the endpoints, the flag gates the page
|
|
267
|
+
* and the switch into the on state, not the calls: an agent already
|
|
268
|
+
* exposed keeps answering, and can still be switched off. Off by
|
|
269
|
+
* default: until this page the switch had no screen, so no organization
|
|
270
|
+
* relied on turning it on by itself.
|
|
271
|
+
*/
|
|
272
|
+
OpenAiApi = "openaiApi",
|
|
263
273
|
/**
|
|
264
274
|
* One flag per integration provider and not one for all of them, for
|
|
265
275
|
* the same reason as the channels: a contract names the CRM or the
|