AI Assistant: Filter command does not create Date objects in filter expression#33756
AI Assistant: Filter command does not create Date objects in filter expression#33756Raushen wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for date-based filter values in the Grid AI Assistant flow by allowing the filtering command to accept Date values and introducing an "AIDate(y, m, d)" string encoding that is converted to Date objects during assistant response parsing.
Changes:
- Extend
filterValuecommand argument schema/types to allowDatevalues and document the"AIDate(...)"encoding. - Convert
"AIDate(...)"strings intoDateobjects while parsingexecuteGridAssistantresponses. - Add unit tests to validate schema acceptance and date conversion behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/filtering.ts | Allows Date as a scalar filter value and documents "AIDate(year, month, day)" encoding in the command description. |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/tests/filtering.test.ts | Adds coverage for accepting/passing Date values through to the legacy filter array. |
| packages/devextreme/js/__internal/core/ai_integration/commands/executeGridAssistant.ts | Adds a JSON.parse reviver to convert "AIDate(...)" strings into Date objects during response parsing. |
| packages/devextreme/js/__internal/core/ai_integration/commands/executeGridAssistant.test.ts | Adds tests asserting "AIDate(...)" strings are converted to Date objects for string response forms. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/filtering.ts:55
- The command instructs the assistant to emit dates as the custom string format
AIDate(y, m, d), but the args schema now usesz.date(). Since the response schema is generated viazodToJsonSchema(..., { target: 'openAi' })(see grid_commands.ts),z.date()will be represented as a JSON string in the schema (often a date-time), which can steer the model toward ISO-style strings thatparseDateswill not convert, causing schema validation to reject the action. Consider modeling date values as a string schema that matches theAIDate(...)pattern and transforming it toDateduring zod parsing (or extend parsing to accept ISO as well) so the schema, prompt, and runtime parsing stay consistent.
const filterOpSchema = z.enum(FILTER_OPS);
const filterValueScalarSchema = z.union([z.string(), z.number(), z.boolean(), z.null(), z.date()]);
const basicFilterExprSchema = z.object({
type: z.enum(['basic']),
field: z.string(),
operator: filterOpSchema,
value: filterValueScalarSchema,
…AIAssistant-Date-Filtering # Conflicts: # packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/filtering.ts
| */ | ||
| const AI_DATE_REGEX = /^AIDate\((\d+),\s*(\d+),\s*(\d+)\)$/; | ||
|
|
||
| export function parseDates(_key: string, value: unknown): unknown { |
There was a problem hiding this comment.
Suggested scenario covers only date, not date-time cases, it also does not take into account timezones.
Suggestion: try to use ISO format, with description how it is build
Also it may be usefull to ask to return range instead of one value - it is possible we have different rows for same date but different time
| const filterOpSchema = z.enum(FILTER_OPS); | ||
|
|
||
| const filterValueScalarSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]); | ||
| const filterValueScalarSchema = z.union([z.string(), z.number(), z.boolean(), z.null(), z.date()]); |
There was a problem hiding this comment.
AI can't return an object of type Date, it'll always be a string, therefore that schema is incorrect
| const filterOpSchema = z.enum(FILTER_OPS); | ||
|
|
||
| const filterValueScalarSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]); | ||
| const filterValueScalarSchema = z.union([z.string(), z.number(), z.boolean(), z.null(), z.date()]); |
There was a problem hiding this comment.
It's better use a separate description for filter value, like following:
z.union([
z.string().describe(
'A plain string value. If the value represents a date, it must use the AIDate(year, month, day) format instead of ISO string or natural language.',
),
z.number().describe('A numeric filter value.'),
z.boolean().describe('A boolean filter value.'),
z.null().describe('A null filter value.'),
]);
No description provided.