@rahul_vendure/ai-chat-plugin 0.1.0

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.
Files changed (134) hide show
  1. package/README.md +214 -0
  2. package/dist/ai-assistant.plugin.d.ts +18 -0
  3. package/dist/ai-assistant.plugin.d.ts.map +1 -0
  4. package/dist/ai-assistant.plugin.js +86 -0
  5. package/dist/ai-assistant.plugin.js.map +1 -0
  6. package/dist/api/ai-assistant.resolver.d.ts +11 -0
  7. package/dist/api/ai-assistant.resolver.d.ts.map +1 -0
  8. package/dist/api/ai-assistant.resolver.js +43 -0
  9. package/dist/api/ai-assistant.resolver.js.map +1 -0
  10. package/dist/api/schema-extensions.d.ts +3 -0
  11. package/dist/api/schema-extensions.d.ts.map +1 -0
  12. package/dist/api/schema-extensions.js +15 -0
  13. package/dist/api/schema-extensions.js.map +1 -0
  14. package/dist/constants.d.ts +41 -0
  15. package/dist/constants.d.ts.map +1 -0
  16. package/dist/constants.js +24 -0
  17. package/dist/constants.js.map +1 -0
  18. package/dist/controllers/admin-chat.controller.d.ts +21 -0
  19. package/dist/controllers/admin-chat.controller.d.ts.map +1 -0
  20. package/dist/controllers/admin-chat.controller.js +64 -0
  21. package/dist/controllers/admin-chat.controller.js.map +1 -0
  22. package/dist/controllers/ai-assistant.controller.d.ts +96 -0
  23. package/dist/controllers/ai-assistant.controller.d.ts.map +1 -0
  24. package/dist/controllers/ai-assistant.controller.js +272 -0
  25. package/dist/controllers/ai-assistant.controller.js.map +1 -0
  26. package/dist/entities/collection-embedding.entity.d.ts +13 -0
  27. package/dist/entities/collection-embedding.entity.d.ts.map +1 -0
  28. package/dist/entities/collection-embedding.entity.js +43 -0
  29. package/dist/entities/collection-embedding.entity.js.map +1 -0
  30. package/dist/entities/product-embedding.entity.d.ts +14 -0
  31. package/dist/entities/product-embedding.entity.d.ts.map +1 -0
  32. package/dist/entities/product-embedding.entity.js +44 -0
  33. package/dist/entities/product-embedding.entity.js.map +1 -0
  34. package/dist/entities/variant-embedding.entity.d.ts +13 -0
  35. package/dist/entities/variant-embedding.entity.d.ts.map +1 -0
  36. package/dist/entities/variant-embedding.entity.js +43 -0
  37. package/dist/entities/variant-embedding.entity.js.map +1 -0
  38. package/dist/handlers/collection-embedding-handler.d.ts +18 -0
  39. package/dist/handlers/collection-embedding-handler.d.ts.map +1 -0
  40. package/dist/handlers/collection-embedding-handler.js +90 -0
  41. package/dist/handlers/collection-embedding-handler.js.map +1 -0
  42. package/dist/handlers/product-embedding-handler.d.ts +20 -0
  43. package/dist/handlers/product-embedding-handler.d.ts.map +1 -0
  44. package/dist/handlers/product-embedding-handler.js +96 -0
  45. package/dist/handlers/product-embedding-handler.js.map +1 -0
  46. package/dist/handlers/variant-embedding-handler.d.ts +19 -0
  47. package/dist/handlers/variant-embedding-handler.d.ts.map +1 -0
  48. package/dist/handlers/variant-embedding-handler.js +101 -0
  49. package/dist/handlers/variant-embedding-handler.js.map +1 -0
  50. package/dist/index.d.ts +23 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +33 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/services/admin-ai-chat.service.d.ts +40 -0
  55. package/dist/services/admin-ai-chat.service.d.ts.map +1 -0
  56. package/dist/services/admin-ai-chat.service.js +201 -0
  57. package/dist/services/admin-ai-chat.service.js.map +1 -0
  58. package/dist/services/admin-system-prompt.d.ts +2 -0
  59. package/dist/services/admin-system-prompt.d.ts.map +1 -0
  60. package/dist/services/admin-system-prompt.js +44 -0
  61. package/dist/services/admin-system-prompt.js.map +1 -0
  62. package/dist/services/admin-tools/admin-collection-tools.d.ts +15 -0
  63. package/dist/services/admin-tools/admin-collection-tools.d.ts.map +1 -0
  64. package/dist/services/admin-tools/admin-collection-tools.js +48 -0
  65. package/dist/services/admin-tools/admin-collection-tools.js.map +1 -0
  66. package/dist/services/admin-tools/admin-customer-tools.d.ts +15 -0
  67. package/dist/services/admin-tools/admin-customer-tools.d.ts.map +1 -0
  68. package/dist/services/admin-tools/admin-customer-tools.js +56 -0
  69. package/dist/services/admin-tools/admin-customer-tools.js.map +1 -0
  70. package/dist/services/admin-tools/admin-order-tools.d.ts +16 -0
  71. package/dist/services/admin-tools/admin-order-tools.d.ts.map +1 -0
  72. package/dist/services/admin-tools/admin-order-tools.js +69 -0
  73. package/dist/services/admin-tools/admin-order-tools.js.map +1 -0
  74. package/dist/services/admin-tools/admin-product-tools.d.ts +29 -0
  75. package/dist/services/admin-tools/admin-product-tools.d.ts.map +1 -0
  76. package/dist/services/admin-tools/admin-product-tools.js +139 -0
  77. package/dist/services/admin-tools/admin-product-tools.js.map +1 -0
  78. package/dist/services/ai-chat.service.d.ts +42 -0
  79. package/dist/services/ai-chat.service.d.ts.map +1 -0
  80. package/dist/services/ai-chat.service.js +308 -0
  81. package/dist/services/ai-chat.service.js.map +1 -0
  82. package/dist/services/chat-result-mapper.d.ts +17 -0
  83. package/dist/services/chat-result-mapper.d.ts.map +1 -0
  84. package/dist/services/chat-result-mapper.js +176 -0
  85. package/dist/services/chat-result-mapper.js.map +1 -0
  86. package/dist/services/collection-embedding.service.d.ts +14 -0
  87. package/dist/services/collection-embedding.service.d.ts.map +1 -0
  88. package/dist/services/collection-embedding.service.js +67 -0
  89. package/dist/services/collection-embedding.service.js.map +1 -0
  90. package/dist/services/conversation-cache.service.d.ts +47 -0
  91. package/dist/services/conversation-cache.service.d.ts.map +1 -0
  92. package/dist/services/conversation-cache.service.js +87 -0
  93. package/dist/services/conversation-cache.service.js.map +1 -0
  94. package/dist/services/embed-all-job.service.d.ts +28 -0
  95. package/dist/services/embed-all-job.service.d.ts.map +1 -0
  96. package/dist/services/embed-all-job.service.js +151 -0
  97. package/dist/services/embed-all-job.service.js.map +1 -0
  98. package/dist/services/embedding.service.d.ts +21 -0
  99. package/dist/services/embedding.service.d.ts.map +1 -0
  100. package/dist/services/embedding.service.js +58 -0
  101. package/dist/services/embedding.service.js.map +1 -0
  102. package/dist/services/product-embedding.service.d.ts +19 -0
  103. package/dist/services/product-embedding.service.d.ts.map +1 -0
  104. package/dist/services/product-embedding.service.js +78 -0
  105. package/dist/services/product-embedding.service.js.map +1 -0
  106. package/dist/services/system-prompt.d.ts +2 -0
  107. package/dist/services/system-prompt.d.ts.map +1 -0
  108. package/dist/services/system-prompt.js +107 -0
  109. package/dist/services/system-prompt.js.map +1 -0
  110. package/dist/services/tools/cart-tools.d.ts +14 -0
  111. package/dist/services/tools/cart-tools.d.ts.map +1 -0
  112. package/dist/services/tools/cart-tools.js +168 -0
  113. package/dist/services/tools/cart-tools.js.map +1 -0
  114. package/dist/services/tools/checkout-tools.d.ts +37 -0
  115. package/dist/services/tools/checkout-tools.d.ts.map +1 -0
  116. package/dist/services/tools/checkout-tools.js +228 -0
  117. package/dist/services/tools/checkout-tools.js.map +1 -0
  118. package/dist/services/tools/order-tools.d.ts +15 -0
  119. package/dist/services/tools/order-tools.d.ts.map +1 -0
  120. package/dist/services/tools/order-tools.js +105 -0
  121. package/dist/services/tools/order-tools.js.map +1 -0
  122. package/dist/services/tools/search-tools.d.ts +21 -0
  123. package/dist/services/tools/search-tools.d.ts.map +1 -0
  124. package/dist/services/tools/search-tools.js +214 -0
  125. package/dist/services/tools/search-tools.js.map +1 -0
  126. package/dist/services/types.d.ts +118 -0
  127. package/dist/services/types.d.ts.map +1 -0
  128. package/dist/services/types.js +3 -0
  129. package/dist/services/types.js.map +1 -0
  130. package/dist/services/variant-embedding.service.d.ts +14 -0
  131. package/dist/services/variant-embedding.service.d.ts.map +1 -0
  132. package/dist/services/variant-embedding.service.js +59 -0
  133. package/dist/services/variant-embedding.service.js.map +1 -0
  134. package/package.json +57 -0
