Where Are the Running Mode Constants Defined in Dify Chat's Core Package?

The running mode constants in Dify Chat are defined as an immutable RunningModes object in packages/core/src/constants/index.ts and re-exported through the core package entry point at packages/core/src/index.ts for convenient access via @dify-chat/core.

The lexmin0412/dify-chat repository organizes its core shared constants in a dedicated constants module within the core package. Understanding the location and structure of these running mode constants is essential for correctly implementing single-app versus multi-app UI logic throughout the application.

Location of the Running Mode Constants

The single source of truth for running mode values resides in the core package's constants directory. In packages/core/src/constants/index.ts, the constants are declared as a frozen object using TypeScript's as const assertion:

export const RunningModes = {
  /** 单应用 */
  SingleApp: 'singleApp',
  /** 多应用 */
  MultiApp: 'multiApp',
} as const;

This location provides immutable string literals that represent the two operational modes supported by Dify Chat: single application mode and multi application mode.

Core Package Entry Point Re-exports

To streamline imports across the monorepo, these constants are aggregated in the core package's main entry point. The file packages/core/src/index.ts re-exports the RunningModes object, enabling developers to import it directly from the @dify-chat/core namespace:

import { RunningModes } from '@dify-chat/core';

This pattern ensures that all consuming packages—including UI components and custom hooks like those found in packages/core/src/hooks/*—reference identical constant values without needing to know the internal file structure of the core package.

Practical Usage Examples

Basic Conditional Rendering

Use the constants to branch UI logic based on the current deployment configuration:

import { RunningModes } from '@dify-chat/core';

function getModeLabel(mode: keyof typeof RunningModes) {
  return mode === RunningModes.SingleApp ? '单应用' : '多应用';
}

// Example: decide which UI to render
const currentMode = RunningModes.MultiApp;

if (currentMode === RunningModes.SingleApp) {
  // render single‑app UI
} else {
  // render multi‑app UI
}

Type-Safe Mode Handling

Leverage TypeScript's type inference to create strictly typed functions that only accept valid running modes:

type Mode = keyof typeof RunningModes; // "SingleApp" | "MultiApp"

function setRunningMode(mode: Mode) {
  // mode is guaranteed to be one of the defined keys
  console.log('Running mode set to:', RunningModes[mode]);
}

This approach prevents runtime errors by catching invalid mode strings at compile time.

Summary

  • packages/core/src/constants/index.ts defines the immutable RunningModes object containing SingleApp and MultiApp string literals.
  • packages/core/src/index.ts re-exports these constants for clean imports via @dify-chat/core.
  • The constants use TypeScript's as const assertion to ensure type safety and prevent mutation.
  • Consuming code in hooks and components should always reference these constants rather than hardcoding string values like 'singleApp' or 'multiApp'.

Frequently Asked Questions

What are the exact string values of the running mode constants?

The RunningModes object maps 'singleApp' to the SingleApp key and 'multiApp' to the MultiApp key. These lowercase string values are the actual runtime values used for mode comparisons and API configurations.

Can I import RunningModes from a specific file instead of the package root?

While you can import directly from packages/core/src/constants/index.ts, the recommended pattern is importing from @dify-chat/core. This insulates your code from internal refactoring and ensures you always consume the officially exported API surface.

How do I add a new running mode to the constants?

You must modify the RunningModes object definition in packages/core/src/constants/index.ts and add the new key-value pair using the same as const pattern. Because the object is frozen at compile time, any new mode must be added to the source code and re-exported through the package entry point.

Where are these constants typically consumed in the codebase?

According to the source analysis, these constants are primarily consumed within the core package's hook implementations—such as use-apps.ts in packages/core/src/hooks/—and throughout UI components that need to toggle between single-app and multi-app interfaces.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →