Skip to content
This repository was archived by the owner on Mar 18, 2026. It is now read-only.
Closed

Hr #16

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 158 additions & 0 deletions src/app/api/interactionAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import { devLog } from '@/app/utils/logger';
import { API_BASE_URL } from '@/app/config.js';

/**
* ExecutionMeta 정보들을 리스트 형태로 반환합니다.
* @param {Object} filters - 필터링 옵션
* @param {string} [filters.interaction_id] - 특정 상호작용 ID로 필터링 (선택적)
* @param {string} [filters.workflow_id] - 특정 워크플로우 ID로 필터링 (선택적)
* @param {number} [filters.limit=100] - 반환할 최대 레코드 수 (기본값: 100)
* @returns {Promise<Object>} ExecutionMeta 데이터 리스트를 포함하는 프로미스
* @throws {Error} API 요청이 실패하면 에러를 발생시킵니다.
*/
export const listInteractions = async (filters = {}) => {
try {
const { interaction_id, workflow_id, limit = 100 } = filters;

// URL 파라미터 구성
const params = new URLSearchParams();
if (interaction_id) params.append('interaction_id', interaction_id);
if (workflow_id) params.append('workflow_id', workflow_id);
params.append('limit', limit.toString());

const response = await fetch(
`${API_BASE_URL}/interaction/list?${params}`,
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
},
);

if (!response.ok) {
const errorData = await response.json();
throw new Error(
errorData.detail || `HTTP error! status: ${response.status}`,
);
}

const result = await response.json();
devLog.log('Interaction list retrieved successfully:', result);
return result;
} catch (error) {
devLog.error('Failed to list interactions:', error);
throw error;
}
};

/**
* 새로운 워크플로우 실행을 시작하고 ExecutionMeta에 메타데이터를 저장합니다.
* @param {Object} requestData - 워크플로우 실행 요청 데이터
* @param {string} requestData.workflow_name - 워크플로우 이름
* @param {string} requestData.workflow_id - 워크플로우 ID
* @param {string} requestData.interaction_id - 상호작용 ID
* @param {string} [requestData.input_data] - 입력 데이터 (선택적)
* @returns {Promise<Object>} 워크플로우 실행 결과를 포함하는 프로미스
* @throws {Error} API 요청이 실패하면 에러를 발생시킵니다.
*/
export const executeWorkflowNew = async (requestData) => {
try {
const { workflow_name, workflow_id, interaction_id, input_data } = requestData;

// 필수 파라미터 검증
if (!workflow_name || !workflow_id || !interaction_id) {
throw new Error('workflow_name, workflow_id, interaction_id는 필수 파라미터입니다.');
}

const requestBody = {
workflow_name,
workflow_id,
interaction_id,
...(input_data && { input_data }),
};

devLog.log('Executing new workflow with data:', requestBody);

const response = await fetch(`${API_BASE_URL}/interaction/new`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody),
});

if (!response.ok) {
const errorData = await response.json();
throw new Error(
errorData.detail || `HTTP error! status: ${response.status}`,
);
}

const result = await response.json();
devLog.log('Workflow executed successfully:', result);
return result;
} catch (error) {
devLog.error('Failed to execute new workflow:', error);
throw error;
}
};

/**
* 특정 workflow_id에 대한 모든 상호작용을 조회합니다.
* @param {string} workflow_id - 워크플로우 ID
* @param {number} [limit=100] - 반환할 최대 레코드 수
* @returns {Promise<Object>} 해당 워크플로우의 상호작용 리스트
* @throws {Error} API 요청이 실패하면 에러를 발생시킵니다.
*/
export const getWorkflowInteractions = async (workflow_id, limit = 100) => {
try {
if (!workflow_id) {
throw new Error('workflow_id는 필수 파라미터입니다.');
}

return await listInteractions({ workflow_id, limit });
} catch (error) {
devLog.error('Failed to get workflow interactions:', error);
throw error;
}
};

/**
* 특정 interaction_id에 대한 상호작용 정보를 조회합니다.
* @param {string} interaction_id - 상호작용 ID
* @returns {Promise<Object>} 해당 상호작용의 정보
* @throws {Error} API 요청이 실패하면 에러를 발생시킵니다.
*/
export const getInteractionById = async (interaction_id) => {
try {
if (!interaction_id) {
throw new Error('interaction_id는 필수 파라미터입니다.');
}

return await listInteractions({ interaction_id, limit: 1 });
} catch (error) {
devLog.error('Failed to get interaction by ID:', error);
throw error;
}
};

/**
* 고유한 interaction_id를 생성합니다.
* @param {string} [prefix='chat'] - ID 접두사
* @returns {string} 생성된 고유 interaction_id
*/
export const generateInteractionId = (prefix = 'chat') => {
const timestamp = Date.now();
const random = Math.random().toString(36).substring(2, 8);
return `${prefix}_${timestamp}_${random}`;
};

