1import{r as e}from"./chunk-Bv0JxpqV.js";import{r as t,t as n}from"./runtime--fcdnjmJ-MvPFGFKu.js";import"./runtime-common-Cs3QsWdy.js";import{nt as r}from"./constants-CH4t2Yue.js";import{S as i,b as a,n as o}from"./operator-mode-state-service-BzdBIN6r.js";import{Y as s}from"./index-DaCZcoCY-C2aR0U0x.js";var c=e({findNonConflictingFilename:()=>findNonConflictingFilename});async function findNonConflictingFilename(e,t){let{baseName:n,extension:r}=parseFilename(e);for(let e=1;e<100;e++){let i=`${n}-${e}${r}`;if(!await t(i))return i}let i=`${n}-100${r}`;if(!await t(i))return i;throw Error(`Unable to find non-conflicting filename for "${e}" after 100 attempts.`)}function parseFilename(e){let t=e.match(/\.([^.]+)$/)?.[0]||``;return{baseName:e.replace(/\.([^.]+)$/,``),extension:t}}var l=e({WriteTextFileCommand:()=>WriteTextFileTool,default:()=>WriteTextFileTool}),WriteTextFileTool=class extends a{static{n(this.prototype,`cardService`,[s])}#e=(t(this,`cardService`),void 0);static{n(this.prototype,`realm`,[s])}#t=(t(this,`realm`),void 0);description=`Write a text file to a realm, such as a module or a card.`;static actionVerb=`Write`;async getInputType(){let{WriteTextFileInput:e}=await this.loadToolModule();return e}requireInputFields=[`path`,`content`];async run(e){if(e.overwrite&&e.useNonConflictingFilename)throw Error(`Cannot use both overwrite and useNonConflictingFilename.`);let t;if(e.realm&&(t=this.realm.realmOf(r(e.realm)),!t))throw Error(`Invalid or unknown realm provided: ${e.realm}`);let n=e.path;n.startsWith(`/`)&&(n=n.slice(1));let i=new URL(n,t),a=i,o=!0;if(!e.overwrite)if(e.useNonConflictingFilename){let t=await this.cardService.getSource(i);if(t.status===404)o=!0;else if(t.status===200)if(t.content.trim()!==``){let e=await findNonConflictingFilename(i.href,e=>this.fileExists(e));a=new URL(e)}else o=e.content.trim()!==``;else throw Error(`Error checking if file exists at ${i}: ${t.status}`)}else{let e=await this.cardService.getSource(i);if(e.status===200||e.status===406)throw Error(`File already exists: ${n}`);if(e.status!==404){let t=e.content?.trim()?`${e.content} (${e.status})`:`${e.status}`;throw Error(`Error checking if file exists at ${n}: ${t}`)}}if(o){let t=e.overwrite?`editor`:`create-file`;await this.cardService.saveSource(a,e.content,t)}let{FileIdentifierCard:s}=await this.loadToolModule();return new s({fileIdentifier:a.href})}async fileExists(e){return(await this.cardService.getSource(r(e))).status!==404}},u=e({SwitchSubmodeCommand:()=>SwitchSubmodeTool,default:()=>SwitchSubmodeTool}),SwitchSubmodeTool=class extends a{static{n(this.prototype,`operatorModeStateService`,[s])}#e=(t(this,`operatorModeStateService`),void 0);static{n(this.prototype,`store`,[s])}#t=(t(this,`store`),void 0);static actionVerb=`Switch`;description=`Navigate the UI to another submode. Possible values for submode are "interact" and "code".`;async getInputType(){let{SwitchSubmodeInput:e}=await this.loadToolModule();return e}requireInputFields=[`submode`];get allStackItems(){return this.operatorModeStateService.state?.stacks.flat()??[]}get lastStackItem(){return this.allStackItems.length<=0?null:this.allStackItems[this.allStackItems.length-1]}get lastCardInRightMostStack(){let e=this.lastStackItem;return e?this.store.peek(e.id)?.id:null}async run(e){let t;switch(e.submode){case i.Interact:await this.operatorModeStateService.updateCodePath(null);break;case i.Code:{let n=this.lastCardInRightMostStack,a=e.codePath??(n?this.lastStackItem?.type===`file`?n:n+`.json`:null),s=a?r(a):null;if(!this.operatorModeStateService.codeSubmodeOffered(s??void 0))throw Error(o(s));let c=this.operatorModeStateService.state.submode,l=s;if(s&&e.createFile&&c===i.Interact){let e=await new WriteTextFileTool(this.toolContext).execute({path:s,content:``,useNonConflictingFilename:!0});if(e.fileIdentifier!==s){l=r(e.fileIdentifier);let{SwitchSubmodeResult:n}=await this.loadToolModule();t=new n({codePath:l})}}await this.operatorModeStateService.updateCodePath(l);break}default:throw Error(`invalid submode specified: ${e.submode}`)}return this.operatorModeStateService.updateSubmode(e.submode),this.operatorModeStateService.workspaceChooserOpened&&this.operatorModeStateService.closeWorkspaceChooser(),t}};export{c as a,l as i,u as n,findNonConflictingFilename as o,WriteTextFileTool as r,SwitchSubmodeTool as t};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.