The chat.mjs header comment now says the seam takes the bus transport it is given: the human one from the signed-in listener, the tester one from the row 176 listener (row 177). The TypeError for a missing or non-function call says 'chat needs a bus transport function' and no longer says human. No behavior changes. The webui README doesn't repeat either phrase and is unchanged. A new chat.test.mjs test passes undefined, null, a string, a number, an object, an array and no call, and reads the new TypeError text. Putting the old text back fails it. Dewey approved round 1 in #1681 comment 29376. Their notes (the tester line names no file, and the test title says both transports pass when only a stand-in function does) need no change.
29 lines
1.6 KiB
JavaScript
29 lines
1.6 KiB
JavaScript
// 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 }),
|
|
});
|
|
}
|