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