Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { getDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-acce
import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js';
import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object.interface.js';
import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object-agent.interface.js';
import { AICoreService, AIProviderType, cleanAIJsonResponse } from '../../../../ai-core/index.js';
import AbstractUseCase from '../../../../common/abstract-use.case.js';
import { IGlobalDatabaseContext } from '../../../../common/application/global-database-context.interface.js';
import { BaseType } from '../../../../common/data-injection.tokens.js';
import { DashboardWidgetTypeEnum } from '../../../../enums/dashboard-widget-type.enum.js';
import { Messages } from '../../../../exceptions/text/messages.js';
import { AICoreService, AIProviderType, cleanAIJsonResponse } from '../../../../ai-core/index.js';
import { validateQuerySafety } from '../../panel/utils/check-query-is-safe.util.js';
import { GeneratePanelPositionWithAiDs } from '../data-structures/generate-panel-position-with-ai.ds.js';
import { GeneratedPanelWithPositionDto } from '../dto/generated-panel-with-position.dto.js';
import { IGeneratePanelPositionWithAi } from './panel-position-use-cases.interface.js';
import { validateQuerySafety } from '../../panel/utils/check-query-is-safe.util.js';

interface AIGeneratedPanelResponse {
name: string;
Expand Down Expand Up @@ -321,7 +321,7 @@ Respond ONLY with the JSON object, no additional text or explanation.`;

const feedbackSection = isError
? `The query FAILED with the following error:\n${explainResultOrError}\n\nPlease fix the query to resolve this error.`
: `The EXPLAIN output for the query is:\n${explainResultOrError}\n\nReview the execution plan. If the query has performance issues (full table scans on large datasets, inefficient joins, etc.), optimize it. If the query is already acceptable, return it unchanged.`;
: `The EXPLAIN output for the query is:\n${explainResultOrError}\n\nReview the execution plan. If the query has performance issues (full table scans on large datasets, inefficient joins, etc.), optimize it if possible. If the query is already acceptable, return it unchanged.`;

return `You are a database query optimization assistant. A SQL query was generated and needs validation.

Expand All @@ -338,10 +338,7 @@ ${currentQuery}

${feedbackSection}

IMPORTANT:
- Preserve the same column aliases used in the original query.
- Write valid ${connectionType} SQL syntax.
- Return ONLY the SQL query, no explanations, no markdown, no JSON wrapping.`;
Respond with SQL only. Preserve column aliases. Valid ${connectionType} syntax.`;
}

private cleanQueryResponse(aiResponse: string): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ import { getDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-acce
import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js';
import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object.interface.js';
import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object-agent.interface.js';
import AbstractUseCase from '../../../../common/abstract-use.case.js';
import { IGlobalDatabaseContext } from '../../../../common/application/global-database-context.interface.js';
import { BaseType } from '../../../../common/data-injection.tokens.js';
import { DashboardWidgetTypeEnum } from '../../../../enums/dashboard-widget-type.enum.js';
import { Messages } from '../../../../exceptions/text/messages.js';
import {
AICoreService,
AIProviderType,
AIToolCall,
AIToolDefinition,
cleanAIJsonResponse,
createDashboardGenerationTools,
encodeToToon,
encodeError,
encodeToToon,
MessageBuilder,
} from '../../../../ai-core/index.js';
import { GenerateTableDashboardWithAiDs } from '../data-structures/generate-table-dashboard-with-ai.ds.js';
import { GeneratedPanelWithPositionDto } from '../dto/generated-panel-with-position.dto.js';
import { IGenerateTableDashboardWithAi } from './panel-position-use-cases.interface.js';
import { validateQuerySafety } from '../../panel/utils/check-query-is-safe.util.js';
import AbstractUseCase from '../../../../common/abstract-use.case.js';
import { IGlobalDatabaseContext } from '../../../../common/application/global-database-context.interface.js';
import { BaseType } from '../../../../common/data-injection.tokens.js';
import { DashboardWidgetTypeEnum } from '../../../../enums/dashboard-widget-type.enum.js';
import { Messages } from '../../../../exceptions/text/messages.js';
import { isConnectionTypeAgent } from '../../../../helpers/is-connection-entity-agent.js';
import { DashboardEntity } from '../../dashboard/dashboard.entity.js';
import { PanelEntity } from '../../panel/panel.entity.js';
import { validateQuerySafety } from '../../panel/utils/check-query-is-safe.util.js';
import { GenerateTableDashboardWithAiDs } from '../data-structures/generate-table-dashboard-with-ai.ds.js';
import { GeneratedPanelWithPositionDto } from '../dto/generated-panel-with-position.dto.js';
import { PanelPositionEntity } from '../panel-position.entity.js';
import { isConnectionTypeAgent } from '../../../../helpers/is-connection-entity-agent.js';
import { IGenerateTableDashboardWithAi } from './panel-position-use-cases.interface.js';

interface AIGeneratedPanelResponse {
name: string;
Expand Down Expand Up @@ -472,7 +472,7 @@ IMPORTANT GUIDELINES:
): string {
const feedbackSection = isError
? `The query FAILED with the following error:\n${explainResultOrError}\n\nPlease fix the query to resolve this error.`
: `The EXPLAIN output for the query is:\n${explainResultOrError}\n\nReview the execution plan. If the query has performance issues (full table scans on large datasets, inefficient joins, etc.), optimize it. If the query is already acceptable, return it unchanged.`;
: `The EXPLAIN output for the query is:\n${explainResultOrError}\n\nReview the execution plan. If the query has performance issues (full table scans on large datasets, inefficient joins, etc.), optimize it if possible. If the query is already acceptable, return it unchanged.`;

return `You are a database query optimization assistant. A SQL query was generated and needs validation.

Expand All @@ -485,10 +485,7 @@ ${currentQuery}

${feedbackSection}

IMPORTANT:
- Preserve the same column aliases used in the original query.
- Write valid ${connectionType} SQL syntax.
- Return ONLY the SQL query, no explanations, no markdown, no JSON wrapping.`;
Respond with SQL only. Preserve column aliases. Valid ${connectionType} syntax.`;
}

private cleanQueryResponse(aiResponse: string): string {
Expand Down
Loading