- Add stocks table (server/db) with list/get/add/update/delete actions, scoped per user, backing both the chat agent and the /stocks UI via useActionQuery/useActionMutation - Add mobile-first /stocks page (shadcn table/cards, watchlist, search) and wire it into the sidebar, navigation state, and view-screen context - Install the platform's Claude Agent SDK harness (server/plugins, server/routes/api/claude-agent) so the app agent runs on the platform's own Claude subscription instead of the Builder.io gateway; fix the vendored turn.post.ts route to resolve the session and wrap it in runWithRequestContext, since custom /api/ routes aren't auto-wrapped in request context the way /_agent-native/actions/* are - Add shadcn table/badge/dialog/select components (Tabler icons, not lucide)
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { defineAction } from "@agent-native/core/action";
|
|
import { and, 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:
|
|
"Update fields on an existing stock listing (patch — only pass the fields that change). Use this to edit price, change percent, sector, or toggle the watchlist.",
|
|
schema: z.object({
|
|
id: z.string().describe("Stock listing id"),
|
|
companyName: z.string().optional(),
|
|
exchange: z.string().optional(),
|
|
sector: z.string().optional(),
|
|
currency: z.string().optional(),
|
|
price: z.coerce.number().optional(),
|
|
changePercent: z.coerce.number().optional(),
|
|
marketCap: z.coerce.number().optional(),
|
|
watchlisted: z
|
|
.enum(["true", "false"])
|
|
.optional()
|
|
.describe("Set to \"true\" or \"false\" to toggle the watchlist"),
|
|
}),
|
|
http: { method: "PUT" },
|
|
run: async (args, ctx) => {
|
|
if (!ctx?.userEmail) throw new Error("Authentication required.");
|
|
const { id, watchlisted, ...rest } = args;
|
|
const db = getDb();
|
|
|
|
const patch: Record<string, unknown> = { ...rest };
|
|
if (watchlisted !== undefined) patch.watchlisted = watchlisted === "true";
|
|
if (Object.keys(patch).length === 0) {
|
|
throw new Error("No fields to update.");
|
|
}
|
|
patch.updatedAt = new Date().toISOString();
|
|
|
|
const updated = await db
|
|
.update(stocks)
|
|
.set(patch)
|
|
.where(and(eq(stocks.id, id), eq(stocks.ownerEmail, ctx.userEmail)))
|
|
.returning();
|
|
|
|
if (!updated[0]) throw new Error("Stock not found.");
|
|
return updated[0];
|
|
},
|
|
});
|