Skip to content

Commit 6ed6ec3

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 b0225a0 commit 6ed6ec3

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
})
@@ -516,10 +517,12 @@ export async function requestChatTitle(params: {
516517
provider?: string
517518
userId?: string
518519
workspaceId?: string
520+
chatId?: string
519521
billingAttribution?: BillingAttributionSnapshot
520522
otelContext?: Context
521523
}): Promise<string | null> {
522-
const { message, model, provider, userId, workspaceId, billingAttribution, otelContext } = params
524+
const { message, model, provider, userId, workspaceId, chatId, billingAttribution, otelContext } =
525+
params
523526
if (!message || !model) return null
524527

525528
const headers = mothershipRequestHeaders()
@@ -550,6 +553,10 @@ export async function requestChatTitle(params: {
550553
body: JSON.stringify({
551554
message,
552555
...(byokApiKey ? { byokApiKey } : {}),
556+
// Metering identity: the worker records title spend into run_analytics.
557+
...(chatId ? { chatId } : {}),
558+
...(workspaceId ? { workspaceId } : {}),
559+
...(userId ? { userId } : {}),
553560
}),
554561
otelContext,
555562
spanName: 'sim → go /api/generate-chat-title',

0 commit comments

Comments
 (0)