@markupai/sidebar-adapter 1.5.3 → 2.1.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,55 +1,53 @@
1
- var oe = /* @__PURE__ */ (function(e) {
1
+ var ce = /* @__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
- })({}), se = [
3
+ })({}), de = [
4
4
  "text/plain",
5
5
  "text/markdown",
6
6
  "text/html",
7
7
  "application/dita+xml"
8
- ], le = {
8
+ ], ge = {
9
9
  integrationName: "unknown",
10
10
  integrationVersion: "unknown",
11
11
  integrationId: "markupai-sidebar-app",
12
12
  hideBanner: !1,
13
- dialogClosingScript: void 0,
14
- useCheckPreviewDialog: !1,
15
13
  supportCheckSelection: !0,
16
14
  multiAgent: !1,
17
15
  multiDocument: !1
18
- }, ce = (e) => typeof e != "object" || e === null ? !1 : Array.isArray(e.fields), de = (e) => {
16
+ }, pe = (e) => typeof e != "object" || e === null ? !1 : Array.isArray(e.fields), ue = (e) => {
19
17
  if (typeof e != "object" || e === null) return !1;
20
18
  const t = e;
21
- 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((i) => {
22
- if (typeof i != "object" || i === null) return !1;
23
- const n = i;
24
- return typeof n.value == "string" && typeof n.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((n) => {
20
+ if (typeof n != "object" || n === null) return !1;
21
+ const r = n;
22
+ return typeof r.value == "string" && typeof r.label == "string";
25
23
  }) : !1;
26
- }, O = class T extends Error {
24
+ }, he = "2.1.0", T = class D extends Error {
27
25
  name = "TextLookupError";
28
26
  constructor(t) {
29
- super(t), Object.setPrototypeOf(this, T.prototype);
27
+ super(t), Object.setPrototypeOf(this, D.prototype);
30
28
  }
31
29
  };
32
- function ge(e) {
33
- return e instanceof O;
34
- }
35
- var P = { TextLookupError: (e) => new O(e) };
36
- function U(e) {
37
- const t = e.message ?? "", i = e.name, n = typeof i == "string" && i in P ? P[i] : void 0;
38
- return n ? n(t, e) : Object.assign(new Error(t), i ? { name: i } : {});
39
- }
40
- var D = ":", x = /^[a-z][a-z0-9-]*$/;
41
- function pe(e) {
42
- const t = e.indexOf(D);
43
- return t <= 0 || t === e.length - 1 ? !1 : x.test(e.slice(0, t));
44
- }
45
- function ue(e, t) {
46
- const i = e.trim().toLowerCase(), n = t.trim();
47
- if (!x.test(i)) throw new Error(`Invalid document reference prefix ${JSON.stringify(e)}: expected a lowercase name like "word".`);
48
- if (n.length === 0) throw new Error("Invalid document reference: the document id is empty.");
49
- const r = `${i}${D}`;
50
- return n.startsWith(r) ? n : `${r}${n}`;
51
- }
52
- var H = class extends Promise {
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 {
53
51
  static get [Symbol.species]() {
54
52
  return Promise;
55
53
  }
@@ -57,20 +55,20 @@ var H = class extends Promise {
57
55
  reject;
58
56
  constructor(e = () => {
59
57
  }) {
60
- let t, i;
61
- super((n, r) => {
62
- t = n, i = r, e(n, r);
63
- }), this.resolve = t, this.reject = i;
64
- }
65
- }, $ = { timeout: 1e4 };
66
- function j(e) {
67
- const t = JSON.stringify(e, Object.getOwnPropertyNames(e)), i = JSON.parse(t);
68
- return i.message === void 0 || i.message === "" ? JSON.stringify({
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({
69
67
  message: e instanceof Error ? e.message : String(e),
70
68
  name: e instanceof Error ? e.name : void 0
71
69
  }) : t;
72
70
  }
73
- var L = class {
71
+ var M = class {
74
72
  promisesByID = {};
75
73
  receiversByName = {};
76
74
  currentID = 0;
@@ -78,7 +76,7 @@ var L = class {
78
76
  postMessage;
79
77
  constructor(e, t) {
80
78
  this.postMessage = e, this.config = {
81
- ...$,
79
+ ...j,
82
80
  ...t
83
81
  };
84
82
  }
@@ -91,24 +89,24 @@ var L = class {
91
89
  call(e, ...t) {
92
90
  return this.callWithOptions(e, {}, ...t);
93
91
  }
94
- callWithOptions(e, t, ...i) {
95
- const n = this.currentID++, r = new H(), a = t.timeout ?? this.config.timeout, o = setTimeout(() => {
96
- if (n in this.promisesByID) {
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) {
97
95
  const l = /* @__PURE__ */ new Error(`IPC call timeout: "${e}" did not respond within ${String(a)}ms`);
98
- r.reject(l), Reflect.deleteProperty(this.promisesByID, n);
96
+ i.reject(l), Reflect.deleteProperty(this.promisesByID, r);
99
97
  }
100
98
  }, a);
