refactor(agent): Move data path from ~/.tabby/agent to ~/.tabby-client/agent. Add config.toml template. (#420)
parent
f0ed366420
commit
12a37e2330
|
|
@ -62,7 +62,7 @@ export interface AgentFunction {
|
|||
/**
|
||||
* The agent configuration has the following levels, will be deep merged in the order:
|
||||
* 1. Default config
|
||||
* 2. User config file `~/.tabby/agent/config.toml` (not available in browser)
|
||||
* 2. User config file `~/.tabby-client/agent/config.toml` (not available in browser)
|
||||
* 3. Agent `initialize` and `updateConfig` methods
|
||||
*
|
||||
* This method will update the 3rd level config.
|
||||
|
|
|
|||
|
|
@ -66,6 +66,49 @@ export const defaultAgentConfig: AgentConfig = {
|
|||
},
|
||||
};
|
||||
|
||||
const configTomlTemplate = `## Tabby agent configuration file
|
||||
|
||||
## You can uncomment any block to enable settings.
|
||||
## Configurations in this file has lower priority than in IDE settings.
|
||||
|
||||
## Server
|
||||
## You can set the server endpoint and request timeout here.
|
||||
# [server]
|
||||
# endpoint = "http://localhost:8080" # http or https URL
|
||||
# requestTimeout = 30000 # ms
|
||||
|
||||
## You can add custom request headers, e.g. for authentication.
|
||||
# [server.requestHeaders]
|
||||
# Authorization = "Bearer eyJhbGciOiJ..........."
|
||||
|
||||
## Completion
|
||||
## You can set the prompt context to send to the server for completion.
|
||||
# [completion.prompt]
|
||||
# maxPrefixLines = 20
|
||||
# maxSuffixLines = 20
|
||||
|
||||
## You can set the debounce mode for auto completion requests when typing.
|
||||
# [completion.debounce]
|
||||
# mode = "adaptive" # or "fixed"
|
||||
# interval = 250 # ms, only used when mode is "fixed"
|
||||
|
||||
## You can set the timeout for completion requests.
|
||||
# [completion.timeout]
|
||||
# auto = 5000 # ms, for auto completion when typing
|
||||
# manually = 30000 # ms, for manually triggered completion
|
||||
|
||||
## Logs
|
||||
## You can set the log level here. The log file is located at ~/.tabby-client/agent/logs/.
|
||||
# [logs]
|
||||
# level = "silent" # or "error" or "debug"
|
||||
|
||||
## Anonymous usage tracking
|
||||
## You can disable anonymous usage tracking here.
|
||||
# [anonymousUsageTracking]
|
||||
# disable = false # set to true to disable
|
||||
|
||||
`;
|
||||
|
||||
export const userAgentConfig = isBrowser
|
||||
? null
|
||||
: (() => {
|
||||
|
|
@ -95,7 +138,19 @@ export const userAgentConfig = isBrowser
|
|||
this.data = toml.parse(fileContent);
|
||||
super.emit("updated", this.data);
|
||||
} catch (error) {
|
||||
this.logger.error({ error }, "Failed to load config file");
|
||||
if (error.code === "ENOENT") {
|
||||
await this.createTemplate();
|
||||
} else {
|
||||
this.logger.error({ error }, "Failed to load config file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async createTemplate() {
|
||||
try {
|
||||
await fs.outputFile(this.filepath, configTomlTemplate);
|
||||
} catch (error) {
|
||||
this.logger.error({ error }, "Failed to create config template file");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -108,6 +163,6 @@ export const userAgentConfig = isBrowser
|
|||
}
|
||||
}
|
||||
|
||||
const configFile = require("path").join(require("os").homedir(), ".tabby", "agent", "config.toml");
|
||||
const configFile = require("path").join(require("os").homedir(), ".tabby-client", "agent", "config.toml");
|
||||
return new ConfigFile(configFile);
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ export class TabbyAgent extends EventEmitter implements Agent {
|
|||
private readonly logger = rootLogger.child({ component: "TabbyAgent" });
|
||||
private anonymousUsageLogger: AnonymousUsageLogger;
|
||||
private config: AgentConfig = defaultAgentConfig;
|
||||
private userConfig: PartialAgentConfig = {}; // config from `~/.tabby/agent/config.toml`
|
||||
private userConfig: PartialAgentConfig = {}; // config from `~/.tabby-client/agent/config.toml`
|
||||
private clientConfig: PartialAgentConfig = {}; // config from `initialize` and `updateConfig` method
|
||||
private status: AgentStatus = "notInitialized";
|
||||
private issues: AgentIssue["name"][] = [];
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export interface DataStore {
|
|||
export const dataStore: DataStore = isBrowser
|
||||
? null
|
||||
: (() => {
|
||||
const dataFile = require("path").join(require("os").homedir(), ".tabby", "agent", "data.json");
|
||||
const dataFile = require("path").join(require("os").homedir(), ".tabby-client", "agent", "data.json");
|
||||
const fs = require("fs-extra");
|
||||
return {
|
||||
data: {},
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ const stream =
|
|||
isBrowser || isTest
|
||||
? null
|
||||
: /**
|
||||
* Default rotating file locate at `~/.tabby/agent/logs/`.
|
||||
* Default rotating file locate at `~/.tabby-client/agent/logs/`.
|
||||
*/
|
||||
require("rotating-file-stream").createStream("tabby-agent.log", {
|
||||
path: require("path").join(require("os").homedir(), ".tabby", "agent", "logs"),
|
||||
path: require("path").join(require("os").homedir(), ".tabby-client", "agent", "logs"),
|
||||
size: "10M",
|
||||
interval: "1d",
|
||||
});
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ const openTabbyAgentSettings: Command = {
|
|||
window.showWarningMessage("Tabby Agent config file is not supported on web.", { modal: true });
|
||||
return;
|
||||
}
|
||||
const agentUserConfig = Uri.joinPath(Uri.file(require("os").homedir()), ".tabby", "agent", "config.toml");
|
||||
const agentUserConfig = Uri.joinPath(Uri.file(require("os").homedir()), ".tabby-client", "agent", "config.toml");
|
||||
workspace.fs.stat(agentUserConfig).then(
|
||||
() => {
|
||||
workspace.openTextDocument(agentUserConfig).then((document) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue