@hosty-sdk/app 0.38.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 (52) hide show
  1. package/README.md +4 -2
  2. package/dist/agent-sessions.d.ts +73 -0
  3. package/dist/agent-sessions.js +1 -0
  4. package/dist/feedback-capture.d.ts +5 -1
  5. package/dist/feedback-capture.js +41 -2
  6. package/dist/feedback-channel.d.ts +91 -0
  7. package/dist/feedback-channel.js +187 -0
  8. package/dist/feedback-client.d.ts +8 -0
  9. package/dist/feedback-client.js +26 -0
  10. package/dist/feedback-draft.d.ts +1 -5
  11. package/dist/feedback-draft.js +0 -31
  12. package/dist/feedback-react.d.ts +6 -2
  13. package/dist/feedback-react.js +235 -357
  14. package/dist/feedback-rpc.d.ts +7 -0
  15. package/dist/feedback-rpc.js +42 -0
  16. package/dist/feedback-workspace.d.ts +13 -0
  17. package/dist/feedback-workspace.js +28 -0
  18. package/dist/history.d.ts +354 -0
  19. package/dist/history.js +1 -0
  20. package/dist/providers-server.d.ts +17 -1
  21. package/dist/providers-server.js +33 -1
  22. package/dist/providers.d.ts +76 -1
  23. package/dist/sdk-chrome.d.ts +1 -1
  24. package/dist/sdk-chrome.js +4 -0
  25. package/dist/tasks-server.d.ts +11 -0
  26. package/dist/tasks-server.js +15 -0
  27. package/dist/ui-embedded.d.ts +10 -0
  28. package/dist/ui-embedded.js +61 -0
  29. package/dist/ui-frame.js +1 -0
  30. package/dist/ui-host.d.ts +15 -2
  31. package/dist/ui-host.js +128 -27
  32. package/dist/ui-navigation-react.js +9 -4
  33. package/dist/ui-react.d.ts +5 -1
  34. package/dist/ui-react.js +59 -15
  35. package/dist/ui-server.d.ts +2 -0
  36. package/dist/ui-server.js +28 -3
  37. package/dist/ui-standalone-context.d.ts +8 -0
  38. package/dist/ui-standalone-context.js +3 -0
  39. package/dist/ui-standalone-preferences.d.ts +17 -0
  40. package/dist/ui-standalone-preferences.js +77 -0
  41. package/dist/ui-standalone-react.d.ts +24 -0
  42. package/dist/ui-standalone-react.js +47 -0
  43. package/dist/ui-transport.js +1 -1
  44. package/dist/ui-types.d.ts +5 -0
  45. package/dist/ui-workspaces.d.ts +7 -0
  46. package/dist/ui-workspaces.js +1 -1
  47. package/dist/ui.d.ts +1 -0
  48. package/package.json +13 -1
  49. package/dist/feedback-audio.d.ts +0 -3
  50. package/dist/feedback-audio.js +0 -40
  51. package/dist/feedback-speech.d.ts +0 -6
  52. package/dist/feedback-speech.js +0 -119
