@astralbeam/sdk 0.30.3 → 0.30.4
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
CHANGED
|
@@ -34,7 +34,7 @@ Without npm or a bundler, import the same entry from jsDelivr in a module script
|
|
|
34
34
|
```html
|
|
35
35
|
<div id="sidebar" style="height:100dvh"></div>
|
|
36
36
|
<script type="module">
|
|
37
|
-
import { mountAstralBeamChat } from "https://cdn.jsdelivr.net/npm/@astralbeam/sdk@0.30.
|
|
37
|
+
import { mountAstralBeamChat } from "https://cdn.jsdelivr.net/npm/@astralbeam/sdk@0.30.4/dist/client.js"
|
|
38
38
|
|
|
39
39
|
mountAstralBeamChat(document.getElementById("sidebar"), {})
|
|
40
40
|
</script>
|
package/dist/client.js
CHANGED
|
@@ -48,4 +48,4 @@ import{s as e}from"./constants-C-Yp0Vhg.js";import{t}from"./debug-DLDY8CZb.js";i
|
|
|
48
48
|
<header><span data-slot="chat-loading-title"></span></header>
|
|
49
49
|
<button type="button" aria-label="Close chat">×</button>
|
|
50
50
|
<div data-slot="chat-loading-status" role="status" data-loading>Loading chat…</div>
|
|
51
|
-
`,c.append(l);let u=l.querySelector(`header`),d=l.querySelector(`[data-slot="chat-loading-title"]`),f=l.querySelector(`button`),p=l.querySelector(`[role="status"]`),m=()=>{d.textContent=a.title??`AstralBeam`,u.hidden=a.showHeader===!1,f.hidden=!a.onClose};m(),f.onclick=e=>{e.detail<2&&a.onClose?.()};let h=matchMedia(`(prefers-color-scheme: dark)`),g=/* @__PURE__ */ new Set,v=()=>{let{colorScheme:e,dark:t}=r(c,g,a,h.matches);o?.(`theme`,`color scheme "${e}" resolved to ${t?`dark`:`light`}`,{themeVariables:[...g]})};v(),h.addEventListener(`change`,v);let y=!1,b;return import(`./widget-
|
|
51
|
+
`,c.append(l);let u=l.querySelector(`header`),d=l.querySelector(`[data-slot="chat-loading-title"]`),f=l.querySelector(`button`),p=l.querySelector(`[role="status"]`),m=()=>{d.textContent=a.title??`AstralBeam`,u.hidden=a.showHeader===!1,f.hidden=!a.onClose};m(),f.onclick=e=>{e.detail<2&&a.onClose?.()};let h=matchMedia(`(prefers-color-scheme: dark)`),g=/* @__PURE__ */ new Set,v=()=>{let{colorScheme:e,dark:t}=r(c,g,a,h.matches);o?.(`theme`,`color scheme "${e}" resolved to ${t?`dark`:`light`}`,{themeVariables:[...g]})};v(),h.addEventListener(`change`,v);let y=!1,b;return import(`./widget-Bea4OV_z.js`).then(({renderChat:e})=>{o?.(`mount`,`chat chunk loaded`),y||(b=e(s,c,a))}).catch(()=>{y||(delete p.dataset.loading,p.textContent=`Could not load chat. Reload this page to try again.`)}),{update:e=>{let n={...a,...e};if(_(n),!!n.chat!=!!a.chat)throw Error(`Remount chat to change session ownership`);a=n,o=t(a.debug),o?.(`mount`,`options updated`,{changed:Object.keys(e)}),v(),m(),b?.update(a)},unmount:()=>{o?.(`mount`,`unmounting chat widget`),y=!0,h.removeEventListener(`change`,v),b?.dispose(),b=void 0,c.remove()}}}export{i as defineTool,a as defineWidget,v as mountAstralBeamChat,g as mountAstralBeamMcpServers,o as mountAstralBeamTenantList,s as mountAstralBeamTenantUserList,c as mountAstralBeamThreadList};
|
|
@@ -11663,9 +11663,10 @@ function startAuthentication(options) {
|
|
|
11663
11663
|
//#region src/core/mcp.ts
|
|
11664
11664
|
async function manageMcpConnection(operation, options) {
|
|
11665
11665
|
switch (operation.action) {
|
|
11666
|
-
case "connect":
|
|
11666
|
+
case "connect":
|
|
11667
11667
|
case "headers": {
|
|
11668
11668
|
const connection = await personalMcpCreateConnection({ mcp_server_id: operation.mcpServerId }, options);
|
|
11669
|
+
if (operation.action === "connect") return connection;
|
|
11669
11670
|
await personalMcpSetHeaders(connection.id, {
|
|
11670
11671
|
lock_version: connection.lock_version,
|
|
11671
11672
|
headers: operation.headers
|
|
@@ -11690,64 +11691,71 @@ async function authorizeMcpConnection(input, requestOptions) {
|
|
|
11690
11691
|
};
|
|
11691
11692
|
const url = new URL(response.popup_url);
|
|
11692
11693
|
url.searchParams.set("origin", window.location.origin);
|
|
11693
|
-
|
|
11694
|
-
|
|
11695
|
-
|
|
11696
|
-
|
|
11697
|
-
|
|
11698
|
-
|
|
11699
|
-
|
|
11700
|
-
|
|
11701
|
-
|
|
11702
|
-
|
|
11703
|
-
|
|
11704
|
-
const fail = (error) => {
|
|
11705
|
-
cleanup();
|
|
11706
|
-
reject(error instanceof Error ? error : /* @__PURE__ */ new Error("Authorization failed."));
|
|
11694
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
11695
|
+
let phase = { state: "waiting" };
|
|
11696
|
+
const controller = new AbortController();
|
|
11697
|
+
let completing = false;
|
|
11698
|
+
const fail = (error) => reject(error instanceof Error ? error : /* @__PURE__ */ new Error("Authorization failed."));
|
|
11699
|
+
const authorizationOptions = async () => {
|
|
11700
|
+
const options = await requestOptions();
|
|
11701
|
+
controller.signal.throwIfAborted();
|
|
11702
|
+
return {
|
|
11703
|
+
...options,
|
|
11704
|
+
signal: AbortSignal.any([controller.signal, ...options.signal ? [options.signal] : []])
|
|
11707
11705
|
};
|
|
11708
|
-
|
|
11709
|
-
|
|
11710
|
-
|
|
11711
|
-
|
|
11712
|
-
|
|
11713
|
-
|
|
11714
|
-
|
|
11715
|
-
|
|
11716
|
-
|
|
11717
|
-
|
|
11718
|
-
|
|
11719
|
-
|
|
11720
|
-
if (finished) return;
|
|
11721
|
-
const connected = await personalMcpCompleteAuthorization(id, { attempt_id: attempt.id }, await requestOptions());
|
|
11722
|
-
if (finished) return;
|
|
11723
|
-
if (connected) {
|
|
11724
|
-
cleanup();
|
|
11725
|
-
resolve();
|
|
11726
|
-
return;
|
|
11727
|
-
}
|
|
11728
|
-
}
|
|
11729
|
-
if (popup.closed) fail(/* @__PURE__ */ new Error("Authorization window closed."));
|
|
11730
|
-
} catch (error) {
|
|
11731
|
-
const status = error instanceof Error ? error.status : void 0;
|
|
11732
|
-
if (!(error instanceof TypeError) && status !== 429 && (status ?? 0) < 500) fail(error);
|
|
11733
|
-
} finally {
|
|
11734
|
-
completing = false;
|
|
11706
|
+
};
|
|
11707
|
+
const complete = async () => {
|
|
11708
|
+
if (completing || controller.signal.aborted) return;
|
|
11709
|
+
completing = true;
|
|
11710
|
+
try {
|
|
11711
|
+
if (phase.state === "binding") {
|
|
11712
|
+
await personalMcpBindBrowser(id, {
|
|
11713
|
+
attempt_id: attempt.id,
|
|
11714
|
+
challenge: phase.challenge
|
|
11715
|
+
}, await authorizationOptions());
|
|
11716
|
+
controller.signal.throwIfAborted();
|
|
11717
|
+
phase = { state: "completing" };
|
|
11735
11718
|
}
|
|
11736
|
-
|
|
11737
|
-
|
|
11738
|
-
|
|
11739
|
-
|
|
11740
|
-
|
|
11741
|
-
|
|
11742
|
-
|
|
11743
|
-
complete();
|
|
11719
|
+
if (phase.state === "completing") {
|
|
11720
|
+
const connected = await personalMcpCompleteAuthorization(id, { attempt_id: attempt.id }, await authorizationOptions());
|
|
11721
|
+
controller.signal.throwIfAborted();
|
|
11722
|
+
if (connected) {
|
|
11723
|
+
resolve();
|
|
11724
|
+
return;
|
|
11725
|
+
}
|
|
11744
11726
|
}
|
|
11745
|
-
|
|
11746
|
-
|
|
11747
|
-
|
|
11727
|
+
if (popup.closed) fail(/* @__PURE__ */ new Error("Authorization window closed."));
|
|
11728
|
+
} catch (error) {
|
|
11729
|
+
const status = error instanceof Error ? error.status : void 0;
|
|
11730
|
+
if (!(error instanceof TypeError) && status !== 429 && (status ?? 0) < 500) fail(error);
|
|
11731
|
+
} finally {
|
|
11732
|
+
completing = false;
|
|
11733
|
+
}
|
|
11734
|
+
};
|
|
11735
|
+
const receive = (event) => {
|
|
11736
|
+
if (event.source !== popup || event.origin !== url.origin) return;
|
|
11737
|
+
const data = event.data;
|
|
11738
|
+
if (!data?.attempt || data.attempt.id !== attempt.id || data.attempt.organizationId !== attempt.organizationId || data.attempt.tenantId !== attempt.tenantId || data.attempt.connectionId !== attempt.connectionId) return;
|
|
11739
|
+
if (data.type === "mcp-browser-challenge" && phase.state === "waiting" && typeof data.challenge === "string") {
|
|
11740
|
+
phase = {
|
|
11741
|
+
state: "binding",
|
|
11742
|
+
challenge: data.challenge
|
|
11743
|
+
};
|
|
11744
|
+
complete();
|
|
11745
|
+
}
|
|
11746
|
+
};
|
|
11747
|
+
const poll = setInterval(() => void complete(), 5e3);
|
|
11748
|
+
const expiry = setTimeout(() => fail(/* @__PURE__ */ new Error("Authorization expired. Try connecting again.")), 6e5);
|
|
11749
|
+
try {
|
|
11748
11750
|
window.addEventListener("message", receive);
|
|
11749
11751
|
popup.location.replace(url.href);
|
|
11750
|
-
|
|
11752
|
+
await promise;
|
|
11753
|
+
} finally {
|
|
11754
|
+
controller.abort();
|
|
11755
|
+
window.removeEventListener("message", receive);
|
|
11756
|
+
clearInterval(poll);
|
|
11757
|
+
clearTimeout(expiry);
|
|
11758
|
+
}
|
|
11751
11759
|
return id;
|
|
11752
11760
|
} finally {
|
|
11753
11761
|
popup.close();
|
package/dist/core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { h as ASK_QUESTIONNAIRE_TOOL, g as RENDER_WIDGET_TOOL, _ as SANDBOX_LIST_FILES_TOOL, v as SANDBOX_PUBLISH_ARTIFACT_TOOL, y as SANDBOX_READ_FILE_TOOL, b as SANDBOX_RUN_COMMAND_TOOL, x as SANDBOX_STATUS_EVENT, S as SANDBOX_WRITE_FILE_TOOL, m as buildAgentTools, i as collectSandboxActivity, r as createAstralBeamChat, t as defineTool, a as describeSandboxCommandRun, d as hasPendingToolRun, o as isSandboxTool, f as isSettledToolCall, p as lastPartInProgress, s as readSandboxArtifact, c as readSandboxCommandRun, l as readSandboxFileWrite, u as sandboxRefusal } from "./core-
|
|
1
|
+
export { h as ASK_QUESTIONNAIRE_TOOL, g as RENDER_WIDGET_TOOL, _ as SANDBOX_LIST_FILES_TOOL, v as SANDBOX_PUBLISH_ARTIFACT_TOOL, y as SANDBOX_READ_FILE_TOOL, b as SANDBOX_RUN_COMMAND_TOOL, x as SANDBOX_STATUS_EVENT, S as SANDBOX_WRITE_FILE_TOOL, m as buildAgentTools, i as collectSandboxActivity, r as createAstralBeamChat, t as defineTool, a as describeSandboxCommandRun, d as hasPendingToolRun, o as isSandboxTool, f as isSettledToolCall, p as lastPartInProgress, s as readSandboxArtifact, c as readSandboxCommandRun, l as readSandboxFileWrite, u as sandboxRefusal } from "./core-BJ_Td5TR.js";
|
package/dist/react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as CORE_OPTION_KEYS, r as createAstralBeamChat } from "./core-
|
|
1
|
+
import { n as CORE_OPTION_KEYS, r as createAstralBeamChat } from "./core-BJ_Td5TR.js";
|
|
2
2
|
import { Kt as DEFAULT_COLOR_SCHEME } from "./api-CzXKVU8Z.js";
|
|
3
3
|
import { forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|