summaryrefslogtreecommitdiff
path: root/libpanto/src/provider.zig
diff options
context:
space:
mode:
authorT <t@tjp.lol>2026-05-25 21:50:43 -0600
committerT <t@tjp.lol>2026-05-25 22:19:44 -0600
commitf026bb81ae68f516910d0eb4f23c9344dd36b62b (patch)
treee091d1a870cc75dc92e6cee785ee78ff4d6f088f /libpanto/src/provider.zig
parentdf2edee86eec2a8deb0ad57b5d20552199c12b65 (diff)
phase 2 done
Diffstat (limited to 'libpanto/src/provider.zig')
-rw-r--r--libpanto/src/provider.zig30
1 files changed, 30 insertions, 0 deletions
diff --git a/libpanto/src/provider.zig b/libpanto/src/provider.zig
index 16c3dd6..6d97bb7 100644
--- a/libpanto/src/provider.zig
+++ b/libpanto/src/provider.zig
@@ -1,5 +1,6 @@
const std = @import("std");
const conversation = @import("conversation.zig");
+const config_mod = @import("config.zig");
pub const ContentBlockType = enum {
Text,
@@ -73,6 +74,35 @@ pub const Provider = struct {
ptr: *anyopaque,
vtable: *const ProviderVTable,
+ /// Construct the concrete provider implementation that matches `cfg`'s
+ /// API style, heap-allocate it, and return a `Provider` interface bound
+ /// to it. `deinit` tears down the impl and frees the allocation.
+ ///
+ /// The concrete provider types (`OpenAIChatProvider`, etc.) are
+ /// implementation details; callers interact only with this interface.
+ pub fn init(
+ allocator: std.mem.Allocator,
+ io: std.Io,
+ cfg: config_mod.Config,
+ ) !Provider {
+ // Imported lazily to break the circular module graph:
+ // provider.zig <- provider_openai_chat.zig <- provider.zig.
+ const provider_openai_chat = @import("provider_openai_chat.zig");
+ const provider_anthropic_messages = @import("provider_anthropic_messages.zig");
+ switch (cfg) {
+ .openai_chat => |c| {
+ const impl = try allocator.create(provider_openai_chat.OpenAIChatProvider);
+ impl.* = provider_openai_chat.OpenAIChatProvider.init(allocator, io, c);
+ return impl.provider();
+ },
+ .anthropic_messages => |c| {
+ const impl = try allocator.create(provider_anthropic_messages.AnthropicMessagesProvider);
+ impl.* = provider_anthropic_messages.AnthropicMessagesProvider.init(allocator, io, c);
+ return impl.provider();
+ },
+ }
+ }
+
pub fn streamStep(self: Provider, conv: *conversation.Conversation, receiver: *Receiver) anyerror!void {
return self.vtable.streamStep(self.ptr, conv, receiver);
}