mirror of
https://github.com/mudler/LocalAI.git
synced 2026-10-31 10:40:49 -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>
178 lines
9.5 KiB
JavaScript
178 lines
9.5 KiB
JavaScript
import { test, expect } from '@playwright/test'
|
|
import fs from 'node:fs'
|
|
|
|
// The add-ons foundation, seen from the browser through real servers. The
|
|
// runner (scripts/addons/foundation.sh) starts three UI test servers: the
|
|
// add-on owner and two frontends that hold no add-on state and forward to the
|
|
// owner over the pinned mTLS carrier. They share one account store, so a
|
|
// session is a stored key that every server decides about. The UI package was
|
|
// installed from a catalog after the host build and enabled through a
|
|
// frontend. Nothing here mocks a route: every refusal below is the server's.
|
|
//
|
|
// The specs end sessions and change the add-on's state, so they run in order.
|
|
|
|
const ready = JSON.parse(fs.readFileSync(process.env.ADDONS_FOUNDATION, 'utf8'))
|
|
const URLS = ready.urls
|
|
const ID = 'found-ui'
|
|
|
|
async function browserAs(browser, node, who, extra = {}) {
|
|
const base = URLS[node]
|
|
const context = await browser.newContext({ baseURL: base, ...extra })
|
|
await context.addCookies([{ name: 'session', value: ready.users[who].session, url: base }])
|
|
const page = await context.newPage()
|
|
return { context, page, base }
|
|
}
|
|
|
|
// A same-origin fetch from the page, so the server sees the metadata a real
|
|
// browser sends. It bypasses the HTTP cache: add-on assets are cacheable for a
|
|
// year by design, and what these specs ask is what the server answers.
|
|
const call = (page, method, path, body) => page.evaluate(async ({ method, path, body }) => {
|
|
const response = await fetch(path, { method, cache: 'no-store', headers: { 'content-type': 'application/json' }, body: body ? JSON.stringify(body) : undefined })
|
|
return { status: response.status, text: await response.text() }
|
|
}, { method, path, body })
|
|
|
|
const isAddonAsset = (url) => /\/api\/addons\/[^/]+\/assets\//.test(url)
|
|
// The drawer draws a tile for the add-on; its start and stop controls are in
|
|
// the card of the detail sheet (/app/addons?detail=ID).
|
|
const card = (page) => page.locator(`[data-testid="addon-tile"][data-app="${ID}"]`)
|
|
const sheetCard = (page) => page.getByTestId('addon-detail').locator(`[data-app="${ID}"]`)
|
|
|
|
test.describe.configure({ mode: 'serial' })
|
|
|
|
test.describe('Add-ons foundation through real servers', () => {
|
|
test('foundation: a member opens the add-on through each non-owner frontend and its module comes from the owner by digest', async ({ browser }) => {
|
|
for (const node of ['front-a', 'front-b']) {
|
|
const { context, page, base } = await browserAs(browser, node, 'member')
|
|
const answers = []
|
|
page.on('response', r => { if (isAddonAsset(r.url())) answers.push({ url: r.url(), status: r.status() }) })
|
|
await page.goto('/app/addons')
|
|
await expect(card(page)).toBeVisible({ timeout: 30_000 })
|
|
await card(page).getByRole('link').click()
|
|
await expect(page).toHaveURL(/\/app\/addons\/found-ui\/home$/)
|
|
await expect(page.getByTestId('fnd-title')).toHaveText('Foundation fixture', { timeout: 30_000 })
|
|
expect(answers.length).toBeGreaterThanOrEqual(1)
|
|
for (const a of answers) {
|
|
expect(a.status).toBe(200)
|
|
expect(new URL(a.url).origin).toBe(new URL(base).origin)
|
|
expect(new URL(a.url).pathname).toMatch(/^\/api\/addons\/found-ui\/assets\/[0-9a-f]{64}\//)
|
|
}
|
|
await context.close()
|
|
}
|
|
})
|
|
|
|
test('foundation: the owner and both frontends list the same add-on to the same account', async ({ browser }) => {
|
|
for (const node of ['owner', 'front-a', 'front-b']) {
|
|
const { context, page } = await browserAs(browser, node, 'member')
|
|
await page.goto('/app/addons')
|
|
await expect(card(page)).toBeVisible({ timeout: 30_000 })
|
|
await expect(card(page).locator('.ad-tile__state')).toHaveText('On')
|
|
await context.close()
|
|
}
|
|
})
|
|
|
|
test('foundation: a member sees the add-on list only and the server refuses every management request', async ({ browser }) => {
|
|
for (const node of ['front-a', 'front-b', 'owner']) {
|
|
const { context, page } = await browserAs(browser, node, 'member')
|
|
await page.goto('/app/addons')
|
|
await expect(card(page)).toBeVisible({ timeout: 30_000 })
|
|
await expect(page.getByRole('tablist')).toHaveCount(0)
|
|
await expect(page.getByRole('button', { name: /^Turn (on|off)$/ })).toHaveCount(0)
|
|
await expect(page.getByRole('link', { name: 'Manage' })).toHaveCount(0)
|
|
// The detail sheet hides them as well.
|
|
await page.goto(`/app/addons?detail=${ID}`)
|
|
await expect(sheetCard(page)).toBeVisible({ timeout: 30_000 })
|
|
await expect(page.getByRole('button', { name: /^Turn (on|off)$/ })).toHaveCount(0)
|
|
await expect(page.getByRole('link', { name: 'Manage' })).toHaveCount(0)
|
|
// The page hides the controls; the server is what refuses.
|
|
for (const action of ['install', 'upgrade', 'enable', 'disable', 'uninstall', 'catalog-sources', 'addons-installed']) {
|
|
const r = await call(page, 'POST', '/api/addons/dispatch', { operationId: `m-${node}-${action}`, addonId: ID, generation: 1, action, arguments: {} })
|
|
expect(r.status, `${node} ${action}`).toBe(403)
|
|
}
|
|
for (const verb of ['start', 'stop']) {
|
|
const r = await call(page, 'POST', `/api/addons/apps/${ID}/${verb}`, { operationId: `m-${node}-${verb}`, generation: 1 })
|
|
expect(r.status, `${node} ${verb}`).toBe(403)
|
|
}
|
|
await context.close()
|
|
}
|
|
})
|
|
|
|
test('foundation: an account without the add-ons feature gets no apps and no code on any node', async ({ browser }) => {
|
|
for (const node of ['front-a', 'front-b', 'owner']) {
|
|
const { context, page } = await browserAs(browser, node, 'outsider')
|
|
await page.goto('/app')
|
|
const apps = await call(page, 'GET', '/api/addons/apps')
|
|
expect(apps.status, node).toBe(403)
|
|
const asset = await call(page, 'GET', `/api/addons/${ID}/assets/${'0'.repeat(64)}/ui.js`)
|
|
expect(asset.status, node).toBe(403)
|
|
await page.goto(`/app/addons/${ID}/home`)
|
|
await expect(page.getByTestId('fnd-title')).toHaveCount(0)
|
|
await context.close()
|
|
}
|
|
})
|
|
|
|
test('foundation: an administrator manages through a frontend and the change is the owner\'s', async ({ browser }) => {
|
|
const { context, page } = await browserAs(browser, 'front-b', 'admin')
|
|
await page.goto('/app/addons')
|
|
await expect(card(page)).toBeVisible({ timeout: 30_000 })
|
|
await expect(page.getByRole('tablist')).toBeVisible()
|
|
await page.goto(`/app/addons?detail=${ID}`)
|
|
await sheetCard(page).getByRole('button', { name: 'Turn off' }).click()
|
|
await expect(sheetCard(page).getByRole('img', { name: 'State: Off' })).toBeVisible({ timeout: 30_000 })
|
|
// The other frontend and the owner see the same stopped add-on: the
|
|
// administrator in the list with its state, a member not at all, because
|
|
// the owner lists a disabled add-on to administrators only.
|
|
for (const node of ['front-a', 'owner']) {
|
|
const other = await browserAs(browser, node, 'admin')
|
|
await other.page.goto(`/app/addons?detail=${ID}`)
|
|
await expect(sheetCard(other.page).getByRole('img', { name: 'State: Off' })).toBeVisible({ timeout: 30_000 })
|
|
await other.context.close()
|
|
const member = await browserAs(browser, node, 'member')
|
|
await member.page.goto('/app/addons')
|
|
await expect(member.page.getByTestId('addons')).toBeVisible({ timeout: 30_000 })
|
|
await expect(card(member.page)).toHaveCount(0)
|
|
await member.context.close()
|
|
}
|
|
await sheetCard(page).getByRole('button', { name: 'Turn on' }).click()
|
|
await expect(sheetCard(page).getByRole('img', { name: 'State: On' })).toBeVisible({ timeout: 30_000 })
|
|
await context.close()
|
|
})
|
|
|
|
test('foundation: deep links of the add-on page work behind a proxy path prefix on a non-owner frontend', async ({ browser }) => {
|
|
const { context, page } = await browserAs(browser, 'front-a', 'member', { extraHTTPHeaders: { 'X-Forwarded-Prefix': '/llm' } })
|
|
const assets = []
|
|
page.on('request', r => { if (isAddonAsset(r.url())) assets.push(new URL(r.url()).pathname) })
|
|
await page.goto('/llm/app/addons/found-ui/home')
|
|
await expect(page.getByTestId('fnd-title')).toBeVisible({ timeout: 30_000 })
|
|
expect(assets.length).toBeGreaterThanOrEqual(1)
|
|
for (const p of assets) expect(p).toMatch(/^\/llm\/api\/addons\/found-ui\/assets\/[0-9a-f]{64}\//)
|
|
// A reload of the deep link keeps the prefix and the page.
|
|
await page.reload()
|
|
await expect(page.getByTestId('fnd-title')).toBeVisible({ timeout: 30_000 })
|
|
await expect(page).toHaveURL(/\/llm\/app\/addons\/found-ui\/home$/)
|
|
await context.close()
|
|
})
|
|
|
|
test('foundation: a session ended through one frontend is refused for add-on assets by the other servers', async ({ browser }) => {
|
|
const a = await browserAs(browser, 'front-a', 'friend')
|
|
await a.page.goto(`/app/addons/${ID}/home`)
|
|
await expect(a.page.getByTestId('fnd-title')).toBeVisible({ timeout: 30_000 })
|
|
const entry = (await call(a.page, 'GET', '/api/addons/apps').then(r => JSON.parse(r.text))).apps.find(x => x.id === ID).ui.entry
|
|
expect((await call(a.page, 'GET', entry)).status).toBe(200)
|
|
|
|
const b = await browserAs(browser, 'front-b', 'friend')
|
|
await b.page.goto('/app')
|
|
expect((await call(b.page, 'GET', entry)).status).toBe(200)
|
|
|
|
const out = await call(a.page, 'POST', '/api/auth/logout')
|
|
expect(out.status).toBe(200)
|
|
for (const [label, page] of [['front-a', a.page], ['front-b', b.page]]) {
|
|
const r = await call(page, 'GET', entry)
|
|
expect(r.status, label).toBe(401)
|
|
}
|
|
await b.page.goto(`/app/addons/${ID}/home`)
|
|
await expect(b.page.getByTestId('fnd-title')).toHaveCount(0)
|
|
await a.context.close()
|
|
await b.context.close()
|
|
})
|
|
})
|