Build Verse: a poem-quote app on the agent-native chat template
CI / build (push) Successful in 4m26s
CI / build (push) Successful in 4m26s
Adds a Postgres-backed quotes domain (poems/quotes/favorites) exposed as five agent-native actions (list-quotes, get-random-quote, create-quote, toggle-favorite, list-favorites) callable from both chat and the React UI via useActionQuery/useActionMutation. Moves the primary UI from chat to a mobile-first Quotes/Favorites experience (chat moves to /chat), adds manual OpenTelemetry instrumentation exporting traces/metrics/logs over OTLP, and wires a local Docker Postgres for shared state.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { defineAction } from "@agent-native/core/action";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { z } from "zod";
|
||||
|
||||
import { db, schema } from "../server/db/index.js";
|
||||
import { fetchAllQuoteRows, hydrateQuotes } from "../server/lib/quotes.js";
|
||||
import { withActionSpan } from "../server/otel.js";
|
||||
|
||||
export default defineAction({
|
||||
description: "List all quotes a given visitor has favorited, most recently favorited first.",
|
||||
schema: z.object({
|
||||
visitorId: z.string().min(1).describe("Anonymous visitor id (from browser storage)"),
|
||||
}),
|
||||
http: { method: "GET" },
|
||||
run: async (args) => {
|
||||
return withActionSpan("list-favorites", { visitorId: args.visitorId }, async () => {
|
||||
const favorites = await db()
|
||||
.select()
|
||||
.from(schema.favorites)
|
||||
.where(eq(schema.favorites.visitor_id, args.visitorId));
|
||||
|
||||
if (favorites.length === 0) return [];
|
||||
|
||||
const favoritedAt = new Map(favorites.map((f) => [f.quote_id, f.created_at ?? ""]));
|
||||
const allRows = await fetchAllQuoteRows();
|
||||
const rows = allRows.filter((row) => favoritedAt.has(row.quote.id));
|
||||
rows.sort((a, b) => (favoritedAt.get(b.quote.id) ?? "").localeCompare(favoritedAt.get(a.quote.id) ?? ""));
|
||||
|
||||
return hydrateQuotes(rows, args.visitorId);
|
||||
});
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user