diff --git a/src/commands/runPrompt.ts b/src/commands/runPrompt.ts index 0b48d23..eb2e990 100644 --- a/src/commands/runPrompt.ts +++ b/src/commands/runPrompt.ts @@ -6,7 +6,6 @@ import { showPromptPicker } from "../utils/promptPicker"; import { createOutputBuffer } from "../utils/promptFilename"; import { spawnPromptImage, writeKeyToVolume } from "../utils/promptRunner"; import { verifyHasOpenAIKey } from "./setOpenAIKey"; -import { getCredential } from "../utils/credential"; import { setProjectDir } from "./setProjectDir"; import { postToBackendSocket } from "../utils/ddSocket"; import { ctx } from "../extension"; @@ -162,15 +161,13 @@ export const runPrompt: (secrets: vscode.SecretStorage, mode: PromptOption) => v progress.report({ increment: 5, message: "Detecting docker desktop token" }); - const { Username, Password } = await getCredential("docker"); - try { progress.report({ increment: 5, message: "Mounting secrets..." }); await writeKeyToVolume(apiKey!); progress.report({ increment: 5, message: "Running..." }); const ranges: Record = {}; const getBaseFunctionRange = () => new vscode.Range(doc.lineCount, 0, doc.lineCount, 0); - await spawnPromptImage(promptOption.id, runningLocal ? inputWorkspace! : workspaceFolder!.uri.fsPath, Username, process.platform, Password, async (json) => { + await spawnPromptImage(promptOption.id, runningLocal ? inputWorkspace! : workspaceFolder!.uri.fsPath, 'vscode-user', process.platform, async (json) => { if (json.method === 'functions') { const functions = json.params; for (const func of functions) { diff --git a/src/utils/credential.ts b/src/utils/credential.ts deleted file mode 100644 index 48e1182..0000000 --- a/src/utils/credential.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { spawnSync } from "child_process"; -import { env } from "vscode"; - -export const getCredential = async (service: string) => { - const auth = spawnSync( - `echo "https://index.docker.io/v1/" | docker-credential-desktop get`, - { - shell: process.platform === 'win32' ? "powershell" : true, - } - ); - let Username = `vscode-${env.machineId}`; - let Password = ""; - if (auth.stdout.toString().startsWith("{") && auth.status === 0 && !auth.error) { - try { - const authPayload = JSON.parse(auth.stdout.toString()) as { - "ServerURL": string, - "Username": string, - "Secret": string - }; - Username = authPayload.Username; - Password = authPayload.Secret; - } - catch (e) { - throw new Error(`Expected JSON from docker-credential-desktop, got STDOUT: ${auth.stdout.toString()} STDERR: ${auth.stderr.toString()} ERR: ${(auth.error || "N/A").toString()}`); - } - } - return { - Username, - Password - }; -}; \ No newline at end of file diff --git a/src/utils/ddSocket.ts b/src/utils/ddSocket.ts index dea112b..b783a82 100644 --- a/src/utils/ddSocket.ts +++ b/src/utils/ddSocket.ts @@ -1,43 +1,10 @@ import os from 'os'; -import path from 'path'; import http from 'http'; -import { ctx } from '../extension'; import { ExtensionContext } from 'vscode'; -const getDevhomePrefix = () => { - return process.env['DEVHOME'] ? path.basename(process.env['DEVHOME']) : ''; -} const getDevhome = (): string => { return process.env['DEVHOME'] ?? os.homedir(); } -const getUserDataDirectory = ( - /** This distinction is only currently meaningful on Windows */ - type: 'local' | 'roaming' = 'local', -): string => { - const devhome = getDevhome(); - if (os.platform() === 'win32') { - return path.join( - devhome, - 'AppData', - type === 'local' ? 'Local' : 'Roaming', - 'Docker', - ); - } - if (os.platform() === 'linux') { - return path.join(devhome, '.docker', 'desktop'); - } - if (os.platform() === 'darwin') { - return path.join( - devhome, - 'Library', - 'Containers', - 'com.docker.docker', - 'Data', - ); - } - - throw new Error('Unrecognized platform'); -} export function getBackendSocketByPlatform(): string { switch (os.platform()) { diff --git a/src/utils/promptRunner.ts b/src/utils/promptRunner.ts index 47b862b..1445266 100644 --- a/src/utils/promptRunner.ts +++ b/src/utils/promptRunner.ts @@ -3,7 +3,7 @@ import { CancellationToken, commands, window, workspace } from "vscode"; import { setThreadId } from "../commands/setThreadId"; const output = window.createOutputChannel("Docker Labs: AI Tools"); -export const getRunArgs = async (promptRef: string, projectDir: string, username: string, platform: string, pat: string, render = false) => { +export const getRunArgs = async (promptRef: string, projectDir: string, username: string, platform: string, render = false) => { const isLocal = promptRef.startsWith('local://'); const isMarkdown = promptRef.toLowerCase().endsWith('.md'); const threadId = await commands.executeCommand>('docker.labs-ai-tools-vscode.thread-id', false) @@ -35,7 +35,6 @@ export const getRunArgs = async (promptRef: string, projectDir: string, username "--platform", platform, ...promptArgs, '--jsonrpc', - ...(pat ? ['--pat', pat] : []), ...(threadId ? ['--thread-id', threadId] : []), ]; @@ -119,8 +118,8 @@ const runAndStream = async (command: string, args: string[], callback: (json: an }); }; -export const spawnPromptImage = async (promptArg: string, projectDir: string, username: string, platform: string, pat: string, callback: (json: any) => Promise, token: CancellationToken) => { - const args = await getRunArgs(promptArg!, projectDir!, username, platform, pat); +export const spawnPromptImage = async (promptArg: string, projectDir: string, username: string, platform: string, callback: (json: any) => Promise, token: CancellationToken) => { + const args = await getRunArgs(promptArg!, projectDir!, username, platform); callback({ method: 'message', params: { debug: `Running ${args.join(' ')}` } }); return runAndStream("docker", args, callback, token); };