@retrivora-ai/rag-engine 2.4.2 → 2.4.5

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 (140) hide show
  1. package/dist/{BatchProcessor-zbQMaZHm.d.mts → BatchProcessor-Csy_K1qQ.d.mts} +2 -0
  2. package/dist/{BatchProcessor-D42E706a.d.ts → BatchProcessor-Dg18zZGk.d.ts} +2 -0
  3. package/dist/handlers/index.js +31 -5
  4. package/dist/handlers/index.mjs +31 -5
  5. package/dist/index.d.mts +3 -3
  6. package/dist/index.d.ts +3 -3
  7. package/dist/index.js +41 -21
  8. package/dist/index.min.css +2 -0
  9. package/dist/index.mjs +41 -21
  10. package/dist/server.d.mts +2 -2
  11. package/dist/server.d.ts +2 -2
  12. package/dist/server.js +32 -5
  13. package/dist/server.mjs +32 -5
  14. package/package.json +5 -4
  15. package/src/LicensedRetrivora.ts +0 -278
  16. package/src/app/api/chat/route.ts +0 -4
  17. package/src/app/api/health/route.ts +0 -5
  18. package/src/app/api/ingest/route.ts +0 -27
  19. package/src/app/api/suggestions/route.ts +0 -5
  20. package/src/app/api/upload/route.ts +0 -5
  21. package/src/app/constants.tsx +0 -270
  22. package/src/app/favicon.ico +0 -0
  23. package/src/app/globals.css +0 -449
  24. package/src/app/layout.tsx +0 -22
  25. package/src/app/page.tsx +0 -64
  26. package/src/app/types.ts +0 -30
  27. package/src/browser.tsx +0 -139
  28. package/src/components/ChatWidget.tsx +0 -393
  29. package/src/components/ChatWindow.tsx +0 -952
  30. package/src/components/CodeViewer.tsx +0 -56
  31. package/src/components/ConfigProvider.tsx +0 -123
  32. package/src/components/DocumentUpload.tsx +0 -354
  33. package/src/components/DynamicChart.tsx +0 -297
  34. package/src/components/HourglassLoader.tsx +0 -87
  35. package/src/components/MarkdownComponents.tsx +0 -186
  36. package/src/components/MessageBubble.tsx +0 -498
  37. package/src/components/ObservabilityPanel.tsx +0 -374
  38. package/src/components/ProductCard.tsx +0 -107
  39. package/src/components/ProductCarousel.tsx +0 -97
  40. package/src/components/SourceCard.tsx +0 -61
  41. package/src/components/ThemeProvider.tsx +0 -8
  42. package/src/components/ThemeToggle.tsx +0 -29
  43. package/src/components/ThinkingBlock.tsx +0 -75
  44. package/src/components/UIDispatcher.tsx +0 -342
  45. package/src/components/VisualizationRenderer.tsx +0 -621
  46. package/src/components/constants.tsx +0 -503
  47. package/src/config/ConfigBuilder.ts +0 -285
  48. package/src/config/EmbeddingStrategy.ts +0 -148
  49. package/src/config/LicenseConfigResolver.ts +0 -298
  50. package/src/config/RagConfig.ts +0 -328
  51. package/src/config/UniversalProfiles.ts +0 -82
  52. package/src/config/constants.ts +0 -64
  53. package/src/config/serverConfig.ts +0 -378
  54. package/src/config/uiConstants.ts +0 -47
  55. package/src/core/BatchProcessor.ts +0 -385
  56. package/src/core/CircuitBreaker.ts +0 -118
  57. package/src/core/ConfigFetcher.ts +0 -220
  58. package/src/core/ConfigResolver.ts +0 -165
  59. package/src/core/ConfigValidator.ts +0 -197
  60. package/src/core/DatabaseStorage.ts +0 -526
  61. package/src/core/FreeTierLimitsGuard.ts +0 -281
  62. package/src/core/LLMRouter.ts +0 -79
  63. package/src/core/LangChainAgent.ts +0 -132
  64. package/src/core/LicenseValidator.ts +0 -284
  65. package/src/core/LicenseVerifier.ts +0 -261
  66. package/src/core/MultiAgentCoordinator.ts +0 -239
  67. package/src/core/Pipeline.ts +0 -1279
  68. package/src/core/PluginManager.ts +0 -277
  69. package/src/core/ProjectSettings.ts +0 -247
  70. package/src/core/ProviderHealthCheck.ts +0 -133
  71. package/src/core/ProviderInterfaces.ts +0 -37
  72. package/src/core/ProviderRegistry.ts +0 -156
  73. package/src/core/QueryProcessor.ts +0 -399
  74. package/src/core/Retrivora.ts +0 -98
  75. package/src/core/VectorPlugin.ts +0 -193
  76. package/src/core/mcp.ts +0 -261
  77. package/src/exceptions/index.ts +0 -131
  78. package/src/handlers/index.ts +0 -1625
  79. package/src/hooks/useHydrated.ts +0 -13
  80. package/src/hooks/useProjectSettings.ts +0 -105
  81. package/src/hooks/useRagChat.ts +0 -436
  82. package/src/hooks/useStoredMessages.ts +0 -64
  83. package/src/index.css +0 -4269
  84. package/src/index.ts +0 -137
  85. package/src/lib/plugin.ts +0 -24
  86. package/src/llm/ILLMProvider.ts +0 -60
  87. package/src/llm/LLMFactory.ts +0 -141
  88. package/src/llm/providers/AnthropicProvider.ts +0 -215
  89. package/src/llm/providers/GeminiProvider.ts +0 -311
  90. package/src/llm/providers/GroqProvider.ts +0 -184
  91. package/src/llm/providers/OllamaProvider.ts +0 -232
  92. package/src/llm/providers/OpenAIProvider.ts +0 -188
  93. package/src/llm/providers/QwenProvider.ts +0 -199
  94. package/src/llm/providers/UniversalLLMAdapter.ts +0 -422
  95. package/src/llm/utils.ts +0 -46
  96. package/src/providers/graphdb/BaseGraphProvider.ts +0 -43
  97. package/src/providers/graphdb/SimpleGraphProvider.ts +0 -66
  98. package/src/providers/vectordb/BaseVectorProvider.ts +0 -98
  99. package/src/providers/vectordb/ChromaDBProvider.ts +0 -130
  100. package/src/providers/vectordb/MilvusProvider.ts +0 -134
  101. package/src/providers/vectordb/MongoDBProvider.ts +0 -250
  102. package/src/providers/vectordb/MultiTablePostgresProvider.ts +0 -461
  103. package/src/providers/vectordb/PineconeProvider.ts +0 -295
  104. package/src/providers/vectordb/PostgreSQLProvider.ts +0 -227
  105. package/src/providers/vectordb/QdrantProvider.ts +0 -294
  106. package/src/providers/vectordb/RedisProvider.ts +0 -105
  107. package/src/providers/vectordb/UniversalVectorProvider.ts +0 -221
  108. package/src/providers/vectordb/WeaviateProvider.ts +0 -172
  109. package/src/rag/DocumentChunker.ts +0 -144
  110. package/src/rag/EntityExtractor.ts +0 -90
  111. package/src/rag/LlamaIndexIngestor.ts +0 -60
  112. package/src/rag/Reranker.ts +0 -106
  113. package/src/rendering/IntentClassifier.ts +0 -167
  114. package/src/rendering/RendererRegistry.ts +0 -164
  115. package/src/rendering/RuleEngine.ts +0 -67
  116. package/src/rendering/VisualizationDecisionEngine.ts +0 -164
  117. package/src/rendering/__tests__/VisualizationDecisionEngine.test.ts +0 -237
  118. package/src/rendering/index.ts +0 -12
  119. package/src/rendering/rules/Rule1SpecificInfoRule.ts +0 -28
  120. package/src/rendering/rules/Rule2ComparisonRule.ts +0 -24
  121. package/src/rendering/rules/Rule3ProductDiscoveryRule.ts +0 -28
  122. package/src/rendering/rules/Rule4AnalyticalRule.ts +0 -38
  123. package/src/rendering/rules/Rule5MixedResponseRule.ts +0 -29
  124. package/src/rendering/rules/Rule6SmallResultSetRule.ts +0 -24
  125. package/src/rendering/rules/Rule7LargeTableRule.ts +0 -35
  126. package/src/rendering/types.ts +0 -96
  127. package/src/server.ts +0 -156
  128. package/src/tailwind.css +0 -194
  129. package/src/telemetry/TelemetryService.ts +0 -330
  130. package/src/types/chat.ts +0 -89
  131. package/src/types/index.ts +0 -278
  132. package/src/types/pdf-parse.d.ts +0 -13
  133. package/src/types/props.ts +0 -169
  134. package/src/utils/DocumentParser.ts +0 -111
  135. package/src/utils/ProductExtractor.ts +0 -350
  136. package/src/utils/SchemaMapper.ts +0 -176
  137. package/src/utils/UITransformer.ts +0 -1812
  138. package/src/utils/synonyms.ts +0 -80
  139. package/src/utils/templateUtils.ts +0 -78
  140. package/src/version.ts +0 -6
