Skip to content

Commit

Permalink
fix: eslint fixes (#842)
Browse files Browse the repository at this point in the history
* feat: simplify context API

* a few eslint fixes
  • Loading branch information
Yonom authored Sep 16, 2024
1 parent e039c16 commit 548bec1
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 20 deletions.
7 changes: 6 additions & 1 deletion packages/react/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function createContextStoreHook<T, K extends keyof T & string>(

// Define useStoreStoreHook with overloads
function useStoreStoreHook(): ReadonlyStore<StateType>;
function useStoreStoreHook<TSelected>(options: {
function useStoreStoreHook(options: {
optional: true;
}): ReadonlyStore<StateType> | null;
function useStoreStoreHook(options?: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const useActionBarEdit = () => {
const callback = useCallback(() => {
const { edit } = editComposerStore.getState();
edit();
}, [useEditComposer]);
}, [editComposerStore]);

if (disabled) return null;
return callback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ export const ActionBarPrimitiveStopSpeaking = forwardRef<
/>
);
});

ActionBarPrimitiveStopSpeaking.displayName = "ActionBarPrimitive.StopSpeaking";
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { FC } from "react";
import { useBranchPickerCount } from "../../primitive-hooks/branchPicker/useBranchPickerCount";

export type BranchPickerPrimitiveCountProps = {};
export type BranchPickerPrimitiveCountProps = Record<string, never>;

export const BranchPickerPrimitiveCount: FC<
BranchPickerPrimitiveCountProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { FC } from "react";
import { useBranchPickerNumber } from "../../primitive-hooks/branchPicker/useBranchPickerNumber";

export type BranchPickerPrimitiveNumberProps = {};
export type BranchPickerPrimitiveNumberProps = Record<string, never>;

export const BranchPickerPrimitiveNumber: FC<
BranchPickerPrimitiveNumberProps
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import type { FC } from "react";
import { useContentPartDisplay } from "../../primitive-hooks/contentPart/useContentPartDisplay";

export type ContentPartPrimitiveDisplayProps = {};
export type ContentPartPrimitiveDisplayProps = Record<string, never>;

export const ContentPartPrimitiveDisplay: FC<
ContentPartPrimitiveDisplayProps
> = () => {
export const ContentPartPrimitiveDisplay: FC = () => {
const {
part: { display },
} = useContentPartDisplay();
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/primitives/message/MessageRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLDivElement>(forwardRef, isHoveringRef);

return <Primitive.div {...rest} ref={ref} />;
return <Primitive.div {...props} ref={ref} />;
});

MessagePrimitiveRoot.displayName = "MessagePrimitive.Root";
2 changes: 1 addition & 1 deletion packages/react/src/primitives/thread/ThreadViewport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLDivElement>({
autoScroll,
});
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/runtimes/edge/createEdgeRuntimeAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ export const getEdgeRuntimeStream = async ({
}
}

let model;

model =
const model =
typeof modelOrCreator === "function"
? await modelOrCreator({ apiKey, baseUrl, modelName })
: modelOrCreator;
Expand Down Expand Up @@ -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!,
},
});
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/runtimes/local/LocalThreadRuntime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/utils/smooth/useSmooth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<TextStreamAnimator>(
new TextStreamAnimator(text, setText),
Expand Down

0 comments on commit 548bec1

Please sign in to comment.