@basaltkit/ai 0.9.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/LICENSE +21 -0
- package/README.md +122 -0
- package/dist/index.d.ts +789 -0
- package/dist/index.js +2312 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Basalt Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# @basaltkit/ai
|
|
2
|
+
|
|
3
|
+
AI-native developer experience for Basalt. A provider-agnostic engine plus a
|
|
4
|
+
`basalt ai` CLI that **understands the project's stack**, analyzes it, and
|
|
5
|
+
diagnoses issues — following the framework's own conventions instead of inventing
|
|
6
|
+
new ones.
|
|
7
|
+
|
|
8
|
+
> **Status: 0.1 (foundation).** This release ships the provider abstraction and
|
|
9
|
+
> the read-only `ai:analyze` / `ai:doctor` commands. Natural-language planning and
|
|
10
|
+
> scaffolding (`ai:plan`, `ai:make`) build on this foundation in later phases.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @basaltkit/ai
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## CLI
|
|
19
|
+
|
|
20
|
+
Register the commands alongside the generator's, through `@basaltkit/cli`:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { commandsPlugin } from '@basaltkit/cli'
|
|
24
|
+
import { generatorCommands } from '@basaltkit/generator'
|
|
25
|
+
import { aiCommands } from '@basaltkit/ai'
|
|
26
|
+
|
|
27
|
+
commandsPlugin([...generatorCommands(), ...aiCommands()])
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Then:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
basalt ai # overview: detected stack + available commands
|
|
34
|
+
basalt ai:analyze # static analysis report (read-only)
|
|
35
|
+
basalt ai:doctor # diagnostics with suggested fixes (read-only)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
All three are **deterministic and offline** — no API key required. `ai:doctor`
|
|
39
|
+
exits non-zero when it finds an error-severity issue, so you can gate CI on it.
|
|
40
|
+
|
|
41
|
+
### `basalt ai:analyze`
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
Analyzing project...
|
|
45
|
+
|
|
46
|
+
✓ Fastify detected
|
|
47
|
+
✓ Prisma detected
|
|
48
|
+
✓ PostgreSQL detected
|
|
49
|
+
✓ Tenancy enabled
|
|
50
|
+
✓ Authentication enabled
|
|
51
|
+
✓ RBAC enabled
|
|
52
|
+
|
|
53
|
+
Data model (3 models):
|
|
54
|
+
• Tenant
|
|
55
|
+
• Post (tenant-scoped)
|
|
56
|
+
• Invoice
|
|
57
|
+
|
|
58
|
+
Diagnostics: 1 error(s), 2 warning(s), 1 info.
|
|
59
|
+
Run `basalt ai:doctor` for details and fixes.
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### `basalt ai:doctor`
|
|
63
|
+
|
|
64
|
+
Runs a rules engine over the project. Built-in rules include:
|
|
65
|
+
|
|
66
|
+
| id | severity | what it catches |
|
|
67
|
+
| --- | --- | --- |
|
|
68
|
+
| `insecure-app-secret` | error | `APP_SECRET` has a committed default (e.g. `change-me-…`) |
|
|
69
|
+
| `prisma-lazy-boot` | warning | server never `$connect()`s, so a wrong DB fails silently on first request |
|
|
70
|
+
| `fastify-logger-off` | warning | Fastify's logger is off, so 500s never print in the terminal |
|
|
71
|
+
| `tenant-scoping-missing` | warning | tenancy is on but some models lack `tenantId` |
|
|
72
|
+
| `memory-sources-in-use` | info | non-durable `Memory*Source` still wired |
|
|
73
|
+
| `redis-localhost-default` | info | `REDIS_URL` defaults to localhost with a queue/subscriptions backend |
|
|
74
|
+
|
|
75
|
+
## Provider abstraction
|
|
76
|
+
|
|
77
|
+
Vendor-agnostic by design (`AI_PROVIDER`): the agent depends on the `AIProvider`
|
|
78
|
+
interface, never a specific SDK.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { createProvider } from '@basaltkit/ai'
|
|
82
|
+
|
|
83
|
+
const ai = createProvider(process.env) // AI_PROVIDER, AI_MODEL, AI_API_KEY, AI_BASE_URL
|
|
84
|
+
const answer = await ai.generate({ messages: [{ role: 'user', content: 'Hello' }] })
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Wired now: **Anthropic** (default), **Ollama** (local, no key), and **any
|
|
88
|
+
OpenAI-compatible Chat Completions gateway** (`AI_PROVIDER=openai`) — OpenAI,
|
|
89
|
+
LiteLLM, OpenRouter, go4ai, etc. Google is stubbed with a clear error.
|
|
90
|
+
|
|
91
|
+
### OpenAI-compatible gateway
|
|
92
|
+
|
|
93
|
+
Point `AI_BASE_URL` at the gateway's `/v1`; the provider appends
|
|
94
|
+
`/chat/completions` and sends `Authorization: Bearer <AI_API_KEY>`:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
export AI_PROVIDER=openai
|
|
98
|
+
export AI_BASE_URL=https://ai.go4ai.io/v1
|
|
99
|
+
export AI_API_KEY=sk_inf_xxx
|
|
100
|
+
export AI_MODEL=us.anthropic.claude-sonnet-4-5-20250929-v1:0
|
|
101
|
+
|
|
102
|
+
basalt ai:plan "Add a patients module"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Programmatic API
|
|
106
|
+
|
|
107
|
+
Everything the CLI uses is exported, so you can build your own tooling:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { detectProject, analyze, runDoctor } from '@basaltkit/ai'
|
|
111
|
+
|
|
112
|
+
const ctx = detectProject(process.cwd())
|
|
113
|
+
const report = analyze(ctx) // stack, data model, diagnostics
|
|
114
|
+
const findings = runDoctor(ctx) // Diagnostic[], most severe first
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`detectProject` accepts an injectable reader (`memoryReader({...})`) so the whole
|
|
118
|
+
detection layer is testable without touching disk.
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
MIT
|