/**
* 워크플로우 이름에서 .json 확장자를 제거합니다.
* @param {string} workflowName - 워크플로우 이름
* @returns {string} 확장자가 제거된 워크플로우 이름
*/
export const normalizeWorkflowName = (workflowName) => {
return workflowName.replace('.json', '');
};
100 changes: 91 additions & 9 deletions src/app/api/workflowAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,19 @@ export const getWorkflowPerformance = async (workflowName, workflowId) => {
};

/**
* 특정 워크플로우의 성능 모니터링 데이터를 가져옵니다.
* 특정 워크플로우의 실행 기록 데이터를 가져옵니다.
* @param {string} workflowName - 워크플로우 이름 (.json 확장자 제외)
* @param {string} workflowId - 워크플로우 ID
* @returns {Promise<Object>} 성능 데이터를 포함하는 프로미스
* @param {string} interactionId - 상호작용 ID (선택사항, 기본값: "default")
* @returns {Promise<Object>} 실행 기록 데이터를 포함하는 프로미스
* @throws {Error} API 요청이 실패하면 에러를 발생시킵니다.
*/
export const getWorkflowIOLogs = async (workflowName, workflowId) => {
export const getWorkflowIOLogs = async (workflowName, workflowId, interactionId = 'default') => {
try {
const params = new URLSearchParams({
workflow_name: workflowName,
workflow_id: workflowId,
interaction_id: interactionId,
});

const response = await fetch(
Expand All @@ -289,10 +291,52 @@ export const getWorkflowIOLogs = async (workflowName, workflowId) => {
}

const result = await response.json();
devLog.log('Workflow performance data retrieved successfully:', result);
devLog.log('Workflow IO logs retrieved successfully:', result);
return result;
} catch (error) {
devLog.error('Failed to get workflow performance:', error);
devLog.error('Failed to get workflow IO logs:', error);
throw error;
}
};

/**
* 특정 워크플로우의 실행 기록 데이터를 삭제합니다.
* @param {string} workflowName - 워크플로우 이름 (.json 확장자 제외)
* @param {string} workflowId - 워크플로우 ID
* @param {string} interactionId - 상호작용 ID (기본값: "default")
* @returns {Promise<Object>} 삭제 결과 데이터를 포함하는 프로미스
* @throws {Error} API 요청이 실패하면 에러를 발생시킵니다.
*/
export const deleteWorkflowIOLogs = async (workflowName, workflowId, interactionId = 'default') => {
try {
const params = new URLSearchParams({
workflow_name: workflowName,
workflow_id: workflowId,
interaction_id: interactionId,
});

const response = await fetch(
`${API_BASE_URL}/workflow/io_logs?${params}`,
{
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
},
);

if (!response.ok) {
const errorData = await response.json();
throw new Error(
errorData.detail || `HTTP error! status: ${response.status}`,
);
}

const result = await response.json();
devLog.log('Workflow IO logs deleted successfully:', result);
return result;
} catch (error) {
devLog.error('Failed to delete workflow IO logs:', error);
throw error;
}
};
Expand All @@ -309,17 +353,15 @@ export const executeWorkflowById = async (
workflowName,
workflowId,
inputData = '',
interaction_id = 'default',
) => {
try {
const body = {
workflow_name: workflowName,
workflow_id: workflowId,
input_data: inputData || '',
interaction_id: interaction_id || 'default',
};
devLog.log('ExecuteWorkflowById called with:');
devLog.log('- workflowName:', workflowName);
devLog.log('- workflowId:', workflowId);
devLog.log('- inputData:', inputData);
const response = await fetch(
`${API_BASE_URL}/workflow/execute/based_id`,
{
Expand All @@ -346,3 +388,43 @@ export const executeWorkflowById = async (
throw error;
}
};

/**
* 워크플로우의 성능 데이터를 삭제합니다.
* @param {string} workflowName - 워크플로우 이름 (.json 확장자 제외)
* @param {string} workflowId - 워크플로우 ID
* @returns {Promise<Object>} 삭제 결과를 포함하는 프로미스
* @throws {Error} API 요청이 실패하면 에러를 발생시킵니다.
*/
export const deleteWorkflowPerformance = async (workflowName, workflowId) => {
try {
const params = new URLSearchParams({
workflow_name: workflowName,
workflow_id: workflowId,
});

const response = await fetch(
`${API_BASE_URL}/workflow/performance?${params}`,
{
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
},
);

if (!response.ok) {
const errorData = await response.json();
throw new Error(
errorData.detail || `HTTP error! status: ${response.status}`,
);
}

const result = await response.json();
devLog.log('Workflow performance data deleted successfully:', result);
return result;
} catch (error) {
devLog.error('Failed to delete workflow performance data:', error);
throw error;
}
};
Loading
Loading