13 for (const row of res.rows) {
14 console.log("delete", row.id);
15 blob.delete("pondiverse_image" + row.id);
16 }
17
46 for (let creation of response.rows) {
47 creation.uri = `https://pondiverse.val.run/get-creation?id=${creation.id}`;
48 creation.image = `https://pondiverse.val.run/get-creation-image?id=${creation.id}`;
49 }
50
9 data TEXT,
10 type TEXT,
11 image TEXT,
12 time DATETIME NOT NULL
13 )`,
1import addCreation from "./addCreation";
2import getCreation from "./getCreation";
3import getCreationImage from "./getCreationImage";
4import getCreations from "./getCreations";
5import updateTable from "./updateTable";
13 case "/get-creation":
14 return getCreation(req);
15 case "/get-creation-image":
16 return getCreationImage(req);
17 case "/get-creations":
18 return getCreations(req);
9 let response;
10 try {
11 response = await blob.get("pondiverse_image" + id);
12 } catch (e) {
13 return new Response(null, { status: 404 });
9 // - data (string)
10 // - type (string)
11 // - image (data url string)
12
13 // sanity checks:
15 // - data, hmm this needs to be long i guess.. maybe some crazy upper limit sanity check though
16 // - type, not too long
17 // - image, not toooo large a file size
18 let body;
19 try {
26 const data = body.data;
27 const type = body.type;
28 const image = body.image;
29
30 // Sanity checks
38 }
39
40 if (image.length > 20 * 1024 * 1024) {
41 return Response.json({ ok: false, error: "Thumbnail too large" });
42 }
57 );
58
59 await blob.set("pondiverse_image" + id.lastInsertRowid, image);
60 return Response.json({ ok: true });
61}
45 user: {
46 username: string;
47 profileImageUrl: string | null;
48 };
49 project: any;
51 return (
52 <div className="card">
53 {project.imageUrl
54 ? <img src={project.imageUrl} className="card-image" />
55 : user.profileImageUrl
56 ? (
57 <div className="card-image">
58 <img
59 src={user.profileImageUrl}
60 width="48"
61 height="48"
64 </div>
65 )
66 : <div className="card-image placeholder" />}
67 <div className="card-body">
68 <div className="username">{user.username}</div>
46 model: message.model,
47 price: message.price,
48 images: message.images,
49 finishReason: message.finish_reason,
50 };
168 model,
169 price,
170 images,
171 finishReason,
172}: {
181 model?: string;
182 price?: number;
183 images?: any;
184 finishReason?: string;
185}): Promise<number> {
186 const result = await sqlite.execute(
187 `INSERT INTO ${MESSAGES_TABLE}
188 (thread_id, user_id, content, created_at, role, inputTokens, outputTokens, cache_read_tokens, cache_write_tokens, model, price, images, finish_reason)
189 VALUES (?, ?, ?, datetime('now'), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
190 RETURNING id`,
199 model || null,
200 price || null,
201 images ? JSON.stringify(images) : null,
202 finishReason || null,
203 ],
29 role: string;
30 version?: number;
31 images?: string;
32 input_tokens?: number;
33 output_tokens?: number;
70 role STRING NOT NULL,
71 version INTEGER,
72 images JSON,
73 input_tokens Integer,
74 output_tokens Integer,
15
16app.post("/", async (c) => {
17 let { messages, project, branchId, anthropicApiKey, selectedFiles, images, threadId } = await c.req.json();
18 console.log("Original messages:", JSON.stringify(messages, null, 2));
19 console.log("Images received:", JSON.stringify(images, null, 2));
20
21 // TODO: put in zod
47 content: messages.at(-1).content,
48 role: "user",
49 // TODO: images
50 });
51
52 let coreMessages = convertToCoreMessages(messages);
53
54 // If there are images, we need to add them to the last user message
55 if (images && Array.isArray(images) && images.length > 0) {
56 // Find the last user message
57 const lastUserMessageIndex = coreMessages.findIndex(
75 };
76
77 // Add each image to the content array using the correct ImagePart format
78 for (const image of images) {
79 if (image && image.url) {
80 // Extract mime type from data URL if available
81 let mimeType = undefined;
82 if (image.url.startsWith("data:")) {
83 const matches = image.url.match(/^data:([^;]+);/);
84 if (matches && matches.length > 1) {
85 mimeType = matches[1];
88
89 newUserMessage.content.push({
90 type: "image",
91 image: image.url,
92 mimeType,
93 });
1import addCreation from "./addCreation";
2import getCreation from "./getCreation";
3import getCreationImage from "./getCreationImage";
4import getCreations from "./getCreations";
5import updateTable from "./updateTable";
13 case "/get-creation":
14 return getCreation(req);
15 case "/get-creation-image":
16 return getCreationImage(req);
17 case "/get-creations":
18 return getCreations(req);