synapse-gateway 2.0.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/README.md +385 -0
- package/bin/synapse.js +242 -0
- package/docs/PLAN.md +1723 -0
- package/docs/PRD.md +1799 -0
- package/drizzle.config.ts +12 -0
- package/next.config.ts +8 -0
- package/package.json +82 -0
- package/postcss.config.mjs +7 -0
- package/public/file.svg +1 -0
- package/public/globe.svg +1 -0
- package/public/next.svg +1 -0
- package/public/vercel.svg +1 -0
- package/public/window.svg +1 -0
- package/src/app/api/analytics/cost/route.ts +13 -0
- package/src/app/api/analytics/usage/route.ts +16 -0
- package/src/app/api/auth/login/route.ts +42 -0
- package/src/app/api/cache/route.ts +19 -0
- package/src/app/api/dashboard/route.ts +35 -0
- package/src/app/api/distill/route.ts +10 -0
- package/src/app/api/events/route.ts +54 -0
- package/src/app/api/health/route.ts +10 -0
- package/src/app/api/intelligence/forensics/route.ts +23 -0
- package/src/app/api/intelligence/neural-router/route.ts +23 -0
- package/src/app/api/keys/route.ts +34 -0
- package/src/app/api/mcp/route.ts +49 -0
- package/src/app/api/memory/route.ts +10 -0
- package/src/app/api/models/benchmark/route.ts +13 -0
- package/src/app/api/models/route.ts +39 -0
- package/src/app/api/namespace/route.ts +25 -0
- package/src/app/api/plugins/route.ts +41 -0
- package/src/app/api/providers/accounts/route.ts +91 -0
- package/src/app/api/providers/fetch-models/route.ts +52 -0
- package/src/app/api/providers/health/route.ts +10 -0
- package/src/app/api/providers/route.ts +46 -0
- package/src/app/api/routes/pipeline/route.ts +20 -0
- package/src/app/api/settings/route.ts +33 -0
- package/src/app/api/skills/route.ts +39 -0
- package/src/app/api/v1/chat/completions/route.ts +156 -0
- package/src/app/api/v1/models/route.ts +44 -0
- package/src/app/dashboard/intelligence/loading.tsx +14 -0
- package/src/app/dashboard/intelligence/page.tsx +125 -0
- package/src/app/dashboard/layout.tsx +143 -0
- package/src/app/dashboard/loading.tsx +17 -0
- package/src/app/dashboard/memory/loading.tsx +15 -0
- package/src/app/dashboard/memory/page.tsx +71 -0
- package/src/app/dashboard/models/loading.tsx +13 -0
- package/src/app/dashboard/models/page.tsx +107 -0
- package/src/app/dashboard/page.tsx +183 -0
- package/src/app/dashboard/playground/loading.tsx +17 -0
- package/src/app/dashboard/playground/page.tsx +212 -0
- package/src/app/dashboard/providers/loading.tsx +15 -0
- package/src/app/dashboard/providers/page.tsx +248 -0
- package/src/app/dashboard/routes/loading.tsx +15 -0
- package/src/app/dashboard/routes/page.tsx +72 -0
- package/src/app/dashboard/settings/loading.tsx +20 -0
- package/src/app/dashboard/settings/page.tsx +208 -0
- package/src/app/dashboard/skills/loading.tsx +26 -0
- package/src/app/dashboard/skills/page.tsx +137 -0
- package/src/app/dashboard/vault/loading.tsx +18 -0
- package/src/app/dashboard/vault/page.tsx +139 -0
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +59 -0
- package/src/app/layout.tsx +32 -0
- package/src/app/login/page.tsx +87 -0
- package/src/app/page.tsx +5 -0
- package/src/components/ui/badge.tsx +32 -0
- package/src/components/ui/button.tsx +38 -0
- package/src/components/ui/card.tsx +50 -0
- package/src/components/ui/error-boundary.tsx +47 -0
- package/src/components/ui/index.ts +11 -0
- package/src/components/ui/input.tsx +26 -0
- package/src/components/ui/select.tsx +24 -0
- package/src/components/ui/skeleton.tsx +53 -0
- package/src/components/ui/toast.tsx +51 -0
- package/src/instrumentation.ts +6 -0
- package/src/lib/__tests__/auth.test.ts +42 -0
- package/src/lib/__tests__/format.test.ts +94 -0
- package/src/lib/__tests__/namespace.test.ts +102 -0
- package/src/lib/__tests__/squeezer.test.ts +93 -0
- package/src/lib/__tests__/utils.test.ts +28 -0
- package/src/lib/analytics/index.ts +187 -0
- package/src/lib/auth/guard.tsx +71 -0
- package/src/lib/auth/index.ts +105 -0
- package/src/lib/auth/middleware.ts +64 -0
- package/src/lib/benchmark/index.ts +137 -0
- package/src/lib/bootstrap.ts +122 -0
- package/src/lib/cache/index.ts +1 -0
- package/src/lib/cache/semantic.ts +211 -0
- package/src/lib/config/defaults.ts +61 -0
- package/src/lib/config/index.ts +72 -0
- package/src/lib/config/schema.ts +63 -0
- package/src/lib/db/index.ts +22 -0
- package/src/lib/db/migrate.ts +327 -0
- package/src/lib/db/schema.ts +303 -0
- package/src/lib/distiller/index.ts +331 -0
- package/src/lib/fallback/index.ts +153 -0
- package/src/lib/forensics/index.ts +188 -0
- package/src/lib/format/anthropic.ts +139 -0
- package/src/lib/format/gemini.ts +130 -0
- package/src/lib/format/index.ts +3 -0
- package/src/lib/format/openai.ts +78 -0
- package/src/lib/health/index.ts +158 -0
- package/src/lib/mcp/builtin.ts +83 -0
- package/src/lib/mcp/index.ts +1 -0
- package/src/lib/mcp/registry.ts +49 -0
- package/src/lib/memory/index.ts +3 -0
- package/src/lib/memory/store.ts +215 -0
- package/src/lib/memory/types.ts +56 -0
- package/src/lib/namespace/index.ts +89 -0
- package/src/lib/neural/features.ts +74 -0
- package/src/lib/neural/index.ts +85 -0
- package/src/lib/neural/strategies.ts +124 -0
- package/src/lib/pipeline/index.ts +84 -0
- package/src/lib/pipeline/types.ts +77 -0
- package/src/lib/plugins/builtin.ts +79 -0
- package/src/lib/plugins/index.ts +65 -0
- package/src/lib/prediction/index.ts +113 -0
- package/src/lib/providers/api-key/anthropic.ts +96 -0
- package/src/lib/providers/api-key/deepseek.ts +108 -0
- package/src/lib/providers/api-key/gemini.ts +112 -0
- package/src/lib/providers/api-key/openai.ts +122 -0
- package/src/lib/providers/api-key/openrouter.ts +112 -0
- package/src/lib/providers/base-adapter.ts +122 -0
- package/src/lib/providers/registry.ts +46 -0
- package/src/lib/providers/types.ts +121 -0
- package/src/lib/router/index.ts +82 -0
- package/src/lib/skills/forge.ts +57 -0
- package/src/lib/skills/index.ts +3 -0
- package/src/lib/skills/registry.ts +195 -0
- package/src/lib/skills/types.ts +44 -0
- package/src/lib/squeezer/index.ts +158 -0
- package/src/lib/utils/cn.ts +6 -0
- package/src/lib/utils/logger.ts +16 -0
- package/src/middleware.ts +60 -0
- package/tsconfig.json +34 -0
package/docs/PLAN.md
ADDED
|
@@ -0,0 +1,1723 @@
|
|
|
1
|
+
# Implementation Plan — Adnify v2.0
|
|
2
|
+
# Next-Gen AI Gateway & Intelligence Platform
|
|
3
|
+
|
|
4
|
+
> **Codename:** NEXUS
|
|
5
|
+
> **Versi:** 2.0.0
|
|
6
|
+
> **Tanggal:** 8 Juni 2026
|
|
7
|
+
> **Estimasi Total:** 12 Minggu
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 0. Project Structure
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
adnify/
|
|
15
|
+
├── src/
|
|
16
|
+
│ ├── app/ # Next.js 15 App Router
|
|
17
|
+
│ │ ├── layout.tsx
|
|
18
|
+
│ │ ├── page.tsx # → redirect /dashboard
|
|
19
|
+
│ │ ├── globals.css
|
|
20
|
+
│ │ │
|
|
21
|
+
│ │ ├── (auth)/ # Auth group
|
|
22
|
+
│ │ │ ├── login/page.tsx
|
|
23
|
+
│ │ │ └── webauthn/page.tsx
|
|
24
|
+
│ │ │
|
|
25
|
+
│ │ ├── dashboard/ # Dashboard pages
|
|
26
|
+
│ │ │ ├── layout.tsx # Sidebar + header + realtime
|
|
27
|
+
│ │ │ ├── page.tsx # Command Center
|
|
28
|
+
│ │ │ ├── providers/
|
|
29
|
+
│ │ │ │ ├── page.tsx # Provider grid
|
|
30
|
+
│ │ │ │ ├── [id]/page.tsx # Provider detail
|
|
31
|
+
│ │ │ │ └── discover/page.tsx # Auto-discovery
|
|
32
|
+
│ │ │ ├── models/
|
|
33
|
+
│ │ │ │ ├── page.tsx # Model browser
|
|
34
|
+
│ │ │ │ └── benchmark/page.tsx # Quality benchmark
|
|
35
|
+
│ │ │ ├── routes/
|
|
36
|
+
│ │ │ │ ├── page.tsx # Routes & combos
|
|
37
|
+
│ │ │ │ ├── new/page.tsx # Combo builder
|
|
38
|
+
│ │ │ │ └── pipeline/page.tsx # Pipeline builder
|
|
39
|
+
│ │ │ ├── skills/
|
|
40
|
+
│ │ │ │ ├── page.tsx # Skill browser & rotation status
|
|
41
|
+
│ │ │ │ ├── new/page.tsx # Skill forge (create new skill)
|
|
42
|
+
│ │ │ │ ├── [id]/page.tsx # Skill detail & edit
|
|
43
|
+
│ │ │ │ ├── groups/page.tsx # Skill group manager
|
|
44
|
+
│ │ │ │ └── import/page.tsx # Import from OpenClaw / URL / file
|
|
45
|
+
│ │ │ ├── intelligence/
|
|
46
|
+
│ │ │ │ ├── page.tsx # Predictions
|
|
47
|
+
│ │ │ │ ├── forensics/page.tsx # Request forensics
|
|
48
|
+
│ │ │ │ └── patterns/page.tsx # Pattern analysis
|
|
49
|
+
│ │ │ ├── memory/
|
|
50
|
+
│ │ │ │ ├── page.tsx # Memory status & knowledge base
|
|
51
|
+
│ │ │ │ ├── knowledge/page.tsx # Browse semantic memory
|
|
52
|
+
│ │ │ │ ├── rules/page.tsx # View procedural rules
|
|
53
|
+
│ │ │ │ └── insights/page.tsx # Learning insights timeline
|
|
54
|
+
│ │ │ ├── playground/
|
|
55
|
+
│ │ │ │ └── page.tsx # Multi-model playground
|
|
56
|
+
│ │ │ ├── vault/
|
|
57
|
+
│ │ │ │ └── page.tsx # Security & keys
|
|
58
|
+
│ │ │ └── settings/
|
|
59
|
+
│ │ │ └── page.tsx # App settings
|
|
60
|
+
│ │ │
|
|
61
|
+
│ │ └── api/
|
|
62
|
+
│ │ ├── v1/ # OpenAI-compatible
|
|
63
|
+
│ │ │ ├── models/route.ts
|
|
64
|
+
│ │ │ ├── chat/completions/route.ts
|
|
65
|
+
│ │ │ ├── completions/route.ts
|
|
66
|
+
│ │ │ └── messages/route.ts # Claude-compatible
|
|
67
|
+
│ │ │
|
|
68
|
+
│ │ ├── mcp/ # MCP Gateway
|
|
69
|
+
│ │ │ ├── route.ts # MCP endpoint
|
|
70
|
+
│ │ │ ├── tools/route.ts
|
|
71
|
+
│ │ │ └── resources/route.ts
|
|
72
|
+
│ │ │
|
|
73
|
+
│ │ ├── auth/
|
|
74
|
+
│ │ │ ├── login/route.ts
|
|
75
|
+
│ │ │ ├── logout/route.ts
|
|
76
|
+
│ │ │ └── webauthn/
|
|
77
|
+
│ │ │ ├── register/route.ts
|
|
78
|
+
│ │ │ └── verify/route.ts
|
|
79
|
+
│ │ │
|
|
80
|
+
│ │ ├── providers/
|
|
81
|
+
│ │ │ ├── route.ts
|
|
82
|
+
│ │ │ ├── [id]/route.ts
|
|
83
|
+
│ │ │ ├── [id]/models/route.ts
|
|
84
|
+
│ │ │ ├── [id]/health/route.ts
|
|
85
|
+
│ │ │ ├── [id]/quota/route.ts
|
|
86
|
+
│ │ │ ├── [id]/accounts/route.ts
|
|
87
|
+
│ │ │ └── discover/route.ts # Auto-discovery scan
|
|
88
|
+
│ │ │
|
|
89
|
+
│ │ ├── models/
|
|
90
|
+
│ │ │ ├── route.ts
|
|
91
|
+
│ │ │ ├── [id]/route.ts
|
|
92
|
+
│ │ │ └── benchmark/route.ts
|
|
93
|
+
│ │ │
|
|
94
|
+
│ │ ├── routes/
|
|
95
|
+
│ │ │ ├── combos/route.ts
|
|
96
|
+
│ │ │ ├── combos/[id]/route.ts
|
|
97
|
+
│ │ │ ├── namespaces/route.ts
|
|
98
|
+
│ │ │ └── pipeline/route.ts
|
|
99
|
+
│ │ │
|
|
100
|
+
│ │ ├── intelligence/
|
|
101
|
+
│ │ │ ├── neural-router/route.ts
|
|
102
|
+
│ │ │ ├── predictions/route.ts
|
|
103
|
+
│ │ │ ├── forensics/route.ts
|
|
104
|
+
│ │ │ ├── recommendations/route.ts
|
|
105
|
+
│ │ │ └── patterns/route.ts
|
|
106
|
+
│ │ │
|
|
107
|
+
│ │ ├── analytics/
|
|
108
|
+
│ │ │ ├── usage/route.ts
|
|
109
|
+
│ │ │ ├── cost/route.ts
|
|
110
|
+
│ │ │ ├── tokens/route.ts
|
|
111
|
+
│ │ │ ├── savings/route.ts
|
|
112
|
+
│ │ │ └── export/route.ts
|
|
113
|
+
│ │ │
|
|
114
|
+
│ │ ├── cache/
|
|
115
|
+
│ │ │ ├── route.ts # GET stats, DELETE clear
|
|
116
|
+
│ │ │ └── semantic/route.ts # Semantic cache management
|
|
117
|
+
│ │ │
|
|
118
|
+
│ │ ├── mesh/
|
|
119
|
+
│ │ │ ├── route.ts # Mesh topology
|
|
120
|
+
│ │ │ └── arbitrage/route.ts # Cost comparison
|
|
121
|
+
│ │ │
|
|
122
|
+
│ │ ├── memory/ # Memory & Learning API
|
|
123
|
+
│ │ │ ├── route.ts # GET memory status
|
|
124
|
+
│ │ │ ├── knowledge/route.ts # GET knowledge base
|
|
125
|
+
│ │ │ ├── rules/route.ts # GET/PUT procedural rules
|
|
126
|
+
│ │ │ ├── insights/route.ts # GET learning insights
|
|
127
|
+
│ │ │ ├── distill/route.ts # POST trigger distillation
|
|
128
|
+
│ │ │ └── export/route.ts # GET export all memory
|
|
129
|
+
│ │ │
|
|
130
|
+
│ │ ├── skills/ # Skill Management API
|
|
131
|
+
│ │ │ ├── route.ts # GET list, POST create
|
|
132
|
+
│ │ │ ├── [id]/route.ts # GET, PUT, DELETE skill
|
|
133
|
+
│ │ │ ├── [id]/test/route.ts # POST test skill with sample request
|
|
134
|
+
│ │ │ ├── groups/route.ts # GET list, POST create group
|
|
135
|
+
│ │ │ ├── groups/[id]/route.ts # GET, PUT, DELETE group
|
|
136
|
+
│ │ │ ├── rotation/route.ts # GET status, PUT update rotation
|
|
137
|
+
│ │ │ ├── import/
|
|
138
|
+
│ │ │ │ ├── openclaw/route.ts # POST import from OpenClaw
|
|
139
|
+
│ │ │ │ ├── url/route.ts # POST import from URL
|
|
140
|
+
│ │ │ │ └── file/route.ts # POST import from file
|
|
141
|
+
│ │ │ └── export/route.ts # GET export skill as JSON/MD
|
|
142
|
+
│ │ │
|
|
143
|
+
│ │ ├── quota/route.ts
|
|
144
|
+
│ │ ├── health/route.ts
|
|
145
|
+
│ │ ├── metrics/route.ts
|
|
146
|
+
│ │ ├── keys/route.ts
|
|
147
|
+
│ │ ├── settings/route.ts
|
|
148
|
+
│ │ └── events/route.ts # SSE realtime events
|
|
149
|
+
│ │
|
|
150
|
+
│ ├── lib/
|
|
151
|
+
│ │ ├── config/
|
|
152
|
+
│ │ │ ├── index.ts # Config loader + watcher
|
|
153
|
+
│ │ │ ├── defaults.ts
|
|
154
|
+
│ │ │ ├── schema.ts # Zod schema
|
|
155
|
+
│ │ │ └── secrets.ts # Encryption for config
|
|
156
|
+
│ │ │
|
|
157
|
+
│ │ ├── db/
|
|
158
|
+
│ │ │ ├── index.ts # Database singleton
|
|
159
|
+
│ │ │ ├── schema.ts # Drizzle schema
|
|
160
|
+
│ │ │ ├── migrate.ts
|
|
161
|
+
│ │ │ ├── seed.ts
|
|
162
|
+
│ │ │ └── vector.ts # Vector operations for semantic cache
|
|
163
|
+
│ │ │
|
|
164
|
+
│ │ ├── neural/ # Neural Router Engine
|
|
165
|
+
│ │ │ ├── index.ts # Router orchestrator
|
|
166
|
+
│ │ │ ├── model.ts # ONNX model wrapper
|
|
167
|
+
│ │ │ ├── features.ts # Feature extraction
|
|
168
|
+
│ │ │ ├── trainer.ts # Model trainer (background)
|
|
169
|
+
│ │ │ ├── predictor.ts # Fast inference
|
|
170
|
+
│ │ │ ├── strategies/
|
|
171
|
+
│ │ │ │ ├── neural.ts # ML-based routing
|
|
172
|
+
│ │ │ │ ├── hybrid.ts # Neural + rules
|
|
173
|
+
│ │ │ │ ├── priority.ts # Traditional
|
|
174
|
+
│ │ │ │ ├── latency.ts
|
|
175
|
+
│ │ │ │ ├── cost.ts
|
|
176
|
+
│ │ │ │ └── round-robin.ts
|
|
177
|
+
│ │ │ └── feedback.ts # Feedback loop
|
|
178
|
+
│ │ │
|
|
179
|
+
│ │ ├── cache/
|
|
180
|
+
│ │ │ ├── index.ts # Cache orchestrator
|
|
181
|
+
│ │ │ ├── semantic.ts # Semantic cache (embedding-based)
|
|
182
|
+
│ │ │ ├── exact.ts # Exact match cache
|
|
183
|
+
│ │ │ ├── embedding.ts # MiniLM embedding generator
|
|
184
|
+
│ │ │ ├── similarity.ts # Vector similarity search
|
|
185
|
+
│ │ │ └── eviction.ts # Smart eviction policy
|
|
186
|
+
│ │ │
|
|
187
|
+
│ │ ├── squeezer/ # Adaptive Token Squeezer
|
|
188
|
+
│ │ │ ├── index.ts # Squeezer orchestrator
|
|
189
|
+
│ │ │ ├── pipeline.ts # Multi-pass pipeline
|
|
190
|
+
│ │ │ ├── classifier.ts # Content type classifier
|
|
191
|
+
│ │ │ ├── budget.ts # Token budget allocator
|
|
192
|
+
│ │ │ ├── quality.ts # Quality scoring
|
|
193
|
+
│ │ │ ├── filters/
|
|
194
|
+
│ │ │ │ ├── git-diff-semantic.ts # Semantic diff compression
|
|
195
|
+
│ │ │ │ ├── git-status.ts
|
|
196
|
+
│ │ │ │ ├── grep-results.ts
|
|
197
|
+
│ │ │ │ ├── file-tree.ts
|
|
198
|
+
│ │ │ │ ├── log-analyzer.ts
|
|
199
|
+
│ │ │ │ ├── code-ast.ts # AST-based code compression
|
|
200
|
+
│ │ │ │ ├── numbered-content.ts
|
|
201
|
+
│ │ │ │ ├── smart-truncate.ts
|
|
202
|
+
│ │ │ │ ├── context-dedup.ts # Deduplicate context
|
|
203
|
+
│ │ │ │ └── adaptive-general.ts # General adaptive filter
|
|
204
|
+
│ │ │ └── language/
|
|
205
|
+
│ │ │ ├── javascript.ts # JS/TS-aware compression
|
|
206
|
+
│ │ │ ├── python.ts
|
|
207
|
+
│ │ │ ├── go.ts
|
|
208
|
+
│ │ │ ├── rust.ts
|
|
209
|
+
│ │ │ └── generic.ts
|
|
210
|
+
│ │ │
|
|
211
|
+
│ │ ├── providers/
|
|
212
|
+
│ │ │ ├── types.ts
|
|
213
|
+
│ │ │ ├── registry.ts
|
|
214
|
+
│ │ │ ├── base-adapter.ts
|
|
215
|
+
│ │ │ ├── mesh.ts # Provider Mesh Network
|
|
216
|
+
│ │ │ ├── discovery.ts # Auto-discovery
|
|
217
|
+
│ │ │ ├── oauth/
|
|
218
|
+
│ │ │ │ ├── manager.ts
|
|
219
|
+
│ │ │ │ ├── claude-code.ts
|
|
220
|
+
│ │ │ │ ├── codex.ts
|
|
221
|
+
│ │ │ │ ├── github.ts
|
|
222
|
+
│ │ │ │ ├── cursor.ts
|
|
223
|
+
│ │ │ │ ├── kiro.ts
|
|
224
|
+
│ │ │ │ └── antigravity.ts
|
|
225
|
+
│ │ │ ├── api-key/
|
|
226
|
+
│ │ │ │ ├── openai.ts
|
|
227
|
+
│ │ │ │ ├── anthropic.ts
|
|
228
|
+
│ │ │ │ ├── gemini.ts
|
|
229
|
+
│ │ │ │ ├── deepseek.ts
|
|
230
|
+
│ │ │ │ ├── openrouter.ts
|
|
231
|
+
│ │ │ │ ├── groq.ts
|
|
232
|
+
│ │ │ │ ├── xai.ts
|
|
233
|
+
│ │ │ │ ├── mistral.ts
|
|
234
|
+
│ │ │ │ ├── together.ts
|
|
235
|
+
│ │ │ │ ├── fireworks.ts
|
|
236
|
+
│ │ │ │ ├── cerebras.ts
|
|
237
|
+
│ │ │ │ ├── cohere.ts
|
|
238
|
+
│ │ │ │ ├── glm.ts
|
|
239
|
+
│ │ │ │ ├── minimax.ts
|
|
240
|
+
│ │ │ │ ├── kimi.ts
|
|
241
|
+
│ │ │ │ ├── siliconflow.ts
|
|
242
|
+
│ │ │ │ ├── nvidia.ts
|
|
243
|
+
│ │ │ │ ├── perplexity.ts
|
|
244
|
+
│ │ │ │ ├── nebius.ts
|
|
245
|
+
│ │ │ │ ├── chutes.ts
|
|
246
|
+
│ │ │ │ ├── hyperbolic.ts
|
|
247
|
+
│ │ │ │ └── custom.ts
|
|
248
|
+
│ │ │ ├── free/
|
|
249
|
+
│ │ │ │ ├── opencode.ts
|
|
250
|
+
│ │ │ │ └── vertex.ts
|
|
251
|
+
│ │ │ └── local/
|
|
252
|
+
│ │ │ ├── ollama.ts
|
|
253
|
+
│ │ │ └── lmstudio.ts
|
|
254
|
+
│ │ │
|
|
255
|
+
│ │ ├── translate/
|
|
256
|
+
│ │ │ ├── index.ts # Translation pipeline
|
|
257
|
+
│ │ │ ├── detector.ts # Format auto-detection
|
|
258
|
+
│ │ │ ├── openai.ts
|
|
259
|
+
│ │ │ ├── claude.ts
|
|
260
|
+
│ │ │ ├── gemini.ts
|
|
261
|
+
│ │ │ ├── cursor.ts
|
|
262
|
+
│ │ │ ├── kiro.ts
|
|
263
|
+
│ │ │ ├── vertex.ts
|
|
264
|
+
│ │ │ ├── ollama.ts
|
|
265
|
+
│ │ │ ├── responses.ts
|
|
266
|
+
│ │ │ └── mcp.ts # MCP format
|
|
267
|
+
│ │ │
|
|
268
|
+
│ │ ├── pipeline/ # Request Pipeline Builder
|
|
269
|
+
│ │ │ ├── index.ts # Pipeline engine
|
|
270
|
+
│ │ │ ├── builder.ts # Pipeline builder
|
|
271
|
+
│ │ │ ├── nodes/
|
|
272
|
+
│ │ │ │ ├── auth.ts
|
|
273
|
+
│ │ │ │ ├── rate-limit.ts
|
|
274
|
+
│ │ │ │ ├── preprocessor.ts # Prompt pre-processor
|
|
275
|
+
│ │ │ │ ├── squeezer.ts
|
|
276
|
+
│ │ │ │ ├── cache-check.ts
|
|
277
|
+
│ │ │ │ ├── cache-store.ts
|
|
278
|
+
│ │ │ │ ├── router.ts
|
|
279
|
+
│ │ │ │ ├── translator.ts
|
|
280
|
+
│ │ │ │ ├── context-manager.ts # Context window manager
|
|
281
|
+
│ │ │ │ └── custom.ts # User custom JS nodes
|
|
282
|
+
│ │ │ └── conditions.ts # Conditional routing
|
|
283
|
+
│ │ │
|
|
284
|
+
│ │ ├── preprocessor/ # Prompt Pre-processor
|
|
285
|
+
│ │ │ ├── index.ts
|
|
286
|
+
│ │ │ ├── system-prompts.ts # Optimal system prompt templates
|
|
287
|
+
│ │ │ ├── dedup.ts # Context deduplication
|
|
288
|
+
│ │ │ ├── clarity.ts # Instruction clarity optimization
|
|
289
|
+
│ │ │ └── context-optimize.ts # Code context optimization
|
|
290
|
+
│ │ │
|
|
291
|
+
│ │ ├── context/ # Conversation Context Manager
|
|
292
|
+
│ │ │ ├── index.ts
|
|
293
|
+
│ │ │ ├── window.ts # Sliding window
|
|
294
|
+
│ │ │ ├── summarizer.ts # Auto-summarization
|
|
295
|
+
│ │ │ ├── ranker.ts # Relevance ranking
|
|
296
|
+
│ │ │ └── budget.ts # Token budget allocation
|
|
297
|
+
│ │ │
|
|
298
|
+
│ │ ├── forensics/ # Smart Request Forensics
|
|
299
|
+
│ │ │ ├── index.ts
|
|
300
|
+
│ │ │ ├── analyzer.ts # Error analyzer
|
|
301
|
+
│ │ │ ├── root-cause.ts # Root cause detection
|
|
302
|
+
│ │ │ └── suggestions.ts # Auto-suggestions
|
|
303
|
+
│ │ │
|
|
304
|
+
│ │ ├── prediction/ # Predictive Cost Engine
|
|
305
|
+
│ │ │ ├── index.ts
|
|
306
|
+
│ │ │ ├── forecaster.ts # Usage forecasting
|
|
307
|
+
│ │ │ ├── budgetter.ts # Budget management
|
|
308
|
+
│ │ │ ├── optimizer.ts # Auto-optimization rules
|
|
309
|
+
│ │ │ └── arbitrage.ts # Provider arbitrage
|
|
310
|
+
│ │ │
|
|
311
|
+
│ │ ├── benchmark/ # Model Quality Benchmark
|
|
312
|
+
│ │ │ ├── index.ts
|
|
313
|
+
│ │ │ ├── shadow.ts # Shadow mode A/B testing
|
|
314
|
+
│ │ │ ├── scorer.ts # Quality scoring
|
|
315
|
+
│ │ │ └── compare.ts # Model comparison
|
|
316
|
+
│ │ │
|
|
317
|
+
│ │ ├── namespace/ # Universal Model Namespace
|
|
318
|
+
│ │ │ ├── index.ts
|
|
319
|
+
│ │ │ ├── resolver.ts # Namespace → provider resolution
|
|
320
|
+
│ │ │ ├── aliases.ts # Built-in aliases
|
|
321
|
+
│ │ │ └── tasks.ts # Task type definitions
|
|
322
|
+
│ │ │
|
|
323
|
+
│ │ ├── mcp/ # MCP Gateway
|
|
324
|
+
│ │ │ ├── index.ts
|
|
325
|
+
│ │ │ ├── server.ts # MCP server implementation
|
|
326
|
+
│ │ │ ├── client.ts # MCP client for external servers
|
|
327
|
+
│ │ │ ├── tools.ts # Exposed tools
|
|
328
|
+
│ │ │ └── resources.ts # Exposed resources
|
|
329
|
+
│ │ │
|
|
330
|
+
│ │ ├── skills/ # Dynamic Skill Engine
|
|
331
|
+
│ │ │ ├── index.ts # Skill orchestrator
|
|
332
|
+
│ │ │ ├── types.ts # Skill + SkillGroup interfaces
|
|
333
|
+
│ │ │ ├── registry.ts # Skill registry (CRUD)
|
|
334
|
+
│ │ │ ├── groups.ts # Skill group manager
|
|
335
|
+
│ │ │ ├── rotation/
|
|
336
|
+
│ │ │ │ ├── index.ts # Rotation engine
|
|
337
|
+
│ │ │ │ ├── task-match.ts # Task-based rotation
|
|
338
|
+
│ │ │ │ ├── round-robin.ts # Round-robin rotation
|
|
339
|
+
│ │ │ │ ├── quality-based.ts # Quality-score rotation
|
|
340
|
+
│ │ │ │ ├── schedule.ts # Time-based rotation
|
|
341
|
+
│ │ │ │ └── weighted-random.ts # Weighted random rotation
|
|
342
|
+
│ │ │ ├── forge.ts # Skill creation & validation
|
|
343
|
+
│ │ │ ├── importer/
|
|
344
|
+
│ │ │ │ ├── openclaw.ts # OpenClaw skill importer
|
|
345
|
+
│ │ │ │ ├── url.ts # URL-based importer
|
|
346
|
+
│ │ │ │ ├── file.ts # File-based importer
|
|
347
|
+
│ │ │ │ └── converter.ts # Format converter
|
|
348
|
+
│ │ │ ├── executor.ts # Apply skill to request
|
|
349
|
+
│ │ │ └── quality-tracker.ts # Track skill quality scores
|
|
350
|
+
│ │ │
|
|
351
|
+
│ │ │
|
|
352
|
+
│ │ ├── health/
|
|
353
|
+
│ │ │ ├── index.ts
|
|
354
|
+
│ │ │ ├── checker.ts
|
|
355
|
+
│ │ │ ├── metrics.ts
|
|
356
|
+
│ │ │ └── mesh-health.ts # Mesh-aware health
|
|
357
|
+
│ │ │
|
|
358
|
+
│ │ ├── quota/
|
|
359
|
+
│ │ │ ├── index.ts
|
|
360
|
+
│ │ │ ├── tracker.ts
|
|
361
|
+
│ │ │ ├── scheduler.ts
|
|
362
|
+
│ │ │ └── calculator.ts
|
|
363
|
+
│ │ │
|
|
364
|
+
│ │ ├── fallback/
|
|
365
|
+
│ │ │ ├── index.ts # Fallback orchestrator
|
|
366
|
+
│ │ │ ├── decision-tree.ts # Decision tree fallback
|
|
367
|
+
│ │ │ ├── cooldown.ts
|
|
368
|
+
│ │ │ └── mesh-failover.ts # Mesh-aware failover
|
|
369
|
+
│ │ │
|
|
370
|
+
│ │ ├── analytics/
|
|
371
|
+
│ │ │ ├── index.ts
|
|
372
|
+
│ │ │ ├── aggregator.ts
|
|
373
|
+
│ │ │ ├── exporter.ts
|
|
374
|
+
│ │ │ └── real-time.ts # Real-time metrics
|
|
375
|
+
│ │ │
|
|
376
|
+
│ │ ├── auth/
|
|
377
|
+
│ │ │ ├── jwt.ts
|
|
378
|
+
│ │ │ ├── webauthn.ts # Passwordless auth
|
|
379
|
+
│ │ │ ├── api-key.ts
|
|
380
|
+
│ │ │ └── middleware.ts
|
|
381
|
+
│ │ │
|
|
382
|
+
│ │ ├── middleware/
|
|
383
|
+
│ │ │ ├── rate-limit.ts
|
|
384
|
+
│ │ │ ├── cors.ts
|
|
385
|
+
│ │ │ ├── request-id.ts
|
|
386
|
+
│ │ │ ├── logging.ts
|
|
387
|
+
│ │ │ └── error-handler.ts
|
|
388
|
+
│ │ │
|
|
389
|
+
│ │ ├── plugins/
|
|
390
|
+
│ │ │ ├── index.ts
|
|
391
|
+
│ │ │ ├── types.ts
|
|
392
|
+
│ │ │ ├── loader.ts
|
|
393
|
+
│ │ │ └── built-in/
|
|
394
|
+
│ │ │ ├── pii-redactor.ts
|
|
395
|
+
│ │ │ ├── sentiment.ts
|
|
396
|
+
│ │ │ ├── profanity-filter.ts
|
|
397
|
+
│ │ │ └── response-validator.ts
|
|
398
|
+
│ │ │
|
|
399
|
+
│ │ ├── sync/
|
|
400
|
+
│ │ │ ├── index.ts
|
|
401
|
+
│ │ │ ├── crypto.ts
|
|
402
|
+
│ │ │ ├── scheduler.ts
|
|
403
|
+
│ │ │ └── collaboration.ts # Team sharing
|
|
404
|
+
│ │ │
|
|
405
|
+
│ │ ├── memory/ # Persistent Memory Engine
|
|
406
|
+
│ │ │ ├── index.ts # Memory orchestrator
|
|
407
|
+
│ │ │ ├── episodic.ts # Episodic memory (recent events)
|
|
408
|
+
│ │ │ ├── semantic.ts # Semantic memory (knowledge base)
|
|
409
|
+
│ │ │ ├── procedural.ts # Procedural memory (compiled rules)
|
|
410
|
+
│ │ │ ├── restore.ts # Memory restore on startup
|
|
411
|
+
│ │ │ └── persist.ts # Memory persistence to disk
|
|
412
|
+
│ │ │
|
|
413
|
+
│ │ ├── distiller/ # Experience Distiller
|
|
414
|
+
│ │ │ ├── index.ts # Distiller orchestrator
|
|
415
|
+
│ │ │ ├── aggregator.ts # Aggregate episodic data
|
|
416
|
+
│ │ │ ├── pattern-miner.ts # Extract patterns from episodes
|
|
417
|
+
│ │ │ ├── knowledge-merger.ts # Merge new findings into semantic
|
|
418
|
+
│ │ │ ├── rule-generator.ts # Generate procedural rules
|
|
419
|
+
│ │ │ ├── model-retrainer.ts # Retrain neural router from data
|
|
420
|
+
│ │ │ ├── compactor.ts # Archive old episodic data
|
|
421
|
+
│ │ │ ├── scheduler.ts # Distillation schedule (6h/24h/7d)
|
|
422
|
+
│ │ │ └── anomaly.ts # Anomaly detection
|
|
423
|
+
│ │ │
|
|
424
|
+
│ │ ├── adaptive/ # Adaptive Intelligence Layer
|
|
425
|
+
│ │ │ ├── index.ts # Intelligence orchestrator
|
|
426
|
+
│ │ │ ├── consultant.ts # Consult memory before decisions
|
|
427
|
+
│ │ │ ├── feedback-loop.ts # Learn from outcomes
|
|
428
|
+
│ │ │ ├── confidence.ts # Confidence scoring
|
|
429
|
+
│ │ │ ├── insight-generator.ts # Generate human-readable insights
|
|
430
|
+
│ │ │ └── progress-tracker.ts # Track learning progress over time
|
|
431
|
+
│ │ │
|
|
432
|
+
│ │ └── utils/
|
|
433
|
+
│ │ ├── logger.ts
|
|
434
|
+
│ │ ├── crypto.ts
|
|
435
|
+
│ │ ├── token-counter.ts
|
|
436
|
+
│ │ ├── stream.ts
|
|
437
|
+
│ │ ├── embedding.ts # Embedding utilities
|
|
438
|
+
│ │ └── onnx.ts # ONNX Runtime wrapper
|
|
439
|
+
│ │
|
|
440
|
+
│ └── components/
|
|
441
|
+
│ ├── ui/ # Radix UI + Tailwind
|
|
442
|
+
│ ├── layout/
|
|
443
|
+
│ │ ├── sidebar.tsx
|
|
444
|
+
│ │ ├── header.tsx
|
|
445
|
+
│ │ ├── mobile-nav.tsx
|
|
446
|
+
│ │ └── realtime-provider.tsx # SSE realtime context
|
|
447
|
+
│ ├── command-center/
|
|
448
|
+
│ │ ├── stats-cards.tsx
|
|
449
|
+
│ │ ├── neural-status.tsx
|
|
450
|
+
│ │ ├── cache-stats.tsx
|
|
451
|
+
│ │ ├── live-feed.tsx
|
|
452
|
+
│ │ ├── recommendations.tsx
|
|
453
|
+
│ │ └── cost-ticker.tsx
|
|
454
|
+
│ ├── providers/
|
|
455
|
+
│ │ ├── provider-grid.tsx
|
|
456
|
+
│ │ ├── provider-card.tsx
|
|
457
|
+
│ │ ├── provider-detail.tsx
|
|
458
|
+
│ │ ├── connect-modal.tsx
|
|
459
|
+
│ │ ├── mesh-topology.tsx # Visual mesh network
|
|
460
|
+
│ │ ├── auto-discover.tsx
|
|
461
|
+
│ │ └── health-matrix.tsx
|
|
462
|
+
│ ├── models/
|
|
463
|
+
│ │ ├── model-browser.tsx
|
|
464
|
+
│ │ ├── model-card.tsx
|
|
465
|
+
│ │ ├── benchmark-table.tsx
|
|
466
|
+
│ │ ├── quality-chart.tsx
|
|
467
|
+
│ │ └── namespace-resolver.tsx
|
|
468
|
+
│ ├── routes/
|
|
469
|
+
│ │ ├── combo-list.tsx
|
|
470
|
+
│ │ ├── combo-builder.tsx
|
|
471
|
+
│ │ ├── pipeline-editor.tsx # Visual pipeline builder
|
|
472
|
+
│ │ ├── pipeline-node.tsx
|
|
473
|
+
│ │ └── routing-config.tsx
|
|
474
|
+
│ ├── intelligence/
|
|
475
|
+
│ │ ├── prediction-chart.tsx
|
|
476
|
+
│ │ ├── forensics-panel.tsx
|
|
477
|
+
│ │ ├── pattern-heatmap.tsx
|
|
478
|
+
│ │ ├── recommendation-card.tsx
|
|
479
|
+
│ │ └── neural-dashboard.tsx
|
|
480
|
+
│ ├── memory/ # Memory & Learning UI
|
|
481
|
+
│ │ ├── memory-status.tsx # Memory status overview
|
|
482
|
+
│ │ ├── knowledge-browser.tsx # Browse semantic memory
|
|
483
|
+
│ │ ├── rules-table.tsx # View/edit procedural rules
|
|
484
|
+
│ │ ├── learning-progress.tsx # Learning progress bar
|
|
485
|
+
│ │ ├── insight-feed.tsx # Stream of AI insights
|
|
486
|
+
│ │ ├── distillation-log.tsx # Distillation history
|
|
487
|
+
│ │ └── timeline.tsx # Memory timeline visualization
|
|
488
|
+
│ ├── skills/ # Skill Management UI
|
|
489
|
+
│ │ ├── skill-browser.tsx # Browse all skills
|
|
490
|
+
│ │ ├── skill-card.tsx # Skill preview card
|
|
491
|
+
│ │ ├── skill-forge.tsx # Skill creation form
|
|
492
|
+
│ │ ├── skill-detail.tsx # Skill detail + edit
|
|
493
|
+
│ │ ├── skill-group-manager.tsx # Group CRUD + rotation config
|
|
494
|
+
│ │ ├── skill-rotation-status.tsx # Live rotation indicator
|
|
495
|
+
│ │ ├── skill-performance-table.tsx # Quality/usage stats per skill
|
|
496
|
+
│ │ ├── skill-import-modal.tsx # Import from OpenClaw/URL/file
|
|
497
|
+
│ │ ├── skill-test-panel.tsx # Test skill with sample request
|
|
498
|
+
│ │ └── skill-timeline.tsx # Rotation history visualization
|
|
499
|
+
│ ├── playground/
|
|
500
|
+
│ │ ├── multi-compare.tsx # Side-by-side comparison
|
|
501
|
+
│ │ ├── chat-panel.tsx
|
|
502
|
+
│ │ ├── token-analyzer.tsx
|
|
503
|
+
│ │ ├── pipeline-preview.tsx
|
|
504
|
+
│ │ └── model-selector.tsx
|
|
505
|
+
│ ├── vault/
|
|
506
|
+
│ │ ├── key-manager.tsx
|
|
507
|
+
│ │ ├── oauth-sessions.tsx
|
|
508
|
+
│ │ └── access-log.tsx
|
|
509
|
+
│ └── shared/
|
|
510
|
+
│ ├── health-badge.tsx
|
|
511
|
+
│ ├── quota-bar.tsx
|
|
512
|
+
│ ├── cost-badge.tsx
|
|
513
|
+
│ ├── quality-score.tsx
|
|
514
|
+
│ ├── latency-sparkline.tsx
|
|
515
|
+
│ └── loading-skeleton.tsx
|
|
516
|
+
│
|
|
517
|
+
├── models/ # ML Models
|
|
518
|
+
│ ├── neural-router/ # ONNX neural router
|
|
519
|
+
│ │ ├── model.onnx
|
|
520
|
+
│ │ ├── tokenizer.json
|
|
521
|
+
│ │ └── labels.json
|
|
522
|
+
│ └── embeddings/ # Embedding models
|
|
523
|
+
│ ├── minilm-l6-v2/
|
|
524
|
+
│ │ ├── model.onnx
|
|
525
|
+
│ │ └── tokenizer.json
|
|
526
|
+
│ └── tfidf/ # Lightweight fallback
|
|
527
|
+
│ └── vocab.json
|
|
528
|
+
│
|
|
529
|
+
├── drizzle/
|
|
530
|
+
│ ├── 0001_initial.sql
|
|
531
|
+
│ ├── 0002_vector.sql
|
|
532
|
+
│ ├── 0003_benchmark.sql
|
|
533
|
+
│ └── meta/
|
|
534
|
+
│
|
|
535
|
+
├── public/
|
|
536
|
+
│ ├── providers/ # Provider logos
|
|
537
|
+
│ └── favicon.svg
|
|
538
|
+
│
|
|
539
|
+
├── tests/
|
|
540
|
+
│ ├── unit/
|
|
541
|
+
│ │ ├── neural-router.test.ts
|
|
542
|
+
│ │ ├── semantic-cache.test.ts
|
|
543
|
+
│ │ ├── squeezer.test.ts
|
|
544
|
+
│ │ ├── pipeline.test.ts
|
|
545
|
+
│ │ ├── forensics.test.ts
|
|
546
|
+
│ │ ├── namespace.test.ts
|
|
547
|
+
│ │ ├── mesh.test.ts
|
|
548
|
+
│ │ ├── translate.test.ts
|
|
549
|
+
│ │ └── prediction.test.ts
|
|
550
|
+
│ ├── integration/
|
|
551
|
+
│ │ ├── providers.test.ts
|
|
552
|
+
│ │ ├── api-v1.test.ts
|
|
553
|
+
│ │ ├── mcp.test.ts
|
|
554
|
+
│ │ └── full-pipeline.test.ts
|
|
555
|
+
│ └── e2e/
|
|
556
|
+
│ ├── command-center.spec.ts
|
|
557
|
+
│ ├── playground.spec.ts
|
|
558
|
+
│ └── provider-setup.spec.ts
|
|
559
|
+
│
|
|
560
|
+
├── scripts/
|
|
561
|
+
│ ├── setup.sh
|
|
562
|
+
│ ├── setup.ps1
|
|
563
|
+
│ ├── download-models.ts # Download ML models
|
|
564
|
+
│ └── train-router.ts # Train neural router
|
|
565
|
+
│
|
|
566
|
+
├── .env.example
|
|
567
|
+
├── .gitignore
|
|
568
|
+
├── package.json
|
|
569
|
+
├── tsconfig.json
|
|
570
|
+
├── next.config.mjs
|
|
571
|
+
├── tailwind.config.ts
|
|
572
|
+
├── postcss.config.mjs
|
|
573
|
+
├── drizzle.config.ts
|
|
574
|
+
├── vitest.config.ts
|
|
575
|
+
├── playwright.config.ts
|
|
576
|
+
├── Makefile
|
|
577
|
+
├── PRD.md
|
|
578
|
+
├── PLAN.md
|
|
579
|
+
└── README.md
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
---
|
|
583
|
+
|
|
584
|
+
## 1. Phase 1 — Foundation (Minggu 1-2)
|
|
585
|
+
|
|
586
|
+
### 1.1 Project Bootstrap (Hari 1-2)
|
|
587
|
+
|
|
588
|
+
**Tasks:**
|
|
589
|
+
```bash
|
|
590
|
+
# Create Next.js project
|
|
591
|
+
npx create-next-app@latest adnify \
|
|
592
|
+
--typescript --tailwind --eslint --app --src-dir \
|
|
593
|
+
--import-alias "@/*" --turbopack
|
|
594
|
+
|
|
595
|
+
# Core dependencies
|
|
596
|
+
npm install better-sqlite3 drizzle-orm zod pino jose bcryptjs
|
|
597
|
+
npm install onnxruntime-node # ML inference
|
|
598
|
+
npm install @tremor/react tremor # Dashboard charts
|
|
599
|
+
|
|
600
|
+
# UI dependencies
|
|
601
|
+
npm install @radix-ui/react-dialog @radix-ui/react-tabs
|
|
602
|
+
npm install @radix-ui/react-dropdown-menu @radix-ui/react-tooltip
|
|
603
|
+
npm install lucide-react class-variance-authority clsx tailwind-merge
|
|
604
|
+
|
|
605
|
+
# Dev dependencies
|
|
606
|
+
npm install -D drizzle-kit vitest @playwright/test
|
|
607
|
+
npm install -D @types/better-sqlite3 @types/bcryptjs
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
**Deliverables:**
|
|
611
|
+
- [x] Project initialized with Next.js 15
|
|
612
|
+
- [x] All dependencies installed
|
|
613
|
+
- [x] Bun support configured
|
|
614
|
+
- [x] `npm run dev` works
|
|
615
|
+
|
|
616
|
+
### 1.2 Database + Vector Support (Hari 3-4)
|
|
617
|
+
|
|
618
|
+
**Tasks:**
|
|
619
|
+
1. Drizzle schema dengan semua tabel + vector columns
|
|
620
|
+
2. SQLite dengan WAL mode + vector0 extension
|
|
621
|
+
3. Auto-migration on startup
|
|
622
|
+
4. Seed data (default settings, namespace aliases)
|
|
623
|
+
5. Vector operations (insert, similarity search)
|
|
624
|
+
|
|
625
|
+
**Key Schema Additions vs v1:**
|
|
626
|
+
```sql
|
|
627
|
+
-- Semantic Cache with embeddings
|
|
628
|
+
CREATE TABLE semantic_cache (
|
|
629
|
+
id TEXT PRIMARY KEY,
|
|
630
|
+
embedding BLOB NOT NULL, -- 384-dim float32 vector
|
|
631
|
+
prompt_hash TEXT NOT NULL,
|
|
632
|
+
prompt_text TEXT NOT NULL,
|
|
633
|
+
response_text TEXT NOT NULL,
|
|
634
|
+
model TEXT NOT NULL,
|
|
635
|
+
input_tokens INTEGER,
|
|
636
|
+
output_tokens INTEGER,
|
|
637
|
+
similarity_threshold REAL DEFAULT 0.95,
|
|
638
|
+
hits INTEGER DEFAULT 0,
|
|
639
|
+
quality_score REAL,
|
|
640
|
+
expires_at DATETIME NOT NULL,
|
|
641
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
642
|
+
);
|
|
643
|
+
|
|
644
|
+
-- Neural Router training data
|
|
645
|
+
CREATE TABLE router_training_data (
|
|
646
|
+
id TEXT PRIMARY KEY,
|
|
647
|
+
features TEXT NOT NULL, -- JSON feature vector
|
|
648
|
+
selected_provider TEXT NOT NULL,
|
|
649
|
+
selected_model TEXT NOT NULL,
|
|
650
|
+
outcome TEXT NOT NULL, -- 'success', 'timeout', 'error', 'rate_limited'
|
|
651
|
+
latency_ms INTEGER,
|
|
652
|
+
cost REAL,
|
|
653
|
+
quality_score REAL,
|
|
654
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
655
|
+
);
|
|
656
|
+
|
|
657
|
+
-- Model Benchmarks
|
|
658
|
+
CREATE TABLE model_benchmarks (
|
|
659
|
+
id TEXT PRIMARY KEY,
|
|
660
|
+
model TEXT NOT NULL,
|
|
661
|
+
task_type TEXT NOT NULL,
|
|
662
|
+
latency_ms INTEGER,
|
|
663
|
+
tokens_used INTEGER,
|
|
664
|
+
quality_score REAL,
|
|
665
|
+
cost REAL,
|
|
666
|
+
provider_id TEXT,
|
|
667
|
+
is_shadow BOOLEAN DEFAULT FALSE,
|
|
668
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
669
|
+
);
|
|
670
|
+
|
|
671
|
+
-- Pipeline configurations
|
|
672
|
+
CREATE TABLE pipelines (
|
|
673
|
+
id TEXT PRIMARY KEY,
|
|
674
|
+
name TEXT NOT NULL UNIQUE,
|
|
675
|
+
description TEXT,
|
|
676
|
+
nodes TEXT NOT NULL, -- JSON: pipeline node config
|
|
677
|
+
connections TEXT NOT NULL, -- JSON: node connections
|
|
678
|
+
is_default BOOLEAN DEFAULT FALSE,
|
|
679
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
680
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
681
|
+
);
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
### 1.3 Provider Adapter System + Mesh (Hari 5-8)
|
|
685
|
+
|
|
686
|
+
**Tasks:**
|
|
687
|
+
1. Provider adapter interface (enhanced with mesh support)
|
|
688
|
+
2. Base adapter with retry, timeout, proxy support
|
|
689
|
+
3. Provider registry with mesh awareness
|
|
690
|
+
4. Provider mesh — track which providers serve same models
|
|
691
|
+
5. Implement 5 initial providers:
|
|
692
|
+
- OpenAI, Anthropic, Gemini, DeepSeek, OpenRouter
|
|
693
|
+
|
|
694
|
+
**Mesh Network Implementation:**
|
|
695
|
+
```typescript
|
|
696
|
+
interface ProviderMesh {
|
|
697
|
+
// Given a model, find all providers that serve it
|
|
698
|
+
resolveModel(modelId: string): MeshProvider[]
|
|
699
|
+
|
|
700
|
+
// Given a model + strategy, pick optimal provider
|
|
701
|
+
selectProvider(modelId: string, strategy: RoutingStrategy): ProviderAccount
|
|
702
|
+
|
|
703
|
+
// Track provider-model relationships
|
|
704
|
+
updateModelRegistry(): Promise<void>
|
|
705
|
+
|
|
706
|
+
// Health-aware routing
|
|
707
|
+
getHealthyProviders(modelId: string): MeshProvider[]
|
|
708
|
+
|
|
709
|
+
// Cost cascade: free → sub → cheap → paid
|
|
710
|
+
getCostOptimalProviders(modelId: string): MeshProvider[]
|
|
711
|
+
}
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
### 1.4 Basic Router + Fallback + API (Hari 9-14)
|
|
715
|
+
|
|
716
|
+
**Tasks:**
|
|
717
|
+
1. Request pipeline engine (basic, without ML)
|
|
718
|
+
2. Priority-based routing strategy
|
|
719
|
+
3. Decision-tree fallback engine
|
|
720
|
+
4. Format translation (OpenAI, Claude, Gemini)
|
|
721
|
+
5. API endpoints (v1/chat/completions, v1/models, v1/messages)
|
|
722
|
+
6. Middleware (auth, CORS, rate-limit, request-id, logging)
|
|
723
|
+
7. Basic dashboard shell (layout + sidebar)
|
|
724
|
+
|
|
725
|
+
**Fallback Decision Tree:**
|
|
726
|
+
```
|
|
727
|
+
Request arrives
|
|
728
|
+
│
|
|
729
|
+
├─ Check Semantic Cache → Hit? → Return cached
|
|
730
|
+
│ └─ Miss → Continue
|
|
731
|
+
│
|
|
732
|
+
├─ Check Provider Health → Healthy?
|
|
733
|
+
│ ├─ Yes → Route to primary provider
|
|
734
|
+
│ │ ├─ Success → Return response
|
|
735
|
+
│ │ ├─ 429 → Rotate account → Retry (max 3x)
|
|
736
|
+
│ │ │ └─ Still 429 → Mesh failover
|
|
737
|
+
│ │ ├─ Timeout → Mesh failover
|
|
738
|
+
│ │ └─ Error → Mesh failover
|
|
739
|
+
│ │
|
|
740
|
+
│ └─ No → Mesh failover (skip unhealthy)
|
|
741
|
+
│
|
|
742
|
+
└─ Mesh failover:
|
|
743
|
+
├─ Find alternative providers for same model
|
|
744
|
+
├─ Filter by health + quota
|
|
745
|
+
├─ Sort by cost (free first)
|
|
746
|
+
└─ Try each until success or all exhausted
|
|
747
|
+
```
|
|
748
|
+
|
|
749
|
+
**Deliverables Phase 1:**
|
|
750
|
+
- [x] 5 providers working
|
|
751
|
+
- [x] Mesh failover working
|
|
752
|
+
- [x] OpenAI + Claude compatible API
|
|
753
|
+
- [x] Basic dashboard shell
|
|
754
|
+
- [x] All middleware active
|
|
755
|
+
|
|
756
|
+
---
|
|
757
|
+
|
|
758
|
+
## 2. Phase 2 — Intelligence Engine (Minggu 3-5)
|
|
759
|
+
|
|
760
|
+
### 2.1 Semantic Cache (Hari 15-18)
|
|
761
|
+
|
|
762
|
+
**Tasks:**
|
|
763
|
+
1. Download + bundle MiniLM-L6-v2 ONNX model (22MB)
|
|
764
|
+
2. Implement embedding generator (`src/lib/cache/embedding.ts`)
|
|
765
|
+
- Tokenize input → Run ONNX inference → L2 normalize → 384-dim vector
|
|
766
|
+
- Target: <15ms per embedding on CPU
|
|
767
|
+
3. Implement vector storage in SQLite (`src/lib/db/vector.ts`)
|
|
768
|
+
- Store as BLOB (float32 array)
|
|
769
|
+
- Brute-force cosine similarity (acceptable for <10K entries)
|
|
770
|
+
- Optional: sqlite-vec extension for larger caches
|
|
771
|
+
4. Implement semantic cache (`src/lib/cache/semantic.ts`)
|
|
772
|
+
- Generate embedding for incoming prompt
|
|
773
|
+
- Search for similar entries (threshold configurable)
|
|
774
|
+
- Return cached response if hit
|
|
775
|
+
- Store new response with embedding on miss
|
|
776
|
+
5. Cache eviction policy (`src/lib/cache/eviction.ts`)
|
|
777
|
+
- LRU + TTL + quality-based eviction
|
|
778
|
+
- Prefer keeping high-quality cached responses
|
|
779
|
+
|
|
780
|
+
**Performance Targets:**
|
|
781
|
+
- Embedding generation: <15ms
|
|
782
|
+
- Similarity search: <10ms (for 10K entries)
|
|
783
|
+
- Cache hit rate: 15-30%
|
|
784
|
+
|
|
785
|
+
### 2.2 Adaptive Token Squeezer (Hari 19-23)
|
|
786
|
+
|
|
787
|
+
**Tasks:**
|
|
788
|
+
1. Content classifier (`src/lib/squeezer/classifier.ts`)
|
|
789
|
+
- Regex patterns for initial detection
|
|
790
|
+
- AST parser for code detection
|
|
791
|
+
- Confidence scoring
|
|
792
|
+
|
|
793
|
+
2. Multi-pass compression pipeline (`src/lib/squeezer/pipeline.ts`)
|
|
794
|
+
```
|
|
795
|
+
Pass 1: Classify content type
|
|
796
|
+
Pass 2: Apply type-specific filter
|
|
797
|
+
Pass 3: Verify quality score
|
|
798
|
+
Pass 4: If quality < threshold, reduce aggressiveness and retry
|
|
799
|
+
```
|
|
800
|
+
|
|
801
|
+
3. Implement filters:
|
|
802
|
+
- `git-diff-semantic.ts` — Parse hunks, keep meaningful changes
|
|
803
|
+
- `code-ast.ts` — AST-based compression (remove comments, whitespace, collapse)
|
|
804
|
+
- `context-dedup.ts` — Detect and remove duplicate information
|
|
805
|
+
- `adaptive-general.ts` — Learn optimal compression from feedback
|
|
806
|
+
|
|
807
|
+
4. Language-aware compressors:
|
|
808
|
+
- JavaScript/TypeScript: Remove type annotations, collapse arrow functions
|
|
809
|
+
- Python: Remove docstrings, collapse comprehensions
|
|
810
|
+
- Go: Remove error handling boilerplate
|
|
811
|
+
- Rust: Remove lifetime annotations
|
|
812
|
+
- Generic: Universal code compression
|
|
813
|
+
|
|
814
|
+
5. Token budget allocator (`src/lib/squeezer/budget.ts`)
|
|
815
|
+
- Calculate context fill percentage
|
|
816
|
+
- Select compression level accordingly
|
|
817
|
+
- Allocate budget per message type
|
|
818
|
+
|
|
819
|
+
6. Quality scoring (`src/lib/squeezer/quality.ts`)
|
|
820
|
+
- Verify no syntax errors in compressed code
|
|
821
|
+
- Verify no information loss (checksums)
|
|
822
|
+
- Score from 0.0 to 1.0
|
|
823
|
+
|
|
824
|
+
### 2.3 Neural Router (Hari 24-28)
|
|
825
|
+
|
|
826
|
+
**Tasks:**
|
|
827
|
+
1. Feature extraction (`src/lib/neural/features.ts`)
|
|
828
|
+
```typescript
|
|
829
|
+
interface RequestFeatures {
|
|
830
|
+
hourOfDay: number // 0-23
|
|
831
|
+
dayOfWeek: number // 0-6
|
|
832
|
+
promptLength: number // token count
|
|
833
|
+
hasCode: boolean // code detection
|
|
834
|
+
hasTools: boolean // tool_use detection
|
|
835
|
+
isStreaming: boolean
|
|
836
|
+
temperature: number
|
|
837
|
+
taskType: string // code, chat, reason, etc.
|
|
838
|
+
modelFamily: string // claude, gpt, gemini, etc.
|
|
839
|
+
budgetUsed: number // % of monthly budget
|
|
840
|
+
providerHealthScores: Map<string, number>
|
|
841
|
+
}
|
|
842
|
+
```
|
|
843
|
+
|
|
844
|
+
2. ONNX model (`src/lib/neural/model.ts`)
|
|
845
|
+
- Simple neural network: Input(features) → Dense(64) → ReLU → Dense(32) → Softmax → Output(provider)
|
|
846
|
+
- Exported to ONNX for fast inference
|
|
847
|
+
- Initial model: Rule-based (neural takes over after training)
|
|
848
|
+
|
|
849
|
+
3. Training pipeline (`src/lib/neural/trainer.ts`)
|
|
850
|
+
- Collect training data from request_logs
|
|
851
|
+
- Train on background thread every 1000 requests or 1 hour
|
|
852
|
+
- Validate accuracy before deploying
|
|
853
|
+
- Rollback if accuracy drops
|
|
854
|
+
|
|
855
|
+
4. Predictor (`src/lib/neural/predictor.ts`)
|
|
856
|
+
- Fast inference: <5ms
|
|
857
|
+
- Returns: provider, confidence, expected_latency, expected_cost
|
|
858
|
+
|
|
859
|
+
5. Feedback loop (`src/lib/neural/feedback.ts`)
|
|
860
|
+
- Record actual outcome vs prediction
|
|
861
|
+
- Calculate accuracy metrics
|
|
862
|
+
- Feed back to training data
|
|
863
|
+
|
|
864
|
+
6. Hybrid mode (`src/lib/neural/strategies/hybrid.ts`)
|
|
865
|
+
- If neural confidence >80% → use neural prediction
|
|
866
|
+
- If confidence 50-80% → blend neural + rule-based
|
|
867
|
+
- If confidence <50% → fall back to rule-based
|
|
868
|
+
|
|
869
|
+
### 2.4 Predictive Cost Engine (Hari 29-32)
|
|
870
|
+
|
|
871
|
+
**Tasks:**
|
|
872
|
+
1. Usage forecaster (`src/lib/prediction/forecaster.ts`)
|
|
873
|
+
- Track daily token usage trend
|
|
874
|
+
- Predict monthly total based on current trajectory
|
|
875
|
+
- Factor in: day of week patterns, project activity, historical data
|
|
876
|
+
|
|
877
|
+
2. Budget manager (`src/lib/prediction/budgetter.ts`)
|
|
878
|
+
- Set monthly budget
|
|
879
|
+
- Track spending vs budget
|
|
880
|
+
- Auto-escalation: normal → cost-saving → budget-conserving → strict-free
|
|
881
|
+
|
|
882
|
+
3. Auto-optimizer (`src/lib/prediction/optimizer.ts`)
|
|
883
|
+
- When budget >60% used → prefer cheap/free providers
|
|
884
|
+
- When budget >80% → cheap only
|
|
885
|
+
- When budget >95% → free only
|
|
886
|
+
- Budget reset → back to normal
|
|
887
|
+
|
|
888
|
+
4. Provider arbitrage (`src/lib/prediction/arbitrage.ts`)
|
|
889
|
+
- For each request, calculate cost across all available providers
|
|
890
|
+
- Auto-select cheapest available
|
|
891
|
+
- Show savings vs most expensive option
|
|
892
|
+
|
|
893
|
+
5. ROI analyzer
|
|
894
|
+
- Track response quality vs cost per model
|
|
895
|
+
- Suggest "best value" models
|
|
896
|
+
- "This model costs 5x more but only 20% better quality"
|
|
897
|
+
|
|
898
|
+
**Deliverables Phase 2:**
|
|
899
|
+
- [x] Semantic cache working (15-30% hit rate)
|
|
900
|
+
- [x] Token squeezer with adaptive compression (40-65% savings)
|
|
901
|
+
- [x] Neural router with training pipeline
|
|
902
|
+
- [x] Predictive cost engine with auto-optimization
|
|
903
|
+
- [x] Provider arbitrage working
|
|
904
|
+
- [x] Persistent Memory Engine (episodic + semantic + procedural)
|
|
905
|
+
- [x] Experience Distiller with scheduled compaction
|
|
906
|
+
- [x] Zero-amnesia — all memory survives restart
|
|
907
|
+
|
|
908
|
+
### 2.6 Persistent Memory Engine (Hari 29-32)
|
|
909
|
+
|
|
910
|
+
**Tasks:**
|
|
911
|
+
|
|
912
|
+
1. **Episodic Memory** (`src/lib/memory/episodic.ts`)
|
|
913
|
+
- Store every request/response event as an episode
|
|
914
|
+
- Each episode: timestamp, model, provider, task_type, tokens, latency, cost, quality, outcome
|
|
915
|
+
- Rolling 90-day window (raw detail)
|
|
916
|
+
- Write to SQLite immediately (no data loss)
|
|
917
|
+
```typescript
|
|
918
|
+
interface Episode {
|
|
919
|
+
id: string
|
|
920
|
+
timestamp: Date
|
|
921
|
+
eventType: 'request_success' | 'request_error' | 'fallback' | 'cache_hit' | 'cache_miss' | 'compression' | 'quota_alert'
|
|
922
|
+
model: string
|
|
923
|
+
provider: string
|
|
924
|
+
taskType: string
|
|
925
|
+
inputTokens: number
|
|
926
|
+
outputTokens: number
|
|
927
|
+
tokensSaved: number
|
|
928
|
+
latencyMs: number
|
|
929
|
+
cost: number
|
|
930
|
+
qualityScore: number
|
|
931
|
+
outcome: 'success' | 'timeout' | 'error_429' | 'error_5xx' | 'error_network'
|
|
932
|
+
metadata: Record<string, unknown>
|
|
933
|
+
}
|
|
934
|
+
```
|
|
935
|
+
|
|
936
|
+
2. **Semantic Memory** (`src/lib/memory/semantic.ts`)
|
|
937
|
+
- Permanent knowledge base that grows forever
|
|
938
|
+
- Confidence-weighted merge when updating
|
|
939
|
+
- Categories: model_knowledge, provider_knowledge, user_patterns, compression_patterns, cost_patterns
|
|
940
|
+
```typescript
|
|
941
|
+
interface KnowledgeEntry {
|
|
942
|
+
id: string
|
|
943
|
+
category: string
|
|
944
|
+
subject: string // e.g., "glm/glm-5.1", "kr/ (Kiro)", "default_user"
|
|
945
|
+
key: string // e.g., "avg_latency", "best_for", "preferred_models"
|
|
946
|
+
value: unknown // The knowledge value
|
|
947
|
+
confidence: number // 0-1, based on sample size
|
|
948
|
+
sampleCount: number // How many data points
|
|
949
|
+
lastUpdated: Date
|
|
950
|
+
source: 'distilled' | 'manual' | 'auto_detected'
|
|
951
|
+
}
|
|
952
|
+
```
|
|
953
|
+
|
|
954
|
+
3. **Procedural Memory** (`src/lib/memory/procedural.ts`)
|
|
955
|
+
- Auto-generated rules from patterns
|
|
956
|
+
- Rules have confidence, can be verified or auto-generated
|
|
957
|
+
- Categories: routing_rules, fallback_rules, compression_rules, cost_rules
|
|
958
|
+
```typescript
|
|
959
|
+
interface ProceduralRule {
|
|
960
|
+
id: string
|
|
961
|
+
category: string
|
|
962
|
+
condition: string // e.g., "task_type == 'code' AND hour IN [9,10,11]"
|
|
963
|
+
action: string // e.g., "prefer glm/glm-5.1"
|
|
964
|
+
confidence: number // 0-1
|
|
965
|
+
sampleCount: number
|
|
966
|
+
status: 'auto_generated' | 'verified' | 'review' | 'disabled'
|
|
967
|
+
createdAt: Date
|
|
968
|
+
verifiedAt?: Date
|
|
969
|
+
}
|
|
970
|
+
```
|
|
971
|
+
|
|
972
|
+
4. **Memory Persistence** (`src/lib/memory/persist.ts`)
|
|
973
|
+
- Save all 3 memory types to `~/.adnify/memory/`
|
|
974
|
+
- Episodic: SQLite `episodes.db` (rolling 90-day)
|
|
975
|
+
- Semantic: SQLite `knowledge.db` (permanent)
|
|
976
|
+
- Procedural: SQLite `rules.db` (permanent)
|
|
977
|
+
- Auto-backup before distillation
|
|
978
|
+
- Crash-safe writes (WAL mode)
|
|
979
|
+
|
|
980
|
+
5. **Memory Restore** (`src/lib/memory/restore.ts`)
|
|
981
|
+
- On startup, load all 3 memory databases
|
|
982
|
+
- Rebuild in-memory indices from disk
|
|
983
|
+
- Validate integrity (checksums)
|
|
984
|
+
- Resume exactly where left off — zero amnesia
|
|
985
|
+
- Show restoration status in dashboard: "Restored 12,340 episodes, 847 knowledge entries"
|
|
986
|
+
|
|
987
|
+
6. **Memory Orchestrator** (`src/lib/memory/index.ts`)
|
|
988
|
+
- Unified API for all memory operations
|
|
989
|
+
- `recordEpisode(event)` — Store new event
|
|
990
|
+
- `queryKnowledge(subject, key)` — Look up knowledge
|
|
991
|
+
- `getRules(category)` — Get applicable rules
|
|
992
|
+
- `getStatus()` — Memory statistics for dashboard
|
|
993
|
+
|
|
994
|
+
**Database Schema for Memory:**
|
|
995
|
+
```sql
|
|
996
|
+
-- Episodic Memory (rolling 90-day)
|
|
997
|
+
CREATE TABLE episodes (
|
|
998
|
+
id TEXT PRIMARY KEY,
|
|
999
|
+
timestamp DATETIME NOT NULL,
|
|
1000
|
+
event_type TEXT NOT NULL,
|
|
1001
|
+
model TEXT,
|
|
1002
|
+
provider TEXT,
|
|
1003
|
+
task_type TEXT,
|
|
1004
|
+
input_tokens INTEGER,
|
|
1005
|
+
output_tokens INTEGER,
|
|
1006
|
+
tokens_saved INTEGER DEFAULT 0,
|
|
1007
|
+
latency_ms INTEGER,
|
|
1008
|
+
cost REAL DEFAULT 0,
|
|
1009
|
+
quality_score REAL,
|
|
1010
|
+
outcome TEXT,
|
|
1011
|
+
metadata TEXT, -- JSON
|
|
1012
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
1013
|
+
);
|
|
1014
|
+
CREATE INDEX idx_episodes_timestamp ON episodes(timestamp);
|
|
1015
|
+
CREATE INDEX idx_episodes_model ON episodes(model);
|
|
1016
|
+
CREATE INDEX idx_episodes_provider ON episodes(provider);
|
|
1017
|
+
|
|
1018
|
+
-- Semantic Memory (permanent knowledge)
|
|
1019
|
+
CREATE TABLE knowledge (
|
|
1020
|
+
id TEXT PRIMARY KEY,
|
|
1021
|
+
category TEXT NOT NULL,
|
|
1022
|
+
subject TEXT NOT NULL,
|
|
1023
|
+
key TEXT NOT NULL,
|
|
1024
|
+
value TEXT NOT NULL, -- JSON
|
|
1025
|
+
confidence REAL DEFAULT 0,
|
|
1026
|
+
sample_count INTEGER DEFAULT 0,
|
|
1027
|
+
source TEXT DEFAULT 'distilled',
|
|
1028
|
+
last_updated DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
1029
|
+
UNIQUE(category, subject, key)
|
|
1030
|
+
);
|
|
1031
|
+
CREATE INDEX idx_knowledge_lookup ON knowledge(category, subject, key);
|
|
1032
|
+
|
|
1033
|
+
-- Procedural Memory (compiled rules)
|
|
1034
|
+
CREATE TABLE procedural_rules (
|
|
1035
|
+
id TEXT PRIMARY KEY,
|
|
1036
|
+
category TEXT NOT NULL,
|
|
1037
|
+
condition TEXT NOT NULL,
|
|
1038
|
+
action TEXT NOT NULL,
|
|
1039
|
+
confidence REAL DEFAULT 0,
|
|
1040
|
+
sample_count INTEGER DEFAULT 0,
|
|
1041
|
+
status TEXT DEFAULT 'auto_generated',
|
|
1042
|
+
priority INTEGER DEFAULT 0,
|
|
1043
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
1044
|
+
verified_at DATETIME,
|
|
1045
|
+
last_applied_at DATETIME,
|
|
1046
|
+
apply_count INTEGER DEFAULT 0,
|
|
1047
|
+
success_count INTEGER DEFAULT 0
|
|
1048
|
+
);
|
|
1049
|
+
CREATE INDEX idx_rules_category ON procedural_rules(category, status);
|
|
1050
|
+
|
|
1051
|
+
-- Distillation Log
|
|
1052
|
+
CREATE TABLE distillation_log (
|
|
1053
|
+
id TEXT PRIMARY KEY,
|
|
1054
|
+
started_at DATETIME NOT NULL,
|
|
1055
|
+
completed_at DATETIME,
|
|
1056
|
+
episodes_processed INTEGER,
|
|
1057
|
+
patterns_found INTEGER,
|
|
1058
|
+
rules_generated INTEGER,
|
|
1059
|
+
rules_updated INTEGER,
|
|
1060
|
+
model_retrained BOOLEAN DEFAULT FALSE,
|
|
1061
|
+
model_accuracy_before REAL,
|
|
1062
|
+
model_accuracy_after REAL,
|
|
1063
|
+
knowledge_entries_added INTEGER,
|
|
1064
|
+
knowledge_entries_updated INTEGER,
|
|
1065
|
+
status TEXT DEFAULT 'running',
|
|
1066
|
+
error_message TEXT,
|
|
1067
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
1068
|
+
);
|
|
1069
|
+
```
|
|
1070
|
+
|
|
1071
|
+
### 2.7 Experience Distiller (Hari 33-35)
|
|
1072
|
+
|
|
1073
|
+
**Tasks:**
|
|
1074
|
+
|
|
1075
|
+
1. **Distiller Orchestrator** (`src/lib/distiller/index.ts`)
|
|
1076
|
+
- Background job scheduler
|
|
1077
|
+
- Runs every 6 hours or every 1000 new episodes
|
|
1078
|
+
- Sequential pipeline: Aggregate → Mine Patterns → Merge Knowledge → Generate Rules → Retrain → Compact
|
|
1079
|
+
- Logs every distillation run
|
|
1080
|
+
|
|
1081
|
+
2. **Aggregator** (`src/lib/distiller/aggregator.ts`)
|
|
1082
|
+
- Query all new episodes since last distillation
|
|
1083
|
+
- Group by: provider, model, task_type, hour_of_day, outcome
|
|
1084
|
+
- Calculate: avg, p50, p95, success_rate, error_rate, avg_cost, avg_tokens
|
|
1085
|
+
- Output: structured aggregation tables
|
|
1086
|
+
|
|
1087
|
+
3. **Pattern Miner** (`src/lib/distiller/pattern-miner.ts`)
|
|
1088
|
+
- Statistical pattern mining:
|
|
1089
|
+
- Correlation: "When provider X fails, provider Y succeeds 94% of the time"
|
|
1090
|
+
- Time patterns: "User does 45% more code reviews on Fridays"
|
|
1091
|
+
- Quality patterns: "Model X gives 92% quality for code, but only 78% for reasoning"
|
|
1092
|
+
- Cost patterns: "GLM is 15x cheaper with only 7% quality loss"
|
|
1093
|
+
- Anomaly detection: "Provider X latency increased 3x today"
|
|
1094
|
+
- Output: list of (pattern, confidence, sample_count)
|
|
1095
|
+
|
|
1096
|
+
4. **Knowledge Merger** (`src/lib/distiller/knowledge-merger.ts`)
|
|
1097
|
+
- Take patterns from miner
|
|
1098
|
+
- Confidence-weighted merge with existing knowledge:
|
|
1099
|
+
```
|
|
1100
|
+
old_value: 0.85, old_samples: 2840, old_confidence: 0.94
|
|
1101
|
+
new_value: 0.83, new_samples: 580, new_confidence: 0.88
|
|
1102
|
+
weight = 580 / (580 + 2840) = 0.17
|
|
1103
|
+
merged_value = 0.85 * 0.83 + 0.83 * 0.17 = 0.847
|
|
1104
|
+
merged_samples = 3420
|
|
1105
|
+
merged_confidence = 0.93
|
|
1106
|
+
```
|
|
1107
|
+
- Never decrease confidence without reason
|
|
1108
|
+
- Flag contradictions for review
|
|
1109
|
+
|
|
1110
|
+
5. **Rule Generator** (`src/lib/distiller/rule-generator.ts`)
|
|
1111
|
+
- Convert high-confidence patterns (>85%) into procedural rules
|
|
1112
|
+
- Rule format: IF condition THEN action (confidence: X%, from N samples)
|
|
1113
|
+
- Categories: routing, fallback, compression, cost
|
|
1114
|
+
- New rules start as 'auto_generated'
|
|
1115
|
+
- After 7 days of successful application → promote to 'verified'
|
|
1116
|
+
- If rule contradicts existing → keep both, flag for user review
|
|
1117
|
+
|
|
1118
|
+
6. **Model Retrainer** (`src/lib/distiller/model-retrainer.ts`)
|
|
1119
|
+
- Retrain Neural Router ONNX model with accumulated data
|
|
1120
|
+
- Scheduled weekly (or manually triggered)
|
|
1121
|
+
- Steps: extract features from episodes → train → validate → deploy if better
|
|
1122
|
+
- Keep old model as fallback if new model underperforms
|
|
1123
|
+
|
|
1124
|
+
7. **Compactor** (`src/lib/distiller/compactor.ts`)
|
|
1125
|
+
- Archive episodic data older than 90 days
|
|
1126
|
+
- Before archiving: ensure all patterns have been extracted
|
|
1127
|
+
- Keep summarized version in semantic memory
|
|
1128
|
+
- VACUUM SQLite to reclaim space
|
|
1129
|
+
- Save distillation checkpoint
|
|
1130
|
+
|
|
1131
|
+
8. **Anomaly Detector** (`src/lib/distiller/anomaly.ts`)
|
|
1132
|
+
- Compare current metrics against historical baselines
|
|
1133
|
+
- Alert on: latency spikes, error rate increases, cost anomalies
|
|
1134
|
+
- Feed anomalies to dashboard as actionable insights
|
|
1135
|
+
- "Provider X latency is 3x higher than usual — consider switching"
|
|
1136
|
+
|
|
1137
|
+
9. **Insight Generator** (`src/lib/adaptive/insight-generator.ts`)
|
|
1138
|
+
- Convert raw patterns into human-readable insights
|
|
1139
|
+
- Examples:
|
|
1140
|
+
- "I've learned that DeepSeek V4 gives you the best results for debugging tasks"
|
|
1141
|
+
- "Your TypeScript compression is now optimized — 52% average savings"
|
|
1142
|
+
- "After 4,500 requests, avg latency improved from 3.8s to 2.1s (45%)"
|
|
1143
|
+
- "Budget alert: at current rate, you'll exceed $50 on June 25"
|
|
1144
|
+
- Insights displayed in dashboard Memory page and Command Center
|
|
1145
|
+
|
|
1146
|
+
---
|
|
1147
|
+
|
|
1148
|
+
## 3. Phase 3 — Advanced Platform (Minggu 6-8)
|
|
1149
|
+
|
|
1150
|
+
### 3.1 Universal Model Namespace (Hari 33-35)
|
|
1151
|
+
|
|
1152
|
+
**Tasks:**
|
|
1153
|
+
1. Namespace resolver (`src/lib/namespace/resolver.ts`)
|
|
1154
|
+
- Parse namespace pattern (best/, fast/, cheap/, free/, auto/, balanced/)
|
|
1155
|
+
- Resolve to concrete model + provider
|
|
1156
|
+
- Cache resolution results
|
|
1157
|
+
|
|
1158
|
+
2. Built-in aliases (`src/lib/namespace/aliases.ts`)
|
|
1159
|
+
- best/code → claude-opus or gpt-5.5 (based on benchmark)
|
|
1160
|
+
- fast/flash → haiku or flash or minimax
|
|
1161
|
+
- free/any → best available free model
|
|
1162
|
+
|
|
1163
|
+
3. Task type detection (`src/lib/namespace/tasks.ts`)
|
|
1164
|
+
- Auto-detect task type from prompt content
|
|
1165
|
+
- Code, chat, reason, review, debug, doc, translate
|
|
1166
|
+
|
|
1167
|
+
### 3.2 Model Quality Benchmark (Hari 36-38)
|
|
1168
|
+
|
|
1169
|
+
**Tasks:**
|
|
1170
|
+
1. Shadow mode testing (`src/lib/benchmark/shadow.ts`)
|
|
1171
|
+
- Send request to primary model (returned to user)
|
|
1172
|
+
- Simultaneously send to shadow model (evaluated silently)
|
|
1173
|
+
- Compare responses
|
|
1174
|
+
|
|
1175
|
+
2. Quality scorer (`src/lib/benchmark/scorer.ts`)
|
|
1176
|
+
- Latency score
|
|
1177
|
+
- Token efficiency score
|
|
1178
|
+
- Code correctness score (syntax check)
|
|
1179
|
+
- User satisfaction proxy (was response retried?)
|
|
1180
|
+
|
|
1181
|
+
3. Benchmark dashboard
|
|
1182
|
+
- Side-by-side model comparison
|
|
1183
|
+
- Quality vs cost chart
|
|
1184
|
+
- "Best value" recommendation
|
|
1185
|
+
|
|
1186
|
+
### 3.3 Prompt Pre-processor (Hari 39-40)
|
|
1187
|
+
|
|
1188
|
+
**Tasks:**
|
|
1189
|
+
1. System prompt templates (`src/lib/preprocessor/system-prompts.ts`)
|
|
1190
|
+
- Optimal prompts per task type
|
|
1191
|
+
- A/B test different system prompts
|
|
1192
|
+
|
|
1193
|
+
2. Context deduplication (`src/lib/preprocessor/dedup.ts`)
|
|
1194
|
+
- Remove repeated information across messages
|
|
1195
|
+
- Detect and collapse duplicate tool outputs
|
|
1196
|
+
|
|
1197
|
+
3. Instruction clarity (`src/lib/preprocessor/clarity.ts`)
|
|
1198
|
+
- Restructure verbose prompts into concise instructions
|
|
1199
|
+
- Preserve intent, reduce tokens
|
|
1200
|
+
|
|
1201
|
+
### 3.4 Request Pipeline Builder (Hari 41-43)
|
|
1202
|
+
|
|
1203
|
+
**Tasks:**
|
|
1204
|
+
1. Pipeline engine (`src/lib/pipeline/index.ts`)
|
|
1205
|
+
- Sequential node execution
|
|
1206
|
+
- Conditional branching
|
|
1207
|
+
- Error handling per node
|
|
1208
|
+
|
|
1209
|
+
2. Built-in pipeline nodes
|
|
1210
|
+
3. Custom JS node support (sandboxed)
|
|
1211
|
+
4. Visual pipeline editor component
|
|
1212
|
+
|
|
1213
|
+
### 3.5 Conversation Context Manager (Hari 44-45)
|
|
1214
|
+
|
|
1215
|
+
**Tasks:**
|
|
1216
|
+
1. Sliding window with summarization
|
|
1217
|
+
2. Relevance ranking using embeddings
|
|
1218
|
+
3. Token budget allocation
|
|
1219
|
+
4. Auto-trim when approaching context limit
|
|
1220
|
+
|
|
1221
|
+
### 3.6 MCP Gateway (Hari 46-48)
|
|
1222
|
+
|
|
1223
|
+
**Tasks:**
|
|
1224
|
+
1. MCP Server implementation
|
|
1225
|
+
- Expose tools (provider health, quota, cost, recommendations)
|
|
1226
|
+
- Expose resources (model list, benchmarks)
|
|
1227
|
+
- Handle MCP protocol messages
|
|
1228
|
+
|
|
1229
|
+
2. MCP Client implementation
|
|
1230
|
+
- Connect to external MCP servers
|
|
1231
|
+
- Proxy tools/resources through Adnify
|
|
1232
|
+
|
|
1233
|
+
### 3.7 Smart Request Forensics (Hari 49-50)
|
|
1234
|
+
|
|
1235
|
+
**Tasks:**
|
|
1236
|
+
1. Error analyzer
|
|
1237
|
+
2. Root cause detector
|
|
1238
|
+
3. Auto-suggestion generator
|
|
1239
|
+
4. Pattern-based recommendation engine
|
|
1240
|
+
|
|
1241
|
+
### 3.8 Dynamic Skill Rotation Engine (Hari 51-54)
|
|
1242
|
+
|
|
1243
|
+
**Tasks:**
|
|
1244
|
+
|
|
1245
|
+
1. **Skill Type System** (`src/lib/skills/types.ts`)
|
|
1246
|
+
- Define Skill interface (id, name, systemPrompt, behavior, rotation config)
|
|
1247
|
+
- Define SkillGroup interface (id, name, skillIds, rotation strategy, state)
|
|
1248
|
+
- Define SkillRotationState (activeSkillId, rotationIndex, lastRotatedAt)
|
|
1249
|
+
|
|
1250
|
+
2. **Skill Registry** (`src/lib/skills/registry.ts`)
|
|
1251
|
+
- CRUD operations for skills (SQLite-backed)
|
|
1252
|
+
- CRUD operations for skill groups
|
|
1253
|
+
- Skill validation (systemPrompt required, rotation config valid)
|
|
1254
|
+
- Search/filter skills by tag, group, task type
|
|
1255
|
+
```typescript
|
|
1256
|
+
interface SkillRegistry {
|
|
1257
|
+
create(skill: Omit<Skill, 'id'>): Promise<Skill>
|
|
1258
|
+
update(id: string, data: Partial<Skill>): Promise<Skill>
|
|
1259
|
+
delete(id: string): Promise<void>
|
|
1260
|
+
get(id: string): Promise<Skill | null>
|
|
1261
|
+
list(filters?: SkillFilters): Promise<Skill[]>
|
|
1262
|
+
|
|
1263
|
+
createGroup(group: Omit<SkillGroup, 'id'>): Promise<SkillGroup>
|
|
1264
|
+
updateGroup(id: string, data: Partial<SkillGroup>): Promise<SkillGroup>
|
|
1265
|
+
deleteGroup(id: string): Promise<void>
|
|
1266
|
+
getGroup(id: string): Promise<SkillGroup | null>
|
|
1267
|
+
listGroups(): Promise<SkillGroup[]>
|
|
1268
|
+
|
|
1269
|
+
addToGroup(skillId: string, groupId: string): Promise<void>
|
|
1270
|
+
removeFromGroup(skillId: string, groupId: string): Promise<void>
|
|
1271
|
+
}
|
|
1272
|
+
```
|
|
1273
|
+
|
|
1274
|
+
3. **Rotation Engine** (`src/lib/skills/rotation/index.ts`)
|
|
1275
|
+
- Central rotation orchestrator
|
|
1276
|
+
- Given a request → determine which group matches → select skill from group
|
|
1277
|
+
- NEVER mix skills — exactly ONE skill per request
|
|
1278
|
+
- Cooldown enforcement (don't re-activate same skill too quickly)
|
|
1279
|
+
|
|
1280
|
+
```typescript
|
|
1281
|
+
interface RotationEngine {
|
|
1282
|
+
// Main entry point: given request context, return active skill (or null)
|
|
1283
|
+
resolveSkill(context: RequestContext): Promise<Skill | null>
|
|
1284
|
+
|
|
1285
|
+
// Force rotate to next skill in group
|
|
1286
|
+
forceRotate(groupId: string): Promise<Skill>
|
|
1287
|
+
|
|
1288
|
+
// Get current rotation state for all groups
|
|
1289
|
+
getRotationStatus(): Promise<Map<string, RotationState>>
|
|
1290
|
+
}
|
|
1291
|
+
```
|
|
1292
|
+
|
|
1293
|
+
4. **Rotation Strategies** (5 implementations):
|
|
1294
|
+
- `task-match.ts` — Match request task_type to skill's taskTypes
|
|
1295
|
+
- `round-robin.ts` — Cycle through skills in order
|
|
1296
|
+
- `quality-based.ts` — Always pick highest quality, occasional rotate for freshness
|
|
1297
|
+
- `schedule.ts` — Time-based rotation (cron-like)
|
|
1298
|
+
- `weighted-random.ts` — Random with quality weights
|
|
1299
|
+
|
|
1300
|
+
5. **Skill Executor** (`src/lib/skills/executor.ts`)
|
|
1301
|
+
- Apply resolved skill to request BEFORE it reaches provider
|
|
1302
|
+
- Inject skill's systemPrompt (replaces default)
|
|
1303
|
+
- Apply behavior overrides (temperature, maxTokens, compression, responseFormat)
|
|
1304
|
+
- Apply model preferences (influence provider selection)
|
|
1305
|
+
- Log which skill was used for quality tracking
|
|
1306
|
+
|
|
1307
|
+
6. **Quality Tracker** (`src/lib/skills/quality-tracker.ts`)
|
|
1308
|
+
- Track quality score per skill (integration with Distiller)
|
|
1309
|
+
- Track: avg_quality, avg_latency, user_acceptance_rate, usage_count
|
|
1310
|
+
- Feed into Distiller for periodic quality updates
|
|
1311
|
+
- Auto-adjust rotation priorities based on quality
|
|
1312
|
+
|
|
1313
|
+
7. **Skill Forge** (`src/lib/skills/forge.ts`)
|
|
1314
|
+
- Skill creation wizard logic
|
|
1315
|
+
- Validate systemPrompt (not empty, reasonable length)
|
|
1316
|
+
- Validate rotation config
|
|
1317
|
+
- Auto-detect task types from systemPrompt content
|
|
1318
|
+
- Auto-suggest group based on skill content
|
|
1319
|
+
|
|
1320
|
+
8. **OpenClaw Importer** (`src/lib/skills/importer/openclaw.ts`)
|
|
1321
|
+
- Fetch skill from OpenClaw registry API
|
|
1322
|
+
- Convert OpenClaw format → Adnify Skill format
|
|
1323
|
+
- Preserve original metadata (author, version, tags)
|
|
1324
|
+
- Map OpenClaw categories → Adnify task types
|
|
1325
|
+
- Import to specified group
|
|
1326
|
+
- Handle import errors gracefully
|
|
1327
|
+
|
|
1328
|
+
9. **Built-in Skills** (seed on first install):
|
|
1329
|
+
- code-architect, debug-detective, code-reviewer
|
|
1330
|
+
- doc-writer, api-designer, test-engineer
|
|
1331
|
+
- perf-optimizer, security-scanner, refactor-pro, sql-architect
|
|
1332
|
+
|
|
1333
|
+
**Database Schema for Skills:**
|
|
1334
|
+
```sql
|
|
1335
|
+
-- Skills
|
|
1336
|
+
CREATE TABLE skills (
|
|
1337
|
+
id TEXT PRIMARY KEY,
|
|
1338
|
+
name TEXT NOT NULL UNIQUE,
|
|
1339
|
+
description TEXT,
|
|
1340
|
+
version TEXT DEFAULT '1.0.0',
|
|
1341
|
+
author TEXT DEFAULT 'user',
|
|
1342
|
+
system_prompt TEXT NOT NULL,
|
|
1343
|
+
behavior TEXT DEFAULT '{}', -- JSON: temperature, maxTokens, etc.
|
|
1344
|
+
rotation_config TEXT NOT NULL, -- JSON: rotation settings
|
|
1345
|
+
group_id TEXT,
|
|
1346
|
+
tags TEXT DEFAULT '[]', -- JSON array
|
|
1347
|
+
quality_score REAL DEFAULT 0,
|
|
1348
|
+
usage_count INTEGER DEFAULT 0,
|
|
1349
|
+
last_used_at DATETIME,
|
|
1350
|
+
enabled BOOLEAN DEFAULT TRUE,
|
|
1351
|
+
source TEXT DEFAULT 'user', -- 'system', 'user', 'openclaw', 'community', 'auto_generated'
|
|
1352
|
+
source_url TEXT,
|
|
1353
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
1354
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
1355
|
+
);
|
|
1356
|
+
CREATE INDEX idx_skills_group ON skills(group_id);
|
|
1357
|
+
CREATE INDEX idx_skills_enabled ON skills(enabled);
|
|
1358
|
+
|
|
1359
|
+
-- Skill Groups
|
|
1360
|
+
CREATE TABLE skill_groups (
|
|
1361
|
+
id TEXT PRIMARY KEY,
|
|
1362
|
+
name TEXT NOT NULL UNIQUE,
|
|
1363
|
+
description TEXT,
|
|
1364
|
+
rotation_strategy TEXT DEFAULT 'round_robin',
|
|
1365
|
+
task_types TEXT DEFAULT '[]', -- JSON: which task types trigger this group
|
|
1366
|
+
active_skill_id TEXT,
|
|
1367
|
+
rotation_index INTEGER DEFAULT 0,
|
|
1368
|
+
enabled BOOLEAN DEFAULT TRUE,
|
|
1369
|
+
last_rotated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
1370
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
1371
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
1372
|
+
);
|
|
1373
|
+
|
|
1374
|
+
-- Skill Quality Tracking (per task type)
|
|
1375
|
+
CREATE TABLE skill_quality (
|
|
1376
|
+
id TEXT PRIMARY KEY,
|
|
1377
|
+
skill_id TEXT NOT NULL REFERENCES skills(id),
|
|
1378
|
+
task_type TEXT NOT NULL,
|
|
1379
|
+
total_requests INTEGER DEFAULT 0,
|
|
1380
|
+
avg_quality_score REAL DEFAULT 0,
|
|
1381
|
+
avg_latency_ms REAL DEFAULT 0,
|
|
1382
|
+
user_acceptance_rate REAL DEFAULT 0,
|
|
1383
|
+
last_updated DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
1384
|
+
UNIQUE(skill_id, task_type)
|
|
1385
|
+
);
|
|
1386
|
+
|
|
1387
|
+
-- Skill Rotation Log
|
|
1388
|
+
CREATE TABLE skill_rotation_log (
|
|
1389
|
+
id TEXT PRIMARY KEY,
|
|
1390
|
+
from_skill_id TEXT,
|
|
1391
|
+
to_skill_id TEXT NOT NULL,
|
|
1392
|
+
group_id TEXT,
|
|
1393
|
+
trigger_type TEXT NOT NULL, -- 'task_match', 'round_robin', 'quality', 'schedule', 'manual'
|
|
1394
|
+
request_id TEXT,
|
|
1395
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
1396
|
+
);
|
|
1397
|
+
```
|
|
1398
|
+
|
|
1399
|
+
### 3.9 Skill Forge UI + OpenClaw Import (Hari 55-56)
|
|
1400
|
+
|
|
1401
|
+
**Tasks:**
|
|
1402
|
+
1. Skill browser page — grid of all skills with filters
|
|
1403
|
+
2. Skill creation form — system prompt editor, behavior config, rotation config
|
|
1404
|
+
3. Skill detail page — view/edit skill, quality stats, rotation history
|
|
1405
|
+
4. Skill group manager — create groups, assign skills, set rotation strategy
|
|
1406
|
+
5. Import modal — OpenClaw URL, local file, community
|
|
1407
|
+
6. Skill test panel — send test request with skill active, see results
|
|
1408
|
+
|
|
1409
|
+
**Deliverables Phase 3:**
|
|
1410
|
+
- [x] Universal namespace working
|
|
1411
|
+
- [x] Quality benchmarks operational
|
|
1412
|
+
- [x] Prompt pre-processor active
|
|
1413
|
+
- [x] Pipeline builder functional
|
|
1414
|
+
- [x] Context manager working
|
|
1415
|
+
- [x] MCP gateway active
|
|
1416
|
+
- [x] Forensics engine working
|
|
1417
|
+
- [x] Adaptive Intelligence Layer connects memory to all decisions
|
|
1418
|
+
- [x] Skill Rotation Engine with 5 rotation strategies
|
|
1419
|
+
- [x] Skill Forge (create, edit, group skills)
|
|
1420
|
+
- [x] OpenClaw skill import working
|
|
1421
|
+
- [x] Skill quality tracking + auto-priority adjustment
|
|
1422
|
+
|
|
1423
|
+
---
|
|
1424
|
+
|
|
1425
|
+
## 4. Phase 4 — Dashboard & UX (Minggu 9-10)
|
|
1426
|
+
|
|
1427
|
+
### 4.1 Command Center (Hari 51-53)
|
|
1428
|
+
|
|
1429
|
+
**Components:**
|
|
1430
|
+
- Real-time stats cards (requests, savings, cost, providers)
|
|
1431
|
+
- Neural Router status panel (mode, confidence, accuracy, recent decisions)
|
|
1432
|
+
- Semantic Cache stats (hit rate, entries, tokens saved)
|
|
1433
|
+
- Live request feed (SSE-based, scrollable)
|
|
1434
|
+
- AI recommendations (actionable suggestions)
|
|
1435
|
+
- Cost ticker (running cost counter)
|
|
1436
|
+
- Memory status widget (learning progress, knowledge count, recent insights)
|
|
1437
|
+
|
|
1438
|
+
### 4.1a Memory Dashboard (Hari 53-54)
|
|
1439
|
+
|
|
1440
|
+
**Components:**
|
|
1441
|
+
- Memory status overview (episodic count, semantic entries, procedural rules)
|
|
1442
|
+
- Learning progress bar (Day 1 → Expert → Mastery)
|
|
1443
|
+
- Knowledge browser (search/filter semantic memory by category)
|
|
1444
|
+
- Procedural rules table (status, confidence, apply count, success rate)
|
|
1445
|
+
- Insight feed (chronological stream of AI-generated insights)
|
|
1446
|
+
- Distillation log (history of distillation runs with results)
|
|
1447
|
+
- Memory timeline (visualization of knowledge growth over time)
|
|
1448
|
+
|
|
1449
|
+
### 4.1b Skills Dashboard (Hari 54-55)
|
|
1450
|
+
|
|
1451
|
+
**Components:**
|
|
1452
|
+
- Skill browser grid (filter by group, tag, source, quality)
|
|
1453
|
+
- Active rotation indicator (which skill is active per group, live)
|
|
1454
|
+
- Skill performance table (usage count, quality score, acceptance rate)
|
|
1455
|
+
- Rotation history timeline (when skills rotated, which trigger)
|
|
1456
|
+
- Skill group overview cards (skills count, rotation strategy, active skill)
|
|
1457
|
+
- Skill comparison (side-by-side quality metrics)
|
|
1458
|
+
|
|
1459
|
+
### 4.2 Provider Management (Hari 54-55)
|
|
1460
|
+
|
|
1461
|
+
**Components:**
|
|
1462
|
+
- Provider grid with health indicators
|
|
1463
|
+
- Mesh topology visualization (which providers cover which models)
|
|
1464
|
+
- Auto-discovery panel (scan system for existing configs)
|
|
1465
|
+
- Connect/Disconnect with OAuth flow
|
|
1466
|
+
- Multi-account management per provider
|
|
1467
|
+
|
|
1468
|
+
### 4.3 Model Browser + Benchmark (Hari 56-57)
|
|
1469
|
+
|
|
1470
|
+
**Components:**
|
|
1471
|
+
- Model table with filters (provider, tier, task, capabilities)
|
|
1472
|
+
- Quality benchmark table with sorting
|
|
1473
|
+
- Namespace resolver (show which providers serve a model)
|
|
1474
|
+
- Multi-model compare launcher
|
|
1475
|
+
|
|
1476
|
+
### 4.4 Multi-Model Playground (Hari 58-60)
|
|
1477
|
+
|
|
1478
|
+
**Components:**
|
|
1479
|
+
- Chat interface with model selector
|
|
1480
|
+
- Side-by-side comparison (2-4 models simultaneously)
|
|
1481
|
+
- Token analyzer (before/after squeezer, before/after pre-processor)
|
|
1482
|
+
- Pipeline preview (show which nodes processed the request)
|
|
1483
|
+
- Raw request/response viewer
|
|
1484
|
+
- Conversation history
|
|
1485
|
+
|
|
1486
|
+
### 4.5 Intelligence Dashboard (Hari 61-62)
|
|
1487
|
+
|
|
1488
|
+
**Components:**
|
|
1489
|
+
- Cost prediction chart (projection to end of month)
|
|
1490
|
+
- Usage heatmap (activity by hour/day)
|
|
1491
|
+
- Pattern analysis (which models used for which tasks)
|
|
1492
|
+
- Forensics panel (recent errors with analysis)
|
|
1493
|
+
- Recommendations feed
|
|
1494
|
+
|
|
1495
|
+
### 4.6 Settings + Vault (Hari 63-64)
|
|
1496
|
+
|
|
1497
|
+
**Components:**
|
|
1498
|
+
- General settings (port, hostname, log level)
|
|
1499
|
+
- Neural Router settings (mode, confidence threshold)
|
|
1500
|
+
- Cache settings (similarity threshold, TTL)
|
|
1501
|
+
- Squeezer settings (aggressiveness, language-aware toggle)
|
|
1502
|
+
- Budget settings (monthly budget, auto-optimization rules)
|
|
1503
|
+
- Pipeline management
|
|
1504
|
+
- API key vault
|
|
1505
|
+
- OAuth session management
|
|
1506
|
+
- Data export/import
|
|
1507
|
+
|
|
1508
|
+
**Deliverables Phase 4:**
|
|
1509
|
+
- [x] Full dashboard operational
|
|
1510
|
+
- [x] All pages functional
|
|
1511
|
+
- [x] Real-time updates via SSE
|
|
1512
|
+
- [x] Mobile responsive
|
|
1513
|
+
- [x] Dark/light theme
|
|
1514
|
+
|
|
1515
|
+
---
|
|
1516
|
+
|
|
1517
|
+
## 5. Phase 5 — Polish & Release (Minggu 11-12)
|
|
1518
|
+
|
|
1519
|
+
### 5.1 Additional Providers (Hari 65-68)
|
|
1520
|
+
|
|
1521
|
+
**Implement 35+ more providers:**
|
|
1522
|
+
OAuth: Claude Code, Codex, GitHub, Cursor, Kiro, Antigravity
|
|
1523
|
+
API Key: Groq, xAI, Mistral, Together, Fireworks, Cerebras, Cohere, GLM, MiniMax, Kimi, SiliconFlow, NVIDIA, Perplexity, Nebius, Chutes, Hyperbolic, Custom
|
|
1524
|
+
Free: OpenCode Free, Vertex AI
|
|
1525
|
+
Local: Ollama, LM Studio
|
|
1526
|
+
|
|
1527
|
+
### 5.2 Plugin System (Hari 69-70)
|
|
1528
|
+
|
|
1529
|
+
**Tasks:**
|
|
1530
|
+
1. Plugin interface with hooks
|
|
1531
|
+
2. Plugin loader (from ~/.adnify/plugins/)
|
|
1532
|
+
3. Sandboxed execution
|
|
1533
|
+
4. Built-in plugins (PII redactor, sentiment, profanity, response validator)
|
|
1534
|
+
|
|
1535
|
+
### 5.3 Testing (Hari 71-74)
|
|
1536
|
+
|
|
1537
|
+
**Unit Tests:**
|
|
1538
|
+
- Neural Router: feature extraction, prediction, training
|
|
1539
|
+
- Semantic Cache: embedding, similarity, hit/miss
|
|
1540
|
+
- Token Squeezer: all filters, pipeline, quality scoring
|
|
1541
|
+
- Pipeline: node execution, conditions, custom nodes
|
|
1542
|
+
- Format Translation: all 8+ formats, round-trip
|
|
1543
|
+
- Namespace: resolution, aliases, task detection
|
|
1544
|
+
- Mesh: topology, failover, cost cascade
|
|
1545
|
+
- Forensics: error analysis, suggestions
|
|
1546
|
+
- Prediction: forecasting, budget management
|
|
1547
|
+
|
|
1548
|
+
**Integration Tests:**
|
|
1549
|
+
- Full request pipeline (input → cache → router → provider → response)
|
|
1550
|
+
- Provider adapters (mock HTTP)
|
|
1551
|
+
- API endpoints
|
|
1552
|
+
- MCP gateway
|
|
1553
|
+
|
|
1554
|
+
**E2E Tests:**
|
|
1555
|
+
- Dashboard login + navigation
|
|
1556
|
+
- Add provider + send request
|
|
1557
|
+
- Create combo + test
|
|
1558
|
+
- Playground multi-model compare
|
|
1559
|
+
- Settings changes persist
|
|
1560
|
+
|
|
1561
|
+
### 5.4 Performance Optimization (Hari 75-76)
|
|
1562
|
+
|
|
1563
|
+
- Embedding generation: batch processing
|
|
1564
|
+
- SQLite query optimization
|
|
1565
|
+
- React component memoization
|
|
1566
|
+
- Bundle size optimization (code splitting)
|
|
1567
|
+
- ONNX model optimization (quantization)
|
|
1568
|
+
|
|
1569
|
+
### 5.5 Documentation (Hari 77-78)
|
|
1570
|
+
|
|
1571
|
+
- README.md — Quick start, features, architecture
|
|
1572
|
+
- API.md — Full API reference
|
|
1573
|
+
- PROVIDERS.md — Provider setup guides
|
|
1574
|
+
- PIPELINE.md — Pipeline builder guide
|
|
1575
|
+
- MCP.md — MCP gateway documentation
|
|
1576
|
+
- PLUGIN.md — Plugin development guide
|
|
1577
|
+
- CONTRIBUTING.md — Contribution guidelines
|
|
1578
|
+
|
|
1579
|
+
### 5.6 npm Package + CLI (Hari 79-80)
|
|
1580
|
+
|
|
1581
|
+
```bash
|
|
1582
|
+
# Install globally
|
|
1583
|
+
npm install -g adnify
|
|
1584
|
+
|
|
1585
|
+
# CLI commands
|
|
1586
|
+
adnify # Start server
|
|
1587
|
+
adnify start # Start in background
|
|
1588
|
+
adnify stop # Stop server
|
|
1589
|
+
adnify status # Show status overview
|
|
1590
|
+
adnify providers # List connected providers
|
|
1591
|
+
adnify models # List available models
|
|
1592
|
+
adnify discover # Run auto-discovery
|
|
1593
|
+
adnify benchmark # Run model benchmarks
|
|
1594
|
+
adnify test <provider> # Test provider connection
|
|
1595
|
+
adnify config # Open config file
|
|
1596
|
+
adnify logs # Tail server logs
|
|
1597
|
+
adnify cost # Show cost report
|
|
1598
|
+
adnify cache clear # Clear semantic cache
|
|
1599
|
+
adnify router train # Force train neural router
|
|
1600
|
+
adnify skills # List all skills
|
|
1601
|
+
adnify skills create # Create new skill interactively
|
|
1602
|
+
adnify skills import <url># Import skill from OpenClaw/URL
|
|
1603
|
+
adnify skills rotate # Show rotation status
|
|
1604
|
+
adnify skills test <id> # Test a skill with sample request
|
|
1605
|
+
adnify skills groups # List skill groups
|
|
1606
|
+
adnify export # Export all data
|
|
1607
|
+
adnify version # Show version
|
|
1608
|
+
```
|
|
1609
|
+
|
|
1610
|
+
### 5.7 Release (Hari 81-84)
|
|
1611
|
+
|
|
1612
|
+
1. Final testing on Windows, macOS, Linux
|
|
1613
|
+
2. npm publish (adnify package)
|
|
1614
|
+
3. GitHub release with binaries
|
|
1615
|
+
4. Landing page / documentation site
|
|
1616
|
+
5. v2.0.0 release
|
|
1617
|
+
|
|
1618
|
+
---
|
|
1619
|
+
|
|
1620
|
+
## 6. Quality Gates
|
|
1621
|
+
|
|
1622
|
+
| Gate | Criteria |
|
|
1623
|
+
|------|----------|
|
|
1624
|
+
| Phase 1 | 5 providers, API working, basic dashboard |
|
|
1625
|
+
| Phase 2 | Semantic cache >10% hit, Squeezer >40% savings, Neural router >80% accuracy, Memory engine operational |
|
|
1626
|
+
| Phase 3 | All breakthrough features functional, Skill rotation working, OpenClaw import working |
|
|
1627
|
+
| Phase 4 | Full dashboard, all pages including Skills, mobile responsive |
|
|
1628
|
+
| Phase 5 | 40+ providers, tests >80% coverage, npm published |
|
|
1629
|
+
|
|
1630
|
+
---
|
|
1631
|
+
|
|
1632
|
+
## 7. Risk Mitigation
|
|
1633
|
+
|
|
1634
|
+
| Risk | Impact | Mitigation |
|
|
1635
|
+
|------|--------|------------|
|
|
1636
|
+
| ONNX Runtime compatibility issues | High | Test on all platforms early, provide TF-IDF fallback |
|
|
1637
|
+
| MiniLM model size too large | Medium | Offer download-on-demand, TF-IDF as lightweight option |
|
|
1638
|
+
| SQLite vector performance | Medium | Use brute-force for <10K, sqlite-vec for larger |
|
|
1639
|
+
| Neural Router accuracy too low | Medium | Always fall back to rule-based if confidence <50% |
|
|
1640
|
+
| Memory usage too high | Medium | Aggressive eviction, lazy loading, streaming processing |
|
|
1641
|
+
| Bun compatibility issues | Medium | Full Node.js fallback path |
|
|
1642
|
+
|
|
1643
|
+
---
|
|
1644
|
+
|
|
1645
|
+
## 8. Timeline Summary
|
|
1646
|
+
|
|
1647
|
+
| Phase | Durasi | Fokus |
|
|
1648
|
+
|-------|--------|-------|
|
|
1649
|
+
| **Phase 1** | Minggu 1-2 | Foundation (DB, Mesh, API, Basic Router) |
|
|
1650
|
+
| **Phase 2** | Minggu 3-5 | Intelligence (Neural Router, Semantic Cache, Squeezer, Cost Engine) |
|
|
1651
|
+
| **Phase 3** | Minggu 6-8 | Platform (Namespace, Benchmark, Pipeline, MCP, Forensics) |
|
|
1652
|
+
| **Phase 4** | Minggu 9-10 | Dashboard (Command Center, Playground, Intelligence UI) |
|
|
1653
|
+
| **Phase 5** | Minggu 11-12 | Polish (40+ Providers, Plugins, Tests, Docs, Release) |
|
|
1654
|
+
| **Total** | **12 Minggu** | **Full v2.0 Release** |
|
|
1655
|
+
|
|
1656
|
+
---
|
|
1657
|
+
|
|
1658
|
+
## 9. Quick Start (Target Experience)
|
|
1659
|
+
|
|
1660
|
+
```bash
|
|
1661
|
+
# 1. Install
|
|
1662
|
+
npm install -g adnify
|
|
1663
|
+
|
|
1664
|
+
# 2. Start (zero config)
|
|
1665
|
+
adnify
|
|
1666
|
+
|
|
1667
|
+
# → Scanning system for existing AI configs...
|
|
1668
|
+
# → ✅ Found: Claude Code (OAuth)
|
|
1669
|
+
# → ✅ Found: OpenAI API Key (env var)
|
|
1670
|
+
# → ✅ Found: Ollama (localhost:11434)
|
|
1671
|
+
# → 3 providers auto-detected!
|
|
1672
|
+
# → Checking for existing memory...
|
|
1673
|
+
# → ✅ Restored: 12,340 episodes, 847 knowledge entries, 134 rules
|
|
1674
|
+
# → 🧠 Intelligence level: Expert (82%) — resuming from where you left off
|
|
1675
|
+
# → Dashboard: http://localhost:3333
|
|
1676
|
+
|
|
1677
|
+
# 3. Open dashboard → Review auto-detected providers → Confirm
|
|
1678
|
+
|
|
1679
|
+
# 4. Use with any AI tool:
|
|
1680
|
+
# Claude Code: anthropic_api_base = http://localhost:3333/v1
|
|
1681
|
+
# Cursor: Base URL = http://localhost:3333/v1
|
|
1682
|
+
# Codex: OPENAI_BASE_URL = http://localhost:3333
|
|
1683
|
+
|
|
1684
|
+
# 5. Neural Router learns your patterns automatically
|
|
1685
|
+
# 6. Semantic Cache starts saving requests
|
|
1686
|
+
# 7. Token Squeezer compresses tool outputs
|
|
1687
|
+
# 8. Memory Engine records every experience — NEVER forgets
|
|
1688
|
+
# 9. Distiller runs every 6h — extracts patterns, generates rules
|
|
1689
|
+
# 10. System gets smarter every day — no amnesia on restart
|
|
1690
|
+
# 11. All automatic, zero configuration needed!
|
|
1691
|
+
```
|
|
1692
|
+
|
|
1693
|
+
### Learning Journey (What User Sees Over Time)
|
|
1694
|
+
|
|
1695
|
+
```
|
|
1696
|
+
Day 1: "Learning basic patterns..."
|
|
1697
|
+
→ Storing episodes, building initial knowledge
|
|
1698
|
+
→ Routing: rule-based (safe defaults)
|
|
1699
|
+
|
|
1700
|
+
Day 7: "Understanding your preferences..."
|
|
1701
|
+
→ "I see you prefer Claude for code review"
|
|
1702
|
+
→ "GLM-5.1 works great for your TypeScript code"
|
|
1703
|
+
→ Routing: neural (80% confidence) + rule-based fallback
|
|
1704
|
+
|
|
1705
|
+
Day 30: "Predicting outcomes accurately..."
|
|
1706
|
+
→ "Routing optimized: avg latency dropped from 3.8s to 2.1s"
|
|
1707
|
+
→ "Compression tuned for your codebase: 52% savings"
|
|
1708
|
+
→ "Budget optimization: $127 saved this month"
|
|
1709
|
+
→ "Skill 'typescript-expert' quality: 94/100 (best in coding group)"
|
|
1710
|
+
→ Routing: neural (92% confidence, auto-mode)
|
|
1711
|
+
|
|
1712
|
+
Day 90: "Expert-level optimization active"
|
|
1713
|
+
→ "Preemptive routing: I switch providers before failures happen"
|
|
1714
|
+
→ "I've learned 156 unique patterns in your workflow"
|
|
1715
|
+
→ "Auto-generated 134 rules, 128 verified correct"
|
|
1716
|
+
→ Routing: neural (95% confidence) + predictive failover
|
|
1717
|
+
|
|
1718
|
+
Day 365: "Mastery achieved"
|
|
1719
|
+
→ "I know your workflow better than any static config"
|
|
1720
|
+
→ "Predicting your next task with 78% accuracy"
|
|
1721
|
+
→ "Optimizing for quality, cost, and speed simultaneously"
|
|
1722
|
+
→ "1,247 knowledge entries, 456 verified rules, zero amnesia"
|
|
1723
|
+
```
|