@cogitator-ai/config 0.3.3 → 0.3.5

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.
Files changed (2) hide show
  1. package/README.md +447 -21
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @cogitator-ai/config
2
2
 
3
- Configuration loading for Cogitator. Supports YAML files, environment variables, and programmatic overrides.
3
+ Configuration loading for Cogitator. Supports YAML files, environment variables, and programmatic overrides with full Zod validation.
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,68 +8,494 @@ Configuration loading for Cogitator. Supports YAML files, environment variables,
8
8
  pnpm add @cogitator-ai/config
9
9
  ```
10
10
 
11
- ## Usage
11
+ ## Quick Start
12
12
 
13
13
  ### YAML Configuration
14
14
 
15
- Create `cogitator.yml`:
15
+ Create `cogitator.yml` in your project root:
16
16
 
17
17
  ```yaml
18
- defaultModel: ollama/llama3.2:3b
18
+ llm:
19
+ defaultProvider: openai
20
+ defaultModel: gpt-4o
21
+ providers:
22
+ openai:
23
+ apiKey: ${OPENAI_API_KEY}
24
+ ollama:
25
+ baseUrl: http://localhost:11434
26
+
19
27
  memory:
20
28
  adapter: redis
21
29
  redis:
22
30
  url: redis://localhost:6379
31
+
23
32
  logging:
24
33
  level: info
25
- format: json
34
+ format: pretty
26
35
  ```
27
36
 
28
37
  ### Load Configuration
29
38
 
30
39
  ```typescript
31
- import { loadConfig } from '@cogitator-ai/config';
40
+ import { loadConfig, defineConfig } from '@cogitator-ai/config';
32
41
 
42
+ // Load from file with env vars and overrides
33
43
  const config = await loadConfig({
34
44
  configPath: './cogitator.yml',
35
45
  overrides: {
36
46
  logging: { level: 'debug' },
37
47
  },
38
48
  });
