@ai4b-team/fsaos-gateway-sdk 4.3.1 → 5.1.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 +27 -1
- package/dist/iife/gateway.js +4 -4
- package/dist/iife/gateway.js.map +4 -4
- package/dist/iife/ui.js +1 -1
- package/dist/index.cjs +463 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +60 -8
- package/dist/index.d.ts +60 -8
- package/dist/index.js +463 -65
- package/dist/index.js.map +1 -1
- package/dist/ui.d.cts +1 -1
- package/dist/ui.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useMemo, useState, useRef, useEffect, useSyncExternalStore, useCallback,
|
|
1
|
+
import React, { createElement, useMemo, useState, useRef, useEffect, useSyncExternalStore, useCallback, useLayoutEffect } from 'react';
|
|
2
2
|
import { QueryClient, QueryClientProvider, useQuery, useInfiniteQuery, useQueryClient, useMutation as useMutation$1 } from '@tanstack/react-query';
|
|
3
3
|
export { QueryClientProvider } from '@tanstack/react-query';
|
|
4
4
|
import { createClient } from '@supabase/supabase-js';
|
|
@@ -100,6 +100,7 @@ __export(src_exports, {
|
|
|
100
100
|
itemsFilterFromQueryFilter: () => itemsFilterFromQueryFilter,
|
|
101
101
|
listChildren: () => listChildren,
|
|
102
102
|
loadMounts: () => loadMounts,
|
|
103
|
+
loadPublishedBundle: () => loadPublishedBundle,
|
|
103
104
|
mount: () => mount2,
|
|
104
105
|
mountRealtimeScope: () => mountRealtimeScope,
|
|
105
106
|
normalizeItem: () => normalizeItem,
|
|
@@ -188,6 +189,7 @@ __export(src_exports, {
|
|
|
188
189
|
usePersonalSections: () => usePersonalSections,
|
|
189
190
|
usePinnedItems: () => usePinnedItems,
|
|
190
191
|
usePrincipal: () => usePrincipal,
|
|
192
|
+
usePublishedComponent: () => usePublishedComponent,
|
|
191
193
|
useRealtimeQuery: () => useRealtimeQuery,
|
|
192
194
|
useRecentActivity: () => useRecentActivity,
|
|
193
195
|
useResolve: () => useResolve,
|
|
@@ -198,7 +200,6 @@ __export(src_exports, {
|
|
|
198
200
|
useSeatMember: () => useSeatMember,
|
|
199
201
|
useTheme: () => useTheme,
|
|
200
202
|
useTimelineHistory: () => useTimelineHistory,
|
|
201
|
-
useTool: () => useTool,
|
|
202
203
|
useTree: () => useTree,
|
|
203
204
|
useType: () => useType,
|
|
204
205
|
useTypeHelpers: () => useTypeHelpers,
|
|
@@ -2531,6 +2532,204 @@ function replaceMounts(refs, anchor) {
|
|
|
2531
2532
|
});
|
|
2532
2533
|
}
|
|
2533
2534
|
|
|
2535
|
+
// src/ui.ts
|
|
2536
|
+
var ui_exports = {};
|
|
2537
|
+
__export(ui_exports, {
|
|
2538
|
+
Badge: () => Badge,
|
|
2539
|
+
Breadcrumbs: () => Breadcrumbs,
|
|
2540
|
+
Button: () => Button,
|
|
2541
|
+
Card: () => Card,
|
|
2542
|
+
DataView: () => DataView,
|
|
2543
|
+
Detail: () => Detail,
|
|
2544
|
+
Empty: () => Empty,
|
|
2545
|
+
FilePreview: () => FilePreview,
|
|
2546
|
+
Form: () => Form,
|
|
2547
|
+
Grid: () => Grid,
|
|
2548
|
+
Image: () => Image,
|
|
2549
|
+
Link: () => Link,
|
|
2550
|
+
Page: () => Page,
|
|
2551
|
+
Router: () => Router,
|
|
2552
|
+
Sidebar: () => Sidebar,
|
|
2553
|
+
Spinner: () => Spinner,
|
|
2554
|
+
Stack: () => Stack,
|
|
2555
|
+
Table: () => Table,
|
|
2556
|
+
Tabs: () => Tabs,
|
|
2557
|
+
Video: () => Video
|
|
2558
|
+
});
|
|
2559
|
+
function getEdgeBaseUrl() {
|
|
2560
|
+
const config2 = typeof window !== "undefined" && window.__FSAOS_CONFIG__ || {};
|
|
2561
|
+
return config2.edgeBaseUrl || "";
|
|
2562
|
+
}
|
|
2563
|
+
function Page(props) {
|
|
2564
|
+
return createElement("div", {
|
|
2565
|
+
style: { minHeight: "100vh", display: "flex", flexDirection: "column" },
|
|
2566
|
+
className: props.className || ""
|
|
2567
|
+
}, props.children);
|
|
2568
|
+
}
|
|
2569
|
+
function Stack(props) {
|
|
2570
|
+
const dir = props.direction || "vertical";
|
|
2571
|
+
return createElement("div", {
|
|
2572
|
+
style: {
|
|
2573
|
+
display: "flex",
|
|
2574
|
+
flexDirection: dir === "horizontal" ? "row" : "column",
|
|
2575
|
+
gap: props.gap || "0.5rem",
|
|
2576
|
+
padding: props.padding || "0",
|
|
2577
|
+
alignItems: props.align || "stretch",
|
|
2578
|
+
justifyContent: props.justify || "flex-start",
|
|
2579
|
+
flex: props.flex || "initial"
|
|
2580
|
+
},
|
|
2581
|
+
className: props.className || ""
|
|
2582
|
+
}, props.children);
|
|
2583
|
+
}
|
|
2584
|
+
function Grid(props) {
|
|
2585
|
+
return createElement("div", {
|
|
2586
|
+
style: {
|
|
2587
|
+
display: "grid",
|
|
2588
|
+
gridTemplateColumns: "repeat(" + (props.columns || 3) + ", 1fr)",
|
|
2589
|
+
gap: props.gap || "1rem",
|
|
2590
|
+
padding: props.padding || "0"
|
|
2591
|
+
},
|
|
2592
|
+
className: props.className || ""
|
|
2593
|
+
}, props.children);
|
|
2594
|
+
}
|
|
2595
|
+
function Sidebar(props) {
|
|
2596
|
+
return createElement("div", {
|
|
2597
|
+
style: { display: "flex", flexDirection: "row", minHeight: "100vh" },
|
|
2598
|
+
className: props.className || ""
|
|
2599
|
+
}, props.children);
|
|
2600
|
+
}
|
|
2601
|
+
function Card(props) {
|
|
2602
|
+
return createElement("div", {
|
|
2603
|
+
style: {
|
|
2604
|
+
border: "1px solid var(--color-border, #e5e7eb)",
|
|
2605
|
+
borderRadius: "var(--border-radius, 0.5rem)",
|
|
2606
|
+
padding: props.padding || "1rem",
|
|
2607
|
+
background: "var(--color-surface, #fff)"
|
|
2608
|
+
},
|
|
2609
|
+
className: props.className || "",
|
|
2610
|
+
onClick: props.onClick
|
|
2611
|
+
}, props.children);
|
|
2612
|
+
}
|
|
2613
|
+
function Badge(props) {
|
|
2614
|
+
return createElement("span", {
|
|
2615
|
+
style: {
|
|
2616
|
+
display: "inline-flex",
|
|
2617
|
+
alignItems: "center",
|
|
2618
|
+
padding: "0.125rem 0.5rem",
|
|
2619
|
+
fontSize: "0.75rem",
|
|
2620
|
+
fontWeight: "500",
|
|
2621
|
+
borderRadius: "9999px",
|
|
2622
|
+
background: props.color || "#e5e7eb",
|
|
2623
|
+
color: props.textColor || "#374151"
|
|
2624
|
+
},
|
|
2625
|
+
className: props.className || ""
|
|
2626
|
+
}, props.children || props.label);
|
|
2627
|
+
}
|
|
2628
|
+
function Spinner(props) {
|
|
2629
|
+
const size = props.size || "1.5rem";
|
|
2630
|
+
return createElement("div", {
|
|
2631
|
+
style: {
|
|
2632
|
+
width: size,
|
|
2633
|
+
height: size,
|
|
2634
|
+
border: "2px solid #e5e7eb",
|
|
2635
|
+
borderTopColor: "var(--color-primary, #3b82f6)",
|
|
2636
|
+
borderRadius: "50%",
|
|
2637
|
+
animation: "fsaos-spin 0.6s linear infinite"
|
|
2638
|
+
}
|
|
2639
|
+
});
|
|
2640
|
+
}
|
|
2641
|
+
function Button(props) {
|
|
2642
|
+
return createElement("button", {
|
|
2643
|
+
style: {
|
|
2644
|
+
display: "inline-flex",
|
|
2645
|
+
alignItems: "center",
|
|
2646
|
+
justifyContent: "center",
|
|
2647
|
+
padding: "0.5rem 1rem",
|
|
2648
|
+
fontSize: "0.875rem",
|
|
2649
|
+
fontWeight: "500",
|
|
2650
|
+
borderRadius: "var(--border-radius, 0.375rem)",
|
|
2651
|
+
border: props.variant === "outline" ? "1px solid var(--color-border, #d1d5db)" : "none",
|
|
2652
|
+
background: props.variant === "outline" || props.variant === "ghost" ? "transparent" : "var(--color-primary, #3b82f6)",
|
|
2653
|
+
color: props.variant === "outline" || props.variant === "ghost" ? "var(--color-text, #1a1a1a)" : "#fff",
|
|
2654
|
+
cursor: props.disabled ? "not-allowed" : "pointer",
|
|
2655
|
+
opacity: props.disabled ? "0.5" : "1",
|
|
2656
|
+
gap: "0.5rem"
|
|
2657
|
+
},
|
|
2658
|
+
className: props.className || "",
|
|
2659
|
+
onClick: props.onClick,
|
|
2660
|
+
disabled: props.disabled
|
|
2661
|
+
}, props.children || props.label);
|
|
2662
|
+
}
|
|
2663
|
+
function Empty(props) {
|
|
2664
|
+
return createElement(
|
|
2665
|
+
"div",
|
|
2666
|
+
{
|
|
2667
|
+
style: {
|
|
2668
|
+
display: "flex",
|
|
2669
|
+
flexDirection: "column",
|
|
2670
|
+
alignItems: "center",
|
|
2671
|
+
justifyContent: "center",
|
|
2672
|
+
padding: "3rem",
|
|
2673
|
+
color: "var(--color-text-secondary, #6b7280)",
|
|
2674
|
+
textAlign: "center"
|
|
2675
|
+
}
|
|
2676
|
+
},
|
|
2677
|
+
props.icon ? createElement("div", { style: { fontSize: "2rem", marginBottom: "0.5rem" } }, props.icon) : null,
|
|
2678
|
+
createElement(
|
|
2679
|
+
"div",
|
|
2680
|
+
{ style: { fontWeight: 500, marginBottom: "0.25rem" } },
|
|
2681
|
+
props.title || props.message || props.children || "No items"
|
|
2682
|
+
),
|
|
2683
|
+
props.description ? createElement("div", { style: { fontSize: "0.875rem", opacity: 0.7 } }, props.description) : null
|
|
2684
|
+
);
|
|
2685
|
+
}
|
|
2686
|
+
function DataView(props) {
|
|
2687
|
+
return createElement("div", { className: props.className || "" }, props.children);
|
|
2688
|
+
}
|
|
2689
|
+
function Table(props) {
|
|
2690
|
+
return createElement("table", { className: props.className || "" }, props.children);
|
|
2691
|
+
}
|
|
2692
|
+
function Form(props) {
|
|
2693
|
+
return createElement("form", { className: props.className || "", onSubmit: props.onSubmit }, props.children);
|
|
2694
|
+
}
|
|
2695
|
+
function Detail(props) {
|
|
2696
|
+
return createElement("div", { className: props.className || "" }, props.children);
|
|
2697
|
+
}
|
|
2698
|
+
function Router(props) {
|
|
2699
|
+
return createElement("div", null, props.children);
|
|
2700
|
+
}
|
|
2701
|
+
function Link(props) {
|
|
2702
|
+
return createElement("a", {
|
|
2703
|
+
href: props.href || props.to,
|
|
2704
|
+
className: props.className || "",
|
|
2705
|
+
onClick: props.onClick
|
|
2706
|
+
}, props.children);
|
|
2707
|
+
}
|
|
2708
|
+
function Tabs(props) {
|
|
2709
|
+
return createElement("div", { className: props.className || "" }, props.children);
|
|
2710
|
+
}
|
|
2711
|
+
function Breadcrumbs(props) {
|
|
2712
|
+
return createElement("nav", { className: props.className || "" }, props.children);
|
|
2713
|
+
}
|
|
2714
|
+
function Image(props) {
|
|
2715
|
+
return createElement("img", {
|
|
2716
|
+
src: props.src || (props.path ? getEdgeBaseUrl() + props.path : ""),
|
|
2717
|
+
alt: props.alt || "",
|
|
2718
|
+
className: props.className || "",
|
|
2719
|
+
style: props.style
|
|
2720
|
+
});
|
|
2721
|
+
}
|
|
2722
|
+
function Video(props) {
|
|
2723
|
+
return createElement("video", {
|
|
2724
|
+
src: props.src || (props.path ? getEdgeBaseUrl() + props.path : ""),
|
|
2725
|
+
controls: true,
|
|
2726
|
+
className: props.className || ""
|
|
2727
|
+
});
|
|
2728
|
+
}
|
|
2729
|
+
function FilePreview(props) {
|
|
2730
|
+
return createElement("div", { className: props.className || "" }, props.children || "File preview");
|
|
2731
|
+
}
|
|
2732
|
+
|
|
2534
2733
|
// src/mounted-reader-events.ts
|
|
2535
2734
|
function inMountedReadScope(event) {
|
|
2536
2735
|
if (typeof event.path !== "string") return false;
|
|
@@ -3471,7 +3670,6 @@ function useAsset(idOrPath) {
|
|
|
3471
3670
|
return { data, loading, error };
|
|
3472
3671
|
}
|
|
3473
3672
|
var componentCache = {};
|
|
3474
|
-
var componentCssCache = {};
|
|
3475
3673
|
registerCleanup(() => {
|
|
3476
3674
|
for (const key of Object.keys(componentCache)) {
|
|
3477
3675
|
delete componentCache[key];
|
|
@@ -3496,9 +3694,11 @@ function sdkRequireShim(name) {
|
|
|
3496
3694
|
return typeof window !== "undefined" && window.React ? { jsx: window.React.createElement, jsxs: window.React.createElement, Fragment: window.React.Fragment } : JsxRuntime;
|
|
3497
3695
|
case "@fsaos/gateway":
|
|
3498
3696
|
case "@fsaos/react":
|
|
3697
|
+
case "@ai4b-team/fsaos-gateway-sdk":
|
|
3499
3698
|
return typeof window !== "undefined" && window.__FSAOS_GATEWAY__ || _sdkExports || {};
|
|
3500
3699
|
case "@fsaos/ui":
|
|
3501
|
-
|
|
3700
|
+
case "@ai4b-team/fsaos-gateway-sdk/ui":
|
|
3701
|
+
return typeof window !== "undefined" && window.__FSAOS_UI__ || ui_exports;
|
|
3502
3702
|
case "@fsaos/theme":
|
|
3503
3703
|
return {};
|
|
3504
3704
|
default:
|
|
@@ -3506,30 +3706,42 @@ function sdkRequireShim(name) {
|
|
|
3506
3706
|
return {};
|
|
3507
3707
|
}
|
|
3508
3708
|
}
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
/^(\s*)(:root|body)(\s*[{,])/gm,
|
|
3512
|
-
(_match, ws2, _sel, rest) => `${ws2}.${scopeClass}${rest}`
|
|
3513
|
-
);
|
|
3514
|
-
}
|
|
3515
|
-
async function loadComponentCss(cssUrl, scopeId) {
|
|
3516
|
-
if (componentCssCache[cssUrl]) return;
|
|
3709
|
+
var componentCss = {};
|
|
3710
|
+
async function fetchComponentCss(cssUrl) {
|
|
3517
3711
|
try {
|
|
3518
3712
|
const response = await fetch(cssUrl);
|
|
3519
|
-
if (!response.ok) return;
|
|
3520
|
-
|
|
3521
|
-
if (!cssText.trim()) return;
|
|
3522
|
-
if (cssText.includes("No CSS bundle for this component")) return;
|
|
3523
|
-
|
|
3524
|
-
const style = document.createElement("style");
|
|
3525
|
-
style.setAttribute("data-fsaos-component-css", cssUrl);
|
|
3526
|
-
if (scopeId) ;
|
|
3527
|
-
style.textContent = cssText;
|
|
3528
|
-
document.head.appendChild(style);
|
|
3529
|
-
componentCssCache[cssUrl] = style;
|
|
3713
|
+
if (!response.ok) return null;
|
|
3714
|
+
const cssText = await response.text();
|
|
3715
|
+
if (!cssText.trim()) return null;
|
|
3716
|
+
if (cssText.includes("No CSS bundle for this component")) return null;
|
|
3717
|
+
return cssText;
|
|
3530
3718
|
} catch {
|
|
3719
|
+
return null;
|
|
3531
3720
|
}
|
|
3532
3721
|
}
|
|
3722
|
+
async function holdComponentCss(cssUrl, text = () => fetchComponentCss(cssUrl)) {
|
|
3723
|
+
let entry = componentCss[cssUrl];
|
|
3724
|
+
if (!entry) {
|
|
3725
|
+
entry = componentCss[cssUrl] = { users: 0, text: text(), style: null };
|
|
3726
|
+
}
|
|
3727
|
+
entry.users += 1;
|
|
3728
|
+
const cssText = await entry.text;
|
|
3729
|
+
if (componentCss[cssUrl] !== entry || entry.users === 0 || entry.style || !cssText) return;
|
|
3730
|
+
if (typeof document === "undefined") return;
|
|
3731
|
+
const style = document.createElement("style");
|
|
3732
|
+
style.setAttribute("data-fsaos-component-css", cssUrl);
|
|
3733
|
+
style.textContent = cssText;
|
|
3734
|
+
document.head.appendChild(style);
|
|
3735
|
+
entry.style = style;
|
|
3736
|
+
}
|
|
3737
|
+
function releaseComponentCss(cssUrl) {
|
|
3738
|
+
const entry = componentCss[cssUrl];
|
|
3739
|
+
if (!entry) return;
|
|
3740
|
+
entry.users -= 1;
|
|
3741
|
+
if (entry.users > 0) return;
|
|
3742
|
+
entry.style?.remove();
|
|
3743
|
+
delete componentCss[cssUrl];
|
|
3744
|
+
}
|
|
3533
3745
|
function evaluateBundle(jsCode) {
|
|
3534
3746
|
let registered = null;
|
|
3535
3747
|
const previousRegister = window.__FSAOS_REGISTER__;
|
|
@@ -3555,65 +3767,84 @@ function evaluateBundle(jsCode) {
|
|
|
3555
3767
|
}
|
|
3556
3768
|
}
|
|
3557
3769
|
}
|
|
3558
|
-
function useComponent(path) {
|
|
3770
|
+
function useComponent(path, options) {
|
|
3559
3771
|
const [Component, setComponent] = useState(null);
|
|
3560
3772
|
const [loading, setLoading] = useState(true);
|
|
3561
3773
|
const [error, setError] = useState(null);
|
|
3774
|
+
const shown = useRef(null);
|
|
3775
|
+
const pinnedVersion = Number.isSafeInteger(options?.version) && options.version > 0 ? options.version : null;
|
|
3562
3776
|
useEffect(() => {
|
|
3563
3777
|
if (!path) return;
|
|
3564
3778
|
let cancelled = false;
|
|
3565
|
-
setLoading(true);
|
|
3566
3779
|
setError(null);
|
|
3780
|
+
if (shown.current?.path !== path) {
|
|
3781
|
+
if (shown.current?.cssUrl) releaseComponentCss(shown.current.cssUrl);
|
|
3782
|
+
shown.current = null;
|
|
3783
|
+
setComponent(null);
|
|
3784
|
+
setLoading(true);
|
|
3785
|
+
}
|
|
3567
3786
|
const config2 = typeof window !== "undefined" && window.__FSAOS_CONFIG__ || {};
|
|
3568
3787
|
const edgeBaseUrl = config2.edgeBaseUrl || "";
|
|
3569
3788
|
(async () => {
|
|
3789
|
+
let heldCssUrl = null;
|
|
3570
3790
|
try {
|
|
3571
3791
|
let version = 1;
|
|
3572
3792
|
let cacheKey = path + "@v1";
|
|
3573
3793
|
let bundleUrl = edgeBaseUrl + path + "/__bundle.js";
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3794
|
+
if (pinnedVersion !== null) {
|
|
3795
|
+
version = pinnedVersion;
|
|
3796
|
+
cacheKey = path + "@v" + version;
|
|
3797
|
+
bundleUrl = edgeBaseUrl + path + "/__bundle.v" + version + ".js";
|
|
3798
|
+
} else {
|
|
3799
|
+
try {
|
|
3800
|
+
const metaResponse = await fetch(edgeBaseUrl + path + "/__meta", { cache: "no-store" });
|
|
3801
|
+
if (metaResponse.ok) {
|
|
3802
|
+
const meta = await metaResponse.json();
|
|
3803
|
+
version = meta.version || 1;
|
|
3804
|
+
cacheKey = path + "@v" + version;
|
|
3805
|
+
bundleUrl = edgeBaseUrl + path + "/__bundle.v" + version + ".js";
|
|
3806
|
+
}
|
|
3807
|
+
} catch {
|
|
3808
|
+
bundleUrl = edgeBaseUrl + path + "/__bundle.js?v=" + Date.now();
|
|
3581
3809
|
}
|
|
3582
|
-
} catch {
|
|
3583
|
-
bundleUrl = edgeBaseUrl + path + "/__bundle.js?v=" + Date.now();
|
|
3584
|
-
}
|
|
3585
|
-
if (cancelled) return;
|
|
3586
|
-
if (componentCache[cacheKey]) {
|
|
3587
|
-
setComponent(() => componentCache[cacheKey]);
|
|
3588
|
-
setLoading(false);
|
|
3589
|
-
return;
|
|
3590
|
-
}
|
|
3591
|
-
const jsResponse = await fetch(bundleUrl);
|
|
3592
|
-
if (!jsResponse.ok) {
|
|
3593
|
-
throw new Error(
|
|
3594
|
-
`Failed to fetch bundle: ${jsResponse.status} ${jsResponse.statusText} (${bundleUrl})`
|
|
3595
|
-
);
|
|
3596
3810
|
}
|
|
3597
|
-
const jsCode = await jsResponse.text();
|
|
3598
3811
|
if (cancelled) return;
|
|
3599
3812
|
const cssUrl = bundleUrl.replace(/__bundle(\.v\d+)?\.js(\?.*)?$/, "__bundle$1.css");
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3813
|
+
heldCssUrl = cssUrl;
|
|
3814
|
+
const cssReady = holdComponentCss(cssUrl);
|
|
3815
|
+
let resolved = componentCache[cacheKey];
|
|
3603
3816
|
if (!resolved) {
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3817
|
+
const jsResponse = await fetch(bundleUrl);
|
|
3818
|
+
if (!jsResponse.ok) {
|
|
3819
|
+
throw new Error(
|
|
3820
|
+
`Failed to fetch bundle: ${jsResponse.status} ${jsResponse.statusText} (${bundleUrl})`
|
|
3821
|
+
);
|
|
3822
|
+
}
|
|
3823
|
+
const jsCode = await jsResponse.text();
|
|
3824
|
+
resolved = evaluateBundle(jsCode);
|
|
3825
|
+
if (!resolved) {
|
|
3826
|
+
throw new Error(
|
|
3827
|
+
"Bundle did not export a component. Expected window.__FSAOS_COMPONENT__ (FSAOS build) or a __FSAOS_REGISTER__(Component) call."
|
|
3828
|
+
);
|
|
3829
|
+
}
|
|
3830
|
+
if (typeof resolved !== "function") {
|
|
3831
|
+
throw new Error(`Bundle export is not a React component (got ${typeof resolved})`);
|
|
3832
|
+
}
|
|
3833
|
+
componentCache[cacheKey] = resolved;
|
|
3610
3834
|
}
|
|
3611
|
-
|
|
3612
|
-
if (
|
|
3613
|
-
|
|
3614
|
-
|
|
3835
|
+
await cssReady;
|
|
3836
|
+
if (cancelled) {
|
|
3837
|
+
releaseComponentCss(cssUrl);
|
|
3838
|
+
return;
|
|
3615
3839
|
}
|
|
3840
|
+
const previousCssUrl = shown.current?.cssUrl ?? null;
|
|
3841
|
+
shown.current = { path, cssUrl };
|
|
3842
|
+
heldCssUrl = null;
|
|
3843
|
+
setComponent(() => resolved);
|
|
3844
|
+
setLoading(false);
|
|
3845
|
+
if (previousCssUrl) releaseComponentCss(previousCssUrl);
|
|
3616
3846
|
} catch (err) {
|
|
3847
|
+
if (heldCssUrl) releaseComponentCss(heldCssUrl);
|
|
3617
3848
|
if (!cancelled) {
|
|
3618
3849
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
3619
3850
|
setLoading(false);
|
|
@@ -3623,9 +3854,179 @@ function useComponent(path) {
|
|
|
3623
3854
|
return () => {
|
|
3624
3855
|
cancelled = true;
|
|
3625
3856
|
};
|
|
3626
|
-
}, [path]);
|
|
3857
|
+
}, [path, pinnedVersion]);
|
|
3858
|
+
useEffect(() => () => {
|
|
3859
|
+
if (shown.current?.cssUrl) releaseComponentCss(shown.current.cssUrl);
|
|
3860
|
+
shown.current = null;
|
|
3861
|
+
}, []);
|
|
3627
3862
|
return { Component, loading, error };
|
|
3628
3863
|
}
|
|
3864
|
+
var IN_APP_SCRIPT = "embed/bundle.js";
|
|
3865
|
+
var IN_APP_STYLESHEET = "embed/bundle.css";
|
|
3866
|
+
var publishedBundles = /* @__PURE__ */ new Map();
|
|
3867
|
+
var publishedComponents = /* @__PURE__ */ new Map();
|
|
3868
|
+
registerCleanup(() => {
|
|
3869
|
+
publishedBundles.clear();
|
|
3870
|
+
publishedComponents.clear();
|
|
3871
|
+
});
|
|
3872
|
+
function plainRecord(value) {
|
|
3873
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
3874
|
+
}
|
|
3875
|
+
function liveRelease(source) {
|
|
3876
|
+
const published = plainRecord(plainRecord(source.type_data).published);
|
|
3877
|
+
const releaseItemId = published.published_release_item_id;
|
|
3878
|
+
const version = published.published_version;
|
|
3879
|
+
if (typeof releaseItemId !== "string" || !releaseItemId) return null;
|
|
3880
|
+
if (typeof version !== "number" || !Number.isSafeInteger(version) || version < 1) return null;
|
|
3881
|
+
return { releaseItemId, version };
|
|
3882
|
+
}
|
|
3883
|
+
async function readSealedFile(file, sha256, what) {
|
|
3884
|
+
const envelope = await fetchOpenEnvelope(file.path, { mode: "render" });
|
|
3885
|
+
const url = plainRecord(plainRecord(envelope.render).props).url;
|
|
3886
|
+
if (typeof url !== "string" || !url) throw new Error(`The published ${what} could not be opened.`);
|
|
3887
|
+
const response = await fetch(url);
|
|
3888
|
+
if (!response.ok) {
|
|
3889
|
+
throw new Error(`Failed to read the published ${what}: ${response.status} ${response.statusText}`.trim());
|
|
3890
|
+
}
|
|
3891
|
+
const bytes = await response.arrayBuffer();
|
|
3892
|
+
const digest = Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", bytes))).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
3893
|
+
if (digest !== sha256) throw new Error(`The published ${what} does not match the bytes its release sealed.`);
|
|
3894
|
+
return new TextDecoder().decode(bytes);
|
|
3895
|
+
}
|
|
3896
|
+
async function readPublishedBundle(componentId, releaseItemId, version) {
|
|
3897
|
+
const release = await fetchVfsItemById(releaseItemId);
|
|
3898
|
+
if (!release) throw new Error("The published release could not be read.");
|
|
3899
|
+
const record = plainRecord(release.type_data);
|
|
3900
|
+
if (release.item_type !== "revdev_release" || record.component_item_id !== componentId || record.status !== "committed" || Number(record.version) !== version) {
|
|
3901
|
+
throw new Error("This component's live version does not match its release record.");
|
|
3902
|
+
}
|
|
3903
|
+
const artifacts = plainRecord(record.artifacts);
|
|
3904
|
+
const scriptSha = plainRecord(artifacts[IN_APP_SCRIPT]).sha256;
|
|
3905
|
+
if (typeof scriptSha !== "string" || !scriptSha) return { status: "no_in_app_version", releaseItemId, version };
|
|
3906
|
+
const stylesheetSha = plainRecord(artifacts[IN_APP_STYLESHEET]).sha256;
|
|
3907
|
+
const wanted = typeof stylesheetSha === "string" && stylesheetSha ? [IN_APP_SCRIPT, IN_APP_STYLESHEET] : [IN_APP_SCRIPT];
|
|
3908
|
+
const buildItemId = record.build_item_id;
|
|
3909
|
+
if (typeof buildItemId !== "string" || !buildItemId) throw new Error("The published release names no build.");
|
|
3910
|
+
const { items } = await fetchItems(
|
|
3911
|
+
{ type: "file", parent_id: buildItemId, field_in: { package_path: wanted }, limit: wanted.length },
|
|
3912
|
+
{ throwOnError: true }
|
|
3913
|
+
);
|
|
3914
|
+
const fileAt = (path) => items.find((item) => plainRecord(item.type_data).package_path === path);
|
|
3915
|
+
const scriptFile = fileAt(IN_APP_SCRIPT);
|
|
3916
|
+
const stylesheetFile = wanted.length > 1 ? fileAt(IN_APP_STYLESHEET) : void 0;
|
|
3917
|
+
if (!scriptFile || wanted.length > 1 && !stylesheetFile) {
|
|
3918
|
+
throw new Error("The published release's in-app files could not be found in its build.");
|
|
3919
|
+
}
|
|
3920
|
+
const [script, stylesheet] = await Promise.all([
|
|
3921
|
+
readSealedFile(scriptFile, scriptSha, "script"),
|
|
3922
|
+
stylesheetFile ? readSealedFile(stylesheetFile, stylesheetSha, "stylesheet") : Promise.resolve(null)
|
|
3923
|
+
]);
|
|
3924
|
+
return { status: "ready", releaseItemId, version, script, stylesheet: stylesheet?.trim() ? stylesheet : null };
|
|
3925
|
+
}
|
|
3926
|
+
function publishedBundle(componentId, releaseItemId, version) {
|
|
3927
|
+
let pending3 = publishedBundles.get(releaseItemId);
|
|
3928
|
+
if (!pending3) {
|
|
3929
|
+
pending3 = readPublishedBundle(componentId, releaseItemId, version);
|
|
3930
|
+
publishedBundles.set(releaseItemId, pending3);
|
|
3931
|
+
pending3.catch(() => {
|
|
3932
|
+
if (publishedBundles.get(releaseItemId) === pending3) publishedBundles.delete(releaseItemId);
|
|
3933
|
+
});
|
|
3934
|
+
}
|
|
3935
|
+
return pending3;
|
|
3936
|
+
}
|
|
3937
|
+
function loadPublishedBundle(source) {
|
|
3938
|
+
const live = liveRelease(source);
|
|
3939
|
+
if (!source.id || !live) return Promise.resolve({ status: "unpublished" });
|
|
3940
|
+
return publishedBundle(source.id, live.releaseItemId, live.version);
|
|
3941
|
+
}
|
|
3942
|
+
function usePublishedComponent(item) {
|
|
3943
|
+
const [onScreen, setOnScreen] = useState(null);
|
|
3944
|
+
const [status, setStatus] = useState("loading");
|
|
3945
|
+
const [error, setError] = useState(null);
|
|
3946
|
+
const shown = useRef(null);
|
|
3947
|
+
const known = item != null;
|
|
3948
|
+
const componentId = item?.id || null;
|
|
3949
|
+
const live = item ? liveRelease(item) : null;
|
|
3950
|
+
const releaseItemId = live?.releaseItemId ?? null;
|
|
3951
|
+
const version = live?.version ?? null;
|
|
3952
|
+
useEffect(() => {
|
|
3953
|
+
if (!known) return;
|
|
3954
|
+
const takeDown = () => {
|
|
3955
|
+
if (shown.current?.cssKey) releaseComponentCss(shown.current.cssKey);
|
|
3956
|
+
shown.current = null;
|
|
3957
|
+
setOnScreen(null);
|
|
3958
|
+
};
|
|
3959
|
+
if (!componentId || !releaseItemId || version === null) {
|
|
3960
|
+
takeDown();
|
|
3961
|
+
setError(null);
|
|
3962
|
+
setStatus("unpublished");
|
|
3963
|
+
return;
|
|
3964
|
+
}
|
|
3965
|
+
let cancelled = false;
|
|
3966
|
+
setError(null);
|
|
3967
|
+
if (shown.current && shown.current.componentId !== componentId) takeDown();
|
|
3968
|
+
if (!shown.current) setStatus("loading");
|
|
3969
|
+
(async () => {
|
|
3970
|
+
let heldCssKey = null;
|
|
3971
|
+
try {
|
|
3972
|
+
const bundle = await publishedBundle(componentId, releaseItemId, version);
|
|
3973
|
+
if (cancelled) return;
|
|
3974
|
+
if (bundle.status !== "ready") {
|
|
3975
|
+
takeDown();
|
|
3976
|
+
setStatus(bundle.status);
|
|
3977
|
+
return;
|
|
3978
|
+
}
|
|
3979
|
+
let resolved = publishedComponents.get(releaseItemId);
|
|
3980
|
+
if (!resolved) {
|
|
3981
|
+
resolved = evaluateBundle(bundle.script);
|
|
3982
|
+
if (!resolved) {
|
|
3983
|
+
throw new Error(
|
|
3984
|
+
"The published script did not hand over a component. Expected a __FSAOS_REGISTER__(Component) call or window.__FSAOS_COMPONENT__."
|
|
3985
|
+
);
|
|
3986
|
+
}
|
|
3987
|
+
if (typeof resolved !== "function") {
|
|
3988
|
+
throw new Error(`The published script handed over something that is not a React component (${typeof resolved}).`);
|
|
3989
|
+
}
|
|
3990
|
+
publishedComponents.set(releaseItemId, resolved);
|
|
3991
|
+
}
|
|
3992
|
+
const cssKey = bundle.stylesheet ? `release:${releaseItemId}` : null;
|
|
3993
|
+
if (cssKey) {
|
|
3994
|
+
heldCssKey = cssKey;
|
|
3995
|
+
await holdComponentCss(cssKey, async () => bundle.stylesheet);
|
|
3996
|
+
}
|
|
3997
|
+
if (cancelled) {
|
|
3998
|
+
if (heldCssKey) releaseComponentCss(heldCssKey);
|
|
3999
|
+
return;
|
|
4000
|
+
}
|
|
4001
|
+
const previousCssKey = shown.current?.cssKey ?? null;
|
|
4002
|
+
shown.current = { componentId, releaseItemId, cssKey };
|
|
4003
|
+
heldCssKey = null;
|
|
4004
|
+
setOnScreen({ Component: resolved, version });
|
|
4005
|
+
setStatus("ready");
|
|
4006
|
+
if (previousCssKey) releaseComponentCss(previousCssKey);
|
|
4007
|
+
} catch (err) {
|
|
4008
|
+
if (heldCssKey) releaseComponentCss(heldCssKey);
|
|
4009
|
+
if (cancelled) return;
|
|
4010
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
4011
|
+
if (!shown.current) setStatus("error");
|
|
4012
|
+
}
|
|
4013
|
+
})();
|
|
4014
|
+
return () => {
|
|
4015
|
+
cancelled = true;
|
|
4016
|
+
};
|
|
4017
|
+
}, [known, componentId, releaseItemId, version]);
|
|
4018
|
+
useEffect(() => () => {
|
|
4019
|
+
if (shown.current?.cssKey) releaseComponentCss(shown.current.cssKey);
|
|
4020
|
+
shown.current = null;
|
|
4021
|
+
}, []);
|
|
4022
|
+
return {
|
|
4023
|
+
Component: onScreen?.Component ?? null,
|
|
4024
|
+
status,
|
|
4025
|
+
error,
|
|
4026
|
+
/** The version on screen. */
|
|
4027
|
+
version: onScreen?.version ?? null
|
|
4028
|
+
};
|
|
4029
|
+
}
|
|
3629
4030
|
var THEME_PROPERTIES = [
|
|
3630
4031
|
"--color-primary",
|
|
3631
4032
|
"--color-secondary",
|
|
@@ -3797,9 +4198,6 @@ function usePrincipal() {
|
|
|
3797
4198
|
error: null
|
|
3798
4199
|
};
|
|
3799
4200
|
}
|
|
3800
|
-
function useTool() {
|
|
3801
|
-
return { data: null, loading: false, error: null };
|
|
3802
|
-
}
|
|
3803
4201
|
function ComponentRenderer(props) {
|
|
3804
4202
|
const { path, ...rest } = props;
|
|
3805
4203
|
const result = useComponent(path);
|
|
@@ -6366,6 +6764,6 @@ function usePersonalSections(contextId, collection) {
|
|
|
6366
6764
|
// src/index.ts
|
|
6367
6765
|
__registerSdkExports(src_exports);
|
|
6368
6766
|
|
|
6369
|
-
export { CHANNEL_AI_MODES, ComponentRenderer, EnforcementDeniedError, FormSubmissionError, GatewayRequestError, InteractionTrackingError, KernelProvider, acceptInvite, answerInput, assignPersonalSection, auth, awaitAnchorReady, awaitScopeReady, callTool, cancelQueuedTurn, cancelTurn, clearCachedToken, clearSession, configureGatewayReads, createAgent, createItem, disconnectSSE, disposeVfsRealtimeWs, electHomeAnchor, emitEvent, fetchChannelMessages, fetchChannelMessagesPage, fetchChannelMessagesWithCards, fetchEdgesForItem, fetchItemHistory, fetchItemVersions, fetchItems, fetchMemberFocus, fetchOpenEnvelope, fetchRecentActivity, fetchResolvedItems, fetchTimelineHistory, fetchTurnQueueEntries, fetchTypeDefinitions, fetchVfsChildren, fetchVfsChildrenPage, fetchVfsItem, fetchVfsItemById, fetchVfsTree, gatewayCall, getAccessToken, getAnchor, getAnchorRef, getAnchorVersion, getAssetUrl, getDefaultSort, getHomeAnchor, getMountVersion, getMounts, getPathSubscriptionState, getQueryClient, getRequiredFormFields, getScope, getScopeVersion, getServerClockOffsetMs, getServerClockSyncedAt, getSessionEntry, hasServerClock, initSession, initVfsRealtimeWs, initializeFsaos, initializeWorkspace, interpretSchema, invalidateAllVfs, invalidateChannelMessages, invalidateChildren, invalidateItem, invalidateOpenEnvelope, invalidatePathAndParent, invalidateSubtree, invalidateTypes, inviteMember, isAnchorReady, isChannelPath, isListableItemsFilter, isScopeReady, itemsFilterFromQueryFilter, listChildren, loadMounts, mount2 as mount, mountRealtimeScope, normalizeItem, onConnectionStateChange, pathSubscriptionMatches, personalSectionsKey, ping, pushChanges, queryClient, readItem, refreshQuery, registerCleanup, replaceMounts, resetAllSdkState, resolvePrincipalId, resubscribePath, seatMember, selectMount, serverDeadlinePassed, serverMsUntil, serverNow, setAnchor, setCachedToken, setQueryClient, setScope, setupRequireShim, signal, startTracking, steerTurn, submitForm, subscribeAnchor, subscribeArtifactStream, subscribeMounts, subscribeScope, subscribeToEvents, subscribeToPath, subscribeToScope, trackAction, trackEvent, trackPageView, unmountRealtimeScope, updateItem, uploadFile, useAcceptInvite, useAccounts, useAgentTimeline, useAllChannels, useAnswerInput, useArrangement, useArtifactStream, useAsset, useAuth, useChannelMessages, useChannels, useChildren, useComponent, useCreate, useCreateAgent, useDelete, useDmChannels, useEdges, useEventStream, useFileUpload, useIncrementalItems, useInfiniteChannelMessages, useInfiniteChildren, useInfiniteItems, useInviteMember, useItem, useItemById, useItemHistory, useItemVersions, useItems, useLink, useList, useMemberFocus, useMintedAsset, useMounts, useMove, useMutation, useNotifications, useOpen, usePermission, usePermissions, usePersonalItemOrder, usePersonalSections, usePinnedItems, usePrincipal, useRealtimeQuery, useRecentActivity, useResolve, useResolvedItems, useScope, useScopeReady, useSearch, useSeatMember, useTheme, useTimelineHistory,
|
|
6767
|
+
export { CHANNEL_AI_MODES, ComponentRenderer, EnforcementDeniedError, FormSubmissionError, GatewayRequestError, InteractionTrackingError, KernelProvider, acceptInvite, answerInput, assignPersonalSection, auth, awaitAnchorReady, awaitScopeReady, callTool, cancelQueuedTurn, cancelTurn, clearCachedToken, clearSession, configureGatewayReads, createAgent, createItem, disconnectSSE, disposeVfsRealtimeWs, electHomeAnchor, emitEvent, fetchChannelMessages, fetchChannelMessagesPage, fetchChannelMessagesWithCards, fetchEdgesForItem, fetchItemHistory, fetchItemVersions, fetchItems, fetchMemberFocus, fetchOpenEnvelope, fetchRecentActivity, fetchResolvedItems, fetchTimelineHistory, fetchTurnQueueEntries, fetchTypeDefinitions, fetchVfsChildren, fetchVfsChildrenPage, fetchVfsItem, fetchVfsItemById, fetchVfsTree, gatewayCall, getAccessToken, getAnchor, getAnchorRef, getAnchorVersion, getAssetUrl, getDefaultSort, getHomeAnchor, getMountVersion, getMounts, getPathSubscriptionState, getQueryClient, getRequiredFormFields, getScope, getScopeVersion, getServerClockOffsetMs, getServerClockSyncedAt, getSessionEntry, hasServerClock, initSession, initVfsRealtimeWs, initializeFsaos, initializeWorkspace, interpretSchema, invalidateAllVfs, invalidateChannelMessages, invalidateChildren, invalidateItem, invalidateOpenEnvelope, invalidatePathAndParent, invalidateSubtree, invalidateTypes, inviteMember, isAnchorReady, isChannelPath, isListableItemsFilter, isScopeReady, itemsFilterFromQueryFilter, listChildren, loadMounts, loadPublishedBundle, mount2 as mount, mountRealtimeScope, normalizeItem, onConnectionStateChange, pathSubscriptionMatches, personalSectionsKey, ping, pushChanges, queryClient, readItem, refreshQuery, registerCleanup, replaceMounts, resetAllSdkState, resolvePrincipalId, resubscribePath, seatMember, selectMount, serverDeadlinePassed, serverMsUntil, serverNow, setAnchor, setCachedToken, setQueryClient, setScope, setupRequireShim, signal, startTracking, steerTurn, submitForm, subscribeAnchor, subscribeArtifactStream, subscribeMounts, subscribeScope, subscribeToEvents, subscribeToPath, subscribeToScope, trackAction, trackEvent, trackPageView, unmountRealtimeScope, updateItem, uploadFile, useAcceptInvite, useAccounts, useAgentTimeline, useAllChannels, useAnswerInput, useArrangement, useArtifactStream, useAsset, useAuth, useChannelMessages, useChannels, useChildren, useComponent, useCreate, useCreateAgent, useDelete, useDmChannels, useEdges, useEventStream, useFileUpload, useIncrementalItems, useInfiniteChannelMessages, useInfiniteChildren, useInfiniteItems, useInviteMember, useItem, useItemById, useItemHistory, useItemVersions, useItems, useLink, useList, useMemberFocus, useMintedAsset, useMounts, useMove, useMutation, useNotifications, useOpen, usePermission, usePermissions, usePersonalItemOrder, usePersonalSections, usePinnedItems, usePrincipal, usePublishedComponent, useRealtimeQuery, useRecentActivity, useResolve, useResolvedItems, useScope, useScopeReady, useSearch, useSeatMember, useTheme, useTimelineHistory, useTree, useType, useTypeHelpers, useTypes, useUnreadCounts, useUpdate, useUpdatePrincipal, vfsKeys, waitForPathReady };
|
|
6370
6768
|
//# sourceMappingURL=index.js.map
|
|
6371
6769
|
//# sourceMappingURL=index.js.map
|