@dudousxd/nestjs-agent-react 0.22.0 → 0.23.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 +5 -0
- package/dist/{client-CYlhK7XD.d.cts → client-ioKDyV2q.d.cts} +5 -1
- package/dist/{client-CYlhK7XD.d.ts → client-ioKDyV2q.d.ts} +5 -1
- package/dist/index.cjs +336 -263
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -12
- package/dist/index.d.ts +35 -12
- package/dist/index.js +171 -99
- package/dist/index.js.map +1 -1
- package/dist/media.cjs.map +1 -1
- package/dist/media.d.cts +1 -1
- package/dist/media.d.ts +1 -1
- package/dist/media.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -83,6 +83,7 @@ __export(src_exports, {
|
|
|
83
83
|
toolCatalogFrom: () => toolCatalogFrom,
|
|
84
84
|
useAgentBackend: () => useAgentBackend,
|
|
85
85
|
useAgentChat: () => useAgentChat,
|
|
86
|
+
useAgentConfig: () => useAgentConfig,
|
|
86
87
|
useAgents: () => useAgents,
|
|
87
88
|
useAmbientRenderUi: () => useAmbientRenderUi,
|
|
88
89
|
useApprovalCountdown: () => useApprovalCountdown,
|
|
@@ -305,6 +306,10 @@ var AgentClient = class {
|
|
|
305
306
|
listAgents() {
|
|
306
307
|
return this.request("GET", "/agents");
|
|
307
308
|
}
|
|
309
|
+
/** `GET <path>/config` — attachment limits and upload mode, and which features are on. */
|
|
310
|
+
getConfig() {
|
|
311
|
+
return this.request("GET", "/config");
|
|
312
|
+
}
|
|
308
313
|
/** `GET <path>/quota` — the caller's budget windows and the one blocking sends, if any. */
|
|
309
314
|
getQuota() {
|
|
310
315
|
return this.request("GET", "/quota");
|
|
@@ -1215,7 +1220,7 @@ function dragHasFiles(data) {
|
|
|
1215
1220
|
__name(dragHasFiles, "dragHasFiles");
|
|
1216
1221
|
|
|
1217
1222
|
// src/attachments/use-attachments.ts
|
|
1218
|
-
var
|
|
1223
|
+
var import_react7 = require("react");
|
|
1219
1224
|
|
|
1220
1225
|
// src/backend.ts
|
|
1221
1226
|
var AgentBackendUnsupportedError = class extends Error {
|
|
@@ -1237,6 +1242,9 @@ function requireBackendMethod(backend, name) {
|
|
|
1237
1242
|
}
|
|
1238
1243
|
__name(requireBackendMethod, "requireBackendMethod");
|
|
1239
1244
|
|
|
1245
|
+
// src/config/use-agent-config.ts
|
|
1246
|
+
var import_react6 = require("react");
|
|
1247
|
+
|
|
1240
1248
|
// src/provider.tsx
|
|
1241
1249
|
var import_react5 = require("react");
|
|
1242
1250
|
|
|
@@ -1801,6 +1809,59 @@ function useAgentBackend(own) {
|
|
|
1801
1809
|
}
|
|
1802
1810
|
__name(useAgentBackend, "useAgentBackend");
|
|
1803
1811
|
|
|
1812
|
+
// src/config/use-agent-config.ts
|
|
1813
|
+
var shared = /* @__PURE__ */ new WeakMap();
|
|
1814
|
+
function load(backend) {
|
|
1815
|
+
const getConfig = backend.getConfig;
|
|
1816
|
+
if (typeof getConfig !== "function") return void 0;
|
|
1817
|
+
let pending = shared.get(backend);
|
|
1818
|
+
if (pending === void 0) {
|
|
1819
|
+
pending = getConfig.call(backend).catch((error) => {
|
|
1820
|
+
shared.delete(backend);
|
|
1821
|
+
throw error;
|
|
1822
|
+
});
|
|
1823
|
+
shared.set(backend, pending);
|
|
1824
|
+
}
|
|
1825
|
+
return pending;
|
|
1826
|
+
}
|
|
1827
|
+
__name(load, "load");
|
|
1828
|
+
function useAgentConfig(options = {}) {
|
|
1829
|
+
const backend = useAgentBackend(options.backend);
|
|
1830
|
+
const enabled = options.enabled !== false;
|
|
1831
|
+
const [config, setConfig] = (0, import_react6.useState)(void 0);
|
|
1832
|
+
const [isLoading, setLoading] = (0, import_react6.useState)(false);
|
|
1833
|
+
const [error, setError] = (0, import_react6.useState)(null);
|
|
1834
|
+
(0, import_react6.useEffect)(() => {
|
|
1835
|
+
if (!enabled) return;
|
|
1836
|
+
const pending = load(backend);
|
|
1837
|
+
if (pending === void 0) return;
|
|
1838
|
+
let cancelled = false;
|
|
1839
|
+
setLoading(true);
|
|
1840
|
+
pending.then((loaded) => {
|
|
1841
|
+
if (cancelled) return;
|
|
1842
|
+
setConfig(loaded !== null && typeof loaded === "object" ? loaded : void 0);
|
|
1843
|
+
setError(null);
|
|
1844
|
+
setLoading(false);
|
|
1845
|
+
}, (failure) => {
|
|
1846
|
+
if (cancelled) return;
|
|
1847
|
+
setError(failure instanceof Error ? failure : new Error(String(failure)));
|
|
1848
|
+
setLoading(false);
|
|
1849
|
+
});
|
|
1850
|
+
return () => {
|
|
1851
|
+
cancelled = true;
|
|
1852
|
+
};
|
|
1853
|
+
}, [
|
|
1854
|
+
backend,
|
|
1855
|
+
enabled
|
|
1856
|
+
]);
|
|
1857
|
+
return {
|
|
1858
|
+
config,
|
|
1859
|
+
isLoading,
|
|
1860
|
+
error
|
|
1861
|
+
};
|
|
1862
|
+
}
|
|
1863
|
+
__name(useAgentConfig, "useAgentConfig");
|
|
1864
|
+
|
|
1804
1865
|
// src/attachments/use-attachments.ts
|
|
1805
1866
|
var DEFAULT_REJECTION = {
|
|
1806
1867
|
type: /* @__PURE__ */ __name((file) => `${file.name} is not a supported file type`, "type"),
|
|
@@ -1810,26 +1871,40 @@ var DEFAULT_REJECTION = {
|
|
|
1810
1871
|
var sequence = 0;
|
|
1811
1872
|
function useAttachments(options = {}) {
|
|
1812
1873
|
const backend = useAgentBackend(options.backend);
|
|
1813
|
-
const
|
|
1814
|
-
...options,
|
|
1874
|
+
const { config } = useAgentConfig({
|
|
1815
1875
|
backend
|
|
1816
1876
|
});
|
|
1817
|
-
|
|
1877
|
+
const limits = config?.attachments;
|
|
1878
|
+
const accept = options.accept ?? limits?.allowedContentTypes;
|
|
1879
|
+
const maxBytes = options.maxBytes ?? limits?.maxBytes;
|
|
1880
|
+
const maxFiles = options.maxFiles ?? limits?.maxPerMessage;
|
|
1881
|
+
const effective = {
|
|
1818
1882
|
...options,
|
|
1819
|
-
backend
|
|
1883
|
+
backend,
|
|
1884
|
+
...accept !== void 0 ? {
|
|
1885
|
+
accept
|
|
1886
|
+
} : {},
|
|
1887
|
+
...maxBytes !== void 0 ? {
|
|
1888
|
+
maxBytes
|
|
1889
|
+
} : {},
|
|
1890
|
+
...maxFiles !== void 0 ? {
|
|
1891
|
+
maxFiles
|
|
1892
|
+
} : {}
|
|
1820
1893
|
};
|
|
1821
|
-
const
|
|
1822
|
-
|
|
1894
|
+
const latest = (0, import_react7.useRef)(effective);
|
|
1895
|
+
latest.current = effective;
|
|
1896
|
+
const [items, setItems] = (0, import_react7.useState)([]);
|
|
1897
|
+
const itemsRef = (0, import_react7.useRef)(items);
|
|
1823
1898
|
itemsRef.current = items;
|
|
1824
|
-
const controllers = (0,
|
|
1825
|
-
const [dragDepth, setDragDepth] = (0,
|
|
1826
|
-
const patch = (0,
|
|
1899
|
+
const controllers = (0, import_react7.useRef)(/* @__PURE__ */ new Map());
|
|
1900
|
+
const [dragDepth, setDragDepth] = (0, import_react7.useState)(0);
|
|
1901
|
+
const patch = (0, import_react7.useCallback)((id, change) => {
|
|
1827
1902
|
setItems((current) => current.map((item) => item.id === id ? {
|
|
1828
1903
|
...item,
|
|
1829
1904
|
...change
|
|
1830
1905
|
} : item));
|
|
1831
1906
|
}, []);
|
|
1832
|
-
const start = (0,
|
|
1907
|
+
const start = (0, import_react7.useCallback)((item) => {
|
|
1833
1908
|
const { upload, backend: backend2 } = latest.current;
|
|
1834
1909
|
const run = upload ?? (backend2.uploadAttachment !== void 0 ? backend2.uploadAttachment.bind(backend2) : void 0);
|
|
1835
1910
|
if (run === void 0) {
|
|
@@ -1865,11 +1940,11 @@ function useAttachments(options = {}) {
|
|
|
1865
1940
|
}, [
|
|
1866
1941
|
patch
|
|
1867
1942
|
]);
|
|
1868
|
-
const add = (0,
|
|
1943
|
+
const add = (0, import_react7.useCallback)((files) => {
|
|
1869
1944
|
if (files == null) return;
|
|
1870
|
-
const { accept: accept2, maxBytes, maxFiles, describeRejection } = latest.current;
|
|
1945
|
+
const { accept: accept2, maxBytes: maxBytes2, maxFiles: maxFiles2, describeRejection } = latest.current;
|
|
1871
1946
|
const describe = /* @__PURE__ */ __name((reason, file) => describeRejection?.(reason, file) ?? DEFAULT_REJECTION[reason](file), "describe");
|
|
1872
|
-
let room =
|
|
1947
|
+
let room = maxFiles2 === void 0 ? Number.POSITIVE_INFINITY : maxFiles2 - itemsRef.current.filter((item) => item.status !== "rejected").length;
|
|
1873
1948
|
const staged = [];
|
|
1874
1949
|
for (const file of Array.from(files)) {
|
|
1875
1950
|
sequence += 1;
|
|
@@ -1881,7 +1956,7 @@ function useAttachments(options = {}) {
|
|
|
1881
1956
|
type: file.type,
|
|
1882
1957
|
progress: 0
|
|
1883
1958
|
};
|
|
1884
|
-
const reason = !acceptsFile(accept2, file) ? "type" :
|
|
1959
|
+
const reason = !acceptsFile(accept2, file) ? "type" : maxBytes2 !== void 0 && file.size > maxBytes2 ? "size" : room <= 0 ? "count" : void 0;
|
|
1885
1960
|
if (reason !== void 0) {
|
|
1886
1961
|
staged.push({
|
|
1887
1962
|
...base,
|
|
@@ -1911,7 +1986,7 @@ function useAttachments(options = {}) {
|
|
|
1911
1986
|
}, [
|
|
1912
1987
|
start
|
|
1913
1988
|
]);
|
|
1914
|
-
const release = (0,
|
|
1989
|
+
const release = (0, import_react7.useCallback)((item) => {
|
|
1915
1990
|
if (item === void 0) return;
|
|
1916
1991
|
controllers.current.get(item.id)?.abort();
|
|
1917
1992
|
controllers.current.delete(item.id);
|
|
@@ -1919,19 +1994,19 @@ function useAttachments(options = {}) {
|
|
|
1919
1994
|
URL.revokeObjectURL(item.previewUrl);
|
|
1920
1995
|
}
|
|
1921
1996
|
}, []);
|
|
1922
|
-
const remove = (0,
|
|
1997
|
+
const remove = (0, import_react7.useCallback)((id) => {
|
|
1923
1998
|
release(itemsRef.current.find((item) => item.id === id));
|
|
1924
1999
|
setItems((current) => current.filter((item) => item.id !== id));
|
|
1925
2000
|
}, [
|
|
1926
2001
|
release
|
|
1927
2002
|
]);
|
|
1928
|
-
const clear = (0,
|
|
2003
|
+
const clear = (0, import_react7.useCallback)(() => {
|
|
1929
2004
|
for (const item of itemsRef.current) release(item);
|
|
1930
2005
|
setItems([]);
|
|
1931
2006
|
}, [
|
|
1932
2007
|
release
|
|
1933
2008
|
]);
|
|
1934
|
-
const retry = (0,
|
|
2009
|
+
const retry = (0, import_react7.useCallback)((id) => {
|
|
1935
2010
|
const item = itemsRef.current.find((candidate) => candidate.id === id);
|
|
1936
2011
|
if (item === void 0 || item.status !== "error") return;
|
|
1937
2012
|
const { error: _previous, ...rest } = item;
|
|
@@ -1945,12 +2020,12 @@ function useAttachments(options = {}) {
|
|
|
1945
2020
|
}, [
|
|
1946
2021
|
start
|
|
1947
2022
|
]);
|
|
1948
|
-
(0,
|
|
2023
|
+
(0, import_react7.useEffect)(() => () => {
|
|
1949
2024
|
for (const item of itemsRef.current) release(item);
|
|
1950
2025
|
}, [
|
|
1951
2026
|
release
|
|
1952
2027
|
]);
|
|
1953
|
-
const onPaste = (0,
|
|
2028
|
+
const onPaste = (0, import_react7.useCallback)((event) => {
|
|
1954
2029
|
const files = filesFromClipboard(event.clipboardData);
|
|
1955
2030
|
if (files.length === 0) return;
|
|
1956
2031
|
event.preventDefault();
|
|
@@ -1958,7 +2033,7 @@ function useAttachments(options = {}) {
|
|
|
1958
2033
|
}, [
|
|
1959
2034
|
add
|
|
1960
2035
|
]);
|
|
1961
|
-
const dropZoneProps = (0,
|
|
2036
|
+
const dropZoneProps = (0, import_react7.useMemo)(() => ({
|
|
1962
2037
|
onDragEnter: /* @__PURE__ */ __name((event) => {
|
|
1963
2038
|
if (!dragHasFiles(event.dataTransfer)) return;
|
|
1964
2039
|
event.preventDefault();
|
|
@@ -1980,11 +2055,10 @@ function useAttachments(options = {}) {
|
|
|
1980
2055
|
}), [
|
|
1981
2056
|
add
|
|
1982
2057
|
]);
|
|
1983
|
-
const
|
|
1984
|
-
const inputProps = (0, import_react6.useMemo)(() => ({
|
|
2058
|
+
const inputProps = (0, import_react7.useMemo)(() => ({
|
|
1985
2059
|
type: "file",
|
|
1986
2060
|
accept: typeof accept === "string" ? accept : accept?.join(","),
|
|
1987
|
-
multiple:
|
|
2061
|
+
multiple: maxFiles === void 0 || maxFiles > 1,
|
|
1988
2062
|
onChange: /* @__PURE__ */ __name((event) => {
|
|
1989
2063
|
const input = event.currentTarget;
|
|
1990
2064
|
add(input.files);
|
|
@@ -1992,12 +2066,11 @@ function useAttachments(options = {}) {
|
|
|
1992
2066
|
}, "onChange")
|
|
1993
2067
|
}), [
|
|
1994
2068
|
accept,
|
|
1995
|
-
|
|
2069
|
+
maxFiles,
|
|
1996
2070
|
add
|
|
1997
2071
|
]);
|
|
1998
|
-
return (0,
|
|
2072
|
+
return (0, import_react7.useMemo)(() => {
|
|
1999
2073
|
const ready = items.filter((item) => item.status === "ready" && item.attachment !== void 0);
|
|
2000
|
-
const attachments = ready.map((item) => item.attachment);
|
|
2001
2074
|
return {
|
|
2002
2075
|
items,
|
|
2003
2076
|
add,
|
|
@@ -2005,9 +2078,8 @@ function useAttachments(options = {}) {
|
|
|
2005
2078
|
retry,
|
|
2006
2079
|
clear,
|
|
2007
2080
|
isUploading: items.some((item) => item.status === "uploading"),
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
mediaId: attachment.mediaId
|
|
2081
|
+
refs: ready.map((item) => ({
|
|
2082
|
+
mediaId: item.attachment.mediaId
|
|
2011
2083
|
})),
|
|
2012
2084
|
inputProps,
|
|
2013
2085
|
dropZoneProps,
|
|
@@ -2029,18 +2101,18 @@ function useAttachments(options = {}) {
|
|
|
2029
2101
|
__name(useAttachments, "useAttachments");
|
|
2030
2102
|
|
|
2031
2103
|
// src/catalog/use-agents.ts
|
|
2032
|
-
var
|
|
2104
|
+
var import_react9 = require("react");
|
|
2033
2105
|
|
|
2034
2106
|
// src/catalog/use-resource.ts
|
|
2035
|
-
var
|
|
2036
|
-
function useResource(
|
|
2037
|
-
const [data, setData] = (0,
|
|
2038
|
-
const [isLoading, setIsLoading] = (0,
|
|
2039
|
-
const [error, setError] = (0,
|
|
2040
|
-
const loadRef = (0,
|
|
2041
|
-
loadRef.current =
|
|
2042
|
-
const generation = (0,
|
|
2043
|
-
const refresh = (0,
|
|
2107
|
+
var import_react8 = require("react");
|
|
2108
|
+
function useResource(load3, key, enabled) {
|
|
2109
|
+
const [data, setData] = (0, import_react8.useState)(void 0);
|
|
2110
|
+
const [isLoading, setIsLoading] = (0, import_react8.useState)(enabled);
|
|
2111
|
+
const [error, setError] = (0, import_react8.useState)(null);
|
|
2112
|
+
const loadRef = (0, import_react8.useRef)(load3);
|
|
2113
|
+
loadRef.current = load3;
|
|
2114
|
+
const generation = (0, import_react8.useRef)(0);
|
|
2115
|
+
const refresh = (0, import_react8.useCallback)(async () => {
|
|
2044
2116
|
const mine = ++generation.current;
|
|
2045
2117
|
setIsLoading(true);
|
|
2046
2118
|
try {
|
|
@@ -2055,7 +2127,7 @@ function useResource(load2, key, enabled) {
|
|
|
2055
2127
|
if (mine === generation.current) setIsLoading(false);
|
|
2056
2128
|
}
|
|
2057
2129
|
}, []);
|
|
2058
|
-
(0,
|
|
2130
|
+
(0, import_react8.useEffect)(() => {
|
|
2059
2131
|
if (!enabled) return;
|
|
2060
2132
|
void refresh();
|
|
2061
2133
|
}, [
|
|
@@ -2077,7 +2149,7 @@ function useAgents(options = {}) {
|
|
|
2077
2149
|
const { enabled = true } = options;
|
|
2078
2150
|
const backend = useAgentBackend(options.backend);
|
|
2079
2151
|
const { data, isLoading, error, refresh } = useResource(() => requireBackendMethod(backend, "listAgents")(), "", enabled);
|
|
2080
|
-
return (0,
|
|
2152
|
+
return (0, import_react9.useMemo)(() => {
|
|
2081
2153
|
const agents = data ?? [];
|
|
2082
2154
|
return {
|
|
2083
2155
|
agents,
|
|
@@ -2096,12 +2168,12 @@ function useAgents(options = {}) {
|
|
|
2096
2168
|
__name(useAgents, "useAgents");
|
|
2097
2169
|
|
|
2098
2170
|
// src/catalog/use-models.ts
|
|
2099
|
-
var
|
|
2171
|
+
var import_react10 = require("react");
|
|
2100
2172
|
function useModels(options = {}) {
|
|
2101
2173
|
const { agent, enabled = true } = options;
|
|
2102
2174
|
const backend = useAgentBackend(options.backend);
|
|
2103
2175
|
const { data, isLoading, error, refresh } = useResource(() => requireBackendMethod(backend, "listModels")(agent), `${agent ?? ""}`, enabled);
|
|
2104
|
-
return (0,
|
|
2176
|
+
return (0, import_react10.useMemo)(() => {
|
|
2105
2177
|
const providers = data?.providers ?? [];
|
|
2106
2178
|
const models = providers.flatMap((provider) => provider.models.map((model) => ({
|
|
2107
2179
|
...model,
|
|
@@ -2131,7 +2203,7 @@ function useModels(options = {}) {
|
|
|
2131
2203
|
__name(useModels, "useModels");
|
|
2132
2204
|
|
|
2133
2205
|
// src/quota/use-quota.ts
|
|
2134
|
-
var
|
|
2206
|
+
var import_react11 = require("react");
|
|
2135
2207
|
|
|
2136
2208
|
// src/threads/threads-events.ts
|
|
2137
2209
|
var listeners = /* @__PURE__ */ new WeakMap();
|
|
@@ -2159,7 +2231,7 @@ function useQuota(options = {}) {
|
|
|
2159
2231
|
const { enabled = true, pollMs } = options;
|
|
2160
2232
|
const backend = useAgentBackend(options.backend);
|
|
2161
2233
|
const { data, isLoading, error, refresh } = useResource(() => requireBackendMethod(backend, "getQuota")(), "", enabled);
|
|
2162
|
-
(0,
|
|
2234
|
+
(0, import_react11.useEffect)(() => {
|
|
2163
2235
|
if (!enabled) return;
|
|
2164
2236
|
return onThreadsEvent(backend, (event) => {
|
|
2165
2237
|
if (event.type === "changed") void refresh();
|
|
@@ -2169,7 +2241,7 @@ function useQuota(options = {}) {
|
|
|
2169
2241
|
enabled,
|
|
2170
2242
|
refresh
|
|
2171
2243
|
]);
|
|
2172
|
-
(0,
|
|
2244
|
+
(0, import_react11.useEffect)(() => {
|
|
2173
2245
|
if (!enabled || pollMs === void 0 || pollMs <= 0) return;
|
|
2174
2246
|
const timer = setInterval(() => void refresh(), pollMs);
|
|
2175
2247
|
return () => clearInterval(timer);
|
|
@@ -2178,7 +2250,7 @@ function useQuota(options = {}) {
|
|
|
2178
2250
|
pollMs,
|
|
2179
2251
|
refresh
|
|
2180
2252
|
]);
|
|
2181
|
-
return (0,
|
|
2253
|
+
return (0, import_react11.useMemo)(() => {
|
|
2182
2254
|
const windows = data?.windows ?? [];
|
|
2183
2255
|
return {
|
|
2184
2256
|
report: data,
|
|
@@ -2200,10 +2272,10 @@ function useQuota(options = {}) {
|
|
|
2200
2272
|
__name(useQuota, "useQuota");
|
|
2201
2273
|
|
|
2202
2274
|
// src/feedback/use-message-feedback.ts
|
|
2203
|
-
var
|
|
2275
|
+
var import_react12 = require("react");
|
|
2204
2276
|
function useMessageFeedback(options = {}) {
|
|
2205
2277
|
const backend = useAgentBackend(options.backend);
|
|
2206
|
-
const latest = (0,
|
|
2278
|
+
const latest = (0, import_react12.useRef)({
|
|
2207
2279
|
...options,
|
|
2208
2280
|
backend
|
|
2209
2281
|
});
|
|
@@ -2211,23 +2283,23 @@ function useMessageFeedback(options = {}) {
|
|
|
2211
2283
|
...options,
|
|
2212
2284
|
backend
|
|
2213
2285
|
};
|
|
2214
|
-
const [local, setLocal] = (0,
|
|
2215
|
-
const [pending, setPending] = (0,
|
|
2216
|
-
const [error, setError] = (0,
|
|
2217
|
-
const localRef = (0,
|
|
2286
|
+
const [local, setLocal] = (0, import_react12.useState)(/* @__PURE__ */ new Map());
|
|
2287
|
+
const [pending, setPending] = (0, import_react12.useState)(/* @__PURE__ */ new Set());
|
|
2288
|
+
const [error, setError] = (0, import_react12.useState)(null);
|
|
2289
|
+
const localRef = (0, import_react12.useRef)(local);
|
|
2218
2290
|
localRef.current = local;
|
|
2219
|
-
const resolved = (0,
|
|
2220
|
-
const feedbackOf = (0,
|
|
2291
|
+
const resolved = (0, import_react12.useRef)(/* @__PURE__ */ new Map());
|
|
2292
|
+
const feedbackOf = (0, import_react12.useCallback)((message) => {
|
|
2221
2293
|
const mine = local.get(message.id);
|
|
2222
2294
|
if (mine !== void 0) return mine.feedback;
|
|
2223
2295
|
return metadataOf(message).feedback ?? null;
|
|
2224
2296
|
}, [
|
|
2225
2297
|
local
|
|
2226
2298
|
]);
|
|
2227
|
-
const isPending = (0,
|
|
2299
|
+
const isPending = (0, import_react12.useCallback)((message) => pending.has(message.id), [
|
|
2228
2300
|
pending
|
|
2229
2301
|
]);
|
|
2230
|
-
const storedIdFor = (0,
|
|
2302
|
+
const storedIdFor = (0, import_react12.useCallback)(async (message) => {
|
|
2231
2303
|
const runId = metadataOf(message).runId;
|
|
2232
2304
|
if (runId === void 0) return message.id;
|
|
2233
2305
|
const known = resolved.current.get(message.id);
|
|
@@ -2247,7 +2319,7 @@ function useMessageFeedback(options = {}) {
|
|
|
2247
2319
|
resolved.current.set(message.id, row.id);
|
|
2248
2320
|
return row.id;
|
|
2249
2321
|
}, []);
|
|
2250
|
-
const rate = (0,
|
|
2322
|
+
const rate = (0, import_react12.useCallback)(async (message, value, comment) => {
|
|
2251
2323
|
const setFeedback = requireBackendMethod(latest.current.backend, "setMessageFeedback");
|
|
2252
2324
|
const had = localRef.current.get(message.id);
|
|
2253
2325
|
const optimistic = value === null ? null : {
|
|
@@ -2293,7 +2365,7 @@ function useMessageFeedback(options = {}) {
|
|
|
2293
2365
|
}, [
|
|
2294
2366
|
storedIdFor
|
|
2295
2367
|
]);
|
|
2296
|
-
const toggle = (0,
|
|
2368
|
+
const toggle = (0, import_react12.useCallback)((message, value) => {
|
|
2297
2369
|
const mine = localRef.current.get(message.id);
|
|
2298
2370
|
const current = mine !== void 0 ? mine.feedback : metadataOf(message).feedback ?? null;
|
|
2299
2371
|
return rate(message, current?.value === value ? null : value);
|
|
@@ -2316,17 +2388,17 @@ function metadataOf(message) {
|
|
|
2316
2388
|
__name(metadataOf, "metadataOf");
|
|
2317
2389
|
|
|
2318
2390
|
// src/threads/use-threads.ts
|
|
2319
|
-
var
|
|
2391
|
+
var import_react13 = require("react");
|
|
2320
2392
|
function useThreads(options = {}) {
|
|
2321
2393
|
const { enabled = true } = options;
|
|
2322
2394
|
const backend = useAgentBackend(options.backend);
|
|
2323
|
-
const [threads, setThreads] = (0,
|
|
2324
|
-
const [isLoading, setIsLoading] = (0,
|
|
2325
|
-
const [error, setError] = (0,
|
|
2326
|
-
const threadsRef = (0,
|
|
2395
|
+
const [threads, setThreads] = (0, import_react13.useState)([]);
|
|
2396
|
+
const [isLoading, setIsLoading] = (0, import_react13.useState)(enabled);
|
|
2397
|
+
const [error, setError] = (0, import_react13.useState)(null);
|
|
2398
|
+
const threadsRef = (0, import_react13.useRef)(threads);
|
|
2327
2399
|
threadsRef.current = threads;
|
|
2328
|
-
const generation = (0,
|
|
2329
|
-
const refresh = (0,
|
|
2400
|
+
const generation = (0, import_react13.useRef)(0);
|
|
2401
|
+
const refresh = (0, import_react13.useCallback)(async () => {
|
|
2330
2402
|
const mine = ++generation.current;
|
|
2331
2403
|
setIsLoading(true);
|
|
2332
2404
|
try {
|
|
@@ -2343,7 +2415,7 @@ function useThreads(options = {}) {
|
|
|
2343
2415
|
}, [
|
|
2344
2416
|
backend
|
|
2345
2417
|
]);
|
|
2346
|
-
(0,
|
|
2418
|
+
(0, import_react13.useEffect)(() => {
|
|
2347
2419
|
if (!enabled) return;
|
|
2348
2420
|
void refresh();
|
|
2349
2421
|
return onThreadsEvent(backend, (event) => {
|
|
@@ -2363,7 +2435,7 @@ function useThreads(options = {}) {
|
|
|
2363
2435
|
enabled,
|
|
2364
2436
|
refresh
|
|
2365
2437
|
]);
|
|
2366
|
-
const rename = (0,
|
|
2438
|
+
const rename = (0, import_react13.useCallback)(async (id, title) => {
|
|
2367
2439
|
const before = threadsRef.current;
|
|
2368
2440
|
setThreads((current) => current.map((thread) => thread.id === id ? {
|
|
2369
2441
|
...thread,
|
|
@@ -2385,7 +2457,7 @@ function useThreads(options = {}) {
|
|
|
2385
2457
|
}, [
|
|
2386
2458
|
backend
|
|
2387
2459
|
]);
|
|
2388
|
-
const remove = (0,
|
|
2460
|
+
const remove = (0, import_react13.useCallback)(async (id) => {
|
|
2389
2461
|
const before = threadsRef.current;
|
|
2390
2462
|
setThreads((current) => current.filter((thread) => thread.id !== id));
|
|
2391
2463
|
try {
|
|
@@ -2460,10 +2532,10 @@ function backgroundRunsFromThread(messages) {
|
|
|
2460
2532
|
__name(backgroundRunsFromThread, "backgroundRunsFromThread");
|
|
2461
2533
|
|
|
2462
2534
|
// src/components/chat-input.tsx
|
|
2463
|
-
var
|
|
2535
|
+
var import_react15 = __toESM(require("react"), 1);
|
|
2464
2536
|
|
|
2465
2537
|
// src/components/use-speech-recognition.ts
|
|
2466
|
-
var
|
|
2538
|
+
var import_react14 = require("react");
|
|
2467
2539
|
function getRecognitionCtor() {
|
|
2468
2540
|
if (typeof window === "undefined") return null;
|
|
2469
2541
|
const scope = window;
|
|
@@ -2471,15 +2543,15 @@ function getRecognitionCtor() {
|
|
|
2471
2543
|
}
|
|
2472
2544
|
__name(getRecognitionCtor, "getRecognitionCtor");
|
|
2473
2545
|
function useSpeechRecognition({ lang = "en-US", onFinalTranscript, onInterimTranscript }) {
|
|
2474
|
-
const recognitionRef = (0,
|
|
2475
|
-
const [isListening, setIsListening] = (0,
|
|
2476
|
-
const ctor = (0,
|
|
2546
|
+
const recognitionRef = (0, import_react14.useRef)(null);
|
|
2547
|
+
const [isListening, setIsListening] = (0, import_react14.useState)(false);
|
|
2548
|
+
const ctor = (0, import_react14.useMemo)(() => getRecognitionCtor(), []);
|
|
2477
2549
|
const isSupported = ctor !== null;
|
|
2478
|
-
const finalRef = (0,
|
|
2479
|
-
const interimRef = (0,
|
|
2550
|
+
const finalRef = (0, import_react14.useRef)(onFinalTranscript);
|
|
2551
|
+
const interimRef = (0, import_react14.useRef)(onInterimTranscript);
|
|
2480
2552
|
finalRef.current = onFinalTranscript;
|
|
2481
2553
|
interimRef.current = onInterimTranscript;
|
|
2482
|
-
(0,
|
|
2554
|
+
(0, import_react14.useEffect)(() => {
|
|
2483
2555
|
if (!ctor) return;
|
|
2484
2556
|
const recognition = new ctor();
|
|
2485
2557
|
recognition.lang = lang;
|
|
@@ -2518,7 +2590,7 @@ function useSpeechRecognition({ lang = "en-US", onFinalTranscript, onInterimTran
|
|
|
2518
2590
|
ctor,
|
|
2519
2591
|
lang
|
|
2520
2592
|
]);
|
|
2521
|
-
const start = (0,
|
|
2593
|
+
const start = (0, import_react14.useCallback)(() => {
|
|
2522
2594
|
const recognition = recognitionRef.current;
|
|
2523
2595
|
if (!recognition) return;
|
|
2524
2596
|
try {
|
|
@@ -2528,7 +2600,7 @@ function useSpeechRecognition({ lang = "en-US", onFinalTranscript, onInterimTran
|
|
|
2528
2600
|
console.warn("SpeechRecognition start failed", error);
|
|
2529
2601
|
}
|
|
2530
2602
|
}, []);
|
|
2531
|
-
const stop = (0,
|
|
2603
|
+
const stop = (0, import_react14.useCallback)(() => {
|
|
2532
2604
|
const recognition = recognitionRef.current;
|
|
2533
2605
|
if (!recognition) return;
|
|
2534
2606
|
try {
|
|
@@ -2547,8 +2619,8 @@ __name(useSpeechRecognition, "useSpeechRecognition");
|
|
|
2547
2619
|
|
|
2548
2620
|
// src/components/chat-input.tsx
|
|
2549
2621
|
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 }) {
|
|
2550
|
-
const [value, setValue] = (0,
|
|
2551
|
-
const [interim, setInterim] = (0,
|
|
2622
|
+
const [value, setValue] = (0, import_react15.useState)("");
|
|
2623
|
+
const [interim, setInterim] = (0, import_react15.useState)("");
|
|
2552
2624
|
const speech = useSpeechRecognition({
|
|
2553
2625
|
lang: speechLang,
|
|
2554
2626
|
onFinalTranscript: /* @__PURE__ */ __name((text) => {
|
|
@@ -2559,7 +2631,7 @@ function ChatInput({ onSubmit, disabled, placeholder, rows = 2, enableSpeech = t
|
|
|
2559
2631
|
}, "onFinalTranscript"),
|
|
2560
2632
|
onInterimTranscript: /* @__PURE__ */ __name((text) => setInterim(text), "onInterimTranscript")
|
|
2561
2633
|
});
|
|
2562
|
-
(0,
|
|
2634
|
+
(0, import_react15.useEffect)(() => {
|
|
2563
2635
|
if (!speech.isListening) setInterim("");
|
|
2564
2636
|
}, [
|
|
2565
2637
|
speech.isListening
|
|
@@ -2587,9 +2659,9 @@ function ChatInput({ onSubmit, disabled, placeholder, rows = 2, enableSpeech = t
|
|
|
2587
2659
|
const displayValue = speech.isListening && interim ? `${value}${value && !value.endsWith(" ") ? " " : ""}${interim}` : value;
|
|
2588
2660
|
const showMic = enableSpeech && speech.isSupported;
|
|
2589
2661
|
const showStop = isStreaming && onStop !== void 0;
|
|
2590
|
-
return /* @__PURE__ */
|
|
2662
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
2591
2663
|
className
|
|
2592
|
-
}, /* @__PURE__ */
|
|
2664
|
+
}, /* @__PURE__ */ import_react15.default.createElement("textarea", {
|
|
2593
2665
|
className: textareaClassName,
|
|
2594
2666
|
rows,
|
|
2595
2667
|
value: displayValue,
|
|
@@ -2600,17 +2672,17 @@ function ChatInput({ onSubmit, disabled, placeholder, rows = 2, enableSpeech = t
|
|
|
2600
2672
|
}, "onChange"),
|
|
2601
2673
|
onKeyDown: handleKeyDown,
|
|
2602
2674
|
placeholder: placeholder ?? "Ask something (Enter to send, Shift+Enter for newline)"
|
|
2603
|
-
}), /* @__PURE__ */
|
|
2675
|
+
}), /* @__PURE__ */ import_react15.default.createElement("button", {
|
|
2604
2676
|
type: "button",
|
|
2605
2677
|
className: sendButtonClassName,
|
|
2606
2678
|
onClick: submit,
|
|
2607
2679
|
disabled: disabled || !value.trim()
|
|
2608
|
-
}, sendLabel), showStop ? /* @__PURE__ */
|
|
2680
|
+
}, sendLabel), showStop ? /* @__PURE__ */ import_react15.default.createElement("button", {
|
|
2609
2681
|
type: "button",
|
|
2610
2682
|
className: stopButtonClassName,
|
|
2611
2683
|
onClick: /* @__PURE__ */ __name(() => void onStop(), "onClick"),
|
|
2612
2684
|
"aria-label": "Stop generating"
|
|
2613
|
-
}, stopLabel) : null, showMic ? /* @__PURE__ */
|
|
2685
|
+
}, stopLabel) : null, showMic ? /* @__PURE__ */ import_react15.default.createElement("button", {
|
|
2614
2686
|
type: "button",
|
|
2615
2687
|
className: micButtonClassName,
|
|
2616
2688
|
onClick: toggleMic,
|
|
@@ -2623,10 +2695,10 @@ function ChatInput({ onSubmit, disabled, placeholder, rows = 2, enableSpeech = t
|
|
|
2623
2695
|
__name(ChatInput, "ChatInput");
|
|
2624
2696
|
|
|
2625
2697
|
// src/components/message-item.tsx
|
|
2626
|
-
var
|
|
2698
|
+
var import_react18 = __toESM(require("react"), 1);
|
|
2627
2699
|
|
|
2628
2700
|
// src/transcript/use-chat-transcript.ts
|
|
2629
|
-
var
|
|
2701
|
+
var import_react17 = require("react");
|
|
2630
2702
|
|
|
2631
2703
|
// src/transcript/model.ts
|
|
2632
2704
|
var import_nestjs_agent_core2 = require("@dudousxd/nestjs-agent-core");
|
|
@@ -3603,11 +3675,11 @@ function formatCostUsd(cost) {
|
|
|
3603
3675
|
__name(formatCostUsd, "formatCostUsd");
|
|
3604
3676
|
|
|
3605
3677
|
// src/transcript/use-stick-to-bottom.ts
|
|
3606
|
-
var
|
|
3678
|
+
var import_react16 = require("react");
|
|
3607
3679
|
function useStickToBottom({ contentKey, threshold = 32 }) {
|
|
3608
|
-
const containerRef = (0,
|
|
3609
|
-
const [isAtBottom, setIsAtBottom] = (0,
|
|
3610
|
-
const measure = (0,
|
|
3680
|
+
const containerRef = (0, import_react16.useRef)(null);
|
|
3681
|
+
const [isAtBottom, setIsAtBottom] = (0, import_react16.useState)(true);
|
|
3682
|
+
const measure = (0, import_react16.useCallback)(() => {
|
|
3611
3683
|
const element = containerRef.current;
|
|
3612
3684
|
if (!element) {
|
|
3613
3685
|
return;
|
|
@@ -3617,7 +3689,7 @@ function useStickToBottom({ contentKey, threshold = 32 }) {
|
|
|
3617
3689
|
}, [
|
|
3618
3690
|
threshold
|
|
3619
3691
|
]);
|
|
3620
|
-
const scrollToBottom = (0,
|
|
3692
|
+
const scrollToBottom = (0, import_react16.useCallback)(() => {
|
|
3621
3693
|
const element = containerRef.current;
|
|
3622
3694
|
if (!element) {
|
|
3623
3695
|
return;
|
|
@@ -3625,7 +3697,7 @@ function useStickToBottom({ contentKey, threshold = 32 }) {
|
|
|
3625
3697
|
element.scrollTop = element.scrollHeight;
|
|
3626
3698
|
setIsAtBottom(true);
|
|
3627
3699
|
}, []);
|
|
3628
|
-
const setContainer = (0,
|
|
3700
|
+
const setContainer = (0, import_react16.useCallback)((element) => {
|
|
3629
3701
|
containerRef.current = element;
|
|
3630
3702
|
if (element) {
|
|
3631
3703
|
measure();
|
|
@@ -3633,7 +3705,7 @@ function useStickToBottom({ contentKey, threshold = 32 }) {
|
|
|
3633
3705
|
}, [
|
|
3634
3706
|
measure
|
|
3635
3707
|
]);
|
|
3636
|
-
(0,
|
|
3708
|
+
(0, import_react16.useEffect)(() => {
|
|
3637
3709
|
if (isAtBottom) {
|
|
3638
3710
|
scrollToBottom();
|
|
3639
3711
|
}
|
|
@@ -3642,7 +3714,7 @@ function useStickToBottom({ contentKey, threshold = 32 }) {
|
|
|
3642
3714
|
isAtBottom,
|
|
3643
3715
|
scrollToBottom
|
|
3644
3716
|
]);
|
|
3645
|
-
const getContainerProps = (0,
|
|
3717
|
+
const getContainerProps = (0, import_react16.useCallback)(() => ({
|
|
3646
3718
|
ref: setContainer,
|
|
3647
3719
|
onScroll: measure
|
|
3648
3720
|
}), [
|
|
@@ -3664,14 +3736,14 @@ var DEFAULT_LOAD_EARLIER_STEP = 50;
|
|
|
3664
3736
|
var DEFAULT_COPY_RESET_MS = 1500;
|
|
3665
3737
|
function useChatTranscript(options) {
|
|
3666
3738
|
const { messages, status, initialVisibleCount = DEFAULT_VISIBLE_COUNT, loadEarlierStep = DEFAULT_LOAD_EARLIER_STEP, followUps, stickToBottomThreshold } = options;
|
|
3667
|
-
const latest = (0,
|
|
3739
|
+
const latest = (0, import_react17.useRef)(options);
|
|
3668
3740
|
latest.current = options;
|
|
3669
|
-
const [visibleCount, setVisibleCount] = (0,
|
|
3670
|
-
const [stopRequested, setStopRequested] = (0,
|
|
3741
|
+
const [visibleCount, setVisibleCount] = (0, import_react17.useState)(initialVisibleCount);
|
|
3742
|
+
const [stopRequested, setStopRequested] = (0, import_react17.useState)(false);
|
|
3671
3743
|
const isStreaming = status === "streaming" || status === "reconnecting";
|
|
3672
3744
|
const isBusy = status === "submitted" || isStreaming;
|
|
3673
3745
|
const isEmpty = messages.length === 0;
|
|
3674
|
-
(0,
|
|
3746
|
+
(0, import_react17.useEffect)(() => {
|
|
3675
3747
|
if (!isBusy) {
|
|
3676
3748
|
setStopRequested(false);
|
|
3677
3749
|
}
|
|
@@ -3688,7 +3760,7 @@ function useChatTranscript(options) {
|
|
|
3688
3760
|
streamingMessageId,
|
|
3689
3761
|
options
|
|
3690
3762
|
});
|
|
3691
|
-
const stop = (0,
|
|
3763
|
+
const stop = (0, import_react17.useCallback)(() => {
|
|
3692
3764
|
const current = latest.current;
|
|
3693
3765
|
if (current.status !== "submitted" && current.status !== "streaming" && current.status !== "reconnecting") {
|
|
3694
3766
|
return;
|
|
@@ -3696,8 +3768,8 @@ function useChatTranscript(options) {
|
|
|
3696
3768
|
setStopRequested(true);
|
|
3697
3769
|
void current.onStop?.();
|
|
3698
3770
|
}, []);
|
|
3699
|
-
const loadEarlier = (0,
|
|
3700
|
-
const showAll = (0,
|
|
3771
|
+
const loadEarlier = (0, import_react17.useCallback)(() => setVisibleCount((count) => count + (latest.current.loadEarlierStep ?? DEFAULT_LOAD_EARLIER_STEP)), []);
|
|
3772
|
+
const showAll = (0, import_react17.useCallback)(() => setVisibleCount(latest.current.messages.length), []);
|
|
3701
3773
|
const scroll = useStickToBottom({
|
|
3702
3774
|
contentKey: contentSignature(messages),
|
|
3703
3775
|
...stickToBottomThreshold !== void 0 ? {
|
|
@@ -3733,7 +3805,7 @@ function useChatTranscript(options) {
|
|
|
3733
3805
|
__name(useChatTranscript, "useChatTranscript");
|
|
3734
3806
|
function useTranscriptItem(options) {
|
|
3735
3807
|
const { message, isStreaming = false } = options;
|
|
3736
|
-
const messagesRef = (0,
|
|
3808
|
+
const messagesRef = (0, import_react17.useRef)([
|
|
3737
3809
|
message
|
|
3738
3810
|
]);
|
|
3739
3811
|
if (messagesRef.current[0] !== message) {
|
|
@@ -3751,15 +3823,15 @@ function useTranscriptItem(options) {
|
|
|
3751
3823
|
}
|
|
3752
3824
|
__name(useTranscriptItem, "useTranscriptItem");
|
|
3753
3825
|
function useTranscriptItems({ messages, visibleStart, streamingMessageId, options }) {
|
|
3754
|
-
const [drafts, setDrafts] = (0,
|
|
3755
|
-
const [copied, setCopied] = (0,
|
|
3756
|
-
const [openReasoning, setOpenReasoning] = (0,
|
|
3757
|
-
const [picks, setPicks] = (0,
|
|
3758
|
-
const [settling, setSettling] = (0,
|
|
3759
|
-
const [settleErrors, setSettleErrors] = (0,
|
|
3826
|
+
const [drafts, setDrafts] = (0, import_react17.useState)(() => /* @__PURE__ */ new Map());
|
|
3827
|
+
const [copied, setCopied] = (0, import_react17.useState)(() => /* @__PURE__ */ new Set());
|
|
3828
|
+
const [openReasoning, setOpenReasoning] = (0, import_react17.useState)(() => /* @__PURE__ */ new Map());
|
|
3829
|
+
const [picks, setPicks] = (0, import_react17.useState)(() => /* @__PURE__ */ new Map());
|
|
3830
|
+
const [settling, setSettling] = (0, import_react17.useState)(() => /* @__PURE__ */ new Map());
|
|
3831
|
+
const [settleErrors, setSettleErrors] = (0, import_react17.useState)(() => /* @__PURE__ */ new Map());
|
|
3760
3832
|
const backend = useAgentBackend();
|
|
3761
3833
|
const handlers = settleHandlers(options, backend);
|
|
3762
|
-
const latest = (0,
|
|
3834
|
+
const latest = (0, import_react17.useRef)({
|
|
3763
3835
|
options,
|
|
3764
3836
|
handlers,
|
|
3765
3837
|
drafts,
|
|
@@ -3773,23 +3845,23 @@ function useTranscriptItems({ messages, visibleStart, streamingMessageId, option
|
|
|
3773
3845
|
picks,
|
|
3774
3846
|
messages
|
|
3775
3847
|
};
|
|
3776
|
-
const copyTimers = (0,
|
|
3777
|
-
(0,
|
|
3848
|
+
const copyTimers = (0, import_react17.useRef)(/* @__PURE__ */ new Map());
|
|
3849
|
+
(0, import_react17.useEffect)(() => () => {
|
|
3778
3850
|
for (const timer of copyTimers.current.values()) {
|
|
3779
3851
|
clearTimeout(timer);
|
|
3780
3852
|
}
|
|
3781
3853
|
copyTimers.current.clear();
|
|
3782
3854
|
}, []);
|
|
3783
|
-
const callbackCache = (0,
|
|
3784
|
-
const reasoningToggleCache = (0,
|
|
3785
|
-
const toggleReasoning = (0,
|
|
3855
|
+
const callbackCache = (0, import_react17.useRef)(/* @__PURE__ */ new Map());
|
|
3856
|
+
const reasoningToggleCache = (0, import_react17.useRef)(/* @__PURE__ */ new Map());
|
|
3857
|
+
const toggleReasoning = (0, import_react17.useCallback)((key, open) => {
|
|
3786
3858
|
setOpenReasoning((current) => {
|
|
3787
3859
|
const next = new Map(current);
|
|
3788
3860
|
next.set(key, open ?? !(current.get(key) ?? false));
|
|
3789
3861
|
return next;
|
|
3790
3862
|
});
|
|
3791
3863
|
}, []);
|
|
3792
|
-
const stableToggle = (0,
|
|
3864
|
+
const stableToggle = (0, import_react17.useCallback)((key) => {
|
|
3793
3865
|
let cached = reasoningToggleCache.current.get(key);
|
|
3794
3866
|
if (!cached) {
|
|
3795
3867
|
cached = /* @__PURE__ */ __name((open) => toggleReasoning(key, open), "cached");
|
|
@@ -3799,10 +3871,10 @@ function useTranscriptItems({ messages, visibleStart, streamingMessageId, option
|
|
|
3799
3871
|
}, [
|
|
3800
3872
|
toggleReasoning
|
|
3801
3873
|
]);
|
|
3802
|
-
const pick = (0,
|
|
3874
|
+
const pick = (0, import_react17.useCallback)((toolCallId, questionId, values) => {
|
|
3803
3875
|
setPicks((current) => new Map(current).set(pickKey(toolCallId, questionId), values));
|
|
3804
3876
|
}, []);
|
|
3805
|
-
const settle = (0,
|
|
3877
|
+
const settle = (0, import_react17.useCallback)((toolCallId, action, send) => {
|
|
3806
3878
|
setSettleErrors((current) => {
|
|
3807
3879
|
if (!current.has(toolCallId)) {
|
|
3808
3880
|
return current;
|
|
@@ -3826,7 +3898,7 @@ function useTranscriptItems({ messages, visibleStart, streamingMessageId, option
|
|
|
3826
3898
|
failed(error);
|
|
3827
3899
|
}
|
|
3828
3900
|
}, []);
|
|
3829
|
-
const answer = (0,
|
|
3901
|
+
const answer = (0, import_react17.useCallback)((toolCallId) => {
|
|
3830
3902
|
const current = latest.current;
|
|
3831
3903
|
const onAnswer = current.handlers.onAnswer;
|
|
3832
3904
|
if (!onAnswer) {
|
|
@@ -3839,7 +3911,7 @@ function useTranscriptItems({ messages, visibleStart, streamingMessageId, option
|
|
|
3839
3911
|
}, [
|
|
3840
3912
|
settle
|
|
3841
3913
|
]);
|
|
3842
|
-
const skip = (0,
|
|
3914
|
+
const skip = (0, import_react17.useCallback)((toolCallId) => {
|
|
3843
3915
|
const onSkip = latest.current.handlers.onSkip;
|
|
3844
3916
|
if (onSkip) {
|
|
3845
3917
|
settle(toolCallId, "skip", () => onSkip({
|
|
@@ -3849,7 +3921,7 @@ function useTranscriptItems({ messages, visibleStart, streamingMessageId, option
|
|
|
3849
3921
|
}, [
|
|
3850
3922
|
settle
|
|
3851
3923
|
]);
|
|
3852
|
-
const approve = (0,
|
|
3924
|
+
const approve = (0, import_react17.useCallback)((toolCallId, options2) => {
|
|
3853
3925
|
const onApprove = latest.current.handlers.onApprove;
|
|
3854
3926
|
if (onApprove) {
|
|
3855
3927
|
settle(toolCallId, "approve", () => onApprove({
|
|
@@ -3862,7 +3934,7 @@ function useTranscriptItems({ messages, visibleStart, streamingMessageId, option
|
|
|
3862
3934
|
}, [
|
|
3863
3935
|
settle
|
|
3864
3936
|
]);
|
|
3865
|
-
const reject = (0,
|
|
3937
|
+
const reject = (0, import_react17.useCallback)((toolCallId) => {
|
|
3866
3938
|
const onReject = latest.current.handlers.onReject;
|
|
3867
3939
|
if (onReject) {
|
|
3868
3940
|
settle(toolCallId, "reject", () => onReject({
|
|
@@ -3872,7 +3944,7 @@ function useTranscriptItems({ messages, visibleStart, streamingMessageId, option
|
|
|
3872
3944
|
}, [
|
|
3873
3945
|
settle
|
|
3874
3946
|
]);
|
|
3875
|
-
const callbacksFor = (0,
|
|
3947
|
+
const callbacksFor = (0, import_react17.useCallback)((id) => {
|
|
3876
3948
|
const cached = callbackCache.current.get(id);
|
|
3877
3949
|
if (cached) {
|
|
3878
3950
|
return cached;
|
|
@@ -4158,7 +4230,7 @@ function MessageItem({ message, isStreaming = false, editable, onEditSubmit, reg
|
|
|
4158
4230
|
getCreatedAt: /* @__PURE__ */ __name(() => createdAt, "getCreatedAt")
|
|
4159
4231
|
} : {}
|
|
4160
4232
|
});
|
|
4161
|
-
return /* @__PURE__ */
|
|
4233
|
+
return /* @__PURE__ */ import_react18.default.createElement(MessageItemView, {
|
|
4162
4234
|
item,
|
|
4163
4235
|
...slots
|
|
4164
4236
|
});
|
|
@@ -4171,51 +4243,51 @@ function MessageItemView({ item, ...given }) {
|
|
|
4171
4243
|
renderUi: ambientRenderUi
|
|
4172
4244
|
} : given;
|
|
4173
4245
|
const { classNames } = slots;
|
|
4174
|
-
const actionRow = /* @__PURE__ */
|
|
4246
|
+
const actionRow = /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
4175
4247
|
className: classNames?.actions,
|
|
4176
4248
|
"data-actions-for": item.role
|
|
4177
|
-
}, item.copy.available ? /* @__PURE__ */
|
|
4249
|
+
}, item.copy.available ? /* @__PURE__ */ import_react18.default.createElement("button", {
|
|
4178
4250
|
type: "button",
|
|
4179
4251
|
onClick: item.copy.copy,
|
|
4180
4252
|
className: classNames?.actionButton,
|
|
4181
4253
|
title: item.copy.copied ? "Copied!" : "Copy message text"
|
|
4182
|
-
}, item.copy.copied ? "Copied" : "Copy") : null, item.fork.available ? /* @__PURE__ */
|
|
4254
|
+
}, item.copy.copied ? "Copied" : "Copy") : null, item.fork.available ? /* @__PURE__ */ import_react18.default.createElement("button", {
|
|
4183
4255
|
type: "button",
|
|
4184
4256
|
onClick: item.fork.run,
|
|
4185
4257
|
className: classNames?.actionButton,
|
|
4186
4258
|
title: "Fork thread from this message"
|
|
4187
|
-
}, "Fork") : null, item.regenerate.available ? /* @__PURE__ */
|
|
4259
|
+
}, "Fork") : null, item.regenerate.available ? /* @__PURE__ */ import_react18.default.createElement("button", {
|
|
4188
4260
|
type: "button",
|
|
4189
4261
|
onClick: item.regenerate.run,
|
|
4190
4262
|
className: classNames?.actionButton,
|
|
4191
4263
|
title: "Regenerate response"
|
|
4192
|
-
}, "Regenerate") : null, slots.meta, !item.isUser && item.usage ? /* @__PURE__ */
|
|
4264
|
+
}, "Regenerate") : null, slots.meta, !item.isUser && item.usage ? /* @__PURE__ */ import_react18.default.createElement("span", {
|
|
4193
4265
|
className: classNames?.usage,
|
|
4194
4266
|
title: `Input ${item.usage.inputTokens.toLocaleString()} \xB7 Output ${item.usage.outputTokens.toLocaleString()} tokens`
|
|
4195
|
-
}, item.usage.costLabel, " \xB7 ", item.usage.tokensLabel) : null, item.timestamp ? /* @__PURE__ */
|
|
4267
|
+
}, item.usage.costLabel, " \xB7 ", item.usage.tokensLabel) : null, item.timestamp ? /* @__PURE__ */ import_react18.default.createElement("span", {
|
|
4196
4268
|
className: classNames?.timestamp,
|
|
4197
4269
|
title: item.timestamp.absolute
|
|
4198
4270
|
}, item.timestamp.relative) : null);
|
|
4199
4271
|
if (item.edit.available) {
|
|
4200
|
-
return /* @__PURE__ */
|
|
4272
|
+
return /* @__PURE__ */ import_react18.default.createElement(EditableUserBubble, {
|
|
4201
4273
|
item,
|
|
4202
4274
|
slots,
|
|
4203
4275
|
actions: actionRow
|
|
4204
4276
|
});
|
|
4205
4277
|
}
|
|
4206
4278
|
const className = joinClasses(classNames?.root, classNames?.byRole?.[item.role]);
|
|
4207
|
-
return /* @__PURE__ */
|
|
4279
|
+
return /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
4208
4280
|
className,
|
|
4209
4281
|
"data-role": item.role,
|
|
4210
4282
|
"data-streaming": item.isStreaming ? "true" : void 0
|
|
4211
|
-
}, /* @__PURE__ */
|
|
4283
|
+
}, /* @__PURE__ */ import_react18.default.createElement("div", null, renderBlocks(item, slots)), actionRow);
|
|
4212
4284
|
}
|
|
4213
4285
|
__name(MessageItemView, "MessageItemView");
|
|
4214
4286
|
function renderBlocks(item, slots) {
|
|
4215
4287
|
const nodes = [];
|
|
4216
4288
|
for (const block of item.blocks) {
|
|
4217
4289
|
if (block.kind === "text") {
|
|
4218
|
-
nodes.push(/* @__PURE__ */
|
|
4290
|
+
nodes.push(/* @__PURE__ */ import_react18.default.createElement("div", {
|
|
4219
4291
|
key: block.key,
|
|
4220
4292
|
className: slots.classNames?.text
|
|
4221
4293
|
}, slots.renderText ? slots.renderText(block.text, {
|
|
@@ -4236,7 +4308,7 @@ function renderBlocks(item, slots) {
|
|
|
4236
4308
|
continue;
|
|
4237
4309
|
}
|
|
4238
4310
|
if (block.kind === "ui" && slots.renderUi) {
|
|
4239
|
-
nodes.push(/* @__PURE__ */
|
|
4311
|
+
nodes.push(/* @__PURE__ */ import_react18.default.createElement("div", {
|
|
4240
4312
|
key: block.key,
|
|
4241
4313
|
"data-slot": "ui",
|
|
4242
4314
|
"data-component": block.component
|
|
@@ -4247,18 +4319,18 @@ function renderBlocks(item, slots) {
|
|
|
4247
4319
|
}
|
|
4248
4320
|
__name(renderBlocks, "renderBlocks");
|
|
4249
4321
|
function renderFilesBlock(block, slots) {
|
|
4250
|
-
return /* @__PURE__ */
|
|
4322
|
+
return /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
4251
4323
|
key: block.key,
|
|
4252
4324
|
className: slots.classNames?.files,
|
|
4253
4325
|
"data-files": "true"
|
|
4254
|
-
}, slots.renderFiles ? slots.renderFiles(block.files) : block.files.map((file) => /* @__PURE__ */
|
|
4326
|
+
}, slots.renderFiles ? slots.renderFiles(block.files) : block.files.map((file) => /* @__PURE__ */ import_react18.default.createElement("a", {
|
|
4255
4327
|
key: file.url,
|
|
4256
4328
|
href: file.url,
|
|
4257
4329
|
target: "_blank",
|
|
4258
4330
|
rel: "noreferrer",
|
|
4259
4331
|
className: slots.classNames?.file,
|
|
4260
4332
|
title: file.filename ?? file.mediaType
|
|
4261
|
-
}, file.isImage ? /* @__PURE__ */
|
|
4333
|
+
}, file.isImage ? /* @__PURE__ */ import_react18.default.createElement("img", {
|
|
4262
4334
|
src: file.url,
|
|
4263
4335
|
alt: file.filename ?? "image",
|
|
4264
4336
|
className: slots.classNames?.fileImage
|
|
@@ -4266,17 +4338,17 @@ function renderFilesBlock(block, slots) {
|
|
|
4266
4338
|
}
|
|
4267
4339
|
__name(renderFilesBlock, "renderFilesBlock");
|
|
4268
4340
|
function renderReasoningBlock(block, slots) {
|
|
4269
|
-
return /* @__PURE__ */
|
|
4341
|
+
return /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
4270
4342
|
key: block.key,
|
|
4271
4343
|
className: slots.classNames?.reasoning,
|
|
4272
4344
|
"data-reasoning": "true",
|
|
4273
4345
|
"data-streaming": block.isStreaming ? "true" : void 0
|
|
4274
|
-
}, /* @__PURE__ */
|
|
4346
|
+
}, /* @__PURE__ */ import_react18.default.createElement("button", {
|
|
4275
4347
|
type: "button",
|
|
4276
4348
|
className: slots.classNames?.reasoningToggle,
|
|
4277
4349
|
onClick: /* @__PURE__ */ __name(() => block.toggle(), "onClick"),
|
|
4278
4350
|
"aria-expanded": block.isOpen
|
|
4279
|
-
}, slots.reasoningLabel ?? "Reasoning"), block.isOpen ? /* @__PURE__ */
|
|
4351
|
+
}, slots.reasoningLabel ?? "Reasoning"), block.isOpen ? /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
4280
4352
|
className: slots.classNames?.reasoningText
|
|
4281
4353
|
}, slots.renderReasoning ? slots.renderReasoning(block.text, {
|
|
4282
4354
|
isStreaming: block.isStreaming,
|
|
@@ -4287,7 +4359,7 @@ __name(renderReasoningBlock, "renderReasoningBlock");
|
|
|
4287
4359
|
function renderToolBlock(item, block, slots) {
|
|
4288
4360
|
if (slots.renderToolGroup) {
|
|
4289
4361
|
return [
|
|
4290
|
-
/* @__PURE__ */
|
|
4362
|
+
/* @__PURE__ */ import_react18.default.createElement(import_react18.default.Fragment, {
|
|
4291
4363
|
key: block.key
|
|
4292
4364
|
}, slots.renderToolGroup(block.parts, block.key))
|
|
4293
4365
|
];
|
|
@@ -4298,7 +4370,7 @@ function renderToolBlock(item, block, slots) {
|
|
|
4298
4370
|
const renderToolPart = slots.renderToolPart;
|
|
4299
4371
|
return block.parts.map((part) => {
|
|
4300
4372
|
const partKey = `${item.id}-${part.toolCallId}`;
|
|
4301
|
-
return /* @__PURE__ */
|
|
4373
|
+
return /* @__PURE__ */ import_react18.default.createElement(import_react18.default.Fragment, {
|
|
4302
4374
|
key: partKey
|
|
4303
4375
|
}, renderToolPart(part, partKey));
|
|
4304
4376
|
});
|
|
@@ -4308,14 +4380,14 @@ function EditableUserBubble({ item, slots, actions }) {
|
|
|
4308
4380
|
const { classNames } = slots;
|
|
4309
4381
|
const { edit } = item;
|
|
4310
4382
|
if (!edit.isEditing) {
|
|
4311
|
-
return /* @__PURE__ */
|
|
4383
|
+
return /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
4312
4384
|
className: joinClasses(classNames?.root, classNames?.byRole?.user),
|
|
4313
4385
|
"data-role": "user"
|
|
4314
|
-
}, /* @__PURE__ */
|
|
4386
|
+
}, /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
4315
4387
|
className: classNames?.text
|
|
4316
4388
|
}, slots.renderText ? slots.renderText(item.text, {
|
|
4317
4389
|
isStreaming: false
|
|
4318
|
-
}) : item.text), /* @__PURE__ */
|
|
4390
|
+
}) : item.text), /* @__PURE__ */ import_react18.default.createElement("button", {
|
|
4319
4391
|
type: "button",
|
|
4320
4392
|
onClick: edit.start,
|
|
4321
4393
|
className: classNames?.actionButton,
|
|
@@ -4323,18 +4395,18 @@ function EditableUserBubble({ item, slots, actions }) {
|
|
|
4323
4395
|
}, "Edit"), actions);
|
|
4324
4396
|
}
|
|
4325
4397
|
const textareaProps = edit.getTextareaProps();
|
|
4326
|
-
return /* @__PURE__ */
|
|
4398
|
+
return /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
4327
4399
|
"data-editing": "true"
|
|
4328
|
-
}, /* @__PURE__ */
|
|
4400
|
+
}, /* @__PURE__ */ import_react18.default.createElement("textarea", {
|
|
4329
4401
|
...textareaProps,
|
|
4330
4402
|
rows: Math.min(8, edit.draft.split("\n").length + 1),
|
|
4331
4403
|
className: classNames?.editTextarea
|
|
4332
|
-
}), /* @__PURE__ */
|
|
4404
|
+
}), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
4333
4405
|
className: classNames?.editActions
|
|
4334
|
-
}, /* @__PURE__ */
|
|
4406
|
+
}, /* @__PURE__ */ import_react18.default.createElement("button", {
|
|
4335
4407
|
type: "button",
|
|
4336
4408
|
onClick: edit.cancel
|
|
4337
|
-
}, "Cancel"), /* @__PURE__ */
|
|
4409
|
+
}, "Cancel"), /* @__PURE__ */ import_react18.default.createElement("button", {
|
|
4338
4410
|
type: "button",
|
|
4339
4411
|
onClick: edit.save,
|
|
4340
4412
|
disabled: !edit.canSave
|
|
@@ -4578,35 +4650,35 @@ function toItem(entry) {
|
|
|
4578
4650
|
__name(toItem, "toItem");
|
|
4579
4651
|
|
|
4580
4652
|
// src/composer/use-composer-autocomplete.ts
|
|
4581
|
-
var
|
|
4653
|
+
var import_react19 = require("react");
|
|
4582
4654
|
function useComposerAutocomplete(options) {
|
|
4583
4655
|
const { value, sources, acceptOnTab = true } = options;
|
|
4584
|
-
const latest = (0,
|
|
4656
|
+
const latest = (0, import_react19.useRef)(options);
|
|
4585
4657
|
latest.current = options;
|
|
4586
|
-
const inputRef = (0,
|
|
4587
|
-
const [caret, setCaret] = (0,
|
|
4588
|
-
const [items, setItems] = (0,
|
|
4589
|
-
const [isLoading, setLoading] = (0,
|
|
4590
|
-
const [error, setError] = (0,
|
|
4591
|
-
const [activeIndex, setActiveIndex] = (0,
|
|
4592
|
-
const [dismissedIndex, setDismissedIndex] = (0,
|
|
4658
|
+
const inputRef = (0, import_react19.useRef)(null);
|
|
4659
|
+
const [caret, setCaret] = (0, import_react19.useState)(value.length);
|
|
4660
|
+
const [items, setItems] = (0, import_react19.useState)([]);
|
|
4661
|
+
const [isLoading, setLoading] = (0, import_react19.useState)(false);
|
|
4662
|
+
const [error, setError] = (0, import_react19.useState)(null);
|
|
4663
|
+
const [activeIndex, setActiveIndex] = (0, import_react19.useState)(0);
|
|
4664
|
+
const [dismissedIndex, setDismissedIndex] = (0, import_react19.useState)(null);
|
|
4593
4665
|
const safeCaret = Math.min(caret, value.length);
|
|
4594
|
-
const match = (0,
|
|
4666
|
+
const match = (0, import_react19.useMemo)(() => findActiveTrigger(value, safeCaret, sources), [
|
|
4595
4667
|
value,
|
|
4596
4668
|
safeCaret,
|
|
4597
4669
|
sources
|
|
4598
4670
|
]);
|
|
4599
4671
|
const isActive = match !== null && dismissedIndex !== match.index;
|
|
4600
|
-
const matchRef = (0,
|
|
4672
|
+
const matchRef = (0, import_react19.useRef)(match);
|
|
4601
4673
|
matchRef.current = match;
|
|
4602
|
-
const caretRef = (0,
|
|
4674
|
+
const caretRef = (0, import_react19.useRef)(safeCaret);
|
|
4603
4675
|
caretRef.current = safeCaret;
|
|
4604
|
-
const itemsRef = (0,
|
|
4676
|
+
const itemsRef = (0, import_react19.useRef)(items);
|
|
4605
4677
|
itemsRef.current = items;
|
|
4606
|
-
const activeIndexRef = (0,
|
|
4678
|
+
const activeIndexRef = (0, import_react19.useRef)(activeIndex);
|
|
4607
4679
|
activeIndexRef.current = activeIndex;
|
|
4608
4680
|
const requestKey = isActive && match ? `${match.source.id}\0${match.query}` : null;
|
|
4609
|
-
(0,
|
|
4681
|
+
(0, import_react19.useEffect)(() => {
|
|
4610
4682
|
const current = matchRef.current;
|
|
4611
4683
|
if (requestKey === null || current === null) {
|
|
4612
4684
|
setItems([]);
|
|
@@ -4654,25 +4726,25 @@ function useComposerAutocomplete(options) {
|
|
|
4654
4726
|
]);
|
|
4655
4727
|
const isOpen = isActive;
|
|
4656
4728
|
const activeItem = isOpen ? items[activeIndex] ?? null : null;
|
|
4657
|
-
const reactId = (0,
|
|
4729
|
+
const reactId = (0, import_react19.useId)();
|
|
4658
4730
|
const listboxId = options.id ?? `agent-autocomplete-${reactId}`;
|
|
4659
|
-
const optionId = (0,
|
|
4731
|
+
const optionId = (0, import_react19.useCallback)((index) => `${listboxId}-option-${index}`, [
|
|
4660
4732
|
listboxId
|
|
4661
4733
|
]);
|
|
4662
|
-
const highlight = (0,
|
|
4734
|
+
const highlight = (0, import_react19.useCallback)((index) => {
|
|
4663
4735
|
const total = itemsRef.current.length;
|
|
4664
4736
|
if (total === 0) return;
|
|
4665
4737
|
setActiveIndex((index % total + total) % total);
|
|
4666
4738
|
}, []);
|
|
4667
|
-
const moveHighlight = (0,
|
|
4739
|
+
const moveHighlight = (0, import_react19.useCallback)((delta) => highlight(activeIndexRef.current + delta), [
|
|
4668
4740
|
highlight
|
|
4669
4741
|
]);
|
|
4670
|
-
const dismiss = (0,
|
|
4742
|
+
const dismiss = (0, import_react19.useCallback)(() => {
|
|
4671
4743
|
const current = matchRef.current;
|
|
4672
4744
|
if (current) setDismissedIndex(current.index);
|
|
4673
4745
|
}, []);
|
|
4674
|
-
const pendingCaret = (0,
|
|
4675
|
-
const accept = (0,
|
|
4746
|
+
const pendingCaret = (0, import_react19.useRef)(null);
|
|
4747
|
+
const accept = (0, import_react19.useCallback)((item) => {
|
|
4676
4748
|
const current = matchRef.current;
|
|
4677
4749
|
if (!current) return;
|
|
4678
4750
|
const chosen = item ?? itemsRef.current[activeIndexRef.current];
|
|
@@ -4683,16 +4755,16 @@ function useComposerAutocomplete(options) {
|
|
|
4683
4755
|
setDismissedIndex(null);
|
|
4684
4756
|
pendingCaret.current = edit.caret;
|
|
4685
4757
|
}, []);
|
|
4686
|
-
(0,
|
|
4758
|
+
(0, import_react19.useLayoutEffect)(() => {
|
|
4687
4759
|
const position = pendingCaret.current;
|
|
4688
4760
|
if (position === null) return;
|
|
4689
4761
|
pendingCaret.current = null;
|
|
4690
4762
|
inputRef.current?.setSelectionRange(position, position);
|
|
4691
4763
|
});
|
|
4692
|
-
const readCaret = (0,
|
|
4764
|
+
const readCaret = (0, import_react19.useCallback)((element) => {
|
|
4693
4765
|
setCaret(element.selectionStart ?? element.value.length);
|
|
4694
4766
|
}, []);
|
|
4695
|
-
const onKeyDown = (0,
|
|
4767
|
+
const onKeyDown = (0, import_react19.useCallback)((event) => {
|
|
4696
4768
|
if (!isOpen) return;
|
|
4697
4769
|
const hasItems = itemsRef.current.length > 0;
|
|
4698
4770
|
switch (event.key) {
|
|
@@ -4730,23 +4802,23 @@ function useComposerAutocomplete(options) {
|
|
|
4730
4802
|
dismiss,
|
|
4731
4803
|
moveHighlight
|
|
4732
4804
|
]);
|
|
4733
|
-
const onChange = (0,
|
|
4805
|
+
const onChange = (0, import_react19.useCallback)((event) => {
|
|
4734
4806
|
readCaret(event.target);
|
|
4735
4807
|
const next = findActiveTrigger(event.target.value, event.target.selectionStart ?? event.target.value.length, latest.current.sources);
|
|
4736
4808
|
setDismissedIndex((current) => current !== null && next?.index === current ? current : null);
|
|
4737
4809
|
}, [
|
|
4738
4810
|
readCaret
|
|
4739
4811
|
]);
|
|
4740
|
-
const onSelect = (0,
|
|
4812
|
+
const onSelect = (0, import_react19.useCallback)((event) => readCaret(event.currentTarget), [
|
|
4741
4813
|
readCaret
|
|
4742
4814
|
]);
|
|
4743
|
-
const onClick = (0,
|
|
4815
|
+
const onClick = (0, import_react19.useCallback)((event) => readCaret(event.currentTarget), [
|
|
4744
4816
|
readCaret
|
|
4745
4817
|
]);
|
|
4746
|
-
const setInput = (0,
|
|
4818
|
+
const setInput = (0, import_react19.useCallback)((element) => {
|
|
4747
4819
|
inputRef.current = element;
|
|
4748
4820
|
}, []);
|
|
4749
|
-
const getInputProps = (0,
|
|
4821
|
+
const getInputProps = (0, import_react19.useCallback)(() => ({
|
|
4750
4822
|
ref: setInput,
|
|
4751
4823
|
onChange,
|
|
4752
4824
|
onKeyDown,
|
|
@@ -4774,7 +4846,7 @@ function useComposerAutocomplete(options) {
|
|
|
4774
4846
|
activeIndex,
|
|
4775
4847
|
optionId
|
|
4776
4848
|
]);
|
|
4777
|
-
const getListboxProps = (0,
|
|
4849
|
+
const getListboxProps = (0, import_react19.useCallback)(() => ({
|
|
4778
4850
|
id: listboxId,
|
|
4779
4851
|
role: "listbox",
|
|
4780
4852
|
"aria-label": match?.source.label ?? match?.source.id ?? "Suggestions"
|
|
@@ -4782,7 +4854,7 @@ function useComposerAutocomplete(options) {
|
|
|
4782
4854
|
listboxId,
|
|
4783
4855
|
match
|
|
4784
4856
|
]);
|
|
4785
|
-
const getOptionProps = (0,
|
|
4857
|
+
const getOptionProps = (0, import_react19.useCallback)((index) => ({
|
|
4786
4858
|
id: optionId(index),
|
|
4787
4859
|
role: "option",
|
|
4788
4860
|
"aria-selected": index === activeIndex
|
|
@@ -4816,13 +4888,13 @@ function isPromise(value) {
|
|
|
4816
4888
|
__name(isPromise, "isPromise");
|
|
4817
4889
|
|
|
4818
4890
|
// src/presentation/use-tool-catalog.ts
|
|
4819
|
-
var
|
|
4820
|
-
var
|
|
4821
|
-
function
|
|
4822
|
-
let byAgent =
|
|
4891
|
+
var import_react20 = require("react");
|
|
4892
|
+
var shared2 = /* @__PURE__ */ new WeakMap();
|
|
4893
|
+
function load2(client, agent) {
|
|
4894
|
+
let byAgent = shared2.get(client);
|
|
4823
4895
|
if (byAgent === void 0) {
|
|
4824
4896
|
byAgent = /* @__PURE__ */ new Map();
|
|
4825
|
-
|
|
4897
|
+
shared2.set(client, byAgent);
|
|
4826
4898
|
}
|
|
4827
4899
|
const key = agent ?? "";
|
|
4828
4900
|
const cached = byAgent.get(key);
|
|
@@ -4837,22 +4909,22 @@ function load(client, agent) {
|
|
|
4837
4909
|
byAgent.set(key, request);
|
|
4838
4910
|
return request;
|
|
4839
4911
|
}
|
|
4840
|
-
__name(
|
|
4912
|
+
__name(load2, "load");
|
|
4841
4913
|
function useToolCatalog(options = {}) {
|
|
4842
4914
|
const { agent, enabled = true } = options;
|
|
4843
4915
|
const client = useAgentBackend(options.backend);
|
|
4844
|
-
const [entries, setEntries] = (0,
|
|
4845
|
-
const [isLoading, setLoading] = (0,
|
|
4846
|
-
const [error, setError] = (0,
|
|
4847
|
-
const [generation, setGeneration] = (0,
|
|
4848
|
-
(0,
|
|
4916
|
+
const [entries, setEntries] = (0, import_react20.useState)([]);
|
|
4917
|
+
const [isLoading, setLoading] = (0, import_react20.useState)(enabled);
|
|
4918
|
+
const [error, setError] = (0, import_react20.useState)(null);
|
|
4919
|
+
const [generation, setGeneration] = (0, import_react20.useState)(0);
|
|
4920
|
+
(0, import_react20.useEffect)(() => {
|
|
4849
4921
|
if (!enabled) {
|
|
4850
4922
|
setLoading(false);
|
|
4851
4923
|
return;
|
|
4852
4924
|
}
|
|
4853
4925
|
let cancelled = false;
|
|
4854
4926
|
setLoading(true);
|
|
4855
|
-
|
|
4927
|
+
load2(client, agent).then((loaded) => {
|
|
4856
4928
|
if (cancelled) return;
|
|
4857
4929
|
setEntries(Array.isArray(loaded) ? loaded : []);
|
|
4858
4930
|
setError(null);
|
|
@@ -4871,14 +4943,14 @@ function useToolCatalog(options = {}) {
|
|
|
4871
4943
|
enabled,
|
|
4872
4944
|
generation
|
|
4873
4945
|
]);
|
|
4874
|
-
const refresh = (0,
|
|
4875
|
-
|
|
4946
|
+
const refresh = (0, import_react20.useCallback)(() => {
|
|
4947
|
+
shared2.get(client)?.delete(agent ?? "");
|
|
4876
4948
|
setGeneration((current) => current + 1);
|
|
4877
4949
|
}, [
|
|
4878
4950
|
client,
|
|
4879
4951
|
agent
|
|
4880
4952
|
]);
|
|
4881
|
-
const catalog = (0,
|
|
4953
|
+
const catalog = (0, import_react20.useMemo)(() => toolCatalogFrom(entries), [
|
|
4882
4954
|
entries
|
|
4883
4955
|
]);
|
|
4884
4956
|
return {
|
|
@@ -4892,7 +4964,7 @@ function useToolCatalog(options = {}) {
|
|
|
4892
4964
|
__name(useToolCatalog, "useToolCatalog");
|
|
4893
4965
|
|
|
4894
4966
|
// src/approvals/countdown.ts
|
|
4895
|
-
var
|
|
4967
|
+
var import_react21 = require("react");
|
|
4896
4968
|
function approvalCountdown(expiresAt, now = Date.now()) {
|
|
4897
4969
|
const deadline = expiresAt == null ? Number.NaN : Date.parse(expiresAt);
|
|
4898
4970
|
if (!Number.isFinite(deadline)) {
|
|
@@ -4910,10 +4982,10 @@ function approvalCountdown(expiresAt, now = Date.now()) {
|
|
|
4910
4982
|
__name(approvalCountdown, "approvalCountdown");
|
|
4911
4983
|
function useApprovalCountdown(expiresAt, options = {}) {
|
|
4912
4984
|
const { intervalMs = 1e3 } = options;
|
|
4913
|
-
const nowRef = (0,
|
|
4985
|
+
const nowRef = (0, import_react21.useRef)(options.now ?? Date.now);
|
|
4914
4986
|
nowRef.current = options.now ?? Date.now;
|
|
4915
|
-
const [state, setState] = (0,
|
|
4916
|
-
(0,
|
|
4987
|
+
const [state, setState] = (0, import_react21.useState)(() => approvalCountdown(expiresAt, nowRef.current()));
|
|
4988
|
+
(0, import_react21.useEffect)(() => {
|
|
4917
4989
|
const read = /* @__PURE__ */ __name(() => approvalCountdown(expiresAt, nowRef.current()), "read");
|
|
4918
4990
|
const first = read();
|
|
4919
4991
|
setState(first);
|
|
@@ -5177,8 +5249,8 @@ function sumUsage(rows) {
|
|
|
5177
5249
|
__name(sumUsage, "sumUsage");
|
|
5178
5250
|
|
|
5179
5251
|
// src/use-agent-chat.ts
|
|
5180
|
-
var
|
|
5181
|
-
var
|
|
5252
|
+
var import_react22 = require("@ai-sdk/react");
|
|
5253
|
+
var import_react23 = require("react");
|
|
5182
5254
|
var localChatSequence = 0;
|
|
5183
5255
|
function localChatId() {
|
|
5184
5256
|
localChatSequence += 1;
|
|
@@ -5186,13 +5258,13 @@ function localChatId() {
|
|
|
5186
5258
|
}
|
|
5187
5259
|
__name(localChatId, "localChatId");
|
|
5188
5260
|
function useAgentChat(options = {}) {
|
|
5189
|
-
const latest = (0,
|
|
5261
|
+
const latest = (0, import_react23.useRef)(options);
|
|
5190
5262
|
latest.current = options;
|
|
5191
5263
|
const resolved = useAgentBackend(options.backend);
|
|
5192
|
-
const client = (0,
|
|
5193
|
-
const createdThreadId = (0,
|
|
5194
|
-
const chatIdRef = (0,
|
|
5195
|
-
const boundThreadRef = (0,
|
|
5264
|
+
const client = (0, import_react23.useRef)(resolved).current;
|
|
5265
|
+
const createdThreadId = (0, import_react23.useRef)(void 0);
|
|
5266
|
+
const chatIdRef = (0, import_react23.useRef)(options.threadId ?? localChatId());
|
|
5267
|
+
const boundThreadRef = (0, import_react23.useRef)(options.threadId);
|
|
5196
5268
|
if (options.threadId !== boundThreadRef.current) {
|
|
5197
5269
|
boundThreadRef.current = options.threadId;
|
|
5198
5270
|
const adopting = options.threadId !== void 0 && options.threadId === createdThreadId.current;
|
|
@@ -5202,26 +5274,26 @@ function useAgentChat(options = {}) {
|
|
|
5202
5274
|
}
|
|
5203
5275
|
}
|
|
5204
5276
|
const chatId = chatIdRef.current;
|
|
5205
|
-
const [runId, setRunId] = (0,
|
|
5206
|
-
const runIdRef = (0,
|
|
5277
|
+
const [runId, setRunId] = (0, import_react23.useState)(options.resumeRunId);
|
|
5278
|
+
const runIdRef = (0, import_react23.useRef)(runId);
|
|
5207
5279
|
runIdRef.current = runId;
|
|
5208
|
-
const settlingRunIdRef = (0,
|
|
5209
|
-
const autoResumeRunIdRef = (0,
|
|
5210
|
-
const [activeRunId, setActiveRunId] = (0,
|
|
5211
|
-
const [isLoadingHistory, setIsLoadingHistory] = (0,
|
|
5212
|
-
const [historyError, setHistoryError] = (0,
|
|
5213
|
-
const [threadModel, setThreadModel] = (0,
|
|
5214
|
-
const [pickedModel, setPickedModel] = (0,
|
|
5215
|
-
const pickedModelRef = (0,
|
|
5280
|
+
const settlingRunIdRef = (0, import_react23.useRef)(void 0);
|
|
5281
|
+
const autoResumeRunIdRef = (0, import_react23.useRef)(void 0);
|
|
5282
|
+
const [activeRunId, setActiveRunId] = (0, import_react23.useState)(null);
|
|
5283
|
+
const [isLoadingHistory, setIsLoadingHistory] = (0, import_react23.useState)(false);
|
|
5284
|
+
const [historyError, setHistoryError] = (0, import_react23.useState)(null);
|
|
5285
|
+
const [threadModel, setThreadModel] = (0, import_react23.useState)(null);
|
|
5286
|
+
const [pickedModel, setPickedModel] = (0, import_react23.useState)(void 0);
|
|
5287
|
+
const pickedModelRef = (0, import_react23.useRef)(pickedModel);
|
|
5216
5288
|
pickedModelRef.current = pickedModel;
|
|
5217
|
-
const pendingPin = (0,
|
|
5218
|
-
const regenerateNext = (0,
|
|
5219
|
-
const currentThreadId = (0,
|
|
5220
|
-
const [connection, setConnection] = (0,
|
|
5289
|
+
const pendingPin = (0, import_react23.useRef)(void 0);
|
|
5290
|
+
const regenerateNext = (0, import_react23.useRef)(false);
|
|
5291
|
+
const currentThreadId = (0, import_react23.useCallback)(() => latest.current.threadId ?? createdThreadId.current, []);
|
|
5292
|
+
const [connection, setConnection] = (0, import_react23.useState)({
|
|
5221
5293
|
status: "live"
|
|
5222
5294
|
});
|
|
5223
|
-
const resyncAfterSettle = (0,
|
|
5224
|
-
const transport = (0,
|
|
5295
|
+
const resyncAfterSettle = (0, import_react23.useRef)(false);
|
|
5296
|
+
const transport = (0, import_react23.useMemo)(() => {
|
|
5225
5297
|
function onMeta(meta) {
|
|
5226
5298
|
settlingRunIdRef.current = meta.runId;
|
|
5227
5299
|
setRunId(meta.runId);
|
|
@@ -5284,8 +5356,8 @@ function useAgentChat(options = {}) {
|
|
|
5284
5356
|
}, "onAttemptStart")
|
|
5285
5357
|
});
|
|
5286
5358
|
}, []);
|
|
5287
|
-
const backgroundRef = (0,
|
|
5288
|
-
const chat = (0,
|
|
5359
|
+
const backgroundRef = (0, import_react23.useRef)(() => Promise.resolve());
|
|
5360
|
+
const chat = (0, import_react22.useChat)({
|
|
5289
5361
|
transport,
|
|
5290
5362
|
id: chatId,
|
|
5291
5363
|
resume: options.resumeRunId !== void 0,
|
|
@@ -5331,7 +5403,7 @@ function useAgentChat(options = {}) {
|
|
|
5331
5403
|
}
|
|
5332
5404
|
}, "onFinish")
|
|
5333
5405
|
});
|
|
5334
|
-
const chatRef = (0,
|
|
5406
|
+
const chatRef = (0, import_react23.useRef)(chat);
|
|
5335
5407
|
chatRef.current = chat;
|
|
5336
5408
|
async function resyncFromThread() {
|
|
5337
5409
|
const threadId = currentThreadId();
|
|
@@ -5343,8 +5415,8 @@ function useAgentChat(options = {}) {
|
|
|
5343
5415
|
}
|
|
5344
5416
|
}
|
|
5345
5417
|
__name(resyncFromThread, "resyncFromThread");
|
|
5346
|
-
const firstChatId = (0,
|
|
5347
|
-
(0,
|
|
5418
|
+
const firstChatId = (0, import_react23.useRef)(chatId);
|
|
5419
|
+
(0, import_react23.useEffect)(() => {
|
|
5348
5420
|
if (chatId === firstChatId.current) return;
|
|
5349
5421
|
firstChatId.current = chatId;
|
|
5350
5422
|
setRunId(void 0);
|
|
@@ -5357,7 +5429,7 @@ function useAgentChat(options = {}) {
|
|
|
5357
5429
|
}, [
|
|
5358
5430
|
chatId
|
|
5359
5431
|
]);
|
|
5360
|
-
(0,
|
|
5432
|
+
(0, import_react23.useEffect)(() => {
|
|
5361
5433
|
const threadId = options.threadId;
|
|
5362
5434
|
if (threadId === void 0) return;
|
|
5363
5435
|
if (threadId === createdThreadId.current) return;
|
|
@@ -5398,8 +5470,8 @@ function useAgentChat(options = {}) {
|
|
|
5398
5470
|
chatId,
|
|
5399
5471
|
options.threadId
|
|
5400
5472
|
]);
|
|
5401
|
-
const turnInFlight = (0,
|
|
5402
|
-
const isTurnInFlight = (0,
|
|
5473
|
+
const turnInFlight = (0, import_react23.useRef)(false);
|
|
5474
|
+
const isTurnInFlight = (0, import_react23.useCallback)(() => turnInFlight.current || transport.isAttemptLive, [
|
|
5403
5475
|
transport
|
|
5404
5476
|
]);
|
|
5405
5477
|
const quota = useQuota({
|
|
@@ -5407,9 +5479,9 @@ function useAgentChat(options = {}) {
|
|
|
5407
5479
|
enabled: options.quota !== false && typeof client.getQuota === "function"
|
|
5408
5480
|
});
|
|
5409
5481
|
const blocked = options.blocked !== void 0 ? options.blocked : quota.blocked;
|
|
5410
|
-
const blockedRef = (0,
|
|
5482
|
+
const blockedRef = (0, import_react23.useRef)(blocked);
|
|
5411
5483
|
blockedRef.current = blocked;
|
|
5412
|
-
const sendMessage = (0,
|
|
5484
|
+
const sendMessage = (0, import_react23.useCallback)(async (...args) => {
|
|
5413
5485
|
const block = blockedRef.current;
|
|
5414
5486
|
if (block != null) throw new QuotaBlockedError(block);
|
|
5415
5487
|
if (isTurnInFlight()) return;
|
|
@@ -5422,13 +5494,13 @@ function useAgentChat(options = {}) {
|
|
|
5422
5494
|
}, [
|
|
5423
5495
|
isTurnInFlight
|
|
5424
5496
|
]);
|
|
5425
|
-
const addToolResult = (0,
|
|
5497
|
+
const addToolResult = (0, import_react23.useCallback)(({ tool, toolCallId, output }) => chatRef.current.addToolResult({
|
|
5426
5498
|
tool,
|
|
5427
5499
|
toolCallId,
|
|
5428
5500
|
output
|
|
5429
5501
|
}), []);
|
|
5430
|
-
const [backgroundRuns, setBackgroundRuns] = (0,
|
|
5431
|
-
const refreshBackground = (0,
|
|
5502
|
+
const [backgroundRuns, setBackgroundRuns] = (0, import_react23.useState)([]);
|
|
5503
|
+
const refreshBackground = (0, import_react23.useCallback)(async () => {
|
|
5432
5504
|
const threadId = currentThreadId();
|
|
5433
5505
|
if (threadId === void 0) {
|
|
5434
5506
|
return;
|
|
@@ -5454,7 +5526,7 @@ function useAgentChat(options = {}) {
|
|
|
5454
5526
|
]);
|
|
5455
5527
|
backgroundRef.current = refreshBackground;
|
|
5456
5528
|
const isWorking = backgroundRuns.some((run) => run.status === "running");
|
|
5457
|
-
(0,
|
|
5529
|
+
(0, import_react23.useEffect)(() => {
|
|
5458
5530
|
if (options.background !== true || options.threadId === void 0) {
|
|
5459
5531
|
return;
|
|
5460
5532
|
}
|
|
@@ -5465,7 +5537,7 @@ function useAgentChat(options = {}) {
|
|
|
5465
5537
|
chatId,
|
|
5466
5538
|
refreshBackground
|
|
5467
5539
|
]);
|
|
5468
|
-
(0,
|
|
5540
|
+
(0, import_react23.useEffect)(() => {
|
|
5469
5541
|
const every = latest.current.backgroundPollMs ?? 5e3;
|
|
5470
5542
|
if (latest.current.background !== true || !isWorking || every <= 0) {
|
|
5471
5543
|
return;
|
|
@@ -5476,7 +5548,7 @@ function useAgentChat(options = {}) {
|
|
|
5476
5548
|
isWorking,
|
|
5477
5549
|
refreshBackground
|
|
5478
5550
|
]);
|
|
5479
|
-
const cancel = (0,
|
|
5551
|
+
const cancel = (0, import_react23.useCallback)(async () => {
|
|
5480
5552
|
chatRef.current.stop();
|
|
5481
5553
|
const active = runIdRef.current;
|
|
5482
5554
|
if (active) {
|
|
@@ -5488,7 +5560,7 @@ function useAgentChat(options = {}) {
|
|
|
5488
5560
|
}, [
|
|
5489
5561
|
client
|
|
5490
5562
|
]);
|
|
5491
|
-
const approve = (0,
|
|
5563
|
+
const approve = (0, import_react23.useCallback)(async ({ toolCallId, remember, via }) => {
|
|
5492
5564
|
await requireBackendMethod(client, "approveToolCall")({
|
|
5493
5565
|
toolCallId,
|
|
5494
5566
|
...remember === true ? {
|
|
@@ -5501,7 +5573,7 @@ function useAgentChat(options = {}) {
|
|
|
5501
5573
|
}, [
|
|
5502
5574
|
client
|
|
5503
5575
|
]);
|
|
5504
|
-
const reject = (0,
|
|
5576
|
+
const reject = (0, import_react23.useCallback)(async ({ toolCallId, reason, via }) => {
|
|
5505
5577
|
await requireBackendMethod(client, "rejectToolCall")({
|
|
5506
5578
|
toolCallId,
|
|
5507
5579
|
...reason !== void 0 ? {
|
|
@@ -5514,7 +5586,7 @@ function useAgentChat(options = {}) {
|
|
|
5514
5586
|
}, [
|
|
5515
5587
|
client
|
|
5516
5588
|
]);
|
|
5517
|
-
const answer = (0,
|
|
5589
|
+
const answer = (0, import_react23.useCallback)(async ({ toolCallId, answers }) => {
|
|
5518
5590
|
await requireBackendMethod(client, "answerToolCall")({
|
|
5519
5591
|
toolCallId,
|
|
5520
5592
|
...answers !== void 0 ? {
|
|
@@ -5524,14 +5596,14 @@ function useAgentChat(options = {}) {
|
|
|
5524
5596
|
}, [
|
|
5525
5597
|
client
|
|
5526
5598
|
]);
|
|
5527
|
-
const skip = (0,
|
|
5599
|
+
const skip = (0, import_react23.useCallback)(async ({ toolCallId }) => {
|
|
5528
5600
|
await requireBackendMethod(client, "skipToolCall")({
|
|
5529
5601
|
toolCallId
|
|
5530
5602
|
});
|
|
5531
5603
|
}, [
|
|
5532
5604
|
client
|
|
5533
5605
|
]);
|
|
5534
|
-
const regenerate = (0,
|
|
5606
|
+
const regenerate = (0, import_react23.useCallback)((_input) => {
|
|
5535
5607
|
const block = blockedRef.current;
|
|
5536
5608
|
if (block != null) throw new QuotaBlockedError(block);
|
|
5537
5609
|
if (isTurnInFlight()) return;
|
|
@@ -5543,7 +5615,7 @@ function useAgentChat(options = {}) {
|
|
|
5543
5615
|
}, [
|
|
5544
5616
|
isTurnInFlight
|
|
5545
5617
|
]);
|
|
5546
|
-
const storedIdOf = (0,
|
|
5618
|
+
const storedIdOf = (0, import_react23.useCallback)(async (messageId, threadId) => {
|
|
5547
5619
|
const message = chatRef.current.messages.find((candidate) => candidate.id === messageId);
|
|
5548
5620
|
const runOf = message?.metadata?.runId;
|
|
5549
5621
|
if (runOf === void 0) return messageId;
|
|
@@ -5555,7 +5627,7 @@ function useAgentChat(options = {}) {
|
|
|
5555
5627
|
}, [
|
|
5556
5628
|
client
|
|
5557
5629
|
]);
|
|
5558
|
-
const fork = (0,
|
|
5630
|
+
const fork = (0, import_react23.useCallback)(async ({ messageId, threadId }) => {
|
|
5559
5631
|
const source = threadId ?? currentThreadId();
|
|
5560
5632
|
if (source === void 0) throw new Error("fork: this chat has no thread yet");
|
|
5561
5633
|
const stored = await storedIdOf(messageId, source);
|
|
@@ -5570,7 +5642,7 @@ function useAgentChat(options = {}) {
|
|
|
5570
5642
|
currentThreadId,
|
|
5571
5643
|
storedIdOf
|
|
5572
5644
|
]);
|
|
5573
|
-
const truncateFrom = (0,
|
|
5645
|
+
const truncateFrom = (0, import_react23.useCallback)(async ({ messageId, threadId }) => {
|
|
5574
5646
|
const target = threadId ?? currentThreadId();
|
|
5575
5647
|
if (target === void 0) throw new Error("truncateFrom: this chat has no thread yet");
|
|
5576
5648
|
const stored = await storedIdOf(messageId, target);
|
|
@@ -5580,7 +5652,7 @@ function useAgentChat(options = {}) {
|
|
|
5580
5652
|
currentThreadId,
|
|
5581
5653
|
storedIdOf
|
|
5582
5654
|
]);
|
|
5583
|
-
const promote = (0,
|
|
5655
|
+
const promote = (0, import_react23.useCallback)(async ({ threadId } = {}) => {
|
|
5584
5656
|
const target = threadId ?? currentThreadId();
|
|
5585
5657
|
if (target === void 0) throw new Error("promote: this chat has no thread yet");
|
|
5586
5658
|
await requireBackendMethod(client, "promoteThread")(target);
|
|
@@ -5591,8 +5663,8 @@ function useAgentChat(options = {}) {
|
|
|
5591
5663
|
client,
|
|
5592
5664
|
currentThreadId
|
|
5593
5665
|
]);
|
|
5594
|
-
const [modelsWanted, setModelsWanted] = (0,
|
|
5595
|
-
const modelsWantedRef = (0,
|
|
5666
|
+
const [modelsWanted, setModelsWanted] = (0, import_react23.useState)(false);
|
|
5667
|
+
const modelsWantedRef = (0, import_react23.useRef)(modelsWanted);
|
|
5596
5668
|
modelsWantedRef.current = modelsWanted;
|
|
5597
5669
|
const catalog = useModels({
|
|
5598
5670
|
backend: client,
|
|
@@ -5601,13 +5673,13 @@ function useAgentChat(options = {}) {
|
|
|
5601
5673
|
} : {},
|
|
5602
5674
|
enabled: modelsWanted && typeof client.listModels === "function"
|
|
5603
5675
|
});
|
|
5604
|
-
const wantModels = (0,
|
|
5676
|
+
const wantModels = (0, import_react23.useCallback)(() => {
|
|
5605
5677
|
if (modelsWantedRef.current) return;
|
|
5606
5678
|
modelsWantedRef.current = true;
|
|
5607
5679
|
queueMicrotask(() => setModelsWanted(true));
|
|
5608
5680
|
}, []);
|
|
5609
|
-
const selectModel = (0,
|
|
5610
|
-
const pinToThread = (0,
|
|
5681
|
+
const selectModel = (0, import_react23.useCallback)((id) => setPickedModel(id), []);
|
|
5682
|
+
const pinToThread = (0, import_react23.useCallback)(async (model) => {
|
|
5611
5683
|
const threadId = currentThreadId();
|
|
5612
5684
|
setThreadModel(model);
|
|
5613
5685
|
if (threadId === void 0) {
|
|
@@ -5647,9 +5719,9 @@ function useAgentChat(options = {}) {
|
|
|
5647
5719
|
...options.composer,
|
|
5648
5720
|
backend: client
|
|
5649
5721
|
});
|
|
5650
|
-
const [text, setText] = (0,
|
|
5651
|
-
const blockedBy = blocked != null ? "quota" : files.isUploading ? "uploading" : isBusy ? "busy" : text.trim().length === 0 && files.
|
|
5652
|
-
const composerRef = (0,
|
|
5722
|
+
const [text, setText] = (0, import_react23.useState)("");
|
|
5723
|
+
const blockedBy = blocked != null ? "quota" : files.isUploading ? "uploading" : isBusy ? "busy" : text.trim().length === 0 && files.refs.length === 0 ? "empty" : null;
|
|
5724
|
+
const composerRef = (0, import_react23.useRef)({
|
|
5653
5725
|
text,
|
|
5654
5726
|
files,
|
|
5655
5727
|
blockedBy
|
|
@@ -5659,7 +5731,7 @@ function useAgentChat(options = {}) {
|
|
|
5659
5731
|
files,
|
|
5660
5732
|
blockedBy
|
|
5661
5733
|
};
|
|
5662
|
-
const submit = (0,
|
|
5734
|
+
const submit = (0, import_react23.useCallback)(async () => {
|
|
5663
5735
|
const current = composerRef.current;
|
|
5664
5736
|
if (current.blockedBy !== null) return;
|
|
5665
5737
|
const refs = current.files.refs;
|
|
@@ -5825,6 +5897,7 @@ var QuotaBlockedError = class extends Error {
|
|
|
5825
5897
|
toolCatalogFrom,
|
|
5826
5898
|
useAgentBackend,
|
|
5827
5899
|
useAgentChat,
|
|
5900
|
+
useAgentConfig,
|
|
5828
5901
|
useAgents,
|
|
5829
5902
|
useAmbientRenderUi,
|
|
5830
5903
|
useApprovalCountdown,
|