@tpmjs/registry-execute 0.1.2 → 0.1.4
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/LICENSE +21 -0
- package/README.md +39 -45
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/package.json +15 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2025 TPMJS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ Execute a tool from the TPMJS registry by its toolId.
|
|
|
42
42
|
|
|
43
43
|
| Name | Type | Required | Description |
|
|
44
44
|
|------|------|----------|-------------|
|
|
45
|
-
| `toolId` | string | Yes | Tool identifier (format: `package::
|
|
45
|
+
| `toolId` | string | Yes | Tool identifier (format: `package::name`) |
|
|
46
46
|
| `params` | object | Yes | Parameters to pass to the tool |
|
|
47
47
|
| `env` | object | No | Environment variables (API keys) if required |
|
|
48
48
|
|
|
@@ -92,73 +92,67 @@ export TPMJS_EXECUTOR_URL=https://executor.mycompany.com
|
|
|
92
92
|
|
|
93
93
|
## Passing API Keys to Tools
|
|
94
94
|
|
|
95
|
-
Many tools require API keys to function (e.g., web scraping tools need a Firecrawl key, search tools need an Exa key). The `
|
|
95
|
+
Many tools require API keys to function (e.g., web scraping tools need a Firecrawl key, search tools need an Exa key). The recommended approach is to wrap `registryExecuteTool` with your pre-configured keys.
|
|
96
96
|
|
|
97
|
-
###
|
|
97
|
+
### Recommended: Create a Wrapper
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
"toolId": "@firecrawl/ai-sdk::scrapeTool",
|
|
103
|
-
"requiredEnvVars": ["FIRECRAWL_API_KEY"]
|
|
104
|
-
}
|
|
105
|
-
```
|
|
99
|
+
```typescript
|
|
100
|
+
import { tool } from 'ai';
|
|
101
|
+
import { registryExecuteTool } from '@tpmjs/registry-execute';
|
|
106
102
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
env: { FIRECRAWL_API_KEY: 'fc-xxx' }
|
|
113
|
-
})
|
|
114
|
-
```
|
|
103
|
+
// Pre-configure your API keys
|
|
104
|
+
const API_KEYS: Record<string, string> = {
|
|
105
|
+
FIRECRAWL_API_KEY: process.env.FIRECRAWL_API_KEY!,
|
|
106
|
+
EXA_API_KEY: process.env.EXA_API_KEY!,
|
|
107
|
+
};
|
|
115
108
|
|
|
116
|
-
|
|
109
|
+
// Create a wrapped version that auto-injects keys
|
|
110
|
+
export const registryExecute = tool({
|
|
111
|
+
description: registryExecuteTool.description,
|
|
112
|
+
parameters: registryExecuteTool.parameters,
|
|
113
|
+
execute: async ({ toolId, params }) => {
|
|
114
|
+
return registryExecuteTool.execute({ toolId, params, env: API_KEYS });
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
```
|
|
117
118
|
|
|
118
|
-
|
|
119
|
+
Now use the wrapped tool in your agent:
|
|
119
120
|
|
|
120
121
|
```typescript
|
|
121
122
|
import { streamText } from 'ai';
|
|
122
123
|
import { anthropic } from '@ai-sdk/anthropic';
|
|
123
124
|
import { registrySearchTool } from '@tpmjs/registry-search';
|
|
124
|
-
import {
|
|
125
|
-
|
|
126
|
-
// Pre-configure API keys your agent can use
|
|
127
|
-
const API_KEYS = {
|
|
128
|
-
FIRECRAWL_API_KEY: process.env.FIRECRAWL_API_KEY,
|
|
129
|
-
EXA_API_KEY: process.env.EXA_API_KEY,
|
|
130
|
-
};
|
|
125
|
+
import { registryExecute } from './tools'; // Your wrapped version
|
|
131
126
|
|
|
132
127
|
const result = streamText({
|
|
133
128
|
model: anthropic('claude-sonnet-4-20250514'),
|
|
134
129
|
tools: {
|
|
135
130
|
registrySearch: registrySearchTool,
|
|
136
|
-
registryExecute
|
|
131
|
+
registryExecute, // Keys are auto-injected
|
|
137
132
|
},
|
|
138
133
|
system: `You have access to the TPMJS tool registry.
|
|
139
|
-
|
|
140
|
-
${JSON.stringify(API_KEYS, null, 2)}
|
|
141
|
-
|
|
142
|
-
If a tool requires a key you don't have, tell the user.`,
|
|
134
|
+
Use registrySearch to find tools, then registryExecute to run them.`,
|
|
143
135
|
prompt: 'Scrape https://example.com and summarize the content',
|
|
144
136
|
});
|
|
145
137
|
```
|
|
146
138
|
|
|
147
|
-
###
|
|
139
|
+
### How It Works
|
|
148
140
|
|
|
149
|
-
|
|
141
|
+
1. **Search returns required keys**: When you search for a tool, the response includes `requiredEnvVars`:
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"toolId": "@firecrawl/ai-sdk::scrapeTool",
|
|
145
|
+
"requiredEnvVars": ["FIRECRAWL_API_KEY"]
|
|
146
|
+
}
|
|
147
|
+
```
|
|
150
148
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
// No env needed
|
|
160
|
-
})
|
|
161
|
-
```
|
|
149
|
+
2. **Your wrapper injects keys**: The wrapped tool automatically passes your configured keys to the executor.
|
|
150
|
+
|
|
151
|
+
3. **Keys are injected into sandbox**: The executor injects these as environment variables in the isolated Deno runtime where the tool runs.
|
|
152
|
+
|
|
153
|
+
### Tools Without Required Keys
|
|
154
|
+
|
|
155
|
+
Some tools don't require any API keys (like `@tpmjs/createblogpost`). They work with or without the wrapper.
|
|
162
156
|
|
|
163
157
|
## Security
|
|
164
158
|
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ export const registryExecuteTool = tool({
|
|
|
18
18
|
properties: {
|
|
19
19
|
toolId: {
|
|
20
20
|
type: 'string',
|
|
21
|
-
description: "Tool identifier from registrySearchTool (format: 'package::
|
|
21
|
+
description: "Tool identifier from registrySearchTool (format: 'package::name')",
|
|
22
22
|
},
|
|
23
23
|
params: {
|
|
24
24
|
type: 'object',
|
|
@@ -37,19 +37,19 @@ export const registryExecuteTool = tool({
|
|
|
37
37
|
additionalProperties: false,
|
|
38
38
|
}),
|
|
39
39
|
async execute({ toolId, params, env }) {
|
|
40
|
-
// Parse toolId format: "package::
|
|
40
|
+
// Parse toolId format: "package::name"
|
|
41
41
|
const separatorIndex = toolId.lastIndexOf('::');
|
|
42
42
|
if (separatorIndex === -1) {
|
|
43
|
-
throw new Error(`Invalid toolId format. Expected "package::
|
|
43
|
+
throw new Error(`Invalid toolId format. Expected "package::name", got "${toolId}"`);
|
|
44
44
|
}
|
|
45
45
|
const packageName = toolId.substring(0, separatorIndex);
|
|
46
|
-
const
|
|
47
|
-
if (!packageName || !
|
|
48
|
-
throw new Error(`Invalid toolId format. Expected "package::
|
|
46
|
+
const name = toolId.substring(separatorIndex + 2);
|
|
47
|
+
if (!packageName || !name) {
|
|
48
|
+
throw new Error(`Invalid toolId format. Expected "package::name", got "${toolId}"`);
|
|
49
49
|
}
|
|
50
50
|
// Fetch tool metadata to get version and importUrl
|
|
51
51
|
const metaParams = new URLSearchParams({
|
|
52
|
-
q:
|
|
52
|
+
q: name,
|
|
53
53
|
limit: '10',
|
|
54
54
|
});
|
|
55
55
|
const metaResponse = await fetch(`${TPMJS_API_URL}/api/tools/search?${metaParams}`);
|
|
@@ -61,7 +61,7 @@ export const registryExecuteTool = tool({
|
|
|
61
61
|
const toolsArray = metaData.results?.tools || [];
|
|
62
62
|
// Find the exact tool match
|
|
63
63
|
// biome-ignore lint/suspicious/noExplicitAny: API response types vary
|
|
64
|
-
const toolMeta = toolsArray.find((t) => t.package.npmPackageName === packageName && t.
|
|
64
|
+
const toolMeta = toolsArray.find((t) => t.package.npmPackageName === packageName && t.name === name);
|
|
65
65
|
if (!toolMeta) {
|
|
66
66
|
throw new Error(`Tool not found: ${toolId}`);
|
|
67
67
|
}
|
|
@@ -73,7 +73,7 @@ export const registryExecuteTool = tool({
|
|
|
73
73
|
headers: { 'Content-Type': 'application/json' },
|
|
74
74
|
body: JSON.stringify({
|
|
75
75
|
packageName,
|
|
76
|
-
|
|
76
|
+
name,
|
|
77
77
|
version,
|
|
78
78
|
importUrl,
|
|
79
79
|
params,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAEtC,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,mBAAmB,CAAC;AACvE,MAAM,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,4BAA4B,CAAC;AAW1F;;;;;;;;;GASG;AACH,MAAM,C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Q,CAAC,OAAO,CAAC,UAAU,CAAC;QAC5C,MAAM,SAAS,GAAG,kBAAkB,WAAW,IAAI,OAAO,EAAE,CAAC;QAE7D,+BAA+B;QAC/B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,kBAAkB,eAAe,EAAE;YACjE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,WAAW;gBACX,IAAI;gBACJ,OAAO;gBACP,SAAS;gBACT,MAAM;gBACN,GAAG,EAAE,GAAG,IAAI,EAAE;aACf,CAAC;SACH,CAAC,CAAC;QAEH,sEAAsE;QACtE,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAQ,CAAC;QAE9C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,uBAAuB,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO;YACL,MAAM;YACN,eAAe,EAAE,MAAM,CAAC,eAAe;YACvC,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tpmjs/registry-execute",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Execute tools from the TPMJS registry in any AI SDK agent",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
6
8
|
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
7
16
|
"keywords": [
|
|
8
|
-
"tpmjs
|
|
17
|
+
"tpmjs",
|
|
9
18
|
"ai-sdk",
|
|
10
19
|
"vercel-ai",
|
|
11
20
|
"registry",
|
|
12
21
|
"execute"
|
|
13
22
|
],
|
|
14
23
|
"dependencies": {
|
|
15
|
-
"ai": "6.0.
|
|
24
|
+
"ai": "6.0.49"
|
|
16
25
|
},
|
|
17
26
|
"devDependencies": {
|
|
18
|
-
"typescript": "^5.
|
|
27
|
+
"typescript": "^5.9.3",
|
|
19
28
|
"@tpmjs/tsconfig": "0.0.0"
|
|
20
29
|
},
|
|
21
30
|
"files": [
|
|
@@ -39,13 +48,13 @@
|
|
|
39
48
|
],
|
|
40
49
|
"tools": [
|
|
41
50
|
{
|
|
42
|
-
"
|
|
51
|
+
"name": "registryExecuteTool",
|
|
43
52
|
"description": "Execute a tool from the TPMJS registry by toolId. Use registrySearchTool first to find toolIds.",
|
|
44
53
|
"parameters": [
|
|
45
54
|
{
|
|
46
55
|
"name": "toolId",
|
|
47
56
|
"type": "string",
|
|
48
|
-
"description": "Tool identifier from registrySearchTool (format: 'package::
|
|
57
|
+
"description": "Tool identifier from registrySearchTool (format: 'package::name')",
|
|
49
58
|
"required": true
|
|
50
59
|
},
|
|
51
60
|
{
|