shuvcode 2.0.0-alpha-15 → 2.0.0-alpha-17

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.
@@ -7,7 +7,7 @@ export const isSessionNotFoundError = (value) => typeof value === "object" && va
7
7
  export const isUnknownError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "UnknownError";
8
8
  export const isMessageNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "MessageNotFoundError";
9
9
  export const isCommandNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "CommandNotFoundError";
10
- export const isCommandEvaluationError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "CommandEvaluationError";
10
+ export const isCommandExecutionError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "CommandExecutionError";
11
11
  export const isSkillNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "SkillNotFoundError";
12
12
  export const isServiceUnavailableError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ServiceUnavailableError";
13
13
  export const isSessionBusyError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "SessionBusyError";
@@ -17,10 +17,12 @@ export const isInstructionEntryValueTooLargeError = (value) => typeof value ===
17
17
  value["_tag"] === "InstructionEntryValueTooLargeError";
18
18
  export const isProviderNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ProviderNotFoundError";
19
19
  export const isMcpServerNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "McpServerNotFoundError";
20
+ export const isProjectNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ProjectNotFoundError";
20
21
  export const isFormNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "FormNotFoundError";
21
22
  export const isFormAlreadySettledError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "FormAlreadySettledError";
22
23
  export const isFormInvalidAnswerError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "FormInvalidAnswerError";
23
24
  export const isPermissionNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "PermissionNotFoundError";
24
25
  export const isPtyNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "PtyNotFoundError";
26
+ export const isForbiddenError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ForbiddenError";
25
27
  export const isShellNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ShellNotFoundError";
26
28
  export const isWorktreeError = (value) => typeof value === "object" && value !== null && "name" in value && value["name"] === "WorktreeError";
