-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathZooGateway.tsx
More file actions
125 lines (112 loc) · 4.37 KB
/
Copy pathZooGateway.tsx
File metadata and controls
125 lines (112 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { useEffect, useMemo } from "react"
import {
type ProviderSettings,
type OrganizationAllowList,
type RouterModels,
zooGatewayDefaultModelId,
} from "@roo-code/types"
import { useExtensionState } from "@src/context/ExtensionStateContext"
import { getZooCodeAuthUrl } from "@src/oauth/urls"
import { useAppTranslation } from "@src/i18n/TranslationContext"
import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink"
import { ModelPicker } from "../ModelPicker"
import { ApiErrorMessage } from "../ApiErrorMessage"
type ZooGatewayProps = {
apiConfiguration: ProviderSettings
setApiConfigurationField: (field: keyof ProviderSettings, value: ProviderSettings[keyof ProviderSettings]) => void
routerModels?: RouterModels
organizationAllowList: OrganizationAllowList
modelValidationError?: string
simplifySettings?: boolean
}
function isClaudeSonnetModelId(id: string) {
return /claude.*sonnet/i.test(id)
}
// Exported for unit tests. Picks the default Zoo Gateway model id, preferring
// Claude Sonnet 4.5 → Sonnet 4 → first available Sonnet → first model overall.
export function pickZooGatewayDefaultModelId(modelIds: string[]) {
if (modelIds.length === 0) {
return zooGatewayDefaultModelId
}
const sonnets = modelIds.filter(isClaudeSonnetModelId)
if (sonnets.length === 0) {
return modelIds[0]
}
return (
sonnets.find((id) => id === "anthropic/claude-sonnet-4.5") ??
sonnets.find((id) => id.includes("claude-sonnet-4.5")) ??
sonnets.find((id) => /sonnet-4[.-]5/i.test(id)) ??
sonnets.find((id) => /sonnet-4(?![.-]?\d)/i.test(id)) ??
sonnets[0]
)
}
export const ZooGateway = ({
apiConfiguration,
setApiConfigurationField,
routerModels,
organizationAllowList,
modelValidationError,
simplifySettings,
}: ZooGatewayProps) => {
const { t } = useAppTranslation()
const { zooCodeIsAuthenticated, zooCodeUserEmail, zooCodeUserName, zooCodeBaseUrl, uriScheme, deviceName } =
useExtensionState()
const authUrl = getZooCodeAuthUrl(uriScheme, zooCodeBaseUrl, deviceName)
const resolvedDashboardBase = zooCodeBaseUrl?.replace(/\/$/, "") || "https://www.zoocode.dev"
const zooModels = useMemo(() => routerModels?.["zoo-gateway"] ?? {}, [routerModels])
const modelIds = useMemo(() => Object.keys(zooModels), [zooModels])
const resolvedDefaultModelId = useMemo(() => pickZooGatewayDefaultModelId(modelIds), [modelIds])
useEffect(() => {
if (modelIds.length === 0) {
return
}
const current = apiConfiguration.zooGatewayModelId
if (!current || !modelIds.includes(current)) {
setApiConfigurationField("zooGatewayModelId", resolvedDefaultModelId)
}
}, [apiConfiguration.zooGatewayModelId, modelIds, resolvedDefaultModelId, setApiConfigurationField])
return (
<>
<div className="flex flex-col gap-1 rounded-md border border-vscode-panel-border p-2">
<div className="flex items-center justify-between">
<label className="block text-sm font-medium">{t("settings:providers.zooGateway.account")}</label>
{zooCodeIsAuthenticated && zooCodeUserEmail && (
<span className="text-xs text-vscode-descriptionForeground">{zooCodeUserEmail}</span>
)}
</div>
{!zooCodeIsAuthenticated ? (
<div className="flex flex-col gap-1">
<ApiErrorMessage errorMessage={t("settings:validation.zooGatewaySignIn")} />
<p className="text-xs text-vscode-descriptionForeground">
{t("settings:providers.zooGateway.signInDescription")}
</p>
<VSCodeButtonLink href={authUrl} appearance="primary">
{t("settings:providers.zooGateway.signInButton")}
</VSCodeButtonLink>
</div>
) : (
<div className="flex items-center gap-1">
<span className="codicon codicon-check text-vscode-charts-green" />
<span className="text-xs text-vscode-descriptionForeground">
{zooCodeUserName
? t("settings:providers.zooGateway.authenticatedAs", { name: zooCodeUserName })
: t("settings:providers.zooGateway.authenticated")}
</span>
</div>
)}
</div>
<ModelPicker
apiConfiguration={apiConfiguration}
setApiConfigurationField={setApiConfigurationField}
defaultModelId={resolvedDefaultModelId}
models={zooModels}
modelIdKey="zooGatewayModelId"
serviceName="Zoo Gateway"
serviceUrl={`${resolvedDashboardBase}/dashboard/models`}
organizationAllowList={organizationAllowList}
errorMessage={modelValidationError}
simplifySettings={simplifySettings}
/>
</>
)
}