@dudousxd/nestjs-agent-react 0.18.0 → 0.19.0
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/README.md +28 -24
- package/dist/generative-ui-BhXFni8j.d.ts +167 -0
- package/dist/generative-ui-C53b3FoA.d.cts +167 -0
- package/dist/genui-json-render.cjs +521 -4
- package/dist/genui-json-render.cjs.map +1 -1
- package/dist/genui-json-render.d.cts +15 -2
- package/dist/genui-json-render.d.ts +15 -2
- package/dist/genui-json-render.js +518 -2
- package/dist/genui-json-render.js.map +1 -1
- package/dist/genui.cjs +120 -23
- package/dist/genui.cjs.map +1 -1
- package/dist/genui.d.cts +5 -52
- package/dist/genui.d.ts +5 -52
- package/dist/genui.js +106 -11
- package/dist/genui.js.map +1 -1
- package/dist/index.cjs +201 -174
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -7
- package/dist/index.d.ts +24 -7
- package/dist/index.js +26 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
- package/dist/types-DFD-soWU.d.cts +0 -86
- package/dist/types-DFD-soWU.d.ts +0 -86
package/dist/index.cjs
CHANGED
|
@@ -35,6 +35,7 @@ __export(src_exports, {
|
|
|
35
35
|
AgentChatTransport: () => AgentChatTransport,
|
|
36
36
|
AgentClient: () => AgentClient,
|
|
37
37
|
AgentHttpError: () => AgentHttpError,
|
|
38
|
+
AmbientRenderUiContext: () => AmbientRenderUiContext,
|
|
38
39
|
ChatInput: () => ChatInput,
|
|
39
40
|
DEFAULT_SPEECH_LANG: () => DEFAULT_SPEECH_LANG,
|
|
40
41
|
MessageItem: () => MessageItem,
|
|
@@ -81,6 +82,7 @@ __export(src_exports, {
|
|
|
81
82
|
toolCatalogFrom: () => toolCatalogFrom,
|
|
82
83
|
useAgentChat: () => useAgentChat,
|
|
83
84
|
useAgents: () => useAgents,
|
|
85
|
+
useAmbientRenderUi: () => useAmbientRenderUi,
|
|
84
86
|
useApprovalCountdown: () => useApprovalCountdown,
|
|
85
87
|
useAttachments: () => useAttachments,
|
|
86
88
|
useChatTranscript: () => useChatTranscript,
|
|
@@ -1850,11 +1852,29 @@ function backgroundRunsFromThread(messages) {
|
|
|
1850
1852
|
}
|
|
1851
1853
|
__name(backgroundRunsFromThread, "backgroundRunsFromThread");
|
|
1852
1854
|
|
|
1855
|
+
// src/components/ambient-ui.ts
|
|
1856
|
+
var import_react9 = require("react");
|
|
1857
|
+
function sharedContext(key) {
|
|
1858
|
+
const symbol = Symbol.for(key);
|
|
1859
|
+
const holder = globalThis;
|
|
1860
|
+
const existing = holder[symbol];
|
|
1861
|
+
if (existing !== void 0) return existing;
|
|
1862
|
+
const created = (0, import_react9.createContext)(null);
|
|
1863
|
+
holder[symbol] = created;
|
|
1864
|
+
return created;
|
|
1865
|
+
}
|
|
1866
|
+
__name(sharedContext, "sharedContext");
|
|
1867
|
+
var AmbientRenderUiContext = sharedContext("@dudousxd/nestjs-agent-react:ambient-render-ui");
|
|
1868
|
+
function useAmbientRenderUi() {
|
|
1869
|
+
return (0, import_react9.useContext)(AmbientRenderUiContext);
|
|
1870
|
+
}
|
|
1871
|
+
__name(useAmbientRenderUi, "useAmbientRenderUi");
|
|
1872
|
+
|
|
1853
1873
|
// src/components/chat-input.tsx
|
|
1854
|
-
var
|
|
1874
|
+
var import_react11 = __toESM(require("react"), 1);
|
|
1855
1875
|
|
|
1856
1876
|
// src/components/use-speech-recognition.ts
|
|
1857
|
-
var
|
|
1877
|
+
var import_react10 = require("react");
|
|
1858
1878
|
function getRecognitionCtor() {
|
|
1859
1879
|
if (typeof window === "undefined") return null;
|
|
1860
1880
|
const scope = window;
|
|
@@ -1862,15 +1882,15 @@ function getRecognitionCtor() {
|
|
|
1862
1882
|
}
|
|
1863
1883
|
__name(getRecognitionCtor, "getRecognitionCtor");
|
|
1864
1884
|
function useSpeechRecognition({ lang = "en-US", onFinalTranscript, onInterimTranscript }) {
|
|
1865
|
-
const recognitionRef = (0,
|
|
1866
|
-
const [isListening, setIsListening] = (0,
|
|
1867
|
-
const ctor = (0,
|
|
1885
|
+
const recognitionRef = (0, import_react10.useRef)(null);
|
|
1886
|
+
const [isListening, setIsListening] = (0, import_react10.useState)(false);
|
|
1887
|
+
const ctor = (0, import_react10.useMemo)(() => getRecognitionCtor(), []);
|
|
1868
1888
|
const isSupported = ctor !== null;
|
|
1869
|
-
const finalRef = (0,
|
|
1870
|
-
const interimRef = (0,
|
|
1889
|
+
const finalRef = (0, import_react10.useRef)(onFinalTranscript);
|
|
1890
|
+
const interimRef = (0, import_react10.useRef)(onInterimTranscript);
|
|
1871
1891
|
finalRef.current = onFinalTranscript;
|
|
1872
1892
|
interimRef.current = onInterimTranscript;
|
|
1873
|
-
(0,
|
|
1893
|
+
(0, import_react10.useEffect)(() => {
|
|
1874
1894
|
if (!ctor) return;
|
|
1875
1895
|
const recognition = new ctor();
|
|
1876
1896
|
recognition.lang = lang;
|
|
@@ -1909,7 +1929,7 @@ function useSpeechRecognition({ lang = "en-US", onFinalTranscript, onInterimTran
|
|
|
1909
1929
|
ctor,
|
|
1910
1930
|
lang
|
|
1911
1931
|
]);
|
|
1912
|
-
const start = (0,
|
|
1932
|
+
const start = (0, import_react10.useCallback)(() => {
|
|
1913
1933
|
const recognition = recognitionRef.current;
|
|
1914
1934
|
if (!recognition) return;
|
|
1915
1935
|
try {
|
|
@@ -1919,7 +1939,7 @@ function useSpeechRecognition({ lang = "en-US", onFinalTranscript, onInterimTran
|
|
|
1919
1939
|
console.warn("SpeechRecognition start failed", error);
|
|
1920
1940
|
}
|
|
1921
1941
|
}, []);
|
|
1922
|
-
const stop = (0,
|
|
1942
|
+
const stop = (0, import_react10.useCallback)(() => {
|
|
1923
1943
|
const recognition = recognitionRef.current;
|
|
1924
1944
|
if (!recognition) return;
|
|
1925
1945
|
try {
|
|
@@ -1938,8 +1958,8 @@ __name(useSpeechRecognition, "useSpeechRecognition");
|
|
|
1938
1958
|
|
|
1939
1959
|
// src/components/chat-input.tsx
|
|
1940
1960
|
function ChatInput({ onSubmit, disabled, placeholder, rows = 2, enableSpeech = true, speechLang = "en-US", sendLabel = "Send", onStop, isStreaming = false, stopLabel = "Stop generating", className, textareaClassName, sendButtonClassName, micButtonClassName, stopButtonClassName, renderMic }) {
|
|
1941
|
-
const [value, setValue] = (0,
|
|
1942
|
-
const [interim, setInterim] = (0,
|
|
1961
|
+
const [value, setValue] = (0, import_react11.useState)("");
|
|
1962
|
+
const [interim, setInterim] = (0, import_react11.useState)("");
|
|
1943
1963
|
const speech = useSpeechRecognition({
|
|
1944
1964
|
lang: speechLang,
|
|
1945
1965
|
onFinalTranscript: /* @__PURE__ */ __name((text) => {
|
|
@@ -1950,7 +1970,7 @@ function ChatInput({ onSubmit, disabled, placeholder, rows = 2, enableSpeech = t
|
|
|
1950
1970
|
}, "onFinalTranscript"),
|
|
1951
1971
|
onInterimTranscript: /* @__PURE__ */ __name((text) => setInterim(text), "onInterimTranscript")
|
|
1952
1972
|
});
|
|
1953
|
-
(0,
|
|
1973
|
+
(0, import_react11.useEffect)(() => {
|
|
1954
1974
|
if (!speech.isListening) setInterim("");
|
|
1955
1975
|
}, [
|
|
1956
1976
|
speech.isListening
|
|
@@ -1978,9 +1998,9 @@ function ChatInput({ onSubmit, disabled, placeholder, rows = 2, enableSpeech = t
|
|
|
1978
1998
|
const displayValue = speech.isListening && interim ? `${value}${value && !value.endsWith(" ") ? " " : ""}${interim}` : value;
|
|
1979
1999
|
const showMic = enableSpeech && speech.isSupported;
|
|
1980
2000
|
const showStop = isStreaming && onStop !== void 0;
|
|
1981
|
-
return /* @__PURE__ */
|
|
2001
|
+
return /* @__PURE__ */ import_react11.default.createElement("div", {
|
|
1982
2002
|
className
|
|
1983
|
-
}, /* @__PURE__ */
|
|
2003
|
+
}, /* @__PURE__ */ import_react11.default.createElement("textarea", {
|
|
1984
2004
|
className: textareaClassName,
|
|
1985
2005
|
rows,
|
|
1986
2006
|
value: displayValue,
|
|
@@ -1991,17 +2011,17 @@ function ChatInput({ onSubmit, disabled, placeholder, rows = 2, enableSpeech = t
|
|
|
1991
2011
|
}, "onChange"),
|
|
1992
2012
|
onKeyDown: handleKeyDown,
|
|
1993
2013
|
placeholder: placeholder ?? "Ask something (Enter to send, Shift+Enter for newline)"
|
|
1994
|
-
}), /* @__PURE__ */
|
|
2014
|
+
}), /* @__PURE__ */ import_react11.default.createElement("button", {
|
|
1995
2015
|
type: "button",
|
|
1996
2016
|
className: sendButtonClassName,
|
|
1997
2017
|
onClick: submit,
|
|
1998
2018
|
disabled: disabled || !value.trim()
|
|
1999
|
-
}, sendLabel), showStop ? /* @__PURE__ */
|
|
2019
|
+
}, sendLabel), showStop ? /* @__PURE__ */ import_react11.default.createElement("button", {
|
|
2000
2020
|
type: "button",
|
|
2001
2021
|
className: stopButtonClassName,
|
|
2002
2022
|
onClick: /* @__PURE__ */ __name(() => void onStop(), "onClick"),
|
|
2003
2023
|
"aria-label": "Stop generating"
|
|
2004
|
-
}, stopLabel) : null, showMic ? /* @__PURE__ */
|
|
2024
|
+
}, stopLabel) : null, showMic ? /* @__PURE__ */ import_react11.default.createElement("button", {
|
|
2005
2025
|
type: "button",
|
|
2006
2026
|
className: micButtonClassName,
|
|
2007
2027
|
onClick: toggleMic,
|
|
@@ -2014,10 +2034,10 @@ function ChatInput({ onSubmit, disabled, placeholder, rows = 2, enableSpeech = t
|
|
|
2014
2034
|
__name(ChatInput, "ChatInput");
|
|
2015
2035
|
|
|
2016
2036
|
// src/components/message-item.tsx
|
|
2017
|
-
var
|
|
2037
|
+
var import_react14 = __toESM(require("react"), 1);
|
|
2018
2038
|
|
|
2019
2039
|
// src/transcript/use-chat-transcript.ts
|
|
2020
|
-
var
|
|
2040
|
+
var import_react13 = require("react");
|
|
2021
2041
|
|
|
2022
2042
|
// src/transcript/model.ts
|
|
2023
2043
|
var import_nestjs_agent_core2 = require("@dudousxd/nestjs-agent-core");
|
|
@@ -2994,11 +3014,11 @@ function formatCostUsd(cost) {
|
|
|
2994
3014
|
__name(formatCostUsd, "formatCostUsd");
|
|
2995
3015
|
|
|
2996
3016
|
// src/transcript/use-stick-to-bottom.ts
|
|
2997
|
-
var
|
|
3017
|
+
var import_react12 = require("react");
|
|
2998
3018
|
function useStickToBottom({ contentKey, threshold = 32 }) {
|
|
2999
|
-
const containerRef = (0,
|
|
3000
|
-
const [isAtBottom, setIsAtBottom] = (0,
|
|
3001
|
-
const measure = (0,
|
|
3019
|
+
const containerRef = (0, import_react12.useRef)(null);
|
|
3020
|
+
const [isAtBottom, setIsAtBottom] = (0, import_react12.useState)(true);
|
|
3021
|
+
const measure = (0, import_react12.useCallback)(() => {
|
|
3002
3022
|
const element = containerRef.current;
|
|
3003
3023
|
if (!element) {
|
|
3004
3024
|
return;
|
|
@@ -3008,7 +3028,7 @@ function useStickToBottom({ contentKey, threshold = 32 }) {
|
|
|
3008
3028
|
}, [
|
|
3009
3029
|
threshold
|
|
3010
3030
|
]);
|
|
3011
|
-
const scrollToBottom = (0,
|
|
3031
|
+
const scrollToBottom = (0, import_react12.useCallback)(() => {
|
|
3012
3032
|
const element = containerRef.current;
|
|
3013
3033
|
if (!element) {
|
|
3014
3034
|
return;
|
|
@@ -3016,7 +3036,7 @@ function useStickToBottom({ contentKey, threshold = 32 }) {
|
|
|
3016
3036
|
element.scrollTop = element.scrollHeight;
|
|
3017
3037
|
setIsAtBottom(true);
|
|
3018
3038
|
}, []);
|
|
3019
|
-
const setContainer = (0,
|
|
3039
|
+
const setContainer = (0, import_react12.useCallback)((element) => {
|
|
3020
3040
|
containerRef.current = element;
|
|
3021
3041
|
if (element) {
|
|
3022
3042
|
measure();
|
|
@@ -3024,7 +3044,7 @@ function useStickToBottom({ contentKey, threshold = 32 }) {
|
|
|
3024
3044
|
}, [
|
|
3025
3045
|
measure
|
|
3026
3046
|
]);
|
|
3027
|
-
(0,
|
|
3047
|
+
(0, import_react12.useEffect)(() => {
|
|
3028
3048
|
if (isAtBottom) {
|
|
3029
3049
|
scrollToBottom();
|
|
3030
3050
|
}
|
|
@@ -3033,7 +3053,7 @@ function useStickToBottom({ contentKey, threshold = 32 }) {
|
|
|
3033
3053
|
isAtBottom,
|
|
3034
3054
|
scrollToBottom
|
|
3035
3055
|
]);
|
|
3036
|
-
const getContainerProps = (0,
|
|
3056
|
+
const getContainerProps = (0, import_react12.useCallback)(() => ({
|
|
3037
3057
|
ref: setContainer,
|
|
3038
3058
|
onScroll: measure
|
|
3039
3059
|
}), [
|
|
@@ -3055,14 +3075,14 @@ var DEFAULT_LOAD_EARLIER_STEP = 50;
|
|
|
3055
3075
|
var DEFAULT_COPY_RESET_MS = 1500;
|
|
3056
3076
|
function useChatTranscript(options) {
|
|
3057
3077
|
const { messages, status, initialVisibleCount = DEFAULT_VISIBLE_COUNT, loadEarlierStep = DEFAULT_LOAD_EARLIER_STEP, followUps, stickToBottomThreshold } = options;
|
|
3058
|
-
const latest = (0,
|
|
3078
|
+
const latest = (0, import_react13.useRef)(options);
|
|
3059
3079
|
latest.current = options;
|
|
3060
|
-
const [visibleCount, setVisibleCount] = (0,
|
|
3061
|
-
const [stopRequested, setStopRequested] = (0,
|
|
3080
|
+
const [visibleCount, setVisibleCount] = (0, import_react13.useState)(initialVisibleCount);
|
|
3081
|
+
const [stopRequested, setStopRequested] = (0, import_react13.useState)(false);
|
|
3062
3082
|
const isStreaming = status === "streaming" || status === "reconnecting";
|
|
3063
3083
|
const isBusy = status === "submitted" || isStreaming;
|
|
3064
3084
|
const isEmpty = messages.length === 0;
|
|
3065
|
-
(0,
|
|
3085
|
+
(0, import_react13.useEffect)(() => {
|
|
3066
3086
|
if (!isBusy) {
|
|
3067
3087
|
setStopRequested(false);
|
|
3068
3088
|
}
|
|
@@ -3079,7 +3099,7 @@ function useChatTranscript(options) {
|
|
|
3079
3099
|
streamingMessageId,
|
|
3080
3100
|
options
|
|
3081
3101
|
});
|
|
3082
|
-
const stop = (0,
|
|
3102
|
+
const stop = (0, import_react13.useCallback)(() => {
|
|
3083
3103
|
const current = latest.current;
|
|
3084
3104
|
if (current.status !== "submitted" && current.status !== "streaming" && current.status !== "reconnecting") {
|
|
3085
3105
|
return;
|
|
@@ -3087,8 +3107,8 @@ function useChatTranscript(options) {
|
|
|
3087
3107
|
setStopRequested(true);
|
|
3088
3108
|
void current.onStop?.();
|
|
3089
3109
|
}, []);
|
|
3090
|
-
const loadEarlier = (0,
|
|
3091
|
-
const showAll = (0,
|
|
3110
|
+
const loadEarlier = (0, import_react13.useCallback)(() => setVisibleCount((count) => count + (latest.current.loadEarlierStep ?? DEFAULT_LOAD_EARLIER_STEP)), []);
|
|
3111
|
+
const showAll = (0, import_react13.useCallback)(() => setVisibleCount(latest.current.messages.length), []);
|
|
3092
3112
|
const scroll = useStickToBottom({
|
|
3093
3113
|
contentKey: contentSignature(messages),
|
|
3094
3114
|
...stickToBottomThreshold !== void 0 ? {
|
|
@@ -3124,7 +3144,7 @@ function useChatTranscript(options) {
|
|
|
3124
3144
|
__name(useChatTranscript, "useChatTranscript");
|
|
3125
3145
|
function useTranscriptItem(options) {
|
|
3126
3146
|
const { message, isStreaming = false } = options;
|
|
3127
|
-
const messagesRef = (0,
|
|
3147
|
+
const messagesRef = (0, import_react13.useRef)([
|
|
3128
3148
|
message
|
|
3129
3149
|
]);
|
|
3130
3150
|
if (messagesRef.current[0] !== message) {
|
|
@@ -3142,13 +3162,13 @@ function useTranscriptItem(options) {
|
|
|
3142
3162
|
}
|
|
3143
3163
|
__name(useTranscriptItem, "useTranscriptItem");
|
|
3144
3164
|
function useTranscriptItems({ messages, visibleStart, streamingMessageId, options }) {
|
|
3145
|
-
const [drafts, setDrafts] = (0,
|
|
3146
|
-
const [copied, setCopied] = (0,
|
|
3147
|
-
const [openReasoning, setOpenReasoning] = (0,
|
|
3148
|
-
const [picks, setPicks] = (0,
|
|
3149
|
-
const [settling, setSettling] = (0,
|
|
3150
|
-
const [settleErrors, setSettleErrors] = (0,
|
|
3151
|
-
const latest = (0,
|
|
3165
|
+
const [drafts, setDrafts] = (0, import_react13.useState)(() => /* @__PURE__ */ new Map());
|
|
3166
|
+
const [copied, setCopied] = (0, import_react13.useState)(() => /* @__PURE__ */ new Set());
|
|
3167
|
+
const [openReasoning, setOpenReasoning] = (0, import_react13.useState)(() => /* @__PURE__ */ new Map());
|
|
3168
|
+
const [picks, setPicks] = (0, import_react13.useState)(() => /* @__PURE__ */ new Map());
|
|
3169
|
+
const [settling, setSettling] = (0, import_react13.useState)(() => /* @__PURE__ */ new Map());
|
|
3170
|
+
const [settleErrors, setSettleErrors] = (0, import_react13.useState)(() => /* @__PURE__ */ new Map());
|
|
3171
|
+
const latest = (0, import_react13.useRef)({
|
|
3152
3172
|
options,
|
|
3153
3173
|
drafts,
|
|
3154
3174
|
picks,
|
|
@@ -3160,23 +3180,23 @@ function useTranscriptItems({ messages, visibleStart, streamingMessageId, option
|
|
|
3160
3180
|
picks,
|
|
3161
3181
|
messages
|
|
3162
3182
|
};
|
|
3163
|
-
const copyTimers = (0,
|
|
3164
|
-
(0,
|
|
3183
|
+
const copyTimers = (0, import_react13.useRef)(/* @__PURE__ */ new Map());
|
|
3184
|
+
(0, import_react13.useEffect)(() => () => {
|
|
3165
3185
|
for (const timer of copyTimers.current.values()) {
|
|
3166
3186
|
clearTimeout(timer);
|
|
3167
3187
|
}
|
|
3168
3188
|
copyTimers.current.clear();
|
|
3169
3189
|
}, []);
|
|
3170
|
-
const callbackCache = (0,
|
|
3171
|
-
const reasoningToggleCache = (0,
|
|
3172
|
-
const toggleReasoning = (0,
|
|
3190
|
+
const callbackCache = (0, import_react13.useRef)(/* @__PURE__ */ new Map());
|
|
3191
|
+
const reasoningToggleCache = (0, import_react13.useRef)(/* @__PURE__ */ new Map());
|
|
3192
|
+
const toggleReasoning = (0, import_react13.useCallback)((key, open) => {
|
|
3173
3193
|
setOpenReasoning((current) => {
|
|
3174
3194
|
const next = new Map(current);
|
|
3175
3195
|
next.set(key, open ?? !(current.get(key) ?? false));
|
|
3176
3196
|
return next;
|
|
3177
3197
|
});
|
|
3178
3198
|
}, []);
|
|
3179
|
-
const stableToggle = (0,
|
|
3199
|
+
const stableToggle = (0, import_react13.useCallback)((key) => {
|
|
3180
3200
|
let cached = reasoningToggleCache.current.get(key);
|
|
3181
3201
|
if (!cached) {
|
|
3182
3202
|
cached = /* @__PURE__ */ __name((open) => toggleReasoning(key, open), "cached");
|
|
@@ -3186,10 +3206,10 @@ function useTranscriptItems({ messages, visibleStart, streamingMessageId, option
|
|
|
3186
3206
|
}, [
|
|
3187
3207
|
toggleReasoning
|
|
3188
3208
|
]);
|
|
3189
|
-
const pick = (0,
|
|
3209
|
+
const pick = (0, import_react13.useCallback)((toolCallId, questionId, values) => {
|
|
3190
3210
|
setPicks((current) => new Map(current).set(pickKey(toolCallId, questionId), values));
|
|
3191
3211
|
}, []);
|
|
3192
|
-
const settle = (0,
|
|
3212
|
+
const settle = (0, import_react13.useCallback)((toolCallId, action, send) => {
|
|
3193
3213
|
setSettleErrors((current) => {
|
|
3194
3214
|
if (!current.has(toolCallId)) {
|
|
3195
3215
|
return current;
|
|
@@ -3213,7 +3233,7 @@ function useTranscriptItems({ messages, visibleStart, streamingMessageId, option
|
|
|
3213
3233
|
failed(error);
|
|
3214
3234
|
}
|
|
3215
3235
|
}, []);
|
|
3216
|
-
const answer = (0,
|
|
3236
|
+
const answer = (0, import_react13.useCallback)((toolCallId) => {
|
|
3217
3237
|
const current = latest.current;
|
|
3218
3238
|
const onAnswer = current.options.onAnswer;
|
|
3219
3239
|
if (!onAnswer) {
|
|
@@ -3223,7 +3243,7 @@ function useTranscriptItems({ messages, visibleStart, streamingMessageId, option
|
|
|
3223
3243
|
}, [
|
|
3224
3244
|
settle
|
|
3225
3245
|
]);
|
|
3226
|
-
const skip = (0,
|
|
3246
|
+
const skip = (0, import_react13.useCallback)((toolCallId) => {
|
|
3227
3247
|
const onSkip = latest.current.options.onSkip;
|
|
3228
3248
|
if (onSkip) {
|
|
3229
3249
|
settle(toolCallId, "skip", () => onSkip(toolCallId));
|
|
@@ -3231,7 +3251,7 @@ function useTranscriptItems({ messages, visibleStart, streamingMessageId, option
|
|
|
3231
3251
|
}, [
|
|
3232
3252
|
settle
|
|
3233
3253
|
]);
|
|
3234
|
-
const approve = (0,
|
|
3254
|
+
const approve = (0, import_react13.useCallback)((toolCallId, options2) => {
|
|
3235
3255
|
const onApprove = latest.current.options.onApprove;
|
|
3236
3256
|
if (onApprove) {
|
|
3237
3257
|
settle(toolCallId, "approve", () => options2 === void 0 ? onApprove(toolCallId) : onApprove(toolCallId, options2));
|
|
@@ -3239,7 +3259,7 @@ function useTranscriptItems({ messages, visibleStart, streamingMessageId, option
|
|
|
3239
3259
|
}, [
|
|
3240
3260
|
settle
|
|
3241
3261
|
]);
|
|
3242
|
-
const reject = (0,
|
|
3262
|
+
const reject = (0, import_react13.useCallback)((toolCallId) => {
|
|
3243
3263
|
const onReject = latest.current.options.onReject;
|
|
3244
3264
|
if (onReject) {
|
|
3245
3265
|
settle(toolCallId, "reject", () => onReject(toolCallId));
|
|
@@ -3247,7 +3267,7 @@ function useTranscriptItems({ messages, visibleStart, streamingMessageId, option
|
|
|
3247
3267
|
}, [
|
|
3248
3268
|
settle
|
|
3249
3269
|
]);
|
|
3250
|
-
const callbacksFor = (0,
|
|
3270
|
+
const callbacksFor = (0, import_react13.useCallback)((id) => {
|
|
3251
3271
|
const cached = callbackCache.current.get(id);
|
|
3252
3272
|
if (cached) {
|
|
3253
3273
|
return cached;
|
|
@@ -3489,59 +3509,64 @@ function MessageItem({ message, isStreaming = false, editable, onEditSubmit, reg
|
|
|
3489
3509
|
getCreatedAt: /* @__PURE__ */ __name(() => createdAt, "getCreatedAt")
|
|
3490
3510
|
} : {}
|
|
3491
3511
|
});
|
|
3492
|
-
return /* @__PURE__ */
|
|
3512
|
+
return /* @__PURE__ */ import_react14.default.createElement(MessageItemView, {
|
|
3493
3513
|
item,
|
|
3494
3514
|
...slots
|
|
3495
3515
|
});
|
|
3496
3516
|
}
|
|
3497
3517
|
__name(MessageItem, "MessageItem");
|
|
3498
|
-
function MessageItemView({ item, ...
|
|
3518
|
+
function MessageItemView({ item, ...given }) {
|
|
3519
|
+
const ambientRenderUi = useAmbientRenderUi();
|
|
3520
|
+
const slots = given.renderUi === void 0 && ambientRenderUi !== null ? {
|
|
3521
|
+
...given,
|
|
3522
|
+
renderUi: ambientRenderUi
|
|
3523
|
+
} : given;
|
|
3499
3524
|
const { classNames } = slots;
|
|
3500
|
-
const actionRow = /* @__PURE__ */
|
|
3525
|
+
const actionRow = /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
3501
3526
|
className: classNames?.actions,
|
|
3502
3527
|
"data-actions-for": item.role
|
|
3503
|
-
}, item.copy.available ? /* @__PURE__ */
|
|
3528
|
+
}, item.copy.available ? /* @__PURE__ */ import_react14.default.createElement("button", {
|
|
3504
3529
|
type: "button",
|
|
3505
3530
|
onClick: item.copy.copy,
|
|
3506
3531
|
className: classNames?.actionButton,
|
|
3507
3532
|
title: item.copy.copied ? "Copied!" : "Copy message text"
|
|
3508
|
-
}, item.copy.copied ? "Copied" : "Copy") : null, item.fork.available ? /* @__PURE__ */
|
|
3533
|
+
}, item.copy.copied ? "Copied" : "Copy") : null, item.fork.available ? /* @__PURE__ */ import_react14.default.createElement("button", {
|
|
3509
3534
|
type: "button",
|
|
3510
3535
|
onClick: item.fork.run,
|
|
3511
3536
|
className: classNames?.actionButton,
|
|
3512
3537
|
title: "Fork thread from this message"
|
|
3513
|
-
}, "Fork") : null, item.regenerate.available ? /* @__PURE__ */
|
|
3538
|
+
}, "Fork") : null, item.regenerate.available ? /* @__PURE__ */ import_react14.default.createElement("button", {
|
|
3514
3539
|
type: "button",
|
|
3515
3540
|
onClick: item.regenerate.run,
|
|
3516
3541
|
className: classNames?.actionButton,
|
|
3517
3542
|
title: "Regenerate response"
|
|
3518
|
-
}, "Regenerate") : null, slots.meta, !item.isUser && item.usage ? /* @__PURE__ */
|
|
3543
|
+
}, "Regenerate") : null, slots.meta, !item.isUser && item.usage ? /* @__PURE__ */ import_react14.default.createElement("span", {
|
|
3519
3544
|
className: classNames?.usage,
|
|
3520
3545
|
title: `Input ${item.usage.inputTokens.toLocaleString()} \xB7 Output ${item.usage.outputTokens.toLocaleString()} tokens`
|
|
3521
|
-
}, item.usage.costLabel, " \xB7 ", item.usage.tokensLabel) : null, item.timestamp ? /* @__PURE__ */
|
|
3546
|
+
}, item.usage.costLabel, " \xB7 ", item.usage.tokensLabel) : null, item.timestamp ? /* @__PURE__ */ import_react14.default.createElement("span", {
|
|
3522
3547
|
className: classNames?.timestamp,
|
|
3523
3548
|
title: item.timestamp.absolute
|
|
3524
3549
|
}, item.timestamp.relative) : null);
|
|
3525
3550
|
if (item.edit.available) {
|
|
3526
|
-
return /* @__PURE__ */
|
|
3551
|
+
return /* @__PURE__ */ import_react14.default.createElement(EditableUserBubble, {
|
|
3527
3552
|
item,
|
|
3528
3553
|
slots,
|
|
3529
3554
|
actions: actionRow
|
|
3530
3555
|
});
|
|
3531
3556
|
}
|
|
3532
3557
|
const className = joinClasses(classNames?.root, classNames?.byRole?.[item.role]);
|
|
3533
|
-
return /* @__PURE__ */
|
|
3558
|
+
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
3534
3559
|
className,
|
|
3535
3560
|
"data-role": item.role,
|
|
3536
3561
|
"data-streaming": item.isStreaming ? "true" : void 0
|
|
3537
|
-
}, /* @__PURE__ */
|
|
3562
|
+
}, /* @__PURE__ */ import_react14.default.createElement("div", null, renderBlocks(item, slots)), actionRow);
|
|
3538
3563
|
}
|
|
3539
3564
|
__name(MessageItemView, "MessageItemView");
|
|
3540
3565
|
function renderBlocks(item, slots) {
|
|
3541
3566
|
const nodes = [];
|
|
3542
3567
|
for (const block of item.blocks) {
|
|
3543
3568
|
if (block.kind === "text") {
|
|
3544
|
-
nodes.push(/* @__PURE__ */
|
|
3569
|
+
nodes.push(/* @__PURE__ */ import_react14.default.createElement("div", {
|
|
3545
3570
|
key: block.key,
|
|
3546
3571
|
className: slots.classNames?.text
|
|
3547
3572
|
}, slots.renderText ? slots.renderText(block.text, {
|
|
@@ -3562,7 +3587,7 @@ function renderBlocks(item, slots) {
|
|
|
3562
3587
|
continue;
|
|
3563
3588
|
}
|
|
3564
3589
|
if (block.kind === "ui" && slots.renderUi) {
|
|
3565
|
-
nodes.push(/* @__PURE__ */
|
|
3590
|
+
nodes.push(/* @__PURE__ */ import_react14.default.createElement("div", {
|
|
3566
3591
|
key: block.key,
|
|
3567
3592
|
"data-slot": "ui",
|
|
3568
3593
|
"data-component": block.component
|
|
@@ -3573,18 +3598,18 @@ function renderBlocks(item, slots) {
|
|
|
3573
3598
|
}
|
|
3574
3599
|
__name(renderBlocks, "renderBlocks");
|
|
3575
3600
|
function renderFilesBlock(block, slots) {
|
|
3576
|
-
return /* @__PURE__ */
|
|
3601
|
+
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
3577
3602
|
key: block.key,
|
|
3578
3603
|
className: slots.classNames?.files,
|
|
3579
3604
|
"data-files": "true"
|
|
3580
|
-
}, slots.renderFiles ? slots.renderFiles(block.files) : block.files.map((file) => /* @__PURE__ */
|
|
3605
|
+
}, slots.renderFiles ? slots.renderFiles(block.files) : block.files.map((file) => /* @__PURE__ */ import_react14.default.createElement("a", {
|
|
3581
3606
|
key: file.url,
|
|
3582
3607
|
href: file.url,
|
|
3583
3608
|
target: "_blank",
|
|
3584
3609
|
rel: "noreferrer",
|
|
3585
3610
|
className: slots.classNames?.file,
|
|
3586
3611
|
title: file.filename ?? file.mediaType
|
|
3587
|
-
}, file.isImage ? /* @__PURE__ */
|
|
3612
|
+
}, file.isImage ? /* @__PURE__ */ import_react14.default.createElement("img", {
|
|
3588
3613
|
src: file.url,
|
|
3589
3614
|
alt: file.filename ?? "image",
|
|
3590
3615
|
className: slots.classNames?.fileImage
|
|
@@ -3592,17 +3617,17 @@ function renderFilesBlock(block, slots) {
|
|
|
3592
3617
|
}
|
|
3593
3618
|
__name(renderFilesBlock, "renderFilesBlock");
|
|
3594
3619
|
function renderReasoningBlock(block, slots) {
|
|
3595
|
-
return /* @__PURE__ */
|
|
3620
|
+
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
3596
3621
|
key: block.key,
|
|
3597
3622
|
className: slots.classNames?.reasoning,
|
|
3598
3623
|
"data-reasoning": "true",
|
|
3599
3624
|
"data-streaming": block.isStreaming ? "true" : void 0
|
|
3600
|
-
}, /* @__PURE__ */
|
|
3625
|
+
}, /* @__PURE__ */ import_react14.default.createElement("button", {
|
|
3601
3626
|
type: "button",
|
|
3602
3627
|
className: slots.classNames?.reasoningToggle,
|
|
3603
3628
|
onClick: /* @__PURE__ */ __name(() => block.toggle(), "onClick"),
|
|
3604
3629
|
"aria-expanded": block.isOpen
|
|
3605
|
-
}, slots.reasoningLabel ?? "Reasoning"), block.isOpen ? /* @__PURE__ */
|
|
3630
|
+
}, slots.reasoningLabel ?? "Reasoning"), block.isOpen ? /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
3606
3631
|
className: slots.classNames?.reasoningText
|
|
3607
3632
|
}, slots.renderReasoning ? slots.renderReasoning(block.text, {
|
|
3608
3633
|
isStreaming: block.isStreaming,
|
|
@@ -3613,7 +3638,7 @@ __name(renderReasoningBlock, "renderReasoningBlock");
|
|
|
3613
3638
|
function renderToolBlock(item, block, slots) {
|
|
3614
3639
|
if (slots.renderToolGroup) {
|
|
3615
3640
|
return [
|
|
3616
|
-
/* @__PURE__ */
|
|
3641
|
+
/* @__PURE__ */ import_react14.default.createElement(import_react14.default.Fragment, {
|
|
3617
3642
|
key: block.key
|
|
3618
3643
|
}, slots.renderToolGroup(block.parts, block.key))
|
|
3619
3644
|
];
|
|
@@ -3624,7 +3649,7 @@ function renderToolBlock(item, block, slots) {
|
|
|
3624
3649
|
const renderToolPart = slots.renderToolPart;
|
|
3625
3650
|
return block.parts.map((part) => {
|
|
3626
3651
|
const partKey = `${item.id}-${part.toolCallId}`;
|
|
3627
|
-
return /* @__PURE__ */
|
|
3652
|
+
return /* @__PURE__ */ import_react14.default.createElement(import_react14.default.Fragment, {
|
|
3628
3653
|
key: partKey
|
|
3629
3654
|
}, renderToolPart(part, partKey));
|
|
3630
3655
|
});
|
|
@@ -3634,14 +3659,14 @@ function EditableUserBubble({ item, slots, actions }) {
|
|
|
3634
3659
|
const { classNames } = slots;
|
|
3635
3660
|
const { edit } = item;
|
|
3636
3661
|
if (!edit.isEditing) {
|
|
3637
|
-
return /* @__PURE__ */
|
|
3662
|
+
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
3638
3663
|
className: joinClasses(classNames?.root, classNames?.byRole?.user),
|
|
3639
3664
|
"data-role": "user"
|
|
3640
|
-
}, /* @__PURE__ */
|
|
3665
|
+
}, /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
3641
3666
|
className: classNames?.text
|
|
3642
3667
|
}, slots.renderText ? slots.renderText(item.text, {
|
|
3643
3668
|
isStreaming: false
|
|
3644
|
-
}) : item.text), /* @__PURE__ */
|
|
3669
|
+
}) : item.text), /* @__PURE__ */ import_react14.default.createElement("button", {
|
|
3645
3670
|
type: "button",
|
|
3646
3671
|
onClick: edit.start,
|
|
3647
3672
|
className: classNames?.actionButton,
|
|
@@ -3649,18 +3674,18 @@ function EditableUserBubble({ item, slots, actions }) {
|
|
|
3649
3674
|
}, "Edit"), actions);
|
|
3650
3675
|
}
|
|
3651
3676
|
const textareaProps = edit.getTextareaProps();
|
|
3652
|
-
return /* @__PURE__ */
|
|
3677
|
+
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
3653
3678
|
"data-editing": "true"
|
|
3654
|
-
}, /* @__PURE__ */
|
|
3679
|
+
}, /* @__PURE__ */ import_react14.default.createElement("textarea", {
|
|
3655
3680
|
...textareaProps,
|
|
3656
3681
|
rows: Math.min(8, edit.draft.split("\n").length + 1),
|
|
3657
3682
|
className: classNames?.editTextarea
|
|
3658
|
-
}), /* @__PURE__ */
|
|
3683
|
+
}), /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
3659
3684
|
className: classNames?.editActions
|
|
3660
|
-
}, /* @__PURE__ */
|
|
3685
|
+
}, /* @__PURE__ */ import_react14.default.createElement("button", {
|
|
3661
3686
|
type: "button",
|
|
3662
3687
|
onClick: edit.cancel
|
|
3663
|
-
}, "Cancel"), /* @__PURE__ */
|
|
3688
|
+
}, "Cancel"), /* @__PURE__ */ import_react14.default.createElement("button", {
|
|
3664
3689
|
type: "button",
|
|
3665
3690
|
onClick: edit.save,
|
|
3666
3691
|
disabled: !edit.canSave
|
|
@@ -3904,35 +3929,35 @@ function toItem(entry) {
|
|
|
3904
3929
|
__name(toItem, "toItem");
|
|
3905
3930
|
|
|
3906
3931
|
// src/composer/use-composer-autocomplete.ts
|
|
3907
|
-
var
|
|
3932
|
+
var import_react15 = require("react");
|
|
3908
3933
|
function useComposerAutocomplete(options) {
|
|
3909
3934
|
const { value, sources, acceptOnTab = true } = options;
|
|
3910
|
-
const latest = (0,
|
|
3935
|
+
const latest = (0, import_react15.useRef)(options);
|
|
3911
3936
|
latest.current = options;
|
|
3912
|
-
const inputRef = (0,
|
|
3913
|
-
const [caret, setCaret] = (0,
|
|
3914
|
-
const [items, setItems] = (0,
|
|
3915
|
-
const [isLoading, setLoading] = (0,
|
|
3916
|
-
const [error, setError] = (0,
|
|
3917
|
-
const [activeIndex, setActiveIndex] = (0,
|
|
3918
|
-
const [dismissedIndex, setDismissedIndex] = (0,
|
|
3937
|
+
const inputRef = (0, import_react15.useRef)(null);
|
|
3938
|
+
const [caret, setCaret] = (0, import_react15.useState)(value.length);
|
|
3939
|
+
const [items, setItems] = (0, import_react15.useState)([]);
|
|
3940
|
+
const [isLoading, setLoading] = (0, import_react15.useState)(false);
|
|
3941
|
+
const [error, setError] = (0, import_react15.useState)(null);
|
|
3942
|
+
const [activeIndex, setActiveIndex] = (0, import_react15.useState)(0);
|
|
3943
|
+
const [dismissedIndex, setDismissedIndex] = (0, import_react15.useState)(null);
|
|
3919
3944
|
const safeCaret = Math.min(caret, value.length);
|
|
3920
|
-
const match = (0,
|
|
3945
|
+
const match = (0, import_react15.useMemo)(() => findActiveTrigger(value, safeCaret, sources), [
|
|
3921
3946
|
value,
|
|
3922
3947
|
safeCaret,
|
|
3923
3948
|
sources
|
|
3924
3949
|
]);
|
|
3925
3950
|
const isActive = match !== null && dismissedIndex !== match.index;
|
|
3926
|
-
const matchRef = (0,
|
|
3951
|
+
const matchRef = (0, import_react15.useRef)(match);
|
|
3927
3952
|
matchRef.current = match;
|
|
3928
|
-
const caretRef = (0,
|
|
3953
|
+
const caretRef = (0, import_react15.useRef)(safeCaret);
|
|
3929
3954
|
caretRef.current = safeCaret;
|
|
3930
|
-
const itemsRef = (0,
|
|
3955
|
+
const itemsRef = (0, import_react15.useRef)(items);
|
|
3931
3956
|
itemsRef.current = items;
|
|
3932
|
-
const activeIndexRef = (0,
|
|
3957
|
+
const activeIndexRef = (0, import_react15.useRef)(activeIndex);
|
|
3933
3958
|
activeIndexRef.current = activeIndex;
|
|
3934
3959
|
const requestKey = isActive && match ? `${match.source.id}\0${match.query}` : null;
|
|
3935
|
-
(0,
|
|
3960
|
+
(0, import_react15.useEffect)(() => {
|
|
3936
3961
|
const current = matchRef.current;
|
|
3937
3962
|
if (requestKey === null || current === null) {
|
|
3938
3963
|
setItems([]);
|
|
@@ -3980,25 +4005,25 @@ function useComposerAutocomplete(options) {
|
|
|
3980
4005
|
]);
|
|
3981
4006
|
const isOpen = isActive;
|
|
3982
4007
|
const activeItem = isOpen ? items[activeIndex] ?? null : null;
|
|
3983
|
-
const reactId = (0,
|
|
4008
|
+
const reactId = (0, import_react15.useId)();
|
|
3984
4009
|
const listboxId = options.id ?? `agent-autocomplete-${reactId}`;
|
|
3985
|
-
const optionId = (0,
|
|
4010
|
+
const optionId = (0, import_react15.useCallback)((index) => `${listboxId}-option-${index}`, [
|
|
3986
4011
|
listboxId
|
|
3987
4012
|
]);
|
|
3988
|
-
const highlight = (0,
|
|
4013
|
+
const highlight = (0, import_react15.useCallback)((index) => {
|
|
3989
4014
|
const total = itemsRef.current.length;
|
|
3990
4015
|
if (total === 0) return;
|
|
3991
4016
|
setActiveIndex((index % total + total) % total);
|
|
3992
4017
|
}, []);
|
|
3993
|
-
const moveHighlight = (0,
|
|
4018
|
+
const moveHighlight = (0, import_react15.useCallback)((delta) => highlight(activeIndexRef.current + delta), [
|
|
3994
4019
|
highlight
|
|
3995
4020
|
]);
|
|
3996
|
-
const dismiss = (0,
|
|
4021
|
+
const dismiss = (0, import_react15.useCallback)(() => {
|
|
3997
4022
|
const current = matchRef.current;
|
|
3998
4023
|
if (current) setDismissedIndex(current.index);
|
|
3999
4024
|
}, []);
|
|
4000
|
-
const pendingCaret = (0,
|
|
4001
|
-
const accept = (0,
|
|
4025
|
+
const pendingCaret = (0, import_react15.useRef)(null);
|
|
4026
|
+
const accept = (0, import_react15.useCallback)((item) => {
|
|
4002
4027
|
const current = matchRef.current;
|
|
4003
4028
|
if (!current) return;
|
|
4004
4029
|
const chosen = item ?? itemsRef.current[activeIndexRef.current];
|
|
@@ -4009,16 +4034,16 @@ function useComposerAutocomplete(options) {
|
|
|
4009
4034
|
setDismissedIndex(null);
|
|
4010
4035
|
pendingCaret.current = edit.caret;
|
|
4011
4036
|
}, []);
|
|
4012
|
-
(0,
|
|
4037
|
+
(0, import_react15.useLayoutEffect)(() => {
|
|
4013
4038
|
const position = pendingCaret.current;
|
|
4014
4039
|
if (position === null) return;
|
|
4015
4040
|
pendingCaret.current = null;
|
|
4016
4041
|
inputRef.current?.setSelectionRange(position, position);
|
|
4017
4042
|
});
|
|
4018
|
-
const readCaret = (0,
|
|
4043
|
+
const readCaret = (0, import_react15.useCallback)((element) => {
|
|
4019
4044
|
setCaret(element.selectionStart ?? element.value.length);
|
|
4020
4045
|
}, []);
|
|
4021
|
-
const onKeyDown = (0,
|
|
4046
|
+
const onKeyDown = (0, import_react15.useCallback)((event) => {
|
|
4022
4047
|
if (!isOpen) return;
|
|
4023
4048
|
const hasItems = itemsRef.current.length > 0;
|
|
4024
4049
|
switch (event.key) {
|
|
@@ -4056,23 +4081,23 @@ function useComposerAutocomplete(options) {
|
|
|
4056
4081
|
dismiss,
|
|
4057
4082
|
moveHighlight
|
|
4058
4083
|
]);
|
|
4059
|
-
const onChange = (0,
|
|
4084
|
+
const onChange = (0, import_react15.useCallback)((event) => {
|
|
4060
4085
|
readCaret(event.target);
|
|
4061
4086
|
const next = findActiveTrigger(event.target.value, event.target.selectionStart ?? event.target.value.length, latest.current.sources);
|
|
4062
4087
|
setDismissedIndex((current) => current !== null && next?.index === current ? current : null);
|
|
4063
4088
|
}, [
|
|
4064
4089
|
readCaret
|
|
4065
4090
|
]);
|
|
4066
|
-
const onSelect = (0,
|
|
4091
|
+
const onSelect = (0, import_react15.useCallback)((event) => readCaret(event.currentTarget), [
|
|
4067
4092
|
readCaret
|
|
4068
4093
|
]);
|
|
4069
|
-
const onClick = (0,
|
|
4094
|
+
const onClick = (0, import_react15.useCallback)((event) => readCaret(event.currentTarget), [
|
|
4070
4095
|
readCaret
|
|
4071
4096
|
]);
|
|
4072
|
-
const setInput = (0,
|
|
4097
|
+
const setInput = (0, import_react15.useCallback)((element) => {
|
|
4073
4098
|
inputRef.current = element;
|
|
4074
4099
|
}, []);
|
|
4075
|
-
const getInputProps = (0,
|
|
4100
|
+
const getInputProps = (0, import_react15.useCallback)(() => ({
|
|
4076
4101
|
ref: setInput,
|
|
4077
4102
|
onChange,
|
|
4078
4103
|
onKeyDown,
|
|
@@ -4100,7 +4125,7 @@ function useComposerAutocomplete(options) {
|
|
|
4100
4125
|
activeIndex,
|
|
4101
4126
|
optionId
|
|
4102
4127
|
]);
|
|
4103
|
-
const getListboxProps = (0,
|
|
4128
|
+
const getListboxProps = (0, import_react15.useCallback)(() => ({
|
|
4104
4129
|
id: listboxId,
|
|
4105
4130
|
role: "listbox",
|
|
4106
4131
|
"aria-label": match?.source.label ?? match?.source.id ?? "Suggestions"
|
|
@@ -4108,7 +4133,7 @@ function useComposerAutocomplete(options) {
|
|
|
4108
4133
|
listboxId,
|
|
4109
4134
|
match
|
|
4110
4135
|
]);
|
|
4111
|
-
const getOptionProps = (0,
|
|
4136
|
+
const getOptionProps = (0, import_react15.useCallback)((index) => ({
|
|
4112
4137
|
id: optionId(index),
|
|
4113
4138
|
role: "option",
|
|
4114
4139
|
"aria-selected": index === activeIndex
|
|
@@ -4142,7 +4167,7 @@ function isPromise(value) {
|
|
|
4142
4167
|
__name(isPromise, "isPromise");
|
|
4143
4168
|
|
|
4144
4169
|
// src/presentation/use-tool-catalog.ts
|
|
4145
|
-
var
|
|
4170
|
+
var import_react16 = require("react");
|
|
4146
4171
|
var shared = /* @__PURE__ */ new WeakMap();
|
|
4147
4172
|
function load(client, agent) {
|
|
4148
4173
|
let byAgent = shared.get(client);
|
|
@@ -4166,11 +4191,11 @@ function load(client, agent) {
|
|
|
4166
4191
|
__name(load, "load");
|
|
4167
4192
|
function useToolCatalog(options) {
|
|
4168
4193
|
const { client, agent, enabled = true } = options;
|
|
4169
|
-
const [entries, setEntries] = (0,
|
|
4170
|
-
const [isLoading, setLoading] = (0,
|
|
4171
|
-
const [error, setError] = (0,
|
|
4172
|
-
const [generation, setGeneration] = (0,
|
|
4173
|
-
(0,
|
|
4194
|
+
const [entries, setEntries] = (0, import_react16.useState)([]);
|
|
4195
|
+
const [isLoading, setLoading] = (0, import_react16.useState)(enabled);
|
|
4196
|
+
const [error, setError] = (0, import_react16.useState)(null);
|
|
4197
|
+
const [generation, setGeneration] = (0, import_react16.useState)(0);
|
|
4198
|
+
(0, import_react16.useEffect)(() => {
|
|
4174
4199
|
if (!enabled) {
|
|
4175
4200
|
setLoading(false);
|
|
4176
4201
|
return;
|
|
@@ -4196,14 +4221,14 @@ function useToolCatalog(options) {
|
|
|
4196
4221
|
enabled,
|
|
4197
4222
|
generation
|
|
4198
4223
|
]);
|
|
4199
|
-
const refresh = (0,
|
|
4224
|
+
const refresh = (0, import_react16.useCallback)(() => {
|
|
4200
4225
|
shared.get(client)?.delete(agent ?? "");
|
|
4201
4226
|
setGeneration((current) => current + 1);
|
|
4202
4227
|
}, [
|
|
4203
4228
|
client,
|
|
4204
4229
|
agent
|
|
4205
4230
|
]);
|
|
4206
|
-
const catalog = (0,
|
|
4231
|
+
const catalog = (0, import_react16.useMemo)(() => toolCatalogFrom(entries), [
|
|
4207
4232
|
entries
|
|
4208
4233
|
]);
|
|
4209
4234
|
return {
|
|
@@ -4217,7 +4242,7 @@ function useToolCatalog(options) {
|
|
|
4217
4242
|
__name(useToolCatalog, "useToolCatalog");
|
|
4218
4243
|
|
|
4219
4244
|
// src/approvals/countdown.ts
|
|
4220
|
-
var
|
|
4245
|
+
var import_react17 = require("react");
|
|
4221
4246
|
function approvalCountdown(expiresAt, now = Date.now()) {
|
|
4222
4247
|
const deadline = expiresAt == null ? Number.NaN : Date.parse(expiresAt);
|
|
4223
4248
|
if (!Number.isFinite(deadline)) {
|
|
@@ -4235,10 +4260,10 @@ function approvalCountdown(expiresAt, now = Date.now()) {
|
|
|
4235
4260
|
__name(approvalCountdown, "approvalCountdown");
|
|
4236
4261
|
function useApprovalCountdown(expiresAt, options = {}) {
|
|
4237
4262
|
const { intervalMs = 1e3 } = options;
|
|
4238
|
-
const nowRef = (0,
|
|
4263
|
+
const nowRef = (0, import_react17.useRef)(options.now ?? Date.now);
|
|
4239
4264
|
nowRef.current = options.now ?? Date.now;
|
|
4240
|
-
const [state, setState] = (0,
|
|
4241
|
-
(0,
|
|
4265
|
+
const [state, setState] = (0, import_react17.useState)(() => approvalCountdown(expiresAt, nowRef.current()));
|
|
4266
|
+
(0, import_react17.useEffect)(() => {
|
|
4242
4267
|
const read = /* @__PURE__ */ __name(() => approvalCountdown(expiresAt, nowRef.current()), "read");
|
|
4243
4268
|
const first = read();
|
|
4244
4269
|
setState(first);
|
|
@@ -4485,21 +4510,21 @@ function sumUsage(rows) {
|
|
|
4485
4510
|
__name(sumUsage, "sumUsage");
|
|
4486
4511
|
|
|
4487
4512
|
// src/use-agent-chat.ts
|
|
4488
|
-
var
|
|
4489
|
-
var
|
|
4513
|
+
var import_react18 = require("@ai-sdk/react");
|
|
4514
|
+
var import_react19 = require("react");
|
|
4490
4515
|
function useAgentChat(options) {
|
|
4491
|
-
const latest = (0,
|
|
4516
|
+
const latest = (0, import_react19.useRef)(options);
|
|
4492
4517
|
latest.current = options;
|
|
4493
|
-
const [runId, setRunId] = (0,
|
|
4494
|
-
const runIdRef = (0,
|
|
4518
|
+
const [runId, setRunId] = (0, import_react19.useState)(options.resumeRunId);
|
|
4519
|
+
const runIdRef = (0, import_react19.useRef)(runId);
|
|
4495
4520
|
runIdRef.current = runId;
|
|
4496
|
-
const settlingRunIdRef = (0,
|
|
4497
|
-
const autoResumeRunIdRef = (0,
|
|
4498
|
-
const [autoResume, setAutoResume] = (0,
|
|
4499
|
-
const [activeRunId, setActiveRunId] = (0,
|
|
4500
|
-
const regenerateNext = (0,
|
|
4501
|
-
const createdThreadId = (0,
|
|
4502
|
-
const client = (0,
|
|
4521
|
+
const settlingRunIdRef = (0, import_react19.useRef)(void 0);
|
|
4522
|
+
const autoResumeRunIdRef = (0, import_react19.useRef)(void 0);
|
|
4523
|
+
const [autoResume, setAutoResume] = (0, import_react19.useState)(false);
|
|
4524
|
+
const [activeRunId, setActiveRunId] = (0, import_react19.useState)(null);
|
|
4525
|
+
const regenerateNext = (0, import_react19.useRef)(false);
|
|
4526
|
+
const createdThreadId = (0, import_react19.useRef)(void 0);
|
|
4527
|
+
const client = (0, import_react19.useMemo)(() => {
|
|
4503
4528
|
if (options.backend) return options.backend;
|
|
4504
4529
|
if (options.client) return options.client;
|
|
4505
4530
|
return new AgentClient({
|
|
@@ -4515,11 +4540,11 @@ function useAgentChat(options) {
|
|
|
4515
4540
|
getHeaders: /* @__PURE__ */ __name(async () => mergeHeaders(latest.current), "getHeaders")
|
|
4516
4541
|
});
|
|
4517
4542
|
}, []);
|
|
4518
|
-
const [connection, setConnection] = (0,
|
|
4543
|
+
const [connection, setConnection] = (0, import_react19.useState)({
|
|
4519
4544
|
status: "live"
|
|
4520
4545
|
});
|
|
4521
|
-
const resyncAfterSettle = (0,
|
|
4522
|
-
(0,
|
|
4546
|
+
const resyncAfterSettle = (0, import_react19.useRef)(false);
|
|
4547
|
+
(0, import_react19.useEffect)(() => {
|
|
4523
4548
|
if (!options.resume || options.threadId === void 0) return;
|
|
4524
4549
|
let cancelled = false;
|
|
4525
4550
|
const threadId = options.threadId;
|
|
@@ -4539,7 +4564,7 @@ function useAgentChat(options) {
|
|
|
4539
4564
|
options.resume,
|
|
4540
4565
|
options.threadId
|
|
4541
4566
|
]);
|
|
4542
|
-
const transport = (0,
|
|
4567
|
+
const transport = (0, import_react19.useMemo)(() => {
|
|
4543
4568
|
function onMeta(meta) {
|
|
4544
4569
|
settlingRunIdRef.current = meta.runId;
|
|
4545
4570
|
setRunId(meta.runId);
|
|
@@ -4594,8 +4619,8 @@ function useAgentChat(options) {
|
|
|
4594
4619
|
}, "onAttemptStart")
|
|
4595
4620
|
});
|
|
4596
4621
|
}, []);
|
|
4597
|
-
const backgroundRef = (0,
|
|
4598
|
-
const chat = (0,
|
|
4622
|
+
const backgroundRef = (0, import_react19.useRef)(() => Promise.resolve());
|
|
4623
|
+
const chat = (0, import_react18.useChat)({
|
|
4599
4624
|
transport,
|
|
4600
4625
|
resume: options.resumeRunId !== void 0 || autoResume,
|
|
4601
4626
|
...options.threadId !== void 0 ? {
|
|
@@ -4643,7 +4668,7 @@ function useAgentChat(options) {
|
|
|
4643
4668
|
}
|
|
4644
4669
|
}, "onFinish")
|
|
4645
4670
|
});
|
|
4646
|
-
const chatRef = (0,
|
|
4671
|
+
const chatRef = (0, import_react19.useRef)(chat);
|
|
4647
4672
|
chatRef.current = chat;
|
|
4648
4673
|
async function resyncFromThread() {
|
|
4649
4674
|
const threadId = latest.current.threadId ?? createdThreadId.current;
|
|
@@ -4655,11 +4680,11 @@ function useAgentChat(options) {
|
|
|
4655
4680
|
}
|
|
4656
4681
|
}
|
|
4657
4682
|
__name(resyncFromThread, "resyncFromThread");
|
|
4658
|
-
const turnInFlight = (0,
|
|
4659
|
-
const isTurnInFlight = (0,
|
|
4683
|
+
const turnInFlight = (0, import_react19.useRef)(false);
|
|
4684
|
+
const isTurnInFlight = (0, import_react19.useCallback)(() => turnInFlight.current || transport.isAttemptLive, [
|
|
4660
4685
|
transport
|
|
4661
4686
|
]);
|
|
4662
|
-
const sendMessage = (0,
|
|
4687
|
+
const sendMessage = (0, import_react19.useCallback)(async (...args) => {
|
|
4663
4688
|
const blocked = latest.current.blocked;
|
|
4664
4689
|
if (blocked != null) throw new QuotaBlockedError(blocked);
|
|
4665
4690
|
if (isTurnInFlight()) return;
|
|
@@ -4672,15 +4697,15 @@ function useAgentChat(options) {
|
|
|
4672
4697
|
}, [
|
|
4673
4698
|
isTurnInFlight
|
|
4674
4699
|
]);
|
|
4675
|
-
const addToolResult = (0,
|
|
4700
|
+
const addToolResult = (0, import_react19.useCallback)(({ tool, toolCallId, output }) => chatRef.current.addToolResult({
|
|
4676
4701
|
tool,
|
|
4677
4702
|
toolCallId,
|
|
4678
4703
|
output
|
|
4679
4704
|
}), []);
|
|
4680
|
-
const [threads, setThreads] = (0,
|
|
4681
|
-
const [quota, setQuota] = (0,
|
|
4682
|
-
const [backgroundRuns, setBackgroundRuns] = (0,
|
|
4683
|
-
const refreshBackground = (0,
|
|
4705
|
+
const [threads, setThreads] = (0, import_react19.useState)([]);
|
|
4706
|
+
const [quota, setQuota] = (0, import_react19.useState)(null);
|
|
4707
|
+
const [backgroundRuns, setBackgroundRuns] = (0, import_react19.useState)([]);
|
|
4708
|
+
const refreshBackground = (0, import_react19.useCallback)(async () => {
|
|
4684
4709
|
const threadId = latest.current.threadId ?? createdThreadId.current;
|
|
4685
4710
|
if (threadId === void 0) {
|
|
4686
4711
|
return;
|
|
@@ -4705,7 +4730,7 @@ function useAgentChat(options) {
|
|
|
4705
4730
|
]);
|
|
4706
4731
|
backgroundRef.current = refreshBackground;
|
|
4707
4732
|
const isWorking = backgroundRuns.some((run) => run.status === "running");
|
|
4708
|
-
(0,
|
|
4733
|
+
(0, import_react19.useEffect)(() => {
|
|
4709
4734
|
if (options.background !== true || options.threadId === void 0) {
|
|
4710
4735
|
return;
|
|
4711
4736
|
}
|
|
@@ -4715,7 +4740,7 @@ function useAgentChat(options) {
|
|
|
4715
4740
|
options.threadId,
|
|
4716
4741
|
refreshBackground
|
|
4717
4742
|
]);
|
|
4718
|
-
(0,
|
|
4743
|
+
(0, import_react19.useEffect)(() => {
|
|
4719
4744
|
const every = latest.current.backgroundPollMs ?? 5e3;
|
|
4720
4745
|
if (latest.current.background !== true || !isWorking || every <= 0) {
|
|
4721
4746
|
return;
|
|
@@ -4726,26 +4751,26 @@ function useAgentChat(options) {
|
|
|
4726
4751
|
isWorking,
|
|
4727
4752
|
refreshBackground
|
|
4728
4753
|
]);
|
|
4729
|
-
const loadThreads = (0,
|
|
4754
|
+
const loadThreads = (0, import_react19.useCallback)(async () => {
|
|
4730
4755
|
const list = await client.listThreads();
|
|
4731
4756
|
setThreads(list);
|
|
4732
4757
|
return list;
|
|
4733
4758
|
}, [
|
|
4734
4759
|
client
|
|
4735
4760
|
]);
|
|
4736
|
-
const loadThread = (0,
|
|
4761
|
+
const loadThread = (0, import_react19.useCallback)((id) => client.getThread(id), [
|
|
4737
4762
|
client
|
|
4738
4763
|
]);
|
|
4739
|
-
const deleteThread = (0,
|
|
4764
|
+
const deleteThread = (0, import_react19.useCallback)(async (id) => {
|
|
4740
4765
|
await client.deleteThread(id);
|
|
4741
4766
|
setThreads((current) => current.filter((thread) => thread.id !== id));
|
|
4742
4767
|
}, [
|
|
4743
4768
|
client
|
|
4744
4769
|
]);
|
|
4745
|
-
const forkThread = (0,
|
|
4770
|
+
const forkThread = (0, import_react19.useCallback)((threadId, messageId) => requireBackendMethod(client, "forkFromMessage")(threadId, messageId), [
|
|
4746
4771
|
client
|
|
4747
4772
|
]);
|
|
4748
|
-
const renameThread = (0,
|
|
4773
|
+
const renameThread = (0, import_react19.useCallback)(async (id, title) => {
|
|
4749
4774
|
await client.updateThread(id, {
|
|
4750
4775
|
title
|
|
4751
4776
|
});
|
|
@@ -4756,24 +4781,24 @@ function useAgentChat(options) {
|
|
|
4756
4781
|
}, [
|
|
4757
4782
|
client
|
|
4758
4783
|
]);
|
|
4759
|
-
const promoteThread = (0,
|
|
4784
|
+
const promoteThread = (0, import_react19.useCallback)(async (id) => {
|
|
4760
4785
|
await requireBackendMethod(client, "promoteThread")(id);
|
|
4761
4786
|
await loadThreads();
|
|
4762
4787
|
}, [
|
|
4763
4788
|
client,
|
|
4764
4789
|
loadThreads
|
|
4765
4790
|
]);
|
|
4766
|
-
const truncateFromMessage = (0,
|
|
4791
|
+
const truncateFromMessage = (0, import_react19.useCallback)((threadId, messageId) => requireBackendMethod(client, "truncateFromMessage")(threadId, messageId).then(() => void 0), [
|
|
4767
4792
|
client
|
|
4768
4793
|
]);
|
|
4769
|
-
const loadQuota = (0,
|
|
4794
|
+
const loadQuota = (0, import_react19.useCallback)(async () => {
|
|
4770
4795
|
const today = await requireBackendMethod(client, "getQuotaToday")();
|
|
4771
4796
|
setQuota(today);
|
|
4772
4797
|
return today;
|
|
4773
4798
|
}, [
|
|
4774
4799
|
client
|
|
4775
4800
|
]);
|
|
4776
|
-
const cancel = (0,
|
|
4801
|
+
const cancel = (0, import_react19.useCallback)(async () => {
|
|
4777
4802
|
chatRef.current.stop();
|
|
4778
4803
|
const activeRunId2 = runIdRef.current;
|
|
4779
4804
|
if (activeRunId2) {
|
|
@@ -4785,7 +4810,7 @@ function useAgentChat(options) {
|
|
|
4785
4810
|
}, [
|
|
4786
4811
|
client
|
|
4787
4812
|
]);
|
|
4788
|
-
const approve = (0,
|
|
4813
|
+
const approve = (0, import_react19.useCallback)(async ({ toolCallId, remember, via }) => {
|
|
4789
4814
|
await requireBackendMethod(client, "approveToolCall")({
|
|
4790
4815
|
toolCallId,
|
|
4791
4816
|
...remember === true ? {
|
|
@@ -4798,7 +4823,7 @@ function useAgentChat(options) {
|
|
|
4798
4823
|
}, [
|
|
4799
4824
|
client
|
|
4800
4825
|
]);
|
|
4801
|
-
const reject = (0,
|
|
4826
|
+
const reject = (0, import_react19.useCallback)(async ({ toolCallId, reason, via }) => {
|
|
4802
4827
|
await requireBackendMethod(client, "rejectToolCall")({
|
|
4803
4828
|
toolCallId,
|
|
4804
4829
|
...reason !== void 0 ? {
|
|
@@ -4811,7 +4836,7 @@ function useAgentChat(options) {
|
|
|
4811
4836
|
}, [
|
|
4812
4837
|
client
|
|
4813
4838
|
]);
|
|
4814
|
-
const answer = (0,
|
|
4839
|
+
const answer = (0, import_react19.useCallback)(async ({ toolCallId, answers }) => {
|
|
4815
4840
|
await requireBackendMethod(client, "answerToolCall")({
|
|
4816
4841
|
toolCallId,
|
|
4817
4842
|
...answers !== void 0 ? {
|
|
@@ -4821,14 +4846,14 @@ function useAgentChat(options) {
|
|
|
4821
4846
|
}, [
|
|
4822
4847
|
client
|
|
4823
4848
|
]);
|
|
4824
|
-
const skip = (0,
|
|
4849
|
+
const skip = (0, import_react19.useCallback)(async ({ toolCallId }) => {
|
|
4825
4850
|
await requireBackendMethod(client, "skipToolCall")({
|
|
4826
4851
|
toolCallId
|
|
4827
4852
|
});
|
|
4828
4853
|
}, [
|
|
4829
4854
|
client
|
|
4830
4855
|
]);
|
|
4831
|
-
const regenerate = (0,
|
|
4856
|
+
const regenerate = (0, import_react19.useCallback)(() => {
|
|
4832
4857
|
const blocked = latest.current.blocked;
|
|
4833
4858
|
if (blocked != null) throw new QuotaBlockedError(blocked);
|
|
4834
4859
|
if (isTurnInFlight()) return;
|
|
@@ -4845,7 +4870,7 @@ function useAgentChat(options) {
|
|
|
4845
4870
|
isWorking,
|
|
4846
4871
|
refresh: refreshBackground
|
|
4847
4872
|
};
|
|
4848
|
-
const setThreadModel = (0,
|
|
4873
|
+
const setThreadModel = (0, import_react19.useCallback)(async (model) => {
|
|
4849
4874
|
const threadId = latest.current.threadId ?? createdThreadId.current;
|
|
4850
4875
|
if (threadId === void 0) {
|
|
4851
4876
|
throw new Error("setThreadModel: this chat has no thread yet");
|
|
@@ -4859,7 +4884,7 @@ function useAgentChat(options) {
|
|
|
4859
4884
|
}, [
|
|
4860
4885
|
client
|
|
4861
4886
|
]);
|
|
4862
|
-
const getThreadId = (0,
|
|
4887
|
+
const getThreadId = (0, import_react19.useCallback)(() => latest.current.threadId ?? createdThreadId.current, []);
|
|
4863
4888
|
const status = connection.status === "reconnecting" ? "reconnecting" : chat.status;
|
|
4864
4889
|
return {
|
|
4865
4890
|
...chat,
|
|
@@ -4926,6 +4951,7 @@ __name(mergeHeaders, "mergeHeaders");
|
|
|
4926
4951
|
AgentChatTransport,
|
|
4927
4952
|
AgentClient,
|
|
4928
4953
|
AgentHttpError,
|
|
4954
|
+
AmbientRenderUiContext,
|
|
4929
4955
|
ChatInput,
|
|
4930
4956
|
DEFAULT_SPEECH_LANG,
|
|
4931
4957
|
MessageItem,
|
|
@@ -4972,6 +4998,7 @@ __name(mergeHeaders, "mergeHeaders");
|
|
|
4972
4998
|
toolCatalogFrom,
|
|
4973
4999
|
useAgentChat,
|
|
4974
5000
|
useAgents,
|
|
5001
|
+
useAmbientRenderUi,
|
|
4975
5002
|
useApprovalCountdown,
|
|
4976
5003
|
useAttachments,
|
|
4977
5004
|
useChatTranscript,
|