Voice assistant can set/check/cancel timers without the timer app being already open

This commit is contained in:
James Babcock committed 2026-08-09 20:10:33 -07:00
1 parent 2562761038
commit b4728f4f15
5 files changed
+124 -49

No files matched your search

+3 -21
View File
@@ -6,10 +6,7 @@
*/
import { roamApiTokenSetting, roamGraphNameSetting } from "../ui/dashboard-settings";
import { toolRegistry, type ToolRegistry, type ToolResult } from "./tool-registry";
const APP_TOOL_PREFIX = "app.roam.";
const TOOL_APPEAR_TIMEOUT_MS = 5_000;
const TOOL_APPEAR_POLL_MS = 150;
import { callAppToolWithLaunch } from "./launch-on-call";
let registered = false;
@@ -52,7 +49,7 @@ export function registerRoamTools(
);
}
/** Launch the Roam app if needed, wait for its tool, and forward the call. */
/** Check Roam configuration, then launch-on-call forward to the Roam app. */
async function callAppTool(
launchApp: (appId: string) => Promise<void>,
registry: ToolRegistry,
@@ -62,22 +59,7 @@ async function callAppTool(
if (roamGraphNameSetting.get().length === 0 || roamApiTokenSetting.get().length === 0) {
return err("Roam is not configured; the user must set the graph name and API token in Settings > Roam.");
}
const fullName = `${APP_TOOL_PREFIX}${unprefixedName}`;
if (!registry.listTools().some((tool) => tool.name === fullName)) {
await launchApp("roam");
const deadline = Date.now() + TOOL_APPEAR_TIMEOUT_MS;
while (!registry.listTools().some((tool) => tool.name === fullName)) {
if (Date.now() > deadline) {
return err("The Roam app did not start in time.");
}
await sleep(TOOL_APPEAR_POLL_MS);
}
}
return registry.callTool(fullName, args);
}
function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
return callAppToolWithLaunch(registry, launchApp, "roam", unprefixedName, args);
}
function err(error: string): ToolResult {