Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

refactor(agent): Enable more eslint rules (#14847)

Ben Bachem5e7fd8955413
diff --git a/web/eslint.config.mjs b/web/eslint.config.mjs
index 89fb96ed87..3a6b6abb2a 100644
--- a/web/eslint.config.mjs
+++ b/web/eslint.config.mjs
@@ -110,6 +110,14 @@ export default [
name: "langfuse/web/in-app-agent",
files: ["src/ee/features/in-app-agent/**/*.{ts,tsx}"],
rules: {
+ "@typescript-eslint/consistent-type-definitions": ["warn", "type"],
+ "@typescript-eslint/no-confusing-void-expression": "warn",
+ "@typescript-eslint/no-non-null-assertion": "warn",
+ "@typescript-eslint/no-meaningless-void-operator": "warn",
+ "@typescript-eslint/no-invalid-void-type": "warn",
+ "@typescript-eslint/no-unsafe-assignment": "warn",
+ "@typescript-eslint/return-await": ["warn", "in-try-catch"],
+ curly: ["error", "all"],
"@repo/no-switch-statements": "error",
},
},
diff --git a/web/src/ee/features/in-app-agent/components/ControlledInAppAgentWindow.tsx b/web/src/ee/features/in-app-agent/components/ControlledInAppAgentWindow.tsx
index 4d3b6e1bf0..f831fecb5a 100644
--- a/web/src/ee/features/in-app-agent/components/ControlledInAppAgentWindow.tsx
+++ b/web/src/ee/features/in-app-agent/components/ControlledInAppAgentWindow.tsx
@@ -79,7 +79,9 @@ export function ControlledInAppAgentWindow(
onOpenConversationHistory={invalidateConversations}
onDeleteConversation={props.onDeleteConversation}
onSelectConversation={selectConversation}
- onNewConversation={() => selectConversation(null)}
+ onNewConversation={() => {
+ selectConversation(null);
+ }}
onExpandedChange={props.onExpandedChange}
onSubmit={submit}
onApproveToolCall={approveToolCall}
diff --git a/web/src/ee/features/in-app-agent/components/InAppAgentMessage.tsx b/web/src/ee/features/in-app-agent/components/InAppAgentMessage.tsx
index 663333ca46..92565f3598 100644
--- a/web/src/ee/features/in-app-agent/components/InAppAgentMessage.tsx
+++ b/web/src/ee/features/in-app-agent/components/InAppAgentMessage.tsx
@@ -398,7 +398,9 @@ function MessageFeedbackControls({
label="Good response"
isSelected={selectedValue === "thumbs_up"}
disabled={isDisabled}
- onClick={() => handleSelectFeedback("thumbs_up")}
+ onClick={() => {
+ handleSelectFeedback("thumbs_up");
+ }}
>
<ThumbsUp
className={cn(
@@ -412,7 +414,9 @@ function MessageFeedbackControls({
label="Bad response"
isSelected={selectedValue === "thumbs_down"}
disabled={isDisabled}
- onClick={() => handleSelectFeedback("thumbs_down")}
+ onClick={() => {
+ handleSelectFeedback("thumbs_down");
+ }}
>
<ThumbsDown
className={cn(
@@ -427,7 +431,9 @@ function MessageFeedbackControls({
className="text-muted-foreground hover:text-foreground ml-1 min-w-0 flex-1 truncate text-left text-xs disabled:cursor-not-allowed disabled:opacity-60"
title={commentButtonText}
disabled={isDisabled}
- onClick={() => setIsCommentPopoverOpen(true)}
+ onClick={() => {
+ setIsCommentPopoverOpen(true);
+ }}
>
{commentButtonText}
</button>
@@ -441,7 +447,9 @@ function MessageFeedbackControls({
<div>
<textarea
value={comment}
- onChange={(event) => setComment(event.target.value)}
+ onChange={(event) => {
+ setComment(event.target.value);
+ }}
disabled={isDisabled}
placeholder="Optional feedback comment"
rows={3}
@@ -833,7 +841,9 @@ function getSelectedMarkdownFromSource(
htmlContainer.append(range.cloneContents());
htmlContainer
.querySelectorAll("[data-in-app-agent-code-copy-button]")
- .forEach((node) => node.remove());
+ .forEach((node) => {
+ node.remove();
+ });
return {
markdown: selectedMarkdown,
diff --git a/web/src/ee/features/in-app-agent/components/InAppAgentWindow.stories.tsx b/web/src/ee/features/in-app-agent/components/InAppAgentWindow.stories.tsx
index d88b2679cd..f03761adc3 100644
--- a/web/src/ee/features/in-app-agent/components/InAppAgentWindow.stories.tsx
+++ b/web/src/ee/features/in-app-agent/components/InAppAgentWindow.stories.tsx
@@ -360,7 +360,9 @@ function StreamingInAppAgentWindow(args: InAppAgentWindowProps) {
);
}, 140);
- return () => window.clearInterval(intervalId);
+ return () => {
+ window.clearInterval(intervalId);
+ };
}, []);
return (
diff --git a/web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx b/web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx
index 8cf5f53354..bccc18232c 100644
--- a/web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx
+++ b/web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx
@@ -189,9 +189,9 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {
currentInput.trim() === trimmedContent ? "" : currentInput,
);
- window.requestAnimationFrame(() =>
- scrollViewportToBottom(viewportRef.current),
- );
+ window.requestAnimationFrame(() => {
+ scrollViewportToBottom(viewportRef.current);
+ });
}
})
.catch(() => undefined);
@@ -329,7 +329,9 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {
conversation.id === selectedConversationId &&
"bg-accent text-accent-foreground",
)}
- onSelect={() => onSelectConversation(conversation.id)}
+ onSelect={() => {
+ onSelectConversation(conversation.id);
+ }}
>
<span
className="min-w-0 flex-1 truncate"
@@ -378,7 +380,9 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {
size="icon"
className="size-6"
aria-label={isExpanded ? "Collapse window" : "Expand window"}
- onClick={() => onExpandedChange(!isExpanded)}
+ onClick={() => {
+ onExpandedChange(!isExpanded);
+ }}
>
{isExpanded ? (
<Minimize2 className="size-3" />
@@ -467,7 +471,9 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {
: "rounded-xl px-2 py-1.5",
)}
disabled={isInputDisabled}
- onClick={() => submitInput(message)}
+ onClick={() => {
+ submitInput(message);
+ }}
>
{label}
</button>
@@ -595,7 +601,9 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {
autoFocus={!isExpanded}
ref={inputRef}
value={input}
- onChange={(event) => setInput(event.target.value)}
+ onChange={(event) => {
+ setInput(event.target.value);
+ }}
onKeyDown={(event: KeyboardEvent<HTMLTextAreaElement>) => {
if (
event.key === "Enter" &&
diff --git a/web/src/ee/features/in-app-agent/components/InAppAiAgentProvider.tsx b/web/src/ee/features/in-app-agent/components/InAppAiAgentProvider.tsx
index 0257546047..20b0aeb1d5 100644
--- a/web/src/ee/features/in-app-agent/components/InAppAiAgentProvider.tsx
+++ b/web/src/ee/features/in-app-agent/components/InAppAiAgentProvider.tsx
@@ -139,9 +139,9 @@ type InAppAiAgentContextType = {
const InAppAiAgentContext = createContext<InAppAiAgentContextType | null>(null);
-export interface InAppAiAgentProviderProps extends PropsWithChildren {
+export type InAppAiAgentProviderProps = PropsWithChildren<{
defaultOpen?: boolean;
-}
+}>;
export function InAppAiAgentProvider({
children,
@@ -417,8 +417,15 @@ function InAppAiAgentProviderInner({
}
subscriptionRef.current = agent.subscribe({
- onRunStartedEvent: ({ event }) => {
- activeRunIdRef.current = event.runId;
+ onRunStartedEvent: (payload: { event: unknown }) => {
+ if (
+ typeof payload.event === "object" &&
+ payload.event !== null &&
+ "runId" in payload.event &&
+ typeof payload.event.runId === "string"
+ ) {
+ activeRunIdRef.current = payload.event.runId;
+ }
},
onCustomEvent: ({ event }) => {
const approvalRequest = parseInAppAgentInterruptEvent(event);
diff --git a/web/src/ee/features/in-app-agent/schema.ts b/web/src/ee/features/in-app-agent/schema.ts
index 9295217baa..341f78b538 100644
--- a/web/src/ee/features/in-app-agent/schema.ts
+++ b/web/src/ee/features/in-app-agent/schema.ts
@@ -183,8 +183,8 @@ export type InAppAgentMessageSource = z.infer<
const AgUiToolSchema = z.object({
name: z.string(),
description: z.string(),
- parameters: z.any().optional(),
- metadata: z.record(z.string(), z.any()).optional(),
+ parameters: z.unknown().optional(),
+ metadata: z.record(z.string(), z.unknown()).optional(),
});
const AgUiContextSchema = z.object({
@@ -196,11 +196,11 @@ export const AgUiRunAgentInputSchema = z.object({
threadId: z.string(),
runId: z.string(),
parentRunId: z.string().optional(),
- state: z.any().optional(),
+ state: z.unknown().optional(),
messages: z.array(AgUiMessageSchema),
tools: z.array(AgUiToolSchema),
context: z.array(AgUiContextSchema),
- forwardedProps: z.any().optional(),
+ forwardedProps: z.unknown().optional(),
});
export type AgUiRunAgentInput = z.infer<typeof AgUiRunAgentInputSchema>;
diff --git a/web/src/ee/features/in-app-agent/server/agent.ts b/web/src/ee/features/in-app-agent/server/agent.ts
index 874a5f45f2..a4f4b15af4 100644
--- a/web/src/ee/features/in-app-agent/server/agent.ts
+++ b/web/src/ee/features/in-app-agent/server/agent.ts
@@ -211,15 +211,16 @@ export async function createAgUiStream(params: {
for (const result of results) {
if (result.status === "rejected") {
+ const error: unknown = result.reason;
logger.error("Error in agent stream cleanup", {
- error: result.reason,
+ error,
runId: params.input.runId,
threadId: params.input.threadId,
});
}
}
})
- .catch((error) => {
+ .catch((error: unknown) => {
logger.error("Error in agent stream cleanup", {
error,
runId: params.input.runId,
@@ -234,7 +235,7 @@ export async function createAgUiStream(params: {
) => {
try {
await callback?.();
- } catch (error) {
+ } catch (error: unknown) {
logger.error(errorContext, {
error,
runId: params.input.runId,
@@ -298,7 +299,9 @@ export async function createAgUiStream(params: {
encoder.encode(`data: ${JSON.stringify(agUiEvent)}\n\n`),
);
})
- .catch((error) => failStream(error, String(agUiEvent.type)));
+ .catch((error: unknown) => {
+ failStream(error, String(agUiEvent.type));
+ });
};
const handleStreamedRunError = () => {
@@ -356,7 +359,9 @@ export async function createAgUiStream(params: {
closed = true;
controller.close();
})
- .catch((error) => failStream(error))
+ .catch((error: unknown) => {
+ failStream(error);
+ })
.finally(finish);
};
@@ -387,7 +392,7 @@ export async function createAgUiStream(params: {
closed = true;
controller.close();
})
- .catch((error) => {
+ .catch((error: unknown) => {
closed = true;
logger.error("Error while aborting agent stream", {
error,
@@ -450,7 +455,7 @@ export async function createAgUiStream(params: {
.then(async (initialAdapter) => {
if (ending || closed || params.signal.aborted) {
initialAdapter.interrupt();
- initialAdapter.cleanup().catch((error) => {
+ initialAdapter.cleanup().catch((error: unknown) => {
logger.error("Error in agent stream cleanup", {
error,
runId: params.input.runId,
@@ -506,7 +511,7 @@ export async function createAgUiStream(params: {
if (ending || closed || params.signal.aborted) {
currentAdapter.interrupt();
- currentAdapter.cleanup().catch((error) => {
+ currentAdapter.cleanup().catch((error: unknown) => {
logger.error("Error in agent stream cleanup", {
error,
runId: params.input.runId,
@@ -569,7 +574,7 @@ export async function createAgUiStream(params: {
}
}
},
- error(error) {
+ error(error: unknown) {
if (ending || closed) {
return;
}
@@ -625,7 +630,7 @@ export async function createAgUiStream(params: {
},
});
})
- .catch((error) => {
+ .catch((error: unknown) => {
if (ending || closed) {
return;
}
@@ -669,7 +674,7 @@ export async function createAgUiStream(params: {
.then(() => {
closed = true;
})
- .catch((error) => {
+ .catch((error: unknown) => {
closed = true;
logger.error("Error while cancelling agent stream", {
error,
@@ -822,8 +827,8 @@ async function createMastraAdapter(params: {
interrupt: () => agent.abortRunStream(params.input.runId),
cleanup: () => mcpClient.disconnect(),
};
- } catch (error) {
- await mcpClient.disconnect().catch((disconnectError) => {
+ } catch (error: unknown) {
+ await mcpClient.disconnect().catch((disconnectError: unknown) => {
logger.error("Error cleaning up failed agent initialization", {
error: disconnectError,
runId: params.input.runId,
diff --git a/web/src/ee/features/in-app-agent/server/handler.ts b/web/src/ee/features/in-app-agent/server/handler.ts
index b56d969caa..7997891d71 100644
--- a/web/src/ee/features/in-app-agent/server/handler.ts
+++ b/web/src/ee/features/in-app-agent/server/handler.ts
@@ -732,7 +732,10 @@ async function cleanupInAppAgentMcpApiKey(params: {
});
}
-type SanitizedAgentInput = AgUiRunAgentInput &
+type SanitizedAgentInput = Omit<
+ AgUiRunAgentInput,
+ "messages" | "forwardedProps"
+> &
(
| {
messages: [SanitizedUserMessage];
@@ -757,7 +760,7 @@ function sanitizeAgentInput(
input: AgUiRunAgentInput,
projectId: string,
): SanitizedAgentInput {
- const forwardedProps = input.forwardedProps;
+ const forwardedProps: unknown = input.forwardedProps;
if (
forwardedProps !== undefined &&
diff --git a/web/src/ee/features/in-app-agent/server/instrumentation.ts b/web/src/ee/features/in-app-agent/server/instrumentation.ts
index 80a55e740c..d0b33074f6 100644
--- a/web/src/ee/features/in-app-agent/server/instrumentation.ts
+++ b/web/src/ee/features/in-app-agent/server/instrumentation.ts
@@ -857,7 +857,7 @@ function normalizeToolOutput(output: unknown): unknown {
return parsedOutput;
}
- const firstContent = parsedOutput.content[0];
+ const firstContent: unknown = parsedOutput.content[0];
if (
parsedOutput.content.length !== 1 ||
diff --git a/web/src/ee/features/in-app-agent/server/persistence.ts b/web/src/ee/features/in-app-agent/server/persistence.ts
index 39d6d7f276..be39825030 100644
--- a/web/src/ee/features/in-app-agent/server/persistence.ts
+++ b/web/src/ee/features/in-app-agent/server/persistence.ts
@@ -197,7 +197,7 @@ export async function finishRun(params: {
errorMessage: params.errorMessage ?? null,
},
})
- .catch((error) =>
+ .catch((error: unknown) =>
logger.error("Failed to finish in-app agent run", {
error,
runId: params.runId,
@@ -713,10 +713,8 @@ export function createConversationMessageAccumulator(
return true;
}
- messages[existingIndex] = mergeMessages(
- messages[existingIndex]!,
- parsed.data,
- );
+ const existingMessage = messages[existingIndex];
+ messages[existingIndex] = mergeMessages(existingMessage, parsed.data);
return true;
};
diff --git a/web/src/ee/features/in-app-agent/server/skills.ts b/web/src/ee/features/in-app-agent/server/skills.ts
index db3955d344..4d32d494ef 100644
--- a/web/src/ee/features/in-app-agent/server/skills.ts
+++ b/web/src/ee/features/in-app-agent/server/skills.ts
@@ -46,7 +46,7 @@ function parseSkillMarkdown(
}
function parseFrontmatter(frontmatter: string): Record<string, string> {
- const parsed = parse(frontmatter);
+ const parsed: unknown = parse(frontmatter);
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
throw new Error("In-app agent skill frontmatter must be a YAML object.");