Skip to content

Commit d238bc9

Browse files
authored
fix: show file picker for assistant with mime types (#1763)
* fix: show file picker for assistant with mime types closes #1652 * fix: lint
1 parent 049d32e commit d238bc9

File tree

1 file changed

+50
-41
lines changed

1 file changed

+50
-41
lines changed

src/lib/components/chat/ChatInput.svelte

+50-41
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@
150150
![documentParserToolId, imageGenToolId, webSearchToolId, fetchUrlToolId].includes(t._id)
151151
) satisfies ToolFront[]
152152
);
153+
154+
let showWebSearch = $derived(!assistant);
155+
let showImageGen = $derived(modelHasTools && !assistant);
156+
let showFileUpload = $derived((modelIsMultimodal || modelHasTools) && mimeTypes.length > 0);
157+
let showExtraTools = $derived(modelHasTools && !assistant);
158+
159+
let showNoTools = $derived(!showWebSearch && !showImageGen && !showFileUpload && !showExtraTools);
153160
</script>
154161

155162
<div class="flex min-h-full flex-1 flex-col" onpaste={onPaste}>
@@ -175,47 +182,51 @@
175182
{disabled}
176183
></textarea>
177184

178-
{#if !assistant}
185+
{#if !showNoTools}
179186
<div
180-
class="scrollbar-custom -ml-0.5 flex max-w-[calc(100%-40px)] flex-wrap items-center justify-start gap-2.5 px-3 pb-2.5 pt-1.5 text-gray-500 dark:text-gray-400 max-md:flex-nowrap max-md:overflow-x-auto sm:gap-2"
187+
class={[
188+
"scrollbar-custom -ml-0.5 flex max-w-[calc(100%-40px)] flex-wrap items-center justify-start gap-2.5 px-3 pb-2.5 pt-1.5 text-gray-500 dark:text-gray-400 max-md:flex-nowrap max-md:overflow-x-auto sm:gap-2",
189+
]}
181190
>
182-
<HoverTooltip
183-
label="Search the web"
184-
position="top"
185-
TooltipClassNames="text-xs !text-left !w-auto whitespace-nowrap !py-1 !mb-0 max-sm:hidden {webSearchIsOn
186-
? 'hidden'
187-
: ''}"
188-
>
189-
<button
190-
class="base-tool"
191-
class:active-tool={webSearchIsOn}
192-
disabled={loading}
193-
onclick={async (e) => {
194-
e.preventDefault();
195-
if (modelHasTools) {
196-
if (webSearchIsOn) {
197-
await settings.instantSet({
198-
tools: ($settings.tools ?? []).filter(
199-
(t) => t !== webSearchToolId && t !== fetchUrlToolId
200-
),
201-
});
191+
{#if showWebSearch}
192+
<HoverTooltip
193+
label="Search the web"
194+
position="top"
195+
TooltipClassNames="text-xs !text-left !w-auto whitespace-nowrap !py-1 !mb-0 max-sm:hidden {webSearchIsOn
196+
? 'hidden'
197+
: ''}"
198+
>
199+
<button
200+
class="base-tool"
201+
class:active-tool={webSearchIsOn}
202+
disabled={loading}
203+
onclick={async (e) => {
204+
e.preventDefault();
205+
if (modelHasTools) {
206+
if (webSearchIsOn) {
207+
await settings.instantSet({
208+
tools: ($settings.tools ?? []).filter(
209+
(t) => t !== webSearchToolId && t !== fetchUrlToolId
210+
),
211+
});
212+
} else {
213+
await settings.instantSet({
214+
tools: [...($settings.tools ?? []), webSearchToolId, fetchUrlToolId],
215+
});
216+
}
202217
} else {
203-
await settings.instantSet({
204-
tools: [...($settings.tools ?? []), webSearchToolId, fetchUrlToolId],
205-
});
218+
$webSearchParameters.useSearch = !webSearchIsOn;
206219
}
207-
} else {
208-
$webSearchParameters.useSearch = !webSearchIsOn;
209-
}
210-
}}
211-
>
212-
<IconInternet classNames="text-xl" />
213-
{#if webSearchIsOn}
214-
Search
215-
{/if}
216-
</button>
217-
</HoverTooltip>
218-
{#if modelHasTools}
220+
}}
221+
>
222+
<IconInternet classNames="text-xl" />
223+
{#if webSearchIsOn}
224+
Search
225+
{/if}
226+
</button>
227+
</HoverTooltip>
228+
{/if}
229+
{#if showImageGen}
219230
<HoverTooltip
220231
label="Generate images"
221232
position="top"
@@ -249,7 +260,7 @@
249260
</button>
250261
</HoverTooltip>
251262
{/if}
252-
{#if modelIsMultimodal || modelHasTools}
263+
{#if showFileUpload}
253264
{@const mimeTypesString = mimeTypes
254265
.map((m) => {
255266
// if the mime type ends in *, grab the first part so image/* becomes image
@@ -311,7 +322,7 @@
311322
</HoverTooltip>
312323
{/if}
313324
{/if}
314-
{#if modelHasTools}
325+
{#if showExtraTools}
315326
{#each extraTools as tool}
316327
<button
317328
class="active-tool base-tool"
@@ -327,8 +338,6 @@
327338
{tool.displayName}
328339
</button>
329340
{/each}
330-
{/if}
331-
{#if modelHasTools}
332341
<HoverTooltip
333342
label="Browse more tools"
334343
position="right"

0 commit comments

Comments
 (0)