|
6 | 6 | "sync" |
7 | 7 | "time" |
8 | 8 |
|
| 9 | + clientsignals "github.com/superfly/client-signals/go" |
9 | 10 | "github.com/superfly/flyctl/terminal" |
10 | 11 | ) |
11 | 12 |
|
@@ -80,7 +81,8 @@ type LaunchStatusPayload struct { |
80 | 81 |
|
81 | 82 | ScannerFamily string `json:"scanner_family"` |
82 | 83 | FlyctlVersion string `json:"flyctlVersion"` |
83 | | - ClientAgent string `json:"clientAgent,omitempty"` |
| 84 | + Operator string `json:"operator,omitempty"` |
| 85 | + AgentName string `json:"agentName,omitempty"` |
84 | 86 | } |
85 | 87 |
|
86 | 88 | func LaunchStatus(ctx context.Context, payload LaunchStatusPayload) { |
@@ -114,7 +116,8 @@ type DeployStatusPayload struct { |
114 | 116 | Strategy string `json:"strategy"` |
115 | 117 |
|
116 | 118 | FlyctlVersion string `json:"flyctlVersion"` |
117 | | - ClientAgent string `json:"clientAgent,omitempty"` |
| 119 | + Operator string `json:"operator,omitempty"` |
| 120 | + AgentName string `json:"agentName,omitempty"` |
118 | 121 | } |
119 | 122 |
|
120 | 123 | func DeployStatus(ctx context.Context, payload DeployStatusPayload) { |
@@ -161,15 +164,17 @@ func StartTiming(ctx context.Context, metricSlug string) func() { |
161 | 164 | } |
162 | 165 | } |
163 | 166 |
|
164 | | -type clientAgentKey struct{} |
165 | | - |
166 | | -func WithClientAgent(ctx context.Context, agent string) context.Context { |
167 | | - return context.WithValue(ctx, clientAgentKey{}, agent) |
168 | | -} |
169 | | - |
170 | | -func ClientAgentFromContext(ctx context.Context) string { |
171 | | - val, _ := ctx.Value(clientAgentKey{}).(string) |
172 | | - return val |
| 167 | +// OperatorFromSignals returns an operator classification and, when the |
| 168 | +// operator is "agent", the agent name. Precedence: agent > ci > interactive. |
| 169 | +func OperatorFromSignals(s clientsignals.Signals) (operator, agentName string) { |
| 170 | + switch { |
| 171 | + case s.Agent != "": |
| 172 | + return "agent", s.Agent |
| 173 | + case s.CI: |
| 174 | + return "ci", "" |
| 175 | + default: |
| 176 | + return "interactive", "" |
| 177 | + } |
173 | 178 | } |
174 | 179 |
|
175 | 180 | type disableFlushMetricsKey struct{} |
|
0 commit comments