mirror of
https://github.com/langgenius/dify.git
synced 2026-03-29 09:59:59 +08:00
Made-with: Cursor # Conflicts: # api/core/agent/cot_chat_agent_runner.py # api/core/agent/fc_agent_runner.py # api/core/memory/token_buffer_memory.py # api/core/variables/segments.py # api/core/workflow/file/file_manager.py # api/core/workflow/nodes/agent/agent_node.py # api/core/workflow/nodes/llm/llm_utils.py # api/core/workflow/nodes/parameter_extractor/parameter_extractor_node.py # api/core/workflow/workflow_entry.py # api/factories/variable_factory.py # api/pyproject.toml # api/services/variable_truncator.py # api/uv.lock # web/app/components/app/app-publisher/index.tsx # web/app/components/app/overview/settings/index.tsx # web/app/components/apps/app-card.tsx # web/app/components/apps/index.tsx # web/app/components/apps/list.tsx # web/app/components/base/chat/chat-with-history/header-in-mobile.tsx # web/app/components/base/features/new-feature-panel/conversation-opener/modal.tsx # web/app/components/base/features/new-feature-panel/file-upload/setting-content.tsx # web/app/components/base/features/new-feature-panel/moderation/moderation-setting-modal.tsx # web/app/components/base/features/new-feature-panel/text-to-speech/param-config-content.tsx # web/app/components/base/message-log-modal/index.tsx # web/app/components/base/switch/index.tsx # web/app/components/base/tab-slider-plain/index.tsx # web/app/components/explore/try-app/app-info/index.tsx # web/app/components/plugins/plugin-detail-panel/tool-selector/components/reasoning-config-form.tsx # web/app/components/workflow/nodes/llm/components/json-schema-config-modal/visual-editor/edit-card/required-switch.tsx # web/app/components/workflow/nodes/llm/panel.tsx # web/contract/router.ts # web/eslint-suppressions.json # web/i18n/fa-IR/workflow.json
199 lines
6.0 KiB
TypeScript
199 lines
6.0 KiB
TypeScript
import type { FC } from 'react'
|
|
import type { HttpNodeType } from './types'
|
|
import type { NodePanelProps } from '@/app/components/workflow/types'
|
|
import { memo } from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import { FileArrow01 } from '@/app/components/base/icons/src/vender/line/files'
|
|
import { Settings01 } from '@/app/components/base/icons/src/vender/line/general'
|
|
import Switch from '@/app/components/base/switch'
|
|
import Field from '@/app/components/workflow/nodes/_base/components/field'
|
|
import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
|
|
import Split from '@/app/components/workflow/nodes/_base/components/split'
|
|
import { cn } from '@/utils/classnames'
|
|
import ApiInput from './components/api-input'
|
|
import AuthorizationModal from './components/authorization'
|
|
import CurlPanel from './components/curl-panel'
|
|
import EditBody from './components/edit-body'
|
|
import KeyValue from './components/key-value'
|
|
import Timeout from './components/timeout'
|
|
import useConfig from './use-config'
|
|
|
|
const i18nPrefix = 'nodes.http'
|
|
|
|
const Panel: FC<NodePanelProps<HttpNodeType>> = ({
|
|
id,
|
|
data,
|
|
}) => {
|
|
const { t } = useTranslation()
|
|
|
|
const {
|
|
readOnly,
|
|
isDataReady,
|
|
inputs,
|
|
handleMethodChange,
|
|
handleUrlChange,
|
|
headers,
|
|
setHeaders,
|
|
addHeader,
|
|
params,
|
|
setParams,
|
|
addParam,
|
|
setBody,
|
|
isShowAuthorization,
|
|
showAuthorization,
|
|
hideAuthorization,
|
|
setAuthorization,
|
|
setTimeout,
|
|
isShowCurlPanel,
|
|
showCurlPanel,
|
|
hideCurlPanel,
|
|
handleCurlImport,
|
|
handleSSLVerifyChange,
|
|
} = useConfig(id, data)
|
|
// To prevent prompt editor in body not update data.
|
|
if (!isDataReady)
|
|
return null
|
|
|
|
return (
|
|
<div className="pt-2">
|
|
<div className="space-y-4 px-4 pb-4">
|
|
<Field
|
|
title={t(`${i18nPrefix}.api`, { ns: 'workflow' })}
|
|
required
|
|
operations={(
|
|
<div className="flex">
|
|
<div
|
|
onClick={showAuthorization}
|
|
className={cn(!readOnly && 'cursor-pointer hover:bg-state-base-hover', 'flex h-6 items-center space-x-1 rounded-md px-2')}
|
|
>
|
|
{!readOnly && <Settings01 className="h-3 w-3 text-text-tertiary" />}
|
|
<div className="text-xs font-medium text-text-tertiary">
|
|
{t(`${i18nPrefix}.authorization.authorization`, { ns: 'workflow' })}
|
|
<span className="ml-1 text-text-secondary">{t(`${i18nPrefix}.authorization.${inputs.authorization.type}`, { ns: 'workflow' })}</span>
|
|
</div>
|
|
</div>
|
|
<div
|
|
onClick={showCurlPanel}
|
|
className={cn(!readOnly && 'cursor-pointer hover:bg-state-base-hover', 'flex h-6 items-center space-x-1 rounded-md px-2')}
|
|
>
|
|
{!readOnly && <FileArrow01 className="h-3 w-3 text-text-tertiary" />}
|
|
<div className="text-xs font-medium text-text-tertiary">
|
|
{t(`${i18nPrefix}.curl.title`, { ns: 'workflow' })}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
>
|
|
<ApiInput
|
|
nodeId={id}
|
|
readonly={readOnly}
|
|
method={inputs.method}
|
|
onMethodChange={handleMethodChange}
|
|
url={inputs.url}
|
|
onUrlChange={handleUrlChange}
|
|
/>
|
|
</Field>
|
|
<Field
|
|
title={t(`${i18nPrefix}.headers`, { ns: 'workflow' })}
|
|
>
|
|
<KeyValue
|
|
nodeId={id}
|
|
list={headers}
|
|
onChange={setHeaders}
|
|
onAdd={addHeader}
|
|
readonly={readOnly}
|
|
/>
|
|
</Field>
|
|
<Field
|
|
title={t(`${i18nPrefix}.params`, { ns: 'workflow' })}
|
|
>
|
|
<KeyValue
|
|
nodeId={id}
|
|
list={params}
|
|
onChange={setParams}
|
|
onAdd={addParam}
|
|
readonly={readOnly}
|
|
/>
|
|
</Field>
|
|
<Field
|
|
title={t(`${i18nPrefix}.body`, { ns: 'workflow' })}
|
|
required
|
|
>
|
|
<EditBody
|
|
nodeId={id}
|
|
readonly={readOnly}
|
|
payload={inputs.body}
|
|
onChange={setBody}
|
|
/>
|
|
</Field>
|
|
<Field
|
|
title={t(`${i18nPrefix}.verifySSL.title`, { ns: 'workflow' })}
|
|
tooltip={t(`${i18nPrefix}.verifySSL.warningTooltip`, { ns: 'workflow' })}
|
|
operations={(
|
|
<Switch
|
|
value={!!inputs.ssl_verify}
|
|
onChange={handleSSLVerifyChange}
|
|
size="md"
|
|
disabled={readOnly}
|
|
/>
|
|
)}
|
|
>
|
|
</Field>
|
|
</div>
|
|
<Split />
|
|
<Timeout
|
|
nodeId={id}
|
|
readonly={readOnly}
|
|
payload={inputs.timeout}
|
|
onChange={setTimeout}
|
|
/>
|
|
{(isShowAuthorization && !readOnly) && (
|
|
<AuthorizationModal
|
|
nodeId={id}
|
|
isShow
|
|
onHide={hideAuthorization}
|
|
payload={inputs.authorization}
|
|
onChange={setAuthorization}
|
|
/>
|
|
)}
|
|
<Split />
|
|
<div className="">
|
|
<OutputVars>
|
|
<>
|
|
<VarItem
|
|
name="body"
|
|
type="string"
|
|
description={t(`${i18nPrefix}.outputVars.body`, { ns: 'workflow' })}
|
|
/>
|
|
<VarItem
|
|
name="status_code"
|
|
type="number"
|
|
description={t(`${i18nPrefix}.outputVars.statusCode`, { ns: 'workflow' })}
|
|
/>
|
|
<VarItem
|
|
name="headers"
|
|
type="object"
|
|
description={t(`${i18nPrefix}.outputVars.headers`, { ns: 'workflow' })}
|
|
/>
|
|
<VarItem
|
|
name="files"
|
|
type="Array[File]"
|
|
description={t(`${i18nPrefix}.outputVars.files`, { ns: 'workflow' })}
|
|
/>
|
|
</>
|
|
</OutputVars>
|
|
</div>
|
|
{(isShowCurlPanel && !readOnly) && (
|
|
<CurlPanel
|
|
nodeId={id}
|
|
isShow
|
|
onHide={hideCurlPanel}
|
|
handleCurlImport={handleCurlImport}
|
|
/>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default memo(Panel)
|