@tpmjs/registry-execute 0.1.1 → 0.1.2
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 +71 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -90,10 +90,81 @@ export TPMJS_API_URL=https://registry.mycompany.com
|
|
|
90
90
|
export TPMJS_EXECUTOR_URL=https://executor.mycompany.com
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
+
## Passing API Keys to Tools
|
|
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 `env` parameter lets you pass these securely.
|
|
96
|
+
|
|
97
|
+
### How It Works
|
|
98
|
+
|
|
99
|
+
1. **Search returns required keys**: When you search for a tool, the response includes `requiredEnvVars`:
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"toolId": "@firecrawl/ai-sdk::scrapeTool",
|
|
103
|
+
"requiredEnvVars": ["FIRECRAWL_API_KEY"]
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
2. **Pass keys when executing**: Include the required keys in the `env` parameter:
|
|
108
|
+
```typescript
|
|
109
|
+
registryExecute({
|
|
110
|
+
toolId: '@firecrawl/ai-sdk::scrapeTool',
|
|
111
|
+
params: { url: 'https://example.com' },
|
|
112
|
+
env: { FIRECRAWL_API_KEY: 'fc-xxx' }
|
|
113
|
+
})
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
3. **Keys are injected into sandbox**: The executor injects these as environment variables in the isolated Deno runtime where the tool runs.
|
|
117
|
+
|
|
118
|
+
### Example: Agent with Pre-configured Keys
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import { streamText } from 'ai';
|
|
122
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
123
|
+
import { registrySearchTool } from '@tpmjs/registry-search';
|
|
124
|
+
import { registryExecuteTool } from '@tpmjs/registry-execute';
|
|
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
|
+
};
|
|
131
|
+
|
|
132
|
+
const result = streamText({
|
|
133
|
+
model: anthropic('claude-sonnet-4-20250514'),
|
|
134
|
+
tools: {
|
|
135
|
+
registrySearch: registrySearchTool,
|
|
136
|
+
registryExecute: registryExecuteTool,
|
|
137
|
+
},
|
|
138
|
+
system: `You have access to the TPMJS tool registry.
|
|
139
|
+
When executing tools, use these API keys in the env parameter:
|
|
140
|
+
${JSON.stringify(API_KEYS, null, 2)}
|
|
141
|
+
|
|
142
|
+
If a tool requires a key you don't have, tell the user.`,
|
|
143
|
+
prompt: 'Scrape https://example.com and summarize the content',
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Tools Without Required Keys
|
|
148
|
+
|
|
149
|
+
Some tools don't require any API keys (like `@tpmjs/createblogpost`). For these, you can omit the `env` parameter entirely:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
registryExecute({
|
|
153
|
+
toolId: '@tpmjs/createblogpost::createBlogPostTool',
|
|
154
|
+
params: {
|
|
155
|
+
title: 'My Post',
|
|
156
|
+
author: 'Jane Doe',
|
|
157
|
+
content: 'Hello world...'
|
|
158
|
+
}
|
|
159
|
+
// No env needed
|
|
160
|
+
})
|
|
161
|
+
```
|
|
162
|
+
|
|
93
163
|
## Security
|
|
94
164
|
|
|
95
165
|
- All tools run in a sandboxed Deno environment on Railway
|
|
96
166
|
- API keys are passed per-request, never stored
|
|
167
|
+
- Keys are isolated to the specific tool execution
|
|
97
168
|
- Only registered tools can be executed (no arbitrary code)
|
|
98
169
|
|
|
99
170
|
## Related
|