Skip to content
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

fix: increase size of session messages area #206

Merged
merged 4 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/components/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
}

&--icon {
@apply px-2 py-2 text-muted;
@apply px-2.5 py-2 text-muted;
@apply hover:text-base;
@apply active:text-active;
}
Expand Down
13 changes: 12 additions & 1 deletion src/lib/components/Field.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
export let disabled: boolean | undefined = false;
export let isTextEditor: boolean | undefined = false;
export let hasNav: boolean | undefined = false;

// HACK: This is needed because Svelte named slots can't be conditionally rendered
// We should be able to remove this once we upgrade to Svelte 5
// REF https://svelte-5-preview.vercel.app/docs/snippets
export let isLabelVisible: boolean | undefined = true;
</script>

<div class="field" class:field--text-editor={isTextEditor} class:field--with-nav={hasNav}>
Expand All @@ -17,7 +22,9 @@
<Label.Root
for={name}
id={`${name}-label`}
class="field-label-root {isTextEditor ? 'field-label-root--text-editor' : ''}"
class="field-label-root {isTextEditor
? 'field-label-root--text-editor'
: ''} {isLabelVisible ? '' : 'field-label-root--no-label'}"
>
<slot name="label" />
</Label.Root>
Expand Down Expand Up @@ -62,6 +69,10 @@
@apply flex items-center gap-x-2 px-3 pb-0.5 pt-3 text-xs font-medium leading-none;
}

:global(.field-label-root--no-label) {
@apply hidden;
}

:global(.field-label-root--text-editor) {
@apply border-b border-shade-2 p-3;
}
Expand Down
9 changes: 7 additions & 2 deletions src/lib/components/FieldSelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
export let placeholder: string = '';
export let allowClear: boolean = true;
export let allowSearch: boolean = true;
export let isLabelVisible: boolean | undefined = true;
export let onChange: (value: Option) => void = () => {};

type Option = Selected<string> & { badge?: string };
Expand Down Expand Up @@ -81,7 +82,7 @@
}
</script>

<Field {name} disabled={isDisabled} hasNav={$$slots.nav}>
<Field {name} disabled={isDisabled} hasNav={$$slots.nav} {isLabelVisible}>
<svelte:fragment slot="label">{label}</svelte:fragment>
<Combobox.Root
bind:touchedInput
Expand All @@ -96,7 +97,7 @@
<div class="field-select-input">
<Combobox.Input
spellcheck="false"
class="field-combobox-input"
class="field-combobox-input {isLabelVisible ? '' : 'field-combobox-input--no-label'}"
placeholder={selected?.value ? selected.label : placeholder}
id={name}
disabled={isDisabled}
Expand Down Expand Up @@ -194,6 +195,10 @@
@apply base-input pr-14 text-sm;
}

:global(.field-combobox-input--no-label) {
@apply py-2.5;
}

