* ui: replace deprecated packages and fix npm audit findings
Swap the mdast stub for @types/mdast, move the katex override to 0.19.0,
and override glob, source-map and html-encoding-sniffer under
workbox-build and http-server so installs no longer pull deprecated
packages. Apply the non-breaking npm audit fixes to the lockfile.
Assisted-by: Claude (Opus 5.5 Medium)
* ui: migrate Llama Chat to SvelteKit 3 and its built-in service worker
Move to SvelteKit 3, Vite 8, TypeScript 6 and Storybook 10.6. The
SvelteKit options move from svelte.config.js into sveltekit() in
vite.config.ts, $lib imports become #lib subpath imports from
package.json, and $app/environment becomes $app/env. Modules named
server.* or living under a server/ folder are server-only in SvelteKit 3,
so the llama-server components, store and enums move to llama-server
names.
@vite-pwa/sveltekit and Workbox give way to SvelteKit's own service
worker in src/service-worker, registered by usePwa(), which precaches the
app files and leaves API requests to the network. A small plugin emits
manifest.webmanifest. static/sw.js removes the worker of older builds, and
llama-server serves a self-removing service-worker.js as well as sw.js
when the built-in UI is off or replaced.
Assisted-by: Claude (Opus 5.5 Medium)
* ui: use SvelteKit 3's update detection and Svelte 5's current patterns
A page the service worker doesn't control now learns of a new build
from SvelteKit itself: `updated` from $app/state checks
_app/version.json on navigation, on focus and every hour. It replaces
the version Llama Chat kept in localStorage and compared by hand.
Reload on the update prompt pulls in the new worker and activates it
before reloading, so one click lands on the new build, whether or not
a worker controlled the page.
Following Svelte's current guidance:
- usePwa keeps its state in $state rather than a store, and no effect
checks `browser`
- nearViewport, autoResizeTextarea and the custom CSS injection are
attachments ({@attach}) rather than actions (use:)
- class lists use arrays rather than class: directives
- the chat contexts come from createContext, typed, in place of
setContext/getContext with string keys
- ActionIconCopyToClipboard takes $props() rather than `export let`
Assisted-by: Claude (Opus 5.5 Medium)
* ui: move to ESLint 10
ESLint 9 is out of support. Every plugin the app uses supports 10:
typescript-eslint, eslint-plugin-svelte, perfectionist,
simple-import-sort, eslint-plugin-storybook and eslint-config-prettier.
@eslint/js and @eslint/compat follow.
ESLint 10's recommended rules ask for two things the code now does:
errors rethrown from a catch keep the caught error as their `cause`,
and no variable starts with a value that every path overwrites.
Assisted-by: Claude (Opus 5.5 Medium)
* ui: override minimatch to clear npm audit's last finding
ESLint 10.14, @eslint/config-array 0.23.5 and typescript-eslint 8.72
depend on minimatch 10, which GHSA-g3hv-75wg-m249 (denial of service
via globparts amplification) affects below 11.0.1. Their fixed releases
move to minimatch 11 but are all younger than the repo's 7-day
min-release-age, so an override pins minimatch 11.0.5, the newest the
rule allows. The three only call new Minimatch(), match() and
minimatch(), which minimatch 11 keeps. npm audit now finds nothing.
Assisted-by: Claude (Opus 5.5 Medium)
232 lines
6.7 KiB
TypeScript
232 lines
6.7 KiB
TypeScript
// Guards the two Settings > Display toggles that drive the default expansion of
|
|
// a tool call block.
|
|
//
|
|
// "Show tool call in progress" mirrors "Show thought in progress": a call is
|
|
// expanded by default only while it is in flight and folds back on its own once
|
|
// the result lands. "Always show tool call content" is the one that keeps
|
|
// finished calls open and wins on its own. A manual toggle always overrides the
|
|
// default, in both directions.
|
|
|
|
import ChatMessageAgenticContent from '#lib/components/app/chat/ChatMessages/ChatMessageAgenticContent.svelte';
|
|
import { COLLAPSIBLE_TRANSITION_MS, SETTINGS_KEYS } from '#lib/constants/index.ts';
|
|
import { MessageRole, MessageType } from '#lib/enums/index.ts';
|
|
import { settingsStore } from '#lib/stores/index.ts';
|
|
import type { DatabaseMessage } from '#lib/types/index.ts';
|
|
import { tick } from 'svelte';
|
|
import { beforeEach, describe, expect, it } from 'vitest';
|
|
import { userEvent } from 'vitest/browser';
|
|
import { render } from 'vitest-browser-svelte';
|
|
|
|
const TOOL_NAME = 'custom_tool';
|
|
const TOOL_CALL_ID = 'call-1';
|
|
// Both markers sit inside the collapsible body, which CollapsibleContentBlock
|
|
// only mounts while open - so their presence is exactly "the block is expanded".
|
|
// The collapse is animated and the body unmounts once it ends, so assertions
|
|
// that a block closed wait for the transition first.
|
|
const PENDING_BODY = 'Waiting for result...';
|
|
const RESULT_BODY = 'marker-tool-output';
|
|
const TRIGGER_SELECTOR = '[data-slot="collapsible-trigger"]';
|
|
// The collapse transition plus a frame of slack.
|
|
const COLLAPSE_SETTLE_MS = COLLAPSIBLE_TRANSITION_MS + 50;
|
|
|
|
function assistantMessage(): DatabaseMessage {
|
|
return {
|
|
children: [],
|
|
content: '',
|
|
convId: 'conv-1',
|
|
id: 'assistant-1',
|
|
parent: null,
|
|
role: MessageRole.ASSISTANT,
|
|
timestamp: 0,
|
|
toolCalls: JSON.stringify([
|
|
{ function: { arguments: '{"path":"a.txt"}', name: TOOL_NAME }, id: TOOL_CALL_ID }
|
|
]),
|
|
type: MessageType.TEXT
|
|
};
|
|
}
|
|
|
|
function toolResultMessage(): DatabaseMessage {
|
|
return {
|
|
...assistantMessage(),
|
|
content: RESULT_BODY,
|
|
id: 'tool-1',
|
|
role: MessageRole.TOOL,
|
|
toolCallId: TOOL_CALL_ID
|
|
};
|
|
}
|
|
|
|
function setSettings({
|
|
alwaysShow,
|
|
inProgress
|
|
}: {
|
|
alwaysShow: boolean;
|
|
inProgress: boolean;
|
|
}): void {
|
|
settingsStore.updateMultipleConfig({
|
|
[SETTINGS_KEYS.ALWAYS_SHOW_TOOL_CALL_CONTENT]: alwaysShow,
|
|
[SETTINGS_KEYS.SHOW_TOOL_CALL_IN_PROGRESS]: inProgress
|
|
});
|
|
}
|
|
|
|
function textOf(container: Element): string {
|
|
return container.textContent ?? '';
|
|
}
|
|
|
|
async function waitForCollapse(): Promise<void> {
|
|
await new Promise((resolve) => setTimeout(resolve, COLLAPSE_SETTLE_MS));
|
|
await tick();
|
|
}
|
|
|
|
async function collapseBlock(screen: { container: Element }): Promise<void> {
|
|
const trigger = screen.container.querySelector(TRIGGER_SELECTOR);
|
|
|
|
if (!(trigger instanceof HTMLButtonElement)) throw new Error('trigger not found');
|
|
|
|
await userEvent.click(trigger);
|
|
await tick();
|
|
}
|
|
|
|
describe('Show tool call in progress', () => {
|
|
beforeEach(() => {
|
|
setSettings({ alwaysShow: false, inProgress: false });
|
|
});
|
|
|
|
it('expands a call that is still executing when the setting is on', async () => {
|
|
setSettings({ alwaysShow: false, inProgress: true });
|
|
|
|
const { container } = render(ChatMessageAgenticContent, {
|
|
isLastAssistantMessage: true,
|
|
isStreaming: true,
|
|
message: assistantMessage(),
|
|
toolMessages: []
|
|
});
|
|
|
|
await tick();
|
|
|
|
expect(textOf(container)).toContain(PENDING_BODY);
|
|
});
|
|
|
|
it('keeps the call collapsed while executing when the setting is off', async () => {
|
|
const { container } = render(ChatMessageAgenticContent, {
|
|
isLastAssistantMessage: true,
|
|
isStreaming: true,
|
|
message: assistantMessage(),
|
|
toolMessages: []
|
|
});
|
|
|
|
await tick();
|
|
|
|
// The header is still there, only the body stays hidden.
|
|
expect(textOf(container)).toContain(TOOL_NAME);
|
|
expect(textOf(container)).not.toContain(PENDING_BODY);
|
|
});
|
|
|
|
it('folds the call back when its result arrives', async () => {
|
|
setSettings({ alwaysShow: false, inProgress: true });
|
|
|
|
const screen = render(ChatMessageAgenticContent, {
|
|
isLastAssistantMessage: true,
|
|
isStreaming: true,
|
|
message: assistantMessage(),
|
|
toolMessages: []
|
|
});
|
|
|
|
await tick();
|
|
|
|
// Open while it waits for the result.
|
|
expect(textOf(screen.container)).toContain(PENDING_BODY);
|
|
|
|
// Same block, now finished: it must close on its own, no toggle given.
|
|
screen.rerender({
|
|
isLastAssistantMessage: true,
|
|
isStreaming: true,
|
|
message: assistantMessage(),
|
|
toolMessages: [toolResultMessage()]
|
|
});
|
|
await waitForCollapse();
|
|
|
|
expect(textOf(screen.container)).toContain(TOOL_NAME);
|
|
expect(textOf(screen.container)).not.toContain(PENDING_BODY);
|
|
expect(textOf(screen.container)).not.toContain(RESULT_BODY);
|
|
});
|
|
|
|
it('keeps the manual choice once the result arrives', async () => {
|
|
setSettings({ alwaysShow: false, inProgress: true });
|
|
|
|
const screen = render(ChatMessageAgenticContent, {
|
|
isLastAssistantMessage: true,
|
|
isStreaming: true,
|
|
message: assistantMessage(),
|
|
toolMessages: []
|
|
});
|
|
|
|
await tick();
|
|
|
|
// Collapsed by hand while running, so the result must not reopen it.
|
|
await collapseBlock(screen);
|
|
|
|
screen.rerender({
|
|
isLastAssistantMessage: true,
|
|
isStreaming: true,
|
|
message: assistantMessage(),
|
|
toolMessages: [toolResultMessage()]
|
|
});
|
|
await waitForCollapse();
|
|
|
|
expect(textOf(screen.container)).toContain(TOOL_NAME);
|
|
expect(textOf(screen.container)).not.toContain(RESULT_BODY);
|
|
});
|
|
|
|
it('still expands a finished call when "always show" is on', async () => {
|
|
setSettings({ alwaysShow: true, inProgress: false });
|
|
|
|
const { container } = render(ChatMessageAgenticContent, {
|
|
isLastAssistantMessage: true,
|
|
isStreaming: true,
|
|
message: assistantMessage(),
|
|
toolMessages: [toolResultMessage()]
|
|
});
|
|
|
|
await tick();
|
|
|
|
expect(textOf(container)).toContain(RESULT_BODY);
|
|
});
|
|
|
|
it('lets a manual collapse win over the in-progress default', async () => {
|
|
setSettings({ alwaysShow: false, inProgress: true });
|
|
|
|
const screen = render(ChatMessageAgenticContent, {
|
|
isLastAssistantMessage: true,
|
|
isStreaming: true,
|
|
message: assistantMessage(),
|
|
toolMessages: []
|
|
});
|
|
|
|
await tick();
|
|
|
|
expect(textOf(screen.container)).toContain(PENDING_BODY);
|
|
|
|
await collapseBlock(screen);
|
|
await waitForCollapse();
|
|
|
|
expect(textOf(screen.container)).not.toContain(PENDING_BODY);
|
|
});
|
|
|
|
it('lets a manual expand win over the collapsed default', async () => {
|
|
const screen = render(ChatMessageAgenticContent, {
|
|
isLastAssistantMessage: true,
|
|
isStreaming: true,
|
|
message: assistantMessage(),
|
|
toolMessages: []
|
|
});
|
|
|
|
await tick();
|
|
|
|
expect(textOf(screen.container)).not.toContain(PENDING_BODY);
|
|
|
|
await collapseBlock(screen);
|
|
|
|
expect(textOf(screen.container)).toContain(PENDING_BODY);
|
|
});
|
|
});
|