Support define is tool logic function (#17926)
- supports isTool and timeout settings in defineLogicFunction in apps and in setting tabs definition - compute for all toolInputSchema for logic funciton, in settings and in code steps <img width="991" height="802" alt="image" src="https://github.com/user-attachments/assets/05dc1221-cac9-45a3-87b0-3b13161446fd" />
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import { Temporal } from 'temporal-polyfill';
|
||||
|
||||
import { parseToPlainDateOrThrow } from '@/utils/date/parseToPlainDateOrThrow';
|
||||
import { turnJSDateToPlainDate } from '@/utils/date/turnJSDateToPlainDate';
|
||||
import { turnPlainDateIntoUserTimeZoneInstantString } from '@/utils/date/turnPlainDateIntoUserTimeZoneInstantString';
|
||||
import { turnPlainDateToShiftedDateInSystemTimeZone } from '@/utils/date/turnPlainDateToShiftedDateInSystemTimeZone';
|
||||
|
||||
describe('parseToPlainDateOrThrow', () => {
|
||||
it('should parse an ISO instant string', () => {
|
||||
const result = parseToPlainDateOrThrow('2024-03-15T10:00:00Z');
|
||||
|
||||
expect(result.year).toBe(2024);
|
||||
expect(result.month).toBe(3);
|
||||
expect(result.day).toBe(15);
|
||||
});
|
||||
|
||||
it('should parse a plain date string', () => {
|
||||
const result = parseToPlainDateOrThrow('2024-03-15');
|
||||
|
||||
expect(result.year).toBe(2024);
|
||||
expect(result.month).toBe(3);
|
||||
expect(result.day).toBe(15);
|
||||
});
|
||||
|
||||
it('should throw for an invalid date string', () => {
|
||||
expect(() => parseToPlainDateOrThrow('not-a-date')).toThrow(
|
||||
'Cannot parse date string as PlainDate',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('turnJSDateToPlainDate', () => {
|
||||
it('should convert a JS Date to a PlainDate', () => {
|
||||
const jsDate = new Date(2024, 2, 15); // March 15, 2024
|
||||
|
||||
const result = turnJSDateToPlainDate(jsDate);
|
||||
|
||||
expect(result.year).toBe(2024);
|
||||
expect(result.month).toBe(3);
|
||||
expect(result.day).toBe(15);
|
||||
});
|
||||
});
|
||||
|
||||
describe('turnPlainDateIntoUserTimeZoneInstantString', () => {
|
||||
it('should convert a PlainDate to an instant string in the given timezone', () => {
|
||||
const plainDate = Temporal.PlainDate.from('2024-03-15');
|
||||
const result = turnPlainDateIntoUserTimeZoneInstantString(
|
||||
plainDate,
|
||||
'UTC',
|
||||
);
|
||||
|
||||
expect(result).toBe('2024-03-15T00:00:00Z');
|
||||
});
|
||||
});
|
||||
|
||||
describe('turnPlainDateToShiftedDateInSystemTimeZone', () => {
|
||||
it('should return a JS Date for the given PlainDate', () => {
|
||||
const plainDate = Temporal.PlainDate.from('2024-03-15');
|
||||
|
||||
const result = turnPlainDateToShiftedDateInSystemTimeZone(plainDate);
|
||||
|
||||
expect(result).toBeInstanceOf(Date);
|
||||
expect(result.getFullYear()).toBe(2024);
|
||||
expect(result.getMonth()).toBe(2); // 0-indexed
|
||||
expect(result.getDate()).toBe(15);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,132 @@
|
||||
import { Temporal } from 'temporal-polyfill';
|
||||
|
||||
import { isPlainDateAfter } from '@/utils/date/isPlainDateAfter';
|
||||
import { isPlainDateBefore } from '@/utils/date/isPlainDateBefore';
|
||||
import { isPlainDateBeforeOrEqual } from '@/utils/date/isPlainDateBeforeOrEqual';
|
||||
import { isPlainDateInSameMonth } from '@/utils/date/isPlainDateInSameMonth';
|
||||
import { isPlainDateInWeekend } from '@/utils/date/isPlainDateInWeekend';
|
||||
import { isSamePlainDate } from '@/utils/date/isSamePlainDate';
|
||||
|
||||
describe('isPlainDateAfter', () => {
|
||||
it('should return true when first date is after second', () => {
|
||||
const a = Temporal.PlainDate.from('2024-03-15');
|
||||
const b = Temporal.PlainDate.from('2024-03-10');
|
||||
|
||||
expect(isPlainDateAfter(a, b)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when first date is before second', () => {
|
||||
const a = Temporal.PlainDate.from('2024-03-10');
|
||||
const b = Temporal.PlainDate.from('2024-03-15');
|
||||
|
||||
expect(isPlainDateAfter(a, b)).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false when dates are equal', () => {
|
||||
const a = Temporal.PlainDate.from('2024-03-15');
|
||||
const b = Temporal.PlainDate.from('2024-03-15');
|
||||
|
||||
expect(isPlainDateAfter(a, b)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isPlainDateBefore', () => {
|
||||
it('should return true when first date is before second', () => {
|
||||
const a = Temporal.PlainDate.from('2024-03-10');
|
||||
const b = Temporal.PlainDate.from('2024-03-15');
|
||||
|
||||
expect(isPlainDateBefore(a, b)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when first date is after second', () => {
|
||||
const a = Temporal.PlainDate.from('2024-03-15');
|
||||
const b = Temporal.PlainDate.from('2024-03-10');
|
||||
|
||||
expect(isPlainDateBefore(a, b)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isPlainDateBeforeOrEqual', () => {
|
||||
it('should return true when first date is before second', () => {
|
||||
const a = Temporal.PlainDate.from('2024-03-10');
|
||||
const b = Temporal.PlainDate.from('2024-03-15');
|
||||
|
||||
expect(isPlainDateBeforeOrEqual(a, b)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true when dates are equal', () => {
|
||||
const a = Temporal.PlainDate.from('2024-03-15');
|
||||
const b = Temporal.PlainDate.from('2024-03-15');
|
||||
|
||||
expect(isPlainDateBeforeOrEqual(a, b)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when first date is after second', () => {
|
||||
const a = Temporal.PlainDate.from('2024-03-20');
|
||||
const b = Temporal.PlainDate.from('2024-03-15');
|
||||
|
||||
expect(isPlainDateBeforeOrEqual(a, b)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isPlainDateInSameMonth', () => {
|
||||
it('should return true for dates in same month and year', () => {
|
||||
const a = Temporal.PlainDate.from('2024-03-01');
|
||||
const b = Temporal.PlainDate.from('2024-03-31');
|
||||
|
||||
expect(isPlainDateInSameMonth(a, b)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for dates in different months', () => {
|
||||
const a = Temporal.PlainDate.from('2024-03-15');
|
||||
const b = Temporal.PlainDate.from('2024-04-15');
|
||||
|
||||
expect(isPlainDateInSameMonth(a, b)).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for same month but different year', () => {
|
||||
const a = Temporal.PlainDate.from('2024-03-15');
|
||||
const b = Temporal.PlainDate.from('2025-03-15');
|
||||
|
||||
expect(isPlainDateInSameMonth(a, b)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isPlainDateInWeekend', () => {
|
||||
it('should return true for Saturday', () => {
|
||||
// 2024-03-16 is a Saturday
|
||||
const saturday = Temporal.PlainDate.from('2024-03-16');
|
||||
|
||||
expect(isPlainDateInWeekend(saturday)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for Sunday', () => {
|
||||
// 2024-03-17 is a Sunday
|
||||
const sunday = Temporal.PlainDate.from('2024-03-17');
|
||||
|
||||
expect(isPlainDateInWeekend(sunday)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for a weekday', () => {
|
||||
// 2024-03-18 is a Monday
|
||||
const monday = Temporal.PlainDate.from('2024-03-18');
|
||||
|
||||
expect(isPlainDateInWeekend(monday)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isSamePlainDate', () => {
|
||||
it('should return true for equal dates', () => {
|
||||
const a = Temporal.PlainDate.from('2024-03-15');
|
||||
const b = Temporal.PlainDate.from('2024-03-15');
|
||||
|
||||
expect(isSamePlainDate(a, b)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for different dates', () => {
|
||||
const a = Temporal.PlainDate.from('2024-03-15');
|
||||
const b = Temporal.PlainDate.from('2024-03-16');
|
||||
|
||||
expect(isSamePlainDate(a, b)).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user