:global(.field-combobox-content) {
@apply overflow-scrollbar relative z-10 max-h-64 max-w-full rounded-md bg-shade-0 py-1 shadow-md;
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/components/FieldSelectModel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import FieldSelect from './FieldSelect.svelte';

export let model: string | undefined = $settingsStore.ollamaModel || '';
export let isLabelVisible: boolean | undefined = true;

type ModelOption = {
value: string;
Expand Down Expand Up @@ -47,8 +48,9 @@
<FieldSelect
name="model"
{disabled}
placeholder={$LL.search()}
placeholder={isLabelVisible ? $LL.search() : $LL.availableModels()}
label={$LL.availableModels()}
{isLabelVisible}
options={[
{ label: $LL.lastUsedModels(), options: lastUsedModels },
{ label: $LL.otherModels(), options: otherModels }
Expand Down
8 changes: 3 additions & 5 deletions src/lib/components/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@

<style lang="postcss">
.header {
@apply flex items-end justify-between border-b bg-shade-1;
@apply flex min-h-10 items-center justify-between border-b bg-shade-1 px-4 text-xs;

&--confirm-deletion {
@apply confirm-deletion;
}
}

.header__headline {
@apply flex flex-col gap-y-1.5 p-4;
@apply lg:p-6;
@apply flex items-center gap-2;
}

.header__nav {
@apply flex flex-row items-center pb-4 pr-4;
@apply lg:pb-6 lg:pr-6;
@apply flex flex-row items-center;
}
</style>
2 changes: 1 addition & 1 deletion src/routes/knowledge/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<Head title={[knowledge.name ? knowledge.name : $LL.newKnowledge(), $LL.knowledge()]} />
<div class="knowledge">
<Header confirmDeletion={$shouldConfirmDeletion}>
<p data-testid="knowledge-id" class="text-sm font-bold leading-none">
<p data-testid="knowledge-id" class="font-bold leading-none">
{$LL.knowledge()}
<Button variant="link" href={`/knowledge/${knowledge.id}`}>
#{knowledge.id}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/sessions/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
title={[$editor.isNewSession ? $LL.newSession() : getSessionTitle($session), $LL.sessions()]}
/>
<Header confirmDeletion={$shouldConfirmDeletion}>
<p data-testid="session-id" class="text-sm font-bold leading-none">
<p data-testid="session-id" class="font-bold leading-none">
{$LL.session()}
<Button variant="link" href={`/sessions/${$session.id}`}>#{$session.id}</Button>
</p>
Expand Down
202 changes: 102 additions & 100 deletions src/routes/sessions/[id]/Prompt.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import ButtonSubmit from '$lib/components/ButtonSubmit.svelte';
import Field from '$lib/components/Field.svelte';
import FieldSelectModel from '$lib/components/FieldSelectModel.svelte';
import Fieldset from '$lib/components/Fieldset.svelte';
import FieldTextEditor from '$lib/components/FieldTextEditor.svelte';
import { settingsStore } from '$lib/localStorage';
import type { Editor } from '$lib/sessions';
Expand Down Expand Up @@ -39,130 +38,133 @@
</script>

<div class="prompt-editor" class:prompt-editor--fullscreen={$editor.isCodeEditor}>
<button class="prompt-editor__toggle" on:click={toggleCodeEditor}>
<UnfoldVertical class="mx-auto my-2 h-3 w-3 opacity-50" />
</button>

<div class="prompt-editor__form">
<Fieldset>
<div class="prompt-editor__project">
<FieldSelectModel bind:model />

<nav class="segmented-nav">
<div
class="segmented-nav__button"
class:segmented-nav__button--active={$editor.view === 'messages'}
>
<Button
aria-label={$LL.messages()}
variant="icon"
on:click={switchToMessages}
class="h-full"
isActive={$editor.view === 'messages'}
>
<MessageSquareText class="base-icon" />
</Button>
</div>
<div
class="segmented-nav__button"
class:segmented-nav__button--active={$editor.view === 'controls'}
>
<Button
aria-label={$LL.controls()}
variant="icon"
on:click={() => ($editor.view = 'controls')}
class="h-full"
isActive={$editor.view === 'controls'}
>
<Settings_2 class="base-icon" />
</Button>
</div>
</nav>
</div>

{#if $editor.isCodeEditor}
<FieldTextEditor label={$LL.prompt()} {handleSubmit} bind:value={$editor.prompt} />
{:else}
<Field name="prompt">
<textarea
name="prompt"
class="prompt-editor__textarea"
placeholder={$LL.promptPlaceholder()}
bind:this={$editor.promptTextarea}
bind:value={$editor.prompt}
on:keydown={handleKeyDown}
/>
</Field>
{/if}
<div class="prompt-editor__project">
<FieldSelectModel isLabelVisible={false} bind:model />

<nav class="prompt-editor__toolbar">
{#if $editor.messageIndexToEdit !== null}
<nav class="segmented-nav">
<div
class="segmented-nav__button"
class:segmented-nav__button--active={$editor.view === 'messages'}
>
<Button
variant="outline"
on:click={() => {
$editor.prompt = '';
$editor.messageIndexToEdit = null;
$editor.isCodeEditor = false;
}}
aria-label={$LL.messages()}
variant="icon"
on:click={switchToMessages}
class="h-full"
isActive={$editor.view === 'messages'}
>
{$LL.cancel()}
<MessageSquareText class="base-icon" />
</Button>
{/if}
<ButtonSubmit
{handleSubmit}
hasMetaKey={$editor.isCodeEditor}
disabled={!$editor.prompt ||
$settingsStore.ollamaServerStatus === 'disconnected' ||
$settingsStore.ollamaModels.length === 0 ||
!$settingsStore.ollamaModel}
</div>
<div
class="segmented-nav__button"
class:segmented-nav__button--active={$editor.view === 'controls'}
>
{$LL.run()}
</ButtonSubmit>

{#if $editor.isCompletionInProgress}
<Button title="Stop completion" variant="outline" on:click={stopCompletion}>
<div class="prompt-editor__stop">
<span class="prompt-editor__stop-icon">
<StopCircle class=" base-icon" />
</span>
<span class="prompt-editor__loading-icon">
<LoaderCircle class="prompt-editor__loading-icon base-icon animate-spin" />
</span>
</div>
<Button
aria-label={$LL.controls()}
variant="icon"
on:click={() => ($editor.view = 'controls')}
class="h-full"
isActive={$editor.view === 'controls'}
>
<Settings_2 class="base-icon" />
</Button>
{/if}
</div>
</nav>
</Fieldset>

<Button
variant={$editor.isCodeEditor ? 'default' : 'outline'}
class="prompt-editor__toggle"
on:click={toggleCodeEditor}
>
<UnfoldVertical class="base-icon" />
</Button>
</div>

{#if $editor.isCodeEditor}
<FieldTextEditor label={$LL.prompt()} {handleSubmit} bind:value={$editor.prompt} />
{:else}
<Field name="prompt">
<textarea
name="prompt"
class="prompt-editor__textarea"
placeholder={$LL.promptPlaceholder()}
bind:this={$editor.promptTextarea}
bind:value={$editor.prompt}
on:keydown={handleKeyDown}
/>
</Field>
{/if}

<nav class="prompt-editor__toolbar">
{#if $editor.messageIndexToEdit !== null}
<Button
variant="outline"
on:click={() => {
$editor.prompt = '';
$editor.messageIndexToEdit = null;
$editor.isCodeEditor = false;
}}
>
{$LL.cancel()}
</Button>
{/if}
<ButtonSubmit
{handleSubmit}
hasMetaKey={$editor.isCodeEditor}
disabled={!$editor.prompt ||
$settingsStore.ollamaServerStatus === 'disconnected' ||
$settingsStore.ollamaModels.length === 0 ||
!$settingsStore.ollamaModel}
>
{$LL.run()}
</ButtonSubmit>

{#if $editor.isCompletionInProgress}
<Button title="Stop completion" variant="outline" on:click={stopCompletion}>
<div class="prompt-editor__stop">
<span class="prompt-editor__stop-icon">
<StopCircle class=" base-icon" />
</span>
<span class="prompt-editor__loading-icon">
<LoaderCircle class="prompt-editor__loading-icon base-icon animate-spin" />
</span>
</div>
</Button>
{/if}
</nav>
</div>
</div>

<style lang="postcss">
.prompt-editor {
@apply sticky bottom-0 z-10 mx-auto flex w-full flex-col border-t;
@apply sticky bottom-0 z-10 mx-auto flex w-full flex-col border-t bg-shade-1 p-3;
@apply md:p-4;
@apply lg:p-6;
@apply 2xl:max-w-[80ch] 2xl:rounded-t-lg 2xl:border-l 2xl:border-r;
}

.prompt-editor__project {
@apply grid grid-cols-[auto,max-content] items-end gap-x-2;
@apply grid grid-cols-[auto,max-content,max-content] items-end gap-x-2;
}

:global(.prompt-editor__toggle) {
@apply h-full;
}

.prompt-editor--fullscreen {
@apply min-h-[60dvh];
@apply md:min-h-[75dvh];
}

.prompt-editor__form {
@apply base-fieldset-container overflow-scrollbar flex h-full bg-shade-1;
}

.prompt-editor__toggle {
@apply border-b bg-shade-1;
@apply hover:bg-shade-2 active:bg-shade-2;
@apply 2xl:rounded-t-lg;
@apply overflow-scrollbar flex h-full flex-col gap-y-2;
}

.prompt-editor__textarea {
@apply base-input min-h-16 resize-none scroll-p-2 px-3 py-2;
@apply md:min-h-20;
field-sizing: content;
@apply base-input max-h-48 min-h-14 resize-none scroll-p-2 px-3 py-2;
}

.prompt-editor__toolbar {
Expand Down Expand Up @@ -197,11 +199,11 @@
}

.segmented-nav {
@apply flex h-full items-center rounded bg-shade-2 p-1;
@apply flex h-full items-center rounded bg-shade-2 p-0.5;
}

.segmented-nav__button {
@apply h-full rounded-sm px-1 text-shade-6;
@apply h-full rounded-sm text-shade-6;

&--active {
@apply bg-shade-0 text-neutral-50 shadow;
Expand Down
Binary file modified tests/docs.test.ts-snapshots/knowledge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/docs.test.ts-snapshots/session-controls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/docs.test.ts-snapshots/session-new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/docs.test.ts-snapshots/session.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading