@assistant-ui/react 0.1.12 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,116 +1,2 @@
1
- import { M as ModelConfigProvider, f as ThreadMessage, e as Unsubscribe, a as ToolCallContentPartComponent, c as ThreadState, d as ThreadActionsState, n as Tool } from './ThreadActions-BLcKtagX.mjs';
2
- export { o as ImageContentPart, I as ImageContentPartComponent, s as ImageContentPartProps, g as ModelConfig, T as TextContentPartComponent, r as TextContentPartProps, p as ToolCallContentPart, b as ToolCallContentPartProps, q as UIContentPart, U as UIContentPartComponent, t as UIContentPartProps } from './ThreadActions-BLcKtagX.mjs';
3
- import { UseBoundStore, StoreApi } from 'zustand';
4
- import { ReactNode } from 'react';
5
- import 'zod';
6
1
 
7
- type AssistantModelConfigState = Readonly<{
8
- getModelConfig: ModelConfigProvider;
9
- registerModelConfigProvider: (provider: ModelConfigProvider) => () => void;
10
- }>;
11
-
12
- type ContentPartState = Readonly<{
13
- status: "in_progress" | "done" | "error";
14
- part: ThreadMessage["content"][number];
15
- }>;
16
-
17
- type MessageState = Readonly<{
18
- message: Readonly<ThreadMessage>;
19
- parentId: string | null;
20
- branches: readonly string[];
21
- isLast: boolean;
22
- }>;
23
-
24
- type BaseComposerState = Readonly<{
25
- value: string;
26
- setValue: (value: string) => void;
27
- }>;
28
-
29
- type ReadonlyStore<T> = UseBoundStore<Omit<StoreApi<T>, "setState" | "destroy" | "getInitialState">>;
30
-
31
- type EditComposerState = BaseComposerState & Readonly<{
32
- isEditing: boolean;
33
- edit: () => void;
34
- send: () => void;
35
- cancel: () => boolean;
36
- }>;
37
-
38
- type ComposerState = BaseComposerState & Readonly<{
39
- isEditing: true;
40
- send: () => void;
41
- cancel: () => boolean;
42
- focus: () => void;
43
- onFocus: (listener: () => void) => Unsubscribe;
44
- }>;
45
-
46
- type ThreadViewportState = Readonly<{
47
- isAtBottom: boolean;
48
- scrollToBottom: () => void;
49
- onScrollToBottom: (callback: () => void) => Unsubscribe;
50
- }>;
51
-
52
- type AssistantToolUIsState = Readonly<{
53
- getToolUI: (toolName: string) => ToolCallContentPartComponent | null;
54
- setToolUI: (toolName: string, render: ToolCallContentPartComponent) => () => void;
55
- }>;
56
-
57
- type AssistantContextValue = {
58
- useModelConfig: ReadonlyStore<AssistantModelConfigState>;
59
- useToolUIs: ReadonlyStore<AssistantToolUIsState>;
60
- };
61
- declare const useAssistantContext: () => AssistantContextValue;
62
-
63
- type ThreadContextValue = {
64
- useThread: ReadonlyStore<ThreadState>;
65
- useThreadActions: ReadonlyStore<ThreadActionsState>;
66
- useComposer: ReadonlyStore<ComposerState>;
67
- useViewport: ReadonlyStore<ThreadViewportState>;
68
- };
69
- declare const useThreadContext: () => ThreadContextValue;
70
-
71
- type ComposerContextValue = {
72
- useComposer: ReadonlyStore<EditComposerState | ComposerState>;
73
- type: "edit" | "new";
74
- };
75
- declare const useComposerContext: () => ComposerContextValue;
76
-
77
- type MessageUtilsState = Readonly<{
78
- inProgressIndicator: ReactNode | null;
79
- setInProgressIndicator: (value: ReactNode | null) => void;
80
- isCopied: boolean;
81
- setIsCopied: (value: boolean) => void;
82
- isHovering: boolean;
83
- setIsHovering: (value: boolean) => void;
84
- }>;
85
-
86
- type MessageContextValue = {
87
- useMessage: ReadonlyStore<MessageState>;
88
- useMessageUtils: ReadonlyStore<MessageUtilsState>;
89
- useEditComposer: ReadonlyStore<EditComposerState>;
90
- };
91
- declare const useMessageContext: () => MessageContextValue;
92
-
93
- type ContentPartContextValue = {
94
- useContentPart: ReadonlyStore<ContentPartState>;
95
- };
96
- declare const useContentPartContext: () => ContentPartContextValue;
97
-
98
- declare const useAssistantInstructions: (instruction: string) => void;
99
-
100
- type AssistantToolProps<TArgs, TResult> = Tool<TArgs, TResult> & {
101
- toolName: string;
102
- render?: ToolCallContentPartComponent<TArgs, TResult>;
103
- };
104
- declare const useAssistantTool: <TArgs, TResult>(tool: AssistantToolProps<TArgs, TResult>) => void;
105
-
106
- type AssistantToolUIProps<TArgs, TResult> = {
107
- toolName: string;
108
- render: ToolCallContentPartComponent<TArgs, TResult>;
109
- };
110
- declare const useAssistantToolUI: (tool: AssistantToolUIProps<any, any> | null) => void;
111
-
112
- declare const makeAssistantTool: <TArgs, TResult>(tool: AssistantToolProps<TArgs, TResult>) => () => null;
113
-
114
- declare const makeAssistantToolUI: <TArgs, TResult>(tool: AssistantToolUIProps<TArgs, TResult>) => () => null;
115
-
116
- 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 };
2
+ export { }
@@ -1,116 +1,2 @@
1
- import { M as ModelConfigProvider, f as ThreadMessage, e as Unsubscribe, a as ToolCallContentPartComponent, c as ThreadState, d as ThreadActionsState, n as Tool } from './ThreadActions-BLcKtagX.js';
2
- export { o as ImageContentPart, I as ImageContentPartComponent, s as ImageContentPartProps, g as ModelConfig, T as TextContentPartComponent, r as TextContentPartProps, p as ToolCallContentPart, b as ToolCallContentPartProps, q as UIContentPart, U as UIContentPartComponent, t as UIContentPartProps } from './ThreadActions-BLcKtagX.js';
3
- import { UseBoundStore, StoreApi } from 'zustand';
4
- import { ReactNode } from 'react';
5
- import 'zod';
6
1
 
