* feat: Add shimmer text animation for processing state indicators * feat: Redesign CollapsibleContentBlock component with improved UX * feat: Add conditional setting display support with dependsOn field * feat: Add showAgenticTurnStats setting for per-turn statistics * feat: Update ChatMessageAgenticContent with improved UI and new features * feat: Enhance file read tool UI/UX * feat: Refine styling of collapsible content and code preview blocks * feat: add terminal variant to CollapsibleContentBlock * feat: add built-in tools UI registry * feat: extract ChatMessageReasoningBlock and ChatMessageToolCallBlock * refactor: simplify ChatMessageAgenticContent to use extracted blocks * fix: correct markdown content block margin spacing * fix: reorganize SettingsChatFields layout and reset button positioning * fix: use direct map access in agentic store session methods * refactor: remove reasoning preview/throttle system from CollapsibleContentBlock * feat: add auto-scroll to reasoning block and remove showThoughtInProgress * feat: add ChatMessageToolCallDateTime component and support for new tool types * feat: improve auto-scroll reliability in reasoning block with RAF coalescing and MutationObserver * feat: show MCP server favicon for tools without a built-in icon * feat: add search-results parsing utilities and tests * feat: add ChatMessageToolCallSearchResults component * feat: integrate search results rendering into ChatMessageAgenticContent * feat: display tool call input alongside output in ChatMessageToolCallBlock * style: use muted foreground color in reasoning block content * chore: Format * feat: Refine reasoning block layout and make pending thoughts display configurable * feat: Stream tool call code blocks with auto-scroll and handle partial JSON * feat: add streaming permission gate infrastructure * feat: wire permission gate into the agentic loop * fix: bail out on abort and skip already-approved tool calls * fix: clear partial tool calls on abort and savePartialResponse * test: cover partial tool call cleanup end-to-end * refactor: Remove streaming permission gate logic * fix: Correct autoscroll and streaming gates for tool calls and reasoning blocks * refactor: Chat Message Assistant componentization * fix: Show health metadata for disabled MCP servers and promote connections on enable * fix: Inherit global enabled state for missing MCP per-chat overrides * refactor: Cleanup * refactor: Split ChatMessageToolCallBlock into dedicated components * feat: Add live streaming and auto-scroll for tool execution output * feat: Add line numbers and change markers to file edit diffs * chore: Formatting * feat: Add type definitions and utilities for recommended MCP servers * feat: Add recommended MCP servers configuration and storage key * feat: Add McpServerCardCompact component for recommended servers * feat: Add recommended servers section to Add New Server dialog * feat: Update McpServerForm to support authorization requirements * feat: Add select-none classes for text selection prevention * feat: Add recommended MCP server icon assets * refactor: Store dismissed MCP recommendations as a boolean flag * feat: Render tool results as JSON or Markdown based on detected content type * feat: UI improvement * feat: Render search block early and update heading to show execution state * fix: Prevent non-web-search tools from triggering the search UI block * refactor: Cleanup * refactor: Extract hardcoded icon size classes into shared constants * refactor: Extract hardcoded tool result separator into a shared constant * refactor: Tool Calls UI/logic * refactor: Cleanup * refactor: Cleanup * refactor: Cleanup
131 lines
4.2 KiB
TypeScript
131 lines
4.2 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { classifyToolResult } from '$lib/utils/agentic';
|
|
|
|
describe('classifyToolResult', () => {
|
|
describe('text', () => {
|
|
it('returns text for undefined input', () => {
|
|
expect(classifyToolResult(undefined)).toBe('text');
|
|
});
|
|
|
|
it('returns text for empty string', () => {
|
|
expect(classifyToolResult('')).toBe('text');
|
|
});
|
|
|
|
it('returns text for whitespace-only input', () => {
|
|
expect(classifyToolResult(' \n ')).toBe('text');
|
|
});
|
|
|
|
it('returns text for plain prose', () => {
|
|
expect(classifyToolResult('Hello, this is just some text.')).toBe('text');
|
|
});
|
|
|
|
it('returns text for shell-style line listings', () => {
|
|
expect(classifyToolResult('file1.java\nfile2.java\nfile3.java\n')).toBe('text');
|
|
});
|
|
|
|
it('returns text when a brace-like string is not valid JSON', () => {
|
|
expect(classifyToolResult('{key: value}')).toBe('text');
|
|
});
|
|
});
|
|
|
|
describe('json', () => {
|
|
it('classifies a flat JSON object', () => {
|
|
expect(classifyToolResult('{"key": "value", "n": 42}')).toBe('json');
|
|
});
|
|
|
|
it('classifies a JSON array', () => {
|
|
expect(classifyToolResult('["a", "b", "c"]')).toBe('json');
|
|
});
|
|
|
|
it('classifies a pretty-printed JSON object', () => {
|
|
expect(classifyToolResult('{\n "key": "value"\n}')).toBe('json');
|
|
});
|
|
|
|
it('classifies a deeply nested JSON payload', () => {
|
|
const nested = JSON.stringify({ items: [{ id: 1, tags: ['a', 'b'] }] }, null, 2);
|
|
expect(classifyToolResult(nested)).toBe('json');
|
|
});
|
|
|
|
it('prefers JSON over inner markdown markers when the content starts with a brace', () => {
|
|
// A JSON object whose inner strings contain link syntax still
|
|
// reads as JSON because the leading `{` parses cleanly -
|
|
// `classifyToolResult` only inspects the top-level shape, not
|
|
// every nested line marker.
|
|
const jsonWithLink = '{"docs": "see [docs](https://example.com) for more"}';
|
|
expect(classifyToolResult(jsonWithLink)).toBe('json');
|
|
});
|
|
});
|
|
|
|
describe('markdown', () => {
|
|
it('classifies an ATX header line', () => {
|
|
expect(classifyToolResult('# Title\n\nSome text below.')).toBe('markdown');
|
|
});
|
|
|
|
it('classifies a fenced code block', () => {
|
|
expect(classifyToolResult('```json\n{"key": "v"}\n```')).toBe('markdown');
|
|
});
|
|
|
|
it('classifies a tilde-fenced code block', () => {
|
|
expect(classifyToolResult('~~~bash\nls -la\n~~~')).toBe('markdown');
|
|
});
|
|
|
|
it('classifies a markdown link', () => {
|
|
expect(classifyToolResult('See [docs](https://example.com) for more.')).toBe('markdown');
|
|
});
|
|
|
|
it('classifies bold text', () => {
|
|
expect(classifyToolResult('This is **very important**.')).toBe('markdown');
|
|
});
|
|
|
|
it('classifies a bulleted list', () => {
|
|
expect(classifyToolResult('- item one\n- item two\n- item three')).toBe('markdown');
|
|
});
|
|
|
|
it('classifies an ordered list', () => {
|
|
expect(classifyToolResult('1. first step\n2. second step\n3. third step')).toBe('markdown');
|
|
});
|
|
|
|
it('classifies a blockquote', () => {
|
|
expect(classifyToolResult('> quoted text\n> second line')).toBe('markdown');
|
|
});
|
|
|
|
it('classifies a markdown table', () => {
|
|
const table = '| a | b |\n| - | - |\n| 1 | 2 |';
|
|
expect(classifyToolResult(table)).toBe('markdown');
|
|
});
|
|
|
|
it('classifies a markdown table with alignment markers', () => {
|
|
const table = '| left | center | right |\n| :--- | :---: | ---: |\n| a | b | c |';
|
|
expect(classifyToolResult(table)).toBe('markdown');
|
|
});
|
|
|
|
it('classifies nested markdown headings', () => {
|
|
expect(classifyToolResult('## Section\n\n### Subsection\n')).toBe('markdown');
|
|
});
|
|
|
|
it('classifies combined markdown markers in one document', () => {
|
|
const md = [
|
|
'# Heading',
|
|
'',
|
|
'A paragraph with a [link](https://example.com) and **bold text**.',
|
|
'',
|
|
'- bullet item',
|
|
'- another bullet',
|
|
'',
|
|
'| col1 | col2 |',
|
|
'| ----- | ----- |',
|
|
'| a | b |'
|
|
].join('\n');
|
|
expect(classifyToolResult(md)).toBe('markdown');
|
|
});
|
|
});
|
|
|
|
describe('precedence', () => {
|
|
it('prefers JSON over markdown when both signals are present', () => {
|
|
// Starts with `[`, parses as JSON - markdown check is skipped.
|
|
const arr = '[1, 2, "# not-a-heading", "**not-bold**"]';
|
|
expect(classifyToolResult(arr)).toBe('json');
|
|
});
|
|
});
|
|
});
|