Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove credential check & pat #39

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/commands/runPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<string, vscode.Range> = {};
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) {
Expand Down
31 changes: 0 additions & 31 deletions src/utils/credential.ts

This file was deleted.

33 changes: 0 additions & 33 deletions src/utils/ddSocket.ts
Original file line number Diff line number Diff line change
@@ -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()) {
Expand Down
7 changes: 3 additions & 4 deletions src/utils/promptRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReturnType<typeof setThreadId>>('docker.labs-ai-tools-vscode.thread-id', false)
Expand Down Expand Up @@ -35,7 +35,6 @@ export const getRunArgs = async (promptRef: string, projectDir: string, username
"--platform", platform,
...promptArgs,
'--jsonrpc',
...(pat ? ['--pat', pat] : []),
...(threadId ? ['--thread-id', threadId] : []),
];

Expand Down Expand Up @@ -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<void>, 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<void>, token: CancellationToken) => {
const args = await getRunArgs(promptArg!, projectDir!, username, platform);
callback({ method: 'message', params: { debug: `Running ${args.join(' ')}` } });
return runAndStream("docker", args, callback, token);
};
Expand Down
Loading