@alquimia-ai/tools 1.0.1 → 1.0.2
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/actions/alquimia.action.d.mts +3 -0
- package/dist/actions/alquimia.action.d.ts +3 -0
- package/dist/actions/alquimia.action.js +62 -0
- package/dist/actions/alquimia.action.js.map +1 -0
- package/dist/actions/alquimia.action.mjs +38 -0
- package/dist/actions/alquimia.action.mjs.map +1 -0
- package/dist/actions/baseApi.action.d.mts +20 -0
- package/dist/actions/baseApi.action.d.ts +20 -0
- package/dist/actions/baseApi.action.js +202 -0
- package/dist/actions/baseApi.action.js.map +1 -0
- package/dist/actions/baseApi.action.mjs +173 -0
- package/dist/actions/baseApi.action.mjs.map +1 -0
- package/dist/actions/index.d.mts +5 -0
- package/dist/actions/index.d.ts +5 -0
- package/dist/actions/index.js +236 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/index.mjs +205 -0
- package/dist/actions/index.mjs.map +1 -0
- package/dist/alquimia-sdk-DK0XLjol.d.mts +77 -0
- package/dist/alquimia-sdk-DK0XLjol.d.ts +77 -0
- package/dist/context/index.d.mts +22 -0
- package/dist/context/index.d.ts +22 -0
- package/dist/context/index.js +124 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/index.mjs +96 -0
- package/dist/context/index.mjs.map +1 -0
- package/dist/hooks/index.d.mts +54 -0
- package/dist/hooks/index.d.ts +54 -0
- package/dist/hooks/index.js +344 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/index.mjs +316 -0
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/index.d.mts +14 -303
- package/dist/index.d.ts +14 -303
- package/dist/index.js +1143 -2448
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1079 -2213
- package/dist/index.mjs.map +1 -1
- package/dist/sdk/index.d.mts +74 -0
- package/dist/sdk/index.d.ts +74 -0
- package/dist/sdk/index.js +561 -0
- package/dist/sdk/index.js.map +1 -0
- package/dist/sdk/index.mjs +510 -0
- package/dist/sdk/index.mjs.map +1 -0
- package/dist/services/index.d.mts +26 -0
- package/dist/services/index.d.ts +26 -0
- package/dist/services/index.js +93 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/index.mjs +63 -0
- package/dist/services/index.mjs.map +1 -0
- package/dist/types/index.d.mts +105 -0
- package/dist/types/index.d.ts +105 -0
- package/dist/types/index.js +41 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +14 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/utils/index.d.mts +29 -0
- package/dist/utils/index.d.ts +29 -0
- package/dist/utils/index.js +170 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +133 -0
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +42 -13
package/dist/index.mjs
CHANGED
|
@@ -1,2336 +1,1202 @@
|
|
|
1
1
|
// src/button.tsx
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function _array_without_holes(arr) {
|
|
11
|
-
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
12
|
-
}
|
|
13
|
-
function _assert_this_initialized(self) {
|
|
14
|
-
if (self === void 0) {
|
|
15
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
16
|
-
}
|
|
17
|
-
return self;
|
|
18
|
-
}
|
|
19
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
20
|
-
try {
|
|
21
|
-
var info = gen[key](arg);
|
|
22
|
-
var value = info.value;
|
|
23
|
-
} catch (error) {
|
|
24
|
-
reject(error);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if (info.done) {
|
|
28
|
-
resolve(value);
|
|
29
|
-
} else {
|
|
30
|
-
Promise.resolve(value).then(_next, _throw);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function _async_to_generator(fn) {
|
|
34
|
-
return function() {
|
|
35
|
-
var self = this, args = arguments;
|
|
36
|
-
return new Promise(function(resolve, reject) {
|
|
37
|
-
var gen = fn.apply(self, args);
|
|
38
|
-
function _next(value) {
|
|
39
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
40
|
-
}
|
|
41
|
-
function _throw(err) {
|
|
42
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
43
|
-
}
|
|
44
|
-
_next(undefined);
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function _call_super(_this, derived, args) {
|
|
49
|
-
derived = _get_prototype_of(derived);
|
|
50
|
-
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
51
|
-
}
|
|
52
|
-
function _class_call_check(instance, Constructor) {
|
|
53
|
-
if (!(instance instanceof Constructor)) {
|
|
54
|
-
throw new TypeError("Cannot call a class as a function");
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
var Button = ({ children, className, appName }) => {
|
|
4
|
+
return /* @__PURE__ */ jsx(
|
|
5
|
+
"button",
|
|
6
|
+
{
|
|
7
|
+
className,
|
|
8
|
+
onClick: () => alert(`Hello from your ${appName} app!`),
|
|
9
|
+
children
|
|
55
10
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
11
|
+
);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/card.tsx
|
|
15
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
16
|
+
function Card({
|
|
17
|
+
className,
|
|
18
|
+
title,
|
|
19
|
+
children,
|
|
20
|
+
href
|
|
21
|
+
}) {
|
|
22
|
+
return /* @__PURE__ */ jsxs(
|
|
23
|
+
"a",
|
|
24
|
+
{
|
|
25
|
+
className,
|
|
26
|
+
href: `${href}?utm_source=create-turbo&utm_medium=basic&utm_campaign=create-turbo"`,
|
|
27
|
+
rel: "noopener noreferrer",
|
|
28
|
+
target: "_blank",
|
|
29
|
+
children: [
|
|
30
|
+
/* @__PURE__ */ jsxs("h2", { children: [
|
|
31
|
+
title,
|
|
32
|
+
" ",
|
|
33
|
+
/* @__PURE__ */ jsx2("span", { children: "->" })
|
|
34
|
+
] }),
|
|
35
|
+
/* @__PURE__ */ jsx2("p", { children })
|
|
36
|
+
]
|
|
64
37
|
}
|
|
38
|
+
);
|
|
65
39
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
value: value,
|
|
75
|
-
enumerable: true,
|
|
76
|
-
configurable: true,
|
|
77
|
-
writable: true
|
|
78
|
-
});
|
|
79
|
-
} else {
|
|
80
|
-
obj[key] = value;
|
|
81
|
-
}
|
|
82
|
-
return obj;
|
|
40
|
+
|
|
41
|
+
// src/code.tsx
|
|
42
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
43
|
+
function Code({
|
|
44
|
+
children,
|
|
45
|
+
className
|
|
46
|
+
}) {
|
|
47
|
+
return /* @__PURE__ */ jsx3("code", { className, children });
|
|
83
48
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
49
|
+
|
|
50
|
+
// src/sdk/alquimia-sdk.ts
|
|
51
|
+
import axios from "axios";
|
|
52
|
+
var AlquimiaSDK = class {
|
|
53
|
+
constructor(config, enforceCharacterization = true) {
|
|
54
|
+
this.conversationId = null;
|
|
55
|
+
this.sessionId = null;
|
|
56
|
+
this.streamId = null;
|
|
57
|
+
this.tools = [];
|
|
58
|
+
this.extraData = {};
|
|
59
|
+
this.forceProfile = {};
|
|
60
|
+
this.config = config;
|
|
61
|
+
this.enforceCharacterization = enforceCharacterization;
|
|
62
|
+
this.axiosInstance = axios.create();
|
|
63
|
+
this.axiosInstance.interceptors.response.use(
|
|
64
|
+
(response) => response,
|
|
65
|
+
async (error) => {
|
|
66
|
+
if (error.response?.status) {
|
|
67
|
+
if (this.loggerProvider) {
|
|
68
|
+
await this.loggerProvider.logError(
|
|
69
|
+
"Server Error",
|
|
70
|
+
error,
|
|
71
|
+
{
|
|
72
|
+
url: error.config.url,
|
|
73
|
+
method: error.config.method,
|
|
74
|
+
data: error.config.data,
|
|
75
|
+
status: error.response.status,
|
|
76
|
+
responseData: error.response.data
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return Promise.reject(error);
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
this.textToSpeech = this.textToSpeech.bind(this);
|
|
85
|
+
this.speechToText = this.speechToText.bind(this);
|
|
86
|
+
}
|
|
87
|
+
static configure(apiKey, inferUrl, streamUrl, assistantId) {
|
|
88
|
+
return {
|
|
89
|
+
apiKey,
|
|
90
|
+
chatUrl: `${inferUrl}/chat/${assistantId}`,
|
|
91
|
+
streamUrl: `${streamUrl}/${assistantId}`,
|
|
92
|
+
assistantId
|
|
87
93
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
}
|
|
95
|
+
widthConversationId(conversationId) {
|
|
96
|
+
this.conversationId = conversationId;
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
withWhisperProvider(provider) {
|
|
100
|
+
this.whisperProvider = provider;
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
withStableDiffusionProvider(provider) {
|
|
104
|
+
this.stableDiffusionProvider = provider;
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
withAnalyzeCharacterizationProvider(provider) {
|
|
108
|
+
this.analyzeCharacterizationProvider = provider;
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
withRatingsProvider(provider) {
|
|
112
|
+
this.ratingsProvider = provider;
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
withLoggerProvider(provider) {
|
|
116
|
+
this.loggerProvider = provider;
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
getEnforceCharacterization() {
|
|
120
|
+
return this.enforceCharacterization ?? true;
|
|
121
|
+
}
|
|
122
|
+
withTools(tools) {
|
|
123
|
+
this.tools = tools;
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
withExtraData(extraData) {
|
|
127
|
+
this.extraData = extraData;
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
withForceProfile(forceProfile) {
|
|
131
|
+
this.forceProfile = forceProfile;
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
textToSpeech(text) {
|
|
135
|
+
if (!this.whisperProvider) {
|
|
136
|
+
throw new Error("Whisper provider not initialized");
|
|
93
137
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
if (superClass) _set_prototype_of(subClass, superClass);
|
|
102
|
-
}
|
|
103
|
-
function _instanceof(left, right) {
|
|
104
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
105
|
-
return !!right[Symbol.hasInstance](left);
|
|
106
|
-
} else {
|
|
107
|
-
return left instanceof right;
|
|
138
|
+
return this.whisperProvider.textToSpeech(text);
|
|
139
|
+
}
|
|
140
|
+
speechToText(audio) {
|
|
141
|
+
if (!this.whisperProvider) {
|
|
142
|
+
throw new Error("Whisper provider not initialized");
|
|
108
143
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
115
|
-
if (_i == null) return;
|
|
116
|
-
var _arr = [];
|
|
117
|
-
var _n = true;
|
|
118
|
-
var _d = false;
|
|
119
|
-
var _s, _e;
|
|
120
|
-
try {
|
|
121
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
122
|
-
_arr.push(_s.value);
|
|
123
|
-
if (i && _arr.length === i) break;
|
|
124
|
-
}
|
|
125
|
-
} catch (err) {
|
|
126
|
-
_d = true;
|
|
127
|
-
_e = err;
|
|
128
|
-
} finally{
|
|
129
|
-
try {
|
|
130
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
131
|
-
} finally{
|
|
132
|
-
if (_d) throw _e;
|
|
133
|
-
}
|
|
144
|
+
return this.whisperProvider.speechToText(audio);
|
|
145
|
+
}
|
|
146
|
+
async sendMessage(query, traceParent) {
|
|
147
|
+
if (!this.conversationId) {
|
|
148
|
+
throw new Error("Conversation not initialized");
|
|
134
149
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
});
|
|
150
|
+
const initMessage = {
|
|
151
|
+
query,
|
|
152
|
+
session_id: this.conversationId,
|
|
153
|
+
tools: this.tools,
|
|
154
|
+
extra_data: this.extraData,
|
|
155
|
+
force_profile: this.forceProfile
|
|
156
|
+
};
|
|
157
|
+
const result = (await this.axiosInstance.post(this.config.chatUrl, initMessage, {
|
|
158
|
+
headers: {
|
|
159
|
+
"Content-Type": "application/json",
|
|
160
|
+
"x-trace-parent": traceParent || ""
|
|
161
|
+
}
|
|
162
|
+
})).data;
|
|
163
|
+
this.streamId = result.data.stream_id;
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
async generateImage(query) {
|
|
167
|
+
if (!this.stableDiffusionProvider) {
|
|
168
|
+
throw new Error("Stable Diffusion provider not initialized");
|
|
155
169
|
}
|
|
156
|
-
return
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
162
|
-
if (enumerableOnly) {
|
|
163
|
-
symbols = symbols.filter(function(sym) {
|
|
164
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
keys.push.apply(keys, symbols);
|
|
170
|
+
return this.stableDiffusionProvider.generateImage(query);
|
|
171
|
+
}
|
|
172
|
+
async analyzeCharacterization(text) {
|
|
173
|
+
if (!this.analyzeCharacterizationProvider) {
|
|
174
|
+
throw new Error("analyze characterization provider not initialized");
|
|
168
175
|
}
|
|
169
|
-
return
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
175
|
-
} else {
|
|
176
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
177
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
178
|
-
});
|
|
176
|
+
return this.analyzeCharacterizationProvider.analyzeCharacterization(text);
|
|
177
|
+
}
|
|
178
|
+
async rate(data) {
|
|
179
|
+
if (!this.ratingsProvider) {
|
|
180
|
+
throw new Error("ratings provider not initialized");
|
|
179
181
|
}
|
|
180
|
-
return
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (
|
|
184
|
-
|
|
182
|
+
return this.ratingsProvider.rate(data);
|
|
183
|
+
}
|
|
184
|
+
async logInfo(message, data) {
|
|
185
|
+
if (!this.loggerProvider) {
|
|
186
|
+
throw new Error("logger provider not initialized");
|
|
185
187
|
}
|
|
186
|
-
return
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return o;
|
|
192
|
-
};
|
|
193
|
-
return _set_prototype_of(o, p);
|
|
194
|
-
}
|
|
195
|
-
function _sliced_to_array(arr, i) {
|
|
196
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
197
|
-
}
|
|
198
|
-
function _to_consumable_array(arr) {
|
|
199
|
-
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
200
|
-
}
|
|
201
|
-
function _type_of(obj) {
|
|
202
|
-
"@swc/helpers - typeof";
|
|
203
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
204
|
-
}
|
|
205
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
206
|
-
if (!o) return;
|
|
207
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
208
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
209
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
210
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
211
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
212
|
-
}
|
|
213
|
-
function _is_native_reflect_construct() {
|
|
214
|
-
try {
|
|
215
|
-
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
216
|
-
} catch (_) {}
|
|
217
|
-
return (_is_native_reflect_construct = function() {
|
|
218
|
-
return !!result;
|
|
219
|
-
})();
|
|
220
|
-
}
|
|
221
|
-
function _ts_generator(thisArg, body) {
|
|
222
|
-
var f, y, t, g, _ = {
|
|
223
|
-
label: 0,
|
|
224
|
-
sent: function() {
|
|
225
|
-
if (t[0] & 1) throw t[1];
|
|
226
|
-
return t[1];
|
|
227
|
-
},
|
|
228
|
-
trys: [],
|
|
229
|
-
ops: []
|
|
230
|
-
};
|
|
231
|
-
return g = {
|
|
232
|
-
next: verb(0),
|
|
233
|
-
"throw": verb(1),
|
|
234
|
-
"return": verb(2)
|
|
235
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
236
|
-
return this;
|
|
237
|
-
}), g;
|
|
238
|
-
function verb(n) {
|
|
239
|
-
return function(v) {
|
|
240
|
-
return step([
|
|
241
|
-
n,
|
|
242
|
-
v
|
|
243
|
-
]);
|
|
244
|
-
};
|
|
188
|
+
return this.loggerProvider.logInfo(message, data);
|
|
189
|
+
}
|
|
190
|
+
async logError(message, error, data) {
|
|
191
|
+
if (!this.loggerProvider) {
|
|
192
|
+
throw new Error("logger provider not initialized");
|
|
245
193
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
op[0] & 2,
|
|
252
|
-
t.value
|
|
253
|
-
];
|
|
254
|
-
switch(op[0]){
|
|
255
|
-
case 0:
|
|
256
|
-
case 1:
|
|
257
|
-
t = op;
|
|
258
|
-
break;
|
|
259
|
-
case 4:
|
|
260
|
-
_.label++;
|
|
261
|
-
return {
|
|
262
|
-
value: op[1],
|
|
263
|
-
done: false
|
|
264
|
-
};
|
|
265
|
-
case 5:
|
|
266
|
-
_.label++;
|
|
267
|
-
y = op[1];
|
|
268
|
-
op = [
|
|
269
|
-
0
|
|
270
|
-
];
|
|
271
|
-
continue;
|
|
272
|
-
case 7:
|
|
273
|
-
op = _.ops.pop();
|
|
274
|
-
_.trys.pop();
|
|
275
|
-
continue;
|
|
276
|
-
default:
|
|
277
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
278
|
-
_ = 0;
|
|
279
|
-
continue;
|
|
280
|
-
}
|
|
281
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
282
|
-
_.label = op[1];
|
|
283
|
-
break;
|
|
284
|
-
}
|
|
285
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
286
|
-
_.label = t[1];
|
|
287
|
-
t = op;
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
290
|
-
if (t && _.label < t[2]) {
|
|
291
|
-
_.label = t[2];
|
|
292
|
-
_.ops.push(op);
|
|
293
|
-
break;
|
|
294
|
-
}
|
|
295
|
-
if (t[2]) _.ops.pop();
|
|
296
|
-
_.trys.pop();
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
op = body.call(thisArg, _);
|
|
300
|
-
} catch (e) {
|
|
301
|
-
op = [
|
|
302
|
-
6,
|
|
303
|
-
e
|
|
304
|
-
];
|
|
305
|
-
y = 0;
|
|
306
|
-
} finally{
|
|
307
|
-
f = t = 0;
|
|
308
|
-
}
|
|
309
|
-
if (op[0] & 5) throw op[1];
|
|
310
|
-
return {
|
|
311
|
-
value: op[0] ? op[1] : void 0,
|
|
312
|
-
done: true
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
var Button = function(param) {
|
|
317
|
-
var children = param.children, className = param.className, appName = param.appName;
|
|
318
|
-
return /* @__PURE__ */ React.createElement("button", {
|
|
319
|
-
className: className,
|
|
320
|
-
onClick: function() {
|
|
321
|
-
return alert("Hello from your ".concat(appName, " app!"));
|
|
322
|
-
}
|
|
323
|
-
}, children);
|
|
194
|
+
return this.loggerProvider.logError(message, error, data);
|
|
195
|
+
}
|
|
196
|
+
getUrlStream() {
|
|
197
|
+
return `${this.config.streamUrl}/${this.streamId}`;
|
|
198
|
+
}
|
|
324
199
|
};
|
|
325
|
-
// src/card.tsx
|
|
326
|
-
function Card(param) {
|
|
327
|
-
var className = param.className, title = param.title, children = param.children, href = param.href;
|
|
328
|
-
return /* @__PURE__ */ React.createElement("a", {
|
|
329
|
-
className: className,
|
|
330
|
-
href: "".concat(href, '?utm_source=create-turbo&utm_medium=basic&utm_campaign=create-turbo"'),
|
|
331
|
-
rel: "noopener noreferrer",
|
|
332
|
-
target: "_blank"
|
|
333
|
-
}, /* @__PURE__ */ React.createElement("h2", null, title, " ", /* @__PURE__ */ React.createElement("span", null, "->")), /* @__PURE__ */ React.createElement("p", null, children));
|
|
334
|
-
}
|
|
335
|
-
// src/code.tsx
|
|
336
|
-
function Code(param) {
|
|
337
|
-
var children = param.children, className = param.className;
|
|
338
|
-
return /* @__PURE__ */ React.createElement("code", {
|
|
339
|
-
className: className
|
|
340
|
-
}, children);
|
|
341
|
-
}
|
|
342
|
-
// src/sdk/alquimia-sdk.ts
|
|
343
|
-
import axios from "axios";
|
|
344
|
-
var AlquimiaSDK = /*#__PURE__*/ function() {
|
|
345
|
-
"use strict";
|
|
346
|
-
function AlquimiaSDK(config) {
|
|
347
|
-
var enforceCharacterization = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
|
|
348
|
-
_class_call_check(this, AlquimiaSDK);
|
|
349
|
-
var _this = this;
|
|
350
|
-
this.conversationId = null;
|
|
351
|
-
this.sessionId = null;
|
|
352
|
-
this.streamId = null;
|
|
353
|
-
this.tools = [];
|
|
354
|
-
this.extraData = {};
|
|
355
|
-
this.forceProfile = {};
|
|
356
|
-
this.config = config;
|
|
357
|
-
this.enforceCharacterization = enforceCharacterization;
|
|
358
|
-
this.axiosInstance = axios.create();
|
|
359
|
-
this.axiosInstance.interceptors.response.use(function(response) {
|
|
360
|
-
return response;
|
|
361
|
-
}, /*#__PURE__*/ function() {
|
|
362
|
-
var _ref = _async_to_generator(function(error) {
|
|
363
|
-
var _error_response;
|
|
364
|
-
return _ts_generator(this, function(_state) {
|
|
365
|
-
switch(_state.label){
|
|
366
|
-
case 0:
|
|
367
|
-
if (!((_error_response = error.response) === null || _error_response === void 0 ? void 0 : _error_response.status)) return [
|
|
368
|
-
3,
|
|
369
|
-
2
|
|
370
|
-
];
|
|
371
|
-
if (!_this.loggerProvider) return [
|
|
372
|
-
3,
|
|
373
|
-
2
|
|
374
|
-
];
|
|
375
|
-
return [
|
|
376
|
-
4,
|
|
377
|
-
_this.loggerProvider.logError("Server Error", error, {
|
|
378
|
-
url: error.config.url,
|
|
379
|
-
method: error.config.method,
|
|
380
|
-
data: error.config.data,
|
|
381
|
-
status: error.response.status,
|
|
382
|
-
responseData: error.response.data
|
|
383
|
-
})
|
|
384
|
-
];
|
|
385
|
-
case 1:
|
|
386
|
-
_state.sent();
|
|
387
|
-
_state.label = 2;
|
|
388
|
-
case 2:
|
|
389
|
-
return [
|
|
390
|
-
2,
|
|
391
|
-
Promise.reject(error)
|
|
392
|
-
];
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
});
|
|
396
|
-
return function(error) {
|
|
397
|
-
return _ref.apply(this, arguments);
|
|
398
|
-
};
|
|
399
|
-
}());
|
|
400
|
-
this.textToSpeech = this.textToSpeech.bind(this);
|
|
401
|
-
this.speechToText = this.speechToText.bind(this);
|
|
402
|
-
}
|
|
403
|
-
_create_class(AlquimiaSDK, [
|
|
404
|
-
{
|
|
405
|
-
key: "widthConversationId",
|
|
406
|
-
value: function widthConversationId(conversationId) {
|
|
407
|
-
this.conversationId = conversationId;
|
|
408
|
-
return this;
|
|
409
|
-
}
|
|
410
|
-
},
|
|
411
|
-
{
|
|
412
|
-
key: "withWhisperProvider",
|
|
413
|
-
value: function withWhisperProvider(provider) {
|
|
414
|
-
this.whisperProvider = provider;
|
|
415
|
-
return this;
|
|
416
|
-
}
|
|
417
|
-
},
|
|
418
|
-
{
|
|
419
|
-
key: "withStableDiffusionProvider",
|
|
420
|
-
value: function withStableDiffusionProvider(provider) {
|
|
421
|
-
this.stableDiffusionProvider = provider;
|
|
422
|
-
return this;
|
|
423
|
-
}
|
|
424
|
-
},
|
|
425
|
-
{
|
|
426
|
-
key: "withAnalyzeCharacterizationProvider",
|
|
427
|
-
value: function withAnalyzeCharacterizationProvider(provider) {
|
|
428
|
-
this.analyzeCharacterizationProvider = provider;
|
|
429
|
-
return this;
|
|
430
|
-
}
|
|
431
|
-
},
|
|
432
|
-
{
|
|
433
|
-
key: "withRatingsProvider",
|
|
434
|
-
value: function withRatingsProvider(provider) {
|
|
435
|
-
this.ratingsProvider = provider;
|
|
436
|
-
return this;
|
|
437
|
-
}
|
|
438
|
-
},
|
|
439
|
-
{
|
|
440
|
-
key: "withLoggerProvider",
|
|
441
|
-
value: function withLoggerProvider(provider) {
|
|
442
|
-
this.loggerProvider = provider;
|
|
443
|
-
return this;
|
|
444
|
-
}
|
|
445
|
-
},
|
|
446
|
-
{
|
|
447
|
-
key: "getEnforceCharacterization",
|
|
448
|
-
value: function getEnforceCharacterization() {
|
|
449
|
-
var _this_enforceCharacterization;
|
|
450
|
-
return (_this_enforceCharacterization = this.enforceCharacterization) !== null && _this_enforceCharacterization !== void 0 ? _this_enforceCharacterization : true;
|
|
451
|
-
}
|
|
452
|
-
},
|
|
453
|
-
{
|
|
454
|
-
key: "withTools",
|
|
455
|
-
value: function withTools(tools) {
|
|
456
|
-
this.tools = tools;
|
|
457
|
-
return this;
|
|
458
|
-
}
|
|
459
|
-
},
|
|
460
|
-
{
|
|
461
|
-
key: "withExtraData",
|
|
462
|
-
value: function withExtraData(extraData) {
|
|
463
|
-
this.extraData = extraData;
|
|
464
|
-
return this;
|
|
465
|
-
}
|
|
466
|
-
},
|
|
467
|
-
{
|
|
468
|
-
key: "withForceProfile",
|
|
469
|
-
value: function withForceProfile(forceProfile) {
|
|
470
|
-
this.forceProfile = forceProfile;
|
|
471
|
-
return this;
|
|
472
|
-
}
|
|
473
|
-
},
|
|
474
|
-
{
|
|
475
|
-
key: "textToSpeech",
|
|
476
|
-
value: function textToSpeech(text) {
|
|
477
|
-
if (!this.whisperProvider) {
|
|
478
|
-
throw new Error("Whisper provider not initialized");
|
|
479
|
-
}
|
|
480
|
-
return this.whisperProvider.textToSpeech(text);
|
|
481
|
-
}
|
|
482
|
-
},
|
|
483
|
-
{
|
|
484
|
-
key: "speechToText",
|
|
485
|
-
value: function speechToText(audio) {
|
|
486
|
-
if (!this.whisperProvider) {
|
|
487
|
-
throw new Error("Whisper provider not initialized");
|
|
488
|
-
}
|
|
489
|
-
return this.whisperProvider.speechToText(audio);
|
|
490
|
-
}
|
|
491
|
-
},
|
|
492
|
-
{
|
|
493
|
-
key: "sendMessage",
|
|
494
|
-
value: function sendMessage(query, traceParent) {
|
|
495
|
-
var _this = this;
|
|
496
|
-
return _async_to_generator(function() {
|
|
497
|
-
var initMessage, result;
|
|
498
|
-
return _ts_generator(this, function(_state) {
|
|
499
|
-
switch(_state.label){
|
|
500
|
-
case 0:
|
|
501
|
-
if (!_this.conversationId) {
|
|
502
|
-
throw new Error("Conversation not initialized");
|
|
503
|
-
}
|
|
504
|
-
initMessage = {
|
|
505
|
-
query: query,
|
|
506
|
-
session_id: _this.conversationId,
|
|
507
|
-
tools: _this.tools,
|
|
508
|
-
extra_data: _this.extraData,
|
|
509
|
-
force_profile: _this.forceProfile
|
|
510
|
-
};
|
|
511
|
-
return [
|
|
512
|
-
4,
|
|
513
|
-
_this.axiosInstance.post(_this.config.chatUrl, initMessage, {
|
|
514
|
-
headers: {
|
|
515
|
-
"Content-Type": "application/json",
|
|
516
|
-
"x-trace-parent": traceParent || ""
|
|
517
|
-
}
|
|
518
|
-
})
|
|
519
|
-
];
|
|
520
|
-
case 1:
|
|
521
|
-
result = _state.sent().data;
|
|
522
|
-
_this.streamId = result.data.stream_id;
|
|
523
|
-
return [
|
|
524
|
-
2,
|
|
525
|
-
_this
|
|
526
|
-
];
|
|
527
|
-
}
|
|
528
|
-
});
|
|
529
|
-
})();
|
|
530
|
-
}
|
|
531
|
-
},
|
|
532
|
-
{
|
|
533
|
-
key: "generateImage",
|
|
534
|
-
value: function generateImage(query) {
|
|
535
|
-
var _this = this;
|
|
536
|
-
return _async_to_generator(function() {
|
|
537
|
-
return _ts_generator(this, function(_state) {
|
|
538
|
-
if (!_this.stableDiffusionProvider) {
|
|
539
|
-
throw new Error("Stable Diffusion provider not initialized");
|
|
540
|
-
}
|
|
541
|
-
return [
|
|
542
|
-
2,
|
|
543
|
-
_this.stableDiffusionProvider.generateImage(query)
|
|
544
|
-
];
|
|
545
|
-
});
|
|
546
|
-
})();
|
|
547
|
-
}
|
|
548
|
-
},
|
|
549
|
-
{
|
|
550
|
-
key: "analyzeCharacterization",
|
|
551
|
-
value: function analyzeCharacterization(text) {
|
|
552
|
-
var _this = this;
|
|
553
|
-
return _async_to_generator(function() {
|
|
554
|
-
return _ts_generator(this, function(_state) {
|
|
555
|
-
if (!_this.analyzeCharacterizationProvider) {
|
|
556
|
-
throw new Error("analyze characterization provider not initialized");
|
|
557
|
-
}
|
|
558
|
-
return [
|
|
559
|
-
2,
|
|
560
|
-
_this.analyzeCharacterizationProvider.analyzeCharacterization(text)
|
|
561
|
-
];
|
|
562
|
-
});
|
|
563
|
-
})();
|
|
564
|
-
}
|
|
565
|
-
},
|
|
566
|
-
{
|
|
567
|
-
key: "rate",
|
|
568
|
-
value: function rate(data) {
|
|
569
|
-
var _this = this;
|
|
570
|
-
return _async_to_generator(function() {
|
|
571
|
-
return _ts_generator(this, function(_state) {
|
|
572
|
-
if (!_this.ratingsProvider) {
|
|
573
|
-
throw new Error("ratings provider not initialized");
|
|
574
|
-
}
|
|
575
|
-
return [
|
|
576
|
-
2,
|
|
577
|
-
_this.ratingsProvider.rate(data)
|
|
578
|
-
];
|
|
579
|
-
});
|
|
580
|
-
})();
|
|
581
|
-
}
|
|
582
|
-
},
|
|
583
|
-
{
|
|
584
|
-
key: "logInfo",
|
|
585
|
-
value: function logInfo(message, data) {
|
|
586
|
-
var _this = this;
|
|
587
|
-
return _async_to_generator(function() {
|
|
588
|
-
return _ts_generator(this, function(_state) {
|
|
589
|
-
if (!_this.loggerProvider) {
|
|
590
|
-
throw new Error("logger provider not initialized");
|
|
591
|
-
}
|
|
592
|
-
return [
|
|
593
|
-
2,
|
|
594
|
-
_this.loggerProvider.logInfo(message, data)
|
|
595
|
-
];
|
|
596
|
-
});
|
|
597
|
-
})();
|
|
598
|
-
}
|
|
599
|
-
},
|
|
600
|
-
{
|
|
601
|
-
key: "logError",
|
|
602
|
-
value: function logError(message, error, data) {
|
|
603
|
-
var _this = this;
|
|
604
|
-
return _async_to_generator(function() {
|
|
605
|
-
return _ts_generator(this, function(_state) {
|
|
606
|
-
if (!_this.loggerProvider) {
|
|
607
|
-
throw new Error("logger provider not initialized");
|
|
608
|
-
}
|
|
609
|
-
return [
|
|
610
|
-
2,
|
|
611
|
-
_this.loggerProvider.logError(message, error, data)
|
|
612
|
-
];
|
|
613
|
-
});
|
|
614
|
-
})();
|
|
615
|
-
}
|
|
616
|
-
},
|
|
617
|
-
{
|
|
618
|
-
key: "getUrlStream",
|
|
619
|
-
value: function getUrlStream() {
|
|
620
|
-
return "".concat(this.config.streamUrl, "/").concat(this.streamId);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
], [
|
|
624
|
-
{
|
|
625
|
-
key: "configure",
|
|
626
|
-
value: function configure(apiKey, inferUrl, streamUrl, assistantId) {
|
|
627
|
-
return {
|
|
628
|
-
apiKey: apiKey,
|
|
629
|
-
chatUrl: "".concat(inferUrl, "/chat/").concat(assistantId),
|
|
630
|
-
streamUrl: "".concat(streamUrl, "/").concat(assistantId),
|
|
631
|
-
assistantId: assistantId
|
|
632
|
-
};
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
]);
|
|
636
|
-
return AlquimiaSDK;
|
|
637
|
-
}();
|
|
638
200
|
var alquimia_sdk_default = AlquimiaSDK;
|
|
201
|
+
|
|
639
202
|
// src/sdk/providers/providers.ts
|
|
640
|
-
var GenerativeProvider =
|
|
641
|
-
|
|
642
|
-
_class_call_check(this, GenerativeProvider);
|
|
203
|
+
var GenerativeProvider = class {
|
|
204
|
+
constructor(config) {
|
|
643
205
|
this.config = config;
|
|
206
|
+
}
|
|
644
207
|
};
|
|
645
|
-
var WhisperProvider =
|
|
646
|
-
|
|
647
|
-
_class_call_check(this, WhisperProvider);
|
|
208
|
+
var WhisperProvider = class {
|
|
209
|
+
constructor(config) {
|
|
648
210
|
this.config = config;
|
|
211
|
+
}
|
|
649
212
|
};
|
|
650
|
-
var StableDiffusionProvider =
|
|
651
|
-
|
|
652
|
-
_class_call_check(this, StableDiffusionProvider);
|
|
213
|
+
var StableDiffusionProvider = class {
|
|
214
|
+
constructor(config) {
|
|
653
215
|
this.config = config;
|
|
216
|
+
}
|
|
654
217
|
};
|
|
655
|
-
var CharacterizationProvider =
|
|
656
|
-
|
|
657
|
-
_class_call_check(this, CharacterizationProvider);
|
|
218
|
+
var CharacterizationProvider = class {
|
|
219
|
+
constructor(config) {
|
|
658
220
|
this.config = config;
|
|
221
|
+
}
|
|
659
222
|
};
|
|
660
|
-
var RatingsProvider =
|
|
661
|
-
|
|
662
|
-
_class_call_check(this, RatingsProvider);
|
|
223
|
+
var RatingsProvider = class {
|
|
224
|
+
constructor(config) {
|
|
663
225
|
this.config = config;
|
|
226
|
+
}
|
|
664
227
|
};
|
|
665
|
-
var LoggerProvider =
|
|
666
|
-
|
|
667
|
-
_class_call_check(this, LoggerProvider);
|
|
228
|
+
var LoggerProvider = class {
|
|
229
|
+
constructor(config) {
|
|
668
230
|
this.config = config;
|
|
231
|
+
}
|
|
669
232
|
};
|
|
233
|
+
|
|
670
234
|
// src/sdk/providers/alquimia.ts
|
|
671
235
|
import axios2 from "axios";
|
|
672
|
-
var AlquimiaWhisperProvider =
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
236
|
+
var AlquimiaWhisperProvider = class extends WhisperProvider {
|
|
237
|
+
constructor(config) {
|
|
238
|
+
super(config);
|
|
239
|
+
}
|
|
240
|
+
async textToSpeech(text) {
|
|
241
|
+
const axiosClient = axios2.create({
|
|
242
|
+
baseURL: this.config.baseURL
|
|
243
|
+
});
|
|
244
|
+
try {
|
|
245
|
+
const response = await axiosClient.post(
|
|
246
|
+
this.config.ttsRoute,
|
|
682
247
|
{
|
|
683
|
-
|
|
684
|
-
value: function textToSpeech(text) {
|
|
685
|
-
var _this = this;
|
|
686
|
-
return _async_to_generator(function() {
|
|
687
|
-
var axiosClient, response, error;
|
|
688
|
-
return _ts_generator(this, function(_state) {
|
|
689
|
-
switch(_state.label){
|
|
690
|
-
case 0:
|
|
691
|
-
axiosClient = axios2.create({
|
|
692
|
-
baseURL: _this.config.baseURL
|
|
693
|
-
});
|
|
694
|
-
_state.label = 1;
|
|
695
|
-
case 1:
|
|
696
|
-
_state.trys.push([
|
|
697
|
-
1,
|
|
698
|
-
3,
|
|
699
|
-
,
|
|
700
|
-
4
|
|
701
|
-
]);
|
|
702
|
-
return [
|
|
703
|
-
4,
|
|
704
|
-
axiosClient.post(_this.config.ttsRoute, {
|
|
705
|
-
text: text
|
|
706
|
-
}, {
|
|
707
|
-
responseType: "blob"
|
|
708
|
-
})
|
|
709
|
-
];
|
|
710
|
-
case 2:
|
|
711
|
-
response = _state.sent();
|
|
712
|
-
return [
|
|
713
|
-
2,
|
|
714
|
-
response.data
|
|
715
|
-
];
|
|
716
|
-
case 3:
|
|
717
|
-
error = _state.sent();
|
|
718
|
-
console.error("Error converting text to speech:", error);
|
|
719
|
-
throw error;
|
|
720
|
-
case 4:
|
|
721
|
-
return [
|
|
722
|
-
2
|
|
723
|
-
];
|
|
724
|
-
}
|
|
725
|
-
});
|
|
726
|
-
})();
|
|
727
|
-
}
|
|
248
|
+
text
|
|
728
249
|
},
|
|
729
|
-
{
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
250
|
+
{ responseType: "blob" }
|
|
251
|
+
);
|
|
252
|
+
return response.data;
|
|
253
|
+
} catch (error) {
|
|
254
|
+
console.error("Error converting text to speech:", error);
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
async speechToText(audio) {
|
|
259
|
+
const axiosClient = axios2.create({
|
|
260
|
+
baseURL: this.config.baseURL
|
|
261
|
+
});
|
|
262
|
+
try {
|
|
263
|
+
const response = await axiosClient.post(this.config.sttRoute, {
|
|
264
|
+
audio
|
|
265
|
+
});
|
|
266
|
+
return response.data;
|
|
267
|
+
} catch (error) {
|
|
268
|
+
console.error("Error converting speech to text:", error);
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
var AlquimiaRatingsProvider = class extends RatingsProvider {
|
|
274
|
+
constructor(config) {
|
|
275
|
+
super(config);
|
|
276
|
+
}
|
|
277
|
+
async rate(data) {
|
|
278
|
+
const path = `${this.config.baseUrl}${this.config.route}`;
|
|
279
|
+
try {
|
|
280
|
+
let response;
|
|
281
|
+
const headers = {
|
|
282
|
+
Authorization: `Bearer ${this.config.token}`,
|
|
283
|
+
"Content-Type": "application/json",
|
|
284
|
+
...this.config.headers || {}
|
|
285
|
+
};
|
|
286
|
+
response = await axios2.post(`${path}`, data, { headers });
|
|
287
|
+
return {
|
|
288
|
+
success: true,
|
|
289
|
+
data: response.data
|
|
290
|
+
};
|
|
291
|
+
} catch (error) {
|
|
292
|
+
if (axios2.isAxiosError(error)) {
|
|
293
|
+
return {
|
|
294
|
+
success: false,
|
|
295
|
+
error: {
|
|
296
|
+
message: error.message,
|
|
297
|
+
response: {
|
|
298
|
+
status: error.response?.status,
|
|
299
|
+
data: error.response?.data
|
|
300
|
+
},
|
|
301
|
+
details: error.response?.data
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
success: false,
|
|
307
|
+
error: {
|
|
308
|
+
message: error instanceof Error ? error.message : "Unknown error occurred",
|
|
309
|
+
response: {
|
|
310
|
+
status: 500
|
|
311
|
+
}
|
|
773
312
|
}
|
|
774
|
-
|
|
775
|
-
return AlquimiaWhisperProvider;
|
|
776
|
-
}(WhisperProvider);
|
|
777
|
-
var AlquimiaRatingsProvider = /*#__PURE__*/ function(RatingsProvider) {
|
|
778
|
-
"use strict";
|
|
779
|
-
_inherits(AlquimiaRatingsProvider, RatingsProvider);
|
|
780
|
-
function AlquimiaRatingsProvider(config) {
|
|
781
|
-
_class_call_check(this, AlquimiaRatingsProvider);
|
|
782
|
-
return _call_super(this, AlquimiaRatingsProvider, [
|
|
783
|
-
config
|
|
784
|
-
]);
|
|
313
|
+
};
|
|
785
314
|
}
|
|
786
|
-
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
// src/utils/utils.ts
|
|
319
|
+
function generateTranslatePrompt(text) {
|
|
320
|
+
const prompt = `
|
|
321
|
+
Arrange the following text according to the given object structure and return it as plain json, values summarized to one word, no formatting:
|
|
787
322
|
{
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
4
|
|
804
|
-
]);
|
|
805
|
-
headers = _object_spread({
|
|
806
|
-
Authorization: "Bearer ".concat(_this.config.token),
|
|
807
|
-
"Content-Type": "application/json"
|
|
808
|
-
}, _this.config.headers || {});
|
|
809
|
-
return [
|
|
810
|
-
4,
|
|
811
|
-
axios2.post("".concat(path), data, {
|
|
812
|
-
headers: headers
|
|
813
|
-
})
|
|
814
|
-
];
|
|
815
|
-
case 2:
|
|
816
|
-
response = _state.sent();
|
|
817
|
-
return [
|
|
818
|
-
2,
|
|
819
|
-
{
|
|
820
|
-
success: true,
|
|
821
|
-
data: response.data
|
|
822
|
-
}
|
|
823
|
-
];
|
|
824
|
-
case 3:
|
|
825
|
-
error = _state.sent();
|
|
826
|
-
if (axios2.isAxiosError(error)) {
|
|
827
|
-
;
|
|
828
|
-
return [
|
|
829
|
-
2,
|
|
830
|
-
{
|
|
831
|
-
success: false,
|
|
832
|
-
error: {
|
|
833
|
-
message: error.message,
|
|
834
|
-
response: {
|
|
835
|
-
status: (_error_response = error.response) === null || _error_response === void 0 ? void 0 : _error_response.status,
|
|
836
|
-
data: (_error_response1 = error.response) === null || _error_response1 === void 0 ? void 0 : _error_response1.data
|
|
837
|
-
},
|
|
838
|
-
details: (_error_response2 = error.response) === null || _error_response2 === void 0 ? void 0 : _error_response2.data
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
];
|
|
842
|
-
}
|
|
843
|
-
return [
|
|
844
|
-
2,
|
|
845
|
-
{
|
|
846
|
-
success: false,
|
|
847
|
-
error: {
|
|
848
|
-
message: _instanceof(error, Error) ? error.message : "Unknown error occurred",
|
|
849
|
-
response: {
|
|
850
|
-
status: 500
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
];
|
|
855
|
-
case 4:
|
|
856
|
-
return [
|
|
857
|
-
2
|
|
858
|
-
];
|
|
859
|
-
}
|
|
860
|
-
});
|
|
861
|
-
})();
|
|
323
|
+
restrictions: {
|
|
324
|
+
value: [''],
|
|
325
|
+
description: 'Restrictions to certain foods'
|
|
326
|
+
},
|
|
327
|
+
alergies: {
|
|
328
|
+
value: [''],
|
|
329
|
+
description: 'Alergies to certain foods'
|
|
330
|
+
},
|
|
331
|
+
wine_preference: {
|
|
332
|
+
value: [''],
|
|
333
|
+
description: 'Preferences for the wine'
|
|
334
|
+
},
|
|
335
|
+
meal_preference: {
|
|
336
|
+
value: [''],
|
|
337
|
+
description: 'Preferences for the meal'
|
|
862
338
|
}
|
|
863
339
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
return prompt;
|
|
340
|
+
|
|
341
|
+
Text: "${text}"
|
|
342
|
+
|
|
343
|
+
Output:
|
|
344
|
+
`;
|
|
345
|
+
return prompt;
|
|
871
346
|
}
|
|
872
347
|
function getCookies(name) {
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
if (parts.length === 2) return (_parts_pop = parts.pop()) === null || _parts_pop === void 0 ? void 0 : _parts_pop.split(";").shift();
|
|
348
|
+
if (typeof document === "undefined") return void 0;
|
|
349
|
+
const value = `; ${document.cookie}`;
|
|
350
|
+
const parts = value.split(`; ${name}=`);
|
|
351
|
+
if (parts.length === 2) return parts.pop()?.split(";").shift();
|
|
878
352
|
}
|
|
879
353
|
function generateHeaders(config) {
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
return headers;
|
|
354
|
+
const headers = {
|
|
355
|
+
"Content-Type": "application/json"
|
|
356
|
+
};
|
|
357
|
+
if (config.token) {
|
|
358
|
+
headers["Authorization"] = `Bearer ${config.token}`;
|
|
359
|
+
}
|
|
360
|
+
if (config.headers) {
|
|
361
|
+
Object.entries(config.headers).forEach(([key, value]) => {
|
|
362
|
+
headers[key] = value;
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
return headers;
|
|
893
366
|
}
|
|
894
367
|
function isTextContent(buffer) {
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
368
|
+
try {
|
|
369
|
+
const text = new TextDecoder().decode(buffer);
|
|
370
|
+
return /^[\w\#\-\*]/.test(text.trim());
|
|
371
|
+
} catch {
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
901
374
|
}
|
|
902
375
|
function getQueryParam(param) {
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
376
|
+
if (typeof window !== "undefined") {
|
|
377
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
378
|
+
return urlParams.get(param);
|
|
379
|
+
}
|
|
380
|
+
return null;
|
|
908
381
|
}
|
|
909
382
|
function defineAssistantId(defaultId) {
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
}
|
|
916
|
-
var storedAssistantId = localStorage.getItem("assistantId");
|
|
917
|
-
return storedAssistantId || defaultId;
|
|
383
|
+
if (typeof window !== "undefined" && window.location.pathname === "/") {
|
|
384
|
+
const queryAssistantId = getQueryParam("talkwith");
|
|
385
|
+
if (queryAssistantId) {
|
|
386
|
+
localStorage.setItem("assistantId", queryAssistantId);
|
|
387
|
+
return queryAssistantId;
|
|
918
388
|
}
|
|
919
|
-
|
|
389
|
+
const storedAssistantId = localStorage.getItem("assistantId");
|
|
390
|
+
return storedAssistantId || defaultId;
|
|
391
|
+
}
|
|
392
|
+
return defaultId;
|
|
920
393
|
}
|
|
921
394
|
function formatTimeWithUnit(timeMs) {
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
395
|
+
if (timeMs >= 1e3) {
|
|
396
|
+
return `${(timeMs / 1e3).toFixed(1)}s`;
|
|
397
|
+
}
|
|
398
|
+
return `${Math.round(timeMs)}ms`;
|
|
926
399
|
}
|
|
927
400
|
function serializeAxiosError(error) {
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
return {
|
|
931
|
-
message: customError === null || customError === void 0 ? void 0 : customError.message,
|
|
932
|
-
name: customError === null || customError === void 0 ? void 0 : customError.name,
|
|
933
|
-
stack: customError === null || customError === void 0 ? void 0 : customError.stack,
|
|
934
|
-
code: customError === null || customError === void 0 ? void 0 : customError.code,
|
|
935
|
-
status: customError === null || customError === void 0 ? void 0 : customError.status
|
|
936
|
-
};
|
|
937
|
-
}
|
|
401
|
+
if (error instanceof Error) {
|
|
402
|
+
const customError = error;
|
|
938
403
|
return {
|
|
939
|
-
|
|
940
|
-
|
|
404
|
+
message: customError?.message,
|
|
405
|
+
name: customError?.name,
|
|
406
|
+
stack: customError?.stack,
|
|
407
|
+
code: customError?.code,
|
|
408
|
+
status: customError?.status
|
|
941
409
|
};
|
|
410
|
+
}
|
|
411
|
+
return {
|
|
412
|
+
message: String(error),
|
|
413
|
+
name: "Unknown Error"
|
|
414
|
+
};
|
|
942
415
|
}
|
|
943
416
|
function parseConversationsMapCookie(cookieValue) {
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
417
|
+
try {
|
|
418
|
+
const decodedValue = decodeURIComponent(cookieValue);
|
|
419
|
+
return JSON.parse(decodedValue);
|
|
420
|
+
} catch (e) {
|
|
421
|
+
console.error("Error parsing conversations cookie:", e);
|
|
422
|
+
return {};
|
|
423
|
+
}
|
|
951
424
|
}
|
|
952
425
|
function getTopicSessionId(topicId) {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
426
|
+
const conversationsStr = getCookies("alquimia-sessions") || "{}";
|
|
427
|
+
if (!conversationsStr) {
|
|
428
|
+
const sessionCookie = getCookies("alquimia-session");
|
|
429
|
+
return sessionCookie || "";
|
|
430
|
+
}
|
|
431
|
+
const conversationsMap = parseConversationsMapCookie(conversationsStr);
|
|
432
|
+
return conversationsMap[topicId] || "";
|
|
960
433
|
}
|
|
961
434
|
function createMessageId() {
|
|
962
|
-
|
|
435
|
+
return Math.floor(Math.random() * 1e6).toString();
|
|
963
436
|
}
|
|
437
|
+
|
|
964
438
|
// src/sdk/providers/openai.ts
|
|
965
439
|
import OpenAI from "openai";
|
|
966
|
-
var OpenAIWhisperProvider =
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
},
|
|
987
|
-
{
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
]);
|
|
1001
|
-
return OpenAIWhisperProvider;
|
|
1002
|
-
}(WhisperProvider);
|
|
1003
|
-
var OpenAIAnalyzeCharProvider = /*#__PURE__*/ function(CharacterizationProvider) {
|
|
1004
|
-
"use strict";
|
|
1005
|
-
_inherits(OpenAIAnalyzeCharProvider, CharacterizationProvider);
|
|
1006
|
-
function OpenAIAnalyzeCharProvider(config) {
|
|
1007
|
-
_class_call_check(this, OpenAIAnalyzeCharProvider);
|
|
1008
|
-
var _this;
|
|
1009
|
-
_this = _call_super(this, OpenAIAnalyzeCharProvider, [
|
|
1010
|
-
config
|
|
1011
|
-
]);
|
|
1012
|
-
_this.client = new OpenAI({
|
|
1013
|
-
apiKey: config.apiKey
|
|
1014
|
-
});
|
|
1015
|
-
return _this;
|
|
1016
|
-
}
|
|
1017
|
-
_create_class(OpenAIAnalyzeCharProvider, [
|
|
1018
|
-
{
|
|
1019
|
-
key: "analyzeCharacterization",
|
|
1020
|
-
value: function analyzeCharacterization(text) {
|
|
1021
|
-
var _this = this;
|
|
1022
|
-
return _async_to_generator(function() {
|
|
1023
|
-
var prompt, response, arrangedText, arrangedObject;
|
|
1024
|
-
return _ts_generator(this, function(_state) {
|
|
1025
|
-
switch(_state.label){
|
|
1026
|
-
case 0:
|
|
1027
|
-
prompt = generateTranslatePrompt(text);
|
|
1028
|
-
return [
|
|
1029
|
-
4,
|
|
1030
|
-
_this.client.chat.completions.create({
|
|
1031
|
-
model: "gpt-4o-mini",
|
|
1032
|
-
messages: [
|
|
1033
|
-
{
|
|
1034
|
-
role: "system",
|
|
1035
|
-
content: "You are a helpful assistant."
|
|
1036
|
-
},
|
|
1037
|
-
{
|
|
1038
|
-
role: "user",
|
|
1039
|
-
content: prompt
|
|
1040
|
-
}
|
|
1041
|
-
],
|
|
1042
|
-
max_tokens: 150,
|
|
1043
|
-
temperature: 0.7
|
|
1044
|
-
})
|
|
1045
|
-
];
|
|
1046
|
-
case 1:
|
|
1047
|
-
response = _state.sent();
|
|
1048
|
-
arrangedText = response.choices[0].message.content.trim();
|
|
1049
|
-
try {
|
|
1050
|
-
arrangedObject = JSON.parse(arrangedText);
|
|
1051
|
-
return [
|
|
1052
|
-
2,
|
|
1053
|
-
arrangedObject
|
|
1054
|
-
];
|
|
1055
|
-
} catch (error) {
|
|
1056
|
-
throw new Error("Failed to parse the response from OpenAI");
|
|
1057
|
-
}
|
|
1058
|
-
return [
|
|
1059
|
-
2
|
|
1060
|
-
];
|
|
1061
|
-
}
|
|
1062
|
-
});
|
|
1063
|
-
})();
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
]);
|
|
1067
|
-
return OpenAIAnalyzeCharProvider;
|
|
1068
|
-
}(CharacterizationProvider);
|
|
1069
|
-
var OpenAIStableDiffusionProvider = /*#__PURE__*/ function(StableDiffusionProvider) {
|
|
1070
|
-
"use strict";
|
|
1071
|
-
_inherits(OpenAIStableDiffusionProvider, StableDiffusionProvider);
|
|
1072
|
-
function OpenAIStableDiffusionProvider(config) {
|
|
1073
|
-
_class_call_check(this, OpenAIStableDiffusionProvider);
|
|
1074
|
-
var _this;
|
|
1075
|
-
_this = _call_super(this, OpenAIStableDiffusionProvider, [
|
|
1076
|
-
config
|
|
1077
|
-
]);
|
|
1078
|
-
_this.client = new OpenAI({
|
|
1079
|
-
apiKey: config.apiKey
|
|
1080
|
-
});
|
|
1081
|
-
return _this;
|
|
440
|
+
var OpenAIWhisperProvider = class extends WhisperProvider {
|
|
441
|
+
async textToSpeech(text) {
|
|
442
|
+
return new Blob();
|
|
443
|
+
}
|
|
444
|
+
async speechToText(audio) {
|
|
445
|
+
return "";
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
var OpenAIAnalyzeCharProvider = class extends CharacterizationProvider {
|
|
449
|
+
constructor(config) {
|
|
450
|
+
super(config);
|
|
451
|
+
this.client = new OpenAI({
|
|
452
|
+
apiKey: config.apiKey
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
async analyzeCharacterization(text) {
|
|
456
|
+
const prompt = generateTranslatePrompt(text);
|
|
457
|
+
const response = await this.client.chat.completions.create({
|
|
458
|
+
model: "gpt-4o-mini",
|
|
459
|
+
messages: [
|
|
460
|
+
{ role: "system", content: "You are a helpful assistant." },
|
|
461
|
+
{ role: "user", content: prompt }
|
|
462
|
+
],
|
|
463
|
+
max_tokens: 150,
|
|
464
|
+
temperature: 0.7
|
|
465
|
+
});
|
|
466
|
+
const arrangedText = response.choices[0].message.content.trim();
|
|
467
|
+
try {
|
|
468
|
+
const arrangedObject = JSON.parse(arrangedText);
|
|
469
|
+
return arrangedObject;
|
|
470
|
+
} catch (error) {
|
|
471
|
+
throw new Error("Failed to parse the response from OpenAI");
|
|
1082
472
|
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
response = _state.sent();
|
|
1104
|
-
return [
|
|
1105
|
-
2,
|
|
1106
|
-
response.data[0].url
|
|
1107
|
-
];
|
|
1108
|
-
}
|
|
1109
|
-
});
|
|
1110
|
-
})();
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
]);
|
|
1114
|
-
return OpenAIStableDiffusionProvider;
|
|
1115
|
-
}(StableDiffusionProvider);
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
var OpenAIStableDiffusionProvider = class extends StableDiffusionProvider {
|
|
476
|
+
constructor(config) {
|
|
477
|
+
super(config);
|
|
478
|
+
this.client = new OpenAI({
|
|
479
|
+
apiKey: config.apiKey
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
async generateImage(query) {
|
|
483
|
+
const response = await this.client.images.generate({
|
|
484
|
+
model: "dall-e-3",
|
|
485
|
+
prompt: query,
|
|
486
|
+
n: 1,
|
|
487
|
+
size: "1024x1024"
|
|
488
|
+
});
|
|
489
|
+
return response.data[0].url;
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
|
|
1116
493
|
// src/sdk/providers/stability.ts
|
|
1117
494
|
import { Buffer } from "buffer";
|
|
1118
495
|
import axios3 from "axios";
|
|
1119
|
-
var StabilityProvider =
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
case 0:
|
|
1138
|
-
payload = {
|
|
1139
|
-
prompt: "query",
|
|
1140
|
-
output_format: "webp"
|
|
1141
|
-
};
|
|
1142
|
-
return [
|
|
1143
|
-
4,
|
|
1144
|
-
axios3.postForm("https://api.stability.ai/v2beta/stable-image/generate/ultra", axios3.toFormData(payload, new FormData()), {
|
|
1145
|
-
validateStatus: void 0,
|
|
1146
|
-
responseType: "arraybuffer",
|
|
1147
|
-
headers: {
|
|
1148
|
-
Authorization: "Bearer ".concat(_this.config.apiKey),
|
|
1149
|
-
Accept: "image/*"
|
|
1150
|
-
}
|
|
1151
|
-
})
|
|
1152
|
-
];
|
|
1153
|
-
case 1:
|
|
1154
|
-
response = _state.sent();
|
|
1155
|
-
if (response.status === 200) {
|
|
1156
|
-
base64Image = Buffer.from(response.data).toString("base64");
|
|
1157
|
-
return [
|
|
1158
|
-
2,
|
|
1159
|
-
"data:image/webp;base64,".concat(base64Image)
|
|
1160
|
-
];
|
|
1161
|
-
} else {
|
|
1162
|
-
throw new Error("".concat(response.status, ": ").concat(response.data.toString()));
|
|
1163
|
-
}
|
|
1164
|
-
return [
|
|
1165
|
-
2
|
|
1166
|
-
];
|
|
1167
|
-
}
|
|
1168
|
-
});
|
|
1169
|
-
})();
|
|
1170
|
-
}
|
|
496
|
+
var StabilityProvider = class extends StableDiffusionProvider {
|
|
497
|
+
constructor(config) {
|
|
498
|
+
super(config);
|
|
499
|
+
}
|
|
500
|
+
async generateImage(query) {
|
|
501
|
+
const payload = {
|
|
502
|
+
prompt: "query",
|
|
503
|
+
output_format: "webp"
|
|
504
|
+
};
|
|
505
|
+
const response = await axios3.postForm(
|
|
506
|
+
`https://api.stability.ai/v2beta/stable-image/generate/ultra`,
|
|
507
|
+
axios3.toFormData(payload, new FormData()),
|
|
508
|
+
{
|
|
509
|
+
validateStatus: void 0,
|
|
510
|
+
responseType: "arraybuffer",
|
|
511
|
+
headers: {
|
|
512
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
513
|
+
Accept: "image/*"
|
|
1171
514
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
515
|
+
}
|
|
516
|
+
);
|
|
517
|
+
if (response.status === 200) {
|
|
518
|
+
const base64Image = Buffer.from(response.data).toString("base64");
|
|
519
|
+
return `data:image/webp;base64,${base64Image}`;
|
|
520
|
+
} else {
|
|
521
|
+
throw new Error(`${response.status}: ${response.data.toString()}`);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
|
|
1175
526
|
// src/sdk/providers/eleven-labs.ts
|
|
1176
527
|
import { ElevenLabsClient, ElevenLabs } from "elevenlabs";
|
|
1177
528
|
import axios4 from "axios";
|
|
1178
529
|
var requestSpecs = {
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
530
|
+
optimize_streaming_latency: ElevenLabs.OptimizeStreamingLatency.Zero,
|
|
531
|
+
output_format: ElevenLabs.OutputFormat.Mp344100128,
|
|
532
|
+
model_id: "eleven_multilingual_v1",
|
|
533
|
+
language: "es",
|
|
534
|
+
voice_settings: {
|
|
535
|
+
stability: 0.1,
|
|
536
|
+
similarity_boost: 0.15,
|
|
537
|
+
style: 0.2
|
|
538
|
+
}
|
|
1188
539
|
};
|
|
1189
|
-
var ElevenLabsWhisperProvider =
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
540
|
+
var ElevenLabsWhisperProvider = class extends WhisperProvider {
|
|
541
|
+
constructor(config) {
|
|
542
|
+
super(config);
|
|
543
|
+
this.client = new ElevenLabsClient(config);
|
|
544
|
+
}
|
|
545
|
+
async speechToText(audio) {
|
|
546
|
+
return "";
|
|
547
|
+
}
|
|
548
|
+
async textToSpeech(text) {
|
|
549
|
+
const axiosClient = axios4.create({
|
|
550
|
+
baseURL: this.config.baseURL,
|
|
551
|
+
headers: {
|
|
552
|
+
Accept: "audio/mpeg",
|
|
553
|
+
"Content-Type": "application/json",
|
|
554
|
+
"Xi-Api-Key": this.config.apiKey
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
try {
|
|
558
|
+
const response = await axiosClient.post(
|
|
559
|
+
`/v1/text-to-speech/${this.config.voiceId}`,
|
|
1202
560
|
{
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
return _async_to_generator(function() {
|
|
1206
|
-
return _ts_generator(this, function(_state) {
|
|
1207
|
-
return [
|
|
1208
|
-
2,
|
|
1209
|
-
""
|
|
1210
|
-
];
|
|
1211
|
-
});
|
|
1212
|
-
})();
|
|
1213
|
-
}
|
|
561
|
+
text,
|
|
562
|
+
...requestSpecs
|
|
1214
563
|
},
|
|
1215
|
-
{
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
baseURL: _this.config.baseURL,
|
|
1226
|
-
headers: {
|
|
1227
|
-
Accept: "audio/mpeg",
|
|
1228
|
-
"Content-Type": "application/json",
|
|
1229
|
-
"Xi-Api-Key": _this.config.apiKey
|
|
1230
|
-
}
|
|
1231
|
-
});
|
|
1232
|
-
_state.label = 1;
|
|
1233
|
-
case 1:
|
|
1234
|
-
_state.trys.push([
|
|
1235
|
-
1,
|
|
1236
|
-
3,
|
|
1237
|
-
,
|
|
1238
|
-
4
|
|
1239
|
-
]);
|
|
1240
|
-
return [
|
|
1241
|
-
4,
|
|
1242
|
-
axiosClient.post("/v1/text-to-speech/".concat(_this.config.voiceId), _object_spread({
|
|
1243
|
-
text: text
|
|
1244
|
-
}, requestSpecs), {
|
|
1245
|
-
responseType: "blob"
|
|
1246
|
-
})
|
|
1247
|
-
];
|
|
1248
|
-
case 2:
|
|
1249
|
-
response = _state.sent();
|
|
1250
|
-
return [
|
|
1251
|
-
2,
|
|
1252
|
-
response.data
|
|
1253
|
-
];
|
|
1254
|
-
case 3:
|
|
1255
|
-
error = _state.sent();
|
|
1256
|
-
console.error("Error converting text to speech:", error);
|
|
1257
|
-
throw error;
|
|
1258
|
-
case 4:
|
|
1259
|
-
return [
|
|
1260
|
-
2
|
|
1261
|
-
];
|
|
1262
|
-
}
|
|
1263
|
-
});
|
|
1264
|
-
})();
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
]);
|
|
1268
|
-
return ElevenLabsWhisperProvider;
|
|
1269
|
-
}(WhisperProvider);
|
|
564
|
+
{ responseType: "blob" }
|
|
565
|
+
);
|
|
566
|
+
return response.data;
|
|
567
|
+
} catch (error) {
|
|
568
|
+
console.error("Error converting text to speech:", error);
|
|
569
|
+
throw error;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
|
|
1270
574
|
// src/sdk/providers/elastic-search.ts
|
|
1271
575
|
import pino from "pino";
|
|
1272
|
-
var ElasticLoggerProvider =
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
3,
|
|
1296
|
-
2
|
|
1297
|
-
];
|
|
1298
|
-
return [
|
|
1299
|
-
4,
|
|
1300
|
-
Promise.all([
|
|
1301
|
-
import("pino-elasticsearch")
|
|
1302
|
-
])
|
|
1303
|
-
];
|
|
1304
|
-
case 1:
|
|
1305
|
-
_ref = _sliced_to_array.apply(void 0, [
|
|
1306
|
-
_state.sent(),
|
|
1307
|
-
1
|
|
1308
|
-
]), pinoElastic = _ref[0];
|
|
1309
|
-
streamToElastic = pinoElastic.default({
|
|
1310
|
-
index: config.index || "logs-index",
|
|
1311
|
-
node: config.endpoint,
|
|
1312
|
-
esVersion: config.esVersion || 7,
|
|
1313
|
-
flushBytes: config.flushBytes || 1e3,
|
|
1314
|
-
auth: {
|
|
1315
|
-
username: config.username || "",
|
|
1316
|
-
password: config.password || ""
|
|
1317
|
-
},
|
|
1318
|
-
tls: {
|
|
1319
|
-
rejectUnauthorized: false
|
|
1320
|
-
},
|
|
1321
|
-
op_type: "create"
|
|
1322
|
-
});
|
|
1323
|
-
streamToElastic.on("error", function(err) {
|
|
1324
|
-
console.error("Elasticsearch stream error:", err);
|
|
1325
|
-
});
|
|
1326
|
-
streamToElastic.on("insertError", function(err) {
|
|
1327
|
-
console.error("Elasticsearch insert error:", err);
|
|
1328
|
-
});
|
|
1329
|
-
streamToElastic.on("insert", function() {
|
|
1330
|
-
console.log("Successfully sent log to Elasticsearch");
|
|
1331
|
-
});
|
|
1332
|
-
_this.logger = pino({
|
|
1333
|
-
level: "info",
|
|
1334
|
-
timestamp: function() {
|
|
1335
|
-
return ',"time":"'.concat(/* @__PURE__ */ new Date().toISOString(), '"');
|
|
1336
|
-
}
|
|
1337
|
-
}, streamToElastic);
|
|
1338
|
-
_state.label = 2;
|
|
1339
|
-
case 2:
|
|
1340
|
-
return [
|
|
1341
|
-
2
|
|
1342
|
-
];
|
|
1343
|
-
}
|
|
1344
|
-
});
|
|
1345
|
-
})();
|
|
1346
|
-
}
|
|
576
|
+
var ElasticLoggerProvider = class _ElasticLoggerProvider extends LoggerProvider {
|
|
577
|
+
constructor(config) {
|
|
578
|
+
super(config);
|
|
579
|
+
this.logger = console;
|
|
580
|
+
}
|
|
581
|
+
static async create(config) {
|
|
582
|
+
const provider = new _ElasticLoggerProvider(config);
|
|
583
|
+
await provider.initialize(config);
|
|
584
|
+
return provider;
|
|
585
|
+
}
|
|
586
|
+
async initialize(config) {
|
|
587
|
+
if (typeof window === "undefined") {
|
|
588
|
+
const [pinoElastic] = await Promise.all([
|
|
589
|
+
import("pino-elasticsearch")
|
|
590
|
+
]);
|
|
591
|
+
const streamToElastic = pinoElastic.default({
|
|
592
|
+
index: config.index || "logs-index",
|
|
593
|
+
node: config.endpoint,
|
|
594
|
+
esVersion: config.esVersion || 7,
|
|
595
|
+
flushBytes: config.flushBytes || 1e3,
|
|
596
|
+
auth: {
|
|
597
|
+
username: config.username || "",
|
|
598
|
+
password: config.password || ""
|
|
1347
599
|
},
|
|
1348
|
-
{
|
|
1349
|
-
|
|
1350
|
-
value: function logInfo(message, data) {
|
|
1351
|
-
this.logger.info(_object_spread({}, data), message);
|
|
1352
|
-
}
|
|
600
|
+
tls: {
|
|
601
|
+
rejectUnauthorized: false
|
|
1353
602
|
},
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
2,
|
|
1385
|
-
provider
|
|
1386
|
-
];
|
|
1387
|
-
}
|
|
1388
|
-
});
|
|
1389
|
-
})();
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
]);
|
|
1393
|
-
return _ElasticLoggerProvider;
|
|
1394
|
-
}(LoggerProvider);
|
|
603
|
+
op_type: "create"
|
|
604
|
+
});
|
|
605
|
+
streamToElastic.on("error", (err) => {
|
|
606
|
+
console.error("Elasticsearch stream error:", err);
|
|
607
|
+
});
|
|
608
|
+
streamToElastic.on("insertError", (err) => {
|
|
609
|
+
console.error("Elasticsearch insert error:", err);
|
|
610
|
+
});
|
|
611
|
+
streamToElastic.on("insert", () => {
|
|
612
|
+
console.log("Successfully sent log to Elasticsearch");
|
|
613
|
+
});
|
|
614
|
+
this.logger = pino({
|
|
615
|
+
level: "info",
|
|
616
|
+
timestamp: () => `,"time":"${(/* @__PURE__ */ new Date()).toISOString()}"`
|
|
617
|
+
}, streamToElastic);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
logInfo(message, data) {
|
|
621
|
+
this.logger.info({ ...data }, message);
|
|
622
|
+
}
|
|
623
|
+
logError(message, error, data) {
|
|
624
|
+
const errorDetails = {
|
|
625
|
+
message: error.message,
|
|
626
|
+
name: error.name,
|
|
627
|
+
stack: error.stack
|
|
628
|
+
};
|
|
629
|
+
this.logger.error({ error, ...data, ...errorDetails }, message);
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
|
|
1395
633
|
// src/hooks/alquimia.hook.tsx
|
|
1396
634
|
import { useEffect as useEffect2, useState } from "react";
|
|
635
|
+
|
|
1397
636
|
// src/context/session-context.tsx
|
|
1398
|
-
import
|
|
637
|
+
import { createContext, useContext, useEffect, useReducer } from "react";
|
|
638
|
+
|
|
1399
639
|
// src/reducer/characterization-reducer.tsx
|
|
1400
|
-
var characterizationReducer =
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
640
|
+
var characterizationReducer = (state, action) => {
|
|
641
|
+
switch (action.type) {
|
|
642
|
+
case "SET_SESSION":
|
|
643
|
+
return {
|
|
644
|
+
...state,
|
|
645
|
+
sessionId: action.payload.sessionId,
|
|
646
|
+
characterizationData: action.payload.characterizationData
|
|
647
|
+
};
|
|
648
|
+
case "CLEAR_SESSION":
|
|
649
|
+
return {
|
|
650
|
+
...state,
|
|
651
|
+
sessionId: null,
|
|
652
|
+
characterizationData: null
|
|
653
|
+
};
|
|
654
|
+
default:
|
|
655
|
+
return state;
|
|
656
|
+
}
|
|
1415
657
|
};
|
|
658
|
+
|
|
1416
659
|
// src/context/session-context.tsx
|
|
1417
660
|
import { openDB } from "idb";
|
|
661
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1418
662
|
var initialState = {
|
|
1419
|
-
|
|
1420
|
-
|
|
663
|
+
sessionId: null,
|
|
664
|
+
characterizationData: null
|
|
1421
665
|
};
|
|
1422
666
|
var AlquimiaContext = createContext(null);
|
|
1423
|
-
var useSessionContext =
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
};
|
|
1431
|
-
}
|
|
1432
|
-
return context;
|
|
1433
|
-
};
|
|
1434
|
-
var SessionProvider = function(param) {
|
|
1435
|
-
var children = param.children;
|
|
1436
|
-
var _useReducer = _sliced_to_array(useReducer(characterizationReducer, initialState), 2), userSessionState = _useReducer[0], sessionDispatch = _useReducer[1];
|
|
1437
|
-
useEffect(function() {
|
|
1438
|
-
getSession();
|
|
1439
|
-
}, []);
|
|
1440
|
-
var getSession = /*#__PURE__*/ function() {
|
|
1441
|
-
var _ref = _async_to_generator(function() {
|
|
1442
|
-
var userCookie, db, sessionIdEntry, characterizationDataEntry, sessionDataMatchesCookie;
|
|
1443
|
-
return _ts_generator(this, function(_state) {
|
|
1444
|
-
switch(_state.label){
|
|
1445
|
-
case 0:
|
|
1446
|
-
return [
|
|
1447
|
-
4,
|
|
1448
|
-
getCookies("alquimia-session")
|
|
1449
|
-
];
|
|
1450
|
-
case 1:
|
|
1451
|
-
userCookie = _state.sent() || "";
|
|
1452
|
-
return [
|
|
1453
|
-
4,
|
|
1454
|
-
openDB("alquimiaDB", 1, {
|
|
1455
|
-
upgrade: function upgrade(db2) {
|
|
1456
|
-
if (!db2.objectStoreNames.contains("session")) {
|
|
1457
|
-
db2.createObjectStore("session", {
|
|
1458
|
-
keyPath: "key"
|
|
1459
|
-
});
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
})
|
|
1463
|
-
];
|
|
1464
|
-
case 2:
|
|
1465
|
-
db = _state.sent();
|
|
1466
|
-
return [
|
|
1467
|
-
4,
|
|
1468
|
-
db.get("session", "sessionId")
|
|
1469
|
-
];
|
|
1470
|
-
case 3:
|
|
1471
|
-
sessionIdEntry = _state.sent();
|
|
1472
|
-
return [
|
|
1473
|
-
4,
|
|
1474
|
-
db.get("session", "characterizationData")
|
|
1475
|
-
];
|
|
1476
|
-
case 4:
|
|
1477
|
-
characterizationDataEntry = _state.sent();
|
|
1478
|
-
sessionDataMatchesCookie = (sessionIdEntry === null || sessionIdEntry === void 0 ? void 0 : sessionIdEntry.value) === userCookie;
|
|
1479
|
-
if (sessionIdEntry && characterizationDataEntry && sessionDataMatchesCookie) {
|
|
1480
|
-
sessionDispatch({
|
|
1481
|
-
type: "SET_SESSION",
|
|
1482
|
-
payload: {
|
|
1483
|
-
sessionId: sessionIdEntry.value,
|
|
1484
|
-
characterizationData: characterizationDataEntry.value
|
|
1485
|
-
}
|
|
1486
|
-
});
|
|
1487
|
-
}
|
|
1488
|
-
return [
|
|
1489
|
-
2
|
|
1490
|
-
];
|
|
1491
|
-
}
|
|
1492
|
-
});
|
|
1493
|
-
});
|
|
1494
|
-
return function getSession() {
|
|
1495
|
-
return _ref.apply(this, arguments);
|
|
1496
|
-
};
|
|
1497
|
-
}();
|
|
1498
|
-
var saveUserSession = /*#__PURE__*/ function() {
|
|
1499
|
-
var _ref = _async_to_generator(function(id, data) {
|
|
1500
|
-
var db;
|
|
1501
|
-
return _ts_generator(this, function(_state) {
|
|
1502
|
-
switch(_state.label){
|
|
1503
|
-
case 0:
|
|
1504
|
-
return [
|
|
1505
|
-
4,
|
|
1506
|
-
openDB("alquimiaDB", 1)
|
|
1507
|
-
];
|
|
1508
|
-
case 1:
|
|
1509
|
-
db = _state.sent();
|
|
1510
|
-
return [
|
|
1511
|
-
4,
|
|
1512
|
-
db.put("session", {
|
|
1513
|
-
key: "sessionId",
|
|
1514
|
-
value: id
|
|
1515
|
-
})
|
|
1516
|
-
];
|
|
1517
|
-
case 2:
|
|
1518
|
-
_state.sent();
|
|
1519
|
-
return [
|
|
1520
|
-
4,
|
|
1521
|
-
db.put("session", {
|
|
1522
|
-
key: "characterizationData",
|
|
1523
|
-
value: data
|
|
1524
|
-
})
|
|
1525
|
-
];
|
|
1526
|
-
case 3:
|
|
1527
|
-
_state.sent();
|
|
1528
|
-
sessionDispatch({
|
|
1529
|
-
type: "SET_SESSION",
|
|
1530
|
-
payload: {
|
|
1531
|
-
sessionId: id,
|
|
1532
|
-
characterizationData: data
|
|
1533
|
-
}
|
|
1534
|
-
});
|
|
1535
|
-
return [
|
|
1536
|
-
2
|
|
1537
|
-
];
|
|
1538
|
-
}
|
|
1539
|
-
});
|
|
1540
|
-
});
|
|
1541
|
-
return function saveUserSession(id, data) {
|
|
1542
|
-
return _ref.apply(this, arguments);
|
|
1543
|
-
};
|
|
1544
|
-
}();
|
|
1545
|
-
var getSessionData = function() {
|
|
1546
|
-
return userSessionState;
|
|
667
|
+
var useSessionContext = () => {
|
|
668
|
+
const context = useContext(AlquimiaContext);
|
|
669
|
+
if (!context) {
|
|
670
|
+
console.warn("useSessionContext must be used within a session provider. Returning default value.");
|
|
671
|
+
return {
|
|
672
|
+
userSessionState: initialState,
|
|
673
|
+
saveUserSession: null
|
|
1547
674
|
};
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
675
|
+
}
|
|
676
|
+
return context;
|
|
677
|
+
};
|
|
678
|
+
var SessionProvider = ({ children }) => {
|
|
679
|
+
const [userSessionState, sessionDispatch] = useReducer(characterizationReducer, initialState);
|
|
680
|
+
useEffect(() => {
|
|
681
|
+
getSession();
|
|
682
|
+
}, []);
|
|
683
|
+
const getSession = async () => {
|
|
684
|
+
const userCookie = await getCookies("alquimia-session") || "";
|
|
685
|
+
const db = await openDB("alquimiaDB", 1, {
|
|
686
|
+
upgrade(db2) {
|
|
687
|
+
if (!db2.objectStoreNames.contains("session")) {
|
|
688
|
+
db2.createObjectStore("session", { keyPath: "key" });
|
|
1553
689
|
}
|
|
1554
|
-
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
const sessionIdEntry = await db.get("session", "sessionId");
|
|
693
|
+
const characterizationDataEntry = await db.get("session", "characterizationData");
|
|
694
|
+
const sessionDataMatchesCookie = sessionIdEntry?.value === userCookie;
|
|
695
|
+
if (sessionIdEntry && characterizationDataEntry && sessionDataMatchesCookie) {
|
|
696
|
+
sessionDispatch({
|
|
697
|
+
type: "SET_SESSION",
|
|
698
|
+
payload: {
|
|
699
|
+
sessionId: sessionIdEntry.value,
|
|
700
|
+
characterizationData: characterizationDataEntry.value
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
const saveUserSession = async (id, data) => {
|
|
706
|
+
const db = await openDB("alquimiaDB", 1);
|
|
707
|
+
await db.put("session", { key: "sessionId", value: id });
|
|
708
|
+
await db.put("session", { key: "characterizationData", value: data });
|
|
709
|
+
sessionDispatch({
|
|
710
|
+
type: "SET_SESSION",
|
|
711
|
+
payload: { sessionId: id, characterizationData: data }
|
|
712
|
+
});
|
|
713
|
+
};
|
|
714
|
+
const getSessionData = () => {
|
|
715
|
+
return userSessionState;
|
|
716
|
+
};
|
|
717
|
+
return /* @__PURE__ */ jsx4(AlquimiaContext.Provider, { value: { userSessionState, getSessionData, saveUserSession }, children });
|
|
1555
718
|
};
|
|
719
|
+
|
|
1556
720
|
// src/hooks/alquimia.hook.tsx
|
|
1557
721
|
function useAlquimia(sdk) {
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
sdk.withExtraData(userSessionState === null || userSessionState === void 0 ? void 0 : userSessionState.characterizationData);
|
|
1580
|
-
}
|
|
1581
|
-
}, [
|
|
1582
|
-
userSessionState
|
|
1583
|
-
]);
|
|
1584
|
-
function cleanMessages() {
|
|
1585
|
-
setMessages([]);
|
|
1586
|
-
}
|
|
1587
|
-
function processMessageChunk(messageId, chunk, error_code, error_detail, additionalInfo) {
|
|
1588
|
-
return _processMessageChunk.apply(this, arguments);
|
|
1589
|
-
}
|
|
1590
|
-
function _processMessageChunk() {
|
|
1591
|
-
_processMessageChunk = _async_to_generator(function(messageId, chunk, error_code, error_detail, additionalInfo) {
|
|
1592
|
-
return _ts_generator(this, function(_state) {
|
|
1593
|
-
setMessages(function(currentMessages) {
|
|
1594
|
-
var messageIndex = currentMessages.findIndex(function(message) {
|
|
1595
|
-
return message.id === messageId;
|
|
1596
|
-
});
|
|
1597
|
-
if (messageIndex !== -1) {
|
|
1598
|
-
var _updatedMessages_messageIndex, _updatedMessages_messageIndex1, _updatedMessages_messageIndex2;
|
|
1599
|
-
var updatedMessages = _to_consumable_array(currentMessages);
|
|
1600
|
-
var updatedMessage = _object_spread_props(_object_spread({}, updatedMessages[messageIndex]), {
|
|
1601
|
-
content: "".concat(((_updatedMessages_messageIndex = updatedMessages[messageIndex]) === null || _updatedMessages_messageIndex === void 0 ? void 0 : _updatedMessages_messageIndex.content) || "").concat(chunk),
|
|
1602
|
-
id: ((_updatedMessages_messageIndex1 = updatedMessages[messageIndex]) === null || _updatedMessages_messageIndex1 === void 0 ? void 0 : _updatedMessages_messageIndex1.id) || "",
|
|
1603
|
-
role: ((_updatedMessages_messageIndex2 = updatedMessages[messageIndex]) === null || _updatedMessages_messageIndex2 === void 0 ? void 0 : _updatedMessages_messageIndex2.role) || "assistant",
|
|
1604
|
-
error_code: error_code,
|
|
1605
|
-
error_detail: error_detail,
|
|
1606
|
-
additionalInfo: additionalInfo,
|
|
1607
|
-
created_at: /* @__PURE__ */ new Date().getTime().toString()
|
|
1608
|
-
});
|
|
1609
|
-
updatedMessages[messageIndex] = updatedMessage;
|
|
1610
|
-
return updatedMessages;
|
|
1611
|
-
} else {
|
|
1612
|
-
return _to_consumable_array(currentMessages).concat([
|
|
1613
|
-
{
|
|
1614
|
-
content: "".concat(chunk),
|
|
1615
|
-
role: "assistant",
|
|
1616
|
-
id: messageId,
|
|
1617
|
-
error_code: error_code,
|
|
1618
|
-
error_detail: error_detail,
|
|
1619
|
-
created_at: /* @__PURE__ */ new Date().getTime().toString()
|
|
1620
|
-
}
|
|
1621
|
-
]);
|
|
1622
|
-
}
|
|
1623
|
-
});
|
|
1624
|
-
return [
|
|
1625
|
-
2
|
|
1626
|
-
];
|
|
1627
|
-
});
|
|
1628
|
-
});
|
|
1629
|
-
return _processMessageChunk.apply(this, arguments);
|
|
1630
|
-
}
|
|
1631
|
-
function handleSubmit(event, traceParentId, sessionId2, additionalInfo) {
|
|
1632
|
-
return _handleSubmit.apply(this, arguments);
|
|
1633
|
-
}
|
|
1634
|
-
function _handleSubmit() {
|
|
1635
|
-
_handleSubmit = _async_to_generator(function(event, traceParentId, sessionId2, additionalInfo) {
|
|
1636
|
-
var messageId;
|
|
1637
|
-
return _ts_generator(this, function(_state) {
|
|
1638
|
-
switch(_state.label){
|
|
1639
|
-
case 0:
|
|
1640
|
-
setIsLoading(true);
|
|
1641
|
-
event.preventDefault();
|
|
1642
|
-
if (!input) return [
|
|
1643
|
-
3,
|
|
1644
|
-
2
|
|
1645
|
-
];
|
|
1646
|
-
addUserMessage(input);
|
|
1647
|
-
messageId = createMessageId();
|
|
1648
|
-
setCurrentMessageIdChuncked(messageId);
|
|
1649
|
-
setStreamingMessageId(messageId);
|
|
1650
|
-
return [
|
|
1651
|
-
4,
|
|
1652
|
-
sendMessage(input, function(chunk) {
|
|
1653
|
-
var _chunk_data;
|
|
1654
|
-
processMessageChunk(messageId, (chunk === null || chunk === void 0 ? void 0 : (_chunk_data = chunk.data) === null || _chunk_data === void 0 ? void 0 : _chunk_data.content) || "", chunk === null || chunk === void 0 ? void 0 : chunk.error_code, chunk === null || chunk === void 0 ? void 0 : chunk.error_detail, additionalInfo);
|
|
1655
|
-
}, traceParentId, sessionId2)
|
|
1656
|
-
];
|
|
1657
|
-
case 1:
|
|
1658
|
-
_state.sent();
|
|
1659
|
-
setInput("");
|
|
1660
|
-
_state.label = 2;
|
|
1661
|
-
case 2:
|
|
1662
|
-
setIsLoading(false);
|
|
1663
|
-
return [
|
|
1664
|
-
2
|
|
1665
|
-
];
|
|
1666
|
-
}
|
|
1667
|
-
});
|
|
1668
|
-
});
|
|
1669
|
-
return _handleSubmit.apply(this, arguments);
|
|
1670
|
-
}
|
|
1671
|
-
function handleInputChange(event) {
|
|
1672
|
-
setInput(event.target.value);
|
|
722
|
+
const [chunkReceived, setChunkReceived] = useState("");
|
|
723
|
+
const [currentMessageIdChuncked, setCurrentMessageIdChuncked] = useState("");
|
|
724
|
+
const [input, setInput] = useState("");
|
|
725
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
726
|
+
const [isMessageStreaming, setIsMessageStreaming] = useState(false);
|
|
727
|
+
const [streamingMessageId, setStreamingMessageId] = useState(null);
|
|
728
|
+
const [isAudioRecording, setIsAudioRecording] = useState(false);
|
|
729
|
+
const [messageMetaData, setMessageMetaData] = useState(null);
|
|
730
|
+
const [messages, setMessages] = useState([]);
|
|
731
|
+
const [sessionId, setSessionId] = useState(null);
|
|
732
|
+
const [activeTool, setActiveTool] = useState(null);
|
|
733
|
+
const [lastRequest, setLastRequest] = useState(null);
|
|
734
|
+
const { userSessionState, saveUserSession } = useSessionContext();
|
|
735
|
+
const shouldShowCharacterizationButton = sdk.getEnforceCharacterization() && !userSessionState?.characterizationData;
|
|
736
|
+
useEffect2(() => {
|
|
737
|
+
if (chunkReceived)
|
|
738
|
+
processMessageChunk(currentMessageIdChuncked, chunkReceived);
|
|
739
|
+
}, [chunkReceived]);
|
|
740
|
+
useEffect2(() => {
|
|
741
|
+
if (userSessionState?.characterizationData && sdk.getEnforceCharacterization()) {
|
|
742
|
+
sdk.withExtraData(userSessionState?.characterizationData);
|
|
1673
743
|
}
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
744
|
+
}, [userSessionState]);
|
|
745
|
+
function cleanMessages() {
|
|
746
|
+
setMessages([]);
|
|
747
|
+
}
|
|
748
|
+
async function processMessageChunk(messageId, chunk, error_code, error_detail, additionalInfo) {
|
|
749
|
+
setMessages((currentMessages) => {
|
|
750
|
+
const messageIndex = currentMessages.findIndex(
|
|
751
|
+
(message) => message.id === messageId
|
|
752
|
+
);
|
|
753
|
+
if (messageIndex !== -1) {
|
|
754
|
+
const updatedMessages = [...currentMessages];
|
|
755
|
+
const updatedMessage = {
|
|
756
|
+
...updatedMessages[messageIndex],
|
|
757
|
+
content: `${updatedMessages[messageIndex]?.content || ""}${chunk}`,
|
|
758
|
+
id: updatedMessages[messageIndex]?.id || "",
|
|
759
|
+
role: updatedMessages[messageIndex]?.role || "assistant",
|
|
760
|
+
error_code,
|
|
761
|
+
error_detail,
|
|
762
|
+
additionalInfo,
|
|
763
|
+
created_at: (/* @__PURE__ */ new Date()).getTime().toString()
|
|
764
|
+
};
|
|
765
|
+
updatedMessages[messageIndex] = updatedMessage;
|
|
766
|
+
return updatedMessages;
|
|
767
|
+
} else {
|
|
768
|
+
return [
|
|
769
|
+
...currentMessages,
|
|
770
|
+
{
|
|
771
|
+
content: `${chunk}`,
|
|
772
|
+
role: "assistant",
|
|
773
|
+
id: messageId,
|
|
774
|
+
error_code,
|
|
775
|
+
error_detail,
|
|
776
|
+
created_at: (/* @__PURE__ */ new Date()).getTime().toString()
|
|
777
|
+
}
|
|
778
|
+
];
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
async function handleSubmit(event, traceParentId, sessionId2, additionalInfo) {
|
|
783
|
+
setIsLoading(true);
|
|
784
|
+
event.preventDefault();
|
|
785
|
+
if (input) {
|
|
786
|
+
addUserMessage(input);
|
|
787
|
+
const messageId = createMessageId();
|
|
788
|
+
setCurrentMessageIdChuncked(messageId);
|
|
789
|
+
setStreamingMessageId(messageId);
|
|
790
|
+
await sendMessage(input, (chunk) => {
|
|
791
|
+
processMessageChunk(
|
|
792
|
+
messageId,
|
|
793
|
+
chunk?.data?.content || "",
|
|
794
|
+
chunk?.error_code,
|
|
795
|
+
chunk?.error_detail,
|
|
796
|
+
additionalInfo
|
|
797
|
+
);
|
|
798
|
+
}, traceParentId, sessionId2);
|
|
799
|
+
setInput("");
|
|
1723
800
|
}
|
|
1724
|
-
|
|
1725
|
-
|
|
801
|
+
setIsLoading(false);
|
|
802
|
+
}
|
|
803
|
+
function handleInputChange(event) {
|
|
804
|
+
setInput(event.target.value);
|
|
805
|
+
}
|
|
806
|
+
function handleReplaceInput(input2) {
|
|
807
|
+
setInput(input2);
|
|
808
|
+
}
|
|
809
|
+
function populateMessages(messages2) {
|
|
810
|
+
setMessages(messages2);
|
|
811
|
+
}
|
|
812
|
+
function handleLoadingCancel() {
|
|
813
|
+
setIsLoading(false);
|
|
814
|
+
setIsMessageStreaming(false);
|
|
815
|
+
setInput("");
|
|
816
|
+
}
|
|
817
|
+
function addUserMessage(message) {
|
|
818
|
+
setMessages((prevMessages) => [
|
|
819
|
+
...prevMessages,
|
|
820
|
+
{
|
|
821
|
+
content: message,
|
|
822
|
+
role: "user",
|
|
823
|
+
id: createMessageId(),
|
|
824
|
+
created_at: (/* @__PURE__ */ new Date()).getTime().toString()
|
|
825
|
+
}
|
|
826
|
+
]);
|
|
827
|
+
}
|
|
828
|
+
function getCookie(name) {
|
|
829
|
+
const cookies2 = document.cookie.split(";");
|
|
830
|
+
for (let cookie of cookies2) {
|
|
831
|
+
const [cookieName, cookieValue] = cookie.trim().split("=");
|
|
832
|
+
if (cookieName === name) {
|
|
833
|
+
return decodeURIComponent(cookieValue);
|
|
834
|
+
}
|
|
1726
835
|
}
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
case 1:
|
|
1742
|
-
response = _state.sent();
|
|
1743
|
-
es = new EventSource(response.getUrlStream());
|
|
1744
|
-
es.onmessage = function(event) {
|
|
1745
|
-
var parsedData = JSON.parse(event.data);
|
|
1746
|
-
if (parsedData.tooler && parsedData.tooler.length > 0 && !activeTool) {
|
|
1747
|
-
setActiveTool({
|
|
1748
|
-
tooler: parsedData.tooler
|
|
1749
|
-
});
|
|
1750
|
-
}
|
|
1751
|
-
if (parsedData.error_code) {
|
|
1752
|
-
callBack({
|
|
1753
|
-
type: "error",
|
|
1754
|
-
error_code: parsedData.error_code,
|
|
1755
|
-
error_detail: parsedData.error_detail
|
|
1756
|
-
});
|
|
1757
|
-
}
|
|
1758
|
-
if (parsedData.is_complete) {
|
|
1759
|
-
setIsMessageStreaming(false);
|
|
1760
|
-
setStreamingMessageId(null);
|
|
1761
|
-
es.close();
|
|
1762
|
-
} else {
|
|
1763
|
-
callBack(parsedData.answer);
|
|
1764
|
-
}
|
|
1765
|
-
};
|
|
1766
|
-
return [
|
|
1767
|
-
2
|
|
1768
|
-
];
|
|
1769
|
-
}
|
|
1770
|
-
});
|
|
836
|
+
return null;
|
|
837
|
+
}
|
|
838
|
+
async function sendMessage(message, callBack, traceParentId, sessionId2) {
|
|
839
|
+
const conversationId = sessionId2 || getCookie("alquimia-session");
|
|
840
|
+
setIsMessageStreaming(true);
|
|
841
|
+
setActiveTool(null);
|
|
842
|
+
setLastRequest(message);
|
|
843
|
+
const response = await sdk.widthConversationId(conversationId || "").sendMessage(message, traceParentId);
|
|
844
|
+
const es = new EventSource(response.getUrlStream());
|
|
845
|
+
es.onmessage = (event) => {
|
|
846
|
+
const parsedData = JSON.parse(event.data);
|
|
847
|
+
if (parsedData.tooler && parsedData.tooler.length > 0 && !activeTool) {
|
|
848
|
+
setActiveTool({
|
|
849
|
+
tooler: parsedData.tooler
|
|
1771
850
|
});
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
_handleSaveCharacterization = _async_to_generator(function(translation) {
|
|
1779
|
-
var conversationId;
|
|
1780
|
-
return _ts_generator(this, function(_state) {
|
|
1781
|
-
conversationId = getCookie("alquimia-session");
|
|
1782
|
-
if (!conversationId || !saveUserSession) return [
|
|
1783
|
-
2
|
|
1784
|
-
];
|
|
1785
|
-
saveUserSession(conversationId, translation);
|
|
1786
|
-
return [
|
|
1787
|
-
2
|
|
1788
|
-
];
|
|
1789
|
-
});
|
|
851
|
+
}
|
|
852
|
+
if (parsedData.error_code) {
|
|
853
|
+
callBack({
|
|
854
|
+
type: "error",
|
|
855
|
+
error_code: parsedData.error_code,
|
|
856
|
+
error_detail: parsedData.error_detail
|
|
1790
857
|
});
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
handleSubmit: handleSubmit,
|
|
1800
|
-
handleSaveCharacterization: handleSaveCharacterization,
|
|
1801
|
-
handleLoadingCancel: handleLoadingCancel,
|
|
1802
|
-
input: input,
|
|
1803
|
-
isLoading: isLoading,
|
|
1804
|
-
isMessageStreaming: isMessageStreaming,
|
|
1805
|
-
streamingMessageId: streamingMessageId,
|
|
1806
|
-
isAudioRecording: isAudioRecording,
|
|
1807
|
-
shouldShowCharacterizationButton: shouldShowCharacterizationButton,
|
|
1808
|
-
lastRequest: lastRequest,
|
|
1809
|
-
messageMetaData: messageMetaData,
|
|
1810
|
-
messages: messages,
|
|
1811
|
-
populateMessages: populateMessages,
|
|
1812
|
-
processMessageChunk: processMessageChunk,
|
|
1813
|
-
sendMessage: sendMessage,
|
|
1814
|
-
sessionId: sessionId,
|
|
1815
|
-
setActiveTool: setActiveTool,
|
|
1816
|
-
setSessionId: setSessionId,
|
|
1817
|
-
setLastRequest: setLastRequest,
|
|
1818
|
-
setIsAudioRecording: setIsAudioRecording
|
|
858
|
+
}
|
|
859
|
+
if (parsedData.is_complete) {
|
|
860
|
+
setIsMessageStreaming(false);
|
|
861
|
+
setStreamingMessageId(null);
|
|
862
|
+
es.close();
|
|
863
|
+
} else {
|
|
864
|
+
callBack(parsedData.answer);
|
|
865
|
+
}
|
|
1819
866
|
};
|
|
867
|
+
}
|
|
868
|
+
async function handleSaveCharacterization(translation) {
|
|
869
|
+
const conversationId = getCookie("alquimia-session");
|
|
870
|
+
if (!conversationId || !saveUserSession) return;
|
|
871
|
+
saveUserSession(conversationId, translation);
|
|
872
|
+
}
|
|
873
|
+
return {
|
|
874
|
+
activeTool,
|
|
875
|
+
cleanMessages,
|
|
876
|
+
createMessageId,
|
|
877
|
+
handleInputChange,
|
|
878
|
+
handleReplaceInput,
|
|
879
|
+
handleSubmit,
|
|
880
|
+
handleSaveCharacterization,
|
|
881
|
+
handleLoadingCancel,
|
|
882
|
+
input,
|
|
883
|
+
isLoading,
|
|
884
|
+
isMessageStreaming,
|
|
885
|
+
streamingMessageId,
|
|
886
|
+
isAudioRecording,
|
|
887
|
+
shouldShowCharacterizationButton,
|
|
888
|
+
lastRequest,
|
|
889
|
+
messageMetaData,
|
|
890
|
+
messages,
|
|
891
|
+
populateMessages,
|
|
892
|
+
processMessageChunk,
|
|
893
|
+
sendMessage,
|
|
894
|
+
sessionId,
|
|
895
|
+
setActiveTool,
|
|
896
|
+
setSessionId,
|
|
897
|
+
setLastRequest,
|
|
898
|
+
setIsAudioRecording
|
|
899
|
+
};
|
|
1820
900
|
}
|
|
901
|
+
|
|
1821
902
|
// src/hooks/useRatings.ts
|
|
1822
903
|
import { useState as useState2, useReducer as useReducer2 } from "react";
|
|
1823
904
|
var initialState2 = {
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
905
|
+
ratingStars: 0,
|
|
906
|
+
ratingThumbs: "",
|
|
907
|
+
ratingComment: ""
|
|
1827
908
|
};
|
|
1828
909
|
function ratingReducer(state, action) {
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
return _object_spread_props(_object_spread({}, state), {
|
|
1840
|
-
ratingComment: action.payload
|
|
1841
|
-
});
|
|
1842
|
-
default:
|
|
1843
|
-
return state;
|
|
1844
|
-
}
|
|
910
|
+
switch (action.type) {
|
|
911
|
+
case "SET_RATING_STARS":
|
|
912
|
+
return { ...state, ratingStars: action.payload };
|
|
913
|
+
case "SET_RATING_THUMBS":
|
|
914
|
+
return { ...state, ratingThumbs: action.payload };
|
|
915
|
+
case "SET_RATING_COMMENT":
|
|
916
|
+
return { ...state, ratingComment: action.payload };
|
|
917
|
+
default:
|
|
918
|
+
return state;
|
|
919
|
+
}
|
|
1845
920
|
}
|
|
1846
|
-
function useRatings(
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
};
|
|
1872
|
-
var handleRate = /*#__PURE__*/ function() {
|
|
1873
|
-
var _ref = _async_to_generator(function(key, value, onHandleRateSuccess) {
|
|
1874
|
-
var sessionId, ratingObj, response, err;
|
|
1875
|
-
return _ts_generator(this, function(_state) {
|
|
1876
|
-
switch(_state.label){
|
|
1877
|
-
case 0:
|
|
1878
|
-
setIsLoading(true);
|
|
1879
|
-
sessionId = getTopicSessionId(topicId);
|
|
1880
|
-
ratingObj = {
|
|
1881
|
-
topicId: parseInt(topicId),
|
|
1882
|
-
sessionId: sessionId || "",
|
|
1883
|
-
assistantId: assistantId,
|
|
1884
|
-
score: key === "score" ? value : thumbsScore(value),
|
|
1885
|
-
description: key === "description" ? value : state.ratingComment
|
|
1886
|
-
};
|
|
1887
|
-
_state.label = 1;
|
|
1888
|
-
case 1:
|
|
1889
|
-
_state.trys.push([
|
|
1890
|
-
1,
|
|
1891
|
-
3,
|
|
1892
|
-
,
|
|
1893
|
-
4
|
|
1894
|
-
]);
|
|
1895
|
-
return [
|
|
1896
|
-
4,
|
|
1897
|
-
sendRating(ratingObj)
|
|
1898
|
-
];
|
|
1899
|
-
case 2:
|
|
1900
|
-
response = _state.sent();
|
|
1901
|
-
if (!response.success) {
|
|
1902
|
-
setIsLoading(false);
|
|
1903
|
-
onHandleRateSuccess(false, response.error.message);
|
|
1904
|
-
return [
|
|
1905
|
-
2
|
|
1906
|
-
];
|
|
1907
|
-
}
|
|
1908
|
-
if (key === "score") {
|
|
1909
|
-
setRatingStars(value);
|
|
1910
|
-
} else if (key === "description") {
|
|
1911
|
-
setRatingComment(value);
|
|
1912
|
-
}
|
|
1913
|
-
setHasReviewed(true);
|
|
1914
|
-
setIsLoading(false);
|
|
1915
|
-
onHandleRateSuccess(true);
|
|
1916
|
-
return [
|
|
1917
|
-
3,
|
|
1918
|
-
4
|
|
1919
|
-
];
|
|
1920
|
-
case 3:
|
|
1921
|
-
err = _state.sent();
|
|
1922
|
-
setIsLoading(false);
|
|
1923
|
-
onHandleRateSuccess(false, String(err));
|
|
1924
|
-
return [
|
|
1925
|
-
3,
|
|
1926
|
-
4
|
|
1927
|
-
];
|
|
1928
|
-
case 4:
|
|
1929
|
-
return [
|
|
1930
|
-
2
|
|
1931
|
-
];
|
|
1932
|
-
}
|
|
1933
|
-
});
|
|
1934
|
-
});
|
|
1935
|
-
return function handleRate(key, value, onHandleRateSuccess) {
|
|
1936
|
-
return _ref.apply(this, arguments);
|
|
1937
|
-
};
|
|
1938
|
-
}();
|
|
1939
|
-
return {
|
|
1940
|
-
handleRate: handleRate,
|
|
1941
|
-
ratingStars: state.ratingStars,
|
|
1942
|
-
ratingThumbs: state.ratingThumbs,
|
|
1943
|
-
ratingComment: state.ratingComment,
|
|
1944
|
-
isLoading: isLoading,
|
|
1945
|
-
hasReviewed: hasReviewed
|
|
921
|
+
function useRatings({ assistantId, sendRating, topicId }) {
|
|
922
|
+
const [isLoading, setIsLoading] = useState2(false);
|
|
923
|
+
const [hasReviewed, setHasReviewed] = useState2(false);
|
|
924
|
+
const [state, dispatch] = useReducer2(ratingReducer, initialState2);
|
|
925
|
+
const setRatingStars = (rating) => {
|
|
926
|
+
dispatch({ type: "SET_RATING_STARS", payload: rating });
|
|
927
|
+
};
|
|
928
|
+
const setRatingThumbs = (rating) => {
|
|
929
|
+
dispatch({ type: "SET_RATING_THUMBS", payload: rating });
|
|
930
|
+
};
|
|
931
|
+
const setRatingComment = (comment) => {
|
|
932
|
+
dispatch({ type: "SET_RATING_COMMENT", payload: comment });
|
|
933
|
+
};
|
|
934
|
+
const thumbsScore = (value) => {
|
|
935
|
+
return value === "thumbsUp" ? 5 : value === "thumbsDown" ? 0 : 0;
|
|
936
|
+
};
|
|
937
|
+
const handleRate = async (key, value, onHandleRateSuccess) => {
|
|
938
|
+
setIsLoading(true);
|
|
939
|
+
const sessionId = getTopicSessionId(topicId);
|
|
940
|
+
const ratingObj = {
|
|
941
|
+
topicId: parseInt(topicId),
|
|
942
|
+
sessionId: sessionId || "",
|
|
943
|
+
assistantId,
|
|
944
|
+
score: key === "score" ? value : thumbsScore(value),
|
|
945
|
+
description: key === "description" ? value : state.ratingComment
|
|
1946
946
|
};
|
|
947
|
+
try {
|
|
948
|
+
const response = await sendRating(ratingObj);
|
|
949
|
+
if (!response.success) {
|
|
950
|
+
setIsLoading(false);
|
|
951
|
+
onHandleRateSuccess(false, response.error.message);
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
if (key === "score") {
|
|
955
|
+
setRatingStars(value);
|
|
956
|
+
} else if (key === "description") {
|
|
957
|
+
setRatingComment(value);
|
|
958
|
+
}
|
|
959
|
+
setHasReviewed(true);
|
|
960
|
+
setIsLoading(false);
|
|
961
|
+
onHandleRateSuccess(true);
|
|
962
|
+
} catch (err) {
|
|
963
|
+
setIsLoading(false);
|
|
964
|
+
onHandleRateSuccess(false, String(err));
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
return {
|
|
968
|
+
handleRate,
|
|
969
|
+
ratingStars: state.ratingStars,
|
|
970
|
+
ratingThumbs: state.ratingThumbs,
|
|
971
|
+
ratingComment: state.ratingComment,
|
|
972
|
+
isLoading,
|
|
973
|
+
hasReviewed
|
|
974
|
+
};
|
|
1947
975
|
}
|
|
976
|
+
|
|
1948
977
|
// src/actions/alquimia.action.ts
|
|
1949
978
|
import { randomUUID } from "crypto";
|
|
1950
979
|
import { cookies } from "next/headers";
|
|
1951
|
-
function initConversation(reset, topicId) {
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
conversationsMap = {};
|
|
1980
|
-
existingConversations = cookieStore.get("alquimia-sessions");
|
|
1981
|
-
if (existingConversations) {
|
|
1982
|
-
try {
|
|
1983
|
-
decodedValue = decodeURIComponent(existingConversations.value);
|
|
1984
|
-
conversationsMap = JSON.parse(decodedValue);
|
|
1985
|
-
} catch (e) {
|
|
1986
|
-
console.error("Error parsing conversations cookie:", e);
|
|
1987
|
-
conversationsMap = {};
|
|
1988
|
-
}
|
|
1989
|
-
}
|
|
1990
|
-
if (!conversationsMap[topicId] || reset) {
|
|
1991
|
-
conversationsMap[topicId] = randomUUID().toString();
|
|
1992
|
-
}
|
|
1993
|
-
cookieStore.set("alquimia-sessions", JSON.stringify(conversationsMap));
|
|
1994
|
-
return [
|
|
1995
|
-
2,
|
|
1996
|
-
conversationsMap[topicId]
|
|
1997
|
-
];
|
|
1998
|
-
}
|
|
1999
|
-
});
|
|
2000
|
-
});
|
|
2001
|
-
return _initConversation.apply(this, arguments);
|
|
2002
|
-
}
|
|
2003
|
-
function createResource(config, payload) {
|
|
2004
|
-
return _createResource.apply(this, arguments);
|
|
980
|
+
async function initConversation(reset, topicId) {
|
|
981
|
+
const cookieStore = await cookies();
|
|
982
|
+
if (!topicId) {
|
|
983
|
+
let conversationId = randomUUID().toString();
|
|
984
|
+
const alquimia_session = cookieStore.get("alquimia-session");
|
|
985
|
+
if (!alquimia_session || reset) {
|
|
986
|
+
cookieStore.set("alquimia-session", conversationId);
|
|
987
|
+
} else {
|
|
988
|
+
conversationId = alquimia_session.value;
|
|
989
|
+
}
|
|
990
|
+
return conversationId;
|
|
991
|
+
}
|
|
992
|
+
let conversationsMap = {};
|
|
993
|
+
const existingConversations = cookieStore.get("alquimia-sessions");
|
|
994
|
+
if (existingConversations) {
|
|
995
|
+
try {
|
|
996
|
+
const decodedValue = decodeURIComponent(existingConversations.value);
|
|
997
|
+
conversationsMap = JSON.parse(decodedValue);
|
|
998
|
+
} catch (e) {
|
|
999
|
+
console.error("Error parsing conversations cookie:", e);
|
|
1000
|
+
conversationsMap = {};
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
if (!conversationsMap[topicId] || reset) {
|
|
1004
|
+
conversationsMap[topicId] = randomUUID().toString();
|
|
1005
|
+
}
|
|
1006
|
+
cookieStore.set("alquimia-sessions", JSON.stringify(conversationsMap));
|
|
1007
|
+
return conversationsMap[topicId];
|
|
2005
1008
|
}
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
,
|
|
2017
|
-
6
|
|
2018
|
-
]);
|
|
2019
|
-
headers = generateHeaders(config);
|
|
2020
|
-
return [
|
|
2021
|
-
4,
|
|
2022
|
-
fetch("".concat(config.baseUrl).concat(config.route), {
|
|
2023
|
-
method: "POST",
|
|
2024
|
-
headers: headers,
|
|
2025
|
-
body: JSON.stringify(payload),
|
|
2026
|
-
cache: "default"
|
|
2027
|
-
})
|
|
2028
|
-
];
|
|
2029
|
-
case 1:
|
|
2030
|
-
response = _state.sent();
|
|
2031
|
-
if (!!response.ok) return [
|
|
2032
|
-
3,
|
|
2033
|
-
3
|
|
2034
|
-
];
|
|
2035
|
-
return [
|
|
2036
|
-
4,
|
|
2037
|
-
response.json()
|
|
2038
|
-
];
|
|
2039
|
-
case 2:
|
|
2040
|
-
error = _state.sent();
|
|
2041
|
-
return [
|
|
2042
|
-
2,
|
|
2043
|
-
{
|
|
2044
|
-
success: false,
|
|
2045
|
-
error: {
|
|
2046
|
-
message: error.message || "Server returned ".concat(response.status),
|
|
2047
|
-
code: response.status.toString(),
|
|
2048
|
-
details: {
|
|
2049
|
-
status: response.status,
|
|
2050
|
-
statusText: response.statusText
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
|
-
}
|
|
2054
|
-
];
|
|
2055
|
-
case 3:
|
|
2056
|
-
_tmp = {
|
|
2057
|
-
success: true
|
|
2058
|
-
};
|
|
2059
|
-
return [
|
|
2060
|
-
4,
|
|
2061
|
-
response.json()
|
|
2062
|
-
];
|
|
2063
|
-
case 4:
|
|
2064
|
-
return [
|
|
2065
|
-
2,
|
|
2066
|
-
(_tmp.data = _state.sent(), _tmp)
|
|
2067
|
-
];
|
|
2068
|
-
case 5:
|
|
2069
|
-
error1 = _state.sent();
|
|
2070
|
-
throw new Error("Failed to create resource");
|
|
2071
|
-
case 6:
|
|
2072
|
-
return [
|
|
2073
|
-
2
|
|
2074
|
-
];
|
|
2075
|
-
}
|
|
2076
|
-
});
|
|
1009
|
+
|
|
1010
|
+
// src/actions/baseApi.action.ts
|
|
1011
|
+
async function createResource(config, payload) {
|
|
1012
|
+
try {
|
|
1013
|
+
const headers = generateHeaders(config);
|
|
1014
|
+
const response = await fetch(`${config.baseUrl}${config.route}`, {
|
|
1015
|
+
method: "POST",
|
|
1016
|
+
headers,
|
|
1017
|
+
body: JSON.stringify(payload),
|
|
1018
|
+
cache: "default"
|
|
2077
1019
|
});
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
1020
|
+
if (!response.ok) {
|
|
1021
|
+
const error = await response.json();
|
|
1022
|
+
return {
|
|
1023
|
+
success: false,
|
|
1024
|
+
error: {
|
|
1025
|
+
message: error.message || `Server returned ${response.status}`,
|
|
1026
|
+
code: response.status.toString(),
|
|
1027
|
+
details: {
|
|
1028
|
+
status: response.status,
|
|
1029
|
+
statusText: response.statusText
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
return {
|
|
1035
|
+
success: true,
|
|
1036
|
+
data: await response.json()
|
|
1037
|
+
};
|
|
1038
|
+
} catch (error) {
|
|
1039
|
+
throw new Error("Failed to create resource");
|
|
1040
|
+
}
|
|
2082
1041
|
}
|
|
2083
|
-
function
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
8,
|
|
2092
|
-
,
|
|
2093
|
-
9
|
|
2094
|
-
]);
|
|
2095
|
-
headers = generateHeaders(config);
|
|
2096
|
-
url = id ? "".concat(config.baseUrl).concat(config.route, "/").concat(id) : "".concat(config.baseUrl).concat(config.route);
|
|
2097
|
-
return [
|
|
2098
|
-
4,
|
|
2099
|
-
fetch(url, {
|
|
2100
|
-
method: "GET",
|
|
2101
|
-
headers: headers,
|
|
2102
|
-
cache: "default"
|
|
2103
|
-
})
|
|
2104
|
-
];
|
|
2105
|
-
case 1:
|
|
2106
|
-
response = _state.sent();
|
|
2107
|
-
if (!!response.ok) return [
|
|
2108
|
-
3,
|
|
2109
|
-
3
|
|
2110
|
-
];
|
|
2111
|
-
return [
|
|
2112
|
-
4,
|
|
2113
|
-
response.json()
|
|
2114
|
-
];
|
|
2115
|
-
case 2:
|
|
2116
|
-
error = _state.sent();
|
|
2117
|
-
return [
|
|
2118
|
-
2,
|
|
2119
|
-
{
|
|
2120
|
-
success: false,
|
|
2121
|
-
error: {
|
|
2122
|
-
message: error.message || "Server returned ".concat(response.status),
|
|
2123
|
-
code: response.status.toString(),
|
|
2124
|
-
details: {
|
|
2125
|
-
status: response.status,
|
|
2126
|
-
statusText: response.statusText
|
|
2127
|
-
}
|
|
2128
|
-
}
|
|
2129
|
-
}
|
|
2130
|
-
];
|
|
2131
|
-
case 3:
|
|
2132
|
-
contentType = response.headers.get("content-type");
|
|
2133
|
-
if (!(contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json"))) return [
|
|
2134
|
-
3,
|
|
2135
|
-
5
|
|
2136
|
-
];
|
|
2137
|
-
_tmp = {
|
|
2138
|
-
success: true
|
|
2139
|
-
};
|
|
2140
|
-
return [
|
|
2141
|
-
4,
|
|
2142
|
-
response.json()
|
|
2143
|
-
];
|
|
2144
|
-
case 4:
|
|
2145
|
-
return [
|
|
2146
|
-
2,
|
|
2147
|
-
(_tmp.data = _state.sent(), _tmp.contentType = contentType || void 0, _tmp)
|
|
2148
|
-
];
|
|
2149
|
-
case 5:
|
|
2150
|
-
return [
|
|
2151
|
-
4,
|
|
2152
|
-
response.arrayBuffer()
|
|
2153
|
-
];
|
|
2154
|
-
case 6:
|
|
2155
|
-
arrayBuffer = _state.sent();
|
|
2156
|
-
if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("octet-stream")) && isTextContent(arrayBuffer)) {
|
|
2157
|
-
return [
|
|
2158
|
-
2,
|
|
2159
|
-
{
|
|
2160
|
-
success: true,
|
|
2161
|
-
data: arrayBuffer,
|
|
2162
|
-
contentType: "text/plain"
|
|
2163
|
-
}
|
|
2164
|
-
];
|
|
2165
|
-
}
|
|
2166
|
-
_tmp1 = {
|
|
2167
|
-
success: true
|
|
2168
|
-
};
|
|
2169
|
-
return [
|
|
2170
|
-
4,
|
|
2171
|
-
response.json()
|
|
2172
|
-
];
|
|
2173
|
-
case 7:
|
|
2174
|
-
return [
|
|
2175
|
-
2,
|
|
2176
|
-
(_tmp1.data = _state.sent(), _tmp1.contentType = contentType || void 0, _tmp1)
|
|
2177
|
-
];
|
|
2178
|
-
case 8:
|
|
2179
|
-
error1 = _state.sent();
|
|
2180
|
-
throw new Error("Failed to read resource");
|
|
2181
|
-
case 9:
|
|
2182
|
-
return [
|
|
2183
|
-
2
|
|
2184
|
-
];
|
|
2185
|
-
}
|
|
2186
|
-
});
|
|
1042
|
+
async function readResource(config, id) {
|
|
1043
|
+
try {
|
|
1044
|
+
const headers = generateHeaders(config);
|
|
1045
|
+
const url = id ? `${config.baseUrl}${config.route}/${id}` : `${config.baseUrl}${config.route}`;
|
|
1046
|
+
const response = await fetch(url, {
|
|
1047
|
+
method: "GET",
|
|
1048
|
+
headers,
|
|
1049
|
+
cache: "default"
|
|
2187
1050
|
});
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
1051
|
+
if (!response.ok) {
|
|
1052
|
+
const error = await response.json();
|
|
1053
|
+
return {
|
|
1054
|
+
success: false,
|
|
1055
|
+
error: {
|
|
1056
|
+
message: error.message || `Server returned ${response.status}`,
|
|
1057
|
+
code: response.status.toString(),
|
|
1058
|
+
details: {
|
|
1059
|
+
status: response.status,
|
|
1060
|
+
statusText: response.statusText
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
const contentType = response.headers.get("content-type");
|
|
1066
|
+
if (contentType?.includes("application/json")) {
|
|
1067
|
+
return {
|
|
1068
|
+
success: true,
|
|
1069
|
+
data: await response.json(),
|
|
1070
|
+
contentType: contentType || void 0
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
1074
|
+
if (contentType?.includes("octet-stream") && isTextContent(arrayBuffer)) {
|
|
1075
|
+
return {
|
|
1076
|
+
success: true,
|
|
1077
|
+
data: arrayBuffer,
|
|
1078
|
+
contentType: "text/plain"
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
return {
|
|
1082
|
+
success: true,
|
|
1083
|
+
data: await response.json(),
|
|
1084
|
+
contentType: contentType || void 0
|
|
1085
|
+
};
|
|
1086
|
+
} catch (error) {
|
|
1087
|
+
throw new Error("Failed to read resource");
|
|
1088
|
+
}
|
|
2192
1089
|
}
|
|
2193
|
-
function
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
5,
|
|
2202
|
-
,
|
|
2203
|
-
6
|
|
2204
|
-
]);
|
|
2205
|
-
headers = generateHeaders(config);
|
|
2206
|
-
return [
|
|
2207
|
-
4,
|
|
2208
|
-
fetch("".concat(config.baseUrl).concat(config.route, "/").concat(id), {
|
|
2209
|
-
method: "PUT",
|
|
2210
|
-
headers: headers,
|
|
2211
|
-
body: JSON.stringify(data),
|
|
2212
|
-
cache: "default"
|
|
2213
|
-
})
|
|
2214
|
-
];
|
|
2215
|
-
case 1:
|
|
2216
|
-
response = _state.sent();
|
|
2217
|
-
if (!!response.ok) return [
|
|
2218
|
-
3,
|
|
2219
|
-
3
|
|
2220
|
-
];
|
|
2221
|
-
return [
|
|
2222
|
-
4,
|
|
2223
|
-
response.json()
|
|
2224
|
-
];
|
|
2225
|
-
case 2:
|
|
2226
|
-
error = _state.sent();
|
|
2227
|
-
return [
|
|
2228
|
-
2,
|
|
2229
|
-
{
|
|
2230
|
-
success: false,
|
|
2231
|
-
error: {
|
|
2232
|
-
message: error.message || "Server returned ".concat(response.status),
|
|
2233
|
-
code: response.status.toString(),
|
|
2234
|
-
details: {
|
|
2235
|
-
status: response.status,
|
|
2236
|
-
statusText: response.statusText
|
|
2237
|
-
}
|
|
2238
|
-
}
|
|
2239
|
-
}
|
|
2240
|
-
];
|
|
2241
|
-
case 3:
|
|
2242
|
-
_tmp = {
|
|
2243
|
-
success: true
|
|
2244
|
-
};
|
|
2245
|
-
return [
|
|
2246
|
-
4,
|
|
2247
|
-
response.json()
|
|
2248
|
-
];
|
|
2249
|
-
case 4:
|
|
2250
|
-
return [
|
|
2251
|
-
2,
|
|
2252
|
-
(_tmp.data = _state.sent(), _tmp)
|
|
2253
|
-
];
|
|
2254
|
-
case 5:
|
|
2255
|
-
error1 = _state.sent();
|
|
2256
|
-
throw new Error("Failed to update resource");
|
|
2257
|
-
case 6:
|
|
2258
|
-
return [
|
|
2259
|
-
2
|
|
2260
|
-
];
|
|
2261
|
-
}
|
|
2262
|
-
});
|
|
1090
|
+
async function updateResource(config, id, data) {
|
|
1091
|
+
try {
|
|
1092
|
+
const headers = generateHeaders(config);
|
|
1093
|
+
const response = await fetch(`${config.baseUrl}${config.route}/${id}`, {
|
|
1094
|
+
method: "PUT",
|
|
1095
|
+
headers,
|
|
1096
|
+
body: JSON.stringify(data),
|
|
1097
|
+
cache: "default"
|
|
2263
1098
|
});
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
1099
|
+
if (!response.ok) {
|
|
1100
|
+
const error = await response.json();
|
|
1101
|
+
return {
|
|
1102
|
+
success: false,
|
|
1103
|
+
error: {
|
|
1104
|
+
message: error.message || `Server returned ${response.status}`,
|
|
1105
|
+
code: response.status.toString(),
|
|
1106
|
+
details: {
|
|
1107
|
+
status: response.status,
|
|
1108
|
+
statusText: response.statusText
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
1113
|
+
return {
|
|
1114
|
+
success: true,
|
|
1115
|
+
data: await response.json()
|
|
1116
|
+
};
|
|
1117
|
+
} catch (error) {
|
|
1118
|
+
throw new Error("Failed to update resource");
|
|
1119
|
+
}
|
|
2268
1120
|
}
|
|
2269
|
-
function
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
0,
|
|
2277
|
-
4,
|
|
2278
|
-
,
|
|
2279
|
-
5
|
|
2280
|
-
]);
|
|
2281
|
-
headers = generateHeaders(config);
|
|
2282
|
-
return [
|
|
2283
|
-
4,
|
|
2284
|
-
fetch("".concat(config.baseUrl).concat(config.route, "/").concat(id), {
|
|
2285
|
-
method: "DELETE",
|
|
2286
|
-
headers: headers,
|
|
2287
|
-
cache: "default"
|
|
2288
|
-
})
|
|
2289
|
-
];
|
|
2290
|
-
case 1:
|
|
2291
|
-
response = _state.sent();
|
|
2292
|
-
if (!!response.ok) return [
|
|
2293
|
-
3,
|
|
2294
|
-
3
|
|
2295
|
-
];
|
|
2296
|
-
return [
|
|
2297
|
-
4,
|
|
2298
|
-
response.json()
|
|
2299
|
-
];
|
|
2300
|
-
case 2:
|
|
2301
|
-
error = _state.sent();
|
|
2302
|
-
return [
|
|
2303
|
-
2,
|
|
2304
|
-
{
|
|
2305
|
-
success: false,
|
|
2306
|
-
error: {
|
|
2307
|
-
message: error.message || "Server returned ".concat(response.status),
|
|
2308
|
-
code: response.status.toString(),
|
|
2309
|
-
details: {
|
|
2310
|
-
status: response.status,
|
|
2311
|
-
statusText: response.statusText
|
|
2312
|
-
}
|
|
2313
|
-
}
|
|
2314
|
-
}
|
|
2315
|
-
];
|
|
2316
|
-
case 3:
|
|
2317
|
-
return [
|
|
2318
|
-
2,
|
|
2319
|
-
{
|
|
2320
|
-
success: true
|
|
2321
|
-
}
|
|
2322
|
-
];
|
|
2323
|
-
case 4:
|
|
2324
|
-
error1 = _state.sent();
|
|
2325
|
-
throw new Error("Failed to delete resource");
|
|
2326
|
-
case 5:
|
|
2327
|
-
return [
|
|
2328
|
-
2
|
|
2329
|
-
];
|
|
2330
|
-
}
|
|
2331
|
-
});
|
|
1121
|
+
async function deleteResource(config, id) {
|
|
1122
|
+
try {
|
|
1123
|
+
const headers = generateHeaders(config);
|
|
1124
|
+
const response = await fetch(`${config.baseUrl}${config.route}/${id}`, {
|
|
1125
|
+
method: "DELETE",
|
|
1126
|
+
headers,
|
|
1127
|
+
cache: "default"
|
|
2332
1128
|
});
|
|
2333
|
-
|
|
1129
|
+
if (!response.ok) {
|
|
1130
|
+
const error = await response.json();
|
|
1131
|
+
return {
|
|
1132
|
+
success: false,
|
|
1133
|
+
error: {
|
|
1134
|
+
message: error.message || `Server returned ${response.status}`,
|
|
1135
|
+
code: response.status.toString(),
|
|
1136
|
+
details: {
|
|
1137
|
+
status: response.status,
|
|
1138
|
+
statusText: response.statusText
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
return {
|
|
1144
|
+
success: true
|
|
1145
|
+
};
|
|
1146
|
+
} catch (error) {
|
|
1147
|
+
throw new Error("Failed to delete resource");
|
|
1148
|
+
}
|
|
2334
1149
|
}
|
|
2335
|
-
|
|
1150
|
+
|
|
1151
|
+
// src/types/type.ts
|
|
1152
|
+
var ToolFactory = class {
|
|
1153
|
+
constructor(toolSpec) {
|
|
1154
|
+
this.toolSpec = null;
|
|
1155
|
+
this.toolSpec = toolSpec;
|
|
1156
|
+
}
|
|
1157
|
+
static createTool(toolSpec) {
|
|
1158
|
+
return toolSpec;
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
1161
|
+
export {
|
|
1162
|
+
AlquimiaRatingsProvider,
|
|
1163
|
+
alquimia_sdk_default as AlquimiaSDK,
|
|
1164
|
+
AlquimiaWhisperProvider,
|
|
1165
|
+
Button,
|
|
1166
|
+
Card,
|
|
1167
|
+
CharacterizationProvider,
|
|
1168
|
+
Code,
|
|
1169
|
+
ElasticLoggerProvider,
|
|
1170
|
+
ElevenLabsWhisperProvider,
|
|
1171
|
+
GenerativeProvider,
|
|
1172
|
+
LoggerProvider,
|
|
1173
|
+
OpenAIAnalyzeCharProvider,
|
|
1174
|
+
OpenAIStableDiffusionProvider,
|
|
1175
|
+
OpenAIWhisperProvider,
|
|
1176
|
+
RatingsProvider,
|
|
1177
|
+
SessionProvider,
|
|
1178
|
+
StabilityProvider,
|
|
1179
|
+
StableDiffusionProvider,
|
|
1180
|
+
ToolFactory,
|
|
1181
|
+
WhisperProvider,
|
|
1182
|
+
createMessageId,
|
|
1183
|
+
createResource,
|
|
1184
|
+
defineAssistantId,
|
|
1185
|
+
deleteResource,
|
|
1186
|
+
formatTimeWithUnit,
|
|
1187
|
+
generateHeaders,
|
|
1188
|
+
generateTranslatePrompt,
|
|
1189
|
+
getCookies,
|
|
1190
|
+
getQueryParam,
|
|
1191
|
+
getTopicSessionId,
|
|
1192
|
+
initConversation,
|
|
1193
|
+
isTextContent,
|
|
1194
|
+
parseConversationsMapCookie,
|
|
1195
|
+
readResource,
|
|
1196
|
+
serializeAxiosError,
|
|
1197
|
+
updateResource,
|
|
1198
|
+
useAlquimia,
|
|
1199
|
+
useRatings,
|
|
1200
|
+
useSessionContext
|
|
1201
|
+
};
|
|
2336
1202
|
//# sourceMappingURL=index.mjs.map
|