| 766 | } |
| 767 | |
| 768 | func (c *turnWorkspaceContext) ensureWorkspaceAgent( |
| 769 | ctx context.Context, |
| 770 | ) (database.Chat, database.WorkspaceAgent, error) { |
| 771 | c.mu.Lock() |
| 772 | defer c.mu.Unlock() |
| 773 | |
| 774 | if c.agentLoaded { |
| 775 | chatSnapshot := c.currentChatSnapshot() |
| 776 | if nullUUIDEqual(c.cachedWorkspaceID, chatSnapshot.WorkspaceID) { |
| 777 | return chatSnapshot, c.agent, nil |
| 778 | } |
| 779 | c.agent = database.WorkspaceAgent{} |
| 780 | c.agentLoaded = false |
| 781 | } |
| 782 | |
| 783 | return c.loadWorkspaceAgentLocked(ctx) |
| 784 | } |
| 785 | |
| 786 | func (c *turnWorkspaceContext) loadWorkspaceAgentLocked( |
| 787 | ctx context.Context, |