@@ -20,21 +20,19 @@ import {
2020interface AgentexContextValue {
2121 agentexClient : AgentexSDK ;
2222 sgpAppURL : string ;
23- // Whether the platform API is configured, so the account picker can fetch/switch accounts
23+ // Platform API configured → the account picker can fetch/switch accounts.
2424 accountsEnabled : boolean ;
25- // Selected account id (from the `account_id` query param) + a setter that mirrors it
26- // to the URL and updates the header the SDK sends.
25+ // Selected account (from the `account_id` param) + a setter that mirrors it to the URL.
2726 selectedAccountId : string | null ;
2827 setSelectedAccountId : ( id : string , replace ?: boolean ) => void ;
2928}
3029
3130const AgentexContext = createContext < AgentexContextValue | null > ( null ) ;
3231
3332/**
34- * Main provider. The SDK ALWAYS targets the same-origin BFF proxy (`/api/agentex`), which
35- * forwards credentials server-side. The selected account travels as the
36- * `x-selected-account-id` header, sourced from the `account_id` query param — no cookie
37- * involved.
33+ * The SDK always targets the same-origin BFF (`/api/agentex`), which attaches credentials
34+ * server-side. The selected account rides as `x-selected-account-id`, from the `account_id`
35+ * query param.
3836 */
3937export function AgentexProvider ( {
4038 children,
@@ -47,9 +45,8 @@ export function AgentexProvider({
4745} ) {
4846 const { sgpAccountID, updateParams } = useSafeSearchParams ( ) ;
4947
50- // Synchronous source for the SDK's per-request header. Seeded from the URL and kept in
51- // sync with it; setSelectedAccountId also sets it synchronously so a switch's refetch doesn't
52- // race the (async) URL navigation.
48+ // Synchronous source for the SDK header: setSelectedAccountId sets it before the (async)
49+ // URL navigation, so a switch's refetch doesn't race it.
5350 const selectedAccountIdRef = useRef < string | null > ( sgpAccountID ) ;
5451 useEffect ( ( ) => {
5552 selectedAccountIdRef . current = sgpAccountID ;
@@ -61,8 +58,8 @@ export function AgentexProvider({
6158 updateParams (
6259 {
6360 [ SearchParamKey . SGP_ACCOUNT_ID ] : id ,
64- // An explicit switch (not the initial bootstrap, which passes replace) drops the
65- // open task — it's account-scoped and won't resolve under the new account.
61+ // An explicit switch (not bootstrap, which passes replace) drops the open task:
62+ // it's account-scoped and won't resolve under the new account.
6663 ...( replace ? { } : { [ SearchParamKey . TASK_ID ] : null } ) ,
6764 } ,
6865 replace
@@ -72,9 +69,8 @@ export function AgentexProvider({
7269 ) ;
7370
7471 const agentexClient = useMemo ( ( ) => {
75- // The SDK builds request URLs with `new URL()`, so the base must be ABSOLUTE. On the
76- // server `window` is absent, but no request fires during the initial server render
77- // (react-query fetches on the client); the client render recomputes an absolute URL.
72+ // The SDK builds URLs with `new URL()`, so the base must be absolute. `window` is absent
73+ // on the server, but no request fires during SSR; the client render recomputes it.
7874 const baseURL =
7975 typeof window !== 'undefined'
8076 ? `${ window . location . origin } /api/agentex`
0 commit comments