// Row 129: the single seam between Console chat operations and the bus transport it is given. // The signed-in listener passes the human transport (cli.mjs, `chat = createChat({ call })`); the row 176 // tester listener passes the tester transport (row 177, `createChat({ call })` over TESTER_CLI). // No browser-selected bus verb, tenant, owner, capability or message class crosses this seam. import { createChannelCaller } from '../../plugins/src/channel.mjs'; import { PluginError } from '../../plugins/src/kinds.mjs'; import { BusReadError } from './bus.mjs'; export function createChat({ call }) { if (typeof call !== 'function') throw new TypeError('chat needs a bus transport function'); const dispatch = createChannelCaller({ name: 'webui', call }); const channel = async (verb, args) => { try { return await dispatch(verb, args); } catch (err) { if (err instanceof PluginError) throw new BusReadError(err.code, err.message); throw err; } }; return Object.freeze({ projects: () => channel('project.list', {}), createProject: ({ name, repo }) => channel('project.create', { name, ...(repo === undefined ? {} : { repo }) }), threads: ({ project } = {}) => channel('thread.list', project === undefined ? {} : { project }), createThread: ({ project, name }) => channel('thread.create', { project, name }), messages: ({ thread, after, limit }) => channel('thread.messages', { thread, ...(after ? { after } : {}), limit }), send: ({ thread, body }) => channel('thread.send', { thread, body, class: 'REQUEST' }), open: ({ thread }) => channel('thread.open', { thread }), }); }