Skip to content

Commit 85a52fa

Browse files
committed
refactor: remove fallback for dashboard
1 parent c1704f6 commit 85a52fa

1 file changed

Lines changed: 5 additions & 107 deletions

File tree

src/app/shell/dashboard/dashboard.ts

Lines changed: 5 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { A2uiRendererService } from '@a2ui/angular/v0_9';
2-
import type { A2uiMessage } from '@a2ui/web_core/v0_9';
32
import {
43
ChangeDetectionStrategy,
54
Component,
65
computed,
76
DestroyRef,
8-
effect,
97
inject,
108
signal,
119
} from '@angular/core';
@@ -25,11 +23,6 @@ import { dashboardFlightSearchAction } from './actions/dashboard-flight-search-a
2523
import { examplePrompts } from './example-prompts';
2624
import { submitFlightSearchTool } from './tools/submit-flight-search.tool';
2725

28-
interface ParsedA2uiSurface {
29-
surfaceId: string;
30-
messages: A2uiMessage[];
31-
}
32-
3326
@Component({
3427
selector: 'app-dashboard',
3528
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -53,10 +46,8 @@ export class Dashboard {
5346
forwardedProps: () => ({ preventCaching: this.preventCaching() }),
5447
});
5548

56-
private readonly synthesizedWidgets = signal<Record<string, AgUiWidget>>({});
57-
5849
protected readonly widgets = computed<AgUiWidget[]>(() =>
59-
collectWidgets(this.chat.value(), this.synthesizedWidgets()),
50+
collectWidgets(this.chat.value()),
6051
);
6152

6253
protected readonly hasOutput = computed(() =>
@@ -83,10 +74,6 @@ export class Dashboard {
8374
dashboardFlightSearch: (action) => dashboardFlightSearchAction(action),
8475
});
8576

86-
effect(() => {
87-
this.absorbA2uiTextFallback(this.chat.value());
88-
});
89-
9077
this.destroyRef.onDestroy(() => {
9178
this.chat.dispose();
9279
});
@@ -99,7 +86,6 @@ export class Dashboard {
9986
}
10087
this.clearRenderedSurfaces();
10188
this.chat.reset();
102-
this.synthesizedWidgets.set({});
10389
this.showToolDetails.set(false);
10490
this.chat.sendMessage({ role: 'user', content });
10591
}
@@ -116,7 +102,6 @@ export class Dashboard {
116102
protected reset(): void {
117103
this.clearRenderedSurfaces();
118104
this.chat.reset();
119-
this.synthesizedWidgets.set({});
120105
this.showToolDetails.set(false);
121106
this.message.set('');
122107
}
@@ -137,58 +122,12 @@ export class Dashboard {
137122
this.renderer.surfaceGroup.deleteSurface(id);
138123
}
139124
}
140-
141-
private absorbA2uiTextFallback(messages: AgUiChatMessage[]): void {
142-
const current = this.synthesizedWidgets();
143-
let next: Record<string, AgUiWidget> | null = null;
144-
145-
for (const message of messages) {
146-
if (message.role !== 'assistant') {
147-
continue;
148-
}
149-
if (message.widgets.length > 0) {
150-
continue;
151-
}
152-
if (current[message.id]) {
153-
continue;
154-
}
155-
const surface = tryParseA2uiSurface(message.content);
156-
if (!surface) {
157-
continue;
158-
}
159-
160-
this.renderer.processMessages(surface.messages);
161-
if (!this.renderer.surfaceGroup.getSurface(surface.surfaceId)) {
162-
continue;
163-
}
164-
165-
next ??= { ...current };
166-
next[message.id] = {
167-
name: `a2ui_${message.id}`,
168-
a2uiSurfaceId: surface.surfaceId,
169-
};
170-
}
171-
172-
if (next) {
173-
this.synthesizedWidgets.set(next);
174-
}
175-
}
176125
}
177126

178-
function collectWidgets(
179-
messages: AgUiChatMessage[],
180-
synthesized: Record<string, AgUiWidget>,
181-
): AgUiWidget[] {
182-
return messages.flatMap((message) => {
183-
if (message.role !== 'assistant') {
184-
return [];
185-
}
186-
if (message.widgets.length > 0) {
187-
return message.widgets;
188-
}
189-
const fallback = synthesized[message.id];
190-
return fallback ? [fallback] : [];
191-
});
127+
function collectWidgets(messages: AgUiChatMessage[]): AgUiWidget[] {
128+
return messages.flatMap((message) =>
129+
message.role === 'assistant' ? message.widgets : [],
130+
);
192131
}
193132

194133
function hasOutput(
@@ -235,44 +174,3 @@ function formatToolArgs(args: unknown): string {
235174
return String(args);
236175
}
237176
}
238-
239-
function tryParseA2uiSurface(content: string): ParsedA2uiSurface | null {
240-
if (!content || !content.includes('"messages"')) {
241-
return null;
242-
}
243-
244-
let parsed: unknown;
245-
try {
246-
parsed = JSON.parse(content);
247-
} catch {
248-
return null;
249-
}
250-
251-
if (
252-
!parsed ||
253-
typeof parsed !== 'object' ||
254-
!('messages' in parsed) ||
255-
!Array.isArray((parsed as { messages?: unknown }).messages)
256-
) {
257-
return null;
258-
}
259-
260-
const list = (parsed as { messages: A2uiMessage[] }).messages;
261-
let surfaceId: string | null = null;
262-
for (const op of list) {
263-
if (op && typeof op === 'object' && 'createSurface' in op) {
264-
const value = (op as { createSurface?: { surfaceId?: string } })
265-
.createSurface;
266-
if (value?.surfaceId) {
267-
surfaceId = value.surfaceId;
268-
break;
269-
}
270-
}
271-
}
272-
273-
if (!surfaceId) {
274-
return null;
275-
}
276-
277-
return { surfaceId, messages: list };
278-
}

0 commit comments

Comments
 (0)