Spaces:
Sleeping
Sleeping
File size: 22,961 Bytes
8aab1a5 cb5990d 7bf1507 2ec957c 7bf1507 5a5937a 7bf1507 1d87f01 2ec957c 98051f8 3dafcf0 01b06a3 d433b55 cb5990d 241ba68 173b88e 241ba68 df3243b c51ecfb 2a808d7 7bf1507 2a808d7 564e576 fd7f926 cb5990d 388034d 7bf1507 1d87f01 8aab1a5 c99779e 14ef8d0 7bf1507 2c83099 cb5990d c99779e a1a6daf 725337f 70c72fa a0e1d3c a1a6daf cb5990d 7bf1507 a0e1d3c 7bf1507 a0e1d3c cb5990d a1a6daf c202241 a1a6daf 725337f 70c72fa a0e1d3c a1a6daf cb5990d 7bf1507 a0e1d3c cb5990d a1a6daf 725337f a0e1d3c 725337f cb5990d a1a6daf 7bf1507 a1a6daf 89cd532 7bf1507 89cd532 173b88e 241ba68 a1a6daf 241ba68 2a808d7 41370a8 c99779e 01b3b9f c99779e 41370a8 fd7f926 7a0286e fd7f926 41370a8 a1a6daf 7bf1507 cb5990d 7bf1507 a1a6daf 3fb2b9c a1a6daf 241ba68 7bf1507 a1a6daf 5b1a9aa e99e7c2 7bf1507 a0c0a49 7bf1507 a0c0a49 2a808d7 a1a6daf 2a808d7 a1a6daf 2a808d7 1f73dd7 a1a6daf fd7f926 7bf1507 fd7f926 7bf1507 a1a6daf 7bf1507 a1a6daf b104edb a1a6daf 2c83099 7bf1507 d2390f1 7bf1507 d2390f1 3b53c7a d2390f1 7bf1507 8aab1a5 5ddf84d a1a6daf 5ddf84d c6ccfa4 7bf1507 2a808d7 85b38e3 7bf1507 2a808d7 564e576 7bf1507 2a808d7 241ba68 2a808d7 b94a87f cb5990d 70c72fa a0e1d3c cb5990d 70c72fa a0e1d3c cb5990d 70c72fa 6216bfd 388034d 2a808d7 6216bfd 2a808d7 7bf1507 8bafc4a 7bf1507 d433b55 14ef8d0 8bafc4a 7bf1507 8bafc4a 2a808d7 7bf1507 8aab1a5 fa5e19e 4fab3dd 725337f 4fab3dd 725337f 8aab1a5 7bf1507 1796fda 7bf1507 1796fda 7bf1507 2d394d3 c99779e 4fab3dd c99779e 7e82675 564e576 7bf1507 564e576 7e82675 94ed0cf 7bf1507 725337f 7bf1507 173b88e 241ba68 725337f 70c72fa 725337f 241ba68 e9e6405 a1a6daf 2c83099 7bf1507 2c83099 241ba68 e9e6405 fd7f926 241ba68 c99779e 241ba68 a0e1d3c b104edb 241ba68 b104edb 7bf1507 a1a6daf 241ba68 7bf1507 2c83099 241ba68 d492075 241ba68 7bf1507 241ba68 7bf1507 241ba68 0031e51 241ba68 94ed0cf 241ba68 d492075 241ba68 af319d7 8aab1a5 c99779e 7bf1507 c99779e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 |
<script lang="ts">
import type { Message, MessageFile, MetacognitiveEvent, MetacognitiveEventType } from "$lib/types/Message";
import type { MetacognitiveConfig, MetacognitivePromptData } from "$lib/types/Metacognitive";
import { determineMetacognitivePrompt } from "$lib/utils/metacognitiveLogic";
import { onDestroy, tick } from "svelte";
import IconOmni from "$lib/components/icons/IconOmni.svelte";
import CarbonCaretDown from "~icons/carbon/caret-down";
import CarbonDirectionRight from "~icons/carbon/direction-right-01";
import CarbonModel from "~icons/carbon/model";
import ChatInput from "./ChatInput.svelte";
import StopGeneratingBtn from "../StopGeneratingBtn.svelte";
import type { Model } from "$lib/types/Model";
import { page } from "$app/state";
import { goto } from "$app/navigation";
import FileDropzone from "./FileDropzone.svelte";
import RetryBtn from "../RetryBtn.svelte";
import file2base64 from "$lib/utils/file2base64";
import { base } from "$app/paths";
import ContinueBtn from "../ContinueBtn.svelte";
import ChatMessage from "./ChatMessage.svelte";
import { browser } from "$app/environment";
import { snapScrollToBottom } from "$lib/actions/snapScrollToBottom";
import SystemPromptModal from "../SystemPromptModal.svelte";
import ShareConversationModal from "../ShareConversationModal.svelte";
import ChatIntroduction from "./ChatIntroduction.svelte";
import UploadedFile from "./UploadedFile.svelte";
import { useSettingsStore } from "$lib/stores/settings";
import { useMetacognitiveEngine } from "$lib/hooks/useMetacognitiveEngine.svelte";
import ModelSwitch from "./ModelSwitch.svelte";
import { routerExamples } from "$lib/constants/routerExamples";
import type { RouterFollowUp, RouterExample } from "$lib/constants/routerExamples";
import { shareModal } from "$lib/stores/shareModal";
import PersonaSelector from "$lib/components/PersonaSelector.svelte";
import { fly } from "svelte/transition";
import { cubicInOut } from "svelte/easing";
import { loginModalOpen } from "$lib/stores/loginModal";
import { isVirtualKeyboard } from "$lib/utils/isVirtualKeyboard";
import superjson from "superjson";
interface Props {
messages?: Message[];
messagesAlternatives?: Message["id"][][];
loading?: boolean;
pending?: boolean;
shared?: boolean;
currentModel: Model;
models: Model[];
preprompt?: string | undefined;
personaId?: string;
lockedPersonaId?: string;
branchState?: {
messageId: string;
personaId: string;
personaName: string;
} | null;
files?: File[];
metacognitiveConfig?: MetacognitiveConfig;
metacognitiveState?: {
targetFrequency?: number;
lastPromptedAtMessageId?: string | null;
};
onmessage?: (content: string) => void;
onstop?: () => void;
onretry?: (payload: { id: Message["id"]; content?: string; personaId?: string }) => void;
oncontinue?: (payload: { id: Message["id"] }) => void;
onshowAlternateMsg?: (payload: { id: Message["id"] }) => void;
onbranch?: (messageId: string, personaId: string) => void;
onmetacognitivebranch?: (messageId: string, personaId: string, promptData: MetacognitivePromptData) => void;
}
let {
messages = [],
messagesAlternatives = [],
loading = false,
pending = false,
shared = false,
currentModel,
models,
preprompt = undefined,
personaId,
lockedPersonaId,
branchState,
files = $bindable([]),
metacognitiveConfig,
metacognitiveState,
onmessage,
onstop,
onretry,
oncontinue,
onshowAlternateMsg,
onbranch,
onmetacognitivebranch,
}: Props = $props();
let isReadOnly = $derived(!models.some((model) => model.id === currentModel.id));
// Get persona information for single-persona mode
let userSettings = useSettingsStore();
let persona = $derived.by(() => {
if (!personaId) return undefined;
return $userSettings.personas?.find((p) => p.id === personaId);
});
// Compute branch points: messages that other messages branch from
// Map of messageId -> array of persona names that branched from it
let branchPointInfo = $derived.by(() => {
const branchPoints = new Map<string, string[]>();
messages.forEach(msg => {
if (msg.branchedFrom) {
const messageId = msg.branchedFrom.messageId;
const personaName = $userSettings.personas?.find(p => p.id === msg.branchedFrom?.personaId)?.name || msg.branchedFrom.personaId;
if (!branchPoints.has(messageId)) {
branchPoints.set(messageId, []);
}
const personas = branchPoints.get(messageId)!;
if (!personas.includes(personaName)) {
personas.push(personaName);
}
}
});
return branchPoints;
});
const metacognitiveEngine = useMetacognitiveEngine(() => ({
messages,
loading,
pending,
metacognitiveConfig,
metacognitiveState,
userSettings: $userSettings,
onmetacognitivebranch
}));
let activeMetacognitivePrompt = $derived(metacognitiveEngine.activeMetacognitivePrompt);
let message: string = $state("");
let shareModalOpen = $state(false);
let editMsdgId: Message["id"] | null = $state(null);
let pastedLongContent = $state(false);
const handleSubmit = () => {
if (loading) return;
onmessage?.(message);
message = "";
};
let lastTarget: EventTarget | null = null;
let onDrag = $state(false);
const onDragEnter = (e: DragEvent) => {
lastTarget = e.target;
onDrag = true;
};
const onDragLeave = (e: DragEvent) => {
if (e.target === lastTarget) {
onDrag = false;
}
};
const onPaste = (e: ClipboardEvent) => {
const textContent = e.clipboardData?.getData("text");
if (!$settings.directPaste && textContent && textContent.length >= 3984) {
e.preventDefault();
pastedLongContent = true;
setTimeout(() => {
pastedLongContent = false;
}, 1000);
const pastedFile = new File([textContent], "Pasted Content", {
type: "application/vnd.chatui.clipboard",
});
files = [...files, pastedFile];
}
if (!e.clipboardData) {
return;
}
// paste of files
const pastedFiles = Array.from(e.clipboardData.files);
if (pastedFiles.length !== 0) {
e.preventDefault();
// filter based on activeMimeTypes, including wildcards
const filteredFiles = pastedFiles.filter((file) => {
return activeMimeTypes.some((mimeType: string) => {
const [type, subtype] = mimeType.split("/");
const [fileType, fileSubtype] = file.type.split("/");
return (
(type === "*" || fileType === type) && (subtype === "*" || fileSubtype === subtype)
);
});
});
files = [...files, ...filteredFiles];
}
};
let lastMessage = $derived(browser && (messages.at(-1) as Message));
let scrollSignal = $derived.by(() => {
const last = messages.at(-1) as Message | undefined;
return last
? `${last.id}:${last.content.length}:${messages.length}:${loading}:${activeMetacognitivePrompt?.messageId ?? ""}`
: `${messages.length}:0:${loading}:${activeMetacognitivePrompt?.messageId ?? ""}`;
});
let lastIsError = $derived(
lastMessage &&
!loading &&
(lastMessage.from === "user" ||
lastMessage.updates?.findIndex((u) => u.type === "status" && u.status === "error") !== -1)
);
let streamingAssistantMessage = $derived(
(() => {
for (let i = messages.length - 1; i >= 0; i -= 1) {
const candidate = messages[i];
if (candidate.from === "assistant") {
return candidate;
}
}
return undefined;
})()
);
let streamingRouterMetadata = $derived(streamingAssistantMessage?.routerMetadata ?? null);
let streamingRouterModelName = $derived(
streamingRouterMetadata?.model
? (streamingRouterMetadata.model.split("/").pop() ?? streamingRouterMetadata.model)
: ""
);
let showRouterDetails = $state(false);
let routerDetailsTimeout: ReturnType<typeof setTimeout> | undefined;
$effect(() => {
if (!currentModel.isRouter || !loading) {
showRouterDetails = false;
if (routerDetailsTimeout) {
clearTimeout(routerDetailsTimeout);
routerDetailsTimeout = undefined;
}
return;
}
if (routerDetailsTimeout) {
clearTimeout(routerDetailsTimeout);
}
showRouterDetails = false;
routerDetailsTimeout = setTimeout(() => {
showRouterDetails = true;
}, 1000);
});
let sources = $derived(
files?.map<Promise<MessageFile>>((file) =>
file2base64(file).then((value) => ({
type: "base64",
value,
mime: file.type,
name: file.name,
}))
)
);
const unsubscribeShareModal = shareModal.subscribe((value) => {
shareModalOpen = value;
});
onDestroy(() => {
unsubscribeShareModal();
shareModal.close();
if (routerDetailsTimeout) {
clearTimeout(routerDetailsTimeout);
}
});
let chatContainer: HTMLElement | undefined = $state();
async function scrollToBottom() {
await tick();
if (!chatContainer) return;
chatContainer.scrollTop = chatContainer.scrollHeight;
}
// If last message is from user, scroll to bottom
$effect(() => {
if (lastMessage && lastMessage.from === "user") {
scrollToBottom();
}
});
const settings = useSettingsStore();
let hideRouterExamples = $derived($settings.hidePromptExamples?.[currentModel.id] ?? false);
// Respect per‑model multimodal toggle from settings (force enable)
let modelIsMultimodalOverride = $derived($settings.multimodalOverrides?.[currentModel.id]);
let modelIsMultimodal = $derived((modelIsMultimodalOverride ?? currentModel.multimodal) === true);
let activeMimeTypes = $derived(
Array.from(
new Set([
...(modelIsMultimodal ? (currentModel.multimodalAcceptedMimetypes ?? ["image/*"]) : []),
])
)
);
let isFileUploadEnabled = $derived(activeMimeTypes.length > 0);
let focused = $state(false);
let activeRouterExamplePrompt = $state<string | null>(null);
let routerFollowUps = $derived<RouterFollowUp[]>(
activeRouterExamplePrompt
? (routerExamples.find((ex) => ex.prompt === activeRouterExamplePrompt)?.followUps ?? [])
: []
);
let routerUserMessages = $derived(messages.filter((msg) => msg.from === "user"));
let shouldShowRouterFollowUps = $derived(
!message.length &&
activeRouterExamplePrompt &&
routerFollowUps.length > 0 &&
routerUserMessages.length === 1 &&
currentModel.isRouter &&
!hideRouterExamples &&
!loading
);
$effect(() => {
if (!currentModel.isRouter || !messages.length) {
activeRouterExamplePrompt = null;
return;
}
const firstUserMessage = messages.find((msg) => msg.from === "user");
if (!firstUserMessage) {
activeRouterExamplePrompt = null;
return;
}
const match = routerExamples.find((ex) => ex.prompt.trim() === firstUserMessage.content.trim());
activeRouterExamplePrompt = match ? match.prompt : null;
});
function triggerPrompt(prompt: string) {
if (loading) return;
if (page.data.loginRequired) {
$loginModalOpen = true;
return;
}
message = prompt;
handleSubmit();
}
async function startExample(example: RouterExample) {
activeRouterExamplePrompt = example.prompt;
if (browser && example.attachments?.length) {
const loadedFiles: File[] = [];
for (const attachment of example.attachments) {
try {
const response = await fetch(`${base}/${attachment.src}`);
if (!response.ok) continue;
const blob = await response.blob();
const name = attachment.src.split("/").pop() ?? "attachment";
loadedFiles.push(
new File([blob], name, { type: blob.type || "application/octet-stream" })
);
} catch (err) {
console.error("Error loading attachment:", err);
}
}
files = loadedFiles;
}
triggerPrompt(example.prompt);
}
function startFollowUp(followUp: RouterFollowUp) {
triggerPrompt(followUp.prompt);
}
</script>
<svelte:window
ondragenter={onDragEnter}
ondragleave={onDragLeave}
ondragover={(e) => {
e.preventDefault();
}}
ondrop={(e) => {
e.preventDefault();
onDrag = false;
}}
/>
<div class="relative z-[-1] min-h-0 min-w-0">
{#if shareModalOpen}
<ShareConversationModal open={shareModalOpen} onclose={() => shareModal.close()} />
{/if}
<div
class="scrollbar-custom h-full overflow-y-auto"
use:snapScrollToBottom={scrollSignal}
bind:this={chatContainer}
>
<div
class="mx-auto flex h-full max-w-3xl flex-col gap-6 px-5 pt-6 sm:gap-8 xl:max-w-4xl xl:pt-10"
>
{#if preprompt && preprompt != currentModel.preprompt}
<SystemPromptModal preprompt={preprompt ?? ""} />
{/if}
{#if messages.length > 0}
<div class="flex h-max flex-col gap-8 pb-52">
{#each messages as message, idx (idx)}
<ChatMessage
{loading}
{message}
alternatives={messagesAlternatives.find((a) => a.includes(message.id)) ?? []}
isAuthor={!shared}
readOnly={isReadOnly}
isLast={idx === messages.length - 1}
personaName={message.from === "assistant" && !message.personaResponses ? persona?.name : undefined}
personaOccupation={message.from === "assistant" && !message.personaResponses ? persona?.jobSector : undefined}
personaStance={message.from === "assistant" && !message.personaResponses ? persona?.stance : undefined}
{branchState}
branchPersonas={branchPointInfo.get(message.id) ?? []}
metacognitivePrompt={idx === messages.length - 1 && activeMetacognitivePrompt?.messageId === message.id ? activeMetacognitivePrompt : null}
bind:editMsdgId
onretry={(payload) => onretry?.(payload)}
onshowAlternateMsg={(payload) => onshowAlternateMsg?.(payload)}
onbranch={(messageId, personaId) => onbranch?.(messageId, personaId)}
onmetacognitiveaction={() => metacognitiveEngine.handleMetacognitiveAction(message.id)}
/>
{/each}
{#if isReadOnly}
<ModelSwitch {models} {currentModel} />
{/if}
</div>
{:else if pending}
<ChatMessage
loading={true}
message={{
id: "0-0-0-0-0",
content: "",
from: "assistant",
children: [],
}}
isAuthor={!shared}
readOnly={isReadOnly}
/>
{:else}
<ChatIntroduction
{currentModel}
onmessage={(content) => {
if (page.data.loginRequired) {
$loginModalOpen = true;
} else {
onmessage?.(content);
}
}}
/>
{/if}
</div>
</div>
<div
class="pointer-events-none absolute inset-x-0 bottom-0 z-0 mx-auto flex w-full
max-w-3xl flex-col items-center justify-center bg-gradient-to-t from-white
via-white/100 to-white/0 px-3.5 pb-4 pt-2 dark:border-gray-800
dark:from-gray-900 dark:via-gray-900/100
dark:to-gray-900/0 max-sm:py-0 sm:px-5 xl:max-w-4xl [&>*]:pointer-events-auto"
>
{#if !message.length && !messages.length && !sources.length && !loading && currentModel.isRouter && routerExamples.length && !hideRouterExamples}
<div
class="no-scrollbar mb-3 flex w-full select-none justify-start gap-2 overflow-x-auto whitespace-nowrap text-gray-400 dark:text-gray-500"
>
{#each routerExamples as ex}
<button
class="flex items-center rounded-lg bg-gray-100/90 px-2 py-0.5 text-center text-sm backdrop-blur hover:text-gray-500 dark:bg-gray-700/50 dark:hover:text-gray-400"
onclick={() => startExample(ex)}>{ex.title}</button
>
{/each}
</div>
{/if}
{#if shouldShowRouterFollowUps}
<div
class="no-scrollbar mb-3 flex w-full select-none justify-start gap-2 overflow-x-auto whitespace-nowrap text-gray-400 dark:text-gray-500"
>
{#each routerFollowUps as followUp}
<button
class="flex items-center gap-1 rounded-lg bg-gray-100/90 px-2 py-0.5 text-center text-sm backdrop-blur hover:text-gray-500 dark:bg-gray-700/50 dark:hover:text-gray-400"
onclick={() => startFollowUp(followUp)}
>
<CarbonDirectionRight class="scale-y-[-1] text-xs" />
{followUp.title}</button
>
{/each}
</div>
{/if}
{#if sources?.length && !loading}
<div
in:fly|local={sources.length === 1 ? { y: -20, easing: cubicInOut } : undefined}
class="flex flex-row flex-wrap justify-center gap-2.5 rounded-xl pb-3"
>
{#each sources as source, index}
{#await source then src}
<UploadedFile
file={src}
onclose={() => {
files = files.filter((_, i) => i !== index);
}}
/>
{/await}
{/each}
</div>
{/if}
<div class="w-full">
<div class="flex w-full *:mb-3">
{#if !loading}
{#if messages && lastMessage && lastMessage.interrupted && !isReadOnly}
<div class="ml-auto gap-2">
<ContinueBtn
onClick={() => {
if (lastMessage && lastMessage.ancestors) {
oncontinue?.({
id: lastMessage?.id,
});
}
}}
/>
</div>
{/if}
{/if}
</div>
<div
class={{
"mb-3 flex items-center justify-end gap-2 self-stretch whitespace-nowrap px-0.5 text-xs text-gray-400/90 max-md:mb-2 max-sm:gap-2": true,
"max-sm:hidden": focused && isVirtualKeyboard(),
}}
>
<PersonaSelector {lockedPersonaId} />
{#if models.find((m) => m.id === currentModel.id)}
{#if !currentModel.isRouter || !loading}
<a
href="{base}/settings/models/{currentModel.id}"
class="flex items-center gap-1.5 rounded-lg border border-gray-300 bg-gray-100 px-4 py-1.5 text-sm text-gray-400 shadow-sm hover:bg-gray-200 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-500 dark:hover:bg-gray-700"
>
<CarbonModel class="text-xs" />
{#if currentModel.isRouter}
<IconOmni classNames="text-xs" />
<span class="max-w-[250px] truncate">{currentModel.displayName}</span>
{:else}
<span class="max-w-[250px] truncate">{currentModel.displayName}</span>
{/if}
</a>
{:else if showRouterDetails && streamingRouterMetadata}
<div
class="mr-2 flex items-center gap-1.5 whitespace-nowrap text-[.70rem] text-xs leading-none text-gray-400 dark:text-gray-400"
>
<IconOmni classNames="text-xs animate-pulse" />
<span class="router-badge-text router-shimmer">
{streamingRouterMetadata.route}
</span>
<span class="text-gray-500">with</span>
<span class="router-badge-text">
{streamingRouterModelName}
</span>
</div>
{:else}
<div
class="loading-dots relative inline-flex items-center text-gray-400 dark:text-gray-400"
aria-label="Routing…"
>
<IconOmni classNames="text-xs animate-pulse mr-1" /> Routing
</div>
{/if}
{:else}
<span class="inline-flex items-center line-through dark:border-gray-700">
{currentModel.id}
</span>
{/if}
</div>
<form
tabindex="-1"
aria-label={isFileUploadEnabled ? "file dropzone" : undefined}
onsubmit={(e) => {
e.preventDefault();
handleSubmit();
}}
class={{
"relative flex w-full max-w-4xl flex-1 items-center rounded-xl border bg-gray-100 dark:border-gray-700 dark:bg-gray-800": true,
"opacity-30": isReadOnly,
"max-sm:mb-4": focused && isVirtualKeyboard(),
}}
>
{#if onDrag && isFileUploadEnabled}
<FileDropzone bind:files bind:onDrag mimeTypes={activeMimeTypes} />
{:else}
<div
class="flex w-full flex-1 rounded-xl border-none bg-transparent"
class:paste-glow={pastedLongContent}
>
{#if lastIsError}
<ChatInput value="Sorry, something went wrong. Please try again." disabled={true} />
{:else}
<ChatInput
placeholder={isReadOnly
? "This conversation is read-only."
: branchState
? `Branched from ${branchState.personaName}`
: "Ask anything"}
{loading}
bind:value={message}
bind:files
mimeTypes={activeMimeTypes}
onsubmit={handleSubmit}
{onPaste}
disabled={isReadOnly || lastIsError}
{modelIsMultimodal}
bind:focused
/>
{/if}
{#if loading}
<StopGeneratingBtn
onClick={() => onstop?.()}
showBorder={true}
classNames="absolute bottom-2 right-2 size-7 self-end rounded-full border bg-white text-black shadow transition-none dark:border-transparent dark:bg-gray-600 dark:text-white"
/>
{:else}
<button
class="btn absolute bottom-2 right-2 size-7 self-end rounded-full border bg-white text-black shadow transition-none enabled:hover:bg-white enabled:hover:shadow-inner dark:border-transparent dark:bg-gray-600 dark:text-white dark:hover:enabled:bg-black {!message ||
isReadOnly
? ''
: '!bg-black !text-white dark:!bg-white dark:!text-black'}"
disabled={!message || isReadOnly}
type="submit"
aria-label="Send message"
name="submit"
>
<svg
width="1em"
height="1em"
viewBox="0 0 32 32"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M17.0606 4.23197C16.4748 3.64618 15.525 3.64618 14.9393 4.23197L5.68412 13.4871C5.09833 14.0729 5.09833 15.0226 5.68412 15.6084C6.2699 16.1942 7.21965 16.1942 7.80544 15.6084L14.4999 8.91395V26.7074C14.4999 27.5359 15.1715 28.2074 15.9999 28.2074C16.8283 28.2074 17.4999 27.5359 17.4999 26.7074V8.91395L24.1944 15.6084C24.7802 16.1942 25.7299 16.1942 26.3157 15.6084C26.9015 15.0226 26.9015 14.0729 26.3157 13.4871L17.0606 4.23197Z"
fill="currentColor"
/>
</svg>
</button>
{/if}
</div>
{/if}
</form>
</div>
</div>
</div>
<style lang="postcss">
.paste-glow {
animation: glow 1s cubic-bezier(0.4, 0, 0.2, 1) forwards;
will-change: box-shadow;
}
@keyframes glow {
0% {
box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.8);
}
50% {
box-shadow: 0 0 20px 4px rgba(59, 130, 246, 0.6);
}
100% {
box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
}
}
.router-badge-text {
display: inline-block;
position: relative;
color: inherit;
}
.router-shimmer {
display: inline-block;
background-image: linear-gradient(
90deg,
rgba(156, 163, 175, 1) 0%,
rgba(156, 163, 175, 0.6) 10%,
rgba(156, 163, 175, 0.6) 50%,
rgba(156, 163, 175, 0.6) 90%,
rgba(156, 163, 175, 1) 100%
);
background-size: 220% 100%;
animation: router-shimmer 2.8s linear infinite;
background-clip: text;
-webkit-background-clip: text;
color: transparent;
-webkit-text-fill-color: transparent;
}
:global(.dark) .router-shimmer {
background-image: linear-gradient(
90deg,
rgba(255, 255, 255, 0.15) 0%,
rgba(255, 255, 255, 0.7) 50%,
rgba(255, 255, 255, 0.15) 100%
);
}
@keyframes router-shimmer {
0% {
background-position: 200% 0;
}
100% {
background-position: -200% 0;
}
}
.loading-dots::after {
content: "";
animation: dots-content 0.9s steps(1, end) infinite;
}
@keyframes dots-content {
0% {
content: "";
}
33% {
content: ".";
}
66% {
content: "..";
}
88% {
content: "...";
}
}
</style>
|