Skip to content

Commit

Permalink
refactor(agent): Move data path from ~/.tabby/agent to ~/.tabby-clien…
Browse files Browse the repository at this point in the history
…t/agent. Add config.toml template. (#420)
  • Loading branch information
icycodes authored Sep 10, 2023
1 parent f0ed366 commit 12a37e2
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 8 deletions.
2 changes: 1 addition & 1 deletion clients/tabby-agent/src/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
59 changes: 57 additions & 2 deletions clients/tabby-agent/src/AgentConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
: (() => {
Expand Down Expand Up @@ -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");
}
}

Expand All @@ -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);
})();
2 changes: 1 addition & 1 deletion clients/tabby-agent/src/TabbyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"][] = [];
Expand Down
2 changes: 1 addition & 1 deletion clients/tabby-agent/src/dataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down
4 changes: 2 additions & 2 deletions clients/tabby-agent/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
Expand Down
2 changes: 1 addition & 1 deletion clients/vscode/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 12a37e2

Please sign in to comment.