Skip to content

Commit 7a681c2

Browse files
committed
fix: TypeScript strict mode errors across AI prompts feature
1 parent 3935f7e commit 7a681c2

File tree

6 files changed

+23
-16
lines changed

6 files changed

+23
-16
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { z } from "zod";
22

33
// Valid section IDs that can have their collapsed state toggled
4-
export const SideMenuSectionIdSchema = z.enum(["manage", "metrics", "project-settings"]);
4+
export const SideMenuSectionIdSchema = z.enum(["ai", "manage", "metrics", "project-settings"]);
55

66
// Inferred type from the schema
77
export type SideMenuSectionId = z.infer<typeof SideMenuSectionIdSchema>;

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function extractAISummarySpanData(
6868
let messageCount: number | undefined;
6969
if (promptJson) {
7070
try {
71-
const parsed = JSON.parse(promptJson);
71+
const parsed = JSON.parse(promptJson) as Record<string, unknown>;
7272
if (parsed.messages && Array.isArray(parsed.messages)) {
7373
messageCount = parsed.messages.length;
7474
} else {
@@ -146,7 +146,7 @@ function parsePromptToDisplayItems(
146146
responseText?: string
147147
): DisplayItem[] | undefined {
148148
try {
149-
const parsed = JSON.parse(promptJson);
149+
const parsed = JSON.parse(promptJson) as Record<string, unknown>;
150150
if (!parsed || typeof parsed !== "object") return undefined;
151151

152152
const items: DisplayItem[] = [];
@@ -162,8 +162,9 @@ function parsePromptToDisplayItems(
162162
if (Array.isArray(parsed.messages)) {
163163
for (const msg of parsed.messages) {
164164
if (!msg || typeof msg !== "object") continue;
165-
const role = msg.role;
166-
const content = extractMessageContent(msg.content);
165+
const m = msg as Record<string, unknown>;
166+
const role = m.role;
167+
const content = extractMessageContent(m.content);
167168
if (!content) continue;
168169

169170
switch (role) {
@@ -196,7 +197,11 @@ function extractMessageContent(content: unknown): string | undefined {
196197
if (Array.isArray(content)) {
197198
// Extract text parts from content array [{type: "text", text: "..."}]
198199
return content
199-
.filter((p) => p && typeof p === "object" && p.type === "text" && typeof p.text === "string")
200+
.filter((p): p is { type: string; text: string } => {
201+
if (!p || typeof p !== "object") return false;
202+
const o = p as Record<string, unknown>;
203+
return o.type === "text" && typeof o.text === "string";
204+
})
200205
.map((p) => p.text)
201206
.join("\n");
202207
}
@@ -214,7 +219,7 @@ function parseProviderMetadata(
214219
if (!jsonStr) return undefined;
215220

216221
try {
217-
const parsed = JSON.parse(jsonStr);
222+
const parsed = JSON.parse(jsonStr) as Record<string, any>;
218223
if (!parsed || typeof parsed !== "object") return undefined;
219224

220225
let serviceTier: string | undefined;

apps/webapp/app/presenters/v3/PromptPresenter.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ function encodeCursor(startTime: string, spanId: string): string {
373373

374374
function decodeCursor(cursor: string): { startTime: string; spanId: string } | null {
375375
try {
376-
const parsed = JSON.parse(Buffer.from(cursor, "base64").toString("utf-8"));
376+
const parsed = JSON.parse(Buffer.from(cursor, "base64").toString("utf-8")) as Record<string, unknown>;
377377
if (typeof parsed.s === "string" && typeof parsed.i === "string") {
378378
return { startTime: parsed.s, spanId: parsed.i };
379379
}

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam/route.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ function TraceView({
509509
<div className={cn("grid h-full max-h-full grid-cols-1 overflow-hidden")}>
510510
<ResizablePanelGroup
511511
autosaveId={resizableSettings.parent.autosaveId}
512-
snapshot={resizable.parent}
512+
snapshot={resizable.parent as ResizableSnapshot}
513513
className="h-full max-h-full"
514514
>
515515
<ResizablePanel
@@ -539,7 +539,7 @@ function TraceView({
539539
rootRun={run.rootTaskRun}
540540
parentRun={run.parentTaskRun}
541541
isCompleted={run.completedAt !== null}
542-
treeSnapshot={resizable.tree}
542+
treeSnapshot={resizable.tree as ResizableSnapshot}
543543
/>
544544
</ResizablePanel>
545545
<ResizableHandle id={resizableSettings.parent.handleId} />
@@ -585,7 +585,7 @@ function NoLogsView({ run, resizable }: Pick<LoaderData, "run" | "resizable">) {
585585
<div className={cn("grid h-full max-h-full grid-cols-1 overflow-hidden")}>
586586
<ResizablePanelGroup
587587
autosaveId={resizableSettings.parent.autosaveId}
588-
snapshot={resizable.parent}
588+
snapshot={resizable.parent as ResizableSnapshot}
589589
className="h-full max-h-full"
590590
>
591591
<ResizablePanel

apps/webapp/app/v3/services/promptService.server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createHash } from "crypto";
2+
import { prisma } from "~/db.server";
23
import { BaseService, ServiceValidationError } from "./baseService.server";
34

45
export class PromptService extends BaseService {
@@ -36,7 +37,7 @@ export class PromptService extends BaseService {
3637
const nextVersion = await this.#getNextVersionNumber(promptId);
3738

3839
// Remove any existing override, then create new — wraps in transaction
39-
await this._prisma.$transaction(async (tx) => {
40+
await prisma.$transaction(async (tx) => {
4041
await tx.$executeRaw`
4142
UPDATE "prompt_versions"
4243
SET "labels" = array_remove("labels", 'override')

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,11 @@ function enrichPromptResolve(event: CreateEventInput): void {
434434

435435
if (typeof slug !== "string") return;
436436

437-
const style = event.style ?? {};
437+
const style = (event.style ?? {}) as Record<string, unknown>;
438+
const accessory = style.accessory as Record<string, unknown> | undefined;
438439
const existingItems =
439-
style.accessory && "items" in style.accessory
440-
? (style.accessory.items as Array<{ text: string; icon?: string; variant?: string }>)
440+
accessory && "items" in accessory
441+
? (accessory.items as Array<{ text: string; icon?: string; variant?: string }>)
441442
: [];
442443

443444
const items = [
@@ -452,5 +453,5 @@ function enrichPromptResolve(event: CreateEventInput): void {
452453
...style,
453454
icon: style.icon ?? "tabler-file-text-ai",
454455
accessory: { style: "pills" as const, items },
455-
};
456+
} as unknown as typeof event.style;
456457
}

0 commit comments

Comments
 (0)