summaryrefslogtreecommitdiff
path: root/libpanto-lua/src/module.zig
diff options
context:
space:
mode:
authort <t@tjp.lol>2026-06-12 10:38:28 -0600
committert <t@tjp.lol>2026-06-12 11:06:18 -0600
commit7343898524f9f692620f4cb276f56cfde30f6269 (patch)
tree8cf0621d33c4ae7f292c95f4684e1e9590175ae8 /libpanto-lua/src/module.zig
parentaf8ba87475bfae9c1b4fa70c88fb4c59630a5670 (diff)
fuzzy selectors for models and reasoning levels
Diffstat (limited to 'libpanto-lua/src/module.zig')
-rw-r--r--libpanto-lua/src/module.zig16
1 files changed, 15 insertions, 1 deletions
diff --git a/libpanto-lua/src/module.zig b/libpanto-lua/src/module.zig
index f905765..8d07b42 100644
--- a/libpanto-lua/src/module.zig
+++ b/libpanto-lua/src/module.zig
@@ -356,9 +356,10 @@ fn registerMetatables(L: *c.lua_State) void {
c.lua_settop(L, c.lua_gettop(L) - 1);
if (c.luaL_newmetatable(L, STREAM_MT) != 0) {
- c.lua_createtable(L, 0, 2); // methods
+ c.lua_createtable(L, 0, 3); // methods
setMethod(L, "next", streamNext);
setMethod(L, "events", streamEvents);
+ setMethod(L, "reopen", streamReopen);
c.lua_setfield(L, -2, "__index");
setMethod(L, "__gc", streamGc);
}
@@ -1758,6 +1759,19 @@ fn streamIterStep(L_opt: ?*c.lua_State) callconv(.c) c_int {
return 1;
}
+/// `stream:reopen()`: reset a failed stream back to its turn-open boundary so
+/// the caller can resume `next()` after changing the agent config (e.g. catch
+/// a terminal error, swap the provider config via `agent:set_config(...)`, and
+/// retry the SAME turn without re-appending the user message). Errors if the
+/// stream has not failed (or is closed).
+fn streamReopen(L_opt: ?*c.lua_State) callconv(.c) c_int {
+ const L = L_opt.?;
+ const sbox = checkStream(L, 1);
+ if (sbox.closed) return luaErr(L, "panto: stream is closed");
+ sbox.stream.reopen() catch return luaErr(L, "panto: stream reopen failed");
+ return 0;
+}
+
fn streamGc(L_opt: ?*c.lua_State) callconv(.c) c_int {
const L = L_opt.?;
const sbox = checkStream(L, 1);