The open-source AI receptionist for businesses. Answers every call, books the appointment and hands over to a person when needed. You own the code and the data.
TypeScript ai-receptionistanswering-serviceappointment-bookinglivekitlocal-firstmcpopen-sourceself-hostedsiptelephonytypescriptvoice-agentvoice-ai
Main dialogs in the address: New contact, Import, New call, Add a number, keyboard shortcuts; Back closes them (PR 2001)
Tim Gutberleta92e14f93e5b
diff --git a/apps/web/e2e/agent.e2e.ts b/apps/web/e2e/agent.e2e.tsindex eeb2613a..8b93502f 100644--- a/apps/web/e2e/agent.e2e.ts+++ b/apps/web/e2e/agent.e2e.ts@@ -93,6 +93,75 @@ test('Insights: the period and the chart are in the address', async ({ page }) =await expect(page.getByRole('tab', { selected: true })).toContainText(/missed/i)})+test('dialogs that start something have an address; Back closes them and stays on the page', async ({ page }) => {+ // By name: the inbox can show a card of its own (Add a passkey) that is a dialog too.+ const dialog = (name: string) => page.getByRole('dialog', { name })+ await openInbox(page)+ // New contact: the button adds a history entry, Back closes the form and stays on Contacts.+ await page+ .getByRole('navigation')+ .getByRole('link', { name: /^Contacts/ })+ .click()+ await page.getByRole('button', { name: /^New contact/ }).click()+ await expect(page).toHaveURL(/#contacts\/new$/)+ await expect(page.getByRole('button', { name: /^Add contact/ })).toBeVisible()+ await page.goBack()+ await expect(page).toHaveURL(/#contacts$/)+ await expect(page.getByRole('button', { name: /^Add contact/ })).toHaveCount(0)+ // Esc is the same step back: the next Back leaves Contacts, it does not open the form again.+ await page.getByRole('button', { name: /^New contact/ }).click()+ await page.keyboard.press('Escape')+ await expect(page).toHaveURL(/#contacts$/)+ await page.goBack()+ await expect(page).toHaveURL(/#calls$/)++ // A link opens the page with the dialog; closing it leaves the page's own address.+ await page.goto('/#contacts/import')+ await expect(dialog('Import contacts')).toBeVisible()+ await page.keyboard.press('Escape')+ await expect(dialog('Import contacts')).toHaveCount(0)+ await expect(page).toHaveURL(/#contacts$/)+ await page.goto('/#workspace/phone/add')+ await expect(dialog('Add a number')).toBeVisible()+ await page.reload()+ await expect(dialog('Add a number')).toBeVisible()+ await page.keyboard.press('Escape')+ await expect(page).toHaveURL(/#workspace\/phone$/)++ // The keyboard shortcuts: a flag on the page they open on; the page's own view stays in the address.+ await page.goto('/#calls/done')+ await expect(page.getByRole('navigation').getByRole('link', { name: /^Done/ })).toHaveAttribute(+ 'aria-current',+ 'page',+ )+ await page.keyboard.press('?')+ await expect(page).toHaveURL(/#calls\/done\?help$/)+ await expect(dialog('Keyboard shortcuts')).toBeVisible()+ await page.goBack()+ await expect(page).toHaveURL(/#calls\/done$/)+ await expect(dialog('Keyboard shortcuts')).toHaveCount(0)+ await page.goto('/#insights?period=7d&help')+ await expect(dialog('Keyboard shortcuts')).toBeVisible()+ await page.keyboard.press('Escape')+ await expect(page).toHaveURL(/#insights\?period=7d$/)+ await expect(page.getByRole('button', { name: /Last 7 days/ })).toBeVisible()+})++test('a saved dialog leaves the address of what it made; Back does not open the form again', async ({ page }) => {+ await page.goto('/#contacts/new')+ const phone = `503555${String(Date.now()).slice(-4)}`+ await page.getByRole('textbox', { name: 'Name' }).fill('Agent Test')+ await page.getByRole('textbox', { name: /^Phone/ }).fill(phone)+ await page.getByRole('button', { name: /^Add contact/ }).click()+ await expect(page).toHaveURL(/#contacts\/(?!new$)[\w-]+$/, { timeout: 15_000 })+ await expect(page.getByRole('button', { name: /^Add contact/ })).toHaveCount(0)+ // Put the list back as it was: delete the contact (its own key on the page).+ await page.keyboard.press('Escape')+ await page.locator('[data-contact-id]').filter({ hasText: 'Agent Test' }).first().hover()+ await page.keyboard.press('#')+ await expect(page.locator('[data-contact-id]').filter({ hasText: 'Agent Test' })).toHaveCount(0)+})+test('every page of the navigation is a link; a contact opens through its link', async ({ page }) => {await openInbox(page)const nav = page.getByRole('navigation')diff --git a/apps/web/src/Workspace.tsx b/apps/web/src/Workspace.tsxindex 630808a6..43c6c626 100644--- a/apps/web/src/Workspace.tsx+++ b/apps/web/src/Workspace.tsx@@ -1,7 +1,7 @@// The signed-in app: composes the inbox, the pages, the navigation, overlays and toasts.import { offersTour } from '@linedesk/actions'import type { Call } from '@linedesk/db/types'-import { useEffect, useMemo, useRef, useState } from 'react'+import { useCallback, useEffect, useMemo, useRef, useState } from 'react'import { useReviewCount } from './review/reviewData.ts'import { AdminMode } from './admin/AdminMode.tsx'import { PasskeyStepUpHost } from './admin/PasskeyStepUp.tsx'@@ -66,6 +66,7 @@ import { SyncBar } from './shell/SyncBar.tsx'import { pages, type Page, type PageRoute } from './shell/pages.tsx'import { ResultLog, Toast } from './shell/Toast.tsx'import { useKeyboard } from './shell/useKeyboard.ts'+import { HELP_FLAG, useDialogFlag } from './shell/dialogAddress.ts'import { callHash, useRoute } from './shell/useRoute.ts'import { useSignOut } from './shell/useSignOut.ts'import { useCallNotifications } from './shell/useCallNotifications.ts'@@ -184,7 +185,19 @@ export function Workspace({ me, onSignedOut, onSessionStale, notice = null, onReconst showGoLive = useShowGoLive(canEditSettings, me.workspace!.id)// The checklist's first step is connecting the number: while it is on screen, the banner saying so stays away.const goLiveVisible = useGoLiveVisible()- const [overlay, setOverlay] = useState<Overlay>(null)+ // The keyboard shortcuts have an address (`?help` on the page they open on, shell/dialogAddress.ts): a link opens+ // them, Back closes them. The other overlays (⌘K, the pickers) belong to a moment, not to an address.+ const [helpOpen, showHelp, hideHelp] = useDialogFlag(HELP_FLAG)+ const [otherOverlay, setOtherOverlay] = useState<Overlay>(null)+ const overlay: Overlay = helpOpen ? 'help' : otherOverlay+ const setOverlay = useCallback(+ (next: Overlay) => {+ if (next === 'help') return showHelp()+ hideHelp()+ setOtherOverlay(next)+ },+ [showHelp, hideHelp],+ )/** Delete… (owners and admins): the calls it deletes, while its dialog asks whether permanently now. */const [deleteFor, setDeleteFor] = useState<{ calls: Call[]; bulk: boolean } | null>(null)const [navOpen, setNavOpen] = useState(false)diff --git a/apps/web/src/contacts/Contacts.tsx b/apps/web/src/contacts/Contacts.tsxindex b8ac5682..e5d9ff77 100644--- a/apps/web/src/contacts/Contacts.tsx+++ b/apps/web/src/contacts/Contacts.tsx@@ -1,4 +1,5 @@// Contacts: everyone who has called, newest call first. Same list model as the inbox; the record opens beside it.+import { useDialogPlace } from '../shell/dialogAddress.ts'import type { Call } from '@linedesk/db/types'import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react'import type { Step } from '../inbox/changes.ts'@@ -108,7 +109,9 @@ export function Contacts({ menu, toast, openCall, runUndoable }: Props) {const withCompany = useMemo(() => page.all.some(r => r.contact.company?.trim()), [page.all])const { rows, cursor, opened, query } = pageconst empty = !waiting && rows.length === 0- const [importing, setImporting] = useState(false)+ // Import has its own address (`#contacts/import`): a link opens it, Back closes it.+ const [importing, showImporting, hideImporting] = useDialogPlace('contacts/import')+ const setImporting = (on: boolean) => (on ? showImporting() : hideImporting())const [merging, setMerging] = useState<{ first: ContactRow; second: ContactRow | null } | null>(null)const duplicates = useMemo(() => {const byId = new Map(page.all.map(r => [r.contact.id, r]))diff --git a/apps/web/src/contacts/useContactsPage.test.ts b/apps/web/src/contacts/useContactsPage.test.tsindex 080e753f..c7b887bd 100644--- a/apps/web/src/contacts/useContactsPage.test.ts+++ b/apps/web/src/contacts/useContactsPage.test.ts@@ -1,7 +1,7 @@import { describe, expect, it } from 'vitest'import { type Place, placeFromHash } from './useContactsPage.ts'-const left: Place = { query: 'mi', searching: true, cursorId: 'a', openId: null, creating: true }+const left: Place = { query: 'mi', searching: true, cursorId: 'a', openId: null }describe('a link to one contact (C9)', () => {it('opens that contact and puts the cursor on it', () => {@@ -9,11 +9,13 @@ describe('a link to one contact (C9)', () => {...left,cursorId: 'ct_9',openId: 'ct_9',- creating: false,})})it('keeps the place the page was left in for any other address', () => {expect(placeFromHash(left, '#contacts')).toBe(left)expect(placeFromHash(left, '#call/c1')).toBe(left)+ // The page's dialogs are not contacts (shell/dialogAddress.ts).+ expect(placeFromHash(left, '#contacts/new')).toBe(left)+ expect(placeFromHash(left, '#contacts/import')).toBe(left)})})diff --git a/apps/web/src/contacts/useContactsPage.ts b/apps/web/src/contacts/useContactsPage.tsindex 1be34c40..405b4a7c 100644--- a/apps/web/src/contacts/useContactsPage.ts+++ b/apps/web/src/contacts/useContactsPage.ts@@ -1,5 +1,6 @@// What the Contacts page shows and what is selected. It keeps its place while a call is open,// so Esc in that call comes back to the same contact, search and row.+import { dialogOf, useDialogPlace } from '../shell/dialogAddress.ts'import { useEffect, useMemo, useRef, useState } from 'react'import { flushSync } from 'react-dom'import { setPageKeys } from '../shell/keys.ts'@@ -10,14 +11,14 @@ import { contactRows, filterContactRows } from './model.ts'export const CONTACT_SEARCH_ID = 'contact-search'-/** `searching`: the search field is open in the header (like the inbox's). `creating`: the New contact form is open. */-export type Place = { query: string; searching: boolean; cursorId: string | null; openId: string | null; creating: boolean }-let remembered: Place = { query: '', searching: false, cursorId: null, openId: null, creating: false }+/** `searching`: the search field is open in the header (like the inbox's). */+export type Place = { query: string; searching: boolean; cursorId: string | null; openId: string | null }+let remembered: Place = { query: '', searching: false, cursorId: null, openId: null }/** The place a `#contacts/<id>` link asks for: that contact open and under the cursor; any other hash keeps `place`. */export function placeFromHash(place: Place, hash: string): Place {const id = contactIdOf(hash)- return id ? { ...place, cursorId: id, openId: id, creating: false } : place+ return id ? { ...place, cursorId: id, openId: id } : place}/** Focus the search field (rendered by then: openSearch flushes the render first). */@@ -33,19 +34,28 @@ export function useContactsPage({ remove }: { remove: (contactId: string) => voiconst calls = useRows('calls')// A link to one contact (`#contacts/<id>`) opens it; otherwise the page is where it was left.const [place, setPlace] = useState(() => placeFromHash(remembered, window.location.hash))+ // The New contact form has its own address (`#contacts/new`): a link opens it, Back closes it.+ const [creating, showCreate, hideCreate] = useDialogPlace('contacts/new')+ const [addressSeen, setAddressSeen] = useState(0)useEffect(() => {remembered = place}, [place])// The address names the open contact, so the panel can be shared and stays open on reload (replaced: Back leaves// the page, it does not step through contacts).+ // biome-ignore lint/correctness/useExhaustiveDependencies: addressSeen runs it again after the address changeduseEffect(() => {const now = window.location.hash.split('?')[0]!const want = place.openId ? contactHash(place.openId) : '#contacts'- if (now !== want && /^#contacts(\/|$)/.test(now)) window.history.replaceState(null, '', want)- }, [place.openId])+ // Not while a dialog of the page is in the address (New contact, Import): that address is theirs.+ if (now !== want && /^#contacts(\/|$)/.test(now) && !dialogOf(now)) window.history.replaceState(null, '', want)+ // Also after the address changed under an open contact (the New contact form closed after a save).+ }, [place.openId, addressSeen])// A contact link opened while the page is shown (pasted, or Back/Forward).useEffect(() => {- const onHash = () => setPlace(p => placeFromHash(p, window.location.hash))+ const onHash = () => {+ setPlace(p => placeFromHash(p, window.location.hash))+ setAddressSeen(n => n + 1)+ }window.addEventListener('hashchange', onHash)return () => window.removeEventListener('hashchange', onHash)}, [])@@ -65,20 +75,26 @@ export function useContactsPage({ remove }: { remove: (contactId: string) => voiconst added = awaiting && all.find(r => r.contact.phone === awaiting)if (!added) returnsetAwaiting(null)+ hideCreate()setPlace(p => ({...p,query: '',searching: false,cursorId: added.contact.id,openId: added.contact.id,- creating: false,}))- }, [awaiting, all])+ }, [awaiting, all, hideCreate])const update = (next: Partial<Place>) => setPlace(p => ({ ...p, ...next }))const select = (id: string) => update({ cursorId: id, openId: place.openId ? id : null }) // an open record follows the cursor- const open = (id: string) => update({ cursorId: id, openId: id, creating: false })- const startCreate = () => update({ creating: true, openId: null })+ const open = (id: string) => {+ hideCreate()+ update({ cursorId: id, openId: id })+ }+ const startCreate = () => {+ update({ openId: null })+ showCreate()+ }// The field renders and takes the focus in the same task, so a key typed right after the click goes into it,// not to the page's shortcuts (a frame later, "z" ran Undo).const openSearch = () => {@@ -105,7 +121,7 @@ export function useContactsPage({ remove }: { remove: (contactId: string) => voielse if (key === '/') openSearch()else if (key === 'n') startCreate()else if (key === '#' && cursor) remove(cursor.contact.id)- else if (key === 'Escape' && place.creating) update({ creating: false })+ else if (key === 'Escape' && creating) hideCreate()else if (key === 'Escape' && place.openId) update({ openId: null })else if (key === 'Escape' && place.searching) closeSearch()else return false@@ -126,9 +142,9 @@ export function useContactsPage({ remove }: { remove: (contactId: string) => voiopenSearch,closeSearch,clearQuery,- creating: place.creating,+ creating,startCreate,- stopCreate: () => update({ creating: false }),+ stopCreate: hideCreate,added: (phone: string) => setAwaiting(phone),setQuery: (query: string) => update({ query, cursorId: null }),hover: (id: string) => update({ cursorId: id }),diff --git a/apps/web/src/insights/Insights.tsx b/apps/web/src/insights/Insights.tsxindex e000c5c0..7aa3ea82 100644--- a/apps/web/src/insights/Insights.tsx+++ b/apps/web/src/insights/Insights.tsx@@ -1,6 +1,7 @@// Insights: how the assistant did over a period (insights.get, counted on the server). One sentence,// four numbers that switch the chart below them, how calls ended, when people call, and an export of// the period (every call through call.export for owners and admins, totals per day for everyone).+import { HELP_FLAG, hasFlag, withFlag } from '../shell/dialogAddress.ts'import type { CallExportData, InsightPeriod, InsightsData, JobValueCurrency } from '@linedesk/actions'import { insightPeriods } from '@linedesk/actions'import { useEffect, useRef, useState } from 'react'@@ -71,9 +72,15 @@ export function Insights({ canEdit, toast }: Props) {const setRange = (range: Range | null) => setPlace(p => ({ ...p, range }))const setMetric = (metric: ChartMetric) => setPlace(p => ({ ...p, metric }))useEffect(() => {+ // The keyboard shortcuts' flag (`?help`, shell/dialogAddress.ts) is not this page's: it stays as it is.+ const now = window.location.hashconst hash = hashForPlace(place)- if (window.location.hash.startsWith('#insights') && window.location.hash !== hash)- window.history.replaceState(null, '', hash)+ if (now.startsWith('#insights') && withFlag(now, HELP_FLAG, false) !== hash)+ window.history.replaceState(+ null,+ '',+ hasFlag(now, HELP_FLAG) ? `${hash}${hash.includes('?') ? '&' : '?'}${HELP_FLAG}` : hash,+ )}, [place])// An address typed or opened while the page is on screen (another period's link) shows that view.useEffect(() => {diff --git a/apps/web/src/outbound/Outbound.tsx b/apps/web/src/outbound/Outbound.tsxindex 4332d7ec..93ed5c10 100644--- a/apps/web/src/outbound/Outbound.tsx+++ b/apps/web/src/outbound/Outbound.tsx@@ -2,6 +2,7 @@// list (on a phone: the list, then the call full screen with Back). A running call shows its transcript as it grows// (calls and transcript_segments are live tables) and takes instructions (call.guide); an ended call shows its// summary. New call (N) dials (call.dial). Owners and admins only, once a server admin turned outbound calls on.+import { useDialogPlace } from '../shell/dialogAddress.ts'import type { Call } from '@linedesk/db/types'import { useT } from '@linedesk/i18n/react'import { type ReactNode, useEffect, useMemo, useRef, useState } from 'react'@@ -70,7 +71,9 @@ export function Outbound({ menu, toast, workspaceName }: Props) {const segments = useSegmentsByCall()const openId = useOpenCallId()const opened = openId ? calls.find(c => c.id === openId) : undefined- const [dialing, setDialing] = useState(false)+ // New call has its own address (`#outbound/new`): a link opens it, Back closes it.+ const [dialing, showDialing, hideDialing] = useDialogPlace('outbound/new')+ const setDialing = (on: boolean) => (on ? showDialing() : hideDialing())const answered = (call: Call) => (segments.get(call.id) ?? []).some(s => s.speaker === 'caller')// A call just dialled shows up once the agent registers it (a second or two): it opens then.diff --git a/apps/web/src/outbound/model.ts b/apps/web/src/outbound/model.tsindex 10db1033..6e42c681 100644--- a/apps/web/src/outbound/model.ts+++ b/apps/web/src/outbound/model.ts@@ -1,6 +1,7 @@// Outbound calls (LIN-873): the assistant phones someone towards a goal (call.dial) and takes instructions while the// call runs (call.guide). Who sees the page, the list of outbound calls, the New call form's input and the log of// the instructions sent to a call.+import { dialogOf } from '../shell/dialogAddress.ts'import {DIAL_FIRST_SENTENCE_MAX,DIAL_GOAL_MAX,@@ -18,7 +19,8 @@ export const outboundHash = (callId?: string | null) => (callId ? `#outbound/${cexport function outboundCallIdOf(hash: string): string | null {const [path = ''] = hash.replace(/^#/, '').split('?')const [page, id, ...rest] = path.split('/')- return page === OUTBOUND_ROUTE && id && rest.length === 0 ? id : null+ // `#outbound/new` is the New call dialog (shell/dialogAddress.ts), not a call.+ return page === OUTBOUND_ROUTE && id && rest.length === 0 && !dialogOf(hash) ? id : null}/**diff --git a/apps/web/src/settings/PhoneNumbers.tsx b/apps/web/src/settings/PhoneNumbers.tsxindex 67d707ac..f30dc01f 100644--- a/apps/web/src/settings/PhoneNumbers.tsx+++ b/apps/web/src/settings/PhoneNumbers.tsx@@ -3,6 +3,7 @@// monthly price; a number already in the carrier account behind a quiet link), then whether the current number forwards// to it. Connecting runs phoneNumber.setup through the outbox; the new row arrives by sync. Where a number can be bought// comes from the install's buy offers (the phone setup status), the same list as onboarding's.+import { useDialogPlace } from '../shell/dialogAddress.ts'import type { Assistant, PhoneNumber } from '@linedesk/db/types'import { useT } from '@linedesk/i18n/react'import { type ReactNode, useEffect, useState } from 'react'@@ -119,8 +120,11 @@ export function PhoneNumbers({ canEdit, status: serverStatus, isInstanceAdmin, econst assistants = useAssistants()const presence = usePresence()const answering = presence.kind === 'answering'- const [adding, setAdding] = useState(false)const canAdd = canEdit && !!status?.available+ // Add a number has its own address (`#workspace/phone/add`): a link opens it, Back closes it. While the server's+ // status loads the address waits; without the right (or a server that can't add numbers) the page shows without it.+ const [adding, showAdding, hideAdding] = useDialogPlace('workspace/phone/add', canAdd || (canEdit && !status))+ const setAdding = (on: boolean) => (on ? showAdding() : hideAdding())return (<>{/* Why calls are not answered: above the cards, not a box inside one (settings audit, 2026-11-26). */}@@ -154,7 +158,7 @@ export function PhoneNumbers({ canEdit, status: serverStatus, isInstanceAdmin, e</Card>}/>- {adding && (+ {adding && canAdd && (<AddNumberDialog status={status} extraNumberCents={extraNumberCents} onClose={() => setAdding(false)} />)}{/* Where numbers come from: the carrier and the own phone system, as setting rows in their own quiet card. */}diff --git a/apps/web/src/shell/dialogAddress.test.ts b/apps/web/src/shell/dialogAddress.test.tsnew file mode 100644index 00000000..ed920248--- /dev/null+++ b/apps/web/src/shell/dialogAddress.test.ts@@ -0,0 +1,36 @@+import { describe, expect, it } from 'vitest'+import { outboundCallIdOf } from '../outbound/model.ts'+import { DIALOG_PLACES, dialogOf, hasFlag, withFlag } from './dialogAddress.ts'+import { contactIdOf, parseHash } from './useRoute.ts'++describe('dialogs with an address', () => {+ it('each lies on a page the router knows, and is not a record of that page', () => {+ for (const [place, page] of Object.entries(DIALOG_PLACES)) {+ expect(dialogOf(`#${place}`), place).toBe(place)+ expect(dialogOf(`#${place}?help`), place).toBe(place)+ const at = parseHash(`#${place}`)+ expect(at.known, place).toBe(true)+ expect(at.route, place).toBe(page.split('/')[0])+ expect(place.startsWith(`${page}/`), place).toBe(true)+ expect(contactIdOf(`#${place}`), place).toBeNull()+ expect(outboundCallIdOf(`#${place}`), place).toBeNull()+ }+ expect(dialogOf('#contacts/ct_1')).toBeNull()+ expect(dialogOf('#contacts')).toBeNull()+ expect(contactIdOf('#contacts/ct_1')).toBe('ct_1')+ })++ it('the shortcuts flag goes on and off any address and keeps the rest', () => {+ expect(withFlag('#calls', 'help', true)).toBe('#calls?help')+ expect(withFlag('#calls?q=leak', 'help', true)).toBe('#calls?q=leak&help')+ expect(withFlag('#calls?q=leak&help', 'help', true)).toBe('#calls?q=leak&help')+ expect(withFlag('#calls?q=leak&help', 'help', false)).toBe('#calls?q=leak')+ expect(withFlag('#insights?help&period=7d', 'help', false)).toBe('#insights?period=7d')+ expect(withFlag('#contacts/ct_1?help', 'help', false)).toBe('#contacts/ct_1')+ expect(hasFlag('#calls?q=help', 'help')).toBe(false)+ expect(hasFlag('#calls?q=x&help', 'help')).toBe(true)+ // The page under the flag is still the page.+ expect(parseHash('#calls/done?help')).toMatchObject({ route: 'calls', tab: 'done', known: true })+ expect(parseHash('#calls?q=leak&help')).toMatchObject({ search: 'leak', known: true })+ })+})diff --git a/apps/web/src/shell/dialogAddress.ts b/apps/web/src/shell/dialogAddress.tsnew file mode 100644index 00000000..0abc8128--- /dev/null+++ b/apps/web/src/shell/dialogAddress.ts@@ -0,0 +1,95 @@+// Dialogs that start something have an address (design principles, rule 20): `#contacts/new`, `#contacts/import`,+// `#outbound/new`, `#workspace/phone/add`, and the keyboard shortcuts as `?help` on the page they were opened on.+// A link or a reload opens the page with the dialog; nothing is sent before the person acts in it. Opening adds a+// history entry, so Back closes the dialog and stays on the page; Esc, Close, Cancel and Save do the same. Dialogs+// that confirm something (delete, leave, block) never get an address: a link must not open "Delete?".+import { useCallback, useEffect, useRef, useState } from 'react'++/** The dialogs with an address of their own, and the page each lies on (its address when the dialog is closed). */+export const DIALOG_PLACES = {+ 'contacts/new': 'contacts',+ 'contacts/import': 'contacts',+ 'outbound/new': 'outbound',+ 'workspace/phone/add': 'workspace/phone',+} as const+export type DialogPlace = keyof typeof DIALOG_PLACES++const pathOf = (hash: string) => hash.replace(/^#/, '').split('?')[0]!+/** The dialog a hash names, or null. */+export const dialogOf = (hash: string): DialogPlace | null =>+ Object.hasOwn(DIALOG_PLACES, pathOf(hash)) ? (pathOf(hash) as DialogPlace) : null++/** The flag in a hash's query that says the keyboard shortcuts are open: `#calls?help`, `#calls?q=leak&help`. */+export const HELP_FLAG = 'help'+const flagsOf = (hash: string) => hash.split('?')[1]?.split('&').filter(Boolean) ?? []+export const hasFlag = (hash: string, flag: string) => flagsOf(hash).includes(flag)+export function withFlag(hash: string, flag: string, on: boolean): string {+ const flags = flagsOf(hash).filter(f => f !== flag)+ if (on) flags.push(flag)+ return `#${pathOf(hash)}${flags.length ? `?${flags.join('&')}` : ''}`+}++/**+ * The shared mechanics: `isOpen(hash)` says whether the address names the dialog; `opened(hash)` and `closed(hash)`+ * give the address with and without it. `pushed`: this tab added the dialog's history entry, so closing is a step+ * back; a dialog opened by a link or a reload has no entry of the page under it, and closing rewrites the address.+ */+function useAddress(+ isOpen: (hash: string) => boolean,+ opened: (hash: string) => string,+ closed: (hash: string) => string,+ allowed: boolean,+): [open: boolean, show: () => void, hide: () => void] {+ const [open, setOpen] = useState(() => isOpen(window.location.hash))+ const pushed = useRef(false)+ const fns = useRef({ isOpen, opened, closed })+ fns.current = { isOpen, opened, closed }+ useEffect(() => {+ const onHash = () => {+ const now = fns.current.isOpen(window.location.hash)+ if (!now) pushed.current = false+ setOpen(now)+ }+ window.addEventListener('hashchange', onHash)+ return () => window.removeEventListener('hashchange', onHash)+ }, [])+ const show = useCallback(() => {+ if (fns.current.isOpen(window.location.hash)) return+ pushed.current = true+ setOpen(true)+ window.location.hash = fns.current.opened(window.location.hash)+ }, [])+ const hide = useCallback(() => {+ setOpen(false)+ if (!fns.current.isOpen(window.location.hash)) return+ if (pushed.current) {+ pushed.current = false+ window.history.back()+ } else window.history.replaceState(null, '', fns.current.closed(window.location.hash))+ }, [])+ // No right for the dialog: the page, without it, and the address says so.+ useEffect(() => {+ if (!allowed && open) hide()+ }, [allowed, open, hide])+ return [open && allowed, show, hide]+}++/** A dialog with its own address. `allowed` false: it never opens, and a link to it shows the page. */+export function useDialogPlace(place: DialogPlace, allowed = true) {+ return useAddress(+ hash => pathOf(hash) === place,+ () => `#${place}`,+ () => `#${DIALOG_PLACES[place]}`,+ allowed,+ )+}++/** A dialog that opens over any page: a flag in the address's query (`?help`). */+export function useDialogFlag(flag: string) {+ return useAddress(+ hash => hasFlag(hash, flag),+ hash => withFlag(hash || '#calls', flag, true),+ hash => withFlag(hash, flag, false),+ true,+ )+}diff --git a/apps/web/src/shell/useRoute.ts b/apps/web/src/shell/useRoute.tsindex 6546f44c..18670e38 100644--- a/apps/web/src/shell/useRoute.ts+++ b/apps/web/src/shell/useRoute.ts@@ -5,7 +5,8 @@// (`#call/<id>?ws=<workspace id>`); the app switches to it before the page opens (linkWorkspaceTarget).import { useCallback, useEffect, useRef, useState } from 'react'import type { InboxTab } from '../inbox-model.ts'-import { hasSections, isPageRoute, type Route } from './pages.tsx'+import { DIALOG_PLACES, dialogOf } from './dialogAddress.ts'+import { hasSections, isPageRoute, type PageRoute, type Route } from './pages.tsx'import { i18n } from '../i18n/index.tsx'/** `member`: whose calls the `member` view lists (null in every other view). */@@ -26,7 +27,8 @@ export const contactHash = (id: string) => `#contacts/${encodeURIComponent(id)}`export function contactIdOf(hash: string): string | null {const [path = ''] = hash.replace(/^#/, '').split('?')const [page, id, ...rest] = path.split('/')- return page === 'contacts' && id && rest.length === 0 ? decode(id) : null+ // `#contacts/new` and `#contacts/import` are dialogs of the page (dialogAddress.ts), not contacts.+ return page === 'contacts' && id && rest.length === 0 && !dialogOf(hash) ? decode(id) : null}export function listHash({ tab, search, member }: InboxPlace): string {const view =@@ -65,6 +67,9 @@ export function parseHash(hash: string, last: InboxPlace = HOME): Location {)return { ...last, route: page, callId: null, known: true }if (contactIdOf(path)) return { ...last, route: 'contacts', callId: null, known: true }+ // A dialog with its own address lies on its page (dialogAddress.ts).+ const dialog = dialogOf(path)+ if (dialog) return { ...last, route: DIALOG_PLACES[dialog].split('/')[0] as PageRoute, callId: null, known: true }// Admin mode has sections of its own (`#admin/users/<id>`); admin/route.ts reads them.if (path.startsWith('admin/')) return { ...last, route: 'admin', callId: null, known: true }const params = query?.split('&') ?? []diff --git a/docs/api.md b/docs/api.mdindex 28d141c9..694d9e65 100644--- a/docs/api.md+++ b/docs/api.md@@ -98,7 +98,7 @@ The coverage test `apps/api/test/ui-parity.test.ts` fails when an action has noA browser with a built-in agent that supports WebMCP (`document.modelContext`, a W3C draft; other browsers get nothing and nothing changes) finds the app's tools on the page while a person is signed in (`apps/web/src/agentTools.ts`):- one tool per public action the person may run, with the MCP server's names (`call_markDone`), descriptions and schemas. A member gets no destructive tool (delete, block, spam, cancel, an outbound call); owners and admins get them marked `consequentialHint`, so the browser can ask first, as are `call.dial`, `call.guide` and `call.export`. `feedback.send` and `integration.*` are not offered.-- `app_view`: the place (the address after `#`), the calls of the list on screen with their ids, and what the last actions answered; `app_open`: opens a call, a contact or a page of the navigation (with its view: `calls?q=…`, `insights?period=7d&metric=missed`), no other address.+- `app_view`: the place (the address after `#`), the calls of the list on screen with their ids, and what the last actions answered; `app_open`: opens a call, a contact or a page of the navigation (with its view: `calls?q=…`, `insights?period=7d&metric=missed`; `contacts/new` and `contacts/import` open the page with that dialog, nothing is sent), no other address.A tool runs as the signed-in person through `POST /v1/actions/<name>`, like a click: the server checks the session and the role again. Every result comes inside `untrusted_caller_content` with the MCP server's notice, and every tool carries `untrustedContentHint`: names, summaries and notes come from callers and are data, never instructions. Not during support access. An agent that works without a person at the page uses the MCP server with a key instead.diff --git a/docs/design-principles.md b/docs/design-principles.mdindex fd2c6f99..1983a8ab 100644--- a/docs/design-principles.md+++ b/docs/design-principles.md@@ -48,6 +48,7 @@ Linedesk should feel like a calm, native tool, not a dashboard. These rules come- **A place is a link.** A row that opens a call or a contact carries an `<a href>` with its address (`r-link` around its name; the row's click still opens it in place); navigation items are links. Every view has its own address, with what it shows (the inbox's view and search, the Insights period and chart: `#insights?period=7d&metric=missed`).- **A control is in the page before the pointer is on it.** Actions that show on hover are hidden with `opacity`, not `display: none`, where the only pointer is a mouse (`.r-acts`; never on a device with a touch screen, where a tap would hit a button nobody sees), and keep their `aria-label`. Tab skips the ones not on screen.- **Names don't change.** A control's name is its `aria-label` or its text; `title` adds the keys. The tooltip script gives a `title` back when the pointer leaves.+ - **A dialog that starts something has an address; one that confirms never has.** New contact (`#contacts/new`), Import (`#contacts/import`), New call (`#outbound/new`), Add a number (`#workspace/phone/add`) and the keyboard shortcuts (`?help` on the page they open on) open by link and survive a reload (`shell/dialogAddress.ts`: `useDialogPlace`, `useDialogFlag`). Opening adds a history entry: Back, Esc, Close and Cancel all close the dialog and stay on the page; after a save the address is the page or the new record. Nothing is sent before the person acts, and without the right the page opens without the dialog. "Delete?", "Leave?" and every other confirmation stay out of the address: a link must never open them.- **A short list is whole in the page.** Up to 150 calls the inbox renders every row, not only those near the window (`WHOLE_LIST_MAX`); a longer list says its length (`aria-setsize`).- **One control per place.** Where one control lies over another (the select box over the read dot), only the one that takes the click is a control; the other action gets a place of its own (Mark read is a row action).- **State is readable.** A list row says which record it is and its state (`data-call-id`, `data-state`, `data-unread`), besides its `aria-label`.