@pablo2410/core-server 0.6.1 → 0.7.0

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/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createSubdomainAuth
3
- } from "./chunk-LH6QZJM4.js";
3
+ } from "./chunk-B63ROBSD.js";
4
4
  import {
5
5
  createHierarchyService
6
6
  } from "./chunk-FSR7KF23.js";
@@ -22,56 +22,6 @@ var SQDCP_PILLAR_LABELS = {
22
22
  people: "People"
23
23
  };
24
24
 
25
- // src/dataApi.ts
26
- function createDataApiClient(env) {
27
- return async function callDataApi(apiId, options = {}) {
28
- if (!env.forgeApiUrl) {
29
- throw new Error("BUILT_IN_FORGE_API_URL is not configured");
30
- }
31
- if (!env.forgeApiKey) {
32
- throw new Error("BUILT_IN_FORGE_API_KEY is not configured");
33
- }
34
- const baseUrl = env.forgeApiUrl.endsWith("/") ? env.forgeApiUrl : `${env.forgeApiUrl}/`;
35
- const fullUrl = new URL(
36
- "webdevtoken.v1.WebDevService/CallApi",
37
- baseUrl
38
- ).toString();
39
- const response = await fetch(fullUrl, {
40
- method: "POST",
41
- headers: {
42
- accept: "application/json",
43
- "content-type": "application/json",
44
- "connect-protocol-version": "1",
45
- authorization: `Bearer ${env.forgeApiKey}`
46
- },
47
- body: JSON.stringify({
48
- apiId,
49
- query: options.query,
50
- body: options.body,
51
- path_params: options.pathParams,
52
- multipart_form_data: options.formData
53
- })
54
- });
55
- if (!response.ok) {
56
- const detail = await response.text().catch(() => "");
57
- throw new Error(
58
- `Data API request failed (${response.status} ${response.statusText})${detail ? `: ${detail}` : ""}`
59
- );
60
- }
61
- const payload = await response.json().catch(() => ({}));
62
- if (payload && typeof payload === "object" && "jsonData" in payload) {
63
- try {
64
- return JSON.parse(
65
- payload.jsonData ?? "{}"
66
- );
67
- } catch {
68
- return payload.jsonData;
69
- }
70
- }
71
- return payload;
72
- };
73
- }
74
-
75
25
  // src/metering.ts
76
26
  var DEFAULT_COST_RATE = {
77
27
  inputPer1k: 75e-6,
@@ -283,280 +233,6 @@ function createLLMClient(env, options = {}) {
283
233
  };
284
234
  }
285
235
 
