feat(ops): logga gemini_usage per scan (best-effort)
This commit is contained in:
@@ -82,6 +82,19 @@ export async function processScanJob(ctx: WorkerContext, scanJobId: string): Pro
|
|||||||
|
|
||||||
await recordScanCompleted(ctx, job, result);
|
await recordScanCompleted(ctx, job, result);
|
||||||
|
|
||||||
|
// Logga token-telemetri för Gemini (best-effort, får aldrig faila scan-vägen).
|
||||||
|
try {
|
||||||
|
await ctx.db.insert(schema.geminiUsage).values({
|
||||||
|
taskType: job.jobType,
|
||||||
|
promptTokens: result.inputTokens ?? null,
|
||||||
|
outputTokens: result.outputTokens ?? null,
|
||||||
|
totalTokens: result.totalTokens ?? null,
|
||||||
|
costMicrocents: result.costUsd != null ? Math.round(result.costUsd * 100_000_000) : null,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error("[scan processor] gemini_usage logging misslyckades:", err);
|
||||||
|
}
|
||||||
|
|
||||||
// Shadow-capture: spara träningspar för framtida AAMOS-distillation (FAS 1).
|
// Shadow-capture: spara träningspar för framtida AAMOS-distillation (FAS 1).
|
||||||
// Kör aldrig synkront på användarens kritiska väg; fel swallås.
|
// Kör aldrig synkront på användarens kritiska väg; fel swallås.
|
||||||
if (result.status === "ok" && result.output != null) {
|
if (result.status === "ok" && result.output != null) {
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
ALTER TABLE "gemini_usage" ALTER COLUMN "prompt_tokens" DROP NOT NULL;--> statement-breakpoint
|
||||||
|
ALTER TABLE "gemini_usage" ALTER COLUMN "output_tokens" DROP NOT NULL;--> statement-breakpoint
|
||||||
|
ALTER TABLE "gemini_usage" ALTER COLUMN "total_tokens" DROP NOT NULL;
|
||||||
@@ -9,8 +9,8 @@ export const geminiUsage = pgTable("gemini_usage", {
|
|||||||
id: uuid("id").primaryKey().defaultRandom(),
|
id: uuid("id").primaryKey().defaultRandom(),
|
||||||
createdAt: createdAt(),
|
createdAt: createdAt(),
|
||||||
taskType: text("task_type").notNull(),
|
taskType: text("task_type").notNull(),
|
||||||
promptTokens: integer("prompt_tokens").notNull(),
|
promptTokens: integer("prompt_tokens"),
|
||||||
outputTokens: integer("output_tokens").notNull(),
|
outputTokens: integer("output_tokens"),
|
||||||
totalTokens: integer("total_tokens").notNull(),
|
totalTokens: integer("total_tokens"),
|
||||||
costMicrocents: bigint("cost_microcents", { mode: "number" }),
|
costMicrocents: bigint("cost_microcents", { mode: "number" }),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user