2026-07-29 11:50:08 +00:00
/**
* 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" ;
2026-07-29 12:18:14 +00:00
import { eq } from "@agent-native/core/db/schema" ;
2026-07-29 11:50:08 +00:00
import { z } from "zod" ;
2026-07-29 12:18:14 +00:00
import { getDb } from "../server/db/index.js" ;
import { stocks } from "../server/db/schema.js" ;
2026-07-29 11:50:08 +00:00
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 ,
2026-07-29 12:18:14 +00:00
run : async ( _args , ctx ) => {
2026-07-29 11:50:08 +00:00
const navigation = await readAppState ( "navigation" );
const screen : Record < string , unknown > = {};
if ( navigation ) screen . navigation = navigation ;
2026-07-29 12:18:14 +00:00
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 };
}
2026-07-29 11:50:08 +00:00
if ( Object . keys ( screen ). length === 0 ) {
return "No application state found. Is the app running?" ;
}
return screen ;
},
});