@tpmjs/registry-execute 0.1.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 +102 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +95 -0
- package/dist/index.js.map +1 -0
- package/package.json +83 -0
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# @tpmjs/registry-execute
|
|
2
|
+
|
|
3
|
+
Execute tools from the TPMJS registry in any AI SDK agent. Tools run in a secure sandbox - no local installation required.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @tpmjs/registry-execute
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @tpmjs/registry-execute
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { Agent } from 'ai';
|
|
17
|
+
import { registrySearchTool } from '@tpmjs/registry-search';
|
|
18
|
+
import { registryExecuteTool } from '@tpmjs/registry-execute';
|
|
19
|
+
|
|
20
|
+
const agent = new Agent({
|
|
21
|
+
model: 'anthropic/claude-sonnet-4-20250514',
|
|
22
|
+
tools: {
|
|
23
|
+
registrySearch: registrySearchTool,
|
|
24
|
+
registryExecute: registryExecuteTool,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// The agent can now:
|
|
29
|
+
// 1. Search for tools: registrySearch({ query: "web scraping" })
|
|
30
|
+
// 2. Execute found tools: registryExecute({ toolId: "@firecrawl/ai-sdk::scrapeTool", params: { url: "..." } })
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Tool: registryExecuteTool
|
|
34
|
+
|
|
35
|
+
Execute a tool from the TPMJS registry by its toolId.
|
|
36
|
+
|
|
37
|
+
### Parameters
|
|
38
|
+
|
|
39
|
+
| Name | Type | Required | Description |
|
|
40
|
+
|------|------|----------|-------------|
|
|
41
|
+
| `toolId` | string | Yes | Tool identifier (format: `package::exportName`) |
|
|
42
|
+
| `params` | object | Yes | Parameters to pass to the tool |
|
|
43
|
+
| `env` | object | No | Environment variables (API keys) if required |
|
|
44
|
+
|
|
45
|
+
### Example
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
// Execute a web search tool
|
|
49
|
+
const result = await registryExecuteTool.execute({
|
|
50
|
+
toolId: '@exalabs/ai-sdk::webSearch',
|
|
51
|
+
params: { query: 'latest AI news' },
|
|
52
|
+
env: { EXA_API_KEY: 'your-api-key' },
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Result:
|
|
56
|
+
// {
|
|
57
|
+
// toolId: '@exalabs/ai-sdk::webSearch',
|
|
58
|
+
// executionTimeMs: 1234,
|
|
59
|
+
// output: { results: [...] }
|
|
60
|
+
// }
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Returns
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"toolId": "@exalabs/ai-sdk::webSearch",
|
|
68
|
+
"executionTimeMs": 1234,
|
|
69
|
+
"output": { ... }
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Environment Variables
|
|
74
|
+
|
|
75
|
+
| Variable | Default | Description |
|
|
76
|
+
|----------|---------|-------------|
|
|
77
|
+
| `TPMJS_API_URL` | `https://tpmjs.com` | Base URL for the registry API |
|
|
78
|
+
| `TPMJS_EXECUTOR_URL` | `https://executor.tpmjs.com` | URL for the sandbox executor |
|
|
79
|
+
|
|
80
|
+
### Self-Hosted Registry
|
|
81
|
+
|
|
82
|
+
To use your own TPMJS registry and executor:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
export TPMJS_API_URL=https://registry.mycompany.com
|
|
86
|
+
export TPMJS_EXECUTOR_URL=https://executor.mycompany.com
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Security
|
|
90
|
+
|
|
91
|
+
- All tools run in a sandboxed Deno environment on Railway
|
|
92
|
+
- API keys are passed per-request, never stored
|
|
93
|
+
- Only registered tools can be executed (no arbitrary code)
|
|
94
|
+
|
|
95
|
+
## Related
|
|
96
|
+
|
|
97
|
+
- [@tpmjs/registry-search](https://www.npmjs.com/package/@tpmjs/registry-search) - Find tools to execute
|
|
98
|
+
- [TPMJS Registry](https://tpmjs.com) - Browse all available tools
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input type for Registry Execute Tool
|
|
3
|
+
*/
|
|
4
|
+
type RegistryExecuteInput = {
|
|
5
|
+
toolId: string;
|
|
6
|
+
params: Record<string, unknown>;
|
|
7
|
+
env?: Record<string, string>;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* AI SDK tool for executing tools from the TPMJS registry
|
|
11
|
+
*
|
|
12
|
+
* Use registrySearchTool first to find the toolId, then execute with this tool.
|
|
13
|
+
* Tools run in a secure sandbox - no local installation required.
|
|
14
|
+
*
|
|
15
|
+
* Supports self-hosted registries via environment variables:
|
|
16
|
+
* - TPMJS_API_URL: Registry API (default: https://tpmjs.com)
|
|
17
|
+
* - TPMJS_EXECUTOR_URL: Sandbox executor (default: https://executor.tpmjs.com)
|
|
18
|
+
*/
|
|
19
|
+
export declare const registryExecuteTool: import("ai").Tool<RegistryExecuteInput, {
|
|
20
|
+
toolId: string;
|
|
21
|
+
executionTimeMs: any;
|
|
22
|
+
output: any;
|
|
23
|
+
}>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,KAAK,oBAAoB,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB;;;;EA+F9B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { jsonSchema, tool } from 'ai';
|
|
2
|
+
const TPMJS_API_URL = process.env.TPMJS_API_URL || 'https://tpmjs.com';
|
|
3
|
+
const TPMJS_EXECUTOR_URL = process.env.TPMJS_EXECUTOR_URL || 'https://executor.tpmjs.com';
|
|
4
|
+
/**
|
|
5
|
+
* AI SDK tool for executing tools from the TPMJS registry
|
|
6
|
+
*
|
|
7
|
+
* Use registrySearchTool first to find the toolId, then execute with this tool.
|
|
8
|
+
* Tools run in a secure sandbox - no local installation required.
|
|
9
|
+
*
|
|
10
|
+
* Supports self-hosted registries via environment variables:
|
|
11
|
+
* - TPMJS_API_URL: Registry API (default: https://tpmjs.com)
|
|
12
|
+
* - TPMJS_EXECUTOR_URL: Sandbox executor (default: https://executor.tpmjs.com)
|
|
13
|
+
*/
|
|
14
|
+
export const registryExecuteTool = tool({
|
|
15
|
+
description: 'Execute a tool from the TPMJS registry. Use registrySearchTool first to find the toolId. Tools run in a secure sandbox.',
|
|
16
|
+
inputSchema: jsonSchema({
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
toolId: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
description: "Tool identifier from registrySearchTool (format: 'package::exportName')",
|
|
22
|
+
},
|
|
23
|
+
params: {
|
|
24
|
+
type: 'object',
|
|
25
|
+
description: 'Parameters to pass to the tool',
|
|
26
|
+
additionalProperties: true,
|
|
27
|
+
},
|
|
28
|
+
env: {
|
|
29
|
+
type: 'object',
|
|
30
|
+
description: 'Environment variables (API keys) if required by the tool',
|
|
31
|
+
additionalProperties: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
required: ['toolId', 'params'],
|
|
37
|
+
additionalProperties: false,
|
|
38
|
+
}),
|
|
39
|
+
async execute({ toolId, params, env }) {
|
|
40
|
+
// Parse toolId format: "package::exportName"
|
|
41
|
+
const separatorIndex = toolId.lastIndexOf('::');
|
|
42
|
+
if (separatorIndex === -1) {
|
|
43
|
+
throw new Error(`Invalid toolId format. Expected "package::exportName", got "${toolId}"`);
|
|
44
|
+
}
|
|
45
|
+
const packageName = toolId.substring(0, separatorIndex);
|
|
46
|
+
const exportName = toolId.substring(separatorIndex + 2);
|
|
47
|
+
if (!packageName || !exportName) {
|
|
48
|
+
throw new Error(`Invalid toolId format. Expected "package::exportName", got "${toolId}"`);
|
|
49
|
+
}
|
|
50
|
+
// Fetch tool metadata to get version and importUrl
|
|
51
|
+
const metaParams = new URLSearchParams({
|
|
52
|
+
q: exportName,
|
|
53
|
+
limit: '10',
|
|
54
|
+
});
|
|
55
|
+
const metaResponse = await fetch(`${TPMJS_API_URL}/api/tools/search?${metaParams}`);
|
|
56
|
+
if (!metaResponse.ok) {
|
|
57
|
+
throw new Error(`Failed to fetch tool metadata: ${metaResponse.statusText}`);
|
|
58
|
+
}
|
|
59
|
+
// biome-ignore lint/suspicious/noExplicitAny: API response types vary
|
|
60
|
+
const metaData = (await metaResponse.json());
|
|
61
|
+
const toolsArray = metaData.results?.tools || [];
|
|
62
|
+
// Find the exact tool match
|
|
63
|
+
// biome-ignore lint/suspicious/noExplicitAny: API response types vary
|
|
64
|
+
const toolMeta = toolsArray.find((t) => t.package.npmPackageName === packageName && t.exportName === exportName);
|
|
65
|
+
if (!toolMeta) {
|
|
66
|
+
throw new Error(`Tool not found: ${toolId}`);
|
|
67
|
+
}
|
|
68
|
+
const version = toolMeta.package.npmVersion;
|
|
69
|
+
const importUrl = `https://esm.sh/${packageName}@${version}`;
|
|
70
|
+
// Execute via sandbox executor
|
|
71
|
+
const response = await fetch(`${TPMJS_EXECUTOR_URL}/execute-tool`, {
|
|
72
|
+
method: 'POST',
|
|
73
|
+
headers: { 'Content-Type': 'application/json' },
|
|
74
|
+
body: JSON.stringify({
|
|
75
|
+
packageName,
|
|
76
|
+
exportName,
|
|
77
|
+
version,
|
|
78
|
+
importUrl,
|
|
79
|
+
params,
|
|
80
|
+
env: env || {},
|
|
81
|
+
}),
|
|
82
|
+
});
|
|
83
|
+
// biome-ignore lint/suspicious/noExplicitAny: API response types vary
|
|
84
|
+
const result = (await response.json());
|
|
85
|
+
if (!result.success) {
|
|
86
|
+
throw new Error(result.error || 'Tool execution failed');
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
toolId,
|
|
90
|
+
executionTimeMs: result.executionTimeMs,
|
|
91
|
+
output: result.output,
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;IACtC,WAAW,EACT,yHAAyH;IAC3H,WAAW,EAAE,UAAU,CAAuB;QAC5C,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,yEAAyE;aACvF;YACD,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,gCAAgC;gBAC7C,oBAAoB,EAAE,IAAI;aAC3B;YAC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|
+
{
|
|
2
|
+
"name": "@tpmjs/registry-execute",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Execute tools from the TPMJS registry in any AI SDK agent",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"tpmjs-tool",
|
|
9
|
+
"ai-sdk",
|
|
10
|
+
"vercel-ai",
|
|
11
|
+
"registry",
|
|
12
|
+
"execute"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"ai": "6.0.0-beta.124"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.7.2",
|
|
19
|
+
"@tpmjs/tsconfig": "0.0.0"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/ajaxdavis/tpmjs.git",
|
|
31
|
+
"directory": "packages/tools/registryExecute"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://tpmjs.com",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"tpmjs": {
|
|
36
|
+
"category": "api-integration",
|
|
37
|
+
"frameworks": [
|
|
38
|
+
"vercel-ai"
|
|
39
|
+
],
|
|
40
|
+
"tools": [
|
|
41
|
+
{
|
|
42
|
+
"exportName": "registryExecuteTool",
|
|
43
|
+
"description": "Execute a tool from the TPMJS registry by toolId. Use registrySearchTool first to find toolIds.",
|
|
44
|
+
"parameters": [
|
|
45
|
+
{
|
|
46
|
+
"name": "toolId",
|
|
47
|
+
"type": "string",
|
|
48
|
+
"description": "Tool identifier from registrySearchTool (format: 'package::exportName')",
|
|
49
|
+
"required": true
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"name": "params",
|
|
53
|
+
"type": "object",
|
|
54
|
+
"description": "Parameters to pass to the tool",
|
|
55
|
+
"required": true
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": "env",
|
|
59
|
+
"type": "object",
|
|
60
|
+
"description": "Environment variables (API keys) if required by the tool",
|
|
61
|
+
"required": false
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
"returns": {
|
|
65
|
+
"type": "object",
|
|
66
|
+
"description": "Tool execution result with output and timing"
|
|
67
|
+
},
|
|
68
|
+
"aiAgent": {
|
|
69
|
+
"useCase": "Use after finding a tool with registrySearchTool. Execute the tool by its toolId with the required parameters.",
|
|
70
|
+
"examples": [
|
|
71
|
+
"Execute '@exalabs/ai-sdk::webSearch' with query parameter",
|
|
72
|
+
"Execute '@firecrawl/ai-sdk::scrapeTool' with url parameter"
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
"scripts": {
|
|
79
|
+
"build": "tsc",
|
|
80
|
+
"dev": "tsc --watch",
|
|
81
|
+
"type-check": "tsc --noEmit"
|
|
82
|
+
}
|
|
83
|
+
}
|