Skip to content

chore(config): adding zod schemas to manage envs - #45

Open
ArtuArtaza wants to merge 1 commit into
CopilotKit:mainfrom
ArtuArtaza:chore/config-zod-env-schemas
Open

ArtuArtaza wants to merge 1 commit into
CopilotKit:mainfrom
ArtuArtaza:chore/config-zod-env-schemas

Conversation

@ArtuArtaza

Copy link
Copy Markdown

Summary

Centralizes environment-variable parsing for the server and browser entrypoints using per-feature zod schemas under src/config/env/. Each feature module (core, parallel, browser, voice, slack, computer) owns its own slice, and the aggregator composes a typed ServerEnv. The downstream PlatformConfig runtime shape is preserved and now derived from the parsed env via platformConfigFromEnv(), with runtimeUrl computed once in the entrypoint.

Why

Previously, both entrypoints read process.env inline, scattering default values, string transforms (SLACK_USER_IDS), enum coercion (WEB_SEARCH_PROVIDER), URL coercion, and boot-time guards (BROWSER_SECRET length, OWNER_TOKEN for external binding) across multiple files. Per-feature zod schemas give:

  • Single source of truth for each env var and its validation rules.
  • Type-safe parsed values via z.infer, no string | undefined handling at every call site.
  • Better failure messages (one combined Invalid <feature> environment: ... error per process).
  • Per-feature cohesion that mirrors how the rest of the code is organized (parallel, slack, voice, computer all live in their own modules).

Changes

  • New: src/config/env/{core,parallel,browser,voice,slack,computer}.ts — zod schemas + inferred Env types per feature.
  • New: src/config/env/index.ts — aggregator (parseServerEnv, parseBrowserEnv) and shared ServerEnv type.
  • New: src/config/env.ts — re-export barrel so call sites keep using ../config/env.js.
  • Refactor: src/server/index.ts — no process.env reads; builds PlatformConfig via platformConfigFromEnv().
  • Refactor: src/browser/index.ts — uses parseBrowserEnv(); BROWSER_SECRET length enforced by the schema.
  • Refactor: src/server/platform-config.ts — PlatformConfig interface kept identical; adds platformConfigFromEnv() projection; setupStatus() unchanged.
  • Refactor: src/server/parallel.ts — re-exports WebSearchProvider type from config; webSearchProvider() helper removed (deprecated-leftover cutover complete; test now exercises parallelEnvSchema directly).
  • New: tests/env.test.ts — 14 cases covering defaults, host classification, external-binding OWNER_TOKEN guard, BROWSER_SECRET length, slack list parsing, computer namespace, parallel enum, and the HOST post-parse guard.

Behavior preserved

  • All documented defaults (HOST=127.0.0.1, PORT=4310, DATABASE_PATH=data/opendots.sqlite, OWNER_ID=opendots-owner, OPENAI_BASE_URL=https://api.openai.com/v1, VOICE_NAME=marin, COMPUTER_NAMESPACE=opendots, BROWSER_HOST=127.0.0.1, BROWSER_PORT=4311).
  • Boot-time errors when:
    • BROWSER_SECRET is missing or shorter than 24 chars.
    • HOST is not local and OWNER_TOKEN is missing or shorter than 24 chars.
    • WEB_SEARCH_PROVIDER is anything other than parallel, browser, or disabled.
    • SLACK_USER_IDS is split/trimmed the same way (a, b ,,c → ['a','b','c']).
  • runtimeUrl derived exactly as before in the entrypoint.

Verification

  • npm run typecheck: clean.
  • npm run lint: clean.
  • npx vitest run: 36 files / 178 tests passing (including the new env schema tests).

Replace inline process.env reads in the server and browser entrypoints with
typed, per-feature zod schemas under src/config/env/. Each feature module
(core, parallel, browser, voice, slack, computer) owns its slice and the
aggregator composes a ServerEnv. PlatformConfig keeps its runtime shape
and is now derived from the parsed env via platformConfigFromEnv(), with
runtimeUrl computed once in the entrypoint.

- Defaults preserved (HOST/PORT/DATABASE_PATH/OWNER_ID/OPENAI_BASE_URL/VOICE_NAME)
- Same boot-time guards: BROWSER_SECRET min 24 chars; OWNER_TOKEN required
  for external bindings; WEB_SEARCH_PROVIDER enum (parallel|browser|disabled)
- Slack user list parsing, port coercion, URL validation all moved into schemas
- Removed the webSearchProvider() helper (deprecated-leftover cutover complete);
  test exercises parallelEnvSchema directly
- Added tests/env.test.ts (14 cases) covering defaults, classification, and
  validation failures
@ArtuArtaza ArtuArtaza changed the title chore(config): adding zod schemas to manage envs and explain the feature or chore chore(config): adding zod schemas to manage envs Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant