Skip to content

Commit

Permalink
added invalid flow, commands updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lazToum committed Dec 3, 2024
1 parent b27ba15 commit 0ee2d36
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 9 deletions.
1 change: 1 addition & 0 deletions examples/invalid.waldiez
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"flow","name":"Waldiez flow","description":"A waldiez flow","tags":[],"requirements":[],"storageId":"3Bl1GbcJVel97pVyYpABSAT33yd9RgOl","createdAt":"2024-12-03T09:16:35.586Z","updatedAt":"2024-12-03T09:16:35.852Z","data":{"nodes":[{"id":"wa-1733216964965ynIanmdz1Q7H5zUHT0_2l","type":"agent","position":{"x":345,"y":435},"hidden":false,"measured":{"width":206,"height":214}},{"id":"wa-1733216966590MqSYSjiSVPXCflTfkNt8D","type":"agent","position":{"x":960,"y":375},"hidden":false,"measured":{"width":206,"height":214}},{"id":"wa-1733216968287fCzQubRx3-Om33Lng8ELx","type":"agent","position":{"x":705,"y":885},"hidden":false,"measured":{"width":206,"height":214}}],"edges":[{"id":"we-1733216970638XLRwEoVQ21OgwQBRgvrt6","source":"wa-1733216964965ynIanmdz1Q7H5zUHT0_2l","target":"wa-1733216966590MqSYSjiSVPXCflTfkNt8D","type":"chat","animated":false,"selected":true,"markerEnd":{"type":"arrowclosed","color":"#bc76f5","width":10,"height":10},"style":{"stroke":"#bc76f5","strokeWidth":3}}],"viewport":{"x":222,"y":-68,"zoom":1},"agents":{"users":[{"id":"wa-1733216964965ynIanmdz1Q7H5zUHT0_2l","type":"agent","agentType":"user","name":"User","description":"A user proxy agent","tags":[],"requirements":[],"createdAt":"2024-12-03T09:09:24.965Z","updatedAt":"2024-12-03T09:09:24.965Z","data":{"systemMessage":null,"humanInputMode":"ALWAYS","codeExecutionConfig":false,"agentDefaultAutoReply":null,"maxConsecutiveAutoReply":null,"termination":{"type":"none","keywords":[],"criterion":null,"methodContent":null},"teachability":{"enabled":false,"verbosity":0,"resetDb":false,"recallThreshold":0,"maxMumRetrievals":0},"modelIds":[],"skills":[],"parentId":null,"nestedChats":[]}}],"assistants":[{"id":"wa-1733216966590MqSYSjiSVPXCflTfkNt8D","type":"agent","agentType":"assistant","name":"Assistant","description":"An assistant agent","tags":[],"requirements":[],"createdAt":"2024-12-03T09:09:26.591Z","updatedAt":"2024-12-03T09:09:26.591Z","data":{"systemMessage":null,"humanInputMode":"NEVER","codeExecutionConfig":false,"agentDefaultAutoReply":null,"maxConsecutiveAutoReply":null,"termination":{"type":"none","keywords":[],"criterion":null,"methodContent":null},"teachability":{"enabled":false,"verbosity":0,"resetDb":false,"recallThreshold":0,"maxMumRetrievals":0},"modelIds":[],"skills":[],"parentId":null,"nestedChats":[]}},{"id":"wa-1733216968287fCzQubRx3-Om33Lng8ELx","type":"agent","agentType":"assistant","name":"Assistant","description":"An assistant agent","tags":[],"requirements":[],"createdAt":"2024-12-03T09:09:28.288Z","updatedAt":"2024-12-03T09:09:28.288Z","data":{"systemMessage":null,"humanInputMode":"NEVER","codeExecutionConfig":false,"agentDefaultAutoReply":null,"maxConsecutiveAutoReply":null,"termination":{"type":"none","keywords":[],"criterion":null,"methodContent":null},"teachability":{"enabled":false,"verbosity":0,"resetDb":false,"recallThreshold":0,"maxMumRetrievals":0},"modelIds":[],"skills":[],"parentId":null,"nestedChats":[]}}],"managers":[],"rag_users":[]},"models":[],"skills":[],"chats":[{"id":"we-1733216970638XLRwEoVQ21OgwQBRgvrt6","data":{"source":"wa-1733216964965ynIanmdz1Q7H5zUHT0_2l","target":"wa-1733216966590MqSYSjiSVPXCflTfkNt8D","name":"User => Assistant","order":1,"description":"New connection","position":1,"clearHistory":true,"maxTurns":null,"message":{"type":"none","use_carryover":false,"content":null,"context":{}},"nestedChat":{"message":null,"reply":null},"summary":{"method":"last_msg","prompt":"","args":{}}}}]}}
2 changes: 1 addition & 1 deletion src/host/commands/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const convertFlow = async (
const to = extension === '.py' ? 'Python' : 'Jupyter Notebook';

// Show progress notification while performing the conversion
vscode.window.withProgress(
return vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: `Converting flow to ${to}`
Expand Down
10 changes: 7 additions & 3 deletions src/host/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const registerCommands = async (
CONVERT_TO_PYTHON,
async (resource: vscode.Uri) => {
traceInfo('Converting flow to Python');
await convertFlow(converter, resource, '.py');
return await convertFlow(converter, resource, '.py');
}
);

Expand All @@ -36,15 +36,19 @@ export const registerCommands = async (
CONVERT_TO_IPYNB,
async (resource: vscode.Uri) => {
traceInfo('Converting flow to Jupyter Notebook');
await convertFlow(converter, resource, '.ipynb');
return await convertFlow(converter, resource, '.ipynb');
}
);

// Register command to run a flow
const runWaldiezFlow = vscode.commands.registerCommand(
RUN_FLOW,
async (resource: vscode.Uri) => {
await runFlow(resource, runner);
try {
return await runFlow(resource, runner);
} catch (error) {
traceInfo('Failed to run flow', error);
}
}
);

Expand Down
11 changes: 10 additions & 1 deletion src/host/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ export const runFlow = async (resource: vscode.Uri, runner: FlowRunner) => {
});
});
};
await runner.run(resource, waitForInput);
return new Promise<void>((resolve, reject) => {
runner
.run(resource, waitForInput)
.then(() => {
resolve();
})
.catch(error => {
reject(error);
});
});
};
function getInputWebviewContent(previousMessages: string[], prompt: string) {
return `
Expand Down
2 changes: 1 addition & 1 deletion src/host/flow/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class FlowRunner extends vscode.Disposable {
this._running = true;
clearOutput();
showOutput();
vscode.window.withProgress(
return vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: 'Running waldiez flow',
Expand Down
49 changes: 46 additions & 3 deletions src/test/suite/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ suite('Extension Test Suite', () => {
undefined,
'Command waldiez.vscode.toPython did not execute correctly'
);
await new Promise(resolve => setTimeout(resolve, 5000));
const pythonFile = vscode.Uri.joinPath(
workspaceFolder.uri,
'simple.py'
);
assert.ok(
await vscode.workspace.fs.stat(pythonFile),
'Python file not found'
);
vscode.workspace.fs.delete(pythonFile);
});
test('Command waldiez.vscode.toIpynb should be executable', async () => {
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
Expand All @@ -50,7 +58,15 @@ suite('Extension Test Suite', () => {
undefined,
'Command waldiez.vscode.toIpynb did not execute correctly'
);
await new Promise(resolve => setTimeout(resolve, 5000));
const ipynbFile = vscode.Uri.joinPath(
workspaceFolder.uri,
'simple.ipynb'
);
assert.ok(
await vscode.workspace.fs.stat(ipynbFile),
'Jupyter Notebook file not found'
);
vscode.workspace.fs.delete(ipynbFile);
});
test('Command waldiez.vscode.run should be executable', async () => {
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
Expand All @@ -64,6 +80,33 @@ suite('Extension Test Suite', () => {
undefined,
'Command waldiez.vscode.run did not execute correctly'
);
await new Promise(resolve => setTimeout(resolve, 5000));
const output_folder = vscode.Uri.joinPath(
workspaceFolder.uri,
'waldiez_out'
);
assert.ok(
await vscode.workspace.fs.stat(output_folder),
'Output folder not found'
);
vscode.workspace.fs.delete(output_folder, { recursive: true });
});
test('It should not convert an invalid .waldiez file', async () => {
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
assert.ok(workspaceFolder, 'No workspace folder found');
await vscode.commands.executeCommand(
'waldiez.vscode.toPython',
vscode.Uri.joinPath(workspaceFolder.uri, 'invalid.waldiez')
);
const pythonFile = vscode.Uri.joinPath(
workspaceFolder.uri,
'invalid.py'
);
const pythonFileExists = await vscode.workspace.fs
.stat(pythonFile)
.then(
() => true,
() => false
);
assert.strictEqual(pythonFileExists, false, 'Python file found');
});
});

0 comments on commit 0ee2d36

Please sign in to comment.