opencode-agent[bot] 4 месяцев назад
Родитель
Сommit
dfc0075f90

+ 38 - 39
packages/opencode/src/server/routes/instance/httpapi/control.ts

@@ -31,42 +31,41 @@ export const ControlPaths = {
   log: "/log",
 } as const
 
-export const ControlApi = HttpApi.make("control")
-  .add(
-    HttpApiGroup.make("control")
-      .add(
-        HttpApiEndpoint.put("authSet", ControlPaths.auth, {
-          params: AuthParams,
-          payload: Auth.Info,
-          success: Schema.Boolean,
-        }).annotateMerge(
-          OpenApi.annotations({
-            identifier: "auth.set",
-            summary: "Set auth credentials",
-            description: "Set authentication credentials",
-          }),
-        ),
-        HttpApiEndpoint.delete("authRemove", ControlPaths.auth, {
-          params: AuthParams,
-          success: Schema.Boolean,
-        }).annotateMerge(
-          OpenApi.annotations({
-            identifier: "auth.remove",
-            summary: "Remove auth credentials",
-            description: "Remove authentication credentials",
-          }),
-        ),
-        HttpApiEndpoint.post("log", ControlPaths.log, {
-          query: LogQuery,
-          payload: LogInput,
-          success: Schema.Boolean,
-        }).annotateMerge(
-          OpenApi.annotations({
-            identifier: "app.log",
-            summary: "Write log",
-            description: "Write a log entry to the server logs with specified level and metadata.",
-          }),
-        ),
-      )
-      .annotateMerge(OpenApi.annotations({ title: "control", description: "Control plane routes." })),
-  )
+export const ControlApi = HttpApi.make("control").add(
+  HttpApiGroup.make("control")
+    .add(
+      HttpApiEndpoint.put("authSet", ControlPaths.auth, {
+        params: AuthParams,
+        payload: Auth.Info,
+        success: Schema.Boolean,
+      }).annotateMerge(
+        OpenApi.annotations({
+          identifier: "auth.set",
+          summary: "Set auth credentials",
+          description: "Set authentication credentials",
+        }),
+      ),
+      HttpApiEndpoint.delete("authRemove", ControlPaths.auth, {
+        params: AuthParams,
+        success: Schema.Boolean,
+      }).annotateMerge(
+        OpenApi.annotations({
+          identifier: "auth.remove",
+          summary: "Remove auth credentials",
+          description: "Remove authentication credentials",
+        }),
+      ),
+      HttpApiEndpoint.post("log", ControlPaths.log, {
+        query: LogQuery,
+        payload: LogInput,
+        success: Schema.Boolean,
+      }).annotateMerge(
+        OpenApi.annotations({
+          identifier: "app.log",
+          summary: "Write log",
+          description: "Write a log entry to the server logs with specified level and metadata.",
+        }),
+      ),
+    )
+    .annotateMerge(OpenApi.annotations({ title: "control", description: "Control plane routes." })),
+)

+ 15 - 16
packages/opencode/src/server/routes/instance/httpapi/event.ts

@@ -11,22 +11,21 @@ export const EventPaths = {
   event: "/event",
 } as const
 
