Skip to content

Commit a5bdcdc

Browse files
committed
Add AI Studio user ID support
1 parent 1246a4f commit a5bdcdc

13 files changed

Lines changed: 142 additions & 6 deletions

File tree

‎packages/browser/src/content-scripts/send-prompt-content-script/send-prompt-content-script.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const is_cwc_hash = hash.startsWith(hash_prefix_new)
3434

3535
const batch_id = hash.substring(hash_prefix_new.length + 1)
3636

37-
const ai_studio_url = 'https://aistudio.google.com/prompts/new_chat'
37+
const ai_studio_url = 'https://aistudio.google.com/'
3838
const is_ai_studio = current_url.startsWith(ai_studio_url)
3939

4040
const gemini_url = 'https://gemini.google.com/'

‎packages/browser/src/manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"content_scripts": [
2525
{
2626
"matches": [
27-
"https://aistudio.google.com/prompts/new_chat*",
27+
"https://aistudio.google.com/*",
2828
"https://chatgpt.com/*",
2929
"https://claude.ai/*",
3030
"https://copilot.microsoft.com/",

‎packages/vscode/package.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,13 @@
600600
"type": "object",
601601
"title": "Code Web Chat Settings",
602602
"properties": {
603+
"codeWebChat.aiStudioUserId": {
604+
"type": [
605+
"integer",
606+
"null"
607+
],
608+
"default": null
609+
},
603610
"codeWebChat.geminiUserId": {
604611
"type": [
605612
"integer",

‎packages/vscode/src/services/websocket-manager.ts‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ export class WebSocketManager {
279279
const web_chat_presets =
280280
config.get<ConfigPresetFormat[]>(params.presets_config_key) ?? []
281281
const gemini_user_id = config.get<number | null>('geminiUserId')
282+
const ai_studio_user_id = config.get<number | null>('aiStudioUserId')
282283

283284
for (const chat of params.chats) {
284285
const preset = web_chat_presets.find((p) => p.name == chat.preset_name)
@@ -289,10 +290,17 @@ export class WebSocketManager {
289290
const chatbot = CHATBOTS[preset.chatbot as keyof typeof CHATBOTS]
290291
let url: string
291292
if (preset.chatbot == 'AI Studio') {
293+
let base_url = chatbot.url
294+
if (ai_studio_user_id !== null && ai_studio_user_id !== undefined) {
295+
base_url = base_url.replace(
296+
'https://aistudio.google.com/',
297+
`https://aistudio.google.com/u/${ai_studio_user_id}/`
298+
)
299+
}
292300
if (preset.model) {
293-
url = `${chatbot.url}?model=${preset.model}`
301+
url = `${base_url}?model=${preset.model}`
294302
} else {
295-
url = chatbot.url
303+
url = base_url
296304
}
297305
} else if (preset.chatbot == 'Open WebUI') {
298306
if (preset.port) {
@@ -362,14 +370,22 @@ export class WebSocketManager {
362370

363371
const config = vscode.workspace.getConfiguration('codeWebChat')
364372
const gemini_user_number = config.get<number | null>('geminiUserNumber')
373+
const ai_studio_user_id = config.get<number | null>('aiStudioUserId')
365374

366375
const chatbot = CHATBOTS[params.preset.chatbot as keyof typeof CHATBOTS]
367376
let url: string
368377
if (params.preset.chatbot == 'AI Studio') {
378+
let base_url = chatbot.url
379+
if (ai_studio_user_id !== null && ai_studio_user_id !== undefined) {
380+
base_url = base_url.replace(
381+
'https://aistudio.google.com/',
382+
`https://aistudio.google.com/u/${ai_studio_user_id}/`
383+
)
384+
}
369385
if (params.preset.model) {
370-
url = `${chatbot.url}?model=${params.preset.model}`
386+
url = `${base_url}?model=${params.preset.model}`
371387
} else {
372-
url = chatbot.url
388+
url = base_url
373389
}
374390
} else if (params.preset.chatbot == 'Open WebUI') {
375391
if (params.preset.port) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as vscode from 'vscode'
2+
import { SettingsProvider } from '@/views/settings/backend/settings-provider'
3+
4+
export const handle_get_ai_studio_user_id = async (
5+
provider: SettingsProvider
6+
): Promise<void> => {
7+
const config = vscode.workspace.getConfiguration('codeWebChat')
8+
const aiStudioUserId = config.get<number | null>('aiStudioUserId') ?? null
9+
provider.postMessage({
10+
command: 'AI_STUDIO_USER_ID',
11+
aiStudioUserId
12+
})
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as vscode from 'vscode'
2+
import { UpdateAiStudioUserIdMessage } from '@/views/settings/types/messages'
3+
4+
export const handle_update_ai_studio_user_id = async (
5+
message: UpdateAiStudioUserIdMessage
6+
): Promise<void> => {
7+
await vscode.workspace
8+
.getConfiguration('codeWebChat')
9+
.update(
10+
'aiStudioUserId',
11+
message.aiStudioUserId || undefined,
12+
vscode.ConfigurationTarget.Global
13+
)
14+
}

‎packages/vscode/src/views/settings/backend/message-handlers/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export * from './handle-get-clear-checks-in-workspace-behavior'
3131
export * from './handle-update-clear-checks-in-workspace-behavior'
3232
export * from './handle-get-gemini-user-id'
3333
export * from './handle-update-gemini-user-id'
34+
export * from './handle-get-ai-studio-user-id'
35+
export * from './handle-update-ai-studio-user-id'
3436
export * from './handle-get-context-size-warning-threshold'
3537
export * from './handle-update-context-size-warning-threshold'
3638
export * from './handle-get-are-automatic-checkpoints-disabled'

‎packages/vscode/src/views/settings/backend/settings-provider.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
handle_get_edit_context_system_instructions,
2424
handle_get_edit_format_instructions,
2525
handle_get_gemini_user_id,
26+
handle_get_ai_studio_user_id,
2627
handle_get_intelligent_update_configurations,
2728
handle_get_model_providers,
2829
handle_get_checkpoint_lifespan,
@@ -42,6 +43,7 @@ import {
4243
handle_update_edit_context_system_instructions,
4344
handle_update_edit_format_instructions,
4445
handle_update_gemini_user_id,
46+
handle_update_ai_studio_user_id,
4547
handle_upsert_configuration,
4648
handle_open_ignore_patterns_settings
4749
} from './message-handlers'
@@ -199,6 +201,10 @@ export class SettingsProvider {
199201
await handle_get_gemini_user_id(this)
200202
} else if (message.command == 'UPDATE_GEMINI_USER_ID') {
201203
await handle_update_gemini_user_id(message)
204+
} else if (message.command == 'GET_AI_STUDIO_USER_ID') {
205+
await handle_get_ai_studio_user_id(this)
206+
} else if (message.command == 'UPDATE_AI_STUDIO_USER_ID') {
207+
await handle_update_ai_studio_user_id(message)
202208
} else if (message.command == 'GET_CHECKPOINT_LIFESPAN') {
203209
await handle_get_checkpoint_lifespan(this)
204210
} else if (
@@ -246,6 +252,7 @@ export class SettingsProvider {
246252
void handle_get_are_automatic_checkpoints_disabled(this)
247253
void handle_get_checkpoint_lifespan(this)
248254
void handle_get_gemini_user_id(this)
255+
void handle_get_ai_studio_user_id(this)
249256
}
250257
})
251258
)

‎packages/vscode/src/views/settings/frontend/Home/Home.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type Props = {
7878
commit_message_auto_accept_after: number | null
7979
context_size_warning_threshold: number
8080
gemini_user_id: number | null
81+
ai_studio_user_id: number | null
8182
are_automatic_checkpoints_disabled: boolean
8283
checkpoint_lifespan: number
8384
edit_format_instructions: EditFormatInstructions
@@ -99,6 +100,7 @@ type Props = {
99100
on_automatic_checkpoints_toggle: (disabled: boolean) => void
100101
on_checkpoint_lifespan_change: (hours: number) => void
101102
on_gemini_user_id_change: (id: number | null) => void
103+
on_ai_studio_user_id_change: (id: number | null) => void
102104
on_clear_checks_in_workspace_behavior_change: (
103105
value: 'ignore-open-editors' | 'uncheck-all'
104106
) => void
@@ -314,7 +316,9 @@ export const Home: React.FC<Props> = (props) => {
314316
<PresetsSection
315317
ref={(el) => (section_refs.current['presets'] = el)}
316318
gemini_user_id={props.gemini_user_id}
319+
ai_studio_user_id={props.ai_studio_user_id}
317320
on_gemini_user_id_change={props.on_gemini_user_id_change}
321+
on_ai_studio_user_id_change={props.on_ai_studio_user_id_change}
318322
on_stuck_change={presets_on_stuck_change}
319323
/>
320324
<Section

‎packages/vscode/src/views/settings/frontend/Home/sections/PresetsSection.tsx‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import { Group } from '@ui/components/editor/settings/Group/Group'
66

77
type Props = {
88
gemini_user_id: number | null
9+
ai_studio_user_id: number | null
910
on_gemini_user_id_change: (id: number | null) => void
11+
on_ai_studio_user_id_change: (id: number | null) => void
1012
on_stuck_change: (is_stuck: boolean) => void
1113
}
1214

1315
export const PresetsSection = forwardRef<HTMLDivElement, Props>(
1416
(props, ref) => {
1517
const [gemini_user_id_str, set_gemini_user_id_str] = useState('')
18+
const [ai_studio_user_id_str, set_ai_studio_user_id_str] = useState('')
1619

1720
useEffect(() => {
1821
set_gemini_user_id_str(
@@ -22,6 +25,15 @@ export const PresetsSection = forwardRef<HTMLDivElement, Props>(
2225
)
2326
}, [props.gemini_user_id])
2427

28+
useEffect(() => {
29+
set_ai_studio_user_id_str(
30+
props.ai_studio_user_id === null ||
31+
props.ai_studio_user_id === undefined
32+
? ''
33+
: String(props.ai_studio_user_id)
34+
)
35+
}, [props.ai_studio_user_id])
36+
2537
const handle_gemini_user_id_blur = () => {
2638
if (gemini_user_id_str === '') {
2739
props.on_gemini_user_id_change(null)
@@ -33,6 +45,17 @@ export const PresetsSection = forwardRef<HTMLDivElement, Props>(
3345
}
3446
}
3547

48+
const handle_ai_studio_user_id_blur = () => {
49+
if (ai_studio_user_id_str === '') {
50+
props.on_ai_studio_user_id_change(null)
51+
return
52+
}
53+
const num_id = parseInt(ai_studio_user_id_str, 10)
54+
if (!isNaN(num_id) && num_id >= 0) {
55+
props.on_ai_studio_user_id_change(num_id)
56+
}
57+
}
58+
3659
return (
3760
<Section
3861
ref={ref}
@@ -54,6 +77,19 @@ export const PresetsSection = forwardRef<HTMLDivElement, Props>(
5477
/>
5578
}
5679
/>
80+
<Item
81+
title="AI Studio User ID"
82+
description="Run AI Studio chatbot as non-default user. Check URL for the numeric ID."
83+
slot_right={
84+
<Input
85+
type="number"
86+
value={ai_studio_user_id_str}
87+
on_change={set_ai_studio_user_id_str}
88+
on_blur={handle_ai_studio_user_id_blur}
89+
max_width={60}
90+
/>
91+
}
92+
/>
5793
</Group>
5894
</Section>
5995
)

0 commit comments

Comments
 (0)