/** * Central configuration — the ONE place the SDK reads environment. * * Values come from node-config (a package's `config/` dir: `default.json` for * defaults + `custom-environment-variables.json` mapping env vars → keys), which * is the single declarative place every env var is documented. If a package * ships no config/ (or a key isn't mapped), we fall back to the raw env var and * then a built-in default — so the SDK works with or without node-config. * * Nothing else in the SDK touches `process.env`. Import { cfg } from here. */ import config from "config"; // read resolves a value in priority order: node-config → raw env var → default. // This module is the only place `process.env` is read. function read(key: string, envVar: string, fallback = ""): string { try { if (config.has(key)) { const v = config.get(key); if (v != null && v !== "") return String(v); } } catch { // node-config not configured for this process (no config/ dir) — fall through. } return process.env[envVar] ?? fallback; } export const cfg = { /** Platform API base URL. env: NP_API_URL */ apiUrl: () => read("api.url", "NP_API_URL", "https://api.nullplatform.com"), /** Platform API key. env: NP_API_KEY */ apiKey: () => read("api.key", "NP_API_KEY"), /** Executions/streaming API URL. env: NP_EXECUTIONS_API_URL */ executionsApiUrl: () => read("api.executionsUrl", "NP_EXECUTIONS_API_URL"), /** Agent transport mode marker. env: NP_AGENT_PLUGIN */ agentMode: () => read("agent.mode", "NP_AGENT_PLUGIN"), /** * When set, the gRPC server listens on this TCP address (e.g. ":50051") instead * of a unix socket + go-plugin handshake. Used when the worker runs as its own * pod/container and the orchestrating agent dials it over the network. * env: NP_GRPC_LISTEN */ grpcListen: () => read("agent.grpcListen", "NP_GRPC_LISTEN"), /** * Execution mode: "dev" | "test" | "" (production/agent). Set explicitly by * `np package dev` / `np package test`. When "dev" or "test" the SDK uses the * in-memory platform client and NEVER touches the real API — even if an API * key is present in the environment. env: NP_MODE */ mode: () => read("mode", "NP_MODE"), /** The action payload injected in subprocess-exec mode. env: NP_ACTION_CONTEXT */ actionContext: () => read("agent.actionContext", "NP_ACTION_CONTEXT"), /** Tracing API base URL; tracing is off when empty. env: NP_TRACING_URL */ tracingUrl: () => read("tracing.url", "NP_TRACING_URL"), /** Path to a plugin manifest override. env: NP_PLUGIN_MANIFEST */ pluginManifest: () => read("plugin.manifest", "NP_PLUGIN_MANIFEST"), } as const;