@assistant-ui/react 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
+ import { ReactNode, ComponentType } from 'react';
1
2
  import { z } from 'zod';
2
- import { ReactNode } from 'react';
3
3
 
4
4
  type TextContentPart = {
5
5
  type: "text";
@@ -42,6 +42,28 @@ type AppendMessage = {
42
42
  };
43
43
  type ThreadMessage = UserMessage | AssistantMessage;
44
44
 
45
+ type ContentPartStatus = "done" | "in_progress" | "error";
46
+ type TextContentPartProps = {
47
+ part: TextContentPart;
48
+ status: ContentPartStatus;
49
+ };
50
+ type TextContentPartComponent = ComponentType<TextContentPartProps>;
51
+ type ImageContentPartProps = {
52
+ part: ImageContentPart;
53
+ status: ContentPartStatus;
54
+ };
55
+ type ImageContentPartComponent = ComponentType<ImageContentPartProps>;
56
+ type UIContentPartProps = {
57
+ part: UIContentPart;
58
+ status: ContentPartStatus;
59
+ };
60
+ type UIContentPartComponent = ComponentType<UIContentPartProps>;
61
+ type ToolCallContentPartProps<TArgs = any, TResult = any> = {
62
+ part: ToolCallContentPart<TArgs, TResult>;
63
+ status: ContentPartStatus;
64
+ };
65
+ type ToolCallContentPartComponent<TArgs = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
66
+
45
67
  type ToolExecuteFunction<TArgs, TResult> = (args: TArgs) => TResult | Promise<TResult>;
46
68
  type Tool<TArgs = unknown, TResult = unknown> = {
47
69
  description?: string;
@@ -67,4 +89,4 @@ type ThreadState = {
67
89
  cancelRun: () => void;
68
90
  };
69
91
 
70
- export type { AssistantContentPart as A, ImageContentPart as I, ModelConfigProvider as M, TextContentPart as T, UIContentPart as U, ToolCallContentPart as a, ThreadState as b, Unsubscribe as c, ThreadMessage as d, ModelConfig as e, AppendMessage as f, AssistantMessage as g, UserMessage as h, UserContentPart as i, AppendContentPart as j, Tool as k };
92
+ 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 };
@@ -1,5 +1,5 @@
1
+ import { ReactNode, ComponentType } from 'react';
1
2
  import { z } from 'zod';
2
- import { ReactNode } from 'react';
3
3
 
4
4
  type TextContentPart = {
5
5
  type: "text";
@@ -42,6 +42,28 @@ type AppendMessage = {
42
42
  };
43
43
  type ThreadMessage = UserMessage | AssistantMessage;
44
44
 
45
+ type ContentPartStatus = "done" | "in_progress" | "error";
46
+ type TextContentPartProps = {
47
+ part: TextContentPart;
48
+ status: ContentPartStatus;
49
+ };
50
+ type TextContentPartComponent = ComponentType<TextContentPartProps>;
51
+ type ImageContentPartProps = {
52
+ part: ImageContentPart;
53
+ status: ContentPartStatus;
54
+ };
55
+ type ImageContentPartComponent = ComponentType<ImageContentPartProps>;
56
+ type UIContentPartProps = {
57
+ part: UIContentPart;
58
+ status: ContentPartStatus;
59
+ };
60
+ type UIContentPartComponent = ComponentType<UIContentPartProps>;
61
+ type ToolCallContentPartProps<TArgs = any, TResult = any> = {
62
+ part: ToolCallContentPart<TArgs, TResult>;
63
+ status: ContentPartStatus;
64
+ };
65
+ type ToolCallContentPartComponent<TArgs = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
66
+
45
67
  type ToolExecuteFunction<TArgs, TResult> = (args: TArgs) => TResult | Promise<TResult>;
46
68
  type Tool<TArgs = unknown, TResult = unknown> = {
47
69
  description?: string;
@@ -67,4 +89,4 @@ type ThreadState = {
67
89
  cancelRun: () => void;
68
90
  };
69
91
 
70
- export type { AssistantContentPart as A, ImageContentPart as I, ModelConfigProvider as M, TextContentPart as T, UIContentPart as U, ToolCallContentPart as a, ThreadState as b, Unsubscribe as c, ThreadMessage as d, ModelConfig as e, AppendMessage as f, AssistantMessage as g, UserMessage as h, UserContentPart as i, AppendContentPart as j, Tool as k };
92
+ 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 };
@@ -1,7 +1,7 @@
1
- import { M as ModelConfigProvider, d as ThreadMessage, c as Unsubscribe, k as Tool, a as ToolCallContentPart, b as ThreadState } from './Thread-DcmnmkmV.mjs';
2
- export { I as ImageContentPart, e as ModelConfig, U as UIContentPart } from './Thread-DcmnmkmV.mjs';
1
+ import { M as ModelConfigProvider, e as ThreadMessage, d as Unsubscribe, a as ToolCallContentPartComponent, c as ThreadState, m as Tool } from './Thread-ZUDFhMtm.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-ZUDFhMtm.mjs';
3
+ import { ReactNode } from 'react';
3
4
  import { UseBoundStore, StoreApi } from 'zustand';
4
- import { ReactNode, ComponentType } from 'react';
5
5
  import 'zod';
6
6
 
7
7
  type AssistantModelConfigState = {
@@ -51,28 +51,9 @@ type ThreadViewportState = {
51
51
  onScrollToBottom: (callback: () => void) => Unsubscribe;
52
52
  };
53
53
 
54
- declare const useAssistantInstructions: (instruction: string) => void;
55
-
56
- type UseAssistantTool<TArgs, TResult> = Tool<TArgs, TResult> & {
57
- name: string;
58
- render?: ToolRenderComponent<TArgs, TResult>;
59
- };
60
- declare const useAssistantTool: <TArgs, TResult>(tool: UseAssistantTool<TArgs, TResult>) => void;
61
-
62
- type UseAssistantToolRenderer<TArgs, TResult> = {
63
- name: string;
64
- render: ToolRenderComponent<TArgs, TResult>;
65
- };
66
- declare const useAssistantToolRenderer: (tool: UseAssistantToolRenderer<any, any> | null) => void;
67
-
68
- type ToolRenderComponent<TArgs, TResult> = ComponentType<{
69
- part: ToolCallContentPart<TArgs, TResult>;
70
- status: "done" | "in_progress" | "error";
71
- }>;
72
-
73
54
  type AssistantToolRenderersState = {
74
- getToolRenderer: (name: string) => ToolRenderComponent<any, any> | null;
75
- setToolRenderer: (name: string, render: ToolRenderComponent<any, any>) => () => void;
55
+ getToolRenderer: (name: string) => ToolCallContentPartComponent | null;
56
+ setToolRenderer: (name: string, render: ToolCallContentPartComponent) => () => void;
76
57
  };
77
58
 
78
59
  type AssistantContextValue = {
@@ -105,4 +86,22 @@ type ContentPartContextValue = {
105
86
  };
106
87
  declare const useContentPartContext: () => ContentPartContextValue;
107
88
 
108
- export { type AssistantContextValue, type AssistantModelConfigState, type ComposerContextValue, type ComposerState, type ContentPartContextValue, type ContentPartState, type EditComposerState, type MessageContextValue, type MessageState, ModelConfigProvider, type ThreadContextValue, ThreadState, type ThreadViewportState, ToolCallContentPart, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolRenderer, useComposerContext, useContentPartContext, useMessageContext, useThreadContext };
89
+ declare const useAssistantInstructions: (instruction: string) => void;
90
+
91
+ type AssistantToolProps<TArgs, TResult> = Tool<TArgs, TResult> & {
92
+ name: string;
93
+ render?: ToolCallContentPartComponent<TArgs, TResult>;
94
+ };
95
+ declare const useAssistantTool: <TArgs, TResult>(tool: AssistantToolProps<TArgs, TResult>) => void;
96
+
97
+ type AssistantToolRendererProps<TArgs, TResult> = {
98
+ name: string;
99
+ render: ToolCallContentPartComponent<TArgs, TResult>;
100
+ };
101
+ declare const useAssistantToolRenderer: (tool: AssistantToolRendererProps<any, any> | null) => void;
102
+
103
+ declare const makeTool: <TArgs, TResult>(tool: AssistantToolProps<TArgs, TResult>) => () => null;
104
+
105
+ declare const makeToolRenderer: <TArgs, TResult>(tool: AssistantToolRendererProps<TArgs, TResult>) => () => null;
106
+
107
+ export { type AssistantContextValue, type AssistantModelConfigState, type AssistantToolProps, type AssistantToolRendererProps, type ComposerContextValue, type ComposerState, type ContentPartContextValue, type ContentPartState, type EditComposerState, type MessageContextValue, type MessageState, ModelConfigProvider, type ThreadContextValue, ThreadState, type ThreadViewportState, ToolCallContentPartComponent, makeTool, makeToolRenderer, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolRenderer, useComposerContext, useContentPartContext, useMessageContext, useThreadContext };
@@ -1,7 +1,7 @@
1
- import { M as ModelConfigProvider, d as ThreadMessage, c as Unsubscribe, k as Tool, a as ToolCallContentPart, b as ThreadState } from './Thread-DcmnmkmV.js';
2
- export { I as ImageContentPart, e as ModelConfig, U as UIContentPart } from './Thread-DcmnmkmV.js';
1
+ import { M as ModelConfigProvider, e as ThreadMessage, d as Unsubscribe, a as ToolCallContentPartComponent, c as ThreadState, m as Tool } from './Thread-ZUDFhMtm.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-ZUDFhMtm.js';
3
+ import { ReactNode } from 'react';
3
4
  import { UseBoundStore, StoreApi } from 'zustand';
4
- import { ReactNode, ComponentType } from 'react';
5
5
  import 'zod';
6
6
 
7
7
  type AssistantModelConfigState = {
@@ -51,28 +51,9 @@ type ThreadViewportState = {
51
51
  onScrollToBottom: (callback: () => void) => Unsubscribe;
52
52
  };
53
53
 
54
- declare const useAssistantInstructions: (instruction: string) => void;
55
-
56
- type UseAssistantTool<TArgs, TResult> = Tool<TArgs, TResult> & {
57
- name: string;
58
- render?: ToolRenderComponent<TArgs, TResult>;
59
- };
60
- declare const useAssistantTool: <TArgs, TResult>(tool: UseAssistantTool<TArgs, TResult>) => void;
61
-
62
- type UseAssistantToolRenderer<TArgs, TResult> = {
63
- name: string;
64
- render: ToolRenderComponent<TArgs, TResult>;
65
- };
66
- declare const useAssistantToolRenderer: (tool: UseAssistantToolRenderer<any, any> | null) => void;
67
-
68
- type ToolRenderComponent<TArgs, TResult> = ComponentType<{
69
- part: ToolCallContentPart<TArgs, TResult>;
70
- status: "done" | "in_progress" | "error";
71
- }>;
72
-
73
54
  type AssistantToolRenderersState = {
74
- getToolRenderer: (name: string) => ToolRenderComponent<any, any> | null;
75
- setToolRenderer: (name: string, render: ToolRenderComponent<any, any>) => () => void;
55
+ getToolRenderer: (name: string) => ToolCallContentPartComponent | null;
56
+ setToolRenderer: (name: string, render: ToolCallContentPartComponent) => () => void;
76
57
  };
77
58
 
78
59
  type AssistantContextValue = {
@@ -105,4 +86,22 @@ type ContentPartContextValue = {
105
86
  };
106
87
  declare const useContentPartContext: () => ContentPartContextValue;
107
88
 
108
- export { type AssistantContextValue, type AssistantModelConfigState, type ComposerContextValue, type ComposerState, type ContentPartContextValue, type ContentPartState, type EditComposerState, type MessageContextValue, type MessageState, ModelConfigProvider, type ThreadContextValue, ThreadState, type ThreadViewportState, ToolCallContentPart, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolRenderer, useComposerContext, useContentPartContext, useMessageContext, useThreadContext };
89
+ declare const useAssistantInstructions: (instruction: string) => void;
90
+
91
+ type AssistantToolProps<TArgs, TResult> = Tool<TArgs, TResult> & {
92
+ name: string;
93
+ render?: ToolCallContentPartComponent<TArgs, TResult>;
94
+ };
95
+ declare const useAssistantTool: <TArgs, TResult>(tool: AssistantToolProps<TArgs, TResult>) => void;
96
+
97
+ type AssistantToolRendererProps<TArgs, TResult> = {
98
+ name: string;
99
+ render: ToolCallContentPartComponent<TArgs, TResult>;
100
+ };
101
+ declare const useAssistantToolRenderer: (tool: AssistantToolRendererProps<any, any> | null) => void;
102
+
103
+ declare const makeTool: <TArgs, TResult>(tool: AssistantToolProps<TArgs, TResult>) => () => null;
104
+
105
+ declare const makeToolRenderer: <TArgs, TResult>(tool: AssistantToolRendererProps<TArgs, TResult>) => () => null;
106
+
107
+ export { type AssistantContextValue, type AssistantModelConfigState, type AssistantToolProps, type AssistantToolRendererProps, type ComposerContextValue, type ComposerState, type ContentPartContextValue, type ContentPartState, type EditComposerState, type MessageContextValue, type MessageState, ModelConfigProvider, type ThreadContextValue, ThreadState, type ThreadViewportState, ToolCallContentPartComponent, makeTool, makeToolRenderer, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolRenderer, useComposerContext, useContentPartContext, useMessageContext, useThreadContext };
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/experimental.ts
21
21
  var experimental_exports = {};
22
22
  __export(experimental_exports, {
23
+ makeTool: () => makeTool,
24
+ makeToolRenderer: () => makeToolRenderer,
23
25
  useAssistantContext: () => useAssistantContext,
24
26
  useAssistantInstructions: () => useAssistantInstructions,
25
27
  useAssistantTool: () => useAssistantTool,
@@ -147,8 +149,28 @@ var useAssistantToolRenderer = (tool) => {
147
149
  return setToolRenderer(name, render);
148
150
  }, [setToolRenderer, tool]);
149
151
  };
152
+
153
+ // src/model-config/makeTool.tsx
154
+ var makeTool = (tool) => {
155
+ const Tool = () => {
156
+ useAssistantTool(tool);
157
+ return null;
158
+ };
159
+ return Tool;
160
+ };
161
+
162
+ // src/model-config/makeToolRenderer.tsx
163
+ var makeToolRenderer = (tool) => {
164
+ const ToolRenderer = () => {
165
+ useAssistantToolRenderer(tool);
166
+ return null;
167
+ };
168
+ return ToolRenderer;
169
+ };
150
170
  // Annotate the CommonJS export names for ESM import in node:
151
171
  0 && (module.exports = {
172
+ makeTool,
173
+ makeToolRenderer,
152
174
  useAssistantContext,
153
175
  useAssistantInstructions,
154
176
  useAssistantTool,
@@ -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"],"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 * from \"./context\";\nexport { useAssistantInstructions } from \"./model-config/useAssistantInstructions\";\nexport { useAssistantTool } from \"./model-config/useAssistantTool\";\nexport { useAssistantToolRenderer } from \"./model-config/useAssistantToolRenderer\";\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 { Tool } from \"../utils/ModelConfigTypes\";\nimport type { ToolRenderComponent } from \"./ToolRenderComponent\";\n\nexport type UseAssistantTool<TArgs, TResult> = Tool<TArgs, TResult> & {\n name: string;\n render?: ToolRenderComponent<TArgs, TResult>;\n};\n\nexport const useAssistantTool = <TArgs, TResult>(\n tool: UseAssistantTool<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 { ToolRenderComponent } from \"./ToolRenderComponent\";\n\ntype UseAssistantToolRenderer<TArgs, TResult> = {\n name: string;\n render: ToolRenderComponent<TArgs, TResult>;\n};\n\nexport const useAssistantToolRenderer = (\n // biome-ignore lint/suspicious/noExplicitAny: intentional any\n tool: UseAssistantToolRenderer<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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA0C;AAUnC,IAAM,uBAAmB;AAAA,EAC9B;AACF;AAEO,IAAM,sBAAsB,MAA6B;AAC9D,QAAM,cAAU,yBAAW,gBAAgB;AAC3C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACrBA,IAAAA,gBAA0C;AAYnC,IAAM,oBAAgB,6BAAyC,IAAI;AAEnE,IAAM,mBAAmB,MAA0B;AACxD,QAAM,cAAU,0BAAW,aAAa;AACxC,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,iEAAiE;AACnF,SAAO;AACT;;;ACnBA,IAAAC,gBAAoC;;;ACApC,IAAAC,gBAA0C;AAUnC,IAAM,qBAAiB,6BAA0C,IAAI;AAErE,IAAM,oBAAoB,MAAM;AACrC,QAAM,cAAU,0BAAW,cAAc;AACzC,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ADPO,IAAM,qBAAqB,MAA4B;AAC5D,QAAM,EAAE,YAAY,IAAI,iBAAiB;AACzC,QAAM,EAAE,aAAa,gBAAgB,QAAI,0BAAW,cAAc,KAAK,CAAC;AACxE,aAAO;AAAA,IACL,OAAO;AAAA,MACL,aAAc,mBAAmB;AAAA,MAGjC,MAAM,kBAAmB,SAAoB;AAAA,IAC/C;AAAA,IACA,CAAC,iBAAiB,WAAW;AAAA,EAC/B;AACF;;;AExBA,IAAAC,gBAA0C;AAQnC,IAAM,yBAAqB;AAAA,EAChC;AACF;AAEO,IAAM,wBAAwB,MAA+B;AAClE,QAAM,cAAU,0BAAW,kBAAkB;AAC7C,MAAI,CAAC;AACH,UAAM,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AAC5B;","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/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 = () => {\n useAssistantToolRenderer(tool);\n return null;\n };\n return ToolRenderer;\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,sBAAsB,MAA6B;AAC9D,QAAM,cAAU,yBAAW,gBAAgB;AAC3C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACrBA,IAAAA,gBAA0C;AAYnC,IAAM,oBAAg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B,iBAAiB,IAAI,oBAAoB;AACjE,QAAM,8BAA8B;AAAA,IAClC,CAAC,MAAM,EAAE;AAAA,EACX;AACA,QAAM,kBAAkB,iBAAiB,CAAC,MAAM,EAAE,eAAe;AACjE,+BAAU,MAAM;AACd,UAAM,EAAE,MAAM,QAAQ,GAAG,KAAK,IAAI;AAClC,UAAM,SAAS;AAAA,MACb,OAAO;AAAA,QACL,CAAC,KAAK,IAAI,GAAG;AAAA,MACf;AAAA,IACF;AACA,UAAM,SAAS,4BAA4B,MAAM,MAAM;AACvD,UAAM,SAAS,SAAS,gBAAgB,MAAM,MAAM,IAAI;AACxD,WAAO,MAAM;AACX,aAAO;AACP,eAAS;AAAA,IACX;AAAA,EACF,GAAG,CAAC,6BAA6B,iBAAiB,IAAI,CAAC;AACzD;;;ACjCA,IAAAC,gBAA0B;AASnB,IAAM,2BAA2B,CAEtC,SACG;AACH,QAAM,EAAE,iBAAiB,IAAI,oBAAoB;AACjD,QAAM,kBAAkB,iBAAiB,CAAC,MAAM,EAAE,eAAe;AACjE,+BAAU,MAAM;AACd,QAAI,CAAC,KAAM;AACX,UAAM,EAAE,MAAM,OAAO,IAAI;AACzB,WAAO,gBAAgB,MAAM,MAAM;AAAA,EACrC,GAAG,CAAC,iBAAiB,IAAI,CAAC;AAC5B;;;AClBO,IAAM,WAAW,CACtB,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"]}
@@ -56,7 +56,27 @@ var useAssistantToolRenderer = (tool) => {
56
56
  return setToolRenderer(name, render);
57
57
  }, [setToolRenderer, tool]);
58
58
  };
59
+
60
+ // src/model-config/makeTool.tsx
61
+ var makeTool = (tool) => {
62
+ const Tool = () => {
63
+ useAssistantTool(tool);
64
+ return null;
65
+ };
66
+ return Tool;
67
+ };
68
+
69
+ // src/model-config/makeToolRenderer.tsx
70
+ var makeToolRenderer = (tool) => {
71
+ const ToolRenderer = () => {
72
+ useAssistantToolRenderer(tool);
73
+ return null;
74
+ };
75
+ return ToolRenderer;
76
+ };
59
77
  export {
78
+ makeTool,
79
+ makeToolRenderer,
60
80
  useAssistantContext,
61
81
  useAssistantInstructions,
62
82
  useAssistantTool,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/model-config/useAssistantInstructions.tsx","../src/model-config/useAssistantTool.tsx","../src/model-config/useAssistantToolRenderer.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 { Tool } from \"../utils/ModelConfigTypes\";\nimport type { ToolRenderComponent } from \"./ToolRenderComponent\";\n\nexport type UseAssistantTool<TArgs, TResult> = Tool<TArgs, TResult> & {\n name: string;\n render?: ToolRenderComponent<TArgs, TResult>;\n};\n\nexport const useAssistantTool = <TArgs, TResult>(\n tool: UseAssistantTool<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 { ToolRenderComponent } from \"./ToolRenderComponent\";\n\ntype UseAssistantToolRenderer<TArgs, TResult> = {\n name: string;\n render: ToolRenderComponent<TArgs, TResult>;\n};\n\nexport const useAssistantToolRenderer = (\n // biome-ignore lint/suspicious/noExplicitAny: intentional any\n tool: UseAssistantToolRenderer<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"],"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,iBAAiB,IAAI,oBAAoB;AACjE,QAAM,8BAA8B;AAAA,IAClC,CAAC,MAAM,EAAE;AAAA,EACX;AACA,QAAM,kBAAkB,iBAAiB,CAAC,MAAM,EAAE,eAAe;AACjE,EAAAC,WAAU,MAAM;AACd,UAAM,EAAE,MAAM,QAAQ,GAAG,KAAK,IAAI;AAClC,UAAM,SAAS;AAAA,MACb,OAAO;AAAA,QACL,CAAC,KAAK,IAAI,GAAG;AAAA,MACf;AAAA,IACF;AACA,UAAM,SAAS,4BAA4B,MAAM,MAAM;AACvD,UAAM,SAAS,SAAS,gBAAgB,MAAM,MAAM,IAAI;AACxD,WAAO,MAAM;AACX,aAAO;AACP,eAAS;AAAA,IACX;AAAA,EACF,GAAG,CAAC,6BAA6B,iBAAiB,IAAI,CAAC;AACzD;;;ACjCA,SAAS,aAAAC,kBAAiB;AASnB,IAAM,2BAA2B,CAEtC,SACG;AACH,QAAM,EAAE,iBAAiB,IAAI,oBAAoB;AACjD,QAAM,kBAAkB,iBAAiB,CAAC,MAAM,EAAE,eAAe;AACjE,EAAAC,WAAU,MAAM;AACd,QAAI,CAAC,KAAM;AACX,UAAM,EAAE,MAAM,OAAO,IAAI;AACzB,WAAO,gBAAgB,MAAM,MAAM;AAAA,EACrC,GAAG,CAAC,iBAAiB,IAAI,CAAC;AAC5B;","names":["useEffect","useEffect","useEffect","useEffect"]}
1
+ {"version":3,"sources":["../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":["\"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 = () => {\n useAssistantToolRenderer(tool);\n return null;\n };\n return ToolRenderer;\n};\n"],"mappings":";;;;;;;;;AAEA,SAAS,iBAAiB;AAGnB,IAAM,2BAA2B,CAAC,gBAAwB;AAC/D,QAAM,EAAE,eAAe,IAAI,oBAAo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;;;ACLO,IAAM,mBAAmB,CAC9B,SACG;AACH,QAAM,eAAe,MAAM;AACzB,6BAAyB,IAAI;AAC7B,WAAO;AAAA,EACT;AACA,SAAO;AACT;","names":["useEffect","useEffect","useEffect","useEffect"]}
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as react from 'react';
2
2
  import { FC, ReactNode, PropsWithChildren, ComponentType } from 'react';
3
3
  import { TextareaAutosizeProps } from 'react-textarea-autosize';
4
- import { T as TextContentPart, I as ImageContentPart, U as UIContentPart, a as ToolCallContentPart, b as ThreadState, c as Unsubscribe, M as ModelConfigProvider, d as ThreadMessage, e as ModelConfig, A as AssistantContentPart, f as AppendMessage } from './Thread-DcmnmkmV.mjs';
5
- export { j as AppendContentPart, g as AssistantMessage, i as UserContentPart, h as UserMessage } from './Thread-DcmnmkmV.mjs';
4
+ import { T as TextContentPartComponent, I as ImageContentPartComponent, U as UIContentPartComponent, a as ToolCallContentPartComponent, b as ToolCallContentPartProps, c as ThreadState, d as Unsubscribe, M as ModelConfigProvider, e as ThreadMessage, f as ModelConfig, A as AssistantContentPart, g as AppendMessage } from './Thread-ZUDFhMtm.mjs';
5
+ export { k as AppendContentPart, h as AssistantMessage, l as TextContentPart, j as UserContentPart, i as UserMessage } from './Thread-ZUDFhMtm.mjs';
6
6
  import { ComponentPropsWithoutRef, Primitive } from '@radix-ui/react-primitive';
7
7
  import 'zod';
8
8
 
@@ -135,27 +135,12 @@ declare const MessageIf: FC<MessageIfProps>;
135
135
 
136
136
  type MessageContentProps = {
137
137
  components?: {
138
- Text?: ComponentType<{
139
- part: TextContentPart;
140
- status: "done" | "in_progress" | "error";
141
- }>;
142
- Image?: ComponentType<{
143
- part: ImageContentPart;
144
- status: "done" | "in_progress" | "error";
145
- }>;
146
- UI?: ComponentType<{
147
- part: UIContentPart;
148
- status: "done" | "in_progress" | "error";
149
- }>;
138
+ Text?: TextContentPartComponent;
139
+ Image?: ImageContentPartComponent;
140
+ UI?: UIContentPartComponent;
150
141
  tools?: {
151
- by_name?: Record<string, ComponentType<{
152
- part: ToolCallContentPart;
153
- status: "done" | "in_progress" | "error";
154
- }>>;
155
- Fallback?: ComponentType<{
156
- part: ToolCallContentPart;
157
- status: "done" | "in_progress" | "error";
158
- }>;
142
+ by_name?: Record<string, ToolCallContentPartComponent>;
143
+ Fallback?: ComponentType<ToolCallContentPartProps>;
159
144
  };
160
145
  };
161
146
  };
@@ -331,4 +316,4 @@ declare namespace internal {
331
316
  export { internal_MessageRepository as MessageRepository, internal_ProxyConfigProvider as ProxyConfigProvider };
332
317
  }
333
318
 
334
- export { index$1 as ActionBarPrimitive, AppendMessage, AssistantContentPart, type AssistantRuntime, AssistantRuntimeProvider, index$2 as BranchPickerPrimitive, type ChatModelAdapter, type ChatModelRunOptions, index$4 as ComposerPrimitive, index as ContentPartPrimitive, internal as INTERNAL, index$3 as MessagePrimitive, type ReactThreadRuntime, TextContentPart, ThreadMessage, index$5 as ThreadPrimitive, type ThreadRuntime, Unsubscribe, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useLocalRuntime, useReloadMessage };
319
+ export { index$1 as ActionBarPrimitive, AppendMessage, AssistantContentPart, type AssistantRuntime, AssistantRuntimeProvider, index$2 as BranchPickerPrimitive, type ChatModelAdapter, type ChatModelRunOptions, index$4 as ComposerPrimitive, index as ContentPartPrimitive, internal as INTERNAL, index$3 as MessagePrimitive, type ReactThreadRuntime, ThreadMessage, index$5 as ThreadPrimitive, type ThreadRuntime, Unsubscribe, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useLocalRuntime, useReloadMessage };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as react from 'react';
2
2
  import { FC, ReactNode, PropsWithChildren, ComponentType } from 'react';
3
3
  import { TextareaAutosizeProps } from 'react-textarea-autosize';
4
- import { T as TextContentPart, I as ImageContentPart, U as UIContentPart, a as ToolCallContentPart, b as ThreadState, c as Unsubscribe, M as ModelConfigProvider, d as ThreadMessage, e as ModelConfig, A as AssistantContentPart, f as AppendMessage } from './Thread-DcmnmkmV.js';
5
- export { j as AppendContentPart, g as AssistantMessage, i as UserContentPart, h as UserMessage } from './Thread-DcmnmkmV.js';
4
+ import { T as TextContentPartComponent, I as ImageContentPartComponent, U as UIContentPartComponent, a as ToolCallContentPartComponent, b as ToolCallContentPartProps, c as ThreadState, d as Unsubscribe, M as ModelConfigProvider, e as ThreadMessage, f as ModelConfig, A as AssistantContentPart, g as AppendMessage } from './Thread-ZUDFhMtm.js';
5
+ export { k as AppendContentPart, h as AssistantMessage, l as TextContentPart, j as UserContentPart, i as UserMessage } from './Thread-ZUDFhMtm.js';
6
6
  import { ComponentPropsWithoutRef, Primitive } from '@radix-ui/react-primitive';
7
7
  import 'zod';
8
8
 
@@ -135,27 +135,12 @@ declare const MessageIf: FC<MessageIfProps>;
135
135
 
136
136
  type MessageContentProps = {
137
137
  components?: {
138
- Text?: ComponentType<{
139
- part: TextContentPart;
140
- status: "done" | "in_progress" | "error";
141
- }>;
142
- Image?: ComponentType<{
143
- part: ImageContentPart;
144
- status: "done" | "in_progress" | "error";
145
- }>;
146
- UI?: ComponentType<{
147
- part: UIContentPart;
148
- status: "done" | "in_progress" | "error";
149
- }>;
138
+ Text?: TextContentPartComponent;
139
+ Image?: ImageContentPartComponent;
140
+ UI?: UIContentPartComponent;
150
141
  tools?: {
151
- by_name?: Record<string, ComponentType<{
152
- part: ToolCallContentPart;
153
- status: "done" | "in_progress" | "error";
154
- }>>;
155
- Fallback?: ComponentType<{
156
- part: ToolCallContentPart;
157
- status: "done" | "in_progress" | "error";
158
- }>;
142
+ by_name?: Record<string, ToolCallContentPartComponent>;
143
+ Fallback?: ComponentType<ToolCallContentPartProps>;
159
144
  };
160
145
  };
161
146
  };
@@ -331,4 +316,4 @@ declare namespace internal {
331
316
  export { internal_MessageRepository as MessageRepository, internal_ProxyConfigProvider as ProxyConfigProvider };
332
317
  }
333
318
 
334
- export { index$1 as ActionBarPrimitive, AppendMessage, AssistantContentPart, type AssistantRuntime, AssistantRuntimeProvider, index$2 as BranchPickerPrimitive, type ChatModelAdapter, type ChatModelRunOptions, index$4 as ComposerPrimitive, index as ContentPartPrimitive, internal as INTERNAL, index$3 as MessagePrimitive, type ReactThreadRuntime, TextContentPart, ThreadMessage, index$5 as ThreadPrimitive, type ThreadRuntime, Unsubscribe, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useLocalRuntime, useReloadMessage };
319
+ export { index$1 as ActionBarPrimitive, AppendMessage, AssistantContentPart, type AssistantRuntime, AssistantRuntimeProvider, index$2 as BranchPickerPrimitive, type ChatModelAdapter, type ChatModelRunOptions, index$4 as ComposerPrimitive, index as ContentPartPrimitive, internal as INTERNAL, index$3 as MessagePrimitive, type ReactThreadRuntime, ThreadMessage, index$5 as ThreadPrimitive, type ThreadRuntime, Unsubscribe, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useLocalRuntime, useReloadMessage };
package/dist/index.js CHANGED
@@ -693,6 +693,7 @@ var ComposerInput = (0, import_react20.forwardRef)(
693
693
  const focus = (0, import_react20.useCallback)(() => {
694
694
  const textarea = textareaRef.current;
695
695
  if (!textarea || !autoFocusEnabled) return;
696
+ console.log("focus");
696
697
  textarea.focus();
697
698
  textarea.setSelectionRange(
698
699
  textareaRef.current.value.length,
@@ -711,6 +712,7 @@ var ComposerInput = (0, import_react20.forwardRef)(
711
712
  value,
712
713
  ...rest,
713
714
  ref,
715
+ autoFocus,
714
716
  disabled,
715
717
  onChange: (0, import_primitive5.composeEventHandlers)(onChange, (e) => {
716
718
  const composerState = useComposer.getState();