[AI] agent node prompt tab new design + refactor (#19012)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { type AgentResponseSchema } from 'twenty-shared/ai';
|
||||
import { type BaseOutputSchemaV2 } from 'twenty-shared/workflow';
|
||||
|
||||
export const agentResponseSchemaToOutputSchema = (
|
||||
schema: AgentResponseSchema | undefined,
|
||||
): BaseOutputSchemaV2 => {
|
||||
if (!schema?.properties || Object.keys(schema.properties).length === 0) {
|
||||
return {
|
||||
response: {
|
||||
isLeaf: true,
|
||||
type: 'string',
|
||||
label: 'Response',
|
||||
value: null,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const outputSchema: BaseOutputSchemaV2 = {};
|
||||
|
||||
for (const [fieldName, field] of Object.entries(schema.properties)) {
|
||||
outputSchema[fieldName] = {
|
||||
isLeaf: true,
|
||||
type: field.type,
|
||||
label: fieldName,
|
||||
value: null,
|
||||
};
|
||||
}
|
||||
|
||||
return outputSchema;
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
import { type OutputSchemaField } from '@/ai/constants/OutputFieldTypeOptions';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
export const createDefaultOutputSchemaField = (): OutputSchemaField => ({
|
||||
id: v4(),
|
||||
name: '',
|
||||
description: '',
|
||||
type: 'string',
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import { type OutputSchemaField } from '@/ai/constants/OutputFieldTypeOptions';
|
||||
import {
|
||||
type AgentResponseFieldType,
|
||||
type AgentResponseSchema,
|
||||
} from 'twenty-shared/ai';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const fieldsToSchema = (
|
||||
fields: OutputSchemaField[],
|
||||
): AgentResponseSchema => {
|
||||
const properties: Record<
|
||||
string,
|
||||
{ type: AgentResponseFieldType; description?: string }
|
||||
> = {};
|
||||
const required: string[] = [];
|
||||
|
||||
for (const field of fields) {
|
||||
if (!field.name.trim() || !isDefined(field.type)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
properties[field.name] = {
|
||||
type: field.type,
|
||||
description: field.description || field.name,
|
||||
};
|
||||
required.push(field.name);
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'object' as const,
|
||||
properties,
|
||||
required,
|
||||
additionalProperties: false as const,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
import { type OutputSchemaField } from '@/ai/constants/OutputFieldTypeOptions';
|
||||
import { type AgentResponseSchema } from 'twenty-shared/ai';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
export const schemaToFields = (
|
||||
schema: AgentResponseSchema,
|
||||
): OutputSchemaField[] => {
|
||||
if (!isDefined(schema.properties)) return [];
|
||||
|
||||
return Object.entries(schema.properties).map(([key, field]) => ({
|
||||
id: v4(),
|
||||
name: key,
|
||||
description: field.description || '',
|
||||
type: field.type,
|
||||
}));
|
||||
};
|
||||
Reference in New Issue
Block a user