mirror of
https://github.com/mudler/LocalAI.git
synced 2026-10-30 10:09:13 -04:00
* refactor(addons): one name and one verb pair in the add-ons UI The sidebar, the page and the tabs now say Add-ons. The tabs are My add-ons, Find add-ons and Sources. Turn on and Turn off replace Enable, Start, Disable and Stop wherever they label a button, and the state words read On and Off. The subtitle no longer names the owner. Other locales get the new keys; the main labels are translated and the rest carry the English text until a translator refines them. A unit test checks that every locale has the keys of English. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): show what an add-on does on its card and move actions to a menu A card now shows the add-on description, an "Adds a page" line and the number of chat tools when they apply. The pin button and the bare arrows are replaced by one overflow menu with Show in sidebar, Details and Remove. Reordering a pinned add-on stays in the same menu. Remove asks first and runs the typed uninstall action; only administrators see it. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): add a preview pane for the selected add-on Selecting a card, or choosing Details in its menu, opens a pane beside the list. It shows the name and state, the description, what the add-on adds, Turn on or Turn off and Remove, and its version and source. The pane replaces the modal sheet and uses the data the list already has. The source comes from the installed list that the host already serves to administrators. Screenshot slots show only when the host lists images for the add-on; today it lists none, so no slot is drawn. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): clear first-run and empty states for My add-ons With nothing installed, an administrator now sees three add-ons from the sources, each with Install and turn on, and a link to Find add-ons. A search that finds nothing says that no add-on matches and offers to clear the search, instead of saying that nothing is installed. Install and turn on is one action of the user: it installs, then turns the add-on on, with a separate operation identity for each step and the progress or the reason for a failure shown on the card. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): one button and folded details on Find add-ons entries Each entry shows its description, an "Adds a page" label when the library entry declares a main page, and one button: Install and turn on. An add-on that is installed but off offers Turn on. Details is folded into the entry and shows the trust and build facts the entry already carries, so the separate details sheet is gone. A backend keeps a plain Install, because a backend has no on or off. The library entry carries no tool count, so the entry cannot say how many chat tools an add-on adds. That label appears on My add-ons, where the list knows it. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): install and turn on in one dialog with inline progress Install and turn on now asks once. The dialog then stays open and shows two steps, the install and the turn on, and ends on the result or on the reason a step failed with a way to try again. A failed turn on keeps the install and the retry only turns the add-on on. Each step is its own action with its own operation identity, so an unknown outcome still blocks further actions on the add-on until it is read or dismissed. The first-run cards use the same dialog. The two-step flow is a plain function with unit tests. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactor(addons): fold the Installed tab into My add-ons The page now has three tabs: My add-ons, Find add-ons and Sources. What the Installed tab showed is in the preview pane of each add-on, under More details for administrators: health, trust, compatibility, storage, data recovery and updates, with Check for updates and Upgrade. Remove and Turn on or Turn off are on the card and in the pane. An old ?tab=installed address opens My add-ons, and the management link ?manage=ID opens the details of that add-on. A card shows an update mark when the host reports one. Closing the pane returns focus to its card. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * docs(addons): describe the new add-ons page labels Update the add-ons feature page and the pages that point at it: the sidebar item and the page are called Add-ons, the tabs are My add-ons, Find add-ons and Sources, Turn on and Turn off replace Start and Stop, the card menu replaces the pin control, and the preview pane holds what the Installed tab showed. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): say what is wrong on the page of an add-on that cannot open The page of an add-on that cannot open now depends on the add-on. One that is installed but off says "<name> is off" and offers Turn on to an administrator. One that is not installed says so and sends an administrator to Find add-ons. One that failed shows the reason and a link to its details. A reader gets a line that says who can fix it, and no button. The page title is the name of the add-on, with a capital first letter when the host lists no title, and no longer the bare identifier. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(chat): put the add-on tools control next to MCP and say what off means The add-on tools control moves from the chat header to the composer, right after the MCP control, because both decide what the model may call in this chat. Its menu starts with one line: an add-on that is off here does nothing in this chat. Only add-ons that ship tools appear in it, as before. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore(addons): clear lint warnings of the new components Add the lint header the add-on components use for JSX-only imports, drop an unneeded directive, stop exporting a helper from a component file and extract the dependencies of an effect. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * test(addons): update the backend library specs for the folded entry details A backend says its kind on the entry, an add-on says it under Details, Details is a fold of the entry and an installed backend has no Install button. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
187 lines
9.7 KiB
JavaScript
187 lines
9.7 KiB
JavaScript
import { test, expect } from './coverage-fixtures.js'
|
|
import { chatOf, pair, mockChat, answerWith, CHATS_KEY } from './chat-fixtures.js'
|
|
import { MEMBER, app, sessionFor, mockAddons } from './addons-fixtures.js'
|
|
|
|
// The add-ons control in the chat composer, next to the MCP control, lists the add-ons that ship tools,
|
|
// one switch each, and shows how many are on. The /addons command of the
|
|
// composer flips all of them and stays in step with it.
|
|
|
|
const TOOL = { name: 'run', kind: 'read', description: 'x', inputSchema: { type: 'object' } }
|
|
const NOTES = app({ id: 'notes', title: 'Notes', toolDefinitions: [TOOL] })
|
|
const INDEXER = app({ id: 'indexer', title: 'Indexer', icon: undefined, toolDefinitions: [TOOL] })
|
|
// Running, but its manifest declares no tool: never listed.
|
|
const VIEWER = app({ id: 'viewer', title: 'Viewer', toolDefinitions: [] })
|
|
// Has tools but is stopped: not offered.
|
|
const STOPPED = app({ id: 'idle', title: 'Idle', enabled: false, state: 'stopped', toolDefinitions: [TOOL] })
|
|
|
|
const button = (page) => page.getByTestId('chat-addons-button')
|
|
const items = (page) => page.getByTestId('chat-addon-item')
|
|
const input = (page) => page.getByTestId('chat-input')
|
|
|
|
// The signed-in person's chats live under a key of their own.
|
|
const KEY = `${CHATS_KEY}:${MEMBER.id}`
|
|
|
|
async function openChat(page, chats) {
|
|
await page.addInitScript(([key, data]) => {
|
|
if (!localStorage.getItem(key)) localStorage.setItem(key, JSON.stringify(data))
|
|
}, [KEY, { chats, activeChatId: chats[0].id, lastSaved: Date.now() }])
|
|
await page.goto('/app/chat')
|
|
await page.getByTestId('chat-composer').waitFor()
|
|
}
|
|
|
|
const storedChats = (page) => page.evaluate((key) => JSON.parse(localStorage.getItem(key) || '{}'), KEY)
|
|
|
|
async function setup(page, apps, user = MEMBER) {
|
|
await mockChat(page)
|
|
await page.route('**/api/auth/status', route => route.fulfill({ json: sessionFor(user, { addons: true }) }))
|
|
await mockAddons(page, { apps })
|
|
}
|
|
|
|
test.describe('Chat add-ons control', () => {
|
|
test('lists only the add-ons that ship tools, with name and icon, and nothing else', async ({ page }) => {
|
|
await setup(page, [NOTES, INDEXER, VIEWER, STOPPED])
|
|
await openChat(page, [chatOf('c1', 'Add-ons', 'qwen3-8b', pair('hi', 'hello'))])
|
|
await expect(button(page)).toBeVisible()
|
|
await expect(page.getByTestId('chat-addons-count')).toHaveCount(0)
|
|
await button(page).click()
|
|
await expect(page.getByTestId('chat-addons-menu')).toBeVisible()
|
|
await expect(items(page)).toHaveCount(2)
|
|
await expect(items(page).nth(0)).toContainText('Notes')
|
|
await expect(items(page).nth(1)).toContainText('Indexer')
|
|
await expect(items(page).nth(0).locator('img.ad-icon')).toBeVisible()
|
|
await expect(items(page).nth(1).locator('.ad-icon--empty')).toBeVisible()
|
|
await expect(page.getByTestId('chat-addons-menu')).not.toContainText('Viewer')
|
|
await expect(page.getByTestId('chat-addons-menu')).not.toContainText('Idle')
|
|
// The menu closes on Escape.
|
|
await page.keyboard.press('Escape')
|
|
await expect(page.getByTestId('chat-addons-menu')).toHaveCount(0)
|
|
})
|
|
|
|
test('sits right after the MCP control in the composer, not in the chat header', async ({ page }) => {
|
|
await setup(page, [NOTES])
|
|
await openChat(page, [chatOf('c1', 'Place', 'qwen3-8b', pair('hi', 'hello'))])
|
|
await expect(button(page)).toBeVisible()
|
|
await expect(page.getByTestId('chat-header').getByTestId('chat-addons')).toHaveCount(0)
|
|
const beside = await page.getByTestId('chat-addons').evaluate(el => {
|
|
const before = el.previousElementSibling
|
|
return Boolean(before && before.classList.contains('chat-mcp-dropdown') && before.textContent.includes('MCP') && el.parentElement === before.parentElement)
|
|
})
|
|
expect(beside).toBe(true)
|
|
})
|
|
|
|
test('says in one line that an add-on that is off does nothing in this chat', async ({ page }) => {
|
|
await setup(page, [NOTES, INDEXER, VIEWER])
|
|
await openChat(page, [chatOf('c1', 'Line', 'qwen3-8b', pair('hi', 'hello'))])
|
|
await button(page).click()
|
|
const menu = page.getByTestId('chat-addons-menu')
|
|
const note = menu.getByTestId('chat-addons-note')
|
|
await expect(note).toHaveText('An add-on that is off here does nothing in this chat.')
|
|
// One line: a single text node paragraph, tied to the control by its description.
|
|
await expect(button(page)).toHaveAttribute('aria-describedby', await note.getAttribute('id'))
|
|
// Only the add-ons that ship tools are listed under it.
|
|
await expect(items(page)).toHaveCount(2)
|
|
await expect(menu).not.toContainText('Viewer')
|
|
})
|
|
|
|
test('shows nothing when no add-on ships tools', async ({ page }) => {
|
|
await setup(page, [VIEWER, STOPPED])
|
|
await openChat(page, [chatOf('c1', 'None', 'qwen3-8b', pair('hi', 'hello'))])
|
|
await expect(page.getByTestId('chat-header')).toBeVisible()
|
|
await expect(page.getByTestId('chat-addons')).toHaveCount(0)
|
|
await input(page).fill('/')
|
|
await expect(page.getByRole('option', { name: /\/addons/ })).toHaveCount(0)
|
|
})
|
|
|
|
test('shows nothing without the add-ons feature', async ({ page }) => {
|
|
await mockChat(page)
|
|
await page.route('**/api/auth/status', route => route.fulfill({ json: sessionFor(MEMBER, { addons: false }) }))
|
|
await mockAddons(page, { apps: [NOTES] })
|
|
await openChat(page, [chatOf('c1', 'None', 'qwen3-8b', pair('hi', 'hello'))])
|
|
await expect(page.getByTestId('chat-addons')).toHaveCount(0)
|
|
})
|
|
|
|
test('a switch turns one add-on on for this chat, counts it, and stores the list on the chat', async ({ page }) => {
|
|
await setup(page, [NOTES, INDEXER])
|
|
await openChat(page, [chatOf('c1', 'One', 'qwen3-8b', pair('hi', 'hello')), chatOf('c2', 'Two', 'qwen3-8b', pair('a', 'b'), {}, Date.now() - 1000)])
|
|
await button(page).click()
|
|
await items(page).nth(0).getByRole('checkbox').check()
|
|
await expect(page.getByTestId('chat-addons-count')).toHaveText('1')
|
|
await expect(items(page).nth(0).getByRole('checkbox')).toBeChecked()
|
|
await expect(items(page).nth(1).getByRole('checkbox')).not.toBeChecked()
|
|
await items(page).nth(1).getByRole('checkbox').check()
|
|
await expect(page.getByTestId('chat-addons-count')).toHaveText('2')
|
|
await items(page).nth(0).getByRole('checkbox').uncheck()
|
|
await expect(page.getByTestId('chat-addons-count')).toHaveText('1')
|
|
await expect.poll(async () => (await storedChats(page)).chats?.find(c => c.id === 'c1')?.addonToolIds).toEqual(['indexer'])
|
|
// The other chat keeps its own selection.
|
|
const stored = await storedChats(page)
|
|
expect(stored.chats.find(c => c.id === 'c2').addonToolIds).toBeUndefined()
|
|
})
|
|
|
|
test('the select-all link flips every add-on', async ({ page }) => {
|
|
await setup(page, [NOTES, INDEXER])
|
|
await openChat(page, [chatOf('c1', 'All', 'qwen3-8b', pair('hi', 'hello'))])
|
|
await button(page).click()
|
|
await page.getByTestId('chat-addons-all').click()
|
|
await expect(page.getByTestId('chat-addons-count')).toHaveText('2')
|
|
await expect(page.getByTestId('chat-addons-all')).toHaveText('Deselect all')
|
|
await page.getByTestId('chat-addons-all').click()
|
|
await expect(page.getByTestId('chat-addons-count')).toHaveCount(0)
|
|
})
|
|
|
|
test('/addons flips all add-ons and the composer control shows it, in step with the switches', async ({ page }) => {
|
|
await setup(page, [NOTES, INDEXER])
|
|
await openChat(page, [chatOf('c1', 'Slash', 'qwen3-8b', pair('hi', 'hello'))])
|
|
await input(page).fill('/addons')
|
|
await input(page).press('Enter')
|
|
await expect(page.getByText('Add-on tools on for this chat')).toBeVisible()
|
|
await expect(page.getByTestId('chat-addons-count')).toHaveText('2')
|
|
await button(page).click()
|
|
await items(page).nth(0).getByRole('checkbox').uncheck()
|
|
await expect(page.getByTestId('chat-addons-count')).toHaveText('1')
|
|
// With some on, /addons turns them all off.
|
|
await input(page).fill('/addons')
|
|
await input(page).press('Enter')
|
|
await expect(page.getByText('Add-on tools off for this chat')).toBeVisible()
|
|
await expect(page.getByTestId('chat-addons-count')).toHaveCount(0)
|
|
await expect(items(page).nth(1).getByRole('checkbox')).not.toBeChecked()
|
|
})
|
|
|
|
test('the request sends the boolean when every add-on is on, the list when some are, nothing when none', async ({ page }) => {
|
|
await setup(page, [NOTES, INDEXER])
|
|
const sent = await answerWith(page, 'ok')
|
|
await openChat(page, [chatOf('c1', 'Send', 'qwen3-8b', pair('hi', 'hello'))])
|
|
const send = async (text) => {
|
|
await input(page).fill(text)
|
|
await input(page).press('Enter')
|
|
await expect(page.getByText('ok').last()).toBeVisible()
|
|
}
|
|
|
|
await send('none on')
|
|
expect(sent.request().metadata?.addon_tools).toBeUndefined()
|
|
expect(sent.request().metadata?.addon_tool_ids).toBeUndefined()
|
|
|
|
await button(page).click()
|
|
await items(page).nth(1).getByRole('checkbox').check()
|
|
await send('some on')
|
|
expect(sent.request().metadata).toMatchObject({ addon_tools: 'true', addon_tool_ids: 'indexer' })
|
|
|
|
await items(page).nth(0).getByRole('checkbox').check()
|
|
await send('all on')
|
|
expect(sent.request().metadata.addon_tools).toBe('true')
|
|
expect(sent.request().metadata.addon_tool_ids).toBeUndefined()
|
|
})
|
|
|
|
test('a chat saved with the older boolean means every add-on', async ({ page }) => {
|
|
await setup(page, [NOTES, INDEXER])
|
|
const sent = await answerWith(page, 'ok')
|
|
await openChat(page, [chatOf('c1', 'Old', 'qwen3-8b', pair('hi', 'hello'), { addonTools: true })])
|
|
await expect(page.getByTestId('chat-addons-count')).toHaveText('2')
|
|
await input(page).fill('hello')
|
|
await input(page).press('Enter')
|
|
await expect(page.getByText('ok').last()).toBeVisible()
|
|
expect(sent.request().metadata).toMatchObject({ addon_tools: 'true' })
|
|
expect(sent.request().metadata.addon_tool_ids).toBeUndefined()
|
|
})
|
|
})
|