@assistant-ui/react 0.7.68 → 0.7.70
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/api/MessageRuntime.d.ts +2 -1
- package/dist/api/MessageRuntime.d.ts.map +1 -1
- package/dist/api/MessageRuntime.js +9 -2
- package/dist/api/MessageRuntime.js.map +1 -1
- package/dist/api/MessageRuntime.mjs +9 -2
- package/dist/api/MessageRuntime.mjs.map +1 -1
- package/dist/context/providers/ThreadRuntimeProvider.d.ts.map +1 -1
- package/dist/context/providers/ThreadRuntimeProvider.js +3 -5
- package/dist/context/providers/ThreadRuntimeProvider.js.map +1 -1
- package/dist/context/providers/ThreadRuntimeProvider.mjs +3 -5
- package/dist/context/providers/ThreadRuntimeProvider.mjs.map +1 -1
- package/dist/context/providers/ThreadViewportProvider.d.ts +3 -0
- package/dist/context/providers/ThreadViewportProvider.d.ts.map +1 -0
- package/dist/context/providers/ThreadViewportProvider.js +63 -0
- package/dist/context/providers/ThreadViewportProvider.js.map +1 -0
- package/dist/context/providers/ThreadViewportProvider.mjs +42 -0
- package/dist/context/providers/ThreadViewportProvider.mjs.map +1 -0
- package/dist/context/react/ThreadContext.d.ts +0 -18
- package/dist/context/react/ThreadContext.d.ts.map +1 -1
- package/dist/context/react/ThreadContext.js +2 -11
- package/dist/context/react/ThreadContext.js.map +1 -1
- package/dist/context/react/ThreadContext.mjs +1 -8
- package/dist/context/react/ThreadContext.mjs.map +1 -1
- package/dist/context/react/ThreadViewportContext.d.ts +24 -0
- package/dist/context/react/ThreadViewportContext.d.ts.map +1 -0
- package/dist/context/react/ThreadViewportContext.js +44 -0
- package/dist/context/react/ThreadViewportContext.js.map +1 -0
- package/dist/context/react/ThreadViewportContext.mjs +18 -0
- package/dist/context/react/ThreadViewportContext.mjs.map +1 -0
- package/dist/context/react/index.d.ts +2 -1
- package/dist/context/react/index.d.ts.map +1 -1
- package/dist/context/react/index.js +3 -2
- package/dist/context/react/index.js.map +1 -1
- package/dist/context/react/index.mjs +4 -2
- package/dist/context/react/index.mjs.map +1 -1
- package/dist/context/stores/ThreadViewport.d.ts.map +1 -1
- package/dist/context/stores/ThreadViewport.js +1 -0
- package/dist/context/stores/ThreadViewport.js.map +1 -1
- package/dist/context/stores/ThreadViewport.mjs +2 -0
- package/dist/context/stores/ThreadViewport.mjs.map +1 -1
- package/dist/model-context/ModelContextTypes.d.ts +3 -0
- package/dist/model-context/ModelContextTypes.d.ts.map +1 -1
- package/dist/model-context/ModelContextTypes.js.map +1 -1
- package/dist/model-context/ModelContextTypes.mjs.map +1 -1
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/primitives/index.js +5 -2
- package/dist/primitives/index.js.map +1 -1
- package/dist/primitives/index.mjs +3 -1
- package/dist/primitives/index.mjs.map +1 -1
- package/dist/primitives/thread/ThreadScrollToBottom.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadScrollToBottom.js +3 -4
- package/dist/primitives/thread/ThreadScrollToBottom.js.map +1 -1
- package/dist/primitives/thread/ThreadScrollToBottom.mjs +1 -2
- package/dist/primitives/thread/ThreadScrollToBottom.mjs.map +1 -1
- package/dist/primitives/thread/ThreadSuggestion.d.ts +2 -2
- package/dist/primitives/thread/ThreadSuggestion.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadSuggestion.js +0 -1
- package/dist/primitives/thread/ThreadSuggestion.js.map +1 -1
- package/dist/primitives/thread/ThreadSuggestion.mjs +0 -1
- package/dist/primitives/thread/ThreadSuggestion.mjs.map +1 -1
- package/dist/primitives/thread/ThreadViewport.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadViewport.js +5 -1
- package/dist/primitives/thread/ThreadViewport.js.map +1 -1
- package/dist/primitives/thread/ThreadViewport.mjs +5 -1
- package/dist/primitives/thread/ThreadViewport.mjs.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.d.ts.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.js +2 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.js.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.mjs +2 -4
- package/dist/primitives/thread/useThreadViewportAutoScroll.mjs.map +1 -1
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.d.ts +1 -1
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js +1 -0
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.mjs +1 -0
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/edge/streams/toolResultStream.d.ts.map +1 -1
- package/dist/runtimes/edge/streams/toolResultStream.js +13 -15
- package/dist/runtimes/edge/streams/toolResultStream.js.map +1 -1
- package/dist/runtimes/edge/streams/toolResultStream.mjs +13 -15
- package/dist/runtimes/edge/streams/toolResultStream.mjs.map +1 -1
- package/dist/styles/tailwindcss/thread.css +5 -5
- package/dist/styles/tailwindcss/thread.css.json +5 -5
- package/dist/utils/hooks/useOnScrollToBottom.js +2 -2
- package/dist/utils/hooks/useOnScrollToBottom.js.map +1 -1
- package/dist/utils/hooks/useOnScrollToBottom.mjs +1 -1
- package/dist/utils/hooks/useOnScrollToBottom.mjs.map +1 -1
- package/package.json +3 -3
- package/src/api/MessageRuntime.ts +14 -5
- package/src/context/providers/ThreadRuntimeProvider.tsx +4 -5
- package/src/context/providers/ThreadViewportProvider.tsx +49 -0
- package/src/context/react/ThreadContext.ts +0 -8
- package/src/context/react/ThreadViewportContext.ts +23 -0
- package/src/context/react/index.ts +4 -1
- package/src/context/stores/ThreadViewport.tsx +2 -0
- package/src/model-context/ModelContextTypes.ts +7 -0
- package/src/primitives/index.ts +1 -0
- package/src/primitives/thread/ThreadScrollToBottom.tsx +1 -2
- package/src/primitives/thread/ThreadSuggestion.tsx +1 -2
- package/src/primitives/thread/ThreadViewport.tsx +13 -1
- package/src/primitives/thread/useThreadViewportAutoScroll.tsx +2 -4
- package/src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx +4 -1
- package/src/runtimes/edge/streams/toolResultStream.ts +20 -18
- package/src/styles/tailwindcss/thread.css +5 -5
- package/src/utils/hooks/useOnScrollToBottom.tsx +1 -1
@@ -0,0 +1,23 @@
|
|
1
|
+
"use client";
|
2
|
+
|
3
|
+
import { createContext } from "react";
|
4
|
+
import { ReadonlyStore } from "../ReadonlyStore";
|
5
|
+
import { UseBoundStore } from "zustand";
|
6
|
+
import { createContextHook } from "./utils/createContextHook";
|
7
|
+
import { createContextStoreHook } from "./utils/createContextStoreHook";
|
8
|
+
import { ThreadViewportState } from "../stores";
|
9
|
+
|
10
|
+
export type ThreadViewportContextValue = {
|
11
|
+
useThreadViewport: UseBoundStore<ReadonlyStore<ThreadViewportState>>;
|
12
|
+
};
|
13
|
+
|
14
|
+
export const ThreadViewportContext =
|
15
|
+
createContext<ThreadViewportContextValue | null>(null);
|
16
|
+
|
17
|
+
const useThreadViewportContext = createContextHook(
|
18
|
+
ThreadViewportContext,
|
19
|
+
"ThreadPrimitive.Viewport",
|
20
|
+
);
|
21
|
+
|
22
|
+
export const { useThreadViewport, useThreadViewportStore } =
|
23
|
+
createContextStoreHook(useThreadViewportContext, "useThreadViewport");
|
@@ -18,9 +18,12 @@ export {
|
|
18
18
|
* @deprecated This method was renamed to `useThreadModelContext`.
|
19
19
|
*/
|
20
20
|
useThreadModelContext as useThreadModelConfig,
|
21
|
+
} from "./ThreadContext";
|
22
|
+
|
23
|
+
export {
|
21
24
|
useThreadViewport,
|
22
25
|
useThreadViewportStore,
|
23
|
-
} from "./
|
26
|
+
} from "./ThreadViewportContext";
|
24
27
|
|
25
28
|
export {
|
26
29
|
useThreadListItemRuntime,
|
@@ -27,10 +27,16 @@ export type LanguageModelConfig = z.infer<typeof LanguageModelConfigSchema>;
|
|
27
27
|
type ToolExecuteFunction<TArgs, TResult> = (
|
28
28
|
args: TArgs,
|
29
29
|
context: {
|
30
|
+
toolCallId: string;
|
30
31
|
abortSignal: AbortSignal;
|
31
32
|
},
|
32
33
|
) => TResult | Promise<TResult>;
|
33
34
|
|
35
|
+
type OnSchemaValidationErrorFunction<TResult> = ToolExecuteFunction<
|
36
|
+
unknown,
|
37
|
+
TResult
|
38
|
+
>;
|
39
|
+
|
34
40
|
export type Tool<
|
35
41
|
TArgs extends Record<string, unknown> = Record<string | number, unknown>,
|
36
42
|
TResult = unknown,
|
@@ -38,6 +44,7 @@ export type Tool<
|
|
38
44
|
description?: string | undefined;
|
39
45
|
parameters: z.ZodSchema<TArgs> | JSONSchema7;
|
40
46
|
execute?: ToolExecuteFunction<TArgs, TResult>;
|
47
|
+
experimental_onSchemaValidationError?: OnSchemaValidationErrorFunction<TResult>;
|
41
48
|
};
|
42
49
|
|
43
50
|
export type ModelContext = {
|
package/src/primitives/index.ts
CHANGED
@@ -12,3 +12,4 @@ export * as ThreadListItemPrimitive from "./threadListItem";
|
|
12
12
|
export { useContentPartDisplay } from "./contentPart/useContentPartDisplay";
|
13
13
|
export { useContentPartImage } from "./contentPart/useContentPartImage";
|
14
14
|
export { useContentPartText } from "./contentPart/useContentPartText";
|
15
|
+
export { useThreadViewportAutoScroll } from "./thread/useThreadViewportAutoScroll";
|
@@ -6,8 +6,7 @@ import {
|
|
6
6
|
createActionButton,
|
7
7
|
} from "../../utils/createActionButton";
|
8
8
|
import { useCallback } from "react";
|
9
|
-
import { useThreadViewport } from "../../context";
|
10
|
-
import { useThreadViewportStore } from "../../context/react/ThreadContext";
|
9
|
+
import { useThreadViewport, useThreadViewportStore } from "../../context/react/ThreadViewportContext";
|
11
10
|
|
12
11
|
const useThreadScrollToBottom = () => {
|
13
12
|
const isAtBottom = useThreadViewport((s) => s.isAtBottom);
|
@@ -14,7 +14,7 @@ const useThreadSuggestion = ({
|
|
14
14
|
autoSend,
|
15
15
|
}: {
|
16
16
|
prompt: string;
|
17
|
-
method
|
17
|
+
method?: "replace";
|
18
18
|
autoSend?: boolean | undefined;
|
19
19
|
}) => {
|
20
20
|
const threadRuntime = useThreadRuntime();
|
@@ -23,7 +23,6 @@ const useThreadSuggestion = ({
|
|
23
23
|
const callback = useCallback(() => {
|
24
24
|
if (autoSend && !threadRuntime.getState().isRunning) {
|
25
25
|
threadRuntime.append(prompt);
|
26
|
-
threadRuntime.composer.setText("");
|
27
26
|
} else {
|
28
27
|
threadRuntime.composer.setText(prompt);
|
29
28
|
}
|
@@ -4,6 +4,7 @@ import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
4
4
|
import { Primitive } from "@radix-ui/react-primitive";
|
5
5
|
import { type ComponentRef, forwardRef, ComponentPropsWithoutRef } from "react";
|
6
6
|
import { useThreadViewportAutoScroll } from "./useThreadViewportAutoScroll";
|
7
|
+
import { ThreadViewportProvider } from "../../context/providers/ThreadViewportProvider";
|
7
8
|
|
8
9
|
export namespace ThreadPrimitiveViewport {
|
9
10
|
export type Element = ComponentRef<typeof Primitive.div>;
|
@@ -12,7 +13,7 @@ export namespace ThreadPrimitiveViewport {
|
|
12
13
|
};
|
13
14
|
}
|
14
15
|
|
15
|
-
|
16
|
+
const ThreadPrimitiveViewportScrollable = forwardRef<
|
16
17
|
ThreadPrimitiveViewport.Element,
|
17
18
|
ThreadPrimitiveViewport.Props
|
18
19
|
>(({ autoScroll, children, ...rest }, forwardedRef) => {
|
@@ -29,4 +30,15 @@ export const ThreadPrimitiveViewport = forwardRef<
|
|
29
30
|
);
|
30
31
|
});
|
31
32
|
|
33
|
+
export const ThreadPrimitiveViewport = forwardRef<
|
34
|
+
ThreadPrimitiveViewport.Element,
|
35
|
+
ThreadPrimitiveViewport.Props
|
36
|
+
>((props, ref) => {
|
37
|
+
return (
|
38
|
+
<ThreadViewportProvider>
|
39
|
+
<ThreadPrimitiveViewportScrollable {...props} ref={ref} />
|
40
|
+
</ThreadViewportProvider>
|
41
|
+
);
|
42
|
+
});
|
43
|
+
|
32
44
|
ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
|
@@ -2,14 +2,12 @@
|
|
2
2
|
|
3
3
|
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
4
4
|
import { RefCallback, useEffect, useRef } from "react";
|
5
|
-
import {
|
6
|
-
useThreadRuntime,
|
7
|
-
useThreadViewportStore,
|
8
|
-
} from "../../context/react/ThreadContext";
|
5
|
+
import { useThreadRuntime } from "../../context/react/ThreadContext";
|
9
6
|
import { useOnResizeContent } from "../../utils/hooks/useOnResizeContent";
|
10
7
|
import { useOnScrollToBottom } from "../../utils/hooks/useOnScrollToBottom";
|
11
8
|
import { useManagedRef } from "../../utils/hooks/useManagedRef";
|
12
9
|
import { writableStore } from "../../context/ReadonlyStore";
|
10
|
+
import { useThreadViewportStore } from "../../context/react/ThreadViewportContext";
|
13
11
|
|
14
12
|
export namespace useThreadViewportAutoScroll {
|
15
13
|
export type Options = {
|
@@ -18,7 +18,7 @@ export class DefaultEditComposerRuntimeCore extends BaseComposerRuntimeCore {
|
|
18
18
|
private _parentId;
|
19
19
|
private _sourceId;
|
20
20
|
constructor(
|
21
|
-
private runtime:
|
21
|
+
private runtime: ThreadRuntimeCore & {
|
22
22
|
adapters?: { attachments?: AttachmentAdapter | undefined } | undefined;
|
23
23
|
},
|
24
24
|
private endEditCallback: () => void,
|
@@ -36,6 +36,9 @@ export class DefaultEditComposerRuntimeCore extends BaseComposerRuntimeCore {
|
|
36
36
|
this._nonTextParts = message.content.filter(
|
37
37
|
(part) => part.type !== "text" && part.type !== "ui",
|
38
38
|
);
|
39
|
+
|
40
|
+
// Use the runConfig from the regular (non-edit) composer as the initial runConfig for the edit composer
|
41
|
+
this.setRunConfig({ ...runtime.composer.runConfig });
|
39
42
|
}
|
40
43
|
|
41
44
|
public async handleSend(
|
@@ -75,30 +75,32 @@ export function toolResultStream(
|
|
75
75
|
return;
|
76
76
|
}
|
77
77
|
|
78
|
-
if (tool.parameters instanceof z.ZodType) {
|
79
|
-
const result = tool.parameters.safeParse(args);
|
80
|
-
if (!result.success) {
|
81
|
-
controller.enqueue({
|
82
|
-
type: "tool-result",
|
83
|
-
toolCallType,
|
84
|
-
toolCallId,
|
85
|
-
toolName,
|
86
|
-
result:
|
87
|
-
"Function parameter validation failed. " +
|
88
|
-
JSON.stringify(result.error.issues),
|
89
|
-
isError: true,
|
90
|
-
});
|
91
|
-
return;
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
78
|
toolCallExecutions.set(
|
96
79
|
toolCallId,
|
97
80
|
(async () => {
|
98
81
|
if (!tool.execute) return;
|
99
82
|
|
83
|
+
let executeFn = tool.execute;
|
84
|
+
|
85
|
+
if (tool.parameters instanceof z.ZodType) {
|
86
|
+
const result = tool.parameters.safeParse(args);
|
87
|
+
if (!result.success) {
|
88
|
+
executeFn =
|
89
|
+
tool.experimental_onSchemaValidationError ??
|
90
|
+
(() => {
|
91
|
+
throw (
|
92
|
+
"Function parameter validation failed. " +
|
93
|
+
JSON.stringify(result.error.issues)
|
94
|
+
);
|
95
|
+
});
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
100
99
|
try {
|
101
|
-
const result = await
|
100
|
+
const result = await executeFn(args, {
|
101
|
+
toolCallId,
|
102
|
+
abortSignal,
|
103
|
+
});
|
102
104
|
|
103
105
|
controller.enqueue({
|
104
106
|
type: "tool-result",
|
@@ -9,7 +9,7 @@
|
|
9
9
|
}
|
10
10
|
|
11
11
|
.aui-thread-viewport-footer {
|
12
|
-
@apply max-w-aui-thread sticky bottom-0 mt-3 flex w-full flex-col items-center justify-end rounded-t-lg bg-inherit pb-4;
|
12
|
+
@apply max-w-[var(--aui-thread-max-width)] sticky bottom-0 mt-3 flex w-full flex-col items-center justify-end rounded-t-lg bg-inherit pb-4;
|
13
13
|
}
|
14
14
|
|
15
15
|
.aui-thread-scroll-to-bottom {
|
@@ -27,7 +27,7 @@
|
|
27
27
|
/* thread welcome */
|
28
28
|
|
29
29
|
.aui-thread-welcome-root {
|
30
|
-
@apply max-w-aui-thread flex w-full flex-grow flex-col;
|
30
|
+
@apply max-w-[var(--aui-thread-max-width)] flex w-full flex-grow flex-col;
|
31
31
|
}
|
32
32
|
|
33
33
|
.aui-thread-welcome-center {
|
@@ -108,7 +108,7 @@
|
|
108
108
|
|
109
109
|
.aui-user-message-root {
|
110
110
|
@apply grid auto-rows-auto grid-cols-[minmax(72px,1fr)_auto] gap-y-2 [&>*]:col-start-2;
|
111
|
-
@apply max-w-aui-thread w-full py-4;
|
111
|
+
@apply max-w-[var(--aui-thread-max-width)] w-full py-4;
|
112
112
|
}
|
113
113
|
|
114
114
|
:where(.aui-user-message-root) > .aui-user-action-bar-root {
|
@@ -146,7 +146,7 @@
|
|
146
146
|
/* edit composer */
|
147
147
|
|
148
148
|
.aui-edit-composer-root {
|
149
|
-
@apply bg-aui-muted max-w-aui-thread my-4 flex w-full flex-col gap-2 rounded-xl;
|
149
|
+
@apply bg-aui-muted max-w-[var(--aui-thread-max-width)] my-4 flex w-full flex-col gap-2 rounded-xl;
|
150
150
|
}
|
151
151
|
|
152
152
|
.aui-edit-composer-input {
|
@@ -161,7 +161,7 @@
|
|
161
161
|
|
162
162
|
.aui-assistant-message-root {
|
163
163
|
@apply grid grid-cols-[auto_auto_1fr] grid-rows-[auto_1fr];
|
164
|
-
@apply max-w-aui-thread relative w-full py-4;
|
164
|
+
@apply max-w-[var(--aui-thread-max-width)] relative w-full py-4;
|
165
165
|
}
|
166
166
|
|
167
167
|
:where(.aui-assistant-message-root) > .aui-avatar-root {
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
|
4
4
|
import { useEffect } from "react";
|
5
|
-
import { useThreadViewport } from "../../context/react/
|
5
|
+
import { useThreadViewport } from "../../context/react/ThreadViewportContext";
|
6
6
|
|
7
7
|
export const useOnScrollToBottom = (callback: () => void) => {
|
8
8
|
const callbackRef = useCallbackRef(callback);
|