Class: Assistant::TechnicalArticleManagementToolBuilder::AddRelatedMaterialTool
- Inherits:
-
ManagementTool
- Object
- RubyLLM::Tool
- ManagementTool
- Assistant::TechnicalArticleManagementToolBuilder::AddRelatedMaterialTool
- Defined in:
- app/services/assistant/technical_article_management_tool_builder.rb
Overview
Adds one curated evidence or related-material link.
Instance Method Summary collapse
-
#execute(id:, edit_token:, target_type:, target_id:, context: ArticleRevision::NO_CONTEXT) ⇒ String
JSON link result.
-
#name ⇒ String
Stable tool name.
Methods inherited from ManagementTool
Constructor Details
This class inherits a constructor from Assistant::TechnicalArticleManagementToolBuilder::ManagementTool
Instance Method Details
#execute(id:, edit_token:, target_type:, target_id:, context: ArticleRevision::NO_CONTEXT) ⇒ String
Returns JSON link result.
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 |
# File 'app/services/assistant/technical_article_management_tool_builder.rb', line 706 def execute(id:, edit_token:, target_type:, target_id:, context: ArticleRevision::NO_CONTEXT, **) safely('add related material') do target, link_type = TechnicalArticleManagementToolBuilder.resolve_target!( target_type, target_id ) (:read, target) context_supplied = !context.equal?(ArticleRevision::NO_CONTEXT) reserved_context = context_supplied && ContentLink.reserved_workflow_context?(context) raise ToolError, 'That link context is reserved for the Technical Article consolidation workflow.' if reserved_context (id, edit_token) do |article, revision| if revision require_actor! staging_attributes = { target:, link_type:, created_by_type: 'sunny' } staging_attributes[:context] = context if context_supplied entry = revision.stage_content_link!(**staging_attributes) = TechnicalArticleManagementToolBuilder.revision_link_rows(revision) = .find { |row| row[:key] == entry['key'] } return revision_response(article, revision, { related_material: }) end link = article.outbound_content_links.with_targets.detect do |candidate| candidate.target == target && candidate.link_type == link_type end raise ToolError, 'Consolidation source links are workflow-managed and cannot be changed directly.' if link&.workflow_managed? link ||= article.outbound_content_links.build( target: target, link_type: link_type, created_by_type: 'sunny', position: article.outbound_content_links.maximum(:position).to_i + 1 ) link.context = context.presence if context_supplied link.save! article.update!(updater_id: require_actor!.id, updated_at: Time.current) return response( article, related_material: TechnicalArticleManagementToolBuilder.link_row(link) ) end end end |
#name ⇒ String
Returns stable tool name.
698 |
# File 'app/services/assistant/technical_article_management_tool_builder.rb', line 698 def name = 'add_technical_article_related_material' |