@snap-agent/rag-ecommerce 0.1.2 → 0.1.3

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/dist/index.js CHANGED
@@ -297,11 +297,7 @@ 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.$or = [
301
- { agentId: { $exists: false } },
302
- { agentId: null },
303
- { agentId: options.agentId }
304
- ];
300
+ filter.agentId = { $in: ["shared", options.agentId] };
305
301
  }
306
302
  Object.entries(options.hardFilters).forEach(([key, value]) => {
307
303
  if (value !== void 0 && value !== null) {
@@ -555,9 +551,8 @@ ${productBlocks.join("\n\n")}`;
555
551
  const metadata = doc.metadata || {};
556
552
  return {
557
553
  tenantId: this.config.tenantId,
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 } : {},
554
+ // Use 'shared' marker for tenant-wide products, specific agentId for agent-only
555
+ agentId: options?.agentId || "shared",
561
556
  sku: doc.id,
562
557
  title: metadata.title || doc.content.substring(0, 100),
563
558
  description: metadata.description || doc.content,
@@ -584,8 +579,8 @@ ${productBlocks.join("\n\n")}`;
584
579
  filter: {
585
580
  tenantId: this.config.tenantId,
586
581
  sku: doc.sku,
587
- // Match by agentId if provided (for agent-specific products)
588
- ...options.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
582
+ // Match by agentId ('shared' for tenant-wide, specific for agent-only)
583
+ agentId: options.agentId || "shared"
589
584
  },
590
585
  replacement: doc,
591
586
  upsert: true
@@ -597,8 +592,8 @@ ${productBlocks.join("\n\n")}`;
597
592
  const existingSkus = await collection.find({
598
593
  tenantId: this.config.tenantId,
599
594
  sku: { $in: productDocs.map((d) => d.sku) },
600
- // Check for matching products (shared or agent-specific)
601
- ...options.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
595
+ // Match by agentId ('shared' for tenant-wide, specific for agent-only)
596
+ agentId: options.agentId || "shared"
602
597
  }).project({ sku: 1 }).toArray();
603
598
  const existingSet = new Set(existingSkus.map((d) => d.sku));
604
599
  const newDocs = productDocs.filter((d) => !existingSet.has(d.sku));
@@ -613,8 +608,8 @@ ${productBlocks.join("\n\n")}`;
613
608
  filter: {
614
609
  tenantId: this.config.tenantId,
615
610
  sku: doc.sku,
616
- // Match by agentId if provided (for agent-specific products)
617
- ...options?.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
611
+ // Match by agentId ('shared' for tenant-wide, specific for agent-only)
612
+ agentId: options?.agentId || "shared"
618
613
  },
619
614
  update: { $set: doc },
620
615
  upsert: true
@@ -703,8 +698,8 @@ ${productBlocks.join("\n\n")}`;
703
698
  {
704
699
  tenantId: this.config.tenantId,
705
700
  sku: id,
706
- // Match by agentId if provided, otherwise match shared products
707
- ...options?.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
701
+ // Match by agentId ('shared' for tenant-wide, specific for agent-only)
702
+ agentId: options?.agentId || "shared"
708
703
  },
709
704
  { $set: update }
710
705
  );
@@ -718,8 +713,8 @@ ${productBlocks.join("\n\n")}`;
718
713
  const result = await collection.deleteMany({
719
714
  tenantId: this.config.tenantId,
720
715
  sku: { $in: skuArray },
721
- // Match by agentId if provided, otherwise match shared products
722
- ...options?.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
716
+ // Match by agentId ('shared' for tenant-wide, specific for agent-only)
717
+ agentId: options?.agentId || "shared"
723
718
  });
724
719
  return result.deletedCount;
725
720
  }
package/dist/index.mjs CHANGED
@@ -261,11 +261,7 @@ 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.$or = [
265
- { agentId: { $exists: false } },
266
- { agentId: null },
267
- { agentId: options.agentId }
268
- ];
264
+ filter.agentId = { $in: ["shared", options.agentId] };
269
265
  }
270
266
  Object.entries(options.hardFilters).forEach(([key, value]) => {
271
267
  if (value !== void 0 && value !== null) {
@@ -519,9 +515,8 @@ ${productBlocks.join("\n\n")}`;
519
515
  const metadata = doc.metadata || {};
520
516
  return {
521
517
  tenantId: this.config.tenantId,
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 } : {},
518
+ // Use 'shared' marker for tenant-wide products, specific agentId for agent-only
519
+ agentId: options?.agentId || "shared",
525
520
  sku: doc.id,
526
521
  title: metadata.title || doc.content.substring(0, 100),
527
522
  description: metadata.description || doc.content,
@@ -548,8 +543,8 @@ ${productBlocks.join("\n\n")}`;
548
543
  filter: {
549
544
  tenantId: this.config.tenantId,
550
545
  sku: doc.sku,
551
- // Match by agentId if provided (for agent-specific products)
552
- ...options.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
546
+ // Match by agentId ('shared' for tenant-wide, specific for agent-only)
547
+ agentId: options.agentId || "shared"
553
548
  },
554
549
  replacement: doc,
555
550
  upsert: true
@@ -561,8 +556,8 @@ ${productBlocks.join("\n\n")}`;
561
556
  const existingSkus = await collection.find({
562
557
  tenantId: this.config.tenantId,
563
558
  sku: { $in: productDocs.map((d) => d.sku) },
564
- // Check for matching products (shared or agent-specific)
565
- ...options.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
559
+ // Match by agentId ('shared' for tenant-wide, specific for agent-only)
560
+ agentId: options.agentId || "shared"
566
561
  }).project({ sku: 1 }).toArray();
567
562
  const existingSet = new Set(existingSkus.map((d) => d.sku));
568
563
  const newDocs = productDocs.filter((d) => !existingSet.has(d.sku));
@@ -577,8 +572,8 @@ ${productBlocks.join("\n\n")}`;
577
572
  filter: {
578
573
  tenantId: this.config.tenantId,
579
574
  sku: doc.sku,
580
- // Match by agentId if provided (for agent-specific products)
581
- ...options?.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
575
+ // Match by agentId ('shared' for tenant-wide, specific for agent-only)
576
+ agentId: options?.agentId || "shared"
582
577
  },
583
578
  update: { $set: doc },
584
579
  upsert: true
@@ -667,8 +662,8 @@ ${productBlocks.join("\n\n")}`;
667
662
  {
668
663
  tenantId: this.config.tenantId,
669
664
  sku: id,
670
- // Match by agentId if provided, otherwise match shared products
671
- ...options?.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
665
+ // Match by agentId ('shared' for tenant-wide, specific for agent-only)
666
+ agentId: options?.agentId || "shared"
672
667
  },
673
668
  { $set: update }
674
669
  );
@@ -682,8 +677,8 @@ ${productBlocks.join("\n\n")}`;
682
677
  const result = await collection.deleteMany({
683
678
  tenantId: this.config.tenantId,
684
679
  sku: { $in: skuArray },
685
- // Match by agentId if provided, otherwise match shared products
686
- ...options?.agentId ? { agentId: options.agentId } : { agentId: { $exists: false } }
680
+ // Match by agentId ('shared' for tenant-wide, specific for agent-only)
681
+ agentId: options?.agentId || "shared"
687
682
  });
688
683
  return result.deletedCount;
689
684
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snap-agent/rag-ecommerce",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
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",