Repository navigation
Hand the agent a file for anything that is not a picture #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -311,13 +311,15 @@ export function createAgentServer(options: { | |
| ) | ||
| return send(400, "bad image data"); | ||
| if ( | ||
| i.page !== undefined && | ||
| (typeof i.page !== "object" || | ||
| i.reference !== undefined && | ||
| (typeof i.reference !== "object" || | ||
| !["project", "community"].every( | ||
| (k) => i.page[k] === undefined || typeof i.page[k] === "string", | ||
| (k) => | ||
| i.reference[k] === undefined || | ||
| typeof i.reference[k] === "string", | ||
| )) | ||
| ) | ||
| return send(400, "bad image page"); | ||
| return send(400, "bad image reference"); | ||
| } | ||
| // The body cap above is the panel's limit in base64; a client that is not the | ||
| // panel meets the limit itself here, in the bytes the files come out as. | ||
|
|
@@ -507,20 +509,24 @@ export function createAgentServer(options: { | |
| name: string; | ||
| type: string; | ||
| data: string; | ||
| page?: { project?: string; community?: string }; | ||
| reference?: { project?: string; community?: string }; | ||
| }) => { | ||
| // A mockup's picture is kept for the panel, and the agent is pointed at its | ||
| // file, `<slug>/<file>.html` in the canvases of the project it was attached | ||
| // from, which need not be the one it is sent from. A community project's is not | ||
| // on this machine, so it keeps the name `sp fetch` finds it by. | ||
| const [slug, file, ...rest] = i.name.split("/"); | ||
| const from = i.page?.project && projects().get(i.page.project); | ||
| // Anything but a picture — a board, a video, a note — keeps its picture for the | ||
| // panel, and the agent is pointed at its file, `<slug>/<path>` in the canvases of | ||
| // the project it was attached from, which need not be the one it is sent from. A | ||
| // community project's is not on this machine, so it keeps the name `sp fetch` | ||
| // finds it by. | ||
| const [slug, ...rest] = i.name.split("/"); | ||
| const ref = i.reference; | ||
| const from = ref?.project && projects().get(ref.project); | ||
| const local = | ||
| i.page?.community === undefined && | ||
| (i.page?.project === undefined || from) && | ||
| rest.length === 0 && | ||
| ref?.community === undefined && | ||
| (ref?.project === undefined || from) && | ||
| SAFE_NAME.test(slug) && | ||
| SAFE_NAME.test(file ?? ""); | ||
| rest.length > 0 && | ||
| rest.every( | ||
| (s) => s && !s.startsWith(".") && !s.includes("\\"), | ||
| ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A |
||
| return { | ||
| ...i, | ||
| path: picture( | ||
|
|
@@ -529,19 +535,19 @@ export function createAgentServer(options: { | |
| i.type, | ||
| Buffer.from(i.data, "base64"), | ||
| ), | ||
| page: | ||
| i.page && | ||
| reference: | ||
| ref && | ||
| (local | ||
| ? path.join( | ||
| folderOf( | ||
| from ? path.join(from, CANVASES) : examplesDir, | ||
| examplesDir, | ||
| slug, | ||
| ), | ||
| file, | ||
| ...rest, | ||
| ) | ||
| : i.page.community | ||
| ? `${i.name} of the community project ${i.page.community}` | ||
| : ref.community | ||
| ? `${i.name} of the community project ${ref.community}` | ||
| : i.name), | ||
| }; | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,7 +94,7 @@ describe("AGENTS", () => { | |
| type: "image/png", | ||
| data: "CCC", | ||
| path: "/tmp/sp-chat-r/2.png", | ||
| page: "/proj/canvases/shop/01-home.html", | ||
| reference: "/proj/canvases/shop/01-home.html", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 2efcbee. |
||
| }; | ||
| expect( | ||
| JSON.parse(def("claude").stdin("tighten #2", "P", [board])).message | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,17 +54,19 @@ async function attach(editor: Editor, target: TLShape) { | |
| `&w=${Math.max(1, Math.round(w * scale))}&h=${Math.max(1, Math.round(h * scale))}`, | ||
| window.location.href, | ||
| ).href; | ||
| return dispatchAttach({ kind: "board", name, src, page: true }); | ||
| return dispatchAttach({ kind: "board", name, src, reference: true }); | ||
| } | ||
| // One of the person's own: whatever it is, the agent gets a picture of it, named by where it | ||
| // reads the thing itself (canvasContent.ts). | ||
| // One of the person's own, drawn for the tile and named by where the agent reads the thing | ||
| // itself (canvasContent.ts). A picture goes over as one; anything else — a video, a note, a | ||
| // drawing — is a file the agent is pointed at, as a board is. | ||
| const slug = personsShape(editor, target); | ||
| if (slug) { | ||
| const { blob } = await editor.toImage([target.id], { format: "png" }); | ||
| return dispatchAttach({ | ||
| kind: "board", | ||
| name: personsShapeName(editor, target, slug), | ||
| src: URL.createObjectURL(blob), | ||
| reference: target.type === "image" ? undefined : true, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a user creates or edits a note/drawing and immediately attaches and sends it, this switches the agent from the freshly rendered snapshot to Useful? React with 👍 / 👎.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in f78f602: the + awaits saveNow(slug) before handing over a reference to one of the person's shapes. |
||
| }); | ||
| } | ||
| const shape = target as TLImageShape; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 New comments contain em dashes
The changed comments here and in canvasAttach.tsx and agents.ts use em dashes, contrary to REVIEW.md.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 2efcbee.