quickblox 2.21.5-alpha.2 → 2.21.5-alpha.3

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "quickblox",
3
3
  "description": "QuickBlox JavaScript SDK",
4
- "version": "2.21.5-alpha.2",
4
+ "version": "2.21.5-alpha.3",
5
5
  "homepage": "https://quickblox.com/developers/Javascript",
6
6
  "main": "src/qbMain.js",
7
7
  "types": "quickblox.d.ts",
package/quickblox.d.ts CHANGED
@@ -485,6 +485,37 @@ export interface AIAnswerResponse {
485
485
 
486
486
  export declare type AIChatHistory = AIChatMessage[] | null | undefined;
487
487
 
488
+ // AI Gateway types
489
+ export interface AIGatewayTextContent {
490
+ type: 'text';
491
+ text: string;
492
+ }
493
+
494
+ export interface AIGatewayImageContent {
495
+ type: 'image_url';
496
+ image_url: {
497
+ url: string;
498
+ };
499
+ }
500
+
501
+ export type AIGatewayContentItem = AIGatewayTextContent | AIGatewayImageContent;
502
+
503
+ export type AIGatewayRole = 'user' | 'assistant' | 'developer';
504
+
505
+ export interface AIGatewayMessage {
506
+ role: AIGatewayRole;
507
+ content: AIGatewayContentItem[];
508
+ }
509
+
510
+ export interface AIGatewayOptions {
511
+ apiKey?: string;
512
+ }
513
+
514
+ // AI Summarize response
515
+ export interface AISummarizeResponse {
516
+ summary: string;
517
+ }
518
+
488
519
  interface QBAIModule{
489
520
  //QB.ai.answerAssist
490
521
  answerAssist(smartChatAssistantId: string,
@@ -497,6 +528,21 @@ interface QBAIModule{
497
528
  languageCode: string,
498
529
  callback: QBCallback<AIAnswerResponse>): void
499
530
 
531
+ //QB.ai.gateway
532
+ gateway(smartChatAssistantId: string,
533
+ messages: AIGatewayMessage[],
534
+ callback: QBCallback<AIAnswerResponse>): void
535
+
536
+ gateway(smartChatAssistantId: string,
537
+ messages: AIGatewayMessage[],
538
+ options: AIGatewayOptions,
539
+ callback: QBCallback<AIAnswerResponse>): void
540
+
541
+ //QB.ai.summarize
542
+ summarize(smartChatAssistantId: string,
543
+ dialogId: string,
544
+ callback: QBCallback<AISummarizeResponse>): void
545
+
500
546
  }
501
547
 
502
548
  interface QBChatModule {
package/quickblox.js CHANGED
@@ -50160,6 +50160,210 @@ AIProxy.prototype = {
50160
50160
  this.service.ajax(attrAjax, callback);
50161
50161
  },
50162
50162
 
50163
+ /**
50164
+ * AI Gateway - multimodal AI endpoint supporting text and images in OpenAI-compatible format
50165
+ * ({@link https://docs.quickblox.com/reference/ai-extensions-ai-gateway read more}).
50166
+ * @memberof QB.ai
50167
+ * @param {String} smartChatAssistantId - Smart Chat Assistant id.
50168
+ * @param {Object[]} messages - Array of message objects. Each message has:
50169
+ * - role: 'user' | 'assistant' | 'developer'
50170
+ * - content: Array of content items (text or image_url)
50171
+ * @param {Object} [options] - Optional configuration.
50172
+ * @param {String} [options.apiKey] - API key for authorization (alternative to session token).
50173
+ * @param {gatewayCallback} callback - The callback function.
50174
+ * @example
50175
+ * var messages = [
50176
+ * {
50177
+ * role: 'user',
50178
+ * content: [
50179
+ * { type: 'text', text: 'What is in this image?' },
50180
+ * { type: 'image_url', image_url: { url: 'https://example.com/image.jpg' } }
50181
+ * ]
50182
+ * }
50183
+ * ];
50184
+ * QB.ai.gateway(smartChatAssistantId, messages, function(err, res) {
50185
+ * console.log(res.answer);
50186
+ * });
50187
+ * // With API key:
50188
+ * QB.ai.gateway(smartChatAssistantId, messages, { apiKey: 'your_api_key' }, callback);
50189
+ */
50190
+ gateway: function(smartChatAssistantId, messages, optionsOrCallback, callback) {
50191
+ /**
50192
+ * Callback for QB.ai.gateway().
50193
+ * @param {Object} error - The error object.
50194
+ * @param {Object} response - The server response object.
50195
+ * @param {String} [response.answer] - AI generated response.
50196
+ * @callback gatewayCallback
50197
+ */
50198
+
50199
+ // Handle optional options parameter
50200
+ var options, cb;
50201
+ if (typeof optionsOrCallback === 'function') {
50202
+ cb = optionsOrCallback;
50203
+ options = {};
50204
+ } else {
50205
+ options = optionsOrCallback || {};
50206
+ cb = callback;
50207
+ }
50208
+
50209
+ // Validate callback
50210
+ if (!cb || typeof cb !== 'function') {
50211
+ throw new Error('Callback function is required and must be a function');
50212
+ }
50213
+
50214
+ // Validate smartChatAssistantId
50215
+ if (!smartChatAssistantId || typeof smartChatAssistantId !== 'string') {
50216
+ throw new Error('smartChatAssistantId is required and must be a string');
50217
+ }
50218
+
50219
+ // Validate messages
50220
+ this._validateGatewayMessages(messages);
50221
+
50222
+ // Build request data
50223
+ var data = {
50224
+ smart_chat_assistant_id: smartChatAssistantId,
50225
+ messages: messages
50226
+ };
50227
+
50228
+ // Build ajax options
50229
+ var attrAjax = {
50230
+ 'type': 'POST',
50231
+ 'url': Utils.formatUrl(AI_API_URL + '/ai_gateway'),
50232
+ 'data': data,
50233
+ 'contentType': 'application/json; charset=utf-8',
50234
+ 'isNeedStringify': true
50235
+ };
50236
+
50237
+ // Add API key header if provided
50238
+ if (options.apiKey) {
50239
+ attrAjax.headers = {
50240
+ 'Authorization': 'ApiKey ' + options.apiKey
50241
+ };
50242
+ }
50243
+
50244
+ this.service.ajax(attrAjax, cb);
50245
+ },
50246
+
50247
+ /**
50248
+ * Validate gateway messages array
50249
+ * @private
50250
+ * @param {Object[]} messages - Array of message objects to validate.
50251
+ * @throws {Error} If messages array is invalid.
50252
+ */
50253
+ _validateGatewayMessages: function(messages) {
50254
+ var validRoles = ['user', 'assistant', 'developer'];
50255
+ var validContentTypes = ['text', 'image_url'];
50256
+
50257
+ if (!messages || !Array.isArray(messages)) {
50258
+ throw new Error('messages is required and must be an array');
50259
+ }
50260
+
50261
+ if (messages.length === 0) {
50262
+ throw new Error('messages array cannot be empty');
50263
+ }
50264
+
50265
+ for (var i = 0; i < messages.length; i++) {
50266
+ var msg = messages[i];
50267
+
50268
+ // Check message is object
50269
+ if (typeof msg !== 'object' || msg === null || Array.isArray(msg)) {
50270
+ throw new Error('Each message must be an object');
50271
+ }
50272
+
50273
+ // Check role
50274
+ if (!msg.role || validRoles.indexOf(msg.role) === -1) {
50275
+ throw new Error('Each message must have a valid role (user, assistant, or developer)');
50276
+ }
50277
+
50278
+ // Check content
50279
+ if (!msg.content || !Array.isArray(msg.content)) {
50280
+ throw new Error('Each message must have a content array');
50281
+ }
50282
+
50283
+ if (msg.content.length === 0) {
50284
+ throw new Error('Message content array cannot be empty');
50285
+ }
50286
+
50287
+ // Validate each content item
50288
+ for (var j = 0; j < msg.content.length; j++) {
50289
+ var item = msg.content[j];
50290
+
50291
+ if (typeof item !== 'object' || item === null) {
50292
+ throw new Error('Each content item must be an object');
50293
+ }
50294
+
50295
+ if (!item.type || validContentTypes.indexOf(item.type) === -1) {
50296
+ throw new Error('Each content item must have a valid type (text or image_url)');
50297
+ }
50298
+
50299
+ if (item.type === 'text') {
50300
+ if (typeof item.text !== 'string') {
50301
+ throw new Error('Text content item must have a text string');
50302
+ }
50303
+ } else if (item.type === 'image_url') {
50304
+ if (!item.image_url || typeof item.image_url.url !== 'string') {
50305
+ throw new Error('Image content item must have image_url.url string');
50306
+ }
50307
+ }
50308
+ }
50309
+ }
50310
+
50311
+ return true;
50312
+ },
50313
+
50314
+ /**
50315
+ * AI Summarize - generates a summary of dialog messages (up to 1000 most recent)
50316
+ * ({@link https://docs.quickblox.com/reference/ai-extensions-ai-summarize read more}).
50317
+ * @memberof QB.ai
50318
+ * @param {String} smartChatAssistantId - Smart Chat Assistant id.
50319
+ * @param {String} dialogId - Dialog id to summarize.
50320
+ * @param {summarizeCallback} callback - The callback function.
50321
+ * @example
50322
+ * QB.ai.summarize(smartChatAssistantId, dialogId, function(err, res) {
50323
+ * console.log(res.summary);
50324
+ * });
50325
+ */
50326
+ summarize: function(smartChatAssistantId, dialogId, callback) {
50327
+ /**
50328
+ * Callback for QB.ai.summarize().
50329
+ * @param {Object} error - The error object.
50330
+ * @param {Object} response - The server response object.
50331
+ * @param {String} [response.summary] - Generated summary of the dialog.
50332
+ * @callback summarizeCallback
50333
+ */
50334
+
50335
+ // Validate callback
50336
+ if (!callback || typeof callback !== 'function') {
50337
+ throw new Error('Callback function is required and must be a function');
50338
+ }
50339
+
50340
+ // Validate smartChatAssistantId
50341
+ if (!smartChatAssistantId || typeof smartChatAssistantId !== 'string') {
50342
+ throw new Error('smartChatAssistantId is required and must be a string');
50343
+ }
50344
+
50345
+ // Validate dialogId
50346
+ if (!dialogId || typeof dialogId !== 'string') {
50347
+ throw new Error('dialogId is required and must be a string');
50348
+ }
50349
+
50350
+ // Build request data
50351
+ var data = {
50352
+ smart_chat_assistant_id: smartChatAssistantId,
50353
+ dialog_id: dialogId
50354
+ };
50355
+
50356
+ // Build ajax options
50357
+ var attrAjax = {
50358
+ 'type': 'POST',
50359
+ 'url': Utils.formatUrl(AI_API_URL + '/ai_summarize'),
50360
+ 'data': data,
50361
+ 'contentType': 'application/json; charset=utf-8',
50362
+ 'isNeedStringify': true
50363
+ };
50364
+
50365
+ this.service.ajax(attrAjax, callback);
50366
+ },
50163
50367
 
50164
50368
  };
50165
50369
 
@@ -55133,7 +55337,7 @@ module.exports = StreamManagement;
55133
55337
 
55134
55338
  var config = {
55135
55339
  version: '2.21.5',
55136
- buildNumber: '1172',
55340
+ buildNumber: '1173',
55137
55341
  creds: {
55138
55342
  'appId': 0,
55139
55343
  'authKey': '',
@@ -55826,6 +56030,13 @@ ServiceProxy.prototype = {
55826
56030
  }
55827
56031
  }
55828
56032
 
56033
+ // Support custom headers (e.g., for Authorization: ApiKey)
56034
+ if (params.headers) {
56035
+ Object.keys(params.headers).forEach(function(key) {
56036
+ qbRequest.headers[key] = params.headers[key];
56037
+ });
56038
+ }
56039
+
55829
56040
  if (config.timeout) {
55830
56041
  qbRequest.timeout = config.timeout;
55831
56042
  }