package/client/index.js CHANGED
@@ -1,7 +1,7 @@
1
- var v=Object.defineProperty;var O=(t)=>t;function k(t,s){this[t]=O.bind(null,s)}var q=(t,s)=>{for(var i in s)v(t,i,{get:s[i],enumerable:!0,configurable:!0,set:k.bind(s,i)})};class d extends Error{reason;name="ClientError";constructor(t,s){super(t,s);this.reason=t}}var R={};q(R,{make:()=>C});var A=16777216;function C(t){let s=t.fetch??globalThis.fetch,i=(e,n)=>{let o=new URL(e.path,t.baseUrl);for(let[y,a]of Object.entries(e.query??{}))b(o.searchParams,y,a);let l=new Headers(t.headers);for(let[y,a]of Object.entries(e.headers??{}))if(a!==void 0&&a!==null)l.set(y,String(a));for(let[y,a]of new Headers(n?.headers))l.set(y,a);if(e.body!==void 0&&!l.has("content-type"))l.set("content-type","application/json");return{url:o,init:{method:e.method,signal:n?.signal,headers:l,body:e.body===void 0?void 0:JSON.stringify(e.body)}}},u=async(e,n)=>{try{let o=i(e,n);return await s(o.url,o.init)}catch(o){throw new d("Transport",{cause:o})}},g=async(e,n)=>{if(n.declaredStatuses.includes(e.status))throw await h(e);try{await e.body?.cancel()}catch{}throw new d("UnexpectedStatus",{cause:{status:e.status}})},r=async(e,n)=>{let o=await u(e,n);if(o.status!==e.successStatus)return g(o,e);if(e.binary)return new Uint8Array(await o.arrayBuffer());if(e.empty){try{await o.body?.cancel()}catch{}return}return await h(o)},f=(e,n)=>({async*[Symbol.asyncIterator](){let o=await u(e,n);if(o.status!==e.successStatus)await g(o,e);if(!D(o,"text/event-stream")){try{await o.body?.cancel()}catch{}throw new d("UnsupportedContentType")}if(o.body===null)throw new d("MalformedResponse");let l=o.body.getReader(),y=new TextDecoder,a="";try{while(!0){let p;try{p=await l.read()}catch(I){throw new d("Transport",{cause:I})}if(a+=y.decode(p.value,{stream:!p.done}),a.length>A)throw new d("SseEventTooLarge");let x=!p.done&&a.endsWith("\r");if(x)a=a.slice(0,-1);if(a=a.replaceAll(`\r
1
+ var v=Object.defineProperty;var O=(t)=>t;function k(t,s){this[t]=O.bind(null,s)}var P=(t,s)=>{for(var i in s)v(t,i,{get:s[i],enumerable:!0,configurable:!0,set:k.bind(s,i)})};class d extends Error{reason;name="ClientError";constructor(t,s){super(t,s);this.reason=t}}var R={};P(R,{make:()=>w});var C=16777216;function w(t){let s=t.fetch??globalThis.fetch,i=(e,n)=>{let o=new URL(e.path,t.baseUrl);for(let[y,a]of Object.entries(e.query??{}))b(o.searchParams,y,a);let l=new Headers(t.headers);for(let[y,a]of Object.entries(e.headers??{}))if(a!==void 0&&a!==null)l.set(y,String(a));for(let[y,a]of new Headers(n?.headers))l.set(y,a);if(e.body!==void 0&&!l.has("content-type"))l.set("content-type","application/json");return{url:o,init:{method:e.method,signal:n?.signal,headers:l,body:e.body===void 0?void 0:JSON.stringify(e.body)}}},u=async(e,n)=>{try{let o=i(e,n);return await s(o.url,o.init)}catch(o){throw new d("Transport",{cause:o})}},g=async(e,n)=>{if(n.declaredStatuses.includes(e.status))throw await h(e);try{await e.body?.cancel()}catch{}throw new d("UnexpectedStatus",{cause:{status:e.status}})},r=async(e,n)=>{let o=await u(e,n);if(o.status!==e.successStatus)return g(o,e);if(e.binary)return new Uint8Array(await o.arrayBuffer());if(e.empty){try{await o.body?.cancel()}catch{}return}return await h(o)},x=(e,n)=>({async*[Symbol.asyncIterator](){let o=await u(e,n);if(o.status!==e.successStatus)await g(o,e);if(!D(o,"text/event-stream")){try{await o.body?.cancel()}catch{}throw new d("UnsupportedContentType")}if(o.body===null)throw new d("MalformedResponse");let l=o.body.getReader(),y=new TextDecoder,a="";try{while(!0){let p;try{p=await l.read()}catch(I){throw new d("Transport",{cause:I})}if(a+=y.decode(p.value,{stream:!p.done}),a.length>C)throw new d("SseEventTooLarge");let f=!p.done&&a.endsWith("\r");if(f)a=a.slice(0,-1);if(a=a.replaceAll(`\r
2
2
  `,`
3
3
  `).replaceAll("\r",`
4
- `),x)a+="\r";if(p.done&&a!=="")a+=`
4
+ `),f)a+="\r";if(p.done&&a!=="")a+=`
5
5
 
6
6
  `;let c=a.indexOf(`
7
7
 
@@ -9,4 +9,4 @@ var v=Object.defineProperty;var O=(t)=>t;function k(t,s){this[t]=O.bind(null,s)}
9
9
  `).flatMap((m)=>m.startsWith("data:")?[m.slice(5).trimStart()]:[]).join(`
10
10
  `);if(S!=="")try{yield JSON.parse(S)}catch(m){throw new d("MalformedResponse",{cause:m})}c=a.indexOf(`
11
11
 
12
- `)}if(p.done)return}}finally{try{await l.cancel()}catch{}l.releaseLock()}}});return{health:{get:(e)=>r({method:"GET",path:"/api/health",successStatus:200,declaredStatuses:[401,400],empty:!1},e),stop:(e,n)=>r({method:"POST",path:"/api/service/stop",body:{instanceID:e.instanceID},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},server:{get:(e)=>r({method:"GET",path:"/api/server",successStatus:200,declaredStatuses:[401,400],empty:!1},e)},location:{get:(e,n)=>r({method:"GET",path:"/api/location",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},agent:{list:(e,n)=>r({method:"GET",path:"/api/agent",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/agent/${encodeURIComponent(e.agentID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[404,401,400],empty:!1},n)},plugin:{list:(e,n)=>r({method:"GET",path:"/api/plugin",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},session:{list:(e,n)=>r({method:"GET",path:"/api/session",query:{workspace:e?.workspace,limit:e?.limit,order:e?.order,search:e?.search,parentID:e?.parentID,directory:e?.directory,project:e?.project,subpath:e?.subpath,cursor:e?.cursor},successStatus:200,declaredStatuses:[400,401],empty:!1},n),create:(e,n)=>r({method:"POST",path:"/api/session",body:{id:e?.id,title:e?.title,agent:e?.agent,model:e?.model,location:e?.location,policy:e?.policy},successStatus:200,declaredStatuses:[401,400],empty:!1},n).then((o)=>o.data),import:(e,n)=>r({method:"POST",path:"/api/session/import",body:{info:e.info,messages:e.messages,location:e.location},successStatus:200,declaredStatuses:[409,401,400],empty:!1},n).then((o)=>o.data),export:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/export`,query:{sanitize:e.sanitize},successStatus:200,declaredStatuses:[404,500,401,400],empty:!1},n).then((o)=>o.data),active:(e)=>r({method:"GET",path:"/api/session/active",successStatus:200,declaredStatuses:[401,400],empty:!1},e).then((n)=>n.data),get:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}`,successStatus:200,declaredStatuses:[404,401,400],empty:!1},n).then((o)=>o.data),remove:(e,n)=>r({method:"DELETE",path:`/api/session/${encodeURIComponent(e.sessionID)}`,successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),fork:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/fork`,body:{boundary:e.boundary,policy:e.policy},successStatus:200,declaredStatuses:[404,400,401],empty:!1},n).then((o)=>o.data),switchAgent:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/agent`,body:{agent:e.agent},successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),switchModel:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/model`,body:{model:e.model},successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),rename:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/rename`,body:{title:e.title},successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),move:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/move`,body:{directory:e.directory,workspaceID:e.workspaceID,delivery:e.delivery},successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),prompt:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/prompt`,body:{id:e.id,text:e.text,files:e.files,agents:e.agents,output:e.output,skills:e.skills,metadata:e.metadata,delivery:e.delivery,resume:e.resume},successStatus:200,declaredStatuses:[409,400,404,401],empty:!1},n).then((o)=>o.data),command:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/command`,body:{id:e.id,command:e.command,arguments:e.arguments,agent:e.agent,model:e.model,files:e.files,agents:e.agents,skills:e.skills,delivery:e.delivery,resume:e.resume},successStatus:200,declaredStatuses:[409,400,404,500,401],empty:!1},n).then((o)=>o.data),skill:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/skill`,body:{id:e.id,skill:e.skill,resume:e.resume},successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),synthetic:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/synthetic`,body:{id:e.id,text:e.text,description:e.description,metadata:e.metadata,delivery:e.delivery,resume:e.resume},successStatus:200,declaredStatuses:[409,404,400,401],empty:!1},n).then((o)=>o.data),shell:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/shell`,body:{id:e.id,command:e.command},successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),compact:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/compact`,body:{id:e.id,delivery:e.delivery},successStatus:200,declaredStatuses:[409,404,400,401],empty:!1},n).then((o)=>o.data),wait:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/wait`,successStatus:204,declaredStatuses:[404,503,400,401],empty:!0},n),revert:{stage:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/revert/stage`,body:{messageID:e.messageID,files:e.files},successStatus:200,declaredStatuses:[404,409,500,400,401],empty:!1},n).then((o)=>o.data),clear:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/revert/clear`,successStatus:204,declaredStatuses:[404,409,500,400,401],empty:!0},n),commit:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/revert/commit`,successStatus:204,declaredStatuses:[404,409,400,401],empty:!0},n)},context:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/context`,successStatus:200,declaredStatuses:[404,500,401,400],empty:!1},n).then((o)=>o.data),inbox:{list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox`,successStatus:200,declaredStatuses:[404,401,400],empty:!1},n).then((o)=>o.data),cancel:(e,n)=>r({method:"DELETE",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox/${encodeURIComponent(e.inboxID)}`,successStatus:204,declaredStatuses:[409,404,401,400],empty:!0},n),steer:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox/${encodeURIComponent(e.inboxID)}/steer`,successStatus:204,declaredStatuses:[409,404,401,400],empty:!0},n),queue:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox/${encodeURIComponent(e.inboxID)}/queue`,successStatus:204,declaredStatuses:[409,404,401,400],empty:!0},n)},instructions:{entry:{list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/instructions/entries`,successStatus:200,declaredStatuses:[404,400,401],empty:!1},n).then((o)=>o.data),put:(e,n)=>r({method:"PUT",path:`/api/session/${encodeURIComponent(e.sessionID)}/instructions/entries/${encodeURIComponent(e.key)}`,body:{value:e.value},successStatus:204,declaredStatuses:[404,413,400,401],empty:!0},n),remove:(e,n)=>r({method:"DELETE",path:`/api/session/${encodeURIComponent(e.sessionID)}/instructions/entries/${encodeURIComponent(e.key)}`,successStatus:204,declaredStatuses:[404,400,401],empty:!0},n)}},generate:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/generate`,body:{prompt:e.prompt},successStatus:200,declaredStatuses:[404,503,400,401],empty:!1},n).then((o)=>o.data),log:(e,n)=>f({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/log`,query:{after:e.after,follow:e.follow},successStatus:200,declaredStatuses:[404,401,400],empty:!1},n),interrupt:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/interrupt`,query:{continue:e.continue},successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),background:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/background`,successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),message:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/message/${encodeURIComponent(e.messageID)}`,successStatus:200,declaredStatuses:[404,401,400],empty:!1},n).then((o)=>o.data),environment:(e,n)=>r({method:"PUT",path:`/api/session/${encodeURIComponent(e.sessionID)}/environment`,body:{variables:e.variables},successStatus:204,declaredStatuses:[404,401,400],empty:!0},n)},message:{list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/message`,query:{limit:e.limit,order:e.order,cursor:e.cursor},successStatus:200,declaredStatuses:[400,404,500,401],empty:!1},n)},model:{list:(e,n)=>r({method:"GET",path:"/api/model",query:{location:e?.location},successStatus:200,declaredStatuses:[503,401,400],empty:!1},n),default:(e,n)=>r({method:"GET",path:"/api/model/default",query:{location:e?.location},successStatus:200,declaredStatuses:[503,401,400],empty:!1},n)},generate:{text:(e,n)=>r({method:"POST",path:"/api/generate",query:{location:e.location},body:{prompt:e.prompt,model:e.model},successStatus:200,declaredStatuses:[400,503,401],empty:!1},n).then((o)=>o.data)},provider:{list:(e,n)=>r({method:"GET",path:"/api/provider",query:{location:e?.location},successStatus:200,declaredStatuses:[503,401,400],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/provider/${encodeURIComponent(e.providerID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[404,503,401,400],empty:!1},n)},integration:{list:(e,n)=>r({method:"GET",path:"/api/integration",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/integration/${encodeURIComponent(e.integrationID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),wellknown:{add:(e,n)=>r({method:"POST",path:"/api/experimental/integration/wellknown",query:{location:e.location},body:{url:e.url},successStatus:204,declaredStatuses:[400,401],empty:!0},n)},connect:{key:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/key`,query:{location:e.location},body:{key:e.key,answer:e.answer,label:e.label},successStatus:204,declaredStatuses:[400,401],empty:!0},n)},oauth:{connect:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/oauth`,query:{location:e.location},body:{methodID:e.methodID,answer:e.answer,label:e.label},successStatus:200,declaredStatuses:[400,401],empty:!1},n),status:(e,n)=>r({method:"GET",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/oauth/${encodeURIComponent(e.attemptID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),complete:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/oauth/${encodeURIComponent(e.attemptID)}/complete`,query:{location:e.location},body:{code:e.code},successStatus:204,declaredStatuses:[400,401],empty:!0},n),cancel:(e,n)=>r({method:"DELETE",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/oauth/${encodeURIComponent(e.attemptID)}`,query:{location:e.location},successStatus:204,declaredStatuses:[401,400],empty:!0},n)},command:{connect:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/command`,query:{location:e.location},body:{methodID:e.methodID,label:e.label},successStatus:200,declaredStatuses:[400,401],empty:!1},n),status:(e,n)=>r({method:"GET",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/command/${encodeURIComponent(e.attemptID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),cancel:(e,n)=>r({method:"DELETE",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/command/${encodeURIComponent(e.attemptID)}`,query:{location:e.location},successStatus:204,declaredStatuses:[401,400],empty:!0},n)}},auth:{status:(e,n)=>r({method:"GET",path:"/api/auth/status",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},mcp:{list:(e,n)=>r({method:"GET",path:"/api/mcp",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),add:(e,n)=>r({method:"PUT",path:`/api/mcp/${encodeURIComponent(e.server)}`,query:{location:e.location},body:{config:e.config},successStatus:204,declaredStatuses:[401,400],empty:!0},n),remove:(e,n)=>r({method:"DELETE",path:`/api/mcp/${encodeURIComponent(e.server)}`,query:{location:e.location},successStatus:204,declaredStatuses:[404,401,400],empty:!0},n),connect:(e,n)=>r({method:"POST",path:`/api/mcp/${encodeURIComponent(e.server)}/connect`,query:{location:e.location},successStatus:204,declaredStatuses:[404,401,400],empty:!0},n),disconnect:(e,n)=>r({method:"POST",path:`/api/mcp/${encodeURIComponent(e.server)}/disconnect`,query:{location:e.location},successStatus:204,declaredStatuses:[404,401,400],empty:!0},n),resource:{catalog:(e,n)=>r({method:"GET",path:"/api/mcp/resource",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)}},credential:{update:(e,n)=>r({method:"PATCH",path:`/api/credential/${encodeURIComponent(e.credentialID)}`,query:{location:e.location},body:{label:e.label},successStatus:204,declaredStatuses:[401,400],empty:!0},n),remove:(e,n)=>r({method:"DELETE",path:`/api/credential/${encodeURIComponent(e.credentialID)}`,query:{location:e.location},successStatus:204,declaredStatuses:[401,400],empty:!0},n)},project:{list:(e)=>r({method:"GET",path:"/api/project",successStatus:200,declaredStatuses:[401,400],empty:!1},e),current:(e,n)=>r({method:"GET",path:"/api/project/current",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},form:{request:{list:(e,n)=>r({method:"GET",path:"/api/form/request",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/form`,successStatus:200,declaredStatuses:[404,400,401],empty:!1},n).then((o)=>o.data),create:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/form`,body:{id:e.id,title:e.title,metadata:e.metadata,fields:e.fields},successStatus:200,declaredStatuses:[404,409,400,401],empty:!1},n).then((o)=>o.data),get:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/form/${encodeURIComponent(e.formID)}`,successStatus:200,declaredStatuses:[404,400,401],empty:!1},n).then((o)=>o.data),state:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/form/${encodeURIComponent(e.formID)}/state`,successStatus:200,declaredStatuses:[404,400,401],empty:!1},n).then((o)=>o.data),reply:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/form/${encodeURIComponent(e.formID)}/reply`,body:{answer:e.answer},successStatus:204,declaredStatuses:[404,409,400,401],empty:!0},n),cancel:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/form/${encodeURIComponent(e.formID)}/cancel`,successStatus:204,declaredStatuses:[404,409,400,401],empty:!0},n)},permission:{request:{list:(e,n)=>r({method:"GET",path:"/api/permission/request",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},saved:{list:(e,n)=>r({method:"GET",path:"/api/permission/saved",query:{projectID:e?.projectID},successStatus:200,declaredStatuses:[401,400],empty:!1},n).then((o)=>o.data),remove:(e,n)=>r({method:"DELETE",path:`/api/permission/saved/${encodeURIComponent(e.id)}`,successStatus:204,declaredStatuses:[401,400],empty:!0},n)},create:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission`,body:{id:e.id,action:e.action,resources:e.resources,save:e.save,metadata:e.metadata,source:e.source,agent:e.agent},successStatus:200,declaredStatuses:[404,400,401],empty:!1},n).then((o)=>o.data),list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission`,successStatus:200,declaredStatuses:[404,400,401],empty:!1},n).then((o)=>o.data),get:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission/${encodeURIComponent(e.requestID)}`,successStatus:200,declaredStatuses:[404,400,401],empty:!1},n).then((o)=>o.data),reply:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission/${encodeURIComponent(e.requestID)}/reply`,body:{reply:e.reply,message:e.message},successStatus:204,declaredStatuses:[404,400,401],empty:!0},n)},file:{read:(e,n)=>r({method:"GET",path:`/api/fs/read/${w(e.path)}`,query:{location:e.location},successStatus:200,declaredStatuses:[401,400],empty:!1,binary:!0},n),list:(e,n)=>r({method:"GET",path:"/api/fs/list",query:{location:e?.location,path:e?.path},successStatus:200,declaredStatuses:[401,400],empty:!1},n),find:(e,n)=>r({method:"GET",path:"/api/fs/find",query:{location:e.location,query:e.query,type:e.type,limit:e.limit},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},command:{list:(e,n)=>r({method:"GET",path:"/api/command",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},skill:{list:(e,n)=>r({method:"GET",path:"/api/skill",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},event:{subscribe:(e)=>f({method:"GET",path:"/api/event",successStatus:200,declaredStatuses:[401,400],empty:!1},e)},pty:{list:(e,n)=>r({method:"GET",path:"/api/pty",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),create:(e,n)=>r({method:"POST",path:"/api/pty",query:{location:e?.location},body:{command:e?.command,args:e?.args,cwd:e?.cwd,title:e?.title,env:e?.env},successStatus:200,declaredStatuses:[401,400],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/pty/${encodeURIComponent(e.ptyID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[404,401,400],empty:!1},n),update:(e,n)=>r({method:"PUT",path:`/api/pty/${encodeURIComponent(e.ptyID)}`,query:{location:e.location},body:{title:e.title,size:e.size},successStatus:200,declaredStatuses:[404,401,400],empty:!1},n),remove:(e,n)=>r({method:"DELETE",path:`/api/pty/${encodeURIComponent(e.ptyID)}`,query:{location:e.location},successStatus:204,declaredStatuses:[404,401,400],empty:!0},n)},shell:{list:(e,n)=>r({method:"GET",path:"/api/shell",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),create:(e,n)=>r({method:"POST",path:"/api/shell",query:{location:e.location},body:{command:e.command,cwd:e.cwd,timeout:e.timeout,metadata:e.metadata},successStatus:200,declaredStatuses:[401,400],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/shell/${encodeURIComponent(e.id)}`,query:{location:e.location},successStatus:200,declaredStatuses:[404,401,400],empty:!1},n),timeout:(e,n)=>r({method:"PATCH",path:`/api/shell/${encodeURIComponent(e.id)}/timeout`,query:{location:e.location},body:{timeout:e.timeout},successStatus:200,declaredStatuses:[404,401,400],empty:!1},n),output:(e,n)=>r({method:"GET",path:`/api/shell/${encodeURIComponent(e.id)}/output`,query:{location:e.location,cursor:e.cursor,limit:e.limit},successStatus:200,declaredStatuses:[404,401,400],empty:!1},n),remove:(e,n)=>r({method:"DELETE",path:`/api/shell/${encodeURIComponent(e.id)}`,query:{location:e.location},successStatus:204,declaredStatuses:[404,401,400],empty:!0},n)},reference:{list:(e,n)=>r({method:"GET",path:"/api/reference",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},worktree:{list:(e,n)=>r({method:"GET",path:`/api/worktree/${encodeURIComponent(e.projectID)}`,successStatus:200,declaredStatuses:[401,400],empty:!1},n),create:(e,n)=>r({method:"POST",path:`/api/worktree/${encodeURIComponent(e.projectID)}`,body:{strategy:e.strategy,from:e.from,directory:e.directory,name:e.name},successStatus:200,declaredStatuses:[400,401],empty:!1},n),remove:(e,n)=>r({method:"DELETE",path:`/api/worktree/${encodeURIComponent(e.projectID)}`,body:{directory:e.directory,force:e.force},successStatus:204,declaredStatuses:[400,401],empty:!0},n),refresh:(e,n)=>r({method:"POST",path:`/api/worktree/${encodeURIComponent(e.projectID)}/refresh`,successStatus:204,declaredStatuses:[400,401],empty:!0},n)},vcs:{get:(e,n)=>r({method:"GET",path:"/api/vcs",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),status:(e,n)=>r({method:"GET",path:"/api/vcs/status",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),diff:(e,n)=>r({method:"GET",path:"/api/vcs/diff",query:{location:e.location,mode:e.mode,context:e.context},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},debug:{location:{list:(e)=>r({method:"GET",path:"/api/debug/location",successStatus:200,declaredStatuses:[401,400],empty:!1},e),evict:(e,n)=>r({method:"DELETE",path:"/api/debug/location",query:{location:e?.location},successStatus:204,declaredStatuses:[401,400],empty:!0},n)}},migration:{v1:{status:(e)=>r({method:"GET",path:"/api/experimental/migration/v1",successStatus:200,declaredStatuses:[401,400],empty:!1},e)}},websearch:{providers:(e,n)=>r({method:"GET",path:"/api/websearch/provider",query:{location:e?.location},successStatus:200,declaredStatuses:[503,401,400],empty:!1},n),query:(e,n)=>r({method:"POST",path:"/api/websearch",query:{location:e.location},body:{query:e.query,providerID:e.providerID},successStatus:200,declaredStatuses:[400,503,401],empty:!1},n)},config:{get:(e,n)=>r({method:"GET",path:"/api/config",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)}}}function w(t){return t.split("/").map(encodeURIComponent).join("/")}function b(t,s,i){if(i===void 0)return;if(i===null){t.append(s,"null");return}if(Array.isArray(i)){for(let u of i)b(t,s,u);return}if(typeof i==="object"){for(let[u,g]of Object.entries(i))b(t,`${s}[${u}]`,g);return}t.append(s,String(i))}async function h(t){if(!D(t,"application/json")&&!t.headers.get("content-type")?.includes("+json")){try{await t.body?.cancel()}catch{}throw new d("UnsupportedContentType")}let s;try{s=await t.text()}catch(i){throw new d("Transport",{cause:i})}if(s==="")throw new d("MalformedResponse");try{return JSON.parse(s)}catch(i){throw new d("MalformedResponse",{cause:i})}}function D(t,s){return t.headers.get("content-type")?.split(";",1)[0]?.trim().toLowerCase()===s}var F=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="UnauthorizedError",M=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="InvalidRequestError",N=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="AgentNotFoundError",T=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="InvalidCursorError",U=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ConflictError",V=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="SessionNotFoundError",J=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="UnknownError",j=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="MessageNotFoundError",G=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="CommandNotFoundError",_=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="CommandEvaluationError",$=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="SkillNotFoundError",W=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ServiceUnavailableError",z=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="SessionBusyError",B=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="InstructionEntryValueTooLargeError",H=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ProviderNotFoundError",Q=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="McpServerNotFoundError",K=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FormNotFoundError",X=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FormAlreadySettledError",Y=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FormInvalidAnswerError",Z=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="PermissionNotFoundError",ee=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="PtyNotFoundError",ne=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ShellNotFoundError",te=(t)=>typeof t==="object"&&t!==null&&("name"in t)&&t.name==="WorktreeError";export{te as isWorktreeError,J as isUnknownError,F as isUnauthorizedError,$ as isSkillNotFoundError,ne as isShellNotFoundError,V as isSessionNotFoundError,z as isSessionBusyError,W as isServiceUnavailableError,ee as isPtyNotFoundError,H as isProviderNotFoundError,Z as isPermissionNotFoundError,j as isMessageNotFoundError,Q as isMcpServerNotFoundError,M as isInvalidRequestError,T as isInvalidCursorError,B as isInstructionEntryValueTooLargeError,K as isFormNotFoundError,Y as isFormInvalidAnswerError,X as isFormAlreadySettledError,U as isConflictError,G as isCommandNotFoundError,_ as isCommandEvaluationError,N as isAgentNotFoundError,R as OpenCode,d as ClientError};
12
+ `)}if(p.done)return}}finally{try{await l.cancel()}catch{}l.releaseLock()}}});return{health:{get:(e)=>r({method:"GET",path:"/api/health",successStatus:200,declaredStatuses:[401,400],empty:!1},e)},server:{get:(e)=>r({method:"GET",path:"/api/server",successStatus:200,declaredStatuses:[401,400],empty:!1},e)},location:{get:(e,n)=>r({method:"GET",path:"/api/location",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},agent:{list:(e,n)=>r({method:"GET",path:"/api/agent",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/agent/${encodeURIComponent(e.agentID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[404,401,400],empty:!1},n)},plugin:{list:(e,n)=>r({method:"GET",path:"/api/plugin",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},session:{list:(e,n)=>r({method:"GET",path:"/api/session",query:{workspace:e?.workspace,limit:e?.limit,order:e?.order,search:e?.search,parentID:e?.parentID,directory:e?.directory,project:e?.project,subpath:e?.subpath,cursor:e?.cursor},successStatus:200,declaredStatuses:[400,401],empty:!1},n),stats:(e,n)=>r({method:"GET",path:"/api/session/stats",query:{from:e?.from,to:e?.to,project:e?.project,timezone:e?.timezone,tools:e?.tools},successStatus:200,declaredStatuses:[400,401],empty:!1},n).then((o)=>o.data),create:(e,n)=>r({method:"POST",path:"/api/session",body:{id:e?.id,title:e?.title,agent:e?.agent,model:e?.model,location:e?.location,policy:e?.policy,metadata:e?.metadata,tools:e?.tools},successStatus:200,declaredStatuses:[400,401],empty:!1},n).then((o)=>o.data),import:(e,n)=>r({method:"POST",path:"/api/session/import",body:{info:e.info,messages:e.messages,location:e.location},successStatus:200,declaredStatuses:[409,404,401,400],empty:!1},n).then((o)=>o.data),export:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/export`,query:{sanitize:e.sanitize},successStatus:200,declaredStatuses:[404,500,401,400],empty:!1},n).then((o)=>o.data),active:(e)=>r({method:"GET",path:"/api/session/active",successStatus:200,declaredStatuses:[401,400],empty:!1},e).then((n)=>n.data),get:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}`,successStatus:200,declaredStatuses:[404,401,400],empty:!1},n).then((o)=>o.data),remove:(e,n)=>r({method:"DELETE",path:`/api/session/${encodeURIComponent(e.sessionID)}`,successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),fork:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/fork`,body:{boundary:e.boundary,policy:e.policy,tools:e.tools},successStatus:200,declaredStatuses:[404,400,401],empty:!1},n).then((o)=>o.data),switchAgent:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/agent`,body:{agent:e.agent},successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),switchModel:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/model`,body:{model:e.model},successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),rename:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/rename`,body:{title:e.title},successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),move:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/move`,body:{directory:e.directory,workspaceID:e.workspaceID,delivery:e.delivery},successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),prompt:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/prompt`,body:{id:e.id,text:e.text,files:e.files,agents:e.agents,skills:e.skills,metadata:e.metadata,delivery:e.delivery,resume:e.resume},successStatus:200,declaredStatuses:[409,400,404,401],empty:!1},n).then((o)=>o.data),command:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/command`,body:{command:e.command,text:e.text,files:e.files,agents:e.agents,skills:e.skills,delivery:e.delivery},successStatus:204,declaredStatuses:[404,500,400,401],empty:!0},n),skill:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/skill`,body:{id:e.id,skill:e.skill,resume:e.resume},successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),synthetic:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/synthetic`,body:{id:e.id,text:e.text,description:e.description,metadata:e.metadata,delivery:e.delivery,resume:e.resume},successStatus:200,declaredStatuses:[409,404,400,401],empty:!1},n).then((o)=>o.data),shell:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/shell`,body:{id:e.id,command:e.command},successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),compact:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/compact`,body:{id:e.id,delivery:e.delivery},successStatus:200,declaredStatuses:[409,404,400,401],empty:!1},n).then((o)=>o.data),wait:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/wait`,successStatus:204,declaredStatuses:[404,503,400,401],empty:!0},n),revert:{stage:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/revert/stage`,body:{messageID:e.messageID,files:e.files},successStatus:200,declaredStatuses:[404,409,500,400,401],empty:!1},n).then((o)=>o.data),clear:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/revert/clear`,successStatus:204,declaredStatuses:[404,409,500,400,401],empty:!0},n),commit:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/revert/commit`,successStatus:204,declaredStatuses:[404,409,400,401],empty:!0},n)},context:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/context`,successStatus:200,declaredStatuses:[404,500,401,400],empty:!1},n).then((o)=>o.data),inbox:{list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox`,successStatus:200,declaredStatuses:[404,401,400],empty:!1},n).then((o)=>o.data),cancel:(e,n)=>r({method:"DELETE",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox/${encodeURIComponent(e.inboxID)}`,successStatus:204,declaredStatuses:[409,404,401,400],empty:!0},n),steer:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox/${encodeURIComponent(e.inboxID)}/steer`,successStatus:204,declaredStatuses:[409,404,401,400],empty:!0},n),queue:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox/${encodeURIComponent(e.inboxID)}/queue`,successStatus:204,declaredStatuses:[409,404,401,400],empty:!0},n)},instructions:{entry:{list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/instructions/entries`,successStatus:200,declaredStatuses:[404,400,401],empty:!1},n).then((o)=>o.data),put:(e,n)=>r({method:"PUT",path:`/api/session/${encodeURIComponent(e.sessionID)}/instructions/entries/${encodeURIComponent(e.key)}`,body:{value:e.value},successStatus:204,declaredStatuses:[404,413,400,401],empty:!0},n),remove:(e,n)=>r({method:"DELETE",path:`/api/session/${encodeURIComponent(e.sessionID)}/instructions/entries/${encodeURIComponent(e.key)}`,successStatus:204,declaredStatuses:[404,400,401],empty:!0},n)}},tools:{put:(e,n)=>r({method:"PUT",path:`/api/session/${encodeURIComponent(e.sessionID)}/tools`,body:{tools:e.tools},successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/tools`,successStatus:200,declaredStatuses:[404,400,401],empty:!1},n).then((o)=>o.data),calls:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/tools/calls`,successStatus:200,declaredStatuses:[404,400,401],empty:!1},n).then((o)=>o.data),reply:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/tools/calls/${encodeURIComponent(e.callID)}/reply`,body:e.payload,successStatus:204,declaredStatuses:[404,409,400,401],empty:!0},n)},generate:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/generate`,body:{prompt:e.prompt},successStatus:200,declaredStatuses:[404,503,400,401],empty:!1},n).then((o)=>o.data),log:(e,n)=>x({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/log`,query:{after:e.after,follow:e.follow},successStatus:200,declaredStatuses:[404,401,400],empty:!1},n),interrupt:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/interrupt`,query:{continue:e.continue},successStatus:200,declaredStatuses:[404,400,401],empty:!1},n),background:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/background`,successStatus:204,declaredStatuses:[404,400,401],empty:!0},n),message:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/message/${encodeURIComponent(e.messageID)}`,successStatus:200,declaredStatuses:[404,401,400],empty:!1},n).then((o)=>o.data),messageUpdate:(e,n)=>r({method:"PATCH",path:`/api/session/${encodeURIComponent(e.sessionID)}/message/${encodeURIComponent(e.messageID)}`,body:{content:e.content},successStatus:200,declaredStatuses:[404,400,409,401],empty:!1},n).then((o)=>o.data),environment:(e,n)=>r({method:"PUT",path:`/api/session/${encodeURIComponent(e.sessionID)}/environment`,body:{variables:e.variables},successStatus:204,declaredStatuses:[404,401,400],empty:!0},n),view:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/view`,body:{idle:e.idle},successStatus:204,declaredStatuses:[404,401,400],empty:!0},n)},message:{list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/message`,query:{limit:e.limit,order:e.order,cursor:e.cursor},successStatus:200,declaredStatuses:[400,404,500,401],empty:!1},n)},model:{list:(e,n)=>r({method:"GET",path:"/api/model",query:{location:e?.location},successStatus:200,declaredStatuses:[503,401,400],empty:!1},n),default:(e,n)=>r({method:"GET",path:"/api/model/default",query:{location:e?.location},successStatus:200,declaredStatuses:[503,401,400],empty:!1},n)},generate:{text:(e,n)=>r({method:"POST",path:"/api/generate",body:{prompt:e.prompt,model:e.model},successStatus:200,declaredStatuses:[400,503,401],empty:!1},n).then((o)=>o.data)},provider:{list:(e,n)=>r({method:"GET",path:"/api/provider",query:{location:e?.location},successStatus:200,declaredStatuses:[503,401,400],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/provider/${encodeURIComponent(e.providerID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[404,503,401,400],empty:!1},n)},integration:{list:(e,n)=>r({method:"GET",path:"/api/integration",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/integration/${encodeURIComponent(e.integrationID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),wellknown:{add:(e,n)=>r({method:"POST",path:"/api/experimental/integration/wellknown",query:{location:e.location},body:{url:e.url},successStatus:204,declaredStatuses:[400,401],empty:!0},n)},connect:{key:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/key`,query:{location:e.location},body:{key:e.key,answer:e.answer,label:e.label},successStatus:204,declaredStatuses:[400,401],empty:!0},n)},oauth:{connect:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/oauth`,query:{location:e.location},body:{methodID:e.methodID,answer:e.answer,label:e.label},successStatus:200,declaredStatuses:[400,401],empty:!1},n),status:(e,n)=>r({method:"GET",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/oauth/${encodeURIComponent(e.attemptID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),complete:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/oauth/${encodeURIComponent(e.attemptID)}/complete`,query:{location:e.location},body:{code:e.code},successStatus:204,declaredStatuses:[400,401],empty:!0},n),cancel:(e,n)=>r({method:"DELETE",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/oauth/${encodeURIComponent(e.attemptID)}`,query:{location:e.location},successStatus:204,declaredStatuses:[401,400],empty:!0},n)},command:{connect:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/command`,query:{location:e.location},body:{methodID:e.methodID,label:e.label},successStatus:200,declaredStatuses:[400,401],empty:!1},n),status:(e,n)=>r({method:"GET",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/command/${encodeURIComponent(e.attemptID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),cancel:(e,n)=>r({method:"DELETE",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/command/${encodeURIComponent(e.attemptID)}`,query:{location:e.location},successStatus:204,declaredStatuses:[401,400],empty:!0},n)}},auth:{status:(e,n)=>r({method:"GET",path:"/api/auth/status",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},mcp:{list:(e,n)=>r({method:"GET",path:"/api/mcp",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),add:(e,n)=>r({method:"PUT",path:`/api/mcp/${encodeURIComponent(e.server)}`,query:{location:e.location},body:{config:e.config},successStatus:204,declaredStatuses:[401,400],empty:!0},n),remove:(e,n)=>r({method:"DELETE",path:`/api/mcp/${encodeURIComponent(e.server)}`,query:{location:e.location},successStatus:204,declaredStatuses:[404,401,400],empty:!0},n),connect:(e,n)=>r({method:"POST",path:`/api/mcp/${encodeURIComponent(e.server)}/connect`,query:{location:e.location},successStatus:204,declaredStatuses:[404,401,400],empty:!0},n),disconnect:(e,n)=>r({method:"POST",path:`/api/mcp/${encodeURIComponent(e.server)}/disconnect`,query:{location:e.location},successStatus:204,declaredStatuses:[404,401,400],empty:!0},n),resource:{catalog:(e,n)=>r({method:"GET",path:"/api/mcp/resource",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)}},credential:{update:(e,n)=>r({method:"PATCH",path:`/api/credential/${encodeURIComponent(e.credentialID)}`,query:{location:e.location},body:{label:e.label},successStatus:204,declaredStatuses:[401,400],empty:!0},n),activate:(e,n)=>r({method:"POST",path:`/api/credential/${encodeURIComponent(e.credentialID)}/activate`,query:{location:e.location},successStatus:204,declaredStatuses:[401,400],empty:!0},n),remove:(e,n)=>r({method:"DELETE",path:`/api/credential/${encodeURIComponent(e.credentialID)}`,query:{location:e.location},successStatus:204,declaredStatuses:[401,400],empty:!0},n)},project:{list:(e)=>r({method:"GET",path:"/api/project",successStatus:200,declaredStatuses:[401,400],empty:!1},e),update:(e,n)=>r({method:"PATCH",path:`/api/project/${encodeURIComponent(e.projectID)}`,body:{name:e.name,icon:e.icon,commands:e.commands},successStatus:200,declaredStatuses:[404,401,400],empty:!1},n),current:(e,n)=>r({method:"GET",path:"/api/project/current",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},form:{request:{list:(e,n)=>r({method:"GET",path:"/api/form/request",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/form`,successStatus:200,declaredStatuses:[404,401,400],empty:!1},n).then((o)=>o.data),create:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/form`,body:{id:e.id,title:e.title,metadata:e.metadata,fields:e.fields},successStatus:200,declaredStatuses:[404,409,400,401],empty:!1},n).then((o)=>o.data),get:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/form/${encodeURIComponent(e.formID)}`,successStatus:200,declaredStatuses:[404,400,401],empty:!1},n).then((o)=>o.data),state:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/form/${encodeURIComponent(e.formID)}/state`,successStatus:200,declaredStatuses:[404,400,401],empty:!1},n).then((o)=>o.data),reply:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/form/${encodeURIComponent(e.formID)}/reply`,body:{answer:e.answer},successStatus:204,declaredStatuses:[404,409,400,401],empty:!0},n),cancel:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/form/${encodeURIComponent(e.formID)}/cancel`,successStatus:204,declaredStatuses:[404,409,400,401],empty:!0},n)},permission:{request:{list:(e,n)=>r({method:"GET",path:"/api/permission/request",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},saved:{list:(e,n)=>r({method:"GET",path:"/api/permission/saved",query:{projectID:e?.projectID},successStatus:200,declaredStatuses:[401,400],empty:!1},n).then((o)=>o.data),remove:(e,n)=>r({method:"DELETE",path:`/api/permission/saved/${encodeURIComponent(e.id)}`,successStatus:204,declaredStatuses:[401,400],empty:!0},n)},create:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission`,body:{id:e.id,action:e.action,resources:e.resources,save:e.save,metadata:e.metadata,source:e.source,agent:e.agent},successStatus:200,declaredStatuses:[404,400,401],empty:!1},n).then((o)=>o.data),list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission`,successStatus:200,declaredStatuses:[404,401,400],empty:!1},n).then((o)=>o.data),get:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission/${encodeURIComponent(e.requestID)}`,successStatus:200,declaredStatuses:[404,400,401],empty:!1},n).then((o)=>o.data),reply:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission/${encodeURIComponent(e.requestID)}/reply`,body:{reply:e.reply,message:e.message},successStatus:204,declaredStatuses:[404,400,401],empty:!0},n)},file:{read:(e,n)=>r({method:"GET",path:`/api/fs/read/${A(e.path)}`,query:{location:e.location},successStatus:200,declaredStatuses:[401,400],empty:!1,binary:!0},n),list:(e,n)=>r({method:"GET",path:"/api/fs/list",query:{location:e?.location,path:e?.path},successStatus:200,declaredStatuses:[401,400],empty:!1},n),find:(e,n)=>r({method:"GET",path:"/api/fs/find",query:{location:e.location,query:e.query,type:e.type,limit:e.limit},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},command:{list:(e,n)=>r({method:"GET",path:"/api/command",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},skill:{list:(e,n)=>r({method:"GET",path:"/api/skill",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},event:{subscribe:(e)=>x({method:"GET",path:"/api/event",successStatus:200,declaredStatuses:[401,400],empty:!1},e)},pty:{list:(e,n)=>r({method:"GET",path:"/api/pty",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),create:(e,n)=>r({method:"POST",path:"/api/pty",query:{location:e?.location},body:{command:e?.command,args:e?.args,cwd:e?.cwd,title:e?.title,env:e?.env},successStatus:200,declaredStatuses:[401,400],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/pty/${encodeURIComponent(e.ptyID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[404,401,400],empty:!1},n),update:(e,n)=>r({method:"PUT",path:`/api/pty/${encodeURIComponent(e.ptyID)}`,query:{location:e.location},body:{title:e.title,size:e.size},successStatus:200,declaredStatuses:[404,401,400],empty:!1},n),remove:(e,n)=>r({method:"DELETE",path:`/api/pty/${encodeURIComponent(e.ptyID)}`,query:{location:e.location},successStatus:204,declaredStatuses:[404,401,400],empty:!0},n),connect:{token:(e,n)=>r({method:"POST",path:`/api/pty/${encodeURIComponent(e.ptyID)}/connect-token`,query:{location:e.location},headers:{"x-opencode-ticket":e["x-opencode-ticket"]},successStatus:200,declaredStatuses:[403,404,401,400],empty:!1},n)}},experimental:{persistentPty:{read:(e,n)=>r({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/terminal/read`,query:{lines:e.lines},successStatus:200,declaredStatuses:[503,401,400],empty:!1},n).then((o)=>o.data),list:(e,n)=>r({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/terminal`,successStatus:200,declaredStatuses:[400,503,401],empty:!1},n).then((o)=>o.data),create:(e,n)=>r({method:"POST",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/terminal`,body:{command:e.command,args:e.args,cwd:e.cwd,title:e.title,env:e.env,size:e.size},successStatus:200,declaredStatuses:[400,503,401],empty:!1},n).then((o)=>o.data),shutdown:(e)=>r({method:"POST",path:"/api/experimental/persistent-pty/shutdown",successStatus:204,declaredStatuses:[503,401,400],empty:!0},e),handoff:(e)=>r({method:"POST",path:"/api/experimental/persistent-pty/handoff",successStatus:200,declaredStatuses:[503,401,400],empty:!1},e),get:(e,n)=>r({method:"GET",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}`,successStatus:200,declaredStatuses:[404,503,401,400],empty:!1},n).then((o)=>o.data),update:(e,n)=>r({method:"PUT",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}`,body:{attachmentID:e.attachmentID,size:e.size},successStatus:200,declaredStatuses:[404,503,401,400],empty:!1},n).then((o)=>o.data),snapshot:(e,n)=>r({method:"GET",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}/snapshot`,successStatus:200,declaredStatuses:[404,503,401,400],empty:!1},n).then((o)=>o.data),remove:(e,n)=>r({method:"DELETE",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}`,successStatus:204,declaredStatuses:[404,503,401,400],empty:!0},n),connectToken:(e,n)=>r({method:"POST",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}/connect-token`,headers:{"x-opencode-ticket":e["x-opencode-ticket"]},successStatus:200,declaredStatuses:[403,404,503,401,400],empty:!1},n).then((o)=>o.data)}},shell:{list:(e,n)=>r({method:"GET",path:"/api/shell",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),create:(e,n)=>r({method:"POST",path:"/api/shell",query:{location:e.location},body:{command:e.command,cwd:e.cwd,timeout:e.timeout,metadata:e.metadata},successStatus:200,declaredStatuses:[401,400],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/shell/${encodeURIComponent(e.id)}`,query:{location:e.location},successStatus:200,declaredStatuses:[404,401,400],empty:!1},n),timeout:(e,n)=>r({method:"PATCH",path:`/api/shell/${encodeURIComponent(e.id)}/timeout`,query:{location:e.location},body:{timeout:e.timeout},successStatus:200,declaredStatuses:[404,401,400],empty:!1},n),output:(e,n)=>r({method:"GET",path:`/api/shell/${encodeURIComponent(e.id)}/output`,query:{location:e.location,cursor:e.cursor,limit:e.limit},successStatus:200,declaredStatuses:[404,401,400],empty:!1},n),remove:(e,n)=>r({method:"DELETE",path:`/api/shell/${encodeURIComponent(e.id)}`,query:{location:e.location},successStatus:204,declaredStatuses:[404,401,400],empty:!0},n)},reference:{list:(e,n)=>r({method:"GET",path:"/api/reference",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)},worktree:{list:(e,n)=>r({method:"GET",path:`/api/worktree/${encodeURIComponent(e.projectID)}`,successStatus:200,declaredStatuses:[401,400],empty:!1},n),create:(e,n)=>r({method:"POST",path:`/api/worktree/${encodeURIComponent(e.projectID)}`,body:{strategy:e.strategy,from:e.from,branch:e.branch,directory:e.directory,name:e.name},successStatus:200,declaredStatuses:[400,401],empty:!1},n),remove:(e,n)=>r({method:"DELETE",path:`/api/worktree/${encodeURIComponent(e.projectID)}`,body:{directory:e.directory,force:e.force},successStatus:204,declaredStatuses:[400,401],empty:!0},n),refresh:(e,n)=>r({method:"POST",path:`/api/worktree/${encodeURIComponent(e.projectID)}/refresh`,successStatus:204,declaredStatuses:[400,401],empty:!0},n)},workspace:{create:(e,n)=>r({method:"POST",path:"/api/workspace",body:{id:e.id,provider:e.provider},successStatus:200,declaredStatuses:[409,404,401,400],empty:!1},n).then((o)=>o.data),destroy:(e,n)=>r({method:"DELETE",path:`/api/workspace/${encodeURIComponent(e.workspaceID)}`,successStatus:200,declaredStatuses:[500,401,400],empty:!1},n)},vcs:{get:(e,n)=>r({method:"GET",path:"/api/vcs",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),base:(e,n)=>r({method:"GET",path:"/api/vcs/base",query:{location:e?.location},successStatus:200,declaredStatuses:[503,401,400],empty:!1},n),status:(e,n)=>r({method:"GET",path:"/api/vcs/status",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n),branches:(e,n)=>r({method:"GET",path:"/api/vcs/branches",query:{location:e?.location,search:e?.search,limit:e?.limit},successStatus:200,declaredStatuses:[401,400],empty:!1},n),diff:(e,n)=>r({method:"GET",path:"/api/vcs/diff",query:{location:e.location,mode:e.mode,base:e.base,context:e.context},successStatus:200,declaredStatuses:[503,401,400],empty:!1},n)},debug:{location:{list:(e)=>r({method:"GET",path:"/api/debug/location",successStatus:200,declaredStatuses:[401,400],empty:!1},e),evict:(e,n)=>r({method:"DELETE",path:"/api/debug/location",query:{location:e?.location},successStatus:204,declaredStatuses:[401,400],empty:!0},n)}},migration:{v1:{status:(e)=>r({method:"GET",path:"/api/experimental/migration/v1",successStatus:200,declaredStatuses:[401,400],empty:!1},e)}},websearch:{providers:(e,n)=>r({method:"GET",path:"/api/websearch/provider",query:{location:e?.location},successStatus:200,declaredStatuses:[503,401,400],empty:!1},n),query:(e,n)=>r({method:"POST",path:"/api/websearch",query:{location:e.location},body:{query:e.query,providerID:e.providerID},successStatus:200,declaredStatuses:[400,503,401],empty:!1},n)},config:{get:(e,n)=>r({method:"GET",path:"/api/config",query:{location:e?.location},successStatus:200,declaredStatuses:[401,400],empty:!1},n)}}}function A(t){return t.split("/").map(encodeURIComponent).join("/")}function b(t,s,i){if(i===void 0)return;if(i===null){t.append(s,"null");return}if(Array.isArray(i)){for(let u of i)b(t,s,u);return}if(typeof i==="object"){for(let[u,g]of Object.entries(i))b(t,`${s}[${u}]`,g);return}t.append(s,String(i))}async function h(t){if(!D(t,"application/json")&&!t.headers.get("content-type")?.includes("+json")){try{await t.body?.cancel()}catch{}throw new d("UnsupportedContentType")}let s;try{s=await t.text()}catch(i){throw new d("Transport",{cause:i})}if(s==="")throw new d("MalformedResponse");try{return JSON.parse(s)}catch(i){throw new d("MalformedResponse",{cause:i})}}function D(t,s){return t.headers.get("content-type")?.split(";",1)[0]?.trim().toLowerCase()===s}var L=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="UnauthorizedError",M=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="InvalidRequestError",F=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="AgentNotFoundError",N=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="InvalidCursorError",U=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ConflictError",V=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="SessionNotFoundError",j=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="UnknownError",J=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="MessageNotFoundError",G=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="CommandNotFoundError",$=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="CommandExecutionError",_=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="SkillNotFoundError",W=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ServiceUnavailableError",z=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="SessionBusyError",B=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="InstructionEntryValueTooLargeError",H=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ProviderNotFoundError",Q=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="McpServerNotFoundError",K=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ProjectNotFoundError",X=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FormNotFoundError",Y=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FormAlreadySettledError",Z=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FormInvalidAnswerError",ee=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="PermissionNotFoundError",ne=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="PtyNotFoundError",te=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ForbiddenError",re=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ShellNotFoundError",oe=(t)=>typeof t==="object"&&t!==null&&("name"in t)&&t.name==="WorktreeError";export{oe as isWorktreeError,j as isUnknownError,L as isUnauthorizedError,_ as isSkillNotFoundError,re as isShellNotFoundError,V as isSessionNotFoundError,z as isSessionBusyError,W as isServiceUnavailableError,ne as isPtyNotFoundError,H as isProviderNotFoundError,K as isProjectNotFoundError,ee as isPermissionNotFoundError,J as isMessageNotFoundError,Q as isMcpServerNotFoundError,M as isInvalidRequestError,N as isInvalidCursorError,B as isInstructionEntryValueTooLargeError,X as isFormNotFoundError,Z as isFormInvalidAnswerError,Y as isFormAlreadySettledError,te as isForbiddenError,U as isConflictError,G as isCommandNotFoundError,$ as isCommandExecutionError,F as isAgentNotFoundError,R as OpenCode,d as ClientError};
package/client/service.js CHANGED
@@ -1,9 +1,10 @@
1
- import { readFile } from "node:fs/promises";
1
+ import { readFile, rm } from "node:fs/promises";
2
2
  import { homedir } from "node:os";
3
3
  import { join } from "node:path";
4
4
  import { contenderFailure, contenderFinished, spawnServiceContender, } from "../service-contender.js";
5
5
  import { defaultEnsureTiming, ensureTiming } from "../service-timing.js";
6
6
  import { matchesVersion } from "../service-version.js";
7
+ import { PtyHandoff } from "../pty-handoff.js";
7
8
  export * from "../service.js";
8
9
  // Find, start, and stop the local opencode background service.
9
10
  //
@@ -12,15 +13,12 @@ export * from "../service.js";
12
13
  // Effect or @effect/platform-node at runtime.
13
14
  /** Discover a healthy, compatible local service without starting one. */
14
15
  export async function discover(options = {}) {
15
- return (await discoverLocal(options))?.endpoint;
16
- }
17
- async function discoverLocal(options) {
18
16
  const found = (await registered(options.file)).service;
19
17
  if (found?.state !== "ready")
20
18
  return undefined;
21
19
  if (!matchesVersion(found.version, options))
22
20
  return undefined;
23
- return found;
21
+ return found.endpoint;
24
22
  }
25
23
  /** Ensure a healthy, compatible local service is running. */
26
24
  export async function ensure(options = {}) {
@@ -37,12 +35,12 @@ export async function ensure(options = {}) {
37
35
  announced = true;
38
36
  options.onStart?.(reason, previousVersion);
39
37
  };
40
- const spawnContender = () => {
38
+ const spawnContender = async () => {
41
39
  const [command, ...args] = options.command ?? ["opencode", "serve", "--service"];
42
40
  if (command === undefined)
43
41
  throw new Error("Missing service command");
44
42
  try {
45
- return spawnServiceContender(command, args);
43
+ return spawnServiceContender(command, args, await PtyHandoff.environment(options.file ?? fallback(), options.env));
46
44
  }
47
45
  catch (cause) {
48
46
  throw new Error("Failed to start server", { cause });
@@ -60,7 +58,9 @@ export async function ensure(options = {}) {
60
58
  };
61
59
  if (timeouts.count >= 3) {
62
60
  announce("missing");
63
- await evict(registration.info, options, timing);
61
+ console.warn("Background service is unresponsive; recovery cannot preserve persistent terminals");
62
+ await PtyHandoff.clear(options.file ?? fallback());
63
+ await terminate(registration.info, options, timing);
64
64
  timeouts = undefined;
65
65
  lastSpawn = Date.now() - spawnDelay;
66
66
  }
@@ -71,13 +71,22 @@ export async function ensure(options = {}) {
71
71
  spawnDelay = timing.spawnDelay;
72
72
  const service = registration.service;
73
73
  const compatible = !service.legacy && matchesVersion(service.version, options);
74
- if (compatible && service.state === "ready")
74
+ if (compatible && service.state === "ready") {
75
+ await PtyHandoff.complete(options.file ?? fallback(), service.info);
75
76
  return service.endpoint;
77
+ }
76
78
  if (compatible && service.state === "failed")
77
79
  throw new Error("Background service failed to start");
78
80
  if (!compatible) {
79
81
  announce("version-mismatch", service.version);
80
- await kill(service, options, timing).catch(() => undefined);
82
+ if (!service.legacy && service.state === "ready")
83
+ await PtyHandoff.prepare(options.file ?? fallback(), service.info, timing.requestTimeout);
84
+ else {
85
+ if (!service.legacy)
86
+ console.warn("Background service is not ready; replacement cannot preserve persistent terminals");
87
+ await PtyHandoff.clear(options.file ?? fallback());
88
+ }
89
+ await terminate(service.info, options, timing).catch(() => undefined);
81
90
  lastSpawn = 0;
82
91
  }
83
92
  }
@@ -95,7 +104,7 @@ export async function ensure(options = {}) {
95
104
  // Keep one candidate plus one lock probe so a pre-lock stall cannot block recovery.
96
105
  if (contenders.size < 2 && Date.now() - lastSpawn >= spawnDelay) {
97
106
  announce("missing");
98
- contenders.add(spawnContender());
107
+ contenders.add(await spawnContender());
99
108
  lastSpawn = Date.now();
100
109
  }
101
110
  }
@@ -108,9 +117,10 @@ export async function ensure(options = {}) {
108
117
  }
109
118
  /** Stop the registered local service. */
110
119
  export async function stop(options = {}) {
111
- const existing = await find(options);
112
- if (existing !== undefined)
113
- await kill(existing, options, defaultEnsureTiming);
120
+ await PtyHandoff.clear(options.file ?? fallback());
121
+ const info = await read(options.file);
122
+ if (info !== undefined)
123
+ await terminate(info, options, defaultEnsureTiming);
114
124
  }
115
125
  function fallback() {
116
126
  return join(process.env["XDG_STATE_HOME"] ?? join(homedir(), ".local", "state"), "opencode", "service.json");
@@ -134,9 +144,6 @@ async function read(file) {
134
144
  return undefined;
135
145
  }
136
146
  }
137
- async function probe(info, allowLegacy = false) {
138
- return (await probeResult(info, allowLegacy)).service;
139
- }
140
147
  async function probeResult(info, allowLegacy = false, timeout = defaultEnsureTiming.requestTimeout) {
141
148
  const endpoint = {
142
149
  url: info.url,
@@ -187,9 +194,6 @@ async function registered(file, allowLegacy = false, timeout) {
187
194
  return { info: undefined, service: undefined, timedOut: false };
188
195
  return { info, ...(await probeResult(info, allowLegacy, timeout)) };
189
196
  }
190
- async function find(options) {
191
- return (await registered(options.file, true)).service;
192
- }
193
197
  function signal(pid, name) {
194
198
  try {
195
199
  process.kill(pid, name);
@@ -217,54 +221,23 @@ async function waitUntilStopped(pid, timing) {
217
221
  function same(left, right) {
218
222
  return left.id === right.id && left.version === right.version && left.url === right.url && left.pid === right.pid;
219
223
  }
220
- async function evict(info, options, timing) {
224
+ async function terminate(info, options, timing) {
221
225
  const current = await read(options.file);
222
226
  if (current === undefined || !same(current, info))
223
227
  return;
224
228
  signal(info.pid, "SIGTERM");
225
- if (await waitUntilStopped(info.pid, timing))
226
- return;
227
- const latest = await read(options.file);
228
- if (latest === undefined || !same(latest, info))
229
- return;
230
- signal(info.pid, "SIGKILL");
231
- if (!(await waitUntilStopped(info.pid, timing)))
232
- throw new Error(`Server process ${info.pid} is still running`);
233
- }
234
- async function kill(service, options, timing) {
235
- const requested = await requestStop(service, timing.requestTimeout);
236
- if (requested === "rejected")
237
- return;
238
- if (requested === "unsupported") {
239
- const current = await find(options);
240
- if (current === undefined || !same(current.info, service.info))
229
+ if (!(await waitUntilStopped(info.pid, timing))) {
230
+ const latest = await read(options.file);
231
+ if (latest === undefined || !same(latest, info))
241
232
  return;
242
- signal(service.info.pid, "SIGTERM");
233
+ signal(info.pid, "SIGKILL");
234
+ if (!(await waitUntilStopped(info.pid, timing)))
235
+ throw new Error(`Server process ${info.pid} is still running`);
243
236
  }
244
- if (await waitUntilStopped(service.info.pid, timing))
245
- return;
246
- const latest = await find(options);
247
- if (latest === undefined || !same(latest.info, service.info))
237
+ const latest = await read(options.file);
238
+ if (latest === undefined || !same(latest, info))
248
239
  return;
249
- signal(service.info.pid, "SIGKILL");
250
- if (!(await waitUntilStopped(service.info.pid, timing)))
251
- throw new Error(`Server process ${service.info.pid} is still running`);
252
- }
253
- async function requestStop(service, timeout = defaultEnsureTiming.requestTimeout) {
254
- if (service.info.id === undefined || service.legacy)
255
- return "unsupported";
256
- const response = await fetch(new URL("/api/service/stop", service.info.url), {
257
- method: "POST",
258
- headers: { ...headers(service.endpoint), "content-type": "application/json" },
259
- body: JSON.stringify({ instanceID: service.info.id }),
260
- signal: AbortSignal.timeout(timeout),
261
- }).catch(() => undefined);
262
- if (response === undefined || response.status === 404 || response.status === 405)
263
- return "unsupported";
264
- const body = (await response.json().catch(() => undefined));
265
- if (!response.ok || body?.accepted !== true)
266
- return "rejected";
267
- return "accepted";
240
+ await rm(options.file ?? fallback(), { force: true });
268
241
  }
269
242
  function delay(milliseconds) {
270
243
  return new Promise((resolve) => setTimeout(resolve, milliseconds));
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "import": "./client/index.js"
15
15
  }
16
16
  },
17
- "version": "2.0.0-alpha-15",
17
+ "version": "2.0.0-alpha-17",
18
18
  "license": "MIT",
19
19
  "repository": {
20
20
  "type": "git",
@@ -30,17 +30,17 @@
30
30
  "x64"
31
31
  ],
32
32
  "optionalDependencies": {
33
- "shuvcode-darwin-arm64": "2.0.0-alpha-15",
34
- "shuvcode-linux-x64-baseline": "2.0.0-alpha-15",
35
- "shuvcode-linux-arm64": "2.0.0-alpha-15",
36
- "shuvcode-linux-x64-musl": "2.0.0-alpha-15",
37
- "shuvcode-darwin-x64-baseline": "2.0.0-alpha-15",
38
- "shuvcode-windows-arm64": "2.0.0-alpha-15",
39
- "shuvcode-windows-x64": "2.0.0-alpha-15",
40
- "shuvcode-linux-x64-baseline-musl": "2.0.0-alpha-15",
41
- "shuvcode-linux-x64": "2.0.0-alpha-15",
42
- "shuvcode-darwin-x64": "2.0.0-alpha-15",
43
- "shuvcode-windows-x64-baseline": "2.0.0-alpha-15",
44
- "shuvcode-linux-arm64-musl": "2.0.0-alpha-15"
33
+ "shuvcode-linux-x64-baseline": "2.0.0-alpha-17",
34
+ "shuvcode-windows-x64-baseline": "2.0.0-alpha-17",
35
+ "shuvcode-linux-x64": "2.0.0-alpha-17",
36
+ "shuvcode-linux-x64-baseline-musl": "2.0.0-alpha-17",
37
+ "shuvcode-linux-arm64-musl": "2.0.0-alpha-17",
38
+ "shuvcode-linux-arm64": "2.0.0-alpha-17",
39
+ "shuvcode-darwin-x64": "2.0.0-alpha-17",
40
+ "shuvcode-darwin-arm64": "2.0.0-alpha-17",
41
+ "shuvcode-windows-arm64": "2.0.0-alpha-17",
42
+ "shuvcode-darwin-x64-baseline": "2.0.0-alpha-17",
43
+ "shuvcode-windows-x64": "2.0.0-alpha-17",
44
+ "shuvcode-linux-x64-musl": "2.0.0-alpha-17"
45
45
  }
46
46
  }