librechat-data-provider 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import axios from 'axios';
2
+ import { z } from 'zod';
2
3
  import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
3
4
 
4
5
  /******************************************************************************
@@ -336,19 +337,301 @@ var EModelEndpoint;
336
337
  EModelEndpoint["azureOpenAI"] = "azureOpenAI";
337
338
  EModelEndpoint["openAI"] = "openAI";
338
339
  EModelEndpoint["bingAI"] = "bingAI";
339
- EModelEndpoint["chatGPT"] = "chatGPT";
340
340
  EModelEndpoint["chatGPTBrowser"] = "chatGPTBrowser";
341
341
  EModelEndpoint["google"] = "google";
342
342
  EModelEndpoint["gptPlugins"] = "gptPlugins";
343
343
  EModelEndpoint["anthropic"] = "anthropic";
344
344
  })(EModelEndpoint || (EModelEndpoint = {}));
345
- var Side;
346
- (function (Side) {
347
- Side["Top"] = "top";
348
- Side["Right"] = "right";
349
- Side["Bottom"] = "bottom";
350
- Side["Left"] = "left";
351
- })(Side || (Side = {}));
345
+ var eModelEndpointSchema = z.nativeEnum(EModelEndpoint);
346
+ var tMessageSchema = z.object({
347
+ messageId: z.string(),
348
+ clientId: z.string().nullable().optional(),
349
+ conversationId: z.string().nullable(),
350
+ parentMessageId: z.string().nullable(),
351
+ sender: z.string(),
352
+ text: z.string(),
353
+ isCreatedByUser: z.boolean(),
354
+ error: z.boolean(),
355
+ createdAt: z
356
+ .string()
357
+ .optional()
358
+ .default(function () { return new Date().toISOString(); }),
359
+ updatedAt: z
360
+ .string()
361
+ .optional()
362
+ .default(function () { return new Date().toISOString(); }),
363
+ current: z.boolean().optional(),
364
+ unfinished: z.boolean().optional(),
365
+ submitting: z.boolean().optional(),
366
+ searchResult: z.boolean().optional(),
367
+ finish_reason: z.string().optional(),
368
+ });
369
+ var tPluginAuthConfigSchema = z.object({
370
+ authField: z.string(),
371
+ label: z.string(),
372
+ description: z.string(),
373
+ });
374
+ var tPluginSchema = z.object({
375
+ name: z.string(),
376
+ pluginKey: z.string(),
377
+ description: z.string(),
378
+ icon: z.string(),
379
+ authConfig: z.array(tPluginAuthConfigSchema),
380
+ authenticated: z.boolean().optional(),
381
+ isButton: z.boolean().optional(),
382
+ });
383
+ var tExampleSchema = z.object({
384
+ input: z.object({
385
+ content: z.string(),
386
+ }),
387
+ output: z.object({
388
+ content: z.string(),
389
+ }),
390
+ });
391
+ var tAgentOptionsSchema = z.object({
392
+ agent: z.string(),
393
+ skipCompletion: z.boolean(),
394
+ model: z.string(),
395
+ temperature: z.number(),
396
+ });
397
+ var tConversationSchema = z.object({
398
+ conversationId: z.string().nullable(),
399
+ title: z.string(),
400
+ user: z.string().optional(),
401
+ endpoint: eModelEndpointSchema.nullable(),
402
+ suggestions: z.array(z.string()).optional(),
403
+ messages: z.array(z.string()).optional(),
404
+ tools: z.array(tPluginSchema).optional(),
405
+ createdAt: z.string(),
406
+ updatedAt: z.string(),
407
+ systemMessage: z.string().nullable().optional(),
408
+ modelLabel: z.string().nullable().optional(),
409
+ examples: z.array(tExampleSchema).optional(),
410
+ chatGptLabel: z.string().nullable().optional(),
411
+ userLabel: z.string().optional(),
412
+ model: z.string().nullable().optional(),
413
+ promptPrefix: z.string().nullable().optional(),
414
+ temperature: z.number().optional(),
415
+ topP: z.number().optional(),
416
+ topK: z.number().optional(),
417
+ context: z.string().nullable().optional(),
418
+ top_p: z.number().optional(),
419
+ frequency_penalty: z.number().optional(),
420
+ presence_penalty: z.number().optional(),
421
+ jailbreak: z.boolean().optional(),
422
+ jailbreakConversationId: z.string().nullable().optional(),
423
+ conversationSignature: z.string().nullable().optional(),
424
+ parentMessageId: z.string().optional(),
425
+ clientId: z.string().nullable().optional(),
426
+ invocationId: z.number().nullable().optional(),
427
+ toneStyle: z.string().nullable().optional(),
428
+ maxOutputTokens: z.number().optional(),
429
+ agentOptions: tAgentOptionsSchema.nullable().optional(),
430
+ });
431
+ var tPresetSchema = tConversationSchema
432
+ .omit({
433
+ conversationId: true,
434
+ createdAt: true,
435
+ updatedAt: true,
436
+ title: true,
437
+ })
438
+ .merge(z.object({
439
+ conversationId: z.string().optional(),
440
+ presetId: z.string().nullable().optional(),
441
+ title: z.string().nullable().optional(),
442
+ }));
443
+ var openAISchema = tConversationSchema
444
+ .pick({
445
+ model: true,
446
+ chatGptLabel: true,
447
+ promptPrefix: true,
448
+ temperature: true,
449
+ top_p: true,
450
+ presence_penalty: true,
451
+ frequency_penalty: true,
452
+ })
453
+ .transform(function (obj) {
454
+ var _a, _b, _c, _d, _e, _f, _g;
455
+ return (__assign(__assign({}, obj), { model: (_a = obj.model) !== null && _a !== void 0 ? _a : 'gpt-3.5-turbo', chatGptLabel: (_b = obj.chatGptLabel) !== null && _b !== void 0 ? _b : null, promptPrefix: (_c = obj.promptPrefix) !== null && _c !== void 0 ? _c : null, temperature: (_d = obj.temperature) !== null && _d !== void 0 ? _d : 1, top_p: (_e = obj.top_p) !== null && _e !== void 0 ? _e : 1, presence_penalty: (_f = obj.presence_penalty) !== null && _f !== void 0 ? _f : 0, frequency_penalty: (_g = obj.frequency_penalty) !== null && _g !== void 0 ? _g : 0 }));
456
+ })
457
+ .catch(function () { return ({
458
+ model: 'gpt-3.5-turbo',
459
+ chatGptLabel: null,
460
+ promptPrefix: null,
461
+ temperature: 1,
462
+ top_p: 1,
463
+ presence_penalty: 0,
464
+ frequency_penalty: 0,
465
+ }); });
466
+ var googleSchema = tConversationSchema
467
+ .pick({
468
+ model: true,
469
+ modelLabel: true,
470
+ promptPrefix: true,
471
+ examples: true,
472
+ temperature: true,
473
+ maxOutputTokens: true,
474
+ topP: true,
475
+ topK: true,
476
+ })
477
+ .transform(function (obj) {
478
+ var _a, _b, _c, _d, _e, _f, _g;
479
+ return (__assign(__assign({}, obj), { model: (_a = obj.model) !== null && _a !== void 0 ? _a : 'chat-bison', modelLabel: (_b = obj.modelLabel) !== null && _b !== void 0 ? _b : null, promptPrefix: (_c = obj.promptPrefix) !== null && _c !== void 0 ? _c : null, temperature: (_d = obj.temperature) !== null && _d !== void 0 ? _d : 0.2, maxOutputTokens: (_e = obj.maxOutputTokens) !== null && _e !== void 0 ? _e : 1024, topP: (_f = obj.topP) !== null && _f !== void 0 ? _f : 0.95, topK: (_g = obj.topK) !== null && _g !== void 0 ? _g : 40 }));
480
+ })
481
+ .catch(function () { return ({
482
+ model: 'chat-bison',
483
+ modelLabel: null,
484
+ promptPrefix: null,
485
+ temperature: 0.2,
486
+ maxOutputTokens: 1024,
487
+ topP: 0.95,
488
+ topK: 40,
489
+ }); });
490
+ var bingAISchema = tConversationSchema
491
+ .pick({
492
+ jailbreak: true,
493
+ systemMessage: true,
494
+ context: true,
495
+ toneStyle: true,
496
+ jailbreakConversationId: true,
497
+ conversationSignature: true,
498
+ clientId: true,
499
+ invocationId: true,
500
+ })
501
+ .transform(function (obj) {
502
+ var _a, _b, _c, _d, _e, _f, _g, _h;
503
+ return (__assign(__assign({}, obj), { model: '', jailbreak: (_a = obj.jailbreak) !== null && _a !== void 0 ? _a : false, systemMessage: (_b = obj.systemMessage) !== null && _b !== void 0 ? _b : null, context: (_c = obj.context) !== null && _c !== void 0 ? _c : null, toneStyle: (_d = obj.toneStyle) !== null && _d !== void 0 ? _d : 'creative', jailbreakConversationId: (_e = obj.jailbreakConversationId) !== null && _e !== void 0 ? _e : null, conversationSignature: (_f = obj.conversationSignature) !== null && _f !== void 0 ? _f : null, clientId: (_g = obj.clientId) !== null && _g !== void 0 ? _g : null, invocationId: (_h = obj.invocationId) !== null && _h !== void 0 ? _h : 1 }));
504
+ })
505
+ .catch(function () { return ({
506
+ model: '',
507
+ jailbreak: false,
508
+ systemMessage: null,
509
+ context: null,
510
+ toneStyle: 'creative',
511
+ jailbreakConversationId: null,
512
+ conversationSignature: null,
513
+ clientId: null,
514
+ invocationId: 1,
515
+ }); });
516
+ var anthropicSchema = tConversationSchema
517
+ .pick({
518
+ model: true,
519
+ modelLabel: true,
520
+ promptPrefix: true,
521
+ temperature: true,
522
+ maxOutputTokens: true,
523
+ topP: true,
524
+ topK: true,
525
+ })
526
+ .transform(function (obj) {
527
+ var _a, _b, _c, _d, _e, _f, _g;
528
+ return (__assign(__assign({}, obj), { model: (_a = obj.model) !== null && _a !== void 0 ? _a : 'claude-1', modelLabel: (_b = obj.modelLabel) !== null && _b !== void 0 ? _b : null, promptPrefix: (_c = obj.promptPrefix) !== null && _c !== void 0 ? _c : null, temperature: (_d = obj.temperature) !== null && _d !== void 0 ? _d : 1, maxOutputTokens: (_e = obj.maxOutputTokens) !== null && _e !== void 0 ? _e : 1024, topP: (_f = obj.topP) !== null && _f !== void 0 ? _f : 0.7, topK: (_g = obj.topK) !== null && _g !== void 0 ? _g : 5 }));
529
+ })
530
+ .catch(function () { return ({
531
+ model: 'claude-1',
532
+ modelLabel: null,
533
+ promptPrefix: null,
534
+ temperature: 1,
535
+ maxOutputTokens: 1024,
536
+ topP: 0.7,
537
+ topK: 5,
538
+ }); });
539
+ var chatGPTBrowserSchema = tConversationSchema
540
+ .pick({
541
+ model: true,
542
+ })
543
+ .transform(function (obj) {
544
+ var _a;
545
+ return (__assign(__assign({}, obj), { model: (_a = obj.model) !== null && _a !== void 0 ? _a : 'text-davinci-002-render-sha' }));
546
+ })
547
+ .catch(function () { return ({
548
+ model: 'text-davinci-002-render-sha',
549
+ }); });
550
+ var gptPluginsSchema = tConversationSchema
551
+ .pick({
552
+ model: true,
553
+ chatGptLabel: true,
554
+ promptPrefix: true,
555
+ temperature: true,
556
+ top_p: true,
557
+ presence_penalty: true,
558
+ frequency_penalty: true,
559
+ tools: true,
560
+ agentOptions: true,
561
+ })
562
+ .transform(function (obj) {
563
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
564
+ return (__assign(__assign({}, obj), { model: (_a = obj.model) !== null && _a !== void 0 ? _a : 'gpt-3.5-turbo', chatGptLabel: (_b = obj.chatGptLabel) !== null && _b !== void 0 ? _b : null, promptPrefix: (_c = obj.promptPrefix) !== null && _c !== void 0 ? _c : null, temperature: (_d = obj.temperature) !== null && _d !== void 0 ? _d : 0.8, top_p: (_e = obj.top_p) !== null && _e !== void 0 ? _e : 1, presence_penalty: (_f = obj.presence_penalty) !== null && _f !== void 0 ? _f : 0, frequency_penalty: (_g = obj.frequency_penalty) !== null && _g !== void 0 ? _g : 0, tools: (_h = obj.tools) !== null && _h !== void 0 ? _h : [], agentOptions: (_j = obj.agentOptions) !== null && _j !== void 0 ? _j : {
565
+ agent: 'functions',
566
+ skipCompletion: true,
567
+ model: 'gpt-3.5-turbo',
568
+ temperature: 0,
569
+ } }));
570
+ })
571
+ .catch(function () { return ({
572
+ model: 'gpt-3.5-turbo',
573
+ chatGptLabel: null,
574
+ promptPrefix: null,
575
+ temperature: 0.8,
576
+ top_p: 1,
577
+ presence_penalty: 0,
578
+ frequency_penalty: 0,
579
+ tools: [],
580
+ agentOptions: {
581
+ agent: 'functions',
582
+ skipCompletion: true,
583
+ model: 'gpt-3.5-turbo',
584
+ temperature: 0,
585
+ },
586
+ }); });
587
+ var endpointSchemas = {
588
+ openAI: openAISchema,
589
+ azureOpenAI: openAISchema,
590
+ google: googleSchema,
591
+ bingAI: bingAISchema,
592
+ anthropic: anthropicSchema,
593
+ chatGPTBrowser: chatGPTBrowserSchema,
594
+ gptPlugins: gptPluginsSchema,
595
+ };
596
+ function getFirstDefinedValue(possibleValues) {
597
+ var returnValue;
598
+ for (var _i = 0, possibleValues_1 = possibleValues; _i < possibleValues_1.length; _i++) {
599
+ var value = possibleValues_1[_i];
600
+ if (value) {
601
+ returnValue = value;
602
+ break;
603
+ }
604
+ }
605
+ return returnValue;
606
+ }
607
+ var parseConvo = function (endpoint, conversation, possibleValues) {
608
+ var _a;
609
+ var schema = endpointSchemas[endpoint];
610
+ if (!schema) {
611
+ throw new Error("Unknown endpoint: ".concat(endpoint));
612
+ }
613
+ var convo = schema.parse(conversation);
614
+ if (possibleValues && convo) {
615
+ convo.model = (_a = getFirstDefinedValue(possibleValues.model)) !== null && _a !== void 0 ? _a : convo.model;
616
+ }
617
+ return convo;
618
+ };
619
+ var getResponseSender = function (endpointOption) {
620
+ var endpoint = endpointOption.endpoint, chatGptLabel = endpointOption.chatGptLabel, modelLabel = endpointOption.modelLabel, jailbreak = endpointOption.jailbreak;
621
+ if (['openAI', 'azureOpenAI', 'gptPlugins', 'chatGPTBrowser'].includes(endpoint)) {
622
+ return chatGptLabel !== null && chatGptLabel !== void 0 ? chatGptLabel : 'ChatGPT';
623
+ }
624
+ if (endpoint === 'bingAI') {
625
+ return jailbreak ? 'Sydney' : 'BingAI';
626
+ }
627
+ if (endpoint === 'anthropic') {
628
+ return modelLabel !== null && modelLabel !== void 0 ? modelLabel : 'Anthropic';
629
+ }
630
+ if (endpoint === 'google') {
631
+ return modelLabel !== null && modelLabel !== void 0 ? modelLabel : 'PaLM2';
632
+ }
633
+ return '';
634
+ };
352
635
 
353
636
  var QueryKeys;
354
637
  (function (QueryKeys) {
@@ -384,7 +667,7 @@ var useGetConversationByIdQuery = function (id, config) {
384
667
  var useGetConversationByIdMutation = function (id) {
385
668
  var queryClient = useQueryClient();
386
669
  return useMutation(function () { return getConversationById(id); }, {
387
- // onSuccess: (res: t.TConversation) => {
670
+ // onSuccess: (res: s.TConversation) => {
388
671
  onSuccess: function () {
389
672
  queryClient.invalidateQueries([QueryKeys.conversation, id]);
390
673
  },
@@ -759,8 +1042,8 @@ var SSE = function (url, options) {
759
1042
  // }
760
1043
 
761
1044
  function createPayload(submission) {
762
- var conversation = submission.conversation, message = submission.message, endpointOption = submission.endpointOption;
763
- var conversationId = conversation.conversationId;
1045
+ var conversation = submission.conversation, message = submission.message, endpointOption = submission.endpointOption, isEdited = submission.isEdited;
1046
+ var conversationId = tConversationSchema.parse(conversation).conversationId;
764
1047
  var endpoint = endpointOption.endpoint;
765
1048
  var endpointUrlMap = {
766
1049
  azureOpenAI: '/api/ask/azureOpenAI',
@@ -773,8 +1056,11 @@ function createPayload(submission) {
773
1056
  anthropic: '/api/ask/anthropic',
774
1057
  };
775
1058
  var server = endpointUrlMap[endpoint];
1059
+ if (isEdited) {
1060
+ server = server.replace('/ask/', '/edit/');
1061
+ }
776
1062
  var payload = __assign(__assign(__assign({}, message), endpointOption), { conversationId: conversationId });
777
1063
  return { server: server, payload: payload };
778
1064
  }
779
1065
 
780
- export { EModelEndpoint, QueryKeys, SSE, Side, abortRequestWithMessage, clearAllConversations, createPayload, createPreset, deleteConversation, deletePreset, getAIEndpoints, getAvailablePlugins, getConversationById, getConversations, getLoginGoogle, getMessagesByConvoId, getPresets, getSearchEnabled, getStartupConfig, getUser, login, logout, refreshToken, register, requestPasswordReset, resetPassword, searchConversations, setAcceptLanguageHeader, setTokenHeader, updateConversation, updatePreset, updateTokenCount, updateUserPlugins, useAbortRequestWithMessage, useAvailablePluginsQuery, useClearConversationsMutation, useCreatePresetMutation, useDeleteConversationMutation, useDeletePresetMutation, useGetConversationByIdMutation, useGetConversationByIdQuery, useGetConversationsQuery, useGetEndpointsQuery, useGetMessagesByConvoId, useGetPresetsQuery, useGetSearchEnabledQuery, useGetStartupConfig, useGetUserQuery, useLoginUserMutation, useLogoutUserMutation, useRefreshTokenMutation, useRegisterUserMutation, useRequestPasswordResetMutation, useResetPasswordMutation, useSearchQuery, useUpdateConversationMutation, useUpdatePresetMutation, useUpdateTokenCountMutation, useUpdateUserPluginsMutation };
1066
+ export { EModelEndpoint, QueryKeys, SSE, abortRequestWithMessage, anthropicSchema, bingAISchema, chatGPTBrowserSchema, clearAllConversations, createPayload, createPreset, deleteConversation, deletePreset, eModelEndpointSchema, getAIEndpoints, getAvailablePlugins, getConversationById, getConversations, getLoginGoogle, getMessagesByConvoId, getPresets, getResponseSender, getSearchEnabled, getStartupConfig, getUser, googleSchema, gptPluginsSchema, login, logout, openAISchema, parseConvo, refreshToken, register, requestPasswordReset, resetPassword, searchConversations, setAcceptLanguageHeader, setTokenHeader, tAgentOptionsSchema, tConversationSchema, tExampleSchema, tMessageSchema, tPluginAuthConfigSchema, tPluginSchema, tPresetSchema, updateConversation, updatePreset, updateTokenCount, updateUserPlugins, useAbortRequestWithMessage, useAvailablePluginsQuery, useClearConversationsMutation, useCreatePresetMutation, useDeleteConversationMutation, useDeletePresetMutation, useGetConversationByIdMutation, useGetConversationByIdQuery, useGetConversationsQuery, useGetEndpointsQuery, useGetMessagesByConvoId, useGetPresetsQuery, useGetSearchEnabledQuery, useGetStartupConfig, useGetUserQuery, useLoginUserMutation, useLogoutUserMutation, useRefreshTokenMutation, useRegisterUserMutation, useRequestPasswordResetMutation, useResetPasswordMutation, useSearchQuery, useUpdateConversationMutation, useUpdatePresetMutation, useUpdateTokenCountMutation, useUpdateUserPluginsMutation };