-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed up a new vercel ai provider (#117)
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const Store = require('electron-store'); | ||
const store = new Store(); | ||
|
||
const Provider = require('./provider'); | ||
|
||
class Vercel extends Provider { | ||
static webviewId = 'webviewVercelAI'; | ||
static fullName = 'Vercel AI Chatbot'; | ||
|
||
static url = 'https://chat.vercel.ai/'; | ||
|
||
static handleInput(input) { | ||
this.getWebview().executeJavaScript(` | ||
var inputElement = document.querySelector('textarea[placeholder*="Send a message."]'); // can be "Ask anything" or "Ask follow-up" | ||
var nativeTextAreaValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set; | ||
nativeTextAreaValueSetter.call(inputElement, "${input}"); | ||
var event = new Event('input', { bubbles: true}); | ||
inputElement.dispatchEvent(event); | ||
`); | ||
} | ||
|
||
static handleSubmit(){ | ||
this.getWebview().executeJavaScript(` | ||
var buttons = Array.from(document.querySelectorAll('button[type="submit"]')); | ||
var buttonsWithSrOnly = buttons.filter(button => { | ||
var span = button.querySelector('span'); | ||
return span && span.textContent.trim() === 'Send message'; | ||
}); | ||
if (buttonsWithSrOnly.length == 1){ | ||
var button = buttonsWithSrOnly[0]; | ||
button.click(); | ||
} | ||
`) | ||
|
||
} | ||
static handleCss() { | ||
this.getWebview().addEventListener('dom-ready', () => { | ||
// hide message below text input, sidebar, suggestions on new chat | ||
setTimeout(() => { | ||
this.getWebview().executeJavaScript(` | ||
`); | ||
}, 100); | ||
// Hide the "Try asking" segment | ||
setTimeout(() => { | ||
this.getWebview().insertCSS(` | ||
.mt-lg { | ||
display: none; | ||
} | ||
`); | ||
}, 100); | ||
}); | ||
} | ||
|
||
static isEnabled() { | ||
return store.get(`${this.webviewId}Enabled`, true); | ||
} | ||
} | ||
|
||
module.exports = Vercel; |