Repository navigation
Dart: show an incognito session - #2200
VelikovPetar wants to merge 12 commits into
Conversation
xsahil03x
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
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.
|
|
||
| ### 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. |
There was a problem hiding this comment.
nit: AGENTS.md asks for PR numbers inline, as the Swift entry below does; this one could end with (#2200).
| 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)}, | ||
| }, |
There was a problem hiding this comment.
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,.
There was a problem hiding this comment.
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.
| List<AgentMessage> get listMessages => _kept | ||
| ? listed(_channel?.state?.messages ?? const [], reasoning, shown: _shown) | ||
| : [ | ||
| for (final message in session.turnMessages) | ||
| AgentMessage.unkept(message), | ||
| ]; |
There was a problem hiding this comment.
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),
];There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
nit: this and ToolCallStep.status (conversation.dart:274) are the only public fields without a doc next to documented neighbours.
| 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; |
There was a problem hiding this comment.
Done in 486e766, with your wording on TurnMessage.text and "Whether it is running, or how it ended." on ToolCallStep.status.
|
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 |
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>
486e766 to
190ebf1
Compare
…-da8afb # Conflicts: # examples/voice_agents/flutter_demo/lib/chat_view.dart
# Conflicts: # .claude/skills/sdk-dart/SKILL.md
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'sConversationdroppedreasoning_deltaandtool_updatedas unknown and ignoredtool_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
Core stays free of Stream: a step is the
({String type, Map payload})record thatAIMessagePart.parseAlltakes, so a kept reply and an incognito one render alike.Changes
AgentEventKind.reasoningDeltaconversation_teststeps groupTurn.steps,Turn.isDone,TurnStep(ReasoningStep,ToolCallStep,ToolCallStepStatus) folded inConversation.applytool_startedshown once_resumedAtprompt_injectionclears the reply in flightTurnMessage.messages/session.turnMessagesturn_message_testapprovalson its stepawaiting_approval,target_user_id= the agents' usersession_test"waits on its step of the reply, for the agents' user…" (fails withsession.userId)flutter_demo:AgentChat.unkept,AgentMessage.unkept, lock toggle in the Chat app barAIConversationfrom the socketagent_chat_test"shows a session with no channel from its socket…"Structure, mirrored from Swift #2091 and Kotlin #2114
Conversation.swiftConversation.applyConversation.ktreducerconversation.dartConversation.apply, same case orderTurnStep+ nestedReasoning/ToolCall/StatusTurnStep.Reasoning/.ToolCall/.StatusTurnStep, top-levelReasoningStep/ToolCallStep/ToolCallStepStatus(no nested types; named apart from tool groups'ToolCallStatus)think/settle/call/changeCallthink/settled/called/changedCall_think/_settled/_called/_changedCallamend(startingAt:),refuseReplyInFlightamend,resumed,ended,refused_amend,_resumed,_ended,_refusedTurnMessage.swiftmessages(of:), private init,StepTurnMessage.ktmessages/of/approval,Stepturn_message.dartmessages/_of/_approval, private constructor, step recordsession.turnMessages(property)turnMessages(Flow)turnMessages(getter, as Swift)swift_assistantAgentChatandroid_assistantAgentTransportflutter_demoAgentChat.unkeptDifferences kept on purpose:
target_user_idisbackend.userIdas in Kotlin, notSession.userIdas 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 anAIToolApprover. Kotlin'scutset andendsTurnon an LLM error come from other main work that other Dart changes cover; the router answers a failed reply withresponded, 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).
ToolCallStatus(#2088); merged tree failed to analyzeToolCallStepStatustool_rannever applied: the router sendsresponded(pending_work)before its tools run (agent.go:3510-3519)reasoningDeltabreaks an exhaustive switch.claude/skills/sdk/SKILL.mdand doubled a CHANGELOG headingTurnMessageconstructorstreamingafter a disconnect; same tool id across turnstarget_user_iddiffers from SwiftValidation
sdks/dart/stream_agents:dart format,flutter analyze,tool/generate.dart --checkclean;flutter test307 passed, 16 skipped (live).flutter_demo: format and analyze clean, 43 passed.flutter_assistant: analyze clean, 132 passed.xai/grok-4.7xai/grok-4.7conversation_id""agent:<session id>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=falser1streaming, then completed 903 ms, 77 chars keptr1streaming, then completed 1114 mslookup_ordercompleted 4 ms,issue_refundcompleted 36 msawaiting_approval,target_user_id= the agents' user (notvision-agent), allowed, then running, then completedresponded, then notThe same run on
anthropic/claude-haiku-5-5showed tool calls, approval and done but no thinking (the model sent none). Not checked:flutter_demoon a simulator or device, and voice mode in an incognito chat.🤖 Generated with Claude Code