@markupai/sidebar-adapter 2.2.0 → 2.3.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.
package/dist/main.js CHANGED
@@ -1,11 +1,11 @@
1
- var ge = /* @__PURE__ */ (function(e) {
1
+ var fe = /* @__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
- })({}), pe = [
3
+ })({}), me = [
4
4
  "text/plain",
5
5
  "text/markdown",
6
6
  "text/html",
7
7
  "application/dita+xml"
8
- ], ue = {
8
+ ], ye = {
9
9
  integrationName: "unknown",
10
10
  integrationVersion: "unknown",
11
11
  integrationId: "markupai-sidebar-app",
@@ -13,41 +13,80 @@ var ge = /* @__PURE__ */ (function(e) {
13
13
  supportCheckSelection: !0,
14
14
  multiAgent: !1,
15
15
  multiDocument: !1
16
- }, he = (e) => typeof e != "object" || e === null ? !1 : Array.isArray(e.fields), fe = (e) => {
16
+ }, Ie = (e) => typeof e != "object" || e === null ? !1 : Array.isArray(e.fields), ve = (e) => {
17
17
  if (typeof e != "object" || e === null) return !1;
18
18
  const t = e;
19
- 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((n) => {
20
- if (typeof n != "object" || n === null) return !1;
21
- const r = n;
22
- return typeof r.value == "string" && typeof r.label == "string";
19
+ 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) => {
20
+ if (typeof r != "object" || r === null) return !1;
21
+ const n = r;
22
+ return typeof n.value == "string" && typeof n.label == "string";
23
23
  }) : !1;
24
- }, U = "2.2.0", O = class D extends Error {
24
+ }, V = "2.3.0", v = class x extends Error {
25
25
  name = "TextLookupError";
26
26
  constructor(t) {
27
- super(t), Object.setPrototypeOf(this, D.prototype);
27
+ super(t), Object.setPrototypeOf(this, x.prototype);
28
+ }
29
+ }, M = class _ extends v {
30
+ name = "ReplaceBatchError";
31
+ applied;
32
+ failed;
33
+ constructor(t, r) {
34
+ super(t), this.applied = r.applied.map((n) => ({
35
+ start: n.start,
36
+ end: n.end
37
+ })), this.failed = r.failed.map((n) => L(n, n.message)), Object.setPrototypeOf(this, _.prototype);
28
38
  }
29
39
  };
30
- function me(e) {
31
- return e instanceof O;
32
- }
33
- var E = { TextLookupError: (e) => new O(e) };
34
- function $(e) {
35
- const t = e.message ?? "", n = e.name, r = typeof n == "string" && n in E ? E[n] : void 0;
36
- return r ? r(t, e) : Object.assign(new Error(t), n ? { name: n } : {});
37
- }
38
- var x = ":", M = /^[a-z][a-z0-9-]*$/;
39
- function ye(e) {
40
- const t = e.indexOf(x);
41
- return t <= 0 || t === e.length - 1 ? !1 : M.test(e.slice(0, t));
42
- }
43
- function Ie(e, t) {
44
- const n = e.trim().toLowerCase(), r = t.trim();
45
- if (!M.test(n)) throw new Error(`Invalid document reference prefix ${JSON.stringify(e)}: expected a lowercase name like "word".`);
46
- if (r.length === 0) throw new Error("Invalid document reference: the document id is empty.");
47
- const i = `${n}${x}`;
48
- return r.startsWith(i) ? r : `${i}${r}`;
49
- }
50
- var j = class extends Promise {
40
+ function Ae(e) {
41
+ return e instanceof M;
42
+ }
43
+ function L(e, t) {
44
+ const r = {
45
+ start: e.start,
46
+ end: e.end
47
+ };
48
+ return typeof t == "string" && t.trim() !== "" && (r.message = t), r;
49
+ }
50
+ function R(e) {
51
+ return Array.isArray(e) ? e.flatMap((t) => {
52
+ if (t === null || typeof t != "object") return [];
53
+ const { start: r, end: n, message: i } = t;
54
+ return typeof r != "number" || typeof n != "number" ? [] : [{
55
+ range: {
56
+ start: r,
57
+ end: n
58
+ },
59
+ message: i
60
+ }];
61
+ }) : [];
62
+ }
63
+ function Ce(e) {
64
+ return e instanceof v;
65
+ }
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))
71
+ })
72
+ };
73
+ function z(e) {
74
+ const t = e.message ?? "", r = e.name, n = typeof r == "string" && r in O ? O[r] : void 0;
75
+ return n ? n(t, e) : Object.assign(new Error(t), r ? { name: r } : {});
76
+ }
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));
81
+ }
82
+ function Se(e, t) {
83
+ 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".`);
85
+ if (n.length === 0) throw new Error("Invalid document reference: the document id is empty.");
86
+ const i = `${r}${k}`;
87
+ return n.startsWith(i) ? n : `${i}${n}`;
88
+ }
89
+ var W = class extends Promise {
51
90
  static get [Symbol.species]() {
52
91
  return Promise;
53
92
  }
@@ -55,21 +94,21 @@ var j = class extends Promise {
55
94
  reject;
56
95
  constructor(e = () => {
57
96
  }) {
58
- let t, n;
59
- super((r, i) => {
60
- t = r, n = i, e(r, i);
61
- }), this.resolve = t, this.reject = n;
62
- }
63
- }, V = { timeout: 1e4 };
64
- function F(e) {
65
- const t = typeof e == "object" && e !== null ? JSON.parse(JSON.stringify(e, Object.getOwnPropertyNames(e))) : {}, n = e instanceof Error ? e.message : String(e), r = typeof t.message == "string" && t.message !== "" ? t.message : n, i = e instanceof Error ? e.name : void 0, a = typeof t.name == "string" ? t.name : i;
97
+ let t, r;
98
+ super((n, i) => {
99
+ t = n, r = i, e(n, i);
100
+ }), this.resolve = t, this.reject = r;
101
+ }
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;
66
105
  return JSON.stringify({
67
106
  ...t,
68
- message: r,
107
+ message: n,
69
108
  ...a !== void 0 && { name: a }
70
109
  });
71
110
  }
