agentbnb 2.2.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/LICENSE +21 -0
- package/README.md +144 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +4048 -0
- package/dist/index.d.ts +676 -0
- package/dist/index.js +894 -0
- package/package.json +75 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,676 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import Database from 'better-sqlite3';
|
|
3
|
+
import { FastifyInstance } from 'fastify';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Capability Card — the core unit of AgentBnB
|
|
7
|
+
*
|
|
8
|
+
* Level 1 (Atomic): Single API capability (e.g. ElevenLabs TTS)
|
|
9
|
+
* Level 2 (Pipeline): Multiple Atomics chained (e.g. text → voice → video)
|
|
10
|
+
* Level 3 (Environment): Full deployment with all dependencies
|
|
11
|
+
*/
|
|
12
|
+
declare const CapabilityCardSchema: z.ZodObject<{
|
|
13
|
+
spec_version: z.ZodDefault<z.ZodLiteral<"1.0">>;
|
|
14
|
+
id: z.ZodString;
|
|
15
|
+
owner: z.ZodString;
|
|
16
|
+
name: z.ZodString;
|
|
17
|
+
description: z.ZodString;
|
|
18
|
+
level: z.ZodUnion<[z.ZodLiteral<1>, z.ZodLiteral<2>, z.ZodLiteral<3>]>;
|
|
19
|
+
inputs: z.ZodArray<z.ZodObject<{
|
|
20
|
+
name: z.ZodString;
|
|
21
|
+
type: z.ZodEnum<["text", "json", "file", "audio", "image", "video", "stream"]>;
|
|
22
|
+
description: z.ZodOptional<z.ZodString>;
|
|
23
|
+
required: z.ZodDefault<z.ZodBoolean>;
|
|
24
|
+
schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
name: string;
|
|
27
|
+
type: "text" | "json" | "file" | "audio" | "image" | "video" | "stream";
|
|
28
|
+
required: boolean;
|
|
29
|
+
description?: string | undefined;
|
|
30
|
+
schema?: Record<string, unknown> | undefined;
|
|
31
|
+
}, {
|
|
32
|
+
name: string;
|
|
33
|
+
type: "text" | "json" | "file" | "audio" | "image" | "video" | "stream";
|
|
34
|
+
description?: string | undefined;
|
|
35
|
+
required?: boolean | undefined;
|
|
36
|
+
schema?: Record<string, unknown> | undefined;
|
|
37
|
+
}>, "many">;
|
|
38
|
+
outputs: z.ZodArray<z.ZodObject<{
|
|
39
|
+
name: z.ZodString;
|
|
40
|
+
type: z.ZodEnum<["text", "json", "file", "audio", "image", "video", "stream"]>;
|
|
41
|
+
description: z.ZodOptional<z.ZodString>;
|
|
42
|
+
required: z.ZodDefault<z.ZodBoolean>;
|
|
43
|
+
schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
44
|
+
}, "strip", z.ZodTypeAny, {
|
|
45
|
+
name: string;
|
|
46
|
+
type: "text" | "json" | "file" | "audio" | "image" | "video" | "stream";
|
|
47
|
+
required: boolean;
|
|
48
|
+
description?: string | undefined;
|
|
49
|
+
schema?: Record<string, unknown> | undefined;
|
|
50
|
+
}, {
|
|
51
|
+
name: string;
|
|
52
|
+
type: "text" | "json" | "file" | "audio" | "image" | "video" | "stream";
|
|
53
|
+
description?: string | undefined;
|
|
54
|
+
required?: boolean | undefined;
|
|
55
|
+
schema?: Record<string, unknown> | undefined;
|
|
56
|
+
}>, "many">;
|
|
57
|
+
pricing: z.ZodObject<{
|
|
58
|
+
credits_per_call: z.ZodNumber;
|
|
59
|
+
credits_per_minute: z.ZodOptional<z.ZodNumber>;
|
|
60
|
+
/** Number of free monthly calls. Shown as a "N free/mo" badge in the Hub. */
|
|
61
|
+
free_tier: z.ZodOptional<z.ZodNumber>;
|
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
credits_per_call: number;
|
|
64
|
+
credits_per_minute?: number | undefined;
|
|
65
|
+
free_tier?: number | undefined;
|
|
66
|
+
}, {
|
|
67
|
+
credits_per_call: number;
|
|
68
|
+
credits_per_minute?: number | undefined;
|
|
69
|
+
free_tier?: number | undefined;
|
|
70
|
+
}>;
|
|
71
|
+
availability: z.ZodObject<{
|
|
72
|
+
online: z.ZodBoolean;
|
|
73
|
+
schedule: z.ZodOptional<z.ZodString>;
|
|
74
|
+
}, "strip", z.ZodTypeAny, {
|
|
75
|
+
online: boolean;
|
|
76
|
+
schedule?: string | undefined;
|
|
77
|
+
}, {
|
|
78
|
+
online: boolean;
|
|
79
|
+
schedule?: string | undefined;
|
|
80
|
+
}>;
|
|
81
|
+
powered_by: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
82
|
+
provider: z.ZodString;
|
|
83
|
+
model: z.ZodOptional<z.ZodString>;
|
|
84
|
+
tier: z.ZodOptional<z.ZodString>;
|
|
85
|
+
}, "strip", z.ZodTypeAny, {
|
|
86
|
+
provider: string;
|
|
87
|
+
model?: string | undefined;
|
|
88
|
+
tier?: string | undefined;
|
|
89
|
+
}, {
|
|
90
|
+
provider: string;
|
|
91
|
+
model?: string | undefined;
|
|
92
|
+
tier?: string | undefined;
|
|
93
|
+
}>, "many">>;
|
|
94
|
+
/**
|
|
95
|
+
* Private per-card metadata. Stripped from all API and CLI responses —
|
|
96
|
+
* never transmitted beyond the local store.
|
|
97
|
+
*/
|
|
98
|
+
_internal: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
99
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
100
|
+
apis_used: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
101
|
+
avg_latency_ms: z.ZodOptional<z.ZodNumber>;
|
|
102
|
+
success_rate: z.ZodOptional<z.ZodNumber>;
|
|
103
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
104
|
+
}, "strip", z.ZodTypeAny, {
|
|
105
|
+
apis_used?: string[] | undefined;
|
|
106
|
+
avg_latency_ms?: number | undefined;
|
|
107
|
+
success_rate?: number | undefined;
|
|
108
|
+
tags?: string[] | undefined;
|
|
109
|
+
}, {
|
|
110
|
+
apis_used?: string[] | undefined;
|
|
111
|
+
avg_latency_ms?: number | undefined;
|
|
112
|
+
success_rate?: number | undefined;
|
|
113
|
+
tags?: string[] | undefined;
|
|
114
|
+
}>>;
|
|
115
|
+
created_at: z.ZodOptional<z.ZodString>;
|
|
116
|
+
updated_at: z.ZodOptional<z.ZodString>;
|
|
117
|
+
}, "strip", z.ZodTypeAny, {
|
|
118
|
+
name: string;
|
|
119
|
+
description: string;
|
|
120
|
+
spec_version: "1.0";
|
|
121
|
+
id: string;
|
|
122
|
+
owner: string;
|
|
123
|
+
level: 1 | 2 | 3;
|
|
124
|
+
inputs: {
|
|
125
|
+
name: string;
|
|
126
|
+
type: "text" | "json" | "file" | "audio" | "image" | "video" | "stream";
|
|
127
|
+
required: boolean;
|
|
128
|
+
description?: string | undefined;
|
|
129
|
+
schema?: Record<string, unknown> | undefined;
|
|
130
|
+
}[];
|
|
131
|
+
outputs: {
|
|
132
|
+
name: string;
|
|
133
|
+
type: "text" | "json" | "file" | "audio" | "image" | "video" | "stream";
|
|
134
|
+
required: boolean;
|
|
135
|
+
description?: string | undefined;
|
|
136
|
+
schema?: Record<string, unknown> | undefined;
|
|
137
|
+
}[];
|
|
138
|
+
pricing: {
|
|
139
|
+
credits_per_call: number;
|
|
140
|
+
credits_per_minute?: number | undefined;
|
|
141
|
+
free_tier?: number | undefined;
|
|
142
|
+
};
|
|
143
|
+
availability: {
|
|
144
|
+
online: boolean;
|
|
145
|
+
schedule?: string | undefined;
|
|
146
|
+
};
|
|
147
|
+
powered_by?: {
|
|
148
|
+
provider: string;
|
|
149
|
+
model?: string | undefined;
|
|
150
|
+
tier?: string | undefined;
|
|
151
|
+
}[] | undefined;
|
|
152
|
+
_internal?: Record<string, unknown> | undefined;
|
|
153
|
+
metadata?: {
|
|
154
|
+
apis_used?: string[] | undefined;
|
|
155
|
+
avg_latency_ms?: number | undefined;
|
|
156
|
+
success_rate?: number | undefined;
|
|
157
|
+
tags?: string[] | undefined;
|
|
158
|
+
} | undefined;
|
|
159
|
+
created_at?: string | undefined;
|
|
160
|
+
updated_at?: string | undefined;
|
|
161
|
+
}, {
|
|
162
|
+
name: string;
|
|
163
|
+
description: string;
|
|
164
|
+
id: string;
|
|
165
|
+
owner: string;
|
|
166
|
+
level: 1 | 2 | 3;
|
|
167
|
+
inputs: {
|
|
168
|
+
name: string;
|
|
169
|
+
type: "text" | "json" | "file" | "audio" | "image" | "video" | "stream";
|
|
170
|
+
description?: string | undefined;
|
|
171
|
+
required?: boolean | undefined;
|
|
172
|
+
schema?: Record<string, unknown> | undefined;
|
|
173
|
+
}[];
|
|
174
|
+
outputs: {
|
|
175
|
+
name: string;
|
|
176
|
+
type: "text" | "json" | "file" | "audio" | "image" | "video" | "stream";
|
|
177
|
+
description?: string | undefined;
|
|
178
|
+
required?: boolean | undefined;
|
|
179
|
+
schema?: Record<string, unknown> | undefined;
|
|
180
|
+
}[];
|
|
181
|
+
pricing: {
|
|
182
|
+
credits_per_call: number;
|
|
183
|
+
credits_per_minute?: number | undefined;
|
|
184
|
+
free_tier?: number | undefined;
|
|
185
|
+
};
|
|
186
|
+
availability: {
|
|
187
|
+
online: boolean;
|
|
188
|
+
schedule?: string | undefined;
|
|
189
|
+
};
|
|
190
|
+
spec_version?: "1.0" | undefined;
|
|
191
|
+
powered_by?: {
|
|
192
|
+
provider: string;
|
|
193
|
+
model?: string | undefined;
|
|
194
|
+
tier?: string | undefined;
|
|
195
|
+
}[] | undefined;
|
|
196
|
+
_internal?: Record<string, unknown> | undefined;
|
|
197
|
+
metadata?: {
|
|
198
|
+
apis_used?: string[] | undefined;
|
|
199
|
+
avg_latency_ms?: number | undefined;
|
|
200
|
+
success_rate?: number | undefined;
|
|
201
|
+
tags?: string[] | undefined;
|
|
202
|
+
} | undefined;
|
|
203
|
+
created_at?: string | undefined;
|
|
204
|
+
updated_at?: string | undefined;
|
|
205
|
+
}>;
|
|
206
|
+
type CapabilityCard = z.infer<typeof CapabilityCardSchema>;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Opens a SQLite database at the given path (or in-memory if ':memory:').
|
|
210
|
+
* Applies WAL mode, enables foreign keys, creates base tables and FTS virtual table,
|
|
211
|
+
* calls createRequestLogTable, then runs schema migrations (which installs v2.0 triggers).
|
|
212
|
+
*
|
|
213
|
+
* @param path - File path or ':memory:' for in-memory. Defaults to ':memory:'.
|
|
214
|
+
* @returns Opened Database instance.
|
|
215
|
+
*/
|
|
216
|
+
declare function openDatabase(path?: string): Database.Database;
|
|
217
|
+
/**
|
|
218
|
+
* Inserts a CapabilityCard into the registry.
|
|
219
|
+
* Validates the card via Zod schema before inserting.
|
|
220
|
+
* Auto-sets created_at and updated_at to current ISO timestamp.
|
|
221
|
+
*
|
|
222
|
+
* @param db - Open database instance.
|
|
223
|
+
* @param card - Card to insert.
|
|
224
|
+
* @throws {AgentBnBError} with code VALIDATION_ERROR if card fails schema validation.
|
|
225
|
+
*/
|
|
226
|
+
declare function insertCard(db: Database.Database, card: CapabilityCard): void;
|
|
227
|
+
/**
|
|
228
|
+
* Retrieves a CapabilityCard by its ID.
|
|
229
|
+
*
|
|
230
|
+
* @param db - Open database instance.
|
|
231
|
+
* @param id - UUID of the card to retrieve.
|
|
232
|
+
* @returns The CapabilityCard if found, or null if not found.
|
|
233
|
+
*/
|
|
234
|
+
declare function getCard(db: Database.Database, id: string): CapabilityCard | null;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Filters for capability card search.
|
|
238
|
+
*/
|
|
239
|
+
interface SearchFilters {
|
|
240
|
+
/** Filter to a specific capability level: 1 (Atomic), 2 (Pipeline), 3 (Environment). */
|
|
241
|
+
level?: 1 | 2 | 3;
|
|
242
|
+
/** Filter by online availability. */
|
|
243
|
+
online?: boolean;
|
|
244
|
+
/** Filter cards that use all of the specified APIs. */
|
|
245
|
+
apis_used?: string[];
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Searches CapabilityCards using FTS5 full-text search with optional filters.
|
|
249
|
+
* Results are ranked by BM25 relevance score (most relevant first).
|
|
250
|
+
* Returns up to 50 results.
|
|
251
|
+
*
|
|
252
|
+
* @param db - Open database instance.
|
|
253
|
+
* @param query - Full-text search query string.
|
|
254
|
+
* @param filters - Optional filters for level, online status, and apis_used.
|
|
255
|
+
* @returns Array of matching CapabilityCard objects sorted by relevance.
|
|
256
|
+
*/
|
|
257
|
+
declare function searchCards(db: Database.Database, query: string, filters?: SearchFilters): CapabilityCard[];
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Opens a SQLite database for the credit system.
|
|
261
|
+
* Uses WAL mode for better read concurrency.
|
|
262
|
+
*
|
|
263
|
+
* @param path - Path to the database file. Defaults to ':memory:' for in-memory.
|
|
264
|
+
* @returns Configured Database instance with all credit tables created.
|
|
265
|
+
*/
|
|
266
|
+
declare function openCreditDb(path?: string): Database.Database;
|
|
267
|
+
/**
|
|
268
|
+
* Returns the current credit balance for an agent.
|
|
269
|
+
* Returns 0 if the agent has never been bootstrapped.
|
|
270
|
+
*
|
|
271
|
+
* @param db - The credit database instance.
|
|
272
|
+
* @param owner - Agent identifier.
|
|
273
|
+
* @returns Current balance in credits.
|
|
274
|
+
*/
|
|
275
|
+
declare function getBalance(db: Database.Database, owner: string): number;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Discriminated union over all four skill configuration types.
|
|
279
|
+
* Used by SkillExecutor to dispatch to the correct executor mode.
|
|
280
|
+
*/
|
|
281
|
+
declare const SkillConfigSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
282
|
+
id: z.ZodString;
|
|
283
|
+
type: z.ZodLiteral<"api">;
|
|
284
|
+
name: z.ZodString;
|
|
285
|
+
endpoint: z.ZodString;
|
|
286
|
+
method: z.ZodEnum<["GET", "POST", "PUT", "DELETE"]>;
|
|
287
|
+
auth: z.ZodOptional<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
288
|
+
type: z.ZodLiteral<"bearer">;
|
|
289
|
+
token: z.ZodString;
|
|
290
|
+
}, "strip", z.ZodTypeAny, {
|
|
291
|
+
type: "bearer";
|
|
292
|
+
token: string;
|
|
293
|
+
}, {
|
|
294
|
+
type: "bearer";
|
|
295
|
+
token: string;
|
|
296
|
+
}>, z.ZodObject<{
|
|
297
|
+
type: z.ZodLiteral<"apikey">;
|
|
298
|
+
header: z.ZodDefault<z.ZodString>;
|
|
299
|
+
key: z.ZodString;
|
|
300
|
+
}, "strip", z.ZodTypeAny, {
|
|
301
|
+
type: "apikey";
|
|
302
|
+
header: string;
|
|
303
|
+
key: string;
|
|
304
|
+
}, {
|
|
305
|
+
type: "apikey";
|
|
306
|
+
key: string;
|
|
307
|
+
header?: string | undefined;
|
|
308
|
+
}>, z.ZodObject<{
|
|
309
|
+
type: z.ZodLiteral<"basic">;
|
|
310
|
+
username: z.ZodString;
|
|
311
|
+
password: z.ZodString;
|
|
312
|
+
}, "strip", z.ZodTypeAny, {
|
|
313
|
+
type: "basic";
|
|
314
|
+
username: string;
|
|
315
|
+
password: string;
|
|
316
|
+
}, {
|
|
317
|
+
type: "basic";
|
|
318
|
+
username: string;
|
|
319
|
+
password: string;
|
|
320
|
+
}>]>>;
|
|
321
|
+
input_mapping: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
322
|
+
output_mapping: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
323
|
+
pricing: z.ZodObject<{
|
|
324
|
+
credits_per_call: z.ZodNumber;
|
|
325
|
+
credits_per_minute: z.ZodOptional<z.ZodNumber>;
|
|
326
|
+
free_tier: z.ZodOptional<z.ZodNumber>;
|
|
327
|
+
}, "strip", z.ZodTypeAny, {
|
|
328
|
+
credits_per_call: number;
|
|
329
|
+
credits_per_minute?: number | undefined;
|
|
330
|
+
free_tier?: number | undefined;
|
|
331
|
+
}, {
|
|
332
|
+
credits_per_call: number;
|
|
333
|
+
credits_per_minute?: number | undefined;
|
|
334
|
+
free_tier?: number | undefined;
|
|
335
|
+
}>;
|
|
336
|
+
timeout_ms: z.ZodDefault<z.ZodNumber>;
|
|
337
|
+
retries: z.ZodDefault<z.ZodNumber>;
|
|
338
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
339
|
+
}, "strip", z.ZodTypeAny, {
|
|
340
|
+
name: string;
|
|
341
|
+
type: "api";
|
|
342
|
+
id: string;
|
|
343
|
+
pricing: {
|
|
344
|
+
credits_per_call: number;
|
|
345
|
+
credits_per_minute?: number | undefined;
|
|
346
|
+
free_tier?: number | undefined;
|
|
347
|
+
};
|
|
348
|
+
endpoint: string;
|
|
349
|
+
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
350
|
+
input_mapping: Record<string, string>;
|
|
351
|
+
output_mapping: Record<string, string>;
|
|
352
|
+
timeout_ms: number;
|
|
353
|
+
retries: number;
|
|
354
|
+
provider?: string | undefined;
|
|
355
|
+
auth?: {
|
|
356
|
+
type: "bearer";
|
|
357
|
+
token: string;
|
|
358
|
+
} | {
|
|
359
|
+
type: "apikey";
|
|
360
|
+
header: string;
|
|
361
|
+
key: string;
|
|
362
|
+
} | {
|
|
363
|
+
type: "basic";
|
|
364
|
+
username: string;
|
|
365
|
+
password: string;
|
|
366
|
+
} | undefined;
|
|
367
|
+
}, {
|
|
368
|
+
name: string;
|
|
369
|
+
type: "api";
|
|
370
|
+
id: string;
|
|
371
|
+
pricing: {
|
|
372
|
+
credits_per_call: number;
|
|
373
|
+
credits_per_minute?: number | undefined;
|
|
374
|
+
free_tier?: number | undefined;
|
|
375
|
+
};
|
|
376
|
+
endpoint: string;
|
|
377
|
+
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
378
|
+
provider?: string | undefined;
|
|
379
|
+
auth?: {
|
|
380
|
+
type: "bearer";
|
|
381
|
+
token: string;
|
|
382
|
+
} | {
|
|
383
|
+
type: "apikey";
|
|
384
|
+
key: string;
|
|
385
|
+
header?: string | undefined;
|
|
386
|
+
} | {
|
|
387
|
+
type: "basic";
|
|
388
|
+
username: string;
|
|
389
|
+
password: string;
|
|
390
|
+
} | undefined;
|
|
391
|
+
input_mapping?: Record<string, string> | undefined;
|
|
392
|
+
output_mapping?: Record<string, string> | undefined;
|
|
393
|
+
timeout_ms?: number | undefined;
|
|
394
|
+
retries?: number | undefined;
|
|
395
|
+
}>, z.ZodObject<{
|
|
396
|
+
id: z.ZodString;
|
|
397
|
+
type: z.ZodLiteral<"pipeline">;
|
|
398
|
+
name: z.ZodString;
|
|
399
|
+
steps: z.ZodArray<z.ZodUnion<[z.ZodObject<{
|
|
400
|
+
skill_id: z.ZodString;
|
|
401
|
+
input_mapping: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
402
|
+
}, "strip", z.ZodTypeAny, {
|
|
403
|
+
input_mapping: Record<string, string>;
|
|
404
|
+
skill_id: string;
|
|
405
|
+
}, {
|
|
406
|
+
skill_id: string;
|
|
407
|
+
input_mapping?: Record<string, string> | undefined;
|
|
408
|
+
}>, z.ZodObject<{
|
|
409
|
+
command: z.ZodString;
|
|
410
|
+
input_mapping: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
411
|
+
}, "strip", z.ZodTypeAny, {
|
|
412
|
+
input_mapping: Record<string, string>;
|
|
413
|
+
command: string;
|
|
414
|
+
}, {
|
|
415
|
+
command: string;
|
|
416
|
+
input_mapping?: Record<string, string> | undefined;
|
|
417
|
+
}>]>, "many">;
|
|
418
|
+
pricing: z.ZodObject<{
|
|
419
|
+
credits_per_call: z.ZodNumber;
|
|
420
|
+
credits_per_minute: z.ZodOptional<z.ZodNumber>;
|
|
421
|
+
free_tier: z.ZodOptional<z.ZodNumber>;
|
|
422
|
+
}, "strip", z.ZodTypeAny, {
|
|
423
|
+
credits_per_call: number;
|
|
424
|
+
credits_per_minute?: number | undefined;
|
|
425
|
+
free_tier?: number | undefined;
|
|
426
|
+
}, {
|
|
427
|
+
credits_per_call: number;
|
|
428
|
+
credits_per_minute?: number | undefined;
|
|
429
|
+
free_tier?: number | undefined;
|
|
430
|
+
}>;
|
|
431
|
+
timeout_ms: z.ZodOptional<z.ZodNumber>;
|
|
432
|
+
}, "strip", z.ZodTypeAny, {
|
|
433
|
+
name: string;
|
|
434
|
+
type: "pipeline";
|
|
435
|
+
id: string;
|
|
436
|
+
pricing: {
|
|
437
|
+
credits_per_call: number;
|
|
438
|
+
credits_per_minute?: number | undefined;
|
|
439
|
+
free_tier?: number | undefined;
|
|
440
|
+
};
|
|
441
|
+
steps: ({
|
|
442
|
+
input_mapping: Record<string, string>;
|
|
443
|
+
skill_id: string;
|
|
444
|
+
} | {
|
|
445
|
+
input_mapping: Record<string, string>;
|
|
446
|
+
command: string;
|
|
447
|
+
})[];
|
|
448
|
+
timeout_ms?: number | undefined;
|
|
449
|
+
}, {
|
|
450
|
+
name: string;
|
|
451
|
+
type: "pipeline";
|
|
452
|
+
id: string;
|
|
453
|
+
pricing: {
|
|
454
|
+
credits_per_call: number;
|
|
455
|
+
credits_per_minute?: number | undefined;
|
|
456
|
+
free_tier?: number | undefined;
|
|
457
|
+
};
|
|
458
|
+
steps: ({
|
|
459
|
+
skill_id: string;
|
|
460
|
+
input_mapping?: Record<string, string> | undefined;
|
|
461
|
+
} | {
|
|
462
|
+
command: string;
|
|
463
|
+
input_mapping?: Record<string, string> | undefined;
|
|
464
|
+
})[];
|
|
465
|
+
timeout_ms?: number | undefined;
|
|
466
|
+
}>, z.ZodObject<{
|
|
467
|
+
id: z.ZodString;
|
|
468
|
+
type: z.ZodLiteral<"openclaw">;
|
|
469
|
+
name: z.ZodString;
|
|
470
|
+
agent_name: z.ZodString;
|
|
471
|
+
channel: z.ZodEnum<["telegram", "webhook", "process"]>;
|
|
472
|
+
pricing: z.ZodObject<{
|
|
473
|
+
credits_per_call: z.ZodNumber;
|
|
474
|
+
credits_per_minute: z.ZodOptional<z.ZodNumber>;
|
|
475
|
+
free_tier: z.ZodOptional<z.ZodNumber>;
|
|
476
|
+
}, "strip", z.ZodTypeAny, {
|
|
477
|
+
credits_per_call: number;
|
|
478
|
+
credits_per_minute?: number | undefined;
|
|
479
|
+
free_tier?: number | undefined;
|
|
480
|
+
}, {
|
|
481
|
+
credits_per_call: number;
|
|
482
|
+
credits_per_minute?: number | undefined;
|
|
483
|
+
free_tier?: number | undefined;
|
|
484
|
+
}>;
|
|
485
|
+
timeout_ms: z.ZodOptional<z.ZodNumber>;
|
|
486
|
+
}, "strip", z.ZodTypeAny, {
|
|
487
|
+
name: string;
|
|
488
|
+
type: "openclaw";
|
|
489
|
+
id: string;
|
|
490
|
+
pricing: {
|
|
491
|
+
credits_per_call: number;
|
|
492
|
+
credits_per_minute?: number | undefined;
|
|
493
|
+
free_tier?: number | undefined;
|
|
494
|
+
};
|
|
495
|
+
agent_name: string;
|
|
496
|
+
channel: "telegram" | "webhook" | "process";
|
|
497
|
+
timeout_ms?: number | undefined;
|
|
498
|
+
}, {
|
|
499
|
+
name: string;
|
|
500
|
+
type: "openclaw";
|
|
501
|
+
id: string;
|
|
502
|
+
pricing: {
|
|
503
|
+
credits_per_call: number;
|
|
504
|
+
credits_per_minute?: number | undefined;
|
|
505
|
+
free_tier?: number | undefined;
|
|
506
|
+
};
|
|
507
|
+
agent_name: string;
|
|
508
|
+
channel: "telegram" | "webhook" | "process";
|
|
509
|
+
timeout_ms?: number | undefined;
|
|
510
|
+
}>, z.ZodObject<{
|
|
511
|
+
id: z.ZodString;
|
|
512
|
+
type: z.ZodLiteral<"command">;
|
|
513
|
+
name: z.ZodString;
|
|
514
|
+
command: z.ZodString;
|
|
515
|
+
output_type: z.ZodEnum<["json", "text", "file"]>;
|
|
516
|
+
allowed_commands: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
517
|
+
working_dir: z.ZodOptional<z.ZodString>;
|
|
518
|
+
timeout_ms: z.ZodDefault<z.ZodNumber>;
|
|
519
|
+
pricing: z.ZodObject<{
|
|
520
|
+
credits_per_call: z.ZodNumber;
|
|
521
|
+
credits_per_minute: z.ZodOptional<z.ZodNumber>;
|
|
522
|
+
free_tier: z.ZodOptional<z.ZodNumber>;
|
|
523
|
+
}, "strip", z.ZodTypeAny, {
|
|
524
|
+
credits_per_call: number;
|
|
525
|
+
credits_per_minute?: number | undefined;
|
|
526
|
+
free_tier?: number | undefined;
|
|
527
|
+
}, {
|
|
528
|
+
credits_per_call: number;
|
|
529
|
+
credits_per_minute?: number | undefined;
|
|
530
|
+
free_tier?: number | undefined;
|
|
531
|
+
}>;
|
|
532
|
+
}, "strip", z.ZodTypeAny, {
|
|
533
|
+
name: string;
|
|
534
|
+
type: "command";
|
|
535
|
+
id: string;
|
|
536
|
+
pricing: {
|
|
537
|
+
credits_per_call: number;
|
|
538
|
+
credits_per_minute?: number | undefined;
|
|
539
|
+
free_tier?: number | undefined;
|
|
540
|
+
};
|
|
541
|
+
timeout_ms: number;
|
|
542
|
+
command: string;
|
|
543
|
+
output_type: "text" | "json" | "file";
|
|
544
|
+
allowed_commands?: string[] | undefined;
|
|
545
|
+
working_dir?: string | undefined;
|
|
546
|
+
}, {
|
|
547
|
+
name: string;
|
|
548
|
+
type: "command";
|
|
549
|
+
id: string;
|
|
550
|
+
pricing: {
|
|
551
|
+
credits_per_call: number;
|
|
552
|
+
credits_per_minute?: number | undefined;
|
|
553
|
+
free_tier?: number | undefined;
|
|
554
|
+
};
|
|
555
|
+
command: string;
|
|
556
|
+
output_type: "text" | "json" | "file";
|
|
557
|
+
timeout_ms?: number | undefined;
|
|
558
|
+
allowed_commands?: string[] | undefined;
|
|
559
|
+
working_dir?: string | undefined;
|
|
560
|
+
}>]>;
|
|
561
|
+
/** TypeScript type for any skill config entry */
|
|
562
|
+
type SkillConfig = z.infer<typeof SkillConfigSchema>;
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Result returned by SkillExecutor.execute() for every invocation.
|
|
566
|
+
* Always includes timing data regardless of success or failure.
|
|
567
|
+
*/
|
|
568
|
+
interface ExecutionResult {
|
|
569
|
+
/** Whether the skill executed successfully. */
|
|
570
|
+
success: boolean;
|
|
571
|
+
/** The output produced by the skill on success. */
|
|
572
|
+
result?: unknown;
|
|
573
|
+
/** Error message if success is false. */
|
|
574
|
+
error?: string;
|
|
575
|
+
/** Wall-clock execution time in milliseconds. */
|
|
576
|
+
latency_ms: number;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Interface that all executor mode implementations must satisfy.
|
|
580
|
+
* Each mode handles one skill type: 'api' | 'pipeline' | 'openclaw' | 'command'.
|
|
581
|
+
*/
|
|
582
|
+
interface ExecutorMode {
|
|
583
|
+
/**
|
|
584
|
+
* Execute a skill with the given config and input parameters.
|
|
585
|
+
*
|
|
586
|
+
* @param config - The validated SkillConfig for this skill.
|
|
587
|
+
* @param params - The input parameters passed by the caller.
|
|
588
|
+
* @returns A partial ExecutionResult without latency_ms (added by SkillExecutor).
|
|
589
|
+
*/
|
|
590
|
+
execute(config: SkillConfig, params: Record<string, unknown>): Promise<Omit<ExecutionResult, 'latency_ms'>>;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Central dispatcher that routes skill execution requests to the appropriate
|
|
594
|
+
* executor mode based on the skill's `type` field.
|
|
595
|
+
*
|
|
596
|
+
* Usage:
|
|
597
|
+
* ```ts
|
|
598
|
+
* const executor = createSkillExecutor(configs, modes);
|
|
599
|
+
* const result = await executor.execute('tts-skill', { text: 'hello' });
|
|
600
|
+
* ```
|
|
601
|
+
*/
|
|
602
|
+
declare class SkillExecutor {
|
|
603
|
+
private readonly skillMap;
|
|
604
|
+
private readonly modeMap;
|
|
605
|
+
/**
|
|
606
|
+
* @param configs - Parsed SkillConfig array (from parseSkillsFile).
|
|
607
|
+
* @param modes - Map from skill type string to its executor implementation.
|
|
608
|
+
*/
|
|
609
|
+
constructor(configs: SkillConfig[], modes: Map<string, ExecutorMode>);
|
|
610
|
+
/**
|
|
611
|
+
* Execute a skill by ID with the given input parameters.
|
|
612
|
+
*
|
|
613
|
+
* Dispatch order:
|
|
614
|
+
* 1. Look up skill config by skillId.
|
|
615
|
+
* 2. Find executor mode by config.type.
|
|
616
|
+
* 3. Invoke mode.execute(), wrap with latency timing.
|
|
617
|
+
* 4. Catch any thrown errors and return as ExecutionResult with success:false.
|
|
618
|
+
*
|
|
619
|
+
* @param skillId - The ID of the skill to execute.
|
|
620
|
+
* @param params - Input parameters for the skill.
|
|
621
|
+
* @returns ExecutionResult including success, result/error, and latency_ms.
|
|
622
|
+
*/
|
|
623
|
+
execute(skillId: string, params: Record<string, unknown>): Promise<ExecutionResult>;
|
|
624
|
+
/**
|
|
625
|
+
* Returns the IDs of all registered skills.
|
|
626
|
+
*
|
|
627
|
+
* @returns Array of skill ID strings.
|
|
628
|
+
*/
|
|
629
|
+
listSkills(): string[];
|
|
630
|
+
/**
|
|
631
|
+
* Returns the SkillConfig for a given skill ID, or undefined if not found.
|
|
632
|
+
*
|
|
633
|
+
* @param skillId - The skill ID to look up.
|
|
634
|
+
* @returns The SkillConfig or undefined.
|
|
635
|
+
*/
|
|
636
|
+
getSkillConfig(skillId: string): SkillConfig | undefined;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* Options for creating a gateway server.
|
|
641
|
+
*/
|
|
642
|
+
interface GatewayOptions {
|
|
643
|
+
/** Port to listen on. Default 7700. */
|
|
644
|
+
port?: number;
|
|
645
|
+
/** Open registry database instance. */
|
|
646
|
+
registryDb: Database.Database;
|
|
647
|
+
/** Open credit database instance. */
|
|
648
|
+
creditDb: Database.Database;
|
|
649
|
+
/** Valid bearer tokens for auth. */
|
|
650
|
+
tokens: string[];
|
|
651
|
+
/** URL of the local capability handler. */
|
|
652
|
+
handlerUrl: string;
|
|
653
|
+
/** Request timeout in ms. Default 30000. */
|
|
654
|
+
timeoutMs?: number;
|
|
655
|
+
/** Disable logging (useful for tests). */
|
|
656
|
+
silent?: boolean;
|
|
657
|
+
/**
|
|
658
|
+
* Optional SkillExecutor instance.
|
|
659
|
+
* When provided, skill execution is dispatched through SkillExecutor.execute()
|
|
660
|
+
* instead of forwarding via fetch(handlerUrl).
|
|
661
|
+
* When absent, the original handlerUrl fetch path is used (backward compat).
|
|
662
|
+
*/
|
|
663
|
+
skillExecutor?: SkillExecutor;
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Creates a Fastify gateway server for agent-to-agent communication.
|
|
667
|
+
* Registers /health (unauthenticated) and /rpc (token-authenticated) endpoints.
|
|
668
|
+
* Returns a configured Fastify instance (call .ready() before using inject,
|
|
669
|
+
* or .listen() to start accepting connections).
|
|
670
|
+
*
|
|
671
|
+
* @param opts - Gateway configuration options.
|
|
672
|
+
* @returns Configured Fastify instance (not yet listening).
|
|
673
|
+
*/
|
|
674
|
+
declare function createGatewayServer(opts: GatewayOptions): FastifyInstance;
|
|
675
|
+
|
|
676
|
+
export { type CapabilityCard, CapabilityCardSchema, createGatewayServer, getBalance, getCard, insertCard, openCreditDb, openDatabase, searchCards };
|