frontend/packages/arch/bot-env/README.md
A TypeScript-based environment variable management system for the bot-studio monorepo, providing compile-time type safety and runtime environment configuration.
# Install the package
rush add -p @coze-arch/bot-env
# Update dependencies
rush update
// Import compile-time environment variables
import { GLOBAL_ENVS } from '@coze-arch/bot-env';
// Access environment variables with full type safety
console.log(GLOBAL_ENVS.REGION); // 'cn' | 'sg' | 'va'
console.log(GLOBAL_ENVS.IS_PROD); // boolean
console.log(GLOBAL_ENVS.BUILD_TYPE); // 'local' | 'online' | 'offline' | 'test'
// Import runtime environment utilities
import { runtimeEnv } from '@coze-arch/bot-env/runtime';
// Access runtime environment information
console.log(runtimeEnv.isPPE); // boolean
// Import TypeScript declarations
/// <reference types="@coze-arch/bot-env/typings" />
// All environment variables are available as global constants
declare const REGION: 'cn' | 'sg' | 'va';
declare const IS_PROD: boolean;
declare const FEATURE_ENABLE_SSO: boolean;
// ... and many more
The main export containing all environment variables organized by category:
BUILD_TYPE: Build environment type ('local' | 'online' | 'offline' | 'test')CUSTOM_VERSION: Version type ('inhouse' | 'release')REGION: Deployment region ('cn' | 'sg' | 'va')NODE_ENV: Node environment ('production' | 'development' | 'test')IS_PROD: Production environment flagIS_BOE: BOE environment flagIS_OVERSEA: Overseas deployment flagIS_RELEASE_VERSION: Release version flagFEATURE_ENABLE_SSO: Single Sign-On featureFEATURE_ENABLE_APP_GUIDE: Application guide featureFEATURE_ENABLE_MSG_DEBUG: Message debugging featureFEATURE_AWEME_LOGIN: Aweme login integrationFEATURE_GOOGLE_LOGIN: Google login integrationCDN: Content delivery network URLUPLOAD_CDN: Upload CDN configurationCOZE_DOMAIN: Coze service domainAPP_ID: Application identifierAPP_KEY: Application keyimport { runtimeEnv } from '@coze-arch/bot-env/runtime';
// Runtime environment detection
runtimeEnv.isPPE // boolean - Production-like environment detection
import { build } from '@coze-arch/bot-env/build';
// Generate TypeScript declarations from environment configuration
build();
src/
āāā index.ts # Main exports
āāā runtime/ # Runtime environment utilities
āāā typings.d.ts # Auto-generated TypeScript declarations
āāā global.d.ts # Global type definitions
scripts/
āāā build.ts # Build script exports
āāā index.ts # Build script runner
This package acts as a wrapper around @coze-studio/bot-env-adapter, which provides the actual environment configuration logic. The adapter package includes:
The package automatically generates TypeScript declarations based on the environment configuration. The build process:
envs object in the source codetypings.d.ts file with the latest typesUse the extractEnvValue utility for environment-specific configurations:
const API_ENDPOINT = extractEnvValue<string>({
cn: {
boe: 'https://boe.api.example.com',
inhouse: 'https://inhouse.api.example.com',
release: 'https://api.example.com'
},
sg: {
inhouse: 'https://sg-inhouse.api.example.com',
release: 'https://sg.api.example.com'
},
va: {
release: 'https://va.api.example.com'
}
});
# Run tests
rush test -t @coze-arch/bot-env
# Run tests with coverage
rush test:cov -t @coze-arch/bot-env
# Build the package
rush build -t @coze-arch/bot-env
# Generate type definitions
rush build:types -t @coze-arch/bot-env
@coze-studio/bot-env-adapter: Core environment configuration adapter@coze-arch/eslint-config: ESLint configuration@coze-arch/ts-config: TypeScript configuration@coze-arch/vitest-config: Vitest testing configurationts-morph: TypeScript AST manipulation for type generationsucrase: Fast TypeScript/JSX compilervitest: Testing frameworkApache-2.0 License - see package.json for details.
For more information about environment configuration patterns and best practices, refer to the bot-studio monorepo documentation.