holy fuck voice to agent response works kinda sorta

This commit is contained in:
pierre committed 2026-08-24 03:26:43 +03:00
commit 3ddb0e77bc
6 files changed
+614

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
const std = @import("std");
const LETTA_PATH = "/home/pierre/.bun/bin/letta";
/// Runs `letta -n <agent> -p <prompt>`, captures everything it writes to
/// stdout, and returns it as an owned slice (caller frees it).
pub fn infer(
io: std.Io,
allocator: std.mem.Allocator,
agent: []const u8,
prompt: []const u8,
) ![]u8 {
var child = try std.process.spawn(io, .{
.argv = &.{ LETTA_PATH, "--agent", agent, "-p", prompt, "--conversation", "default", "--toolset", "default" },
.stdout = .pipe,
.stderr = .inherit, // letta's error output goes straight to your terminal
});
// Non-null because we asked for a pipe.
const stdout_file = child.stdout.?;
var output: std.ArrayList(u8) = .empty;
errdefer output.deinit(allocator);
var buf: [16 * 1024]u8 = undefined;
while (true) {
const n = stdout_file.readStreaming(io, &.{&buf}) catch |err| switch (err) {
// EOF in the new Io API: letta closed its stdout. That's success.
error.EndOfStream => break,
else => |e| return e,
};
if (n == 0) break; // defensive: never spin if a 0 ever comes back
try output.appendSlice(allocator, buf[0..n]);
}
const term = try child.wait(io);
const exited_cleanly = switch (term) {
.exited => |code| code == 0,
else => false,
};
if (!exited_cleanly) return error.LettaFailed;
return output.toOwnedSlice(allocator);
}