Skip to content

final edits - #109

Merged
MohanEhab merged 2 commits into
developfrom
feature/ai-chatbot
May 3, 2026
Merged

final edits#109
MohanEhab merged 2 commits into
developfrom
feature/ai-chatbot

Conversation

@MohanEhab

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings May 3, 2026 04:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Tightens AI safety/robustness around n8n structured responses by returning explicit refusal/clarification results instead of falling back to mock intent detection, and adds parameter-clarification guards before executing genre/profile-based actions.

Changes:

  • Update n8n response validation to return a safe refusal for unknown intents and a safe clarification for malformed structured payloads.
  • Add “missing required parameter” clarification branches in AiActionService for several genre/profile-driven intents.
  • Update/add unit tests to cover the new refusal/clarification behaviors.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/ai/providers/n8n-ai.provider.ts Returns explicit refusal/clarification results for unknown/malformed n8n responses.
src/ai/ai.service.spec.ts Updates n8n helper tests for new refusal behavior; adds malformed payload clarification test.
src/ai/ai-action.service.ts Adds early clarification responses when required params (genre/profile/artist) are missing.
src/ai/ai-action.service.spec.ts Adds test ensuring missing required n8n parameters do not execute playlist creation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -58,7 +58,14 @@ export function validateStructuredAiResponse(raw: unknown, message: string, cont
// Reject unknown or non-whitelisted intents
if (!intent || !(ALLOWED_INTENTS as readonly string[]).includes(intent)) {
logger.warn(`[N8N] Unknown intent "${intent}" — falling back to mock`);
Comment on lines +389 to +400
const genre = this.cleanString(params.genre);
const limit = this.safeLimit(params.limit, 5);

if (!genre) {
return {
reply: 'Which genre should I search for?',
provider,
intent: 'recommend_by_genre',
actionsTaken: [],
needsConfirmation: true,
};
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the missing-genre test in commit 0aedcae. The test covers the recommend_by_genre missing-genre branch by asserting that:

  1. The response has needsConfirmation: true and the reply contains "genre"
  2. Neither prisma.track.findMany nor prisma.genre.findMany are called (no DB queries executed)

Copilot AI commented May 3, 2026

Copy link
Copy Markdown
Contributor

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkpoint.prisma.io
    • Triggering command: /usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/Backend/Backend/node_modules/prisma/build/child {"product":"prisma","version":"7.8.0","cli_install_type":"local","information":"","local_timestamp":"2026-05-03T04:46:23Z","project_hash":"86700263","cli_path":"/home/REDACTED/work/Backend/Backend/node_modules/.bin/prisma","cli_path_hash":"a595029d","endpoi (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@MohanEhab
MohanEhab merged commit 6f48dd5 into develop May 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants