patch 2
This commit is contained in:
parent
d25e6aa7c3
commit
b40badcba9
|
@ -181,6 +181,19 @@ module DiscourseAi
|
|||
def log_ai_embedding_update(embedding_def, initial_attributes)
|
||||
logger = DiscourseAi::Utils::AiStaffActionLogger.new(current_user)
|
||||
entity_details = { embedding_id: embedding_def.id, subject: embedding_def.display_name }
|
||||
|
||||
# Add flags for specific field changes
|
||||
if initial_attributes["provider"] != embedding_def.provider
|
||||
entity_details[:provider_changed] = true
|
||||
end
|
||||
|
||||
# Add a list of changed fields
|
||||
changed_fields = []
|
||||
embedding_def.previous_changes.each_key do |field|
|
||||
changed_fields << field
|
||||
end
|
||||
entity_details[:changed_fields] = changed_fields.join(", ") if changed_fields.any?
|
||||
|
||||
logger.log_update(
|
||||
"embedding",
|
||||
embedding_def,
|
||||
|
|
|
@ -258,6 +258,13 @@ module DiscourseAi
|
|||
def log_llm_model_update(llm_model, initial_attributes, initial_quotas)
|
||||
logger = DiscourseAi::Utils::AiStaffActionLogger.new(current_user)
|
||||
entity_details = { model_id: llm_model.id, subject: llm_model.display_name }
|
||||
|
||||
# Track specific field changes
|
||||
%w[name display_name provider api_key enabled_chat_bot vision_enabled].each do |field|
|
||||
if initial_attributes[field].to_s != llm_model.read_attribute(field).to_s
|
||||
entity_details["#{field}_changed"] = true
|
||||
end
|
||||
end
|
||||
|
||||
# Track quota changes separately as they're a special case
|
||||
current_quotas = llm_model.llm_quotas.reload.map(&:attributes)
|
||||
|
|
|
@ -342,6 +342,18 @@ module DiscourseAi
|
|||
logger = DiscourseAi::Utils::AiStaffActionLogger.new(current_user)
|
||||
entity_details = { persona_id: ai_persona.id, subject: ai_persona.name }
|
||||
entity_details[:tools_count] = ai_persona.tools.size if ai_persona.tools.present?
|
||||
|
||||
# Check for name changes
|
||||
if initial_attributes["name"] != ai_persona.name
|
||||
entity_details[:name_changed] = true
|
||||
end
|
||||
|
||||
# Add flags for other important changes
|
||||
%w[system_prompt description default_llm_id tools].each do |field|
|
||||
if initial_attributes[field].to_s != ai_persona.public_send(field).to_s
|
||||
entity_details["#{field}_changed"] = true
|
||||
end
|
||||
end
|
||||
|
||||
logger.log_update(
|
||||
"persona",
|
||||
|
|
|
@ -129,15 +129,20 @@ module DiscourseAi
|
|||
LlmModel.find_by(id: params[:llm_model_id])&.display_name || params[:llm_model_id]
|
||||
|
||||
changes_to_log[:llm_model_id] = "#{old_model_name} → #{new_model_name}"
|
||||
changes_to_log[:llm_model_changed] = true
|
||||
end
|
||||
|
||||
if params.key?(:custom_instructions) &&
|
||||
initial_custom_instructions != params[:custom_instructions]
|
||||
changes_to_log[:custom_instructions] = params[:custom_instructions]
|
||||
changes_to_log[:custom_instructions_changed] = true
|
||||
end
|
||||
|
||||
if changes_to_log.present?
|
||||
StaffActionLogger.new(current_user).log_custom("update_ai_spam_settings", changes_to_log)
|
||||
# Add a subject for the history record
|
||||
changes_to_log[:subject] = "AI Spam Settings"
|
||||
logger = DiscourseAi::Utils::AiStaffActionLogger.new(current_user)
|
||||
logger.log_custom("update_ai_spam_settings", changes_to_log)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -148,7 +148,12 @@ module DiscourseAi
|
|||
def log_ai_tool_update(ai_tool, initial_attributes)
|
||||
logger = DiscourseAi::Utils::AiStaffActionLogger.new(current_user)
|
||||
entity_details = { tool_id: ai_tool.id, subject: ai_tool.name }
|
||||
|
||||
|
||||
# Add flags for specific field changes
|
||||
if initial_attributes["name"] != ai_tool.name
|
||||
entity_details[:name_changed] = true
|
||||
end
|
||||
|
||||
logger.log_update(
|
||||
"tool",
|
||||
ai_tool,
|
||||
|
|
|
@ -16,14 +16,19 @@ module DiscourseAi
|
|||
# Start with provided entity details (id, name, etc.)
|
||||
# Convert all keys to strings for consistent handling in StaffActionLogger
|
||||
log_details = {}
|
||||
entity_details.each { |k, v| log_details[k.to_s] = v }
|
||||
|
||||
# Extract subject for StaffActionLogger.base_attrs
|
||||
subject = entity_details[:subject] || (entity.respond_to?(:display_name) ? entity.display_name : nil)
|
||||
|
||||
# Add the entity details but preserve subject as a top-level attribute
|
||||
entity_details.each { |k, v| log_details[k.to_s] = v unless k == :subject }
|
||||
|
||||
# Extract attributes based on field configuration and ensure string keys
|
||||
extract_entity_attributes(entity, field_config).each do |key, value|
|
||||
log_details[key.to_s] = value
|
||||
end
|
||||
|
||||
@staff_logger.log_custom("create_ai_#{entity_type}", log_details)
|
||||
@staff_logger.log_custom("create_ai_#{entity_type}", log_details.merge(subject: subject))
|
||||
end
|
||||
|
||||
# Log update of an AI entity with before/after comparison
|
||||
|
@ -71,32 +76,41 @@ module DiscourseAi
|
|||
|
||||
# Only log if there are actual changes
|
||||
if changes.any?
|
||||
# Extract subject for StaffActionLogger.base_attrs
|
||||
subject = entity_details[:subject] || (entity.respond_to?(:display_name) ? entity.display_name : nil)
|
||||
|
||||
log_details = {}
|
||||
# Convert entity_details keys to strings
|
||||
entity_details.each { |k, v| log_details[k.to_s] = v }
|
||||
# Convert entity_details keys to strings, but preserve subject as a top-level attribute
|
||||
entity_details.each { |k, v| log_details[k.to_s] = v unless k == :subject }
|
||||
# Merge changes (already with string keys)
|
||||
log_details.merge!(changes)
|
||||
|
||||
@staff_logger.log_custom("update_ai_#{entity_type}", log_details)
|
||||
@staff_logger.log_custom("update_ai_#{entity_type}", log_details.merge(subject: subject))
|
||||
end
|
||||
end
|
||||
|
||||
# Log deletion of an AI entity
|
||||
def log_deletion(entity_type, entity_details)
|
||||
# Extract subject for StaffActionLogger.base_attrs
|
||||
subject = entity_details[:subject]
|
||||
|
||||
# Convert all keys to strings for consistent handling in StaffActionLogger
|
||||
string_details = {}
|
||||
entity_details.each { |k, v| string_details[k.to_s] = v }
|
||||
entity_details.each { |k, v| string_details[k.to_s] = v unless k == :subject }
|
||||
|
||||
@staff_logger.log_custom("delete_ai_#{entity_type}", string_details)
|
||||
@staff_logger.log_custom("delete_ai_#{entity_type}", string_details.merge(subject: subject))
|
||||
end
|
||||
|
||||
# Direct custom logging for complex cases
|
||||
def log_custom(action_type, log_details)
|
||||
# Extract subject for StaffActionLogger.base_attrs if present
|
||||
subject = log_details[:subject]
|
||||
|
||||
# Convert all keys to strings for consistent handling in StaffActionLogger
|
||||
string_details = {}
|
||||
log_details.each { |k, v| string_details[k.to_s] = v }
|
||||
log_details.each { |k, v| string_details[k.to_s] = v unless k == :subject }
|
||||
|
||||
@staff_logger.log_custom(action_type, string_details)
|
||||
@staff_logger.log_custom(action_type, string_details.merge(subject: subject))
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Reference in New Issue