@markupai/sidebar-adapter 2.3.0 → 2.5.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 (40) hide show
  1. package/README.md +96 -11
  2. package/asyncapi.json +201 -41
  3. package/dist/adapters/index.d.ts +2 -2
  4. package/dist/adapters/pluginAdapter.d.ts +15 -3
  5. package/dist/adapters/pluginAdapter.d.ts.map +1 -1
  6. package/dist/adapters/sidebarAdapter.d.ts +2 -2
  7. package/dist/adapters/sidebarAdapter.d.ts.map +1 -1
  8. package/dist/errors.d.ts +12 -0
  9. package/dist/errors.d.ts.map +1 -1
  10. package/dist/ipc/call-signatures.d.ts +15 -2
  11. package/dist/ipc/call-signatures.d.ts.map +1 -1
  12. package/dist/ipc/deferred-promise.d.ts.map +1 -1
  13. package/dist/ipc/index.d.ts +8 -8
  14. package/dist/ipc/index.d.ts.map +1 -1
  15. package/dist/ipc/ipc-core.d.ts +32 -3
  16. package/dist/ipc/ipc-core.d.ts.map +1 -1
  17. package/dist/ipc/message-types.d.ts +35 -4
  18. package/dist/ipc/message-types.d.ts.map +1 -1
  19. package/dist/ipc/plugin-ipc-adapter.d.ts +16 -5
  20. package/dist/ipc/plugin-ipc-adapter.d.ts.map +1 -1
  21. package/dist/ipc/replace-progress.d.ts +9 -0
  22. package/dist/ipc/replace-progress.d.ts.map +1 -0
  23. package/dist/ipc/sidebar-build-info.d.ts +1 -1
  24. package/dist/ipc/sidebar-ipc-adapter.d.ts +4 -4
  25. package/dist/ipc/sidebar-ipc-adapter.d.ts.map +1 -1
  26. package/dist/load-overlay/loadOverlayStyles.d.ts.map +1 -1
  27. package/dist/load-overlay/sidebarLoadOverlay.d.ts.map +1 -1
  28. package/dist/main.js +319 -210
  29. package/dist/main.umd.cjs +7 -7
  30. package/dist/sidebar-host/createSidebarHost.d.ts +4 -4
  31. package/dist/types/common.d.ts +30 -0
  32. package/dist/types/common.d.ts.map +1 -1
  33. package/dist/types/index.d.ts +1 -0
  34. package/dist/types/index.d.ts.map +1 -1
  35. package/dist/types/integrationSettings.d.ts.map +1 -1
  36. package/dist/types/pluginInterface.d.ts +38 -2
  37. package/dist/types/pluginInterface.d.ts.map +1 -1
  38. package/dist/types/progress.d.ts +18 -0
  39. package/dist/types/progress.d.ts.map +1 -0
  40. package/package.json +3 -3
