mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
refactor: type computer use provider as an enum (#27086)
The deployment-wide computer use provider was passed around as a bare `string` on the `codersdk` wire structs, in `chattool`, and in the generated TypeScript, and its valid values (`anthropic`, `openai`) were never exposed as a `codersdk` enum. That's out of step with our other chat settings (`ChatDebugRunKind`, `ChatUsageLimitPeriod`), which already define enums with `Valid()` and an `All<Name>s` slice, and it left the allowed values duplicated as literals with no typed contract for clients. This adds `codersdk.ChatComputerUseProvider` as the single source of truth and routes the API boundary, `chattool`, `chatd`, and the generated TypeScript through it. The DB layer and chattool's internal model-provider routing stay `string` on purpose, since they handle untrusted or fantasy-model values that just happen to share the names.
This commit is contained in:
+22
-2
@@ -913,16 +913,36 @@ type AdvisorConfig struct {
|
||||
// the request and response shapes are currently identical.
|
||||
type UpdateAdvisorConfigRequest = AdvisorConfig
|
||||
|
||||
// ChatComputerUseProvider identifies the provider that backs computer use for
|
||||
// the virtual desktop.
|
||||
type ChatComputerUseProvider string
|
||||
|
||||
const (
|
||||
ChatComputerUseProviderAnthropic ChatComputerUseProvider = "anthropic"
|
||||
ChatComputerUseProviderOpenAI ChatComputerUseProvider = "openai"
|
||||
)
|
||||
|
||||
// AllChatComputerUseProviders contains every ChatComputerUseProvider value.
|
||||
var AllChatComputerUseProviders = []ChatComputerUseProvider{
|
||||
ChatComputerUseProviderAnthropic,
|
||||
ChatComputerUseProviderOpenAI,
|
||||
}
|
||||
|
||||
// Valid reports whether p is a supported computer use provider.
|
||||
func (p ChatComputerUseProvider) Valid() bool {
|
||||
return slices.Contains(AllChatComputerUseProviders, p)
|
||||
}
|
||||
|
||||
// ChatComputerUseProviderResponse is the response for getting the computer use
|
||||
// provider setting.
|
||||
type ChatComputerUseProviderResponse struct {
|
||||
Provider string `json:"provider"`
|
||||
Provider ChatComputerUseProvider `json:"provider"`
|
||||
}
|
||||
|
||||
// UpdateChatComputerUseProviderRequest is the request to update the computer use
|
||||
// provider setting.
|
||||
type UpdateChatComputerUseProviderRequest struct {
|
||||
Provider string `json:"provider"`
|
||||
Provider ChatComputerUseProvider `json:"provider"`
|
||||
}
|
||||
|
||||
// ChatDebugLoggingAdminSettings describes the runtime admin setting
|
||||
|
||||
Reference in New Issue
Block a user