shuvcode 2.0.0-alpha-19 → 2.0.3-shuv.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/api.d.ts +4 -6
- package/client/client.d.ts +253 -0
- package/client/client.js +13 -0
- package/client/generated/client.d.ts +17 -22
- package/client/generated/client.js +226 -244
- package/client/generated/types.d.ts +832 -1329
- package/client/generated/types.js +10 -4
- package/client/index.d.ts +4 -2
- package/client/index.js +7 -7
- package/client/rpc.d.ts +32 -0
- package/client/rpc.js +86 -0
- package/client/service.js +50 -33
- package/package.json +13 -13
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
export const isUnauthorizedError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "UnauthorizedError";
|
|
2
1
|
export const isInvalidRequestError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "InvalidRequestError";
|
|
2
|
+
export const isUnauthorizedError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "UnauthorizedError";
|
|
3
3
|
export const isAgentNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "AgentNotFoundError";
|
|
4
|
+
export const isServiceUnavailableError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ServiceUnavailableError";
|
|
4
5
|
export const isInvalidCursorError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "InvalidCursorError";
|
|
5
|
-
export const isConflictError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ConflictError";
|
|
6
6
|
export const isSessionNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "SessionNotFoundError";
|
|
7
|
+
export const isConflictError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ConflictError";
|
|
7
8
|
export const isUnknownError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "UnknownError";
|
|
8
9
|
export const isMessageNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "MessageNotFoundError";
|
|
9
10
|
export const isCommandNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "CommandNotFoundError";
|
|
10
11
|
export const isCommandExecutionError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "CommandExecutionError";
|
|
11
12
|
export const isSkillNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "SkillNotFoundError";
|
|
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";
|
|
14
14
|
export const isInstructionEntryValueTooLargeError = (value) => typeof value === "object" &&
|
|
15
15
|
value !== null &&
|
|
16
16
|
"_tag" in value &&
|
|
17
17
|
value["_tag"] === "InstructionEntryValueTooLargeError";
|
|
18
18
|
export const isProviderNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ProviderNotFoundError";
|
|
19
|
+
export const isIntegrationNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "IntegrationNotFoundError";
|
|
20
|
+
export const isIntegrationAttemptNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "IntegrationAttemptNotFoundError";
|
|
21
|
+
export const isIntegrationMethodNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "IntegrationMethodNotFoundError";
|
|
19
22
|
export const isMcpServerNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "McpServerNotFoundError";
|
|
20
23
|
export const isProjectNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ProjectNotFoundError";
|
|
21
24
|
export const isFormNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "FormNotFoundError";
|
|
22
|
-
export const isFormAlreadySettledError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "FormAlreadySettledError";
|
|
23
25
|
export const isFormInvalidAnswerError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "FormInvalidAnswerError";
|
|
26
|
+
export const isFormAlreadySettledError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "FormAlreadySettledError";
|
|
24
27
|
export const isPermissionNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "PermissionNotFoundError";
|
|
28
|
+
export const isFileNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "FileNotFoundError";
|
|
29
|
+
export const isRpcError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "RpcError";
|
|
30
|
+
export const isRpcInternalError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "RpcInternalError";
|
|
25
31
|
export const isPtyNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "PtyNotFoundError";
|
|
26
32
|
export const isForbiddenError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ForbiddenError";
|
|
27
33
|
export const isShellNotFoundError = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ShellNotFoundError";
|
package/client/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { OpenCode } from "./client.js";
|
|
1
2
|
export * from "./generated/index.js";
|
|
2
|
-
export
|
|
3
|
+
export { OpenCode } from "./client.js";
|
|
4
|
+
export type { AgentApi, CommandApi, ConfigApi, EventApi, IntegrationApi, ModelApi, PluginApi, ProviderApi, ReferenceApi, RpcApi, RpcCallOptions, RpcClient, RpcEventPayload, WebSearchApi, SessionApi, SkillApi, } from "./api.js";
|
|
3
5
|
export type { EventSubscribeOutput as OpenCodeEvent } from "./generated/types.js";
|
|
4
|
-
export type OpenCodeClient = ReturnType<typeof
|
|
6
|
+
export type OpenCodeClient = ReturnType<typeof OpenCode.make>;
|
package/client/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
1
|
+
var A=Object.defineProperty;var q=(t)=>t;function E(t,a){this[t]=q.bind(null,a)}var w=(t,a)=>{for(var i in a)A(t,i,{get:a[i],enumerable:!0,configurable:!0,set:E.bind(a,i)})};class g extends Error{reason;name="ClientError";constructor(t,a){super(t,a);this.reason=t}}var L=16777216;function F(t){let a=t.fetch??globalThis.fetch,i=(e,n)=>{let o=new URL(e.path,t.baseUrl);for(let[c,d]of Object.entries(e.query??{}))h(o.searchParams,c,d);let s=new Headers(t.headers);for(let[c,d]of Object.entries(e.headers??{}))if(d!==void 0&&d!==null)s.set(c,String(d));for(let[c,d]of new Headers(n?.headers))s.set(c,d);if(e.body!==void 0&&!s.has("content-type"))s.set("content-type","application/json");return{url:o,init:{method:e.method,signal:n?.signal,headers:s,body:e.body===void 0?void 0:JSON.stringify(e.body)}}},p=async(e,n)=>{try{let o=i(e,n);return await a(o.url,o.init)}catch(o){throw new g("Transport",{cause:o})}},u=async(e,n)=>{if(n.declaredStatuses.includes(e.status))throw await R(e);try{await e.body?.cancel()}catch{}throw new g("UnexpectedStatus",{cause:{status:e.status}})},r=async(e,n)=>{let o=await p(e,n);if(o.status!==e.successStatus)return u(o,e);if(e.binary)return new Uint8Array(await o.arrayBuffer());if(e.empty){try{await o.body?.cancel()}catch{}return}return await R(o)},l=(e,n)=>({async*[Symbol.asyncIterator](){let o=await p(e,n);if(o.status!==e.successStatus)await u(o,e);if(!D(o,"text/event-stream")){try{await o.body?.cancel()}catch{}throw new g("UnsupportedContentType")}if(o.body===null)throw new g("MalformedResponse");let s=o.body.getReader(),c=new TextDecoder,d="";try{while(!0){let m;try{m=await s.read()}catch(I){throw new g("Transport",{cause:I})}if(!m.done)n?.onActivity?.();if(d+=c.decode(m.value,{stream:!m.done}),d.length>L)throw new g("SseEventTooLarge");let f=!m.done&&d.endsWith("\r");if(f)d=d.slice(0,-1);if(d=d.replaceAll(`\r
|
|
2
2
|
`,`
|
|
3
3
|
`).replaceAll("\r",`
|
|
4
|
-
`),f)
|
|
4
|
+
`),f)d+="\r";if(m.done&&d!=="")d+=`
|
|
5
5
|
|
|
6
|
-
`;let
|
|
6
|
+
`;let y=d.indexOf(`
|
|
7
7
|
|
|
8
|
-
`);while(
|
|
9
|
-
`).flatMap((
|
|
10
|
-
`);if(
|
|
8
|
+
`);while(y>=0){let I=d.slice(0,y);d=d.slice(y+2);let b=I.split(`
|
|
9
|
+
`).flatMap((x)=>x.startsWith("data:")?[x.slice(5).trimStart()]:[]).join(`
|
|
10
|
+
`);if(b!=="")try{yield JSON.parse(b)}catch(x){throw new g("MalformedResponse",{cause:x})}y=d.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)},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};
|
|
12
|
+
`)}if(m.done)return}}finally{try{await s.cancel()}catch{}s.releaseLock()}}});return{server:{status:(e)=>r({method:"GET",path:"/api/status",successStatus:200,declaredStatuses:[400,401],empty:!1},e)},location:{get:(e,n)=>r({method:"GET",path:"/api/location",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401],empty:!1},n)},agent:{list:(e,n)=>r({method:"GET",path:"/api/agent",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/agent/${encodeURIComponent(e.agentID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},plugin:{list:(e,n)=>r({method:"GET",path:"/api/plugin",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401],empty:!1},n),check:(e,n)=>r({method:"POST",path:"/api/plugin/check",query:{location:e?.location},body:{target:e?.target},successStatus:200,declaredStatuses:[400,401],empty:!1},n),update:(e,n)=>r({method:"POST",path:"/api/plugin/update",query:{location:e.location},body:{targets:e.targets},successStatus:204,declaredStatuses:[400,401,503],empty:!0},n)},session:{list:(e,n)=>r({method:"GET",path:"/api/session",query:{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/experimental/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,metadata:e?.metadata,permissions:e?.permissions},successStatus:200,declaredStatuses:[400,401],empty:!1},n).then((o)=>o.data),import:(e,n)=>r({method:"POST",path:"/api/experimental/session/import",body:{info:e.info,messages:e.messages,location:e.location},successStatus:200,declaredStatuses:[400,401,404,409],empty:!1},n).then((o)=>o.data),export:(e,n)=>r({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/export`,query:{sanitize:e.sanitize},successStatus:200,declaredStatuses:[400,401,404,500],empty:!1},n).then((o)=>o.data),active:(e)=>r({method:"GET",path:"/api/session/active",successStatus:200,declaredStatuses:[400,401],empty:!1},e).then((n)=>n.data),get:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),remove:(e,n)=>r({method:"DELETE",path:`/api/session/${encodeURIComponent(e.sessionID)}`,successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),fork:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/fork`,body:{before:e.before},successStatus:200,declaredStatuses:[400,401,404],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:[400,401,404],empty:!0},n),switchModel:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/model`,body:{model:e.model},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),rename:(e,n)=>r({method:"PATCH",path:`/api/session/${encodeURIComponent(e.sessionID)}`,body:{title:e.title},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),move:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/move`,body:{directory:e.directory,delivery:e.delivery},successStatus:204,declaredStatuses:[400,401,404],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:[400,401,404,409],empty:!1},n).then((o)=>o.data),command:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/command`,body:{name:e.name,text:e.text,files:e.files,agents:e.agents,skills:e.skills,delivery:e.delivery},successStatus:204,declaredStatuses:[400,401,404,500],empty:!0},n),skill:(e,n)=>r({method:"POST",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/skill`,body:{id:e.id,resume:e.resume},successStatus:204,declaredStatuses:[400,401,404],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:[400,401,404,409],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:[400,401,404],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:[400,401,404,409],empty:!1},n).then((o)=>o.data),wait:(e,n)=>r({method:"POST",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/wait`,successStatus:204,declaredStatuses:[400,401,404,503],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:[400,401,404,409,500],empty:!1},n).then((o)=>o.data),clear:(e,n)=>r({method:"DELETE",path:`/api/session/${encodeURIComponent(e.sessionID)}/revert`,successStatus:204,declaredStatuses:[400,401,404,409,500],empty:!0},n),commit:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/revert/commit`,successStatus:204,declaredStatuses:[400,401,404,409],empty:!0},n)},context:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/context`,successStatus:200,declaredStatuses:[400,401,404,500],empty:!1},n).then((o)=>o.data),diff:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/diff`,query:{from:e.from,to:e.to,context:e.context},successStatus:200,declaredStatuses:[400,401,404,500],empty:!1},n).then((o)=>o.data),inbox:{list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox`,successStatus:200,declaredStatuses:[400,401,404],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:[400,401,404,409],empty:!0},n),steer:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox/${encodeURIComponent(e.inboxID)}/steer`,successStatus:204,declaredStatuses:[400,401,404,409],empty:!0},n),queue:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox/${encodeURIComponent(e.inboxID)}/queue`,successStatus:204,declaredStatuses:[400,401,404,409],empty:!0},n)},instructions:{entry:{list:(e,n)=>r({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/instructions/entries`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),put:(e,n)=>r({method:"PUT",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/instructions/entries/${encodeURIComponent(e.key)}`,body:{value:e.value},successStatus:204,declaredStatuses:[400,401,404,413],empty:!0},n),remove:(e,n)=>r({method:"DELETE",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/instructions/entries/${encodeURIComponent(e.key)}`,successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)}},generate:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/generate`,body:{prompt:e.prompt},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n).then((o)=>o.data),log:(e,n)=>l({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/log`,query:{after:e.after,follow:e.follow},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),interrupt:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/interrupt`,query:{resume:e.resume},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),background:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/background`,successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),message:{get:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/message/${encodeURIComponent(e.messageID)}`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data)},environment:(e,n)=>r({method:"PUT",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/environment`,body:{variables:e.variables},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),view:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/view`,body:{idle:e.idle},successStatus:204,declaredStatuses:[400,401,404],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,type:e.type},successStatus:200,declaredStatuses:[400,401,404,500],empty:!1},n)},model:{list:(e,n)=>r({method:"GET",path:"/api/model",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,503],empty:!1},n),default:(e,n)=>r({method:"GET",path:"/api/model/default",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,503],empty:!1},n)},generate:{text:(e,n)=>r({method:"POST",path:"/api/generate",body:{prompt:e.prompt,model:e.model},successStatus:200,declaredStatuses:[400,401,503],empty:!1},n).then((o)=>o.data)},provider:{list:(e,n)=>r({method:"GET",path:"/api/provider",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,503],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/provider/${encodeURIComponent(e.providerID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n)},integration:{list:(e,n)=>r({method:"GET",path:"/api/integration",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/integration/${encodeURIComponent(e.integrationID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],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,404],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:[400,401,404],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,404],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:[400,401],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,404],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:[400,401,404],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:[400,401],empty:!0},n)}},mcp:{list:(e,n)=>r({method:"GET",path:"/api/mcp",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401],empty:!1},n),add:(e,n)=>r({method:"PUT",path:`/api/experimental/mcp/${encodeURIComponent(e.server)}`,query:{location:e.location},body:{config:e.config},successStatus:204,declaredStatuses:[400,401],empty:!0},n),remove:(e,n)=>r({method:"DELETE",path:`/api/experimental/mcp/${encodeURIComponent(e.server)}`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),connect:(e,n)=>r({method:"POST",path:`/api/experimental/mcp/${encodeURIComponent(e.server)}/connect`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),disconnect:(e,n)=>r({method:"POST",path:`/api/experimental/mcp/${encodeURIComponent(e.server)}/disconnect`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),resource:{catalog:(e,n)=>r({method:"GET",path:"/api/mcp/resource",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401],empty:!1},n)}},credential:{update:(e,n)=>r({method:"PATCH",path:`/api/credential/${encodeURIComponent(e.credentialID)}`,body:{label:e.label},successStatus:204,declaredStatuses:[400,401],empty:!0},n),activate:(e,n)=>r({method:"POST",path:`/api/credential/${encodeURIComponent(e.credentialID)}/activate`,successStatus:204,declaredStatuses:[400,401],empty:!0},n),remove:(e,n)=>r({method:"DELETE",path:`/api/credential/${encodeURIComponent(e.credentialID)}`,successStatus:204,declaredStatuses:[400,401],empty:!0},n)},project:{list:(e)=>r({method:"GET",path:"/api/project",successStatus:200,declaredStatuses:[400,401],empty:!1},e),update:(e,n)=>r({method:"PATCH",path:`/api/project/${encodeURIComponent(e.projectID)}`,body:{canonical:e.canonical,name:e.name,icon:e.icon,commands:e.commands},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},form:{request:{list:(e,n)=>r({method:"GET",path:"/api/form/request",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401],empty:!1},n)},list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/form`,successStatus:200,declaredStatuses:[400,401,404],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:[400,401,404,409],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:[400,401,404],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:[400,401,404],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:[400,401,404,409],empty:!0},n),cancel:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/form/${encodeURIComponent(e.formID)}/cancel`,successStatus:204,declaredStatuses:[400,401,404,409],empty:!0},n)},permission:{request:{list:(e,n)=>r({method:"GET",path:"/api/permission/request",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401],empty:!1},n)},saved:{list:(e,n)=>r({method:"GET",path:"/api/permission/saved",query:{projectID:e?.projectID},successStatus:200,declaredStatuses:[400,401],empty:!1},n).then((o)=>o.data),remove:(e,n)=>r({method:"DELETE",path:`/api/permission/saved/${encodeURIComponent(e.id)}`,successStatus:204,declaredStatuses:[400,401],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:[400,401,404],empty:!1},n).then((o)=>o.data),list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission`,successStatus:200,declaredStatuses:[400,401,404],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:[400,401,404],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:[400,401,404],empty:!0},n),rules:(e,n)=>r({method:"PUT",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission/rules`,body:{permissions:e.permissions},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},file:{read:(e,n)=>r({method:"GET",path:`/api/fs/read/${M(e.path)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],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:[400,401],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:[400,401],empty:!1},n)},command:{list:(e,n)=>r({method:"GET",path:"/api/command",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401],empty:!1},n)},skill:{list:(e,n)=>r({method:"GET",path:"/api/skill",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401],empty:!1},n)},rpc:{call:(e,n)=>r({method:"POST",path:`/api/rpc/${encodeURIComponent(e.rpcID)}/${encodeURIComponent(e.method)}`,query:{location:e.location},body:{input:e.input},successStatus:200,declaredStatuses:[400,401,500],empty:!1},n)},event:{subscribe:(e)=>l({method:"GET",path:"/api/event",successStatus:200,declaredStatuses:[400,401],empty:!1},e)},pty:{list:(e,n)=>r({method:"GET",path:"/api/pty",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401],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:[400,401],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/pty/${encodeURIComponent(e.ptyID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],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:[400,401,404],empty:!1},n),remove:(e,n)=>r({method:"DELETE",path:`/api/pty/${encodeURIComponent(e.ptyID)}`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],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:[400,401,403,404],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:[400,401,503],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,401,503],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,401,503],empty:!1},n).then((o)=>o.data),shutdown:(e)=>r({method:"POST",path:"/api/experimental/persistent-pty/shutdown",successStatus:204,declaredStatuses:[400,401,503],empty:!0},e),handoff:(e)=>r({method:"POST",path:"/api/experimental/persistent-pty/handoff",successStatus:200,declaredStatuses:[400,401,503],empty:!1},e),get:(e,n)=>r({method:"GET",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}`,successStatus:200,declaredStatuses:[400,401,404,503],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:[400,401,404,503],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:[400,401,404,503],empty:!1},n).then((o)=>o.data),remove:(e,n)=>r({method:"DELETE",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}`,successStatus:204,declaredStatuses:[400,401,404,503],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:[400,401,403,404,503],empty:!1},n).then((o)=>o.data)}},shell:{list:(e,n)=>r({method:"GET",path:"/api/shell",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401],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:[400,401],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/shell/${encodeURIComponent(e.id)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],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:[400,401,404],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:[400,401,404],empty:!1},n),remove:(e,n)=>r({method:"DELETE",path:`/api/shell/${encodeURIComponent(e.id)}`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},reference:{list:(e,n)=>r({method:"GET",path:"/api/reference",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401],empty:!1},n)},worktree:{list:(e,n)=>r({method:"GET",path:"/api/worktree",query:{projectID:e.projectID},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),create:(e,n)=>r({method:"POST",path:"/api/worktree",body:{projectID:e.projectID,from:e.from,branch:e.branch,directory:e.directory,name:e.name},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),remove:(e,n)=>r({method:"DELETE",path:"/api/worktree",body:{projectID:e.projectID,directory:e.directory,force:e.force},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),refresh:(e,n)=>r({method:"POST",path:"/api/worktree/refresh",body:{projectID:e.projectID},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},vcs:{get:(e,n)=>r({method:"GET",path:"/api/vcs",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401],empty:!1},n),base:(e,n)=>r({method:"GET",path:"/api/vcs/base",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,503],empty:!1},n),status:(e,n)=>r({method:"GET",path:"/api/vcs/status",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401],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:[400,401],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:[400,401,503],empty:!1},n)},debug:{location:{list:(e)=>r({method:"GET",path:"/api/debug/location",successStatus:200,declaredStatuses:[400,401],empty:!1},e),evict:(e,n)=>r({method:"DELETE",path:"/api/debug/location",query:{location:e?.location},successStatus:204,declaredStatuses:[400,401],empty:!0},n)}},migration:{v1:{status:(e)=>r({method:"GET",path:"/api/experimental/migration/v1",successStatus:200,declaredStatuses:[400,401],empty:!1},e)}},websearch:{providers:(e,n)=>r({method:"GET",path:"/api/websearch/provider",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,503],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,401,503],empty:!1},n)},config:{get:(e,n)=>r({method:"GET",path:"/api/config",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401],empty:!1},n),shells:(e)=>r({method:"GET",path:"/api/config/shell",successStatus:200,declaredStatuses:[400,401],empty:!1},e),update:(e,n)=>r({method:"PATCH",path:"/api/experimental/config",body:{shell:e.shell},successStatus:204,declaredStatuses:[400,401],empty:!0},n)}}}function M(t){return t.split("/").map(encodeURIComponent).join("/")}function h(t,a,i){if(i===void 0)return;if(i===null){t.append(a,"null");return}if(Array.isArray(i)){for(let p of i)h(t,a,p);return}if(typeof i==="object"){for(let[p,u]of Object.entries(i))h(t,`${a}[${p}]`,u);return}t.append(a,String(i))}async function R(t){if(!D(t,"application/json")&&!t.headers.get("content-type")?.includes("+json")){try{await t.body?.cancel()}catch{}throw new g("UnsupportedContentType")}let a;try{a=await t.text()}catch(i){throw new g("Transport",{cause:i})}if(a==="")throw new g("MalformedResponse");try{return JSON.parse(a)}catch(i){throw new g("MalformedResponse",{cause:i})}}function D(t,a){return t.headers.get("content-type")?.split(";",1)[0]?.trim().toLowerCase()===a}var G=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="InvalidRequestError",_=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="UnauthorizedError",W=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="AgentNotFoundError",z=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ServiceUnavailableError",B=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="InvalidCursorError",K=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="SessionNotFoundError",Q=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ConflictError",H=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="UnknownError",X=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="MessageNotFoundError",Y=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="CommandNotFoundError",Z=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="CommandExecutionError",ee=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="SkillNotFoundError",ne=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="SessionBusyError",te=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="InstructionEntryValueTooLargeError",re=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ProviderNotFoundError",oe=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="IntegrationNotFoundError",ae=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="IntegrationAttemptNotFoundError",se=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="IntegrationMethodNotFoundError",ie=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="McpServerNotFoundError",de=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ProjectNotFoundError",le=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FormNotFoundError",ye=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FormInvalidAnswerError",ue=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FormAlreadySettledError",pe=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="PermissionNotFoundError",ge=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FileNotFoundError",O=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="RpcError",P=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="RpcInternalError",ce=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="PtyNotFoundError",me=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ForbiddenError",Ie=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ShellNotFoundError",be=(t)=>typeof t==="object"&&t!==null&&("name"in t)&&t.name==="WorktreeError";var S={};w(S,{OpenCode:()=>S,make:()=>U});function T(t){let a,i=4096;function p(r){if(r.connected=void 0,r.controller.abort(),a===r)a=void 0}async function u(r){let l,e={};try{if(r.controller.signal.aborted)return;l=t(r.controller.signal,()=>{r.subscribers.forEach((n)=>n.activity?.())})[Symbol.asyncIterator]();while(!r.controller.signal.aborted){let n=await l.next();if(n.done||r.controller.signal.aborted)break;if(n.value.type==="server.connected")r.connected=n.value;r.subscribers.forEach((o)=>o.push(n.value))}}catch(n){e={error:n}}finally{p(r);try{await l?.return?.()}catch(n){if(!("error"in e))e={error:n}}r.subscribers.forEach((n)=>n.finish(e))}}return{subscribe(r){return{[Symbol.asyncIterator](){let l=[],e=[],n=!1,o,s;function c(y,I=!0){if(o=y,I)e.length=0;if(r?.signal?.removeEventListener("abort",d),s?.subscribers.delete(m)&&!s.subscribers.size)p(s);l.splice(0).forEach((b)=>{if("error"in y)b.reject(y.error);else b.resolve({done:!0,value:void 0})})}function d(){c({})}let m={activity:r?.onActivity,finish(y){c(y,!1)},push(y){if(o)return;let I=l.shift();if(I){I.resolve({done:!1,value:y});return}if(e.length===4096){c({error:Error("Event subscriber exceeded its 4096-event capacity")});return}e.push(y)}};function f(){if(o)return;let y=!a;if(s=a??{controller:new AbortController,subscribers:new Set},a=s,s.subscribers.add(m),s.connected)m.push(s.connected);if(y)u(s)}return{next(){let y=e.shift();if(y)return Promise.resolve({done:!1,value:y});if(o){if("error"in o)return Promise.reject(o.error);return Promise.resolve({done:!0,value:void 0})}if(r?.signal?.aborted)return d(),Promise.resolve({done:!0,value:void 0});let I=Promise.withResolvers();if(l.push(I),!n)n=!0,r?.signal?.addEventListener("abort",d,{once:!0}),f();return I.promise},return(){return c({}),Promise.resolve({done:!0,value:void 0})}}}}}}}function k(t,a){return(i)=>{let p=(u,r)=>{if(!Object.hasOwn(i.events,u))throw Error(`Unknown RPC event: ${i.id}.${u}`);let l=N(i,u);return{[Symbol.asyncIterator](){let e=new AbortController,n=r?.signal?AbortSignal.any([e.signal,r.signal]):e.signal,o=async function*(){try{for await(let s of a.subscribe({signal:n})){if(n.aborted)return;if(s.type!==l)continue;yield s}}catch(s){if(!n.aborted)throw s}finally{e.abort()}}();return{next:()=>o.next(),return:()=>(e.abort(),o.return())}}}};return Object.assign(Object.fromEntries(Object.keys(i.methods).map((u)=>[u,async(r,l)=>{try{return(await t.rpc.call({rpcID:i.id,method:u,input:r,location:l?.location},{signal:l?.signal,headers:l?.headers})).output}catch(e){if(!O(e)&&!P(e))throw e;throw e.data===void 0?{type:e.type,message:e.message}:{type:e.type,message:e.message,data:e.data}}}])),{events:{subscribe:p,on:(u,r,l)=>{let e=new AbortController,n=l?.signal?AbortSignal.any([e.signal,l.signal]):e.signal,o=p(u,{signal:n});return(async()=>{for await(let s of o)await r(s)})().catch((s)=>console.error(s)),()=>e.abort()}}})}}function N(t,a){return`rpc.${t.id}.${a}`}function U(t){let a=F(t),i=T((p,u)=>a.event.subscribe({signal:p,onActivity:u}));return{...a,rpc:Object.assign(k(a,i),a.rpc),event:i}}export{g as ClientError,S as OpenCode,W as isAgentNotFoundError,Z as isCommandExecutionError,Y as isCommandNotFoundError,Q as isConflictError,ge as isFileNotFoundError,me as isForbiddenError,ue as isFormAlreadySettledError,ye as isFormInvalidAnswerError,le as isFormNotFoundError,te as isInstructionEntryValueTooLargeError,ae as isIntegrationAttemptNotFoundError,se as isIntegrationMethodNotFoundError,oe as isIntegrationNotFoundError,B as isInvalidCursorError,G as isInvalidRequestError,ie as isMcpServerNotFoundError,X as isMessageNotFoundError,pe as isPermissionNotFoundError,de as isProjectNotFoundError,re as isProviderNotFoundError,ce as isPtyNotFoundError,O as isRpcError,P as isRpcInternalError,z as isServiceUnavailableError,ne as isSessionBusyError,K as isSessionNotFoundError,Ie as isShellNotFoundError,ee as isSkillNotFoundError,_ as isUnauthorizedError,H as isUnknownError,be as isWorktreeError};
|
package/client/rpc.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Rpc } from "@opencode/schema/rpc";
|
|
2
|
+
import type { make, RequestOptions } from "./generated/client.js";
|
|
3
|
+
import type { EventSubscribeOutput, LocationGetInput } from "./generated/types.js";
|
|
4
|
+
type RpcEvent = Extract<EventSubscribeOutput, {
|
|
5
|
+
type: `rpc.${string}`;
|
|
6
|
+
}>;
|
|
7
|
+
export interface RpcCallOptions extends RequestOptions {
|
|
8
|
+
readonly location?: LocationGetInput["location"];
|
|
9
|
+
}
|
|
10
|
+
export type RpcArguments<Input, Options> = unknown extends Input ? [input: Input, options?: Options] : undefined extends Input ? [input?: Input, options?: Options] : [input: Input, options?: Options];
|
|
11
|
+
export type RpcClient<D extends Rpc.PortableDefinition, Options = RpcCallOptions> = {
|
|
12
|
+
readonly [Name in keyof D["methods"]]: (...args: RpcArguments<Rpc.Input<D["methods"][Name]["input"]>, Options>) => Promise<Rpc.Output<D["methods"][Name]["output"]>>;
|
|
13
|
+
} & {
|
|
14
|
+
readonly events: {
|
|
15
|
+
readonly subscribe: <Name extends keyof D["events"] & string>(name: Name, options?: Pick<RequestOptions, "signal">) => AsyncIterable<RpcEventPayload<D, Name>>;
|
|
16
|
+
readonly on: <Name extends keyof D["events"] & string>(name: Name, handler: (event: RpcEventPayload<D, Name>) => Promise<void> | void, options?: Pick<RequestOptions, "signal">) => () => void;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
type RpcEventPayloadFor<D extends Rpc.PortableDefinition, Name extends keyof D["events"] & string> = Omit<RpcEvent, "type" | "data"> & {
|
|
20
|
+
type: `rpc.${D["id"]}.${Name}`;
|
|
21
|
+
data: Rpc.EventData<D["events"][Name]["schema"]>;
|
|
22
|
+
};
|
|
23
|
+
export type RpcEventPayload<D extends Rpc.PortableDefinition, Name extends keyof D["events"] & string = keyof D["events"] & string> = {
|
|
24
|
+
[K in Name]: RpcEventPayloadFor<D, K>;
|
|
25
|
+
}[Name];
|
|
26
|
+
export interface RpcApi<Options = RpcCallOptions> {
|
|
27
|
+
<D extends Rpc.PortableDefinition>(definition: D): RpcClient<D, Options>;
|
|
28
|
+
}
|
|
29
|
+
export declare function makeRpc(raw: ReturnType<typeof make>, events: {
|
|
30
|
+
subscribe(options?: Pick<RequestOptions, "signal">): AsyncIterable<EventSubscribeOutput>;
|
|
31
|
+
}): RpcApi;
|
|
32
|
+
export {};
|
package/client/rpc.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { isRpcError, isRpcInternalError } from "./generated/types.js";
|
|
2
|
+
export function makeRpc(raw, events) {
|
|
3
|
+
return (definition) => {
|
|
4
|
+
const subscribe = (name, options) => {
|
|
5
|
+
if (!Object.hasOwn(definition.events, name))
|
|
6
|
+
throw new Error(`Unknown RPC event: ${definition.id}.${name}`);
|
|
7
|
+
const type = eventType(definition, name);
|
|
8
|
+
return {
|
|
9
|
+
[Symbol.asyncIterator]() {
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
const signal = options?.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
12
|
+
const iterator = (async function* () {
|
|
13
|
+
try {
|
|
14
|
+
for await (const published of events.subscribe({ signal })) {
|
|
15
|
+
if (signal.aborted)
|
|
16
|
+
return;
|
|
17
|
+
if (published.type !== type)
|
|
18
|
+
continue;
|
|
19
|
+
// SAFETY: The exact RPC type was selected above; Promise contracts require no client-side transform.
|
|
20
|
+
// oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion
|
|
21
|
+
yield published;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (!signal.aborted)
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
controller.abort();
|
|
30
|
+
}
|
|
31
|
+
})();
|
|
32
|
+
return {
|
|
33
|
+
next: () => iterator.next(),
|
|
34
|
+
return: () => {
|
|
35
|
+
// Interrupt a pending source read before closing the generator.
|
|
36
|
+
controller.abort();
|
|
37
|
+
return iterator.return();
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
// SAFETY: Every runtime key comes from this definition's method and event maps, which define RpcClient's mapped keys.
|
|
44
|
+
// oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion
|
|
45
|
+
return Object.assign(Object.fromEntries(Object.keys(definition.methods).map((name) => [
|
|
46
|
+
name,
|
|
47
|
+
async (input, options) => {
|
|
48
|
+
try {
|
|
49
|
+
const result = await raw.rpc.call({
|
|
50
|
+
rpcID: definition.id,
|
|
51
|
+
method: name,
|
|
52
|
+
// SAFETY: The method schema defines the accepted input; this assertion bridges it to the generic JSON transport.
|
|
53
|
+
// oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion
|
|
54
|
+
input: input,
|
|
55
|
+
location: options?.location,
|
|
56
|
+
}, { signal: options?.signal, headers: options?.headers });
|
|
57
|
+
return result.output;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (!isRpcError(error) && !isRpcInternalError(error))
|
|
61
|
+
throw error;
|
|
62
|
+
throw error.data === undefined
|
|
63
|
+
? { type: error.type, message: error.message }
|
|
64
|
+
: { type: error.type, message: error.message, data: error.data };
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
])), {
|
|
68
|
+
events: {
|
|
69
|
+
subscribe,
|
|
70
|
+
on: (name, handler, options) => {
|
|
71
|
+
const controller = new AbortController();
|
|
72
|
+
const signal = options?.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
73
|
+
const source = subscribe(name, { signal });
|
|
74
|
+
void (async () => {
|
|
75
|
+
for await (const event of source)
|
|
76
|
+
await handler(event);
|
|
77
|
+
})().catch((error) => console.error(error));
|
|
78
|
+
return () => controller.abort();
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function eventType(definition, name) {
|
|
85
|
+
return `rpc.${definition.id}.${name}`;
|
|
86
|
+
}
|
package/client/service.js
CHANGED
|
@@ -16,6 +16,8 @@ export async function discover(options = {}) {
|
|
|
16
16
|
const found = (await registered(options.file)).service;
|
|
17
17
|
if (found?.state !== "ready")
|
|
18
18
|
return undefined;
|
|
19
|
+
if (!found.compatible)
|
|
20
|
+
return undefined;
|
|
19
21
|
if (!matchesVersion(found.version, options))
|
|
20
22
|
return undefined;
|
|
21
23
|
return found.endpoint;
|
|
@@ -36,7 +38,7 @@ export async function ensure(options = {}) {
|
|
|
36
38
|
options.onStart?.(reason, previousVersion);
|
|
37
39
|
};
|
|
38
40
|
const spawnContender = async () => {
|
|
39
|
-
const [command, ...args] = options.command ?? ["
|
|
41
|
+
const [command, ...args] = options.command ?? ["shuvcode", "serve", "--service"];
|
|
40
42
|
if (command === undefined)
|
|
41
43
|
throw new Error("Missing service command");
|
|
42
44
|
try {
|
|
@@ -50,7 +52,7 @@ export async function ensure(options = {}) {
|
|
|
50
52
|
while (true) {
|
|
51
53
|
if (Date.now() >= deadline)
|
|
52
54
|
throw new Error("Timed out waiting for the background service to start");
|
|
53
|
-
const registration = await registered(options.file,
|
|
55
|
+
const registration = await registered(options.file, timing.requestTimeout);
|
|
54
56
|
if (registration.timedOut && registration.info !== undefined) {
|
|
55
57
|
timeouts = {
|
|
56
58
|
info: registration.info,
|
|
@@ -70,7 +72,7 @@ export async function ensure(options = {}) {
|
|
|
70
72
|
if (registration.service !== undefined) {
|
|
71
73
|
spawnDelay = timing.spawnDelay;
|
|
72
74
|
const service = registration.service;
|
|
73
|
-
const compatible =
|
|
75
|
+
const compatible = service.compatible && matchesVersion(service.version, options);
|
|
74
76
|
if (compatible && service.state === "ready") {
|
|
75
77
|
await PtyHandoff.complete(options.file ?? fallback(), service.info);
|
|
76
78
|
return service.endpoint;
|
|
@@ -79,14 +81,12 @@ export async function ensure(options = {}) {
|
|
|
79
81
|
throw new Error("Background service failed to start");
|
|
80
82
|
if (!compatible) {
|
|
81
83
|
announce("version-mismatch", service.version);
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
await terminate(service.info, options, timing).catch(() => undefined);
|
|
84
|
+
if (service.state !== "ready")
|
|
85
|
+
console.warn("Background service is not ready; replacement cannot preserve persistent terminals");
|
|
86
|
+
await stop({
|
|
87
|
+
file: options.file,
|
|
88
|
+
pty: service.state === "ready" ? "handoff" : "clear",
|
|
89
|
+
}).catch(() => undefined);
|
|
90
90
|
lastSpawn = 0;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
@@ -117,13 +117,16 @@ export async function ensure(options = {}) {
|
|
|
117
117
|
}
|
|
118
118
|
/** Stop the registered local service. */
|
|
119
119
|
export async function stop(options = {}) {
|
|
120
|
-
await PtyHandoff.clear(options.file ?? fallback());
|
|
121
120
|
const info = await read(options.file);
|
|
121
|
+
if (options.pty === "handoff" && info !== undefined)
|
|
122
|
+
await PtyHandoff.prepare(options.file ?? fallback(), info, defaultEnsureTiming.requestTimeout);
|
|
123
|
+
else
|
|
124
|
+
await PtyHandoff.clear(options.file ?? fallback());
|
|
122
125
|
if (info !== undefined)
|
|
123
126
|
await terminate(info, options, defaultEnsureTiming);
|
|
124
127
|
}
|
|
125
128
|
function fallback() {
|
|
126
|
-
return join(process.env["XDG_STATE_HOME"] ?? join(homedir(), ".local", "state"), "
|
|
129
|
+
return join(process.env["XDG_STATE_HOME"] ?? join(homedir(), ".local", "state"), "shuvcode", "service.json");
|
|
127
130
|
}
|
|
128
131
|
/** Create HTTP authentication headers for a service endpoint. */
|
|
129
132
|
export function headers(endpoint) {
|
|
@@ -144,7 +147,7 @@ async function read(file) {
|
|
|
144
147
|
return undefined;
|
|
145
148
|
}
|
|
146
149
|
}
|
|
147
|
-
async function probeResult(info,
|
|
150
|
+
async function probeResult(info, timeout = defaultEnsureTiming.requestTimeout) {
|
|
148
151
|
const endpoint = {
|
|
149
152
|
url: info.url,
|
|
150
153
|
auth: info.password === undefined
|
|
@@ -152,47 +155,61 @@ async function probeResult(info, allowLegacy = false, timeout = defaultEnsureTim
|
|
|
152
155
|
: { type: "basic", username: "opencode", password: info.password },
|
|
153
156
|
};
|
|
154
157
|
const signal = AbortSignal.timeout(timeout);
|
|
155
|
-
const result = await fetch(new URL("/api/
|
|
156
|
-
headers: headers(endpoint),
|
|
157
|
-
signal,
|
|
158
|
-
})
|
|
158
|
+
const result = await fetch(new URL("/api/status", info.url), { headers: headers(endpoint), signal })
|
|
159
159
|
.then(async (response) => ({
|
|
160
160
|
response,
|
|
161
|
-
body: (await response.json()),
|
|
161
|
+
body: response.status === 404 ? undefined : (await response.json()),
|
|
162
162
|
}))
|
|
163
163
|
.then((value) => ({ value }), (cause) => ({ cause }));
|
|
164
164
|
if ("cause" in result)
|
|
165
165
|
return { service: undefined, timedOut: signal.aborted };
|
|
166
166
|
const response = result.value.response;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
// The previous V2 service exposes /api/health instead. Its authenticated 404 is enough
|
|
168
|
+
// to recognize the registered daemon as incompatible and route it through replacement.
|
|
169
|
+
if (response.status === 404)
|
|
170
|
+
return {
|
|
171
|
+
service: {
|
|
172
|
+
info,
|
|
173
|
+
endpoint,
|
|
174
|
+
version: info.version,
|
|
175
|
+
state: "ready",
|
|
176
|
+
compatible: false,
|
|
177
|
+
},
|
|
178
|
+
timedOut: false,
|
|
179
|
+
};
|
|
180
|
+
const status = decodeStatus(result.value.body);
|
|
181
|
+
if (status !== undefined) {
|
|
182
|
+
if (status.pid !== info.pid)
|
|
170
183
|
return { service: undefined, timedOut: false };
|
|
171
|
-
if (info.version !== undefined &&
|
|
184
|
+
if (info.version !== undefined && status.version !== info.version)
|
|
172
185
|
return { service: undefined, timedOut: false };
|
|
173
186
|
return {
|
|
174
187
|
service: {
|
|
175
188
|
info,
|
|
176
189
|
endpoint,
|
|
177
|
-
version:
|
|
190
|
+
version: status.version,
|
|
178
191
|
state: response.ok ? "ready" : response.status === 500 ? "failed" : "waiting",
|
|
179
|
-
|
|
192
|
+
compatible: true,
|
|
180
193
|
},
|
|
181
194
|
timedOut: false,
|
|
182
195
|
};
|
|
183
196
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
197
|
+
return { service: undefined, timedOut: false };
|
|
198
|
+
}
|
|
199
|
+
function decodeStatus(input) {
|
|
200
|
+
if (typeof input !== "object" || input === null)
|
|
201
|
+
return;
|
|
202
|
+
if (!("version" in input) || typeof input.version !== "string")
|
|
203
|
+
return;
|
|
204
|
+
if (!("pid" in input) || typeof input.pid !== "number" || !Number.isInteger(input.pid) || input.pid < 0)
|
|
205
|
+
return;
|
|
206
|
+
return { version: input.version, pid: input.pid };
|
|
190
207
|
}
|
|
191
|
-
async function registered(file,
|
|
208
|
+
async function registered(file, timeout) {
|
|
192
209
|
const info = await read(file);
|
|
193
210
|
if (info === undefined)
|
|
194
211
|
return { info: undefined, service: undefined, timedOut: false };
|
|
195
|
-
return { info, ...(await probeResult(info,
|
|
212
|
+
return { info, ...(await probeResult(info, timeout)) };
|
|
196
213
|
}
|
|
197
214
|
function signal(pid, name) {
|
|
198
215
|
try {
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"import": "./client/index.js"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
|
-
"version": "2.0.
|
|
17
|
+
"version": "2.0.3-shuv.1",
|
|
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-
|
|
34
|
-
"shuvcode-linux-x64-baseline": "2.0.
|
|
35
|
-
"shuvcode-linux-
|
|
36
|
-
"shuvcode-
|
|
37
|
-
"shuvcode-
|
|
38
|
-
"shuvcode-darwin-arm64": "2.0.
|
|
39
|
-
"shuvcode-
|
|
40
|
-
"shuvcode-
|
|
41
|
-
"shuvcode-windows-x64": "2.0.
|
|
42
|
-
"shuvcode-
|
|
43
|
-
"shuvcode-linux-arm64-musl": "2.0.
|
|
44
|
-
"shuvcode-
|
|
33
|
+
"shuvcode-linux-x64": "2.0.3-shuv.1",
|
|
34
|
+
"shuvcode-linux-x64-baseline": "2.0.3-shuv.1",
|
|
35
|
+
"shuvcode-linux-arm64": "2.0.3-shuv.1",
|
|
36
|
+
"shuvcode-linux-x64-musl": "2.0.3-shuv.1",
|
|
37
|
+
"shuvcode-windows-x64": "2.0.3-shuv.1",
|
|
38
|
+
"shuvcode-darwin-arm64": "2.0.3-shuv.1",
|
|
39
|
+
"shuvcode-windows-arm64": "2.0.3-shuv.1",
|
|
40
|
+
"shuvcode-linux-x64-baseline-musl": "2.0.3-shuv.1",
|
|
41
|
+
"shuvcode-windows-x64-baseline": "2.0.3-shuv.1",
|
|
42
|
+
"shuvcode-darwin-x64-baseline": "2.0.3-shuv.1",
|
|
43
|
+
"shuvcode-linux-arm64-musl": "2.0.3-shuv.1",
|
|
44
|
+
"shuvcode-darwin-x64": "2.0.3-shuv.1"
|
|
45
45
|
}
|
|
46
46
|
}
|