Просмотр исходного кода

core: add config update endpoint and functionality

Dax Raad 4 месяцев назад
Родитель
Сommit
eb7f4e20df
2 измененных файлов с 31 добавлено и 0 удалено
  1. 7 0
      packages/opencode/src/config/config.ts
  2. 24 0
      packages/opencode/src/server/server.ts

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

@@ -686,6 +686,13 @@ export namespace 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() {
     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())
         },
       )
+      .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(
         "/experimental/tool/ids",
         describeRoute({