@assistant-ui/react 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +79 -4
- package/dist/{Thread-ZUDFhMtm.d.mts → Thread-CoxBELWy.d.mts} +2 -0
- package/dist/{Thread-ZUDFhMtm.d.ts → Thread-CoxBELWy.d.ts} +2 -0
- package/dist/{chunk-KIP3YFVM.mjs → chunk-RITM2IUH.mjs} +4 -2
- package/dist/chunk-RITM2IUH.mjs.map +1 -0
- package/dist/experimental.d.mts +13 -13
- package/dist/experimental.d.ts +13 -13
- package/dist/experimental.js +29 -27
- package/dist/experimental.js.map +1 -1
- package/dist/experimental.mjs +24 -24
- package/dist/experimental.mjs.map +1 -1
- package/dist/index.d.mts +56 -55
- package/dist/index.d.ts +56 -55
- package/dist/index.js +51 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -72
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/dist/chunk-KIP3YFVM.mjs.map +0 -1
package/README.md
CHANGED
@@ -10,12 +10,41 @@
|
|
10
10
|
|
11
11
|
- [Documentation](https://www.assistant-ui.com/docs/getting-started)
|
12
12
|
|
13
|
-
##
|
13
|
+
## Starter Template
|
14
14
|
|
15
|
+
```
|
16
|
+
npx assistant-ui@latest create
|
17
|
+
```
|
18
|
+
|
19
|
+
## Quick Start In Existing Project
|
20
|
+
![Demo of my project](demo.gif)
|
21
|
+
|
22
|
+
### PREREQUISITES:
|
23
|
+
It is assumed that you have already installed and initialized node.js, tailwind, typescript, react, next.js. If not, follow the instructions:
|
24
|
+
```sh
|
25
|
+
npx create-next-app@latest my-app --typescript --tailwind
|
26
|
+
```
|
27
|
+
```sh
|
28
|
+
cd my-app
|
29
|
+
```
|
30
|
+
```sh
|
31
|
+
npm install @ai-sdk/react @assistant-ui/react @assistant-ui/react-ai-sdk
|
32
|
+
```
|
33
|
+
Install shadcn react components, follow instructins with default answers
|
34
|
+
```sh
|
35
|
+
npx shadcn-ui init
|
36
|
+
```
|
37
|
+
|
38
|
+
GETTING STARTED:
|
15
39
|
```sh
|
16
40
|
npx assistant-ui@latest add modal
|
17
41
|
```
|
18
42
|
|
43
|
+
Create/edit your desired page file:
|
44
|
+
```
|
45
|
+
/src/app/pages.tsx
|
46
|
+
```
|
47
|
+
|
19
48
|
```tsx
|
20
49
|
"use client";
|
21
50
|
|
@@ -24,7 +53,7 @@ import { AssistantRuntimeProvider } from "@assistant-ui/react";
|
|
24
53
|
import { useVercelUseChatRuntime } from "@assistant-ui/react-ai-sdk";
|
25
54
|
import { AssistantModal } from "@/components/ui/assistant-ui/assistant-modal";
|
26
55
|
|
27
|
-
|
56
|
+
const MyApp = () => {
|
28
57
|
const chat = useChat({
|
29
58
|
api: "/api/chat" // your backend route
|
30
59
|
});
|
@@ -34,6 +63,52 @@ export default const MyApp = () => {
|
|
34
63
|
<AssistantRuntimeProvider runtime={runtime}>
|
35
64
|
<AssistantModal />
|
36
65
|
</AssistantRuntimeProvider>
|
37
|
-
|
66
|
+
);
|
38
67
|
}
|
39
|
-
|
68
|
+
|
69
|
+
export default MyApp;
|
70
|
+
```
|
71
|
+
|
72
|
+
|
73
|
+
### Backend connection using Vercel AI SDK:
|
74
|
+
|
75
|
+
```sh
|
76
|
+
npm install @ai-sdk/openai
|
77
|
+
```
|
78
|
+
|
79
|
+
```sh
|
80
|
+
npm install @assistant-ui/react-hook-form
|
81
|
+
```
|
82
|
+
|
83
|
+
Create backend route file:
|
84
|
+
```
|
85
|
+
/src/app/api/chat/route.ts
|
86
|
+
```
|
87
|
+
|
88
|
+
```tsx
|
89
|
+
import { openai } from '@ai-sdk/openai';
|
90
|
+
import { streamText } from 'ai';
|
91
|
+
|
92
|
+
export const maxDuration = 30;
|
93
|
+
|
94
|
+
export async function POST(req: Request) {
|
95
|
+
const { messages } = await req.json();
|
96
|
+
|
97
|
+
const result = await streamText({
|
98
|
+
model: openai('gpt-4o'),
|
99
|
+
messages,
|
100
|
+
});
|
101
|
+
|
102
|
+
return result.toAIStreamResponse();
|
103
|
+
}
|
104
|
+
```
|
105
|
+
|
106
|
+
```sh
|
107
|
+
export OPENAI_API_KEY="skXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
108
|
+
```
|
109
|
+
|
110
|
+
```sh
|
111
|
+
npm run dev
|
112
|
+
```
|
113
|
+
|
114
|
+
Now Open: [http://localhost:3000](http://localhost:3000)
|
@@ -61,6 +61,7 @@ type UIContentPartComponent = ComponentType<UIContentPartProps>;
|
|
61
61
|
type ToolCallContentPartProps<TArgs = any, TResult = any> = {
|
62
62
|
part: ToolCallContentPart<TArgs, TResult>;
|
63
63
|
status: ContentPartStatus;
|
64
|
+
addResult: (result: any) => void;
|
64
65
|
};
|
65
66
|
type ToolCallContentPartComponent<TArgs = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
|
66
67
|
|
@@ -87,6 +88,7 @@ type ThreadState = {
|
|
87
88
|
append: (message: AppendMessage) => void;
|
88
89
|
startRun: (parentId: string | null) => void;
|
89
90
|
cancelRun: () => void;
|
91
|
+
addToolResult: (toolCallId: string, result: any) => void;
|
90
92
|
};
|
91
93
|
|
92
94
|
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, Unsubscribe as d, ThreadMessage as e, ModelConfig as f, AppendMessage as g, AssistantMessage as h, UserMessage as i, UserContentPart as j, AppendContentPart as k, TextContentPart as l, Tool as m, ImageContentPart as n, ToolCallContentPart as o, UIContentPart as p, TextContentPartProps as q, ImageContentPartProps as r, UIContentPartProps as s };
|
@@ -61,6 +61,7 @@ type UIContentPartComponent = ComponentType<UIContentPartProps>;
|
|
61
61
|
type ToolCallContentPartProps<TArgs = any, TResult = any> = {
|
62
62
|
part: ToolCallContentPart<TArgs, TResult>;
|
63
63
|
status: ContentPartStatus;
|
64
|
+
addResult: (result: any) => void;
|
64
65
|
};
|
65
66
|
type ToolCallContentPartComponent<TArgs = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
|
66
67
|
|
@@ -87,6 +88,7 @@ type ThreadState = {
|
|
87
88
|
append: (message: AppendMessage) => void;
|
88
89
|
startRun: (parentId: string | null) => void;
|
89
90
|
cancelRun: () => void;
|
91
|
+
addToolResult: (toolCallId: string, result: any) => void;
|
90
92
|
};
|
91
93
|
|
92
94
|
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, Unsubscribe as d, ThreadMessage as e, ModelConfig as f, AppendMessage as g, AssistantMessage as h, UserMessage as i, UserContentPart as j, AppendContentPart as k, TextContentPart as l, Tool as m, ImageContentPart as n, ToolCallContentPart as o, UIContentPart as p, TextContentPartProps as q, ImageContentPartProps as r, UIContentPartProps as s };
|
@@ -22,7 +22,9 @@ var ThreadContext = createContext2(null);
|
|
22
22
|
var useThreadContext = () => {
|
23
23
|
const context = useContext2(ThreadContext);
|
24
24
|
if (!context)
|
25
|
-
throw new Error(
|
25
|
+
throw new Error(
|
26
|
+
"This component must be used within an AssistantRuntimeProvider."
|
27
|
+
);
|
26
28
|
return context;
|
27
29
|
};
|
28
30
|
|
@@ -80,4 +82,4 @@ export {
|
|
80
82
|
ContentPartContext,
|
81
83
|
useContentPartContext
|
82
84
|
};
|
83
|
-
//# sourceMappingURL=chunk-
|
85
|
+
//# sourceMappingURL=chunk-RITM2IUH.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/context/MessageContext.ts","../src/context/ThreadContext.ts","../src/context/ComposerContext.ts","../src/context/AssistantContext.ts","../src/context/ContentPartContext.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { MessageState } from \"./stores/Message\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type MessageContextValue = {\n useMessage: UseBoundStore<StoreApi<MessageState>>;\n useComposer: UseBoundStore<StoreApi<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 { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { ThreadState } from \"./stores/Thread\";\nimport type { ThreadViewportState } from \"./stores/ThreadViewport\";\n\nexport type ThreadContextValue = {\n useThread: UseBoundStore<StoreApi<ThreadState>>;\n useComposer: UseBoundStore<StoreApi<ComposerState>>;\n useViewport: UseBoundStore<StoreApi<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 { useContext, useMemo } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport { MessageContext } from \"./MessageContext\";\nimport { useThreadContext } from \"./ThreadContext\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type ComposerContextValue = {\n useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;\n type: \"edit\" | \"new\";\n};\n\nexport const useComposerContext = (): ComposerContextValue => {\n const { useComposer } = useThreadContext();\n const { useComposer: useEditComposer } = useContext(MessageContext) ?? {};\n return useMemo(\n () => ({\n useComposer: (useEditComposer ?? useComposer) as UseBoundStore<\n StoreApi<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 { StoreApi, UseBoundStore } from \"zustand\";\nimport type { AssistantModelConfigState } from \"./stores/AssistantModelConfig\";\nimport type { AssistantToolUIsState } from \"./stores/AssistantToolUIs\";\n\nexport type AssistantContextValue = {\n useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;\n useToolUIs: UseBoundStore<StoreApi<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 { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ContentPartState } from \"./stores/ContentPart\";\n\nexport type ContentPartContextValue = {\n useContentPart: UseBoundStore<StoreApi<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;AAUnC,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;;;ACnBA,SAAS,iBAAAA,gBAAe,cAAAC,mBAAkB;AAYnC,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;;;ACrBA,SAAS,cAAAC,aAAY,eAAe;AAY7B,IAAM,qBAAqB,MAA4B;AAC5D,QAAM,EAAE,YAAY,IAAI,iBAAiB;AACzC,QAAM,EAAE,aAAa,gBAAgB,IAAIC,YAAW,cAAc,KAAK,CAAC;AACxE,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;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,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","useContext","useContext","createContext","useContext","createContext","useContext"]}
|
package/dist/experimental.d.mts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { M as ModelConfigProvider, e as ThreadMessage, d as Unsubscribe, a as ToolCallContentPartComponent, c as ThreadState, m as Tool } from './Thread-
|
2
|
-
export { n as ImageContentPart, I as ImageContentPartComponent, r as ImageContentPartProps, f as ModelConfig, T as TextContentPartComponent, q as TextContentPartProps, o as ToolCallContentPart, b as ToolCallContentPartProps, p as UIContentPart, U as UIContentPartComponent, s as UIContentPartProps } from './Thread-
|
1
|
+
import { M as ModelConfigProvider, e as ThreadMessage, d as Unsubscribe, a as ToolCallContentPartComponent, c as ThreadState, m as Tool } from './Thread-CoxBELWy.mjs';
|
2
|
+
export { n as ImageContentPart, I as ImageContentPartComponent, r as ImageContentPartProps, f as ModelConfig, T as TextContentPartComponent, q as TextContentPartProps, o as ToolCallContentPart, b as ToolCallContentPartProps, p as UIContentPart, U as UIContentPartComponent, s as UIContentPartProps } from './Thread-CoxBELWy.mjs';
|
3
3
|
import { ReactNode } from 'react';
|
4
4
|
import { UseBoundStore, StoreApi } from 'zustand';
|
5
5
|
import 'zod';
|
@@ -51,14 +51,14 @@ type ThreadViewportState = {
|
|
51
51
|
onScrollToBottom: (callback: () => void) => Unsubscribe;
|
52
52
|
};
|
53
53
|
|
54
|
-
type
|
55
|
-
|
56
|
-
|
54
|
+
type AssistantToolUIsState = {
|
55
|
+
getToolUI: (toolName: string) => ToolCallContentPartComponent | null;
|
56
|
+
setToolUI: (toolName: string, render: ToolCallContentPartComponent) => () => void;
|
57
57
|
};
|
58
58
|
|
59
59
|
type AssistantContextValue = {
|
60
60
|
useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;
|
61
|
-
|
61
|
+
useToolUIs: UseBoundStore<StoreApi<AssistantToolUIsState>>;
|
62
62
|
};
|
63
63
|
declare const useAssistantContext: () => AssistantContextValue;
|
64
64
|
|
@@ -89,19 +89,19 @@ declare const useContentPartContext: () => ContentPartContextValue;
|
|
89
89
|
declare const useAssistantInstructions: (instruction: string) => void;
|
90
90
|
|
91
91
|
type AssistantToolProps<TArgs, TResult> = Tool<TArgs, TResult> & {
|
92
|
-
|
92
|
+
toolName: string;
|
93
93
|
render?: ToolCallContentPartComponent<TArgs, TResult>;
|
94
94
|
};
|
95
95
|
declare const useAssistantTool: <TArgs, TResult>(tool: AssistantToolProps<TArgs, TResult>) => void;
|
96
96
|
|
97
|
-
type
|
98
|
-
|
97
|
+
type AssistantToolUIProps<TArgs, TResult> = {
|
98
|
+
toolName: string;
|
99
99
|
render: ToolCallContentPartComponent<TArgs, TResult>;
|
100
100
|
};
|
101
|
-
declare const
|
101
|
+
declare const useAssistantToolUI: (tool: AssistantToolUIProps<any, any> | null) => void;
|
102
102
|
|
103
|
-
declare const
|
103
|
+
declare const makeAssistantTool: <TArgs, TResult>(tool: AssistantToolProps<TArgs, TResult>) => () => null;
|
104
104
|
|
105
|
-
declare const
|
105
|
+
declare const makeAssistantToolUI: <TArgs, TResult>(tool: AssistantToolUIProps<TArgs, TResult>) => () => null;
|
106
106
|
|
107
|
-
export { type AssistantContextValue, type AssistantModelConfigState, type AssistantToolProps, type
|
107
|
+
export { type AssistantContextValue, type AssistantModelConfigState, type AssistantToolProps, type AssistantToolUIProps, type ComposerContextValue, type ComposerState, type ContentPartContextValue, type ContentPartState, type EditComposerState, type MessageContextValue, type MessageState, ModelConfigProvider, type ThreadContextValue, ThreadState, type ThreadViewportState, ToolCallContentPartComponent, makeAssistantTool, makeAssistantToolUI, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolUI, useComposerContext, useContentPartContext, useMessageContext, useThreadContext };
|
package/dist/experimental.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { M as ModelConfigProvider, e as ThreadMessage, d as Unsubscribe, a as ToolCallContentPartComponent, c as ThreadState, m as Tool } from './Thread-
|
2
|
-
export { n as ImageContentPart, I as ImageContentPartComponent, r as ImageContentPartProps, f as ModelConfig, T as TextContentPartComponent, q as TextContentPartProps, o as ToolCallContentPart, b as ToolCallContentPartProps, p as UIContentPart, U as UIContentPartComponent, s as UIContentPartProps } from './Thread-
|
1
|
+
import { M as ModelConfigProvider, e as ThreadMessage, d as Unsubscribe, a as ToolCallContentPartComponent, c as ThreadState, m as Tool } from './Thread-CoxBELWy.js';
|
2
|
+
export { n as ImageContentPart, I as ImageContentPartComponent, r as ImageContentPartProps, f as ModelConfig, T as TextContentPartComponent, q as TextContentPartProps, o as ToolCallContentPart, b as ToolCallContentPartProps, p as UIContentPart, U as UIContentPartComponent, s as UIContentPartProps } from './Thread-CoxBELWy.js';
|
3
3
|
import { ReactNode } from 'react';
|
4
4
|
import { UseBoundStore, StoreApi } from 'zustand';
|
5
5
|
import 'zod';
|
@@ -51,14 +51,14 @@ type ThreadViewportState = {
|
|
51
51
|
onScrollToBottom: (callback: () => void) => Unsubscribe;
|
52
52
|
};
|
53
53
|
|
54
|
-
type
|
55
|
-
|
56
|
-
|
54
|
+
type AssistantToolUIsState = {
|
55
|
+
getToolUI: (toolName: string) => ToolCallContentPartComponent | null;
|
56
|
+
setToolUI: (toolName: string, render: ToolCallContentPartComponent) => () => void;
|
57
57
|
};
|
58
58
|
|
59
59
|
type AssistantContextValue = {
|
60
60
|
useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;
|
61
|
-
|
61
|
+
useToolUIs: UseBoundStore<StoreApi<AssistantToolUIsState>>;
|
62
62
|
};
|
63
63
|
declare const useAssistantContext: () => AssistantContextValue;
|
64
64
|
|
@@ -89,19 +89,19 @@ declare const useContentPartContext: () => ContentPartContextValue;
|
|
89
89
|
declare const useAssistantInstructions: (instruction: string) => void;
|
90
90
|
|
91
91
|
type AssistantToolProps<TArgs, TResult> = Tool<TArgs, TResult> & {
|
92
|
-
|
92
|
+
toolName: string;
|
93
93
|
render?: ToolCallContentPartComponent<TArgs, TResult>;
|
94
94
|
};
|
95
95
|
declare const useAssistantTool: <TArgs, TResult>(tool: AssistantToolProps<TArgs, TResult>) => void;
|
96
96
|
|
97
|
-
type
|
98
|
-
|
97
|
+
type AssistantToolUIProps<TArgs, TResult> = {
|
98
|
+
toolName: string;
|
99
99
|
render: ToolCallContentPartComponent<TArgs, TResult>;
|
100
100
|
};
|
101
|
-
declare const
|
101
|
+
declare const useAssistantToolUI: (tool: AssistantToolUIProps<any, any> | null) => void;
|
102
102
|
|
103
|
-
declare const
|
103
|
+
declare const makeAssistantTool: <TArgs, TResult>(tool: AssistantToolProps<TArgs, TResult>) => () => null;
|
104
104
|
|
105
|
-
declare const
|
105
|
+
declare const makeAssistantToolUI: <TArgs, TResult>(tool: AssistantToolUIProps<TArgs, TResult>) => () => null;
|
106
106
|
|
107
|
-
export { type AssistantContextValue, type AssistantModelConfigState, type AssistantToolProps, type
|
107
|
+
export { type AssistantContextValue, type AssistantModelConfigState, type AssistantToolProps, type AssistantToolUIProps, type ComposerContextValue, type ComposerState, type ContentPartContextValue, type ContentPartState, type EditComposerState, type MessageContextValue, type MessageState, ModelConfigProvider, type ThreadContextValue, ThreadState, type ThreadViewportState, ToolCallContentPartComponent, makeAssistantTool, makeAssistantToolUI, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolUI, useComposerContext, useContentPartContext, useMessageContext, useThreadContext };
|
package/dist/experimental.js
CHANGED
@@ -20,12 +20,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
20
20
|
// src/experimental.ts
|
21
21
|
var experimental_exports = {};
|
22
22
|
__export(experimental_exports, {
|
23
|
-
|
24
|
-
|
23
|
+
makeAssistantTool: () => makeAssistantTool,
|
24
|
+
makeAssistantToolUI: () => makeAssistantToolUI,
|
25
25
|
useAssistantContext: () => useAssistantContext,
|
26
26
|
useAssistantInstructions: () => useAssistantInstructions,
|
27
27
|
useAssistantTool: () => useAssistantTool,
|
28
|
-
|
28
|
+
useAssistantToolUI: () => useAssistantToolUI,
|
29
29
|
useComposerContext: () => useComposerContext,
|
30
30
|
useContentPartContext: () => useContentPartContext,
|
31
31
|
useMessageContext: () => useMessageContext,
|
@@ -53,7 +53,9 @@ var ThreadContext = (0, import_react2.createContext)(null);
|
|
53
53
|
var useThreadContext = () => {
|
54
54
|
const context = (0, import_react2.useContext)(ThreadContext);
|
55
55
|
if (!context)
|
56
|
-
throw new Error(
|
56
|
+
throw new Error(
|
57
|
+
"This component must be used within an AssistantRuntimeProvider."
|
58
|
+
);
|
57
59
|
return context;
|
58
60
|
};
|
59
61
|
|
@@ -117,41 +119,41 @@ var useAssistantInstructions = (instruction) => {
|
|
117
119
|
// src/model-config/useAssistantTool.tsx
|
118
120
|
var import_react7 = require("react");
|
119
121
|
var useAssistantTool = (tool) => {
|
120
|
-
const { useModelConfig,
|
122
|
+
const { useModelConfig, useToolUIs } = useAssistantContext();
|
121
123
|
const registerModelConfigProvider = useModelConfig(
|
122
124
|
(s) => s.registerModelConfigProvider
|
123
125
|
);
|
124
|
-
const
|
126
|
+
const setToolUI = useToolUIs((s) => s.setToolUI);
|
125
127
|
(0, import_react7.useEffect)(() => {
|
126
|
-
const {
|
128
|
+
const { toolName, render, ...rest } = tool;
|
127
129
|
const config = {
|
128
130
|
tools: {
|
129
|
-
[tool.
|
131
|
+
[tool.toolName]: rest
|
130
132
|
}
|
131
133
|
};
|
132
134
|
const unsub1 = registerModelConfigProvider(() => config);
|
133
|
-
const unsub2 = render ?
|
135
|
+
const unsub2 = render ? setToolUI(toolName, render) : void 0;
|
134
136
|
return () => {
|
135
137
|
unsub1();
|
136
138
|
unsub2?.();
|
137
139
|
};
|
138
|
-
}, [registerModelConfigProvider,
|
140
|
+
}, [registerModelConfigProvider, setToolUI, tool]);
|
139
141
|
};
|
140
142
|
|
141
|
-
// src/model-config/
|
143
|
+
// src/model-config/useAssistantToolUI.tsx
|
142
144
|
var import_react8 = require("react");
|
143
|
-
var
|
144
|
-
const {
|
145
|
-
const
|
145
|
+
var useAssistantToolUI = (tool) => {
|
146
|
+
const { useToolUIs } = useAssistantContext();
|
147
|
+
const setToolUI = useToolUIs((s) => s.setToolUI);
|
146
148
|
(0, import_react8.useEffect)(() => {
|
147
149
|
if (!tool) return;
|
148
|
-
const {
|
149
|
-
return
|
150
|
-
}, [
|
150
|
+
const { toolName, render } = tool;
|
151
|
+
return setToolUI(toolName, render);
|
152
|
+
}, [setToolUI, tool]);
|
151
153
|
};
|
152
154
|
|
153
|
-
// src/model-config/
|
154
|
-
var
|
155
|
+
// src/model-config/makeAssistantTool.tsx
|
156
|
+
var makeAssistantTool = (tool) => {
|
155
157
|
const Tool = () => {
|
156
158
|
useAssistantTool(tool);
|
157
159
|
return null;
|
@@ -159,22 +161,22 @@ var makeTool = (tool) => {
|
|
159
161
|
return Tool;
|
160
162
|
};
|
161
163
|
|
162
|
-
// src/model-config/
|
163
|
-
var
|
164
|
-
const
|
165
|
-
|
164
|
+
// src/model-config/makeAssistantToolUI.tsx
|
165
|
+
var makeAssistantToolUI = (tool) => {
|
166
|
+
const ToolUI = () => {
|
167
|
+
useAssistantToolUI(tool);
|
166
168
|
return null;
|
167
169
|
};
|
168
|
-
return
|
170
|
+
return ToolUI;
|
169
171
|
};
|
170
172
|
// Annotate the CommonJS export names for ESM import in node:
|
171
173
|
0 && (module.exports = {
|
172
|
-
|
173
|
-
|
174
|
+
makeAssistantTool,
|
175
|
+
makeAssistantToolUI,
|
174
176
|
useAssistantContext,
|
175
177
|
useAssistantInstructions,
|
176
178
|
useAssistantTool,
|
177
|
-
|
179
|
+
useAssistantToolUI,
|
178
180
|
useComposerContext,
|
179
181
|
useContentPartContext,
|
180
182
|
useMessageContext,
|
package/dist/experimental.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/experimental.ts","../src/context/AssistantContext.ts","../src/context/ThreadContext.ts","../src/context/ComposerContext.ts","../src/context/MessageContext.ts","../src/context/ContentPartContext.ts","../src/model-config/useAssistantInstructions.tsx","../src/model-config/useAssistantTool.tsx","../src/model-config/useAssistantToolRenderer.tsx","../src/model-config/makeTool.tsx","../src/model-config/makeToolRenderer.tsx"],"sourcesContent":["export type {\n ImageContentPart,\n ToolCallContentPart,\n UIContentPart,\n} from \"./utils/AssistantTypes\";\n\nexport type {\n ModelConfigProvider,\n ModelConfig,\n} from \"./utils/ModelConfigTypes\";\n\nexport type {\n TextContentPartProps,\n TextContentPartComponent,\n ImageContentPartProps,\n ImageContentPartComponent,\n UIContentPartProps,\n UIContentPartComponent,\n ToolCallContentPartProps,\n ToolCallContentPartComponent,\n} from \"./primitives/message/ContentPartComponentTypes\";\n\nexport * from \"./context\";\nexport { useAssistantInstructions } from \"./model-config/useAssistantInstructions\";\nexport {\n useAssistantTool,\n type AssistantToolProps,\n} from \"./model-config/useAssistantTool\";\nexport {\n useAssistantToolRenderer,\n type AssistantToolRendererProps,\n} from \"./model-config/useAssistantToolRenderer\";\nexport { makeTool } from \"./model-config/makeTool\";\nexport { makeToolRenderer } from \"./model-config/makeToolRenderer\";\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { AssistantModelConfigState } from \"./stores/AssistantModelConfig\";\nimport type { AssistantToolRenderersState } from \"./stores/AssistantToolRenderers\";\n\nexport type AssistantContextValue = {\n useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;\n useToolRenderers: UseBoundStore<StoreApi<AssistantToolRenderersState>>;\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 { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { ThreadState } from \"./stores/Thread\";\nimport type { ThreadViewportState } from \"./stores/ThreadViewport\";\n\nexport type ThreadContextValue = {\n useThread: UseBoundStore<StoreApi<ThreadState>>;\n useComposer: UseBoundStore<StoreApi<ComposerState>>;\n useViewport: UseBoundStore<StoreApi<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(\"This component must be used within an AssistantRuntimeProvider.\");\n return context;\n};\n","import { useContext, useMemo } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport { MessageContext } from \"./MessageContext\";\nimport { useThreadContext } from \"./ThreadContext\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type ComposerContextValue = {\n useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;\n type: \"edit\" | \"new\";\n};\n\nexport const useComposerContext = (): ComposerContextValue => {\n const { useComposer } = useThreadContext();\n const { useComposer: useEditComposer } = useContext(MessageContext) ?? {};\n return useMemo(\n () => ({\n useComposer: (useEditComposer ?? useComposer) as UseBoundStore<\n StoreApi<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 { StoreApi, UseBoundStore } from \"zustand\";\nimport type { MessageState } from \"./stores/Message\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type MessageContextValue = {\n useMessage: UseBoundStore<StoreApi<MessageState>>;\n useComposer: UseBoundStore<StoreApi<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 { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ContentPartState } from \"./stores/ContentPart\";\n\nexport type ContentPartContextValue = {\n useContentPart: UseBoundStore<StoreApi<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","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\n\nexport const useAssistantInstructions = (instruction: string) => {\n const { useModelConfig } = useAssistantContext();\n const registerModelConfigProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n useEffect(() => {\n const config = {\n system: instruction,\n };\n return registerModelConfigProvider(() => config);\n }, [registerModelConfigProvider, instruction]);\n};\n","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../primitives/message/ContentPartComponentTypes\";\nimport type { Tool } from \"../utils/ModelConfigTypes\";\n\nexport type AssistantToolProps<TArgs, TResult> = Tool<TArgs, TResult> & {\n name: string;\n render?: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantTool = <TArgs, TResult>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const { useModelConfig, useToolRenderers } = useAssistantContext();\n const registerModelConfigProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n const setToolRenderer = useToolRenderers((s) => s.setToolRenderer);\n useEffect(() => {\n const { name, render, ...rest } = tool;\n const config = {\n tools: {\n [tool.name]: rest,\n },\n };\n const unsub1 = registerModelConfigProvider(() => config);\n const unsub2 = render ? setToolRenderer(name, render) : undefined;\n return () => {\n unsub1();\n unsub2?.();\n };\n }, [registerModelConfigProvider, setToolRenderer, tool]);\n};\n","\"use client\";\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../primitives/message/ContentPartComponentTypes\";\n\nexport type AssistantToolRendererProps<TArgs, TResult> = {\n name: string;\n render: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantToolRenderer = (\n // biome-ignore lint/suspicious/noExplicitAny: intentional any\n tool: AssistantToolRendererProps<any, any> | null,\n) => {\n const { useToolRenderers } = useAssistantContext();\n const setToolRenderer = useToolRenderers((s) => s.setToolRenderer);\n useEffect(() => {\n if (!tool) return;\n const { name, render } = tool;\n return setToolRenderer(name, render);\n }, [setToolRenderer, tool]);\n};\n","\"use client\";\nimport { type AssistantToolProps, useAssistantTool } from \"./useAssistantTool\";\n\nexport const makeTool = <TArgs, TResult>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const Tool = () => {\n useAssistantTool(tool);\n return null;\n };\n return Tool;\n};\n","\"use client\";\nimport {\n type AssistantToolRendererProps,\n useAssistantToolRenderer,\n} from \"./useAssistantToolRenderer\";\n\nexport const makeToolRenderer = <TArgs, TResult>(\n tool: AssistantToolRendererProps<TArgs, TResult>,\n) => {\n const ToolRenderer = ()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ACtB,SACG;AACH,QAAM,OAAO,MAAM;AACjB,qBAAiB,IAAI;AACrB,WAAO;AAAA,EACT;AACA,SAAO;AACT;;;ACLO,IAAM,mBAAmB,CAC9B,SACG;AACH,QAAM,eAAe,MAAM;AACzB,6BAAyB,IAAI;AAC7B,WAAO;AAAA,EACT;AACA,SAAO;AACT;","names":["import_react","import_react","import_react","import_react","import_react","import_react","import_react"]}
|
1
|
+
{"version":3,"sources":["../src/experimental.ts","../src/context/AssistantContext.ts","../src/context/ThreadContext.ts","../src/context/ComposerContext.ts","../src/context/MessageContext.ts","../src/context/ContentPartContext.ts","../src/model-config/useAssistantInstructions.tsx","../src/model-config/useAssistantTool.tsx","../src/model-config/useAssistantToolUI.tsx","../src/model-config/makeAssistantTool.tsx","../src/model-config/makeAssistantToolUI.tsx"],"sourcesContent":["export type {\n ImageContentPart,\n ToolCallContentPart,\n UIContentPart,\n} from \"./utils/AssistantTypes\";\n\nexport type {\n ModelConfigProvider,\n ModelConfig,\n} from \"./utils/ModelConfigTypes\";\n\nexport type {\n TextContentPartProps,\n TextContentPartComponent,\n ImageContentPartProps,\n ImageContentPartComponent,\n UIContentPartProps,\n UIContentPartComponent,\n ToolCallContentPartProps,\n ToolCallContentPartComponent,\n} from \"./primitives/message/ContentPartComponentTypes\";\n\nexport * from \"./context\";\nexport { useAssistantInstructions } from \"./model-config/useAssistantInstructions\";\nexport {\n useAssistantTool,\n type AssistantToolProps,\n} from \"./model-config/useAssistantTool\";\nexport {\n useAssistantToolUI,\n type AssistantToolUIProps,\n} from \"./model-config/useAssistantToolUI\";\nexport { makeAssistantTool } from \"./model-config/makeAssistantTool\";\nexport { makeAssistantToolUI } from \"./model-config/makeAssistantToolUI\";\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { AssistantModelConfigState } from \"./stores/AssistantModelConfig\";\nimport type { AssistantToolUIsState } from \"./stores/AssistantToolUIs\";\n\nexport type AssistantContextValue = {\n useModelConfig: UseBoundStore<StoreApi<AssistantModelConfigState>>;\n useToolUIs: UseBoundStore<StoreApi<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 { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { ThreadState } from \"./stores/Thread\";\nimport type { ThreadViewportState } from \"./stores/ThreadViewport\";\n\nexport type ThreadContextValue = {\n useThread: UseBoundStore<StoreApi<ThreadState>>;\n useComposer: UseBoundStore<StoreApi<ComposerState>>;\n useViewport: UseBoundStore<StoreApi<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 { useContext, useMemo } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport { MessageContext } from \"./MessageContext\";\nimport { useThreadContext } from \"./ThreadContext\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type ComposerContextValue = {\n useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;\n type: \"edit\" | \"new\";\n};\n\nexport const useComposerContext = (): ComposerContextValue => {\n const { useComposer } = useThreadContext();\n const { useComposer: useEditComposer } = useContext(MessageContext) ?? {};\n return useMemo(\n () => ({\n useComposer: (useEditComposer ?? useComposer) as UseBoundStore<\n StoreApi<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 { StoreApi, UseBoundStore } from \"zustand\";\nimport type { MessageState } from \"./stores/Message\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type MessageContextValue = {\n useMessage: UseBoundStore<StoreApi<MessageState>>;\n useComposer: UseBoundStore<StoreApi<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 { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ContentPartState } from \"./stores/ContentPart\";\n\nexport type ContentPartContextValue = {\n useContentPart: UseBoundStore<StoreApi<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","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\n\nexport const useAssistantInstructions = (instruction: string) => {\n const { useModelConfig } = useAssistantContext();\n const registerModelConfigProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n useEffect(() => {\n const config = {\n system: instruction,\n };\n return registerModelConfigProvider(() => config);\n }, [registerModelConfigProvider, instruction]);\n};\n","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../primitives/message/ContentPartComponentTypes\";\nimport type { Tool } from \"../utils/ModelConfigTypes\";\n\nexport type AssistantToolProps<TArgs, TResult> = Tool<TArgs, TResult> & {\n toolName: string;\n render?: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantTool = <TArgs, TResult>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const { useModelConfig, useToolUIs } = useAssistantContext();\n const registerModelConfigProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n const setToolUI = useToolUIs((s) => s.setToolUI);\n useEffect(() => {\n const { toolName, render, ...rest } = tool;\n const config = {\n tools: {\n [tool.toolName]: rest,\n },\n };\n const unsub1 = registerModelConfigProvider(() => config);\n const unsub2 = render ? setToolUI(toolName, render) : undefined;\n return () => {\n unsub1();\n unsub2?.();\n };\n }, [registerModelConfigProvider, setToolUI, tool]);\n};\n","\"use client\";\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../primitives/message/ContentPartComponentTypes\";\n\nexport type AssistantToolUIProps<TArgs, TResult> = {\n toolName: string;\n render: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantToolUI = (\n tool: AssistantToolUIProps<any, any> | null,\n) => {\n const { useToolUIs } = useAssistantContext();\n const setToolUI = useToolUIs((s) => s.setToolUI);\n useEffect(() => {\n if (!tool) return;\n const { toolName, render } = tool;\n return setToolUI(toolName, render);\n }, [setToolUI, tool]);\n};\n","\"use client\";\nimport { type AssistantToolProps, useAssistantTool } from \"./useAssistantTool\";\n\nexport const makeAssistantTool = <TArgs, TResult>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const Tool = () => {\n useAssistantTool(tool);\n return null;\n };\n return Tool;\n};\n","\"use client\";\nimport {\n type AssistantToolUIProps,\n useAssistantToolUI,\n} from \"./useAssistantToolUI\";\n\nexport const makeAssistantToolUI = <TArgs, TResult>(\n tool: AssistantToolUIProps<TArgs, TResult>,\n) => {\n const ToolUI = () => {\n useAssistantToolUI(tool);\n return null;\n };\n return ToolUI;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA0C;AAUnC,IAAM,uBAAmB;AAAA,EAC9B;AACF;AAEO,IAAM,s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AAA,IACV;AACA,WAAO,4BAA4B,MAAM,MAAM;AAAA,EACjD,GAAG,CAAC,6BAA6B,WAAW,CAAC;AAC/C;;;ACdA,IAAAC,gBAA0B;AAUnB,IAAM,mBAAmB,CAC9B,SACG;AACH,QAAM,EAAE,gBAAgB,WAAW,IAAI,oBAAoB;AAC3D,QAAM,8BAA8B;AAAA,IAClC,CAAC,MAAM,EAAE;AAAA,EACX;AACA,QAAM,YAAY,WAAW,CAAC,MAAM,EAAE,SAAS;AAC/C,+BAAU,MAAM;AACd,UAAM,EAAE,UAAU,QAAQ,GAAG,KAAK,IAAI;AACtC,UAAM,SAAS;AAAA,MACb,OAAO;AAAA,QACL,CAAC,KAAK,QAAQ,GAAG;AAAA,MACnB;AAAA,IACF;AACA,UAAM,SAAS,4BAA4B,MAAM,MAAM;AACvD,UAAM,SAAS,SAAS,UAAU,UAAU,MAAM,IAAI;AACtD,WAAO,MAAM;AACX,aAAO;AACP,eAAS;AAAA,IACX;AAAA,EACF,GAAG,CAAC,6BAA6B,WAAW,IAAI,CAAC;AACnD;;;ACjCA,IAAAC,gBAA0B;AASnB,IAAM,qBAAqB,CAChC,SACG;AACH,QAAM,EAAE,WAAW,IAAI,oBAAoB;AAC3C,QAAM,YAAY,WAAW,CAAC,MAAM,EAAE,SAAS;AAC/C,+BAAU,MAAM;AACd,QAAI,CAAC,KAAM;AACX,UAAM,EAAE,UAAU,OAAO,IAAI;AAC7B,WAAO,UAAU,UAAU,MAAM;AAAA,EACnC,GAAG,CAAC,WAAW,IAAI,CAAC;AACtB;;;ACjBO,IAAM,oBAAoB,CAC/B,SACG;AACH,QAAM,OAAO,MAAM;AACjB,qBAAiB,IAAI;AACrB,WAAO;AAAA,EACT;AACA,SAAO;AACT;;;ACLO,IAAM,sBAAsB,CACjC,SACG;AACH,QAAM,SAAS,MAAM;AACnB,uBAAmB,IAAI;AACvB,WAAO;AAAA,EACT;AACA,SAAO;AACT;","names":["import_react","import_react","import_react","import_react","import_react","import_react","import_react"]}
|
package/dist/experimental.mjs
CHANGED
@@ -4,7 +4,7 @@ import {
|
|
4
4
|
useContentPartContext,
|
5
5
|
useMessageContext,
|
6
6
|
useThreadContext
|
7
|
-
} from "./chunk-
|
7
|
+
} from "./chunk-RITM2IUH.mjs";
|
8
8
|
|
9
9
|
// src/model-config/useAssistantInstructions.tsx
|
10
10
|
import { useEffect } from "react";
|
@@ -24,41 +24,41 @@ var useAssistantInstructions = (instruction) => {
|
|
24
24
|
// src/model-config/useAssistantTool.tsx
|
25
25
|
import { useEffect as useEffect2 } from "react";
|
26
26
|
var useAssistantTool = (tool) => {
|
27
|
-
const { useModelConfig,
|
27
|
+
const { useModelConfig, useToolUIs } = useAssistantContext();
|
28
28
|
const registerModelConfigProvider = useModelConfig(
|
29
29
|
(s) => s.registerModelConfigProvider
|
30
30
|
);
|
31
|
-
const
|
31
|
+
const setToolUI = useToolUIs((s) => s.setToolUI);
|
32
32
|
useEffect2(() => {
|
33
|
-
const {
|
33
|
+
const { toolName, render, ...rest } = tool;
|
34
34
|
const config = {
|
35
35
|
tools: {
|
36
|
-
[tool.
|
36
|
+
[tool.toolName]: rest
|
37
37
|
}
|
38
38
|
};
|
39
39
|
const unsub1 = registerModelConfigProvider(() => config);
|
40
|
-
const unsub2 = render ?
|
40
|
+
const unsub2 = render ? setToolUI(toolName, render) : void 0;
|
41
41
|
return () => {
|
42
42
|
unsub1();
|
43
43
|
unsub2?.();
|
44
44
|
};
|
45
|
-
}, [registerModelConfigProvider,
|
45
|
+
}, [registerModelConfigProvider, setToolUI, tool]);
|
46
46
|
};
|
47
47
|
|
48
|
-
// src/model-config/
|
48
|
+
// src/model-config/useAssistantToolUI.tsx
|
49
49
|
import { useEffect as useEffect3 } from "react";
|
50
|
-
var
|
51
|
-
const {
|
52
|
-
const
|
50
|
+
var useAssistantToolUI = (tool) => {
|
51
|
+
const { useToolUIs } = useAssistantContext();
|
52
|
+
const setToolUI = useToolUIs((s) => s.setToolUI);
|
53
53
|
useEffect3(() => {
|
54
54
|
if (!tool) return;
|
55
|
-
const {
|
56
|
-
return
|
57
|
-
}, [
|
55
|
+
const { toolName, render } = tool;
|
56
|
+
return setToolUI(toolName, render);
|
57
|
+
}, [setToolUI, tool]);
|
58
58
|
};
|
59
59
|
|
60
|
-
// src/model-config/
|
61
|
-
var
|
60
|
+
// src/model-config/makeAssistantTool.tsx
|
61
|
+
var makeAssistantTool = (tool) => {
|
62
62
|
const Tool = () => {
|
63
63
|
useAssistantTool(tool);
|
64
64
|
return null;
|
@@ -66,21 +66,21 @@ var makeTool = (tool) => {
|
|
66
66
|
return Tool;
|
67
67
|
};
|
68
68
|
|
69
|
-
// src/model-config/
|
70
|
-
var
|
71
|
-
const
|
72
|
-
|
69
|
+
// src/model-config/makeAssistantToolUI.tsx
|
70
|
+
var makeAssistantToolUI = (tool) => {
|
71
|
+
const ToolUI = () => {
|
72
|
+
useAssistantToolUI(tool);
|
73
73
|
return null;
|
74
74
|
};
|
75
|
-
return
|
75
|
+
return ToolUI;
|
76
76
|
};
|
77
77
|
export {
|
78
|
-
|
79
|
-
|
78
|
+
makeAssistantTool,
|
79
|
+
makeAssistantToolUI,
|
80
80
|
useAssistantContext,
|
81
81
|
useAssistantInstructions,
|
82
82
|
useAssistantTool,
|
83
|
-
|
83
|
+
useAssistantToolUI,
|
84
84
|
useComposerContext,
|
85
85
|
useContentPartContext,
|
86
86
|
useMessageContext,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/model-config/useAssistantInstructions.tsx","../src/model-config/useAssistantTool.tsx","../src/model-config/
|
1
|
+
{"version":3,"sources":["../src/model-config/useAssistantInstructions.tsx","../src/model-config/useAssistantTool.tsx","../src/model-config/useAssistantToolUI.tsx","../src/model-config/makeAssistantTool.tsx","../src/model-config/makeAssistantToolUI.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\n\nexport const useAssistantInstructions = (instruction: string) => {\n const { useModelConfig } = useAssistantContext();\n const registerModelConfigProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n useEffect(() => {\n const config = {\n system: instruction,\n };\n return registerModelConfigProvider(() => config);\n }, [registerModelConfigProvider, instruction]);\n};\n","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../primitives/message/ContentPartComponentTypes\";\nimport type { Tool } from \"../utils/ModelConfigTypes\";\n\nexport type AssistantToolProps<TArgs, TResult> = Tool<TArgs, TResult> & {\n toolName: string;\n render?: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantTool = <TArgs, TResult>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const { useModelConfig, useToolUIs } = useAssistantContext();\n const registerModelConfigProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n const setToolUI = useToolUIs((s) => s.setToolUI);\n useEffect(() => {\n const { toolName, render, ...rest } = tool;\n const config = {\n tools: {\n [tool.toolName]: rest,\n },\n };\n const unsub1 = registerModelConfigProvider(() => config);\n const unsub2 = render ? setToolUI(toolName, render) : undefined;\n return () => {\n unsub1();\n unsub2?.();\n };\n }, [registerModelConfigProvider, setToolUI, tool]);\n};\n","\"use client\";\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../primitives/message/ContentPartComponentTypes\";\n\nexport type AssistantToolUIProps<TArgs, TResult> = {\n toolName: string;\n render: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantToolUI = (\n tool: AssistantToolUIProps<any, any> | null,\n) => {\n const { useToolUIs } = useAssistantContext();\n const setToolUI = useToolUIs((s) => s.setToolUI);\n useEffect(() => {\n if (!tool) return;\n const { toolName, render } = tool;\n return setToolUI(toolName, render);\n }, [setToolUI, tool]);\n};\n","\"use client\";\nimport { type AssistantToolProps, useAssistantTool } from \"./useAssistantTool\";\n\nexport const makeAssistantTool = <TArgs, TResult>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const Tool = () => {\n useAssistantTool(tool);\n return null;\n };\n return Tool;\n};\n","\"use client\";\nimport {\n type AssistantToolUIProps,\n useAssistantToolUI,\n} from \"./useAssistantToolUI\";\n\nexport const makeAssistantToolUI = <TArgs, TResult>(\n tool: AssistantToolUIProps<TArgs, TResult>,\n) => {\n const ToolUI = () => {\n useAssistantToolUI(tool);\n return null;\n };\n return ToolUI;\n};\n"],"mappings":";;;;;;;;;AAEA,SAAS,iBAAiB;AAGnB,IAAM,2BAA2B,CAAC,gBAAwB;AAC/D,QAAM,EAAE,eAAe,IAAI,oBAAoB;AAC/C,QAAM,8BAA8B;AAAA,IAClC,CAAC,MAAM,EAAE;AAAA,EACX;AACA,YAAU,MAAM;AACd,UAAM,SAAS;AAAA,MACb,QAAQ;AAAA,IACV;AACA,WAAO,4BAA4B,MAAM,MAAM;AAAA,EACjD,GAAG,CAAC,6BAA6B,WAAW,CAAC;AAC/C;;;ACdA,SAAS,aAAAA,kBAAiB;AAUnB,IAAM,mBAAmB,CAC9B,SACG;AACH,QAAM,EAAE,gBAAgB,WAAW,IAAI,oBAAoB;AAC3D,QAAM,8BAA8B;AAAA,IAClC,CAAC,MAAM,EAAE;AAAA,EACX;AACA,QAAM,YAAY,WAAW,CAAC,MAAM,EAAE,SAAS;AAC/C,EAAAC,WAAU,MAAM;AACd,UAAM,EAAE,UAAU,QAAQ,GAAG,KAAK,IAAI;AACtC,UAAM,SAAS;AAAA,MACb,OAAO;AAAA,QACL,CAAC,KAAK,QAAQ,GAAG;AAAA,MACnB;AAAA,IACF;AACA,UAAM,SAAS,4BAA4B,MAAM,MAAM;AACvD,UAAM,SAAS,SAAS,UAAU,UAAU,MAAM,IAAI;AACtD,WAAO,MAAM;AACX,aAAO;AACP,eAAS;AAAA,IACX;AAAA,EACF,GAAG,CAAC,6BAA6B,WAAW,IAAI,CAAC;AACnD;;;ACjCA,SAAS,aAAAC,kB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