Class: Assistant::TechnicalArticleManagementToolBuilder::ClassifyKnowledgeTool

Inherits:
ManagementTool
  • Object
show all
Defined in:
app/services/assistant/technical_article_management_tool_builder.rb

Overview

Changes corpus classification without altering content, lifecycle state,
or replacement lineage. This is intentionally available for approved
records so a worksheet can leave retrieval without a replacement draft.

Instance Method Summary collapse

Methods inherited from ManagementTool

#initialize

Constructor Details

This class inherits a constructor from Assistant::TechnicalArticleManagementToolBuilder::ManagementTool

Instance Method Details

#execute(id:, edit_token:, knowledge_role:) ⇒ String

Returns JSON classification result.

Parameters:

  • id (Integer)

    Technical Article ID

  • edit_token (String)

    current optimistic token

  • knowledge_role (String)

    requested corpus classification

Returns:

  • (String)

    JSON classification result



576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
# File 'app/services/assistant/technical_article_management_tool_builder.rb', line 576

def execute(id:, edit_token:, knowledge_role:, **)
  safely('classify knowledge') do
    knowledge_role = knowledge_role.to_s
    raise ToolError, "Unknown knowledge role: #{knowledge_role}." unless knowledge_role.in?(KNOWLEDGE_ROLES)

    article = find_article!(id)
    authorize!(:update, article)

    article.with_lock do
      raise ToolError, 'This Technical Article changed since it was read. Refresh it before classifying.' unless TechnicalArticleManagementToolBuilder.edit_token(article) == edit_token.to_s

      article.assign_attributes(knowledge_role:, updater_id: require_actor!.id)
      # Some legacy approved articles predate lifecycle metadata that is
      # required today. Classification changes only corpus metadata, so
      # preserve those records while still running update/commit callbacks
      # for audit attribution and embedding eligibility synchronization.
      article.save!(validate: false)
    end

    response(article)
  end
end

#nameString

Returns stable tool name.

Returns:

  • (String)

    stable tool name



570
# File 'app/services/assistant/technical_article_management_tool_builder.rb', line 570

def name = 'set_technical_article_knowledge_role'