Przeglądaj źródła

core: add config update endpoint and functionality

Dax Raad 4 miesięcy temu
rodzic
commit
eb7f4e20df

+ 7 - 0
packages/opencode/src/config/config.ts

@@ -686,6 +686,13 @@ export namespace Config {
     return state().then((x) => x.config)
     return state().then((x) => x.config)
   }
   }
 
 
+  export async function update(config: Info) {
+    const filepath = path.join(Instance.directory, "config.json")
+    const existing = await loadFile(filepath)
+    await Bun.write(filepath, JSON.stringify(mergeDeep(existing, config), null, 2))
+    await Instance.dispose()
+  }
+
   export async function directories() {
   export async function directories() {
     return state().then((x) => x.directories)
     return state().then((x) => x.directories)
   }
   }

+ 24 - 0
packages/opencode/src/server/server.ts

@@ -135,6 +135,30 @@ export namespace Server {
           return c.json(await Config.get())
           return c.json(await Config.get())
         },
         },
       )
       )
+      .patch(
+        "/config",
+        describeRoute({
+          description: "Update config",
+          operationId: "config.update",
+          responses: {
+            200: {
+              description: "Successfully updated config",
+              content: {
+                "application/json": {
+                  schema: resolver(Config.Info),
+                },
+              },
+            },
+            ...ERRORS,
+          },
+        }),
+        validator("json", Config.Info),
+        async (c) => {
+          const config = c.req.valid("json")
+          await Config.update(config)
+          return c.json(config)
+        },
+      )
       .get(
       .get(
         "/experimental/tool/ids",
         "/experimental/tool/ids",
         describeRoute({
         describeRoute({