diff options
Diffstat (limited to 'libpanto/src/turn_persist.zig')
| -rw-r--r-- | libpanto/src/turn_persist.zig | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/libpanto/src/turn_persist.zig b/libpanto/src/turn_persist.zig index 0147fbd..1dacfec 100644 --- a/libpanto/src/turn_persist.zig +++ b/libpanto/src/turn_persist.zig @@ -41,7 +41,7 @@ const Session = session_store.Session; pub fn persistTurn( alloc: Allocator, session: *Session, - conv: *const conversation.Conversation, + conv: *conversation.Conversation, start_index: usize, identity: WireIdentity, tools: []const ToolDecl, @@ -52,14 +52,22 @@ pub fn persistTurn( const all_messages = conv.messages.items; var i = start_index; while (i < all_messages.len) : (i += 1) { - const msg = all_messages[i]; + const msg = &all_messages[i]; if (msg.role == .assistant and hasToolUseWithoutFollowingResults(conv, i)) { continue; } + // Stamp the producing identity once, on first persist. A message that + // already carries one (e.g. a kept-verbatim turn carried through + // compaction, or one rebuilt from disk) keeps it — only the messages + // freshly produced under `identity` are stamped now. This is what + // makes the stamp survive a later compaction onto a different model. + if (msg.identity == null) { + msg.identity = try conversation.dupeWireIdentity(alloc, identity); + } try batch.append(alloc, .{ - .message = msg, + .message = msg.*, .usage = msg.usage, - .identity = identity, + .identity = msg.identity.?, .conversation = all_messages, .tools_available = tools, }); @@ -75,7 +83,7 @@ pub fn persistTurn( pub fn persistCompaction( alloc: Allocator, session: *Session, - conv: *const conversation.Conversation, + conv: *conversation.Conversation, identity: WireIdentity, tools: []const ToolDecl, ) !void { |
