@hosty-sdk/app 0.39.0 → 0.41.1

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.
Files changed (43) hide show
  1. package/README.md +4 -2
  2. package/dist/feedback-capture.d.ts +5 -1
  3. package/dist/feedback-capture.js +41 -2
  4. package/dist/feedback-channel.d.ts +91 -0
  5. package/dist/feedback-channel.js +187 -0
  6. package/dist/feedback-client.d.ts +8 -0
  7. package/dist/feedback-client.js +26 -0
  8. package/dist/feedback-draft.d.ts +1 -5
  9. package/dist/feedback-draft.js +0 -31
  10. package/dist/feedback-react.d.ts +6 -2
  11. package/dist/feedback-react.js +235 -357
  12. package/dist/feedback-rpc.d.ts +7 -0
  13. package/dist/feedback-rpc.js +42 -0
  14. package/dist/feedback-workspace.d.ts +13 -0
  15. package/dist/feedback-workspace.js +28 -0
  16. package/dist/sdk-chrome.d.ts +1 -1
  17. package/dist/sdk-chrome.js +4 -0
  18. package/dist/ui-embedded.d.ts +10 -0
  19. package/dist/ui-embedded.js +61 -0
  20. package/dist/ui-frame.js +1 -0
  21. package/dist/ui-host.d.ts +15 -2
  22. package/dist/ui-host.js +128 -27
  23. package/dist/ui-navigation-react.js +9 -4
  24. package/dist/ui-react.d.ts +5 -1
  25. package/dist/ui-react.js +59 -15
  26. package/dist/ui-server.d.ts +2 -0
  27. package/dist/ui-server.js +28 -3
  28. package/dist/ui-standalone-context.d.ts +8 -0
  29. package/dist/ui-standalone-context.js +3 -0
  30. package/dist/ui-standalone-preferences.d.ts +17 -0
  31. package/dist/ui-standalone-preferences.js +77 -0
  32. package/dist/ui-standalone-react.d.ts +24 -0
  33. package/dist/ui-standalone-react.js +47 -0
  34. package/dist/ui-transport.js +1 -1
  35. package/dist/ui-types.d.ts +5 -0
  36. package/dist/ui-workspaces.d.ts +7 -0
  37. package/dist/ui-workspaces.js +1 -1
  38. package/dist/ui.d.ts +1 -0
  39. package/package.json +5 -1
  40. package/dist/feedback-audio.d.ts +0 -3
  41. package/dist/feedback-audio.js +0 -40
  42. package/dist/feedback-speech.d.ts +0 -6
  43. package/dist/feedback-speech.js +0 -119
@@ -0,0 +1,7 @@
1
+ /** Bounded requests tied to a verified document generation by the caller. */
2
+ export declare class FeedbackRpc {
3
+ private pending;
4
+ request(owner: object, send: (id: string) => void): Promise<unknown>;
5
+ receive(owner: object, id: unknown, value: unknown, error: unknown): void;
6
+ clear(owner?: object): void;
7
+ }
@@ -0,0 +1,42 @@
1
+ /** Bounded requests tied to a verified document generation by the caller. */
2
+ export class FeedbackRpc {
3
+ pending = new Map();
4
+ request(owner, send) {
5
+ if (this.pending.size >= 64)
6
+ return Promise.reject(new Error('Too many pending capture requests.'));
7
+ return new Promise((resolve, reject) => {
8
+ const id = crypto.randomUUID(), timer = setTimeout(() => { this.pending.delete(id); reject(new Error('Capture timed out. Select the application and retry.')); }, 120000);
9
+ this.pending.set(id, { resolve, reject, timer, owner });
10
+ try {
11
+ send(id);
12
+ }
13
+ catch (e) {
14
+ this.pending.delete(id);
15
+ clearTimeout(timer);
16
+ reject(e);
17
+ }
18
+ });
19
+ }
20
+ receive(owner, id, value, error) {
21
+ if (typeof id !== 'string')
22
+ return;
23
+ const p = this.pending.get(id);
24
+ if (!p || p.owner !== owner)
25
+ return;
26
+ this.pending.delete(id);
27
+ clearTimeout(p.timer);
28
+ if (typeof error === 'string')
29
+ p.reject(new Error(error.slice(0, 4096)));
30
+ else
31
+ p.resolve(value);
32
+ }
33
+ clear(owner) {
34
+ for (const [id, p] of this.pending) {
35
+ if (owner && owner !== p.owner)
36
+ continue;
37
+ this.pending.delete(id);
38
+ clearTimeout(p.timer);
39
+ p.reject(new Error('The capture connection changed. Reopen the application before retrying.'));
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,13 @@
1
+ export declare function useHostyFeedback(): {
2
+ host: import("./ui-host").UiHost | null;
3
+ feedback: import("./feedback-channel").FeedbackHost | undefined;
4
+ state: {
5
+ picking: boolean;
6
+ pickMode: "element" | "region" | undefined;
7
+ };
8
+ };
9
+ /** Optional host chrome shortcut. The form is always an ordinary app-provided tool. */
10
+ export declare function HostyFeedbackLauncher({ workspaceId, className }: {
11
+ workspaceId?: string;
12
+ className?: string;
13
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,28 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useContext, useState, useSyncExternalStore } from 'react';
4
+ import { UiHostContext } from './ui-context.js';
5
+ import { EMPTY_FEEDBACK } from './feedback-channel.js';
6
+ const noop = () => () => { };
7
+ export function useHostyFeedback() {
8
+ const host = useContext(UiHostContext), feedback = host?.feedback;
9
+ const state = useSyncExternalStore(feedback?.subscribe ?? noop, feedback?.getSnapshot ?? (() => EMPTY_FEEDBACK), () => EMPTY_FEEDBACK);
10
+ return { host, feedback, state };
11
+ }
12
+ /** Optional host chrome shortcut. The form is always an ordinary app-provided tool. */
13
+ export function HostyFeedbackLauncher({ workspaceId = 'default', className }) {
14
+ const host = useContext(UiHostContext);
15
+ const snapshot = useSyncExternalStore(host?.subscribeSnapshot ?? noop, host?.getSnapshot ?? (() => null), () => null);
16
+ const providers = snapshot?.catalog.filter(p => p.feedbackComposer) ?? [];
17
+ const [error, setError] = useState('');
18
+ if (!providers.length)
19
+ return null;
20
+ return _jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: className, "aria-label": "Feedback", title: "Feedback", onClick: () => {
21
+ setError('');
22
+ const operation = providers.length === 1 ? host?.selectPanel(providers[0].panel, workspaceId) : host?.openToolPicker({ requestId: crypto.randomUUID() });
23
+ void operation?.then(result => {
24
+ if (result.status !== 'opened' && result.status !== 'accepted')
25
+ setError('Could not open the Feedback tool.');
26
+ }).catch(e => setError(e.message));
27
+ }, children: _jsx("svg", { "aria-hidden": true, viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: "1.7", children: _jsx("path", { d: "M21 11.5a8.5 8.5 0 0 1-8.5 8.5H4l-2 2V11.5a9.5 9.5 0 0 1 19 0Z" }) }) }), error && _jsx("span", { role: "alert", children: error })] });
28
+ }
@@ -5,7 +5,7 @@ export declare function SdkProgress({ label }: {
5
5
  label: string;
6
6
  }): import("react").JSX.Element;
