@henrylabs/mcp 0.14.0 → 0.17.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/README.md +13 -334
- 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 +2 -2
- package/code-tool.d.mts.map +1 -1
- package/code-tool.d.ts +2 -2
- package/code-tool.d.ts.map +1 -1
- package/code-tool.js +27 -130
- package/code-tool.js.map +1 -1
- package/code-tool.mjs +27 -97
- package/code-tool.mjs.map +1 -1
- package/docs-search-tool.d.mts +15 -9
- package/docs-search-tool.d.mts.map +1 -1
- package/docs-search-tool.d.ts +15 -9
- package/docs-search-tool.d.ts.map +1 -1
- package/docs-search-tool.js +4 -1
- package/docs-search-tool.js.map +1 -1
- package/docs-search-tool.mjs +4 -1
- package/docs-search-tool.mjs.map +1 -1
- package/http.d.mts.map +1 -1
- package/http.d.ts.map +1 -1
- package/http.js +1 -18
- package/http.js.map +1 -1
- package/http.mjs +1 -18
- package/http.mjs.map +1 -1
- package/index.js +4 -40
- package/index.js.map +1 -1
- package/index.mjs +4 -40
- package/index.mjs.map +1 -1
- package/options.d.mts +0 -9
- package/options.d.mts.map +1 -1
- package/options.d.ts +0 -9
- package/options.d.ts.map +1 -1
- package/options.js +4 -359
- package/options.js.map +1 -1
- package/options.mjs +4 -359
- package/options.mjs.map +1 -1
- package/package.json +10 -66
- package/server.d.mts +3 -8
- package/server.d.mts.map +1 -1
- package/server.d.ts +3 -8
- package/server.d.ts.map +1 -1
- package/server.js +12 -65
- package/server.js.map +1 -1
- package/server.mjs +11 -62
- package/server.mjs.map +1 -1
- package/src/code-tool-types.ts +5 -1
- package/src/code-tool.ts +36 -121
- package/src/docs-search-tool.ts +8 -1
- package/src/http.ts +1 -19
- package/src/index.ts +5 -52
- package/src/options.ts +5 -386
- package/src/server.ts +12 -72
- package/src/stdio.ts +2 -3
- package/src/{tools/types.ts → types.ts} +1 -1
- package/stdio.d.mts +1 -2
- package/stdio.d.mts.map +1 -1
- package/stdio.d.ts +1 -2
- package/stdio.d.ts.map +1 -1
- package/stdio.js +2 -2
- package/stdio.js.map +1 -1
- package/stdio.mjs +2 -2
- package/stdio.mjs.map +1 -1
- package/{tools/types.d.mts → types.d.mts} +1 -1
- package/types.d.mts.map +1 -0
- package/{tools/types.d.ts → types.d.ts} +1 -1
- package/types.d.ts.map +1 -0
- package/types.js.map +1 -0
- package/types.mjs.map +1 -0
- 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/compat.d.mts +0 -58
- package/compat.d.mts.map +0 -1
- package/compat.d.ts +0 -58
- package/compat.d.ts.map +0 -1
- package/compat.js +0 -387
- package/compat.js.map +0 -1
- package/compat.mjs +0 -378
- package/compat.mjs.map +0 -1
- package/dynamic-tools.d.mts +0 -12
- package/dynamic-tools.d.mts.map +0 -1
- package/dynamic-tools.d.ts +0 -12
- package/dynamic-tools.d.ts.map +0 -1
- package/dynamic-tools.js +0 -135
- package/dynamic-tools.js.map +0 -1
- package/dynamic-tools.mjs +0 -132
- package/dynamic-tools.mjs.map +0 -1
- package/filtering.d.mts +0 -3
- package/filtering.d.mts.map +0 -1
- package/filtering.d.ts +0 -3
- package/filtering.d.ts.map +0 -1
- package/filtering.js +0 -24
- package/filtering.js.map +0 -1
- package/filtering.mjs +0 -16
- package/filtering.mjs.map +0 -1
- package/src/code-tool-paths.cts +0 -3
- package/src/code-tool-worker.ts +0 -208
- package/src/compat.ts +0 -483
- package/src/dynamic-tools.ts +0 -153
- package/src/filtering.ts +0 -18
- package/src/tools/cart/create-cart-checkout.ts +0 -56
- package/src/tools/cart/items/add-cart-items.ts +0 -100
- package/src/tools/cart/items/clear-cart-items.ts +0 -54
- package/src/tools/cart/items/list-cart-items.ts +0 -54
- package/src/tools/cart/items/remove-cart-items.ts +0 -57
- package/src/tools/index.ts +0 -87
- package/src/tools/orders/retrieve-status-orders.ts +0 -54
- package/src/tools/products/retrieve-product-details.ts +0 -41
- package/src/tools/products/search-products.ts +0 -110
- package/src/tools/wallet/collect-payment-details.ts +0 -56
- package/src/tools.ts +0 -1
- package/tools/cart/create-cart-checkout.d.mts +0 -45
- package/tools/cart/create-cart-checkout.d.mts.map +0 -1
- package/tools/cart/create-cart-checkout.d.ts +0 -45
- package/tools/cart/create-cart-checkout.d.ts.map +0 -1
- package/tools/cart/create-cart-checkout.js +0 -52
- package/tools/cart/create-cart-checkout.js.map +0 -1
- package/tools/cart/create-cart-checkout.mjs +0 -48
- package/tools/cart/create-cart-checkout.mjs.map +0 -1
- package/tools/cart/items/add-cart-items.d.mts +0 -45
- package/tools/cart/items/add-cart-items.d.mts.map +0 -1
- package/tools/cart/items/add-cart-items.d.ts +0 -45
- package/tools/cart/items/add-cart-items.d.ts.map +0 -1
- package/tools/cart/items/add-cart-items.js +0 -94
- package/tools/cart/items/add-cart-items.js.map +0 -1
- package/tools/cart/items/add-cart-items.mjs +0 -90
- package/tools/cart/items/add-cart-items.mjs.map +0 -1
- package/tools/cart/items/clear-cart-items.d.mts +0 -45
- package/tools/cart/items/clear-cart-items.d.mts.map +0 -1
- package/tools/cart/items/clear-cart-items.d.ts +0 -45
- package/tools/cart/items/clear-cart-items.d.ts.map +0 -1
- package/tools/cart/items/clear-cart-items.js +0 -50
- package/tools/cart/items/clear-cart-items.js.map +0 -1
- package/tools/cart/items/clear-cart-items.mjs +0 -46
- package/tools/cart/items/clear-cart-items.mjs.map +0 -1
- package/tools/cart/items/list-cart-items.d.mts +0 -45
- package/tools/cart/items/list-cart-items.d.mts.map +0 -1
- package/tools/cart/items/list-cart-items.d.ts +0 -45
- package/tools/cart/items/list-cart-items.d.ts.map +0 -1
- package/tools/cart/items/list-cart-items.js +0 -50
- package/tools/cart/items/list-cart-items.js.map +0 -1
- package/tools/cart/items/list-cart-items.mjs +0 -46
- package/tools/cart/items/list-cart-items.mjs.map +0 -1
- package/tools/cart/items/remove-cart-items.d.mts +0 -45
- package/tools/cart/items/remove-cart-items.d.mts.map +0 -1
- package/tools/cart/items/remove-cart-items.d.ts +0 -45
- package/tools/cart/items/remove-cart-items.d.ts.map +0 -1
- package/tools/cart/items/remove-cart-items.js +0 -53
- package/tools/cart/items/remove-cart-items.js.map +0 -1
- package/tools/cart/items/remove-cart-items.mjs +0 -49
- package/tools/cart/items/remove-cart-items.mjs.map +0 -1
- package/tools/index.d.mts +0 -10
- package/tools/index.d.mts.map +0 -1
- package/tools/index.d.ts +0 -10
- package/tools/index.d.ts.map +0 -1
- package/tools/index.js +0 -71
- package/tools/index.js.map +0 -1
- package/tools/index.mjs +0 -64
- package/tools/index.mjs.map +0 -1
- package/tools/orders/retrieve-status-orders.d.mts +0 -45
- package/tools/orders/retrieve-status-orders.d.mts.map +0 -1
- package/tools/orders/retrieve-status-orders.d.ts +0 -45
- package/tools/orders/retrieve-status-orders.d.ts.map +0 -1
- package/tools/orders/retrieve-status-orders.js +0 -50
- package/tools/orders/retrieve-status-orders.js.map +0 -1
- package/tools/orders/retrieve-status-orders.mjs +0 -46
- package/tools/orders/retrieve-status-orders.mjs.map +0 -1
- package/tools/products/retrieve-product-details.d.mts +0 -45
- package/tools/products/retrieve-product-details.d.mts.map +0 -1
- package/tools/products/retrieve-product-details.d.ts +0 -45
- package/tools/products/retrieve-product-details.d.ts.map +0 -1
- package/tools/products/retrieve-product-details.js +0 -37
- package/tools/products/retrieve-product-details.js.map +0 -1
- package/tools/products/retrieve-product-details.mjs +0 -33
- package/tools/products/retrieve-product-details.mjs.map +0 -1
- package/tools/products/search-products.d.mts +0 -45
- package/tools/products/search-products.d.mts.map +0 -1
- package/tools/products/search-products.d.ts +0 -45
- package/tools/products/search-products.d.ts.map +0 -1
- package/tools/products/search-products.js +0 -106
- package/tools/products/search-products.js.map +0 -1
- package/tools/products/search-products.mjs +0 -102
- package/tools/products/search-products.mjs.map +0 -1
- package/tools/types.d.mts.map +0 -1
- package/tools/types.d.ts.map +0 -1
- package/tools/types.js.map +0 -1
- package/tools/types.mjs.map +0 -1
- package/tools/wallet/collect-payment-details.d.mts +0 -45
- package/tools/wallet/collect-payment-details.d.mts.map +0 -1
- package/tools/wallet/collect-payment-details.d.ts +0 -45
- package/tools/wallet/collect-payment-details.d.ts.map +0 -1
- package/tools/wallet/collect-payment-details.js +0 -52
- package/tools/wallet/collect-payment-details.js.map +0 -1
- package/tools/wallet/collect-payment-details.mjs +0 -48
- package/tools/wallet/collect-payment-details.mjs.map +0 -1
- package/tools.d.mts +0 -2
- package/tools.d.mts.map +0 -1
- package/tools.d.ts +0 -2
- package/tools.d.ts.map +0 -1
- package/tools.js +0 -18
- package/tools.js.map +0 -1
- package/tools.mjs +0 -2
- package/tools.mjs.map +0 -1
- /package/{tools/types.js → types.js} +0 -0
- /package/{tools/types.mjs → types.mjs} +0 -0
package/dynamic-tools.mjs
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { asTextContentResult } from "./tools/types.mjs";
|
|
2
|
-
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
import { Cabidela } from '@cloudflare/cabidela';
|
|
5
|
-
function zodToInputSchema(schema) {
|
|
6
|
-
return {
|
|
7
|
-
type: 'object',
|
|
8
|
-
...zodToJsonSchema(schema),
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* A list of tools that expose all the endpoints in the API dynamically.
|
|
13
|
-
*
|
|
14
|
-
* Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
|
|
15
|
-
* we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
|
|
16
|
-
* a generic endpoint that can be used to invoke any endpoint with the provided arguments.
|
|
17
|
-
*
|
|
18
|
-
* @param endpoints - The endpoints to include in the list.
|
|
19
|
-
*/
|
|
20
|
-
export function dynamicTools(endpoints) {
|
|
21
|
-
const listEndpointsSchema = z.object({
|
|
22
|
-
search_query: z
|
|
23
|
-
.string()
|
|
24
|
-
.optional()
|
|
25
|
-
.describe('An optional search query to filter the endpoints by. Provide a partial name, resource, operation, or tag to filter the endpoints returned.'),
|
|
26
|
-
});
|
|
27
|
-
const listEndpointsTool = {
|
|
28
|
-
metadata: {
|
|
29
|
-
resource: 'dynamic_tools',
|
|
30
|
-
operation: 'read',
|
|
31
|
-
tags: [],
|
|
32
|
-
},
|
|
33
|
-
tool: {
|
|
34
|
-
name: 'list_api_endpoints',
|
|
35
|
-
description: 'List or search for all endpoints in the Henry SDK TypeScript API',
|
|
36
|
-
inputSchema: zodToInputSchema(listEndpointsSchema),
|
|
37
|
-
},
|
|
38
|
-
handler: async (client, args) => {
|
|
39
|
-
const query = args && listEndpointsSchema.parse(args).search_query?.trim();
|
|
40
|
-
const filteredEndpoints = query && query.length > 0 ?
|
|
41
|
-
endpoints.filter((endpoint) => {
|
|
42
|
-
const fieldsToMatch = [
|
|
43
|
-
endpoint.tool.name,
|
|
44
|
-
endpoint.tool.description,
|
|
45
|
-
endpoint.metadata.resource,
|
|
46
|
-
endpoint.metadata.operation,
|
|
47
|
-
...endpoint.metadata.tags,
|
|
48
|
-
];
|
|
49
|
-
return fieldsToMatch.some((field) => field && field.toLowerCase().includes(query.toLowerCase()));
|
|
50
|
-
})
|
|
51
|
-
: endpoints;
|
|
52
|
-
return asTextContentResult({
|
|
53
|
-
tools: filteredEndpoints.map(({ tool, metadata }) => ({
|
|
54
|
-
name: tool.name,
|
|
55
|
-
description: tool.description,
|
|
56
|
-
resource: metadata.resource,
|
|
57
|
-
operation: metadata.operation,
|
|
58
|
-
tags: metadata.tags,
|
|
59
|
-
})),
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
const getEndpointSchema = z.object({
|
|
64
|
-
endpoint: z.string().describe('The name of the endpoint to get the schema for.'),
|
|
65
|
-
});
|
|
66
|
-
const getEndpointTool = {
|
|
67
|
-
metadata: {
|
|
68
|
-
resource: 'dynamic_tools',
|
|
69
|
-
operation: 'read',
|
|
70
|
-
tags: [],
|
|
71
|
-
},
|
|
72
|
-
tool: {
|
|
73
|
-
name: 'get_api_endpoint_schema',
|
|
74
|
-
description: 'Get the schema for an endpoint in the Henry SDK TypeScript API. You can use the schema returned by this tool to invoke an endpoint with the `invoke_api_endpoint` tool.',
|
|
75
|
-
inputSchema: zodToInputSchema(getEndpointSchema),
|
|
76
|
-
},
|
|
77
|
-
handler: async (client, args) => {
|
|
78
|
-
if (!args) {
|
|
79
|
-
throw new Error('No endpoint provided');
|
|
80
|
-
}
|
|
81
|
-
const endpointName = getEndpointSchema.parse(args).endpoint;
|
|
82
|
-
const endpoint = endpoints.find((e) => e.tool.name === endpointName);
|
|
83
|
-
if (!endpoint) {
|
|
84
|
-
throw new Error(`Endpoint ${endpointName} not found`);
|
|
85
|
-
}
|
|
86
|
-
return asTextContentResult(endpoint.tool);
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
const invokeEndpointSchema = z.object({
|
|
90
|
-
endpoint_name: z.string().describe('The name of the endpoint to invoke.'),
|
|
91
|
-
args: z
|
|
92
|
-
.record(z.string(), z.any())
|
|
93
|
-
.describe('The arguments to pass to the endpoint. This must match the schema returned by the `get_api_endpoint_schema` tool.'),
|
|
94
|
-
});
|
|
95
|
-
const invokeEndpointTool = {
|
|
96
|
-
metadata: {
|
|
97
|
-
resource: 'dynamic_tools',
|
|
98
|
-
operation: 'write',
|
|
99
|
-
tags: [],
|
|
100
|
-
},
|
|
101
|
-
tool: {
|
|
102
|
-
name: 'invoke_api_endpoint',
|
|
103
|
-
description: 'Invoke an endpoint in the Henry SDK TypeScript API. Note: use the `list_api_endpoints` tool to get the list of endpoints and `get_api_endpoint_schema` tool to get the schema for an endpoint.',
|
|
104
|
-
inputSchema: zodToInputSchema(invokeEndpointSchema),
|
|
105
|
-
},
|
|
106
|
-
handler: async (client, args) => {
|
|
107
|
-
if (!args) {
|
|
108
|
-
throw new Error('No endpoint provided');
|
|
109
|
-
}
|
|
110
|
-
const { success, data, error } = invokeEndpointSchema.safeParse(args);
|
|
111
|
-
if (!success) {
|
|
112
|
-
throw new Error(`Invalid arguments for endpoint. ${error?.format()}`);
|
|
113
|
-
}
|
|
114
|
-
const { endpoint_name, args: endpointArgs } = data;
|
|
115
|
-
const endpoint = endpoints.find((e) => e.tool.name === endpoint_name);
|
|
116
|
-
if (!endpoint) {
|
|
117
|
-
throw new Error(`Endpoint ${endpoint_name} not found. Use the \`list_api_endpoints\` tool to get the list of available endpoints.`);
|
|
118
|
-
}
|
|
119
|
-
try {
|
|
120
|
-
// Try to validate the arguments for a better error message
|
|
121
|
-
const cabidela = new Cabidela(endpoint.tool.inputSchema, { fullErrors: true });
|
|
122
|
-
cabidela.validate(endpointArgs);
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
throw new Error(`Invalid arguments for endpoint ${endpoint_name}:\n${error}`);
|
|
126
|
-
}
|
|
127
|
-
return await endpoint.handler(client, endpointArgs);
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
return [getEndpointTool, listEndpointsTool, invokeEndpointTool];
|
|
131
|
-
}
|
|
132
|
-
//# sourceMappingURL=dynamic-tools.mjs.map
|
package/dynamic-tools.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-tools.mjs","sourceRoot":"","sources":["src/dynamic-tools.ts"],"names":[],"mappings":"OACO,EAAY,mBAAmB,EAAkB;OACjD,EAAE,eAAe,EAAE,MAAM,oBAAoB;OAC7C,EAAE,CAAC,EA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D,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;YAEnD,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC;YACtE,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CACb,YAAY,aAAa,yFAAyF,CACnH,CAAC;YACJ,CAAC;YAED,IAAI,CAAC;gBACH,2DAA2D;gBAC3D,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC/E,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YAClC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CAAC,kCAAkC,aAAa,MAAM,KAAK,EAAE,CAAC,CAAC;YAChF,CAAC;YAED,OAAO,MAAM,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QACtD,CAAC;KACF,CAAC;IAEF,OAAO,CAAC,eAAe,EAAE,iBAAiB,EAAE,kBAAkB,CAAC,CAAC;AAClE,CAAC"}
|
package/filtering.d.mts
DELETED
package/filtering.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filtering.d.mts","sourceRoot":"","sources":["src/filtering.ts"],"names":[],"mappings":"AAGA,wBAAsB,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,EAAE,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAM5F;AAMD,wBAAgB,SAAS,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,KAAK,CAEpD"}
|
package/filtering.d.ts
DELETED
package/filtering.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["src/filtering.ts"],"names":[],"mappings":"AAGA,wBAAsB,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,EAAE,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAM5F;AAMD,wBAAgB,SAAS,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,KAAK,CAEpD"}
|
package/filtering.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.maybeFilter = maybeFilter;
|
|
7
|
-
exports.isJqError = isJqError;
|
|
8
|
-
// @ts-nocheck
|
|
9
|
-
const jq_web_1 = __importDefault(require("jq-web"));
|
|
10
|
-
async function maybeFilter(jqFilter, response) {
|
|
11
|
-
if (jqFilter && typeof jqFilter === 'string') {
|
|
12
|
-
return await jq(response, jqFilter);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
return response;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
async function jq(json, jqFilter) {
|
|
19
|
-
return (await jq_web_1.default).json(json, jqFilter);
|
|
20
|
-
}
|
|
21
|
-
function isJqError(error) {
|
|
22
|
-
return error instanceof Error && 'stderr' in error;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=filtering.js.map
|
package/filtering.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filtering.js","sourceRoot":"","sources":["src/filtering.ts"],"names":[],"mappings":";;;;;AAGA,kCAMC;AAMD,8BAEC;AAjBD,cAAc;AACd,oDAA4B;AAErB,KAAK,UAAU,WAAW,CAAC,QAA6B,EAAE,QAAa;IAC5E,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC7C,OAAO,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACtC,CAAC;SAAM,CAAC;QACN,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC,IAAS,EAAE,QAAgB;IAC3C,OAAO,CAAC,MAAM,gBAAM,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC7C,CAAC;AAED,SAAgB,SAAS,CAAC,KAAU;IAClC,OAAO,KAAK,YAAY,KAAK,IAAI,QAAQ,IAAI,KAAK,CAAC;AACrD,CAAC"}
|
package/filtering.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import initJq from 'jq-web';
|
|
2
|
-
export async function maybeFilter(jqFilter, response) {
|
|
3
|
-
if (jqFilter && typeof jqFilter === 'string') {
|
|
4
|
-
return await jq(response, jqFilter);
|
|
5
|
-
}
|
|
6
|
-
else {
|
|
7
|
-
return response;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
async function jq(json, jqFilter) {
|
|
11
|
-
return (await initJq).json(json, jqFilter);
|
|
12
|
-
}
|
|
13
|
-
export function isJqError(error) {
|
|
14
|
-
return error instanceof Error && 'stderr' in error;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=filtering.mjs.map
|
package/filtering.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filtering.mjs","sourceRoot":"","sources":["src/filtering.ts"],"names":[],"mappings":"OACO,MAAM,MAAM,QAAQ;AAE3B,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,QAA6B,EAAE,QAAa;IAC5E,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC7C,OAAO,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACtC,CAAC;SAAM,CAAC;QACN,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC,IAAS,EAAE,QAAgB;IAC3C,OAAO,CAAC,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,KAAU;IAClC,OAAO,KAAK,YAAY,KAAK,IAAI,QAAQ,IAAI,KAAK,CAAC;AACrD,CAAC"}
|
package/src/code-tool-paths.cts
DELETED
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 };
|