package/dist/main.js CHANGED
@@ -1,19 +1,20 @@
1
- var fe = /* @__PURE__ */ (function(e) {
1
+ var Pe = /* @__PURE__ */ (function(e) {
2
2
  return e.TEXT_PLAIN = "text/plain", e.TEXT_MARKDOWN = "text/markdown", e.TEXT_HTML = "text/html", e.APPLICATION_DITA_XML = "application/dita+xml", e;
3
- })({}), me = [
3
+ })({}), Ee = [
4
4
  "text/plain",
5
5
  "text/markdown",
6
6
  "text/html",
7
7
  "application/dita+xml"
8
- ], ye = {
8
+ ], Re = {
9
9
  integrationName: "unknown",
10
10
  integrationVersion: "unknown",
11
11
  integrationId: "markupai-sidebar-app",
12
12
  hideBanner: !1,
13
13
  supportCheckSelection: !0,
14
+ supportComments: !1,
14
15
  multiAgent: !1,
15
16
  multiDocument: !1
16
- }, Ie = (e) => typeof e != "object" || e === null ? !1 : Array.isArray(e.fields), ve = (e) => {
17
+ }, Oe = (e) => typeof e != "object" || e === null ? !1 : Array.isArray(e.fields), Te = (e) => {
17
18
  if (typeof e != "object" || e === null) return !1;
18
19
  const t = e;
19
20
  return typeof t.id != "string" || t.id.length === 0 || typeof t.label != "string" ? !1 : t.type === "boolean" ? typeof t.default == "boolean" : t.type === "enum" ? typeof t.default != "string" || !Array.isArray(t.options) || t.options.length === 0 ? !1 : t.options.every((r) => {
@@ -21,12 +22,12 @@ var fe = /* @__PURE__ */ (function(e) {
21
22
  const n = r;
22
23
  return typeof n.value == "string" && typeof n.label == "string";
23
24
  }) : !1;
24
- }, V = "2.3.0", v = class x extends Error {
25
+ }, Y = "2.5.0", A = class _ extends Error {
25
26
  name = "TextLookupError";
26
27
  constructor(t) {
27
- super(t), Object.setPrototypeOf(this, x.prototype);
28
+ super(t), Object.setPrototypeOf(this, _.prototype);
28
29
  }
29
- }, M = class _ extends v {
30
+ }, L = class k extends A {
30
31
  name = "ReplaceBatchError";
31
32
  applied;
32
33
  failed;
@@ -34,20 +35,28 @@ var fe = /* @__PURE__ */ (function(e) {
34
35
  super(t), this.applied = r.applied.map((n) => ({
35
36
  start: n.start,
36
37
  end: n.end
37
- })), this.failed = r.failed.map((n) => L(n, n.message)), Object.setPrototypeOf(this, _.prototype);
38
+ })), this.failed = r.failed.map((n) => U(n, n.message)), Object.setPrototypeOf(this, k.prototype);
39
+ }
40
+ }, N = class B extends Error {
41
+ name = "IpcTimeoutError";
42
+ constructor(t, r, n) {
43
+ super(`IPC call timeout: "${t}" did not respond within ${String(r)}ms` + (n === void 0 ? "" : ` (timeout ${String(n)} could not be used)`)), Object.setPrototypeOf(this, B.prototype);
38
44
  }
39
45
  };
40
- function Ae(e) {
41
- return e instanceof M;
46
+ function De(e) {
47
+ return e instanceof N;
48
+ }
49
+ function Me(e) {
50
+ return e instanceof L;
42
51
  }
43
- function L(e, t) {
52
+ function U(e, t) {
44
53
  const r = {
45
54
  start: e.start,
46
55
  end: e.end
47
56
  };
48
57
  return typeof t == "string" && t.trim() !== "" && (r.message = t), r;
49
58
  }
50
- function R(e) {
59
+ function O(e) {
51
60
  return Array.isArray(e) ? e.flatMap((t) => {
52
61
  if (t === null || typeof t != "object") return [];
53
62
  const { start: r, end: n, message: i } = t;
@@ -60,33 +69,33 @@ function R(e) {
60
69
  }];
61
70
  }) : [];
62
71
  }
63
- function Ce(e) {
64
- return e instanceof v;
72
+ function xe(e) {
73
+ return e instanceof A;
65
74
  }
66
- var O = {
67
- TextLookupError: (e) => new v(e),
68
- ReplaceBatchError: (e, t) => new M(e, {
69
- applied: R(t.applied).map((r) => r.range),
70
- failed: R(t.failed).map((r) => L(r.range, r.message))
75
+ var T = {
76
+ TextLookupError: (e) => new A(e),
77
+ ReplaceBatchError: (e, t) => new L(e, {
78
+ applied: O(t.applied).map((r) => r.range),
79
+ failed: O(t.failed).map((r) => U(r.range, r.message))
71
80
  })
72
81
  };
73
- function z(e) {
74
- const t = e.message ?? "", r = e.name, n = typeof r == "string" && r in O ? O[r] : void 0;
82
+ function X(e) {
83
+ const t = e.message ?? "", r = e.name, n = typeof r == "string" && r in T ? T[r] : void 0;
75
84
  return n ? n(t, e) : Object.assign(new Error(t), r ? { name: r } : {});
76
85
  }
77
- var k = ":", B = /^[a-z][a-z0-9-]*$/;
78
- function be(e) {
79
- const t = e.indexOf(k);
80
- return t <= 0 || t === e.length - 1 ? !1 : B.test(e.slice(0, t));
86
+ var H = ":", $ = /^[a-z][a-z0-9-]*$/;
87
+ function _e(e) {
88
+ const t = e.indexOf(H);
89
+ return t <= 0 || t === e.length - 1 ? !1 : $.test(e.slice(0, t));
81
90
  }
82
- function Se(e, t) {
91
+ function Le(e, t) {
83
92
  const r = e.trim().toLowerCase(), n = t.trim();
84
- if (!B.test(r)) throw new Error(`Invalid document reference prefix ${JSON.stringify(e)}: expected a lowercase name like "word".`);
93
+ if (!$.test(r)) throw new Error(`Invalid document reference prefix ${JSON.stringify(e)}: expected a lowercase name like "word".`);
85
94
  if (n.length === 0) throw new Error("Invalid document reference: the document id is empty.");
86
- const i = `${r}${k}`;
95
+ const i = `${r}${H}`;
87
96
  return n.startsWith(i) ? n : `${i}${n}`;
88
97
  }
89
- var W = class extends Promise {
98
+ var K = class extends Promise {
90
99
  static get [Symbol.species]() {
91
100
  return Promise;
92
101
  }
@@ -99,24 +108,44 @@ var W = class extends Promise {
99
108
  t = n, r = i, e(n, i);
100
109
  }), this.resolve = t, this.reject = r;
101
110
  }
102
- }, G = { timeout: 1e4 };
103
- function J(e) {
104
- const t = typeof e == "object" && e !== null ? Object.fromEntries(Object.getOwnPropertyNames(e).map((o) => [o, e[o]])) : {}, r = e instanceof Error ? e.message : String(e), n = typeof t.message == "string" && t.message !== "" ? t.message : r, i = e instanceof Error ? e.name : void 0, a = typeof t.name == "string" ? t.name : i;
111
+ }, j = { timeout: 1e4 };
112
+ function I(e, t) {
113
+ try {
114
+ e?.(t);
115
+ } catch {
116
+ }
117
+ }
118
+ function q(e) {
119
+ const t = typeof e == "object" && e !== null ? Object.fromEntries(Object.getOwnPropertyNames(e).map((s) => [s, e[s]])) : {}, r = e instanceof Error ? e.message : String(e), n = typeof t.message == "string" && t.message !== "" ? t.message : r, i = e instanceof Error ? e.name : void 0, a = typeof t.name == "string" ? t.name : i;
105
120
  return JSON.stringify({
106
121
  ...t,
107
122
  message: n,
108
123
  ...a !== void 0 && { name: a }
109
124
  });
110
125
  }
111
- var N = class {
126
+ function Z(e) {
127
+ try {
128
+ return X(JSON.parse(e));
129
+ } catch {
130
+ return /* @__PURE__ */ new Error("Failed to parse error from IPC");
131
+ }
132
+ }
133
+ var Q = 3e5, ee = 2147483647;
134
+ function te(e, t) {
135
+ const r = (i) => !Number.isNaN(i) && i > 0;
136
+ let n = j.timeout;
137
+ return r(e) ? n = e : r(t) && (n = t), Math.min(Math.max(1, Math.ceil(n)), ee);
138
+ }
139
+ var F = class {
112
140
  promisesByID = {};
113
141
  receiversByName = {};
142
+ progressReceiverNames = /* @__PURE__ */ new Set();
114
143
  currentID = 0;
115
144
  config;
116
145
  postMessage;
117
146
  constructor(e, t) {
118
147
  this.postMessage = e, this.config = {
119
- ...G,
148
+ ...j,
120
149
  ...t
121
150
  };
122
151
  }
@@ -130,29 +159,38 @@ var N = class {
130
159
  return this.callWithOptions(e, {}, ...t);
131
160
  }
132
161
  callWithOptions(e, t, ...r) {
133
- const n = this.currentID++, i = new W(), a = t.timeout ?? this.config.timeout, o = setTimeout(() => {
134
- if (n in this.promisesByID) {
135
- const l = /* @__PURE__ */ new Error(`IPC call timeout: "${e}" did not respond within ${String(a)}ms`);
136
- i.reject(l), Reflect.deleteProperty(this.promisesByID, n);
137
- }
138
- }, a);
139
- this.promisesByID[n] = {
140
- promise: i,
141
- timeoutId: o
162
+ const n = t.timeout ?? this.config.timeout, i = te(n, this.config.timeout), a = this.currentID++, s = new K(), o = setTimeout(() => {
163
+ if (a in this.promisesByID)
164
+ if (s.reject(new N(e, i, i === n ? void 0 : n)), t.onProgress || t.onLateResult) {
165
+ const c = this.promisesByID[a];
166
+ c.timedOut = !0, c.timeoutId = setTimeout(() => {
167
+ this.promisesByID[a] === c && Reflect.deleteProperty(this.promisesByID, a);
168
+ }, Q);
169
+ } else Reflect.deleteProperty(this.promisesByID, a);
170
+ }, i);
171
+ this.promisesByID[a] = {
172
+ promise: s,
173
+ timeoutId: o,
174
+ onProgress: t.onProgress,
175
+ onLateResult: t.onLateResult,
176
+ timedOut: !1
142
177
  };
143
- const s = {
178
+ const l = {
144
179
  type: "call",
145
- id: n,
180
+ id: a,
146
181
  name: e,
147
182
  data: r
148
183
  };
149
- return this.postMessage(s), i;
184
+ return this.postMessage(l), s;
150
185
  }
151
186
  receive(e, t) {
152
- this.receiversByName[e] = t;
187
+ this.receiversByName[e] = t, this.progressReceiverNames.delete(e);
188
+ }
189
+ receiveWithProgress(e, t) {
190
+ this.receiversByName[e] = t, this.progressReceiverNames.add(e);
153
191
  }
154
192
  ignore(e) {
155
- delete this.receiversByName[e];
193
+ delete this.receiversByName[e], this.progressReceiverNames.delete(e);
156
194
  }
157
195
  async handleMessage(e) {
158
196
  switch (e.type) {
@@ -165,98 +203,146 @@ var N = class {
165
203
  case "error":
166
204
  this.handleError(e);
167
205
  break;
206
+ case "progress":
207
+ this.handleProgress(e);
208
+ break;
168
209
  default:
169
210
  }
170
211
  }
171
212
  async handleCall(e) {
172
213
  const { id: t, name: r, data: n } = e;
173
214
  if (!(r in this.receiversByName)) {
174
- const a = /* @__PURE__ */ new Error(`No receiver registered for: ${r}`), o = JSON.stringify({
175
- message: a.message,
176
- name: a.name
215
+ const o = /* @__PURE__ */ new Error(`No receiver registered for: ${r}`), l = JSON.stringify({
216
+ message: o.message,
217
+ name: o.name
177
218
  });
178
219
  this.postMessage({
179
220
  type: "error",
180
221
  id: t,
181
222
  name: r,
182
- errorJSON: o
223
+ errorJSON: l
183
224
  });
184
225
  return;
185
226
  }
186
227
  const i = this.receiversByName[r];
228
+ let a = !1;
229
+ const s = (o) => {
230
+ if (!a)
231
+ try {
232
+ this.postMessage({
233
+ type: "progress",
234
+ id: t,
235
+ name: r,
236
+ data: o
237
+ });
238
+ } catch {
239
+ }
240
+ };
187
241
  try {
188
242
  if (!Array.isArray(n)) throw new TypeError(`IPC: Expected array of arguments but got ${typeof n}`);
189
- const a = await i(...n), o = {
243
+ const o = n, l = await (this.progressReceiverNames.has(r) ? i(s, ...o) : i(...o));
244
+ a = !0;
245
+ const c = {
190
246
  type: "response",
191
247
  id: t,
192
248
  name: r,
193
- data: a
249
+ data: l
194
250
  };
195
- this.postMessage(o);
196
- } catch (a) {
197
- const o = {
251
+ this.postMessage(c);
252
+ } catch (o) {
253
+ a = !0;
254
+ const l = {
198
255
  type: "error",
199
256
  id: t,
200
257
  name: r,
201
- errorJSON: J(a)
258
+ errorJSON: q(o)
202
259
  };
203
- this.postMessage(o);
260
+ this.postMessage(l);
204
261
  }
205
262
  }
206
263
  handleResponse(e) {
207
264
  const { id: t } = e;
208
265
  if (t in this.promisesByID) {
209
- const { promise: r, timeoutId: n } = this.promisesByID[t];
210
- clearTimeout(n), r.resolve(e.data), Reflect.deleteProperty(this.promisesByID, t);
266
+ const { promise: r, timeoutId: n, timedOut: i, onLateResult: a } = this.promisesByID[t];
267
+ if (clearTimeout(n), Reflect.deleteProperty(this.promisesByID, t), i) {
268
+ I(a, { status: "success" });
269
+ return;
270
+ }
271
+ r.resolve(e.data);
211
272
  }
212
273
  }
213
274
  handleError(e) {
214
275
  const { id: t, errorJSON: r } = e;
215
276
  if (t in this.promisesByID) {
216
- const { promise: n, timeoutId: i } = this.promisesByID[t];
217
- clearTimeout(i);
218
- try {
219
- const a = JSON.parse(r), o = z(a);
220
- n.reject(o);
221
- } catch {
222
- n.reject(/* @__PURE__ */ new Error("Failed to parse error from IPC"));
277
+ const { promise: n, timeoutId: i, timedOut: a, onLateResult: s } = this.promisesByID[t];
278
+ clearTimeout(i), Reflect.deleteProperty(this.promisesByID, t);
279
+ const o = Z(r);
280
+ if (a) {
281
+ I(s, {
282
+ status: "error",
283
+ error: o
284
+ });
285
+ return;
223
286
  }
224
- Reflect.deleteProperty(this.promisesByID, t);
287
+ n.reject(o);
225
288
  }
226
289
  }
290
+ handleProgress(e) {
291
+ const { id: t } = e;
292
+ t in this.promisesByID && I(this.promisesByID[t].onProgress, e.data);
293
+ }
227
294
  destroy() {
228
295
  for (const { promise: e, timeoutId: t } of Object.values(this.promisesByID))
229
296
  clearTimeout(t), e.reject(/* @__PURE__ */ new Error("IPC destroyed"));
230
- this.promisesByID = {}, this.receiversByName = {};
297
+ this.promisesByID = {}, this.receiversByName = {}, this.progressReceiverNames.clear();
231
298
  }
232
299
  };
233
- var Y = /* @__PURE__ */ new Set(["auto", "prompt"]), I = (e, t) => {
300
+ function re(e) {
301
+ if (typeof e != "object" || e === null) return !1;
302
+ const { start: t, end: r } = e;
303
+ return typeof t == "number" && typeof r == "number";
304
+ }
305
+ var D = (e) => `${String(e.start)}:${String(e.end)}`;
306
+ function ne(e, t) {
307
+ if (typeof e != "object" || e === null) return null;
308
+ const { total: r, applied: n } = e;
309
+ if (typeof r != "number" || !Array.isArray(n) || !n.every(re)) return null;
310
+ const i = new Set(t.map(({ range: a }) => D(a)));
311
+ return {
312
+ total: r,
313
+ applied: n.filter((a) => i.has(D(a))).map(({ start: a, end: s }) => ({
314
+ start: a,
315
+ end: s
316
+ }))
317
+ };
318
+ }
319
+ var ie = /* @__PURE__ */ new Set(["auto", "prompt"]), v = (e, t) => {
234
320
  const r = e[t];
235
321
  if (!(typeof r != "string" || r.length === 0))
236
322
  return r.slice(0, 64);
237
323
  };
238
- function X(e) {
324
+ function ae(e) {
239
325
  if (typeof e != "object" || e === null || Array.isArray(e)) return null;
240
- const t = e, r = I(t, "version"), n = I(t, "commitHash");
326
+ const t = e, r = v(t, "version"), n = v(t, "commitHash");
241
327
  if (r === void 0 || n === void 0) return null;
242
328
  const i = {
243
329
  version: r,
244
330
  commitHash: n
245
331
  };
246
- typeof t.swControlled == "boolean" && (i.swControlled = t.swControlled), Y.has(t.pwaUpdateMode) && (i.pwaUpdateMode = t.pwaUpdateMode);
247
- const a = I(t, "adapterVersion");
332
+ typeof t.swControlled == "boolean" && (i.swControlled = t.swControlled), ie.has(t.pwaUpdateMode) && (i.pwaUpdateMode = t.pwaUpdateMode);
333
+ const a = v(t, "adapterVersion");
248
334
  return a !== void 0 && (i.adapterVersion = a), i;
249
335
  }
250
- function K(e) {
336
+ function se(e) {
251
337
  return typeof e != "string" || e.length === 0 ? null : e.slice(0, 64);
252
338
  }
253
- var q = class {
339
+ var oe = class {
254
340
  ipc;
255
341
  sidebar;
256
342
  targetOrigin;
257
343
  latestHostAdapterVersion = null;
258
344
  constructor(e, t, r = "*") {
259
- this.sidebar = e || {}, this.targetOrigin = r, this.ipc = new N((n) => {
345
+ this.sidebar = e || {}, this.targetOrigin = r, this.ipc = new F((n) => {
260
346
  window.parent.postMessage(n, this.targetOrigin);
261
347
  }, t), window.addEventListener("message", this.handleMessage), this.registerReceivers();
262
348
  }
@@ -315,9 +401,9 @@ var q = class {
315
401
  async getInitConfig(e) {
316
402
  const { hostAdapterVersion: t, ...r } = e ? await this.ipc.call("getInitConfig", {
317
403
  ...e,
318
- adapterVersion: e.adapterVersion ?? "2.3.0"
404
+ adapterVersion: e.adapterVersion ?? "2.5.0"
319
405
  }) : await this.ipc.call("getInitConfig");
320
- return this.latestHostAdapterVersion = K(t), r;
406
+ return this.latestHostAdapterVersion = se(t), r;
321
407
  }
322
408
  getHostAdapterVersion() {
323
409
  return this.latestHostAdapterVersion;
@@ -334,8 +420,15 @@ var q = class {
334
420
  async selectContent(e, t = null) {
335
421
  await this.ipc.call("selectContent", e, t);
336
422
  }
337
- async replaceMultipleContents(e) {
338
- await this.ipc.call("replaceMultipleContents", e);
423
+ async replaceMultipleContents(e, t) {
424
+ const { onProgress: r, ...n } = t ?? {};
425
+ await this.ipc.callWithOptions("replaceMultipleContents", {
426
+ ...n,
427
+ ...r && { onProgress: (i) => {
428
+ const a = ne(i, e);
429
+ a && r(a);
430
+ } }
431
+ }, e);
339
432
  }
340
433
  async onAgenticAgentResults(e, t, r = null) {
341
434
  await this.ipc.call("onAgenticAgentResults", e, t, r);
@@ -355,6 +448,9 @@ var q = class {
355
448
  async copyToClipboard(e) {
356
449
  await this.ipc.call("copyToClipboard", e);
357
450
  }
451
+ async addComment(e, t = null) {
452
+ await this.ipc.call("addComment", e, t);
453
+ }
358
454
  async onIntegrationSettingsChange(e, t) {
359
455
  await this.ipc.call("onIntegrationSettingsChange", e, t);
360
456
  }
@@ -377,10 +473,10 @@ var q = class {
377
473
  destroy() {
378
474
  window.removeEventListener("message", this.handleMessage), this.ipc.destroy();
379
475
  }
380
- }, we = class {
476
+ }, ke = class {
381
477
  ipcAdapter;
382
478
  constructor(e, t, r) {
383
- this.ipcAdapter = new q(e, t, r);
479
+ this.ipcAdapter = new oe(e, t, r);
384
480
  }
385
481
  destroy() {
386
482
  this.ipcAdapter.destroy();
@@ -403,8 +499,8 @@ var q = class {
403
499
  async selectContent(e, t = null) {
404
500
  await this.ipcAdapter.selectContent(e, t);
405
501
  }
406
- async replaceMultipleContents(e) {
407
- await this.ipcAdapter.replaceMultipleContents(e);
502
+ async replaceMultipleContents(e, t) {
503
+ await this.ipcAdapter.replaceMultipleContents(e, t);
408
504
  }
409
505
  onAgenticAgentResults(e, t, r = null) {
410
506
  return this.ipcAdapter.onAgenticAgentResults(e, t, r);
@@ -424,6 +520,9 @@ var q = class {
424
520
  copyToClipboard(e) {
425
521
  return this.ipcAdapter.copyToClipboard(e);
426
522
  }
523
+ addComment(e, t = null) {
524
+ return this.ipcAdapter.addComment(e, t);
525
+ }
427
526
  onIntegrationSettingsChange(e, t) {
428
527
  return this.ipcAdapter.onIntegrationSettingsChange(e, t);
429
528
  }
@@ -436,7 +535,7 @@ var q = class {
436
535
  getTargetOrigin() {
437
536
  return this.ipcAdapter.getTargetOrigin();
438
537
  }
439
- }, Z = class {
538
+ }, le = class {
440
539
  ipc;
441
540
  plugin;
442
541
  iframe;
@@ -444,7 +543,7 @@ var q = class {
444
543
  targetOrigin;
445
544
  latestSidebarBuildInfo = null;
446
545
  constructor(e, t, r, n, i = "*") {
447
- this.plugin = e, this.iframe = t, this.window = r ?? window, this.targetOrigin = i, this.ipc = new N((a) => {
546
+ this.plugin = e, this.iframe = t, this.window = r ?? window, this.targetOrigin = i, this.ipc = new F((a) => {
448
547
  this.iframe.contentWindow?.postMessage(a, this.targetOrigin);
449
548
  }, n), this.window.addEventListener("message", this.handleMessage, !1), this.registerReceivers();
450
549
  }
@@ -454,17 +553,17 @@ var q = class {
454
553
  };
455
554
  registerReceivers() {
456
555
  if (this.ipc.receive("getInitConfig", async (e) => {
457
- const t = X(e);
556
+ const t = ae(e);
458
557
  return this.latestSidebarBuildInfo = t, {
459
558
  ...await this.plugin.getInitConfig(t ?? void 0),
460
- hostAdapterVersion: V
559
+ hostAdapterVersion: Y
461
560
  };
462
561
  }), this.ipc.receive("getContent", async () => await this.plugin.getContent()), this.ipc.receive("getSelectedContent", async () => await this.plugin.getSelectedContent()), this.ipc.receive("replaceContent", async (e, t, r) => {
463
562
  await this.plugin.replaceContent(e, t, typeof r == "string" ? r : null);
464
563
  }), this.ipc.receive("selectContent", async (e, t) => {
465
564
  await this.plugin.selectContent(e, typeof t == "string" ? t : null);
466
- }), this.ipc.receive("replaceMultipleContents", async (e) => {
467
- await this.plugin.replaceMultipleContents(e);
565
+ }), this.ipc.receiveWithProgress("replaceMultipleContents", async (e, t) => {
566
+ await this.plugin.replaceMultipleContents(t, { reportProgress: e });
468
567
  }), this.ipc.receive("onAgenticAgentResults", async (e, t, r) => {
469
568
  if (!Array.isArray(t))
470
569
  return;
@@ -499,6 +598,12 @@ var q = class {
499
598
  await e(t);
500
599
  });
501
600
  }
601
+ if (this.plugin.addComment) {
602
+ const e = this.plugin.addComment;
603
+ this.ipc.receive("addComment", async (t, r) => {
604
+ await e(t, typeof r == "string" ? r : null);
605
+ });
606
+ }
502
607
  if (this.plugin.onIntegrationSettingsChange) {
503
608
  const e = this.plugin.onIntegrationSettingsChange;
504
609
  this.ipc.receive("onIntegrationSettingsChange", async (t, r) => {
@@ -539,10 +644,10 @@ var q = class {
539
644
  destroy() {
540
645
  this.window.removeEventListener("message", this.handleMessage), this.ipc.destroy();
541
646
  }
542
- }, Q = class {
647
+ }, ce = class {
543
648
  ipcAdapter;
544
649
  constructor(e, t, r) {
545
- this.ipcAdapter = new Z(e, t, r?.win, r?.config, r?.targetOrigin);
650
+ this.ipcAdapter = new le(e, t, r?.win, r?.config, r?.targetOrigin);
546
651
  }
547
652
  destroy() {
548
653
  this.ipcAdapter.destroy();
@@ -577,7 +682,7 @@ var q = class {
577
682
  configure(e) {
578
683
  this.ipcAdapter.configure(e);
579
684
  }
580
- }, ee = `
685
+ }, de = `
581
686
  <div class="sidebar-load-overlay-card">
582
687
  <div class="sidebar-load-overlay-title">Sidebar failed to load</div>
583
688
  <div class="sidebar-load-overlay-description">Check your connection or try again.</div>
@@ -598,16 +703,16 @@ var q = class {
598
703
  <span>Retry</span>
599
704
  </button>
600
705
  </div>
601
- `, te = () => {
706
+ `, ge = () => {
602
707
  const e = document.createElement("div");
603
- e.className = "sidebar-load-overlay", e.style.display = "none", e.innerHTML = ee;
708
+ e.className = "sidebar-load-overlay", e.style.display = "none", e.innerHTML = de;
604
709
  const t = e.querySelector(".sidebar-load-overlay-button");
605
710
  if (!t) throw new Error("Missing retry button in load overlay template.");
606
711
  return {
607
712
  overlay: e,
608
713
  button: t
609
714
  };
610
- }, T = "markupai-sidebar-load-overlay-styles", re = `
715
+ }, M = "markupai-sidebar-load-overlay-styles", pe = `
611
716
  :root {
612
717
  --background: #f5f5f4;
613
718
  --foreground: #333332;
@@ -699,68 +804,68 @@ var q = class {
699
804
  box-shadow: 0 0 0 2px
700
805
  color-mix(in srgb, var(--accent, #ef4640) 60%, transparent);
701
806
  }
702
- `, ne = (e) => {
807
+ `, ue = (e) => {
703
808
  const t = e ?? document;
704
- if (t.getElementById(T)) return;
809
+ if (t.getElementById(M)) return;
705
810
  const r = t.createElement("style");
706
- r.id = T, r.textContent = re, t.head.appendChild(r);
707
- }, ie = 8e3, ae = 12e3, oe = (e, t, r = {}) => {
708
- ne(e.ownerDocument);
709
- const { sidebarUrl: n, targetOrigin: i, timeoutMs: a = ie, retryIntervalMs: o = ae, messageListenWindow: s } = r, l = s ?? (typeof globalThis.window < "u" ? globalThis.window : globalThis), p = () => n ?? t.src, j = () => {
811
+ r.id = M, r.textContent = pe, t.head.appendChild(r);
812
+ }, he = 8e3, fe = 12e3, me = (e, t, r = {}) => {
813
+ ue(e.ownerDocument);
814
+ const { sidebarUrl: n, targetOrigin: i, timeoutMs: a = he, retryIntervalMs: s = fe, messageListenWindow: o } = r, l = o ?? (typeof globalThis.window < "u" ? globalThis.window : globalThis), c = () => n ?? t.src, G = () => {
710
815
  if (i) return i;
711
816
  try {
712
- return new URL(p()).origin;
817
+ return new URL(c()).origin;
713
818
  } catch {
714
819
  return "*";
715
820
  }
716
- }, { overlay: y, button: A } = te();
821
+ }, { overlay: y, button: C } = ge();
717
822
  e.appendChild(y);
718
- let u = !1, h, d;
719
- const g = (c) => {
720
- y.style.display = c ? "flex" : "none";
823
+ let u = !1, h, g;
824
+ const p = (d) => {
825
+ y.style.display = d ? "flex" : "none";
721
826
  };
722
- g(!1);
827
+ p(!1);
723
828
  const f = () => {
724
829
  h && (globalThis.clearTimeout(h), h = void 0);
725
- }, C = () => {
830
+ }, b = () => {
726
831
  f(), h = globalThis.setTimeout(() => {
727
- u || g(!0);
832
+ u || p(!0);
728
833
  }, a);
729
- }, b = (c) => {
730
- const m = c?.preserveOverlay ?? !0;
731
- u = !1, m || g(!1), t.src = p(), C();
732
- }, F = () => {
733
- d || o <= 0 || (d = globalThis.setInterval(() => {
734
- u || b({ preserveOverlay: !0 });
735
- }, o));
736
- }, S = () => {
737
- d && (globalThis.clearInterval(d), d = void 0);
738
- }, w = (c) => {
739
- if (!t.contentWindow || c.source !== t.contentWindow) return;
740
- const m = j();
741
- m !== "*" && c.origin !== m || (u = !0, f(), S(), g(!1));
742
- }, P = () => {
743
- f(), g(!0);
834
+ }, S = (d) => {
835
+ const m = d?.preserveOverlay ?? !0;
836
+ u = !1, m || p(!1), t.src = c(), b();
837
+ }, J = () => {
838
+ g || s <= 0 || (g = globalThis.setInterval(() => {
839
+ u || S({ preserveOverlay: !0 });
840
+ }, s));
841
+ }, w = () => {
842
+ g && (globalThis.clearInterval(g), g = void 0);
843
+ }, P = (d) => {
844
+ if (!t.contentWindow || d.source !== t.contentWindow) return;
845
+ const m = G();
846
+ m !== "*" && d.origin !== m || (u = !0, f(), w(), p(!1));
744
847
  }, E = () => {
745
- b();
848
+ f(), p(!0);
849
+ }, R = () => {
850
+ S();
746
851
  };
747
- return A.addEventListener("click", E), t.addEventListener("error", P), l.addEventListener("message", w), C(), F(), () => {
748
- f(), S(), t.removeEventListener("error", P), l.removeEventListener("message", w), A.removeEventListener("click", E), y.remove();
852
+ return C.addEventListener("click", R), t.addEventListener("error", E), l.addEventListener("message", P), b(), J(), () => {
853
+ f(), w(), t.removeEventListener("error", E), l.removeEventListener("message", P), C.removeEventListener("click", R), y.remove();
749
854
  };
750
- }, se = "Markup AI Sidebar", le = "clipboard-read; clipboard-write", Pe = "markupai.sidebarNextGen.overrideUrl", Ee = "https://sidebar.markup.ai/";
751
- function Re(e) {
855
+ }, ye = "Markup AI Sidebar", Ie = "clipboard-read; clipboard-write", Ne = "markupai.sidebarNextGen.overrideUrl", Be = "https://sidebar.markup.ai/";
856
+ function Ue(e) {
752
857
  try {
753
858
  return "localStorage" in globalThis && globalThis.localStorage.getItem("markupai.sidebarNextGen.overrideUrl")?.trim() || e;
754
859
  } catch {
755
860
  return e;
756
861
  }
757
862
  }
758
- var ce = "markupai.sidebarNextGen.authOverride";
759
- function Oe(e, t) {
863
+ var ve = "markupai.sidebarNextGen.authOverride";
864
+ function He(e, t) {
760
865
  if (!t) return e;
761
866
  try {
762
867
  if (!("localStorage" in globalThis)) return e;
763
- const r = globalThis.localStorage.getItem(ce)?.trim();
868
+ const r = globalThis.localStorage.getItem(ve)?.trim();
764
869
  if (!r) return e;
765
870
  const n = JSON.parse(r);
766
871
  return n !== null && typeof n == "object" && "type" in n && (n.type === "mediation" || n.type === "popup") ? n : e;
@@ -768,17 +873,17 @@ function Oe(e, t) {
768
873
  return e;
769
874
  }
770
875
  }
771
- function Te(e, t) {
876
+ function $e(e, t) {
772
877
  try {
773
878
  return new URL(e).origin;
774
879
  } catch (r) {
775
880
  return t?.onInvalidUrl?.(e, r), "*";
776
881
  }
777
882
  }
778
- function De(e, t = "Expected SidebarAdapter from createSidebarHost") {
883
+ function je(e, t = "Expected SidebarAdapter from createSidebarHost") {
779
884
  if (e.adapter === null) throw new Error(t);
780
885
  }
781
- function de(e) {
886
+ function Ae(e) {
782
887
  const { iframe: t, iframeMount: r } = e;
783
888
  if (t !== void 0 && r !== void 0) throw new Error("createSidebarHost: pass only one of `iframe` or `iframeMount`");
784
889
  if (t !== void 0) return {
@@ -786,23 +891,23 @@ function de(e) {
786
891
  removeMountedIframe: null
787
892
  };
788
893
  if (r === void 0) throw new Error("createSidebarHost: pass either `iframe` or `iframeMount`");
789
- const { container: n, src: i, allow: a = le } = r, o = document.createElement("iframe");
790
- return o.title = se, o.src = i, a && o.setAttribute("allow", a), n.appendChild(o), {
791
- iframe: o,
894
+ const { container: n, src: i, allow: a = Ie } = r, s = document.createElement("iframe");
895
+ return s.title = ye, s.src = i, a && s.setAttribute("allow", a), n.appendChild(s), {
896
+ iframe: s,
792
897
  removeMountedIframe: () => {
793
- o.remove();
898
+ s.remove();
794
899
  }
795
900
  };
796
901
  }
797
- function xe(e) {
798
- const { plugin: t, loadOverlayContainer: r, loadOverlayOptions: n, adapterOptions: i } = e, { iframe: a, removeMountedIframe: o } = de(e), s = r !== void 0 ? oe(r, a, n ?? {}) : null;
902
+ function Fe(e) {
903
+ const { plugin: t, loadOverlayContainer: r, loadOverlayOptions: n, adapterOptions: i } = e, { iframe: a, removeMountedIframe: s } = Ae(e), o = r !== void 0 ? me(r, a, n ?? {}) : null;
799
904
  if (t !== void 0) {
800
- const l = new Q(t, a, i);
905
+ const l = new ce(t, a, i);
801
906
  return {
802
907
  iframe: a,
803
908
  adapter: l,
804
909
  destroy: () => {
805
- s?.(), l.destroy(), o?.();
910
+ o?.(), l.destroy(), s?.();
806
911
  }
807
912
  };
808
913
  }
@@ -810,18 +915,18 @@ function xe(e) {
810
915
  iframe: a,
811
916
  adapter: null,
812
917
  destroy: () => {
813
- s?.(), o?.();
918
+ o?.(), s?.();
814
919
  }
815
920
  };
816
921
  }
817
- var H = "sidebarContainer", D = "markupai-sidebar-host-shell-styles";
818
- function U(e) {
922
+ var V = "sidebarContainer", x = "markupai-sidebar-host-shell-styles";
923
+ function W(e) {
819
924
  if (typeof CSS < "u" && typeof CSS.escape == "function") return CSS.escape(e);
820
925
  if (!/^[a-zA-Z_][\w-]*$/.test(e)) throw new Error(String.raw`sidebar host shell: containerId must match /^[a-zA-Z_][\w-]*$/ when CSS.escape is unavailable (got ${JSON.stringify(e)})`);
821
926
  return e;
822
927
  }
823
- function $(e = H) {
824
- const t = U(e);
928
+ function z(e = V) {
929
+ const t = W(e);
825
930
  return `
826
931
  html {
827
932
  height: 100%;
@@ -846,89 +951,93 @@ body {
846
951
  }
847
952
  `.trim();
848
953
  }
849
- var Me = $();
850
- function ge(e) {
954
+ var Ve = z();
955
+ function Ce(e) {
851
956
  return e instanceof Document ? e : e.ownerDocument;
852
957
  }
853
- function pe(e, t, r) {
854
- if (!t || e.getElementById(D)) return;
958
+ function be(e, t, r) {
959
+ if (!t || e.getElementById(x)) return;
855
960
  const n = e.createElement("style");
856
- n.id = D, n.textContent = $(r), e.head.appendChild(n);
961
+ n.id = x, n.textContent = z(r), e.head.appendChild(n);
857
962
  }
858
- function _e(e) {
859
- const { root: t = typeof document < "u" ? document : void 0, containerId: r = H, includeDefaultStyles: n = !0 } = e ?? {};
963
+ function We(e) {
964
+ const { root: t = typeof document < "u" ? document : void 0, containerId: r = V, includeDefaultStyles: n = !0 } = e ?? {};
860
965
  if (t === void 0) throw new Error("ensureSidebarHostShell: no document — pass `root` in non-browser environments");
861
- const i = ge(t);
862
- pe(i, n, r);
863
- const a = t instanceof Document ? i.getElementById(r) : t.querySelector(`#${U(r)}`);
966
+ const i = Ce(t);
967
+ be(i, n, r);
968
+ const a = t instanceof Document ? i.getElementById(r) : t.querySelector(`#${W(r)}`);
864
969
  if (a instanceof HTMLElement && (t instanceof Document || t.contains(a))) return a;
865
970
  if (!(t instanceof Document)) {
866
- const s = i.createElement("div");
867
- return s.id = r, t.appendChild(s), s;
971
+ const o = i.createElement("div");
972
+ return o.id = r, t.appendChild(o), o;
868
973
  }
869
- const o = i.createElement("div");
870
- return o.id = r, i.body.appendChild(o), o;
974
+ const s = i.createElement("div");
975
+ return s.id = r, i.body.appendChild(s), s;
871
976
  }
872
- function ue() {
977
+ function Se() {
873
978
  return ' <meta name="viewport" content="width=device-width, initial-scale=1.0" />';
874
979
  }
875
- function Le(e) {
876
- const { title: t = "Markup AI Sidebar", headInnerHtml: r = "", includePluginHostHead: n = !1, bodyScriptsHtml: i, htmlLang: a = "en", htmlAttrs: o = `lang="${a}" style="height:100%"`, bodyAttrs: s = 'style="height:100%;margin:0"' } = e, l = [n ? ue() : "", r].filter((p) => p.trim().length > 0).join(`
980
+ function ze(e) {
981
+ const { title: t = "Markup AI Sidebar", headInnerHtml: r = "", includePluginHostHead: n = !1, bodyScriptsHtml: i, htmlLang: a = "en", htmlAttrs: s = `lang="${a}" style="height:100%"`, bodyAttrs: o = 'style="height:100%;margin:0"' } = e, l = [n ? Se() : "", r].filter((c) => c.trim().length > 0).join(`
877
982
  `);
878
983
  return `<!DOCTYPE html>
879
- <html ${o}>
984
+ <html ${s}>
880
985
  <head>
881
986
  <base target="_top" />
882
987
  <meta charset="UTF-8" />
883
- <title>${he(t)}</title>${l ? `
988
+ <title>${we(t)}</title>${l ? `
884
989
  ${l}` : ""}
885
990
  </head>
886
- <body ${s}>
991
+ <body ${o}>
887
992
  ${i}
888
993
  </body>
889
994
  </html>
890
995
  `;
891
996
  }
892
- function he(e) {
997
+ function we(e) {
893
998
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
894
999
  }
895
1000
  export {
896
- V as ADAPTER_VERSION,
897
- ce as AUTH_CONFIG_OVERRIDE_STORAGE_KEY,
898
- G as DEFAULT_IPC_CONFIG,
899
- ye as DEFAULT_SIDEBAR_CONFIG,
900
- W as DeferredPromise,
901
- N as IPCCore,
902
- fe as MimeType,
903
- we as PluginAdapter,
904
- q as PluginIPCAdapter,
905
- M as ReplaceBatchError,
906
- Ee as SIDEBAR_DEFAULT_PRODUCTION_BASE_URL,
907
- H as SIDEBAR_HOST_CONTAINER_ID,
908
- Me as SIDEBAR_HOST_SHELL_CSS,
909
- le as SIDEBAR_IFRAME_DEFAULT_ALLOW,
910
- se as SIDEBAR_IFRAME_DEFAULT_TITLE,
911
- Pe as SIDEBAR_URL_OVERRIDE_STORAGE_KEY,
912
- Q as SidebarAdapter,
913
- Z as SidebarIPCAdapter,
914
- me as TEXT_MIME_TYPES,
915
- v as TextLookupError,
916
- De as assertSidebarHostAdapter,
917
- Se as buildDocumentReference,
918
- Le as buildSidebarHostHtmlDocument,
919
- $ as buildSidebarHostShellCss,
920
- ue as buildSidebarPluginHostHeadInnerHtml,
921
- xe as createSidebarHost,
922
- _e as ensureSidebarHostShell,
923
- Oe as getAuthConfigWithOverride,
924
- Re as getSidebarBaseUrlWithOverride,
925
- O as ipcErrorReconstructors,
926
- be as isDocumentReference,
927
- ve as isIntegrationSettingField,
928
- Ie as isIntegrationSettingsSchema,
929
- Ae as isReplaceBatchError,
930
- Ce as isTextLookupError,
931
- z as reconstructError,
932
- oe as setupSidebarLoadOverlay,
933
- Te as sidebarPostMessageTargetOrigin
1001
+ Y as ADAPTER_VERSION,
1002
+ ve as AUTH_CONFIG_OVERRIDE_STORAGE_KEY,
1003
+ j as DEFAULT_IPC_CONFIG,
1004
+ Re as DEFAULT_SIDEBAR_CONFIG,
1005
+ K as DeferredPromise,
1006
+ F as IPCCore,
1007
+ N as IpcTimeoutError,
1008
+ Q as LATE_RESULT_WINDOW_MS,
1009
+ ee as MAX_IPC_TIMEOUT_MS,
1010
+ Pe as MimeType,
1011
+ ke as PluginAdapter,
1012
+ oe as PluginIPCAdapter,
1013
+ L as ReplaceBatchError,
1014
+ Be as SIDEBAR_DEFAULT_PRODUCTION_BASE_URL,
1015
+ V as SIDEBAR_HOST_CONTAINER_ID,
1016
+ Ve as SIDEBAR_HOST_SHELL_CSS,
1017
+ Ie as SIDEBAR_IFRAME_DEFAULT_ALLOW,
1018
+ ye as SIDEBAR_IFRAME_DEFAULT_TITLE,
1019
+ Ne as SIDEBAR_URL_OVERRIDE_STORAGE_KEY,
1020
+ ce as SidebarAdapter,
1021
+ le as SidebarIPCAdapter,
1022
+ Ee as TEXT_MIME_TYPES,
1023
+ A as TextLookupError,
1024
+ je as assertSidebarHostAdapter,
1025
+ Le as buildDocumentReference,
1026
+ ze as buildSidebarHostHtmlDocument,
1027
+ z as buildSidebarHostShellCss,
1028
+ Se as buildSidebarPluginHostHeadInnerHtml,
1029
+ Fe as createSidebarHost,
1030
+ We as ensureSidebarHostShell,
1031
+ He as getAuthConfigWithOverride,
1032
+ Ue as getSidebarBaseUrlWithOverride,
1033
+ T as ipcErrorReconstructors,
1034
+ _e as isDocumentReference,
1035
+ Te as isIntegrationSettingField,
1036
+ Oe as isIntegrationSettingsSchema,
1037
+ De as isIpcTimeoutError,
1038
+ Me as isReplaceBatchError,
1039
+ xe as isTextLookupError,
1040
+ X as reconstructError,
1041
+ me as setupSidebarLoadOverlay,
1042
+ $e as sidebarPostMessageTargetOrigin
934
1043
  };