feat: use new controller

This commit is contained in:
Shivam Mishra
2025-12-16 17:14:01 +05:30
parent db7c7f5edf
commit b4bd5634a1
2 changed files with 75 additions and 3 deletions
@@ -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();
@@ -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<boolean>}
*/
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,