@particle-academy/agent-integrations 0.19.0 → 0.20.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.
@@ -1,5 +1,5 @@
1
- import { ShareControls, AgentCursor, AgentActivityHighlight, AgentPanel } from './chunk-YEEOTIGY.js';
2
- import { createSessionDescriptor, attachSseRelay } from './chunk-CPNOF4HI.js';
1
+ import { ShareControls, AgentCursor, AgentActivityHighlight, AgentPanel } from './chunk-HKQBG2HZ.js';
2
+ import { createSessionDescriptor, attachSseRelay } from './chunk-FUI7KXE7.js';
3
3
  import { attachInProcess } from './chunk-AFUULW5E.js';
4
4
  import { registerWhiteboardBridge } from './chunk-3QJSOS7G.js';
5
5
  import './chunk-KJ5AOOV7.js';
package/dist/index.cjs CHANGED
@@ -2490,6 +2490,7 @@ function constantTimeEqual(a, b) {
2490
2490
  // src/sharing/sse-relay.ts
2491
2491
  var SseRelayTransport = class {
2492
2492
  constructor(options) {
2493
+ this.disposed = false;
2493
2494
  this.sendQueue = [];
2494
2495
  this.connected = false;
2495
2496
  this.listeners = /* @__PURE__ */ new Set();
@@ -2500,26 +2501,45 @@ var SseRelayTransport = class {
2500
2501
  bindServer(server) {
2501
2502
  this.server = server;
2502
2503
  }
2503
- /** Open the SSE channel. Idempotent. */
2504
+ /** Open the receive channel. Idempotent. */
2504
2505
  start() {
2505
- if (this.connected || typeof window === "undefined") return;
2506
- const url = `${this.opts.baseUrl}/${encodeURIComponent(this.opts.sessionId)}/events?token=${encodeURIComponent(this.opts.token)}`;
2506
+ if (this.connected || this.disposed || typeof window === "undefined") return;
2507
2507
  this.setState("connecting");
2508
+ void import('@particle-academy/fancy-cf-relay').then(({ createRelayChannel }) => {
2509
+ if (this.connected || this.disposed) return;
2510
+ this.channel = createRelayChannel({
2511
+ baseUrl: this.opts.baseUrl,
2512
+ session: this.opts.sessionId,
2513
+ token: this.opts.token,
2514
+ transport: "auto",
2515
+ receiveDirection: "inbound",
2516
+ sendPath: "outbox",
2517
+ onFrame: (raw) => this.handleInbound(raw),
2518
+ onOpen: () => this.markOpen(),
2519
+ onError: () => this.setState("error"),
2520
+ fetchImpl: this.opts.fetch
2521
+ });
2522
+ this.channel.start();
2523
+ }).catch(() => {
2524
+ if (!this.disposed) this.startSse();
2525
+ });
2526
+ }
2527
+ /** Fallback receive leg: a plain EventSource (no fancy-cf-relay installed). */
2528
+ startSse() {
2529
+ if (this.connected || this.disposed) return;
2530
+ const url = `${this.opts.baseUrl}/${encodeURIComponent(this.opts.sessionId)}/events?token=${encodeURIComponent(this.opts.token)}`;
2508
2531
  const es = new EventSource(url, { withCredentials: false });
2509
2532
  this.es = es;
2510
- es.addEventListener("open", () => {
2511
- this.connected = true;
2512
- this.setState("open");
2513
- const queued = this.sendQueue.splice(0);
2514
- for (const msg of queued) this.postOut(msg);
2515
- });
2516
- es.addEventListener("mcp", (ev) => {
2517
- const raw = ev.data;
2518
- this.handleInbound(raw);
2519
- });
2520
- es.addEventListener("error", () => {
2521
- this.setState("error");
2522
- });
2533
+ es.addEventListener("open", () => this.markOpen());
2534
+ es.addEventListener("mcp", (ev) => this.handleInbound(ev.data));
2535
+ es.addEventListener("error", () => this.setState("error"));
2536
+ }
2537
+ /** Mark the channel live + flush any queued outbound frames. */
2538
+ markOpen() {
2539
+ this.connected = true;
2540
+ this.setState("open");
2541
+ const queued = this.sendQueue.splice(0);
2542
+ for (const msg of queued) this.postOut(msg);
2523
2543
  }
2524
2544
  send(message) {
2525
2545
  if (!this.connected) {
@@ -2529,6 +2549,9 @@ var SseRelayTransport = class {
2529
2549
  this.postOut(message);
2530
2550
  }
2531
2551
  close() {
2552
+ this.disposed = true;
2553
+ this.channel?.stop();
2554
+ this.channel = void 0;
2532
2555
  this.es?.close();
2533
2556
  this.es = void 0;
2534
2557
  this.connected = false;