@lyxa.ai/core 1.4.280 → 1.4.282

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.
Files changed (32) hide show
  1. package/dist/index.js +3 -3
  2. package/dist/index.js.map +1 -1
  3. package/dist/libraries/index.d.ts +2 -2
  4. package/dist/libraries/index.js +3 -3
  5. package/dist/libraries/index.js.map +1 -1
  6. package/dist/libraries/llm/interfaces/common-llm-interfaces.d.ts +23 -0
  7. package/dist/libraries/{transliteration/interfaces/common-transliteration.js → llm/interfaces/common-llm-interfaces.js} +1 -1
  8. package/dist/libraries/llm/interfaces/common-llm-interfaces.js.map +1 -0
  9. package/dist/libraries/llm/llm-provider-service.d.ts +13 -0
  10. package/dist/libraries/{transliteration/transliteration-service.js → llm/llm-provider-service.js} +17 -22
  11. package/dist/libraries/llm/llm-provider-service.js.map +1 -0
  12. package/dist/libraries/llm/providers/openai-provider.d.ts +14 -0
  13. package/dist/libraries/llm/providers/openai-provider.js +166 -0
  14. package/dist/libraries/llm/providers/openai-provider.js.map +1 -0
  15. package/dist/libraries/mongo/models/spend-to-get-history.model.d.ts +1 -1
  16. package/dist/libraries/mongo/models/spend-to-get-history.model.js +4 -4
  17. package/dist/libraries/mongo/models/spend-to-get-history.model.js.map +1 -1
  18. package/dist/libraries/trpc/middlewares/auth.d.ts +1 -1
  19. package/dist/libraries/trpc/middlewares/createRoleProtectedProcedure.d.ts +1 -1
  20. package/dist/libraries/trpc/middlewares/phone-verified.d.ts +1 -1
  21. package/dist/libraries/trpc/middlewares/publicUserDecoder.d.ts +1 -1
  22. package/dist/types/README.md +1 -1
  23. package/dist/types/package.json +1 -1
  24. package/dist/types/utilities/validation/common-validation.d.ts +12 -12
  25. package/package.json +1 -1
  26. package/dist/libraries/transliteration/interfaces/common-transliteration.d.ts +0 -19
  27. package/dist/libraries/transliteration/interfaces/common-transliteration.js.map +0 -1
  28. package/dist/libraries/transliteration/providers/openai-provider.d.ts +0 -10
  29. package/dist/libraries/transliteration/providers/openai-provider.js +0 -85
  30. package/dist/libraries/transliteration/providers/openai-provider.js.map +0 -1
  31. package/dist/libraries/transliteration/transliteration-service.d.ts +0 -14
  32. package/dist/libraries/transliteration/transliteration-service.js.map +0 -1
package/dist/index.js CHANGED
@@ -68,7 +68,7 @@ const lyxa_fcm_service_1 = require("./libraries/notification/lyxa-fcm.service");
68
68
  const lyxa_fcm_sender_1 = require("./libraries/notification/lyxa-fcm-sender");
69
69
  const firebase_message_builder_1 = require("./libraries/notification/firebase-message.builder");
70
70
  const google_translate_1 = require("./libraries/google-translate");
71
- const transliteration_service_1 = require("./libraries/transliteration/transliteration-service");
71
+ const llm_provider_service_1 = require("./libraries/llm/llm-provider-service");
72
72
  var EnvironmentConfigurationType_2 = require("./libraries/configuration/types/EnvironmentConfigurationType");
73
73
  Object.defineProperty(exports, "EnvironmentConfigurationType", { enumerable: true, get: function () { return EnvironmentConfigurationType_2.EnvironmentConfigurationType; } });
74
74
  var mongo_2 = require("./libraries/mongo");
