Redesign AI chat and add pre-existing prompts. (#17787)
Redesigned AI-chat based on the following provided design. <p align="center"> <img src="https://github.com/user-attachments/assets/f10ebbd2-9ee9-402f-b246-6e8f8cedbd53" width="225" /> </p> --------- Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
import { validateAllowedValue } from 'src/engine/core-modules/sql-sanitization/utils/validate-allowed-value.util';
|
||||
|
||||
describe('validateAllowedValue', () => {
|
||||
const allowedFruits = ['apple', 'banana', 'cherry'] as const;
|
||||
|
||||
it('should accept allowed values', () => {
|
||||
expect(() =>
|
||||
validateAllowedValue('apple', allowedFruits, 'fruit'),
|
||||
).not.toThrow();
|
||||
expect(() =>
|
||||
validateAllowedValue('banana', allowedFruits, 'fruit'),
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it('should reject disallowed values', () => {
|
||||
expect(() => validateAllowedValue('mango', allowedFruits, 'fruit')).toThrow(
|
||||
'Invalid fruit: mango',
|
||||
);
|
||||
});
|
||||
|
||||
it('should reject empty string when not in allowed list', () => {
|
||||
expect(() => validateAllowedValue('', allowedFruits, 'fruit')).toThrow();
|
||||
});
|
||||
|
||||
it('should be case-sensitive', () => {
|
||||
expect(() =>
|
||||
validateAllowedValue('Apple', allowedFruits, 'fruit'),
|
||||
).toThrow();
|
||||
});
|
||||
});
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// Runtime validation that a string value is one of the allowed values.
|
||||
// Use for values that will be interpolated into SQL to ensure they
|
||||
// match a known-safe set (e.g. enum values, action keywords).
|
||||
export const validateAllowedValue = (
|
||||
value: string,
|
||||
allowedValues: readonly string[],
|
||||
label: string,
|
||||
): void => {
|
||||
if (!allowedValues.includes(value)) {
|
||||
throw new Error(`Invalid ${label}: ${value}`);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user