@hosty-sdk/app 0.39.0 → 0.42.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 +4 -2
- package/dist/decisions-server.d.ts +6 -0
- package/dist/decisions-server.js +21 -0
- package/dist/decisions.d.ts +140 -0
- package/dist/decisions.js +53 -0
- package/dist/feedback-capture.d.ts +5 -1
- package/dist/feedback-capture.js +41 -2
- package/dist/feedback-channel.d.ts +91 -0
- package/dist/feedback-channel.js +187 -0
- package/dist/feedback-client.d.ts +8 -0
- package/dist/feedback-client.js +26 -0
- package/dist/feedback-draft.d.ts +1 -5
- package/dist/feedback-draft.js +0 -31
- package/dist/feedback-react.d.ts +6 -2
- package/dist/feedback-react.js +235 -357
- package/dist/feedback-rpc.d.ts +7 -0
- package/dist/feedback-rpc.js +42 -0
- package/dist/feedback-workspace.d.ts +13 -0
- package/dist/feedback-workspace.js +28 -0
- package/dist/sdk-chrome.d.ts +1 -1
- package/dist/sdk-chrome.js +4 -0
- package/dist/tasks.d.ts +4 -0
- package/dist/tasks.js +2 -0
- package/dist/ui-embedded.d.ts +10 -0
- package/dist/ui-embedded.js +61 -0
- package/dist/ui-frame.js +1 -0
- package/dist/ui-host.d.ts +15 -2
- package/dist/ui-host.js +128 -27
- package/dist/ui-navigation-react.js +9 -4
- package/dist/ui-react.d.ts +5 -1
- package/dist/ui-react.js +59 -15
- package/dist/ui-server.d.ts +2 -0
- package/dist/ui-server.js +28 -3
- package/dist/ui-standalone-context.d.ts +8 -0
- package/dist/ui-standalone-context.js +3 -0
- package/dist/ui-standalone-preferences.d.ts +17 -0
- package/dist/ui-standalone-preferences.js +77 -0
- package/dist/ui-standalone-react.d.ts +24 -0
- package/dist/ui-standalone-react.js +47 -0
- package/dist/ui-transport.js +1 -1
- package/dist/ui-types.d.ts +5 -0
- package/dist/ui-workspaces.d.ts +7 -0
- package/dist/ui-workspaces.js +1 -1
- package/dist/ui.d.ts +1 -0
- package/package.json +13 -1
- package/dist/feedback-audio.d.ts +0 -3
- package/dist/feedback-audio.js +0 -40
- package/dist/feedback-speech.d.ts +0 -6
- package/dist/feedback-speech.js +0 -119
|
@@ -4,12 +4,14 @@ import { useContext, useEffect, useLayoutEffect, useRef, useState, useSyncExtern
|
|
|
4
4
|
import { SdkChromeStyles, SdkIcon } from "./sdk-chrome.js";
|
|
5
5
|
import { ui, createPresentationRequestId } from "./ui.js";
|
|
6
6
|
import { INITIAL_CHROME, INITIAL_NAVIGATION } from "./ui-composition.js";
|
|
7
|
+
import { StandaloneNavigationContext } from "./ui-standalone-context.js";
|
|
7
8
|
import { UiCompositionContext } from "./ui-context.js";
|
|
8
9
|
import { UI_COMPOSITION_CAPABILITY } from "./ui-types.js";
|
|
9
10
|
export function useHostyChrome() { return useSyncExternalStore(ui.subscribeChrome, ui.getChrome, () => INITIAL_CHROME); }
|
|
10
11
|
export function useHostyNavigation() { return useSyncExternalStore(ui.subscribeNavigation, ui.getNavigation, () => INITIAL_NAVIGATION); }
|
|
11
12
|
export function HostyNavigationBoundary({ children, className }) {
|
|
12
|
-
const chrome = useHostyChrome(),
|
|
13
|
+
const chrome = useHostyChrome(), standalone = useContext(StandaloneNavigationContext), ref = useRef(null);
|
|
14
|
+
const hidden = chrome.navigation === "hide" || !!standalone?.collapsed && !standalone.narrow;
|
|
13
15
|
const focused = useRef(false);
|
|
14
16
|
useLayoutEffect(() => { if (hidden && focused.current) {
|
|
15
17
|
document.querySelector('[data-hosty-content][tabindex="-1"]')?.focus();
|
|
@@ -31,8 +33,11 @@ export function HostyToolLauncher() {
|
|
|
31
33
|
export function HostyNavigation({ className = "" }) {
|
|
32
34
|
const composition = useContext(UiCompositionContext);
|
|
33
35
|
const model = useHostyNavigation(), chrome = useHostyChrome();
|
|
34
|
-
const
|
|
35
|
-
const [
|
|
36
|
+
const standalone = useContext(StandaloneNavigationContext);
|
|
37
|
+
const [localExpanded, setLocalExpanded] = useState(false), [error, setError] = useState(null);
|
|
38
|
+
const [viewportNarrow, setNarrow] = useState(false), dialog = useRef(null), localOpener = useRef(null);
|
|
39
|
+
const narrow = standalone?.narrow ?? viewportNarrow, expanded = standalone?.open ?? localExpanded;
|
|
40
|
+
const setExpanded = standalone?.setOpen ?? setLocalExpanded, opener = standalone?.opener ?? localOpener;
|
|
36
41
|
useEffect(() => { const resize = () => setNarrow(window.innerWidth < 900); resize(); window.addEventListener("resize", resize); return () => window.removeEventListener("resize", resize); }, []);
|
|
37
42
|
useEffect(() => {
|
|
38
43
|
const modal = (event) => { if (event.detail !== "navigation")
|
|
@@ -72,7 +77,7 @@ export function HostyNavigation({ className = "" }) {
|
|
|
72
77
|
}, children: [entry.icon && _jsx("img", { src: entry.icon, alt: "", width: 18, height: 18 }), _jsx("span", { children: entry.label })] }, entry.key)), error && _jsx("p", { role: "status", children: error })] });
|
|
73
78
|
if (empty)
|
|
74
79
|
return null;
|
|
75
|
-
return _jsxs(HostyNavigationBoundary, { children: [_jsx(SdkChromeStyles, {}), _jsx("style", { children: navigationStyles }), _jsx("div", { "data-hosty-sdk": true, className: `hosty-navigation ${className}`, children: narrow ? _jsxs(_Fragment, { children: [_jsx("button", { ref: opener, type: "button", "aria-label": "Page navigation", "aria-expanded": expanded, onClick: () => setExpanded(true), children: _jsx(SdkIcon, { name: "menu" }) }), _jsxs("dialog", { "data-hosty-sdk": true, ref: dialog, className: "hosty-navigation-dialog", "aria-label": "Page navigation", onCancel: () => setExpanded(false), children: [_jsx("button", { type: "button", onClick: () => setExpanded(false), children: "Close navigation" }), _jsx("nav", { "aria-label": "App pages", children: links })] })] }) : _jsx("nav", { "aria-label": "App pages", children: links }) })] });
|
|
80
|
+
return _jsxs(HostyNavigationBoundary, { children: [_jsx(SdkChromeStyles, {}), _jsx("style", { children: navigationStyles }), _jsx("div", { "data-hosty-sdk": true, className: `hosty-navigation ${className}`, style: standalone && narrow ? { padding: 0, flex: "0 0 0" } : undefined, children: narrow ? _jsxs(_Fragment, { children: [!standalone && _jsx("button", { ref: opener, type: "button", "aria-label": "Page navigation", "aria-expanded": expanded, onClick: () => setExpanded(true), children: _jsx(SdkIcon, { name: "menu" }) }), _jsxs("dialog", { "data-hosty-sdk": true, ref: dialog, className: "hosty-navigation-dialog", "aria-label": "Page navigation", onCancel: () => setExpanded(false), children: [_jsx("button", { type: "button", onClick: () => setExpanded(false), children: "Close navigation" }), _jsx("nav", { "aria-label": "App pages", children: links })] })] }) : _jsx("nav", { "aria-label": "App pages", children: links }) })] });
|
|
76
81
|
}
|
|
77
82
|
const navigationStyles = `
|
|
78
83
|
[data-hosty-navigation=hide] [data-hosty-navigation-boundary]{display:none!important}
|
package/dist/ui-react.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { HostyFeedbackLauncher, useHostyFeedback } from "./feedback-workspace.js";
|
|
1
2
|
import { type ReactNode } from "react";
|
|
2
3
|
import { type UiClient } from "./ui.js";
|
|
3
4
|
import { type UiHost } from "./ui-host.js";
|
|
@@ -21,6 +22,9 @@ export declare function HostyUiRoot({ children, uiPath, panelLayout, active, chr
|
|
|
21
22
|
}): import("react").JSX.Element;
|
|
22
23
|
export type HostyPanelWorkspaceProps = {
|
|
23
24
|
workspaceId?: string;
|
|
25
|
+
/** Automatic standalone chrome; explicit host renderers retain the rail by default. */
|
|
26
|
+
launcherLayout?: "rail" | "topbar";
|
|
27
|
+
standardNavigation?: boolean;
|
|
24
28
|
/** A host-owned tool window can keep dock geometry even in a narrow container. */
|
|
25
29
|
layout?: "responsive" | "dock";
|
|
26
30
|
/** Keep a visible dismiss control in drawers; hosts with a tool rail can omit it in docks. */
|
|
@@ -44,4 +48,4 @@ export type HostyPanelWorkspaceProps = {
|
|
|
44
48
|
renderIcon?: (panel: UiPanel) => ReactNode;
|
|
45
49
|
};
|
|
46
50
|
/** A single retained frame tree for dock and drawer; only CSS placement changes at the breakpoint. */
|
|
47
|
-
export declare function HostyPanelWorkspace({ children, workspaceId, layout, minimizeControl, railMode, className, initialWidth, initialExpanded, onWidthChange, onExpandedChange, onStartApp, onAskAssistant, onAuthRequired, outbound, renderIcon }: HostyPanelWorkspaceProps): import("react").JSX.Element;
|
|
51
|
+
export declare function HostyPanelWorkspace({ children, workspaceId, layout, launcherLayout, standardNavigation, minimizeControl, railMode, className, initialWidth, initialExpanded, onWidthChange, onExpandedChange, onStartApp, onAskAssistant, onAuthRequired, outbound, renderIcon }: HostyPanelWorkspaceProps): import("react").JSX.Element;
|
package/dist/ui-react.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { StandaloneChrome, StandaloneHeader, useStandalonePreferences } from "./ui-standalone-react.js";
|
|
4
|
+
import { bindFeedbackClient } from "./feedback-client.js";
|
|
5
|
+
export { HostyFeedbackLauncher, useHostyFeedback } from "./feedback-workspace.js";
|
|
3
6
|
import { FeedbackCapture } from "./feedback-react.js";
|
|
4
7
|
import { SdkChromeStyles, SdkIcon } from "./sdk-chrome.js";
|
|
5
8
|
import { useContext, useEffect, useId, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
@@ -40,13 +43,14 @@ export function HostyUiRoot({ children, uiPath, panelLayout = "auto", active = t
|
|
|
40
43
|
client.setActive(activeRef.current);
|
|
41
44
|
client.composition.attachRouter(navigation?.router);
|
|
42
45
|
clientRef.current = client;
|
|
46
|
+
const releaseFeedback = bindFeedbackClient(client.connectFeedback);
|
|
43
47
|
const release = bindUiClient(client), stop = client.subscribe(event => { if (event.type === "environment")
|
|
44
48
|
setEnvironment(event.value); });
|
|
45
49
|
if (client instanceof EmbeddedUiClient)
|
|
46
50
|
setHost(null);
|
|
47
51
|
else
|
|
48
52
|
setHost(client);
|
|
49
|
-
return () => { stop(); release(); client.dispose(); clientRef.current = null; };
|
|
53
|
+
return () => { stop(); releaseFeedback(); release(); client.dispose(); clientRef.current = null; };
|
|
50
54
|
}, [uiPath]);
|
|
51
55
|
useEffect(() => { clientRef.current?.composition.configure(chrome ?? {}); }, [chrome]);
|
|
52
56
|
useEffect(() => { clientRef.current?.composition.attachRouter(navigation?.router); }, [navigation?.router]);
|
|
@@ -54,17 +58,20 @@ export function HostyUiRoot({ children, uiPath, panelLayout = "auto", active = t
|
|
|
54
58
|
if (allowed)
|
|
55
59
|
mounted.current = true;
|
|
56
60
|
const content = _jsxs("div", { className: "hosty-app-layout", children: [navigation?.renderer !== "custom" && _jsx(HostyNavigation, {}), _jsxs("div", { className: "hosty-app-content", "data-hosty-content": true, tabIndex: -1, children: [_jsx(HostyToolLauncher, {}), children] })] });
|
|
57
|
-
return _jsx(UiHostContext.Provider, { value: host, children: _jsx(UiCompositionContext.Provider, { value: clientRef.current?.composition ?? null, children: _jsxs(UiFrameLayerContext.Provider, { value: layer, children: [_jsx("style", { children: `.hosty-app-layout{display:flex;width:100%;height:100%;min-width:0;min-height:0}.hosty-app-content{flex:1;min-width:0;min-height:0;overflow:auto;outline:none}` }), _jsx("div", { hidden: !allowed, inert: !allowed, style: { display: allowed ? "contents" : "none" }, children: mounted.current && (panelLayout === "auto" && host ? _jsx(HostyPanelWorkspace, { children: content }) : content) }), !allowed && _jsxs("div", { "data-hosty-sdk": true, role: "status", className: "hosty-panel-notice", children: [_jsx(SdkChromeStyles, {}), environment?.connection === "blocked" ? _jsxs(_Fragment, { children: [_jsx("strong", { children: environment.code === "actor_mismatch" ? "Use the same Hosty account in this app and its host" : "Cannot verify this app’s host" }), _jsx("p", { children: "Check your account and access in Hosty Core, then reconnect. Your existing discussion is unchanged." }), _jsx("button", { type: "button", onClick: () => window.location.reload(), children: "Reconnect" })] }) : "Connecting to the workspace…"] }), _jsx(FeedbackCapture, { active: active && !!allowed, uiPath: uiPath }), host && _jsx(HostyPresentationLayer, { layer: layer, host: host, active: !!allowed })] }) }) });
|
|
61
|
+
return _jsx(UiHostContext.Provider, { value: host, children: _jsx(UiCompositionContext.Provider, { value: clientRef.current?.composition ?? null, children: _jsxs(UiFrameLayerContext.Provider, { value: layer, children: [_jsx("style", { children: `.hosty-app-layout{display:flex;width:100%;height:100%;min-width:0;min-height:0}.hosty-app-content{flex:1;min-width:0;min-height:0;overflow:auto;outline:none}` }), _jsx("div", { hidden: !allowed, inert: !allowed, style: { display: allowed ? "contents" : "none" }, children: mounted.current && (panelLayout === "auto" && host ? _jsx(StandaloneChrome, { navigation: navigation?.renderer !== "custom", children: _jsx(HostyPanelWorkspace, { launcherLayout: "topbar", standardNavigation: navigation?.renderer !== "custom", children: content }) }) : content) }), !allowed && _jsxs("div", { "data-hosty-sdk": true, role: "status", className: "hosty-panel-notice", children: [_jsx(SdkChromeStyles, {}), environment?.connection === "blocked" ? _jsxs(_Fragment, { children: [_jsx("strong", { children: environment.code === "actor_mismatch" ? "Use the same Hosty account in this app and its host" : "Cannot verify this app’s host" }), _jsx("p", { children: "Check your account and access in Hosty Core, then reconnect. Your existing discussion is unchanged." }), _jsx("button", { type: "button", onClick: () => window.location.reload(), children: "Reconnect" })] }) : "Connecting to the workspace…"] }), _jsx(FeedbackCapture, { active: active && !!allowed, uiPath: uiPath, client: clientRef.current }), host && _jsx(HostyPresentationLayer, { layer: layer, host: host, active: !!allowed })] }) }) });
|
|
58
62
|
}
|
|
59
63
|
const empty = { bootstrap: null, catalog: [], tools: [], selected: null, expanded: false, width: 360, error: null };
|
|
60
64
|
const noop = () => () => { };
|
|
61
65
|
/** A single retained frame tree for dock and drawer; only CSS placement changes at the breakpoint. */
|
|
62
|
-
export function HostyPanelWorkspace({ children, workspaceId = DEFAULT_WORKSPACE, layout = "responsive", minimizeControl = "always", railMode = "opened", className = "", initialWidth, initialExpanded, onWidthChange, onExpandedChange, onStartApp, onAskAssistant, onAuthRequired, outbound, renderIcon }) {
|
|
66
|
+
export function HostyPanelWorkspace({ children, workspaceId = DEFAULT_WORKSPACE, layout = "responsive", launcherLayout = "rail", standardNavigation = true, minimizeControl = "always", railMode = "opened", className = "", initialWidth, initialExpanded, onWidthChange, onExpandedChange, onStartApp, onAskAssistant, onAuthRequired, outbound, renderIcon }) {
|
|
63
67
|
const host = useHostyUiHost();
|
|
64
68
|
const layer = useContext(UiFrameLayerContext), chrome = useHostyChrome();
|
|
65
69
|
const viewport = useRef(null);
|
|
66
70
|
const state = useSyncExternalStore(host?.subscribeSnapshot ?? noop, host?.getSnapshot ?? (() => empty), () => empty);
|
|
67
71
|
const unsupported = state.error?.code.startsWith("unsupported") === true;
|
|
72
|
+
const standalone = launcherLayout === "topbar";
|
|
73
|
+
const topbar = standalone && !unsupported && (chrome.navigation === "show" || chrome.tools.enabled && chrome.tools.launcher !== "hide");
|
|
74
|
+
const preferences = useStandalonePreferences();
|
|
68
75
|
const workspace = state.workspaces?.find(w => w.workspaceId === workspaceId);
|
|
69
76
|
const workspaceTools = state.tools.filter(t => t.workspaceId === workspaceId);
|
|
70
77
|
const root = useRef(null), content = useRef(null), body = useRef(null), minimize = useRef(null);
|
|
@@ -72,6 +79,13 @@ export function HostyPanelWorkspace({ children, workspaceId = DEFAULT_WORKSPACE,
|
|
|
72
79
|
const [size, setSize] = useState(1200), [chooser, setChooser] = useState(false), [error, setError] = useState(null);
|
|
73
80
|
const chooserRef = useRef(null);
|
|
74
81
|
const bodyId = useId();
|
|
82
|
+
const expanded = !!workspace?.expanded && !!workspace.selectedId;
|
|
83
|
+
const tool = workspaceTools.find(t => t.presentationId === workspace?.selectedId);
|
|
84
|
+
const selectedKey = tool?.key ?? null;
|
|
85
|
+
const selected = state.catalog.find(p => panelKey(p.panel) === selectedKey);
|
|
86
|
+
const compact = layout === "responsive" && size < 900;
|
|
87
|
+
const stacked = compact && expanded && selected?.feedbackComposer === true;
|
|
88
|
+
const drawer = compact && !stacked;
|
|
75
89
|
useEffect(() => {
|
|
76
90
|
if (!host || !layer)
|
|
77
91
|
return;
|
|
@@ -102,24 +116,20 @@ export function HostyPanelWorkspace({ children, workspaceId = DEFAULT_WORKSPACE,
|
|
|
102
116
|
useLayoutEffect(() => {
|
|
103
117
|
if (!layer || !viewport.current)
|
|
104
118
|
return;
|
|
105
|
-
return layer.register(workspaceId, { element: viewport.current, drawer
|
|
106
|
-
}, [layer, workspaceId,
|
|
119
|
+
return layer.register(workspaceId, { element: viewport.current, drawer, onAskAssistant, onAuthRequired, outbound });
|
|
120
|
+
}, [layer, workspaceId, drawer, onAskAssistant, onAuthRequired, outbound]);
|
|
107
121
|
useEffect(() => {
|
|
108
122
|
const onModal = (event) => {
|
|
109
123
|
const kind = event.detail;
|
|
110
124
|
if (kind !== `picker:${workspaceId}`)
|
|
111
125
|
setChooser(false);
|
|
112
|
-
if (kind === "navigation" ||
|
|
126
|
+
if (kind === "navigation" || drawer && kind !== `tools:${workspaceId}` && kind !== `picker:${workspaceId}`)
|
|
113
127
|
host?.collapseWorkspace(workspaceId);
|
|
114
128
|
};
|
|
115
129
|
window.addEventListener("hosty:ui:modal", onModal);
|
|
116
130
|
return () => window.removeEventListener("hosty:ui:modal", onModal);
|
|
117
|
-
}, [host, workspaceId,
|
|
118
|
-
const drawer = layout === "responsive" && size < 900, expanded = !!workspace?.expanded && !!workspace.selectedId;
|
|
119
|
-
const tool = workspaceTools.find(t => t.presentationId === workspace?.selectedId);
|
|
120
|
-
const selectedKey = tool?.key ?? null;
|
|
131
|
+
}, [host, workspaceId, drawer]);
|
|
121
132
|
const tabs = railMode === "catalog" ? state.catalog : [...new Set(workspaceTools.map(tool => tool.key))].map(key => state.catalog.find(p => panelKey(p.panel) === key)).filter((p) => !!p);
|
|
122
|
-
const selected = state.catalog.find(p => panelKey(p.panel) === selectedKey);
|
|
123
133
|
const width = Math.min(workspace?.width ?? 360, Math.max(280, size - 480 - 60));
|
|
124
134
|
const optionsRef = useRef({ onWidthChange, onExpandedChange });
|
|
125
135
|
optionsRef.current = { onWidthChange, onExpandedChange };
|
|
@@ -245,14 +255,14 @@ export function HostyPanelWorkspace({ children, workspaceId = DEFAULT_WORKSPACE,
|
|
|
245
255
|
handle.addEventListener("pointerup", end);
|
|
246
256
|
handle.addEventListener("lostpointercapture", end);
|
|
247
257
|
};
|
|
248
|
-
return _jsxs("div", { ref: root, className: `hosty-panel-workspace ${className}`, "data-hosty-panel-layout": drawer ? "drawer" : "dock", style: { "--hosty-panel-width": `${width}px`, ...(unsupported ? { display: "contents" } : {}) }, children: [_jsx(SdkChromeStyles, {}), _jsx("style", { children: styles }), _jsx("div", { ref: content, className: "hosty-panel-document", style: unsupported ? { display: "contents" } : undefined, inert: expanded && drawer, children: children }), _jsxs("nav", { "data-hosty-sdk": true, className: "hosty-panel-rail", "aria-label": "Tools", style: unsupported || !chrome.tools.enabled || chrome.tools.launcher === "hide" ? { display: "none" } : undefined, inert:
|
|
258
|
+
return _jsxs("div", { ref: root, className: `hosty-panel-workspace ${topbar ? "hosty-panel-topbar" : ""} ${className}`, "data-hosty-panel-layout": stacked ? "stacked" : drawer ? "drawer" : "dock", style: { "--hosty-panel-width": `${width}px`, ...(unsupported && !topbar ? { display: "contents" } : {}) }, children: [_jsx(SdkChromeStyles, {}), _jsx("style", { children: styles }), topbar && _jsx(StandaloneHeader, { panels: state.catalog, selected: selectedKey, expanded: expanded, chooserOpen: chooser, canNavigate: standardNavigation, onSelect: panel => void select(panel), onChoose: () => { setError(null); setChooser(true); void host?.refresh(); }, attention: panel => workspaceTools.some(t => t.key === panelKey(panel.panel) && t.attention > 0) }), _jsx("div", { ref: content, className: "hosty-panel-document", style: unsupported ? { display: "contents" } : undefined, inert: expanded && drawer, children: children }), !standalone && _jsxs("nav", { "data-hosty-sdk": true, className: "hosty-panel-rail", "aria-label": "Tools", style: standalone || unsupported || !chrome.tools.enabled || chrome.tools.launcher === "hide" ? { display: "none" } : undefined, inert: expanded && drawer, children: [tabs.map((panel, index) => _jsxs("button", { type: "button", title: `${panel.appName}: ${panel.label}`, "aria-label": panel.label, "aria-controls": bodyId, "aria-expanded": expanded && selectedKey === panelKey(panel.panel), onClick: () => void select(panel), onKeyDown: event => {
|
|
249
259
|
const delta = event.key === "ArrowDown" ? 1 : event.key === "ArrowUp" ? -1 : 0;
|
|
250
260
|
const next = event.key === "Home" ? 0 : event.key === "End" ? tabs.length - 1 : delta ? (index + delta + tabs.length) % tabs.length : null;
|
|
251
261
|
if (next !== null) {
|
|
252
262
|
event.preventDefault();
|
|
253
263
|
event.currentTarget.parentElement?.children[next]?.focus();
|
|
254
264
|
}
|
|
255
|
-
}, children: [renderIcon?.(panel) ?? panel.label.slice(0, 2), workspaceTools.some(t => t.key === panelKey(panel.panel) && t.attention > 0) ? _jsx("span", { className: "hosty-panel-attention", "aria-label": "Needs attention", children: _jsx(SdkIcon, { name: "warning" }) }) : null] }, panelKey(panel.panel))), _jsx("button", { type: "button", "aria-label": "Add tool", title: "Add tool", onClick: () => { setError(null); setChooser(true); void host?.refresh(); }, children: _jsx(SdkIcon, { name: "plus" }) })] }), expanded && drawer && _jsx("button", { type: "button", className: "hosty-panel-backdrop", "aria-label": "Return to document", onClick: () => host?.setExpanded(false, workspaceId) }), _jsxs("aside", { "data-hosty-sdk": true, ref: body, id: bodyId, className: "hosty-panel-body", hidden: !expanded, inert: !expanded, role: drawer ? "dialog" : "complementary", "aria-modal": drawer && expanded ? true : undefined, "aria-label": selected?.label ?? "Tool", onKeyDown: event => {
|
|
265
|
+
}, children: [renderIcon?.(panel) ?? panel.label.slice(0, 2), workspaceTools.some(t => t.key === panelKey(panel.panel) && t.attention > 0) ? _jsx("span", { className: "hosty-panel-attention", "aria-label": "Needs attention", children: _jsx(SdkIcon, { name: "warning" }) }) : null] }, panelKey(panel.panel))), _jsx("button", { hidden: unsupported, type: "button", "aria-label": "Add tool", title: "Add tool", onClick: () => { setError(null); setChooser(true); void host?.refresh(); }, children: _jsx(SdkIcon, { name: "plus" }) })] }), expanded && drawer && _jsx("button", { type: "button", className: "hosty-panel-backdrop", "aria-label": "Return to document", onClick: () => host?.setExpanded(false, workspaceId) }), _jsxs("aside", { "data-hosty-sdk": true, ref: body, id: bodyId, className: "hosty-panel-body", hidden: !expanded, inert: !expanded, role: drawer ? "dialog" : "complementary", "aria-modal": drawer && expanded ? true : undefined, "aria-label": selected?.label ?? "Tool", onKeyDown: event => {
|
|
256
266
|
if (!drawer)
|
|
257
267
|
return;
|
|
258
268
|
if (event.key === "Escape") {
|
|
@@ -272,7 +282,7 @@ export function HostyPanelWorkspace({ children, workspaceId = DEFAULT_WORKSPACE,
|
|
|
272
282
|
(frame ?? first)?.focus();
|
|
273
283
|
}
|
|
274
284
|
}
|
|
275
|
-
}, children: [drawer && expanded && _jsx("span", { tabIndex: 0, "aria-hidden": "true", className: "hosty-panel-focus-guard", onFocus: () => presentationElement(workspace?.selectedId ?? "")?.querySelector("iframe")?.focus() }), _jsx("div", { className: "hosty-panel-resize", role: "separator", "aria-label": "Tool panel width", "aria-orientation": "vertical", tabIndex:
|
|
285
|
+
}, children: [drawer && expanded && _jsx("span", { tabIndex: 0, "aria-hidden": "true", className: "hosty-panel-focus-guard", onFocus: () => presentationElement(workspace?.selectedId ?? "")?.querySelector("iframe")?.focus() }), _jsx("div", { className: "hosty-panel-resize", role: "separator", "aria-label": "Tool panel width", "aria-orientation": "vertical", tabIndex: compact ? -1 : 0, "aria-valuemin": 280, "aria-valuemax": Math.max(280, Math.min(800, size - 540)), "aria-valuenow": width, onPointerDown: resize, onDoubleClick: () => host?.setWidth(360, workspaceId), onKeyDown: event => {
|
|
276
286
|
if (event.key === "Home") {
|
|
277
287
|
event.preventDefault();
|
|
278
288
|
host?.setWidth(360, workspaceId);
|
|
@@ -281,9 +291,38 @@ export function HostyPanelWorkspace({ children, workspaceId = DEFAULT_WORKSPACE,
|
|
|
281
291
|
event.preventDefault();
|
|
282
292
|
host?.setWidth(width + (event.key === "ArrowLeft" ? 16 : -16), workspaceId);
|
|
283
293
|
}
|
|
284
|
-
} }), _jsxs("header", { children: [_jsx("strong", { children: selected?.label ?? "Tool" }), tool?.resolved.standaloneHref && _jsx("a", { href: tool.resolved.standaloneHref, target: "_blank", rel: "noopener noreferrer", title: "Open separately", "aria-label": "Open separately", children: _jsx(SdkIcon, { name: "external" }) }), (
|
|
294
|
+
} }), _jsxs("header", { children: [_jsx("strong", { children: selected?.label ?? "Tool" }), tool?.resolved.standaloneHref && _jsx("a", { href: tool.resolved.standaloneHref, target: "_blank", rel: "noopener noreferrer", title: "Open separately", "aria-label": "Open separately", children: _jsx(SdkIcon, { name: "external" }) }), (compact || minimizeControl === "always") && _jsx("button", { ref: minimize, type: "button", onClick: () => host?.setExpanded(false, workspaceId), "aria-label": "Minimize panel", title: "Minimize panel (keep tool open)", children: _jsx(SdkIcon, { name: "minus" }) })] }), tool?.resolved.state === "degraded" && _jsx("div", { className: "hosty-panel-state", role: "status", children: "This app\u2019s health check is failing. Its page may still work." }), tool?.readiness === "unreported" && _jsxs("div", { className: "hosty-panel-state", role: "status", children: ["This tool has not confirmed that it loaded. If the page is blank or refuses to connect, use ", _jsx("a", { href: tool.resolved.standaloneHref ?? undefined, target: "_blank", rel: "noopener noreferrer", children: "Open separately" }), "."] }), tool?.readiness === "auth-required" && _jsx("div", { className: "hosty-panel-state", role: "status", children: "Check access in the tool below, then retry opening the discussion." }), tool && workspaceTools.filter(t => t.key === tool.key).length > 1 && _jsxs("label", { className: "hosty-panel-state", children: ["Open views", _jsx("select", { "aria-label": "Tool instance", value: tool.presentationId, onChange: event => host?.focusPresentation(event.target.value), children: workspaceTools.filter(t => t.key === tool.key).map((item, index) => _jsxs("option", { value: item.presentationId, children: [selected?.label ?? "Tool", " ", index + 1] }, item.presentationId)) })] }), _jsx("div", { ref: viewport, className: "hosty-panel-viewport", "aria-owns": tool ? `hosty-presentation-${tool.presentationId}` : undefined }), drawer && expanded && _jsx("span", { tabIndex: 0, "aria-hidden": "true", className: "hosty-panel-focus-guard", onFocus: () => minimize.current?.focus() })] }), _jsxs("dialog", { "data-hosty-sdk": true, ref: chooserRef, className: `hosty-tool-chooser ${standalone ? "hosty-tool-menu" : ""}`, onCancel: () => setChooser(false), "aria-label": standalone ? "Tools" : "Add tool", onClick: event => {
|
|
295
|
+
if (event.target !== event.currentTarget)
|
|
296
|
+
return;
|
|
297
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
298
|
+
if (event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom)
|
|
299
|
+
setChooser(false);
|
|
300
|
+
}, onKeyDown: event => {
|
|
301
|
+
if (!standalone || !["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key))
|
|
302
|
+
return;
|
|
303
|
+
const buttons = Array.from(event.currentTarget.querySelectorAll("button:not(:disabled)"));
|
|
304
|
+
const index = buttons.indexOf(document.activeElement);
|
|
305
|
+
const next = event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : (index + (event.key === "ArrowDown" ? 1 : -1) + buttons.length) % buttons.length;
|
|
306
|
+
event.preventDefault();
|
|
307
|
+
buttons[next]?.focus();
|
|
308
|
+
}, children: [_jsxs("header", { children: [_jsx("strong", { children: standalone ? "Tools" : "Add tool" }), _jsx("button", { type: "button", onClick: () => setChooser(false), "aria-label": "Close tool chooser", children: _jsx(SdkIcon, { name: "close" }) })] }), _jsx("p", { children: standalone ? "Pin tools to the top bar" : "Open a tool beside your document." }), standalone && preferences.error && _jsx("p", { role: "status", children: preferences.error }), error && _jsx("p", { role: "status", children: error }), state.error && _jsx("p", { role: "status", children: state.error.message }), !state.bootstrap?.canHost && _jsx("p", { children: "This app needs optional panel access in Hosty Core to show tools here. You can still use the app." }), state.bootstrap?.canHost && !state.catalog.length && _jsx("p", { children: "No tools are available for your account." }), _jsx("ul", { children: state.catalog.map(panel => _jsxs("li", { children: [_jsxs("button", { type: "button", className: "hosty-tool-option", onClick: () => void select(panel), children: [_jsx("strong", { children: panel.label }), _jsxs("span", { children: [panel.appName, panel.available ? "" : ` · ${panel.state}`] })] }), standalone && _jsx("button", { type: "button", className: "hosty-tool-pin", disabled: !preferences.ready, "aria-label": `Pin ${panel.appName} — ${panel.label} to top bar`, "aria-pressed": preferences.pins.includes(panelKey(panel.panel)), title: preferences.pins.includes(panelKey(panel.panel)) ? "Unpin from top bar" : "Pin to top bar", onClick: () => preferences.setPinned(panel, !preferences.pins.includes(panelKey(panel.panel))), children: _jsx(SdkIcon, { name: "pin" }) }), !panel.available && panel.canStart && onStartApp && _jsx("button", { type: "button", onClick: () => void Promise.resolve(onStartApp(panel.panel.appId)).then(() => host?.refresh()), children: "Start app" })] }, panelKey(panel.panel))) }), _jsx("button", { type: "button", onClick: () => void host?.refresh(), children: "Refresh tools" })] }), error && !chooser && _jsxs("div", { "data-hosty-sdk": true, className: "hosty-panel-error", role: "status", children: [error, " ", _jsx("button", { type: "button", onClick: () => { setChooser(true); setError(null); }, children: "Choose tool" })] })] });
|
|
285
309
|
}
|
|
286
310
|
const styles = `
|
|
311
|
+
.hosty-panel-topbar{display:grid!important;grid-template-columns:minmax(0,1fr) auto;grid-template-rows:44px minmax(0,1fr)}
|
|
312
|
+
.hosty-standalone-header{grid-column:1/-1;grid-row:1;display:flex;align-items:center;gap:16px;padding:0 10px;background:var(--hs-bg);border-bottom:1px solid var(--hs-border);min-width:0}
|
|
313
|
+
.hosty-standalone-identity{display:flex;align-items:center;gap:8px;min-width:0;flex:1}.hosty-standalone-identity strong{font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.hosty-standalone-identity>img{width:22px;height:22px;object-fit:contain;flex:none}
|
|
314
|
+
.hosty-standalone-header button{position:relative;display:inline-flex;align-items:center;justify-content:center;gap:6px;border:0;border-radius:6px;min-height:30px;padding:5px 8px;color:inherit;background:transparent;font:500 13px/20px var(--hs-font);cursor:pointer;white-space:nowrap;flex:none}
|
|
315
|
+
.hosty-standalone-header button:hover,.hosty-standalone-header button[aria-expanded=true]{background:var(--hs-brand-soft)}.hosty-standalone-header button:disabled{opacity:.5;cursor:not-allowed}
|
|
316
|
+
.hosty-standalone-tools,.hosty-pinned-tools{display:flex;align-items:center;gap:4px;min-width:0}.hosty-standalone-tools{max-width:70%}.hosty-pinned-tools{overflow:auto;padding:3px;scrollbar-width:thin}.hosty-pinned-tools button>span:not(.hosty-panel-attention){max-width:150px;overflow:hidden;text-overflow:ellipsis}
|
|
317
|
+
.hosty-panel-topbar>.hosty-panel-document{grid-column:1;grid-row:2}.hosty-panel-topbar>.hosty-panel-body{grid-column:2;grid-row:2;width:var(--hosty-panel-width)}
|
|
318
|
+
.hosty-panel-workspace.hosty-panel-topbar[data-hosty-panel-layout=drawer]>.hosty-panel-body{top:44px}.hosty-panel-topbar>.hosty-panel-backdrop{top:44px}
|
|
319
|
+
.hosty-panel-workspace.hosty-panel-topbar[data-hosty-panel-layout=stacked]{grid-template-rows:44px minmax(0,45fr) minmax(0,55fr)}
|
|
320
|
+
.hosty-panel-workspace.hosty-panel-topbar[data-hosty-panel-layout=stacked]>.hosty-panel-document{grid-column:1/-1;grid-row:2;height:auto}
|
|
321
|
+
.hosty-panel-workspace.hosty-panel-topbar[data-hosty-panel-layout=stacked]>.hosty-panel-body{grid-column:1/-1;grid-row:3;height:auto;width:auto}
|
|
322
|
+
.hosty-tool-chooser.hosty-tool-menu{position:fixed;inset:48px 8px auto auto;margin:0;width:min(360px,calc(100vw - 16px));max-height:calc(100dvh - 64px);padding:12px;border-radius:12px}.hosty-tool-chooser.hosty-tool-menu::backdrop{background:transparent}
|
|
323
|
+
.hosty-tool-menu li>.hosty-tool-pin{flex:0 0 36px;display:grid;place-items:center;padding:8px}.hosty-tool-menu li>.hosty-tool-pin[aria-pressed=true]{background:var(--hs-brand-soft);color:var(--hs-brand-edge)}.hosty-tool-menu .hosty-tool-option{min-width:0}.hosty-tool-menu .hosty-tool-option :is(strong,span){display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
324
|
+
@media(max-width:600px){.hosty-standalone-header{gap:6px}.hosty-pinned-tools button>span:not(.hosty-panel-attention){display:none}.hosty-standalone-tools{max-width:55%}.hosty-standalone-identity strong{font-size:13px}}
|
|
325
|
+
|
|
287
326
|
.hosty-panel-viewport{flex:1;min-height:0;min-width:0}
|
|
288
327
|
.hosty-app-layout{display:flex;width:100%;height:100%;min-width:0;min-height:0}.hosty-app-content{flex:1;min-width:0;min-height:0;overflow:auto}
|
|
289
328
|
.hosty-panel-workspace{display:flex;position:relative;min-width:0;min-height:0;width:100%;height:100dvh;overflow:hidden}
|
|
@@ -302,6 +341,11 @@ const styles = `
|
|
|
302
341
|
.hosty-panel-resize{position:absolute;left:-12px;top:0;bottom:0;width:12px;cursor:col-resize;touch-action:none}.hosty-panel-resize:hover{background:var(--hs-brand-soft)}
|
|
303
342
|
.hosty-panel-state{padding:8px 12px;font:400 13px/20px var(--hs-font);border-bottom:1px solid var(--hp-border);color:var(--hp-muted)}.hosty-panel-state a{color:var(--hs-info);text-decoration:underline;text-underline-offset:3px}.hosty-panel-state select{display:block;max-width:100%;margin-top:6px;padding:6px 10px;border:1px solid var(--hp-border);border-radius:8px;background:var(--hp-bg);color:var(--hp-fg)}
|
|
304
343
|
.hosty-panel-workspace[data-hosty-panel-layout=drawer] .hosty-panel-body{position:absolute;inset:0 0 0 auto;width:min(440px,100%);z-index:102;margin:0;box-shadow:-8px 0 30px #0F1B2D29}.hosty-panel-workspace[data-hosty-panel-layout=drawer] .hosty-panel-resize{display:none}
|
|
344
|
+
.hosty-panel-workspace[data-hosty-panel-layout=stacked]{flex-wrap:wrap}
|
|
345
|
+
.hosty-panel-workspace[data-hosty-panel-layout=stacked]>.hosty-panel-document{flex:1 1 calc(100% - 48px);height:45%}
|
|
346
|
+
.hosty-panel-workspace[data-hosty-panel-layout=stacked]>.hosty-panel-rail{order:1;height:45%}
|
|
347
|
+
.hosty-panel-workspace[data-hosty-panel-layout=stacked]>.hosty-panel-body{flex:1 1 100%;height:55%;margin:0;border-left:0;border-top:1px solid var(--hp-border)}
|
|
348
|
+
.hosty-panel-workspace[data-hosty-panel-layout=stacked] .hosty-panel-resize{display:none}
|
|
305
349
|
.hosty-panel-backdrop{position:absolute;inset:0;border:0;background:#0F1B2D57;z-index:101;cursor:pointer}.hosty-panel-backdrop:focus-visible{outline:2px solid #A3E635;outline-offset:-2px}
|
|
306
350
|
.hosty-tool-chooser{width:min(440px,calc(100vw - 32px));max-height:calc(100dvh - 32px);margin:auto;border:1px solid var(--hp-border);border-radius:14px;padding:20px;background:var(--hp-bg);color:var(--hp-fg);overflow:auto;box-shadow:0 14px 34px -8px #0F1B2D3D}.hosty-tool-chooser::backdrop{background:#0F1B2D57}.hosty-tool-chooser header{border:0;padding:0;min-height:32px}.hosty-tool-chooser>p{margin:12px 0;color:var(--hp-muted);font-size:13px}.hosty-tool-chooser ul{list-style:none;padding:0;margin:16px 0;display:grid;gap:8px}.hosty-tool-chooser li{display:flex;gap:8px}.hosty-tool-chooser li>button,.hosty-tool-chooser>button,.hosty-panel-error>button{font:500 14px/20px var(--hs-font);border:1px solid var(--hp-border);background:var(--hs-card);color:inherit;border-radius:8px;padding:8px 12px;cursor:pointer}.hosty-tool-chooser li>button{flex:1;text-align:left;padding:12px}.hosty-tool-chooser li>button:hover,.hosty-tool-chooser>button:hover,.hosty-panel-error>button:hover{background:var(--hs-brand-soft)}.hosty-tool-chooser li span{display:block;color:var(--hp-muted);font:400 13px/20px var(--hs-font)}.hosty-panel-error{position:absolute;bottom:16px;right:60px;max-width:calc(100% - 76px);z-index:4;border:1px solid var(--hp-border);border-radius:10px;padding:12px;font:400 13px/20px var(--hs-font);box-shadow:0 4px 14px -4px #0F1B2D29}.hosty-panel-error>button{margin:8px 0 0 8px}
|
|
307
351
|
`;
|
package/dist/ui-server.d.ts
CHANGED
|
@@ -6,10 +6,12 @@ export declare class UiServerClient {
|
|
|
6
6
|
private readonly core;
|
|
7
7
|
private readonly service;
|
|
8
8
|
constructor(options?: ProviderServerOptions);
|
|
9
|
+
private response;
|
|
9
10
|
private request;
|
|
10
11
|
bootstrap(options: {
|
|
11
12
|
parentOrigin?: string;
|
|
12
13
|
}, token: string, signal?: AbortSignal): Promise<UiBootstrap>;
|
|
14
|
+
icon(token: string, signal?: AbortSignal): Promise<Response>;
|
|
13
15
|
listPanels(token: string, signal?: AbortSignal): Promise<UiPanel[]>;
|
|
14
16
|
activity(token: string, signal?: AbortSignal): Promise<ToolActivity[]>;
|
|
15
17
|
navigation(token: string, signal?: AbortSignal): Promise<UiNavigationCatalog>;
|
package/dist/ui-server.js
CHANGED
|
@@ -15,15 +15,18 @@ export class UiServerClient {
|
|
|
15
15
|
if (!this.appId || !this.service)
|
|
16
16
|
throw new UiError("hosty_misconfigured", "Hosty app credentials are not configured.", 503);
|
|
17
17
|
}
|
|
18
|
-
async
|
|
18
|
+
async response(path, token, body, signal) {
|
|
19
19
|
if (!token)
|
|
20
20
|
throw new UiError("app_identity_required", "Sign in to use application panels.", 401);
|
|
21
|
-
|
|
21
|
+
return fetch(new URL(`/api/internal/apps/${encodeURIComponent(this.appId)}/ui/${path}`, this.core), {
|
|
22
22
|
method: body === undefined ? "GET" : "POST", redirect: "error", cache: "no-store",
|
|
23
23
|
signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(10_000)]) : AbortSignal.timeout(10_000),
|
|
24
24
|
headers: { authorization: `Bearer ${this.service}`, "X-Hosty-User-Token": token, "content-type": "application/json" },
|
|
25
25
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
26
26
|
});
|
|
27
|
+
}
|
|
28
|
+
async request(path, token, body, signal) {
|
|
29
|
+
const response = await this.response(path, token, body, signal);
|
|
27
30
|
const value = await response.json().catch(() => null);
|
|
28
31
|
if (response.status === 404)
|
|
29
32
|
throw new UiError("unsupported_core", "Update Core to use application panels.", 409);
|
|
@@ -36,6 +39,20 @@ export class UiServerClient {
|
|
|
36
39
|
bootstrap(options, token, signal) {
|
|
37
40
|
return this.request(`bootstrap${options.parentOrigin ? `?parentOrigin=${encodeURIComponent(options.parentOrigin)}` : ""}`, token, undefined, signal);
|
|
38
41
|
}
|
|
42
|
+
async icon(token, signal) {
|
|
43
|
+
const response = await this.response("icon", token, undefined, signal);
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
await response.body?.cancel();
|
|
46
|
+
return new Response(null, { status: response.status, headers: responseHeaders });
|
|
47
|
+
}
|
|
48
|
+
const type = response.headers.get("content-type")?.split(";", 1)[0] ?? "";
|
|
49
|
+
if (!["image/svg+xml", "image/png", "image/webp", "image/jpeg", "image/gif", "image/avif"].includes(type)) {
|
|
50
|
+
await response.body?.cancel();
|
|
51
|
+
throw new UiError("ui_response_invalid", "Core returned an invalid app icon.", 502);
|
|
52
|
+
}
|
|
53
|
+
return new Response(response.body, { headers: { ...responseHeaders, "Content-Type": type,
|
|
54
|
+
"X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'; sandbox" } });
|
|
55
|
+
}
|
|
39
56
|
async listPanels(token, signal) {
|
|
40
57
|
return (await this.request("panels", token, undefined, signal)).panels;
|
|
41
58
|
}
|
|
@@ -101,7 +118,15 @@ export async function createHostyUiResponse(request, context, options = {}) {
|
|
|
101
118
|
else if (request.method === "GET" && route === "bootstrap") {
|
|
102
119
|
if ([...url.searchParams.keys()].some(k => k !== "parentOrigin") || url.searchParams.getAll("parentOrigin").length > 1)
|
|
103
120
|
throw new UiError("ui_request_invalid", "Invalid bootstrap request.", 400);
|
|
104
|
-
|
|
121
|
+
const bootstrap = await client.bootstrap({ parentOrigin: url.searchParams.get("parentOrigin") ?? undefined }, context.token, request.signal);
|
|
122
|
+
const icon = bootstrap.app.iconUrl ? new URL(bootstrap.app.iconUrl, bootstrap.coreOrigin) : null;
|
|
123
|
+
const ownAsset = icon?.origin === bootstrap.coreOrigin && icon.pathname.startsWith(`/api/apps/${encodeURIComponent(bootstrap.app.appId)}/assets/`);
|
|
124
|
+
result = ownAsset ? { ...bootstrap, app: { ...bootstrap.app, iconUrl: prefix + "/icon" } } : bootstrap;
|
|
125
|
+
}
|
|
126
|
+
else if (request.method === "GET" && route === "icon") {
|
|
127
|
+
if (url.search)
|
|
128
|
+
throw new UiError("ui_request_invalid", "Unexpected icon parameters.", 400);
|
|
129
|
+
return await client.icon(context.token, request.signal);
|
|
105
130
|
}
|
|
106
131
|
else if (request.method === "GET" && route === "panels") {
|
|
107
132
|
result = { panels: await client.listPanels(context.token, request.signal) };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
export declare const StandaloneNavigationContext: import("react").Context<{
|
|
3
|
+
collapsed: boolean;
|
|
4
|
+
narrow: boolean;
|
|
5
|
+
open: boolean;
|
|
6
|
+
setOpen: (open: boolean) => void;
|
|
7
|
+
opener: RefObject<HTMLButtonElement | null>;
|
|
8
|
+
} | null>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type UiBootstrap, type UiPanel } from "./ui-types.js";
|
|
2
|
+
type Preferences = {
|
|
3
|
+
ready: boolean;
|
|
4
|
+
collapsed: boolean;
|
|
5
|
+
pins: string[];
|
|
6
|
+
error: string | null;
|
|
7
|
+
};
|
|
8
|
+
export declare const standalonePreferenceKey: (bootstrap: UiBootstrap | null) => string | null;
|
|
9
|
+
export declare function parseStandalonePreferences(raw: string | null): Pick<Preferences, "collapsed" | "pins">;
|
|
10
|
+
export declare function createStandalonePreferenceStore(key: string | null): {
|
|
11
|
+
getSnapshot: () => Preferences;
|
|
12
|
+
getServerSnapshot: () => Preferences;
|
|
13
|
+
subscribe(listener: () => void): () => void;
|
|
14
|
+
setCollapsed: (collapsed: boolean) => void;
|
|
15
|
+
setPinned(panel: UiPanel, pinned: boolean): void;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { panelKey } from "./ui-types.js";
|
|
2
|
+
const initial = { ready: false, collapsed: false, pins: [], error: null };
|
|
3
|
+
export const standalonePreferenceKey = (bootstrap) => bootstrap
|
|
4
|
+
? `hosty:standalone:v1:${JSON.stringify([bootstrap.coreOrigin, bootstrap.userId, bootstrap.app.appId, bootstrap.app.installationId])}` : null;
|
|
5
|
+
export function parseStandalonePreferences(raw) {
|
|
6
|
+
try {
|
|
7
|
+
const value = JSON.parse(raw ?? "null");
|
|
8
|
+
if (value?.version !== 1)
|
|
9
|
+
return { collapsed: false, pins: [] };
|
|
10
|
+
const pins = Array.isArray(value.pins) ? value.pins.slice(0, 100).filter((key) => {
|
|
11
|
+
if (typeof key !== "string" || key.length > 2048)
|
|
12
|
+
return false;
|
|
13
|
+
try {
|
|
14
|
+
const ref = JSON.parse(key);
|
|
15
|
+
return Array.isArray(ref) && ref.length === 3 && ref.every(part => typeof part === "string" && part.length > 0);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}) : [];
|
|
21
|
+
return { collapsed: value.collapsed === true, pins: [...new Set(pins)] };
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return { collapsed: false, pins: [] };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function createStandalonePreferenceStore(key) {
|
|
28
|
+
let snapshot = initial, raw;
|
|
29
|
+
const listeners = new Set();
|
|
30
|
+
function read() {
|
|
31
|
+
if (!key || typeof window === "undefined")
|
|
32
|
+
return snapshot;
|
|
33
|
+
try {
|
|
34
|
+
const next = window.localStorage.getItem(key);
|
|
35
|
+
if (next !== raw) {
|
|
36
|
+
raw = next;
|
|
37
|
+
snapshot = { ...parseStandalonePreferences(next), ready: true, error: null };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
if (!snapshot.ready)
|
|
42
|
+
snapshot = { ...initial, ready: true, error: "Preferences cannot be saved in this browser." };
|
|
43
|
+
}
|
|
44
|
+
return snapshot;
|
|
45
|
+
}
|
|
46
|
+
function write(patch) {
|
|
47
|
+
if (!key)
|
|
48
|
+
return;
|
|
49
|
+
snapshot = { ...read(), ...patch, ready: true, error: null };
|
|
50
|
+
try {
|
|
51
|
+
const next = JSON.stringify({ version: 1, collapsed: snapshot.collapsed, pins: snapshot.pins });
|
|
52
|
+
window.localStorage.setItem(key, next);
|
|
53
|
+
raw = next;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
snapshot = { ...snapshot, error: "Preferences apply until you reload; this browser could not save them." };
|
|
57
|
+
}
|
|
58
|
+
listeners.forEach(listener => listener());
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
getSnapshot: read, getServerSnapshot: () => initial,
|
|
62
|
+
subscribe(listener) {
|
|
63
|
+
listeners.add(listener);
|
|
64
|
+
const storage = (event) => { if (event.key === key || event.key === null) {
|
|
65
|
+
read();
|
|
66
|
+
listeners.forEach(fn => fn());
|
|
67
|
+
} };
|
|
68
|
+
window.addEventListener("storage", storage);
|
|
69
|
+
return () => { listeners.delete(listener); window.removeEventListener("storage", storage); };
|
|
70
|
+
},
|
|
71
|
+
setCollapsed: (collapsed) => write({ collapsed }),
|
|
72
|
+
setPinned(panel, pinned) {
|
|
73
|
+
const key = panelKey(panel.panel), pins = read().pins.filter(item => item !== key);
|
|
74
|
+
write({ pins: pinned ? [...pins, key].slice(-100) : pins });
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type UiPanel } from "./ui-types.js";
|
|
3
|
+
export declare function StandaloneChrome({ children, navigation }: {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
navigation?: boolean;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
7
|
+
export declare function useStandalonePreferences(): {
|
|
8
|
+
setPinned: (panel: UiPanel, pinned: boolean) => void;
|
|
9
|
+
setCollapsed: (collapsed: boolean) => void;
|
|
10
|
+
ready: boolean;
|
|
11
|
+
collapsed: boolean;
|
|
12
|
+
pins: string[];
|
|
13
|
+
error: string | null;
|
|
14
|
+
};
|
|
15
|
+
export declare function StandaloneHeader({ panels, selected, expanded, onSelect, onChoose, canNavigate, chooserOpen, attention }: {
|
|
16
|
+
panels: UiPanel[];
|
|
17
|
+
selected: string | null;
|
|
18
|
+
expanded: boolean;
|
|
19
|
+
onSelect: (panel: UiPanel) => void;
|
|
20
|
+
onChoose: () => void;
|
|
21
|
+
canNavigate: boolean;
|
|
22
|
+
chooserOpen: boolean;
|
|
23
|
+
attention: (panel: UiPanel) => boolean;
|
|
24
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
+
import { SdkIcon } from "./sdk-chrome.js";
|
|
5
|
+
import { UiHostContext } from "./ui-context.js";
|
|
6
|
+
import { useHostyChrome, useHostyNavigation } from "./ui-navigation-react.js";
|
|
7
|
+
import { StandaloneNavigationContext } from "./ui-standalone-context.js";
|
|
8
|
+
import { createStandalonePreferenceStore, standalonePreferenceKey } from "./ui-standalone-preferences.js";
|
|
9
|
+
import { panelKey } from "./ui-types.js";
|
|
10
|
+
const noop = () => () => { };
|
|
11
|
+
const PreferencesContext = createContext(null);
|
|
12
|
+
export function StandaloneChrome({ children, navigation = true }) {
|
|
13
|
+
const host = useContext(UiHostContext);
|
|
14
|
+
const snapshot = useSyncExternalStore(host?.subscribeSnapshot ?? noop, host?.getSnapshot ?? (() => null), () => null);
|
|
15
|
+
const key = standalonePreferenceKey(snapshot?.bootstrap ?? null);
|
|
16
|
+
const store = useMemo(() => createStandalonePreferenceStore(key), [key]);
|
|
17
|
+
const prefs = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot);
|
|
18
|
+
const [narrow, setNarrow] = useState(false), [drawer, setDrawer] = useState({ key, open: false });
|
|
19
|
+
const opener = useRef(null);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const resize = () => setNarrow(window.innerWidth < 900);
|
|
22
|
+
resize();
|
|
23
|
+
window.addEventListener("resize", resize);
|
|
24
|
+
return () => window.removeEventListener("resize", resize);
|
|
25
|
+
}, []);
|
|
26
|
+
return _jsx(PreferencesContext.Provider, { value: store, children: _jsx(StandaloneNavigationContext.Provider, { value: navigation ? {
|
|
27
|
+
collapsed: prefs.collapsed, narrow, open: drawer.key === key && drawer.open,
|
|
28
|
+
setOpen: open => setDrawer({ key, open }), opener,
|
|
29
|
+
} : null, children: children }) });
|
|
30
|
+
}
|
|
31
|
+
export function useStandalonePreferences() {
|
|
32
|
+
const store = useContext(PreferencesContext);
|
|
33
|
+
const fallback = useMemo(() => createStandalonePreferenceStore(null), []), current = store ?? fallback;
|
|
34
|
+
const state = useSyncExternalStore(current.subscribe, current.getSnapshot, current.getServerSnapshot);
|
|
35
|
+
return { ...state, setPinned: current.setPinned, setCollapsed: current.setCollapsed };
|
|
36
|
+
}
|
|
37
|
+
export function StandaloneHeader({ panels, selected, expanded, onSelect, onChoose, canNavigate, chooserOpen, attention }) {
|
|
38
|
+
const host = useContext(UiHostContext), nav = useContext(StandaloneNavigationContext);
|
|
39
|
+
const snapshot = useSyncExternalStore(host?.subscribeSnapshot ?? noop, host?.getSnapshot ?? (() => null), () => null);
|
|
40
|
+
const chrome = useHostyChrome(), navigation = useHostyNavigation(), prefs = useStandalonePreferences();
|
|
41
|
+
const app = snapshot?.bootstrap?.app, [failedIcon, setFailedIcon] = useState(null);
|
|
42
|
+
const name = app?.displayName || app?.appId || "Application";
|
|
43
|
+
const icon = app?.iconUrl && /^(https?:\/\/|\/(?!\/))/.test(app.iconUrl) ? app.iconUrl : null;
|
|
44
|
+
const showNavigation = canNavigate && chrome.navigation === "show" && (navigation.status !== "ready" || navigation.entries.length > 0);
|
|
45
|
+
const toolsVisible = chrome.tools.enabled && chrome.tools.launcher !== "hide";
|
|
46
|
+
return _jsxs("header", { "data-hosty-sdk": true, className: "hosty-standalone-header", children: [_jsxs("div", { className: "hosty-standalone-identity", children: [showNavigation && nav && _jsx("button", { ref: nav.opener, type: "button", className: "hosty-standalone-navigation", disabled: !prefs.ready, "aria-label": nav.narrow ? nav.open ? "Hide navigation" : "Show navigation" : prefs.collapsed ? "Show navigation" : "Hide navigation", title: nav.narrow ? "Page navigation" : prefs.collapsed ? "Show navigation" : "Hide navigation", "aria-expanded": nav.narrow ? nav.open : !prefs.collapsed, onClick: () => nav.narrow ? nav.setOpen(!nav.open) : prefs.setCollapsed(!prefs.collapsed), children: _jsx(SdkIcon, { name: "sidebar" }) }), icon && icon !== failedIcon ? _jsx("img", { src: icon, alt: "", draggable: false, onError: () => setFailedIcon(icon) }) : _jsx(SdkIcon, { name: "app" }), _jsx("strong", { title: name, children: name })] }), toolsVisible && _jsxs("div", { className: "hosty-standalone-tools", children: [_jsx("nav", { className: "hosty-pinned-tools", "aria-label": "Pinned tools", children: prefs.pins.map(key => panels.find(panel => panelKey(panel.panel) === key)).filter((panel) => !!panel).map(panel => _jsxs("button", { type: "button", "aria-label": `Open ${panel.appName} — ${panel.label}`, title: `${panel.appName}: ${panel.label}`, "aria-expanded": expanded && selected === panelKey(panel.panel), onClick: () => onSelect(panel), children: [_jsx(SdkIcon, { name: "tools" }), _jsx("span", { children: panel.label }), attention(panel) && _jsx("span", { className: "hosty-panel-attention", "aria-label": "Needs attention", children: _jsx(SdkIcon, { name: "warning" }) })] }, panelKey(panel.panel))) }), _jsxs("button", { type: "button", "aria-label": "Tools", "aria-haspopup": "dialog", "aria-expanded": chooserOpen, onClick: onChoose, children: [_jsx(SdkIcon, { name: "tools" }), _jsx("span", { children: "Tools" }), _jsx(SdkIcon, { name: "chevron" })] })] })] });
|
|
47
|
+
}
|
package/dist/ui-transport.js
CHANGED
|
@@ -7,7 +7,7 @@ export function readUiMessage(value) {
|
|
|
7
7
|
if (!value || typeof value !== "object")
|
|
8
8
|
return null;
|
|
9
9
|
try {
|
|
10
|
-
if (new TextEncoder().encode(JSON.stringify(value)).length > 16_384)
|
|
10
|
+
if (new TextEncoder().encode(JSON.stringify(value)).length > (value.type?.startsWith("hosty:ui:feedback-") ? 262_144 : 16_384))
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
13
|
catch {
|
package/dist/ui-types.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export type UiPeer = {
|
|
|
22
22
|
appId: string;
|
|
23
23
|
installationId: string;
|
|
24
24
|
origins: string[];
|
|
25
|
+
displayName?: string;
|
|
26
|
+
iconUrl?: string | null;
|
|
25
27
|
};
|
|
26
28
|
export type UiBootstrap = {
|
|
27
29
|
version: 1;
|
|
@@ -44,10 +46,13 @@ export type UiPanel = {
|
|
|
44
46
|
state: string;
|
|
45
47
|
canStart: boolean;
|
|
46
48
|
framePolicy: UiFramePolicy;
|
|
49
|
+
feedbackComposer?: boolean;
|
|
50
|
+
assistantKey?: string | null;
|
|
47
51
|
};
|
|
48
52
|
export type UiFrameSurface = AppSurfaceRef & {
|
|
49
53
|
origin: string;
|
|
50
54
|
framePolicy: UiFramePolicy;
|
|
55
|
+
feedbackComposer?: boolean;
|
|
51
56
|
panelId?: string;
|
|
52
57
|
};
|
|
53
58
|
export type UiResolvedPanel = {
|
package/dist/ui-workspaces.d.ts
CHANGED
|
@@ -17,6 +17,9 @@ export type UiWorkspaceSnapshot = {
|
|
|
17
17
|
selectedId: string | null;
|
|
18
18
|
expanded: boolean;
|
|
19
19
|
width: number;
|
|
20
|
+
/** Presentations shown when expanded; focus is selectedId. Omitted by older hosts. */
|
|
21
|
+
visibleIds?: string[];
|
|
22
|
+
multiple?: boolean;
|
|
20
23
|
};
|
|
21
24
|
/** Adapters retain frames in one layer; present is also used for movement to another region. */
|
|
22
25
|
export type UiWorkspaceRenderer = {
|
|
@@ -33,6 +36,10 @@ export type UiViewDescriptor = {
|
|
|
33
36
|
workspaceId: string;
|
|
34
37
|
chrome?: UiChromeOverrides;
|
|
35
38
|
presentationId?: string;
|
|
39
|
+
onSurfaceState?: (state: {
|
|
40
|
+
route: string;
|
|
41
|
+
title?: string;
|
|
42
|
+
}) => void;
|
|
36
43
|
navigate?: (surface: UiFrameSurface) => void | Promise<void>;
|
|
37
44
|
};
|
|
38
45
|
export type UiPlacementResolver = (request: {
|
package/dist/ui-workspaces.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export const DEFAULT_WORKSPACE = "default";
|
|
2
2
|
export const ROOT_VIEW = "root";
|
|
3
|
-
export const workspace = (workspaceId) => ({ workspaceId, selectedId: null, expanded: false, width: 360, generation: 0 });
|
|
3
|
+
export const workspace = (workspaceId) => ({ workspaceId, selectedId: null, expanded: false, width: 360, visibleIds: [], multiple: false, generation: 0 });
|
package/dist/ui.d.ts
CHANGED