librechat-data-provider 0.1.2 → 0.1.4

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
  /******************************************************************************
@@ -342,6 +343,101 @@ var EModelEndpoint;
342
343
  EModelEndpoint["gptPlugins"] = "gptPlugins";
343
344
  EModelEndpoint["anthropic"] = "anthropic";
344
345
  })(EModelEndpoint || (EModelEndpoint = {}));
346
+ var eModelEndpointSchema = z.nativeEnum(EModelEndpoint);
347
+ var tMessageSchema = z.object({
348
+ messageId: z.string(),
349
+ conversationId: z.string(),
350
+ clientId: z.string(),
351
+ parentMessageId: z.string(),
352
+ sender: z.string(),
353
+ text: z.string(),
354
+ isCreatedByUser: z.boolean(),
355
+ error: z.boolean(),
356
+ createdAt: z.string(),
357
+ updatedAt: z.string(),
358
+ });
359
+ var tPluginAuthConfigSchema = z.object({
360
+ authField: z.string(),
361
+ label: z.string(),
362
+ description: z.string(),
363
+ });
364
+ var tPluginSchema = z.object({
365
+ name: z.string(),
366
+ pluginKey: z.string(),
367
+ description: z.string(),
368
+ icon: z.string(),
369
+ authConfig: z.array(tPluginAuthConfigSchema),
370
+ authenticated: z.boolean().optional(),
371
+ isButton: z.boolean().optional(),
372
+ });
373
+ var tExampleSchema = z.object({
374
+ input: z.object({
375
+ content: z.string(),
376
+ }),
377
+ output: z.object({
378
+ content: z.string(),
379
+ }),
380
+ });
381
+ var tAgentOptionsSchema = z.object({
382
+ agent: z.string(),
383
+ skipCompletion: z.boolean(),
384
+ model: z.string(),
385
+ temperature: z.number(),
386
+ });
387
+ var tConversationSchema = z.object({
388
+ conversationId: z.string().nullable(),
389
+ title: z.string(),
390
+ user: z.string().optional(),
391
+ endpoint: eModelEndpointSchema.nullable(),
392
+ suggestions: z.array(z.string()).optional(),
393
+ messages: z.array(z.string()).optional(),
394
+ tools: z.array(tPluginSchema).optional(),
395
+ createdAt: z.string(),
396
+ updatedAt: z.string(),
397
+ systemMessage: z.string().nullable().optional(),
398
+ modelLabel: z.string().nullable().optional(),
399
+ examples: z.array(tExampleSchema).optional(),
400
+ chatGptLabel: z.string().nullable().optional(),
401
+ userLabel: z.string().optional(),
402
+ model: z.string().optional(),
403
+ promptPrefix: z.string().nullable().optional(),
404
+ temperature: z.number().optional(),
405
+ topP: z.number().optional(),
406
+ topK: z.number().optional(),
407
+ context: z.string().nullable().optional(),
408
+ top_p: z.number().optional(),
409
+ frequency_penalty: z.number().optional(),
410
+ presence_penalty: z.number().optional(),
411
+ jailbreak: z.boolean().optional(),
412
+ jailbreakConversationId: z.string().nullable().optional(),
413
+ conversationSignature: z.string().nullable().optional(),
414
+ parentMessageId: z.string().optional(),
415
+ clientId: z.string().nullable().optional(),
416
+ invocationId: z.number().nullable().optional(),
417
+ toneStyle: z.string().nullable().optional(),
418
+ maxOutputTokens: z.number().optional(),
419
+ agentOptions: tAgentOptionsSchema.nullable().optional(),
420
+ });
421
+ var tPresetSchema = tConversationSchema
422
+ .omit({
423
+ conversationId: true,
424
+ createdAt: true,
425
+ updatedAt: true,
426
+ title: true,
427
+ })
428
+ .merge(z.object({
429
+ conversationId: z.string().optional(),
430
+ presetId: z.string().nullable().optional(),
431
+ title: z.string().nullable().optional(),
432
+ }));
433
+
434
+ var Side;
435
+ (function (Side) {
436
+ Side["Top"] = "top";
437
+ Side["Right"] = "right";
438
+ Side["Bottom"] = "bottom";
439
+ Side["Left"] = "left";
440
+ })(Side || (Side = {}));
345
441
 
346
442
  var QueryKeys;
347
443
  (function (QueryKeys) {
@@ -377,7 +473,7 @@ var useGetConversationByIdQuery = function (id, config) {
377
473
  var useGetConversationByIdMutation = function (id) {
378
474
  var queryClient = useQueryClient();
379
475
  return useMutation(function () { return getConversationById(id); }, {
380
- // onSuccess: (res: t.TConversation) => {
476
+ // onSuccess: (res: s.TConversation) => {
381
477
  onSuccess: function () {
382
478
  queryClient.invalidateQueries([QueryKeys.conversation, id]);
383
479
  },
@@ -454,7 +550,10 @@ var useSearchQuery = function (searchQuery, pageNumber, config) {
454
550
  };
455
551
  var useUpdateTokenCountMutation = function () {
456
552
  var queryClient = useQueryClient();
457
- return useMutation(function (text) { return updateTokenCount(text); }, {
553
+ return useMutation(function (_a) {
554
+ var text = _a.text;
555
+ return updateTokenCount(text);
556
+ }, {
458
557
  onSuccess: function () {
459
558
  queryClient.invalidateQueries([QueryKeys.tokenCount]);
460
559
  },
@@ -750,7 +849,7 @@ var SSE = function (url, options) {
750
849
 
751
850
  function createPayload(submission) {
752
851
  var conversation = submission.conversation, message = submission.message, endpointOption = submission.endpointOption;
753
- var conversationId = conversation.conversationId;
852
+ var conversationId = tConversationSchema.parse(conversation).conversationId;
754
853
  var endpoint = endpointOption.endpoint;
755
854
  var endpointUrlMap = {
756
855
  azureOpenAI: '/api/ask/azureOpenAI',
@@ -767,4 +866,4 @@ function createPayload(submission) {
767
866
  return { server: server, payload: payload };
768
867
  }
769
868
 
770
- export { EModelEndpoint, QueryKeys, SSE, 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 };
869
+ export { EModelEndpoint, QueryKeys, SSE, Side, abortRequestWithMessage, clearAllConversations, createPayload, createPreset, deleteConversation, deletePreset, eModelEndpointSchema, getAIEndpoints, getAvailablePlugins, getConversationById, getConversations, getLoginGoogle, getMessagesByConvoId, getPresets, getSearchEnabled, getStartupConfig, getUser, login, logout, 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 };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var axios = require('axios');
4
+ var zod = require('zod');
4
5
  var reactQuery = require('@tanstack/react-query');
5
6
 
6
7
  /******************************************************************************
@@ -344,6 +345,101 @@ exports.EModelEndpoint = void 0;
344
345
  EModelEndpoint["gptPlugins"] = "gptPlugins";
345
346
  EModelEndpoint["anthropic"] = "anthropic";
346
347
  })(exports.EModelEndpoint || (exports.EModelEndpoint = {}));
348
+ var eModelEndpointSchema = zod.z.nativeEnum(exports.EModelEndpoint);
349
+ var tMessageSchema = zod.z.object({
350
+ messageId: zod.z.string(),
351
+ conversationId: zod.z.string(),
352
+ clientId: zod.z.string(),
353
+ parentMessageId: zod.z.string(),
354
+ sender: zod.z.string(),
355
+ text: zod.z.string(),
356
+ isCreatedByUser: zod.z.boolean(),
357
+ error: zod.z.boolean(),
358
+ createdAt: zod.z.string(),
359
+ updatedAt: zod.z.string(),
360
+ });
361
+ var tPluginAuthConfigSchema = zod.z.object({
362
+ authField: zod.z.string(),
363
+ label: zod.z.string(),
364
+ description: zod.z.string(),
365
+ });
366
+ var tPluginSchema = zod.z.object({
367
+ name: zod.z.string(),
368
+ pluginKey: zod.z.string(),
369
+ description: zod.z.string(),
370
+ icon: zod.z.string(),
371
+ authConfig: zod.z.array(tPluginAuthConfigSchema),
372
+ authenticated: zod.z.boolean().optional(),
373
+ isButton: zod.z.boolean().optional(),
374
+ });
375
+ var tExampleSchema = zod.z.object({
376
+ input: zod.z.object({
377
+ content: zod.z.string(),
378
+ }),
379
+ output: zod.z.object({
380
+ content: zod.z.string(),
381
+ }),
382
+ });
383
+ var tAgentOptionsSchema = zod.z.object({
384
+ agent: zod.z.string(),
385
+ skipCompletion: zod.z.boolean(),
386
+ model: zod.z.string(),
387
+ temperature: zod.z.number(),
388
+ });
389
+ var tConversationSchema = zod.z.object({
390
+ conversationId: zod.z.string().nullable(),
391
+ title: zod.z.string(),
392
+ user: zod.z.string().optional(),
393
+ endpoint: eModelEndpointSchema.nullable(),
394
+ suggestions: zod.z.array(zod.z.string()).optional(),
395
+ messages: zod.z.array(zod.z.string()).optional(),
396
+ tools: zod.z.array(tPluginSchema).optional(),
397
+ createdAt: zod.z.string(),
398
+ updatedAt: zod.z.string(),
399
+ systemMessage: zod.z.string().nullable().optional(),
400
+ modelLabel: zod.z.string().nullable().optional(),
401
+ examples: zod.z.array(tExampleSchema).optional(),
402
+ chatGptLabel: zod.z.string().nullable().optional(),
403
+ userLabel: zod.z.string().optional(),
404
+ model: zod.z.string().optional(),
405
+ promptPrefix: zod.z.string().nullable().optional(),
406
+ temperature: zod.z.number().optional(),
407
+ topP: zod.z.number().optional(),
408
+ topK: zod.z.number().optional(),
409
+ context: zod.z.string().nullable().optional(),
410
+ top_p: zod.z.number().optional(),
411
+ frequency_penalty: zod.z.number().optional(),
412
+ presence_penalty: zod.z.number().optional(),
413
+ jailbreak: zod.z.boolean().optional(),
414
+ jailbreakConversationId: zod.z.string().nullable().optional(),
415
+ conversationSignature: zod.z.string().nullable().optional(),
416
+ parentMessageId: zod.z.string().optional(),
417
+ clientId: zod.z.string().nullable().optional(),
418
+ invocationId: zod.z.number().nullable().optional(),
419
+ toneStyle: zod.z.string().nullable().optional(),
420
+ maxOutputTokens: zod.z.number().optional(),
421
+ agentOptions: tAgentOptionsSchema.nullable().optional(),
422
+ });
423
+ var tPresetSchema = tConversationSchema
424
+ .omit({
425
+ conversationId: true,
426
+ createdAt: true,
427
+ updatedAt: true,
428
+ title: true,
429
+ })
430
+ .merge(zod.z.object({
431
+ conversationId: zod.z.string().optional(),
432
+ presetId: zod.z.string().nullable().optional(),
433
+ title: zod.z.string().nullable().optional(),
434
+ }));
435
+
436
+ exports.Side = void 0;
437
+ (function (Side) {
438
+ Side["Top"] = "top";
439
+ Side["Right"] = "right";
440
+ Side["Bottom"] = "bottom";
441
+ Side["Left"] = "left";
442
+ })(exports.Side || (exports.Side = {}));
347
443
 
348
444
  exports.QueryKeys = void 0;
349
445
  (function (QueryKeys) {
@@ -379,7 +475,7 @@ var useGetConversationByIdQuery = function (id, config) {
379
475
  var useGetConversationByIdMutation = function (id) {
380
476
  var queryClient = reactQuery.useQueryClient();
381
477
  return reactQuery.useMutation(function () { return getConversationById(id); }, {
382
- // onSuccess: (res: t.TConversation) => {
478
+ // onSuccess: (res: s.TConversation) => {
383
479
  onSuccess: function () {
384
480
  queryClient.invalidateQueries([exports.QueryKeys.conversation, id]);
385
481
  },
@@ -456,7 +552,10 @@ var useSearchQuery = function (searchQuery, pageNumber, config) {
456
552
  };
457
553
  var useUpdateTokenCountMutation = function () {
458
554
  var queryClient = reactQuery.useQueryClient();
459
- return reactQuery.useMutation(function (text) { return updateTokenCount(text); }, {
555
+ return reactQuery.useMutation(function (_a) {
556
+ var text = _a.text;
557
+ return updateTokenCount(text);
558
+ }, {
460
559
  onSuccess: function () {
461
560
  queryClient.invalidateQueries([exports.QueryKeys.tokenCount]);
462
561
  },
@@ -752,7 +851,7 @@ var SSE = function (url, options) {
752
851
 
753
852
  function createPayload(submission) {
754
853
  var conversation = submission.conversation, message = submission.message, endpointOption = submission.endpointOption;
755
- var conversationId = conversation.conversationId;
854
+ var conversationId = tConversationSchema.parse(conversation).conversationId;
756
855
  var endpoint = endpointOption.endpoint;
757
856
  var endpointUrlMap = {
758
857
  azureOpenAI: '/api/ask/azureOpenAI',
@@ -776,6 +875,7 @@ exports.createPayload = createPayload;
776
875
  exports.createPreset = createPreset;
777
876
  exports.deleteConversation = deleteConversation;
778
877
  exports.deletePreset = deletePreset;
878
+ exports.eModelEndpointSchema = eModelEndpointSchema;
779
879
  exports.getAIEndpoints = getAIEndpoints;
780
880
  exports.getAvailablePlugins = getAvailablePlugins;
781
881
  exports.getConversationById = getConversationById;
@@ -795,6 +895,13 @@ exports.resetPassword = resetPassword;
795
895
  exports.searchConversations = searchConversations;
796
896
  exports.setAcceptLanguageHeader = setAcceptLanguageHeader;
797
897
  exports.setTokenHeader = setTokenHeader;
898
+ exports.tAgentOptionsSchema = tAgentOptionsSchema;
899
+ exports.tConversationSchema = tConversationSchema;
900
+ exports.tExampleSchema = tExampleSchema;
901
+ exports.tMessageSchema = tMessageSchema;
902
+ exports.tPluginAuthConfigSchema = tPluginAuthConfigSchema;
903
+ exports.tPluginSchema = tPluginSchema;
904
+ exports.tPresetSchema = tPresetSchema;
798
905
  exports.updateConversation = updateConversation;
799
906
  exports.updatePreset = updatePreset;
800
907
  exports.updateTokenCount = updateTokenCount;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "librechat-data-provider",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "data services for librechat apps",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
@@ -25,7 +25,8 @@
25
25
  "homepage": "https://github.com/danny-avila/LibreChat#readme",
26
26
  "dependencies": {
27
27
  "@tanstack/react-query": "^4.28.0",
28
- "axios": "^1.3.4"
28
+ "axios": "^1.3.4",
29
+ "zod": "^3.21.4"
29
30
  },
30
31
  "devDependencies": {
31
32
  "@babel/preset-env": "^7.21.5",
@@ -36,6 +37,7 @@
36
37
  "@tanstack/query-core": "^4.29.19",
37
38
  "@types/jest": "^29.5.2",
38
39
  "@types/node": "^20.3.0",
40
+ "@types/react": "^18.2.18",
39
41
  "jest": "^29.5.0",
40
42
  "jest-junit": "^16.0.0",
41
43
  "rimraf": "^5.0.1",
@@ -1,8 +1,9 @@
1
- import type { TConversation, TSubmission, EModelEndpoint } from './types';
1
+ import { tConversationSchema } from './schemas';
2
+ import type { TSubmission, EModelEndpoint } from './types';
2
3
 
3
4
  export default function createPayload(submission: TSubmission) {
4
5
  const { conversation, message, endpointOption } = submission;
5
- const { conversationId } = conversation as TConversation;
6
+ const { conversationId } = tConversationSchema.parse(conversation);
6
7
  const { endpoint } = endpointOption as { endpoint: EModelEndpoint };
7
8
 
8
9
  const endpointUrlMap = {
@@ -1,4 +1,5 @@
1
1
  import * as t from './types';
2
+ import * as s from './schemas';
2
3
  import request from './request';
3
4
  import * as endpoints from './api-endpoints';
4
5
 
@@ -23,11 +24,11 @@ export function clearAllConversations(): Promise<unknown> {
23
24
  return request.post(endpoints.deleteConversation(), { arg: {} });
24
25
  }
25
26
 
26
- export function getMessagesByConvoId(id: string): Promise<t.TMessage[]> {
27
+ export function getMessagesByConvoId(id: string): Promise<s.TMessage[]> {
27
28
  return request.get(endpoints.messages(id));
28
29
  }
29
30
 
30
- export function getConversationById(id: string): Promise<t.TConversation> {
31
+ export function getConversationById(id: string): Promise<s.TConversation> {
31
32
  return request.get(endpoints.conversationById(id));
32
33
  }
33
34
 
@@ -37,19 +38,19 @@ export function updateConversation(
37
38
  return request.post(endpoints.updateConversation(), { arg: payload });
38
39
  }
39
40
 
40
- export function getPresets(): Promise<t.TPreset[]> {
41
+ export function getPresets(): Promise<s.TPreset[]> {
41
42
  return request.get(endpoints.presets());
42
43
  }
43
44
 
44
- export function createPreset(payload: t.TPreset): Promise<t.TPreset[]> {
45
+ export function createPreset(payload: s.TPreset): Promise<s.TPreset[]> {
45
46
  return request.post(endpoints.presets(), payload);
46
47
  }
47
48
 
48
- export function updatePreset(payload: t.TPreset): Promise<t.TPreset[]> {
49
+ export function updatePreset(payload: s.TPreset): Promise<s.TPreset[]> {
49
50
  return request.post(endpoints.presets(), payload);
50
51
  }
51
52
 
52
- export function deletePreset(arg: t.TPreset | object): Promise<t.TPreset[]> {
53
+ export function deletePreset(arg: s.TPreset | object): Promise<s.TPreset[]> {
53
54
  return request.post(endpoints.deletePreset(), arg);
54
55
  }
55
56
 
@@ -106,7 +107,7 @@ export const resetPassword = (payload: t.TResetPassword) => {
106
107
  return request.post(endpoints.resetPassword(), payload);
107
108
  };
108
109
 
109
- export const getAvailablePlugins = (): Promise<t.TPlugin[]> => {
110
+ export const getAvailablePlugins = (): Promise<s.TPlugin[]> => {
110
111
  return request.get(endpoints.plugins());
111
112
  };
112
113
 
@@ -7,6 +7,7 @@ import {
7
7
  QueryObserverResult,
8
8
  } from '@tanstack/react-query';
9
9
  import * as t from './types';
10
+ import * as s from './schemas';
10
11
  import * as dataService from './data-service';
11
12
 
12
13
  export enum QueryKeys {
@@ -47,9 +48,9 @@ export const useGetUserQuery = (
47
48
 
48
49
  export const useGetMessagesByConvoId = (
49
50
  id: string,
50
- config?: UseQueryOptions<t.TMessage[]>,
51
- ): QueryObserverResult<t.TMessage[]> => {
52
- return useQuery<t.TMessage[]>(
51
+ config?: UseQueryOptions<s.TMessage[]>,
52
+ ): QueryObserverResult<s.TMessage[]> => {
53
+ return useQuery<s.TMessage[]>(
53
54
  [QueryKeys.messages, id],
54
55
  () => dataService.getMessagesByConvoId(id),
55
56
  {
@@ -63,9 +64,9 @@ export const useGetMessagesByConvoId = (
63
64
 
64
65
  export const useGetConversationByIdQuery = (
65
66
  id: string,
66
- config?: UseQueryOptions<t.TConversation>,
67
- ): QueryObserverResult<t.TConversation> => {
68
- return useQuery<t.TConversation>(
67
+ config?: UseQueryOptions<s.TConversation>,
68
+ ): QueryObserverResult<s.TConversation> => {
69
+ return useQuery<s.TConversation>(
69
70
  [QueryKeys.conversation, id],
70
71
  () => dataService.getConversationById(id),
71
72
  {
@@ -79,10 +80,10 @@ export const useGetConversationByIdQuery = (
79
80
 
80
81
  //This isn't ideal because its just a query and we're using mutation, but it was the only way
81
82
  //to make it work with how the Chat component is structured
82
- export const useGetConversationByIdMutation = (id: string): UseMutationResult<t.TConversation> => {
83
+ export const useGetConversationByIdMutation = (id: string): UseMutationResult<s.TConversation> => {
83
84
  const queryClient = useQueryClient();
84
85
  return useMutation(() => dataService.getConversationById(id), {
85
- // onSuccess: (res: t.TConversation) => {
86
+ // onSuccess: (res: s.TConversation) => {
86
87
  onSuccess: () => {
87
88
  queryClient.invalidateQueries([QueryKeys.conversation, id]);
88
89
  },
@@ -165,7 +166,7 @@ export const useGetSearchEnabledQuery = (
165
166
  });
166
167
  };
167
168
 
168
- export const useGetEndpointsQuery = (): QueryObserverResult<t.TEndpoints> => {
169
+ export const useGetEndpointsQuery = (): QueryObserverResult<t.TEndpointsConfig> => {
169
170
  return useQuery([QueryKeys.endpoints], () => dataService.getAIEndpoints(), {
170
171
  refetchOnWindowFocus: false,
171
172
  refetchOnReconnect: false,
@@ -174,13 +175,13 @@ export const useGetEndpointsQuery = (): QueryObserverResult<t.TEndpoints> => {
174
175
  };
175
176
 
176
177
  export const useCreatePresetMutation = (): UseMutationResult<
177
- t.TPreset[],
178
+ s.TPreset[],
178
179
  unknown,
179
- t.TPreset,
180
+ s.TPreset,
180
181
  unknown
181
182
  > => {
182
183
  const queryClient = useQueryClient();
183
- return useMutation((payload: t.TPreset) => dataService.createPreset(payload), {
184
+ return useMutation((payload: s.TPreset) => dataService.createPreset(payload), {
184
185
  onSuccess: () => {
185
186
  queryClient.invalidateQueries([QueryKeys.presets]);
186
187
  },
@@ -188,13 +189,13 @@ export const useCreatePresetMutation = (): UseMutationResult<
188
189
  };
189
190
 
190
191
  export const useUpdatePresetMutation = (): UseMutationResult<
191
- t.TPreset[],
192
+ s.TPreset[],
192
193
  unknown,
193
- t.TPreset,
194
+ s.TPreset,
194
195
  unknown
195
196
  > => {
196
197
  const queryClient = useQueryClient();
197
- return useMutation((payload: t.TPreset) => dataService.updatePreset(payload), {
198
+ return useMutation((payload: s.TPreset) => dataService.updatePreset(payload), {
198
199
  onSuccess: () => {
199
200
  queryClient.invalidateQueries([QueryKeys.presets]);
200
201
  },
@@ -202,9 +203,9 @@ export const useUpdatePresetMutation = (): UseMutationResult<
202
203
  };
203
204
 
204
205
  export const useGetPresetsQuery = (
205
- config?: UseQueryOptions<t.TPreset[]>,
206
- ): QueryObserverResult<t.TPreset[], unknown> => {
207
- return useQuery<t.TPreset[]>([QueryKeys.presets], () => dataService.getPresets(), {
206
+ config?: UseQueryOptions<s.TPreset[]>,
207
+ ): QueryObserverResult<s.TPreset[], unknown> => {
208
+ return useQuery<s.TPreset[]>([QueryKeys.presets], () => dataService.getPresets(), {
208
209
  refetchOnWindowFocus: false,
209
210
  refetchOnReconnect: false,
210
211
  refetchOnMount: false,
@@ -213,13 +214,13 @@ export const useGetPresetsQuery = (
213
214
  };
214
215
 
215
216
  export const useDeletePresetMutation = (): UseMutationResult<
216
- t.TPreset[],
217
+ s.TPreset[],
217
218
  unknown,
218
- t.TPreset | object,
219
+ s.TPreset | object,
219
220
  unknown
220
221
  > => {
221
222
  const queryClient = useQueryClient();
222
- return useMutation((payload: t.TPreset | object) => dataService.deletePreset(payload), {
223
+ return useMutation((payload: s.TPreset | object) => dataService.deletePreset(payload), {
223
224
  onSuccess: () => {
224
225
  queryClient.invalidateQueries([QueryKeys.presets]);
225
226
  },
@@ -246,11 +247,11 @@ export const useSearchQuery = (
246
247
  export const useUpdateTokenCountMutation = (): UseMutationResult<
247
248
  t.TUpdateTokenCountResponse,
248
249
  unknown,
249
- string,
250
+ { text: string },
250
251
  unknown
251
252
  > => {
252
253
  const queryClient = useQueryClient();
253
- return useMutation((text: string) => dataService.updateTokenCount(text), {
254
+ return useMutation(({ text }: { text: string }) => dataService.updateTokenCount(text), {
254
255
  onSuccess: () => {
255
256
  queryClient.invalidateQueries([QueryKeys.tokenCount]);
256
257
  },
@@ -323,8 +324,8 @@ export const useResetPasswordMutation = (): UseMutationResult<
323
324
  return useMutation((payload: t.TResetPassword) => dataService.resetPassword(payload));
324
325
  };
325
326
 
326
- export const useAvailablePluginsQuery = (): QueryObserverResult<t.TPlugin[]> => {
327
- return useQuery<t.TPlugin[]>(
327
+ export const useAvailablePluginsQuery = (): QueryObserverResult<s.TPlugin[]> => {
328
+ return useQuery<s.TPlugin[]>(
328
329
  [QueryKeys.availablePlugins],
329
330
  () => dataService.getAvailablePlugins(),
330
331
  {
package/src/schemas.ts ADDED
@@ -0,0 +1,121 @@
1
+ import { z } from 'zod';
2
+
3
+ export enum EModelEndpoint {
4
+ azureOpenAI = 'azureOpenAI',
5
+ openAI = 'openAI',
6
+ bingAI = 'bingAI',
7
+ chatGPT = 'chatGPT',
8
+ chatGPTBrowser = 'chatGPTBrowser',
9
+ google = 'google',
10
+ gptPlugins = 'gptPlugins',
11
+ anthropic = 'anthropic',
12
+ }
13
+
14
+ export const eModelEndpointSchema = z.nativeEnum(EModelEndpoint);
15
+
16
+ export const tMessageSchema = z.object({
17
+ messageId: z.string(),
18
+ conversationId: z.string(),
19
+ clientId: z.string(),
20
+ parentMessageId: z.string(),
21
+ sender: z.string(),
22
+ text: z.string(),
23
+ isCreatedByUser: z.boolean(),
24
+ error: z.boolean(),
25
+ createdAt: z.string(),
26
+ updatedAt: z.string(),
27
+ });
28
+
29
+ export type TMessage = z.infer<typeof tMessageSchema>;
30
+
31
+ export const tPluginAuthConfigSchema = z.object({
32
+ authField: z.string(),
33
+ label: z.string(),
34
+ description: z.string(),
35
+ });
36
+
37
+ export type TPluginAuthConfig = z.infer<typeof tPluginAuthConfigSchema>;
38
+
39
+ export const tPluginSchema = z.object({
40
+ name: z.string(),
41
+ pluginKey: z.string(),
42
+ description: z.string(),
43
+ icon: z.string(),
44
+ authConfig: z.array(tPluginAuthConfigSchema),
45
+ authenticated: z.boolean().optional(),
46
+ isButton: z.boolean().optional(),
47
+ });
48
+
49
+ export type TPlugin = z.infer<typeof tPluginSchema>;
50
+
51
+ export const tExampleSchema = z.object({
52
+ input: z.object({
53
+ content: z.string(),
54
+ }),
55
+ output: z.object({
56
+ content: z.string(),
57
+ }),
58
+ });
59
+
60
+ export type TExample = z.infer<typeof tExampleSchema>;
61
+
62
+ export const tAgentOptionsSchema = z.object({
63
+ agent: z.string(),
64
+ skipCompletion: z.boolean(),
65
+ model: z.string(),
66
+ temperature: z.number(),
67
+ });
68
+
69
+ export const tConversationSchema = z.object({
70
+ conversationId: z.string().nullable(),
71
+ title: z.string(),
72
+ user: z.string().optional(),
73
+ endpoint: eModelEndpointSchema.nullable(),
74
+ suggestions: z.array(z.string()).optional(),
75
+ messages: z.array(z.string()).optional(),
76
+ tools: z.array(tPluginSchema).optional(),
77
+ createdAt: z.string(),
78
+ updatedAt: z.string(),
79
+ systemMessage: z.string().nullable().optional(),
80
+ modelLabel: z.string().nullable().optional(),
81
+ examples: z.array(tExampleSchema).optional(),
82
+ chatGptLabel: z.string().nullable().optional(),
83
+ userLabel: z.string().optional(),
84
+ model: z.string().optional(),
85
+ promptPrefix: z.string().nullable().optional(),
86
+ temperature: z.number().optional(),
87
+ topP: z.number().optional(),
88
+ topK: z.number().optional(),
89
+ context: z.string().nullable().optional(),
90
+ top_p: z.number().optional(),
91
+ frequency_penalty: z.number().optional(),
92
+ presence_penalty: z.number().optional(),
93
+ jailbreak: z.boolean().optional(),
94
+ jailbreakConversationId: z.string().nullable().optional(),
95
+ conversationSignature: z.string().nullable().optional(),
96
+ parentMessageId: z.string().optional(),
97
+ clientId: z.string().nullable().optional(),
98
+ invocationId: z.number().nullable().optional(),
99
+ toneStyle: z.string().nullable().optional(),
100
+ maxOutputTokens: z.number().optional(),
101
+ agentOptions: tAgentOptionsSchema.nullable().optional(),
102
+ });
103
+
104
+ export type TConversation = z.infer<typeof tConversationSchema>;
105
+
106
+ export const tPresetSchema = tConversationSchema
107
+ .omit({
108
+ conversationId: true,
109
+ createdAt: true,
110
+ updatedAt: true,
111
+ title: true,
112
+ })
113
+ .merge(
114
+ z.object({
115
+ conversationId: z.string().optional(),
116
+ presetId: z.string().nullable().optional(),
117
+ title: z.string().nullable().optional(),
118
+ }),
119
+ );
120
+
121
+ export type TPreset = z.infer<typeof tPresetSchema>;