@markupai/sidebar-adapter 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.umd.cjs CHANGED
@@ -1,4 +1,4 @@
1
- (function(r,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(r=typeof globalThis<"u"?globalThis:r||self,g(r.main={}))})(this,function(r){Object.defineProperty(r,Symbol.toStringTag,{value:"Module"});var g=(function(e){return e.TEXT_PLAIN="text/plain",e.TEXT_MARKDOWN="text/markdown",e.TEXT_HTML="text/html",e.APPLICATION_DITA_XML="application/dita+xml",e})({}),te=["text/plain","text/markdown","text/html","application/dita+xml"],ne={integrationName:"unknown",integrationVersion:"unknown",integrationId:"markupai-sidebar-app",hideBanner:!1,supportCheckSelection:!0,supportComments:!1,multiAgent:!1,multiDocument:!1},ie=e=>typeof e!="object"||e===null?!1:Array.isArray(e.fields),re=e=>{if(typeof e!="object"||e===null)return!1;const t=e;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=>{if(typeof n!="object"||n===null)return!1;const i=n;return typeof i.value=="string"&&typeof i.label=="string"}):!1},R="2.4.0",h=class Q extends Error{name="TextLookupError";constructor(t){super(t),Object.setPrototypeOf(this,Q.prototype)}},v=class ee extends h{name="ReplaceBatchError";applied;failed;constructor(t,n){super(t),this.applied=n.applied.map(i=>({start:i.start,end:i.end})),this.failed=n.failed.map(i=>T(i,i.message)),Object.setPrototypeOf(this,ee.prototype)}};function ae(e){return e instanceof v}function T(e,t){const n={start:e.start,end:e.end};return typeof t=="string"&&t.trim()!==""&&(n.message=t),n}function O(e){return Array.isArray(e)?e.flatMap(t=>{if(t===null||typeof t!="object")return[];const{start:n,end:i,message:a}=t;return typeof n!="number"||typeof i!="number"?[]:[{range:{start:n,end:i},message:a}]}):[]}function oe(e){return e instanceof h}var C={TextLookupError:e=>new h(e),ReplaceBatchError:(e,t)=>new v(e,{applied:O(t.applied).map(n=>n.range),failed:O(t.failed).map(n=>T(n.range,n.message))})};function _(e){const t=e.message??"",n=e.name,i=typeof n=="string"&&n in C?C[n]:void 0;return i?i(t,e):Object.assign(new Error(t),n?{name:n}:{})}var D=":",L=/^[a-z][a-z0-9-]*$/;function se(e){const t=e.indexOf(D);return t<=0||t===e.length-1?!1:L.test(e.slice(0,t))}function le(e,t){const n=e.trim().toLowerCase(),i=t.trim();if(!L.test(n))throw new Error(`Invalid document reference prefix ${JSON.stringify(e)}: expected a lowercase name like "word".`);if(i.length===0)throw new Error("Invalid document reference: the document id is empty.");const a=`${n}${D}`;return i.startsWith(a)?i:`${a}${i}`}var M=class extends Promise{static get[Symbol.species](){return Promise}resolve;reject;constructor(e=()=>{}){let t,n;super((i,a)=>{t=i,n=a,e(i,a)}),this.resolve=t,this.reject=n}},B={timeout:1e4};function ce(e){const t=typeof e=="object"&&e!==null?Object.fromEntries(Object.getOwnPropertyNames(e).map(s=>[s,e[s]])):{},n=e instanceof Error?e.message:String(e),i=typeof t.message=="string"&&t.message!==""?t.message:n,a=e instanceof Error?e.name:void 0,o=typeof t.name=="string"?t.name:a;return JSON.stringify({...t,message:i,...o!==void 0&&{name:o}})}var b=class{promisesByID={};receiversByName={};currentID=0;config;postMessage;constructor(e,t){this.postMessage=e,this.config={...B,...t}}configure(e){this.config={...this.config,...e}}call(e,...t){return this.callWithOptions(e,{},...t)}callWithOptions(e,t,...n){const i=this.currentID++,a=new M,o=t.timeout??this.config.timeout,s=setTimeout(()=>{if(i in this.promisesByID){const c=new Error(`IPC call timeout: "${e}" did not respond within ${String(o)}ms`);a.reject(c),Reflect.deleteProperty(this.promisesByID,i)}},o);this.promisesByID[i]={promise:a,timeoutId:s};const l={type:"call",id:i,name:e,data:n};return this.postMessage(l),a}receive(e,t){this.receiversByName[e]=t}ignore(e){delete this.receiversByName[e]}async handleMessage(e){switch(e.type){case"call":await this.handleCall(e);break;case"response":this.handleResponse(e);break;case"error":this.handleError(e);break;default:}}async handleCall(e){const{id:t,name:n,data:i}=e;if(!(n in this.receiversByName)){const o=new Error(`No receiver registered for: ${n}`),s=JSON.stringify({message:o.message,name:o.name});this.postMessage({type:"error",id:t,name:n,errorJSON:s});return}const a=this.receiversByName[n];try{if(!Array.isArray(i))throw new TypeError(`IPC: Expected array of arguments but got ${typeof i}`);const o=await a(...i),s={type:"response",id:t,name:n,data:o};this.postMessage(s)}catch(o){const s={type:"error",id:t,name:n,errorJSON:ce(o)};this.postMessage(s)}}handleResponse(e){const{id:t}=e;if(t in this.promisesByID){const{promise:n,timeoutId:i}=this.promisesByID[t];clearTimeout(i),n.resolve(e.data),Reflect.deleteProperty(this.promisesByID,t)}}handleError(e){const{id:t,errorJSON:n}=e;if(t in this.promisesByID){const{promise:i,timeoutId:a}=this.promisesByID[t];clearTimeout(a);try{const o=JSON.parse(n),s=_(o);i.reject(s)}catch{i.reject(new Error("Failed to parse error from IPC"))}Reflect.deleteProperty(this.promisesByID,t)}}destroy(){for(const{promise:e,timeoutId:t}of Object.values(this.promisesByID))clearTimeout(t),e.reject(new Error("IPC destroyed"));this.promisesByID={},this.receiversByName={}}},Ne=64,de=new Set(["auto","prompt"]),S=(e,t)=>{const n=e[t];if(!(typeof n!="string"||n.length===0))return n.slice(0,64)};function ge(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;const t=e,n=S(t,"version"),i=S(t,"commitHash");if(n===void 0||i===void 0)return null;const a={version:n,commitHash:i};typeof t.swControlled=="boolean"&&(a.swControlled=t.swControlled),de.has(t.pwaUpdateMode)&&(a.pwaUpdateMode=t.pwaUpdateMode);const o=S(t,"adapterVersion");return o!==void 0&&(a.adapterVersion=o),a}function ue(e){return typeof e!="string"||e.length===0?null:e.slice(0,64)}function He(e,t){if(!e)return`getInitConfig from sidebar build unknown (no valid build report — sidebar predates build reporting; host adapter ${t})`;const n=[e.commitHash];return e.swControlled!==void 0&&n.push(e.swControlled?"sw-controlled":"network"),e.pwaUpdateMode&&n.push(`${e.pwaUpdateMode} update mode`),e.adapterVersion&&n.push(`sidebar adapter ${e.adapterVersion}`),n.push(`host adapter ${t}`),`getInitConfig from sidebar v${e.version} (${n.join(", ")})`}var k=class{ipc;sidebar;targetOrigin;latestHostAdapterVersion=null;constructor(e,t,n="*"){this.sidebar=e||{},this.targetOrigin=n,this.ipc=new b(i=>{window.parent.postMessage(i,this.targetOrigin)},t),window.addEventListener("message",this.handleMessage),this.registerReceivers()}handleMessage=e=>{const t=globalThis.window.location.origin,n=this.targetOrigin;e.origin!==t&&(n!=="*"&&e.origin!==n||e.data&&typeof e.data=="object"&&this.ipc.handleMessage(e.data))};registerReceivers(){if(this.sidebar.onPluginStatusChange){const e=this.sidebar.onPluginStatusChange;this.ipc.receive("onPluginStatusChange",async(t,n)=>{await e(t,n)})}if(this.sidebar.activateAgenticIssue){const e=this.sidebar.activateAgenticIssue;this.ipc.receive("activateAgenticIssue",async(t,n)=>{await e(t,typeof n=="string"?n:null)})}if(this.sidebar.invalidateAgenticIssue){const e=this.sidebar.invalidateAgenticIssue;this.ipc.receive("invalidateAgenticIssue",async t=>{await e(t)})}if(this.sidebar.markAgenticIssueResolved){const e=this.sidebar.markAgenticIssueResolved;this.ipc.receive("markAgenticIssueResolved",async t=>{await e(t)})}if(this.sidebar.restoreAgenticIssue){const e=this.sidebar.restoreAgenticIssue;this.ipc.receive("restoreAgenticIssue",async t=>{await e(t)})}if(this.sidebar.applyIntegrationSettings){const e=this.sidebar.applyIntegrationSettings;this.ipc.receive("applyIntegrationSettings",async t=>{await e(t)})}if(this.sidebar.getIntegrationSettings){const e=this.sidebar.getIntegrationSettings;this.ipc.receive("getIntegrationSettings",async()=>await e())}if(this.sidebar.onActiveDocumentChanged){const e=this.sidebar.onActiveDocumentChanged;this.ipc.receive("onActiveDocumentChanged",async t=>{await e(t)})}}async getInitConfig(e){const{hostAdapterVersion:t,...n}=e?await this.ipc.call("getInitConfig",{...e,adapterVersion:e.adapterVersion??"2.4.0"}):await this.ipc.call("getInitConfig");return this.latestHostAdapterVersion=ue(t),n}getHostAdapterVersion(){return this.latestHostAdapterVersion}async getContent(e){return this.ipc.callWithOptions("getContent",e??{})}async getSelectedContent(e){return this.ipc.callWithOptions("getSelectedContent",e??{})}async replaceContent(e,t,n=null){await this.ipc.call("replaceContent",e,t,n)}async selectContent(e,t=null){await this.ipc.call("selectContent",e,t)}async replaceMultipleContents(e){await this.ipc.call("replaceMultipleContents",e)}async onAgenticAgentResults(e,t,n=null){await this.ipc.call("onAgenticAgentResults",e,t,n)}async onAgenticStreamComplete(e=null){await this.ipc.call("onAgenticStreamComplete",e)}async onAgenticIssueStatusChanged(e,t,n){await this.ipc.call("onAgenticIssueStatusChanged",e,t,n)}async onAgenticIssuesCleared(e=null){await this.ipc.call("onAgenticIssuesCleared",e)}async openAuthUrl(e){await this.ipc.call("openAuthUrl",e)}async copyToClipboard(e){await this.ipc.call("copyToClipboard",e)}async addComment(e,t=null){await this.ipc.call("addComment",e,t)}async onIntegrationSettingsChange(e,t){await this.ipc.call("onIntegrationSettingsChange",e,t)}configure(e){this.ipc.configure(e)}setTargetOrigin(e){if(!e||typeof e!="string")throw new Error("Invalid targetOrigin: must be a non-empty string");try{const t=new URL(e);if(!["http:","https:"].includes(t.protocol)||!t.host)throw new Error("Invalid targetOrigin: protocol must be http or https and must have a host")}catch{throw new Error("Invalid targetOrigin: must be a valid origin (e.g., https://example.com)")}this.targetOrigin=e}getTargetOrigin(){return this.targetOrigin}destroy(){window.removeEventListener("message",this.handleMessage),this.ipc.destroy()}},pe=class{ipcAdapter;constructor(e,t,n){this.ipcAdapter=new k(e,t,n)}destroy(){this.ipcAdapter.destroy()}async getInitConfig(e){return await this.ipcAdapter.getInitConfig(e)}getHostAdapterVersion(){return this.ipcAdapter.getHostAdapterVersion()}async getContent(e){return await this.ipcAdapter.getContent(e)}async getSelectedContent(e){return await this.ipcAdapter.getSelectedContent(e)}async replaceContent(e,t,n=null){await this.ipcAdapter.replaceContent(e,t,n)}async selectContent(e,t=null){await this.ipcAdapter.selectContent(e,t)}async replaceMultipleContents(e){await this.ipcAdapter.replaceMultipleContents(e)}onAgenticAgentResults(e,t,n=null){return this.ipcAdapter.onAgenticAgentResults(e,t,n)}onAgenticStreamComplete(e=null){return this.ipcAdapter.onAgenticStreamComplete(e)}onAgenticIssueStatusChanged(e,t,n){return this.ipcAdapter.onAgenticIssueStatusChanged(e,t,n)}onAgenticIssuesCleared(e=null){return this.ipcAdapter.onAgenticIssuesCleared(e)}openAuthUrl(e){return this.ipcAdapter.openAuthUrl(e)}copyToClipboard(e){return this.ipcAdapter.copyToClipboard(e)}addComment(e,t=null){return this.ipcAdapter.addComment(e,t)}onIntegrationSettingsChange(e,t){return this.ipcAdapter.onIntegrationSettingsChange(e,t)}configure(e){this.ipcAdapter.configure(e)}setTargetOrigin(e){this.ipcAdapter.setTargetOrigin(e)}getTargetOrigin(){return this.ipcAdapter.getTargetOrigin()}},N=class{ipc;plugin;iframe;window;targetOrigin;latestSidebarBuildInfo=null;constructor(e,t,n,i,a="*"){this.plugin=e,this.iframe=t,this.window=n??window,this.targetOrigin=a,this.ipc=new b(o=>{this.iframe.contentWindow?.postMessage(o,this.targetOrigin)},i),this.window.addEventListener("message",this.handleMessage,!1),this.registerReceivers()}handleMessage=e=>{const t=this.window.location.origin,n=this.targetOrigin;e.origin!==t&&(n!=="*"&&e.origin!==n||e.data&&typeof e.data=="object"&&this.ipc.handleMessage(e.data))};registerReceivers(){if(this.ipc.receive("getInitConfig",async e=>{const t=ge(e);return this.latestSidebarBuildInfo=t,{...await this.plugin.getInitConfig(t??void 0),hostAdapterVersion:R}}),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)=>{await this.plugin.replaceContent(e,t,typeof n=="string"?n:null)}),this.ipc.receive("selectContent",async(e,t)=>{await this.plugin.selectContent(e,typeof t=="string"?t:null)}),this.ipc.receive("replaceMultipleContents",async e=>{await this.plugin.replaceMultipleContents(e)}),this.ipc.receive("onAgenticAgentResults",async(e,t,n)=>{if(!Array.isArray(t))return;const i=this.plugin.onAgenticAgentResults;i&&await i(e,t,typeof n=="string"?n:null)}),this.ipc.receive("onAgenticStreamComplete",async e=>{const t=this.plugin.onAgenticStreamComplete;t&&await t(typeof e=="string"?e:null)}),this.ipc.receive("onAgenticIssueStatusChanged",async(e,t,n)=>{const i=this.plugin.onAgenticIssueStatusChanged;if(i&&!(t!=="active"&&t!=="resolved"&&t!=="dismissed"||n!=="user"&&n!=="host"))try{await i(e,t,n)}catch{}}),this.ipc.receive("onAgenticIssuesCleared",async e=>{const t=this.plugin.onAgenticIssuesCleared;if(t)try{await t(typeof e=="string"?e:null)}catch{}}),this.plugin.openAuthUrl){const e=this.plugin.openAuthUrl;this.ipc.receive("openAuthUrl",async t=>{await e(t)})}if(this.plugin.copyToClipboard){const e=this.plugin.copyToClipboard;this.ipc.receive("copyToClipboard",async t=>{await e(t)})}if(this.plugin.addComment){const e=this.plugin.addComment;this.ipc.receive("addComment",async(t,n)=>{await e(t,typeof n=="string"?n:null)})}if(this.plugin.onIntegrationSettingsChange){const e=this.plugin.onIntegrationSettingsChange;this.ipc.receive("onIntegrationSettingsChange",async(t,n)=>{await e(t,n)})}}async activateAgenticIssue(e,t=null){await this.ipc.call("activateAgenticIssue",e,t)}async invalidateAgenticIssue(e){await this.ipc.call("invalidateAgenticIssue",e)}async markAgenticIssueResolved(e){await this.ipc.call("markAgenticIssueResolved",e)}async restoreAgenticIssue(e){await this.ipc.call("restoreAgenticIssue",e)}async notifyPluginStatus(e,t){await this.ipc.call("onPluginStatusChange",e,t)}async applyIntegrationSettings(e){await this.ipc.call("applyIntegrationSettings",e)}async getIntegrationSettings(){return await this.ipc.call("getIntegrationSettings")}async notifyActiveDocumentChanged(e){await this.ipc.call("onActiveDocumentChanged",e)}getSidebarBuildInfo(){return this.latestSidebarBuildInfo}configure(e){this.ipc.configure(e)}destroy(){this.window.removeEventListener("message",this.handleMessage),this.ipc.destroy()}},H=class{ipcAdapter;constructor(e,t,n){this.ipcAdapter=new N(e,t,n?.win,n?.config,n?.targetOrigin)}destroy(){this.ipcAdapter.destroy()}async notifyPluginStatus(e,t){await this.ipcAdapter.notifyPluginStatus(e,t)}async activateAgenticIssue(e,t=null){await this.ipcAdapter.activateAgenticIssue(e,t)}async invalidateAgenticIssue(e){await this.ipcAdapter.invalidateAgenticIssue(e)}async markAgenticIssueResolved(e){await this.ipcAdapter.markAgenticIssueResolved(e)}async restoreAgenticIssue(e){await this.ipcAdapter.restoreAgenticIssue(e)}async applyIntegrationSettings(e){await this.ipcAdapter.applyIntegrationSettings(e)}async getIntegrationSettings(){return await this.ipcAdapter.getIntegrationSettings()}async notifyActiveDocumentChanged(e){await this.ipcAdapter.notifyActiveDocumentChanged(e)}getSidebarBuildInfo(){return this.ipcAdapter.getSidebarBuildInfo()}configure(e){this.ipcAdapter.configure(e)}},he=`
1
+ (function(o,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(o=typeof globalThis<"u"?globalThis:o||self,u(o.main={}))})(this,function(o){Object.defineProperty(o,Symbol.toStringTag,{value:"Module"});var u=(function(e){return e.TEXT_PLAIN="text/plain",e.TEXT_MARKDOWN="text/markdown",e.TEXT_HTML="text/html",e.APPLICATION_DITA_XML="application/dita+xml",e})({}),se=["text/plain","text/markdown","text/html","application/dita+xml"],le={integrationName:"unknown",integrationVersion:"unknown",integrationId:"markupai-sidebar-app",hideBanner:!1,supportCheckSelection:!0,supportComments:!1,multiAgent:!1,multiDocument:!1},ce=e=>typeof e!="object"||e===null?!1:Array.isArray(e.fields),de=e=>{if(typeof e!="object"||e===null)return!1;const t=e;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=>{if(typeof r!="object"||r===null)return!1;const n=r;return typeof n.value=="string"&&typeof n.label=="string"}):!1},_="2.5.0",f=class ie extends Error{name="TextLookupError";constructor(t){super(t),Object.setPrototypeOf(this,ie.prototype)}},v=class ae extends f{name="ReplaceBatchError";applied;failed;constructor(t,r){super(t),this.applied=r.applied.map(n=>({start:n.start,end:n.end})),this.failed=r.failed.map(n=>D(n,n.message)),Object.setPrototypeOf(this,ae.prototype)}},C=class oe extends Error{name="IpcTimeoutError";constructor(t,r,n){super(`IPC call timeout: "${t}" did not respond within ${String(r)}ms`+(n===void 0?"":` (timeout ${String(n)} could not be used)`)),Object.setPrototypeOf(this,oe.prototype)}};function ge(e){return e instanceof C}function ue(e){return e instanceof v}function D(e,t){const r={start:e.start,end:e.end};return typeof t=="string"&&t.trim()!==""&&(r.message=t),r}function M(e){return Array.isArray(e)?e.flatMap(t=>{if(t===null||typeof t!="object")return[];const{start:r,end:n,message:i}=t;return typeof r!="number"||typeof n!="number"?[]:[{range:{start:r,end:n},message:i}]}):[]}function pe(e){return e instanceof f}var b={TextLookupError:e=>new f(e),ReplaceBatchError:(e,t)=>new v(e,{applied:M(t.applied).map(r=>r.range),failed:M(t.failed).map(r=>D(r.range,r.message))})};function L(e){const t=e.message??"",r=e.name,n=typeof r=="string"&&r in b?b[r]:void 0;return n?n(t,e):Object.assign(new Error(t),r?{name:r}:{})}var B=":",N=/^[a-z][a-z0-9-]*$/;function he(e){const t=e.indexOf(B);return t<=0||t===e.length-1?!1:N.test(e.slice(0,t))}function fe(e,t){const r=e.trim().toLowerCase(),n=t.trim();if(!N.test(r))throw new Error(`Invalid document reference prefix ${JSON.stringify(e)}: expected a lowercase name like "word".`);if(n.length===0)throw new Error("Invalid document reference: the document id is empty.");const i=`${r}${B}`;return n.startsWith(i)?n:`${i}${n}`}var k=class extends Promise{static get[Symbol.species](){return Promise}resolve;reject;constructor(e=()=>{}){let t,r;super((n,i)=>{t=n,r=i,e(n,i)}),this.resolve=t,this.reject=r}},S={timeout:1e4};function w(e,t){try{e?.(t)}catch{}}function me(e){const t=typeof e=="object"&&e!==null?Object.fromEntries(Object.getOwnPropertyNames(e).map(s=>[s,e[s]])):{},r=e instanceof Error?e.message:String(e),n=typeof t.message=="string"&&t.message!==""?t.message:r,i=e instanceof Error?e.name:void 0,a=typeof t.name=="string"?t.name:i;return JSON.stringify({...t,message:n,...a!==void 0&&{name:a}})}function Ie(e){try{return L(JSON.parse(e))}catch{return new Error("Failed to parse error from IPC")}}var U=3e5,H=2147483647;function ye(e,t){const r=i=>!Number.isNaN(i)&&i>0;let n=S.timeout;return r(e)?n=e:r(t)&&(n=t),Math.min(Math.max(1,Math.ceil(n)),H)}var E=class{promisesByID={};receiversByName={};progressReceiverNames=new Set;currentID=0;config;postMessage;constructor(e,t){this.postMessage=e,this.config={...S,...t}}configure(e){this.config={...this.config,...e}}call(e,...t){return this.callWithOptions(e,{},...t)}callWithOptions(e,t,...r){const n=t.timeout??this.config.timeout,i=ye(n,this.config.timeout),a=this.currentID++,s=new k,l=setTimeout(()=>{if(a in this.promisesByID)if(s.reject(new C(e,i,i===n?void 0:n)),t.onProgress||t.onLateResult){const d=this.promisesByID[a];d.timedOut=!0,d.timeoutId=setTimeout(()=>{this.promisesByID[a]===d&&Reflect.deleteProperty(this.promisesByID,a)},U)}else Reflect.deleteProperty(this.promisesByID,a)},i);this.promisesByID[a]={promise:s,timeoutId:l,onProgress:t.onProgress,onLateResult:t.onLateResult,timedOut:!1};const c={type:"call",id:a,name:e,data:r};return this.postMessage(c),s}receive(e,t){this.receiversByName[e]=t,this.progressReceiverNames.delete(e)}receiveWithProgress(e,t){this.receiversByName[e]=t,this.progressReceiverNames.add(e)}ignore(e){delete this.receiversByName[e],this.progressReceiverNames.delete(e)}async handleMessage(e){switch(e.type){case"call":await this.handleCall(e);break;case"response":this.handleResponse(e);break;case"error":this.handleError(e);break;case"progress":this.handleProgress(e);break;default:}}async handleCall(e){const{id:t,name:r,data:n}=e;if(!(r in this.receiversByName)){const l=new Error(`No receiver registered for: ${r}`),c=JSON.stringify({message:l.message,name:l.name});this.postMessage({type:"error",id:t,name:r,errorJSON:c});return}const i=this.receiversByName[r];let a=!1;const s=l=>{if(!a)try{this.postMessage({type:"progress",id:t,name:r,data:l})}catch{}};try{if(!Array.isArray(n))throw new TypeError(`IPC: Expected array of arguments but got ${typeof n}`);const l=n,c=await(this.progressReceiverNames.has(r)?i(s,...l):i(...l));a=!0;const d={type:"response",id:t,name:r,data:c};this.postMessage(d)}catch(l){a=!0;const c={type:"error",id:t,name:r,errorJSON:me(l)};this.postMessage(c)}}handleResponse(e){const{id:t}=e;if(t in this.promisesByID){const{promise:r,timeoutId:n,timedOut:i,onLateResult:a}=this.promisesByID[t];if(clearTimeout(n),Reflect.deleteProperty(this.promisesByID,t),i){w(a,{status:"success"});return}r.resolve(e.data)}}handleError(e){const{id:t,errorJSON:r}=e;if(t in this.promisesByID){const{promise:n,timeoutId:i,timedOut:a,onLateResult:s}=this.promisesByID[t];clearTimeout(i),Reflect.deleteProperty(this.promisesByID,t);const l=Ie(r);if(a){w(s,{status:"error",error:l});return}n.reject(l)}}handleProgress(e){const{id:t}=e;t in this.promisesByID&&w(this.promisesByID[t].onProgress,e.data)}destroy(){for(const{promise:e,timeoutId:t}of Object.values(this.promisesByID))clearTimeout(t),e.reject(new Error("IPC destroyed"));this.promisesByID={},this.receiversByName={},this.progressReceiverNames.clear()}};function Ae(e){if(typeof e!="object"||e===null)return!1;const{start:t,end:r}=e;return typeof t=="number"&&typeof r=="number"}var F=e=>`${String(e.start)}:${String(e.end)}`;function ve(e,t){if(typeof e!="object"||e===null)return null;const{total:r,applied:n}=e;if(typeof r!="number"||!Array.isArray(n)||!n.every(Ae))return null;const i=new Set(t.map(({range:a})=>F(a)));return{total:r,applied:n.filter(a=>i.has(F(a))).map(({start:a,end:s})=>({start:a,end:s}))}}var Ye=64,Ce=new Set(["auto","prompt"]),P=(e,t)=>{const r=e[t];if(!(typeof r!="string"||r.length===0))return r.slice(0,64)};function be(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;const t=e,r=P(t,"version"),n=P(t,"commitHash");if(r===void 0||n===void 0)return null;const i={version:r,commitHash:n};typeof t.swControlled=="boolean"&&(i.swControlled=t.swControlled),Ce.has(t.pwaUpdateMode)&&(i.pwaUpdateMode=t.pwaUpdateMode);const a=P(t,"adapterVersion");return a!==void 0&&(i.adapterVersion=a),i}function Se(e){return typeof e!="string"||e.length===0?null:e.slice(0,64)}function Xe(e,t){if(!e)return`getInitConfig from sidebar build unknown (no valid build report — sidebar predates build reporting; host adapter ${t})`;const r=[e.commitHash];return e.swControlled!==void 0&&r.push(e.swControlled?"sw-controlled":"network"),e.pwaUpdateMode&&r.push(`${e.pwaUpdateMode} update mode`),e.adapterVersion&&r.push(`sidebar adapter ${e.adapterVersion}`),r.push(`host adapter ${t}`),`getInitConfig from sidebar v${e.version} (${r.join(", ")})`}var $=class{ipc;sidebar;targetOrigin;latestHostAdapterVersion=null;constructor(e,t,r="*"){this.sidebar=e||{},this.targetOrigin=r,this.ipc=new E(n=>{window.parent.postMessage(n,this.targetOrigin)},t),window.addEventListener("message",this.handleMessage),this.registerReceivers()}handleMessage=e=>{const t=globalThis.window.location.origin,r=this.targetOrigin;e.origin!==t&&(r!=="*"&&e.origin!==r||e.data&&typeof e.data=="object"&&this.ipc.handleMessage(e.data))};registerReceivers(){if(this.sidebar.onPluginStatusChange){const e=this.sidebar.onPluginStatusChange;this.ipc.receive("onPluginStatusChange",async(t,r)=>{await e(t,r)})}if(this.sidebar.activateAgenticIssue){const e=this.sidebar.activateAgenticIssue;this.ipc.receive("activateAgenticIssue",async(t,r)=>{await e(t,typeof r=="string"?r:null)})}if(this.sidebar.invalidateAgenticIssue){const e=this.sidebar.invalidateAgenticIssue;this.ipc.receive("invalidateAgenticIssue",async t=>{await e(t)})}if(this.sidebar.markAgenticIssueResolved){const e=this.sidebar.markAgenticIssueResolved;this.ipc.receive("markAgenticIssueResolved",async t=>{await e(t)})}if(this.sidebar.restoreAgenticIssue){const e=this.sidebar.restoreAgenticIssue;this.ipc.receive("restoreAgenticIssue",async t=>{await e(t)})}if(this.sidebar.applyIntegrationSettings){const e=this.sidebar.applyIntegrationSettings;this.ipc.receive("applyIntegrationSettings",async t=>{await e(t)})}if(this.sidebar.getIntegrationSettings){const e=this.sidebar.getIntegrationSettings;this.ipc.receive("getIntegrationSettings",async()=>await e())}if(this.sidebar.onActiveDocumentChanged){const e=this.sidebar.onActiveDocumentChanged;this.ipc.receive("onActiveDocumentChanged",async t=>{await e(t)})}}async getInitConfig(e){const{hostAdapterVersion:t,...r}=e?await this.ipc.call("getInitConfig",{...e,adapterVersion:e.adapterVersion??"2.5.0"}):await this.ipc.call("getInitConfig");return this.latestHostAdapterVersion=Se(t),r}getHostAdapterVersion(){return this.latestHostAdapterVersion}async getContent(e){return this.ipc.callWithOptions("getContent",e??{})}async getSelectedContent(e){return this.ipc.callWithOptions("getSelectedContent",e??{})}async replaceContent(e,t,r=null){await this.ipc.call("replaceContent",e,t,r)}async selectContent(e,t=null){await this.ipc.call("selectContent",e,t)}async replaceMultipleContents(e,t){const{onProgress:r,...n}=t??{};await this.ipc.callWithOptions("replaceMultipleContents",{...n,...r&&{onProgress:i=>{const a=ve(i,e);a&&r(a)}}},e)}async onAgenticAgentResults(e,t,r=null){await this.ipc.call("onAgenticAgentResults",e,t,r)}async onAgenticStreamComplete(e=null){await this.ipc.call("onAgenticStreamComplete",e)}async onAgenticIssueStatusChanged(e,t,r){await this.ipc.call("onAgenticIssueStatusChanged",e,t,r)}async onAgenticIssuesCleared(e=null){await this.ipc.call("onAgenticIssuesCleared",e)}async openAuthUrl(e){await this.ipc.call("openAuthUrl",e)}async copyToClipboard(e){await this.ipc.call("copyToClipboard",e)}async addComment(e,t=null){await this.ipc.call("addComment",e,t)}async onIntegrationSettingsChange(e,t){await this.ipc.call("onIntegrationSettingsChange",e,t)}configure(e){this.ipc.configure(e)}setTargetOrigin(e){if(!e||typeof e!="string")throw new Error("Invalid targetOrigin: must be a non-empty string");try{const t=new URL(e);if(!["http:","https:"].includes(t.protocol)||!t.host)throw new Error("Invalid targetOrigin: protocol must be http or https and must have a host")}catch{throw new Error("Invalid targetOrigin: must be a valid origin (e.g., https://example.com)")}this.targetOrigin=e}getTargetOrigin(){return this.targetOrigin}destroy(){window.removeEventListener("message",this.handleMessage),this.ipc.destroy()}},we=class{ipcAdapter;constructor(e,t,r){this.ipcAdapter=new $(e,t,r)}destroy(){this.ipcAdapter.destroy()}async getInitConfig(e){return await this.ipcAdapter.getInitConfig(e)}getHostAdapterVersion(){return this.ipcAdapter.getHostAdapterVersion()}async getContent(e){return await this.ipcAdapter.getContent(e)}async getSelectedContent(e){return await this.ipcAdapter.getSelectedContent(e)}async replaceContent(e,t,r=null){await this.ipcAdapter.replaceContent(e,t,r)}async selectContent(e,t=null){await this.ipcAdapter.selectContent(e,t)}async replaceMultipleContents(e,t){await this.ipcAdapter.replaceMultipleContents(e,t)}onAgenticAgentResults(e,t,r=null){return this.ipcAdapter.onAgenticAgentResults(e,t,r)}onAgenticStreamComplete(e=null){return this.ipcAdapter.onAgenticStreamComplete(e)}onAgenticIssueStatusChanged(e,t,r){return this.ipcAdapter.onAgenticIssueStatusChanged(e,t,r)}onAgenticIssuesCleared(e=null){return this.ipcAdapter.onAgenticIssuesCleared(e)}openAuthUrl(e){return this.ipcAdapter.openAuthUrl(e)}copyToClipboard(e){return this.ipcAdapter.copyToClipboard(e)}addComment(e,t=null){return this.ipcAdapter.addComment(e,t)}onIntegrationSettingsChange(e,t){return this.ipcAdapter.onIntegrationSettingsChange(e,t)}configure(e){this.ipcAdapter.configure(e)}setTargetOrigin(e){this.ipcAdapter.setTargetOrigin(e)}getTargetOrigin(){return this.ipcAdapter.getTargetOrigin()}},j=class{ipc;plugin;iframe;window;targetOrigin;latestSidebarBuildInfo=null;constructor(e,t,r,n,i="*"){this.plugin=e,this.iframe=t,this.window=r??window,this.targetOrigin=i,this.ipc=new E(a=>{this.iframe.contentWindow?.postMessage(a,this.targetOrigin)},n),this.window.addEventListener("message",this.handleMessage,!1),this.registerReceivers()}handleMessage=e=>{const t=this.window.location.origin,r=this.targetOrigin;e.origin!==t&&(r!=="*"&&e.origin!==r||e.data&&typeof e.data=="object"&&this.ipc.handleMessage(e.data))};registerReceivers(){if(this.ipc.receive("getInitConfig",async e=>{const t=be(e);return this.latestSidebarBuildInfo=t,{...await this.plugin.getInitConfig(t??void 0),hostAdapterVersion:_}}),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)=>{await this.plugin.replaceContent(e,t,typeof r=="string"?r:null)}),this.ipc.receive("selectContent",async(e,t)=>{await this.plugin.selectContent(e,typeof t=="string"?t:null)}),this.ipc.receiveWithProgress("replaceMultipleContents",async(e,t)=>{await this.plugin.replaceMultipleContents(t,{reportProgress:e})}),this.ipc.receive("onAgenticAgentResults",async(e,t,r)=>{if(!Array.isArray(t))return;const n=this.plugin.onAgenticAgentResults;n&&await n(e,t,typeof r=="string"?r:null)}),this.ipc.receive("onAgenticStreamComplete",async e=>{const t=this.plugin.onAgenticStreamComplete;t&&await t(typeof e=="string"?e:null)}),this.ipc.receive("onAgenticIssueStatusChanged",async(e,t,r)=>{const n=this.plugin.onAgenticIssueStatusChanged;if(n&&!(t!=="active"&&t!=="resolved"&&t!=="dismissed"||r!=="user"&&r!=="host"))try{await n(e,t,r)}catch{}}),this.ipc.receive("onAgenticIssuesCleared",async e=>{const t=this.plugin.onAgenticIssuesCleared;if(t)try{await t(typeof e=="string"?e:null)}catch{}}),this.plugin.openAuthUrl){const e=this.plugin.openAuthUrl;this.ipc.receive("openAuthUrl",async t=>{await e(t)})}if(this.plugin.copyToClipboard){const e=this.plugin.copyToClipboard;this.ipc.receive("copyToClipboard",async t=>{await e(t)})}if(this.plugin.addComment){const e=this.plugin.addComment;this.ipc.receive("addComment",async(t,r)=>{await e(t,typeof r=="string"?r:null)})}if(this.plugin.onIntegrationSettingsChange){const e=this.plugin.onIntegrationSettingsChange;this.ipc.receive("onIntegrationSettingsChange",async(t,r)=>{await e(t,r)})}}async activateAgenticIssue(e,t=null){await this.ipc.call("activateAgenticIssue",e,t)}async invalidateAgenticIssue(e){await this.ipc.call("invalidateAgenticIssue",e)}async markAgenticIssueResolved(e){await this.ipc.call("markAgenticIssueResolved",e)}async restoreAgenticIssue(e){await this.ipc.call("restoreAgenticIssue",e)}async notifyPluginStatus(e,t){await this.ipc.call("onPluginStatusChange",e,t)}async applyIntegrationSettings(e){await this.ipc.call("applyIntegrationSettings",e)}async getIntegrationSettings(){return await this.ipc.call("getIntegrationSettings")}async notifyActiveDocumentChanged(e){await this.ipc.call("onActiveDocumentChanged",e)}getSidebarBuildInfo(){return this.latestSidebarBuildInfo}configure(e){this.ipc.configure(e)}destroy(){this.window.removeEventListener("message",this.handleMessage),this.ipc.destroy()}},x=class{ipcAdapter;constructor(e,t,r){this.ipcAdapter=new j(e,t,r?.win,r?.config,r?.targetOrigin)}destroy(){this.ipcAdapter.destroy()}async notifyPluginStatus(e,t){await this.ipcAdapter.notifyPluginStatus(e,t)}async activateAgenticIssue(e,t=null){await this.ipcAdapter.activateAgenticIssue(e,t)}async invalidateAgenticIssue(e){await this.ipcAdapter.invalidateAgenticIssue(e)}async markAgenticIssueResolved(e){await this.ipcAdapter.markAgenticIssueResolved(e)}async restoreAgenticIssue(e){await this.ipcAdapter.restoreAgenticIssue(e)}async applyIntegrationSettings(e){await this.ipcAdapter.applyIntegrationSettings(e)}async getIntegrationSettings(){return await this.ipcAdapter.getIntegrationSettings()}async notifyActiveDocumentChanged(e){await this.ipcAdapter.notifyActiveDocumentChanged(e)}getSidebarBuildInfo(){return this.ipcAdapter.getSidebarBuildInfo()}configure(e){this.ipcAdapter.configure(e)}},Ee=`
2
2
  <div class="sidebar-load-overlay-card">
