summaryrefslogtreecommitdiff
path: root/src/main.zig
blob: 4f9c4906d0bb89caf5ec046bc18ec7d5a6468f15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const std = @import("std");
const libpanto = @import("panto");

pub fn main() !void {
    const config = libpanto.config.Config{
        .api_style = .anthropic,
        .api_key = "test",
        .base_url = "https://api.anthropic.com",
        .model = "claude-sonnet-4-20250514",
    };

    var debug_allocator = std.heap.DebugAllocator(.{}).init;
    defer _ = debug_allocator.deinit();
    const alloc = debug_allocator.allocator();

    var conv = libpanto.conversation.Conversation.init(alloc);
    defer conv.deinit();

    try conv.addSystemMessage("You are a helpful assistant.");

    const io = std.Io.Threaded.global_single_threaded.io();

    var stdout_buffer: [4096]u8 = undefined;
    var stdout_file = std.Io.File.stdout().writer(io, &stdout_buffer);
    const stdout = &stdout_file.interface;

    var stdin_buffer: [4096]u8 = undefined;
    var stdin_file = std.Io.File.stdin().reader(io, &stdin_buffer);
    const stdin = &stdin_file.interface;

    try stdout.print("panto — model: {s}\n> ", .{config.model});
    try stdout_file.flush();

    while (true) {
        const line = stdin.takeDelimiter('\n') catch |err| {
            std.debug.print("Read error: {}\n", .{err});
            return;
        };
        if (line) |text| {
            if (text.len == 0) {
                try stdout.print("> ", .{});
                try stdout_file.flush();
                continue;
            }
            // Copy the line since the reader buffer may be reused
            const owned = try alloc.dupe(u8, text);
            defer alloc.free(owned);
            try conv.addUserMessage(owned);
            // TODO: call agent.runStep() once provider is implemented
            try stdout.print("(streaming not yet implemented)\n> ", .{});
            try stdout_file.flush();
        } else {
            // EOF (Ctrl+D)
            try stdout.print("\n", .{});
            try stdout_file.flush();
            break;
        }
    }
}