@assistant-ui/react 0.7.0 → 0.7.2

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 (116) hide show
  1. package/dist/api/AssistantRuntime.d.ts +4 -34
  2. package/dist/api/AssistantRuntime.d.ts.map +1 -1
  3. package/dist/api/AssistantRuntime.js.map +1 -1
  4. package/dist/api/AssistantRuntime.mjs.map +1 -1
  5. package/dist/api/AttachmentRuntime.d.ts +4 -4
  6. package/dist/api/AttachmentRuntime.d.ts.map +1 -1
  7. package/dist/api/AttachmentRuntime.js.map +1 -1
  8. package/dist/api/AttachmentRuntime.mjs.map +1 -1
  9. package/dist/api/ComposerRuntime.d.ts +10 -10
  10. package/dist/api/ComposerRuntime.d.ts.map +1 -1
  11. package/dist/api/ComposerRuntime.js.map +1 -1
  12. package/dist/api/ComposerRuntime.mjs.map +1 -1
  13. package/dist/api/ContentPartRuntime.d.ts +2 -2
  14. package/dist/api/ContentPartRuntime.d.ts.map +1 -1
  15. package/dist/api/ContentPartRuntime.js.map +1 -1
  16. package/dist/api/ContentPartRuntime.mjs.map +1 -1
  17. package/dist/api/MessageRuntime.d.ts +7 -7
  18. package/dist/api/MessageRuntime.d.ts.map +1 -1
  19. package/dist/api/MessageRuntime.js +2 -2
  20. package/dist/api/MessageRuntime.js.map +1 -1
  21. package/dist/api/MessageRuntime.mjs +2 -2
  22. package/dist/api/MessageRuntime.mjs.map +1 -1
  23. package/dist/api/RuntimePathTypes.d.ts +33 -33
  24. package/dist/api/RuntimePathTypes.d.ts.map +1 -1
  25. package/dist/api/RuntimePathTypes.js.map +1 -1
  26. package/dist/api/ThreadListItemRuntime.d.ts +4 -4
  27. package/dist/api/ThreadListItemRuntime.d.ts.map +1 -1
  28. package/dist/api/ThreadListItemRuntime.js.map +1 -1
  29. package/dist/api/ThreadListItemRuntime.mjs.map +1 -1
  30. package/dist/api/ThreadListRuntime.d.ts +9 -9
  31. package/dist/api/ThreadListRuntime.d.ts.map +1 -1
  32. package/dist/api/ThreadListRuntime.js.map +1 -1
  33. package/dist/api/ThreadListRuntime.mjs.map +1 -1
  34. package/dist/api/ThreadRuntime.d.ts +45 -56
  35. package/dist/api/ThreadRuntime.d.ts.map +1 -1
  36. package/dist/api/ThreadRuntime.js.map +1 -1
  37. package/dist/api/ThreadRuntime.mjs.map +1 -1
  38. package/dist/api/index.d.ts +1 -0
  39. package/dist/api/index.d.ts.map +1 -1
  40. package/dist/api/index.js.map +1 -1
  41. package/dist/context/providers/ThreadListItemRuntimeProvider.d.ts +1 -1
  42. package/dist/context/providers/ThreadListItemRuntimeProvider.d.ts.map +1 -1
  43. package/dist/context/react/AssistantContext.d.ts +10 -48
  44. package/dist/context/react/AssistantContext.d.ts.map +1 -1
  45. package/dist/context/react/AttachmentContext.d.ts +16 -16
  46. package/dist/context/react/MessageContext.d.ts +6 -36
  47. package/dist/context/react/MessageContext.d.ts.map +1 -1
  48. package/dist/context/react/ThreadContext.d.ts +10 -138
  49. package/dist/context/react/ThreadContext.d.ts.map +1 -1
  50. package/dist/context/stores/AssistantToolUIs.d.ts +9 -6
  51. package/dist/context/stores/AssistantToolUIs.d.ts.map +1 -1
  52. package/dist/context/stores/AssistantToolUIs.js.map +1 -1
  53. package/dist/context/stores/AssistantToolUIs.mjs.map +1 -1
  54. package/dist/context/stores/MessageUtils.d.ts +7 -12
  55. package/dist/context/stores/MessageUtils.d.ts.map +1 -1
  56. package/dist/context/stores/MessageUtils.js.map +1 -1
  57. package/dist/context/stores/MessageUtils.mjs.map +1 -1
  58. package/dist/context/stores/ThreadViewport.d.ts +6 -10
  59. package/dist/context/stores/ThreadViewport.d.ts.map +1 -1
  60. package/dist/context/stores/ThreadViewport.js +0 -1
  61. package/dist/context/stores/ThreadViewport.js.map +1 -1
  62. package/dist/context/stores/ThreadViewport.mjs +0 -2
  63. package/dist/context/stores/ThreadViewport.mjs.map +1 -1
  64. package/dist/primitive-hooks/contentPart/useContentPartDisplay.d.ts +1 -1
  65. package/dist/primitive-hooks/contentPart/useContentPartImage.d.ts +1 -1
  66. package/dist/primitive-hooks/contentPart/useContentPartText.d.ts +1 -1
  67. package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts +2 -4
  68. package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts.map +1 -1
  69. package/dist/runtimes/core/ThreadRuntimeCore.d.ts +22 -22
  70. package/dist/runtimes/core/ThreadRuntimeCore.d.ts.map +1 -1
  71. package/dist/runtimes/core/ThreadRuntimeCore.js.map +1 -1
  72. package/dist/runtimes/edge/converters/fromCoreMessage.d.ts.map +1 -1
  73. package/dist/runtimes/edge/converters/fromCoreMessage.js +6 -3
  74. package/dist/runtimes/edge/converters/fromCoreMessage.js.map +1 -1
  75. package/dist/runtimes/edge/converters/fromCoreMessage.mjs +6 -3
  76. package/dist/runtimes/edge/converters/fromCoreMessage.mjs.map +1 -1
  77. package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts +3 -3
  78. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts +2 -11
  79. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
  80. package/dist/runtimes/external-store/ThreadMessageLike.d.ts +5 -1
  81. package/dist/runtimes/external-store/ThreadMessageLike.d.ts.map +1 -1
  82. package/dist/runtimes/external-store/ThreadMessageLike.js +18 -6
  83. package/dist/runtimes/external-store/ThreadMessageLike.js.map +1 -1
  84. package/dist/runtimes/external-store/ThreadMessageLike.mjs +18 -6
  85. package/dist/runtimes/external-store/ThreadMessageLike.mjs.map +1 -1
  86. package/dist/runtimes/local/ChatModelAdapter.d.ts +4 -4
  87. package/dist/runtimes/local/ChatModelAdapter.d.ts.map +1 -1
  88. package/dist/runtimes/local/ChatModelAdapter.js.map +1 -1
  89. package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts.map +1 -1
  90. package/dist/runtimes/local/LocalThreadRuntimeCore.js +1 -0
  91. package/dist/runtimes/local/LocalThreadRuntimeCore.js.map +1 -1
  92. package/dist/runtimes/local/LocalThreadRuntimeCore.mjs +1 -0
  93. package/dist/runtimes/local/LocalThreadRuntimeCore.mjs.map +1 -1
  94. package/dist/types/AssistantTypes.d.ts +13 -4
  95. package/dist/types/AssistantTypes.d.ts.map +1 -1
  96. package/dist/types/AssistantTypes.js.map +1 -1
  97. package/package.json +3 -3
  98. package/src/api/AssistantRuntime.ts +2 -2
  99. package/src/api/AttachmentRuntime.ts +4 -4
  100. package/src/api/ComposerRuntime.ts +10 -10
  101. package/src/api/ContentPartRuntime.ts +2 -2
  102. package/src/api/MessageRuntime.ts +9 -9
  103. package/src/api/RuntimePathTypes.ts +26 -26
  104. package/src/api/ThreadListItemRuntime.ts +4 -4
  105. package/src/api/ThreadListRuntime.ts +10 -10
  106. package/src/api/ThreadRuntime.ts +45 -14
  107. package/src/api/index.ts +4 -0
  108. package/src/context/stores/AssistantToolUIs.ts +9 -2
  109. package/src/context/stores/MessageUtils.ts +6 -6
  110. package/src/context/stores/ThreadViewport.tsx +5 -6
  111. package/src/runtimes/core/ThreadRuntimeCore.tsx +28 -29
  112. package/src/runtimes/edge/converters/fromCoreMessage.ts +4 -0
  113. package/src/runtimes/external-store/ThreadMessageLike.tsx +21 -4
  114. package/src/runtimes/local/ChatModelAdapter.tsx +4 -4
  115. package/src/runtimes/local/LocalThreadRuntimeCore.tsx +1 -0
  116. package/src/types/AssistantTypes.ts +13 -5
