mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 17:54:23 +01:00
core: add config update endpoint and functionality
This commit is contained in:
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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({
|
||||||
|
|||||||
Reference in New Issue
Block a user