2024-03-08 10:07:48 +00:00
|
|
|
import Component from "@glimmer/component";
|
|
|
|
import { action } from "@ember/object";
|
|
|
|
import { service } from "@ember/service";
|
|
|
|
import DButton from "discourse/components/d-button";
|
2025-02-06 16:42:32 +00:00
|
|
|
import { i18n } from "discourse-i18n";
|
2024-03-08 10:07:48 +00:00
|
|
|
import { composeAiBotMessage } from "../lib/ai-bot-helper";
|
|
|
|
|
|
|
|
export default class AiBotHeaderIcon extends Component {
|
2024-06-18 14:32:14 -03:00
|
|
|
@service currentUser;
|
2024-03-08 10:07:48 +00:00
|
|
|
@service siteSettings;
|
|
|
|
@service composer;
|
|
|
|
|
|
|
|
get bots() {
|
2024-06-18 14:32:14 -03:00
|
|
|
const availableBots = this.currentUser.ai_enabled_chat_bots
|
|
|
|
.filter((bot) => !bot.is_persosna)
|
|
|
|
.filter(Boolean);
|
|
|
|
|
|
|
|
return availableBots ? availableBots.map((bot) => bot.model_name) : [];
|
|
|
|
}
|
|
|
|
|
|
|
|
get showHeaderButton() {
|
|
|
|
return this.bots.length > 0 && this.siteSettings.ai_bot_add_to_header;
|
2024-03-08 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
compose() {
|
|
|
|
composeAiBotMessage(this.bots[0], this.composer);
|
|
|
|
}
|
|
|
|
|
|
|
|
<template>
|
2024-06-18 14:32:14 -03:00
|
|
|
{{#if this.showHeaderButton}}
|
2024-03-08 10:07:48 +00:00
|
|
|
<li>
|
2024-05-14 17:54:54 +10:00
|
|
|
<DButton
|
2024-05-14 15:30:03 +02:00
|
|
|
@action={{this.compose}}
|
2024-05-14 17:54:54 +10:00
|
|
|
@icon="robot"
|
2024-05-14 15:30:03 +02:00
|
|
|
title={{i18n "discourse_ai.ai_bot.shortcut_title"}}
|
2024-05-14 17:54:54 +10:00
|
|
|
class="ai-bot-button icon btn-flat"
|
|
|
|
/>
|
2024-03-08 10:07:48 +00:00
|
|
|
</li>
|
|
|
|
{{/if}}
|
|
|
|
</template>
|
|
|
|
}
|