@particle-academy/agent-integrations 0.41.0 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/dist/bridges/artboard.d.cts +2 -2
  2. package/dist/bridges/artboard.d.ts +2 -2
  3. package/dist/bridges/catalog.d.cts +2 -2
  4. package/dist/bridges/catalog.d.ts +2 -2
  5. package/dist/bridges/charts.d.cts +2 -2
  6. package/dist/bridges/charts.d.ts +2 -2
  7. package/dist/bridges/cms.d.cts +2 -2
  8. package/dist/bridges/cms.d.ts +2 -2
  9. package/dist/bridges/code.d.cts +2 -2
  10. package/dist/bridges/code.d.ts +2 -2
  11. package/dist/bridges/doc.d.cts +2 -2
  12. package/dist/bridges/doc.d.ts +2 -2
  13. package/dist/bridges/features.d.cts +2 -2
  14. package/dist/bridges/features.d.ts +2 -2
  15. package/dist/bridges/files.d.cts +2 -2
  16. package/dist/bridges/files.d.ts +2 -2
  17. package/dist/bridges/flow.d.cts +2 -2
  18. package/dist/bridges/flow.d.ts +2 -2
  19. package/dist/bridges/forms.d.cts +2 -2
  20. package/dist/bridges/forms.d.ts +2 -2
  21. package/dist/bridges/git.d.cts +2 -2
  22. package/dist/bridges/git.d.ts +2 -2
  23. package/dist/bridges/grid.d.cts +2 -2
  24. package/dist/bridges/grid.d.ts +2 -2
  25. package/dist/bridges/map.d.cts +2 -2
  26. package/dist/bridges/map.d.ts +2 -2
  27. package/dist/bridges/passkeys.d.cts +2 -2
  28. package/dist/bridges/passkeys.d.ts +2 -2
  29. package/dist/bridges/scene.d.cts +2 -2
  30. package/dist/bridges/scene.d.ts +2 -2
  31. package/dist/bridges/screens.d.cts +2 -2
  32. package/dist/bridges/screens.d.ts +2 -2
  33. package/dist/bridges/sheets.d.cts +2 -2
  34. package/dist/bridges/sheets.d.ts +2 -2
  35. package/dist/bridges/slides.d.cts +2 -2
  36. package/dist/bridges/slides.d.ts +2 -2
  37. package/dist/bridges/terminal.d.cts +2 -2
  38. package/dist/bridges/terminal.d.ts +2 -2
  39. package/dist/bridges/tui.d.cts +1 -1
  40. package/dist/bridges/tui.d.ts +1 -1
  41. package/dist/bridges/whiteboard.d.cts +2 -2
  42. package/dist/bridges/whiteboard.d.ts +2 -2
  43. package/dist/bridges-artboard.cjs.map +1 -1
  44. package/dist/bridges-artboard.js +2 -2
  45. package/dist/bridges-catalog.cjs.map +1 -1
  46. package/dist/bridges-catalog.js +3 -3
  47. package/dist/bridges-charts.cjs.map +1 -1
  48. package/dist/bridges-charts.js +3 -3
  49. package/dist/bridges-cms.cjs.map +1 -1
  50. package/dist/bridges-cms.js +4 -4
  51. package/dist/bridges-code.cjs.map +1 -1
  52. package/dist/bridges-code.js +3 -3
  53. package/dist/bridges-doc.cjs.map +1 -1
  54. package/dist/bridges-doc.js +3 -3
  55. package/dist/bridges-features.cjs.map +1 -1
  56. package/dist/bridges-features.js +3 -3
  57. package/dist/bridges-files.cjs.map +1 -1
  58. package/dist/bridges-files.js +3 -3
  59. package/dist/bridges-flow.cjs.map +1 -1
  60. package/dist/bridges-flow.js +2 -2
  61. package/dist/bridges-forms.cjs.map +1 -1
  62. package/dist/bridges-forms.js +3 -3
  63. package/dist/bridges-git.cjs.map +1 -1
  64. package/dist/bridges-git.js +3 -3
  65. package/dist/bridges-grid.cjs.map +1 -1
  66. package/dist/bridges-grid.js +3 -3
  67. package/dist/bridges-map.cjs.map +1 -1
  68. package/dist/bridges-map.js +3 -3
  69. package/dist/bridges-passkeys.cjs.map +1 -1
  70. package/dist/bridges-passkeys.js +3 -3
  71. package/dist/bridges-scene.cjs.map +1 -1
  72. package/dist/bridges-scene.js +3 -3
  73. package/dist/bridges-screens.cjs.map +1 -1
  74. package/dist/bridges-screens.js +3 -3
  75. package/dist/bridges-sheets.cjs.map +1 -1
  76. package/dist/bridges-sheets.js +3 -3
  77. package/dist/bridges-slides.cjs.map +1 -1
  78. package/dist/bridges-slides.js +3 -3
  79. package/dist/bridges-terminal.cjs.map +1 -1
  80. package/dist/bridges-terminal.js +3 -3
  81. package/dist/bridges-tui.cjs.map +1 -1
  82. package/dist/bridges-tui.js +2 -2
  83. package/dist/bridges-whiteboard.cjs.map +1 -1
  84. package/dist/bridges-whiteboard.js +3 -3
  85. package/dist/{chunk-2U5JB6ZA.js → chunk-2LSU3NFO.js} +4 -4
  86. package/dist/{chunk-2U5JB6ZA.js.map → chunk-2LSU3NFO.js.map} +1 -1
  87. package/dist/{chunk-PR4SXFZH.js → chunk-2Q4EGZHJ.js} +4 -4
  88. package/dist/{chunk-PR4SXFZH.js.map → chunk-2Q4EGZHJ.js.map} +1 -1
  89. package/dist/{chunk-G5EZNWXJ.js → chunk-5W6YOXLT.js} +4 -4
  90. package/dist/{chunk-G5EZNWXJ.js.map → chunk-5W6YOXLT.js.map} +1 -1
  91. package/dist/{chunk-CA7GIJJC.js → chunk-7LLMILTM.js} +4 -4
  92. package/dist/{chunk-CA7GIJJC.js.map → chunk-7LLMILTM.js.map} +1 -1
  93. package/dist/{chunk-MFMBR6LN.js → chunk-E2I3YVKC.js} +3 -3
  94. package/dist/{chunk-MFMBR6LN.js.map → chunk-E2I3YVKC.js.map} +1 -1
  95. package/dist/{chunk-USQGA672.js → chunk-EIBV76IB.js} +4 -4
  96. package/dist/{chunk-USQGA672.js.map → chunk-EIBV76IB.js.map} +1 -1
  97. package/dist/{chunk-WCKSDFTM.js → chunk-GT63LSPJ.js} +4 -4
  98. package/dist/{chunk-WCKSDFTM.js.map → chunk-GT63LSPJ.js.map} +1 -1
  99. package/dist/{chunk-CT3LRNH7.js → chunk-HVDHT7DM.js} +3 -3
  100. package/dist/{chunk-CT3LRNH7.js.map → chunk-HVDHT7DM.js.map} +1 -1
  101. package/dist/{chunk-7THGQUX3.js → chunk-LOD77NCD.js} +4 -4
  102. package/dist/{chunk-7THGQUX3.js.map → chunk-LOD77NCD.js.map} +1 -1
  103. package/dist/{chunk-BHQJJ2YG.js → chunk-MZ74LLDS.js} +4 -4
  104. package/dist/{chunk-BHQJJ2YG.js.map → chunk-MZ74LLDS.js.map} +1 -1
  105. package/dist/{chunk-D756GBMQ.js → chunk-N5VOPV64.js} +4 -4
  106. package/dist/{chunk-D756GBMQ.js.map → chunk-N5VOPV64.js.map} +1 -1
  107. package/dist/{chunk-ZNGTC4CO.js → chunk-NIFPRC7P.js} +4 -4
  108. package/dist/{chunk-ZNGTC4CO.js.map → chunk-NIFPRC7P.js.map} +1 -1
  109. package/dist/{chunk-JJUABMAP.js → chunk-NIXOY473.js} +3 -3
  110. package/dist/{chunk-JJUABMAP.js.map → chunk-NIXOY473.js.map} +1 -1
  111. package/dist/{chunk-OAFJ53X3.js → chunk-NKAH67JK.js} +4 -4
  112. package/dist/{chunk-OAFJ53X3.js.map → chunk-NKAH67JK.js.map} +1 -1
  113. package/dist/{chunk-RIXYCFDO.js → chunk-PCFRBVKS.js} +4 -4
  114. package/dist/{chunk-RIXYCFDO.js.map → chunk-PCFRBVKS.js.map} +1 -1
  115. package/dist/{chunk-4D3II37O.js → chunk-PUMQDV67.js} +4 -4
  116. package/dist/{chunk-4D3II37O.js.map → chunk-PUMQDV67.js.map} +1 -1
  117. package/dist/{chunk-DF3PLL2E.js → chunk-QJYRWEXD.js} +28 -5
  118. package/dist/chunk-QJYRWEXD.js.map +1 -0
  119. package/dist/{chunk-XY2TDE6E.js → chunk-SXVRIIXW.js} +4 -4
  120. package/dist/{chunk-XY2TDE6E.js.map → chunk-SXVRIIXW.js.map} +1 -1
  121. package/dist/{chunk-6YUBWQTS.js → chunk-TEB5U6Y5.js} +4 -4
  122. package/dist/{chunk-6YUBWQTS.js.map → chunk-TEB5U6Y5.js.map} +1 -1
  123. package/dist/{chunk-MJ2S25ON.js → chunk-VJD3Y7E5.js} +4 -4
  124. package/dist/{chunk-MJ2S25ON.js.map → chunk-VJD3Y7E5.js.map} +1 -1
  125. package/dist/{chunk-BT7HM5I6.js → chunk-WEXMZMJH.js} +3 -3
  126. package/dist/{chunk-BT7HM5I6.js.map → chunk-WEXMZMJH.js.map} +1 -1
  127. package/dist/{chunk-UZHNKUER.js → chunk-Z4L2GOAK.js} +4 -4
  128. package/dist/{chunk-UZHNKUER.js.map → chunk-Z4L2GOAK.js.map} +1 -1
  129. package/dist/components-shared-whiteboard.cjs +26 -3
  130. package/dist/components-shared-whiteboard.cjs.map +1 -1
  131. package/dist/components-shared-whiteboard.js +3 -3
  132. package/dist/index.cjs +88 -3
  133. package/dist/index.cjs.map +1 -1
  134. package/dist/index.d.cts +88 -8
  135. package/dist/index.d.ts +88 -8
  136. package/dist/index.js +87 -26
  137. package/dist/index.js.map +1 -1
  138. package/dist/mcp/index.d.cts +3 -3
  139. package/dist/mcp/index.d.ts +3 -3
  140. package/dist/mcp.cjs +26 -3
  141. package/dist/mcp.cjs.map +1 -1
  142. package/dist/mcp.js +1 -1
  143. package/dist/{server-DDD3IZ56.d.cts → server-BJNF7pQe.d.cts} +1 -1
  144. package/dist/{server-CDX643Kz.d.ts → server-Dt97UxuD.d.ts} +1 -1
  145. package/dist/sharing/index.d.cts +2 -2
  146. package/dist/sharing/index.d.ts +2 -2
  147. package/dist/sheets-adapter.d.cts +2 -2
  148. package/dist/sheets-adapter.d.ts +2 -2
  149. package/dist/{tool-host-EuYHYSSH.d.cts → tool-host-BpEBqf5u.d.cts} +17 -0
  150. package/dist/{tool-host-CWTOJEm2.d.ts → tool-host-xY5F-eqG.d.ts} +17 -0
  151. package/dist/{types-NFGP769G.d.cts → types-C4NaIW6B.d.cts} +1 -1
  152. package/dist/{types-BKD6uf86.d.ts → types-DSwsNTBG.d.ts} +1 -1
  153. package/dist/undo/index.d.cts +1 -1
  154. package/dist/undo/index.d.ts +1 -1
  155. package/dist/undo.cjs.map +1 -1
  156. package/dist/undo.js +3 -3
  157. package/package.json +1 -1
  158. package/dist/chunk-DF3PLL2E.js.map +0 -1
