feat: add /config chat config updates

This commit is contained in:
Peter Steinberger
2026-01-10 03:00:24 +01:00
parent 63b0a16357
commit 8b579c91a5
13 changed files with 421 additions and 108 deletions

View File

@@ -0,0 +1,62 @@
import { parseConfigValue } from "./config-value.js";
export type ConfigCommand =
| { action: "show"; path?: string }
| { action: "set"; path: string; value: unknown }
| { action: "unset"; path: string }
| { action: "error"; message: string };
export function parseConfigCommand(raw: string): ConfigCommand | null {
const trimmed = raw.trim();
if (!trimmed.toLowerCase().startsWith("/config")) return null;
const rest = trimmed.slice("/config".length).trim();
if (!rest) return { action: "show" };
const match = rest.match(/^(\S+)(?:\s+([\s\S]+))?$/);
if (!match) return { action: "error", message: "Invalid /config syntax." };
const action = match[1].toLowerCase();
const args = (match[2] ?? "").trim();
switch (action) {
case "show":
return { action: "show", path: args || undefined };
case "unset": {
if (!args)
return { action: "error", message: "Usage: /config unset path" };
return { action: "unset", path: args };
}
case "set": {
if (!args) {
return {
action: "error",
message: "Usage: /config set path=value",
};
}
const eqIndex = args.indexOf("=");
if (eqIndex <= 0) {
return {
action: "error",
message: "Usage: /config set path=value",
};
}
const path = args.slice(0, eqIndex).trim();
const rawValue = args.slice(eqIndex + 1);
if (!path) {
return {
action: "error",
message: "Usage: /config set path=value",
};
}
const parsed = parseConfigValue(rawValue);
if (parsed.error) {
return { action: "error", message: parsed.error };
}
return { action: "set", path, value: parsed.value };
}
default:
return {
action: "error",
message: "Usage: /config show|set|unset",
};
}
}