Skip to content

Commit faf71c1

Browse files
committed
fix(app): set the added provider or agent as the active chat target before handoff
1 parent 809b6d6 commit faf71c1

4 files changed

Lines changed: 28 additions & 14 deletions

File tree

packages/browseros-agent/apps/app/screens/ai-settings/CustomCodingAgentDialog.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export interface CustomCodingAgentDialogProps {
4444
onOpenChange: (open: boolean) => void
4545
/** When set, the dialog edits this agent instead of creating a new one. */
4646
agent?: AcpAgent | null
47-
/** Fires after a new custom agent is successfully created (not on edit). */
48-
onSaved?: () => void
47+
/** Fires with the new agent's id after a custom agent is created (not on edit). */
48+
onSaved?: (agentId: string) => void
4949
}
5050

5151
export const CustomCodingAgentDialog: FC<CustomCodingAgentDialogProps> = ({
@@ -124,6 +124,7 @@ export const CustomCodingAgentDialog: FC<CustomCodingAgentDialogProps> = ({
124124
systemPromptAppend,
125125
icon: logoKey,
126126
})
127+
let createdId: string | undefined
127128
if (isEdit && agent) {
128129
await updateAgent.mutateAsync({
129130
agentId: agent.id,
@@ -136,17 +137,18 @@ export const CustomCodingAgentDialog: FC<CustomCodingAgentDialogProps> = ({
136137
},
137138
})
138139
} else {
139-
await createAgent.mutateAsync({
140+
const created = await createAgent.mutateAsync({
140141
name: name.trim(),
141142
type: 'custom',
142143
modelId: modelId || undefined,
143144
reasoningEffort: reasoningEffort || undefined,
144145
workingDirectory: workingDirectory.trim() || undefined,
145146
customConfig,
146147
})
148+
createdId = created.id
147149
}
148150
onOpenChange(false)
149-
if (!agent) onSaved?.()
151+
if (createdId) onSaved?.(createdId)
150152
}
151153

152154
return (

packages/browseros-agent/apps/app/screens/ai-settings/NewCodingAgentDialog.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export interface NewCodingAgentDialogProps {
2929
type: AcpAgentType | null
3030
open: boolean
3131
onOpenChange: (open: boolean) => void
32-
/** Fires after the agent is successfully created. */
33-
onSaved?: () => void
32+
/** Fires with the new agent's id after it is successfully created. */
33+
onSaved?: (agentId: string) => void
3434
}
3535

3636
export const NewCodingAgentDialog: FC<NewCodingAgentDialogProps> = ({
@@ -58,14 +58,14 @@ export const NewCodingAgentDialog: FC<NewCodingAgentDialogProps> = ({
5858

5959
const handleCreate = async () => {
6060
if (!type || !name.trim()) return
61-
await createAgent.mutateAsync({
61+
const created = await createAgent.mutateAsync({
6262
name: name.trim(),
6363
type,
6464
modelId: modelId || undefined,
6565
reasoningEffort: reasoningEffort || undefined,
6666
})
6767
onOpenChange(false)
68-
onSaved?.()
68+
onSaved?.(created.id)
6969
}
7070

7171
return (

packages/browseros-agent/apps/app/screens/ai-settings/add-provider.hooks.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ interface AddProviderDialogState {
9999
activeDeviceCode: ReturnType<typeof useOAuthProviderFlow>['pendingDeviceCode']
100100
clearActiveDeviceCode: () => void
101101
onSaveProvider: (provider: LlmProviderConfig) => Promise<void>
102-
onAgentAdded?: () => void
102+
onAgentAdded?: (agentId: string) => void
103103
}
104104

105105
/**
@@ -121,7 +121,7 @@ export function useAddProvider(input: {
121121
/** Fires once a provider is successfully added on any path, OAuth included. */
122122
onProviderAdded?: (provider: LlmProviderConfig) => void | Promise<void>
123123
/** Fires once a coding agent is successfully created. */
124-
onAgentAdded?: () => void
124+
onAgentAdded?: (agentId: string) => void
125125
}): AddProviderController {
126126
const {
127127
providers,

packages/browseros-agent/apps/app/screens/onboarding-ai/OnboardingAiPage.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { FC } from 'react'
22
import { useNavigate } from 'react-router'
3+
import { commitChatTargetSelection } from '@/modules/chat/sidepanel-chat-targets'
34
import { useLlmProviders } from '@/modules/llm-providers/llm-providers.hooks'
45
import { AddProviderSection } from '@/screens/ai-settings/AddProviderSection'
56
import {
@@ -26,16 +27,27 @@ export const OnboardingAiPage: FC = () => {
2627
const goHome = () => navigate('/home', { replace: true })
2728

2829
// Adding a provider or a coding agent both count as connecting something, so
29-
// either hands off to the new tab page. A newly added provider also becomes
30-
// the default so the user's first chat uses what they just set up.
30+
// either makes what was just added the active chat target and then hands off.
31+
// commitChatTargetSelection writes the unified selection new chats read (and
32+
// updates the default-provider id for an LLM target); await it before the hop
33+
// so the new tab page opens on the target the user just set up.
3134
const addProvider = useAddProvider({
3235
providers,
3336
saveProvider,
3437
onProviderAdded: async (provider) => {
35-
await setDefaultProvider(provider.id)
38+
await commitChatTargetSelection(
39+
{ kind: 'llm', id: provider.id },
40+
{ setDefaultProvider },
41+
)
42+
goHome()
43+
},
44+
onAgentAdded: async (agentId) => {
45+
await commitChatTargetSelection(
46+
{ kind: 'acp', id: agentId },
47+
{ setDefaultProvider },
48+
)
3649
goHome()
3750
},
38-
onAgentAdded: goHome,
3951
})
4052

4153
return (

0 commit comments

Comments
 (0)