@markupai/sidebar-adapter 1.3.1 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -16
- package/asyncapi.json +1912 -0
- package/dist/adapters/pluginAdapter.d.ts +7 -0
- package/dist/adapters/pluginAdapter.d.ts.map +1 -1
- package/dist/ipc/call-signatures.d.ts +5 -0
- package/dist/ipc/call-signatures.d.ts.map +1 -1
- package/dist/ipc/deferred-promise.d.ts +14 -29
- package/dist/ipc/deferred-promise.d.ts.map +1 -1
- package/dist/ipc/ipc-core.d.ts.map +1 -1
- package/dist/ipc/plugin-ipc-adapter.d.ts +6 -0
- package/dist/ipc/plugin-ipc-adapter.d.ts.map +1 -1
- package/dist/ipc/sidebar-ipc-adapter.d.ts.map +1 -1
- package/dist/main.js +164 -155
- package/dist/main.umd.cjs +6 -6
- package/dist/types/common.d.ts +60 -7
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/integrationSettings.d.ts +9 -4
- package/dist/types/integrationSettings.d.ts.map +1 -1
- package/dist/types/pluginInterface.d.ts +31 -4
- package/dist/types/pluginInterface.d.ts.map +1 -1
- package/package.json +14 -6
package/README.md
CHANGED
|
@@ -44,7 +44,13 @@ Use this if you are **embedding Markup AI’s sidebar** in your product for the
|
|
|
44
44
|
5. **Test the basics** — After load, the sidebar will request **`getInitConfig`** and **`getContent`**. Confirm your app returns sensible values before testing edits and dialogs.
|
|
45
45
|
6. **Tear down on exit** — Call **`destroy()`** on the host returned by `createSidebarHost`, or on your `SidebarAdapter`, when the user leaves the screen or you remove the iframe.
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
The sidebar runs the **agentic** experience. Its optional `PluginInterface` hooks and `SidebarInterface` RPCs let a host mirror the sidebar's issues in its own UI — useful for tracking issues and for context-menu flows such as applying a suggestion inline or activating an issue's card:
|
|
48
|
+
|
|
49
|
+
- **Receive streaming results** — implement **`onAgenticAgentResults`** and **`onAgenticStreamComplete`** to get issues (each with its suggestions) as they stream plus a completion signal, so you can draw your own underlines or build a context menu (see [PluginInterface](#plugininterface)).
|
|
50
|
+
- **Track issue state** — implement **`onAgenticIssueStatusChanged`**; the sidebar emits it after every Open / Resolved / Dismissed transition so you can keep annotations or other host UI in sync.
|
|
51
|
+
- **Drive the sidebar** — call **`activateAgenticIssue`** to expand and scroll to a card (e.g. when the user clicks an underline or picks the issue from a context menu), and **`markAgenticIssueResolved`** / **`restoreAgenticIssue`** / **`invalidateAgenticIssue`** to resolve / restore / dismiss a card — for example after applying a suggestion inline from your own context menu.
|
|
52
|
+
|
|
53
|
+
See [Agentic issue lifecycle](#agentic-issue-lifecycle).
|
|
48
54
|
|
|
49
55
|
## How the pieces fit together
|
|
50
56
|
|
|
@@ -72,15 +78,6 @@ If you use the **agentic** layout, implement the optional hooks **`onAgenticAgen
|
|
|
72
78
|
npm install @markupai/sidebar-adapter
|
|
73
79
|
```
|
|
74
80
|
|
|
75
|
-
### Upgrading from 0.x to 1.x
|
|
76
|
-
|
|
77
|
-
These releases introduce **breaking** IPC and TypeScript contract updates:
|
|
78
|
-
|
|
79
|
-
- **`selectContent`** is `selectContent(range: ContentRange)` with a **required** **`ContentRange`** and highlights the half-open document span **`[range.start, range.end)`** using offsets only (no separate `original` string on the contract).
|
|
80
|
-
- **`replaceContent`** is `replaceContent(suggestion, range)` with a **required** **`ContentRange`** (`[range.start, range.end)` half-open semantics).
|
|
81
|
-
- **`ContentReplacement`** batch entries are **`{ suggestion, range }`** only (no `original` field).
|
|
82
|
-
- Update every **`PluginInterface`** implementation and any code that decodes **`selectContent`** / **`replaceContent`** IPC payloads so they match the published shapes: **`selectContent`** is one argument **`[range]`** on the wire; **`replaceContent`** is **`[suggestion, range]`** (argument order matters).
|
|
83
|
-
|
|
84
81
|
## Architecture options
|
|
85
82
|
|
|
86
83
|
| Integration style | Where the sidebar iframe runs | Where your document/editor code runs | Typical approach |
|
|
@@ -213,13 +210,13 @@ const pluginInterface: PluginInterface = {
|
|
|
213
210
|
replaceMultipleContentsInEditor(replacements);
|
|
214
211
|
},
|
|
215
212
|
|
|
216
|
-
// Show a dialog
|
|
213
|
+
// Show a dialog (optional — omit on hosts without dialog support)
|
|
217
214
|
showDialog: async (dialogHtml: string, width?: number, height?: number, title?: string) => {
|
|
218
215
|
console.log("Show dialog:", title);
|
|
219
216
|
showDialogInEditor(dialogHtml, width, height, title);
|
|
220
217
|
},
|
|
221
218
|
|
|
222
|
-
// Close the dialog
|
|
219
|
+
// Close the dialog (optional — omit on hosts without dialog support)
|
|
223
220
|
closeDialog: async () => {
|
|
224
221
|
console.log("Close dialog");
|
|
225
222
|
closeDialogInEditor();
|
|
@@ -237,6 +234,11 @@ const sidebarAdapter = new SidebarAdapter(pluginInterface, iframe);
|
|
|
237
234
|
sidebarAdapter.destroy();
|
|
238
235
|
```
|
|
239
236
|
|
|
237
|
+
> **`integrationName` vs `integrationId`** — two distinct concerns:
|
|
238
|
+
>
|
|
239
|
+
> - **`integrationName`** (required) is the **human-readable** name of the integration, **display only** (e.g. shown on the sidebar's About page). Example: `"Madcap Flare Desktop"`. Never derive a machine identifier from it.
|
|
240
|
+
> - **`integrationId`** (optional) is the **stable, machine-readable slug** (lowercase, hyphenated, no spaces) used for everything non-display: the Auth0 mediation login provider, PostHog analytics keys, the `x-integration-id` API header, and per-integration settings storage. Example: `"madcap-flare-desktop"`. Keep it stable across releases. When omitted it falls back to `DEFAULT_SIDEBAR_CONFIG.integrationId` (`"markupai-sidebar-app"`); mediation-login hosts **must** set it to match their Auth0 relay connection name (e.g. Figma → `"figma"`), since the sidebar feeds it straight to the login provider.
|
|
241
|
+
|
|
240
242
|
### SidebarLoadOverlay (Editor UI)
|
|
241
243
|
|
|
242
244
|
Use `setupSidebarLoadOverlay` when you manage the iframe yourself and only want the **failed-to-load / retry** UI. Overlay styles are injected into **`container.ownerDocument`** (usually the same as the global `document` when the container lives in your host page). That keeps styles aligned with the document that actually contains the overlay—important if the container is in another **window** (e.g. undocked popup) or **frame**.
|
|
@@ -339,6 +341,14 @@ getInitConfig: async () => ({
|
|
|
339
341
|
});
|
|
340
342
|
```
|
|
341
343
|
|
|
344
|
+
For mediation, you may also set **`provider`** — the Auth0 relay-connection slug the sidebar sends to start the OAuth handshake:
|
|
345
|
+
|
|
346
|
+
```typescript
|
|
347
|
+
auth: { type: "mediation", provider: "microsoft-365" }
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
Set `provider` when **one** login provider must serve **several** `integrationId`s — e.g. a single add-in spanning multiple editors that each report a distinct `integrationId` (for analytics / the `x-integration-id` header / settings storage) but share one Auth0 relay connection. When omitted, the sidebar derives the provider from `integrationId`.
|
|
351
|
+
|
|
342
352
|
When **`auth`** is omitted, the sidebar falls back to **legacy heuristic selection** for backwards compatibility.
|
|
343
353
|
|
|
344
354
|
#### openAuthUrl (sandboxed hosts)
|
|
@@ -462,14 +472,14 @@ For agentic streaming callbacks, issue objects match the exported **`AgenticIssu
|
|
|
462
472
|
|
|
463
473
|
Implement these **on the host** as async functions. The sidebar calls them over IPC and waits on the returned promises (pull style):
|
|
464
474
|
|
|
465
|
-
- `getInitConfig(): Promise<SidebarConfig>` — Integration name, version, feature flags, dialog closing script, etc.
|
|
475
|
+
- `getInitConfig(): Promise<SidebarConfig>` — Integration display name (`integrationName`), stable machine id (`integrationId`), version, feature flags, dialog closing script, etc. See the `integrationName` vs `integrationId` note above.
|
|
466
476
|
- `getContent(): Promise<ContentInfo>` — Full document (or main buffer) text; must include `documentReference`; `mimeType` optional
|
|
467
477
|
- `getSelectedContent(): Promise<ContentInfo>` — Current selection; same `ContentInfo` rules as `getContent`
|
|
468
478
|
- `selectContent(range: ContentRange): Promise<void>` — Focus/highlight the document span `[range.start, range.end)`
|
|
469
479
|
- `replaceContent(suggestion: string, range: ContentRange): Promise<void>` — Apply a single edit to `[range.start, range.end)`
|
|
470
480
|
- `replaceMultipleContents(replacements: ContentReplacement[]): Promise<void>` — Batch edits
|
|
471
|
-
- `showDialog(dialogHtml: string, width?: number, height?: number, title?: string): Promise<void>` — Host-rendered dialog chrome around HTML from the sidebar
|
|
472
|
-
- `closeDialog(): Promise<void>` — Dismiss that dialog
|
|
481
|
+
- `showDialog?(dialogHtml: string, width?: number, height?: number, title?: string): Promise<void>` — Host-rendered dialog chrome around HTML from the sidebar. **Optional** — omit on hosts without dialog support (also leave `useCheckPreviewDialog: false`).
|
|
482
|
+
- `closeDialog?(): Promise<void>` — Dismiss that dialog. **Optional**, pairs with `showDialog`.
|
|
473
483
|
|
|
474
484
|
Optional (agentic / streaming flows):
|
|
475
485
|
|
|
@@ -481,6 +491,10 @@ Optional (authentication):
|
|
|
481
491
|
|
|
482
492
|
- `openAuthUrl?(url: string): Promise<void>` — Open the Auth0 `authorizeUrl` in whatever external-browser primitive the host provides. Implement this in sandboxed hosts where `globalThis.open` is blocked or unavailable (e.g. Office task panes should call `Office.context.ui.openBrowserWindow(url)`). Throw if the window cannot be opened so the mediation flow fails fast instead of polling to timeout. When omitted, the sidebar falls back to `globalThis.open(url, "_blank", "noopener,noreferrer")`.
|
|
483
493
|
|
|
494
|
+
Optional (clipboard):
|
|
495
|
+
|
|
496
|
+
- `copyToClipboard?(text: string): Promise<void>` — Write text to the system clipboard on the sidebar's behalf. Implement this in hosts where the sidebar iframe cannot use the async clipboard API itself — notably VS Code webviews, whose Electron permission handler denies `clipboard-write` to any frame that is not on the `vscode-webview://` origin (the VS Code extension calls `vscode.env.clipboard.writeText(text)` in the extension host). Reject to signal the write failed. When omitted, the sidebar detects the absence via the standard `"No receiver registered for: copyToClipboard"` IPC error and falls back to `navigator.clipboard.writeText`, then `document.execCommand("copy")`.
|
|
497
|
+
|
|
484
498
|
#### Error control flows
|
|
485
499
|
|
|
486
500
|
When implementing `selectContent` or `replaceContent`, throw `TextLookupError` from this package when text lookup (e.g. locating the selection or target range) fails. The sidebar will treat it as a selection failure and can invalidate the issue card with the error message.
|
|
@@ -650,7 +664,7 @@ This is **opt-in and additive**. Hosts that omit `integrationSettings` from thei
|
|
|
650
664
|
import type { SidebarConfig } from "@markupai/sidebar-adapter";
|
|
651
665
|
|
|
652
666
|
const config: SidebarConfig = {
|
|
653
|
-
integrationName: "
|
|
667
|
+
integrationName: "My Integration",
|
|
654
668
|
integrationVersion: "1.0.0",
|
|
655
669
|
integrationId: "my-integration",
|
|
656
670
|
useCheckPreviewDialog: false,
|
|
@@ -776,3 +790,23 @@ npm run test:coverage
|
|
|
776
790
|
npm run format:fix
|
|
777
791
|
npm run format:check
|
|
778
792
|
```
|
|
793
|
+
|
|
794
|
+
## IPC contract (AsyncAPI)
|
|
795
|
+
|
|
796
|
+
The sidebar↔host IPC protocol is published as a machine-readable **AsyncAPI 3.0**
|
|
797
|
+
document, generated from this package's TypeScript types. Other-language ports
|
|
798
|
+
(e.g. a C# host embedding the sidebar) use it for codegen and contract testing.
|
|
799
|
+
|
|
800
|
+
**Get it three ways:**
|
|
801
|
+
|
|
802
|
+
- **npm resource** — it ships in the tarball: `@markupai/sidebar-adapter/asyncapi.json`.
|
|
803
|
+
- **`require.resolve`** — `require.resolve("@markupai/sidebar-adapter/asyncapi.json")`.
|
|
804
|
+
- **Served URL** — per environment, e.g. `https://sidebar.dev.markup.ai/asyncapi.json`
|
|
805
|
+
(also `sidebar.stg.markup.ai`, `sidebar.markup.ai`), with permissive CORS.
|
|
806
|
+
|
|
807
|
+
`info.version` equals this package's version, so a consumer always knows which
|
|
808
|
+
contract revision it is testing against. The document is **generated — do not
|
|
809
|
+
hand-edit `asyncapi.json`.** Regenerate with `npm run build:contract`.
|
|
810
|
+
|
|
811
|
+
See [`docs/contract/consuming-the-ipc-contract.md`](../../docs/contract/consuming-the-ipc-contract.md)
|
|
812
|
+
for the consumer workflow.
|