diff --git a/app/api/html/route.ts b/app/api/html/route.ts index 3392094..6393e99 100644 --- a/app/api/html/route.ts +++ b/app/api/html/route.ts @@ -28,9 +28,11 @@ export async function POST(req: NextRequest) { const url = formData.get("url")! as string; const rawDeps = (formData.get("deps") as string) || "[]"; const deps = JSON.parse(rawDeps); + const prompts = JSON.parse((formData.get("prompts")! as string) || "[]"); const settings: Settings = JSON.parse(formData.get("settings")! as string); const programStream = await createProgramStream({ url, + prompts, // Keep only the last 3 deps deps: deps .filter( @@ -57,11 +59,22 @@ async function createProgramStream({ url, deps, settings, + prompts, }: { url: string; deps: { url: string; html: string }[]; settings: Settings; + prompts: string[]; }) { + const makeMessage = (url: string) => { + if (!prompts.length) { + return `${url}`; + } + + return `${prompts + .map((prompt) => `${prompt}`) + .join("\n")}\n${url}`; + }; const params: ChatCompletionCreateParamsStreaming = { messages: [ { @@ -71,7 +84,7 @@ async function createProgramStream({ ...deps.flatMap((dep): ChatCompletionMessageParam[] => [ { role: "user", - content: dep.url, + content: makeMessage(dep.url), }, { role: "assistant", @@ -83,7 +96,7 @@ async function createProgramStream({ ]), { role: "user", - content: url, + content: makeMessage(url), }, ], diff --git a/components/BottomBar.tsx b/components/BottomBar.tsx index 29880e6..dab5313 100644 --- a/components/BottomBar.tsx +++ b/components/BottomBar.tsx @@ -1,4 +1,4 @@ -import { Hand, MousePointer2, PanelTop } from "lucide-react"; +import { Hand, MousePointer2, PanelTop, ScrollText } from "lucide-react"; import { Card } from "./ui/card"; import { ToggleGroupItem, ToggleGroup } from "./ui/toggle-group"; import { useEditor, useValue } from "tldraw"; @@ -29,6 +29,9 @@ export function BottomBar() { + + + ); diff --git a/components/BrowserShape.tsx b/components/BrowserShape.tsx index 095347b..f10f6a2 100644 --- a/components/BrowserShape.tsx +++ b/components/BrowserShape.tsx @@ -7,6 +7,7 @@ import { TLBaseShape, TLShape, TLShapeId, + TLTextShape, Vec, toDomPrecision, useIsEditing, @@ -245,6 +246,21 @@ export class BrowserShapeUtil extends BaseBoxShapeUtil { [this.editor] ); + const promptsParam = useValue( + "prompts", + () => { + return JSON.stringify( + this.editor + .getCurrentPageShapes() + .filter((s): s is TLTextShape => + Boolean(s.type === "text" && s.meta.prompt) + ) + .map((t) => t.props.text) + ); + }, + [this.editor] + ); + // The deps are in top to bottom order const depsParams = useValue( "deps", @@ -346,6 +362,7 @@ export class BrowserShapeUtil extends BaseBoxShapeUtil { /> +