package/README.md CHANGED
@@ -396,8 +396,10 @@ export const POST = handler;
396
396
  ```
397
397
 
398
398
  Non-Next servers use `createHostyUiResponse` from `@hosty-sdk/app/ui/server` with their
399
- revalidated own app-user session/token. `UiServerClient` provides only `bootstrap`,
400
- `listPanels`, `resolvePanel`, `navigation` and `resolveNavigation`; never expose a generic Core proxy or caller-supplied credentials.
399
+ revalidated own app-user session/token. Forward the returned status, headers and body unchanged:
400
+ UI routes include the binary `icon` response as well as JSON metadata. The same-origin icon route
401
+ serves only the caller's declared icon using its service token and the revalidated user session.
402
+ `UiServerClient` exposes fixed operations; never expose a generic Core proxy or caller-supplied credentials.
401
403
  Both server adapters return `no-store` metadata. The React root's `uiPath` defaults to
402
404
  `/api/hosty/ui` and must be a same-origin path.
403
405
 
@@ -0,0 +1,73 @@
1
+ /** Local-to-Core identities. Never infer an app, conversation, native session or run from another ID. */
2
+ export type ProviderRef = {
3
+ appId: string;
4
+ installationId: string;
5
+ key: string;
6
+ };
7
+ export type ConversationRef = {
8
+ provider: ProviderRef;
9
+ id: string;
10
+ };
11
+ export type NativeSessionRef = {
12
+ provider: ProviderRef;
13
+ id: string;
14
+ };
15
+ export type RunRef = {
16
+ provider: ProviderRef;
17
+ id: string;
18
+ };
19
+ /** Decimal strings avoid integer truncation across language boundaries. */
20
+ export type Revision = string;
21
+ export type AgentSession = {
22
+ ref: NativeSessionRef;
23
+ revision: Revision;
24
+ activeRuns: RunRef[];
25
+ capabilities: string[];
26
+ conversation?: ConversationRef | null;
27
+ };
28
+ export type AgentRun = {
29
+ ref: RunRef;
30
+ revision: Revision;
31
+ state: "queued" | "running" | "waiting_for_input" | "succeeded" | "failed" | "cancelled" | "unknown";
32
+ observedAt: string;
33
+ freshness: "current" | "last_known" | "unavailable";
34
+ stopConfirmed: boolean;
35
+ nativeSession?: NativeSessionRef | null;
36
+ conversation?: ConversationRef | null;
37
+ };
38
+ export type AgentSessionPage = {
39
+ sessions: AgentSession[];
40
+ nextCursor: string | null;
41
+ availability: "available" | "partial" | "unavailable";
42
+ observedAt: string;
43
+ };
44
+ export type AgentSessionQuery = {
45
+ provider: ProviderRef;
46
+ conversation?: ConversationRef;
47
+ cursor?: string;
48
+ limit?: number;
49
+ };
50
+ export type RunCancel = {
51
+ run: RunRef;
52
+ requestId: string;
53
+ expectedRevision: Revision;
54
+ };
55
+ export type RunCancelReceipt = {
56
+ requestId: string;
57
+ state: "accepted" | "completed";
58
+ run: AgentRun;
59
+ };
60
+ export type AgentRunNotification = {
61
+ run: AgentRun;
62
+ cursor: string;
63
+ rescanRequired: boolean;
64
+ };
65
+ export type AgentRunSubscription = {
66
+ handle: string;
67
+ expiresAt: string;
68
+ initial: AgentRunNotification;
69
+ };
70
+ export type AgentRunSubscriptionCreate = {
71
+ run: RunRef;
72
+ cursor?: string;
73
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,7 @@
1
1
  import type { FeedbackRect } from "./feedback-types.js";
2
- export declare function captureStill(hide: (hidden: boolean) => void, signal: AbortSignal): Promise<Blob>;
2
+ export declare function captureStill(hide: (hidden: boolean) => void, requestedSignal: AbortSignal, onCrop?: (cropped: boolean) => void, crop?: (track: MediaStreamTrack | undefined) => Promise<boolean>): Promise<Blob>;
3
+ /** Capture the entire browser-approved surface after the caller has prepared its selection outline. */
4
+ export declare function captureScreen(signal: AbortSignal, beforeCapture?: () => Promise<void>): Promise<Blob>;
3
5
  export declare function cropStill(blob: Blob, crop: FeedbackRect | null): Promise<Blob>;
6
+ /** Only the browser can prove that the chosen capture contains this document. Never infer it from dimensions. */
7
+ export declare function cropCaptureToDocument(track?: MediaStreamTrack): Promise<boolean>;
@@ -1,4 +1,4 @@
1
- export async function captureStill(hide, signal) {
1
+ export async function captureStill(hide, requestedSignal, onCrop, crop) {
2
2
  if (!navigator.mediaDevices?.getDisplayMedia)
3
3
  throw new Error("Screen capture is unavailable in this browser. You can still send comments.");
4
4
  // Offer the application tab while retaining the browser-owned chooser and permission.
@@ -8,11 +8,20 @@ export async function captureStill(hide, signal) {
8
8
  const stream = await navigator.mediaDevices.getDisplayMedia(options);
9
9
  const video = document.createElement("video");
10
10
  const stop = () => { stream.getTracks().forEach(t => t.stop()); };
11
+ const controller = new AbortController(), signal = controller.signal;
12
+ const abort = () => controller.abort(requestedSignal.reason);
13
+ const ended = () => controller.abort(new Error("Screen capture ended."));
14
+ requestedSignal.addEventListener("abort", abort, { once: true });
15
+ if (requestedSignal.aborted)
16
+ abort();
17
+ stream.getTracks().forEach(t => t.addEventListener?.("ended", ended, { once: true }));
11
18
  signal.addEventListener("abort", stop, { once: true });
12
19
  try {
13
20
  signal.throwIfAborted();
14
21
  hide(true);
15
- // Let the hidden overlay reach the compositor before consuming the live stream.
22
+ const cropped = await abortable((crop ?? cropCaptureToDocument)(stream.getVideoTracks?.()[0]), signal);
23
+ onCrop?.(cropped);
24
+ // Let the prepared outline or hidden overlay reach the compositor before reading a frame.
16
25
  await new Promise(resolve => setTimeout(resolve, 100));
17
26
  signal.throwIfAborted();
18
27
  video.muted = true;
@@ -53,10 +62,25 @@ export async function captureStill(hide, signal) {
53
62
  finally {
54
63
  stop();
55
64
  signal.removeEventListener("abort", stop);
65
+ requestedSignal.removeEventListener("abort", abort);
66
+ stream.getTracks().forEach(t => t.removeEventListener?.("ended", ended));
56
67
  video.srcObject = null;
57
68
  hide(false);
58
69
  }
59
70
  }
71
+ /** Capture the entire browser-approved surface after the caller has prepared its selection outline. */
72
+ export function captureScreen(signal, beforeCapture) {
73
+ return captureStill(() => { }, signal, undefined, async () => { await beforeCapture?.(); return false; });
74
+ }
75
+ function abortable(operation, signal) {
76
+ return new Promise((resolve, reject) => {
77
+ const abort = () => reject(signal.reason);
78
+ signal.addEventListener("abort", abort, { once: true });
79
+ if (signal.aborted)
80
+ abort();
81
+ operation.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
82
+ });
83
+ }
60
84
  export async function cropStill(blob, crop) {
61
85
  if (!crop)
62
86
  return blob;
@@ -78,3 +102,18 @@ export async function cropStill(blob, crop) {
78
102
  function canvasBlob(canvas) {
79
103
  return new Promise((resolve, reject) => canvas.toBlob(blob => blob ? resolve(blob) : reject(new Error("Could not encode the screenshot.")), "image/png"));
80
104
  }
105
+ /** Only the browser can prove that the chosen capture contains this document. Never infer it from dimensions. */
106
+ export async function cropCaptureToDocument(track) {
107
+ const api = globalThis;
108
+ const capture = track;
109
+ if (!api.CropTarget?.fromElement || !capture?.cropTo)
110
+ return false;
111
+ try {
112
+ const target = await api.CropTarget.fromElement(document.documentElement);
113
+ await capture.cropTo(target);
114
+ return true;
115
+ }
116
+ catch {
117
+ return false;
118
+ } // Another tab/window or unsupported geometry: explicit preview/manual crop.
119
+ }
@@ -0,0 +1,91 @@
1
+ import type { FeedbackCapabilities, FeedbackNoteInput, FeedbackTarget } from './feedback-types.js';
2
+ export declare const FEEDBACK_CAPABILITY = "feedback.capture.v2";
3
+ export declare const FEEDBACK_ROOT = "host";
4
+ export type DraftNote = Omit<FeedbackNoteInput, 'image'> & {
5
+ image?: Blob;
6
+ };
7
+ export type FeedbackDraft = {
8
+ key: string;
9
+ revision: number;
10
+ requestId: string;
11
+ comment: string;
12
+ annotations: DraftNote[];
13
+ submitting: boolean;
14
+ };
15
+ export type FeedbackSource = {
16
+ id: string;
17
+ capabilities: FeedbackCapabilities;
18
+ label: string;
19
+ route: string;
20
+ workspaceId: string;
21
+ };
22
+ export type FeedbackOperation = {
23
+ action: 'sources' | 'pick' | 'cancel' | 'page' | 'highlight' | 'crop-target' | 'legacy-read' | 'legacy-delete' | 'submit';
24
+ sourceId?: string;
25
+ mode?: 'element' | 'region';
26
+ target?: FeedbackTarget;
27
+ draft?: FeedbackDraft;
28
+ requestId?: string;
29
+ revision?: number;
30
+ };
31
+ export type FeedbackEvent = {
32
+ type: 'sources';
33
+ sources: FeedbackSource[];
34
+ } | {
35
+ type: 'selection';
36
+ source: FeedbackSource;
37
+ note: DraftNote;
38
+ } | {
39
+ type: 'picking';
40
+ mode: 'element' | 'region' | null;
41
+ };
42
+ export type FeedbackPort = {
43
+ request(operation: FeedbackOperation): Promise<unknown>;
44
+ close(): void;
45
+ };
46
+ export type FeedbackConnection = (receive: (event: FeedbackEvent) => void) => FeedbackPort;
47
+ type Source = FeedbackSource & {
48
+ visible(): boolean;
49
+ invoke(operation: FeedbackOperation): Promise<unknown>;
50
+ };
51
+ type Composer = {
52
+ workspaceId: string;
53
+ visible(): boolean;
54
+ receive(event: FeedbackEvent): void;
55
+ };
56
+ export declare const EMPTY_FEEDBACK: {
57
+ picking: boolean;
58
+ pickMode: "element" | "region" | undefined;
59
+ };
60
+ export declare function feedbackScope(c: FeedbackCapabilities): string;
61
+ export declare function validCapabilities(value: unknown): value is FeedbackCapabilities;
62
+ export declare function validTarget(t: unknown): t is FeedbackTarget;
63
+ export declare function validDraft(value: unknown): value is FeedbackDraft;
64
+ export declare function feedbackOperation(value: unknown): value is FeedbackOperation;
65
+ /** Mounted, verified documents only. Form state never lives in this broker. */
66
+ export declare class FeedbackHost {
67
+ private sources;
68
+ private composers;
69
+ private listeners;
70
+ private delivered;
71
+ private snapshot;
72
+ private picking;
73
+ private generation;
74
+ getSnapshot: () => {
75
+ picking: boolean;
76
+ pickMode: "element" | "region" | undefined;
77
+ };
78
+ subscribe: (listener: () => void) => () => void;
79
+ refresh: () => void;
80
+ private publish;
81
+ register(source: Source): void;
82
+ removeSource(id: string): void;
83
+ remove(id: string): void;
84
+ clear(): void;
85
+ connect(id: string, composer: Composer): FeedbackPort;
86
+ disconnect(id: string): void;
87
+ private available;
88
+ cancel(notify?: boolean): void;
89
+ request(id: string, operation: FeedbackOperation): Promise<unknown>;
90
+ }
91
+ export {};
@@ -0,0 +1,187 @@
1
+ export const FEEDBACK_CAPABILITY = 'feedback.capture.v2';
2
+ export const FEEDBACK_ROOT = 'host';
3
+ export const EMPTY_FEEDBACK = { picking: false, pickMode: undefined };
4
+ export function feedbackScope(c) { return JSON.stringify([c.coreId, c.appId, c.installation, c.userId]); }
5
+ export function validCapabilities(value) {
6
+ if (!value || typeof value !== 'object')
7
+ return false;
8
+ const c = value;
9
+ return c.version === 1 && [c.coreId, c.appId, c.installation, c.userId].every(s => typeof s === 'string' && s.length > 0 && s.length <= 512)
10
+ && c.maxAnnotations > 0 && c.maxAnnotations <= 20 && c.maxImageBytes > 0 && c.maxImageBytes <= 2097152 && c.maxTotalImageBytes > 0 && c.maxTotalImageBytes <= 8388608;
11
+ }
12
+ export function validTarget(t) {
13
+ if (!t || typeof t !== 'object')
14
+ return false;
15
+ const v = t;
16
+ return ['page', 'element', 'region'].includes(v.kind) && (v.label === undefined || typeof v.label === 'string' && v.label.length <= 200)
17
+ && (v.selector === undefined || typeof v.selector === 'string' && v.selector.length <= 2048)
18
+ && (!v.bounds || ['x', 'y', 'width', 'height'].every(k => Number.isFinite(v.bounds[k])))
19
+ && (!v.viewport || ['width', 'height', 'scale'].every(k => Number.isFinite(v.viewport[k])));
20
+ }
21
+ export function validDraft(value) {
22
+ if (!value || typeof value !== 'object')
23
+ return false;
24
+ const d = value;
25
+ if (typeof d.key !== 'string' || d.key.length > 4096 || typeof d.requestId !== 'string' || d.requestId.length > 128 || !d.requestId
26
+ || !Number.isSafeInteger(d.revision) || d.revision < 0 || typeof d.submitting !== 'boolean' || typeof d.comment !== 'string' || d.comment.length > 5000
27
+ || !Array.isArray(d.annotations) || d.annotations.length > 20)
28
+ return false;
29
+ let bytes = 0;
30
+ return d.annotations.every(n => {
31
+ if (!n || typeof n.id !== 'string' || n.id.length > 128 || typeof n.text !== 'string' || n.text.length > 2000 || typeof n.route !== 'string' || n.route.length > 8192
32
+ || typeof n.capturedAt !== 'string' || !Number.isFinite(Date.parse(n.capturedAt)) || n.target && !validTarget(n.target))
33
+ return false;
34
+ if (n.image) {
35
+ if (!(n.image instanceof Blob) || !['image/png', 'image/jpeg'].includes(n.image.type) || n.image.size > 2097152)
36
+ return false;
37
+ bytes += n.image.size;
38
+ }
39
+ return bytes <= 8388608;
40
+ });
41
+ }
42
+ export function feedbackOperation(value) {
43
+ if (!value || typeof value !== 'object')
44
+ return false;
45
+ const o = value;
46
+ return ['sources', 'pick', 'cancel', 'page', 'highlight', 'crop-target', 'legacy-read', 'legacy-delete', 'submit'].includes(o.action)
47
+ && (o.sourceId === undefined || typeof o.sourceId === 'string' && o.sourceId.length <= 512)
48
+ && (o.mode === undefined || ['element', 'region'].includes(o.mode)) && (o.target === undefined || validTarget(o.target))
49
+ && (o.requestId === undefined || typeof o.requestId === 'string' && o.requestId.length <= 128)
50
+ && (o.revision === undefined || Number.isSafeInteger(o.revision) && o.revision >= 0)
51
+ && (o.draft === undefined || validDraft(o.draft));
52
+ }
53
+ /** Mounted, verified documents only. Form state never lives in this broker. */
54
+ export class FeedbackHost {
55
+ sources = new Map();
56
+ composers = new Map();
57
+ listeners = new Set();
58
+ delivered = new Map();
59
+ snapshot = EMPTY_FEEDBACK;
60
+ picking = null;
61
+ generation = 0;
62
+ getSnapshot = () => this.snapshot;
63
+ subscribe = (listener) => { this.listeners.add(listener); return () => { this.listeners.delete(listener); }; };
64
+ refresh = () => {
65
+ for (const [id, composer] of this.composers) {
66
+ const sources = this.available(id), serialized = JSON.stringify(sources);
67
+ if (this.delivered.get(id) === serialized)
68
+ continue;
69
+ this.delivered.set(id, serialized);
70
+ composer.receive({ type: 'sources', sources });
71
+ }
72
+ if (this.picking && !this.composers.get(this.picking.owner)?.visible())
73
+ this.cancel();
74
+ };
75
+ publish() { this.refresh(); for (const listener of this.listeners)
76
+ listener(); }
77
+ register(source) {
78
+ const current = this.sources.get(source.id);
79
+ if (current && feedbackScope(current.capabilities) === feedbackScope(source.capabilities) && current.route === source.route && current.workspaceId === source.workspaceId)
80
+ Object.assign(current, source);
81
+ else
82
+ this.sources.set(source.id, source);
83
+ this.publish();
84
+ }
85
+ removeSource(id) {
86
+ if (this.picking?.ids.includes(id))
87
+ this.cancel();
88
+ this.sources.delete(id);
89
+ this.publish();
90
+ }
91
+ remove(id) { this.disconnect(id); this.removeSource(id); }
92
+ clear() { this.cancel(); this.sources.clear(); this.publish(); this.composers.clear(); }
93
+ connect(id, composer) {
94
+ this.disconnect(id);
95
+ this.composers.set(id, composer);
96
+ this.refresh();
97
+ return { request: o => this.request(id, o), close: () => this.disconnect(id) };
98
+ }
99
+ disconnect(id) {
100
+ if (this.picking?.owner === id)
101
+ this.cancel();
102
+ this.composers.delete(id);
103
+ this.delivered.delete(id);
104
+ }
105
+ available(id) {
106
+ const c = this.composers.get(id);
107
+ if (!c?.visible())
108
+ return [];
109
+ return [...this.sources.values()].filter(s => s.visible() && (c.workspaceId === 'default' || c.workspaceId === s.workspaceId))
110
+ .map(({ visible: _visible, invoke: _invoke, ...s }) => s);
111
+ }
112
+ cancel(notify = true) {
113
+ const pick = this.picking;
114
+ this.picking = null;
115
+ ++this.generation;
116
+ this.snapshot = EMPTY_FEEDBACK;
117
+ if (pick) {
118
+ for (const id of pick.ids)
119
+ void this.sources.get(id)?.invoke({ action: 'cancel' }).catch(() => { });
120
+ if (notify)
121
+ this.composers.get(pick.owner)?.receive({ type: 'picking', mode: null });
122
+ }
123
+ for (const l of this.listeners)
124
+ l();
125
+ }
126
+ async request(id, operation) {
127
+ if (!feedbackOperation(operation) || !this.composers.get(id)?.visible())
128
+ throw new Error('Open a declared Feedback tool to collect feedback.');
129
+ if (operation.action === 'sources')
130
+ return this.available(id);
131
+ if (operation.action === 'cancel') {
132
+ if (this.picking?.owner === id)
133
+ this.cancel();
134
+ return null;
135
+ }
136
+ const allowed = this.available(id);
137
+ if (operation.action === 'pick') {
138
+ this.cancel();
139
+ const mode = operation.mode ?? 'element';
140
+ const candidates = allowed.filter(s => mode === 'element' || s.id === operation.sourceId);
141
+ if (!candidates.length)
142
+ throw new Error('Open the application before selecting an element.');
143
+ const generation = ++this.generation;
144
+ this.picking = { owner: id, generation, ids: candidates.map(s => s.id) };
145
+ this.snapshot = { picking: true, pickMode: mode };
146
+ this.composers.get(id)?.receive({ type: 'picking', mode });
147
+ for (const l of this.listeners)
148
+ l();
149
+ for (const s of candidates)
150
+ void this.sources.get(s.id).invoke({ ...operation, mode }).then(value => {
151
+ if (this.picking?.generation !== generation)
152
+ return;
153
+ if (!value) {
154
+ this.cancel();
155
+ return;
156
+ }
157
+ if (!this.available(id).some(a => a.id === s.id) || !validDraft({ key: '', revision: 0, requestId: 'selection', comment: '', submitting: false, annotations: [value] })) {
158
+ this.cancel();
159
+ return;
160
+ }
161
+ this.cancel(false);
162
+ const composer = this.composers.get(id);
163
+ // Deliver the result before ending selection so capture can distinguish completion from cancellation.
164
+ composer?.receive({ type: 'selection', source: s, note: value });
165
+ composer?.receive({ type: 'picking', mode: null });
166
+ }).catch(() => {
167
+ if (this.picking?.generation === generation)
168
+ this.cancel();
169
+ });
170
+ return null;
171
+ }
172
+ const source = this.sources.get(operation.sourceId ?? '');
173
+ if (!source || !allowed.some(s => s.id === source.id))
174
+ throw new Error('This application is no longer visible in the workspace.');
175
+ if (operation.action === 'submit' && (!operation.draft || operation.draft.key !== feedbackScope(source.capabilities)))
176
+ throw new Error('Feedback belongs to a different application or account.');
177
+ const composer = this.composers.get(id);
178
+ const value = await source.invoke(operation);
179
+ if (this.composers.get(id) !== composer || this.sources.get(source.id) !== source || !this.available(id).some(s => s.id === source.id))
180
+ throw new Error('The source document changed. Reopen it before retrying.');
181
+ if (operation.action === 'legacy-read' && value !== null && (!validDraft(value) || value.key !== feedbackScope(source.capabilities)))
182
+ throw new Error('The source returned an invalid recovery draft.');
183
+ if (operation.action === 'page' && !validDraft({ key: '', revision: 0, requestId: 'page', comment: '', submitting: false, annotations: [value] }))
184
+ throw new Error('The source returned invalid page context.');
185
+ return value;
186
+ }
187
+ }
@@ -0,0 +1,8 @@
1
+ import type { FeedbackConnection, FeedbackEvent, FeedbackPort } from './feedback-channel.js';
2
+ export type { FeedbackDraft, DraftNote, FeedbackSource, FeedbackEvent, FeedbackOperation, FeedbackPort } from './feedback-channel.js';
3
+ export { feedbackScope, validDraft } from './feedback-channel.js';
4
+ export { captureStill, captureScreen, cropStill } from './feedback-capture.js';
5
+ /** Internal root binding: no window globals and no credentials cross the channel. */
6
+ export declare function bindFeedbackClient(value: FeedbackConnection): () => void;
7
+ /** Reconnects after the UI root establishes or replaces its verified channel. */
8
+ export declare function connectFeedback(receive: (event: FeedbackEvent) => void): FeedbackPort;
@@ -0,0 +1,26 @@
1
+ export { feedbackScope, validDraft } from './feedback-channel.js';
2
+ export { captureStill, captureScreen, cropStill } from './feedback-capture.js';
3
+ let connect = null;
4
+ const listeners = new Set();
5
+ /** Internal root binding: no window globals and no credentials cross the channel. */
6
+ export function bindFeedbackClient(value) {
7
+ connect = value;
8
+ for (const listener of listeners)
9
+ listener();
10
+ return () => {
11
+ if (connect === value) {
12
+ connect = null;
13
+ for (const listener of listeners)
14
+ listener();
15
+ }
16
+ };
17
+ }
18
+ /** Reconnects after the UI root establishes or replaces its verified channel. */
19
+ export function connectFeedback(receive) {
20
+ let port = null;
21
+ const refresh = () => { port?.close(); port = connect?.(receive) ?? null; };
22
+ listeners.add(refresh);
23
+ refresh();
24
+ return { request: (op) => port?.request(op) ?? Promise.reject(new Error('Feedback tools require a connected workspace.')),
25
+ close: () => { listeners.delete(refresh); port?.close(); } };
26
+ }
@@ -1,4 +1,4 @@
1
- import type { FeedbackCapabilities, FeedbackNoteInput, FeedbackSubmit, FeedbackTarget } from "./feedback-types.js";
1
+ import type { FeedbackCapabilities, FeedbackNoteInput, FeedbackSubmit } from "./feedback-types.js";
2
2
  export type DraftNote = Omit<FeedbackNoteInput, "image"> & {
3
3
  image?: Blob;
4
4
  };
@@ -12,9 +12,5 @@ export type FeedbackDraft = {
12
12
  };
13
13
  export declare function draftKey(capabilities: FeedbackCapabilities): string;
14
14
  export declare function readDraft(key: string): Promise<FeedbackDraft | null>;
15
- /** Read-check-write is one transaction: an older tab cannot overwrite a newer draft. */
16
- export declare function saveDraft(draft: FeedbackDraft, expectedRevision: number, expectedRequestId: string | null): Promise<void>;
17
15
  export declare function deleteDraft(key: string, requestId: string, expectedRevision: number): Promise<void>;
18
- export declare function blankDraft(key: string): FeedbackDraft;
19
- export declare function makeNote(target: FeedbackTarget): DraftNote;
20
16
  export declare function submission(draft: FeedbackDraft): Promise<FeedbackSubmit>;
@@ -32,31 +32,6 @@ export async function readDraft(key) {
32
32
  db.close();
33
33
  }
34
34
  }
35
- /** Read-check-write is one transaction: an older tab cannot overwrite a newer draft. */
36
- export async function saveDraft(draft, expectedRevision, expectedRequestId) {
37
- const db = await open();
38
- try {
39
- await new Promise((resolve, reject) => {
40
- const tx = db.transaction("drafts", "readwrite");
41
- const store = tx.objectStore("drafts");
42
- const read = store.get(draft.key);
43
- let conflict = false;
44
- read.onsuccess = () => {
45
- if ((read.result?.revision ?? 0) !== expectedRevision || (read.result?.requestId ?? null) !== expectedRequestId) {
46
- conflict = true;
47
- tx.abort();
48
- return;
49
- }
50
- store.put(draft);
51
- };
52
- tx.oncomplete = () => resolve();
53
- tx.onabort = tx.onerror = () => reject(conflict ? new Error("This draft changed in another tab. Reload to restore its latest saved version.") : tx.error ?? new Error("Draft could not be saved locally."));
54
- });
55
- }
56
- finally {
57
- db.close();
58
- }
59
- }
60
35
  export async function deleteDraft(key, requestId, expectedRevision) {
61
36
  const db = await open();
62
37
  try {
@@ -83,12 +58,6 @@ export async function deleteDraft(key, requestId, expectedRevision) {
83
58
  db.close();
84
59
  }
85
60
  }
86
- export function blankDraft(key) {
87
- return { key, revision: 0, requestId: crypto.randomUUID(), comment: "", annotations: [], submitting: false };
88
- }
89
- export function makeNote(target) {
90
- return { id: crypto.randomUUID(), text: "", route: location.pathname, capturedAt: new Date().toISOString(), target };
91
- }
92
61
  export async function submission(draft) {
93
62
  const [coreId, appId, installation, userId] = JSON.parse(draft.key);
94
63
  return { scope: { coreId: coreId, appId: appId, installation: installation, userId: userId }, requestId: draft.requestId, comment: draft.comment, annotations: await Promise.all(draft.annotations.map(async (note) => {
@@ -1,4 +1,8 @@
1
- export declare function FeedbackCapture({ active, uiPath }: {
1
+ import type { UiHost } from './ui-host.js';
2
+ import type { EmbeddedUiClient } from './ui-embedded.js';
3
+ /** Selection and source-authenticated intake only. The tool application owns all form UI/storage. */
4
+ export declare function FeedbackCapture({ active, uiPath, client }: {
2
5
  active: boolean;
3
6
  uiPath?: string;
4
- }): import("react").JSX.Element | null;
7
+ client?: UiHost | EmbeddedUiClient | null;
8
+ }): import("react").ReactPortal | null;