49
+
50
+ // Or define config programmatically with type safety
51
+ const config = defineConfig({
52
+ llm: {
53
+ defaultProvider: 'openai',
54
+ providers: {
55
+ openai: { apiKey: process.env.OPENAI_API_KEY! },
56
+ },
57
+ },
58
+ });
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Configuration Reference
64
+
65
+ ### LLM Configuration
66
+
67
+ ```yaml
68
+ llm:
69
+ defaultProvider: openai # ollama | openai | anthropic | google | azure | bedrock | vllm
70
+ defaultModel: gpt-4o
71
+ providers:
72
+ ollama:
73
+ baseUrl: http://localhost:11434
74
+ openai:
75
+ apiKey: sk-xxx
76
+ baseUrl: https://api.openai.com/v1 # optional, for proxies
77
+ anthropic:
78
+ apiKey: sk-ant-xxx
79
+ google:
80
+ apiKey: xxx
81
+ azure:
82
+ apiKey: xxx
83
+ endpoint: https://xxx.openai.azure.com
84
+ apiVersion: 2024-02-15-preview # optional
85
+ bedrock:
86
+ region: us-east-1
87
+ accessKeyId: xxx # optional, uses AWS credentials chain
88
+ secretAccessKey: xxx # optional
89
+ vllm:
90
+ baseUrl: http://localhost:8000
91
+ ```
92
+
93
+ ### Memory Configuration
94
+
95
+ ```yaml
96
+ memory:
97
+ adapter: postgres # memory | redis | postgres | sqlite | mongodb | qdrant
98
+
99
+ # In-memory (for development)
100
+ inMemory:
101
+ maxEntries: 1000
102
+
103
+ # Redis
104
+ redis:
105
+ url: redis://localhost:6379
106
+ # Or individual settings:
107
+ host: localhost
108
+ port: 6379
109
+ password: secret
110
+ keyPrefix: cogitator:
111
+ ttl: 3600 # seconds
112
+ # Cluster mode:
113
+ cluster:
114
+ nodes:
115
+ - host: redis-1
116
+ port: 6379
117
+ - host: redis-2
118
+ port: 6379
119
+ scaleReads: slave # master | slave | all
120
+
121
+ # PostgreSQL with pgvector
122
+ postgres:
123
+ connectionString: postgresql://user:pass@localhost:5432/cogitator
124
+ schema: public
125
+ poolSize: 10
126
+
127
+ # SQLite
128
+ sqlite:
129
+ path: ./data/cogitator.db
130
+ walMode: true
131
+
132
+ # MongoDB
133
+ mongodb:
134
+ uri: mongodb://localhost:27017
135
+ database: cogitator
136
+ collectionPrefix: cog_
137
+
138
+ # Qdrant (vector database)
139
+ qdrant:
140
+ url: http://localhost:6333
141
+ apiKey: xxx
142
+ collection: cogitator
143
+ dimensions: 1536
144
+
145
+ # Embedding service for semantic search
146
+ embedding:
147
+ provider: openai # openai | ollama | google
148
+ apiKey: sk-xxx
149
+ model: text-embedding-3-small
150
+
151
+ # Context builder settings
152
+ contextBuilder:
153
+ maxTokens: 4000
154
+ reserveTokens: 500
155
+ strategy: recent # recent | relevant | hybrid
156
+ includeSystemPrompt: true
157
+ includeFacts: true
158
+ includeSemanticContext: true
159
+ includeGraphContext: false
160
+ graphContextOptions:
161
+ maxNodes: 20
162
+ maxDepth: 3
163
+ ```
164
+
165
+ ### Sandbox Configuration
166
+
167
+ ```yaml
168
+ sandbox:
169
+ defaults:
170
+ type: docker # docker | native | wasm
171
+ image: python:3.11-slim
172
+ timeout: 30000
173
+ workdir: /workspace
174
+ user: sandbox
175
+ resources:
176
+ memory: 512m
177
+ cpus: 0.5
178
+ cpuShares: 512
179
+ pidsLimit: 100
180
+ network:
181
+ mode: none # none | bridge | host
182
+ allowedHosts:
183
+ - api.example.com
184
+ dns:
185
+ - 8.8.8.8
186
+
187
+ pool:
188
+ maxSize: 10
189
+ idleTimeoutMs: 60000
190
+
191
+ docker:
192
+ socketPath: /var/run/docker.sock
193
+ # Or TCP:
194
+ host: localhost
195
+ port: 2375
196
+
197
+ wasm:
198
+ wasmModule: ./tools.wasm
199
+ memoryPages: 256
200
+ functionName: run
201
+ wasi: true
202
+ cacheSize: 100
203
+ ```
204
+
205
+ ### Reflection Configuration
206
+
207
+ ```yaml
208
+ reflection:
209
+ enabled: true
210
+ reflectAfterToolCall: true
211
+ reflectAfterError: true
212
+ reflectAtEnd: true
213
+ storeInsights: true
214
+ maxInsightsPerAgent: 50
215
+ minConfidenceToStore: 0.7
216
+ useSmallModelForReflection: true
217
+ reflectionModel: gpt-4o-mini
218
+ ```
219
+
220
+ ### Guardrails Configuration
221
+
222
+ ```yaml
223
+ guardrails:
224
+ enabled: true
225
+ model: gpt-4o-mini
226
+ filterInput: true
227
+ filterOutput: true
228
+ filterToolCalls: true
229
+ filterToolResults: false
230
+ enableCritiqueRevision: true
231
+ maxRevisionIterations: 3
232
+ revisionConfidenceThreshold: 0.8
233
+ strictMode: false
234
+ logViolations: true
235
+ thresholds:
236
+ violence: high
237
+ hate: high
238
+ sexual: medium
239
+ self-harm: high
240
+ illegal: high
241
+ privacy: medium
242
+ misinformation: medium
243
+ manipulation: medium
244
+ ```
245
+
246
+ ### Cost Routing Configuration
247
+
248
+ ```yaml
249
+ costRouting:
250
+ enabled: true
251
+ autoSelectModel: true
252
+ preferLocal: true
253
+ minCapabilityMatch: 0.3
254
+ trackCosts: true
255
+ ollamaUrl: http://localhost:11434
256
+ budget:
257
+ maxCostPerRun: 0.10
258
+ maxCostPerHour: 5.00
259
+ maxCostPerDay: 50.00
260
+ warningThreshold: 0.8
39
261
  ```
40
262
 
