diff --git a/.gitignore b/.gitignore index 0c25f88c9..bb828f401 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,6 @@ scripts/scaffold.yaml node_modules .prettierrc **/.env* -!.env.dist \ No newline at end of file +!.env.dist +database/Dockerfile.flyway +database/flyway_migrate.sh \ No newline at end of file diff --git a/database/migrate.sh b/database/migrate.sh index 1b577fb58..7f1da72ac 100755 --- a/database/migrate.sh +++ b/database/migrate.sh @@ -2,7 +2,14 @@ set -ex set +o history -# Grab all command line arguments to pass them into Docker, or default to "migrate". +# Check if first argument is --host-network +DOCKER_NETWORK="" +if [ "$1" = "--host-network" ]; then + DOCKER_NETWORK="--network host" + shift # Remove --host-network from arguments +fi + +# Grab remaining command line arguments to pass them into Docker, or default to "migrate". if [ $# -eq 0 ]; then FLYWAY_COMMAND=("migrate") else @@ -11,7 +18,7 @@ fi echo "Running Flyway command: ${FLYWAY_COMMAND[@]} on jdbc:postgresql://${PGHOST}:${PGPORT}/${PGDATABASE}" -docker run --rm \ +docker run --rm ${DOCKER_NETWORK} \ -v "$(pwd)/migrations:/tmp/migrations" \ flyway/flyway:latest-alpine \ -locations="filesystem:/tmp/migrations" \ diff --git a/database/migrations/V1756973486__addConversationIdToChatResponses.sql b/database/migrations/V1756973486__addConversationIdToChatResponses.sql new file mode 100644 index 000000000..df938665b --- /dev/null +++ b/database/migrations/V1756973486__addConversationIdToChatResponses.sql @@ -0,0 +1,8 @@ +ALTER TABLE chat_responses +ADD COLUMN conversation_id UUID DEFAULT gen_random_uuid(); + +-- Create index for efficient conversation queries +CREATE INDEX idx_chat_responses_conversation_id ON chat_responses(conversation_id); + +-- Create index for efficient conversation + timestamp queries +CREATE INDEX idx_chat_responses_conversation_created_at ON chat_responses(conversation_id, created_at); \ No newline at end of file diff --git a/database/migrations/V1756973487__alterChatResponsesRouterResponseCheck.sql b/database/migrations/V1756973487__alterChatResponsesRouterResponseCheck.sql new file mode 100644 index 000000000..f9d4d2785 --- /dev/null +++ b/database/migrations/V1756973487__alterChatResponsesRouterResponseCheck.sql @@ -0,0 +1,9 @@ +-- Drop the existing check constraint +ALTER TABLE chat_responses DROP CONSTRAINT chat_responses_router_response_check; + +UPDATE chat_responses SET router_response = 'create_query' +WHERE router_response = 'text-to-sql'; + +-- Add the new check constraint with 'create_query' instead of 'text-to-sql' +ALTER TABLE chat_responses ADD CONSTRAINT chat_responses_router_response_check + CHECK (router_response IN ('pipes', 'create_query', 'stop')); \ No newline at end of file diff --git a/database/migrations/V1759392166__addAskClarificationRouterResponseType.sql b/database/migrations/V1759392166__addAskClarificationRouterResponseType.sql new file mode 100644 index 000000000..84fb0e825 --- /dev/null +++ b/database/migrations/V1759392166__addAskClarificationRouterResponseType.sql @@ -0,0 +1,9 @@ +-- Drop the existing check constraint +ALTER TABLE chat_responses DROP CONSTRAINT chat_responses_router_response_check; + +-- Add the new check constraint with 'ask_clarification' +ALTER TABLE chat_responses ADD CONSTRAINT chat_responses_router_response_check + CHECK (router_response IN ('pipes', 'create_query', 'stop', 'ask_clarification')); + +-- Add clarification_question column to store the clarification question +ALTER TABLE chat_responses ADD COLUMN IF NOT EXISTS clarification_question TEXT; diff --git a/database/migrations/V1759927411__createChatResponseAgentStepsTable.sql b/database/migrations/V1759927411__createChatResponseAgentStepsTable.sql new file mode 100644 index 000000000..e1cc71511 --- /dev/null +++ b/database/migrations/V1759927411__createChatResponseAgentStepsTable.sql @@ -0,0 +1,27 @@ +-- Create enum for agent types +CREATE TYPE agent_type AS ENUM ('ROUTER', 'PIPE', 'TEXT_TO_SQL', 'AUDITOR', 'CHART', 'EXECUTE_INSTRUCTIONS'); + +-- Create table to track individual agent execution steps +CREATE TABLE IF NOT EXISTS chat_response_agent_steps ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + chat_response_id UUID NOT NULL, + created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + model TEXT, + agent agent_type NOT NULL, + response JSONB, + input_tokens INTEGER DEFAULT 0, + output_tokens INTEGER DEFAULT 0, + response_time_seconds NUMERIC NOT NULL DEFAULT 0, + instructions TEXT, + error_message TEXT, + + CONSTRAINT fk_chat_response + FOREIGN KEY (chat_response_id) + REFERENCES chat_responses(id) + ON DELETE CASCADE +); + +-- Create indexes for efficient querying +CREATE INDEX idx_agent_steps_chat_response_id ON chat_response_agent_steps(chat_response_id); +CREATE INDEX idx_agent_steps_created_at ON chat_response_agent_steps(created_at DESC); +CREATE INDEX idx_agent_steps_agent_type ON chat_response_agent_steps(agent); diff --git a/database/migrations/V1759927412__makeChatResponsesNullable.sql b/database/migrations/V1759927412__makeChatResponsesNullable.sql new file mode 100644 index 000000000..d94efe725 --- /dev/null +++ b/database/migrations/V1759927412__makeChatResponsesNullable.sql @@ -0,0 +1,18 @@ +-- Make router fields nullable to allow early creation of chat_responses +ALTER TABLE chat_responses ALTER COLUMN router_response DROP NOT NULL; +ALTER TABLE chat_responses ALTER COLUMN router_reason DROP NOT NULL; + +-- Drop existing constraints +ALTER TABLE chat_responses DROP CONSTRAINT IF EXISTS chat_responses_router_response_check; +ALTER TABLE chat_responses DROP CONSTRAINT IF EXISTS check_pipe_instructions; + +-- Add new constraint that allows NULL or valid enum values +ALTER TABLE chat_responses ADD CONSTRAINT chat_responses_router_response_check + CHECK (router_response IS NULL OR router_response IN ('pipes', 'create_query', 'stop', 'ask_clarification')); + +-- Recreate pipe_instructions check with NULL handling +ALTER TABLE chat_responses ADD CONSTRAINT check_pipe_instructions CHECK ( + router_response IS NULL OR + (router_response = 'pipes' AND pipe_instructions IS NOT NULL) OR + (router_response != 'pipes' AND pipe_instructions IS NULL) +); diff --git a/frontend/app/components/shared/modules/copilot/components/chat-history/chat-result.vue b/frontend/app/components/shared/modules/copilot/components/chat-history/chat-result.vue index 495888bd6..b6c03b183 100644 --- a/frontend/app/components/shared/modules/copilot/components/chat-history/chat-result.vue +++ b/frontend/app/components/shared/modules/copilot/components/chat-history/chat-result.vue @@ -24,33 +24,11 @@ SPDX-License-Identifier: MIT > {{ reasoning }} -
{{ message.content }}
- - - - - -