This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-9604-cb1d61946ba1ad1102c68a57c89fdd1a3613a546 in repository https://gitbox.apache.org/repos/asf/texera.git
commit ba8558bc36facee2ed6d50185300f7afce31b330 Author: Jiadong Bai <[email protected]> AuthorDate: Tue Nov 24 21:39:09 2026 +0000 fix(frontend): link a locked agent tab to its workflow (#9604) ### What changes were proposed in this PR? Two ways an agent's chat could not be reopened: - **An agent on another workflow:** its tab was disabled behind a lock. It can now be selected, and shows the agent's workflow with a link to it in place of the chat. The agent stays inactive there, since an active agent loads its workflow into the canvas. The link is a plain one, as on the admin executions page: the workspace reads the workflow id only when it is created. - **Your own agent on this workflow:** a prompt sent right after its tab opened could arrive before the page fetched the workflow, carrying the content alone. The reload dropped the workflow's id and name, blanking the title and locking the tab. For an agent bound to the open workflow, the reload now keeps them. An agent bound to no workflow reloads as before. **An agent on another workflow.** On "Iris species report", the chat of an agent working on "Q4 sales by region". Before, its tab does not respond: <img width="1080" height="680" alt="Before: clicking the locked tab of an agent on another workflow does nothing" src="https://github.com/user-attachments/assets/20673e20-034c-4e6a-80de-00f2a3b488d5" /> After, it names that workflow and links to it, where the chat is: <img width="1080" height="680" alt="After: the tab names the agent's workflow, and its link opens that workflow with the chat" src="https://github.com/user-attachments/assets/833b007e-d46d-4d88-8126-46e505319627" /> **Your own agent on this workflow.** A prompt sent the moment the agent's tab opens. Before, the title and the workflow id disappear, and both tabs lock: <img width="1080" height="680" alt="Before: after a quick prompt the workflow title and id disappear and the agent tabs lock" src="https://github.com/user-attachments/assets/ea75e501-f4ca-4188-b272-acbc5c061024" /> After, they stay: <img width="1080" height="680" alt="After: after a quick prompt the workflow title and id stay and the tabs stay open" src="https://github.com/user-attachments/assets/871c6df9-c9c2-4d0b-a847-54eababa7019" /> ### Any related issues, documentation, discussions? Part of #9575: this fixes the chats that cannot be reopened, and #9579 fixes the model card that does not respond. ### How was this PR tested? New specs cover the selectable tab, the link and the kept workflow id; each fails without its change. Also run in headless Chromium against a local stack with a real model, alone and merged with #9579. The link opens the agent's workflow, where the chat answers, and a prompt sent at once keeps the title. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Fable 5.2, Claude Opus 5.5) --- .../agent-chat/agent-chat.component.spec.ts | 27 +++++++- .../agent-panel/agent-chat/agent-chat.component.ts | 10 ++- .../agent/agent-panel/agent-panel.component.html | 29 +++++++-- .../agent/agent-panel/agent-panel.component.scss | 18 +++++ .../agent-panel/agent-panel.component.spec.ts | 76 ++++++++++++++-------- .../agent/agent-panel/agent-panel.component.ts | 35 +++++----- 6 files changed, 142 insertions(+), 53 deletions(-) diff --git a/frontend/src/app/workspace/component/agent/agent-panel/agent-chat/agent-chat.component.spec.ts b/frontend/src/app/workspace/component/agent/agent-panel/agent-chat/agent-chat.component.spec.ts index e2f70a6dc3..4edc93d4a0 100644 --- a/frontend/src/app/workspace/component/agent/agent-panel/agent-chat/agent-chat.component.spec.ts +++ b/frontend/src/app/workspace/component/agent/agent-panel/agent-chat/agent-chat.component.spec.ts @@ -101,6 +101,10 @@ function makeStep(overrides: Partial<ReActStep> = {}): ReActStep { }; } +/** What the workspace knows about the workflow it has open, apart from its content. */ +const OPEN_WORKFLOW = { wid: 42, name: "wf" }; +const USER_INFO = { uid: 1, name: "user", email: "[email protected]", role: "REGULAR" }; + describe("AgentChatComponent", () => { let fixture: ComponentFixture<AgentChatComponent>; let component: AgentChatComponent; @@ -139,7 +143,7 @@ describe("AgentChatComponent", () => { // so the real service is required to render the system-info modal. NzModalService, { provide: AgentService, useValue: agentService }, - { provide: WorkflowActionService, useValue: { reloadWorkflow } }, + { provide: WorkflowActionService, useValue: { reloadWorkflow, getWorkflowMetadata: () => OPEN_WORKFLOW } }, { provide: NotificationService, useValue: notification }, { provide: WorkflowPersistService, useValue: persist }, ...commonTestProviders, @@ -341,6 +345,27 @@ describe("AgentChatComponent", () => { } as unknown as Workflow); expect(reloadWorkflow).toHaveBeenCalledTimes(2); }); + + it("keeps the open workflow's id and name when the content of an agent bound to it arrives alone", () => { + // A step can reach the page before the workflow itself has been fetched, and then all there + // is to put on the stream is the content. Reloading that as it came wiped the workspace's + // workflow id and name, and the agent's own tab locked as "a different workflow". + createComponent(makeAgentInfo({ delegate: { userInfo: USER_INFO, workflowId: OPEN_WORKFLOW.wid } }), true); + const content = { operators: [{ operatorID: "op-9" }] }; + + agentService.workflowSubject.next({ content } as unknown as Workflow); + + expect(reloadWorkflow).toHaveBeenCalledWith({ ...OPEN_WORKFLOW, content }, false, false); + }); + + it("reloads the content of an agent bound to no workflow as it came, so it is not saved over the open one", () => { + createComponent(makeAgentInfo(), true); + const workflow = { content: { operators: [{ operatorID: "op-9" }] } } as unknown as Workflow; + + agentService.workflowSubject.next(workflow); + + expect(reloadWorkflow).toHaveBeenCalledWith(workflow, false, false); + }); }); describe("sendMessage / onEnterPress", () => { diff --git a/frontend/src/app/workspace/component/agent/agent-panel/agent-chat/agent-chat.component.ts b/frontend/src/app/workspace/component/agent/agent-panel/agent-chat/agent-chat.component.ts index 867e21aa7e..b04f75b626 100644 --- a/frontend/src/app/workspace/component/agent/agent-panel/agent-chat/agent-chat.component.ts +++ b/frontend/src/app/workspace/component/agent/agent-panel/agent-chat/agent-chat.component.ts @@ -284,7 +284,15 @@ export class AgentChatComponent implements OnInit, AfterViewChecked, OnDestroy, ) .subscribe(workflow => { if (workflow) { - this.workflowActionService.reloadWorkflow(workflow, false, false); + // A step that reaches the page before the agent's workflow has been fetched carries the + // content alone. Reloaded as it came, it made the workspace forget which workflow it had + // open: the title went blank and this agent's own tab locked as on another workflow. An + // agent bound to the open workflow works on it, so that workflow's id and name stand in. + // An agent bound to none keeps what it sent, so its content is not saved over this one. + const open = this.workflowActionService.getWorkflowMetadata(); + const boundWid = this.agentInfo.delegate?.workflowId; + const isBoundToOpen = !!boundWid && boundWid === open.wid; + this.workflowActionService.reloadWorkflow(isBoundToOpen ? { ...open, ...workflow } : workflow, false, false); } }); } diff --git a/frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.html b/frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.html index a2154d8e96..671500a407 100644 --- a/frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.html +++ b/frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.html @@ -97,17 +97,16 @@ <nz-tab *ngFor="let agent of agents; let i = index" [nzTitle]="agentTabTitle" - [nzForceRender]="true" - [nzDisabled]="!canSwitchToAgent(agent)"> + [nzForceRender]="true"> <ng-template #agentTabTitle let-active="active"> <div class="agent-tab-title" - [class.workflow-mismatch]="!canSwitchToAgent(agent)"> + [class.workflow-mismatch]="isOnAnotherWorkflow(agent)"> <span class="agent-tab-name">{{ agent.name }}</span> <i - *ngIf="!canSwitchToAgent(agent)" + *ngIf="isOnAnotherWorkflow(agent)" nz-icon nzType="lock" nzTheme="outline" @@ -131,8 +130,30 @@ </ng-template> <ng-template nz-tab> <texera-agent-chat + *ngIf="!isOnAnotherWorkflow(agent); else onAnotherWorkflow" [agentInfo]="agent" [isActive]="activeAgentId === agent.id"></texera-agent-chat> + <!-- An agent that works on another workflow has no chat here: chatting with it would + load its workflow into this canvas. Its tab says where the chat is instead. Only + such an agent reaches this template, so its delegate is set. The link is a plain + one, so that the browser loads the page: the workspace reads the workflow's id + from its address only when it is created, and the router would keep the same + workspace for another workflow's address. --> + <ng-template #onAnotherWorkflow> + <div + *ngIf="agent.delegate!.workflowId as workflowId" + class="other-workflow-notice"> + <p> + This agent is working on a different workflow: {{ agent.delegate!.workflowName || "#" + workflowId }}. + </p> + <a + nz-button + nzType="primary" + [href]="workspaceCanvasUrl(workflowId)"> + Open that workflow + </a> + </div> + </ng-template> </ng-template> </nz-tab> </nz-tabs> diff --git a/frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.scss b/frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.scss index 80c3ec719d..fd1d24d3d7 100644 --- a/frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.scss +++ b/frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.scss @@ -136,6 +136,24 @@ } } +// Shown in place of the chat of an agent that works on another workflow. +.other-workflow-notice { + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 16px; + padding: 20px; + text-align: center; + font-size: 14px; + color: #595959; + + p { + margin: 0; + } +} + .agent-tab-close { padding: 0 !important; width: 20px !important; diff --git a/frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.spec.ts b/frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.spec.ts index c732e899a6..38d4660412 100644 --- a/frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.spec.ts +++ b/frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.spec.ts @@ -125,7 +125,6 @@ describe("AgentPanelComponent", () => { providers: [ { provide: AgentService, useValue: agentService }, { provide: WorkflowActionService, useValue: workflowAction }, - { provide: NotificationService, useValue: notification }, ...commonTestProviders, ], }).compileComponents(); @@ -395,18 +394,18 @@ describe("AgentPanelComponent", () => { expect(component.selectedTabIndex).toBe(2); }); - it("blocks switching to an agent bound to a different workflow and warns", () => { - agentService.agentList = [makeDelegateAgent("foreign", 99)]; + it("selects the tab of an agent bound to a different workflow without activating it", () => { + agentService.agentList = [makeAgent("local"), makeDelegateAgent("foreign", 99)]; createComponent(); + component.onTabSelectChange(1); // "local" active - component.onTabSelectChange(1); + component.onTabSelectChange(2); - expect(notification.warning).toHaveBeenCalledTimes(1); - const message = notification.warning.mock.calls[0][0] as string; - expect(message).toContain('Cannot switch to agent "Agent foreign"'); - expect(message).toContain("Open workflow #99"); - expect(agentService.activateAgent).not.toHaveBeenCalled(); - expect(component.selectedTabIndex).toBe(0); + // An active agent loads its workflow into the canvas, here over the open one. + expect(agentService.activateAgent).not.toHaveBeenCalledWith("foreign"); + expect(agentService.deactivateAgent).toHaveBeenCalledWith("local"); + expect(component.activeAgentId).toBeNull(); + expect(component.selectedTabIndex).toBe(2); }); it("allows switching when the agent's workflow matches the current one", () => { @@ -415,7 +414,6 @@ describe("AgentPanelComponent", () => { component.onTabSelectChange(1); - expect(notification.warning).not.toHaveBeenCalled(); expect(agentService.activateAgent).toHaveBeenCalledWith("bound"); expect(component.selectedTabIndex).toBe(1); }); @@ -459,14 +457,14 @@ describe("AgentPanelComponent", () => { }); }); - describe("canSwitchToAgent", () => { - it("permits agents with no delegate, no workflow id, or a matching workflow id", () => { + describe("isOnAnotherWorkflow", () => { + it("is true only for an agent bound to a workflow other than the open one", () => { createComponent(); - expect(component.canSwitchToAgent(makeAgent("plain"))).toBe(true); - expect(component.canSwitchToAgent(makeDelegateAgent("no-wid", undefined))).toBe(true); - expect(component.canSwitchToAgent(makeDelegateAgent("zero", 0))).toBe(true); - expect(component.canSwitchToAgent(makeDelegateAgent("same", CURRENT_WID))).toBe(true); - expect(component.canSwitchToAgent(makeDelegateAgent("other", 99))).toBe(false); + expect(component.isOnAnotherWorkflow(makeAgent("plain"))).toBe(false); + expect(component.isOnAnotherWorkflow(makeDelegateAgent("no-wid", undefined))).toBe(false); + expect(component.isOnAnotherWorkflow(makeDelegateAgent("zero", 0))).toBe(false); + expect(component.isOnAnotherWorkflow(makeDelegateAgent("same", CURRENT_WID))).toBe(false); + expect(component.isOnAnotherWorkflow(makeDelegateAgent("other", 99))).toBe(true); }); it("renders a lock icon and mismatch style only on agents from another workflow", () => { @@ -478,6 +476,28 @@ describe("AgentPanelComponent", () => { expect(titles[0].classList.contains("workflow-mismatch")).toBe(false); expect(titles[1].classList.contains("workflow-mismatch")).toBe(true); }); + + it("gives an agent from another workflow a link to that workflow in place of a chat", () => { + agentService.agentList = [ + makeAgent("local"), + makeAgent("named", { delegate: { userInfo: USER_INFO, workflowId: 99, workflowName: "Orders" } }), + makeDelegateAgent("unnamed", 7), + ]; + createComponent(); + + const chats = fixture.debugElement.queryAll(By.directive(StubAgentChatComponent)); + expect(chats.map(chat => chat.componentInstance.agentInfo.id)).toEqual(["local"]); + + const notices = Array.from(fixture.nativeElement.querySelectorAll(".other-workflow-notice")) as HTMLElement[]; + expect(notices.map(notice => notice.querySelector("p")?.textContent?.trim())).toEqual([ + "This agent is working on a different workflow: Orders.", + "This agent is working on a different workflow: #7.", + ]); + expect(notices.map(notice => notice.querySelector("a")?.getAttribute("href"))).toEqual([ + "/user/workflow/99", + "/user/workflow/7", + ]); + }); }); describe("deleteAgent", () => { @@ -831,21 +851,23 @@ describe("AgentPanelComponent", () => { expect(chats().map(c => c.isActive)).toEqual([false, true]); }); - it("disables the tab of an agent bound to another workflow so a click cannot select it", () => { + it("clicking the tab of an agent bound to another workflow shows the link to it, not a chat", async () => { service.agentList = [makeAgent("local"), makeDelegateAgent("foreign", 99)]; createComponent(); - const headers = tabHeaders(); - expect(headers[1].classList.contains("ant-tabs-tab-disabled")).toBe(false); - expect(headers[2].classList.contains("ant-tabs-tab-disabled")).toBe(true); - - (headers[2].querySelector(".ant-tabs-tab-btn") as HTMLElement).click(); + (tabHeaders()[2].querySelector(".ant-tabs-tab-btn") as HTMLElement).click(); + fixture.detectChanges(); + await settle(); fixture.detectChanges(); - // Disabled by the template, so onTabSelectChange never runs and never warns. - expect(notification.warning).not.toHaveBeenCalled(); + expect(component.selectedTabIndex).toBe(2); + const selectedPane = fixture.nativeElement.querySelector(".ant-tabs-tabpane-active") as HTMLElement; + expect(selectedPane.querySelector("a")?.getAttribute("href")).toBe("/user/workflow/99"); + expect(selectedPane.querySelector("texera-agent-chat")).toBeNull(); + // The agent stays inactive, and the only chat is that of the agent on this workflow. expect(service.activateAgent).not.toHaveBeenCalled(); - expect(chats().map(c => c.isActive)).toEqual([false, false]); + expect(chats().map(c => c.agentInfo.id)).toEqual(["local"]); + expect(chats().map(c => c.isActive)).toEqual([false]); }); it("the close button on a tab header deletes that agent without selecting its tab", () => { diff --git a/frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.ts b/frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.ts index 3a5e165017..5e09b2dafd 100644 --- a/frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.ts +++ b/frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.ts @@ -22,7 +22,7 @@ import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy"; import { NzResizeEvent, NzResizableDirective, NzResizeHandlesComponent } from "ng-zorro-antd/resizable"; import { AgentService, AgentInfo } from "../../../service/agent/agent.service"; import { WorkflowActionService } from "../../../service/workflow-graph/model/workflow-action.service"; -import { NotificationService } from "../../../../common/service/notification/notification.service"; +import { workspaceCanvasUrl } from "../../../../app-routing.constant"; import { NgIf, NgFor } from "@angular/common"; import { NzSpaceCompactItemDirective } from "ng-zorro-antd/space"; import { NzButtonComponent } from "ng-zorro-antd/button"; @@ -66,6 +66,7 @@ import { AgentChatComponent } from "./agent-chat/agent-chat.component"; }) export class AgentPanelComponent implements OnInit, OnDestroy, OnChanges { protected readonly window = window; + protected readonly workspaceCanvasUrl = workspaceCanvasUrl; private static readonly MIN_PANEL_WIDTH = 400; private static readonly MIN_PANEL_HEIGHT = 450; @@ -91,8 +92,7 @@ export class AgentPanelComponent implements OnInit, OnDestroy, OnChanges { constructor( private agentService: AgentService, - private workflowActionService: WorkflowActionService, - private notificationService: NotificationService + private workflowActionService: WorkflowActionService ) {} ngOnInit(): void { @@ -210,7 +210,7 @@ export class AgentPanelComponent implements OnInit, OnDestroy, OnChanges { } /** - * Handle tab selection change - validates workflow compatibility before switching + * Handle tab selection change - activates the tab's agent only on the workflow it works on */ public onTabSelectChange(index: number): void { // Tab 0 is registration - always allow @@ -227,19 +227,13 @@ export class AgentPanelComponent implements OnInit, OnDestroy, OnChanges { } const agent = this.agents[agentIndex]; - const agentWorkflowId = agent.delegate?.workflowId; - const currentWorkflowId = this.workflowActionService.getWorkflowMetadata().wid; - // If agent has a workflow ID, check if it matches the current workflow - if (agentWorkflowId !== undefined && agentWorkflowId !== 0) { - if (currentWorkflowId !== agentWorkflowId) { - // Block switching - workflow mismatch - this.notificationService.warning( - `Cannot switch to agent "${agent.name}": It's working on a different workflow. ` + - `Open workflow #${agentWorkflowId} to interact with this agent.` - ); - return; - } + // An agent that works on another workflow is shown, not activated: its tab holds a link to + // that workflow in place of the chat, and an active agent loads its workflow into the canvas. + if (this.isOnAnotherWorkflow(agent)) { + this.deactivateCurrentAgent(); + this.selectedTabIndex = index; + return; } // Workflow matches or agent has no workflow - allow switch @@ -277,15 +271,16 @@ export class AgentPanelComponent implements OnInit, OnDestroy, OnChanges { } /** - * Check if an agent's workflow matches the current workspace workflow + * Whether the agent works on a workflow other than the open one. Its tab then shows a link to + * that workflow in place of the chat; an agent on the open workflow, or on none, chats here. */ - public canSwitchToAgent(agent: AgentInfo): boolean { + public isOnAnotherWorkflow(agent: AgentInfo): boolean { const agentWorkflowId = agent.delegate?.workflowId; if (agentWorkflowId === undefined || agentWorkflowId === 0) { - return true; // Agent has no workflow - always allow + return false; // Agent has no workflow } const currentWorkflowId = this.workflowActionService.getWorkflowMetadata().wid; - return currentWorkflowId === agentWorkflowId; + return currentWorkflowId !== agentWorkflowId; } /**