package/dist/index.d.cts CHANGED
@@ -1,13 +1,13 @@
1
- import { M as MicroMcpServer } from './server-DDD3IZ56.cjs';
2
- export { a as McpServerOptions, T as Transport, e as errorResult, r as rpcError, t as textResult } from './server-DDD3IZ56.cjs';
3
- import { T as ToolHost } from './tool-host-EuYHYSSH.cjs';
4
- export { a as ToolRegistry } from './tool-host-EuYHYSSH.cjs';
1
+ import { M as MicroMcpServer } from './server-BJNF7pQe.cjs';
2
+ export { a as McpServerOptions, T as Transport, e as errorResult, r as rpcError, t as textResult } from './server-BJNF7pQe.cjs';
3
+ import { T as ToolHost } from './tool-host-BpEBqf5u.cjs';
4
+ export { a as ToolRegistry } from './tool-host-BpEBqf5u.cjs';
5
5
  export { InProcessTransport, RelayChannel, RelayTransport, attachInProcess, attachRelay } from './mcp/index.cjs';
6
6
  export { C as CallToolResult, d as ContentBlock, I as InitializeResult, J as JsonObject, b as JsonRpcMessage, e as JsonRpcNotification, f as JsonRpcRequest, g as JsonValue, M as MCP_PROTOCOL_VERSION, a as ServerCapabilities, S as ServerInfo, h as ToolCallContext, T as ToolDefinition, c as ToolHandler } from './types-C58ZXs4K.cjs';