7
7
  export declare function SdkLoader(): import("react").JSX.Element;
8
- type Icon = "close" | "external" | "menu" | "plus" | "minus" | "check" | "warning" | "error";
8
+ type Icon = "sidebar" | "app" | "tools" | "pin" | "chevron" | "close" | "external" | "menu" | "plus" | "minus" | "check" | "warning" | "error";
9
9
  export declare function SdkIcon({ name }: {
10
10
  name: Icon;
11
11
  }): import("react").JSX.Element;
@@ -50,6 +50,10 @@ export function SdkLoader() {
50
50
  return _jsx("svg", { className: "hosty-sdk-loader", viewBox: "0 0 100 100", "aria-hidden": "true", focusable: "false", children: [[12, 12], [12, 41], [12, 70], [41, 41], [70, 70], [70, 41], [70, 12]].map(([x, y], index) => _jsx("rect", { x: x, y: y, width: "18", height: "18", style: { "--hosty-cell-delay": `${index * .16}s` } }, index)) });
51
51
  }
52
52
  const paths = {
53
+ sidebar: "M9 3v18M5 3h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2Z",
54
+ app: "M5 3h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2ZM3 9h18M7 6h.01M10 6h.01",
55
+ tools: "M3 3h18v18H3ZM3 9h18M15 9v12", chevron: "m6 9 6 6 6-6",
56
+ pin: "M16 3H8l1 7-4 4v2h14v-2l-4-4 1-7ZM12 16v6",
53
57
  close: "m18 6-12 12M6 6l12 12", external: "M15 3h6v6m0-6L10 14m8-1v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",
54
58
  menu: "M4 6h16M4 12h16M4 18h16", plus: "M12 5v14M5 12h14", minus: "M5 12h14", check: "m20 6-11 11-5-5",
55
59
  warning: "m12 3 9 9-9 9-9-9 9-9Zm0 4v6m0 3v.01", error: "M12 8v4m0 4v.01M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z",
@@ -1,3 +1,5 @@
1
+ import type { FeedbackCapabilities } from "./feedback-types.js";
2
+ import { type FeedbackOperation, type FeedbackEvent, type FeedbackPort } from "./feedback-channel.js";
1
3
  import { UiCompositionModel } from "./ui-composition.js";
2
4
  import { type UiNavigationOptions, type UiChromeOverrides, type UiActionOptions, type UiActionResult } from "./ui-types.js";
3
5
  import { type UiClient } from "./ui.js";
@@ -6,6 +8,13 @@ import { type PanelTarget, type PresentationOptions, type PresentationResult, ty
6
8
  export declare class EmbeddedUiClient implements UiClient {
7
9
  private readonly path;
8
10
  readonly composition: UiCompositionModel;
11
+ feedbackSupported: boolean;
12
+ private readonly feedbackRpc;
13
+ private feedbackSource?;
14
+ private feedbackReceiver?;
15
+ registerFeedbackSource(capabilities: FeedbackCapabilities, invoke: (operation: FeedbackOperation) => Promise<unknown>): void;
16
+ unregisterFeedbackSource(): void;
17
+ connectFeedback: (receive: (event: FeedbackEvent) => void) => FeedbackPort;
9
18
  private readonly localActions;
10
19
  private environment;
11
20
  private nonce;
@@ -58,6 +67,7 @@ export declare class EmbeddedUiClient implements UiClient {
58
67
  route: string;
59
68
  state: "ready" | "blocked";
60
69
  code?: string;
70
+ title?: string;
61
71
  }) => void;
62
72
  dispose: () => void;
63
73
  }
@@ -1,3 +1,5 @@
1
+ import { FEEDBACK_CAPABILITY, feedbackOperation, feedbackScope } from "./feedback-channel.js";
2
+ import { FeedbackRpc } from "./feedback-rpc.js";
1
3
  import { activeNavigationKey, UiCompositionModel } from "./ui-composition.js";
2
4
  import { UI_COMPOSITION_CAPABILITY, UI_MAIN_NAVIGATION_CAPABILITY, navigationSearch } from "./ui-types.js";
3
5
  import { createPresentationRequestId } from "./ui.js";
@@ -7,6 +9,31 @@ import { canonicalSurfaceRoute, DISCOVERY_TIMEOUT, failure, readUiMessage, uiReq
7
9
  export class EmbeddedUiClient {
8
10
  path;
9
11
  composition;
12
+ feedbackSupported = false;
13
+ feedbackRpc = new FeedbackRpc();
14
+ feedbackSource;
15
+ feedbackReceiver;
16
+ registerFeedbackSource(capabilities, invoke) {
17
+ // Metadata refresh is not a new document. Keep pending picker replies attached to this source.
18
+ if (this.feedbackSource?.invoke === invoke && feedbackScope(this.feedbackSource.capabilities) === feedbackScope(capabilities))
19
+ this.feedbackSource.capabilities = capabilities;
20
+ else
21
+ this.feedbackSource = { capabilities, invoke };
22
+ if (this.feedbackSupported)
23
+ this.post({ type: 'hosty:ui:feedback-source', value: capabilities });
24
+ }
25
+ unregisterFeedbackSource() { this.feedbackSource = undefined; this.post({ type: 'hosty:ui:feedback-source-close' }); }
26
+ connectFeedback = (receive) => {
27
+ this.feedbackReceiver = receive;
28
+ if (this.feedbackSupported)
29
+ this.post({ type: 'hosty:ui:feedback-connect' });
30
+ return { request: operation => this.feedbackSupported ? this.feedbackRpc.request(this, requestId => this.post({ type: 'hosty:ui:feedback-request', requestId, operation })) : Promise.reject(new Error('This host does not support feedback tools.')),
31
+ close: () => { if (this.feedbackReceiver === receive) {
32
+ this.feedbackReceiver = undefined;
33
+ this.post({ type: 'hosty:ui:feedback-disconnect' });
34
+ this.feedbackRpc.clear();
35
+ } } };
36
+ };
10
37
  localActions = new Map();
11
38
  environment = { mode: "embedded", connection: "connecting" };
12
39
  nonce = createPresentationRequestId();
@@ -85,6 +112,7 @@ export class EmbeddedUiClient {
85
112
  for (const listener of this.listeners)
86
113
  listener(event); }
87
114
  retirePending() {
115
+ this.feedbackRpc.clear();
88
116
  for (const [requestId, entry] of this.pending)
89
117
  entry.resolve(entry.sent
90
118
  ? { status: "uncertain", requestId, code: "presentation_unknown" }
@@ -93,6 +121,10 @@ export class EmbeddedUiClient {
93
121
  setEnvironment(connection, code) {
94
122
  if (this.disposed)
95
123
  return;
124
+ if (connection !== "connected") {
125
+ this.feedbackSupported = false;
126
+ this.feedbackRpc.clear();
127
+ }
96
128
  this.environment = { mode: "embedded", connection, ...(code ? { code } : {}) };
97
129
  this.composition.setEnvironment(this.environment);
98
130
  this.emit({ type: "environment", value: this.environment });
@@ -200,6 +232,7 @@ export class EmbeddedUiClient {
200
232
  this.setEnvironment("blocked", "actor_mismatch");
201
233
  return;
202
234
  }
235
+ this.feedbackSupported = Array.isArray(msg.capabilities) && msg.capabilities.includes(FEEDBACK_CAPABILITY);
203
236
  clearTimeout(this.deadline);
204
237
  this.mainNavigation = Array.isArray(msg.capabilities) && msg.capabilities.includes(UI_MAIN_NAVIGATION_CAPABILITY);
205
238
  this.setEnvironment("connected");
@@ -211,10 +244,37 @@ export class EmbeddedUiClient {
211
244
  void this.composition.refreshNavigation();
212
245
  if (this.state)
213
246
  this.reportSurfaceState(this.state);
247
+ if (this.feedbackSource)
248
+ this.post({ type: 'hosty:ui:feedback-source', value: this.feedbackSource.capabilities });
249
+ if (this.feedbackReceiver)
250
+ this.post({ type: 'hosty:ui:feedback-connect' });
214
251
  return;
215
252
  }
216
253
  if (this.environment.connection !== "connected")
217
254
  return;
255
+ if (msg.type === 'hosty:ui:feedback-invoke' && this.feedbackSupported && validId(msg.requestId) && feedbackOperation(msg.operation)) {
256
+ const source = this.feedbackSource;
257
+ let value, error;
258
+ try {
259
+ if (!source)
260
+ throw new Error('Capture is unavailable in this document.');
261
+ value = await source.invoke(msg.operation);
262
+ }
263
+ catch (e) {
264
+ error = e instanceof Error ? e.message : 'Capture failed.';
265
+ }
266
+ if (this.channel === channel && this.feedbackSource === source)
267
+ this.post({ type: 'hosty:ui:feedback-source-result', requestId: msg.requestId, value, error });
268
+ return;
269
+ }
270
+ if (msg.type === 'hosty:ui:feedback-result') {
271
+ this.feedbackRpc.receive(this, msg.requestId, msg.value, msg.error);
272
+ return;
273
+ }
274
+ if (msg.type === 'hosty:ui:feedback-event' && this.feedbackSupported) {
275
+ this.feedbackReceiver?.(msg.value);
276
+ return;
277
+ }
218
278
  if (msg.type === "hosty:ui:chrome" && this.getChrome().capabilities.includes(UI_COMPOSITION_CAPABILITY)) {
219
279
  this.composition.setHostPolicy(channel.generation, msg.revision, msg.chrome, msg.rootDisabled === true, msg.endpoint);
220
280
  return;
@@ -370,6 +430,7 @@ export class EmbeddedUiClient {
370
430
  }
371
431
  };
372
432
  dispose = () => {
433
+ this.feedbackRpc.clear();
373
434
  this.disposed = true;
374
435
  this.composition.dispose();
375
436
  this.localActions.clear();
package/dist/ui-frame.js CHANGED
@@ -70,6 +70,7 @@ export function HostyAppFrame(props) {
70
70
  return;
71
71
  const view = callbacks.current.view;
72
72
  return host.registerFrame(frame, surface, ready => setConnection(current => ({ ready, generation: current.generation + (ready ? 1 : 0) })), { viewId: defaultViewId, workspaceId: "default", chrome: { navigation: "hide", tools: { launcher: "hide" } }, ...view,
73
+ onSurfaceState: state => callbacks.current.view?.onSurfaceState?.(state),
73
74
  navigate: next => {
74
75
  const current = callbacks.current;
75
76
  if (current.view?.navigate)
package/dist/ui-host.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { FeedbackHost, type FeedbackEvent, type FeedbackPort } from "./feedback-channel.js";
1
2
  import { UiCompositionModel } from "./ui-composition.js";
2
3
  import { type UiPresentation, type UiWorkspaceSnapshot, type UiWorkspaceRenderer, type UiViewDescriptor, type UiPlacementResolver } from "./ui-workspaces.js";
3
4
  export type { UiWorkspaceRenderer, UiViewDescriptor, UiPlacementResolver, UiPresentation } from "./ui-workspaces.js";
@@ -31,6 +32,9 @@ export declare function createUiHost(options?: {
31
32
  export declare class UiHost implements UiClient {
32
33
  private readonly path;
33
34
  private active;
35
+ readonly feedback: FeedbackHost;
36
+ private readonly feedbackRpc;
37
+ connectFeedback: (receive: (event: FeedbackEvent) => void) => FeedbackPort;
34
38
  private snapshot;
35
39
  private environment;
36
40
  private readonly windowId;
@@ -71,9 +75,10 @@ export declare class UiHost implements UiClient {
71
75
  setActive(active: boolean): void;
72
76
  private checkActivity;
73
77
  claimWorkspace: (owner: object) => () => void;
74
- registerWorkspace: ({ workspaceId, renderer }: {
78
+ registerWorkspace: ({ workspaceId, renderer, multiple }: {
75
79
  workspaceId: string;
76
80
  renderer: UiWorkspaceRenderer;
81
+ multiple?: boolean;
77
82
  }) => () => void;
78
83
  private publishWorkspaces;
79
84
  setPlacementResolver: (resolver?: UiPlacementResolver) => void;
@@ -81,7 +86,14 @@ export declare class UiHost implements UiClient {
81
86
  setViewChrome: (viewId: string, overrides: UiChromeOverrides) => void;
82
87
  private publishPolicy;
83
88
  private requireTools;
84
- focusPresentation: (id: string) => boolean;
89
+ private showPresentation;
90
+ private hideFromWorkspace;
91
+ /** Hide one panel while retaining its frame, route and draft. */
92
+ hidePresentation: (id: string) => void;
93
+ /** Record observed focus without moving the active DOM control when focus is false. */
94
+ focusPresentation: (id: string, options?: {
95
+ focus?: boolean;
96
+ }) => boolean;
85
97
  collapseWorkspace: (id: string) => void;
86
98
  closePresentation: (id: string) => void;
87
99
  private releasePresentation;
@@ -121,6 +133,7 @@ export declare class UiHost implements UiClient {
121
133
  route: string;
122
134
  state: "ready" | "blocked";
123
135
  code?: string;
136
+ title?: string;
124
137
  }) => void;
125
138
  private forgetFrameRequests;
126
139
  registerFrame: (element: HTMLIFrameElement, surface: UiFrameSurface, onConnection?: (connected: boolean) => void, view?: UiViewDescriptor) => (() => void);
package/dist/ui-host.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { FeedbackHost, FEEDBACK_CAPABILITY, feedbackOperation, validCapabilities } from "./feedback-channel.js";
2
+ import { FeedbackRpc } from "./feedback-rpc.js";
1
3
  import { UiCompositionModel, validChromeOverrides, withChromeHints } from "./ui-composition.js";
2
4
  import { DEFAULT_WORKSPACE, ROOT_VIEW, workspace } from "./ui-workspaces.js";
3
5
  import { UI_COMPOSITION_CAPABILITY, UI_MAIN_NAVIGATION_CAPABILITY, navigationSearch } from "./ui-types.js";
@@ -26,6 +28,13 @@ export function createUiHost(options = {}) {
26
28
  export class UiHost {
27
29
  path;
28
30
  active;
31
+ feedback = new FeedbackHost();
32
+ feedbackRpc = new FeedbackRpc();
33
+ connectFeedback = (receive) => {
34
+ const allowed = () => this.active && this.activityReady && this.snapshot.catalog.some(p => p.feedbackComposer && p.panel.appId === this.snapshot.bootstrap?.app.appId
35
+ && p.panel.installationId === this.snapshot.bootstrap?.app.installationId && p.origin === location.origin && routeWithin(location.pathname, p.route));
36
+ return this.feedback.connect('root-composer', { workspaceId: 'default', visible: allowed, receive });
37
+ };
29
38
  snapshot = { bootstrap: null, catalog: [], tools: [], selected: null, expanded: false, width: 360, error: null };
30
39
  environment = { mode: "standalone", connection: "connecting" };
31
40
  windowId = createPresentationRequestId();
@@ -84,6 +93,8 @@ export class UiHost {
84
93
  move.abort();
85
94
  this.active = active;
86
95
  this.activityReady = false;
96
+ this.feedbackRpc.clear();
97
+ this.feedback.clear();
87
98
  this.activityGeneration++;
88
99
  for (const state of this.workspaces.values())
89
100
  state.generation++;
@@ -125,13 +136,16 @@ export class UiHost {
125
136
  return () => { if (state.owner === owner)
126
137
  state.owner = undefined; };
127
138
  };
128
- registerWorkspace = ({ workspaceId, renderer }) => {
139
+ registerWorkspace = ({ workspaceId, renderer, multiple = false }) => {
129
140
  if (!workspaceId || workspaceId.length > 256)
130
141
  throw new Error("Invalid workspace ID.");
131
142
  const state = this.workspaces.get(workspaceId) ?? workspace(workspaceId);
132
143
  if (state.renderer && state.renderer !== renderer)
133
144
  throw new Error("A workspace already has a renderer.");
134
145
  state.renderer = renderer;
146
+ state.multiple = multiple;
147
+ if (!multiple)
148
+ state.visibleIds = state.selectedId ? [state.selectedId] : [];
135
149
  this.workspaces.set(workspaceId, state);
136
150
  this.publishWorkspaces();
137
151
  return () => {
@@ -150,7 +164,7 @@ export class UiHost {
150
164
  const selected = this.snapshot.tools.find(t => t.presentationId === state.selectedId);
151
165
  this.update({ selected: selected?.target.panel ?? null, selectedPresentationId: state.selectedId,
152
166
  expanded: state.expanded, width: state.width,
153
- workspaces: [...this.workspaces.values()].map(({ workspaceId, selectedId, expanded, width }) => ({ workspaceId, selectedId, expanded, width })) });
167
+ workspaces: [...this.workspaces.values()].map(({ workspaceId, selectedId, expanded, width, visibleIds, multiple }) => ({ workspaceId, selectedId, expanded, width, visibleIds: [...visibleIds ?? []], multiple })) });
154
168
  }
155
169
  setPlacementResolver = (resolver) => { this.placement = resolver; };
156
170
  getViewChrome = (viewId) => {
@@ -181,21 +195,50 @@ export class UiHost {
181
195
  if (!this.getChrome().tools.enabled || frame?.chrome.tools?.enabled === false)
182
196
  throw new UiError("tools_disabled", "Tools are disabled in this view.");
183
197
  }
184
- focusPresentation = (id) => {
198
+ showPresentation(state, id) {
199
+ state.selectedId = id;
200
+ state.expanded = true;
201
+ state.visibleIds = state.multiple ? [...new Set([...state.visibleIds ?? [], id])] : [id];
202
+ }
203
+ hideFromWorkspace(state, id) {
204
+ state.visibleIds = (state.visibleIds ?? []).filter(item => item !== id);
205
+ if (state.selectedId === id)
206
+ state.selectedId = state.visibleIds.at(-1) ?? null;
207
+ if (!state.visibleIds.length) {
208
+ state.expanded = false;
209
+ state.renderer?.collapse();
210
+ }
211
+ }
212
+ /** Hide one panel while retaining its frame, route and draft. */
213
+ hidePresentation = (id) => {
214
+ this.feedback.cancel();
215
+ const tool = this.snapshot.tools.find(t => t.presentationId === id);
216
+ if (!tool)
217
+ return;
218
+ const state = this.workspaces.get(tool.workspaceId);
219
+ state.generation++;
220
+ this.hideFromWorkspace(state, id);
221
+ this.publishWorkspaces();
222
+ if (state.expanded && state.selectedId)
223
+ state.renderer?.focus(state.selectedId);
224
+ };
225
+ /** Record observed focus without moving the active DOM control when focus is false. */
226
+ focusPresentation = (id, options) => {
185
227
  const tool = this.snapshot.tools.find(t => t.presentationId === id);
186
228
  if (!tool)
187
229
  return false;
188
230
  this.requireTools();
189
231
  const state = this.workspaces.get(tool.workspaceId);
190
232
  state.generation++;
191
- state.selectedId = id;
192
- state.expanded = true;
233
+ this.showPresentation(state, id);
193
234
  this.update({ tools: this.snapshot.tools.map(t => t === tool ? { ...t, focusedAt: ++this.focusSequence } : t) });
194
235
  this.publishWorkspaces();
195
- state.renderer?.focus(id);
236
+ if (options?.focus !== false)
237
+ state.renderer?.focus(id);
196
238
  return true;
197
239
  };
198
240
  collapseWorkspace = (id) => {
241
+ this.feedback.cancel();
199
242
  const state = this.workspaces.get(id);
200
243
  if (!state)
201
244
  return;
@@ -218,10 +261,7 @@ export class UiHost {
218
261
  state.generation++;
219
262
  state.renderer?.release(id);
220
263
  this.update({ tools: this.snapshot.tools.filter(t => t !== tool) });
221
- if (state.selectedId === id) {
222
- state.selectedId = null;
223
- state.expanded = false;
224
- }
264
+ this.hideFromWorkspace(state, id);
225
265
  this.publishWorkspaces();
226
266
  }
227
267
  resetPresentations() {
@@ -229,6 +269,7 @@ export class UiHost {
229
269
  this.closePresentation(tool.presentationId);
230
270
  for (const state of this.workspaces.values()) {
231
271
  state.selectedId = null;
272
+ state.visibleIds = [];
232
273
  state.expanded = false;
233
274
  state.generation++;
234
275
  state.renderer?.collapse();
@@ -265,11 +306,7 @@ export class UiHost {
265
306
  stop();
266
307
  previous.generation++;
267
308
  this.update({ tools: this.snapshot.tools.map(t => t.presentationId === id ? { ...t, workspaceId } : t) });
268
- if (previous.selectedId === id) {
269
- previous.selectedId = null;
270
- previous.expanded = false;
271
- previous.renderer?.collapse();
272
- }
309
+ this.hideFromWorkspace(previous, id);
273
310
  for (const frame of this.frames)
274
311
  if (frame.view.presentationId === id)
275
312
  frame.view = { ...frame.view, workspaceId };
@@ -558,8 +595,7 @@ export class UiHost {
558
595
  }
559
596
  throw error;
560
597
  }
561
- state.selectedId = tool.presentationId;
562
- state.expanded = true;
598
+ this.showPresentation(state, tool.presentationId);
563
599
  this.update({ tools: this.snapshot.tools.map(t => t.presentationId === tool.presentationId ? { ...t, focusedAt: ++this.focusSequence } : t) });
564
600
  this.publishWorkspaces();
565
601
  state.renderer?.focus(tool.presentationId);
@@ -833,6 +869,8 @@ export class UiHost {
833
869
  const state = this.workspaces.get(workspaceId);
834
870
  if (state) {
835
871
  state.expanded = true;
872
+ if (state.selectedId && !state.visibleIds?.length)
873
+ state.visibleIds = [state.selectedId];
836
874
  this.publishWorkspaces();
837
875
  if (state.expanded && state.selectedId)
838
876
  state.renderer?.focus(state.selectedId);
@@ -848,7 +886,10 @@ export class UiHost {
848
886
  setAttention = (panel, attention) => this.update({ tools: this.snapshot.tools.map(t => (typeof panel === "string" ? t.presentationId === panel : t.key === panelKey(panel)) ? { ...t, attention: Math.max(0, Math.floor(attention)) } : t) });
849
887
  reportSurfaceState = (_state) => { };
850
888
  forgetFrameRequests(frame) {
889
+ this.feedbackRpc.clear(frame);
890
+ this.feedback.remove(frame.view.viewId);
851
891
  frame.routeReport = undefined;
892
+ frame.navigationRoot = undefined;
852
893
  for (const [controller, work] of this.rendererWork)
853
894
  if (work.frame === frame)
854
895
  controller.abort();
@@ -888,7 +929,9 @@ export class UiHost {
888
929
  this.post(frame, { type: "hosty:ui:probe-request" });
889
930
  frame.waitForReadiness();
890
931
  };
891
- frame.cleanup = () => { frame.live = false; forget(); clearTimeout(timer); element.removeEventListener("load", loaded); this.frames.delete(frame); };
932
+ const visibility = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(() => this.feedback.refresh());
933
+ visibility?.observe(element);
934
+ frame.cleanup = () => { visibility?.disconnect(); frame.live = false; forget(); clearTimeout(timer); element.removeEventListener("load", loaded); this.frames.delete(frame); };
892
935
  this.frames.add(frame);
893
936
  element.addEventListener("load", loaded);
894
937
  loaded();
@@ -923,19 +966,25 @@ export class UiHost {
923
966
  }
924
967
  }
925
968
  reportRoute(frame, value, entryKey) {
926
- if (!frame.view.presentationId)
969
+ if (!frame.view.presentationId && !frame.view.onSurfaceState)
927
970
  return;
928
971
  const route = canonicalSurfaceRoute(value);
929
972
  if (frame.routeReport?.route === route && frame.routeReport.pending)
930
973
  return;
974
+ if (frame.surface.feedbackComposer && route && !routeWithin(route, frame.surface.route))
975
+ this.feedback.disconnect(frame.view.viewId);
931
976
  const report = { route };
932
977
  frame.routeReport = report;
933
978
  const tool = this.snapshot.tools.find(t => t.presentationId === frame.view.presentationId);
934
979
  const declared = this.snapshot.catalog.find(p => p.panel.appId === frame.surface.appId && p.panel.panelId === frame.surface.panelId);
935
- const roots = [tool?.navigationRoot, declared?.origin === frame.surface.origin && declared.endpoint === frame.surface.endpoint ? declared.route : undefined];
980
+ const roots = frame.view.presentationId
981
+ ? [tool?.navigationRoot, declared?.origin === frame.surface.origin && declared.endpoint === frame.surface.endpoint ? declared.route : undefined]
982
+ : [frame.navigationRoot, frame.surface.route];
936
983
  const currentRoute = route && roots.some(root => root && routeWithin(route, root)) ? route : null;
937
- this.update({ tools: this.snapshot.tools.map(t => t.presentationId === frame.view.presentationId && t.currentRoute !== currentRoute
938
- ? { ...t, currentRoute, readiness: "unreported" } : t) });
984
+ report.currentRoute = currentRoute;
985
+ if (frame.view.presentationId)
986
+ this.update({ tools: this.snapshot.tools.map(t => t.presentationId === frame.view.presentationId && t.currentRoute !== currentRoute
987
+ ? { ...t, currentRoute, readiness: "unreported" } : t) });
939
988
  if (currentRoute || !route || typeof entryKey !== "string" || !entryKey || entryKey.length > 256)
940
989
  return;
941
990
  const activity = this.activityGeneration, generation = frame.generation, nonce = frame.nonce, surface = frame.surface;
@@ -953,8 +1002,11 @@ export class UiHost {
953
1002
  || next.origin !== surface.origin || next.endpoint !== surface.endpoint || !routeWithin(route, next.route)
954
1003
  || JSON.stringify(next.framePolicy) !== JSON.stringify(surface.framePolicy))
955
1004
  return;
956
- this.update({ tools: this.snapshot.tools.map(t => t.presentationId === frame.view.presentationId
957
- ? { ...t, navigationRoot: next.route, currentRoute: route, readiness: "unreported" } : t) });
1005
+ report.currentRoute = route;
1006
+ frame.navigationRoot = next.route;
1007
+ if (frame.view.presentationId)
1008
+ this.update({ tools: this.snapshot.tools.map(t => t.presentationId === frame.view.presentationId
1009
+ ? { ...t, navigationRoot: next.route, currentRoute: route, readiness: "unreported" } : t) });
958
1010
  }
959
1011
  catch { /* Local navigation remains usable when its host cannot verify new metadata. */ }
960
1012
  })().finally(() => { report.pending = undefined; });
@@ -985,6 +1037,8 @@ export class UiHost {
985
1037
  return;
986
1038
  // This is advisory state, accepted only from the mounted origin/document. It grants no authority.
987
1039
  if (msg.type === "hosty:ui:auth-required") {
1040
+ this.feedbackRpc.clear(frame);
1041
+ this.feedback.remove(frame.view.viewId);
988
1042
  frame.connected = false;
989
1043
  frame.actor = null;
990
1044
  frame.onConnection?.(false);
@@ -1002,7 +1056,7 @@ export class UiHost {
1002
1056
  }
1003
1057
  this.post(frame, { type: "hosty:ui:connected", coreOrigin: own.coreOrigin, userId: own.userId,
1004
1058
  appId: own.app.appId, installationId: own.app.installationId, code: frame.connected ? null : "actor_mismatch", route: frame.surface.route,
1005
- ...(frame.composition ? { capabilities: [UI_COMPOSITION_CAPABILITY, UI_MAIN_NAVIGATION_CAPABILITY], chrome: frame.chrome, revision: ++frame.policyRevision,
1059
+ ...(frame.composition ? { capabilities: [UI_COMPOSITION_CAPABILITY, UI_MAIN_NAVIGATION_CAPABILITY, FEEDBACK_CAPABILITY], chrome: frame.chrome, revision: ++frame.policyRevision,
1006
1060
  rootDisabled: !this.getChrome().tools.enabled, endpoint: frame.surface.endpoint } : {}) });
1007
1061
  if (frame.connected !== wasConnected)
1008
1062
  frame.onConnection?.(frame.connected);
@@ -1012,6 +1066,47 @@ export class UiHost {
1012
1066
  }
1013
1067
  if (!frame.connected)
1014
1068
  return;
1069
+ const visible = () => frame.live && frame.connected && frame.actor === this.snapshot.bootstrap?.userId && !frame.element.closest('[hidden],[inert]') && frame.element.getBoundingClientRect().width > 0;
1070
+ if (msg.type === "hosty:ui:feedback-source" && validCapabilities(msg.value)) {
1071
+ const c = msg.value;
1072
+ if (c.appId !== frame.surface.appId || c.installation !== frame.surface.installationId || c.userId !== own.userId)
1073
+ return;
1074
+ this.feedback.register({ id: frame.view.viewId, capabilities: c, workspaceId: frame.view.workspaceId, route: frame.surface.route, label: frame.element.title || c.appId,
1075
+ visible, invoke: operation => this.feedbackRpc.request(frame, requestId => this.post(frame, { type: 'hosty:ui:feedback-invoke', requestId, operation })) });
1076
+ return;
1077
+ }
1078
+ if (msg.type === 'hosty:ui:feedback-source-close') {
1079
+ this.feedbackRpc.clear(frame);
1080
+ this.feedback.removeSource(frame.view.viewId);
1081
+ return;
1082
+ }
1083
+ if (msg.type === 'hosty:ui:feedback-source-result') {
1084
+ this.feedbackRpc.receive(frame, msg.requestId, msg.value, msg.error);
1085
+ return;
1086
+ }
1087
+ if (msg.type === 'hosty:ui:feedback-connect' && frame.surface.feedbackComposer && (!frame.routeReport?.route || routeWithin(frame.routeReport.route, frame.surface.route))) {
1088
+ this.feedback.connect(frame.view.viewId, { workspaceId: frame.view.workspaceId, visible, receive: value => this.post(frame, { type: 'hosty:ui:feedback-event', value }) });
1089
+ return;
1090
+ }
1091
+ if (msg.type === 'hosty:ui:feedback-disconnect') {
1092
+ this.feedback.disconnect(frame.view.viewId);
1093
+ return;
1094
+ }
1095
+ if (msg.type === 'hosty:ui:feedback-request' && validId(msg.requestId) && feedbackOperation(msg.operation)) {
1096
+ const generation = frame.generation, nonce = frame.nonce;
1097
+ let value, error;
1098
+ try {
1099
+ if (!frame.surface.feedbackComposer || frame.routeReport?.route && !routeWithin(frame.routeReport.route, frame.surface.route))
1100
+ throw new Error('This panel is not a declared feedback composer.');
1101
+ value = await this.feedback.request(frame.view.viewId, msg.operation);
1102
+ }
1103
+ catch (e) {
1104
+ error = e instanceof Error ? e.message : 'Capture failed.';
1105
+ }
1106
+ if (frame.live && frame.connected && generation === frame.generation && nonce === frame.nonce)
1107
+ this.post(frame, { type: 'hosty:ui:feedback-result', requestId: msg.requestId, value, error });
1108
+ return;
1109
+ }
1015
1110
  const source = `${frame.surface.appId}:${frame.generation}:${frame.nonce}`;
1016
1111
  if (frame.composition && (msg.type === "hosty:ui:picker" || msg.type === "hosty:ui:navigate" || msg.type === "hosty:ui:navigate-main") && validId(msg.requestId)) {
1017
1112
  const result = msg.type === "hosty:ui:picker" ? await this.pickTools({ requestId: msg.requestId }, frame)
@@ -1048,9 +1143,13 @@ export class UiHost {
1048
1143
  }
1049
1144
  else if (msg.type === "hosty:ui:surface-state" && canonicalSurfaceRoute(msg.route) !== null
1050
1145
  && canonicalSurfaceRoute(msg.route) === canonicalSurfaceRoute(frame.view.presentationId
1051
- ? this.snapshot.tools.find(t => t.presentationId === frame.view.presentationId)?.currentRoute : frame.surface.route)) {
1052
- if (msg.state === "ready")
1146
+ ? this.snapshot.tools.find(t => t.presentationId === frame.view.presentationId)?.currentRoute : frame.routeReport ? frame.routeReport.currentRoute : frame.surface.route)) {
1147
+ if (msg.state === "ready") {
1053
1148
  this.reportFrame(frame, "ready");
1149
+ frame.view.onSurfaceState?.({ route: canonicalSurfaceRoute(msg.route),
1150
+ ...(typeof msg.title === "string" && msg.title.trim().length > 0 && msg.title.length <= 200
1151
+ && !/[\u0000-\u001f\u007f]/.test(msg.title) ? { title: msg.title.trim() } : {}) });
1152
+ }
1054
1153
  else if (msg.state === "auth-required" || msg.state === "blocked")
1055
1154
  this.reportFrame(frame, "auth-required");
1056
1155
  }
@@ -1065,6 +1164,8 @@ export class UiHost {
1065
1164
  if (this.disposed)
1066
1165
  return;
1067
1166
  this.resetPresentations();
1167
+ this.feedbackRpc.clear();
1168
+ this.feedback.clear();
1068
1169
  this.disposed = true;
1069
1170
  this.composition.dispose();
1070
1171
  this.actions.clear();