72
- var _ = class {
111
+ var N = class {
73
112
  promisesByID = {};
74
113
  receiversByName = {};
75
114
  currentID = 0;
@@ -77,7 +116,7 @@ var _ = class {
77
116
  postMessage;
78
117
  constructor(e, t) {
79
118
  this.postMessage = e, this.config = {
80
- ...V,
119
+ ...G,
81
120
  ...t
82
121
  };
83
122
  }
@@ -90,22 +129,22 @@ var _ = class {
90
129
  call(e, ...t) {
91
130
  return this.callWithOptions(e, {}, ...t);
92
131
  }
93
- callWithOptions(e, t, ...n) {
94
- const r = this.currentID++, i = new j(), a = t.timeout ?? this.config.timeout, o = setTimeout(() => {
95
- if (r in this.promisesByID) {
132
+ 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) {
96
135
  const l = /* @__PURE__ */ new Error(`IPC call timeout: "${e}" did not respond within ${String(a)}ms`);
97
- i.reject(l), Reflect.deleteProperty(this.promisesByID, r);
136
+ i.reject(l), Reflect.deleteProperty(this.promisesByID, n);
98
137
  }
99
138
  }, a);
100
- this.promisesByID[r] = {
139
+ this.promisesByID[n] = {
101
140
  promise: i,
102
141
  timeoutId: o
103
142
  };
104
143
  const s = {
105
144
  type: "call",
106
- id: r,
145
+ id: n,
107
146
  name: e,
108
- data: n
147
+ data: r
109
148
  };
110
149
  return this.postMessage(s), i;
111
150
  }
@@ -130,27 +169,27 @@ var _ = class {
130
169
  }
131
170
  }
132
171
  async handleCall(e) {
133
- const { id: t, name: n, data: r } = e;
134
- if (!(n in this.receiversByName)) {
135
- const a = /* @__PURE__ */ new Error(`No receiver registered for: ${n}`), o = JSON.stringify({
172
+ const { id: t, name: r, data: n } = e;
173
+ if (!(r in this.receiversByName)) {
174
+ const a = /* @__PURE__ */ new Error(`No receiver registered for: ${r}`), o = JSON.stringify({
136
175
  message: a.message,
137
176
  name: a.name
138
177
  });
139
178
  this.postMessage({
140
179
  type: "error",
141
180
  id: t,
142
- name: n,
181
+ name: r,
143
182
  errorJSON: o
144
183
  });
145
184
  return;
146
185
  }
147
- const i = this.receiversByName[n];
186
+ const i = this.receiversByName[r];
148
187
  try {
149
- if (!Array.isArray(r)) throw new TypeError(`IPC: Expected array of arguments but got ${typeof r}`);
150
- const a = await i(...r), o = {
188
+ if (!Array.isArray(n)) throw new TypeError(`IPC: Expected array of arguments but got ${typeof n}`);
189
+ const a = await i(...n), o = {
151
190
  type: "response",
152
191
  id: t,
153
- name: n,
192
+ name: r,
154
193
  data: a
155
194
  };
156
195
  this.postMessage(o);
@@ -158,8 +197,8 @@ var _ = class {
158
197
  const o = {
159
198
  type: "error",
160
199
  id: t,
161
- name: n,
162
- errorJSON: F(a)
200
+ name: r,
201
+ errorJSON: J(a)
163
202
  };
164
203
  this.postMessage(o);
165
204
  }
@@ -167,20 +206,20 @@ var _ = class {
167
206
  handleResponse(e) {
168
207
  const { id: t } = e;
169
208
  if (t in this.promisesByID) {
170
- const { promise: n, timeoutId: r } = this.promisesByID[t];
171
- clearTimeout(r), n.resolve(e.data), Reflect.deleteProperty(this.promisesByID, t);
209
+ const { promise: r, timeoutId: n } = this.promisesByID[t];
210
+ clearTimeout(n), r.resolve(e.data), Reflect.deleteProperty(this.promisesByID, t);
172
211
  }
173
212
  }
174
213
  handleError(e) {
175
- const { id: t, errorJSON: n } = e;
214
+ const { id: t, errorJSON: r } = e;
176
215
  if (t in this.promisesByID) {
177
- const { promise: r, timeoutId: i } = this.promisesByID[t];
216
+ const { promise: n, timeoutId: i } = this.promisesByID[t];
178
217
  clearTimeout(i);
179
218
  try {
180
- const a = JSON.parse(n), o = $(a);
181
- r.reject(o);
219
+ const a = JSON.parse(r), o = z(a);
220
+ n.reject(o);
182
221
  } catch {
183
- r.reject(/* @__PURE__ */ new Error("Failed to parse error from IPC"));
222
+ n.reject(/* @__PURE__ */ new Error("Failed to parse error from IPC"));
184
223
  }
185
224
  Reflect.deleteProperty(this.promisesByID, t);
186
225
  }
@@ -191,51 +230,51 @@ var _ = class {
191
230
  this.promisesByID = {}, this.receiversByName = {};
192
231
  }
193
232
  };
194
- var z = /* @__PURE__ */ new Set(["auto", "prompt"]), I = (e, t) => {
195
- const n = e[t];
196
- if (!(typeof n != "string" || n.length === 0))
197
- return n.slice(0, 64);
233
+ var Y = /* @__PURE__ */ new Set(["auto", "prompt"]), I = (e, t) => {
234
+ const r = e[t];
235
+ if (!(typeof r != "string" || r.length === 0))
236
+ return r.slice(0, 64);
198
237
  };
199
- function W(e) {
238
+ function X(e) {
200
239
  if (typeof e != "object" || e === null || Array.isArray(e)) return null;
201
- const t = e, n = I(t, "version"), r = I(t, "commitHash");
202
- if (n === void 0 || r === void 0) return null;
240
+ const t = e, r = I(t, "version"), n = I(t, "commitHash");
241
+ if (r === void 0 || n === void 0) return null;
203
242
  const i = {
204
- version: n,
205
- commitHash: r
243
+ version: r,
244
+ commitHash: n
206
245
  };
207
- typeof t.swControlled == "boolean" && (i.swControlled = t.swControlled), z.has(t.pwaUpdateMode) && (i.pwaUpdateMode = t.pwaUpdateMode);
246
+ typeof t.swControlled == "boolean" && (i.swControlled = t.swControlled), Y.has(t.pwaUpdateMode) && (i.pwaUpdateMode = t.pwaUpdateMode);
208
247
  const a = I(t, "adapterVersion");
209
248
  return a !== void 0 && (i.adapterVersion = a), i;
210
249
  }
211
- function G(e) {
250
+ function K(e) {
212
251
  return typeof e != "string" || e.length === 0 ? null : e.slice(0, 64);
213
252
  }
214
- var J = class {
253
+ var q = class {
215
254
  ipc;
216
255
  sidebar;
217
256
  targetOrigin;
218
257
  latestHostAdapterVersion = null;
219
- constructor(e, t, n = "*") {
220
- this.sidebar = e || {}, this.targetOrigin = n, this.ipc = new _((r) => {
221
- window.parent.postMessage(r, this.targetOrigin);
258
+ constructor(e, t, r = "*") {
259
+ this.sidebar = e || {}, this.targetOrigin = r, this.ipc = new N((n) => {
260
+ window.parent.postMessage(n, this.targetOrigin);
222
261
  }, t), window.addEventListener("message", this.handleMessage), this.registerReceivers();
223
262
  }
224
263
  handleMessage = (e) => {
225
- const t = globalThis.window.location.origin, n = this.targetOrigin;
226
- e.origin !== t && (n !== "*" && e.origin !== n || e.data && typeof e.data == "object" && this.ipc.handleMessage(e.data));
264
+ const t = globalThis.window.location.origin, r = this.targetOrigin;
265
+ e.origin !== t && (r !== "*" && e.origin !== r || e.data && typeof e.data == "object" && this.ipc.handleMessage(e.data));
227
266
  };
228
267
  registerReceivers() {
229
268
  if (this.sidebar.onPluginStatusChange) {
230
269
  const e = this.sidebar.onPluginStatusChange;
231
- this.ipc.receive("onPluginStatusChange", async (t, n) => {
232
- await e(t, n);
270
+ this.ipc.receive("onPluginStatusChange", async (t, r) => {
271
+ await e(t, r);
233
272
  });
234
273
  }
235
274
  if (this.sidebar.activateAgenticIssue) {
236
275
  const e = this.sidebar.activateAgenticIssue;
237
- this.ipc.receive("activateAgenticIssue", async (t, n) => {
238
- await e(t, typeof n == "string" ? n : null);
276
+ this.ipc.receive("activateAgenticIssue", async (t, r) => {
277
+ await e(t, typeof r == "string" ? r : null);
239
278
  });
240
279
  }
241
280
  if (this.sidebar.invalidateAgenticIssue) {
@@ -274,11 +313,11 @@ var J = class {
274
313
  }
275
314
  }
276
315
  async getInitConfig(e) {
277
- const { hostAdapterVersion: t, ...n } = e ? await this.ipc.call("getInitConfig", {
316
+ const { hostAdapterVersion: t, ...r } = e ? await this.ipc.call("getInitConfig", {
278
317
  ...e,
279
- adapterVersion: e.adapterVersion ?? "2.2.0"
318
+ adapterVersion: e.adapterVersion ?? "2.3.0"
280
319
  }) : await this.ipc.call("getInitConfig");
281
- return this.latestHostAdapterVersion = G(t), n;
320
+ return this.latestHostAdapterVersion = K(t), r;
282
321
  }
283
322
  getHostAdapterVersion() {
284
323
  return this.latestHostAdapterVersion;
@@ -289,8 +328,8 @@ var J = class {
289
328
  async getSelectedContent(e) {
290
329
  return this.ipc.callWithOptions("getSelectedContent", e ?? {});
291
330
  }
292
- async replaceContent(e, t, n = null) {
293
- await this.ipc.call("replaceContent", e, t, n);
331
+ async replaceContent(e, t, r = null) {
332
+ await this.ipc.call("replaceContent", e, t, r);
294
333
  }
295
334
  async selectContent(e, t = null) {
296
335
  await this.ipc.call("selectContent", e, t);
@@ -298,14 +337,14 @@ var J = class {
298
337
  async replaceMultipleContents(e) {
299
338
  await this.ipc.call("replaceMultipleContents", e);
300
339
  }
301
- async onAgenticAgentResults(e, t, n = null) {
302
- await this.ipc.call("onAgenticAgentResults", e, t, n);
340
+ async onAgenticAgentResults(e, t, r = null) {
341
+ await this.ipc.call("onAgenticAgentResults", e, t, r);
303
342
  }
304
343
  async onAgenticStreamComplete(e = null) {
305
344
  await this.ipc.call("onAgenticStreamComplete", e);
306
345
  }
307
- async onAgenticIssueStatusChanged(e, t, n) {
308
- await this.ipc.call("onAgenticIssueStatusChanged", e, t, n);
346
+ async onAgenticIssueStatusChanged(e, t, r) {
347
+ await this.ipc.call("onAgenticIssueStatusChanged", e, t, r);
309
348
  }
310
349
  async onAgenticIssuesCleared(e = null) {
311
350
  await this.ipc.call("onAgenticIssuesCleared", e);
@@ -338,10 +377,10 @@ var J = class {
338
377
  destroy() {
339
378
  window.removeEventListener("message", this.handleMessage), this.ipc.destroy();
340
379
  }
341
- }, ve = class {
380
+ }, we = class {
342
381
  ipcAdapter;
343
- constructor(e, t, n) {
344
- this.ipcAdapter = new J(e, t, n);
382
+ constructor(e, t, r) {
383
+ this.ipcAdapter = new q(e, t, r);
345
384
  }
346
385
  destroy() {
347
386
  this.ipcAdapter.destroy();
@@ -358,8 +397,8 @@ var J = class {
358
397
  async getSelectedContent(e) {
359
398
  return await this.ipcAdapter.getSelectedContent(e);
360
399
  }
361
- async replaceContent(e, t, n = null) {
362
- await this.ipcAdapter.replaceContent(e, t, n);
400
+ async replaceContent(e, t, r = null) {
401
+ await this.ipcAdapter.replaceContent(e, t, r);
363
402
  }
364
403
  async selectContent(e, t = null) {
365
404
  await this.ipcAdapter.selectContent(e, t);
@@ -367,14 +406,14 @@ var J = class {
367
406
  async replaceMultipleContents(e) {
368
407
  await this.ipcAdapter.replaceMultipleContents(e);
369
408
  }
370
- onAgenticAgentResults(e, t, n = null) {
371
- return this.ipcAdapter.onAgenticAgentResults(e, t, n);
409
+ onAgenticAgentResults(e, t, r = null) {
410
+ return this.ipcAdapter.onAgenticAgentResults(e, t, r);
372
411
  }
373
412
  onAgenticStreamComplete(e = null) {
374
413
  return this.ipcAdapter.onAgenticStreamComplete(e);
375
414
  }
376
- onAgenticIssueStatusChanged(e, t, n) {
377
- return this.ipcAdapter.onAgenticIssueStatusChanged(e, t, n);
415
+ onAgenticIssueStatusChanged(e, t, r) {
416
+ return this.ipcAdapter.onAgenticIssueStatusChanged(e, t, r);
378
417
  }
379
418
  onAgenticIssuesCleared(e = null) {
380
419
  return this.ipcAdapter.onAgenticIssuesCleared(e);
@@ -397,48 +436,48 @@ var J = class {
397
436
  getTargetOrigin() {
398
437
  return this.ipcAdapter.getTargetOrigin();
399
438
  }
400
- }, Y = class {
439
+ }, Z = class {
401
440
  ipc;
402
441
  plugin;
403
442
  iframe;
404
443
  window;
405
444
  targetOrigin;
406
445
  latestSidebarBuildInfo = null;
407
- constructor(e, t, n, r, i = "*") {
408
- this.plugin = e, this.iframe = t, this.window = n ?? window, this.targetOrigin = i, this.ipc = new _((a) => {
446
+ 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) => {
409
448
  this.iframe.contentWindow?.postMessage(a, this.targetOrigin);
410
- }, r), this.window.addEventListener("message", this.handleMessage, !1), this.registerReceivers();
449
+ }, n), this.window.addEventListener("message", this.handleMessage, !1), this.registerReceivers();
411
450
  }
412
451
  handleMessage = (e) => {
413
- const t = this.window.location.origin, n = this.targetOrigin;
414
- e.origin !== t && (n !== "*" && e.origin !== n || e.data && typeof e.data == "object" && this.ipc.handleMessage(e.data));
452
+ const t = this.window.location.origin, r = this.targetOrigin;
453
+ e.origin !== t && (r !== "*" && e.origin !== r || e.data && typeof e.data == "object" && this.ipc.handleMessage(e.data));
415
454
  };
416
455
  registerReceivers() {
417
456
  if (this.ipc.receive("getInitConfig", async (e) => {
418
- const t = W(e);
457
+ const t = X(e);
419
458
  return this.latestSidebarBuildInfo = t, {
420
459
  ...await this.plugin.getInitConfig(t ?? void 0),
421
- hostAdapterVersion: U
460
+ hostAdapterVersion: V
422
461
  };
423
- }), 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, n) => {
424
- await this.plugin.replaceContent(e, t, typeof n == "string" ? n : null);
462
+ }), 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
+ await this.plugin.replaceContent(e, t, typeof r == "string" ? r : null);
425
464
  }), this.ipc.receive("selectContent", async (e, t) => {
426
465
  await this.plugin.selectContent(e, typeof t == "string" ? t : null);
427
466
  }), this.ipc.receive("replaceMultipleContents", async (e) => {
428
467
  await this.plugin.replaceMultipleContents(e);
429
- }), this.ipc.receive("onAgenticAgentResults", async (e, t, n) => {
468
+ }), this.ipc.receive("onAgenticAgentResults", async (e, t, r) => {
430
469
  if (!Array.isArray(t))
431
470
  return;
432
- const r = this.plugin.onAgenticAgentResults;
433
- r && await r(e, t, typeof n == "string" ? n : null);
471
+ const n = this.plugin.onAgenticAgentResults;
472
+ n && await n(e, t, typeof r == "string" ? r : null);
434
473
  }), this.ipc.receive("onAgenticStreamComplete", async (e) => {
435
474
  const t = this.plugin.onAgenticStreamComplete;
436
475
  t && await t(typeof e == "string" ? e : null);
437
- }), this.ipc.receive("onAgenticIssueStatusChanged", async (e, t, n) => {
438
- const r = this.plugin.onAgenticIssueStatusChanged;
439
- if (r && !(t !== "active" && t !== "resolved" && t !== "dismissed" || n !== "user" && n !== "host"))
476
+ }), this.ipc.receive("onAgenticIssueStatusChanged", async (e, t, r) => {
477
+ const n = this.plugin.onAgenticIssueStatusChanged;
478
+ if (n && !(t !== "active" && t !== "resolved" && t !== "dismissed" || r !== "user" && r !== "host"))
440
479
  try {
441
- await r(e, t, n);
480
+ await n(e, t, r);
442
481
  } catch {
443
482
  }
444
483
  }), this.ipc.receive("onAgenticIssuesCleared", async (e) => {
@@ -462,8 +501,8 @@ var J = class {
462
501
  }
463
502
  if (this.plugin.onIntegrationSettingsChange) {
464
503
  const e = this.plugin.onIntegrationSettingsChange;
465
- this.ipc.receive("onIntegrationSettingsChange", async (t, n) => {
466
- await e(t, n);
504
+ this.ipc.receive("onIntegrationSettingsChange", async (t, r) => {
505
+ await e(t, r);
467
506
  });
468
507
  }
469
508
  }
@@ -500,10 +539,10 @@ var J = class {
500
539
  destroy() {
501
540
  this.window.removeEventListener("message", this.handleMessage), this.ipc.destroy();
502
541
  }
503
- }, X = class {
542
+ }, Q = class {
504
543
  ipcAdapter;
505
- constructor(e, t, n) {
506
- this.ipcAdapter = new Y(e, t, n?.win, n?.config, n?.targetOrigin);
544
+ constructor(e, t, r) {
545
+ this.ipcAdapter = new Z(e, t, r?.win, r?.config, r?.targetOrigin);
507
546
  }
508
547
  destroy() {
509
548
  this.ipcAdapter.destroy();
@@ -538,7 +577,7 @@ var J = class {
538
577
  configure(e) {
539
578
  this.ipcAdapter.configure(e);
540
579
  }
541
- }, K = `
580
+ }, ee = `
542
581
  <div class="sidebar-load-overlay-card">
543
582
  <div class="sidebar-load-overlay-title">Sidebar failed to load</div>
544
583
  <div class="sidebar-load-overlay-description">Check your connection or try again.</div>
@@ -559,16 +598,16 @@ var J = class {
559
598
  <span>Retry</span>
560
599
  </button>
561
600
  </div>
562
- `, q = () => {
601
+ `, te = () => {
563
602
  const e = document.createElement("div");
564
- e.className = "sidebar-load-overlay", e.style.display = "none", e.innerHTML = K;
603
+ e.className = "sidebar-load-overlay", e.style.display = "none", e.innerHTML = ee;
565
604
  const t = e.querySelector(".sidebar-load-overlay-button");
566
605
  if (!t) throw new Error("Missing retry button in load overlay template.");
567
606
  return {
568
607
  overlay: e,
569
608
  button: t
570
609
  };
571
- }, R = "markupai-sidebar-load-overlay-styles", Z = `
610
+ }, T = "markupai-sidebar-load-overlay-styles", re = `
572
611
  :root {
573
612
  --background: #f5f5f4;
574
613
  --foreground: #333332;
@@ -660,21 +699,21 @@ var J = class {
660
699
  box-shadow: 0 0 0 2px
661
700
  color-mix(in srgb, var(--accent, #ef4640) 60%, transparent);
662
701
  }
663
- `, Q = (e) => {
702
+ `, ne = (e) => {
664
703
  const t = e ?? document;
665
- if (t.getElementById(R)) return;
666
- const n = t.createElement("style");
667
- n.id = R, n.textContent = Z, t.head.appendChild(n);
668
- }, ee = 8e3, te = 12e3, ne = (e, t, n = {}) => {
669
- Q(e.ownerDocument);
670
- const { sidebarUrl: r, targetOrigin: i, timeoutMs: a = ee, retryIntervalMs: o = te, messageListenWindow: s } = n, l = s ?? (typeof globalThis.window < "u" ? globalThis.window : globalThis), p = () => r ?? t.src, B = () => {
704
+ if (t.getElementById(T)) return;
705
+ 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 = () => {
671
710
  if (i) return i;
672
711
  try {
673
712
  return new URL(p()).origin;
674
713
  } catch {
675
714
  return "*";
676
715
  }
677
- }, { overlay: y, button: v } = q();
716
+ }, { overlay: y, button: A } = te();
678
717
  e.appendChild(y);
679
718
  let u = !1, h, d;
680
719
  const g = (c) => {
@@ -683,82 +722,82 @@ var J = class {
683
722
  g(!1);
684
723
  const f = () => {
685
724
  h && (globalThis.clearTimeout(h), h = void 0);
686
- }, A = () => {
725
+ }, C = () => {
687
726
  f(), h = globalThis.setTimeout(() => {
688
727
  u || g(!0);
689
728
  }, a);
690
- }, C = (c) => {
729
+ }, b = (c) => {
691
730
  const m = c?.preserveOverlay ?? !0;
692
- u = !1, m || g(!1), t.src = p(), A();
693
- }, H = () => {
731
+ u = !1, m || g(!1), t.src = p(), C();
732
+ }, F = () => {
694
733
  d || o <= 0 || (d = globalThis.setInterval(() => {
695
- u || C({ preserveOverlay: !0 });
734
+ u || b({ preserveOverlay: !0 });
696
735
  }, o));
697
- }, b = () => {
736
+ }, S = () => {
698
737
  d && (globalThis.clearInterval(d), d = void 0);
699
- }, S = (c) => {
738
+ }, w = (c) => {
700
739
  if (!t.contentWindow || c.source !== t.contentWindow) return;
701
- const m = B();
702
- m !== "*" && c.origin !== m || (u = !0, f(), b(), g(!1));
703
- }, w = () => {
704
- f(), g(!0);
740
+ const m = j();
741
+ m !== "*" && c.origin !== m || (u = !0, f(), S(), g(!1));
705
742
  }, P = () => {
706
- C();
743
+ f(), g(!0);
744
+ }, E = () => {
745
+ b();
707
746
  };
708
- return v.addEventListener("click", P), t.addEventListener("error", w), l.addEventListener("message", S), A(), H(), () => {
709
- f(), b(), t.removeEventListener("error", w), l.removeEventListener("message", S), v.removeEventListener("click", P), y.remove();
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();
710
749
  };
711
- }, re = "Markup AI Sidebar", ie = "clipboard-read; clipboard-write", Ae = "markupai.sidebarNextGen.overrideUrl", Ce = "https://sidebar.markup.ai/";
712
- function be(e) {
750
+ }, se = "Markup AI Sidebar", le = "clipboard-read; clipboard-write", Pe = "markupai.sidebarNextGen.overrideUrl", Ee = "https://sidebar.markup.ai/";
751
+ function Re(e) {
713
752
  try {
714
753
  return "localStorage" in globalThis && globalThis.localStorage.getItem("markupai.sidebarNextGen.overrideUrl")?.trim() || e;
715
754
  } catch {
716
755
  return e;
717
756
  }
718
757
  }
719
- var ae = "markupai.sidebarNextGen.authOverride";
720
- function Se(e, t) {
758
+ var ce = "markupai.sidebarNextGen.authOverride";
759
+ function Oe(e, t) {
721
760
  if (!t) return e;
722
761
  try {
723
762
  if (!("localStorage" in globalThis)) return e;
724
- const n = globalThis.localStorage.getItem(ae)?.trim();
725
- if (!n) return e;
726
- const r = JSON.parse(n);
727
- return r !== null && typeof r == "object" && "type" in r && (r.type === "mediation" || r.type === "popup") ? r : e;
763
+ const r = globalThis.localStorage.getItem(ce)?.trim();
764
+ if (!r) return e;
765
+ const n = JSON.parse(r);
766
+ return n !== null && typeof n == "object" && "type" in n && (n.type === "mediation" || n.type === "popup") ? n : e;
728
767
  } catch {
729
768
  return e;
730
769
  }
731
770
  }
732
- function we(e, t) {
771
+ function Te(e, t) {
733
772
  try {
734
773
  return new URL(e).origin;
735
- } catch (n) {
736
- return t?.onInvalidUrl?.(e, n), "*";
774
+ } catch (r) {
775
+ return t?.onInvalidUrl?.(e, r), "*";
737
776
  }
738
777
  }
739
- function Pe(e, t = "Expected SidebarAdapter from createSidebarHost") {
778
+ function De(e, t = "Expected SidebarAdapter from createSidebarHost") {
740
779
  if (e.adapter === null) throw new Error(t);
741
780
  }
742
- function oe(e) {
743
- const { iframe: t, iframeMount: n } = e;
744
- if (t !== void 0 && n !== void 0) throw new Error("createSidebarHost: pass only one of `iframe` or `iframeMount`");
781
+ function de(e) {
782
+ const { iframe: t, iframeMount: r } = e;
783
+ if (t !== void 0 && r !== void 0) throw new Error("createSidebarHost: pass only one of `iframe` or `iframeMount`");
745
784
  if (t !== void 0) return {
746
785
  iframe: t,
747
786
  removeMountedIframe: null
748
787
  };
749
- if (n === void 0) throw new Error("createSidebarHost: pass either `iframe` or `iframeMount`");
750
- const { container: r, src: i, allow: a = ie } = n, o = document.createElement("iframe");
751
- return o.title = re, o.src = i, a && o.setAttribute("allow", a), r.appendChild(o), {
788
+ 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), {
752
791
  iframe: o,
753
792
  removeMountedIframe: () => {
754
793
  o.remove();
755
794
  }
756
795
  };
757
796
  }
758
- function Ee(e) {
759
- const { plugin: t, loadOverlayContainer: n, loadOverlayOptions: r, adapterOptions: i } = e, { iframe: a, removeMountedIframe: o } = oe(e), s = n !== void 0 ? ne(n, a, r ?? {}) : null;
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;
760
799
  if (t !== void 0) {
761
- const l = new X(t, a, i);
800
+ const l = new Q(t, a, i);
762
801
  return {
763
802
  iframe: a,
764
803
  adapter: l,
@@ -775,14 +814,14 @@ function Ee(e) {
775
814
  }
776
815
  };
777
816
  }
778
- var L = "sidebarContainer", T = "markupai-sidebar-host-shell-styles";
779
- function k(e) {
817
+ var H = "sidebarContainer", D = "markupai-sidebar-host-shell-styles";
818
+ function U(e) {
780
819
  if (typeof CSS < "u" && typeof CSS.escape == "function") return CSS.escape(e);
781
820
  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)})`);
782
821
  return e;
783
822
  }
784
- function N(e = L) {
785
- const t = k(e);
823
+ function $(e = H) {
824
+ const t = U(e);
786
825
  return `
787
826
  html {
788
827
  height: 100%;
@@ -807,41 +846,41 @@ body {
807
846
  }
808
847
  `.trim();
809
848
  }
810
- var Re = N();
811
- function se(e) {
849
+ var Me = $();
850
+ function ge(e) {
812
851
  return e instanceof Document ? e : e.ownerDocument;
813
852
  }
814
- function le(e, t, n) {
815
- if (!t || e.getElementById(T)) return;
816
- const r = e.createElement("style");
817
- r.id = T, r.textContent = N(n), e.head.appendChild(r);
853
+ function pe(e, t, r) {
854
+ if (!t || e.getElementById(D)) return;
855
+ const n = e.createElement("style");
856
+ n.id = D, n.textContent = $(r), e.head.appendChild(n);
818
857
  }
819
- function Te(e) {
820
- const { root: t = typeof document < "u" ? document : void 0, containerId: n = L, includeDefaultStyles: r = !0 } = e ?? {};
858
+ function _e(e) {
859
+ const { root: t = typeof document < "u" ? document : void 0, containerId: r = H, includeDefaultStyles: n = !0 } = e ?? {};
821
860
  if (t === void 0) throw new Error("ensureSidebarHostShell: no document — pass `root` in non-browser environments");
822
- const i = se(t);
823
- le(i, r, n);
824
- const a = t instanceof Document ? i.getElementById(n) : t.querySelector(`#${k(n)}`);
861
+ const i = ge(t);
862
+ pe(i, n, r);
863
+ const a = t instanceof Document ? i.getElementById(r) : t.querySelector(`#${U(r)}`);
825
864
  if (a instanceof HTMLElement && (t instanceof Document || t.contains(a))) return a;
826
865
  if (!(t instanceof Document)) {
827
866
  const s = i.createElement("div");
828
- return s.id = n, t.appendChild(s), s;
867
+ return s.id = r, t.appendChild(s), s;
829
868
  }
830
869
  const o = i.createElement("div");
831
- return o.id = n, i.body.appendChild(o), o;
870
+ return o.id = r, i.body.appendChild(o), o;
832
871
  }
833
- function ce() {
872
+ function ue() {
834
873
  return ' <meta name="viewport" content="width=device-width, initial-scale=1.0" />';
835
874
  }
836
- function Oe(e) {
837
- const { title: t = "Markup AI Sidebar", headInnerHtml: n = "", includePluginHostHead: r = !1, bodyScriptsHtml: i, htmlLang: a = "en", htmlAttrs: o = `lang="${a}" style="height:100%"`, bodyAttrs: s = 'style="height:100%;margin:0"' } = e, l = [r ? ce() : "", n].filter((p) => p.trim().length > 0).join(`
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(`
838
877
  `);
839
878
  return `<!DOCTYPE html>
840
879
  <html ${o}>
841
880
  <head>
842
881
  <base target="_top" />
843
882
  <meta charset="UTF-8" />
844
- <title>${de(t)}</title>${l ? `
883
+ <title>${he(t)}</title>${l ? `
845
884
  ${l}` : ""}
846
885
  </head>
847
886
  <body ${s}>
@@ -850,44 +889,46 @@ ${l}` : ""}
850
889
  </html>
851
890
  `;
852
891
  }
853
- function de(e) {
892
+ function he(e) {
854
893
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
855
894
  }
856
895
  export {
857
- U as ADAPTER_VERSION,
858
- ae as AUTH_CONFIG_OVERRIDE_STORAGE_KEY,
859
- V as DEFAULT_IPC_CONFIG,
860
- ue as DEFAULT_SIDEBAR_CONFIG,
861
- j as DeferredPromise,
862
- _ as IPCCore,
863
- ge as MimeType,
864
- ve as PluginAdapter,
865
- J as PluginIPCAdapter,
866
- Ce as SIDEBAR_DEFAULT_PRODUCTION_BASE_URL,
867
- L as SIDEBAR_HOST_CONTAINER_ID,
868
- Re as SIDEBAR_HOST_SHELL_CSS,
869
- ie as SIDEBAR_IFRAME_DEFAULT_ALLOW,
870
- re as SIDEBAR_IFRAME_DEFAULT_TITLE,
871
- Ae as SIDEBAR_URL_OVERRIDE_STORAGE_KEY,
872
- X as SidebarAdapter,
873
- Y as SidebarIPCAdapter,
874
- pe as TEXT_MIME_TYPES,
875
- O as TextLookupError,
876
- Pe as assertSidebarHostAdapter,
877
- Ie as buildDocumentReference,
878
- Oe as buildSidebarHostHtmlDocument,
879
- N as buildSidebarHostShellCss,
880
- ce as buildSidebarPluginHostHeadInnerHtml,
881
- Ee as createSidebarHost,
882
- Te as ensureSidebarHostShell,
883
- Se as getAuthConfigWithOverride,
884
- be as getSidebarBaseUrlWithOverride,
885
- E as ipcErrorReconstructors,
886
- ye as isDocumentReference,
887
- fe as isIntegrationSettingField,
888
- he as isIntegrationSettingsSchema,
889
- me as isTextLookupError,
890
- $ as reconstructError,
891
- ne as setupSidebarLoadOverlay,
892
- we as sidebarPostMessageTargetOrigin
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
893
934
  };