Skip to content

Commit

Permalink
Create output channel for debug, fix headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinMcNeil committed Oct 28, 2024
1 parent 7d1959e commit 3f27824
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/commands/runPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { verifyHasOpenAIKey } from "./setOpenAIKey";
import { getCredential } from "../utils/credential";
import { setProjectDir } from "./setProjectDir";
import { postToBackendSocket } from "../utils/ddSocket";
import { extensionOutput } from "../extension";

type PromptOption = 'local-dir' | 'local-file' | 'remote';

Expand Down Expand Up @@ -169,6 +170,7 @@ export const runPrompt: (secrets: vscode.SecretStorage, mode: PromptOption) => v
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 || 'vscode-user', Password, process.platform, async (json) => {
extensionOutput.appendLine(JSON.stringify(json))

Check warning on line 173 in src/commands/runPrompt.ts

View workflow job for this annotation

GitHub Actions / test

Missing semicolon
switch (json.method) {
case 'functions':
const { id, function: { arguments: args } } = json.params;
Expand All @@ -195,7 +197,7 @@ export const runPrompt: (secrets: vscode.SecretStorage, mode: PromptOption) => v
await writeToEditor(`${header} ROLE ${role}${content ? ` (${content})` : ''}\n\n`);
break;
case 'functions-done':
await writeToEditor(json.params.content);
await writeToEditor(json.params.content+'\n\n');
break;
case 'message':
await writeToEditor(json.params.content);
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export const extensionId = 'docker.labs-ai-tools-vscode';

export const packageJSON = vscode.extensions.getExtension(extensionId)?.packageJSON;

export const extensionOutput = vscode.window.createOutputChannel('Docker Labs AI', 'json')


const getLatestVersion = async () => {
const resp = (await fetch(
Expand Down
3 changes: 2 additions & 1 deletion src/utils/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const notifications = {
message: new rpc.NotificationType<{ content: string }>('message'),
error: new rpc.NotificationType<{ content: string }>('error'),
functions: new rpc.NotificationType<{ function: { arguments: string, name: string }, id: string }>('functions'),
functionsDone: new rpc.NotificationType<{ id: string, function: { name: string, arguments: string } }>('functions-done'),
"functions-done": new rpc.NotificationType<{ id: string, function: { name: string, arguments: string } }>('functions-done'),
start: new rpc.NotificationType<{ id: string, function: { name: string, arguments: string } }>('start'),
}
24 changes: 12 additions & 12 deletions src/utils/promptRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { CancellationToken, commands, window, workspace } from "vscode";
import { setThreadId } from "../commands/setThreadId";
import * as rpc from 'vscode-jsonrpc/node';
import { notifications } from "./notifications";

const output = window.createOutputChannel("Docker Labs: AI Tools");
import { extensionOutput } from "../extension";

export const getRunArgs = async (promptRef: string, projectDir: string, username: string, pat: string, platform: string, render = false) => {
const isLocal = promptRef.startsWith('local://');
Expand Down Expand Up @@ -77,10 +76,10 @@ export const spawnPromptImage = async (promptArg: string, projectDir: string, us
}
}

connection.onNotification(notifications.message, (params) => pushNotification('message', params));
connection.onNotification(notifications.error, (params) => pushNotification('error', params));
connection.onNotification(notifications.functions, (params) => pushNotification('functions', params));
connection.onNotification(notifications.functionsDone, (params) => pushNotification('functions-done', params));
for (const [type, properties] of Object.entries(notifications)){
// @ts-expect-error
connection.onNotification(properties, (params)=> pushNotification(type, params))
}

connection.listen();

Expand All @@ -95,29 +94,30 @@ export const spawnPromptImage = async (promptArg: string, projectDir: string, us
export const writeKeyToVolume = async (key: string) => {

const args1 = ["pull", "vonwig/function_write_files"];

const args2 = [
"run",
"-v",
"-v", "openai_key:/secret",
"--rm",
"openai_key:/secret",
"--workdir", "/secret",
"vonwig/function_write_files",
`'` + JSON.stringify({ files: [{ path: ".openai-api-key", content: key, executable: false }] }) + `'`
];

const child1 = spawn("docker", args1);

child1.stdout.on('data', (data) => {
output.appendLine(data.toString());
extensionOutput.appendLine(data.toString());
});
child1.stderr.on('data', (data) => {
output.appendLine(data.toString());
extensionOutput.appendLine(data.toString());
});

const child2 = spawn("docker", args2);
child2.stdout.on('data', (data) => {
output.appendLine(data.toString());
extensionOutput.appendLine(data.toString());
});
child2.stderr.on('data', (data) => {
output.appendLine(data.toString());
extensionOutput.appendLine(data.toString());
});
};

0 comments on commit 3f27824

Please sign in to comment.