@assistant-ui/react 0.1.11 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "conversational-ui",
30
30
  "conversational-ai"
31
31
  ],
32
- "version": "0.1.11",
32
+ "version": "0.2.0",
33
33
  "license": "MIT",
34
34
  "exports": {
35
35
  ".": {
@@ -65,6 +65,8 @@
65
65
  "dependencies": {
66
66
  "@radix-ui/primitive": "^1.1.0",
67
67
  "@radix-ui/react-compose-refs": "^1.1.0",
68
+ "@radix-ui/react-context": "^1.1.0",
69
+ "@radix-ui/react-popover": "^1.1.1",
68
70
  "@radix-ui/react-primitive": "^2.0.0",
69
71
  "@radix-ui/react-slot": "^1.1.0",
70
72
  "@radix-ui/react-use-callback-ref": "^1.1.0",
@@ -72,7 +74,7 @@
72
74
  "nanoid": "^5.0.7",
73
75
  "react-textarea-autosize": "^8.5.3",
74
76
  "zod": "^3.23.8",
75
- "zustand": "^4.5.2"
77
+ "zustand": "^4.5.4"
76
78
  },
77
79
  "peerDependencies": {
78
80
  "@types/react": "*",
@@ -84,8 +86,8 @@
84
86
  }
85
87
  },
86
88
  "devDependencies": {
87
- "@ai-sdk/react": "^0.0.4",
88
- "@types/node": "^20.14.7",
89
+ "@ai-sdk/react": "^0.0.11",
90
+ "@types/node": "^20.14.9",
89
91
  "tsup": "^8.1.0",
90
92
  "@assistant-ui/tsconfig": "0.0.0"
91
93
  },
@@ -1,98 +0,0 @@
1
- import { ReactNode, ComponentType } from 'react';
2
- import { z } from 'zod';
3
-
4
- type TextContentPart = {
5
- type: "text";
6
- text: string;
7
- };
8
- type ImageContentPart = {
9
- type: "image";
10
- image: string;
11
- };
12
- type UIContentPart = {
13
- type: "ui";
14
- display: ReactNode;
15
- };
16
- type ToolCallContentPart<TArgs = unknown, TResult = unknown> = {
17
- type: "tool-call";
18
- toolCallId: string;
19
- toolName: string;
20
- args: TArgs;
21
- result?: TResult;
22
- };
23
- type UserContentPart = TextContentPart | ImageContentPart | UIContentPart;
24
- type AssistantContentPart = TextContentPart | ToolCallContentPart | UIContentPart;
25
- type AppendContentPart = TextContentPart | ImageContentPart;
26
- type BaseMessage = {
27
- id: string;
28
- createdAt: Date;
29
- };
30
- type UserMessage = BaseMessage & {
31
- role: "user";
32
- content: UserContentPart[];
33
- };
34
- type AssistantMessage = BaseMessage & {
35
- role: "assistant";
36
- content: AssistantContentPart[];
37
- status: "in_progress" | "done" | "error";
38
- };
39
- type AppendMessage = {
40
- parentId: string | null;
41
- role: "user";
42
- content: AppendContentPart[];
43
- };
44
- type ThreadMessage = UserMessage | AssistantMessage;
45
-
46
- type ContentPartStatus = "done" | "in_progress" | "error";
47
- type TextContentPartProps = {
48
- part: TextContentPart;
49
- status: ContentPartStatus;
50
- };
51
- type TextContentPartComponent = ComponentType<TextContentPartProps>;
52
- type ImageContentPartProps = {
53
- part: ImageContentPart;
54
- status: ContentPartStatus;
55
- };
56
- type ImageContentPartComponent = ComponentType<ImageContentPartProps>;
57
- type UIContentPartProps = {
58
- part: UIContentPart;
59
- status: ContentPartStatus;
60
- };
61
- type UIContentPartComponent = ComponentType<UIContentPartProps>;
62
- type ToolCallContentPartProps<TArgs = any, TResult = any> = {
63
- part: ToolCallContentPart<TArgs, TResult>;
64
- status: ContentPartStatus;
65
- addResult: (result: any) => void;
66
- };
67
- type ToolCallContentPartComponent<TArgs = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
68
-
69
- type ToolExecuteFunction<TArgs, TResult> = (args: TArgs) => TResult | Promise<TResult>;
70
- type Tool<TArgs = unknown, TResult = unknown> = {
71
- description?: string;
72
- parameters: z.ZodSchema<TArgs>;
73
- execute: ToolExecuteFunction<TArgs, TResult>;
74
- };
75
- type ModelConfig = {
76
- priority?: number;
77
- system?: string;
78
- tools?: Record<string, Tool<any, any>>;
79
- };
80
- type ModelConfigProvider = () => ModelConfig;
81
-
82
- type Unsubscribe = () => void;
83
-
84
- type ThreadState = Readonly<{
85
- messages: readonly ThreadMessage[];
86
- isRunning: boolean;
87
- }>;
88
-
89
- type ThreadActionsState = Readonly<{
90
- getBranches: (messageId: string) => readonly string[];
91
- switchToBranch: (branchId: string) => void;
92
- append: (message: AppendMessage) => void;
93
- startRun: (parentId: string | null) => void;
94
- cancelRun: () => void;
95
- addToolResult: (toolCallId: string, result: any) => void;
96
- }>;
97
-
98
- export type { AssistantContentPart as A, ImageContentPartComponent as I, ModelConfigProvider as M, TextContentPartComponent as T, UIContentPartComponent as U, ToolCallContentPartComponent as a, ToolCallContentPartProps as b, ThreadState as c, ThreadActionsState as d, Unsubscribe as e, ThreadMessage as f, ModelConfig as g, AppendMessage as h, AssistantMessage as i, UserMessage as j, UserContentPart as k, AppendContentPart as l, TextContentPart as m, Tool as n, ImageContentPart as o, ToolCallContentPart as p, UIContentPart as q, TextContentPartProps as r, ImageContentPartProps as s, UIContentPartProps as t };
@@ -1,98 +0,0 @@
1
- import { ReactNode, ComponentType } from 'react';
2
- import { z } from 'zod';
3
-
4
- type TextContentPart = {
5
- type: "text";
6
- text: string;
7
- };
8
- type ImageContentPart = {
9
- type: "image";
10
- image: string;
11
- };
12
- type UIContentPart = {
13
- type: "ui";
14
- display: ReactNode;
15
- };
16
- type ToolCallContentPart<TArgs = unknown, TResult = unknown> = {
17
- type: "tool-call";
18
- toolCallId: string;
19
- toolName: string;
20
- args: TArgs;
21
- result?: TResult;
22
- };
23
- type UserContentPart = TextContentPart | ImageContentPart | UIContentPart;
24
- type AssistantContentPart = TextContentPart | ToolCallContentPart | UIContentPart;
25
- type AppendContentPart = TextContentPart | ImageContentPart;
26
- type BaseMessage = {
27
- id: string;
28
- createdAt: Date;
29
- };
30
- type UserMessage = BaseMessage & {
31
- role: "user";
32
- content: UserContentPart[];
33
- };
34
- type AssistantMessage = BaseMessage & {
35
- role: "assistant";
36
- content: AssistantContentPart[];
37
- status: "in_progress" | "done" | "error";
38
- };
39
- type AppendMessage = {
40
- parentId: string | null;
41
- role: "user";
42
- content: AppendContentPart[];
43
- };
44
- type ThreadMessage = UserMessage | AssistantMessage;
45
-
46
- type ContentPartStatus = "done" | "in_progress" | "error";
47
- type TextContentPartProps = {
48
- part: TextContentPart;
49
- status: ContentPartStatus;
50
- };
51
- type TextContentPartComponent = ComponentType<TextContentPartProps>;
52
- type ImageContentPartProps = {
53
- part: ImageContentPart;
54
- status: ContentPartStatus;
55
- };
56
- type ImageContentPartComponent = ComponentType<ImageContentPartProps>;
57
- type UIContentPartProps = {
58
- part: UIContentPart;
59
- status: ContentPartStatus;
60
- };
61
- type UIContentPartComponent = ComponentType<UIContentPartProps>;
62
- type ToolCallContentPartProps<TArgs = any, TResult = any> = {
63
- part: ToolCallContentPart<TArgs, TResult>;
64
- status: ContentPartStatus;
65
- addResult: (result: any) => void;
66
- };
67
- type ToolCallContentPartComponent<TArgs = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
68
-
69
- type ToolExecuteFunction<TArgs, TResult> = (args: TArgs) => TResult | Promise<TResult>;
70
- type Tool<TArgs = unknown, TResult = unknown> = {
71
- description?: string;
72
- parameters: z.ZodSchema<TArgs>;
73
- execute: ToolExecuteFunction<TArgs, TResult>;
74
- };
75
- type ModelConfig = {
76
- priority?: number;
77
- system?: string;
78
- tools?: Record<string, Tool<any, any>>;
79
- };
80
- type ModelConfigProvider = () => ModelConfig;
81
-
82
- type Unsubscribe = () => void;
83
-
84
- type ThreadState = Readonly<{
85
- messages: readonly ThreadMessage[];
86
- isRunning: boolean;
87
- }>;
88
-
89
- type ThreadActionsState = Readonly<{
90
- getBranches: (messageId: string) => readonly string[];
91
- switchToBranch: (branchId: string) => void;
92
- append: (message: AppendMessage) => void;
93
- startRun: (parentId: string | null) => void;
94
- cancelRun: () => void;
95
- addToolResult: (toolCallId: string, result: any) => void;
96
- }>;
97
-
98
- export type { AssistantContentPart as A, ImageContentPartComponent as I, ModelConfigProvider as M, TextContentPartComponent as T, UIContentPartComponent as U, ToolCallContentPartComponent as a, ToolCallContentPartProps as b, ThreadState as c, ThreadActionsState as d, Unsubscribe as e, ThreadMessage as f, ModelConfig as g, AppendMessage as h, AssistantMessage as i, UserMessage as j, UserContentPart as k, AppendContentPart as l, TextContentPart as m, Tool as n, ImageContentPart as o, ToolCallContentPart as p, UIContentPart as q, TextContentPartProps as r, ImageContentPartProps as s, UIContentPartProps as t };
@@ -1,85 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- // src/context/react/MessageContext.ts
8
- import { createContext, useContext } from "react";
9
- var MessageContext = createContext(null);
10
- var useMessageContext = () => {
11
- const context = useContext(MessageContext);
12
- if (!context)
13
- throw new Error(
14
- "This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
15
- );
16
- return context;
17
- };
18
-
19
- // src/context/react/ThreadContext.ts
20
- import { createContext as createContext2, useContext as useContext2 } from "react";
21
- var ThreadContext = createContext2(null);
22
- var useThreadContext = () => {
23
- const context = useContext2(ThreadContext);
24
- if (!context)
25
- throw new Error(
26
- "This component must be used within an AssistantRuntimeProvider."
27
- );
28
- return context;
29
- };
30
-
31
- // src/context/react/AssistantContext.ts
32
- import { createContext as createContext3, useContext as useContext3 } from "react";
33
- var AssistantContext = createContext3(
34
- null
35
- );
36
- var useAssistantContext = () => {
37
- const context = useContext3(AssistantContext);
38
- if (!context)
39
- throw new Error(
40
- "This component must be used within an AssistantRuntimeProvider."
41
- );
42
- return context;
43
- };
44
-
45
- // src/context/react/ComposerContext.ts
46
- import { useContext as useContext4, useMemo } from "react";
47
- var useComposerContext = () => {
48
- const { useComposer } = useThreadContext();
49
- const { useEditComposer } = useContext4(MessageContext) ?? {};
50
- return useMemo(
51
- () => ({
52
- useComposer: useEditComposer ?? useComposer,
53
- type: useEditComposer ? "edit" : "new"
54
- }),
55
- [useEditComposer, useComposer]
56
- );
57
- };
58
-
59
- // src/context/react/ContentPartContext.ts
60
- import { createContext as createContext4, useContext as useContext5 } from "react";
61
- var ContentPartContext = createContext4(
62
- null
63
- );
64
- var useContentPartContext = () => {
65
- const context = useContext5(ContentPartContext);
66
- if (!context)
67
- throw new Error(
68
- "This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
69
- );
70
- return context;
71
- };
72
-
73
- export {
74
- __export,
75
- MessageContext,
76
- useMessageContext,
77
- ThreadContext,
78
- useThreadContext,
79
- AssistantContext,
80
- useAssistantContext,
81
- useComposerContext,
82
- ContentPartContext,
83
- useContentPartContext
84
- };
85
- //# sourceMappingURL=chunk-KUACYNLE.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/context/react/MessageContext.ts","../src/context/react/ThreadContext.ts","../src/context/react/AssistantContext.ts","../src/context/react/ComposerContext.ts","../src/context/react/ContentPartContext.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { MessageState } from \"../stores/Message\";\nimport type { EditComposerState } from \"../stores/EditComposer\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { MessageUtilsState } from \"../stores/MessageUtils\";\n\nexport type MessageContextValue = {\n useMessage: ReadonlyStore<MessageState>;\n useMessageUtils: ReadonlyStore<MessageUtilsState>;\n useEditComposer: ReadonlyStore<EditComposerState>;\n};\n\nexport const MessageContext = createContext<MessageContextValue | null>(null);\n\nexport const useMessageContext = () => {\n const context = useContext(MessageContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />.\",\n );\n return context;\n};\n","import { createContext, useContext } from \"react\";\nimport type { ComposerState } from \"../stores/Composer\";\nimport type { ThreadState } from \"../stores/Thread\";\nimport type { ThreadViewportState } from \"../stores/ThreadViewport\";\nimport { ThreadActionsState } from \"../stores/ThreadActions\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\n\nexport type ThreadContextValue = {\n useThread: ReadonlyStore<ThreadState>;\n useThreadActions: ReadonlyStore<ThreadActionsState>;\n useComposer: ReadonlyStore<ComposerState>;\n useViewport: ReadonlyStore<ThreadViewportState>;\n};\n\nexport const ThreadContext = createContext<ThreadContextValue | null>(null);\n\nexport const useThreadContext = (): ThreadContextValue => {\n const context = useContext(ThreadContext);\n if (!context)\n throw new Error(\n \"This component must be used within an AssistantRuntimeProvider.\",\n );\n return context;\n};\n","import { createContext, useContext } from \"react\";\nimport type { AssistantModelConfigState } from \"../stores/AssistantModelConfig\";\nimport type { AssistantToolUIsState } from \"../stores/AssistantToolUIs\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\n\nexport type AssistantContextValue = {\n useModelConfig: ReadonlyStore<AssistantModelConfigState>;\n useToolUIs: ReadonlyStore<AssistantToolUIsState>;\n};\n\nexport const AssistantContext = createContext<AssistantContextValue | null>(\n null,\n);\n\nexport const useAssistantContext = (): AssistantContextValue => {\n const context = useContext(AssistantContext);\n if (!context)\n throw new Error(\n \"This component must be used within an AssistantRuntimeProvider.\",\n );\n return context;\n};\n","import { useContext, useMemo } from \"react\";\nimport { MessageContext } from \"./MessageContext\";\nimport { useThreadContext } from \"./ThreadContext\";\nimport type { ComposerState } from \"../stores/Composer\";\nimport type { EditComposerState } from \"../stores/EditComposer\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\n\nexport type ComposerContextValue = {\n useComposer: ReadonlyStore<EditComposerState | ComposerState>;\n type: \"edit\" | \"new\";\n};\n\nexport const useComposerContext = (): ComposerContextValue => {\n const { useComposer } = useThreadContext();\n const { useEditComposer } = useContext(MessageContext) ?? {};\n return useMemo(\n () => ({\n useComposer: (useEditComposer ?? useComposer) as ReadonlyStore<\n EditComposerState | ComposerState\n >,\n type: useEditComposer ? (\"edit\" as const) : (\"new\" as const),\n }),\n [useEditComposer, useComposer],\n );\n};\n","import { createContext, useContext } from \"react\";\nimport type { ContentPartState } from \"../stores/ContentPart\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\n\nexport type ContentPartContextValue = {\n useContentPart: ReadonlyStore<ContentPartState>;\n};\n\nexport const ContentPartContext = createContext<ContentPartContextValue | null>(\n null,\n);\n\nexport const useContentPartContext = (): ContentPartContextValue => {\n const context = useContext(ContentPartContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >.\",\n );\n return context;\n};\n"],"mappings":";;;;;;;AAAA,SAAS,eAAe,kBAAkB;AAYnC,IAAM,iBAAiB,cAA0C,IAAI;AAErE,IAAM,oBAAoB,MAAM;AACrC,QAAM,UAAU,WAAW,cAAc;AACzC,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACrBA,SAAS,iBAAAA,gBAAe,cAAAC,mBAAkB;AAcnC,IAAM,gBAAgBD,eAAyC,IAAI;AAEnE,IAAM,mBAAmB,MAA0B;AACxD,QAAM,UAAUC,YAAW,aAAa;AACxC,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACvBA,SAAS,iBAAAC,gBAAe,cAAAC,mBAAkB;AAUnC,IAAM,mBAAmBD;AAAA,EAC9B;AACF;AAEO,IAAM,sBAAsB,MAA6B;AAC9D,QAAM,UAAUC,YAAW,gBAAgB;AAC3C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACrBA,SAAS,cAAAC,aAAY,eAAe;AAY7B,IAAM,qBAAqB,MAA4B;AAC5D,QAAM,EAAE,YAAY,IAAI,iBAAiB;AACzC,QAAM,EAAE,gBAAgB,IAAIC,YAAW,cAAc,KAAK,CAAC;AAC3D,SAAO;AAAA,IACL,OAAO;AAAA,MACL,aAAc,mBAAmB;AAAA,MAGjC,MAAM,kBAAmB,SAAoB;AAAA,IAC/C;AAAA,IACA,CAAC,iBAAiB,WAAW;AAAA,EAC/B;AACF;;;ACxBA,SAAS,iBAAAC,gBAAe,cAAAC,mBAAkB;AAQnC,IAAM,qBAAqBD;AAAA,EAChC;AACF;AAEO,IAAM,wBAAwB,MAA+B;AAClE,QAAM,UAAUC,YAAW,kBAAkB;AAC7C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;","names":["createContext","useContext","createContext","useContext","useContext","useContext","createContext","useContext"]}