Skip to content

Dart: show an incognito session - #2200

Open
VelikovPetar wants to merge 12 commits into
mainfrom
claude/dart-incognito-da8afb
Open

VelikovPetar wants to merge 12 commits into
mainfrom
claude/dart-incognito-da8afb

Conversation

@VelikovPetar

@VelikovPetar VelikovPetar commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Why

An incognito session has no Stream Chat channel, so session.chat() throws and a Flutter app had nothing to show its replies with. Dart's Conversation dropped reasoning_delta and tool_updated as unknown and ignored tool_started/tool_ran, so a reply was bare text. JavaScript (#2090), Swift (#2091) and Kotlin (#2114) already fold the socket's steps; this brings Dart in line.

How it works

session socket                       Conversation (immutable value)
--------------                       ------------------------------
responding / response_delta  ---->   Turn.text, _resumedAt
reasoning_delta              ---->   Turn.steps  ReasoningStep r1, r2...
tool_started / tool_updated  ---->   Turn.steps  ToolCallStep running, summary
tool_ran                     ---->   completed / failed, duration
responded / interrupted      ---->   Turn.isDone (unless pending_work)
error prompt_injection       ---->   reply in flight loses text and UI
                                            |
session.approvals, backend.userId           v
                             ---->   session.turnMessages: List<TurnMessage>
                                     one reply per question, steps as
                                     (type:, payload:) records
                                            |
                                            v
              flutter_demo AgentChat.unkept -> AIMessagePart.parseAll
                                     -> AIConversation (stream_chat_flutter_ai)

Core stays free of Stream: a step is the ({String type, Map payload}) record that AIMessagePart.parseAll takes, so a kept reply and an incognito one render alike.

Changes

Change Result Test that proves it
AgentEventKind.reasoningDelta The frame is named, not dropped conversation_test steps group
Turn.steps, Turn.isDone, TurnStep (ReasoningStep, ToolCallStep, ToolCallStepStatus) folded in Conversation.apply Thinking and tool calls in order, failed call marked, non-verbatim update as summary, repeated tool_started shown once "a written reply keeps its thinking and tool calls in the order they happened", "a call shows once…"
Round of thinking timed from _resumedAt "Thought for 4.25 s", not 0.25 s, for a model that thinks in one burst "times a round of thinking from when the model was asked…" (fails without it)
prompt_injection clears the reply in flight Refused text and UI go, steps stay; a done reply is left alone "a reply the prompt injection screen refused…" (fails without it)
TurnMessage.messages / session.turnMessages One reply across its tools' turns, rounds numbered across it, whole thinking by step turn_message_test
A call in approvals on its step awaiting_approval, target_user_id = the agents' user session_test "waits on its step of the reply, for the agents' user…" (fails with session.userId)
flutter_demo: AgentChat.unkept, AgentMessage.unkept, lock toggle in the Chat app bar Incognito chat rendered by AIConversation from the socket agent_chat_test "shows a session with no channel from its socket…"

Structure, mirrored from Swift #2091 and Kotlin #2114

