🚧 chore: merge latest dev build (#4288)

* fix: agent initialization, add `collectedUsage` handling

* style: improve side panel styling

* refactor(loadAgent): Optimize order agent project ID retrieval

* feat: code execution

* fix: typing issues

* feat: ExecuteCode content part

* refactor: use local state for default collapsed state of analysis content parts

* fix: code parsing in ExecuteCode component

* chore: bump agents package, export loadAuthValues

* refactor: Update handleTools.js to use EnvVar for code execution tool authentication

* WIP

* feat: download code outputs

* fix(useEventHandlers): type issues

* feat: backend handling for code outputs

* Refactor: Remove console.log statement in Part.tsx

* refactor: add attachments to TMessage/messageSchema

* WIP: prelim handling for code outputs

* feat: attachments rendering

* refactor: improve attachments rendering

* fix: attachments, nullish edge case, handle attachments from event stream, bump agents package

* fix filename download

* fix: tool assignment for 'run code' on agent creation

* fix: image handling by adding attachments

* refactor: prevent agent creation without provider/model

* refactor: remove unnecessary space in agent creation success message

* refactor: select first model if selecting provider from empty on form

* fix: Agent avatar bug

* fix: `defaultAgentFormValues` causing boolean typing issue and typeerror

* fix: capabilities counting as tools, causing duplication of them

* fix: formatted messages edge case where consecutive content text type parts with the latter having tool_call_ids would cause consecutive AI messages to be created. furthermore, content could not be an array for tool_use messages (anthropic limitation)

* chore: bump @librechat/agents dependency to version 1.6.9

* feat: bedrock agents

* feat: new Agents icon

* feat: agent titling

* feat: agent landing

* refactor: allow sharing agent globally only if user is admin or author

* feat: initial AgentPanelSkeleton

* feat: AgentPanelSkeleton

* feat: collaborative agents

* chore: add potential authorName as part of schema

* chore: Remove unnecessary console.log statement

* WIP: agent model parameters

* chore: ToolsDialog typing and tool related localization chnages

* refactor: update tool instance type (latest langchain class), and rename google tool to 'google' proper

* chore: add back tools

* feat: Agent knowledge files upload

* refactor: better verbiage for disabled knowledge

* chore: debug logs for file deletions

* chore: debug logs for file deletions

* feat: upload/delete agent knowledge/file-search files

* feat: file search UI for agents

* feat: first pass, file search tool

* chore: update default agent capabilities and info
This commit is contained in:
Danny Avila 2024-09-30 17:17:57 -04:00 committed by GitHub
parent f33e75e2ee
commit ad74350036
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
123 changed files with 3611 additions and 1541 deletions

View file

@ -3,15 +3,20 @@ import { useGetModelsQuery } from 'librechat-data-provider/react-query';
import { Controller, useWatch, useForm, FormProvider } from 'react-hook-form';
import {
Tools,
SystemRoles,
EModelEndpoint,
isAssistantsEndpoint,
defaultAgentFormValues,
} from 'librechat-data-provider';
import type { TConfig } from 'librechat-data-provider';
import type { AgentForm, AgentPanelProps, Option } from '~/common';
import { useCreateAgentMutation, useUpdateAgentMutation } from '~/data-provider';
import { useSelectAgent, useLocalize } from '~/hooks';
// import CapabilitiesForm from './CapabilitiesForm';
import type { AgentForm, AgentPanelProps, StringOption } from '~/common';
import {
useCreateAgentMutation,
useUpdateAgentMutation,
useGetAgentByIdQuery,
} from '~/data-provider';
import { useSelectAgent, useLocalize, useAuthContext } from '~/hooks';
import AgentPanelSkeleton from './AgentPanelSkeleton';
import { createProviderOption } from '~/utils';
import { useToastContext } from '~/Providers';
import AgentConfig from './AgentConfig';
@ -29,11 +34,17 @@ export default function AgentPanel({
agentsConfig,
endpointsConfig,
}: AgentPanelProps & { agentsConfig?: TConfig | null }) {
const { onSelect: onSelectAgent } = useSelectAgent();
const { showToast } = useToastContext();
const localize = useLocalize();
const { user } = useAuthContext();
const { showToast } = useToastContext();
const { onSelect: onSelectAgent } = useSelectAgent();
const modelsQuery = useGetModelsQuery();
const agentQuery = useGetAgentByIdQuery(current_agent_id ?? '', {
enabled: !!(current_agent_id ?? ''),
});
const models = useMemo(() => modelsQuery.data ?? {}, [modelsQuery.data]);
const methods = useForm<AgentForm>({
defaultValues: defaultAgentFormValues,
@ -81,7 +92,7 @@ export default function AgentPanel({
onSuccess: (data) => {
setCurrentAgentId(data.id);
showToast({
message: `${localize('com_assistants_create_success ')} ${
message: `${localize('com_assistants_create_success')} ${
data.name ?? localize('com_ui_agent')
}`,
});
@ -101,23 +112,25 @@ export default function AgentPanel({
(data: AgentForm) => {
const tools = data.tools ?? [];
if (data.code_interpreter) {
tools.push(Tools.code_interpreter);
if (data.execute_code === true) {
tools.push(Tools.execute_code);
}
if (data.retrieval) {
if (data.file_search === true) {
tools.push(Tools.file_search);
}
const {
name,
model,
model_parameters,
provider: _provider,
description,
instructions,
model: _model,
model_parameters,
provider: _provider,
} = data;
const provider = typeof _provider === 'string' ? _provider : (_provider as Option).value;
const model = _model ?? '';
const provider =
(typeof _provider === 'string' ? _provider : (_provider as StringOption).value) ?? '';
if (agent_id) {
update.mutate({
@ -135,6 +148,13 @@ export default function AgentPanel({
return;
}
if (!provider || !model) {
return showToast({
message: localize('com_agents_missing_provider_model'),
status: 'error',
});
}
create.mutate({
name,
description,
@ -145,7 +165,7 @@ export default function AgentPanel({
model_parameters,
});
},
[agent_id, create, update],
[agent_id, create, update, showToast, localize],
);
const handleSelectAgent = useCallback(() => {
@ -154,6 +174,15 @@ export default function AgentPanel({
}
}, [agent_id, onSelectAgent]);
if (agentQuery.isInitialLoading) {
return <AgentPanelSkeleton />;
}
const canEditAgent =
agentQuery.data?.isCollaborative ?? false
? true
: agentQuery.data?.author === user?.id || user?.role === SystemRoles.ADMIN;
return (
<FormProvider {...methods}>
<form
@ -169,6 +198,7 @@ export default function AgentPanel({
<AgentSelect
reset={reset}
value={field.value}
agentQuery={agentQuery}
setCurrentAgentId={setCurrentAgentId}
selectedAgentId={current_agent_id ?? null}
createMutation={create}
@ -188,10 +218,25 @@ export default function AgentPanel({
</button>
)}
</div>
{activePanel === Panel.model ? (
<ModelPanel setActivePanel={setActivePanel} providers={providers} models={models} />
) : null}
{activePanel === Panel.builder ? (
{!canEditAgent && (
<div className="flex h-[30vh] w-full items-center justify-center">
<div className="text-center">
<h2 className="text-token-text-primary m-2 text-xl font-semibold">
{localize('com_agents_not_available')}
</h2>
<p className="text-token-text-secondary">{localize('com_agents_no_access')}</p>
</div>
</div>
)}
{canEditAgent && activePanel === Panel.model && (
<ModelPanel
setActivePanel={setActivePanel}
agent_id={agent_id}
providers={providers}
models={models}
/>
)}
{canEditAgent && activePanel === Panel.builder && (
<AgentConfig
actions={actions}
setAction={setAction}
@ -200,7 +245,7 @@ export default function AgentPanel({
endpointsConfig={endpointsConfig}
setCurrentAgentId={setCurrentAgentId}
/>
) : null}
)}
</form>
</FormProvider>
);