2024-03-08 05:07:48 -05:00
|
|
|
import Component from "@glimmer/component";
|
|
|
|
import { action } from "@ember/object";
|
|
|
|
import { service } from "@ember/service";
|
|
|
|
import DButton from "discourse/components/d-button";
|
|
|
|
import i18n from "discourse-common/helpers/i18n";
|
|
|
|
import { composeAiBotMessage } from "../lib/ai-bot-helper";
|
|
|
|
|
|
|
|
export default class AiBotHeaderIcon extends Component {
|
2024-06-18 13:32:14 -04:00
|
|
|
@service currentUser;
|
2024-03-08 05:07:48 -05:00
|
|
|
@service siteSettings;
|
|
|
|
@service composer;
|
|
|
|
|
|
|
|
get bots() {
|
2024-06-18 13:32:14 -04: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 05:07:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
compose() {
|
|
|
|
composeAiBotMessage(this.bots[0], this.composer);
|
|
|
|
}
|
|
|
|
|
|
|
|
<template>
|
2024-06-18 13:32:14 -04:00
|
|
|
{{#if this.showHeaderButton}}
|
2024-03-08 05:07:48 -05:00
|
|
|
<li>
|
2024-05-14 03:54:54 -04:00
|
|
|
<DButton
|
2024-05-14 09:30:03 -04:00
|
|
|
@action={{this.compose}}
|
2024-05-14 03:54:54 -04:00
|
|
|
@icon="robot"
|
2024-05-14 09:30:03 -04:00
|
|
|
title={{i18n "discourse_ai.ai_bot.shortcut_title"}}
|
2024-05-14 03:54:54 -04:00
|
|
|
class="ai-bot-button icon btn-flat"
|
|
|
|
/>
|
2024-03-08 05:07:48 -05:00
|
|
|
</li>
|
|
|
|
{{/if}}
|
|
|
|
</template>
|
|
|
|
}
|