-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* do not use fetch event source directly * refactor * fix type errors * fix command menu * initial image support * render images back to the user * add more image processing * update image button style * update styling * tauri support for images
- Loading branch information
1 parent
ab730ab
commit fb51793
Showing
15 changed files
with
601 additions
and
196 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<script lang="ts"> | ||
import { XCircle, Image } from "lucide-svelte"; | ||
import { attachedImage } from "$lib/stores/stores"; | ||
import { processImageForAI } from "$lib/utils"; | ||
import { toast } from "$lib/toast"; | ||
import { getSystem } from "$lib/gui"; | ||
const sys = getSystem(); | ||
async function handleFileSelect(e: MouseEvent) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
try { | ||
const result = await sys.chooseAndOpenImageFile(); | ||
if (!result) return; | ||
const file = new File([result.data], result.name, { | ||
type: result.name.endsWith(".svg") ? "image/svg+xml" : "image/jpeg", // fallback type | ||
}); | ||
const processed = await processImageForAI(file); | ||
attachedImage.set(processed); | ||
} catch (error) { | ||
console.error("Error processing file:", error); | ||
toast({ | ||
type: "error", | ||
title: "Error processing image", | ||
message: | ||
error instanceof Error ? error.message : "Could not process the selected image file", | ||
}); | ||
} | ||
} | ||
</script> | ||
|
||
<div class="flex items-end pb-[2px] space-x-2 h-auto pr-[2px] border-r border-zinc-700 relative"> | ||
<button | ||
type="button" | ||
class="cursor-pointer p-2 hover:bg-zinc-700 rounded-lg !ml-[2px]" | ||
on:click={handleFileSelect} | ||
> | ||
<Image class="w-5 h-5" /> | ||
</button> | ||
|
||
{#if $attachedImage} | ||
<div class="absolute left-full bottom-[calc(100%+8px)] w-20 h-20 drop-shadow-lg"> | ||
<img | ||
src={$attachedImage.base64} | ||
alt="Attached" | ||
class="w-full h-full object-cover rounded-lg" | ||
/> | ||
<button | ||
class="absolute -top-2 -right-2 bg-zinc-800 rounded-full" | ||
on:click={() => attachedImage.set(null)} | ||
> | ||
<XCircle class="w-4 h-4" /> | ||
</button> | ||
</div> | ||
{/if} | ||
</div> |
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 |
---|---|---|
@@ -1,23 +1,34 @@ | ||
<script lang="ts"> | ||
import { Command as CommandPrimitive } from "cmdk-sv"; | ||
import { Search } from "lucide-svelte"; | ||
import { cn } from "$lib/utils"; | ||
import { Command as CommandPrimitive } from "cmdk-sv"; | ||
import { Search } from "lucide-svelte"; | ||
import { cn } from "$lib/utils"; | ||
import { createEventDispatcher } from "svelte"; | ||
type $$Props = CommandPrimitive.InputProps; | ||
type $$Props = CommandPrimitive.InputProps; | ||
let className: string | undefined | null = undefined; | ||
export { className as class }; | ||
export let value: string = ""; | ||
let className: string | undefined | null = undefined; | ||
export { className as class }; | ||
export let value: string = ""; | ||
const dispatch = createEventDispatcher(); | ||
function handleInput(event: Event) { | ||
const target = event.target as HTMLInputElement; | ||
value = target.value; | ||
dispatch("input", value); | ||
} | ||
</script> | ||
|
||
<div class="flex items-center border-b px-2" data-cmdk-input-wrapper=""> | ||
<Search class="mr-2 h-4 w-4 shrink-0 opacity-50" /> | ||
<CommandPrimitive.Input | ||
class={cn( | ||
"flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50", | ||
className | ||
)} | ||
{...$$restProps} | ||
bind:value | ||
/> | ||
<div class="flex items-center border-b px-3" data-cmdk-input-wrapper=""> | ||
<Search class="mr-2 h-4 w-4 shrink-0 opacity-50" /> | ||
<input | ||
class={cn( | ||
"flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50", | ||
className | ||
)} | ||
type="text" | ||
bind:value | ||
on:input={handleInput} | ||
{...$$restProps} | ||
/> | ||
</div> |
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,35 @@ | ||
/** | ||
* Calculate a score for how well a string matches a search query. | ||
* Higher scores indicate better matches. | ||
*/ | ||
export function commandScore(str: string, query: string): number { | ||
if (!str || !query) return 0; | ||
|
||
str = str.toLowerCase(); | ||
query = query.toLowerCase(); | ||
|
||
// Exact match gets highest score | ||
if (str === query) return 1; | ||
|
||
// Check if string starts with query | ||
if (str.startsWith(query)) return 0.8; | ||
|
||
// Check if string contains query | ||
if (str.includes(query)) return 0.5; | ||
|
||
// Check if all characters in query appear in order in str | ||
let strIndex = 0; | ||
let queryIndex = 0; | ||
|
||
while (strIndex < str.length && queryIndex < query.length) { | ||
if (str[strIndex] === query[queryIndex]) { | ||
queryIndex++; | ||
} | ||
strIndex++; | ||
} | ||
|
||
// If all characters were found in order, give a lower score | ||
if (queryIndex === query.length) return 0.3; | ||
|
||
return 0; | ||
} |
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 |
---|---|---|
@@ -1,22 +1,29 @@ | ||
<script lang="ts"> | ||
import { Command as CommandPrimitive } from "cmdk-sv"; | ||
import { cn } from "$lib/utils"; | ||
import { Command as CommandPrimitive } from "cmdk-sv"; | ||
import { cn } from "$lib/utils"; | ||
import { createEventDispatcher } from "svelte"; | ||
type $$Props = CommandPrimitive.CommandProps; | ||
type $$Props = CommandPrimitive.CommandProps; | ||
export let value: $$Props["value"] = undefined; | ||
let className: string | undefined | null = undefined; | ||
export { className as class }; | ||
export let value: string = ""; | ||
let className: string | undefined | null = undefined; | ||
export { className as class }; | ||
const dispatch = createEventDispatcher(); | ||
function handleKeydown(event: CustomEvent<KeyboardEvent>) { | ||
dispatch("keydown", event.detail); | ||
} | ||
</script> | ||
|
||
<CommandPrimitive.Root | ||
class={cn( | ||
"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground", | ||
className | ||
)} | ||
bind:value | ||
{...$$restProps} | ||
class={cn( | ||
"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground", | ||
className | ||
)} | ||
bind:value | ||
{...$$restProps} | ||
on:keydown={handleKeydown} | ||
> | ||
<slot /> | ||
<slot /> | ||
</CommandPrimitive.Root> |
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
Oops, something went wrong.