/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once #include "mtproto/sender.h" #include "ui/text/text_entity.h" #include #include class ApiWrap; namespace Main { class Session; } // namespace Main namespace Ui { class InputField; class Show; } // namespace Ui namespace Api { class ComposeWithAi final { public: struct ToneRef { QString defaultTone; uint64 id = 0; uint64 accessHash = 0; }; struct Request { TextWithEntities text; QString translateToLang; std::optional tone; bool proofread = false; bool emojify = false; void setDefaultTone(const QString &type) { tone = ToneRef{ .defaultTone = type }; } void setCustomTone(uint64 id, uint64 accessHash) { tone = ToneRef{ .id = id, .accessHash = accessHash }; } }; struct DiffEntity { enum class Type { Insert, Replace, Delete, }; Type type = Type::Insert; int offset = 0; int length = 0; QString oldText; }; struct Diff { TextWithEntities text; std::vector entities; }; struct Result { TextWithEntities resultText; std::optional diffText; }; explicit ComposeWithAi(not_null api); [[nodiscard]] mtpRequestId request( Request request, Fn done, Fn fail = nullptr); void cancel(mtpRequestId requestId); private: [[nodiscard]] static Diff ParseDiff( not_null session, const MTPTextWithEntities &text); const not_null _session; MTP::Sender _api; }; void ApplyAiInPlaceBySlug( not_null session, TextWithEntities text, QString slug, Fn done, Fn fail = nullptr); [[nodiscard]] QString AiApplyBoundSlug(); void SetAiApplyBoundSlug(const QString &slug); void ClearAiApplyBoundSlug(); [[nodiscard]] QString AiApplyShortcutText(); void TriggerAiApplyInPlace( not_null session, std::shared_ptr show, not_null guard, not_null field, TextWithEntities fullFieldText, Fn applyToField); } // namespace Api