nttp 1.4.6 → 1.4.9
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/README.md +85 -1
- package/dist/cli/docs.d.ts +9 -0
- package/dist/cli/docs.d.ts.map +1 -0
- package/dist/cli/docs.js +437 -0
- package/dist/cli/docs.js.map +1 -0
- package/dist/cli/setup-ink.d.ts +15 -2
- package/dist/cli/setup-ink.d.ts.map +1 -1
- package/dist/cli/setup-ink.js +21 -3
- package/dist/cli/setup-ink.js.map +1 -1
- package/dist/cli/setup-non-interactive.d.ts +17 -0
- package/dist/cli/setup-non-interactive.d.ts.map +1 -0
- package/dist/cli/setup-non-interactive.js +166 -0
- package/dist/cli/setup-non-interactive.js.map +1 -0
- package/dist/cli.js +18 -2
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,8 @@ npm install nttp
|
|
|
10
10
|
|
|
11
11
|
## Quick Start with CLI (Recommended)
|
|
12
12
|
|
|
13
|
+
### For Humans: Interactive Setup
|
|
14
|
+
|
|
13
15
|
The easiest way to get started is with our **interactive setup wizard** (powered by [Ink](https://github.com/vadimdemedes/ink) for a beautiful CLI experience):
|
|
14
16
|
|
|
15
17
|
```bash
|
|
@@ -23,12 +25,62 @@ This will:
|
|
|
23
25
|
- ✅ Create your `.env` file
|
|
24
26
|
- ✅ Generate example code
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
### For LLM Agents: Non-Interactive Setup
|
|
29
|
+
|
|
30
|
+
Perfect for automation, CI/CD, or LLM agents:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npx nttp setup --non-interactive \
|
|
34
|
+
--database-type=pg \
|
|
35
|
+
--database-url=postgresql://user:pass@localhost:5432/db \
|
|
36
|
+
--llm-provider=anthropic \
|
|
37
|
+
--llm-api-key=sk-ant-... \
|
|
38
|
+
--redis-url=redis://localhost:6379 \
|
|
39
|
+
--enable-l2-cache \
|
|
40
|
+
--embedding-api-key=sk-...
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Minimal example (SQLite + Claude):**
|
|
44
|
+
```bash
|
|
45
|
+
npx nttp setup --non-interactive \
|
|
46
|
+
--database-type=better-sqlite3 \
|
|
47
|
+
--database-path=./data.db \
|
|
48
|
+
--llm-provider=anthropic \
|
|
49
|
+
--llm-api-key=sk-ant-...
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**All available flags:**
|
|
53
|
+
- `--database-type` - Required: `pg`, `mysql2`, `better-sqlite3`, `mssql`
|
|
54
|
+
- `--database-url` - Required (except for SQLite): Connection URL
|
|
55
|
+
- `--database-path` - Required for SQLite: Path to .db file
|
|
56
|
+
- `--llm-provider` - Required: `anthropic`, `openai`, `cohere`, `mistral`, `google`
|
|
57
|
+
- `--llm-model` - Optional: Model name (auto-selected if omitted)
|
|
58
|
+
- `--llm-api-key` - Required: API key for LLM provider
|
|
59
|
+
- `--redis-url` - Optional: Redis URL for L1 cache persistence
|
|
60
|
+
- `--enable-l2-cache` - Optional: Enable semantic caching
|
|
61
|
+
- `--embedding-api-key` - Required if L2 enabled: OpenAI API key
|
|
62
|
+
|
|
63
|
+
### Query Your Database
|
|
27
64
|
|
|
28
65
|
```bash
|
|
29
66
|
npx nttp query "show me 5 users"
|
|
30
67
|
```
|
|
31
68
|
|
|
69
|
+
### Get Documentation (Great for LLM Agents)
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Show all documentation
|
|
73
|
+
npx nttp docs
|
|
74
|
+
|
|
75
|
+
# Search documentation
|
|
76
|
+
npx nttp docs redis
|
|
77
|
+
npx nttp docs "cache configuration"
|
|
78
|
+
npx nttp docs setup
|
|
79
|
+
npx nttp docs --query "semantic cache"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Returns relevant sections instantly - perfect for agents to quickly find information!
|
|
83
|
+
|
|
32
84
|
Or use in your code:
|
|
33
85
|
|
|
34
86
|
```typescript
|
|
@@ -300,6 +352,8 @@ Beautiful interactive setup wizard (powered by Ink) with Vercel-inspired DX:
|
|
|
300
352
|
- Creates `.env` file
|
|
301
353
|
- Generates example code
|
|
302
354
|
|
|
355
|
+
For non-interactive setup (agents/automation), see the section above.
|
|
356
|
+
|
|
303
357
|
### `npx nttp init`
|
|
304
358
|
|
|
305
359
|
Alias for `npx nttp setup`. Quick project initialization.
|
|
@@ -317,6 +371,36 @@ npx nttp query "top 10 customers by revenue" --format json
|
|
|
317
371
|
Options:
|
|
318
372
|
- `--format <type>` - Output format: `table` (default) or `json`
|
|
319
373
|
|
|
374
|
+
### `npx nttp docs [query]`
|
|
375
|
+
|
|
376
|
+
Show documentation or search for specific topics (perfect for LLM agents):
|
|
377
|
+
|
|
378
|
+
```bash
|
|
379
|
+
# Show all documentation
|
|
380
|
+
npx nttp docs
|
|
381
|
+
|
|
382
|
+
# Search for specific topics
|
|
383
|
+
npx nttp docs redis # Find Redis-related docs
|
|
384
|
+
npx nttp docs cache # Find cache documentation
|
|
385
|
+
npx nttp docs setup # Find setup instructions
|
|
386
|
+
npx nttp docs "l2 semantic" # Multi-word search
|
|
387
|
+
npx nttp docs --query "api key" # Alternative syntax
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
**Searchable Topics:**
|
|
391
|
+
- `setup` - Setup command and configuration
|
|
392
|
+
- `cache` - 3-layer cache system (L1, L2, L3)
|
|
393
|
+
- `redis` - Redis persistence configuration
|
|
394
|
+
- `query` - Query command and examples
|
|
395
|
+
- `api` - Programmatic API usage
|
|
396
|
+
- `databases` - Supported databases
|
|
397
|
+
- `llm` - LLM providers and models
|
|
398
|
+
- `performance` - Performance metrics and optimization
|
|
399
|
+
- `troubleshooting` - Common issues and solutions
|
|
400
|
+
- `examples` - Example natural language queries
|
|
401
|
+
|
|
402
|
+
**Agent-Friendly Output:** Returns only relevant sections with context, making it easy for LLM agents to quickly find information without parsing full documentation files.
|
|
403
|
+
|
|
320
404
|
## Error Handling
|
|
321
405
|
|
|
322
406
|
```typescript
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../../src/cli/docs.ts"],"names":[],"mappings":"AAAA;;GAEG;AAgYH,UAAU,WAAW;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,IAAI,CAsEvE"}
|
package/dist/cli/docs.js
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Documentation command for LLM agents
|
|
3
|
+
*/
|
|
4
|
+
const DOCS = {
|
|
5
|
+
overview: `
|
|
6
|
+
# NTTP Documentation
|
|
7
|
+
|
|
8
|
+
Natural Text Transfer Protocol - Query databases with natural language.
|
|
9
|
+
|
|
10
|
+
## Quick Start
|
|
11
|
+
|
|
12
|
+
### Interactive Setup (for humans):
|
|
13
|
+
npx nttp setup
|
|
14
|
+
|
|
15
|
+
### Non-Interactive Setup (for agents):
|
|
16
|
+
npx nttp setup --non-interactive \\
|
|
17
|
+
--database-type=pg \\
|
|
18
|
+
--database-url=postgresql://... \\
|
|
19
|
+
--llm-provider=anthropic \\
|
|
20
|
+
--llm-api-key=sk-ant-...
|
|
21
|
+
|
|
22
|
+
### Query Database:
|
|
23
|
+
npx nttp query "show me 5 users"
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
`,
|
|
27
|
+
setup: `
|
|
28
|
+
## Setup Command
|
|
29
|
+
|
|
30
|
+
### Interactive Mode:
|
|
31
|
+
npx nttp setup
|
|
32
|
+
|
|
33
|
+
Guides you through configuration with beautiful UI.
|
|
34
|
+
|
|
35
|
+
### Non-Interactive Mode (for agents/automation):
|
|
36
|
+
npx nttp setup --non-interactive [options]
|
|
37
|
+
|
|
38
|
+
Required Options:
|
|
39
|
+
--database-type <type> pg, mysql2, better-sqlite3, mssql
|
|
40
|
+
--database-url <url> Connection URL (not for SQLite)
|
|
41
|
+
--database-path <path> SQLite database path
|
|
42
|
+
--llm-provider <provider> anthropic, openai, cohere, mistral, google
|
|
43
|
+
--llm-api-key <key> API key for LLM provider
|
|
44
|
+
|
|
45
|
+
Optional Options:
|
|
46
|
+
--llm-model <model> Model name (auto-selected if omitted)
|
|
47
|
+
--redis-url <url> Redis URL for L1 cache persistence
|
|
48
|
+
--enable-l2-cache Enable semantic caching
|
|
49
|
+
--embedding-api-key <key> OpenAI API key (required if --enable-l2-cache)
|
|
50
|
+
|
|
51
|
+
Example:
|
|
52
|
+
npx nttp setup --non-interactive \\
|
|
53
|
+
--database-type=pg \\
|
|
54
|
+
--database-url=postgresql://user:pass@localhost:5432/db \\
|
|
55
|
+
--llm-provider=anthropic \\
|
|
56
|
+
--llm-api-key=sk-ant-...
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
`,
|
|
60
|
+
cache: `
|
|
61
|
+
## Cache System
|
|
62
|
+
|
|
63
|
+
NTTP uses a 3-layer cache for cost optimization:
|
|
64
|
+
|
|
65
|
+
### L1: Exact Match Cache
|
|
66
|
+
- Type: Hash-based lookup
|
|
67
|
+
- Storage: In-memory (default) or Redis (persistent)
|
|
68
|
+
- Cost: $0
|
|
69
|
+
- Latency: <1ms (in-memory) or ~5ms (Redis)
|
|
70
|
+
- Use: Identical queries
|
|
71
|
+
|
|
72
|
+
### L2: Semantic Match Cache
|
|
73
|
+
- Type: Embedding-based similarity
|
|
74
|
+
- Storage: In-memory
|
|
75
|
+
- Cost: ~$0.0001 per query
|
|
76
|
+
- Latency: 50-100ms
|
|
77
|
+
- Use: Similar phrasing (e.g., "get users" vs "show users")
|
|
78
|
+
- Threshold: 0.85 similarity (configurable)
|
|
79
|
+
|
|
80
|
+
### L3: LLM Generation
|
|
81
|
+
- Type: Full intent parsing + SQL generation
|
|
82
|
+
- Provider: Claude, GPT-4, etc.
|
|
83
|
+
- Cost: ~$0.01 per query
|
|
84
|
+
- Latency: 2-3s
|
|
85
|
+
- Use: Novel queries
|
|
86
|
+
|
|
87
|
+
### Cache Persistence with Redis
|
|
88
|
+
|
|
89
|
+
Enable Redis for L1 cache to persist across CLI invocations:
|
|
90
|
+
|
|
91
|
+
Environment Variable:
|
|
92
|
+
REDIS_URL=redis://localhost:6379
|
|
93
|
+
|
|
94
|
+
Non-Interactive Setup:
|
|
95
|
+
npx nttp setup --non-interactive \\
|
|
96
|
+
--redis-url=redis://localhost:6379 \\
|
|
97
|
+
[other options...]
|
|
98
|
+
|
|
99
|
+
Configuration (programmatic):
|
|
100
|
+
const nttp = new NTTP({
|
|
101
|
+
cache: {
|
|
102
|
+
redis: {
|
|
103
|
+
url: 'redis://localhost:6379'
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
Benefits:
|
|
109
|
+
- Cache persists across CLI invocations
|
|
110
|
+
- Shared cache in multi-instance deployments
|
|
111
|
+
- Reduced cold-start latency
|
|
112
|
+
- 24-hour TTL for cached entries
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
`,
|
|
116
|
+
query: `
|
|
117
|
+
## Query Command
|
|
118
|
+
|
|
119
|
+
Execute natural language queries:
|
|
120
|
+
|
|
121
|
+
npx nttp query "your question here"
|
|
122
|
+
|
|
123
|
+
Options:
|
|
124
|
+
-f, --format <type> Output format: table (default) or json
|
|
125
|
+
|
|
126
|
+
Examples:
|
|
127
|
+
npx nttp query "show me 5 users"
|
|
128
|
+
npx nttp query "count active orders"
|
|
129
|
+
npx nttp query "top 10 products by price" --format json
|
|
130
|
+
|
|
131
|
+
Query Patterns:
|
|
132
|
+
- Simple: "show me users"
|
|
133
|
+
- Filtered: "active users from California"
|
|
134
|
+
- Sorted: "top 10 products by price"
|
|
135
|
+
- Aggregated: "count orders by status"
|
|
136
|
+
- Complex: "users who joined this year with orders"
|
|
137
|
+
|
|
138
|
+
Output:
|
|
139
|
+
- SQL: Generated SQL query
|
|
140
|
+
- Cache: HIT or MISS (which layer)
|
|
141
|
+
- Data: Query results
|
|
142
|
+
- Time: Execution time in ms
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
`,
|
|
146
|
+
api: `
|
|
147
|
+
## Programmatic API
|
|
148
|
+
|
|
149
|
+
### From Environment (.env)
|
|
150
|
+
|
|
151
|
+
import { NTTP } from 'nttp';
|
|
152
|
+
|
|
153
|
+
const nttp = await NTTP.fromEnv();
|
|
154
|
+
const result = await nttp.query("show me users");
|
|
155
|
+
await nttp.close();
|
|
156
|
+
|
|
157
|
+
Requires .env file:
|
|
158
|
+
DATABASE_URL=postgresql://...
|
|
159
|
+
DATABASE_TYPE=pg
|
|
160
|
+
LLM_PROVIDER=anthropic
|
|
161
|
+
LLM_MODEL=claude-sonnet-4-5-20250929
|
|
162
|
+
ANTHROPIC_API_KEY=sk-ant-...
|
|
163
|
+
REDIS_URL=redis://localhost:6379 # Optional
|
|
164
|
+
|
|
165
|
+
### Manual Configuration
|
|
166
|
+
|
|
167
|
+
import { NTTP } from 'nttp';
|
|
168
|
+
|
|
169
|
+
const nttp = new NTTP({
|
|
170
|
+
database: {
|
|
171
|
+
client: 'pg',
|
|
172
|
+
connection: process.env.DATABASE_URL
|
|
173
|
+
},
|
|
174
|
+
llm: {
|
|
175
|
+
provider: 'anthropic',
|
|
176
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
177
|
+
apiKey: process.env.ANTHROPIC_API_KEY
|
|
178
|
+
},
|
|
179
|
+
cache: {
|
|
180
|
+
redis: {
|
|
181
|
+
url: 'redis://localhost:6379'
|
|
182
|
+
},
|
|
183
|
+
l2: {
|
|
184
|
+
provider: 'openai',
|
|
185
|
+
model: 'text-embedding-3-small',
|
|
186
|
+
apiKey: process.env.OPENAI_API_KEY
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
await nttp.init();
|
|
192
|
+
const result = await nttp.query("your question");
|
|
193
|
+
await nttp.close();
|
|
194
|
+
|
|
195
|
+
### Query Result
|
|
196
|
+
|
|
197
|
+
{
|
|
198
|
+
query: string, // Original natural language query
|
|
199
|
+
data: any[], // Query results
|
|
200
|
+
sql: string, // Generated SQL
|
|
201
|
+
params: any[], // SQL parameters
|
|
202
|
+
schemaId: string, // Cache key
|
|
203
|
+
cacheHit: boolean, // Was query cached?
|
|
204
|
+
executionTimeMs: number, // Execution time
|
|
205
|
+
intent: Intent, // Parsed intent
|
|
206
|
+
meta?: { // Cache metadata
|
|
207
|
+
cacheLayer: 1 | 2 | 3,
|
|
208
|
+
cost: number,
|
|
209
|
+
latency: number,
|
|
210
|
+
similarity?: number // For L2 hits
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
`,
|
|
216
|
+
databases: `
|
|
217
|
+
## Supported Databases
|
|
218
|
+
|
|
219
|
+
### PostgreSQL
|
|
220
|
+
Type: pg
|
|
221
|
+
Connection: postgresql://user:pass@host:port/database
|
|
222
|
+
Recommended for: Production
|
|
223
|
+
|
|
224
|
+
### MySQL
|
|
225
|
+
Type: mysql2
|
|
226
|
+
Connection: mysql://user:pass@host:port/database
|
|
227
|
+
Recommended for: Web applications
|
|
228
|
+
|
|
229
|
+
### SQLite
|
|
230
|
+
Type: better-sqlite3
|
|
231
|
+
Connection: Path to .db file
|
|
232
|
+
Recommended for: Development, testing
|
|
233
|
+
|
|
234
|
+
### SQL Server
|
|
235
|
+
Type: mssql
|
|
236
|
+
Connection: Server=host;Database=db;User Id=user;Password=pass
|
|
237
|
+
Recommended for: Enterprise applications
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
`,
|
|
241
|
+
llm: `
|
|
242
|
+
## LLM Providers
|
|
243
|
+
|
|
244
|
+
### Anthropic (Claude)
|
|
245
|
+
Provider: anthropic
|
|
246
|
+
Models: claude-sonnet-4-5-20250929, claude-opus-4-5, claude-haiku-4
|
|
247
|
+
API Key: ANTHROPIC_API_KEY
|
|
248
|
+
Best for: Highest quality SQL generation
|
|
249
|
+
|
|
250
|
+
### OpenAI (GPT)
|
|
251
|
+
Provider: openai
|
|
252
|
+
Models: gpt-4o, gpt-4-turbo, gpt-3.5-turbo
|
|
253
|
+
API Key: OPENAI_API_KEY
|
|
254
|
+
Best for: Fast and reliable
|
|
255
|
+
|
|
256
|
+
### Cohere
|
|
257
|
+
Provider: cohere
|
|
258
|
+
Models: command-r-plus, command-r
|
|
259
|
+
API Key: COHERE_API_KEY
|
|
260
|
+
Best for: Enterprise deployments
|
|
261
|
+
|
|
262
|
+
### Mistral
|
|
263
|
+
Provider: mistral
|
|
264
|
+
Models: mistral-large-latest, mistral-medium
|
|
265
|
+
API Key: MISTRAL_API_KEY
|
|
266
|
+
Best for: Open-source preference
|
|
267
|
+
|
|
268
|
+
### Google (Gemini)
|
|
269
|
+
Provider: google
|
|
270
|
+
Models: gemini-pro, gemini-ultra
|
|
271
|
+
API Key: GOOGLE_API_KEY
|
|
272
|
+
Best for: Multimodal capabilities
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
`,
|
|
276
|
+
performance: `
|
|
277
|
+
## Performance Metrics
|
|
278
|
+
|
|
279
|
+
### Cache Performance
|
|
280
|
+
L1 (In-Memory): <1ms latency, $0 cost
|
|
281
|
+
L1 (Redis): ~5ms latency, $0 cost
|
|
282
|
+
L2 (Semantic): 50-100ms latency, ~$0.0001 cost
|
|
283
|
+
L3 (LLM): 2-3s latency, ~$0.01 cost
|
|
284
|
+
|
|
285
|
+
### Cost Savings
|
|
286
|
+
Without caching: 1000 queries × $0.01 = $10.00
|
|
287
|
+
With caching: ~$1.00 (90% savings after warmup)
|
|
288
|
+
|
|
289
|
+
### Hit Rates (typical after warmup)
|
|
290
|
+
L1: 60-70% of queries
|
|
291
|
+
L2: 20-30% of queries
|
|
292
|
+
L3: 5-10% of queries
|
|
293
|
+
|
|
294
|
+
### Throughput
|
|
295
|
+
Cached queries: >10,000 req/s
|
|
296
|
+
LLM queries: Limited by API rate limits
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
`,
|
|
300
|
+
troubleshooting: `
|
|
301
|
+
## Troubleshooting
|
|
302
|
+
|
|
303
|
+
### Setup Issues
|
|
304
|
+
|
|
305
|
+
Q: "Cannot find package 'nttp'"
|
|
306
|
+
A: Run: npm install nttp dotenv
|
|
307
|
+
|
|
308
|
+
Q: "Cannot find package 'dotenv'"
|
|
309
|
+
A: Run: npm install dotenv
|
|
310
|
+
|
|
311
|
+
Q: Setup fails to install dependencies
|
|
312
|
+
A: Manually run: npm install nttp dotenv
|
|
313
|
+
|
|
314
|
+
### Query Issues
|
|
315
|
+
|
|
316
|
+
Q: Query returns empty results
|
|
317
|
+
A: Check database connection and schema
|
|
318
|
+
Verify query makes sense for your data
|
|
319
|
+
|
|
320
|
+
Q: "SQL generation failed"
|
|
321
|
+
A: Check LLM API key is valid
|
|
322
|
+
Ensure LLM provider is correctly configured
|
|
323
|
+
Try simpler query first
|
|
324
|
+
|
|
325
|
+
Q: Cache always shows MISS
|
|
326
|
+
A: First query is always MISS (populates cache)
|
|
327
|
+
Check Redis connection if using Redis
|
|
328
|
+
Verify REDIS_URL is correct
|
|
329
|
+
|
|
330
|
+
### Connection Issues
|
|
331
|
+
|
|
332
|
+
Q: "Database connection failed"
|
|
333
|
+
A: Verify DATABASE_URL is correct
|
|
334
|
+
Check database server is running
|
|
335
|
+
Confirm network access to database
|
|
336
|
+
|
|
337
|
+
Q: "Redis connection failed"
|
|
338
|
+
A: Verify Redis server is running
|
|
339
|
+
Check REDIS_URL format: redis://host:port
|
|
340
|
+
Confirm network access to Redis
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
`,
|
|
344
|
+
examples: `
|
|
345
|
+
## Example Queries
|
|
346
|
+
|
|
347
|
+
### Simple Queries
|
|
348
|
+
"show me all users"
|
|
349
|
+
"get all products"
|
|
350
|
+
"list recent orders"
|
|
351
|
+
|
|
352
|
+
### Filtered Queries
|
|
353
|
+
"active users from California"
|
|
354
|
+
"products under $50"
|
|
355
|
+
"orders from last 30 days"
|
|
356
|
+
"pending orders"
|
|
357
|
+
|
|
358
|
+
### Sorting and Limits
|
|
359
|
+
"top 10 most expensive products"
|
|
360
|
+
"newest 20 users"
|
|
361
|
+
"5 most recent orders"
|
|
362
|
+
|
|
363
|
+
### Aggregations
|
|
364
|
+
"count users by status"
|
|
365
|
+
"total revenue by category"
|
|
366
|
+
"average order value"
|
|
367
|
+
|
|
368
|
+
### Complex Queries
|
|
369
|
+
"show users with their order count"
|
|
370
|
+
"products with average rating above 4"
|
|
371
|
+
"top customers by total spent"
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
`,
|
|
375
|
+
};
|
|
376
|
+
export function runDocs(query, options = {}) {
|
|
377
|
+
const searchQuery = query || options.query;
|
|
378
|
+
if (!searchQuery) {
|
|
379
|
+
// Show all documentation
|
|
380
|
+
console.log('📚 NTTP Documentation\n');
|
|
381
|
+
console.log('='.repeat(60));
|
|
382
|
+
Object.values(DOCS).forEach(section => {
|
|
383
|
+
console.log(section);
|
|
384
|
+
});
|
|
385
|
+
console.log('='.repeat(60));
|
|
386
|
+
console.log('\nSearch docs: npx nttp docs <query>');
|
|
387
|
+
console.log('Examples:');
|
|
388
|
+
console.log(' npx nttp docs redis');
|
|
389
|
+
console.log(' npx nttp docs "cache configuration"');
|
|
390
|
+
console.log(' npx nttp docs setup');
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
// Search/grep through documentation
|
|
394
|
+
const searchTerm = searchQuery.toLowerCase();
|
|
395
|
+
const results = [];
|
|
396
|
+
Object.entries(DOCS).forEach(([section, content]) => {
|
|
397
|
+
const lines = content.split('\n');
|
|
398
|
+
const matchingLines = [];
|
|
399
|
+
lines.forEach((line, index) => {
|
|
400
|
+
if (line.toLowerCase().includes(searchTerm)) {
|
|
401
|
+
// Include context: 2 lines before and after
|
|
402
|
+
const start = Math.max(0, index - 2);
|
|
403
|
+
const end = Math.min(lines.length, index + 3);
|
|
404
|
+
const context = lines.slice(start, end).join('\n');
|
|
405
|
+
matchingLines.push(context);
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
if (matchingLines.length > 0) {
|
|
409
|
+
results.push({
|
|
410
|
+
section,
|
|
411
|
+
content,
|
|
412
|
+
matches: matchingLines,
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
if (results.length === 0) {
|
|
417
|
+
console.log(`❌ No results found for: "${searchQuery}"\n`);
|
|
418
|
+
console.log('💡 Try searching for:');
|
|
419
|
+
console.log(' - setup, query, cache, redis, database, llm, api, examples');
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
console.log(`🔍 Search results for: "${searchQuery}"\n`);
|
|
423
|
+
console.log('='.repeat(60));
|
|
424
|
+
results.forEach(({ section, matches }) => {
|
|
425
|
+
console.log(`\n## ${section.toUpperCase()}\n`);
|
|
426
|
+
// Show unique matches (deduplicate overlapping contexts)
|
|
427
|
+
const uniqueMatches = [...new Set(matches)];
|
|
428
|
+
uniqueMatches.forEach(match => {
|
|
429
|
+
console.log(match);
|
|
430
|
+
console.log('---');
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
console.log('='.repeat(60));
|
|
434
|
+
console.log(`\nFound ${results.length} section(s) with "${searchQuery}"`);
|
|
435
|
+
console.log('\nShow all docs: npx nttp docs');
|
|
436
|
+
}
|
|
437
|
+
//# sourceMappingURL=docs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs.js","sourceRoot":"","sources":["../../src/cli/docs.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,IAAI,GAAG;IACX,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;CAqBX;IAEC,KAAK,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCR;IAEC,KAAK,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuDR;IAEC,KAAK,EAAE;;;;;;;;;;;;;;;;;;;;;;;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CAAC;QACrC,OAAO,CAAC,GAAG,CAAC,8DAA8D,CAAC,CAAC;QAC5E,OAAO;IACT,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,2BAA2B,WAAW,KAAK,CAAC,CAAC;IACzD,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAE5B,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;QACvC,OAAO,CAAC,GAAG,CAAC,QAAQ,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QAE/C,yDAAyD;QACzD,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;QAC5C,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YAC5B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACnB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5B,OAAO,CAAC,GAAG,CAAC,WAAW,OAAO,CAAC,MAAM,qBAAqB,WAAW,GAAG,CAAC,CAAC;IAC1E,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;AAChD,CAAC"}
|
package/dist/cli/setup-ink.d.ts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Setup
|
|
2
|
+
* Setup using Ink (interactive) or CLI (non-interactive)
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
interface SetupOptions {
|
|
5
|
+
nonInteractive?: boolean;
|
|
6
|
+
databaseType?: string;
|
|
7
|
+
databaseUrl?: string;
|
|
8
|
+
databasePath?: string;
|
|
9
|
+
llmProvider?: string;
|
|
10
|
+
llmModel?: string;
|
|
11
|
+
llmApiKey?: string;
|
|
12
|
+
redisUrl?: string;
|
|
13
|
+
enableL2Cache?: boolean;
|
|
14
|
+
embeddingApiKey?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function runSetup(options?: SetupOptions): Promise<void>;
|
|
17
|
+
export {};
|
|
5
18
|
//# sourceMappingURL=setup-ink.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-ink.d.ts","sourceRoot":"","sources":["../../src/cli/setup-ink.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"setup-ink.d.ts","sourceRoot":"","sources":["../../src/cli/setup-ink.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,UAAU,YAAY;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAsB,QAAQ,CAAC,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBxE"}
|
package/dist/cli/setup-ink.js
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Setup
|
|
2
|
+
* Setup using Ink (interactive) or CLI (non-interactive)
|
|
3
3
|
*/
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { render } from 'ink';
|
|
6
6
|
import SetupWizard from './SetupWizard.js';
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import { runNonInteractiveSetup } from './setup-non-interactive.js';
|
|
8
|
+
export async function runSetup(options = {}) {
|
|
9
|
+
// Check if running in non-interactive mode
|
|
10
|
+
if (options.nonInteractive) {
|
|
11
|
+
runNonInteractiveSetup({
|
|
12
|
+
databaseType: options.databaseType,
|
|
13
|
+
databaseUrl: options.databaseUrl,
|
|
14
|
+
databasePath: options.databasePath,
|
|
15
|
+
llmProvider: options.llmProvider,
|
|
16
|
+
llmModel: options.llmModel,
|
|
17
|
+
llmApiKey: options.llmApiKey,
|
|
18
|
+
redisUrl: options.redisUrl,
|
|
19
|
+
enableL2Cache: options.enableL2Cache,
|
|
20
|
+
embeddingApiKey: options.embeddingApiKey,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
// Run interactive Ink wizard
|
|
25
|
+
render(React.createElement(SetupWizard));
|
|
26
|
+
}
|
|
9
27
|
}
|
|
10
28
|
//# sourceMappingURL=setup-ink.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-ink.js","sourceRoot":"","sources":["../../src/cli/setup-ink.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,WAAW,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"setup-ink.js","sourceRoot":"","sources":["../../src/cli/setup-ink.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAepE,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,UAAwB,EAAE;IACvD,2CAA2C;IAC3C,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;QAC3B,sBAAsB,CAAC;YACrB,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,eAAe,EAAE,OAAO,CAAC,eAAe;SACzC,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,6BAA6B;QAC7B,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Non-interactive setup for LLM agents and automation
|
|
3
|
+
*/
|
|
4
|
+
interface NonInteractiveConfig {
|
|
5
|
+
databaseType?: string;
|
|
6
|
+
databaseUrl?: string;
|
|
7
|
+
databasePath?: string;
|
|
8
|
+
llmProvider?: string;
|
|
9
|
+
llmModel?: string;
|
|
10
|
+
llmApiKey?: string;
|
|
11
|
+
redisUrl?: string;
|
|
12
|
+
enableL2Cache?: boolean;
|
|
13
|
+
embeddingApiKey?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function runNonInteractiveSetup(options: NonInteractiveConfig): void;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=setup-non-interactive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-non-interactive.d.ts","sourceRoot":"","sources":["../../src/cli/setup-non-interactive.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,UAAU,oBAAoB;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAUD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CA2K1E"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Non-interactive setup for LLM agents and automation
|
|
3
|
+
*/
|
|
4
|
+
import { writeFileSync, existsSync } from 'fs';
|
|
5
|
+
import { execSync } from 'child_process';
|
|
6
|
+
const LLM_MODELS = {
|
|
7
|
+
anthropic: 'claude-sonnet-4-5-20250929',
|
|
8
|
+
openai: 'gpt-4o',
|
|
9
|
+
cohere: 'command-r-plus',
|
|
10
|
+
mistral: 'mistral-large-latest',
|
|
11
|
+
google: 'gemini-pro',
|
|
12
|
+
};
|
|
13
|
+
export function runNonInteractiveSetup(options) {
|
|
14
|
+
console.log('🤖 Running non-interactive setup...\n');
|
|
15
|
+
// Validate required options
|
|
16
|
+
const errors = [];
|
|
17
|
+
if (!options.databaseType) {
|
|
18
|
+
errors.push('--database-type is required (pg, mysql2, better-sqlite3, mssql)');
|
|
19
|
+
}
|
|
20
|
+
if (options.databaseType === 'better-sqlite3') {
|
|
21
|
+
if (!options.databasePath) {
|
|
22
|
+
errors.push('--database-path is required for SQLite');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
if (!options.databaseUrl) {
|
|
27
|
+
errors.push('--database-url is required');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!options.llmProvider) {
|
|
31
|
+
errors.push('--llm-provider is required (anthropic, openai, cohere, mistral, google)');
|
|
32
|
+
}
|
|
33
|
+
if (!options.llmApiKey) {
|
|
34
|
+
errors.push('--llm-api-key is required');
|
|
35
|
+
}
|
|
36
|
+
if (options.enableL2Cache && !options.embeddingApiKey) {
|
|
37
|
+
errors.push('--embedding-api-key is required when --enable-l2-cache is set');
|
|
38
|
+
}
|
|
39
|
+
if (errors.length > 0) {
|
|
40
|
+
console.error('❌ Configuration errors:\n');
|
|
41
|
+
errors.forEach(err => console.error(` • ${err}`));
|
|
42
|
+
console.error('\n💡 Example usage:');
|
|
43
|
+
console.error(' npx nttp setup --non-interactive \\');
|
|
44
|
+
console.error(' --database-type=pg \\');
|
|
45
|
+
console.error(' --database-url=postgresql://user:pass@localhost/db \\');
|
|
46
|
+
console.error(' --llm-provider=anthropic \\');
|
|
47
|
+
console.error(' --llm-api-key=sk-ant-... \\');
|
|
48
|
+
console.error(' --redis-url=redis://localhost:6379 \\');
|
|
49
|
+
console.error(' --enable-l2-cache \\');
|
|
50
|
+
console.error(' --embedding-api-key=sk-...');
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
// Auto-fill model if not provided
|
|
54
|
+
const llmModel = options.llmModel || LLM_MODELS[options.llmProvider];
|
|
55
|
+
console.log('✓ Configuration validated');
|
|
56
|
+
console.log('✓ Creating .env file...');
|
|
57
|
+
// Generate .env file
|
|
58
|
+
const envLines = [
|
|
59
|
+
'# nttp configuration',
|
|
60
|
+
'# Generated by nttp setup --non-interactive',
|
|
61
|
+
'',
|
|
62
|
+
'# Database',
|
|
63
|
+
];
|
|
64
|
+
if (options.databaseType === 'better-sqlite3') {
|
|
65
|
+
envLines.push(`DATABASE_PATH=${options.databasePath}`);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
envLines.push(`DATABASE_URL=${options.databaseUrl}`);
|
|
69
|
+
}
|
|
70
|
+
envLines.push(`DATABASE_TYPE=${options.databaseType}`);
|
|
71
|
+
envLines.push('');
|
|
72
|
+
envLines.push('# LLM Provider');
|
|
73
|
+
envLines.push(`LLM_PROVIDER=${options.llmProvider}`);
|
|
74
|
+
envLines.push(`LLM_MODEL=${llmModel}`);
|
|
75
|
+
const envKeys = {
|
|
76
|
+
anthropic: 'ANTHROPIC_API_KEY',
|
|
77
|
+
openai: 'OPENAI_API_KEY',
|
|
78
|
+
cohere: 'COHERE_API_KEY',
|
|
79
|
+
mistral: 'MISTRAL_API_KEY',
|
|
80
|
+
google: 'GOOGLE_API_KEY',
|
|
81
|
+
};
|
|
82
|
+
envLines.push(`${envKeys[options.llmProvider]}=${options.llmApiKey}`);
|
|
83
|
+
if (options.redisUrl) {
|
|
84
|
+
envLines.push('');
|
|
85
|
+
envLines.push('# Redis Cache');
|
|
86
|
+
envLines.push(`REDIS_URL=${options.redisUrl}`);
|
|
87
|
+
}
|
|
88
|
+
if (options.enableL2Cache) {
|
|
89
|
+
envLines.push('');
|
|
90
|
+
envLines.push('# Semantic Cache');
|
|
91
|
+
envLines.push('EMBEDDING_PROVIDER=openai');
|
|
92
|
+
envLines.push(`OPENAI_API_KEY=${options.embeddingApiKey}`);
|
|
93
|
+
}
|
|
94
|
+
writeFileSync('.env', envLines.join('\n') + '\n');
|
|
95
|
+
console.log('✓ .env created');
|
|
96
|
+
// Generate example code
|
|
97
|
+
console.log('✓ Creating nttp-example.js...');
|
|
98
|
+
const code = `/**
|
|
99
|
+
* NTTP Example - Ready to run!
|
|
100
|
+
* Run: node nttp-example.js or npm start
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
import 'dotenv/config';
|
|
104
|
+
import { NTTP } from 'nttp';
|
|
105
|
+
|
|
106
|
+
async function main() {
|
|
107
|
+
// Load configuration from .env
|
|
108
|
+
const nttp = await NTTP.fromEnv();
|
|
109
|
+
|
|
110
|
+
console.log('✓ Connected to database');
|
|
111
|
+
|
|
112
|
+
// Run a natural language query
|
|
113
|
+
const result = await nttp.query('show me 5 records');
|
|
114
|
+
|
|
115
|
+
console.log(\`\\n✓ Query succeeded! Got \${result.data.length} rows\`);
|
|
116
|
+
console.log(\` Generated SQL: \${result.sql}\`);
|
|
117
|
+
console.log(\` Cache hit: \${result.cacheHit}\`);
|
|
118
|
+
console.log(\` Time: \${result.executionTimeMs}ms\\n\`);
|
|
119
|
+
|
|
120
|
+
// Display results
|
|
121
|
+
console.table(result.data);
|
|
122
|
+
|
|
123
|
+
// Cleanup
|
|
124
|
+
await nttp.close();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
main().catch(console.error);
|
|
128
|
+
`;
|
|
129
|
+
writeFileSync('nttp-example.js', code);
|
|
130
|
+
console.log('✓ nttp-example.js created');
|
|
131
|
+
// Create package.json if it doesn't exist
|
|
132
|
+
if (!existsSync('package.json')) {
|
|
133
|
+
console.log('✓ Creating package.json...');
|
|
134
|
+
const packageJson = {
|
|
135
|
+
name: 'nttp-project',
|
|
136
|
+
version: '1.0.0',
|
|
137
|
+
type: 'module',
|
|
138
|
+
scripts: {
|
|
139
|
+
start: 'node nttp-example.js'
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
writeFileSync('package.json', JSON.stringify(packageJson, null, 2));
|
|
143
|
+
console.log('✓ package.json created');
|
|
144
|
+
}
|
|
145
|
+
// Install dependencies
|
|
146
|
+
console.log('✓ Installing dependencies (nttp, dotenv)...');
|
|
147
|
+
try {
|
|
148
|
+
execSync('npm install nttp dotenv', { stdio: 'inherit' });
|
|
149
|
+
console.log('✓ Dependencies installed');
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
console.error('⚠ Failed to install dependencies. Please run: npm install nttp dotenv');
|
|
153
|
+
}
|
|
154
|
+
// Success message
|
|
155
|
+
console.log('\n✅ Setup complete!\n');
|
|
156
|
+
console.log('Created:');
|
|
157
|
+
console.log(' • .env (your configuration)');
|
|
158
|
+
console.log(' • nttp-example.js (example code)');
|
|
159
|
+
console.log(' • package.json (if not exists)');
|
|
160
|
+
console.log(' • node_modules/ (installed nttp, dotenv)\n');
|
|
161
|
+
console.log('Next steps:');
|
|
162
|
+
console.log(' 1. Try CLI: npx nttp query "show me 5 records"');
|
|
163
|
+
console.log(' 2. Or run code: node nttp-example.js');
|
|
164
|
+
console.log(' 3. Or use in your code: npm start\n');
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=setup-non-interactive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-non-interactive.js","sourceRoot":"","sources":["../../src/cli/setup-non-interactive.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAczC,MAAM,UAAU,GAA2B;IACzC,SAAS,EAAE,4BAA4B;IACvC,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,gBAAgB;IACxB,OAAO,EAAE,sBAAsB;IAC/B,MAAM,EAAE,YAAY;CACrB,CAAC;AAEF,MAAM,UAAU,sBAAsB,CAAC,OAA6B;IAClE,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;IAErD,4BAA4B;IAC5B,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;QAC1B,MAAM,CAAC,IAAI,CAAC,iEAAiE,CAAC,CAAC;IACjF,CAAC;IAED,IAAI,OAAO,CAAC,YAAY,KAAK,gBAAgB,EAAE,CAAC;QAC9C,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;YAC1B,MAAM,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;YACzB,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QACzB,MAAM,CAAC,IAAI,CAAC,yEAAyE,CAAC,CAAC;IACzF,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QACvB,MAAM,CAAC,IAAI,CAAC,2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E,CAAC,CAAC;IACzF,CAAC;IAED,kBAAkB;IAClB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IACrC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;IAClD,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;IAChD,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;IAC5D,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC3B,OAAO,CAAC,GAAG,CAAC,kDAAkD,CAAC,CAAC;IAChE,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;IACtD,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;AACvD,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -6,14 +6,25 @@ import { Command } from 'commander';
|
|
|
6
6
|
import { runSetup } from './cli/setup-ink.js';
|
|
7
7
|
import { runQuery } from './cli/query.js';
|
|
8
8
|
import { runInit } from './cli/init.js';
|
|
9
|
+
import { runDocs } from './cli/docs.js';
|
|
9
10
|
const program = new Command();
|
|
10
11
|
program
|
|
11
12
|
.name('nttp')
|
|
12
13
|
.description('Query databases with natural language')
|
|
13
|
-
.version('1.4.
|
|
14
|
+
.version('1.4.9');
|
|
14
15
|
program
|
|
15
16
|
.command('setup')
|
|
16
|
-
.description('Interactive setup wizard')
|
|
17
|
+
.description('Interactive setup wizard (or use --non-interactive for agents)')
|
|
18
|
+
.option('--non-interactive', 'Run setup without interactive prompts (for agents/automation)')
|
|
19
|
+
.option('--database-type <type>', 'Database type: pg, mysql2, better-sqlite3, mssql')
|
|
20
|
+
.option('--database-url <url>', 'Database connection URL')
|
|
21
|
+
.option('--database-path <path>', 'SQLite database path (for better-sqlite3)')
|
|
22
|
+
.option('--llm-provider <provider>', 'LLM provider: anthropic, openai, cohere, mistral, google')
|
|
23
|
+
.option('--llm-model <model>', 'LLM model name')
|
|
24
|
+
.option('--llm-api-key <key>', 'LLM API key')
|
|
25
|
+
.option('--redis-url <url>', 'Redis URL for L1 cache persistence (optional)')
|
|
26
|
+
.option('--enable-l2-cache', 'Enable L2 semantic cache (optional)')
|
|
27
|
+
.option('--embedding-api-key <key>', 'OpenAI API key for embeddings (required if --enable-l2-cache)')
|
|
17
28
|
.action(runSetup);
|
|
18
29
|
program
|
|
19
30
|
.command('init')
|
|
@@ -24,5 +35,10 @@ program
|
|
|
24
35
|
.description('Execute a natural language query')
|
|
25
36
|
.option('-f, --format <type>', 'Output format (json|table)', 'table')
|
|
26
37
|
.action(runQuery);
|
|
38
|
+
program
|
|
39
|
+
.command('docs [query]')
|
|
40
|
+
.description('Show documentation (optionally search with query)')
|
|
41
|
+
.option('-q, --query <search>', 'Search query for documentation')
|
|
42
|
+
.action(runDocs);
|
|
27
43
|
program.parse();
|
|
28
44
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,MAAM,CAAC;KACZ,WAAW,CAAC,uCAAuC,CAAC;KACpD,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src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