@assistant-ui/react 0.5.35 → 0.5.37
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-LX7F2T2K.mjs → chunk-5ZTUOAPH.mjs} +374 -102
- package/dist/chunk-5ZTUOAPH.mjs.map +1 -0
- package/dist/{chunk-JKRONBQK.js → chunk-BQ3MRWUV.js} +377 -105
- package/dist/chunk-BQ3MRWUV.js.map +1 -0
- package/dist/{EdgeRuntimeRequestOptions-BP7q0lyh.d.mts → edge-6dYzFCV5.d.mts} +31 -4
- package/dist/{EdgeRuntimeRequestOptions-BP7q0lyh.d.ts → edge-6dYzFCV5.d.ts} +31 -4
- package/dist/edge.js.map +1 -1
- package/dist/edge.mjs.map +1 -1
- package/dist/index.d.mts +13 -4
- package/dist/index.d.ts +13 -4
- package/dist/index.js +104 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -20
- package/dist/index.mjs.map +1 -1
- package/dist/styles/index.css +9 -0
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/tailwindcss/thread.css +1 -1
- package/package.json +3 -3
- package/dist/chunk-JKRONBQK.js.map +0 -1
- package/dist/chunk-LX7F2T2K.mjs.map +0 -1
package/dist/index.mjs
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
"use client";
|
2
2
|
import {
|
3
3
|
PipeableTransformStream,
|
4
|
+
getEdgeRuntimeStream,
|
4
5
|
mergeModelConfigs,
|
5
6
|
runResultStream,
|
6
7
|
streamPartEncoderStream,
|
@@ -9,7 +10,7 @@ import {
|
|
9
10
|
toLanguageModelMessages,
|
10
11
|
toLanguageModelTools,
|
11
12
|
toolResultStream
|
12
|
-
} from "./chunk-
|
13
|
+
} from "./chunk-5ZTUOAPH.mjs";
|
13
14
|
import {
|
14
15
|
__export
|
15
16
|
} from "./chunk-BJPOCE4O.mjs";
|
@@ -18,7 +19,7 @@ import {
|
|
18
19
|
import { memo } from "react";
|
19
20
|
|
20
21
|
// src/context/providers/AssistantProvider.tsx
|
21
|
-
import { useEffect as useEffect4, useInsertionEffect as useInsertionEffect3, useRef as useRef2, useState as
|
22
|
+
import { useEffect as useEffect4, useInsertionEffect as useInsertionEffect3, useRef as useRef2, useState as useState8 } from "react";
|
22
23
|
|
23
24
|
// src/context/react/AssistantContext.ts
|
24
25
|
import { createContext, useContext } from "react";
|
@@ -97,7 +98,7 @@ var makeAssistantToolUIsStore = () => create2((set) => {
|
|
97
98
|
});
|
98
99
|
|
99
100
|
// src/context/providers/ThreadProvider.tsx
|
100
|
-
import { useEffect as useEffect3, useInsertionEffect as useInsertionEffect2, useState as
|
101
|
+
import { useEffect as useEffect3, useInsertionEffect as useInsertionEffect2, useState as useState7 } from "react";
|
101
102
|
|
102
103
|
// src/context/react/ThreadContext.ts
|
103
104
|
import { createContext as createContext2, useContext as useContext2 } from "react";
|
@@ -1297,6 +1298,19 @@ var LocalRuntime = class extends BaseAssistantRuntime {
|
|
1297
1298
|
this.thread.adapter
|
1298
1299
|
);
|
1299
1300
|
}
|
1301
|
+
reset({
|
1302
|
+
initialMessages
|
1303
|
+
} = {}) {
|
1304
|
+
this.switchToThread(null);
|
1305
|
+
if (!initialMessages) return;
|
1306
|
+
const messages = fromCoreMessages(initialMessages);
|
1307
|
+
this.thread.import({
|
1308
|
+
messages: messages.map((m, idx) => ({
|
1309
|
+
parentId: messages[idx - 1]?.id ?? null,
|
1310
|
+
message: m
|
1311
|
+
}))
|
1312
|
+
});
|
1313
|
+
}
|
1300
1314
|
};
|
1301
1315
|
|
1302
1316
|
// src/runtimes/local/useLocalRuntime.tsx
|
@@ -1614,13 +1628,49 @@ var useExternalStoreRuntime = (store) => {
|
|
1614
1628
|
return runtime;
|
1615
1629
|
};
|
1616
1630
|
|
1631
|
+
// src/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.ts
|
1632
|
+
import { useState as useState6 } from "react";
|
1633
|
+
|
1634
|
+
// src/runtimes/dangerous-in-browser/DangerousInBrowserAdapter.ts
|
1635
|
+
var DangerousInBrowserAdapter = class {
|
1636
|
+
constructor(options) {
|
1637
|
+
this.options = options;
|
1638
|
+
}
|
1639
|
+
async *run({ messages, abortSignal, config }) {
|
1640
|
+
const res = await getEdgeRuntimeStream({
|
1641
|
+
options: this.options,
|
1642
|
+
abortSignal,
|
1643
|
+
requestData: {
|
1644
|
+
system: config.system,
|
1645
|
+
messages: toCoreMessages(messages),
|
1646
|
+
tools: config.tools ? toLanguageModelTools(config.tools) : [],
|
1647
|
+
...config.callSettings,
|
1648
|
+
...config.config
|
1649
|
+
}
|
1650
|
+
});
|
1651
|
+
const stream = res.pipeThrough(toolResultStream(config.tools, abortSignal)).pipeThrough(runResultStream());
|
1652
|
+
for await (const update of asAsyncIterable(stream)) {
|
1653
|
+
yield update;
|
1654
|
+
}
|
1655
|
+
}
|
1656
|
+
};
|
1657
|
+
|
1658
|
+
// src/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.ts
|
1659
|
+
var useDangerousInBrowserRuntime = ({
|
1660
|
+
initialMessages,
|
1661
|
+
...options
|
1662
|
+
}) => {
|
1663
|
+
const [adapter] = useState6(() => new DangerousInBrowserAdapter(options));
|
1664
|
+
return useLocalRuntime(adapter, { initialMessages });
|
1665
|
+
};
|
1666
|
+
|
1617
1667
|
// src/context/providers/ThreadProvider.tsx
|
1618
1668
|
import { jsx as jsx6, jsxs as jsxs2 } from "react/jsx-runtime";
|
1619
1669
|
var ThreadProvider = ({
|
1620
1670
|
children,
|
1621
1671
|
provider
|
1622
1672
|
}) => {
|
1623
|
-
const [context] =
|
1673
|
+
const [context] = useState7(() => {
|
1624
1674
|
const useThreadRuntime = makeThreadRuntimeStore(provider.thread);
|
1625
1675
|
const useThread = makeThreadStore(useThreadRuntime);
|
1626
1676
|
const useThreadMessages = makeThreadMessagesStore(useThreadRuntime);
|
@@ -1686,6 +1736,12 @@ var makeAssistantActionsStore = (runtimeRef) => create10(
|
|
1686
1736
|
})
|
1687
1737
|
);
|
1688
1738
|
|
1739
|
+
// src/context/stores/AssistantRuntime.tsx
|
1740
|
+
import { create as create11 } from "zustand";
|
1741
|
+
var makeAssistantRuntimeStore = (runtime) => {
|
1742
|
+
return create11(() => runtime);
|
1743
|
+
};
|
1744
|
+
|
1689
1745
|
// src/context/providers/AssistantProvider.tsx
|
1690
1746
|
import { jsx as jsx7 } from "react/jsx-runtime";
|
1691
1747
|
var AssistantProvider = ({ children, runtime }) => {
|
@@ -1693,16 +1749,26 @@ var AssistantProvider = ({ children, runtime }) => {
|
|
1693
1749
|
useInsertionEffect3(() => {
|
1694
1750
|
runtimeRef.current = runtime;
|
1695
1751
|
});
|
1696
|
-
const [context] =
|
1752
|
+
const [context] = useState8(() => {
|
1753
|
+
const useAssistantRuntime = makeAssistantRuntimeStore(runtime);
|
1697
1754
|
const useModelConfig = makeAssistantModelConfigStore();
|
1698
1755
|
const useToolUIs = makeAssistantToolUIsStore();
|
1699
1756
|
const useAssistantActions = makeAssistantActionsStore(runtimeRef);
|
1700
|
-
return {
|
1757
|
+
return {
|
1758
|
+
useModelConfig,
|
1759
|
+
useToolUIs,
|
1760
|
+
useAssistantRuntime,
|
1761
|
+
useAssistantActions
|
1762
|
+
};
|
1701
1763
|
});
|
1702
1764
|
const getModelConfig = context.useModelConfig();
|
1703
1765
|
useEffect4(() => {
|
1704
1766
|
return runtime.registerModelConfigProvider(getModelConfig);
|
1705
1767
|
}, [runtime, getModelConfig]);
|
1768
|
+
useEffect4(
|
1769
|
+
() => context.useAssistantRuntime.setState(runtime, true),
|
1770
|
+
[runtime, context]
|
1771
|
+
);
|
1706
1772
|
return /* @__PURE__ */ jsx7(AssistantContext.Provider, { value: context, children: /* @__PURE__ */ jsx7(ThreadProvider, { provider: runtime, children }) });
|
1707
1773
|
};
|
1708
1774
|
|
@@ -2285,7 +2351,7 @@ __export(assistantModal_exports, {
|
|
2285
2351
|
});
|
2286
2352
|
|
2287
2353
|
// src/primitives/assistantModal/AssistantModalRoot.tsx
|
2288
|
-
import { useState as
|
2354
|
+
import { useState as useState9 } from "react";
|
2289
2355
|
import * as PopoverPrimitive2 from "@radix-ui/react-popover";
|
2290
2356
|
import { composeEventHandlers as composeEventHandlers2 } from "@radix-ui/primitive";
|
2291
2357
|
|
@@ -2309,7 +2375,7 @@ var usePopoverScope = PopoverPrimitive.createPopoverScope();
|
|
2309
2375
|
// src/primitives/assistantModal/AssistantModalRoot.tsx
|
2310
2376
|
import { jsx as jsx11 } from "react/jsx-runtime";
|
2311
2377
|
var useAssistantModalOpenState = (defaultOpen = false) => {
|
2312
|
-
const state =
|
2378
|
+
const state = useState9(defaultOpen);
|
2313
2379
|
const [, setOpen] = state;
|
2314
2380
|
useOnComposerFocus(() => {
|
2315
2381
|
setOpen(true);
|
@@ -2523,8 +2589,8 @@ MessagePrimitiveIf.displayName = "MessagePrimitive.If";
|
|
2523
2589
|
import { memo as memo2 } from "react";
|
2524
2590
|
|
2525
2591
|
// src/context/providers/ContentPartProvider.tsx
|
2526
|
-
import { useEffect as useEffect9, useState as
|
2527
|
-
import { create as
|
2592
|
+
import { useEffect as useEffect9, useState as useState10 } from "react";
|
2593
|
+
import { create as create12 } from "zustand";
|
2528
2594
|
import { jsx as jsx18 } from "react/jsx-runtime";
|
2529
2595
|
var COMPLETE_STATUS = {
|
2530
2596
|
type: "complete"
|
@@ -2562,8 +2628,8 @@ var getContentPartState = ({ message }, useContentPart, partIndex) => {
|
|
2562
2628
|
};
|
2563
2629
|
var useContentPartContext2 = (partIndex) => {
|
2564
2630
|
const { useMessage } = useMessageContext();
|
2565
|
-
const [context] =
|
2566
|
-
const useContentPart =
|
2631
|
+
const [context] = useState10(() => {
|
2632
|
+
const useContentPart = create12(
|
2567
2633
|
() => getContentPartState(useMessage.getState(), void 0, partIndex)
|
2568
2634
|
);
|
2569
2635
|
return { useContentPart };
|
@@ -3070,15 +3136,15 @@ ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
|
|
3070
3136
|
import { memo as memo3 } from "react";
|
3071
3137
|
|
3072
3138
|
// src/context/providers/MessageProvider.tsx
|
3073
|
-
import { useEffect as useEffect12, useState as
|
3074
|
-
import { create as
|
3139
|
+
import { useEffect as useEffect12, useState as useState11 } from "react";
|
3140
|
+
import { create as create15 } from "zustand";
|
3075
3141
|
|
3076
3142
|
// src/context/stores/EditComposer.ts
|
3077
|
-
import { create as
|
3143
|
+
import { create as create13 } from "zustand";
|
3078
3144
|
var makeEditComposerStore = ({
|
3079
3145
|
onEdit,
|
3080
3146
|
onSend
|
3081
|
-
}) =>
|
3147
|
+
}) => create13()((set, get) => ({
|
3082
3148
|
get value() {
|
3083
3149
|
return get().text;
|
3084
3150
|
},
|
@@ -3106,8 +3172,8 @@ var makeEditComposerStore = ({
|
|
3106
3172
|
}));
|
3107
3173
|
|
3108
3174
|
// src/context/stores/MessageUtils.ts
|
3109
|
-
import { create as
|
3110
|
-
var makeMessageUtilsStore = () =>
|
3175
|
+
import { create as create14 } from "zustand";
|
3176
|
+
var makeMessageUtilsStore = () => create14((set) => ({
|
3111
3177
|
isCopied: false,
|
3112
3178
|
setIsCopied: (value) => {
|
3113
3179
|
set({ isCopied: value });
|
@@ -3141,8 +3207,8 @@ var getMessageState = (messages, getBranches, useMessage, messageIndex) => {
|
|
3141
3207
|
};
|
3142
3208
|
var useMessageContext2 = (messageIndex) => {
|
3143
3209
|
const { useThreadMessages, useThreadActions } = useThreadContext();
|
3144
|
-
const [context] =
|
3145
|
-
const useMessage =
|
3210
|
+
const [context] = useState11(() => {
|
3211
|
+
const useMessage = create15(
|
3146
3212
|
() => getMessageState(
|
3147
3213
|
useThreadMessages.getState(),
|
3148
3214
|
useThreadActions.getState().getBranches,
|
@@ -4030,6 +4096,7 @@ export {
|
|
4030
4096
|
useContentPartDisplay,
|
4031
4097
|
useContentPartImage,
|
4032
4098
|
useContentPartText,
|
4099
|
+
useDangerousInBrowserRuntime,
|
4033
4100
|
useEdgeRuntime,
|
4034
4101
|
useExternalStoreRuntime,
|
4035
4102
|
useLocalRuntime,
|