@henrylabs/mcp 0.8.0 → 0.10.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 (79) hide show
  1. package/README.md +246 -12
  2. package/code-tool-worker.d.mts.map +1 -1
  3. package/code-tool-worker.d.ts.map +1 -1
  4. package/code-tool-worker.js +97 -7
  5. package/code-tool-worker.js.map +1 -1
  6. package/code-tool-worker.mjs +97 -7
  7. package/code-tool-worker.mjs.map +1 -1
  8. package/code-tool.js +1 -1
  9. package/code-tool.js.map +1 -1
  10. package/code-tool.mjs +1 -1
  11. package/code-tool.mjs.map +1 -1
  12. package/http.js +2 -2
  13. package/http.js.map +1 -1
  14. package/http.mjs +2 -2
  15. package/http.mjs.map +1 -1
  16. package/package.json +3 -2
  17. package/server.js +1 -1
  18. package/server.js.map +1 -1
  19. package/server.mjs +1 -1
  20. package/server.mjs.map +1 -1
  21. package/src/code-tool-worker.ts +126 -7
  22. package/src/code-tool.ts +1 -1
  23. package/src/http.ts +2 -2
  24. package/src/server.ts +1 -1
  25. package/src/tools/cart/create-cart-checkout.ts +1 -1
  26. package/src/tools/cart/items/add-cart-items.ts +2 -2
  27. package/src/tools/cart/items/clear-cart-items.ts +2 -2
  28. package/src/tools/cart/items/list-cart-items.ts +2 -2
  29. package/src/tools/cart/items/remove-cart-items.ts +2 -2
  30. package/src/tools/checkout/session/confirm-checkout-session.ts +1 -1
  31. package/src/tools/checkout/session/create-checkout-session.ts +1 -1
  32. package/src/tools/orders/retrieve-status-orders.ts +1 -1
  33. package/src/tools/products/retrieve-product-details.ts +1 -1
  34. package/src/tools/products/search-products.ts +1 -1
  35. package/src/tools/wallet/collect-payment-details.ts +1 -1
  36. package/tools/cart/create-cart-checkout.js +1 -1
  37. package/tools/cart/create-cart-checkout.js.map +1 -1
  38. package/tools/cart/create-cart-checkout.mjs +1 -1
  39. package/tools/cart/create-cart-checkout.mjs.map +1 -1
  40. package/tools/cart/items/add-cart-items.js +2 -2
  41. package/tools/cart/items/add-cart-items.js.map +1 -1
  42. package/tools/cart/items/add-cart-items.mjs +2 -2
  43. package/tools/cart/items/add-cart-items.mjs.map +1 -1
  44. package/tools/cart/items/clear-cart-items.js +2 -2
  45. package/tools/cart/items/clear-cart-items.js.map +1 -1
  46. package/tools/cart/items/clear-cart-items.mjs +2 -2
  47. package/tools/cart/items/clear-cart-items.mjs.map +1 -1
  48. package/tools/cart/items/list-cart-items.js +2 -2
  49. package/tools/cart/items/list-cart-items.js.map +1 -1
  50. package/tools/cart/items/list-cart-items.mjs +2 -2
  51. package/tools/cart/items/list-cart-items.mjs.map +1 -1
  52. package/tools/cart/items/remove-cart-items.js +2 -2
  53. package/tools/cart/items/remove-cart-items.js.map +1 -1
  54. package/tools/cart/items/remove-cart-items.mjs +2 -2
  55. package/tools/cart/items/remove-cart-items.mjs.map +1 -1
  56. package/tools/checkout/session/confirm-checkout-session.js +1 -1
  57. package/tools/checkout/session/confirm-checkout-session.js.map +1 -1
  58. package/tools/checkout/session/confirm-checkout-session.mjs +1 -1
  59. package/tools/checkout/session/confirm-checkout-session.mjs.map +1 -1
  60. package/tools/checkout/session/create-checkout-session.js +1 -1
  61. package/tools/checkout/session/create-checkout-session.js.map +1 -1
  62. package/tools/checkout/session/create-checkout-session.mjs +1 -1
  63. package/tools/checkout/session/create-checkout-session.mjs.map +1 -1
  64. package/tools/orders/retrieve-status-orders.js +1 -1
  65. package/tools/orders/retrieve-status-orders.js.map +1 -1
  66. package/tools/orders/retrieve-status-orders.mjs +1 -1
  67. package/tools/orders/retrieve-status-orders.mjs.map +1 -1
  68. package/tools/products/retrieve-product-details.js +1 -1
  69. package/tools/products/retrieve-product-details.js.map +1 -1
  70. package/tools/products/retrieve-product-details.mjs +1 -1
  71. package/tools/products/retrieve-product-details.mjs.map +1 -1
  72. package/tools/products/search-products.js +1 -1
  73. package/tools/products/search-products.js.map +1 -1
  74. package/tools/products/search-products.mjs +1 -1
  75. package/tools/products/search-products.mjs.map +1 -1
  76. package/tools/wallet/collect-payment-details.js +1 -1
  77. package/tools/wallet/collect-payment-details.js.map +1 -1
  78. package/tools/wallet/collect-payment-details.mjs +1 -1
  79. package/tools/wallet/collect-payment-details.mjs.map +1 -1
package/README.md CHANGED
@@ -34,12 +34,36 @@ For clients with a configuration JSON, it might look something like this:
34
34
  }
35
35
  ```
36
36
 
37
+ ### Cursor
38
+
39
+ If you use Cursor, you can install the MCP server by using the button below. You will need to set your environment variables
40
+ in Cursor's `mcp.json`, which can be found in Cursor Settings > Tools & MCP > New MCP Server.
41
+
42
+ [![Add to Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en-US/install-mcp?name=@henrylabs/mcp&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBoZW5yeWxhYnMvbWNwIl0sImVudiI6eyJIRU5SWV9TREtfQVBJX0tFWSI6IlNldCB5b3VyIEhFTlJZX1NES19BUElfS0VZIGhlcmUuIn19)
43
+
44
+ ### VS Code
45
+
46
+ If you use MCP, you can install the MCP server by clicking the link below. You will need to set your environment variables
47
+ in VS Code's `mcp.json`, which can be found via Command Palette > MCP: Open User Configuration.
48
+
49
+ [Open VS Code](https://vscode.stainless.com/mcp/%7B%22name%22%3A%22%40henrylabs%2Fmcp%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40henrylabs%2Fmcp%22%5D%2C%22env%22%3A%7B%22HENRY_SDK_API_KEY%22%3A%22Set%20your%20HENRY_SDK_API_KEY%20here.%22%7D%7D)
50
+
51
+ ### Claude Code
52
+
53
+ If you use Claude Code, you can install the MCP server by running the command below in your terminal. You will need to set your
54
+ environment variables in Claude Code's `.claude.json`, which can be found in your home directory.
55
+
56
+ ```
57
+ claude mcp add --transport stdio henrylabs_sdk_api --env HENRY_SDK_API_KEY="Your HENRY_SDK_API_KEY here." -- npx -y @henrylabs/mcp
58
+ ```
59
+
37
60
  ## Exposing endpoints to your MCP Client
38
61
 
39
- There are two ways to expose endpoints as tools in the MCP server:
62
+ There are three ways to expose endpoints as tools in the MCP server:
40
63
 
41
64
  1. Exposing one tool per endpoint, and filtering as necessary
42
65
  2. Exposing a set of tools to dynamically discover and invoke endpoints from the API
66
+ 3. Exposing a docs search tool and a code execution tool, allowing the client to write code to be executed against the TypeScript client
43
67
 
44
68
  ### Filtering endpoints and tools
45
69
 
@@ -75,6 +99,18 @@ All of these command-line options can be repeated, combined together, and have c
75
99
 
76
100
  Use `--list` to see the list of available tools, or see below.
77
101
 
102
+ ### Code execution
103
+
104
+ If you specify `--tools=code` to the MCP server, it will expose just two tools:
105
+
106
+ - `search_docs` - Searches the API documentation and returns a list of markdown results
107
+ - `execute` - Runs code against the TypeScript client
108
+
109
+ This allows the LLM to implement more complex logic by chaining together many API calls without loading
110
+ intermediary results into its context window.
111
+
112
+ The code execution itself happens in a Deno sandbox that has network access only to the base URL for the API.
113
+
78
114
  ### Specifying the MCP Client
79
115
 
80
116
  Different clients have varying abilities to handle arbitrary tools and schemas.
@@ -205,29 +241,227 @@ The following tools are available in this MCP server.
205
241
 
206
242
  ### Resource `products`:
207
243
 
208
- - `retrieve_product_details` (`read`) tags: [headless, hosted]: Retrieve detailed information about a specific product given product ID. Must be called to first get a product link before adding an item to cart
209
- - `search_products` (`write`) tags: [headless, hosted]: Search for products using keyword and passing various filters and criteria
244
+ - `retrieve_product_details` (`read`) tags: [headless, hosted]: Retrieve comprehensive product details using a product ID from search results.
245
+
246
+ MUST BE CALLED BEFORE adding items to cart - this is the only way to get the productLink required for cart operations.
247
+
248
+ Returns:
249
+
250
+ - Product title, brand, rating, review count
251
+ - Stores array with name, price, shipping, total, and LINK for each retailer
252
+ - Available variants (sizes, colors, etc.) with availability status
253
+ - Thumbnail images (multiple angles)
254
+
255
+ - `search_products` (`write`) tags: [headless, hosted]: Search for products using keywords and filters (price range, color, size, gender, manufacturer, region).
256
+
257
+ Returns basic product information:
258
+
259
+ - Product ID (required for next step)
260
+ - Name, price, currency, description
261
+ - Thumbnail image URL
262
+
263
+ You MUST call retrieve_product_details() with each product's ID to get:
264
+
265
+ - Actual store links for purchasing
266
+ - All available variants
267
+ - Detailed reviews and ratings
268
+ - Price comparisons across stores
269
+
270
+ Recommended flow:
271
+
272
+ 1. search_products(query, filters) - Get product IDs
273
+ 2. retrieve_product_details(productId) - Get store URLs and variants for each
274
+ 3. Present results with images, prices, AND clickable store links
275
+
276
+ Common filters: limit (default 10), greaterThanPrice, lowerThanPrice, color, size, gender
210
277
 
211
278
  ### Resource `cart`:
212
279
 
213
- - `create_cart_checkout` (`write`) tags: [hosted]: Generates a hosted checkout URL for the user's cart. The page walks the buyer through reviewing the order, entering shipping, payment information, and confirming the purchase.
280
+ - `create_cart_checkout` (`write`) tags: [hosted]: Generates a fully-hosted checkout URL for the user's cart. This is the SIMPLEST checkout method.
281
+
282
+ The hosted page handles:
283
+
284
+ - Order review
285
+ - Shipping address collection
286
+ - Payment information (via Stripe)
287
+ - Order confirmation
288
+ - All UI and validation
289
+
290
+ Returns: checkout_url (direct link for user to complete purchase)
291
+
292
+ Parameters:
293
+
294
+ - auth: true (default) - requires user authentication, false for guest checkout
295
+
296
+ Use this when:
297
+
298
+ - You want a quick, complete checkout solution
299
+ - Don't need custom checkout UI
300
+ - Want Stripe to handle payment collection
301
+
302
+ For custom checkout UI, use the headless flow instead:
303
+ create_checkout_session → collect_payment_details → confirm_checkout_session
214
304
 
215
305
  ### Resource `cart.items`:
216
306
 
217
- - `list_cart_items` (`read`) tags: [hosted]: Get all products from the cart
218
- - `add_cart_items` (`write`) tags: [hosted]: Adds product data to existing cart or create a new one.
219
- - `clear_cart_items` (`write`) tags: [hosted]: Delete all products from the cart
220
- - `remove_cart_items` (`write`) tags: [hosted]: Delete a product from the cart
307
+ - `list_cart_items` (`read`) tags: [headless, hosted]: Retrieve all products currently in the user's cart.
308
+
309
+ Returns products array with:
310
+
311
+ - name, price, productLink, quantity
312
+ - productId (if provided when added)
313
+ - metadata (variant selections)
314
+ - productImageLink (thumbnail)
315
+ - affiliateProductLink (if used)
316
+
317
+ Use this to:
318
+
319
+ - Show cart contents before checkout
320
+ - Calculate totals
321
+ - Verify items before creating checkout
322
+
323
+ - `add_cart_items` (`write`) tags: [headless, hosted]: Add products to cart or update quantities if already in cart.
324
+
325
+ Required fields per product:
326
+
327
+ - name: Product name (from retrieve_product_details)
328
+ - price: Price as string, e.g. "29.99" (from stores[0].price)
329
+ - productLink: Store URL (from stores[0].link - MUST call retrieve_product_details first)
330
+ - quantity: Number of items
331
+
332
+ Optional but IMPORTANT:
333
+
334
+ - metadata: Object containing variant selections (size, color, etc.)
335
+ Example: {"size": "Large", "color": "Blue"}
336
+ - productImageLink: Thumbnail URL (from thumbnails[0])
337
+ - affiliateProductLink: Use instead of productLink for affiliate tracking
338
+ - productId: Include for easier tracking
339
+
340
+ VARIANT HANDLING:
341
+ If retrieve_product_details shows variants array, you MUST:
342
+
343
+ 1. Show variants to user: "Available sizes: S, M, L, XL"
344
+ 2. Get user's selection
345
+ 3. Include in metadata: {"size": "L"}
346
+
347
+ Optional: Set checkVariantAvailability: true to verify variants exist at stores
348
+
349
+ Returns:
350
+
351
+ - added_products: New items in cart
352
+ - updated_products: Items with quantity increases
353
+ - cart_summary: total_items and total_unique_products
354
+ - variant_checks: Availability verification results (if requested)
355
+
356
+ - `clear_cart_items` (`write`) tags: [headless, hosted]: Remove ALL products from the cart. Cannot be undone.
357
+
358
+ Use when:
359
+
360
+ - User wants to start over
361
+ - Clearing abandoned cart
362
+ - After successful order completion
363
+
364
+ Returns success confirmation message.
365
+
366
+ - `remove_cart_items` (`write`) tags: [headless, hosted]: Remove a specific product from the cart by its productId.
367
+
368
+ Required: productId (must match the ID used when adding item)
369
+
370
+ Returns success confirmation message.
221
371
 
222
372
  ### Resource `checkout.session`:
223
373
 
224
- - `confirm_checkout_session` (`write`) tags: [headless]: Confirms the checkout session and creates an order for the user. Returns an order ID that can be used to view order status
225
- - `create_checkout_session` (`write`) tags: [headless]: Creates or updates a checkout session with shipping details and returns pricing metadata plus a session token needed for confirming checkout
374
+ - `confirm_checkout_session` (`write`) tags: [headless]: Finalize the checkout and create an order. Returns order details with order ID.
375
+
376
+ Required:
377
+
378
+ - x-session-token: From create_checkout_session
379
+ - shippingDetails: Same address object used in create_checkout_session
380
+
381
+ IMPORTANT: Must call collect_payment_details BEFORE this to save payment method.
382
+
383
+ Returns order details:
384
+
385
+ - id: Order ID (use with retrieve_status_orders)
386
+ - products: List with productName, quantity, productMetadata
387
+ - currency, subtotal, shipping, tax, grandTotal
388
+ - shippingDetails: Delivery address
389
+ - status: Order status (e.g., "processing")
390
+ - statusMessage: Human-readable status
391
+ - cardLast4: Last 4 digits of payment card (if available)
392
+
393
+ After confirmation, provide order ID to user for tracking.
394
+
395
+ - `create_checkout_session` (`write`) tags: [headless]: Create/update a checkout session for headless checkout flow. Returns pricing breakdown and session token.
396
+
397
+ Required: shippingDetails object with:
398
+
399
+ - fullName, email, phoneNumber
400
+ - addressLine1, city, stateOrProvince, postalCode, countryCode
401
+ - addressLine2 (optional)
402
+
403
+ Returns:
404
+
405
+ - order_metadata: shipping details, shipping_total, tax, total_price
406
+ - session_token: Required for confirm_checkout_session
407
+
408
+ The session_token expires, so confirm checkout soon after receiving it.
409
+
410
+ Headless checkout flow:
411
+
412
+ 1. create_checkout_session (get quote + token)
413
+ 2. collect_payment_details (save card via modal)
414
+ 3. confirm_checkout_session (finalize order)
415
+
416
+ Use hosted checkout (create_cart_checkout) for simpler implementation.
226
417
 
227
418
  ### Resource `orders`:
228
419
 
229
- - `retrieve_status_orders` (`read`) tags: [headless, hosted]: Retrieve the status and details of an order given order ID
420
+ - `retrieve_status_orders` (`read`) tags: [headless, hosted]: Check the status and details of an order using its order ID.
421
+
422
+ Returns:
423
+
424
+ - id: Order ID
425
+ - status: Current order status (e.g., "processing", "shipped", "delivered")
426
+ - statusMessage: Detailed status description
427
+ - products: Array with productName, quantity, productMetadata (variants)
428
+ - currency, subtotal, shipping, tax, grandTotal
429
+ - shippingDetails: Full delivery address
430
+ - userId: User who placed order
431
+ - cardLast4: Payment card used (last 4 digits)
432
+
433
+ Use for:
434
+
435
+ - Order tracking
436
+ - Status updates
437
+ - Order history
438
+ - Customer support
230
439
 
231
440
  ### Resource `wallet`:
232
441
 
233
- - `collect_payment_details` (`write`) tags: [headless]: Returns a modal URL for users to save payment cards. Supports both authenticated and guest card collection. Must be called at some point before checkout session is confirmed. After payment details are saved, they can proceed with checkout confirmation.
442
+ - `collect_payment_details` (`write`) tags: [headless]: Generate a modal URL for securely collecting payment card information via Stripe.
443
+
444
+ MUST be called in headless checkout flow BEFORE confirm_checkout_session.
445
+
446
+ Parameters:
447
+
448
+ - auth: true (default) - requires authentication, false for guest checkout
449
+
450
+ Returns:
451
+
452
+ - modal_url: Stripe-hosted page for card collection
453
+
454
+ Workflow:
455
+
456
+ 1. Call this endpoint
457
+ 2. Direct user to modal_url to enter payment details
458
+ 3. After user completes payment form, proceed with confirm_checkout_session
459
+
460
+ The modal handles:
461
+
462
+ - PCI-compliant card collection
463
+ - Card validation
464
+ - Secure tokenization
465
+ - Saving card for future use
466
+
467
+ For hosted checkout, payment collection is automatic (use create_cart_checkout instead).
@@ -1 +1 @@
1
- {"version":3,"file":"code-tool-worker.d.mts","sourceRoot":"","sources":["src/code-tool-worker.ts"],"names":[],"mappings":";iBAyC0B,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC;;AAmDrD,wBAAyB"}
1
+ {"version":3,"file":"code-tool-worker.d.mts","sourceRoot":"","sources":["src/code-tool-worker.ts"],"names":[],"mappings":";iBA2J0B,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC;;AAwDrD,wBAAyB"}
@@ -1 +1 @@
1
- {"version":3,"file":"code-tool-worker.d.ts","sourceRoot":"","sources":["src/code-tool-worker.ts"],"names":[],"mappings":";iBAyC0B,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC;;AAmDrD,wBAAyB"}
1
+ {"version":3,"file":"code-tool-worker.d.ts","sourceRoot":"","sources":["src/code-tool-worker.ts"],"names":[],"mappings":";iBA2J0B,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC;;AAwDrD,wBAAyB"}
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const node_util_1 = __importDefault(require("node:util"));
8
+ const fuse_js_1 = __importDefault(require("fuse.js"));
8
9
  const typescript_1 = __importDefault(require("typescript"));
9
10
  const sdk_1 = require("@henrylabs/sdk");
10
11
  function getRunFunctionNode(code) {
@@ -31,8 +32,101 @@ function getRunFunctionNode(code) {
31
32
  }
32
33
  return null;
33
34
  }
35
+ const fuse = new fuse_js_1.default([
36
+ 'client.products.retrieveDetails',
37
+ 'client.products.search',
38
+ 'client.products.variantCheck.create',
39
+ 'client.products.variantCheck.retrieveStatus',
40
+ 'client.cart.createCheckout',
41
+ 'client.cart.items.add',
42
+ 'client.cart.items.clear',
43
+ 'client.cart.items.list',
44
+ 'client.cart.items.remove',
45
+ 'client.checkout.session.confirmCheckout',
46
+ 'client.checkout.session.createQuote',
47
+ 'client.checkout.session.listProducts',
48
+ 'client.checkout.session.retrieveShippingInfo',
49
+ 'client.orders.retrieveStatus',
50
+ 'client.wallet.createCardCollection',
51
+ 'client.merchants.checkStatus',
52
+ 'client.merchants.getShippingInfo',
53
+ 'client.merchants.listSupported',
54
+ ], { threshold: 1, shouldSort: true });
55
+ function getMethodSuggestions(fullyQualifiedMethodName) {
56
+ return fuse
57
+ .search(fullyQualifiedMethodName)
58
+ .map(({ item }) => item)
59
+ .slice(0, 5);
60
+ }
61
+ const proxyToObj = new WeakMap();
62
+ const objToProxy = new WeakMap();
63
+ function makeSdkProxy(obj, { path, isBelievedBad = false }) {
64
+ let proxy = objToProxy.get(obj);
65
+ if (!proxy) {
66
+ proxy = new Proxy(obj, {
67
+ get(target, prop, receiver) {
68
+ const propPath = [...path, String(prop)];
69
+ const value = Reflect.get(target, prop, receiver);
70
+ if (isBelievedBad || (!(prop in target) && value === undefined)) {
71
+ // If we're accessing a path that doesn't exist, it will probably eventually error.
72
+ // Let's proxy it and mark it bad so that we can control the error message.
73
+ // We proxy an empty class so that an invocation or construction attempt is possible.
74
+ return makeSdkProxy(class {
75
+ }, { path: propPath, isBelievedBad: true });
76
+ }
77
+ if (value !== null && (typeof value === 'object' || typeof value === 'function')) {
78
+ return makeSdkProxy(value, { path: propPath, isBelievedBad });
79
+ }
80
+ return value;
81
+ },
82
+ apply(target, thisArg, args) {
83
+ if (isBelievedBad || typeof target !== 'function') {
84
+ const fullyQualifiedMethodName = path.join('.');
85
+ const suggestions = getMethodSuggestions(fullyQualifiedMethodName);
86
+ throw new Error(`${fullyQualifiedMethodName} is not a function. Did you mean: ${suggestions.join(', ')}`);
87
+ }
88
+ return Reflect.apply(target, proxyToObj.get(thisArg) ?? thisArg, args);
89
+ },
90
+ construct(target, args, newTarget) {
91
+ if (isBelievedBad || typeof target !== 'function') {
92
+ const fullyQualifiedMethodName = path.join('.');
93
+ const suggestions = getMethodSuggestions(fullyQualifiedMethodName);
94
+ throw new Error(`${fullyQualifiedMethodName} is not a constructor. Did you mean: ${suggestions.join(', ')}`);
95
+ }
96
+ return Reflect.construct(target, args, newTarget);
97
+ },
98
+ });
99
+ objToProxy.set(obj, proxy);
100
+ proxyToObj.set(proxy, obj);
101
+ }
102
+ return proxy;
103
+ }
104
+ function parseError(code, error) {
105
+ if (!(error instanceof Error))
106
+ return;
107
+ const message = error.name ? `${error.name}: ${error.message}` : error.message;
108
+ try {
109
+ // Deno uses V8; the first "<anonymous>:LINE:COLUMN" is the top of stack.
110
+ const lineNumber = error.stack?.match(/<anonymous>:([0-9]+):[0-9]+/)?.[1];
111
+ // -1 for the zero-based indexing
112
+ const line = lineNumber &&
113
+ code
114
+ .split('\n')
115
+ .at(parseInt(lineNumber, 10) - 1)
116
+ ?.trim();
117
+ return line ? `${message}\n at line ${lineNumber}\n ${line}` : message;
118
+ }
119
+ catch {
120
+ return message;
121
+ }
122
+ }
34
123
  const fetch = async (req) => {
35
124
  const { opts, code } = (await req.json());
125
+ if (code == null) {
126
+ return Response.json({
127
+ message: 'The code param is missing. Provide one containing a top-level `run` function. Write code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```',
128
+ }, { status: 400, statusText: 'Code execution error' });
129
+ }
36
130
  const runFunctionNode = getRunFunctionNode(code);
37
131
  if (!runFunctionNode) {
38
132
  return Response.json({
@@ -54,11 +148,8 @@ const fetch = async (req) => {
54
148
  };
55
149
  try {
56
150
  let run_ = async (client) => { };
57
- eval(`
58
- ${code}
59
- run_ = run;
60
- `);
61
- const result = await run_(client);
151
+ eval(`${code}\nrun_ = run;`);
152
+ const result = await run_(makeSdkProxy(client, { path: ['client'] }));
62
153
  return Response.json({
63
154
  result,
64
155
  logLines,
@@ -66,9 +157,8 @@ const fetch = async (req) => {
66
157
  });
67
158
  }
68
159
  catch (e) {
69
- const message = e instanceof Error ? e.message : undefined;
70
160
  return Response.json({
71
- message,
161
+ message: parseError(code, e),
72
162
  }, { status: 400, statusText: 'Code execution error' });
73
163
  }
74
164
  };
@@ -1 +1 @@
1
- {"version":3,"file":"code-tool-worker.js","sourceRoot":"","sources":["src/code-tool-worker.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;AAEtF,0DAA6B;AAE7B,4DAA4B;AAG5B,wCAA0C;AAE1C,SAAS,kBAAkB,CACzB,IAAY;IAEZ,MAAM,UAAU,GAAG,oBAAE,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,EAAE,oBAAE,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAEtF,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;QAC9C,4CAA4C;QAC5C,IAAI,oBAAE,CAAC,qBAAqB,CAAC,SAAS,CAAC,EAAE,CAAC;YACxC,IAAI,SAAS,CAAC,IAAI,EAAE,IAAI,KAAK,KAAK,EAAE,CA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@ -1,5 +1,6 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
  import util from 'node:util';
3
+ import Fuse from 'fuse.js';
3
4
  import ts from 'typescript';
4
5
  import { HenrySDK } from '@henrylabs/sdk';
5
6
  function getRunFunctionNode(code) {
@@ -26,8 +27,101 @@ function getRunFunctionNode(code) {
26
27
  }
27
28
  return null;
28
29
  }
30
+ const fuse = new Fuse([
31
+ 'client.products.retrieveDetails',
32
+ 'client.products.search',
33
+ 'client.products.variantCheck.create',
34
+ 'client.products.variantCheck.retrieveStatus',
35
+ 'client.cart.createCheckout',
36
+ 'client.cart.items.add',
37
+ 'client.cart.items.clear',
38
+ 'client.cart.items.list',
39
+ 'client.cart.items.remove',
40
+ 'client.checkout.session.confirmCheckout',
41
+ 'client.checkout.session.createQuote',
42
+ 'client.checkout.session.listProducts',
43
+ 'client.checkout.session.retrieveShippingInfo',
44
+ 'client.orders.retrieveStatus',
45
+ 'client.wallet.createCardCollection',
46
+ 'client.merchants.checkStatus',
47
+ 'client.merchants.getShippingInfo',
48
+ 'client.merchants.listSupported',
49
+ ], { threshold: 1, shouldSort: true });
50
+ function getMethodSuggestions(fullyQualifiedMethodName) {
51
+ return fuse
52
+ .search(fullyQualifiedMethodName)
53
+ .map(({ item }) => item)
54
+ .slice(0, 5);
55
+ }
56
+ const proxyToObj = new WeakMap();
57
+ const objToProxy = new WeakMap();
58
+ function makeSdkProxy(obj, { path, isBelievedBad = false }) {
59
+ let proxy = objToProxy.get(obj);
60
+ if (!proxy) {
61
+ proxy = new Proxy(obj, {
62
+ get(target, prop, receiver) {
63
+ const propPath = [...path, String(prop)];
64
+ const value = Reflect.get(target, prop, receiver);
65
+ if (isBelievedBad || (!(prop in target) && value === undefined)) {
66
+ // If we're accessing a path that doesn't exist, it will probably eventually error.
67
+ // Let's proxy it and mark it bad so that we can control the error message.
68
+ // We proxy an empty class so that an invocation or construction attempt is possible.
69
+ return makeSdkProxy(class {
70
+ }, { path: propPath, isBelievedBad: true });
71
+ }
72
+ if (value !== null && (typeof value === 'object' || typeof value === 'function')) {
73
+ return makeSdkProxy(value, { path: propPath, isBelievedBad });
74
+ }
75
+ return value;
76
+ },
77
+ apply(target, thisArg, args) {
78
+ if (isBelievedBad || typeof target !== 'function') {
79
+ const fullyQualifiedMethodName = path.join('.');
80
+ const suggestions = getMethodSuggestions(fullyQualifiedMethodName);
81
+ throw new Error(`${fullyQualifiedMethodName} is not a function. Did you mean: ${suggestions.join(', ')}`);
82
+ }
83
+ return Reflect.apply(target, proxyToObj.get(thisArg) ?? thisArg, args);
84
+ },
85
+ construct(target, args, newTarget) {
86
+ if (isBelievedBad || typeof target !== 'function') {
87
+ const fullyQualifiedMethodName = path.join('.');
88
+ const suggestions = getMethodSuggestions(fullyQualifiedMethodName);
89
+ throw new Error(`${fullyQualifiedMethodName} is not a constructor. Did you mean: ${suggestions.join(', ')}`);
90
+ }
91
+ return Reflect.construct(target, args, newTarget);
92
+ },
93
+ });
94
+ objToProxy.set(obj, proxy);
95
+ proxyToObj.set(proxy, obj);
96
+ }
97
+ return proxy;
98
+ }
99
+ function parseError(code, error) {
100
+ if (!(error instanceof Error))
101
+ return;
102
+ const message = error.name ? `${error.name}: ${error.message}` : error.message;
103
+ try {
104
+ // Deno uses V8; the first "<anonymous>:LINE:COLUMN" is the top of stack.
105
+ const lineNumber = error.stack?.match(/<anonymous>:([0-9]+):[0-9]+/)?.[1];
106
+ // -1 for the zero-based indexing
107
+ const line = lineNumber &&
108
+ code
109
+ .split('\n')
110
+ .at(parseInt(lineNumber, 10) - 1)
111
+ ?.trim();
112
+ return line ? `${message}\n at line ${lineNumber}\n ${line}` : message;
113
+ }
114
+ catch {
115
+ return message;
116
+ }
117
+ }
29
118
  const fetch = async (req) => {
30
119
  const { opts, code } = (await req.json());
120
+ if (code == null) {
121
+ return Response.json({
122
+ message: 'The code param is missing. Provide one containing a top-level `run` function. Write code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```',
123
+ }, { status: 400, statusText: 'Code execution error' });
124
+ }
31
125
  const runFunctionNode = getRunFunctionNode(code);
32
126
  if (!runFunctionNode) {
33
127
  return Response.json({
@@ -49,11 +143,8 @@ const fetch = async (req) => {
49
143
  };
50
144
  try {
51
145
  let run_ = async (client) => { };
52
- eval(`
53
- ${code}
54
- run_ = run;
55
- `);
56
- const result = await run_(client);
146
+ eval(`${code}\nrun_ = run;`);
147
+ const result = await run_(makeSdkProxy(client, { path: ['client'] }));
57
148
  return Response.json({
58
149
  result,
59
150
  logLines,
@@ -61,9 +152,8 @@ const fetch = async (req) => {
61
152
  });
62
153
  }
63
154
  catch (e) {
64
- const message = e instanceof Error ? e.message : undefined;
65
155
  return Response.json({
66
- message,
156
+ message: parseError(code, e),
67
157
  }, { status: 400, statusText: 'Code execution error' });
68
158
  }
69
159
  };
@@ -1 +1 @@
1
- {"version":3,"file":"code-tool-worker.mjs","sourceRoot":"","sources":["src/code-tool-worker.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,IAAI,MAAM,WAAW;OAErB,EAAE,MAAM,YAAY;OAGpB,EAAE,QAAQ,EAAE,MAAM,gBAAgB;AAEzC,SAAS,kBAAkB,CACzB,IAAY;IAEZ,MAAM,UAAU,GAAG,EAAE,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAEtF,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;QAC9C,4CAA4C;QAC5C,IAAI,EAAE,CAAC,qBAAqB,CAAC,SAAS,CAAC,EAAE,CAAC;YACxC,IAAI,SAAS,CAAC,IAAI,EAAE,IAAI,KAAK,KAAK,EAAE,CAAC;gBACnC,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;QAED,qFAAqF;QACrF,IAAI,EAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC;YACtC,KAAK,MAAM,WA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MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC;QAC1B,GAAG,IAAI;KACR,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,OAAO,GAAG;QACd,GAAG,EAAE,CAAC,GAAG,IAAe,EAAE,EAAE;YAC1B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACtC,CAAC;QACD,KAAK,EAAE,CAAC,GAAG,IAAe,EAAE,EAAE;YAC5B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACtC,CAAC;KACF,CAAC;IACF,IAAI,CAAC;QACH,IAAI,IAAI,GAAG,KAAK,EAAE,MAAW,EAAE,EAAE,GAAE,CAAC,CAAC;QACrC,IAAI,CAAC,GAAG,IAAI,eAAe,CAAC,CAAC;QAC7B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;QACtE,OAAO,QAAQ,CAAC,IAAI,CAAC;YACnB,MAAM;YACN,QAAQ;YACR,QAAQ;SACe,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,QAAQ,CAAC,IAAI,CAClB;YACE,OAAO,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;SACP,EACvB,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,sBAAsB,EAAE,CACpD,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,EAAE,KAAK,EAAE,CAAC"}
package/code-tool.js CHANGED
@@ -50,7 +50,7 @@ async function codeTool() {
50
50
  const metadata = { resource: 'all', operation: 'write', tags: [] };
51
51
  const tool = {
52
52
  name: 'execute',
53
- description: 'Runs TypeScript code to interact with the API.\nYou are a skilled programmer writing code to interface with the service.\nDefine an async function named "run" that takes a single parameter of an initialized client, and it will be run.\nDo not initialize a client, but instead use the client that you are given as a parameter.\nYou will be returned anything that your function returns, plus the results of any console.log statements.\nIf any code triggers an error, the tool will return an error response, so you do not need to add error handling unless you want to output something more helpful than the raw error.\nIt is not necessary to add comments to code, unless by adding those comments you believe that you can generate better code.\nThis code will run in a container, and you will not be able to use fetch or otherwise interact with the network calls other than through the client you are given.\nAny variables you define won\'t live between successive uses of this call, so make sure to return or log any data you might need later.',
53
+ description: 'Runs JavaScript code to interact with the API.\n\nYou are a skilled programmer writing code to interface with the service.\nDefine an async function named "run" that takes a single parameter of an initialized client named "client", and it will be run.\nWrite code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```\n\nYou will be returned anything that your function returns, plus the results of any console.log statements.\nIf any code triggers an error, the tool will return an error response, so you do not need to add error handling unless you want to output something more helpful than the raw error.\nIt is not necessary to add comments to code, unless by adding those comments you believe that you can generate better code.\nThis code will run in a container, and you will not be able to use fetch or otherwise interact with the network calls other than through the client you are given.\nAny variables you define won\'t live between successive uses of this call, so make sure to return or log any data you might need later.',
54
54
  inputSchema: { type: 'object', properties: { code: { type: 'string' } } },
55
55
  };
56
56
  // Import dynamically to avoid failing at import time in cases where the environment is not well-supported.
package/code-tool.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"code-tool.js","sourceRoot":"","sources":["src/code-tool.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBtF,4BA8HC;AAhJD,yCAAoC;AACpC,uCAAyC;AAQzC;;;;;;;;GAQG;AACI,KAAK,UAAU,QAAQ;IAC5B,MAAM,QAAQ,GAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IAC7E,MAAM,IAAI,GAAS;QACjB,IAAI,EAAE,S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CAAC,IAAI,CAAC;qBAC1B,CAAC;gBACN,MAAM,SAAS,GACb,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;oBACrB,IAAI;oBACN,CAAC,CAAC;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,iBAAiB,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;qBAC9C,CAAC;gBACN,OAAO;oBACL,OAAO,EAAE,CAAC,YAAY,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC;iBAChF,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAgB,CAAC;gBACvD,OAAO;oBACL,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;oBACjE,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,SAAS,EAAE,CAAC;QACrB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AACrC,CAAC"}
package/code-tool.mjs CHANGED
@@ -14,7 +14,7 @@ export async function codeTool() {
14
14
  const metadata = { resource: 'all', operation: 'write', tags: [] };
15
15
  const tool = {
16
16
  name: 'execute',
17
- description: 'Runs TypeScript code to interact with the API.\nYou are a skilled programmer writing code to interface with the service.\nDefine an async function named "run" that takes a single parameter of an initialized client, and it will be run.\nDo not initialize a client, but instead use the client that you are given as a parameter.\nYou will be returned anything that your function returns, plus the results of any console.log statements.\nIf any code triggers an error, the tool will return an error response, so you do not need to add error handling unless you want to output something more helpful than the raw error.\nIt is not necessary to add comments to code, unless by adding those comments you believe that you can generate better code.\nThis code will run in a container, and you will not be able to use fetch or otherwise interact with the network calls other than through the client you are given.\nAny variables you define won\'t live between successive uses of this call, so make sure to return or log any data you might need later.',
17
+ description: 'Runs JavaScript code to interact with the API.\n\nYou are a skilled programmer writing code to interface with the service.\nDefine an async function named "run" that takes a single parameter of an initialized client named "client", and it will be run.\nWrite code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```\n\nYou will be returned anything that your function returns, plus the results of any console.log statements.\nIf any code triggers an error, the tool will return an error response, so you do not need to add error handling unless you want to output something more helpful than the raw error.\nIt is not necessary to add comments to code, unless by adding those comments you believe that you can generate better code.\nThis code will run in a container, and you will not be able to use fetch or otherwise interact with the network calls other than through the client you are given.\nAny variables you define won\'t live between successive uses of this call, so make sure to return or log any data you might need later.',
18
18
  inputSchema: { type: 'object', properties: { code: { type: 'string' } } },
19
19
  };
20
20
  // Import dynamically to avoid failing at import time in cases where the environment is not well-supported.