@convex-dev/agent 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/react/index.d.ts +5 -1
- package/dist/commonjs/react/index.d.ts.map +1 -1
- package/dist/commonjs/react/index.js +48 -3
- package/dist/commonjs/react/index.js.map +1 -1
- package/dist/esm/react/index.d.ts +5 -1
- package/dist/esm/react/index.d.ts.map +1 -1
- package/dist/esm/react/index.js +48 -3
- package/dist/esm/react/index.js.map +1 -1
- package/package.json +9 -2
- package/src/react/index.ts +55 -3
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function useStreamingText(url: string, threadId: string | null, token?: string): readonly [{
|
|
2
|
+
readonly text: string;
|
|
3
|
+
readonly loading: boolean;
|
|
4
|
+
readonly error: Error | null;
|
|
5
|
+
}, (prompt: string) => Promise<void>];
|
|
2
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAMA,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,KAAK,CAAC,EAAE,MAAM;;;;YAOS,MAAM,oBA2C9B"}
|
|
@@ -1,8 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
import { useState, useMemo } from "react";
|
|
2
2
|
if (typeof window === "undefined") {
|
|
3
3
|
throw new Error("this is frontend code, but it's running somewhere else!");
|
|
4
4
|
}
|
|
5
|
-
export function
|
|
6
|
-
|
|
5
|
+
export function useStreamingText(url, threadId, token) {
|
|
6
|
+
const [text, setText] = useState("");
|
|
7
|
+
const [loading, setLoading] = useState(false);
|
|
8
|
+
const [error, setError] = useState(null);
|
|
9
|
+
const readStream = useMemo(() => async (prompt) => {
|
|
10
|
+
if (!threadId)
|
|
11
|
+
return;
|
|
12
|
+
try {
|
|
13
|
+
setText("");
|
|
14
|
+
setLoading(true);
|
|
15
|
+
setError(null);
|
|
16
|
+
const response = await fetch(url, {
|
|
17
|
+
method: "POST",
|
|
18
|
+
headers: {
|
|
19
|
+
"Content-Type": "application/json",
|
|
20
|
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
21
|
+
},
|
|
22
|
+
body: JSON.stringify({ prompt, threadId }),
|
|
23
|
+
});
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
26
|
+
}
|
|
27
|
+
if (!response.body) {
|
|
28
|
+
throw new Error("No body");
|
|
29
|
+
}
|
|
30
|
+
const reader = response.body.getReader();
|
|
31
|
+
const decoder = new TextDecoder();
|
|
32
|
+
let accumulatedText = "";
|
|
33
|
+
while (true) {
|
|
34
|
+
const { done, value } = await reader.read();
|
|
35
|
+
if (done) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
accumulatedText += decoder.decode(value);
|
|
39
|
+
setText(accumulatedText);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
if (e instanceof Error && e.name !== "AbortError") {
|
|
44
|
+
setError(e);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
setLoading(false);
|
|
49
|
+
}
|
|
50
|
+
}, [threadId, token]);
|
|
51
|
+
return [{ text, loading, error }, readStream];
|
|
7
52
|
}
|
|
8
53
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA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BACnB,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC;YAC7B,CAAC;YACD,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACzC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;YAClC,IAAI,eAAe,GAAG,EAAE,CAAC;YAEzB,OAAO,IAAI,EAAE,CAAC;gBACZ,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;gBAC5C,IAAI,IAAI,EAAE,CAAC;oBACT,MAAM;gBACR,CAAC;gBACD,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACzC,OAAO,CAAC,eAAe,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;gBAClD,QAAQ,CAAC,CAAC,CAAC,CAAC;YACd,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EACD,CAAC,QAAQ,EAAE,KAAK,CAAC,CAClB,CAAC;IACF,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,UAAU,CAAU,CAAC;AACzD,CAAC"}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function useStreamingText(url: string, threadId: string | null, token?: string): readonly [{
|
|
2
|
+
readonly text: string;
|
|
3
|
+
readonly loading: boolean;
|
|
4
|
+
readonly error: Error | null;
|
|
5
|
+
}, (prompt: string) => Promise<void>];
|
|
2
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAMA,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,KAAK,CAAC,EAAE,MAAM;;;;YAOS,MAAM,oBA2C9B"}
|
package/dist/esm/react/index.js
CHANGED
|
@@ -1,8 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
import { useState, useMemo } from "react";
|
|
2
2
|
if (typeof window === "undefined") {
|
|
3
3
|
throw new Error("this is frontend code, but it's running somewhere else!");
|
|
4
4
|
}
|
|
5
|
-
export function
|
|
6
|
-
|
|
5
|
+
export function useStreamingText(url, threadId, token) {
|
|
6
|
+
const [text, setText] = useState("");
|
|
7
|
+
const [loading, setLoading] = useState(false);
|
|
8
|
+
const [error, setError] = useState(null);
|
|
9
|
+
const readStream = useMemo(() => async (prompt) => {
|
|
10
|
+
if (!threadId)
|
|
11
|
+
return;
|
|
12
|
+
try {
|
|
13
|
+
setText("");
|
|
14
|
+
setLoading(true);
|
|
15
|
+
setError(null);
|
|
16
|
+
const response = await fetch(url, {
|
|
17
|
+
method: "POST",
|
|
18
|
+
headers: {
|
|
19
|
+
"Content-Type": "application/json",
|
|
20
|
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
21
|
+
},
|
|
22
|
+
body: JSON.stringify({ prompt, threadId }),
|
|
23
|
+
});
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
26
|
+
}
|
|
27
|
+
if (!response.body) {
|
|
28
|
+
throw new Error("No body");
|
|
29
|
+
}
|
|
30
|
+
const reader = response.body.getReader();
|
|
31
|
+
const decoder = new TextDecoder();
|
|
32
|
+
let accumulatedText = "";
|
|
33
|
+
while (true) {
|
|
34
|
+
const { done, value } = await reader.read();
|
|
35
|
+
if (done) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
accumulatedText += decoder.decode(value);
|
|
39
|
+
setText(accumulatedText);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
if (e instanceof Error && e.name !== "AbortError") {
|
|
44
|
+
setError(e);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
setLoading(false);
|
|
49
|
+
}
|
|
50
|
+
}, [threadId, token]);
|
|
51
|
+
return [{ text, loading, error }, readStream];
|
|
7
52
|
}
|
|
8
53
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE1C,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,GAAW,EACX,QAAuB,EACvB,KAAc;IAEd,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACrC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAC;IAEvD,MAAM,UAAU,GAAG,OAAO,CACxB,GAAG,EAAE,CAAC,KAAK,EAAE,MAAc,EAAE,EAAE;QAC7B,IAAI,CAAC,QAAQ;YAAE,OAAO;QACtB,IAAI,CAAC;YACH,OAAO,CAAC,EAAE,CAAC,CAAC;YACZ,UAAU,CAAC,IAAI,CAAC,CAAC;YACjB,QAAQ,CAAC,IAAI,C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ACT,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EACD,CAAC,QAAQ,EAAE,KAAK,CAAC,CAClB,CAAC;IACF,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,UAAU,CAAU,CAAC;AACzD,CAAC"}
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"email": "support@convex.dev",
|
|
8
8
|
"url": "https://github.com/get-convex/agent/issues"
|
|
9
9
|
},
|
|
10
|
-
"version": "0.0.
|
|
10
|
+
"version": "0.0.8",
|
|
11
11
|
"license": "Apache-2.0",
|
|
12
12
|
"keywords": [
|
|
13
13
|
"convex",
|
|
@@ -84,11 +84,18 @@
|
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"ai": "^4.3.4",
|
|
86
86
|
"convex": "^1.23.0",
|
|
87
|
-
"convex-helpers": "^0.1.78"
|
|
87
|
+
"convex-helpers": "^0.1.78",
|
|
88
|
+
"react": "^18.3.1 || ^19.0.0"
|
|
89
|
+
},
|
|
90
|
+
"peerDependenciesMeta": {
|
|
91
|
+
"react": {
|
|
92
|
+
"optional": true
|
|
93
|
+
}
|
|
88
94
|
},
|
|
89
95
|
"devDependencies": {
|
|
90
96
|
"@eslint/js": "^9.9.1",
|
|
91
97
|
"@types/node": "^18.19.86",
|
|
98
|
+
"@types/react": "^19.1.1",
|
|
92
99
|
"convex-test": "^0.0.33",
|
|
93
100
|
"eslint": "^9.24.0",
|
|
94
101
|
"globals": "^15.15.0",
|
package/src/react/index.ts
CHANGED
|
@@ -1,8 +1,60 @@
|
|
|
1
|
-
|
|
1
|
+
import { useState, useMemo } from "react";
|
|
2
|
+
|
|
2
3
|
if (typeof window === "undefined") {
|
|
3
4
|
throw new Error("this is frontend code, but it's running somewhere else!");
|
|
4
5
|
}
|
|
5
6
|
|
|
6
|
-
export function
|
|
7
|
-
|
|
7
|
+
export function useStreamingText(
|
|
8
|
+
url: string,
|
|
9
|
+
threadId: string | null,
|
|
10
|
+
token?: string
|
|
11
|
+
) {
|
|
12
|
+
const [text, setText] = useState("");
|
|
13
|
+
const [loading, setLoading] = useState(false);
|
|
14
|
+
const [error, setError] = useState<Error | null>(null);
|
|
15
|
+
|
|
16
|
+
const readStream = useMemo(
|
|
17
|
+
() => async (prompt: string) => {
|
|
18
|
+
if (!threadId) return;
|
|
19
|
+
try {
|
|
20
|
+
setText("");
|
|
21
|
+
setLoading(true);
|
|
22
|
+
setError(null);
|
|
23
|
+
const response = await fetch(url, {
|
|
24
|
+
method: "POST",
|
|
25
|
+
headers: {
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
28
|
+
},
|
|
29
|
+
body: JSON.stringify({ prompt, threadId }),
|
|
30
|
+
});
|
|
31
|
+
if (!response.ok) {
|
|
32
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
33
|
+
}
|
|
34
|
+
if (!response.body) {
|
|
35
|
+
throw new Error("No body");
|
|
36
|
+
}
|
|
37
|
+
const reader = response.body.getReader();
|
|
38
|
+
const decoder = new TextDecoder();
|
|
39
|
+
let accumulatedText = "";
|
|
40
|
+
|
|
41
|
+
while (true) {
|
|
42
|
+
const { done, value } = await reader.read();
|
|
43
|
+
if (done) {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
accumulatedText += decoder.decode(value);
|
|
47
|
+
setText(accumulatedText);
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (e instanceof Error && e.name !== "AbortError") {
|
|
51
|
+
setError(e);
|
|
52
|
+
}
|
|
53
|
+
} finally {
|
|
54
|
+
setLoading(false);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
[threadId, token]
|
|
58
|
+
);
|
|
59
|
+
return [{ text, loading, error }, readStream] as const;
|
|
8
60
|
}
|