61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { createAgent } from "./src/agent/create";
|
|
import { sendMessageStream } from "./src/agent/message";
|
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
|
|
async function main() {
|
|
// Create a simple test image (1x1 red PNG)
|
|
const testImageBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==";
|
|
const testImagePath = "/tmp/test.png";
|
|
writeFileSync(testImagePath, Buffer.from(testImageBase64, "base64"));
|
|
console.log("Created test image at", testImagePath);
|
|
|
|
// Create agent
|
|
console.log("\nCreating test agent...");
|
|
const agent = await createAgent("image-test-agent");
|
|
console.log("Agent created:", agent.id);
|
|
|
|
// Read image
|
|
const imageData = readFileSync(testImagePath).toString("base64");
|
|
|
|
// Send message with image
|
|
console.log("\nSending image to agent...");
|
|
const stream = await sendMessageStream(agent.id, [
|
|
{
|
|
role: "user",
|
|
content: [
|
|
{
|
|
type: "text",
|
|
text: "What do you see in this image?",
|
|
},
|
|
{
|
|
type: "image",
|
|
source: {
|
|
type: "base64",
|
|
media_type: "image/png",
|
|
data: imageData,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
|
|
// Print response
|
|
console.log("\nAgent response:");
|
|
let fullResponse = "";
|
|
for await (const chunk of stream) {
|
|
if (chunk.message_type === "assistant_message" && chunk.content) {
|
|
fullResponse += chunk.content;
|
|
process.stdout.write(chunk.content);
|
|
}
|
|
}
|
|
if (!fullResponse) {
|
|
console.log("(no assistant message received)");
|
|
}
|
|
console.log("\n\n✅ Done!");
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error("❌ Error:", err);
|
|
process.exit(1);
|
|
});
|