Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export async function POST(
cancelled: false,
editor_name: null,
has_tools: false,
machine_id: null,
};

await insertUsageRecord(coreUsageFields, metadataFields);
Expand Down
1 change: 1 addition & 0 deletions src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ export const microdollar_usage_metadata = pgTable(
cancelled: boolean(),
editor_name_id: integer(),
has_tools: boolean(),
machine_id: text(),
},
table => [index('idx_microdollar_usage_metadata_created_at').on(table.created_at)]
);
Expand Down
3 changes: 3 additions & 0 deletions src/lib/processUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ export type UsageMetaData = {
cancelled: boolean | null;
editor_name: string | null;
has_tools: boolean | null;
machine_id: string | null;
};

export async function insertUsageRecord(
Expand Down Expand Up @@ -529,6 +530,7 @@ async function insertUsageAndMetadataWithBalanceUpdate(
streamed,
cancelled,
has_tools,
machine_id,

http_user_agent_id,
http_ip_id,
Expand Down Expand Up @@ -559,6 +561,7 @@ async function insertUsageAndMetadataWithBalanceUpdate(
${metadataFields.streamed},
${metadataFields.cancelled},
${metadataFields.has_tools},
${metadataFields.machine_id},

(SELECT http_user_agent_id FROM http_user_agent_cte),
(SELECT http_ip_id FROM http_ip_cte),
Expand Down
1 change: 1 addition & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function getFraudDetectionHeaders(headers: Headers) {
http_x_vercel_ip_longitude: parseFloatOrNull(headers.get('x-vercel-ip-longitude')),
http_x_vercel_ja4_digest: headers.get('x-vercel-ja4-digest'),
http_user_agent: headers.get('user-agent'),
machine_id: headers.get('x-kilocode-machineid'),
};
}

Expand Down
1 change: 1 addition & 0 deletions src/scripts/usage/benchmark-insert-usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ function generateRandomRecord(
cancelled: maybeNull(Math.random() < 0.05, 50),
editor_name: maybeNull(pickRandom(['vscode', 'cursor', 'windsurf', 'vim'], Math.random()), 30),
has_tools: maybeNull(Math.random() < 0.3, 20),
machine_id: maybeNull(randomString(36, 36, 36), 50),
};

return { core, metadata };
Expand Down
1 change: 1 addition & 0 deletions src/tests/helpers/microdollar-usage.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function defineDefaultContextInfo(): UsageContextInfo {
http_x_vercel_ip_latitude: 43,
http_x_vercel_ip_longitude: -79,
http_x_vercel_ja4_digest: 'normal_fingerprint',
machine_id: null,
provider: 'openrouter',
user_prompt_prefix: '<task>Implement a feature',
system_prompt_prefix: 'You are Kilo Code, a highly skilled software engineer',
Expand Down
2 changes: 2 additions & 0 deletions src/tests/stripe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ describe('ensurePaymentMethodStored', () => {
http_x_vercel_ip_longitude: -122.4194,
http_x_vercel_ja4_digest: 'test_digest',
http_user_agent: 'Mozilla/5.0 (test)',
machine_id: null,
};

const result = await ensurePaymentMethodStored(testUser.id, mockStripePaymentMethod, headers);
Expand Down Expand Up @@ -262,6 +263,7 @@ describe('ensurePaymentMethodStored', () => {
http_x_vercel_ip_longitude: null,
http_x_vercel_ja4_digest: null,
http_user_agent: null,
machine_id: null,
};

const uniquePaymentMethod = sampleStripePaymentMethod();
Expand Down
Loading