The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Inline the single-use answer tool call hook and translate two chat errors (#27530)
Félix Malfaite71231d06659
diff --git a/packages/twenty-front/src/modules/ai/components/AgentChatStreamKeepAliveEffect.tsx b/packages/twenty-front/src/modules/ai/components/AgentChatStreamKeepAliveEffect.tsxindex 0719a6b8ea6..3b5b3d21baf 100644--- a/packages/twenty-front/src/modules/ai/components/AgentChatStreamKeepAliveEffect.tsx+++ b/packages/twenty-front/src/modules/ai/components/AgentChatStreamKeepAliveEffect.tsx@@ -1,3 +1,4 @@+import { t } from '@lingui/core/macro';import { useStore } from 'jotai';import { useCallback, useEffect } from 'react';import { isDefined, isValidUuid } from 'twenty-shared/utils';@@ -62,7 +63,7 @@ export const AgentChatStreamKeepAliveEffect = () => {store.set(errorFamilyCallback(familyKey),createAiChatCodedError(- 'Connection to the assistant was lost. Reload to see the response.',+ t`Connection to the assistant was lost. Reload to see the response.`,AiChatErrorCode.CONNECTION_LOST,),);diff --git a/packages/twenty-front/src/modules/ai/components/NavigationDrawerAiChatThreadItem.tsx b/packages/twenty-front/src/modules/ai/components/NavigationDrawerAiChatThreadItem.tsxindex 94f9fdeb599..852db2e2492 100644--- a/packages/twenty-front/src/modules/ai/components/NavigationDrawerAiChatThreadItem.tsx+++ b/packages/twenty-front/src/modules/ai/components/NavigationDrawerAiChatThreadItem.tsx@@ -5,8 +5,7 @@ import { useId } from 'react';import { AiChatThreadActionsDropdown } from '@/ai/components/AiChatThreadActionsDropdown';import { useAiChatThreadRename } from '@/ai/hooks/useAiChatThreadRename';-import { agentChatThreadInboxStatusFamilySelector } from '@/ai/states/selectors/agentChatThreadInboxStatusFamilySelector';-import { useAtomFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilySelectorValue';+import { useIsAgentChatThreadShownAsUnread } from '@/ai/hooks/useIsAgentChatThreadShownAsUnread';import { getCommandMenuDropdownIdFromCommandMenuId } from '@/command-menu-item/utils/getCommandMenuDropdownIdFromCommandMenuId';import { isDropdownOpenComponentState } from '@/ui/layout/dropdown/states/isDropdownOpenComponentState';import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';@@ -37,10 +36,7 @@ export const NavigationDrawerAiChatThreadItem = ({} = useAiChatThreadRename(thread);const isDeleted = Boolean(thread.deletedAt);- const { isUnread } = useAtomFamilySelectorValue(- agentChatThreadInboxStatusFamilySelector,- thread.id,- );+ const isShownAsUnread = useIsAgentChatThreadShownAsUnread(thread);const displayLabel = thread.title || t`New chat`;const actionsInstanceId = useId();const isDropdownOpen = useAtomComponentStateValue(@@ -67,7 +63,7 @@ export const NavigationDrawerAiChatThreadItem = ({active={isActive}onClick={() => onClick(thread)}variant={isDeleted ? 'tertiary' : 'default'}- isUnread={!isDeleted && isUnread}+ isUnread={isShownAsUnread}isRightOptionsDropdownOpen={isDropdownOpen}rightOptions={<AiChatThreadActionsDropdowndiff --git a/packages/twenty-front/src/modules/ai/hooks/useAgentChatSubscription.ts b/packages/twenty-front/src/modules/ai/hooks/useAgentChatSubscription.tsindex 08e9598cb65..4d36d12e0e9 100644--- a/packages/twenty-front/src/modules/ai/hooks/useAgentChatSubscription.ts+++ b/packages/twenty-front/src/modules/ai/hooks/useAgentChatSubscription.ts@@ -416,7 +416,7 @@ export const useAgentChatSubscription = (threadId: string | null) => {store.set(errorAtom,createAiChatCodedError(- 'Chat stopped: no more available credits.',+ t`Chat stopped: no more available credits.`,AiChatErrorCode.CREDITS_EXHAUSTED,),);diff --git a/packages/twenty-front/src/modules/ai/hooks/useAnswerAgentChatToolCall.ts b/packages/twenty-front/src/modules/ai/hooks/useAnswerAgentChatToolCall.tsindex 7f90040232b..4cad9c49057 100644--- a/packages/twenty-front/src/modules/ai/hooks/useAnswerAgentChatToolCall.ts+++ b/packages/twenty-front/src/modules/ai/hooks/useAnswerAgentChatToolCall.ts@@ -4,7 +4,6 @@ import { isDefined } from 'twenty-shared/utils';import { AGENT_CHAT_REFETCH_MESSAGES_EVENT_NAME } from '@/ai/constants/AgentChatRefetchMessagesEventName';import { useAgentChatModelId } from '@/ai/hooks/useAgentChatModelId';-import { useAnswerToolCall } from '@/ai/hooks/useAnswerToolCall';import { agentChatDisplayedThreadState } from '@/ai/states/agentChatDisplayedThreadState';import { AiChatErrorCode } from '@/ai/utils/aiChatErrorCode';import { findToolPartOutput } from '@/ai/utils/findToolPartOutput';@@ -15,12 +14,14 @@ import { updateToolPartOutput } from '@/ai/utils/updateToolPartOutput';import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';import { dispatchBrowserEvent } from '@/browser-event/utils/dispatchBrowserEvent';import { getToastOptionsFromError } from '@/error-handler/utils/getToastOptionsFromError';+import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';import { markWorkspaceCreditsExhausted } from '@/workspace/utils/updateWorkspaceResourceCreditCap';import { useToast } from 'twenty-ui/components/feedback';+import { AnswerToolCallDocument } from '~/generated/graphql';import { isGraphqlErrorOfType } from '~/utils/is-graphql-error-of-type.util';export const useAnswerAgentChatToolCall = () => {- const { answerToolCall } = useAnswerToolCall();+ const apolloCoreClient = useApolloCoreClient();const store = useStore();const { enqueueToast } = useToast();const { modelIdForRequest } = useAgentChatModelId();@@ -63,12 +64,18 @@ export const useAnswerAgentChatToolCall = () => {store.set(isAwaitingFirstChunkAtom, true);try {- const { streamId } = await answerToolCall({- threadId,- toolCallId,- response,- modelId: modelIdForRequest,+ const { data } = await apolloCoreClient.mutate({+ mutation: AnswerToolCallDocument,+ variables: {+ input: {+ threadId,+ toolCallId,+ response,+ modelId: modelIdForRequest,+ },+ },});+ const streamId = data?.answerToolCall.streamId;// No chunk follows when a workflow run resumes in its own executor or other calls still wait.if (!isDefined(streamId)) {@@ -106,7 +113,7 @@ export const useAnswerAgentChatToolCall = () => {return false;}},- [answerToolCall, store, enqueueToast, modelIdForRequest],+ [apolloCoreClient, store, enqueueToast, modelIdForRequest],);return { answerAgentChatToolCall };diff --git a/packages/twenty-front/src/modules/ai/hooks/useAnswerToolCall.ts b/packages/twenty-front/src/modules/ai/hooks/useAnswerToolCall.tsdeleted file mode 100644index 3f41fb2b3a1..00000000000--- a/packages/twenty-front/src/modules/ai/hooks/useAnswerToolCall.ts+++ /dev/null@@ -1,32 +0,0 @@-import { useCallback } from 'react';--import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';-import { AnswerToolCallDocument } from '~/generated/graphql';--export const useAnswerToolCall = () => {- const apolloCoreClient = useApolloCoreClient();-- const answerToolCall = useCallback(- async ({- threadId,- toolCallId,- response,- modelId,- }: {- threadId: string;- toolCallId: string;- response: Record<string, unknown>;- modelId?: string;- }) => {- const { data } = await apolloCoreClient.mutate({- mutation: AnswerToolCallDocument,- variables: { input: { threadId, toolCallId, response, modelId } },- });-- return { streamId: data?.answerToolCall.streamId ?? null };- },- [apolloCoreClient],- );-- return { answerToolCall };-};