@contiva/sapbtp-docs-mcp 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +395 -0
- package/README.md +386 -0
- package/build/cache/embedding-cache.d.ts +39 -0
- package/build/cache/embedding-cache.d.ts.map +1 -0
- package/build/cache/embedding-cache.js +105 -0
- package/build/cache/embedding-cache.js.map +1 -0
- package/build/cache/file-cache.d.ts +40 -0
- package/build/cache/file-cache.d.ts.map +1 -0
- package/build/cache/file-cache.js +124 -0
- package/build/cache/file-cache.js.map +1 -0
- package/build/cache/search-cache.d.ts +39 -0
- package/build/cache/search-cache.d.ts.map +1 -0
- package/build/cache/search-cache.js +97 -0
- package/build/cache/search-cache.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +17 -0
- package/build/index.js.map +1 -0
- package/build/indexing/file-registry.d.ts +47 -0
- package/build/indexing/file-registry.d.ts.map +1 -0
- package/build/indexing/file-registry.js +130 -0
- package/build/indexing/file-registry.js.map +1 -0
- package/build/indexing/topic-index.d.ts +57 -0
- package/build/indexing/topic-index.d.ts.map +1 -0
- package/build/indexing/topic-index.js +181 -0
- package/build/indexing/topic-index.js.map +1 -0
- package/build/parsers/links.d.ts +14 -0
- package/build/parsers/links.d.ts.map +1 -0
- package/build/parsers/links.js +80 -0
- package/build/parsers/links.js.map +1 -0
- package/build/parsers/markdown.d.ts +10 -0
- package/build/parsers/markdown.d.ts.map +1 -0
- package/build/parsers/markdown.js +120 -0
- package/build/parsers/markdown.js.map +1 -0
- package/build/parsers/metadata.d.ts +19 -0
- package/build/parsers/metadata.d.ts.map +1 -0
- package/build/parsers/metadata.js +63 -0
- package/build/parsers/metadata.js.map +1 -0
- package/build/search/fulltext.d.ts +20 -0
- package/build/search/fulltext.d.ts.map +1 -0
- package/build/search/fulltext.js +117 -0
- package/build/search/fulltext.js.map +1 -0
- package/build/search/ranking.d.ts +27 -0
- package/build/search/ranking.d.ts.map +1 -0
- package/build/search/ranking.js +119 -0
- package/build/search/ranking.js.map +1 -0
- package/build/search/semantic.d.ts +53 -0
- package/build/search/semantic.d.ts.map +1 -0
- package/build/search/semantic.js +260 -0
- package/build/search/semantic.js.map +1 -0
- package/build/search/title.d.ts +18 -0
- package/build/search/title.d.ts.map +1 -0
- package/build/search/title.js +95 -0
- package/build/search/title.js.map +1 -0
- package/build/server.d.ts +32 -0
- package/build/server.d.ts.map +1 -0
- package/build/server.js +183 -0
- package/build/server.js.map +1 -0
- package/build/tools/get-related.d.ts +64 -0
- package/build/tools/get-related.d.ts.map +1 -0
- package/build/tools/get-related.js +203 -0
- package/build/tools/get-related.js.map +1 -0
- package/build/tools/list-topics.d.ts +43 -0
- package/build/tools/list-topics.d.ts.map +1 -0
- package/build/tools/list-topics.js +63 -0
- package/build/tools/list-topics.js.map +1 -0
- package/build/tools/read-article.d.ts +42 -0
- package/build/tools/read-article.d.ts.map +1 -0
- package/build/tools/read-article.js +89 -0
- package/build/tools/read-article.js.map +1 -0
- package/build/tools/search.d.ts +57 -0
- package/build/tools/search.d.ts.map +1 -0
- package/build/tools/search.js +109 -0
- package/build/tools/search.js.map +1 -0
- package/build/types/index.d.ts +179 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +2 -0
- package/build/types/index.js.map +1 -0
- package/build/utils/docs-downloader.d.ts +9 -0
- package/build/utils/docs-downloader.d.ts.map +1 -0
- package/build/utils/docs-downloader.js +82 -0
- package/build/utils/docs-downloader.js.map +1 -0
- package/build/utils/paths.d.ts +67 -0
- package/build/utils/paths.d.ts.map +1 -0
- package/build/utils/paths.js +132 -0
- package/build/utils/paths.js.map +1 -0
- package/build/utils/text-processing.d.ts +62 -0
- package/build/utils/text-processing.d.ts.map +1 -0
- package/build/utils/text-processing.js +214 -0
- package/build/utils/text-processing.js.map +1 -0
- package/package.json +63 -0
package/README.md
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
# SAP Business Technology Platform Documentation MCP Server
|
|
2
|
+
|
|
3
|
+
> **Bring the entire SAP Business Technology Platform documentation directly into Claude Desktop** - search, explore, and get instant answers without leaving your AI assistant.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@contiva/sapbtp-docs-mcp)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
## What is this?
|
|
9
|
+
|
|
10
|
+
This MCP (Model Context Protocol) server gives Claude Desktop instant access to **3,500+ SAP Business Technology Platform documentation pages**, including:
|
|
11
|
+
|
|
12
|
+
- 📘 **SAP Business Technology Platform** - Complete platform documentation
|
|
13
|
+
- 🔌 **Cloud Integration** - Integration flows, adapters, security
|
|
14
|
+
- 🚀 **API Management** - API proxies, policies, analytics
|
|
15
|
+
|
|
16
|
+
**No more switching between browser tabs.** Ask Claude about SAP Business Technology Platform directly in your conversation.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Quick Start (2 minutes)
|
|
21
|
+
|
|
22
|
+
### Step 1: Install via Claude Desktop Config
|
|
23
|
+
|
|
24
|
+
Add this to your Claude Desktop configuration:
|
|
25
|
+
|
|
26
|
+
**macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
27
|
+
**Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"mcpServers": {
|
|
32
|
+
"sapis-docs": {
|
|
33
|
+
"command": "npx",
|
|
34
|
+
"args": ["@contiva/sapbtp-docs-mcp"]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Step 2: Restart Claude Desktop
|
|
41
|
+
|
|
42
|
+
That's it! On first launch, the documentation (~50MB) downloads automatically in 1-2 minutes.
|
|
43
|
+
|
|
44
|
+
### Step 3: Start asking questions
|
|
45
|
+
|
|
46
|
+
Try these in Claude:
|
|
47
|
+
|
|
48
|
+
> "Search for OAuth 2.0 authentication in API Management"
|
|
49
|
+
|
|
50
|
+
> "Show me how to configure CSRF protection in Cloud Integration"
|
|
51
|
+
|
|
52
|
+
> "What are the best practices for error handling in integration flows?"
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Why Use This?
|
|
57
|
+
|
|
58
|
+
### ✅ **Instant, Context-Aware Answers**
|
|
59
|
+
Instead of searching through help.sap.com manually, Claude can:
|
|
60
|
+
- Search across all documentation instantly
|
|
61
|
+
- Understand your question contextually
|
|
62
|
+
- Combine information from multiple articles
|
|
63
|
+
- Give you step-by-step guidance based on official docs
|
|
64
|
+
|
|
65
|
+
### ✅ **Three Powerful Search Methods**
|
|
66
|
+
- **Full-text search** - Find anything in 3,500+ pages
|
|
67
|
+
- **Title-based search** - Fast fuzzy matching for quick lookups
|
|
68
|
+
- **Semantic search** - AI understands what you mean, not just keywords
|
|
69
|
+
|
|
70
|
+
### ✅ **Works Offline**
|
|
71
|
+
All documentation and AI embeddings run locally. No API keys needed, no data leaves your machine.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Real-World Examples
|
|
76
|
+
|
|
77
|
+
### Example 1: Learning a New Feature
|
|
78
|
+
|
|
79
|
+
**You:**
|
|
80
|
+
> "I need to set up OAuth 2.0 authentication for my API proxy. Show me the steps."
|
|
81
|
+
|
|
82
|
+
**Claude (with MCP):**
|
|
83
|
+
> I'll search the API Management documentation for OAuth 2.0 setup...
|
|
84
|
+
>
|
|
85
|
+
> Based on the official documentation, here are the steps to configure OAuth 2.0:
|
|
86
|
+
>
|
|
87
|
+
> 1. Create an OAuth 2.0 Provider in API Management
|
|
88
|
+
> 2. Configure the Token Endpoint...
|
|
89
|
+
> [Complete step-by-step guide with exact configuration]
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
### Example 2: Troubleshooting
|
|
94
|
+
|
|
95
|
+
**You:**
|
|
96
|
+
> "My integration flow is failing with a CSRF token error. How do I fix this?"
|
|
97
|
+
|
|
98
|
+
**Claude (with MCP):**
|
|
99
|
+
> Let me search for CSRF protection documentation in Cloud Integration...
|
|
100
|
+
>
|
|
101
|
+
> The error occurs because Cloud Integration requires CSRF tokens for state-changing operations. Here's how to configure it:
|
|
102
|
+
>
|
|
103
|
+
> [Specific troubleshooting steps from the docs]
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
### Example 3: Architecture Decisions
|
|
108
|
+
|
|
109
|
+
**You:**
|
|
110
|
+
> "What's the difference between Basic Authentication and OAuth in SAP Cloud Integration?"
|
|
111
|
+
|
|
112
|
+
**Claude (with MCP):**
|
|
113
|
+
> I'll compare both authentication methods from the documentation...
|
|
114
|
+
>
|
|
115
|
+
> **Basic Authentication:**
|
|
116
|
+
> - Use case: [from docs]
|
|
117
|
+
> - Security considerations: [from docs]
|
|
118
|
+
>
|
|
119
|
+
> **OAuth 2.0:**
|
|
120
|
+
> - Use case: [from docs]
|
|
121
|
+
> - Security considerations: [from docs]
|
|
122
|
+
>
|
|
123
|
+
> **Recommendation:** [Based on official SAP guidance]
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Features in Detail
|
|
128
|
+
|
|
129
|
+
### 🔍 Smart Search Capabilities
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
Claude can now:
|
|
133
|
+
├─ Search by keywords (full-text)
|
|
134
|
+
├─ Search by topic titles (fuzzy matching)
|
|
135
|
+
├─ Search by meaning (semantic AI search)
|
|
136
|
+
└─ Combine all three for best results
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 📚 Complete Documentation Coverage
|
|
140
|
+
|
|
141
|
+
- **1,980 files** - Integration Suite main docs
|
|
142
|
+
- **1,175 files** - Cloud Integration specifics
|
|
143
|
+
- **312 files** - API Management guides
|
|
144
|
+
- Automatically updated from [SAP's official repository](https://github.com/SAP-docs/btp-cloud-platform)
|
|
145
|
+
|
|
146
|
+
### ⚡ Performance
|
|
147
|
+
|
|
148
|
+
- **Startup**: < 1 second
|
|
149
|
+
- **Search**: 100-200ms for full-text, 500ms for semantic
|
|
150
|
+
- **Memory**: ~50-65MB total
|
|
151
|
+
- **First-time setup**: 1-2 minutes (one-time documentation download)
|
|
152
|
+
|
|
153
|
+
### 🔒 Privacy-First
|
|
154
|
+
|
|
155
|
+
- **100% local** - All AI embeddings run on your machine
|
|
156
|
+
- **No API keys** - No external services required
|
|
157
|
+
- **No data sharing** - Your queries stay private
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Available Commands
|
|
162
|
+
|
|
163
|
+
Once installed, Claude can use these tools automatically:
|
|
164
|
+
|
|
165
|
+
### 🔍 search_documentation
|
|
166
|
+
Search across all documentation with combined search methods.
|
|
167
|
+
|
|
168
|
+
**Example questions:**
|
|
169
|
+
- "Search for SAML authentication"
|
|
170
|
+
- "Find documentation about message mapping"
|
|
171
|
+
- "Show me API proxy configuration examples"
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
### 📖 read_article
|
|
176
|
+
Read complete documentation articles.
|
|
177
|
+
|
|
178
|
+
**Example questions:**
|
|
179
|
+
- "Read the full article about OAuth configuration"
|
|
180
|
+
- "Show me the complete guide for CSRF protection"
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
### 📑 list_topics
|
|
185
|
+
Browse documentation structure hierarchically.
|
|
186
|
+
|
|
187
|
+
**Example questions:**
|
|
188
|
+
- "List all Cloud Integration topics"
|
|
189
|
+
- "Show me the table of contents for API Management"
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
### 🔗 get_related_articles
|
|
194
|
+
Find related documentation automatically.
|
|
195
|
+
|
|
196
|
+
**Example questions:**
|
|
197
|
+
- "What else should I read about authentication?"
|
|
198
|
+
- "Find related articles to this integration flow guide"
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Advanced Configuration
|
|
203
|
+
|
|
204
|
+
### Custom Documentation Path
|
|
205
|
+
|
|
206
|
+
If you cloned the SAP docs repository locally:
|
|
207
|
+
|
|
208
|
+
```json
|
|
209
|
+
{
|
|
210
|
+
"mcpServers": {
|
|
211
|
+
"sapis-docs": {
|
|
212
|
+
"command": "npx",
|
|
213
|
+
"args": ["@contiva/sapbtp-docs-mcp"],
|
|
214
|
+
"env": {
|
|
215
|
+
"MCP_DOCS_PATH": "/path/to/btp-integration-suite/docs"
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Cloud Embeddings (Optional)
|
|
223
|
+
|
|
224
|
+
For faster initial indexing, use cloud-based embeddings:
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
{
|
|
228
|
+
"mcpServers": {
|
|
229
|
+
"sapis-docs": {
|
|
230
|
+
"command": "npx",
|
|
231
|
+
"args": ["@contiva/sapbtp-docs-mcp"],
|
|
232
|
+
"env": {
|
|
233
|
+
"EMBEDDING_PROVIDER": "voyage",
|
|
234
|
+
"VOYAGE_API_KEY": "your-api-key"
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**Note:** Local embeddings (default) are free and work offline. Cloud embeddings reduce first-time indexing from 10-15 minutes to 2-3 minutes but require an API key.
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## Troubleshooting
|
|
246
|
+
|
|
247
|
+
### "Documentation not found" error
|
|
248
|
+
|
|
249
|
+
The first run downloads docs automatically. If it fails:
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
# Manual installation
|
|
253
|
+
git clone https://github.com/SAP-docs/btp-cloud-platform.git
|
|
254
|
+
export MCP_DOCS_PATH=/path/to/btp-integration-suite/docs
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Then restart Claude Desktop.
|
|
258
|
+
|
|
259
|
+
### MCP server not showing up
|
|
260
|
+
|
|
261
|
+
1. Check your config file path is correct
|
|
262
|
+
2. Ensure JSON syntax is valid (use a JSON validator)
|
|
263
|
+
3. Restart Claude Desktop completely
|
|
264
|
+
4. Check Claude Desktop logs for errors
|
|
265
|
+
|
|
266
|
+
### Slow semantic search
|
|
267
|
+
|
|
268
|
+
First-time semantic search builds an AI index (10-15 minutes with local embeddings). This is one-time only - subsequent searches are instant.
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## Development
|
|
273
|
+
|
|
274
|
+
### Local Development Setup
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
# Clone the MCP server
|
|
278
|
+
git clone https://github.com/robertfels/sapbtp-docs-mcp.git
|
|
279
|
+
cd sapbtp-docs-mcp
|
|
280
|
+
|
|
281
|
+
# Clone SAP docs (or it downloads automatically)
|
|
282
|
+
git clone https://github.com/SAP-docs/btp-cloud-platform.git
|
|
283
|
+
|
|
284
|
+
# Install and build
|
|
285
|
+
npm install
|
|
286
|
+
npm run build
|
|
287
|
+
|
|
288
|
+
# Test locally
|
|
289
|
+
npm start
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Publishing Updates
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
npm version patch
|
|
296
|
+
npm publish --otp=<your-2fa-code>
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## How It Works
|
|
302
|
+
|
|
303
|
+
```
|
|
304
|
+
┌─────────────────┐
|
|
305
|
+
│ Claude Desktop │
|
|
306
|
+
│ │
|
|
307
|
+
│ "Search for │
|
|
308
|
+
│ OAuth in │
|
|
309
|
+
│ API Mgmt" │
|
|
310
|
+
└────────┬────────┘
|
|
311
|
+
│
|
|
312
|
+
│ MCP Protocol
|
|
313
|
+
▼
|
|
314
|
+
┌─────────────────────────────────┐
|
|
315
|
+
│ @contiva/sapbtp-docs-mcp │
|
|
316
|
+
│ │
|
|
317
|
+
│ ┌───────────┐ ┌────────────┐ │
|
|
318
|
+
│ │ Full-text │ │ Title │ │
|
|
319
|
+
│ │ Search │ │ Search │ │
|
|
320
|
+
│ └───────────┘ └────────────┘ │
|
|
321
|
+
│ │
|
|
322
|
+
│ ┌───────────────────────────┐ │
|
|
323
|
+
│ │ Semantic AI Search │ │
|
|
324
|
+
│ │ (Local Embeddings) │ │
|
|
325
|
+
│ └───────────────────────────┘ │
|
|
326
|
+
│ │
|
|
327
|
+
│ ┌───────────────────────────┐ │
|
|
328
|
+
│ │ 3,500+ Markdown Files │ │
|
|
329
|
+
│ │ (Downloaded from SAP) │ │
|
|
330
|
+
│ └───────────────────────────┘ │
|
|
331
|
+
└─────────────────────────────────┘
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## Related Projects
|
|
337
|
+
|
|
338
|
+
- [Model Context Protocol](https://modelcontextprotocol.io/) - Open protocol for AI-tool integration
|
|
339
|
+
- [SAP Business Technology Platform Docs](https://github.com/SAP-docs/btp-cloud-platform) - Official SAP documentation repository
|
|
340
|
+
- [Claude Desktop](https://claude.ai/download) - AI assistant with MCP support
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## Contributing to SAP Documentation
|
|
345
|
+
|
|
346
|
+
Found an error in the SAP documentation? You can contribute!
|
|
347
|
+
|
|
348
|
+
This MCP server uses the official [SAP Business Technology Platform documentation repository](https://github.com/SAP-docs/btp-cloud-platform). All contributions to the documentation should be made there.
|
|
349
|
+
|
|
350
|
+
### How to Contribute
|
|
351
|
+
|
|
352
|
+
1. Open the relevant guide on [SAP Help Portal](https://help.sap.com/docs/SAP_INTEGRATION_SUITE)
|
|
353
|
+
2. Choose **Feedback** > **Edit page** to suggest changes
|
|
354
|
+
3. Or choose **Feedback** > **Create issue** to report problems
|
|
355
|
+
|
|
356
|
+
See [SAP's Contribution Guidelines](https://help.sap.com/products/open-documentation-initiative/contribution-guidelines/readme.html) for more details.
|
|
357
|
+
|
|
358
|
+
### Covered Documentation Areas
|
|
359
|
+
|
|
360
|
+
| Guide | Description |
|
|
361
|
+
|:---|:---|
|
|
362
|
+
| [SAP Business Technology Platform](https://help.sap.com/docs/SAP_INTEGRATION_SUITE/51ab953548be4459bfe8539ecaeee98d/5cc6987511104c418b7cb4c25f3d9cb0.html?version=CLOUD) | Platform overview and general capabilities |
|
|
363
|
+
| [SAP API Management](https://help.sap.com/docs/sap-api-management/sap-api-management/sap-api-management-in-cloud-foundry-environment?version=Cloud) | API proxies, policies, and analytics |
|
|
364
|
+
| [SAP Cloud Integration](https://help.sap.com/docs/cloud-integration/sap-cloud-integration/sap-cloud-integration) | Integration flows, adapters, and security |
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## License
|
|
369
|
+
|
|
370
|
+
This MCP server is licensed under [Apache-2.0](LICENSE).
|
|
371
|
+
|
|
372
|
+
The SAP documentation content is subject to SAP's licensing terms. See the [SAP documentation repository](https://github.com/SAP-docs/btp-cloud-platform) for details.
|
|
373
|
+
|
|
374
|
+
---
|
|
375
|
+
|
|
376
|
+
## Support
|
|
377
|
+
|
|
378
|
+
- **Issues**: [GitHub Issues](https://github.com/robertfels/sapbtp-docs-mcp/issues)
|
|
379
|
+
- **NPM Package**: [@contiva/sapbtp-docs-mcp](https://www.npmjs.com/package/@contiva/sapbtp-docs-mcp)
|
|
380
|
+
- **SAP Documentation**: [help.sap.com](https://help.sap.com/docs/SAP_INTEGRATION_SUITE)
|
|
381
|
+
|
|
382
|
+
---
|
|
383
|
+
|
|
384
|
+
**Made with ❤️ for the SAP Business Technology Platform community**
|
|
385
|
+
|
|
386
|
+
[](https://api.reuse.software/info/github.com/SAP-docs/btp-cloud-platform)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { EmbeddingCacheData, EmbeddingProvider } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Persistent cache for document embeddings
|
|
4
|
+
*/
|
|
5
|
+
export declare class EmbeddingCache {
|
|
6
|
+
private cachePath;
|
|
7
|
+
private cacheDir;
|
|
8
|
+
private version;
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Loads embeddings from cache file
|
|
12
|
+
*/
|
|
13
|
+
load(): Promise<EmbeddingCacheData | null>;
|
|
14
|
+
/**
|
|
15
|
+
* Saves embeddings to cache file
|
|
16
|
+
*/
|
|
17
|
+
save(data: EmbeddingCacheData): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Checks if the cache is valid for a given provider
|
|
20
|
+
*/
|
|
21
|
+
isValid(provider: EmbeddingProvider, model: string): Promise<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Gets the cache file size in MB
|
|
24
|
+
*/
|
|
25
|
+
getSize(): Promise<number>;
|
|
26
|
+
/**
|
|
27
|
+
* Deletes the cache file
|
|
28
|
+
*/
|
|
29
|
+
clear(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Checks if cache exists
|
|
32
|
+
*/
|
|
33
|
+
exists(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Gets cache file path
|
|
36
|
+
*/
|
|
37
|
+
getPath(): string;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=embedding-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedding-cache.d.ts","sourceRoot":"","sources":["../../src/cache/embedding-cache.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAG/E;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAmB;;IAOlC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAsBhD;;OAEG;IACG,IAAI,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBnD;;OAEG;IACG,OAAO,CAAC,QAAQ,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAY3E;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAahC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ5B;;OAEG;IACH,MAAM,IAAI,OAAO;IAIjB;;OAEG;IACH,OAAO,IAAI,MAAM;CAGlB"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { readFile, writeFile, mkdir } from 'fs/promises';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { resolveCacheDir } from '../utils/paths.js';
|
|
5
|
+
/**
|
|
6
|
+
* Persistent cache for document embeddings
|
|
7
|
+
*/
|
|
8
|
+
export class EmbeddingCache {
|
|
9
|
+
cachePath;
|
|
10
|
+
cacheDir;
|
|
11
|
+
version = '1.0.0';
|
|
12
|
+
constructor() {
|
|
13
|
+
this.cacheDir = resolveCacheDir();
|
|
14
|
+
this.cachePath = join(this.cacheDir, 'embeddings.json');
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Loads embeddings from cache file
|
|
18
|
+
*/
|
|
19
|
+
async load() {
|
|
20
|
+
if (!existsSync(this.cachePath)) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const content = await readFile(this.cachePath, 'utf-8');
|
|
25
|
+
const data = JSON.parse(content);
|
|
26
|
+
// Validate cache version
|
|
27
|
+
if (data.version !== this.version) {
|
|
28
|
+
console.error(`Embedding cache version mismatch. Expected ${this.version}, got ${data.version}. Rebuilding...`);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.error('Error loading embedding cache:', error);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Saves embeddings to cache file
|
|
40
|
+
*/
|
|
41
|
+
async save(data) {
|
|
42
|
+
try {
|
|
43
|
+
// Ensure cache directory exists
|
|
44
|
+
await mkdir(this.cacheDir, { recursive: true });
|
|
45
|
+
// Write to file
|
|
46
|
+
const content = JSON.stringify(data, null, 2);
|
|
47
|
+
await writeFile(this.cachePath, content, 'utf-8');
|
|
48
|
+
console.error(`Embedding cache saved: ${data.embeddings.length} embeddings`);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.error('Error saving embedding cache:', error);
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Checks if the cache is valid for a given provider
|
|
57
|
+
*/
|
|
58
|
+
async isValid(provider, model) {
|
|
59
|
+
const data = await this.load();
|
|
60
|
+
if (!data) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return data.version === this.version &&
|
|
64
|
+
data.provider === provider &&
|
|
65
|
+
data.model === model;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Gets the cache file size in MB
|
|
69
|
+
*/
|
|
70
|
+
async getSize() {
|
|
71
|
+
if (!existsSync(this.cachePath)) {
|
|
72
|
+
return 0;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const stats = await import('fs/promises').then(fs => fs.stat(this.cachePath));
|
|
76
|
+
return stats.size / (1024 * 1024); // Convert to MB
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Deletes the cache file
|
|
84
|
+
*/
|
|
85
|
+
async clear() {
|
|
86
|
+
if (existsSync(this.cachePath)) {
|
|
87
|
+
const { unlink } = await import('fs/promises');
|
|
88
|
+
await unlink(this.cachePath);
|
|
89
|
+
console.error('Embedding cache cleared');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Checks if cache exists
|
|
94
|
+
*/
|
|
95
|
+
exists() {
|
|
96
|
+
return existsSync(this.cachePath);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Gets cache file path
|
|
100
|
+
*/
|
|
101
|
+
getPath() {
|
|
102
|
+
return this.cachePath;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=embedding-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedding-cache.js","sourceRoot":"","sources":["../../src/cache/embedding-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;GAEG;AACH,MAAM,OAAO,cAAc;IACjB,SAAS,CAAS;IAClB,QAAQ,CAAS;IACjB,OAAO,GAAW,OAAO,CAAC;IAElC;QACE,IAAI,CAAC,QAAQ,GAAG,eAAe,EAAE,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAChC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YACxD,MAAM,IAAI,GAAuB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAErD,yBAAyB;YACzB,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;gBAClC,OAAO,CAAC,KAAK,CAAC,8CAA8C,IAAI,CAAC,OAAO,SAAS,IAAI,CAAC,OAAO,iBAAiB,CAAC,CAAC;gBAChH,OAAO,IAAI,CAAC;YACd,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;YACvD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,IAAwB;QACjC,IAAI,CAAC;YACH,gCAAgC;YAChC,MAAM,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAEhD,gBAAgB;YAChB,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAC9C,MAAM,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAElD,OAAO,CAAC,KAAK,CAAC,0BAA0B,IAAI,CAAC,UAAU,CAAC,MAAM,aAAa,CAAC,CAAC;QAC/E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;YACtD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,QAA2B,EAAE,KAAa;QACtD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAE/B,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO;YAC7B,IAAI,CAAC,QAAQ,KAAK,QAAQ;YAC1B,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAChC,OAAO,CAAC,CAAC;QACX,CAAC;QAED,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;YAC9E,OAAO,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,gBAAgB;QACrD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,CAAC;QACX,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAC/B,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;YAC/C,MAAM,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC7B,OAAO,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ParsedDocument, CacheStats } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* LRU Cache for parsed documents
|
|
4
|
+
*/
|
|
5
|
+
export declare class FileCache {
|
|
6
|
+
private cache;
|
|
7
|
+
private maxSize;
|
|
8
|
+
private hits;
|
|
9
|
+
private misses;
|
|
10
|
+
constructor(maxSize?: number);
|
|
11
|
+
/**
|
|
12
|
+
* Gets a parsed document from cache or parses it
|
|
13
|
+
*/
|
|
14
|
+
get(filePath: string): Promise<ParsedDocument>;
|
|
15
|
+
/**
|
|
16
|
+
* Sets a parsed document in the cache
|
|
17
|
+
*/
|
|
18
|
+
set(filePath: string, document: ParsedDocument): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if a file is in the cache and up-to-date
|
|
21
|
+
*/
|
|
22
|
+
has(filePath: string): Promise<boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* Clears the entire cache
|
|
25
|
+
*/
|
|
26
|
+
clear(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Removes a specific file from cache
|
|
29
|
+
*/
|
|
30
|
+
invalidate(filePath: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Gets cache statistics
|
|
33
|
+
*/
|
|
34
|
+
getStats(): CacheStats;
|
|
35
|
+
/**
|
|
36
|
+
* Gets cache hit rate as a percentage
|
|
37
|
+
*/
|
|
38
|
+
getHitRate(): number;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=file-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-cache.d.ts","sourceRoot":"","sources":["../../src/cache/file-cache.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAc,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGhF;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAAsD;IACnE,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,MAAM,CAAa;gBAEf,OAAO,GAAE,MAAY;IAIjC;;OAEG;IACG,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IA+BpD;;OAEG;IACG,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BpE;;OAEG;IACG,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAmB7C;;OAEG;IACH,KAAK,IAAI,IAAI;IAMb;;OAEG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIlC;;OAEG;IACH,QAAQ,IAAI,UAAU;IAStB;;OAEG;IACH,UAAU,IAAI,MAAM;CASrB"}
|