* 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)
164 lines
5.9 KiB
TypeScript
164 lines
5.9 KiB
TypeScript
import { ContinueIntentKind, MessageRole, MessageType } from '#lib/enums/index.ts';
|
|
import type { DatabaseMessage } from '#lib/types/database.js';
|
|
import { classifyContinueIntent } from '#lib/utils/agentic.ts';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
/**
|
|
* Tests for the Continue button intent classifier.
|
|
*
|
|
* The classifier walks the persisted message history to decide which of three
|
|
* resume paths a Continue click should take:
|
|
*
|
|
* A. append_text -> plain text assistant turn, resume with
|
|
* continue_final_message.
|
|
* B. rerun_turn -> assistant turn with tool_calls but no tool results yet,
|
|
* the stream was cut mid turn and the tool_calls are
|
|
* unrecoverable as a token level continuation. Drop the
|
|
* target and rerun from the previous history.
|
|
* C. next_turn -> assistant turn with tool_calls that were already
|
|
* resolved by trailing tool results. Hand the history
|
|
* back to the agentic loop so it starts the next turn.
|
|
*/
|
|
|
|
let nextId = 0;
|
|
|
|
function makeMsg(role: MessageRole, opts: Partial<DatabaseMessage> = {}): DatabaseMessage {
|
|
nextId++;
|
|
|
|
return {
|
|
children: [],
|
|
content: '',
|
|
convId: 'conv-1',
|
|
id: `msg-${nextId}`,
|
|
parent: null,
|
|
role,
|
|
timestamp: nextId,
|
|
type: MessageType.TEXT,
|
|
...opts
|
|
};
|
|
}
|
|
|
|
function toolCall(id: string, name: string, args: string = '{}'): string {
|
|
return JSON.stringify([{ function: { arguments: args, name }, id, type: 'function' }]);
|
|
}
|
|
|
|
describe('classifyContinueIntent', () => {
|
|
it('returns append_text for a plain text assistant turn at the tail', () => {
|
|
const messages = [
|
|
makeMsg(MessageRole.USER, { content: 'hello' }),
|
|
makeMsg(MessageRole.ASSISTANT, { content: 'hi there' })
|
|
];
|
|
const intent = classifyContinueIntent(messages, 1);
|
|
|
|
expect(intent).toEqual({ kind: ContinueIntentKind.APPEND_TEXT });
|
|
});
|
|
|
|
it('returns append_text for a plain text assistant turn in the middle', () => {
|
|
const messages = [
|
|
makeMsg(MessageRole.USER, { content: 'q1' }),
|
|
makeMsg(MessageRole.ASSISTANT, { content: 'a1' }),
|
|
makeMsg(MessageRole.USER, { content: 'q2' }),
|
|
makeMsg(MessageRole.ASSISTANT, { content: 'a2' })
|
|
];
|
|
|
|
expect(classifyContinueIntent(messages, 1)).toEqual({ kind: ContinueIntentKind.APPEND_TEXT });
|
|
});
|
|
|
|
it('returns rerun_turn when the assistant has tool_calls without results', () => {
|
|
const messages = [
|
|
makeMsg(MessageRole.USER, { content: 'list files' }),
|
|
makeMsg(MessageRole.ASSISTANT, {
|
|
content: '',
|
|
toolCalls: toolCall('call_1', 'bash_tool', '{"command":"ls"}')
|
|
})
|
|
];
|
|
const intent = classifyContinueIntent(messages, 1);
|
|
|
|
expect(intent).toEqual({ kind: ContinueIntentKind.RERUN_TURN, truncateAfter: 0 });
|
|
});
|
|
|
|
it('returns next_turn when trailing tool results resolve the tool_calls', () => {
|
|
const messages = [
|
|
makeMsg(MessageRole.USER, { content: 'list files' }),
|
|
makeMsg(MessageRole.ASSISTANT, {
|
|
content: '',
|
|
toolCalls: toolCall('call_1', 'bash_tool')
|
|
}),
|
|
makeMsg(MessageRole.TOOL, { content: 'file1\nfile2', toolCallId: 'call_1' })
|
|
];
|
|
const intent = classifyContinueIntent(messages, 1);
|
|
|
|
expect(intent).toEqual({ kind: ContinueIntentKind.NEXT_TURN, truncateAfter: 2 });
|
|
});
|
|
|
|
it('next_turn keeps all consecutive trailing tool results, not just one', () => {
|
|
const messages = [
|
|
makeMsg(MessageRole.USER, { content: 'do many things' }),
|
|
makeMsg(MessageRole.ASSISTANT, {
|
|
content: '',
|
|
toolCalls: JSON.stringify([
|
|
{ function: { arguments: '{}', name: 'a' }, id: 'call_1', type: 'function' },
|
|
{ function: { arguments: '{}', name: 'b' }, id: 'call_2', type: 'function' }
|
|
])
|
|
}),
|
|
makeMsg(MessageRole.TOOL, { content: 'r1', toolCallId: 'call_1' }),
|
|
makeMsg(MessageRole.TOOL, { content: 'r2', toolCallId: 'call_2' })
|
|
];
|
|
const intent = classifyContinueIntent(messages, 1);
|
|
|
|
expect(intent).toEqual({ kind: ContinueIntentKind.NEXT_TURN, truncateAfter: 3 });
|
|
});
|
|
|
|
it('next_turn stops at the first non tool message after the target', () => {
|
|
const messages = [
|
|
makeMsg(MessageRole.USER, { content: 'go' }),
|
|
makeMsg(MessageRole.ASSISTANT, {
|
|
content: '',
|
|
toolCalls: toolCall('call_1', 'a')
|
|
}),
|
|
makeMsg(MessageRole.TOOL, { content: 'r1', toolCallId: 'call_1' }),
|
|
makeMsg(MessageRole.USER, { content: 'wait' }),
|
|
makeMsg(MessageRole.TOOL, { content: 'late', toolCallId: 'call_1' })
|
|
];
|
|
const intent = classifyContinueIntent(messages, 1);
|
|
|
|
// truncateAfter must point at the contiguous tool block, not jump over
|
|
// the user message to grab the dangling late tool.
|
|
expect(intent).toEqual({ kind: ContinueIntentKind.NEXT_TURN, truncateAfter: 2 });
|
|
});
|
|
|
|
it('returns append_text when toolCalls is set but parses to empty array', () => {
|
|
const messages = [
|
|
makeMsg(MessageRole.USER, { content: 'q' }),
|
|
makeMsg(MessageRole.ASSISTANT, { content: 'a', toolCalls: '[]' })
|
|
];
|
|
|
|
expect(classifyContinueIntent(messages, 1)).toEqual({ kind: ContinueIntentKind.APPEND_TEXT });
|
|
});
|
|
|
|
it('returns append_text when toolCalls is malformed JSON', () => {
|
|
const messages = [
|
|
makeMsg(MessageRole.USER, { content: 'q' }),
|
|
makeMsg(MessageRole.ASSISTANT, { content: 'a', toolCalls: '{not json' })
|
|
];
|
|
|
|
expect(classifyContinueIntent(messages, 1)).toEqual({ kind: ContinueIntentKind.APPEND_TEXT });
|
|
});
|
|
|
|
it('returns append_text defensively when idx points at a non assistant message', () => {
|
|
const messages = [
|
|
makeMsg(MessageRole.USER, { content: 'q' }),
|
|
makeMsg(MessageRole.ASSISTANT, { content: 'a' })
|
|
];
|
|
|
|
expect(classifyContinueIntent(messages, 0)).toEqual({ kind: ContinueIntentKind.APPEND_TEXT });
|
|
});
|
|
|
|
it('returns append_text defensively when idx is out of bounds', () => {
|
|
const messages = [makeMsg(MessageRole.ASSISTANT, { content: 'a' })];
|
|
|
|
expect(classifyContinueIntent(messages, 5)).toEqual({ kind: ContinueIntentKind.APPEND_TEXT });
|
|
expect(classifyContinueIntent([], 0)).toEqual({ kind: ContinueIntentKind.APPEND_TEXT });
|
|
});
|
|
});
|