Fix find tool filters by mapping many-to-one relations to fieldId (#15716)
**Root Cause** Many-to-one relation filters were being exposed under the relation name (e.g., `company`) instead of the corresponding foreign-key attribute (e.g., `companyId`). **Change** - Detect many-to-one relation metadata and remap those filter keys to `<fieldName>Id`. - Removed some unused code unrelated to this fix.
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
export const hasStructuredStreamData = (data: string): boolean => {
|
||||
if (!data.includes('\n')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return data.split('\n').some((line) => {
|
||||
try {
|
||||
JSON.parse(line);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -20,7 +20,7 @@ import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.ent
|
||||
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
|
||||
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
||||
|
||||
export interface ChatRequest {
|
||||
interface ChatRequest {
|
||||
messages: ModelMessage[];
|
||||
temperature?: number;
|
||||
maxOutputTokens?: number;
|
||||
|
||||
+15
-3
@@ -1,10 +1,15 @@
|
||||
import { type RestrictedFieldsPermissions } from 'twenty-shared/types';
|
||||
import {
|
||||
FieldMetadataType,
|
||||
RelationType,
|
||||
type RestrictedFieldsPermissions,
|
||||
} from 'twenty-shared/types';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { generateFieldFilterZodSchema } from 'src/engine/core-modules/record-crud/zod-schemas/field-filters.zod-schema';
|
||||
import { ObjectRecordOrderBySchema } from 'src/engine/core-modules/record-crud/zod-schemas/order-by.zod-schema';
|
||||
import { shouldExcludeFieldFromAgentToolSchema } from 'src/engine/metadata-modules/field-metadata/utils/should-exclude-field-from-agent-tool-schema.util';
|
||||
import { type ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { isFieldMetadataEntityOfType } from 'src/engine/utils/is-field-metadata-of-type.util';
|
||||
|
||||
export const generateFindToolInputSchema = (
|
||||
objectMetadata: ObjectMetadataEntity,
|
||||
@@ -23,9 +28,16 @@ export const generateFindToolInputSchema = (
|
||||
|
||||
const filterSchema = generateFieldFilterZodSchema(field);
|
||||
|
||||
if (filterSchema) {
|
||||
filterShape[field.name] = filterSchema;
|
||||
if (!filterSchema) {
|
||||
return;
|
||||
}
|
||||
|
||||
const isManyToOneRelationField =
|
||||
isFieldMetadataEntityOfType(field, FieldMetadataType.RELATION) &&
|
||||
field.settings?.relationType === RelationType.MANY_TO_ONE;
|
||||
|
||||
filterShape[isManyToOneRelationField ? `${field.name}Id` : field.name] =
|
||||
filterSchema;
|
||||
});
|
||||
|
||||
return z.object({
|
||||
|
||||
+2
-5
@@ -7,11 +7,8 @@ export const transformStandardAgentDefinitionToFlatAgent = (
|
||||
standardAgentDefinition: StandardAgentDefinition,
|
||||
workspaceId: string,
|
||||
): FlatAgent => {
|
||||
const {
|
||||
createHandoffFromDefaultAgent: _createHandoffFromDefaultAgent,
|
||||
standardRoleId: _standardRoleId,
|
||||
...agentData
|
||||
} = standardAgentDefinition;
|
||||
const { standardRoleId: _standardRoleId, ...agentData } =
|
||||
standardAgentDefinition;
|
||||
|
||||
return {
|
||||
...agentData,
|
||||
|
||||
-1
@@ -9,7 +9,6 @@ export const DATA_MANIPULATOR_AGENT: StandardAgentDefinition = {
|
||||
'AI agent specialized in creating, updating, and managing data across all objects',
|
||||
icon: 'IconEdit',
|
||||
applicationId: null,
|
||||
createHandoffFromDefaultAgent: true,
|
||||
prompt: `You are a Data Manipulator Agent specialized in helping users create, update, and manage data in Twenty.
|
||||
|
||||
Your capabilities include:
|
||||
|
||||
-1
@@ -9,7 +9,6 @@ export const DATA_NAVIGATOR_AGENT: StandardAgentDefinition = {
|
||||
'AI agent specialized in exploring and reading data across all objects',
|
||||
icon: 'IconSearch',
|
||||
applicationId: null,
|
||||
createHandoffFromDefaultAgent: true,
|
||||
prompt: `You are a Data Navigator Agent specialized in helping users explore and understand their data in Twenty.
|
||||
|
||||
Your capabilities include:
|
||||
|
||||
-1
@@ -8,7 +8,6 @@ export const HELPER_AGENT: StandardAgentDefinition = {
|
||||
'AI agent specialized in helping users learn how to use Twenty CRM',
|
||||
icon: 'IconHelp',
|
||||
applicationId: null,
|
||||
createHandoffFromDefaultAgent: true,
|
||||
prompt: `You are a Helper Agent specialized in assisting users with questions about how to use Twenty CRM.
|
||||
|
||||
Your capabilities include:
|
||||
|
||||
-1
@@ -8,7 +8,6 @@ export const WORKFLOW_BUILDER_AGENT: StandardAgentDefinition = {
|
||||
description: 'AI agent specialized in creating and managing workflows',
|
||||
icon: 'IconSettingsAutomation',
|
||||
applicationId: null,
|
||||
createHandoffFromDefaultAgent: true,
|
||||
prompt: `You are a Workflow Builder Agent specialized in helping users create, modify, and manage workflows in Twenty.
|
||||
|
||||
Your capabilities include:
|
||||
|
||||
-2
@@ -6,6 +6,4 @@ export type StandardAgentDefinition = Omit<
|
||||
> & {
|
||||
standardId: string;
|
||||
standardRoleId?: string;
|
||||
// If true, creates a handoff from the default agent to this agent
|
||||
createHandoffFromDefaultAgent?: boolean;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user