@longline/aqua-ui 1.0.201 → 1.0.203
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.
|
@@ -43,7 +43,6 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
43
43
|
}
|
|
44
44
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
45
45
|
};
|
|
46
|
-
import axios from 'axios';
|
|
47
46
|
import { useCallback, useRef } from 'react';
|
|
48
47
|
/**
|
|
49
48
|
* Hook to stream OpenAI responses via a backend endpoint that acts as a proxy.
|
|
@@ -52,6 +51,11 @@ import { useCallback, useRef } from 'react';
|
|
|
52
51
|
*/
|
|
53
52
|
var useOpenAIStream = function (url) {
|
|
54
53
|
var abortRef = useRef(null);
|
|
54
|
+
// Get CSRF token, if any, from cookie:
|
|
55
|
+
var getCsrfTokenFromCookie = function () {
|
|
56
|
+
var match = document.cookie.match(/XSRF-TOKEN=([^;]+)/);
|
|
57
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
58
|
+
};
|
|
55
59
|
/**
|
|
56
60
|
* Streams a prompt to a backend AI endpoint and handles streamed chunks.
|
|
57
61
|
*
|
|
@@ -72,32 +76,34 @@ var useOpenAIStream = function (url) {
|
|
|
72
76
|
case 0:
|
|
73
77
|
controller = new AbortController();
|
|
74
78
|
abortRef.current = controller;
|
|
75
|
-
return [4 /*yield*/,
|
|
76
|
-
|
|
77
|
-
temperature: options.temperature || 0,
|
|
78
|
-
top_p: options.top_p || 0
|
|
79
|
-
}, {
|
|
80
|
-
signal: controller.signal,
|
|
79
|
+
return [4 /*yield*/, fetch(url, {
|
|
80
|
+
method: 'POST',
|
|
81
81
|
headers: {
|
|
82
82
|
'Content-Type': 'application/json',
|
|
83
|
+
//'X-XSRF-TOKEN': getCsrfTokenFromCookie() ?? '',
|
|
83
84
|
'Accept': 'text/event-stream',
|
|
84
85
|
'Connection': 'keep-alive',
|
|
85
86
|
'Cache-Control': 'no-cache, no-transform'
|
|
86
87
|
},
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
body: JSON.stringify({
|
|
89
|
+
input: prompt,
|
|
90
|
+
temperature: options.temperature || 0,
|
|
91
|
+
top_p: options.top_p || 0
|
|
92
|
+
}),
|
|
93
|
+
credentials: 'include',
|
|
94
|
+
signal: controller.signal
|
|
93
95
|
})];
|
|
94
96
|
case 1:
|
|
95
97
|
response = _f.sent();
|
|
96
|
-
if (!response.
|
|
98
|
+
if (!response.ok) {
|
|
99
|
+
console.error("OpenAI stream request failed: ".concat(response.statusText));
|
|
100
|
+
return [2 /*return*/];
|
|
101
|
+
}
|
|
102
|
+
if (!response.body) {
|
|
97
103
|
console.error('No response body (ReadableStream) found.');
|
|
98
104
|
return [2 /*return*/];
|
|
99
105
|
}
|
|
100
|
-
reader = response.
|
|
106
|
+
reader = response.body.getReader();
|
|
101
107
|
decoder = new TextDecoder('utf-8');
|
|
102
108
|
buffer = '';
|
|
103
109
|
isDone = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longline/aqua-ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.203",
|
|
4
4
|
"description": "AquaUI",
|
|
5
5
|
"author": "Alexander van Oostenrijk / Longline Environment",
|
|
6
6
|
"license": "Commercial",
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
"@types/react": "^18.3.10",
|
|
53
53
|
"@types/react-dom": "^18.3.0",
|
|
54
54
|
"awesome-debounce-promise": "^2.1.0",
|
|
55
|
-
"axios": "^1.10.0",
|
|
56
55
|
"country-flag-emoji-polyfill": "^0.1.8",
|
|
57
56
|
"extendable-media-recorder": "^9.2.26",
|
|
58
57
|
"extendable-media-recorder-wav-encoder": "^7.0.128",
|