@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.
- package/README.md +5 -3
- package/dist/{Thread-ZUDFhMtm.d.mts → ThreadActions-DqqhRbf1.d.mts} +8 -3
- package/dist/{Thread-ZUDFhMtm.d.ts → ThreadActions-DqqhRbf1.d.ts} +8 -3
- package/dist/{chunk-XVZ2GVQM.mjs → chunk-7O2URLFI.mjs} +1 -1
- package/dist/chunk-7O2URLFI.mjs.map +1 -0
- package/dist/experimental.d.mts +40 -33
- package/dist/experimental.d.ts +40 -33
- package/dist/experimental.js +26 -26
- package/dist/experimental.js.map +1 -1
- package/dist/experimental.mjs +24 -24
- package/dist/experimental.mjs.map +1 -1
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +156 -120
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +157 -121
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -4
- package/dist/chunk-XVZ2GVQM.mjs.map +0 -1
package/dist/experimental.mjs
CHANGED
@@ -4,7 +4,7 @@ import {
|
|
4
4
|
useContentPartContext,
|
5
5
|
useMessageContext,
|
6
6
|
useThreadContext
|
7
|
-
} from "./chunk-
|
7
|
+
} from "./chunk-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,
|
27
|
+
const { useModelConfig, useToolUIs } = useAssistantContext();
|
28
28
|
const registerModelConfigProvider = useModelConfig(
|
29
29
|
(s) => s.registerModelConfigProvider
|
30
30
|
);
|
31
|
-
const
|
31
|
+
const setToolUI = useToolUIs((s) => s.setToolUI);
|
32
32
|
useEffect2(() => {
|
33
|
-
const {
|
33
|
+
const { toolName, render, ...rest } = tool;
|
34
34
|
const config = {
|
35
35
|
tools: {
|
36
|
-
[tool.
|
36
|
+
[tool.toolName]: rest
|
37
37
|
}
|
38
38
|
};
|
39
39
|
const unsub1 = registerModelConfigProvider(() => config);
|
40
|
-
const unsub2 = render ?
|
40
|
+
const unsub2 = render ? setToolUI(toolName, render) : void 0;
|
41
41
|
return () => {
|
42
42
|
unsub1();
|
43
43
|
unsub2?.();
|
44
44
|
};
|
45
|
-
}, [registerModelConfigProvider,
|
45
|
+
}, [registerModelConfigProvider, setToolUI, tool]);
|
46
46
|
};
|
47
47
|
|
48
|
-
// src/model-config/
|
48
|
+
// src/model-config/useAssistantToolUI.tsx
|
49
49
|
import { useEffect as useEffect3 } from "react";
|
50
|
-
var
|
51
|
-
const {
|
52
|
-
const
|
50
|
+
var useAssistantToolUI = (tool) => {
|
51
|
+
const { useToolUIs } = useAssistantContext();
|
52
|
+
const setToolUI = useToolUIs((s) => s.setToolUI);
|
53
53
|
useEffect3(() => {
|
54
54
|
if (!tool) return;
|
55
|
-
const {
|
56
|
-
return
|
57
|
-
}, [
|
55
|
+
const { toolName, render } = tool;
|
56
|
+
return setToolUI(toolName, render);
|
57
|
+
}, [setToolUI, tool]);
|
58
58
|
};
|
59
59
|
|
60
|
-
// src/model-config/
|
61
|
-
var
|
60
|
+
// src/model-config/makeAssistantTool.tsx
|
61
|
+
var makeAssistantTool = (tool) => {
|
62
62
|
const Tool = () => {
|
63
63
|
useAssistantTool(tool);
|
64
64
|
return null;
|
@@ -66,21 +66,21 @@ var makeTool = (tool) => {
|
|
66
66
|
return Tool;
|
67
67
|
};
|
68
68
|
|
69
|
-
// src/model-config/
|
70
|
-
var
|
71
|
-
const
|
72
|
-
|
69
|
+
// src/model-config/makeAssistantToolUI.tsx
|
70
|
+
var makeAssistantToolUI = (tool) => {
|
71
|
+
const ToolUI = () => {
|
72
|
+
useAssistantToolUI(tool);
|
73
73
|
return null;
|
74
74
|
};
|
75
|
-
return
|
75
|
+
return ToolUI;
|
76
76
|
};
|
77
77
|
export {
|
78
|
-
|
79
|
-
|
78
|
+
makeAssistantTool,
|
79
|
+
makeAssistantToolUI,
|
80
80
|
useAssistantContext,
|
81
81
|
useAssistantInstructions,
|
82
82
|
useAssistantTool,
|
83
|
-
|
83
|
+
useAssistantToolUI,
|
84
84
|
useComposerContext,
|
85
85
|
useContentPartContext,
|
86
86
|
useMessageContext,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/model-config/useAssistantInstructions.tsx","../src/model-config/useAssistantTool.tsx","../src/model-config/
|
1
|
+
{"version":3,"sources":["../src/model-config/useAssistantInstructions.tsx","../src/model-config/useAssistantTool.tsx","../src/model-config/useAssistantToolUI.tsx","../src/model-config/makeAssistantTool.tsx","../src/model-config/makeAssistantToolUI.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\n\nexport const useAssistantInstructions = (instruction: string) => {\n const { useModelConfig } = useAssistantContext();\n const registerModelConfigProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n useEffect(() => {\n const config = {\n system: instruction,\n };\n return registerModelConfigProvider(() => config);\n }, [registerModelConfigProvider, instruction]);\n};\n","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../primitives/message/ContentPartComponentTypes\";\nimport type { Tool } from \"../utils/ModelConfigTypes\";\n\nexport type AssistantToolProps<TArgs, TResult> = Tool<TArgs, TResult> & {\n toolName: string;\n render?: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantTool = <TArgs, TResult>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const { useModelConfig, useToolUIs } = useAssistantContext();\n const registerModelConfigProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n const setToolUI = useToolUIs((s) => s.setToolUI);\n useEffect(() => {\n const { toolName, render, ...rest } = tool;\n const config = {\n tools: {\n [tool.toolName]: rest,\n },\n };\n const unsub1 = registerModelConfigProvider(() => config);\n const unsub2 = render ? setToolUI(toolName, render) : undefined;\n return () => {\n unsub1();\n unsub2?.();\n };\n }, [registerModelConfigProvider, setToolUI, tool]);\n};\n","\"use client\";\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../primitives/message/ContentPartComponentTypes\";\n\nexport type AssistantToolUIProps<TArgs, TResult> = {\n toolName: string;\n render: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantToolUI = (\n tool: AssistantToolUIProps<any, any> | null,\n) => {\n const { useToolUIs } = useAssistantContext();\n const setToolUI = useToolUIs((s) => s.setToolUI);\n useEffect(() => {\n if (!tool) return;\n const { toolName, render } = tool;\n return setToolUI(toolName, render);\n }, [setToolUI, tool]);\n};\n","\"use client\";\nimport { type AssistantToolProps, useAssistantTool } from \"./useAssistantTool\";\n\nexport const makeAssistantTool = <TArgs, TResult>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const Tool = () => {\n useAssistantTool(tool);\n return null;\n };\n return Tool;\n};\n","\"use client\";\nimport {\n type AssistantToolUIProps,\n useAssistantToolUI,\n} from \"./useAssistantToolUI\";\n\nexport const makeAssistantToolUI = <TArgs, TResult>(\n tool: AssistantToolUIProps<TArgs, TResult>,\n) => {\n const ToolUI = () => {\n useAssistantToolUI(tool);\n return null;\n };\n return ToolUI;\n};\n"],"mappings":";;;;;;;;;AAEA,SAAS,iBAAiB;AAGnB,IAAM,2BAA2B,CAAC,gBAAwB;AAC/D,QAAM,EAAE,eAAe,IAAI,oBAAoB;AAC/C,QAAM,8BAA8B;AAAA,IAClC,CAAC,MAAM,EAAE;AAAA,EACX;AACA,YAAU,MAAM;AACd,UAAM,SAAS;AAAA,MACb,QAAQ;AAAA,IACV;AACA,WAAO,4BAA4B,MAAM,MAAM;AAAA,EACjD,GAAG,CAAC,6BAA6B,WAAW,CAAC;AAC/C;;;ACdA,SAAS,aAAAA,kBAAiB;AAUnB,IAAM,mBAAmB,CAC9B,SACG;AACH,QAAM,EAAE,gBAAgB,WAAW,IAAI,oBAAoB;AAC3D,QAAM,8BAA8B;AAAA,IAClC,CAAC,MAAM,EAAE;AAAA,EACX;AACA,QAAM,YAAY,WAAW,CAAC,MAAM,EAAE,SAAS;AAC/C,EAAAC,WAAU,MAAM;AACd,UAAM,EAAE,UAAU,QAAQ,GAAG,KAAK,IAAI;AACtC,UAAM,SAAS;AAAA,MACb,OAAO;AAAA,QACL,CAAC,KAAK,QAAQ,GAAG;AAAA,MACnB;AAAA,IACF;AACA,UAAM,SAAS,4BAA4B,MAAM,MAAM;AACvD,UAAM,SAAS,SAAS,UAAU,UAAU,MAAM,IAAI;AACtD,WAAO,MAAM;AACX,aAAO;AACP,eAAS;AAAA,IACX;AAAA,EACF,GAAG,CAAC,6BAA6B,WAAW,IAAI,CAAC;AACnD;;;ACjCA,SAAS,aAAAC,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"]}
|
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,
|
5
|
-
export {
|
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,
|
5
|
-
export {
|
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;
|