@tpmjs/registry-execute 0.1.2 → 0.1.3
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 +38 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -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
|
|