| 1 | import { data } from "react-router"; |
| 2 | |
| 3 | import type { Route } from "./+types/memory"; |
| 4 | import { page } from "../../lib/meta"; |
| 5 | import { AddMemory, MemoryList, memoryAction } from "../../components/memory"; |
| 6 | import { agents } from "../../lib/services.server"; |
| 7 | import { assertSameOrigin, getViewer, requireUser, roleIn, unwrap } from "../../lib/session.server"; |
| 8 | import { Card } from "../../components/ui/card"; |
| 9 | |
| 10 | export function meta({ params, ...args }: Route.MetaArgs) { |
| 11 | return page(args, { title: `Workspace memory · ${params.owner} · g1t` }); |
| 12 | } |
| 13 | |
| 14 | export async function loader({ params, context }: Route.LoaderArgs) { |
| 15 | const viewer = getViewer(context); |
| 16 | if (!roleIn(viewer, params.owner)) throw data(null, { status: 404 }); |
| 17 | const memories = await agents.listMemories(viewer, params.owner); |
| 18 | return { workspace: unwrap(memories).workspace }; |
| 19 | } |
| 20 | |
| 21 | export async function action({ params, context, request }: Route.ActionArgs) { |
| 22 | assertSameOrigin(request); |
| 23 | const user = requireUser(context, request); |
| 24 | return memoryAction(agents, user, params.owner, null, await request.formData()); |
| 25 | } |
| 26 | |
| 27 | export default function WorkspaceMemory({ loaderData, params }: Route.ComponentProps) { |
| 28 | const { workspace } = loaderData; |
| 29 | const action = `/${params.owner}/-/memory`; |
| 30 | return ( |
| 31 | <div className="space-y-8"> |
| 32 | <div className="grid gap-3 text-sm sm:grid-cols-2"> |
| 33 | <Card className="p-4"> |
| 34 | <p className="font-medium">Here: true in every project</p> |
| 35 | <p className="mt-1 text-muted"> |
| 36 | "We use pnpm everywhere." "Staging lives at staging.example.com." "Every service logs |
| 37 | JSON to stdout." What an agent in any project should know. |
| 38 | </p> |
| 39 | </Card> |
| 40 | <Card className="p-4"> |
| 41 | <p className="font-medium">In a project: true of its code</p> |
| 42 | <p className="mt-1 text-muted"> |
| 43 | How to build and test it, its conventions and its traps. Each project keeps its own under |
| 44 | Agents, Memory. |
| 45 | </p> |
| 46 | </Card> |
| 47 | </div> |
| 48 | |
| 49 | <AddMemory scope="workspace" action={action} placeholder="We use pnpm everywhere, never npm or yarn." /> |
| 50 | |
| 51 | <section> |
| 52 | <div className="flex items-baseline justify-between"> |
| 53 | <h2 className="text-sm font-medium">What the workspace remembers</h2> |
| 54 | <span className="text-xs text-muted">{workspace.length} kept</span> |
| 55 | </div> |
| 56 | <div className="mt-3"> |
| 57 | <MemoryList |
| 58 | memories={workspace} |
| 59 | action={action} |
| 60 | editable |
| 61 | empty="Nothing yet. Agents add what holds across projects as they learn it, and so can you." |
| 62 | /> |
| 63 | </div> |
| 64 | </section> |
| 65 | </div> |
| 66 | ); |
| 67 | } |