Skip to content

Commit 2410480

Browse files
msukkariclaude
andcommitted
refactor(web): rename distinctId to userId in ToolContext
The field carries a user ID, not a PostHog-specific concept. The captureEvent options parameter remains distinctId since that's the PostHog term, but the application-level interfaces use userId. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent df7c298 commit 2410480

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

packages/web/src/app/api/(server)/chat/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const POST = apiHandler(async (req: NextRequest) => {
112112
modelName: languageModelConfig.displayName ?? languageModelConfig.model,
113113
modelProviderOptions: providerOptions,
114114
modelTemperature: temperature,
115-
distinctId: user?.id,
115+
userId: user?.id,
116116
onFinish: async ({ messages }) => {
117117
await updateChatMessages({ chatId: id, messages, prisma });
118118
},

packages/web/src/features/chat/agent.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ interface CreateMessageStreamResponseProps {
4343
modelProviderOptions?: Record<string, Record<string, JSONValue>>;
4444
modelTemperature?: number;
4545
metadata?: Partial<SBChatMessageMetadata>;
46-
/** PostHog distinct ID for telemetry attribution on tool_used events. */
47-
distinctId?: string;
46+
/** User ID for telemetry attribution on tool_used events. */
47+
userId?: string;
4848
}
4949

5050
export const createMessageStream = async ({
@@ -58,7 +58,7 @@ export const createMessageStream = async ({
5858
modelTemperature,
5959
onFinish,
6060
onError,
61-
distinctId,
61+
userId,
6262
}: CreateMessageStreamResponseProps) => {
6363
const latestMessage = messages[messages.length - 1];
6464
const sources = latestMessage.parts
@@ -104,7 +104,7 @@ export const createMessageStream = async ({
104104
inputMessages: messageHistory,
105105
inputSources: sources,
106106
selectedRepos,
107-
distinctId,
107+
userId,
108108
onWriteSource: (source) => {
109109
writer.write({
110110
type: 'data-source',
@@ -158,7 +158,7 @@ interface AgentOptions {
158158
onWriteSource: (source: Source) => void;
159159
traceId: string;
160160
chatId: string;
161-
distinctId?: string;
161+
userId?: string;
162162
}
163163

164164
const createAgentStream = async ({
@@ -171,7 +171,7 @@ const createAgentStream = async ({
171171
onWriteSource,
172172
traceId,
173173
chatId,
174-
distinctId,
174+
userId,
175175
}: AgentOptions) => {
176176
// For every file source, resolve the source code so that we can include it in the system prompt.
177177
const fileSources = inputSources.filter((source) => source.type === 'file');
@@ -208,7 +208,7 @@ const createAgentStream = async ({
208208
providerOptions,
209209
messages: inputMessages,
210210
system: systemPrompt,
211-
tools: createTools({ source: 'sourcebot-ask-agent', selectedRepos, distinctId }),
211+
tools: createTools({ source: 'sourcebot-ask-agent', selectedRepos, userId }),
212212
temperature: temperature ?? env.SOURCEBOT_CHAT_MODEL_TEMPERATURE,
213213
stopWhen: [
214214
stepCountIsGTE(env.SOURCEBOT_CHAT_MAX_STEP_COUNT),

packages/web/src/features/mcp/askCodebase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export const askCodebase = (params: AskCodebaseParams): Promise<AskCodebaseResul
159159
modelName,
160160
modelProviderOptions: providerOptions,
161161
modelTemperature: temperature,
162-
distinctId: user?.id,
162+
userId: user?.id,
163163
onFinish: async ({ messages }) => {
164164
finalMessages = messages;
165165
},

packages/web/src/features/mcp/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export async function createMcpServer(options?: { userId?: string }): Promise<Mc
3737

3838
const toolContext: ToolContext = {
3939
source: 'sourcebot-mcp-server',
40-
distinctId: options?.userId,
40+
userId: options?.userId,
4141
}
4242

4343
registerMcpTool(server, grepDefinition, toolContext);

packages/web/src/features/tools/adapters.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function toVercelAITool<TName extends string, TShape extends z.ZodRawShap
2525
toolName: def.name,
2626
source: context.source ?? 'unknown',
2727
success,
28-
}, { distinctId: context.distinctId }).catch((error) => {
28+
}, { distinctId: context.userId }).catch((error) => {
2929
logger.warn(`Failed to capture tool_used event for ${def.name}:`, error);
3030
});
3131
}
@@ -63,7 +63,7 @@ export function registerMcpTool<TName extends string, TShape extends z.ZodRawSha
6363
toolName: def.name,
6464
source: context.source ?? 'unknown',
6565
success: true,
66-
}, { distinctId: context.distinctId }).catch((error) => {
66+
}, { distinctId: context.userId }).catch((error) => {
6767
logger.warn(`Failed to capture tool_used event for ${def.name}:`, error);
6868
});
6969
return { content: [{ type: "text" as const, text: result.output }] };
@@ -72,7 +72,7 @@ export function registerMcpTool<TName extends string, TShape extends z.ZodRawSha
7272
toolName: def.name,
7373
source: context.source ?? 'unknown',
7474
success: false,
75-
}, { distinctId: context.distinctId }).catch((error) => {
75+
}, { distinctId: context.userId }).catch((error) => {
7676
logger.warn(`Failed to capture tool_used event for ${def.name}:`, error);
7777
});
7878
const message = error instanceof Error ? error.message : String(error);

packages/web/src/features/tools/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export type Source = z.infer<typeof sourceSchema>;
1717
export interface ToolContext {
1818
source?: string;
1919
selectedRepos?: string[];
20-
/** PostHog distinct ID for telemetry attribution. When set, tool_used events will be attributed to this user. */
21-
distinctId?: string;
20+
/** User ID for telemetry attribution. When set, tool_used events will be attributed to this user. */
21+
userId?: string;
2222
}
2323

2424
export interface ToolDefinition<

0 commit comments

Comments
 (0)