mirror of
https://github.com/mudler/LocalAI.git
synced 2026-11-01 18:19:50 -05: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>
233 lines
14 KiB
JavaScript
233 lines
14 KiB
JavaScript
import { test, expect } from '@playwright/test'
|
|
import { ADMIN, release, sessionFor, mockAddons } from './addons-fixtures.js'
|
|
|
|
// Backends in the library (phase 1): an entry has a kind, the Browse tab shows
|
|
// it, and a backend installs through the backend route, not the add-on
|
|
// lifecycle. The server is the authority, so these specs drive the page
|
|
// against a stand-in and assert what the page sent.
|
|
|
|
const POLICY = { requireSignature: true, issuer: 'https://token.actions.githubusercontent.com', identityRegex: '^https://github\\.com/o/r/\\.github/workflows/w\\.yml@refs/(heads/master|tags/.+)$' }
|
|
const backend = (over = {}) => release('cpu-local-store', {
|
|
kind: 'backend', name: 'cpu-local-store', alias: 'local-store', description: 'A vector store.', version: '0.0.0-latest.0a1056fd8633',
|
|
sourceId: 'official-backends', artifact: 'oci://registry.example/backends:latest-cpu-local-store', policy: POLICY, ...over,
|
|
})
|
|
|
|
async function signIn(page) {
|
|
await page.route('**/api/auth/status', route => route.fulfill({ json: sessionFor(ADMIN) }))
|
|
}
|
|
|
|
// The backend routes of the host. `installed` is the mutable list GET /backends
|
|
// answers. An install is a job: the request answers with its ID and the job
|
|
// route reports the steps in `phases`, one per read, then the result. `fail`
|
|
// ends the job with that error at the last step reached.
|
|
async function mockBackends(page, { installed = [], phases = ['resolving', 'size', 'fetching', 'writing'], fail, refuse } = {}) {
|
|
const state = { installed: [...installed], installs: [], reads: 0 }
|
|
await page.route(/\/backends$/, route => route.fulfill({ json: state.installed }))
|
|
await page.route(/\/backends\/library\/install$/, route => {
|
|
const body = route.request().postDataJSON()
|
|
state.installs.push(body)
|
|
state.reads = 0
|
|
if (refuse) return route.fulfill(refuse)
|
|
return route.fulfill({ json: { id: 'job-1', status_url: '/backends/jobs/job-1' } })
|
|
})
|
|
await page.route(/\/backends\/jobs\/job-1$/, route => {
|
|
const body = state.installs.at(-1)
|
|
const at = state.reads++
|
|
const phase = phases[Math.min(at, phases.length - 1)]
|
|
const last = at >= phases.length
|
|
if (last && fail) return route.fulfill({ json: { phase, processed: true, error: fail, message: `error: ${fail}` } })
|
|
if (last) {
|
|
state.installed.push({ Name: body.name, Metadata: { library: body.sourceId } })
|
|
return route.fulfill({ json: { phase: 'done', processed: true, progress: 100, message: 'completed' } })
|
|
}
|
|
return route.fulfill({ json: { phase, processed: false, progress: phase === 'fetching' ? 40 : 0 } })
|
|
})
|
|
return state
|
|
}
|
|
|
|
test.describe('Library backends', () => {
|
|
test('browse: an entry shows its kind, and add-ons are still add-ons', async ({ page }) => {
|
|
await signIn(page)
|
|
const state = await mockAddons(page, { installed: [], releases: [release('tables'), backend()] })
|
|
await mockBackends(page)
|
|
await page.goto('/app/addons?tab=browse')
|
|
await expect(page.locator('.cat-item')).toHaveCount(2)
|
|
// A backend says what it is on the entry; an add-on is the default and says it under Details.
|
|
const tables = page.locator('.cat-item', { hasText: 'Tables' })
|
|
await expect(tables.getByTestId('entry-kind')).toHaveCount(0)
|
|
await tables.getByText('Details', { exact: true }).click()
|
|
await expect(tables.getByTestId('details-kind')).toHaveText('Add-on')
|
|
const row = page.locator('.cat-item', { hasText: 'cpu-local-store' })
|
|
await expect(row.getByTestId('entry-kind')).toHaveText('Backend')
|
|
await expect(row.getByTestId('entry-kind')).toHaveAttribute('data-kind', 'backend')
|
|
// The page asks for every kind this host reads.
|
|
expect(state.log.dispatch.find(d => d.action === 'catalog-search').arguments.kind).toBe('all')
|
|
})
|
|
|
|
test('browse: a backend installs through the backend route and never through the add-on lifecycle', async ({ page }) => {
|
|
await signIn(page)
|
|
const state = await mockAddons(page, { installed: [], releases: [backend()] })
|
|
const backends = await mockBackends(page)
|
|
await page.goto('/app/addons?tab=browse')
|
|
const row = page.locator('.cat-item', { hasText: 'cpu-local-store' })
|
|
await row.getByRole('button', { name: 'Install' }).click()
|
|
const dialog = page.getByRole('alertdialog')
|
|
await expect(dialog).toContainText('Install cpu-local-store?')
|
|
await expect(dialog).toContainText('backend gallery is not changed')
|
|
await expect(dialog).toContainText('native code')
|
|
expect(backends.installs).toHaveLength(0)
|
|
await dialog.getByRole('button', { name: 'Install' }).click()
|
|
// The steps show while the job runs: a signed library lists the signature step.
|
|
const steps = row.getByTestId('install-steps')
|
|
await expect(steps.locator('[data-step]')).toHaveCount(5)
|
|
await expect(steps.locator('[data-step="fetching"]')).toHaveAttribute('data-state', /active|done/)
|
|
await expect(row.getByText('Installed as a backend on this node')).toBeVisible()
|
|
await expect(steps).toHaveCount(0)
|
|
expect(backends.installs).toEqual([{ sourceId: 'official-backends', name: 'cpu-local-store', version: '0.0.0-latest.0a1056fd8633' }])
|
|
expect(state.log.dispatch.filter(d => d.action === 'install')).toHaveLength(0)
|
|
// Once installed the entry says so and offers no second install.
|
|
await expect(row.getByText('Installed', { exact: true })).toBeVisible()
|
|
await expect(row.getByRole('button', { name: 'Install' })).toHaveCount(0)
|
|
})
|
|
|
|
test('browse: a refusal of the host is shown with its own reason', async ({ page }) => {
|
|
await signIn(page)
|
|
await mockAddons(page, { installed: [], releases: [backend()] })
|
|
await mockBackends(page, {
|
|
phases: ['resolving'],
|
|
fail: 'backend is already installed from another origin: "cpu-local-store"',
|
|
})
|
|
await page.goto('/app/addons?tab=browse')
|
|
const row = page.locator('.cat-item', { hasText: 'cpu-local-store' })
|
|
await row.getByRole('button', { name: 'Install' }).click()
|
|
await page.getByRole('alertdialog').getByRole('button', { name: 'Install' }).click()
|
|
await expect(row.getByRole('alert')).toContainText('The backend was not installed.')
|
|
await expect(row.getByRole('alert')).toContainText('already installed from another origin')
|
|
await expect(row.getByRole('button', { name: 'Install' })).toBeEnabled()
|
|
// The step that failed stays marked.
|
|
await expect(row.locator('[data-step="resolving"]')).toHaveAttribute('data-state', 'failed')
|
|
await expect(row.locator('[data-step="fetching"]')).toHaveAttribute('data-state', 'pending')
|
|
})
|
|
|
|
test('browse: a request the host refuses is shown with its reason', async ({ page }) => {
|
|
await signIn(page)
|
|
await mockAddons(page, { installed: [], releases: [backend()] })
|
|
await mockBackends(page, { refuse: { status: 409, json: { error: { type: 'backend_library', code: 409, message: 'this backend is already being installed' } } } })
|
|
await page.goto('/app/addons?tab=browse')
|
|
const row = page.locator('.cat-item', { hasText: 'cpu-local-store' })
|
|
await row.getByRole('button', { name: 'Install' }).click()
|
|
await page.getByRole('alertdialog').getByRole('button', { name: 'Install' }).click()
|
|
await expect(row.getByRole('alert')).toContainText('already being installed')
|
|
})
|
|
|
|
test('browse: the details give the kind, the alias and the signer pattern', async ({ page }) => {
|
|
await signIn(page)
|
|
await mockAddons(page, { installed: [], releases: [backend()] })
|
|
await mockBackends(page)
|
|
await page.goto('/app/addons?tab=browse')
|
|
await page.locator('.cat-item', { hasText: 'cpu-local-store' }).getByText('Details', { exact: true }).click()
|
|
await expect(page.getByTestId('details-kind')).toHaveText('Backend')
|
|
await expect(page.getByText('local-store', { exact: true })).toBeVisible()
|
|
await expect(page.getByText('workflows/w', { exact: false })).toBeVisible()
|
|
})
|
|
|
|
test('libraries: a signer pattern is edited and saved without an exact identity, and skipped entries are reported', async ({ page }) => {
|
|
await signIn(page)
|
|
const state = await mockAddons(page, {
|
|
sources: [{ id: 'official-backends', name: 'Official backends', url: 'https://catalog.example/backends.yaml', enabled: true, policy: POLICY, refresh: { checkedAt: new Date().toISOString(), lastSuccess: new Date().toISOString(), count: 1, skipped: 2, skippedKinds: ['model'], failed: false } }],
|
|
})
|
|
await mockBackends(page)
|
|
await page.goto('/app/addons?tab=libraries')
|
|
await expect(page.getByTestId('skipped-kinds')).toContainText('2 entries skipped: kind model')
|
|
await page.getByRole('button', { name: 'Edit' }).click()
|
|
const pattern = page.getByLabel('Signer identity pattern (optional)')
|
|
await expect(pattern).toHaveValue(POLICY.identityRegex)
|
|
await page.getByRole('button', { name: 'Save' }).click()
|
|
await expect.poll(() => state.log.dispatch.filter(d => d.action === 'catalog-source-save').length).toBe(1)
|
|
const saved = state.log.dispatch.find(d => d.action === 'catalog-source-save').arguments
|
|
expect(saved.policy).toEqual(POLICY)
|
|
})
|
|
})
|
|
|
|
// The Backends page (phase 2): a backend that came from a library says so, and
|
|
// a newer build in its library is an update the administrator starts.
|
|
const PINNED = 'sha256:' + 'a1'.repeat(32)
|
|
const NEWER = 'sha256:' + 'b2'.repeat(32)
|
|
|
|
async function mockBackendsPage(page, { updates = true, phases = ['resolving', 'verifying', 'size', 'fetching', 'writing'] } = {}) {
|
|
const state = { digest: PINNED, updates: updates ? [{ name: 'cpu-local-store', sourceId: 'official-backends', installedVersion: '0.0.0-latest.0a1056fd8633', installedDigest: PINNED, version: '0.0.0-latest.0b2', digest: NEWER, signed: true }] : [], installs: [], reads: 0 }
|
|
await page.route('**/api/backends?*', route => route.fulfill({ json: { backends: [] } }))
|
|
await page.route('**/api/backends/upgrades', route => route.fulfill({ json: { 'llama-cpp': { backend_name: 'llama-cpp', installed_version: '1', available_version: '2' } } }))
|
|
await page.route(/\/backends$/, route => route.fulfill({
|
|
json: [
|
|
{ Name: 'cpu-local-store', Metadata: { name: 'cpu-local-store', library: 'official-backends', digest: state.digest, version: '0.0.0-latest.0a1056fd8633' } },
|
|
{ Name: 'llama-cpp', Metadata: { name: 'llama-cpp', gallery_url: 'https://gallery.example/index.yaml', version: '1' } },
|
|
],
|
|
}))
|
|
await page.route(/\/backends\/library\/updates$/, route => route.fulfill({ json: { updates: state.updates } }))
|
|
await page.route(/\/backends\/library\/install$/, route => {
|
|
state.installs.push(route.request().postDataJSON())
|
|
state.reads = 0
|
|
return route.fulfill({ json: { id: 'job-2', status_url: '/backends/jobs/job-2' } })
|
|
})
|
|
await page.route(/\/backends\/jobs\/job-2$/, route => {
|
|
const at = state.reads++
|
|
if (at >= phases.length) {
|
|
state.digest = NEWER
|
|
state.updates = []
|
|
return route.fulfill({ json: { phase: 'done', processed: true, progress: 100, message: 'completed' } })
|
|
}
|
|
return route.fulfill({ json: { phase: phases[at], processed: false, progress: 0 } })
|
|
})
|
|
return state
|
|
}
|
|
|
|
test.describe('Backends page and libraries', () => {
|
|
test('a library backend carries its library and the digest it pinned; a gallery backend does not', async ({ page }) => {
|
|
await signIn(page)
|
|
await mockBackendsPage(page)
|
|
await page.goto('/app/backends?view=installed')
|
|
const row = page.locator('[data-entity="cpu-local-store"]')
|
|
await expect(row.getByTestId('backend-library')).toContainText('Library: official-backends')
|
|
await expect(page.locator('[data-entity="llama-cpp"]').getByTestId('backend-library')).toHaveCount(0)
|
|
await row.click()
|
|
const detail = page.getByTestId('backend-detail')
|
|
await expect(detail.getByTestId('library-id')).toHaveText('official-backends')
|
|
await expect(detail).toContainText('Pinned digest')
|
|
await expect(detail).toContainText(PINNED)
|
|
})
|
|
|
|
test('a newer build in the library shows as an update and is installed only on request', async ({ page }) => {
|
|
await signIn(page)
|
|
const state = await mockBackendsPage(page)
|
|
await page.goto('/app/backends?view=installed')
|
|
const row = page.locator('[data-entity="cpu-local-store"]')
|
|
await expect(row).toContainText('Update available')
|
|
// Nothing is installed by looking at the page.
|
|
expect(state.installs).toHaveLength(0)
|
|
await row.click()
|
|
await expect(page.getByTestId('library-update-facts')).toContainText('sha256:b2b2b2b2b2b2')
|
|
await row.getByTestId('backend-library-update').click()
|
|
await expect.poll(() => state.installs).toEqual([{ sourceId: 'official-backends', name: 'cpu-local-store', version: '0.0.0-latest.0b2' }])
|
|
// The steps of the install show in the detail while it runs.
|
|
await expect(page.getByTestId('backend-detail').getByTestId('install-steps').locator('[data-step]')).toHaveCount(5)
|
|
// When it ends the row is current and pins the new digest.
|
|
await expect(row).not.toContainText('Update available', { timeout: 15000 })
|
|
await expect(page.getByTestId('backend-detail')).toContainText(NEWER)
|
|
await expect(row.getByTestId('backend-library-update')).toHaveCount(0)
|
|
})
|
|
|
|
test('with no newer build the library backend is current, and gallery upgrades are unchanged', async ({ page }) => {
|
|
await signIn(page)
|
|
const state = await mockBackendsPage(page, { updates: false })
|
|
await page.goto('/app/backends?view=installed')
|
|
await expect(page.locator('[data-entity="cpu-local-store"]')).toContainText('Current')
|
|
await expect(page.locator('[data-entity="cpu-local-store"]').getByTestId('backend-library-update')).toHaveCount(0)
|
|
// The gallery backend keeps the gallery upgrade state and button.
|
|
const gallery = page.locator('[data-entity="llama-cpp"]')
|
|
await expect(gallery).toContainText('Update')
|
|
await expect(gallery.getByRole('button', { name: 'Update llama-cpp' })).toBeVisible()
|
|
expect(state.installs).toHaveLength(0)
|
|
})
|
|
})
|