@yugenlab/vaayu 0.1.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 (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +365 -0
  3. package/chunks/chunk-E5A3SCDJ.js +246 -0
  4. package/chunks/chunk-G5VYCA6O.js +69 -0
  5. package/chunks/chunk-H76V36OF.js +1029 -0
  6. package/chunks/chunk-HAPVUJ6A.js +238 -0
  7. package/chunks/chunk-IEKAYVA3.js +137 -0
  8. package/chunks/chunk-IGKYKEKT.js +43 -0
  9. package/chunks/chunk-IIET2K6D.js +7728 -0
  10. package/chunks/chunk-ITIVYGUG.js +347 -0
  11. package/chunks/chunk-JAWZ7ANC.js +208 -0
  12. package/chunks/chunk-JZU37VQ5.js +714 -0
  13. package/chunks/chunk-KC6NRZ7U.js +198 -0
  14. package/chunks/chunk-KDRROLVN.js +433 -0
  15. package/chunks/chunk-L7JICQBW.js +1006 -0
  16. package/chunks/chunk-MINFB5LT.js +1479 -0
  17. package/chunks/chunk-MJ74G5RB.js +5816 -0
  18. package/chunks/chunk-S4TBVCL2.js +2158 -0
  19. package/chunks/chunk-SMVJRPAH.js +2753 -0
  20. package/chunks/chunk-U6OLJ36B.js +438 -0
  21. package/chunks/chunk-URGEODS5.js +752 -0
  22. package/chunks/chunk-YSU3BWV6.js +123 -0
  23. package/chunks/consolidation-indexer-TOTTDZXW.js +21 -0
  24. package/chunks/day-consolidation-NKO63HZQ.js +24 -0
  25. package/chunks/graphrag-ZI2FSU7S.js +13 -0
  26. package/chunks/hierarchical-temporal-search-ZD46UMKR.js +8 -0
  27. package/chunks/hybrid-search-ZVLZVGFS.js +19 -0
  28. package/chunks/memory-store-KNJPMBLQ.js +17 -0
  29. package/chunks/periodic-consolidation-BPKOZDGB.js +10 -0
  30. package/chunks/postgres-3ZXBYTPC.js +8 -0
  31. package/chunks/recall-GMVHWQWW.js +20 -0
  32. package/chunks/search-7HZETVMZ.js +18 -0
  33. package/chunks/session-store-XKPGKXUS.js +44 -0
  34. package/chunks/sqlite-JPF5TICX.js +152 -0
  35. package/chunks/src-6GVZTUH6.js +12 -0
  36. package/chunks/src-QAXOD5SB.js +273 -0
  37. package/chunks/suncalc-NOHGYHDU.js +186 -0
  38. package/chunks/tree-RSHKDTCR.js +10 -0
  39. package/gateway.js +61944 -0
  40. package/package.json +51 -0
  41. package/pair-cli.js +133 -0
@@ -0,0 +1,347 @@
1
+ import {
2
+ getMemory,
3
+ listMemoryScopes
4
+ } from "./chunk-E5A3SCDJ.js";
5
+ import {
6
+ listSessions,
7
+ loadSession
8
+ } from "./chunk-L7JICQBW.js";
9
+ import {
10
+ DatabaseManager,
11
+ initAgentSchema
12
+ } from "./chunk-U6OLJ36B.js";
13
+
14
+ // ../chitragupta/packages/smriti/src/search.ts
15
+ var _dbInitialized = false;
16
+ function getAgentDb() {
17
+ const dbm = DatabaseManager.instance();
18
+ if (!_dbInitialized) {
19
+ try {
20
+ initAgentSchema(dbm);
21
+ _dbInitialized = true;
22
+ } catch (err) {
23
+ process.stderr.write(`[chitragupta] search DB schema init failed: ${err instanceof Error ? err.message : err}
24
+ `);
25
+ throw err;
26
+ }
27
+ }
28
+ return dbm.get("agent");
29
+ }
30
+ function _resetSearchDbInit() {
31
+ _dbInitialized = false;
32
+ }
33
+ function sanitizeFts5Query(query) {
34
+ const cleaned = query.replace(/[*^"(){}:]/g, "").replace(/\b(NOT|AND|OR|NEAR)\b/gi, "").trim();
35
+ if (!cleaned) return "";
36
+ const terms = cleaned.split(/\s+/).filter((t) => t.length >= 2).map((t) => `"${t}"`).join(" ");
37
+ return terms;
38
+ }
39
+ function recencyBoost(epochMs) {
40
+ const ageMs = Date.now() - epochMs;
41
+ const ageHours = ageMs / (1e3 * 60 * 60);
42
+ if (ageHours < 1) return 1.5 - 0.2 * (ageHours / 1);
43
+ if (ageHours < 24) return 1.3 - 0.2 * ((ageHours - 1) / 23);
44
+ if (ageHours < 168) return 1.1 - 0.1 * ((ageHours - 24) / 144);
45
+ return 1;
46
+ }
47
+ function recencyBoostIso(isoDate) {
48
+ return recencyBoost(new Date(isoDate).getTime());
49
+ }
50
+ var STOP_WORDS = /* @__PURE__ */ new Set([
51
+ "a",
52
+ "an",
53
+ "the",
54
+ "and",
55
+ "or",
56
+ "but",
57
+ "in",
58
+ "on",
59
+ "at",
60
+ "to",
61
+ "for",
62
+ "of",
63
+ "with",
64
+ "by",
65
+ "from",
66
+ "is",
67
+ "it",
68
+ "its",
69
+ "this",
70
+ "that",
71
+ "was",
72
+ "are",
73
+ "be",
74
+ "been",
75
+ "being",
76
+ "have",
77
+ "has",
78
+ "had",
79
+ "do",
80
+ "does",
81
+ "did",
82
+ "will",
83
+ "would",
84
+ "could",
85
+ "should",
86
+ "may",
87
+ "might",
88
+ "shall",
89
+ "can",
90
+ "not",
91
+ "no",
92
+ "nor",
93
+ "so",
94
+ "if",
95
+ "then",
96
+ "than",
97
+ "too",
98
+ "very",
99
+ "just",
100
+ "about",
101
+ "above",
102
+ "after",
103
+ "again",
104
+ "all",
105
+ "also",
106
+ "am",
107
+ "any",
108
+ "as",
109
+ "because",
110
+ "before",
111
+ "between",
112
+ "both",
113
+ "each",
114
+ "few",
115
+ "get",
116
+ "got",
117
+ "he",
118
+ "her",
119
+ "here",
120
+ "him",
121
+ "his",
122
+ "how",
123
+ "i",
124
+ "into",
125
+ "me",
126
+ "more",
127
+ "most",
128
+ "my",
129
+ "now",
130
+ "only",
131
+ "other",
132
+ "our",
133
+ "out",
134
+ "over",
135
+ "own",
136
+ "s",
137
+ "same",
138
+ "she",
139
+ "some",
140
+ "still",
141
+ "such",
142
+ "t",
143
+ "their",
144
+ "them",
145
+ "there",
146
+ "these",
147
+ "they",
148
+ "those",
149
+ "through",
150
+ "under",
151
+ "up",
152
+ "us",
153
+ "we",
154
+ "what",
155
+ "when",
156
+ "where",
157
+ "which",
158
+ "while",
159
+ "who",
160
+ "whom",
161
+ "why",
162
+ "you",
163
+ "your"
164
+ ]);
165
+ var BM25_K1 = 1.2;
166
+ var BM25_B = 0.75;
167
+ function tokenize(text) {
168
+ return text.toLowerCase().replace(/[^a-z0-9\s]/g, " ").split(/\s+/).filter((t) => t.length >= 2 && !STOP_WORDS.has(t));
169
+ }
170
+ var BM25Corpus = class {
171
+ documents = [];
172
+ df = /* @__PURE__ */ new Map();
173
+ avgDl = 0;
174
+ addDocument(payload, text) {
175
+ const tokens = tokenize(text);
176
+ const tf = /* @__PURE__ */ new Map();
177
+ for (const token of tokens) {
178
+ tf.set(token, (tf.get(token) ?? 0) + 1);
179
+ }
180
+ this.documents.push({ payload, tf, length: tokens.length });
181
+ for (const term of tf.keys()) {
182
+ this.df.set(term, (this.df.get(term) ?? 0) + 1);
183
+ }
184
+ }
185
+ finalize() {
186
+ if (this.documents.length === 0) {
187
+ this.avgDl = 0;
188
+ return;
189
+ }
190
+ const totalLength = this.documents.reduce((sum, doc) => sum + doc.length, 0);
191
+ this.avgDl = totalLength / this.documents.length;
192
+ }
193
+ idf(term) {
194
+ const N = this.documents.length;
195
+ const df = this.df.get(term) ?? 0;
196
+ return Math.log((N - df + 0.5) / (df + 0.5) + 1);
197
+ }
198
+ scoreDocument(doc, queryTerms) {
199
+ let score = 0;
200
+ for (const term of queryTerms) {
201
+ const tf = doc.tf.get(term) ?? 0;
202
+ if (tf === 0) continue;
203
+ const idf = this.idf(term);
204
+ const numerator = tf * (BM25_K1 + 1);
205
+ const denominator = tf + BM25_K1 * (1 - BM25_B + BM25_B * (doc.length / (this.avgDl || 1)));
206
+ score += idf * (numerator / denominator);
207
+ }
208
+ return score;
209
+ }
210
+ query(queryText) {
211
+ const queryTerms = tokenize(queryText);
212
+ if (queryTerms.length === 0) return [];
213
+ const results = [];
214
+ for (const doc of this.documents) {
215
+ const score = this.scoreDocument(doc, queryTerms);
216
+ if (score > 0) results.push({ payload: doc.payload, score });
217
+ }
218
+ results.sort((a, b) => b.score - a.score);
219
+ return results;
220
+ }
221
+ };
222
+ function searchSessions(query, project) {
223
+ if (!query || query.trim().length === 0) return [];
224
+ try {
225
+ return searchSessionsFts5(query, project);
226
+ } catch (err) {
227
+ process.stderr.write(`[chitragupta] FTS5 search failed, falling back to BM25: ${err instanceof Error ? err.message : err}
228
+ `);
229
+ return searchSessionsBm25(query, project);
230
+ }
231
+ }
232
+ function searchSessionsFts5(query, project) {
233
+ const ftsQuery = sanitizeFts5Query(query);
234
+ if (!ftsQuery) return [];
235
+ const db = getAgentDb();
236
+ const sql = project ? `SELECT t.session_id, t.turn_number, t.content, f.rank,
237
+ s.title, s.project, s.created_at, s.updated_at,
238
+ s.agent, s.model, s.cost, s.tokens, s.tags, s.parent_id, s.branch
239
+ FROM turns_fts f
240
+ JOIN turns t ON t.id = f.rowid
241
+ JOIN sessions s ON s.id = t.session_id
242
+ WHERE turns_fts MATCH ? AND s.project = ?
243
+ ORDER BY f.rank
244
+ LIMIT 200` : `SELECT t.session_id, t.turn_number, t.content, f.rank,
245
+ s.title, s.project, s.created_at, s.updated_at,
246
+ s.agent, s.model, s.cost, s.tokens, s.tags, s.parent_id, s.branch
247
+ FROM turns_fts f
248
+ JOIN turns t ON t.id = f.rowid
249
+ JOIN sessions s ON s.id = t.session_id
250
+ WHERE turns_fts MATCH ?
251
+ ORDER BY f.rank
252
+ LIMIT 200`;
253
+ const rows = project ? db.prepare(sql).all(ftsQuery, project) : db.prepare(sql).all(ftsQuery);
254
+ const sessionBest = /* @__PURE__ */ new Map();
255
+ for (const row of rows) {
256
+ const bm25Score = -row.rank;
257
+ const boost = recencyBoost(row.updated_at);
258
+ const finalScore = bm25Score * boost;
259
+ const existing = sessionBest.get(row.session_id);
260
+ if (!existing || finalScore > existing.score) {
261
+ sessionBest.set(row.session_id, { row, score: finalScore });
262
+ }
263
+ }
264
+ const sorted = [...sessionBest.values()].sort((a, b) => b.score - a.score);
265
+ return sorted.map(({ row }) => ({
266
+ id: row.session_id,
267
+ title: row.title,
268
+ created: new Date(row.created_at).toISOString(),
269
+ updated: new Date(row.updated_at).toISOString(),
270
+ agent: row.agent ?? "chitragupta",
271
+ model: row.model ?? "unknown",
272
+ project: row.project,
273
+ parent: row.parent_id ?? null,
274
+ branch: row.branch ?? null,
275
+ tags: (() => {
276
+ try {
277
+ return JSON.parse(row.tags ?? "[]");
278
+ } catch {
279
+ return [];
280
+ }
281
+ })(),
282
+ totalCost: row.cost ?? 0,
283
+ totalTokens: row.tokens ?? 0
284
+ }));
285
+ }
286
+ function searchSessionsBm25(query, project) {
287
+ const allMetas = listSessions(project);
288
+ const corpus = new BM25Corpus();
289
+ for (const meta of allMetas) {
290
+ const parts = [];
291
+ parts.push(meta.title, meta.title, meta.title);
292
+ const tagsText = meta.tags.join(" ");
293
+ parts.push(tagsText, tagsText);
294
+ parts.push(meta.agent);
295
+ try {
296
+ const session = loadSession(meta.id, meta.project);
297
+ for (const turn of session.turns) {
298
+ parts.push(turn.content);
299
+ if (turn.toolCalls) {
300
+ for (const tc of turn.toolCalls) {
301
+ parts.push(tc.name, tc.input, tc.result);
302
+ }
303
+ }
304
+ }
305
+ } catch {
306
+ }
307
+ corpus.addDocument(meta, parts.join(" "));
308
+ }
309
+ corpus.finalize();
310
+ const results = corpus.query(query);
311
+ const boosted = results.map((r) => ({
312
+ meta: r.payload,
313
+ score: r.score * recencyBoostIso(r.payload.updated)
314
+ }));
315
+ boosted.sort((a, b) => b.score - a.score);
316
+ return boosted.map((s) => s.meta);
317
+ }
318
+ function searchMemory(query) {
319
+ if (!query || query.trim().length === 0) return [];
320
+ const scopes = listMemoryScopes();
321
+ const corpus = new BM25Corpus();
322
+ for (const scope of scopes) {
323
+ try {
324
+ const content = getMemory(scope);
325
+ if (!content) continue;
326
+ corpus.addDocument({ scope, content }, content);
327
+ } catch {
328
+ }
329
+ }
330
+ corpus.finalize();
331
+ const results = corpus.query(query);
332
+ if (results.length === 0) return [];
333
+ const maxScore = results[0].score;
334
+ return results.map((r) => ({
335
+ scope: r.payload.scope,
336
+ content: r.payload.content,
337
+ relevance: maxScore > 0 ? r.score / maxScore : 0
338
+ }));
339
+ }
340
+
341
+ export {
342
+ _resetSearchDbInit,
343
+ sanitizeFts5Query,
344
+ searchSessions,
345
+ searchMemory
346
+ };
347
+ //# sourceMappingURL=chunk-ITIVYGUG.js.map
@@ -0,0 +1,208 @@
1
+ // ../chitragupta/packages/smriti/src/graphrag-scoring.ts
2
+ var ALPHA = 0.6;
3
+ var BETA = 0.25;
4
+ var GAMMA = 0.15;
5
+ var STOP_WORDS = /* @__PURE__ */ new Set([
6
+ "a",
7
+ "an",
8
+ "the",
9
+ "and",
10
+ "or",
11
+ "but",
12
+ "in",
13
+ "on",
14
+ "at",
15
+ "to",
16
+ "for",
17
+ "of",
18
+ "with",
19
+ "by",
20
+ "from",
21
+ "is",
22
+ "it",
23
+ "this",
24
+ "that",
25
+ "was",
26
+ "are",
27
+ "be",
28
+ "have",
29
+ "has",
30
+ "had",
31
+ "do",
32
+ "does",
33
+ "did",
34
+ "will",
35
+ "would",
36
+ "could",
37
+ "should",
38
+ "not",
39
+ "no"
40
+ ]);
41
+ function cosineSimilarity(a, b) {
42
+ if (a.length !== b.length) return 0;
43
+ let dotProduct = 0;
44
+ let normA = 0;
45
+ let normB = 0;
46
+ for (let i = 0; i < a.length; i++) {
47
+ dotProduct += a[i] * b[i];
48
+ normA += a[i] * a[i];
49
+ normB += b[i] * b[i];
50
+ }
51
+ const denominator = Math.sqrt(normA) * Math.sqrt(normB);
52
+ if (denominator === 0) return 0;
53
+ return dotProduct / denominator;
54
+ }
55
+ function estimateTokens(text) {
56
+ return Math.ceil(text.length / 4);
57
+ }
58
+ function tokenize(text) {
59
+ return text.toLowerCase().replace(/[^a-z0-9\s]/g, " ").split(/\s+/).filter((t) => t.length >= 2 && !STOP_WORDS.has(t));
60
+ }
61
+ function textMatchScore(query, docText) {
62
+ const queryTokens = tokenize(query);
63
+ const docTokens = tokenize(docText);
64
+ if (queryTokens.length === 0 || docTokens.length === 0) return 0;
65
+ const docTf = /* @__PURE__ */ new Map();
66
+ for (const token of docTokens) {
67
+ docTf.set(token, (docTf.get(token) ?? 0) + 1);
68
+ }
69
+ let score = 0;
70
+ let matchedTerms = 0;
71
+ for (const qTerm of queryTokens) {
72
+ const tf = docTf.get(qTerm) ?? 0;
73
+ if (tf > 0) {
74
+ score += 1 + Math.log(1 + tf);
75
+ matchedTerms++;
76
+ }
77
+ }
78
+ const coverage = matchedTerms / queryTokens.length;
79
+ score *= 0.5 + 0.5 * coverage;
80
+ score /= queryTokens.length;
81
+ return Math.min(score, 1);
82
+ }
83
+
84
+ // ../chitragupta/packages/smriti/src/embedding-service.ts
85
+ var FALLBACK_DIM = 384;
86
+ var DEFAULT_MAX_CACHE = 5e3;
87
+ var MAX_CACHE_CEILING = 2e4;
88
+ function fnv1aHash(text) {
89
+ let h1 = 2166136261;
90
+ let h2 = 16777619;
91
+ for (let i = 0; i < text.length; i++) {
92
+ const c = text.charCodeAt(i);
93
+ h1 = Math.imul(h1 ^ c, 16777619);
94
+ h2 = Math.imul(h2 ^ c >> 8, 16777619);
95
+ }
96
+ return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
97
+ }
98
+ function fallbackEmbedding(text) {
99
+ const vector = new Array(FALLBACK_DIM).fill(0);
100
+ const lower = text.toLowerCase();
101
+ for (let i = 0; i < lower.length; i++) {
102
+ const code = lower.charCodeAt(i);
103
+ const idx = (code * 7 + i * 13) % FALLBACK_DIM;
104
+ vector[idx] += 1;
105
+ }
106
+ const magnitude = Math.sqrt(vector.reduce((sum, v) => sum + v * v, 0));
107
+ if (magnitude > 0) {
108
+ for (let i = 0; i < FALLBACK_DIM; i++) {
109
+ vector[i] /= magnitude;
110
+ }
111
+ }
112
+ return vector;
113
+ }
114
+ var LRUCache = class {
115
+ map = /* @__PURE__ */ new Map();
116
+ maxSize;
117
+ constructor(maxSize) {
118
+ this.maxSize = maxSize;
119
+ }
120
+ get(key) {
121
+ const value = this.map.get(key);
122
+ if (value !== void 0) {
123
+ this.map.delete(key);
124
+ this.map.set(key, value);
125
+ }
126
+ return value;
127
+ }
128
+ set(key, value) {
129
+ if (this.map.has(key)) {
130
+ this.map.delete(key);
131
+ } else if (this.map.size >= this.maxSize) {
132
+ const oldest = this.map.keys().next().value;
133
+ if (oldest !== void 0) {
134
+ this.map.delete(oldest);
135
+ }
136
+ }
137
+ this.map.set(key, value);
138
+ }
139
+ get size() {
140
+ return this.map.size;
141
+ }
142
+ clear() {
143
+ this.map.clear();
144
+ }
145
+ };
146
+ var EmbeddingService = class {
147
+ provider;
148
+ cache;
149
+ providerAvailable = null;
150
+ constructor(provider, maxCacheSize) {
151
+ this.provider = provider;
152
+ const bounded = Math.min(maxCacheSize ?? DEFAULT_MAX_CACHE, MAX_CACHE_CEILING);
153
+ this.cache = new LRUCache(bounded);
154
+ }
155
+ async getEmbedding(text) {
156
+ const cacheKey = fnv1aHash(text);
157
+ const cached = this.cache.get(cacheKey);
158
+ if (cached) return cached;
159
+ let vector;
160
+ if (this.provider) {
161
+ if (this.providerAvailable === null) {
162
+ try {
163
+ this.providerAvailable = await this.provider.isConfigured();
164
+ } catch {
165
+ this.providerAvailable = false;
166
+ }
167
+ }
168
+ if (this.providerAvailable) {
169
+ try {
170
+ const result = await this.provider.embed(text);
171
+ vector = result.embedding;
172
+ } catch {
173
+ this.providerAvailable = false;
174
+ vector = fallbackEmbedding(text);
175
+ }
176
+ } else {
177
+ vector = fallbackEmbedding(text);
178
+ }
179
+ } else {
180
+ vector = fallbackEmbedding(text);
181
+ }
182
+ this.cache.set(cacheKey, vector);
183
+ return vector;
184
+ }
185
+ resetAvailability() {
186
+ this.providerAvailable = null;
187
+ }
188
+ clearCache() {
189
+ this.cache.clear();
190
+ }
191
+ /** Current number of cached embeddings. */
192
+ get cacheSize() {
193
+ return this.cache.size;
194
+ }
195
+ };
196
+
197
+ export {
198
+ ALPHA,
199
+ BETA,
200
+ GAMMA,
201
+ STOP_WORDS,
202
+ cosineSimilarity,
203
+ estimateTokens,
204
+ textMatchScore,
205
+ fallbackEmbedding,
206
+ EmbeddingService
207
+ };
208
+ //# sourceMappingURL=chunk-JAWZ7ANC.js.map