openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
9 lines • 21 kB
JavaScript
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Oc as t,Ul as n,eu as r,ql as i,tu as a}from"./control-ui-connection-Bfj9beF_.js";import{ab as o,ib as s}from"./control-ui-boot-shared-DFTSUQQ0.js";import{Dl as c,Ol as l,_l as u,gl as d,hl as f,vl as p,xl as m,yl as h}from"./control-ui-boot-chat-DewxEbIm.js";import{n as g}from"./deferred-ui-support-D-VedBtc.js";import{ft as _,ht as ee,mt as te,pt as ne}from"./control-ui-boot-chat-styles-CEPkk0Pv.js";function v(e){if(!e)return e;let t=e.trim();return t.length>=2&&(t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`))?t.slice(1,-1).trim():t}function y(e,t=48){let n=e??``,r={words:[],unsupported:!1},i=``,a,o=!1,s=!1,c=!1,l=!1,u=()=>{s&&(l||r.words.push(i),l=!1),i=``,s=!1,c=!1};for(let e=0;e<n.length;e+=1){let d=n.charAt(e),f=n.charAt(e+1),p=o;if(o=!1,a===`'`)d===a?a=void 0:i+=d;else if(d===`\\`&&(!a||a===`ansi-c`||/[$`"\\\n]/u.test(f))){if(!f){r.unsupported=!0;break}e+=1,f===`
`?o=p:(i+=f,s=c=!0)}else if(a)d===(a===`ansi-c`?`'`:a)?a=void 0:i+=d;else if(d===`"`||d===`'`)a=d===`'`&&p?`ansi-c`:d,s=c=!0;else if(/\s/u.test(d)){if(u(),r.words.length>=t)return r}else{if(d===`#`&&!s)break;if(d===`<`||d===`>`||d===`&`&&f===`>`){f===`(`&&(r.unsupported=!0),!c&&/^(?:\d+|\{[A-Za-z_][A-Za-z0-9_]*\})$/u.test(i)&&(i=``,s=!1),u();let t=d;d===`&`?(t+=f,e+=1,n.charAt(e+1)===`>`&&(t+=`>`,e+=1)):(f===d||f===`&`||d===`<`&&f===`>`||d===`>`&&f===`|`)&&(t+=f,e+=1,t===`<<`&&(n.charAt(e+1)===`-`||n.charAt(e+1)===`<`)&&(t+=n.charAt(++e))),t.startsWith(`<<`)&&(r.hereInput=t===`<<<`?`here-string`:`heredoc`),l=!0}else i+=d,s=!0,o=d===`$`}}return u(),r.unsupported||=a!==void 0||l,r}function b(e){if(!e)return;let t=v(e)??e,r=t.split(/[/]/).at(-1)??t;return n(r)}function x(e,t=1,n=[]){let r=[],i=new Map,a=new Set(n),o=(e,t)=>{i.has(e)||i.set(e,t)};for(let n=t;n<e.length;n+=1){let t=e[n];if(t===void 0)break;if(t===`--`){r.push(...e.slice(n+1));break}if(a.has(t))o(t,e[++n]);else if(t.startsWith(`--`)){let e=t.indexOf(`=`);o(e<0?t:t.slice(0,e),e<0?void 0:t.slice(e+1))}else if(t.startsWith(`-`)&&t.length>1)for(let r=1;r<t.length;r+=1){let i=`-${t[r]}`;if(a.has(i)){o(i,t.slice(r+1)||e[++n]);break}o(i)}else r.push(t)}return{positional:r,options:i}}function S(e,t){let{options:n}=x(e,1,t);for(let[e,r]of n)if(t.includes(e))return r}function re(e){if(e.length===0)return e;let t=b(e[0])===`env`,n=+!!t;for(;n<e.length;){let r=e[n];if(!r||!(t&&r.startsWith(`-`))&&!/^[A-Za-z_][A-Za-z0-9_]*=/.test(r))break;n+=1}return e.slice(n)}function ie(e){let{words:t}=y(e,10);if(t.length<3)return e;let n=b(t[0]);if(n!==`bash`&&n!==`sh`&&n!==`zsh`&&n!==`fish`)return e;let r=t.findIndex((e,t)=>t>0&&(e===`-c`||e===`-lc`||e===`-ic`));if(r===-1)return e;let i=t.slice(r+1).join(` `).trim();return i?v(i)??e:e}function C(e,t,n=/[ \t]/u){if(e[t]!==`<`||e[t-1]===`<`||e[t+1]!==`<`||e[t+2]===`<`)return;let r=e[t+2]===`-`,i=t+(r?3:2);for(;n.test(e[i]??``);)i+=1;let a=``,o;for(;i<e.length;i+=1){let t=e[i]??``;if(o&&t===o)o=void 0;else{if(!o){if(/[\r\n;&|<>]/u.test(t)||n.test(t))break;if(t===`'`||t===`"`){o=t;continue}}o!==`'`&&t===`\\`&&i+1<e.length&&(i+=1,t=e[i]??``),a+=t}}return a?{value:a,stripLeadingTabs:r,operatorIndex:t}:void 0}function ae(e,t,n){let r=n;for(;r<=e.length;){let n=e.indexOf(`
`,r),i=n===-1?e.length:n,a=e.slice(r,i).replace(/\r$/u,``);if((t.stripLeadingTabs?a.replace(/^\t+/u,``):a)===t.value)return i;if(n===-1)return;r=n+1}}function oe(e,t){let n=t+1;for(;e[n]===`\\`&&e[n+1]===`
`;)n+=2;return e[n]===`(`?n:void 0}function w(e,t,n){let r,i=!1,a=!0,o=0,s=0,c=[],l=!1;for(let u=0;u<e.length;u+=1){let d=e.charAt(u),f=l;if(l=!1,i){if(i=!1,d===`
`){if(l=f,t(``,u-1)===!1||t(``,u)===!1)return}else a=!1;continue}if(r===`'`){d===r&&(r=void 0);continue}if(d===`\\`){l=f,i=!0;continue}if(r){d===(r===`ansi-c`?`'`:r)&&(r=void 0);continue}if(d===`"`||d===`'`){r=d===`'`&&f?`ansi-c`:d,a=!1;continue}if(d===`#`&&a&&o===0){let t=e.indexOf(`
`,u+1);if(t===-1)return;u=t-1;continue}let p=o===0&&d===`(`&&(f||a)?oe(e,u):void 0,m=p!==void 0,h=o>0||m;if(!h){let t=C(e,u);t&&c.push(t)}if(d===`
`&&c.length>0){let t=u+1,r,i=[];for(let n of c){if(r=ae(e,n,t),r===void 0)break;i.push({marker:n,start:t,end:r}),t=r+1}if(c=[],r!==void 0){for(let e of i)n?.(e.marker.operatorIndex,e.start,e.end);u=r-1;continue}}if(p!==void 0){if(t(d,u)===!1||t(e.charAt(p),p)===!1)return}else if(!h&&t(d,u)===!1)return;if(d===`(`&&(o>0||m))o+=1;else if(d===`)`&&o>0)--o;else if(!h){if(/\s/u.test(d))a=!0;else if(d===`(`){let t=e[u-1];t===`$`||t===`<`||t===`>`?a=!0:a&&=(s+=1,!0)}else d===`)`?s>0?(--s,a=!0):a=!1:a=!!/[;&|<>]/u.test(d);l=d===`$`}}}function se(e,t){let n=[],r=0,i=0,a=[];return w(e,(o,s)=>{let c=t(o,s);return c===0||(n.push(a.join(``)+e.slice(i,s)),r=s+c,i=r,a=[]),!0},(t,n,o)=>{t<r&&(a.push(e.slice(i,n)),i=o)}),n.push(a.join(``)+e.slice(i)),n.map(e=>e.trim()).filter(e=>e.length>0)}function ce(e){let t=Array.from({length:e.length},()=>`\0`);w(e,(e,n)=>(t[n]=e,!0));let n=t.join(``);return M.some(e=>e.test(n))}function le(e){return ce(e)?e.trim()?[e.trim()]:[]:se(e,(t,n)=>t===`;`?1:(t===`&`||t===`|`)&&e[n+1]===t?2:0)}function ue(e){return se(e,(t,n)=>+(t===`|`&&e[n-1]!==`|`&&e[n-1]!==`>`&&e[n+1]!==`|`))}function T(e){let t=e.trim(),n;for(let e=0;e<4;e+=1){let r;w(t,(e,n)=>{if((e===`&`||e===`|`)&&t[n+1]===e)return r={index:n,length:2,isOr:e===`|`},!1;if(e===`;`||e===`
`)return r={index:n,length:1},!1});let i=(r?t.slice(0,r.index):t).trim(),{words:a}=y(i,3),o=b(a[0]),s=(r?!r.isOr:e>0)&&(o===`cd`||o===`pushd`||o===`popd`);if(!(i.startsWith(`set `)||i.startsWith(`export `)||i.startsWith(`unset `)||s)||(s&&(n=o===`popd`?void 0:a[1]||n),t=r?t.slice(r.index+r.length).trimStart():``,!t))break}return{command:t.trim(),chdirPath:n}}var E,D,O,k,A,j,M;function N(){return(N=e((()=>{E=String.raw`(?:^|;|\n|(?<!>)\||(?<![<>])&(?![>&]))\s*(?:(?:time(?:\s+-p)?(?:\s+--)?|!)(?:\s+|(?=\()))*`,D=String.raw`(?=$|[\s;&|()<>])`,O=`(?:(?:for|while|until|if|case|select|coproc)${D}|(?:\\[\\[|\\{)${D})`,k=`(?:${O}|\\((?!\\())`,A=`(?:${O}|\\()`,j=`[^\\s;&|()<>]+`,M=[E,String.raw`(?:\$\((?!\()|[<>]\()\s*(?:(?:time(?:\s+-p)?(?:\s+--)?|!)(?:\s+|(?=\()))*`].flatMap(e=>[k,`function\\s+${j}(?:\\s+${A}|\\((?!\\s*\\)))`,`(?:function\\s+)?${j}\\s*\\(\\s*\\)\\s*${A}`].map(t=>RegExp(`${e}${t}`,`u`)))})))()}function de(e,t){if(e.length===0)return`run command`;let n=b(e[0])??`command`;if(n===`git`){let t=new Set([`-C`,`-c`,`--git-dir`,`--work-tree`,`--namespace`,`--config-env`]),n=S(e,[`-C`]),r;for(let n=1;n<e.length;n+=1){let i=e[n];if(i){if(i===`--`){r=x(e,n+1).positional[0];break}if(i.startsWith(`-`))t.has(i)&&(n+=1);else{r=i;break}}}return(r?{status:`check git status`,diff:`check git diff`,log:`view git history`,show:`show git object`,branch:`list git branches`,checkout:`switch git branch`,switch:`switch git branch`,commit:`create git commit`,pull:`pull git changes`,push:`push git changes`,fetch:`fetch git changes`,merge:`merge git changes`,rebase:`rebase git branch`,add:`stage git changes`,restore:`restore git files`,reset:`reset git state`,stash:`stash git changes`}[r]:void 0)||(!r||r.startsWith(`/`)||r.startsWith(`~`)||r.includes(`/`)?n?`run git command in ${n}`:`run git command`:`run git ${r}`)}if(n===`grep`||n===`rg`||n===`ripgrep`){let{positional:t,options:r}=x(e,1,[`-e`,`--regexp`,`-f`,`--file`,`-m`,`--max-count`,`-A`,`--after-context`,`-B`,`--before-context`,`-C`,`--context`,...n===`grep`?[`--include`,`--exclude`,`--exclude-from`,`--binary-files`,`-D`,`--devices`,`-d`,`--directories`,`--label`]:`--pre.--pre-glob.--dfa-size-limit.-E.--encoding.--engine.--regex-size-limit.-j.--threads.-g.--glob.--iglob.--ignore-file.-d.--max-depth.--max-filesize.-t.--type.-T.--type-not.--type-add.--type-clear.--color.--colors.--context-separator.--field-context-separator.--field-match-separator.--hostname-bin.--hyperlink-format.-M.--max-columns.--path-separator.-r.--replace.--sort.--sortr.--generate`.split(`.`)]);if(n!==`grep`&&r.has(`--files`)){let e=t.at(-1);return e?`list files in ${e}`:`list files`}let i=[`-e`,`--regexp`,`-f`,`--file`].some(e=>r.has(e)),a=r.get(`-e`)??r.get(`--regexp`)??(i?void 0:t[0]),o=i||t.length>1?t.at(-1):void 0;return a?fe(a)?o?`search text in ${o}`:`search text`:o?`search "${a}" in ${o}`:`search "${a}"`:o?`search text in ${o}`:`search text`}if(n===`find`){let t=e[1]&&!e[1].startsWith(`-`)?e[1]:`.`,n=S(e,[`-name`,`-iname`]);return n?`find files named "${n}" in ${t}`:`find files in ${t}`}let r=B.get(n);if(r){let[t,n]=r,i=x(e).positional[0];return i?`${t} ${i}`:n}if(n===`head`||n===`tail`){let t=S(e,[`-n`,`--lines`])??e.slice(1).find(e=>/^-\d+$/.test(e))?.slice(1),{positional:r}=x(e,1,[`-n`,`--lines`]),i=r.at(-1);return i&&/^\d+$/.test(i)&&r.length===1&&(i=void 0),t?`show ${n===`head`?`first`:`last`} ${t} ${t===`1`?`line`:`lines`}${i?` of ${i}`:``}`:i?`show ${i}`:`show ${n} output`}if(n===`sed`){let t=S(e,[`-e`,`--expression`]),{positional:n}=x(e,1,[`-e`,`--expression`,`-f`,`--file`]),r=t??n[0],i=t?n[0]:n[1];if(r){let e=(v(r)??r).replace(/\s+/g,``).match(/^([0-9]+)(?:,([0-9]+))?p$/);if(e)return`print ${e[2]?`lines ${e[1]}-${e[2]}`:`line ${e[1]}`}${i?` from ${i}`:``}`}return i?`run sed on ${i}`:`run sed transform`}if(n===`printf`||n===`echo`)return`print text`;if(n===`cp`||n===`mv`){let{positional:t}=x(e,1,[`-t`,`--target-directory`,`-S`,`--suffix`]),r=t[0],i=t[1],a=n===`cp`?`copy`:`move`;return r&&i?`${a} ${r} to ${i}`:r?`${a} ${r}`:`${a} files`}if(n===`curl`||n===`wget`){let t=e.find(e=>/^https?:\/\//i.test(e));return t?`fetch ${t}`:`fetch url`}if(n===`npm`||n===`pnpm`||n===`yarn`||n===`bun`){let{positional:t}=x(e,1,[`--prefix`,`-C`,`--cwd`,`--config`]),r=t[0]??`command`;return{install:`install dependencies`,test:`run tests`,build:`run build`,start:`start app`,lint:`run lint`,run:t[1]?`run ${t[1]}`:`run script`}[r]??`run ${n} ${r}`}if(n===`node`||n===`python`||n===`python3`||n===`ruby`||n===`php`){if(t)return`run ${n} inline script (${t})`;if((n===`node`?S(e,[`-e`,`--eval`]):n===`python`||n===`python3`?S(e,[`-c`]):void 0)!==void 0)return`run ${n} inline script`;let r=x(e,1,n===`node`?[`-e`,`--eval`,`-m`]:[`-c`,`-e`,`--eval`,`-m`]).positional[0];return r?n===`node`?`${e.includes(`--check`)||e.includes(`-c`)?`check js syntax for`:`run node script`} ${r}`:`run ${n} ${r}`:`run ${n}`}if(n===`openclaw`){let t=x(e).positional[0];return t?`run openclaw ${t}`:`run openclaw`}let i=x(e).positional[0];return!i||i.length>48?`run ${n}`:/^[A-Za-z0-9._/-]+$/.test(i)?`run ${n} ${i}`:`run ${n}`}function fe(e){let t=e.trim();return!t||e.length>120||/[\r\n`]/u.test(e)||/^Bash failed:/iu.test(t)||pe(t)}function pe(e){return e.split(/(?:\||->)/u).some(e=>V.test(e.trim()))}function me(e){let t=e=>{let t=y(e);return t.unsupported?void 0:de(re(t.words),t.hereInput)},n=ue(e);if(n.length>1){let e=t(n[0]),r=t(n[n.length-1]);return!e||!r?void 0:`${e} -> ${r}${n.length>2?` (+${n.length-2} steps)`:``}`}return t(e)}function he(e){let t=[];return w(e,(n,r)=>{let i=C(e,r,/\s/u);return i&&t.push(i),!0}),t}function ge(e){if(!e.includes(`
`))return;let t=e.split(/\r?\n/u),n=[],r=!1;for(let e=0;e<t.length;e+=1){let i=t[e]??``;n.push(i);let a=he(i);if(a.length!==0){r=!0;for(let n of a)for(e+=1;e<t.length&&(n.stripLeadingTabs?(t[e]??``).replace(/^\t+/u,``):t[e]??``)!==n.value;)e+=1}}if(r)return n.map(e=>e.trim()).filter(Boolean).join(`; `)}function _e(e){let t=e.split(/[\\/]/).filter(Boolean);for(let[e,n]of t.entries()){if(n===`.openclaw`&&t[e+1]===`workspace`)return`agent`;if(n===`.openclaw`&&t[e+1]===`sandboxes`)return`sandbox`;if(/[-_]workspace$/i.test(n)||/^workspace[-_]/i.test(n))return`agent`}if(t.includes(`Projects`)||t.includes(`projects`))return`repo`;if(t.at(-1)?.toLowerCase()===`workspace`)return`workspace`}function P(e){let t=_e(e);if(t!==`sandbox`)return t?`(${t})`:`(in ${e})`}function F(e){let{command:t,chdirPath:n}=T(e);if(!t)return n?{text:``,chdirPath:n}:void 0;let r=le(ge(t)??t);if(r.length===0)return;let i=r.map(e=>me(e));if(i.some(e=>e===void 0))return;let a=i.length===1?i.at(0):i.join(` → `);if(a)return{text:a,chdirPath:n,allGeneric:i.every(e=>e!==void 0&&I(e))}}function I(e){return e===`run command`?!0:e.startsWith(`run `)?!H.some(t=>e.startsWith(t)):!1}function L(e){let n=e.replace(/\s*\n\s*/g,` `).replace(/\s{2,}/g,` `).trim();return n.length<=120?n:`${t(n,0,59)}…${t(n,-60)}`}function R(e){let n=a(e)?.title;if(typeof n!=`string`)return;let r=o(n.replace(/\s+/gu,` `)).trim();return t(r,0,120)||void 0}function z(e){let t=a(e);for(let e of[t?.code,t?.input])if(typeof e==`string`&&e.trim())return e}function ve(e,t){let n=a(e);if(!n)return;let r=t?.detailMode===`raw`?void 0:R(n);if(r)return r;let i=z(n);if(i)return t?.detailMode===`raw`?L(i):n.language===`typescript`?`run TypeScript`:`run JavaScript`;let o=typeof n.command==`string`?n.command.trim():void 0;if(!o)return;let s=n.host===`node`&&typeof n.node==`string`&&n.node.trim()?n.node.trim():void 0,c=ie(o),l=L(c),u=typeof n.workdir==`string`?n.workdir:typeof n.cwd==`string`?n.cwd:void 0,d=s?`, node: ${s}`:``;if(ce(c)){let e=u?.trim()?P(u.trim()):void 0;return`${e?`${l} ${e}`:l}${d}`}let f=F(c)??F(o),p=f?.text||`run command`,m=u?.trim()||f?.chdirPath||void 0,h=m?P(m):void 0;if(f?.allGeneric!==!1&&I(p))return`${h?`${l} ${h}`:l}${d}`;let _=h?`${p} ${h}`:p;return t?.detailMode!==`explain`&&l&&l!==_&&l!==p?`${_}${d}, ${g(l)}`:`${_}${d}`}var B,V,H;function U(){return(U=e((()=>{s(),N(),B=new Map([[`ls`,[`list files in`,`list files`]],[`cat`,[`show`,`show output`]],[`rm`,[`remove`,`remove files`]],[`mkdir`,[`create folder`,`create folder`]],[`touch`,[`create file`,`create file`]]]),V=/^search\s+(?:["']|text(?:\s+in(?:\s|$)|$))/iu,H=[`run tests`,`run build`,`run lint`,`run openclaw`,`run node `,`run python`,`run ruby`,`run php`,`run sed`,`run git `,`run npm `,`run pnpm `,`run yarn `,`run bun `]})))()}function W(e,t,n){let r=n.trim(),i={operation:t,sourcePath:r,path:r,lines:[],stat:{added:0,removed:0}};return e.sections.push(i),i}function G(e,t,n){n.kind===`add`?t.stat.added+=1:n.kind===`del`&&(t.stat.removed+=1),e.storedRows<400?(t.lines.push(n),e.storedRows+=1):e.truncated=!0}function K(e,t,n,r,i=!1){if(n.startsWith(`@@`)){t&&t.lines.length>0&&t.lines.at(-1)?.kind!==`skip`&&G(e,t,{kind:`skip`,text:``});let r=n.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);return r?{oldLine:Number.parseInt(r[1]??``,10),oldLeft:r[2]===void 0?1:Number.parseInt(r[2],10),newLine:Number.parseInt(r[3]??``,10),newLeft:r[4]===void 0?1:Number.parseInt(r[4],10)}:{}}if(t&&(r||i)&&(n.startsWith(`+`)||n.startsWith(`-`)||n.startsWith(` `)||i&&n===``)){let i=n.startsWith(`+`)?`add`:n.startsWith(`-`)?`del`:`ctx`,a=i===`del`?r?.oldLine:r?.newLine;return r&&(i!==`ctx`||r.oldLine!==void 0&&r.newLine!==void 0)&&(i!==`add`&&r.oldLine!==void 0&&(r.oldLine+=1,r.oldLeft=Math.max(0,(r.oldLeft??0)-1)),i!==`del`&&r.newLine!==void 0&&(r.newLine+=1,r.newLeft=Math.max(0,(r.newLeft??0)-1))),G(e,t,{kind:i,...a===void 0?{}:{lineNo:a},text:n.slice(1)}),r?.oldLeft===0&&r.newLeft===0?null:r}return r}function ye(e){return e.operation===`update`&&e.path!==e.sourcePath?`Move ${e.sourcePath} → ${e.path}`:`${e.operation===`add`?`Add`:e.operation===`delete`?`Delete`:`Update`} ${e.path}`}function q(e){if(e.sections.length===0)return null;let t=[...new Set(e.sections.map(e=>e.path).filter(Boolean))],n=e.sections.map(({operation:e,path:t,sourcePath:n})=>({operation:e,path:t,...e===`update`&&n!==t?{oldPath:n}:{}})),r=e.sections.reduce((e,t)=>({added:e.added+t.stat.added,removed:e.removed+t.stat.removed}),{added:0,removed:0}),i=[],a=e.truncated,o=e=>{i.length<400?i.push(e):a=!0};for(let[t,r]of e.sections.entries()){e.sections.length>1&&(i.length>0&&i.at(-1)?.kind!==`skip`&&o({kind:`skip`,text:``}),o({kind:`file`,path:r.path,...`oldPath`in n[t]?{oldPath:r.sourcePath}:{},text:ye(r)}));for(let e of r.lines)o(e)}a&&i.at(-1)?.kind!==`skip`&&i.push({kind:`skip`,text:``});let s=e.sections.length===1?e.sections.at(0):void 0,c=s&&s.operation===`update`&&s.sourcePath!==s.path?{from:s.sourcePath,to:s.path}:void 0;return{paths:t,fileOperations:n,lines:i,stat:r,...c?{move:c}:{}}}function J(e){return(e.split(` `,1)[0]?.trim()??``).replace(/^[ab]\//,``)}function be(e){let t=r(e);if(!t)return null;if(Array.isArray(t.changes)){let e={sections:[],storedRows:0,truncated:!1};for(let n of t.changes){let t=r(n),a=i(t?.path)?.trim();if(!t||!a)continue;let o=t.kind,s=typeof o==`string`?o:r(o)?.type,c=s===`add`||s===`delete`?s:`update`,l=W(e,c,a),u=i(r(t.kind)?.move_path??r(t.kind)?.movePath);if(u&&(l.path=u.trim()),typeof t.diff==`string`){if(c===`update`){let n=null;for(let r of m(t.diff))n=K(e,l,r,n)}else{let n=c===`add`?`add`:`del`;for(let[r,i]of m(t.diff).entries())G(e,l,{kind:n,lineNo:r+1,text:i})}}let d=r(t.stat),f=d?.added,p=d?.removed,h=typeof f==`number`&&typeof p==`number`&&f>=0&&p>=0?{added:Math.trunc(f),removed:Math.trunc(p)}:null;h&&(l.stat=h),e.truncated||=t.diffTruncated===!0}let n=q(e);if(n)return n}let n=i(t.patch)??i(t.input)??i(t.diff);if(!n)return null;let a=/(?:^|\n)\s*\*\*\* (?:Begin Patch|Update File:|Add File:|Delete File:)/.test(n),o={sections:[],storedRows:0,truncated:!1},s=m(n),c=null,l=null,u=!1;for(let e=0;e<s.length;e++){let t=s[e];if(a){let e=c?.operation===`update`?t.trimEnd():t.trim(),n=e.match(/^\*\*\* (Update|Add|Delete) File: (.+)$/);if(n){c=W(o,n[1].toLowerCase(),n[2]),l=null;continue}let r=c?.operation===`update`?e.match(/^\*\*\* Move to: (.+)$/):null;if(r&&c){c.path=r[1]?.trim()??c.path;continue}if(e===`*** Begin Patch`||e===`*** End Patch`||e===`*** End of File`||e.startsWith(`*** Environment ID:`)||!c||(c.operation===`add`&&t.startsWith(`+`)&&G(o,c,{kind:`add`,lineNo:c.stat.added+1,text:t.slice(1)}),c.operation!==`update`))continue}else{let n=t.match(/^diff --git a\/(.+) b\/(.+)$/);if(n){c=W(o,`update`,n[2]),c.sourcePath=n[1],l=null,u=!0;continue}let r=s[e+1];if(!l&&t.startsWith(`--- `)&&r?.startsWith(`+++ `)){let n=J(t.slice(4)),i=J(r.slice(4)),a=n===`/dev/null`?`add`:i===`/dev/null`?`delete`:`update`,s=i===`/dev/null`?n:i,l=u&&c?c:W(o,a,s);l.operation=a,l.sourcePath=n||l.sourcePath,l.path=s||l.path,c=l,u=!1,e+=1;continue}if(t.startsWith(`@@`)&&(u=!1),/^index |^new file mode |^deleted file mode |^similarity index /.test(t))continue}l=K(o,c,t,l,a)}return q(o)}function Y(e){let t=e.replace(/\\/g,`/`).replace(/\/+$/,``),n=t.lastIndexOf(`/`);return n<=0?{base:t||e}:{base:t.slice(n+1),dir:t.slice(0,n)}}function xe(e){if(!e)return null;let t=[],n=0,i=!1,a=Array.isArray(e.edits)?e.edits:[e];for(let[e,o]of a.entries()){if(e>=X){i=!0;break}let a=r(o);if(!a)continue;let s=a.oldText??a.old_string??a.oldString??a.old_str,c=a.newText??a.new_string??a.newString??a.new_str;if(typeof s==`string`&&typeof c==`string`){let e=s.length+c.length;if(n+e>Z){i=!0;break}n+=e,t.push({oldText:s,newText:c})}}if(t.length===0)return i?{diff:[{kind:`skip`,text:``}]}:null;let o=t.map(e=>d(e.oldText,e.newText)),s=p(o,{truncated:i});return s.lines.length===0?null:{diff:s.lines,...s.kind===`complete`?{stat:s.stat}:{}}}function Se(e){let t=r(e),n=i(t?.diff);if(!n)return null;let a=h(n);return a?{diff:a.lines,...a.kind===`complete`?{stat:a.stat}:{}}:null}function Ce(e){let t=i(e?.insert_text);if(!t)return null;let n=d(``,t).lines;return n.length>0?{diff:n}:null}function we(e){let t=l(e),n=r(t.args),i=n??r(e.details),a=t.name.trim().toLowerCase();if(i){let t=Q.get(i);if(t&&t.details===e.details&&t.name===a)return t.view}let o=Te(e,n,a);return i&&Q.set(i,{details:e.details,name:a,view:o}),o}function Te(e,t,n){let a=ee(n,t),{kind:o,editorCommand:s}=a;if(o===`command`){let e=i(t?.command),r=e?.match(/^\s*(?:\/(?:usr\/)?bin\/)?(?:ba|z|da)?sh\s+-l?c\s+(['"])([\s\S]+)\1\s*$/);return{kind:o,title:_.has(n)?R(t):void 0,command:r?.[2]??e,code:z(t)}}if(o===`edit`&&ne.has(n)){let e=be(t);if(!e)return{kind:`generic`};let n={kind:`edit`,fileOperations:e.fileOperations,diff:e.lines,stat:e.stat};if(e.paths.length>1)return{...n,target:`${e.paths.length} files`};if(e.move){let t=Y(e.move.from),r=Y(e.move.to),i=t.dir===r.dir?t.dir:void 0;return{...n,target:i?`${t.base} → ${r.base}`:`${e.move.from} → ${e.move.to}`,targetDetail:i}}let r=e.paths[0]?Y(e.paths[0]):null;return{...n,target:r?.base,targetDetail:r?.dir}}if(o===`read`||o===`edit`||o===`write`){let n=a.path;if(!n)return{kind:`generic`};let{base:c,dir:l}=Y(n),u={kind:o,target:c,targetDetail:l};if(o===`read`)return u;let d=Se(e.details);if(d)return{...u,...d};if(o===`edit`){let e=s===`insert`?Ce(t):s===`undo_edit`?null:xe(t);return{...u,...e}}let p=r(e.details);if(p?.changed===!1)return u;let h=i(t?.[s===`create`?`file_text`:`content`]);if(!h)return u;let g=f(h);return{...u,diff:g,...p&&p.created!==!0?{}:{stat:{added:m(h).length,removed:0}}}}if(o===`search`){let e=i(t?.pattern)??i(t?.query)??i(t?.glob),n=a.path;return!e&&!n?{kind:`generic`}:{kind:o,target:e??n,targetDetail:e?n:void 0}}if(o===`fetch`){let e=i(t?.url);return e?{kind:o,target:e}:{kind:`generic`}}return{kind:`generic`}}var X,Z,Q;function $(){return($=e((()=>{c(),U(),u(),te(),X=8,Z=12e4,Q=new WeakMap})))()}export{N as a,ve as i,we as n,T as o,U as r,$ as t};