Skip to content

Commit

Permalink
Added Assistant autoplay option
Browse files Browse the repository at this point in the history
  • Loading branch information
codemakerai-dev committed Jul 8, 2024
1 parent 9fb40cf commit 8b8ef83
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
28 changes: 17 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,41 +108,47 @@
"default": false,
"order": 4
},
"codemaker.enableAssistantActions": {
"description": "Enable assistant contextual operations.",
"codemaker.muteAssistant": {
"description": "Mutes Assistant.",
"type": "boolean",
"default": true,
"order": 5
},
"codemaker.enableAssistantCodeLens": {
"description": "Enable assistant code lens.",
"codemaker.enableAssistantActions": {
"description": "Enable Assistant contextual operations.",
"type": "boolean",
"default": true,
"order": 6
},
"codemaker.enableAssistantCodeLens": {
"description": "Enable Assistant Code Lens.",
"type": "boolean",
"default": true,
"order": 7
},
"codemaker.allowLocalContext": {
"description": "Allow local context search.",
"type": "boolean",
"default": false,
"order": 7
"order": 8
},
"codemaker.enableCodeActions": {
"description": "Enable code actions",
"type": "boolean",
"default": true,
"order": 8
"order": 9
},
"codemaker.enablePredictiveGeneration": {
"description": "Enable predictive generation",
"type": "boolean",
"default": false,
"order": 9
"order": 10
},
"codemaker.enableExtendedSourceContext": {
"description": "Enable extended source context",
"type": "boolean",
"default": false,
"order": 10
"order": 11
},
"codemaker.extendedSourceContextDepth": {
"description": "Extended source context maximum depth",
Expand All @@ -153,18 +159,18 @@
2,
3
],
"order": 11
"order": 12
},
"codemaker.enableSyntaxAutocorrection": {
"description": "Enable syntax autocorrection",
"type": "boolean",
"default": false,
"order": 12
"order": 13
},
"codemaker.endpoint": {
"markdownDescription": "CodeMaker AI Endpoint.",
"type": "string",
"order": 13
"order": 14
}
}
},
Expand Down
13 changes: 10 additions & 3 deletions src/assistant/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@ class AssistantRequestCommand implements ICommand {

try {
const isAssistantActionsEnabled = Configuration.isAssistantActionsEnabled();
const autoplay = !Configuration.isAssistantMuted();

const editor = vscode.window.activeTextEditor;

if (!isAssistantActionsEnabled || !editor || !isFileSupported(editor.document.fileName)) {
const result = await this._codemakerService.assistantCompletion(message.text);
const output = await this._codemakerService.assistantCompletion(message.text);

webviewView.webview.postMessage({
command: CommandType.assistantResponse,
result: result,
result: {
...output,
autoplay
},
});
} else {
const path = editor.document.uri;
Expand All @@ -63,7 +67,10 @@ class AssistantRequestCommand implements ICommand {

webviewView.webview.postMessage({
command: CommandType.assistantResponse,
result: output,
result: {
...output,
autoplay
},
});
}
} catch (error) {
Expand Down
4 changes: 4 additions & 0 deletions src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export class Configuration {
return this.get('codemaker.extendedSourceContextDepth');
}

static isAssistantMuted(): boolean {
return this.get('codemaker.muteAssistant');
}

static isAssistantActionsEnabled(): boolean {
return this.get('codemaker.enableAssistantActions');
}
Expand Down
16 changes: 13 additions & 3 deletions webview/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ function createMessageElement(sender, message) {
controlsElement.appendChild(copyButtonElement);

let audio = null;
equalizerButtonElement.addEventListener('click', function(event) {
function togglePlay() {
if (!audio) {
const input = encodeBase64url(message.message);
audio = new Audio(`${window.speachEndpoint}?input=${input}`);
audio.autoplay = true;
['pause', 'ended'].forEach(event => {
['ended'].forEach(event => {
audio.addEventListener(event, () => {
audio = null;
equalizerButtonElement.src = window.resolveMediaFile("equalizer.svg");
Expand All @@ -168,10 +168,20 @@ function createMessageElement(sender, message) {

equalizerButtonElement.src = window.resolveMediaFile("pause.svg");
} else {
audio.pause();
audio.pause();
audio = null;
equalizerButtonElement.src = window.resolveMediaFile("equalizer.svg");
}
}

equalizerButtonElement.addEventListener('click', function(event) {
togglePlay();
});

if (message.autoplay) {
togglePlay();
}

upVoteButtonElement.addEventListener('click', function(event) {
vscode.postMessage({
command: 'assistantFeedback',
Expand Down

0 comments on commit 8b8ef83

Please sign in to comment.