286
- // src/imageGeneration.ts
287
- function createImageGenerator(env, storagePut) {
288
- return async function generateImage(options) {
289
- if (!env.forgeApiUrl) {
290
- throw new Error("BUILT_IN_FORGE_API_URL is not configured");
291
- }
292
- if (!env.forgeApiKey) {
293
- throw new Error("BUILT_IN_FORGE_API_KEY is not configured");
294
- }
295
- const baseUrl = env.forgeApiUrl.endsWith("/") ? env.forgeApiUrl : `${env.forgeApiUrl}/`;
296
- const fullUrl = new URL(
297
- "images.v1.ImageService/GenerateImage",
298
- baseUrl
299
- ).toString();
300
- const response = await fetch(fullUrl, {
301
- method: "POST",
302
- headers: {
303
- accept: "application/json",
304
- "content-type": "application/json",
305
- "connect-protocol-version": "1",
306
- authorization: `Bearer ${env.forgeApiKey}`
307
- },
308
- body: JSON.stringify({
309
- prompt: options.prompt,
310
- original_images: options.originalImages || []
311
- })
312
- });
313
- if (!response.ok) {
314
- const detail = await response.text().catch(() => "");
315
- throw new Error(
316
- `Image generation request failed (${response.status} ${response.statusText})${detail ? `: ${detail}` : ""}`
317
- );
318
- }
319
- const result = await response.json();
320
- const base64Data = result.image.b64Json;
321
- const buffer = Buffer.from(base64Data, "base64");
322
- const { url } = await storagePut(
323
- `generated/${Date.now()}.png`,
324
- buffer,
325
- result.image.mimeType
326
- );
327
- return { url };
328
- };
329
- }
330
-
331
- // src/map.ts
332
- function createMapClient(env) {
333
- return async function makeRequest(endpoint, params = {}) {
334
- if (!env.forgeApiUrl) {
335
- throw new Error("BUILT_IN_FORGE_API_URL is not configured");
336
- }
337
- if (!env.forgeApiKey) {
338
- throw new Error("BUILT_IN_FORGE_API_KEY is not configured");
339
- }
340
- const baseUrl = env.forgeApiUrl.endsWith("/") ? env.forgeApiUrl : `${env.forgeApiUrl}/`;
341
- const proxyUrl = new URL(
342
- "webdevtoken.v1.WebDevService/GoogleMapsProxy",
343
- baseUrl
344
- ).toString();
345
- const processedParams = {};
346
- for (const [key, value] of Object.entries(params)) {
347
- if (value === void 0) continue;
348
- if (Array.isArray(value)) {
349
- processedParams[key] = value.join("|");
350
- } else {
351
- processedParams[key] = String(value);
352
- }
353
- }
354
- const response = await fetch(proxyUrl, {
355
- method: "POST",
356
- headers: {
357
- accept: "application/json",
358
- "content-type": "application/json",
359
- "connect-protocol-version": "1",
360
- authorization: `Bearer ${env.forgeApiKey}`
361
- },
362
- body: JSON.stringify({
363
- endpoint,
364
- params: processedParams
365
- })
366
- });
367
- if (!response.ok) {
368
- const detail = await response.text().catch(() => "");
369
- throw new Error(
370
- `Maps API request failed (${response.status} ${response.statusText})${detail ? `: ${detail}` : ""}`
371
- );
372
- }
373
- const wrapper = await response.json();
374
- if (wrapper.jsonData) {
375
- try {
376
- return JSON.parse(wrapper.jsonData);
377
- } catch {
378
- return wrapper.jsonData;
379
- }
380
- }
381
- return wrapper;
382
- };
383
- }
384
-
385
- // src/notification.ts
386
- var TITLE_MAX_LENGTH = 1200;
387
- var CONTENT_MAX_LENGTH = 2e4;
388
- function createNotificationClient(env) {
389
- return async function notifyOwner(payload) {
390
- if (!env.forgeApiUrl) {
391
- throw new Error("BUILT_IN_FORGE_API_URL is not configured");
392
- }
393
- if (!env.forgeApiKey) {
394
- throw new Error("BUILT_IN_FORGE_API_KEY is not configured");
395
- }
396
- const title = payload.title.length > TITLE_MAX_LENGTH ? payload.title.slice(0, TITLE_MAX_LENGTH) : payload.title;
397
- const content = payload.content.length > CONTENT_MAX_LENGTH ? payload.content.slice(0, CONTENT_MAX_LENGTH) : payload.content;
398
- const baseUrl = env.forgeApiUrl.endsWith("/") ? env.forgeApiUrl : `${env.forgeApiUrl}/`;
399
- const fullUrl = new URL(
400
- "webdevtoken.v1.WebDevService/NotifyOwner",
401
- baseUrl
402
- ).toString();
403
- try {
404
- const response = await fetch(fullUrl, {
405
- method: "POST",
406
- headers: {
407
- accept: "application/json",
408
- "content-type": "application/json",
409
- "connect-protocol-version": "1",
410
- authorization: `Bearer ${env.forgeApiKey}`
411
- },
412
- body: JSON.stringify({ title, content })
413
- });
414
- if (!response.ok) {
415
- console.error(
416
- `Notification failed: ${response.status} ${response.statusText}`
417
- );
418
- return false;
419
- }
420
- return true;
421
- } catch (error) {
422
- console.error("Notification error:", error);
423
- return false;
424
- }
425
- };
426
- }
427
-
428
- // src/voiceTranscription.ts
429
- var SUPPORTED_MIME_TYPES = [
430
- "audio/webm",
431
- "audio/mp3",
432
- "audio/mpeg",
433
- "audio/wav",
434
- "audio/wave",
435
- "audio/ogg",
436
- "audio/m4a",
437
- "audio/mp4"
438
- ];
439
- function getFileExtension(mimeType) {
440
- const mimeToExt = {
441
- "audio/webm": "webm",
442
- "audio/mp3": "mp3",
443
- "audio/mpeg": "mp3",
444
- "audio/wav": "wav",
445
- "audio/wave": "wav",
446
- "audio/ogg": "ogg",
447
- "audio/m4a": "m4a",
448
- "audio/mp4": "m4a"
449
- };
450
- return mimeToExt[mimeType] || "audio";
451
- }
452
- function getLanguageName(langCode) {
453
- const langMap = {
454
- en: "English",
455
- es: "Spanish",
456
- fr: "French",
457
- de: "German",
458
- it: "Italian",
459
- pt: "Portuguese",
460
- ru: "Russian",
461
- ja: "Japanese",
462
- ko: "Korean",
463
- zh: "Chinese",
464
- ar: "Arabic",
465
- hi: "Hindi",
466
- nl: "Dutch",
467
- pl: "Polish",
468
- tr: "Turkish",
469
- sv: "Swedish",
470
- da: "Danish",
471
- no: "Norwegian",
472
- fi: "Finnish"
473
- };
474
- return langMap[langCode] || langCode;
475
- }
476
- function createTranscriptionClient(env) {
477
- return async function transcribeAudio(options) {
478
- try {
479
- if (!env.forgeApiUrl) {
480
- throw new Error("BUILT_IN_FORGE_API_URL is not configured");
481
- }
482
- if (!env.forgeApiKey) {
483
- throw new Error("BUILT_IN_FORGE_API_KEY is not configured");
484
- }
485
- const audioResponse = await fetch(options.audioUrl);
486
- if (!audioResponse.ok) {
487
- return {
488
- error: "Failed to fetch audio file",
489
- code: "FETCH_FAILED",
490
- details: `HTTP ${audioResponse.status} ${audioResponse.statusText}`
491
- };
492
- }
493
- const contentType = audioResponse.headers.get("content-type") || "audio/webm";
494
- const mimeType = contentType.split(";")[0].trim();
495
- if (!SUPPORTED_MIME_TYPES.includes(
496
- mimeType
497
- )) {
498
- return {
499
- error: "Unsupported audio format",
500
- code: "UNSUPPORTED_FORMAT",
501
- details: `MIME type '${mimeType}' is not supported. Supported: ${SUPPORTED_MIME_TYPES.join(", ")}`
502
- };
503
- }
504
- const audioBuffer = await audioResponse.arrayBuffer();
505
- const sizeMB = audioBuffer.byteLength / (1024 * 1024);
506
- if (sizeMB > 16) {
507
- return {
508
- error: "Audio file exceeds maximum size limit",
509
- code: "FILE_TOO_LARGE",
510
- details: `File size is ${sizeMB.toFixed(2)}MB, maximum allowed is 16MB`
511
- };
512
- }
513
- const formData = new FormData();
514
- const filename = `audio.${getFileExtension(mimeType)}`;
515
- const audioBlob = new Blob([new Uint8Array(audioBuffer)], {
516
- type: mimeType
517
- });
518
- formData.append("file", audioBlob, filename);
519
- formData.append("model", "whisper-1");
520
- formData.append("response_format", "verbose_json");
521
- const prompt = options.prompt || (options.language ? `Transcribe the user's voice to text, the user's working language is ${getLanguageName(options.language)}` : "Transcribe the user's voice to text");
522
- formData.append("prompt", prompt);
523
- const baseUrl = env.forgeApiUrl.endsWith("/") ? env.forgeApiUrl : `${env.forgeApiUrl}/`;
524
- const fullUrl = new URL("v1/audio/transcriptions", baseUrl).toString();
525
- const response = await fetch(fullUrl, {
526
- method: "POST",
527
- headers: {
528
- authorization: `Bearer ${env.forgeApiKey}`,
529
- "Accept-Encoding": "identity"
530
- },
531
- body: formData
532
- });
533
- if (!response.ok) {
534
- const errorText = await response.text().catch(() => "");
535
- return {
536
- error: "Transcription service request failed",
537
- code: "TRANSCRIPTION_FAILED",
538
- details: `${response.status} ${response.statusText}${errorText ? `: ${errorText}` : ""}`
539
- };
540
- }
541
- const whisperResponse = await response.json();
542
- if (!whisperResponse.text || typeof whisperResponse.text !== "string") {
543
- return {
544
- error: "Invalid transcription response",
545
- code: "SERVICE_ERROR",
546
- details: "Transcription service returned an invalid response format"
547
- };
548
- }
549
- return whisperResponse;
550
- } catch (error) {
551
- return {
552
- error: "Voice transcription failed",
553
- code: "SERVICE_ERROR",
554
- details: error instanceof Error ? error.message : "An unexpected error occurred"
555
- };
556
- }
557
- };
558
- }
559
-
560
236
  // src/ai/personas.ts
561
237
  var BASE_PERSONA = `
562
238
  You are the Oplytics AI assistant \u2014 a knowledgeable, friendly guide to the Oplytics operational-excellence platform.
@@ -872,16 +548,11 @@ export {
872
548
  SQDCP_PILLAR_LABELS,
873
549
  buildSystemPrompt,
874
550
  computeCostUsd,
875
- createDataApiClient,
876
551
  createHierarchyService,
877
- createImageGenerator,
878
552
  createLLMClient,
879
- createMapClient,
880
- createNotificationClient,
881
553
  createStaticRetriever,
882
554
  createSubdomainAuth,
883
555
  createSupportEngine,
884
- createTranscriptionClient,
885
556
  estimateMessageTokens,
886
557
  estimateTokens,
887
558
  formatKnowledge