Skip to content

Commit 4bf78b4

Browse files
websocket agent glow service added (#159)
1 parent 5a0bc02 commit 4bf78b4

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/lib/agent/TeachWebSocketAgent.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ExecutionMetadata } from "@/lib/types/messaging";
66
import { TeachModeEventPayload } from "@/lib/pubsub/types";
77
import { Logging } from "@/lib/utils/Logging";
88
import { type SemanticWorkflow } from "@/lib/teach-mode/types";
9+
import { GlowAnimationService } from '@/lib/services/GlowAnimationService';
910

1011
interface PredefinedPlan {
1112
agentId: string;
@@ -22,6 +23,7 @@ interface PredefinedPlan {
2223
export class TeachWebSocketAgent {
2324
private readonly executionContext: ExecutionContext;
2425
private readonly mainPubsub: PubSubChannel; // Main channel for teach-mode events
26+
private readonly glowService: GlowAnimationService;
2527

2628
// WebSocket state
2729
private ws: WebSocket | null = null;
@@ -33,6 +35,7 @@ export class TeachWebSocketAgent {
3335
constructor(executionContext: ExecutionContext) {
3436
this.executionContext = executionContext;
3537
this.mainPubsub = PubSub.getChannel('main'); // Get main channel for teach-mode events
38+
this.glowService = GlowAnimationService.getInstance();
3639
Logging.log("TeachWebSocketAgent", "Agent instance created", "info");
3740
}
3841

@@ -173,6 +176,16 @@ ${JSON.stringify(userTrajectorySteps, null, 2)}`;
173176
totalSteps: workflow?.steps?.length || 0
174177
});
175178

179+
// Start glow animation
180+
try {
181+
const currentPage = await this.executionContext.browserContext.getCurrentPage();
182+
if (currentPage?.tabId && !this.glowService.isGlowActive(currentPage.tabId)) {
183+
await this.glowService.startGlow(currentPage.tabId);
184+
}
185+
} catch (error) {
186+
Logging.log("TeachWebSocketAgent", `Could not start glow animation: ${error}`, "warning");
187+
}
188+
176189
// Connect to WebSocket server
177190
await this._connect();
178191

@@ -196,6 +209,16 @@ ${JSON.stringify(userTrajectorySteps, null, 2)}`;
196209
endTime: Date.now(),
197210
});
198211
this._logMetrics();
212+
213+
// Stop glow animation
214+
try {
215+
const activeGlows = this.glowService.getAllActiveGlows();
216+
for (const tabId of activeGlows) {
217+
await this.glowService.stopGlow(tabId);
218+
}
219+
} catch (error) {
220+
Logging.log("TeachWebSocketAgent", `Could not stop glow animation: ${error}`, "warning");
221+
}
199222
}
200223
}
201224

src/lib/agent/WebSocketAgent.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { PubSub } from "@/lib/pubsub";
33
import { AbortError } from "@/lib/utils/Abortable";
44
import { ExecutionMetadata } from "@/lib/types/messaging";
55
import { Logging } from "@/lib/utils/Logging";
6+
import { GlowAnimationService } from '@/lib/services/GlowAnimationService';
67

78

89
interface PredefinedPlan {
@@ -19,6 +20,7 @@ interface PredefinedPlan {
1920
*/
2021
export class WebSocketAgent {
2122
private readonly executionContext: ExecutionContext;
23+
private readonly glowService: GlowAnimationService;
2224

2325
// WebSocket state
2426
private ws: WebSocket | null = null;
@@ -29,6 +31,7 @@ export class WebSocketAgent {
2931

3032
constructor(executionContext: ExecutionContext) {
3133
this.executionContext = executionContext;
34+
this.glowService = GlowAnimationService.getInstance();
3235
Logging.log("WebSocketAgent", "Agent instance created", "info");
3336
}
3437

@@ -119,6 +122,16 @@ export class WebSocketAgent {
119122

120123
Logging.log("WebSocketAgent", "Starting execution", "info");
121124

125+
// Start glow animation
126+
try {
127+
const currentPage = await this.executionContext.browserContext.getCurrentPage();
128+
if (currentPage?.tabId && !this.glowService.isGlowActive(currentPage.tabId)) {
129+
await this.glowService.startGlow(currentPage.tabId);
130+
}
131+
} catch (error) {
132+
Logging.log("WebSocketAgent", `Could not start glow animation: ${error}`, "warning");
133+
}
134+
122135
// Connect to WebSocket server
123136
await this._connect();
124137

@@ -141,6 +154,16 @@ export class WebSocketAgent {
141154
endTime: Date.now(),
142155
});
143156
this._logMetrics();
157+
158+
// Stop glow animation
159+
try {
160+
const activeGlows = this.glowService.getAllActiveGlows();
161+
for (const tabId of activeGlows) {
162+
await this.glowService.stopGlow(tabId);
163+
}
164+
} catch (error) {
165+
Logging.log("WebSocketAgent", `Could not stop glow animation: ${error}`, "warning");
166+
}
144167
}
145168
}
146169

0 commit comments

Comments
 (0)