feat(vision): add vision chat mode

- Add new "vision" chat mode to the application
- Implement the `visionChatMode` function to handle vision-based chat interactions
- Update the UI to include a new button to toggle the vision chat mode
- Add new translations for the "vision" chat mode tooltip
- Disable certain UI elements when the vision chat mode is active
This commit is contained in:
n4ze3m
2024-11-23 14:04:57 +05:30
parent edc5380a76
commit 2c12b17dda
5 changed files with 368 additions and 47 deletions

View File

@@ -0,0 +1,46 @@
const captureVisibleTab = () => {
const result = new Promise<string>((resolve) => {
if (import.meta.env.BROWSER === "chrome") {
chrome.tabs.query({ active: true, currentWindow: true }, async (tabs) => {
const tab = tabs[0]
chrome.tabs.captureVisibleTab(null, { format: "png" }, (dataUrl) => {
resolve(dataUrl)
})
})
} else {
browser.tabs
.query({ active: true, currentWindow: true })
.then(async (tabs) => {
const dataUrl = (await Promise.race([
browser.tabs.captureVisibleTab(null, { format: "png" }),
new Promise((_, reject) =>
setTimeout(
() => reject(new Error("Screenshot capture timed out")),
10000
)
)
])) as string
resolve(dataUrl)
})
}
})
return result
}
export const getScreenshotFromCurrentTab = async () => {
try {
const screenshotDataUrl = await captureVisibleTab()
return {
success: true,
screenshot: screenshotDataUrl,
error: null
}
} catch (error) {
return {
success: false,
screenshot: null,
error:
error instanceof Error ? error.message : "Failed to capture screenshot"
}
}
}