@astralbeam/sdk 0.4.2 → 0.6.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.
- package/README.md +49 -42
- package/dist/client.d.ts +36 -19
- package/dist/client.js +1 -1
- package/dist/{core-2LtbAqiQ.js → core-DYXxodYg.js} +61 -42
- package/dist/core.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/{index-DJWIt_VP.d.ts → index-TbZxlv54.d.ts} +29 -9
- package/dist/react.d.ts +25 -25
- package/dist/react.js +25 -35
- package/dist/server.d.ts +9 -28
- package/dist/server.js +12 -46
- package/dist/widget-CfLWAtV7.js +79 -0
- package/package.json +1 -1
- package/dist/widget-C6NW94JW.js +0 -79
package/dist/react.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { C as AstralBeamChatState, S as AstralBeamChatCoreOptions, x as AstralBeamChatCore } from "./index-
|
|
1
|
+
import { C as AstralBeamChatState, S as AstralBeamChatCoreOptions, x as AstralBeamChatCore } from "./index-TbZxlv54.js";
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
|
-
import { AstralBeamChatAttachmentOptions,
|
|
3
|
+
import { AstralBeamChatAttachmentOptions, AstralBeamChatAuthTokenRequest, AstralBeamChatAuthTokenSource, AstralBeamChatColorScheme, AstralBeamChatTheme, InferParameters, JsonSchemaObject, ParametersSchema, ToolDefinition, WidgetDefinition as WidgetDefinition$1, defineTool } from "@astralbeam/sdk/client";
|
|
4
4
|
|
|
5
5
|
//#region src/react/index.d.ts
|
|
6
6
|
interface WidgetDefinition extends Omit<WidgetDefinition$1, "render"> {
|
|
@@ -26,11 +26,9 @@ interface UseAstralBeamChatResult extends AstralBeamChatState {
|
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* The headless chat session as a React hook: authentication, transport, tools, and transcript
|
|
29
|
-
* state with no markup, for hosts that own their whole chat UI.
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* ordinary closures over props and state stay live. Whether a widget renderer exists at all is
|
|
33
|
-
* part of the declared surface and is read at mount.
|
|
29
|
+
* state with no markup, for hosts that own their whole chat UI. Every option follows the props it
|
|
30
|
+
* is given, keeping the transcript and the chat session, so ordinary closures over props and
|
|
31
|
+
* state stay live and nothing needs a remount.
|
|
34
32
|
*/
|
|
35
33
|
declare function useAstralBeamChat(options: AstralBeamChatCoreOptions): UseAstralBeamChatResult;
|
|
36
34
|
/** Imperative surface of a mounted `<AstralBeamChat>`, for hosts that draw their own controls. */
|
|
@@ -42,15 +40,16 @@ interface AstralBeamChatRef {
|
|
|
42
40
|
}
|
|
43
41
|
interface AstralBeamChatProps {
|
|
44
42
|
/**
|
|
45
|
-
* Public ID of the organization-owned agent
|
|
46
|
-
*
|
|
43
|
+
* Public ID of the organization-owned agent. Omit it to use the organization's default agent,
|
|
44
|
+
* which the dashboard's agents page selects. A change answers the next run with the new agent
|
|
45
|
+
* and keeps the transcript, which that agent then sees as history.
|
|
47
46
|
*/
|
|
48
47
|
agentId?: string;
|
|
49
|
-
/** Name shown in the widget's header
|
|
48
|
+
/** Name shown in the widget's header. Default `"AstralBeam"`. */
|
|
50
49
|
title?: string;
|
|
51
50
|
/**
|
|
52
51
|
* Shows the widget's header with the title and the reset button; `false` hides both and gives
|
|
53
|
-
* the transcript the full height.
|
|
52
|
+
* the transcript the full height. Default `true`.
|
|
54
53
|
*/
|
|
55
54
|
showHeader?: boolean;
|
|
56
55
|
/** Replaces the header's content with the host's own React content; `showHeader` still applies. */
|
|
@@ -59,28 +58,29 @@ interface AstralBeamChatProps {
|
|
|
59
58
|
empty?: ReactNode;
|
|
60
59
|
/** Extra host controls at the end of the composer's button row, next to send. */
|
|
61
60
|
composerActions?: ReactNode;
|
|
62
|
-
/** Headline shown on the empty transcript
|
|
61
|
+
/** Headline shown on the empty transcript. Default `"Ask the assistant"`. */
|
|
63
62
|
emptyTitle?: string;
|
|
64
|
-
/** Subtitle under the empty transcript's headline
|
|
63
|
+
/** Subtitle under the empty transcript's headline. */
|
|
65
64
|
emptyDescription?: string;
|
|
66
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* Base URL of the AstralBeam API; the widget calls `/chat` under it. Read per request, so a
|
|
67
|
+
* change moves the next one. Default the hosted cloud.
|
|
68
|
+
*/
|
|
67
69
|
apiUrl?: string;
|
|
68
|
-
/** Application endpoint that mints a short-lived chat JWT. Default `"/api/astralbeam/token"`. */
|
|
69
|
-
authTokenUrl?: string;
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
71
|
+
* Where the short-lived chat JWT comes from: `{ url, ...RequestInit }` for a token endpoint, or
|
|
72
|
+
* a function minting `{ token }`, optionally a promise, in the host app. Read per token, and
|
|
73
|
+
* the function form runs in the host's React tree, so an inline closure over current auth state
|
|
74
|
+
* is fine and needs no memoization. Default `{ url: "/api/astralbeam/token" }`.
|
|
75
75
|
*/
|
|
76
|
-
|
|
76
|
+
fetchChatAuthToken?: AstralBeamChatAuthTokenSource;
|
|
77
77
|
/** Host-defined tools the agent can call, executed in the host's React app, keyed by name. */
|
|
78
78
|
tools?: Record<string, ToolDefinition>;
|
|
79
79
|
/** Host-defined widgets the agent can render inline in the conversation, keyed by identifier. */
|
|
80
80
|
widgets?: Record<string, WidgetDefinition>;
|
|
81
|
-
/** Color scheme of the chat widget
|
|
81
|
+
/** Color scheme of the chat widget. Default `"system"`. */
|
|
82
82
|
colorScheme?: AstralBeamChatColorScheme;
|
|
83
|
-
/** Custom values for the widget's theming CSS variables, per color scheme
|
|
83
|
+
/** Custom values for the widget's theming CSS variables, per color scheme. */
|
|
84
84
|
theme?: AstralBeamChatTheme | undefined;
|
|
85
85
|
/** File attachments in the composer, on by default; `false` turns them off. */
|
|
86
86
|
attachments?: boolean | AstralBeamChatAttachmentOptions;
|
|
@@ -88,10 +88,10 @@ interface AstralBeamChatProps {
|
|
|
88
88
|
sandboxPanel?: boolean;
|
|
89
89
|
/**
|
|
90
90
|
* Logs every SDK action to the browser console with UTC timestamps and full payloads,
|
|
91
|
-
* and asks the endpoint to log its side of the run too
|
|
91
|
+
* and asks the endpoint to log its side of the run too.
|
|
92
92
|
*/
|
|
93
93
|
debug?: boolean;
|
|
94
94
|
}
|
|
95
95
|
declare const AstralBeamChat: import("react").ForwardRefExoticComponent<AstralBeamChatProps & import("react").RefAttributes<AstralBeamChatRef>>;
|
|
96
96
|
//#endregion
|
|
97
|
-
export { AstralBeamChat, type AstralBeamChatAttachmentOptions, type
|
|
97
|
+
export { AstralBeamChat, type AstralBeamChatAttachmentOptions, type AstralBeamChatAuthTokenRequest, type AstralBeamChatAuthTokenSource, type AstralBeamChatColorScheme, type AstralBeamChatCore, type AstralBeamChatCoreOptions, AstralBeamChatProps, AstralBeamChatRef, type AstralBeamChatState, type AstralBeamChatTheme, type InferParameters, type ParametersSchema, type ToolDefinition, TypedReactWidgetDefinition, UseAstralBeamChatResult, WidgetDefinition, defineTool, defineWidget, useAstralBeamChat };
|
package/dist/react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as DEFAULT_COLOR_SCHEME, r as createAstralBeamChat } from "./core-
|
|
1
|
+
import { C as DEFAULT_COLOR_SCHEME, r as createAstralBeamChat } from "./core-DYXxodYg.js";
|
|
2
2
|
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
3
3
|
import { createPortal } from "react-dom";
|
|
4
4
|
import { defineTool, mountAstralBeamChat } from "@astralbeam/sdk/client";
|
|
@@ -10,27 +10,24 @@ function defineWidget(widget) {
|
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* The headless chat session as a React hook: authentication, transport, tools, and transcript
|
|
13
|
-
* state with no markup, for hosts that own their whole chat UI.
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* ordinary closures over props and state stay live. Whether a widget renderer exists at all is
|
|
17
|
-
* part of the declared surface and is read at mount.
|
|
13
|
+
* state with no markup, for hosts that own their whole chat UI. Every option follows the props it
|
|
14
|
+
* is given, keeping the transcript and the chat session, so ordinary closures over props and
|
|
15
|
+
* state stay live and nothing needs a remount.
|
|
18
16
|
*/
|
|
19
17
|
function useAstralBeamChat(options) {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}));
|
|
18
|
+
const [core] = useState(() => createAstralBeamChat(options));
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
core.updateOptions(options);
|
|
21
|
+
}, [
|
|
22
|
+
core,
|
|
23
|
+
options.agentId,
|
|
24
|
+
options.apiUrl,
|
|
25
|
+
options.fetchChatAuthToken,
|
|
26
|
+
options.tools,
|
|
27
|
+
options.widgets,
|
|
28
|
+
options.onRenderWidget,
|
|
29
|
+
options.debug
|
|
30
|
+
]);
|
|
34
31
|
useEffect(() => () => core.dispose(), [core]);
|
|
35
32
|
return {
|
|
36
33
|
...useSyncExternalStore(core.subscribe, core.getState, core.getState),
|
|
@@ -42,7 +39,7 @@ function useAstralBeamChat(options) {
|
|
|
42
39
|
core
|
|
43
40
|
};
|
|
44
41
|
}
|
|
45
|
-
const AstralBeamChat = forwardRef(function AstralBeamChat({ agentId, title, showHeader, header, empty, composerActions, emptyTitle, emptyDescription, apiUrl,
|
|
42
|
+
const AstralBeamChat = forwardRef(function AstralBeamChat({ agentId, title, showHeader, header, empty, composerActions, emptyTitle, emptyDescription, apiUrl, fetchChatAuthToken, tools, widgets = {}, colorScheme = DEFAULT_COLOR_SCHEME, theme, attachments, sandboxPanel, debug }, ref) {
|
|
46
43
|
const targetRef = useRef(null);
|
|
47
44
|
const handleRef = useRef(null);
|
|
48
45
|
const [activeRenders, setActiveRenders] = useState(/* @__PURE__ */ new Map());
|
|
@@ -54,10 +51,6 @@ const AstralBeamChat = forwardRef(function AstralBeamChat({ agentId, title, show
|
|
|
54
51
|
useEffect(() => {
|
|
55
52
|
toolsRef.current = tools;
|
|
56
53
|
});
|
|
57
|
-
const authTokenHeadersRef = useRef(authTokenHeaders);
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
authTokenHeadersRef.current = authTokenHeaders;
|
|
60
|
-
});
|
|
61
54
|
const nextRenderKey = useRef(0);
|
|
62
55
|
const hostTools = useMemo(() => Object.fromEntries(Object.entries(tools ?? {}).map(([name, definition]) => [name, {
|
|
63
56
|
...definition,
|
|
@@ -111,6 +104,9 @@ const AstralBeamChat = forwardRef(function AstralBeamChat({ agentId, title, show
|
|
|
111
104
|
hasComposerActions
|
|
112
105
|
]);
|
|
113
106
|
const live = useMemo(() => ({
|
|
107
|
+
agentId,
|
|
108
|
+
apiUrl,
|
|
109
|
+
fetchChatAuthToken,
|
|
114
110
|
title,
|
|
115
111
|
showHeader,
|
|
116
112
|
emptyTitle,
|
|
@@ -124,6 +120,9 @@ const AstralBeamChat = forwardRef(function AstralBeamChat({ agentId, title, show
|
|
|
124
120
|
widgets: hostWidgets,
|
|
125
121
|
slots: chromeSlots
|
|
126
122
|
}), [
|
|
123
|
+
agentId,
|
|
124
|
+
apiUrl,
|
|
125
|
+
fetchChatAuthToken,
|
|
127
126
|
title,
|
|
128
127
|
showHeader,
|
|
129
128
|
emptyTitle,
|
|
@@ -141,16 +140,7 @@ const AstralBeamChat = forwardRef(function AstralBeamChat({ agentId, title, show
|
|
|
141
140
|
liveRef.current = live;
|
|
142
141
|
useEffect(() => {
|
|
143
142
|
if (!targetRef.current) return;
|
|
144
|
-
const handle = mountAstralBeamChat(targetRef.current,
|
|
145
|
-
...liveRef.current,
|
|
146
|
-
agentId,
|
|
147
|
-
apiUrl,
|
|
148
|
-
authTokenUrl,
|
|
149
|
-
authTokenHeaders: () => {
|
|
150
|
-
const current = authTokenHeadersRef.current;
|
|
151
|
-
return typeof current === "function" ? current() : current ?? {};
|
|
152
|
-
}
|
|
153
|
-
});
|
|
143
|
+
const handle = mountAstralBeamChat(targetRef.current, liveRef.current);
|
|
154
144
|
handleRef.current = handle;
|
|
155
145
|
return () => {
|
|
156
146
|
handleRef.current = null;
|
package/dist/server.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as Schema from "effect/Schema";
|
|
2
2
|
|
|
3
3
|
//#region src/server/index.d.ts
|
|
4
|
-
declare const
|
|
5
|
-
declare const
|
|
6
|
-
declare const
|
|
7
|
-
declare const
|
|
8
|
-
declare const
|
|
4
|
+
declare const CHAT_AUTH_TOKEN_AUDIENCE = "astralbeam";
|
|
5
|
+
declare const CHAT_AUTH_TOKEN_TYPE = "astralbeam+jwt";
|
|
6
|
+
declare const CHAT_AUTH_TOKEN_VERSION = 4;
|
|
7
|
+
declare const CHAT_AUTH_TOKEN_LIFETIME_SECONDS = 300;
|
|
8
|
+
declare const CHAT_AUTH_TOKEN_MAX_LIFETIME_SECONDS = 600;
|
|
9
9
|
declare const TenantSchema: Schema.Struct<{
|
|
10
10
|
readonly id: Schema.String;
|
|
11
11
|
readonly name: Schema.optional<Schema.String>;
|
|
@@ -21,37 +21,18 @@ declare const TenantUserSchema: Schema.Struct<{
|
|
|
21
21
|
type Tenant = typeof TenantSchema.Type;
|
|
22
22
|
/** User of an Organization's Tenant who interacts with AstralBeam. */
|
|
23
23
|
type TenantUser = typeof TenantUserSchema.Type;
|
|
24
|
-
interface
|
|
24
|
+
interface CreateChatAuthTokenOptions<TTenantUser extends TenantUser = TenantUser, TTenant extends Tenant = Tenant> {
|
|
25
25
|
readonly apiKey: string;
|
|
26
26
|
readonly user: TTenantUser;
|
|
27
27
|
readonly tenant: TTenant;
|
|
28
28
|
readonly expiresInSeconds?: number | undefined;
|
|
29
29
|
}
|
|
30
|
-
interface CreateAstralBeamTokenRouteOptions<TSession extends object = object, TTenantUser extends TenantUser = TenantUser, TTenant extends Tenant = Tenant> {
|
|
31
|
-
/** The full API key, or a thunk read per request; missing or empty answers 503. */
|
|
32
|
-
readonly apiKey: string | undefined | (() => string | undefined);
|
|
33
|
-
/**
|
|
34
|
-
* Authenticates the request against the application's own session. Returning nothing, or
|
|
35
|
-
* throwing, answers 401.
|
|
36
|
-
*/
|
|
37
|
-
readonly authenticate: (request: Request) => TSession | null | undefined | Promise<TSession | null | undefined>;
|
|
38
|
-
/** Maps the authenticated session to the tenant user minted into the token. */
|
|
39
|
-
readonly user: (session: TSession) => TTenantUser;
|
|
40
|
-
/** Maps the same authenticated session to the tenant minted into the token. */
|
|
41
|
-
readonly tenant: (session: TSession) => TTenant;
|
|
42
|
-
readonly expiresInSeconds?: number | undefined;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Builds the fetch-standard `POST` handler for an application's token endpoint, owning the
|
|
46
|
-
* method check, the unconfigured-key 503, the unauthenticated 401, and the `no-store` header.
|
|
47
|
-
*/
|
|
48
|
-
declare function createAstralBeamTokenRoute<TSession extends object, TTenantUser extends TenantUser = TenantUser, TTenant extends Tenant = Tenant>(options: CreateAstralBeamTokenRouteOptions<TSession, TTenantUser, TTenant>): (request: Request) => Promise<Response>;
|
|
49
30
|
/** Creates the short-lived bearer token returned by an application's server auth endpoint. */
|
|
50
|
-
declare function
|
|
31
|
+
declare function createChatAuthToken<TTenantUser extends TenantUser = TenantUser, TTenant extends Tenant = Tenant>({
|
|
51
32
|
apiKey,
|
|
52
33
|
user,
|
|
53
34
|
tenant,
|
|
54
35
|
expiresInSeconds
|
|
55
|
-
}:
|
|
36
|
+
}: CreateChatAuthTokenOptions<TTenantUser, TTenant>): Promise<string>;
|
|
56
37
|
//#endregion
|
|
57
|
-
export {
|
|
38
|
+
export { CHAT_AUTH_TOKEN_AUDIENCE, CHAT_AUTH_TOKEN_LIFETIME_SECONDS, CHAT_AUTH_TOKEN_MAX_LIFETIME_SECONDS, CHAT_AUTH_TOKEN_TYPE, CHAT_AUTH_TOKEN_VERSION, CreateChatAuthTokenOptions, Tenant, TenantSchema, TenantUser, TenantUserSchema, createChatAuthToken };
|
package/dist/server.js
CHANGED
|
@@ -638,12 +638,12 @@ var SignJWT = class {
|
|
|
638
638
|
};
|
|
639
639
|
//#endregion
|
|
640
640
|
//#region src/server/index.ts
|
|
641
|
-
const
|
|
642
|
-
const
|
|
643
|
-
const
|
|
644
|
-
const
|
|
645
|
-
const
|
|
646
|
-
const
|
|
641
|
+
const CHAT_AUTH_TOKEN_AUDIENCE = "astralbeam";
|
|
642
|
+
const CHAT_AUTH_TOKEN_TYPE = "astralbeam+jwt";
|
|
643
|
+
const CHAT_AUTH_TOKEN_VERSION = 4;
|
|
644
|
+
const CHAT_AUTH_TOKEN_LIFETIME_SECONDS = 300;
|
|
645
|
+
const CHAT_AUTH_TOKEN_MAX_LIFETIME_SECONDS = 600;
|
|
646
|
+
const CHAT_AUTH_TOKEN_MAX_BYTES = 16384;
|
|
647
647
|
const IDENTITY_MAX_BYTES = 8192;
|
|
648
648
|
const textEncoder = new TextEncoder();
|
|
649
649
|
const SlugSchema = Schema.String.pipe(Schema.check(Schema.isPattern(/^[0-9a-z-]{1,63}$/)));
|
|
@@ -701,43 +701,9 @@ async function signingKey(secret) {
|
|
|
701
701
|
const digest = await crypto.subtle.digest("SHA-256", textEncoder.encode(secret));
|
|
702
702
|
return textEncoder.encode(encode(new Uint8Array(digest)));
|
|
703
703
|
}
|
|
704
|
-
function tokenRouteResponse(body, status) {
|
|
705
|
-
return Response.json(body, {
|
|
706
|
-
status,
|
|
707
|
-
headers: { "cache-control": "no-store" }
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
/**
|
|
711
|
-
* Builds the fetch-standard `POST` handler for an application's token endpoint, owning the
|
|
712
|
-
* method check, the unconfigured-key 503, the unauthenticated 401, and the `no-store` header.
|
|
713
|
-
*/
|
|
714
|
-
function createAstralBeamTokenRoute(options) {
|
|
715
|
-
return async (request) => {
|
|
716
|
-
if (request.method !== "POST") return tokenRouteResponse({ error: "Use POST" }, 405);
|
|
717
|
-
const apiKey = typeof options.apiKey === "function" ? options.apiKey() : options.apiKey;
|
|
718
|
-
if (!apiKey) return tokenRouteResponse({ error: "The AstralBeam API key is not configured" }, 503);
|
|
719
|
-
let session;
|
|
720
|
-
try {
|
|
721
|
-
session = await options.authenticate(request);
|
|
722
|
-
} catch {
|
|
723
|
-
session = void 0;
|
|
724
|
-
}
|
|
725
|
-
if (!session) return tokenRouteResponse({ error: "The session could not be verified" }, 401);
|
|
726
|
-
try {
|
|
727
|
-
return tokenRouteResponse({ token: await createAstralBeamChatToken({
|
|
728
|
-
apiKey,
|
|
729
|
-
user: options.user(session),
|
|
730
|
-
tenant: options.tenant(session),
|
|
731
|
-
...options.expiresInSeconds === void 0 ? {} : { expiresInSeconds: options.expiresInSeconds }
|
|
732
|
-
}) }, 200);
|
|
733
|
-
} catch {
|
|
734
|
-
return tokenRouteResponse({ error: "The chat token could not be created" }, 500);
|
|
735
|
-
}
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
704
|
/** Creates the short-lived bearer token returned by an application's server auth endpoint. */
|
|
739
|
-
async function
|
|
740
|
-
if (!Number.isInteger(expiresInSeconds) || expiresInSeconds < 60 || expiresInSeconds > 600) throw new Error("
|
|
705
|
+
async function createChatAuthToken({ apiKey, user, tenant, expiresInSeconds = 300 }) {
|
|
706
|
+
if (!Number.isInteger(expiresInSeconds) || expiresInSeconds < 60 || expiresInSeconds > 600) throw new Error("chat auth tokens must live for 60-600 seconds");
|
|
741
707
|
const { keyId, organizationSlug, keySecret } = parseApiKey(apiKey);
|
|
742
708
|
const identity = validatedIdentity(user, tenant);
|
|
743
709
|
const now = Math.floor(Date.now() / 1e3);
|
|
@@ -747,11 +713,11 @@ async function createAstralBeamChatToken({ apiKey, user, tenant, expiresInSecond
|
|
|
747
713
|
tenant: identity.tenant
|
|
748
714
|
}).setProtectedHeader({
|
|
749
715
|
alg: "HS256",
|
|
750
|
-
typ:
|
|
716
|
+
typ: CHAT_AUTH_TOKEN_TYPE,
|
|
751
717
|
kid: keyId
|
|
752
|
-
}).setIssuer(organizationSlug).setAudience(
|
|
753
|
-
if (textEncoder.encode(token).byteLength >
|
|
718
|
+
}).setIssuer(organizationSlug).setAudience(CHAT_AUTH_TOKEN_AUDIENCE).setIssuedAt(now).setExpirationTime(now + expiresInSeconds).sign(await signingKey(keySecret));
|
|
719
|
+
if (textEncoder.encode(token).byteLength > CHAT_AUTH_TOKEN_MAX_BYTES) throw new Error(`chat auth tokens must not exceed ${CHAT_AUTH_TOKEN_MAX_BYTES} bytes`);
|
|
754
720
|
return token;
|
|
755
721
|
}
|
|
756
722
|
//#endregion
|
|
757
|
-
export {
|
|
723
|
+
export { CHAT_AUTH_TOKEN_AUDIENCE, CHAT_AUTH_TOKEN_LIFETIME_SECONDS, CHAT_AUTH_TOKEN_MAX_LIFETIME_SECONDS, CHAT_AUTH_TOKEN_TYPE, CHAT_AUTH_TOKEN_VERSION, TenantSchema, TenantUserSchema, createChatAuthToken };
|