/** * See what the user is currently looking at on screen. * * Reads and returns the current navigation state from application state. * * Usage: * pnpm action view-screen */ import { defineAction } from "@agent-native/core/action"; import { readAppState } from "@agent-native/core/application-state"; import { eq } from "@agent-native/core/db/schema"; import { z } from "zod"; import { getDb } from "../server/db/index.js"; import { stocks } from "../server/db/schema.js"; export default defineAction({ description: "See what the user is currently looking at on screen. Returns the current navigation state for the chat-first app. Always call this first before taking any action.", schema: z.object({}), http: false, readOnly: true, run: async (_args, ctx) => { const navigation = await readAppState("navigation"); const screen: Record = {}; if (navigation) screen.navigation = navigation; const view = (navigation as { view?: string } | null)?.view; if (view === "stocks" && ctx?.userEmail) { const db = getDb(); const rows = await db .select() .from(stocks) .where(eq(stocks.ownerEmail, ctx.userEmail)); screen.stocks = { count: rows.length, listings: rows }; } if (Object.keys(screen).length === 0) { return "No application state found. Is the app running?"; } return screen; }, });