-
Notifications
You must be signed in to change notification settings - Fork 325
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
Provider modules #32
Provider modules #32
Conversation
@@ -0,0 +1,436 @@ | |||
console.log('interface.js loaded'); | |||
const Store = require('electron-store'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like nodejs imports are fine here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed! Not sure what was going on the other day — imports are working fine so i split out each provider class to it's own file.
interface.js
Outdated
document.addEventListener('paste', (event) => { | ||
event.preventDefault(); | ||
let text = event.clipboardData.getData('text'); | ||
let activeElement = document.activeElement; | ||
let start = activeElement.selectionStart; | ||
let end = activeElement.selectionEnd; | ||
activeElement.value = activeElement.value.slice(0, start) + text + activeElement.value.slice(end); | ||
activeElement.selectionStart = activeElement.selectionEnd = start + text.length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i somewhat worry about overriding paste like this, lets make sure to check it works in the main chat apps
interface.js
Outdated
activeElement.selectionStart = activeElement.selectionEnd = start + text.length; | ||
}); | ||
`); | ||
}.bind(this) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fun js trivia - how to rewrite your function so you dont have to .bind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
() => !
interface.js
Outdated
class OpenAi extends Provider { | ||
static webviewId = 'webviewOAI'; | ||
static webview = document.getElementById('webviewOAI'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prob wanna give it a "display name" too since we'll probably be showing a dropdown
interface.js
Outdated
/* END Providers ------------------------------------------------------------ */ | ||
|
||
/* ========================================================================== */ | ||
/* Create Panes */ | ||
/* ========================================================================== */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good comments
interface.js
Outdated
let paneProviders = [Bard, OpenAi, Claude]; | ||
|
||
// Create the panes based on the mapping | ||
paneProviders.forEach(provider => { | ||
|
||
const providerPane = document.getElementById(`${provider.name.toLowerCase()}Pane`); | ||
providerPane.classList.remove('hidden'); | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wonder how this will look with a 4th provider.. (Bing)
interface.js
Outdated
// Adjust styling for enabled providers | ||
Bard.handleCss(); | ||
OpenAi.handleCss(); | ||
Claude.handleCss(Claude.webview); | ||
|
||
// fix double-pasting inside webviews | ||
OpenAi.setupCustomPasteBehavior(); | ||
Bard.setupCustomPasteBehavior(); | ||
Claude.setupCustomPasteBehavior(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feels like "setup code" that should belong higher up, because the other stuff directly above this is oninput and onsubmit code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good so far!
@swyxio I think with these changes we're very close (assuming it's working on your end) — i noticed another PR open for smoltalk is started but not too much progress yet. This one feels like a significant enough refactor that you might want to merge it in sooner rather than later since modularizing the providers required touching so many parts of the app. Once it's merged in, I can submit another PR for additional providers, without blocking your/others' work on other parts of the app. Resizing and Keyboard Shortcuts:
Moved Preferences to Context Menu:
If you can clarify the Cmd 1/2/3 behavior I can push a final change to get this merged! This feels like a big update! |
@zleman1593 can you try running @swyxio happy to remove this for the release, too, but having terminal logging for the render process has been super helpful so probably makes sense to at least keep in the dev environment! |
I did both of those steps before publishing the above. Unfortunately, neither worked. |
@zleman1593 thanks for flagging this -- I can reproduce this and will update here once we have a fix! |
@zleman1593 when you have a second can you clone this latest version and see if it's working for you? it looks like it was that the package was missing from package.json |
That worked. |
@seanoliver amazing - grabby bars works! i only see 3 windows, not 4. what is the default supposed to be? smol bug with cmd+1/2/3/A - also refreshes the screen for some reason. cmd+1/2/3 basically shrinks one window and maximizes one window to one specific chat, or cmd+A to restore equal width for all chats. lastly, checking these disable buttons while they are actually enabled is unintuitive. would massage the wording or flip the checkbox state here |
@swyxio Ah thanks I realize now I could have just run the last release version to confirm the behavior!
Lmk if this is working for you! If so I think we can ship Bing and I'll start a branch to add more providers. 🙌 |
wooohoo! |
@swyxio Not ready for a PR yet but wanted to share some direction in case I'm taking this too far haha. I refactored the provider-specific code into subclasses so that we can more easily swap one in out for another.
You probably already know this but since I'm new to Electron I found out that we need to keep JS in the render process to access the providers' DOMs. So we can't use Node.js imports/requires to organize the code in separate files. Argh.
If this directionally looks good my next steps will be to add another provider and a setting that saves you preferred providers to local disk. Also the grabby bars between panes aren't working on this version so I'll fix that before submitting.