Skip to content

Commit edae68f

Browse files
robbie-cclaude
andauthored
feat(wizard): Add User-Agent header to wizard HTTP requests (#291)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 12a2a29 commit edae68f

File tree

5 files changed

+16
-1
lines changed

5 files changed

+16
-1
lines changed

src/lib/agent-interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { analytics } from '../utils/analytics';
1111
import {
1212
WIZARD_INTERACTION_EVENT_NAME,
1313
WIZARD_REMARK_EVENT_NAME,
14+
WIZARD_USER_AGENT,
1415
} from './constants';
1516
import { getLlmGatewayUrlFromHost } from '../utils/urls';
1617
import { LINTING_TOOLS } from './safe-tools';
@@ -357,6 +358,7 @@ export async function initializeAgent(
357358
url: config.posthogMcpUrl,
358359
headers: {
359360
Authorization: `Bearer ${config.posthogApiKey}`,
361+
'User-Agent': WIZARD_USER_AGENT,
360362
},
361363
},
362364
...Object.fromEntries(

src/lib/api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import axios, { AxiosError } from 'axios';
22
import { z } from 'zod';
33
import { analytics } from '../utils/analytics';
4+
import { WIZARD_USER_AGENT } from './constants';
45

56
export const ApiUserSchema = z.object({
67
distinct_id: z.string(),
@@ -48,6 +49,7 @@ export async function fetchUserData(
4849
const response = await axios.get(`${baseUrl}/api/users/@me/`, {
4950
headers: {
5051
Authorization: `Bearer ${accessToken}`,
52+
'User-Agent': WIZARD_USER_AGENT,
5153
},
5254
});
5355

@@ -71,6 +73,7 @@ export async function fetchProjectData(
7173
const response = await axios.get(`${baseUrl}/api/projects/${projectId}/`, {
7274
headers: {
7375
Authorization: `Bearer ${accessToken}`,
76+
'User-Agent': WIZARD_USER_AGENT,
7477
},
7578
});
7679

src/lib/constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,11 @@ export const OAUTH_PORT = 8239;
5757

5858
export const WIZARD_INTERACTION_EVENT_NAME = 'wizard interaction';
5959
export const WIZARD_REMARK_EVENT_NAME = 'wizard remark';
60+
61+
/**
62+
* User-Agent string for the wizard when making HTTP requests.
63+
* Used for direct PostHog API calls and passed to the MCP server
64+
* so it can identify requests originating from the wizard.
65+
*/
66+
import packageJson from '../../package.json';
67+
export const WIZARD_USER_AGENT = `posthog/wizard; version: ${packageJson.version}`;

src/utils/oauth.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import chalk from 'chalk';
55
import opn from 'opn';
66
import { z } from 'zod';
77
import clack from './clack';
8-
import { ISSUES_URL, OAUTH_PORT } from '../lib/constants';
8+
import { ISSUES_URL, OAUTH_PORT, WIZARD_USER_AGENT } from '../lib/constants';
99
import { abort } from './clack-utils';
1010
import { analytics } from './analytics';
1111
import type { CloudRegion } from './types';
@@ -187,6 +187,7 @@ async function exchangeCodeForToken(
187187
{
188188
headers: {
189189
'Content-Type': 'application/json',
190+
'User-Agent': WIZARD_USER_AGENT,
190191
},
191192
},
192193
);

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"types": ["node", "jest"],
88
"typeRoots": ["./node_modules/@types", "./types"],
99
"declaration": true,
10+
"resolveJsonModule": true,
1011
"outDir": "dist"
1112
},
1213
"include": [

0 commit comments

Comments
 (0)