@markupai/sidebar-adapter 0.0.23 → 1.0.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.
Files changed (51) hide show
  1. package/README.md +38 -21
  2. package/dist/adapters/index.d.ts +3 -0
  3. package/dist/adapters/index.d.ts.map +1 -0
  4. package/dist/adapters/pluginAdapter.d.ts +73 -0
  5. package/dist/adapters/pluginAdapter.d.ts.map +1 -0
  6. package/dist/adapters/sidebarAdapter.d.ts +43 -0
  7. package/dist/adapters/sidebarAdapter.d.ts.map +1 -0
  8. package/dist/errors.d.ts +48 -0
  9. package/dist/errors.d.ts.map +1 -0
  10. package/dist/index.d.ts +7 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/ipc/call-signatures.d.ts +64 -0
  13. package/dist/ipc/call-signatures.d.ts.map +1 -0
  14. package/dist/ipc/deferred-promise.d.ts +49 -0
  15. package/dist/ipc/deferred-promise.d.ts.map +1 -0
  16. package/dist/ipc/index.d.ts +9 -0
  17. package/dist/ipc/index.d.ts.map +1 -0
  18. package/dist/ipc/ipc-core.d.ts +72 -0
  19. package/dist/ipc/ipc-core.d.ts.map +1 -0
  20. package/dist/ipc/message-types.d.ts +57 -0
  21. package/dist/ipc/message-types.d.ts.map +1 -0
  22. package/dist/ipc/plugin-ipc-adapter.d.ts +77 -0
  23. package/dist/ipc/plugin-ipc-adapter.d.ts.map +1 -0
  24. package/dist/ipc/sidebar-ipc-adapter.d.ts +38 -0
  25. package/dist/ipc/sidebar-ipc-adapter.d.ts.map +1 -0
  26. package/dist/load-overlay/index.d.ts +2 -0
  27. package/dist/load-overlay/index.d.ts.map +1 -0
  28. package/dist/load-overlay/loadOverlayDom.d.ts +5 -0
  29. package/dist/load-overlay/loadOverlayDom.d.ts.map +1 -0
  30. package/dist/load-overlay/loadOverlayStyles.d.ts +3 -0
  31. package/dist/load-overlay/loadOverlayStyles.d.ts.map +1 -0
  32. package/dist/load-overlay/sidebarLoadOverlay.d.ts +14 -0
  33. package/dist/load-overlay/sidebarLoadOverlay.d.ts.map +1 -0
  34. package/dist/main.js +289 -517
  35. package/dist/main.umd.cjs +12 -12
  36. package/dist/sidebar-host/createSidebarHost.d.ts +84 -0
  37. package/dist/sidebar-host/createSidebarHost.d.ts.map +1 -0
  38. package/dist/sidebar-host/index.d.ts +3 -0
  39. package/dist/sidebar-host/index.d.ts.map +1 -0
  40. package/dist/sidebar-host/sidebarHostShell.d.ts +56 -0
  41. package/dist/sidebar-host/sidebarHostShell.d.ts.map +1 -0
  42. package/dist/types/common.d.ts +95 -0
  43. package/dist/types/common.d.ts.map +1 -0
  44. package/dist/types/index.d.ts +4 -0
  45. package/dist/types/index.d.ts.map +1 -0
  46. package/dist/types/pluginInterface.d.ts +70 -0
  47. package/dist/types/pluginInterface.d.ts.map +1 -0
  48. package/dist/types/sidebarInterface.d.ts +41 -0
  49. package/dist/types/sidebarInterface.d.ts.map +1 -0
  50. package/package.json +5 -5
  51. package/dist/main.d.ts +0 -888