@@ -33,23 +33,23 @@ export type ComposerRuntimeCoreBinding = SubscribableWithState<
33
33
  >;
34
34
 
35
35
  type BaseComposerState = {
36
- text: string;
37
- role: MessageRole;
38
- attachments: readonly Attachment[];
36
+ readonly text: string;
37
+ readonly role: MessageRole;
38
+ readonly attachments: readonly Attachment[];
39
39
 
40
- canCancel: boolean;
41
- isEditing: boolean;
42
- isEmpty: boolean;
40
+ readonly canCancel: boolean;
41
+ readonly isEditing: boolean;
42
+ readonly isEmpty: boolean;
43
43
  };
44
44
 
45
45
  export type ThreadComposerState = BaseComposerState & {
46
- type: "thread";
46
+ readonly type: "thread";
47
47
 
48
- attachments: readonly PendingAttachment[];
48
+ readonly attachments: readonly PendingAttachment[];
49
49
  };
50
50
 
51
51
  export type EditComposerState = BaseComposerState & {
52
- type: "edit";
52
+ readonly type: "edit";
53
53
  };
54
54
 
55
55
  export type ComposerState = ThreadComposerState | EditComposerState;
@@ -90,7 +90,7 @@ const getEditComposerState = (
90
90
  };
91
91
 
