@majkapp/plugin-kit 3.7.3 → 3.7.5
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/bin/promptable-cli.js +88 -0
- package/docs/AGENTS.md +641 -0
- package/docs/AUTH.md +248 -0
- package/docs/BATCH.md +256 -0
- package/docs/CONFIG_API.md +206 -0
- package/docs/CONVERSATIONS_API.md +283 -0
- package/docs/DELEGATION.md +196 -0
- package/docs/INDEX.md +38 -0
- package/docs/KNOWLEDGE.md +225 -0
- package/docs/PLUGINS.md +356 -0
- package/docs/REPORTS.md +271 -0
- package/docs/SCRIPTING.md +231 -0
- package/docs/SECRETS.md +412 -0
- package/docs/SKILLS.md +514 -0
- package/docs/TASKS.md +622 -0
- package/docs/TOOL_DISCOVERY.md +240 -0
- package/package.json +1 -1
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# Tool Discovery API
|
|
2
|
+
|
|
3
|
+
Discover available service functions and invoke them dynamically.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
handler: async (input, ctx) => {
|
|
9
|
+
// Discover all available tools
|
|
10
|
+
const { services, summary } = await ctx.majk.toolDiscovery.discover_tools();
|
|
11
|
+
ctx.logger.info(`Found ${summary.totalFunctions} functions`);
|
|
12
|
+
|
|
13
|
+
// Get schema for a specific function
|
|
14
|
+
const schema = await ctx.majk.toolDiscovery.get_tool_schema({
|
|
15
|
+
functionName: 'list_reports'
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// Invoke dynamically
|
|
19
|
+
const result = await ctx.majk.toolDiscovery.invoke_tool({
|
|
20
|
+
functionName: 'list_reports',
|
|
21
|
+
parameters: { limit: 10 }
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return { reports: result.reports };
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## API Reference
|
|
29
|
+
|
|
30
|
+
### discover_tools(input?)
|
|
31
|
+
|
|
32
|
+
Discover available service functions.
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
const { services, summary } = await ctx.majk.toolDiscovery.discover_tools({
|
|
36
|
+
pluginId?: string, // Filter by plugin
|
|
37
|
+
category?: string, // Filter by category
|
|
38
|
+
functionNameContains?: string, // Search function names
|
|
39
|
+
builtinOnly?: boolean, // Only built-in services
|
|
40
|
+
requiresIdentity?: string // Filter by identity requirement
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Returns:
|
|
44
|
+
{
|
|
45
|
+
services: DiscoveredService[],
|
|
46
|
+
summary: {
|
|
47
|
+
totalServices: number,
|
|
48
|
+
totalFunctions: number,
|
|
49
|
+
byCategory: Record<string, number>,
|
|
50
|
+
byPlugin: Record<string, number>
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### DiscoveredService
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
interface DiscoveredService {
|
|
59
|
+
pluginId: string;
|
|
60
|
+
serviceName: string;
|
|
61
|
+
displayName: string;
|
|
62
|
+
description: string;
|
|
63
|
+
isBuiltin: boolean;
|
|
64
|
+
category?: string;
|
|
65
|
+
functionCount: number;
|
|
66
|
+
functions: DiscoveredFunction[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface DiscoveredFunction {
|
|
70
|
+
name: string;
|
|
71
|
+
description: string;
|
|
72
|
+
inputSchema: Record<string, any>;
|
|
73
|
+
identityRequirements?: Array<{
|
|
74
|
+
identityType: string;
|
|
75
|
+
required: boolean;
|
|
76
|
+
description?: string;
|
|
77
|
+
}>;
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### get_tool_schema(input)
|
|
82
|
+
|
|
83
|
+
Get detailed schema for a function.
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
const { function: fn, service } = await ctx.majk.toolDiscovery.get_tool_schema({
|
|
87
|
+
functionName: string
|
|
88
|
+
});
|
|
89
|
+
// fn: DiscoveredFunction with full inputSchema
|
|
90
|
+
// service: { pluginId, serviceName, displayName, category? }
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### list_tool_names()
|
|
94
|
+
|
|
95
|
+
Get simple list of all function names.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
const { functions, count } = await ctx.majk.toolDiscovery.list_tool_names();
|
|
99
|
+
// functions: string[]
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### list_tool_categories()
|
|
103
|
+
|
|
104
|
+
List all tool categories.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
const { categories, count } = await ctx.majk.toolDiscovery.list_tool_categories();
|
|
108
|
+
// categories: string[]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### get_rpc_invocation_info(input)
|
|
112
|
+
|
|
113
|
+
Get RPC details for a function.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
const info = await ctx.majk.toolDiscovery.get_rpc_invocation_info({
|
|
117
|
+
functionName: string
|
|
118
|
+
});
|
|
119
|
+
// Returns: { rpcServiceName, functionName, inputSchema, outputSchema?, readOnly, service, identityRequirements? }
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### invoke_tool(input)
|
|
123
|
+
|
|
124
|
+
Invoke a function dynamically.
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
const result = await ctx.majk.toolDiscovery.invoke_tool({
|
|
128
|
+
functionName: string,
|
|
129
|
+
parameters?: Record<string, any>,
|
|
130
|
+
timeoutMs?: number
|
|
131
|
+
});
|
|
132
|
+
// Returns: Function result (type depends on function)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Common Patterns
|
|
136
|
+
|
|
137
|
+
### Filter by Category
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
// Find all delegation tools
|
|
141
|
+
const { services } = await ctx.majk.toolDiscovery.discover_tools({
|
|
142
|
+
category: 'delegation'
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
for (const service of services) {
|
|
146
|
+
console.log(`${service.displayName}: ${service.functionCount} functions`);
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Search Functions
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
// Find functions related to reports
|
|
154
|
+
const { services } = await ctx.majk.toolDiscovery.discover_tools({
|
|
155
|
+
functionNameContains: 'report'
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const reportFunctions = services.flatMap(s => s.functions);
|
|
159
|
+
console.log('Report functions:', reportFunctions.map(f => f.name));
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Dynamic Invocation
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
// Build a generic tool executor
|
|
166
|
+
async function executeTool(name: string, params: any) {
|
|
167
|
+
// Validate function exists
|
|
168
|
+
const { function: fn } = await ctx.majk.toolDiscovery.get_tool_schema({
|
|
169
|
+
functionName: name
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
ctx.logger.info(`Invoking ${name}`, { params });
|
|
173
|
+
|
|
174
|
+
const result = await ctx.majk.toolDiscovery.invoke_tool({
|
|
175
|
+
functionName: name,
|
|
176
|
+
parameters: params,
|
|
177
|
+
timeoutMs: 30000
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Check Identity Requirements
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
const { function: fn } = await ctx.majk.toolDiscovery.get_tool_schema({
|
|
188
|
+
functionName: 'github_create_pr'
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
if (fn.identityRequirements?.some(r => r.required)) {
|
|
192
|
+
const required = fn.identityRequirements.filter(r => r.required);
|
|
193
|
+
ctx.logger.warn('Function requires identity:', required);
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Build Tool Browser
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
// Get all tools organized by category
|
|
201
|
+
const { services, summary } = await ctx.majk.toolDiscovery.discover_tools();
|
|
202
|
+
|
|
203
|
+
const byCategory: Record<string, DiscoveredFunction[]> = {};
|
|
204
|
+
|
|
205
|
+
for (const service of services) {
|
|
206
|
+
const category = service.category || 'uncategorized';
|
|
207
|
+
byCategory[category] = byCategory[category] || [];
|
|
208
|
+
byCategory[category].push(...service.functions);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Display summary
|
|
212
|
+
for (const [category, functions] of Object.entries(byCategory)) {
|
|
213
|
+
console.log(`\n${category} (${functions.length} functions)`);
|
|
214
|
+
for (const fn of functions) {
|
|
215
|
+
console.log(` - ${fn.name}: ${fn.description}`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Use Cases
|
|
221
|
+
|
|
222
|
+
1. **Plugin orchestration** - Discover and call functions from other plugins
|
|
223
|
+
2. **Dynamic workflows** - Build flexible automation based on available tools
|
|
224
|
+
3. **Tool documentation** - Generate docs from discovered schemas
|
|
225
|
+
4. **Validation** - Check function existence before invocation
|
|
226
|
+
5. **Admin interfaces** - Build tool browsers and executors
|
|
227
|
+
|
|
228
|
+
## Best Practices
|
|
229
|
+
|
|
230
|
+
1. **Cache discovery results** - Don't call discover_tools repeatedly
|
|
231
|
+
2. **Handle missing functions** - Check if function exists before invoke
|
|
232
|
+
3. **Validate parameters** - Use schema to validate inputs
|
|
233
|
+
4. **Set timeouts** - Use timeoutMs for long-running functions
|
|
234
|
+
5. **Check identity requirements** - Ensure required identities are available
|
|
235
|
+
|
|
236
|
+
## Next Steps
|
|
237
|
+
|
|
238
|
+
Run `npx @majkapp/plugin-kit --scripting` - Script execution API
|
|
239
|
+
Run `npx @majkapp/plugin-kit --services` - Service grouping patterns
|
|
240
|
+
Run `npx @majkapp/plugin-kit --rpc` - RPC and callbacks
|
package/package.json
CHANGED