From b4bd5634a1c5fcdbea832fa0a695c2e73c997c2e Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Tue, 16 Dec 2025 17:14:01 +0530 Subject: [PATCH] feat: use new controller --- .../dashboard/api/captain/editor.js | 72 +++++++++++++++++++ app/javascript/dashboard/composables/useAI.js | 6 +- 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 app/javascript/dashboard/api/captain/editor.js diff --git a/app/javascript/dashboard/api/captain/editor.js b/app/javascript/dashboard/api/captain/editor.js new file mode 100644 index 000000000..95d2872ba --- /dev/null +++ b/app/javascript/dashboard/api/captain/editor.js @@ -0,0 +1,72 @@ +/* global axios */ +import ApiClient from '../ApiClient'; + +/** + * A client for the Captain Editor API. + * @extends ApiClient + */ +class EditorAPI extends ApiClient { + /** + * Creates a new EditorAPI instance. + */ + constructor() { + super('captain/editor', { accountScoped: true }); + + /** + * The conversation events supported by the API. + * @type {string[]} + */ + this.conversation_events = ['summarize', 'reply_suggestion']; + + /** + * The message events supported by the API. + * @type {string[]} + */ + this.message_events = ['rephrase']; + } + + /** + * Processes an event using the Captain Editor API. + * @param {Object} options - The options for the event. + * @param {string} [options.type='rephrase'] - The type of event to process. + * @param {string} [options.content] - The content of the event. + * @param {string} [options.tone] - The tone of the event. + * @param {string} [options.conversationId] - The ID of the conversation to process the event for. + * @param {AbortSignal} [signal] - AbortSignal to cancel the request. + * @returns {Promise} A promise that resolves with the result of the event processing. + */ + processEvent({ type = 'rephrase', content, tone, conversationId }, signal) { + /** + * @type {Object} + */ + let data = { + tone, + content, + }; + + // Always include conversation_display_id when available for session tracking + if (conversationId) { + data.conversation_display_id = conversationId; + } + + // For conversation-level events, only send conversation_display_id + if (this.conversation_events.includes(type)) { + data = { + conversation_display_id: conversationId, + }; + } + + return axios.post( + `${this.url}/process_event`, + { + event: { + name: type, + data, + }, + }, + { signal } + ); + } +} + +export default new EditorAPI(); diff --git a/app/javascript/dashboard/composables/useAI.js b/app/javascript/dashboard/composables/useAI.js index d519dc295..ab94d7016 100644 --- a/app/javascript/dashboard/composables/useAI.js +++ b/app/javascript/dashboard/composables/useAI.js @@ -8,6 +8,7 @@ import { useAlert, useTrack } from 'dashboard/composables'; import { useI18n } from 'vue-i18n'; import { OPEN_AI_EVENTS } from 'dashboard/helper/AnalyticsHelper/events'; import OpenAPI from 'dashboard/api/integrations/openapi'; +import EditorAPI from 'dashboard/api/captain/editor'; /** * Cleans and normalizes a list of labels. @@ -57,7 +58,7 @@ export function useAI() { * Computed property to check if AI integration is enabled. * @type {import('vue').ComputedRef} */ - const isAIIntegrationEnabled = computed(() => !!aiIntegration.value); + const isAIIntegrationEnabled = computed(() => true); /** * Computed property to check if label suggestion feature is enabled. @@ -169,9 +170,8 @@ export function useAI() { options = {} ) => { try { - const result = await OpenAPI.processEvent( + const result = await EditorAPI.processEvent( { - hookId: hookId.value, type, content: content || draftMessage.value, conversationId: conversationId.value,