outlet-orm 9.0.0 → 9.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "outlet-orm",
3
- "version": "9.0.0",
3
+ "version": "9.0.2",
4
4
  "description": "A Laravel Eloquent-inspired ORM for Node.js with support for MySQL, PostgreSQL, and SQLite",
5
5
  "main": "src/index.js",
6
6
  "types": "types/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "src/**",
16
16
  "bin/**",
17
17
  "types/**",
18
- "docs/skills/**",
18
+ "skills/**",
19
19
  "README.md",
20
20
  "LICENSE"
21
21
  ],
@@ -0,0 +1,570 @@
1
+ ---
2
+ name: outlet-orm-ai-integration
3
+ description: Guide for AI agents to use Outlet ORM's AiBridge multi-provider LLM, AI Query Builder, AI Seeder, AI Optimizer, AI Prompt Enhancer, MCP Server, and AI Safety Guardrails. Use this skill when an AI agent needs to interact with LLMs, databases, run migrations, generate data, optimize queries, or create projects safely.
4
+ license: MIT
5
+ metadata:
6
+ author: omgbwa-yasse
7
+ version: "9.0.0"
8
+ source: https://github.com/omgbwa-yasse/outlet-orm
9
+ npm: https://www.npmjs.com/package/outlet-orm
10
+ ---
11
+
12
+ # Outlet ORM — AI Integration Guide
13
+
14
+ This skill covers Outlet ORM's complete AI feature set (v7.0.0 – v9.0.0):
15
+
16
+ - **AiBridge** — Multi-provider LLM abstraction (9 providers, chat, stream, embeddings, images, TTS, STT, tool calling)
17
+ - **AI Query Builder** — Natural language to SQL
18
+ - **AI Seeder** — LLM-powered realistic data generation
19
+ - **AI Query Optimizer** — SQL optimization and EXPLAIN analysis
20
+ - **AI Prompt Enhancer** — Schema/model/migration code generation from natural language
21
+ - **MCP Server** — Model Context Protocol server for AI agents (13 tools)
22
+ - **AI Safety Guardrails** — Protection against destructive operations
23
+
24
+ ---
25
+
26
+ ## AiBridge — Multi-Provider LLM Abstraction
27
+
28
+ > Since v8.0.0
29
+
30
+ AiBridge provides a unified API to interact with 9+ LLM providers. Zero production dependencies (Node 18+ native `fetch`).
31
+
32
+ ### Configuration
33
+
34
+ ```javascript
35
+ // config/aibridge.js
36
+ module.exports = {
37
+ default: process.env.AI_DEFAULT_PROVIDER || 'openai',
38
+ providers: {
39
+ openai: { api_key: process.env.OPENAI_API_KEY, model: 'gpt-4o' },
40
+ claude: { api_key: process.env.ANTHROPIC_API_KEY, model: 'claude-sonnet-4-20250514' },
41
+ gemini: { api_key: process.env.GEMINI_API_KEY, model: 'gemini-2.0-flash' },
42
+ ollama: { endpoint: 'http://localhost:11434', model: 'llama3' },
43
+ ollama_turbo: { api_key: process.env.OLLAMA_TURBO_API_KEY, endpoint: 'https://api.ollama.ai', model: 'llama3' },
44
+ grok: { api_key: process.env.GROK_API_KEY, model: 'grok-1' },
45
+ mistral: { api_key: process.env.MISTRAL_API_KEY, model: 'mistral-large-latest' },
46
+ onn: { api_key: process.env.ONN_API_KEY, model: 'onn-default' },
47
+ openai_custom: {
48
+ api_key: process.env.CUSTOM_OPENAI_API_KEY,
49
+ base_url: process.env.CUSTOM_OPENAI_BASE_URL || 'http://localhost:1234/v1',
50
+ model: 'local-model'
51
+ },
52
+ openrouter: {
53
+ api_key: process.env.OPENROUTER_API_KEY,
54
+ base_url: 'https://openrouter.ai/api/v1',
55
+ model: 'openai/gpt-4o'
56
+ }
57
+ },
58
+ settings: {
59
+ max_file_bytes: 10485760,
60
+ default_max_tokens: 2048,
61
+ default_temperature: 0.7,
62
+ max_tool_iterations: 5
63
+ }
64
+ };
65
+ ```
66
+
67
+ ### Environment Variables
68
+
69
+ | Variable | Description | Default |
70
+ |----------|-------------|---------|
71
+ | `AI_DEFAULT_PROVIDER` | Default provider name | `openai` |
72
+ | `OPENAI_API_KEY` | OpenAI API key | — |
73
+ | `ANTHROPIC_API_KEY` | Claude API key | — |
74
+ | `GEMINI_API_KEY` | Google Gemini API key | — |
75
+ | `OLLAMA_ENDPOINT` | Ollama local URL | `http://localhost:11434` |
76
+ | `GROK_API_KEY` | xAI Grok API key | — |
77
+ | `MISTRAL_API_KEY` | Mistral AI API key | — |
78
+ | `ONN_API_KEY` | Onn.ai API key | — |
79
+ | `OPENROUTER_API_KEY` | OpenRouter API key | — |
80
+ | `CUSTOM_OPENAI_BASE_URL` | Custom OpenAI-compatible URL | — |
81
+ | `AI_MAX_TOKENS` | Default max tokens | `2048` |
82
+ | `AI_TEMPERATURE` | Default temperature | `0.7` |
83
+
84
+ ### Chat
85
+
86
+ ```javascript
87
+ const { AiBridgeManager } = require('outlet-orm');
88
+
89
+ const ai = new AiBridgeManager(config);
90
+
91
+ const response = await ai.chat('openai', [
92
+ { role: 'system', content: 'You are a helpful assistant.' },
93
+ { role: 'user', content: 'Explain closures in JavaScript.' }
94
+ ], { model: 'gpt-4o-mini', max_tokens: 500 });
95
+
96
+ console.log(response.text);
97
+ ```
98
+
99
+ ### Streaming
100
+
101
+ ```javascript
102
+ for await (const chunk of ai.stream('openai', messages)) {
103
+ process.stdout.write(chunk.text || '');
104
+ }
105
+ ```
106
+
107
+ ### Embeddings
108
+
109
+ ```javascript
110
+ const result = await ai.embeddings('openai', ['The quick brown fox'], {
111
+ model: 'text-embedding-3-small'
112
+ });
113
+ console.log(result.vectors);
114
+ ```
115
+
116
+ ### Image Generation
117
+
118
+ ```javascript
119
+ const image = await ai.image('openai', 'A sunset over mountains', {
120
+ model: 'dall-e-3', size: '1024x1024'
121
+ });
122
+ ```
123
+
124
+ ### TTS / STT
125
+
126
+ ```javascript
127
+ const { audio, mime } = await ai.tts('openai', 'Hello!', { voice: 'alloy' });
128
+ const { text } = await ai.stt('openai', '/path/to/audio.mp3');
129
+ ```
130
+
131
+ ### TextBuilder (Fluent API)
132
+
133
+ ```javascript
134
+ const { text } = await ai.text()
135
+ .using('openai', 'gpt-4o')
136
+ .withSystemPrompt('You are a poet.')
137
+ .withPrompt('Write a haiku about coding.')
138
+ .withMaxTokens(100)
139
+ .usingTemperature(0.9)
140
+ .asText();
141
+ ```
142
+
143
+ | Method | Description |
144
+ |--------|-------------|
145
+ | `.using(provider, model)` | Set provider and model |
146
+ | `.withPrompt(text, attachments?)` | Add user message |
147
+ | `.withSystemPrompt(text)` | Set system prompt |
148
+ | `.withMaxTokens(n)` | Max tokens limit |
149
+ | `.usingTemperature(t)` | Temperature (0–2) |
150
+ | `.withApiKey(key)` | Override API key |
151
+ | `.withBaseUrl(url)` | Override base URL |
152
+ | `.asText()` | Returns `{ text, raw, usage }` |
153
+ | `.asStream()` | Returns `AsyncGenerator<StreamChunk>` |
154
+ | `.asRaw()` | Returns raw provider response |
155
+
156
+ ### Tool Calling (Function Calling)
157
+
158
+ ```javascript
159
+ const { ToolContract } = require('outlet-orm');
160
+
161
+ class WeatherTool extends ToolContract {
162
+ name() { return 'get_weather'; }
163
+ description() { return 'Get current weather for a city'; }
164
+ schema() {
165
+ return {
166
+ type: 'object',
167
+ properties: { city: { type: 'string' } },
168
+ required: ['city']
169
+ };
170
+ }
171
+ async execute({ city }) {
172
+ return JSON.stringify({ city, temperature: 22, unit: 'celsius' });
173
+ }
174
+ }
175
+
176
+ ai.registerTool(new WeatherTool());
177
+ const response = await ai.chatWithTools('openai', [
178
+ { role: 'user', content: "What's the weather in Paris?" }
179
+ ]);
180
+ ```
181
+
182
+ ### AiBridge Facade
183
+
184
+ ```javascript
185
+ const { AiBridge, AiBridgeManager } = require('outlet-orm');
186
+
187
+ AiBridge.setManager(new AiBridgeManager(config));
188
+
189
+ const { text } = await AiBridge.text()
190
+ .using('openai', 'gpt-4o')
191
+ .withPrompt('Hello!')
192
+ .asText();
193
+ ```
194
+
195
+ ### Support Classes
196
+
197
+ | Class | Purpose |
198
+ |-------|---------|
199
+ | `Message` | Value object: `Message.system()`, `.user()`, `.assistant()` |
200
+ | `Document` | Attachments: `.fromLocalPath()`, `.fromUrl()`, `.fromBase64()`, `.fromChunks()` |
201
+ | `StreamChunk` | Streaming DTO: `.text`, `.usage`, `.finishReason`, `.toolCalls` |
202
+ | `ProviderError` | Error handling: `.notFound(name)`, `.unsupported(name, feature)` |
203
+ | `FileSecurity` | File attachment validation (size, type) |
204
+ | `JsonSchemaValidator` | Validates structured LLM outputs |
205
+
206
+ ### Providers
207
+
208
+ | Provider | Class | Capabilities |
209
+ |----------|-------|-------------|
210
+ | **OpenAI** | `OpenAIProvider` | Chat, SSE streaming, embeddings, images, TTS, STT, function calling |
211
+ | **Claude** | `ClaudeProvider` | Chat, simulated streaming |
212
+ | **Gemini** | `GeminiProvider` | Chat, simulated streaming, embeddings |
213
+ | **Ollama** | `OllamaProvider` | Chat, NDJSON streaming, embeddings, images, multimodal |
214
+ | **Ollama Turbo** | `OllamaTurboProvider` | Ollama + Bearer token auth |
215
+ | **Grok** | `GrokProvider` | Chat, simulated streaming |
216
+ | **Mistral** | `MistralProvider` | OpenAI-compatible |
217
+ | **ONN** | `OnnProvider` | Chat, simulated streaming |
218
+ | **Custom OpenAI** | `CustomOpenAIProvider` | Any OpenAI-compatible endpoint (LM Studio, vLLM, Azure, OpenRouter) |
219
+
220
+ ---
221
+
222
+ ## AI Query Builder — Natural Language to SQL
223
+
224
+ > Since v8.0.0
225
+
226
+ Convert natural language questions into SQL queries using any LLM.
227
+
228
+ ```javascript
229
+ const { AiBridgeManager, AIQueryBuilder, DatabaseConnection } = require('outlet-orm');
230
+
231
+ const ai = new AiBridgeManager(config);
232
+ const db = new DatabaseConnection();
233
+ const qb = new AIQueryBuilder(ai, db);
234
+
235
+ // Convert and execute
236
+ const result = await qb.query('How many users signed up last month?');
237
+ console.log(result.sql); // SELECT COUNT(*) ...
238
+ console.log(result.results); // [{ count: 42 }]
239
+
240
+ // Generate SQL without executing
241
+ const { sql } = await qb.toSql('Find duplicate emails');
242
+ ```
243
+
244
+ ### API
245
+
246
+ | Method | Returns | Description |
247
+ |--------|---------|-------------|
248
+ | `using(provider, model)` | `this` | Set LLM provider |
249
+ | `safeMode(bool)` | `this` | Restrict to SELECT/WITH (default: true) |
250
+ | `query(question)` | `{ sql, params, results, explanation }` | Convert + execute |
251
+ | `toSql(question)` | `{ sql, params, explanation }` | Convert only |
252
+
253
+ ### Schema Introspection
254
+
255
+ | Driver | Method |
256
+ |--------|--------|
257
+ | SQLite | `PRAGMA table_list` + `PRAGMA table_info` |
258
+ | PostgreSQL | `information_schema.tables` + `columns` |
259
+ | MySQL | `SHOW TABLES` + `DESCRIBE` |
260
+
261
+ ---
262
+
263
+ ## AI Seeder — LLM-Powered Data Generation
264
+
265
+ > Since v8.0.0
266
+
267
+ Generate realistic, domain-specific seed data using AI.
268
+
269
+ ```javascript
270
+ const { AiBridgeManager, AISeeder, DatabaseConnection } = require('outlet-orm');
271
+
272
+ const seeder = new AISeeder(new AiBridgeManager(config), new DatabaseConnection());
273
+
274
+ // Generate and insert
275
+ const { records, inserted } = await seeder.seed('users', 10, {
276
+ domain: 'e-commerce',
277
+ locale: 'fr_FR',
278
+ description: 'An online fashion store'
279
+ });
280
+
281
+ // Generate without inserting (preview)
282
+ const records = await seeder.generate('products', 20, {
283
+ domain: 'electronics'
284
+ });
285
+ ```
286
+
287
+ ### API
288
+
289
+ | Method | Returns | Description |
290
+ |--------|---------|-------------|
291
+ | `using(provider, model)` | `this` | Set LLM provider |
292
+ | `seed(table, count, context)` | `{ records, inserted }` | Generate + insert |
293
+ | `generate(table, count, context)` | `Array<Object>` | Generate only (preview) |
294
+
295
+ ### Context Options
296
+
297
+ | Option | Type | Description |
298
+ |--------|------|-------------|
299
+ | `domain` | `string` | Business domain (`'e-commerce'`, `'healthcare'`, `'finance'`, etc.) |
300
+ | `locale` | `string` | Name/address locale (`'fr_FR'`, `'ja_JP'`, `'pt_BR'`, etc.) |
301
+ | `description` | `string` | Detailed domain description for better data quality |
302
+
303
+ ---
304
+
305
+ ## AI Query Optimizer
306
+
307
+ > Since v8.0.0
308
+
309
+ Analyze and optimize SQL queries using AI with index recommendations.
310
+
311
+ ```javascript
312
+ const { AiBridgeManager, AIQueryOptimizer, DatabaseConnection } = require('outlet-orm');
313
+
314
+ const optimizer = new AIQueryOptimizer(new AiBridgeManager(config), new DatabaseConnection());
315
+
316
+ // Optimize
317
+ const result = await optimizer.optimize(
318
+ 'SELECT * FROM orders WHERE user_id IN (SELECT id FROM users WHERE status = "active")'
319
+ );
320
+ console.log(result.optimized); // Rewritten SQL
321
+ console.log(result.suggestions); // [{ type, description, impact }]
322
+ console.log(result.indexes); // ['CREATE INDEX ...']
323
+
324
+ // Explain
325
+ const { plan, analysis } = await optimizer.explain('SELECT ...');
326
+ ```
327
+
328
+ ### API
329
+
330
+ | Method | Returns | Description |
331
+ |--------|---------|-------------|
332
+ | `using(provider, model)` | `this` | Set LLM provider |
333
+ | `optimize(sql)` | `{ original, optimized, suggestions, indexes, explanation }` | Analyze + rewrite |
334
+ | `explain(sql)` | `{ plan, analysis }` | EXPLAIN + LLM interpretation |
335
+
336
+ ### Common Optimizations Detected
337
+
338
+ | Issue | Impact | Suggestion |
339
+ |-------|--------|------------|
340
+ | `SELECT *` | Medium | Specify explicit columns |
341
+ | Missing index on JOIN column | High | `CREATE INDEX` on foreign keys |
342
+ | `IN` subquery | High | Rewrite as `JOIN` |
343
+ | Leading wildcard `LIKE '%...'` | High | Use full-text search |
344
+ | Large `OFFSET` pagination | Medium | Use keyset pagination |
345
+
346
+ ---
347
+
348
+ ## AI Prompt Enhancer — Schema & Code Generation
349
+
350
+ > Since v8.0.0
351
+
352
+ Generate complete schemas, models, and migrations from natural language.
353
+
354
+ ```javascript
355
+ const { AiBridgeManager, AIPromptEnhancer } = require('outlet-orm');
356
+
357
+ const enhancer = new AIPromptEnhancer(new AiBridgeManager(config));
358
+
359
+ // Generate full schema
360
+ const schema = await enhancer.generateSchema(
361
+ 'A veterinary clinic with pets, owners, appointments, and medical records'
362
+ );
363
+ // schema.tables, schema.relations, schema.seedHints
364
+
365
+ // Generate model code
366
+ const code = await enhancer.generateModelCode('pets', schema.tables.pets, relations);
367
+
368
+ // Generate migration code
369
+ const migration = await enhancer.generateMigrationCode('pets', schema.tables.pets);
370
+ ```
371
+
372
+ ### API
373
+
374
+ | Method | Returns | Description |
375
+ |--------|---------|-------------|
376
+ | `using(provider, model)` | `this` | Set LLM provider |
377
+ | `generateSchema(description)` | `{ tables, relations, seedHints }` | Full schema from description |
378
+ | `generateModelCode(table, schema, rels)` | `string` | outlet-orm Model class code |
379
+ | `generateMigrationCode(table, schema)` | `string` | outlet-orm Migration class code |
380
+
381
+ ### PromptGenerator (Regex-Based, Offline)
382
+
383
+ For offline scaffolding without an LLM:
384
+
385
+ ```javascript
386
+ const { PromptGenerator } = require('outlet-orm');
387
+
388
+ const blueprint = PromptGenerator.parse('Create a blog with comments and tags');
389
+ PromptGenerator.generateModels(blueprint, './src/models');
390
+ PromptGenerator.generateMigrations(blueprint, './database/migrations');
391
+ PromptGenerator.generateSeeder(blueprint, './database/seeds');
392
+ ```
393
+
394
+ Built-in templates: E-commerce, Blog/CMS, Task/Project, Social Network, SaaS, Habit Tracker, API/Auth.
395
+
396
+ ### CLI
397
+
398
+ ```bash
399
+ outlet-init --prompt "Create a blog with posts, comments, and tags"
400
+ outlet-init --prompt "E-commerce store" --driver sqlite
401
+ ```
402
+
403
+ ---
404
+
405
+ ## MCP Server
406
+
407
+ > Since v7.0.0
408
+
409
+ The MCP server exposes Outlet ORM's full capabilities to AI agents via JSON-RPC 2.0 over stdio.
410
+
411
+ ### Configuration
412
+
413
+ Add to your AI editor's MCP config (`.cursor/mcp.json`, `.vscode/mcp.json`, `claude_desktop_config.json`):
414
+
415
+ ```json
416
+ {
417
+ "mcpServers": {
418
+ "outlet-orm": {
419
+ "command": "npx",
420
+ "args": ["outlet-mcp"],
421
+ "env": {
422
+ "DB_DRIVER": "sqlite",
423
+ "DB_DATABASE": "./database.sqlite"
424
+ }
425
+ }
426
+ }
427
+ }
428
+ ```
429
+
430
+ ### Available Tools
431
+
432
+ | Tool | Description | Destructive |
433
+ |------|-------------|:-----------:|
434
+ | `migrate_status` | Show pending and executed migrations | No |
435
+ | `migrate_run` | Run all pending migrations | No |
436
+ | `migrate_rollback` | Rollback last batch | No |
437
+ | `migrate_reset` | Rollback ALL migrations | **Yes** |
438
+ | `migrate_make` | Create a new migration file | No |
439
+ | `seed_run` | Run database seeders | No |
440
+ | `schema_introspect` | Introspect database schema | No |
441
+ | `query_execute` | Execute raw SQL | Conditional |
442
+ | `model_list` | List all model files | No |
443
+ | `backup_create` | Create database backup | No |
444
+ | `backup_restore` | Restore from backup | **Yes** |
445
+ | `ai_query` | AI natural language to SQL | No |
446
+ | `query_optimize` | AI query optimization | No |
447
+
448
+ ### Tool Usage Examples
449
+
450
+ ```json
451
+ // Introspect schema
452
+ { "method": "tools/call", "params": { "name": "schema_introspect", "arguments": {} } }
453
+
454
+ // Run a SELECT query
455
+ { "method": "tools/call", "params": { "name": "query_execute", "arguments": { "sql": "SELECT * FROM users LIMIT 10" } } }
456
+
457
+ // AI query
458
+ { "method": "tools/call", "params": { "name": "ai_query", "arguments": { "question": "How many users signed up this month?" } } }
459
+
460
+ // Destructive operation (requires consent)
461
+ { "method": "tools/call", "params": { "name": "migrate_reset", "arguments": { "consent": "User confirmed: reset dev migrations" } } }
462
+ ```
463
+
464
+ ### Programmatic Usage
465
+
466
+ ```javascript
467
+ const { MCPServer } = require('outlet-orm');
468
+
469
+ const server = new MCPServer({
470
+ projectDir: process.cwd(),
471
+ safetyGuardrails: true
472
+ });
473
+
474
+ const handler = server.handler();
475
+ const response = await handler({
476
+ jsonrpc: '2.0', id: 1,
477
+ method: 'tools/call',
478
+ params: { name: 'schema_introspect', arguments: {} }
479
+ });
480
+ ```
481
+
482
+ ---
483
+
484
+ ## AI Safety Guardrails
485
+
486
+ > Since v7.0.0
487
+
488
+ Automatic AI agent detection and protection against destructive operations.
489
+
490
+ ### Detected Agents
491
+
492
+ | Agent | Detection |
493
+ |-------|-----------|
494
+ | **Cursor** | `CURSOR_*` env variables |
495
+ | **Claude Code** | `CLAUDE_*` env variables |
496
+ | **GitHub Copilot** | `GITHUB_COPILOT_*` or `VSCODE_*` with Copilot |
497
+ | **Windsurf** | `WINDSURF_*` env variables |
498
+ | **Gemini CLI** | `GEMINI_*` env variables |
499
+ | **Aider** | `AIDER_*` env variables |
500
+ | **Replit** | `REPL_*` env variables |
501
+ | **Qwen Code** | `QWEN_*` env variables |
502
+ | **Generic MCP** | `MCP_*` env variables |
503
+
504
+ ### Destructive Commands
505
+
506
+ Blocked without consent: `reset`, `fresh`, `drop`, `truncate`, `restore`
507
+
508
+ ### Consent Mechanism
509
+
510
+ ```bash
511
+ # Via environment variable
512
+ export OUTLET_USER_CONSENT_FOR_DANGEROUS_AI_ACTION="User approved: reset dev database"
513
+ ```
514
+
515
+ ```json
516
+ // Via MCP tool argument
517
+ { "consent": "User confirmed: reset the development database" }
518
+ ```
519
+
520
+ ### Programmatic Usage
521
+
522
+ ```javascript
523
+ const { AISafetyGuardrails } = require('outlet-orm');
524
+
525
+ const { detected, agentName } = AISafetyGuardrails.detectAgent();
526
+ const result = AISafetyGuardrails.validateDestructiveAction('reset', { consent: 'User approved' });
527
+ console.log(result.allowed); // true
528
+ ```
529
+
530
+ ---
531
+
532
+ ## Best Practices for AI Agents
533
+
534
+ 1. **Always introspect first** — Use `schema_introspect` before modifying the database.
535
+ 2. **Never bypass safety guardrails** — Always obtain explicit user consent for destructive operations.
536
+ 3. **Use migrations, not raw DDL** — Prefer `migrate_make` + `migrate_run` over raw `CREATE TABLE`.
537
+ 4. **Check migration status** — Use `migrate_status` before running migrations.
538
+ 5. **Explain write queries** — When using `query_execute` for writes, explain what the query does.
539
+ 6. **Prefer backups before destructive operations** — Use `backup_create` before `migrate_reset`.
540
+ 7. **Use AI Query Builder for natural language** — Use `ai_query` tool instead of crafting SQL manually.
541
+ 8. **Preview before seeding** — Use `generate()` to preview AI-generated data before `seed()`.
542
+
543
+ ---
544
+
545
+ ## Quick Reference
546
+
547
+ ```javascript
548
+ const {
549
+ // AiBridge — Multi-Provider LLM
550
+ AiBridgeManager, // Main manager (chat, stream, embeddings, images, TTS, STT, tools)
551
+ AiBridge, // Static facade
552
+ // AiBridge Support
553
+ Message, // Chat message value object
554
+ Document, // File/URL/base64 attachment
555
+ StreamChunk, // Streaming DTO
556
+ ToolContract, // Base class for function calling tools
557
+ ProviderError, // Error handling
558
+ FileSecurity, // Attachment validation
559
+ JsonSchemaValidator, // Structured output validation
560
+ // ORM AI Features
561
+ AIQueryBuilder, // Natural language → SQL
562
+ AISeeder, // AI-powered data seeding
563
+ AIQueryOptimizer, // SQL optimization
564
+ AIPromptEnhancer, // Schema/code generation from descriptions
565
+ PromptGenerator, // Regex-based offline scaffolding
566
+ // AI Agent Integration
567
+ MCPServer, // MCP server for AI agents (13 tools)
568
+ AISafetyGuardrails, // AI agent detection & safety
569
+ } = require('outlet-orm');
570
+ ```
@@ -515,6 +515,114 @@ const db = new DatabaseConnection({
515
515
 
516
516
  ---
517
517
 
518
+ ## AiBridgeManager
519
+
520
+ > Since v8.0.0
521
+
522
+ ### Constructor
523
+
524
+ ```javascript
525
+ const { AiBridgeManager } = require('outlet-orm');
526
+ const ai = new AiBridgeManager(config); // From config/aibridge.js or inline
527
+ ```
528
+
529
+ ### Methods
530
+
531
+ | Method | Returns | Description |
532
+ |--------|---------|-------------|
533
+ |`chat(provider, messages, opts?)`| `{ text, tool_calls, raw }` | Send chat request |
534
+ |`stream(provider, messages, opts?)`| `AsyncGenerator<StreamChunk>` | SSE/NDJSON stream |
535
+ |`streamEvents(provider, messages, opts?)`| `AsyncGenerator<{type, data}>` | Structured stream events |
536
+ |`embeddings(provider, inputs, opts?)`| `{ vectors, usage, raw }` | Generate embeddings |
537
+ |`image(provider, prompt, opts?)`| `{ url, b64_json, raw }` | Generate image |
538
+ |`tts(provider, text, opts?)`| `{ audio, mime }` | Text-to-speech |
539
+ |`stt(provider, filePath, opts?)`| `{ text }` | Speech-to-text |
540
+ |`models(provider)`| `Array<{id, ...}>` | List available models |
541
+ |`model(provider, id)`| `Object` | Get single model info |
542
+ |`text()`| `TextBuilder` | Fluent text builder |
543
+ |`chatWithTools(provider, messages, opts?)`| `{ text, raw }` | Chat with tool calling loop |
544
+ |`registerTool(tool)`| `void` | Register a custom tool |
545
+ |`registerProvider(name, provider)`| `void` | Register a custom provider |
546
+ |`provider(name)`| `Provider` | Get registered provider |
547
+ |`tool(name)`| `ToolContract` | Get registered tool |
548
+ |`tools()`| `Array<ToolContract>` | Get all tools |
549
+
550
+ ---
551
+
552
+ ## TextBuilder
553
+
554
+ | Method | Returns | Description |
555
+ |--------|---------|-------------|
556
+ |`.using(provider, model)`| `this` | Set provider and model |
557
+ |`.withPrompt(text, attachments?)`| `this` | Add user message |
558
+ |`.withSystemPrompt(text)`| `this` | Set system prompt |
559
+ |`.withMaxTokens(n)`| `this` | Max tokens limit |
560
+ |`.usingTemperature(t)`| `this` | Temperature (0–2) |
561
+ |`.usingTopP(p)`| `this` | Top-p sampling |
562
+ |`.withApiKey(key)`| `this` | Override API key |
563
+ |`.withEndpoint(url)`| `this` | Override endpoint |
564
+ |`.withBaseUrl(url)`| `this` | Override base URL |
565
+ |`.withAuthHeader(header, prefix?)`| `this` | Override auth header |
566
+ |`.withExtraHeaders(headers)`| `this` | Extra HTTP headers |
567
+ |`.asText()`| `{ text, raw, usage, finish_reason }` | Text response |
568
+ |`.asStream()`| `AsyncGenerator<StreamChunk>` | Streaming response |
569
+ |`.asRaw()`| `Object` | Raw provider response |
570
+
571
+ ---
572
+
573
+ ## AIQueryBuilder
574
+
575
+ | Method | Returns | Description |
576
+ |--------|---------|-------------|
577
+ |`using(provider, model)`| `this` | Set LLM provider |
578
+ |`safeMode(bool)`| `this` | Restrict to SELECT/WITH |
579
+ |`query(question)`| `{ sql, params, results, explanation }` | NL → SQL + execute |
580
+ |`toSql(question)`| `{ sql, params, explanation }` | NL → SQL only |
581
+
582
+ ---
583
+
584
+ ## AISeeder
585
+
586
+ | Method | Returns | Description |
587
+ |--------|---------|-------------|
588
+ |`using(provider, model)`| `this` | Set LLM provider |
589
+ |`seed(table, count, ctx)`| `{ records, inserted }` | Generate + insert |
590
+ |`generate(table, count, ctx)`| `Array<Object>` | Preview only |
591
+
592
+ ---
593
+
594
+ ## AIQueryOptimizer
595
+
596
+ | Method | Returns | Description |
597
+ |--------|---------|-------------|
598
+ |`using(provider, model)`| `this` | Set LLM provider |
599
+ |`optimize(sql)`| `{ original, optimized, suggestions, indexes, explanation }` | Analyze + rewrite |
600
+ |`explain(sql)`| `{ plan, analysis }` | EXPLAIN + LLM analysis |
601
+
602
+ ---
603
+
604
+ ## AIPromptEnhancer
605
+
606
+ | Method | Returns | Description |
607
+ |--------|---------|-------------|
608
+ |`using(provider, model)`| `this` | Set LLM provider |
609
+ |`generateSchema(description)`| `{ tables, relations, seedHints }` | Schema from description |
610
+ |`generateModelCode(table, schema, rels)`| `string` | Model class code |
611
+ |`generateMigrationCode(table, schema)`| `string` | Migration class code |
612
+
613
+ ---
614
+
615
+ ## AISafetyGuardrails (Static)
616
+
617
+ | Method | Returns | Description |
618
+ |--------|---------|-------------|
619
+ |`detectAgent()`| `{ detected, agentName }` | Detect AI agent |
620
+ |`isDestructiveCommand(cmd)`| `boolean` | Check if destructive |
621
+ |`validateDestructiveAction(cmd, flags)`| `{ allowed, message }` | Validate with consent |
622
+ |`CONSENT_ENV_VAR`| `string` | Consent env var name |
623
+
624
+ ---
625
+
518
626
  ## References
519
627
 
520
628
  - <https://github.com/omgbwa-yasse/outlet-orm>
@@ -300,6 +300,70 @@ const native = await db.execute(
300
300
 
301
301
  ---
302
302
 
303
+ ## AI Query Builder — Natural Language to SQL
304
+
305
+ > Since v8.0.0
306
+
307
+ Convert natural language into SQL queries using any LLM provider via AiBridge.
308
+
309
+ ```javascript
310
+ const { AiBridgeManager, AIQueryBuilder, DatabaseConnection } = require('outlet-orm');
311
+
312
+ const ai = new AiBridgeManager({ providers: { openai: { api_key: process.env.OPENAI_API_KEY, model: 'gpt-4o-mini' } } });
313
+ const db = new DatabaseConnection();
314
+ const qb = new AIQueryBuilder(ai, db);
315
+
316
+ // Convert and execute
317
+ const result = await qb.query('How many users signed up last month?');
318
+ console.log(result.sql); // SELECT COUNT(*) ...
319
+ console.log(result.results); // [{ count: 42 }]
320
+
321
+ // Generate SQL without executing
322
+ const { sql } = await qb.toSql('Find duplicate emails');
323
+
324
+ // Use a specific provider
325
+ const r = await qb.using('claude', 'claude-sonnet-4-20250514')
326
+ .query('List users without orders');
327
+
328
+ // Disable safe mode (allow writes)
329
+ qb.safeMode(false);
330
+ ```
331
+
332
+ ### AI Query Builder Methods
333
+
334
+ | Method | Returns | Description |
335
+ |--------|---------|-------------|
336
+ |`using(provider, model)`| `this` | Set LLM provider |
337
+ |`safeMode(bool)`| `this` | Restrict to SELECT/WITH (default: `true`) |
338
+ |`query(question)`| `{ sql, params, results, explanation }` | NL → SQL + execute |
339
+ |`toSql(question)`| `{ sql, params, explanation }` | NL → SQL only |
340
+
341
+ See [AI.md](AI.md) for full details.
342
+
343
+ ---
344
+
345
+ ## AI Query Optimizer
346
+
347
+ > Since v8.0.0
348
+
349
+ Analyze and optimize SQL queries with AI.
350
+
351
+ ```javascript
352
+ const { AIQueryOptimizer } = require('outlet-orm');
353
+
354
+ const optimizer = new AIQueryOptimizer(ai, db);
355
+ const result = await optimizer.optimize('SELECT * FROM orders WHERE ...');
356
+ console.log(result.optimized); // Rewritten SQL
357
+ console.log(result.suggestions); // [{ type, description, impact }]
358
+ console.log(result.indexes); // ['CREATE INDEX ...']
359
+
360
+ const { plan, analysis } = await optimizer.explain('SELECT ...');
361
+ ```
362
+
363
+ See [AI.md](AI.md) for full details.
364
+
365
+ ---
366
+
303
367
  ## Query Builder Methods Summary
304
368
 
305
369
  | Method | Description |
@@ -96,3 +96,50 @@ outlet-migrate seed
96
96
  - Control FK order explicitly in`DatabaseSeeder`.
97
97
  - Keep heavy bulk data in dedicated import scripts.
98
98
  - Prefer unique constraints to prevent duplicate seed data.
99
+
100
+ ---
101
+
102
+ ## AI Seeder — LLM-Powered Data Generation
103
+
104
+ > Since v8.0.0
105
+
106
+ Generate realistic domain-specific seed data using AI instead of generic lorem ipsum.
107
+
108
+ ```javascript
109
+ const { AiBridgeManager, AISeeder, DatabaseConnection } = require('outlet-orm');
110
+
111
+ const ai = new AiBridgeManager({
112
+ providers: { openai: { api_key: process.env.OPENAI_API_KEY, model: 'gpt-4o-mini' } }
113
+ });
114
+ const seeder = new AISeeder(ai, new DatabaseConnection());
115
+
116
+ // Generate and insert 10 realistic user records
117
+ const { records, inserted } = await seeder.seed('users', 10, {
118
+ domain: 'e-commerce',
119
+ locale: 'fr_FR',
120
+ description: 'An online fashion store'
121
+ });
122
+
123
+ // Preview without inserting
124
+ const preview = await seeder.generate('products', 5, {
125
+ domain: 'electronics'
126
+ });
127
+ ```
128
+
129
+ ### AI Seeder API
130
+
131
+ | Method | Returns | Description |
132
+ |--------|---------|-------------|
133
+ |`using(provider, model)`| `this` | Set LLM provider |
134
+ |`seed(table, count, context)`| `{ records, inserted }` | Generate + insert |
135
+ |`generate(table, count, context)`| `Array<Object>` | Generate only (preview) |
136
+
137
+ ### Context Options
138
+
139
+ | Option | Type | Description |
140
+ |--------|------|-------------|
141
+ | `domain` | `string` | Business domain (`'e-commerce'`, `'healthcare'`, `'finance'`) |
142
+ | `locale` | `string` | Locale for names/addresses (`'fr_FR'`, `'ja_JP'`, `'pt_BR'`) |
143
+ | `description` | `string` | Detailed description for better data quality |
144
+
145
+ See [AI.md](AI.md) for full details.
@@ -1,10 +1,10 @@
1
1
  ---
2
2
  name: outlet-orm-best-practices
3
- description: Outlet ORM is a Laravel Eloquent-inspired ORM for Node.js with MySQL, PostgreSQL, and SQLite support. Use this skill when working with Outlet ORM models, queries, relationships, migrations, backup, and database operations. v6.0.0 adds a full Backup module (BackupManager, BackupScheduler, AES-256-GCM encryption, TCP daemon).
3
+ description: Outlet ORM is a Laravel Eloquent-inspired ORM for Node.js with MySQL, PostgreSQL, and SQLite support. Use this skill when working with Outlet ORM models, queries, relationships, migrations, backup, AI integration (AiBridge multi-provider LLM, AI Query Builder, AI Seeder, AI Optimizer, MCP Server) and database operations.
4
4
  license: MIT
5
5
  metadata:
6
6
  author: omgbwa-yasse
7
- version: "6.0.0"
7
+ version: "9.0.0"
8
8
  source: https://github.com/omgbwa-yasse/outlet-orm
9
9
  npm: https://www.npmjs.com/package/outlet-orm
10
10
  ---
@@ -13,11 +13,15 @@ npm: https://www.npmjs.com/package/outlet-orm
13
13
 
14
14
  Comprehensive guide for using Outlet ORM - a Laravel Eloquent-inspired ORM for Node.js/TypeScript with support for MySQL, PostgreSQL, and SQLite.
15
15
 
16
- > 🆕 **v7.0.0**: AI IntegrationMCP Server (Model Context Protocol), AI Safety Guardrails, Prompt-based project initialization. See [AI.md](AI.md).
16
+ > 🆕 **v9.0.0**: Complete AI documentationAiBridge multi-provider LLM, AI Query Builder, AI Seeder, AI Optimizer, AI Prompt Enhancer, AI Safety Guardrails. See [AI.md](AI.md).
17
+ >
18
+ > 🔖 **v8.0.0**: AiBridge multi-provider LLM abstraction (9 providers), AI Query Builder, AI Seeder, AI Query Optimizer, AI Prompt Enhancer.
19
+ >
20
+ > 🔖 **v7.0.0**: AI Integration — MCP Server (Model Context Protocol), AI Safety Guardrails, Prompt-based project initialization.
17
21
  >
18
22
  > 🔖 **v6.5.0**: Accessors & Mutators, firstOrCreate/firstOrNew/updateOrCreate, upsert, Observer pattern, cursor/stream.
19
23
  >
20
- > 🔖 **v6.0.0**: Full Backup module — `BackupManager`, `BackupScheduler`, AES-256-GCM `BackupEncryption`, `BackupSocketServer` TCP daemon, `BackupSocketClient` with remote restore. See [BACKUP.md](BACKUP.md).
24
+ > 🔖 **v6.0.0**: Full Backup module — `BackupManager`, `BackupScheduler`, AES-256-GCM `BackupEncryption`, `BackupSocketServer` TCP daemon. See [BACKUP.md](BACKUP.md).
21
25
  >
22
26
  > 🔖 **v5.0.0**: Full TypeScript support with Generic Model, typed Schema Builder, MigrationInterface and Copilot Skills integration.
23
27
 
@@ -33,7 +37,7 @@ Comprehensive guide for using Outlet ORM - a Laravel Eloquent-inspired ORM for N
33
37
  | **[TYPESCRIPT.md](TYPESCRIPT.md)** | TypeScript types, generics, typed models, migrations |
34
38
  | **[SECURITY.md](SECURITY.md)** | 🔐 Security best practices, authentication, authorisation |
35
39
  | **[BACKUP.md](BACKUP.md)** | 🗄️ Backups, scheduling, AES-256-GCM encryption, TCP daemon, restore |
36
- | **[AI.md](AI.md)** | 🤖 MCP Server, AI Safety Guardrails, Prompt-based Init |
40
+ | **[AI.md](AI.md)** | 🤖 AiBridge (9 LLM providers), AI Query Builder, AI Seeder, AI Optimizer, AI Prompt Enhancer, MCP Server, AI Safety Guardrails |
37
41
  | **[API.md](API.md)** | Complete API Reference |
38
42
 
39
43
  ---
@@ -52,8 +56,12 @@ Reference these guidelines when:
52
56
  - Scheduling or encrypting database backups [BACKUP.md](BACKUP.md)
53
57
  - Restoring a database from a backup file [BACKUP.md](BACKUP.md)
54
58
  - Running a long-lived backup daemon over TCP [BACKUP.md](BACKUP.md)
59
+ - Configuring LLM providers (AiBridge) [AI.md](AI.md)
60
+ - Converting natural language to SQL (AI Query Builder) [AI.md](AI.md)
61
+ - Generating realistic seed data with AI [AI.md](AI.md)
62
+ - Optimizing SQL queries with AI [AI.md](AI.md)
63
+ - Generating schemas/models/migrations from descriptions [AI.md](AI.md)
55
64
  - Exposing the ORM to AI agents via MCP [AI.md](AI.md)
56
- - Generating projects from natural language prompts [AI.md](AI.md)
57
65
  - Protecting against AI-initiated destructive operations [AI.md](AI.md)
58
66
 
59
67
  ---
@@ -194,7 +202,7 @@ outlet-migrate migrate
194
202
  | 7 | Validation & Events | MEDIUM | [ADVANCED.md](ADVANCED.md) |
195
203
  | 8 | Migrations & CLI | LOW-MEDIUM | [MIGRATIONS.md](MIGRATIONS.md) |
196
204
  | 9 | Backup & Restore | MEDIUM | [BACKUP.md](BACKUP.md) |
197
- | 10 | AI / MCP Integration | MEDIUM | [AI.md](AI.md) |
205
+ | 10 | AI / MCP Integration | MEDIUM-HIGH | [AI.md](AI.md) |
198
206
 
199
207
  ---
200
208
 
@@ -1,220 +0,0 @@
1
- ---
2
- name: outlet-orm-ai-integration
3
- description: Guide for AI agents to use Outlet ORM's MCP Server, AI Safety Guardrails, and prompt-based project initialization. Use this skill when an AI agent needs to interact with Outlet ORM databases, run migrations, create projects, or execute queries safely.
4
- license: MIT
5
- metadata:
6
- author: omgbwa-yasse
7
- version: "7.0.0"
8
- source: https://github.com/omgbwa-yasse/outlet-orm
9
- npm: https://www.npmjs.com/package/outlet-orm
10
- ---
11
-
12
- # Outlet ORM — AI Integration Guide
13
-
14
- This skill covers Outlet ORM's AI-oriented features introduced in v7.0.0:
15
-
16
- - **MCP Server** — Model Context Protocol server for AI agents
17
- - **AI Safety Guardrails** — Protection against destructive operations
18
- - **Prompt-based Init** — Generate projects from natural language descriptions
19
-
20
- ---
21
-
22
- ## MCP Server
23
-
24
- The MCP server exposes Outlet ORM's full capabilities to AI agents via JSON-RPC 2.0 over stdio.
25
-
26
- ### Configuration
27
-
28
- Add to your AI editor's MCP config (e.g. `.cursor/mcp.json`, `.vscode/mcp.json`, `claude_desktop_config.json`):
29
-
30
- ```json
31
- {
32
- "mcpServers": {
33
- "outlet-orm": {
34
- "command": "npx",
35
- "args": ["outlet-mcp"],
36
- "env": {
37
- "DB_DRIVER": "sqlite",
38
- "DB_DATABASE": "./database.sqlite"
39
- }
40
- }
41
- }
42
- }
43
- ```
44
-
45
- ### Available Tools
46
-
47
- | Tool | Description | Destructive |
48
- |------|-------------|:-----------:|
49
- | `migrate_status` | Show pending and executed migrations | No |
50
- | `migrate_run` | Run all pending migrations | No |
51
- | `migrate_rollback` | Rollback last batch (supports `steps` param) | No |
52
- | `migrate_reset` | Rollback ALL migrations | **Yes** |
53
- | `migrate_make` | Create a new migration file | No |
54
- | `seed_run` | Run database seeders | No |
55
- | `schema_introspect` | Introspect database schema (all tables or specific) | No |
56
- | `query_execute` | Execute raw SQL (write queries need consent) | Conditional |
57
- | `model_list` | List all model files in the project | No |
58
- | `backup_create` | Create a database backup (full/partial/journal) | No |
59
- | `backup_restore` | Restore from a backup file | **Yes** |
60
-
61
- ### Tool Usage Examples
62
-
63
- **Introspect the schema:**
64
- ```json
65
- { "method": "tools/call", "params": { "name": "schema_introspect", "arguments": {} } }
66
- ```
67
-
68
- **Run a SELECT query:**
69
- ```json
70
- { "method": "tools/call", "params": { "name": "query_execute", "arguments": { "sql": "SELECT * FROM users LIMIT 10" } } }
71
- ```
72
-
73
- **Create a migration:**
74
- ```json
75
- { "method": "tools/call", "params": { "name": "migrate_make", "arguments": { "name": "create_products_table" } } }
76
- ```
77
-
78
- **Destructive operation (requires consent):**
79
- ```json
80
- { "method": "tools/call", "params": { "name": "migrate_reset", "arguments": { "consent": "User confirmed: reset all migrations in dev environment" } } }
81
- ```
82
-
83
- ### Programmatic Usage
84
-
85
- ```javascript
86
- const { MCPServer } = require('outlet-orm');
87
-
88
- const server = new MCPServer({
89
- projectDir: process.cwd(),
90
- safetyGuardrails: true
91
- });
92
-
93
- // Programmatic handler (for testing or embedding)
94
- const handler = server.handler();
95
- const response = await handler({
96
- jsonrpc: '2.0',
97
- id: 1,
98
- method: 'tools/call',
99
- params: { name: 'schema_introspect', arguments: {} }
100
- });
101
- ```
102
-
103
- ---
104
-
105
- ## AI Safety Guardrails
106
-
107
- Outlet ORM automatically detects AI agent invocations and blocks destructive operations without explicit user consent.
108
-
109
- ### Detected Agents
110
-
111
- - **Cursor** (CURSOR_TRACE_ID, CURSOR_SESSION_ID)
112
- - **Claude Code** (CLAUDE_CODE)
113
- - **GitHub Copilot** (COPILOT_AGENT_MODE)
114
- - **Windsurf** (WINDSURF_SESSION_ID, CODEIUM_SESSION)
115
- - **Gemini CLI** (GEMINI_API_KEY + process title)
116
- - **Aider** (AIDER_SESSION)
117
- - **Replit** (REPLIT_DB_URL, REPLIT_AI_ENABLED)
118
- - **Qwen Code** (QWEN_SESSION)
119
- - **MCP Clients** (MCP_SERVER_NAME, MCP_SESSION_ID)
120
-
121
- ### Destructive Commands
122
-
123
- These commands are blocked when an AI agent is detected without consent:
124
- `reset`, `fresh`, `migrate:reset`, `migrate:fresh`, `drop`, `truncate`, `restore`
125
-
126
- ### Consent Mechanism
127
-
128
- To allow a destructive operation, the AI agent must either:
129
-
130
- 1. **Set the environment variable:**
131
- ```bash
132
- OUTLET_USER_CONSENT_FOR_DANGEROUS_AI_ACTION="User confirmed: reset dev database"
133
- ```
134
-
135
- 2. **Pass the `consent` flag** in MCP tool arguments:
136
- ```json
137
- { "consent": "User explicitly approved resetting the development database" }
138
- ```
139
-
140
- ### Programmatic Usage
141
-
142
- ```javascript
143
- const { AISafetyGuardrails } = require('outlet-orm');
144
-
145
- // Detect if running under an AI agent
146
- const { detected, agentName } = AISafetyGuardrails.detectAgent();
147
- console.log(detected, agentName); // true, 'GitHub Copilot'
148
-
149
- // Validate a destructive action
150
- const result = AISafetyGuardrails.validateDestructiveAction('reset', { consent: 'User approved' });
151
- console.log(result.allowed); // true
152
- ```
153
-
154
- ---
155
-
156
- ## Prompt-based Initialization
157
-
158
- Generate an entire project from a natural language description.
159
-
160
- ### CLI Usage
161
-
162
- ```bash
163
- outlet-init --prompt "Create a blog application with posts, comments, and tags"
164
- outlet-init --prompt "E-commerce store with products, orders, and payments" --driver sqlite
165
- ```
166
-
167
- ### Supported Domains
168
-
169
- | Domain | Keywords | Generated Tables |
170
- |--------|----------|-----------------|
171
- | **E-commerce** | shop, store, product, cart, order, payment | users, products, categories, orders, order_items, payments |
172
- | **Blog/CMS** | blog, article, post, cms, comment, tag | users, posts, categories, tags, post_tag, comments |
173
- | **Task/Project** | task, project, todo, kanban, sprint | users, projects, tasks, labels, task_label |
174
- | **Social Network** | social, friend, follow, like, feed, message | users, posts, comments, likes, follows, messages |
175
- | **SaaS** | saas, tenant, subscription, plan, billing | organizations, users, plans, subscriptions, invoices |
176
- | **Habit Tracker** | habit, tracker, health, fitness, goal | users, habits, logs, goals |
177
- | **API/Auth** | api, auth, rest, user | users, tokens, password_resets |
178
-
179
- ### Programmatic Usage
180
-
181
- ```javascript
182
- const { PromptGenerator } = require('outlet-orm');
183
-
184
- // Parse a prompt
185
- const blueprint = PromptGenerator.parse('Create a blog with comments and tags');
186
- console.log(blueprint.domain); // 'blog'
187
- console.log(blueprint.tables); // { users: {...}, posts: {...}, ... }
188
-
189
- // Generate models
190
- const modelFiles = PromptGenerator.generateModels(blueprint, './models');
191
-
192
- // Generate migrations
193
- const migrationFiles = PromptGenerator.generateMigrations(blueprint, './database/migrations');
194
-
195
- // Generate seeder
196
- const seederFile = PromptGenerator.generateSeeder(blueprint, './database/seeds');
197
- ```
198
-
199
- ---
200
-
201
- ## Best Practices for AI Agents
202
-
203
- 1. **Always introspect first** — Use `schema_introspect` before modifying the database.
204
- 2. **Never bypass safety guardrails** — Always obtain explicit user consent for destructive operations.
205
- 3. **Use migrations, not raw DDL** — Prefer `migrate_make` + `migrate_run` over raw `CREATE TABLE` queries.
206
- 4. **Check migration status** — Use `migrate_status` before running migrations.
207
- 5. **Explain write queries** — When using `query_execute` for writes, explain what the query does to the user.
208
- 6. **Prefer backups before destructive operations** — Use `backup_create` before `migrate_reset`.
209
-
210
- ---
211
-
212
- ## Quick Reference
213
-
214
- ```javascript
215
- const {
216
- MCPServer, // MCP server for AI agents
217
- AISafetyGuardrails, // AI agent detection & safety
218
- PromptGenerator // Natural language project generation
219
- } = require('outlet-orm');
220
- ```
File without changes
File without changes
File without changes
File without changes
File without changes