forked from bhancockio/openai-assistant-crash-course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom.ts
43 lines (38 loc) · 1.17 KB
/
atom.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { atom } from "jotai";
import { Assistant } from "openai/resources/beta/assistants/assistants.mjs";
import { ThreadMessage } from "openai/resources/beta/threads/messages/messages.mjs";
import { Run } from "openai/resources/beta/threads/runs/runs.mjs";
import { Thread } from "openai/resources/beta/threads/threads.mjs";
export const assistantAtom = atom<Assistant | null>(null);
export const fileAtom = atom<string | null>(null);
export const assistantFileAtom = atom<string | null>(null);
export const threadAtom = atom<Thread | null>(null);
export const runAtom = atom<Run | null>(null);
export const messagesAtom = atom<ThreadMessage[]>([]);
export type RunState =
| "queued"
| "in_progress"
| "requires_action"
| "cancelling"
| "cancelled"
| "failed"
| "completed"
| "expired"
| "N/A";
export const runStateAtom = atom<RunState>("N/A");
export const isValidRunState = (
value: RunState | string
): value is RunState => {
const validStates: RunState[] = [
"queued",
"in_progress",
"requires_action",
"cancelling",
"cancelled",
"failed",
"completed",
"expired",
"N/A",
];
return validStates.includes(value as RunState);
};