Skip to content

Commit e99ab5b

Browse files
committed
fix some typescript errors
1 parent 45dc649 commit e99ab5b

File tree

10 files changed

+40
-32
lines changed

10 files changed

+40
-32
lines changed

apps/webapp/app/components/runs/v3/ai/extractAISpanData.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ function parseProviderMetadata(
426426
): { serviceTier?: string; resolvedProvider?: string; gatewayCost?: string } | undefined {
427427
if (typeof raw !== "string") return undefined;
428428
try {
429-
const parsed = JSON.parse(raw);
429+
const parsed = JSON.parse(raw) as Record<string, unknown>;
430430
if (!parsed || typeof parsed !== "object") return undefined;
431431

432432
let serviceTier: string | undefined;
@@ -469,12 +469,13 @@ function parseToolChoice(raw: unknown): string | undefined {
469469
try {
470470
const parsed = JSON.parse(raw);
471471
if (typeof parsed === "string") return parsed;
472-
if (parsed && typeof parsed === "object" && typeof parsed.type === "string") {
473-
return parsed.type;
472+
if (parsed && typeof parsed === "object") {
473+
const obj = parsed as Record<string, unknown>;
474+
if (typeof obj.type === "string") return obj.type;
474475
}
475476
return undefined;
476477
} catch {
477-
return raw || undefined;
478+
return undefined;
478479
}
479480
}
480481

apps/webapp/app/routes/admin.llm-models.$modelId.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { llmPricingRegistry } from "~/v3/llmPricingRegistry.server";
1414
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
1515
const userId = await requireUserId(request);
1616
const user = await prisma.user.findUnique({ where: { id: userId } });
17-
if (!user?.admin) return redirect("/");
17+
if (!user?.admin) throw redirect("/");
1818

1919
const model = await prisma.llmModel.findUnique({
2020
where: { friendlyId: params.modelId },
@@ -46,7 +46,7 @@ const SaveSchema = z.object({
4646
export async function action({ request, params }: ActionFunctionArgs) {
4747
const userId = await requireUserId(request);
4848
const user = await prisma.user.findUnique({ where: { id: userId } });
49-
if (!user?.admin) return redirect("/");
49+
if (!user?.admin) throw redirect("/");
5050

5151
const friendlyId = params.modelId!;
5252
const existing = await prisma.llmModel.findUnique({ where: { friendlyId } });
@@ -89,7 +89,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
8989
prices: Record<string, number>;
9090
}>;
9191
try {
92-
pricingTiers = JSON.parse(pricingTiersJson);
92+
pricingTiers = JSON.parse(pricingTiersJson) as typeof pricingTiers;
9393
} catch {
9494
return typedjson({ error: "Invalid pricing tiers JSON" }, { status: 400 });
9595
}

apps/webapp/app/routes/admin.llm-models._index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const SearchParams = z.object({
3333
export const loader = async ({ request }: LoaderFunctionArgs) => {
3434
const userId = await requireUserId(request);
3535
const user = await prisma.user.findUnique({ where: { id: userId } });
36-
if (!user?.admin) return redirect("/");
36+
if (!user?.admin) throw redirect("/");
3737

3838
const searchParams = createSearchParams(request.url, SearchParams);
3939
if (!searchParams.success) throw new Error(searchParams.error);
@@ -79,7 +79,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
7979
export async function action({ request }: ActionFunctionArgs) {
8080
const userId = await requireUserId(request);
8181
const user = await prisma.user.findUnique({ where: { id: userId } });
82-
if (!user?.admin) return redirect("/");
82+
if (!user?.admin) throw redirect("/");
8383

8484
const formData = await request.formData();
8585
const _action = formData.get("_action");

apps/webapp/app/routes/admin.llm-models.missing.$model.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
1515
const userId = await requireUserId(request);
1616
const user = await prisma.user.findUnique({ where: { id: userId } });
17-
if (!user?.admin) return redirect("/");
17+
if (!user?.admin) throw redirect("/");
1818

1919
// Model name is URL-encoded in the URL param
2020
const modelName = decodeURIComponent(params.model ?? "");
@@ -142,7 +142,7 @@ export default function AdminMissingModelDetailRoute() {
142142
</span>
143143
<div className="flex gap-4 mt-1 font-mono text-text-bright">
144144
<span>input: {providerCosts[0].estimatedInputPrice.toExponential(4)}</span>
145-
<span>output: {providerCosts[0].estimatedOutputPrice ?? 0.toExponential(4)}</span>
145+
<span>output: {(providerCosts[0].estimatedOutputPrice ?? 0).toExponential(4)}</span>
146146
</div>
147147
<span className="text-text-dimmed mt-1 block">
148148
Cross-reference with the provider's pricing page before using these estimates.
@@ -176,7 +176,7 @@ export default function AdminMissingModelDetailRoute() {
176176
const expanded = expandedSpans.has(s.span_id);
177177
let parsedAttrs: Record<string, unknown> | null = null;
178178
try {
179-
parsedAttrs = JSON.parse(s.attributes_text);
179+
parsedAttrs = JSON.parse(s.attributes_text) as Record<string, unknown>;
180180
} catch {
181181
// ignore
182182
}
@@ -226,7 +226,7 @@ function extractTokenTypes(samples: MissingModelSample[]): TokenTypeSummary[] {
226226
for (const s of samples) {
227227
let attrs: Record<string, unknown>;
228228
try {
229-
attrs = JSON.parse(s.attributes_text);
229+
attrs = JSON.parse(s.attributes_text) as Record<string, unknown>;
230230
} catch {
231231
continue;
232232
}
@@ -300,7 +300,7 @@ function extractProviderCosts(samples: MissingModelSample[]): ProviderCostInfo[]
300300
for (const s of samples) {
301301
let attrs: Record<string, unknown>;
302302
try {
303-
attrs = JSON.parse(s.attributes_text);
303+
attrs = JSON.parse(s.attributes_text) as Record<string, unknown>;
304304
} catch {
305305
continue;
306306
}
@@ -310,7 +310,7 @@ function extractProviderCosts(samples: MissingModelSample[]): ProviderCostInfo[]
310310
const aiResponse = getNestedObj(attrs, ["ai", "response"]);
311311
const rawMeta = aiResponse?.providerMetadata;
312312
if (typeof rawMeta === "string") {
313-
try { providerMeta = JSON.parse(rawMeta); } catch {}
313+
try { providerMeta = JSON.parse(rawMeta) as Record<string, unknown>; } catch {}
314314
} else if (rawMeta && typeof rawMeta === "object") {
315315
providerMeta = rawMeta as Record<string, unknown>;
316316
}
@@ -390,13 +390,15 @@ function buildPrompt(modelName: string, samples: MissingModelSample[], providerC
390390
let sampleAttrs = "";
391391
if (samples.length > 0) {
392392
try {
393-
const attrs = JSON.parse(samples[0].attributes_text);
393+
const attrs = JSON.parse(samples[0].attributes_text) as Record<string, unknown>;
394+
const ai = attrs.ai as Record<string, unknown> | undefined;
395+
const aiResponse = (ai?.response ?? {}) as Record<string, unknown>;
394396
// Extract just the relevant fields
395397
const compact: Record<string, unknown> = {};
396398
if (attrs.gen_ai) compact.gen_ai = attrs.gen_ai;
397-
if (attrs.ai?.usage) compact["ai.usage"] = attrs.ai.usage;
398-
if (attrs.ai?.response?.providerMetadata) {
399-
compact["ai.response.providerMetadata"] = attrs.ai.response.providerMetadata;
399+
if (ai?.usage) compact["ai.usage"] = ai.usage;
400+
if (aiResponse.providerMetadata) {
401+
compact["ai.response.providerMetadata"] = aiResponse.providerMetadata;
400402
}
401403
sampleAttrs = JSON.stringify(compact, null, 2);
402404
} catch {
@@ -457,7 +459,7 @@ The gateway/router is reporting costs for this model. Use these to cross-referen
457459
${providerCosts.map((c) => `- $${c.cost.toFixed(6)} for ${c.inputTokens.toLocaleString()} input + ${c.outputTokens.toLocaleString()} output tokens`).join("\n")}${providerCosts[0].estimatedInputPrice != null ? `
458460
- Estimated per-token rates (rough, assuming ~3x output/input ratio):
459461
- input: ${providerCosts[0].estimatedInputPrice.toExponential(4)} (${(providerCosts[0].estimatedInputPrice * 1_000_000).toFixed(4)} $/M)
460-
- output: ${providerCosts[0].estimatedOutputPrice ?? 0.toExponential(4)} (${(providerCosts[0].estimatedOutputPrice ?? 0 * 1_000_000).toFixed(4)} $/M)
462+
- output: ${(providerCosts[0].estimatedOutputPrice ?? 0).toExponential(4)} (${((providerCosts[0].estimatedOutputPrice ?? 0) * 1_000_000).toFixed(4)} $/M)
461463
- Verify these against the official pricing page before using.` : ""}` : ""}${sampleAttrs ? `
462464
463465
## Sample span attributes (first span)

apps/webapp/app/routes/admin.llm-models.missing._index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const SearchParams = z.object({
3333
export const loader = async ({ request }: LoaderFunctionArgs) => {
3434
const userId = await requireUserId(request);
3535
const user = await prisma.user.findUnique({ where: { id: userId } });
36-
if (!user?.admin) return redirect("/");
36+
if (!user?.admin) throw redirect("/");
3737

3838
const url = new URL(request.url);
3939
const lookbackHours = parseInt(url.searchParams.get("lookbackHours") ?? "24", 10);

apps/webapp/app/routes/admin.llm-models.new.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { llmPricingRegistry } from "~/v3/llmPricingRegistry.server";
1414
export const loader = async ({ request }: LoaderFunctionArgs) => {
1515
const userId = await requireUserId(request);
1616
const user = await prisma.user.findUnique({ where: { id: userId } });
17-
if (!user?.admin) return redirect("/");
17+
if (!user?.admin) throw redirect("/");
1818
return typedjson({});
1919
};
2020

@@ -27,7 +27,7 @@ const CreateSchema = z.object({
2727
export async function action({ request }: ActionFunctionArgs) {
2828
const userId = await requireUserId(request);
2929
const user = await prisma.user.findUnique({ where: { id: userId } });
30-
if (!user?.admin) return redirect("/");
30+
if (!user?.admin) throw redirect("/");
3131

3232
const formData = await request.formData();
3333
const raw = Object.fromEntries(formData);
@@ -57,7 +57,7 @@ export async function action({ request }: ActionFunctionArgs) {
5757
prices: Record<string, number>;
5858
}>;
5959
try {
60-
pricingTiers = JSON.parse(pricingTiersJson);
60+
pricingTiers = JSON.parse(pricingTiersJson) as typeof pricingTiers;
6161
} catch {
6262
return typedjson({ error: "Invalid pricing tiers JSON" }, { status: 400 });
6363
}

apps/webapp/app/services/admin/missingLlmModels.server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ export async function getMissingLlmModels(opts: {
7070

7171
// Filter out models that now have pricing in the database (added after spans were inserted).
7272
// The registry's match() handles prefix stripping for gateway/openrouter models.
73-
if (!llmPricingRegistry?.isLoaded) return candidates;
74-
return candidates.filter((c) => !llmPricingRegistry.match(c.model));
73+
if (!llmPricingRegistry || !llmPricingRegistry.isLoaded) return candidates;
74+
const registry = llmPricingRegistry;
75+
return candidates.filter((c) => !registry.match(c.model));
7576
}
7677

7778
export type MissingModelSample = {

apps/webapp/app/v3/utils/enrichCreatableEvents.server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ function enrichLlmCost(event: CreateEventInput): void {
126126
}
127127

128128
event.style = {
129-
...event.style,
129+
...(event.style as Record<string, unknown> | undefined),
130130
accessory: {
131131
style: "pills",
132132
items: pillItems,
133133
},
134-
};
134+
} as unknown as typeof event.style;
135135

136136
// Only write llm_usage when cost data is available
137137
if (!cost && !providerCost) return;
@@ -270,7 +270,7 @@ function extractProviderCost(
270270

271271
let meta: Record<string, unknown>;
272272
try {
273-
meta = JSON.parse(rawMeta);
273+
meta = JSON.parse(rawMeta) as Record<string, unknown>;
274274
} catch {
275275
return null;
276276
}

internal-packages/llm-pricing/src/registry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PrismaClient } from "@trigger.dev/database";
1+
import type { PrismaClient, PrismaReplicaClient } from "@trigger.dev/database";
22
import type {
33
LlmModelWithPricing,
44
LlmCostResult,
@@ -20,12 +20,12 @@ function compilePattern(pattern: string): RegExp {
2020
}
2121

2222
export class ModelPricingRegistry {
23-
private _prisma: PrismaClient;
23+
private _prisma: PrismaClient | PrismaReplicaClient;
2424
private _patterns: CompiledPattern[] = [];
2525
private _exactMatchCache: Map<string, LlmModelWithPricing | null> = new Map();
2626
private _loaded = false;
2727

28-
constructor(prisma: PrismaClient) {
28+
constructor(prisma: PrismaClient | PrismaReplicaClient) {
2929
this._prisma = prisma;
3030
}
3131

internal-packages/tsql/src/query/schema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export type ClickHouseType =
2323
| "Date32"
2424
| "DateTime"
2525
| "DateTime64"
26+
| "DateTime64(3)"
27+
| "DateTime64(9)"
28+
| "Decimal64(12)"
2629
| "UUID"
2730
| "Bool"
2831
| "JSON"
@@ -281,6 +284,7 @@ export type ColumnFormatType =
281284
| "runId"
282285
| "runStatus"
283286
| "duration"
287+
| "durationNs"
284288
| "durationSeconds"
285289
| "costInDollars"
286290
| "cost"

0 commit comments

Comments
 (0)