-export const EventApi = HttpApi.make("event")
-  .add(
-    HttpApiGroup.make("event")
-      .add(
-        HttpApiEndpoint.get("subscribe", EventPaths.event, {
-          success: Schema.Unknown,
-        }).annotateMerge(
-          OpenApi.annotations({
-            identifier: "event.subscribe",
-            summary: "Subscribe to events",
-            description: "Get events",
-          }),
-        ),
-      )
-      .annotateMerge(OpenApi.annotations({ title: "event", description: "Instance event stream route." })),
-  )
+export const EventApi = HttpApi.make("event").add(
+  HttpApiGroup.make("event")
+    .add(
+      HttpApiEndpoint.get("subscribe", EventPaths.event, {
+        success: Schema.Unknown,
+      }).annotateMerge(
+        OpenApi.annotations({
+          identifier: "event.subscribe",
+          summary: "Subscribe to events",
+          description: "Get events",
+        }),
+      ),
+    )
+    .annotateMerge(OpenApi.annotations({ title: "event", description: "Instance event stream route." })),
+)
 
 function eventData(data: unknown) {
   return `data: ${JSON.stringify(data)}\n\n`

+ 62 - 63
packages/opencode/src/server/routes/instance/httpapi/global.ts

@@ -37,66 +37,65 @@ export const GlobalPaths = {
   upgrade: "/global/upgrade",
 } as const
 
-export const GlobalApi = HttpApi.make("global")
-  .add(
-    HttpApiGroup.make("global")
-      .add(
-        HttpApiEndpoint.get("health", GlobalPaths.health, {
-          success: GlobalHealth,
-        }).annotateMerge(
-          OpenApi.annotations({
-            identifier: "global.health",
-            summary: "Get health",
-            description: "Get health information about the OpenCode server.",
-          }),
-        ),
-        HttpApiEndpoint.get("event", GlobalPaths.event, {
-          success: GlobalEvent,
-        }).annotateMerge(
-          OpenApi.annotations({
-            identifier: "global.event",
-            summary: "Get global events",
-            description: "Subscribe to global events from the OpenCode system using server-sent events.",
-          }),
-        ),
-        HttpApiEndpoint.get("configGet", GlobalPaths.config, {
-          success: Config.Info,
-        }).annotateMerge(
-          OpenApi.annotations({
-            identifier: "global.config.get",
-            summary: "Get global configuration",
-            description: "Retrieve the current global OpenCode configuration settings and preferences.",
-          }),
-        ),
-        HttpApiEndpoint.patch("configUpdate", GlobalPaths.config, {
-          payload: Config.Info,
-          success: Config.Info,
-        }).annotateMerge(
-          OpenApi.annotations({
-            identifier: "global.config.update",
-            summary: "Update global configuration",
-            description: "Update global OpenCode configuration settings and preferences.",
-          }),
-        ),
-        HttpApiEndpoint.post("dispose", GlobalPaths.dispose, {
-          success: Schema.Boolean,
-        }).annotateMerge(
-          OpenApi.annotations({
-            identifier: "global.dispose",
-            summary: "Dispose instance",
-            description: "Clean up and dispose all OpenCode instances, releasing all resources.",
-          }),
-        ),
-        HttpApiEndpoint.post("upgrade", GlobalPaths.upgrade, {
-          payload: GlobalUpgradeInput,
-          success: GlobalUpgradeResult,
-        }).annotateMerge(
-          OpenApi.annotations({
-            identifier: "global.upgrade",
-            summary: "Upgrade opencode",
-            description: "Upgrade opencode to the specified version or latest if not specified.",
-          }),
-        ),
-      )
-      .annotateMerge(OpenApi.annotations({ title: "global", description: "Global server routes." })),
-  )
+export const GlobalApi = HttpApi.make("global").add(
+  HttpApiGroup.make("global")
+    .add(
+      HttpApiEndpoint.get("health", GlobalPaths.health, {
+        success: GlobalHealth,
+      }).annotateMerge(
+        OpenApi.annotations({
+          identifier: "global.health",
+          summary: "Get health",
+          description: "Get health information about the OpenCode server.",
+        }),
+      ),
+      HttpApiEndpoint.get("event", GlobalPaths.event, {
+        success: GlobalEvent,
+      }).annotateMerge(
+        OpenApi.annotations({
+          identifier: "global.event",
+          summary: "Get global events",
+          description: "Subscribe to global events from the OpenCode system using server-sent events.",
+        }),
+      ),
+      HttpApiEndpoint.get("configGet", GlobalPaths.config, {
+        success: Config.Info,
+      }).annotateMerge(
+        OpenApi.annotations({
+          identifier: "global.config.get",
+          summary: "Get global configuration",
+          description: "Retrieve the current global OpenCode configuration settings and preferences.",
+        }),
+      ),
+      HttpApiEndpoint.patch("configUpdate", GlobalPaths.config, {
+        payload: Config.Info,
+        success: Config.Info,
+      }).annotateMerge(
+        OpenApi.annotations({
+          identifier: "global.config.update",
+          summary: "Update global configuration",
+          description: "Update global OpenCode configuration settings and preferences.",
+        }),
+      ),
+      HttpApiEndpoint.post("dispose", GlobalPaths.dispose, {
+        success: Schema.Boolean,
+      }).annotateMerge(
+        OpenApi.annotations({
+          identifier: "global.dispose",
+          summary: "Dispose instance",
+          description: "Clean up and dispose all OpenCode instances, releasing all resources.",
+        }),
+      ),
+      HttpApiEndpoint.post("upgrade", GlobalPaths.upgrade, {
+        payload: GlobalUpgradeInput,
+        success: GlobalUpgradeResult,
+      }).annotateMerge(
+        OpenApi.annotations({
+          identifier: "global.upgrade",
+          summary: "Upgrade opencode",
+          description: "Upgrade opencode to the specified version or latest if not specified.",
+        }),
+      ),
+    )
+    .annotateMerge(OpenApi.annotations({ title: "global", description: "Global server routes." })),
+)

+ 18 - 18
packages/opencode/src/server/routes/instance/httpapi/pty.ts

@@ -113,24 +113,24 @@ export const PtyApi = HttpApi.make("pty")
     }),
   )
 
-export const PtyConnectApi = HttpApi.make("pty-connect")
-  .add(
-    HttpApiGroup.make("pty-connect")
-      .add(
-        HttpApiEndpoint.get("connect", PtyPaths.connect, {
-          params: Params,
-          query: CursorQuery,
-          success: Schema.Boolean,
-        }).annotateMerge(
-          OpenApi.annotations({
-            identifier: "pty.connect",
-            summary: "Connect to PTY session",
-            description: "Establish a WebSocket connection to interact with a pseudo-terminal (PTY) session in real-time.",
-          }),
-        ),
-      )
-      .annotateMerge(OpenApi.annotations({ title: "pty", description: "PTY websocket route." })),
-  )
+export const PtyConnectApi = HttpApi.make("pty-connect").add(
+  HttpApiGroup.make("pty-connect")
+    .add(
+      HttpApiEndpoint.get("connect", PtyPaths.connect, {
+        params: Params,
+        query: CursorQuery,
+        success: Schema.Boolean,
+      }).annotateMerge(
+        OpenApi.annotations({
+          identifier: "pty.connect",
+          summary: "Connect to PTY session",
+          description:
+            "Establish a WebSocket connection to interact with a pseudo-terminal (PTY) session in real-time.",
+        }),
+      ),
+    )
+    .annotateMerge(OpenApi.annotations({ title: "pty", description: "PTY websocket route." })),
+)
 
 export const ptyHandlers = Layer.unwrap(
   Effect.gen(function* () {

+ 3 - 1
packages/opencode/test/server/httpapi-bridge.test.ts

@@ -80,7 +80,9 @@ function reflectedHttpApiRoutes() {
 
 function openApiRouteKeys(spec: { paths: Record<string, Partial<Record<(typeof methods)[number], unknown>>> }) {
   return Object.entries(spec.paths)
-    .flatMap(([path, item]) => methods.filter((method) => item[method]).map((method) => `${method.toUpperCase()} ${path}`))
+    .flatMap(([path, item]) =>
+      methods.filter((method) => item[method]).map((method) => `${method.toUpperCase()} ${path}`),
+    )
     .sort()
 }