@astralbeam/sdk 0.10.1 → 0.12.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 +71 -46
- package/dist/{api-CaNIR6Af.js → api-DiwSihrG.js} +29 -2
- package/dist/api-ImuMGEar.d.ts +370 -0
- package/dist/api.d.ts +2 -333
- package/dist/api.js +2 -2
- package/dist/client.d.ts +93 -4
- package/dist/client.js +1 -1
- package/dist/constants-CgaMxV3q.js +1 -0
- package/dist/{core-Dr2IDA6j.js → core-DfA5fxd0.js} +286 -72
- package/dist/core.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/debug-qLts7gEt.js +1 -0
- package/dist/{index-BQBdZKyB.d.ts → index-B3y8nySY.d.ts} +12 -5
- package/dist/index-BVVgDSdq.d.ts +1 -0
- package/dist/listings-BQZUPClK.js +21 -0
- package/dist/react.d.ts +60 -4
- package/dist/react.js +112 -20
- package/dist/server.js +1 -116
- package/dist/styles.generated-D-Scd4Y1.js +60 -0
- package/dist/type_checks-C-WTHaWs.js +117 -0
- package/dist/widget-Dq9yzJIB.js +20 -0
- package/package.json +55 -40
- package/dist/debug-BSzSiibd.js +0 -1
- package/dist/widget-B6YT3G1i.js +0 -79
package/dist/react.js
CHANGED
|
@@ -1,9 +1,87 @@
|
|
|
1
|
-
import { n as CORE_OPTION_KEYS, r as createAstralBeamChat } from "./core-
|
|
2
|
-
import {
|
|
1
|
+
import { n as CORE_OPTION_KEYS, r as createAstralBeamChat } from "./core-DfA5fxd0.js";
|
|
2
|
+
import { M as DEFAULT_COLOR_SCHEME } from "./api-DiwSihrG.js";
|
|
3
3
|
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { defineTool, mountAstralBeamChat, mountAstralBeamTenantList, mountAstralBeamTenantUserList } from "@astralbeam/sdk/client";
|
|
4
6
|
import { createPortal } from "react-dom";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
//#region src/react/listings.tsx
|
|
8
|
+
const AstralBeamTenantList = forwardRef(function AstralBeamTenantList({ className, style, ...options }, ref) {
|
|
9
|
+
return /* @__PURE__ */ jsx("div", {
|
|
10
|
+
ref: useListingMount(mountAstralBeamTenantList, options, ref),
|
|
11
|
+
className,
|
|
12
|
+
style
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
const AstralBeamTenantUserList = forwardRef(function AstralBeamTenantUserList({ className, style, ...options }, ref) {
|
|
16
|
+
return /* @__PURE__ */ jsx("div", {
|
|
17
|
+
ref: useListingMount(mountAstralBeamTenantUserList, options, ref),
|
|
18
|
+
className,
|
|
19
|
+
style
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
function useListingMount(mount, options, ref) {
|
|
23
|
+
const target = useRef(null);
|
|
24
|
+
const handle = useRef(null);
|
|
25
|
+
const { apiUrl, fetchAstralBeamToken, scope, tenantId, tenantExternalId, showAdmin, pageSize, title, showHeader, customCss, colorScheme, theme, onError, onTenantChange, onTenantSelect, onTenantUserSelect } = options;
|
|
26
|
+
const live = useMemo(() => ({
|
|
27
|
+
apiUrl,
|
|
28
|
+
fetchAstralBeamToken,
|
|
29
|
+
scope,
|
|
30
|
+
tenantId,
|
|
31
|
+
tenantExternalId,
|
|
32
|
+
showAdmin,
|
|
33
|
+
pageSize,
|
|
34
|
+
title,
|
|
35
|
+
showHeader,
|
|
36
|
+
customCss,
|
|
37
|
+
colorScheme,
|
|
38
|
+
theme,
|
|
39
|
+
onError,
|
|
40
|
+
onTenantChange,
|
|
41
|
+
onTenantSelect,
|
|
42
|
+
onTenantUserSelect
|
|
43
|
+
}), [
|
|
44
|
+
apiUrl,
|
|
45
|
+
fetchAstralBeamToken,
|
|
46
|
+
scope,
|
|
47
|
+
tenantId,
|
|
48
|
+
tenantExternalId,
|
|
49
|
+
showAdmin,
|
|
50
|
+
pageSize,
|
|
51
|
+
title,
|
|
52
|
+
showHeader,
|
|
53
|
+
customCss,
|
|
54
|
+
colorScheme,
|
|
55
|
+
theme,
|
|
56
|
+
onError,
|
|
57
|
+
onTenantChange,
|
|
58
|
+
onTenantSelect,
|
|
59
|
+
onTenantUserSelect
|
|
60
|
+
]);
|
|
61
|
+
const liveRef = useRef(live);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
liveRef.current = live;
|
|
64
|
+
});
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
const mounted = mount(target.current, liveRef.current);
|
|
67
|
+
handle.current = mounted;
|
|
68
|
+
return () => {
|
|
69
|
+
handle.current = null;
|
|
70
|
+
mounted.unmount();
|
|
71
|
+
};
|
|
72
|
+
}, [mount]);
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
handle.current?.update(live);
|
|
75
|
+
}, [live]);
|
|
76
|
+
useImperativeHandle(ref, () => ({
|
|
77
|
+
update: (next) => handle.current?.update(next),
|
|
78
|
+
refresh: () => handle.current?.refresh(),
|
|
79
|
+
reset: () => handle.current?.reset(),
|
|
80
|
+
unmount: () => handle.current?.unmount()
|
|
81
|
+
}), []);
|
|
82
|
+
return target;
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
7
85
|
//#region src/react/index.tsx
|
|
8
86
|
/** Declares a host widget; a Standard Schema `parameters` types (and validates) `render`'s props. */
|
|
9
87
|
function defineWidget(widget) {
|
|
@@ -16,13 +94,19 @@ function defineWidget(widget) {
|
|
|
16
94
|
* state stay live and nothing needs a remount.
|
|
17
95
|
*/
|
|
18
96
|
function useAstralBeamChat(options) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const
|
|
97
|
+
const [core] = useState(() => createAstralBeamChat(options, true));
|
|
98
|
+
const watched = CORE_OPTION_KEYS.map((key) => options[key]);
|
|
99
|
+
const watchedRef = useRef(void 0);
|
|
22
100
|
useEffect(() => {
|
|
101
|
+
const previous = watchedRef.current;
|
|
102
|
+
watchedRef.current = watched;
|
|
103
|
+
if (previous?.every((value, index) => Object.is(value, watched[index]))) return;
|
|
23
104
|
core.updateOptions(options);
|
|
24
|
-
}
|
|
25
|
-
useEffect(() =>
|
|
105
|
+
});
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
core.start();
|
|
108
|
+
return () => core.dispose();
|
|
109
|
+
}, [core]);
|
|
26
110
|
return {
|
|
27
111
|
...useSyncExternalStore(core.subscribe, core.getState, core.getState),
|
|
28
112
|
sendMessage: core.sendMessage,
|
|
@@ -33,7 +117,7 @@ function useAstralBeamChat(options) {
|
|
|
33
117
|
core
|
|
34
118
|
};
|
|
35
119
|
}
|
|
36
|
-
const AstralBeamChat = forwardRef(function AstralBeamChat({ agentId, title, showHeader, header, empty, composerActions, emptyTitle, emptyDescription, apiUrl, fetchAstralBeamToken, tools, widgets = {}, colorScheme = DEFAULT_COLOR_SCHEME, theme, attachments, sandboxPanel, debug }, ref) {
|
|
120
|
+
const AstralBeamChat = forwardRef(function AstralBeamChat({ agentId, title, showHeader, header, empty, composerActions, emptyTitle, emptyDescription, apiUrl, fetchAstralBeamToken, tools, widgets = {}, colorScheme = DEFAULT_COLOR_SCHEME, theme, customCss, attachments, sandboxPanel, debug }, ref) {
|
|
37
121
|
const targetRef = useRef(null);
|
|
38
122
|
const handleRef = useRef(null);
|
|
39
123
|
const [activeRenders, setActiveRenders] = useState(/* @__PURE__ */ new Map());
|
|
@@ -46,14 +130,18 @@ const AstralBeamChat = forwardRef(function AstralBeamChat({ agentId, title, show
|
|
|
46
130
|
toolsRef.current = tools;
|
|
47
131
|
});
|
|
48
132
|
const nextRenderKey = useRef(0);
|
|
49
|
-
const hostTools = useMemo(() =>
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
133
|
+
const hostTools = useMemo(() => {
|
|
134
|
+
const adapted = {};
|
|
135
|
+
for (const [name, definition] of Object.entries(tools ?? {})) adapted[name] = {
|
|
136
|
+
...definition,
|
|
137
|
+
execute: (input) => {
|
|
138
|
+
const current = toolsRef.current?.[name];
|
|
139
|
+
if (!current) throw new Error(`Tool "${name}" is no longer registered`);
|
|
140
|
+
return current.execute(input);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
return adapted;
|
|
144
|
+
}, [tools]);
|
|
57
145
|
const hostWidgets = useMemo(() => Object.fromEntries(Object.entries(widgets).map(([name, definition]) => [name, {
|
|
58
146
|
...definition,
|
|
59
147
|
render: (props, container) => {
|
|
@@ -107,6 +195,7 @@ const AstralBeamChat = forwardRef(function AstralBeamChat({ agentId, title, show
|
|
|
107
195
|
emptyDescription,
|
|
108
196
|
colorScheme,
|
|
109
197
|
theme,
|
|
198
|
+
customCss,
|
|
110
199
|
attachments,
|
|
111
200
|
sandboxPanel,
|
|
112
201
|
debug,
|
|
@@ -123,6 +212,7 @@ const AstralBeamChat = forwardRef(function AstralBeamChat({ agentId, title, show
|
|
|
123
212
|
emptyDescription,
|
|
124
213
|
colorScheme,
|
|
125
214
|
theme,
|
|
215
|
+
customCss,
|
|
126
216
|
attachments,
|
|
127
217
|
sandboxPanel,
|
|
128
218
|
debug,
|
|
@@ -131,7 +221,9 @@ const AstralBeamChat = forwardRef(function AstralBeamChat({ agentId, title, show
|
|
|
131
221
|
chromeSlots
|
|
132
222
|
]);
|
|
133
223
|
const liveRef = useRef(live);
|
|
134
|
-
|
|
224
|
+
useEffect(() => {
|
|
225
|
+
liveRef.current = live;
|
|
226
|
+
});
|
|
135
227
|
useEffect(() => {
|
|
136
228
|
if (!targetRef.current) return;
|
|
137
229
|
const handle = mountAstralBeamChat(targetRef.current, liveRef.current);
|
|
@@ -159,4 +251,4 @@ const AstralBeamChat = forwardRef(function AstralBeamChat({ agentId, title, show
|
|
|
159
251
|
});
|
|
160
252
|
});
|
|
161
253
|
//#endregion
|
|
162
|
-
export { AstralBeamChat, defineTool, defineWidget, useAstralBeamChat };
|
|
254
|
+
export { AstralBeamChat, AstralBeamTenantList, AstralBeamTenantUserList, defineTool, defineWidget, useAstralBeamChat };
|
package/dist/server.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const encoder = new TextEncoder();
|
|
3
|
-
const decoder = new TextDecoder();
|
|
4
|
-
new TextDecoder("utf-8", { fatal: true });
|
|
5
|
-
function concat(...buffers) {
|
|
6
|
-
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
7
|
-
const buf = new Uint8Array(size);
|
|
8
|
-
let i = 0;
|
|
9
|
-
for (const buffer of buffers) {
|
|
10
|
-
buf.set(buffer, i);
|
|
11
|
-
i += buffer.length;
|
|
12
|
-
}
|
|
13
|
-
return buf;
|
|
14
|
-
}
|
|
15
|
-
function encode$1(string) {
|
|
16
|
-
const bytes = new Uint8Array(string.length);
|
|
17
|
-
for (let i = 0; i < string.length; i++) {
|
|
18
|
-
const code = string.charCodeAt(i);
|
|
19
|
-
if (code > 127) throw new TypeError("non-ASCII string encountered in encode()");
|
|
20
|
-
bytes[i] = code;
|
|
21
|
-
}
|
|
22
|
-
return bytes;
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
1
|
+
import { a as isPublicJWK, c as encode, d as JWTInvalid, f as concat, i as isPrivateJWK, l as JOSENotSupported, m as encoder, n as isJWK, o as isSecretJWK, p as encode$1, r as isObject, s as decode, t as isDisjoint, u as JWSInvalid } from "./type_checks-C-WTHaWs.js";
|
|
25
2
|
//#region node_modules/.deno/jose@6.2.9/node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
26
3
|
const unusable = (name, prop = "algorithm.name") => /* @__PURE__ */ new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
27
4
|
function checkUsage(key, usage) {
|
|
@@ -56,29 +33,6 @@ function message(msg, actual, ...types) {
|
|
|
56
33
|
}
|
|
57
34
|
const withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
58
35
|
//#endregion
|
|
59
|
-
//#region node_modules/.deno/jose@6.2.9/node_modules/jose/dist/webapi/util/errors.js
|
|
60
|
-
var JOSEError = class extends Error {
|
|
61
|
-
static code = "ERR_JOSE_GENERIC";
|
|
62
|
-
code = "ERR_JOSE_GENERIC";
|
|
63
|
-
constructor(message, options) {
|
|
64
|
-
super(message, options);
|
|
65
|
-
this.name = this.constructor.name;
|
|
66
|
-
Error.captureStackTrace?.(this, this.constructor);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
var JOSENotSupported = class extends JOSEError {
|
|
70
|
-
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
71
|
-
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
72
|
-
};
|
|
73
|
-
var JWSInvalid = class extends JOSEError {
|
|
74
|
-
static code = "ERR_JWS_INVALID";
|
|
75
|
-
code = "ERR_JWS_INVALID";
|
|
76
|
-
};
|
|
77
|
-
var JWTInvalid = class extends JOSEError {
|
|
78
|
-
static code = "ERR_JWT_INVALID";
|
|
79
|
-
code = "ERR_JWT_INVALID";
|
|
80
|
-
};
|
|
81
|
-
//#endregion
|
|
82
36
|
//#region node_modules/.deno/jose@6.2.9/node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
83
37
|
const isCryptoKey = (key) => {
|
|
84
38
|
if (key?.[Symbol.toStringTag] === "CryptoKey") return true;
|
|
@@ -91,75 +45,6 @@ const isCryptoKey = (key) => {
|
|
|
91
45
|
const isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
92
46
|
const isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
93
47
|
//#endregion
|
|
94
|
-
//#region node_modules/.deno/jose@6.2.9/node_modules/jose/dist/webapi/lib/base64.js
|
|
95
|
-
function encodeBase64(input) {
|
|
96
|
-
if (Uint8Array.prototype.toBase64) return input.toBase64();
|
|
97
|
-
const CHUNK_SIZE = 32768;
|
|
98
|
-
const arr = [];
|
|
99
|
-
for (let i = 0; i < input.length; i += CHUNK_SIZE) arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
100
|
-
return btoa(arr.join(""));
|
|
101
|
-
}
|
|
102
|
-
function decodeBase64(encoded) {
|
|
103
|
-
if (Uint8Array.fromBase64) return Uint8Array.fromBase64(encoded);
|
|
104
|
-
const binary = atob(encoded);
|
|
105
|
-
const bytes = new Uint8Array(binary.length);
|
|
106
|
-
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
107
|
-
return bytes;
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
110
|
-
//#region node_modules/.deno/jose@6.2.9/node_modules/jose/dist/webapi/util/base64url.js
|
|
111
|
-
const invalid = "The input to be decoded is not correctly encoded.";
|
|
112
|
-
function decode(input) {
|
|
113
|
-
if (Uint8Array.fromBase64) try {
|
|
114
|
-
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), { alphabet: "base64url" });
|
|
115
|
-
} catch (cause) {
|
|
116
|
-
throw new TypeError(invalid, { cause });
|
|
117
|
-
}
|
|
118
|
-
let encoded = input;
|
|
119
|
-
if (encoded instanceof Uint8Array) encoded = decoder.decode(encoded);
|
|
120
|
-
if (encoded.includes("+") || encoded.includes("/")) throw new TypeError(invalid);
|
|
121
|
-
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
122
|
-
try {
|
|
123
|
-
return decodeBase64(encoded);
|
|
124
|
-
} catch {
|
|
125
|
-
throw new TypeError(invalid);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function encode(input) {
|
|
129
|
-
let unencoded = input;
|
|
130
|
-
if (typeof unencoded === "string") unencoded = encoder.encode(unencoded);
|
|
131
|
-
if (Uint8Array.prototype.toBase64) return unencoded.toBase64({
|
|
132
|
-
alphabet: "base64url",
|
|
133
|
-
omitPadding: true
|
|
134
|
-
});
|
|
135
|
-
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
136
|
-
}
|
|
137
|
-
//#endregion
|
|
138
|
-
//#region node_modules/.deno/jose@6.2.9/node_modules/jose/dist/webapi/lib/type_checks.js
|
|
139
|
-
function isObject(input) {
|
|
140
|
-
if (typeof input !== "object" || input === null || Object.prototype.toString.call(input) !== "[object Object]") return false;
|
|
141
|
-
const prototype = Object.getPrototypeOf(input);
|
|
142
|
-
if (prototype === null) return true;
|
|
143
|
-
let proto = prototype;
|
|
144
|
-
while (Object.getPrototypeOf(proto) !== null) proto = Object.getPrototypeOf(proto);
|
|
145
|
-
return prototype === proto;
|
|
146
|
-
}
|
|
147
|
-
function isDisjoint(...headers) {
|
|
148
|
-
const parameters = /* @__PURE__ */ new Set();
|
|
149
|
-
for (const header of headers) {
|
|
150
|
-
if (!header) continue;
|
|
151
|
-
for (const parameter of Object.keys(header)) {
|
|
152
|
-
if (parameters.has(parameter)) return false;
|
|
153
|
-
parameters.add(parameter);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
const isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
159
|
-
const isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
160
|
-
const isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
|
|
161
|
-
const isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
162
|
-
//#endregion
|
|
163
48
|
//#region node_modules/.deno/jose@6.2.9/node_modules/jose/dist/webapi/lib/helpers.js
|
|
164
49
|
function assertNotSet(value, name) {
|
|
165
50
|
if (value) throw new TypeError(`${name} can only be called once`);
|