llms.ts
This file
Path
apps/web/src/server/llms.ts
97 lines · 2.7 KiB · TypeScript
Last changed by
Merge build/comments-web-rest into mainoscabrielbefore adoption0eb1248
History of this fileTake it
Merge build/1221-front-and-project-homeoscabrielbefore adoption493b2dd
lines 1–12why, one step back1import { Client } from "@repo/protocol/contracts";2import { ProjectName } from "@repo/protocol/ids";3import { Array as Arr, Effect, Option, Schema } from "effect";4import type { Layer } from "effect";56import { commands } from "../features/agents/catalog.ts";7import {8 frontLlms,9 missingProjectLlms,10 projectLlms,11} from "../features/agents/llms.ts";12import { markdown, unavailable } from "../features/agents/respond.ts";Fix the finish review's findings: drafted code draws, counts agree, commands hangoscabrielbefore adoptionf7f6e49
line 13why, one step back13import { stillWaiting } from "../features/front/families.ts";Merge build/1221-front-and-project-homeoscabrielbefore adoption493b2dd
lines 14–84why, one step back1415export type ClientFor = (request: Request) => Layer.Layer<Client>;1617export const frontLlmsHandler =18 (clientFor: ClientFor, platformUrl: string) =>19 ({ request }: { readonly request: Request }): Promise<Response> =>20 Effect.runPromise(21 Effect.gen(function* () {22 const client = yield* Client;23 const { projects } = yield* client.listProjects({});2425 return markdown(26 frontLlms({27 commands,28 platformUrl,29 projects,30 webUrl: new URL(request.url).origin,31 })32 );33 }).pipe(34 Effect.orElseSucceed(unavailable),35 Effect.provide(clientFor(request))36 )37 );3839const decodeProject = Schema.decodeUnknownOption(ProjectName);4041export const projectLlmsHandler =42 (clientFor: ClientFor, platformUrl: string) =>43 ({44 params,45 request,46 }: {47 readonly params: { readonly project: string };48 readonly request: Request;49 }): Promise<Response> =>50 Effect.runPromise(51 Effect.gen(function* () {52 const webUrl = new URL(request.url).origin;53 const project = decodeProject(params.project);5455 const missing = () =>56 markdown(missingProjectLlms({ project, webUrl }), 404);5758 if (Option.isNone(project)) {59 return missing();60 }6162 const client = yield* Client;63 const { projects } = yield* client.listProjects({});6465 const listing = Arr.findFirst(66 projects,67 (each) => each.project === project.value68 );6970 if (Option.isNone(listing)) {71 return missing();72 }7374 const asks = yield* client.listAsks({ project: project.value }).pipe(75 Effect.map((listed) => Option.some(listed.asks)),76 Effect.catchTag("UnknownProject", () => Effect.succeedNone)77 );7879 if (Option.isNone(asks)) {80 return missing();81 }8283 return markdown(84 projectLlms({Fix the finish review's findings: drafted code draws, counts agree, commands hangoscabrielbefore adoptionf7f6e49
lines 85–86why, one step back85 // An ask waits only on asks still open, as the page says.86 asks: stillWaiting(asks.value),Merge build/1221-front-and-project-homeoscabrielbefore adoption493b2dd
lines 87–97why, one step back87 commands,88 listing: listing.value,89 platformUrl,90 webUrl,91 })92 );93 }).pipe(94 Effect.orElseSucceed(unavailable),95 Effect.provide(clientFor(request))96 )97 );