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