@assistant-ui/react 0.12.15 → 0.12.17
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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/legacy-runtime/cloud/AssistantCloudThreadHistoryAdapter.d.ts +1 -4
- package/dist/legacy-runtime/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/legacy-runtime/cloud/AssistantCloudThreadHistoryAdapter.js +2 -527
- package/dist/legacy-runtime/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/legacy-runtime/hooks/AttachmentContext.d.ts +96 -96
- package/dist/legacy-runtime/runtime-cores/adapters/RuntimeAdapterProvider.d.ts +1 -16
- package/dist/legacy-runtime/runtime-cores/adapters/RuntimeAdapterProvider.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/adapters/RuntimeAdapterProvider.js +1 -14
- package/dist/legacy-runtime/runtime-cores/adapters/RuntimeAdapterProvider.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/adapters/attachment/CloudFileAttachmentAdapter.d.ts +1 -13
- package/dist/legacy-runtime/runtime-cores/adapters/attachment/CloudFileAttachmentAdapter.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/adapters/attachment/CloudFileAttachmentAdapter.js +2 -82
- package/dist/legacy-runtime/runtime-cores/adapters/attachment/CloudFileAttachmentAdapter.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.d.ts +1 -23
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js +1 -410
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.d.ts +1 -16
- package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.js +1 -48
- package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts +1 -33
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js +1 -307
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.d.ts +1 -3
- package/dist/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.js +1 -17
- package/dist/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.d.ts +2 -26
- package/dist/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.js +1 -13
- package/dist/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.d.ts +1 -3
- package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.js +1 -51
- package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts +1 -96
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.js +1 -110
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts +1 -112
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js +1 -439
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.d.ts +1 -12
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.js +1 -102
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.d.ts +1 -3
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.js +1 -46
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarCopy.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarCopy.js +7 -20
- package/dist/primitives/actionBar/ActionBarCopy.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarEdit.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarEdit.js +3 -8
- package/dist/primitives/actionBar/ActionBarEdit.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.js +4 -7
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.js +5 -7
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarReload.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarReload.js +3 -10
- package/dist/primitives/actionBar/ActionBarReload.js.map +1 -1
- package/dist/primitives/composer/ComposerAddAttachment.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerAddAttachment.js +5 -4
- package/dist/primitives/composer/ComposerAddAttachment.js.map +1 -1
- package/dist/primitives/composer/ComposerCancel.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerCancel.js +3 -8
- package/dist/primitives/composer/ComposerCancel.js.map +1 -1
- package/dist/primitives/composer/ComposerSend.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerSend.js +3 -8
- package/dist/primitives/composer/ComposerSend.js.map +1 -1
- package/dist/utils/createActionButton.js +1 -1
- package/dist/utils/createActionButton.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +1 -1
- package/src/internal.ts +1 -1
- package/src/legacy-runtime/cloud/AssistantCloudThreadHistoryAdapter.ts +2 -784
- package/src/legacy-runtime/runtime-cores/adapters/RuntimeAdapterProvider.tsx +5 -43
- package/src/legacy-runtime/runtime-cores/adapters/attachment/CloudFileAttachmentAdapter.ts +2 -100
- package/src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.ts +4 -580
- package/src/legacy-runtime/runtime-cores/external-store/createMessageConverter.ts +1 -76
- package/src/legacy-runtime/runtime-cores/external-store/external-message-converter.ts +4 -483
- package/src/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.ts +1 -27
- package/src/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.ts +2 -35
- package/src/legacy-runtime/runtime-cores/local/useLocalRuntime.ts +1 -67
- package/src/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.tsx +1 -178
- package/src/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx +1 -529
- package/src/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.tsx +1 -152
- package/src/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.ts +1 -80
- package/src/primitives/actionBar/ActionBarCopy.tsx +7 -26
- package/src/primitives/actionBar/ActionBarEdit.ts +3 -10
- package/src/primitives/actionBar/ActionBarFeedbackNegative.tsx +4 -9
- package/src/primitives/actionBar/ActionBarFeedbackPositive.tsx +5 -9
- package/src/primitives/actionBar/ActionBarReload.ts +3 -16
- package/src/primitives/composer/ComposerAddAttachment.ts +5 -4
- package/src/primitives/composer/ComposerCancel.ts +3 -10
- package/src/primitives/composer/ComposerSend.ts +3 -13
- package/src/tests/BaseComposerRuntimeCore.test.ts +2 -3
- package/src/utils/createActionButton.tsx +1 -1
|
@@ -1,154 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
FC,
|
|
5
|
-
PropsWithChildren,
|
|
6
|
-
useCallback,
|
|
7
|
-
useEffect,
|
|
8
|
-
useMemo,
|
|
9
|
-
useRef,
|
|
10
|
-
} from "react";
|
|
11
|
-
import { AssistantCloud } from "assistant-cloud";
|
|
12
|
-
import type { RemoteThreadListAdapter } from "@assistant-ui/core";
|
|
13
|
-
import { InMemoryThreadListAdapter } from "@assistant-ui/core";
|
|
14
|
-
import { useAssistantCloudThreadHistoryAdapter } from "../../../cloud/AssistantCloudThreadHistoryAdapter";
|
|
15
|
-
import { RuntimeAdapterProvider } from "../../adapters/RuntimeAdapterProvider";
|
|
16
|
-
import { CloudFileAttachmentAdapter } from "../../adapters";
|
|
17
|
-
|
|
18
|
-
type ThreadData = {
|
|
19
|
-
externalId: string | undefined;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
type CloudThreadListAdapterOptions = {
|
|
23
|
-
cloud?: AssistantCloud | undefined;
|
|
24
|
-
|
|
25
|
-
create?: (() => Promise<ThreadData>) | undefined;
|
|
26
|
-
delete?: ((threadId: string) => Promise<void>) | undefined;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const baseUrl =
|
|
30
|
-
typeof process !== "undefined" &&
|
|
31
|
-
process?.env?.["NEXT_PUBLIC_ASSISTANT_BASE_URL"];
|
|
32
|
-
const autoCloud = baseUrl
|
|
33
|
-
? new AssistantCloud({ baseUrl, anonymous: true })
|
|
34
|
-
: undefined;
|
|
35
|
-
|
|
36
|
-
export const useCloudThreadListAdapter = (
|
|
37
|
-
adapter: CloudThreadListAdapterOptions,
|
|
38
|
-
): RemoteThreadListAdapter => {
|
|
39
|
-
const adapterRef = useRef(adapter);
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
adapterRef.current = adapter;
|
|
42
|
-
}, [adapter]);
|
|
43
|
-
|
|
44
|
-
const unstable_Provider = useCallback<FC<PropsWithChildren>>(
|
|
45
|
-
function Provider({ children }) {
|
|
46
|
-
const history = useAssistantCloudThreadHistoryAdapter({
|
|
47
|
-
get current() {
|
|
48
|
-
return adapterRef.current.cloud ?? autoCloud!;
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
const cloudInstance = adapterRef.current.cloud ?? autoCloud!;
|
|
52
|
-
const attachments = useMemo(
|
|
53
|
-
() => new CloudFileAttachmentAdapter(cloudInstance),
|
|
54
|
-
[cloudInstance],
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
const adapters = useMemo(
|
|
58
|
-
() => ({
|
|
59
|
-
history,
|
|
60
|
-
attachments,
|
|
61
|
-
}),
|
|
62
|
-
[history, attachments],
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
return (
|
|
66
|
-
<RuntimeAdapterProvider adapters={adapters}>
|
|
67
|
-
{children}
|
|
68
|
-
</RuntimeAdapterProvider>
|
|
69
|
-
);
|
|
70
|
-
},
|
|
71
|
-
[],
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
const cloud = adapter.cloud ?? autoCloud;
|
|
75
|
-
if (!cloud) {
|
|
76
|
-
const ref = adapterRef;
|
|
77
|
-
const inMemory = new InMemoryThreadListAdapter();
|
|
78
|
-
inMemory.initialize = async (threadId: string) => {
|
|
79
|
-
const result = await ref.current.create?.();
|
|
80
|
-
return { remoteId: threadId, externalId: result?.externalId };
|
|
81
|
-
};
|
|
82
|
-
return inMemory;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
list: async () => {
|
|
87
|
-
const { threads } = await cloud.threads.list();
|
|
88
|
-
return {
|
|
89
|
-
threads: threads.map((t) => ({
|
|
90
|
-
status: t.is_archived ? "archived" : "regular",
|
|
91
|
-
remoteId: t.id,
|
|
92
|
-
title: t.title,
|
|
93
|
-
externalId: t.external_id ?? undefined,
|
|
94
|
-
})),
|
|
95
|
-
};
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
initialize: async () => {
|
|
99
|
-
const createTask = adapter.create?.() ?? Promise.resolve();
|
|
100
|
-
const t = await createTask;
|
|
101
|
-
const external_id = t ? t.externalId : undefined;
|
|
102
|
-
const { thread_id: remoteId } = await cloud.threads.create({
|
|
103
|
-
last_message_at: new Date(),
|
|
104
|
-
external_id,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
return { externalId: external_id, remoteId: remoteId };
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
rename: async (threadId, newTitle) => {
|
|
111
|
-
return cloud.threads.update(threadId, { title: newTitle });
|
|
112
|
-
},
|
|
113
|
-
archive: async (threadId) => {
|
|
114
|
-
return cloud.threads.update(threadId, { is_archived: true });
|
|
115
|
-
},
|
|
116
|
-
unarchive: async (threadId) => {
|
|
117
|
-
return cloud.threads.update(threadId, { is_archived: false });
|
|
118
|
-
},
|
|
119
|
-
delete: async (threadId) => {
|
|
120
|
-
await adapter.delete?.(threadId);
|
|
121
|
-
return cloud.threads.delete(threadId);
|
|
122
|
-
},
|
|
123
|
-
|
|
124
|
-
generateTitle: async (threadId, messages) => {
|
|
125
|
-
// Filter messages to only include content types the title generator understands
|
|
126
|
-
// (reasoning, source, etc. are not needed for title generation)
|
|
127
|
-
// TODO serialize these to a more efficient format
|
|
128
|
-
const filteredMessages = messages.map((msg) => ({
|
|
129
|
-
...msg,
|
|
130
|
-
content: msg.content.filter(
|
|
131
|
-
(part) => part.type === "text" || part.type === "tool-call",
|
|
132
|
-
),
|
|
133
|
-
}));
|
|
134
|
-
|
|
135
|
-
return cloud.runs.stream({
|
|
136
|
-
thread_id: threadId,
|
|
137
|
-
assistant_id: "system/thread_title",
|
|
138
|
-
messages: filteredMessages,
|
|
139
|
-
});
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
fetch: async (threadId: string) => {
|
|
143
|
-
const thread = await cloud.threads.get(threadId);
|
|
144
|
-
return {
|
|
145
|
-
status: thread.is_archived ? "archived" : "regular",
|
|
146
|
-
remoteId: thread.id,
|
|
147
|
-
title: thread.title,
|
|
148
|
-
externalId: thread.external_id ?? undefined,
|
|
149
|
-
};
|
|
150
|
-
},
|
|
151
|
-
|
|
152
|
-
unstable_Provider,
|
|
153
|
-
};
|
|
154
|
-
};
|
|
3
|
+
export { useCloudThreadListAdapter } from "@assistant-ui/core/react";
|
|
@@ -1,82 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
BaseAssistantRuntimeCore,
|
|
6
|
-
AssistantRuntimeImpl,
|
|
7
|
-
type RemoteThreadListOptions,
|
|
8
|
-
} from "@assistant-ui/core/internal";
|
|
9
|
-
import type {
|
|
10
|
-
AssistantRuntimeCore,
|
|
11
|
-
AssistantRuntime,
|
|
12
|
-
} from "@assistant-ui/core";
|
|
13
|
-
import { RemoteThreadListThreadListRuntimeCore } from "./RemoteThreadListThreadListRuntimeCore";
|
|
14
|
-
import { useAui } from "@assistant-ui/store";
|
|
15
|
-
|
|
16
|
-
class RemoteThreadListRuntimeCore
|
|
17
|
-
extends BaseAssistantRuntimeCore
|
|
18
|
-
implements AssistantRuntimeCore
|
|
19
|
-
{
|
|
20
|
-
public readonly threads;
|
|
21
|
-
|
|
22
|
-
constructor(options: RemoteThreadListOptions) {
|
|
23
|
-
super();
|
|
24
|
-
this.threads = new RemoteThreadListThreadListRuntimeCore(
|
|
25
|
-
options,
|
|
26
|
-
this._contextProvider,
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public get RenderComponent() {
|
|
31
|
-
return this.threads.__internal_RenderComponent;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const useRemoteThreadListRuntimeImpl = (
|
|
36
|
-
options: RemoteThreadListOptions,
|
|
37
|
-
): AssistantRuntime => {
|
|
38
|
-
const [runtime] = useState(() => new RemoteThreadListRuntimeCore(options));
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
runtime.threads.__internal_setOptions(options);
|
|
41
|
-
runtime.threads.__internal_load();
|
|
42
|
-
}, [runtime, options]);
|
|
43
|
-
return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const useRemoteThreadListRuntime = (
|
|
47
|
-
options: RemoteThreadListOptions,
|
|
48
|
-
): AssistantRuntime => {
|
|
49
|
-
const runtimeHookRef = useRef(options.runtimeHook);
|
|
50
|
-
runtimeHookRef.current = options.runtimeHook;
|
|
51
|
-
|
|
52
|
-
const stableRuntimeHook = useCallback(() => {
|
|
53
|
-
return runtimeHookRef.current();
|
|
54
|
-
}, []);
|
|
55
|
-
|
|
56
|
-
const stableOptions = useMemo<RemoteThreadListOptions>(
|
|
57
|
-
() => ({
|
|
58
|
-
adapter: options.adapter,
|
|
59
|
-
allowNesting: options.allowNesting,
|
|
60
|
-
runtimeHook: stableRuntimeHook,
|
|
61
|
-
}),
|
|
62
|
-
[options.adapter, options.allowNesting, stableRuntimeHook],
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
const aui = useAui();
|
|
66
|
-
const isNested = aui.threadListItem.source !== null;
|
|
67
|
-
|
|
68
|
-
if (isNested) {
|
|
69
|
-
if (!stableOptions.allowNesting) {
|
|
70
|
-
throw new Error(
|
|
71
|
-
"useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. " +
|
|
72
|
-
"Set allowNesting: true to allow nesting (the inner runtime will become a no-op).",
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// If allowNesting is true and already inside a thread list context,
|
|
77
|
-
// just call the runtimeHook directly (no-op behavior)
|
|
78
|
-
return stableRuntimeHook();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return useRemoteThreadListRuntimeImpl(stableOptions);
|
|
82
|
-
};
|
|
3
|
+
export { useRemoteThreadListRuntime } from "@assistant-ui/core/react";
|
|
@@ -4,8 +4,8 @@ import { forwardRef } from "react";
|
|
|
4
4
|
import { ActionButtonProps } from "../../utils/createActionButton";
|
|
5
5
|
import { composeEventHandlers } from "@radix-ui/primitive";
|
|
6
6
|
import { Primitive } from "@radix-ui/react-primitive";
|
|
7
|
-
import {
|
|
8
|
-
import { useAuiState
|
|
7
|
+
import { useActionBarCopy } from "@assistant-ui/core/react";
|
|
8
|
+
import { useAuiState } from "@assistant-ui/store";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Hook that provides copy functionality for action bar buttons.
|
|
@@ -36,31 +36,12 @@ const useActionBarPrimitiveCopy = ({
|
|
|
36
36
|
}: {
|
|
37
37
|
copiedDuration?: number | undefined;
|
|
38
38
|
} = {}) => {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
(s.message.role !== "assistant" ||
|
|
43
|
-
s.message.status?.type !== "running") &&
|
|
44
|
-
s.message.parts.some((c) => c.type === "text" && c.text.length > 0)
|
|
45
|
-
);
|
|
39
|
+
const { copy, disabled } = useActionBarCopy({
|
|
40
|
+
copiedDuration,
|
|
41
|
+
copyToClipboard: (text) => navigator.clipboard.writeText(text),
|
|
46
42
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const composerValue = useAuiState((s) => s.composer.text);
|
|
50
|
-
|
|
51
|
-
const callback = useCallback(() => {
|
|
52
|
-
const valueToCopy = isEditing ? composerValue : aui.message().getCopyText();
|
|
53
|
-
|
|
54
|
-
if (!valueToCopy) return;
|
|
55
|
-
|
|
56
|
-
navigator.clipboard.writeText(valueToCopy).then(() => {
|
|
57
|
-
aui.message().setIsCopied(true);
|
|
58
|
-
setTimeout(() => aui.message().setIsCopied(false), copiedDuration);
|
|
59
|
-
});
|
|
60
|
-
}, [aui, isEditing, composerValue, copiedDuration]);
|
|
61
|
-
|
|
62
|
-
if (!hasCopyableContent) return null;
|
|
63
|
-
return callback;
|
|
43
|
+
if (disabled) return null;
|
|
44
|
+
return copy;
|
|
64
45
|
};
|
|
65
46
|
|
|
66
47
|
export namespace ActionBarPrimitiveCopy {
|
|
@@ -5,8 +5,7 @@ import {
|
|
|
5
5
|
ActionButtonProps,
|
|
6
6
|
createActionButton,
|
|
7
7
|
} from "../../utils/createActionButton";
|
|
8
|
-
import {
|
|
9
|
-
import { useAuiState, useAui } from "@assistant-ui/store";
|
|
8
|
+
import { useActionBarEdit as useActionBarEditBehavior } from "@assistant-ui/core/react";
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Hook that provides edit functionality for action bar buttons.
|
|
@@ -30,15 +29,9 @@ import { useAuiState, useAui } from "@assistant-ui/store";
|
|
|
30
29
|
* ```
|
|
31
30
|
*/
|
|
32
31
|
const useActionBarEdit = () => {
|
|
33
|
-
const
|
|
34
|
-
const disabled = useAuiState((s) => s.composer.isEditing);
|
|
35
|
-
|
|
36
|
-
const callback = useCallback(() => {
|
|
37
|
-
aui.composer().beginEdit();
|
|
38
|
-
}, [aui]);
|
|
39
|
-
|
|
32
|
+
const { disabled, edit } = useActionBarEditBehavior();
|
|
40
33
|
if (disabled) return null;
|
|
41
|
-
return
|
|
34
|
+
return edit;
|
|
42
35
|
};
|
|
43
36
|
|
|
44
37
|
export namespace ActionBarPrimitiveEdit {
|
|
@@ -4,17 +4,12 @@ import { forwardRef } from "react";
|
|
|
4
4
|
import { ActionButtonProps } from "../../utils/createActionButton";
|
|
5
5
|
import { composeEventHandlers } from "@radix-ui/primitive";
|
|
6
6
|
import { Primitive } from "@radix-ui/react-primitive";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { useAuiState } from "@assistant-ui/store";
|
|
8
|
+
import { useActionBarFeedbackNegative as useActionBarFeedbackNegativeBehavior } from "@assistant-ui/core/react";
|
|
9
9
|
|
|
10
10
|
const useActionBarFeedbackNegative = () => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const callback = useCallback(() => {
|
|
14
|
-
aui.message().submitFeedback({ type: "negative" });
|
|
15
|
-
}, [aui]);
|
|
16
|
-
|
|
17
|
-
return callback;
|
|
11
|
+
const { submit } = useActionBarFeedbackNegativeBehavior();
|
|
12
|
+
return submit;
|
|
18
13
|
};
|
|
19
14
|
|
|
20
15
|
export namespace ActionBarPrimitiveFeedbackNegative {
|
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { forwardRef
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
4
|
import { ActionButtonProps } from "../../utils/createActionButton";
|
|
5
5
|
import { composeEventHandlers } from "@radix-ui/primitive";
|
|
6
|
-
import { useAuiState
|
|
6
|
+
import { useAuiState } from "@assistant-ui/store";
|
|
7
7
|
import { Primitive } from "@radix-ui/react-primitive";
|
|
8
|
+
import { useActionBarFeedbackPositive as useActionBarFeedbackPositiveBehavior } from "@assistant-ui/core/react";
|
|
8
9
|
|
|
9
10
|
const useActionBarFeedbackPositive = () => {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const callback = useCallback(() => {
|
|
13
|
-
aui.message().submitFeedback({ type: "positive" });
|
|
14
|
-
}, [aui]);
|
|
15
|
-
|
|
16
|
-
return callback;
|
|
11
|
+
const { submit } = useActionBarFeedbackPositiveBehavior();
|
|
12
|
+
return submit;
|
|
17
13
|
};
|
|
18
14
|
|
|
19
15
|
export namespace ActionBarPrimitiveFeedbackPositive {
|
|
@@ -5,8 +5,7 @@ import {
|
|
|
5
5
|
ActionButtonProps,
|
|
6
6
|
createActionButton,
|
|
7
7
|
} from "../../utils/createActionButton";
|
|
8
|
-
import {
|
|
9
|
-
import { useAuiState, useAui } from "@assistant-ui/store";
|
|
8
|
+
import { useActionBarReload as useActionBarReloadBehavior } from "@assistant-ui/core/react";
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Hook that provides reload functionality for action bar buttons.
|
|
@@ -30,21 +29,9 @@ import { useAuiState, useAui } from "@assistant-ui/store";
|
|
|
30
29
|
* ```
|
|
31
30
|
*/
|
|
32
31
|
const useActionBarReload = () => {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const disabled = useAuiState(
|
|
36
|
-
(s) =>
|
|
37
|
-
s.thread.isRunning ||
|
|
38
|
-
s.thread.isDisabled ||
|
|
39
|
-
s.message.role !== "assistant",
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const callback = useCallback(() => {
|
|
43
|
-
aui.message().reload();
|
|
44
|
-
}, [aui]);
|
|
45
|
-
|
|
32
|
+
const { disabled, reload } = useActionBarReloadBehavior();
|
|
46
33
|
if (disabled) return null;
|
|
47
|
-
return
|
|
34
|
+
return reload;
|
|
48
35
|
};
|
|
49
36
|
|
|
50
37
|
export namespace ActionBarPrimitiveReload {
|
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
createActionButton,
|
|
7
7
|
} from "../../utils/createActionButton";
|
|
8
8
|
import { useCallback } from "react";
|
|
9
|
-
import {
|
|
9
|
+
import { useAui } from "@assistant-ui/store";
|
|
10
|
+
import { useComposerAddAttachment as useComposerAddAttachmentBehavior } from "@assistant-ui/core/react";
|
|
10
11
|
|
|
11
12
|
const useComposerAddAttachment = ({
|
|
12
13
|
multiple = true,
|
|
@@ -14,7 +15,7 @@ const useComposerAddAttachment = ({
|
|
|
14
15
|
/** allow selecting multiple files */
|
|
15
16
|
multiple?: boolean | undefined;
|
|
16
17
|
} = {}) => {
|
|
17
|
-
const disabled =
|
|
18
|
+
const { disabled, addAttachment } = useComposerAddAttachmentBehavior();
|
|
18
19
|
const aui = useAui();
|
|
19
20
|
|
|
20
21
|
const callback = useCallback(() => {
|
|
@@ -34,7 +35,7 @@ const useComposerAddAttachment = ({
|
|
|
34
35
|
const fileList = (e.target as HTMLInputElement).files;
|
|
35
36
|
if (!fileList) return;
|
|
36
37
|
for (const file of fileList) {
|
|
37
|
-
|
|
38
|
+
addAttachment(file);
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
document.body.removeChild(input);
|
|
@@ -47,7 +48,7 @@ const useComposerAddAttachment = ({
|
|
|
47
48
|
};
|
|
48
49
|
|
|
49
50
|
input.click();
|
|
50
|
-
}, [aui, multiple]);
|
|
51
|
+
}, [aui, multiple, addAttachment]);
|
|
51
52
|
|
|
52
53
|
if (disabled) return null;
|
|
53
54
|
return callback;
|
|
@@ -5,19 +5,12 @@ import {
|
|
|
5
5
|
ActionButtonProps,
|
|
6
6
|
createActionButton,
|
|
7
7
|
} from "../../utils/createActionButton";
|
|
8
|
-
import {
|
|
9
|
-
import { useAuiState, useAui } from "@assistant-ui/store";
|
|
8
|
+
import { useComposerCancel as useComposerCancelBehavior } from "@assistant-ui/core/react";
|
|
10
9
|
|
|
11
10
|
const useComposerCancel = () => {
|
|
12
|
-
const
|
|
13
|
-
const disabled = useAuiState((s) => !s.composer.canCancel);
|
|
14
|
-
|
|
15
|
-
const callback = useCallback(() => {
|
|
16
|
-
aui.composer().cancel();
|
|
17
|
-
}, [aui]);
|
|
18
|
-
|
|
11
|
+
const { disabled, cancel } = useComposerCancelBehavior();
|
|
19
12
|
if (disabled) return null;
|
|
20
|
-
return
|
|
13
|
+
return cancel;
|
|
21
14
|
};
|
|
22
15
|
|
|
23
16
|
export namespace ComposerPrimitiveCancel {
|
|
@@ -5,22 +5,12 @@ import {
|
|
|
5
5
|
ActionButtonProps,
|
|
6
6
|
createActionButton,
|
|
7
7
|
} from "../../utils/createActionButton";
|
|
8
|
-
import {
|
|
9
|
-
import { useAuiState, useAui } from "@assistant-ui/store";
|
|
8
|
+
import { useComposerSend as useComposerSendBehavior } from "@assistant-ui/core/react";
|
|
10
9
|
|
|
11
10
|
export const useComposerSend = () => {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const disabled = useAuiState(
|
|
15
|
-
(s) => s.thread.isRunning || !s.composer.isEditing || s.composer.isEmpty,
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
const callback = useCallback(() => {
|
|
19
|
-
aui.composer().send();
|
|
20
|
-
}, [aui]);
|
|
21
|
-
|
|
11
|
+
const { disabled, send } = useComposerSendBehavior();
|
|
22
12
|
if (disabled) return null;
|
|
23
|
-
return
|
|
13
|
+
return send;
|
|
24
14
|
};
|
|
25
15
|
|
|
26
16
|
export namespace ComposerPrimitiveSend {
|
|
@@ -181,11 +181,10 @@ describe("BaseComposerRuntimeCore", () => {
|
|
|
181
181
|
expect(composer.quote).toBeUndefined();
|
|
182
182
|
});
|
|
183
183
|
|
|
184
|
-
it("send with empty text
|
|
184
|
+
it("send with empty text is a no-op", async () => {
|
|
185
185
|
await composer.send();
|
|
186
186
|
|
|
187
|
-
expect(composer.sentMessages).toHaveLength(
|
|
188
|
-
expect(composer.sentMessages[0]!.content).toEqual([]);
|
|
187
|
+
expect(composer.sentMessages).toHaveLength(0);
|
|
189
188
|
});
|
|
190
189
|
|
|
191
190
|
it("addAttachment throws when no adapter", async () => {
|
|
@@ -41,8 +41,8 @@ export const createActionButton = <TProps,>(
|
|
|
41
41
|
const callback = useActionButton(forwardedProps as TProps) ?? undefined;
|
|
42
42
|
return (
|
|
43
43
|
<Primitive.button
|
|
44
|
-
type="button"
|
|
45
44
|
{...primitiveProps}
|
|
45
|
+
type="button"
|
|
46
46
|
ref={forwardedRef}
|
|
47
47
|
disabled={primitiveProps.disabled || !callback}
|
|
48
48
|
onClick={composeEventHandlers(primitiveProps.onClick, callback)}
|