@alquimia-ai/tools 1.0.2 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/index.d.mts +38 -3
- package/dist/actions/index.d.ts +38 -3
- package/dist/actions/index.js +152 -20
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/index.mjs +153 -12
- package/dist/actions/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +2 -3
- package/dist/hooks/index.d.ts +2 -3
- package/dist/hooks/index.js +29 -60
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +16 -42
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/providers/index.d.mts +74 -0
- package/dist/providers/index.d.ts +74 -0
- package/dist/providers/index.js +2183 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/index.mjs +2173 -0
- package/dist/providers/index.mjs.map +1 -0
- package/dist/providers-D6FJ6tlA.d.mts +33 -0
- package/dist/providers-D6FJ6tlA.d.ts +33 -0
- package/dist/sdk/index.d.mts +41 -68
- package/dist/sdk/index.d.ts +41 -68
- package/dist/sdk/index.js +1 -374
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/index.mjs +1 -356
- package/dist/sdk/index.mjs.map +1 -1
- package/dist/services/index.js +0 -7
- package/dist/services/index.mjs +1 -0
- package/dist/types/index.js +0 -4
- package/dist/utils/index.js +0 -14
- package/package.json +16 -27
- package/dist/actions/alquimia.action.d.mts +0 -3
- package/dist/actions/alquimia.action.d.ts +0 -3
- package/dist/actions/alquimia.action.js +0 -62
- package/dist/actions/alquimia.action.js.map +0 -1
- package/dist/actions/alquimia.action.mjs +0 -38
- package/dist/actions/alquimia.action.mjs.map +0 -1
- package/dist/actions/baseApi.action.d.mts +0 -20
- package/dist/actions/baseApi.action.d.ts +0 -20
- package/dist/actions/baseApi.action.js +0 -202
- package/dist/actions/baseApi.action.js.map +0 -1
- package/dist/actions/baseApi.action.mjs +0 -173
- package/dist/actions/baseApi.action.mjs.map +0 -1
- package/dist/alquimia-sdk-DK0XLjol.d.mts +0 -77
- package/dist/alquimia-sdk-DK0XLjol.d.ts +0 -77
- package/dist/context/index.d.mts +0 -22
- package/dist/context/index.d.ts +0 -22
- package/dist/context/index.js +0 -124
- package/dist/context/index.js.map +0 -1
- package/dist/context/index.mjs +0 -96
- package/dist/context/index.mjs.map +0 -1
- package/dist/index.d.mts +0 -33
- package/dist/index.d.ts +0 -33
- package/dist/index.js +0 -1277
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -1202
- package/dist/index.mjs.map +0 -1
package/dist/index.js
DELETED
|
@@ -1,1277 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
AlquimiaRatingsProvider: () => AlquimiaRatingsProvider,
|
|
34
|
-
AlquimiaSDK: () => alquimia_sdk_default,
|
|
35
|
-
AlquimiaWhisperProvider: () => AlquimiaWhisperProvider,
|
|
36
|
-
Button: () => Button,
|
|
37
|
-
Card: () => Card,
|
|
38
|
-
CharacterizationProvider: () => CharacterizationProvider,
|
|
39
|
-
Code: () => Code,
|
|
40
|
-
ElasticLoggerProvider: () => ElasticLoggerProvider,
|
|
41
|
-
ElevenLabsWhisperProvider: () => ElevenLabsWhisperProvider,
|
|
42
|
-
GenerativeProvider: () => GenerativeProvider,
|
|
43
|
-
LoggerProvider: () => LoggerProvider,
|
|
44
|
-
OpenAIAnalyzeCharProvider: () => OpenAIAnalyzeCharProvider,
|
|
45
|
-
OpenAIStableDiffusionProvider: () => OpenAIStableDiffusionProvider,
|
|
46
|
-
OpenAIWhisperProvider: () => OpenAIWhisperProvider,
|
|
47
|
-
RatingsProvider: () => RatingsProvider,
|
|
48
|
-
SessionProvider: () => SessionProvider,
|
|
49
|
-
StabilityProvider: () => StabilityProvider,
|
|
50
|
-
StableDiffusionProvider: () => StableDiffusionProvider,
|
|
51
|
-
ToolFactory: () => ToolFactory,
|
|
52
|
-
WhisperProvider: () => WhisperProvider,
|
|
53
|
-
createMessageId: () => createMessageId,
|
|
54
|
-
createResource: () => createResource,
|
|
55
|
-
defineAssistantId: () => defineAssistantId,
|
|
56
|
-
deleteResource: () => deleteResource,
|
|
57
|
-
formatTimeWithUnit: () => formatTimeWithUnit,
|
|
58
|
-
generateHeaders: () => generateHeaders,
|
|
59
|
-
generateTranslatePrompt: () => generateTranslatePrompt,
|
|
60
|
-
getCookies: () => getCookies,
|
|
61
|
-
getQueryParam: () => getQueryParam,
|
|
62
|
-
getTopicSessionId: () => getTopicSessionId,
|
|
63
|
-
initConversation: () => initConversation,
|
|
64
|
-
isTextContent: () => isTextContent,
|
|
65
|
-
parseConversationsMapCookie: () => parseConversationsMapCookie,
|
|
66
|
-
readResource: () => readResource,
|
|
67
|
-
serializeAxiosError: () => serializeAxiosError,
|
|
68
|
-
updateResource: () => updateResource,
|
|
69
|
-
useAlquimia: () => useAlquimia,
|
|
70
|
-
useRatings: () => useRatings,
|
|
71
|
-
useSessionContext: () => useSessionContext
|
|
72
|
-
});
|
|
73
|
-
module.exports = __toCommonJS(index_exports);
|
|
74
|
-
|
|
75
|
-
// src/button.tsx
|
|
76
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
77
|
-
var Button = ({ children, className, appName }) => {
|
|
78
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
79
|
-
"button",
|
|
80
|
-
{
|
|
81
|
-
className,
|
|
82
|
-
onClick: () => alert(`Hello from your ${appName} app!`),
|
|
83
|
-
children
|
|
84
|
-
}
|
|
85
|
-
);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// src/card.tsx
|
|
89
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
90
|
-
function Card({
|
|
91
|
-
className,
|
|
92
|
-
title,
|
|
93
|
-
children,
|
|
94
|
-
href
|
|
95
|
-
}) {
|
|
96
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
97
|
-
"a",
|
|
98
|
-
{
|
|
99
|
-
className,
|
|
100
|
-
href: `${href}?utm_source=create-turbo&utm_medium=basic&utm_campaign=create-turbo"`,
|
|
101
|
-
rel: "noopener noreferrer",
|
|
102
|
-
target: "_blank",
|
|
103
|
-
children: [
|
|
104
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("h2", { children: [
|
|
105
|
-
title,
|
|
106
|
-
" ",
|
|
107
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "->" })
|
|
108
|
-
] }),
|
|
109
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children })
|
|
110
|
-
]
|
|
111
|
-
}
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// src/code.tsx
|
|
116
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
117
|
-
function Code({
|
|
118
|
-
children,
|
|
119
|
-
className
|
|
120
|
-
}) {
|
|
121
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("code", { className, children });
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// src/sdk/alquimia-sdk.ts
|
|
125
|
-
var import_axios = __toESM(require("axios"));
|
|
126
|
-
var AlquimiaSDK = class {
|
|
127
|
-
constructor(config, enforceCharacterization = true) {
|
|
128
|
-
this.conversationId = null;
|
|
129
|
-
this.sessionId = null;
|
|
130
|
-
this.streamId = null;
|
|
131
|
-
this.tools = [];
|
|
132
|
-
this.extraData = {};
|
|
133
|
-
this.forceProfile = {};
|
|
134
|
-
this.config = config;
|
|
135
|
-
this.enforceCharacterization = enforceCharacterization;
|
|
136
|
-
this.axiosInstance = import_axios.default.create();
|
|
137
|
-
this.axiosInstance.interceptors.response.use(
|
|
138
|
-
(response) => response,
|
|
139
|
-
async (error) => {
|
|
140
|
-
if (error.response?.status) {
|
|
141
|
-
if (this.loggerProvider) {
|
|
142
|
-
await this.loggerProvider.logError(
|
|
143
|
-
"Server Error",
|
|
144
|
-
error,
|
|
145
|
-
{
|
|
146
|
-
url: error.config.url,
|
|
147
|
-
method: error.config.method,
|
|
148
|
-
data: error.config.data,
|
|
149
|
-
status: error.response.status,
|
|
150
|
-
responseData: error.response.data
|
|
151
|
-
}
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return Promise.reject(error);
|
|
156
|
-
}
|
|
157
|
-
);
|
|
158
|
-
this.textToSpeech = this.textToSpeech.bind(this);
|
|
159
|
-
this.speechToText = this.speechToText.bind(this);
|
|
160
|
-
}
|
|
161
|
-
static configure(apiKey, inferUrl, streamUrl, assistantId) {
|
|
162
|
-
return {
|
|
163
|
-
apiKey,
|
|
164
|
-
chatUrl: `${inferUrl}/chat/${assistantId}`,
|
|
165
|
-
streamUrl: `${streamUrl}/${assistantId}`,
|
|
166
|
-
assistantId
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
widthConversationId(conversationId) {
|
|
170
|
-
this.conversationId = conversationId;
|
|
171
|
-
return this;
|
|
172
|
-
}
|
|
173
|
-
withWhisperProvider(provider) {
|
|
174
|
-
this.whisperProvider = provider;
|
|
175
|
-
return this;
|
|
176
|
-
}
|
|
177
|
-
withStableDiffusionProvider(provider) {
|
|
178
|
-
this.stableDiffusionProvider = provider;
|
|
179
|
-
return this;
|
|
180
|
-
}
|
|
181
|
-
withAnalyzeCharacterizationProvider(provider) {
|
|
182
|
-
this.analyzeCharacterizationProvider = provider;
|
|
183
|
-
return this;
|
|
184
|
-
}
|
|
185
|
-
withRatingsProvider(provider) {
|
|
186
|
-
this.ratingsProvider = provider;
|
|
187
|
-
return this;
|
|
188
|
-
}
|
|
189
|
-
withLoggerProvider(provider) {
|
|
190
|
-
this.loggerProvider = provider;
|
|
191
|
-
return this;
|
|
192
|
-
}
|
|
193
|
-
getEnforceCharacterization() {
|
|
194
|
-
return this.enforceCharacterization ?? true;
|
|
195
|
-
}
|
|
196
|
-
withTools(tools) {
|
|
197
|
-
this.tools = tools;
|
|
198
|
-
return this;
|
|
199
|
-
}
|
|
200
|
-
withExtraData(extraData) {
|
|
201
|
-
this.extraData = extraData;
|
|
202
|
-
return this;
|
|
203
|
-
}
|
|
204
|
-
withForceProfile(forceProfile) {
|
|
205
|
-
this.forceProfile = forceProfile;
|
|
206
|
-
return this;
|
|
207
|
-
}
|
|
208
|
-
textToSpeech(text) {
|
|
209
|
-
if (!this.whisperProvider) {
|
|
210
|
-
throw new Error("Whisper provider not initialized");
|
|
211
|
-
}
|
|
212
|
-
return this.whisperProvider.textToSpeech(text);
|
|
213
|
-
}
|
|
214
|
-
speechToText(audio) {
|
|
215
|
-
if (!this.whisperProvider) {
|
|
216
|
-
throw new Error("Whisper provider not initialized");
|
|
217
|
-
}
|
|
218
|
-
return this.whisperProvider.speechToText(audio);
|
|
219
|
-
}
|
|
220
|
-
async sendMessage(query, traceParent) {
|
|
221
|
-
if (!this.conversationId) {
|
|
222
|
-
throw new Error("Conversation not initialized");
|
|
223
|
-
}
|
|
224
|
-
const initMessage = {
|
|
225
|
-
query,
|
|
226
|
-
session_id: this.conversationId,
|
|
227
|
-
tools: this.tools,
|
|
228
|
-
extra_data: this.extraData,
|
|
229
|
-
force_profile: this.forceProfile
|
|
230
|
-
};
|
|
231
|
-
const result = (await this.axiosInstance.post(this.config.chatUrl, initMessage, {
|
|
232
|
-
headers: {
|
|
233
|
-
"Content-Type": "application/json",
|
|
234
|
-
"x-trace-parent": traceParent || ""
|
|
235
|
-
}
|
|
236
|
-
})).data;
|
|
237
|
-
this.streamId = result.data.stream_id;
|
|
238
|
-
return this;
|
|
239
|
-
}
|
|
240
|
-
async generateImage(query) {
|
|
241
|
-
if (!this.stableDiffusionProvider) {
|
|
242
|
-
throw new Error("Stable Diffusion provider not initialized");
|
|
243
|
-
}
|
|
244
|
-
return this.stableDiffusionProvider.generateImage(query);
|
|
245
|
-
}
|
|
246
|
-
async analyzeCharacterization(text) {
|
|
247
|
-
if (!this.analyzeCharacterizationProvider) {
|
|
248
|
-
throw new Error("analyze characterization provider not initialized");
|
|
249
|
-
}
|
|
250
|
-
return this.analyzeCharacterizationProvider.analyzeCharacterization(text);
|
|
251
|
-
}
|
|
252
|
-
async rate(data) {
|
|
253
|
-
if (!this.ratingsProvider) {
|
|
254
|
-
throw new Error("ratings provider not initialized");
|
|
255
|
-
}
|
|
256
|
-
return this.ratingsProvider.rate(data);
|
|
257
|
-
}
|
|
258
|
-
async logInfo(message, data) {
|
|
259
|
-
if (!this.loggerProvider) {
|
|
260
|
-
throw new Error("logger provider not initialized");
|
|
261
|
-
}
|
|
262
|
-
return this.loggerProvider.logInfo(message, data);
|
|
263
|
-
}
|
|
264
|
-
async logError(message, error, data) {
|
|
265
|
-
if (!this.loggerProvider) {
|
|
266
|
-
throw new Error("logger provider not initialized");
|
|
267
|
-
}
|
|
268
|
-
return this.loggerProvider.logError(message, error, data);
|
|
269
|
-
}
|
|
270
|
-
getUrlStream() {
|
|
271
|
-
return `${this.config.streamUrl}/${this.streamId}`;
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
var alquimia_sdk_default = AlquimiaSDK;
|
|
275
|
-
|
|
276
|
-
// src/sdk/providers/providers.ts
|
|
277
|
-
var GenerativeProvider = class {
|
|
278
|
-
constructor(config) {
|
|
279
|
-
this.config = config;
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
var WhisperProvider = class {
|
|
283
|
-
constructor(config) {
|
|
284
|
-
this.config = config;
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
var StableDiffusionProvider = class {
|
|
288
|
-
constructor(config) {
|
|
289
|
-
this.config = config;
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
var CharacterizationProvider = class {
|
|
293
|
-
constructor(config) {
|
|
294
|
-
this.config = config;
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
var RatingsProvider = class {
|
|
298
|
-
constructor(config) {
|
|
299
|
-
this.config = config;
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
var LoggerProvider = class {
|
|
303
|
-
constructor(config) {
|
|
304
|
-
this.config = config;
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
// src/sdk/providers/alquimia.ts
|
|
309
|
-
var import_axios2 = __toESM(require("axios"));
|
|
310
|
-
var AlquimiaWhisperProvider = class extends WhisperProvider {
|
|
311
|
-
constructor(config) {
|
|
312
|
-
super(config);
|
|
313
|
-
}
|
|
314
|
-
async textToSpeech(text) {
|
|
315
|
-
const axiosClient = import_axios2.default.create({
|
|
316
|
-
baseURL: this.config.baseURL
|
|
317
|
-
});
|
|
318
|
-
try {
|
|
319
|
-
const response = await axiosClient.post(
|
|
320
|
-
this.config.ttsRoute,
|
|
321
|
-
{
|
|
322
|
-
text
|
|
323
|
-
},
|
|
324
|
-
{ responseType: "blob" }
|
|
325
|
-
);
|
|
326
|
-
return response.data;
|
|
327
|
-
} catch (error) {
|
|
328
|
-
console.error("Error converting text to speech:", error);
|
|
329
|
-
throw error;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
async speechToText(audio) {
|
|
333
|
-
const axiosClient = import_axios2.default.create({
|
|
334
|
-
baseURL: this.config.baseURL
|
|
335
|
-
});
|
|
336
|
-
try {
|
|
337
|
-
const response = await axiosClient.post(this.config.sttRoute, {
|
|
338
|
-
audio
|
|
339
|
-
});
|
|
340
|
-
return response.data;
|
|
341
|
-
} catch (error) {
|
|
342
|
-
console.error("Error converting speech to text:", error);
|
|
343
|
-
throw error;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
var AlquimiaRatingsProvider = class extends RatingsProvider {
|
|
348
|
-
constructor(config) {
|
|
349
|
-
super(config);
|
|
350
|
-
}
|
|
351
|
-
async rate(data) {
|
|
352
|
-
const path = `${this.config.baseUrl}${this.config.route}`;
|
|
353
|
-
try {
|
|
354
|
-
let response;
|
|
355
|
-
const headers = {
|
|
356
|
-
Authorization: `Bearer ${this.config.token}`,
|
|
357
|
-
"Content-Type": "application/json",
|
|
358
|
-
...this.config.headers || {}
|
|
359
|
-
};
|
|
360
|
-
response = await import_axios2.default.post(`${path}`, data, { headers });
|
|
361
|
-
return {
|
|
362
|
-
success: true,
|
|
363
|
-
data: response.data
|
|
364
|
-
};
|
|
365
|
-
} catch (error) {
|
|
366
|
-
if (import_axios2.default.isAxiosError(error)) {
|
|
367
|
-
return {
|
|
368
|
-
success: false,
|
|
369
|
-
error: {
|
|
370
|
-
message: error.message,
|
|
371
|
-
response: {
|
|
372
|
-
status: error.response?.status,
|
|
373
|
-
data: error.response?.data
|
|
374
|
-
},
|
|
375
|
-
details: error.response?.data
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
return {
|
|
380
|
-
success: false,
|
|
381
|
-
error: {
|
|
382
|
-
message: error instanceof Error ? error.message : "Unknown error occurred",
|
|
383
|
-
response: {
|
|
384
|
-
status: 500
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
// src/utils/utils.ts
|
|
393
|
-
function generateTranslatePrompt(text) {
|
|
394
|
-
const prompt = `
|
|
395
|
-
Arrange the following text according to the given object structure and return it as plain json, values summarized to one word, no formatting:
|
|
396
|
-
{
|
|
397
|
-
restrictions: {
|
|
398
|
-
value: [''],
|
|
399
|
-
description: 'Restrictions to certain foods'
|
|
400
|
-
},
|
|
401
|
-
alergies: {
|
|
402
|
-
value: [''],
|
|
403
|
-
description: 'Alergies to certain foods'
|
|
404
|
-
},
|
|
405
|
-
wine_preference: {
|
|
406
|
-
value: [''],
|
|
407
|
-
description: 'Preferences for the wine'
|
|
408
|
-
},
|
|
409
|
-
meal_preference: {
|
|
410
|
-
value: [''],
|
|
411
|
-
description: 'Preferences for the meal'
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
Text: "${text}"
|
|
416
|
-
|
|
417
|
-
Output:
|
|
418
|
-
`;
|
|
419
|
-
return prompt;
|
|
420
|
-
}
|
|
421
|
-
function getCookies(name) {
|
|
422
|
-
if (typeof document === "undefined") return void 0;
|
|
423
|
-
const value = `; ${document.cookie}`;
|
|
424
|
-
const parts = value.split(`; ${name}=`);
|
|
425
|
-
if (parts.length === 2) return parts.pop()?.split(";").shift();
|
|
426
|
-
}
|
|
427
|
-
function generateHeaders(config) {
|
|
428
|
-
const headers = {
|
|
429
|
-
"Content-Type": "application/json"
|
|
430
|
-
};
|
|
431
|
-
if (config.token) {
|
|
432
|
-
headers["Authorization"] = `Bearer ${config.token}`;
|
|
433
|
-
}
|
|
434
|
-
if (config.headers) {
|
|
435
|
-
Object.entries(config.headers).forEach(([key, value]) => {
|
|
436
|
-
headers[key] = value;
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
return headers;
|
|
440
|
-
}
|
|
441
|
-
function isTextContent(buffer) {
|
|
442
|
-
try {
|
|
443
|
-
const text = new TextDecoder().decode(buffer);
|
|
444
|
-
return /^[\w\#\-\*]/.test(text.trim());
|
|
445
|
-
} catch {
|
|
446
|
-
return false;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
function getQueryParam(param) {
|
|
450
|
-
if (typeof window !== "undefined") {
|
|
451
|
-
const urlParams = new URLSearchParams(window.location.search);
|
|
452
|
-
return urlParams.get(param);
|
|
453
|
-
}
|
|
454
|
-
return null;
|
|
455
|
-
}
|
|
456
|
-
function defineAssistantId(defaultId) {
|
|
457
|
-
if (typeof window !== "undefined" && window.location.pathname === "/") {
|
|
458
|
-
const queryAssistantId = getQueryParam("talkwith");
|
|
459
|
-
if (queryAssistantId) {
|
|
460
|
-
localStorage.setItem("assistantId", queryAssistantId);
|
|
461
|
-
return queryAssistantId;
|
|
462
|
-
}
|
|
463
|
-
const storedAssistantId = localStorage.getItem("assistantId");
|
|
464
|
-
return storedAssistantId || defaultId;
|
|
465
|
-
}
|
|
466
|
-
return defaultId;
|
|
467
|
-
}
|
|
468
|
-
function formatTimeWithUnit(timeMs) {
|
|
469
|
-
if (timeMs >= 1e3) {
|
|
470
|
-
return `${(timeMs / 1e3).toFixed(1)}s`;
|
|
471
|
-
}
|
|
472
|
-
return `${Math.round(timeMs)}ms`;
|
|
473
|
-
}
|
|
474
|
-
function serializeAxiosError(error) {
|
|
475
|
-
if (error instanceof Error) {
|
|
476
|
-
const customError = error;
|
|
477
|
-
return {
|
|
478
|
-
message: customError?.message,
|
|
479
|
-
name: customError?.name,
|
|
480
|
-
stack: customError?.stack,
|
|
481
|
-
code: customError?.code,
|
|
482
|
-
status: customError?.status
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
return {
|
|
486
|
-
message: String(error),
|
|
487
|
-
name: "Unknown Error"
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
function parseConversationsMapCookie(cookieValue) {
|
|
491
|
-
try {
|
|
492
|
-
const decodedValue = decodeURIComponent(cookieValue);
|
|
493
|
-
return JSON.parse(decodedValue);
|
|
494
|
-
} catch (e) {
|
|
495
|
-
console.error("Error parsing conversations cookie:", e);
|
|
496
|
-
return {};
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
function getTopicSessionId(topicId) {
|
|
500
|
-
const conversationsStr = getCookies("alquimia-sessions") || "{}";
|
|
501
|
-
if (!conversationsStr) {
|
|
502
|
-
const sessionCookie = getCookies("alquimia-session");
|
|
503
|
-
return sessionCookie || "";
|
|
504
|
-
}
|
|
505
|
-
const conversationsMap = parseConversationsMapCookie(conversationsStr);
|
|
506
|
-
return conversationsMap[topicId] || "";
|
|
507
|
-
}
|
|
508
|
-
function createMessageId() {
|
|
509
|
-
return Math.floor(Math.random() * 1e6).toString();
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
// src/sdk/providers/openai.ts
|
|
513
|
-
var import_openai = __toESM(require("openai"));
|
|
514
|
-
var OpenAIWhisperProvider = class extends WhisperProvider {
|
|
515
|
-
async textToSpeech(text) {
|
|
516
|
-
return new Blob();
|
|
517
|
-
}
|
|
518
|
-
async speechToText(audio) {
|
|
519
|
-
return "";
|
|
520
|
-
}
|
|
521
|
-
};
|
|
522
|
-
var OpenAIAnalyzeCharProvider = class extends CharacterizationProvider {
|
|
523
|
-
constructor(config) {
|
|
524
|
-
super(config);
|
|
525
|
-
this.client = new import_openai.default({
|
|
526
|
-
apiKey: config.apiKey
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
async analyzeCharacterization(text) {
|
|
530
|
-
const prompt = generateTranslatePrompt(text);
|
|
531
|
-
const response = await this.client.chat.completions.create({
|
|
532
|
-
model: "gpt-4o-mini",
|
|
533
|
-
messages: [
|
|
534
|
-
{ role: "system", content: "You are a helpful assistant." },
|
|
535
|
-
{ role: "user", content: prompt }
|
|
536
|
-
],
|
|
537
|
-
max_tokens: 150,
|
|
538
|
-
temperature: 0.7
|
|
539
|
-
});
|
|
540
|
-
const arrangedText = response.choices[0].message.content.trim();
|
|
541
|
-
try {
|
|
542
|
-
const arrangedObject = JSON.parse(arrangedText);
|
|
543
|
-
return arrangedObject;
|
|
544
|
-
} catch (error) {
|
|
545
|
-
throw new Error("Failed to parse the response from OpenAI");
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
};
|
|
549
|
-
var OpenAIStableDiffusionProvider = class extends StableDiffusionProvider {
|
|
550
|
-
constructor(config) {
|
|
551
|
-
super(config);
|
|
552
|
-
this.client = new import_openai.default({
|
|
553
|
-
apiKey: config.apiKey
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
async generateImage(query) {
|
|
557
|
-
const response = await this.client.images.generate({
|
|
558
|
-
model: "dall-e-3",
|
|
559
|
-
prompt: query,
|
|
560
|
-
n: 1,
|
|
561
|
-
size: "1024x1024"
|
|
562
|
-
});
|
|
563
|
-
return response.data[0].url;
|
|
564
|
-
}
|
|
565
|
-
};
|
|
566
|
-
|
|
567
|
-
// src/sdk/providers/stability.ts
|
|
568
|
-
var import_buffer = require("buffer");
|
|
569
|
-
var import_axios3 = __toESM(require("axios"));
|
|
570
|
-
var StabilityProvider = class extends StableDiffusionProvider {
|
|
571
|
-
constructor(config) {
|
|
572
|
-
super(config);
|
|
573
|
-
}
|
|
574
|
-
async generateImage(query) {
|
|
575
|
-
const payload = {
|
|
576
|
-
prompt: "query",
|
|
577
|
-
output_format: "webp"
|
|
578
|
-
};
|
|
579
|
-
const response = await import_axios3.default.postForm(
|
|
580
|
-
`https://api.stability.ai/v2beta/stable-image/generate/ultra`,
|
|
581
|
-
import_axios3.default.toFormData(payload, new FormData()),
|
|
582
|
-
{
|
|
583
|
-
validateStatus: void 0,
|
|
584
|
-
responseType: "arraybuffer",
|
|
585
|
-
headers: {
|
|
586
|
-
Authorization: `Bearer ${this.config.apiKey}`,
|
|
587
|
-
Accept: "image/*"
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
);
|
|
591
|
-
if (response.status === 200) {
|
|
592
|
-
const base64Image = import_buffer.Buffer.from(response.data).toString("base64");
|
|
593
|
-
return `data:image/webp;base64,${base64Image}`;
|
|
594
|
-
} else {
|
|
595
|
-
throw new Error(`${response.status}: ${response.data.toString()}`);
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
};
|
|
599
|
-
|
|
600
|
-
// src/sdk/providers/eleven-labs.ts
|
|
601
|
-
var import_elevenlabs = require("elevenlabs");
|
|
602
|
-
var import_axios4 = __toESM(require("axios"));
|
|
603
|
-
var requestSpecs = {
|
|
604
|
-
optimize_streaming_latency: import_elevenlabs.ElevenLabs.OptimizeStreamingLatency.Zero,
|
|
605
|
-
output_format: import_elevenlabs.ElevenLabs.OutputFormat.Mp344100128,
|
|
606
|
-
model_id: "eleven_multilingual_v1",
|
|
607
|
-
language: "es",
|
|
608
|
-
voice_settings: {
|
|
609
|
-
stability: 0.1,
|
|
610
|
-
similarity_boost: 0.15,
|
|
611
|
-
style: 0.2
|
|
612
|
-
}
|
|
613
|
-
};
|
|
614
|
-
var ElevenLabsWhisperProvider = class extends WhisperProvider {
|
|
615
|
-
constructor(config) {
|
|
616
|
-
super(config);
|
|
617
|
-
this.client = new import_elevenlabs.ElevenLabsClient(config);
|
|
618
|
-
}
|
|
619
|
-
async speechToText(audio) {
|
|
620
|
-
return "";
|
|
621
|
-
}
|
|
622
|
-
async textToSpeech(text) {
|
|
623
|
-
const axiosClient = import_axios4.default.create({
|
|
624
|
-
baseURL: this.config.baseURL,
|
|
625
|
-
headers: {
|
|
626
|
-
Accept: "audio/mpeg",
|
|
627
|
-
"Content-Type": "application/json",
|
|
628
|
-
"Xi-Api-Key": this.config.apiKey
|
|
629
|
-
}
|
|
630
|
-
});
|
|
631
|
-
try {
|
|
632
|
-
const response = await axiosClient.post(
|
|
633
|
-
`/v1/text-to-speech/${this.config.voiceId}`,
|
|
634
|
-
{
|
|
635
|
-
text,
|
|
636
|
-
...requestSpecs
|
|
637
|
-
},
|
|
638
|
-
{ responseType: "blob" }
|
|
639
|
-
);
|
|
640
|
-
return response.data;
|
|
641
|
-
} catch (error) {
|
|
642
|
-
console.error("Error converting text to speech:", error);
|
|
643
|
-
throw error;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
};
|
|
647
|
-
|
|
648
|
-
// src/sdk/providers/elastic-search.ts
|
|
649
|
-
var import_pino = __toESM(require("pino"));
|
|
650
|
-
var ElasticLoggerProvider = class _ElasticLoggerProvider extends LoggerProvider {
|
|
651
|
-
constructor(config) {
|
|
652
|
-
super(config);
|
|
653
|
-
this.logger = console;
|
|
654
|
-
}
|
|
655
|
-
static async create(config) {
|
|
656
|
-
const provider = new _ElasticLoggerProvider(config);
|
|
657
|
-
await provider.initialize(config);
|
|
658
|
-
return provider;
|
|
659
|
-
}
|
|
660
|
-
async initialize(config) {
|
|
661
|
-
if (typeof window === "undefined") {
|
|
662
|
-
const [pinoElastic] = await Promise.all([
|
|
663
|
-
import("pino-elasticsearch")
|
|
664
|
-
]);
|
|
665
|
-
const streamToElastic = pinoElastic.default({
|
|
666
|
-
index: config.index || "logs-index",
|
|
667
|
-
node: config.endpoint,
|
|
668
|
-
esVersion: config.esVersion || 7,
|
|
669
|
-
flushBytes: config.flushBytes || 1e3,
|
|
670
|
-
auth: {
|
|
671
|
-
username: config.username || "",
|
|
672
|
-
password: config.password || ""
|
|
673
|
-
},
|
|
674
|
-
tls: {
|
|
675
|
-
rejectUnauthorized: false
|
|
676
|
-
},
|
|
677
|
-
op_type: "create"
|
|
678
|
-
});
|
|
679
|
-
streamToElastic.on("error", (err) => {
|
|
680
|
-
console.error("Elasticsearch stream error:", err);
|
|
681
|
-
});
|
|
682
|
-
streamToElastic.on("insertError", (err) => {
|
|
683
|
-
console.error("Elasticsearch insert error:", err);
|
|
684
|
-
});
|
|
685
|
-
streamToElastic.on("insert", () => {
|
|
686
|
-
console.log("Successfully sent log to Elasticsearch");
|
|
687
|
-
});
|
|
688
|
-
this.logger = (0, import_pino.default)({
|
|
689
|
-
level: "info",
|
|
690
|
-
timestamp: () => `,"time":"${(/* @__PURE__ */ new Date()).toISOString()}"`
|
|
691
|
-
}, streamToElastic);
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
logInfo(message, data) {
|
|
695
|
-
this.logger.info({ ...data }, message);
|
|
696
|
-
}
|
|
697
|
-
logError(message, error, data) {
|
|
698
|
-
const errorDetails = {
|
|
699
|
-
message: error.message,
|
|
700
|
-
name: error.name,
|
|
701
|
-
stack: error.stack
|
|
702
|
-
};
|
|
703
|
-
this.logger.error({ error, ...data, ...errorDetails }, message);
|
|
704
|
-
}
|
|
705
|
-
};
|
|
706
|
-
|
|
707
|
-
// src/hooks/alquimia.hook.tsx
|
|
708
|
-
var import_react2 = require("react");
|
|
709
|
-
|
|
710
|
-
// src/context/session-context.tsx
|
|
711
|
-
var import_react = require("react");
|
|
712
|
-
|
|
713
|
-
// src/reducer/characterization-reducer.tsx
|
|
714
|
-
var characterizationReducer = (state, action) => {
|
|
715
|
-
switch (action.type) {
|
|
716
|
-
case "SET_SESSION":
|
|
717
|
-
return {
|
|
718
|
-
...state,
|
|
719
|
-
sessionId: action.payload.sessionId,
|
|
720
|
-
characterizationData: action.payload.characterizationData
|
|
721
|
-
};
|
|
722
|
-
case "CLEAR_SESSION":
|
|
723
|
-
return {
|
|
724
|
-
...state,
|
|
725
|
-
sessionId: null,
|
|
726
|
-
characterizationData: null
|
|
727
|
-
};
|
|
728
|
-
default:
|
|
729
|
-
return state;
|
|
730
|
-
}
|
|
731
|
-
};
|
|
732
|
-
|
|
733
|
-
// src/context/session-context.tsx
|
|
734
|
-
var import_idb = require("idb");
|
|
735
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
736
|
-
var initialState = {
|
|
737
|
-
sessionId: null,
|
|
738
|
-
characterizationData: null
|
|
739
|
-
};
|
|
740
|
-
var AlquimiaContext = (0, import_react.createContext)(null);
|
|
741
|
-
var useSessionContext = () => {
|
|
742
|
-
const context = (0, import_react.useContext)(AlquimiaContext);
|
|
743
|
-
if (!context) {
|
|
744
|
-
console.warn("useSessionContext must be used within a session provider. Returning default value.");
|
|
745
|
-
return {
|
|
746
|
-
userSessionState: initialState,
|
|
747
|
-
saveUserSession: null
|
|
748
|
-
};
|
|
749
|
-
}
|
|
750
|
-
return context;
|
|
751
|
-
};
|
|
752
|
-
var SessionProvider = ({ children }) => {
|
|
753
|
-
const [userSessionState, sessionDispatch] = (0, import_react.useReducer)(characterizationReducer, initialState);
|
|
754
|
-
(0, import_react.useEffect)(() => {
|
|
755
|
-
getSession();
|
|
756
|
-
}, []);
|
|
757
|
-
const getSession = async () => {
|
|
758
|
-
const userCookie = await getCookies("alquimia-session") || "";
|
|
759
|
-
const db = await (0, import_idb.openDB)("alquimiaDB", 1, {
|
|
760
|
-
upgrade(db2) {
|
|
761
|
-
if (!db2.objectStoreNames.contains("session")) {
|
|
762
|
-
db2.createObjectStore("session", { keyPath: "key" });
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
});
|
|
766
|
-
const sessionIdEntry = await db.get("session", "sessionId");
|
|
767
|
-
const characterizationDataEntry = await db.get("session", "characterizationData");
|
|
768
|
-
const sessionDataMatchesCookie = sessionIdEntry?.value === userCookie;
|
|
769
|
-
if (sessionIdEntry && characterizationDataEntry && sessionDataMatchesCookie) {
|
|
770
|
-
sessionDispatch({
|
|
771
|
-
type: "SET_SESSION",
|
|
772
|
-
payload: {
|
|
773
|
-
sessionId: sessionIdEntry.value,
|
|
774
|
-
characterizationData: characterizationDataEntry.value
|
|
775
|
-
}
|
|
776
|
-
});
|
|
777
|
-
}
|
|
778
|
-
};
|
|
779
|
-
const saveUserSession = async (id, data) => {
|
|
780
|
-
const db = await (0, import_idb.openDB)("alquimiaDB", 1);
|
|
781
|
-
await db.put("session", { key: "sessionId", value: id });
|
|
782
|
-
await db.put("session", { key: "characterizationData", value: data });
|
|
783
|
-
sessionDispatch({
|
|
784
|
-
type: "SET_SESSION",
|
|
785
|
-
payload: { sessionId: id, characterizationData: data }
|
|
786
|
-
});
|
|
787
|
-
};
|
|
788
|
-
const getSessionData = () => {
|
|
789
|
-
return userSessionState;
|
|
790
|
-
};
|
|
791
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AlquimiaContext.Provider, { value: { userSessionState, getSessionData, saveUserSession }, children });
|
|
792
|
-
};
|
|
793
|
-
|
|
794
|
-
// src/hooks/alquimia.hook.tsx
|
|
795
|
-
function useAlquimia(sdk) {
|
|
796
|
-
const [chunkReceived, setChunkReceived] = (0, import_react2.useState)("");
|
|
797
|
-
const [currentMessageIdChuncked, setCurrentMessageIdChuncked] = (0, import_react2.useState)("");
|
|
798
|
-
const [input, setInput] = (0, import_react2.useState)("");
|
|
799
|
-
const [isLoading, setIsLoading] = (0, import_react2.useState)(false);
|
|
800
|
-
const [isMessageStreaming, setIsMessageStreaming] = (0, import_react2.useState)(false);
|
|
801
|
-
const [streamingMessageId, setStreamingMessageId] = (0, import_react2.useState)(null);
|
|
802
|
-
const [isAudioRecording, setIsAudioRecording] = (0, import_react2.useState)(false);
|
|
803
|
-
const [messageMetaData, setMessageMetaData] = (0, import_react2.useState)(null);
|
|
804
|
-
const [messages, setMessages] = (0, import_react2.useState)([]);
|
|
805
|
-
const [sessionId, setSessionId] = (0, import_react2.useState)(null);
|
|
806
|
-
const [activeTool, setActiveTool] = (0, import_react2.useState)(null);
|
|
807
|
-
const [lastRequest, setLastRequest] = (0, import_react2.useState)(null);
|
|
808
|
-
const { userSessionState, saveUserSession } = useSessionContext();
|
|
809
|
-
const shouldShowCharacterizationButton = sdk.getEnforceCharacterization() && !userSessionState?.characterizationData;
|
|
810
|
-
(0, import_react2.useEffect)(() => {
|
|
811
|
-
if (chunkReceived)
|
|
812
|
-
processMessageChunk(currentMessageIdChuncked, chunkReceived);
|
|
813
|
-
}, [chunkReceived]);
|
|
814
|
-
(0, import_react2.useEffect)(() => {
|
|
815
|
-
if (userSessionState?.characterizationData && sdk.getEnforceCharacterization()) {
|
|
816
|
-
sdk.withExtraData(userSessionState?.characterizationData);
|
|
817
|
-
}
|
|
818
|
-
}, [userSessionState]);
|
|
819
|
-
function cleanMessages() {
|
|
820
|
-
setMessages([]);
|
|
821
|
-
}
|
|
822
|
-
async function processMessageChunk(messageId, chunk, error_code, error_detail, additionalInfo) {
|
|
823
|
-
setMessages((currentMessages) => {
|
|
824
|
-
const messageIndex = currentMessages.findIndex(
|
|
825
|
-
(message) => message.id === messageId
|
|
826
|
-
);
|
|
827
|
-
if (messageIndex !== -1) {
|
|
828
|
-
const updatedMessages = [...currentMessages];
|
|
829
|
-
const updatedMessage = {
|
|
830
|
-
...updatedMessages[messageIndex],
|
|
831
|
-
content: `${updatedMessages[messageIndex]?.content || ""}${chunk}`,
|
|
832
|
-
id: updatedMessages[messageIndex]?.id || "",
|
|
833
|
-
role: updatedMessages[messageIndex]?.role || "assistant",
|
|
834
|
-
error_code,
|
|
835
|
-
error_detail,
|
|
836
|
-
additionalInfo,
|
|
837
|
-
created_at: (/* @__PURE__ */ new Date()).getTime().toString()
|
|
838
|
-
};
|
|
839
|
-
updatedMessages[messageIndex] = updatedMessage;
|
|
840
|
-
return updatedMessages;
|
|
841
|
-
} else {
|
|
842
|
-
return [
|
|
843
|
-
...currentMessages,
|
|
844
|
-
{
|
|
845
|
-
content: `${chunk}`,
|
|
846
|
-
role: "assistant",
|
|
847
|
-
id: messageId,
|
|
848
|
-
error_code,
|
|
849
|
-
error_detail,
|
|
850
|
-
created_at: (/* @__PURE__ */ new Date()).getTime().toString()
|
|
851
|
-
}
|
|
852
|
-
];
|
|
853
|
-
}
|
|
854
|
-
});
|
|
855
|
-
}
|
|
856
|
-
async function handleSubmit(event, traceParentId, sessionId2, additionalInfo) {
|
|
857
|
-
setIsLoading(true);
|
|
858
|
-
event.preventDefault();
|
|
859
|
-
if (input) {
|
|
860
|
-
addUserMessage(input);
|
|
861
|
-
const messageId = createMessageId();
|
|
862
|
-
setCurrentMessageIdChuncked(messageId);
|
|
863
|
-
setStreamingMessageId(messageId);
|
|
864
|
-
await sendMessage(input, (chunk) => {
|
|
865
|
-
processMessageChunk(
|
|
866
|
-
messageId,
|
|
867
|
-
chunk?.data?.content || "",
|
|
868
|
-
chunk?.error_code,
|
|
869
|
-
chunk?.error_detail,
|
|
870
|
-
additionalInfo
|
|
871
|
-
);
|
|
872
|
-
}, traceParentId, sessionId2);
|
|
873
|
-
setInput("");
|
|
874
|
-
}
|
|
875
|
-
setIsLoading(false);
|
|
876
|
-
}
|
|
877
|
-
function handleInputChange(event) {
|
|
878
|
-
setInput(event.target.value);
|
|
879
|
-
}
|
|
880
|
-
function handleReplaceInput(input2) {
|
|
881
|
-
setInput(input2);
|
|
882
|
-
}
|
|
883
|
-
function populateMessages(messages2) {
|
|
884
|
-
setMessages(messages2);
|
|
885
|
-
}
|
|
886
|
-
function handleLoadingCancel() {
|
|
887
|
-
setIsLoading(false);
|
|
888
|
-
setIsMessageStreaming(false);
|
|
889
|
-
setInput("");
|
|
890
|
-
}
|
|
891
|
-
function addUserMessage(message) {
|
|
892
|
-
setMessages((prevMessages) => [
|
|
893
|
-
...prevMessages,
|
|
894
|
-
{
|
|
895
|
-
content: message,
|
|
896
|
-
role: "user",
|
|
897
|
-
id: createMessageId(),
|
|
898
|
-
created_at: (/* @__PURE__ */ new Date()).getTime().toString()
|
|
899
|
-
}
|
|
900
|
-
]);
|
|
901
|
-
}
|
|
902
|
-
function getCookie(name) {
|
|
903
|
-
const cookies2 = document.cookie.split(";");
|
|
904
|
-
for (let cookie of cookies2) {
|
|
905
|
-
const [cookieName, cookieValue] = cookie.trim().split("=");
|
|
906
|
-
if (cookieName === name) {
|
|
907
|
-
return decodeURIComponent(cookieValue);
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
return null;
|
|
911
|
-
}
|
|
912
|
-
async function sendMessage(message, callBack, traceParentId, sessionId2) {
|
|
913
|
-
const conversationId = sessionId2 || getCookie("alquimia-session");
|
|
914
|
-
setIsMessageStreaming(true);
|
|
915
|
-
setActiveTool(null);
|
|
916
|
-
setLastRequest(message);
|
|
917
|
-
const response = await sdk.widthConversationId(conversationId || "").sendMessage(message, traceParentId);
|
|
918
|
-
const es = new EventSource(response.getUrlStream());
|
|
919
|
-
es.onmessage = (event) => {
|
|
920
|
-
const parsedData = JSON.parse(event.data);
|
|
921
|
-
if (parsedData.tooler && parsedData.tooler.length > 0 && !activeTool) {
|
|
922
|
-
setActiveTool({
|
|
923
|
-
tooler: parsedData.tooler
|
|
924
|
-
});
|
|
925
|
-
}
|
|
926
|
-
if (parsedData.error_code) {
|
|
927
|
-
callBack({
|
|
928
|
-
type: "error",
|
|
929
|
-
error_code: parsedData.error_code,
|
|
930
|
-
error_detail: parsedData.error_detail
|
|
931
|
-
});
|
|
932
|
-
}
|
|
933
|
-
if (parsedData.is_complete) {
|
|
934
|
-
setIsMessageStreaming(false);
|
|
935
|
-
setStreamingMessageId(null);
|
|
936
|
-
es.close();
|
|
937
|
-
} else {
|
|
938
|
-
callBack(parsedData.answer);
|
|
939
|
-
}
|
|
940
|
-
};
|
|
941
|
-
}
|
|
942
|
-
async function handleSaveCharacterization(translation) {
|
|
943
|
-
const conversationId = getCookie("alquimia-session");
|
|
944
|
-
if (!conversationId || !saveUserSession) return;
|
|
945
|
-
saveUserSession(conversationId, translation);
|
|
946
|
-
}
|
|
947
|
-
return {
|
|
948
|
-
activeTool,
|
|
949
|
-
cleanMessages,
|
|
950
|
-
createMessageId,
|
|
951
|
-
handleInputChange,
|
|
952
|
-
handleReplaceInput,
|
|
953
|
-
handleSubmit,
|
|
954
|
-
handleSaveCharacterization,
|
|
955
|
-
handleLoadingCancel,
|
|
956
|
-
input,
|
|
957
|
-
isLoading,
|
|
958
|
-
isMessageStreaming,
|
|
959
|
-
streamingMessageId,
|
|
960
|
-
isAudioRecording,
|
|
961
|
-
shouldShowCharacterizationButton,
|
|
962
|
-
lastRequest,
|
|
963
|
-
messageMetaData,
|
|
964
|
-
messages,
|
|
965
|
-
populateMessages,
|
|
966
|
-
processMessageChunk,
|
|
967
|
-
sendMessage,
|
|
968
|
-
sessionId,
|
|
969
|
-
setActiveTool,
|
|
970
|
-
setSessionId,
|
|
971
|
-
setLastRequest,
|
|
972
|
-
setIsAudioRecording
|
|
973
|
-
};
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
// src/hooks/useRatings.ts
|
|
977
|
-
var import_react3 = require("react");
|
|
978
|
-
var initialState2 = {
|
|
979
|
-
ratingStars: 0,
|
|
980
|
-
ratingThumbs: "",
|
|
981
|
-
ratingComment: ""
|
|
982
|
-
};
|
|
983
|
-
function ratingReducer(state, action) {
|
|
984
|
-
switch (action.type) {
|
|
985
|
-
case "SET_RATING_STARS":
|
|
986
|
-
return { ...state, ratingStars: action.payload };
|
|
987
|
-
case "SET_RATING_THUMBS":
|
|
988
|
-
return { ...state, ratingThumbs: action.payload };
|
|
989
|
-
case "SET_RATING_COMMENT":
|
|
990
|
-
return { ...state, ratingComment: action.payload };
|
|
991
|
-
default:
|
|
992
|
-
return state;
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
function useRatings({ assistantId, sendRating, topicId }) {
|
|
996
|
-
const [isLoading, setIsLoading] = (0, import_react3.useState)(false);
|
|
997
|
-
const [hasReviewed, setHasReviewed] = (0, import_react3.useState)(false);
|
|
998
|
-
const [state, dispatch] = (0, import_react3.useReducer)(ratingReducer, initialState2);
|
|
999
|
-
const setRatingStars = (rating) => {
|
|
1000
|
-
dispatch({ type: "SET_RATING_STARS", payload: rating });
|
|
1001
|
-
};
|
|
1002
|
-
const setRatingThumbs = (rating) => {
|
|
1003
|
-
dispatch({ type: "SET_RATING_THUMBS", payload: rating });
|
|
1004
|
-
};
|
|
1005
|
-
const setRatingComment = (comment) => {
|
|
1006
|
-
dispatch({ type: "SET_RATING_COMMENT", payload: comment });
|
|
1007
|
-
};
|
|
1008
|
-
const thumbsScore = (value) => {
|
|
1009
|
-
return value === "thumbsUp" ? 5 : value === "thumbsDown" ? 0 : 0;
|
|
1010
|
-
};
|
|
1011
|
-
const handleRate = async (key, value, onHandleRateSuccess) => {
|
|
1012
|
-
setIsLoading(true);
|
|
1013
|
-
const sessionId = getTopicSessionId(topicId);
|
|
1014
|
-
const ratingObj = {
|
|
1015
|
-
topicId: parseInt(topicId),
|
|
1016
|
-
sessionId: sessionId || "",
|
|
1017
|
-
assistantId,
|
|
1018
|
-
score: key === "score" ? value : thumbsScore(value),
|
|
1019
|
-
description: key === "description" ? value : state.ratingComment
|
|
1020
|
-
};
|
|
1021
|
-
try {
|
|
1022
|
-
const response = await sendRating(ratingObj);
|
|
1023
|
-
if (!response.success) {
|
|
1024
|
-
setIsLoading(false);
|
|
1025
|
-
onHandleRateSuccess(false, response.error.message);
|
|
1026
|
-
return;
|
|
1027
|
-
}
|
|
1028
|
-
if (key === "score") {
|
|
1029
|
-
setRatingStars(value);
|
|
1030
|
-
} else if (key === "description") {
|
|
1031
|
-
setRatingComment(value);
|
|
1032
|
-
}
|
|
1033
|
-
setHasReviewed(true);
|
|
1034
|
-
setIsLoading(false);
|
|
1035
|
-
onHandleRateSuccess(true);
|
|
1036
|
-
} catch (err) {
|
|
1037
|
-
setIsLoading(false);
|
|
1038
|
-
onHandleRateSuccess(false, String(err));
|
|
1039
|
-
}
|
|
1040
|
-
};
|
|
1041
|
-
return {
|
|
1042
|
-
handleRate,
|
|
1043
|
-
ratingStars: state.ratingStars,
|
|
1044
|
-
ratingThumbs: state.ratingThumbs,
|
|
1045
|
-
ratingComment: state.ratingComment,
|
|
1046
|
-
isLoading,
|
|
1047
|
-
hasReviewed
|
|
1048
|
-
};
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
// src/actions/alquimia.action.ts
|
|
1052
|
-
var import_crypto = require("crypto");
|
|
1053
|
-
var import_headers = require("next/headers");
|
|
1054
|
-
async function initConversation(reset, topicId) {
|
|
1055
|
-
const cookieStore = await (0, import_headers.cookies)();
|
|
1056
|
-
if (!topicId) {
|
|
1057
|
-
let conversationId = (0, import_crypto.randomUUID)().toString();
|
|
1058
|
-
const alquimia_session = cookieStore.get("alquimia-session");
|
|
1059
|
-
if (!alquimia_session || reset) {
|
|
1060
|
-
cookieStore.set("alquimia-session", conversationId);
|
|
1061
|
-
} else {
|
|
1062
|
-
conversationId = alquimia_session.value;
|
|
1063
|
-
}
|
|
1064
|
-
return conversationId;
|
|
1065
|
-
}
|
|
1066
|
-
let conversationsMap = {};
|
|
1067
|
-
const existingConversations = cookieStore.get("alquimia-sessions");
|
|
1068
|
-
if (existingConversations) {
|
|
1069
|
-
try {
|
|
1070
|
-
const decodedValue = decodeURIComponent(existingConversations.value);
|
|
1071
|
-
conversationsMap = JSON.parse(decodedValue);
|
|
1072
|
-
} catch (e) {
|
|
1073
|
-
console.error("Error parsing conversations cookie:", e);
|
|
1074
|
-
conversationsMap = {};
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
if (!conversationsMap[topicId] || reset) {
|
|
1078
|
-
conversationsMap[topicId] = (0, import_crypto.randomUUID)().toString();
|
|
1079
|
-
}
|
|
1080
|
-
cookieStore.set("alquimia-sessions", JSON.stringify(conversationsMap));
|
|
1081
|
-
return conversationsMap[topicId];
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
// src/actions/baseApi.action.ts
|
|
1085
|
-
async function createResource(config, payload) {
|
|
1086
|
-
try {
|
|
1087
|
-
const headers = generateHeaders(config);
|
|
1088
|
-
const response = await fetch(`${config.baseUrl}${config.route}`, {
|
|
1089
|
-
method: "POST",
|
|
1090
|
-
headers,
|
|
1091
|
-
body: JSON.stringify(payload),
|
|
1092
|
-
cache: "default"
|
|
1093
|
-
});
|
|
1094
|
-
if (!response.ok) {
|
|
1095
|
-
const error = await response.json();
|
|
1096
|
-
return {
|
|
1097
|
-
success: false,
|
|
1098
|
-
error: {
|
|
1099
|
-
message: error.message || `Server returned ${response.status}`,
|
|
1100
|
-
code: response.status.toString(),
|
|
1101
|
-
details: {
|
|
1102
|
-
status: response.status,
|
|
1103
|
-
statusText: response.statusText
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
};
|
|
1107
|
-
}
|
|
1108
|
-
return {
|
|
1109
|
-
success: true,
|
|
1110
|
-
data: await response.json()
|
|
1111
|
-
};
|
|
1112
|
-
} catch (error) {
|
|
1113
|
-
throw new Error("Failed to create resource");
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
async function readResource(config, id) {
|
|
1117
|
-
try {
|
|
1118
|
-
const headers = generateHeaders(config);
|
|
1119
|
-
const url = id ? `${config.baseUrl}${config.route}/${id}` : `${config.baseUrl}${config.route}`;
|
|
1120
|
-
const response = await fetch(url, {
|
|
1121
|
-
method: "GET",
|
|
1122
|
-
headers,
|
|
1123
|
-
cache: "default"
|
|
1124
|
-
});
|
|
1125
|
-
if (!response.ok) {
|
|
1126
|
-
const error = await response.json();
|
|
1127
|
-
return {
|
|
1128
|
-
success: false,
|
|
1129
|
-
error: {
|
|
1130
|
-
message: error.message || `Server returned ${response.status}`,
|
|
1131
|
-
code: response.status.toString(),
|
|
1132
|
-
details: {
|
|
1133
|
-
status: response.status,
|
|
1134
|
-
statusText: response.statusText
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
};
|
|
1138
|
-
}
|
|
1139
|
-
const contentType = response.headers.get("content-type");
|
|
1140
|
-
if (contentType?.includes("application/json")) {
|
|
1141
|
-
return {
|
|
1142
|
-
success: true,
|
|
1143
|
-
data: await response.json(),
|
|
1144
|
-
contentType: contentType || void 0
|
|
1145
|
-
};
|
|
1146
|
-
}
|
|
1147
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
1148
|
-
if (contentType?.includes("octet-stream") && isTextContent(arrayBuffer)) {
|
|
1149
|
-
return {
|
|
1150
|
-
success: true,
|
|
1151
|
-
data: arrayBuffer,
|
|
1152
|
-
contentType: "text/plain"
|
|
1153
|
-
};
|
|
1154
|
-
}
|
|
1155
|
-
return {
|
|
1156
|
-
success: true,
|
|
1157
|
-
data: await response.json(),
|
|
1158
|
-
contentType: contentType || void 0
|
|
1159
|
-
};
|
|
1160
|
-
} catch (error) {
|
|
1161
|
-
throw new Error("Failed to read resource");
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
async function updateResource(config, id, data) {
|
|
1165
|
-
try {
|
|
1166
|
-
const headers = generateHeaders(config);
|
|
1167
|
-
const response = await fetch(`${config.baseUrl}${config.route}/${id}`, {
|
|
1168
|
-
method: "PUT",
|
|
1169
|
-
headers,
|
|
1170
|
-
body: JSON.stringify(data),
|
|
1171
|
-
cache: "default"
|
|
1172
|
-
});
|
|
1173
|
-
if (!response.ok) {
|
|
1174
|
-
const error = await response.json();
|
|
1175
|
-
return {
|
|
1176
|
-
success: false,
|
|
1177
|
-
error: {
|
|
1178
|
-
message: error.message || `Server returned ${response.status}`,
|
|
1179
|
-
code: response.status.toString(),
|
|
1180
|
-
details: {
|
|
1181
|
-
status: response.status,
|
|
1182
|
-
statusText: response.statusText
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
};
|
|
1186
|
-
}
|
|
1187
|
-
return {
|
|
1188
|
-
success: true,
|
|
1189
|
-
data: await response.json()
|
|
1190
|
-
};
|
|
1191
|
-
} catch (error) {
|
|
1192
|
-
throw new Error("Failed to update resource");
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
async function deleteResource(config, id) {
|
|
1196
|
-
try {
|
|
1197
|
-
const headers = generateHeaders(config);
|
|
1198
|
-
const response = await fetch(`${config.baseUrl}${config.route}/${id}`, {
|
|
1199
|
-
method: "DELETE",
|
|
1200
|
-
headers,
|
|
1201
|
-
cache: "default"
|
|
1202
|
-
});
|
|
1203
|
-
if (!response.ok) {
|
|
1204
|
-
const error = await response.json();
|
|
1205
|
-
return {
|
|
1206
|
-
success: false,
|
|
1207
|
-
error: {
|
|
1208
|
-
message: error.message || `Server returned ${response.status}`,
|
|
1209
|
-
code: response.status.toString(),
|
|
1210
|
-
details: {
|
|
1211
|
-
status: response.status,
|
|
1212
|
-
statusText: response.statusText
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
};
|
|
1216
|
-
}
|
|
1217
|
-
return {
|
|
1218
|
-
success: true
|
|
1219
|
-
};
|
|
1220
|
-
} catch (error) {
|
|
1221
|
-
throw new Error("Failed to delete resource");
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
// src/types/type.ts
|
|
1226
|
-
var ToolFactory = class {
|
|
1227
|
-
constructor(toolSpec) {
|
|
1228
|
-
this.toolSpec = null;
|
|
1229
|
-
this.toolSpec = toolSpec;
|
|
1230
|
-
}
|
|
1231
|
-
static createTool(toolSpec) {
|
|
1232
|
-
return toolSpec;
|
|
1233
|
-
}
|
|
1234
|
-
};
|
|
1235
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1236
|
-
0 && (module.exports = {
|
|
1237
|
-
AlquimiaRatingsProvider,
|
|
1238
|
-
AlquimiaSDK,
|
|
1239
|
-
AlquimiaWhisperProvider,
|
|
1240
|
-
Button,
|
|
1241
|
-
Card,
|
|
1242
|
-
CharacterizationProvider,
|
|
1243
|
-
Code,
|
|
1244
|
-
ElasticLoggerProvider,
|
|
1245
|
-
ElevenLabsWhisperProvider,
|
|
1246
|
-
GenerativeProvider,
|
|
1247
|
-
LoggerProvider,
|
|
1248
|
-
OpenAIAnalyzeCharProvider,
|
|
1249
|
-
OpenAIStableDiffusionProvider,
|
|
1250
|
-
OpenAIWhisperProvider,
|
|
1251
|
-
RatingsProvider,
|
|
1252
|
-
SessionProvider,
|
|
1253
|
-
StabilityProvider,
|
|
1254
|
-
StableDiffusionProvider,
|
|
1255
|
-
ToolFactory,
|
|
1256
|
-
WhisperProvider,
|
|
1257
|
-
createMessageId,
|
|
1258
|
-
createResource,
|
|
1259
|
-
defineAssistantId,
|
|
1260
|
-
deleteResource,
|
|
1261
|
-
formatTimeWithUnit,
|
|
1262
|
-
generateHeaders,
|
|
1263
|
-
generateTranslatePrompt,
|
|
1264
|
-
getCookies,
|
|
1265
|
-
getQueryParam,
|
|
1266
|
-
getTopicSessionId,
|
|
1267
|
-
initConversation,
|
|
1268
|
-
isTextContent,
|
|
1269
|
-
parseConversationsMapCookie,
|
|
1270
|
-
readResource,
|
|
1271
|
-
serializeAxiosError,
|
|
1272
|
-
updateResource,
|
|
1273
|
-
useAlquimia,
|
|
1274
|
-
useRatings,
|
|
1275
|
-
useSessionContext
|
|
1276
|
-
});
|
|
1277
|
-
//# sourceMappingURL=index.js.map
|