package/dist/main.d.ts DELETED
@@ -1,888 +0,0 @@
1
- /**
2
- * Serializable payload for a single agentic issue sent over IPC (Sidebar → Plugin).
3
- * Used when streaming agent results so the plugin can render underlines or other UI.
4
- */
5
- export declare interface AgenticIssuePayload {
6
- id: string;
7
- groupKey: string;
8
- status: "active" | "resolved" | "dismissed";
9
- original: string;
10
- agent: string;
11
- explanation: string;
12
- severity: "low" | "medium" | "high" | "critical";
13
- confidence: number;
14
- position: {
15
- start: number;
16
- end: number;
17
- sentence: string;
18
- };
19
- suggestion?: string;
20
- category?: string;
21
- }
22
-
23
- /**
24
- * Narrows {@link SidebarHost} after {@link createSidebarHost} when `plugin` was provided.
25
- */
26
- export declare function assertSidebarHostAdapter(host: SidebarHost, message?: string): asserts host is SidebarHostWithAdapter;
27
-
28
- /**
29
- * Build a minimal HTML document string for hosts that generate UI HTML at build time
30
- * (e.g. inline script into a single file). Runtime hosts usually prefer {@link ensureSidebarHostShell}
31
- * plus a tiny static HTML file.
32
- */
33
- export declare function buildSidebarHostHtmlDocument(options: BuildSidebarHostHtmlDocumentOptions): string;
34
-
35
- export declare type BuildSidebarHostHtmlDocumentOptions = {
36
- title?: string;
37
- /**
38
- * Extra tags inside `<head>` after charset/title (and after the plugin viewport block if {@link includePluginHostHead}).
39
- * No need to include shell styles.
40
- */
41
- headInnerHtml?: string;
42
- /**
43
- * When true, inserts {@link buildSidebarPluginHostHeadInnerHtml} before {@link headInnerHtml}.
44
- */
45
- includePluginHostHead?: boolean;
46
- /** One or more `<script>` tags (e.g. Vite entry). */
47
- bodyScriptsHtml: string;
48
- htmlLang?: string;
49
- /** Attributes for `<html>`, e.g. `lang="en" style="height:100%"`. */
50
- htmlAttrs?: string;
51
- /** Attributes for `<body>`, e.g. `style="height:100%;margin:0"`. */
52
- bodyAttrs?: string;
53
- /** Include `<base target="_top" />` as first element in `<head>`. */
54
- googleApps?: boolean;
55
- };
56
-
57
- /**
58
- * Layout CSS for hosts that embed the sidebar iframe (matches prior Google Workspace / Figma shells).
59
- * Use {@link buildSidebarHostShellCss} when the container id is not {@link SIDEBAR_HOST_CONTAINER_ID}.
60
- */
61
- export declare function buildSidebarHostShellCss(containerId?: string): string;
62
-
63
- /**
64
- * Default viewport `<meta>` for plugin UI host documents.
65
- * Use with {@link buildSidebarHostHtmlDocument} via {@link includePluginHostHead}, or as `headInnerHtml`.
66
- */
67
- export declare function buildSidebarPluginHostHeadInnerHtml(): string;
68
-
69
- /**
70
- * Message sent when calling a remote function
71
- */
72
- export declare type CallMessage = MessageBase & {
73
- type: "call";
74
- data: any[];
75
- };
76
-
77
- /**
78
- * Optional overrides for a single IPC call (e.g. timeout).
79
- */
80
- export declare interface CallOptions {
81
- /**
82
- * Timeout in milliseconds for this call. Overrides default IPC config timeout.
83
- */
84
- timeout?: number;
85
- }
86
-
87
- /**
88
- * Call signatures for all bidirectional IPC communication.
89
- * This interface maps method names to their parameter types and return types.
90
- */
91
- export declare interface CallSignatures {
92
- /**
93
- * Request content from the editor in whatever format the integration supports
94
- */
95
- getContent(): Promise<ContentInfo>;
96
- /**
97
- * Request selected content from the editor in whatever format the integration supports
98
- */
99
- getSelectedContent(): Promise<ContentInfo>;
100
- /**
101
- * Replace content in the editor
102
- * @throws {TextLookupError} When the requested text cannot be found or located
103
- */
104
- replaceContent(original: string, suggestion: string, range?: ContentRange): Promise<void>;
105
- /**
106
- * Select content in the editor
107
- * @throws {TextLookupError} When the requested text cannot be found or located
108
- */
109
- selectContent(original: string, startIndex: number): Promise<void>;
110
- /**
111
- * Show a dialog in the editor
112
- */
113
- showDialog(dialogHtml: string, width?: number, height?: number, title?: string): Promise<void>;
114
- /**
115
- * Close the dialog in the editor
116
- */
117
- closeDialog(): Promise<void>;
118
- /**
119
- * Replace multiple contents in the editor
120
- */
121
- replaceMultipleContents(replacements: ContentReplacement[]): Promise<void>;
122
- /**
123
- * Get initialization configuration from the editor
124
- * This is called by the sidebar when it's ready to initialize
125
- */
126
- getInitConfig(): Promise<SidebarConfig>;
127
- /**
128
- * Notify plugin when one agent's agentic results are available (streaming).
129
- */
130
- onAgenticAgentResults(agentName: string, issues: AgenticIssuePayload[]): Promise<void>;
131
- /**
132
- * Notify plugin when the agentic stream has finished.
133
- */
134
- onAgenticStreamComplete(): Promise<void>;
135
- /**
136
- * Notify sidebar of plugin status changes
137
- * Optional method - demonstrates Plugin → Sidebar communication pattern
138
- */
139
- onPluginStatusChange?(status: string): Promise<void>;
140
- /**
141
- * Request sidebar to activate (expand and scroll to) the card for the given issue id.
142
- */
143
- activateAgenticIssue(issueId: string): Promise<void>;
144
- }
145
-
146
- /**
147
- * Content information including the content, document reference, and optional mime type
148
- * The integration must provide content and documentReference - mimeType is optional
149
- * mimeType can be any valid MIME type string, not limited to AdapterMimeType enum values
150
- */
151
- export declare interface ContentInfo {
152
- content: string | number[];
153
- documentReference: string;
154
- mimeType?: string;
155
- }
156
-
157
- /**
158
- * Range of content to replace.
159
- * Used to specify the location of content in a document for replacement operations.
160
- */
161
- export declare interface ContentRange {
162
- /**
163
- * The zero-based character offset from the beginning of the document where the content to replace starts.
164
- * Must be a non-negative integer.
165
- */
166
- start: number;
167
- }
168
-
169
- export declare type ContentReplacement = {
170
- original: string;
171
- suggestion: string;
172
- range: ContentRange;
173
- };
174
-
175
- export declare function createSidebarHost(options: CreateSidebarHostOptions): SidebarHost;
176
-
177
- export declare type CreateSidebarHostOptions = {
178
- /**
179
- * When set, a {@link SidebarAdapter} is created. Omit for **iframe-only** hosts (e.g. Figma UI)
180
- * that forward IPC to another thread and only need the load overlay.
181
- */
182
- plugin?: PluginInterface;
183
- /**
184
- * When set, {@link setupSidebarLoadOverlay} is mounted for this container + iframe.
185
- */
186
- loadOverlayContainer?: HTMLElement;
187
- /** Options for the load overlay; only used when a load overlay container is in effect. */
188
- loadOverlayOptions?: SidebarLoadOverlayOptions;
189
- /** Forwarded to {@link SidebarAdapter} when `plugin` is set (e.g. `targetOrigin`, `config`, `win`). */
190
- adapterOptions?: SidebarAdapterOptions;
191
- /**
192
- * Existing sidebar iframe. Provide this **or** {@link iframeMount}, not both.
193
- */
194
- iframe?: HTMLIFrameElement;
195
- /**
196
- * Create and append a new iframe. Provide this **or** {@link iframe}, not both.
197
- */
198
- iframeMount?: CreateSidebarIframeMount;
199
- };
200
-
201
- /** Create and mount a new sidebar iframe under `container`. */
202
- export declare type CreateSidebarIframeMount = {
203
- /** Parent element; the iframe is appended as the last child. */
204
- container: HTMLElement;
205
- /** Full URL for `iframe.src` (include hash route if needed, e.g. `.../#/next-ui`). */
206
- src: string;
207
- /**
208
- * `iframe.allow` (Permissions Policy). Defaults to {@link SIDEBAR_IFRAME_DEFAULT_ALLOW}.
209
- * Pass `""` to omit the attribute.
210
- */
211
- allow?: string;
212
- };
213
-
214
- /**
215
- * Default IPC configuration
216
- */
217
- export declare const DEFAULT_IPC_CONFIG: Required<IPCConfig>;
218
-
219
- export declare const DEFAULT_SIDEBAR_CONFIG: SidebarConfig;
220
-
221
- /**
222
- * Represents a deferred promise that can be resolved or rejected via method
223
- * calls on the instance.
224
- */
225
- export declare class DeferredPromise<T> implements Promise<T> {
226
- private _promise;
227
- readonly [Symbol.toStringTag]: string;
228
- /**
229
- * Resolves the underlying promise with a specified value.
230
- *
231
- * @param value - The value to resolve the promise with.
232
- */
233
- resolve: (value: PromiseLike<T> | T) => void;
234
- /**
235
- * Rejects the underlying promise with a specified reason.
236
- *
237
- * @param reason - The reason for rejecting the promise.
238
- */
239
- reject: (reason?: any) => void;
240
- /**
241
- * Creates a new instance of DeferredPromise.
242
- */
243
- constructor();
244
- /**
245
- * Attaches callbacks for the resolution and/or rejection of the promise.
246
- *
247
- * @param onFulfilled - The callback to execute when the promise is resolved.
248
- * @param onRejected - The callback to execute when the promise is rejected.
249
- * @returns - A new promise resolved or rejected by the onFulfilled or
250
- * onRejected callback.
251
- */
252
- then<TResult1 = T, TResult2 = never>(onFulfilled?: (value: T) => PromiseLike<TResult1> | TResult1, onRejected?: (reason: any) => PromiseLike<TResult2> | TResult2): Promise<TResult1 | TResult2>;
253
- /**
254
- * Attaches a callback for the rejection of the promise.
255
- *
256
- * @param onRejected - The callback to execute when the promise is rejected.
257
- * @returns - A new promise resolved by the onRejected callback.
258
- */
259
- catch<TResult2 = never>(onRejected: (reason: any) => PromiseLike<TResult2> | TResult2): Promise<T | TResult2>;
260
- /**
261
- * Attaches a callback that is executed when the promise is settled, whether
262
- * fulfilled or rejected.
263
- *
264
- * @param onFinally - The callback to execute when the promise is settled.
265
- * @returns - A new promise resolved by the onFinally callback.
266
- */
267
- finally(onFinally?: (() => void) | null): Promise<T>;
268
- }
269
-
270
- /**
271
- * Ensures a sidebar host container exists and default shell styles are applied.
272
- * Host apps can use an almost empty HTML document and call this from their entry script
273
- * (Google Workspace, Figma plugin UI, etc.).
274
- */
275
- export declare function ensureSidebarHostShell(options?: EnsureSidebarHostShellOptions): HTMLElement;
276
-
277
- export declare type EnsureSidebarHostShellOptions = {
278
- /** Host element for the container; defaults to `document`. */
279
- root?: Document | HTMLElement;
280
- /** Container element id. Defaults to {@link SIDEBAR_HOST_CONTAINER_ID}. */
281
- containerId?: string;
282
- /** Inject {@link SIDEBAR_HOST_SHELL_CSS} once. Default `true`. */
283
- includeDefaultStyles?: boolean;
284
- };
285
-
286
- /**
287
- * Message sent when an error occurs during call handling
288
- */
289
- export declare type ErrorMessage = MessageBase & {
290
- type: "error";
291
- errorJSON: string;
292
- };
293
-
294
- export declare type ErrorReconstructor = (message: string, parsed: SerializedError) => Error;
295
-
296
- /**
297
- * Resolves the sidebar base URL: reads {@link SIDEBAR_URL_OVERRIDE_STORAGE_KEY} from `localStorage`
298
- * when present (trimmed), otherwise returns `defaultUrl`. Safe when `localStorage` is unavailable or throws.
299
- */
300
- export declare function getSidebarBaseUrlWithOverride(defaultUrl: string): string;
301
-
302
- /**
303
- * Configuration for IPC system
304
- */
305
- export declare interface IPCConfig {
306
- /**
307
- * Timeout in milliseconds for waiting for a response
308
- * @default 10000 (10 seconds)
309
- */
310
- timeout?: number;
311
- }
312
-
313
- /**
314
- * Core IPC system managing bidirectional communication
315
- */
316
- export declare class IPCCore {
317
- private promisesByID;
318
- private receiversByName;
319
- private currentID;
320
- private config;
321
- private readonly postMessage;
322
- constructor(postMessage: (message: IPCMessage) => void, config?: IPCConfig);
323
- /**
324
- * Update IPC configuration
325
- */
326
- configure(config: IPCConfig): void;
327
- /**
328
- * Makes a call to the other side. Returns a promise that resolves when
329
- * the other side responds.
330
- *
331
- * @param name - The name of the receiver on the other side
332
- * @param data - Parameters to send to the receiver
333
- * @returns Promise that resolves with the receiver's response
334
- */
335
- call<T extends keyof CallSignatures>(name: T, ...data: Parameters<NonNullable<CallSignatures[T]>>): Promise<ReturnType<NonNullable<CallSignatures[T]>>>;
336
- /**
337
- * Makes a call with per-call overrides (e.g. timeout).
338
- *
339
- * @param name - The name of the receiver on the other side
340
- * @param options - Per-call overrides (e.g. timeout in ms)
341
- * @param data - Parameters to send to the receiver
342
- * @returns Promise that resolves with the receiver's response
343
- */
344
- callWithOptions<T extends keyof CallSignatures>(name: T, options: CallOptions, ...data: Parameters<NonNullable<CallSignatures[T]>>): Promise<ReturnType<NonNullable<CallSignatures[T]>>>;
345
- /**
346
- * Registers a function to receive calls with a particular name.
347
- * The return value will be sent back to the caller.
348
- *
349
- * @param name - The name of the receiver
350
- * @param fn - The function that will receive calls
351
- */
352
- receive<R extends keyof CallSignatures>(name: R, fn: ReceiverFn<R>): void;
353
- /**
354
- * Unregisters a receiver for a given call name
355
- *
356
- * @param name - The name of the receiver to unregister
357
- */
358
- ignore(name: string): void;
359
- /**
360
- * Handles incoming messages from the other side
361
- * @param message - The IPC message to handle
362
- */
363
- handleMessage(message: IPCMessage): Promise<void>;
364
- /**
365
- * Handles incoming call messages
366
- */
367
- private handleCall;
368
- /**
369
- * Handles incoming response messages
370
- */
371
- private handleResponse;
372
- /**
373
- * Handles incoming error messages
374
- */
375
- private handleError;
376
- /**
377
- * Cleanup all pending promises and receivers
378
- */
379
- destroy(): void;
380
- }
381
-
382
- /**
383
- * Registry of known error names to reconstructors. Add entries here when introducing
384
- * new error types that should be reconstructed on the receiving side (e.g. for instanceof).
385
- */
386
- export declare const ipcErrorReconstructors: Record<string, ErrorReconstructor>;
387
-
388
- /**
389
- * Union of all possible message types
390
- */
391
- export declare type IPCMessage = CallMessage | ResponseMessage | ErrorMessage;
392
-
393
- /**
394
- * Type guard for TextLookupError. Use when catching errors from adapter methods
395
- * (e.g. selectContent, replaceContent) to narrow the type and handle text
396
- * lookup failures specifically.
397
- */
398
- export declare function isTextLookupError(error: unknown): error is TextLookupError;
399
-
400
- /**
401
- * Base message structure for IPC communication
402
- */
403
- export declare type MessageBase = {
404
- type: "call" | "response" | "error";
405
- id: number;
406
- name: string;
407
- };
408
-
409
- /**
410
- * Common MIME type constants for text content
411
- * Integrations are not limited to these values - any valid MIME type string can be used
412
- * Note: The sidebar currently only supports text-based content analysis
413
- */
414
- declare enum MimeType_2 {
415
- TEXT_PLAIN = "text/plain",
416
- TEXT_MARKDOWN = "text/markdown",
417
- TEXT_HTML = "text/html",
418
- APPLICATION_DITA_XML = "application/dita+xml"
419
- }
420
- export { MimeType_2 as MimeType }
421
-
422
- /**
423
- * PluginAdapter - Use in the Sidebar to communicate with the Plugin in the editor
424
- * This is a wrapper around PluginIPCAdapter for backwards compatibility and ease of use
425
- *
426
- * @param sidebar - Optional SidebarInterface implementation for Plugin → Sidebar callbacks
427
- * @param config - Optional IPC configuration
428
- * @param targetOrigin - Optional target origin for postMessage (defaults to '*')
429
- */
430
- export declare class PluginAdapter {
431
- private readonly ipcAdapter;
432
- constructor(sidebar?: SidebarInterface, config?: IPCConfig, targetOrigin?: string);
433
- /**
434
- * Cleanup and destroy the adapter
435
- */
436
- destroy(): void;
437
- /**
438
- * Request initialization configuration from the editor
439
- */
440
- getInitConfig(): Promise<SidebarConfig>;
441
- /**
442
- * Request content from the editor in whatever format the integration supports
443
- * @param options - Optional per-call overrides (e.g. timeout in ms; overrides default IPC timeout)
444
- */
445
- getContent(options?: CallOptions): Promise<ContentInfo>;
446
- /**
447
- * Request selected content from the editor in whatever format the integration supports
448
- * @param options - Optional per-call overrides (e.g. timeout in ms; overrides default IPC timeout)
449
- */
450
- getSelectedContent(options?: CallOptions): Promise<ContentInfo>;
451
- /**
452
- * Replace content in the editor
453
- */
454
- replaceContent(original: string, suggestion: string, range?: ContentRange): Promise<void>;
455
- /**
456
- * Select content in the editor
457
- */
458
- selectContent(original: string, startIndex: number): Promise<void>;
459
- /**
460
- * Show a dialog in the editor
461
- */
462
- showDialog(dialogHtml: string, width?: number, height?: number, title?: string): Promise<void>;
463
- /**
464
- * Close the dialog in the editor
465
- */
466
- closeDialog(): Promise<void>;
467
- /**
468
- * Replace multiple contents in the editor
469
- */
470
- replaceMultipleContents(replacements: ContentReplacement[]): Promise<void>;
471
- /**
472
- * Notify plugin that one agent's results are available (streaming).
473
- */
474
- onAgenticAgentResults(agentName: string, issues: AgenticIssuePayload[]): Promise<void>;
475
- /**
476
- * Notify plugin that the agentic stream has finished.
477
- */
478
- onAgenticStreamComplete(): Promise<void>;
479
- /**
480
- * Update IPC configuration
481
- */
482
- configure(config: IPCConfig): void;
483
- /**
484
- * Set or update the target origin for postMessage communication
485
- */
486
- setTargetOrigin(targetOrigin: string): void;
487
- /**
488
- * Get the current target origin
489
- */
490
- getTargetOrigin(): string;
491
- }
492
-
493
- /**
494
- * Interface for the functions to implement in the Editor that the Sidebar will call via IPC
495
- * All methods return Promises for proper async handling
496
- */
497
- export declare interface PluginInterface {
498
- /**
499
- * Get content from the editor in whatever format the integration supports
500
- * The integration must provide content and documentReference; mimeType is optional
501
- * @returns Promise that resolves with content info including documentReference and optional mimeType
502
- */
503
- getContent: () => Promise<ContentInfo>;
504
- /**
505
- * Get selected content from the editor in whatever format the integration supports
506
- * The integration must provide content and documentReference; mimeType is optional
507
- * @returns Promise that resolves with content info including documentReference and optional mimeType
508
- */
509
- getSelectedContent: () => Promise<ContentInfo>;
510
- /**
511
- * Replace content in the editor
512
- * @param original - The original text to replace
513
- * @param suggestion - The suggested replacement text
514
- * @param range - Optional range specifying where to replace
515
- * @returns Promise that resolves when replacement is complete
516
- * @throws {TextLookupError} When the requested text cannot be found or located (see ReplaceContentError)
517
- */
518
- replaceContent: (original: string, suggestion: string, range?: ContentRange) => Promise<void>;
519
- /**
520
- * Select content in the editor
521
- * @param original - The original text to select
522
- * @param startIndex - The start index of the selection
523
- * @returns Promise that resolves when selection is complete
524
- * @throws {TextLookupError} When the requested text cannot be found or located (see SelectContentError)
525
- */
526
- selectContent: (original: string, startIndex: number) => Promise<void>;
527
- /**
528
- * Show a dialog in the editor
529
- * @param dialogHtml - The HTML content of the dialog
530
- * @param width - Optional dialog width
531
- * @param height - Optional dialog height
532
- * @param title - Optional dialog title
533
- * @returns Promise that resolves when dialog is shown
534
- */
535
- showDialog: (dialogHtml: string, width?: number, height?: number, title?: string) => Promise<void>;
536
- /**
537
- * Close the dialog in the editor
538
- * @returns Promise that resolves when dialog is closed
539
- */
540
- closeDialog: () => Promise<void>;
541
- /**
542
- * Replace multiple contents in the editor
543
- * @param replacements - Array of content replacements to apply
544
- * @returns Promise that resolves when all replacements are complete
545
- */
546
- replaceMultipleContents: (replacements: ContentReplacement[]) => Promise<void>;
547
- /**
548
- * Get initialization configuration from the editor
549
- * Called by the sidebar when it's ready to initialize
550
- * @returns Promise that resolves with the sidebar configuration
551
- */
552
- getInitConfig: () => Promise<SidebarConfig>;
553
- /**
554
- * Called when one agent's results are available during agentic streaming.
555
- * Enables the plugin to render underlines or update UI per agent as results arrive.
556
- */
557
- onAgenticAgentResults?: (agentName: string, issues: AgenticIssuePayload[]) => Promise<void>;
558
- /**
559
- * Called when the agentic stream has finished (all agents done or completion/error event).
560
- */
561
- onAgenticStreamComplete?: () => Promise<void>;
562
- }
563
-
564
- /**
565
- * PluginIPCAdapter - Used in the Sidebar to communicate with the Plugin in the editor
566
- * Provides async methods to call plugin functions
567
- *
568
- * Primarily uses PULL pattern where Sidebar initiates calls.
569
- * Optional SidebarInterface parameter allows Plugin → Sidebar callbacks if needed.
570
- */
571
- export declare class PluginIPCAdapter {
572
- private readonly ipc;
573
- private readonly sidebar;
574
- private targetOrigin;
575
- constructor(sidebar?: SidebarInterface, config?: IPCConfig, targetOrigin?: string);
576
- private readonly handleMessage;
577
- private registerReceivers;
578
- /**
579
- * Request initialization configuration from the editor
580
- */
581
- getInitConfig(): Promise<SidebarConfig>;
582
- /**
583
- * Request content from the editor in whatever format the integration supports
584
- * @param options - Optional per-call overrides (e.g. timeout in ms; overrides default IPC timeout)
585
- */
586
- getContent(options?: CallOptions): Promise<ContentInfo>;
587
- /**
588
- * Request selected content from the editor in whatever format the integration supports
589
- * @param options - Optional per-call overrides (e.g. timeout in ms; overrides default IPC timeout)
590
- */
591
- getSelectedContent(options?: CallOptions): Promise<ContentInfo>;
592
- /**
593
- * Replace content in the editor
594
- */
595
- replaceContent(original: string, suggestion: string, range?: ContentRange): Promise<void>;
596
- /**
597
- * Select content in the editor
598
- */
599
- selectContent(original: string, startIndex: number): Promise<void>;
600
- /**
601
- * Show a dialog in the editor
602
- */
603
- showDialog(dialogHtml: string, width?: number, height?: number, title?: string): Promise<void>;
604
- /**
605
- * Close the dialog in the editor
606
- */
607
- closeDialog(): Promise<void>;
608
- /**
609
- * Replace multiple contents in the editor
610
- */
611
- replaceMultipleContents(replacements: ContentReplacement[]): Promise<void>;
612
- /**
613
- * Notify plugin that one agent's results are available (streaming).
614
- */
615
- onAgenticAgentResults(agentName: string, issues: AgenticIssuePayload[]): Promise<void>;
616
- /**
617
- * Notify plugin that the agentic stream has finished.
618
- */
619
- onAgenticStreamComplete(): Promise<void>;
620
- /**
621
- * Update IPC configuration
622
- */
623
- configure(config: IPCConfig): void;
624
- /**
625
- * Set or update the target origin for postMessage communication
626
- */
627
- setTargetOrigin(targetOrigin: string): void;
628
- /**
629
- * Get the current target origin
630
- */
631
- getTargetOrigin(): string;
632
- /**
633
- * Cleanup and destroy the adapter
634
- */
635
- destroy(): void;
636
- }
637
-
638
- export declare type ReceiverFn<R extends keyof CallSignatures> = (...data: Parameters<NonNullable<CallSignatures[R]>>) => ReturnType<NonNullable<CallSignatures[R]>>;
639
-
640
- /**
641
- * Reconstructs an Error from IPC-serialized payload. Uses ipcErrorReconstructors
642
- * when name is known; otherwise returns a plain Error with the message.
643
- */
644
- export declare function reconstructError(parsed: SerializedError): Error;
645
-
646
- /**
647
- * Union of errors that replaceContent may throw. Use for control-flow typing when
648
- * catching. Extend when adding new known errors for replaceContent.
649
- */
650
- export declare type ReplaceContentError = TextLookupError;
651
-
652
- /**
653
- * Message sent when responding to a call
654
- */
655
- export declare type ResponseMessage = MessageBase & {
656
- type: "response";
657
- data: any;
658
- };
659
-
660
- /**
661
- * Union of errors that selectContent may throw. Use for control-flow typing when
662
- * catching (e.g. narrow with isTextLookupError).
663
- */
664
- export declare type SelectContentError = TextLookupError;
665
-
666
- /**
667
- * Serialized shape of an error sent over IPC (name + message; extend for custom payloads).
668
- */
669
- export declare interface SerializedError {
670
- name?: string;
671
- message?: string;
672
- [key: string]: unknown;
673
- }
674
-
675
- export declare const setupSidebarLoadOverlay: (container: HTMLElement, iframe: HTMLIFrameElement, options?: SidebarLoadOverlayOptions) => () => void;
676
-
677
- /**
678
- * Canonical production sidebar app base URL (trailing slash).
679
- * Use as {@link getSidebarBaseUrlWithOverride}'s `defaultUrl` when no build-time env override is set.
680
- */
681
- export declare const SIDEBAR_DEFAULT_PRODUCTION_BASE_URL: "https://sidebar.markup.ai/";
682
-
683
- /** Default `id` of the element {@link ensureSidebarHostShell} creates or looks up. */
684
- export declare const SIDEBAR_HOST_CONTAINER_ID = "sidebarContainer";
685
-
686
- /** Default shell CSS for {@link SIDEBAR_HOST_CONTAINER_ID}. */
687
- export declare const SIDEBAR_HOST_SHELL_CSS: string;
688
-
689
- /** Default `iframe.allow` so the embedded sidebar can use the clipboard (Permissions Policy). */
690
- export declare const SIDEBAR_IFRAME_DEFAULT_ALLOW = "clipboard-read; clipboard-write";
691
-
692
- /** Fixed `iframe.title` for accessibility on adapter-created sidebars. */
693
- export declare const SIDEBAR_IFRAME_DEFAULT_TITLE = "Markup AI Sidebar";
694
-
695
- /**
696
- * Shared `localStorage` key integrations may read to override the sidebar base URL (e.g. local dev).
697
- * Used by {@link getSidebarBaseUrlWithOverride}, Google Workspace, and Figma plugin UI.
698
- */
699
- export declare const SIDEBAR_URL_OVERRIDE_STORAGE_KEY = "markupai.sidebarNextGen.overrideUrl";
700
-
701
- /**
702
- * SidebarAdapter - Use in the Editor to communicate with the Sidebar in the iframe
703
- * This is a wrapper around SidebarIPCAdapter for backwards compatibility and ease of use
704
- */
705
- export declare class SidebarAdapter {
706
- private readonly ipcAdapter;
707
- constructor(plugin: PluginInterface, iframe: HTMLIFrameElement, options?: SidebarAdapterOptions);
708
- /**
709
- * Cleanup and destroy the adapter
710
- */
711
- destroy(): void;
712
- /**
713
- * Notify sidebar of plugin status changes
714
- * Example method demonstrating Plugin → Sidebar communication
715
- */
716
- notifyPluginStatus(status: string): Promise<void>;
717
- /**
718
- * Request sidebar to activate (expand and scroll to) the card for the given issue.
719
- */
720
- activateAgenticIssue(issueId: string): Promise<void>;
721
- /**
722
- * Update IPC configuration
723
- */
724
- configure(config: IPCConfig): void;
725
- }
726
-
727
- /**
728
- * Options for SidebarAdapter constructor
729
- */
730
- export declare interface SidebarAdapterOptions {
731
- /** Optional window object (defaults to globalThis.window) */
732
- win?: Window;
733
- /** Optional IPC configuration */
734
- config?: IPCConfig;
735
- /** Optional target origin for postMessage (defaults to '*') */
736
- targetOrigin?: string;
737
- }
738
-
739
- /**
740
- * Configuration for the sidebar
741
- */
742
- export declare interface SidebarConfig {
743
- integrationName: string;
744
- integrationVersion: string;
745
- integrationId?: string;
746
- hideBanner?: boolean;
747
- dialogClosingScript?: string;
748
- /**
749
- * Origin of the plugin/editor window where messages should be sent
750
- * This is the origin where the plugin is listening for messages from the sidebar
751
- */
752
- pluginOrigin?: string;
753
- /**
754
- * Whether to use the check preview workflow dialog
755
- * If true, the sidebar will show a check preview dialog where the user can apply issues to the content
756
- * If false, the sidebar will not show a dialog, but there will be an issue tab on the sidebar from where the user can apply issues
757
- */
758
- useCheckPreviewDialog: boolean;
759
- /**
760
- * Whether to support selection-based check and rewrite functionality
761
- * If true or undefined (default), the selection toggle UI will be shown and users can toggle between full content and selection modes
762
- * If false, the selection toggle UI will be hidden and checkSelectionEnabled will be forced to false
763
- */
764
- supportCheckSelection?: boolean;
765
- }
766
-
767
- /** Return type when `plugin` is provided or omitted. */
768
- export declare type SidebarHost = SidebarHostWithAdapter | SidebarShellHost;
769
-
770
- export declare type SidebarHostWithAdapter = {
771
- iframe: HTMLIFrameElement;
772
- adapter: SidebarAdapter;
773
- destroy: () => void;
774
- };
775
-
776
- /**
777
- * Interface for functions to implement in the Sidebar that the Plugin can call via IPC
778
- *
779
- * Currently using PULL pattern where Sidebar initiates all communication.
780
- * This interface is provided for future extensibility when Plugin → Sidebar calls are needed.
781
- */
782
- export declare interface SidebarInterface {
783
- /**
784
- * Example method: Called when plugin status changes (e.g., initialization complete)
785
- * This serves as a template for adding future Plugin → Sidebar communication
786
- *
787
- * @param status - Status message from the plugin
788
- * @returns Promise that resolves when the sidebar has processed the status
789
- *
790
- * @example
791
- * // In Plugin implementation:
792
- * onPluginStatusChange: async (status: string) => {
793
- * console.log('Plugin status:', status);
794
- * }
795
- *
796
- * // Sidebar can implement:
797
- * const sidebarInterface: SidebarInterface = {
798
- * onPluginStatusChange: async (status) => {
799
- * console.log('Sidebar received status:', status);
800
- * // Update UI, show notification, etc.
801
- * }
802
- * };
803
- */
804
- onPluginStatusChange?: (status: string) => Promise<void>;
805
- /**
806
- * Request the sidebar to activate (expand and scroll to) the card for the given issue.
807
- * Used when the user clicks an underline in the document so the sidebar focuses that issue.
808
- */
809
- activateAgenticIssue?: (issueId: string) => Promise<void>;
810
- }
811
-
812
- /**
813
- * SidebarIPCAdapter - Used in the Plugin to communicate with the Sidebar in the iframe
814
- * Provides async methods to call sidebar functions and registers receivers for plugin functions
815
- */
816
- export declare class SidebarIPCAdapter {
817
- private readonly ipc;
818
- private readonly plugin;
819
- private readonly iframe;
820
- private readonly window;
821
- private readonly targetOrigin;
822
- constructor(plugin: PluginInterface, iframe: HTMLIFrameElement, win?: Window, config?: IPCConfig, targetOrigin?: string);
823
- private readonly handleMessage;
824
- private registerReceivers;
825
- /**
826
- * Request sidebar to activate (expand and scroll to) the card for the given issue.
827
- */
828
- activateAgenticIssue(issueId: string): Promise<void>;
829
- /**
830
- * Notify sidebar of plugin status changes
831
- * Example method demonstrating Plugin → Sidebar communication
832
- */
833
- notifyPluginStatus(status: string): Promise<void>;
834
- /**
835
- * Update IPC configuration
836
- */
837
- configure(config: IPCConfig): void;
838
- /**
839
- * Cleanup and destroy the adapter
840
- */
841
- destroy(): void;
842
- }
843
-
844
- export declare type SidebarLoadOverlayOptions = {
845
- sidebarUrl?: string;
846
- targetOrigin?: string;
847
- timeoutMs?: number;
848
- retryIntervalMs?: number;
849
- };
850
-
851
- /**
852
- * Origin for {@link SidebarAdapterOptions.targetOrigin} / `postMessage` to the sidebar iframe,
853
- * derived from the sidebar URL (hash routes are ignored by `URL#origin`). Returns `"*"` if parsing fails.
854
- */
855
- export declare function sidebarPostMessageTargetOrigin(sidebarUrl: string, options?: SidebarPostMessageTargetOriginOptions): string;
856
-
857
- export declare type SidebarPostMessageTargetOriginOptions = {
858
- /** Invoked when `sidebarUrl` is not a valid URL; the return value falls back to `"*"`. */
859
- onInvalidUrl?: (sidebarUrl: string, error: unknown) => void;
860
- };
861
-
862
- export declare type SidebarShellHost = {
863
- iframe: HTMLIFrameElement;
864
- adapter: null;
865
- destroy: () => void;
866
- };
867
-
868
- /**
869
- * Array of common text MIME types
870
- * This is a convenience constant for reference - integrations can use any MIME type
871
- * The sidebar accepts any MIME type string and passes it through to the API
872
- */
873
- export declare const TEXT_MIME_TYPES: readonly [MimeType_2.TEXT_PLAIN, MimeType_2.TEXT_MARKDOWN, MimeType_2.TEXT_HTML, MimeType_2.APPLICATION_DITA_XML];
874
-
875
- /**
876
- * Error thrown by integration/plugin code when text lookup (e.g. selection or
877
- * positioning) fails. The sidebar treats this as a selection failure and can
878
- * invalidate the issue card with the error message.
879
- *
880
- * Plugin developers should throw this from selectContent (and optionally
881
- * replaceContent) when the requested text cannot be found or located.
882
- */
883
- export declare class TextLookupError extends Error {
884
- readonly name = "TextLookupError";
885
- constructor(message: string);
886
- }
887
-
888
- export { }