add-setting-env

lobehub/lobe-chat · updated Apr 8, 2026

$npx skills add https://github.com/lobehub/lobe-chat --skill add-setting-env
0 commentsdiscussion
summary

Add server-side environment variables to configure default values for user settings.

skill.md

Adding Environment Variable for User Settings

Add server-side environment variables to configure default values for user settings.

Priority: User Custom > Server Env Var > Hardcoded Default

Steps

1. Define Environment Variable

Create src/envs/<domain>.ts:

import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';

export const get<Domain>Config = () => {
  return createEnv({
    server: {
      YOUR_ENV_VAR: z.coerce.number().min(MIN).max(MAX).optional(),
    },
    runtimeEnv: {
      YOUR_ENV_VAR: process.env.YOUR_ENV_VAR,
    },
  });
};

export const <domain>Env = get<Domain>Config();

2. Update Type (if new domain)

Add to packages/types/src/serverConfig.ts:

import { User<Domain>Config } from './user/settings';

export interface GlobalServerConfig {
  <domain>?: PartialDeep<User<Domain>Config>;
}

Prefer reusing existing types from packages/types/src/user/settings.

3. Assemble Server Config (if new domain)

In src/server/globalConfig/index.ts:

import { <domain>Env } from '@/envs/<domain>';

export const getServerGlobalConfig = async () => {
  const config: GlobalServerConfig = {
    <domain>: cleanObject({
      <settingName>: <domain>Env.YOUR_ENV_VAR,
    }),
  };
  return config;
};

4. Merge to User Store (if new domain)

In src/store/user/slices/common/action.ts:

const serverSettings: PartialDeep<UserSettings> = {
  <domain>: serverConfig.<domain>,
};

5. Update .env.example

# <Description> (range/options, default: X)
# YOUR_ENV_VAR=<example>

6. Update Documentation

  • docs/self-hosting/environment-variables/basic.mdx (EN)
  • docs/self-hosting/environment-variables/basic.zh-CN.mdx (CN)

Example: AI_IMAGE_DEFAULT_IMAGE_NUM

// src/envs/image.ts
AI_IMAGE_DEFAULT_IMAGE_NUM: z.coerce.number().min(1).max(20).optional(),

// packages/types/src/serverConfig.ts
image?: PartialDeep<UserImageConfig>;

// src/server/globalConfig/index.ts
image: cleanObject({ defaultImageNum: imageEnv.AI_IMAGE_DEFAULT_IMAGE_NUM }),

// src/store/user/slices/common/action.ts
image: serverConfig.image,

// .env.example
# AI_IMAGE_DEFAULT_IMAGE_NUM=4

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.656 reviews
  • Mei Torres· Dec 28, 2024

    add-setting-env has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Chaitanya Patil· Dec 20, 2024

    Registry listing for add-setting-env matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Isabella Smith· Dec 20, 2024

    add-setting-env fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Carlos Brown· Dec 16, 2024

    add-setting-env is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Kofi Ramirez· Dec 16, 2024

    add-setting-env reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Valentina Nasser· Dec 8, 2024

    Solid pick for teams standardizing on skills: add-setting-env is focused, and the summary matches what you get after install.

  • Kiara Liu· Dec 4, 2024

    add-setting-env reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Kaira Li· Nov 23, 2024

    add-setting-env has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Charlotte Jain· Nov 19, 2024

    add-setting-env reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Piyush G· Nov 11, 2024

    Keeps context tight: add-setting-env is the kind of skill you can hand to a new teammate without a long onboarding doc.

showing 1-10 of 56

1 / 6