Skip to content

Commit 4f22f79

Browse files
refactor: eliminate remaining Task 2/6/8 issues
- Route fetch('/.auth/me') through platformClient (HttpClient with empty baseUrl) - Un-export parseTextContent/resolveImageUrl (module-internal only) - DRY userId || 'anonymous' x6 into normalizeUserId() helper - Remove redundant duplicate prompt field from WelcomeCard suggestions
1 parent ddf6a0c commit 4f22f79

5 files changed

Lines changed: 24 additions & 15 deletions

File tree

content-gen/src/app/frontend/src/api/httpClient.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ export class HttpClient {
163163

164164
const httpClient = new HttpClient('/api');
165165

166+
/**
167+
* Client for Azure platform endpoints (/.auth/me, etc.) — no base URL prefix.
168+
* Shares the same interceptor pattern but targets the host root.
169+
*/
170+
export const platformClient = new HttpClient('', 10_000);
171+
166172
// ---- request interceptor: auth headers ----
167173
httpClient.onRequest((_url, init) => {
168174
const headers = new Headers(init.headers);

content-gen/src/app/frontend/src/api/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import httpClient from './httpClient';
1313
export { default as httpClient } from './httpClient';
1414
import { parseSSEStream, getGenerationStage } from '../utils';
1515

16+
/** Normalize optional userId to a safe fallback. */
17+
function normalizeUserId(userId?: string): string {
18+
return userId || 'anonymous';
19+
}
20+
1621
/**
1722
* Get application configuration including feature flags
1823
*/
@@ -32,7 +37,7 @@ export async function parseBrief(
3237
return httpClient.post<ParsedBriefResponse>('/brief/parse', {
3338
brief_text: briefText,
3439
conversation_id: conversationId,
35-
user_id: userId || 'anonymous',
40+
user_id: normalizeUserId(userId),
3641
}, { signal });
3742
}
3843

@@ -47,7 +52,7 @@ export async function confirmBrief(
4752
return httpClient.post('/brief/confirm', {
4853
brief,
4954
conversation_id: conversationId,
50-
user_id: userId || 'anonymous',
55+
user_id: normalizeUserId(userId),
5156
});
5257
}
5358

@@ -65,7 +70,7 @@ export async function selectProducts(
6570
request,
6671
current_products: currentProducts,
6772
conversation_id: conversationId,
68-
user_id: userId || 'anonymous',
73+
user_id: normalizeUserId(userId),
6974
}, { signal });
7075
}
7176

@@ -85,7 +90,7 @@ export async function* streamChat(
8590
body: JSON.stringify({
8691
message,
8792
conversation_id: conversationId,
88-
user_id: userId || 'anonymous',
93+
user_id: normalizeUserId(userId),
8994
}),
9095
});
9196

@@ -118,7 +123,7 @@ export async function* streamGenerateContent(
118123
products: products || [],
119124
generate_images: generateImages,
120125
conversation_id: conversationId,
121-
user_id: userId || 'anonymous',
126+
user_id: normalizeUserId(userId),
122127
}, { signal });
123128
const taskId = startData.task_id;
124129

@@ -210,7 +215,7 @@ export async function* streamRegenerateImage(
210215
products: products || [],
211216
previous_image_prompt: previousImagePrompt,
212217
conversation_id: conversationId,
213-
user_id: userId || 'anonymous',
218+
user_id: normalizeUserId(userId),
214219
}),
215220
});
216221

content-gen/src/app/frontend/src/components/WelcomeCard.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,16 @@ import SecondPromptIcon from '../styles/images/secondprompt.png';
99

1010
interface SuggestionData {
1111
title: string;
12-
prompt: string;
1312
icon: string;
1413
}
1514

1615
const suggestions: SuggestionData[] = [
1716
{
1817
title: "I need to create a social media post about paint products for home remodels. The campaign is titled \"Brighten Your Springtime\" and the audience is new homeowners. I need marketing copy plus an image. The image should be an informal living room with tasteful furnishings.",
19-
prompt: "I need to create a social media post about paint products for home remodels. The campaign is titled \"Brighten Your Springtime\" and the audience is new homeowners. I need marketing copy plus an image. The image should be an informal living room with tasteful furnishings.",
2018
icon: FirstPromptIcon,
2119
},
2220
{
2321
title: "Generate a social media campaign with ad copy and an image. This is for \"Back to School\" and the audience is parents of school age children. Tone is playful and humorous. The image must have minimal kids accessories in a children's bedroom. Show the room in a wide view.",
24-
prompt: "Generate a social media campaign with ad copy and an image. This is for \"Back to School\" and the audience is parents of school age children. Tone is playful and humorous. The image must have minimal kids accessories in a children's bedroom. Show the room in a wide view.",
2522
icon: SecondPromptIcon,
2623
}
2724
];
@@ -33,7 +30,7 @@ interface WelcomeCardProps {
3330

3431
export const WelcomeCard = memo(function WelcomeCard({ onSuggestionClick, currentInput = '' }: WelcomeCardProps) {
3532
const selectedIndex = useMemo(
36-
() => suggestions.findIndex(s => s.prompt === currentInput),
33+
() => suggestions.findIndex(s => s.title === currentInput),
3734
[currentInput],
3835
);
3936

@@ -99,7 +96,7 @@ export const WelcomeCard = memo(function WelcomeCard({ onSuggestionClick, curren
9996
title={suggestion.title}
10097
icon={suggestion.icon}
10198
isSelected={isSelected}
102-
onClick={() => onSuggestionClick(suggestion.prompt)}
99+
onClick={() => onSuggestionClick(suggestion.title)}
103100
/>
104101
);
105102
})}

content-gen/src/app/frontend/src/store/appSlice.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ export const fetchAppConfig = createAsyncThunk(
6161
export const fetchUserInfo = createAsyncThunk(
6262
'app/fetchUserInfo',
6363
async () => {
64-
const response = await fetch('/.auth/me');
64+
const { platformClient } = await import('../api/httpClient');
65+
const response = await platformClient.raw('/.auth/me');
6566
if (!response.ok) return { userId: 'anonymous', userName: '' };
6667

6768
const payload = await response.json();

content-gen/src/app/frontend/src/utils/contentParsing.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ function rewriteBlobUrl(url: string): string {
2525
}
2626

2727
/* ------------------------------------------------------------------ */
28-
/* Exported utilities */
28+
/* Parsing helpers (module-internal — not re-exported) */
2929
/* ------------------------------------------------------------------ */
3030

3131
/**
3232
* Parse `text_content` which may arrive as a JSON string or an object.
3333
* Returns an object with known fields, or `undefined` if unusable.
3434
*/
35-
export function parseTextContent(
35+
function parseTextContent(
3636
raw: unknown,
3737
): { headline?: string; body?: string; cta_text?: string; tagline?: string } | undefined {
3838
let textContent = raw;
@@ -64,7 +64,7 @@ export function parseTextContent(
6464
* Pass `rewriteBlobs: true` (default) when restoring from a saved
6565
* conversation; `false` when the response just came from the live API.
6666
*/
67-
export function resolveImageUrl(
67+
function resolveImageUrl(
6868
raw: { image_url?: string; image_base64?: string },
6969
rewriteBlobs = false,
7070
): string | undefined {

0 commit comments

Comments
 (0)