Skip to content

Commit 555bfc9

Browse files
committed
fix: send images as filePart entries (partId='image') instead of base64 in JSON
PubNub publishes are size-capped (~32KB default); inlining a 100-300KB base64 image into the textPart JSON exceeded that and failed with 'failed to publish request event'. filePart hands the bytes to the SDK, which uploads anything >16KB via the pre-signed URL flow (out-of-band of the PubNub message). The PubNub message itself stays tiny — just an artifactRef pointing at the upload session. Pairs with the agent-card image input declaration (contentType image/jpeg) and the handler change that reads file parts via ctx.download_input_artifact(part).
1 parent 0b704ba commit 555bfc9

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/main.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import './style.css';
2-
import { TaskClient, textPart } from '@blocks-network/sdk';
2+
import { TaskClient, textPart, filePart } from '@blocks-network/sdk';
33

44
const AGENT_NAME = '5090_gemma_4';
55
const BILLING_MODE = 'paid';
@@ -301,10 +301,22 @@ async function sendPrompt(promptText, images) {
301301
try {
302302
const client = await getClient();
303303
const payload = { prompt: promptText, max_tokens: state.maxTokens };
304-
if (images && images.length) payload.images = images;
304+
const parts = [textPart(JSON.stringify(payload), 'request')];
305+
for (let i = 0; i < (images || []).length; i++) {
306+
const bin = atob(images[i]);
307+
const bytes = new Uint8Array(bin.length);
308+
for (let j = 0; j < bin.length; j++) bytes[j] = bin.charCodeAt(j);
309+
parts.push(
310+
filePart(bytes, {
311+
partId: 'image',
312+
contentType: 'image/jpeg',
313+
fileName: `image-${i}.jpg`,
314+
})
315+
);
316+
}
305317
const session = await client.sendMessage({
306318
agentName: AGENT_NAME,
307-
requestParts: [textPart(JSON.stringify(payload), 'request')],
319+
requestParts: parts,
308320
});
309321

310322
const terminal = await session.waitForTerminal(180_000);

0 commit comments

Comments
 (0)