@constructive-io/llm-env 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Dan Lynch <pyramation@gmail.com>
4
+ Copyright (c) 2025 Constructive <developers@constructive.io>
5
+ Copyright (c) 2020-present, Interweb, Inc.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # @constructive-io/llm-env
2
+
3
+ <p align="center" width="100%">
4
+ <img height="250" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
5
+ </p>
6
+
7
+ Single source of truth for all LLM-related environment variables and defaults.
8
+ Follows the same conventions as `@pgpmjs/env`.
9
+
10
+ ## Usage
11
+
12
+ ```typescript
13
+ import { getEnvVars, getEnvOptions, llmDefaults } from '@constructive-io/llm-env';
14
+
15
+ // Raw env parsing — only keys that are set, no defaults
16
+ const envVars = getEnvVars(process.env);
17
+ // → { embedding: { model: 'text-embedding-3-small' } } (only set keys)
18
+
19
+ // Merged: defaults → env → overrides
20
+ const opts = getEnvOptions();
21
+ // opts.embedding.provider → EMBEDDER_PROVIDER || 'ollama'
22
+ // opts.embedding.model → EMBEDDER_MODEL || 'nomic-embed-text'
23
+ // opts.embedding.baseUrl → EMBEDDER_BASE_URL || 'http://localhost:11434'
24
+ // opts.chat.provider → CHAT_PROVIDER || 'ollama'
25
+ // opts.chat.model → CHAT_MODEL || 'llama3'
26
+ // opts.chat.baseUrl → CHAT_BASE_URL || 'http://localhost:11434'
27
+
28
+ // With runtime overrides
29
+ const custom = getEnvOptions({ embedding: { model: 'mxbai-embed-large' } });
30
+ ```
31
+
32
+ ## Environment Variables
33
+
34
+ | Variable | Default | Description |
35
+ |----------|---------|-------------|
36
+ | `EMBEDDER_PROVIDER` | `ollama` | Embedding provider name |
37
+ | `EMBEDDER_MODEL` | `nomic-embed-text` | Embedding model identifier |
38
+ | `EMBEDDER_BASE_URL` | `http://localhost:11434` | Embedding provider URL |
39
+ | `CHAT_PROVIDER` | `ollama` | Chat provider name |
40
+ | `CHAT_MODEL` | `llama3` | Chat model identifier |
41
+ | `CHAT_BASE_URL` | `http://localhost:11434` | Chat provider URL |
42
+
43
+ ---
44
+
45
+ ## Education and Tutorials
46
+
47
+ 1. 🚀 [Quickstart: Getting Up and Running](https://constructive.io/learn/quickstart)
48
+ Get started with modular databases in minutes. Install prerequisites and deploy your first module.
49
+
50
+ 2. 📦 [Modular PostgreSQL Development with Database Packages](https://constructive.io/learn/modular-postgres)
51
+ Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.
52
+
53
+ 3. ✏️ [Authoring Database Changes](https://constructive.io/learn/authoring-database-changes)
54
+ Master the workflow for adding, organizing, and managing database changes with pgpm.
55
+
56
+ 4. 🧪 [End-to-End PostgreSQL Testing with TypeScript](https://constructive.io/learn/e2e-postgres-testing)
57
+ Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.
58
+
59
+ 5. ⚡ [Supabase Testing](https://constructive.io/learn/supabase)
60
+ Use TypeScript-first tools to test Supabase projects with realistic RLS, policies, and auth contexts.
61
+
62
+ 6. 💧 [Drizzle ORM Testing](https://constructive.io/learn/drizzle-testing)
63
+ Run full-stack tests with Drizzle ORM, including database setup, teardown, and RLS enforcement.
64
+
65
+ 7. 🔧 [Troubleshooting](https://constructive.io/learn/troubleshooting)
66
+ Common issues and solutions for pgpm, PostgreSQL, and testing.
67
+
68
+ ## Related Constructive Tooling
69
+
70
+ ### 📦 Package Management
71
+
72
+ * [pgpm](https://github.com/constructive-io/constructive/tree/main/pgpm/pgpm): **🖥️ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
73
+
74
+ ### 🧪 Testing
75
+
76
+ * [pgsql-test](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
77
+ * [pgsql-seed](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-seed): **🌱 PostgreSQL seeding utilities** for CSV, JSON, SQL data loading, and pgpm deployment.
78
+ * [supabase-test](https://github.com/constructive-io/constructive/tree/main/postgres/supabase-test): **🧪 Supabase-native test harness** preconfigured for the local Supabase stack—per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
79
+ * [graphile-test](https://github.com/constructive-io/constructive/tree/main/graphile/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
80
+ * [pg-query-context](https://github.com/constructive-io/constructive/tree/main/postgres/pg-query-context): **🔒 Session context injection** to add session-local context (e.g., `SET LOCAL`) into queries—ideal for setting `role`, `jwt.claims`, and other session settings.
81
+
82
+ ### 🧠 Parsing & AST
83
+
84
+ * [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
85
+ * [libpg-query-node](https://www.npmjs.com/package/libpg-query): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
86
+ * [pg-proto-parser](https://www.npmjs.com/package/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
87
+ * [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
88
+ * [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
89
+ * [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
90
+
91
+ ### 📚 Documentation & Skills
92
+
93
+ * [constructive-skills](https://github.com/constructive-io/constructive-skills): **📖 Platform documentation and AI agent skills** — feature catalog, blueprint reference, SDK guides (i18n, billing, limits, events, uploads, security, entities, search, AI), and deployment guides.
94
+
95
+ Install skills for AI coding agents:
96
+
97
+ ```bash
98
+ # All platform skills (security, blueprints, codegen, billing, etc.)
99
+ npx skills add constructive-io/constructive-skills
100
+
101
+ # Individual repo skills (pgpm, testing, CLI, search, etc.)
102
+ npx skills add https://github.com/constructive-io/constructive --skill pgpm
103
+ npx skills add https://github.com/constructive-io/constructive --skill constructive-testing
104
+ ```
105
+
106
+ ## Credits
107
+
108
+ **🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
109
+
110
+ ## Disclaimer
111
+
112
+ AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
113
+
114
+ No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
package/esm/index.js ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * @constructive-io/llm-env — LLM Environment Configuration
3
+ *
4
+ * Single source of truth for all LLM-related environment variables and defaults.
5
+ * Both graphile-llm and agentic-server import from here — no direct process.env
6
+ * reads elsewhere.
7
+ *
8
+ * Follows the same conventions as @pgpmjs/env:
9
+ * - getEnvVars(env) → raw env parser, no defaults, conditional spread
10
+ * - llmDefaults → defaults constant
11
+ * - getEnvOptions(overrides, env) → merged: defaults → env → overrides
12
+ *
13
+ * Environment variables:
14
+ * EMBEDDER_PROVIDER - Embedding provider name (default: 'ollama')
15
+ * EMBEDDER_MODEL - Embedding model (default: 'nomic-embed-text')
16
+ * EMBEDDER_BASE_URL - Embedding provider URL (default: 'http://localhost:11434')
17
+ * CHAT_PROVIDER - Chat provider name (default: 'ollama')
18
+ * CHAT_MODEL - Chat model (default: 'llama3')
19
+ * CHAT_BASE_URL - Chat provider URL (default: 'http://localhost:11434')
20
+ */
21
+ // ─── Defaults ───────────────────────────────────────────────────────────────
22
+ export const llmDefaults = {
23
+ embedding: {
24
+ provider: 'ollama',
25
+ model: 'nomic-embed-text',
26
+ baseUrl: 'http://localhost:11434'
27
+ },
28
+ chat: {
29
+ provider: 'ollama',
30
+ model: 'llama3',
31
+ baseUrl: 'http://localhost:11434'
32
+ }
33
+ };
34
+ // ─── Env Parsing ────────────────────────────────────────────────────────────
35
+ /**
36
+ * Parse LLM-related environment variables.
37
+ *
38
+ * Returns only keys that are actually set — no defaults mixed in.
39
+ * Follows the @pgpmjs/env `getEnvVars(env)` pattern.
40
+ *
41
+ * @param env - Environment object to read from (defaults to process.env)
42
+ */
43
+ export const getEnvVars = (env = process.env) => {
44
+ const { EMBEDDER_PROVIDER, EMBEDDER_MODEL, EMBEDDER_BASE_URL, CHAT_PROVIDER, CHAT_MODEL, CHAT_BASE_URL, } = env;
45
+ return {
46
+ ...((EMBEDDER_PROVIDER || EMBEDDER_MODEL || EMBEDDER_BASE_URL) && {
47
+ embedding: {
48
+ ...(EMBEDDER_PROVIDER && { provider: EMBEDDER_PROVIDER }),
49
+ ...(EMBEDDER_MODEL && { model: EMBEDDER_MODEL }),
50
+ ...(EMBEDDER_BASE_URL && { baseUrl: EMBEDDER_BASE_URL }),
51
+ },
52
+ }),
53
+ ...((CHAT_PROVIDER || CHAT_MODEL || CHAT_BASE_URL) && {
54
+ chat: {
55
+ ...(CHAT_PROVIDER && { provider: CHAT_PROVIDER }),
56
+ ...(CHAT_MODEL && { model: CHAT_MODEL }),
57
+ ...(CHAT_BASE_URL && { baseUrl: CHAT_BASE_URL }),
58
+ },
59
+ }),
60
+ };
61
+ };
62
+ // ─── Merged Resolution ──────────────────────────────────────────────────────
63
+ /**
64
+ * Get fully resolved LLM configuration by merging:
65
+ * 1. llmDefaults
66
+ * 2. Environment variables
67
+ * 3. Runtime overrides
68
+ *
69
+ * @param overrides - Runtime overrides to apply last
70
+ * @param env - Environment object to read from (defaults to process.env)
71
+ */
72
+ export const getEnvOptions = (overrides = {}, env = process.env) => {
73
+ const envOptions = getEnvVars(env);
74
+ return {
75
+ embedding: {
76
+ ...llmDefaults.embedding,
77
+ ...envOptions.embedding,
78
+ ...overrides.embedding,
79
+ },
80
+ chat: {
81
+ ...llmDefaults.chat,
82
+ ...envOptions.chat,
83
+ ...overrides.chat,
84
+ },
85
+ };
86
+ };
87
+ /**
88
+ * @deprecated Use `getEnvOptions()` instead. Kept for backward compatibility.
89
+ */
90
+ export const getLlmEnvOptions = (env = process.env) => getEnvOptions({}, env);
package/index.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @constructive-io/llm-env — LLM Environment Configuration
3
+ *
4
+ * Single source of truth for all LLM-related environment variables and defaults.
5
+ * Both graphile-llm and agentic-server import from here — no direct process.env
6
+ * reads elsewhere.
7
+ *
8
+ * Follows the same conventions as @pgpmjs/env:
9
+ * - getEnvVars(env) → raw env parser, no defaults, conditional spread
10
+ * - llmDefaults → defaults constant
11
+ * - getEnvOptions(overrides, env) → merged: defaults → env → overrides
12
+ *
13
+ * Environment variables:
14
+ * EMBEDDER_PROVIDER - Embedding provider name (default: 'ollama')
15
+ * EMBEDDER_MODEL - Embedding model (default: 'nomic-embed-text')
16
+ * EMBEDDER_BASE_URL - Embedding provider URL (default: 'http://localhost:11434')
17
+ * CHAT_PROVIDER - Chat provider name (default: 'ollama')
18
+ * CHAT_MODEL - Chat model (default: 'llama3')
19
+ * CHAT_BASE_URL - Chat provider URL (default: 'http://localhost:11434')
20
+ */
21
+ export interface LlmProviderConfig {
22
+ provider?: string;
23
+ model?: string;
24
+ baseUrl?: string;
25
+ }
26
+ export interface LlmEnvOptions {
27
+ embedding?: LlmProviderConfig;
28
+ chat?: LlmProviderConfig;
29
+ }
30
+ /** Fully resolved LLM config — every field guaranteed present after merge. */
31
+ export interface ResolvedLlmEnvOptions {
32
+ embedding: Required<LlmProviderConfig>;
33
+ chat: Required<LlmProviderConfig>;
34
+ }
35
+ export declare const llmDefaults: ResolvedLlmEnvOptions;
36
+ /**
37
+ * Parse LLM-related environment variables.
38
+ *
39
+ * Returns only keys that are actually set — no defaults mixed in.
40
+ * Follows the @pgpmjs/env `getEnvVars(env)` pattern.
41
+ *
42
+ * @param env - Environment object to read from (defaults to process.env)
43
+ */
44
+ export declare const getEnvVars: (env?: NodeJS.ProcessEnv) => LlmEnvOptions;
45
+ /**
46
+ * Get fully resolved LLM configuration by merging:
47
+ * 1. llmDefaults
48
+ * 2. Environment variables
49
+ * 3. Runtime overrides
50
+ *
51
+ * @param overrides - Runtime overrides to apply last
52
+ * @param env - Environment object to read from (defaults to process.env)
53
+ */
54
+ export declare const getEnvOptions: (overrides?: LlmEnvOptions, env?: NodeJS.ProcessEnv) => ResolvedLlmEnvOptions;
55
+ /**
56
+ * @deprecated Use `getEnvOptions()` instead. Kept for backward compatibility.
57
+ */
58
+ export declare const getLlmEnvOptions: (env?: NodeJS.ProcessEnv) => ResolvedLlmEnvOptions;
package/index.js ADDED
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ /**
3
+ * @constructive-io/llm-env — LLM Environment Configuration
4
+ *
5
+ * Single source of truth for all LLM-related environment variables and defaults.
6
+ * Both graphile-llm and agentic-server import from here — no direct process.env
7
+ * reads elsewhere.
8
+ *
9
+ * Follows the same conventions as @pgpmjs/env:
10
+ * - getEnvVars(env) → raw env parser, no defaults, conditional spread
11
+ * - llmDefaults → defaults constant
12
+ * - getEnvOptions(overrides, env) → merged: defaults → env → overrides
13
+ *
14
+ * Environment variables:
15
+ * EMBEDDER_PROVIDER - Embedding provider name (default: 'ollama')
16
+ * EMBEDDER_MODEL - Embedding model (default: 'nomic-embed-text')
17
+ * EMBEDDER_BASE_URL - Embedding provider URL (default: 'http://localhost:11434')
18
+ * CHAT_PROVIDER - Chat provider name (default: 'ollama')
19
+ * CHAT_MODEL - Chat model (default: 'llama3')
20
+ * CHAT_BASE_URL - Chat provider URL (default: 'http://localhost:11434')
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.getLlmEnvOptions = exports.getEnvOptions = exports.getEnvVars = exports.llmDefaults = void 0;
24
+ // ─── Defaults ───────────────────────────────────────────────────────────────
25
+ exports.llmDefaults = {
26
+ embedding: {
27
+ provider: 'ollama',
28
+ model: 'nomic-embed-text',
29
+ baseUrl: 'http://localhost:11434'
30
+ },
31
+ chat: {
32
+ provider: 'ollama',
33
+ model: 'llama3',
34
+ baseUrl: 'http://localhost:11434'
35
+ }
36
+ };
37
+ // ─── Env Parsing ────────────────────────────────────────────────────────────
38
+ /**
39
+ * Parse LLM-related environment variables.
40
+ *
41
+ * Returns only keys that are actually set — no defaults mixed in.
42
+ * Follows the @pgpmjs/env `getEnvVars(env)` pattern.
43
+ *
44
+ * @param env - Environment object to read from (defaults to process.env)
45
+ */
46
+ const getEnvVars = (env = process.env) => {
47
+ const { EMBEDDER_PROVIDER, EMBEDDER_MODEL, EMBEDDER_BASE_URL, CHAT_PROVIDER, CHAT_MODEL, CHAT_BASE_URL, } = env;
48
+ return {
49
+ ...((EMBEDDER_PROVIDER || EMBEDDER_MODEL || EMBEDDER_BASE_URL) && {
50
+ embedding: {
51
+ ...(EMBEDDER_PROVIDER && { provider: EMBEDDER_PROVIDER }),
52
+ ...(EMBEDDER_MODEL && { model: EMBEDDER_MODEL }),
53
+ ...(EMBEDDER_BASE_URL && { baseUrl: EMBEDDER_BASE_URL }),
54
+ },
55
+ }),
56
+ ...((CHAT_PROVIDER || CHAT_MODEL || CHAT_BASE_URL) && {
57
+ chat: {
58
+ ...(CHAT_PROVIDER && { provider: CHAT_PROVIDER }),
59
+ ...(CHAT_MODEL && { model: CHAT_MODEL }),
60
+ ...(CHAT_BASE_URL && { baseUrl: CHAT_BASE_URL }),
61
+ },
62
+ }),
63
+ };
64
+ };
65
+ exports.getEnvVars = getEnvVars;
66
+ // ─── Merged Resolution ──────────────────────────────────────────────────────
67
+ /**
68
+ * Get fully resolved LLM configuration by merging:
69
+ * 1. llmDefaults
70
+ * 2. Environment variables
71
+ * 3. Runtime overrides
72
+ *
73
+ * @param overrides - Runtime overrides to apply last
74
+ * @param env - Environment object to read from (defaults to process.env)
75
+ */
76
+ const getEnvOptions = (overrides = {}, env = process.env) => {
77
+ const envOptions = (0, exports.getEnvVars)(env);
78
+ return {
79
+ embedding: {
80
+ ...exports.llmDefaults.embedding,
81
+ ...envOptions.embedding,
82
+ ...overrides.embedding,
83
+ },
84
+ chat: {
85
+ ...exports.llmDefaults.chat,
86
+ ...envOptions.chat,
87
+ ...overrides.chat,
88
+ },
89
+ };
90
+ };
91
+ exports.getEnvOptions = getEnvOptions;
92
+ /**
93
+ * @deprecated Use `getEnvOptions()` instead. Kept for backward compatibility.
94
+ */
95
+ const getLlmEnvOptions = (env = process.env) => (0, exports.getEnvOptions)({}, env);
96
+ exports.getLlmEnvOptions = getLlmEnvOptions;
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@constructive-io/llm-env",
3
+ "version": "0.1.1",
4
+ "author": "Constructive <developers@constructive.io>",
5
+ "description": "LLM environment configuration — single source of truth for all LLM-related env vars and defaults",
6
+ "main": "index.js",
7
+ "module": "esm/index.js",
8
+ "types": "index.d.ts",
9
+ "homepage": "https://github.com/constructive-io/constructive",
10
+ "license": "MIT",
11
+ "publishConfig": {
12
+ "access": "public",
13
+ "directory": "dist"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/constructive-io/constructive"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/constructive-io/constructive/issues"
21
+ },
22
+ "scripts": {
23
+ "clean": "makage clean",
24
+ "prepack": "npm run build",
25
+ "build": "makage build",
26
+ "build:dev": "makage build --dev",
27
+ "lint": "eslint . --fix",
28
+ "test": "jest",
29
+ "test:watch": "jest --watch"
30
+ },
31
+ "devDependencies": {
32
+ "makage": "^0.3.0"
33
+ },
34
+ "keywords": [
35
+ "llm",
36
+ "env",
37
+ "environment",
38
+ "config",
39
+ "constructive",
40
+ "ollama",
41
+ "openai",
42
+ "embedding"
43
+ ],
44
+ "gitHead": "16c2ae1c30850db1d71c021346c9d34361361d8e"
45
+ }