92
92
  export type ComposerRuntime = {
93
- path: ComposerRuntimePath;
93
+ readonly path: ComposerRuntimePath;
94
94
  readonly type: "edit" | "thread";
95
95
  getState(): ComposerState;
96
96
 
@@ -14,7 +14,7 @@ export type ContentPartState = (
14
14
  | ThreadUserContentPart
15
15
  | ThreadAssistantContentPart
16
16
  ) & {
17
- status: ContentPartStatus | ToolCallContentPartStatus;
17
+ readonly status: ContentPartStatus | ToolCallContentPartStatus;
18
18
  };
19
19
 
20
20
  type ContentPartSnapshotBinding = SubscribableWithState<
@@ -23,7 +23,7 @@ type ContentPartSnapshotBinding = SubscribableWithState<
23
23
  >;
24
24
 
25
25
  export type ContentPartRuntime = {
26
- path: ContentPartRuntimePath;
26
+ readonly path: ContentPartRuntimePath;
27
27
 
28
28
  getState(): ContentPartState;
29
29
  addToolResult(result: any): void;
@@ -34,9 +34,9 @@ import { SKIP_UPDATE } from "./subscribable/SKIP_UPDATE";
34
34
  import { ShallowMemoizeSubject } from "./subscribable/ShallowMemoizeSubject";
35
35
  import { SubscribableWithState } from "./subscribable/Subscribable";
36
36
 
37
- const COMPLETE_STATUS: ContentPartStatus = {
37
+ const COMPLETE_STATUS: ContentPartStatus = Object.freeze({
38
38
  type: "complete",
39
- };
39
+ });
40
40
 
41
41
  export const toContentPartStatus = (
42
42
  message: ThreadMessage,
@@ -92,17 +92,17 @@ const getContentPartState = (
92
92
  };
93
93
 
94
94
  export type MessageState = ThreadMessage & {
95
- parentId: string | null;
96
- isLast: boolean;
95
+ readonly parentId: string | null;
96
+ readonly isLast: boolean;
97
97
 
98
- branchNumber: number;
99
- branchCount: number;
98
+ readonly branchNumber: number;
99
+ readonly branchCount: number;
100
100
 
101
101
  /**
102
102
  * @deprecated This API is still under active development and might change without notice.
103
103
  */
104
- speech: SpeechState | undefined;
105
- submittedFeedback: SubmittedFeedback | undefined;
104
+ readonly speech: SpeechState | undefined;
105
+ readonly submittedFeedback: SubmittedFeedback | undefined;
106
106
  };
107
107
 
108
108
  export type MessageStateBinding = SubscribableWithState<
@@ -169,7 +169,7 @@ export class MessageRuntimeImpl implements MessageRuntime {
169
169
  );
170
170
  }
171
171
 
172
- public composer;
172
+ public readonly composer;
173
173
 
174
174
  public getState() {
175
175
  return this._core.getState();
@@ -1,60 +1,60 @@
1
1
  export type ThreadListRuntimePath = {
2
- ref: string;
2
+ readonly ref: string;
3
3
  };
4
4
 
5
5
  export type ThreadListItemRuntimePath = {
6
- ref: string;
7
- threadSelector:
8
- | { type: "main" }
9
- | { type: "index"; index: number }
10
- | { type: "archiveIndex"; index: number }
11
- | { type: "threadId"; threadId: string };
6
+ readonly ref: string;
7
+ readonly threadSelector:
8
+ | { readonly type: "main" }
9
+ | { readonly type: "index"; readonly index: number }
10
+ | { readonly type: "archiveIndex"; readonly index: number }
11
+ | { readonly type: "threadId"; readonly threadId: string };
12
12
  };
13
13
 
14
14
  export type ThreadRuntimePath = {
15
- ref: string;
16
- threadSelector: { type: "main" };
15
+ readonly ref: string;
16
+ readonly threadSelector: { type: "main" };
17
17
  };
18
18
 
19
19
  export type MessageRuntimePath = ThreadRuntimePath & {
20
- messageSelector:
21
- | { type: "messageId"; messageId: string }
22
- | { type: "index"; index: number };
20
+ readonly messageSelector:
21
+ | { readonly type: "messageId"; readonly messageId: string }
22
+ | { readonly type: "index"; readonly index: number };
23
23
  };
24
24
 
25
25
  export type ContentPartRuntimePath = MessageRuntimePath & {
26
- contentPartSelector:
27
- | { type: "index"; index: number }
28
- | { type: "toolCallId"; toolCallId: string };
26
+ readonly contentPartSelector:
27
+ | { readonly type: "index"; readonly index: number }
28
+ | { readonly type: "toolCallId"; readonly toolCallId: string };
29
29
  };
30
30
 
31
31
  export type AttachmentRuntimePath = (
32
32
  | (MessageRuntimePath & {
33
- attachmentSource: "message" | "edit-composer";
33
+ readonly attachmentSource: "message" | "edit-composer";
34
34
  })
35
35
  | (ThreadRuntimePath & {
36
- attachmentSource: "thread-composer";
36
+ readonly attachmentSource: "thread-composer";
37
37
  })
38
38
  ) & {
39
- attachmentSelector:
39
+ readonly attachmentSelector:
40
40
  | {
41
- type: "index";
42
- index: number;
41
+ readonly type: "index";
42
+ readonly index: number;
43
43
  }
44
44
  | {
45
- type: "index";
46
- index: number;
45
+ readonly type: "index";
46
+ readonly index: number;
47
47
  }
48
48
  | {
49
- type: "index";
50
- index: number;
49
+ readonly type: "index";
50
+ readonly index: number;
51
51
  };
52
52
  };
53
53
 
54
54
  export type ComposerRuntimePath =
55
55
  | (ThreadRuntimePath & {
56
- composerSource: "thread";
56
+ readonly composerSource: "thread";
57
57
  })
58
58
  | (MessageRuntimePath & {
59
- composerSource: "edit";
59
+ readonly composerSource: "edit";
60
60
  });
@@ -5,11 +5,11 @@ import { SubscribableWithState } from "./subscribable/Subscribable";
5
5
  import { ThreadListRuntimeCoreBinding } from "./ThreadListRuntime";
6
6
 
7
7
  export type ThreadListItemState = ThreadMetadata & {
8
- isMain: boolean;
8
+ readonly isMain: boolean;
9
9
  };
10
10
 
11
- export type ThreadListItemRuntime = Readonly<{
12
- path: ThreadListItemRuntimePath;
11
+ export type ThreadListItemRuntime = {
12
+ readonly path: ThreadListItemRuntimePath;
13
13
  getState(): ThreadListItemState;
14
14
 
15
15
  switchTo(): Promise<void>;
@@ -19,7 +19,7 @@ export type ThreadListItemRuntime = Readonly<{
19
19
  delete(): Promise<void>;
20
20
 
21
21
  subscribe(callback: () => void): Unsubscribe;
22
- }>;
22
+ };
23
23
 
24
24
  export type ThreadListItemStateBinding = SubscribableWithState<
25
25
  ThreadListItemState,
@@ -10,15 +10,15 @@ import {
10
10
  import { SKIP_UPDATE } from "./subscribable/SKIP_UPDATE";
11
11
  import { ShallowMemoizeSubject } from "./subscribable/ShallowMemoizeSubject";
12
12
 
13
- export type ThreadListState = Readonly<{
14
- mainThreadId: string;
15
- newThread: string | undefined;
16
- threads: readonly string[];
17
- archivedThreads: readonly string[];
18
- }>;
19
-
20
- export type ThreadListRuntime = Readonly<{
21
- path: ThreadListRuntimePath;
13
+ export type ThreadListState = {
14
+ readonly mainThreadId: string;
15
+ readonly newThread: string | undefined;
16
+ readonly threads: readonly string[];
17
+ readonly archivedThreads: readonly string[];
18
+ };
19
+
20
+ export type ThreadListRuntime = {
21
+ readonly path: ThreadListRuntimePath;
22
22
  getState(): ThreadListState;
23
23
 
24
24
  subscribe(callback: () => void): Unsubscribe;
@@ -26,7 +26,7 @@ export type ThreadListRuntime = Readonly<{
26
26
  getThreadListItemById(threadId: string): ThreadListItemRuntime;
27
27
  getThreadListItemByIndex(idx: number): ThreadListItemRuntime;
28
28
  getThreadListArchivedItemByIndex(idx: number): ThreadListItemRuntime;
29
- }>;
29
+ };
30
30
 
31
31
  const getThreadListState = (
32
32
  threadList: ThreadListRuntimeCore,
@@ -74,53 +74,53 @@ export type ThreadRuntimeCoreBinding = SubscribableWithState<
74
74
  outerSubscribe(callback: () => void): Unsubscribe;
75
75
  };
76
76
 
77
- export type ThreadState = Readonly<{
77
+ export type ThreadState = {
78
78
  /**
79
79
  * The thread ID.
80
- * @deprecated This field is deprecated and will be removed in 0.7.0. Use `metadata.threadId` instead.
80
+ * @deprecated This field is deprecated and will be removed in 0.8.0. Use `metadata.threadId` instead.
81
81
  */
82
- threadId: string;
82
+ readonly threadId: string;
83
83
 
84
84
  /**
85
85
  * The thread metadata.
86
86
  */
87
- metadata: ThreadMetadata;
87
+ readonly metadata: ThreadMetadata;
88
88
 
89
89
  /**
90
90
  * Whether the thread is disabled. Disabled threads cannot receive new messages.
91
91
  */
92
- isDisabled: boolean;
92
+ readonly isDisabled: boolean;
93
93
 
94
94
  /**
95
95
  * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.
96
96
  */
97
- isRunning: boolean;
97
+ readonly isRunning: boolean;
98
98
 
99
99
  /**
100
100
  * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.
101
101
  */
102
- capabilities: RuntimeCapabilities;
102
+ readonly capabilities: RuntimeCapabilities;
103
103
 
104
104
  /**
105
105
  * The messages in the currently selected branch of the thread.
106
106
  */
107
- messages: readonly ThreadMessage[];
107
+ readonly messages: readonly ThreadMessage[];
108
108
 
109
109
  /**
110
110
  * Follow up message suggestions to show the user.
111
111
  */
112
- suggestions: readonly ThreadSuggestion[];
112
+ readonly suggestions: readonly ThreadSuggestion[];
113
113
 
114
114
  /**
115
115
  * Custom extra information provided by the runtime.
116
116
  */
117
- extras: unknown;
117
+ readonly extras: unknown;
118
118
 
119
119
  /**
120
120
  * @deprecated This API is still under active development and might change without notice.
121
121
  */
122
- speech: SpeechState | undefined;
123
- }>;
122
+ readonly speech: SpeechState | undefined;
123
+ };
124
124
 
125
125
  export const getThreadState = (runtime: ThreadRuntimeCore): ThreadState => {
126
126
  const lastMessage = runtime.messages.at(-1);
@@ -140,13 +140,44 @@ export const getThreadState = (runtime: ThreadRuntimeCore): ThreadState => {
140
140
  });
141
141
  };
142
142
 
143
- export type ThreadRuntime = Readonly<{
143
+ export type ThreadRuntime = {
144
+ /**
145
+ * The selector for the thread runtime.
146
+ */
144
147
  readonly path: ThreadRuntimePath;
145
148
 
149
+ /**
150
+ * The thread composer runtime.
151
+ */
146
152
  readonly composer: ThreadComposerRuntime;
153
+
154
+ /**
155
+ * Gets a snapshot of the thread state.
156
+ */
147
157
  getState(): ThreadState;
148
158
 
159
+ /**
160
+ * Append a new message to the thread.
161
+ *
162
+ * @example ```ts
163
+ * // append a new user message with the text "Hello, world!"
164
+ * threadRuntime.append("Hello, world!");
165
+ * ```
166
+ *
167
+ * @example ```ts
168
+ * // append a new assistant message with the text "Hello, world!"
169
+ * threadRuntime.append({
170
+ * role: "assistant",
171
+ * content: [{ type: "text", text: "Hello, world!" }],
172
+ * });
173
+ * ```
174
+ */
149
175
  append(message: CreateAppendMessage): void;
176
+
177
+ /**
178
+ *
179
+ * @param parentId
180
+ */
150
181
  startRun(parentId: string | null): void;
151
182
  subscribe(callback: () => void): Unsubscribe;
152
183
  cancelRun(): void;
@@ -162,7 +193,7 @@ export type ThreadRuntime = Readonly<{
162
193
  stopSpeaking: () => void;
163
194
 
164
195
  unstable_on(event: ThreadRuntimeEventType, callback: () => void): Unsubscribe;
165
- }>;
196
+ };
166
197
 
167
198
  export class ThreadRuntimeImpl implements ThreadRuntime {
168
199
  public get path() {
package/src/api/index.ts CHANGED
@@ -15,3 +15,7 @@ export type {
15
15
  } from "./ComposerRuntime";
16
16
  export type { AttachmentRuntime, AttachmentState } from "./AttachmentRuntime";
17
17
  export type { ThreadListRuntime, ThreadListState } from "./ThreadListRuntime";
18
+ export type {
19
+ ThreadListItemRuntime,
20
+ ThreadListItemState,
21
+ } from "./ThreadListItemRuntime";
@@ -4,13 +4,20 @@ import { create } from "zustand";
4
4
  import type { ToolCallContentPartComponent } from "../../types/ContentPartComponentTypes";
5
5
  import { Unsubscribe } from "../../types";
6
6
 
7
- export type AssistantToolUIsState = Readonly<{
7
+ export type AssistantToolUIsState = {
8
+ /**
9
+ * Get the tool UI configured for a given tool name.
10
+ */
8
11
  getToolUI: (toolName: string) => ToolCallContentPartComponent | null;
12
+
13
+ /**
14
+ * Registers a tool UI for a given tool name. Returns an unsubscribe function to remove the tool UI.
15
+ */
9
16
  setToolUI: (
10
17
  toolName: string,
11
18
  render: ToolCallContentPartComponent,
12
19
  ) => Unsubscribe;
13
- }>;
20
+ };
14
21
 
15
22
  export const makeAssistantToolUIsStore = () =>
16
23
  create<AssistantToolUIsState>((set) => {
@@ -1,12 +1,12 @@
1
1
  import { create } from "zustand";
2
2
 
3
- export type MessageUtilsState = Readonly<{
4
- isCopied: boolean;
5
- setIsCopied: (value: boolean) => void;
3
+ export type MessageUtilsState = {
4
+ readonly isCopied: boolean;
5
+ readonly setIsCopied: (value: boolean) => void;
6
6
 
7
- isHovering: boolean;
8
- setIsHovering: (value: boolean) => void;
9
- }>;
7
+ readonly isHovering: boolean;
8
+ readonly setIsHovering: (value: boolean) => void;
9
+ };
10
10
 
11
11
  export const makeMessageUtilsStore = () =>
12
12
  create<MessageUtilsState>((set) => {
@@ -1,12 +1,11 @@
1
- "use client";
2
1
  import { create } from "zustand";
3
2
  import type { Unsubscribe } from "../../types/Unsubscribe";
4
3
 
5
- export type ThreadViewportState = Readonly<{
6
- isAtBottom: boolean;
7
- scrollToBottom: () => void;
8
- onScrollToBottom: (callback: () => void) => Unsubscribe;
9
- }>;
4
+ export type ThreadViewportState = {
5
+ readonly isAtBottom: boolean;
6
+ readonly scrollToBottom: () => void;
7
+ readonly onScrollToBottom: (callback: () => void) => Unsubscribe;
8
+ };
10
9
 
11
10
  export const makeThreadViewportStore = () => {
12
11
  const scrollToBottomListeners = new Set<() => void>();
@@ -7,16 +7,16 @@ import {
7
7
  ThreadComposerRuntimeCore,
8
8
  } from "./ComposerRuntimeCore";
9
9
 
10
- export type RuntimeCapabilities = Readonly<{
11
- switchToBranch: boolean;
12
- edit: boolean;
13
- reload: boolean;
14
- cancel: boolean;
15
- unstable_copy: boolean;
16
- speech: boolean;
17
- attachments: boolean;
18
- feedback: boolean;
19
- }>;
10
+ export type RuntimeCapabilities = {
11
+ readonly switchToBranch: boolean;
12
+ readonly edit: boolean;
13
+ readonly reload: boolean;
14
+ readonly cancel: boolean;
15
+ readonly unstable_copy: boolean;
16
+ readonly speech: boolean;
17
+ readonly attachments: boolean;
18
+ readonly feedback: boolean;
19
+ };
20
20
 
21
21
  export type AddToolResultOptions = {
22
22
  messageId: string;
@@ -34,19 +34,19 @@ export type ThreadSuggestion = {
34
34
  prompt: string;
35
35
  };
36
36
 
37
- export type SpeechState = Readonly<{
38
- messageId: string;
39
- status: SpeechSynthesisAdapter.Status;
40
- }>;
37
+ export type SpeechState = {
38
+ readonly messageId: string;
39
+ readonly status: SpeechSynthesisAdapter.Status;
40
+ };
41
41
 
42
- export type SubmittedFeedback = Readonly<{
43
- type: "negative" | "positive";
44
- }>;
42
+ export type SubmittedFeedback = {
43
+ readonly type: "negative" | "positive";
44
+ };
45
45
 
46
46
  export type ThreadMetadata = Readonly<{
47
- threadId: string;
48
- state: "archived" | "regular" | "new" | "deleted";
49
- title?: string | undefined;
47
+ readonly threadId: string;
48
+ readonly state: "archived" | "regular" | "new" | "deleted";
49
+ readonly title?: string | undefined;
50
50
  }>;
51
51
 
52
52
  export type ThreadRuntimeEventType =
@@ -55,15 +55,14 @@ export type ThreadRuntimeEventType =
55
55
  | "run-start"
56
56
  | "model-config-update";
57
57
 
58
- export type ThreadMetadataRuntimeCore = ThreadMetadata &
59
- Readonly<{
60
- create(title?: string): Promise<void>;
61
- rename(newTitle: string): Promise<void>;
62
- archive(): Promise<void>;
63
- unarchive(): Promise<void>;
64
- delete(): Promise<void>;
65
- subscribe(callback: () => void): Unsubscribe;
66
- }>;
58
+ export type ThreadMetadataRuntimeCore = ThreadMetadata & {
59
+ create(title?: string): Promise<void>;
60
+ rename(newTitle: string): Promise<void>;
61
+ archive(): Promise<void>;
62
+ unarchive(): Promise<void>;
63
+ delete(): Promise<void>;
64
+ subscribe(callback: () => void): Unsubscribe;
65
+ };
67
66
 
68
67
  export type ThreadRuntimeCore = Readonly<{
69
68
  metadata: ThreadMetadataRuntimeCore;
@@ -42,6 +42,8 @@ export const fromCoreMessage = (
42
42
  return part;
43
43
  }),
44
44
  status,
45
+
46
+ metadata: { steps: [], custom: {} },
45
47
  } satisfies ThreadMessage;
46
48
 
47
49
  case "user":
@@ -50,6 +52,7 @@ export const fromCoreMessage = (
50
52
  role,
51
53
  content: message.content,
52
54
  attachments,
55
+ metadata: { custom: {} },
53
56
  } satisfies ThreadMessage;
54
57
 
55
58
  case "system":
@@ -57,6 +60,7 @@ export const fromCoreMessage = (
57
60
  ...commonProps,
58
61
  role,
59
62
  content: message.content,
63
+ metadata: { custom: {} },
60
64
  } satisfies ThreadMessage;
61
65
 
62
66
  default: {
@@ -14,6 +14,7 @@ import {
14
14
  } from "../../types";
15
15
  import {
16
16
  CoreToolCallContentPart,
17
+ ThreadStep,
17
18
  Unstable_AudioContentPart,
18
19
  } from "../../types/AssistantTypes";
19
20
 
@@ -33,7 +34,10 @@ export type ThreadMessageLike = {
33
34
  createdAt?: Date | undefined;
34
35
  status?: MessageStatus | undefined;
35
36
  attachments?: CompleteAttachment[] | undefined;
36
- // TODO metadata
37
+ metadata?: {
38
+ steps?: ThreadStep[] | undefined;
39
+ custom?: Record<string, unknown> | undefined;
40
+ };
37
41
  };
38
42
 
39
43
  export const fromThreadMessageLike = (
@@ -41,7 +45,7 @@ export const fromThreadMessageLike = (
41
45
  fallbackId: string,
42
46
  fallbackStatus: MessageStatus,
43
47
  ): ThreadMessage => {
44
- const { role, id, createdAt, attachments, status } = like;
48
+ const { role, id, createdAt, attachments, status, metadata } = like;
45
49
  const common = {
46
50
  id: id ?? fallbackId,
47
51
  createdAt: createdAt ?? new Date(),
@@ -53,10 +57,13 @@ export const fromThreadMessageLike = (
53
57
  : like.content;
54
58
 
55
59
  if (role !== "user" && attachments)
56
- throw new Error("Attachments are only supported for user messages");
60
+ throw new Error("attachments are only supported for user messages");
57
61
 
58
62
  if (role !== "assistant" && status)
59
- throw new Error("Status is only supported for assistant messages");
63
+ throw new Error("status is only supported for assistant messages");
64
+
65
+ if (role !== "assistant" && metadata?.steps)
66
+ throw new Error("metadata.steps is only supported for assistant messages");
60
67
 
61
68
  switch (role) {
62
69
  case "assistant":
@@ -90,6 +97,10 @@ export const fromThreadMessageLike = (
90
97
  })
91
98
  .filter((c) => !!c),
92
99
  status: status ?? fallbackStatus,
100
+ metadata: {
101
+ custom: metadata?.custom ?? {},
102
+ steps: metadata?.steps ?? [],
103
+ },
93
104
  } satisfies ThreadAssistantMessage;
94
105
 
95
106
  case "user":
@@ -112,6 +123,9 @@ export const fromThreadMessageLike = (
112
123
  }
113
124
  }),
114
125
  attachments: attachments ?? [],
126
+ metadata: {
127
+ custom: metadata?.custom ?? {},
128
+ },
115
129
  } satisfies ThreadUserMessage;
116
130
 
117
131
  case "system":
@@ -124,6 +138,9 @@ export const fromThreadMessageLike = (
124
138
  ...common,
125
139
  role,
126
140
  content: content as [TextContentPart],
141
+ metadata: {
142
+ custom: metadata?.custom ?? {},
143
+ },
127
144
  } satisfies ThreadSystemMessage;
128
145
 
129
146
  default: {
@@ -14,11 +14,11 @@ export type ChatModelRunUpdate = {
14
14
  };
15
15
 
16
16
  export type ChatModelRunResult = {
17
- content?: ThreadAssistantContentPart[];
18
- status?: MessageStatus;
17
+ content?: ThreadAssistantContentPart[] | undefined;
18
+ status?: MessageStatus | undefined;
19
19
  metadata?: {
20
- steps?: ThreadStep[];
21
- custom?: Record<string, unknown>;
20
+ steps?: ThreadStep[] | undefined;
21
+ custom?: Record<string, unknown> | undefined;
22
22
  };
23
23
  };
24
24
 
@@ -118,6 +118,7 @@ export class LocalThreadRuntimeCore
118
118
  role: "assistant",
119
119
  status: { type: "running" },
120
120
  content: [],
121
+ metadata: { steps: [], custom: {} },
121
122
  createdAt: new Date(),
122
123
  };
123
124