( ctx context.Context, chatSnapshot database.Chat, agent database.WorkspaceAgent, )
| 1033 | } |
| 1034 | |
| 1035 | func (c *turnWorkspaceContext) externalAgentPreflightError( |
| 1036 | ctx context.Context, |
| 1037 | chatSnapshot database.Chat, |
| 1038 | agent database.WorkspaceAgent, |
| 1039 | ) error { |
| 1040 | // Mirror the cache-hit gate: only short-circuit on clearly offline |
| 1041 | // states (Disconnected/Timeout). Connecting is allowed through so |
| 1042 | // an external agent the user just started can still connect inside |
| 1043 | // the normal dial window. |
| 1044 | if !isAgentUnreachable(c.server.clock.Now(), agent, c.server.agentInactiveDisconnectTimeout) { |
| 1045 | return nil |
| 1046 | } |
| 1047 | |
| 1048 | isExternal, err := chattool.IsExternalWorkspaceAgent(ctx, c.server.db, agent) |
| 1049 | if err != nil || !isExternal || !chatSnapshot.WorkspaceID.Valid { |
| 1050 | return nil |
| 1051 | } |
| 1052 | |
| 1053 | // Stale agent bindings rely on dialWithLazyValidation to discover |
| 1054 | // replacement agents, so only skip the dial when this agent is still |
| 1055 | // the latest selected chat agent for the workspace. |
| 1056 | latestAgentID, err := c.latestWorkspaceAgentID(ctx, chatSnapshot.WorkspaceID.UUID) |
| 1057 | if err != nil || latestAgentID != agent.ID { |
| 1058 | return nil |
| 1059 | } |
| 1060 | return newChatExternalAgentUnavailableError(agent) |
| 1061 | } |
| 1062 | |
| 1063 | func (c *turnWorkspaceContext) getWorkspaceConn(ctx context.Context) (workspacesdk.AgentConn, error) { |
| 1064 | if c.server.agentConnFn == nil { |
no test coverage detected