Swift Kotlin Dart
Conversation.swift Conversation.apply Conversation.kt reducer conversation.dart Conversation.apply, same case order
TurnStep + nested Reasoning / ToolCall / Status TurnStep.Reasoning / .ToolCall / .Status sealed TurnStep, top-level ReasoningStep / ToolCallStep / ToolCallStepStatus (no nested types; named apart from tool groups' ToolCallStatus)
think / settle / call / changeCall think / settled / called / changedCall _think / _settled / _called / _changedCall
amend(startingAt:), refuseReplyInFlight amend, resumed, ended, refused _amend, _resumed, _ended, _refused
TurnMessage.swift messages(of:), private init, Step TurnMessage.kt messages / of / approval, Step turn_message.dart messages / _of / _approval, private constructor, step record
session.turnMessages (property) turnMessages (Flow) turnMessages (getter, as Swift)
swift_assistant AgentChat android_assistant AgentTransport flutter_demo AgentChat.unkept

Differences kept on purpose: target_user_id is backend.userId as in Kotlin, not Session.userId as in Swift and JavaScript; the spec (openapi.yaml, Session.user_id) calls that "the name the agent joined the call as", so Swift's and JavaScript's approval cards likely never match an AIToolApprover. Kotlin's cut set and endsTurn on an LLM error come from other main work that other Dart changes cover; the router answers a failed reply with responded, so the turn is done here anyway.

Review findings and outcomes

Three independent reviews (full change, then only what each fix or the rebase changed).

Finding Outcome
Step status enum collided with main's new ToolCallStatus (#2088); merged tree failed to analyze Fixed: ToolCallStepStatus
Timing a round from tool_ran never applied: the router sends responded(pending_work) before its tools run (agent.go:3510-3519) Removed; timing matches Swift and Kotlin; tests replay the router's frame order
Docs and CHANGELOG missing; reasoningDelta breaks an exhaustive switch Added (sdk and sdk-dart skills, README, both CHANGELOGs)
Rebase mis-merged .claude/skills/sdk/SKILL.md and doubled a CHANGELOG heading Fixed
Public TurnMessage constructor Made private, as Swift's
A scheduled reply right after a finished one joins it; a step stays streaming after a disconnect; same tool id across turns Left as is: Swift, Kotlin and JavaScript do the same; a change belongs to all of them
target_user_id differs from Swift Dart follows Kotlin and the spec; no other SDK changed here

Validation

  • sdks/dart/stream_agents: dart format, flutter analyze, tool/generate.dart --check clean; flutter test 307 passed, 16 skipped (live).
  • flutter_demo: format and analyze clean, 43 passed. flutter_assistant: analyze clean, 132 passed.
  • Each regression test above was checked to fail without its fix.
  • Live, on a local router from origin/main 876681a (no agent config, tools declared by the test, the tool that refunds asks first):
Incognito, xai/grok-4.7 Kept, xai/grok-4.7
conversation_id "" agent:<session id>
Frames responding, responded pending_work=true, tool_started/tool_ran lookup_order, responding, reasoning_delta, responded pending_work=true, tool_started issue_refund, tool_ran, responding, responded pending_work=false same
Reply one message across 3 turns one message across 3 turns
Thinking r1 streaming, then completed 903 ms, 77 chars kept r1 streaming, then completed 1114 ms
Tool calls lookup_order completed 4 ms, issue_refund completed 36 ms completed 8 ms / 125 ms
Approval awaiting_approval, target_user_id = the agents' user (not vision-agent), allowed, then running, then completed same
Done generating until the last responded, then not same

The same run on anthropic/claude-haiku-5-5 showed tool calls, approval and done but no thinking (the model sent none). Not checked: flutter_demo on a simulator or device, and voice mode in an incognito chat.

🤖 Generated with Claude Code

@VelikovPetar
VelikovPetar marked this pull request as ready for review November 23, 2026 13:06
@VelikovPetar
VelikovPetar requested a review from a team November 23, 2026 13:06

@xsahil03x xsahil03x left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Petar, this lines up well: the frames fold as Kotlin's reducer does, case for case, and TurnMessage matches Swift's field for field. The step records are exactly what stream_chat_flutter_ai reads as AIMessagePartAttachment, statuses and approval keys included. Format, analyze and the tests (309 + 43) are clean. One note to fix in the skill file; the rest is nits and optional, inline.

Tests, nit: a few check several behaviours each (in conversation_test.dart "a turn is done once it answered with nothing left to come, or was cut off" and "progress for a call or a turn never seen changes nothing; thinking starts the turn"; in turn_message_test.dart "only the latest reply is being written, and only while the socket carries it"; in session_test.dart "waits on its step…"); splitting them would keep a failure pointing at one thing.

Connections in JavaScript (AI-3378, AI-3387): `api.connections` has `create(connectorId, { label, userId })`, `authorize(id, { returnUrl, userId })`, `get(id, { userId })`, `list({ connectorId, userId })` (every page, 200 a page, newest first) and `delete(id, { userId })`. The user is an optional parameter of each call, never a client of its own: given, it is sent as `owner.user_id` (create) and `X-Stream-User-Id` on every call, reads included, with the app's server credential (an internal `speakingFor(backend, userId)` in `backend.ts`, kept off `Backend`'s type, which Dispatch's `answer` also uses); left out or empty, the call is the app's (`owner.type: app`, `owner_type=app`, no header added). Optional parts are one options object, never adjacent positional strings. `Backend.actingFor` stays public and working, marked `@deprecated` (Chat's "deprecate, never break"), and a test pins its requests to the base commit's. A client built with `BackendOptions.userId` still sends that user on a call without `userId`, as on every other call; one built on the deprecated `actingFor` does not (the call is the app's). A `userId` on a client that is not server side (a device, or a page on a customer-id router) is a `ConfigurationError` before any request. Other SDKs need to update: Python, .NET, Ruby, Rust and PHP (AI-3379..AI-3383).
Connections in Python (AI-3379, no spec change): `plugins/stream` has `api.connections` with the Go shape: `create(connector_id, *, label=None, user_id=None)`, `authorize(id, *, return_url=None, user_id=None)` returning `Authorization`, `get(id, *, user_id=None)`, `list(*, connector_id=None, user_id=None)` reading every page, `delete(id, *, user_id=None)`; every option is keyword-only, so a user id cannot land in the label's or connector's slot. A user given is `owner.user_id` (create) and `X-Stream-User-Id` on every call, replacing whoever the client acts for and the user its backend was built for (which behind the proxy would sign that user's own token); none is the app's connection, sent as the client is otherwise (a client built for a user still names that user). AI-3387 in Python: `Client.for_user` is deprecated (`DeprecationWarning`, still working) in favour of a keyword-only `user_id=None`, last, on `Client.agent` and `Client.router`, on a client built with `team=`/`usage_categories=`; a device naming a user is refused before any request. Dispatch and `Accelerated` keep `Backend.acting_for` internally.
The session socket sends `reasoning_delta` (`turn_id`, `text`): the next piece of the model's thinking on a written reply, which a kept conversation also streams into the reply's Chat message and an incognito one has nowhere else to show. JavaScript folds it, with `tool_started`, `tool_updated` (not `verbatim`) and `tool_ran`, into each agent turn's `steps` in `sdks/js/src/conversation.ts`: a round of thinking `r1`, `r2`... opens on a delta after anything else and completes when the turn writes text or UI, calls a tool, answers or is cut off; a call runs until `tool_ran`, failed when it carries an `error`, its summary the last non-verbatim update. A turn is `done` on `responded` with no `pending_work`, or `interrupted`. `AgentChat` shows a session with no `conversationId` from these turns (`sdks/js/src/turn-messages.ts`): the agent's turns between two of the person's messages are one reply, shaped as the channel's messages (top level in stream-chat 9, under `custom` in 10) with `ai_reasoning` and `ai_tool_call` steps, rounds numbered across the reply, its whole thinking given to `reasoning`, and a call waiting in `approvals` shown `awaiting_approval` with its question and the session's `user_id` as `target_user_id`. The clients that carry the socket's description (JavaScript types, Python `plugins/stream`) are regenerated. Swift does the same: `Conversation` folds the frames into `Turn.steps` and `Turn.isDone`, and `TurnMessage.messages(of:approvals:userID:isConnected:)` (`session.turnMessages`) builds the replies, each step an attachment type and JSON payload for `AIMessagePart.parts(from:)`, the session's user now `Session.userID`; `swift_assistant`'s `AgentChat` shows an incognito session from them. Kotlin does the same: `Conversation` folds the frames into `Turn.steps` (`TurnStep.Reasoning`, `TurnStep.ToolCall`) and `Turn.isDone`, and `TurnMessage.messages(conversation, approvals, userId, isConnected)` (`AgentSession.turnMessages`, a `Flow`) builds the replies, each step an attachment type and plain-Kotlin fields for `AIMessagePart.parts`; its `target_user_id` is the user `setUser` named (`backend.user`), not the session's `user_id`, which is the name the agent joined the call as; `android_assistant`'s `AgentTransport` shows an incognito session from them. Other SDKs need to update: Dart, whose AI components read the same steps, should fold the same frames into their `Conversation` turns and show a session with no channel through their transports; the server SDKs need nothing.
The session socket sends `reasoning_delta` (`turn_id`, `text`): the next piece of the model's thinking on a written reply, which a kept conversation also streams into the reply's Chat message and an incognito one has nowhere else to show. JavaScript folds it, with `tool_started`, `tool_updated` (not `verbatim`) and `tool_ran`, into each agent turn's `steps` in `sdks/js/src/conversation.ts`: a round of thinking `r1`, `r2`... opens on a delta after anything else and completes when the turn writes text or UI, calls a tool, answers or is cut off; a call runs until `tool_ran`, failed when it carries an `error`, its summary the last non-verbatim update. A turn is `done` on `responded` with no `pending_work`, or `interrupted`. `AgentChat` shows a session with no `conversationId` from these turns (`sdks/js/src/turn-messages.ts`): the agent's turns between two of the person's messages are one reply, shaped as the channel's messages (top level in stream-chat 9, under `custom` in 10) with `ai_reasoning` and `ai_tool_call` steps, rounds numbered across the reply, its whole thinking given to `reasoning`, and a call waiting in `approvals` shown `awaiting_approval` with its question and the session's `user_id` as `target_user_id`. The clients that carry the socket's description (JavaScript types, Python `plugins/stream`) are regenerated. Swift does the same: `Conversation` folds the frames into `Turn.steps` and `Turn.isDone`, and `TurnMessage.messages(of:approvals:userID:isConnected:)` (`session.turnMessages`) builds the replies, each step an attachment type and JSON payload for `AIMessagePart.parts(from:)`, the session's user now `Session.userID`; `swift_assistant`'s `AgentChat` shows an incognito session from them. Kotlin does the same: `Conversation` folds the frames into `Turn.steps` (`TurnStep.Reasoning`, `TurnStep.ToolCall`) and `Turn.isDone`, and `TurnMessage.messages(conversation, approvals, userId, isConnected)` (`AgentSession.turnMessages`, a `Flow`) builds the replies, each step an attachment type and plain-Kotlin fields for `AIMessagePart.parts`; its `target_user_id` is the user `setUser` named (`backend.user`), not the session's `user_id`, which is the name the agent joined the call as; `android_assistant`'s `AgentTransport` shows an incognito session from them. Dart does the same (`Turn.steps`, `Turn.isDone`, `session.turnMessages`, each step the record `AIMessagePart.parseAll` takes), its `target_user_id` the agents' own user as in Kotlin; `flutter_demo`'s `AgentChat` shows an incognito session from them. The server SDKs need nothing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR's own evidence shows Swift and JavaScript send the wrong target_user_id: Session.user_id is "the name the agent joined the call as. It is not the owner of the session" (openapi.yaml), while a kept reply's step uses the conversation's owner (parts.go:208, Initiator: c.data.Owner). AGENTS.md asks for a note when other SDKs need to update, but this one ends "The server SDKs need nothing". Something like: "Other SDKs need to update: Swift and JavaScript should send the person's user (the one the app signed in as) as target_user_id, as Kotlin and Dart do, not Session.userId. The server SDKs need nothing."

@VelikovPetar VelikovPetar Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Since #2207, a note that other SDKs still need something goes in its own file, not the skill, so this one is now .claude/skills/sdk/notes/2026-11-23-target-user-id.md (190ebf1), with your wording: Swift and JavaScript should send the person's user as target_user_id, as Kotlin and Dart do, not Session.userId. The skill's reasoning_delta paragraph now says Dart does the same, in place of the sentence that said Dart still needed to update.

Comment thread CHANGELOG.md Outdated

### The Dart SDK shows an incognito session

An incognito session has no Stream Chat channel, so a Flutter app had nothing to show its replies with. `Turn` now has `steps` (rounds of thinking and tool calls) and `isDone`, from the socket, and `session.turnMessages` is the conversation in the shape Stream's AI components read, a waiting call's approval card included. `AgentEventKind` gains `reasoningDelta`, so an exhaustive `switch` over it needs the case. `flutter_demo` has an incognito toggle.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: AGENTS.md asks for PR numbers inline, as the Swift entry below does; this one could end with (#2200).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 486e766: the Dart entry ends with (#2200).

Comment on lines +105 to +112
payload: {
'id': step.id,
'name': step.name,
'status': waiting != null ? 'awaiting_approval' : step.status.wire,
if (step.summary.isNotEmpty) 'summary': step.summary,
'duration_ms': ?step.duration?.inMilliseconds,
if (waiting != null) ...{'target_user_id': userId, 'approval': _approval(waiting)},
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional, and the same in every SDK: the ai_tool_call payload has no display_title. A kept reply's step carries one (parts.go:204), and AIToolCallPart falls back to the tool name with underscores as spaces without it, so an incognito reply shows "issue refund" where a kept one shows the tool's title. AgentSession already has toolCallsForTurn with ToolCallState.displayTitle, so turnMessages could pass a call-id-to-title map in and emit if (displayTitles[step.id] case final title? when title.isNotEmpty) 'display_title': title,.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipping here for SDK parity: Swift (TurnMessage.swift), Kotlin (TurnMessage.kt) and JavaScript (turn-messages.ts) don't put display_title on the ai_tool_call step either, and adding it to Dart alone would break the mirror. All four have it available from the socket's tool_call.* state (ToolCallState.displayTitle), so it can be added to every SDK together later.

Comment on lines +88 to +93
List<AgentMessage> get listMessages => _kept
? listed(_channel?.state?.messages ?? const [], reasoning, shown: _shown)
: [
for (final message in session.turnMessages)
AgentMessage.unkept(message),
];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the kept path drops a reply with nothing written (isUnwrittenReply), but this one doesn't, so a reply that failed or was refused shows as an empty bubble in incognito. Something like:

: [
    for (final message in session.turnMessages)
      if (!message.isAgentReply || message.isGenerating || message.text.isNotEmpty || message.steps.isNotEmpty)
        AgentMessage.unkept(message),
  ];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 486e766. The incognito path now leaves out an agent reply that is not generating and has no text and no steps (UnkeptReply.isUnwrittenReply, the same rule as AgentReply.isUnwrittenReply for a kept one). A failed or refused reply was already hidden by AIConversation, because its error marks it stopped. What still showed as an empty bubble was a reply that ended empty with no error, such as a model answering with nothing. The new test "leaves out a reply with no channel that ended with nothing written" covers that case, and it fails without the fix.


/// Whether the agent wrote it, rather than the person.
final bool isAgentReply;
final String text;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this and ToolCallStep.status (conversation.dart:274) are the only public fields without a doc next to documented neighbours.

Suggested change
final String text;
/// What it says: the person's question, or the reply's text, its turns' text joined by a blank line.
final String text;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 486e766, with your wording on TurnMessage.text and "Whether it is running, or how it ended." on ToolCallStep.status.

@VelikovPetar

Copy link
Copy Markdown
Contributor Author

On the tests note: split in 486e766, one behaviour each. "a turn is done once…" is now three tests and "progress for a call or a turn never seen…" two, in conversation_test.dart. "only the latest reply is being written…" is four in turn_message_test.dart. "waits on its step…" is three in session_test.dart, which share a waitingUnkept() setup like the file's open().

VelikovPetar and others added 9 commits November 23, 2026 19:08
Conversation folds reasoning_delta, tool_started, tool_updated and tool_ran
into Turn.steps and Turn.isDone; TurnMessage builds the channel's message
shape from them; flutter_demo shows an incognito chat from the socket.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…reducer, docs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tatus; time thinking as Swift and Kotlin do

The router answers a reply as waiting before its tools run, so resuming on
tool_ran never applied. Tests now play frames in the router's order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the router's frame order

TurnMessage compares its steps by value rather than by encoding them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… docs

Steps copy as Kotlin's data classes do; flutter_demo maps turnMessages
straight to messages, as swift_assistant and android_assistant do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The flutter_demo's incognito path leaves out a reply that ended with no
text and no steps, as the kept path does. The sdk skill notes that Swift
and JavaScript should send the person's user as target_user_id. Docs on
TurnMessage.text and ToolCallStep.status, the PR number in the
CHANGELOG, and the multi-behaviour tests split one behaviour each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Swift and JavaScript target_user_id note moves to
.claude/skills/sdk/notes/2026-11-23-target-user-id.md. The sdk skill's
reasoning_delta paragraph no longer says Dart still needs to update. The
root CHANGELOG keeps one Breaking Changes line for AgentEventKind's new
value; the package CHANGELOG is left as main has it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@VelikovPetar
VelikovPetar force-pushed the claude/dart-incognito-da8afb branch from 486e766 to 190ebf1 Compare November 23, 2026 18:10
…-da8afb

# Conflicts:
#	examples/voice_agents/flutter_demo/lib/chat_view.dart
# Conflicts:
#	.claude/skills/sdk-dart/SKILL.md

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants