diff --git a/package-lock.json b/package-lock.json index 726e1da..a02393d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "twinny", - "version": "3.19.3", + "version": "3.19.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "twinny", - "version": "3.19.3", + "version": "3.19.4", "cpu": [ "x64", "arm64" diff --git a/package.json b/package.json index c7ce96d..7a3bbc8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "twinny", "displayName": "twinny - AI Code Completion and Chat", "description": "Locally hosted AI code completion plugin for vscode", - "version": "3.19.3", + "version": "3.19.4", "icon": "assets/icon.png", "keywords": [ "code-inference", diff --git a/src/extension/symmetry-service.ts b/src/extension/symmetry-service.ts index ca20a5d..c768f2c 100644 --- a/src/extension/symmetry-service.ts +++ b/src/extension/symmetry-service.ts @@ -8,7 +8,8 @@ import os from "os" import path from "path" import { EventEmitter } from "stream" import { serverMessageKeys, SymmetryProvider } from "symmetry-core" -import { commands, ExtensionContext, Webview, workspace } from "vscode" +import * as vscode from "vscode" +import { commands, ExtensionContext, Webview, window, workspace } from "vscode" import { ACTIVE_CHAT_PROVIDER_STORAGE_KEY, @@ -262,7 +263,7 @@ export class SymmetryService extends EventEmitter { return path.join(homeDir, ".config", "symmetry", "provider.yaml") } - private createOrUpdateProviderConfig(providerConfig: TwinnyProvider): void { + private createProviderConfig(provider: TwinnyProvider): Promise { const configPath = this.getSymmetryConfigPath() const configDir = path.dirname(configPath) @@ -270,35 +271,59 @@ export class SymmetryService extends EventEmitter { fs.mkdirSync(configDir, { recursive: true }) } + const existingConfig = yaml.load(fs.readFileSync(configPath, "utf8")) as any + + const userSecret = existingConfig?.userSecret + ? existingConfig.userSecret + : crypto.randomBytes(32).toString("hex") + const symmetryConfiguration = yaml.dump({ - apiHostname: providerConfig.apiHostname, - apiKey: providerConfig.apiKey, - apiPath: providerConfig.apiPath, - apiPort: providerConfig.apiPort, - apiProtocol: providerConfig.apiProtocol, - apiProvider: providerConfig.provider, + apiHostname: provider.apiHostname, + apiKey: provider.apiKey, + apiPath: provider.apiPath, + apiPort: provider.apiPort, + apiProtocol: provider.apiProtocol, + apiProvider: provider.provider, dataCollectionEnabled: false, maxConnections: 10, - modelName: providerConfig.modelName, + modelName: provider.modelName, name: os.hostname(), path: configPath, public: true, serverKey: this._config.symmetryServerKey, + userSecret, systemMessage: "" }) - fs.writeFileSync(configPath, symmetryConfiguration, "utf8") + return fs.promises.writeFile(configPath, symmetryConfiguration, "utf8"); } - public async startSymmetryProvider() { - const providerConfig = this.getChatProvider() + public startSymmetryProvider = async () => { + const provider = this.getChatProvider() - if (!providerConfig) return + if (!provider) return const configPath = this.getSymmetryConfigPath() if (!fs.existsSync(configPath)) { - this.createOrUpdateProviderConfig(providerConfig) + await this.createProviderConfig(provider) + } + + const existingConfig = yaml.load(fs.readFileSync(configPath, "utf8")) as any + const { userSecret } = existingConfig + + if (!userSecret) { + vscode.window.showInformationMessage( + ` + Twinny did not detect a userSecret for your provider. + Generating a \`userSecret\` for you at at ${configPath} + This only needs to be done once. + ` + ) + await fs.promises.writeFile(configPath, yaml.dump({ + ...existingConfig, + userSecret: crypto.randomBytes(32).toString("hex") + }), "utf8") } this._provider = new SymmetryProvider(configPath) @@ -324,7 +349,7 @@ export class SymmetryService extends EventEmitter { }) } - public async stopSymmetryProvider() { + public stopSymmetryProvider = async () => { await this._provider?.destroySwarms() updateSymmetryStatus(this._webView, "disconnected") const sessionKey = EXTENSION_SESSION_NAME.twinnySymmetryConnectionProvider