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
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { isStartPage, waitForSignIn } from './signIn.ts'
const server = 'https://app.linedesk.ai'
const challenge = 'a'.repeat(43)
const start = `${server}/app-sign-in?provider=google&challenge=${challenge}`
test('only the server’s own start page opens in the browser', () => {
assert.equal(isStartPage(start, server), true)
assert.equal(isStartPage(`https://evil.example/app-sign-in?provider=google&challenge=${challenge}`, server), false)
assert.equal(isStartPage(`${server}/elsewhere?provider=google&challenge=${challenge}`, server), false)
assert.equal(isStartPage(`${server}/app-sign-in?provider=google&challenge=short`, server), false)
assert.equal(isStartPage(`${start}&port=1234`, server), false)
assert.equal(isStartPage('file:///x', server), false)
})
test('the browser hands the code back on the loopback port, then sees the server’s note', async () => {
const waiting = await waitForSignIn(start, server)
const port = new URL(waiting.url).searchParams.get('port')
assert.match(port ?? '', /^\d+$/)
const other = await fetch(`http://127.0.0.1:${port}/favicon.ico`)
assert.equal(other.status, 404)
// A malformed code and another host name are ignored; the wait goes on.
assert.equal((await fetch(`http://127.0.0.1:${port}/app-sign-in/back?code=short`)).status, 404)
const rebound = await fetch(`http://localhost:${port}/app-sign-in/back?code=${'c'.repeat(43)}`).catch(() => null)
assert.notEqual(rebound?.status, 302)
const res = await fetch(`http://127.0.0.1:${port}/app-sign-in/back?code=${'c'.repeat(43)}`, { redirect: 'manual' })
assert.equal(res.status, 302)
assert.equal(res.headers.get('location'), `${server}/app-sign-in/back?desktop=1`)
const back = new URL(await waiting.done)
assert.equal(back.searchParams.get('code'), 'c'.repeat(43))
// One use: the port is closed now.
await assert.rejects(fetch(`http://127.0.0.1:${port}/app-sign-in/back?code=x`))
})
test('an error comes back as an error; cancel rejects', async () => {
const waiting = await waitForSignIn(start, server)
const port = new URL(waiting.url).searchParams.get('port')
await fetch(`http://127.0.0.1:${port}/app-sign-in/back?error=access_denied`, { redirect: 'manual' })
assert.equal(new URL(await waiting.done).searchParams.get('error'), 'access_denied')
const other = await waitForSignIn(start, server)
other.cancel()
await assert.rejects(other.done, /cancelled/)
})