From 2f81fcee8c63c1045325149e2888b3219ae5d95d Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 17 Dec 2025 16:57:32 +0530 Subject: [PATCH] feat: use new service --- .../dashboard/api/integrations/openapi.js | 89 ------------------- .../dashboard/composables/spec/useAI.spec.js | 9 +- app/javascript/dashboard/composables/useAI.js | 10 +-- 3 files changed, 5 insertions(+), 103 deletions(-) delete mode 100644 app/javascript/dashboard/api/integrations/openapi.js diff --git a/app/javascript/dashboard/api/integrations/openapi.js b/app/javascript/dashboard/api/integrations/openapi.js deleted file mode 100644 index fb92bba0d..000000000 --- a/app/javascript/dashboard/api/integrations/openapi.js +++ /dev/null @@ -1,89 +0,0 @@ -/* global axios */ - -import ApiClient from '../ApiClient'; - -/** - * Represents the data object for a OpenAI hook. - * @typedef {Object} ConversationMessageData - * @property {string} [tone] - The tone of the message. - * @property {string} [content] - The content of the message. - * @property {string} [conversation_display_id] - The display ID of the conversation (optional). - */ - -/** - * A client for the OpenAI API. - * @extends ApiClient - */ -class OpenAIAPI extends ApiClient { - /** - * Creates a new OpenAIAPI instance. - */ - constructor() { - super('integrations', { accountScoped: true }); - - /** - * The conversation events supported by the API. - * @type {string[]} - */ - this.conversation_events = [ - 'summarize', - 'reply_suggestion', - 'label_suggestion', - ]; - - /** - * The message events supported by the API. - * @type {string[]} - */ - this.message_events = ['rephrase']; - } - - /** - * Processes an event using the OpenAI 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 {string} options.hookId - The ID of the hook to use for processing the event. - * @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, hookId }, - signal - ) { - /** - * @type {ConversationMessageData} - */ - 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}/hooks/${hookId}/process_event`, - { - event: { - name: type, - data, - }, - }, - { signal } - ); - } -} - -export default new OpenAIAPI(); diff --git a/app/javascript/dashboard/composables/spec/useAI.spec.js b/app/javascript/dashboard/composables/spec/useAI.spec.js index 2431fe196..d7074c222 100644 --- a/app/javascript/dashboard/composables/spec/useAI.spec.js +++ b/app/javascript/dashboard/composables/spec/useAI.spec.js @@ -5,12 +5,12 @@ import { useMapGetter, } from 'dashboard/composables/store'; import { useI18n } from 'vue-i18n'; -import OpenAPI from 'dashboard/api/integrations/openapi'; +import EditorAPI from 'dashboard/api/captain/editor'; import analyticsHelper from 'dashboard/helper/AnalyticsHelper/index'; vi.mock('dashboard/composables/store'); vi.mock('vue-i18n'); -vi.mock('dashboard/api/integrations/openapi'); +vi.mock('dashboard/api/captain/editor'); vi.mock('dashboard/helper/AnalyticsHelper/index', async importOriginal => { const actual = await importOriginal(); actual.default = { @@ -94,7 +94,7 @@ describe('useAI', () => { }); it('fetches label suggestions', async () => { - OpenAPI.processEvent.mockResolvedValue({ + EditorAPI.processEvent.mockResolvedValue({ data: { message: 'label1, label2' }, }); @@ -111,9 +111,8 @@ describe('useAI', () => { const { fetchLabelSuggestions } = useAI(); const result = await fetchLabelSuggestions(); - expect(OpenAPI.processEvent).toHaveBeenCalledWith({ + expect(EditorAPI.processEvent).toHaveBeenCalledWith({ type: 'label_suggestion', - hookId: 'hook1', conversationId: '123', }); diff --git a/app/javascript/dashboard/composables/useAI.js b/app/javascript/dashboard/composables/useAI.js index ab94d7016..009aed6ac 100644 --- a/app/javascript/dashboard/composables/useAI.js +++ b/app/javascript/dashboard/composables/useAI.js @@ -7,7 +7,6 @@ import { 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'; /** @@ -78,12 +77,6 @@ export function useAI() { */ const isFetchingAppIntegrations = computed(() => uiFlags.value.isFetching); - /** - * Computed property for the hook ID. - * @type {import('vue').ComputedRef} - */ - const hookId = computed(() => aiIntegration.value?.id); - /** * Computed property for the conversation ID. * @type {import('vue').ComputedRef} @@ -140,9 +133,8 @@ export function useAI() { if (!conversationId.value) return []; try { - const result = await OpenAPI.processEvent({ + const result = await EditorAPI.processEvent({ type: 'label_suggestion', - hookId: hookId.value, conversationId: conversationId.value, });