@eldrforge/ai-service 0.1.13 → 0.1.15
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 +1112 -226
- package/dist/index.js +1325 -108
- package/dist/index.js.map +1 -1
- package/dist/src/agentic/commit.d.ts +6 -0
- package/dist/src/agentic/commit.d.ts.map +1 -1
- package/dist/src/agentic/executor.d.ts +7 -1
- package/dist/src/agentic/executor.d.ts.map +1 -1
- package/dist/src/agentic/publish.d.ts +31 -0
- package/dist/src/agentic/publish.d.ts.map +1 -0
- package/dist/src/agentic/release.d.ts +6 -0
- package/dist/src/agentic/release.d.ts.map +1 -1
- package/dist/src/ai.d.ts.map +1 -1
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/observability/conversation-logger.d.ts +53 -0
- package/dist/src/observability/conversation-logger.d.ts.map +1 -0
- package/dist/src/observability/index.d.ts +15 -0
- package/dist/src/observability/index.d.ts.map +1 -0
- package/dist/src/observability/metrics.d.ts +53 -0
- package/dist/src/observability/metrics.d.ts.map +1 -0
- package/dist/src/observability/reflection.d.ts +36 -0
- package/dist/src/observability/reflection.d.ts.map +1 -0
- package/dist/src/prompts/commit.d.ts.map +1 -1
- package/dist/src/prompts/index.d.ts +1 -0
- package/dist/src/prompts/index.d.ts.map +1 -1
- package/dist/src/prompts/release.d.ts.map +1 -1
- package/dist/src/prompts/review.d.ts.map +1 -1
- package/dist/src/prompts/templates.d.ts +22 -0
- package/dist/src/prompts/templates.d.ts.map +1 -0
- package/dist/src/tools/publish-tools.d.ts +6 -0
- package/dist/src/tools/publish-tools.d.ts.map +1 -0
- package/dist/src/tools/types.d.ts +17 -0
- package/dist/src/tools/types.d.ts.map +1 -1
- package/examples/01-simple-commit.ts +80 -0
- package/examples/02-release-notes.ts +124 -0
- package/examples/03-interactive-commit.ts +150 -0
- package/examples/04-custom-storage.ts +162 -0
- package/examples/05-custom-tools.ts +243 -0
- package/examples/README.md +320 -0
- package/package.json +6 -5
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
This directory contains practical examples demonstrating how to use `@eldrforge/ai-service` as a standalone library.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
Before running these examples, ensure you have:
|
|
8
|
+
|
|
9
|
+
1. **Node.js** (v18 or later)
|
|
10
|
+
2. **OpenAI API Key** set as environment variable:
|
|
11
|
+
```bash
|
|
12
|
+
export OPENAI_API_KEY=sk-...
|
|
13
|
+
```
|
|
14
|
+
3. **tsx** for running TypeScript (or compile with `tsc` first):
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g tsx
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Examples Overview
|
|
20
|
+
|
|
21
|
+
### 1. Simple Commit Message Generation
|
|
22
|
+
**File:** `01-simple-commit.ts`
|
|
23
|
+
|
|
24
|
+
The most basic example - generates a commit message from staged git changes.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Stage some changes
|
|
28
|
+
git add .
|
|
29
|
+
|
|
30
|
+
# Run the example
|
|
31
|
+
npx tsx examples/01-simple-commit.ts
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Features:**
|
|
35
|
+
- Reads staged git changes
|
|
36
|
+
- Generates commit message using agentic AI
|
|
37
|
+
- Shows tool usage statistics
|
|
38
|
+
- Suggests commit splits if appropriate
|
|
39
|
+
|
|
40
|
+
**Use Case:** Quick commit message generation without interaction
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
### 2. Release Notes Generation
|
|
45
|
+
**File:** `02-release-notes.ts`
|
|
46
|
+
|
|
47
|
+
Generates comprehensive release notes by analyzing changes between two git references.
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Generate release notes from v1.0.0 to v1.1.0
|
|
51
|
+
npx tsx examples/02-release-notes.ts v1.0.0 v1.1.0
|
|
52
|
+
|
|
53
|
+
# Or from a tag to HEAD
|
|
54
|
+
npx tsx examples/02-release-notes.ts v1.0.0 HEAD
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Features:**
|
|
58
|
+
- Analyzes commit history and diffs
|
|
59
|
+
- Uses 13 specialized tools for deep analysis
|
|
60
|
+
- Generates detailed markdown release notes
|
|
61
|
+
- Saves output to files
|
|
62
|
+
- Shows tool usage metrics
|
|
63
|
+
|
|
64
|
+
**Use Case:** Automated release note generation for GitHub releases, changelogs, etc.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
### 3. Interactive Commit Workflow
|
|
69
|
+
**File:** `03-interactive-commit.ts`
|
|
70
|
+
|
|
71
|
+
An interactive workflow that lets users review, edit, and approve commit messages.
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Stage changes first
|
|
75
|
+
git add .
|
|
76
|
+
|
|
77
|
+
# Run interactive workflow
|
|
78
|
+
npx tsx examples/03-interactive-commit.ts
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**Features:**
|
|
82
|
+
- Generates initial commit message
|
|
83
|
+
- Interactive review loop:
|
|
84
|
+
- **[c]** Confirm and create commit
|
|
85
|
+
- **[e]** Edit in your editor
|
|
86
|
+
- **[s]** Skip and cancel
|
|
87
|
+
- Automatically creates the git commit
|
|
88
|
+
- Full TTY support
|
|
89
|
+
|
|
90
|
+
**Use Case:** Daily development workflow with human oversight
|
|
91
|
+
|
|
92
|
+
**Requirements:** Must run in a terminal (TTY), not in piped or non-interactive environments.
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
### 4. Custom Storage Adapter
|
|
97
|
+
**File:** `04-custom-storage.ts`
|
|
98
|
+
|
|
99
|
+
Demonstrates how to implement custom storage adapters for saving AI-generated content.
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npx tsx examples/04-custom-storage.ts
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Features:**
|
|
106
|
+
- Custom storage adapter implementation
|
|
107
|
+
- Structured output directory
|
|
108
|
+
- Saves multiple artifacts:
|
|
109
|
+
- Commit message
|
|
110
|
+
- Metadata (JSON)
|
|
111
|
+
- Tool metrics (JSON)
|
|
112
|
+
- Example cloud storage adapter structure
|
|
113
|
+
- Timestamped output organization
|
|
114
|
+
|
|
115
|
+
**Use Case:**
|
|
116
|
+
- Integrating with cloud storage (S3, Google Cloud Storage)
|
|
117
|
+
- Saving AI artifacts for auditing
|
|
118
|
+
- Custom file organization
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
### 5. Custom Tool Integration
|
|
123
|
+
**File:** `05-custom-tools.ts`
|
|
124
|
+
|
|
125
|
+
Shows how to create and register custom tools that extend the AI's capabilities.
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
npx tsx examples/05-custom-tools.ts
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Features:**
|
|
132
|
+
- Three custom tools:
|
|
133
|
+
- `check_test_coverage` - Analyze test coverage
|
|
134
|
+
- `check_linter_errors` - Find ESLint errors
|
|
135
|
+
- `analyze_package_dependencies` - Check dependencies
|
|
136
|
+
- Tool registry management
|
|
137
|
+
- Custom AI workflows
|
|
138
|
+
- Code quality analysis example
|
|
139
|
+
|
|
140
|
+
**Use Case:**
|
|
141
|
+
- Domain-specific code analysis
|
|
142
|
+
- Custom CI/CD integrations
|
|
143
|
+
- Project-specific quality checks
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Running the Examples
|
|
148
|
+
|
|
149
|
+
### Option 1: Using tsx (Recommended)
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# Run directly with tsx
|
|
153
|
+
npx tsx examples/01-simple-commit.ts
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Option 2: Compile then run
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
# Compile TypeScript
|
|
160
|
+
npx tsc examples/*.ts --outDir examples/dist
|
|
161
|
+
|
|
162
|
+
# Run compiled JavaScript
|
|
163
|
+
node examples/dist/01-simple-commit.js
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Option 3: Install tsx globally
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
# Install tsx globally
|
|
170
|
+
npm install -g tsx
|
|
171
|
+
|
|
172
|
+
# Run examples
|
|
173
|
+
tsx examples/01-simple-commit.ts
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Configuration
|
|
177
|
+
|
|
178
|
+
All examples can be configured by:
|
|
179
|
+
|
|
180
|
+
1. **Environment Variables:**
|
|
181
|
+
```bash
|
|
182
|
+
export OPENAI_API_KEY=sk-...
|
|
183
|
+
export EDITOR=code --wait
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
2. **Modifying the code:**
|
|
187
|
+
- Change `model` parameter (e.g., `gpt-4o-mini`, `gpt-4o`)
|
|
188
|
+
- Adjust `maxIterations` for more/less thorough analysis
|
|
189
|
+
- Add custom logic specific to your needs
|
|
190
|
+
|
|
191
|
+
## Integration Patterns
|
|
192
|
+
|
|
193
|
+
### As a CLI Tool
|
|
194
|
+
|
|
195
|
+
Add to your `package.json`:
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
{
|
|
199
|
+
"scripts": {
|
|
200
|
+
"commit": "tsx examples/01-simple-commit.ts",
|
|
201
|
+
"release": "tsx examples/02-release-notes.ts"
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Then use:
|
|
207
|
+
```bash
|
|
208
|
+
npm run commit
|
|
209
|
+
npm run release v1.0.0 v1.1.0
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### In Your Own Scripts
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
import { runAgenticCommit } from '@eldrforge/ai-service';
|
|
216
|
+
|
|
217
|
+
// Your custom logic here
|
|
218
|
+
const result = await runAgenticCommit({
|
|
219
|
+
changedFiles,
|
|
220
|
+
diffContent,
|
|
221
|
+
model: 'gpt-4o-mini',
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// Do something with result.commitMessage
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### In a Web Service
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
import express from 'express';
|
|
231
|
+
import { runAgenticCommit } from '@eldrforge/ai-service';
|
|
232
|
+
|
|
233
|
+
const app = express();
|
|
234
|
+
|
|
235
|
+
app.post('/api/commit-message', async (req, res) => {
|
|
236
|
+
const { changedFiles, diffContent } = req.body;
|
|
237
|
+
|
|
238
|
+
const result = await runAgenticCommit({
|
|
239
|
+
changedFiles,
|
|
240
|
+
diffContent,
|
|
241
|
+
model: 'gpt-4o-mini',
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
res.json({ message: result.commitMessage });
|
|
245
|
+
});
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Cost Considerations
|
|
249
|
+
|
|
250
|
+
Approximate token usage and costs (as of 2024, with GPT-4o):
|
|
251
|
+
|
|
252
|
+
| Example | Tokens | Est. Cost | Time |
|
|
253
|
+
|---------|--------|-----------|------|
|
|
254
|
+
| Simple Commit | 5,000-20,000 | $0.05-$0.20 | 10-30s |
|
|
255
|
+
| Release Notes | 20,000-100,000 | $0.20-$1.00 | 30-180s |
|
|
256
|
+
| Interactive Commit | 5,000-30,000 | $0.05-$0.30 | 10-60s |
|
|
257
|
+
| Custom Storage | 5,000-20,000 | $0.05-$0.20 | 10-30s |
|
|
258
|
+
| Custom Tools | 10,000-40,000 | $0.10-$0.40 | 20-60s |
|
|
259
|
+
|
|
260
|
+
Use `gpt-4o-mini` for 60% cost reduction with slightly lower quality.
|
|
261
|
+
|
|
262
|
+
## Troubleshooting
|
|
263
|
+
|
|
264
|
+
### "OpenAI API key not found"
|
|
265
|
+
|
|
266
|
+
Set your API key:
|
|
267
|
+
```bash
|
|
268
|
+
export OPENAI_API_KEY=sk-...
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### "No staged changes found"
|
|
272
|
+
|
|
273
|
+
Stage changes first:
|
|
274
|
+
```bash
|
|
275
|
+
git add .
|
|
276
|
+
# or
|
|
277
|
+
git add <specific-files>
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### "Interactive mode requires a terminal"
|
|
281
|
+
|
|
282
|
+
Examples 03 requires a real terminal. Don't pipe input or run in CI. Use example 01 instead for non-interactive use.
|
|
283
|
+
|
|
284
|
+
### "Invalid git reference"
|
|
285
|
+
|
|
286
|
+
Ensure the git references exist:
|
|
287
|
+
```bash
|
|
288
|
+
git tag # List available tags
|
|
289
|
+
git log --oneline # See commits
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### npm/npx issues
|
|
293
|
+
|
|
294
|
+
Install dependencies:
|
|
295
|
+
```bash
|
|
296
|
+
npm install @eldrforge/ai-service openai @riotprompt/riotprompt
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## Next Steps
|
|
300
|
+
|
|
301
|
+
After exploring these examples:
|
|
302
|
+
|
|
303
|
+
1. **Integrate into your workflow** - Add to package.json scripts
|
|
304
|
+
2. **Customize for your needs** - Modify models, parameters, prompts
|
|
305
|
+
3. **Create custom tools** - Extend with domain-specific capabilities
|
|
306
|
+
4. **Build automation** - Use in CI/CD pipelines
|
|
307
|
+
5. **Explore the API** - See [main README](../README.md) for full API documentation
|
|
308
|
+
|
|
309
|
+
## Additional Resources
|
|
310
|
+
|
|
311
|
+
- [Main README](../README.md) - Full API documentation
|
|
312
|
+
- [OpenAI API Docs](https://platform.openai.com/docs) - OpenAI reference
|
|
313
|
+
- [kodrdriv](https://github.com/calenvarek/kodrdriv) - Full automation toolkit
|
|
314
|
+
|
|
315
|
+
## Questions or Issues?
|
|
316
|
+
|
|
317
|
+
- 🐛 [Report bugs](https://github.com/calenvarek/ai-service/issues)
|
|
318
|
+
- 💬 [Discussions](https://github.com/calenvarek/ai-service/discussions)
|
|
319
|
+
- 📖 [Documentation](../README.md)
|
|
320
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eldrforge/ai-service",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "AI-powered content generation for automation - OpenAI integration with structured prompts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
|
-
"dist"
|
|
14
|
+
"dist",
|
|
15
|
+
"examples"
|
|
15
16
|
],
|
|
16
17
|
"repository": {
|
|
17
18
|
"type": "git",
|
|
@@ -42,8 +43,8 @@
|
|
|
42
43
|
"author": "Calen Varek <calenvarek@gmail.com>",
|
|
43
44
|
"license": "Apache-2.0",
|
|
44
45
|
"dependencies": {
|
|
45
|
-
"@eldrforge/git-tools": "^0.1.
|
|
46
|
-
"@riotprompt/riotprompt": "^0.0.
|
|
46
|
+
"@eldrforge/git-tools": "^0.1.15",
|
|
47
|
+
"@riotprompt/riotprompt": "^0.0.10",
|
|
47
48
|
"openai": "^6.3.0"
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
|
@@ -63,7 +64,7 @@
|
|
|
63
64
|
"@typescript-eslint/eslint-plugin": "^8.39.1",
|
|
64
65
|
"@typescript-eslint/parser": "^8.47.0",
|
|
65
66
|
"@vitest/coverage-v8": "^4.0.13",
|
|
66
|
-
"esbuild": "0.27.
|
|
67
|
+
"esbuild": "0.27.2",
|
|
67
68
|
"eslint": "^9.33.0",
|
|
68
69
|
"eslint-plugin-import": "^2.32.0",
|
|
69
70
|
"globals": "^16.3.0",
|