@soleri/core 0.0.1 → 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.
Files changed (74) hide show
  1. package/dist/brain/brain.d.ts +85 -0
  2. package/dist/brain/brain.d.ts.map +1 -0
  3. package/dist/brain/brain.js +506 -0
  4. package/dist/brain/brain.js.map +1 -0
  5. package/dist/cognee/client.d.ts +35 -0
  6. package/dist/cognee/client.d.ts.map +1 -0
  7. package/dist/cognee/client.js +289 -0
  8. package/dist/cognee/client.js.map +1 -0
  9. package/dist/cognee/types.d.ts +46 -0
  10. package/dist/cognee/types.d.ts.map +1 -0
  11. package/dist/cognee/types.js +3 -0
  12. package/dist/cognee/types.js.map +1 -0
  13. package/dist/facades/facade-factory.d.ts +5 -0
  14. package/dist/facades/facade-factory.d.ts.map +1 -0
  15. package/dist/facades/facade-factory.js +49 -0
  16. package/dist/facades/facade-factory.js.map +1 -0
  17. package/dist/facades/types.d.ts +42 -0
  18. package/dist/facades/types.d.ts.map +1 -0
  19. package/dist/facades/types.js +6 -0
  20. package/dist/facades/types.js.map +1 -0
  21. package/dist/index.d.ts +19 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +19 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/intelligence/loader.d.ts +3 -0
  26. package/dist/intelligence/loader.d.ts.map +1 -0
  27. package/dist/intelligence/loader.js +41 -0
  28. package/dist/intelligence/loader.js.map +1 -0
  29. package/dist/intelligence/types.d.ts +20 -0
  30. package/dist/intelligence/types.d.ts.map +1 -0
  31. package/dist/intelligence/types.js +2 -0
  32. package/dist/intelligence/types.js.map +1 -0
  33. package/dist/llm/key-pool.d.ts +38 -0
  34. package/dist/llm/key-pool.d.ts.map +1 -0
  35. package/dist/llm/key-pool.js +154 -0
  36. package/dist/llm/key-pool.js.map +1 -0
  37. package/dist/llm/types.d.ts +80 -0
  38. package/dist/llm/types.d.ts.map +1 -0
  39. package/dist/llm/types.js +37 -0
  40. package/dist/llm/types.js.map +1 -0
  41. package/dist/llm/utils.d.ts +26 -0
  42. package/dist/llm/utils.d.ts.map +1 -0
  43. package/dist/llm/utils.js +197 -0
  44. package/dist/llm/utils.js.map +1 -0
  45. package/dist/planning/planner.d.ts +48 -0
  46. package/dist/planning/planner.d.ts.map +1 -0
  47. package/dist/planning/planner.js +109 -0
  48. package/dist/planning/planner.js.map +1 -0
  49. package/dist/vault/vault.d.ts +80 -0
  50. package/dist/vault/vault.d.ts.map +1 -0
  51. package/dist/vault/vault.js +353 -0
  52. package/dist/vault/vault.js.map +1 -0
  53. package/package.json +56 -4
  54. package/src/__tests__/brain.test.ts +740 -0
  55. package/src/__tests__/cognee-client.test.ts +524 -0
  56. package/src/__tests__/llm.test.ts +556 -0
  57. package/src/__tests__/loader.test.ts +176 -0
  58. package/src/__tests__/planner.test.ts +261 -0
  59. package/src/__tests__/vault.test.ts +494 -0
  60. package/src/brain/brain.ts +678 -0
  61. package/src/cognee/client.ts +350 -0
  62. package/src/cognee/types.ts +62 -0
  63. package/src/facades/facade-factory.ts +64 -0
  64. package/src/facades/types.ts +42 -0
  65. package/src/index.ts +75 -0
  66. package/src/intelligence/loader.ts +42 -0
  67. package/src/intelligence/types.ts +20 -0
  68. package/src/llm/key-pool.ts +190 -0
  69. package/src/llm/types.ts +116 -0
  70. package/src/llm/utils.ts +248 -0
  71. package/src/planning/planner.ts +151 -0
  72. package/src/vault/vault.ts +455 -0
  73. package/tsconfig.json +22 -0
  74. package/vitest.config.ts +15 -0
@@ -0,0 +1,350 @@
1
+ import type {
2
+ CogneeConfig,
3
+ CogneeSearchResult,
4
+ CogneeSearchType,
5
+ CogneeStatus,
6
+ CogneeAddResult,
7
+ CogneeCognifyResult,
8
+ } from './types.js';
9
+ import type { IntelligenceEntry } from '../intelligence/types.js';
10
+
11
+ // ─── Defaults ──────────────────────────────────────────────────────
12
+ // Aligned with Salvador MCP's battle-tested Cognee integration.
13
+
14
+ const DEFAULT_SERVICE_EMAIL = 'soleri-agent@cognee.dev';
15
+ const DEFAULT_SERVICE_PASSWORD = 'soleri-cognee-local';
16
+
17
+ /** Only allow default service credentials for local endpoints. */
18
+ function isLocalUrl(url: string): boolean {
19
+ try {
20
+ const { hostname } = new URL(url);
21
+ return (
22
+ hostname === 'localhost' ||
23
+ hostname === '127.0.0.1' ||
24
+ hostname === '::1' ||
25
+ hostname === '0.0.0.0'
26
+ );
27
+ } catch {
28
+ return false;
29
+ }
30
+ }
31
+
32
+ const DEFAULT_CONFIG: CogneeConfig = {
33
+ baseUrl: 'http://localhost:8000',
34
+ dataset: 'vault',
35
+ timeoutMs: 30_000,
36
+ searchTimeoutMs: 120_000, // Ollama cold start can take 90s
37
+ healthTimeoutMs: 5_000,
38
+ healthCacheTtlMs: 60_000,
39
+ cognifyDebounceMs: 30_000,
40
+ };
41
+
42
+ // ─── CogneeClient ──────────────────────────────────────────────────
43
+
44
+ export class CogneeClient {
45
+ private config: CogneeConfig;
46
+ private healthCache: { status: CogneeStatus; cachedAt: number } | null = null;
47
+ private accessToken: string | null = null;
48
+ private cognifyTimers: Map<string, ReturnType<typeof setTimeout>> = new Map();
49
+ private pendingDatasets: Set<string> = new Set();
50
+
51
+ constructor(config?: Partial<CogneeConfig>) {
52
+ this.config = { ...DEFAULT_CONFIG, ...config };
53
+ // Strip trailing slash
54
+ this.config.baseUrl = this.config.baseUrl.replace(/\/+$/, '');
55
+ // Pre-set token if provided
56
+ if (this.config.apiToken) {
57
+ this.accessToken = this.config.apiToken;
58
+ }
59
+ }
60
+
61
+ // ─── Health ────────────────────────────────────────────────────
62
+
63
+ get isAvailable(): boolean {
64
+ if (!this.healthCache) return false;
65
+ const age = Date.now() - this.healthCache.cachedAt;
66
+ if (age > this.config.healthCacheTtlMs) return false;
67
+ return this.healthCache.status.available;
68
+ }
69
+
70
+ async healthCheck(): Promise<CogneeStatus> {
71
+ const start = Date.now();
72
+ try {
73
+ // Cognee health endpoint is GET / (returns {"message":"Hello, World, I am alive!"})
74
+ const res = await globalThis.fetch(`${this.config.baseUrl}/`, {
75
+ signal: AbortSignal.timeout(this.config.healthTimeoutMs),
76
+ });
77
+ const latencyMs = Date.now() - start;
78
+ if (res.ok) {
79
+ const status: CogneeStatus = { available: true, url: this.config.baseUrl, latencyMs };
80
+ this.healthCache = { status, cachedAt: Date.now() };
81
+ return status;
82
+ }
83
+ const status: CogneeStatus = {
84
+ available: false,
85
+ url: this.config.baseUrl,
86
+ latencyMs,
87
+ error: `HTTP ${res.status}`,
88
+ };
89
+ this.healthCache = { status, cachedAt: Date.now() };
90
+ return status;
91
+ } catch (err) {
92
+ const latencyMs = Date.now() - start;
93
+ const status: CogneeStatus = {
94
+ available: false,
95
+ url: this.config.baseUrl,
96
+ latencyMs,
97
+ error: err instanceof Error ? err.message : String(err),
98
+ };
99
+ this.healthCache = { status, cachedAt: Date.now() };
100
+ return status;
101
+ }
102
+ }
103
+
104
+ // ─── Ingest ────────────────────────────────────────────────────
105
+
106
+ async addEntries(entries: IntelligenceEntry[]): Promise<CogneeAddResult> {
107
+ if (!this.isAvailable || entries.length === 0) return { added: 0 };
108
+
109
+ try {
110
+ const token = await this.ensureAuth().catch(() => null);
111
+
112
+ // Cognee /add expects multipart/form-data with files + datasetName
113
+ const formData = new FormData();
114
+ formData.append('datasetName', this.config.dataset);
115
+
116
+ for (const entry of entries) {
117
+ const text = this.serializeEntry(entry);
118
+ const blob = new Blob([text], { type: 'text/plain' });
119
+ formData.append('data', blob, `${entry.id}.txt`);
120
+ }
121
+
122
+ const headers: Record<string, string> = {};
123
+ if (token) headers.Authorization = `Bearer ${token}`;
124
+
125
+ const res = await globalThis.fetch(`${this.config.baseUrl}/api/v1/add`, {
126
+ method: 'POST',
127
+ headers,
128
+ body: formData,
129
+ signal: AbortSignal.timeout(this.config.timeoutMs),
130
+ });
131
+
132
+ if (!res.ok) return { added: 0 };
133
+
134
+ // Schedule debounced cognify (multiple rapid ingests coalesce)
135
+ this.scheduleCognify(this.config.dataset);
136
+
137
+ return { added: entries.length };
138
+ } catch {
139
+ return { added: 0 };
140
+ }
141
+ }
142
+
143
+ async cognify(dataset?: string): Promise<CogneeCognifyResult> {
144
+ if (!this.isAvailable) return { status: 'unavailable' };
145
+
146
+ try {
147
+ const res = await this.post('/api/v1/cognify', {
148
+ datasets: [dataset ?? this.config.dataset],
149
+ });
150
+
151
+ if (!res.ok) return { status: `error: HTTP ${res.status}` };
152
+ return { status: 'ok' };
153
+ } catch (err) {
154
+ return { status: `error: ${err instanceof Error ? err.message : String(err)}` };
155
+ }
156
+ }
157
+
158
+ // ─── Cognify debounce ───────────────────────────────────────────
159
+
160
+ /**
161
+ * Schedule a debounced cognify for a dataset.
162
+ * Sliding window: each call resets the timer. When it expires,
163
+ * cognify fires once. Prevents pipeline dedup on rapid ingests.
164
+ */
165
+ private scheduleCognify(dataset: string): void {
166
+ const existing = this.cognifyTimers.get(dataset);
167
+ if (existing) clearTimeout(existing);
168
+
169
+ this.pendingDatasets.add(dataset);
170
+
171
+ const timer = setTimeout(() => {
172
+ this.cognifyTimers.delete(dataset);
173
+ this.pendingDatasets.delete(dataset);
174
+ this.post('/api/v1/cognify', { datasets: [dataset] }).catch(() => {});
175
+ }, this.config.cognifyDebounceMs);
176
+
177
+ // Unref so the timer doesn't keep the process alive during shutdown
178
+ if (typeof timer === 'object' && 'unref' in timer) (timer as NodeJS.Timeout).unref();
179
+
180
+ this.cognifyTimers.set(dataset, timer);
181
+ }
182
+
183
+ /** Flush all pending debounced cognify calls immediately. */
184
+ async flushPendingCognify(): Promise<void> {
185
+ const datasets = [...this.pendingDatasets];
186
+ for (const timer of this.cognifyTimers.values()) clearTimeout(timer);
187
+ this.cognifyTimers.clear();
188
+ this.pendingDatasets.clear();
189
+
190
+ if (datasets.length === 0) return;
191
+
192
+ await Promise.allSettled(
193
+ datasets.map((ds) => this.post('/api/v1/cognify', { datasets: [ds] }).catch(() => {})),
194
+ );
195
+ }
196
+
197
+ /** Cancel all pending cognify calls without firing them. For test teardown. */
198
+ resetPendingCognify(): void {
199
+ for (const timer of this.cognifyTimers.values()) clearTimeout(timer);
200
+ this.cognifyTimers.clear();
201
+ this.pendingDatasets.clear();
202
+ }
203
+
204
+ // ─── Search ────────────────────────────────────────────────────
205
+
206
+ async search(
207
+ query: string,
208
+ opts?: { searchType?: CogneeSearchType; limit?: number },
209
+ ): Promise<CogneeSearchResult[]> {
210
+ if (!this.isAvailable) return [];
211
+
212
+ // Default to CHUNKS (pure vector similarity) — GRAPH_COMPLETION requires
213
+ // the LLM to produce instructor-compatible JSON which small local models
214
+ // (llama3.2) can't do reliably, causing infinite retries and timeouts.
215
+ const searchType = opts?.searchType ?? 'CHUNKS';
216
+ const topK = opts?.limit ?? 10;
217
+
218
+ try {
219
+ const res = await this.post(
220
+ '/api/v1/search',
221
+ { query, search_type: searchType, datasets: [this.config.dataset], topK },
222
+ this.config.searchTimeoutMs,
223
+ );
224
+
225
+ if (!res.ok) return [];
226
+
227
+ const data = (await res.json()) as Array<{
228
+ id?: string;
229
+ text?: string;
230
+ score?: number;
231
+ payload?: { id?: string };
232
+ }>;
233
+
234
+ // Position-based scoring when Cognee omits scores.
235
+ // Cognee returns results ordered by relevance but may not include numeric scores.
236
+ return data.slice(0, topK).map((item, idx) => ({
237
+ id: item.payload?.id ?? item.id ?? '',
238
+ score: item.score ?? positionScore(idx, data.length),
239
+ text: typeof item.text === 'string' ? item.text : String(item.text ?? ''),
240
+ searchType,
241
+ }));
242
+ } catch {
243
+ return [];
244
+ }
245
+ }
246
+
247
+ // ─── Config access ─────────────────────────────────────────────
248
+
249
+ getConfig(): Readonly<CogneeConfig> {
250
+ return { ...this.config };
251
+ }
252
+
253
+ getStatus(): CogneeStatus | null {
254
+ return this.healthCache?.status ?? null;
255
+ }
256
+
257
+ // ─── Auth ──────────────────────────────────────────────────────
258
+ // Auto-register + login pattern from Salvador MCP.
259
+ // Tries login first (account may already exist), falls back to register.
260
+
261
+ private async ensureAuth(): Promise<string> {
262
+ if (this.accessToken) return this.accessToken;
263
+
264
+ const email = this.config.serviceEmail ?? DEFAULT_SERVICE_EMAIL;
265
+ const password = this.config.servicePassword ?? DEFAULT_SERVICE_PASSWORD;
266
+
267
+ // Refuse default credentials for non-local endpoints
268
+ if (
269
+ !isLocalUrl(this.config.baseUrl) &&
270
+ email === DEFAULT_SERVICE_EMAIL &&
271
+ password === DEFAULT_SERVICE_PASSWORD
272
+ ) {
273
+ throw new Error('Explicit Cognee credentials are required for non-local endpoints');
274
+ }
275
+
276
+ // Try login first
277
+ const loginResp = await globalThis.fetch(`${this.config.baseUrl}/api/v1/auth/login`, {
278
+ method: 'POST',
279
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
280
+ body: `username=${encodeURIComponent(email)}&password=${encodeURIComponent(password)}`,
281
+ signal: AbortSignal.timeout(this.config.healthTimeoutMs),
282
+ });
283
+
284
+ if (loginResp.ok) {
285
+ const data = (await loginResp.json()) as { access_token: string };
286
+ this.accessToken = data.access_token;
287
+ return this.accessToken;
288
+ }
289
+
290
+ // Register, then retry login
291
+ await globalThis.fetch(`${this.config.baseUrl}/api/v1/auth/register`, {
292
+ method: 'POST',
293
+ headers: { 'Content-Type': 'application/json' },
294
+ body: JSON.stringify({ email, password }),
295
+ signal: AbortSignal.timeout(this.config.healthTimeoutMs),
296
+ });
297
+
298
+ const retryLogin = await globalThis.fetch(`${this.config.baseUrl}/api/v1/auth/login`, {
299
+ method: 'POST',
300
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
301
+ body: `username=${encodeURIComponent(email)}&password=${encodeURIComponent(password)}`,
302
+ signal: AbortSignal.timeout(this.config.healthTimeoutMs),
303
+ });
304
+
305
+ if (!retryLogin.ok) {
306
+ throw new Error(`Cognee auth failed: HTTP ${retryLogin.status}`);
307
+ }
308
+
309
+ const retryData = (await retryLogin.json()) as { access_token: string };
310
+ this.accessToken = retryData.access_token;
311
+ return this.accessToken;
312
+ }
313
+
314
+ private async authHeaders(): Promise<Record<string, string>> {
315
+ try {
316
+ const token = await this.ensureAuth();
317
+ return { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` };
318
+ } catch {
319
+ // Fall back to no auth (works if AUTH_REQUIRED=false)
320
+ return { 'Content-Type': 'application/json' };
321
+ }
322
+ }
323
+
324
+ // ─── Private helpers ───────────────────────────────────────────
325
+
326
+ private serializeEntry(entry: IntelligenceEntry): string {
327
+ const parts = [entry.title, entry.description];
328
+ if (entry.context) parts.push(entry.context);
329
+ if (entry.tags.length > 0) parts.push(`Tags: ${entry.tags.join(', ')}`);
330
+ return parts.join('\n');
331
+ }
332
+
333
+ private async post(path: string, body: unknown, timeoutMs?: number): Promise<Response> {
334
+ const headers = await this.authHeaders();
335
+ return globalThis.fetch(`${this.config.baseUrl}${path}`, {
336
+ method: 'POST',
337
+ headers,
338
+ body: JSON.stringify(body),
339
+ signal: AbortSignal.timeout(timeoutMs ?? this.config.timeoutMs),
340
+ });
341
+ }
342
+ }
343
+
344
+ // ─── Helpers ──────────────────────────────────────────────────────
345
+
346
+ /** Position-based score: first result gets ~1.0, last gets ~0.05. */
347
+ function positionScore(index: number, total: number): number {
348
+ if (total <= 1) return 1.0;
349
+ return Math.max(0.05, 1.0 - (index / (total - 1)) * 0.95);
350
+ }
@@ -0,0 +1,62 @@
1
+ // ─── Cognee Integration Types ──────────────────────────────────────
2
+
3
+ export interface CogneeConfig {
4
+ /** Base URL of the Cognee API (default: http://localhost:8000) */
5
+ baseUrl: string;
6
+ /** Dataset name for this agent's vault entries */
7
+ dataset: string;
8
+ /** Bearer token for Cognee API authentication (auto-acquired if not set) */
9
+ apiToken?: string;
10
+ /** Service account email for auto-login (default: soleri-agent@cognee.dev) */
11
+ serviceEmail?: string;
12
+ /** Service account password for auto-login */
13
+ servicePassword?: string;
14
+ /** Default request timeout in milliseconds (default: 30000) */
15
+ timeoutMs: number;
16
+ /** Search timeout in milliseconds — Ollama cold start can take 90s (default: 120000) */
17
+ searchTimeoutMs: number;
18
+ /** Health check timeout in milliseconds (default: 5000) */
19
+ healthTimeoutMs: number;
20
+ /** Health check cache TTL in milliseconds (default: 60000) */
21
+ healthCacheTtlMs: number;
22
+ /** Cognify debounce window in milliseconds (default: 30000) */
23
+ cognifyDebounceMs: number;
24
+ }
25
+
26
+ export interface CogneeSearchResult {
27
+ /** Vault entry ID (cross-reference key) */
28
+ id: string;
29
+ /** Relevance score (0–1). Position-based when Cognee omits scores. */
30
+ score: number;
31
+ /** Text content from Cognee */
32
+ text: string;
33
+ /** Cognee search type that produced this result */
34
+ searchType: CogneeSearchType;
35
+ }
36
+
37
+ export type CogneeSearchType =
38
+ | 'SUMMARIES'
39
+ | 'CHUNKS'
40
+ | 'RAG_COMPLETION'
41
+ | 'TRIPLET_COMPLETION'
42
+ | 'GRAPH_COMPLETION'
43
+ | 'GRAPH_SUMMARY_COMPLETION'
44
+ | 'NATURAL_LANGUAGE'
45
+ | 'GRAPH_COMPLETION_COT'
46
+ | 'FEELING_LUCKY'
47
+ | 'CHUNKS_LEXICAL';
48
+
49
+ export interface CogneeStatus {
50
+ available: boolean;
51
+ url: string;
52
+ latencyMs: number;
53
+ error?: string;
54
+ }
55
+
56
+ export interface CogneeAddResult {
57
+ added: number;
58
+ }
59
+
60
+ export interface CogneeCognifyResult {
61
+ status: string;
62
+ }
@@ -0,0 +1,64 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { z } from 'zod';
3
+ import type { FacadeConfig, FacadeResponse } from './types.js';
4
+
5
+ export function registerFacade(server: McpServer, facade: FacadeConfig): void {
6
+ const opNames = facade.ops.map((o) => o.name);
7
+
8
+ server.tool(
9
+ facade.name,
10
+ `${facade.description}\n\nOperations: ${opNames.join(', ')}`,
11
+ {
12
+ op: z.string().describe(`Operation: ${opNames.join(' | ')}`),
13
+ params: z.record(z.unknown()).optional().default({}).describe('Operation parameters'),
14
+ },
15
+ async ({ op, params }): Promise<{ content: Array<{ type: 'text'; text: string }> }> => {
16
+ const response = await dispatchOp(facade, op, params);
17
+ return { content: [{ type: 'text' as const, text: JSON.stringify(response, null, 2) }] };
18
+ },
19
+ );
20
+ }
21
+
22
+ async function dispatchOp(
23
+ facade: FacadeConfig,
24
+ opName: string,
25
+ params: Record<string, unknown>,
26
+ ): Promise<FacadeResponse> {
27
+ const op = facade.ops.find((o) => o.name === opName);
28
+ if (!op) {
29
+ return {
30
+ success: false,
31
+ error: `Unknown operation "${opName}" on ${facade.name}. Available: ${facade.ops.map((o) => o.name).join(', ')}`,
32
+ op: opName,
33
+ facade: facade.name,
34
+ };
35
+ }
36
+
37
+ try {
38
+ let validatedParams = params;
39
+ if (op.schema) {
40
+ const result = op.schema.safeParse(params);
41
+ if (!result.success) {
42
+ return {
43
+ success: false,
44
+ error: `Invalid params for ${opName}: ${result.error.message}`,
45
+ op: opName,
46
+ facade: facade.name,
47
+ };
48
+ }
49
+ validatedParams = result.data as Record<string, unknown>;
50
+ }
51
+
52
+ const data = await op.handler(validatedParams);
53
+ return { success: true, data, op: opName, facade: facade.name };
54
+ } catch (err) {
55
+ const message = err instanceof Error ? err.message : String(err);
56
+ return { success: false, error: message, op: opName, facade: facade.name };
57
+ }
58
+ }
59
+
60
+ export function registerAllFacades(server: McpServer, facades: FacadeConfig[]): void {
61
+ for (const facade of facades) {
62
+ registerFacade(server, facade);
63
+ }
64
+ }
@@ -0,0 +1,42 @@
1
+ import { z } from 'zod';
2
+
3
+ /** Handler function for a single facade operation */
4
+ export type OpHandler = (params: Record<string, unknown>) => Promise<unknown>;
5
+
6
+ /** Auth level required for an operation */
7
+ export type AuthLevel = 'read' | 'write' | 'admin';
8
+
9
+ /** Operation definition within a facade */
10
+ export interface OpDefinition {
11
+ name: string;
12
+ description: string;
13
+ auth: AuthLevel;
14
+ handler: OpHandler;
15
+ schema?: z.ZodType;
16
+ }
17
+
18
+ /** Facade configuration — one MCP tool */
19
+ export interface FacadeConfig {
20
+ /** MCP tool name */
21
+ name: string;
22
+ /** Human-readable description */
23
+ description: string;
24
+ /** Domain operations */
25
+ ops: OpDefinition[];
26
+ }
27
+
28
+ /** Standard facade response envelope */
29
+ export interface FacadeResponse {
30
+ success: boolean;
31
+ data?: unknown;
32
+ error?: string;
33
+ op?: string;
34
+ facade?: string;
35
+ }
36
+
37
+ export const facadeInputSchema = z.object({
38
+ op: z.string().describe('Operation name'),
39
+ params: z.record(z.unknown()).optional().default({}),
40
+ });
41
+
42
+ export type FacadeInput = z.infer<typeof facadeInputSchema>;
package/src/index.ts ADDED
@@ -0,0 +1,75 @@
1
+ // ─── Intelligence ────────────────────────────────────────────────────
2
+ export type { IntelligenceEntry, IntelligenceBundle } from './intelligence/types.js';
3
+ export { loadIntelligenceData } from './intelligence/loader.js';
4
+
5
+ // ─── Vault ───────────────────────────────────────────────────────────
6
+ export { Vault } from './vault/vault.js';
7
+ export type { SearchResult, VaultStats, ProjectInfo, Memory, MemoryStats } from './vault/vault.js';
8
+
9
+ // ─── Brain ───────────────────────────────────────────────────────────
10
+ export { Brain } from './brain/brain.js';
11
+ export type {
12
+ ScoringWeights,
13
+ ScoreBreakdown,
14
+ RankedResult,
15
+ SearchOptions,
16
+ CaptureResult,
17
+ BrainStats,
18
+ QueryContext,
19
+ } from './brain/brain.js';
20
+
21
+ // ─── Cognee ─────────────────────────────────────────────────────────
22
+ export { CogneeClient } from './cognee/client.js';
23
+ export type {
24
+ CogneeConfig,
25
+ CogneeSearchResult,
26
+ CogneeSearchType,
27
+ CogneeStatus,
28
+ CogneeAddResult,
29
+ CogneeCognifyResult,
30
+ } from './cognee/types.js';
31
+
32
+ // ─── Planning ────────────────────────────────────────────────────────
33
+ export { Planner } from './planning/planner.js';
34
+ export type { PlanStatus, TaskStatus, PlanTask, Plan, PlanStore } from './planning/planner.js';
35
+
36
+ // ─── LLM Types ───────────────────────────────────────────────────────
37
+ export { SecretString, LLMError } from './llm/types.js';
38
+ export type {
39
+ LLMCallOptions,
40
+ LLMCallResult,
41
+ CircuitState,
42
+ CircuitBreakerConfig,
43
+ CircuitBreakerSnapshot,
44
+ KeyPoolConfig,
45
+ KeyStatus,
46
+ RouteEntry,
47
+ RoutingConfig,
48
+ RateLimitInfo,
49
+ RetryConfig,
50
+ } from './llm/types.js';
51
+
52
+ // ─── LLM Utils ───────────────────────────────────────────────────────
53
+ export {
54
+ CircuitBreaker,
55
+ CircuitOpenError,
56
+ computeDelay,
57
+ retry,
58
+ parseRateLimitHeaders,
59
+ } from './llm/utils.js';
60
+
61
+ // ─── LLM Key Pool ───────────────────────────────────────────────────
62
+ export { KeyPool, loadKeyPoolConfig } from './llm/key-pool.js';
63
+ export type { KeyPoolFiles } from './llm/key-pool.js';
64
+
65
+ // ─── Facades ─────────────────────────────────────────────────────────
66
+ export { registerFacade, registerAllFacades } from './facades/facade-factory.js';
67
+ export { facadeInputSchema } from './facades/types.js';
68
+ export type {
69
+ OpHandler,
70
+ AuthLevel,
71
+ OpDefinition,
72
+ FacadeConfig,
73
+ FacadeResponse,
74
+ FacadeInput,
75
+ } from './facades/types.js';
@@ -0,0 +1,42 @@
1
+ import { readFileSync, readdirSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import type { IntelligenceBundle, IntelligenceEntry } from './types.js';
4
+
5
+ export function loadIntelligenceData(dataDir: string): IntelligenceEntry[] {
6
+ const entries: IntelligenceEntry[] = [];
7
+ let files: string[];
8
+ try {
9
+ files = readdirSync(dataDir).filter((f) => f.endsWith('.json'));
10
+ } catch {
11
+ console.warn('Intelligence data directory not found: ' + dataDir);
12
+ return entries;
13
+ }
14
+
15
+ for (const file of files) {
16
+ try {
17
+ const raw = readFileSync(join(dataDir, file), 'utf-8');
18
+ const bundle = JSON.parse(raw) as IntelligenceBundle;
19
+ if (!bundle.entries || !Array.isArray(bundle.entries)) continue;
20
+ for (const entry of bundle.entries) {
21
+ if (validateEntry(entry)) entries.push(entry);
22
+ }
23
+ } catch (err) {
24
+ console.warn('Failed to load ' + file + ': ' + (err instanceof Error ? err.message : err));
25
+ }
26
+ }
27
+ return entries;
28
+ }
29
+
30
+ function validateEntry(entry: IntelligenceEntry): boolean {
31
+ return (
32
+ typeof entry.id === 'string' &&
33
+ entry.id.length > 0 &&
34
+ ['pattern', 'anti-pattern', 'rule'].includes(entry.type) &&
35
+ typeof entry.title === 'string' &&
36
+ entry.title.length > 0 &&
37
+ typeof entry.description === 'string' &&
38
+ entry.description.length > 0 &&
39
+ ['critical', 'warning', 'suggestion'].includes(entry.severity) &&
40
+ Array.isArray(entry.tags)
41
+ );
42
+ }
@@ -0,0 +1,20 @@
1
+ export interface IntelligenceEntry {
2
+ id: string;
3
+ type: 'pattern' | 'anti-pattern' | 'rule';
4
+ domain: string;
5
+ title: string;
6
+ severity: 'critical' | 'warning' | 'suggestion';
7
+ description: string;
8
+ context?: string;
9
+ example?: string;
10
+ counterExample?: string;
11
+ why?: string;
12
+ tags: string[];
13
+ appliesTo?: string[];
14
+ }
15
+
16
+ export interface IntelligenceBundle {
17
+ domain: string;
18
+ version: string;
19
+ entries: IntelligenceEntry[];
20
+ }