From 2fac78575aa073216620b90cafc35c70c286354f Mon Sep 17 00:00:00 2001 From: warren Date: Thu, 26 Dec 2024 15:08:10 +0800 Subject: [PATCH] reformat --- web/service/workflow.ts | 41 ++++++++++++++++++++++++----------------- web/types/workflow.ts | 20 +++++++------------- web/utils/var.ts | 17 +++++++++++------ 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/web/service/workflow.ts b/web/service/workflow.ts index 10b5eac7cc5f29..52864fd13f3c8b 100644 --- a/web/service/workflow.ts +++ b/web/service/workflow.ts @@ -1,21 +1,25 @@ -import type { Fetcher } from 'swr' -import { get, post } from './base' -import type { CommonResponse } from '@/models/common' +import type {Fetcher} from 'swr' +import {get, post} from './base' +import type {CommonResponse} from '@/models/common' import { - ChatRunHistoryResponse, - ConversationVariableResponse, FetchWorkflowDraftPageResponse, - FetchWorkflowDraftResponse, - NodesDefaultConfigsResponse, - WorkflowRunHistoryResponse, + ChatRunHistoryResponse, + ConversationVariableResponse, + FetchWorkflowDraftPageResponse, + FetchWorkflowDraftResponse, + NodesDefaultConfigsResponse, + WorkflowRunHistoryResponse, } from '@/types/workflow' -import type { BlockEnum } from '@/app/components/workflow/types' +import type {BlockEnum} from '@/app/components/workflow/types' export const fetchWorkflowDraft = (url: string) => { - return get(url, {}, { silent: true }) as Promise + 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 syncWorkflowDraft = ({url, params}: { + url: string; + params: Pick +}) => { + return post(url, {body: params}, {silent: true}) } export const fetchNodesDefaultConfigs: Fetcher = (url) => { @@ -31,7 +35,7 @@ export const fetchChatRunHistory: Fetcher = (url } export const singleNodeRun = (appId: string, nodeId: string, params: object) => { - return post(`apps/${appId}/workflows/draft/nodes/${nodeId}/run`, { body: params }) + return post(`apps/${appId}/workflows/draft/nodes/${nodeId}/run`, {body: params}) } export const getIterationSingleNodeRunUrl = (isChatFlow: boolean, appId: string, nodeId: string) => { @@ -56,15 +60,18 @@ export const stopWorkflowRun = (url: string) => { export const fetchNodeDefault = (appId: string, blockType: BlockEnum, query = {}) => { return get(`apps/${appId}/workflows/default-workflow-block-configs/${blockType}`, { - params: { q: JSON.stringify(query) }, + params: {q: JSON.stringify(query)}, }) } // TODO: archived export const updateWorkflowDraftFromDSL = (appId: string, data: string) => { - return post(`apps/${appId}/workflows/draft/import`, { body: { data } }) + return post(`apps/${appId}/workflows/draft/import`, {body: {data}}) } -export const fetchCurrentValueOfConversationVariable: Fetcher = ({ url, params }) => { - return get(url, { params }) +export const fetchCurrentValueOfConversationVariable: Fetcher = ({url, params}) => { + return get(url, {params}) } diff --git a/web/types/workflow.ts b/web/types/workflow.ts index 74ba458c825ed6..e1c47f3cfa8e74 100644 --- a/web/types/workflow.ts +++ b/web/types/workflow.ts @@ -1,13 +1,7 @@ -import type { Viewport } from 'reactflow' -import type { - BlockEnum, - ConversationVariable, - Edge, - EnvironmentVariable, - Node, -} from '@/app/components/workflow/types' -import type { TransferMethod } from '@/types/app' -import type { ErrorHandleTypeEnum } from '@/app/components/workflow/nodes/_base/components/error-handle/types' +import type {Viewport} from 'reactflow' +import type {BlockEnum, ConversationVariable, Edge, EnvironmentVariable, Node,} from '@/app/components/workflow/types' +import type {TransferMethod} from '@/types/app' +import type {ErrorHandleTypeEnum} from '@/app/components/workflow/nodes/_base/components/error-handle/types' export type NodeTracing = { id: string @@ -85,9 +79,9 @@ export type FetchWorkflowDraftResponse = { export type VersionHistory = FetchWorkflowDraftResponse export type FetchWorkflowDraftPageResponse = { - items: VersionHistory[] - has_more: boolean - page: number + items: VersionHistory[] + has_more: boolean + page: number } export type NodeTracingListResponse = { diff --git a/web/utils/var.ts b/web/utils/var.ts index 236c9debac6b31..4f8d9ae7961e88 100644 --- a/web/utils/var.ts +++ b/web/utils/var.ts @@ -1,11 +1,16 @@ -import { MAX_VAR_KEY_LENGTH, VAR_ITEM_TEMPLATE, VAR_ITEM_TEMPLATE_IN_WORKFLOW, getMaxVarNameLength } from '@/config' -import { CONTEXT_PLACEHOLDER_TEXT, HISTORY_PLACEHOLDER_TEXT, PRE_PROMPT_PLACEHOLDER_TEXT, QUERY_PLACEHOLDER_TEXT } from '@/app/components/base/prompt-editor/constants' -import { InputVarType } from '@/app/components/workflow/types' +import {getMaxVarNameLength, MAX_VAR_KEY_LENGTH, VAR_ITEM_TEMPLATE, VAR_ITEM_TEMPLATE_IN_WORKFLOW} from '@/config' +import { + CONTEXT_PLACEHOLDER_TEXT, + HISTORY_PLACEHOLDER_TEXT, + PRE_PROMPT_PLACEHOLDER_TEXT, + QUERY_PLACEHOLDER_TEXT +} from '@/app/components/base/prompt-editor/constants' +import {InputVarType} from '@/app/components/workflow/types' const otherAllowedRegex = /^[a-zA-Z0-9_]+$/ export const getNewVar = (key: string, type: string) => { - const { max_length, ...rest } = VAR_ITEM_TEMPLATE + const {max_length, ...rest} = VAR_ITEM_TEMPLATE if (type !== 'string') { return { ...rest, @@ -23,7 +28,7 @@ export const getNewVar = (key: string, type: string) => { } export const getNewVarInWorkflow = (key: string, type = InputVarType.textInput) => { - const { max_length, ...rest } = VAR_ITEM_TEMPLATE_IN_WORKFLOW + const {max_length, ...rest} = VAR_ITEM_TEMPLATE_IN_WORKFLOW if (type !== InputVarType.textInput) { return { ...rest, @@ -74,7 +79,7 @@ export const checkKeys = (keys: string[], canBeEmpty?: boolean) => { errorMessageKey = res } }) - return { isValid, errorKey, errorMessageKey } + return {isValid, errorKey, errorMessageKey} } const varRegex = /\{\{([a-zA-Z_][a-zA-Z0-9_]*)\}\}/g