@assistant-ui/react 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +24 -4
- package/dist/index.d.ts +24 -4
- package/dist/index.js +39 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
@@ -148,11 +148,14 @@ var makeBaseComposer = (set) => ({
|
|
148
148
|
});
|
149
149
|
|
150
150
|
// src/context/stores/Composer.ts
|
151
|
-
var makeComposerStore = (
|
151
|
+
var makeComposerStore = (useThreadMessages, useThreadActions) => {
|
152
152
|
const focusListeners = /* @__PURE__ */ new Set();
|
153
153
|
return create3()((set, get, store) => {
|
154
154
|
return {
|
155
155
|
...makeBaseComposer(set, get, store),
|
156
|
+
get canCancel() {
|
157
|
+
return useThreadActions.getState().capabilities.cancel;
|
158
|
+
},
|
156
159
|
isEditing: true,
|
157
160
|
send: () => {
|
158
161
|
const { setValue, value } = get();
|
@@ -164,10 +167,7 @@ var makeComposerStore = (useThread, useThreadMessages, useThreadActions) => {
|
|
164
167
|
});
|
165
168
|
},
|
166
169
|
cancel: () => {
|
167
|
-
const thread = useThread.getState();
|
168
|
-
if (!thread.isRunning) return false;
|
169
170
|
useThreadActions.getState().cancelRun();
|
170
|
-
return true;
|
171
171
|
},
|
172
172
|
focus: () => {
|
173
173
|
for (const listener of focusListeners) {
|
@@ -217,6 +217,9 @@ import { create as create6 } from "zustand";
|
|
217
217
|
var makeThreadActionStore = (runtimeRef) => {
|
218
218
|
return create6(
|
219
219
|
() => Object.freeze({
|
220
|
+
get capabilities() {
|
221
|
+
return runtimeRef.current.capabilities;
|
222
|
+
},
|
220
223
|
getBranches: (messageId) => runtimeRef.current.getBranches(messageId),
|
221
224
|
switchToBranch: (branchId) => runtimeRef.current.switchToBranch(branchId),
|
222
225
|
startRun: (parentId) => runtimeRef.current.startRun(parentId),
|
@@ -248,11 +251,7 @@ var ThreadProvider = ({
|
|
248
251
|
const useThreadMessages = makeThreadMessagesStore(runtimeRef);
|
249
252
|
const useThreadActions = makeThreadActionStore(runtimeRef);
|
250
253
|
const useViewport = makeThreadViewportStore();
|
251
|
-
const useComposer = makeComposerStore(
|
252
|
-
useThread,
|
253
|
-
useThreadMessages,
|
254
|
-
useThreadActions
|
255
|
-
);
|
254
|
+
const useComposer = makeComposerStore(useThreadMessages, useThreadActions);
|
256
255
|
return {
|
257
256
|
useThread,
|
258
257
|
useThreadMessages,
|
@@ -625,7 +624,7 @@ var useBranchPickerPrevious = () => {
|
|
625
624
|
import { useCallback as useCallback9 } from "react";
|
626
625
|
var useComposerCancel = () => {
|
627
626
|
const { useComposer } = useComposerContext();
|
628
|
-
const disabled = useComposer((c) => !c.
|
627
|
+
const disabled = useComposer((c) => !c.canCancel);
|
629
628
|
const callback = useCallback9(() => {
|
630
629
|
const { cancel } = useComposer.getState();
|
631
630
|
cancel();
|
@@ -757,15 +756,18 @@ var useThreadSuggestion = ({
|
|
757
756
|
autoSend
|
758
757
|
}) => {
|
759
758
|
const { useThread, useComposer } = useThreadContext();
|
759
|
+
const append = useAppendMessage();
|
760
760
|
const disabled = useThread((t) => t.isRunning);
|
761
761
|
const callback = useCallback12(() => {
|
762
762
|
const thread = useThread.getState();
|
763
763
|
const composer = useComposer.getState();
|
764
|
-
composer.setValue(prompt);
|
765
764
|
if (autoSend && !thread.isRunning) {
|
766
|
-
|
765
|
+
append(prompt);
|
766
|
+
composer.setValue("");
|
767
|
+
} else {
|
768
|
+
composer.setValue(prompt);
|
767
769
|
}
|
768
|
-
}, [useThread, useComposer,
|
770
|
+
}, [useThread, useComposer, autoSend, append, prompt]);
|
769
771
|
if (disabled) return null;
|
770
772
|
return callback;
|
771
773
|
};
|
@@ -1203,7 +1205,7 @@ import { jsx as jsx16, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1203
1205
|
var defaultComponents = {
|
1204
1206
|
Text: () => /* @__PURE__ */ jsxs2("p", { style: { whiteSpace: "pre-line" }, children: [
|
1205
1207
|
/* @__PURE__ */ jsx16(ContentPartPrimitiveText, {}),
|
1206
|
-
/* @__PURE__ */ jsx16(ContentPartPrimitiveInProgress, { children: " \u25CF" })
|
1208
|
+
/* @__PURE__ */ jsx16(ContentPartPrimitiveInProgress, { children: /* @__PURE__ */ jsx16("span", { style: { fontFamily: "revert" }, children: " \u25CF" }) })
|
1207
1209
|
] }),
|
1208
1210
|
Image: () => /* @__PURE__ */ jsx16(ContentPartPrimitiveImage, {}),
|
1209
1211
|
UI: () => /* @__PURE__ */ jsx16(ContentPartPrimitiveDisplay, {}),
|
@@ -1348,7 +1350,8 @@ var ComposerPrimitiveInput = forwardRef11(
|
|
1348
1350
|
const ref = useComposedRefs2(forwardedRef, textareaRef);
|
1349
1351
|
useEscapeKeydown((e) => {
|
1350
1352
|
const composer = useComposer.getState();
|
1351
|
-
if (composer.
|
1353
|
+
if (composer.canCancel) {
|
1354
|
+
composer.cancel();
|
1352
1355
|
e.preventDefault();
|
1353
1356
|
}
|
1354
1357
|
});
|
@@ -1622,20 +1625,19 @@ var makeEditComposerStore = ({
|
|
1622
1625
|
onSend
|
1623
1626
|
}) => create10()((set, get, store) => ({
|
1624
1627
|
...makeBaseComposer(set, get, store),
|
1628
|
+
canCancel: false,
|
1625
1629
|
isEditing: false,
|
1626
1630
|
edit: () => {
|
1627
1631
|
const value = onEdit();
|
1628
|
-
set({ isEditing: true, value });
|
1632
|
+
set({ isEditing: true, canCancel: true, value });
|
1629
1633
|
},
|
1630
1634
|
send: () => {
|
1631
1635
|
const value = get().value;
|
1632
|
-
set({ isEditing: false });
|
1636
|
+
set({ isEditing: false, canCancel: false });
|
1633
1637
|
onSend(value);
|
1634
1638
|
},
|
1635
1639
|
cancel: () => {
|
1636
|
-
|
1637
|
-
set({ isEditing: false });
|
1638
|
-
return true;
|
1640
|
+
set({ isEditing: false, canCancel: false });
|
1639
1641
|
}
|
1640
1642
|
}));
|
1641
1643
|
|
@@ -1756,9 +1758,9 @@ var ThreadMessageImpl = ({
|
|
1756
1758
|
};
|
1757
1759
|
var ThreadMessage = memo3(
|
1758
1760
|
ThreadMessageImpl,
|
1759
|
-
(prev, next) => prev.messageIndex === next.messageIndex && prev.components.UserMessage === next.components.UserMessage && prev.components.EditComposer === next.components.EditComposer && prev.components.AssistantMessage === next.components.AssistantMessage
|
1761
|
+
(prev, next) => prev.messageIndex === next.messageIndex && prev.components.Message === next.components.Message && prev.components.UserMessage === next.components.UserMessage && prev.components.EditComposer === next.components.EditComposer && prev.components.AssistantMessage === next.components.AssistantMessage
|
1760
1762
|
);
|
1761
|
-
var
|
1763
|
+
var ThreadPrimitiveMessagesImpl = ({
|
1762
1764
|
components
|
1763
1765
|
}) => {
|
1764
1766
|
const { useThreadMessages } = useThreadContext();
|
@@ -1776,7 +1778,11 @@ var ThreadPrimitiveMessages = ({
|
|
1776
1778
|
);
|
1777
1779
|
});
|
1778
1780
|
};
|
1779
|
-
|
1781
|
+
ThreadPrimitiveMessagesImpl.displayName = "ThreadPrimitive.Messages";
|
1782
|
+
var ThreadPrimitiveMessages = memo3(
|
1783
|
+
ThreadPrimitiveMessagesImpl,
|
1784
|
+
(prev, next) => prev.components?.Message === next.components?.Message && prev.components?.UserMessage === next.components?.UserMessage && prev.components?.EditComposer === next.components?.EditComposer && prev.components?.AssistantMessage === next.components?.AssistantMessage
|
1785
|
+
);
|
1780
1786
|
|
1781
1787
|
// src/primitives/thread/ThreadScrollToBottom.tsx
|
1782
1788
|
var ThreadPrimitiveScrollToBottom = createActionButton(
|
@@ -1960,6 +1966,9 @@ var BaseAssistantRuntime = class {
|
|
1960
1966
|
this._thread = _thread;
|
1961
1967
|
this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);
|
1962
1968
|
}
|
1969
|
+
get capabilities() {
|
1970
|
+
return this._thread.capabilities;
|
1971
|
+
}
|
1963
1972
|
_unsubscribe;
|
1964
1973
|
get thread() {
|
1965
1974
|
return this._thread;
|
@@ -2032,6 +2041,12 @@ var LocalRuntime = class extends BaseAssistantRuntime {
|
|
2032
2041
|
);
|
2033
2042
|
}
|
2034
2043
|
};
|
2044
|
+
var CAPABILITIES = Object.freeze({
|
2045
|
+
edit: true,
|
2046
|
+
reload: true,
|
2047
|
+
cancel: true,
|
2048
|
+
copy: true
|
2049
|
+
});
|
2035
2050
|
var LocalThreadRuntime = class {
|
2036
2051
|
constructor(_configProviders, adapter) {
|
2037
2052
|
this._configProviders = _configProviders;
|
@@ -2040,6 +2055,7 @@ var LocalThreadRuntime = class {
|
|
2040
2055
|
_subscriptions = /* @__PURE__ */ new Set();
|
2041
2056
|
abortController = null;
|
2042
2057
|
repository = new MessageRepository();
|
2058
|
+
capabilities = CAPABILITIES;
|
2043
2059
|
get messages() {
|
2044
2060
|
return this.repository.getMessages();
|
2045
2061
|
}
|