Skip to content

feat: improve workflow variable identifiers#6586

Open
yoqu wants to merge 3 commits intolabring:mainfrom
yoqu:main
Open

feat: improve workflow variable identifiers#6586
yoqu wants to merge 3 commits intolabring:mainfrom
yoqu:main

Conversation

@yoqu
Copy link
Copy Markdown

@yoqu yoqu commented Mar 19, 2026

Summary

This PR adds an optional technical identifier (key) for workflow global variables, while preserving the previous runtime behavior for users who do not need custom identifiers.

Before this change, global variables only exposed a display name (label) in the UI, while the real runtime identifier was hidden and generated internally. That made workflow debugging, API integration, and variable inspection harder because users could not define a readable key such as customer_name.

With this PR:

  • users can manually provide a custom variable identifier when creating a workflow global variable
  • the previous default behavior is preserved: if the identifier is left empty, the variable still gets a random key on save
  • existing variable identifiers remain read-only during edit mode
  • both frontend and backend now validate identifiers for format, duplication, and reserved system keys

What changed

key.mp4
  • Optional custom variable identifiers in the editor
    The workflow global variable settings modal now shows a Variable Identifier field when creating a variable.

  • Default behavior stays backward-compatible
    If the user does not manually set a variable identifier, the saved variable still uses the old random key generation flow. The identifier no longer auto-syncs from the variable name.

  • Shared identifier validation rules
    Added reusable identifier helpers to validate:

    • required / optional handling
    • allowed format
    • duplicate keys
    • conflicts with reserved workflow system keys
  • Server-side validation before persistence
    App update and publish flows now validate chatConfig.variables so invalid, duplicate, or reserved identifiers are rejected before being saved.

  • Better visibility in the variable list
    The variable table now shows each variable's identifier and provides a copy action, which makes debugging and integration easier.

  • Localization and tests
    Added i18n strings and regression coverage for the identifier helpers, editor behavior, and server-side validation.

Files changed

  • packages/global/core/app/variableIdentifier.ts - shared identifier validation utilities
  • packages/service/core/app/controller.ts - validate variable identifiers before persistence
  • projects/app/src/components/core/app/VariableEdit.tsx - show/copy variable identifiers in the variable list
  • projects/app/src/components/core/app/VariableEditModal/index.tsx - manual identifier editing flow
  • projects/app/src/components/core/app/utils/formValidation.ts - frontend validation hooks for labels and identifiers
  • projects/app/src/components/core/app/utils/variableEditor.ts - identifier edit-mode behavior helper
  • projects/app/src/pageComponents/app/detail/WorkflowComponents/Flow/nodes/NodePluginIO/InputTypeConfig.tsx - render identifier input for workflow variables
  • projects/app/src/pages/api/core/app/update.ts - validate identifiers on app update
  • projects/app/src/pages/api/core/app/version/publish.ts - validate identifiers on publish
  • packages/web/i18n/en/app.json - English copy
  • packages/web/i18n/zh-CN/app.json - Simplified Chinese copy
  • packages/web/i18n/zh-Hant/app.json - Traditional Chinese copy
  • projects/app/test/web/core/app/variableEditor.test.ts - frontend helper tests
  • test/cases/global/core/app/variableIdentifier.test.ts - identifier utility tests
  • test/cases/service/core/app/controller.test.ts - server-side validation tests

How to test

  1. Create a new workflow global variable and leave Variable Identifier empty.
    The variable should still save successfully and use the old random-key behavior.

  2. Create a new workflow global variable and manually set Variable Identifier to something like customer_name.
    Save the variable and confirm that:

    • the custom identifier is stored
    • it appears in the variable list
    • it can be copied from the table
  3. Try invalid identifiers, for example:

    • duplicate keys
    • reserved system keys such as userId
    • invalid formats such as customer-name
      The editor should block the save with validation feedback.
  4. Edit an existing variable.
    The identifier should be visible but read-only.

  5. Trigger app update / publish with invalid variable identifiers.
    The server should reject invalid, duplicate, or reserved keys before persistence.

Notes

  • This PR does not change the default identifier generation strategy for users who do not manually customize identifiers.
  • This PR does not introduce migration for historical variable keys or change existing runtime reference structure.

@cla-assistant
Copy link
Copy Markdown

cla-assistant bot commented Mar 19, 2026

CLA assistant check
All committers have signed the CLA.

@c121914yu
Copy link
Copy Markdown
Collaborator

目前没有该需求,暂不计划合入。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants