nitrostack 1.0.55 → 1.0.56

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 (222) hide show
  1. package/dist/cli/commands/init.d.ts.map +1 -1
  2. package/dist/cli/commands/init.js +14 -9
  3. package/dist/cli/commands/init.js.map +1 -1
  4. package/dist/widgets/hooks/index.d.ts +7 -0
  5. package/dist/widgets/hooks/index.d.ts.map +1 -0
  6. package/dist/widgets/hooks/index.js +7 -0
  7. package/dist/widgets/hooks/index.js.map +1 -0
  8. package/dist/widgets/hooks/use-display-mode.d.ts +11 -0
  9. package/dist/widgets/hooks/use-display-mode.d.ts.map +1 -0
  10. package/dist/widgets/hooks/use-display-mode.js +13 -0
  11. package/dist/widgets/hooks/use-display-mode.js.map +1 -0
  12. package/dist/widgets/hooks/use-max-height.d.ts +10 -0
  13. package/dist/widgets/hooks/use-max-height.d.ts.map +1 -0
  14. package/dist/widgets/hooks/use-max-height.js +13 -0
  15. package/dist/widgets/hooks/use-max-height.js.map +1 -0
  16. package/dist/widgets/hooks/use-openai-global.d.ts +12 -0
  17. package/dist/widgets/hooks/use-openai-global.d.ts.map +1 -0
  18. package/dist/widgets/hooks/use-openai-global.js +32 -0
  19. package/dist/widgets/hooks/use-openai-global.js.map +1 -0
  20. package/dist/widgets/hooks/use-theme.d.ts +10 -0
  21. package/dist/widgets/hooks/use-theme.d.ts.map +1 -0
  22. package/dist/widgets/hooks/use-theme.js +12 -0
  23. package/dist/widgets/hooks/use-theme.js.map +1 -0
  24. package/dist/widgets/hooks/use-widget-state.d.ts +18 -0
  25. package/dist/widgets/hooks/use-widget-state.d.ts.map +1 -0
  26. package/dist/widgets/hooks/use-widget-state.js +27 -0
  27. package/dist/widgets/hooks/use-widget-state.js.map +1 -0
  28. package/dist/widgets/hooks/useWidgetSDK.d.ts +47 -0
  29. package/dist/widgets/hooks/useWidgetSDK.d.ts.map +1 -0
  30. package/dist/widgets/hooks/useWidgetSDK.js +67 -0
  31. package/dist/widgets/hooks/useWidgetSDK.js.map +1 -0
  32. package/dist/widgets/index.d.ts +7 -1
  33. package/dist/widgets/index.d.ts.map +1 -1
  34. package/dist/widgets/index.js +11 -1
  35. package/dist/widgets/index.js.map +1 -1
  36. package/dist/widgets/runtime/WidgetLayout.d.ts +32 -0
  37. package/dist/widgets/runtime/WidgetLayout.d.ts.map +1 -0
  38. package/dist/widgets/runtime/WidgetLayout.js +143 -0
  39. package/dist/widgets/runtime/WidgetLayout.js.map +1 -0
  40. package/dist/widgets/runtime/widget-polyfill.d.ts +1 -0
  41. package/dist/widgets/runtime/widget-polyfill.d.ts.map +1 -0
  42. package/dist/widgets/runtime/widget-polyfill.js +28 -0
  43. package/dist/widgets/runtime/widget-polyfill.js.map +1 -0
  44. package/dist/widgets/sdk.d.ts +109 -0
  45. package/dist/widgets/sdk.d.ts.map +1 -0
  46. package/dist/widgets/sdk.js +221 -0
  47. package/dist/widgets/sdk.js.map +1 -0
  48. package/dist/widgets/types.d.ts +89 -0
  49. package/dist/widgets/types.d.ts.map +1 -0
  50. package/dist/widgets/types.js +8 -0
  51. package/dist/widgets/types.js.map +1 -0
  52. package/dist/widgets/utils/media-queries.d.ts +34 -0
  53. package/dist/widgets/utils/media-queries.d.ts.map +1 -0
  54. package/dist/widgets/utils/media-queries.js +42 -0
  55. package/dist/widgets/utils/media-queries.js.map +1 -0
  56. package/package.json +1 -1
  57. package/src/studio/app/chat/page.tsx +274 -137
  58. package/src/studio/app/globals.css +140 -64
  59. package/src/studio/branding.md +807 -0
  60. package/src/studio/components/WidgetRenderer.tsx +222 -16
  61. package/src/studio/lib/llm-service.ts +39 -39
  62. package/templates/typescript-oauth/{env.example → .env.example} +4 -10
  63. package/templates/typescript-oauth/README.md +226 -306
  64. package/templates/typescript-oauth/package-lock.json +4253 -0
  65. package/templates/typescript-oauth/package.json +10 -5
  66. package/templates/typescript-oauth/src/app.module.ts +39 -36
  67. package/templates/typescript-oauth/src/guards/oauth.guard.ts +0 -1
  68. package/templates/typescript-oauth/src/index.ts +22 -30
  69. package/templates/typescript-oauth/src/modules/flights/booking.tools.ts +323 -0
  70. package/templates/typescript-oauth/src/modules/flights/flights.module.ts +14 -0
  71. package/templates/typescript-oauth/src/modules/flights/flights.prompts.ts +231 -0
  72. package/templates/typescript-oauth/src/modules/flights/flights.resources.ts +215 -0
  73. package/templates/typescript-oauth/src/modules/flights/flights.tools.ts +457 -0
  74. package/templates/typescript-oauth/src/services/duffel.service.ts +285 -0
  75. package/templates/typescript-oauth/src/widgets/app/airport-search/page.tsx +270 -0
  76. package/templates/typescript-oauth/src/widgets/app/flight-details/page.tsx +261 -0
  77. package/templates/typescript-oauth/src/widgets/app/flight-search-results/page.tsx +378 -0
  78. package/templates/typescript-oauth/src/widgets/app/globals.css +167 -0
  79. package/templates/typescript-oauth/src/widgets/app/layout.tsx +6 -2
  80. package/templates/typescript-oauth/src/widgets/app/order-cancellation/page.tsx +207 -0
  81. package/templates/typescript-oauth/src/widgets/app/order-summary/page.tsx +245 -0
  82. package/templates/typescript-oauth/src/widgets/app/payment-confirmation/page.tsx +152 -0
  83. package/templates/typescript-oauth/src/widgets/app/seat-selection/page.tsx +486 -0
  84. package/templates/typescript-oauth/src/widgets/next-env.d.ts +5 -0
  85. package/templates/typescript-oauth/src/widgets/package-lock.json +155 -126
  86. package/templates/typescript-oauth/src/widgets/widget-manifest.json +374 -27
  87. package/templates/typescript-pizzaz/IMPLEMENTATION.md +98 -0
  88. package/templates/typescript-pizzaz/README.md +233 -0
  89. package/templates/typescript-pizzaz/package.json +31 -0
  90. package/templates/typescript-pizzaz/src/app.module.ts +28 -0
  91. package/templates/typescript-pizzaz/src/index.ts +30 -0
  92. package/templates/typescript-pizzaz/src/modules/pizzaz/pizzaz.data.ts +106 -0
  93. package/templates/typescript-pizzaz/src/modules/pizzaz/pizzaz.module.ts +11 -0
  94. package/templates/typescript-pizzaz/src/modules/pizzaz/pizzaz.service.ts +60 -0
  95. package/templates/typescript-pizzaz/src/modules/pizzaz/pizzaz.tools.ts +197 -0
  96. package/templates/typescript-pizzaz/src/widgets/app/layout.tsx +18 -0
  97. package/templates/typescript-pizzaz/src/widgets/app/pizza-list/page.tsx +272 -0
  98. package/templates/typescript-pizzaz/src/widgets/app/pizza-map/page.tsx +216 -0
  99. package/templates/typescript-pizzaz/src/widgets/app/pizza-shop/page.tsx +374 -0
  100. package/templates/typescript-pizzaz/src/widgets/components/CompactShopCard.tsx +144 -0
  101. package/templates/typescript-pizzaz/src/widgets/components/PizzaCard.tsx +191 -0
  102. package/templates/typescript-pizzaz/src/widgets/package.json +30 -0
  103. package/templates/typescript-pizzaz/src/widgets/widget-manifest.json +253 -0
  104. package/templates/typescript-pizzaz/tsconfig.json +30 -0
  105. package/templates/typescript-starter/src/modules/calculator/calculator.resources.ts +0 -1
  106. package/templates/typescript-starter/src/widgets/app/calculator-result/page.tsx +102 -56
  107. package/templates/typescript-starter/src/widgets/app/layout.tsx +6 -2
  108. package/templates/typescript-auth/AI_AGENT_CLI_REFERENCE.md +0 -702
  109. package/templates/typescript-auth/AI_AGENT_SDK_REFERENCE.md +0 -1260
  110. package/templates/typescript-auth/README.md +0 -402
  111. package/templates/typescript-auth/env.example +0 -25
  112. package/templates/typescript-auth/package.json +0 -36
  113. package/templates/typescript-auth/src/app.module.ts +0 -103
  114. package/templates/typescript-auth/src/db/database.ts +0 -160
  115. package/templates/typescript-auth/src/db/seed.ts +0 -374
  116. package/templates/typescript-auth/src/db/setup.ts +0 -87
  117. package/templates/typescript-auth/src/events/analytics.service.ts +0 -52
  118. package/templates/typescript-auth/src/events/notification.service.ts +0 -40
  119. package/templates/typescript-auth/src/filters/global-exception.filter.ts +0 -28
  120. package/templates/typescript-auth/src/guards/README.md +0 -75
  121. package/templates/typescript-auth/src/guards/jwt.guard.ts +0 -105
  122. package/templates/typescript-auth/src/health/database.health.ts +0 -41
  123. package/templates/typescript-auth/src/index.ts +0 -29
  124. package/templates/typescript-auth/src/interceptors/transform.interceptor.ts +0 -24
  125. package/templates/typescript-auth/src/middleware/logging.middleware.ts +0 -42
  126. package/templates/typescript-auth/src/modules/addresses/addresses.module.ts +0 -16
  127. package/templates/typescript-auth/src/modules/addresses/addresses.prompts.ts +0 -114
  128. package/templates/typescript-auth/src/modules/addresses/addresses.resources.ts +0 -40
  129. package/templates/typescript-auth/src/modules/addresses/addresses.tools.ts +0 -284
  130. package/templates/typescript-auth/src/modules/auth/auth.module.ts +0 -16
  131. package/templates/typescript-auth/src/modules/auth/auth.prompts.ts +0 -147
  132. package/templates/typescript-auth/src/modules/auth/auth.resources.ts +0 -84
  133. package/templates/typescript-auth/src/modules/auth/auth.tools.ts +0 -139
  134. package/templates/typescript-auth/src/modules/cart/cart.module.ts +0 -16
  135. package/templates/typescript-auth/src/modules/cart/cart.prompts.ts +0 -95
  136. package/templates/typescript-auth/src/modules/cart/cart.resources.ts +0 -44
  137. package/templates/typescript-auth/src/modules/cart/cart.tools.ts +0 -277
  138. package/templates/typescript-auth/src/modules/orders/orders.module.ts +0 -16
  139. package/templates/typescript-auth/src/modules/orders/orders.prompts.ts +0 -88
  140. package/templates/typescript-auth/src/modules/orders/orders.resources.ts +0 -48
  141. package/templates/typescript-auth/src/modules/orders/orders.tools.ts +0 -303
  142. package/templates/typescript-auth/src/modules/products/products.module.ts +0 -16
  143. package/templates/typescript-auth/src/modules/products/products.prompts.ts +0 -146
  144. package/templates/typescript-auth/src/modules/products/products.resources.ts +0 -98
  145. package/templates/typescript-auth/src/modules/products/products.tools.ts +0 -266
  146. package/templates/typescript-auth/src/pipes/validation.pipe.ts +0 -42
  147. package/templates/typescript-auth/src/services/database.service.ts +0 -90
  148. package/templates/typescript-auth/src/widgets/app/add-to-cart/page.tsx +0 -122
  149. package/templates/typescript-auth/src/widgets/app/address-added/page.tsx +0 -116
  150. package/templates/typescript-auth/src/widgets/app/address-deleted/page.tsx +0 -105
  151. package/templates/typescript-auth/src/widgets/app/address-list/page.tsx +0 -139
  152. package/templates/typescript-auth/src/widgets/app/address-updated/page.tsx +0 -153
  153. package/templates/typescript-auth/src/widgets/app/cart-cleared/page.tsx +0 -86
  154. package/templates/typescript-auth/src/widgets/app/cart-updated/page.tsx +0 -116
  155. package/templates/typescript-auth/src/widgets/app/categories/page.tsx +0 -134
  156. package/templates/typescript-auth/src/widgets/app/layout.tsx +0 -21
  157. package/templates/typescript-auth/src/widgets/app/login-result/page.tsx +0 -129
  158. package/templates/typescript-auth/src/widgets/app/order-confirmation/page.tsx +0 -231
  159. package/templates/typescript-auth/src/widgets/app/order-details/page.tsx +0 -225
  160. package/templates/typescript-auth/src/widgets/app/order-history/page.tsx +0 -218
  161. package/templates/typescript-auth/src/widgets/app/product-card/page.tsx +0 -121
  162. package/templates/typescript-auth/src/widgets/app/products-grid/page.tsx +0 -198
  163. package/templates/typescript-auth/src/widgets/app/shopping-cart/page.tsx +0 -187
  164. package/templates/typescript-auth/src/widgets/app/whoami/page.tsx +0 -165
  165. package/templates/typescript-auth/src/widgets/next.config.js +0 -38
  166. package/templates/typescript-auth/src/widgets/package.json +0 -18
  167. package/templates/typescript-auth/src/widgets/styles/ecommerce.ts +0 -169
  168. package/templates/typescript-auth/src/widgets/tsconfig.json +0 -28
  169. package/templates/typescript-auth/src/widgets/types/tool-data.ts +0 -141
  170. package/templates/typescript-auth/src/widgets/widget-manifest.json +0 -464
  171. package/templates/typescript-auth/tsconfig.json +0 -27
  172. package/templates/typescript-auth-api-key/AI_AGENT_CLI_REFERENCE.md +0 -701
  173. package/templates/typescript-auth-api-key/AI_AGENT_SDK_REFERENCE.md +0 -1260
  174. package/templates/typescript-auth-api-key/README.md +0 -485
  175. package/templates/typescript-auth-api-key/env.example +0 -17
  176. package/templates/typescript-auth-api-key/package.json +0 -21
  177. package/templates/typescript-auth-api-key/src/app.module.ts +0 -38
  178. package/templates/typescript-auth-api-key/src/guards/apikey.guard.ts +0 -47
  179. package/templates/typescript-auth-api-key/src/guards/multi-auth.guard.ts +0 -157
  180. package/templates/typescript-auth-api-key/src/index.ts +0 -47
  181. package/templates/typescript-auth-api-key/src/modules/calculator/calculator.module.ts +0 -12
  182. package/templates/typescript-auth-api-key/src/modules/calculator/calculator.prompts.ts +0 -73
  183. package/templates/typescript-auth-api-key/src/modules/calculator/calculator.resources.ts +0 -60
  184. package/templates/typescript-auth-api-key/src/modules/calculator/calculator.tools.ts +0 -71
  185. package/templates/typescript-auth-api-key/src/modules/demo/demo.module.ts +0 -18
  186. package/templates/typescript-auth-api-key/src/modules/demo/demo.tools.ts +0 -155
  187. package/templates/typescript-auth-api-key/src/modules/demo/multi-auth.tools.ts +0 -123
  188. package/templates/typescript-auth-api-key/src/widgets/app/calculator-operations/page.tsx +0 -133
  189. package/templates/typescript-auth-api-key/src/widgets/app/calculator-result/page.tsx +0 -134
  190. package/templates/typescript-auth-api-key/src/widgets/app/layout.tsx +0 -14
  191. package/templates/typescript-auth-api-key/src/widgets/package.json +0 -24
  192. package/templates/typescript-auth-api-key/src/widgets/widget-manifest.json +0 -48
  193. package/templates/typescript-auth-api-key/tsconfig.json +0 -23
  194. package/templates/typescript-oauth/OAUTH_SETUP.md +0 -592
  195. package/templates/typescript-oauth/src/modules/demo/demo.module.ts +0 -16
  196. package/templates/typescript-oauth/src/modules/demo/demo.tools.ts +0 -190
  197. package/templates/typescript-oauth/src/widgets/app/calculator-operations/page.tsx +0 -133
  198. package/templates/typescript-oauth/src/widgets/app/calculator-result/page.tsx +0 -134
  199. package/templates/typescript-oauth/src/widgets/out/404.html +0 -1
  200. package/templates/typescript-oauth/src/widgets/out/_next/static/WU9THacVqL52RZbrZOLS1/_buildManifest.js +0 -1
  201. package/templates/typescript-oauth/src/widgets/out/_next/static/WU9THacVqL52RZbrZOLS1/_ssgManifest.js +0 -1
  202. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/117-eb57c7ef86f964a4.js +0 -2
  203. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/app/_not-found/page-dcb83ba3e4d0aafd.js +0 -1
  204. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/app/calculator-operations/page-b8913a740073ea8a.js +0 -1
  205. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/app/calculator-result/page-ddaaab2fce95dea2.js +0 -1
  206. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/app/layout-cbd3ebdc4ecc5247.js +0 -1
  207. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/fd9d1056-749e5812300142af.js +0 -1
  208. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/framework-f66176bb897dc684.js +0 -1
  209. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/main-76df43fcef3db344.js +0 -1
  210. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/main-app-f9c40224d04023c5.js +0 -1
  211. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/pages/_app-72b849fbd24ac258.js +0 -1
  212. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/pages/_error-7ba65e1336b92748.js +0 -1
  213. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/polyfills-42372ed130431b0a.js +0 -1
  214. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/webpack-100b9e646d9c912e.js +0 -1
  215. package/templates/typescript-oauth/src/widgets/out/calculator-operations.html +0 -1
  216. package/templates/typescript-oauth/src/widgets/out/calculator-operations.txt +0 -7
  217. package/templates/typescript-oauth/src/widgets/out/calculator-result.html +0 -1
  218. package/templates/typescript-oauth/src/widgets/out/calculator-result.txt +0 -7
  219. package/templates/typescript-starter/src/widgets/app/calculator-operations/page.tsx +0 -133
  220. /package/templates/{typescript-auth-api-key → typescript-oauth}/src/health/system.health.ts +0 -0
  221. /package/templates/{typescript-auth-api-key → typescript-pizzaz}/src/widgets/next.config.js +0 -0
  222. /package/templates/{typescript-auth-api-key → typescript-pizzaz}/src/widgets/tsconfig.json +0 -0
