mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 18:00:15 +01:00
🚧 WIP: Merge Dev Build (#4611)
* refactor: Agent CodeFiles, abortUpload WIP * feat: code environment file upload * refactor: useLazyEffect * refactor: - Add `watch` from `useFormContext` to check if code execution is enabled - Disable file upload button if `agent_id` is not selected or code execution is disabled * WIP: primeCodeFiles; refactor: rename sessionId to session_id for uniformity * Refactor: Rename session_id to sessionId for uniformity in AuthService.js * chore: bump @librechat/agents to version 1.7.1 * WIP: prime code files * refactor: Update code env file upload method to use read stream * feat: reupload code env file if no longer active * refactor: isAssistantTool -> isEntityTool + address type issues * feat: execute code tool hook * refactor: Rename isPluginAuthenticated to checkPluginAuth in PluginController.js * refactor: Update PluginController.js to use AuthType constant for comparison * feat: verify tool authentication (execute_code) * feat: enter librechat_code_api_key * refactor: Remove unused imports in BookmarkForm.tsx * feat: authenticate code tool * refactor: Update Action.tsx to conditionally render the key and revoke key buttons * refactor(Code/Action): prevent uncheck-able 'Run Code' capability when key is revoked * refactor(Code/Action): Update Action.tsx to conditionally render the key and revoke key buttons * fix: agent file upload edge cases * chore: bump @librechat/agents * fix: custom endpoint providerValue icon * feat: ollama meta modal token values + context * feat: ollama agents * refactor: Update token models for Ollama models * chore: Comment out CodeForm * refactor: Update token models for Ollama and Meta models
This commit is contained in:
parent
1909efd6ba
commit
95011ce349
58 changed files with 1418 additions and 1002 deletions
1
client/src/hooks/Generic/index.ts
Normal file
1
client/src/hooks/Generic/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from './useLazyEffect';
|
||||
18
client/src/hooks/Generic/useLazyEffect.ts
Normal file
18
client/src/hooks/Generic/useLazyEffect.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* eslint-disable react-hooks/exhaustive-deps */
|
||||
// https://stackoverflow.com/a/67504622/51500
|
||||
import { DependencyList, EffectCallback, useCallback, useEffect, useRef } from 'react';
|
||||
import debounce from 'lodash/debounce';
|
||||
|
||||
export function useLazyEffect(effect: EffectCallback, deps: DependencyList = [], wait = 300) {
|
||||
const cleanUp = useRef<void | (() => void)>();
|
||||
const effectRef = useRef<EffectCallback>();
|
||||
effectRef.current = useCallback(effect, deps);
|
||||
const lazyEffect = useCallback(
|
||||
debounce(() => (cleanUp.current = effectRef.current?.()), wait),
|
||||
[],
|
||||
);
|
||||
useEffect(lazyEffect, deps);
|
||||
useEffect(() => {
|
||||
return () => (cleanUp.current instanceof Function ? cleanUp.current() : undefined);
|
||||
}, []);
|
||||
}
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
export { default as useAuthCodeTool } from './useAuthCodeTool';
|
||||
export { default as usePluginInstall } from './usePluginInstall';
|
||||
export { default as usePluginDialogHelpers } from './usePluginDialogHelpers';
|
||||
|
|
|
|||
53
client/src/hooks/Plugins/useAuthCodeTool.ts
Normal file
53
client/src/hooks/Plugins/useAuthCodeTool.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { useCallback } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { AuthType, Tools, QueryKeys } from 'librechat-data-provider';
|
||||
import { useUpdateUserPluginsMutation } from 'librechat-data-provider/react-query';
|
||||
// import { useToastContext } from '~/Providers';
|
||||
|
||||
const useAuthCodeTool = (options?: { isEntityTool: boolean }) => {
|
||||
// const { showToast } = useToastContext();
|
||||
const queryClient = useQueryClient();
|
||||
const isEntityTool = options?.isEntityTool ?? true;
|
||||
const updateUserPlugins = useUpdateUserPluginsMutation({
|
||||
onMutate: (vars) => {
|
||||
queryClient.setQueryData([QueryKeys.toolAuth, Tools.execute_code], () => ({
|
||||
authenticated: vars.action === 'install',
|
||||
message: AuthType.USER_PROVIDED,
|
||||
}));
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries([QueryKeys.toolAuth, Tools.execute_code]);
|
||||
},
|
||||
onError: () => {
|
||||
queryClient.invalidateQueries([QueryKeys.toolAuth, Tools.execute_code]);
|
||||
},
|
||||
});
|
||||
|
||||
const installTool = useCallback(
|
||||
(apiKey: string) => {
|
||||
updateUserPlugins.mutate({
|
||||
pluginKey: Tools.execute_code,
|
||||
action: 'install',
|
||||
auth: { LIBRECHAT_CODE_API_KEY: apiKey },
|
||||
isEntityTool,
|
||||
});
|
||||
},
|
||||
[updateUserPlugins, isEntityTool],
|
||||
);
|
||||
|
||||
const removeTool = useCallback(() => {
|
||||
updateUserPlugins.mutate({
|
||||
pluginKey: Tools.execute_code,
|
||||
action: 'uninstall',
|
||||
auth: { LIBRECHAT_CODE_API_KEY: null },
|
||||
isEntityTool,
|
||||
});
|
||||
}, [updateUserPlugins, isEntityTool]);
|
||||
|
||||
return {
|
||||
removeTool,
|
||||
installTool,
|
||||
};
|
||||
};
|
||||
|
||||
export default useAuthCodeTool;
|
||||
|
|
@ -6,6 +6,7 @@ export * from './Config';
|
|||
export * from './Conversations';
|
||||
export * from './Nav';
|
||||
export * from './Files';
|
||||
export * from './Generic';
|
||||
export * from './Input';
|
||||
export * from './Messages';
|
||||
export * from './Plugins';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue