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.
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { defineAction } from "@agent-native/core/action";
|
|
import { z } from "zod";
|
|
|
|
import { withActionSpan } from "../server/otel.js";
|
|
import { fetchAllQuoteRows, hydrateQuotes, parseTags } from "../server/lib/quotes.js";
|
|
|
|
export default defineAction({
|
|
description:
|
|
"Get one random poem quote, optionally restricted to a tag. Use for a \"quote of the day\" / discover surface.",
|
|
schema: z.object({
|
|
tag: z.string().optional().describe("Only pick from quotes with this tag"),
|
|
visitorId: z
|
|
.string()
|
|
.optional()
|
|
.describe("Anonymous visitor id, used to mark whether this visitor already favorited the pick"),
|
|
}),
|
|
http: { method: "GET" },
|
|
run: async (args) => {
|
|
return withActionSpan("get-random-quote", { tag: args.tag }, async () => {
|
|
const rows = await fetchAllQuoteRows();
|
|
const candidates = args.tag
|
|
? rows.filter((row) => parseTags(row.quote.tags_json).includes(args.tag!))
|
|
: rows;
|
|
|
|
if (candidates.length === 0) return null;
|
|
|
|
const pick = candidates[Math.floor(Math.random() * candidates.length)];
|
|
const [hydrated] = await hydrateQuotes([pick], args.visitorId);
|
|
return hydrated;
|
|
});
|
|
},
|
|
});
|