@peopl-health/nexus 1.5.6 → 1.5.8

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.
@@ -86,7 +86,7 @@ async function generatePresignedUrl(bucketName, key, expiration = 300) {
86
86
  };
87
87
 
88
88
  try {
89
- const url = s3.getSignedUrlPromise('getObject', params);
89
+ const url = await s3.getSignedUrlPromise('getObject', params);
90
90
  console.log(`Presigned URL generated: ${url}`);
91
91
  return url;
92
92
  } catch (error) {
@@ -1,3 +1,28 @@
1
+ const runtimeConfig = require('./runtimeConfig');
2
+
3
+ let anthropicClient = null;
4
+
5
+ const resolveAnthropicClient = () => {
6
+ if (anthropicClient) return anthropicClient;
7
+
8
+ const apiKey = runtimeConfig.get('ANTHROPIC_API_KEY') || process.env.ANTHROPIC_API_KEY;
9
+ if (!apiKey) return null;
10
+
11
+ try {
12
+ const { Anthropic } = require('@anthropic-ai/sdk');
13
+ anthropicClient = new Anthropic({ apiKey });
14
+ console.log('[llmConfig] Anthropic client initialised');
15
+ } catch (error) {
16
+ console.warn('[llmConfig] Failed to initialise Anthropic client. Install @anthropic-ai/sdk if you plan to use vision features.', error?.message || error);
17
+ anthropicClient = null;
18
+ }
19
+
20
+ return anthropicClient;
21
+ };
22
+
1
23
  module.exports = {
2
- openaiClient: null
24
+ openaiClient: null,
25
+ get anthropicClient() {
26
+ return resolveAnthropicClient();
27
+ }
3
28
  };
@@ -211,18 +211,23 @@ async function processMessage(code, reply, thread) {
211
211
  continue;
212
212
  }
213
213
  if (fileName.includes('image') || fileName.includes('document') || fileName.includes('application')) {
214
- const imageAnalysis = await analyzeImage(fileName);
214
+ let imageAnalysis = null;
215
+ try {
216
+ imageAnalysis = await analyzeImage(fileName);
217
+ } catch (error) {
218
+ console.warn('[assistantHelper] analyzeImage failed:', error?.message || error);
219
+ }
215
220
  console.log(imageAnalysis);
216
221
  const invalidAnalysis = ['NOT_MEDICAL', 'QUALITY_INSUFFICIENT'];
217
- if (imageAnalysis.medical_relevance) {
222
+ if (imageAnalysis?.medical_relevance) {
218
223
  url = await generatePresignedUrl(reply.media.bucketName, reply.media.key);
219
224
  }
220
- if (imageAnalysis.has_table) {
225
+ if (imageAnalysis?.has_table && imageAnalysis.table_data) {
221
226
  messagesChat.push({
222
227
  type: 'text',
223
228
  text: imageAnalysis.table_data,
224
229
  });
225
- } else if (!invalidAnalysis.some(tag => imageAnalysis.medical_analysis.includes(tag))) {
230
+ } else if (imageAnalysis?.medical_analysis && !invalidAnalysis.some(tag => imageAnalysis.medical_analysis.includes(tag))) {
226
231
  messagesChat.push({
227
232
  type: 'text',
228
233
  text: imageAnalysis.medical_analysis,
@@ -1,10 +1,21 @@
1
- const { anthropicClient } = require('../config/llmConfig.js');
1
+ const llmConfig = require('../config/llmConfig.js');
2
2
  const fs = require('fs');
3
3
  const mime = require('mime-types');
4
4
 
5
5
 
6
6
  async function analyzeImage(imagePath) {
7
7
  try {
8
+ const anthropicClient = llmConfig.anthropicClient;
9
+ if (!anthropicClient || !anthropicClient.messages) {
10
+ console.warn('[llmsHelper] Anthropics client not configured; skipping image analysis');
11
+ return {
12
+ medical_analysis: 'QUALITY_INSUFFICIENT',
13
+ medical_relevance: false,
14
+ has_table: false,
15
+ table_data: null
16
+ };
17
+ }
18
+
8
19
  // Skip WBMP images and stickers
9
20
  if (imagePath.toLowerCase().includes('.wbmp') || imagePath.toLowerCase().includes('sticker')) {
10
21
  console.log('Skipping WBMP image or sticker analysis:', imagePath);
package/package.json CHANGED
@@ -1,12 +1,26 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "1.5.6",
3
+ "version": "1.5.8",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
- "publishConfig": {
6
- "access": "public"
5
+ "keywords": [
6
+ "whatsapp",
7
+ "messaging",
8
+ "ai-assistant",
9
+ "twilio",
10
+ "baileys",
11
+ "communication"
12
+ ],
13
+ "homepage": "https://github.com/peopl-health/nexus#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/peopl-health/nexus/issues"
7
16
  },
8
- "main": "lib/index.js",
9
- "types": "lib/index.d.ts",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/peopl-health/nexus.git"
20
+ },
21
+ "license": "MIT",
22
+ "author": "PEOPL Health Tech",
23
+ "type": "commonjs",
10
24
  "exports": {
11
25
  ".": {
12
26
  "import": "./lib/index.js",
@@ -30,6 +44,21 @@
30
44
  "require": "./lib/routes/index.js"
31
45
  }
32
46
  },
47
+ "main": "lib/index.js",
48
+ "types": "lib/index.d.ts",
49
+ "directories": {
50
+ "example": "examples",
51
+ "lib": "lib",
52
+ "test": "test"
53
+ },
54
+ "files": [
55
+ "lib/",
56
+ "examples/",
57
+ "README.md",
58
+ "LICENSE",
59
+ "CHANGELOG.md",
60
+ "MIGRATION_GUIDE.md"
61
+ ],
33
62
  "scripts": {
34
63
  "build": "tsc",
35
64
  "dev": "tsc --watch",
@@ -40,16 +69,6 @@
40
69
  "version": "npm run prepublishOnly && git add -A lib",
41
70
  "postversion": "git push && git push --tags"
42
71
  },
43
- "keywords": [
44
- "whatsapp",
45
- "messaging",
46
- "ai-assistant",
47
- "twilio",
48
- "baileys",
49
- "communication"
50
- ],
51
- "author": "PEOPL Health Tech",
52
- "license": "MIT",
53
72
  "dependencies": {
54
73
  "airtable": "^0.12.2",
55
74
  "aws-sdk": "2.1674.0",
@@ -63,12 +82,6 @@
63
82
  "pino-pretty": "^10.2.0",
64
83
  "uuid": "^9.0.0"
65
84
  },
66
- "peerDependencies": {
67
- "baileys": "^6.4.0",
68
- "express": "4.21.2",
69
- "openai": "^4.0.0",
70
- "twilio": "5.6.0"
71
- },
72
85
  "devDependencies": {
73
86
  "@types/node": "^20.5.0",
74
87
  "eslint": "^8.47.0",
@@ -76,19 +89,17 @@
76
89
  "sharp": "0.32.6",
77
90
  "typescript": "^5.1.6"
78
91
  },
92
+ "peerDependencies": {
93
+ "baileys": "^6.4.0",
94
+ "express": "4.21.2",
95
+ "openai": "^4.0.0",
96
+ "twilio": "5.6.0",
97
+ "@anthropic-ai/sdk": "^0.32.0"
98
+ },
79
99
  "engines": {
80
100
  "node": ">=20.0.0"
81
101
  },
82
- "repository": {
83
- "type": "git",
84
- "url": "https://github.com/peopl-health/nexus.git"
85
- },
86
- "files": [
87
- "lib/",
88
- "examples/",
89
- "README.md",
90
- "LICENSE",
91
- "CHANGELOG.md",
92
- "MIGRATION_GUIDE.md"
93
- ]
102
+ "publishConfig": {
103
+ "access": "public"
104
+ }
94
105
  }