This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/texera.git
The following commit(s) were added to refs/heads/main by this push:
new b83963a916 refactor(frontend): extract agent payload and ReActStep
mapping helpers (#5995)
b83963a916 is described below
commit b83963a9161c645d9ee2520004c498bad5f61386
Author: Matthew B. <[email protected]>
AuthorDate: Sun Nov 15 05:45:51 2026 +0000
refactor(frontend): extract agent payload and ReActStep mapping helpers
(#5995)
### What changes were proposed in this PR?
- Added a private `mapApiAgentInfo(api)` helper in `AgentService` and
routed `createAgent`, `getAgent`, and `getAllAgents` through it,
removing three identical inline `ApiAgentInfo -> AgentInfo` mappings
(including the duplicated `delegate` sub-mapping).
- Added a private `convertApiReActSteps(steps)` helper and routed the
three `steps.map(s => convertApiReActStep(s))` sites through it.
- No behavior change: the produced `AgentInfo` and `ReActStep[]` values
are identical to before.
### Any related issues, documentation, discussions?
Closes: #5990
### How was this PR tested?
- Run `cd frontend && yarn test --include='**/agent.service.spec.ts'`,
expect the existing `AgentService` suite (including the `createAgent`
cases that flush an API payload and assert the mapped `AgentInfo`) to
pass.
- Typecheck with `cd frontend && npx tsc --noEmit -p tsconfig.json`,
expect no errors in `agent.service.ts` (the only error is a pre-existing
unrelated missing-module in `migration-llm.ts`).
### Was this PR authored or co-authored using generative AI tooling?
Co-authored with Claude Opus 4.8 in compliance with ASF
---------
Co-authored-by: Claude Opus 4.8 <[email protected]>
Co-authored-by: Jiadong Bai <[email protected]>
---
.../app/workspace/service/agent/agent.service.ts | 82 ++++++++--------------
1 file changed, 31 insertions(+), 51 deletions(-)
diff --git a/frontend/src/app/workspace/service/agent/agent.service.ts
b/frontend/src/app/workspace/service/agent/agent.service.ts
index 7e53227da3..4692d7beb7 100644
--- a/frontend/src/app/workspace/service/agent/agent.service.ts
+++ b/frontend/src/app/workspace/service/agent/agent.service.ts
@@ -373,6 +373,31 @@ export class AgentService {
};
}
+ // Helper to batch-convert an array of API ReActSteps to the frontend format.
+ private convertApiReActSteps(apiSteps: any[]): ReActStep[] {
+ return apiSteps.map(s => this.convertApiReActStep(s));
+ }
+
+ // Helper to map an API agent info payload to the frontend AgentInfo model.
+ private mapApiAgentInfo(api: ApiAgentInfo): AgentInfo {
+ return {
+ id: api.id,
+ name: api.name,
+ modelType: api.modelType,
+ isBaselineMode: false,
+ createdAt: new Date(api.createdAt),
+ state: this.mapStateToAgentState(api.state),
+ delegate: api.delegate
+ ? {
+ userInfo: api.delegate.userInfo,
+ workflowId: api.delegate.workflowId,
+ workflowName: api.delegate.workflowName,
+ }
+ : undefined,
+ settings: api.settings,
+ };
+ }
+
/**
* Get or create state tracking for an agent.
* If tracking exists but doesn't have workflowId and one is provided,
updates it.
@@ -481,7 +506,7 @@ export class AgentService {
tracking.stateSubject.next(this.mapStateToAgentState(message.state));
}
if (message.steps && Array.isArray(message.steps)) {
- const steps = message.steps.map((s: any) =>
this.convertApiReActStep(s));
+ const steps = this.convertApiReActSteps(message.steps);
tracking.reActStepsSubject.next(steps);
}
// Handle initial HEAD pointer
@@ -695,22 +720,7 @@ export class AgentService {
return this.http.post<ApiAgentInfo>(`${this.AGENT_API_BASE}/agents`,
body).pipe(
map(response => {
- const agentInfo: AgentInfo = {
- id: response.id,
- name: response.name,
- modelType: response.modelType,
- isBaselineMode: false,
- createdAt: new Date(response.createdAt),
- state: this.mapStateToAgentState(response.state),
- delegate: response.delegate
- ? {
- userInfo: response.delegate.userInfo,
- workflowId: response.delegate.workflowId,
- workflowName: response.delegate.workflowName,
- }
- : undefined,
- settings: response.settings,
- };
+ const agentInfo = this.mapApiAgentInfo(response);
this.agents.set(response.id, agentInfo);
// Pass workflowId to enable workflow polling from backend database
@@ -744,22 +754,7 @@ export class AgentService {
// Fetch from API if not in cache
return
this.http.get<ApiAgentInfo>(`${this.AGENT_API_BASE}/agents/${agentId}`,
this.agentHeaders(agentId)).pipe(
map(response => {
- const agentInfo: AgentInfo = {
- id: response.id,
- name: response.name,
- modelType: response.modelType,
- isBaselineMode: false,
- createdAt: new Date(response.createdAt),
- state: this.mapStateToAgentState(response.state),
- delegate: response.delegate
- ? {
- userInfo: response.delegate.userInfo,
- workflowId: response.delegate.workflowId,
- workflowName: response.delegate.workflowName,
- }
- : undefined,
- settings: response.settings,
- };
+ const agentInfo = this.mapApiAgentInfo(response);
this.agents.set(response.id, agentInfo);
return agentInfo;
}),
@@ -775,22 +770,7 @@ export class AgentService {
public getAllAgents(): Observable<AgentInfo[]> {
return
this.http.get<ApiAgentListResponse>(`${this.AGENT_API_BASE}/agents`).pipe(
map(response => {
- const agents = response.agents.map(a => ({
- id: a.id,
- name: a.name,
- modelType: a.modelType,
- isBaselineMode: false,
- createdAt: new Date(a.createdAt),
- state: this.mapStateToAgentState(a.state),
- delegate: a.delegate
- ? {
- userInfo: a.delegate.userInfo,
- workflowId: a.delegate.workflowId,
- workflowName: a.delegate.workflowName,
- }
- : undefined,
- settings: a.settings,
- }));
+ const agents = response.agents.map(a => this.mapApiAgentInfo(a));
// Build a set of backend agent IDs for quick lookup
const backendAgentIds = new Set(agents.map(a => a.id));
@@ -931,7 +911,7 @@ export class AgentService {
return this.http
.get<ApiReActStepsResponse>(`${this.AGENT_API_BASE}/agents/${agentId}/react-steps`,
this.agentHeaders(agentId))
.pipe(
- map(response => response.steps.map((s: any) =>
this.convertApiReActStep(s))),
+ map(response => this.convertApiReActSteps(response.steps)),
catchError(() => of([]))
);
}
@@ -1223,7 +1203,7 @@ export class AgentService {
}>(`${this.AGENT_API_BASE}/agents/${agentId}/steps-by-operators`, {
operatorIds }, this.agentHeaders(agentId))
.pipe(
map(response => ({
- steps: response.steps.map((s: any) => this.convertApiReActStep(s)),
+ steps: this.convertApiReActSteps(response.steps),
})),
catchError(() =>
of({