@assistant-ui/react 0.7.68 → 0.7.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/dist/api/MessageRuntime.d.ts +2 -1
  2. package/dist/api/MessageRuntime.d.ts.map +1 -1
  3. package/dist/api/MessageRuntime.js +9 -2
  4. package/dist/api/MessageRuntime.js.map +1 -1
  5. package/dist/api/MessageRuntime.mjs +9 -2
  6. package/dist/api/MessageRuntime.mjs.map +1 -1
  7. package/dist/context/providers/ThreadRuntimeProvider.d.ts.map +1 -1
  8. package/dist/context/providers/ThreadRuntimeProvider.js +3 -5
  9. package/dist/context/providers/ThreadRuntimeProvider.js.map +1 -1
  10. package/dist/context/providers/ThreadRuntimeProvider.mjs +3 -5
  11. package/dist/context/providers/ThreadRuntimeProvider.mjs.map +1 -1
  12. package/dist/context/providers/ThreadViewportProvider.d.ts +3 -0
  13. package/dist/context/providers/ThreadViewportProvider.d.ts.map +1 -0
  14. package/dist/context/providers/ThreadViewportProvider.js +63 -0
  15. package/dist/context/providers/ThreadViewportProvider.js.map +1 -0
  16. package/dist/context/providers/ThreadViewportProvider.mjs +42 -0
  17. package/dist/context/providers/ThreadViewportProvider.mjs.map +1 -0
  18. package/dist/context/react/ThreadContext.d.ts +0 -18
  19. package/dist/context/react/ThreadContext.d.ts.map +1 -1
  20. package/dist/context/react/ThreadContext.js +2 -11
  21. package/dist/context/react/ThreadContext.js.map +1 -1
  22. package/dist/context/react/ThreadContext.mjs +1 -8
  23. package/dist/context/react/ThreadContext.mjs.map +1 -1
  24. package/dist/context/react/ThreadViewportContext.d.ts +24 -0
  25. package/dist/context/react/ThreadViewportContext.d.ts.map +1 -0
  26. package/dist/context/react/ThreadViewportContext.js +44 -0
  27. package/dist/context/react/ThreadViewportContext.js.map +1 -0
  28. package/dist/context/react/ThreadViewportContext.mjs +18 -0
  29. package/dist/context/react/ThreadViewportContext.mjs.map +1 -0
  30. package/dist/context/react/index.d.ts +2 -1
  31. package/dist/context/react/index.d.ts.map +1 -1
  32. package/dist/context/react/index.js +3 -2
  33. package/dist/context/react/index.js.map +1 -1
  34. package/dist/context/react/index.mjs +4 -2
  35. package/dist/context/react/index.mjs.map +1 -1
  36. package/dist/context/stores/ThreadViewport.d.ts.map +1 -1
  37. package/dist/context/stores/ThreadViewport.js +1 -0
  38. package/dist/context/stores/ThreadViewport.js.map +1 -1
  39. package/dist/context/stores/ThreadViewport.mjs +2 -0
  40. package/dist/context/stores/ThreadViewport.mjs.map +1 -1
  41. package/dist/model-context/ModelContextTypes.d.ts +3 -0
  42. package/dist/model-context/ModelContextTypes.d.ts.map +1 -1
  43. package/dist/model-context/ModelContextTypes.js.map +1 -1
  44. package/dist/model-context/ModelContextTypes.mjs.map +1 -1
  45. package/dist/primitives/index.d.ts +1 -0
  46. package/dist/primitives/index.d.ts.map +1 -1
  47. package/dist/primitives/index.js +5 -2
  48. package/dist/primitives/index.js.map +1 -1
  49. package/dist/primitives/index.mjs +3 -1
  50. package/dist/primitives/index.mjs.map +1 -1
  51. package/dist/primitives/thread/ThreadScrollToBottom.d.ts.map +1 -1
  52. package/dist/primitives/thread/ThreadScrollToBottom.js +3 -4
  53. package/dist/primitives/thread/ThreadScrollToBottom.js.map +1 -1
  54. package/dist/primitives/thread/ThreadScrollToBottom.mjs +1 -2
  55. package/dist/primitives/thread/ThreadScrollToBottom.mjs.map +1 -1
  56. package/dist/primitives/thread/ThreadSuggestion.d.ts +2 -2
  57. package/dist/primitives/thread/ThreadSuggestion.d.ts.map +1 -1
  58. package/dist/primitives/thread/ThreadSuggestion.js +0 -1
  59. package/dist/primitives/thread/ThreadSuggestion.js.map +1 -1
  60. package/dist/primitives/thread/ThreadSuggestion.mjs +0 -1
  61. package/dist/primitives/thread/ThreadSuggestion.mjs.map +1 -1
  62. package/dist/primitives/thread/ThreadViewport.d.ts.map +1 -1
  63. package/dist/primitives/thread/ThreadViewport.js +5 -1
  64. package/dist/primitives/thread/ThreadViewport.js.map +1 -1
  65. package/dist/primitives/thread/ThreadViewport.mjs +5 -1
  66. package/dist/primitives/thread/ThreadViewport.mjs.map +1 -1
  67. package/dist/primitives/thread/useThreadViewportAutoScroll.d.ts.map +1 -1
  68. package/dist/primitives/thread/useThreadViewportAutoScroll.js +2 -1
  69. package/dist/primitives/thread/useThreadViewportAutoScroll.js.map +1 -1
  70. package/dist/primitives/thread/useThreadViewportAutoScroll.mjs +2 -4
  71. package/dist/primitives/thread/useThreadViewportAutoScroll.mjs.map +1 -1
  72. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.d.ts +1 -1
  73. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.d.ts.map +1 -1
  74. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js +1 -0
  75. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js.map +1 -1
  76. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.mjs +1 -0
  77. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.mjs.map +1 -1
  78. package/dist/runtimes/edge/streams/toolResultStream.d.ts.map +1 -1
  79. package/dist/runtimes/edge/streams/toolResultStream.js +13 -15
  80. package/dist/runtimes/edge/streams/toolResultStream.js.map +1 -1
  81. package/dist/runtimes/edge/streams/toolResultStream.mjs +13 -15
  82. package/dist/runtimes/edge/streams/toolResultStream.mjs.map +1 -1
  83. package/dist/styles/tailwindcss/thread.css +5 -5
  84. package/dist/styles/tailwindcss/thread.css.json +5 -5
  85. package/dist/utils/hooks/useOnScrollToBottom.js +2 -2
  86. package/dist/utils/hooks/useOnScrollToBottom.js.map +1 -1
  87. package/dist/utils/hooks/useOnScrollToBottom.mjs +1 -1
  88. package/dist/utils/hooks/useOnScrollToBottom.mjs.map +1 -1
  89. package/package.json +3 -3
  90. package/src/api/MessageRuntime.ts +14 -5
  91. package/src/context/providers/ThreadRuntimeProvider.tsx +4 -5
  92. package/src/context/providers/ThreadViewportProvider.tsx +49 -0
  93. package/src/context/react/ThreadContext.ts +0 -8
  94. package/src/context/react/ThreadViewportContext.ts +23 -0
  95. package/src/context/react/index.ts +4 -1
  96. package/src/context/stores/ThreadViewport.tsx +2 -0
  97. package/src/model-context/ModelContextTypes.ts +7 -0
  98. package/src/primitives/index.ts +1 -0
  99. package/src/primitives/thread/ThreadScrollToBottom.tsx +1 -2
  100. package/src/primitives/thread/ThreadSuggestion.tsx +1 -2
  101. package/src/primitives/thread/ThreadViewport.tsx +13 -1
  102. package/src/primitives/thread/useThreadViewportAutoScroll.tsx +2 -4
  103. package/src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx +4 -1
  104. package/src/runtimes/edge/streams/toolResultStream.ts +20 -18
  105. package/src/styles/tailwindcss/thread.css +5 -5
  106. 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 "./ThreadContext";
26
+ } from "./ThreadViewportContext";
24
27
 
25
28
  export {
26
29
  useThreadListItemRuntime,
@@ -1,3 +1,5 @@
1
+ "use client";
2
+
1
3
  import { create } from "zustand";
2
4
  import type { Unsubscribe } from "../../types/Unsubscribe";
3
5
 
@@ -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 = {
@@ -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: "replace";
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
- export const ThreadPrimitiveViewport = forwardRef<
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: Omit<ThreadRuntimeCore, "composer"> & {
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 tool.execute(args, { abortSignal });
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/ThreadContext";
5
+ import { useThreadViewport } from "../../context/react/ThreadViewportContext";
6
6
 
7
7
  export const useOnScrollToBottom = (callback: () => void) => {
8
8
  const callbackRef = useCallbackRef(callback);