@assistant-ui/core 0.2.23 → 0.3.1
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/react/adapters/LocalStorageThreadListAdapter.js +2 -2
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/client/Tools.d.ts.map +1 -1
- package/dist/react/client/Tools.js +40 -55
- package/dist/react/client/Tools.js.map +1 -1
- package/dist/react/interactables-legacy/useAssistantInteractable.js +1 -1
- package/dist/react/interactables-legacy/useAssistantInteractable.js.map +1 -1
- package/dist/react/interactables-legacy/useInteractableState.js +3 -3
- package/dist/react/interactables-legacy/useInteractableState.js.map +1 -1
- package/dist/react/model-context/useAssistantContext.js +1 -1
- package/dist/react/model-context/useAssistantContext.js.map +1 -1
- package/dist/react/model-context/useAssistantDataUI.js +1 -1
- package/dist/react/model-context/useAssistantDataUI.js.map +1 -1
- package/dist/react/model-context/useAssistantInstructions.js +1 -1
- package/dist/react/model-context/useAssistantInstructions.js.map +1 -1
- package/dist/react/model-context/useAssistantTool.js +29 -25
- package/dist/react/model-context/useAssistantTool.js.map +1 -1
- package/dist/react/model-context/useAssistantToolUI.js +1 -1
- package/dist/react/model-context/useAssistantToolUI.js.map +1 -1
- package/dist/react/model-context/useAuiToolOverrides.js +1 -1
- package/dist/react/model-context/useAuiToolOverrides.js.map +1 -1
- package/dist/react/model-context/useInteractable.d.ts.map +1 -1
- package/dist/react/model-context/useInteractable.js +3 -5
- package/dist/react/model-context/useInteractable.js.map +1 -1
- package/dist/react/model-context/useInteractableState.js +2 -2
- package/dist/react/model-context/useInteractableState.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarCopy.js +3 -3
- package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarEdit.js +1 -1
- package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarFeedback.js +2 -2
- package/dist/react/primitive-hooks/useActionBarFeedback.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarReload.js +1 -1
- package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarSpeak.js +1 -1
- package/dist/react/primitive-hooks/useActionBarSpeak.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarStopSpeaking.js +1 -1
- package/dist/react/primitive-hooks/useActionBarStopSpeaking.js.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerNext.js +1 -1
- package/dist/react/primitive-hooks/useBranchPickerNext.js.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js +1 -1
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerAddAttachment.js +1 -1
- package/dist/react/primitive-hooks/useComposerAddAttachment.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerCancel.js +1 -1
- package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerDictate.js +1 -1
- package/dist/react/primitive-hooks/useComposerDictate.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerSend.js +1 -1
- package/dist/react/primitive-hooks/useComposerSend.js.map +1 -1
- package/dist/react/primitive-hooks/useEditComposerCancel.js +1 -1
- package/dist/react/primitive-hooks/useEditComposerCancel.js.map +1 -1
- package/dist/react/primitive-hooks/useEditComposerSend.js +1 -1
- package/dist/react/primitive-hooks/useEditComposerSend.js.map +1 -1
- package/dist/react/primitive-hooks/useMessageBranching.js +2 -2
- package/dist/react/primitive-hooks/useMessageBranching.js.map +1 -1
- package/dist/react/primitive-hooks/useMessageReload.js +1 -1
- package/dist/react/primitive-hooks/useMessageReload.js.map +1 -1
- package/dist/react/primitive-hooks/useSuggestionTrigger.js +7 -7
- package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemArchive.js +1 -1
- package/dist/react/primitive-hooks/useThreadListItemArchive.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemDelete.js +1 -1
- package/dist/react/primitive-hooks/useThreadListItemDelete.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemTrigger.js +1 -1
- package/dist/react/primitive-hooks/useThreadListItemTrigger.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemUnarchive.js +1 -1
- package/dist/react/primitive-hooks/useThreadListItemUnarchive.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.js +1 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListNew.js +1 -1
- package/dist/react/primitive-hooks/useThreadListNew.js.map +1 -1
- package/dist/react/primitive-hooks/useVoice.js +5 -13
- package/dist/react/primitive-hooks/useVoice.js.map +1 -1
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +1 -1
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js.map +1 -1
- package/dist/react/primitives/composer/ComposerAttachments.js +1 -1
- package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
- package/dist/react/primitives/composer/ComposerQueue.d.ts.map +1 -1
- package/dist/react/primitives/composer/ComposerQueue.js +1 -1
- package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
- package/dist/react/primitives/message/MessageAttachments.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageAttachments.js +1 -1
- package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.js +84 -122
- package/dist/react/primitives/message/MessageParts.js.map +1 -1
- package/dist/react/primitives/thread/ThreadMessages.js +1 -1
- package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
- package/dist/react/primitives/thread/ThreadSuggestions.js +1 -1
- package/dist/react/primitives/thread/ThreadSuggestions.js.map +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.js +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
- package/dist/react/providers/AttachmentByIndexProvider.js +2 -2
- package/dist/react/providers/AttachmentByIndexProvider.js.map +1 -1
- package/dist/react/providers/ChainOfThoughtByIndicesProvider.js +1 -1
- package/dist/react/providers/ChainOfThoughtByIndicesProvider.js.map +1 -1
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.d.ts.map +1 -1
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js +30 -18
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js.map +1 -1
- package/dist/react/providers/MessageByIdProvider.js +2 -2
- package/dist/react/providers/MessageByIdProvider.js.map +1 -1
- package/dist/react/providers/MessageByIndexProvider.js +2 -2
- package/dist/react/providers/MessageByIndexProvider.js.map +1 -1
- package/dist/react/providers/PartByIndexProvider.d.ts.map +1 -1
- package/dist/react/providers/PartByIndexProvider.js +30 -18
- package/dist/react/providers/PartByIndexProvider.js.map +1 -1
- package/dist/react/providers/QueueItemByIndexProvider.js +1 -1
- package/dist/react/providers/QueueItemByIndexProvider.js.map +1 -1
- package/dist/react/providers/ReadonlyThreadProvider.js +1 -1
- package/dist/react/providers/ReadonlyThreadProvider.js.map +1 -1
- package/dist/react/providers/SuggestionByIndexProvider.js +1 -1
- package/dist/react/providers/SuggestionByIndexProvider.js.map +1 -1
- package/dist/react/providers/ThreadListItemByIndexProvider.js +1 -1
- package/dist/react/providers/ThreadListItemByIndexProvider.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +3 -3
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +32 -20
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/createRuntimeExtras.js +1 -1
- package/dist/react/runtimes/createRuntimeExtras.js.map +1 -1
- package/dist/react/types/scopes/tools.d.ts +0 -6
- package/dist/react/types/scopes/tools.d.ts.map +1 -1
- package/dist/react/utils/groupParts.d.ts +1 -3
- package/dist/react/utils/groupParts.d.ts.map +1 -1
- package/dist/react/utils/groupParts.js +1 -3
- package/dist/react/utils/groupParts.js.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +4 -3
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/store/clients/runtime-adapter.js +3 -3
- package/dist/store/clients/runtime-adapter.js.map +1 -1
- package/package.json +5 -5
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +2 -2
- package/src/react/client/Tools.ts +0 -7
- package/src/react/interactables-legacy/useAssistantInteractable.ts +1 -1
- package/src/react/interactables-legacy/useInteractableState.ts +3 -3
- package/src/react/model-context/useAssistantContext.ts +1 -1
- package/src/react/model-context/useAssistantDataUI.ts +1 -1
- package/src/react/model-context/useAssistantInstructions.ts +1 -1
- package/src/react/model-context/useAssistantTool.ts +2 -2
- package/src/react/model-context/useAssistantToolUI.ts +1 -1
- package/src/react/model-context/useAuiToolOverrides.ts +1 -1
- package/src/react/model-context/useInteractable.ts +3 -7
- package/src/react/model-context/useInteractableState.ts +2 -2
- package/src/react/primitive-hooks/useActionBarCopy.test.ts +2 -2
- package/src/react/primitive-hooks/useActionBarCopy.ts +3 -3
- package/src/react/primitive-hooks/useActionBarEdit.ts +1 -1
- package/src/react/primitive-hooks/useActionBarFeedback.ts +2 -2
- package/src/react/primitive-hooks/useActionBarReload.ts +1 -1
- package/src/react/primitive-hooks/useActionBarSpeak.ts +1 -1
- package/src/react/primitive-hooks/useActionBarStopSpeaking.ts +1 -1
- package/src/react/primitive-hooks/useBranchPickerNext.ts +1 -1
- package/src/react/primitive-hooks/useBranchPickerPrevious.ts +1 -1
- package/src/react/primitive-hooks/useComposerAddAttachment.ts +1 -1
- package/src/react/primitive-hooks/useComposerCancel.ts +1 -1
- package/src/react/primitive-hooks/useComposerDictate.ts +1 -1
- package/src/react/primitive-hooks/useComposerSend.ts +1 -1
- package/src/react/primitive-hooks/useEditComposerCancel.ts +1 -1
- package/src/react/primitive-hooks/useEditComposerSend.ts +1 -1
- package/src/react/primitive-hooks/useMessageBranching.ts +2 -2
- package/src/react/primitive-hooks/useMessageReload.ts +1 -1
- package/src/react/primitive-hooks/useSuggestionTrigger.ts +9 -9
- package/src/react/primitive-hooks/useThreadListItemArchive.ts +1 -1
- package/src/react/primitive-hooks/useThreadListItemDelete.ts +1 -1
- package/src/react/primitive-hooks/useThreadListItemTrigger.ts +1 -1
- package/src/react/primitive-hooks/useThreadListItemUnarchive.ts +1 -1
- package/src/react/primitive-hooks/useThreadListLoadMore.ts +1 -1
- package/src/react/primitive-hooks/useThreadListNew.ts +1 -1
- package/src/react/primitive-hooks/useVoice.ts +5 -5
- package/src/react/primitives/chainOfThought/ChainOfThoughtParts.tsx +1 -1
- package/src/react/primitives/composer/ComposerAttachments.tsx +1 -1
- package/src/react/primitives/composer/ComposerQueue.tsx +1 -3
- package/src/react/primitives/message/MessageAttachments.tsx +1 -3
- package/src/react/primitives/message/MessageParts.tsx +9 -9
- package/src/react/primitives/thread/ThreadMessages.tsx +1 -1
- package/src/react/primitives/thread/ThreadSuggestions.tsx +1 -1
- package/src/react/primitives/threadList/ThreadListItems.tsx +1 -1
- package/src/react/providers/AttachmentByIndexProvider.tsx +2 -2
- package/src/react/providers/ChainOfThoughtByIndicesProvider.tsx +1 -1
- package/src/react/providers/ChainOfThoughtPartByIndexProvider.tsx +2 -19
- package/src/react/providers/MessageByIdProvider.tsx +2 -2
- package/src/react/providers/MessageByIndexProvider.tsx +2 -2
- package/src/react/providers/PartByIndexProvider.tsx +2 -16
- package/src/react/providers/QueueItemByIndexProvider.tsx +1 -1
- package/src/react/providers/ReadonlyThreadProvider.tsx +1 -1
- package/src/react/providers/SuggestionByIndexProvider.tsx +1 -1
- package/src/react/providers/ThreadListItemByIndexProvider.tsx +1 -1
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +3 -3
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +32 -7
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +26 -16
- package/src/react/runtimes/createRuntimeExtras.test.ts +1 -1
- package/src/react/runtimes/createRuntimeExtras.ts +1 -1
- package/src/react/types/scopes/tools.ts +0 -6
- package/src/react/utils/groupParts.ts +1 -7
- package/src/runtimes/local/local-thread-runtime-core.test.ts +38 -0
- package/src/runtimes/local/local-thread-runtime-core.ts +6 -3
- package/src/store/clients/runtime-adapter.ts +3 -3
- package/src/tests/groupParts.test.ts +3 -48
|
@@ -7,11 +7,11 @@ export const useMessageBranching = () => {
|
|
|
7
7
|
const branchCount = useAuiState((s) => s.message.branchCount);
|
|
8
8
|
|
|
9
9
|
const goToPrev = useCallback(() => {
|
|
10
|
-
aui.message
|
|
10
|
+
aui.message.switchToBranch({ position: "previous" });
|
|
11
11
|
}, [aui]);
|
|
12
12
|
|
|
13
13
|
const goToNext = useCallback(() => {
|
|
14
|
-
aui.message
|
|
14
|
+
aui.message.switchToBranch({ position: "next" });
|
|
15
15
|
}, [aui]);
|
|
16
16
|
|
|
17
17
|
return { branchNumber, branchCount, goToPrev, goToNext };
|
|
@@ -17,24 +17,24 @@ export const useSuggestionTrigger = ({
|
|
|
17
17
|
const resolvedSend = send ?? false;
|
|
18
18
|
|
|
19
19
|
const trigger = useCallback(() => {
|
|
20
|
-
const isRunning = aui.thread
|
|
20
|
+
const isRunning = aui.thread.getState().isRunning;
|
|
21
21
|
|
|
22
22
|
if (resolvedSend && !isRunning) {
|
|
23
|
-
aui.thread
|
|
23
|
+
aui.thread.append({
|
|
24
24
|
content: [{ type: "text", text: prompt }],
|
|
25
|
-
runConfig: aui.composer
|
|
25
|
+
runConfig: aui.composer.getState().runConfig,
|
|
26
26
|
});
|
|
27
27
|
if (clearComposer) {
|
|
28
|
-
aui.composer
|
|
28
|
+
aui.composer.setText("");
|
|
29
29
|
}
|
|
30
30
|
} else {
|
|
31
31
|
if (clearComposer) {
|
|
32
|
-
aui.composer
|
|
32
|
+
aui.composer.setText(prompt);
|
|
33
33
|
} else {
|
|
34
|
-
const currentText = aui.composer
|
|
35
|
-
aui
|
|
36
|
-
.
|
|
37
|
-
|
|
34
|
+
const currentText = aui.composer.getState().text;
|
|
35
|
+
aui.composer.setText(
|
|
36
|
+
currentText.trim() ? `${currentText} ${prompt}` : prompt,
|
|
37
|
+
);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
}, [aui, resolvedSend, clearComposer, prompt]);
|
|
@@ -10,7 +10,7 @@ const getServerVolume = () => 0;
|
|
|
10
10
|
|
|
11
11
|
export const useVoiceVolume = (): number => {
|
|
12
12
|
const aui = useAui();
|
|
13
|
-
const thread = aui.thread
|
|
13
|
+
const thread = aui.thread;
|
|
14
14
|
return useSyncExternalStore(
|
|
15
15
|
thread.subscribeVoiceVolume,
|
|
16
16
|
thread.getVoiceVolume,
|
|
@@ -22,19 +22,19 @@ export const useVoiceControls = () => {
|
|
|
22
22
|
const aui = useAui();
|
|
23
23
|
|
|
24
24
|
const connect = useCallback(() => {
|
|
25
|
-
aui.thread
|
|
25
|
+
aui.thread.connectVoice();
|
|
26
26
|
}, [aui]);
|
|
27
27
|
|
|
28
28
|
const disconnect = useCallback(() => {
|
|
29
|
-
aui.thread
|
|
29
|
+
aui.thread.disconnectVoice();
|
|
30
30
|
}, [aui]);
|
|
31
31
|
|
|
32
32
|
const mute = useCallback(() => {
|
|
33
|
-
aui.thread
|
|
33
|
+
aui.thread.muteVoice();
|
|
34
34
|
}, [aui]);
|
|
35
35
|
|
|
36
36
|
const unmute = useCallback(() => {
|
|
37
|
-
aui.thread
|
|
37
|
+
aui.thread.unmuteVoice();
|
|
38
38
|
}, [aui]);
|
|
39
39
|
|
|
40
40
|
return { connect, disconnect, mute, unmute };
|
|
@@ -51,7 +51,7 @@ const ChainOfThoughtPrimitivePartsInner: FC<{
|
|
|
51
51
|
Array.from({ length: partsLength }, (_, index) => (
|
|
52
52
|
<ChainOfThoughtPartByIndexProvider key={index} index={index}>
|
|
53
53
|
<RenderChildrenWithAccessor
|
|
54
|
-
getItemState={(aui) => aui.part
|
|
54
|
+
getItemState={(aui) => aui.part.getState()}
|
|
55
55
|
>
|
|
56
56
|
{(getItem) =>
|
|
57
57
|
children({
|
|
@@ -99,7 +99,7 @@ const ComposerPrimitiveAttachmentsInner: FC<{
|
|
|
99
99
|
<ComposerAttachmentByIndexProvider key={index} index={index}>
|
|
100
100
|
<RenderChildrenWithAccessor
|
|
101
101
|
getItemState={(aui) =>
|
|
102
|
-
aui.composer
|
|
102
|
+
aui.composer.attachment({ index }).getState()
|
|
103
103
|
}
|
|
104
104
|
>
|
|
105
105
|
{(getItem) =>
|
|
@@ -20,9 +20,7 @@ const ComposerPrimitiveQueueInner: FC<{
|
|
|
20
20
|
Array.from({ length: queue }, (_, index) => (
|
|
21
21
|
<QueueItemByIndexProvider key={index} index={index}>
|
|
22
22
|
<RenderChildrenWithAccessor
|
|
23
|
-
getItemState={(aui) =>
|
|
24
|
-
aui.composer().queueItem({ index }).getState()
|
|
25
|
-
}
|
|
23
|
+
getItemState={(aui) => aui.composer.queueItem({ index }).getState()}
|
|
26
24
|
>
|
|
27
25
|
{(getItem) =>
|
|
28
26
|
children({
|
|
@@ -101,9 +101,7 @@ const MessagePrimitiveAttachmentsInner: FC<{
|
|
|
101
101
|
Array.from({ length: attachmentsCount }, (_, index) => (
|
|
102
102
|
<MessageAttachmentByIndexProvider key={index} index={index}>
|
|
103
103
|
<RenderChildrenWithAccessor
|
|
104
|
-
getItemState={(aui) =>
|
|
105
|
-
aui.message().attachment({ index }).getState()
|
|
106
|
-
}
|
|
104
|
+
getItemState={(aui) => aui.message.attachment({ index }).getState()}
|
|
107
105
|
>
|
|
108
106
|
{(getItem) =>
|
|
109
107
|
children({
|
|
@@ -415,9 +415,9 @@ export const MessagePartComponent: FC<MessagePartComponentProps> = ({
|
|
|
415
415
|
|
|
416
416
|
const type = part.type;
|
|
417
417
|
if (type === "tool-call") {
|
|
418
|
-
const addResult = aui.part
|
|
419
|
-
const resume = aui.part
|
|
420
|
-
const respondToApproval = aui.part
|
|
418
|
+
const addResult = aui.part.addToolResult;
|
|
419
|
+
const resume = aui.part.resumeToolCall;
|
|
420
|
+
const respondToApproval = aui.part.respondToToolApproval;
|
|
421
421
|
if ("Override" in tools)
|
|
422
422
|
return (
|
|
423
423
|
<tools.Override
|
|
@@ -636,9 +636,9 @@ const RegisteredToolUI: FC = () => {
|
|
|
636
636
|
return (
|
|
637
637
|
<Render
|
|
638
638
|
{...part}
|
|
639
|
-
addResult={aui.part
|
|
640
|
-
resume={aui.part
|
|
641
|
-
respondToApproval={aui.part
|
|
639
|
+
addResult={aui.part.addToolResult}
|
|
640
|
+
resume={aui.part.resumeToolCall}
|
|
641
|
+
respondToApproval={aui.part.respondToToolApproval}
|
|
642
642
|
/>
|
|
643
643
|
);
|
|
644
644
|
};
|
|
@@ -743,16 +743,16 @@ const MessagePartChildrenInner: FC<
|
|
|
743
743
|
|
|
744
744
|
return (
|
|
745
745
|
<RenderChildrenWithAccessor
|
|
746
|
-
getItemState={(client) => client.part
|
|
746
|
+
getItemState={(client) => client.part.getState()}
|
|
747
747
|
>
|
|
748
748
|
{(getItem) =>
|
|
749
749
|
children({
|
|
750
750
|
get part() {
|
|
751
751
|
const state = getItem();
|
|
752
752
|
if (state.type === "tool-call") {
|
|
753
|
-
const toolsState = aui.tools
|
|
753
|
+
const toolsState = aui.tools.getState();
|
|
754
754
|
const hasUI = resolveToolRender(toolsState, state) !== null;
|
|
755
|
-
const partMethods = aui.part
|
|
755
|
+
const partMethods = aui.part;
|
|
756
756
|
return {
|
|
757
757
|
...state,
|
|
758
758
|
toolUI: hasUI ? <RegisteredToolUI /> : null,
|
|
@@ -247,7 +247,7 @@ const ThreadPrimitiveMessagesInner: FC<{
|
|
|
247
247
|
return Array.from({ length: messagesLength }, (_, index) => (
|
|
248
248
|
<MessageByIndexProvider key={index} index={index}>
|
|
249
249
|
<RenderChildrenWithAccessor
|
|
250
|
-
getItemState={(aui) => aui.thread
|
|
250
|
+
getItemState={(aui) => aui.thread.message({ index }).getState()}
|
|
251
251
|
>
|
|
252
252
|
{(getItem) =>
|
|
253
253
|
children({
|
|
@@ -77,7 +77,7 @@ const ThreadPrimitiveSuggestionsInner: FC<{
|
|
|
77
77
|
<SuggestionByIndexProvider key={index} index={index}>
|
|
78
78
|
<RenderChildrenWithAccessor
|
|
79
79
|
getItemState={(aui) =>
|
|
80
|
-
aui.suggestions
|
|
80
|
+
aui.suggestions.suggestion({ index }).getState()
|
|
81
81
|
}
|
|
82
82
|
>
|
|
83
83
|
{(getItem) =>
|
|
@@ -10,7 +10,7 @@ export const MessageAttachmentByIndexProvider: FC<
|
|
|
10
10
|
attachment: Derived({
|
|
11
11
|
source: "message",
|
|
12
12
|
query: { type: "index", index },
|
|
13
|
-
get: (aui) => aui.message
|
|
13
|
+
get: (aui) => aui.message.attachment({ index }),
|
|
14
14
|
}),
|
|
15
15
|
});
|
|
16
16
|
|
|
@@ -26,7 +26,7 @@ export const ComposerAttachmentByIndexProvider: FC<
|
|
|
26
26
|
attachment: Derived({
|
|
27
27
|
source: "composer",
|
|
28
28
|
query: { type: "index", index },
|
|
29
|
-
get: (aui) => aui.composer
|
|
29
|
+
get: (aui) => aui.composer.attachment({ index }),
|
|
30
30
|
}),
|
|
31
31
|
});
|
|
32
32
|
|
|
@@ -25,7 +25,7 @@ export const ChainOfThoughtByIndicesProvider: FC<
|
|
|
25
25
|
`ChainOfThought part index ${index} is out of bounds (0..${parts.length - 1})`,
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
|
-
return parentAui.message
|
|
28
|
+
return parentAui.message.part({ index: startIndex + index });
|
|
29
29
|
},
|
|
30
30
|
}),
|
|
31
31
|
});
|
|
@@ -1,33 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FC, PropsWithChildren } from "react";
|
|
2
2
|
import { useAui, AuiProvider, Derived } from "@assistant-ui/store";
|
|
3
|
-
import type { PartMethods } from "../../store/scopes/part";
|
|
4
3
|
|
|
5
4
|
export const ChainOfThoughtPartByIndexProvider: FC<
|
|
6
5
|
PropsWithChildren<{
|
|
7
6
|
index: number;
|
|
8
7
|
}>
|
|
9
8
|
> = ({ index, children }) => {
|
|
10
|
-
const lastPartRef = useMemo(
|
|
11
|
-
() => ({ index, current: null as PartMethods | null }),
|
|
12
|
-
[index],
|
|
13
|
-
);
|
|
14
9
|
const aui = useAui({
|
|
15
10
|
part: Derived({
|
|
16
11
|
source: "chainOfThought",
|
|
17
12
|
query: { type: "index", index },
|
|
18
|
-
get: (aui) => {
|
|
19
|
-
const chainOfThought = aui.chainOfThought();
|
|
20
|
-
if (
|
|
21
|
-
index >= chainOfThought.getState().parts.length &&
|
|
22
|
-
lastPartRef.current
|
|
23
|
-
) {
|
|
24
|
-
return lastPartRef.current;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const part = chainOfThought.part({ index });
|
|
28
|
-
lastPartRef.current = part;
|
|
29
|
-
return part;
|
|
30
|
-
},
|
|
13
|
+
get: (aui) => aui.chainOfThought.part({ index }),
|
|
31
14
|
}),
|
|
32
15
|
});
|
|
33
16
|
|
|
@@ -10,12 +10,12 @@ export const MessageByIdProvider: FC<
|
|
|
10
10
|
message: Derived({
|
|
11
11
|
source: "thread",
|
|
12
12
|
query: { type: "id", id },
|
|
13
|
-
get: (aui) => aui.thread
|
|
13
|
+
get: (aui) => aui.thread.message({ id }),
|
|
14
14
|
}),
|
|
15
15
|
composer: Derived({
|
|
16
16
|
source: "message",
|
|
17
17
|
query: {},
|
|
18
|
-
get: (aui) => aui.thread
|
|
18
|
+
get: (aui) => aui.thread.message({ id }).composer(),
|
|
19
19
|
}),
|
|
20
20
|
});
|
|
21
21
|
|
|
@@ -10,12 +10,12 @@ export const MessageByIndexProvider: FC<
|
|
|
10
10
|
message: Derived({
|
|
11
11
|
source: "thread",
|
|
12
12
|
query: { type: "index", index },
|
|
13
|
-
get: (aui) => aui.thread
|
|
13
|
+
get: (aui) => aui.thread.message({ index }),
|
|
14
14
|
}),
|
|
15
15
|
composer: Derived({
|
|
16
16
|
source: "message",
|
|
17
17
|
query: {},
|
|
18
|
-
get: (aui) => aui.thread
|
|
18
|
+
get: (aui) => aui.thread.message({ index }).composer(),
|
|
19
19
|
}),
|
|
20
20
|
});
|
|
21
21
|
|
|
@@ -1,30 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FC, PropsWithChildren } from "react";
|
|
2
2
|
import { useAui, AuiProvider, Derived } from "@assistant-ui/store";
|
|
3
|
-
import type { PartMethods } from "../../store/scopes/part";
|
|
4
3
|
|
|
5
4
|
export const PartByIndexProvider: FC<
|
|
6
5
|
PropsWithChildren<{
|
|
7
6
|
index: number;
|
|
8
7
|
}>
|
|
9
8
|
> = ({ index, children }) => {
|
|
10
|
-
const lastPartRef = useMemo(
|
|
11
|
-
() => ({ index, current: null as PartMethods | null }),
|
|
12
|
-
[index],
|
|
13
|
-
);
|
|
14
9
|
const aui = useAui({
|
|
15
10
|
part: Derived({
|
|
16
11
|
source: "message",
|
|
17
12
|
query: { type: "index", index },
|
|
18
|
-
get: (aui) => {
|
|
19
|
-
const message = aui.message();
|
|
20
|
-
if (index >= message.getState().parts.length && lastPartRef.current) {
|
|
21
|
-
return lastPartRef.current;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const part = message.part({ index });
|
|
25
|
-
lastPartRef.current = part;
|
|
26
|
-
return part;
|
|
27
|
-
},
|
|
13
|
+
get: (aui) => aui.message.part({ index }),
|
|
28
14
|
}),
|
|
29
15
|
});
|
|
30
16
|
|
|
@@ -13,7 +13,7 @@ export const QueueItemByIndexProvider: FC<QueueItemByIndexProviderProps> = ({
|
|
|
13
13
|
queueItem: Derived({
|
|
14
14
|
source: "composer",
|
|
15
15
|
query: { index },
|
|
16
|
-
get: (aui) => aui.composer
|
|
16
|
+
get: (aui) => aui.composer.queueItem({ index }),
|
|
17
17
|
}),
|
|
18
18
|
});
|
|
19
19
|
|
|
@@ -13,7 +13,7 @@ export const SuggestionByIndexProvider: FC<SuggestionByIndexProviderProps> = ({
|
|
|
13
13
|
suggestion: Derived({
|
|
14
14
|
source: "suggestions",
|
|
15
15
|
query: { index },
|
|
16
|
-
get: (aui) => aui.suggestions
|
|
16
|
+
get: (aui) => aui.suggestions.suggestion({ index }),
|
|
17
17
|
}),
|
|
18
18
|
});
|
|
19
19
|
|
|
@@ -11,7 +11,7 @@ export const ThreadListItemByIndexProvider: FC<
|
|
|
11
11
|
threadListItem: Derived({
|
|
12
12
|
source: "threads",
|
|
13
13
|
query: { type: "index", index, archived },
|
|
14
|
-
get: (aui) => aui.threads
|
|
14
|
+
get: (aui) => aui.threads.item({ index, archived }),
|
|
15
15
|
}),
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -147,15 +147,15 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
|
147
147
|
return runtime.threads.main.unstable_on("initialize", () => {
|
|
148
148
|
if (hasInitializedRef.current) return;
|
|
149
149
|
|
|
150
|
-
const state = aui.threadListItem
|
|
150
|
+
const state = aui.threadListItem.getState();
|
|
151
151
|
if (state.status !== "new") return;
|
|
152
152
|
hasInitializedRef.current = true;
|
|
153
153
|
|
|
154
|
-
initPromiseRef.current = aui.threadListItem
|
|
154
|
+
initPromiseRef.current = aui.threadListItem.initialize();
|
|
155
155
|
|
|
156
156
|
const dispose = runtime.thread.unstable_on("runEnd", () => {
|
|
157
157
|
dispose();
|
|
158
|
-
aui.threadListItem
|
|
158
|
+
aui.threadListItem.generateTitle();
|
|
159
159
|
});
|
|
160
160
|
});
|
|
161
161
|
}, [runtime, aui]);
|
|
@@ -6,20 +6,22 @@ import { describe, expect, it, vi } from "vitest";
|
|
|
6
6
|
import { useAssistantCloudThreadHistoryAdapter } from "./AssistantCloudThreadHistoryAdapter";
|
|
7
7
|
|
|
8
8
|
const mocks = vi.hoisted(() => {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const makeClient = (remoteId: string) =>
|
|
10
|
+
({
|
|
11
|
+
threadListItem: {
|
|
12
|
+
getState: () => ({ remoteId }),
|
|
13
|
+
},
|
|
14
|
+
}) as unknown as import("@assistant-ui/store").AssistantClient;
|
|
12
15
|
|
|
13
16
|
return {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
+
makeClient,
|
|
18
|
+
aui: makeClient("thread-1"),
|
|
17
19
|
};
|
|
18
20
|
});
|
|
19
21
|
|
|
20
22
|
vi.mock("@assistant-ui/store", async (importOriginal) => ({
|
|
21
23
|
...(await importOriginal<typeof import("@assistant-ui/store")>()),
|
|
22
|
-
useAui: () => mocks.
|
|
24
|
+
useAui: () => mocks.aui,
|
|
23
25
|
}));
|
|
24
26
|
|
|
25
27
|
const makeCloud = () =>
|
|
@@ -33,6 +35,7 @@ const makeCloud = () =>
|
|
|
33
35
|
|
|
34
36
|
describe("useAssistantCloudThreadHistoryAdapter", () => {
|
|
35
37
|
it("refreshes formatted persistence when the Cloud client changes", async () => {
|
|
38
|
+
mocks.aui = mocks.makeClient("thread-1");
|
|
36
39
|
const firstCloud = makeCloud();
|
|
37
40
|
const secondCloud = makeCloud();
|
|
38
41
|
const cloudRef = { current: firstCloud };
|
|
@@ -66,4 +69,26 @@ describe("useAssistantCloudThreadHistoryAdapter", () => {
|
|
|
66
69
|
format: "test",
|
|
67
70
|
});
|
|
68
71
|
});
|
|
72
|
+
|
|
73
|
+
it("resolves the aui client at call time instead of capturing it", async () => {
|
|
74
|
+
mocks.aui = mocks.makeClient("thread-1");
|
|
75
|
+
const cloud = makeCloud();
|
|
76
|
+
const cloudRef = { current: cloud };
|
|
77
|
+
const { result, rerender } = renderHook(() =>
|
|
78
|
+
useAssistantCloudThreadHistoryAdapter(cloudRef),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
await result.current.load();
|
|
82
|
+
expect(cloud.threads.messages.list).toHaveBeenCalledWith("thread-1", {
|
|
83
|
+
format: "aui/v0",
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
mocks.aui = mocks.makeClient("thread-2");
|
|
87
|
+
rerender();
|
|
88
|
+
|
|
89
|
+
await result.current.load();
|
|
90
|
+
expect(cloud.threads.messages.list).toHaveBeenCalledWith("thread-2", {
|
|
91
|
+
format: "aui/v0",
|
|
92
|
+
});
|
|
93
|
+
});
|
|
69
94
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type RefObject, useState } from "react";
|
|
1
|
+
import { type RefObject, useEffect, useRef, useState } from "react";
|
|
2
2
|
import type {
|
|
3
3
|
GenericThreadHistoryAdapter,
|
|
4
4
|
ThreadHistoryAdapter,
|
|
@@ -13,25 +13,31 @@ import {
|
|
|
13
13
|
createFormattedPersistence,
|
|
14
14
|
} from "assistant-cloud";
|
|
15
15
|
import { auiV0Decode, auiV0Encode } from "./auiV0";
|
|
16
|
-
import { type AssistantClient, useAui } from "@assistant-ui/store";
|
|
17
|
-
import type { ThreadListItemMethods } from "../../../store/scopes/thread-list-item";
|
|
16
|
+
import { type AssistantClient, getClientId, useAui } from "@assistant-ui/store";
|
|
18
17
|
|
|
19
18
|
const globalPersistence = new WeakMap<
|
|
20
|
-
|
|
19
|
+
getClientId.ClientId,
|
|
21
20
|
CloudMessagePersistence
|
|
22
21
|
>();
|
|
23
22
|
|
|
24
23
|
class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
|
|
25
24
|
private cloudRef: RefObject<AssistantCloud>;
|
|
26
|
-
private
|
|
25
|
+
private auiRef: RefObject<AssistantClient>;
|
|
27
26
|
|
|
28
|
-
constructor(
|
|
27
|
+
constructor(
|
|
28
|
+
cloudRef: RefObject<AssistantCloud>,
|
|
29
|
+
auiRef: RefObject<AssistantClient>,
|
|
30
|
+
) {
|
|
29
31
|
this.cloudRef = cloudRef;
|
|
30
|
-
this.
|
|
32
|
+
this.auiRef = auiRef;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private get aui(): AssistantClient {
|
|
36
|
+
return this.auiRef.current;
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
private get _persistence(): CloudMessagePersistence {
|
|
34
|
-
const key = this.aui.threadListItem
|
|
40
|
+
const key = getClientId(this.aui.threadListItem);
|
|
35
41
|
if (!globalPersistence.has(key)) {
|
|
36
42
|
globalPersistence.set(
|
|
37
43
|
key,
|
|
@@ -52,11 +58,11 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
|
|
|
52
58
|
return {
|
|
53
59
|
// Note: callers must also call reportTelemetry() for run tracking
|
|
54
60
|
async append(item: MessageFormatItem<TMessage>) {
|
|
55
|
-
const { remoteId } = await adapter.aui.threadListItem
|
|
61
|
+
const { remoteId } = await adapter.aui.threadListItem.initialize();
|
|
56
62
|
await formatted.append(remoteId, item);
|
|
57
63
|
},
|
|
58
64
|
async update(item: MessageFormatItem<TMessage>, localMessageId: string) {
|
|
59
|
-
const remoteId = adapter.aui.threadListItem
|
|
65
|
+
const remoteId = adapter.aui.threadListItem.getState().remoteId;
|
|
60
66
|
if (!remoteId) return;
|
|
61
67
|
await formatted.update?.(remoteId, item, localMessageId);
|
|
62
68
|
},
|
|
@@ -82,7 +88,7 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
|
|
|
82
88
|
);
|
|
83
89
|
},
|
|
84
90
|
async load(): Promise<MessageFormatRepository<TMessage>> {
|
|
85
|
-
const remoteId = adapter.aui.threadListItem
|
|
91
|
+
const remoteId = adapter.aui.threadListItem.getState().remoteId;
|
|
86
92
|
if (!remoteId) return { messages: [] };
|
|
87
93
|
return formatted.load(remoteId);
|
|
88
94
|
},
|
|
@@ -90,7 +96,7 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
|
|
|
90
96
|
}
|
|
91
97
|
|
|
92
98
|
async append({ parentId, message }: ExportedMessageRepositoryItem) {
|
|
93
|
-
const { remoteId } = await this.aui.threadListItem
|
|
99
|
+
const { remoteId } = await this.aui.threadListItem.initialize();
|
|
94
100
|
const encoded = auiV0Encode(message);
|
|
95
101
|
await this._persistence.append(
|
|
96
102
|
remoteId,
|
|
@@ -110,7 +116,7 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
|
|
|
110
116
|
return this.append(item);
|
|
111
117
|
}
|
|
112
118
|
const { message } = item;
|
|
113
|
-
const remoteId = this.aui.threadListItem
|
|
119
|
+
const remoteId = this.aui.threadListItem.getState().remoteId;
|
|
114
120
|
if (!remoteId) return;
|
|
115
121
|
const encoded = auiV0Encode(message);
|
|
116
122
|
await this._persistence.update(remoteId, message.id, "aui/v0", encoded);
|
|
@@ -127,7 +133,7 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
|
|
|
127
133
|
}
|
|
128
134
|
|
|
129
135
|
async load() {
|
|
130
|
-
const remoteId = this.aui.threadListItem
|
|
136
|
+
const remoteId = this.aui.threadListItem.getState().remoteId;
|
|
131
137
|
if (!remoteId) return { messages: [] };
|
|
132
138
|
const messages = await this._persistence.load(remoteId, "aui/v0");
|
|
133
139
|
return {
|
|
@@ -150,7 +156,7 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
|
|
|
150
156
|
) {
|
|
151
157
|
if (!this.cloudRef.current.telemetry.enabled) return;
|
|
152
158
|
|
|
153
|
-
const remoteId = this.aui.threadListItem
|
|
159
|
+
const remoteId = this.aui.threadListItem.getState().remoteId;
|
|
154
160
|
if (!remoteId) return;
|
|
155
161
|
|
|
156
162
|
const extracted = extractRunTelemetry(format, runMessages);
|
|
@@ -810,8 +816,12 @@ export function useAssistantCloudThreadHistoryAdapter(
|
|
|
810
816
|
cloudRef: RefObject<AssistantCloud>,
|
|
811
817
|
): ThreadHistoryAdapter {
|
|
812
818
|
const aui = useAui();
|
|
819
|
+
const auiRef = useRef(aui);
|
|
820
|
+
useEffect(() => {
|
|
821
|
+
auiRef.current = aui;
|
|
822
|
+
});
|
|
813
823
|
const [adapter] = useState(
|
|
814
|
-
() => new AssistantCloudThreadHistoryAdapter(cloudRef,
|
|
824
|
+
() => new AssistantCloudThreadHistoryAdapter(cloudRef, auiRef),
|
|
815
825
|
);
|
|
816
826
|
return adapter;
|
|
817
827
|
}
|