41
- ### Environment Variables
263
+ ### Limits Configuration
264
+
265
+ ```yaml
266
+ limits:
267
+ maxConcurrentRuns: 10
268
+ defaultTimeout: 120000
269
+ maxTokensPerRun: 100000
270
+ ```
271
+
272
+ ### Logging Configuration
273
+
274
+ ```yaml
275
+ logging:
276
+ level: info # debug | info | warn | error | silent
277
+ format: pretty # json | pretty
278
+ destination: console # console | file
279
+ filePath: ./logs/cogitator.log
280
+ ```
281
+
282
+ ---
283
+
284
+ ## Environment Variables
285
+
286
+ All configuration can be set via environment variables with `COGITATOR_` prefix:
287
+
288
+ | Variable | Description |
289
+ | -------------------------------- | -------------------- |
290
+ | `COGITATOR_LLM_DEFAULT_PROVIDER` | Default LLM provider |
291
+ | `COGITATOR_LLM_DEFAULT_MODEL` | Default model |
292
+ | `COGITATOR_MEMORY_ADAPTER` | Memory adapter type |
293
+ | `COGITATOR_LOGGING_LEVEL` | Log level |
294
+ | `COGITATOR_LOGGING_FORMAT` | Log format |
295
+
296
+ Nested values use underscores:
297
+
298
+ ```bash
299
+ COGITATOR_LLM_PROVIDERS_OPENAI_API_KEY=sk-xxx
300
+ COGITATOR_MEMORY_REDIS_URL=redis://localhost:6379
301
+ ```
42
302
 
43
- Environment variables with `COGITATOR_` prefix are automatically loaded:
303
+ Provider API keys can also use standard env vars:
44
304
 
45
305
  ```bash
46
- COGITATOR_DEFAULT_MODEL=openai/gpt-4o
47
- COGITATOR_LOGGING_LEVEL=debug
306
+ OPENAI_API_KEY=sk-xxx
307
+ ANTHROPIC_API_KEY=sk-ant-xxx
308
+ GOOGLE_API_KEY=xxx
48
309
  ```
49
310
 
50
- ### Priority Order
311
+ ---
51
312
 
52
- 1. Programmatic overrides (highest)
53
- 2. Environment variables
54
- 3. YAML config file
55
- 4. Defaults (lowest)
313
+ ## Priority Order
314
+
315
+ Configuration is merged in this order (later overrides earlier):
316
+
317
+ 1. **Defaults** (lowest priority)
318
+ 2. **YAML config file** (`cogitator.yml`)
319
+ 3. **Environment variables** (`COGITATOR_*`)
320
+ 4. **Programmatic overrides** (highest priority)
321
+
322
+ ---
56
323
 
57
324
  ## Schema Validation
58
325
 
59
- Configuration is validated using Zod schemas:
326
+ All configuration is validated using Zod schemas:
60
327
 
