refactor: move vscode dev options to agent config. (#283)

sweep/improve-logging-information
Zhiming Ma 2023-07-07 00:31:15 +08:00 committed by GitHub
parent 920ff9d0fe
commit 62e0ea91d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 86 additions and 144 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -40,6 +40,10 @@ type AgentConfig = {
server: { server: {
endpoint: string; endpoint: string;
}; };
completion: {
maxPrefixLines: number;
maxSuffixLines: number;
};
logs: { logs: {
level: "debug" | "error" | "silent"; level: "debug" | "error" | "silent";
}; };
@ -57,8 +61,8 @@ type CompletionRequest = {
language: string; language: string;
text: string; text: string;
position: number; position: number;
maxPrefixLines: number; maxPrefixLines?: number;
maxSuffixLines: number; maxSuffixLines?: number;
}; };
type CompletionResponse = CompletionResponse$1; type CompletionResponse = CompletionResponse$1;
type LogEventRequest = LogEventRequest$1; type LogEventRequest = LogEventRequest$1;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -850,6 +850,10 @@ var defaultAgentConfig = {
server: { server: {
endpoint: "http://localhost:8080" endpoint: "http://localhost:8080"
}, },
completion: {
maxPrefixLines: 20,
maxSuffixLines: 20
},
logs: { logs: {
level: "silent" level: "silent"
}, },
@ -1256,8 +1260,8 @@ var _TabbyAgent = class extends import_events2.EventEmitter {
}); });
} }
createSegments(request2) { createSegments(request2) {
const maxPrefixLines = request2.maxPrefixLines; const maxPrefixLines = request2.maxPrefixLines ?? this.config.completion.maxPrefixLines;
const maxSuffixLines = request2.maxSuffixLines; const maxSuffixLines = request2.maxSuffixLines ?? this.config.completion.maxSuffixLines;
const prefix = request2.text.slice(0, request2.position); const prefix = request2.text.slice(0, request2.position);
const prefixLines = splitLines(prefix); const prefixLines = splitLines(prefix);
const suffix = request2.text.slice(request2.position); const suffix = request2.text.slice(request2.position);

File diff suppressed because one or more lines are too long

View File

@ -43811,6 +43811,10 @@ var defaultAgentConfig = {
server: { server: {
endpoint: "http://localhost:8080" endpoint: "http://localhost:8080"
}, },
completion: {
maxPrefixLines: 20,
maxSuffixLines: 20
},
logs: { logs: {
level: "silent" level: "silent"
}, },
@ -45566,8 +45570,8 @@ var _TabbyAgent = class extends EventEmitter {
}); });
} }
createSegments(request2) { createSegments(request2) {
const maxPrefixLines = request2.maxPrefixLines; const maxPrefixLines = request2.maxPrefixLines ?? this.config.completion.maxPrefixLines;
const maxSuffixLines = request2.maxSuffixLines; const maxSuffixLines = request2.maxSuffixLines ?? this.config.completion.maxSuffixLines;
const prefix = request2.text.slice(0, request2.position); const prefix = request2.text.slice(0, request2.position);
const prefixLines = splitLines(prefix); const prefixLines = splitLines(prefix);
const suffix = request2.text.slice(request2.position); const suffix = request2.text.slice(request2.position);

File diff suppressed because one or more lines are too long

View File

@ -16,8 +16,8 @@ export type CompletionRequest = {
language: string; language: string;
text: string; text: string;
position: number; position: number;
maxPrefixLines: number; maxPrefixLines?: number;
maxSuffixLines: number; maxSuffixLines?: number;
}; };
export type CompletionResponse = ApiCompletionResponse; export type CompletionResponse = ApiCompletionResponse;

View File

@ -4,6 +4,10 @@ export type AgentConfig = {
server: { server: {
endpoint: string; endpoint: string;
}; };
completion: {
maxPrefixLines: number;
maxSuffixLines: number;
};
logs: { logs: {
level: "debug" | "error" | "silent"; level: "debug" | "error" | "silent";
}; };
@ -16,6 +20,10 @@ export const defaultAgentConfig: AgentConfig = {
server: { server: {
endpoint: "http://localhost:8080", endpoint: "http://localhost:8080",
}, },
completion: {
maxPrefixLines: 20,
maxSuffixLines: 20,
},
logs: { logs: {
level: "silent", level: "silent",
}, },

View File

@ -129,8 +129,8 @@ export class TabbyAgent extends EventEmitter implements Agent {
private createSegments(request: CompletionRequest): { prefix: string; suffix: string } { private createSegments(request: CompletionRequest): { prefix: string; suffix: string } {
// max lines in prefix and suffix configurable // max lines in prefix and suffix configurable
const maxPrefixLines = request.maxPrefixLines; const maxPrefixLines = request.maxPrefixLines ?? this.config.completion.maxPrefixLines;
const maxSuffixLines = request.maxSuffixLines; const maxSuffixLines = request.maxSuffixLines ?? this.config.completion.maxSuffixLines;
const prefix = request.text.slice(0, request.position); const prefix = request.text.slice(0, request.position);
const prefixLines = splitLines(prefix); const prefixLines = splitLines(prefix);
const suffix = request.text.slice(request.position); const suffix = request.text.slice(request.position);

View File

@ -44,11 +44,23 @@
"command": "tabby.openSettings", "command": "tabby.openSettings",
"title": "Tabby: Open Settings" "title": "Tabby: Open Settings"
}, },
{
"command": "tabby.openTabbyAgentSettings",
"title": "Tabby: Open Tabby Agent Settings"
},
{ {
"command": "tabby.gettingStarted", "command": "tabby.gettingStarted",
"title": "Tabby: Getting Started" "title": "Tabby: Getting Started"
} }
], ],
"menus": {
"commandPalette": [
{
"command": "tabby.openTabbyAgentSettings",
"when": "!isWeb"
}
]
},
"walkthroughs": [ "walkthroughs": [
{ {
"id": "gettingStarted", "id": "gettingStarted",
@ -83,7 +95,7 @@
{ {
"id": "commands", "id": "commands",
"title": "Commands", "title": "Commands",
"description": "Type `>Tabby:` in quick open prompt to list all Tabby commands. \n[Tabby commands](command:workbench.action.quickOpen?%5B%22%3ETabby%3A%22%5D)", "description": "Type `>Tabby:` in command palette to list all Tabby commands. \n[Tabby commands](command:workbench.action.quickOpen?%5B%22%3ETabby%3A%22%5D)",
"media": { "media": {
"image": "assets/walkthroughs/commands.png", "image": "assets/walkthroughs/commands.png",
"altText": "Tabby Commands" "altText": "Tabby Commands"
@ -97,54 +109,16 @@
"properties": { "properties": {
"tabby.api.endpoint": { "tabby.api.endpoint": {
"type": "string", "type": "string",
"default": "http://localhost:8080", "default": "",
"format": "uri", "pattern": "(^$)|(^https?:\\/\\/\\S+$)",
"pattern": "^https?:\\/\\/[^\\s]+$",
"patternErrorMessage": "Please enter a validate http or https URL.", "patternErrorMessage": "Please enter a validate http or https URL.",
"description": "Specify API Endpoint of Tabby." "markdownDescription": "Specify API Endpoint of Tabby. \nIf leave empty, server endpoint in [Tabby Agent Settings](command:tabby.openTabbyAgentSettings) will be used."
}, },
"tabby.codeCompletion": { "tabby.codeCompletion": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
"description": "Enable Tabby code completion or not." "description": "Enable Tabby code completion or not."
}, },
"tabby.developerOptions": {
"type": "object",
"description": "Developer options for Tabby.",
"properties": {
"maxPrefixLines": {
"type": "number",
"default": 20,
"description": "Number of lines to include in the Prefix for completion requests"
},
"maxSuffixLines": {
"type": "number",
"default": 20,
"description": "Number of lines to include in the Suffix for completion requests"
},
"suggestionDelay": {
"type": "number",
"default": 150,
"minimum": 0,
"description": "Specifies the delay in milliseconds after which the request is sent to the tabby."
},
"agent": {
"type": "object",
"properties": {
"logs": {
"type": "string",
"enum": [
"debug",
"error",
"silent"
],
"default": "error",
"markdownDescription": "Specifies the log level for tabby-agent."
}
}
}
}
},
"tabby.usage.anonymousUsageTracking": { "tabby.usage.anonymousUsageTracking": {
"type": "boolean", "type": "boolean",
"default": false, "default": false,
@ -190,7 +164,6 @@
"webpack-cli": "^4.10.0" "webpack-cli": "^4.10.0"
}, },
"dependencies": { "dependencies": {
"@sapphire/duration": "^1.1.0",
"@xstate/fsm": "^2.0.1", "@xstate/fsm": "^2.0.1",
"tabby-agent": "file:../tabby-agent" "tabby-agent": "file:../tabby-agent"
} }

View File

@ -21,6 +21,8 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider {
// User Settings // User Settings
private enabled: boolean = true; private enabled: boolean = true;
// These settings will be move to tabby-agent
private suggestionDelay: number = 150; private suggestionDelay: number = 150;
private maxPrefixLines: number = 20; private maxPrefixLines: number = 20;
private maxSuffixLines: number = 20; private maxSuffixLines: number = 20;
@ -79,9 +81,6 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider {
private updateConfiguration() { private updateConfiguration() {
const configuration = workspace.getConfiguration("tabby"); const configuration = workspace.getConfiguration("tabby");
this.enabled = configuration.get("codeCompletion", true); this.enabled = configuration.get("codeCompletion", true);
this.suggestionDelay = configuration.get("developerOptions.suggestionDelay", 150);
this.maxPrefixLines = configuration.get("developerOptions.maxPrefixLines", 20);
this.maxSuffixLines = configuration.get("developerOptions.maxSuffixLines", 20);
} }
private toInlineCompletions(tabbyCompletion: CompletionResponse | null, range: Range): InlineCompletionItem[] { private toInlineCompletions(tabbyCompletion: CompletionResponse | null, range: Range): InlineCompletionItem[] {

View File

@ -5,17 +5,11 @@ function getWorkspaceConfiguration(): Partial<AgentConfig> {
const configuration = workspace.getConfiguration("tabby"); const configuration = workspace.getConfiguration("tabby");
const config: Partial<AgentConfig> = {}; const config: Partial<AgentConfig> = {};
const endpoint = configuration.get<string>("api.endpoint"); const endpoint = configuration.get<string>("api.endpoint");
if (endpoint) { if (endpoint && endpoint.trim().length > 0) {
config.server = { config.server = {
endpoint, endpoint,
}; };
} }
const agentLogs = configuration.get<"debug" | "error" | "silent">("developerOptions.agent.logs");
if (agentLogs) {
config.logs = {
level: agentLogs,
};
}
const anonymousUsageTrackingDisabled = configuration.get<boolean>("usage.anonymousUsageTracking", false); const anonymousUsageTrackingDisabled = configuration.get<boolean>("usage.anonymousUsageTracking", false);
config.anonymousUsageTracking = { config.anonymousUsageTracking = {
disable: anonymousUsageTrackingDisabled, disable: anonymousUsageTrackingDisabled,

View File

@ -2,8 +2,6 @@ import {
ConfigurationTarget, ConfigurationTarget,
InputBoxValidationSeverity, InputBoxValidationSeverity,
ProgressLocation, ProgressLocation,
QuickPickItem,
QuickPickItemKind,
Uri, Uri,
workspace, workspace,
window, window,
@ -11,7 +9,6 @@ import {
commands, commands,
} from "vscode"; } from "vscode";
import { strict as assert } from "assert"; import { strict as assert } from "assert";
import { Duration } from "@sapphire/duration";
import { CancelablePromise } from "tabby-agent"; import { CancelablePromise } from "tabby-agent";
import { agent } from "./agent"; import { agent } from "./agent";
import { notifications } from "./notifications"; import { notifications } from "./notifications";
@ -34,67 +31,6 @@ const toggleEnabled: Command = {
}, },
}; };
const setSuggestionDelay: Command = {
command: "tabby.setSuggestionDelay",
callback: () => {
const configuration = workspace.getConfiguration("tabby");
const current = configuration.get("developerOptions.suggestionDelay", 150);
const items = {
Immediately: 0, // ms
Default: 150,
Slowly: 1000,
};
const createQuickPickItem = (value: number): QuickPickItem => {
const tags: string[] = [];
if (value == current) {
tags.push("Current");
}
Object.entries(items).forEach(([k, v]) => {
if (v == value) {
tags.push(k);
}
});
return {
label: value % 1000 == 0 ? `${value / 1000}s` : `${value}ms`,
description: tags.join(" "),
alwaysShow: true,
};
};
const buildQuickPickList = (input: string = "") => {
const list: QuickPickItem[] = [];
const customized = new Duration(input).offset || Number.parseInt(input);
if (customized >= 0) {
list.push(createQuickPickItem(customized));
}
if (current != customized) {
list.push(createQuickPickItem(current));
}
list.push({
label: "",
kind: QuickPickItemKind.Separator,
});
Object.values(items)
.filter((item) => item != current && item != customized)
.forEach((item) => list.push(createQuickPickItem(item)));
return list;
};
const quickPick = window.createQuickPick();
quickPick.placeholder = "Enter the delay after which the completion request is sent";
quickPick.matchOnDescription = true;
quickPick.items = buildQuickPickList();
quickPick.onDidChangeValue((input: string) => {
quickPick.items = buildQuickPickList(input);
});
quickPick.onDidAccept(() => {
quickPick.hide();
const delay = new Duration(quickPick.selectedItems[0].label).offset;
console.debug("Set suggestion delay: ", delay);
configuration.update("developerOptions.suggestionDelay", delay, configTarget, false);
});
quickPick.show();
},
};
const setApiEndpoint: Command = { const setApiEndpoint: Command = {
command: "tabby.setApiEndpoint", command: "tabby.setApiEndpoint",
callback: () => { callback: () => {
@ -132,6 +68,27 @@ const openSettings: Command = {
}, },
}; };
const openTabbyAgentSettings: Command = {
command: "tabby.openTabbyAgentSettings",
callback: () => {
if (env.appHost !== "desktop") {
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");
workspace.fs.stat(agentUserConfig).then(
() => {
workspace.openTextDocument(agentUserConfig).then((document) => {
window.showTextDocument(document);
});
},
() => {
window.showWarningMessage("Tabby Agent config file not found.", { modal: true });
}
);
},
};
const gettingStarted: Command = { const gettingStarted: Command = {
command: "tabby.gettingStarted", command: "tabby.gettingStarted",
callback: () => { callback: () => {
@ -219,8 +176,8 @@ export const tabbyCommands = () =>
[ [
toggleEnabled, toggleEnabled,
setApiEndpoint, setApiEndpoint,
setSuggestionDelay,
openSettings, openSettings,
openTabbyAgentSettings,
gettingStarted, gettingStarted,
emitEvent, emitEvent,
openAuthPage, openAuthPage,

View File

@ -1,6 +1,4 @@
import { commands, window, workspace, ConfigurationTarget } from "vscode"; import { commands, window } from "vscode";
const configTarget = ConfigurationTarget.Global;
function showInformationWhenLoading() { function showInformationWhenLoading() {
window.showInformationMessage("Tabby is initializing.", "Settings").then((selection) => { window.showInformationMessage("Tabby is initializing.", "Settings").then((selection) => {

View File

@ -2527,9 +2527,9 @@ object-keys@^1.1.1:
integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA== integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==
object-sizeof@^2.6.1: object-sizeof@^2.6.1:
version "2.6.1" version "2.6.2"
resolved "https://registry.yarnpkg.com/object-sizeof/-/object-sizeof-2.6.1.tgz#1e2b6a01d182c268dbb07ee3403f539de45f63d3" resolved "https://registry.yarnpkg.com/object-sizeof/-/object-sizeof-2.6.2.tgz#f162e4fc842115cf06253c89d287105b23ed055b"
integrity sha512-a7VJ1Zx7ZuHceKwjgfsSqzV/X0PVGvpZz7ho3Dn4Cs0LLcR5e5WuV+gsbizmplD8s0nAXMJmckKB2rkSiPm/Gg== integrity sha512-yBcuQmJ/hezl+j6TaDxXzVYMRBFH2iJgkJWQz1nRh8t9JfFEcnZyqwEhJqVkpjnbQIJ2s7Xg4pSZxgQcEULgMA==
dependencies: dependencies:
buffer "^6.0.3" buffer "^6.0.3"
@ -2908,14 +2908,15 @@ readable-stream@^3.1.1, readable-stream@^3.4.0:
util-deprecate "^1.0.1" util-deprecate "^1.0.1"
readable-stream@^4.0.0: readable-stream@^4.0.0:
version "4.4.1" version "4.4.2"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-4.4.1.tgz#fa0f0878c3bc0c12b6a82e4e58c5dc160e1faaa2" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-4.4.2.tgz#e6aced27ad3b9d726d8308515b9a1b98dc1b9d13"
integrity sha512-llAHX9QC25bz5RPIoTeJxPaA/hgryaldValRhVZ2fK9bzbmFiscpz8fw6iBTvJfAk1w4FC1KXQme/nO7fbKyKg== integrity sha512-Lk/fICSyIhodxy1IDK2HazkeGjSmezAWX2egdtJnYhtzKEsBPJowlI6F6LPb5tqIQILrMbx22S5o3GuJavPusA==
dependencies: dependencies:
abort-controller "^3.0.0" abort-controller "^3.0.0"
buffer "^6.0.3" buffer "^6.0.3"
events "^3.3.0" events "^3.3.0"
process "^0.11.10" process "^0.11.10"
string_decoder "^1.3.0"
readdirp@~3.6.0: readdirp@~3.6.0:
version "3.6.0" version "3.6.0"
@ -3181,7 +3182,7 @@ string-width@^4.1.0, string-width@^4.2.0:
is-fullwidth-code-point "^3.0.0" is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1" strip-ansi "^6.0.1"
string_decoder@^1.1.1: string_decoder@^1.1.1, string_decoder@^1.3.0:
version "1.3.0" version "1.3.0"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e"
integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==