Skip to content

Commit 2dfefa6

Browse files
committed
Address pr feedback v1
1 parent ca6a3e7 commit 2dfefa6

8 files changed

Lines changed: 59 additions & 40 deletions

File tree

‎packages/types/src/vscode-extension-host.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ export type ExtensionState = Pick<
376376
zooCodeUserName?: string
377377
zooCodeUserEmail?: string
378378
zooCodeUserImage?: string
379+
zooCodeBaseUrl?: string
379380
debug?: boolean
380381

381382
/**

‎src/activate/handleUri.ts‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,22 @@ export const handleUri = async (uri: vscode.Uri) => {
3434
case "/auth-callback": {
3535
const token = query.get("token")
3636
if (token) {
37-
// Extract user info from callback URL params with proper URL decoding
38-
const name = query.get("name") ? decodeURIComponent(query.get("name")!.replace(/\+/g, " ")) : undefined
39-
const email = query.get("email")
40-
? decodeURIComponent(query.get("email")!.replace(/\+/g, " "))
41-
: undefined
42-
const image = query.get("image") ? decodeURIComponent(query.get("image")!) : undefined
43-
44-
// Store user info if provided
45-
if (name || email || image) {
46-
await setZooCodeUserInfo({
47-
name,
48-
email,
49-
image,
50-
})
51-
}
37+
// Extract user info from callback URL params
38+
// URLSearchParams.get() already decodes percent-encoded values - no need for decodeURIComponent
39+
const name = query.get("name") ?? undefined
40+
const email = query.get("email") ?? undefined
41+
const image = query.get("image") ?? undefined
5242

5343
const success = await handleZooCodeAuthCallback(token)
5444
if (success && visibleProvider) {
45+
// Store user info only after successful auth validation
46+
if (name || email || image) {
47+
await setZooCodeUserInfo({
48+
name,
49+
email,
50+
image,
51+
})
52+
}
5553
// Update the active API configuration to use zoo-code with the new token
5654
await visibleProvider.handleZooCodeCallback(token)
5755
}

‎src/core/webview/ClineProvider.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,10 +1684,10 @@ export class ClineProvider
16841684

16851685
// Zoo Code Auth (for observability telemetry)
16861686

1687-
async handleZooCodeCallback(token: string) {
1688-
const { handleAuthCallback } = await import("../../services/zoo-code-auth")
1689-
await handleAuthCallback(token)
1690-
// Refresh webview state to show updated auth status
1687+
async handleZooCodeCallback(_token: string) {
1688+
// Auth mutation (token storage, subscription check, success toast) was already
1689+
// performed by handleAuthCallback() in handleUri.ts before this method was called.
1690+
// This method only needs to refresh the webview state to reflect the new auth status.
16911691
await this.postStateToWebview()
16921692
}
16931693

@@ -2299,18 +2299,20 @@ export class ClineProvider
22992299
})(),
23002300
...(() => {
23012301
try {
2302-
const { getCachedZooCodeUserInfo } = require("../../services/zoo-code-auth")
2302+
const { getCachedZooCodeUserInfo, getZooCodeBaseUrl } = require("../../services/zoo-code-auth")
23032303
const userInfo = getCachedZooCodeUserInfo()
23042304
return {
23052305
zooCodeUserName: userInfo.name,
23062306
zooCodeUserEmail: userInfo.email,
23072307
zooCodeUserImage: userInfo.image,
2308+
zooCodeBaseUrl: getZooCodeBaseUrl(),
23082309
}
23092310
} catch {
23102311
return {
23112312
zooCodeUserName: undefined,
23122313
zooCodeUserEmail: undefined,
23132314
zooCodeUserImage: undefined,
2315+
zooCodeBaseUrl: "https://www.zoocode.dev",
23142316
}
23152317
}
23162318
})(),

‎src/extension.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export async function activate(context: vscode.ExtensionContext) {
160160
openAiCodexOAuthManager.initialize(context, (message) => outputChannel.appendLine(message))
161161

162162
// Initialize Zoo Code auth service for extension session token management.
163-
initZooCodeAuth(context)
163+
await initZooCodeAuth(context)
164164

165165
// Get default commands from configuration.
166166
const defaultCommands = vscode.workspace.getConfiguration(Package.name).get<string[]>("allowedCommands") || []

‎src/services/zoo-code-auth.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ let _lastSubscriptionCheck: number = 0
2020
const SUBSCRIPTION_CHECK_INTERVAL_MS = 5 * 60 * 1000 // 5 minutes
2121

2222
export async function initZooCodeAuth(context: vscode.ExtensionContext): Promise<void> {
23+
if (!context.secrets) {
24+
// Secret storage unavailable (e.g. test environment without secrets mock).
25+
// Treat as unauthenticated startup — all cached values remain undefined.
26+
return
27+
}
2328
secretStorage = context.secrets
2429

2530
// Pre-load the token and user info into memory on init so ZooCodeHandler can access them synchronously
@@ -234,6 +239,7 @@ export async function verifyZooCodeToken(): Promise<boolean> {
234239
try {
235240
const response = await fetch(`${baseUrl}/api/extension/auth/verify`, {
236241
headers: { Authorization: `Bearer ${token}` },
242+
signal: AbortSignal.timeout(10_000),
237243
})
238244

239245
if (!response.ok) {
@@ -242,6 +248,9 @@ export async function verifyZooCodeToken(): Promise<boolean> {
242248
}
243249

244250
const data = (await response.json()) as { valid?: boolean }
251+
if (!data.valid) {
252+
await clearZooCodeToken()
253+
}
245254
return data.valid === true
246255
} catch {
247256
return false
@@ -263,6 +272,7 @@ export async function disconnectZooCode(): Promise<void> {
263272
await fetch(`${baseUrl}/api/extension/auth/revoke`, {
264273
method: "POST",
265274
headers: { Authorization: `Bearer ${token}` },
275+
signal: AbortSignal.timeout(10_000),
266276
})
267277
} catch {
268278
// Ignore errors during revocation

‎src/services/zoo-telemetry.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export async function sendLlmTelemetry(payload: LlmTelemetryPayload): Promise<vo
5555
Authorization: `Bearer ${token}`,
5656
},
5757
body: JSON.stringify(body),
58+
signal: AbortSignal.timeout(10_000),
5859
}).catch(() => {
5960
// Silently ignore errors - telemetry should never impact user experience
6061
})

‎webview-ui/src/components/chat/ZooCodeAuthBadge.tsx‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ function getInitials(name?: string, email?: string): string {
3333
return "?"
3434
}
3535

36-
const ZOO_CODE_BASE_URL = "https://www.zoocode.dev"
37-
3836
export const ZooCodeAuthBadge: React.FC<ZooCodeAuthBadgeProps> = ({ className }) => {
39-
const { zooCodeIsAuthenticated, zooCodeUserName, zooCodeUserEmail, zooCodeUserImage, uriScheme } =
37+
const { zooCodeIsAuthenticated, zooCodeUserName, zooCodeUserEmail, zooCodeUserImage, zooCodeBaseUrl, uriScheme } =
4038
useExtensionState()
4139
const [isOpen, setIsOpen] = useState(false)
4240
const [imageError, setImageError] = useState(false)
@@ -58,7 +56,7 @@ export const ZooCodeAuthBadge: React.FC<ZooCodeAuthBadgeProps> = ({ className })
5856
setImageError(false)
5957
}, [zooCodeUserImage])
6058

61-
const authUrl = getZooCodeAuthUrl(uriScheme)
59+
const authUrl = getZooCodeAuthUrl(uriScheme, zooCodeBaseUrl)
6260

6361
const showImage = zooCodeIsAuthenticated && zooCodeUserImage && !imageError
6462
const avatarColor = getAvatarColor(zooCodeUserEmail || zooCodeUserName || "ZC")
@@ -87,7 +85,8 @@ export const ZooCodeAuthBadge: React.FC<ZooCodeAuthBadgeProps> = ({ className })
8785
fontSize: zooCodeIsAuthenticated && !showImage ? 9 : 14,
8886
fontWeight: 600,
8987
background: zooCodeIsAuthenticated ? (showImage ? "transparent" : avatarColor) : undefined,
90-
color: zooCodeIsAuthenticated && !showImage ? "#ffffff" : undefined,
88+
color:
89+
zooCodeIsAuthenticated && !showImage ? "var(--vscode-button-foreground, #ffffff)" : undefined,
9190
}}
9291
title={zooCodeIsAuthenticated ? `Zoo Code: ${zooCodeUserEmail || "Connected"}` : "Sign in to Zoo Code"}>
9392
{zooCodeIsAuthenticated ? (
@@ -134,8 +133,8 @@ export const ZooCodeAuthBadge: React.FC<ZooCodeAuthBadgeProps> = ({ className })
134133
"overflow-hidden",
135134
)}
136135
style={{
137-
background: "#1e1e1e",
138-
border: "1px solid #3c3c3c",
136+
background: "var(--vscode-menu-background)",
137+
border: "1px solid var(--vscode-menu-border, var(--vscode-widget-border, #3c3c3c))",
139138
zIndex: 9999,
140139
}}>
141140
{!zooCodeIsAuthenticated ? (
@@ -144,9 +143,11 @@ export const ZooCodeAuthBadge: React.FC<ZooCodeAuthBadgeProps> = ({ className })
144143
onClick={() => setIsOpen(false)}
145144
className={cn("block px-3.5 py-2.5", "text-[13px]", "no-underline cursor-pointer")}
146145
style={{
147-
color: "#cccccc",
146+
color: "var(--vscode-menu-foreground)",
148147
}}
149-
onMouseEnter={(e) => (e.currentTarget.style.background = "#094771")}
148+
onMouseEnter={(e) =>
149+
(e.currentTarget.style.background = "var(--vscode-menu-selectionBackground)")
150+
}
150151
onMouseLeave={(e) => (e.currentTarget.style.background = "transparent")}>
151152
Sign in to Zoo Code
152153
</a>
@@ -160,20 +161,23 @@ export const ZooCodeAuthBadge: React.FC<ZooCodeAuthBadgeProps> = ({ className })
160161
"pointer-events-none select-none",
161162
)}
162163
style={{
163-
color: "#858585",
164-
borderBottom: "1px solid #3c3c3c",
164+
color: "var(--vscode-descriptionForeground)",
165+
borderBottom:
166+
"1px solid var(--vscode-menu-separatorBackground, var(--vscode-widget-border, #3c3c3c))",
165167
}}>
166168
{zooCodeUserEmail}
167169
</div>
168170
)}
169171
<a
170-
href={`${ZOO_CODE_BASE_URL}/dashboard`}
172+
href={`${zooCodeBaseUrl || "https://www.zoocode.dev"}/dashboard`}
171173
onClick={() => setIsOpen(false)}
172174
className={cn("block px-3.5 py-2.5", "text-[13px]", "no-underline cursor-pointer")}
173175
style={{
174-
color: "#cccccc",
176+
color: "var(--vscode-menu-foreground)",
175177
}}
176-
onMouseEnter={(e) => (e.currentTarget.style.background = "#094771")}
178+
onMouseEnter={(e) =>
179+
(e.currentTarget.style.background = "var(--vscode-menu-selectionBackground)")
180+
}
177181
onMouseLeave={(e) => (e.currentTarget.style.background = "transparent")}>
178182
Go to Dashboard
179183
</a>
@@ -186,9 +190,11 @@ export const ZooCodeAuthBadge: React.FC<ZooCodeAuthBadgeProps> = ({ className })
186190
"text-left cursor-pointer",
187191
)}
188192
style={{
189-
color: "#f14c4c",
193+
color: "var(--vscode-errorForeground)",
190194
}}
191-
onMouseEnter={(e) => (e.currentTarget.style.background = "#094771")}
195+
onMouseEnter={(e) =>
196+
(e.currentTarget.style.background = "var(--vscode-menu-selectionBackground)")
197+
}
192198
onMouseLeave={(e) => (e.currentTarget.style.background = "transparent")}>
193199
Sign out
194200
</button>

‎webview-ui/src/oauth/urls.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ export function getRequestyAuthUrl(uriScheme?: string) {
1212
return `https://app.requesty.ai/oauth/authorize?callback_url=${getCallbackUrl("requesty", uriScheme)}`
1313
}
1414

15-
const ZOO_CODE_BASE_URL = "https://www.zoocode.dev"
15+
const ZOO_CODE_DEFAULT_BASE_URL = "https://www.zoocode.dev"
1616

17-
export function getZooCodeAuthUrl(uriScheme?: string) {
17+
export function getZooCodeAuthUrl(uriScheme?: string, baseUrl?: string) {
18+
const resolvedBaseUrl = baseUrl || ZOO_CODE_DEFAULT_BASE_URL
1819
const callbackUri = getCallbackUrl("auth-callback", uriScheme)
1920
const deviceName = encodeURIComponent("VS Code")
2021
const editor = encodeURIComponent("VS Code")
2122
const version = Package.version
22-
return `${ZOO_CODE_BASE_URL}/dashboard/connect?device=${deviceName}&editor=${editor}&version=${version}&callback_uri=${callbackUri}`
23+
return `${resolvedBaseUrl}/dashboard/connect?device=${deviceName}&editor=${editor}&version=${version}&callback_uri=${callbackUri}`
2324
}

0 commit comments

Comments
 (0)