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