@omiron33/omi-neuron-web 0.1.6 → 0.2.1

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 CHANGED
@@ -1,59 +1,819 @@
1
1
  # omi-neuron-web
2
2
 
3
- A drop-in Next.js library for data analysis and 3D visualization with OpenAI-powered insights.
3
+ Agent Implementation Guide (exhaustive)
4
4
 
5
- ## Features
5
+ This README is written for AI agents and engineers who need a complete, precise view of the repo and how to implement or extend it. It enumerates every public entry point, type, class, configuration field, and runtime behavior that the library exposes today.
6
6
 
7
- - 🔮 **AI-powered analysis** - OpenAI integration for embeddings, clustering, and relationship inference
8
- - 🕸️ **Interactive visualization** - Three.js graph with customizable themes and interactions
9
- - 🐘 **Zero-config database** - Docker PostgreSQL with pgvector automatically provisioned
10
- - 📊 **Smart clustering** - K-means and DBSCAN algorithms for grouping similar nodes
11
- - 🎨 **Fully customizable** - Themes, colors, node types, and domains configurable per project
12
- - 🔌 **Simple React API** - Provider and hooks for seamless integration
7
+ If you are working inside this repo, also read `AGENTS.md` for execution rules, plan order, and task tracking.
13
8
 
14
- ## Quick Start
9
+ ## What this repo provides
15
10
 
16
- ```bash
17
- # Install the package
18
- pnpm add @omiron33/omi-neuron-web
11
+ - A TypeScript library for graph data analysis plus 3D visualization (Three.js) with a Next.js-friendly API.
12
+ - A CLI that scaffolds configuration, Docker Postgres (pgvector), and Next.js route handlers.
13
+ - A Node/Edge/Cluster data model, plus analysis and embeddings pipelines.
14
+ - A React provider and hooks that wrap the API client.
15
+
16
+ ## Package entry points
17
+
18
+ The published package exposes these entry points (see `package.json` exports):
19
+
20
+ - `@omiron33/omi-neuron-web` (root) - types, schemas, analysis, storage, config helpers, visualization component, React hooks/provider.
21
+ - `@omiron33/omi-neuron-web/api` - API route factory, repositories, query builder, middleware, API types.
22
+ - `@omiron33/omi-neuron-web/visualization` - NeuronWeb component, theme, layout utilities, scene manager.
23
+ - `@omiron33/omi-neuron-web/migration` - migration list and runner.
24
+ - `@omiron33/omi-neuron-web/cli` - CLI entry (also exposed via the `omi-neuron` binary).
25
+
26
+ ## Repository map (what to edit)
27
+
28
+ - `src/core/types/*` - Type system. If you add fields, update Zod schemas and migrations.
29
+ - `src/core/schemas/*` - Zod runtime validation. Keep in sync with types.
30
+ - `src/core/analysis/*` - Embeddings, clustering, relationship inference, scoring, pipeline.
31
+ - `src/core/events/*` - Event bus and event types.
32
+ - `src/storage/*` - Database, Docker manager, query helpers, migrations.
33
+ - `src/api/*` - Route factory, repositories, query builder, middleware.
34
+ - `src/visualization/*` - Three.js scene, renderers, interactions, animations, layout.
35
+ - `src/react/*` - Provider, context, API client, hooks.
36
+ - `src/cli/*` - CLI commands and templates.
37
+ - `docs/*` - Additional docs (older, not as exhaustive as this README).
38
+
39
+ ## Root exports (from `src/index.ts`)
40
+
41
+ ```ts
42
+ // Types and schemas
43
+ export * from './core/types';
44
+ export * from './core/schemas';
45
+ export * from './core/events';
46
+
47
+ // Analysis engines
48
+ export { DataProcessor } from './core/analysis/data-processor';
49
+ export { EmbeddingsService } from './core/analysis/embeddings-service';
50
+ export { ClusteringEngine } from './core/analysis/clustering-engine';
51
+ export { RelationshipEngine } from './core/analysis/relationship-engine';
52
+ export { ScoringEngine } from './core/analysis/scoring-engine';
53
+ export { AnalysisPipeline } from './core/analysis/pipeline';
54
+
55
+ // Storage helpers
56
+ export * from './storage';
57
+
58
+ // Config helper
59
+ export * from './config';
60
+
61
+ // Visualization
62
+ export { NeuronWeb } from './visualization';
63
+ export type { NeuronWebProps, NeuronWebTheme, NeuronLayoutOptions, NeuronLayoutMode } from './visualization';
19
64
 
20
- # Initialize in your Next.js project
21
- npx @omiron33/omi-neuron-web init
65
+ // React integration
66
+ export * from './react/hooks';
67
+ export { NeuronWebProvider } from './react/NeuronWebProvider';
22
68
 
23
- # Start the database
24
- npx @omiron33/omi-neuron-web db:up
69
+ // Version constant
70
+ export const VERSION = '0.1.1';
71
+ ```
72
+
73
+ Note: `VERSION` is not currently auto-synced to `package.json`. Update it when releasing.
74
+
75
+ ## Configuration: NeuronConfig and NeuronSettings
76
+
77
+ These types live in `src/core/types/settings.ts` and are validated by Zod schemas in `src/core/schemas/settings.ts`.
78
+
79
+ ### NeuronConfig (full configuration)
80
+
81
+ ```ts
82
+ export interface NeuronConfig extends NeuronSettings {
83
+ openai: {
84
+ apiKey: string;
85
+ organization?: string;
86
+ requestsPerMinute?: number;
87
+ maxRetries?: number;
88
+ };
89
+ database: {
90
+ mode: 'docker' | 'external';
91
+ port: number;
92
+ containerName?: string;
93
+ image?: string;
94
+ user?: string;
95
+ password?: string;
96
+ database?: string;
97
+ url?: string;
98
+ pool?: {
99
+ min: number;
100
+ max: number;
101
+ idleTimeoutMs: number;
102
+ connectionTimeoutMs: number;
103
+ };
104
+ resources?: {
105
+ memoryLimit: string;
106
+ cpuLimit?: string;
107
+ };
108
+ };
109
+ api: {
110
+ basePath: string;
111
+ enableCors: boolean;
112
+ rateLimit?: {
113
+ windowMs: number;
114
+ max: number;
115
+ };
116
+ };
117
+ logging: {
118
+ level: 'debug' | 'info' | 'warn' | 'error';
119
+ prettyPrint: boolean;
120
+ };
121
+ }
122
+ ```
123
+
124
+ ### NeuronSettings (runtime settings persisted in DB)
25
125
 
26
- # Run your Next.js app
27
- npm run dev
126
+ ```ts
127
+ export interface NeuronSettings {
128
+ instance: {
129
+ name: string;
130
+ version: string;
131
+ repoName: string;
132
+ };
133
+ visualization: VisualizationSettings;
134
+ analysis: AnalysisSettings;
135
+ nodeTypes: NodeTypeConfig[];
136
+ domains: DomainConfig[];
137
+ relationshipTypes: RelationshipTypeConfig[];
138
+ }
28
139
  ```
29
140
 
30
- ## Documentation
141
+ ### Default settings (exact defaults)
142
+
143
+ From `DEFAULT_VISUALIZATION_SETTINGS` and `DEFAULT_ANALYSIS_SETTINGS` in `src/core/types/settings.ts`:
144
+
145
+ ```ts
146
+ export const DEFAULT_VISUALIZATION_SETTINGS = {
147
+ domainColors: {},
148
+ defaultDomainColor: '#c0c5ff',
149
+ edgeColor: '#4d4d55',
150
+ edgeActiveColor: '#c6d4ff',
151
+ backgroundColor: '#020314',
152
+ defaultCameraPosition: [4, 8, 20],
153
+ defaultCameraTarget: [0, 0, 0],
154
+ minZoomDistance: 4,
155
+ maxZoomDistance: 42,
156
+ enableStarfield: true,
157
+ starfieldCount: 1200,
158
+ labelDistance: 26,
159
+ maxVisibleLabels: 50,
160
+ performanceMode: 'auto',
161
+ nodeCountThreshold: 120,
162
+ pixelRatioCap: 2,
163
+ enableAnimations: true,
164
+ focusTweenDuration: 800,
165
+ filterTransitionDuration: 650,
166
+ enableHover: true,
167
+ enableClick: true,
168
+ enableDoubleClick: true,
169
+ enablePan: true,
170
+ enableZoom: true,
171
+ enableRotate: true,
172
+ };
173
+
174
+ export const DEFAULT_ANALYSIS_SETTINGS = {
175
+ embeddingModel: 'text-embedding-3-small',
176
+ embeddingDimensions: 1536,
177
+ embeddingBatchSize: 20,
178
+ embeddingCacheTTL: 86400,
179
+ clusteringAlgorithm: 'kmeans',
180
+ defaultClusterCount: 8,
181
+ minClusterSize: 3,
182
+ clusterSimilarityThreshold: 0.75,
183
+ relationshipInferenceModel: 'gpt-4o-mini',
184
+ relationshipMinConfidence: 0.7,
185
+ relationshipMaxPerNode: 10,
186
+ openaiRateLimit: 60,
187
+ maxConcurrentAnalysis: 5,
188
+ };
189
+ ```
190
+
191
+ ### Full config example (neuron.config.ts)
192
+
193
+ The CLI (`omi-neuron init`) writes a full config file. A complete config looks like:
194
+
195
+ ```ts
196
+ import { defineNeuronConfig, DEFAULT_ANALYSIS_SETTINGS, DEFAULT_VISUALIZATION_SETTINGS } from '@omiron33/omi-neuron-web';
197
+
198
+ export default defineNeuronConfig({
199
+ instance: {
200
+ name: 'my-instance',
201
+ version: '0.1.1',
202
+ repoName: 'my-repo',
203
+ },
204
+ visualization: DEFAULT_VISUALIZATION_SETTINGS,
205
+ analysis: DEFAULT_ANALYSIS_SETTINGS,
206
+ nodeTypes: [],
207
+ domains: [],
208
+ relationshipTypes: [],
209
+ openai: {
210
+ apiKey: process.env.OPENAI_API_KEY ?? '',
211
+ organization: undefined,
212
+ requestsPerMinute: undefined,
213
+ maxRetries: 3,
214
+ },
215
+ database: {
216
+ mode: 'docker',
217
+ port: 5433,
218
+ containerName: undefined,
219
+ image: 'pgvector/pgvector:pg16',
220
+ user: 'neuron',
221
+ password: 'neuron_dev',
222
+ database: 'neuron_web',
223
+ url: undefined,
224
+ pool: {
225
+ min: 0,
226
+ max: 10,
227
+ idleTimeoutMs: 30000,
228
+ connectionTimeoutMs: 5000,
229
+ },
230
+ resources: {
231
+ memoryLimit: '1g',
232
+ cpuLimit: undefined,
233
+ },
234
+ },
235
+ api: {
236
+ basePath: '/api/neuron',
237
+ enableCors: false,
238
+ rateLimit: undefined,
239
+ },
240
+ logging: {
241
+ level: 'info',
242
+ prettyPrint: true,
243
+ },
244
+ });
245
+ ```
246
+
247
+ ### Environment variables
248
+
249
+ - `OPENAI_API_KEY` - required for embeddings and relationship inference.
250
+ - `DATABASE_URL` - optional; if set, the Database factory uses it.
251
+ - `DB_HOST`, `DB_PORT`, `DB_USER`, `DB_PASSWORD`, `DB_NAME` - optional per `createDatabaseFromEnv()`.
252
+
253
+ ## Core data model (Types)
254
+
255
+ ### Nodes
256
+
257
+ `NeuronNode` fields (see `src/core/types/node.ts`):
258
+
259
+ - identity: `id`, `slug`, `label`, `nodeType`, `domain`, `createdAt`, `updatedAt`
260
+ - content: `summary`, `description`, `content`
261
+ - metadata: `metadata: Record<string, unknown>`
262
+ - analysis fields: `embedding`, `embeddingModel`, `embeddingGeneratedAt`, `clusterId`, `clusterSimilarity`
263
+ - relationship counts: `connectionCount`, `inboundCount`, `outboundCount`
264
+ - status: `analysisStatus`, `analysisError`
265
+ - visualization hints: `tier`, `visualPriority`, `positionOverride`
266
+
267
+ Input types:
268
+
269
+ - `NeuronNodeCreate` (minimal required fields: `label`; optional `slug`, `nodeType`, `domain`, `summary`, `description`, `content`, `metadata`, `tier`)
270
+ - `NeuronNodeUpdate` (partial updates)
271
+ - `NeuronNodeBatchCreate` (batch create with options)
272
+
273
+ Visualization type:
274
+
275
+ - `NeuronVisualNode` has `id`, `slug`, `label`, `domain`, `tier`, `metadata`, `ref`, `connectionCount`, `position`.
276
+
277
+ ### Edges
278
+
279
+ `NeuronEdge` fields (see `src/core/types/edge.ts`):
280
+
281
+ - identity: `id`, `fromNodeId`, `toNodeId`, `relationshipType`
282
+ - strength/confidence: `strength`, `confidence`
283
+ - evidence: `EdgeEvidence[]`
284
+ - metadata: `label`, `description`, `metadata`, `source`, `sourceModel`, `bidirectional`, timestamps
285
+
286
+ Input types: `NeuronEdgeCreate`, `NeuronEdgeUpdate`.
287
+
288
+ Visualization type: `NeuronVisualEdge` uses `from` and `to` slugs.
289
+
290
+ ### Clusters
291
+
292
+ `NeuronCluster` fields (see `src/core/types/cluster.ts`):
293
+
294
+ - identity: `id`, `label`, `clusterType`
295
+ - centroid: `centroid: number[]`
296
+ - stats: `memberCount`, `avgSimilarity`, `cohesion`
297
+ - metadata: `description`, `keywords`, `metadata`
31
298
 
32
- - [Getting Started](./docs/getting-started.md)
33
- - [Configuration](./docs/configuration.md)
34
- - [API Reference](./docs/api-reference.md)
35
- - [Hooks Reference](./docs/hooks-reference.md)
36
- - [Component Props](./docs/component-props.md)
37
- - [CLI Reference](./docs/cli-reference.md)
38
- - [Architecture](./docs/architecture.md)
39
- - [Troubleshooting](./docs/troubleshooting.md)
299
+ ### Analysis
40
300
 
41
- ### Phase Overview
301
+ `AnalysisRun`, `AnalysisRequest`, `AnalysisResponse`, `AnalysisPipelineConfig` are in `src/core/types/analysis.ts`.
42
302
 
43
- 1. **Foundation** - Core types, Docker setup, migrations, CLI
44
- 2. **Analysis Engine** - Embeddings, clustering, relationships, events
45
- 3. **API Layer** - REST endpoints, repositories, query builder
46
- 4. **Visualization** - Three.js component, themes, interactions
47
- 5. **Integration** - Provider, hooks, examples
48
- 6. **Validation** - Tests, documentation, npm publishing
303
+ ### Events
49
304
 
50
- ## Development Status
305
+ Event types and payloads are defined in `src/core/types/events.ts`.
306
+
307
+ ## Zod schemas
308
+
309
+ All runtime validation lives in `src/core/schemas/*`.
310
+
311
+ Key exports:
312
+
313
+ - Nodes: `nodeTierSchema`, `nodeCreateSchema`, `nodeUpdateSchema`, `nodeBatchCreateSchema`, `nodeFilterSchema`
314
+ - Edges: `edgeEvidenceSchema`, `edgeCreateSchema`, `edgeUpdateSchema`, `edgeFilterSchema`
315
+ - Clusters: `clusteringConfigSchema`, `clusterCreateSchema`, `clusterUpdateSchema`
316
+ - Analysis: `analysisOptionsSchema`, `analysisRequestSchema`
317
+ - Settings: `nodeTypeConfigSchema`, `domainConfigSchema`, `relationshipTypeConfigSchema`, `visualizationSettingsSchema`, `analysisSettingsSchema`, `neuronSettingsSchema`, `neuronSettingsUpdateSchema`, `neuronConfigSchema`
318
+ - API: `listNodesParamsSchema`, `listEdgesParamsSchema`, `getGraphParamsSchema`, `expandGraphRequestSchema`, `findPathRequestSchema`, `semanticSearchRequestSchema`, `findSimilarRequestSchema`
319
+
320
+ ## Storage layer
321
+
322
+ ### Database
323
+
324
+ Class: `Database` in `src/storage/database.ts`.
325
+
326
+ Constructor:
327
+
328
+ ```ts
329
+ new Database({
330
+ connectionString?: string,
331
+ host?: string,
332
+ port?: number,
333
+ user?: string,
334
+ password?: string,
335
+ database?: string,
336
+ pool?: { min; max; idleTimeoutMs; connectionTimeoutMs },
337
+ ssl?: boolean | object,
338
+ slowQueryThresholdMs?: number,
339
+ });
340
+ ```
341
+
342
+ Methods:
343
+
344
+ - `connect()` / `disconnect()`
345
+ - `isConnected()`
346
+ - `query<T>(sql, params)`
347
+ - `queryOne<T>(sql, params)`
348
+ - `execute(sql, params)`
349
+ - `transaction(fn)`
350
+ - `tableExists(tableName)`
351
+ - `getPoolStats()`
352
+
353
+ ### DockerManager
354
+
355
+ Class: `DockerManager` in `src/storage/docker-manager.ts`.
356
+
357
+ Constructor config:
358
+
359
+ ```ts
360
+ new DockerManager({
361
+ repoName: string,
362
+ port: number,
363
+ containerName?: string,
364
+ image?: string,
365
+ user?: string,
366
+ password?: string,
367
+ database?: string,
368
+ memoryLimit?: string,
369
+ });
370
+ ```
371
+
372
+ Methods:
373
+
374
+ - `start({ forceRecreate?, waitForReady?, timeoutMs? })`
375
+ - `stop({ removeVolumes?, timeoutMs? })`
376
+ - `ensureRunning({ waitForReady? })`
377
+ - `isRunning()`
378
+ - `healthCheck()` -> `{ containerRunning, databaseReady, connectionString, details? }`
379
+ - `getStats()` -> container stats
380
+ - `getConnectionString()`
381
+ - `getLogs({ tail?, since? })`
382
+ - `execSql(sql)`
383
+ - `updatePort(newPort)`
384
+
385
+ ### MigrationRunner
386
+
387
+ Class: `MigrationRunner` in `src/storage/migrations/runner.ts`.
388
+
389
+ Methods:
390
+
391
+ - `getStatus()` -> applied/pending
392
+ - `getPending()`
393
+ - `getApplied()`
394
+ - `up({ to? })`
395
+ - `down({ to?, count? })`
396
+ - `reset()`
397
+ - `dryRun('up' | 'down')`
398
+
399
+ ### Database schema (migrations)
400
+
401
+ Defined in `src/storage/migrations/*.ts`:
402
+
403
+ - `nodes` table: `slug`, `label`, `node_type`, `domain`, `summary`, `description`, `content`, `metadata`, `tier`, `visual_priority`, `position_override`, `connection_count`, `inbound_count`, `outbound_count`, `analysis_status`, `analysis_error`, timestamps.
404
+ - `edges` table: `from_node_id`, `to_node_id`, `relationship_type`, `strength`, `confidence`, `evidence`, `label`, `description`, `metadata`, `source`, `source_model`, `bidirectional`, timestamps.
405
+ - `settings` table: JSONB settings for `visualization`, `analysis`, `node_types`, `domains`, `relationship_types`.
406
+ - `clusters` table and `cluster_memberships` table.
407
+ - `analysis_runs` table for pipeline jobs.
408
+ - Extensions: `uuid-ossp`, `vector` (pgvector).
409
+
410
+ ## Analysis engines
411
+
412
+ ### DataProcessor
413
+
414
+ File: `src/core/analysis/data-processor.ts`
415
+
416
+ - Converts arbitrary input records to `NeuronNodeCreate`.
417
+ - Options: `skipDuplicates`, `updateOnConflict`, `defaultNodeType`, `defaultDomain`, `contentFields`, `labelField`, `slugField`, `metadataFields`.
418
+ - Key methods: `processItem`, `processBatch`, `processJSON`, `processCSV`, `generateSlug`, `extractContent`, `detectDuplicates`.
419
+
420
+ ### EmbeddingsService
421
+
422
+ File: `src/core/analysis/embeddings-service.ts`
423
+
424
+ Constructor:
425
+
426
+ ```ts
427
+ new EmbeddingsService({
428
+ openaiApiKey: string,
429
+ model: 'text-embedding-ada-002' | 'text-embedding-3-small' | 'text-embedding-3-large',
430
+ dimensions?: number,
431
+ batchSize: number,
432
+ rateLimit: number,
433
+ cacheTTL: number,
434
+ maxRetries: number,
435
+ }, db)
436
+ ```
437
+
438
+ Methods:
439
+
440
+ - `generateEmbedding(text)`
441
+ - `generateBatchEmbeddings(texts)`
442
+ - `embedNode(nodeId)`
443
+ - `embedNodes(nodeIds)`
444
+ - `getCachedEmbedding(nodeId)`
445
+ - `cacheEmbedding(nodeId, embedding, model)`
446
+ - `invalidateCache(nodeIds?)`
447
+ - `countTokens(text)`
448
+ - `estimateCost(nodeCount)`
449
+
450
+ ### ClusteringEngine
451
+
452
+ File: `src/core/analysis/clustering-engine.ts`
453
+
454
+ Methods:
455
+
456
+ - `clusterNodes(config)` -> `{ clusters, unassigned }`
457
+ - `recluster(config)`
458
+ - `assignToCluster(nodeId)`
459
+ - `findBestCluster(embedding)`
460
+ - `recomputeCentroid(clusterId)` / `recomputeAllCentroids()`
461
+ - `generateClusterLabel(clusterId)` / `generateAllLabels()`
462
+ - `calculateSilhouetteScore(clusters)`
463
+ - `calculateCohesion(cluster)`
464
+
465
+ ### RelationshipEngine
466
+
467
+ File: `src/core/analysis/relationship-engine.ts`
468
+
469
+ Constructor config:
470
+
471
+ ```ts
472
+ {
473
+ model: string;
474
+ minConfidence: number;
475
+ maxPerNode: number;
476
+ similarityThreshold: number;
477
+ includeExisting: boolean;
478
+ batchSize: number;
479
+ rateLimit: number;
480
+ }
481
+ ```
51
482
 
52
- 🟥 **In Planning** - Implementation not yet started
483
+ Methods:
53
484
 
54
- See [plans/master-plan-planner.md](./plans/master-plan-planner.md) for current status.
485
+ - `inferForNode(nodeId)`
486
+ - `inferForNodes(nodeIds)`
487
+ - `inferAll()`
488
+ - `findCandidates(nodeId)`
489
+ - `validateRelationship(rel)`
490
+ - `createEdgesFromInferences(inferences, autoApprove?)`
491
+
492
+ ### ScoringEngine
493
+
494
+ File: `src/core/analysis/scoring-engine.ts`
495
+
496
+ - Constructor accepts optional config `{ similarityWeight, connectionWeight, recencyWeight, domainBoost }`.
497
+ - Key methods: `cosineSimilarity`, `semanticSimilarity`, `scoreForQuery`, `findSimilar`, `calculateNodeImportance`, `rankAllNodes`, `scoreRelevance`.
498
+
499
+ ### AnalysisPipeline
500
+
501
+ File: `src/core/analysis/pipeline.ts`
502
+
503
+ Constructor: `(db, embeddings, clustering, relationships, events)`.
504
+
505
+ Methods:
506
+
507
+ - `runFull(options)`
508
+ - `runEmbeddings(options)`
509
+ - `runClustering(options)`
510
+ - `runRelationships(options)`
511
+ - `getJob(jobId)` / `listJobs({ status?, limit? })`
512
+ - `cancelJob(jobId)` / `isRunning()`
513
+
514
+ `PipelineOptions` fields include `nodeIds`, `forceRecompute`, `skipEmbeddings`, `embeddingModel`, `skipClustering`, `clusterCount`, `clusteringAlgorithm`, `skipRelationships`, `relationshipThreshold`, `maxRelationshipsPerNode`, `onProgress`, `webhookUrl`.
515
+
516
+ ## API layer
517
+
518
+ ### createNeuronRoutes
519
+
520
+ Entry point: `createNeuronRoutes(config)` from `@omiron33/omi-neuron-web/api`.
521
+
522
+ Returns:
523
+
524
+ ```ts
525
+ {
526
+ nodes: createNodesRoutes(config),
527
+ edges: createEdgesRoutes(config),
528
+ graph: createGraphRoutes(config),
529
+ analyze: createAnalyzeRoutes(config),
530
+ settings: createSettingsRoutes(config),
531
+ search: createSearchRoutes(config),
532
+ health: createHealthRoutes(config),
533
+ }
534
+ ```
535
+
536
+ ### Route behaviors
537
+
538
+ All handlers accept a Fetch API `Request` and return `Response` (Next.js route handlers are compatible).
539
+
540
+ Nodes:
541
+
542
+ - `GET /nodes` -> list nodes with pagination. Uses `listNodesParamsSchema`.
543
+ - `POST /nodes` -> batch create. Uses `nodeBatchCreateSchema`.
544
+ - `PATCH /nodes/:id` -> update. Uses `nodeUpdateSchema`.
545
+ - `DELETE /nodes/:id` -> delete.
546
+
547
+ Edges:
548
+
549
+ - `GET /edges` -> list edges. Uses `listEdgesParamsSchema`.
550
+ - `POST /edges` -> batch create. Uses `edgeCreateSchema`.
551
+ - `PATCH /edges/:id` -> update.
552
+ - `DELETE /edges/:id` -> delete.
553
+
554
+ Graph:
555
+
556
+ - `GET /graph` -> returns `NeuronVisualNode` and `NeuronVisualEdge` arrays.
557
+ - `POST /graph/expand` -> expansion by depth.
558
+ - `POST /graph/path` -> find paths.
559
+
560
+ Analyze:
561
+
562
+ - `POST /analyze` -> runs analysis pipeline (embeddings, clustering, relationships, or full).
563
+ - `GET /analyze/:jobId` -> fetch job status.
564
+ - `POST /analyze/:jobId/cancel` -> cancel job.
565
+ - `GET /analyze/history` -> list recent jobs.
566
+
567
+ Settings:
568
+
569
+ - `GET /settings` -> fetch settings from DB.
570
+ - `PATCH /settings` -> update settings.
571
+ - `POST /settings/reset` -> reset entire or specific sections.
572
+
573
+ Search:
574
+
575
+ - `POST /search` -> semantic search.
576
+ - `POST /search/similar` -> find similar to node.
577
+
578
+ Health:
579
+
580
+ - `GET /health` -> basic DB connectivity.
581
+
582
+ ### API client
583
+
584
+ `NeuronApiClient` in `src/react/api-client.ts` wraps these endpoints; see that file for exact method names and payloads.
585
+
586
+ ### Middleware
587
+
588
+ From `src/api/middleware/*` (exported in `@omiron33/omi-neuron-web/api`):
589
+
590
+ - `withNeuronMiddleware(handler, { cors? })`
591
+ - `withErrorHandler(handler)` and `handleError(error)`
592
+ - `withLogging(handler)`
593
+ - `withTiming(handler)`
594
+ - `withCors({ origins? })`
595
+ - `withValidation(schema, source)`
596
+
597
+ ## React integration
598
+
599
+ ### NeuronWebProvider
600
+
601
+ Wrap your app and provide configuration. The provider loads settings from `/api/neuron/settings` via the API client.
602
+
603
+ ```tsx
604
+ import { NeuronWebProvider } from '@omiron33/omi-neuron-web';
605
+
606
+ export default function RootLayout({ children }) {
607
+ return (
608
+ <NeuronWebProvider
609
+ config={{
610
+ openaiApiKey: process.env.NEXT_PUBLIC_OPENAI_API_KEY,
611
+ databaseUrl: process.env.NEXT_PUBLIC_DATABASE_URL,
612
+ settings: {},
613
+ onEvent: (event) => {},
614
+ onError: (error) => {},
615
+ }}
616
+ >
617
+ {children}
618
+ </NeuronWebProvider>
619
+ );
620
+ }
621
+ ```
622
+
623
+ ### Hooks
624
+
625
+ - `useNeuronContext()` -> access provider context.
626
+ - `useNeuronGraph({ domains?, nodeTypes?, minEdgeStrength?, autoRefresh?, refreshInterval? })` -> fetch and explore graph.
627
+ - `useNeuronNodes({ initialFilters?, pageSize? })` -> CRUD nodes and pagination.
628
+ - `useNeuronAnalysis()` -> start/cancel/check analysis jobs.
629
+ - `useNeuronSettings()` -> update or reset settings.
630
+ - `useNeuronSearch()` -> semantic search and find similar nodes.
631
+ - `useNeuronEvents()` -> subscribe/emit events.
632
+
633
+ Also available:
634
+
635
+ - `useNodeEvents(handlers)`
636
+ - `useAnalysisEvents(handlers)`
637
+
638
+ ## Visualization (NeuronWeb)
639
+
640
+ ### Component props (full list)
641
+
642
+ `NeuronWebProps` from `src/visualization/types.ts`:
643
+
644
+ ```ts
645
+ export interface NeuronWebProps {
646
+ graphData: {
647
+ nodes: NeuronVisualNode[];
648
+ edges: NeuronVisualEdge[];
649
+ storyBeats?: NeuronStoryBeat[];
650
+ };
651
+ fullHeight?: boolean;
652
+ isFullScreen?: boolean;
653
+ className?: string;
654
+ style?: React.CSSProperties;
655
+ isLoading?: boolean;
656
+ error?: string | null;
657
+ selectedNode?: NeuronNode | null;
658
+ focusNodeSlug?: string | null;
659
+ visibleNodeSlugs?: string[] | null;
660
+ onNodeClick?: (node: NeuronNode) => void;
661
+ onNodeDoubleClick?: (node: NeuronNode) => void;
662
+ onNodeHover?: (node: NeuronNode | null) => void;
663
+ onNodeFocused?: (node: NeuronNode) => void;
664
+ onEdgeClick?: (edge: NeuronEdge) => void;
665
+ onBackgroundClick?: () => void;
666
+ onCameraChange?: (position: [number, number, number]) => void;
667
+ studyPathRequest?: StudyPathRequest | null;
668
+ onStudyPathComplete?: () => void;
669
+ layout?: NeuronLayoutOptions;
670
+ cameraFit?: CameraFitOptions;
671
+ theme?: NeuronWebThemeOverride;
672
+ domainColors?: Record<string, string>;
673
+ renderNodeHover?: (node: NeuronVisualNode) => React.ReactNode;
674
+ hoverCard?: HoverCardOptions;
675
+ renderNodeDetail?: (node: NeuronNode) => React.ReactNode;
676
+ renderEmptyState?: () => React.ReactNode;
677
+ renderLoadingState?: () => React.ReactNode;
678
+ performanceMode?: 'auto' | 'normal' | 'degraded' | 'fallback';
679
+ ariaLabel?: string;
680
+ }
681
+ ```
682
+
683
+ Props currently used inside `NeuronWeb` (others are reserved for future use):
684
+
685
+ - Used: `graphData`, `className`, `style`, `fullHeight`, `isFullScreen`, `isLoading`, `error`, `renderEmptyState`, `renderLoadingState`, `ariaLabel`, `theme`, `layout`, `renderNodeHover`, `hoverCard`, `onNodeHover`, `onNodeClick`, `onNodeDoubleClick`, `onNodeFocused`, `onBackgroundClick`, `performanceMode`.
686
+ - Used: `cameraFit` (auto-fit bounds to a viewport fraction).
687
+ - Reserved (declared but not used in the component yet): `selectedNode`, `focusNodeSlug`, `visibleNodeSlugs`, `onEdgeClick`, `onCameraChange`, `studyPathRequest`, `onStudyPathComplete`, `domainColors`, `renderNodeDetail`, `graphData.storyBeats`.
688
+
689
+ ### Layout modes
690
+
691
+ `NeuronLayoutMode` = `'auto' | 'positioned' | 'fuzzy' | 'atlas'`.
692
+
693
+ `applyFuzzyLayout()` behavior:
694
+
695
+ - `positioned`: return nodes as-is (use positions from DB or API).
696
+ - `auto`: if any node lacks a `position`, run `atlas` layout; otherwise return nodes as-is.
697
+ - `atlas`: sphere layout with built-in override map (`ATLAS_POSITION_OVERRIDES` in `src/visualization/layouts/fuzzy-layout.ts`).
698
+ - `fuzzy`: deterministic pseudo-random scatter based on `seed` and node key.
699
+
700
+ Layout options:
701
+
702
+ ```ts
703
+ {
704
+ mode?: NeuronLayoutMode;
705
+ radius?: number; // base radius for layout
706
+ insightRadius?: number; // smaller radius for insight nodes
707
+ jitter?: number; // random jitter
708
+ zSpread?: number; // z-axis spread
709
+ seed?: string; // deterministic seed
710
+ spread?: number; // global scale factor
711
+ overrides?: Record<string, [number, number, number]>; // slug/id -> position
712
+ }
713
+ ```
714
+
715
+ ### Camera auto-fit (center-third framing)
716
+
717
+ Use `cameraFit` to center and zoom so all nodes sit inside a specific viewport fraction (default: 0.33 = center third).
718
+ When `isFullScreen` is true and `cameraFit.enabled` is not specified, auto-fit is enabled by default.
719
+
720
+ ```tsx
721
+ <NeuronWeb
722
+ graphData={graphData}
723
+ isFullScreen
724
+ cameraFit={{
725
+ enabled: true,
726
+ mode: 'once', // or 'onChange' to refit when node positions change
727
+ viewportFraction: 0.33, // center-third framing
728
+ padding: 0.15, // 15% padding around bounds
729
+ }}
730
+ />
731
+ ```
732
+
733
+ To disable in fullscreen:
734
+
735
+ ```tsx
736
+ <NeuronWeb graphData={graphData} isFullScreen cameraFit={{ enabled: false }} />
737
+ ```
738
+
739
+ ### Theme
740
+
741
+ `NeuronWebTheme` defines colors, typography, effects, and animation. Defaults are in `src/visualization/constants.ts`.
742
+
743
+ Key behavior in `NeuronWeb`:
744
+
745
+ - Performance mode is auto-detected unless explicitly set.
746
+ - Hover cards are disabled in `fallback` mode.
747
+ - Labels and starfield density are reduced in `degraded`/`fallback`.
748
+
749
+ ### Fullscreen vs element rendering
750
+
751
+ - `isFullScreen: true` makes the component `position: fixed` with `width: 100vw` and `height: 100vh`.
752
+ - Default (not full screen) uses `width: 100%` and `height: 100%`. The parent element must define a height.
753
+ - `fullHeight: true` sets `min-height: 100vh` when not full screen.
754
+
755
+ ## Visualization internals (agent map)
756
+
757
+ Key internal modules:
758
+
759
+ - `src/visualization/scene/scene-manager.ts` - sets up Three.js scene, camera, renderer, lights, starfield, labels.
760
+ - `src/visualization/scene/node-renderer.ts` - renders nodes, labels, hover/selection states.
761
+ - `src/visualization/scene/edge-renderer.ts` - renders edges, flow animations.
762
+ - `src/visualization/interactions/interaction-manager.ts` - hover/click/double-click handling.
763
+ - `src/visualization/animations/animation-controller.ts` - camera focus/transition animations.
764
+ - `src/visualization/layouts/fuzzy-layout.ts` - layout generation.
765
+
766
+ ## Events
767
+
768
+ Event system in `src/core/events/event-bus.ts` with types in `src/core/types/events.ts`.
769
+
770
+ - Subscribe with `EventBus.subscribe(type, handler)` or `subscribeAll(handler)`.
771
+ - Emit with `EventBus.emit(createEvent(type, payload, source))`.
772
+ - `useNeuronEvents()` provides React helpers to subscribe/emit inside components.
773
+
774
+ ## API types (request/response)
775
+
776
+ All API request/response types are defined in `src/core/types/api.ts`. If you need to implement a server or client manually, this file is the contract.
777
+
778
+ ## CLI reference (omi-neuron)
779
+
780
+ The CLI is defined in `src/cli/index.ts` and subcommands in `src/cli/commands/*`.
781
+
782
+ Commands:
783
+
784
+ - `omi-neuron init` - scaffold config, docker compose, env file, and Next.js route.
785
+ - `--name`, `--port`, `--skip-docker`, `--skip-api`, `--skip-config`, `--app-dir`, `--force`
786
+ - `omi-neuron db up|down|migrate|status|reset|seed`
787
+ - `up`: `--port`, `--force-recreate`, `--wait`
788
+ - `down`: `--remove-volumes`
789
+ - `migrate`: `--status`, `--rollback <n>`, `--to <version>`, `--dry-run`
790
+ - `status`: `--json`, `--verbose`
791
+ - `reset`: `--confirm`
792
+ - `seed`: `--file`, `--clear`, `--count`
793
+ - `omi-neuron analyze embeddings|cluster|relationships|full`
794
+ - `embeddings`: `--node-ids`, `--force`
795
+ - `cluster`: `--count`, `--algorithm`
796
+ - `relationships`: `--threshold`, `--dry-run`
797
+ - `full`: `--force`
798
+ - `omi-neuron validate` - checks config, docker, DB, and OpenAI env.
799
+ - `omi-neuron config get|set|list|reset` - manage `neuron.config.ts` values.
800
+
801
+ ## Known gaps and reserved fields
802
+
803
+ - Several `NeuronWebProps` are defined but not yet used internally (see list above).
804
+ - `VisualizationSettings` vs `NeuronWebTheme`: the component uses theme overrides, not settings. If you want settings to drive visuals, wire them in `NeuronWeb`.
805
+ - `VERSION` constant is not auto-updated.
806
+
807
+ ## Build and test
808
+
809
+ ```bash
810
+ pnpm install
811
+ pnpm build
812
+ pnpm typecheck
813
+ pnpm lint
814
+ pnpm test
815
+ ```
55
816
 
56
817
  ## License
57
818
 
58
819
  MIT
59
-