3
3
  <div class="sidebar-load-overlay-title">Sidebar failed to load</div>
4
4
  <div class="sidebar-load-overlay-description">Check your connection or try again.</div>
@@ -19,7 +19,7 @@
19
19
  <span>Retry</span>
20
20
  </button>
21
21
  </div>
22
- `,fe=()=>{const e=document.createElement("div");e.className="sidebar-load-overlay",e.style.display="none",e.innerHTML=he;const t=e.querySelector(".sidebar-load-overlay-button");if(!t)throw new Error("Missing retry button in load overlay template.");return{overlay:e,button:t}},U="markupai-sidebar-load-overlay-styles",me=`
22
+ `,Pe=()=>{const e=document.createElement("div");e.className="sidebar-load-overlay",e.style.display="none",e.innerHTML=Ee;const t=e.querySelector(".sidebar-load-overlay-button");if(!t)throw new Error("Missing retry button in load overlay template.");return{overlay:e,button:t}},V="markupai-sidebar-load-overlay-styles",Re=`
23
23
  :root {
24
24
  --background: #f5f5f4;
25
25
  --foreground: #333332;
@@ -111,7 +111,7 @@
111
111
  box-shadow: 0 0 0 2px
112
112
  color-mix(in srgb, var(--accent, #ef4640) 60%, transparent);
113
113
  }
114
- `,Ie=e=>{const t=e??document;if(t.getElementById(U))return;const n=t.createElement("style");n.id=U,n.textContent=me,t.head.appendChild(n)},ye=8e3,Ae=12e3,F=(e,t,n={})=>{Ie(e.ownerDocument);const{sidebarUrl:i,targetOrigin:a,timeoutMs:o=ye,retryIntervalMs:s=Ae,messageListenWindow:l}=n,c=l??(typeof globalThis.window<"u"?globalThis.window:globalThis),f=()=>i??t.src,Be=()=>{if(a)return a;try{return new URL(f()).origin}catch{return"*"}},{overlay:P,button:z}=fe();e.appendChild(P);let m=!1,I,u;const p=d=>{P.style.display=d?"flex":"none"};p(!1);const y=()=>{I&&(globalThis.clearTimeout(I),I=void 0)},Y=()=>{y(),I=globalThis.setTimeout(()=>{m||p(!0)},o)},J=d=>{const A=d?.preserveOverlay??!0;m=!1,A||p(!1),t.src=f(),Y()},ke=()=>{u||s<=0||(u=globalThis.setInterval(()=>{m||J({preserveOverlay:!0})},s))},X=()=>{u&&(globalThis.clearInterval(u),u=void 0)},K=d=>{if(!t.contentWindow||d.source!==t.contentWindow)return;const A=Be();A!=="*"&&d.origin!==A||(m=!0,y(),X(),p(!1))},q=()=>{y(),p(!0)},Z=()=>{J()};return z.addEventListener("click",Z),t.addEventListener("error",q),c.addEventListener("message",K),Y(),ke(),()=>{y(),X(),t.removeEventListener("error",q),c.removeEventListener("message",K),z.removeEventListener("click",Z),P.remove()}},x="Markup AI Sidebar",$="clipboard-read; clipboard-write",ve="markupai.sidebarNextGen.overrideUrl",Ce="https://sidebar.markup.ai/";function be(e){try{return"localStorage"in globalThis&&globalThis.localStorage.getItem("markupai.sidebarNextGen.overrideUrl")?.trim()||e}catch{return e}}var j="markupai.sidebarNextGen.authOverride";function Se(e,t){if(!t)return e;try{if(!("localStorage"in globalThis))return e;const n=globalThis.localStorage.getItem(j)?.trim();if(!n)return e;const i=JSON.parse(n);return i!==null&&typeof i=="object"&&"type"in i&&(i.type==="mediation"||i.type==="popup")?i:e}catch{return e}}function we(e,t){try{return new URL(e).origin}catch(n){return t?.onInvalidUrl?.(e,n),"*"}}function Ee(e,t="Expected SidebarAdapter from createSidebarHost"){if(e.adapter===null)throw new Error(t)}function Pe(e){const{iframe:t,iframeMount:n}=e;if(t!==void 0&&n!==void 0)throw new Error("createSidebarHost: pass only one of `iframe` or `iframeMount`");if(t!==void 0)return{iframe:t,removeMountedIframe:null};if(n===void 0)throw new Error("createSidebarHost: pass either `iframe` or `iframeMount`");const{container:i,src:a,allow:o=$}=n,s=document.createElement("iframe");return s.title=x,s.src=a,o&&s.setAttribute("allow",o),i.appendChild(s),{iframe:s,removeMountedIframe:()=>{s.remove()}}}function Re(e){const{plugin:t,loadOverlayContainer:n,loadOverlayOptions:i,adapterOptions:a}=e,{iframe:o,removeMountedIframe:s}=Pe(e),l=n!==void 0?F(n,o,i??{}):null;if(t!==void 0){const c=new H(t,o,a);return{iframe:o,adapter:c,destroy:()=>{l?.(),c.destroy(),s?.()}}}return{iframe:o,adapter:null,destroy:()=>{l?.(),s?.()}}}var w="sidebarContainer",V="markupai-sidebar-host-shell-styles";function G(e){if(typeof CSS<"u"&&typeof CSS.escape=="function")return CSS.escape(e);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)})`);return e}function E(e=w){const t=G(e);return`
114
+ `,Te=e=>{const t=e??document;if(t.getElementById(V))return;const r=t.createElement("style");r.id=V,r.textContent=Re,t.head.appendChild(r)},Oe=8e3,_e=12e3,W=(e,t,r={})=>{Te(e.ownerDocument);const{sidebarUrl:n,targetOrigin:i,timeoutMs:a=Oe,retryIntervalMs:s=_e,messageListenWindow:l}=r,c=l??(typeof globalThis.window<"u"?globalThis.window:globalThis),d=()=>n??t.src,Ge=()=>{if(i)return i;try{return new URL(d()).origin}catch{return"*"}},{overlay:O,button:q}=Pe();e.appendChild(O);let m=!1,I,p;const h=g=>{O.style.display=g?"flex":"none"};h(!1);const y=()=>{I&&(globalThis.clearTimeout(I),I=void 0)},Z=()=>{y(),I=globalThis.setTimeout(()=>{m||h(!0)},a)},Q=g=>{const A=g?.preserveOverlay??!0;m=!1,A||h(!1),t.src=d(),Z()},ze=()=>{p||s<=0||(p=globalThis.setInterval(()=>{m||Q({preserveOverlay:!0})},s))},ee=()=>{p&&(globalThis.clearInterval(p),p=void 0)},te=g=>{if(!t.contentWindow||g.source!==t.contentWindow)return;const A=Ge();A!=="*"&&g.origin!==A||(m=!0,y(),ee(),h(!1))},re=()=>{y(),h(!0)},ne=()=>{Q()};return q.addEventListener("click",ne),t.addEventListener("error",re),c.addEventListener("message",te),Z(),ze(),()=>{y(),ee(),t.removeEventListener("error",re),c.removeEventListener("message",te),q.removeEventListener("click",ne),O.remove()}},G="Markup AI Sidebar",z="clipboard-read; clipboard-write",De="markupai.sidebarNextGen.overrideUrl",Me="https://sidebar.markup.ai/";function Le(e){try{return"localStorage"in globalThis&&globalThis.localStorage.getItem("markupai.sidebarNextGen.overrideUrl")?.trim()||e}catch{return e}}var Y="markupai.sidebarNextGen.authOverride";function Be(e,t){if(!t)return e;try{if(!("localStorage"in globalThis))return e;const r=globalThis.localStorage.getItem(Y)?.trim();if(!r)return e;const n=JSON.parse(r);return n!==null&&typeof n=="object"&&"type"in n&&(n.type==="mediation"||n.type==="popup")?n:e}catch{return e}}function Ne(e,t){try{return new URL(e).origin}catch(r){return t?.onInvalidUrl?.(e,r),"*"}}function ke(e,t="Expected SidebarAdapter from createSidebarHost"){if(e.adapter===null)throw new Error(t)}function Ue(e){const{iframe:t,iframeMount:r}=e;if(t!==void 0&&r!==void 0)throw new Error("createSidebarHost: pass only one of `iframe` or `iframeMount`");if(t!==void 0)return{iframe:t,removeMountedIframe:null};if(r===void 0)throw new Error("createSidebarHost: pass either `iframe` or `iframeMount`");const{container:n,src:i,allow:a=z}=r,s=document.createElement("iframe");return s.title=G,s.src=i,a&&s.setAttribute("allow",a),n.appendChild(s),{iframe:s,removeMountedIframe:()=>{s.remove()}}}function He(e){const{plugin:t,loadOverlayContainer:r,loadOverlayOptions:n,adapterOptions:i}=e,{iframe:a,removeMountedIframe:s}=Ue(e),l=r!==void 0?W(r,a,n??{}):null;if(t!==void 0){const c=new x(t,a,i);return{iframe:a,adapter:c,destroy:()=>{l?.(),c.destroy(),s?.()}}}return{iframe:a,adapter:null,destroy:()=>{l?.(),s?.()}}}var R="sidebarContainer",X="markupai-sidebar-host-shell-styles";function J(e){if(typeof CSS<"u"&&typeof CSS.escape=="function")return CSS.escape(e);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)})`);return e}function T(e=R){const t=J(e);return`
115
115
  html {
116
116
  height: 100%;
117
117
  }
