diff --git a/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-agents-edit.js b/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-agents-edit.js new file mode 100644 index 00000000..0b834eb4 --- /dev/null +++ b/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-agents-edit.js @@ -0,0 +1,19 @@ +import DiscourseRoute from "discourse/routes/discourse"; + +export default class AdminPluginsShowDiscourseAiAgentsEdit extends DiscourseRoute { + async model(params) { + const allAgents = this.modelFor( + "adminPlugins.show.discourse-ai-agents" + ); + const id = parseInt(params.id, 10); + return allAgents.findBy("id", id); + } + + setupController(controller, model) { + super.setupController(controller, model); + controller.set( + "allAgents", + this.modelFor("adminPlugins.show.discourse-ai-agents") + ); + } +} diff --git a/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-personas-new.js b/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-agents-new.js similarity index 68% rename from admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-personas-new.js rename to admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-agents-new.js index 826799e9..06ca6753 100644 --- a/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-personas-new.js +++ b/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-agents-new.js @@ -1,16 +1,16 @@ import { AUTO_GROUPS } from "discourse/lib/constants"; import DiscourseRoute from "discourse/routes/discourse"; -export default class AdminPluginsShowDiscourseAiPersonasNew extends DiscourseRoute { +export default class AdminPluginsShowDiscourseAiAgentsNew extends DiscourseRoute { async model() { - const record = this.store.createRecord("ai-persona"); + const record = this.store.createRecord("ai-agent"); record.set("allowed_group_ids", [AUTO_GROUPS.trust_level_0.id]); record.set("rag_uploads", []); // these match the defaults on the table record.set("rag_chunk_tokens", 374); record.set("rag_chunk_overlap_tokens", 10); record.set("rag_conversation_chunks", 10); - record.set("allow_personal_messages", true); + record.set("allow_agentl_messages", true); record.set("tool_details", false); return record; } @@ -18,8 +18,8 @@ export default class AdminPluginsShowDiscourseAiPersonasNew extends DiscourseRou setupController(controller, model) { super.setupController(controller, model); controller.set( - "allPersonas", - this.modelFor("adminPlugins.show.discourse-ai-personas") + "allAgents", + this.modelFor("adminPlugins.show.discourse-ai-agents") ); } } diff --git a/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-agents.js b/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-agents.js new file mode 100644 index 00000000..5e19108f --- /dev/null +++ b/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-agents.js @@ -0,0 +1,7 @@ +import DiscourseRoute from "discourse/routes/discourse"; + +export default class DiscourseAiAiAgentsRoute extends DiscourseRoute { + model() { + return this.store.findAll("ai-agent"); + } +} diff --git a/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-personas-edit.js b/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-personas-edit.js deleted file mode 100644 index 8b5fdd02..00000000 --- a/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-personas-edit.js +++ /dev/null @@ -1,19 +0,0 @@ -import DiscourseRoute from "discourse/routes/discourse"; - -export default class AdminPluginsShowDiscourseAiPersonasEdit extends DiscourseRoute { - async model(params) { - const allPersonas = this.modelFor( - "adminPlugins.show.discourse-ai-personas" - ); - const id = parseInt(params.id, 10); - return allPersonas.findBy("id", id); - } - - setupController(controller, model) { - super.setupController(controller, model); - controller.set( - "allPersonas", - this.modelFor("adminPlugins.show.discourse-ai-personas") - ); - } -} diff --git a/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-personas.js b/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-personas.js deleted file mode 100644 index 7455e4d5..00000000 --- a/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-personas.js +++ /dev/null @@ -1,7 +0,0 @@ -import DiscourseRoute from "discourse/routes/discourse"; - -export default class DiscourseAiAiPersonasRoute extends DiscourseRoute { - model() { - return this.store.findAll("ai-persona"); - } -} diff --git a/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-agents/edit.hbs b/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-agents/edit.hbs new file mode 100644 index 00000000..61c184a1 --- /dev/null +++ b/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-agents/edit.hbs @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-agents/index.hbs b/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-agents/index.hbs new file mode 100644 index 00000000..9de1767c --- /dev/null +++ b/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-agents/index.hbs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-agents/new.hbs b/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-agents/new.hbs new file mode 100644 index 00000000..61c184a1 --- /dev/null +++ b/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-agents/new.hbs @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-features/index.gjs b/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-features/index.gjs index 9bf9fc9c..35da9ee4 100644 --- a/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-features/index.gjs +++ b/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-features/index.gjs @@ -15,7 +15,7 @@ export default RouteTemplate( const prefix = "discourse_ai.features.list.header"; return [ i18n(`${prefix}.name`), - i18n(`${prefix}.persona`), + i18n(`${prefix}.agent`), i18n(`${prefix}.groups`), "", ]; @@ -75,21 +75,21 @@ export default RouteTemplate( - {{#if (gt feature.persona.allowed_groups.length 0)}} + {{#if (gt feature.agent.allowed_groups.length 0)}}
    - {{#each feature.persona.allowed_groups as |group|}} + {{#each feature.agent.allowed_groups as |group|}}
  • {{group.name}}
  • {{/each}}
diff --git a/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-personas/edit.hbs b/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-personas/edit.hbs deleted file mode 100644 index a3173af4..00000000 --- a/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-personas/edit.hbs +++ /dev/null @@ -1,4 +0,0 @@ - \ No newline at end of file diff --git a/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-personas/index.hbs b/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-personas/index.hbs deleted file mode 100644 index 74bb4581..00000000 --- a/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-personas/index.hbs +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-personas/new.hbs b/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-personas/new.hbs deleted file mode 100644 index a3173af4..00000000 --- a/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-personas/new.hbs +++ /dev/null @@ -1,4 +0,0 @@ - \ No newline at end of file diff --git a/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-tools/edit.hbs b/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-tools/edit.hbs index 444f6966..dadffab2 100644 --- a/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-tools/edit.hbs +++ b/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-tools/edit.hbs @@ -1,4 +1,4 @@ -
+
+
{ order("priority DESC, lower(name) ASC") } - def self.all_personas(enabled_only: true) - persona_cache[:value] ||= AiPersona + def self.all_agents(enabled_only: true) + agent_cache[:value] ||= AiAgent .ordered .all - .limit(MAX_PERSONAS_PER_SITE) + .limit(MAX_AGENTS_PER_SITE) .map(&:class_instance) if enabled_only - persona_cache[:value].select { |p| p.enabled } + agent_cache[:value].select { |p| p.enabled } else - persona_cache[:value] + agent_cache[:value] end end - def self.persona_users(user: nil) - persona_users = - persona_cache[:persona_users] ||= AiPersona + def self.agent_users(user: nil) + agent_users = + agent_cache[:agent_users] ||= AiAgent .where(enabled: true) .joins(:user) - .map do |persona| + .map do |agent| { - id: persona.id, - user_id: persona.user_id, - username: persona.user.username_lower, - allowed_group_ids: persona.allowed_group_ids, - default_llm_id: persona.default_llm_id, - force_default_llm: persona.force_default_llm, - allow_chat_channel_mentions: persona.allow_chat_channel_mentions, - allow_chat_direct_messages: persona.allow_chat_direct_messages, - allow_topic_mentions: persona.allow_topic_mentions, - allow_personal_messages: persona.allow_personal_messages, + id: agent.id, + user_id: agent.user_id, + username: agent.user.username_lower, + allowed_group_ids: agent.allowed_group_ids, + default_llm_id: agent.default_llm_id, + force_default_llm: agent.force_default_llm, + allow_chat_channel_mentions: agent.allow_chat_channel_mentions, + allow_chat_direct_messages: agent.allow_chat_direct_messages, + allow_topic_mentions: agent.allow_topic_mentions, + allow_agentl_messages: agent.allow_agentl_messages, } end if user - persona_users.select { |persona_user| user.in_any_groups?(persona_user[:allowed_group_ids]) } + agent_users.select { |agent_user| user.in_any_groups?(agent_user[:allowed_group_ids]) } else - persona_users + agent_users end end @@ -93,31 +93,31 @@ class AiPersona < ActiveRecord::Base allow_chat_channel_mentions: false, allow_chat_direct_messages: false, allow_topic_mentions: false, - allow_personal_messages: false + allow_agentl_messages: false ) index = - "modality-#{allow_chat_channel_mentions}-#{allow_chat_direct_messages}-#{allow_topic_mentions}-#{allow_personal_messages}" + "modality-#{allow_chat_channel_mentions}-#{allow_chat_direct_messages}-#{allow_topic_mentions}-#{allow_agentl_messages}" - personas = - persona_cache[index.to_sym] ||= persona_users.select do |persona| - next true if allow_chat_channel_mentions && persona[:allow_chat_channel_mentions] - next true if allow_chat_direct_messages && persona[:allow_chat_direct_messages] - next true if allow_topic_mentions && persona[:allow_topic_mentions] - next true if allow_personal_messages && persona[:allow_personal_messages] + agents = + agent_cache[index.to_sym] ||= agent_users.select do |agent| + next true if allow_chat_channel_mentions && agent[:allow_chat_channel_mentions] + next true if allow_chat_direct_messages && agent[:allow_chat_direct_messages] + next true if allow_topic_mentions && agent[:allow_topic_mentions] + next true if allow_agentl_messages && agent[:allow_agentl_messages] false end if user - personas.select { |u| user.in_any_groups?(u[:allowed_group_ids]) } + agents.select { |u| user.in_any_groups?(u[:allowed_group_ids]) } else - personas + agents end end after_commit :bump_cache def bump_cache - self.class.persona_cache.flush! + self.class.agent_cache.flush! end def tools_can_not_be_duplicated @@ -138,7 +138,7 @@ class AiPersona < ActiveRecord::Base end if seen_tools.include?(inner_name) - errors.add(:tools, I18n.t("discourse_ai.ai_bot.personas.cannot_have_duplicate_tools")) + errors.add(:tools, I18n.t("discourse_ai.ai_bot.agents.cannot_have_duplicate_tools")) break else seen_tools.add(inner_name) @@ -154,7 +154,7 @@ class AiPersona < ActiveRecord::Base .pluck(:tool_name) .each do |tool_name| if builtin_tool_names.include?(tool_name.downcase) - errors.add(:tools, I18n.t("discourse_ai.ai_bot.personas.cannot_have_duplicate_tools")) + errors.add(:tools, I18n.t("discourse_ai.ai_bot.agents.cannot_have_duplicate_tools")) break end end @@ -176,7 +176,7 @@ class AiPersona < ActiveRecord::Base allow_chat_channel_mentions allow_chat_direct_messages allow_topic_mentions - allow_personal_messages + allow_agentl_messages force_default_llm name description @@ -208,14 +208,14 @@ class AiPersona < ActiveRecord::Base if inner_name.start_with?("custom-") custom_tool_id = inner_name.split("-", 2).last.to_i if AiTool.exists?(id: custom_tool_id, enabled: true) - klass = DiscourseAi::Personas::Tools::Custom.class_instance(custom_tool_id) + klass = DiscourseAi::Agents::Tools::Custom.class_instance(custom_tool_id) end else inner_name = inner_name.gsub("Tool", "") inner_name = "List#{inner_name}" if %w[Categories Tags].include?(inner_name) begin - klass = "DiscourseAi::Personas::Tools::#{inner_name}".constantize + klass = "DiscourseAi::Agents::Tools::#{inner_name}".constantize options[klass] = current_options if current_options rescue StandardError end @@ -225,14 +225,14 @@ class AiPersona < ActiveRecord::Base klass end - persona_class = DiscourseAi::Personas::Persona.system_personas_by_id[self.id] - if persona_class + agent_class = DiscourseAi::Agents::Agent.system_agents_by_id[self.id] + if agent_class return( # we need a new copy so we don't leak information # across sites - Class.new(persona_class) do + Class.new(agent_class) do # required for localization - define_singleton_method(:to_s) { persona_class.to_s } + define_singleton_method(:to_s) { agent_class.to_s } instance_attributes.each do |key, value| # description/name are localized define_singleton_method(key) { value } if key != :description && key != :name @@ -242,9 +242,9 @@ class AiPersona < ActiveRecord::Base ) end - ai_persona_id = self.id + ai_agent_id = self.id - Class.new(DiscourseAi::Personas::Persona) do + Class.new(DiscourseAi::Agents::Agent) do instance_attributes.each { |key, value| define_singleton_method(key) { value } } define_singleton_method(:to_s) do @@ -254,24 +254,24 @@ class AiPersona < ActiveRecord::Base define_singleton_method(:inspect) { to_s } define_method(:initialize) do |*args, **kwargs| - @ai_persona = AiPersona.find_by(id: ai_persona_id) + @ai_agent = AiAgent.find_by(id: ai_agent_id) super(*args, **kwargs) end define_method(:tools) { tools } define_method(:force_tool_use) { force_tool_use } - define_method(:forced_tool_count) { @ai_persona&.forced_tool_count } + define_method(:forced_tool_count) { @ai_agent&.forced_tool_count } define_method(:options) { options } - define_method(:temperature) { @ai_persona&.temperature } - define_method(:top_p) { @ai_persona&.top_p } - define_method(:system_prompt) { @ai_persona&.system_prompt || "You are a helpful bot." } - define_method(:uploads) { @ai_persona&.uploads } - define_method(:response_format) { @ai_persona&.response_format } - define_method(:examples) { @ai_persona&.examples } + define_method(:temperature) { @ai_agent&.temperature } + define_method(:top_p) { @ai_agent&.top_p } + define_method(:system_prompt) { @ai_agent&.system_prompt || "You are a helpful bot." } + define_method(:uploads) { @ai_agent&.uploads } + define_method(:response_format) { @ai_agent&.response_format } + define_method(:examples) { @ai_agent&.examples } end end - FIRST_PERSONA_USER_ID = -1200 + FIRST_AGENT_USER_ID = -1200 def create_user! raise "User already exists" if user_id && User.exists?(user_id) @@ -279,7 +279,7 @@ class AiPersona < ActiveRecord::Base # find the first id smaller than FIRST_USER_ID that is not taken id = nil - id = DB.query_single(<<~SQL, FIRST_PERSONA_USER_ID, FIRST_PERSONA_USER_ID - 200).first + id = DB.query_single(<<~SQL, FIRST_AGENT_USER_ID, FIRST_AGENT_USER_ID - 200).first WITH seq AS ( SELECT generate_series(?, ?, -1) AS id ) @@ -323,12 +323,12 @@ class AiPersona < ActiveRecord::Base allow_chat_channel_mentions || allow_chat_direct_messages || allow_topic_mentions || force_default_llm ) && !default_llm_id - errors.add(:default_llm, I18n.t("discourse_ai.ai_bot.personas.default_llm_required")) + errors.add(:default_llm, I18n.t("discourse_ai.ai_bot.agents.default_llm_required")) end end - def system_persona_unchangeable - error_msg = I18n.t("discourse_ai.ai_bot.personas.cannot_edit_system_persona") + def system_agent_unchangeable + error_msg = I18n.t("discourse_ai.ai_bot.agents.cannot_edit_system_agent") if top_p_changed? || temperature_changed? || system_prompt_changed? || name_changed? || description_changed? @@ -356,7 +356,7 @@ class AiPersona < ActiveRecord::Base def ensure_not_system if system - errors.add(:base, I18n.t("discourse_ai.ai_bot.personas.cannot_delete_system_persona")) + errors.add(:base, I18n.t("discourse_ai.ai_bot.agents.cannot_delete_system_agent")) throw :abort end end @@ -380,13 +380,13 @@ class AiPersona < ActiveRecord::Base return end - errors.add(:examples, I18n.t("discourse_ai.personas.malformed_examples")) + errors.add(:examples, I18n.t("discourse_ai.agents.malformed_examples")) end end # == Schema Information # -# Table name: ai_personas +# Table name: ai_agents # # id :bigint not null, primary key # name :string(100) not null @@ -414,7 +414,7 @@ end # allow_chat_channel_mentions :boolean default(FALSE), not null # allow_chat_direct_messages :boolean default(FALSE), not null # allow_topic_mentions :boolean default(FALSE), not null -# allow_personal_messages :boolean default(TRUE), not null +# allow_agentl_messages :boolean default(TRUE), not null # force_default_llm :boolean default(FALSE), not null # rag_llm_model_id :bigint # default_llm_id :bigint @@ -424,5 +424,5 @@ end # # Indexes # -# index_ai_personas_on_name (name) UNIQUE +# index_ai_agents_on_name (name) UNIQUE # diff --git a/app/models/ai_tool.rb b/app/models/ai_tool.rb index 6ff5582a..8da0df0f 100644 --- a/app/models/ai_tool.rb +++ b/app/models/ai_tool.rb @@ -36,7 +36,7 @@ class AiTool < ActiveRecord::Base end def runner(parameters, llm:, bot_user:, context: nil) - DiscourseAi::Personas::ToolRunner.new( + DiscourseAi::Agents::ToolRunner.new( parameters: parameters, llm: llm, bot_user: bot_user, @@ -45,10 +45,10 @@ class AiTool < ActiveRecord::Base ) end - after_commit :bump_persona_cache + after_commit :bump_agent_cache - def bump_persona_cache - AiPersona.persona_cache.flush! + def bump_agent_cache + AiAgent.agent_cache.flush! end def regenerate_rag_fragments @@ -176,11 +176,11 @@ class AiTool < ActiveRecord::Base * user_id_or_username (number | string): The ID or username of the user. * Returns: Object (User details using UserSerializer structure) or null if not found. * - * discourse.getPersona(name): Gets an object representing another AI Persona configured on the site. + * discourse.getAgent(name): Gets an object representing another AI Agent configured on the site. * Parameters: - * name (string): The name of the target persona. - * Returns: Object { respondTo: function(params) } or null if persona not found. - * respondTo(params): Instructs the target persona to generate a response within the current context (e.g., replying to the same post or chat message). + * name (string): The name of the target agent. + * Returns: Object { respondTo: function(params) } or null if agent not found. + * respondTo(params): Instructs the target agent to generate a response within the current context (e.g., replying to the same post or chat message). * Parameters: * params (Object, optional): { instructions: string, whisper: boolean } * Returns: { success: boolean, post_id?: number, post_number?: number, message_id?: number } or { error: string } @@ -201,7 +201,7 @@ class AiTool < ActiveRecord::Base * private_message (boolean): Whether the context is a private message (in Post context). * message_id (number): ID of the chat message triggering the tool (if in Chat context). * channel_id (number): ID of the chat channel (if in Chat context). - * user (Object): Details of the user invoking the tool/persona (structure may vary, often null or SystemUser details unless explicitly passed). + * user (Object): Details of the user invoking the tool/agent (structure may vary, often null or SystemUser details unless explicitly passed). * participants (string): Comma-separated list of usernames in a PM (if applicable). * // ... other potential context-specific properties added by the calling environment. * diff --git a/app/models/rag_document_fragment.rb b/app/models/rag_document_fragment.rb index b546b164..a1b3fbbf 100644 --- a/app/models/rag_document_fragment.rb +++ b/app/models/rag_document_fragment.rb @@ -2,7 +2,7 @@ class RagDocumentFragment < ActiveRecord::Base # TODO Jan 2025 - remove - self.ignored_columns = %i[ai_persona_id] + self.ignored_columns = %i[ai_agent_id] belongs_to :upload belongs_to :target, polymorphic: true @@ -38,7 +38,7 @@ class RagDocumentFragment < ActiveRecord::Base end end - def indexing_status(persona, uploads) + def indexing_status(agent, uploads) embeddings_table = DiscourseAi::Embeddings::Schema.for(self).table results = @@ -56,8 +56,8 @@ class RagDocumentFragment < ActiveRecord::Base WHERE uploads.id IN (:upload_ids) GROUP BY uploads.id SQL - target_id: persona.id, - target_type: persona.class.to_s, + target_id: agent.id, + target_type: agent.class.to_s, upload_ids: uploads.map(&:id), ) diff --git a/app/models/shared_ai_conversation.rb b/app/models/shared_ai_conversation.rb index f9e96d33..b7a8f74f 100644 --- a/app/models/shared_ai_conversation.rb +++ b/app/models/shared_ai_conversation.rb @@ -51,13 +51,13 @@ class SharedAiConversation < ActiveRecord::Base # but this name works class SharedPost attr_accessor :user - attr_reader :id, :user_id, :created_at, :cooked, :persona + attr_reader :id, :user_id, :created_at, :cooked, :agent def initialize(post) @id = post[:id] @user_id = post[:user_id] @created_at = DateTime.parse(post[:created_at]) @cooked = post[:cooked] - @persona = post[:persona] + @agent = post[:agent] end end @@ -140,9 +140,9 @@ class SharedAiConversation < ActiveRecord::Base llm_name = ActiveSupport::Inflector.humanize(llm_name) if llm_name llm_name ||= I18n.t("discourse_ai.unknown_model") - persona = nil - if persona_id = topic.custom_fields["ai_persona_id"] - persona = AiPersona.find_by(id: persona_id.to_i)&.name + agent = nil + if agent_id = topic.custom_fields["ai_agent_id"] + agent = AiAgent.find_by(id: agent_id.to_i)&.name end posts = @@ -167,7 +167,7 @@ class SharedAiConversation < ActiveRecord::Base cooked: cook_artifacts(post), } - mapped[:persona] = persona if ai_bot_participant&.id == post.user_id + mapped[:agent] = agent if ai_bot_participant&.id == post.user_id mapped[:username] = post.user&.username if include_usernames mapped end, diff --git a/app/serializers/ai_features_persona_serializer.rb b/app/serializers/ai_features_agent_serializer.rb similarity index 81% rename from app/serializers/ai_features_persona_serializer.rb rename to app/serializers/ai_features_agent_serializer.rb index 782b5604..4a1f62e5 100644 --- a/app/serializers/ai_features_persona_serializer.rb +++ b/app/serializers/ai_features_agent_serializer.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class AiFeaturesPersonaSerializer < ApplicationSerializer +class AiFeaturesAgentSerializer < ApplicationSerializer attributes :id, :name, :system_prompt, :allowed_groups, :enabled def allowed_groups diff --git a/app/serializers/llm_model_serializer.rb b/app/serializers/llm_model_serializer.rb index 736757d4..1a3fcf72 100644 --- a/app/serializers/llm_model_serializer.rb +++ b/app/serializers/llm_model_serializer.rb @@ -2,7 +2,7 @@ class LlmModelSerializer < ApplicationSerializer # TODO: we probably should rename the table LlmModel to AiLlm - # it is consistent with AiPersona and AiTool + # it is consistent with AiAgent and AiTool # LLM model is a bit confusing given that large langauge model model is a confusing # name root "ai_llm" diff --git a/app/serializers/localized_ai_persona_serializer.rb b/app/serializers/localized_ai_agent_serializer.rb similarity index 91% rename from app/serializers/localized_ai_persona_serializer.rb rename to app/serializers/localized_ai_agent_serializer.rb index 11b9d815..8485f7ed 100644 --- a/app/serializers/localized_ai_persona_serializer.rb +++ b/app/serializers/localized_ai_agent_serializer.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -class LocalizedAiPersonaSerializer < ApplicationSerializer - root "ai_persona" +class LocalizedAiAgentSerializer < ApplicationSerializer + root "ai_agent" attributes :id, :name, @@ -29,7 +29,7 @@ class LocalizedAiPersonaSerializer < ApplicationSerializer :allow_chat_channel_mentions, :allow_chat_direct_messages, :allow_topic_mentions, - :allow_personal_messages, + :allow_agentl_messages, :force_default_llm, :response_format, :examples diff --git a/app/views/discourse_ai/ai_bot/shared_ai_conversations/show.html.erb b/app/views/discourse_ai/ai_bot/shared_ai_conversations/show.html.erb index 2981ab13..8b07cb90 100644 --- a/app/views/discourse_ai/ai_bot/shared_ai_conversations/show.html.erb +++ b/app/views/discourse_ai/ai_bot/shared_ai_conversations/show.html.erb @@ -43,8 +43,8 @@
<%= post.user.username %> - <%if post.persona.present? %> - <%= post.persona %> + <%if post.agent.present? %> + <%= post.agent %> <% end %>
diff --git a/assets/javascripts/discourse/admin-discourse-ai-plugin-route-map.js b/assets/javascripts/discourse/admin-discourse-ai-plugin-route-map.js index aa2bed60..1bbb8fc4 100644 --- a/assets/javascripts/discourse/admin-discourse-ai-plugin-route-map.js +++ b/assets/javascripts/discourse/admin-discourse-ai-plugin-route-map.js @@ -4,7 +4,7 @@ export default { path: "/plugins", map() { - this.route("discourse-ai-personas", { path: "ai-personas" }, function () { + this.route("discourse-ai-agents", { path: "ai-agents" }, function () { this.route("new"); this.route("edit", { path: "/:id/edit" }); }); diff --git a/assets/javascripts/discourse/admin/adapters/ai-persona.js b/assets/javascripts/discourse/admin/adapters/ai-agent.js similarity index 94% rename from assets/javascripts/discourse/admin/adapters/ai-persona.js rename to assets/javascripts/discourse/admin/adapters/ai-agent.js index 6a837690..d6c73c5f 100644 --- a/assets/javascripts/discourse/admin/adapters/ai-persona.js +++ b/assets/javascripts/discourse/admin/adapters/ai-agent.js @@ -16,6 +16,6 @@ export default class Adapter extends RestAdapter { } apiNameFor() { - return "ai-persona"; + return "ai-agent"; } } diff --git a/assets/javascripts/discourse/admin/models/ai-persona.js b/assets/javascripts/discourse/admin/models/ai-agent.js similarity index 91% rename from assets/javascripts/discourse/admin/models/ai-persona.js rename to assets/javascripts/discourse/admin/models/ai-agent.js index 042bc786..9cd3dbd6 100644 --- a/assets/javascripts/discourse/admin/models/ai-persona.js +++ b/assets/javascripts/discourse/admin/models/ai-agent.js @@ -29,7 +29,7 @@ const CREATE_ATTRIBUTES = [ "allow_chat", "tool_details", "forced_tool_count", - "allow_personal_messages", + "allow_agentl_messages", "allow_topic_mentions", "allow_chat_channel_mentions", "allow_chat_direct_messages", @@ -58,16 +58,16 @@ const SYSTEM_ATTRIBUTES = [ "rag_llm_model_id", "question_consolidator_llm_id", "tool_details", - "allow_personal_messages", + "allow_agentl_messages", "allow_topic_mentions", "allow_chat_channel_mentions", "allow_chat_direct_messages", ]; -export default class AiPersona extends RestModel { +export default class AiAgent extends RestModel { async createUser() { const result = await ajax( - `/admin/plugins/discourse-ai/ai-personas/${this.id}/create-user.json`, + `/admin/plugins/discourse-ai/ai-agents/${this.id}/create-user.json`, { type: "POST", } @@ -143,10 +143,10 @@ export default class AiPersona extends RestModel { fromPOJO(data) { const dataClone = JSON.parse(JSON.stringify(data)); - const persona = AiPersona.create(dataClone); - persona.tools = this.flattenedToolStructure(dataClone); + const agent = AiAgent.create(dataClone); + agent.tools = this.flattenedToolStructure(dataClone); - return persona; + return agent; } toPOJO() { diff --git a/assets/javascripts/discourse/admin/models/ai-feature.js b/assets/javascripts/discourse/admin/models/ai-feature.js index 85dfa7ca..f343a1e4 100644 --- a/assets/javascripts/discourse/admin/models/ai-feature.js +++ b/assets/javascripts/discourse/admin/models/ai-feature.js @@ -8,8 +8,8 @@ export default class AiFeature extends RestModel { "ref", "description", "enable_setting", - "persona", - "persona_setting" + "agent", + "agent_setting" ); } } diff --git a/assets/javascripts/discourse/components/ai-persona-editor.gjs b/assets/javascripts/discourse/components/ai-agent-editor.gjs similarity index 74% rename from assets/javascripts/discourse/components/ai-persona-editor.gjs rename to assets/javascripts/discourse/components/ai-agent-editor.gjs index caf9c403..d6e1692b 100644 --- a/assets/javascripts/discourse/components/ai-persona-editor.gjs +++ b/assets/javascripts/discourse/components/ai-agent-editor.gjs @@ -15,15 +15,15 @@ import Group from "discourse/models/group"; import { i18n } from "discourse-i18n"; import AdminUser from "admin/models/admin-user"; import GroupChooser from "select-kit/components/group-chooser"; -import AiPersonaResponseFormatEditor from "../components/modal/ai-persona-response-format-editor"; +import AiAgentResponseFormatEditor from "../components/modal/ai-agent-response-format-editor"; import AiLlmSelector from "./ai-llm-selector"; -import AiPersonaCollapsableExample from "./ai-persona-example"; -import AiPersonaToolOptions from "./ai-persona-tool-options"; +import AiAgentCollapsableExample from "./ai-agent-example"; +import AiAgentToolOptions from "./ai-agent-tool-options"; import AiToolSelector from "./ai-tool-selector"; import RagOptionsFk from "./rag-options-fk"; import RagUploader from "./rag-uploader"; -export default class PersonaEditor extends Component { +export default class AgentEditor extends Component { @service router; @service store; @service dialog; @@ -59,12 +59,12 @@ export default class PersonaEditor extends Component { } get allTools() { - return this.args.personas.resultSetMeta.tools; + return this.args.agents.resultSetMeta.tools; } get maxPixelValues() { const l = (key) => - i18n(`discourse_ai.ai_persona.vision_max_pixel_sizes.${key}`); + i18n(`discourse_ai.ai_agent.vision_max_pixel_sizes.${key}`); return [ { name: l("low"), id: 65536 }, { name: l("medium"), id: 262144 }, @@ -76,14 +76,14 @@ export default class PersonaEditor extends Component { const content = [ { id: -1, - name: i18n("discourse_ai.ai_persona.tool_strategies.all"), + name: i18n("discourse_ai.ai_agent.tool_strategies.all"), }, ]; [1, 2, 5].forEach((i) => { content.push({ id: i, - name: i18n("discourse_ai.ai_persona.tool_strategies.replies", { + name: i18n("discourse_ai.ai_agent.tool_strategies.replies", { count: i, }), }); @@ -112,23 +112,23 @@ export default class PersonaEditor extends Component { this.isSaving = true; try { - const personaToSave = Object.assign( + const agentToSave = Object.assign( this.args.model, this.args.model.fromPOJO(data) ); - await personaToSave.save(); - this.#sortPersonas(); + await agentToSave.save(); + this.#sortAgents(); if (isNew && this.args.model.rag_uploads.length === 0) { - this.args.personas.addObject(personaToSave); + this.args.agents.addObject(agentToSave); this.router.transitionTo( - "adminPlugins.show.discourse-ai-personas.edit", - personaToSave + "adminPlugins.show.discourse-ai-agents.edit", + agentToSave ); } else { this.toasts.success({ - data: { message: i18n("discourse_ai.ai_persona.saved") }, + data: { message: i18n("discourse_ai.ai_agent.saved") }, duration: 2000, }); } @@ -151,12 +151,12 @@ export default class PersonaEditor extends Component { @action delete() { return this.dialog.confirm({ - message: i18n("discourse_ai.ai_persona.confirm_delete"), + message: i18n("discourse_ai.ai_agent.confirm_delete"), didConfirm: () => { return this.args.model.destroyRecord().then(() => { - this.args.personas.removeObject(this.args.model); + this.args.agents.removeObject(this.args.model); this.router.transitionTo( - "adminPlugins.show.discourse-ai-personas.index" + "adminPlugins.show.discourse-ai-agents.index" ); }); }, @@ -259,7 +259,7 @@ export default class PersonaEditor extends Component { return updatedOptions; } - async persistField(dirtyData, field, newValue, sortPersonas) { + async persistField(dirtyData, field, newValue, sortAgents) { if (!this.args.model.isNew) { const updatedDirtyData = Object.assign({}, dirtyData); updatedDirtyData[field] = newValue; @@ -270,8 +270,8 @@ export default class PersonaEditor extends Component { this.dirtyFormData = updatedDirtyData; await this.args.model.update(args); - if (sortPersonas) { - this.#sortPersonas(); + if (sortAgents) { + this.#sortAgents(); } } catch (e) { popupAjaxError(e); @@ -279,8 +279,8 @@ export default class PersonaEditor extends Component { } } - #sortPersonas() { - const sorted = this.args.personas.toArray().sort((a, b) => { + #sortAgents() { + const sorted = this.args.agents.toArray().sort((a, b) => { if (a.priority && !b.priority) { return -1; } else if (!a.priority && b.priority) { @@ -289,20 +289,20 @@ export default class PersonaEditor extends Component { return a.name.localeCompare(b.name); } }); - this.args.personas.clear(); - this.args.personas.setObjects(sorted); + this.args.agents.clear(); + this.args.agents.setObjects(sorted); }