7
- type AssistantModelConfigState = Readonly<{
8
- getModelConfig: ModelConfigProvider;
9
- registerModelConfigProvider: (provider: ModelConfigProvider) => () => void;
10
- }>;
11
-
12
- type ContentPartState = Readonly<{
13
- status: "in_progress" | "done" | "error";
14
- part: ThreadMessage["content"][number];
15
- }>;
16
-
17
- type MessageState = Readonly<{
18
- message: Readonly<ThreadMessage>;
19
- parentId: string | null;
20
- branches: readonly string[];
21
- isLast: boolean;
22
- }>;
23
-
24
- type BaseComposerState = Readonly<{
25
- value: string;
26
- setValue: (value: string) => void;
27
- }>;
28
-
29
- type ReadonlyStore<T> = UseBoundStore<Omit<StoreApi<T>, "setState" | "destroy" | "getInitialState">>;
30
-
31
- type EditComposerState = BaseComposerState & Readonly<{
32
- isEditing: boolean;
33
- edit: () => void;
34
- send: () => void;
35
- cancel: () => boolean;
36
- }>;
37
-
38
- type ComposerState = BaseComposerState & Readonly<{
39
- isEditing: true;
40
- send: () => void;
41
- cancel: () => boolean;
42
- focus: () => void;
43
- onFocus: (listener: () => void) => Unsubscribe;
44
- }>;
45
-
46
- type ThreadViewportState = Readonly<{
47
- isAtBottom: boolean;
48
- scrollToBottom: () => void;
49
- onScrollToBottom: (callback: () => void) => Unsubscribe;
50
- }>;
51
-
52
- type AssistantToolUIsState = Readonly<{
53
- getToolUI: (toolName: string) => ToolCallContentPartComponent | null;
54
- setToolUI: (toolName: string, render: ToolCallContentPartComponent) => () => void;
55
- }>;
56
-
57
- type AssistantContextValue = {
58
- useModelConfig: ReadonlyStore<AssistantModelConfigState>;
59
- useToolUIs: ReadonlyStore<AssistantToolUIsState>;
60
- };
61
- declare const useAssistantContext: () => AssistantContextValue;
62
-
63
- type ThreadContextValue = {
64
- useThread: ReadonlyStore<ThreadState>;
65
- useThreadActions: ReadonlyStore<ThreadActionsState>;
66
- useComposer: ReadonlyStore<ComposerState>;
67
- useViewport: ReadonlyStore<ThreadViewportState>;
68
- };
69
- declare const useThreadContext: () => ThreadContextValue;
70
-
71
- type ComposerContextValue = {
72
- useComposer: ReadonlyStore<EditComposerState | ComposerState>;
73
- type: "edit" | "new";
74
- };
75
- declare const useComposerContext: () => ComposerContextValue;
76
-
77
- type MessageUtilsState = Readonly<{
78
- inProgressIndicator: ReactNode | null;
79
- setInProgressIndicator: (value: ReactNode | null) => void;
80
- isCopied: boolean;
81
- setIsCopied: (value: boolean) => void;
82
- isHovering: boolean;
83
- setIsHovering: (value: boolean) => void;
84
- }>;
85
-
86
- type MessageContextValue = {
87
- useMessage: ReadonlyStore<MessageState>;
88
- useMessageUtils: ReadonlyStore<MessageUtilsState>;
89
- useEditComposer: ReadonlyStore<EditComposerState>;
90
- };
91
- declare const useMessageContext: () => MessageContextValue;
92
-
93
- type ContentPartContextValue = {
94
- useContentPart: ReadonlyStore<ContentPartState>;
95
- };
96
- declare const useContentPartContext: () => ContentPartContextValue;
97
-
98
- declare const useAssistantInstructions: (instruction: string) => void;
99
-
100
- type AssistantToolProps<TArgs, TResult> = Tool<TArgs, TResult> & {
101
- toolName: string;
102
- render?: ToolCallContentPartComponent<TArgs, TResult>;
103
- };
104
- declare const useAssistantTool: <TArgs, TResult>(tool: AssistantToolProps<TArgs, TResult>) => void;
105
-
106
- type AssistantToolUIProps<TArgs, TResult> = {
107
- toolName: string;
108
- render: ToolCallContentPartComponent<TArgs, TResult>;
109
- };
110
- declare const useAssistantToolUI: (tool: AssistantToolUIProps<any, any> | null) => void;
111
-
112
- declare const makeAssistantTool: <TArgs, TResult>(tool: AssistantToolProps<TArgs, TResult>) => () => null;
113
-
114
- declare const makeAssistantToolUI: <TArgs, TResult>(tool: AssistantToolUIProps<TArgs, TResult>) => () => null;
115
-
116
- 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 };
2
+ export { }
@@ -1,185 +1,2 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/experimental.ts
21
- var experimental_exports = {};
22
- __export(experimental_exports, {
23
- makeAssistantTool: () => makeAssistantTool,
24
- makeAssistantToolUI: () => makeAssistantToolUI,
25
- useAssistantContext: () => useAssistantContext,
26
- useAssistantInstructions: () => useAssistantInstructions,
27
- useAssistantTool: () => useAssistantTool,
28
- useAssistantToolUI: () => useAssistantToolUI,
29
- useComposerContext: () => useComposerContext,
30
- useContentPartContext: () => useContentPartContext,
31
- useMessageContext: () => useMessageContext,
32
- useThreadContext: () => useThreadContext
33
- });
34
- module.exports = __toCommonJS(experimental_exports);
35
-
36
- // src/context/react/AssistantContext.ts
37
- var import_react = require("react");
38
- var AssistantContext = (0, import_react.createContext)(
39
- null
40
- );
41
- var useAssistantContext = () => {
42
- const context = (0, import_react.useContext)(AssistantContext);
43
- if (!context)
44
- throw new Error(
45
- "This component must be used within an AssistantRuntimeProvider."
46
- );
47
- return context;
48
- };
49
-
50
- // src/context/react/ThreadContext.ts
51
- var import_react2 = require("react");
52
- var ThreadContext = (0, import_react2.createContext)(null);
53
- var useThreadContext = () => {
54
- const context = (0, import_react2.useContext)(ThreadContext);
55
- if (!context)
56
- throw new Error(
57
- "This component must be used within an AssistantRuntimeProvider."
58
- );
59
- return context;
60
- };
61
-
62
- // src/context/react/ComposerContext.ts
63
- var import_react4 = require("react");
64
-
65
- // src/context/react/MessageContext.ts
66
- var import_react3 = require("react");
67
- var MessageContext = (0, import_react3.createContext)(null);
68
- var useMessageContext = () => {
69
- const context = (0, import_react3.useContext)(MessageContext);
70
- if (!context)
71
- throw new Error(
72
- "This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
73
- );
74
- return context;
75
- };
76
-
77
- // src/context/react/ComposerContext.ts
78
- var useComposerContext = () => {
79
- const { useComposer } = useThreadContext();
80
- const { useEditComposer } = (0, import_react4.useContext)(MessageContext) ?? {};
81
- return (0, import_react4.useMemo)(
82
- () => ({
83
- useComposer: useEditComposer ?? useComposer,
84
- type: useEditComposer ? "edit" : "new"
85
- }),
86
- [useEditComposer, useComposer]
87
- );
88
- };
89
-
90
- // src/context/react/ContentPartContext.ts
91
- var import_react5 = require("react");
92
- var ContentPartContext = (0, import_react5.createContext)(
93
- null
94
- );
95
- var useContentPartContext = () => {
96
- const context = (0, import_react5.useContext)(ContentPartContext);
97
- if (!context)
98
- throw new Error(
99
- "This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
100
- );
101
- return context;
102
- };
103
-
104
- // src/model-config/useAssistantInstructions.tsx
105
- var import_react6 = require("react");
106
- var useAssistantInstructions = (instruction) => {
107
- const { useModelConfig } = useAssistantContext();
108
- const registerModelConfigProvider = useModelConfig(
109
- (s) => s.registerModelConfigProvider
110
- );
111
- (0, import_react6.useEffect)(() => {
112
- const config = {
113
- system: instruction
114
- };
115
- return registerModelConfigProvider(() => config);
116
- }, [registerModelConfigProvider, instruction]);
117
- };
118
-
119
- // src/model-config/useAssistantTool.tsx
120
- var import_react7 = require("react");
121
- var useAssistantTool = (tool) => {
122
- const { useModelConfig, useToolUIs } = useAssistantContext();
123
- const registerModelConfigProvider = useModelConfig(
124
- (s) => s.registerModelConfigProvider
125
- );
126
- const setToolUI = useToolUIs((s) => s.setToolUI);
127
- (0, import_react7.useEffect)(() => {
128
- const { toolName, render, ...rest } = tool;
129
- const config = {
130
- tools: {
131
- [tool.toolName]: rest
132
- }
133
- };
134
- const unsub1 = registerModelConfigProvider(() => config);
135
- const unsub2 = render ? setToolUI(toolName, render) : void 0;
136
- return () => {
137
- unsub1();
138
- unsub2?.();
139
- };
140
- }, [registerModelConfigProvider, setToolUI, tool]);
141
- };
142
-
143
- // src/model-config/useAssistantToolUI.tsx
144
- var import_react8 = require("react");
145
- var useAssistantToolUI = (tool) => {
146
- const { useToolUIs } = useAssistantContext();
147
- const setToolUI = useToolUIs((s) => s.setToolUI);
148
- (0, import_react8.useEffect)(() => {
149
- if (!tool) return;
150
- const { toolName, render } = tool;
151
- return setToolUI(toolName, render);
152
- }, [setToolUI, tool]);
153
- };
154
-
155
- // src/model-config/makeAssistantTool.tsx
156
- var makeAssistantTool = (tool) => {
157
- const Tool = () => {
158
- useAssistantTool(tool);
159
- return null;
160
- };
161
- return Tool;
162
- };
163
-
164
- // src/model-config/makeAssistantToolUI.tsx
165
- var makeAssistantToolUI = (tool) => {
166
- const ToolUI = () => {
167
- useAssistantToolUI(tool);
168
- return null;
169
- };
170
- return ToolUI;
171
- };
172
- // Annotate the CommonJS export names for ESM import in node:
173
- 0 && (module.exports = {
174
- makeAssistantTool,
175
- makeAssistantToolUI,
176
- useAssistantContext,
177
- useAssistantInstructions,
178
- useAssistantTool,
179
- useAssistantToolUI,
180
- useComposerContext,
181
- useContentPartContext,
182
- useMessageContext,
183
- useThreadContext
184
- });
185
2
  //# sourceMappingURL=experimental.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/experimental.ts","../src/context/react/AssistantContext.ts","../src/context/react/ThreadContext.ts","../src/context/react/ComposerContext.ts","../src/context/react/MessageContext.ts","../src/context/react/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 \"./types/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 \"./types/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 { 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 { 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 { 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 { 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 { 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","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/react/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/react/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../types/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/react/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../types/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":"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","names":["import_react","import_react","import_react","import_react","import_react","import_react","import_react"]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,89 +1 @@