61
328
  ```typescript
62
- import { configSchema } from '@cogitator-ai/config';
329
+ import {
330
+ CogitatorConfigSchema,
331
+ LLMConfigSchema,
332
+ MemoryConfigSchema,
333
+ ReflectionConfigSchema,
334
+ } from '@cogitator-ai/config';
63
335
 
64
- const result = configSchema.safeParse(rawConfig);
336
+ // Validate raw config
337
+ const result = CogitatorConfigSchema.safeParse(rawConfig);
65
338
  if (!result.success) {
66
- console.error(result.error.issues);
339
+ console.error('Invalid config:', result.error.issues);
67
340
  }
341
+
342
+ // Type-safe config
343
+ import type { CogitatorConfigInput, CogitatorConfigOutput } from '@cogitator-ai/config';
344
+ ```
345
+
346
+ ### Available Schemas
347
+
348
+ | Schema | Description |
349
+ | ------------------------- | ---------------------------- |
350
+ | `CogitatorConfigSchema` | Full configuration |
351
+ | `LLMConfigSchema` | LLM providers and defaults |
352
+ | `MemoryConfigSchema` | Memory adapters and settings |
353
+ | `SandboxConfigSchema` | Sandbox execution settings |
354
+ | `ReflectionConfigSchema` | Self-reflection settings |
355
+ | `GuardrailConfigSchema` | Safety guardrails |
356
+ | `CostRoutingConfigSchema` | Cost-aware model selection |
357
+ | `LoggingConfigSchema` | Logging settings |
358
+
359
+ ---
360
+
361
+ ## Examples
362
+
363
+ ### Development Configuration
364
+
365
+ ```yaml
366
+ # cogitator.dev.yml
367
+ llm:
368
+ defaultProvider: ollama
369
+ providers:
370
+ ollama:
371
+ baseUrl: http://localhost:11434
372
+
373
+ memory:
374
+ adapter: memory
375
+ inMemory:
376
+ maxEntries: 100
377
+
378
+ logging:
379
+ level: debug
380
+ format: pretty
381
+
382
+ sandbox:
383
+ defaults:
384
+ type: native # no Docker needed
385
+ ```
386
+
387
+ ### Production Configuration
388
+
389
+ ```yaml
390
+ # cogitator.prod.yml
391
+ llm:
392
+ defaultProvider: openai
393
+ defaultModel: gpt-4o
394
+ providers:
395
+ openai:
396
+ apiKey: ${OPENAI_API_KEY}
397
+ anthropic:
398
+ apiKey: ${ANTHROPIC_API_KEY}
399
+
400
+ memory:
401
+ adapter: postgres
402
+ postgres:
403
+ connectionString: ${DATABASE_URL}
404
+ poolSize: 20
405
+ embedding:
406
+ provider: openai
407
+ apiKey: ${OPENAI_API_KEY}
408
+ contextBuilder:
409
+ maxTokens: 8000
410
+ strategy: hybrid
411
+
412
+ reflection:
413
+ enabled: true
414
+ storeInsights: true
415
+
416
+ guardrails:
417
+ enabled: true
418
+ strictMode: true
419
+
420
+ costRouting:
421
+ enabled: true
422
+ autoSelectModel: true
423
+ budget:
424
+ maxCostPerDay: 100.00
425
+
426
+ logging:
427
+ level: info
428
+ format: json
429
+ destination: file
430
+ filePath: /var/log/cogitator/app.log
431
+
432
+ sandbox:
433
+ defaults:
434
+ type: docker
435
+ resources:
436
+ memory: 256m
437
+ cpus: 0.25
438
+ pool:
439
+ maxSize: 20
68
440
  ```
69
441
 
70
- ## Documentation
442
+ ---
443
+
444
+ ## API Reference
445
+
446
+ ### loadConfig(options)
447
+
448
+ Load configuration from file, environment, and overrides.
449
+
450
+ ```typescript
451
+ interface LoadConfigOptions {
452
+ configPath?: string; // Path to YAML file
453
+ envPrefix?: string; // Env var prefix (default: 'COGITATOR')
454
+ overrides?: CogitatorConfigInput; // Programmatic overrides
455
+ }
456
+
457
+ const config = await loadConfig({
458
+ configPath: './cogitator.yml',
459
+ overrides: { logging: { level: 'debug' } },
460
+ });
461
+ ```
462
+
463
+ ### defineConfig(config)
464
+
465
+ Type-safe config definition helper.
466
+
467
+ ```typescript
468
+ const config = defineConfig({
469
+ llm: {
470
+ defaultProvider: 'openai',
471
+ providers: {
472
+ openai: { apiKey: 'sk-xxx' },
473
+ },
474
+ },
475
+ });
476
+ ```
477
+
478
+ ### loadYamlConfig(path)
479
+
480
+ Load and parse YAML config file.
481
+
482
+ ```typescript
483
+ import { loadYamlConfig } from '@cogitator-ai/config';
484
+
485
+ const config = await loadYamlConfig('./cogitator.yml');
486
+ ```
487
+
488
+ ### loadEnvConfig(prefix)
489
+
490
+ Load config from environment variables.
491
+
492
+ ```typescript
493
+ import { loadEnvConfig } from '@cogitator-ai/config';
494
+
495
+ const config = loadEnvConfig('COGITATOR');
496
+ ```
71
497
 
72
- See the [Cogitator documentation](https://github.com/eL1fe/cogitator) for full API reference.
498
+ ---
73
499
 
74
500
  ## License
75
501
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cogitator-ai/config",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Configuration loading for Cogitator (YAML, env)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,7 +18,7 @@
18
18
  "@types/node": "^25.0.0",
19
19
  "yaml": "^2.3.4",
20
20
  "zod": "^3.22.4",
21
- "@cogitator-ai/types": "0.12.0"
21
+ "@cogitator-ai/types": "0.13.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "typescript": "^5.3.0",