feat: share the tool catalog with voice

This commit is contained in:
Sameh Khamis committed 2026-10-01 13:52:36 -07:00
1 parent 0953ebb026
commit 1a03e7483d
19 files changed
+288 -15

No files matched your search

+25 -1
View File
@@ -1,11 +1,35 @@
import { toFunctionOutput } from '../tools/functions.js';
import { GEV_ACTION_SCHEMAS } from './actionSchemas.js';
import { createGevActionRunner } from './gevActions.js';
import { createVoiceCommands } from './commands.js';
export * from './realtimeController.js';
const ACTION_NAMES = new Set(GEV_ACTION_SCHEMAS.map((schema) => schema.name));
/**
* Run app actions through `runner` and every other tool the catalog has
* through the catalog. `loadCatalog` resolves the catalog when first needed.
*/
export function withToolCatalog(runner, loadCatalog) {
if (typeof loadCatalog !== 'function') return runner;
return async function runGevTool(name, args, options = {}) {
if (ACTION_NAMES.has(name)) return runner(name, args, options);
const catalog = await loadCatalog();
if (!catalog?.get(name)) return runner(name, args, options);
const result = await catalog.call(name, args ?? {}, {
signal: options.signal,
});
return toFunctionOutput(name, result);
};
}
/** Compose the standalone action runner with the voice controls. */
export function initGevVoiceCommands(options) {
return createVoiceCommands({
...options,
runner: createGevActionRunner(options),
runner: withToolCatalog(
createGevActionRunner(options),
options.toolCatalog,
),
});
}