1
- import {
2
- useAssistantContext,
3
- useComposerContext,
4
- useContentPartContext,
5
- useMessageContext,
6
- useThreadContext
7
- } from "./chunk-KUACYNLE.mjs";
8
-
9
- // src/model-config/useAssistantInstructions.tsx
10
- import { useEffect } from "react";
11
- var useAssistantInstructions = (instruction) => {
12
- const { useModelConfig } = useAssistantContext();
13
- const registerModelConfigProvider = useModelConfig(
14
- (s) => s.registerModelConfigProvider
15
- );
16
- useEffect(() => {
17
- const config = {
18
- system: instruction
19
- };
20
- return registerModelConfigProvider(() => config);
21
- }, [registerModelConfigProvider, instruction]);
22
- };
23
-
24
- // src/model-config/useAssistantTool.tsx
25
- import { useEffect as useEffect2 } from "react";
26
- var useAssistantTool = (tool) => {
27
- const { useModelConfig, useToolUIs } = useAssistantContext();
28
- const registerModelConfigProvider = useModelConfig(
29
- (s) => s.registerModelConfigProvider
30
- );
31
- const setToolUI = useToolUIs((s) => s.setToolUI);
32
- useEffect2(() => {
33
- const { toolName, render, ...rest } = tool;
34
- const config = {
35
- tools: {
36
- [tool.toolName]: rest
37
- }
38
- };
39
- const unsub1 = registerModelConfigProvider(() => config);
40
- const unsub2 = render ? setToolUI(toolName, render) : void 0;
41
- return () => {
42
- unsub1();
43
- unsub2?.();
44
- };
45
- }, [registerModelConfigProvider, setToolUI, tool]);
46
- };
47
-
48
- // src/model-config/useAssistantToolUI.tsx
49
- import { useEffect as useEffect3 } from "react";
50
- var useAssistantToolUI = (tool) => {
51
- const { useToolUIs } = useAssistantContext();
52
- const setToolUI = useToolUIs((s) => s.setToolUI);
53
- useEffect3(() => {
54
- if (!tool) return;
55
- const { toolName, render } = tool;
56
- return setToolUI(toolName, render);
57
- }, [setToolUI, tool]);
58
- };
59
-
60
- // src/model-config/makeAssistantTool.tsx
61
- var makeAssistantTool = (tool) => {
62
- const Tool = () => {
63
- useAssistantTool(tool);
64
- return null;
65
- };
66
- return Tool;
67
- };
68
-
69
- // src/model-config/makeAssistantToolUI.tsx
70
- var makeAssistantToolUI = (tool) => {
71
- const ToolUI = () => {
72
- useAssistantToolUI(tool);
73
- return null;
74
- };
75
- return ToolUI;
76
- };
77
- export {
78
- makeAssistantTool,
79
- makeAssistantToolUI,
80
- useAssistantContext,
81
- useAssistantInstructions,
82
- useAssistantTool,
83
- useAssistantToolUI,
84
- useComposerContext,
85
- useContentPartContext,
86
- useMessageContext,
87
- useThreadContext
88
- };
89
1
  //# sourceMappingURL=experimental.mjs.map
@@ -1 +1 @@
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/react/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/react/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../types/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/react/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../types/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,kBAAiB;AASnB,IAAM,qBAAqB,CAChC,SACG;AACH,QAAM,EAAE,WAAW,IAAI,oBAAoB;AAC3C,QAAM,YAAY,WAAW,CAAC,MAAM,EAAE,SAAS;AAC/C,EAAAC,WAAU,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":["useEffect","useEffect","useEffect","useEffect"]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}