@@ -1,95 +0,0 @@
1
- import { PromptDecorator as Prompt, ExecutionContext } from 'nitrostack';
2
-
3
- /**
4
- * Cart Prompts
5
- * Provides helpful prompts for cart management
6
- */
7
- export class CartPrompts {
8
- /**
9
- * Cart management help prompt
10
- */
11
- @Prompt({
12
- name: 'cart-management-help',
13
- description: 'Get help managing your shopping cart',
14
- })
15
- async cartHelp(args: Record<string, any>, context: ExecutionContext) {
16
- return [
17
- {
18
- role: 'user' as const,
19
- content: 'I need help managing my shopping cart',
20
- },
21
- {
22
- role: 'assistant' as const,
23
- content: `**Shopping Cart Management Guide**
24
-
25
- **Available Tools (Requires Authentication):**
26
- 1. \`add_to_cart\` - Add products to cart
27
- 2. \`view_cart\` - View cart contents and total
28
- 3. \`update_cart_item\` - Change quantity or remove items
29
- 4. \`clear_cart\` - Empty entire cart
30
-
31
- **Adding Items:**
32
- \`\`\`
33
- add_to_cart({
34
- product_id: "product-uuid",
35
- quantity: 2
36
- })
37
- \`\`\`
38
- - Make sure to login first
39
- - Check product stock availability
40
- - Quantity must be > 0
41
-
42
- **Viewing Cart:**
43
- \`\`\`
44
- view_cart({})
45
- \`\`\`
46
- - Shows all items with images
47
- - Displays individual and total prices
48
- - Item count included
49
-
50
- **Updating Items:**
51
- \`\`\`
52
- update_cart_item({
53
- product_id: "product-uuid",
54
- quantity: 5 // or 0 to remove
55
- })
56
- \`\`\`
57
- - Set quantity to 0 to remove item
58
- - Must have sufficient stock
59
-
60
- **Clearing Cart:**
61
- \`\`\`
62
- clear_cart({})
63
- \`\`\`
64
- - Removes ALL items
65
- - Cannot be undone
66
-
67
- **Common Operations:**
68
- 📦 **Add Multiple Items:**
69
- Call \`add_to_cart\` multiple times with different product_ids
70
-
71
- 🔄 **Update Quantity:**
72
- Use \`update_cart_item\` with new quantity
73
-
74
- 🗑️ **Remove Single Item:**
75
- Use \`update_cart_item\` with quantity: 0
76
-
77
- 💰 **Check Total:**
78
- Call \`view_cart\` to see current total
79
-
80
- **Best Practices:**
81
- ✓ Login before adding to cart
82
- ✓ Check stock before adding large quantities
83
- ✓ Review cart before checkout
84
- ✓ Use \`view_cart\` to verify changes
85
-
86
- **Tips:**
87
- - Cart persists between sessions
88
- - Items added increment existing quantities
89
- - Checkout with \`create_order\` when ready
90
- - Cart clears automatically after order`,
91
- },
92
- ];
93
- }
94
- }
95
-
@@ -1,44 +0,0 @@
1
- import { ResourceDecorator as Resource, ExecutionContext } from 'nitrostack';
2
-
3
- /**
4
- * Cart Resources
5
- * Provides cart-related resource endpoints
6
- */
7
- export class CartResources {
8
- /**
9
- * Cart schema resource
10
- */
11
- @Resource({
12
- uri: 'cart://schema',
13
- name: 'Cart Schema',
14
- description: 'Schema definition for shopping cart objects',
15
- mimeType: 'application/json',
16
- })
17
- async getCartSchema(context: ExecutionContext) {
18
- return {
19
- type: 'json' as const,
20
- data: {
21
- type: 'object',
22
- properties: {
23
- items: {
24
- type: 'array',
25
- items: {
26
- type: 'object',
27
- properties: {
28
- id: { type: 'string', description: 'Cart item ID' },
29
- product_id: { type: 'string', description: 'Product ID' },
30
- name: { type: 'string', description: 'Product name' },
31
- price: { type: 'number', description: 'Product price' },
32
- quantity: { type: 'integer', minimum: 1, description: 'Quantity in cart' },
33
- image_url: { type: 'string', nullable: true, description: 'Product image' },
34
- },
35
- },
36
- },
37
- total: { type: 'number', description: 'Total cart value' },
38
- itemCount: { type: 'integer', description: 'Number of items in cart' },
39
- },
40
- },
41
- };
42
- }
43
- }
44
-
@@ -1,277 +0,0 @@
1
- import { ToolDecorator as Tool, Widget, UseGuards, z, ExecutionContext } from 'nitrostack';
2
- import { v4 as uuidv4 } from 'uuid';
3
- import { getDatabase } from '../../db/database.js';
4
- import { JWTGuard } from '../../guards/jwt.guard.js';
5
-
6
- /**
7
- * Cart Tools
8
- * Handles shopping cart operations (requires authentication)
9
- */
10
- export class CartTools {
11
- /**
12
- * Add product to cart - Requires authentication
13
- */
14
- @Tool({
15
- name: 'add_to_cart',
16
- description: 'Add a product to the shopping cart. Requires authentication. IMPORTANT: Use the product ID from browse_products or get_product_details results. If user says "add apple", find the product with name "Apple" from previous results and use its ID.',
17
- inputSchema: z.object({
18
- product_id: z.string().describe('The ID of the product to add (e.g., "prod-3"). Get this from browse_products results by matching the product name.'),
19
- quantity: z.number().min(1).default(1).describe('Quantity to add'),
20
- }),
21
- examples: {
22
- request: {
23
- product_id: 'prod-1',
24
- quantity: 2
25
- },
26
- response: {
27
- message: 'Added to cart!',
28
- product_id: 'prod-1',
29
- product_name: 'Essence Mascara Lash Princess',
30
- price: 9.99,
31
- quantity: 2,
32
- image_url: 'https://cdn.dummyjson.com/product-images/beauty/essence-mascara-lash-princess/thumbnail.webp',
33
- cartItemCount: 2
34
- }
35
- }
36
- })
37
- @Widget('add-to-cart')
38
- @UseGuards(JWTGuard)
39
- async addToCart(input: any, context: ExecutionContext) {
40
- const db = getDatabase();
41
- const userId = context.auth?.subject;
42
-
43
- // Check if product exists and has stock
44
- const product: any = db.prepare('SELECT * FROM products WHERE id = ?').get(input.product_id);
45
-
46
- if (!product) {
47
- throw new Error(`Product with ID ${input.product_id} not found`);
48
- }
49
-
50
- if (product.stock < (input.quantity || 1)) {
51
- throw new Error(`Insufficient stock. Only ${product.stock} units available.`);
52
- }
53
-
54
- // Check if item already in cart
55
- const existing: any = db.prepare(`
56
- SELECT * FROM carts WHERE user_id = ? AND product_id = ?
57
- `).get(userId, input.product_id);
58
-
59
- if (existing) {
60
- // Update quantity
61
- const newQuantity = existing.quantity + input.quantity;
62
-
63
- if (product.stock < newQuantity) {
64
- throw new Error(`Cannot add ${input.quantity} more units. Only ${product.stock - existing.quantity} additional units available.`);
65
- }
66
-
67
- db.prepare(`
68
- UPDATE carts SET quantity = ? WHERE id = ?
69
- `).run(newQuantity, existing.id);
70
-
71
- context.logger.info(`Updated cart: product=${product.name}, quantity=${newQuantity}`);
72
-
73
- // Get total cart count
74
- const cartCount: any = db.prepare(`
75
- SELECT SUM(quantity) as total FROM carts WHERE user_id = ?
76
- `).get(userId);
77
-
78
- return {
79
- message: `Added to cart!`,
80
- product_id: input.product_id,
81
- product_name: product.name,
82
- price: product.price,
83
- quantity: input.quantity,
84
- image_url: product.image_url,
85
- cartItemCount: cartCount.total || 0,
86
- };
87
- } else {
88
- // Add new item
89
- const cartId = uuidv4();
90
-
91
- db.prepare(`
92
- INSERT INTO carts (id, user_id, product_id, quantity)
93
- VALUES (?, ?, ?, ?)
94
- `).run(cartId, userId, input.product_id, input.quantity);
95
-
96
- context.logger.info(`Added to cart: product=${product.name}, quantity=${input.quantity}`);
97
-
98
- // Get total cart count
99
- const cartCount: any = db.prepare(`
100
- SELECT SUM(quantity) as total FROM carts WHERE user_id = ?
101
- `).get(userId);
102
-
103
- return {
104
- message: `Added to cart!`,
105
- product_id: input.product_id,
106
- product_name: product.name,
107
- price: product.price,
108
- quantity: input.quantity,
109
- image_url: product.image_url,
110
- cartItemCount: cartCount.total || 0,
111
- };
112
- }
113
- }
114
-
115
- /**
116
- * View shopping cart - Requires authentication
117
- */
118
- @Tool({
119
- name: 'view_cart',
120
- description: 'View the current shopping cart with all items and total price. Requires authentication.',
121
- inputSchema: z.object({}),
122
- examples: {
123
- request: {},
124
- response: {
125
- items: [
126
- {
127
- id: 'cart-item-1',
128
- quantity: 2,
129
- product_id: 'prod-1',
130
- name: 'Essence Mascara Lash Princess',
131
- price: 9.99,
132
- image_url: 'https://cdn.dummyjson.com/product-images/beauty/essence-mascara-lash-princess/thumbnail.webp'
133
- },
134
- {
135
- id: 'cart-item-2',
136
- quantity: 1,
137
- product_id: 'prod-2',
138
- name: 'Eyeshadow Palette with Mirror',
139
- price: 19.99,
140
- image_url: 'https://cdn.dummyjson.com/product-images/beauty/eyeshadow-palette-with-mirror/thumbnail.webp'
141
- }
142
- ],
143
- total: 39.97,
144
- itemCount: 2
145
- }
146
- }
147
- })
148
- @Widget('shopping-cart')
149
- @UseGuards(JWTGuard)
150
- async viewCart(input: any, context: ExecutionContext) {
151
- const db = getDatabase();
152
- const userId = context.auth?.subject;
153
-
154
- const items: any[] = db.prepare(`
155
- SELECT c.id, c.quantity, p.id as product_id, p.name, p.price, p.image_url, p.description, p.stock
156
- FROM carts c
157
- JOIN products p ON c.product_id = p.id
158
- WHERE c.user_id = ?
159
- `).all(userId);
160
-
161
- const total = items.reduce((sum, item) => sum + (item.price * item.quantity), 0);
162
-
163
- context.logger.info(`Viewed cart: ${items.length} items, total=$${total.toFixed(2)}`);
164
-
165
- return {
166
- items,
167
- total,
168
- itemCount: items.length,
169
- };
170
- }
171
-
172
- /**
173
- * Update cart item quantity - Requires authentication
174
- */
175
- @Tool({
176
- name: 'update_cart_item',
177
- description: 'Update the quantity of a product in the cart. Set to 0 to remove. Requires authentication.',
178
- inputSchema: z.object({
179
- product_id: z.string().describe('The ID of the product to update'),
180
- quantity: z.number().min(0).describe('New quantity (0 to remove)'),
181
- }),
182
- examples: {
183
- request: {
184
- product_id: 'prod-1',
185
- quantity: 3
186
- },
187
- response: {
188
- message: 'Cart updated successfully',
189
- product: 'Essence Mascara Lash Princess',
190
- quantity: 3
191
- }
192
- }
193
- })
194
- @Widget('cart-updated')
195
- @UseGuards(JWTGuard)
196
- async updateCartItem(input: any, context: ExecutionContext) {
197
- const db = getDatabase();
198
- const userId = context.auth?.subject;
199
-
200
- if (input.quantity === 0) {
201
- // Remove item
202
- db.prepare(`
203
- DELETE FROM carts WHERE user_id = ? AND product_id = ?
204
- `).run(userId, input.product_id);
205
-
206
- context.logger.info(`Removed from cart: product_id=${input.product_id}`);
207
-
208
- return {
209
- message: 'Item removed from cart',
210
- product: input.product_id,
211
- };
212
- } else {
213
- // Check stock
214
- const product: any = db.prepare('SELECT * FROM products WHERE id = ?').get(input.product_id);
215
-
216
- if (!product) {
217
- throw new Error(`Product with ID ${input.product_id} not found`);
218
- }
219
-
220
- if (product.stock < input.quantity) {
221
- throw new Error(`Insufficient stock. Only ${product.stock} units available.`);
222
- }
223
-
224
- // Update quantity
225
- db.prepare(`
226
- UPDATE carts SET quantity = ? WHERE user_id = ? AND product_id = ?
227
- `).run(input.quantity, userId, input.product_id);
228
-
229
- context.logger.info(`Updated cart item: product=${product.name}, quantity=${input.quantity}`);
230
-
231
- return {
232
- message: 'Cart updated successfully',
233
- product: product.name,
234
- quantity: input.quantity,
235
- };
236
- }
237
- }
238
-
239
- /**
240
- * Clear shopping cart - Requires authentication
241
- */
242
- @Tool({
243
- name: 'clear_cart',
244
- description: 'Remove all items from the shopping cart. Requires authentication.',
245
- inputSchema: z.object({}),
246
- examples: {
247
- request: {},
248
- response: {
249
- message: 'Shopping cart cleared',
250
- itemsRemoved: 2
251
- }
252
- }
253
- })
254
- @Widget('cart-cleared')
255
- @UseGuards(JWTGuard)
256
- async clearCart(input: any, context: ExecutionContext) {
257
- const db = getDatabase();
258
- const userId = context.auth?.subject;
259
-
260
- // Get count before clearing
261
- const count: any = db.prepare(`
262
- SELECT COUNT(*) as count FROM carts WHERE user_id = ?
263
- `).get(userId);
264
-
265
- db.prepare(`
266
- DELETE FROM carts WHERE user_id = ?
267
- `).run(userId);
268
-
269
- context.logger.info(`Cleared cart: removed ${count.count} items`);
270
-
271
- return {
272
- message: 'Shopping cart cleared',
273
- itemsRemoved: count.count,
274
- };
275
- }
276
- }
277
-
@@ -1,16 +0,0 @@
1
- import { Module } from 'nitrostack';
2
- import { OrdersTools } from './orders.tools.js';
3
- import { OrdersResources } from './orders.resources.js';
4
- import { OrdersPrompts } from './orders.prompts.js';
5
-
6
- /**
7
- * Orders Module
8
- * Provides order creation, history, resources, and prompts
9
- */
10
- @Module({
11
- name: 'orders',
12
- description: 'Order creation and management',
13
- controllers: [OrdersTools, OrdersResources, OrdersPrompts],
14
- })
15
- export class OrdersModule {}
16
-
@@ -1,88 +0,0 @@
1
- import { PromptDecorator as Prompt, ExecutionContext } from 'nitrostack';
2
-
3
- /**
4
- * Orders Prompts
5
- * Provides helpful prompts for order management
6
- */
7
- export class OrdersPrompts {
8
- /**
9
- * Order help prompt
10
- */
11
- @Prompt({
12
- name: 'order-help',
13
- description: 'Get help with placing and managing orders',
14
- })
15
- async orderHelp(args: Record<string, any>, context: ExecutionContext) {
16
- return [
17
- {
18
- role: 'user' as const,
19
- content: 'I need help with orders',
20
- },
21
- {
22
- role: 'assistant' as const,
23
- content: `**Order Management Guide**
24
-
25
- **Available Tools (Requires Authentication):**
26
- 1. \`create_order\` - Place order from cart
27
- 2. \`get_order_history\` - View all your orders
28
- 3. \`get_order_details\` - View specific order details
29
-
30
- **Creating an Order:**
31
- \`\`\`
32
- create_order({
33
- payment_method: "credit_card" | "paypal" | "apple_pay",
34
- shipping_address_id: "optional-address-id"
35
- })
36
- \`\`\`
37
-
38
- **Prerequisites:**
39
- ✓ Must be logged in
40
- ✓ Must have items in cart
41
- ✓ Must have a shipping address (or set default)
42
-
43
- **Order Process:**
44
- 1. **Add items to cart** → \`add_to_cart\`
45
- 2. **Review cart** → \`view_cart\`
46
- 3. **Set shipping address** → \`add_address\` or use default
47
- 4. **Place order** → \`create_order\`
48
- 5. **Get confirmation** → Order ID returned
49
-
50
- **Payment Methods:**
51
- - \`credit_card\` - Credit/Debit card
52
- - \`paypal\` - PayPal account
53
- - \`apple_pay\` - Apple Pay
54
-
55
- **After Order Created:**
56
- - Cart is automatically cleared
57
- - Product stock is updated
58
- - Order appears in history
59
- - Status starts as "pending"
60
-
61
- **Viewing Orders:**
62
- \`\`\`
63
- get_order_history({}) // All your orders
64
- get_order_details({ order_id: "order-uuid" }) // Specific order
65
- \`\`\`
66
-
67
- **Order Statuses:**
68
- - 🟡 **pending** - Order placed, awaiting processing
69
- - 🔵 **processing** - Being prepared
70
- - 📦 **shipped** - In transit
71
- - ✅ **delivered** - Completed
72
- - ❌ **cancelled** - Cancelled
73
-
74
- **Common Issues:**
75
- ❌ "Cart is empty" → Add items first
76
- ❌ "No shipping address" → Add address with \`add_address\`
77
- ❌ "Insufficient stock" → Product sold out, update cart
78
-
79
- **Tips:**
80
- - Review cart before ordering
81
- - Ensure correct shipping address
82
- - Keep order ID for tracking
83
- - Check order history anytime`,
84
- },
85
- ];
86
- }
87
- }
88
-
@@ -1,48 +0,0 @@
1
- import { ResourceDecorator as Resource, ExecutionContext } from 'nitrostack';
2
-
3
- /**
4
- * Orders Resources
5
- * Provides order-related resource endpoints
6
- */
7
- export class OrdersResources {
8
- /**
9
- * Order schema resource
10
- */
11
- @Resource({
12
- uri: 'orders://schema',
13
- name: 'Order Schema',
14
- description: 'Schema definition for order objects',
15
- mimeType: 'application/json',
16
- })
17
- async getOrderSchema(context: ExecutionContext) {
18
- return {
19
- type: 'json' as const,
20
- data: {
21
- type: 'object',
22
- properties: {
23
- id: { type: 'string', format: 'uuid', description: 'Order ID' },
24
- user_id: { type: 'string', description: 'User ID' },
25
- total: { type: 'number', minimum: 0, description: 'Order total' },
26
- status: { type: 'string', enum: ['pending', 'processing', 'shipped', 'delivered', 'cancelled'], description: 'Order status' },
27
- payment_method: { type: 'string', enum: ['credit_card', 'paypal', 'apple_pay'], description: 'Payment method' },
28
- shipping_address_id: { type: 'string', description: 'Shipping address ID' },
29
- created_at: { type: 'string', format: 'date-time', description: 'Order creation time' },
30
- items: {
31
- type: 'array',
32
- items: {
33
- type: 'object',
34
- properties: {
35
- id: { type: 'string', description: 'Order item ID' },
36
- product_id: { type: 'string', description: 'Product ID' },
37
- name: { type: 'string', description: 'Product name' },
38
- quantity: { type: 'integer', minimum: 1, description: 'Quantity ordered' },
39
- price: { type: 'number', description: 'Price at time of order' },
40
- },
41
- },
42
- },
43
- },
44
- },
45
- };
46
- }
47
- }
48
-