Skip to content
Open
Show file tree
Hide file tree
Changes from all 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: 8 additions & 2 deletions src/components/ContentRender/ContentRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import { OnSendContentParams, CustomRenderBarProps } from "../types";
import remarkBreaks from "remark-breaks";
import { processMarkdownText } from "./utils/process-markdown";

// Define types for markdown components
interface CodeProps extends React.HTMLAttributes<HTMLElement> {
node?: unknown;
inline?: boolean;
}

// Define component Props type
export interface ContentRenderProps {
content: string;
Expand Down Expand Up @@ -69,8 +75,8 @@ const ContentRender: React.FC<ContentRenderProps> = ({
tooltipMinLength={tooltipMinLength}
/>
),
code: (props) => {
const { inline, className, children, ...rest } = props as any;
code: (props: CodeProps) => {
const { inline, className, children, ...rest } = props;
const match = /language-(\w+)/.exec(className || "");
const language = match ? match[1] : "";

Expand Down
1 change: 1 addition & 0 deletions src/components/ContentRender/plugins/CustomVariable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface CustomVariableProps {
defaultInputText?: string;
readonly?: boolean;
onSend?: (content: OnSendContentParams) => void;
tooltipMinLength?: number;
}

interface ComponentsWithCustomVariable extends Components {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface CustomButtonNode extends Node {
type: "element";
data?: {
hName?: string;
hProperties?: Record<string, any>;
hProperties?: Record<string, unknown>;
hChildren?: Array<{ type: string; value: string }>;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ export default function remarkCustomButtonInputVariable() {
// Replace the original node
parent.children.splice(index, 1, ...segments);
} catch (error) {
// eslint-disable-next-line no-console
console.warn("Failed to parse custom variable syntax:", error);
// If parsing fails, keep the original content
return;
Expand Down
2 changes: 1 addition & 1 deletion src/components/MarkdownFlow/useScrollToBottom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface UseScrollToBottomReturn {

const useScrollToBottom = (
containerRef: RefObject<HTMLDivElement | null>,
dependencies: any[] = [],
dependencies: unknown[] = [],
options: UseScrollToBottomOptions = {}
): UseScrollToBottomReturn => {
const {
Expand Down
23 changes: 18 additions & 5 deletions src/components/Playground/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ import { ContentRenderProps } from "../ContentRender/ContentRender";
import { OnSendContentParams, CustomRenderBarProps } from "../types";
import { Loader } from "lucide-react";

// Define proper types for variables
type VariableValue = string | number | boolean | null | undefined;

// Define type for SSE response data

type PlaygroundComponentProps = {
defaultContent: string;
defaultVariables?: {
[key: string]: any;
[key: string]: VariableValue;
};
defaultDocumentPrompt?: string;
styles?: React.CSSProperties;
Expand All @@ -26,7 +31,7 @@ type SSEParams = {
content: string;
}>;
variables?: {
[key: string]: any;
[key: string]: VariableValue;
};
user_input: string | null;
document_prompt: string | null;
Expand Down Expand Up @@ -154,7 +159,16 @@ const PlaygroundComponent: React.FC<PlaygroundComponentProps> = ({
return newList;
};

const handleOnFinish = (data: string) => {
const handleOnFinish = (data: unknown, _index: number) => {
// Type guard to ensure data is string
if (typeof data !== "string") {
console.warn(
"Expected string data in handleOnFinish, received:",
typeof data
);
return;
}

const isCurrentInteractionBlock = interaction_blocks.includes(
currentBlockIndexRef.current
);
Expand Down Expand Up @@ -223,7 +237,7 @@ const PlaygroundComponent: React.FC<PlaygroundComponentProps> = ({
return list;
};

const { data, connect } = useSSE<any>(sseUrl, {
const { data, connect } = useSSE<string>(sseUrl, {
method: "POST",
body: getSSEBody(),
headers: sessionId ? { "session-id": sessionId } : {},
Expand All @@ -244,7 +258,6 @@ const PlaygroundComponent: React.FC<PlaygroundComponentProps> = ({
const updatedList = updateContentListWithSseData(data);
setContentList(updatedList);
} catch (error) {
// eslint-disable-next-line no-console
console.error("Error processing SSE message:", error);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/components/Playground/useMarkdownInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ const useMarkdownInfo = (content: string) => {
} else {
setError(result.message || "Request failed");
}
} catch (err: any) {
setError(err.message || "Network error");
} catch (err: unknown) {
const errorMessage =
err instanceof Error ? err.message : "Network error";
setError(errorMessage);
} finally {
setLoading(false);
}
Expand Down
11 changes: 5 additions & 6 deletions src/components/sse/useSSE.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, useEffect, useRef, useCallback } from "react";
import { fetchEventSource } from "@microsoft/fetch-event-source";

interface UseSSEReturn<T = any> {
interface UseSSEReturn<T = unknown> {
data: T | null;
isLoading: boolean;
error: Error | null;
Expand All @@ -15,7 +15,7 @@ const FINISHED_MESSAGE = "[DONE]";
interface UseSSEOptions extends RequestInit {
autoConnect?: boolean;
onStart?: (index: number) => void;
onFinish?: (finalData: any, index: number) => void;
onFinish?: (finalData: unknown, index: number) => void;
maxRetries?: number;
retryDelay?: number;
}
Expand All @@ -27,7 +27,7 @@ type ConnectionState =
| "error"
| "closed";

const useSSE = <T = any>(
const useSSE = <T = unknown>(
url: string,
options: UseSSEOptions = {}
): UseSSEReturn<T> => {
Expand Down Expand Up @@ -113,11 +113,10 @@ const useSSE = <T = any>(
return;
}
try {
const parsedData: any = event.data;
const parsedData: string = event.data;
finalDataRef.current += parsedData;
setData(finalDataRef.current as any);
setData(finalDataRef.current as T);
} catch (err) {
// eslint-disable-next-line no-console
console.warn("Failed to process SSE message:", err);
}
}
Expand Down