librechat-data-provider 0.1.3 → 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 +92 -3
- package/dist/index.js +99 -2
- package/package.json +3 -2
- package/src/createPayload.ts +3 -2
- package/src/data-service.ts +8 -7
- package/src/react-query-service.ts +23 -22
- package/src/schemas.ts +121 -0
- package/src/types.ts +10 -133
- package/types/createPayload.d.ts +5 -5
- package/types/data-service.d.ts +8 -7
- package/types/react-query-service.d.ts +9 -8
- package/types/schemas.d.ts +625 -0
- package/types/types.d.ts +9 -117
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,94 @@ 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
|
+
|
|
345
434
|
var Side;
|
|
346
435
|
(function (Side) {
|
|
347
436
|
Side["Top"] = "top";
|
|
@@ -384,7 +473,7 @@ var useGetConversationByIdQuery = function (id, config) {
|
|
|
384
473
|
var useGetConversationByIdMutation = function (id) {
|
|
385
474
|
var queryClient = useQueryClient();
|
|
386
475
|
return useMutation(function () { return getConversationById(id); }, {
|
|
387
|
-
// onSuccess: (res:
|
|
476
|
+
// onSuccess: (res: s.TConversation) => {
|
|
388
477
|
onSuccess: function () {
|
|
389
478
|
queryClient.invalidateQueries([QueryKeys.conversation, id]);
|
|
390
479
|
},
|
|
@@ -760,7 +849,7 @@ var SSE = function (url, options) {
|
|
|
760
849
|
|
|
761
850
|
function createPayload(submission) {
|
|
762
851
|
var conversation = submission.conversation, message = submission.message, endpointOption = submission.endpointOption;
|
|
763
|
-
var conversationId = conversation.conversationId;
|
|
852
|
+
var conversationId = tConversationSchema.parse(conversation).conversationId;
|
|
764
853
|
var endpoint = endpointOption.endpoint;
|
|
765
854
|
var endpointUrlMap = {
|
|
766
855
|
azureOpenAI: '/api/ask/azureOpenAI',
|
|
@@ -777,4 +866,4 @@ function createPayload(submission) {
|
|
|
777
866
|
return { server: server, payload: payload };
|
|
778
867
|
}
|
|
779
868
|
|
|
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 };
|
|
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,94 @@ 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
|
+
|
|
347
436
|
exports.Side = void 0;
|
|
348
437
|
(function (Side) {
|
|
349
438
|
Side["Top"] = "top";
|
|
@@ -386,7 +475,7 @@ var useGetConversationByIdQuery = function (id, config) {
|
|
|
386
475
|
var useGetConversationByIdMutation = function (id) {
|
|
387
476
|
var queryClient = reactQuery.useQueryClient();
|
|
388
477
|
return reactQuery.useMutation(function () { return getConversationById(id); }, {
|
|
389
|
-
// onSuccess: (res:
|
|
478
|
+
// onSuccess: (res: s.TConversation) => {
|
|
390
479
|
onSuccess: function () {
|
|
391
480
|
queryClient.invalidateQueries([exports.QueryKeys.conversation, id]);
|
|
392
481
|
},
|
|
@@ -762,7 +851,7 @@ var SSE = function (url, options) {
|
|
|
762
851
|
|
|
763
852
|
function createPayload(submission) {
|
|
764
853
|
var conversation = submission.conversation, message = submission.message, endpointOption = submission.endpointOption;
|
|
765
|
-
var conversationId = conversation.conversationId;
|
|
854
|
+
var conversationId = tConversationSchema.parse(conversation).conversationId;
|
|
766
855
|
var endpoint = endpointOption.endpoint;
|
|
767
856
|
var endpointUrlMap = {
|
|
768
857
|
azureOpenAI: '/api/ask/azureOpenAI',
|
|
@@ -786,6 +875,7 @@ exports.createPayload = createPayload;
|
|
|
786
875
|
exports.createPreset = createPreset;
|
|
787
876
|
exports.deleteConversation = deleteConversation;
|
|
788
877
|
exports.deletePreset = deletePreset;
|
|
878
|
+
exports.eModelEndpointSchema = eModelEndpointSchema;
|
|
789
879
|
exports.getAIEndpoints = getAIEndpoints;
|
|
790
880
|
exports.getAvailablePlugins = getAvailablePlugins;
|
|
791
881
|
exports.getConversationById = getConversationById;
|
|
@@ -805,6 +895,13 @@ exports.resetPassword = resetPassword;
|
|
|
805
895
|
exports.searchConversations = searchConversations;
|
|
806
896
|
exports.setAcceptLanguageHeader = setAcceptLanguageHeader;
|
|
807
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;
|
|
808
905
|
exports.updateConversation = updateConversation;
|
|
809
906
|
exports.updatePreset = updatePreset;
|
|
810
907
|
exports.updateTokenCount = updateTokenCount;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "librechat-data-provider",
|
|
3
|
-
"version": "0.1.
|
|
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",
|
package/src/createPayload.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
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
|
|
6
|
+
const { conversationId } = tConversationSchema.parse(conversation);
|
|
6
7
|
const { endpoint } = endpointOption as { endpoint: EModelEndpoint };
|
|
7
8
|
|
|
8
9
|
const endpointUrlMap = {
|
package/src/data-service.ts
CHANGED
|
@@ -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<
|
|
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<
|
|
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<
|
|
41
|
+
export function getPresets(): Promise<s.TPreset[]> {
|
|
41
42
|
return request.get(endpoints.presets());
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
export function createPreset(payload:
|
|
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:
|
|
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:
|
|
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<
|
|
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<
|
|
51
|
-
): QueryObserverResult<
|
|
52
|
-
return useQuery<
|
|
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<
|
|
67
|
-
): QueryObserverResult<
|
|
68
|
-
return useQuery<
|
|
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<
|
|
83
|
+
export const useGetConversationByIdMutation = (id: string): UseMutationResult<s.TConversation> => {
|
|
83
84
|
const queryClient = useQueryClient();
|
|
84
85
|
return useMutation(() => dataService.getConversationById(id), {
|
|
85
|
-
// onSuccess: (res:
|
|
86
|
+
// onSuccess: (res: s.TConversation) => {
|
|
86
87
|
onSuccess: () => {
|
|
87
88
|
queryClient.invalidateQueries([QueryKeys.conversation, id]);
|
|
88
89
|
},
|
|
@@ -174,13 +175,13 @@ export const useGetEndpointsQuery = (): QueryObserverResult<t.TEndpointsConfig>
|
|
|
174
175
|
};
|
|
175
176
|
|
|
176
177
|
export const useCreatePresetMutation = (): UseMutationResult<
|
|
177
|
-
|
|
178
|
+
s.TPreset[],
|
|
178
179
|
unknown,
|
|
179
|
-
|
|
180
|
+
s.TPreset,
|
|
180
181
|
unknown
|
|
181
182
|
> => {
|
|
182
183
|
const queryClient = useQueryClient();
|
|
183
|
-
return useMutation((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
|
-
|
|
192
|
+
s.TPreset[],
|
|
192
193
|
unknown,
|
|
193
|
-
|
|
194
|
+
s.TPreset,
|
|
194
195
|
unknown
|
|
195
196
|
> => {
|
|
196
197
|
const queryClient = useQueryClient();
|
|
197
|
-
return useMutation((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<
|
|
206
|
-
): QueryObserverResult<
|
|
207
|
-
return useQuery<
|
|
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
|
-
|
|
217
|
+
s.TPreset[],
|
|
217
218
|
unknown,
|
|
218
|
-
|
|
219
|
+
s.TPreset | object,
|
|
219
220
|
unknown
|
|
220
221
|
> => {
|
|
221
222
|
const queryClient = useQueryClient();
|
|
222
|
-
return useMutation((payload:
|
|
223
|
+
return useMutation((payload: s.TPreset | object) => dataService.deletePreset(payload), {
|
|
223
224
|
onSuccess: () => {
|
|
224
225
|
queryClient.invalidateQueries([QueryKeys.presets]);
|
|
225
226
|
},
|
|
@@ -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<
|
|
327
|
-
return useQuery<
|
|
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>;
|