-
Notifications
You must be signed in to change notification settings - Fork 46
fix(sessions): show "Thinking…" on the group chip while the agent thinks #2961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
adboio
wants to merge
5
commits into
main
Choose a base branch
from
posthog-code/thinking-chip-label
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
67bb500
fix(sessions): show "Thinking…" on the group chip while the agent thinks
adboio 1232e9d
style: apply Biome formatting to buildThreadGroups test
adboio 86ed3c2
test: parameterise buildThreadGroups thinking-awareness cases
adboio bcaeb2e
fix(sessions): no empty box on expand; show thinking text inline
adboio c6c511b
Merge branch 'main' into posthog-code/thinking-chip-label
adboio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
152 changes: 152 additions & 0 deletions
152
packages/ui/src/features/sessions/components/new-thread/buildThreadGroups.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| import type { | ||
| ConversationItem, | ||
| TurnContext, | ||
| } from "@posthog/ui/features/sessions/components/buildConversationItems"; | ||
| import { | ||
| buildThreadGroups, | ||
| groupItemRendersContent, | ||
| } from "@posthog/ui/features/sessions/components/new-thread/buildThreadGroups"; | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| const activeContext: TurnContext = { | ||
| toolCalls: new Map(), | ||
| childItems: new Map(), | ||
| turnCancelled: false, | ||
| turnComplete: false, | ||
| }; | ||
|
|
||
| const completeContext: TurnContext = { | ||
| toolCalls: new Map(), | ||
| childItems: new Map(), | ||
| turnCancelled: false, | ||
| turnComplete: true, | ||
| }; | ||
|
|
||
| function thought( | ||
| id: string, | ||
| { | ||
| thoughtComplete, | ||
| text = "pondering", | ||
| }: { thoughtComplete?: boolean; text?: string }, | ||
| turnContext: TurnContext = activeContext, | ||
| ): ConversationItem { | ||
| return { | ||
| type: "session_update", | ||
| id, | ||
| turnContext, | ||
| thoughtComplete, | ||
| update: { | ||
| sessionUpdate: "agent_thought_chunk", | ||
| content: { type: "text", text }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| function toolItem( | ||
| id: string, | ||
| turnContext: TurnContext = activeContext, | ||
| ): ConversationItem { | ||
| return { | ||
| type: "session_update", | ||
| id, | ||
| turnContext, | ||
| update: { | ||
| sessionUpdate: "tool_call", | ||
| toolCallId: id, | ||
| kind: "read", | ||
| title: "Read file.ts", | ||
| status: turnContext.turnComplete ? "completed" : "in_progress", | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| /** The single tool_group row's summary, or a failed assertion. */ | ||
| function summaryOf(items: ConversationItem[]) { | ||
| const { rows } = buildThreadGroups(items, "all", {}); | ||
| const group = rows.find((r) => r.kind === "tool_group"); | ||
| if (group?.kind !== "tool_group") | ||
| throw new Error("expected a tool_group row"); | ||
| return group.summary; | ||
| } | ||
|
|
||
| describe("buildThreadGroups summary — thinking awareness", () => { | ||
| it.each([ | ||
| { | ||
| // A still-streaming thought is the only activity so far: the chip must say | ||
| // it's thinking, not fall back to the done label. | ||
| name: "reads a turn mid extended-thinking as live, not 'Worked'", | ||
| items: [thought("th1", { thoughtComplete: false })], | ||
| active: true, | ||
| liveLabel: "Thinking…", | ||
| hasCountableWork: false, | ||
| doneLabel: "Worked", | ||
| }, | ||
| { | ||
| // Thought, then an in-flight tool call: the tool is the latest activity, | ||
| // so its title wins over the thinking label. | ||
| name: "keeps the tool's live label when a tool runs after thinking", | ||
| items: [thought("th1", { thoughtComplete: true }), toolItem("t1")], | ||
| active: true, | ||
| liveLabel: "Read file.ts", | ||
| hasCountableWork: true, | ||
| doneLabel: "Read a file", | ||
| }, | ||
| { | ||
| // Tool finished, agent is thinking once more: countable work plus a live | ||
| // thinking label, so the chip can read "Read a file · Thinking…". | ||
| name: "shows thinking again when a thought trails completed tool work", | ||
| items: [toolItem("t1"), thought("th1", { thoughtComplete: false })], | ||
| active: true, | ||
| liveLabel: "Thinking…", | ||
| hasCountableWork: true, | ||
| doneLabel: "Read a file", | ||
| }, | ||
| { | ||
| // A finished turn whose only activity was thinking: no live label, falls | ||
| // back to the "Worked" done label (there is no countable tool work). | ||
| name: "does not treat a completed thought as live work", | ||
| items: [thought("th1", { thoughtComplete: true }, completeContext)], | ||
| active: false, | ||
| liveLabel: null, | ||
| hasCountableWork: false, | ||
| doneLabel: "Worked", | ||
| }, | ||
| ])("$name", ({ items, active, liveLabel, hasCountableWork, doneLabel }) => { | ||
| const summary = summaryOf(items); | ||
|
|
||
| expect(summary.active).toBe(active); | ||
| expect(summary.liveLabel).toBe(liveLabel); | ||
| expect(summary.hasCountableWork).toBe(hasCountableWork); | ||
| expect(summary.doneLabel).toBe(doneLabel); | ||
| }); | ||
| }); | ||
|
|
||
| describe("groupItemRendersContent", () => { | ||
| it.each([ | ||
| { | ||
| name: "a completed thought with text renders", | ||
| item: thought("th", { thoughtComplete: true, text: "reasoned" }), | ||
| expected: true, | ||
| }, | ||
| { | ||
| // The bug source: blank extended-thinking streams as a text-less thought | ||
| // chunk, which renders nothing once complete — so it must not keep the | ||
| // chip's bordered box alive. | ||
| name: "a completed blank thought renders nothing", | ||
| item: thought("th", { thoughtComplete: true, text: " " }), | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "a blank thought still streaming renders (its spinner)", | ||
| item: thought("th", { thoughtComplete: false, text: "" }), | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "a tool call renders", | ||
| item: toolItem("t1", completeContext), | ||
| expected: true, | ||
| }, | ||
| ])("$name", ({ item, expected }) => { | ||
| expect(groupItemRendersContent(item)).toBe(expected); | ||
| }); | ||
| }); | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The four cases share the same shape — a list of
ConversationItems in, a set ofGroupSummaryfields out — which is the canonical fit forit.each. With separateit()blocks, adding or adjusting a case also requires updating the surrounding boilerplate, and the inline comments duplicate what a table's column names would express. Consolidating into anit.eachtable (withactive,liveLabel,hasCountableWork, anddoneLabelas expectation columns) keeps every scenario OnceAndOnlyOnce and matches the repo's stated test convention.Context Used: Do not attempt to comment on incorrect alphabetica... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!