(msg *FrontendMessage)
| 345 | } |
| 346 | |
| 347 | func (a *App) handleChat(msg *FrontendMessage) (*BackendResponse, error) { |
| 348 | var payload ChatPayload |
| 349 | if err := json.Unmarshal(msg.Payload, &payload); err != nil { |
| 350 | return &BackendResponse{ |
| 351 | ID: msg.ID, |
| 352 | Success: false, |
| 353 | Error: fmt.Sprintf("invalid payload: %v", err), |
| 354 | }, nil |
| 355 | } |
| 356 | |
| 357 | ag, ok := a.GetAgent(msg.AgentID) |
| 358 | if !ok { |
| 359 | return &BackendResponse{ |
| 360 | ID: msg.ID, |
| 361 | Success: false, |
| 362 | Error: "agent not found: " + msg.AgentID, |
| 363 | }, nil |
| 364 | } |
| 365 | |
| 366 | // Subscribe to events and forward to frontend |
| 367 | go a.forwardAgentEvents(ag, msg.AgentID) |
| 368 | |
| 369 | // Send message to agent (non-blocking, events will be sent via bridge) |
| 370 | go func() { |
| 371 | ctx := context.Background() |
| 372 | err := ag.Send(ctx, payload.Message) |
| 373 | if err != nil { |
| 374 | _ = a.bridge.SendEvent(&FrontendEvent{ |
| 375 | Type: EventTypeError, |
| 376 | AgentID: msg.AgentID, |
| 377 | Data: map[string]string{"error": err.Error()}, |
| 378 | }) |
| 379 | } |
| 380 | // Note: Done event will be sent when agent finishes processing |
| 381 | }() |
| 382 | |
| 383 | return &BackendResponse{ |
| 384 | ID: msg.ID, |
| 385 | Success: true, |
| 386 | Data: map[string]string{"status": "started"}, |
| 387 | }, nil |
| 388 | } |
| 389 | |
| 390 | func (a *App) handleCancel(msg *FrontendMessage) (*BackendResponse, error) { |
| 391 | ag, ok := a.GetAgent(msg.AgentID) |
no test coverage detected