@terminals-tech/sdk 1.0.0-rc.1 → 1.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 (82) hide show
  1. package/README.md +15 -19
  2. package/dist/WebContainerManager-4LIOGRVM.js +22 -0
  3. package/dist/browser-http-client-ZQLDWZMU.js +317 -0
  4. package/dist/cache-VKYSQRXX.js +45 -0
  5. package/dist/capabilities-MIPUMBLL.js +96 -0
  6. package/dist/chunk-2ESYSVXG.js +48 -0
  7. package/dist/chunk-2WTYE4SW.js +190 -0
  8. package/dist/chunk-3LFMIVJM.js +40 -0
  9. package/dist/chunk-ABCK4FWN.js +136 -0
  10. package/dist/chunk-AFDUOYHD.js +2060 -0
  11. package/dist/chunk-BCOQMFKT.js +265 -0
  12. package/dist/chunk-BYXBJQAS.js +0 -0
  13. package/dist/chunk-DKFJIILR.js +9798 -0
  14. package/dist/chunk-EXI3LJVJ.js +51 -0
  15. package/dist/chunk-FOXUEYWK.js +42 -0
  16. package/dist/chunk-GJWAJAX3.js +173 -0
  17. package/dist/chunk-H3POJCFA.js +333 -0
  18. package/dist/chunk-KASHT6C5.js +784 -0
  19. package/dist/chunk-KHR7ZYCX.js +4034 -0
  20. package/dist/chunk-L45BSQDJ.js +296 -0
  21. package/dist/chunk-LLGZTP3G.js +5521 -0
  22. package/dist/chunk-NTMBOESX.js +152 -0
  23. package/dist/chunk-OCLSAUCD.js +474 -0
  24. package/dist/chunk-OSSRZOGC.js +190 -0
  25. package/dist/chunk-PPFTKJDB.js +497 -0
  26. package/dist/chunk-PWAHFID5.js +381 -0
  27. package/dist/chunk-Q2VI6ICE.js +188 -0
  28. package/dist/chunk-QJFKEQHF.js +6460 -0
  29. package/dist/chunk-QWXPVB2L.js +320 -0
  30. package/dist/chunk-QWZRZKLZ.js +896 -0
  31. package/dist/chunk-STMI72WH.js +1005 -0
  32. package/dist/chunk-TSQ3BGLA.js +11945 -0
  33. package/dist/chunk-UJDUQNE2.js +79 -0
  34. package/dist/chunk-VZA2NUH3.js +118 -0
  35. package/dist/chunk-WGBCRNMB.js +1817 -0
  36. package/dist/chunk-WU4OTGJE.js +752 -0
  37. package/dist/chunk-XPJ63Y6T.js +70 -0
  38. package/dist/chunk-Y2EULKA2.js +172 -0
  39. package/dist/chunk-YJEZWCYV.js +94 -0
  40. package/dist/chunk-ZVO47SQV.js +150 -0
  41. package/dist/container-lite-QD3CRLS4.js +327 -0
  42. package/dist/core-H2UUDATO.js +146 -0
  43. package/dist/crypto-D4LMI2RN.js +45 -0
  44. package/dist/db-BWC2GGBN.js +50 -0
  45. package/dist/demo-T655Z5S4.js +87 -0
  46. package/dist/diagnostics-6RQTBR6I.js +113 -0
  47. package/dist/dist-OPDCWARF.js +727 -0
  48. package/dist/dist-VXJEKX3T.js +2441 -0
  49. package/dist/dist-VYGJXGUS.js +1008 -0
  50. package/dist/embeddings-7QXTXUMC.js +15 -0
  51. package/dist/embeddings-MAEWWUHW.js +9 -0
  52. package/dist/graph-RKMNE2X5.js +36 -0
  53. package/dist/hvm-CBEP3M4F.js +126 -0
  54. package/dist/index.cjs +49874 -8001
  55. package/dist/index.d.cts +1629 -1363
  56. package/dist/index.d.ts +1629 -1363
  57. package/dist/index.js +2462 -8130
  58. package/dist/mcp-NK34ZNM5.js +101 -0
  59. package/dist/mcp-client-service-browser-SGB2K3VZ.js +14 -0
  60. package/dist/neuro-state-XHRGIRVO.js +498 -0
  61. package/dist/nodes-K6GKI2FM.js +364 -0
  62. package/dist/package-EXUIU2RL.js +93 -0
  63. package/dist/package-VGL7HYTO.js +106 -0
  64. package/dist/package-XHMLOAQ4.js +98 -0
  65. package/dist/pg-events-QJAM2HIP.js +15 -0
  66. package/dist/pglite-adapter-43IOUBMV.js +50 -0
  67. package/dist/pgliteService-IUGNNOVU.js +258 -0
  68. package/dist/policy-IRJCM6FS.js +13 -0
  69. package/dist/registry-5WTDYQVQ.js +26 -0
  70. package/dist/registry-FW63E7FE.js +16 -0
  71. package/dist/registry-ZQ2IBLF6.js +9 -0
  72. package/dist/resolver-ALOJSOK5.js +24 -0
  73. package/dist/scheduler-B5CEYKWT.js +127 -0
  74. package/dist/secret-store-H7273UIT.js +18 -0
  75. package/dist/server-VW6DYDLH.js +18 -0
  76. package/dist/skills-VN7IN7SJ.js +6375 -0
  77. package/dist/stack-4KWCQQP7.js +103 -0
  78. package/dist/storage-L7MWNSPG.js +13 -0
  79. package/dist/supabaseService-6AYP2VY3.js +476 -0
  80. package/dist/topology-CIWWNVAN.js +13 -0
  81. package/dist/webcontainer-XWCE56F3.js +281 -0
  82. package/package.json +9 -3
