diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..35b0920 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +.env +.env.* +!.env.example +!.env.template +.dev.vars +.dev.vars.* +!.dev.vars.example +*.log diff --git a/app/.dev.vars.example b/app/.dev.vars.example index 5904c67..1cfc9e3 100644 --- a/app/.dev.vars.example +++ b/app/.dev.vars.example @@ -13,3 +13,7 @@ APP_ORIGIN="" # Connector token for TigerInbox's MCP (inbox.tigerapps.org/api/mcp); matches TIGERINBOX_MCP_TOKEN there. TIGERINBOX_MCP_TOKEN="" + +# TigerDraw companion: set the URL for local development. Token matches MCP_ACCESS_TOKEN there. +TIGERDRAW_MCP_URL="http://127.0.0.1:3333/mcp" +TIGERDRAW_MCP_TOKEN="" diff --git a/app/.gitignore b/app/.gitignore index 8694df6..b205a04 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -3,3 +3,8 @@ dist .dev.vars .wrangler worker-configuration.d.ts +.env +.env.* +!.env.example +*.log +*.tsbuildinfo diff --git a/app/README.md b/app/README.md index 596b7e8..d040f98 100644 --- a/app/README.md +++ b/app/README.md @@ -72,6 +72,14 @@ browser (React + useAgentChat over WebSocket) ## Develop +TigerDraw uses its own read-only MCP companion in the TigerDraw repository. +Enable it in My apps after starting that service. Set `TIGERDRAW_MCP_URL` to +`http://127.0.0.1:3333/mcp` for local development, and `TIGERDRAW_MCP_TOKEN` to +its `MCP_ACCESS_TOKEN` if authentication is enabled. Production defaults to +`https://draw.tigerapps.org/mcp`. PI forwards only this dedicated token, without +Junction credentials or student identity. The endpoint must be deployed before +hosted PI can reach it. No new database credentials are required. + ```bash npm install cp .dev.vars.example .dev.vars # fill in secrets as needed @@ -124,3 +132,10 @@ token. matches the production transform. - `useAgentChat` suspends while loading history — keep chat pages under a `` boundary. + +### Floor-plan previews + +TigerDraw owns and hosts floor-plan previews. MCP results supply `preview_url` +alongside each original PDF URL. PI renders that URL with an original-document +link and a compact fallback if the preview is unavailable. PI contains no +TigerDraw document assets, manifest, PDF renderer, or preview-generation step. diff --git a/app/public/logos/tigerdraw.png b/app/public/logos/tigerdraw.png new file mode 100644 index 0000000..087fe9d Binary files /dev/null and b/app/public/logos/tigerdraw.png differ diff --git a/app/src/client/components/Icons.tsx b/app/src/client/components/Icons.tsx index 9028d19..48d42a9 100644 --- a/app/src/client/components/Icons.tsx +++ b/app/src/client/components/Icons.tsx @@ -298,3 +298,50 @@ export function PiMark({ size = 16, title, ...rest }: IconProps) { ); } + +/** Room facts, matching the shared outline icon set. */ +export function IconPeople(props: IconProps) { + return ( + + + + + ); +} +export function IconArea(props: IconProps) { + return ( + + + + + ); +} +export function IconFloors(props: IconProps) { + return ( + + + + ); +} +export function IconCooling(props: IconProps) { + return ( + + + + ); +} +export function IconElevator(props: IconProps) { + return ( + + + + + ); +} +export function IconRank(props: IconProps) { + return ( + + + + ); +} diff --git a/app/src/client/components/Markdown.tsx b/app/src/client/components/Markdown.tsx index 97c687f..8307353 100644 --- a/app/src/client/components/Markdown.tsx +++ b/app/src/client/components/Markdown.tsx @@ -1,5 +1,6 @@ import { Fragment, type ReactNode } from "react"; import { IconExternal } from "./Icons"; +import { studentSourceLink } from "../../shared/source-links"; /** * A deliberately small markdown renderer for chat prose: paragraphs, lists @@ -36,10 +37,11 @@ function inline(text: string, keyBase: string): ReactNode[] { } else if (tok.startsWith("[")) { const lm = tok.match(/^\[([^\]]+)\]\(([^)\s]+)\)$/); if (lm) { - const external = /^https?:\/\//i.test(lm[2]); + const link = studentSourceLink(lm[2]); + const external = /^https?:\/\//i.test(link.href); out.push( - - {lm[1]} + + {link.label ?? lm[1]} {external && } ); diff --git a/app/src/client/components/TigerDrawResults.tsx b/app/src/client/components/TigerDrawResults.tsx new file mode 100644 index 0000000..769f889 --- /dev/null +++ b/app/src/client/components/TigerDrawResults.tsx @@ -0,0 +1,357 @@ +import { useState } from "react"; +import { + IconPeople, + IconArea, + IconFloors, + IconCooling, + IconElevator, + IconRank, + IconStar, +} from "./Icons"; +import { + housingObject, + housingContent, + housingDataStatus, + housingUrl, + housingTourUrl, + housingWarnings, +} from "../lib/tigerdraw"; + +const text = (value: unknown) => (typeof value === "string" ? value : ""); +function RoomRow({ room }: { room: Record }) { + const conflicts = housingObject(room.conflicts); + const known = (field: string) => !Object.hasOwn(conflicts, field); + const numeric = (field: string) => + known(field) && + typeof room[field] === "number" && + Number.isFinite(room[field]); + const facts = [ + numeric("occupancy") && { + key: "occupancy", + icon: IconPeople, + label: "Occupancy", + value: `${room.occupancy} ${room.occupancy === 1 ? "person" : "people"}`, + }, + numeric("sq_footage") && { + key: "area", + icon: IconArea, + label: "Room size", + value: `${room.sq_footage} sq ft`, + }, + known("floor") && + (typeof room.floor === "string" || typeof room.floor === "number") && + String(room.floor).trim() !== "" && { + key: "floor", + icon: IconFloors, + label: "Floor", + value: String(room.floor), + }, + known("ac") && + room.ac === true && { + key: "ac", + icon: IconCooling, + label: "Air conditioning", + value: "Available", + }, + known("elevator") && + room.elevator === true && { + key: "elevator", + icon: IconElevator, + label: "Elevator", + value: "Available", + }, + numeric("draw_rank") && { + key: "rank", + icon: IconRank, + label: "Historical draw rank", + value: `#${room.draw_rank}`, + }, + numeric("avg_rating") && { + key: "rating", + icon: IconStar, + label: "Student rating", + value: `${room.avg_rating}/5${numeric("num_reviews") ? ` · ${room.num_reviews} ${room.num_reviews === 1 ? "review" : "reviews"}` : ""}`, + }, + ].filter((fact) => !!fact); + return ( +
+ + {text(room.building)} {text(room.room_no)} + + {facts.length > 0 && ( +
+ {facts.map(({ key, icon: FactIcon, label, value }) => ( +
+ +
+
{label}
+
{value}
+
+
+ ))} +
+ )} +
+ ); +} +function mediaTitle(media: Record) { + return ( + (( + { + floor_plan: /\.pdf$/i.test(new URL(housingUrl(media.url)!).pathname) + ? "PDF floor plan" + : "Image floor plan", + room_plan: "Room plan", + thumbnail: "Building photo", + "360": "360° tour", + } as Record + )[text(media.type)] || "Room image") + + (media.floor ? ` · floor ${text(media.floor)}` : "") + ); +} +function MediaPreview({ + media, + roomLabel, +}: { + media: Record; + roomLabel: string; +}) { + const [failed, setFailed] = useState(false); + const url = housingUrl(media.url)!; + const title = mediaTitle(media); + const tour = media.type === "360" ? housingTourUrl(url) : null; + const preview = housingUrl(media.preview_url); + const image = + preview || + (media.type !== "360" && + /\.(?:png|jpe?g|webp|gif|avif|svg)$/i.test(new URL(url).pathname)); + return ( + <> +
+ {tour ? ( +