Skip to content

Commit 63fdec9

Browse files
committed
fix(mothership): title calls carry metering identity for worker-side billing
Companion to worker batch D. The worker now records title spend into run_analytics and settles it under the billing headers this call already stamps; chatId/workspaceId/userId ride the payload so the row joins to the chat instead of synthetic ids. Regenerated protocol mirror. Claude-Session: https://claude.ai/code/session_01CgaxNAaeD3taGdghbXn17w
1 parent 6dc3a6c commit 63fdec9

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎apps/sim/lib/mothership/generated/protocol.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ export interface TitleRequest {
9696
message: string;
9797
/** Enterprise BYOK: the title call reads user content, so it pins the same key (S27). */
9898
byokApiKey?: string | undefined;
99+
/** Metering identity (Go metered title spend into request analytics): optional so
100+
* older sim builds keep validating; absent values degrade to synthetic ids. */
101+
chatId?: string | undefined;
102+
workspaceId?: string | undefined;
103+
userId?: string | undefined;
99104
}
100105

101106
/** The 409 body for a duplicate send while a sibling instance streams (S32). */

‎apps/sim/lib/mothership/request/lifecycle/start.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ function fireTitleGeneration(params: {
485485
provider: titleProvider,
486486
userId,
487487
workspaceId,
488+
chatId,
488489
billingAttribution,
489490
otelContext,
490491
})
@@ -526,10 +527,12 @@ export async function requestChatTitle(params: {
526527
provider?: string
527528
userId?: string
528529
workspaceId?: string
530+
chatId?: string
529531
billingAttribution?: BillingAttributionSnapshot
530532
otelContext?: Context
531533
}): Promise<string | null> {
532-
const { message, model, provider, userId, workspaceId, billingAttribution, otelContext } = params
534+
const { message, model, provider, userId, workspaceId, chatId, billingAttribution, otelContext } =
535+
params
533536
if (!message || !model) return null
534537

535538
const headers = mothershipRequestHeaders()
@@ -560,6 +563,10 @@ export async function requestChatTitle(params: {
560563
body: JSON.stringify({
561564
message,
562565
...(byokApiKey ? { byokApiKey } : {}),
566+
// Metering identity: the worker records title spend into run_analytics.
567+
...(chatId ? { chatId } : {}),
568+
...(workspaceId ? { workspaceId } : {}),
569+
...(userId ? { userId } : {}),
563570
}),
564571
otelContext,
565572
spanName: 'sim → go /api/generate-chat-title',

0 commit comments

Comments
 (0)