@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.
Files changed (2) hide show
  1. package/README.md +38 -44
  2. 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 `env` parameter lets you pass these securely.
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
- ### How It Works
97
+ ### Recommended: Create a Wrapper
98
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
- ```
99
+ ```typescript
100
+ import { tool } from 'ai';
101
+ import { registryExecuteTool } from '@tpmjs/registry-execute';
106
102
 
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
- ```
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
- 3. **Keys are injected into sandbox**: The executor injects these as environment variables in the isolated Deno runtime where the tool runs.
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
- ### Example: Agent with Pre-configured Keys
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 { 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
- };
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: registryExecuteTool,
131
+ registryExecute, // Keys are auto-injected
137
132
  },
138
133
  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.`,
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
- ### Tools Without Required Keys
139
+ ### How It Works
148
140
 
149
- Some tools don't require any API keys (like `@tpmjs/createblogpost`). For these, you can omit the `env` parameter entirely:
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
- ```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
- ```
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tpmjs/registry-execute",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Execute tools from the TPMJS registry in any AI SDK agent",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",