@@ -0,0 +1,727 @@
1
+ import {
2
+ __commonJS,
3
+ __require
4
+ } from "./chunk-2ESYSVXG.js";
5
+
6
+ // ../../node_modules/@terminals-tech/embeddings/dist/types.js
7
+ var require_types = __commonJS({
8
+ "../../node_modules/@terminals-tech/embeddings/dist/types.js"(exports) {
9
+ "use strict";
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ }
12
+ });
13
+
14
+ // ../../node_modules/@terminals-tech/embeddings/dist/cache.js
15
+ var require_cache = __commonJS({
16
+ "../../node_modules/@terminals-tech/embeddings/dist/cache.js"(exports) {
17
+ "use strict";
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.EmbeddingCache = void 0;
20
+ var EmbeddingCache = class {
21
+ constructor(options = {}) {
22
+ this.cache = /* @__PURE__ */ new Map();
23
+ this.lru = [];
24
+ this.timestamps = /* @__PURE__ */ new Map();
25
+ this.hitCount = 0;
26
+ this.missCount = 0;
27
+ this.maxSize = options.maxSize || 1e3;
28
+ this.ttlMs = options.ttlMs;
29
+ this.quantize = options.quantize || false;
30
+ }
31
+ /**
32
+ * Get an embedding from cache
33
+ */
34
+ get(key) {
35
+ if (!this.cache.has(key)) {
36
+ return null;
37
+ }
38
+ if (this.ttlMs) {
39
+ const timestamp = this.timestamps.get(key);
40
+ if (timestamp && Date.now() - timestamp > this.ttlMs) {
41
+ this.delete(key);
42
+ return null;
43
+ }
44
+ }
45
+ this.updateLRU(key);
46
+ const cached = this.cache.get(key);
47
+ if (this.quantize) {
48
+ return this.dequantizeVector(cached);
49
+ }
50
+ return cached;
51
+ }
52
+ /**
53
+ * Set an embedding in cache
54
+ */
55
+ set(key, embedding) {
56
+ if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
57
+ const oldest = this.lru.shift();
58
+ if (oldest) {
59
+ this.cache.delete(oldest);
60
+ this.timestamps.delete(oldest);
61
+ }
62
+ }
63
+ const toStore = this.quantize ? this.quantizeVector(embedding) : embedding;
64
+ this.cache.set(key, toStore);
65
+ this.timestamps.set(key, Date.now());
66
+ this.updateLRU(key);
67
+ }
68
+ /**
69
+ * Delete an entry from cache
70
+ */
71
+ delete(key) {
72
+ this.cache.delete(key);
73
+ this.timestamps.delete(key);
74
+ const index = this.lru.indexOf(key);
75
+ if (index > -1) {
76
+ this.lru.splice(index, 1);
77
+ }
78
+ }
79
+ /**
80
+ * Clear the entire cache
81
+ */
82
+ clear() {
83
+ this.cache.clear();
84
+ this.timestamps.clear();
85
+ this.lru = [];
86
+ }
87
+ /**
88
+ * Get cache statistics
89
+ */
90
+ stats() {
91
+ const size = this.cache.size;
92
+ const bytesPerVector = this.quantize ? 1 : 4;
93
+ const avgDimensions = 384;
94
+ const memoryUsage = size * avgDimensions * bytesPerVector;
95
+ return {
96
+ size,
97
+ maxSize: this.maxSize,
98
+ hitRate: this.hitCount / Math.max(1, this.hitCount + this.missCount),
99
+ memoryUsage
100
+ };
101
+ }
102
+ /**
103
+ * Update LRU order
104
+ */
105
+ updateLRU(key) {
106
+ const index = this.lru.indexOf(key);
107
+ if (index > -1) {
108
+ this.lru.splice(index, 1);
109
+ }
110
+ this.lru.push(key);
111
+ }
112
+ /**
113
+ * Quantize to int8 (saves 75% memory)
114
+ */
115
+ quantizeVector(vector) {
116
+ const { values, dimensions, normalized } = vector;
117
+ let min = Infinity;
118
+ let max = -Infinity;
119
+ for (let i = 0; i < dimensions; i++) {
120
+ min = Math.min(min, values[i]);
121
+ max = Math.max(max, values[i]);
122
+ }
123
+ const scale = 255 / (max - min);
124
+ const quantized = new Int8Array(dimensions);
125
+ for (let i = 0; i < dimensions; i++) {
126
+ quantized[i] = Math.round((values[i] - min) * scale - 128);
127
+ }
128
+ const metadata = new Float32Array(dimensions);
129
+ metadata[0] = min;
130
+ metadata[1] = max;
131
+ for (let i = 0; i < dimensions; i++) {
132
+ metadata[i + 2] = quantized[i];
133
+ }
134
+ return { values: metadata, dimensions, normalized };
135
+ }
136
+ /**
137
+ * Dequantize from int8 back to float32
138
+ */
139
+ dequantizeVector(vector) {
140
+ const { values, dimensions, normalized } = vector;
141
+ const min = values[0];
142
+ const max = values[1];
143
+ const scale = 255 / (max - min);
144
+ const dequantized = new Float32Array(dimensions);
145
+ for (let i = 0; i < dimensions; i++) {
146
+ const quantized = values[i + 2];
147
+ dequantized[i] = (quantized + 128) / scale + min;
148
+ }
149
+ return { values: dequantized, dimensions, normalized };
150
+ }
151
+ };
152
+ exports.EmbeddingCache = EmbeddingCache;
153
+ }
154
+ });
155
+
156
+ // ../../node_modules/@terminals-tech/embeddings/dist/providers/base.js
157
+ var require_base = __commonJS({
158
+ "../../node_modules/@terminals-tech/embeddings/dist/providers/base.js"(exports) {
159
+ "use strict";
160
+ Object.defineProperty(exports, "__esModule", { value: true });
161
+ exports.BaseEmbeddingProvider = void 0;
162
+ var cache_1 = require_cache();
163
+ var BaseEmbeddingProvider = class {
164
+ get ready() {
165
+ return this._ready;
166
+ }
167
+ constructor(options = {}) {
168
+ this.options = options;
169
+ this._ready = false;
170
+ if (options.cache !== false) {
171
+ this.cache = new cache_1.EmbeddingCache({
172
+ maxSize: options.cacheSize || 1e3,
173
+ ttlMs: options.cacheTTL,
174
+ quantize: options.quantizeCache || false
175
+ });
176
+ }
177
+ }
178
+ /**
179
+ * Generate embedding with caching
180
+ */
181
+ async embed(text) {
182
+ if (this.cache) {
183
+ const cached = this.cache.get(text);
184
+ if (cached)
185
+ return cached;
186
+ }
187
+ const embedding = await this.embedInternal(text);
188
+ if (this.cache) {
189
+ this.cache.set(text, embedding);
190
+ }
191
+ return embedding;
192
+ }
193
+ /**
194
+ * Batch embedding with optimal processing
195
+ */
196
+ async embedBatch(texts) {
197
+ const results = new Array(texts.length);
198
+ const toProcess = [];
199
+ for (let i = 0; i < texts.length; i++) {
200
+ if (this.cache) {
201
+ const cached = this.cache.get(texts[i]);
202
+ if (cached) {
203
+ results[i] = cached;
204
+ continue;
205
+ }
206
+ }
207
+ toProcess.push({ index: i, text: texts[i] });
208
+ }
209
+ if (toProcess.length > 0) {
210
+ const embeddings = await this.embedBatchInternal(toProcess.map((item) => item.text));
211
+ for (let i = 0; i < toProcess.length; i++) {
212
+ const { index, text } = toProcess[i];
213
+ results[index] = embeddings[i];
214
+ if (this.cache) {
215
+ this.cache.set(text, embeddings[i]);
216
+ }
217
+ }
218
+ }
219
+ return results;
220
+ }
221
+ /**
222
+ * Calculate cosine similarity between two vectors
223
+ */
224
+ similarity(a, b) {
225
+ if (a.dimensions !== b.dimensions) {
226
+ throw new Error("Vectors must have same dimensions");
227
+ }
228
+ let dotProduct = 0;
229
+ let normA = 0;
230
+ let normB = 0;
231
+ for (let i = 0; i < a.dimensions; i++) {
232
+ dotProduct += a.values[i] * b.values[i];
233
+ normA += a.values[i] * a.values[i];
234
+ normB += b.values[i] * b.values[i];
235
+ }
236
+ if (a.normalized && b.normalized) {
237
+ return dotProduct;
238
+ }
239
+ return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
240
+ }
241
+ /**
242
+ * Normalize a vector
243
+ */
244
+ normalize(vector) {
245
+ let norm = 0;
246
+ for (let i = 0; i < vector.length; i++) {
247
+ norm += vector[i] * vector[i];
248
+ }
249
+ norm = Math.sqrt(norm);
250
+ const normalized = new Float32Array(vector.length);
251
+ for (let i = 0; i < vector.length; i++) {
252
+ normalized[i] = vector[i] / norm;
253
+ }
254
+ return normalized;
255
+ }
256
+ /**
257
+ * Clean up resources
258
+ */
259
+ dispose() {
260
+ this.cache?.clear();
261
+ this._ready = false;
262
+ }
263
+ };
264
+ exports.BaseEmbeddingProvider = BaseEmbeddingProvider;
265
+ }
266
+ });
267
+
268
+ // ../../node_modules/@terminals-tech/embeddings/dist/providers/mock.js
269
+ var require_mock = __commonJS({
270
+ "../../node_modules/@terminals-tech/embeddings/dist/providers/mock.js"(exports) {
271
+ "use strict";
272
+ Object.defineProperty(exports, "__esModule", { value: true });
273
+ exports.MockEmbeddingProvider = void 0;
274
+ var base_1 = require_base();
275
+ var MockEmbeddingProvider = class extends base_1.BaseEmbeddingProvider {
276
+ constructor() {
277
+ super(...arguments);
278
+ this.name = "mock";
279
+ this.dimensions = 64;
280
+ this.maxTokens = 512;
281
+ }
282
+ async initialize() {
283
+ this._ready = true;
284
+ }
285
+ async embedInternal(text) {
286
+ const values = this.generateMockEmbedding(text);
287
+ return {
288
+ values,
289
+ dimensions: this.dimensions,
290
+ normalized: true
291
+ };
292
+ }
293
+ async embedBatchInternal(texts) {
294
+ return texts.map((text) => ({
295
+ values: this.generateMockEmbedding(text),
296
+ dimensions: this.dimensions,
297
+ normalized: true
298
+ }));
299
+ }
300
+ /**
301
+ * Generate a deterministic mock embedding from text
302
+ */
303
+ generateMockEmbedding(text) {
304
+ const embedding = new Float32Array(this.dimensions);
305
+ let hash = 0;
306
+ for (let i = 0; i < text.length; i++) {
307
+ hash = (hash << 5) - hash + text.charCodeAt(i);
308
+ hash = hash & hash;
309
+ }
310
+ for (let i = 0; i < this.dimensions; i++) {
311
+ const seed = hash + i * 31;
312
+ const x = Math.sin(seed) * 1e4;
313
+ embedding[i] = x - Math.floor(x);
314
+ if (i < 10) {
315
+ embedding[i] += text.length / 1e3;
316
+ } else if (i < 20) {
317
+ const words = text.split(/\s+/).length;
318
+ embedding[i] += words / 100;
319
+ } else if (i < 30) {
320
+ const punctuation = (text.match(/[.,!?;:]/g) || []).length;
321
+ embedding[i] += punctuation / 50;
322
+ }
323
+ }
324
+ return this.normalize(embedding);
325
+ }
326
+ };
327
+ exports.MockEmbeddingProvider = MockEmbeddingProvider;
328
+ }
329
+ });
330
+
331
+ // ../../node_modules/@terminals-tech/embeddings/dist/providers/transformers.js
332
+ var require_transformers = __commonJS({
333
+ "../../node_modules/@terminals-tech/embeddings/dist/providers/transformers.js"(exports) {
334
+ "use strict";
335
+ var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
336
+ if (k2 === void 0) k2 = k;
337
+ var desc = Object.getOwnPropertyDescriptor(m, k);
338
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
339
+ desc = { enumerable: true, get: function() {
340
+ return m[k];
341
+ } };
342
+ }
343
+ Object.defineProperty(o, k2, desc);
344
+ }) : (function(o, m, k, k2) {
345
+ if (k2 === void 0) k2 = k;
346
+ o[k2] = m[k];
347
+ }));
348
+ var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
349
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
350
+ }) : function(o, v) {
351
+ o["default"] = v;
352
+ });
353
+ var __importStar = exports && exports.__importStar || /* @__PURE__ */ (function() {
354
+ var ownKeys = function(o) {
355
+ ownKeys = Object.getOwnPropertyNames || function(o2) {
356
+ var ar = [];
357
+ for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
358
+ return ar;
359
+ };
360
+ return ownKeys(o);
361
+ };
362
+ return function(mod) {
363
+ if (mod && mod.__esModule) return mod;
364
+ var result = {};
365
+ if (mod != null) {
366
+ for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
367
+ }
368
+ __setModuleDefault(result, mod);
369
+ return result;
370
+ };
371
+ })();
372
+ Object.defineProperty(exports, "__esModule", { value: true });
373
+ exports.TransformersEmbeddingProvider = void 0;
374
+ var base_1 = require_base();
375
+ var pipeline = null;
376
+ var TransformersEmbeddingProvider = class extends base_1.BaseEmbeddingProvider {
377
+ constructor(options = {}) {
378
+ super(options);
379
+ this.name = "transformers-minilm";
380
+ this.dimensions = 384;
381
+ this.maxTokens = 256;
382
+ this.extractor = null;
383
+ this.modelId = options.modelId || "Xenova/all-MiniLM-L6-v2";
384
+ }
385
+ async initialize() {
386
+ if (this._ready)
387
+ return;
388
+ try {
389
+ if (typeof window !== "undefined") {
390
+ const transformers = await Promise.resolve().then(() => __importStar(__require("@huggingface/transformers")));
391
+ pipeline = transformers.pipeline;
392
+ } else {
393
+ const transformers = __require("@huggingface/transformers");
394
+ pipeline = transformers.pipeline;
395
+ }
396
+ this.extractor = await pipeline("feature-extraction", this.modelId);
397
+ this._ready = true;
398
+ } catch (error) {
399
+ console.warn("Transformers.js not available, falling back to mock provider");
400
+ throw error;
401
+ }
402
+ }
403
+ async embedInternal(text) {
404
+ if (!this._ready || !this.extractor) {
405
+ throw new Error("Provider not initialized. Call initialize() first.");
406
+ }
407
+ const truncated = this.truncateText(text);
408
+ const output = await this.extractor(truncated, {
409
+ pooling: "mean",
410
+ normalize: true
411
+ });
412
+ const values = new Float32Array(output.data);
413
+ return {
414
+ values,
415
+ dimensions: this.dimensions,
416
+ normalized: true
417
+ };
418
+ }
419
+ async embedBatchInternal(texts) {
420
+ if (!this._ready || !this.extractor) {
421
+ throw new Error("Provider not initialized. Call initialize() first.");
422
+ }
423
+ const truncated = texts.map((text) => this.truncateText(text));
424
+ const batchSize = 16;
425
+ const results = [];
426
+ for (let i = 0; i < truncated.length; i += batchSize) {
427
+ const batch = truncated.slice(i, i + batchSize);
428
+ const outputs = await this.extractor(batch, {
429
+ pooling: "mean",
430
+ normalize: true
431
+ });
432
+ for (let j = 0; j < outputs.length; j++) {
433
+ const values = new Float32Array(outputs[j].data);
434
+ results.push({
435
+ values,
436
+ dimensions: this.dimensions,
437
+ normalized: true
438
+ });
439
+ }
440
+ }
441
+ return results;
442
+ }
443
+ /**
444
+ * Truncate text to fit within token limit
445
+ */
446
+ truncateText(text) {
447
+ const maxChars = this.maxTokens * 4;
448
+ if (text.length <= maxChars)
449
+ return text;
450
+ return text.substring(0, maxChars - 3) + "...";
451
+ }
452
+ dispose() {
453
+ super.dispose();
454
+ this.extractor = null;
455
+ }
456
+ };
457
+ exports.TransformersEmbeddingProvider = TransformersEmbeddingProvider;
458
+ }
459
+ });
460
+
461
+ // ../../node_modules/@terminals-tech/embeddings/dist/search.js
462
+ var require_search = __commonJS({
463
+ "../../node_modules/@terminals-tech/embeddings/dist/search.js"(exports) {
464
+ "use strict";
465
+ Object.defineProperty(exports, "__esModule", { value: true });
466
+ exports.SemanticSearch = void 0;
467
+ var SemanticSearch = class {
468
+ constructor(provider) {
469
+ this.provider = provider;
470
+ this.embeddings = /* @__PURE__ */ new Map();
471
+ this.texts = [];
472
+ this.metadata = /* @__PURE__ */ new Map();
473
+ }
474
+ /**
475
+ * Add documents to the search index
476
+ */
477
+ async addDocuments(documents) {
478
+ const texts = documents.map((d) => d.text);
479
+ const embeddings = await this.provider.embedBatch(texts);
480
+ for (let i = 0; i < documents.length; i++) {
481
+ const { text, metadata } = documents[i];
482
+ this.texts.push(text);
483
+ this.embeddings.set(text, embeddings[i]);
484
+ if (metadata) {
485
+ this.metadata.set(text, metadata);
486
+ }
487
+ }
488
+ }
489
+ /**
490
+ * Search for similar documents
491
+ */
492
+ async search(query, options = {}) {
493
+ const { topK = 10, threshold = 0 } = options;
494
+ const queryEmbedding = await this.provider.embed(query);
495
+ const results = [];
496
+ for (const text of this.texts) {
497
+ const embedding = this.embeddings.get(text);
498
+ const score = this.provider.similarity(queryEmbedding, embedding);
499
+ if (score >= threshold) {
500
+ results.push({
501
+ text,
502
+ score,
503
+ embedding,
504
+ metadata: this.metadata.get(text)
505
+ });
506
+ }
507
+ }
508
+ results.sort((a, b) => b.score - a.score);
509
+ return results.slice(0, topK);
510
+ }
511
+ /**
512
+ * Find clusters in the documents
513
+ */
514
+ async findClusters(options = {}) {
515
+ const { minClusterSize = 2, similarityThreshold = 0.7 } = options;
516
+ const clusters = [];
517
+ const assigned = /* @__PURE__ */ new Set();
518
+ for (const text of this.texts) {
519
+ if (assigned.has(text))
520
+ continue;
521
+ const cluster = /* @__PURE__ */ new Set([text]);
522
+ const embedding = this.embeddings.get(text);
523
+ for (const other of this.texts) {
524
+ if (other === text || assigned.has(other))
525
+ continue;
526
+ const otherEmbedding = this.embeddings.get(other);
527
+ const similarity = this.provider.similarity(embedding, otherEmbedding);
528
+ if (similarity >= similarityThreshold) {
529
+ cluster.add(other);
530
+ assigned.add(other);
531
+ }
532
+ }
533
+ if (cluster.size >= minClusterSize) {
534
+ clusters.push(cluster);
535
+ assigned.add(text);
536
+ }
537
+ }
538
+ return clusters.map((cluster) => ({
539
+ members: Array.from(cluster),
540
+ centroid: Array.from(cluster)[0]
541
+ // Simple: use first member as centroid
542
+ }));
543
+ }
544
+ /**
545
+ * Clear the search index
546
+ */
547
+ clear() {
548
+ this.embeddings.clear();
549
+ this.texts = [];
550
+ this.metadata.clear();
551
+ }
552
+ /**
553
+ * Get index statistics
554
+ */
555
+ stats() {
556
+ const documentCount = this.texts.length;
557
+ const dimensions = this.provider.dimensions;
558
+ const memoryUsage = documentCount * dimensions * 4;
559
+ return {
560
+ documentCount,
561
+ dimensions,
562
+ memoryUsage
563
+ };
564
+ }
565
+ };
566
+ exports.SemanticSearch = SemanticSearch;
567
+ }
568
+ });
569
+
570
+ // ../../node_modules/@terminals-tech/embeddings/dist/index.js
571
+ var require_dist = __commonJS({
572
+ "../../node_modules/@terminals-tech/embeddings/dist/index.js"(exports) {
573
+ var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
574
+ if (k2 === void 0) k2 = k;
575
+ var desc = Object.getOwnPropertyDescriptor(m, k);
576
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
577
+ desc = { enumerable: true, get: function() {
578
+ return m[k];
579
+ } };
580
+ }
581
+ Object.defineProperty(o, k2, desc);
582
+ }) : (function(o, m, k, k2) {
583
+ if (k2 === void 0) k2 = k;
584
+ o[k2] = m[k];
585
+ }));
586
+ var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
587
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
588
+ }) : function(o, v) {
589
+ o["default"] = v;
590
+ });
591
+ var __exportStar = exports && exports.__exportStar || function(m, exports2) {
592
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
593
+ };
594
+ var __importStar = exports && exports.__importStar || /* @__PURE__ */ (function() {
595
+ var ownKeys = function(o) {
596
+ ownKeys = Object.getOwnPropertyNames || function(o2) {
597
+ var ar = [];
598
+ for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
599
+ return ar;
600
+ };
601
+ return ownKeys(o);
602
+ };
603
+ return function(mod) {
604
+ if (mod && mod.__esModule) return mod;
605
+ var result = {};
606
+ if (mod != null) {
607
+ for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
608
+ }
609
+ __setModuleDefault(result, mod);
610
+ return result;
611
+ };
612
+ })();
613
+ Object.defineProperty(exports, "__esModule", { value: true });
614
+ exports.VERSION = exports.EmbeddingProviderFactory = exports.SemanticSearch = exports.TransformersEmbeddingProvider = exports.MockEmbeddingProvider = exports.BaseEmbeddingProvider = exports.EmbeddingCache = void 0;
615
+ exports.enhanceGraphWithSemantics = enhanceGraphWithSemantics;
616
+ __exportStar(require_types(), exports);
617
+ var cache_1 = require_cache();
618
+ Object.defineProperty(exports, "EmbeddingCache", { enumerable: true, get: function() {
619
+ return cache_1.EmbeddingCache;
620
+ } });
621
+ var base_1 = require_base();
622
+ Object.defineProperty(exports, "BaseEmbeddingProvider", { enumerable: true, get: function() {
623
+ return base_1.BaseEmbeddingProvider;
624
+ } });
625
+ var mock_1 = require_mock();
626
+ Object.defineProperty(exports, "MockEmbeddingProvider", { enumerable: true, get: function() {
627
+ return mock_1.MockEmbeddingProvider;
628
+ } });
629
+ var transformers_1 = require_transformers();
630
+ Object.defineProperty(exports, "TransformersEmbeddingProvider", { enumerable: true, get: function() {
631
+ return transformers_1.TransformersEmbeddingProvider;
632
+ } });
633
+ var search_1 = require_search();
634
+ Object.defineProperty(exports, "SemanticSearch", { enumerable: true, get: function() {
635
+ return search_1.SemanticSearch;
636
+ } });
637
+ var EmbeddingProviderFactory = class {
638
+ /**
639
+ * Create the best available provider
640
+ */
641
+ static async createBest(options = {}) {
642
+ const { preferredProvider = "transformers" } = options;
643
+ if (preferredProvider === "transformers") {
644
+ try {
645
+ const { TransformersEmbeddingProvider } = await Promise.resolve().then(() => __importStar(require_transformers()));
646
+ const provider2 = new TransformersEmbeddingProvider(options);
647
+ await provider2.initialize();
648
+ return provider2;
649
+ } catch (error) {
650
+ console.warn("Transformers.js not available, falling back to mock provider");
651
+ }
652
+ }
653
+ const { MockEmbeddingProvider } = await Promise.resolve().then(() => __importStar(require_mock()));
654
+ const provider = new MockEmbeddingProvider(options);
655
+ await provider.initialize();
656
+ return provider;
657
+ }
658
+ /**
659
+ * Create a specific provider
660
+ */
661
+ static async create(type, options = {}) {
662
+ switch (type) {
663
+ case "transformers": {
664
+ const { TransformersEmbeddingProvider } = await Promise.resolve().then(() => __importStar(require_transformers()));
665
+ const provider = new TransformersEmbeddingProvider(options);
666
+ await provider.initialize();
667
+ return provider;
668
+ }
669
+ case "mock": {
670
+ const { MockEmbeddingProvider } = await Promise.resolve().then(() => __importStar(require_mock()));
671
+ const provider = new MockEmbeddingProvider(options);
672
+ await provider.initialize();
673
+ return provider;
674
+ }
675
+ default:
676
+ throw new Error(`Unknown provider type: ${type}`);
677
+ }
678
+ }
679
+ };
680
+ exports.EmbeddingProviderFactory = EmbeddingProviderFactory;
681
+ async function enhanceGraphWithSemantics(graph, provider) {
682
+ const embeddingProvider = provider || await EmbeddingProviderFactory.createBest();
683
+ graph.extractSemanticRelations = async function(text) {
684
+ const sentences = text.split(/[.!?]+/).filter((s) => s.trim());
685
+ const embeddings = await embeddingProvider.embedBatch(sentences);
686
+ const relations = [];
687
+ const patterns = {
688
+ causal: await embeddingProvider.embed("X causes Y"),
689
+ temporal: await embeddingProvider.embed("X happens before Y"),
690
+ dependency: await embeddingProvider.embed("X depends on Y")
691
+ };
692
+ for (let i = 0; i < sentences.length - 1; i++) {
693
+ for (let j = i + 1; j < sentences.length; j++) {
694
+ const similarity = embeddingProvider.similarity(embeddings[i], embeddings[j]);
695
+ for (const [type, pattern] of Object.entries(patterns)) {
696
+ const patternSimilarity = embeddingProvider.similarity(embeddings[i], pattern);
697
+ if (patternSimilarity > 0.7) {
698
+ relations.push({
699
+ type,
700
+ from: sentences[i],
701
+ to: sentences[j],
702
+ weight: similarity,
703
+ semantic: true
704
+ });
705
+ }
706
+ }
707
+ }
708
+ }
709
+ return relations;
710
+ };
711
+ graph.findSemanticClusters = async function(events) {
712
+ const { SemanticSearch } = await Promise.resolve().then(() => __importStar(require_search()));
713
+ const search = new SemanticSearch(embeddingProvider);
714
+ await search.addDocuments(events.map((e) => ({
715
+ text: e.description || e.type || "",
716
+ metadata: { id: e.id, type: e.type }
717
+ })));
718
+ return search.findClusters({
719
+ minClusterSize: 3,
720
+ similarityThreshold: 0.8
721
+ });
722
+ };
723
+ }
724
+ exports.VERSION = "0.1.0";
725
+ }
726
+ });
727
+ export default require_dist();