profound-mcp 0.9.0 → 0.10.1
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 +37 -1
- package/code-tool-worker.d.mts.map +1 -1
- package/code-tool-worker.d.ts.map +1 -1
- package/code-tool-worker.js +123 -7
- package/code-tool-worker.js.map +1 -1
- package/code-tool-worker.mjs +123 -7
- package/code-tool-worker.mjs.map +1 -1
- package/code-tool.d.mts +1 -1
- package/code-tool.d.mts.map +1 -1
- package/code-tool.d.ts +1 -1
- package/code-tool.d.ts.map +1 -1
- package/code-tool.js +11 -13
- package/code-tool.js.map +1 -1
- package/code-tool.mjs +11 -13
- package/code-tool.mjs.map +1 -1
- package/dynamic-tools.d.mts +1 -1
- package/dynamic-tools.d.ts +1 -1
- package/dynamic-tools.js +1 -1
- package/dynamic-tools.mjs +1 -1
- package/filtering.d.mts +1 -0
- package/filtering.d.mts.map +1 -1
- package/filtering.d.ts +1 -0
- package/filtering.d.ts.map +1 -1
- package/filtering.js +4 -0
- package/filtering.js.map +1 -1
- package/filtering.mjs +3 -0
- package/filtering.mjs.map +1 -1
- package/http.js +2 -2
- package/http.js.map +1 -1
- package/http.mjs +2 -2
- package/http.mjs.map +1 -1
- package/options.d.mts.map +1 -1
- package/options.d.ts.map +1 -1
- package/options.js +6 -3
- package/options.js.map +1 -1
- package/options.mjs +6 -3
- package/options.mjs.map +1 -1
- package/package.json +5 -3
- package/server.js +1 -1
- package/server.js.map +1 -1
- package/server.mjs +1 -1
- package/server.mjs.map +1 -1
- package/src/code-tool-worker.ts +168 -7
- package/src/code-tool.ts +14 -13
- package/src/dynamic-tools.ts +1 -1
- package/src/filtering.ts +4 -0
- package/src/http.ts +2 -2
- package/src/options.ts +10 -3
- package/src/server.ts +1 -1
- package/src/tools/organizations/categories/list-organizations-categories.ts +10 -3
- package/src/tools/organizations/categories/prompts-organizations-categories.ts +12 -5
- package/src/tools/organizations/categories/tags-organizations-categories.ts +12 -5
- package/src/tools/organizations/categories/topics-organizations-categories.ts +12 -5
- package/src/tools/organizations/domains-organizations.ts +10 -3
- package/src/tools/organizations/models-organizations.ts +10 -3
- package/src/tools/organizations/regions-organizations.ts +10 -3
- package/src/tools/reports/sentiment-reports.ts +1 -1
- package/src/tools/types.ts +12 -0
- package/tools/organizations/categories/list-organizations-categories.d.mts.map +1 -1
- package/tools/organizations/categories/list-organizations-categories.d.ts.map +1 -1
- package/tools/organizations/categories/list-organizations-categories.js +9 -1
- package/tools/organizations/categories/list-organizations-categories.js.map +1 -1
- package/tools/organizations/categories/list-organizations-categories.mjs +11 -3
- package/tools/organizations/categories/list-organizations-categories.mjs.map +1 -1
- package/tools/organizations/categories/prompts-organizations-categories.d.mts.map +1 -1
- package/tools/organizations/categories/prompts-organizations-categories.d.ts.map +1 -1
- package/tools/organizations/categories/prompts-organizations-categories.js +9 -1
- package/tools/organizations/categories/prompts-organizations-categories.js.map +1 -1
- package/tools/organizations/categories/prompts-organizations-categories.mjs +11 -3
- package/tools/organizations/categories/prompts-organizations-categories.mjs.map +1 -1
- package/tools/organizations/categories/tags-organizations-categories.d.mts.map +1 -1
- package/tools/organizations/categories/tags-organizations-categories.d.ts.map +1 -1
- package/tools/organizations/categories/tags-organizations-categories.js +9 -1
- package/tools/organizations/categories/tags-organizations-categories.js.map +1 -1
- package/tools/organizations/categories/tags-organizations-categories.mjs +11 -3
- package/tools/organizations/categories/tags-organizations-categories.mjs.map +1 -1
- package/tools/organizations/categories/topics-organizations-categories.d.mts.map +1 -1
- package/tools/organizations/categories/topics-organizations-categories.d.ts.map +1 -1
- package/tools/organizations/categories/topics-organizations-categories.js +9 -1
- package/tools/organizations/categories/topics-organizations-categories.js.map +1 -1
- package/tools/organizations/categories/topics-organizations-categories.mjs +11 -3
- package/tools/organizations/categories/topics-organizations-categories.mjs.map +1 -1
- package/tools/organizations/domains-organizations.d.mts.map +1 -1
- package/tools/organizations/domains-organizations.d.ts.map +1 -1
- package/tools/organizations/domains-organizations.js +9 -1
- package/tools/organizations/domains-organizations.js.map +1 -1
- package/tools/organizations/domains-organizations.mjs +11 -3
- package/tools/organizations/domains-organizations.mjs.map +1 -1
- package/tools/organizations/models-organizations.d.mts.map +1 -1
- package/tools/organizations/models-organizations.d.ts.map +1 -1
- package/tools/organizations/models-organizations.js +9 -1
- package/tools/organizations/models-organizations.js.map +1 -1
- package/tools/organizations/models-organizations.mjs +11 -3
- package/tools/organizations/models-organizations.mjs.map +1 -1
- package/tools/organizations/regions-organizations.d.mts.map +1 -1
- package/tools/organizations/regions-organizations.d.ts.map +1 -1
- package/tools/organizations/regions-organizations.js +9 -1
- package/tools/organizations/regions-organizations.js.map +1 -1
- package/tools/organizations/regions-organizations.mjs +11 -3
- package/tools/organizations/regions-organizations.mjs.map +1 -1
- package/tools/reports/sentiment-reports.js +1 -1
- package/tools/reports/sentiment-reports.js.map +1 -1
- package/tools/reports/sentiment-reports.mjs +1 -1
- package/tools/reports/sentiment-reports.mjs.map +1 -1
- package/tools/types.d.mts +1 -0
- package/tools/types.d.mts.map +1 -1
- package/tools/types.d.ts +1 -0
- package/tools/types.d.ts.map +1 -1
- package/tools/types.js +12 -0
- package/tools/types.js.map +1 -1
- package/tools/types.mjs +11 -0
- package/tools/types.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
|
+
[](https://cursor.com/en-US/install-mcp?name=profound-mcp&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsInByb2ZvdW5kLW1jcCJdLCJlbnYiOnsiUFJPRk9VTkRfQVBJX0tFWSI6IlNldCB5b3VyIFBST0ZPVU5EX0FQSV9LRVkgaGVyZS4ifX0)
|
|
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%22profound-mcp%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22profound-mcp%22%5D%2C%22env%22%3A%7B%22PROFOUND_API_KEY%22%3A%22Set%20your%20PROFOUND_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 profoundai_api --env PROFOUND_API_KEY="Your PROFOUND_API_KEY here." -- npx -y profound-mcp
|
|
58
|
+
```
|
|
59
|
+
|
|
37
60
|
## Exposing endpoints to your MCP Client
|
|
38
61
|
|
|
39
|
-
There are
|
|
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
|
|
|
@@ -74,6 +98,18 @@ All of these command-line options can be repeated, combined together, and have c
|
|
|
74
98
|
|
|
75
99
|
Use `--list` to see the list of available tools, or see below.
|
|
76
100
|
|
|
101
|
+
### Code execution
|
|
102
|
+
|
|
103
|
+
If you specify `--tools=code` to the MCP server, it will expose just two tools:
|
|
104
|
+
|
|
105
|
+
- `search_docs` - Searches the API documentation and returns a list of markdown results
|
|
106
|
+
- `execute` - Runs code against the TypeScript client
|
|
107
|
+
|
|
108
|
+
This allows the LLM to implement more complex logic by chaining together many API calls without loading
|
|
109
|
+
intermediary results into its context window.
|
|
110
|
+
|
|
111
|
+
The code execution itself happens in a Deno sandbox that has network access only to the base URL for the API.
|
|
112
|
+
|
|
77
113
|
### Specifying the MCP Client
|
|
78
114
|
|
|
79
115
|
Different clients have varying abilities to handle arbitrary tools and schemas.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-tool-worker.d.mts","sourceRoot":"","sources":["src/code-tool-worker.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"code-tool-worker.d.mts","sourceRoot":"","sources":["src/code-tool-worker.ts"],"names":[],"mappings":";iBAsJ0B,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":";
|
|
1
|
+
{"version":3,"file":"code-tool-worker.d.ts","sourceRoot":"","sources":["src/code-tool-worker.ts"],"names":[],"mappings":";iBAsJ0B,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC;;AAwDrD,wBAAyB"}
|
package/code-tool-worker.js
CHANGED
|
@@ -5,9 +5,129 @@ 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"));
|
|
9
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
8
10
|
const profoundai_1 = require("profoundai");
|
|
11
|
+
function getRunFunctionNode(code) {
|
|
12
|
+
const sourceFile = typescript_1.default.createSourceFile('code.ts', code, typescript_1.default.ScriptTarget.Latest, true);
|
|
13
|
+
for (const statement of sourceFile.statements) {
|
|
14
|
+
// Check for top-level function declarations
|
|
15
|
+
if (typescript_1.default.isFunctionDeclaration(statement)) {
|
|
16
|
+
if (statement.name?.text === 'run') {
|
|
17
|
+
return statement;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// Check for variable declarations: const run = () => {} or const run = function() {}
|
|
21
|
+
if (typescript_1.default.isVariableStatement(statement)) {
|
|
22
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
23
|
+
if (typescript_1.default.isIdentifier(declaration.name) && declaration.name.text === 'run') {
|
|
24
|
+
// Check if it's initialized with a function
|
|
25
|
+
if (declaration.initializer &&
|
|
26
|
+
(typescript_1.default.isFunctionExpression(declaration.initializer) || typescript_1.default.isArrowFunction(declaration.initializer))) {
|
|
27
|
+
return declaration.initializer;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const fuse = new fuse_js_1.default([
|
|
36
|
+
'client.organizations.domains',
|
|
37
|
+
'client.organizations.models',
|
|
38
|
+
'client.organizations.regions',
|
|
39
|
+
'client.organizations.categories.list',
|
|
40
|
+
'client.organizations.categories.prompts',
|
|
41
|
+
'client.organizations.categories.tags',
|
|
42
|
+
'client.organizations.categories.topics',
|
|
43
|
+
'client.prompts.answers',
|
|
44
|
+
'client.reports.citations',
|
|
45
|
+
'client.reports.sentiment',
|
|
46
|
+
'client.reports.visibility',
|
|
47
|
+
'client.logs.raw.bots',
|
|
48
|
+
'client.logs.raw.logs',
|
|
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
|
+
}
|
|
9
118
|
const fetch = async (req) => {
|
|
10
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
|
+
}
|
|
125
|
+
const runFunctionNode = getRunFunctionNode(code);
|
|
126
|
+
if (!runFunctionNode) {
|
|
127
|
+
return Response.json({
|
|
128
|
+
message: '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```',
|
|
129
|
+
}, { status: 400, statusText: 'Code execution error' });
|
|
130
|
+
}
|
|
11
131
|
const client = new profoundai_1.Profound({
|
|
12
132
|
...opts,
|
|
13
133
|
});
|
|
@@ -23,11 +143,8 @@ const fetch = async (req) => {
|
|
|
23
143
|
};
|
|
24
144
|
try {
|
|
25
145
|
let run_ = async (client) => { };
|
|
26
|
-
eval(
|
|
27
|
-
|
|
28
|
-
run_ = run;
|
|
29
|
-
`);
|
|
30
|
-
const result = await run_(client);
|
|
146
|
+
eval(`${code}\nrun_ = run;`);
|
|
147
|
+
const result = await run_(makeSdkProxy(client, { path: ['client'] }));
|
|
31
148
|
return Response.json({
|
|
32
149
|
result,
|
|
33
150
|
logLines,
|
|
@@ -35,9 +152,8 @@ const fetch = async (req) => {
|
|
|
35
152
|
});
|
|
36
153
|
}
|
|
37
154
|
catch (e) {
|
|
38
|
-
const message = e instanceof Error ? e.message : undefined;
|
|
39
155
|
return Response.json({
|
|
40
|
-
message,
|
|
156
|
+
message: parseError(code, e),
|
|
41
157
|
}, { status: 400, statusText: 'Code execution error' });
|
|
42
158
|
}
|
|
43
159
|
};
|
package/code-tool-worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-tool-worker.js","sourceRoot":"","sources":["src/code-tool-worker.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;AAEtF,0DAA6B;AAE7B,2CAAsC;AAEtC,MAAM,KAAK,GAAG,KAAK,EAAE,GAAY,EAAqB,EAAE;IACtD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAgB,CAAC;IACzD,MAAM,MAAM,GAAG,IAAI,qBAAQ,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,mBAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACtC,CAAC;QACD,KAAK,EAAE,CAAC,GAAG,IAAe,EAAE,EAAE;YAC5B,QAAQ,C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C,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,kBAAe,EAAE,KAAK,EAAE,CAAC"}
|
package/code-tool-worker.mjs
CHANGED
|
@@ -1,8 +1,128 @@
|
|
|
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';
|
|
4
|
+
import ts from 'typescript';
|
|
3
5
|
import { Profound } from 'profoundai';
|
|
6
|
+
function getRunFunctionNode(code) {
|
|
7
|
+
const sourceFile = ts.createSourceFile('code.ts', code, ts.ScriptTarget.Latest, true);
|
|
8
|
+
for (const statement of sourceFile.statements) {
|
|
9
|
+
// Check for top-level function declarations
|
|
10
|
+
if (ts.isFunctionDeclaration(statement)) {
|
|
11
|
+
if (statement.name?.text === 'run') {
|
|
12
|
+
return statement;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
// Check for variable declarations: const run = () => {} or const run = function() {}
|
|
16
|
+
if (ts.isVariableStatement(statement)) {
|
|
17
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
18
|
+
if (ts.isIdentifier(declaration.name) && declaration.name.text === 'run') {
|
|
19
|
+
// Check if it's initialized with a function
|
|
20
|
+
if (declaration.initializer &&
|
|
21
|
+
(ts.isFunctionExpression(declaration.initializer) || ts.isArrowFunction(declaration.initializer))) {
|
|
22
|
+
return declaration.initializer;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const fuse = new Fuse([
|
|
31
|
+
'client.organizations.domains',
|
|
32
|
+
'client.organizations.models',
|
|
33
|
+
'client.organizations.regions',
|
|
34
|
+
'client.organizations.categories.list',
|
|
35
|
+
'client.organizations.categories.prompts',
|
|
36
|
+
'client.organizations.categories.tags',
|
|
37
|
+
'client.organizations.categories.topics',
|
|
38
|
+
'client.prompts.answers',
|
|
39
|
+
'client.reports.citations',
|
|
40
|
+
'client.reports.sentiment',
|
|
41
|
+
'client.reports.visibility',
|
|
42
|
+
'client.logs.raw.bots',
|
|
43
|
+
'client.logs.raw.logs',
|
|
44
|
+
], { threshold: 1, shouldSort: true });
|
|
45
|
+
function getMethodSuggestions(fullyQualifiedMethodName) {
|
|
46
|
+
return fuse
|
|
47
|
+
.search(fullyQualifiedMethodName)
|
|
48
|
+
.map(({ item }) => item)
|
|
49
|
+
.slice(0, 5);
|
|
50
|
+
}
|
|
51
|
+
const proxyToObj = new WeakMap();
|
|
52
|
+
const objToProxy = new WeakMap();
|
|
53
|
+
function makeSdkProxy(obj, { path, isBelievedBad = false }) {
|
|
54
|
+
let proxy = objToProxy.get(obj);
|
|
55
|
+
if (!proxy) {
|
|
56
|
+
proxy = new Proxy(obj, {
|
|
57
|
+
get(target, prop, receiver) {
|
|
58
|
+
const propPath = [...path, String(prop)];
|
|
59
|
+
const value = Reflect.get(target, prop, receiver);
|
|
60
|
+
if (isBelievedBad || (!(prop in target) && value === undefined)) {
|
|
61
|
+
// If we're accessing a path that doesn't exist, it will probably eventually error.
|
|
62
|
+
// Let's proxy it and mark it bad so that we can control the error message.
|
|
63
|
+
// We proxy an empty class so that an invocation or construction attempt is possible.
|
|
64
|
+
return makeSdkProxy(class {
|
|
65
|
+
}, { path: propPath, isBelievedBad: true });
|
|
66
|
+
}
|
|
67
|
+
if (value !== null && (typeof value === 'object' || typeof value === 'function')) {
|
|
68
|
+
return makeSdkProxy(value, { path: propPath, isBelievedBad });
|
|
69
|
+
}
|
|
70
|
+
return value;
|
|
71
|
+
},
|
|
72
|
+
apply(target, thisArg, args) {
|
|
73
|
+
if (isBelievedBad || typeof target !== 'function') {
|
|
74
|
+
const fullyQualifiedMethodName = path.join('.');
|
|
75
|
+
const suggestions = getMethodSuggestions(fullyQualifiedMethodName);
|
|
76
|
+
throw new Error(`${fullyQualifiedMethodName} is not a function. Did you mean: ${suggestions.join(', ')}`);
|
|
77
|
+
}
|
|
78
|
+
return Reflect.apply(target, proxyToObj.get(thisArg) ?? thisArg, args);
|
|
79
|
+
},
|
|
80
|
+
construct(target, args, newTarget) {
|
|
81
|
+
if (isBelievedBad || typeof target !== 'function') {
|
|
82
|
+
const fullyQualifiedMethodName = path.join('.');
|
|
83
|
+
const suggestions = getMethodSuggestions(fullyQualifiedMethodName);
|
|
84
|
+
throw new Error(`${fullyQualifiedMethodName} is not a constructor. Did you mean: ${suggestions.join(', ')}`);
|
|
85
|
+
}
|
|
86
|
+
return Reflect.construct(target, args, newTarget);
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
objToProxy.set(obj, proxy);
|
|
90
|
+
proxyToObj.set(proxy, obj);
|
|
91
|
+
}
|
|
92
|
+
return proxy;
|
|
93
|
+
}
|
|
94
|
+
function parseError(code, error) {
|
|
95
|
+
if (!(error instanceof Error))
|
|
96
|
+
return;
|
|
97
|
+
const message = error.name ? `${error.name}: ${error.message}` : error.message;
|
|
98
|
+
try {
|
|
99
|
+
// Deno uses V8; the first "<anonymous>:LINE:COLUMN" is the top of stack.
|
|
100
|
+
const lineNumber = error.stack?.match(/<anonymous>:([0-9]+):[0-9]+/)?.[1];
|
|
101
|
+
// -1 for the zero-based indexing
|
|
102
|
+
const line = lineNumber &&
|
|
103
|
+
code
|
|
104
|
+
.split('\n')
|
|
105
|
+
.at(parseInt(lineNumber, 10) - 1)
|
|
106
|
+
?.trim();
|
|
107
|
+
return line ? `${message}\n at line ${lineNumber}\n ${line}` : message;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return message;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
4
113
|
const fetch = async (req) => {
|
|
5
114
|
const { opts, code } = (await req.json());
|
|
115
|
+
if (code == null) {
|
|
116
|
+
return Response.json({
|
|
117
|
+
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```',
|
|
118
|
+
}, { status: 400, statusText: 'Code execution error' });
|
|
119
|
+
}
|
|
120
|
+
const runFunctionNode = getRunFunctionNode(code);
|
|
121
|
+
if (!runFunctionNode) {
|
|
122
|
+
return Response.json({
|
|
123
|
+
message: '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```',
|
|
124
|
+
}, { status: 400, statusText: 'Code execution error' });
|
|
125
|
+
}
|
|
6
126
|
const client = new Profound({
|
|
7
127
|
...opts,
|
|
8
128
|
});
|
|
@@ -18,11 +138,8 @@ const fetch = async (req) => {
|
|
|
18
138
|
};
|
|
19
139
|
try {
|
|
20
140
|
let run_ = async (client) => { };
|
|
21
|
-
eval(
|
|
22
|
-
|
|
23
|
-
run_ = run;
|
|
24
|
-
`);
|
|
25
|
-
const result = await run_(client);
|
|
141
|
+
eval(`${code}\nrun_ = run;`);
|
|
142
|
+
const result = await run_(makeSdkProxy(client, { path: ['client'] }));
|
|
26
143
|
return Response.json({
|
|
27
144
|
result,
|
|
28
145
|
logLines,
|
|
@@ -30,9 +147,8 @@ const fetch = async (req) => {
|
|
|
30
147
|
});
|
|
31
148
|
}
|
|
32
149
|
catch (e) {
|
|
33
|
-
const message = e instanceof Error ? e.message : undefined;
|
|
34
150
|
return Response.json({
|
|
35
|
-
message,
|
|
151
|
+
message: parseError(code, e),
|
|
36
152
|
}, { status: 400, statusText: 'Code execution error' });
|
|
37
153
|
}
|
|
38
154
|
};
|
package/code-tool-worker.mjs.map
CHANGED
|
@@ -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,QAAQ,EAAE,MAAM,YAAY;AAErC,MAAM,KAAK,GAAG,KAAK,EAAE,GAAY,EAAqB,EAAE;IACtD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAgB,CAAC;IACzD,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
|
|
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,IAAI,MAAM,SAAS;OACnB,EAAE,MAAM,YAAY;OAGpB,EAAE,QAAQ,EAAE,MAAM,YAAY;AAErC,SAAS,kBAAkB,CACzB,IAAY;IAEZ,MAAM,UAAU,GAAG,EAAE,CAA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
package/code-tool.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import { Endpoint } from "./tools/types.mjs";
|
|
|
2
2
|
/**
|
|
3
3
|
* A tool that runs code against a copy of the SDK.
|
|
4
4
|
*
|
|
5
|
-
* Instead of exposing every endpoint as
|
|
5
|
+
* Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
|
|
6
6
|
* we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
|
|
7
7
|
* a generic endpoint that can be used to invoke any endpoint with the provided arguments.
|
|
8
8
|
*
|
package/code-tool.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-tool.d.mts","sourceRoot":"","sources":["src/code-tool.ts"],"names":[],"mappings":"OAKO,
|
|
1
|
+
{"version":3,"file":"code-tool.d.mts","sourceRoot":"","sources":["src/code-tool.ts"],"names":[],"mappings":"OAKO,EAAgB,QAAQ,EAA4B;AAM3D;;;;;;;;GAQG;AACH,wBAAsB,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,CA8HlD"}
|
package/code-tool.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Endpoint } from "./tools/types.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* A tool that runs code against a copy of the SDK.
|
|
4
4
|
*
|
|
5
|
-
* Instead of exposing every endpoint as
|
|
5
|
+
* Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
|
|
6
6
|
* we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
|
|
7
7
|
* a generic endpoint that can be used to invoke any endpoint with the provided arguments.
|
|
8
8
|
*
|
package/code-tool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-tool.d.ts","sourceRoot":"","sources":["src/code-tool.ts"],"names":[],"mappings":"OAKO,
|
|
1
|
+
{"version":3,"file":"code-tool.d.ts","sourceRoot":"","sources":["src/code-tool.ts"],"names":[],"mappings":"OAKO,EAAgB,QAAQ,EAA4B;AAM3D;;;;;;;;GAQG;AACH,wBAAsB,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,CA8HlD"}
|
package/code-tool.js
CHANGED
|
@@ -40,7 +40,7 @@ const node_url_1 = require("node:url");
|
|
|
40
40
|
/**
|
|
41
41
|
* A tool that runs code against a copy of the SDK.
|
|
42
42
|
*
|
|
43
|
-
* Instead of exposing every endpoint as
|
|
43
|
+
* Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
|
|
44
44
|
* we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
|
|
45
45
|
* a generic endpoint that can be used to invoke any endpoint with the provided arguments.
|
|
46
46
|
*
|
|
@@ -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
|
|
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.
|
|
@@ -110,7 +110,7 @@ async function codeTool() {
|
|
|
110
110
|
code,
|
|
111
111
|
});
|
|
112
112
|
req.write(body, (err) => {
|
|
113
|
-
if (err
|
|
113
|
+
if (err != null) {
|
|
114
114
|
reject(err);
|
|
115
115
|
}
|
|
116
116
|
});
|
|
@@ -118,12 +118,10 @@ async function codeTool() {
|
|
|
118
118
|
});
|
|
119
119
|
if (resp.status === 200) {
|
|
120
120
|
const { result, logLines, errLines } = (await resp.json());
|
|
121
|
-
const returnOutput = result
|
|
122
|
-
:
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
text: typeof result === 'string' ? result : JSON.stringify(result),
|
|
126
|
-
};
|
|
121
|
+
const returnOutput = result == null ? null : ({
|
|
122
|
+
type: 'text',
|
|
123
|
+
text: typeof result === 'string' ? result : JSON.stringify(result),
|
|
124
|
+
});
|
|
127
125
|
const logOutput = logLines.length === 0 ?
|
|
128
126
|
null
|
|
129
127
|
: {
|
|
@@ -142,12 +140,12 @@ async function codeTool() {
|
|
|
142
140
|
}
|
|
143
141
|
else {
|
|
144
142
|
const { message } = (await resp.json());
|
|
145
|
-
|
|
143
|
+
return {
|
|
144
|
+
content: message == null ? [] : [{ type: 'text', text: message }],
|
|
145
|
+
isError: true,
|
|
146
|
+
};
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
|
-
catch (e) {
|
|
149
|
-
throw e;
|
|
150
|
-
}
|
|
151
149
|
finally {
|
|
152
150
|
worker.terminate();
|
|
153
151
|
}
|
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,
|
|
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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AO,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
|
@@ -4,7 +4,7 @@ import { pathToFileURL } from 'node:url';
|
|
|
4
4
|
/**
|
|
5
5
|
* A tool that runs code against a copy of the SDK.
|
|
6
6
|
*
|
|
7
|
-
* Instead of exposing every endpoint as
|
|
7
|
+
* Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
|
|
8
8
|
* we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
|
|
9
9
|
* a generic endpoint that can be used to invoke any endpoint with the provided arguments.
|
|
10
10
|
*
|
|
@@ -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
|
|
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.
|
|
@@ -74,7 +74,7 @@ export async function codeTool() {
|
|
|
74
74
|
code,
|
|
75
75
|
});
|
|
76
76
|
req.write(body, (err) => {
|
|
77
|
-
if (err
|
|
77
|
+
if (err != null) {
|
|
78
78
|
reject(err);
|
|
79
79
|
}
|
|
80
80
|
});
|
|
@@ -82,12 +82,10 @@ export async function codeTool() {
|
|
|
82
82
|
});
|
|
83
83
|
if (resp.status === 200) {
|
|
84
84
|
const { result, logLines, errLines } = (await resp.json());
|
|
85
|
-
const returnOutput = result
|
|
86
|
-
:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
text: typeof result === 'string' ? result : JSON.stringify(result),
|
|
90
|
-
};
|
|
85
|
+
const returnOutput = result == null ? null : ({
|
|
86
|
+
type: 'text',
|
|
87
|
+
text: typeof result === 'string' ? result : JSON.stringify(result),
|
|
88
|
+
});
|
|
91
89
|
const logOutput = logLines.length === 0 ?
|
|
92
90
|
null
|
|
93
91
|
: {
|
|
@@ -106,12 +104,12 @@ export async function codeTool() {
|
|
|
106
104
|
}
|
|
107
105
|
else {
|
|
108
106
|
const { message } = (await resp.json());
|
|
109
|
-
|
|
107
|
+
return {
|
|
108
|
+
content: message == null ? [] : [{ type: 'text', text: message }],
|
|
109
|
+
isError: true,
|
|
110
|
+
};
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
|
-
catch (e) {
|
|
113
|
-
throw e;
|
|
114
|
-
}
|
|
115
113
|
finally {
|
|
116
114
|
worker.terminate();
|
|
117
115
|
}
|
package/code-tool.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-tool.mjs","sourceRoot":"","sources":["src/code-tool.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,OAAO,EAAE,MAAM,WAAW;OAC5B,EAAE,aAAa,EAAE,MAA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C,IAAI,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/dynamic-tools.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import { Endpoint } from "./tools/types.mjs";
|
|
|
2
2
|
/**
|
|
3
3
|
* A list of tools that expose all the endpoints in the API dynamically.
|
|
4
4
|
*
|
|
5
|
-
* Instead of exposing every endpoint as
|
|
5
|
+
* Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
|
|
6
6
|
* we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
|
|
7
7
|
* a generic endpoint that can be used to invoke any endpoint with the provided arguments.
|
|
8
8
|
*
|
package/dynamic-tools.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Endpoint } from "./tools/types.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* A list of tools that expose all the endpoints in the API dynamically.
|
|
4
4
|
*
|
|
5
|
-
* Instead of exposing every endpoint as
|
|
5
|
+
* Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
|
|
6
6
|
* we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
|
|
7
7
|
* a generic endpoint that can be used to invoke any endpoint with the provided arguments.
|
|
8
8
|
*
|