From 2e1529c755c41f0488e12e1dc6221850f47335bf Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 16 Jul 2025 16:57:19 +0530 Subject: [PATCH] fix: tool mention format --- enterprise/app/models/captain/scenario.rb | 6 +++--- .../models/concerns/captain_tools_helpers.rb | 4 ++-- .../concerns/captain_tools_helpers_spec.rb | 18 +++++++++++------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/enterprise/app/models/captain/scenario.rb b/enterprise/app/models/captain/scenario.rb index 69fc9eef1..ecfba396f 100644 --- a/enterprise/app/models/captain/scenario.rb +++ b/enterprise/app/models/captain/scenario.rb @@ -48,11 +48,11 @@ class Captain::Scenario < ApplicationRecord # @return [void] # @api private # @example Valid instruction - # scenario.instruction = "Use (tool://add_contact_note) to document" + # scenario.instruction = "Use [Add Contact Note](tool://add_contact_note) to document" # scenario.valid? # => true # # @example Invalid instruction - # scenario.instruction = "Use (tool://invalid_tool) to process" + # scenario.instruction = "Use [Invalid Tool](tool://invalid_tool) to process" # scenario.valid? # => false # scenario.errors[:instruction] # => ["contains invalid tools: invalid_tool"] def validate_instruction_tools @@ -76,7 +76,7 @@ class Captain::Scenario < ApplicationRecord # @return [void] # @api private # @example - # scenario.instruction = "First (tool://add_private_note) then (tool://update_priority)" + # scenario.instruction = "First [@Add Private Note](tool://add_private_note) then [@Update Priority](tool://update_priority)" # scenario.save! # scenario.tools # => ["add_private_note", "update_priority"] # diff --git a/enterprise/app/models/concerns/captain_tools_helpers.rb b/enterprise/app/models/concerns/captain_tools_helpers.rb index 311d7e277..5a660310c 100644 --- a/enterprise/app/models/concerns/captain_tools_helpers.rb +++ b/enterprise/app/models/concerns/captain_tools_helpers.rb @@ -4,8 +4,8 @@ module Concerns::CaptainToolsHelpers extend ActiveSupport::Concern # Regular expression pattern for matching tool references in text. - # Matches patterns like (tool://tool_id) following Chatwoot's mention syntax. - TOOL_REFERENCE_REGEX = %r{\(tool://([^/)]+)\)} + # Matches patterns like [Tool name](tool://tool_id) following markdown link syntax. + TOOL_REFERENCE_REGEX = %r{\[[^\]]+\]\(tool://([^/)]+)\)} class_methods do # Returns all available agent tools with their metadata. diff --git a/spec/enterprise/models/concerns/captain_tools_helpers_spec.rb b/spec/enterprise/models/concerns/captain_tools_helpers_spec.rb index 3d88522d9..afe482385 100644 --- a/spec/enterprise/models/concerns/captain_tools_helpers_spec.rb +++ b/spec/enterprise/models/concerns/captain_tools_helpers_spec.rb @@ -16,7 +16,7 @@ RSpec.describe Concerns::CaptainToolsHelpers, type: :concern do describe 'TOOL_REFERENCE_REGEX' do it 'matches tool references in text' do - text = 'Use (tool://add_contact_note) and (tool://update_priority)' + text = 'Use [@Add Contact Note](tool://add_contact_note) and [Update Priority](tool://update_priority)' matches = text.scan(Concerns::CaptainToolsHelpers::TOOL_REFERENCE_REGEX) expect(matches.flatten).to eq(%w[add_contact_note update_priority]) @@ -28,7 +28,11 @@ RSpec.describe Concerns::CaptainToolsHelpers, type: :concern do 'tool://invalid', '(tool:invalid)', '(tool://)', - '(tool://with/slash)' + '(tool://with/slash)', + '(tool://add_contact_note)', + '[@Tool](tool://)', + '[Tool](tool://with/slash)', + '[](tool://valid)' ] invalid_formats.each do |format| @@ -136,14 +140,14 @@ RSpec.describe Concerns::CaptainToolsHelpers, type: :concern do describe '#extract_tool_ids_from_text' do it 'extracts tool IDs from text' do - text = 'First (tool://add_contact_note) then (tool://update_priority)' + text = 'First [@Add Contact Note](tool://add_contact_note) then [@Update Priority](tool://update_priority)' result = test_instance.extract_tool_ids_from_text(text) expect(result).to eq(%w[add_contact_note update_priority]) end it 'returns unique tool IDs' do - text = 'Use (tool://add_contact_note) and (tool://add_contact_note) again' + text = 'Use [@Add Contact Note](tool://add_contact_note) and [@Contact Note](tool://add_contact_note) again' result = test_instance.extract_tool_ids_from_text(text) expect(result).to eq(['add_contact_note']) @@ -164,9 +168,9 @@ RSpec.describe Concerns::CaptainToolsHelpers, type: :concern do it 'handles complex text with multiple tools' do text = <<~TEXT - Start with (tool://add_contact_note) to document. - Then use (tool://update_priority) if needed. - Finally (tool://add_private_note) for internal notes. + Start with [@Add Contact Note](tool://add_contact_note) to document. + Then use [@Update Priority](tool://update_priority) if needed. + Finally [@Add Private Note](tool://add_private_note) for internal notes. TEXT result = test_instance.extract_tool_ids_from_text(text)