From 548bec128fadc76d78e5c0c44bad2dbb324e3e27 Mon Sep 17 00:00:00 2001 From: Simon Farshid Date: Sun, 15 Sep 2024 21:05:06 -0700 Subject: [PATCH] fix: eslint fixes (#842) * feat: simplify context API * a few eslint fixes --- packages/react/.eslintrc.json | 7 ++++++- .../src/context/providers/ComposerAttachmentProvider.tsx | 2 +- .../src/context/providers/MessageAttachmentProvider.tsx | 2 +- .../src/context/react/utils/createContextStoreHook.ts | 2 +- .../src/primitive-hooks/actionBar/useActionBarEdit.tsx | 2 +- .../src/primitives/actionBar/ActionBarStopSpeaking.tsx | 2 ++ .../src/primitives/branchPicker/BranchPickerCount.tsx | 2 +- .../src/primitives/branchPicker/BranchPickerNumber.tsx | 2 +- .../src/primitives/contentPart/ContentPartDisplay.tsx | 6 ++---- packages/react/src/primitives/message/MessageRoot.tsx | 4 ++-- packages/react/src/primitives/thread/ThreadViewport.tsx | 2 +- packages/react/src/runtimes/edge/createEdgeRuntimeAPI.ts | 6 +++--- packages/react/src/runtimes/local/LocalThreadRuntime.tsx | 4 +++- packages/react/src/utils/smooth/useSmooth.tsx | 4 ++-- 14 files changed, 27 insertions(+), 20 deletions(-) diff --git a/packages/react/.eslintrc.json b/packages/react/.eslintrc.json index bffb357a7..b24c10c56 100644 --- a/packages/react/.eslintrc.json +++ b/packages/react/.eslintrc.json @@ -1,3 +1,8 @@ { - "extends": "next/core-web-vitals" + "extends": ["next/core-web-vitals", "next/typescript"], + "rules": { + "@typescript-eslint/no-unused-vars": "off", + "@typescript-eslint/no-namespace": "off", + "@typescript-eslint/no-explicit-any": "off" + } } diff --git a/packages/react/src/context/providers/ComposerAttachmentProvider.tsx b/packages/react/src/context/providers/ComposerAttachmentProvider.tsx index edde1b553..465986ff9 100644 --- a/packages/react/src/context/providers/ComposerAttachmentProvider.tsx +++ b/packages/react/src/context/providers/ComposerAttachmentProvider.tsx @@ -20,7 +20,7 @@ const getAttachment = ( useAttachment: AttachmentContextValue["useAttachment"] | undefined, partIndex: number, ) => { - let attachment = attachments[partIndex]; + const attachment = attachments[partIndex]; if (!attachment) return null; // if the attachment is the same, don't update diff --git a/packages/react/src/context/providers/MessageAttachmentProvider.tsx b/packages/react/src/context/providers/MessageAttachmentProvider.tsx index 9defd4cb2..2656a0133 100644 --- a/packages/react/src/context/providers/MessageAttachmentProvider.tsx +++ b/packages/react/src/context/providers/MessageAttachmentProvider.tsx @@ -23,7 +23,7 @@ const getAttachment = ( if (message.role !== "user") return null; const attachments = message.attachments; - let attachment = attachments[partIndex]; + const attachment = attachments[partIndex]; if (!attachment) return null; // if the attachment is the same, don't update diff --git a/packages/react/src/context/react/utils/createContextStoreHook.ts b/packages/react/src/context/react/utils/createContextStoreHook.ts index 384d22921..ea6027ced 100644 --- a/packages/react/src/context/react/utils/createContextStoreHook.ts +++ b/packages/react/src/context/react/utils/createContextStoreHook.ts @@ -16,7 +16,7 @@ export function createContextStoreHook( // Define useStoreStoreHook with overloads function useStoreStoreHook(): ReadonlyStore; - function useStoreStoreHook(options: { + function useStoreStoreHook(options: { optional: true; }): ReadonlyStore | null; function useStoreStoreHook(options?: { diff --git a/packages/react/src/primitive-hooks/actionBar/useActionBarEdit.tsx b/packages/react/src/primitive-hooks/actionBar/useActionBarEdit.tsx index bbef50de6..018f3c38b 100644 --- a/packages/react/src/primitive-hooks/actionBar/useActionBarEdit.tsx +++ b/packages/react/src/primitive-hooks/actionBar/useActionBarEdit.tsx @@ -11,7 +11,7 @@ export const useActionBarEdit = () => { const callback = useCallback(() => { const { edit } = editComposerStore.getState(); edit(); - }, [useEditComposer]); + }, [editComposerStore]); if (disabled) return null; return callback; diff --git a/packages/react/src/primitives/actionBar/ActionBarStopSpeaking.tsx b/packages/react/src/primitives/actionBar/ActionBarStopSpeaking.tsx index a0af61654..e46913251 100644 --- a/packages/react/src/primitives/actionBar/ActionBarStopSpeaking.tsx +++ b/packages/react/src/primitives/actionBar/ActionBarStopSpeaking.tsx @@ -37,3 +37,5 @@ export const ActionBarPrimitiveStopSpeaking = forwardRef< /> ); }); + +ActionBarPrimitiveStopSpeaking.displayName = "ActionBarPrimitive.StopSpeaking"; diff --git a/packages/react/src/primitives/branchPicker/BranchPickerCount.tsx b/packages/react/src/primitives/branchPicker/BranchPickerCount.tsx index b45d81001..b6b26e25b 100644 --- a/packages/react/src/primitives/branchPicker/BranchPickerCount.tsx +++ b/packages/react/src/primitives/branchPicker/BranchPickerCount.tsx @@ -3,7 +3,7 @@ import type { FC } from "react"; import { useBranchPickerCount } from "../../primitive-hooks/branchPicker/useBranchPickerCount"; -export type BranchPickerPrimitiveCountProps = {}; +export type BranchPickerPrimitiveCountProps = Record; export const BranchPickerPrimitiveCount: FC< BranchPickerPrimitiveCountProps diff --git a/packages/react/src/primitives/branchPicker/BranchPickerNumber.tsx b/packages/react/src/primitives/branchPicker/BranchPickerNumber.tsx index 0e44e88da..adfae6d96 100644 --- a/packages/react/src/primitives/branchPicker/BranchPickerNumber.tsx +++ b/packages/react/src/primitives/branchPicker/BranchPickerNumber.tsx @@ -3,7 +3,7 @@ import type { FC } from "react"; import { useBranchPickerNumber } from "../../primitive-hooks/branchPicker/useBranchPickerNumber"; -export type BranchPickerPrimitiveNumberProps = {}; +export type BranchPickerPrimitiveNumberProps = Record; export const BranchPickerPrimitiveNumber: FC< BranchPickerPrimitiveNumberProps diff --git a/packages/react/src/primitives/contentPart/ContentPartDisplay.tsx b/packages/react/src/primitives/contentPart/ContentPartDisplay.tsx index 9169e45ec..12873f447 100644 --- a/packages/react/src/primitives/contentPart/ContentPartDisplay.tsx +++ b/packages/react/src/primitives/contentPart/ContentPartDisplay.tsx @@ -1,11 +1,9 @@ import type { FC } from "react"; import { useContentPartDisplay } from "../../primitive-hooks/contentPart/useContentPartDisplay"; -export type ContentPartPrimitiveDisplayProps = {}; +export type ContentPartPrimitiveDisplayProps = Record; -export const ContentPartPrimitiveDisplay: FC< - ContentPartPrimitiveDisplayProps -> = () => { +export const ContentPartPrimitiveDisplay: FC = () => { const { part: { display }, } = useContentPartDisplay(); diff --git a/packages/react/src/primitives/message/MessageRoot.tsx b/packages/react/src/primitives/message/MessageRoot.tsx index a1473e779..aa955d268 100644 --- a/packages/react/src/primitives/message/MessageRoot.tsx +++ b/packages/react/src/primitives/message/MessageRoot.tsx @@ -47,11 +47,11 @@ export type MessagePrimitiveRootProps = PrimitiveDivProps; export const MessagePrimitiveRoot = forwardRef< MessagePrimitiveRootElement, MessagePrimitiveRootProps ->(({ onMouseEnter, onMouseLeave, ...rest }, forwardRef) => { +>((props, forwardRef) => { const isHoveringRef = useIsHoveringRef(); const ref = useComposedRefs(forwardRef, isHoveringRef); - return ; + return ; }); MessagePrimitiveRoot.displayName = "MessagePrimitive.Root"; diff --git a/packages/react/src/primitives/thread/ThreadViewport.tsx b/packages/react/src/primitives/thread/ThreadViewport.tsx index 51944ac8f..4d4f8bd54 100644 --- a/packages/react/src/primitives/thread/ThreadViewport.tsx +++ b/packages/react/src/primitives/thread/ThreadViewport.tsx @@ -17,7 +17,7 @@ export type ThreadPrimitiveViewportProps = PrimitiveDivProps & export const ThreadPrimitiveViewport = forwardRef< ThreadPrimitiveViewportElement, ThreadPrimitiveViewportProps ->(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => { +>(({ autoScroll, children, ...rest }, forwardedRef) => { const autoScrollRef = useThreadViewportAutoScroll({ autoScroll, }); diff --git a/packages/react/src/runtimes/edge/createEdgeRuntimeAPI.ts b/packages/react/src/runtimes/edge/createEdgeRuntimeAPI.ts index 04563295f..704a0304f 100644 --- a/packages/react/src/runtimes/edge/createEdgeRuntimeAPI.ts +++ b/packages/react/src/runtimes/edge/createEdgeRuntimeAPI.ts @@ -102,9 +102,7 @@ export const getEdgeRuntimeStream = async ({ } } - let model; - - model = + const model = typeof modelOrCreator === "function" ? await modelOrCreator({ apiKey, baseUrl, modelName }) : modelOrCreator; @@ -157,6 +155,8 @@ export const getEdgeRuntimeStream = async ({ onFinish({ messages: resultingMessages, metadata: { + // TODO + // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain roundtrips: lastChunk.metadata?.roundtrips!, }, }); diff --git a/packages/react/src/runtimes/local/LocalThreadRuntime.tsx b/packages/react/src/runtimes/local/LocalThreadRuntime.tsx index 2a27a93b0..e6b668cf7 100644 --- a/packages/react/src/runtimes/local/LocalThreadRuntime.tsx +++ b/packages/react/src/runtimes/local/LocalThreadRuntime.tsx @@ -269,7 +269,9 @@ export class LocalThreadRuntime implements ThreadRuntime { toolCallId, result, }: AddToolResultOptions) { - let { parentId, message } = this.repository.getMessage(messageId); + const messageData = this.repository.getMessage(messageId); + const { parentId } = messageData; + let { message } = messageData; if (message.role !== "assistant") throw new Error("Tried to add tool result to non-assistant message"); diff --git a/packages/react/src/utils/smooth/useSmooth.tsx b/packages/react/src/utils/smooth/useSmooth.tsx index 7e1608eed..23443c78f 100644 --- a/packages/react/src/utils/smooth/useSmooth.tsx +++ b/packages/react/src/utils/smooth/useSmooth.tsx @@ -5,7 +5,7 @@ import { useMessage } from "../../context"; import { ContentPartStatus } from "../../types/AssistantTypes"; import { TextContentPartState } from "../../context/stores/ContentPart"; import { useCallbackRef } from "@radix-ui/react-use-callback-ref"; -import { useSmoothStatus, useSmoothStatusStore } from "./SmoothContext"; +import { useSmoothStatusStore } from "./SmoothContext"; import { writableStore } from "../../context/ReadonlyStore"; class TextStreamAnimator { @@ -95,7 +95,7 @@ export const useSmooth = ( text !== state.part.text ? SMOOTH_STATUS : state.status, ); } - }, [useSmoothStatus, text, displayedText, state.status]); + }, [smoothStatusStore, text, displayedText, state.status, state.part.text]); const [animatorRef] = useState( new TextStreamAnimator(text, setText),