feat(conversation): enhance events and stream integrity#401
Open
feat(conversation): enhance events and stream integrity#401
Conversation
c8f47b5 to
4386773
Compare
This commit introduces a structured turn model and robust stream sanitization to `jp_conversation`. A new `TurnStart` event kind is used to group sequences of events within a single query invocation, enabling better navigation and filtering of conversation history. The `EventBuilder` is added to handle the accumulation of partial LLM stream chunks into complete `ConversationEvent` objects, supporting interleaved reasoning, message, and structured output parts. To improve privacy and prevent sensitive data from leaking into workspace search results, a storage-level encoding layer has been implemented. Tool arguments, results, and metadata are now base64-encoded when persisted to disk, while remaining transparent to the rest of the application. Additionally, the `ConversationStream` now includes a `sanitize` process to repair structural invariants that may be violated after filtering or interrupted tool executions. This includes injecting synthetic error responses for orphaned tool calls and re-indexing turn markers. The `Thread` model has also been updated to replace the concept of "instructions" with "sections", providing a more flexible way to render context before sending it to providers. Signed-off-by: Jean Mertz <git@jeanmertz.com>
4386773 to
2dd28b8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce
TurnStartevents to mark turn boundaries, providing clear grouping for sequences of events originating from a single query. This improves the structural representation of multi-turn conversations.Extend the chat model to support structured outputs.
ChatRequestnow includes an optional JSON schema, andChatResponsegains aStructuredvariant for carrying parsed JSON data.Introduce
EventBuilderto aggregate streamed event chunks from LLM providers into completeConversationEvents. It handles index-based buffering for reasoning, messages, tool calls, and structured data, ensuring multi-part responses are correctly merged.Implement
ConversationStream::sanitizeand associated utilities to maintain stream integrity. These tools repair structural invariants broken by filtering or interruptions, such as orphaned tool call responses or missing turn markers.Refactor
Threadto replaceinstructionswithsections, aligning the model with the rendering logic for modular prompt construction. Inquiry events are also refined withInquiryIdandSelectOptionto provide better context for interactive prompts.