@astralbeam/sdk 0.9.0 → 0.11.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.
@@ -0,0 +1,309 @@
1
+ //#region src/lib/constants.ts
2
+ /** Base URL of the AstralBeam API when the mount options give none; versioned routes hang off it. */
3
+ const DEFAULT_API_URL = "https://app.astralbeam.ai/api";
4
+ /** Host endpoint that mints chat JWTs when the mount options give none. */
5
+ const DEFAULT_CHAT_AUTH_TOKEN_URL = "/api/astralbeam/token";
6
+ /** Color scheme used when the mount options and the React prop give none. */
7
+ const DEFAULT_COLOR_SCHEME = "system";
8
+ //#endregion
9
+ //#region src/api/api.ts
10
+ function isAstralBeamApiError(error) {
11
+ return error instanceof Error && error.name === "AstralBeamApiError" && "status" in error && typeof error.status === "number";
12
+ }
13
+ function resolveApiUrl(path, apiUrl = DEFAULT_API_URL) {
14
+ return `${apiUrl.replace(/\/+$/, "")}${path.replace(/^\/api(?=\/)/, "")}`;
15
+ }
16
+ function isApiErrorBody(value, status) {
17
+ if (!value || typeof value !== "object") return false;
18
+ const body = value;
19
+ return body.status === status && typeof body.type === "string" && typeof body.title === "string" && typeof body.detail === "string" && (body.issues === void 0 || Array.isArray(body.issues) && body.issues.every((issue) => issue && typeof issue.path === "string" && typeof issue.message === "string"));
20
+ }
21
+ async function apiResponse(path, options) {
22
+ const { apiUrl, apiKey, astralBeamToken, fetchClient = globalThis.fetch, ...init } = options;
23
+ const headers = new Headers();
24
+ const entries = init.headers instanceof Headers ? init.headers.entries() : Array.isArray(init.headers) ? init.headers : Object.entries(init.headers ?? {});
25
+ for (const [name, value] of entries) headers.set(name, value);
26
+ headers.delete("authorization");
27
+ headers.delete("x-api-key");
28
+ if (apiKey) headers.set("x-api-key", apiKey);
29
+ if (astralBeamToken) headers.set("authorization", `Bearer ${astralBeamToken}`);
30
+ const response = await fetchClient(resolveApiUrl(path, apiUrl), {
31
+ ...init,
32
+ headers
33
+ });
34
+ if (response.ok) return response;
35
+ const value = await response.json().catch((error) => {
36
+ if (!(error instanceof SyntaxError)) throw error;
37
+ });
38
+ const body = isApiErrorBody(value, response.status) ? value : void 0;
39
+ throw Object.assign(new Error(body?.detail ?? `AstralBeam API returned HTTP ${response.status}`), {
40
+ name: "AstralBeamApiError",
41
+ status: response.status,
42
+ headers: response.headers,
43
+ body
44
+ });
45
+ }
46
+ async function astralBeamApiFetch(path, options) {
47
+ return await (await apiResponse(path, options)).json();
48
+ }
49
+ function astralBeamJwtFetch(path, options) {
50
+ return astralBeamApiFetch(path, options);
51
+ }
52
+ function astralBeamChatFetch(path, options) {
53
+ return apiResponse(path, options);
54
+ }
55
+ function astralBeamFileFetch(path, options = {}) {
56
+ return apiResponse(path, options);
57
+ }
58
+ //#endregion
59
+ //#region src/api/generated/api.ts
60
+ /**
61
+ * Generated by Orval. Do not edit by hand.
62
+ */
63
+ const ListUsersForTenantFilterAdmin = {
64
+ true: "true",
65
+ false: "false"
66
+ };
67
+ const getListTenantsUrl = (params) => {
68
+ const normalizedParams = new URLSearchParams();
69
+ Object.entries(params || {}).forEach(([key, value]) => {
70
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
71
+ });
72
+ const stringifiedParams = normalizedParams.toString();
73
+ return stringifiedParams.length > 0 ? `/api/v1/tenants?${stringifiedParams}` : `/api/v1/tenants`;
74
+ };
75
+ /**
76
+ * List Tenants in internal ID order. q searches name or external ID as a case-insensitive literal substring. filter[external_id] adds an exact match. Organization keys and organization-management JWTs see their organization; admin tenant JWTs see only their signed Tenant. Keep filters unchanged when reusing cursors. Live listing, not a snapshot.
77
+ * @summary List Tenants
78
+ */
79
+ const listTenants = (params, options) => {
80
+ return astralBeamApiFetch(getListTenantsUrl(params), {
81
+ ...options,
82
+ method: "GET"
83
+ });
84
+ };
85
+ const getCreateTenantUrl = () => {
86
+ return `/api/v1/tenants`;
87
+ };
88
+ /**
89
+ * Create a Tenant with an exact customer-provided external_id. Requires an organization API key or organization-management JWT with a current owner/developer role. An external_id already used in this organization returns 409; creation never upserts.
90
+ * @summary Create a Tenant
91
+ */
92
+ const createTenant = (createTenantInput, options) => {
93
+ const getHeaders = (h) => {
94
+ if (!h) return {};
95
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
96
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
97
+ const headers = {};
98
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
99
+ return headers;
100
+ };
101
+ return astralBeamApiFetch(getCreateTenantUrl(), {
102
+ ...options,
103
+ method: "POST",
104
+ headers: {
105
+ "Content-Type": "application/json",
106
+ ...getHeaders(options?.headers)
107
+ },
108
+ body: JSON.stringify(createTenantInput)
109
+ });
110
+ };
111
+ const getGetTenantUrl = (id) => {
112
+ return `/api/v1/tenants/${encodeURIComponent(String(id))}`;
113
+ };
114
+ /**
115
+ * Get a Tenant by internal UUID, not external_id.
116
+ * @summary Get a Tenant
117
+ */
118
+ const getTenant = (id, options) => {
119
+ return astralBeamApiFetch(getGetTenantUrl(id), {
120
+ ...options,
121
+ method: "GET"
122
+ });
123
+ };
124
+ const getUpdateTenantUrl = (id) => {
125
+ return `/api/v1/tenants/${encodeURIComponent(String(id))}`;
126
+ };
127
+ /**
128
+ * Update supplied name/metadata fields only. Requires an organization API key or organization-management JWT with a current owner/developer role. name:null clears the name; metadata replaces the object. Last-write-wins; no upsert.
129
+ * @summary Update a Tenant
130
+ */
131
+ const updateTenant = (id, updateTenantInput, options) => {
132
+ const getHeaders = (h) => {
133
+ if (!h) return {};
134
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
135
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
136
+ const headers = {};
137
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
138
+ return headers;
139
+ };
140
+ return astralBeamApiFetch(getUpdateTenantUrl(id), {
141
+ ...options,
142
+ method: "PATCH",
143
+ headers: {
144
+ "Content-Type": "application/json",
145
+ ...getHeaders(options?.headers)
146
+ },
147
+ body: JSON.stringify(updateTenantInput)
148
+ });
149
+ };
150
+ const getListUsersForTenantUrl = (tenantId, params) => {
151
+ const normalizedParams = new URLSearchParams();
152
+ Object.entries(params || {}).forEach(([key, value]) => {
153
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
154
+ });
155
+ const stringifiedParams = normalizedParams.toString();
156
+ return stringifiedParams.length > 0 ? `/api/v1/tenants/${encodeURIComponent(String(tenantId))}/tenant_users?${stringifiedParams}` : `/api/v1/tenants/${encodeURIComponent(String(tenantId))}/tenant_users`;
157
+ };
158
+ /**
159
+ * List users of one Tenant in internal ID order. q searches name or external ID as a case-insensitive literal substring. Exact filter[external_id] and filter[admin] combine with AND. No matching user returns an empty page; missing and out-of-scope Tenants return 404. Cursors cannot be reused for another Tenant or filter. Live listing, not a snapshot.
160
+ * @summary List TenantUsers
161
+ */
162
+ const listUsersForTenant = (tenantId, params, options) => {
163
+ return astralBeamApiFetch(getListUsersForTenantUrl(tenantId, params), {
164
+ ...options,
165
+ method: "GET"
166
+ });
167
+ };
168
+ const getCreateTenantUserUrl = (tenantId) => {
169
+ return `/api/v1/tenants/${encodeURIComponent(String(tenantId))}/tenant_users`;
170
+ };
171
+ /**
172
+ * Create a TenantUser under the internal tenant_id path identifier, with a customer-provided tenant-local external_id. An external_id already used in this Tenant returns 409; the same external_id in another Tenant is allowed. Stored admin does not change signed JWT authority.
173
+ * @summary Create a TenantUser
174
+ */
175
+ const createTenantUser = (tenantId, createTenantUserInput, options) => {
176
+ const getHeaders = (h) => {
177
+ if (!h) return {};
178
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
179
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
180
+ const headers = {};
181
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
182
+ return headers;
183
+ };
184
+ return astralBeamApiFetch(getCreateTenantUserUrl(tenantId), {
185
+ ...options,
186
+ method: "POST",
187
+ headers: {
188
+ "Content-Type": "application/json",
189
+ ...getHeaders(options?.headers)
190
+ },
191
+ body: JSON.stringify(createTenantUserInput)
192
+ });
193
+ };
194
+ const getGetTenantUserUrl = (tenantId, id) => {
195
+ return `/api/v1/tenants/${encodeURIComponent(String(tenantId))}/tenant_users/${encodeURIComponent(String(id))}`;
196
+ };
197
+ /**
198
+ * Get a TenantUser by the internal tenant_id and id pair within the authorized scope. No identity upsert.
199
+ * @summary Get a TenantUser
200
+ */
201
+ const getTenantUser = (tenantId, id, options) => {
202
+ return astralBeamApiFetch(getGetTenantUserUrl(tenantId, id), {
203
+ ...options,
204
+ method: "GET"
205
+ });
206
+ };
207
+ const getUpdateTenantUserUrl = (tenantId, id) => {
208
+ return `/api/v1/tenants/${encodeURIComponent(String(tenantId))}/tenant_users/${encodeURIComponent(String(id))}`;
209
+ };
210
+ /**
211
+ * Update supplied name/metadata/admin fields only. Stored admin does not grant or revoke JWT authority. name:null clears the name; metadata replaces the object.
212
+ * @summary Update a TenantUser
213
+ */
214
+ const updateTenantUser = (tenantId, id, updateTenantUserInput, options) => {
215
+ const getHeaders = (h) => {
216
+ if (!h) return {};
217
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
218
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
219
+ const headers = {};
220
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
221
+ return headers;
222
+ };
223
+ return astralBeamApiFetch(getUpdateTenantUserUrl(tenantId, id), {
224
+ ...options,
225
+ method: "PATCH",
226
+ headers: {
227
+ "Content-Type": "application/json",
228
+ ...getHeaders(options?.headers)
229
+ },
230
+ body: JSON.stringify(updateTenantUserInput)
231
+ });
232
+ };
233
+ const getRunChatUrl = () => {
234
+ return `/api/v1/chat`;
235
+ };
236
+ /**
237
+ * Stream an AG-UI agent run using a tenant user JWT. No admin claim required. HTTP failures before streaming use AstralBeamApiError. Once streaming starts, failures use RUN_ERROR events. Tool results continue in a subsequent request. Disconnecting cancels the run. Limited to 20 requests per minute per organization, tenant, and user.
238
+ * @summary Run chat
239
+ */
240
+ const runChat = (chatRunInput, options) => {
241
+ const getHeaders = (h) => {
242
+ if (!h) return {};
243
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
244
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
245
+ const headers = {};
246
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
247
+ return headers;
248
+ };
249
+ return astralBeamChatFetch(getRunChatUrl(), {
250
+ ...options,
251
+ method: "POST",
252
+ headers: {
253
+ "Content-Type": "application/json",
254
+ ...getHeaders(options?.headers)
255
+ },
256
+ body: JSON.stringify(chatRunInput)
257
+ });
258
+ };
259
+ const getGetChatConfigUrl = (params) => {
260
+ const normalizedParams = new URLSearchParams();
261
+ Object.entries(params || {}).forEach(([key, value]) => {
262
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
263
+ });
264
+ const stringifiedParams = normalizedParams.toString();
265
+ return stringifiedParams.length > 0 ? `/api/v1/chat/config?${stringifiedParams}` : `/api/v1/chat/config`;
266
+ };
267
+ /**
268
+ * Read the selected agent's attachment grant using a tenant user JWT. Omit agentId to use the organization's default agent. Client settings may narrow this grant, never widen it.
269
+ * @summary Get chat capabilities
270
+ */
271
+ const getChatConfig = (params, options) => {
272
+ return astralBeamJwtFetch(getGetChatConfigUrl(params), {
273
+ ...options,
274
+ method: "GET"
275
+ });
276
+ };
277
+ const getGetChatFileUrl = (params) => {
278
+ const normalizedParams = new URLSearchParams();
279
+ Object.entries(params || {}).forEach(([key, value]) => {
280
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
281
+ });
282
+ const stringifiedParams = normalizedParams.toString();
283
+ return stringifiedParams.length > 0 ? `/api/v1/chat/files?${stringifiedParams}` : `/api/v1/chat/files`;
284
+ };
285
+ /**
286
+ * Use the signed ticket returned when chat publishes an artifact. No bearer token is required. Returns the original bytes with a content-sniffed Content-Type and Content-Disposition filename. Invalid or expired tickets, a missing sandbox, and rejected artifact checks return 404. Provider or file-read failures return 500.
287
+ * @summary Download a chat artifact
288
+ */
289
+ const getChatFile = (params, options) => {
290
+ return astralBeamFileFetch(getGetChatFileUrl(params), {
291
+ ...options,
292
+ method: "GET"
293
+ });
294
+ };
295
+ const getGetCurrentUserUrl = () => {
296
+ return `/api/v1/me`;
297
+ };
298
+ /**
299
+ * Use a tenant JWT to upsert its own Tenant and TenantUser atomically, without requiring admin authority. Supplied names and metadata replace stored values, omitted profile fields and admin are preserved, and an explicit admin claim updates stored admin. An organization JWT returns existing user membership and the current database role without provisioning identities. API keys and cookies are not accepted. Limited to 100 requests per five minutes per identity.
300
+ * @summary Get the current user
301
+ */
302
+ const getCurrentUser = (options) => {
303
+ return astralBeamJwtFetch(getGetCurrentUserUrl(), {
304
+ ...options,
305
+ method: "POST"
306
+ });
307
+ };
308
+ //#endregion
309
+ export { DEFAULT_COLOR_SCHEME as A, runChat as C, isAstralBeamApiError as D, astralBeamChatFetch as E, resolveApiUrl as O, listUsersForTenant as S, updateTenantUser as T, getTenant as _, getChatFile as a, getUpdateTenantUserUrl as b, getCurrentUser as c, getGetCurrentUserUrl as d, getGetTenantUrl as f, getRunChatUrl as g, getListUsersForTenantUrl as h, getChatConfig as i, DEFAULT_CHAT_AUTH_TOKEN_URL as k, getGetChatConfigUrl as l, getListTenantsUrl as m, createTenant as n, getCreateTenantUrl as o, getGetTenantUserUrl as p, createTenantUser as r, getCreateTenantUserUrl as s, ListUsersForTenantFilterAdmin as t, getGetChatFileUrl as u, getTenantUser as v, updateTenant as w, listTenants as x, getUpdateTenantUrl as y };
package/dist/api.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { $ as ApiOptions, A as getChatConfig, B as getListTenantsUrl, C as TenantUserRecordEncodedMetadata, D as UpdateTenantUserInputMetadata, E as UpdateTenantUserInput, F as getGetChatConfigUrl, G as getUpdateTenantUrl, H as getRunChatUrl, I as getGetChatFileUrl, J as listUsersForTenant, K as getUpdateTenantUserUrl, L as getGetCurrentUserUrl, M as getCreateTenantUrl, N as getCreateTenantUserUrl, O as createTenant, P as getCurrentUser, Q as ApiKeyOptions, R as getGetTenantUrl, S as TenantUserRecordEncoded, T as UpdateTenantInputMetadata, U as getTenant, V as getListUsersForTenantUrl, W as getTenantUser, X as updateTenant, Y as runChat, Z as updateTenantUser, _ as ListUsersForTenantParams, a as ChatRunInput, b as TenantRecordEncodedMetadata, c as CreateTenantInput, d as CreateTenantUserInputMetadata, et as ApiRequestOptions, f as CurrentUser, g as ListUsersForTenantFilterAdmin, h as ListTenantsParams, i as ChatConfigurationCapabilities, it as isAstralBeamApiError, j as getChatFile, k as createTenantUser, l as CreateTenantInputMetadata, m as GetChatFileParams, n as AstralBeamApiErrorIssuesItem, nt as FileOptions, o as ChatRunInputData, p as GetChatConfigParams, q as listTenants, r as ChatConfiguration, rt as JwtOptions, s as ChatRunInputForwardedProps, t as AstralBeamApiError$1, tt as AstralBeamApiError, u as CreateTenantUserInput, v as TenantPage, w as UpdateTenantInput, x as TenantUserPage, y as TenantRecordEncoded, z as getGetTenantUserUrl } from "./api-CWgQSDaI.js";
2
+ export { type ApiKeyOptions, type ApiOptions, type ApiRequestOptions, AstralBeamApiError, type AstralBeamApiError$1 as AstralBeamApiErrorBody, AstralBeamApiErrorIssuesItem, ChatConfiguration, ChatConfigurationCapabilities, ChatRunInput, ChatRunInputData, ChatRunInputForwardedProps, CreateTenantInput, CreateTenantInputMetadata, CreateTenantUserInput, CreateTenantUserInputMetadata, CurrentUser, type FileOptions, GetChatConfigParams, GetChatFileParams, type JwtOptions, ListTenantsParams, ListUsersForTenantFilterAdmin, ListUsersForTenantParams, TenantPage, TenantRecordEncoded, TenantRecordEncodedMetadata, TenantUserPage, TenantUserRecordEncoded, TenantUserRecordEncodedMetadata, UpdateTenantInput, UpdateTenantInputMetadata, UpdateTenantUserInput, UpdateTenantUserInputMetadata, createTenant, createTenantUser, getChatConfig, getChatFile, getCreateTenantUrl, getCreateTenantUserUrl, getCurrentUser, getGetChatConfigUrl, getGetChatFileUrl, getGetCurrentUserUrl, getGetTenantUrl, getGetTenantUserUrl, getListTenantsUrl, getListUsersForTenantUrl, getRunChatUrl, getTenant, getTenantUser, getUpdateTenantUrl, getUpdateTenantUserUrl, isAstralBeamApiError, listTenants, listUsersForTenant, runChat, updateTenant, updateTenantUser };
package/dist/api.js ADDED
@@ -0,0 +1,2 @@
1
+ import { C as runChat, D as isAstralBeamApiError, S as listUsersForTenant, T as updateTenantUser, _ as getTenant, a as getChatFile, b as getUpdateTenantUserUrl, c as getCurrentUser, d as getGetCurrentUserUrl, f as getGetTenantUrl, g as getRunChatUrl, h as getListUsersForTenantUrl, i as getChatConfig, l as getGetChatConfigUrl, m as getListTenantsUrl, n as createTenant, o as getCreateTenantUrl, p as getGetTenantUserUrl, r as createTenantUser, s as getCreateTenantUserUrl, t as ListUsersForTenantFilterAdmin, u as getGetChatFileUrl, v as getTenantUser, w as updateTenant, x as listTenants, y as getUpdateTenantUrl } from "./api-DrKgAIBT.js";
2
+ export { ListUsersForTenantFilterAdmin, createTenant, createTenantUser, getChatConfig, getChatFile, getCreateTenantUrl, getCreateTenantUserUrl, getCurrentUser, getGetChatConfigUrl, getGetChatFileUrl, getGetCurrentUserUrl, getGetTenantUrl, getGetTenantUserUrl, getListTenantsUrl, getListUsersForTenantUrl, getRunChatUrl, getTenant, getTenantUser, getUpdateTenantUrl, getUpdateTenantUserUrl, isAstralBeamApiError, listTenants, listUsersForTenant, runChat, updateTenant, updateTenantUser };
package/dist/client.d.ts CHANGED
@@ -14,7 +14,7 @@ interface StandardSchemaV1<Input = unknown, Output = Input> {
14
14
  * Input type `defineTool`/`defineWidget` derive from a `parameters` schema: a Standard Schema's
15
15
  * validated output, or untyped props for a plain JSON Schema, which nothing validates in the browser.
16
16
  */
17
- type InferParameters<S extends ParametersSchema> = S extends StandardSchemaV1<any, infer O> ? O : Record<string, unknown>;
17
+ type InferParameters<S extends ParametersSchema> = S extends StandardSchemaV1<unknown, infer O> ? O : Record<string, unknown>;
18
18
  /** A plain JSON Schema object, the same shape tool definitions use for their parameters. */
19
19
  interface JsonSchemaObject {
20
20
  type: "object";
@@ -55,7 +55,7 @@ interface ToolDefinition {
55
55
  * Runs in the host page with the agent-chosen input. The resolved value is returned
56
56
  * to the agent as the tool result; a thrown error is returned as a tool error.
57
57
  */
58
- execute: (input: Record<string, unknown>) => unknown | Promise<unknown>;
58
+ execute: (input: Record<string, unknown>) => unknown;
59
59
  }
60
60
  /**
61
61
  * Limits and accepted types for the composer's file attachments. Every field is optional;
@@ -187,6 +187,8 @@ interface MountAstralBeamChatOptions {
187
187
  colorScheme?: AstralBeamChatColorScheme | undefined;
188
188
  /** Custom values for the widget's theming CSS variables, per color scheme. */
189
189
  theme?: AstralBeamChatTheme | undefined;
190
+ /** Trusted application CSS, scoped to this widget's shadow root. */
191
+ customCss?: string | undefined;
190
192
  /**
191
193
  * Logs every SDK action to the browser console with UTC timestamps and full payloads,
192
194
  * and asks the endpoint (via the forwarded props) to log its side of the run too.
@@ -217,7 +219,7 @@ interface TypedToolDefinition<S extends ParametersSchema = JsonSchemaObject> {
217
219
  description: string;
218
220
  metadata?: Record<string, unknown> | undefined;
219
221
  parameters?: S;
220
- execute: (input: InferParameters<S>) => unknown | Promise<unknown>;
222
+ execute: (input: InferParameters<S>) => unknown;
221
223
  }
222
224
  interface TypedWidgetDefinition<S extends ParametersSchema = JsonSchemaObject> {
223
225
  description: string;
@@ -229,7 +231,94 @@ declare function defineTool<const S extends ParametersSchema = JsonSchemaObject>
229
231
  /** Declares a host widget; a Standard Schema `parameters` types (and validates) `render`'s props. */
230
232
  declare function defineWidget<const S extends ParametersSchema = JsonSchemaObject>(widget: TypedWidgetDefinition<S>): WidgetDefinition;
231
233
  //#endregion
234
+ //#region src/api/generated/api.d.ts
235
+ /**
236
+ * Customer-defined JSON object; keys are preserved.
237
+ */
238
+ type TenantRecordEncodedMetadata = {
239
+ [key: string]: unknown;
240
+ };
241
+ /**
242
+ * Persisted Tenant; id is internal, external_id is the customer's exact identity.
243
+ */
244
+ interface TenantRecordEncoded {
245
+ id: string;
246
+ external_id: string;
247
+ name: string | null;
248
+ /** Customer-defined JSON object; keys are preserved. */
249
+ metadata: TenantRecordEncodedMetadata;
250
+ created_at: string;
251
+ updated_at: string;
252
+ }
253
+ /**
254
+ * Customer-defined JSON object; keys are preserved.
255
+ */
256
+ type TenantUserRecordEncodedMetadata = {
257
+ [key: string]: unknown;
258
+ };
259
+ /**
260
+ * Persisted TenantUser. Stored admin does not grant or revoke signed JWT authority.
261
+ */
262
+ interface TenantUserRecordEncoded {
263
+ id: string;
264
+ external_id: string;
265
+ name: string | null;
266
+ /** Customer-defined JSON object; keys are preserved. */
267
+ metadata: TenantUserRecordEncodedMetadata;
268
+ created_at: string;
269
+ updated_at: string;
270
+ tenant_id: string;
271
+ admin: boolean;
272
+ }
273
+ //#endregion
274
+ //#region src/core/listings.d.ts
275
+ interface AstralBeamListingCoreOptions {
276
+ apiUrl?: string | undefined;
277
+ fetchAstralBeamToken?: AstralBeamTokenSource | undefined;
278
+ /** Tenant is the safe default. Organization mode requires an organization-management JWT. */
279
+ scope?: "tenant" | "organization" | undefined;
280
+ /** Internal UUID. Supply this or tenantExternalId for tenant mode with an organization JWT. */
281
+ tenantId?: string | undefined;
282
+ /** Exact customer-owned Tenant ID. tenantId takes precedence when both are supplied. */
283
+ tenantExternalId?: string | undefined;
284
+ /** Final request failures, after authentication retry. Cancellations are not reported. */
285
+ onError?: ((error: Error) => void) | undefined;
286
+ }
287
+ //#endregion
288
+ //#region src/client/listings.d.ts
289
+ interface AstralBeamListingOptions extends AstralBeamListingCoreOptions {
290
+ fetchAstralBeamToken: NonNullable<AstralBeamListingCoreOptions["fetchAstralBeamToken"]>;
291
+ pageSize?: 20 | 50 | 100 | undefined;
292
+ title?: string | undefined;
293
+ showHeader?: boolean | undefined;
294
+ /** Trusted application CSS, scoped to this widget's shadow root. */
295
+ customCss?: string | undefined;
296
+ colorScheme?: AstralBeamChatColorScheme | undefined;
297
+ theme?: AstralBeamChatTheme | undefined;
298
+ }
299
+ interface MountAstralBeamTenantListOptions extends AstralBeamListingOptions {
300
+ onTenantSelect?: ((tenant: TenantRecordEncoded) => void) | undefined;
301
+ }
302
+ interface MountAstralBeamTenantUserListOptions extends AstralBeamListingOptions {
303
+ /** Called when the Tenant picker selection changes. null means cleared. */
304
+ onTenantChange?: ((tenant: TenantRecordEncoded | null) => void) | undefined;
305
+ /** Show the stored admin column and filter. Does not control authorization. Defaults to false. */
306
+ showAdmin?: boolean | undefined;
307
+ onTenantUserSelect?: ((user: TenantUserRecordEncoded) => void) | undefined;
308
+ }
309
+ interface AstralBeamListingHandle<T extends AstralBeamListingOptions = AstralBeamListingOptions> {
310
+ update(options: Partial<T>): void;
311
+ refresh(): void;
312
+ /** Clears state and reloads using the ready host session. Unmount during sign-out or account transitions. */
313
+ reset(): void;
314
+ unmount(): void;
315
+ }
316
+ type AstralBeamTenantListHandle = AstralBeamListingHandle<MountAstralBeamTenantListOptions>;
317
+ type AstralBeamTenantUserListHandle = AstralBeamListingHandle<MountAstralBeamTenantUserListOptions>;
318
+ declare function mountAstralBeamTenantList(target: HTMLElement, options: MountAstralBeamTenantListOptions): AstralBeamTenantListHandle;
319
+ declare function mountAstralBeamTenantUserList(target: HTMLElement, options: MountAstralBeamTenantUserListOptions): AstralBeamTenantUserListHandle;
320
+ //#endregion
232
321
  //#region src/client/index.d.ts
233
322
  declare function mountAstralBeamChat(target: HTMLElement, options: MountAstralBeamChatOptions): AstralBeamChatHandle;
234
323
  //#endregion
235
- export { type AstralBeamChatAttachmentOptions, type AstralBeamChatColorScheme, type AstralBeamChatHandle, type AstralBeamChatSlotRenderer, type AstralBeamChatSlots, type AstralBeamChatTheme, type AstralBeamChatThemeVariables, type AstralBeamChatUpdate, type AstralBeamTokenRequest, type AstralBeamTokenSource, type InferParameters, type JsonSchemaObject, type MountAstralBeamChatOptions, type ParametersSchema, type StandardSchemaV1, type ToolDefinition, type TypedToolDefinition, type TypedWidgetDefinition, type WidgetDefinition, defineTool, defineWidget, mountAstralBeamChat };
324
+ export { type AstralBeamChatAttachmentOptions, type AstralBeamChatColorScheme, type AstralBeamChatHandle, type AstralBeamChatSlotRenderer, type AstralBeamChatSlots, type AstralBeamChatTheme, type AstralBeamChatThemeVariables, type AstralBeamChatUpdate, type AstralBeamListingHandle, type AstralBeamListingOptions, type AstralBeamTenantListHandle, type AstralBeamTenantUserListHandle, type AstralBeamTokenRequest, type AstralBeamTokenSource, type InferParameters, type JsonSchemaObject, type MountAstralBeamChatOptions, type MountAstralBeamTenantListOptions, type MountAstralBeamTenantUserListOptions, type ParametersSchema, type StandardSchemaV1, type ToolDefinition, type TypedToolDefinition, type TypedWidgetDefinition, type WidgetDefinition, defineTool, defineWidget, mountAstralBeamChat, mountAstralBeamTenantList, mountAstralBeamTenantUserList };
package/dist/client.js CHANGED
@@ -1 +1 @@
1
- import{c as e,t}from"./debug-66ETHfXh.js";function n(e){return e}function r(e){return e}function i(n,r){let i={...r},a=t(i.debug);a?.(`mount`,`mounting chat widget`,{agentId:i.agentId??`(organization default)`,title:i.title??`AstralBeam`,showHeader:i.showHeader??!0,emptyTitle:i.emptyTitle??`Ask the assistant`,emptyDescription:i.emptyDescription??`It can answer questions and act through this app's own tools and widgets.`,apiUrl:i.apiUrl??`https://app.astralbeam.ai/api`,authentication:`configured`,colorScheme:i.colorScheme??`system`,theme:i.theme,tools:Object.keys(i.tools??{}),widgets:Object.keys(i.widgets??{}),attachments:i.attachments??!0});let o=n.shadowRoot??n.attachShadow({mode:`open`}),s=document.createElement(`div`);s.className=e,s.style.height=`100%`,o.append(s);let c=matchMedia(`(prefers-color-scheme: dark)`),l=new Set,u=e=>{for(let e of l)s.style.removeProperty(e);l.clear();let t={...i.theme?.light,...e?i.theme?.dark:void 0};for(let[e,n]of Object.entries(t))e.startsWith(`--`)&&(s.style.setProperty(e,n),l.add(e))},d=()=>{let e=i.colorScheme??`system`,t=e===`dark`||e===`system`&&c.matches;s.classList.toggle(`dark`,t),u(t),a?.(`theme`,`color scheme "${e}" resolved to ${t?`dark`:`light`}`,{themeVariables:[...l]})};d(),c.addEventListener(`change`,d);let f=!1,p;return import(`./widget-DLUt14KM.js`).then(({renderChat:e})=>{a?.(`mount`,`chat chunk loaded`),f||(p=e(o,s,i))}),{update:e=>{i={...i,...e},a=t(i.debug),a?.(`mount`,`options updated`,{changed:Object.keys(e)}),d(),p?.update(i)},reset:()=>p?.reset(),stop:()=>p?.stop(),unmount:()=>{a?.(`mount`,`unmounting chat widget`),f=!0,c.removeEventListener(`change`,d),p?.dispose(),p=void 0,s.remove()}}}export{n as defineTool,r as defineWidget,i as mountAstralBeamChat};
1
+ import{s as e}from"./constants-CgaMxV3q.js";import{t}from"./debug-qLts7gEt.js";function n(e,t,n,r){let i=n.colorScheme??`system`,a=i===`dark`||i===`system`&&r;e.classList.toggle(`dark`,a);for(let n of t)e.style.removeProperty(n);t.clear();let o={...n.theme?.light,...a?n.theme?.dark:void 0};for(let[n,r]of Object.entries(o))n.startsWith(`--`)&&(e.style.setProperty(n,r),t.add(n));return{colorScheme:i,dark:a}}function r(e){return e}function i(e){return e}function a(e,t){return s(e,t,`tenants`)}function o(e,t){return s(e,t,`users`)}function s(t,n,r){let i=t.shadowRoot??t.attachShadow({mode:`open`}),a=document.createElement(`div`);a.className=`${e} bg-transparent`,a.style.height=`100%`,i.append(a);let o=matchMedia(`(prefers-color-scheme: dark)`),s={options:{...n},kind:r,shadow:i,container:a,media:o,variables:new Set,disposed:!1},f=()=>c(s);return f(),o.addEventListener(`change`,f),l(s),{update:e=>u(s,e),refresh:()=>{!s.disposed&&s.renderer&&s.runtime.refreshListing(s.renderer)},reset:()=>{!s.disposed&&s.renderer&&s.runtime.resetListing(s.renderer)},unmount:()=>d(s,f)}}function c({options:e,media:t,container:r,variables:i}){n(r,i,e,t.matches)}async function l(e){e.retryLoad?.remove();try{if(e.runtime=await import(`./listings-DVfsUaPv.js`),e.disposed)return;e.renderer=e.runtime.renderListing(e.shadow,e.container,e.options,e.kind)}catch{if(e.disposed)return;e.retryLoad=document.createElement(`button`),e.retryLoad.textContent=`Could not load directory. Retry`,e.retryLoad.onclick=()=>void l(e),e.container.append(e.retryLoad)}}function u(e,t){e.disposed||(e.options={...e.options,...t},c(e),e.renderer&&e.runtime.updateListing(e.renderer,e.options))}function d(e,t){e.disposed||(e.disposed=!0,e.media.removeEventListener(`change`,t),e.renderer&&e.runtime.disposeListing(e.renderer),e.container.remove())}function f(r,i){let a={...i},o=t(a.debug);o?.(`mount`,`mounting chat widget`,{agentId:a.agentId??`(organization default)`,title:a.title??`AstralBeam`,showHeader:a.showHeader??!0,emptyTitle:a.emptyTitle??`Ask the assistant`,emptyDescription:a.emptyDescription??`It can answer questions and act through this app's own tools and widgets.`,apiUrl:a.apiUrl??`https://app.astralbeam.ai/api`,authentication:`configured`,colorScheme:a.colorScheme??`system`,theme:a.theme,tools:Object.keys(a.tools??{}),widgets:Object.keys(a.widgets??{}),attachments:a.attachments??!0});let s=r.shadowRoot??r.attachShadow({mode:`open`}),c=document.createElement(`div`);c.className=e,c.style.height=`100%`,s.append(c);let l=matchMedia(`(prefers-color-scheme: dark)`),u=new Set,d=()=>{let{colorScheme:e,dark:t}=n(c,u,a,l.matches);o?.(`theme`,`color scheme "${e}" resolved to ${t?`dark`:`light`}`,{themeVariables:[...u]})};d(),l.addEventListener(`change`,d);let f=!1,p;return import(`./widget-CrC3teP8.js`).then(({renderChat:e})=>{o?.(`mount`,`chat chunk loaded`),f||(p=e(s,c,a))}),{update:e=>{a={...a,...e},o=t(a.debug),o?.(`mount`,`options updated`,{changed:Object.keys(e)}),d(),p?.update(a)},reset:()=>p?.reset(),stop:()=>p?.stop(),unmount:()=>{o?.(`mount`,`unmounting chat widget`),f=!0,l.removeEventListener(`change`,d),p?.dispose(),p=void 0,c.remove()}}}export{r as defineTool,i as defineWidget,f as mountAstralBeamChat,a as mountAstralBeamTenantList,o as mountAstralBeamTenantUserList};
@@ -0,0 +1 @@
1
+ const e=`AstralBeam`,t=`Ask the assistant`,n=`It can answer questions and act through this app's own tools and widgets.`,r=`https://app.astralbeam.ai/api`,i=`/api/astralbeam/token`,a=`system`,o=`astralbeam-root`;export{t as a,n as i,i as n,e as o,a as r,o as s,r as t};