Files
gods-eye-view/src/tools/surfaces.js
T
Sameh Khamis 963c791a5c fix: run composite tool sections through the catalog
situation_brief, military_awareness and the HUD caption called other tools
directly, so replaced tools and interceptors did not apply to their sections.
Tools now reach each other through the catalog, and interceptors see these
calls with the calling tool as parent. Surfaces become a view over the
composed catalog, so a composite offered on voice keeps sections that voice
does not list.
2026-10-02 15:21:36 -07:00

83 lines
2.9 KiB
JavaScript

/**
* Which surfaces offer each tool. A tool is on every surface unless this
* table turns it off; edit an entry to turn a tool on or off for MCP, voice,
* or both. Applications can pass overrides when they compose a surface.
*/
import { ToolError } from './catalog.js';
export const SURFACES = Object.freeze(['mcp', 'voice']);
const voiceOff = Object.freeze({ voice: false });
export const TOOL_SURFACES = Object.freeze({
// Voice runs inside the app, so a link to it adds nothing.
open_in_gods_eye_view: voiceOff,
// Voice has an app action of the same name.
next_satellite_pass: voiceOff,
// Voice receives text only, so tools that answer with an image are off.
get_weather_map: voiceOff,
get_recent_imagery: voiceOff,
get_cctv_snapshot: voiceOff,
// Voice shows the HUD caption in the app itself.
get_hud_caption: voiceOff,
// Voice answers these from the loaded layers with analyst_query.
aircraft_in_area: voiceOff,
vessels_in_area: voiceOff,
find_aircraft: voiceOff,
find_vessel: voiceOff,
get_earthquakes: voiceOff,
get_active_fires: voiceOff,
find_infrastructure: voiceOff,
satellites_overhead: voiceOff,
});
/**
* The tools a surface offers, in their original order. `overrides` uses the
* table's shape and wins over it, such as `{ get_weather_map: { voice: true } }`.
* An override naming an unknown tool or surface throws, so a typo cannot
* silently do nothing.
*/
export function toolsForSurface(tools, surface, overrides = {}) {
if (!SURFACES.includes(surface))
throw new TypeError(`Unknown tool surface: ${surface}`);
const names = new Set(tools.map((tool) => tool.name));
for (const [name, entry] of Object.entries(overrides)) {
if (!names.has(name)) throw new TypeError(`Unknown tool: ${name}`);
for (const key of Object.keys(entry)) {
if (!SURFACES.includes(key))
throw new TypeError(`Unknown tool surface for ${name}: ${key}`);
}
}
return tools.filter(
(tool) =>
(overrides[tool.name]?.[surface] ??
TOOL_SURFACES[tool.name]?.[surface]) !== false,
);
}
/**
* A view of a composed catalog that lists and calls only the tools a surface
* offers. Tools that combine others still reach the whole catalog, so a
* composite such as military_awareness keeps its sections on every surface.
*/
export function catalogForSurface(catalog, surface, overrides = {}) {
const offered = new Set(
toolsForSurface(catalog.list(), surface, overrides).map(
(tool) => tool.name,
),
);
return Object.freeze({
list: () => catalog.list().filter((tool) => offered.has(tool.name)),
get: (name) => (offered.has(name) ? catalog.get(name) : undefined),
async call(name, args, options) {
if (!offered.has(name))
throw new ToolError(
'unsupported',
`No tool named ${name} is available`,
);
return catalog.call(name, args, options);
},
});
}