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