Skip to content

feat(conversation): enhance events and stream integrity#401

Open
JeanMertz wants to merge 1 commit intomainfrom
pr/2-conversation-events
Open

feat(conversation): enhance events and stream integrity#401
JeanMertz wants to merge 1 commit intomainfrom
pr/2-conversation-events

Conversation

@JeanMertz
Copy link
Collaborator

Introduce TurnStart events 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. ChatRequest now includes an optional JSON schema, and ChatResponse gains a Structured variant for carrying parsed JSON data.

Introduce EventBuilder to aggregate streamed event chunks from LLM providers into complete ConversationEvents. It handles index-based buffering for reasoning, messages, tool calls, and structured data, ensuring multi-part responses are correctly merged.

Implement ConversationStream::sanitize and 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 Thread to replace instructions with sections, aligning the model with the rendering logic for modular prompt construction. Inquiry events are also refined with InquiryId and SelectOption to provide better context for interactive prompts.

@JeanMertz JeanMertz force-pushed the pr/2-conversation-events branch 3 times, most recently from c8f47b5 to 4386773 Compare February 25, 2026 00:36
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>
@JeanMertz JeanMertz force-pushed the pr/2-conversation-events branch from 4386773 to 2dd28b8 Compare February 25, 2026 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant