create-byan-agent 2.2.1 → 2.3.0
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/install/bin/create-byan-agent-v2.js +24 -0
- package/install/lib/platforms/claude-code.js +115 -5
- package/install/lib/yanstaller/agent-launcher.js +348 -0
- package/install/lib/yanstaller/index.js +56 -10
- package/install/lib/yanstaller/platform-selector.js +328 -0
- package/install/package.json +2 -2
- package/install/templates/.github/agents/bmad-agent-claude.md +48 -0
- package/install/templates/.github/agents/bmad-agent-codex.md +48 -0
- package/install/templates/_byan/bmb/agents/claude.md +502 -0
- package/install/templates/_byan/bmb/agents/codex.md +407 -0
- package/install/templates/_byan/workers/launchers/README.md +308 -0
- package/install/templates/_byan/workers/launchers/launch-yanstaller-claude.md +204 -0
- package/install/templates/_byan/workers/launchers/launch-yanstaller-codex.md +209 -0
- package/install/templates/_byan/workers/launchers/launch-yanstaller-copilot.md +173 -0
- package/install/templates/_byan/workers.md +343 -1126
- package/install/templates/workers/README.md +148 -0
- package/install/templates/workers/cost-optimizer.js +169 -0
- package/package.json +5 -2
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Cost Optimizer Worker Template
|
|
2
|
+
|
|
3
|
+
Worker BYAN qui optimise automatiquement les coûts LLM en routant vers le modèle optimal.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Ce worker est automatiquement installé par Yanstaller si vous sélectionnez "Cost Optimizer".
|
|
8
|
+
|
|
9
|
+
## Utilisation
|
|
10
|
+
|
|
11
|
+
### Dans un agent BYAN
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
const CostOptimizerWorker = require('./_byan/workers/cost-optimizer');
|
|
15
|
+
|
|
16
|
+
const worker = new CostOptimizerWorker({
|
|
17
|
+
workerThreshold: 30,
|
|
18
|
+
agentThreshold: 60,
|
|
19
|
+
verbose: true
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Router une tâche
|
|
23
|
+
const result = await worker.execute({
|
|
24
|
+
input: 'Your prompt here',
|
|
25
|
+
type: 'generate'
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
console.log(result.content);
|
|
29
|
+
console.log(`Cost: $${result.cost}`);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Configuration
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
const worker = new CostOptimizerWorker({
|
|
36
|
+
workerThreshold: 30, // < 30 → worker (cheap)
|
|
37
|
+
agentThreshold: 60, // ≥ 60 → agent (expensive)
|
|
38
|
+
fallbackEnabled: true, // Fallback worker → agent si échec
|
|
39
|
+
maxRetries: 3, // Tentatives max
|
|
40
|
+
testMode: true, // Mode test (sans vraie API)
|
|
41
|
+
verbose: false // Logs détaillés
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Méthodes
|
|
46
|
+
|
|
47
|
+
**execute(task)** - Route et exécute une tâche
|
|
48
|
+
```javascript
|
|
49
|
+
const result = await worker.execute({
|
|
50
|
+
input: 'Fix this bug',
|
|
51
|
+
type: 'simple',
|
|
52
|
+
contextSize: 1000,
|
|
53
|
+
steps: 2,
|
|
54
|
+
outputFormat: 'text'
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**getStatistics()** - Obtenir les statistiques
|
|
59
|
+
```javascript
|
|
60
|
+
const stats = worker.getStatistics();
|
|
61
|
+
console.log(`Économies: ${stats.savingsPercent}%`);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**printSummary()** - Afficher résumé formaté
|
|
65
|
+
```javascript
|
|
66
|
+
worker.printSummary();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**analyzeComplexity(task)** - Analyser sans exécuter
|
|
70
|
+
```javascript
|
|
71
|
+
const complexity = worker.analyzeComplexity({ input: prompt });
|
|
72
|
+
console.log(`Score: ${complexity.total}`);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**exportData(format)** - Exporter données
|
|
76
|
+
```javascript
|
|
77
|
+
const json = worker.exportData('json');
|
|
78
|
+
const csv = worker.exportData('csv');
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**reset()** - Réinitialiser stats
|
|
82
|
+
```javascript
|
|
83
|
+
worker.reset();
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**close()** - Nettoyer ressources
|
|
87
|
+
```javascript
|
|
88
|
+
await worker.close();
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Types de tâches
|
|
92
|
+
|
|
93
|
+
- **simple** - Corrections simples, typos (score: 0-25)
|
|
94
|
+
- **format** - Formatage, organisation (score: 5-30)
|
|
95
|
+
- **generate** - Génération de code (score: 15-45)
|
|
96
|
+
- **analysis** - Analyse de code (score: 30-60)
|
|
97
|
+
- **reasoning** - Conception, architecture (score: 30-75)
|
|
98
|
+
- **creation** - Création complexe (score: 30-75)
|
|
99
|
+
|
|
100
|
+
## Économies attendues
|
|
101
|
+
|
|
102
|
+
- **Workload typique:** 60% worker, 40% agent
|
|
103
|
+
- **Économies:** ~54% sur les coûts LLM
|
|
104
|
+
- **Coût worker:** $0.0003 par appel
|
|
105
|
+
- **Coût agent:** $0.003 par appel (10x plus cher)
|
|
106
|
+
|
|
107
|
+
## Test
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
cd install/templates/workers
|
|
111
|
+
node cost-optimizer.js
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Output attendu:
|
|
115
|
+
```
|
|
116
|
+
🚀 Cost Optimizer Worker Demo
|
|
117
|
+
|
|
118
|
+
1️⃣ Simple task:
|
|
119
|
+
[CostOptimizer] Routed to: worker
|
|
120
|
+
Result: ✓
|
|
121
|
+
|
|
122
|
+
2️⃣ Complex task:
|
|
123
|
+
[CostOptimizer] Routed to: worker
|
|
124
|
+
Result: ✓
|
|
125
|
+
|
|
126
|
+
📊 Statistics:
|
|
127
|
+
Savings: 87.5%
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Production
|
|
131
|
+
|
|
132
|
+
Pour utiliser avec vraie API:
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
const worker = new CostOptimizerWorker({
|
|
136
|
+
testMode: false, // IMPORTANT
|
|
137
|
+
verbose: true
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Nécessite:
|
|
142
|
+
- GitHub Copilot subscription
|
|
143
|
+
- GITHUB_TOKEN env variable
|
|
144
|
+
|
|
145
|
+
## Support
|
|
146
|
+
|
|
147
|
+
- Package: https://npmjs.com/package/byan-copilot-router
|
|
148
|
+
- Issues: https://github.com/byan/copilot-router/issues
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost Optimizer Worker
|
|
3
|
+
*
|
|
4
|
+
* Automatically routes LLM calls to optimal model based on complexity.
|
|
5
|
+
* Integrates with byan-copilot-router for cost optimization.
|
|
6
|
+
*
|
|
7
|
+
* @module workers/cost-optimizer
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const { CopilotRouter } = require('byan-copilot-router');
|
|
11
|
+
|
|
12
|
+
class CostOptimizerWorker {
|
|
13
|
+
constructor(config = {}) {
|
|
14
|
+
this.router = new CopilotRouter({
|
|
15
|
+
workerThreshold: config.workerThreshold || 30,
|
|
16
|
+
agentThreshold: config.agentThreshold || 60,
|
|
17
|
+
fallbackEnabled: config.fallbackEnabled !== false,
|
|
18
|
+
maxRetries: config.maxRetries || 3,
|
|
19
|
+
clientOptions: {
|
|
20
|
+
testMode: config.testMode !== false // Default to test mode
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
this.role = 'worker';
|
|
25
|
+
this.model = 'auto'; // Auto-select based on complexity
|
|
26
|
+
this.verbose = config.verbose || false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Execute task with automatic routing
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} task - Task to execute
|
|
33
|
+
* @param {string} task.input - User prompt
|
|
34
|
+
* @param {string} task.type - Task type (simple/generate/analysis/reasoning)
|
|
35
|
+
* @param {number} [task.contextSize] - Context size in characters
|
|
36
|
+
* @param {number} [task.steps] - Number of steps
|
|
37
|
+
* @param {string} [task.outputFormat] - Output format (text/json/complex)
|
|
38
|
+
* @returns {Promise<Object>} Execution result
|
|
39
|
+
*/
|
|
40
|
+
async execute(task) {
|
|
41
|
+
if (this.verbose) {
|
|
42
|
+
console.log('[CostOptimizer] Routing task:', task.type);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const result = await this.router.route({
|
|
47
|
+
input: task.input || task.prompt,
|
|
48
|
+
type: task.type || 'generate',
|
|
49
|
+
contextSize: task.contextSize || (task.context?.length || 0),
|
|
50
|
+
steps: task.steps,
|
|
51
|
+
outputFormat: task.outputFormat
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (this.verbose) {
|
|
55
|
+
console.log(`[CostOptimizer] Routed to: ${result.route}`);
|
|
56
|
+
console.log(`[CostOptimizer] Cost: $${result.cost.toFixed(6)}`);
|
|
57
|
+
console.log(`[CostOptimizer] Complexity: ${result.complexityScore.total}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
success: true,
|
|
62
|
+
content: result.content,
|
|
63
|
+
route: result.route,
|
|
64
|
+
model: result.model,
|
|
65
|
+
cost: result.cost,
|
|
66
|
+
tokens: result.tokens,
|
|
67
|
+
complexity: result.complexityScore.total
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error('[CostOptimizer] Error:', error.message);
|
|
72
|
+
return {
|
|
73
|
+
success: false,
|
|
74
|
+
error: error.message
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get routing statistics
|
|
81
|
+
*
|
|
82
|
+
* @returns {Object} Statistics with costs and savings
|
|
83
|
+
*/
|
|
84
|
+
getStatistics() {
|
|
85
|
+
return this.router.getTracker().getStatistics();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Print cost summary
|
|
90
|
+
*/
|
|
91
|
+
printSummary() {
|
|
92
|
+
console.log(this.router.getTracker().printSummary());
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Export cost data
|
|
97
|
+
*
|
|
98
|
+
* @param {string} format - Format (json/csv)
|
|
99
|
+
* @returns {string} Exported data
|
|
100
|
+
*/
|
|
101
|
+
exportData(format = 'json') {
|
|
102
|
+
const tracker = this.router.getTracker();
|
|
103
|
+
return format === 'csv' ? tracker.exportCSV() : tracker.exportJSON();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Reset statistics
|
|
108
|
+
*/
|
|
109
|
+
reset() {
|
|
110
|
+
this.router.getTracker().reset();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Cleanup resources
|
|
115
|
+
*/
|
|
116
|
+
async close() {
|
|
117
|
+
await this.router.close();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Get complexity score for a task without executing
|
|
122
|
+
*
|
|
123
|
+
* @param {Object} task - Task to analyze
|
|
124
|
+
* @returns {Object} Complexity score
|
|
125
|
+
*/
|
|
126
|
+
analyzeComplexity(task) {
|
|
127
|
+
return this.router.analyzer.calculateComplexity({
|
|
128
|
+
input: task.input || task.prompt,
|
|
129
|
+
type: task.type || 'generate',
|
|
130
|
+
contextSize: task.contextSize || 0,
|
|
131
|
+
steps: task.steps,
|
|
132
|
+
outputFormat: task.outputFormat
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
module.exports = CostOptimizerWorker;
|
|
138
|
+
|
|
139
|
+
// Example usage
|
|
140
|
+
if (require.main === module) {
|
|
141
|
+
(async () => {
|
|
142
|
+
console.log('🚀 Cost Optimizer Worker Demo\n');
|
|
143
|
+
|
|
144
|
+
const worker = new CostOptimizerWorker({ verbose: true });
|
|
145
|
+
|
|
146
|
+
// Simple task
|
|
147
|
+
console.log('1️⃣ Simple task:');
|
|
148
|
+
const r1 = await worker.execute({
|
|
149
|
+
input: 'Fix typo in code',
|
|
150
|
+
type: 'simple'
|
|
151
|
+
});
|
|
152
|
+
console.log('Result:', r1.success ? '✓' : '✗', '\n');
|
|
153
|
+
|
|
154
|
+
// Complex task
|
|
155
|
+
console.log('2️⃣ Complex task:');
|
|
156
|
+
const r2 = await worker.execute({
|
|
157
|
+
input: 'Design microservices architecture',
|
|
158
|
+
type: 'reasoning',
|
|
159
|
+
steps: 5
|
|
160
|
+
});
|
|
161
|
+
console.log('Result:', r2.success ? '✓' : '✗', '\n');
|
|
162
|
+
|
|
163
|
+
// Show statistics
|
|
164
|
+
console.log('📊 Statistics:');
|
|
165
|
+
worker.printSummary();
|
|
166
|
+
|
|
167
|
+
await worker.close();
|
|
168
|
+
})();
|
|
169
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-byan-agent",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "BYAN v2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"description": "BYAN v2.3.0 - Intelligent AI agent creator with Multi-platform native support (Copilot CLI, Claude Code, Codex) + Automatic LLM cost optimization",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"create-byan-agent": "./install/bin/create-byan-agent-v2.js",
|
|
@@ -83,5 +83,8 @@
|
|
|
83
83
|
"statements": 80
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
+
},
|
|
87
|
+
"optionalDependencies": {
|
|
88
|
+
"byan-copilot-router": "^1.0.1"
|
|
86
89
|
}
|
|
87
90
|
}
|