@assistant-ui/react 0.7.68 → 0.7.70
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/api/MessageRuntime.d.ts +2 -1
- package/dist/api/MessageRuntime.d.ts.map +1 -1
- package/dist/api/MessageRuntime.js +9 -2
- package/dist/api/MessageRuntime.js.map +1 -1
- package/dist/api/MessageRuntime.mjs +9 -2
- package/dist/api/MessageRuntime.mjs.map +1 -1
- package/dist/context/providers/ThreadRuntimeProvider.d.ts.map +1 -1
- package/dist/context/providers/ThreadRuntimeProvider.js +3 -5
- package/dist/context/providers/ThreadRuntimeProvider.js.map +1 -1
- package/dist/context/providers/ThreadRuntimeProvider.mjs +3 -5
- package/dist/context/providers/ThreadRuntimeProvider.mjs.map +1 -1
- package/dist/context/providers/ThreadViewportProvider.d.ts +3 -0
- package/dist/context/providers/ThreadViewportProvider.d.ts.map +1 -0
- package/dist/context/providers/ThreadViewportProvider.js +63 -0
- package/dist/context/providers/ThreadViewportProvider.js.map +1 -0
- package/dist/context/providers/ThreadViewportProvider.mjs +42 -0
- package/dist/context/providers/ThreadViewportProvider.mjs.map +1 -0
- package/dist/context/react/ThreadContext.d.ts +0 -18
- package/dist/context/react/ThreadContext.d.ts.map +1 -1
- package/dist/context/react/ThreadContext.js +2 -11
- package/dist/context/react/ThreadContext.js.map +1 -1
- package/dist/context/react/ThreadContext.mjs +1 -8
- package/dist/context/react/ThreadContext.mjs.map +1 -1
- package/dist/context/react/ThreadViewportContext.d.ts +24 -0
- package/dist/context/react/ThreadViewportContext.d.ts.map +1 -0
- package/dist/context/react/ThreadViewportContext.js +44 -0
- package/dist/context/react/ThreadViewportContext.js.map +1 -0
- package/dist/context/react/ThreadViewportContext.mjs +18 -0
- package/dist/context/react/ThreadViewportContext.mjs.map +1 -0
- package/dist/context/react/index.d.ts +2 -1
- package/dist/context/react/index.d.ts.map +1 -1
- package/dist/context/react/index.js +3 -2
- package/dist/context/react/index.js.map +1 -1
- package/dist/context/react/index.mjs +4 -2
- package/dist/context/react/index.mjs.map +1 -1
- package/dist/context/stores/ThreadViewport.d.ts.map +1 -1
- package/dist/context/stores/ThreadViewport.js +1 -0
- package/dist/context/stores/ThreadViewport.js.map +1 -1
- package/dist/context/stores/ThreadViewport.mjs +2 -0
- package/dist/context/stores/ThreadViewport.mjs.map +1 -1
- package/dist/model-context/ModelContextTypes.d.ts +3 -0
- package/dist/model-context/ModelContextTypes.d.ts.map +1 -1
- package/dist/model-context/ModelContextTypes.js.map +1 -1
- package/dist/model-context/ModelContextTypes.mjs.map +1 -1
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/primitives/index.js +5 -2
- package/dist/primitives/index.js.map +1 -1
- package/dist/primitives/index.mjs +3 -1
- package/dist/primitives/index.mjs.map +1 -1
- package/dist/primitives/thread/ThreadScrollToBottom.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadScrollToBottom.js +3 -4
- package/dist/primitives/thread/ThreadScrollToBottom.js.map +1 -1
- package/dist/primitives/thread/ThreadScrollToBottom.mjs +1 -2
- package/dist/primitives/thread/ThreadScrollToBottom.mjs.map +1 -1
- package/dist/primitives/thread/ThreadSuggestion.d.ts +2 -2
- package/dist/primitives/thread/ThreadSuggestion.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadSuggestion.js +0 -1
- package/dist/primitives/thread/ThreadSuggestion.js.map +1 -1
- package/dist/primitives/thread/ThreadSuggestion.mjs +0 -1
- package/dist/primitives/thread/ThreadSuggestion.mjs.map +1 -1
- package/dist/primitives/thread/ThreadViewport.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadViewport.js +5 -1
- package/dist/primitives/thread/ThreadViewport.js.map +1 -1
- package/dist/primitives/thread/ThreadViewport.mjs +5 -1
- package/dist/primitives/thread/ThreadViewport.mjs.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.d.ts.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.js +2 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.js.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.mjs +2 -4
- package/dist/primitives/thread/useThreadViewportAutoScroll.mjs.map +1 -1
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.d.ts +1 -1
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js +1 -0
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.mjs +1 -0
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/edge/streams/toolResultStream.d.ts.map +1 -1
- package/dist/runtimes/edge/streams/toolResultStream.js +13 -15
- package/dist/runtimes/edge/streams/toolResultStream.js.map +1 -1
- package/dist/runtimes/edge/streams/toolResultStream.mjs +13 -15
- package/dist/runtimes/edge/streams/toolResultStream.mjs.map +1 -1
- package/dist/styles/tailwindcss/thread.css +5 -5
- package/dist/styles/tailwindcss/thread.css.json +5 -5
- package/dist/utils/hooks/useOnScrollToBottom.js +2 -2
- package/dist/utils/hooks/useOnScrollToBottom.js.map +1 -1
- package/dist/utils/hooks/useOnScrollToBottom.mjs +1 -1
- package/dist/utils/hooks/useOnScrollToBottom.mjs.map +1 -1
- package/package.json +3 -3
- package/src/api/MessageRuntime.ts +14 -5
- package/src/context/providers/ThreadRuntimeProvider.tsx +4 -5
- package/src/context/providers/ThreadViewportProvider.tsx +49 -0
- package/src/context/react/ThreadContext.ts +0 -8
- package/src/context/react/ThreadViewportContext.ts +23 -0
- package/src/context/react/index.ts +4 -1
- package/src/context/stores/ThreadViewport.tsx +2 -0
- package/src/model-context/ModelContextTypes.ts +7 -0
- package/src/primitives/index.ts +1 -0
- package/src/primitives/thread/ThreadScrollToBottom.tsx +1 -2
- package/src/primitives/thread/ThreadSuggestion.tsx +1 -2
- package/src/primitives/thread/ThreadViewport.tsx +13 -1
- package/src/primitives/thread/useThreadViewportAutoScroll.tsx +2 -4
- package/src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx +4 -1
- package/src/runtimes/edge/streams/toolResultStream.ts +20 -18
- package/src/styles/tailwindcss/thread.css +5 -5
- package/src/utils/hooks/useOnScrollToBottom.tsx +1 -1
|
@@ -31,11 +31,12 @@ var import_useOnResizeContent = require("../../utils/hooks/useOnResizeContent.js
|
|
|
31
31
|
var import_useOnScrollToBottom = require("../../utils/hooks/useOnScrollToBottom.js");
|
|
32
32
|
var import_useManagedRef = require("../../utils/hooks/useManagedRef.js");
|
|
33
33
|
var import_ReadonlyStore = require("../../context/ReadonlyStore.js");
|
|
34
|
+
var import_ThreadViewportContext = require("../../context/react/ThreadViewportContext.js");
|
|
34
35
|
var useThreadViewportAutoScroll = ({
|
|
35
36
|
autoScroll = true
|
|
36
37
|
}) => {
|
|
37
38
|
const divRef = (0, import_react.useRef)(null);
|
|
38
|
-
const threadViewportStore = (0,
|
|
39
|
+
const threadViewportStore = (0, import_ThreadViewportContext.useThreadViewportStore)();
|
|
39
40
|
const lastScrollTop = (0, import_react.useRef)(0);
|
|
40
41
|
const isScrollingToBottomRef = (0, import_react.useRef)(false);
|
|
41
42
|
const scrollToBottom = (behavior) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/primitives/thread/useThreadViewportAutoScroll.tsx"],"sourcesContent":["\"use client\";\n\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { RefCallback, useEffect, useRef } from \"react\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/primitives/thread/useThreadViewportAutoScroll.tsx"],"sourcesContent":["\"use client\";\n\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { RefCallback, useEffect, useRef } from \"react\";\nimport { useThreadRuntime } from \"../../context/react/ThreadContext\";\nimport { useOnResizeContent } from \"../../utils/hooks/useOnResizeContent\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\nimport { useManagedRef } from \"../../utils/hooks/useManagedRef\";\nimport { writableStore } from \"../../context/ReadonlyStore\";\nimport { useThreadViewportStore } from \"../../context/react/ThreadViewportContext\";\n\nexport namespace useThreadViewportAutoScroll {\n export type Options = {\n autoScroll?: boolean | undefined;\n };\n}\n\nexport const useThreadViewportAutoScroll = <TElement extends HTMLElement>({\n autoScroll = true,\n}: useThreadViewportAutoScroll.Options): RefCallback<TElement> => {\n const divRef = useRef<TElement>(null);\n\n const threadViewportStore = useThreadViewportStore();\n\n const lastScrollTop = useRef<number>(0);\n\n // bug: when ScrollToBottom's button changes its disabled state, the scroll stops\n // fix: delay the state change until the scroll is done\n const isScrollingToBottomRef = useRef(false);\n\n const scrollToBottom = (behavior: ScrollBehavior) => {\n const div = divRef.current;\n if (!div || !autoScroll) return;\n\n isScrollingToBottomRef.current = true;\n div.scrollTo({ top: div.scrollHeight, behavior });\n };\n\n const handleScroll = () => {\n const div = divRef.current;\n if (!div) return;\n\n const isAtBottom = threadViewportStore.getState().isAtBottom;\n const newIsAtBottom =\n div.scrollHeight - div.scrollTop <= div.clientHeight + 1; // TODO figure out why +1 is needed\n\n if (!newIsAtBottom && lastScrollTop.current < div.scrollTop) {\n // ignore scroll down\n } else {\n if (newIsAtBottom) {\n isScrollingToBottomRef.current = false;\n }\n\n if (newIsAtBottom !== isAtBottom) {\n writableStore(threadViewportStore).setState({\n isAtBottom: newIsAtBottom,\n });\n }\n }\n\n lastScrollTop.current = div.scrollTop;\n };\n\n const resizeRef = useOnResizeContent(() => {\n if (\n isScrollingToBottomRef.current ||\n threadViewportStore.getState().isAtBottom\n ) {\n scrollToBottom(\"instant\");\n }\n\n handleScroll();\n });\n\n const scrollRef = useManagedRef<HTMLElement>((el) => {\n el.addEventListener(\"scroll\", handleScroll);\n return () => {\n el.removeEventListener(\"scroll\", handleScroll);\n };\n });\n\n useOnScrollToBottom(() => {\n scrollToBottom(\"auto\");\n });\n\n // autoscroll on run start\n const threadRuntime = useThreadRuntime();\n useEffect(() => {\n return threadRuntime.unstable_on(\"run-start\", () => scrollToBottom(\"auto\"));\n }, []);\n\n const autoScrollRef = useComposedRefs<TElement>(resizeRef, scrollRef, divRef);\n return autoScrollRef;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,gCAAgC;AAChC,mBAA+C;AAC/C,2BAAiC;AACjC,gCAAmC;AACnC,iCAAoC;AACpC,2BAA8B;AAC9B,2BAA8B;AAC9B,mCAAuC;AAQhC,IAAM,8BAA8B,CAA+B;AAAA,EACxE,aAAa;AACf,MAAkE;AAChE,QAAM,aAAS,qBAAiB,IAAI;AAEpC,QAAM,0BAAsB,qDAAuB;AAEnD,QAAM,oBAAgB,qBAAe,CAAC;AAItC,QAAM,6BAAyB,qBAAO,KAAK;AAE3C,QAAM,iBAAiB,CAAC,aAA6B;AACnD,UAAM,MAAM,OAAO;AACnB,QAAI,CAAC,OAAO,CAAC,WAAY;AAEzB,2BAAuB,UAAU;AACjC,QAAI,SAAS,EAAE,KAAK,IAAI,cAAc,SAAS,CAAC;AAAA,EAClD;AAEA,QAAM,eAAe,MAAM;AACzB,UAAM,MAAM,OAAO;AACnB,QAAI,CAAC,IAAK;AAEV,UAAM,aAAa,oBAAoB,SAAS,EAAE;AAClD,UAAM,gBACJ,IAAI,eAAe,IAAI,aAAa,IAAI,eAAe;AAEzD,QAAI,CAAC,iBAAiB,cAAc,UAAU,IAAI,WAAW;AAAA,IAE7D,OAAO;AACL,UAAI,eAAe;AACjB,+BAAuB,UAAU;AAAA,MACnC;AAEA,UAAI,kBAAkB,YAAY;AAChC,gDAAc,mBAAmB,EAAE,SAAS;AAAA,UAC1C,YAAY;AAAA,QACd,CAAC;AAAA,MACH;AAAA,IACF;AAEA,kBAAc,UAAU,IAAI;AAAA,EAC9B;AAEA,QAAM,gBAAY,8CAAmB,MAAM;AACzC,QACE,uBAAuB,WACvB,oBAAoB,SAAS,EAAE,YAC/B;AACA,qBAAe,SAAS;AAAA,IAC1B;AAEA,iBAAa;AAAA,EACf,CAAC;AAED,QAAM,gBAAY,oCAA2B,CAAC,OAAO;AACnD,OAAG,iBAAiB,UAAU,YAAY;AAC1C,WAAO,MAAM;AACX,SAAG,oBAAoB,UAAU,YAAY;AAAA,IAC/C;AAAA,EACF,CAAC;AAED,sDAAoB,MAAM;AACxB,mBAAe,MAAM;AAAA,EACvB,CAAC;AAGD,QAAM,oBAAgB,uCAAiB;AACvC,8BAAU,MAAM;AACd,WAAO,cAAc,YAAY,aAAa,MAAM,eAAe,MAAM,CAAC;AAAA,EAC5E,GAAG,CAAC,CAAC;AAEL,QAAM,oBAAgB,2CAA0B,WAAW,WAAW,MAAM;AAC5E,SAAO;AACT;","names":[]}
|
|
@@ -3,14 +3,12 @@
|
|
|
3
3
|
// src/primitives/thread/useThreadViewportAutoScroll.tsx
|
|
4
4
|
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
5
5
|
import { useEffect, useRef } from "react";
|
|
6
|
-
import {
|
|
7
|
-
useThreadRuntime,
|
|
8
|
-
useThreadViewportStore
|
|
9
|
-
} from "../../context/react/ThreadContext.mjs";
|
|
6
|
+
import { useThreadRuntime } from "../../context/react/ThreadContext.mjs";
|
|
10
7
|
import { useOnResizeContent } from "../../utils/hooks/useOnResizeContent.mjs";
|
|
11
8
|
import { useOnScrollToBottom } from "../../utils/hooks/useOnScrollToBottom.mjs";
|
|
12
9
|
import { useManagedRef } from "../../utils/hooks/useManagedRef.mjs";
|
|
13
10
|
import { writableStore } from "../../context/ReadonlyStore.mjs";
|
|
11
|
+
import { useThreadViewportStore } from "../../context/react/ThreadViewportContext.mjs";
|
|
14
12
|
var useThreadViewportAutoScroll = ({
|
|
15
13
|
autoScroll = true
|
|
16
14
|
}) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/primitives/thread/useThreadViewportAutoScroll.tsx"],"sourcesContent":["\"use client\";\n\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { RefCallback, useEffect, useRef } from \"react\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/primitives/thread/useThreadViewportAutoScroll.tsx"],"sourcesContent":["\"use client\";\n\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { RefCallback, useEffect, useRef } from \"react\";\nimport { useThreadRuntime } from \"../../context/react/ThreadContext\";\nimport { useOnResizeContent } from \"../../utils/hooks/useOnResizeContent\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\nimport { useManagedRef } from \"../../utils/hooks/useManagedRef\";\nimport { writableStore } from \"../../context/ReadonlyStore\";\nimport { useThreadViewportStore } from \"../../context/react/ThreadViewportContext\";\n\nexport namespace useThreadViewportAutoScroll {\n export type Options = {\n autoScroll?: boolean | undefined;\n };\n}\n\nexport const useThreadViewportAutoScroll = <TElement extends HTMLElement>({\n autoScroll = true,\n}: useThreadViewportAutoScroll.Options): RefCallback<TElement> => {\n const divRef = useRef<TElement>(null);\n\n const threadViewportStore = useThreadViewportStore();\n\n const lastScrollTop = useRef<number>(0);\n\n // bug: when ScrollToBottom's button changes its disabled state, the scroll stops\n // fix: delay the state change until the scroll is done\n const isScrollingToBottomRef = useRef(false);\n\n const scrollToBottom = (behavior: ScrollBehavior) => {\n const div = divRef.current;\n if (!div || !autoScroll) return;\n\n isScrollingToBottomRef.current = true;\n div.scrollTo({ top: div.scrollHeight, behavior });\n };\n\n const handleScroll = () => {\n const div = divRef.current;\n if (!div) return;\n\n const isAtBottom = threadViewportStore.getState().isAtBottom;\n const newIsAtBottom =\n div.scrollHeight - div.scrollTop <= div.clientHeight + 1; // TODO figure out why +1 is needed\n\n if (!newIsAtBottom && lastScrollTop.current < div.scrollTop) {\n // ignore scroll down\n } else {\n if (newIsAtBottom) {\n isScrollingToBottomRef.current = false;\n }\n\n if (newIsAtBottom !== isAtBottom) {\n writableStore(threadViewportStore).setState({\n isAtBottom: newIsAtBottom,\n });\n }\n }\n\n lastScrollTop.current = div.scrollTop;\n };\n\n const resizeRef = useOnResizeContent(() => {\n if (\n isScrollingToBottomRef.current ||\n threadViewportStore.getState().isAtBottom\n ) {\n scrollToBottom(\"instant\");\n }\n\n handleScroll();\n });\n\n const scrollRef = useManagedRef<HTMLElement>((el) => {\n el.addEventListener(\"scroll\", handleScroll);\n return () => {\n el.removeEventListener(\"scroll\", handleScroll);\n };\n });\n\n useOnScrollToBottom(() => {\n scrollToBottom(\"auto\");\n });\n\n // autoscroll on run start\n const threadRuntime = useThreadRuntime();\n useEffect(() => {\n return threadRuntime.unstable_on(\"run-start\", () => scrollToBottom(\"auto\"));\n }, []);\n\n const autoScrollRef = useComposedRefs<TElement>(resizeRef, scrollRef, divRef);\n return autoScrollRef;\n};\n"],"mappings":";;;AAEA,SAAS,uBAAuB;AAChC,SAAsB,WAAW,cAAc;AAC/C,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AACnC,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,8BAA8B;AAQhC,IAAM,8BAA8B,CAA+B;AAAA,EACxE,aAAa;AACf,MAAkE;AAChE,QAAM,SAAS,OAAiB,IAAI;AAEpC,QAAM,sBAAsB,uBAAuB;AAEnD,QAAM,gBAAgB,OAAe,CAAC;AAItC,QAAM,yBAAyB,OAAO,KAAK;AAE3C,QAAM,iBAAiB,CAAC,aAA6B;AACnD,UAAM,MAAM,OAAO;AACnB,QAAI,CAAC,OAAO,CAAC,WAAY;AAEzB,2BAAuB,UAAU;AACjC,QAAI,SAAS,EAAE,KAAK,IAAI,cAAc,SAAS,CAAC;AAAA,EAClD;AAEA,QAAM,eAAe,MAAM;AACzB,UAAM,MAAM,OAAO;AACnB,QAAI,CAAC,IAAK;AAEV,UAAM,aAAa,oBAAoB,SAAS,EAAE;AAClD,UAAM,gBACJ,IAAI,eAAe,IAAI,aAAa,IAAI,eAAe;AAEzD,QAAI,CAAC,iBAAiB,cAAc,UAAU,IAAI,WAAW;AAAA,IAE7D,OAAO;AACL,UAAI,eAAe;AACjB,+BAAuB,UAAU;AAAA,MACnC;AAEA,UAAI,kBAAkB,YAAY;AAChC,sBAAc,mBAAmB,EAAE,SAAS;AAAA,UAC1C,YAAY;AAAA,QACd,CAAC;AAAA,MACH;AAAA,IACF;AAEA,kBAAc,UAAU,IAAI;AAAA,EAC9B;AAEA,QAAM,YAAY,mBAAmB,MAAM;AACzC,QACE,uBAAuB,WACvB,oBAAoB,SAAS,EAAE,YAC/B;AACA,qBAAe,SAAS;AAAA,IAC1B;AAEA,iBAAa;AAAA,EACf,CAAC;AAED,QAAM,YAAY,cAA2B,CAAC,OAAO;AACnD,OAAG,iBAAiB,UAAU,YAAY;AAC1C,WAAO,MAAM;AACX,SAAG,oBAAoB,UAAU,YAAY;AAAA,IAC/C;AAAA,EACF,CAAC;AAED,sBAAoB,MAAM;AACxB,mBAAe,MAAM;AAAA,EACvB,CAAC;AAGD,QAAM,gBAAgB,iBAAiB;AACvC,YAAU,MAAM;AACd,WAAO,cAAc,YAAY,aAAa,MAAM,eAAe,MAAM,CAAC;AAAA,EAC5E,GAAG,CAAC,CAAC;AAEL,QAAM,gBAAgB,gBAA0B,WAAW,WAAW,MAAM;AAC5E,SAAO;AACT;","names":[]}
|
|
@@ -11,7 +11,7 @@ export declare class DefaultEditComposerRuntimeCore extends BaseComposerRuntimeC
|
|
|
11
11
|
private _previousText;
|
|
12
12
|
private _parentId;
|
|
13
13
|
private _sourceId;
|
|
14
|
-
constructor(runtime:
|
|
14
|
+
constructor(runtime: ThreadRuntimeCore & {
|
|
15
15
|
adapters?: {
|
|
16
16
|
attachments?: AttachmentAdapter | undefined;
|
|
17
17
|
} | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultEditComposerRuntimeCore.d.ts","sourceRoot":"","sources":["../../../src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,qBAAa,8BAA+B,SAAQ,uBAAuB;IAcvE,OAAO,CAAC,OAAO;IAGf,OAAO,CAAC,eAAe;IAhBzB,IAAW,SAAS,YAEnB;IAED,SAAS,CAAC,oBAAoB;IAI9B,OAAO,CAAC,aAAa,CAAC;IACtB,OAAO,CAAC,aAAa,CAAC;IACtB,OAAO,CAAC,SAAS,CAAC;IAClB,OAAO,CAAC,SAAS,CAAC;gBAER,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"DefaultEditComposerRuntimeCore.d.ts","sourceRoot":"","sources":["../../../src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,qBAAa,8BAA+B,SAAQ,uBAAuB;IAcvE,OAAO,CAAC,OAAO;IAGf,OAAO,CAAC,eAAe;IAhBzB,IAAW,SAAS,YAEnB;IAED,SAAS,CAAC,oBAAoB;IAI9B,OAAO,CAAC,aAAa,CAAC;IACtB,OAAO,CAAC,aAAa,CAAC;IACtB,OAAO,CAAC,SAAS,CAAC;IAClB,OAAO,CAAC,SAAS,CAAC;gBAER,OAAO,EAAE,iBAAiB,GAAG;QACnC,QAAQ,CAAC,EAAE;YAAE,WAAW,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAA;SAAE,GAAG,SAAS,CAAC;KACxE,EACO,eAAe,EAAE,MAAM,IAAI,EACnC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,OAAO,EAAE,aAAa,CAAA;KAAE;IAmB/D,UAAU,CACrB,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,UAAU,GAAG,UAAU,CAAC;IAehD,YAAY;CAIpB"}
|
|
@@ -39,6 +39,7 @@ var DefaultEditComposerRuntimeCore = class extends import_BaseComposerRuntimeCor
|
|
|
39
39
|
this._nonTextParts = message.content.filter(
|
|
40
40
|
(part) => part.type !== "text" && part.type !== "ui"
|
|
41
41
|
);
|
|
42
|
+
this.setRunConfig({ ...runtime.composer.runConfig });
|
|
42
43
|
}
|
|
43
44
|
get canCancel() {
|
|
44
45
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx"],"sourcesContent":["import { AppendMessage, ThreadMessage } from \"../../types\";\nimport { getThreadMessageText } from \"../../utils/getThreadMessageText\";\nimport { AttachmentAdapter } from \"../adapters/attachment\";\nimport { ThreadRuntimeCore } from \"../core/ThreadRuntimeCore\";\nimport { BaseComposerRuntimeCore } from \"./BaseComposerRuntimeCore\";\n\nexport class DefaultEditComposerRuntimeCore extends BaseComposerRuntimeCore {\n public get canCancel() {\n return true;\n }\n\n protected getAttachmentAdapter() {\n return this.runtime.adapters?.attachments;\n }\n\n private _nonTextParts;\n private _previousText;\n private _parentId;\n private _sourceId;\n constructor(\n private runtime:
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx"],"sourcesContent":["import { AppendMessage, ThreadMessage } from \"../../types\";\nimport { getThreadMessageText } from \"../../utils/getThreadMessageText\";\nimport { AttachmentAdapter } from \"../adapters/attachment\";\nimport { ThreadRuntimeCore } from \"../core/ThreadRuntimeCore\";\nimport { BaseComposerRuntimeCore } from \"./BaseComposerRuntimeCore\";\n\nexport class DefaultEditComposerRuntimeCore extends BaseComposerRuntimeCore {\n public get canCancel() {\n return true;\n }\n\n protected getAttachmentAdapter() {\n return this.runtime.adapters?.attachments;\n }\n\n private _nonTextParts;\n private _previousText;\n private _parentId;\n private _sourceId;\n constructor(\n private runtime: ThreadRuntimeCore & {\n adapters?: { attachments?: AttachmentAdapter | undefined } | undefined;\n },\n private endEditCallback: () => void,\n { parentId, message }: { parentId: string | null; message: ThreadMessage },\n ) {\n super();\n this._parentId = parentId;\n this._sourceId = message.id;\n this._previousText = getThreadMessageText(message);\n this.setText(this._previousText);\n\n this.setRole(message.role);\n this.setAttachments(message.attachments ?? []);\n\n this._nonTextParts = message.content.filter(\n (part) => part.type !== \"text\" && part.type !== \"ui\",\n );\n\n // Use the runConfig from the regular (non-edit) composer as the initial runConfig for the edit composer\n this.setRunConfig({ ...runtime.composer.runConfig });\n }\n\n public async handleSend(\n message: Omit<AppendMessage, \"parentId\" | \"sourceId\">,\n ) {\n const text = getThreadMessageText(message as AppendMessage);\n if (text !== this._previousText) {\n this.runtime.append({\n ...message,\n content: [...message.content, ...this._nonTextParts] as any,\n parentId: this._parentId,\n sourceId: this._sourceId,\n });\n }\n\n this.handleCancel();\n }\n\n public handleCancel() {\n this.endEditCallback();\n this._notifySubscribers();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kCAAqC;AAGrC,qCAAwC;AAEjC,IAAM,iCAAN,cAA6C,uDAAwB;AAAA,EAa1E,YACU,SAGA,iBACR,EAAE,UAAU,QAAQ,GACpB;AACA,UAAM;AANE;AAGA;AAIR,SAAK,YAAY;AACjB,SAAK,YAAY,QAAQ;AACzB,SAAK,oBAAgB,kDAAqB,OAAO;AACjD,SAAK,QAAQ,KAAK,aAAa;AAE/B,SAAK,QAAQ,QAAQ,IAAI;AACzB,SAAK,eAAe,QAAQ,eAAe,CAAC,CAAC;AAE7C,SAAK,gBAAgB,QAAQ,QAAQ;AAAA,MACnC,CAAC,SAAS,KAAK,SAAS,UAAU,KAAK,SAAS;AAAA,IAClD;AAGA,SAAK,aAAa,EAAE,GAAG,QAAQ,SAAS,UAAU,CAAC;AAAA,EACrD;AAAA,EAlCA,IAAW,YAAY;AACrB,WAAO;AAAA,EACT;AAAA,EAEU,uBAAuB;AAC/B,WAAO,KAAK,QAAQ,UAAU;AAAA,EAChC;AAAA,EAEQ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAyBR,MAAa,WACX,SACA;AACA,UAAM,WAAO,kDAAqB,OAAwB;AAC1D,QAAI,SAAS,KAAK,eAAe;AAC/B,WAAK,QAAQ,OAAO;AAAA,QAClB,GAAG;AAAA,QACH,SAAS,CAAC,GAAG,QAAQ,SAAS,GAAG,KAAK,aAAa;AAAA,QACnD,UAAU,KAAK;AAAA,QACf,UAAU,KAAK;AAAA,MACjB,CAAC;AAAA,IACH;AAEA,SAAK,aAAa;AAAA,EACpB;AAAA,EAEO,eAAe;AACpB,SAAK,gBAAgB;AACrB,SAAK,mBAAmB;AAAA,EAC1B;AACF;","names":[]}
|
|
@@ -15,6 +15,7 @@ var DefaultEditComposerRuntimeCore = class extends BaseComposerRuntimeCore {
|
|
|
15
15
|
this._nonTextParts = message.content.filter(
|
|
16
16
|
(part) => part.type !== "text" && part.type !== "ui"
|
|
17
17
|
);
|
|
18
|
+
this.setRunConfig({ ...runtime.composer.runConfig });
|
|
18
19
|
}
|
|
19
20
|
get canCancel() {
|
|
20
21
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx"],"sourcesContent":["import { AppendMessage, ThreadMessage } from \"../../types\";\nimport { getThreadMessageText } from \"../../utils/getThreadMessageText\";\nimport { AttachmentAdapter } from \"../adapters/attachment\";\nimport { ThreadRuntimeCore } from \"../core/ThreadRuntimeCore\";\nimport { BaseComposerRuntimeCore } from \"./BaseComposerRuntimeCore\";\n\nexport class DefaultEditComposerRuntimeCore extends BaseComposerRuntimeCore {\n public get canCancel() {\n return true;\n }\n\n protected getAttachmentAdapter() {\n return this.runtime.adapters?.attachments;\n }\n\n private _nonTextParts;\n private _previousText;\n private _parentId;\n private _sourceId;\n constructor(\n private runtime:
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx"],"sourcesContent":["import { AppendMessage, ThreadMessage } from \"../../types\";\nimport { getThreadMessageText } from \"../../utils/getThreadMessageText\";\nimport { AttachmentAdapter } from \"../adapters/attachment\";\nimport { ThreadRuntimeCore } from \"../core/ThreadRuntimeCore\";\nimport { BaseComposerRuntimeCore } from \"./BaseComposerRuntimeCore\";\n\nexport class DefaultEditComposerRuntimeCore extends BaseComposerRuntimeCore {\n public get canCancel() {\n return true;\n }\n\n protected getAttachmentAdapter() {\n return this.runtime.adapters?.attachments;\n }\n\n private _nonTextParts;\n private _previousText;\n private _parentId;\n private _sourceId;\n constructor(\n private runtime: ThreadRuntimeCore & {\n adapters?: { attachments?: AttachmentAdapter | undefined } | undefined;\n },\n private endEditCallback: () => void,\n { parentId, message }: { parentId: string | null; message: ThreadMessage },\n ) {\n super();\n this._parentId = parentId;\n this._sourceId = message.id;\n this._previousText = getThreadMessageText(message);\n this.setText(this._previousText);\n\n this.setRole(message.role);\n this.setAttachments(message.attachments ?? []);\n\n this._nonTextParts = message.content.filter(\n (part) => part.type !== \"text\" && part.type !== \"ui\",\n );\n\n // Use the runConfig from the regular (non-edit) composer as the initial runConfig for the edit composer\n this.setRunConfig({ ...runtime.composer.runConfig });\n }\n\n public async handleSend(\n message: Omit<AppendMessage, \"parentId\" | \"sourceId\">,\n ) {\n const text = getThreadMessageText(message as AppendMessage);\n if (text !== this._previousText) {\n this.runtime.append({\n ...message,\n content: [...message.content, ...this._nonTextParts] as any,\n parentId: this._parentId,\n sourceId: this._sourceId,\n });\n }\n\n this.handleCancel();\n }\n\n public handleCancel() {\n this.endEditCallback();\n this._notifySubscribers();\n }\n}\n"],"mappings":";AACA,SAAS,4BAA4B;AAGrC,SAAS,+BAA+B;AAEjC,IAAM,iCAAN,cAA6C,wBAAwB;AAAA,EAa1E,YACU,SAGA,iBACR,EAAE,UAAU,QAAQ,GACpB;AACA,UAAM;AANE;AAGA;AAIR,SAAK,YAAY;AACjB,SAAK,YAAY,QAAQ;AACzB,SAAK,gBAAgB,qBAAqB,OAAO;AACjD,SAAK,QAAQ,KAAK,aAAa;AAE/B,SAAK,QAAQ,QAAQ,IAAI;AACzB,SAAK,eAAe,QAAQ,eAAe,CAAC,CAAC;AAE7C,SAAK,gBAAgB,QAAQ,QAAQ;AAAA,MACnC,CAAC,SAAS,KAAK,SAAS,UAAU,KAAK,SAAS;AAAA,IAClD;AAGA,SAAK,aAAa,EAAE,GAAG,QAAQ,SAAS,UAAU,CAAC;AAAA,EACrD;AAAA,EAlCA,IAAW,YAAY;AACrB,WAAO;AAAA,EACT;AAAA,EAEU,uBAAuB;AAC/B,WAAO,KAAK,QAAQ,UAAU;AAAA,EAChC;AAAA,EAEQ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAyBR,MAAa,WACX,SACA;AACA,UAAM,OAAO,qBAAqB,OAAwB;AAC1D,QAAI,SAAS,KAAK,eAAe;AAC/B,WAAK,QAAQ,OAAO;AAAA,QAClB,GAAG;AAAA,QACH,SAAS,CAAC,GAAG,QAAQ,SAAS,GAAG,KAAK,aAAa;AAAA,QACnD,UAAU,KAAK;AAAA,QACf,UAAU,KAAK;AAAA,MACjB,CAAC;AAAA,IACH;AAEA,SAAK,aAAa;AAAA,EACpB;AAAA,EAEO,eAAe;AACpB,SAAK,gBAAgB;AACrB,SAAK,mBAAmB;AAAA,EAC1B;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolResultStream.d.ts","sourceRoot":"","sources":["../../../../src/runtimes/edge/streams/toolResultStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,0CAA0C,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAG7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,MAAM,MAAM,oBAAoB,GAC5B,yBAAyB,GACzB;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,WAAW,EAAE,iBAAiB,EAAE,CAAC;CAClC,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,iBAAiB,EAAE,CAAC;CAC3B,GACD;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,YAAY,EAAE,UAAU,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GACD;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,YAAY,EACR,MAAM,GACN,QAAQ,GACR,gBAAgB,GAChB,YAAY,GACZ,OAAO,GACP,OAAO,GACP,SAAS,CAAC;IACd,KAAK,EAAE;QACL,YAAY,EAAE,MAAM,CAAC;QACrB,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;IACF,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEN,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,SAAS,EACvC,WAAW,EAAE,WAAW,+
|
|
1
|
+
{"version":3,"file":"toolResultStream.d.ts","sourceRoot":"","sources":["../../../../src/runtimes/edge/streams/toolResultStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,0CAA0C,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAG7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,MAAM,MAAM,oBAAoB,GAC5B,yBAAyB,GACzB;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,WAAW,EAAE,iBAAiB,EAAE,CAAC;CAClC,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,iBAAiB,EAAE,CAAC;CAC3B,GACD;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,YAAY,EAAE,UAAU,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GACD;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,YAAY,EACR,MAAM,GACN,QAAQ,GACR,gBAAgB,GAChB,YAAY,GACZ,OAAO,GACP,OAAO,GACP,SAAS,CAAC;IACd,KAAK,EAAE;QACL,YAAY,EAAE,MAAM,CAAC;QACrB,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;IACF,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEN,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,SAAS,EACvC,WAAW,EAAE,WAAW,+DA4GzB"}
|
|
@@ -60,26 +60,24 @@ function toolResultStream(tools, abortSignal) {
|
|
|
60
60
|
});
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
|
-
if (tool.parameters instanceof import_zod.z.ZodType) {
|
|
64
|
-
const result = tool.parameters.safeParse(args);
|
|
65
|
-
if (!result.success) {
|
|
66
|
-
controller.enqueue({
|
|
67
|
-
type: "tool-result",
|
|
68
|
-
toolCallType,
|
|
69
|
-
toolCallId,
|
|
70
|
-
toolName,
|
|
71
|
-
result: "Function parameter validation failed. " + JSON.stringify(result.error.issues),
|
|
72
|
-
isError: true
|
|
73
|
-
});
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
63
|
toolCallExecutions.set(
|
|
78
64
|
toolCallId,
|
|
79
65
|
(async () => {
|
|
80
66
|
if (!tool.execute) return;
|
|
67
|
+
let executeFn = tool.execute;
|
|
68
|
+
if (tool.parameters instanceof import_zod.z.ZodType) {
|
|
69
|
+
const result = tool.parameters.safeParse(args);
|
|
70
|
+
if (!result.success) {
|
|
71
|
+
executeFn = tool.experimental_onSchemaValidationError ?? (() => {
|
|
72
|
+
throw "Function parameter validation failed. " + JSON.stringify(result.error.issues);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
81
76
|
try {
|
|
82
|
-
const result = await
|
|
77
|
+
const result = await executeFn(args, {
|
|
78
|
+
toolCallId,
|
|
79
|
+
abortSignal
|
|
80
|
+
});
|
|
83
81
|
controller.enqueue({
|
|
84
82
|
type: "tool-result",
|
|
85
83
|
toolCallType,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/edge/streams/toolResultStream.ts"],"sourcesContent":["import { Tool } from \"../../../model-context/ModelContextTypes\";\nimport { LanguageModelV1StreamPart } from \"@ai-sdk/provider\";\nimport { z } from \"zod\";\nimport sjson from \"secure-json-parse\";\nimport { ReadonlyJSONValue } from \"../../../utils/json/json-value\";\n\nexport type ToolResultStreamPart =\n | LanguageModelV1StreamPart\n | {\n type: \"annotations\";\n annotations: ReadonlyJSONValue[];\n }\n | {\n type: \"data\";\n data: ReadonlyJSONValue[];\n }\n | {\n type: \"tool-result\";\n toolCallType: \"function\";\n toolCallId: string;\n toolName: string;\n result: unknown;\n isError?: boolean;\n }\n | {\n type: \"step-finish\";\n finishReason:\n | \"stop\"\n | \"length\"\n | \"content-filter\"\n | \"tool-calls\"\n | \"error\"\n | \"other\"\n | \"unknown\";\n usage: {\n promptTokens: number;\n completionTokens: number;\n };\n isContinued: boolean;\n };\n\nexport function toolResultStream(\n tools: Record<string, Tool> | undefined,\n abortSignal: AbortSignal,\n) {\n const toolCallExecutions = new Map<string, Promise<any>>();\n\n return new TransformStream<ToolResultStreamPart, ToolResultStreamPart>({\n transform(chunk, controller) {\n // forward everything\n controller.enqueue(chunk);\n\n // handle tool calls\n const chunkType = chunk.type;\n switch (chunkType) {\n case \"tool-call\": {\n const { toolCallId, toolCallType, toolName, args: argsText } = chunk;\n const tool = tools?.[toolName];\n if (!tool || !tool.execute) return;\n\n let args;\n try {\n args = sjson.parse(argsText);\n } catch (e) {\n controller.enqueue({\n type: \"tool-result\",\n toolCallType,\n toolCallId,\n toolName,\n result:\n \"Function parameter parsing failed. \" +\n JSON.stringify((e as Error).message),\n isError: true,\n });\n return;\n }\n\n if (tool.parameters instanceof z.ZodType) {\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/edge/streams/toolResultStream.ts"],"sourcesContent":["import { Tool } from \"../../../model-context/ModelContextTypes\";\nimport { LanguageModelV1StreamPart } from \"@ai-sdk/provider\";\nimport { z } from \"zod\";\nimport sjson from \"secure-json-parse\";\nimport { ReadonlyJSONValue } from \"../../../utils/json/json-value\";\n\nexport type ToolResultStreamPart =\n | LanguageModelV1StreamPart\n | {\n type: \"annotations\";\n annotations: ReadonlyJSONValue[];\n }\n | {\n type: \"data\";\n data: ReadonlyJSONValue[];\n }\n | {\n type: \"tool-result\";\n toolCallType: \"function\";\n toolCallId: string;\n toolName: string;\n result: unknown;\n isError?: boolean;\n }\n | {\n type: \"step-finish\";\n finishReason:\n | \"stop\"\n | \"length\"\n | \"content-filter\"\n | \"tool-calls\"\n | \"error\"\n | \"other\"\n | \"unknown\";\n usage: {\n promptTokens: number;\n completionTokens: number;\n };\n isContinued: boolean;\n };\n\nexport function toolResultStream(\n tools: Record<string, Tool> | undefined,\n abortSignal: AbortSignal,\n) {\n const toolCallExecutions = new Map<string, Promise<any>>();\n\n return new TransformStream<ToolResultStreamPart, ToolResultStreamPart>({\n transform(chunk, controller) {\n // forward everything\n controller.enqueue(chunk);\n\n // handle tool calls\n const chunkType = chunk.type;\n switch (chunkType) {\n case \"tool-call\": {\n const { toolCallId, toolCallType, toolName, args: argsText } = chunk;\n const tool = tools?.[toolName];\n if (!tool || !tool.execute) return;\n\n let args;\n try {\n args = sjson.parse(argsText);\n } catch (e) {\n controller.enqueue({\n type: \"tool-result\",\n toolCallType,\n toolCallId,\n toolName,\n result:\n \"Function parameter parsing failed. \" +\n JSON.stringify((e as Error).message),\n isError: true,\n });\n return;\n }\n\n toolCallExecutions.set(\n toolCallId,\n (async () => {\n if (!tool.execute) return;\n\n let executeFn = tool.execute;\n\n if (tool.parameters instanceof z.ZodType) {\n const result = tool.parameters.safeParse(args);\n if (!result.success) {\n executeFn =\n tool.experimental_onSchemaValidationError ??\n (() => {\n throw (\n \"Function parameter validation failed. \" +\n JSON.stringify(result.error.issues)\n );\n });\n }\n }\n\n try {\n const result = await executeFn(args, {\n toolCallId,\n abortSignal,\n });\n\n controller.enqueue({\n type: \"tool-result\",\n toolCallType,\n toolCallId,\n toolName,\n result,\n });\n } catch (error) {\n controller.enqueue({\n type: \"tool-result\",\n toolCallType,\n toolCallId,\n toolName,\n result: \"Error: \" + error,\n isError: true,\n });\n } finally {\n toolCallExecutions.delete(toolCallId);\n }\n })(),\n );\n break;\n }\n\n // ignore other parts\n case \"text-delta\":\n case \"tool-call-delta\":\n case \"tool-result\":\n case \"step-finish\":\n case \"finish\":\n case \"error\":\n case \"response-metadata\":\n case \"annotations\":\n case \"data\":\n break;\n\n default: {\n const unhandledType: never = chunkType;\n throw new Error(`Unhandled chunk type: ${unhandledType}`);\n }\n }\n },\n\n async flush() {\n await Promise.all(toolCallExecutions.values());\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iBAAkB;AAClB,+BAAkB;AAsCX,SAAS,iBACd,OACA,aACA;AACA,QAAM,qBAAqB,oBAAI,IAA0B;AAEzD,SAAO,IAAI,gBAA4D;AAAA,IACrE,UAAU,OAAO,YAAY;AAE3B,iBAAW,QAAQ,KAAK;AAGxB,YAAM,YAAY,MAAM;AACxB,cAAQ,WAAW;AAAA,QACjB,KAAK,aAAa;AAChB,gBAAM,EAAE,YAAY,cAAc,UAAU,MAAM,SAAS,IAAI;AAC/D,gBAAM,OAAO,QAAQ,QAAQ;AAC7B,cAAI,CAAC,QAAQ,CAAC,KAAK,QAAS;AAE5B,cAAI;AACJ,cAAI;AACF,mBAAO,yBAAAA,QAAM,MAAM,QAAQ;AAAA,UAC7B,SAAS,GAAG;AACV,uBAAW,QAAQ;AAAA,cACjB,MAAM;AAAA,cACN;AAAA,cACA;AAAA,cACA;AAAA,cACA,QACE,wCACA,KAAK,UAAW,EAAY,OAAO;AAAA,cACrC,SAAS;AAAA,YACX,CAAC;AACD;AAAA,UACF;AAEA,6BAAmB;AAAA,YACjB;AAAA,aACC,YAAY;AACX,kBAAI,CAAC,KAAK,QAAS;AAEnB,kBAAI,YAAY,KAAK;AAErB,kBAAI,KAAK,sBAAsB,aAAE,SAAS;AACxC,sBAAM,SAAS,KAAK,WAAW,UAAU,IAAI;AAC7C,oBAAI,CAAC,OAAO,SAAS;AACnB,8BACE,KAAK,yCACJ,MAAM;AACL,0BACE,2CACA,KAAK,UAAU,OAAO,MAAM,MAAM;AAAA,kBAEtC;AAAA,gBACJ;AAAA,cACF;AAEA,kBAAI;AACF,sBAAM,SAAS,MAAM,UAAU,MAAM;AAAA,kBACnC;AAAA,kBACA;AAAA,gBACF,CAAC;AAED,2BAAW,QAAQ;AAAA,kBACjB,MAAM;AAAA,kBACN;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA;AAAA,gBACF,CAAC;AAAA,cACH,SAAS,OAAO;AACd,2BAAW,QAAQ;AAAA,kBACjB,MAAM;AAAA,kBACN;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA,QAAQ,YAAY;AAAA,kBACpB,SAAS;AAAA,gBACX,CAAC;AAAA,cACH,UAAE;AACA,mCAAmB,OAAO,UAAU;AAAA,cACtC;AAAA,YACF,GAAG;AAAA,UACL;AACA;AAAA,QACF;AAAA;AAAA,QAGA,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AACH;AAAA,QAEF,SAAS;AACP,gBAAM,gBAAuB;AAC7B,gBAAM,IAAI,MAAM,yBAAyB,aAAa,EAAE;AAAA,QAC1D;AAAA,MACF;AAAA,IACF;AAAA,IAEA,MAAM,QAAQ;AACZ,YAAM,QAAQ,IAAI,mBAAmB,OAAO,CAAC;AAAA,IAC/C;AAAA,EACF,CAAC;AACH;","names":["sjson"]}
|
|
@@ -26,26 +26,24 @@ function toolResultStream(tools, abortSignal) {
|
|
|
26
26
|
});
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
if (tool.parameters instanceof z.ZodType) {
|
|
30
|
-
const result = tool.parameters.safeParse(args);
|
|
31
|
-
if (!result.success) {
|
|
32
|
-
controller.enqueue({
|
|
33
|
-
type: "tool-result",
|
|
34
|
-
toolCallType,
|
|
35
|
-
toolCallId,
|
|
36
|
-
toolName,
|
|
37
|
-
result: "Function parameter validation failed. " + JSON.stringify(result.error.issues),
|
|
38
|
-
isError: true
|
|
39
|
-
});
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
29
|
toolCallExecutions.set(
|
|
44
30
|
toolCallId,
|
|
45
31
|
(async () => {
|
|
46
32
|
if (!tool.execute) return;
|
|
33
|
+
let executeFn = tool.execute;
|
|
34
|
+
if (tool.parameters instanceof z.ZodType) {
|
|
35
|
+
const result = tool.parameters.safeParse(args);
|
|
36
|
+
if (!result.success) {
|
|
37
|
+
executeFn = tool.experimental_onSchemaValidationError ?? (() => {
|
|
38
|
+
throw "Function parameter validation failed. " + JSON.stringify(result.error.issues);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
47
42
|
try {
|
|
48
|
-
const result = await
|
|
43
|
+
const result = await executeFn(args, {
|
|
44
|
+
toolCallId,
|
|
45
|
+
abortSignal
|
|
46
|
+
});
|
|
49
47
|
controller.enqueue({
|
|
50
48
|
type: "tool-result",
|
|
51
49
|
toolCallType,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/edge/streams/toolResultStream.ts"],"sourcesContent":["import { Tool } from \"../../../model-context/ModelContextTypes\";\nimport { LanguageModelV1StreamPart } from \"@ai-sdk/provider\";\nimport { z } from \"zod\";\nimport sjson from \"secure-json-parse\";\nimport { ReadonlyJSONValue } from \"../../../utils/json/json-value\";\n\nexport type ToolResultStreamPart =\n | LanguageModelV1StreamPart\n | {\n type: \"annotations\";\n annotations: ReadonlyJSONValue[];\n }\n | {\n type: \"data\";\n data: ReadonlyJSONValue[];\n }\n | {\n type: \"tool-result\";\n toolCallType: \"function\";\n toolCallId: string;\n toolName: string;\n result: unknown;\n isError?: boolean;\n }\n | {\n type: \"step-finish\";\n finishReason:\n | \"stop\"\n | \"length\"\n | \"content-filter\"\n | \"tool-calls\"\n | \"error\"\n | \"other\"\n | \"unknown\";\n usage: {\n promptTokens: number;\n completionTokens: number;\n };\n isContinued: boolean;\n };\n\nexport function toolResultStream(\n tools: Record<string, Tool> | undefined,\n abortSignal: AbortSignal,\n) {\n const toolCallExecutions = new Map<string, Promise<any>>();\n\n return new TransformStream<ToolResultStreamPart, ToolResultStreamPart>({\n transform(chunk, controller) {\n // forward everything\n controller.enqueue(chunk);\n\n // handle tool calls\n const chunkType = chunk.type;\n switch (chunkType) {\n case \"tool-call\": {\n const { toolCallId, toolCallType, toolName, args: argsText } = chunk;\n const tool = tools?.[toolName];\n if (!tool || !tool.execute) return;\n\n let args;\n try {\n args = sjson.parse(argsText);\n } catch (e) {\n controller.enqueue({\n type: \"tool-result\",\n toolCallType,\n toolCallId,\n toolName,\n result:\n \"Function parameter parsing failed. \" +\n JSON.stringify((e as Error).message),\n isError: true,\n });\n return;\n }\n\n if (tool.parameters instanceof z.ZodType) {\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/edge/streams/toolResultStream.ts"],"sourcesContent":["import { Tool } from \"../../../model-context/ModelContextTypes\";\nimport { LanguageModelV1StreamPart } from \"@ai-sdk/provider\";\nimport { z } from \"zod\";\nimport sjson from \"secure-json-parse\";\nimport { ReadonlyJSONValue } from \"../../../utils/json/json-value\";\n\nexport type ToolResultStreamPart =\n | LanguageModelV1StreamPart\n | {\n type: \"annotations\";\n annotations: ReadonlyJSONValue[];\n }\n | {\n type: \"data\";\n data: ReadonlyJSONValue[];\n }\n | {\n type: \"tool-result\";\n toolCallType: \"function\";\n toolCallId: string;\n toolName: string;\n result: unknown;\n isError?: boolean;\n }\n | {\n type: \"step-finish\";\n finishReason:\n | \"stop\"\n | \"length\"\n | \"content-filter\"\n | \"tool-calls\"\n | \"error\"\n | \"other\"\n | \"unknown\";\n usage: {\n promptTokens: number;\n completionTokens: number;\n };\n isContinued: boolean;\n };\n\nexport function toolResultStream(\n tools: Record<string, Tool> | undefined,\n abortSignal: AbortSignal,\n) {\n const toolCallExecutions = new Map<string, Promise<any>>();\n\n return new TransformStream<ToolResultStreamPart, ToolResultStreamPart>({\n transform(chunk, controller) {\n // forward everything\n controller.enqueue(chunk);\n\n // handle tool calls\n const chunkType = chunk.type;\n switch (chunkType) {\n case \"tool-call\": {\n const { toolCallId, toolCallType, toolName, args: argsText } = chunk;\n const tool = tools?.[toolName];\n if (!tool || !tool.execute) return;\n\n let args;\n try {\n args = sjson.parse(argsText);\n } catch (e) {\n controller.enqueue({\n type: \"tool-result\",\n toolCallType,\n toolCallId,\n toolName,\n result:\n \"Function parameter parsing failed. \" +\n JSON.stringify((e as Error).message),\n isError: true,\n });\n return;\n }\n\n toolCallExecutions.set(\n toolCallId,\n (async () => {\n if (!tool.execute) return;\n\n let executeFn = tool.execute;\n\n if (tool.parameters instanceof z.ZodType) {\n const result = tool.parameters.safeParse(args);\n if (!result.success) {\n executeFn =\n tool.experimental_onSchemaValidationError ??\n (() => {\n throw (\n \"Function parameter validation failed. \" +\n JSON.stringify(result.error.issues)\n );\n });\n }\n }\n\n try {\n const result = await executeFn(args, {\n toolCallId,\n abortSignal,\n });\n\n controller.enqueue({\n type: \"tool-result\",\n toolCallType,\n toolCallId,\n toolName,\n result,\n });\n } catch (error) {\n controller.enqueue({\n type: \"tool-result\",\n toolCallType,\n toolCallId,\n toolName,\n result: \"Error: \" + error,\n isError: true,\n });\n } finally {\n toolCallExecutions.delete(toolCallId);\n }\n })(),\n );\n break;\n }\n\n // ignore other parts\n case \"text-delta\":\n case \"tool-call-delta\":\n case \"tool-result\":\n case \"step-finish\":\n case \"finish\":\n case \"error\":\n case \"response-metadata\":\n case \"annotations\":\n case \"data\":\n break;\n\n default: {\n const unhandledType: never = chunkType;\n throw new Error(`Unhandled chunk type: ${unhandledType}`);\n }\n }\n },\n\n async flush() {\n await Promise.all(toolCallExecutions.values());\n },\n });\n}\n"],"mappings":";AAEA,SAAS,SAAS;AAClB,OAAO,WAAW;AAsCX,SAAS,iBACd,OACA,aACA;AACA,QAAM,qBAAqB,oBAAI,IAA0B;AAEzD,SAAO,IAAI,gBAA4D;AAAA,IACrE,UAAU,OAAO,YAAY;AAE3B,iBAAW,QAAQ,KAAK;AAGxB,YAAM,YAAY,MAAM;AACxB,cAAQ,WAAW;AAAA,QACjB,KAAK,aAAa;AAChB,gBAAM,EAAE,YAAY,cAAc,UAAU,MAAM,SAAS,IAAI;AAC/D,gBAAM,OAAO,QAAQ,QAAQ;AAC7B,cAAI,CAAC,QAAQ,CAAC,KAAK,QAAS;AAE5B,cAAI;AACJ,cAAI;AACF,mBAAO,MAAM,MAAM,QAAQ;AAAA,UAC7B,SAAS,GAAG;AACV,uBAAW,QAAQ;AAAA,cACjB,MAAM;AAAA,cACN;AAAA,cACA;AAAA,cACA;AAAA,cACA,QACE,wCACA,KAAK,UAAW,EAAY,OAAO;AAAA,cACrC,SAAS;AAAA,YACX,CAAC;AACD;AAAA,UACF;AAEA,6BAAmB;AAAA,YACjB;AAAA,aACC,YAAY;AACX,kBAAI,CAAC,KAAK,QAAS;AAEnB,kBAAI,YAAY,KAAK;AAErB,kBAAI,KAAK,sBAAsB,EAAE,SAAS;AACxC,sBAAM,SAAS,KAAK,WAAW,UAAU,IAAI;AAC7C,oBAAI,CAAC,OAAO,SAAS;AACnB,8BACE,KAAK,yCACJ,MAAM;AACL,0BACE,2CACA,KAAK,UAAU,OAAO,MAAM,MAAM;AAAA,kBAEtC;AAAA,gBACJ;AAAA,cACF;AAEA,kBAAI;AACF,sBAAM,SAAS,MAAM,UAAU,MAAM;AAAA,kBACnC;AAAA,kBACA;AAAA,gBACF,CAAC;AAED,2BAAW,QAAQ;AAAA,kBACjB,MAAM;AAAA,kBACN;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA;AAAA,gBACF,CAAC;AAAA,cACH,SAAS,OAAO;AACd,2BAAW,QAAQ;AAAA,kBACjB,MAAM;AAAA,kBACN;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA,QAAQ,YAAY;AAAA,kBACpB,SAAS;AAAA,gBACX,CAAC;AAAA,cACH,UAAE;AACA,mCAAmB,OAAO,UAAU;AAAA,cACtC;AAAA,YACF,GAAG;AAAA,UACL;AACA;AAAA,QACF;AAAA;AAAA,QAGA,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AACH;AAAA,QAEF,SAAS;AACP,gBAAM,gBAAuB;AAC7B,gBAAM,IAAI,MAAM,yBAAyB,aAAa,EAAE;AAAA,QAC1D;AAAA,MACF;AAAA,IACF;AAAA,IAEA,MAAM,QAAQ;AACZ,YAAM,QAAQ,IAAI,mBAAmB,OAAO,CAAC;AAAA,IAC/C;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
.aui-thread-viewport-footer {
|
|
12
|
-
@apply max-w-aui-thread sticky bottom-0 mt-3 flex w-full flex-col items-center justify-end rounded-t-lg bg-inherit pb-4;
|
|
12
|
+
@apply max-w-[var(--aui-thread-max-width)] sticky bottom-0 mt-3 flex w-full flex-col items-center justify-end rounded-t-lg bg-inherit pb-4;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
.aui-thread-scroll-to-bottom {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
/* thread welcome */
|
|
28
28
|
|
|
29
29
|
.aui-thread-welcome-root {
|
|
30
|
-
@apply max-w-aui-thread flex w-full flex-grow flex-col;
|
|
30
|
+
@apply max-w-[var(--aui-thread-max-width)] flex w-full flex-grow flex-col;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
.aui-thread-welcome-center {
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
|
|
109
109
|
.aui-user-message-root {
|
|
110
110
|
@apply grid auto-rows-auto grid-cols-[minmax(72px,1fr)_auto] gap-y-2 [&>*]:col-start-2;
|
|
111
|
-
@apply max-w-aui-thread w-full py-4;
|
|
111
|
+
@apply max-w-[var(--aui-thread-max-width)] w-full py-4;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
:where(.aui-user-message-root) > .aui-user-action-bar-root {
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
/* edit composer */
|
|
147
147
|
|
|
148
148
|
.aui-edit-composer-root {
|
|
149
|
-
@apply bg-aui-muted max-w-aui-thread my-4 flex w-full flex-col gap-2 rounded-xl;
|
|
149
|
+
@apply bg-aui-muted max-w-[var(--aui-thread-max-width)] my-4 flex w-full flex-col gap-2 rounded-xl;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
.aui-edit-composer-input {
|
|
@@ -161,7 +161,7 @@
|
|
|
161
161
|
|
|
162
162
|
.aui-assistant-message-root {
|
|
163
163
|
@apply grid grid-cols-[auto_auto_1fr] grid-rows-[auto_1fr];
|
|
164
|
-
@apply max-w-aui-thread relative w-full py-4;
|
|
164
|
+
@apply max-w-[var(--aui-thread-max-width)] relative w-full py-4;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
:where(.aui-assistant-message-root) > .aui-avatar-root {
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"@apply bg-aui-background flex h-full flex-col items-center overflow-y-scroll scroll-smooth px-4 pt-8": {}
|
|
8
8
|
},
|
|
9
9
|
".aui-thread-viewport-footer": {
|
|
10
|
-
"@apply max-w-aui-thread sticky bottom-0 mt-3 flex w-full flex-col items-center justify-end rounded-t-lg bg-inherit pb-4": {}
|
|
10
|
+
"@apply max-w-[var(--aui-thread-max-width)] sticky bottom-0 mt-3 flex w-full flex-col items-center justify-end rounded-t-lg bg-inherit pb-4": {}
|
|
11
11
|
},
|
|
12
12
|
".aui-thread-scroll-to-bottom": {
|
|
13
13
|
"@apply absolute -top-8 rounded-full disabled:invisible": {}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@apply bg-aui-background hover:bg-aui-muted/80 rounded-full border px-3 py-1 text-sm transition-colors ease-in": {}
|
|
20
20
|
},
|
|
21
21
|
".aui-thread-welcome-root": {
|
|
22
|
-
"@apply max-w-aui-thread flex w-full flex-grow flex-col": {}
|
|
22
|
+
"@apply max-w-[var(--aui-thread-max-width)] flex w-full flex-grow flex-col": {}
|
|
23
23
|
},
|
|
24
24
|
".aui-thread-welcome-center": {
|
|
25
25
|
"@apply flex w-full flex-grow flex-col items-center justify-center": {}
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
},
|
|
75
75
|
".aui-user-message-root": {
|
|
76
76
|
"@apply grid auto-rows-auto grid-cols-[minmax(72px,1fr)_auto] gap-y-2 [&>*]:col-start-2": {},
|
|
77
|
-
"@apply max-w-aui-thread w-full py-4": {}
|
|
77
|
+
"@apply max-w-[var(--aui-thread-max-width)] w-full py-4": {}
|
|
78
78
|
},
|
|
79
79
|
":where(.aui-user-message-root) > .aui-user-action-bar-root": {
|
|
80
80
|
"@apply col-start-1 row-start-2 mr-3 mt-2.5": {}
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"@apply flex flex-col items-end": {}
|
|
101
101
|
},
|
|
102
102
|
".aui-edit-composer-root": {
|
|
103
|
-
"@apply bg-aui-muted max-w-aui-thread my-4 flex w-full flex-col gap-2 rounded-xl": {}
|
|
103
|
+
"@apply bg-aui-muted max-w-[var(--aui-thread-max-width)] my-4 flex w-full flex-col gap-2 rounded-xl": {}
|
|
104
104
|
},
|
|
105
105
|
".aui-edit-composer-input": {
|
|
106
106
|
"@apply text-aui-foreground flex h-8 w-full resize-none bg-transparent p-4 pb-0 outline-none": {}
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
},
|
|
111
111
|
".aui-assistant-message-root": {
|
|
112
112
|
"@apply grid grid-cols-[auto_auto_1fr] grid-rows-[auto_1fr]": {},
|
|
113
|
-
"@apply max-w-aui-thread relative w-full py-4": {}
|
|
113
|
+
"@apply max-w-[var(--aui-thread-max-width)] relative w-full py-4": {}
|
|
114
114
|
},
|
|
115
115
|
":where(.aui-assistant-message-root) > .aui-avatar-root": {
|
|
116
116
|
"@apply col-start-1 row-span-full row-start-1 mr-4": {}
|
|
@@ -26,10 +26,10 @@ __export(useOnScrollToBottom_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(useOnScrollToBottom_exports);
|
|
27
27
|
var import_react_use_callback_ref = require("@radix-ui/react-use-callback-ref");
|
|
28
28
|
var import_react = require("react");
|
|
29
|
-
var
|
|
29
|
+
var import_ThreadViewportContext = require("../../context/react/ThreadViewportContext.js");
|
|
30
30
|
var useOnScrollToBottom = (callback) => {
|
|
31
31
|
const callbackRef = (0, import_react_use_callback_ref.useCallbackRef)(callback);
|
|
32
|
-
const onScrollToBottom = (0,
|
|
32
|
+
const onScrollToBottom = (0, import_ThreadViewportContext.useThreadViewport)((vp) => vp.onScrollToBottom);
|
|
33
33
|
(0, import_react.useEffect)(() => {
|
|
34
34
|
return onScrollToBottom(callbackRef);
|
|
35
35
|
}, [onScrollToBottom, callbackRef]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/hooks/useOnScrollToBottom.tsx"],"sourcesContent":["\"use client\";\n\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { useEffect } from \"react\";\nimport { useThreadViewport } from \"../../context/react/
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/hooks/useOnScrollToBottom.tsx"],"sourcesContent":["\"use client\";\n\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { useEffect } from \"react\";\nimport { useThreadViewport } from \"../../context/react/ThreadViewportContext\";\n\nexport const useOnScrollToBottom = (callback: () => void) => {\n const callbackRef = useCallbackRef(callback);\n const onScrollToBottom = useThreadViewport((vp) => vp.onScrollToBottom);\n\n useEffect(() => {\n return onScrollToBottom(callbackRef);\n }, [onScrollToBottom, callbackRef]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oCAA+B;AAC/B,mBAA0B;AAC1B,mCAAkC;AAE3B,IAAM,sBAAsB,CAAC,aAAyB;AAC3D,QAAM,kBAAc,8CAAe,QAAQ;AAC3C,QAAM,uBAAmB,gDAAkB,CAAC,OAAO,GAAG,gBAAgB;AAEtE,8BAAU,MAAM;AACd,WAAO,iBAAiB,WAAW;AAAA,EACrC,GAAG,CAAC,kBAAkB,WAAW,CAAC;AACpC;","names":[]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// src/utils/hooks/useOnScrollToBottom.tsx
|
|
4
4
|
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
|
|
5
5
|
import { useEffect } from "react";
|
|
6
|
-
import { useThreadViewport } from "../../context/react/
|
|
6
|
+
import { useThreadViewport } from "../../context/react/ThreadViewportContext.mjs";
|
|
7
7
|
var useOnScrollToBottom = (callback) => {
|
|
8
8
|
const callbackRef = useCallbackRef(callback);
|
|
9
9
|
const onScrollToBottom = useThreadViewport((vp) => vp.onScrollToBottom);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/hooks/useOnScrollToBottom.tsx"],"sourcesContent":["\"use client\";\n\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { useEffect } from \"react\";\nimport { useThreadViewport } from \"../../context/react/
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/hooks/useOnScrollToBottom.tsx"],"sourcesContent":["\"use client\";\n\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { useEffect } from \"react\";\nimport { useThreadViewport } from \"../../context/react/ThreadViewportContext\";\n\nexport const useOnScrollToBottom = (callback: () => void) => {\n const callbackRef = useCallbackRef(callback);\n const onScrollToBottom = useThreadViewport((vp) => vp.onScrollToBottom);\n\n useEffect(() => {\n return onScrollToBottom(callbackRef);\n }, [onScrollToBottom, callbackRef]);\n};\n"],"mappings":";;;AAEA,SAAS,sBAAsB;AAC/B,SAAS,iBAAiB;AAC1B,SAAS,yBAAyB;AAE3B,IAAM,sBAAsB,CAAC,aAAyB;AAC3D,QAAM,cAAc,eAAe,QAAQ;AAC3C,QAAM,mBAAmB,kBAAkB,CAAC,OAAO,GAAG,gBAAgB;AAEtE,YAAU,MAAM;AACd,WAAO,iBAAiB,WAAW;AAAA,EACrC,GAAG,CAAC,kBAAkB,WAAW,CAAC;AACpC;","names":[]}
|
package/package.json
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"conversational-ui",
|
|
30
30
|
"conversational-ai"
|
|
31
31
|
],
|
|
32
|
-
"version": "0.7.
|
|
32
|
+
"version": "0.7.70",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"exports": {
|
|
35
35
|
".": {
|
|
@@ -117,9 +117,9 @@
|
|
|
117
117
|
"tailwindcss": "^3.4.17",
|
|
118
118
|
"tailwindcss-animate": "^1.0.7",
|
|
119
119
|
"tsx": "^4.19.2",
|
|
120
|
-
"@assistant-ui/
|
|
120
|
+
"@assistant-ui/tsbuildutils": "^0.0.1",
|
|
121
121
|
"@assistant-ui/tsconfig": "0.0.0",
|
|
122
|
-
"@assistant-ui/
|
|
122
|
+
"@assistant-ui/tailwindcss-transformer": "0.1.0"
|
|
123
123
|
},
|
|
124
124
|
"publishConfig": {
|
|
125
125
|
"access": "public",
|
|
@@ -150,10 +150,7 @@ export class MessageRuntimeImpl implements MessageRuntime {
|
|
|
150
150
|
ref: this.path.ref + `${this.path.ref}.composer`,
|
|
151
151
|
composerSource: "edit",
|
|
152
152
|
},
|
|
153
|
-
getState:
|
|
154
|
-
this._threadBinding
|
|
155
|
-
.getState()
|
|
156
|
-
.getEditComposer(this._core.getState().id),
|
|
153
|
+
getState: this._getEditComposerRuntimeCore,
|
|
157
154
|
subscribe: (callback) => this._threadBinding.subscribe(callback),
|
|
158
155
|
}),
|
|
159
156
|
() => this._threadBinding.getState().beginEdit(this._core.getState().id),
|
|
@@ -177,11 +174,23 @@ export class MessageRuntimeImpl implements MessageRuntime {
|
|
|
177
174
|
|
|
178
175
|
public readonly composer;
|
|
179
176
|
|
|
177
|
+
private _getEditComposerRuntimeCore = () => {
|
|
178
|
+
return this._threadBinding
|
|
179
|
+
.getState()
|
|
180
|
+
.getEditComposer(this._core.getState().id);
|
|
181
|
+
};
|
|
182
|
+
|
|
180
183
|
public getState() {
|
|
181
184
|
return this._core.getState();
|
|
182
185
|
}
|
|
183
186
|
|
|
184
|
-
public reload(
|
|
187
|
+
public reload(reloadConfig: ReloadConfig = {}) {
|
|
188
|
+
const editComposerRuntimeCore = this._getEditComposerRuntimeCore();
|
|
189
|
+
const composerRuntimeCore =
|
|
190
|
+
editComposerRuntimeCore ?? this._threadBinding.getState().composer;
|
|
191
|
+
const composer = editComposerRuntimeCore ?? composerRuntimeCore;
|
|
192
|
+
|
|
193
|
+
const { runConfig = composer.runConfig } = reloadConfig;
|
|
185
194
|
const state = this._core.getState();
|
|
186
195
|
if (state.role !== "assistant")
|
|
187
196
|
throw new Error("Can only reload assistant messages");
|
|
@@ -4,13 +4,13 @@ import type { FC, PropsWithChildren } from "react";
|
|
|
4
4
|
import { useEffect, useState } from "react";
|
|
5
5
|
import type { ThreadContextValue } from "../react/ThreadContext";
|
|
6
6
|
import { ThreadContext } from "../react/ThreadContext";
|
|
7
|
-
import { makeThreadViewportStore } from "../stores/ThreadViewport";
|
|
8
7
|
import { writableStore } from "../ReadonlyStore";
|
|
9
8
|
import { ThreadRuntime } from "../../api/ThreadRuntime";
|
|
10
9
|
import { create } from "zustand";
|
|
11
10
|
import { ThreadListItemRuntime } from "../../api/ThreadListItemRuntime";
|
|
12
11
|
import { ThreadListItemRuntimeProvider } from "./ThreadListItemRuntimeProvider";
|
|
13
12
|
import { ensureBinding } from "../react/utils/ensureBinding";
|
|
13
|
+
import { ThreadViewportProvider } from "./ThreadViewportProvider";
|
|
14
14
|
|
|
15
15
|
type ThreadProviderProps = {
|
|
16
16
|
listItemRuntime: ThreadListItemRuntime;
|
|
@@ -36,18 +36,17 @@ export const ThreadRuntimeProvider: FC<
|
|
|
36
36
|
const useThreadRuntime = useThreadRuntimeStore(runtime);
|
|
37
37
|
|
|
38
38
|
const [context] = useState<ThreadContextValue>(() => {
|
|
39
|
-
const useViewport = makeThreadViewportStore();
|
|
40
|
-
|
|
41
39
|
return {
|
|
42
40
|
useThreadRuntime,
|
|
43
|
-
useViewport,
|
|
44
41
|
};
|
|
45
42
|
});
|
|
46
43
|
|
|
47
44
|
return (
|
|
48
45
|
<ThreadListItemRuntimeProvider runtime={threadListItemRuntime}>
|
|
49
46
|
<ThreadContext.Provider value={context}>
|
|
50
|
-
{
|
|
47
|
+
{/* TODO temporarily allow accessing viewport state from outside the viewport */}
|
|
48
|
+
{/* TODO figure out if this behavior should be deprecated, since it is quite hacky */}
|
|
49
|
+
<ThreadViewportProvider>{children}</ThreadViewportProvider>
|
|
51
50
|
</ThreadContext.Provider>
|
|
52
51
|
</ThreadListItemRuntimeProvider>
|
|
53
52
|
);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { FC, PropsWithChildren } from "react";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
import { makeThreadViewportStore } from "../stores/ThreadViewport";
|
|
6
|
+
import {
|
|
7
|
+
ThreadViewportContext,
|
|
8
|
+
ThreadViewportContextValue,
|
|
9
|
+
useThreadViewportStore,
|
|
10
|
+
} from "../react/ThreadViewportContext";
|
|
11
|
+
import { writableStore } from "../ReadonlyStore";
|
|
12
|
+
|
|
13
|
+
const useThreadViewportStoreValue = () => {
|
|
14
|
+
const outerViewport = useThreadViewportStore({ optional: true });
|
|
15
|
+
const [store] = useState(() => makeThreadViewportStore());
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
return outerViewport?.getState().onScrollToBottom(() => {
|
|
19
|
+
store.getState().scrollToBottom();
|
|
20
|
+
});
|
|
21
|
+
}, [outerViewport, store]);
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!outerViewport) return;
|
|
25
|
+
return store.subscribe((state) => {
|
|
26
|
+
if (outerViewport.getState().isAtBottom !== state.isAtBottom) {
|
|
27
|
+
writableStore(outerViewport).setState({ isAtBottom: state.isAtBottom });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}, [store, outerViewport]);
|
|
31
|
+
|
|
32
|
+
return store;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const ThreadViewportProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
36
|
+
const useThreadViewport = useThreadViewportStoreValue();
|
|
37
|
+
|
|
38
|
+
const [context] = useState<ThreadViewportContextValue>(() => {
|
|
39
|
+
return {
|
|
40
|
+
useThreadViewport,
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<ThreadViewportContext.Provider value={context}>
|
|
46
|
+
{children}
|
|
47
|
+
</ThreadViewportContext.Provider>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { createContext, useEffect, useState } from "react";
|
|
4
|
-
import type { ThreadViewportState } from "../stores/ThreadViewport";
|
|
5
4
|
import { ReadonlyStore } from "../ReadonlyStore";
|
|
6
5
|
import { UseBoundStore } from "zustand";
|
|
7
6
|
import { createContextHook } from "./utils/createContextHook";
|
|
8
|
-
import { createContextStoreHook } from "./utils/createContextStoreHook";
|
|
9
7
|
import { ThreadRuntime } from "../../api/ThreadRuntime";
|
|
10
8
|
import { ModelContext } from "../../model-context";
|
|
11
9
|
import { createStateHookForRuntime } from "./utils/createStateHookForRuntime";
|
|
@@ -13,7 +11,6 @@ import { ThreadComposerRuntime } from "../../api";
|
|
|
13
11
|
|
|
14
12
|
export type ThreadContextValue = {
|
|
15
13
|
useThreadRuntime: UseBoundStore<ReadonlyStore<ThreadRuntime>>;
|
|
16
|
-
useViewport: UseBoundStore<ReadonlyStore<ThreadViewportState>>;
|
|
17
14
|
};
|
|
18
15
|
|
|
19
16
|
export const ThreadContext = createContext<ThreadContextValue | null>(null);
|
|
@@ -44,11 +41,6 @@ export const useThreadComposer = createStateHookForRuntime(
|
|
|
44
41
|
useThreadComposerRuntime,
|
|
45
42
|
);
|
|
46
43
|
|
|
47
|
-
export const {
|
|
48
|
-
useViewport: useThreadViewport,
|
|
49
|
-
useViewportStore: useThreadViewportStore,
|
|
50
|
-
} = createContextStoreHook(useThreadContext, "useViewport");
|
|
51
|
-
|
|
52
44
|
export function useThreadModelContext(options?: {
|
|
53
45
|
optional?: false | undefined;
|
|
54
46
|
}): ModelContext;
|