Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
warren830 committed Dec 26, 2024
1 parent 24186ae commit 2fac785
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 36 deletions.
41 changes: 24 additions & 17 deletions web/service/workflow.ts
Original file line number Diff line number Diff line change
@@ -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<FetchWorkflowDraftResponse>
return get(url, {}, {silent: true}) as Promise<FetchWorkflowDraftResponse>
}

export const syncWorkflowDraft = ({ url, params }: { url: string; params: Pick<FetchWorkflowDraftResponse, 'graph' | 'features' | 'environment_variables' | 'conversation_variables'> }) => {
return post<CommonResponse & { updated_at: number; hash: string }>(url, { body: params }, { silent: true })
export const syncWorkflowDraft = ({url, params}: {
url: string;
params: Pick<FetchWorkflowDraftResponse, 'graph' | 'features' | 'environment_variables' | 'conversation_variables'>
}) => {
return post<CommonResponse & { updated_at: number; hash: string }>(url, {body: params}, {silent: true})
}

export const fetchNodesDefaultConfigs: Fetcher<NodesDefaultConfigsResponse, string> = (url) => {
Expand All @@ -31,7 +35,7 @@ export const fetchChatRunHistory: Fetcher<ChatRunHistoryResponse, string> = (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) => {
Expand All @@ -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<FetchWorkflowDraftResponse>(`apps/${appId}/workflows/draft/import`, { body: { data } })
return post<FetchWorkflowDraftResponse>(`apps/${appId}/workflows/draft/import`, {body: {data}})
}

export const fetchCurrentValueOfConversationVariable: Fetcher<ConversationVariableResponse, { url: string; params: { conversation_id: string } }> = ({ url, params }) => {
return get<ConversationVariableResponse>(url, { params })
export const fetchCurrentValueOfConversationVariable: Fetcher<ConversationVariableResponse, {
url: string;
params: { conversation_id: string }
}> = ({url, params}) => {
return get<ConversationVariableResponse>(url, {params})
}
20 changes: 7 additions & 13 deletions web/types/workflow.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = {
Expand Down
17 changes: 11 additions & 6 deletions web/utils/var.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2fac785

Please sign in to comment.