@assistant-ui/react 0.15.0 → 0.15.1
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { useAuiState } from "@assistant-ui/store";
|
|
3
3
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
4
4
|
import { useEffect, useState } from "@assistant-ui/tap/react-shim";
|
|
5
5
|
//#region src/hooks/useToolCallElapsed.ts
|
|
@@ -22,48 +22,43 @@ import { useEffect, useState } from "@assistant-ui/tap/react-shim";
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
const useToolCallElapsed = () => {
|
|
25
|
-
const $ = c(
|
|
26
|
-
const
|
|
25
|
+
const $ = c(3);
|
|
26
|
+
const timing = useAuiState(_temp);
|
|
27
|
+
const partRunning = useAuiState(_temp2);
|
|
28
|
+
const running = timing !== void 0 && timing.completedAt === void 0 && partRunning;
|
|
29
|
+
const [now, setNow] = useState(_temp3);
|
|
27
30
|
let t0;
|
|
28
|
-
if ($[0] !== hasPart) {
|
|
29
|
-
t0 = (s) => hasPart && s.part.type === "tool-call" ? s.part.timing : void 0;
|
|
30
|
-
$[0] = hasPart;
|
|
31
|
-
$[1] = t0;
|
|
32
|
-
} else t0 = $[1];
|
|
33
|
-
const timing = useAuiState(t0);
|
|
34
31
|
let t1;
|
|
35
|
-
if ($[
|
|
36
|
-
|
|
37
|
-
$[2] = hasPart;
|
|
38
|
-
$[3] = t1;
|
|
39
|
-
} else t1 = $[3];
|
|
40
|
-
const partRunning = useAuiState(t1);
|
|
41
|
-
const running = timing !== void 0 && timing.completedAt === void 0 && partRunning;
|
|
42
|
-
const [now, setNow] = useState(_temp);
|
|
43
|
-
let t2;
|
|
44
|
-
let t3;
|
|
45
|
-
if ($[4] !== running) {
|
|
46
|
-
t2 = () => {
|
|
32
|
+
if ($[0] !== running) {
|
|
33
|
+
t0 = () => {
|
|
47
34
|
if (!running) return;
|
|
48
35
|
setNow(Date.now());
|
|
49
36
|
const id = setInterval(() => setNow(Date.now()), 1e3);
|
|
50
37
|
return () => clearInterval(id);
|
|
51
38
|
};
|
|
52
|
-
|
|
53
|
-
$[
|
|
54
|
-
$[
|
|
55
|
-
$[
|
|
39
|
+
t1 = [running];
|
|
40
|
+
$[0] = running;
|
|
41
|
+
$[1] = t0;
|
|
42
|
+
$[2] = t1;
|
|
56
43
|
} else {
|
|
57
|
-
|
|
58
|
-
|
|
44
|
+
t0 = $[1];
|
|
45
|
+
t1 = $[2];
|
|
59
46
|
}
|
|
60
|
-
useEffect(
|
|
47
|
+
useEffect(t0, t1);
|
|
61
48
|
if (timing === void 0) return;
|
|
62
49
|
if (timing.completedAt !== void 0) return Math.max(0, timing.completedAt - timing.startedAt);
|
|
63
50
|
if (!running) return;
|
|
64
51
|
return Math.max(0, now - timing.startedAt);
|
|
65
52
|
};
|
|
66
|
-
function _temp() {
|
|
53
|
+
function _temp(s) {
|
|
54
|
+
const part = s.optional.part;
|
|
55
|
+
return part?.type === "tool-call" ? part.timing : void 0;
|
|
56
|
+
}
|
|
57
|
+
function _temp2(s_0) {
|
|
58
|
+
const part_0 = s_0.optional.part;
|
|
59
|
+
return part_0?.type === "tool-call" && part_0.status.type === "running";
|
|
60
|
+
}
|
|
61
|
+
function _temp3() {
|
|
67
62
|
return Date.now();
|
|
68
63
|
}
|
|
69
64
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useToolCallElapsed.js","names":["c","_c","useEffect","useState","
|
|
1
|
+
{"version":3,"file":"useToolCallElapsed.js","names":["c","_c","useEffect","useState","useAuiState","useToolCallElapsed","$","timing","_temp","partRunning","_temp2","running","undefined","completedAt","now","setNow","_temp3","t0","t1","Date","id","setInterval","clearInterval","Math","max","startedAt","s","part","optional","type","s_0","part_0","status"],"sources":["../../src/hooks/useToolCallElapsed.ts"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useState } from \"react\";\nimport { useAuiState } from \"@assistant-ui/store\";\n\n/**\n * Hook that returns the elapsed wall-clock time of the current tool call in\n * milliseconds, ticking once per second while the call runs.\n *\n * Reads `part.timing`. Returns `undefined` when the part is not a tool call,\n * carries no timing, ended without a recorded completion (the duration is\n * unknown), or when no message part scope is available (so kit components\n * stay renderable standalone, e.g. in docs previews).\n *\n * @example\n * ```tsx\n * function ToolDuration() {\n * const elapsedMs = useToolCallElapsed();\n * if (elapsedMs === undefined) return null;\n * return <span>{(elapsedMs / 1000).toFixed(1)}s</span>;\n * }\n * ```\n */\nexport const useToolCallElapsed = (): number | undefined => {\n const timing = useAuiState((s) => {\n const part = s.optional.part;\n return part?.type === \"tool-call\" ? part.timing : undefined;\n });\n const partRunning = useAuiState((s) => {\n const part = s.optional.part;\n return part?.type === \"tool-call\" && part.status.type === \"running\";\n });\n const running =\n timing !== undefined && timing.completedAt === undefined && partRunning;\n const [now, setNow] = useState(() => Date.now());\n\n useEffect(() => {\n if (!running) return undefined;\n setNow(Date.now());\n const id = setInterval(() => setNow(Date.now()), 1000);\n return () => clearInterval(id);\n }, [running]);\n\n if (timing === undefined) return undefined;\n if (timing.completedAt !== undefined)\n return Math.max(0, timing.completedAt - timing.startedAt);\n if (!running) return undefined;\n return Math.max(0, now - timing.startedAt);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAaK,2BAAqB;CAAA,MAAAC,IAAAL,EAAA,CAAA;CAChC,MAAAM,SAAeH,YAAYI,KAG1B;CACD,MAAAC,cAAoBL,YAAYM,MAG/B;CACD,MAAAC,UACEJ,WAAWK,KAAAA,KAAaL,OAAMM,gBAAiBD,KAAAA,KAA/CH;CACF,MAAA,CAAAK,KAAAC,UAAsBZ,SAASa,MAAgB;CAAE,IAAAC;CAAA,IAAAC;CAAA,IAAAZ,EAAA,OAAAK,SAAA;EAEvCM,WAAA;GACR,IAAI,CAACN,SAAO;GACZI,OAAOI,KAAIL,IAAK,CAAC;GACjB,MAAAM,KAAWC,kBAAkBN,OAAOI,KAAIL,IAAK,CAAC,GAAG,GAAI;GAAE,aAC1CQ,cAAcF,EAAE;EAAC;EAC7BF,KAAA,CAACP,OAAO;EAACL,EAAA,KAAAK;EAAAL,EAAA,KAAAW;EAAAX,EAAA,KAAAY;CAAA,OAAA;EAAAD,KAAAX,EAAA;EAAAY,KAAAZ,EAAA;CAAA;CALZJ,UAAUe,IAKPC,EAAS;CAEZ,IAAIX,WAAWK,KAAAA,GAAS;CACxB,IAAIL,OAAMM,gBAAiBD,KAAAA,GAAS,OAC3BW,KAAIC,IAAK,GAAGjB,OAAMM,cAAeN,OAAMkB,SAAU;CAC1D,IAAI,CAACd,SAAO;CAAmB,OACxBY,KAAIC,IAAK,GAAGV,MAAMP,OAAMkB,SAAU;AAAC;AAxBV,SAAAjB,MAAAkB,GAAA;CAE9B,MAAAC,OAAaD,EAACE,SAASD;CAAM,OACtBA,MAAIE,SAAW,cAAcF,KAAIpB,SAAjCK,KAAAA;AAAoD;AAH7B,SAAAF,OAAAoB,KAAA;CAM9B,MAAAC,SAAaL,IAACE,SAASD;CAAM,OACtBA,QAAIE,SAAW,eAAeF,OAAIK,OAAOH,SAAU;AAAS;AAPrC,SAAAb,SAAA;CAAA,OAWKG,KAAIL,IAAK;AAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
//#region src/utils/useToolArgsFieldStatus.d.ts
|
|
2
2
|
declare const useToolArgsFieldStatus: (fieldPath: (string | number)[]) => {
|
|
3
|
+
type: string;
|
|
4
|
+
} | {
|
|
3
5
|
readonly type: "running";
|
|
4
6
|
} | {
|
|
5
7
|
readonly type: "complete";
|
|
@@ -7,8 +9,6 @@ declare const useToolArgsFieldStatus: (fieldPath: (string | number)[]) => {
|
|
|
7
9
|
readonly type: "incomplete";
|
|
8
10
|
readonly reason: "cancelled" | "length" | "content-filter" | "other" | "error";
|
|
9
11
|
readonly error?: unknown;
|
|
10
|
-
} | {
|
|
11
|
-
type: string;
|
|
12
12
|
};
|
|
13
13
|
//#endregion
|
|
14
14
|
export { useToolArgsFieldStatus };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/react",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.1",
|
|
4
4
|
"description": "Open-source TypeScript/React library for building production-grade AI chat experiences",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
],
|
|
56
56
|
"sideEffects": false,
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@assistant-ui/core": "^0.3.
|
|
59
|
-
"@assistant-ui/store": "^0.3.
|
|
58
|
+
"@assistant-ui/core": "^0.3.1",
|
|
59
|
+
"@assistant-ui/store": "^0.3.1",
|
|
60
60
|
"@assistant-ui/tap": "^0.9.7",
|
|
61
61
|
"@radix-ui/primitive": "^1.1.7",
|
|
62
62
|
"@radix-ui/react-collection": "^1.1.15",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"@radix-ui/react-use-controllable-state": "^1.2.6",
|
|
68
68
|
"@radix-ui/react-use-escape-keydown": "^1.1.5",
|
|
69
69
|
"assistant-cloud": "^0.1.37",
|
|
70
|
-
"assistant-stream": "^0.3.
|
|
70
|
+
"assistant-stream": "^0.3.30",
|
|
71
71
|
"nanoid": "^6.0.0",
|
|
72
72
|
"radix-ui": "^1.6.7",
|
|
73
73
|
"react-textarea-autosize": "^8.5.9",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { useEffect, useState } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { useAuiState } from "@assistant-ui/store";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Hook that returns the elapsed wall-clock time of the current tool call in
|
|
@@ -22,17 +22,14 @@ import { useAui, useAuiState } from "@assistant-ui/store";
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
export const useToolCallElapsed = (): number | undefined => {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
s.part.type === "tool-call" &&
|
|
34
|
-
s.part.status.type === "running",
|
|
35
|
-
);
|
|
25
|
+
const timing = useAuiState((s) => {
|
|
26
|
+
const part = s.optional.part;
|
|
27
|
+
return part?.type === "tool-call" ? part.timing : undefined;
|
|
28
|
+
});
|
|
29
|
+
const partRunning = useAuiState((s) => {
|
|
30
|
+
const part = s.optional.part;
|
|
31
|
+
return part?.type === "tool-call" && part.status.type === "running";
|
|
32
|
+
});
|
|
36
33
|
const running =
|
|
37
34
|
timing !== undefined && timing.completedAt === undefined && partRunning;
|
|
38
35
|
const [now, setNow] = useState(() => Date.now());
|