Files
letta-code/src/tests/message.smoke.ts
Charles Packer ef7d8c98df refactor: use conversations (#475)
Co-authored-by: Letta <noreply@letta.com>
2026-01-13 16:40:59 -08:00

100 lines
2.8 KiB
TypeScript
Executable File

#!/usr/bin/env bun
/**
* Quick sanity check: create an agent, send a message, log streamed output.
*/
import { getClient } from "../agent/client";
import { createAgent } from "../agent/create";
import { sendMessageStream } from "../agent/message";
async function main() {
const apiKey = process.env.LETTA_API_KEY;
if (!apiKey) {
console.error("❌ Missing LETTA_API_KEY in env");
process.exit(1);
}
const client = await getClient();
console.log("🧠 Creating test agent...");
const { agent } = await createAgent("smoke-agent", "openai/gpt-4.1");
console.log(`✅ Agent created: ${agent.id}`);
console.log("📝 Creating conversation...");
const conversation = await client.conversations.create({
agent_id: agent.id,
});
console.log(`✅ Conversation created: ${conversation.id}`);
console.log("💬 Sending test message...");
const stream = await sendMessageStream(conversation.id, [
{
role: "user",
content: "Hello from Bun smoke test! Try calling a tool.",
},
]);
// Print every chunk as it arrives
for await (const chunk of stream) {
const type = chunk.message_type ?? "unknown";
switch (chunk.message_type) {
case "reasoning_message": {
const run = chunk.run_id
? `run=${chunk.run_id}:${chunk.seq_id ?? "-"} `
: "";
process.stdout.write(
`[reasoning] ${run}${JSON.stringify(chunk) ?? ""}\n`,
);
break;
}
case "assistant_message": {
const run = chunk.run_id
? `run=${chunk.run_id}:${chunk.seq_id ?? "-"} `
: "";
process.stdout.write(
`[assistant] ${run}${JSON.stringify(chunk) ?? ""}\n`,
);
break;
}
case "tool_call_message": {
const run = chunk.run_id
? `run=${chunk.run_id}:${chunk.seq_id ?? "-"} `
: "";
process.stdout.write(
`[tool_call] ${run}${JSON.stringify(chunk) ?? ""}\n`,
);
break;
}
case "tool_return_message": {
const run = chunk.run_id
? `run=${chunk.run_id}:${chunk.seq_id ?? "-"} `
: "";
process.stdout.write(`[tool_return] ${run}${chunk}\n`);
break;
}
case "approval_request_message": {
const run = chunk.run_id
? `run=${chunk.run_id}:${chunk.seq_id ?? "-"} `
: "";
process.stdout.write(
`[approval_request] ${run}${JSON.stringify(chunk)}\n`,
);
break;
}
case "ping":
// keepalive ping, ignore
break;
default:
process.stdout.write(`[event:${type}] ${JSON.stringify(chunk)}\n`);
}
}
console.log("\n✅ Stream ended cleanly");
}
main().catch((err) => {
console.error("❌ Smoke test failed:", err);
process.exit(1);
});