mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 19:04:02 +00:00
feat: share the tool catalog with voice
This commit is contained in:
1 parent
0953ebb026
commit
1a03e7483d
19 files changed
+288
-15
No files matched your search
@@ -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,
|
||||
),
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user