@@ -0,0 +1,21 @@
1
+ import type { AiAssistantPluginOptions } from '../constants';
2
+ export interface EmbeddingOptions {
3
+ openaiApiKey: string;
4
+ /** Model name, e.g. 'text-embedding-3-small' (default) or 'text-embedding-3-large' */
5
+ model?: string;
6
+ }
7
+ /**
8
+ * Generates text embeddings using OpenAI's embedding API.
9
+ * Used to embed product name + description for semantic search.
10
+ */
11
+ export declare class EmbeddingService {
12
+ private client;
13
+ private model;
14
+ constructor(options: AiAssistantPluginOptions);
15
+ /**
16
+ * Generate embedding vector for the given text.
17
+ * @returns Array of numbers (e.g. 1536 dims for text-embedding-3-small)
18
+ */
19
+ embed(text: string): Promise<number[]>;
20
+ }
21
+ //# sourceMappingURL=embedding.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embedding.service.d.ts","sourceRoot":"","sources":["../../src/services/embedding.service.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAE7D,MAAM,WAAW,gBAAgB;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,sFAAsF;IACtF,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,qBACa,gBAAgB;IACzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAS;gBAGY,OAAO,EAAE,wBAAwB;IAMnE;;;OAGG;IACG,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAc/C"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.EmbeddingService = void 0;
19
+ const common_1 = require("@nestjs/common");
20
+ const openai_1 = __importDefault(require("openai"));
21
+ const constants_1 = require("../constants");
22
+ /**
23
+ * Generates text embeddings using OpenAI's embedding API.
24
+ * Used to embed product name + description for semantic search.
25
+ */
26
+ let EmbeddingService = class EmbeddingService {
27
+ constructor(options) {
28
+ var _a;
29
+ this.client = new openai_1.default({ apiKey: options.openaiApiKey });
30
+ this.model = (_a = options.embeddingModel) !== null && _a !== void 0 ? _a : 'text-embedding-3-small';
31
+ }
32
+ /**
33
+ * Generate embedding vector for the given text.
34
+ * @returns Array of numbers (e.g. 1536 dims for text-embedding-3-small)
35
+ */
36
+ async embed(text) {
37
+ var _a;
38
+ if (!(text === null || text === void 0 ? void 0 : text.trim())) {
39
+ throw new Error('EmbeddingService.embed: text is required');
40
+ }
41
+ const response = await this.client.embeddings.create({
42
+ model: this.model,
43
+ input: text.trim().slice(0, 8191), // model limit
44
+ });
45
+ const embedding = (_a = response.data[0]) === null || _a === void 0 ? void 0 : _a.embedding;
46
+ if (!embedding || !Array.isArray(embedding)) {
47
+ throw new Error('EmbeddingService.embed: no embedding in response');
48
+ }
49
+ return embedding;
50
+ }
51
+ };
52
+ exports.EmbeddingService = EmbeddingService;
53
+ exports.EmbeddingService = EmbeddingService = __decorate([
54
+ (0, common_1.Injectable)(),
55
+ __param(0, (0, common_1.Inject)(constants_1.AI_ASSISTANT_OPTIONS)),
56
+ __metadata("design:paramtypes", [Object])
57
+ ], EmbeddingService);
58
+ //# sourceMappingURL=embedding.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embedding.service.js","sourceRoot":"","sources":["../../src/services/embedding.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;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interface SimilarProductResult {
3
+ productId: number;
4
+ score: number;
5
+ }
6
+ /**
7
+ * Persists and queries product embeddings using pgvector (raw SQL).
8
+ * Table must have embedding vector(1536); migration creates it.
9
+ */
10
+ export declare class ProductEmbeddingService {
11
+ private connection;
12
+ constructor(connection: TransactionalConnection);
13
+ upsertEmbedding(ctx: RequestContext, productId: number, embedding: number[]): Promise<void>;
14
+ deleteByProductId(ctx: RequestContext, productId: number): Promise<void>;
15
+ findSimilar(ctx: RequestContext, queryEmbedding: number[], limit?: number, minScore?: number): Promise<SimilarProductResult[]>;
16
+ /** Ensure row exists (for migration that creates table with no embedding column initially). */
17
+ ensureRow(ctx: RequestContext, productId: number): Promise<void>;
18
+ }
19
+ //# sourceMappingURL=product-embedding.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product-embedding.service.d.ts","sourceRoot":"","sources":["../../src/services/product-embedding.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAGxE,MAAM,WAAW,oBAAoB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,qBACa,uBAAuB;IACpB,OAAO,CAAC,UAAU;gBAAV,UAAU,EAAE,uBAAuB;IAEjD,eAAe,CACjB,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EAAE,GACpB,OAAO,CAAC,IAAI,CAAC;IAWV,iBAAiB,CAAC,GAAG,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxE,WAAW,CACb,GAAG,EAAE,cAAc,EACnB,cAAc,EAAE,MAAM,EAAE,EACxB,KAAK,GAAE,MAAW,EAClB,QAAQ,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAwBlC,+FAA+F;IACzF,SAAS,CAAC,GAAG,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAQzE"}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ProductEmbeddingService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const core_1 = require("@vendure/core");
15
+ const product_embedding_entity_1 = require("../entities/product-embedding.entity");
16
+ /**
17
+ * Persists and queries product embeddings using pgvector (raw SQL).
18
+ * Table must have embedding vector(1536); migration creates it.
19
+ */
20
+ let ProductEmbeddingService = class ProductEmbeddingService {
21
+ constructor(connection) {
22
+ this.connection = connection;
23
+ }
24
+ async upsertEmbedding(ctx, productId, embedding) {
25
+ var _a;
26
+ await this.ensureRow(ctx, productId);
27
+ const conn = this.connection.rawConnection;
28
+ const vectorStr = toVectorStr(embedding);
29
+ const schema = (_a = conn.options.schema) !== null && _a !== void 0 ? _a : 'public';
30
+ await conn.query(`UPDATE ${schema}.product_embedding SET embedding = $1::vector, "updatedAt" = NOW() WHERE "productId" = $2`, [vectorStr, productId]);
31
+ }
32
+ async deleteByProductId(ctx, productId) {
33
+ const repo = this.connection.rawConnection.getRepository(product_embedding_entity_1.ProductEmbedding);
34
+ await repo.delete({ productId });
35
+ }
36
+ async findSimilar(ctx, queryEmbedding, limit = 10, minScore) {
37
+ var _a;
38
+ const conn = this.connection.rawConnection;
39
+ const vectorStr = toVectorStr(queryEmbedding);
40
+ const schema = (_a = conn.options.schema) !== null && _a !== void 0 ? _a : 'public';
41
+ const hasThreshold = minScore != null && minScore > 0;
42
+ const sql = hasThreshold
43
+ ? `SELECT "productId", 1 - (embedding <=> $1::vector) AS score
44
+ FROM ${schema}.product_embedding
45
+ WHERE embedding IS NOT NULL AND (1 - (embedding <=> $1::vector)) >= $3
46
+ ORDER BY embedding <=> $1::vector
47
+ LIMIT $2`
48
+ : `SELECT "productId", 1 - (embedding <=> $1::vector) AS score
49
+ FROM ${schema}.product_embedding
50
+ WHERE embedding IS NOT NULL
51
+ ORDER BY embedding <=> $1::vector
52
+ LIMIT $2`;
53
+ const params = hasThreshold ? [vectorStr, limit, minScore] : [vectorStr, limit];
54
+ const rows = await conn.query(sql, params);
55
+ return rows.map((r) => ({
56
+ productId: r.productId,
57
+ score: Number(r.score),
58
+ }));
59
+ }
60
+ /** Ensure row exists (for migration that creates table with no embedding column initially). */
61
+ async ensureRow(ctx, productId) {
62
+ const repo = this.connection.rawConnection.getRepository(product_embedding_entity_1.ProductEmbedding);
63
+ let row = await repo.findOne({ where: { productId } });
64
+ if (!row) {
65
+ row = repo.create({ productId });
66
+ await repo.save(row);
67
+ }
68
+ }
69
+ };
70
+ exports.ProductEmbeddingService = ProductEmbeddingService;
71
+ exports.ProductEmbeddingService = ProductEmbeddingService = __decorate([
72
+ (0, common_1.Injectable)(),
73
+ __metadata("design:paramtypes", [core_1.TransactionalConnection])
74
+ ], ProductEmbeddingService);
75
+ function toVectorStr(arr) {
76
+ return '[' + arr.map((n) => Number(n)).join(',') + ']';
77
+ }
78
+ //# sourceMappingURL=product-embedding.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product-embedding.service.js","sourceRoot":"","sources":["../../src/services/product-embedding.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,wC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,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const SYSTEM_PROMPT = "You are a friendly and helpful shopping assistant for our online store. Your job is to help customers find products, browse collections, manage their cart, view order history, and track their orders.\n\n## What you CAN do:\n- Help customers find products using search, semantic search, or browsing by collections\n- Answer questions about products (features, prices, availability based on tool data)\n- Help customers filter products by price/budget\n- Recommend products based on intent (e.g. \"gift for dad\", \"something for gaming\")\n- Greet customers, have polite small talk ONLY about shopping/store context\n- Answer questions about the store, shipping, returns (give general helpful answers)\n- Add items to the customer's cart when they ask\n- Show the customer their current cart and adjust quantities or remove items\n- Show the customer their order history\n- Track the status of their orders and provide fulfillment/tracking info\n\n## What you MUST NOT do:\n- Answer questions unrelated to the store (e.g. \"who is Elon Musk\", \"capital of France\", \"write me a poem\")\n- Make up or fabricate product information - ONLY use data from tool results\n- Discuss politics, celebrities, news, science, or any topic outside the store\n\n## How to handle off-topic questions:\nPolitely redirect: \"I'm your shopping assistant and can only help with store-related questions. Can I help you find a product instead?\"\n\n## Tool usage:\n- `searchProducts` \u2014 keyword search (e.g. \"laptop\", \"camera\", \"headphones\")\n- `vectorSearch` \u2014 intent/semantic search (e.g. \"gift for dad\", \"something romantic\")\n- `getCollections` \u2014 list product categories/collections\n- `filterByPrice` \u2014 filter by budget/price range\n- `addToCart` \u2014 add a product to the customer's cart\n- `getActiveOrder` \u2014 get the customer's current cart/active order with all line items (requires login)\n- `adjustOrderLine` \u2014 change the quantity of an item in the cart, or remove it by setting quantity to 0 (requires login)\n- `getOrderHistory` \u2014 show the customer's past orders (requires login)\n- `trackOrder` \u2014 get status and tracking info for an order (requires login)\n- `getAvailableCountries` \u2014 list countries available for shipping/billing addresses\n- `getEligibleShippingMethods` \u2014 get available shipping methods for the active order (after address is set)\n- `getEligiblePaymentMethods` \u2014 get available payment methods for the active order\n- `setShippingAddress` \u2014 set shipping address on the active order (requires login and active order)\n- `setBillingAddress` \u2014 set billing address on the active order (requires login and active order)\n- `setShippingMethod` \u2014 set shipping method on the active order (requires login and active order)\n\n## CRITICAL response rules for products:\n- When tools return product data, do NOT list product names, prices, or images in your text. The UI automatically renders product cards with images, names, prices, and \"Add to Cart\" buttons below your message.\n- Keep your text to a brief friendly comment like \"Here are some cameras I found!\" \u2014 NOT a detailed listing.\n- NEVER include markdown images (![...](url)) in your response.\n- NEVER list individual product names with prices. The product cards handle that.\n\n## CRITICAL rules for addToCart:\n- The variantId MUST be the EXACT numeric ID string from the MOST RECENT search results for that specific product (e.g. \"42\", \"15\", \"103\"). It is always a number.\n- NEVER fabricate or guess a variantId. If you are not 100% certain of the correct variantId, search for the product AGAIN first.\n- When the user says \"buy this\" or \"add this\", look at the MOST RECENTLY shown product results. Do NOT reuse variantIds from older search results for different products.\n- You may confirm ONCE: mention the product name, price, and ask about quantity. But if the user has ALREADY confirmed (said \"yes\", \"sure\", \"go ahead\", \"do it\", given a quantity, etc.), call addToCart IMMEDIATELY. NEVER ask for confirmation more than once.\n- Once confirmed, call addToCart with the exact variantId AND productName from the search results and the requested quantity.\n- If there is ANY ambiguity about WHICH product the user means, ASK. But if the product is clear and user said yes, just add it.\n- ALWAYS provide the productName parameter when calling addToCart so the backend can verify the correct product.\n\n## Rules for cart tools (getActiveOrder, adjustOrderLine):\n- Use `getActiveOrder` when the customer asks about their cart, what's in their cart, cart total, or wants to review before checkout.\n- **CRITICAL: ALWAYS call `getActiveOrder` every time the customer asks about their cart, even if you already showed it earlier in the conversation.** The customer may have modified their cart outside of this chat (e.g. on the cart page). NEVER rely on previous tool results for cart state \u2014 always fetch fresh data.\n- Use `adjustOrderLine` to change quantities or remove items. You need the orderLineId from getActiveOrder results.\n- When adjusting quantity, set the new absolute quantity (not a delta). To remove an item, set quantity to 0.\n- Always call `getActiveOrder` first if you don't already have the orderLineId from the conversation context.\n- When showing the cart, summarize each item: product name, quantity, and line price. Also mention the cart total.\n\n## Rules for order tools:\n- Use `getOrderHistory` when the customer asks about their past orders, recent purchases, or order history.\n- Use `trackOrder` when the customer asks about a specific order's status, tracking, or shipment.\n- When showing order history, summarize each order briefly: order code, status, total, and what they ordered.\n- When tracking an order, mention the order state, fulfillment status, tracking code (if available), and items.\n- If a customer says \"where's my order?\" or \"track my order\" without specifying which one, use getOrderHistory first to find their most recent order, then use trackOrder on that order.\n\n## Rules for checkout tools:\n- **IMPORTANT \u2014 Country codes:** ALWAYS call `getAvailableCountries` FIRST before setting any address. Only use country codes returned by that tool. If the customer gives a country name or code not in the list, tell them which countries are available and ask them to pick one. NEVER guess or assume a country code \u2014 the backend will reject invalid ones.\n- Use `setShippingAddress` when the customer provides their shipping address. Collect all required fields: fullName, streetLine1, city, province, postalCode, countryCode, phoneNumber. Ask for missing fields before calling.\n- Use `setBillingAddress` when the customer provides a billing address. If they say \"same as shipping\", use the same address data.\n- Use `getEligibleShippingMethods` after the shipping address is set to show available shipping options.\n- Use `setShippingMethod` with the id from getEligibleShippingMethods when the customer chooses a shipping option.\n- You CANNOT process payments directly. After shipping address, billing address, and shipping method are all set, call `getEligiblePaymentMethods` to show the customer their available payment options (e.g. \"You can pay with Credit Card or PayPal\"), then tell them: \"Head to the [checkout page](/checkout) to complete your payment.\" Do NOT attempt to handle payment in the chat.\n- Always ensure there is an active order before calling checkout tools. If no active order exists, suggest adding items first.\n- The typical checkout flow is: getAvailableCountries \u2192 set shipping address \u2192 (optionally) set billing address \u2192 get eligible shipping methods \u2192 set shipping method \u2192 getEligiblePaymentMethods \u2192 direct user to /checkout for payment.\n- If the customer asks \"how can I pay?\" or \"what payment methods do you accept?\" at any point, call `getEligiblePaymentMethods` to answer.\n\n## IMPORTANT \u2014 matching products from conversation context:\n- When the user refers to a product that was ALREADY shown in the MOST RECENT search results, use the variantId from that specific search. Do NOT reuse variantIds from older/different searches.\n- If the user switches topics to a different product, ALWAYS search again to get the correct variantId for the new product. Do NOT mix up variantIds between different products.\n- Users will often use partial names, abbreviations, or slightly different wording. For example:\n - \"the wooden desk\" \u2192 matches \"Wooden Side Desk\"\n - \"add the camera\" \u2192 if only one camera was shown, use that one\n - \"the first one\" \u2192 use the first product from the last search\n - \"that laptop\" \u2192 matches the laptop shown earlier\n- Be smart about fuzzy matching. If the user's reference clearly maps to a product already in the conversation, just use it. Only search again if you genuinely cannot tell which product they mean.\n\n## Price formatting:\n- All prices in tool result summaries are already formatted in dollars (e.g. \"$42.63\"). Do NOT divide, convert, or reformat them \u2014 use them as-is.\n- When calling filterByPrice, prices must be provided in cents (smallest currency unit). For example, $50 = 5000 cents.\n\n## Response style:\n- Be concise and helpful\n- Keep product-related messages SHORT since product cards are shown separately\n- Always be honest - if something isn't available, say so\n- NEVER echo or repeat raw tool result text in your response. Tool results are internal data for you to use \u2014 do NOT include \"[Tool result: ...]\" or the summary text verbatim. Instead, paraphrase the result naturally in your own words.\n- When addToCart succeeds, simply confirm with something like \"Done! I've added X to your cart.\" Do NOT repeat the tool output summary.";
2
+ //# sourceMappingURL=system-prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/services/system-prompt.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,wpTAmG8G,CAAC"}
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SYSTEM_PROMPT = void 0;
4
+ // ──────────────────────────────────────────────
5
+ // System prompt
6
+ // ──────────────────────────────────────────────
7
+ exports.SYSTEM_PROMPT = `You are a friendly and helpful shopping assistant for our online store. Your job is to help customers find products, browse collections, manage their cart, view order history, and track their orders.
8
+
9
+ ## What you CAN do:
10
+ - Help customers find products using search, semantic search, or browsing by collections
11
+ - Answer questions about products (features, prices, availability based on tool data)
12
+ - Help customers filter products by price/budget
13
+ - Recommend products based on intent (e.g. "gift for dad", "something for gaming")
14
+ - Greet customers, have polite small talk ONLY about shopping/store context
15
+ - Answer questions about the store, shipping, returns (give general helpful answers)
16
+ - Add items to the customer's cart when they ask
17
+ - Show the customer their current cart and adjust quantities or remove items
18
+ - Show the customer their order history
19
+ - Track the status of their orders and provide fulfillment/tracking info
20
+
21
+ ## What you MUST NOT do:
22
+ - Answer questions unrelated to the store (e.g. "who is Elon Musk", "capital of France", "write me a poem")
23
+ - Make up or fabricate product information - ONLY use data from tool results
24
+ - Discuss politics, celebrities, news, science, or any topic outside the store
25
+
26
+ ## How to handle off-topic questions:
27
+ Politely redirect: "I'm your shopping assistant and can only help with store-related questions. Can I help you find a product instead?"
28
+
29
+ ## Tool usage:
30
+ - \`searchProducts\` — keyword search (e.g. "laptop", "camera", "headphones")
31
+ - \`vectorSearch\` — intent/semantic search (e.g. "gift for dad", "something romantic")
32
+ - \`getCollections\` — list product categories/collections
33
+ - \`filterByPrice\` — filter by budget/price range
34
+ - \`addToCart\` — add a product to the customer's cart
35
+ - \`getActiveOrder\` — get the customer's current cart/active order with all line items (requires login)
36
+ - \`adjustOrderLine\` — change the quantity of an item in the cart, or remove it by setting quantity to 0 (requires login)
37
+ - \`getOrderHistory\` — show the customer's past orders (requires login)
38
+ - \`trackOrder\` — get status and tracking info for an order (requires login)
39
+ - \`getAvailableCountries\` — list countries available for shipping/billing addresses
40
+ - \`getEligibleShippingMethods\` — get available shipping methods for the active order (after address is set)
41
+ - \`getEligiblePaymentMethods\` — get available payment methods for the active order
42
+ - \`setShippingAddress\` — set shipping address on the active order (requires login and active order)
43
+ - \`setBillingAddress\` — set billing address on the active order (requires login and active order)
44
+ - \`setShippingMethod\` — set shipping method on the active order (requires login and active order)
45
+
46
+ ## CRITICAL response rules for products:
47
+ - When tools return product data, do NOT list product names, prices, or images in your text. The UI automatically renders product cards with images, names, prices, and "Add to Cart" buttons below your message.
48
+ - Keep your text to a brief friendly comment like "Here are some cameras I found!" — NOT a detailed listing.
49
+ - NEVER include markdown images (![...](url)) in your response.
50
+ - NEVER list individual product names with prices. The product cards handle that.
51
+
52
+ ## CRITICAL rules for addToCart:
53
+ - The variantId MUST be the EXACT numeric ID string from the MOST RECENT search results for that specific product (e.g. "42", "15", "103"). It is always a number.
54
+ - NEVER fabricate or guess a variantId. If you are not 100% certain of the correct variantId, search for the product AGAIN first.
55
+ - When the user says "buy this" or "add this", look at the MOST RECENTLY shown product results. Do NOT reuse variantIds from older search results for different products.
56
+ - You may confirm ONCE: mention the product name, price, and ask about quantity. But if the user has ALREADY confirmed (said "yes", "sure", "go ahead", "do it", given a quantity, etc.), call addToCart IMMEDIATELY. NEVER ask for confirmation more than once.
57
+ - Once confirmed, call addToCart with the exact variantId AND productName from the search results and the requested quantity.
58
+ - If there is ANY ambiguity about WHICH product the user means, ASK. But if the product is clear and user said yes, just add it.
59
+ - ALWAYS provide the productName parameter when calling addToCart so the backend can verify the correct product.
60
+
61
+ ## Rules for cart tools (getActiveOrder, adjustOrderLine):
62
+ - Use \`getActiveOrder\` when the customer asks about their cart, what's in their cart, cart total, or wants to review before checkout.
63
+ - **CRITICAL: ALWAYS call \`getActiveOrder\` every time the customer asks about their cart, even if you already showed it earlier in the conversation.** The customer may have modified their cart outside of this chat (e.g. on the cart page). NEVER rely on previous tool results for cart state — always fetch fresh data.
64
+ - Use \`adjustOrderLine\` to change quantities or remove items. You need the orderLineId from getActiveOrder results.
65
+ - When adjusting quantity, set the new absolute quantity (not a delta). To remove an item, set quantity to 0.
66
+ - Always call \`getActiveOrder\` first if you don't already have the orderLineId from the conversation context.
67
+ - When showing the cart, summarize each item: product name, quantity, and line price. Also mention the cart total.
68
+
69
+ ## Rules for order tools:
70
+ - Use \`getOrderHistory\` when the customer asks about their past orders, recent purchases, or order history.
71
+ - Use \`trackOrder\` when the customer asks about a specific order's status, tracking, or shipment.
72
+ - When showing order history, summarize each order briefly: order code, status, total, and what they ordered.
73
+ - When tracking an order, mention the order state, fulfillment status, tracking code (if available), and items.
74
+ - If a customer says "where's my order?" or "track my order" without specifying which one, use getOrderHistory first to find their most recent order, then use trackOrder on that order.
75
+
76
+ ## Rules for checkout tools:
77
+ - **IMPORTANT — Country codes:** ALWAYS call \`getAvailableCountries\` FIRST before setting any address. Only use country codes returned by that tool. If the customer gives a country name or code not in the list, tell them which countries are available and ask them to pick one. NEVER guess or assume a country code — the backend will reject invalid ones.
78
+ - Use \`setShippingAddress\` when the customer provides their shipping address. Collect all required fields: fullName, streetLine1, city, province, postalCode, countryCode, phoneNumber. Ask for missing fields before calling.
79
+ - Use \`setBillingAddress\` when the customer provides a billing address. If they say "same as shipping", use the same address data.
80
+ - Use \`getEligibleShippingMethods\` after the shipping address is set to show available shipping options.
81
+ - Use \`setShippingMethod\` with the id from getEligibleShippingMethods when the customer chooses a shipping option.
82
+ - You CANNOT process payments directly. After shipping address, billing address, and shipping method are all set, call \`getEligiblePaymentMethods\` to show the customer their available payment options (e.g. "You can pay with Credit Card or PayPal"), then tell them: "Head to the [checkout page](/checkout) to complete your payment." Do NOT attempt to handle payment in the chat.
83
+ - Always ensure there is an active order before calling checkout tools. If no active order exists, suggest adding items first.
84
+ - The typical checkout flow is: getAvailableCountries → set shipping address → (optionally) set billing address → get eligible shipping methods → set shipping method → getEligiblePaymentMethods → direct user to /checkout for payment.
85
+ - If the customer asks "how can I pay?" or "what payment methods do you accept?" at any point, call \`getEligiblePaymentMethods\` to answer.
86
+
87
+ ## IMPORTANT — matching products from conversation context:
88
+ - When the user refers to a product that was ALREADY shown in the MOST RECENT search results, use the variantId from that specific search. Do NOT reuse variantIds from older/different searches.
89
+ - If the user switches topics to a different product, ALWAYS search again to get the correct variantId for the new product. Do NOT mix up variantIds between different products.
90
+ - Users will often use partial names, abbreviations, or slightly different wording. For example:
91
+ - "the wooden desk" → matches "Wooden Side Desk"
92
+ - "add the camera" → if only one camera was shown, use that one
93
+ - "the first one" → use the first product from the last search
94
+ - "that laptop" → matches the laptop shown earlier
95
+ - Be smart about fuzzy matching. If the user's reference clearly maps to a product already in the conversation, just use it. Only search again if you genuinely cannot tell which product they mean.
96
+
97
+ ## Price formatting:
98
+ - All prices in tool result summaries are already formatted in dollars (e.g. "$42.63"). Do NOT divide, convert, or reformat them — use them as-is.
99
+ - When calling filterByPrice, prices must be provided in cents (smallest currency unit). For example, $50 = 5000 cents.
100
+
101
+ ## Response style:
102
+ - Be concise and helpful
103
+ - Keep product-related messages SHORT since product cards are shown separately
104
+ - Always be honest - if something isn't available, say so
105
+ - NEVER echo or repeat raw tool result text in your response. Tool results are internal data for you to use — do NOT include "[Tool result: ...]" or the summary text verbatim. Instead, paraphrase the result naturally in your own words.
106
+ - When addToCart succeeds, simply confirm with something like "Done! I've added X to your cart." Do NOT repeat the tool output summary.`;
107
+ //# sourceMappingURL=system-prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/services/system-prompt.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AACjD,gBAAgB;AAChB,iDAAiD;AACpC,QAAA,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wIAmG2G,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { RequestContext, TransactionalConnection, OrderService } from '@vendure/core';
2
+ import { ChatResultMapper } from '../chat-result-mapper';
3
+ import type { ToolResult } from '../types';
4
+ export declare class CartTools {
5
+ private connection;
6
+ private orderService;
7
+ private mapper;
8
+ private readonly logger;
9
+ constructor(connection: TransactionalConnection, orderService: OrderService, mapper: ChatResultMapper);
10
+ addToCart(_ctx: RequestContext, args: Record<string, unknown>): Promise<ToolResult>;
11
+ getActiveOrder(ctx: RequestContext, _args: Record<string, unknown>): Promise<ToolResult>;
12
+ adjustOrderLine(ctx: RequestContext, args: Record<string, unknown>): Promise<ToolResult>;
13
+ }
14
+ //# sourceMappingURL=cart-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cart-tools.d.ts","sourceRoot":"","sources":["../../../src/services/tools/cart-tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAkB,YAAY,EAA+B,MAAM,eAAe,CAAC;AACnI,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,KAAK,EAAmE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE5G,qBAAa,SAAS;IAId,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,MAAM;IALlB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8B;gBAGzC,UAAU,EAAE,uBAAuB,EACnC,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,gBAAgB;IAG9B,SAAS,CACX,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,OAAO,CAAC,UAAU,CAAC;IAqEhB,cAAc,CAChB,GAAG,EAAE,cAAc,EACnB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,UAAU,CAAC;IAwChB,eAAe,CACjB,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,OAAO,CAAC,UAAU,CAAC;CAoEzB"}
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CartTools = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const core_1 = require("@vendure/core");
6
+ const constants_1 = require("../../constants");
7
+ class CartTools {
8
+ constructor(connection, orderService, mapper) {
9
+ this.connection = connection;
10
+ this.orderService = orderService;
11
+ this.mapper = mapper;
12
+ this.logger = new common_1.Logger(CartTools.name);
13
+ }
14
+ async addToCart(_ctx, args) {
15
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
16
+ const variantId = String((_a = args.variantId) !== null && _a !== void 0 ? _a : '').trim();
17
+ const quantity = Math.max(1, Number(args.quantity) || 1);
18
+ const productName = args.productName ? String(args.productName) : undefined;
19
+ this.logger.log(`addToCart called with variantId=${variantId}, quantity=${quantity}, productName=${productName}`);
20
+ if (!variantId) {
21
+ return { products: [], collections: [], summary: 'Error: No variantId provided. Search for the product first to get the correct variantId.' };
22
+ }
23
+ // Validate that variantId is a numeric ID, not a fabricated slug, somehow is stupid enough to send slugs sometimess
24
+ if (!/^\d+$/.test(variantId)) {
25
+ return {
26
+ products: [],
27
+ collections: [],
28
+ summary: `Error: Invalid variantId "${variantId}". The variantId must be a numeric ID (e.g. "42") from a previous search result. Please search for the product first to get the correct variantId.`,
29
+ };
30
+ }
31
+ // Verify the variant actually exists and get the real product name
32
+ const variantRepo = this.connection.rawConnection.getRepository(core_1.ProductVariant);
33
+ const variant = await variantRepo.findOne({
34
+ where: { id: Number(variantId) },
35
+ relations: ['product', 'product.translations', 'translations'],
36
+ });
37
+ if (!variant) {
38
+ return {
39
+ products: [],
40
+ collections: [],
41
+ summary: `Error: No product variant found with ID ${variantId}. Please search for the product again to get the correct variantId.`,
42
+ };
43
+ }
44
+ const actualProductName = (_h = (_e = (_d = (_c = (_b = variant.product) === null || _b === void 0 ? void 0 : _b.translations) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.name) !== null && _e !== void 0 ? _e : (_g = (_f = variant.translations) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.name) !== null && _h !== void 0 ? _h : 'item';
45
+ this.logger.log(`addToCart verified: variantId=${variantId} is "${actualProductName}" (variant: ${(_l = (_k = (_j = variant.translations) === null || _j === void 0 ? void 0 : _j[0]) === null || _k === void 0 ? void 0 : _k.name) !== null && _l !== void 0 ? _l : variant.id}), LLM said productName="${productName}"`);
46
+ // Safety check: if the LLM provided a productName, verify it roughly matches the actual product
47
+ if (productName && actualProductName !== 'item') {
48
+ const requestedLower = productName.toLowerCase().trim();
49
+ const actualLower = actualProductName.toLowerCase().trim();
50
+ // Check if neither name contains the other (very loose match)
51
+ const isMatch = actualLower.includes(requestedLower)
52
+ || requestedLower.includes(actualLower)
53
+ || actualLower.split(/\s+/).some((w) => requestedLower.includes(w))
54
+ || requestedLower.split(/\s+/).some((w) => actualLower.includes(w));
55
+ if (!isMatch) {
56
+ this.logger.warn(`addToCart MISMATCH: LLM requested "${productName}" but variantId ${variantId} is "${actualProductName}". Rejecting.`);
57
+ return {
58
+ products: [],
59
+ collections: [],
60
+ summary: `Error: The variantId ${variantId} corresponds to "${actualProductName}", but you are trying to add "${productName}". These don't match. Please search for "${productName}" first to get the correct variantId.`,
61
+ };
62
+ }
63
+ }
64
+ return {
65
+ products: [],
66
+ collections: [],
67
+ summary: `Adding ${quantity}x "${actualProductName}" (variantId: ${variantId}) to cart.`,
68
+ addToCartAction: { variantId, quantity, productName: actualProductName },
69
+ };
70
+ }
71
+ async getActiveOrder(ctx, _args) {
72
+ if (!ctx.activeUserId) {
73
+ return { products: [], collections: [], summary: 'Error: You must be logged in to view your cart.' };
74
+ }
75
+ try {
76
+ const order = await this.orderService.getActiveOrderForUser(ctx, ctx.activeUserId);
77
+ if (!order) {
78
+ return { products: [], collections: [], summary: 'Your cart is empty. No active order found.' };
79
+ }
80
+ const orderRepo = this.connection.rawConnection.getRepository(core_1.Order);
81
+ const fullOrder = await orderRepo.findOne({
82
+ where: { id: order.id },
83
+ relations: ['lines', 'lines.productVariant', 'lines.productVariant.translations', 'lines.featuredAsset'],
84
+ });
85
+ if (!fullOrder || !fullOrder.lines || fullOrder.lines.length === 0) {
86
+ return { products: [], collections: [], summary: 'Your cart is empty.' };
87
+ }
88
+ const activeOrder = this.mapper.mapActiveOrder(fullOrder);
89
+ const linesSummary = activeOrder.lines
90
+ .map(l => `${l.quantity}x "${l.productName}" (orderLineId: ${l.orderLineId}, variantId: ${l.variantId}, linePrice: ${(0, constants_1.formatPrice)(l.linePriceWithTax)})`)
91
+ .join(', ');
92
+ return {
93
+ products: [],
94
+ collections: [],
95
+ activeOrder,
96
+ summary: `Cart has ${activeOrder.totalQuantity} item(s), total: ${(0, constants_1.formatPrice)(activeOrder.totalWithTax)}. Lines: ${linesSummary}. Use the orderLineId when adjusting quantities.`,
97
+ };
98
+ }
99
+ catch (e) {
100
+ this.logger.error(`Error fetching active order: ${e}`);
101
+ return { products: [], collections: [], summary: 'Error fetching your cart. Please try again.' };
102
+ }
103
+ }
104
+ async adjustOrderLine(ctx, args) {
105
+ var _a, _b, _c, _d;
106
+ if (!ctx.activeUserId) {
107
+ return { products: [], collections: [], summary: 'Error: You must be logged in to modify your cart.' };
108
+ }
109
+ const orderLineId = String((_a = args.orderLineId) !== null && _a !== void 0 ? _a : '').trim();
110
+ const quantity = Number((_b = args.quantity) !== null && _b !== void 0 ? _b : -1);
111
+ if (!orderLineId || !/^\d+$/.test(orderLineId)) {
112
+ return { products: [], collections: [], summary: 'Error: Invalid orderLineId. Use getActiveOrder first to get the correct orderLineId.' };
113
+ }
114
+ if (quantity < 0) {
115
+ return { products: [], collections: [], summary: 'Error: quantity must be 0 or greater. Set to 0 to remove the item.' };
116
+ }
117
+ try {
118
+ const order = await this.orderService.getActiveOrderForUser(ctx, ctx.activeUserId);
119
+ if (!order) {
120
+ return { products: [], collections: [], summary: 'Error: No active order found. Your cart is empty.' };
121
+ }
122
+ let result;
123
+ if (quantity === 0) {
124
+ result = await this.orderService.removeItemFromOrder(ctx, order.id, Number(orderLineId));
125
+ }
126
+ else {
127
+ result = await this.orderService.adjustOrderLine(ctx, order.id, Number(orderLineId), quantity);
128
+ }
129
+ if ((0, core_1.isGraphQlErrorResult)(result)) {
130
+ const errorMsg = (_d = (_c = result.message) !== null && _c !== void 0 ? _c : result.errorCode) !== null && _d !== void 0 ? _d : 'Unknown error';
131
+ this.logger.warn(`adjustOrderLine error: ${errorMsg}`);
132
+ return { products: [], collections: [], summary: `Error adjusting cart: ${errorMsg}` };
133
+ }
134
+ const orderRepo = this.connection.rawConnection.getRepository(core_1.Order);
135
+ const fullOrder = await orderRepo.findOne({
136
+ where: { id: order.id },
137
+ relations: ['lines', 'lines.productVariant', 'lines.productVariant.translations', 'lines.featuredAsset'],
138
+ });
139
+ if (!fullOrder || !fullOrder.lines || fullOrder.lines.length === 0) {
140
+ return {
141
+ products: [],
142
+ collections: [],
143
+ activeOrder: { id: String(order.id), code: order.code, totalQuantity: 0, totalWithTax: 0, lines: [] },
144
+ summary: quantity === 0
145
+ ? 'Item removed. Your cart is now empty.'
146
+ : 'Cart updated. Your cart is now empty.',
147
+ };
148
+ }
149
+ const activeOrder = this.mapper.mapActiveOrder(fullOrder);
150
+ const action = quantity === 0 ? 'removed' : `quantity updated to ${quantity}`;
151
+ const linesSummary = activeOrder.lines
152
+ .map(l => `${l.quantity}x "${l.productName}" (orderLineId: ${l.orderLineId})`)
153
+ .join(', ');
154
+ return {
155
+ products: [],
156
+ collections: [],
157
+ activeOrder,
158
+ summary: `Item ${action}. Cart now has ${activeOrder.totalQuantity} item(s), total: ${(0, constants_1.formatPrice)(activeOrder.totalWithTax)}. Lines: ${linesSummary}`,
159
+ };
160
+ }
161
+ catch (e) {
162
+ this.logger.error(`Error adjusting order line: ${e}`);
163
+ return { products: [], collections: [], summary: 'Error adjusting your cart. Please try again.' };
164
+ }
165
+ }
166
+ }
167
+ exports.CartTools = CartTools;
168
+ //# sourceMappingURL=cart-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cart-tools.js","sourceRoot":"","sources":["../../../src/services/tools/cart-tools.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AACxC,wCAAmI;AAEnI,+CAA8C;AAG9C,MAAa,SAAS;IAGlB,YACY,UAAmC,EACnC,YAA0B,EAC1B,MAAwB;QAFxB,eAAU,GAAV,UAAU,CAAyB;QACnC,iBAAY,GAAZ,YAAY,CAAc;QAC1B,WAAM,GAAN,MAAM,CAAkB;QALnB,WAAM,GAAG,IAAI,eAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAMlD,CAAC;IAEJ,KAAK,CAAC,SAAS,CACX,IAAoB,EACpB,IAA6B;;QAE7B,MAAM,SAAS,GAAG,MAAM,CAAC,MA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uBAAuB,QAAQ,EAAE,CAAC;YAC9E,MAAM,YAAY,GAAG,WAAW,CAAC,KAAK;iBACjC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,MAAM,CAAC,CAAC,WAAW,mBAAmB,CAAC,CAAC,WAAW,GAAG,CAAC;iBAC7E,IAAI,CAAC,IAAI,CAAC,CAAC;YAEhB,OAAO;gBACH,QAAQ,EAAE,EAAE;gBACZ,WAAW,EAAE,EAAE;gBACf,WAAW;gBACX,OAAO,EAAE,QAAQ,MAAM,kBAAkB,WAAW,CAAC,aAAa,oBAAoB,IAAA,uBAAW,EAAC,WAAW,CAAC,YAAY,CAAC,YAAY,YAAY,EAAE;aACxJ,CAAC;QACN,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,CAAC,EAAE,CAAC,CAAC;YACtD,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,8CAA8C,EAAE,CAAC;QACtG,CAAC;IACL,CAAC;CACJ;AAnMD,8BAmMC"}
@@ -0,0 +1,37 @@
1
+ import { RequestContext, TransactionalConnection, OrderService } from '@vendure/core';
2
+ import type { ToolResult } from '../types';
3
+ export declare class CheckoutTools {
4
+ private connection;
5
+ private orderService;
6
+ private readonly logger;
7
+ constructor(connection: TransactionalConnection, orderService: OrderService);
8
+ getAvailableCountries(ctx: RequestContext): Promise<ToolResult>;
9
+ getEligibleShippingMethods(ctx: RequestContext): Promise<ToolResult>;
10
+ getEligiblePaymentMethods(ctx: RequestContext): Promise<ToolResult>;
11
+ setShippingAddress(ctx: RequestContext, params: {
12
+ fullName: string;
13
+ streetLine1: string;
14
+ streetLine2?: string;
15
+ city: string;
16
+ province: string;
17
+ postalCode: string;
18
+ countryCode: string;
19
+ phoneNumber: string;
20
+ company?: string;
21
+ }): Promise<ToolResult>;
22
+ setBillingAddress(ctx: RequestContext, params: {
23
+ fullName: string;
24
+ streetLine1: string;
25
+ streetLine2?: string;
26
+ city: string;
27
+ province: string;
28
+ postalCode: string;
29
+ countryCode: string;
30
+ phoneNumber: string;
31
+ company?: string;
32
+ }): Promise<ToolResult>;
33
+ setShippingMethod(ctx: RequestContext, params: {
34
+ shippingMethodId: string;
35
+ }): Promise<ToolResult>;
36
+ }
37
+ //# sourceMappingURL=checkout-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkout-tools.d.ts","sourceRoot":"","sources":["../../../src/services/tools/checkout-tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,YAAY,EAA+B,MAAM,eAAe,CAAC;AAEnH,OAAO,KAAK,EAAE,UAAU,EAA8E,MAAM,UAAU,CAAC;AAEvH,qBAAa,aAAa;IAIlB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,YAAY;IAJxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkC;gBAG7C,UAAU,EAAE,uBAAuB,EACnC,YAAY,EAAE,YAAY;IAGhC,qBAAqB,CACvB,GAAG,EAAE,cAAc,GACpB,OAAO,CAAC,UAAU,CAAC;IA2BhB,0BAA0B,CAC5B,GAAG,EAAE,cAAc,GACpB,OAAO,CAAC,UAAU,CAAC;IA8BhB,yBAAyB,CAC3B,GAAG,EAAE,cAAc,GACpB,OAAO,CAAC,UAAU,CAAC;IA+BhB,kBAAkB,CACpB,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE;QACJ,QAAQ,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAC5D,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QACnD,WAAW,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;K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