appium-mcp 1.1.4 → 1.1.6
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/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/locators/generate-all-locators.js +2 -1
- package/dist/locators/generate-all-locators.js.map +1 -1
- package/dist/resources/index.js +2 -1
- package/dist/resources/index.js.map +1 -1
- package/dist/tools/answer-appium.js +2 -1
- package/dist/tools/answer-appium.js.map +1 -1
- package/dist/tools/boot-simulator.js +2 -1
- package/dist/tools/boot-simulator.js.map +1 -1
- package/dist/tools/delete-session.js +2 -1
- package/dist/tools/delete-session.js.map +1 -1
- package/dist/tools/documentation/index.js +7 -6
- package/dist/tools/documentation/index.js.map +1 -1
- package/dist/tools/documentation/reasoning-rag.js +16 -15
- package/dist/tools/documentation/reasoning-rag.js.map +1 -1
- package/dist/tools/documentation/sentence-transformers-embeddings.js +8 -7
- package/dist/tools/documentation/sentence-transformers-embeddings.js.map +1 -1
- package/dist/tools/documentation/simple-pdf-indexer.js +48 -47
- package/dist/tools/documentation/simple-pdf-indexer.js.map +1 -1
- package/dist/tools/index.js +2 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/install-wda.js +6 -5
- package/dist/tools/install-wda.js.map +1 -1
- package/dist/tools/interactions/get-page-source.d.ts +2 -0
- package/dist/tools/interactions/get-page-source.js +48 -0
- package/dist/tools/interactions/get-page-source.js.map +1 -0
- package/dist/tools/locators.js +2 -3
- package/dist/tools/locators.js.map +1 -1
- package/dist/tools/scroll.js +5 -4
- package/dist/tools/scroll.js.map +1 -1
- package/dist/tools/session-store.js +6 -5
- package/dist/tools/session-store.js.map +1 -1
- package/package.json +1 -1
- package/src/locators/generate-all-locators.ts +2 -1
- package/src/resources/index.ts +2 -1
- package/src/tools/README.md +2 -1
- package/src/tools/answer-appium.ts +2 -1
- package/src/tools/boot-simulator.ts +2 -1
- package/src/tools/delete-session.ts +2 -1
- package/src/tools/documentation/index.ts +7 -6
- package/src/tools/documentation/reasoning-rag.ts +16 -15
- package/src/tools/documentation/sentence-transformers-embeddings.ts +9 -7
- package/src/tools/documentation/simple-pdf-indexer.ts +48 -51
- package/src/tools/index.ts +2 -0
- package/src/tools/install-wda.ts +6 -5
- package/src/tools/interactions/get-page-source.ts +52 -0
- package/src/tools/locators.ts +3 -4
- package/src/tools/scroll.ts +5 -4
- package/src/tools/session-store.ts +6 -5
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AndroidUiautomator2Driver } from 'appium-uiautomator2-driver';
|
|
2
2
|
import { XCUITestDriver } from 'appium-xcuitest-driver';
|
|
3
|
+
import log from '../locators/logger.js';
|
|
3
4
|
let driver = null;
|
|
4
5
|
let sessionId = null;
|
|
5
6
|
let isDeletingSession = false; // Lock to prevent concurrent deletion
|
|
@@ -26,27 +27,27 @@ export function hasActiveSession() {
|
|
|
26
27
|
export async function safeDeleteSession() {
|
|
27
28
|
// Check if there's no session to delete
|
|
28
29
|
if (!driver || !sessionId) {
|
|
29
|
-
|
|
30
|
+
log.info('No active session to delete.');
|
|
30
31
|
return false;
|
|
31
32
|
}
|
|
32
33
|
// Check if deletion is already in progress
|
|
33
34
|
if (isDeletingSession) {
|
|
34
|
-
|
|
35
|
+
log.info('Session deletion already in progress, skipping...');
|
|
35
36
|
return false;
|
|
36
37
|
}
|
|
37
38
|
// Set lock
|
|
38
39
|
isDeletingSession = true;
|
|
39
40
|
try {
|
|
40
|
-
|
|
41
|
+
log.info('Deleting current session');
|
|
41
42
|
await driver.deleteSession();
|
|
42
43
|
// Clear the session from store
|
|
43
44
|
driver = null;
|
|
44
45
|
sessionId = null;
|
|
45
|
-
|
|
46
|
+
log.info('Session deleted successfully.');
|
|
46
47
|
return true;
|
|
47
48
|
}
|
|
48
49
|
catch (error) {
|
|
49
|
-
|
|
50
|
+
log.error('Error deleting session:', error);
|
|
50
51
|
throw error;
|
|
51
52
|
}
|
|
52
53
|
finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-store.js","sourceRoot":"","sources":["../../src/tools/session-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"session-store.js","sourceRoot":"","sources":["../../src/tools/session-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,GAAG,MAAM,uBAAuB,CAAC;AAExC,IAAI,MAAM,GAAQ,IAAI,CAAC;AACvB,IAAI,SAAS,GAAkB,IAAI,CAAC;AACpC,IAAI,iBAAiB,GAAG,KAAK,CAAC,CAAC,sCAAsC;AAErE,MAAM,UAAU,UAAU,CAAC,CAAM,EAAE,EAAiB;IAClD,MAAM,GAAG,CAAC,CAAC;IACX,SAAS,GAAG,EAAE,CAAC;IACf,iDAAiD;IACjD,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;QACZ,iBAAiB,GAAG,KAAK,CAAC;IAC5B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,SAAS;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,MAAM,KAAK,IAAI,IAAI,SAAS,KAAK,IAAI,IAAI,CAAC,iBAAiB,CAAC;AACrE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACrC,wCAAwC;IACxC,IAAI,CAAC,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QAC1B,GAAG,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;QACzC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,2CAA2C;IAC3C,IAAI,iBAAiB,EAAE,CAAC;QACtB,GAAG,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;QAC9D,OAAO,KAAK,CAAC;IACf,CAAC;IAED,WAAW;IACX,iBAAiB,GAAG,IAAI,CAAC;IAEzB,IAAI,CAAC;QACH,GAAG,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QACrC,MAAM,MAAM,CAAC,aAAa,EAAE,CAAC;QAE7B,+BAA+B;QAC/B,MAAM,GAAG,IAAI,CAAC;QACd,SAAS,GAAG,IAAI,CAAC;QAEjB,GAAG,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QAC5C,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,sBAAsB;QACtB,iBAAiB,GAAG,KAAK,CAAC;IAC5B,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAW,EAAU,EAAE;IACrD,IAAI,MAAM,YAAY,yBAAyB;QAAE,OAAO,SAAS,CAAC;IAClE,IAAI,MAAM,YAAY,cAAc;QAAE,OAAO,KAAK,CAAC;IACnD,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;AACzC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import { getSuggestedLocators } from './locator-generation.js';
|
|
|
5
5
|
import { xmlToJSON, JSONElement } from './source-parsing.js';
|
|
6
6
|
import { shouldIncludeElement, FilterOptions } from './element-filter.js';
|
|
7
7
|
import * as fs from 'fs';
|
|
8
|
+
import log from './logger.js';
|
|
8
9
|
|
|
9
10
|
export interface ElementWithLocators {
|
|
10
11
|
tagName: string;
|
|
@@ -69,7 +70,7 @@ function processElement(
|
|
|
69
70
|
);
|
|
70
71
|
results.push(transformElementWithLocators(element, strategyMap));
|
|
71
72
|
} catch (error) {
|
|
72
|
-
|
|
73
|
+
log.error(
|
|
73
74
|
`Error generating locators for element at path ${element.path}:`,
|
|
74
75
|
error
|
|
75
76
|
);
|
package/src/resources/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Export all resources
|
|
2
2
|
import javaTemplatesResource from './java/template.js';
|
|
3
|
+
import log from '../locators/logger.js';
|
|
3
4
|
|
|
4
5
|
export default function registerResources(server: any) {
|
|
5
6
|
javaTemplatesResource(server);
|
|
6
|
-
|
|
7
|
+
log.info('All resources registered');
|
|
7
8
|
}
|
package/src/tools/README.md
CHANGED
|
@@ -25,6 +25,7 @@ This directory contains all MCP tools available in MCP Appium.
|
|
|
25
25
|
- `double-tap.ts` - Double tap elements
|
|
26
26
|
- `set-value.ts` - Enter text
|
|
27
27
|
- `get-text.ts` - Get element text
|
|
28
|
+
- `get-page-source.ts` - Get page source (XML) from current screen
|
|
28
29
|
- `screenshot.ts` - Capture screenshots
|
|
29
30
|
- `activate-app.ts` - Activate apps
|
|
30
31
|
- `terminate-app.ts` - Terminate apps
|
|
@@ -112,7 +113,7 @@ export default function registerTools(server: FastMCP): void {
|
|
|
112
113
|
1. **Always check for active session**: Use `getDriver()` and check for null
|
|
113
114
|
2. **Provide helpful errors**: Give clear error messages
|
|
114
115
|
3. **Use proper types**: Leverage TypeScript and Zod for type safety
|
|
115
|
-
4. **Add logging**: Use `console.log`
|
|
116
|
+
4. **Add logging**: Use the logger from `../locators/logger.js` for debugging. Import with: `import log from '../locators/logger.js'`. Use `log.info()`, `log.error()`, `log.warn()` instead of `console.log/error/warn` to maintain JSON-RPC compatibility
|
|
116
117
|
5. **Handle errors**: Always wrap risky operations in try-catch
|
|
117
118
|
6. **Return proper format**: Always return content in expected MCP format
|
|
118
119
|
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
answerAppiumQuery,
|
|
7
7
|
initializeAppiumDocumentation,
|
|
8
8
|
} from './documentation/index.js';
|
|
9
|
+
import log from '../locators/logger.js';
|
|
9
10
|
|
|
10
11
|
export default function answerAppium(server: any): void {
|
|
11
12
|
server.addTool({
|
|
@@ -45,7 +46,7 @@ export default function answerAppium(server: any): void {
|
|
|
45
46
|
} catch (docError) {
|
|
46
47
|
// If documentation query fails, try to initialize and retry once
|
|
47
48
|
try {
|
|
48
|
-
|
|
49
|
+
log.info('Documentation not initialized, initializing now...');
|
|
49
50
|
await initializeAppiumDocumentation();
|
|
50
51
|
const result = await answerAppiumQuery({ query });
|
|
51
52
|
return {
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { Simctl } from 'node-simctl';
|
|
6
6
|
import { IOSManager } from '../devicemanager/ios-manager.js';
|
|
7
|
+
import log from '../locators/logger.js';
|
|
7
8
|
|
|
8
9
|
export default function bootSimulator(server: any): void {
|
|
9
10
|
server.addTool({
|
|
@@ -79,7 +80,7 @@ export default function bootSimulator(server: any): void {
|
|
|
79
80
|
],
|
|
80
81
|
};
|
|
81
82
|
} catch (error: any) {
|
|
82
|
-
|
|
83
|
+
log.error('Error booting simulator:', error);
|
|
83
84
|
throw new Error(`Failed to boot simulator: ${error.message}`);
|
|
84
85
|
}
|
|
85
86
|
},
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { safeDeleteSession } from './session-store.js';
|
|
6
|
+
import log from '../locators/logger.js';
|
|
6
7
|
|
|
7
8
|
export default function deleteSession(server: any): void {
|
|
8
9
|
server.addTool({
|
|
@@ -38,7 +39,7 @@ export default function deleteSession(server: any): void {
|
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
} catch (error: any) {
|
|
41
|
-
|
|
42
|
+
log.error(`Error deleting session`, error);
|
|
42
43
|
throw new Error(`Failed to delete session: ${error.message}`);
|
|
43
44
|
}
|
|
44
45
|
},
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
indexAllMarkdownFiles,
|
|
11
11
|
} from './simple-pdf-indexer.js';
|
|
12
12
|
import * as path from 'path';
|
|
13
|
+
import log from '../../locators/logger.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Interface for the query response
|
|
@@ -31,11 +32,11 @@ export async function initializeAppiumDocumentation(
|
|
|
31
32
|
// Default to submodules directory if not specified
|
|
32
33
|
const docsPath =
|
|
33
34
|
resourcesPath || path.resolve(__dirname, '../../resources/submodules');
|
|
34
|
-
|
|
35
|
+
log.info(`Initializing Appium documentation from: ${docsPath}`);
|
|
35
36
|
await indexAllMarkdownFiles(docsPath);
|
|
36
|
-
|
|
37
|
+
log.info('Appium documentation indexing completed');
|
|
37
38
|
} catch (error) {
|
|
38
|
-
|
|
39
|
+
log.error('Error initializing Appium documentation:', error);
|
|
39
40
|
throw error;
|
|
40
41
|
}
|
|
41
42
|
}
|
|
@@ -50,7 +51,7 @@ export async function answerAppiumQuery(options: {
|
|
|
50
51
|
}): Promise<QueryResponse> {
|
|
51
52
|
try {
|
|
52
53
|
const { query } = options;
|
|
53
|
-
|
|
54
|
+
log.info(`Querying vector store for: "${query}"`);
|
|
54
55
|
const results = await queryVectorStore(query); // Get relevant chunks
|
|
55
56
|
|
|
56
57
|
if (!results || results.length === 0) {
|
|
@@ -75,7 +76,7 @@ export async function answerAppiumQuery(options: {
|
|
|
75
76
|
source && arr.indexOf(source) === index
|
|
76
77
|
); // Remove duplicates
|
|
77
78
|
|
|
78
|
-
|
|
79
|
+
log.info(
|
|
79
80
|
`Found ${results.length} relevant chunks from ${sources.length} sources`
|
|
80
81
|
);
|
|
81
82
|
|
|
@@ -91,7 +92,7 @@ export async function answerAppiumQuery(options: {
|
|
|
91
92
|
chunks,
|
|
92
93
|
};
|
|
93
94
|
} catch (error) {
|
|
94
|
-
|
|
95
|
+
log.error('Error querying Appium documentation:', error);
|
|
95
96
|
throw error;
|
|
96
97
|
}
|
|
97
98
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { Document } from 'langchain/document';
|
|
10
10
|
import { queryVectorStore } from './simple-pdf-indexer.js';
|
|
11
|
+
import log from '../../locators/logger.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Reasoning task types supported by the system
|
|
@@ -77,9 +78,9 @@ export class ReasoningRAG {
|
|
|
77
78
|
);
|
|
78
79
|
this.transformers = await importTransformers();
|
|
79
80
|
this.isInitialized = true;
|
|
80
|
-
|
|
81
|
+
log.info('Xenova transformers initialized for reasoning');
|
|
81
82
|
} catch (error) {
|
|
82
|
-
|
|
83
|
+
log.error('Error importing @xenova/transformers:', error);
|
|
83
84
|
throw new Error(
|
|
84
85
|
`Failed to import @xenova/transformers: ${error instanceof Error ? error.message : String(error)}`
|
|
85
86
|
);
|
|
@@ -98,7 +99,7 @@ export class ReasoningRAG {
|
|
|
98
99
|
|
|
99
100
|
await this.initializeTransformers();
|
|
100
101
|
|
|
101
|
-
|
|
102
|
+
log.info(`Loading model for ${config.task}: ${config.modelName}`);
|
|
102
103
|
|
|
103
104
|
try {
|
|
104
105
|
const model = await this.transformers.pipeline(
|
|
@@ -106,10 +107,10 @@ export class ReasoningRAG {
|
|
|
106
107
|
config.modelName
|
|
107
108
|
);
|
|
108
109
|
this.models.set(modelKey, model);
|
|
109
|
-
|
|
110
|
+
log.info(`Successfully loaded model: ${config.modelName}`);
|
|
110
111
|
return model;
|
|
111
112
|
} catch (error) {
|
|
112
|
-
|
|
113
|
+
log.error(`Error loading model ${config.modelName}:`, error);
|
|
113
114
|
throw new Error(
|
|
114
115
|
`Failed to load model: ${error instanceof Error ? error.message : String(error)}`
|
|
115
116
|
);
|
|
@@ -190,7 +191,7 @@ export class ReasoningRAG {
|
|
|
190
191
|
},
|
|
191
192
|
};
|
|
192
193
|
} catch (error) {
|
|
193
|
-
|
|
194
|
+
log.error(`Error performing reasoning with ${config.task}:`, error);
|
|
194
195
|
return {
|
|
195
196
|
originalChunk: text,
|
|
196
197
|
reasoningOutput: `Error during reasoning: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -230,7 +231,7 @@ export class ReasoningRAG {
|
|
|
230
231
|
|
|
231
232
|
// Log progress for large batches
|
|
232
233
|
if (chunks.length > batchSize) {
|
|
233
|
-
|
|
234
|
+
log.info(
|
|
234
235
|
`Processed reasoning for ${Math.min(i + batchSize, chunks.length)}/${chunks.length} chunks`
|
|
235
236
|
);
|
|
236
237
|
}
|
|
@@ -295,10 +296,10 @@ export class ReasoningRAG {
|
|
|
295
296
|
} = options;
|
|
296
297
|
|
|
297
298
|
try {
|
|
298
|
-
|
|
299
|
+
log.info(`Starting reasoning-enhanced RAG query: "${query}"`);
|
|
299
300
|
|
|
300
301
|
// Step 1: Retrieve relevant chunks using existing RAG
|
|
301
|
-
|
|
302
|
+
log.info(`Retrieving top ${topK} relevant chunks...`);
|
|
302
303
|
const retrievedChunks = await queryVectorStore(query, topK);
|
|
303
304
|
|
|
304
305
|
if (!retrievedChunks || retrievedChunks.length === 0) {
|
|
@@ -312,7 +313,7 @@ export class ReasoningRAG {
|
|
|
312
313
|
};
|
|
313
314
|
}
|
|
314
315
|
|
|
315
|
-
|
|
316
|
+
log.info(`Retrieved ${retrievedChunks.length} chunks for reasoning`);
|
|
316
317
|
|
|
317
318
|
// Step 2: Configure reasoning models
|
|
318
319
|
const configs: ReasoningConfig[] = customConfigs || [
|
|
@@ -336,7 +337,7 @@ export class ReasoningRAG {
|
|
|
336
337
|
);
|
|
337
338
|
|
|
338
339
|
// Step 3: Perform reasoning on retrieved chunks
|
|
339
|
-
|
|
340
|
+
log.info(
|
|
340
341
|
`Performing reasoning with ${filteredConfigs.length} different models...`
|
|
341
342
|
);
|
|
342
343
|
const reasoningResults = await this.processChunksWithReasoning(
|
|
@@ -346,7 +347,7 @@ export class ReasoningRAG {
|
|
|
346
347
|
);
|
|
347
348
|
|
|
348
349
|
// Step 4: Generate comprehensive summary
|
|
349
|
-
|
|
350
|
+
log.info('Generating comprehensive summary...');
|
|
350
351
|
const summary = await this.generateComprehensiveSummary(
|
|
351
352
|
reasoningResults,
|
|
352
353
|
query
|
|
@@ -379,7 +380,7 @@ export class ReasoningRAG {
|
|
|
379
380
|
source && arr.indexOf(source) === index
|
|
380
381
|
);
|
|
381
382
|
|
|
382
|
-
|
|
383
|
+
log.info(
|
|
383
384
|
`Reasoning-enhanced RAG completed. Generated ${reasoningResults.length} reasoning results from ${sources.length} sources`
|
|
384
385
|
);
|
|
385
386
|
|
|
@@ -392,7 +393,7 @@ export class ReasoningRAG {
|
|
|
392
393
|
sources,
|
|
393
394
|
};
|
|
394
395
|
} catch (error) {
|
|
395
|
-
|
|
396
|
+
log.error('Error in reasoning-enhanced RAG:', error);
|
|
396
397
|
throw new Error(
|
|
397
398
|
`Reasoning-enhanced RAG failed: ${error instanceof Error ? error.message : String(error)}`
|
|
398
399
|
);
|
|
@@ -426,7 +427,7 @@ export class ReasoningRAG {
|
|
|
426
427
|
*/
|
|
427
428
|
async cleanup(): Promise<void> {
|
|
428
429
|
this.models.clear();
|
|
429
|
-
|
|
430
|
+
log.info('Reasoning RAG resources cleaned up');
|
|
430
431
|
}
|
|
431
432
|
}
|
|
432
433
|
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* This is perfect for self-hosted MCP servers and eliminates external dependencies.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import log from '../../locators/logger.js';
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* LangChain-compatible embeddings class using sentence-transformers
|
|
10
12
|
*/
|
|
@@ -34,7 +36,7 @@ export class SentenceTransformersEmbeddings {
|
|
|
34
36
|
);
|
|
35
37
|
this.transformers = await importTransformers();
|
|
36
38
|
} catch (error) {
|
|
37
|
-
|
|
39
|
+
log.error('Error importing @xenova/transformers:', error);
|
|
38
40
|
throw new Error(
|
|
39
41
|
`Failed to import @xenova/transformers: ${error instanceof Error ? error.message : String(error)}`
|
|
40
42
|
);
|
|
@@ -51,18 +53,18 @@ export class SentenceTransformersEmbeddings {
|
|
|
51
53
|
|
|
52
54
|
await this.initializeTransformers();
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
log.info(`Initializing sentence-transformers model: ${this.modelName}`);
|
|
55
57
|
try {
|
|
56
58
|
this.model = await this.transformers.pipeline(
|
|
57
59
|
'feature-extraction',
|
|
58
60
|
this.modelName
|
|
59
61
|
);
|
|
60
62
|
this.isInitialized = true;
|
|
61
|
-
|
|
63
|
+
log.info(
|
|
62
64
|
`Successfully initialized sentence-transformers model: ${this.modelName}`
|
|
63
65
|
);
|
|
64
66
|
} catch (error) {
|
|
65
|
-
|
|
67
|
+
log.error('Error initializing sentence-transformers model:', error);
|
|
66
68
|
throw new Error(
|
|
67
69
|
`Failed to initialize sentence-transformers model: ${error instanceof Error ? error.message : String(error)}`
|
|
68
70
|
);
|
|
@@ -89,7 +91,7 @@ export class SentenceTransformersEmbeddings {
|
|
|
89
91
|
const embeddings = Array.from(result.data) as number[];
|
|
90
92
|
return embeddings;
|
|
91
93
|
} catch (error) {
|
|
92
|
-
|
|
94
|
+
log.error('Error generating embeddings:', error);
|
|
93
95
|
throw new Error(
|
|
94
96
|
`Failed to generate embeddings: ${error instanceof Error ? error.message : String(error)}`
|
|
95
97
|
);
|
|
@@ -125,7 +127,7 @@ export class SentenceTransformersEmbeddings {
|
|
|
125
127
|
|
|
126
128
|
// Log progress for large batches
|
|
127
129
|
if (texts.length > batchSize) {
|
|
128
|
-
|
|
130
|
+
log.info(
|
|
129
131
|
`Processed ${Math.min(i + batchSize, texts.length)}/${texts.length} documents`
|
|
130
132
|
);
|
|
131
133
|
}
|
|
@@ -133,7 +135,7 @@ export class SentenceTransformersEmbeddings {
|
|
|
133
135
|
|
|
134
136
|
return embeddings;
|
|
135
137
|
} catch (error) {
|
|
136
|
-
|
|
138
|
+
log.error('Error generating document embeddings:', error);
|
|
137
139
|
throw new Error(
|
|
138
140
|
`Failed to generate document embeddings: ${error instanceof Error ? error.message : String(error)}`
|
|
139
141
|
);
|