Give agents your app's own diagnostics and actions
Expose focused Cordova/Capacitor app data and operations so agents can answer questions the built-in tools cannot.
Custom tools let an agent ask your JavaScript app code for a precise answer, such as the current user or an app-specific state snapshot. Expose small, structured results and only the development actions your workflow needs.
const registration = Ansight.registerTool(
{
id: "app.get_state",
name: "Get app state",
category: "app",
policy: "read",
},
async () => ({
success: true,
result: { ready: true },
}),
);
await registration.ready;
await registration.unregister();
Use stable ids, structured inputs and results, an explicit read, write, or
critical policy, and the least-permissive tool guard. Prefer a small
app-specific tool over broad DOM actions or native reflection when the app can
provide a precise answer.
Native tool entries report dynamic runtime availability and remediation through the shared catalog. JavaScript-backed custom tools are advertised as available while registered; when one becomes unusable, unregister it or return a stable failure errorCode from the handler. The Capacitor registration API does not currently expose a pre-invocation availability callback.
Authoring and Execution Context
registerTool(definition, handler) already supplies the concise form for Capacitor. Define argumentsSchema and resultSchema and choose an explicit policy. The bridge currently supplies flattened string arguments, so validate and parse booleans, numbers, and JSON fields explicitly.
Handlers execute in the WebView JavaScript runtime. Await state changes before returning and keep heavy work off the UI event loop. Native plugins must dispatch UI and engine access to their owning queues. A bridge timeout does not guarantee cancellation. JavaScript tools have no pre-invocation availability callback: unregister unavailable tools or return a stable scene_not_ready failure.
Expose a Domain Model
Start with scene.snapshot (read) returning a bounded JSON projection of scene id, selected entity, and transforms. Add scene.set_visible (write) taking one entity id and a boolean. Reject unknown ids and a loading scene with stable error codes, dispatch the change to the scene owner, and return the updated visibility. Read current state at invocation time rather than capturing a stale snapshot at registration.
Keep schemas, policy, and dispatch explicit even when using registerTool. Verify a successful read, a successful mutation, invalid arguments, an unavailable scene, and a denied write under a read-only guard. For a large model or a durable snapshot, use artifact publication from the app instead of embedding it in a tool result.