@@ -133,17 +133,17 @@ body {
133
133
  margin: 0;
134
134
  display: block;
135
135
  }
136
- `.trim()}var Te=E();function Oe(e){return e instanceof Document?e:e.ownerDocument}function _e(e,t,n){if(!t||e.getElementById(V))return;const i=e.createElement("style");i.id=V,i.textContent=E(n),e.head.appendChild(i)}function De(e){const{root:t=typeof document<"u"?document:void 0,containerId:n=w,includeDefaultStyles:i=!0}=e??{};if(t===void 0)throw new Error("ensureSidebarHostShell: no document — pass `root` in non-browser environments");const a=Oe(t);_e(a,i,n);const o=t instanceof Document?a.getElementById(n):t.querySelector(`#${G(n)}`);if(o instanceof HTMLElement&&(t instanceof Document||t.contains(o)))return o;if(!(t instanceof Document)){const l=a.createElement("div");return l.id=n,t.appendChild(l),l}const s=a.createElement("div");return s.id=n,a.body.appendChild(s),s}function W(){return' <meta name="viewport" content="width=device-width, initial-scale=1.0" />'}function Le(e){const{title:t="Markup AI Sidebar",headInnerHtml:n="",includePluginHostHead:i=!1,bodyScriptsHtml:a,htmlLang:o="en",htmlAttrs:s=`lang="${o}" style="height:100%"`,bodyAttrs:l='style="height:100%;margin:0"'}=e,c=[i?W():"",n].filter(f=>f.trim().length>0).join(`
136
+ `.trim()}var Fe=T();function $e(e){return e instanceof Document?e:e.ownerDocument}function je(e,t,r){if(!t||e.getElementById(X))return;const n=e.createElement("style");n.id=X,n.textContent=T(r),e.head.appendChild(n)}function xe(e){const{root:t=typeof document<"u"?document:void 0,containerId:r=R,includeDefaultStyles:n=!0}=e??{};if(t===void 0)throw new Error("ensureSidebarHostShell: no document — pass `root` in non-browser environments");const i=$e(t);je(i,n,r);const a=t instanceof Document?i.getElementById(r):t.querySelector(`#${J(r)}`);if(a instanceof HTMLElement&&(t instanceof Document||t.contains(a)))return a;if(!(t instanceof Document)){const l=i.createElement("div");return l.id=r,t.appendChild(l),l}const s=i.createElement("div");return s.id=r,i.body.appendChild(s),s}function K(){return' <meta name="viewport" content="width=device-width, initial-scale=1.0" />'}function Ve(e){const{title:t="Markup AI Sidebar",headInnerHtml:r="",includePluginHostHead:n=!1,bodyScriptsHtml:i,htmlLang:a="en",htmlAttrs:s=`lang="${a}" style="height:100%"`,bodyAttrs:l='style="height:100%;margin:0"'}=e,c=[n?K():"",r].filter(d=>d.trim().length>0).join(`
137
137
  `);return`<!DOCTYPE html>
