@henrylabs/mcp 0.14.0 → 0.15.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.
- package/code-tool-types.d.mts +2 -0
- package/code-tool-types.d.mts.map +1 -1
- package/code-tool-types.d.ts +2 -0
- package/code-tool-types.d.ts.map +1 -1
- package/code-tool.d.mts +44 -2
- package/code-tool.d.mts.map +1 -1
- package/code-tool.d.ts +44 -2
- package/code-tool.d.ts.map +1 -1
- package/code-tool.js +22 -129
- package/code-tool.js.map +1 -1
- package/code-tool.mjs +22 -96
- package/code-tool.mjs.map +1 -1
- package/docs-search-tool.d.mts +12 -6
- package/docs-search-tool.d.mts.map +1 -1
- package/docs-search-tool.d.ts +12 -6
- package/docs-search-tool.d.ts.map +1 -1
- package/docs-search-tool.js +3 -0
- package/docs-search-tool.js.map +1 -1
- package/docs-search-tool.mjs +3 -0
- package/docs-search-tool.mjs.map +1 -1
- package/package.json +3 -19
- package/server.js +1 -1
- package/server.mjs +1 -1
- package/src/code-tool-types.ts +5 -1
- package/src/code-tool.ts +32 -121
- package/src/docs-search-tool.ts +7 -0
- package/src/server.ts +1 -1
- package/src/tools/cart/create-cart-checkout.ts +5 -1
- package/src/tools/cart/items/add-cart-items.ts +1 -1
- package/src/tools/cart/items/clear-cart-items.ts +1 -1
- package/src/tools/cart/items/list-cart-items.ts +1 -1
- package/src/tools/cart/items/remove-cart-items.ts +1 -1
- package/src/tools/orders/retrieve-status-orders.ts +1 -1
- package/src/tools/products/retrieve-product-details.ts +9 -2
- package/src/tools/products/search-products.ts +1 -1
- package/src/tools/wallet/collect-payment-details.ts +1 -1
- package/tools/cart/create-cart-checkout.d.mts +12 -6
- package/tools/cart/create-cart-checkout.d.mts.map +1 -1
- package/tools/cart/create-cart-checkout.d.ts +12 -6
- package/tools/cart/create-cart-checkout.d.ts.map +1 -1
- package/tools/cart/create-cart-checkout.js +9 -1
- package/tools/cart/create-cart-checkout.js.map +1 -1
- package/tools/cart/create-cart-checkout.mjs +6 -1
- package/tools/cart/create-cart-checkout.mjs.map +1 -1
- package/tools/cart/items/add-cart-items.d.mts +12 -6
- package/tools/cart/items/add-cart-items.d.mts.map +1 -1
- package/tools/cart/items/add-cart-items.d.ts +12 -6
- package/tools/cart/items/add-cart-items.d.ts.map +1 -1
- package/tools/cart/items/add-cart-items.js +5 -1
- package/tools/cart/items/add-cart-items.js.map +1 -1
- package/tools/cart/items/add-cart-items.mjs +2 -1
- package/tools/cart/items/add-cart-items.mjs.map +1 -1
- package/tools/cart/items/clear-cart-items.d.mts +12 -6
- package/tools/cart/items/clear-cart-items.d.mts.map +1 -1
- package/tools/cart/items/clear-cart-items.d.ts +12 -6
- package/tools/cart/items/clear-cart-items.d.ts.map +1 -1
- package/tools/cart/items/clear-cart-items.js +5 -1
- package/tools/cart/items/clear-cart-items.js.map +1 -1
- package/tools/cart/items/clear-cart-items.mjs +2 -1
- package/tools/cart/items/clear-cart-items.mjs.map +1 -1
- package/tools/cart/items/list-cart-items.d.mts +12 -6
- package/tools/cart/items/list-cart-items.d.mts.map +1 -1
- package/tools/cart/items/list-cart-items.d.ts +12 -6
- package/tools/cart/items/list-cart-items.d.ts.map +1 -1
- package/tools/cart/items/list-cart-items.js +5 -1
- package/tools/cart/items/list-cart-items.js.map +1 -1
- package/tools/cart/items/list-cart-items.mjs +2 -1
- package/tools/cart/items/list-cart-items.mjs.map +1 -1
- package/tools/cart/items/remove-cart-items.d.mts +12 -6
- package/tools/cart/items/remove-cart-items.d.mts.map +1 -1
- package/tools/cart/items/remove-cart-items.d.ts +12 -6
- package/tools/cart/items/remove-cart-items.d.ts.map +1 -1
- package/tools/cart/items/remove-cart-items.js +5 -1
- package/tools/cart/items/remove-cart-items.js.map +1 -1
- package/tools/cart/items/remove-cart-items.mjs +2 -1
- package/tools/cart/items/remove-cart-items.mjs.map +1 -1
- package/tools/orders/retrieve-status-orders.d.mts +12 -6
- package/tools/orders/retrieve-status-orders.d.mts.map +1 -1
- package/tools/orders/retrieve-status-orders.d.ts +12 -6
- package/tools/orders/retrieve-status-orders.d.ts.map +1 -1
- package/tools/orders/retrieve-status-orders.js +5 -1
- package/tools/orders/retrieve-status-orders.js.map +1 -1
- package/tools/orders/retrieve-status-orders.mjs +2 -1
- package/tools/orders/retrieve-status-orders.mjs.map +1 -1
- package/tools/products/retrieve-product-details.d.mts +12 -6
- package/tools/products/retrieve-product-details.d.mts.map +1 -1
- package/tools/products/retrieve-product-details.d.ts +12 -6
- package/tools/products/retrieve-product-details.d.ts.map +1 -1
- package/tools/products/retrieve-product-details.js +13 -1
- package/tools/products/retrieve-product-details.js.map +1 -1
- package/tools/products/retrieve-product-details.mjs +11 -2
- package/tools/products/retrieve-product-details.mjs.map +1 -1
- package/tools/products/search-products.d.mts +12 -6
- package/tools/products/search-products.d.mts.map +1 -1
- package/tools/products/search-products.d.ts +12 -6
- package/tools/products/search-products.d.ts.map +1 -1
- package/tools/products/search-products.js +5 -1
- package/tools/products/search-products.js.map +1 -1
- package/tools/products/search-products.mjs +2 -1
- package/tools/products/search-products.mjs.map +1 -1
- package/tools/wallet/collect-payment-details.d.mts +12 -6
- package/tools/wallet/collect-payment-details.d.mts.map +1 -1
- package/tools/wallet/collect-payment-details.d.ts +12 -6
- package/tools/wallet/collect-payment-details.d.ts.map +1 -1
- package/tools/wallet/collect-payment-details.js +5 -1
- package/tools/wallet/collect-payment-details.js.map +1 -1
- package/tools/wallet/collect-payment-details.mjs +2 -1
- package/tools/wallet/collect-payment-details.mjs.map +1 -1
- package/code-tool-paths.cjs +0 -6
- package/code-tool-paths.cjs.map +0 -1
- package/code-tool-paths.d.cts +0 -2
- package/code-tool-paths.d.cts.map +0 -1
- package/code-tool-worker.d.mts +0 -5
- package/code-tool-worker.d.mts.map +0 -1
- package/code-tool-worker.d.ts +0 -5
- package/code-tool-worker.d.ts.map +0 -1
- package/code-tool-worker.js +0 -162
- package/code-tool-worker.js.map +0 -1
- package/code-tool-worker.mjs +0 -157
- package/code-tool-worker.mjs.map +0 -1
- package/src/code-tool-paths.cts +0 -3
- package/src/code-tool-worker.ts +0 -208
package/src/code-tool-worker.ts
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
-
|
|
3
|
-
import util from 'node:util';
|
|
4
|
-
|
|
5
|
-
import Fuse from 'fuse.js';
|
|
6
|
-
import ts from 'typescript';
|
|
7
|
-
|
|
8
|
-
import { WorkerInput, WorkerSuccess, WorkerError } from './code-tool-types';
|
|
9
|
-
import { HenrySDK } from '@henrylabs/sdk';
|
|
10
|
-
|
|
11
|
-
function getRunFunctionNode(
|
|
12
|
-
code: string,
|
|
13
|
-
): ts.FunctionDeclaration | ts.FunctionExpression | ts.ArrowFunction | null {
|
|
14
|
-
const sourceFile = ts.createSourceFile('code.ts', code, ts.ScriptTarget.Latest, true);
|
|
15
|
-
|
|
16
|
-
for (const statement of sourceFile.statements) {
|
|
17
|
-
// Check for top-level function declarations
|
|
18
|
-
if (ts.isFunctionDeclaration(statement)) {
|
|
19
|
-
if (statement.name?.text === 'run') {
|
|
20
|
-
return statement;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Check for variable declarations: const run = () => {} or const run = function() {}
|
|
25
|
-
if (ts.isVariableStatement(statement)) {
|
|
26
|
-
for (const declaration of statement.declarationList.declarations) {
|
|
27
|
-
if (ts.isIdentifier(declaration.name) && declaration.name.text === 'run') {
|
|
28
|
-
// Check if it's initialized with a function
|
|
29
|
-
if (
|
|
30
|
-
declaration.initializer &&
|
|
31
|
-
(ts.isFunctionExpression(declaration.initializer) || ts.isArrowFunction(declaration.initializer))
|
|
32
|
-
) {
|
|
33
|
-
return declaration.initializer;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const fuse = new Fuse(
|
|
44
|
-
[
|
|
45
|
-
'client.products.retrieveDetails',
|
|
46
|
-
'client.products.search',
|
|
47
|
-
'client.products.variantCheck.create',
|
|
48
|
-
'client.products.variantCheck.retrieveStatus',
|
|
49
|
-
'client.cart.createCheckout',
|
|
50
|
-
'client.cart.items.add',
|
|
51
|
-
'client.cart.items.clear',
|
|
52
|
-
'client.cart.items.list',
|
|
53
|
-
'client.cart.items.remove',
|
|
54
|
-
'client.orders.retrieveStatus',
|
|
55
|
-
'client.wallet.createCardCollection',
|
|
56
|
-
'client.merchants.checkStatus',
|
|
57
|
-
'client.merchants.getShippingInfo',
|
|
58
|
-
'client.merchants.listSupported',
|
|
59
|
-
],
|
|
60
|
-
{ threshold: 1, shouldSort: true },
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
function getMethodSuggestions(fullyQualifiedMethodName: string): string[] {
|
|
64
|
-
return fuse
|
|
65
|
-
.search(fullyQualifiedMethodName)
|
|
66
|
-
.map(({ item }) => item)
|
|
67
|
-
.slice(0, 5);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const proxyToObj = new WeakMap<any, any>();
|
|
71
|
-
const objToProxy = new WeakMap<any, any>();
|
|
72
|
-
|
|
73
|
-
type ClientProxyConfig = {
|
|
74
|
-
path: string[];
|
|
75
|
-
isBelievedBad?: boolean;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
function makeSdkProxy<T extends object>(obj: T, { path, isBelievedBad = false }: ClientProxyConfig): T {
|
|
79
|
-
let proxy: T = objToProxy.get(obj);
|
|
80
|
-
|
|
81
|
-
if (!proxy) {
|
|
82
|
-
proxy = new Proxy(obj, {
|
|
83
|
-
get(target, prop, receiver) {
|
|
84
|
-
const propPath = [...path, String(prop)];
|
|
85
|
-
const value = Reflect.get(target, prop, receiver);
|
|
86
|
-
|
|
87
|
-
if (isBelievedBad || (!(prop in target) && value === undefined)) {
|
|
88
|
-
// If we're accessing a path that doesn't exist, it will probably eventually error.
|
|
89
|
-
// Let's proxy it and mark it bad so that we can control the error message.
|
|
90
|
-
// We proxy an empty class so that an invocation or construction attempt is possible.
|
|
91
|
-
return makeSdkProxy(class {}, { path: propPath, isBelievedBad: true });
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (value !== null && (typeof value === 'object' || typeof value === 'function')) {
|
|
95
|
-
return makeSdkProxy(value, { path: propPath, isBelievedBad });
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return value;
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
apply(target, thisArg, args) {
|
|
102
|
-
if (isBelievedBad || typeof target !== 'function') {
|
|
103
|
-
const fullyQualifiedMethodName = path.join('.');
|
|
104
|
-
const suggestions = getMethodSuggestions(fullyQualifiedMethodName);
|
|
105
|
-
throw new Error(
|
|
106
|
-
`${fullyQualifiedMethodName} is not a function. Did you mean: ${suggestions.join(', ')}`,
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return Reflect.apply(target, proxyToObj.get(thisArg) ?? thisArg, args);
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
construct(target, args, newTarget) {
|
|
114
|
-
if (isBelievedBad || typeof target !== 'function') {
|
|
115
|
-
const fullyQualifiedMethodName = path.join('.');
|
|
116
|
-
const suggestions = getMethodSuggestions(fullyQualifiedMethodName);
|
|
117
|
-
throw new Error(
|
|
118
|
-
`${fullyQualifiedMethodName} is not a constructor. Did you mean: ${suggestions.join(', ')}`,
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return Reflect.construct(target, args, newTarget);
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
objToProxy.set(obj, proxy);
|
|
127
|
-
proxyToObj.set(proxy, obj);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return proxy;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function parseError(code: string, error: unknown): string | undefined {
|
|
134
|
-
if (!(error instanceof Error)) return;
|
|
135
|
-
const message = error.name ? `${error.name}: ${error.message}` : error.message;
|
|
136
|
-
try {
|
|
137
|
-
// Deno uses V8; the first "<anonymous>:LINE:COLUMN" is the top of stack.
|
|
138
|
-
const lineNumber = error.stack?.match(/<anonymous>:([0-9]+):[0-9]+/)?.[1];
|
|
139
|
-
// -1 for the zero-based indexing
|
|
140
|
-
const line =
|
|
141
|
-
lineNumber &&
|
|
142
|
-
code
|
|
143
|
-
.split('\n')
|
|
144
|
-
.at(parseInt(lineNumber, 10) - 1)
|
|
145
|
-
?.trim();
|
|
146
|
-
return line ? `${message}\n at line ${lineNumber}\n ${line}` : message;
|
|
147
|
-
} catch {
|
|
148
|
-
return message;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const fetch = async (req: Request): Promise<Response> => {
|
|
153
|
-
const { opts, code } = (await req.json()) as WorkerInput;
|
|
154
|
-
if (code == null) {
|
|
155
|
-
return Response.json(
|
|
156
|
-
{
|
|
157
|
-
message:
|
|
158
|
-
'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```',
|
|
159
|
-
} satisfies WorkerError,
|
|
160
|
-
{ status: 400, statusText: 'Code execution error' },
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const runFunctionNode = getRunFunctionNode(code);
|
|
165
|
-
if (!runFunctionNode) {
|
|
166
|
-
return Response.json(
|
|
167
|
-
{
|
|
168
|
-
message:
|
|
169
|
-
'The code is missing a top-level `run` function. Write code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```',
|
|
170
|
-
} satisfies WorkerError,
|
|
171
|
-
{ status: 400, statusText: 'Code execution error' },
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const client = new HenrySDK({
|
|
176
|
-
...opts,
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
const logLines: string[] = [];
|
|
180
|
-
const errLines: string[] = [];
|
|
181
|
-
const console = {
|
|
182
|
-
log: (...args: unknown[]) => {
|
|
183
|
-
logLines.push(util.format(...args));
|
|
184
|
-
},
|
|
185
|
-
error: (...args: unknown[]) => {
|
|
186
|
-
errLines.push(util.format(...args));
|
|
187
|
-
},
|
|
188
|
-
};
|
|
189
|
-
try {
|
|
190
|
-
let run_ = async (client: any) => {};
|
|
191
|
-
eval(`${code}\nrun_ = run;`);
|
|
192
|
-
const result = await run_(makeSdkProxy(client, { path: ['client'] }));
|
|
193
|
-
return Response.json({
|
|
194
|
-
result,
|
|
195
|
-
logLines,
|
|
196
|
-
errLines,
|
|
197
|
-
} satisfies WorkerSuccess);
|
|
198
|
-
} catch (e) {
|
|
199
|
-
return Response.json(
|
|
200
|
-
{
|
|
201
|
-
message: parseError(code, e),
|
|
202
|
-
} satisfies WorkerError,
|
|
203
|
-
{ status: 400, statusText: 'Code execution error' },
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
export default { fetch };
|