@assistant-ui/react 0.7.35 → 0.7.36
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.
- package/dist/internal.d.ts +2 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +7 -1
- package/dist/internal.js.map +1 -1
- package/dist/internal.mjs +5 -1
- package/dist/internal.mjs.map +1 -1
- package/dist/primitive-hooks/contentPart/useContentPartDisplay.d.ts +3 -0
- package/dist/primitive-hooks/contentPart/useContentPartDisplay.d.ts.map +1 -1
- package/dist/primitive-hooks/contentPart/useContentPartDisplay.js.map +1 -1
- package/dist/primitive-hooks/contentPart/useContentPartDisplay.mjs.map +1 -1
- package/dist/primitives/message/MessageContent.d.ts +2 -1
- package/dist/primitives/message/MessageContent.d.ts.map +1 -1
- package/dist/primitives/message/MessageContent.js +6 -2
- package/dist/primitives/message/MessageContent.js.map +1 -1
- package/dist/primitives/message/MessageContent.mjs +6 -2
- package/dist/primitives/message/MessageContent.mjs.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.js +1 -0
- package/dist/runtimes/composer/BaseComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs +1 -0
- package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/core/ComposerRuntimeCore.d.ts +1 -1
- package/dist/runtimes/core/ComposerRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.d.ts +28 -0
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.d.ts.map +1 -1
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.js +6 -0
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.js.map +1 -1
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.mjs +6 -0
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.mjs.map +1 -1
- package/dist/runtimes/edge/converters/fromLanguageModelMessages.d.ts.map +1 -1
- package/dist/runtimes/edge/converters/fromLanguageModelMessages.js +8 -1
- package/dist/runtimes/edge/converters/fromLanguageModelMessages.js.map +1 -1
- package/dist/runtimes/edge/converters/fromLanguageModelMessages.mjs +8 -1
- package/dist/runtimes/edge/converters/fromLanguageModelMessages.mjs.map +1 -1
- package/dist/runtimes/edge/converters/toLanguageModelMessages.d.ts.map +1 -1
- package/dist/runtimes/edge/converters/toLanguageModelMessages.js +7 -0
- package/dist/runtimes/edge/converters/toLanguageModelMessages.js.map +1 -1
- package/dist/runtimes/edge/converters/toLanguageModelMessages.mjs +7 -0
- package/dist/runtimes/edge/converters/toLanguageModelMessages.mjs.map +1 -1
- package/dist/runtimes/external-store/ThreadMessageLike.d.ts +3 -3
- package/dist/runtimes/external-store/ThreadMessageLike.d.ts.map +1 -1
- package/dist/runtimes/external-store/ThreadMessageLike.js +7 -2
- package/dist/runtimes/external-store/ThreadMessageLike.js.map +1 -1
- package/dist/runtimes/external-store/ThreadMessageLike.mjs +7 -2
- package/dist/runtimes/external-store/ThreadMessageLike.mjs.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.d.ts +2 -1
- package/dist/runtimes/local/LocalRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.js +7 -2
- package/dist/runtimes/local/LocalRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.mjs +7 -2
- package/dist/runtimes/local/LocalRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/LocalRuntimeOptions.d.ts +3 -3
- package/dist/runtimes/local/LocalRuntimeOptions.d.ts.map +1 -1
- package/dist/runtimes/local/LocalRuntimeOptions.js.map +1 -1
- package/dist/runtimes/local/LocalRuntimeOptions.mjs.map +1 -1
- package/dist/styles/index.css +1 -0
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/tailwindcss/thread.css +1 -1
- package/dist/styles/tailwindcss/thread.css.json +1 -1
- package/dist/types/AssistantTypes.d.ts +44 -2
- package/dist/types/AssistantTypes.d.ts.map +1 -1
- package/dist/types/AssistantTypes.js.map +1 -1
- package/dist/types/ContentPartComponentTypes.d.ts +3 -1
- package/dist/types/ContentPartComponentTypes.d.ts.map +1 -1
- package/dist/types/ContentPartComponentTypes.js.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/package.json +1 -1
- package/src/internal.ts +2 -0
- package/src/primitive-hooks/contentPart/useContentPartDisplay.tsx +3 -0
- package/src/primitives/message/MessageContent.tsx +9 -1
- package/src/runtimes/composer/BaseComposerRuntimeCore.tsx +1 -0
- package/src/runtimes/core/ComposerRuntimeCore.tsx +1 -1
- package/src/runtimes/edge/EdgeRuntimeRequestOptions.ts +7 -0
- package/src/runtimes/edge/converters/fromLanguageModelMessages.ts +9 -2
- package/src/runtimes/edge/converters/toLanguageModelMessages.ts +15 -1
- package/src/runtimes/external-store/ThreadMessageLike.tsx +11 -4
- package/src/runtimes/local/LocalRuntimeCore.tsx +10 -4
- package/src/runtimes/local/LocalRuntimeOptions.tsx +2 -2
- package/src/styles/tailwindcss/thread.css +1 -1
- package/src/types/AssistantTypes.ts +45 -0
- package/src/types/ContentPartComponentTypes.tsx +4 -0
- package/src/types/index.ts +6 -5
|
@@ -24,6 +24,12 @@ const ImageContentPartSchema = z.object({
|
|
|
24
24
|
image: z.string(),
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
+
const FileContentPartSchema = z.object({
|
|
28
|
+
type: z.literal("file"),
|
|
29
|
+
data: z.string(),
|
|
30
|
+
mimeType: z.string(),
|
|
31
|
+
});
|
|
32
|
+
|
|
27
33
|
const Unstable_AudioContentPart = z.object({
|
|
28
34
|
type: z.literal("audio"),
|
|
29
35
|
audio: z.object({
|
|
@@ -49,6 +55,7 @@ const CoreUserMessageSchema = z.object({
|
|
|
49
55
|
z.discriminatedUnion("type", [
|
|
50
56
|
TextContentPartSchema,
|
|
51
57
|
ImageContentPartSchema,
|
|
58
|
+
FileContentPartSchema,
|
|
52
59
|
Unstable_AudioContentPart,
|
|
53
60
|
]),
|
|
54
61
|
)
|
|
@@ -49,9 +49,16 @@ export const fromLanguageModelMessages = (
|
|
|
49
49
|
throw new Error("Only images with URL data are supported");
|
|
50
50
|
}
|
|
51
51
|
case "file": {
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
if (part.data instanceof URL) {
|
|
53
|
+
return {
|
|
54
|
+
type: "file",
|
|
55
|
+
data: part.data.href,
|
|
56
|
+
mimeType: part.mimeType,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
throw new Error("Only files with URL data are supported");
|
|
54
60
|
}
|
|
61
|
+
|
|
55
62
|
default: {
|
|
56
63
|
const unhandledType: never = type;
|
|
57
64
|
throw new Error(`Unknown content part type: ${unhandledType}`);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
LanguageModelV1FilePart,
|
|
2
3
|
LanguageModelV1ImagePart,
|
|
3
4
|
LanguageModelV1Message,
|
|
4
5
|
LanguageModelV1TextPart,
|
|
@@ -90,7 +91,12 @@ export function toLanguageModelMessages(
|
|
|
90
91
|
const msg: LanguageModelV1Message = {
|
|
91
92
|
role: "user",
|
|
92
93
|
content: content.map(
|
|
93
|
-
(
|
|
94
|
+
(
|
|
95
|
+
part,
|
|
96
|
+
):
|
|
97
|
+
| LanguageModelV1TextPart
|
|
98
|
+
| LanguageModelV1ImagePart
|
|
99
|
+
| LanguageModelV1FilePart => {
|
|
94
100
|
const type = part.type;
|
|
95
101
|
switch (type) {
|
|
96
102
|
case "text": {
|
|
@@ -104,6 +110,14 @@ export function toLanguageModelMessages(
|
|
|
104
110
|
};
|
|
105
111
|
}
|
|
106
112
|
|
|
113
|
+
case "file": {
|
|
114
|
+
return {
|
|
115
|
+
type: "file",
|
|
116
|
+
data: new URL(part.data),
|
|
117
|
+
mimeType: part.mimeType,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
107
121
|
default: {
|
|
108
122
|
const unhandledType: "ui" | "audio" = type;
|
|
109
123
|
throw new Error(
|
|
@@ -11,11 +11,12 @@ import {
|
|
|
11
11
|
ThreadUserMessage,
|
|
12
12
|
ThreadSystemMessage,
|
|
13
13
|
CompleteAttachment,
|
|
14
|
+
FileContentPart,
|
|
15
|
+
Unstable_AudioContentPart,
|
|
14
16
|
} from "../../types";
|
|
15
17
|
import {
|
|
16
18
|
CoreToolCallContentPart,
|
|
17
19
|
ThreadStep,
|
|
18
|
-
Unstable_AudioContentPart,
|
|
19
20
|
} from "../../types/AssistantTypes";
|
|
20
21
|
|
|
21
22
|
export type ThreadMessageLike = {
|
|
@@ -25,6 +26,7 @@ export type ThreadMessageLike = {
|
|
|
25
26
|
| readonly (
|
|
26
27
|
| TextContentPart
|
|
27
28
|
| ImageContentPart
|
|
29
|
+
| FileContentPart
|
|
28
30
|
| Unstable_AudioContentPart
|
|
29
31
|
| ToolCallContentPart<any, any>
|
|
30
32
|
| CoreToolCallContentPart<any, any>
|
|
@@ -93,8 +95,10 @@ export const fromThreadMessageLike = (
|
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
default: {
|
|
96
|
-
const unhandledType: "image" | "audio" = type;
|
|
97
|
-
throw new Error(
|
|
98
|
+
const unhandledType: "image" | "audio" | "file" = type;
|
|
99
|
+
throw new Error(
|
|
100
|
+
`Unsupported assistant content part type: ${unhandledType}`,
|
|
101
|
+
);
|
|
98
102
|
}
|
|
99
103
|
}
|
|
100
104
|
})
|
|
@@ -118,11 +122,14 @@ export const fromThreadMessageLike = (
|
|
|
118
122
|
case "ui":
|
|
119
123
|
case "image":
|
|
120
124
|
case "audio":
|
|
125
|
+
case "file":
|
|
121
126
|
return part;
|
|
122
127
|
|
|
123
128
|
default: {
|
|
124
129
|
const unhandledType: "tool-call" = type;
|
|
125
|
-
throw new Error(
|
|
130
|
+
throw new Error(
|
|
131
|
+
`Unsupported user content part type: ${unhandledType}`,
|
|
132
|
+
);
|
|
126
133
|
}
|
|
127
134
|
}
|
|
128
135
|
}),
|
|
@@ -2,14 +2,20 @@ import type { CoreMessage } from "../../types/AssistantTypes";
|
|
|
2
2
|
import { BaseAssistantRuntimeCore } from "../core/BaseAssistantRuntimeCore";
|
|
3
3
|
import { LocalThreadRuntimeCore } from "./LocalThreadRuntimeCore";
|
|
4
4
|
import { LocalRuntimeOptionsBase } from "./LocalRuntimeOptions";
|
|
5
|
-
import { fromCoreMessages } from "../edge/converters/fromCoreMessage";
|
|
6
5
|
import { LocalThreadListRuntimeCore } from "./LocalThreadListRuntimeCore";
|
|
7
6
|
import { ExportedMessageRepository } from "../utils/MessageRepository";
|
|
7
|
+
import { ThreadMessageLike } from "../external-store";
|
|
8
|
+
import { fromThreadMessageLike } from "../external-store/ThreadMessageLike";
|
|
9
|
+
import { generateId } from "../../internal";
|
|
10
|
+
import { getAutoStatus } from "../external-store/auto-status";
|
|
8
11
|
|
|
9
12
|
const getExportFromInitialMessages = (
|
|
10
|
-
initialMessages: readonly
|
|
13
|
+
initialMessages: readonly ThreadMessageLike[],
|
|
11
14
|
): ExportedMessageRepository => {
|
|
12
|
-
const messages =
|
|
15
|
+
const messages = initialMessages.map((i, idx) => {
|
|
16
|
+
const isLast = idx === initialMessages.length - 1;
|
|
17
|
+
return fromThreadMessageLike(i, generateId(), getAutoStatus(isLast, false));
|
|
18
|
+
});
|
|
13
19
|
return {
|
|
14
20
|
messages: messages.map((m, idx) => ({
|
|
15
21
|
parentId: messages[idx - 1]?.id ?? null,
|
|
@@ -26,7 +32,7 @@ export class LocalRuntimeCore extends BaseAssistantRuntimeCore {
|
|
|
26
32
|
|
|
27
33
|
constructor(
|
|
28
34
|
options: LocalRuntimeOptionsBase,
|
|
29
|
-
initialMessages: readonly
|
|
35
|
+
initialMessages: readonly ThreadMessageLike[] | undefined,
|
|
30
36
|
) {
|
|
31
37
|
super();
|
|
32
38
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CoreMessage } from "../../types";
|
|
2
1
|
import { AttachmentAdapter } from "../attachment/AttachmentAdapter";
|
|
2
|
+
import { ThreadMessageLike } from "../external-store";
|
|
3
3
|
import { FeedbackAdapter } from "../feedback/FeedbackAdapter";
|
|
4
4
|
import { SpeechSynthesisAdapter } from "../speech/SpeechAdapterTypes";
|
|
5
5
|
import { ChatModelAdapter } from "./ChatModelAdapter";
|
|
@@ -16,7 +16,7 @@ export type LocalRuntimeOptionsBase = {
|
|
|
16
16
|
|
|
17
17
|
// TODO align LocalRuntimeOptions with LocalRuntimeOptionsBase
|
|
18
18
|
export type LocalRuntimeOptions = Omit<LocalRuntimeOptionsBase, "adapters"> & {
|
|
19
|
-
initialMessages?: readonly
|
|
19
|
+
initialMessages?: readonly ThreadMessageLike[] | undefined;
|
|
20
20
|
adapters?: Omit<LocalRuntimeOptionsBase["adapters"], "chatModel"> | undefined;
|
|
21
21
|
};
|
|
22
22
|
|
|
@@ -13,6 +13,12 @@ export type ImageContentPart = {
|
|
|
13
13
|
readonly image: string;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
export type FileContentPart = {
|
|
17
|
+
readonly type: "file";
|
|
18
|
+
readonly data: string;
|
|
19
|
+
readonly mimeType: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
16
22
|
export type Unstable_AudioContentPart = {
|
|
17
23
|
readonly type: "audio";
|
|
18
24
|
readonly audio: {
|
|
@@ -21,6 +27,43 @@ export type Unstable_AudioContentPart = {
|
|
|
21
27
|
};
|
|
22
28
|
};
|
|
23
29
|
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated UI content parts are deprecated and will be removed in v0.8.0.
|
|
32
|
+
* Migration guide for external-store users using UI content parts:
|
|
33
|
+
* If you must, store UI elements on your external store messages, update your
|
|
34
|
+
* external store converter:
|
|
35
|
+
* ```ts
|
|
36
|
+
* const UI_PLACEHOLDER = Object.freeze({ type: "text", text: "UI content placeholder" });
|
|
37
|
+
* const convertMessage = (message: TMessage): ThreadMessageLike => ({
|
|
38
|
+
* content: [
|
|
39
|
+
* // other content parts,
|
|
40
|
+
* UI_PLACEHOLDER
|
|
41
|
+
* ],
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* Then, define a custom `TextContentPartComponent`:
|
|
46
|
+
*
|
|
47
|
+
* ```tsx
|
|
48
|
+
* const MyText: FC = () => {
|
|
49
|
+
* const isUIPlaceholder = useContentPart(p => p === UI_PLACEHOLDER);
|
|
50
|
+
*
|
|
51
|
+
* // this assumes that you have a `display` field on your original message objects before conversion.
|
|
52
|
+
* const ui = useMessage(m => isUIPlaceholder ? getExternalStoreMessage(m).display : undefined);
|
|
53
|
+
* if (ui) {
|
|
54
|
+
* return ui;
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* return <MarkdownText />; // your default text component
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* Pass this component to your Thread:
|
|
62
|
+
*
|
|
63
|
+
* ```tsx
|
|
64
|
+
* <Thread assistantMessage={{ components: { Text: MyText } }} userMessage={{ components: { Text: MyText } }} />
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
24
67
|
export type UIContentPart = {
|
|
25
68
|
readonly type: "ui";
|
|
26
69
|
readonly display: ReactNode;
|
|
@@ -48,6 +91,7 @@ export type ToolCallContentPart<
|
|
|
48
91
|
export type ThreadUserContentPart =
|
|
49
92
|
| TextContentPart
|
|
50
93
|
| ImageContentPart
|
|
94
|
+
| FileContentPart
|
|
51
95
|
| Unstable_AudioContentPart
|
|
52
96
|
| UIContentPart;
|
|
53
97
|
|
|
@@ -178,6 +222,7 @@ export type ThreadMessage = BaseThreadMessage &
|
|
|
178
222
|
export type CoreUserContentPart =
|
|
179
223
|
| TextContentPart
|
|
180
224
|
| ImageContentPart
|
|
225
|
+
| FileContentPart
|
|
181
226
|
| Unstable_AudioContentPart;
|
|
182
227
|
export type CoreAssistantContentPart =
|
|
183
228
|
| TextContentPart
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ComponentType } from "react";
|
|
2
2
|
import type {
|
|
3
3
|
ContentPartStatus,
|
|
4
|
+
FileContentPart,
|
|
4
5
|
ImageContentPart,
|
|
5
6
|
TextContentPart,
|
|
6
7
|
ToolCallContentPart,
|
|
@@ -20,6 +21,9 @@ export type TextContentPartComponent = ComponentType<TextContentPartProps>;
|
|
|
20
21
|
export type ImageContentPartProps = ContentPartState & ImageContentPart;
|
|
21
22
|
export type ImageContentPartComponent = ComponentType<ImageContentPartProps>;
|
|
22
23
|
|
|
24
|
+
export type FileContentPartProps = ContentPartState & FileContentPart;
|
|
25
|
+
export type FileContentPartComponent = ComponentType<FileContentPartProps>;
|
|
26
|
+
|
|
23
27
|
export type Unstable_AudioContentPartProps = ContentPartState &
|
|
24
28
|
Unstable_AudioContentPart;
|
|
25
29
|
export type Unstable_AudioContentPartComponent =
|
package/src/types/index.ts
CHANGED
|
@@ -9,6 +9,8 @@ export type {
|
|
|
9
9
|
AppendMessage,
|
|
10
10
|
TextContentPart,
|
|
11
11
|
ImageContentPart,
|
|
12
|
+
FileContentPart,
|
|
13
|
+
Unstable_AudioContentPart,
|
|
12
14
|
ToolCallContentPart,
|
|
13
15
|
UIContentPart,
|
|
14
16
|
MessageStatus,
|
|
@@ -28,9 +30,6 @@ export type {
|
|
|
28
30
|
CoreUserMessage,
|
|
29
31
|
CoreAssistantMessage,
|
|
30
32
|
CoreMessage,
|
|
31
|
-
|
|
32
|
-
// TODO
|
|
33
|
-
Unstable_AudioContentPart,
|
|
34
33
|
} from "./AssistantTypes";
|
|
35
34
|
|
|
36
35
|
export type {
|
|
@@ -40,12 +39,14 @@ export type {
|
|
|
40
39
|
TextContentPartComponent,
|
|
41
40
|
ImageContentPartProps,
|
|
42
41
|
ImageContentPartComponent,
|
|
42
|
+
FileContentPartProps,
|
|
43
|
+
FileContentPartComponent,
|
|
44
|
+
Unstable_AudioContentPartProps,
|
|
45
|
+
Unstable_AudioContentPartComponent,
|
|
43
46
|
UIContentPartProps,
|
|
44
47
|
UIContentPartComponent,
|
|
45
48
|
ToolCallContentPartProps,
|
|
46
49
|
ToolCallContentPartComponent,
|
|
47
|
-
Unstable_AudioContentPartProps,
|
|
48
|
-
Unstable_AudioContentPartComponent,
|
|
49
50
|
} from "./ContentPartComponentTypes";
|
|
50
51
|
|
|
51
52
|
export type {
|