import type { Fetcher } from 'swr' import { get, post } from './base' import type { CommonResponse } from '@/models/common' import type { ChatRunHistoryResponse, FetchWorkflowDraftResponse, NodesDefaultConfigsResponse, WorkflowRunHistoryResponse, } from '@/types/workflow' import type { BlockEnum } from '@/app/components/workflow/types' export const fetchWorkflowDraft = (url: string) => { return get(url, {}, { silent: true }) as Promise } export const syncWorkflowDraft = ({ url, params }: { url: string; params: Pick }) => { return post(url, { body: params }, { silent: true }) } export const fetchNodesDefaultConfigs: Fetcher = (url) => { return get(url) } export const fetchWorkflowRunHistory: Fetcher = (url) => { return get(url) } export const fetcChatRunHistory: Fetcher = (url) => { return get(url) } export const singleNodeRun = (appId: string, nodeId: string, params: object) => { return post(`apps/${appId}/workflows/draft/nodes/${nodeId}/run`, { body: params }) } export const publishWorkflow = (url: string) => { return post(url) } export const fetchPublishedWorkflow: Fetcher = (url) => { return get(url) } export const stopWorkflowRun = (url: string) => { return post(url) } export const fetchNodeDefault = (appId: string, blockType: BlockEnum, query = {}) => { return get(`apps/${appId}/workflows/default-workflow-block-configs/${blockType}`, { params: { q: JSON.stringify(query) }, }) }