mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-19 08:46:11 +01:00
* agents - phase 1 (#30) * chore: copy assistant files * feat: frontend and data-provider * feat: backend get endpoint test * fix(MessageEndpointIcon): switched to AgentName and AgentAvatar * fix: small fixes * fix: agent endpoint config * fix: show Agent Builder * chore: install agentus * chore: initial scaffolding for agents * fix: updated Assistant logic to Agent Logic for some Agent components * WIP first pass, demo of agent package * WIP: initial backend infra for agents * fix: agent list error * wip: agents routing * chore: Refactor useSSE hook to handle different data events * wip: correctly emit events * chore: Update @librechat/agentus npm dependency to version 1.0.9 * remove comment * first pass: streaming agent text * chore: Remove @librechat/agentus root-level workspace npm dependency * feat: Agent Schema and Model * fix: content handling fixes * fix: content message save * WIP: new content data * fix: run step issue with tool calls * chore: Update @librechat/agentus npm dependency to version 1.1.5 * feat: update controller and agent routes * wip: initial backend tool and tool error handling support * wip: tool chunks * chore: Update @librechat/agentus npm dependency to version 1.1.7 * chore: update tool_call typing, add test conditions and logs * fix: create agent * fix: create agent * first pass: render completed content parts * fix: remove logging, fix step handler typing * chore: Update @librechat/agentus npm dependency to version 1.1.9 * refactor: cleanup maps on unmount * chore: Update BaseClient.js to safely count tokens for string, number, and boolean values * fix: support subsequent messages with tool_calls * chore: export order * fix: select agent * fix: tool call types and handling * chore: switch to anthropic for testing * fix: AgentSelect * refactor: experimental: OpenAIClient to use array for intermediateReply * fix(useSSE): revert old condition for streaming legacy client tokens * fix: lint * revert `agent_id` to `id` * chore: update localization keys for agent-related components * feat: zod schema handling for actions * refactor(actions): if no params, no zodSchema * chore: Update @librechat/agentus npm dependency to version 1.2.1 * feat: first pass, actions * refactor: empty schema for actions without params * feat: Update createRun function to accept additional options * fix: message payload formatting; feat: add more client options * fix: ToolCall component rendering when action has no args but has output * refactor(ToolCall): allow non-stringy args * WIP: first pass, correctly formatted tool_calls between providers * refactor: Remove duplicate import of 'roles' module * refactor: Exclude 'vite.config.ts' from TypeScript compilation * refactor: fix agent related types > - no need to use endpoint/model fields for identifying agent metadata > - add `provider` distinction for agent-configured 'endpoint' - no need for agent-endpoint map - reduce complexity of tools as functions into tools as string[] - fix types related to above changes - reduce unnecessary variables for queries/mutations and corresponding react-query keys * refactor: Add tools and tool_kwargs fields to agent schema * refactor: Remove unused code and update dependencies * refactor: Update updateAgentHandler to use req.body directly * refactor: Update AgentSelect component to use localized hooks * refactor: Update agent schema to include tools and provider fields * refactor(AgentPanel): add scrollbar gutter, add provider field to form, fix agent schema required values * refactor: Update AgentSwitcher component to use selectedAgentId instead of selectedAgent * refactor: Update AgentPanel component to include alternateName import and defaultAgentFormValues * refactor(SelectDropDown): allow setting value as option while still supporting legacy usage (string values only) * refactor: SelectDropdown changes - Only necessary when the available values are objects with label/value fields and the selected value is expected to be a string. * refactor: TypeError issues and handle provider as option * feat: Add placeholder for provider selection in AgentPanel component * refactor: Update agent schema to include author and provider fields * fix: show expected 'create agent' placeholder when creating agent * chore: fix localization strings, hide capabilities form for now * chore: typing * refactor: import order and use compact agents schema for now * chore: typing * refactor: Update AgentForm type to use AgentCapabilities * fix agent form agent selection issues * feat: responsive agent selection * fix: Handle cancelled fetch in useSelectAgent hook * fix: reset agent form on accordion close/open * feat: Add agent_id to default conversation for agents endpoint * feat: agents endpoint request handling * refactor: reset conversation model on agent select * refactor: add `additional_instructions` to conversation schema, organize other fields * chore: casing * chore: types * refactor(loadAgentTools): explicitly pass agent_id, do not pass `model` to loadAgentTools for now, load action sets by agent_id * WIP: initial draft of real agent client initialization * WIP: first pass, anthropic agent requests * feat: remember last selected agent * feat: openai and azure connected * fix: prioritize agent model for runs unless an explicit override model is passed from client * feat: Agent Actions * fix: save agent id to convo * feat: model panel (#29) * feat: model panel * bring back comments * fix: method still null * fix: AgentPanel FormContext * feat: add more parameters * fix: style issues; refactor: Agent Controller * fix: cherry-pick * fix: Update AgentAvatar component to use AssistantIcon instead of BrainCircuit * feat: OGDialog for delete agent; feat(assistant): update Agent types, introduced `model_parameters` * feat: icon and general `model_parameters` update * feat: use react-hook-form better * fix: agent builder form reset issue when switching panels * refactor: modularize agent builder form --------- Co-authored-by: Danny Avila <danny@librechat.ai> * fix: AgentPanel and ModelPanel type issues and use `useFormContext` and `watch` instead of `methods` directly and `useWatch`. * fix: tool call issues due to invalid input (anthropic) of empty string * fix: handle empty text in Part component --------- Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com> * refactor: remove form ModelPanel and fixed nested ternary expressions in AgentConfig * fix: Model Parameters not saved correctly * refactor: remove console log * feat: avatar upload and get for Agents (#36) Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com> * chore: update to public package * fix: typing, optional chaining * fix: cursor not showing for content parts * chore: conditionally enable agents * ci: fix azure test * ci: fix frontend tests, fix eslint api * refactor: Remove unused errorContentPart variable * continue of the agent message PR (#40) * last fixes * fix: agentMap * pr merge test (#41) * fix: model icon not fetching correctly * remove console logs * feat: agent name * refactor: pass documentsMap as a prop to allow re-render of assistant form * refactor: pass documentsMap as a prop to allow re-render of assistant form * chore: Bump version to 0.7.419 * fix: TypeError: Cannot read properties of undefined (reading 'id') * refactor: update AgentSwitcher component to use ControlCombobox instead of Combobox --------- Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com>
296 lines
13 KiB
TypeScript
296 lines
13 KiB
TypeScript
import { useFormContext } from 'react-hook-form';
|
|
import * as RadioGroup from '@radix-ui/react-radio-group';
|
|
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
import {
|
|
AuthTypeEnum,
|
|
AuthorizationTypeEnum,
|
|
TokenExchangeMethodEnum,
|
|
} from 'librechat-data-provider';
|
|
import { DialogContent } from '~/components/ui/';
|
|
|
|
export default function ActionsAuth({
|
|
setOpenAuthDialog,
|
|
}: {
|
|
setOpenAuthDialog: React.Dispatch<React.SetStateAction<boolean>>;
|
|
}) {
|
|
const { watch, setValue, trigger } = useFormContext();
|
|
const type = watch('type');
|
|
return (
|
|
<DialogContent
|
|
role="dialog"
|
|
id="radix-:rf5:"
|
|
aria-describedby="radix-:rf7:"
|
|
aria-labelledby="radix-:rf6:"
|
|
data-state="open"
|
|
className="left-1/2 col-auto col-start-2 row-auto row-start-2 w-full max-w-md -translate-x-1/2 rounded-xl bg-white pb-0 text-left shadow-xl transition-all dark:bg-gray-700 dark:text-gray-100"
|
|
tabIndex={-1}
|
|
style={{ pointerEvents: 'auto' }}
|
|
>
|
|
<div className="flex items-center justify-between border-b border-black/10 px-4 pb-4 pt-5 dark:border-white/10 sm:p-6">
|
|
<div className="flex">
|
|
<div className="flex items-center">
|
|
<div className="flex grow flex-col gap-1">
|
|
<h2
|
|
id="radix-:rf6:"
|
|
className="text-token-text-primary text-lg font-medium leading-6"
|
|
>
|
|
Authentication
|
|
</h2>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="p-4 sm:p-6 sm:pt-0">
|
|
<div className="mb-4">
|
|
<label className="mb-1 block text-sm font-medium">Authentication Type</label>
|
|
<RadioGroup.Root
|
|
defaultValue={AuthTypeEnum.None}
|
|
onValueChange={(value) => setValue('type', value)}
|
|
value={type}
|
|
role="radiogroup"
|
|
aria-required="false"
|
|
dir="ltr"
|
|
className="flex gap-4"
|
|
tabIndex={0}
|
|
style={{ outline: 'none' }}
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
<label htmlFor=":rf8:" className="flex cursor-pointer items-center gap-1">
|
|
<RadioGroup.Item
|
|
type="button"
|
|
role="radio"
|
|
value={AuthTypeEnum.None}
|
|
id=":rf8:"
|
|
className="mr-1 flex h-5 w-5 items-center justify-center rounded-full border border-gray-500 bg-white dark:border-gray-500 dark:bg-gray-500"
|
|
tabIndex={-1}
|
|
>
|
|
<RadioGroup.Indicator className="h-2 w-2 rounded-full bg-gray-950 dark:bg-white"></RadioGroup.Indicator>
|
|
</RadioGroup.Item>
|
|
None
|
|
</label>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<label htmlFor=":rfa:" className="flex cursor-pointer items-center gap-1">
|
|
<RadioGroup.Item
|
|
type="button"
|
|
role="radio"
|
|
value={AuthTypeEnum.ServiceHttp}
|
|
id=":rfa:"
|
|
className="mr-1 flex h-5 w-5 items-center justify-center rounded-full border border-gray-500 bg-white dark:border-gray-500 dark:bg-gray-500"
|
|
tabIndex={0}
|
|
>
|
|
<RadioGroup.Indicator className="h-2 w-2 rounded-full bg-gray-950 dark:bg-white"></RadioGroup.Indicator>
|
|
</RadioGroup.Item>
|
|
API Key
|
|
</label>
|
|
</div>
|
|
<div className="flex items-center gap-2 text-gray-500">
|
|
<label htmlFor=":rfc:" className="flex cursor-not-allowed items-center gap-1">
|
|
<RadioGroup.Item
|
|
type="button"
|
|
role="radio"
|
|
disabled={true}
|
|
value={AuthTypeEnum.OAuth}
|
|
id=":rfc:"
|
|
className="mr-1 flex h-5 w-5 cursor-not-allowed items-center justify-center rounded-full border border-gray-500 bg-gray-300 dark:border-gray-600 dark:bg-gray-700"
|
|
tabIndex={-1}
|
|
>
|
|
<RadioGroup.Indicator className="h-2 w-2 rounded-full bg-gray-950 dark:bg-white"></RadioGroup.Indicator>
|
|
</RadioGroup.Item>
|
|
OAuth
|
|
</label>
|
|
</div>
|
|
</RadioGroup.Root>
|
|
</div>
|
|
{type === 'none' ? null : type === 'service_http' ? <ApiKey /> : <OAuth />}
|
|
{/* Cancel/Save */}
|
|
<div className="mt-5 flex flex-col gap-3 sm:mt-4 sm:flex-row-reverse">
|
|
<button
|
|
className="btn relative bg-green-500 text-white hover:bg-green-600 dark:hover:bg-green-600"
|
|
onClick={async () => {
|
|
const result = await trigger(undefined, { shouldFocus: true });
|
|
setValue('saved_auth_fields', result);
|
|
setOpenAuthDialog(!result);
|
|
}}
|
|
>
|
|
<div className="flex w-full items-center justify-center gap-2">Save</div>
|
|
</button>
|
|
<DialogPrimitive.Close className="btn btn-neutral relative">
|
|
<div className="flex w-full items-center justify-center gap-2">Cancel</div>
|
|
</DialogPrimitive.Close>
|
|
</div>
|
|
</div>
|
|
</DialogContent>
|
|
);
|
|
}
|
|
|
|
const ApiKey = () => {
|
|
const { register, watch, setValue } = useFormContext();
|
|
const authorization_type = watch('authorization_type');
|
|
const type = watch('type');
|
|
return (
|
|
<>
|
|
<label className="mb-1 block text-sm font-medium">API Key</label>
|
|
<input
|
|
placeholder="<HIDDEN>"
|
|
type="password"
|
|
autoComplete="new-password"
|
|
className="border-token-border-medium mb-2 h-9 w-full resize-none overflow-y-auto rounded-lg border px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-blue-400 dark:bg-gray-600"
|
|
{...register('api_key', { required: type === AuthTypeEnum.ServiceHttp })}
|
|
/>
|
|
<label className="mb-1 block text-sm font-medium">Auth Type</label>
|
|
<RadioGroup.Root
|
|
defaultValue={AuthorizationTypeEnum.Basic}
|
|
onValueChange={(value) => setValue('authorization_type', value)}
|
|
value={authorization_type}
|
|
role="radiogroup"
|
|
aria-required="true"
|
|
dir="ltr"
|
|
className="mb-2 flex gap-6 overflow-hidden rounded-lg"
|
|
tabIndex={0}
|
|
style={{ outline: 'none' }}
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
<label htmlFor=":rfu:" className="flex cursor-pointer items-center gap-1">
|
|
<RadioGroup.Item
|
|
type="button"
|
|
role="radio"
|
|
value={AuthorizationTypeEnum.Basic}
|
|
id=":rfu:"
|
|
className="mr-1 flex h-5 w-5 items-center justify-center rounded-full border border-gray-500 bg-white dark:border-gray-500 dark:bg-gray-500"
|
|
tabIndex={-1}
|
|
>
|
|
<RadioGroup.Indicator className="h-2 w-2 rounded-full bg-gray-950 dark:bg-white"></RadioGroup.Indicator>
|
|
</RadioGroup.Item>
|
|
Basic
|
|
</label>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<label htmlFor=":rg0:" className="flex cursor-pointer items-center gap-1">
|
|
<RadioGroup.Item
|
|
type="button"
|
|
role="radio"
|
|
value={AuthorizationTypeEnum.Bearer}
|
|
id=":rg0:"
|
|
className="mr-1 flex h-5 w-5 items-center justify-center rounded-full border border-gray-500 bg-white dark:border-gray-500 dark:bg-gray-500"
|
|
tabIndex={-1}
|
|
>
|
|
<RadioGroup.Indicator className="h-2 w-2 rounded-full bg-gray-950 dark:bg-white"></RadioGroup.Indicator>
|
|
</RadioGroup.Item>
|
|
Bearer
|
|
</label>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<label htmlFor=":rg2:" className="flex cursor-pointer items-center gap-1">
|
|
<RadioGroup.Item
|
|
type="button"
|
|
role="radio"
|
|
value={AuthorizationTypeEnum.Custom}
|
|
id=":rg2:"
|
|
className="mr-1 flex h-5 w-5 items-center justify-center rounded-full border border-gray-500 bg-white dark:border-gray-500 dark:bg-gray-500"
|
|
tabIndex={0}
|
|
>
|
|
<RadioGroup.Indicator className="h-2 w-2 rounded-full bg-gray-950 dark:bg-white"></RadioGroup.Indicator>
|
|
</RadioGroup.Item>
|
|
Custom
|
|
</label>
|
|
</div>
|
|
</RadioGroup.Root>
|
|
{authorization_type === AuthorizationTypeEnum.Custom && (
|
|
<div className="mt-2">
|
|
<label className="mb-1 block text-sm font-medium">Custom Header Name</label>
|
|
<input
|
|
className="border-token-border-medium mb-2 h-9 w-full resize-none overflow-y-auto rounded-lg border px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-blue-400 dark:bg-gray-600"
|
|
placeholder="X-Api-Key"
|
|
{...register('custom_auth_header', {
|
|
required: authorization_type === AuthorizationTypeEnum.Custom,
|
|
})}
|
|
/>
|
|
</div>
|
|
)}
|
|
</>
|
|
);
|
|
};
|
|
|
|
const OAuth = () => {
|
|
const { register, watch, setValue } = useFormContext();
|
|
const token_exchange_method = watch('token_exchange_method');
|
|
const type = watch('type');
|
|
return (
|
|
<>
|
|
<label className="mb-1 block text-sm font-medium">Client ID</label>
|
|
<input
|
|
placeholder="<HIDDEN>"
|
|
type="password"
|
|
autoComplete="off"
|
|
className="border-token-border-medium mb-2 h-9 w-full resize-none overflow-y-auto rounded-lg border px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-blue-400 dark:bg-gray-800"
|
|
{...register('oauth_client_id', { required: type === AuthTypeEnum.OAuth })}
|
|
/>
|
|
<label className="mb-1 block text-sm font-medium">Client Secret</label>
|
|
<input
|
|
placeholder="<HIDDEN>"
|
|
type="password"
|
|
autoComplete="off"
|
|
className="border-token-border-medium mb-2 h-9 w-full resize-none overflow-y-auto rounded-lg border px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-blue-400 dark:bg-gray-800"
|
|
{...register('oauth_client_secret', { required: type === AuthTypeEnum.OAuth })}
|
|
/>
|
|
<label className="mb-1 block text-sm font-medium">Authorization URL</label>
|
|
<input
|
|
className="border-token-border-medium mb-2 h-9 w-full resize-none overflow-y-auto rounded-lg border px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-blue-400 dark:bg-gray-800"
|
|
{...register('authorization_url', { required: type === AuthTypeEnum.OAuth })}
|
|
/>
|
|
<label className="mb-1 block text-sm font-medium">Token URL</label>
|
|
<input
|
|
className="border-token-border-medium mb-2 h-9 w-full resize-none overflow-y-auto rounded-lg border px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-blue-400 dark:bg-gray-800"
|
|
{...register('client_url', { required: type === AuthTypeEnum.OAuth })}
|
|
/>
|
|
<label className="mb-1 block text-sm font-medium">Scope</label>
|
|
<input
|
|
className="border-token-border-medium mb-2 h-9 w-full resize-none overflow-y-auto rounded-lg border px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-blue-400 dark:bg-gray-800"
|
|
{...register('scope', { required: type === AuthTypeEnum.OAuth })}
|
|
/>
|
|
<label className="mb-1 block text-sm font-medium">Token Exchange Method</label>
|
|
<RadioGroup.Root
|
|
defaultValue={AuthorizationTypeEnum.Basic}
|
|
onValueChange={(value) => setValue('token_exchange_method', value)}
|
|
value={token_exchange_method}
|
|
role="radiogroup"
|
|
aria-required="true"
|
|
dir="ltr"
|
|
tabIndex={0}
|
|
style={{ outline: 'none' }}
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
<label htmlFor=":rj1:" className="flex cursor-pointer items-center gap-1">
|
|
<RadioGroup.Item
|
|
type="button"
|
|
role="radio"
|
|
value={TokenExchangeMethodEnum.DefaultPost}
|
|
id=":rj1:"
|
|
className="mr-1 flex h-5 w-5 items-center justify-center rounded-full border border-gray-500 bg-white dark:border-gray-700 dark:bg-gray-700"
|
|
tabIndex={-1}
|
|
>
|
|
<RadioGroup.Indicator className="h-2 w-2 rounded-full bg-gray-950 dark:bg-white"></RadioGroup.Indicator>
|
|
</RadioGroup.Item>
|
|
Default (POST request)
|
|
</label>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<label htmlFor=":rj3:" className="flex cursor-pointer items-center gap-1">
|
|
<RadioGroup.Item
|
|
type="button"
|
|
role="radio"
|
|
value={TokenExchangeMethodEnum.BasicAuthHeader}
|
|
id=":rj3:"
|
|
className="mr-1 flex h-5 w-5 items-center justify-center rounded-full border border-gray-500 bg-white dark:border-gray-700 dark:bg-gray-700"
|
|
tabIndex={-1}
|
|
>
|
|
<RadioGroup.Indicator className="h-2 w-2 rounded-full bg-gray-950 dark:bg-white"></RadioGroup.Indicator>
|
|
</RadioGroup.Item>
|
|
Basic authorization header
|
|
</label>
|
|
</div>
|
|
</RadioGroup.Root>
|
|
</>
|
|
);
|
|
};
|