import{$r as e,ii as t,ri as n,yr as r}from"./app-server-manager-signals-Yn0WSnoY.js";import{U as i}from"./vscode-api-DjORcpSo.js";import{r as a,t as o}from"./route-scope-CLteRG86.js";import{a as s,b as c,h as l,o as u,t as d,y as f}from"./mention-item-C-utQkFh.js";import{t as p}from"./external-link-source-DmXOJHWG.js";var m=i(`ComposerScope`,{key:h,parent:o,retain:{max:100}});function h(e){switch(e.kind){case`new`:return e.entrypoint===`home`?`new-conversation`:`panel-new-conversation`;case`local`:return`local:${e.conversationId}`;case`cloud`:return`cloud:${e.taskId}`;case`other`:return`other`}}function g(e,t=`main`,n=e){return{conversationId:e,kind:`local`,placement:t,routeConversationId:n}}function _(e){let t=a(e);switch(e.routeKind){case`home`:return{entrypoint:`home`,kind:`new`,routeConversationId:t};case`new-thread-panel`:return{entrypoint:`panel`,kind:`new`,routeConversationId:t};case`local-thread`:return g(e.conversationId);case`remote-thread`:return{kind:`cloud`,routeConversationId:t,taskId:e.taskId};case`other`:return{kind:`other`,routeConversationId:t}}}function v(e){let t=e.trim();if(t.length===0||/\s/u.test(t))return null;let n;try{n=new URL(t)}catch{return null}return n.protocol!==`http:`&&n.protocol!==`https:`?null:t}function y(e){let t=v(e);if(t==null)return null;let n=new URL(t),r=p(t);return r==null?null:{displayText:x(t,n,r),href:t,sourceAppId:r.appId}}function b({displayText:e,href:t}){let n;try{n=new URL(t)}catch{return null}if(n.protocol!==`http:`&&n.protocol!==`https:`)return null;let r=p(t);return r==null?null:{displayText:e,href:t,sourceAppId:r.appId}}function x(e,t,n){switch(n.appId){case`figma`:return w(t)??e;case`github`:return S(t)??e;case`notion`:return C(t)??e;case`gmail`:case`google-calendar`:case`google-drive`:case`linear`:case`slack`:return e}}function S(e){let t=E(e),[n,r,i,a]=t;return n==null||r==null?null:i===`blob`&&t.length>=5?O(t[t.length-1]):i===`pull`&&a!=null&&t.length===4&&e.search.length===0&&e.hash.length===0?`${n}/${r}#${a}`:t.length===2&&e.search.length===0&&e.hash.length===0?`${n}/${r}`:null}function C(e){let t=T(e);return t==null?null:D(t.replace(/-[a-f0-9]{32}$/iu,``))}function w(e){let t=T(e);return t==null?null:D(t)}function T(e){let t=E(e);return t[t.length-1]??null}function E(e){return e.pathname.split(`/`).filter(e=>e.length>0)}function D(e){let t=O(e);if(t==null)return null;let n=t.replace(/[-_]+/gu,` `).trim();return n.length===0?null:n}function O(e){if(e==null)return null;let t;try{t=decodeURIComponent(e)}catch{return null}return t.length===0?null:t}var k=/\[((?:\\.|[^\]])+)\]\(((?:\\.|[^)])+)\)/g,A=/\[((?:\\.|[^\]])+)\]\((?!(?:[A-Za-z][A-Za-z0-9+.-]*:\/\/|www\.|mailto:|tel:))(?:\\.|[^)])+\)/,j=/\[((?:\\.|[^\]])+)\]\(((?:https?:\/\/)(?:\\.|[^)])+)\)/gi,M=/\[(?:\\.|[^\]])+\]\(codex-text-link:\/\/https?:\/\/(?:\\.|[^)])+\)/i,N=/^(?:[A-Za-z][A-Za-z0-9+.-]*:\/\/|www\.|mailto:|tel:)/;function P(e){return I(e)||M.test(e)||z(e)}function F(e){for(let n of e.matchAll(j)){let e=n[2];if(e!=null&&v(t(e))!=null)return!0}return!1}function I(e){return B(e)||A.test(e)}function L({schema:e,text:t}){let n=e.nodes.paragraph,r=e.nodes.doc;if(!n||!r)throw Error(`plainTextToDoc requires doc+paragraph nodes`);let i=t.split(`
`).map(t=>n.create(null,t===``?null:e.text(t)));return r.create(null,i.length?i:[n.create()])}function R(i,a,{restoreMarkdownLinksAsTextLinks:o=!1,restorePathLinksAsFileMentions:p=!0}={}){let m=i.nodes.skillMention,h=i.nodes.appMention,g=i.nodes.pluginMention,_=i.nodes.atMention,y=i.nodes.agentMention,x=i.nodes.resourceMention,S=i.nodes.richLink,C=[],w=0,T=0,E=e=>{e<=T||C.push(i.text(a.slice(T,e)))};for(;w<a.length;){let D=a.indexOf(`[`,w);if(D===-1)break;let O=D+1;for(;O<a.length;){let e=a[O],t=a[O+1];if(e===`\\`&&(t===`\\`||t===`]`&&a[O+2]!==`(`)){O+=2;continue}if(e===`]`)break;O+=1}if(O>=a.length)break;if(a[O+1]!==`(`){w=O+1;continue}let k=O+2,A=``,j=!1;for(;k<a.length;){let e=a[k];if(e===`\\`){let e=a[k+1];if(e){A+=`\\${e}`,k+=2;continue}}if(e===`)`){j=!0;break}A+=e,k+=1}if(!j)break;let M=a.slice(D+1,O),P=n(M),F=A.startsWith(e),I=t(F?A.slice(e.length):A),L=F||o?v(I):null;E(D);let R=f({href:I,label:P}),z=b({displayText:P,href:I}),B=l(P);if(g&&R===`plugin`)C.push(g.create({name:B,displayName:B,path:I,description:``,iconSmall:``}));else if(R===`app`||R===`skill`){let e=P.startsWith(`$`)?B:P;R===`app`&&h?C.push(h.create({name:d(e),displayName:e,path:I,description:``,iconSmall:``})):R===`skill`&&m?C.push(m.create({name:e,displayName:r(e),path:I,description:``,iconSmall:``})):C.push(i.text(`[${M}](${A})`))}else if(R===`agent`&&y){let e=P.startsWith(`@`)?P.slice(1):P,t=s(I),n=c(I);t!=null||n!=null?C.push(y.create({name:e,displayName:e,conversationId:t,path:I})):C.push(i.text(`[${M}](${A})`))}else if(R===`mcp-resource`&&x){let e=u(I);e==null?C.push(i.text(`[${M}](${A})`)):C.push(x.create({...e,title:P}))}else F&&L!=null&&i.marks.link!=null?C.push(i.text(P,[i.marks.link.create({href:L})])):S&&z!=null?C.push(S.create(z)):L!=null&&i.marks.link!=null?C.push(i.text(P,[i.marks.link.create({href:L})])):N.test(I)?C.push(i.text(`[${M}](${A})`)):p&&_?C.push(_.create({label:P,path:I,fsPath:I})):C.push(i.text(`[${M}](${A})`));T=k+1,w=T}return E(a.length),C.length?C:null}function z(e){for(let n of e.matchAll(j)){let e=n[1],r=n[2];if(!(e==null||r==null)&&b({displayText:e,href:t(r)})!=null)return!0}return!1}function B(e){for(let r of e.matchAll(k)){let e=r[1],i=r[2];if(!(e==null||i==null)&&f({href:t(i),label:n(e)})!==`text`)return!0}return!1}function V({schema:e,text:t,restoreMarkdownLinksAsTextLinks:n=!1,restorePathLinksAsFileMentions:r=!0}){let i=e.nodes.paragraph,a=e.nodes.doc;if(!i||!a)throw Error(`promptTextToDoc requires doc+paragraph nodes`);let o=t.split(`
`).map(t=>i.create(null,R(e,t,{restoreMarkdownLinksAsTextLinks:n,restorePathLinksAsFileMentions:r})));return a.create(null,o.length?o:[i.create()])}export{V as a,m as c,h as d,L as i,_ as l,P as n,v as o,I as r,y as s,F as t,g as u};
//# sourceMappingURL=prompt-text-D8vtuyFP.js.map