MCPcopy Index your code
hub / github.com/coder/coder / externalAgentPreflightError

Method externalAgentPreflightError

coderd/x/chatd/chatd.go:1035–1061  ·  view source on GitHub ↗
(
	ctx context.Context,
	chatSnapshot database.Chat,
	agent database.WorkspaceAgent,
)

Source from the content-addressed store, hash-verified

1033}
1034
1035func (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
1063func (c *turnWorkspaceContext) getWorkspaceConn(ctx context.Context) (workspacesdk.AgentConn, error) {
1064 if c.server.agentConnFn == nil {

Callers 1

getWorkspaceConnMethod · 0.95

Calls 4

IsExternalWorkspaceAgentFunction · 0.92
isAgentUnreachableFunction · 0.85

Tested by

no test coverage detected