101
- this.promisesByID[n] = {
102
- promise: r,
99
+ this.promisesByID[r] = {
100
+ promise: i,
103
101
  timeoutId: o
104
102
  };
105
103
  const s = {
106
104
  type: "call",
107
- id: n,
105
+ id: r,
108
106
  name: e,
109
- data: i
107
+ data: n
110
108
  };
111
- return this.postMessage(s), r;
109
+ return this.postMessage(s), i;
112
110
  }
113
111
  receive(e, t) {
114
112
  this.receiversByName[e] = t;
@@ -131,27 +129,27 @@ var L = class {
131
129
  }
132
130
  }
133
131
  async handleCall(e) {
134
- const { id: t, name: i, data: n } = e;
135
- if (!(i in this.receiversByName)) {
136
- const a = /* @__PURE__ */ new Error(`No receiver registered for: ${i}`), o = JSON.stringify({
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({
137
135
  message: a.message,
138
136
  name: a.name
139
137
  });
140
138
  this.postMessage({
141
139
  type: "error",
142
140
  id: t,
143
- name: i,
141
+ name: n,
144
142
  errorJSON: o
145
143
  });
146
144
  return;
147
145
  }
148
- const r = this.receiversByName[i];
146
+ const i = this.receiversByName[n];
149
147
  try {
150
- if (!Array.isArray(n)) throw new TypeError(`IPC: Expected array of arguments but got ${typeof n}`);
151
- const a = await r(...n), o = {
148
+ if (!Array.isArray(r)) throw new TypeError(`IPC: Expected array of arguments but got ${typeof r}`);
149
+ const a = await i(...r), o = {
152
150
  type: "response",
153
151
  id: t,
154
- name: i,
152
+ name: n,
155
153
  data: a
156
154
  };
157
155
  this.postMessage(o);
@@ -159,8 +157,8 @@ var L = class {
159
157
  const o = {
160
158
  type: "error",
161
159
  id: t,
162
- name: i,
163
- errorJSON: j(a)
160
+ name: n,
161
+ errorJSON: F(a)
164
162
  };
165
163
  this.postMessage(o);
166
164
  }
@@ -168,20 +166,20 @@ var L = class {
168
166
  handleResponse(e) {
169
167
  const { id: t } = e;
170
168
  if (t in this.promisesByID) {
171
- const { promise: i, timeoutId: n } = this.promisesByID[t];
172
- clearTimeout(n), i.resolve(e.data), Reflect.deleteProperty(this.promisesByID, t);
169
+ const { promise: n, timeoutId: r } = this.promisesByID[t];
170
+ clearTimeout(r), n.resolve(e.data), Reflect.deleteProperty(this.promisesByID, t);
173
171
  }
174
172
  }
175
173
  handleError(e) {
176
- const { id: t, errorJSON: i } = e;
174
+ const { id: t, errorJSON: n } = e;
177
175
  if (t in this.promisesByID) {
178
- const { promise: n, timeoutId: r } = this.promisesByID[t];
179
- clearTimeout(r);
176
+ const { promise: r, timeoutId: i } = this.promisesByID[t];
177
+ clearTimeout(i);
180
178
  try {
181
- const a = U(JSON.parse(i));
182
- n.reject(a);
179
+ const a = JSON.parse(n), o = H(a);
180
+ r.reject(o);
183
181
  } catch {
184
- n.reject(/* @__PURE__ */ new Error("Failed to parse error from IPC"));
182
+ r.reject(/* @__PURE__ */ new Error("Failed to parse error from IPC"));
185
183
  }
186
184
  Reflect.deleteProperty(this.promisesByID, t);
187
185
  }
@@ -191,30 +189,30 @@ var L = class {
191
189
  clearTimeout(t), e.reject(/* @__PURE__ */ new Error("IPC destroyed"));
192
190
  this.promisesByID = {}, this.receiversByName = {};
193
191
  }
194
- }, F = class {
192
+ }, z = class {
195
193
  ipc;
196
194
  sidebar;
197
195
  targetOrigin;
198
- constructor(e, t, i = "*") {
199
- this.sidebar = e || {}, this.targetOrigin = i, this.ipc = new L((n) => {
200
- window.parent.postMessage(n, this.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);
201
199
  }, t), window.addEventListener("message", this.handleMessage), this.registerReceivers();
202
200
  }
203
201
  handleMessage = (e) => {
204
- const t = globalThis.window.location.origin, i = this.targetOrigin;
205
- e.origin !== t && (i !== "*" && e.origin !== i || e.data && typeof e.data == "object" && this.ipc.handleMessage(e.data));
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));
206
204
  };
207
205
  registerReceivers() {
208
206
  if (this.sidebar.onPluginStatusChange) {
209
207
  const e = this.sidebar.onPluginStatusChange;
210
- this.ipc.receive("onPluginStatusChange", async (t, i) => {
211
- await e(t, i);
208
+ this.ipc.receive("onPluginStatusChange", async (t, n) => {
209
+ await e(t, n);
212
210
  });
213
211
  }
214
212
  if (this.sidebar.activateAgenticIssue) {
215
213
  const e = this.sidebar.activateAgenticIssue;
216
- this.ipc.receive("activateAgenticIssue", async (t, i) => {
217
- await e(t, typeof i == "string" ? i : null);
214
+ this.ipc.receive("activateAgenticIssue", async (t, n) => {
215
+ await e(t, typeof n == "string" ? n : null);
218
216
  });
219
217
  }
220
218
  if (this.sidebar.invalidateAgenticIssue) {
@@ -252,8 +250,11 @@ var L = class {
252
250
  });
253
251
  }
254
252
  }
255
- async getInitConfig() {
256
- return await this.ipc.call("getInitConfig");
253
+ async getInitConfig(e) {
254
+ return e ? await this.ipc.call("getInitConfig", {
255
+ ...e,
256
+ adapterVersion: e.adapterVersion ?? "2.1.0"
257
+ }) : await this.ipc.call("getInitConfig");
257
258
  }
258
259
  async getContent(e) {
259
260
  return this.ipc.callWithOptions("getContent", e ?? {});
@@ -261,29 +262,23 @@ var L = class {
261
262
  async getSelectedContent(e) {
262
263
  return this.ipc.callWithOptions("getSelectedContent", e ?? {});
263
264
  }
264
- async replaceContent(e, t, i = null) {
265
- await this.ipc.call("replaceContent", e, t, i);
265
+ async replaceContent(e, t, n = null) {
266
+ await this.ipc.call("replaceContent", e, t, n);
266
267
  }
267
268
  async selectContent(e, t = null) {
268
269
  await this.ipc.call("selectContent", e, t);
269
270
  }
270
- async showDialog(e, t, i, n) {
271
- await this.ipc.call("showDialog", e, t, i, n);
272
- }
273
- async closeDialog() {
274
- await this.ipc.call("closeDialog");
275
- }
276
271
  async replaceMultipleContents(e) {
277
272
  await this.ipc.call("replaceMultipleContents", e);
278
273
  }
279
- async onAgenticAgentResults(e, t, i = null) {
280
- await this.ipc.call("onAgenticAgentResults", e, t, i);
274
+ async onAgenticAgentResults(e, t, n = null) {
275
+ await this.ipc.call("onAgenticAgentResults", e, t, n);
281
276
  }
282
277
  async onAgenticStreamComplete(e = null) {
283
278
  await this.ipc.call("onAgenticStreamComplete", e);
284
279
  }
285
- async onAgenticIssueStatusChanged(e, t, i) {
286
- await this.ipc.call("onAgenticIssueStatusChanged", e, t, i);
280
+ async onAgenticIssueStatusChanged(e, t, n) {
281
+ await this.ipc.call("onAgenticIssueStatusChanged", e, t, n);
287
282
  }
288
283
  async onAgenticIssuesCleared(e = null) {
289
284
  await this.ipc.call("onAgenticIssuesCleared", e);
@@ -316,16 +311,16 @@ var L = class {
316
311
  destroy() {
317
312
  window.removeEventListener("message", this.handleMessage), this.ipc.destroy();
318
313
  }
319
- }, he = class {
314
+ }, Ie = class {
320
315
  ipcAdapter;
321
- constructor(e, t, i) {
322
- this.ipcAdapter = new F(e, t, i);
316
+ constructor(e, t, n) {
317
+ this.ipcAdapter = new z(e, t, n);
323
318
  }
324
319
  destroy() {
325
320
  this.ipcAdapter.destroy();
326
321
  }
327
- async getInitConfig() {
328
- return await this.ipcAdapter.getInitConfig();
322
+ async getInitConfig(e) {
323
+ return await this.ipcAdapter.getInitConfig(e);
329
324
  }
330
325
  async getContent(e) {
331
326
  return await this.ipcAdapter.getContent(e);
@@ -333,29 +328,23 @@ var L = class {
333
328
  async getSelectedContent(e) {
334
329
  return await this.ipcAdapter.getSelectedContent(e);
335
330
  }
336
- async replaceContent(e, t, i = null) {
337
- await this.ipcAdapter.replaceContent(e, t, i);
331
+ async replaceContent(e, t, n = null) {
332
+ await this.ipcAdapter.replaceContent(e, t, n);
338
333
  }
339
334
  async selectContent(e, t = null) {
340
335
  await this.ipcAdapter.selectContent(e, t);
341
336
  }
342
- async showDialog(e, t, i, n) {
343
- await this.ipcAdapter.showDialog(e, t, i, n);
344
- }
345
- async closeDialog() {
346
- await this.ipcAdapter.closeDialog();
347
- }
348
337
  async replaceMultipleContents(e) {
349
338
  await this.ipcAdapter.replaceMultipleContents(e);
350
339
  }
351
- onAgenticAgentResults(e, t, i = null) {
352
- return this.ipcAdapter.onAgenticAgentResults(e, t, i);
340
+ onAgenticAgentResults(e, t, n = null) {
341
+ return this.ipcAdapter.onAgenticAgentResults(e, t, n);
353
342
  }
354
343
  onAgenticStreamComplete(e = null) {
355
344
  return this.ipcAdapter.onAgenticStreamComplete(e);
356
345
  }
357
- onAgenticIssueStatusChanged(e, t, i) {
358
- return this.ipcAdapter.onAgenticIssueStatusChanged(e, t, i);
346
+ onAgenticIssueStatusChanged(e, t, n) {
347
+ return this.ipcAdapter.onAgenticIssueStatusChanged(e, t, n);
359
348
  }
360
349
  onAgenticIssuesCleared(e = null) {
361
350
  return this.ipcAdapter.onAgenticIssuesCleared(e);
@@ -378,47 +367,63 @@ var L = class {
378
367
  getTargetOrigin() {
379
368
  return this.ipcAdapter.getTargetOrigin();
380
369
  }
381
- }, z = class {
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 {
382
389
  ipc;
383
390
  plugin;
384
391
  iframe;
385
392
  window;
386
393
  targetOrigin;
387
- constructor(e, t, i, n, r = "*") {
388
- this.plugin = e, this.iframe = t, this.window = i ?? window, this.targetOrigin = r, this.ipc = new L((a) => {
394
+ 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) => {
389
397
  this.iframe.contentWindow?.postMessage(a, this.targetOrigin);
390
- }, n), this.window.addEventListener("message", this.handleMessage, !1), this.registerReceivers();
398
+ }, r), this.window.addEventListener("message", this.handleMessage, !1), this.registerReceivers();
391
399
  }
392
400
  handleMessage = (e) => {
393
- const t = this.window.location.origin, i = this.targetOrigin;
394
- e.origin !== t && (i !== "*" && e.origin !== i || e.data && typeof e.data == "object" && this.ipc.handleMessage(e.data));
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));
395
403
  };
396
404
  registerReceivers() {
397
- if (this.ipc.receive("getInitConfig", async () => await this.plugin.getInitConfig()), 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, i) => {
398
- await this.plugin.replaceContent(e, t, typeof i == "string" ? i : null);
405
+ 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);
399
410
  }), this.ipc.receive("selectContent", async (e, t) => {
400
411
  await this.plugin.selectContent(e, typeof t == "string" ? t : null);
401
- }), this.ipc.receive("showDialog", async (e, t, i, n) => {
402
- if (!this.plugin.showDialog) throw new Error("SidebarIPCAdapter: host does not implement showDialog");
403
- await this.plugin.showDialog(e, t, i, n);
404
- }), this.ipc.receive("closeDialog", async () => {
405
- if (!this.plugin.closeDialog) throw new Error("SidebarIPCAdapter: host does not implement closeDialog");
406
- await this.plugin.closeDialog();
407
412
  }), this.ipc.receive("replaceMultipleContents", async (e) => {
408
413
  await this.plugin.replaceMultipleContents(e);
409
- }), this.ipc.receive("onAgenticAgentResults", async (e, t, i) => {
414
+ }), this.ipc.receive("onAgenticAgentResults", async (e, t, n) => {
410
415
  if (!Array.isArray(t))
411
416
  return;
412
- const n = this.plugin.onAgenticAgentResults;
413
- n && await n(e, t, typeof i == "string" ? i : null);
417
+ const r = this.plugin.onAgenticAgentResults;
418
+ r && await r(e, t, typeof n == "string" ? n : null);
414
419
  }), this.ipc.receive("onAgenticStreamComplete", async (e) => {
415
420
  const t = this.plugin.onAgenticStreamComplete;
416
421
  t && await t(typeof e == "string" ? e : null);
417
- }), this.ipc.receive("onAgenticIssueStatusChanged", async (e, t, i) => {
418
- const n = this.plugin.onAgenticIssueStatusChanged;
419
- if (n && !(t !== "active" && t !== "resolved" && t !== "dismissed" || i !== "user" && i !== "host"))
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"))
420
425
  try {
421
- await n(e, t, i);
426
+ await r(e, t, n);
422
427
  } catch {
423
428
  }
424
429
  }), this.ipc.receive("onAgenticIssuesCleared", async (e) => {
@@ -442,8 +447,8 @@ var L = class {
442
447
  }
443
448
  if (this.plugin.onIntegrationSettingsChange) {
444
449
  const e = this.plugin.onIntegrationSettingsChange;
445
- this.ipc.receive("onIntegrationSettingsChange", async (t, i) => {
446
- await e(t, i);
450
+ this.ipc.receive("onIntegrationSettingsChange", async (t, n) => {
451
+ await e(t, n);
447
452
  });
448
453
  }
449
454
  }
@@ -471,16 +476,19 @@ var L = class {
471
476
  async notifyActiveDocumentChanged(e) {
472
477
  await this.ipc.call("onActiveDocumentChanged", e);
473
478
  }
479
+ getSidebarBuildInfo() {
480
+ return this.latestSidebarBuildInfo;
481
+ }
474
482
  configure(e) {
475
483
  this.ipc.configure(e);
476
484
  }
477
485
  destroy() {
478
486
  this.window.removeEventListener("message", this.handleMessage), this.ipc.destroy();
479
487
  }
480
- }, W = class {
488
+ }, J = class {
481
489
  ipcAdapter;
482
- constructor(e, t, i) {
483
- this.ipcAdapter = new z(e, t, i?.win, i?.config, i?.targetOrigin);
490
+ constructor(e, t, n) {
491
+ this.ipcAdapter = new G(e, t, n?.win, n?.config, n?.targetOrigin);
484
492
  }
485
493
  destroy() {
486
494
  this.ipcAdapter.destroy();
@@ -509,10 +517,13 @@ var L = class {
509
517
  async notifyActiveDocumentChanged(e) {
510
518
  await this.ipcAdapter.notifyActiveDocumentChanged(e);
511
519
  }
520
+ getSidebarBuildInfo() {
521
+ return this.ipcAdapter.getSidebarBuildInfo();
522
+ }
512
523
  configure(e) {
513
524
  this.ipcAdapter.configure(e);
514
525
  }
515
- }, G = `
526
+ }, Y = `
516
527
  <div class="sidebar-load-overlay-card">
517
528
  <div class="sidebar-load-overlay-title">Sidebar failed to load</div>
518
529
  <div class="sidebar-load-overlay-description">Check your connection or try again.</div>
@@ -533,16 +544,16 @@ var L = class {
533
544
  <span>Retry</span>
534
545
  </button>
535
546
  </div>
536
- `, J = () => {
547
+ `, X = () => {
537
548
  const e = document.createElement("div");
538
- e.className = "sidebar-load-overlay", e.style.display = "none", e.innerHTML = G;
549
+ e.className = "sidebar-load-overlay", e.style.display = "none", e.innerHTML = Y;
539
550
  const t = e.querySelector(".sidebar-load-overlay-button");
540
551
  if (!t) throw new Error("Missing retry button in load overlay template.");
541
552
  return {
542
553
  overlay: e,
543
554
  button: t
544
555
  };
545
- }, E = "markupai-sidebar-load-overlay-styles", Y = `
556
+ }, R = "markupai-sidebar-load-overlay-styles", K = `
546
557
  :root {
547
558
  --background: #f5f5f4;
548
559
  --foreground: #333332;
@@ -634,21 +645,21 @@ var L = class {
634
645
  box-shadow: 0 0 0 2px
635
646
  color-mix(in srgb, var(--accent, #ef4640) 60%, transparent);
636
647
  }
637
- `, V = (e) => {
648
+ `, q = (e) => {
638
649
  const t = e ?? document;
639
- if (t.getElementById(E)) return;
640
- const i = t.createElement("style");
641
- i.id = E, i.textContent = Y, t.head.appendChild(i);
642
- }, X = 8e3, K = 12e3, q = (e, t, i = {}) => {
643
- V(e.ownerDocument);
644
- const { sidebarUrl: n, targetOrigin: r, timeoutMs: a = X, retryIntervalMs: o = K, messageListenWindow: s } = i, l = s ?? (typeof globalThis.window < "u" ? globalThis.window : globalThis), p = () => n ?? t.src, N = () => {
645
- if (r) return r;
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 = () => {
656
+ if (i) return i;
646
657
  try {
647
658
  return new URL(p()).origin;
648
659
  } catch {
649
660
  return "*";
650
661
  }
651
- }, { overlay: y, button: I } = J();
662
+ }, { overlay: y, button: v } = X();
652
663
  e.appendChild(y);
653
664
  let u = !1, h, d;
654
665
  const g = (c) => {
@@ -657,82 +668,82 @@ var L = class {
657
668
  g(!1);
658
669
  const f = () => {
659
670
  h && (globalThis.clearTimeout(h), h = void 0);
660
- }, v = () => {
671
+ }, A = () => {
661
672
  f(), h = globalThis.setTimeout(() => {
662
673
  u || g(!0);
663
674
  }, a);
664
- }, A = (c) => {
675
+ }, C = (c) => {
665
676
  const m = c?.preserveOverlay ?? !0;
666
- u = !1, m || g(!1), t.src = p(), v();
667
- }, B = () => {
677
+ u = !1, m || g(!1), t.src = p(), A();
678
+ }, U = () => {
668
679
  d || o <= 0 || (d = globalThis.setInterval(() => {
669
- u || A({ preserveOverlay: !0 });
680
+ u || C({ preserveOverlay: !0 });
670
681
  }, o));
671
- }, C = () => {
682
+ }, b = () => {
672
683
  d && (globalThis.clearInterval(d), d = void 0);
673
- }, b = (c) => {
684
+ }, S = (c) => {
674
685
  if (!t.contentWindow || c.source !== t.contentWindow) return;
675
- const m = N();
676
- m !== "*" && c.origin !== m || (u = !0, f(), C(), g(!1));
686
+ const m = B();
687
+ m !== "*" && c.origin !== m || (u = !0, f(), b(), g(!1));
677
688
  }, w = () => {
678
689
  f(), g(!0);
679
- }, S = () => {
680
- A();
690
+ }, P = () => {
691
+ C();
681
692
  };
682
- return I.addEventListener("click", S), t.addEventListener("error", w), l.addEventListener("message", b), v(), B(), () => {
683
- f(), C(), t.removeEventListener("error", w), l.removeEventListener("message", b), I.removeEventListener("click", S), y.remove();
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();
684
695
  };
685
- }, Z = "Markup AI Sidebar", Q = "clipboard-read; clipboard-write", fe = "markupai.sidebarNextGen.overrideUrl", me = "https://sidebar.markup.ai/";
686
- function ye(e) {
696
+ }, te = "Markup AI Sidebar", ne = "clipboard-read; clipboard-write", ve = "markupai.sidebarNextGen.overrideUrl", Ae = "https://sidebar.markup.ai/";
697
+ function Ce(e) {
687
698
  try {
688
699
  return "localStorage" in globalThis && globalThis.localStorage.getItem("markupai.sidebarNextGen.overrideUrl")?.trim() || e;
689
700
  } catch {
690
701
  return e;
691
702
  }
692
703
  }
693
- var ee = "markupai.sidebarNextGen.authOverride";
694
- function Ie(e, t) {
704
+ var re = "markupai.sidebarNextGen.authOverride";
705
+ function be(e, t) {
695
706
  if (!t) return e;
696
707
  try {
697
708
  if (!("localStorage" in globalThis)) return e;
698
- const i = globalThis.localStorage.getItem(ee)?.trim();
699
- if (!i) return e;
700
- const n = JSON.parse(i);
701
- return n !== null && typeof n == "object" && "type" in n && (n.type === "mediation" || n.type === "popup") ? n : 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;
702
713
  } catch {
703
714
  return e;
704
715
  }
705
716
  }
706
- function ve(e, t) {
717
+ function Se(e, t) {
707
718
  try {
708
719
  return new URL(e).origin;
709
- } catch (i) {
710
- return t?.onInvalidUrl?.(e, i), "*";
720
+ } catch (n) {
721
+ return t?.onInvalidUrl?.(e, n), "*";
711
722
  }
712
723
  }
713
- function Ae(e, t = "Expected SidebarAdapter from createSidebarHost") {
724
+ function we(e, t = "Expected SidebarAdapter from createSidebarHost") {
714
725
  if (e.adapter === null) throw new Error(t);
715
726
  }
716
- function te(e) {
717
- const { iframe: t, iframeMount: i } = e;
718
- if (t !== void 0 && i !== void 0) throw new Error("createSidebarHost: pass only one of `iframe` or `iframeMount`");
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`");
719
730
  if (t !== void 0) return {
720
731
  iframe: t,
721
732
  removeMountedIframe: null
722
733
  };
723
- if (i === void 0) throw new Error("createSidebarHost: pass either `iframe` or `iframeMount`");
724
- const { container: n, src: r, allow: a = Q } = i, o = document.createElement("iframe");
725
- return o.title = Z, o.src = r, a && o.setAttribute("allow", a), n.appendChild(o), {
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), {
726
737
  iframe: o,
727
738
  removeMountedIframe: () => {
728
739
  o.remove();
729
740
  }
730
741
  };
731
742
  }
732
- function Ce(e) {
733
- const { plugin: t, loadOverlayContainer: i, loadOverlayOptions: n, adapterOptions: r } = e, { iframe: a, removeMountedIframe: o } = te(e), s = i !== void 0 ? q(i, a, n ?? {}) : null;
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;
734
745
  if (t !== void 0) {
735
- const l = new W(t, a, r);
746
+ const l = new J(t, a, i);
736
747
  return {
737
748
  iframe: a,
738
749
  adapter: l,
@@ -749,14 +760,14 @@ function Ce(e) {
749
760
  }
750
761
  };
751
762
  }
752
- var M = "sidebarContainer", R = "markupai-sidebar-host-shell-styles";
753
- function _(e) {
763
+ var L = "sidebarContainer", O = "markupai-sidebar-host-shell-styles";
764
+ function k(e) {
754
765
  if (typeof CSS < "u" && typeof CSS.escape == "function") return CSS.escape(e);
755
766
  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)})`);
756
767
  return e;
757
768
  }
758
- function k(e = M) {
759
- const t = _(e);
769
+ function N(e = L) {
770
+ const t = k(e);
760
771
  return `
761
772
  html {
762
773
  height: 100%;
@@ -781,86 +792,87 @@ body {
781
792
  }
782
793
  `.trim();
783
794
  }
784
- var be = k();
785
- function ie(e) {
795
+ var Ee = N();
796
+ function ae(e) {
786
797
  return e instanceof Document ? e : e.ownerDocument;
787
798
  }
788
- function ne(e, t, i) {
789
- if (!t || e.getElementById(R)) return;
790
- const n = e.createElement("style");
791
- n.id = R, n.textContent = k(i), e.head.appendChild(n);
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);
792
803
  }
793
- function we(e) {
794
- const { root: t = typeof document < "u" ? document : void 0, containerId: i = M, includeDefaultStyles: n = !0 } = e ?? {};
804
+ function Re(e) {
805
+ const { root: t = typeof document < "u" ? document : void 0, containerId: n = L, includeDefaultStyles: r = !0 } = e ?? {};
795
806
  if (t === void 0) throw new Error("ensureSidebarHostShell: no document — pass `root` in non-browser environments");
796
- const r = ie(t);
797
- ne(r, n, i);
798
- const a = t instanceof Document ? r.getElementById(i) : t.querySelector(`#${_(i)}`);
807
+ const i = ae(t);
808
+ oe(i, r, n);
809
+ const a = t instanceof Document ? i.getElementById(n) : t.querySelector(`#${k(n)}`);
799
810
  if (a instanceof HTMLElement && (t instanceof Document || t.contains(a))) return a;
800
811
  if (!(t instanceof Document)) {
801
- const s = r.createElement("div");
802
- return s.id = i, t.appendChild(s), s;
812
+ const s = i.createElement("div");
813
+ return s.id = n, t.appendChild(s), s;
803
814
  }
804
- const o = r.createElement("div");
805
- return o.id = i, r.body.appendChild(o), o;
815
+ const o = i.createElement("div");
816
+ return o.id = n, i.body.appendChild(o), o;
806
817
  }
807
- function re() {
818
+ function se() {
808
819
  return ' <meta name="viewport" content="width=device-width, initial-scale=1.0" />';
809
820
  }
810
- function Se(e) {
811
- const { title: t = "Markup AI Sidebar", headInnerHtml: i = "", includePluginHostHead: n = !1, bodyScriptsHtml: r, htmlLang: a = "en", htmlAttrs: o = `lang="${a}" style="height:100%"`, bodyAttrs: s = 'style="height:100%;margin:0"' } = e, l = [n ? re() : "", i].filter((p) => p.trim().length > 0).join(`
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(`
812
823
  `);
813
824
  return `<!DOCTYPE html>
814
825
  <html ${o}>
815
826
  <head>
816
827
  <base target="_top" />
817
828
  <meta charset="UTF-8" />
818
- <title>${ae(t)}</title>${l ? `
829
+ <title>${le(t)}</title>${l ? `
819
830
  ${l}` : ""}
820
831
  </head>
821
832
  <body ${s}>
822
- ${r}
833
+ ${i}
823
834
  </body>
824
835
  </html>
825
836
  `;
826
837
  }
827
- function ae(e) {
838
+ function le(e) {
828
839
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
829
840
  }
830
841
  export {
831
- ee as AUTH_CONFIG_OVERRIDE_STORAGE_KEY,
832
- $ as DEFAULT_IPC_CONFIG,
833
- le as DEFAULT_SIDEBAR_CONFIG,
834
- H as DeferredPromise,
835
- L as IPCCore,
836
- oe as MimeType,
837
- he as PluginAdapter,
838
- F as PluginIPCAdapter,
839
- me as SIDEBAR_DEFAULT_PRODUCTION_BASE_URL,
840
- M as SIDEBAR_HOST_CONTAINER_ID,
841
- be as SIDEBAR_HOST_SHELL_CSS,
842
- Q as SIDEBAR_IFRAME_DEFAULT_ALLOW,
843
- Z as SIDEBAR_IFRAME_DEFAULT_TITLE,
844
- fe as SIDEBAR_URL_OVERRIDE_STORAGE_KEY,
845
- W as SidebarAdapter,
846
- z as SidebarIPCAdapter,
847
- se as TEXT_MIME_TYPES,
848
- O as TextLookupError,
849
- Ae as assertSidebarHostAdapter,
850
- ue as buildDocumentReference,
851
- Se as buildSidebarHostHtmlDocument,
852
- k as buildSidebarHostShellCss,
853
- re as buildSidebarPluginHostHeadInnerHtml,
854
- Ce as createSidebarHost,
855
- we as ensureSidebarHostShell,
856
- Ie as getAuthConfigWithOverride,
857
- ye as getSidebarBaseUrlWithOverride,
858
- P as ipcErrorReconstructors,
859
- pe as isDocumentReference,
860
- de as isIntegrationSettingField,
861
- ce as isIntegrationSettingsSchema,
862
- ge as isTextLookupError,
863
- U as reconstructError,
864
- q as setupSidebarLoadOverlay,
865
- ve as sidebarPostMessageTargetOrigin
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
866
878
  };