-
Notifications
You must be signed in to change notification settings - Fork 865
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Time travel, use checkpoint as primary source of truth Refactor state management for chat window Add support for state graph Fixes Pare down unneeded functionality, frontend updates Fix repeated history fetches Add basic state graph support, many other fixes Revise state graph time travel flow Use message graph as default Fix flashing messages in UI on send Allow adding and deleting tool calls Hacks! Only accept module paths More logs add env add built ui files Build ui files Update cli Delete .github/workflows/build_deploy_image.yml Update path Update ui files Move migrations Move ui files 0.0.5 Allow resume execution for tool messages (#2) Undo Undo Remove cli Undo Undo Update storage/threads Undo ui Undo Lint Undo Rm Undo Rm Update api Undo WIP
- Loading branch information
1 parent
cb39b9b
commit 0dab4d6
Showing
12 changed files
with
678 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Ref } from "react"; | ||
import { cn } from "../utils/cn"; | ||
|
||
const COMMON_CLS = cn( | ||
"text-sm col-[1] row-[1] m-0 resize-none overflow-hidden whitespace-pre-wrap break-words bg-transparent px-2 py-1 rounded shadow-none", | ||
); | ||
|
||
export function AutosizeTextarea(props: { | ||
id?: string; | ||
inputRef?: Ref<HTMLTextAreaElement>; | ||
value?: string | null | undefined; | ||
placeholder?: string; | ||
className?: string; | ||
onChange?: (e: string) => void; | ||
onFocus?: () => void; | ||
onBlur?: () => void; | ||
onKeyDown?: (e: React.KeyboardEvent<HTMLTextAreaElement>) => void; | ||
autoFocus?: boolean; | ||
readOnly?: boolean; | ||
cursorPointer?: boolean; | ||
disabled?: boolean; | ||
fullHeight?: boolean; | ||
}) { | ||
return ( | ||
<div | ||
className={ | ||
cn("grid w-full", props.className) + | ||
(props.fullHeight ? "" : " max-h-80 overflow-auto ") | ||
} | ||
> | ||
<textarea | ||
ref={props.inputRef} | ||
id={props.id} | ||
className={cn( | ||
COMMON_CLS, | ||
"text-transparent caret-black rounded focus:outline-0 focus:ring-0", | ||
)} | ||
disabled={props.disabled} | ||
value={props.value ?? ""} | ||
rows={1} | ||
onChange={(e) => { | ||
const target = e.target as HTMLTextAreaElement; | ||
props.onChange?.(target.value); | ||
}} | ||
onFocus={props.onFocus} | ||
onBlur={props.onBlur} | ||
placeholder={props.placeholder} | ||
readOnly={props.readOnly} | ||
autoFocus={props.autoFocus && !props.readOnly} | ||
onKeyDown={props.onKeyDown} | ||
/> | ||
<div | ||
aria-hidden | ||
className={cn(COMMON_CLS, "pointer-events-none select-none")} | ||
> | ||
{props.value}{" "} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { useState } from "react"; | ||
import { Slider } from "@mui/material"; | ||
import { | ||
ChevronLeftIcon, | ||
ChevronRightIcon, | ||
ClockIcon, | ||
} from "@heroicons/react/24/outline"; | ||
import { cn } from "../utils/cn"; | ||
import { History } from "../hooks/useHistories"; | ||
|
||
export function Timeline(props: { | ||
disabled: boolean; | ||
histories: History[]; | ||
activeHistoryIndex: number; | ||
onChange?: (newValue: number) => void; | ||
}) { | ||
const [expanded, setExpanded] = useState(false); | ||
return ( | ||
<div className="flex items-center"> | ||
<button | ||
className="flex items-center p-2 text-sm" | ||
type="submit" | ||
disabled={props.disabled} | ||
onClick={() => setExpanded((expanded) => !expanded)} | ||
> | ||
<ClockIcon className="h-4 w-4 mr-1 rounded-md shrink-0" /> | ||
<span className="text-gray-900 font-semibold shrink-0"> | ||
Time travel | ||
</span> | ||
</button> | ||
<Slider | ||
className={cn( | ||
"w-full shrink transition-max-width duration-200", | ||
expanded ? " ml-8 mr-8 max-w-full" : " invisible max-w-0", | ||
)} | ||
aria-label="Timeline" | ||
value={props.activeHistoryIndex} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
onChange={(e) => props.onChange?.((e.target as any).value)} | ||
valueLabelDisplay="auto" | ||
step={1} | ||
marks | ||
min={0} | ||
max={props.histories.length - 1} | ||
/> | ||
{expanded ? ( | ||
<ChevronLeftIcon | ||
className="h-4 w-4 cursor-pointer shrink-0 mr-4" | ||
onClick={() => setExpanded((expanded) => !expanded)} | ||
/> | ||
) : ( | ||
<ChevronRightIcon | ||
className="h-4 w-4 cursor-pointer shrink-0 mr-4" | ||
onClick={() => setExpanded((expanded) => !expanded)} | ||
/> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useEffect, useState } from "react"; | ||
import { Message as MessageType } from "./useChatList"; | ||
import { StreamState } from "./useStreamState"; | ||
|
||
async function getHistories(threadId: string) { | ||
const response = await fetch(`/threads/${threadId}/history`, { | ||
headers: { | ||
Accept: "application/json", | ||
}, | ||
}).then((r) => r.json()); | ||
return response; | ||
} | ||
|
||
export interface History { | ||
values: MessageType[]; | ||
next: string[]; | ||
config: Record<string, unknown>; | ||
} | ||
|
||
export function useHistories( | ||
threadId: string | null, | ||
stream: StreamState | null, | ||
): { | ||
histories: History[]; | ||
setHistories: React.Dispatch<React.SetStateAction<History[]>>; | ||
} { | ||
const [histories, setHistories] = useState<History[]>([]); | ||
|
||
useEffect(() => { | ||
async function fetchHistories() { | ||
if (threadId) { | ||
const histories = await getHistories(threadId); | ||
setHistories(histories); | ||
} | ||
} | ||
fetchHistories(); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [threadId, stream?.status]); | ||
|
||
return { histories, setHistories }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.