package/src/server.ts DELETED
@@ -1,156 +0,0 @@
1
- /**
2
- * Server-only entry point for @retrivora-ai/rag-engine.
3
- *
4
- * Import this in Next.js API routes, Server Components, or any Node.js server.
5
- * Do NOT import this in client-side code — use the default export ('@retrivora-ai/rag-engine') instead.
6
- */
7
-
8
- // ── Shared Types ──────────────────────────────────────────────
9
- export type {
10
- RagConfig,
11
- UniversalRagConfig,
12
- RetrievalConfig,
13
- WorkflowConfig,
14
- VectorDBConfig,
15
- LLMConfig,
16
- EmbeddingConfig,
17
- UIConfig,
18
- RAGConfig,
19
- VectorDBProvider,
20
- LLMProvider,
21
- EmbeddingProvider,
22
- } from './config/RagConfig';
23
- export type * from './types';
24
- export type { ILLMProvider, EmbedOptions } from './llm/ILLMProvider';
25
- export type { Chunk, ChunkOptions } from './rag/DocumentChunker';
26
- export type { HealthCheckResult, IProviderValidator, IProviderHealthChecker } from './core/ProviderInterfaces';
27
- export type { ValidationError } from './core/ConfigValidator';
28
- export type { LicensePayload } from './core/LicenseVerifier';
29
- export type { BatchOptions, BatchResult } from './core/BatchProcessor';
30
- export type { HandlerOptions } from './handlers';
31
-
32
- // ── Core Orchestration ─────────────────────────────────────────
33
- export { Retrivora } from './core/Retrivora';
34
- export { VectorPlugin } from './core/VectorPlugin';
35
- export { Pipeline } from './core/Pipeline';
36
- export { ConfigResolver } from './core/ConfigResolver';
37
- export { ProviderRegistry } from './core/ProviderRegistry';
38
- export { ConfigValidator } from './core/ConfigValidator';
39
- export { LicenseVerifier } from './core/LicenseVerifier';
40
- export { SDK_VERSION } from './version';
41
- export { ProviderHealthCheck } from './core/ProviderHealthCheck';
42
- export { BatchProcessor } from './core/BatchProcessor';
43
- export { ConfigFetcher } from './core/ConfigFetcher';
44
- export {
45
- createDefaultProjectSettings,
46
- normalizeProjectSettings,
47
- projectSettingsToUiConfig,
48
- } from './core/ProjectSettings';
49
- export type {
50
- RemoteConfig,
51
- RemoteVectorConfig,
52
- RemoteEmbeddingConfig,
53
- RemoteLLMConfig,
54
- } from './core/ConfigFetcher';
55
- export type {
56
- AuthMode,
57
- ProjectAiSettings,
58
- ProjectAuthSettings,
59
- ProjectBrandingSettings,
60
- ProjectChatSettings,
61
- ProjectTelemetrySettings,
62
- ProjectWidgetSettings,
63
- ThemeMode,
64
- WidgetPosition,
65
- } from './core/ProjectSettings';
66
-
67
- // ── Configuration Helpers ──────────────────────────────────────
68
- export { getRagConfig, injectRuntimeConfig, getRuntimeConfig } from './config/serverConfig';
69
- export type { RuntimeTierConfig } from './config/serverConfig';
70
- export { ConfigBuilder, PRESETS, createFromPreset } from './config/ConfigBuilder';
71
- export { EmbeddingStrategyResolver, EmbeddingStrategy } from './config/EmbeddingStrategy';
72
- export { LLM_PROFILES, VECTOR_PROFILES } from './config/UniversalProfiles';
73
-
74
- // ── RAG Utilities & Visualization ──────────────────────────────────────────────
75
- export { DocumentChunker } from './rag/DocumentChunker';
76
- export { DocumentParser } from './utils/DocumentParser';
77
- export * from './rendering';
78
-
79
- // ── Vector DB Providers ────────────────────────────────────────
80
- export { BaseVectorProvider } from './providers/vectordb/BaseVectorProvider';
81
- export { PineconeProvider } from './providers/vectordb/PineconeProvider';
82
- export { PostgreSQLProvider } from './providers/vectordb/PostgreSQLProvider';
83
- export { MultiTablePostgresProvider } from './providers/vectordb/MultiTablePostgresProvider';
84
- export { MongoDBProvider } from './providers/vectordb/MongoDBProvider';
85
- export { MilvusProvider } from './providers/vectordb/MilvusProvider';
86
- export { QdrantProvider } from './providers/vectordb/QdrantProvider';
87
- export { ChromaDBProvider } from './providers/vectordb/ChromaDBProvider';
88
- export { RedisProvider } from './providers/vectordb/RedisProvider';
89
- export { WeaviateProvider } from './providers/vectordb/WeaviateProvider';
90
- export { UniversalVectorProvider } from './providers/vectordb/UniversalVectorProvider';
91
-
92
- // ── LLM Providers ─────────────────────────────────────────────
93
- export { LLMFactory } from './llm/LLMFactory';
94
- export { OpenAIProvider } from './llm/providers/OpenAIProvider';
95
- export { AnthropicProvider } from './llm/providers/AnthropicProvider';
96
- export { OllamaProvider } from './llm/providers/OllamaProvider';
97
- export { GroqProvider } from './llm/providers/GroqProvider';
98
- export { QwenProvider } from './llm/providers/QwenProvider';
99
- export { UniversalLLMAdapter } from './llm/providers/UniversalLLMAdapter';
100
-
101
- // ── Next.js Route Handler Factories ───────────────────────────
102
- export {
103
- createChatHandler,
104
- createStreamHandler,
105
- createIngestHandler,
106
- createHealthHandler,
107
- createUploadHandler,
108
- createHistoryHandler,
109
- createFeedbackHandler,
110
- createSessionsHandler,
111
- createRagHandler,
112
- sseFrame,
113
- sseTextFrame,
114
- sseMetaFrame,
115
- sseErrorFrame,
116
- } from './handlers';
117
-
118
- // ── License Validator ─────────────────────────────────────────
119
- export { LicenseValidator } from './core/LicenseValidator';
120
- export type { LicenseValidationRequest, LicenseValidationResponse } from './core/LicenseValidator';
121
-
122
- // ── Licensed Retrivora SDK (Server-only) ──────────────────────
123
- // End-user SDK that only requires license key + project ID
124
- // Only available via server.ts import, not from main index.ts
125
- export { LicensedRetrivora, createRetrivora } from './LicensedRetrivora';
126
- export type { LicensedRetrivoraOptions } from './LicensedRetrivora';
127
-
128
- // ── License Config Resolver (Server-only) ──────────────────────
129
- export { LicenseConfigResolver } from './config/LicenseConfigResolver';
130
- export type { LicenseTierConfig, ProviderCredentials } from './config/LicenseConfigResolver';
131
-
132
- // ── Telemetry Service (Server-only) ─────────────────────────────
133
- // Tracks usage, billing, and analytics
134
- export {
135
- TelemetryService,
136
- EventType,
137
- getTelemetryService,
138
- initializeTelemetryService,
139
- shutdownTelemetryService,
140
- } from './telemetry/TelemetryService';
141
- export type { TelemetryEvent } from './telemetry/TelemetryService';
142
-
143
- // ── Exceptions ────────────────────────────────────────────────
144
- export type { RetrivoraErrorCode } from './exceptions';
145
- export {
146
- RetrivoraError,
147
- ProviderNotFoundException,
148
- EmbeddingFailedException,
149
- RetrievalException,
150
- RateLimitException,
151
- ConfigurationException,
152
- AuthenticationException,
153
- SDKVersionUnsupportedError,
154
- LicenseValidationError,
155
- wrapError,
156
- } from './exceptions';
package/src/tailwind.css DELETED
@@ -1,194 +0,0 @@
1
- @import "tailwindcss";
2
- @source "./**/*.{ts,tsx,js,jsx}";
3
-
4
- @theme {
5
- --animate-shapeshift: shapeshift 5s ease-in-out infinite forwards;
6
- --animate-gradientMove: gradientMove 3.5s ease-in-out infinite alternate;
7
-
8
- @keyframes shapeshift {
9
- 0% {
10
- clip-path: var(--circle);
11
- rotate: 0turn;
12
- }
13
-
14
- 25% {
15
- clip-path: var(--flower);
16
- }
17
-
18
- 50% {
19
- clip-path: var(--cylinder);
20
- }
21
-
22
- 75% {
23
- clip-path: var(--hexagon);
24
- }
25
-
26
- 100% {
27
- clip-path: var(--circle);
28
- rotate: 1turn;
29
- }
30
-
31
- 120% {
32
- clip-path: var(--flower);
33
- }
34
-
35
- 140% {
36
- clip-path: var(--cylinder);
37
- }
38
-
39
- 160% {
40
- clip-path: var(--hexagon);
41
- }
42
-
43
- 180% {
44
- clip-path: var(--circle);
45
- rotate: 1turn;
46
- }
47
- }
48
-
49
- @keyframes gradientMove {
50
- 0% {
51
- translate: 0 0;
52
- }
53
-
54
- 100% {
55
- translate: -75% -75%;
56
- }
57
- }
58
- }
59
-
60
- @layer base {
61
- :root {
62
- --star: shape(evenodd from 50% 24.787%,
63
- curve by 7.143% 18.016% with 0% 0% / 2.9725% 13.814%,
64
- curve by 17.882% 7.197% with 4.171% 4.2025% / 17.882% 7.197%,
65
- curve by -17.882% 8.6765% with 0% 0% / -13.711% 4.474%,
66
- curve by -7.143% 16.5365% with -4.1705% 4.202% / -7.143% 16.5365%,
67
- curve by -8.6115% -16.5365% with 0% 0% / -4.441% -12.3345%,
68
- curve by -16.4135% -8.6765% with -4.171% -4.2025% / -16.4135% -8.6765%,
69
- curve by 16.4135% -7.197% with 0% 0% / 12.2425% -2.9945%,
70
- curve by 8.6115% -18.016% with 4.1705% -4.202% / 8.6115% -18.016%,
71
- close);
72
- --flower: shape(evenodd from 17.9665% 82.0335%,
73
- curve by -12.349% -32.0335% with -13.239% -5.129% / -18.021% -15.402%,
74
- curve by -0.0275% -22.203% with -3.1825% -9.331% / -3.074% -16.6605%,
75
- curve by 12.3765% -9.8305% with 2.3835% -4.3365% / 6.565% -7.579%,
76
- curve by 32.0335% -12.349% with 5.129% -13.239% / 15.402% -18.021%,
77
- curve by 20.4535% -0.8665% with 8.3805% -2.858% / 15.1465% -3.062%,
78
- curve by 11.58% 13.2155% with 5.225% 2.161% / 9.0355% 6.6475%,
79
- curve by 12.349% 32.0335% with 13.239% 5.129% / 18.021% 15.402%,
80
- curve by 0.5715% 21.1275% with 2.9805% 8.7395% / 3.0745% 15.723%,
81
- curve by -12.9205% 10.906% with -2.26% 4.88% / -6.638% 8.472%,
82
- curve by -32.0335% 12.349% with -5.129% 13.239% / -15.402% 18.021%,
83
- curve by -21.1215% 0.5745% with -8.736% 2.9795% / -15.718% 3.0745%,
84
- curve by -10.912% -12.9235% with -4.883% -2.2595% / -8.477% -6.6385%,
85
- close);
86
- --hexagon: shape(evenodd from 6.47% 67.001%,
87
- curve by 0% -34.002% with -1.1735% -7.7% / -1.1735% -26.302%,
88
- curve by 7.0415% -12.1965% with 0.7075% -4.641% / 3.3765% -9.2635%,
89
- curve by 29.447% -17.001% with 6.0815% -4.8665% / 22.192% -14.1675%,
90
- curve by 14.083% 0% with 4.3725% -1.708% / 9.7105% -1.708%,
91
- curve by 29.447% 17.001% with 7.255% 2.8335% / 23.3655% 12.1345%,
92
- curve by 7.0415% 12.1965% with 3.665% 2.933% / 6.334% 7.5555%,
93
- curve by 0% 34.002% with 1.1735% 7.7% / 1.1735% 26.302%,
94
- curve by -7.0415% 12.1965% with -0.7075% 4.641% / -3.3765% 9.2635%,
95
- curve by -29.447% 17.001% with -6.0815% 4.8665% / -22.192% 14.1675%,
96
- curve by -14.083% 0% with -4.3725% 1.708% / -9.7105% 1.708%,
97
- curve by -29.447% -17.001% with -7.255% -2.8335% / -23.3655% -12.1345%,
98
- curve by -7.0415% -12.1965% with -3.665% -2.933% / -6.334% -7.5555%,
99
- close);
100
- --cylinder: shape(evenodd from 10.5845% 59.7305%,
101
- curve by 0% -19.461% with -0.113% -1.7525% / -0.11% -18.14%,
102
- curve by 10.098% -26.213% with 0.837% -10.0375% / 3.821% -19.2625%,
103
- curve by 29.3175% -13.0215% with 7.2175% -7.992% / 17.682% -13.0215%,
104
- curve by 19.5845% 5.185% with 7.1265% 0% / 13.8135% 1.887%,
105
- curve by 9.8595% 7.9775% with 3.7065% 2.1185% / 7.035% 4.8195%,
106
- curve by 9.9715% 26.072% with 6.2015% 6.933% / 9.4345% 16.082%,
107
- curve by 0% 19.461% with 0.074% 1.384% / 0.0745% 17.7715%,
108
- curve by -13.0065% 29.1155% with -0.511% 11.5345% / -5.021% 21.933%,
109
- curve by -26.409% 10.119% with -6.991% 6.288% / -16.254% 10.119%,
110
- curve by -20.945% -5.9995% with -7.6935% 0% / -14.8755% -2.199%,
111
- curve by -8.713% -7.404% with -3.255% -2.0385% / -6.1905% -4.537%,
112
- curve by -9.7575% -25.831% with -6.074% -6.9035% / -9.1205% -15.963%,
113
- close);
114
- --circle: shape(evenodd from 13.482% 79.505%,
115
- curve by -7.1945% -12.47% with -1.4985% -1.8575% / -6.328% -10.225%,
116
- curve by 0.0985% -33.8965% with -4.1645% -10.7945% / -4.1685% -23.0235%,
117
- curve by 6.9955% -12.101% with 1.72% -4.3825% / 4.0845% -8.458%,
118
- curve by 30.125% -17.119% with 7.339% -9.1825% / 18.4775% -15.5135%,
119
- curve by 13.4165% 0.095% with 4.432% -0.6105% / 8.9505% -0.5855%,
120
- curve by 29.364% 16.9% with 11.6215% 1.77% / 22.102% 7.9015%,
121
- curve by 7.176% 12.4145% with 3.002% 3.7195% / 5.453% 7.968%,
122
- curve by -0.0475% 33.8925% with 4.168% 10.756% / 4.2305% 22.942%,
123
- curve by -7.1135% 12.2825% with -1.74% 4.4535% / -4.1455% 8.592%,
124
- curve by -29.404% 16.9075% with -7.202% 8.954% / -18.019% 15.137%,
125
- curve by -14.19% -0.018% with -4.6635% 0.7255% / -9.4575% 0.7205%,
126
- curve by -29.226% -16.8875% with -11.573% -1.8065% / -21.9955% -7.9235%,
127
- close);
128
- --heart: shape(evenodd from 51.311% 83.603%,
129
- curve by -8.333% -20.508% with -14.104% -4.287% / -16.406% -16.185%,
130
- curve by -4.271% -37.41% with -5.419% -9.658% / -6.815% -22.733%,
131
- curve by 13.589% -33.586% with 3.982% -7.448% / 8.411% -15.994%,
132
- curve by 28.187% -21.985% with 4.029% -4.29% / 4.029% -4.29%,
133
- curve by 33.835% 0.721% with 9.618% 4.647% / 22.541% 9.618%,
134
- curve by 37.596% 21.304% with 3.306% 13.266% / 7.589% 24.251%,
135
- curve by 21.985% 43.613% with -4.208% 3.982% / -15.994% 8.411%,
136
- curve by 0.721% 37.596% with -7.448% 4.029% / -15.994% 8.411%,
137
- curve by -16.185% 28.187% with -9.658% 5.419% / -22.733% 6.815%,
138
- curve by -37.41% 4.271% with -4.29% 4.029% / -4.29% 4.029%,
139
- curve by -33.586% -13.589% with -7.448% 3.982% / -15.994% 8.411%,
140
- curve by -28.187% -32.094% with -4.029% 4.029% / -4.029% 4.029%,
141
- close);
142
- --spiral: shape(evenodd from 13.347% 30.885%,
143
- curve by 5.502% 18.447% with 11.052% 5.562% / 19.995% 9.169%,
144
- curve by -20.309% 16.907% with -7.146% -1.332% / -9.016% -2.812%,
145
- curve by -25.848% -13.087% with -7.017% -7.46% / -9.941% -15.041%,
146
- curve by 10.154% -25.731% with 2.473% -6.063% / 7.163% -10.656%,
147
- curve by 31.473% -7.963% with 8.814% 2.403% / 13.84% 8.748%,
148
- curve by 16.526% 20.487% with -4.058% 1.502% / -9.51% 3.304%,
149
- curve by 5.502% 18.447% with 11.052% 5.562% / 19.995% 9.169%,
150
- close);
151
- --star2: shape(open from 28.947% 47.744%,
152
- curve by 24.042% -2.139% with 0% 0% / -24.042% 2.139%,
153
- curve by 4.208% -25.165% with 4.208% -25.165% / 4.208% -25.165%,
154
- curve by 2.341% -18.447% with 0% 0% / 1.888% -1.438%,
155
- curve by 32.355% 1.085% with 0% 0% / 25.984% 1.085%,
156
- curve by -4.655% 25.165% with 0% 0% / -4.655% 25.165%,
157
- curve by -4.208% -25.165% with -4.208% -25.165% / -4.208% -25.165%,
158
- curve by 2.566% -4.208% with 0% 0% / 2.072% -1.639%,
159
- curve by 30.069% 1.085% with 0% 0% / 24.156% 1.085%,
160
- curve by -2.791% 25.165% with 0% 0% / -2.791% 25.165%,
161
- curve by -4.208% -25.165% with -4.208% -25.165% / -4.208% -25.165%,
162
- curve by 2.116% -4.208% with 0% 0% / 1.659% -1.557%,
163
- close);
164
- --sun: shape(evenodd from 12.758% 22.039%,
165
- curve by 2.2585% 27.561% with 4.517% 18.961% / 2.2585% 27.561%,
166
- curve by 3.187% -11.541% with 2.2585% -8.483% / 4.7615% -12.541%,
167
- curve by 31.034% 31.034% with 31.034% 31.034% / 31.034% 31.034%,
168
- curve by 33.825% -14.163% with 8.961% -7.455% / 13.585% -11.059%,
169
- curve by 19.814% -34.731% with 4.7615% -12.541% / 2.2585% -27.561%,
170
- curve by 33.825% -14.163% with 2.2585% -8.483% / 4.517% -18.961%,
171
- curve by 19.814% -34.731% with 0% 0% / -3.187% 11.541%,
172
- curve by 33.825% -14.163% with 8.961% -7.455% / 13.585% -11.059%,
173
- curve by 31.034% 31.034% with 31.034% 31.034% / 31.034% 31.034%,
174
- curve by 19.814% -34.731% with 4.7615% -12.541% / 2.2585% -27.561%,
175
- curve by 33.825% -14.163% with 2.2585% -8.483% / 4.517% -18.961%,
176
- close);
177
- --star2: shape(open from 28.947% 47.744%,
178
- curve by 24.042% -2.139% with 0% 0% / -24.042% 2.139%,
179
- curve by 4.208% -25.165% with 4.208% -25.165% / 4.208% -25.165%,
180
- curve by 2.341% -18.447% with 0% 0% / 1.888% -1.438%,
181
- curve by 32.355% 1.085% with 0% 0% / 25.984% 1.085%,
182
- curve by -4.655% 25.165% with 0% 0% / -4.655% 25.165%,
183
- curve by -4.208% -25.165% with -4.208% -25.165% / -4.208% -25.165%,
184
- curve by 2.566% -4.208% with 0% 0% / 2.072% -1.639%,
185
- curve by 30.069% 1.085% with 0% 0% / 24.156% 1.085%,
186
- curve by -2.791% 25.165% with 0% 0% / -2.791% 25.165%,
187
- curve by -4.208% -25.165% with -4.208% -25.165% / -4.208% -25.165%,
188
- curve by 2.116% -4.208% with 0% 0% / 1.659% -1.557%,
189
- close);
190
- --tri-star: shape(open from 25% 25%,
191
- curve by 25% 25% with 0% 0% / 25% 25%,
192
- close);
193
- }
194
- }
@@ -1,330 +0,0 @@
1
- /**
2
- * TelemetryService — Tracks LLM calls, embedding operations, and user interactions
3
- * for billing, analytics, and usage monitoring.
4
- *
5
- * Sends telemetry to both:
6
- * - Admin dashboard (retrivora.com)
7
- * - User's own dashboard (if configured)
8
- */
9
-
10
- import axios, { AxiosInstance } from 'axios';
11
-
12
- export enum EventType {
13
- EMBEDDING_GENERATED = 'embedding_generated',
14
- LLM_CHAT_COMPLETION = 'llm_chat_completion',
15
- DOCUMENT_INGESTED = 'document_ingested',
16
- QUERY_EXECUTED = 'query_executed',
17
- ERROR_OCCURRED = 'error_occurred',
18
- CONFIGURATION_LOADED = 'configuration_loaded',
19
- }
20
-
21
- export interface TelemetryEvent {
22
- eventType: EventType;
23
- projectId: string;
24
- timestamp: number;
25
-
26
- // Operation details
27
- operationId?: string; // Unique ID for correlating related events
28
- durationMs?: number;
29
-
30
- // LLM-specific
31
- model?: string;
32
- inputTokens?: number;
33
- outputTokens?: number;
34
- totalTokens?: number;
35
-
36
- // Embedding-specific
37
- embeddingModel?: string;
38
- vectorDimensions?: number;
39
- textLength?: number;
40
-
41
- // Document ingestion
42
- documentId?: string;
43
- documentName?: string;
44
- documentSize?: number;
45
- chunksGenerated?: number;
46
-
47
- // Query
48
- queryText?: string;
49
- resultCount?: number;
50
-
51
- // Error tracking
52
- errorCode?: string;
53
- errorMessage?: string;
54
- stackTrace?: string;
55
-
56
- // Custom metadata
57
- metadata?: Record<string, unknown>;
58
- }
59
-
60
- /**
61
- * Telemetry service for tracking usage, billing, and analytics
62
- */
63
- export class TelemetryService {
64
- private static readonly RETRIVORA_TELEMETRY_URL = 'https://www.retrivora.com/api/telemetry';
65
- private static readonly USER_TELEMETRY_URL_ENV_KEY = 'TELEMETRY_URL';
66
-
67
- private http: AxiosInstance;
68
- private projectId: string;
69
- private licenseKey: string;
70
- private userTelemetryUrl?: string;
71
- private batchSize: number = 10;
72
- private flushIntervalMs: number = 30000; // 30 seconds
73
- private eventQueue: TelemetryEvent[] = [];
74
- private flushTimer?: NodeJS.Timeout;
75
- private enabled: boolean = true;
76
-
77
- constructor(projectId: string, licenseKey: string, userTelemetryUrl?: string) {
78
- this.projectId = projectId;
79
- this.licenseKey = licenseKey;
80
- this.userTelemetryUrl = userTelemetryUrl || process.env[TelemetryService.USER_TELEMETRY_URL_ENV_KEY];
81
-
82
- this.http = axios.create({
83
- timeout: 5000,
84
- headers: {
85
- 'Content-Type': 'application/json',
86
- 'X-License-Key': licenseKey,
87
- 'X-Project-ID': projectId,
88
- },
89
- });
90
-
91
- // Start automatic flush interval
92
- this.startAutoFlush();
93
- }
94
-
95
- /**
96
- * Record a telemetry event
97
- */
98
- recordEvent(event: Partial<TelemetryEvent>): void {
99
- if (!this.enabled) return;
100
-
101
- // Exclude licenseKey from event payload (privacy/security)
102
- const { licenseKey, ...safeEvent } = event as any;
103
-
104
- const completeEvent: TelemetryEvent = {
105
- eventType: event.eventType || EventType.ERROR_OCCURRED,
106
- projectId: this.projectId,
107
- timestamp: event.timestamp || Date.now(),
108
- ...safeEvent,
109
- };
110
-
111
- this.eventQueue.push(completeEvent);
112
-
113
- // Flush if batch size reached
114
- if (this.eventQueue.length >= this.batchSize) {
115
- this.flush().catch(err => {
116
- console.warn('[TelemetryService] Flush error:', err.message);
117
- });
118
- }
119
- }
120
-
121
- /**
122
- * Record LLM completion event
123
- */
124
- recordLLMCompletion(data: {
125
- model: string;
126
- inputTokens: number;
127
- outputTokens: number;
128
- durationMs: number;
129
- operationId?: string;
130
- metadata?: Record<string, unknown>;
131
- }): void {
132
- this.recordEvent({
133
- eventType: EventType.LLM_CHAT_COMPLETION,
134
- model: data.model,
135
- inputTokens: data.inputTokens,
136
- outputTokens: data.outputTokens,
137
- totalTokens: data.inputTokens + data.outputTokens,
138
- durationMs: data.durationMs,
139
- operationId: data.operationId,
140
- metadata: data.metadata,
141
- });
142
- }
143
-
144
- /**
145
- * Record embedding generation event
146
- */
147
- recordEmbeddingGenerated(data: {
148
- embeddingModel: string;
149
- vectorDimensions: number;
150
- textLength: number;
151
- durationMs: number;
152
- operationId?: string;
153
- }): void {
154
- this.recordEvent({
155
- eventType: EventType.EMBEDDING_GENERATED,
156
- embeddingModel: data.embeddingModel,
157
- vectorDimensions: data.vectorDimensions,
158
- textLength: data.textLength,
159
- durationMs: data.durationMs,
160
- operationId: data.operationId,
161
- });
162
- }
163
-
164
- /**
165
- * Record document ingestion event
166
- */
167
- recordDocumentIngested(data: {
168
- documentId: string;
169
- documentName: string;
170
- documentSize: number;
171
- chunksGenerated: number;
172
- durationMs: number;
173
- }): void {
174
- this.recordEvent({
175
- eventType: EventType.DOCUMENT_INGESTED,
176
- documentId: data.documentId,
177
- documentName: data.documentName,
178
- documentSize: data.documentSize,
179
- chunksGenerated: data.chunksGenerated,
180
- durationMs: data.durationMs,
181
- });
182
- }
183
-
184
- /**
185
- * Record query execution event
186
- */
187
- recordQueryExecuted(data: {
188
- queryText: string;
189
- resultCount: number;
190
- durationMs: number;
191
- operationId?: string;
192
- }): void {
193
- this.recordEvent({
194
- eventType: EventType.QUERY_EXECUTED,
195
- queryText: data.queryText,
196
- resultCount: data.resultCount,
197
- durationMs: data.durationMs,
198
- operationId: data.operationId,
199
- });
200
- }
201
-
202
- /**
203
- * Record error event
204
- */
205
- recordError(error: Error, context?: Record<string, unknown>): void {
206
- this.recordEvent({
207
- eventType: EventType.ERROR_OCCURRED,
208
- errorCode: (error as any).code || 'UNKNOWN',
209
- errorMessage: error.message,
210
- stackTrace: error.stack,
211
- metadata: context,
212
- });
213
- }
214
-
215
- /**
216
- * Flush all queued events to telemetry endpoints
217
- */
218
- async flush(): Promise<void> {
219
- if (this.eventQueue.length === 0) return;
220
-
221
- const events = this.eventQueue.splice(0, this.batchSize);
222
-
223
- // Create payload without license key (send only in headers)
224
- const payload = {
225
- events: events.map(e => {
226
- const { ...eventWithoutKey } = e;
227
- return eventWithoutKey;
228
- }),
229
- batchId: `${this.projectId}_${Date.now()}`,
230
- };
231
-
232
- // Send to Retrivora admin dashboard
233
- try {
234
- await this.http.post(TelemetryService.RETRIVORA_TELEMETRY_URL, payload);
235
- //console.log(`[TelemetryService] Flushed ${events.length} events to Retrivora`);
236
- } catch (err: any) {
237
- console.warn('[TelemetryService] Failed to send telemetry to Retrivora:', err.message);
238
- // Re-queue events if send fails
239
- this.eventQueue.unshift(...events);
240
- }
241
-
242
- // Send to user's telemetry endpoint if configured
243
- if (this.userTelemetryUrl) {
244
- try {
245
- await axios.post(this.userTelemetryUrl, payload, {
246
- timeout: 5000,
247
- headers: {
248
- 'Content-Type': 'application/json',
249
- 'X-Project-ID': this.projectId,
250
- },
251
- });
252
- //console.log(`[TelemetryService] Flushed ${events.length} events to user telemetry`);
253
- } catch (err: any) {
254
- console.warn('[TelemetryService] Failed to send telemetry to user endpoint:', err.message);
255
- }
256
- }
257
- }
258
-
259
- /**
260
- * Start automatic flush interval
261
- */
262
- private startAutoFlush(): void {
263
- this.flushTimer = setInterval(() => {
264
- this.flush().catch(err => {
265
- console.warn('[TelemetryService] Auto-flush error:', err.message);
266
- });
267
- }, this.flushIntervalMs);
268
- }
269
-
270
- /**
271
- * Stop telemetry service and flush remaining events
272
- */
273
- async shutdown(): Promise<void> {
274
- if (this.flushTimer) {
275
- clearInterval(this.flushTimer);
276
- }
277
- await this.flush();
278
- this.enabled = false;
279
- }
280
-
281
- /**
282
- * Disable telemetry temporarily
283
- */
284
- disable(): void {
285
- this.enabled = false;
286
- }
287
-
288
- /**
289
- * Enable telemetry
290
- */
291
- enable(): void {
292
- this.enabled = true;
293
- }
294
-
295
- /**
296
- * Get current queue size (for debugging)
297
- */
298
- getQueueSize(): number {
299
- return this.eventQueue.length;
300
- }
301
- }
302
-
303
- // Singleton instance
304
- let globalTelemetryService: TelemetryService | null = null;
305
-
306
- /**
307
- * Get or create global telemetry service instance
308
- */
309
- export function getTelemetryService(): TelemetryService | null {
310
- return globalTelemetryService;
311
- }
312
-
313
- /**
314
- * Initialize global telemetry service
315
- */
316
- export function initializeTelemetryService(projectId: string, licenseKey: string, userTelemetryUrl?: string): TelemetryService {
317
- globalTelemetryService = new TelemetryService(projectId, licenseKey, userTelemetryUrl);
318
- //console.log('[TelemetryService] Initialized for project:', projectId);
319
- return globalTelemetryService;
320
- }
321
-
322
- /**
323
- * Shutdown global telemetry service
324
- */
325
- export async function shutdownTelemetryService(): Promise<void> {
326
- if (globalTelemetryService) {
327
- await globalTelemetryService.shutdown();
328
- globalTelemetryService = null;
329
- }
330
- }