7
7
  export { HumanPlusDisposition, HumanPlusEvent, HumanPlusEventPage, HumanPlusEventQuery, HumanPlusEventStore, MemoryHumanPlusEventStore, NewHumanPlusEvent } from './human-plus/index.cjs';
8
8
  export { TuiBridgeOptions, TuiSurfaceRegistryLike, registerTuiBridge } from './bridges/tui.cjs';
9
- import { B as Bridge } from './types-NFGP769G.cjs';
10
- export { a as BridgeFactory } from './types-NFGP769G.cjs';
9
+ import { B as Bridge } from './types-C4NaIW6B.cjs';
10
+ export { a as BridgeFactory } from './types-C4NaIW6B.cjs';
11
11
  import { FormFieldDescriptor } from './bridges/forms.cjs';
12
12
  export { FormBridgeAdapter, FormBridgeOptions, registerFormBridge } from './bridges/forms.cjs';
13
13
  export { SheetsBridgeAdapter, SheetsBridgeOptions, registerSheetsBridge } from './bridges/sheets.cjs';
@@ -202,6 +202,63 @@ interface ScreenDocBridgeOptions {
202
202
  /** Register the screen-content bridge (prefix `screen_`) over a screen's `DocTree`. */
203
203
  declare function registerScreenDocBridge(host: ToolHost, options: ScreenDocBridgeOptions): Bridge;
204
204
 
205
+ /**
206
+ * A page's contribution to the shared tool surface.
207
+ *
208
+ * Return the disposer that withdraws it — typically the `Bridge`'s own
209
+ * `dispose`, or the function `registerTool` returns. Returning nothing is
210
+ * allowed (the original `extraBridges` was typed that way) but means the
211
+ * contribution can never be withdrawn.
212
+ */
213
+ type BridgeContribution = (server: MicroMcpServer) => (() => void) | void;
214
+ /**
215
+ * The registry behind **"site tools always; page tools while mounted"**.
216
+ *
217
+ * `useCoBrowseSession` already had an `extraBridges` hook and already called it.
218
+ * What that shape could not express is a tool surface that CHANGES under the
219
+ * agent mid-session, because the callback is invoked exactly once while the
220
+ * server is being built:
221
+ *
222
+ * - a page that mounts later never gets a chance to contribute;
223
+ * - a page that unmounts cannot withdraw, so the agent keeps a tool aimed at
224
+ * a surface that is gone and only finds out by calling it.
225
+ *
226
+ * Both are silent. Nothing errors; the agent just never sees the tools, or sees
227
+ * dead ones. So contributions live in a registry that is applied when a server
228
+ * appears, re-applied if it is replaced, and withdrawn when the page unmounts —
229
+ * rather than a callback captured at construction.
230
+ *
231
+ * Withdrawal needs no notification machinery of its own: a bridge's disposer
232
+ * unregisters its tools, `ToolRegistry` fires `onToolsChanged`, and
233
+ * `MicroMcpServer` broadcasts `notifications/tools/list_changed`. That was
234
+ * verified before this was written — a grep for `unregisterTool` reads as
235
+ * "nothing unregisters", which is a false negative, because bridges use the
236
+ * disposer `registerTool` returns.
237
+ */
238
+ declare class BridgeContributions {
239
+ private readonly contributions;
240
+ private readonly applied;
241
+ private server;
242
+ /**
243
+ * Contribute bridges for as long as the returned disposer is uncalled.
244
+ *
245
+ * Applies immediately when a server is already live, and is held for the next
246
+ * one otherwise — so a page need not know whether sharing has started.
247
+ */
248
+ add(contribute: BridgeContribution): () => void;
249
+ /** Attach a server and apply every live contribution to it. */
250
+ bind(server: MicroMcpServer): void;
251
+ /**
252
+ * Detach the current server, withdrawing what was applied to it. Contributions
253
+ * themselves are KEPT: a session can be stopped and restarted under a page
254
+ * that never unmounted, and its tools must come back rather than silently
255
+ * vanish.
256
+ */
257
+ unbind(): void;
258
+ private apply;
259
+ private withdraw;
260
+ }
261
+
205
262
  /** A thing the human did, surfaced so the connected agent stays aware. */
206
263
  type CoBrowseUserEvent = {
207
264
  kind: "navigation";
@@ -256,7 +313,15 @@ type UseCoBrowseSessionOptions = {
256
313
  version: string;
257
314
  instructions?: string;
258
315
  };
259
- /** Register extra bridges (forms/screens/…) on the same server. */
316
+ /**
317
+ * Register extra bridges (forms/screens/…) on the same server, once, at
318
+ * construction.
319
+ *
320
+ * For a surface that comes and goes with navigation use
321
+ * {@link CoBrowseSession.contributeBridges} instead: this callback fires
322
+ * exactly once while the server is built, so a page mounted afterwards can
323
+ * never contribute through it, and one that unmounts can never withdraw.
324
+ */
260
325
  extraBridges?: (server: MicroMcpServer) => void;
261
326
  /** CSRF token for the relay register/unregister POSTs. */
262
327
  csrfToken?: () => string | null | undefined;
@@ -265,6 +330,21 @@ type UseCoBrowseSessionOptions = {
265
330
  };
266
331
  type CoBrowseSession = {
267
332
  server: MicroMcpServer | null;
333
+ /**
334
+ * Contribute bridges for as long as the returned disposer is uncalled —
335
+ * "site tools always; page tools while mounted".
336
+ *
337
+ * Call it from a page's mount effect and return its disposer:
338
+ *
339
+ * ```tsx
340
+ * useEffect(() => contributeBridges((server) =>
341
+ * registerArtboardBridge(server, { adapter }).dispose), []);
342
+ * ```
343
+ *
344
+ * Safe to call before sharing starts — the contribution is applied to the
345
+ * server as soon as one exists, and re-applied if the session is restarted.
346
+ */
347
+ contributeBridges: (contribute: BridgeContribution) => () => void;
268
348
  session: SessionDescriptor | null;
269
349
  relayState: RelayState;
270
350
  /**
@@ -596,4 +676,4 @@ type SimulateUsersButtonProps = {
596
676
  */
597
677
  declare function SimulateUsersButton({ endpoint, count, label, csrfToken, onTriggered, onError, className, style, }: SimulateUsersButtonProps): react.JSX.Element;
598
678
 
599
- export { type AgentActivity, AgentActivityHighlight, type AgentActivityHighlightProps, AgentCursor, type AgentCursorProps, AgentPanel, type AgentPanelProps, Bridge, BridgedForm, type BridgedFormProps, CoBrowseCursorLayer, type CoBrowseCursorLayerProps, CoBrowsePresence, type CoBrowsePresenceProps, type CoBrowseSession, type CoBrowseUserEvent, DocAdapter, FormFieldDescriptor, MicroMcpServer, type NavigationBridgeAdapter, type NavigationBridgeOptions, type NavigationConfirmRequest, type PageAction, type PageSnapshot, RelayState, SCREEN_TEXT_NODE_TYPE, type ScreenDocBridgeOptions, type ScreenDocNode, type ScreenDocOp, ScreensActivityBridge, type ScreensActivityBridgeProps, SessionDescriptor, ShareControls, type ShareControlsProps, SimulateUsersButton, type SimulateUsersButtonProps, ToolHost, type UseCoBrowseSessionOptions, buildAgentPrompt, registerNavigationBridge, registerScreenDocBridge, useCoBrowseSession };
679
+ export { type AgentActivity, AgentActivityHighlight, type AgentActivityHighlightProps, AgentCursor, type AgentCursorProps, AgentPanel, type AgentPanelProps, Bridge, type BridgeContribution, BridgeContributions, BridgedForm, type BridgedFormProps, CoBrowseCursorLayer, type CoBrowseCursorLayerProps, CoBrowsePresence, type CoBrowsePresenceProps, type CoBrowseSession, type CoBrowseUserEvent, DocAdapter, FormFieldDescriptor, MicroMcpServer, type NavigationBridgeAdapter, type NavigationBridgeOptions, type NavigationConfirmRequest, type PageAction, type PageSnapshot, RelayState, SCREEN_TEXT_NODE_TYPE, type ScreenDocBridgeOptions, type ScreenDocNode, type ScreenDocOp, ScreensActivityBridge, type ScreensActivityBridgeProps, SessionDescriptor, ShareControls, type ShareControlsProps, SimulateUsersButton, type SimulateUsersButtonProps, ToolHost, type UseCoBrowseSessionOptions, buildAgentPrompt, registerNavigationBridge, registerScreenDocBridge, useCoBrowseSession };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { M as MicroMcpServer } from './server-CDX643Kz.js';
2
- export { a as McpServerOptions, T as Transport, e as errorResult, r as rpcError, t as textResult } from './server-CDX643Kz.js';
3
- import { T as ToolHost } from './tool-host-CWTOJEm2.js';
4
- export { a as ToolRegistry } from './tool-host-CWTOJEm2.js';
1
+ import { M as MicroMcpServer } from './server-Dt97UxuD.js';
2
+ export { a as McpServerOptions, T as Transport, e as errorResult, r as rpcError, t as textResult } from './server-Dt97UxuD.js';
3
+ import { T as ToolHost } from './tool-host-xY5F-eqG.js';
4
+ export { a as ToolRegistry } from './tool-host-xY5F-eqG.js';
5
5
  export { InProcessTransport, RelayChannel, RelayTransport, attachInProcess, attachRelay } from './mcp/index.js';
6
6
  export { C as CallToolResult, d as ContentBlock, I as InitializeResult, J as JsonObject, b as JsonRpcMessage, e as JsonRpcNotification, f as JsonRpcRequest, g as JsonValue, M as MCP_PROTOCOL_VERSION, a as ServerCapabilities, S as ServerInfo, h as ToolCallContext, T as ToolDefinition, c as ToolHandler } from './types-C58ZXs4K.js';
7
7
  export { HumanPlusDisposition, HumanPlusEvent, HumanPlusEventPage, HumanPlusEventQuery, HumanPlusEventStore, MemoryHumanPlusEventStore, NewHumanPlusEvent } from './human-plus/index.js';
8
8
  export { TuiBridgeOptions, TuiSurfaceRegistryLike, registerTuiBridge } from './bridges/tui.js';
9
- import { B as Bridge } from './types-BKD6uf86.js';
10
- export { a as BridgeFactory } from './types-BKD6uf86.js';
9
+ import { B as Bridge } from './types-DSwsNTBG.js';
10
+ export { a as BridgeFactory } from './types-DSwsNTBG.js';
11
11
  import { FormFieldDescriptor } from './bridges/forms.js';
12
12
  export { FormBridgeAdapter, FormBridgeOptions, registerFormBridge } from './bridges/forms.js';
13
13
  export { SheetsBridgeAdapter, SheetsBridgeOptions, registerSheetsBridge } from './bridges/sheets.js';
@@ -202,6 +202,63 @@ interface ScreenDocBridgeOptions {
202
202
  /** Register the screen-content bridge (prefix `screen_`) over a screen's `DocTree`. */
203
203
  declare function registerScreenDocBridge(host: ToolHost, options: ScreenDocBridgeOptions): Bridge;
204
204
 
205
+ /**
206
+ * A page's contribution to the shared tool surface.
207
+ *
208
+ * Return the disposer that withdraws it — typically the `Bridge`'s own
209
+ * `dispose`, or the function `registerTool` returns. Returning nothing is
210
+ * allowed (the original `extraBridges` was typed that way) but means the
211
+ * contribution can never be withdrawn.
212
+ */
213
+ type BridgeContribution = (server: MicroMcpServer) => (() => void) | void;
214
+ /**
215
+ * The registry behind **"site tools always; page tools while mounted"**.
216
+ *
217
+ * `useCoBrowseSession` already had an `extraBridges` hook and already called it.
218
+ * What that shape could not express is a tool surface that CHANGES under the
219
+ * agent mid-session, because the callback is invoked exactly once while the
220
+ * server is being built:
221
+ *
222
+ * - a page that mounts later never gets a chance to contribute;
223
+ * - a page that unmounts cannot withdraw, so the agent keeps a tool aimed at
224
+ * a surface that is gone and only finds out by calling it.
225
+ *
226
+ * Both are silent. Nothing errors; the agent just never sees the tools, or sees
227
+ * dead ones. So contributions live in a registry that is applied when a server
228
+ * appears, re-applied if it is replaced, and withdrawn when the page unmounts —
229
+ * rather than a callback captured at construction.
230
+ *
231
+ * Withdrawal needs no notification machinery of its own: a bridge's disposer
232
+ * unregisters its tools, `ToolRegistry` fires `onToolsChanged`, and
233
+ * `MicroMcpServer` broadcasts `notifications/tools/list_changed`. That was
234
+ * verified before this was written — a grep for `unregisterTool` reads as
235
+ * "nothing unregisters", which is a false negative, because bridges use the
236
+ * disposer `registerTool` returns.
237
+ */
238
+ declare class BridgeContributions {
239
+ private readonly contributions;
240
+ private readonly applied;
241
+ private server;
242
+ /**
243
+ * Contribute bridges for as long as the returned disposer is uncalled.
244
+ *
245
+ * Applies immediately when a server is already live, and is held for the next
246
+ * one otherwise — so a page need not know whether sharing has started.
247
+ */
248
+ add(contribute: BridgeContribution): () => void;
249
+ /** Attach a server and apply every live contribution to it. */
250
+ bind(server: MicroMcpServer): void;
251
+ /**
252
+ * Detach the current server, withdrawing what was applied to it. Contributions
253
+ * themselves are KEPT: a session can be stopped and restarted under a page
254
+ * that never unmounted, and its tools must come back rather than silently
255
+ * vanish.
256
+ */
257
+ unbind(): void;
258
+ private apply;
259
+ private withdraw;
260
+ }
261
+
205
262
  /** A thing the human did, surfaced so the connected agent stays aware. */
206
263
  type CoBrowseUserEvent = {
207
264
  kind: "navigation";
@@ -256,7 +313,15 @@ type UseCoBrowseSessionOptions = {
256
313
  version: string;
257
314
  instructions?: string;
258
315
  };
259
- /** Register extra bridges (forms/screens/…) on the same server. */
316
+ /**
317
+ * Register extra bridges (forms/screens/…) on the same server, once, at
318
+ * construction.
319
+ *
320
+ * For a surface that comes and goes with navigation use
321
+ * {@link CoBrowseSession.contributeBridges} instead: this callback fires
322
+ * exactly once while the server is built, so a page mounted afterwards can
323
+ * never contribute through it, and one that unmounts can never withdraw.
324
+ */
260
325
  extraBridges?: (server: MicroMcpServer) => void;
261
326
  /** CSRF token for the relay register/unregister POSTs. */
262
327
  csrfToken?: () => string | null | undefined;
@@ -265,6 +330,21 @@ type UseCoBrowseSessionOptions = {
265
330
  };
266
331
  type CoBrowseSession = {
267
332
  server: MicroMcpServer | null;
333
+ /**
334
+ * Contribute bridges for as long as the returned disposer is uncalled —
335
+ * "site tools always; page tools while mounted".
336
+ *
337
+ * Call it from a page's mount effect and return its disposer:
338
+ *
339
+ * ```tsx
340
+ * useEffect(() => contributeBridges((server) =>
341
+ * registerArtboardBridge(server, { adapter }).dispose), []);
342
+ * ```
343
+ *
344
+ * Safe to call before sharing starts — the contribution is applied to the
345
+ * server as soon as one exists, and re-applied if the session is restarted.
346
+ */
347
+ contributeBridges: (contribute: BridgeContribution) => () => void;
268
348
  session: SessionDescriptor | null;
269
349
  relayState: RelayState;
270
350
  /**
@@ -596,4 +676,4 @@ type SimulateUsersButtonProps = {
596
676
  */
597
677
  declare function SimulateUsersButton({ endpoint, count, label, csrfToken, onTriggered, onError, className, style, }: SimulateUsersButtonProps): react.JSX.Element;
598
678
 
599
- export { type AgentActivity, AgentActivityHighlight, type AgentActivityHighlightProps, AgentCursor, type AgentCursorProps, AgentPanel, type AgentPanelProps, Bridge, BridgedForm, type BridgedFormProps, CoBrowseCursorLayer, type CoBrowseCursorLayerProps, CoBrowsePresence, type CoBrowsePresenceProps, type CoBrowseSession, type CoBrowseUserEvent, DocAdapter, FormFieldDescriptor, MicroMcpServer, type NavigationBridgeAdapter, type NavigationBridgeOptions, type NavigationConfirmRequest, type PageAction, type PageSnapshot, RelayState, SCREEN_TEXT_NODE_TYPE, type ScreenDocBridgeOptions, type ScreenDocNode, type ScreenDocOp, ScreensActivityBridge, type ScreensActivityBridgeProps, SessionDescriptor, ShareControls, type ShareControlsProps, SimulateUsersButton, type SimulateUsersButtonProps, ToolHost, type UseCoBrowseSessionOptions, buildAgentPrompt, registerNavigationBridge, registerScreenDocBridge, useCoBrowseSession };
679
+ export { type AgentActivity, AgentActivityHighlight, type AgentActivityHighlightProps, AgentCursor, type AgentCursorProps, AgentPanel, type AgentPanelProps, Bridge, type BridgeContribution, BridgeContributions, BridgedForm, type BridgedFormProps, CoBrowseCursorLayer, type CoBrowseCursorLayerProps, CoBrowsePresence, type CoBrowsePresenceProps, type CoBrowseSession, type CoBrowseUserEvent, DocAdapter, FormFieldDescriptor, MicroMcpServer, type NavigationBridgeAdapter, type NavigationBridgeOptions, type NavigationConfirmRequest, type PageAction, type PageSnapshot, RelayState, SCREEN_TEXT_NODE_TYPE, type ScreenDocBridgeOptions, type ScreenDocNode, type ScreenDocOp, ScreensActivityBridge, type ScreensActivityBridgeProps, SessionDescriptor, ShareControls, type ShareControlsProps, SimulateUsersButton, type SimulateUsersButtonProps, ToolHost, type UseCoBrowseSessionOptions, buildAgentPrompt, registerNavigationBridge, registerScreenDocBridge, useCoBrowseSession };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { useUndoStack } from './chunk-BT7HM5I6.js';
1
+ export { useUndoStack } from './chunk-WEXMZMJH.js';
2
2
  export { useSheetsActivityHighlights, useSheetsAdapter } from './chunk-KHKSQEMC.js';
3
3
  import { ConnectorButtons } from './chunk-5HNTNIWY.js';
4
4
  export { CLAUDE_CONNECTORS_URL, CONNECTOR_GLYPHS, CONNECTOR_TARGETS, ClaudeMark, ConnectorButtons, CursorMark, DesktopMark, VscodeMark, WrenchMark, buildCursorDeeplink, buildManualConfig, buildManualConfigSnippet, buildVscodeDeeplink, connectorHref, encodeBase64Json, slugifyServerName } from './chunk-5HNTNIWY.js';
@@ -9,40 +9,40 @@ import './chunk-IJ6JX5VC.js';
9
9
  import { createSessionDescriptor, attachSseRelay } from './chunk-6TZ5IBRN.js';
10
10
  export { SseRelayTransport, attachSseRelay, buildShareConfig, buildShareUrl, createSessionDescriptor, describeSession, readSessionFromUrl } from './chunk-6TZ5IBRN.js';
11
11
  export { attachHeuristicsSink, mapActivityToEvent as mapActivityToHeuristicsEvent } from './chunk-7R6RMROL.js';
12
- export { registerTerminalBridge } from './chunk-UZHNKUER.js';
13
- export { registerCatalogBridge } from './chunk-OAFJ53X3.js';
14
- export { registerFeaturesBridge } from './chunk-ZNGTC4CO.js';
15
- export { PASSKEY_BRIDGE_TOOLS, registerPasskeyBridge } from './chunk-7THGQUX3.js';
16
- export { cmsReducer, registerCmsBridge } from './chunk-JJUABMAP.js';
17
- import { registerDocBridge } from './chunk-XY2TDE6E.js';
18
- export { registerDocBridge } from './chunk-XY2TDE6E.js';
19
- export { registerTuiBridge } from './chunk-MFMBR6LN.js';
12
+ export { registerTerminalBridge } from './chunk-Z4L2GOAK.js';
13
+ export { registerCatalogBridge } from './chunk-NKAH67JK.js';
14
+ export { registerFeaturesBridge } from './chunk-NIFPRC7P.js';
15
+ export { PASSKEY_BRIDGE_TOOLS, registerPasskeyBridge } from './chunk-LOD77NCD.js';
16
+ export { cmsReducer, registerCmsBridge } from './chunk-NIXOY473.js';
17
+ import { registerDocBridge } from './chunk-SXVRIIXW.js';
18
+ export { registerDocBridge } from './chunk-SXVRIIXW.js';
19
+ export { registerTuiBridge } from './chunk-E2I3YVKC.js';
20
20
  import { useAgentActivity } from './chunk-UCKJAUBY.js';
21
21
  export { useAgentActivity, useAgentActivityForScreen } from './chunk-UCKJAUBY.js';
22
22
  export { MemoryHumanPlusEventStore } from './chunk-PMI4C5S4.js';
23
- export { registerChartsBridge } from './chunk-G5EZNWXJ.js';
24
- export { registerGridBridge } from './chunk-MJ2S25ON.js';
25
- export { registerSceneBridge } from './chunk-CA7GIJJC.js';
26
- export { registerScreensBridge } from './chunk-6YUBWQTS.js';
27
- export { registerSlidesBridge } from './chunk-PR4SXFZH.js';
28
- export { registerMapBridge } from './chunk-BHQJJ2YG.js';
29
- export { registerGitBridge } from './chunk-4D3II37O.js';
30
- export { registerFilesBridge } from './chunk-D756GBMQ.js';
23
+ export { registerChartsBridge } from './chunk-5W6YOXLT.js';
24
+ export { registerGridBridge } from './chunk-VJD3Y7E5.js';
25
+ export { registerSceneBridge } from './chunk-7LLMILTM.js';
26
+ export { registerScreensBridge } from './chunk-TEB5U6Y5.js';
27
+ export { registerSlidesBridge } from './chunk-2Q4EGZHJ.js';
28
+ export { registerMapBridge } from './chunk-MZ74LLDS.js';
29
+ export { registerGitBridge } from './chunk-PUMQDV67.js';
30
+ export { registerFilesBridge } from './chunk-N5VOPV64.js';
31
31
  export { RelayTransport, attachRelay } from './chunk-G6N2TQVO.js';
32
32
  import { attachInProcess } from './chunk-AFUULW5E.js';
33
33
  export { InProcessTransport, attachInProcess } from './chunk-AFUULW5E.js';
34
- import { registerFormBridge } from './chunk-USQGA672.js';
35
- export { registerFormBridge } from './chunk-USQGA672.js';
36
- export { registerSheetsBridge } from './chunk-WCKSDFTM.js';
37
- export { registerCodeBridge } from './chunk-RIXYCFDO.js';
38
- import { ensureUndoToolsRegistered, pushUndoEntry } from './chunk-CT3LRNH7.js';
39
- export { clearStack as clearUndoStack, ensureUndoToolsRegistered, pushUndoEntry, readHistory as readUndoHistory, redoOne, registerUndoTools, resetAllUndoStacks, undoOne } from './chunk-CT3LRNH7.js';
34
+ import { registerFormBridge } from './chunk-EIBV76IB.js';
35
+ export { registerFormBridge } from './chunk-EIBV76IB.js';
36
+ export { registerSheetsBridge } from './chunk-GT63LSPJ.js';
37
+ export { registerCodeBridge } from './chunk-PCFRBVKS.js';
38
+ import { ensureUndoToolsRegistered, pushUndoEntry } from './chunk-HVDHT7DM.js';
39
+ export { clearStack as clearUndoStack, ensureUndoToolsRegistered, pushUndoEntry, readHistory as readUndoHistory, redoOne, registerUndoTools, resetAllUndoStacks, undoOne } from './chunk-HVDHT7DM.js';
40
40
  import { wrapToolWithActivity } from './chunk-2VENWGLZ.js';
41
41
  export { wrapToolWithActivity } from './chunk-2VENWGLZ.js';
42
42
  import { emitActivity, onActivity } from './chunk-C3TYI5TJ.js';
43
43
  export { emitActivity, onActivity, readActivityHistory, resetActivityRegistry } from './chunk-C3TYI5TJ.js';
44
- import { textResult, MicroMcpServer, errorResult } from './chunk-DF3PLL2E.js';
45
- export { MCP_PROTOCOL_VERSION, MicroMcpServer, ToolRegistry, errorResult, rpcError, textResult } from './chunk-DF3PLL2E.js';
44
+ import { textResult, MicroMcpServer, errorResult } from './chunk-QJYRWEXD.js';
45
+ export { MCP_PROTOCOL_VERSION, MicroMcpServer, ToolRegistry, errorResult, rpcError, textResult } from './chunk-QJYRWEXD.js';
46
46
  import { childrenOf, appendOrder } from '@particle-academy/fancy-doc-commons';
47
47
  import { useRef, useState, useEffect, useCallback, useMemo } from 'react';
48
48
  import { jsx, jsxs } from 'react/jsx-runtime';
@@ -395,6 +395,58 @@ function registerScreenDocBridge(host, options) {
395
395
  }
396
396
  };
397
397
  }
398
+
399
+ // src/sharing/bridge-contributions.ts
400
+ var BridgeContributions = class {
401
+ constructor() {
402
+ this.contributions = /* @__PURE__ */ new Map();
403
+ this.applied = /* @__PURE__ */ new Map();
404
+ this.server = null;
405
+ }
406
+ /**
407
+ * Contribute bridges for as long as the returned disposer is uncalled.
408
+ *
409
+ * Applies immediately when a server is already live, and is held for the next
410
+ * one otherwise — so a page need not know whether sharing has started.
411
+ */
412
+ add(contribute) {
413
+ const key = /* @__PURE__ */ Symbol("bridge-contribution");
414
+ this.contributions.set(key, contribute);
415
+ if (this.server) this.apply(key, contribute, this.server);
416
+ return () => {
417
+ this.contributions.delete(key);
418
+ this.withdraw(key);
419
+ };
420
+ }
421
+ /** Attach a server and apply every live contribution to it. */
422
+ bind(server) {
423
+ if (this.server === server) return;
424
+ if (this.server) this.unbind();
425
+ this.server = server;
426
+ for (const [key, contribute] of this.contributions) this.apply(key, contribute, server);
427
+ }
428
+ /**
429
+ * Detach the current server, withdrawing what was applied to it. Contributions
430
+ * themselves are KEPT: a session can be stopped and restarted under a page
431
+ * that never unmounted, and its tools must come back rather than silently
432
+ * vanish.
433
+ */
434
+ unbind() {
435
+ for (const key of [...this.applied.keys()]) this.withdraw(key);
436
+ this.server = null;
437
+ }
438
+ apply(key, contribute, server) {
439
+ const dispose = contribute(server);
440
+ if (typeof dispose === "function") this.applied.set(key, dispose);
441
+ }
442
+ withdraw(key) {
443
+ const dispose = this.applied.get(key);
444
+ this.applied.delete(key);
445
+ dispose?.();
446
+ }
447
+ };
448
+
449
+ // src/sharing/use-co-browse-session.ts
398
450
  var DEFAULT_AGENT2 = { id: "agent", name: "Agent", color: "#a855f7" };
399
451
  var USER = { id: "human", name: "You" };
400
452
  function useCoBrowseSession(options) {
@@ -402,6 +454,8 @@ function useCoBrowseSession(options) {
402
454
  const agent = { ...DEFAULT_AGENT2, ...options.agent ?? {} };
403
455
  const relayBaseUrl = options.relayBaseUrl ?? "/agent-relay";
404
456
  const serverRef = useRef(null);
457
+ const contributionsRef = useRef(null);
458
+ if (!contributionsRef.current) contributionsRef.current = new BridgeContributions();
405
459
  const relayRef = useRef(null);
406
460
  const detachInProc = useRef(null);
407
461
  const disposeBridge = useRef(null);
@@ -415,6 +469,7 @@ function useCoBrowseSession(options) {
415
469
  });
416
470
  const bridge = registerNavigationBridge(server, { adapter, agent, pendingMode: options.pendingMode });
417
471
  extraBridges?.(server);
472
+ contributionsRef.current.bind(server);
418
473
  const inProc = attachInProcess(server);
419
474
  detachInProc.current = () => inProc.close();
420
475
  disposeBridge.current = bridge.dispose;
@@ -422,6 +477,7 @@ function useCoBrowseSession(options) {
422
477
  return () => {
423
478
  relayRef.current?.close();
424
479
  relayRef.current = null;
480
+ contributionsRef.current.unbind();
425
481
  disposeBridge.current?.();
426
482
  detachInProc.current?.();
427
483
  serverRef.current = null;
@@ -480,8 +536,13 @@ function useCoBrowseSession(options) {
480
536
  meta: event
481
537
  });
482
538
  }, []);
539
+ const contributeBridges = useCallback(
540
+ (contribute) => contributionsRef.current.add(contribute),
541
+ []
542
+ );
483
543
  return {
484
544
  server: serverRef.current,
545
+ contributeBridges,
485
546
  session,
486
547
  relayState,
487
548
  agentConnected: agentCount > 0,
@@ -795,6 +856,6 @@ function SimulateUsersButton({
795
856
  );
796
857
  }
797
858
 
798
- export { BridgedForm, CoBrowseCursorLayer, CoBrowsePresence, SCREEN_TEXT_NODE_TYPE, ScreensActivityBridge, SimulateUsersButton, registerNavigationBridge, registerScreenDocBridge, useCoBrowseSession };
859
+ export { BridgeContributions, BridgedForm, CoBrowseCursorLayer, CoBrowsePresence, SCREEN_TEXT_NODE_TYPE, ScreensActivityBridge, SimulateUsersButton, registerNavigationBridge, registerScreenDocBridge, useCoBrowseSession };
799
860
  //# sourceMappingURL=index.js.map
800
861
  //# sourceMappingURL=index.js.map