Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 additions & 0 deletions apps/gateway/src/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,7 @@ chat.openapi(completions, async (c) => {
source,
customHeaders,
debugMode,
image_config,
routingMetadata,
rawBody,
rawCachedResponseData, // Raw SSE data from cached response
Expand Down Expand Up @@ -1911,6 +1912,7 @@ chat.openapi(completions, async (c) => {
source,
customHeaders,
debugMode,
image_config,
routingMetadata,
rawBody,
cachedResponse,
Expand Down Expand Up @@ -2183,6 +2185,7 @@ chat.openapi(completions, async (c) => {
source,
customHeaders,
debugMode,
image_config,
routingMetadata,
rawBody,
null, // No response for canceled request
Expand Down Expand Up @@ -2266,6 +2269,7 @@ chat.openapi(completions, async (c) => {
source,
customHeaders,
debugMode,
image_config,
routingMetadata,
rawBody,
null, // No response for fetch error
Expand Down Expand Up @@ -2416,6 +2420,7 @@ chat.openapi(completions, async (c) => {
source,
customHeaders,
debugMode,
image_config,
routingMetadata,
rawBody,
null, // No response for error case
Expand Down Expand Up @@ -3467,6 +3472,7 @@ chat.openapi(completions, async (c) => {
source,
customHeaders,
debugMode,
image_config,
routingMetadata,
rawBody,
streamingError
Expand Down Expand Up @@ -3685,6 +3691,7 @@ chat.openapi(completions, async (c) => {
source,
customHeaders,
debugMode,
image_config,
routingMetadata,
rawBody,
null, // No response for fetch error
Expand Down Expand Up @@ -3773,6 +3780,7 @@ chat.openapi(completions, async (c) => {
source,
customHeaders,
debugMode,
image_config,
routingMetadata,
rawBody,
null, // No response for canceled request
Expand Down Expand Up @@ -3866,6 +3874,7 @@ chat.openapi(completions, async (c) => {
source,
customHeaders,
debugMode,
image_config,
routingMetadata,
rawBody,
errorResponseText, // Our formatted error response
Expand Down Expand Up @@ -4101,6 +4110,7 @@ chat.openapi(completions, async (c) => {
source,
customHeaders,
debugMode,
image_config,
routingMetadata,
rawBody,
transformedResponse, // Our formatted response that we return to user
Expand Down
10 changes: 10 additions & 0 deletions apps/gateway/src/chat/tools/create-log-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export function createLogEntry(
source: string | undefined,
customHeaders: Record<string, string>,
debugMode: boolean,
imageConfig?:
| {
aspect_ratio?: string;
image_size?: string;
}
| undefined,
routingMetadata?: RoutingMetadata,
rawRequest?: unknown,
rawResponse?: unknown,
Expand Down Expand Up @@ -64,6 +70,10 @@ export function createLogEntry(
mode: project.mode,
source: source || null,
customHeaders: Object.keys(customHeaders).length > 0 ? customHeaders : null,
params:
imageConfig?.aspect_ratio || imageConfig?.image_size
? { image_config: imageConfig }
: null,
routingMetadata: routingMetadata || null,
traceId,
// Only include raw payloads if x-debug header is set to true
Expand Down
42 changes: 42 additions & 0 deletions apps/ui/src/components/dashboard/log-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,40 @@ export function LogCard({ log }: { log: Partial<Log> }) {
return `${(ms / 1000).toFixed(2)}s`;
};

// Recursively render params object
const renderParams = (
obj: Record<string, any>,
depth = 0,
): React.ReactNode => {
return Object.entries(obj).map(([key, value]) => {
const formattedKey = key
.replace(/_/g, " ")
.replace(/\b\w/g, (l) => l.toUpperCase());

if (value === null || value === undefined) {
return null;
}

if (typeof value === "object" && !Array.isArray(value)) {
return (
<div key={key} className="contents">
<div className="text-muted-foreground col-span-2 font-medium mt-2 first:mt-0">
{formattedKey}
</div>
{renderParams(value, depth + 1)}
</div>
);
}

return (
<div key={key} className="contents">
<div className="text-muted-foreground">{formattedKey}</div>
<div>{Array.isArray(value) ? value.join(", ") : String(value)}</div>
</div>
);
});
};
Comment on lines +50 to +77

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Replace any type and remove unused parameter.

Two issues with this function:

  1. The use of Record<string, any> violates the coding guideline that prohibits any types unless absolutely necessary. Replace with Record<string, unknown> for better type safety.

  2. The depth parameter is declared but never used in the function logic.

Apply this diff:

-	const renderParams = (
-		obj: Record<string, any>,
-		depth = 0,
-	): React.ReactNode => {
+	const renderParams = (obj: Record<string, unknown>): React.ReactNode => {
 		return Object.entries(obj).map(([key, value]) => {
 			const formattedKey = key
 				.replace(/_/g, " ")
 				.replace(/\b\w/g, (l) => l.toUpperCase());

 			if (value === null || value === undefined) {
 				return null;
 			}

 			if (typeof value === "object" && !Array.isArray(value)) {
 				return (
 					<div key={key} className="contents">
 						<div className="text-muted-foreground col-span-2 font-medium mt-2 first:mt-0">
 							{formattedKey}
 						</div>
-						{renderParams(value, depth + 1)}
+						{renderParams(value as Record<string, unknown>)}
 					</div>
 				);
 			}

 			return (
 				<div key={key} className="contents">
 					<div className="text-muted-foreground">{formattedKey}</div>
 					<div>{Array.isArray(value) ? value.join(", ") : String(value)}</div>
 				</div>
 			);
 		});
 	};

As per coding guidelines, avoid any types in TypeScript code.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Recursively render params object
const renderParams = (
obj: Record<string, any>,
depth = 0,
): React.ReactNode => {
return Object.entries(obj).map(([key, value]) => {
const formattedKey = key
.replace(/_/g, " ")
.replace(/\b\w/g, (l) => l.toUpperCase());
if (value === null || value === undefined) {
return null;
}
if (typeof value === "object" && !Array.isArray(value)) {
return (
<div key={key} className="contents">
<div className="text-muted-foreground col-span-2 font-medium mt-2 first:mt-0">
{formattedKey}
</div>
{renderParams(value, depth + 1)}
</div>
);
}
return (
<div key={key} className="contents">
<div className="text-muted-foreground">{formattedKey}</div>
<div>{Array.isArray(value) ? value.join(", ") : String(value)}</div>
</div>
);
});
};
// Recursively render params object
const renderParams = (obj: Record<string, unknown>): React.ReactNode => {
return Object.entries(obj).map(([key, value]) => {
const formattedKey = key
.replace(/_/g, " ")
.replace(/\b\w/g, (l) => l.toUpperCase());
if (value === null || value === undefined) {
return null;
}
if (typeof value === "object" && !Array.isArray(value)) {
return (
<div key={key} className="contents">
<div className="text-muted-foreground col-span-2 font-medium mt-2 first:mt-0">
{formattedKey}
</div>
{renderParams(value as Record<string, unknown>)}
</div>
);
}
return (
<div key={key} className="contents">
<div className="text-muted-foreground">{formattedKey}</div>
<div>{Array.isArray(value) ? value.join(", ") : String(value)}</div>
</div>
);
});
};
🤖 Prompt for AI Agents
In apps/ui/src/components/dashboard/log-card.tsx around lines 50 to 82, replace
the permissive any type and remove the unused depth parameter: change the
function signature to accept obj: Record<string, unknown> (drop the depth
parameter), update runtime checks to guard against null (e.g. typeof value ===
"object" && value !== null && !Array.isArray(value)) and when recursing cast the
value to Record<string, unknown> (or narrow it) before passing to renderParams;
ensure return types stay the same and remove any references to depth.


// Determine status icon and color based on error status or unified finish reason
let StatusIcon = CheckCircle2;
let color = "text-green-500";
Expand Down Expand Up @@ -602,6 +636,14 @@ export function LogCard({ log }: { log: Partial<Log> }) {
</TooltipProvider>
</div>
</div>
{log.params && Object.keys(log.params).length > 0 && (
<div className="space-y-2">
<h4 className="text-sm font-medium">Additional Parameters</h4>
<div className="grid grid-cols-2 gap-2 rounded-md border p-3 text-sm">
{renderParams(log.params)}
</div>
</div>
)}
{(log.tools || log.toolChoice || log.toolResults) && (
<div className="space-y-2">
<h4 className="text-sm font-medium">Tool Information</h4>
Expand Down
1 change: 1 addition & 0 deletions packages/db/migrations/1764175966_dear_silvermane.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "log" ADD COLUMN "params" json;
Loading