Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(web): preserve numeric zero defaults in Studio previews (#45005)

MindOfqc9e55d5351f76
diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json
index a58720c35e9..721ae9483f3 100644
--- a/oxlint-suppressions.json
+++ b/oxlint-suppressions.json
@@ -618,9 +618,6 @@
}
},
"web/app/components/app/configuration/debug/index.tsx": {
- "better-tailwindcss/enforce-logical-properties": {
- "count": 4
- },
"eslint-react/set-state-in-effect": {
"count": 1
},
@@ -633,11 +630,6 @@
"count": 1
}
},
- "web/app/components/app/configuration/prompt-value-panel/index.tsx": {
- "better-tailwindcss/enforce-logical-properties": {
- "count": 2
- }
- },
"web/app/components/app/configuration/tools/external-data-tool-modal.tsx": {
"better-tailwindcss/enforce-logical-properties": {
"count": 2
diff --git a/web/app/components/app/configuration/debug/__tests__/index.spec.tsx b/web/app/components/app/configuration/debug/__tests__/index.spec.tsx
index 7bf1f2f0ebd..1e9c6e85c1b 100644
--- a/web/app/components/app/configuration/debug/__tests__/index.spec.tsx
+++ b/web/app/components/app/configuration/debug/__tests__/index.spec.tsx
@@ -323,6 +323,83 @@ it.each([
expect(api.stream).not.toHaveBeenCalled()
},
)
+it.each(['chat', 'completion'] as const)(
+ 'displays and sends a required numeric zero default in %s preview',
+ async (mode) => {
+ const { user } = setup({
+ context: {
+ mode,
+ modelConfig: createModelConfigFixture({
+ provider: 'openai',
+ model_id: 'gpt-4',
+ mode: ModelModeType.chat,
+ configs: {
+ prompt_template: 'Count {{count}}',
+ prompt_variables: [
+ { key: 'count', name: 'Count', type: 'number', required: true, default: 0 },
+ ],
+ },
+ }),
+ },
+ })
+
+ expect.soft(screen.getByRole('spinbutton', { name: 'Count' })).toHaveValue(0)
+ if (mode === 'completion') await run(user)
+ else await sendChat(user)
+
+ expect(api.stream).toHaveBeenCalledTimes(1)
+ expect(api.stream.mock.lastCall![1].body).toHaveProperty('inputs', { count: 0 })
+ },
+)
+
+it('blocks missing and cleared required numeric inputs', async () => {
+ const { user } = setup({
+ context: {
+ mode: 'completion',
+ modelConfig: createModelConfigFixture({
+ configs: {
+ prompt_template: 'Count {{count}}',
+ prompt_variables: [{ key: 'count', name: 'Count', type: 'number', required: true }],
+ },
+ }),
+ },
+ })
+ const input = screen.getByRole('spinbutton', { name: 'Count' })
+
+ await run(user)
+ expect(
+ await screen.findByText('appDebug.errorMessage.valueOfVarRequired:{"key":"Count"}'),
+ ).toBeVisible()
+ expect(api.stream).not.toHaveBeenCalled()
+
+ await user.type(input, '1')
+ await user.clear(input)
+ await run(user)
+ expect(api.stream).not.toHaveBeenCalled()
+})
+
+it('keeps a required numeric false value invalid', async () => {
+ const { user } = setup({
+ context: {
+ mode: 'completion',
+ inputs: { count: false },
+ modelConfig: createModelConfigFixture({
+ configs: {
+ prompt_template: 'Count {{count}}',
+ prompt_variables: [{ key: 'count', name: 'Count', type: 'number', required: true }],
+ },
+ }),
+ },
+ })
+
+ await run(user)
+
+ expect(
+ await screen.findByText('appDebug.errorMessage.valueOfVarRequired:{"key":"Count"}'),
+ ).toBeVisible()
+ expect(api.stream).not.toHaveBeenCalled()
+})
+
it('validates a required completion input and sends the corrected value', async () => {
const { user } = setup({ context: { mode: 'completion', modelConfig: variableModel() } })
await run(user)
diff --git a/web/app/components/app/configuration/debug/chat-user-input.tsx b/web/app/components/app/configuration/debug/chat-user-input.tsx
index c876c706cf7..a5fa0af45d8 100644
--- a/web/app/components/app/configuration/debug/chat-user-input.tsx
+++ b/web/app/components/app/configuration/debug/chat-user-input.tsx
@@ -150,7 +150,7 @@ const ChatUserInput = ({ inputs }: Props) => {
<Input
aria-labelledby={`${baseId}-${key}-label`}
type="number"
- value={inputs[key] ? `${inputs[key]}` : ''}
+ value={inputs[key] || inputs[key] === 0 ? `${inputs[key]}` : ''}
onValueChange={(value) => handleInputValueChange(key, value)}
placeholder={name}
maxLength={max_length}
diff --git a/web/app/components/app/configuration/debug/index.tsx b/web/app/components/app/configuration/debug/index.tsx
index 60c9eb57e0e..5f64876c6fe 100644
--- a/web/app/components/app/configuration/debug/index.tsx
+++ b/web/app/components/app/configuration/debug/index.tsx
@@ -176,10 +176,10 @@ const Debug: FC<IDebug> = ({
return res
},
) // compatible with old version
- requiredVars.forEach(({ key, name }) => {
+ requiredVars.forEach(({ key, name, type }) => {
if (hasEmptyInput) return
- if (!inputs[key]) hasEmptyInput = name
+ if (!inputs[key] && !(type === 'number' && inputs[key] === 0)) hasEmptyInput = name
})
if (hasEmptyInput) {
@@ -492,7 +492,7 @@ const Debug: FC<IDebug> = ({
)}
{varList.length > 0 && (
- <div className="relative mr-2 ml-1">
+ <div className="relative ms-1 me-2">
<Tooltip>
<TooltipTrigger
render={
@@ -514,7 +514,7 @@ const Debug: FC<IDebug> = ({
</TooltipContent>
</Tooltip>
{expanded && (
- <div className="absolute right-1.25 -bottom-3.5 z-10 h-3 w-3 rotate-45 border-t-[0.5px] border-l-[0.5px] border-components-panel-border-subtle bg-components-panel-on-panel-item-bg" />
+ <div className="absolute inset-e-1.25 -bottom-3.5 z-10 h-3 w-3 rotate-45 border-s-[0.5px] border-t-[0.5px] border-components-panel-border-subtle bg-components-panel-on-panel-item-bg rtl:-rotate-45" />
)}
</div>
)}
diff --git a/web/app/components/app/configuration/prompt-value-panel/index.tsx b/web/app/components/app/configuration/prompt-value-panel/index.tsx
index 8de91ac5bc8..460a7a25f6a 100644
--- a/web/app/components/app/configuration/prompt-value-panel/index.tsx
+++ b/web/app/components/app/configuration/prompt-value-panel/index.tsx
@@ -139,7 +139,7 @@ const PromptValuePanel: FC<IPromptValuePanelProps> = ({
<div className={cn('px-4 pt-3', userInputFieldCollapse ? 'pb-3' : 'pb-1')}>
<button
type="button"
- className="flex cursor-pointer items-center gap-0.5 border-none bg-transparent px-0 py-0.5 text-left focus-visible:ring-1 focus-visible:ring-components-input-border-active focus-visible:outline-hidden"
+ className="flex cursor-pointer items-center gap-0.5 border-none bg-transparent px-0 py-0.5 text-start focus-visible:ring-1 focus-visible:ring-components-input-border-active focus-visible:outline-hidden"
onClick={() => setUserInputFieldCollapse(!userInputFieldCollapse)}
>
<div className="system-md-semibold-uppercase text-text-secondary">
@@ -231,7 +231,7 @@ const PromptValuePanel: FC<IPromptValuePanelProps> = ({
<Input
aria-labelledby={`${baseId}-${key}-label`}
type="number"
- value={inputs[key] ? `${inputs[key]}` : ''}
+ value={inputs[key] || inputs[key] === 0 ? `${inputs[key]}` : ''}
onValueChange={(value) => handleInputValueChange(key, value)}
placeholder={name}
maxLength={max_length}
@@ -255,7 +255,7 @@ const PromptValuePanel: FC<IPromptValuePanelProps> = ({
))}
{visionConfig?.enabled && (
<div className="mt-3 justify-between xl:flex">
- <div className="mr-1 w-30 shrink-0 py-2 text-sm text-text-primary">
+ <div className="me-1 w-30 shrink-0 py-2 text-sm text-text-primary">
{t(($) => $['imageUploader.imageUpload'], { ns: 'common' })}
</div>
<div className="grow">