@snap-agent/rag-ecommerce 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -273,7 +273,7 @@ MIT © ViloTech
273
273
  ## Support
274
274
 
275
275
  - [ViloTech]("https://vilotech.co")
276
+ - [SnapAgent SDK](https://github.com/vilotech/snap-agent)
276
277
  - [Documentation](../../sdk/README.md)
277
278
  - [GitHub Issues](https://github.com/vilotech/snap-agent/issues)
278
- - [SnapAgent SDK](https://github.com/vilotech/snap-agent)
279
279
 
package/dist/index.d.mts CHANGED
@@ -127,8 +127,8 @@ declare class EcommerceRAGPlugin implements RAGPlugin {
127
127
  /**
128
128
  * Main retrieval method - called by the SDK
129
129
  */
130
- retrieveContext(message: string, options: {
131
- agentId: string;
130
+ retrieveContext(message: string, options?: {
131
+ agentId?: string;
132
132
  threadId?: string;
133
133
  filters?: Record<string, any>;
134
134
  metadata?: Record<string, any>;
package/dist/index.d.ts CHANGED
@@ -127,8 +127,8 @@ declare class EcommerceRAGPlugin implements RAGPlugin {
127
127
  /**
128
128
  * Main retrieval method - called by the SDK
129
129
  */
130
- retrieveContext(message: string, options: {
131
- agentId: string;
130
+ retrieveContext(message: string, options?: {
131
+ agentId?: string;
132
132
  threadId?: string;
133
133
  filters?: Record<string, any>;
134
134
  metadata?: Record<string, any>;
package/dist/index.js CHANGED
@@ -116,7 +116,7 @@ var EcommerceRAGPlugin = class {
116
116
  /**
117
117
  * Main retrieval method - called by the SDK
118
118
  */
119
- async retrieveContext(message, options) {
119
+ async retrieveContext(message, options = {}) {
120
120
  const queryVector = await this.embedText(message);
121
121
  let attributes = {};
122
122
  if (this.config.enableAttributeExtraction) {
@@ -124,7 +124,7 @@ var EcommerceRAGPlugin = class {
124
124
  }
125
125
  const searchResults = await this.vectorSearch({
126
126
  queryVector,
127
- agentId: options.agentId,
127
+ ...options.agentId && { agentId: options.agentId },
128
128
  hardFilters: options.filters || {}
129
129
  });
130
130
  const rescored = this.softRescore(searchResults, attributes);
@@ -297,7 +297,11 @@ var EcommerceRAGPlugin = class {
297
297
  const collection = db.collection(this.config.collection);
298
298
  const filter = { tenantId: this.config.tenantId };
299
299
  if (options.agentId) {
300
- filter.agentId = options.agentId;
300
+ filter.$or = [
301
+ { agentId: { $exists: false } },
302
+ { agentId: null },
303
+ { agentId: options.agentId }
304
+ ];
301
305
  }
302
306
  Object.entries(options.hardFilters).forEach(([key, value]) => {
303
307
  if (value !== void 0 && value !== null) {
@@ -551,7 +555,9 @@ ${productBlocks.join("\n\n")}`;
551
555
  const metadata = doc.metadata || {};
552
556
  return {
553
557
  tenantId: this.config.tenantId,
554
- agentId: options?.agentId,
558
+ // Only set agentId if explicitly provided (agent-specific product)
559
+ // Products without agentId are shared across all agents in tenant
560
+ ...options?.agentId ? { agentId: options.agentId } : {},
555
561
  sku: doc.id,
556
562
  title: metadata.title || doc.content.substring(0, 100),
557
563
  description: metadata.description || doc.content,
@@ -578,7 +584,8 @@ ${productBlocks.join("\n\n")}`;
578
584
  filter: {
579
585
  tenantId: this.config.tenantId,
580
586
  sku: doc.sku,
581
- ...options.agentId ? { agentId: options.agentId } : {}
587
+ // Match by agentId if provided (for agent-specific products)
588
+ ...options.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
582
589
  },
583
590
  replacement: doc,
584
591
  upsert: true
@@ -590,7 +597,8 @@ ${productBlocks.join("\n\n")}`;
590
597
  const existingSkus = await collection.find({
591
598
  tenantId: this.config.tenantId,
592
599
  sku: { $in: productDocs.map((d) => d.sku) },
593
- ...options.agentId ? { agentId: options.agentId } : {}
600
+ // Check for matching products (shared or agent-specific)
601
+ ...options.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
594
602
  }).project({ sku: 1 }).toArray();
595
603
  const existingSet = new Set(existingSkus.map((d) => d.sku));
596
604
  const newDocs = productDocs.filter((d) => !existingSet.has(d.sku));
@@ -605,7 +613,8 @@ ${productBlocks.join("\n\n")}`;
605
613
  filter: {
606
614
  tenantId: this.config.tenantId,
607
615
  sku: doc.sku,
608
- ...options?.agentId ? { agentId: options.agentId } : {}
616
+ // Match by agentId if provided (for agent-specific products)
617
+ ...options?.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
609
618
  },
610
619
  update: { $set: doc },
611
620
  upsert: true
@@ -694,7 +703,8 @@ ${productBlocks.join("\n\n")}`;
694
703
  {
695
704
  tenantId: this.config.tenantId,
696
705
  sku: id,
697
- ...options?.agentId ? { agentId: options.agentId } : {}
706
+ // Match by agentId if provided, otherwise match shared products
707
+ ...options?.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
698
708
  },
699
709
  { $set: update }
700
710
  );
@@ -708,7 +718,8 @@ ${productBlocks.join("\n\n")}`;
708
718
  const result = await collection.deleteMany({
709
719
  tenantId: this.config.tenantId,
710
720
  sku: { $in: skuArray },
711
- ...options?.agentId ? { agentId: options.agentId } : {}
721
+ // Match by agentId if provided, otherwise match shared products
722
+ ...options?.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
712
723
  });
713
724
  return result.deletedCount;
714
725
  }
package/dist/index.mjs CHANGED
@@ -80,7 +80,7 @@ var EcommerceRAGPlugin = class {
80
80
  /**
81
81
  * Main retrieval method - called by the SDK
82
82
  */
83
- async retrieveContext(message, options) {
83
+ async retrieveContext(message, options = {}) {
84
84
  const queryVector = await this.embedText(message);
85
85
  let attributes = {};
86
86
  if (this.config.enableAttributeExtraction) {
@@ -88,7 +88,7 @@ var EcommerceRAGPlugin = class {
88
88
  }
89
89
  const searchResults = await this.vectorSearch({
90
90
  queryVector,
91
- agentId: options.agentId,
91
+ ...options.agentId && { agentId: options.agentId },
92
92
  hardFilters: options.filters || {}
93
93
  });
94
94
  const rescored = this.softRescore(searchResults, attributes);
@@ -261,7 +261,11 @@ var EcommerceRAGPlugin = class {
261
261
  const collection = db.collection(this.config.collection);
262
262
  const filter = { tenantId: this.config.tenantId };
263
263
  if (options.agentId) {
264
- filter.agentId = options.agentId;
264
+ filter.$or = [
265
+ { agentId: { $exists: false } },
266
+ { agentId: null },
267
+ { agentId: options.agentId }
268
+ ];
265
269
  }
266
270
  Object.entries(options.hardFilters).forEach(([key, value]) => {
267
271
  if (value !== void 0 && value !== null) {
@@ -515,7 +519,9 @@ ${productBlocks.join("\n\n")}`;
515
519
  const metadata = doc.metadata || {};
516
520
  return {
517
521
  tenantId: this.config.tenantId,
518
- agentId: options?.agentId,
522
+ // Only set agentId if explicitly provided (agent-specific product)
523
+ // Products without agentId are shared across all agents in tenant
524
+ ...options?.agentId ? { agentId: options.agentId } : {},
519
525
  sku: doc.id,
520
526
  title: metadata.title || doc.content.substring(0, 100),
521
527
  description: metadata.description || doc.content,
@@ -542,7 +548,8 @@ ${productBlocks.join("\n\n")}`;
542
548
  filter: {
543
549
  tenantId: this.config.tenantId,
544
550
  sku: doc.sku,
545
- ...options.agentId ? { agentId: options.agentId } : {}
551
+ // Match by agentId if provided (for agent-specific products)
552
+ ...options.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
546
553
  },
547
554
  replacement: doc,
548
555
  upsert: true
@@ -554,7 +561,8 @@ ${productBlocks.join("\n\n")}`;
554
561
  const existingSkus = await collection.find({
555
562
  tenantId: this.config.tenantId,
556
563
  sku: { $in: productDocs.map((d) => d.sku) },
557
- ...options.agentId ? { agentId: options.agentId } : {}
564
+ // Check for matching products (shared or agent-specific)
565
+ ...options.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
558
566
  }).project({ sku: 1 }).toArray();
559
567
  const existingSet = new Set(existingSkus.map((d) => d.sku));
560
568
  const newDocs = productDocs.filter((d) => !existingSet.has(d.sku));
@@ -569,7 +577,8 @@ ${productBlocks.join("\n\n")}`;
569
577
  filter: {
570
578
  tenantId: this.config.tenantId,
571
579
  sku: doc.sku,
572
- ...options?.agentId ? { agentId: options.agentId } : {}
580
+ // Match by agentId if provided (for agent-specific products)
581
+ ...options?.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
573
582
  },
574
583
  update: { $set: doc },
575
584
  upsert: true
@@ -658,7 +667,8 @@ ${productBlocks.join("\n\n")}`;
658
667
  {
659
668
  tenantId: this.config.tenantId,
660
669
  sku: id,
661
- ...options?.agentId ? { agentId: options.agentId } : {}
670
+ // Match by agentId if provided, otherwise match shared products
671
+ ...options?.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
662
672
  },
663
673
  { $set: update }
664
674
  );
@@ -672,7 +682,8 @@ ${productBlocks.join("\n\n")}`;
672
682
  const result = await collection.deleteMany({
673
683
  tenantId: this.config.tenantId,
674
684
  sku: { $in: skuArray },
675
- ...options?.agentId ? { agentId: options.agentId } : {}
685
+ // Match by agentId if provided, otherwise match shared products
686
+ ...options?.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
676
687
  });
677
688
  return result.deletedCount;
678
689
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snap-agent/rag-ecommerce",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "E-commerce RAG plugin for SnapAgent SDK - Product search with vector embeddings",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -17,6 +17,11 @@
17
17
  "README.md",
18
18
  "LICENSE"
19
19
  ],
20
+ "scripts": {
21
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
22
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
23
+ "prepublishOnly": "npm run build"
24
+ },
20
25
  "keywords": [
21
26
  "rag",
22
27
  "ecommerce",
@@ -49,9 +54,5 @@
49
54
  "homepage": "https://github.com/vilo-hq/snap-agent/tree/main/plugins/rag/ecommerce",
50
55
  "bugs": {
51
56
  "url": "https://github.com/vilo-hq/snap-agent/issues"
52
- },
53
- "scripts": {
54
- "build": "tsup src/index.ts --format cjs,esm --dts --clean",
55
- "dev": "tsup src/index.ts --format cjs,esm --dts --watch"
56
57
  }
57
- }
58
+ }