Repository navigation
fix(agent): show a blank chat when switching to a tab with no chat #23313
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
Changes from all commits
ce3b7f1
dc78c85
7b80c73
6cbab48
2bdb70a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,8 +56,14 @@ type FollowDeps = { | |
| ) => Promise<boolean> | boolean | ||
| adoptWorkflowTarget: (workflow: ComfyWorkflow, workflowId: string) => void | ||
| adoptRestoredWorkflowTab: (workflowId: string) => void | ||
| startBlankChat: () => void | ||
| } | ||
|
|
||
| type WorkflowIdLookup = | ||
| | { status: 'found'; workflowId: string } | ||
| | { status: 'unlisted' } | ||
| | { status: 'failed' } | ||
|
|
||
| function requestedState( | ||
| state: FollowState, | ||
| event: Extract<FollowEvent, { type: 'requested' }> | ||
|
|
@@ -133,7 +139,7 @@ export function useAgentWorkflowChatFollow(deps: FollowDeps) { | |
| const target = deps.selectedTarget() | ||
| const chatTargetsWorkflow = | ||
| !deps.followsVisibleWorkflow() && target?.path === workflow.path | ||
| return workflow.isTemporary || deps.userEngaged() || chatTargetsWorkflow | ||
| return deps.userEngaged() || chatTargetsWorkflow | ||
| } | ||
|
|
||
| function latestChatFor(workflowId: string): string | undefined { | ||
|
|
@@ -179,13 +185,21 @@ export function useAgentWorkflowChatFollow(deps: FollowDeps) { | |
| deps.trackThreadStarted() | ||
| } | ||
|
|
||
| async function resolveWorkflowId( | ||
| async function lookUpWorkflowId( | ||
| workflow: ComfyWorkflow | ||
| ): Promise<string | undefined> { | ||
| ): Promise<WorkflowIdLookup> { | ||
| const existing = deps.cloudIdFor(workflow) | ||
| if (existing !== undefined) return existing | ||
| await deps.refreshCloudWorkflowIds() | ||
| return deps.cloudIdFor(workflow) | ||
| if (existing !== undefined) return { status: 'found', workflowId: existing } | ||
| const listed = await deps.refreshCloudWorkflowIds() | ||
| const workflowId = deps.cloudIdFor(workflow) | ||
| if (workflowId !== undefined) return { status: 'found', workflowId } | ||
| return { status: listed ? 'unlisted' : 'failed' } | ||
| } | ||
|
|
||
| function showBlankChat(operation: FollowOperation): void { | ||
| if (!isCurrent(operation)) return | ||
| if (deps.currentThreadId() === null && deps.followsVisibleWorkflow()) return | ||
| deps.startBlankChat() | ||
| } | ||
|
|
||
| async function refreshForFollow( | ||
|
|
@@ -207,26 +221,55 @@ export function useAgentWorkflowChatFollow(deps: FollowDeps) { | |
|
|
||
| async function openLatestChat( | ||
| workflowId: string, | ||
| operation: FollowOperation | ||
| operation: FollowOperation, | ||
| blankWhenNoChat: boolean | ||
| ): Promise<void> { | ||
| const latest = latestChatFor(workflowId) | ||
| if (latest !== undefined && latest !== deps.currentThreadId()) | ||
| if (latest === undefined) { | ||
| if (blankWhenNoChat) showBlankChat(operation) | ||
| } else if (latest !== deps.currentThreadId()) | ||
| await openFollowedChat(latest, operation, workflowId) | ||
| } | ||
|
|
||
| async function followTab(workflow: ComfyWorkflow): Promise<void> { | ||
| function followTemporaryTab( | ||
| workflow: ComfyWorkflow, | ||
| operation: FollowOperation, | ||
| blankWhenNoChat: boolean | ||
| ): void { | ||
| const boundToCloudWorkflow = deps.cloudIdFor(workflow) !== undefined | ||
| if (blankWhenNoChat && !boundToCloudWorkflow) showBlankChat(operation) | ||
| } | ||
|
|
||
| async function followSavedTab( | ||
| workflow: ComfyWorkflow, | ||
| operation: FollowOperation, | ||
| blankWhenNoChat: boolean | ||
| ): Promise<void> { | ||
| const lookup = await lookUpWorkflowId(workflow) | ||
| if (lookup.status === 'failed' || !isCurrent(operation)) return | ||
| if (lookup.status === 'unlisted') { | ||
| if (blankWhenNoChat) showBlankChat(operation) | ||
| return | ||
| } | ||
| if ( | ||
| !(await refreshForFollow(lookup.workflowId, operation)) || | ||
| !isCurrent(operation) | ||
| ) | ||
| return | ||
| await openLatestChat(lookup.workflowId, operation, blankWhenNoChat) | ||
| } | ||
|
|
||
| async function followTab( | ||
| workflow: ComfyWorkflow, | ||
| { blankWhenNoChat = true } = {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve The panel’s initial follow passes If the retry finds no chat, it resets the existing chat instead of preserving the mount-time restore path. Retain the option in the operation and failed state, then pass it through retries.
|
||
| ): Promise<void> { | ||
| dispatch({ type: 'requested', workflow, heldBack: heldBack(workflow) }) | ||
| const operation = state.value | ||
| if (operation.status !== 'loading') return | ||
| try { | ||
| const workflowId = await resolveWorkflowId(workflow) | ||
| if (workflowId === undefined || !isCurrent(operation)) return | ||
| if ( | ||
| !(await refreshForFollow(workflowId, operation)) || | ||
| !isCurrent(operation) | ||
| ) | ||
| return | ||
| await openLatestChat(workflowId, operation) | ||
| if (workflow.isTemporary) | ||
| followTemporaryTab(workflow, operation, blankWhenNoChat) | ||
| else await followSavedTab(workflow, operation, blankWhenNoChat) | ||
| } finally { | ||
| dispatch({ type: 'finished', generation: operation.generation }) | ||
| } | ||
|
|
||
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.
Make the previous and newly created workflows distinct.
The protected behavior is activation of the workflow created by
loadBlankWorkflow. This test captures the active workflow before execution and does not arrange a replacement during loading. An implementation that reports the previous workflow could therefore pass.Configure the load double to install a distinct workflow before resolving. Assert that
reportUserActivationreceives that workflow.As per coding guidelines: “Choose rows that distinguish correct and incorrect outcomes.”
Source: Coding guidelines