@@ -125,8 +125,8 @@ async function registerLibraries(options) {
125
125
  typedi_1.Container.set(dispatcher_1.MicroServiceDispatcher, microserviceDispatcherInstance);
126
126
  const twilioServiceInstance = new twilio_1.TwilioService();
127
127
  typedi_1.Container.set(twilio_1.TwilioService, twilioServiceInstance);
128
- const transliterationService = new transliteration_service_1.TransliterationService(transliteration_service_1.TransliterationProvider.OPENAI);
129
- typedi_1.Container.set(transliteration_service_1.TransliterationService, transliterationService);
128
+ const llmCompletionService = new llm_provider_service_1.LLMCompletionService(llm_provider_service_1.LLMProvider.OPENAI);
129
+ typedi_1.Container.set(llm_provider_service_1.LLMCompletionService, llmCompletionService);
130
130
  const googleMapsKey = await getLibraries().getSecretsService().getKey('GOOGLE_MAPS_API_KEY');
131
131
  const googleMapService = new map_1.GoogleMapsService(redisInstance, googleMapsKey);
132
132
  const osrmMapService = new osrm_1.OsrmMapService();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":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BAAwB,CAAC,CAAC;YACnD,oBAAoB,CAAC,GAAG,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;QACvD,CAAC;QAED,MAAM,IAAA,wBAAgB,EAAC,OAAO,EAAE,KAAK,EAAC,OAAO,EAAC,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACjF,CAAC;AACF,CAAC;AAED,SAAgB,YAAY;IAC3B,OAAO,kBAAS,CAAC,GAAG,CAAC,0BAAc,CAAC,CAAC;AACtC,CAAC","sourcesContent":["// Apply the soft delete plugin globally before any connections or models\nimport { applySoftDeletePlugin } from './libraries/mongo/plugins/soft-delete-plugin';\n\napplySoftDeletePlugin();\n\nimport { LibraryManager } from './libraries';\nimport { Container } from 'typedi';\nimport { ConfigurationOptions, ConfigurationService } from './libraries/configuration';\nimport { LyxaLogger } from './libraries/logger';\nimport { RedisService } from './libraries/redis';\nimport { initGlobalConnection, initLyxaMongoDbConnection } from './libraries/mongo';\nimport { SecretManagerService } from './libraries/secrets';\nimport { MicroServiceDispatcher } from './libraries/dispatcher';\nimport { TwilioService } from './libraries/twilio';\nimport { FirebaseService } from './libraries/firebase';\nimport { initRabbitMQConnection, subscribeToEvent } from './libraries/event';\nimport { SubscriptionRegistry } from './libraries/event/registry/SubscriptionRegistry';\nimport { GoogleMapsService, MapService } from './libraries/map';\nimport { CachedSettingsService } from './libraries/cache/settings';\nimport { FirebaseFcmService } from './libraries/notification/firebase-fcm.service';\nimport { BullMQService } from './libraries/bullmq/bull-mq-service';\nimport { BOBSecrets, BOBService, CashSettlementService } from './libraries/cash-settlement';\nimport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\nimport { OsrmMapService } from './libraries/map/providers/osrm';\nimport { RabbitMQUrlMap } from './utilities/environment/rabbitmq-environments';\nimport { disconnectAllEntitiesFromInstance } from './libraries/socket/connections/instance-disconnect';\nimport { LyxaLoggerKit } from './libraries/logger-kit';\nimport { LyxaFcmService } from './libraries/notification/lyxa-fcm.service';\nimport { LyxaFcmSender } from './libraries/notification/lyxa-fcm-sender';\nimport { FirebaseMessageBuilderFactory } from './libraries/notification/firebase-message.builder';\nimport { GoogleTranslateService } from './libraries/google-translate';\nimport { TransliterationProvider, TransliterationService } from './libraries/transliteration/transliteration-service';\n\nexport { ConfigurationOptions } from './libraries/configuration';\nexport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\nexport { initGlobalConnection } from './libraries/mongo';\nexport * from './libraries/google-translate';\n\nexport async function bootstrapCore(options?: ConfigurationOptions) {\n\ttry {\n\t\tawait registerLibraries(options);\n\t\tgetLibraries().getLogger().logger.info('Successfully bootstrapped lyxa-core.');\n\n\t\tconst gracefulShutdown = async () => {\n\t\t\tgetLibraries().getLogger().logger.info('Received shutdown signal, shutting down gracefully...');\n\t\t\tif (options?.instanceType == 'socket') await disconnectAllEntitiesFromInstance();\n\t\t\tprocess.exit();\n\t\t};\n\n\t\tprocess.on('SIGTERM', gracefulShutdown);\n\t\tprocess.on('SIGINT', gracefulShutdown);\n\t\tprocess.on('uncaughtException', err => {\n\t\t\tconsole.log('err', err);\n\t\t\tgetLibraries().getLogger().logger.error('Uncaught exception, shutting down...', err);\n\t\t\tgracefulShutdown();\n\t\t});\n\t\tprocess.on('exit', code => {\n\t\t\tgetLibraries().getLogger().logger.info(`Exiting with code: ${code}`);\n\t\t});\n\n\t\tconsole.log('Created hooks.');\n\t} catch (e) {\n\t\tconsole.error(e);\n\t}\n}\n\nexport async function registerLibraries(options?: ConfigurationOptions) {\n\t// Setup configuration.\n\tconst configurationInstance = new ConfigurationService(options);\n\tContainer.set(ConfigurationService, configurationInstance);\n\n\t// Setup redis.\n\tconst redisInstance = new RedisService(configurationInstance.redisURL);\n\tContainer.set(RedisService, redisInstance);\n\n\t// Setup secret\n\tconst secretInstance = new SecretManagerService(configurationInstance, redisInstance);\n\tContainer.set(SecretManagerService, secretInstance);\n\n\t// Setup BullMQ\n\tconst bullMQInstance = new BullMQService(redisInstance);\n\tContainer.set(BullMQService, bullMQInstance);\n\n\tconst mongoUrl = options?.mongoDbUrl\n\t\t? options.mongoDbUrl\n\t\t: await getLibraries().getSecretsService().getKey('MONGO_URL');\n\n\tawait initLyxaMongoDbConnection(mongoUrl!, options);\n\tawait initGlobalConnection(mongoUrl!, options!.environment);\n\n\tconst loggerInstance = new LyxaLogger(options!.instanceType!, mongoUrl!);\n\tContainer.set(LyxaLogger, loggerInstance);\n\n\tconst loggerKit = new LyxaLoggerKit({ instanceType: options!.instanceType! });\n\tContainer.set(LyxaLoggerKit, loggerKit);\n\n\t// Setup firebase\n\tconst firebaseInstance = new FirebaseService(configurationInstance!);\n\tContainer.set(FirebaseService, firebaseInstance);\n\n\t//Setup google translate\n\tContainer.set(GoogleTranslateService, Container.get(GoogleTranslateService));\n\n\t// Setup microservice dispatcher\n\tconst microserviceDispatcherInstance = new MicroServiceDispatcher(secretInstance);\n\tContainer.set(MicroServiceDispatcher, microserviceDispatcherInstance);\n\n\t// Setup twilio\n\tconst twilioServiceInstance = new TwilioService();\n\tContainer.set(TwilioService, twilioServiceInstance);\n\n\t// Setup Transliteration service\n\tconst transliterationService = new TransliterationService(TransliterationProvider.OPENAI);\n\tContainer.set(TransliterationService, transliterationService);\n\n\t// Setup map service\n\tconst googleMapsKey = await getLibraries().getSecretsService().getKey('GOOGLE_MAPS_API_KEY');\n\tconst googleMapService = new GoogleMapsService(redisInstance, googleMapsKey as string);\n\tconst osrmMapService = new OsrmMapService();\n\tconst mapServiceInstance = new MapService(googleMapService, osrmMapService);\n\tContainer.set(MapService, mapServiceInstance);\n\n\t// Setup cash settlement service\n\tconst bobUsername = await getLibraries().getSecretsService().getKey('BOB_USER_NAME');\n\tconst bobPassword = await getLibraries().getSecretsService().getKey('BOB_PASSWORD');\n\tconst bobURL = await getLibraries().getSecretsService().getKey('BOB_URL');\n\n\tconst bobService = new BOBService({\n\t\tBOB_USER_NAME: bobUsername,\n\t\tBOB_PASSWORD: bobPassword,\n\t\tBOB_URL: bobURL,\n\t} as BOBSecrets);\n\tconst cashSettlementServiceInstance = new CashSettlementService(bobService);\n\tContainer.set(CashSettlementService, cashSettlementServiceInstance);\n\tContainer.set(BOBService, bobService);\n\n\tconst settingsServiceInstance = new CachedSettingsService(redisInstance);\n\tContainer.set(CachedSettingsService, settingsServiceInstance);\n\n\ttry {\n\t\tconst settings = await settingsServiceInstance.getSettings();\n\t\tconst { _setTimezone } = await import('./utilities/dayjs/dayjs');\n\t\t_setTimezone(settings?.timezone || 'Asia/Beirut');\n\t\tconsole.log('Timezone initialized:', settings?.timezone || 'Asia/Beirut');\n\t} catch (error) {\n\t\tconsole.error('Failed to initialize timezone:', error);\n\t}\n\n\t// Setup fcm service\n\tconst fcmService = new FirebaseFcmService();\n\tconst builder = new FirebaseMessageBuilderFactory();\n\tconst lyxaFcmSender = new LyxaFcmSender(fcmService, builder);\n\tconst lyxaFcmService = new LyxaFcmService(lyxaFcmSender);\n\n\tContainer.set(FirebaseFcmService, fcmService);\n\tContainer.set(LyxaFcmService, lyxaFcmService);\n\n\tconsole.log('Initialized everything');\n\n\tawait initRabbitMQConnection(RabbitMQUrlMap[options?.environment ?? EnvironmentConfigurationType.DEV]);\n\n\tconst allSubscriptions = SubscriptionRegistry.getAllSubscriptions();\n\n\tconst instantiatedServices = new Map<Function, any>();\n\n\tfor (const { eventId, targetConstructor, methodName } of allSubscriptions) {\n\t\tlet instance = instantiatedServices.get(targetConstructor);\n\t\tif (!instance) {\n\t\t\tinstance = Container.get(targetConstructor as any);\n\t\t\tinstantiatedServices.set(targetConstructor, instance);\n\t\t}\n\n\t\tawait subscribeToEvent(eventId, async payload => instance[methodName](payload));\n\t}\n}\n\nexport function getLibraries(): LibraryManager {\n\treturn Container.get(LibraryManager);\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA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;QAED,MAAM,IAAA,wBAAgB,EAAC,OAAO,EAAE,KAAK,EAAC,OAAO,EAAC,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACjF,CAAC;AACF,CAAC;AAED,SAAgB,YAAY;IAC3B,OAAO,kBAAS,CAAC,GAAG,CAAC,0BAAc,CAAC,CAAC;AACtC,CAAC","sourcesContent":["// Apply the soft delete plugin globally before any connections or models\nimport { applySoftDeletePlugin } from './libraries/mongo/plugins/soft-delete-plugin';\n\napplySoftDeletePlugin();\n\nimport { LibraryManager } from './libraries';\nimport { Container } from 'typedi';\nimport { ConfigurationOptions, ConfigurationService } from './libraries/configuration';\nimport { LyxaLogger } from './libraries/logger';\nimport { RedisService } from './libraries/redis';\nimport { initGlobalConnection, initLyxaMongoDbConnection } from './libraries/mongo';\nimport { SecretManagerService } from './libraries/secrets';\nimport { MicroServiceDispatcher } from './libraries/dispatcher';\nimport { TwilioService } from './libraries/twilio';\nimport { FirebaseService } from './libraries/firebase';\nimport { initRabbitMQConnection, subscribeToEvent } from './libraries/event';\nimport { SubscriptionRegistry } from './libraries/event/registry/SubscriptionRegistry';\nimport { GoogleMapsService, MapService } from './libraries/map';\nimport { CachedSettingsService } from './libraries/cache/settings';\nimport { FirebaseFcmService } from './libraries/notification/firebase-fcm.service';\nimport { BullMQService } from './libraries/bullmq/bull-mq-service';\nimport { BOBSecrets, BOBService, CashSettlementService } from './libraries/cash-settlement';\nimport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\nimport { OsrmMapService } from './libraries/map/providers/osrm';\nimport { RabbitMQUrlMap } from './utilities/environment/rabbitmq-environments';\nimport { disconnectAllEntitiesFromInstance } from './libraries/socket/connections/instance-disconnect';\nimport { LyxaLoggerKit } from './libraries/logger-kit';\nimport { LyxaFcmService } from './libraries/notification/lyxa-fcm.service';\nimport { LyxaFcmSender } from './libraries/notification/lyxa-fcm-sender';\nimport { FirebaseMessageBuilderFactory } from './libraries/notification/firebase-message.builder';\nimport { GoogleTranslateService } from './libraries/google-translate';\nimport { LLMCompletionService, LLMProvider } from './libraries/llm/llm-provider-service';\n\nexport { ConfigurationOptions } from './libraries/configuration';\nexport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\nexport { initGlobalConnection } from './libraries/mongo';\nexport * from './libraries/google-translate';\n\nexport async function bootstrapCore(options?: ConfigurationOptions) {\n\ttry {\n\t\tawait registerLibraries(options);\n\t\tgetLibraries().getLogger().logger.info('Successfully bootstrapped lyxa-core.');\n\n\t\tconst gracefulShutdown = async () => {\n\t\t\tgetLibraries().getLogger().logger.info('Received shutdown signal, shutting down gracefully...');\n\t\t\tif (options?.instanceType == 'socket') await disconnectAllEntitiesFromInstance();\n\t\t\tprocess.exit();\n\t\t};\n\n\t\tprocess.on('SIGTERM', gracefulShutdown);\n\t\tprocess.on('SIGINT', gracefulShutdown);\n\t\tprocess.on('uncaughtException', err => {\n\t\t\tconsole.log('err', err);\n\t\t\tgetLibraries().getLogger().logger.error('Uncaught exception, shutting down...', err);\n\t\t\tgracefulShutdown();\n\t\t});\n\t\tprocess.on('exit', code => {\n\t\t\tgetLibraries().getLogger().logger.info(`Exiting with code: ${code}`);\n\t\t});\n\n\t\tconsole.log('Created hooks.');\n\t} catch (e) {\n\t\tconsole.error(e);\n\t}\n}\n\nexport async function registerLibraries(options?: ConfigurationOptions) {\n\t// Setup configuration.\n\tconst configurationInstance = new ConfigurationService(options);\n\tContainer.set(ConfigurationService, configurationInstance);\n\n\t// Setup redis.\n\tconst redisInstance = new RedisService(configurationInstance.redisURL);\n\tContainer.set(RedisService, redisInstance);\n\n\t// Setup secret\n\tconst secretInstance = new SecretManagerService(configurationInstance, redisInstance);\n\tContainer.set(SecretManagerService, secretInstance);\n\n\t// Setup BullMQ\n\tconst bullMQInstance = new BullMQService(redisInstance);\n\tContainer.set(BullMQService, bullMQInstance);\n\n\tconst mongoUrl = options?.mongoDbUrl\n\t\t? options.mongoDbUrl\n\t\t: await getLibraries().getSecretsService().getKey('MONGO_URL');\n\n\tawait initLyxaMongoDbConnection(mongoUrl!, options);\n\tawait initGlobalConnection(mongoUrl!, options!.environment);\n\n\tconst loggerInstance = new LyxaLogger(options!.instanceType!, mongoUrl!);\n\tContainer.set(LyxaLogger, loggerInstance);\n\n\tconst loggerKit = new LyxaLoggerKit({ instanceType: options!.instanceType! });\n\tContainer.set(LyxaLoggerKit, loggerKit);\n\n\t// Setup firebase\n\tconst firebaseInstance = new FirebaseService(configurationInstance!);\n\tContainer.set(FirebaseService, firebaseInstance);\n\n\t//Setup google translate\n\tContainer.set(GoogleTranslateService, Container.get(GoogleTranslateService));\n\n\t// Setup microservice dispatcher\n\tconst microserviceDispatcherInstance = new MicroServiceDispatcher(secretInstance);\n\tContainer.set(MicroServiceDispatcher, microserviceDispatcherInstance);\n\n\t// Setup twilio\n\tconst twilioServiceInstance = new TwilioService();\n\tContainer.set(TwilioService, twilioServiceInstance);\n\n\t// Setup LLM service\n\tconst llmCompletionService = new LLMCompletionService(LLMProvider.OPENAI);\n\tContainer.set(LLMCompletionService, llmCompletionService);\n\n\t// Setup map service\n\tconst googleMapsKey = await getLibraries().getSecretsService().getKey('GOOGLE_MAPS_API_KEY');\n\tconst googleMapService = new GoogleMapsService(redisInstance, googleMapsKey as string);\n\tconst osrmMapService = new OsrmMapService();\n\tconst mapServiceInstance = new MapService(googleMapService, osrmMapService);\n\tContainer.set(MapService, mapServiceInstance);\n\n\t// Setup cash settlement service\n\tconst bobUsername = await getLibraries().getSecretsService().getKey('BOB_USER_NAME');\n\tconst bobPassword = await getLibraries().getSecretsService().getKey('BOB_PASSWORD');\n\tconst bobURL = await getLibraries().getSecretsService().getKey('BOB_URL');\n\n\tconst bobService = new BOBService({\n\t\tBOB_USER_NAME: bobUsername,\n\t\tBOB_PASSWORD: bobPassword,\n\t\tBOB_URL: bobURL,\n\t} as BOBSecrets);\n\tconst cashSettlementServiceInstance = new CashSettlementService(bobService);\n\tContainer.set(CashSettlementService, cashSettlementServiceInstance);\n\tContainer.set(BOBService, bobService);\n\n\tconst settingsServiceInstance = new CachedSettingsService(redisInstance);\n\tContainer.set(CachedSettingsService, settingsServiceInstance);\n\n\ttry {\n\t\tconst settings = await settingsServiceInstance.getSettings();\n\t\tconst { _setTimezone } = await import('./utilities/dayjs/dayjs');\n\t\t_setTimezone(settings?.timezone || 'Asia/Beirut');\n\t\tconsole.log('Timezone initialized:', settings?.timezone || 'Asia/Beirut');\n\t} catch (error) {\n\t\tconsole.error('Failed to initialize timezone:', error);\n\t}\n\n\t// Setup fcm service\n\tconst fcmService = new FirebaseFcmService();\n\tconst builder = new FirebaseMessageBuilderFactory();\n\tconst lyxaFcmSender = new LyxaFcmSender(fcmService, builder);\n\tconst lyxaFcmService = new LyxaFcmService(lyxaFcmSender);\n\n\tContainer.set(FirebaseFcmService, fcmService);\n\tContainer.set(LyxaFcmService, lyxaFcmService);\n\n\tconsole.log('Initialized everything');\n\n\tawait initRabbitMQConnection(RabbitMQUrlMap[options?.environment ?? EnvironmentConfigurationType.DEV]);\n\n\tconst allSubscriptions = SubscriptionRegistry.getAllSubscriptions();\n\n\tconst instantiatedServices = new Map<Function, any>();\n\n\tfor (const { eventId, targetConstructor, methodName } of allSubscriptions) {\n\t\tlet instance = instantiatedServices.get(targetConstructor);\n\t\tif (!instance) {\n\t\t\tinstance = Container.get(targetConstructor as any);\n\t\t\tinstantiatedServices.set(targetConstructor, instance);\n\t\t}\n\n\t\tawait subscribeToEvent(eventId, async payload => instance[methodName](payload));\n\t}\n}\n\nexport function getLibraries(): LibraryManager {\n\treturn Container.get(LibraryManager);\n}\n"]}
@@ -16,7 +16,7 @@ import { LyxaLoggerKit } from './logger-kit';
16
16
  import { ICloudStorage, StorageProvider } from './cloud-storage';
17
17
  import { LyxaFcmService } from './notification/lyxa-fcm.service';
18
18
  import { GoogleTranslateService } from './google-translate';
19
- import { TransliterationService } from './transliteration/transliteration-service';
19
+ import { LLMCompletionService } from './llm/llm-provider-service';
20
20
  export declare class LibraryManager {
21
21
  getLogger(): LyxaLogger;
22
22
  getGoogleTranslateService(): GoogleTranslateService;
@@ -39,5 +39,5 @@ export declare class LibraryManager {
39
39
  getBullMQService(): BullMQService;
40
40
  getCashSettlementService(): CashSettlementService;
41
41
  getBOBService(): BOBService;
42
- getTranliterationService(): TransliterationService;
42
+ getLLMService(): LLMCompletionService;
43
43
  }
@@ -26,7 +26,7 @@ const logger_kit_1 = require("./logger-kit");
26
26
  const cloud_storage_1 = require("./cloud-storage");
27
27
  const lyxa_fcm_service_1 = require("./notification/lyxa-fcm.service");
28
28
  const google_translate_1 = require("./google-translate");
29
- const transliteration_service_1 = require("./transliteration/transliteration-service");
29
+ const llm_provider_service_1 = require("./llm/llm-provider-service");
30
30
  let LibraryManager = class LibraryManager {
31
31
  getLogger() {
32
32
  return typedi_1.Container.get(logger_1.LyxaLogger);
@@ -91,8 +91,8 @@ let LibraryManager = class LibraryManager {
91
91
  getBOBService() {
92
92
  return typedi_1.Container.get(cash_settlement_1.BOBService);
93
93
  }
94
- getTranliterationService() {
95
- return typedi_1.Container.get(transliteration_service_1.TransliterationService);
94
+ getLLMService() {
95
+ return typedi_1.Container.get(llm_provider_service_1.LLMCompletionService);
96
96
  }
97
97
  };
98
98
  exports.LibraryManager = LibraryManager;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,mCAA4C;AAC5C,qCAAyC;AACzC,qCAAsC;AACtC,6CAAsD;AACtD,uCAAiD;AACjD,mCAAuC;AACvC,mDAAuD;AACvD,qCAAyC;AACzC,yCAA6C;AAC7C,kDAAoD;AACpD,+BAAmC;AACnC,+CAAyD;AACzD,8EAAyE;AACzE,8DAAyD;AACzD,uDAAsE;AACtE,6CAA6C;AAC7C,mDAAsF;AACtF,sEAAiE;AACjE,yDAA4D;AAC5D,uFAAmF;AAG5E,IAAM,cAAc,GAApB,MAAM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AAuB,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACrG,CAAC;IACM,aAAa;QACnB,OAAO,kBAAS,CAAC,GAAG,CAAC,gBAAU,CAAC,CAAC;IAClC,CAAC;IACM,wBAAwB;QAC9B,OAAO,kBAAS,CAAC,GAAG,CAAC,gCAAqB,CAAC,CAAC;IAC7C,CAAC;IAEM,iBAAiB;QACvB,OAAO,kBAAS,CAAC,GAAG,CAAC,iCAAc,CAAC,CAAC;IACtC,CAAC;IAEM,aAAa;QACnB,OAAO,kBAAS,CAAC,GAAG,CAAC,yCAAkB,CAAC,CAAC;IAC1C,CAAC;IACM,gBAAgB;QACtB,OAAO,kBAAS,CAAC,GAAG,CAAC,+BAAa,CAAC,CAAC;IACrC,CAAC;IACM,wBAAwB;QAC9B,OAAO,kBAAS,CAAC,GAAG,CAAC,uCAAqB,CAAC,CAAC;IAC7C,CAAC;IACM,aAAa;QACnB,OAAO,kBAAS,CAAC,GAAG,CAAC,4BAAU,CAAC,CAAC;IAClC,CAAC;IACM,wBAAwB;QAC9B,OAAO,kBAAS,CAAC,GAAG,CAAC,gDAAsB,CAAC,CAAC;IAC9C,CAAC;CACD,CAAA;AAvEY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,gBAAO,GAAE;GACG,cAAc,CAuE1B","sourcesContent":["import { Container, Service } from 'typedi';\nimport { TwilioService } from './twilio';\nimport { LyxaLogger } from './logger';\nimport { MicroServiceDispatcher } from './dispatcher';\nimport { SecretManagerService } from './secrets';\nimport { RedisService } from './redis';\nimport { ConfigurationService } from './configuration';\nimport { UploadService } from './upload';\nimport { FirebaseService } from './firebase';\nimport { TokenRepository } from './auth/repository';\nimport { MapService } from './map';\nimport { CachedSettingsService } from './cache/settings';\nimport { FirebaseFcmService } from './notification/firebase-fcm.service';\nimport { BullMQService } from './bullmq/bull-mq-service';\nimport { BOBService, CashSettlementService } from './cash-settlement';\nimport { LyxaLoggerKit } from './logger-kit';\nimport { CloudStorageFactory, ICloudStorage, StorageProvider } from './cloud-storage';\nimport { LyxaFcmService } from './notification/lyxa-fcm.service';\nimport { GoogleTranslateService } from './google-translate';\nimport { TransliterationService } from './transliteration/transliteration-service';\n\n@Service()\nexport class LibraryManager {\n\tpublic getLogger(): LyxaLogger {\n\t\treturn Container.get(LyxaLogger);\n\t}\n\tpublic getGoogleTranslateService() {\n\t\treturn Container.get(GoogleTranslateService);\n\t}\n\tpublic getLoggerKit(): LyxaLoggerKit {\n\t\treturn Container.get(LyxaLoggerKit);\n\t}\n\tpublic getMicroServiceDispatcher(): MicroServiceDispatcher {\n\t\treturn Container.get(MicroServiceDispatcher);\n\t}\n\tpublic getTwilioService(): TwilioService {\n\t\treturn Container.get(TwilioService);\n\t}\n\tpublic getSecretsService(): SecretManagerService {\n\t\treturn Container.get(SecretManagerService);\n\t}\n\tpublic getRedisService(): RedisService {\n\t\treturn Container.get(RedisService);\n\t}\n\tpublic getConfigurationService(): ConfigurationService {\n\t\treturn Container.get(ConfigurationService);\n\t}\n\tpublic getFirebaseService(): FirebaseService {\n\t\treturn Container.get(FirebaseService);\n\t}\n\tpublic getAuthTokenRepository(): TokenRepository {\n\t\treturn Container.get(TokenRepository);\n\t}\n\tpublic getGlobalUploadService(): UploadService {\n\t\treturn new UploadService();\n\t}\n\tpublic getTenetUploadService(): UploadService {\n\t\treturn new UploadService('lyxa-' + this.getConfigurationService().options.tenet);\n\t}\n\n\tpublic getGlobalStorageService(provider?: StorageProvider): ICloudStorage {\n\t\treturn CloudStorageFactory.create(undefined, provider);\n\t}\n\n\tpublic getTenetStorageService(provider?: StorageProvider): ICloudStorage {\n\t\treturn CloudStorageFactory.create('lyxa-' + this.getConfigurationService().options.tenet, provider);\n\t}\n\tpublic getMapService(): MapService {\n\t\treturn Container.get(MapService);\n\t}\n\tpublic getCachedSettingsService(): CachedSettingsService {\n\t\treturn Container.get(CachedSettingsService);\n\t}\n\n\tpublic getLyxaFcmService(): LyxaFcmService {\n\t\treturn Container.get(LyxaFcmService);\n\t}\n\n\tpublic getFCMService(): FirebaseFcmService {\n\t\treturn Container.get(FirebaseFcmService);\n\t}\n\tpublic getBullMQService(): BullMQService {\n\t\treturn Container.get(BullMQService);\n\t}\n\tpublic getCashSettlementService(): CashSettlementService {\n\t\treturn Container.get(CashSettlementService);\n\t}\n\tpublic getBOBService(): BOBService {\n\t\treturn Container.get(BOBService);\n\t}\n\tpublic getTranliterationService(): TransliterationService {\n\t\treturn Container.get(TransliterationService);\n\t}\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,mCAA4C;AAC5C,qCAAyC;AACzC,qCAAsC;AACtC,6CAAsD;AACtD,uCAAiD;AACjD,mCAAuC;AACvC,mDAAuD;AACvD,qCAAyC;AACzC,yCAA6C;AAC7C,kDAAoD;AACpD,+BAAmC;AACnC,+CAAyD;AACzD,8EAAyE;AACzE,8DAAyD;AACzD,uDAAsE;AACtE,6CAA6C;AAC7C,mDAAsF;AACtF,sEAAiE;AACjE,yDAA4D;AAC5D,qEAAkE;AAG3D,IAAM,cAAc,GAApB,MAAM,cAAc;IACnB,SAAS;QACf,OAAO,kBAAS,CAAC,GAAG,CAAC,mBAAU,CAAC,CAAC;IAClC,CAAC;IACM,yBAAyB;QAC/B,OAAO,kBAAS,CAAC,GAAG,CAAC,yCAAsB,CAAC,CAAC;IAC9C,CAAC;IACM,YAAY;QAClB,OAAO,kBAAS,CAAC,GAAG,CAAC,0BAAa,CAAC,CAAC;IACrC,CAAC;IACM,yBAAyB;QAC/B,OAAO,kBAAS,CAAC,GAAG,CAAC,mCAAsB,CAAC,CAAC;IAC9C,CAAC;IACM,gBAAgB;QACtB,OAAO,kBAAS,CAAC,GAAG,CAAC,sBAAa,CAAC,CAAC;IACrC,CAAC;IACM,iBAAiB;QACvB,OAAO,kBAAS,CAAC,GAAG,CAAC,8BAAoB,CAAC,CAAC;IAC5C,CAAC;IACM,eAAe;QACrB,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CAAC,GAAG,CAAC,uCAAqB,CAAC,CAAC;IAC7C,CAAC;IACM,aAAa;QACnB,OAAO,kBAAS,CAAC,GAAG,CAAC,4BAAU,CAAC,CAAC;IAClC,CAAC;IACM,aAAa;QACnB,OAAO,kBAAS,CAAC,GAAG,CAAC,2CAAoB,CAAC,CAAC;IAC5C,CAAC;CACD,CAAA;AAvEY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,gBAAO,GAAE;GACG,cAAc,CAuE1B","sourcesContent":["import { Container, Service } from 'typedi';\nimport { TwilioService } from './twilio';\nimport { LyxaLogger } from './logger';\nimport { MicroServiceDispatcher } from './dispatcher';\nimport { SecretManagerService } from './secrets';\nimport { RedisService } from './redis';\nimport { ConfigurationService } from './configuration';\nimport { UploadService } from './upload';\nimport { FirebaseService } from './firebase';\nimport { TokenRepository } from './auth/repository';\nimport { MapService } from './map';\nimport { CachedSettingsService } from './cache/settings';\nimport { FirebaseFcmService } from './notification/firebase-fcm.service';\nimport { BullMQService } from './bullmq/bull-mq-service';\nimport { BOBService, CashSettlementService } from './cash-settlement';\nimport { LyxaLoggerKit } from './logger-kit';\nimport { CloudStorageFactory, ICloudStorage, StorageProvider } from './cloud-storage';\nimport { LyxaFcmService } from './notification/lyxa-fcm.service';\nimport { GoogleTranslateService } from './google-translate';\nimport { LLMCompletionService } from './llm/llm-provider-service';\n\n@Service()\nexport class LibraryManager {\n\tpublic getLogger(): LyxaLogger {\n\t\treturn Container.get(LyxaLogger);\n\t}\n\tpublic getGoogleTranslateService() {\n\t\treturn Container.get(GoogleTranslateService);\n\t}\n\tpublic getLoggerKit(): LyxaLoggerKit {\n\t\treturn Container.get(LyxaLoggerKit);\n\t}\n\tpublic getMicroServiceDispatcher(): MicroServiceDispatcher {\n\t\treturn Container.get(MicroServiceDispatcher);\n\t}\n\tpublic getTwilioService(): TwilioService {\n\t\treturn Container.get(TwilioService);\n\t}\n\tpublic getSecretsService(): SecretManagerService {\n\t\treturn Container.get(SecretManagerService);\n\t}\n\tpublic getRedisService(): RedisService {\n\t\treturn Container.get(RedisService);\n\t}\n\tpublic getConfigurationService(): ConfigurationService {\n\t\treturn Container.get(ConfigurationService);\n\t}\n\tpublic getFirebaseService(): FirebaseService {\n\t\treturn Container.get(FirebaseService);\n\t}\n\tpublic getAuthTokenRepository(): TokenRepository {\n\t\treturn Container.get(TokenRepository);\n\t}\n\tpublic getGlobalUploadService(): UploadService {\n\t\treturn new UploadService();\n\t}\n\tpublic getTenetUploadService(): UploadService {\n\t\treturn new UploadService('lyxa-' + this.getConfigurationService().options.tenet);\n\t}\n\n\tpublic getGlobalStorageService(provider?: StorageProvider): ICloudStorage {\n\t\treturn CloudStorageFactory.create(undefined, provider);\n\t}\n\n\tpublic getTenetStorageService(provider?: StorageProvider): ICloudStorage {\n\t\treturn CloudStorageFactory.create('lyxa-' + this.getConfigurationService().options.tenet, provider);\n\t}\n\tpublic getMapService(): MapService {\n\t\treturn Container.get(MapService);\n\t}\n\tpublic getCachedSettingsService(): CachedSettingsService {\n\t\treturn Container.get(CachedSettingsService);\n\t}\n\n\tpublic getLyxaFcmService(): LyxaFcmService {\n\t\treturn Container.get(LyxaFcmService);\n\t}\n\n\tpublic getFCMService(): FirebaseFcmService {\n\t\treturn Container.get(FirebaseFcmService);\n\t}\n\tpublic getBullMQService(): BullMQService {\n\t\treturn Container.get(BullMQService);\n\t}\n\tpublic getCashSettlementService(): CashSettlementService {\n\t\treturn Container.get(CashSettlementService);\n\t}\n\tpublic getBOBService(): BOBService {\n\t\treturn Container.get(BOBService);\n\t}\n\tpublic getLLMService(): LLMCompletionService {\n\t\treturn Container.get(LLMCompletionService);\n\t}\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import { LLMProvider } from "../llm-provider-service";
2
+ export interface IAICompletionProvider {
3
+ generatePromptVariantsBatch(items: ItemTextInput[], model?: string, instructions?: string, options?: {
4
+ pollIntervalMs?: number;
5
+ maxWaitMs?: number;
6
+ }): Promise<TextVariantResult[]>;
7
+ }
8
+ export interface TextVariantResult {
9
+ original: string;
10
+ arabic?: string[];
11
+ arabizi?: string[];
12
+ arabicTransliteration?: string[];
13
+ }
14
+ export interface AiConfiguration {
15
+ provider: LLMProvider;
16
+ model?: string;
17
+ instructions?: string;
18
+ prompt?: string;
19
+ }
20
+ export interface ItemTextInput {
21
+ itemId: string;
22
+ text: string;
23
+ }
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=common-transliteration.js.map
3
+ //# sourceMappingURL=common-llm-interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-llm-interfaces.js","sourceRoot":"/","sources":["libraries/llm/interfaces/common-llm-interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import { LLMProvider } from \"../llm-provider-service\";\n\nexport interface IAICompletionProvider {\n\tgeneratePromptVariantsBatch(\n\t\titems: ItemTextInput[],\n\t\tmodel?: string,\n\t\tinstructions?: string,\n\t\toptions?: { pollIntervalMs?: number; maxWaitMs?: number }\n\t): Promise<TextVariantResult[]>;\n}\n\n// export interface TextVariantConfig {\n// \tisArabic?: boolean; // Arabic translation, Arabic script\n// \tisArabizi?: boolean; // Arabic word, Latin script (e.g. \"zaytoon\")\n// \tisArabicTransliteration?: boolean; // original word, spelled phonetically in Arabic script (e.g. \"أوليف\")\n// }\n\nexport interface TextVariantResult {\n\toriginal: string;\n\tarabic?: string[];\n\tarabizi?: string[];\n\tarabicTransliteration?: string[];\n}\n\nexport interface AiConfiguration {\n\tprovider: LLMProvider;\n\tmodel?: string;\n\tinstructions?: string;\n\tprompt?: string;\n}\n\nexport interface ItemTextInput {\n\titemId: string;\n\ttext: string;\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { ItemTextInput, AiConfiguration, TextVariantResult } from './interfaces/common-llm-interfaces';
2
+ export declare enum LLMProvider {
3
+ OPENAI = "openai",
4
+ GEMINI = "gemini"
5
+ }
6
+ export declare class LLMCompletionService {
7
+ private readonly provider;
8
+ private providerInstance;
9
+ private readonly factories;
10
+ constructor(provider: LLMProvider);
11
+ generatePromptVariantsBatch(payload: ItemTextInput[], aiConfigurations: AiConfiguration): Promise<TextVariantResult[]>;
12
+ private getProvider;
13
+ }
@@ -1,41 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TransliterationService = exports.TransliterationProvider = void 0;
3
+ exports.LLMCompletionService = exports.LLMProvider = void 0;
4
4
  const __1 = require("../..");
5
5
  const error_common_1 = require("../../utilities/error-common");
6
6
  const openai_provider_1 = require("./providers/openai-provider");
7
- var TransliterationProvider;
8
- (function (TransliterationProvider) {
9
- TransliterationProvider["OPENAI"] = "openai";
10
- TransliterationProvider["GEMINI"] = "gemini";
11
- })(TransliterationProvider || (exports.TransliterationProvider = TransliterationProvider = {}));
12
- class TransliterationService {
7
+ var LLMProvider;
8
+ (function (LLMProvider) {
9
+ LLMProvider["OPENAI"] = "openai";
10
+ LLMProvider["GEMINI"] = "gemini";
11
+ })(LLMProvider || (exports.LLMProvider = LLMProvider = {}));
12
+ class LLMCompletionService {
13
13
  provider;
14
14
  providerInstance = null;
15
15
  factories = {
16
- [TransliterationProvider.OPENAI]: async () => {
16
+ [LLMProvider.OPENAI]: async () => {
17
17
  const apiKey = await (0, __1.getLibraries)().getSecretsService().getKey('OPENAI_API_KEY');
18
18
  if (!apiKey) {
19
- throw (0, error_common_1.badRequestError)(`No API key found for provider ${TransliterationProvider.OPENAI}`);
19
+ throw (0, error_common_1.badRequestError)(`No API key found for provider ${LLMProvider.OPENAI}`);
20
20
  }
21
- return new openai_provider_1.OpenAICompletionProvider(apiKey, 'gpt-5.5');
21
+ return new openai_provider_1.OpenAICompletionProvider(apiKey, 'gpt-5-mini');
22
22
  },
23
- [TransliterationProvider.GEMINI]: async () => {
24
- throw (0, error_common_1.badRequestError)(`Provider ${TransliterationProvider.GEMINI} is not implemented yet`);
23
+ [LLMProvider.GEMINI]: async () => {
24
+ throw (0, error_common_1.badRequestError)(`Provider ${LLMProvider.GEMINI} is not implemented yet`);
25
25
  },
26
26
  };
27
27
  constructor(provider) {
28
28
  this.provider = provider;
29
29
  }
30
- async translateToArabizi(text) {
30
+ async generatePromptVariantsBatch(payload, aiConfigurations) {
31
31
  const provider = await this.getProvider();
32
- return provider.prompt(text, {
33
- instructions: 'You are a translation assistant. Translate the given text to Arabizi.',
34
- });
35
- }
36
- async generatePromptVariants(text, config) {
37
- const provider = await this.getProvider();
38
- return provider.generatePromptVariants(text, config);
32
+ console.log(`You are using llm provider: ${this.provider} with model: ${aiConfigurations.model ?? 'gpt-5-mini'}`);
33
+ return provider.generatePromptVariantsBatch(payload, aiConfigurations.model, aiConfigurations.instructions);
39
34
  }
40
35
  async getProvider() {
41
36
  if (!this.providerInstance) {
@@ -48,5 +43,5 @@ class TransliterationService {
48
43
  return this.providerInstance;
49
44
  }
50
45
  }
51
- exports.TransliterationService = TransliterationService;
52
- //# sourceMappingURL=transliteration-service.js.map
46
+ exports.LLMCompletionService = LLMCompletionService;
47
+ //# sourceMappingURL=llm-provider-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-provider-service.js","sourceRoot":"/","sources":["libraries/llm/llm-provider-service.ts"],"names":[],"mappings":";;;AAAA,6BAAqC;AAOrC,+DAA+D;AAC/D,iEAAuE;AAEvE,IAAY,WAGX;AAHD,WAAY,WAAW;IACtB,gCAAiB,CAAA;IACjB,gCAAiB,CAAA;AAClB,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB;AAID,MAAa,oBAAoB;IAgBH;IAfrB,gBAAgB,GAAiC,IAAI,CAAC;IAE7C,SAAS,GAAyC;QAClE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,KAAK,IAAI,EAAE;YAChC,MAAM,MAAM,GAAG,MAAM,IAAA,gBAAY,GAAE,CAAC,iBAAiB,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;YACjF,IAAI,CAAC,MAAM,EAAE,CAAC;g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tTextVariantResult,\n\tIAICompletionProvider,\n} from './interfaces/common-llm-interfaces';\nimport { badRequestError } from '../../utilities/error-common';\nimport { OpenAICompletionProvider } from './providers/openai-provider';\n\nexport enum LLMProvider {\n\tOPENAI = 'openai',\n\tGEMINI = 'gemini',\n}\n\ntype ProviderFactory = () => Promise<IAICompletionProvider>;\n\nexport class LLMCompletionService {\n\tprivate providerInstance: IAICompletionProvider | null = null;\n\n\tprivate readonly factories: Record<LLMProvider, ProviderFactory> = {\n\t\t[LLMProvider.OPENAI]: async () => {\n\t\t\tconst apiKey = await getLibraries().getSecretsService().getKey('OPENAI_API_KEY');\t\t\t\n\t\t\tif (!apiKey) {\n\t\t\t\tthrow badRequestError(`No API key found for provider ${LLMProvider.OPENAI}`);\n\t\t\t}\n\t\t\treturn new OpenAICompletionProvider(apiKey, 'gpt-5-mini');\n\t\t},\n\t\t[LLMProvider.GEMINI]: async () => {\n\t\t\tthrow badRequestError(`Provider ${LLMProvider.GEMINI} is not implemented yet`);\n\t\t},\n\t};\n\n\tconstructor(private readonly provider: LLMProvider) {}\n\t\n\tasync generatePromptVariantsBatch(payload: ItemTextInput[], aiConfigurations: AiConfiguration): Promise<TextVariantResult[]> {\n\t\tconst provider = await this.getProvider();\n\t\tconsole.log(`You are using llm provider: ${this.provider} with model: ${aiConfigurations.model ?? 'gpt-5-mini'}`);\n\t\treturn provider.generatePromptVariantsBatch(payload, aiConfigurations.model,aiConfigurations.instructions);\n\t}\n\n\tprivate async getProvider(): Promise<IAICompletionProvider> {\n\t\tif (!this.providerInstance) {\n\t\t\tconst factory = this.factories[this.provider];\n\t\t\tif (!factory) {\n\t\t\t\tthrow badRequestError(`Unsupported transliteration provider: ${this.provider}`);\n\t\t\t}\n\t\t\tthis.providerInstance = await factory();\n\t\t}\n\t\treturn this.providerInstance;\n\t}\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import { IAICompletionProvider, ItemTextInput, TextVariantResult } from '../interfaces/common-llm-interfaces';
2
+ export declare class OpenAICompletionProvider implements IAICompletionProvider {
3
+ private readonly client;
4
+ private readonly model;
5
+ constructor(apiKey: string | undefined, model?: string);
6
+ generatePromptVariantsBatch(items: ItemTextInput[], model?: string, instructions?: string, options?: {
7
+ pollIntervalMs?: number;
8
+ maxWaitMs?: number;
9
+ }): Promise<TextVariantResult[]>;
10
+ private buildVariantRequest;
11
+ private pollBatch;
12
+ private readJsonlFile;
13
+ private buildJsonSchema;
14
+ }
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.OpenAICompletionProvider = void 0;
37
+ const openai_1 = __importStar(require("openai"));
38
+ class OpenAICompletionProvider {
39
+ client;
40
+ model;
41
+ constructor(apiKey, model = 'gpt-5-mini') {
42
+ if (!apiKey) {
43
+ throw new Error('OPENAI_API_KEY is required to construct OpenAICompletionProvider');
44
+ }
45
+ this.client = new openai_1.default({ apiKey });
46
+ this.model = model;
47
+ }
48
+ async generatePromptVariantsBatch(items, model, instructions, options) {
49
+ const { fields, instructions: defaultInstructions } = this.buildVariantRequest();
50
+ const finalInstructions = instructions ?? defaultInstructions;
51
+ const finalModel = model ?? this.model;
52
+ const schema = this.buildJsonSchema(fields);
53
+ if (items.length > 50_000) {
54
+ throw new Error('Batch API supports max 50,000 requests per batch — chunk your items first.');
55
+ }
56
+ const jsonl = items
57
+ .map(({ itemId, text }) => JSON.stringify({
58
+ custom_id: itemId,
59
+ method: 'POST',
60
+ url: '/v1/responses',
61
+ body: {
62
+ model: finalModel,
63
+ instructions: finalInstructions,
64
+ input: text,
65
+ text: {
66
+ format: {
67
+ type: 'json_schema',
68
+ name: 'text_variants',
69
+ schema,
70
+ strict: true,
71
+ },
72
+ },
73
+ },
74
+ }))
75
+ .join('\n');
76
+ const inputFile = await this.client.files.create({
77
+ file: await (0, openai_1.toFile)(Buffer.from(jsonl, 'utf-8'), 'batch-input.jsonl'),
78
+ purpose: 'batch',
79
+ });
80
+ let batch = await this.client.batches.create({
81
+ input_file_id: inputFile.id,
82
+ endpoint: '/v1/responses',
83
+ completion_window: '24h',
84
+ });
85
+ batch = await this.pollBatch(batch.id, options?.pollIntervalMs, options?.maxWaitMs);
86
+ if (batch.status !== 'completed') {
87
+ throw new Error(`Batch ${batch.id} ended with status "${batch.status}" (${batch.request_counts?.failed ?? 0} failed)`);
88
+ }
89
+ const outputById = await this.readJsonlFile(batch.output_file_id);
90
+ const errorsById = await this.readJsonlFile(batch.error_file_id);
91
+ return items.map(({ itemId, text }) => {
92
+ const record = outputById.get(itemId);
93
+ const body = record?.response?.body;
94
+ const outputText = body?.output_text ??
95
+ body?.output
96
+ ?.find((o) => o.type === 'message')
97
+ ?.content?.find((c) => c.type === 'output_text')?.text;
98
+ if (!outputText) {
99
+ const err = errorsById.get(itemId);
100
+ console.error(`generatePromptVariantsBatch: no output for itemId=${itemId}`, err ?? record?.error);
101
+ return { itemId, original: text };
102
+ }
103
+ try {
104
+ return { itemId, original: text, ...JSON.parse(outputText) };
105
+ }
106
+ catch {
107
+ console.error(`generatePromptVariantsBatch: failed to parse output for itemId=${itemId}`, outputText);
108
+ return { itemId, original: text };
109
+ }
110
+ });
111
+ }
112
+ buildVariantRequest() {
113
+ const fieldDescriptions = {
114
+ arabic: 'The Arabic translation of the word/phrase, written in Arabic script (e.g. "زيتون" for "olive"). Provide 1-3 common variants if applicable.',
115
+ arabizi: 'The Arabic word\'s meaning, written phonetically in Latin script/numerals — i.e. Arabizi (e.g. "zaytoon"). Provide 1-3 common spelling variants.',
116
+ arabicTransliteration: 'The original word spelled phonetically in Arabic script, NOT translated (e.g. "أوليف" for "olive"). Useful when there is no native Arabic equivalent.',
117
+ };
118
+ const fields = Object.keys(fieldDescriptions);
119
+ const instructions = [
120
+ 'You generate search-name variants for a food delivery app product/shop name.',
121
+ 'For the given input text, return ONLY the following fields as arrays of strings:',
122
+ ...fields.map(f => `- ${f}: ${fieldDescriptions[f]}`),
123
+ 'Return strict JSON matching the schema. No extra commentary, no extra fields.',
124
+ ].join('\n');
125
+ return { fields, instructions };
126
+ }
127
+ async pollBatch(batchId, intervalMs = 5000, maxWaitMs = 24 * 60 * 60 * 1000) {
128
+ const terminal = new Set(['completed', 'failed', 'expired', 'cancelled']);
129
+ const start = Date.now();
130
+ while (true) {
131
+ const batch = await this.client.batches.retrieve(batchId);
132
+ if (terminal.has(batch.status))
133
+ return batch;
134
+ if (Date.now() - start > maxWaitMs) {
135
+ throw new Error(`Batch ${batchId} did not finish within ${maxWaitMs}ms (status: ${batch.status})`);
136
+ }
137
+ await new Promise(resolve => setTimeout(resolve, intervalMs));
138
+ }
139
+ }
140
+ async readJsonlFile(fileId) {
141
+ const result = new Map();
142
+ if (!fileId)
143
+ return result;
144
+ const fileResponse = await this.client.files.content(fileId);
145
+ const text = await fileResponse.text();
146
+ for (const line of text.split('\n').filter(Boolean)) {
147
+ const record = JSON.parse(line);
148
+ result.set(record.custom_id, record);
149
+ }
150
+ return result;
151
+ }
152
+ buildJsonSchema(fields) {
153
+ const properties = {};
154
+ for (const field of fields) {
155
+ properties[field] = { type: 'array', items: { type: 'string' } };
156
+ }
157
+ return {
158
+ type: 'object',
159
+ properties,
160
+ required: fields,
161
+ additionalProperties: false,
162
+ };
163
+ }
164
+ }
165
+ exports.OpenAICompletionProvider = OpenAICompletionProvider;
166
+ //# sourceMappingURL=openai-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-provider.js","sourceRoot":"/","sources":["libraries/llm/providers/openai-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAwC;AAOxC,MAAa,wBAAwB;IACnB,MAAM,CAAS;IACf,KAAK,CAAS;IAE/B,YAAY,MAA0B,EAAE,QAAgB,YAAY;QACnE,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;QACrF,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,2BAA2B,CAChC,KAAsB,EACtB,KAAc,EACd,YAAqB,EACrB,OAAyD;QAEzD,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,mBAAmB,EAAE,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACjF,MAAM,iBAAiB,GAAG,YAAY,IAAI,mBAAmB,CAAC;QAC9D,MAAM,UAAU,GAAG,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;QACvC,MAAM,MAAM,GAAG,IAAI,CAAC,eA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ACH,CAAC;CACD;AAjLD,4DAiLC","sourcesContent":["import OpenAI, { toFile } from 'openai';\nimport {\n\tIAICompletionProvider,\n\tItemTextInput,\n\tTextVariantResult,\n} from '../interfaces/common-llm-interfaces';\n\nexport class OpenAICompletionProvider implements IAICompletionProvider {\n\tprivate readonly client: OpenAI;\n\tprivate readonly model: string;\n\n\tconstructor(apiKey: string | undefined, model: string = 'gpt-5-mini') {\n\t\tif (!apiKey) {\n\t\t\tthrow new Error('OPENAI_API_KEY is required to construct OpenAICompletionProvider');\n\t\t}\n\t\tthis.client = new OpenAI({ apiKey });\n\t\tthis.model = model;\n\t}\n\n\tasync generatePromptVariantsBatch(\n\t\titems: ItemTextInput[],\n\t\tmodel?: string,\n\t\tinstructions?: string,\n\t\toptions?: { pollIntervalMs?: number; maxWaitMs?: number }\n\t): Promise<TextVariantResult[]> {\n\t\tconst { fields, instructions: defaultInstructions } = this.buildVariantRequest();\n\t\tconst finalInstructions = instructions ?? defaultInstructions;\n\t\tconst finalModel = model ?? this.model;\n\t\tconst schema = this.buildJsonSchema(fields);\n\n\t\tif (items.length > 50_000) {\n\t\t\tthrow new Error('Batch API supports max 50,000 requests per batch — chunk your items first.');\n\t\t}\n\n\t\t// 1. Build JSONL — one line per item, keyed by custom_id\n\t\tconst jsonl = items\n\t\t\t.map(({ itemId, text }) =>\n\t\t\t\tJSON.stringify({\n\t\t\t\t\tcustom_id: itemId,\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\turl: '/v1/responses',\n\t\t\t\t\tbody: {\n\t\t\t\t\t\tmodel: finalModel,\n\t\t\t\t\t\tinstructions: finalInstructions,\n\t\t\t\t\t\tinput: text,\n\t\t\t\t\t\ttext: {\n\t\t\t\t\t\t\tformat: {\n\t\t\t\t\t\t\t\ttype: 'json_schema',\n\t\t\t\t\t\t\t\tname: 'text_variants',\n\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\tstrict: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t)\n\t\t\t.join('\\n');\n\n\t\t// 2. Upload input file\n\t\tconst inputFile = await this.client.files.create({\n\t\t\tfile: await toFile(Buffer.from(jsonl, 'utf-8'), 'batch-input.jsonl'),\n\t\t\tpurpose: 'batch',\n\t\t});\n\n\t\t// 3. Create batch job\n\t\tlet batch = await this.client.batches.create({\n\t\t\tinput_file_id: inputFile.id,\n\t\t\tendpoint: '/v1/responses',\n\t\t\tcompletion_window: '24h',\n\t\t});\n\n\t\t// 4. Poll until done\n\t\tbatch = await this.pollBatch(batch.id, options?.pollIntervalMs, options?.maxWaitMs);\n\n\t\tif (batch.status !== 'completed') {\n\t\t\tthrow new Error(\n\t\t\t\t`Batch ${batch.id} ended with status \"${batch.status}\" (${batch.request_counts?.failed ?? 0} failed)`\n\t\t\t);\n\t\t}\n\n\t\t// 5. Parse output (+ errors, if any partial failures)\n\t\tconst outputById = await this.readJsonlFile(batch.output_file_id);\n\t\tconst errorsById = await this.readJsonlFile(batch.error_file_id);\n\n\t\t// 6. Merge back, preserving input order and itemId\n\t\treturn items.map(({ itemId, text }) => {\n\t\t\tconst record = outputById.get(itemId);\n\t\t\tconst body = record?.response?.body;\n\t\t\tconst outputText =\n\t\t\t\tbody?.output_text ??\n\t\t\t\tbody?.output\n\t\t\t\t\t?.find((o: any) => o.type === 'message')\n\t\t\t\t\t?.content?.find((c: any) => c.type === 'output_text')?.text;\n\n\t\t\tif (!outputText) {\n\t\t\t\tconst err = errorsById.get(itemId);\n\t\t\t\tconsole.error(`generatePromptVariantsBatch: no output for itemId=${itemId}`, err ?? record?.error);\n\t\t\t\treturn { itemId, original: text };\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\treturn { itemId, original: text, ...JSON.parse(outputText) };\n\t\t\t} catch {\n\t\t\t\tconsole.error(`generatePromptVariantsBatch: failed to parse output for itemId=${itemId}`, outputText);\n\t\t\t\treturn { itemId, original: text };\n\t\t\t}\n\t\t});\n\t}\n\n\t// ── Helpers ──────────────────────────────────────────────────────\n\n\tprivate buildVariantRequest(): {\n\t\tfields: (keyof TextVariantResult)[];\n\t\tinstructions: string;\n\t} {\n\t\tconst fieldDescriptions: Record<Exclude<keyof TextVariantResult, 'original'>, string> = {\n\t\t\tarabic:\n\t\t\t\t'The Arabic translation of the word/phrase, written in Arabic script (e.g. \"زيتون\" for \"olive\"). Provide 1-3 common variants if applicable.',\n\t\t\tarabizi:\n\t\t\t\t'The Arabic word\\'s meaning, written phonetically in Latin script/numerals — i.e. Arabizi (e.g. \"zaytoon\"). Provide 1-3 common spelling variants.',\n\t\t\tarabicTransliteration:\n\t\t\t\t'The original word spelled phonetically in Arabic script, NOT translated (e.g. \"أوليف\" for \"olive\"). Useful when there is no native Arabic equivalent.',\n\t\t};\n\n\t\tconst fields = Object.keys(fieldDescriptions) as (keyof TextVariantResult)[];\n\n\t\tconst instructions = [\n\t\t\t'You generate search-name variants for a food delivery app product/shop name.',\n\t\t\t'For the given input text, return ONLY the following fields as arrays of strings:',\n\t\t\t...fields.map(f => `- ${f}: ${fieldDescriptions[f as Exclude<keyof TextVariantResult, 'original'>]}`),\n\t\t\t'Return strict JSON matching the schema. No extra commentary, no extra fields.',\n\t\t].join('\\n');\n\n\t\treturn { fields, instructions };\n\t}\n\n\tprivate async pollBatch(\n\t\tbatchId: string,\n\t\tintervalMs = 5000,\n\t\tmaxWaitMs = 24 * 60 * 60 * 1000\n\t): Promise<OpenAI.Batches.Batch> {\n\t\tconst terminal = new Set(['completed', 'failed', 'expired', 'cancelled']);\n\t\tconst start = Date.now();\n\n\t\twhile (true) {\n\t\t\tconst batch = await this.client.batches.retrieve(batchId);\n\t\t\tif (terminal.has(batch.status)) return batch;\n\n\t\t\tif (Date.now() - start > maxWaitMs) {\n\t\t\t\tthrow new Error(`Batch ${batchId} did not finish within ${maxWaitMs}ms (status: ${batch.status})`);\n\t\t\t}\n\n\t\t\tawait new Promise(resolve => setTimeout(resolve, intervalMs));\n\t\t}\n\t}\n\n\tprivate async readJsonlFile(fileId: string | null | undefined): Promise<Map<string, any>> {\n\t\tconst result = new Map<string, any>();\n\t\tif (!fileId) return result;\n\n\t\tconst fileResponse = await this.client.files.content(fileId);\n\t\tconst text = await fileResponse.text();\n\n\t\tfor (const line of text.split('\\n').filter(Boolean)) {\n\t\t\tconst record = JSON.parse(line);\n\t\t\tresult.set(record.custom_id, record);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tprivate buildJsonSchema(fields: (keyof TextVariantResult)[]) {\n\t\tconst properties: Record<string, any> = {};\n\t\tfor (const field of fields) {\n\t\t\tproperties[field] = { type: 'array', items: { type: 'string' } };\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'object',\n\t\t\tproperties,\n\t\t\trequired: fields,\n\t\t\tadditionalProperties: false,\n\t\t};\n\t}\n}\n"]}
@@ -9,5 +9,5 @@ export declare class SpendToGetHistory extends TimeStamps {
9
9
  marketing: Ref<SpendToGetMarketing>;
10
10
  shop: Ref<Shop>;
11
11
  redemptionCount: number;
12
- lastOrder?: Ref<Order>;
12
+ redeemingOrders: Ref<Order>[];
13
13
  }
@@ -21,7 +21,7 @@ let SpendToGetHistory = class SpendToGetHistory extends defaultClasses_1.TimeSta
21
21
  marketing;
22
22
  shop;
23
23
  redemptionCount;
24
- lastOrder;
24
+ redeemingOrders;
25
25
  };
26
26
  exports.SpendToGetHistory = SpendToGetHistory;
27
27
  __decorate([
@@ -41,9 +41,9 @@ __decorate([
41
41
  __metadata("design:type", Number)
42
42
  ], SpendToGetHistory.prototype, "redemptionCount", void 0);
43
43
  __decorate([
44
- (0, typegoose_1.prop)({ ref: () => order_model_1.Order, default: null }),
45
- __metadata("design:type", Object)
46
- ], SpendToGetHistory.prototype, "lastOrder", void 0);
44
+ (0, typegoose_1.prop)({ ref: () => order_model_1.Order, default: [] }),
45
+ __metadata("design:type", Array)
46
+ ], SpendToGetHistory.prototype, "redeemingOrders", void 0);
47
47
  exports.SpendToGetHistory = SpendToGetHistory = __decorate([
48
48
  (0, typegoose_1.modelOptions)({ schemaOptions: { collection: 'spendToGetHistories' } }),
49
49
  (0, typegoose_1.Index)({ user: 1, marketing: 1 }, { unique: true })
@@ -1 +1 @@
1
- {"version":3,"file":"spend-to-get-history.model.js","sourceRoot":"/","sources":["libraries/mongo/models/spend-to-get-history.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAsE;AACtE,4EAAqE;AACrE,2FAA+E;AAC/E,6CAAoC;AACpC,6CAAoC;AACpC,+CAAsC;AAI/B,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,2BAAU;IAEzC,IAAI,CAAa;IAGjB,SAAS,CAA4B;IAGrC,IAAI,CAAa;IAGjB,eAAe,CAAS;IAGxB,SAAS,CAAc;CAC9B,CAAA;AAfY,8CAAiB;AAEtB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,iBAAI,EAAE,CAAC;;+CAClB;AAGjB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,kDAAmB,EAAE,CAAC;;oDACb;AAGrC;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,iBAAI,EAAE,CAAC;;+CAClB;AAGjB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;0DACJ;AAGxB;IADN,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,mBAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;oDACZ;4BAdlB,iBAAiB;IAF7B,IAAA,wBAAY,EAAC,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,qBAAqB,EAAE,EAAE,CAAC;IACtE,IAAA,iBAAK,EAAC,EAAE,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;GACtC,iBAAiB,CAe7B","sourcesContent":["import { Index, modelOptions, prop, Ref } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { SpendToGetMarketing } from './providers/spend-to-get-marketing.model';\nimport { Shop } from './shop.model';\nimport { User } from './user.model';\nimport { Order } from './order.model';\n\n@modelOptions({ schemaOptions: { collection: 'spendToGetHistories' } })\n@Index({ user: 1, marketing: 1 }, { unique: true })\nexport class SpendToGetHistory extends TimeStamps {\n\t@prop({ required: true, ref: () => User })\n\tpublic user!: Ref<User>;\n\n\t@prop({ required: true, ref: () => SpendToGetMarketing })\n\tpublic marketing!: Ref<SpendToGetMarketing>;\n\n\t@prop({ required: true, ref: () => Shop })\n\tpublic shop!: Ref<Shop>;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic redemptionCount: number;\n\n\t@prop({ ref: () => Order, default: null })\n\tpublic lastOrder?: Ref<Order>;\n}\n"]}
1
+ {"version":3,"file":"spend-to-get-history.model.js","sourceRoot":"/","sources":["libraries/mongo/models/spend-to-get-history.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAsE;AACtE,4EAAqE;AACrE,2FAA+E;AAC/E,6CAAoC;AACpC,6CAAoC;AACpC,+CAAsC;AAI/B,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,2BAAU;IAEzC,IAAI,CAAa;IAGjB,SAAS,CAA4B;IAGrC,IAAI,CAAa;IAGjB,eAAe,CAAS;IAGxB,eAAe,CAAgB;CACtC,CAAA;AAfY,8CAAiB;AAEtB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,iBAAI,EAAE,CAAC;;+CAClB;AAGjB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,kDAAmB,EAAE,CAAC;;oDACb;AAGrC;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,iBAAI,EAAE,CAAC;;+CAClB;AAGjB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;0DACJ;AAGxB;IADN,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,mBAAK,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;0DACF;4BAd1B,iBAAiB;IAF7B,IAAA,wBAAY,EAAC,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,qBAAqB,EAAE,EAAE,CAAC;IACtE,IAAA,iBAAK,EAAC,EAAE,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;GACtC,iBAAiB,CAe7B","sourcesContent":["import { Index, modelOptions, prop, Ref } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { SpendToGetMarketing } from './providers/spend-to-get-marketing.model';\nimport { Shop } from './shop.model';\nimport { User } from './user.model';\nimport { Order } from './order.model';\n\n@modelOptions({ schemaOptions: { collection: 'spendToGetHistories' } })\n@Index({ user: 1, marketing: 1 }, { unique: true })\nexport class SpendToGetHistory extends TimeStamps {\n\t@prop({ required: true, ref: () => User })\n\tpublic user!: Ref<User>;\n\n\t@prop({ required: true, ref: () => SpendToGetMarketing })\n\tpublic marketing!: Ref<SpendToGetMarketing>;\n\n\t@prop({ required: true, ref: () => Shop })\n\tpublic shop!: Ref<Shop>;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic redemptionCount: number;\n\n\t@prop({ ref: () => Order, default: [] })\n\tpublic redeemingOrders!: Ref<Order>[];\n}\n"]}
@@ -5,9 +5,9 @@ interface AuthOptions {
5
5
  autoRefresh?: boolean;
6
6
  }
7
7
  export declare function createAuthenticatedProcedure(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
8
+ req: import("http").IncomingMessage;
8
9
  res: import("http").ServerResponse<import("http").IncomingMessage>;
9
10
  tokenType: TokenType | undefined;
10
- req: import("http").IncomingMessage;
11
11
  requestId: string | undefined;
12
12
  entity: import("../context").EntityContext | undefined;
13
13
  usedRefreshToken: boolean | undefined;
@@ -4,9 +4,9 @@ interface RoleProtectedOptions {
4
4
  allowedRoles: string[];
5
5
  }
6
6
  export declare function createRoleProtectedProcedure(options: RoleProtectedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
7
+ req: import("http").IncomingMessage;
7
8
  res: import("http").ServerResponse<import("http").IncomingMessage>;
8
9
  tokenType: import("../../auth").TokenType | undefined;
9
- req: import("http").IncomingMessage;
10
10
  requestId: string | undefined;
11
11
  entity: import("../context").EntityContext | undefined;
12
12
  usedRefreshToken: boolean | undefined;
@@ -3,9 +3,9 @@ interface PhoneVerifiedOptions {
3
3
  entityTypes: AuthEntityType[];
4
4
  }
5
5
  export declare function createPhoneVerifiedProcedure(options: PhoneVerifiedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
6
+ req: import("http").IncomingMessage;
6
7
  res: import("http").ServerResponse<import("http").IncomingMessage>;
7
8
  tokenType: import("../../auth").TokenType | undefined;
8
- req: import("http").IncomingMessage;
9
9
  requestId: string | undefined;
10
10
  entity: import("../context").EntityContext | undefined;
11
11
  usedRefreshToken: boolean | undefined;
@@ -5,9 +5,9 @@ interface AuthOptions {
5
5
  autoRefresh?: boolean;
6
6
  }
7
7
  export declare function publicUserDecoder(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
8
+ req: import("http").IncomingMessage;
8
9
  res: import("http").ServerResponse<import("http").IncomingMessage>;
9
10
  tokenType: TokenType | undefined;
10
- req: import("http").IncomingMessage;
11
11
  requestId: string | undefined;
12
12
  entity: import("../context").EntityContext | undefined;
13
13
  usedRefreshToken: boolean | undefined;
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.4.280
25
+ Version: 1.4.282
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.4.280",
3
+ "version": "1.4.282",
4
4
  "description": "Lyxa type definitions and validation schemas for both frontend and backend",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -26,8 +26,8 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
26
26
  searchFields?: string[] | undefined;
27
27
  } | undefined;
28
28
  sort?: Record<string, 1 | -1> | undefined;
29
- select?: Record<string, 0 | 1> | undefined;
30
29
  populate?: any;
30
+ select?: Record<string, 0 | 1> | undefined;
31
31
  query?: Record<string, any> | undefined;
32
32
  }, {
33
33
  search?: {
@@ -36,8 +36,8 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
36
36
  } | undefined;
37
37
  sort?: Record<string, 1 | -1> | undefined;
38
38
  size?: number | undefined;
39
- select?: Record<string, 0 | 1> | undefined;
40
39
  populate?: any;
40
+ select?: Record<string, 0 | 1> | undefined;
41
41
  query?: Record<string, any> | undefined;
42
42
  page?: number | undefined;
43
43
  }>>;
@@ -736,12 +736,12 @@ export declare const GetByIdInputSchema: z.ZodObject<{
736
736
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
737
737
  }, "strip", z.ZodTypeAny, {
738
738
  _id: import("mongoose").Types.ObjectId;
739
- select?: Record<string, 0 | 1> | undefined;
740
739
  populate?: any;
740
+ select?: Record<string, 0 | 1> | undefined;
741
741
  }, {
742
742
  _id: string | import("mongoose").Types.ObjectId;
743
- select?: Record<string, 0 | 1> | undefined;
744
743
  populate?: any;
744
+ select?: Record<string, 0 | 1> | undefined;
745
745
  }>;
746
746
  export type GetByIdInputDTO = DTO<typeof GetByIdInputSchema>;
747
747
  export declare const GetProductByIdInputSchema: z.ZodObject<{
@@ -754,12 +754,12 @@ export declare const GetProductByIdInputSchema: z.ZodObject<{
754
754
  _id: import("mongoose").Types.ObjectId;
755
755
  withAttributeHiddenItems: boolean;
756
756
  withAddonsHiddenItems: boolean;
757
- select?: Record<string, 0 | 1> | undefined;
758
757
  populate?: any;
758
+ select?: Record<string, 0 | 1> | undefined;
759
759
  }, {
760
760
  _id: string | import("mongoose").Types.ObjectId;
761
- select?: Record<string, 0 | 1> | undefined;
762
761
  populate?: any;
762
+ select?: Record<string, 0 | 1> | undefined;
763
763
  withAttributeHiddenItems?: boolean | undefined;
764
764
  withAddonsHiddenItems?: boolean | undefined;
765
765
  }>;
@@ -773,15 +773,15 @@ export declare const GetOrderByIdInputSchema: z.ZodObject<{
773
773
  userOrderCompletionScope: z.ZodOptional<z.ZodNativeEnum<typeof UserOrderCompletionScope>>;
774
774
  }, "strip", z.ZodTypeAny, {
775
775
  _id: import("mongoose").Types.ObjectId;
776
- select?: Record<string, 0 | 1> | undefined;
777
776
  populate?: any;
777
+ select?: Record<string, 0 | 1> | undefined;
778
778
  groupByCategories?: boolean | undefined;
779
779
  getParentCategory?: boolean | undefined;
780
780
  userOrderCompletionScope?: UserOrderCompletionScope | undefined;
781
781
  }, {
782
782
  _id: string | import("mongoose").Types.ObjectId;
783
- select?: Record<string, 0 | 1> | undefined;
784
783
  populate?: any;
784
+ select?: Record<string, 0 | 1> | undefined;
785
785
  groupByCategories?: boolean | undefined;
786
786
  getParentCategory?: boolean | undefined;
787
787
  userOrderCompletionScope?: UserOrderCompletionScope | undefined;
@@ -791,11 +791,11 @@ export declare const GetByTokenInputSchema: z.ZodOptional<z.ZodObject<{
791
791
  select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
792
792
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
793
793
  }, "strip", z.ZodTypeAny, {
794
- select?: Record<string, 0 | 1> | undefined;
795
794
  populate?: any;
796
- }, {
797
795
  select?: Record<string, 0 | 1> | undefined;
796
+ }, {
798
797
  populate?: any;
798
+ select?: Record<string, 0 | 1> | undefined;
799
799
  }>>;
800
800
  export type GetByTokenInputDTO = DTO<typeof GetByTokenInputSchema>;
801
801
  export declare const GetOneQuerySchema: z.ZodObject<{
@@ -803,12 +803,12 @@ export declare const GetOneQuerySchema: z.ZodObject<{
803
803
  select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
804
804
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
805
805
  }, "strip", z.ZodTypeAny, {
806
- select?: Record<string, 0 | 1> | undefined;
807
806
  populate?: any;
807
+ select?: Record<string, 0 | 1> | undefined;
808
808
  query?: Record<string, any> | undefined;
809
809
  }, {
810
- select?: Record<string, 0 | 1> | undefined;
811
810
  populate?: any;
811
+ select?: Record<string, 0 | 1> | undefined;
812
812
  query?: Record<string, any> | undefined;
813
813
  }>;
814
814
  export type GetOneQueryDTO = DTO<typeof GetOneQuerySchema>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.4.280",
3
+ "version": "1.4.282",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -1,19 +0,0 @@
1
- export interface AICompletionOptions {
2
- instructions?: string;
3
- temperature?: number;
4
- }
5
- export interface IAICompletionProvider {
6
- prompt(text: string, options?: AICompletionOptions): Promise<string>;
7
- generatePromptVariants(text: string, config: TextVariantConfig): Promise<TextVariantResult>;
8
- }
9
- export interface TextVariantConfig {
10
- isArabic?: boolean;
11
- isArabizi?: boolean;
12
- isArabicTransliteration?: boolean;
13
- }
14
- export interface TextVariantResult {
15
- original: string;
16
- arabic?: string[];
17
- arabizi?: string[];
18
- arabicTransliteration?: string[];
19
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"common-transliteration.js","sourceRoot":"/","sources":["libraries/transliteration/interfaces/common-transliteration.ts"],"names":[],"mappings":"","sourcesContent":["export interface AICompletionOptions {\n\tinstructions?: string;\n\ttemperature?: number;\n}\n\nexport interface IAICompletionProvider {\n\tprompt(text: string, options?: AICompletionOptions): Promise<string>;\n\tgeneratePromptVariants(text: string, config: TextVariantConfig): Promise<TextVariantResult>;\n}\n\nexport interface TextVariantConfig {\n\tisArabic?: boolean; // Arabic translation, Arabic script\n\tisArabizi?: boolean; // Arabic word, Latin script (e.g. \"zaytoon\")\n\tisArabicTransliteration?: boolean; // original word, spelled phonetically in Arabic script (e.g. \"أوليف\")\n}\n\nexport interface TextVariantResult {\n\toriginal: string;\n\tarabic?: string[];\n\tarabizi?: string[];\n\tarabicTransliteration?: string[];\t\n}"]}
@@ -1,10 +0,0 @@
1
- import { AICompletionOptions, IAICompletionProvider, TextVariantConfig, TextVariantResult } from '../interfaces/common-transliteration';
2
- export declare class OpenAICompletionProvider implements IAICompletionProvider {
3
- private readonly client;
4
- private readonly model;
5
- constructor(apiKey: string | undefined, model?: string);
6
- prompt(text: string, options?: AICompletionOptions): Promise<string>;
7
- generatePromptVariants(text: string, config: TextVariantConfig): Promise<TextVariantResult>;
8
- private buildVariantRequest;
9
- private buildJsonSchema;
10
- }
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.OpenAICompletionProvider = void 0;
7
- const openai_1 = __importDefault(require("openai"));
8
- class OpenAICompletionProvider {
9
- client;
10
- model;
11
- constructor(apiKey, model = 'gpt-5.5') {
12
- if (!apiKey) {
13
- throw new Error('OPENAI_API_KEY is required to construct OpenAICompletionProvider');
14
- }
15
- this.client = new openai_1.default({ apiKey });
16
- this.model = model;
17
- }
18
- async prompt(text, options) {
19
- const response = await this.client.responses.create({
20
- model: this.model,
21
- instructions: options?.instructions,
22
- input: text,
23
- });
24
- return response.output_text ?? '';
25
- }
26
- async generatePromptVariants(text, config) {
27
- console.log({ text, config });
28
- const { fields, instructions } = this.buildVariantRequest(config);
29
- if (fields.length === 0) {
30
- return { original: text };
31
- }
32
- const response = await this.client.responses.create({
33
- model: this.model,
34
- instructions,
35
- input: text,
36
- text: {
37
- format: {
38
- type: 'json_schema',
39
- name: 'text_variants',
40
- schema: this.buildJsonSchema(fields),
41
- strict: true,
42
- },
43
- },
44
- });
45
- console.log('generateTextVariants: ', { response });
46
- const parsedResult = JSON.parse(response.output_text ?? '{}');
47
- console.log('generateTextVariants: ', { parsedResult });
48
- return { original: text, ...parsedResult };
49
- }
50
- buildVariantRequest(config) {
51
- const fieldDescriptions = {
52
- arabic: 'The Arabic translation of the word/phrase, written in Arabic script (e.g. "زيتون" for "olive"). Provide 1-3 common variants if applicable.',
53
- arabizi: 'The Arabic word\'s meaning, written phonetically in Latin script/numerals — i.e. Arabizi (e.g. "zaytoon"). Provide 1-3 common spelling variants.',
54
- arabicTransliteration: 'The original word spelled phonetically in Arabic script, NOT translated (e.g. "أوليف" for "olive"). Useful when there is no native Arabic equivalent.',
55
- };
56
- const fields = [];
57
- if (config.isArabic)
58
- fields.push('arabic');
59
- if (config.isArabizi)
60
- fields.push('arabizi');
61
- if (config.isArabicTransliteration)
62
- fields.push('arabicTransliteration');
63
- const instructions = [
64
- 'You generate search-name variants for a food delivery app product/shop name.',
65
- 'For the given input text, return ONLY the following fields as arrays of strings:',
66
- ...fields.map(f => `- ${f}: ${fieldDescriptions[f]}`),
67
- 'Return strict JSON matching the schema. No extra commentary, no extra fields.',
68
- ].join('\n');
69
- return { fields, instructions };
70
- }
71
- buildJsonSchema(fields) {
72
- const properties = {};
73
- for (const field of fields) {
74
- properties[field] = { type: 'array', items: { type: 'string' } };
75
- }
76
- return {
77
- type: 'object',
78
- properties,
79
- required: fields,
80
- additionalProperties: false,
81
- };
82
- }
83
- }
84
- exports.OpenAICompletionProvider = OpenAICompletionProvider;
85
- //# sourceMappingURL=openai-provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"openai-provider.js","sourceRoot":"/","sources":["libraries/transliteration/providers/openai-provider.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAQ5B,MAAa,wBAAwB;IACnB,MAAM,CAAS;IACf,KAAK,CAAS;IAE/B,YAAY,MAA0B,EAAE,QAAgB,SAAS;QAChE,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;QACrF,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,OAA6B;QACvD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;YACnD,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,YAAY,EAAE,OAAO,EAAE,YAAY;YACnC,KAAK,EAAE,IAAI;SACX,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,WAAW,IAAI,EAAE,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,sBAAsB,CAAC,IAAY,EAAE,MAAyB;QACnE,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,EAAC,CAAC,CAAA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AC7C,IAAI,MAAM,CAAC,uBAAuB;YAAE,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;QAEzE,MAAM,YAAY,GAAG;YACpB,8EAA8E;YAC9E,kFAAkF;YAClF,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,iBAAiB,CAAC,CAAiD,CAAC,EAAE,CAAC;YACrG,+EAA+E;SAC/E,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEb,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;IACjC,CAAC;IAEO,eAAe,CAAC,MAAmC;QAC1D,MAAM,UAAU,GAAwB,EAAE,CAAC;QAC3C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC5B,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC;QAClE,CAAC;QAED,OAAO;YACN,IAAI,EAAE,QAAQ;YACd,UAAU;YACV,QAAQ,EAAE,MAAM;YAChB,oBAAoB,EAAE,KAAK;SAC3B,CAAC;IACH,CAAC;CACD;AA3FD,4DA2FC","sourcesContent":["import OpenAI from 'openai';\nimport {\n\tAICompletionOptions,\n\tIAICompletionProvider,\n\tTextVariantConfig,\n\tTextVariantResult,\n} from '../interfaces/common-transliteration';\n\nexport class OpenAICompletionProvider implements IAICompletionProvider {\n\tprivate readonly client: OpenAI;\n\tprivate readonly model: string;\n\n\tconstructor(apiKey: string | undefined, model: string = 'gpt-5.5') {\n\t\tif (!apiKey) {\n\t\t\tthrow new Error('OPENAI_API_KEY is required to construct OpenAICompletionProvider');\n\t\t}\n\t\tthis.client = new OpenAI({ apiKey });\n\t\tthis.model = model;\n\t}\n\n\tasync prompt(text: string, options?: AICompletionOptions): Promise<string> {\n\t\tconst response = await this.client.responses.create({\n\t\t\tmodel: this.model,\n\t\t\tinstructions: options?.instructions,\n\t\t\tinput: text,\n\t\t});\n\t\treturn response.output_text ?? '';\n\t}\n\n\tasync generatePromptVariants(text: string, config: TextVariantConfig): Promise<TextVariantResult> {\n\t\tconsole.log({ text, config})\n\t\tconst { fields, instructions } = this.buildVariantRequest(config);\n\n\t\tif (fields.length === 0) {\n\t\t\treturn { original: text };\n\t\t}\n\n\t\tconst response = await this.client.responses.create({\n\t\t\tmodel: this.model,\n\t\t\tinstructions,\n\t\t\tinput: text,\n\t\t\ttext: {\n\t\t\t\tformat: {\n\t\t\t\t\ttype: 'json_schema',\n\t\t\t\t\tname: 'text_variants',\n\t\t\t\t\tschema: this.buildJsonSchema(fields),\n\t\t\t\t\tstrict: true,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t\tconsole.log('generateTextVariants: ', { response })\n\t\tconst parsedResult = JSON.parse(response.output_text ?? '{}');\n\t\tconsole.log('generateTextVariants: ', { parsedResult })\n\t\treturn { original: text, ...parsedResult };\n\t}\n\n\t// ── Helpers ──────────────────────────────────────────────────────\n\n\tprivate buildVariantRequest(config: TextVariantConfig): {\n\t\tfields: (keyof TextVariantResult)[];\n\t\tinstructions: string;\n\t} {\n\t\tconst fieldDescriptions: Record<Exclude<keyof TextVariantResult, 'original'>, string> = {\n\t\t\tarabic:\n\t\t\t\t'The Arabic translation of the word/phrase, written in Arabic script (e.g. \"زيتون\" for \"olive\"). Provide 1-3 common variants if applicable.',\n\t\t\tarabizi:\n\t\t\t\t'The Arabic word\\'s meaning, written phonetically in Latin script/numerals — i.e. Arabizi (e.g. \"zaytoon\"). Provide 1-3 common spelling variants.',\n\t\t\tarabicTransliteration:\n\t\t\t\t'The original word spelled phonetically in Arabic script, NOT translated (e.g. \"أوليف\" for \"olive\"). Useful when there is no native Arabic equivalent.',\n\t\t};\n\n\t\tconst fields: (keyof TextVariantResult)[] = [];\n\t\tif (config.isArabic) fields.push('arabic');\n\t\tif (config.isArabizi) fields.push('arabizi');\n\t\tif (config.isArabicTransliteration) fields.push('arabicTransliteration');\n\n\t\tconst instructions = [\n\t\t\t'You generate search-name variants for a food delivery app product/shop name.',\n\t\t\t'For the given input text, return ONLY the following fields as arrays of strings:',\n\t\t\t...fields.map(f => `- ${f}: ${fieldDescriptions[f as Exclude<keyof TextVariantResult, 'original'>]}`),\n\t\t\t'Return strict JSON matching the schema. No extra commentary, no extra fields.',\n\t\t].join('\\n');\n\n\t\treturn { fields, instructions };\n\t}\n\n\tprivate buildJsonSchema(fields: (keyof TextVariantResult)[]) {\n\t\tconst properties: Record<string, any> = {};\n\t\tfor (const field of fields) {\n\t\t\tproperties[field] = { type: 'array', items: { type: 'string' } };\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'object',\n\t\t\tproperties,\n\t\t\trequired: fields,\n\t\t\tadditionalProperties: false,\n\t\t};\n\t}\n}\n"]}
@@ -1,14 +0,0 @@
1
- import { TextVariantConfig, TextVariantResult } from './interfaces/common-transliteration';
2
- export declare enum TransliterationProvider {
3
- OPENAI = "openai",
4
- GEMINI = "gemini"
5
- }
6
- export declare class TransliterationService {
7
- private readonly provider;
8
- private providerInstance;
9
- private readonly factories;
10
- constructor(provider: TransliterationProvider);
11
- translateToArabizi(text: string): Promise<string>;
12
- generatePromptVariants(text: string, config: TextVariantConfig): Promise<TextVariantResult>;
13
- private getProvider;
14
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"transliteration-service.js","sourceRoot":"/","sources":["libraries/transliteration/transliteration-service.ts"],"names":[],"mappings":";;;AAAA,6BAAqC;AACrC,+DAA+D;AAM/D,iEAAuE;AAEvE,IAAY,uBAGX;AAHD,WAAY,uBAAuB;IAClC,4CAAiB,CAAA;IACjB,4CAAiB,CAAA;AAClB,CAAC,EAHW,uBAAuB,uCAAvB,uBAAuB,QAGlC;AAID,MAAa,sBAAsB;IAgBL;IAfrB,gBAAgB,GAAiC,IAAI,CAAC;IAE7C,SAAS,GAAqD;QAC9E,CAAC,uBAAuB,CAAC,MAAM,CAAC,EAAE,KAAK,IAAI,EAA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D,IAAI,CAAC,gBAAgB,GAAG,MAAM,OAAO,EAAE,CAAC;QACzC,CAAC;QACD,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC9B,CAAC;CACD;AAxCD,wDAwCC","sourcesContent":["import { getLibraries } from '../..';\nimport { badRequestError } from '../../utilities/error-common';\nimport {\n\tIAICompletionProvider,\n\tTextVariantConfig,\n\tTextVariantResult,\n} from './interfaces/common-transliteration';\nimport { OpenAICompletionProvider } from './providers/openai-provider';\n\nexport enum TransliterationProvider {\n\tOPENAI = 'openai',\n\tGEMINI = 'gemini',\n}\n\ntype ProviderFactory = () => Promise<IAICompletionProvider>;\n\nexport class TransliterationService {\n\tprivate providerInstance: IAICompletionProvider | null = null;\n\n\tprivate readonly factories: Record<TransliterationProvider, ProviderFactory> = {\n\t\t[TransliterationProvider.OPENAI]: async () => {\n\t\t\tconst apiKey = await getLibraries().getSecretsService().getKey('OPENAI_API_KEY');\t\t\t\n\t\t\tif (!apiKey) {\n\t\t\t\tthrow badRequestError(`No API key found for provider ${TransliterationProvider.OPENAI}`);\n\t\t\t}\n\t\t\treturn new OpenAICompletionProvider(apiKey, 'gpt-5.5');\n\t\t},\n\t\t[TransliterationProvider.GEMINI]: async () => {\n\t\t\tthrow badRequestError(`Provider ${TransliterationProvider.GEMINI} is not implemented yet`);\n\t\t},\n\t};\n\n\tconstructor(private readonly provider: TransliterationProvider) {}\n\n\tasync translateToArabizi(text: string): Promise<string> {\n\t\tconst provider = await this.getProvider();\n\t\treturn provider.prompt(text, {\n\t\t\tinstructions: 'You are a translation assistant. Translate the given text to Arabizi.',\n\t\t});\n\t}\n\n\tasync generatePromptVariants(text: string, config: TextVariantConfig): Promise<TextVariantResult> {\n\t\tconst provider = await this.getProvider();\n\t\treturn provider.generatePromptVariants(text, config);\n\t}\n\n\tprivate async getProvider(): Promise<IAICompletionProvider> {\n\t\tif (!this.providerInstance) {\n\t\t\tconst factory = this.factories[this.provider];\n\t\t\tif (!factory) {\n\t\t\t\tthrow badRequestError(`Unsupported transliteration provider: ${this.provider}`);\n\t\t\t}\n\t\t\tthis.providerInstance = await factory();\n\t\t}\n\t\treturn this.providerInstance;\n\t}\n}\n"]}