138
138
  <html ${s}>
139
139
  <head>
140
140
  <base target="_top" />
141
141
  <meta charset="UTF-8" />
142
- <title>${Me(t)}</title>${c?`
142
+ <title>${We(t)}</title>${c?`
143
143
  ${c}`:""}
144
144
  </head>
145
145
  <body ${l}>
146
- ${a}
146
+ ${i}
147
147
  </body>
148
148
  </html>
149
- `}function Me(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}r.ADAPTER_VERSION=R,r.AUTH_CONFIG_OVERRIDE_STORAGE_KEY=j,r.DEFAULT_IPC_CONFIG=B,r.DEFAULT_SIDEBAR_CONFIG=ne,r.DeferredPromise=M,r.IPCCore=b,r.MimeType=g,r.PluginAdapter=pe,r.PluginIPCAdapter=k,r.ReplaceBatchError=v,r.SIDEBAR_DEFAULT_PRODUCTION_BASE_URL=Ce,r.SIDEBAR_HOST_CONTAINER_ID=w,r.SIDEBAR_HOST_SHELL_CSS=Te,r.SIDEBAR_IFRAME_DEFAULT_ALLOW=$,r.SIDEBAR_IFRAME_DEFAULT_TITLE=x,r.SIDEBAR_URL_OVERRIDE_STORAGE_KEY=ve,r.SidebarAdapter=H,r.SidebarIPCAdapter=N,r.TEXT_MIME_TYPES=te,r.TextLookupError=h,r.assertSidebarHostAdapter=Ee,r.buildDocumentReference=le,r.buildSidebarHostHtmlDocument=Le,r.buildSidebarHostShellCss=E,r.buildSidebarPluginHostHeadInnerHtml=W,r.createSidebarHost=Re,r.ensureSidebarHostShell=De,r.getAuthConfigWithOverride=Se,r.getSidebarBaseUrlWithOverride=be,r.ipcErrorReconstructors=C,r.isDocumentReference=se,r.isIntegrationSettingField=re,r.isIntegrationSettingsSchema=ie,r.isReplaceBatchError=ae,r.isTextLookupError=oe,r.reconstructError=_,r.setupSidebarLoadOverlay=F,r.sidebarPostMessageTargetOrigin=we});
149
+ `}function We(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}o.ADAPTER_VERSION=_,o.AUTH_CONFIG_OVERRIDE_STORAGE_KEY=Y,o.DEFAULT_IPC_CONFIG=S,o.DEFAULT_SIDEBAR_CONFIG=le,o.DeferredPromise=k,o.IPCCore=E,o.IpcTimeoutError=C,o.LATE_RESULT_WINDOW_MS=U,o.MAX_IPC_TIMEOUT_MS=H,o.MimeType=u,o.PluginAdapter=we,o.PluginIPCAdapter=$,o.ReplaceBatchError=v,o.SIDEBAR_DEFAULT_PRODUCTION_BASE_URL=Me,o.SIDEBAR_HOST_CONTAINER_ID=R,o.SIDEBAR_HOST_SHELL_CSS=Fe,o.SIDEBAR_IFRAME_DEFAULT_ALLOW=z,o.SIDEBAR_IFRAME_DEFAULT_TITLE=G,o.SIDEBAR_URL_OVERRIDE_STORAGE_KEY=De,o.SidebarAdapter=x,o.SidebarIPCAdapter=j,o.TEXT_MIME_TYPES=se,o.TextLookupError=f,o.assertSidebarHostAdapter=ke,o.buildDocumentReference=fe,o.buildSidebarHostHtmlDocument=Ve,o.buildSidebarHostShellCss=T,o.buildSidebarPluginHostHeadInnerHtml=K,o.createSidebarHost=He,o.ensureSidebarHostShell=xe,o.getAuthConfigWithOverride=Be,o.getSidebarBaseUrlWithOverride=Le,o.ipcErrorReconstructors=b,o.isDocumentReference=he,o.isIntegrationSettingField=de,o.isIntegrationSettingsSchema=ce,o.isIpcTimeoutError=ge,o.isReplaceBatchError=ue,o.isTextLookupError=pe,o.reconstructError=L,o.setupSidebarLoadOverlay=W,o.sidebarPostMessageTargetOrigin=Ne});
@@ -2,5 +2,6 @@ export * from "./common";
2
2
  export * from "./pluginInterface";
3
3
  export * from "./sidebarInterface";
4
4
  export * from "./integrationSettings";
5
+ export * from "./progress";
5
6
  export * from "./errors";
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAC;AAGzB,cAAc,mBAAmB,CAAC;AAGlC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,uBAAuB,CAAC;AAGtC,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAC;AAGzB,cAAc,mBAAmB,CAAC;AAGlC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,uBAAuB,CAAC;AAGtC,cAAc,YAAY,CAAC;AAG3B,cAAc,UAAU,CAAC"}
@@ -1,5 +1,14 @@
1
1
  import type { CommentRequest, ContentRange, ContentReplacement, ContentInfo, SidebarConfig, SidebarBuildInfo, AgenticIssuePayload } from "./common";
2
2
  import type { IntegrationSettingsValues, IntegrationSettingsChangeMeta } from "./integrationSettings";
3
+ import type { ReplaceProgress } from "./progress";
4
+ /** What the adapter hands the host with a `replaceMultipleContents` call. */
5
+ export interface ReplaceMultipleContext {
6
+ /**
7
+ * Report which places are replaced so far. Best effort: it never throws,
8
+ * returns nothing to wait for, and does not change the call's timeout.
9
+ */
10
+ reportProgress?: (progress: ReplaceProgress) => void;
11
+ }
3
12
  /**
4
13
  * Interface for the functions to implement in the Editor that the Sidebar will call via IPC
5
14
  * All methods return Promises for proper async handling
@@ -42,12 +51,14 @@ export interface PluginInterface {
42
51
  /**
43
52
  * Replace multiple contents in the editor
44
53
  * @param replacements - Array of content replacements to apply
54
+ * @param context - Created by the adapter; lets the host report progress. It
55
+ * is optional to use: a host with one parameter keeps working.
45
56
  * @returns Promise that resolves when all replacements are complete
46
57
  * @throws {ReplaceBatchError} When the batch could not be applied in full; carries
47
58
  * the ranges that were applied and the ones that failed (see ReplaceMultipleContentsError)
48
59
  * @throws {TextLookupError} When the batch failed and the host cannot say which ranges landed
49
60
  */
50
- replaceMultipleContents: (replacements: ContentReplacement[]) => Promise<void>;
61
+ replaceMultipleContents: (replacements: ContentReplacement[], context?: ReplaceMultipleContext) => Promise<void>;
51
62
  /**
52
63
  * Get initialization configuration from the editor
53
64
  * Called by the sidebar when it's ready to initialize — once per sidebar
@@ -1 +1 @@
1
- {"version":3,"file":"pluginInterface.d.ts","sourceRoot":"","sources":["../../src/types/pluginInterface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EACV,yBAAyB,EACzB,6BAA6B,EAC9B,MAAM,uBAAuB,CAAC;AAE/B;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IAEvC;;;;;OAKG;IACH,kBAAkB,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IAE/C;;;;;;;;OAQG;IACH,cAAc,EAAE,CACd,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,YAAY,EACnB,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,KAC9B,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnB;;;;;;;OAOG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzF;;;;;;;OAOG;IACH,uBAAuB,EAAE,CAAC,YAAY,EAAE,kBAAkB,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/E;;;;;;;;;;;;;;;;OAgBG;IACH,aAAa,EAAE,CAAC,gBAAgB,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IAE/E;;;;;;;;OAQG;IACH,qBAAqB,CAAC,EAAE,CACtB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,mBAAmB,EAAE,EAC7B,iBAAiB,EAAE,MAAM,GAAG,IAAI,KAC7B,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnB;;;;;OAKG;IACH,uBAAuB,CAAC,EAAE,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9E;;;;;;;;;;;OAWG;IACH,2BAA2B,CAAC,EAAE,CAC5B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,WAAW,EAC3C,MAAM,EAAE,MAAM,GAAG,MAAM,KACpB,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,sBAAsB,CAAC,EAAE,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7E;;;;;;;;;;;;;;;;;OAiBG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7C;;;;;;;;;;;;;;;;OAgBG;IACH,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAElD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3F;;;;;;;;;;;OAWG;IACH,2BAA2B,CAAC,EAAE,CAC5B,MAAM,EAAE,yBAAyB,EACjC,IAAI,EAAE,6BAA6B,KAChC,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB"}
1
+ {"version":3,"file":"pluginInterface.d.ts","sourceRoot":"","sources":["../../src/types/pluginInterface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EACV,yBAAyB,EACzB,6BAA6B,EAC9B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,6EAA6E;AAC7E,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;CACtD;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IAEvC;;;;;OAKG;IACH,kBAAkB,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IAE/C;;;;;;;;OAQG;IACH,cAAc,EAAE,CACd,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,YAAY,EACnB,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,KAC9B,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnB;;;;;;;OAOG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzF;;;;;;;;;OASG;IACH,uBAAuB,EAAE,CACvB,YAAY,EAAE,kBAAkB,EAAE,EAClC,OAAO,CAAC,EAAE,sBAAsB,KAC7B,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnB;;;;;;;;;;;;;;;;OAgBG;IACH,aAAa,EAAE,CAAC,gBAAgB,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IAE/E;;;;;;;;OAQG;IACH,qBAAqB,CAAC,EAAE,CACtB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,mBAAmB,EAAE,EAC7B,iBAAiB,EAAE,MAAM,GAAG,IAAI,KAC7B,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnB;;;;;OAKG;IACH,uBAAuB,CAAC,EAAE,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9E;;;;;;;;;;;OAWG;IACH,2BAA2B,CAAC,EAAE,CAC5B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,WAAW,EAC3C,MAAM,EAAE,MAAM,GAAG,MAAM,KACpB,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,sBAAsB,CAAC,EAAE,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7E;;;;;;;;;;;;;;;;;OAiBG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7C;;;;;;;;;;;;;;;;OAgBG;IACH,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAElD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3F;;;;;;;;;;;OAWG;IACH,2BAA2B,CAAC,EAAE,CAC5B,MAAM,EAAE,yBAAyB,EACjC,IAAI,EAAE,6BAA6B,KAChC,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB"}
@@ -0,0 +1,18 @@
1
+ import type { ContentRange } from "./common";
2
+ /**
3
+ * Wire shape of the `data` of a `progress` message for
4
+ * `replaceMultipleContents`: which places are in the document already.
5
+ *
6
+ * It carries no failures; those come with the error that ends the call. An
7
+ * empty `applied` says that the host is still working.
8
+ */
9
+ export interface ReplaceProgress {
10
+ /** How many places the host is replacing. */
11
+ total: number;
12
+ /**
13
+ * Every range replaced so far, as it was sent in the call. List a range only
14
+ * after its edit is in the document: the sidebar settles it at once.
15
+ */
16
+ applied: ContentRange[];
17
+ }
18
+ //# sourceMappingURL=progress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../src/types/progress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,OAAO,EAAE,YAAY,EAAE,CAAC;CACzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markupai/sidebar-adapter",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Adapter package for MarkupAI Sidebar integration",
5
5
  "keywords": [
6
6
  "markupai",
@@ -43,10 +43,10 @@
43
43
  "type-check": "tsc --project tsconfig.json --noEmit"
44
44
  },
45
45
  "devDependencies": {
46
- "@asyncapi/parser": "^3.6.3",
46
+ "@asyncapi/parser": "^3.6.4",
47
47
  "ajv": "^8.20.0",
48
48
  "ts-json-schema-generator": "^2.9.0",
49
- "tsc-alias": "1.9.7"
49
+ "tsc-alias": "1.9.8"
50
50
  },
51
51
  "publishConfig": {
52
52
  "access": "public"