@alquimia-ai/tools 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/dist/index.d.mts +322 -0
- package/dist/index.d.ts +322 -0
- package/dist/index.js +2582 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2336 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +71 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2582 @@
|
|
|
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
|
+
var __create = Object.create;
|
|
358
|
+
var __defProp = Object.defineProperty;
|
|
359
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
360
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
361
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
362
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
363
|
+
var __export = function(target, all) {
|
|
364
|
+
for(var name in all)__defProp(target, name, {
|
|
365
|
+
get: all[name],
|
|
366
|
+
enumerable: true
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
var __copyProps = function(to, from, except, desc) {
|
|
370
|
+
if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
|
|
371
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
372
|
+
try {
|
|
373
|
+
var _loop = function() {
|
|
374
|
+
var key = _step.value;
|
|
375
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
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);
|
|
414
|
+
};
|
|
415
|
+
// src/index.ts
|
|
416
|
+
var index_exports = {};
|
|
417
|
+
__export(index_exports, {
|
|
418
|
+
AlquimiaRatingsProvider: function() {
|
|
419
|
+
return AlquimiaRatingsProvider;
|
|
420
|
+
},
|
|
421
|
+
AlquimiaSDK: function() {
|
|
422
|
+
return alquimia_sdk_default;
|
|
423
|
+
},
|
|
424
|
+
AlquimiaWhisperProvider: function() {
|
|
425
|
+
return AlquimiaWhisperProvider;
|
|
426
|
+
},
|
|
427
|
+
Button: function() {
|
|
428
|
+
return Button;
|
|
429
|
+
},
|
|
430
|
+
Card: function() {
|
|
431
|
+
return Card;
|
|
432
|
+
},
|
|
433
|
+
CharacterizationProvider: function() {
|
|
434
|
+
return CharacterizationProvider;
|
|
435
|
+
},
|
|
436
|
+
Code: function() {
|
|
437
|
+
return Code;
|
|
438
|
+
},
|
|
439
|
+
ElasticLoggerProvider: function() {
|
|
440
|
+
return ElasticLoggerProvider;
|
|
441
|
+
},
|
|
442
|
+
ElevenLabsWhisperProvider: function() {
|
|
443
|
+
return ElevenLabsWhisperProvider;
|
|
444
|
+
},
|
|
445
|
+
GenerativeProvider: function() {
|
|
446
|
+
return GenerativeProvider;
|
|
447
|
+
},
|
|
448
|
+
LoggerProvider: function() {
|
|
449
|
+
return LoggerProvider;
|
|
450
|
+
},
|
|
451
|
+
OpenAIAnalyzeCharProvider: function() {
|
|
452
|
+
return OpenAIAnalyzeCharProvider;
|
|
453
|
+
},
|
|
454
|
+
OpenAIStableDiffusionProvider: function() {
|
|
455
|
+
return OpenAIStableDiffusionProvider;
|
|
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
|
+
}
|
|
532
|
+
});
|
|
533
|
+
module.exports = __toCommonJS(index_exports);
|
|
534
|
+
// src/button.tsx
|
|
535
|
+
var Button = function(param) {
|
|
536
|
+
var children = param.children, className = param.className, appName = param.appName;
|
|
537
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
538
|
+
className: className,
|
|
539
|
+
onClick: function() {
|
|
540
|
+
return alert("Hello from your ".concat(appName, " app!"));
|
|
541
|
+
}
|
|
542
|
+
}, children);
|
|
543
|
+
};
|
|
544
|
+
// src/card.tsx
|
|
545
|
+
function Card(param) {
|
|
546
|
+
var className = param.className, title = param.title, children = param.children, href = param.href;
|
|
547
|
+
return /* @__PURE__ */ React.createElement("a", {
|
|
548
|
+
className: className,
|
|
549
|
+
href: "".concat(href, '?utm_source=create-turbo&utm_medium=basic&utm_campaign=create-turbo"'),
|
|
550
|
+
rel: "noopener noreferrer",
|
|
551
|
+
target: "_blank"
|
|
552
|
+
}, /* @__PURE__ */ React.createElement("h2", null, title, " ", /* @__PURE__ */ React.createElement("span", null, "->")), /* @__PURE__ */ React.createElement("p", null, children));
|
|
553
|
+
}
|
|
554
|
+
// src/code.tsx
|
|
555
|
+
function Code(param) {
|
|
556
|
+
var children = param.children, className = param.className;
|
|
557
|
+
return /* @__PURE__ */ React.createElement("code", {
|
|
558
|
+
className: className
|
|
559
|
+
}, children);
|
|
560
|
+
}
|
|
561
|
+
// src/sdk/alquimia-sdk.ts
|
|
562
|
+
var import_axios = __toESM(require("axios"));
|
|
563
|
+
var AlquimiaSDK = /*#__PURE__*/ function() {
|
|
564
|
+
function AlquimiaSDK(config) {
|
|
565
|
+
var enforceCharacterization = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
|
|
566
|
+
_class_call_check(this, AlquimiaSDK);
|
|
567
|
+
var _this = this;
|
|
568
|
+
this.conversationId = null;
|
|
569
|
+
this.sessionId = null;
|
|
570
|
+
this.streamId = null;
|
|
571
|
+
this.tools = [];
|
|
572
|
+
this.extraData = {};
|
|
573
|
+
this.forceProfile = {};
|
|
574
|
+
this.config = config;
|
|
575
|
+
this.enforceCharacterization = enforceCharacterization;
|
|
576
|
+
this.axiosInstance = import_axios.default.create();
|
|
577
|
+
this.axiosInstance.interceptors.response.use(function(response) {
|
|
578
|
+
return response;
|
|
579
|
+
}, /*#__PURE__*/ function() {
|
|
580
|
+
var _ref = _async_to_generator(function(error) {
|
|
581
|
+
var _error_response;
|
|
582
|
+
return _ts_generator(this, function(_state) {
|
|
583
|
+
switch(_state.label){
|
|
584
|
+
case 0:
|
|
585
|
+
if (!((_error_response = error.response) === null || _error_response === void 0 ? void 0 : _error_response.status)) return [
|
|
586
|
+
3,
|
|
587
|
+
2
|
|
588
|
+
];
|
|
589
|
+
if (!_this.loggerProvider) return [
|
|
590
|
+
3,
|
|
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
|
+
}
|
|
852
|
+
}
|
|
853
|
+
]);
|
|
854
|
+
return AlquimiaSDK;
|
|
855
|
+
}();
|
|
856
|
+
var alquimia_sdk_default = AlquimiaSDK;
|
|
857
|
+
// src/sdk/providers/providers.ts
|
|
858
|
+
var GenerativeProvider = function GenerativeProvider(config) {
|
|
859
|
+
_class_call_check(this, GenerativeProvider);
|
|
860
|
+
this.config = config;
|
|
861
|
+
};
|
|
862
|
+
var WhisperProvider = function WhisperProvider(config) {
|
|
863
|
+
_class_call_check(this, WhisperProvider);
|
|
864
|
+
this.config = config;
|
|
865
|
+
};
|
|
866
|
+
var StableDiffusionProvider = function StableDiffusionProvider(config) {
|
|
867
|
+
_class_call_check(this, StableDiffusionProvider);
|
|
868
|
+
this.config = config;
|
|
869
|
+
};
|
|
870
|
+
var CharacterizationProvider = function CharacterizationProvider(config) {
|
|
871
|
+
_class_call_check(this, CharacterizationProvider);
|
|
872
|
+
this.config = config;
|
|
873
|
+
};
|
|
874
|
+
var RatingsProvider = function RatingsProvider(config) {
|
|
875
|
+
_class_call_check(this, RatingsProvider);
|
|
876
|
+
this.config = config;
|
|
877
|
+
};
|
|
878
|
+
var LoggerProvider = function LoggerProvider(config) {
|
|
879
|
+
_class_call_check(this, LoggerProvider);
|
|
880
|
+
this.config = config;
|
|
881
|
+
};
|
|
882
|
+
// src/sdk/providers/alquimia.ts
|
|
883
|
+
var import_axios2 = __toESM(require("axios"));
|
|
884
|
+
var AlquimiaWhisperProvider = /*#__PURE__*/ function(WhisperProvider) {
|
|
885
|
+
_inherits(AlquimiaWhisperProvider, WhisperProvider);
|
|
886
|
+
function AlquimiaWhisperProvider(config) {
|
|
887
|
+
_class_call_check(this, AlquimiaWhisperProvider);
|
|
888
|
+
return _call_super(this, AlquimiaWhisperProvider, [
|
|
889
|
+
config
|
|
890
|
+
]);
|
|
891
|
+
}
|
|
892
|
+
_create_class(AlquimiaWhisperProvider, [
|
|
893
|
+
{
|
|
894
|
+
key: "textToSpeech",
|
|
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
|
+
}
|
|
939
|
+
},
|
|
940
|
+
{
|
|
941
|
+
key: "speechToText",
|
|
942
|
+
value: function speechToText(audio) {
|
|
943
|
+
var _this = this;
|
|
944
|
+
return _async_to_generator(function() {
|
|
945
|
+
var axiosClient, response, error;
|
|
946
|
+
return _ts_generator(this, function(_state) {
|
|
947
|
+
switch(_state.label){
|
|
948
|
+
case 0:
|
|
949
|
+
axiosClient = import_axios2.default.create({
|
|
950
|
+
baseURL: _this.config.baseURL
|
|
951
|
+
});
|
|
952
|
+
_state.label = 1;
|
|
953
|
+
case 1:
|
|
954
|
+
_state.trys.push([
|
|
955
|
+
1,
|
|
956
|
+
3,
|
|
957
|
+
,
|
|
958
|
+
4
|
|
959
|
+
]);
|
|
960
|
+
return [
|
|
961
|
+
4,
|
|
962
|
+
axiosClient.post(_this.config.sttRoute, {
|
|
963
|
+
audio: audio
|
|
964
|
+
})
|
|
965
|
+
];
|
|
966
|
+
case 2:
|
|
967
|
+
response = _state.sent();
|
|
968
|
+
return [
|
|
969
|
+
2,
|
|
970
|
+
response.data
|
|
971
|
+
];
|
|
972
|
+
case 3:
|
|
973
|
+
error = _state.sent();
|
|
974
|
+
console.error("Error converting speech to text:", error);
|
|
975
|
+
throw error;
|
|
976
|
+
case 4:
|
|
977
|
+
return [
|
|
978
|
+
2
|
|
979
|
+
];
|
|
980
|
+
}
|
|
981
|
+
});
|
|
982
|
+
})();
|
|
983
|
+
}
|
|
984
|
+
}
|
|
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
|
+
]);
|
|
995
|
+
}
|
|
996
|
+
_create_class(AlquimiaRatingsProvider, [
|
|
997
|
+
{
|
|
998
|
+
key: "rate",
|
|
999
|
+
value: function rate(data) {
|
|
1000
|
+
var _this = this;
|
|
1001
|
+
return _async_to_generator(function() {
|
|
1002
|
+
var path, response, headers, error, _error_response, _error_response1, _error_response2;
|
|
1003
|
+
return _ts_generator(this, function(_state) {
|
|
1004
|
+
switch(_state.label){
|
|
1005
|
+
case 0:
|
|
1006
|
+
path = "".concat(_this.config.baseUrl).concat(_this.config.route);
|
|
1007
|
+
_state.label = 1;
|
|
1008
|
+
case 1:
|
|
1009
|
+
_state.trys.push([
|
|
1010
|
+
1,
|
|
1011
|
+
3,
|
|
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
|
+
})();
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
]);
|
|
1075
|
+
return AlquimiaRatingsProvider;
|
|
1076
|
+
}(RatingsProvider);
|
|
1077
|
+
// src/utils/utils.ts
|
|
1078
|
+
function generateTranslatePrompt(text) {
|
|
1079
|
+
var prompt = "\n Arrange the following text according to the given object structure and return it as plain json, values summarized to one word, no formatting:\n {\n restrictions: {\n value: [''],\n description: 'Restrictions to certain foods'\n },\n alergies: {\n value: [''],\n description: 'Alergies to certain foods'\n },\n wine_preference: {\n value: [''],\n description: 'Preferences for the wine'\n },\n meal_preference: {\n value: [''],\n description: 'Preferences for the meal'\n }\n }\n\n Text: \"".concat(text, '"\n\n Output:\n ');
|
|
1080
|
+
return prompt;
|
|
1081
|
+
}
|
|
1082
|
+
function getCookies(name) {
|
|
1083
|
+
var _parts_pop;
|
|
1084
|
+
if (typeof document === "undefined") return void 0;
|
|
1085
|
+
var value = "; ".concat(document.cookie);
|
|
1086
|
+
var parts = value.split("; ".concat(name, "="));
|
|
1087
|
+
if (parts.length === 2) return (_parts_pop = parts.pop()) === null || _parts_pop === void 0 ? void 0 : _parts_pop.split(";").shift();
|
|
1088
|
+
}
|
|
1089
|
+
function generateHeaders(config) {
|
|
1090
|
+
var headers = {
|
|
1091
|
+
"Content-Type": "application/json"
|
|
1092
|
+
};
|
|
1093
|
+
if (config.token) {
|
|
1094
|
+
headers["Authorization"] = "Bearer ".concat(config.token);
|
|
1095
|
+
}
|
|
1096
|
+
if (config.headers) {
|
|
1097
|
+
Object.entries(config.headers).forEach(function(param) {
|
|
1098
|
+
var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
|
1099
|
+
headers[key] = value;
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
return headers;
|
|
1103
|
+
}
|
|
1104
|
+
function isTextContent(buffer) {
|
|
1105
|
+
try {
|
|
1106
|
+
var text = new TextDecoder().decode(buffer);
|
|
1107
|
+
return /^[\w\#\-\*]/.test(text.trim());
|
|
1108
|
+
} catch (e) {
|
|
1109
|
+
return false;
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
function getQueryParam(param) {
|
|
1113
|
+
if (typeof window !== "undefined") {
|
|
1114
|
+
var urlParams = new URLSearchParams(window.location.search);
|
|
1115
|
+
return urlParams.get(param);
|
|
1116
|
+
}
|
|
1117
|
+
return null;
|
|
1118
|
+
}
|
|
1119
|
+
function defineAssistantId(defaultId) {
|
|
1120
|
+
if (typeof window !== "undefined" && window.location.pathname === "/") {
|
|
1121
|
+
var queryAssistantId = getQueryParam("talkwith");
|
|
1122
|
+
if (queryAssistantId) {
|
|
1123
|
+
localStorage.setItem("assistantId", queryAssistantId);
|
|
1124
|
+
return queryAssistantId;
|
|
1125
|
+
}
|
|
1126
|
+
var storedAssistantId = localStorage.getItem("assistantId");
|
|
1127
|
+
return storedAssistantId || defaultId;
|
|
1128
|
+
}
|
|
1129
|
+
return defaultId;
|
|
1130
|
+
}
|
|
1131
|
+
function formatTimeWithUnit(timeMs) {
|
|
1132
|
+
if (timeMs >= 1e3) {
|
|
1133
|
+
return "".concat((timeMs / 1e3).toFixed(1), "s");
|
|
1134
|
+
}
|
|
1135
|
+
return "".concat(Math.round(timeMs), "ms");
|
|
1136
|
+
}
|
|
1137
|
+
function serializeAxiosError(error) {
|
|
1138
|
+
if (_instanceof(error, Error)) {
|
|
1139
|
+
var customError = error;
|
|
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
|
+
}
|
|
1148
|
+
return {
|
|
1149
|
+
message: String(error),
|
|
1150
|
+
name: "Unknown Error"
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
function parseConversationsMapCookie(cookieValue) {
|
|
1154
|
+
try {
|
|
1155
|
+
var decodedValue = decodeURIComponent(cookieValue);
|
|
1156
|
+
return JSON.parse(decodedValue);
|
|
1157
|
+
} catch (e) {
|
|
1158
|
+
console.error("Error parsing conversations cookie:", e);
|
|
1159
|
+
return {};
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
function getTopicSessionId(topicId) {
|
|
1163
|
+
var conversationsStr = getCookies("alquimia-sessions") || "{}";
|
|
1164
|
+
if (!conversationsStr) {
|
|
1165
|
+
var sessionCookie = getCookies("alquimia-session");
|
|
1166
|
+
return sessionCookie || "";
|
|
1167
|
+
}
|
|
1168
|
+
var conversationsMap = parseConversationsMapCookie(conversationsStr);
|
|
1169
|
+
return conversationsMap[topicId] || "";
|
|
1170
|
+
}
|
|
1171
|
+
function createMessageId() {
|
|
1172
|
+
return Math.floor(Math.random() * 1e6).toString();
|
|
1173
|
+
}
|
|
1174
|
+
// src/sdk/providers/openai.ts
|
|
1175
|
+
var import_openai = __toESM(require("openai"));
|
|
1176
|
+
var OpenAIWhisperProvider = /*#__PURE__*/ function(WhisperProvider) {
|
|
1177
|
+
_inherits(OpenAIWhisperProvider, WhisperProvider);
|
|
1178
|
+
function OpenAIWhisperProvider() {
|
|
1179
|
+
_class_call_check(this, OpenAIWhisperProvider);
|
|
1180
|
+
return _call_super(this, OpenAIWhisperProvider, arguments);
|
|
1181
|
+
}
|
|
1182
|
+
_create_class(OpenAIWhisperProvider, [
|
|
1183
|
+
{
|
|
1184
|
+
key: "textToSpeech",
|
|
1185
|
+
value: function textToSpeech(text) {
|
|
1186
|
+
return _async_to_generator(function() {
|
|
1187
|
+
return _ts_generator(this, function(_state) {
|
|
1188
|
+
return [
|
|
1189
|
+
2,
|
|
1190
|
+
new Blob()
|
|
1191
|
+
];
|
|
1192
|
+
});
|
|
1193
|
+
})();
|
|
1194
|
+
}
|
|
1195
|
+
},
|
|
1196
|
+
{
|
|
1197
|
+
key: "speechToText",
|
|
1198
|
+
value: function speechToText(audio) {
|
|
1199
|
+
return _async_to_generator(function() {
|
|
1200
|
+
return _ts_generator(this, function(_state) {
|
|
1201
|
+
return [
|
|
1202
|
+
2,
|
|
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;
|
|
1289
|
+
}
|
|
1290
|
+
_create_class(OpenAIStableDiffusionProvider, [
|
|
1291
|
+
{
|
|
1292
|
+
key: "generateImage",
|
|
1293
|
+
value: function generateImage(query) {
|
|
1294
|
+
var _this = this;
|
|
1295
|
+
return _async_to_generator(function() {
|
|
1296
|
+
var response;
|
|
1297
|
+
return _ts_generator(this, function(_state) {
|
|
1298
|
+
switch(_state.label){
|
|
1299
|
+
case 0:
|
|
1300
|
+
return [
|
|
1301
|
+
4,
|
|
1302
|
+
_this.client.images.generate({
|
|
1303
|
+
model: "dall-e-3",
|
|
1304
|
+
prompt: query,
|
|
1305
|
+
n: 1,
|
|
1306
|
+
size: "1024x1024"
|
|
1307
|
+
})
|
|
1308
|
+
];
|
|
1309
|
+
case 1:
|
|
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);
|
|
1323
|
+
// src/sdk/providers/stability.ts
|
|
1324
|
+
var import_buffer = require("buffer");
|
|
1325
|
+
var import_axios3 = __toESM(require("axios"));
|
|
1326
|
+
var StabilityProvider = /*#__PURE__*/ function(StableDiffusionProvider) {
|
|
1327
|
+
_inherits(StabilityProvider, StableDiffusionProvider);
|
|
1328
|
+
function StabilityProvider(config) {
|
|
1329
|
+
_class_call_check(this, StabilityProvider);
|
|
1330
|
+
return _call_super(this, StabilityProvider, [
|
|
1331
|
+
config
|
|
1332
|
+
]);
|
|
1333
|
+
}
|
|
1334
|
+
_create_class(StabilityProvider, [
|
|
1335
|
+
{
|
|
1336
|
+
key: "generateImage",
|
|
1337
|
+
value: function generateImage(query) {
|
|
1338
|
+
var _this = this;
|
|
1339
|
+
return _async_to_generator(function() {
|
|
1340
|
+
var payload, response, base64Image;
|
|
1341
|
+
return _ts_generator(this, function(_state) {
|
|
1342
|
+
switch(_state.label){
|
|
1343
|
+
case 0:
|
|
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
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
]);
|
|
1379
|
+
return StabilityProvider;
|
|
1380
|
+
}(StableDiffusionProvider);
|
|
1381
|
+
// src/sdk/providers/eleven-labs.ts
|
|
1382
|
+
var import_elevenlabs = require("elevenlabs");
|
|
1383
|
+
var import_axios4 = __toESM(require("axios"));
|
|
1384
|
+
var requestSpecs = {
|
|
1385
|
+
optimize_streaming_latency: import_elevenlabs.ElevenLabs.OptimizeStreamingLatency.Zero,
|
|
1386
|
+
output_format: import_elevenlabs.ElevenLabs.OutputFormat.Mp344100128,
|
|
1387
|
+
model_id: "eleven_multilingual_v1",
|
|
1388
|
+
language: "es",
|
|
1389
|
+
voice_settings: {
|
|
1390
|
+
stability: 0.1,
|
|
1391
|
+
similarity_boost: 0.15,
|
|
1392
|
+
style: 0.2
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
var ElevenLabsWhisperProvider = /*#__PURE__*/ function(WhisperProvider) {
|
|
1396
|
+
_inherits(ElevenLabsWhisperProvider, WhisperProvider);
|
|
1397
|
+
function ElevenLabsWhisperProvider(config) {
|
|
1398
|
+
_class_call_check(this, ElevenLabsWhisperProvider);
|
|
1399
|
+
var _this;
|
|
1400
|
+
_this = _call_super(this, ElevenLabsWhisperProvider, [
|
|
1401
|
+
config
|
|
1402
|
+
]);
|
|
1403
|
+
_this.client = new import_elevenlabs.ElevenLabsClient(config);
|
|
1404
|
+
return _this;
|
|
1405
|
+
}
|
|
1406
|
+
_create_class(ElevenLabsWhisperProvider, [
|
|
1407
|
+
{
|
|
1408
|
+
key: "speechToText",
|
|
1409
|
+
value: function speechToText(audio) {
|
|
1410
|
+
return _async_to_generator(function() {
|
|
1411
|
+
return _ts_generator(this, function(_state) {
|
|
1412
|
+
return [
|
|
1413
|
+
2,
|
|
1414
|
+
""
|
|
1415
|
+
];
|
|
1416
|
+
});
|
|
1417
|
+
})();
|
|
1418
|
+
}
|
|
1419
|
+
},
|
|
1420
|
+
{
|
|
1421
|
+
key: "textToSpeech",
|
|
1422
|
+
value: function textToSpeech(text) {
|
|
1423
|
+
var _this = this;
|
|
1424
|
+
return _async_to_generator(function() {
|
|
1425
|
+
var axiosClient, response, error;
|
|
1426
|
+
return _ts_generator(this, function(_state) {
|
|
1427
|
+
switch(_state.label){
|
|
1428
|
+
case 0:
|
|
1429
|
+
axiosClient = import_axios4.default.create({
|
|
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);
|
|
1475
|
+
// src/sdk/providers/elastic-search.ts
|
|
1476
|
+
var import_pino = __toESM(require("pino"));
|
|
1477
|
+
var ElasticLoggerProvider = /*#__PURE__*/ function(LoggerProvider) {
|
|
1478
|
+
_inherits(_ElasticLoggerProvider, LoggerProvider);
|
|
1479
|
+
function _ElasticLoggerProvider(config) {
|
|
1480
|
+
_class_call_check(this, _ElasticLoggerProvider);
|
|
1481
|
+
var _this;
|
|
1482
|
+
_this = _call_super(this, _ElasticLoggerProvider, [
|
|
1483
|
+
config
|
|
1484
|
+
]);
|
|
1485
|
+
_this.logger = console;
|
|
1486
|
+
return _this;
|
|
1487
|
+
}
|
|
1488
|
+
_create_class(_ElasticLoggerProvider, [
|
|
1489
|
+
{
|
|
1490
|
+
key: "initialize",
|
|
1491
|
+
value: function initialize(config) {
|
|
1492
|
+
var _this = this;
|
|
1493
|
+
return _async_to_generator(function() {
|
|
1494
|
+
var _ref, pinoElastic, streamToElastic;
|
|
1495
|
+
return _ts_generator(this, function(_state) {
|
|
1496
|
+
switch(_state.label){
|
|
1497
|
+
case 0:
|
|
1498
|
+
if (!(typeof window === "undefined")) return [
|
|
1499
|
+
3,
|
|
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
|
+
}
|
|
1553
|
+
},
|
|
1554
|
+
{
|
|
1555
|
+
key: "logInfo",
|
|
1556
|
+
value: function logInfo(message, data) {
|
|
1557
|
+
this.logger.info(_object_spread({}, data), message);
|
|
1558
|
+
}
|
|
1559
|
+
},
|
|
1560
|
+
{
|
|
1561
|
+
key: "logError",
|
|
1562
|
+
value: function logError(message, error, data) {
|
|
1563
|
+
var errorDetails = {
|
|
1564
|
+
message: error.message,
|
|
1565
|
+
name: error.name,
|
|
1566
|
+
stack: error.stack
|
|
1567
|
+
};
|
|
1568
|
+
this.logger.error(_object_spread({
|
|
1569
|
+
error: error
|
|
1570
|
+
}, data, errorDetails), message);
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
], [
|
|
1574
|
+
{
|
|
1575
|
+
key: "create",
|
|
1576
|
+
value: function create(config) {
|
|
1577
|
+
return _async_to_generator(function() {
|
|
1578
|
+
var provider;
|
|
1579
|
+
return _ts_generator(this, function(_state) {
|
|
1580
|
+
switch(_state.label){
|
|
1581
|
+
case 0:
|
|
1582
|
+
provider = new _ElasticLoggerProvider(config);
|
|
1583
|
+
return [
|
|
1584
|
+
4,
|
|
1585
|
+
provider.initialize(config)
|
|
1586
|
+
];
|
|
1587
|
+
case 1:
|
|
1588
|
+
_state.sent();
|
|
1589
|
+
return [
|
|
1590
|
+
2,
|
|
1591
|
+
provider
|
|
1592
|
+
];
|
|
1593
|
+
}
|
|
1594
|
+
});
|
|
1595
|
+
})();
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
]);
|
|
1599
|
+
return _ElasticLoggerProvider;
|
|
1600
|
+
}(LoggerProvider);
|
|
1601
|
+
// src/hooks/alquimia.hook.tsx
|
|
1602
|
+
var import_react2 = require("react");
|
|
1603
|
+
// src/context/session-context.tsx
|
|
1604
|
+
var import_react = __toESM(require("react"));
|
|
1605
|
+
// src/reducer/characterization-reducer.tsx
|
|
1606
|
+
var characterizationReducer = function(state, action) {
|
|
1607
|
+
switch(action.type){
|
|
1608
|
+
case "SET_SESSION":
|
|
1609
|
+
return _object_spread_props(_object_spread({}, state), {
|
|
1610
|
+
sessionId: action.payload.sessionId,
|
|
1611
|
+
characterizationData: action.payload.characterizationData
|
|
1612
|
+
});
|
|
1613
|
+
case "CLEAR_SESSION":
|
|
1614
|
+
return _object_spread_props(_object_spread({}, state), {
|
|
1615
|
+
sessionId: null,
|
|
1616
|
+
characterizationData: null
|
|
1617
|
+
});
|
|
1618
|
+
default:
|
|
1619
|
+
return state;
|
|
1620
|
+
}
|
|
1621
|
+
};
|
|
1622
|
+
// src/context/session-context.tsx
|
|
1623
|
+
var import_idb = require("idb");
|
|
1624
|
+
var initialState = {
|
|
1625
|
+
sessionId: null,
|
|
1626
|
+
characterizationData: null
|
|
1627
|
+
};
|
|
1628
|
+
var AlquimiaContext = (0, import_react.createContext)(null);
|
|
1629
|
+
var useSessionContext = function() {
|
|
1630
|
+
var context = (0, import_react.useContext)(AlquimiaContext);
|
|
1631
|
+
if (!context) {
|
|
1632
|
+
console.warn("useSessionContext must be used within a session provider. Returning default value.");
|
|
1633
|
+
return {
|
|
1634
|
+
userSessionState: initialState,
|
|
1635
|
+
saveUserSession: null
|
|
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;
|
|
1753
|
+
};
|
|
1754
|
+
return /* @__PURE__ */ import_react.default.createElement(AlquimiaContext.Provider, {
|
|
1755
|
+
value: {
|
|
1756
|
+
userSessionState: userSessionState,
|
|
1757
|
+
getSessionData: getSessionData,
|
|
1758
|
+
saveUserSession: saveUserSession
|
|
1759
|
+
}
|
|
1760
|
+
}, children);
|
|
1761
|
+
};
|
|
1762
|
+
// src/hooks/alquimia.hook.tsx
|
|
1763
|
+
function useAlquimia(sdk) {
|
|
1764
|
+
var _ref = _sliced_to_array((0, import_react2.useState)(""), 2), chunkReceived = _ref[0], setChunkReceived = _ref[1];
|
|
1765
|
+
var _ref1 = _sliced_to_array((0, import_react2.useState)(""), 2), currentMessageIdChuncked = _ref1[0], setCurrentMessageIdChuncked = _ref1[1];
|
|
1766
|
+
var _ref2 = _sliced_to_array((0, import_react2.useState)(""), 2), input = _ref2[0], setInput = _ref2[1];
|
|
1767
|
+
var _ref3 = _sliced_to_array((0, import_react2.useState)(false), 2), isLoading = _ref3[0], setIsLoading = _ref3[1];
|
|
1768
|
+
var _ref4 = _sliced_to_array((0, import_react2.useState)(false), 2), isMessageStreaming = _ref4[0], setIsMessageStreaming = _ref4[1];
|
|
1769
|
+
var _ref5 = _sliced_to_array((0, import_react2.useState)(null), 2), streamingMessageId = _ref5[0], setStreamingMessageId = _ref5[1];
|
|
1770
|
+
var _ref6 = _sliced_to_array((0, import_react2.useState)(false), 2), isAudioRecording = _ref6[0], setIsAudioRecording = _ref6[1];
|
|
1771
|
+
var _ref7 = _sliced_to_array((0, import_react2.useState)(null), 2), messageMetaData = _ref7[0], setMessageMetaData = _ref7[1];
|
|
1772
|
+
var _ref8 = _sliced_to_array((0, import_react2.useState)([]), 2), messages = _ref8[0], setMessages = _ref8[1];
|
|
1773
|
+
var _ref9 = _sliced_to_array((0, import_react2.useState)(null), 2), sessionId = _ref9[0], setSessionId = _ref9[1];
|
|
1774
|
+
var _ref10 = _sliced_to_array((0, import_react2.useState)(null), 2), activeTool = _ref10[0], setActiveTool = _ref10[1];
|
|
1775
|
+
var _ref11 = _sliced_to_array((0, import_react2.useState)(null), 2), lastRequest = _ref11[0], setLastRequest = _ref11[1];
|
|
1776
|
+
var _useSessionContext = useSessionContext(), userSessionState = _useSessionContext.userSessionState, saveUserSession = _useSessionContext.saveUserSession;
|
|
1777
|
+
var shouldShowCharacterizationButton = sdk.getEnforceCharacterization() && !(userSessionState === null || userSessionState === void 0 ? void 0 : userSessionState.characterizationData);
|
|
1778
|
+
(0, import_react2.useEffect)(function() {
|
|
1779
|
+
if (chunkReceived) processMessageChunk(currentMessageIdChuncked, chunkReceived);
|
|
1780
|
+
}, [
|
|
1781
|
+
chunkReceived
|
|
1782
|
+
]);
|
|
1783
|
+
(0, import_react2.useEffect)(function() {
|
|
1784
|
+
if ((userSessionState === null || userSessionState === void 0 ? void 0 : userSessionState.characterizationData) && sdk.getEnforceCharacterization()) {
|
|
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("");
|
|
1890
|
+
}
|
|
1891
|
+
function addUserMessage(message) {
|
|
1892
|
+
setMessages(function(prevMessages) {
|
|
1893
|
+
return _to_consumable_array(prevMessages).concat([
|
|
1894
|
+
{
|
|
1895
|
+
content: message,
|
|
1896
|
+
role: "user",
|
|
1897
|
+
id: createMessageId(),
|
|
1898
|
+
created_at: /* @__PURE__ */ new Date().getTime().toString()
|
|
1899
|
+
}
|
|
1900
|
+
]);
|
|
1901
|
+
});
|
|
1902
|
+
}
|
|
1903
|
+
function getCookie(name) {
|
|
1904
|
+
var cookies2 = document.cookie.split(";");
|
|
1905
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1906
|
+
try {
|
|
1907
|
+
for(var _iterator = cookies2[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1908
|
+
var cookie = _step.value;
|
|
1909
|
+
var _cookie_trim_split = _sliced_to_array(cookie.trim().split("="), 2), cookieName = _cookie_trim_split[0], cookieValue = _cookie_trim_split[1];
|
|
1910
|
+
if (cookieName === name) {
|
|
1911
|
+
return decodeURIComponent(cookieValue);
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
} catch (err) {
|
|
1915
|
+
_didIteratorError = true;
|
|
1916
|
+
_iteratorError = err;
|
|
1917
|
+
} finally{
|
|
1918
|
+
try {
|
|
1919
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1920
|
+
_iterator.return();
|
|
1921
|
+
}
|
|
1922
|
+
} finally{
|
|
1923
|
+
if (_didIteratorError) {
|
|
1924
|
+
throw _iteratorError;
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
return null;
|
|
1929
|
+
}
|
|
1930
|
+
function sendMessage(message, callBack, traceParentId, sessionId2) {
|
|
1931
|
+
return _sendMessage.apply(this, arguments);
|
|
1932
|
+
}
|
|
1933
|
+
function _sendMessage() {
|
|
1934
|
+
_sendMessage = _async_to_generator(function(message, callBack, traceParentId, sessionId2) {
|
|
1935
|
+
var conversationId, response, es;
|
|
1936
|
+
return _ts_generator(this, function(_state) {
|
|
1937
|
+
switch(_state.label){
|
|
1938
|
+
case 0:
|
|
1939
|
+
conversationId = sessionId2 || getCookie("alquimia-session");
|
|
1940
|
+
setIsMessageStreaming(true);
|
|
1941
|
+
setActiveTool(null);
|
|
1942
|
+
setLastRequest(message);
|
|
1943
|
+
return [
|
|
1944
|
+
4,
|
|
1945
|
+
sdk.widthConversationId(conversationId || "").sendMessage(message, traceParentId)
|
|
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
|
+
});
|
|
1977
|
+
});
|
|
1978
|
+
return _sendMessage.apply(this, arguments);
|
|
1979
|
+
}
|
|
1980
|
+
function handleSaveCharacterization(translation) {
|
|
1981
|
+
return _handleSaveCharacterization.apply(this, arguments);
|
|
1982
|
+
}
|
|
1983
|
+
function _handleSaveCharacterization() {
|
|
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
|
+
});
|
|
1996
|
+
});
|
|
1997
|
+
return _handleSaveCharacterization.apply(this, arguments);
|
|
1998
|
+
}
|
|
1999
|
+
return {
|
|
2000
|
+
activeTool: activeTool,
|
|
2001
|
+
cleanMessages: cleanMessages,
|
|
2002
|
+
createMessageId: createMessageId,
|
|
2003
|
+
handleInputChange: handleInputChange,
|
|
2004
|
+
handleReplaceInput: handleReplaceInput,
|
|
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
|
|
2025
|
+
};
|
|
2026
|
+
}
|
|
2027
|
+
// src/hooks/useRatings.ts
|
|
2028
|
+
var import_react3 = require("react");
|
|
2029
|
+
var initialState2 = {
|
|
2030
|
+
ratingStars: 0,
|
|
2031
|
+
ratingThumbs: "",
|
|
2032
|
+
ratingComment: ""
|
|
2033
|
+
};
|
|
2034
|
+
function ratingReducer(state, action) {
|
|
2035
|
+
switch(action.type){
|
|
2036
|
+
case "SET_RATING_STARS":
|
|
2037
|
+
return _object_spread_props(_object_spread({}, state), {
|
|
2038
|
+
ratingStars: action.payload
|
|
2039
|
+
});
|
|
2040
|
+
case "SET_RATING_THUMBS":
|
|
2041
|
+
return _object_spread_props(_object_spread({}, state), {
|
|
2042
|
+
ratingThumbs: action.payload
|
|
2043
|
+
});
|
|
2044
|
+
case "SET_RATING_COMMENT":
|
|
2045
|
+
return _object_spread_props(_object_spread({}, state), {
|
|
2046
|
+
ratingComment: action.payload
|
|
2047
|
+
});
|
|
2048
|
+
default:
|
|
2049
|
+
return state;
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
function useRatings(param) {
|
|
2053
|
+
var assistantId = param.assistantId, sendRating = param.sendRating, topicId = param.topicId;
|
|
2054
|
+
var _ref = _sliced_to_array((0, import_react3.useState)(false), 2), isLoading = _ref[0], setIsLoading = _ref[1];
|
|
2055
|
+
var _ref1 = _sliced_to_array((0, import_react3.useState)(false), 2), hasReviewed = _ref1[0], setHasReviewed = _ref1[1];
|
|
2056
|
+
var _ref2 = _sliced_to_array((0, import_react3.useReducer)(ratingReducer, initialState2), 2), state = _ref2[0], dispatch = _ref2[1];
|
|
2057
|
+
var setRatingStars = function(rating) {
|
|
2058
|
+
dispatch({
|
|
2059
|
+
type: "SET_RATING_STARS",
|
|
2060
|
+
payload: rating
|
|
2061
|
+
});
|
|
2062
|
+
};
|
|
2063
|
+
var setRatingThumbs = function(rating) {
|
|
2064
|
+
dispatch({
|
|
2065
|
+
type: "SET_RATING_THUMBS",
|
|
2066
|
+
payload: rating
|
|
2067
|
+
});
|
|
2068
|
+
};
|
|
2069
|
+
var setRatingComment = function(comment) {
|
|
2070
|
+
dispatch({
|
|
2071
|
+
type: "SET_RATING_COMMENT",
|
|
2072
|
+
payload: comment
|
|
2073
|
+
});
|
|
2074
|
+
};
|
|
2075
|
+
var thumbsScore = function(value) {
|
|
2076
|
+
return value === "thumbsUp" ? 5 : value === "thumbsDown" ? 0 : 0;
|
|
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
|
|
2152
|
+
};
|
|
2153
|
+
}
|
|
2154
|
+
// src/actions/alquimia.action.ts
|
|
2155
|
+
var import_crypto = require("crypto");
|
|
2156
|
+
var import_headers = require("next/headers");
|
|
2157
|
+
function initConversation(reset, topicId) {
|
|
2158
|
+
return _initConversation.apply(this, arguments);
|
|
2159
|
+
}
|
|
2160
|
+
function _initConversation() {
|
|
2161
|
+
_initConversation = _async_to_generator(function(reset, topicId) {
|
|
2162
|
+
var cookieStore, conversationId, alquimia_session, conversationsMap, existingConversations, decodedValue;
|
|
2163
|
+
return _ts_generator(this, function(_state) {
|
|
2164
|
+
switch(_state.label){
|
|
2165
|
+
case 0:
|
|
2166
|
+
return [
|
|
2167
|
+
4,
|
|
2168
|
+
(0, import_headers.cookies)()
|
|
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
|
+
});
|
|
2206
|
+
});
|
|
2207
|
+
return _initConversation.apply(this, arguments);
|
|
2208
|
+
}
|
|
2209
|
+
function createResource(config, payload) {
|
|
2210
|
+
return _createResource.apply(this, arguments);
|
|
2211
|
+
}
|
|
2212
|
+
function _createResource() {
|
|
2213
|
+
_createResource = // src/actions/baseApi.action.ts
|
|
2214
|
+
_async_to_generator(function(config, payload) {
|
|
2215
|
+
var headers, response, error, _tmp, error1;
|
|
2216
|
+
return _ts_generator(this, function(_state) {
|
|
2217
|
+
switch(_state.label){
|
|
2218
|
+
case 0:
|
|
2219
|
+
_state.trys.push([
|
|
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
|
+
});
|
|
2283
|
+
});
|
|
2284
|
+
return _createResource.apply(this, arguments);
|
|
2285
|
+
}
|
|
2286
|
+
function readResource(config, id) {
|
|
2287
|
+
return _readResource.apply(this, arguments);
|
|
2288
|
+
}
|
|
2289
|
+
function _readResource() {
|
|
2290
|
+
_readResource = _async_to_generator(function(config, id) {
|
|
2291
|
+
var headers, url, response, error, contentType, _tmp, arrayBuffer, _tmp1, error1;
|
|
2292
|
+
return _ts_generator(this, function(_state) {
|
|
2293
|
+
switch(_state.label){
|
|
2294
|
+
case 0:
|
|
2295
|
+
_state.trys.push([
|
|
2296
|
+
0,
|
|
2297
|
+
8,
|
|
2298
|
+
,
|
|
2299
|
+
9
|
|
2300
|
+
]);
|
|
2301
|
+
headers = generateHeaders(config);
|
|
2302
|
+
url = id ? "".concat(config.baseUrl).concat(config.route, "/").concat(id) : "".concat(config.baseUrl).concat(config.route);
|
|
2303
|
+
return [
|
|
2304
|
+
4,
|
|
2305
|
+
fetch(url, {
|
|
2306
|
+
method: "GET",
|
|
2307
|
+
headers: headers,
|
|
2308
|
+
cache: "default"
|
|
2309
|
+
})
|
|
2310
|
+
];
|
|
2311
|
+
case 1:
|
|
2312
|
+
response = _state.sent();
|
|
2313
|
+
if (!!response.ok) return [
|
|
2314
|
+
3,
|
|
2315
|
+
3
|
|
2316
|
+
];
|
|
2317
|
+
return [
|
|
2318
|
+
4,
|
|
2319
|
+
response.json()
|
|
2320
|
+
];
|
|
2321
|
+
case 2:
|
|
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);
|
|
2398
|
+
}
|
|
2399
|
+
function _updateResource() {
|
|
2400
|
+
_updateResource = _async_to_generator(function(config, id, data) {
|
|
2401
|
+
var headers, response, error, _tmp, error1;
|
|
2402
|
+
return _ts_generator(this, function(_state) {
|
|
2403
|
+
switch(_state.label){
|
|
2404
|
+
case 0:
|
|
2405
|
+
_state.trys.push([
|
|
2406
|
+
0,
|
|
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
|
+
});
|
|
2469
|
+
});
|
|
2470
|
+
return _updateResource.apply(this, arguments);
|
|
2471
|
+
}
|
|
2472
|
+
function deleteResource(config, id) {
|
|
2473
|
+
return _deleteResource.apply(this, arguments);
|
|
2474
|
+
}
|
|
2475
|
+
function _deleteResource() {
|
|
2476
|
+
_deleteResource = _async_to_generator(function(config, id) {
|
|
2477
|
+
var headers, response, error, error1;
|
|
2478
|
+
return _ts_generator(this, function(_state) {
|
|
2479
|
+
switch(_state.label){
|
|
2480
|
+
case 0:
|
|
2481
|
+
_state.trys.push([
|
|
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
|
+
});
|
|
2538
|
+
});
|
|
2539
|
+
return _deleteResource.apply(this, arguments);
|
|
2540
|
+
}
|
|
2541
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2542
|
+
0 && (module.exports = {
|
|
2543
|
+
AlquimiaRatingsProvider: AlquimiaRatingsProvider,
|
|
2544
|
+
AlquimiaSDK: AlquimiaSDK,
|
|
2545
|
+
AlquimiaWhisperProvider: AlquimiaWhisperProvider,
|
|
2546
|
+
Button: Button,
|
|
2547
|
+
Card: Card,
|
|
2548
|
+
CharacterizationProvider: CharacterizationProvider,
|
|
2549
|
+
Code: Code,
|
|
2550
|
+
ElasticLoggerProvider: ElasticLoggerProvider,
|
|
2551
|
+
ElevenLabsWhisperProvider: ElevenLabsWhisperProvider,
|
|
2552
|
+
GenerativeProvider: GenerativeProvider,
|
|
2553
|
+
LoggerProvider: LoggerProvider,
|
|
2554
|
+
OpenAIAnalyzeCharProvider: OpenAIAnalyzeCharProvider,
|
|
2555
|
+
OpenAIStableDiffusionProvider: OpenAIStableDiffusionProvider,
|
|
2556
|
+
OpenAIWhisperProvider: OpenAIWhisperProvider,
|
|
2557
|
+
RatingsProvider: RatingsProvider,
|
|
2558
|
+
SessionProvider: SessionProvider,
|
|
2559
|
+
StabilityProvider: StabilityProvider,
|
|
2560
|
+
StableDiffusionProvider: StableDiffusionProvider,
|
|
2561
|
+
WhisperProvider: WhisperProvider,
|
|
2562
|
+
createMessageId: createMessageId,
|
|
2563
|
+
createResource: createResource,
|
|
2564
|
+
defineAssistantId: defineAssistantId,
|
|
2565
|
+
deleteResource: deleteResource,
|
|
2566
|
+
formatTimeWithUnit: formatTimeWithUnit,
|
|
2567
|
+
generateHeaders: generateHeaders,
|
|
2568
|
+
generateTranslatePrompt: generateTranslatePrompt,
|
|
2569
|
+
getCookies: getCookies,
|
|
2570
|
+
getQueryParam: getQueryParam,
|
|
2571
|
+
getTopicSessionId: getTopicSessionId,
|
|
2572
|
+
initConversation: initConversation,
|
|
2573
|
+
isTextContent: isTextContent,
|
|
2574
|
+
parseConversationsMapCookie: parseConversationsMapCookie,
|
|
2575
|
+
readResource: readResource,
|
|
2576
|
+
serializeAxiosError: serializeAxiosError,
|
|
2577
|
+
updateResource: updateResource,
|
|
2578
|
+
useAlquimia: useAlquimia,
|
|
2579
|
+
useRatings: useRatings,
|
|
2580
|
+
useSessionContext: useSessionContext
|
|
2581
|
+
});
|
|
2582
|
+
//# sourceMappingURL=index.js.map
|