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.
This commit is contained in:
Sameh Khamis committed 2026-10-02 15:21:36 -07:00
1 parent 7ddee426e7
commit 963c791a5c
9 files changed
+219 -65

No files matched your search

+53 -1
View File
@@ -1,6 +1,12 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { composeCatalog, coreTools, ToolError } from '../index.js';
import {
catalogForSurface,
composeCatalog,
coreTools,
defineTool,
ToolError,
} from '../index.js';
const conditions = {
observedAt: '2026-10-01T19:15:00.000Z',
@@ -536,6 +542,19 @@ test('military awareness gathers contacts around a point and marks failures', as
reason: 'unavailable right now',
});
assert.equal(result.data.radius_km, 100);
const voice = catalogForSurface(catalog, 'voice');
assert.equal(voice.get('aircraft_in_area'), undefined);
assert.deepEqual(
Object.keys(
(
await voice.call('military_awareness', {
location: { lat: 32.7, lon: -117.2 },
radius_km: 100,
})
).data.sections,
),
['military_aircraft', 'aircraft', 'installations'],
);
assert.equal(
(await catalog.call('military_awareness', { location: { lat: 0, lon: 0 } }))
.data.radius_km,
@@ -549,3 +568,36 @@ test('military awareness gathers contacts around a point and marks failures', as
/radius_km/,
);
});
test('composites reach their sections through the catalog', async () => {
const replacement = defineTool({
name: 'get_weather',
title: 'Weather',
description: 'Replaced weather.',
inputSchema: {
type: 'object',
properties: { location: { type: 'object' } },
},
run: async () => ({ summary: 'Replaced weather.', data: {} }),
});
const seen = [];
const catalog = composeCatalog({
tools: [...coreTools, replacement],
replace: ['get_weather'],
services: { weather, places },
interceptors: [
(call, next) => {
seen.push([call.tool.name, call.parent ?? null]);
return next(call);
},
],
});
const result = await catalog.call('situation_brief', {
area: { place: 'Austin' },
});
assert.equal(result.data.sections.weather.summary, 'Replaced weather.');
assert.deepEqual(seen, [
['situation_brief', null],
['get_weather', 'situation_brief'],
]);
});