@assistant-ui/react 0.1.7 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ import {
4
4
  useContentPartContext,
5
5
  useMessageContext,
6
6
  useThreadContext
7
- } from "./chunk-XVZ2GVQM.mjs";
7
+ } from "./chunk-7O2URLFI.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, useToolRenderers } = useAssistantContext();
27
+ const { useModelConfig, useToolUIs } = useAssistantContext();
28
28
  const registerModelConfigProvider = useModelConfig(
29
29
  (s) => s.registerModelConfigProvider
30
30
  );
31
- const setToolRenderer = useToolRenderers((s) => s.setToolRenderer);
31
+ const setToolUI = useToolUIs((s) => s.setToolUI);
32
32
  useEffect2(() => {
33
- const { name, render, ...rest } = tool;
33
+ const { toolName, render, ...rest } = tool;
34
34
  const config = {
35
35
  tools: {
36
- [tool.name]: rest
36
+ [tool.toolName]: rest
37
37
  }
38
38
  };
39
39
  const unsub1 = registerModelConfigProvider(() => config);
40
- const unsub2 = render ? setToolRenderer(name, render) : void 0;
40
+ const unsub2 = render ? setToolUI(toolName, render) : void 0;
41
41
  return () => {
42
42
  unsub1();
43
43
  unsub2?.();
44
44
  };
45
- }, [registerModelConfigProvider, setToolRenderer, tool]);
45
+ }, [registerModelConfigProvider, setToolUI, tool]);
46
46
  };
47
47
 
48
- // src/model-config/useAssistantToolRenderer.tsx
48
+ // src/model-config/useAssistantToolUI.tsx
49
49
  import { useEffect as useEffect3 } from "react";
50
- var useAssistantToolRenderer = (tool) => {
51
- const { useToolRenderers } = useAssistantContext();
52
- const setToolRenderer = useToolRenderers((s) => s.setToolRenderer);
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 { name, render } = tool;
56
- return setToolRenderer(name, render);
57
- }, [setToolRenderer, tool]);
55
+ const { toolName, render } = tool;
56
+ return setToolUI(toolName, render);
57
+ }, [setToolUI, tool]);
58
58
  };
59
59
 
60
- // src/model-config/makeTool.tsx
61
- var makeTool = (tool) => {
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/makeToolRenderer.tsx
70
- var makeToolRenderer = (tool) => {
71
- const ToolRenderer = () => {
72
- useAssistantToolRenderer(tool);
69
+ // src/model-config/makeAssistantToolUI.tsx
70
+ var makeAssistantToolUI = (tool) => {
71
+ const ToolUI = () => {
72
+ useAssistantToolUI(tool);
73
73
  return null;
74
74
  };
75
- return ToolRenderer;
75
+ return ToolUI;
76
76
  };
77
77
  export {
78
- makeTool,
79
- makeToolRenderer,
78
+ makeAssistantTool,
79
+ makeAssistantToolUI,
80
80
  useAssistantContext,
81
81
  useAssistantInstructions,
82
82
  useAssistantTool,
83
- useAssistantToolRenderer,
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/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 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,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,CACtC,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;;;ACjBO,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":["useEffect","useEffect","useEffect","useEffect"]}
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,YA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AAO;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, ComponentPropsWithoutRef } from 'react';
3
3
  import { TextareaAutosizeProps } from 'react-textarea-autosize';
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';
4
+ import { T as TextContentPartComponent, I as ImageContentPartComponent, U as UIContentPartComponent, a as ToolCallContentPartComponent, b as ToolCallContentPartProps, c as ThreadState, d as ThreadActionsState, e as Unsubscribe, M as ModelConfigProvider, f as ThreadMessage, g as ModelConfig, A as AssistantContentPart, h as AppendMessage } from './ThreadActions-DqqhRbf1.mjs';
5
+ export { l as AppendContentPart, i as AssistantMessage, m as TextContentPart, k as UserContentPart, j as UserMessage } from './ThreadActions-DqqhRbf1.mjs';
6
6
  import { Primitive } from '@radix-ui/react-primitive';
7
7
  import 'zod';
8
8
 
@@ -237,7 +237,7 @@ declare namespace index {
237
237
  export { ContentPartDisplay as Display, ContentPartImage as Image, ContentPartInProgressIndicator as InProgressIndicator, ContentPartText as Text };
238
238
  }
239
239
 
240
- type ThreadRuntime = Readonly<ThreadState & {
240
+ type ThreadRuntime = Readonly<ThreadState & ThreadActionsState & {
241
241
  subscribe: (callback: () => void) => Unsubscribe;
242
242
  }>;
243
243
 
@@ -279,6 +279,7 @@ declare class LocalRuntime implements AssistantRuntime {
279
279
  private notifySubscribers;
280
280
  subscribe(callback: () => void): Unsubscribe;
281
281
  registerModelConfigProvider(provider: ModelConfigProvider): () => boolean;
282
+ addToolResult(): void;
282
283
  }
283
284
 
284
285
  declare const useLocalRuntime: (adapter: ChatModelAdapter) => LocalRuntime;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as react from 'react';
2
2
  import { FC, ReactNode, PropsWithChildren, ComponentType, ComponentPropsWithoutRef } from 'react';
3
3
  import { TextareaAutosizeProps } from 'react-textarea-autosize';
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';
4
+ import { T as TextContentPartComponent, I as ImageContentPartComponent, U as UIContentPartComponent, a as ToolCallContentPartComponent, b as ToolCallContentPartProps, c as ThreadState, d as ThreadActionsState, e as Unsubscribe, M as ModelConfigProvider, f as ThreadMessage, g as ModelConfig, A as AssistantContentPart, h as AppendMessage } from './ThreadActions-DqqhRbf1.js';
5
+ export { l as AppendContentPart, i as AssistantMessage, m as TextContentPart, k as UserContentPart, j as UserMessage } from './ThreadActions-DqqhRbf1.js';
6
6
  import { Primitive } from '@radix-ui/react-primitive';
7
7
  import 'zod';
8
8
 
@@ -237,7 +237,7 @@ declare namespace index {
237
237
  export { ContentPartDisplay as Display, ContentPartImage as Image, ContentPartInProgressIndicator as InProgressIndicator, ContentPartText as Text };
238
238
  }
239
239
 
240
- type ThreadRuntime = Readonly<ThreadState & {
240
+ type ThreadRuntime = Readonly<ThreadState & ThreadActionsState & {
241
241
  subscribe: (callback: () => void) => Unsubscribe;
242
242
  }>;
243
243
 
@@ -279,6 +279,7 @@ declare class LocalRuntime implements AssistantRuntime {
279
279
  private notifySubscribers;
280
280
  subscribe(callback: () => void): Unsubscribe;
281
281
  registerModelConfigProvider(provider: ModelConfigProvider): () => boolean;
282
+ addToolResult(): void;
282
283
  }
283
284
 
284
285
  declare const useLocalRuntime: (adapter: ChatModelAdapter) => LocalRuntime;