kunwp1 commented on code in PR #9604:
URL: https://github.com/apache/texera/pull/9604#discussion_r4661716600


##########
frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.html:
##########
@@ -131,8 +130,30 @@
         </ng-template>
         <ng-template nz-tab>
           <texera-agent-chat
+            *ngIf="canSwitchToAgent(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>

Review Comment:
   The plain `href` makes sense: `workspace.component.ts` reads 
`route.snapshot.params.id` only once, and this is the first link from one 
workspace to another. Two small notes:
   - After the reload, the panel opens on the "+ Agent" tab, so the user still 
has to click the agent's tab to see the chat.
   - A follow-up could have the workspace react to `paramMap` (or add a 
`RouteReuseStrategy`), so links like this one can be `routerLink`s.
   
   Neither is needed here.



##########
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);

Review Comment:
   The content-only `Workflow` comes from `agent.service.ts` (the 
`WsServerStepEvent` branch, around lines 555-561), where `{ 
...(existingWorkflow || {}), content }` is cast with `as Workflow`. Merging 
here works, since only the workspace has the full metadata. As a follow-up, 
typing that stream as `WorkflowContent` and building `{ ...open, content }` 
here would stop any other consumer from getting a `Workflow` with no id. Not 
blocking.



##########
frontend/src/app/workspace/component/agent/agent-panel/agent-panel.component.ts:
##########
@@ -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.canSwitchToAgent(agent)) {
+      this.deactivateCurrentAgent();
+      this.selectedTabIndex = index;
+      return;
     }

Review Comment:
   Every tab can be selected now, so `canSwitchToAgent` really means "the agent 
is on the open workflow". The new `*ngIf` and this branch both rely on it. 
Renaming it (e.g. to `isOnOpenWorkflow`) would read better. Optional.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to