-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/web search #27
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ab556b1
feat: add web search functionality and related settings
Louis-7 c5bc91a
feat: implement external URL handling and web sources display
Louis-7 935717e
fix: update request builders to handle token limits for web search re…
Louis-7 f668f95
docs: clarify streaming annotation handling in extractOpenAISources f…
Louis-7 1f23dc6
feat: enhance OllamaProvider to support reasoning and thinking features
Louis-7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,126 @@ | ||
| import { useState } from 'react'; | ||
| import { Drawer, DrawerContent, DrawerHeader, DrawerBody } from '@heroui/drawer'; | ||
| import { LuGlobe, LuExternalLink } from 'react-icons/lu'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { ChatSource } from '@/types/chat'; | ||
|
|
||
| interface MessageWebSourcesProps { | ||
| sources: ChatSource[]; | ||
| } | ||
|
|
||
| function extractHostname(url: string): string { | ||
| try { | ||
| return new URL(url).hostname.replace(/^www\./, ''); | ||
| } catch { | ||
| return url; | ||
| } | ||
| } | ||
|
|
||
| const PILL_COLORS = [ | ||
| 'bg-blue-500', | ||
| 'bg-emerald-500', | ||
| 'bg-amber-500', | ||
| 'bg-rose-500', | ||
| 'bg-violet-500', | ||
| 'bg-cyan-500', | ||
| ]; | ||
|
|
||
| function colorForIndex(i: number): string { | ||
| return PILL_COLORS[i % PILL_COLORS.length]; | ||
| } | ||
|
|
||
| function openUrl(url: string) { | ||
| if (window.electronAPI?.openExternalUrl) { | ||
| window.electronAPI.openExternalUrl(url); | ||
| } else { | ||
| window.open(url, '_blank', 'noopener'); | ||
| } | ||
| } | ||
|
|
||
| export default function MessageWebSources({ sources }: MessageWebSourcesProps) { | ||
| const [isOpen, setIsOpen] = useState(false); | ||
| const { t } = useTranslation(); | ||
|
|
||
| if (!sources || sources.length === 0) return null; | ||
|
|
||
| const uniqueHosts = [...new Set(sources.map((s) => extractHostname(s.url)))]; | ||
| const previewCount = Math.min(uniqueHosts.length, 3); | ||
|
|
||
| return ( | ||
| <> | ||
| {/* Pill trigger */} | ||
| <button | ||
| type="button" | ||
| onClick={() => setIsOpen(true)} | ||
| className="mt-2 inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full | ||
| bg-default-100 hover:bg-default-200 transition-colors | ||
| text-xs text-default-600 cursor-pointer select-none" | ||
| aria-label={t('chat.sources')} | ||
| > | ||
| {/* Stacked host indicators */} | ||
| <span className="flex -space-x-1.5"> | ||
| {uniqueHosts.slice(0, previewCount).map((host, i) => ( | ||
| <span | ||
| key={host} | ||
| className={`inline-flex items-center justify-center w-4 h-4 rounded-full | ||
| ring-1 ring-background text-[8px] font-bold text-white | ||
| ${colorForIndex(i)}`} | ||
| title={host} | ||
| > | ||
| {host.charAt(0).toUpperCase()} | ||
| </span> | ||
| ))} | ||
| </span> | ||
| <span className="font-medium"> | ||
| {t('chat.sources')} · {sources.length} | ||
| </span> | ||
| </button> | ||
|
|
||
| {/* Sources drawer */} | ||
| <Drawer isOpen={isOpen} onClose={() => setIsOpen(false)} placement="right" size="sm"> | ||
| <DrawerContent> | ||
| <DrawerHeader className="flex items-center gap-2 text-base font-semibold"> | ||
| <LuGlobe size={16} /> | ||
| {t('chat.sources')} | ||
| </DrawerHeader> | ||
| <DrawerBody className="px-4 pb-6"> | ||
| <ul className="flex flex-col gap-2"> | ||
| {sources.map((source, i) => { | ||
| const host = extractHostname(source.url); | ||
| return ( | ||
| <li key={`${source.url}-${i}`}> | ||
| <button | ||
| type="button" | ||
| onClick={() => openUrl(source.url)} | ||
| className="w-full text-left flex items-start gap-3 p-3 rounded-xl | ||
| bg-default-50 hover:bg-default-100 transition-colors | ||
| cursor-pointer group" | ||
| > | ||
| <span | ||
| className={`mt-0.5 flex-shrink-0 inline-flex items-center justify-center | ||
| w-6 h-6 rounded-lg text-[10px] font-bold text-white | ||
| ${colorForIndex(i)}`} | ||
| > | ||
| {host.charAt(0).toUpperCase()} | ||
| </span> | ||
| <span className="flex-1 min-w-0"> | ||
| <span className="block text-sm font-medium text-foreground truncate"> | ||
| {source.title || host} | ||
| </span> | ||
| <span className="block text-xs text-default-400 truncate">{host}</span> | ||
| </span> | ||
| <LuExternalLink | ||
| size={14} | ||
| className="mt-1 flex-shrink-0 text-default-300 group-hover:text-default-500 transition-colors" | ||
| /> | ||
| </button> | ||
| </li> | ||
| ); | ||
| })} | ||
| </ul> | ||
| </DrawerBody> | ||
| </DrawerContent> | ||
| </Drawer> | ||
| </> | ||
| ); | ||
| } |
This file contains hidden or 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,35 @@ | ||
| import { useSwitch, VisuallyHidden } from '@heroui/react'; | ||
| import Icon from './Icon'; | ||
|
|
||
| interface WebSearchToggleProps { | ||
| isSelected: boolean; | ||
| onValueChange: (checked: boolean) => void; | ||
| 'aria-label': string; | ||
| } | ||
|
|
||
| export default function WebSearchToggle(props: WebSearchToggleProps) { | ||
| const { Component, slots, isSelected, getBaseProps, getInputProps, getWrapperProps } = | ||
| useSwitch(props); | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-2"> | ||
| <Component {...getBaseProps()}> | ||
| <VisuallyHidden> | ||
| <input {...getInputProps()} aria-label={props['aria-label']} /> | ||
| </VisuallyHidden> | ||
| <div | ||
| {...getWrapperProps()} | ||
| className={slots.wrapper({ | ||
| class: [ | ||
| 'w-8 h-8', | ||
| 'flex items-center justify-center', | ||
| 'rounded-lg bg-default-100 hover:bg-default-200', | ||
| ], | ||
| })} | ||
| > | ||
| <Icon icon="globe" /> | ||
| </div> | ||
| </Component> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.