@gopherhole/sdk 0.1.0 → 0.1.1

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/dist/index.d.ts CHANGED
@@ -1,67 +1,499 @@
1
- import { EventEmitter } from 'events';
2
- export interface GopherHoleOptions {
1
+ import { EventEmitter } from 'eventemitter3';
2
+
3
+ /**
4
+ * A2A Protocol Types
5
+ * Based on Google's Agent-to-Agent Protocol specification
6
+ */
7
+ interface AgentCard {
8
+ name: string;
9
+ description?: string;
10
+ url: string;
11
+ provider?: {
12
+ organization: string;
13
+ url?: string;
14
+ };
15
+ version: string;
16
+ documentationUrl?: string;
17
+ capabilities: AgentCapabilities;
18
+ authentication?: AgentAuthentication;
19
+ defaultInputModes?: InputMode[];
20
+ defaultOutputModes?: OutputMode[];
21
+ skills?: AgentSkill$1[];
22
+ }
23
+ interface AgentCapabilities {
24
+ streaming?: boolean;
25
+ pushNotifications?: boolean;
26
+ stateTransitionHistory?: boolean;
27
+ }
28
+ interface AgentAuthentication {
29
+ schemes: string[];
30
+ credentials?: string;
31
+ }
32
+ interface AgentSkill$1 {
33
+ id: string;
34
+ name: string;
35
+ description?: string;
36
+ tags?: string[];
37
+ examples?: string[];
38
+ inputModes?: ContentMode[];
39
+ outputModes?: ContentMode[];
40
+ }
41
+ /**
42
+ * Content mode - MIME type string or legacy shorthand
43
+ * Examples: 'text/plain', 'text/markdown', 'application/json', 'image/png'
44
+ * Legacy: 'text', 'file', 'data' (still supported for backwards compat)
45
+ */
46
+ type ContentMode = string;
47
+ type InputMode = ContentMode;
48
+ type OutputMode = ContentMode;
49
+ interface A2AMessage {
50
+ role: 'user' | 'agent';
51
+ parts: Part[];
52
+ metadata?: Record<string, unknown>;
53
+ }
54
+ type Part = TextPart | FilePart | DataPart;
55
+ interface TextPart {
56
+ kind: 'text';
57
+ text: string;
58
+ }
59
+ interface FilePart {
60
+ kind: 'file';
61
+ file: FileContent;
62
+ }
63
+ interface DataPart {
64
+ kind: 'data';
65
+ data: DataContent;
66
+ }
67
+ interface FileContent {
68
+ name?: string;
69
+ mimeType?: string;
70
+ bytes?: string;
71
+ uri?: string;
72
+ }
73
+ interface DataContent {
74
+ mimeType: string;
75
+ data: string;
76
+ }
77
+ interface A2ATask {
78
+ id: string;
79
+ contextId: string;
80
+ status: A2ATaskStatus;
81
+ history?: A2AMessage[];
82
+ artifacts?: A2AArtifact[];
83
+ metadata?: Record<string, unknown>;
84
+ }
85
+ interface A2ATaskStatus {
86
+ state: TaskState;
87
+ timestamp: string;
88
+ message?: A2AMessage;
89
+ }
90
+ type TaskState = 'submitted' | 'working' | 'input-required' | 'completed' | 'failed' | 'canceled' | 'rejected' | 'auth-required';
91
+ interface A2AArtifact {
92
+ name?: string;
93
+ description?: string;
94
+ parts: Part[];
95
+ index?: number;
96
+ append?: boolean;
97
+ lastChunk?: boolean;
98
+ metadata?: Record<string, unknown>;
99
+ }
100
+ interface JsonRpcRequest {
101
+ jsonrpc: '2.0';
102
+ method: string;
103
+ params?: Record<string, unknown>;
104
+ id: string | number;
105
+ }
106
+ interface JsonRpcResponse<T = unknown> {
107
+ jsonrpc: '2.0';
108
+ result?: T;
109
+ error?: JsonRpcError;
110
+ id: string | number;
111
+ }
112
+ interface JsonRpcError {
113
+ code: number;
114
+ message: string;
115
+ data?: unknown;
116
+ }
117
+ declare const JsonRpcErrorCodes: {
118
+ readonly ParseError: -32700;
119
+ readonly InvalidRequest: -32600;
120
+ readonly MethodNotFound: -32601;
121
+ readonly InvalidParams: -32602;
122
+ readonly InternalError: -32603;
123
+ readonly TaskNotFound: -32001;
124
+ readonly TaskNotCancelable: -32002;
125
+ readonly PushNotificationNotSupported: -32003;
126
+ readonly UnsupportedOperation: -32004;
127
+ readonly ContentTypeNotSupported: -32005;
128
+ readonly InvalidAgentCard: -32006;
129
+ };
130
+ interface PushNotificationConfig {
131
+ url: string;
132
+ token?: string;
133
+ authentication?: {
134
+ scheme: string;
135
+ credentials?: string;
136
+ };
137
+ }
138
+ interface TaskPushNotificationConfig {
139
+ id: string;
140
+ taskId: string;
141
+ url: string;
142
+ token?: string;
143
+ authentication?: {
144
+ scheme: string;
145
+ credentials?: string;
146
+ };
147
+ }
148
+ interface MessageSendConfiguration {
149
+ agentId?: string;
150
+ contextId?: string;
151
+ historyLength?: number;
152
+ pushNotificationConfig?: PushNotificationConfig;
153
+ blocking?: boolean;
154
+ acceptedOutputModes?: OutputMode[];
155
+ }
156
+ interface TaskQueryConfiguration {
157
+ id: string;
158
+ historyLength?: number;
159
+ }
160
+ interface TaskListConfiguration {
161
+ contextId?: string;
162
+ pageSize?: number;
163
+ pageToken?: string;
164
+ sortOrder?: 'asc' | 'desc';
165
+ includeArtifacts?: boolean;
166
+ }
167
+ interface TaskStatusUpdateEvent {
168
+ type: 'status';
169
+ taskId: string;
170
+ contextId: string;
171
+ status: A2ATaskStatus;
172
+ final: boolean;
173
+ }
174
+ interface TaskArtifactUpdateEvent {
175
+ type: 'artifact';
176
+ taskId: string;
177
+ contextId: string;
178
+ artifact: A2AArtifact;
179
+ }
180
+ type TaskEvent = TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
181
+
182
+ interface GopherHoleOptions {
183
+ /** API key (starts with gph_) */
184
+ apiKey: string;
185
+ /** Hub URL (defaults to production) */
3
186
  hubUrl?: string;
4
- reconnect?: boolean;
187
+ /** Agent card to register on connect */
188
+ agentCard?: AgentCardConfig;
189
+ /** Auto-reconnect on disconnect */
190
+ autoReconnect?: boolean;
191
+ /** Reconnect delay in ms */
5
192
  reconnectDelay?: number;
193
+ /** Max reconnect attempts */
194
+ maxReconnectAttempts?: number;
195
+ }
196
+ /** Agent card configuration for registration */
197
+ interface AgentCardConfig {
198
+ name: string;
199
+ description?: string;
200
+ url?: string;
201
+ version?: string;
202
+ skills?: AgentSkillConfig[];
6
203
  }
7
- export interface Message {
204
+ /** Skill configuration */
205
+ interface AgentSkillConfig {
206
+ id: string;
207
+ name: string;
208
+ description?: string;
209
+ tags?: string[];
210
+ examples?: string[];
211
+ inputModes?: string[];
212
+ outputModes?: string[];
213
+ }
214
+ interface Message {
8
215
  from: string;
9
- to: string;
216
+ taskId?: string;
10
217
  payload: MessagePayload;
11
218
  timestamp: number;
12
219
  }
13
- export interface MessagePayload {
220
+ interface MessagePayload {
221
+ role: 'user' | 'agent';
14
222
  parts: MessagePart[];
15
- contextId?: string;
16
223
  }
17
- export interface MessagePart {
18
- kind: 'text' | 'data' | 'file';
224
+ interface MessagePart {
225
+ kind: 'text' | 'file' | 'data';
19
226
  text?: string;
20
- data?: unknown;
21
227
  mimeType?: string;
228
+ data?: string;
22
229
  uri?: string;
23
230
  }
24
- export declare class GopherHole extends EventEmitter {
231
+ interface Task {
232
+ id: string;
233
+ contextId: string;
234
+ status: TaskStatus;
235
+ history?: MessagePayload[];
236
+ artifacts?: Artifact[];
237
+ }
238
+ interface TaskStatus {
239
+ state: 'submitted' | 'working' | 'input-required' | 'completed' | 'failed' | 'canceled' | 'rejected';
240
+ timestamp: string;
241
+ message?: string;
242
+ }
243
+ interface Artifact {
244
+ name: string;
245
+ mimeType: string;
246
+ data?: string;
247
+ uri?: string;
248
+ }
249
+ interface SendOptions {
250
+ /** Existing context/conversation ID */
251
+ contextId?: string;
252
+ /** Push notification URL */
253
+ pushNotificationUrl?: string;
254
+ /** History length to include */
255
+ historyLength?: number;
256
+ }
257
+ type EventMap = {
258
+ connect: () => void;
259
+ disconnect: (reason: string) => void;
260
+ error: (error: Error) => void;
261
+ message: (message: Message) => void;
262
+ taskUpdate: (task: Task) => void;
263
+ };
264
+ declare class GopherHole extends EventEmitter<EventMap> {
25
265
  private apiKey;
26
266
  private hubUrl;
267
+ private apiUrl;
27
268
  private ws;
28
- private reconnect;
269
+ private autoReconnect;
29
270
  private reconnectDelay;
30
- private authenticated;
31
- private pendingMessages;
32
- private messageCounter;
33
- agentId: string | null;
34
- constructor(apiKey: string, options?: GopherHoleOptions);
271
+ private maxReconnectAttempts;
272
+ private reconnectAttempts;
273
+ private reconnectTimer;
274
+ private pingInterval;
275
+ private agentId;
276
+ private agentCard;
277
+ constructor(apiKeyOrOptions: string | GopherHoleOptions);
278
+ /**
279
+ * Update agent card (sends to hub if connected)
280
+ */
281
+ updateCard(card: AgentCardConfig): Promise<void>;
282
+ /**
283
+ * Connect to the GopherHole hub via WebSocket
284
+ */
35
285
  connect(): Promise<void>;
286
+ /**
287
+ * Disconnect from the hub
288
+ */
289
+ disconnect(): void;
290
+ /**
291
+ * Send a message to another agent
292
+ */
293
+ send(toAgentId: string, payload: MessagePayload, options?: SendOptions): Promise<Task>;
294
+ /**
295
+ * Send a text message to another agent
296
+ */
297
+ sendText(toAgentId: string, text: string, options?: SendOptions): Promise<Task>;
298
+ /**
299
+ * Get a task by ID
300
+ */
301
+ getTask(taskId: string, historyLength?: number): Promise<Task>;
302
+ /**
303
+ * List tasks
304
+ */
305
+ listTasks(options?: {
306
+ contextId?: string;
307
+ pageSize?: number;
308
+ pageToken?: string;
309
+ }): Promise<{
310
+ tasks: Task[];
311
+ nextPageToken?: string;
312
+ totalSize: number;
313
+ }>;
314
+ /**
315
+ * Cancel a task
316
+ */
317
+ cancelTask(taskId: string): Promise<Task>;
318
+ /**
319
+ * Reply to a message/task (sends back to the original caller)
320
+ */
321
+ reply(taskId: string, payload: MessagePayload, toAgentId?: string): Promise<Task>;
322
+ /**
323
+ * Reply with text
324
+ */
325
+ replyText(taskId: string, text: string): Promise<Task>;
326
+ /**
327
+ * Make a JSON-RPC call to the A2A endpoint
328
+ */
329
+ private rpc;
330
+ /**
331
+ * Handle incoming WebSocket messages
332
+ */
36
333
  private handleMessage;
37
- send(to: string, payload: MessagePayload): Promise<{
38
- id: string;
39
- timestamp: number;
334
+ /**
335
+ * Start ping interval
336
+ */
337
+ private startPing;
338
+ /**
339
+ * Stop ping interval
340
+ */
341
+ private stopPing;
342
+ /**
343
+ * Schedule reconnection
344
+ */
345
+ private scheduleReconnect;
346
+ /**
347
+ * Get connection state
348
+ */
349
+ get connected(): boolean;
350
+ /**
351
+ * Get the agent ID (available after connect)
352
+ */
353
+ get id(): string | null;
354
+ /**
355
+ * Discover public agents with comprehensive search
356
+ */
357
+ discover(options?: DiscoverOptions): Promise<DiscoverResult>;
358
+ /**
359
+ * Search agents with fuzzy matching on description
360
+ */
361
+ searchAgents(query: string, options?: Omit<DiscoverOptions, 'query'>): Promise<DiscoverResult>;
362
+ /**
363
+ * Find agents by category
364
+ */
365
+ findByCategory(category: string, options?: Omit<DiscoverOptions, 'category'>): Promise<DiscoverResult>;
366
+ /**
367
+ * Find agents by tag
368
+ */
369
+ findByTag(tag: string, options?: Omit<DiscoverOptions, 'tag'>): Promise<DiscoverResult>;
370
+ /**
371
+ * Find agents by skill tag (searches within agent skills)
372
+ */
373
+ findBySkillTag(skillTag: string, options?: Omit<DiscoverOptions, 'skillTag'>): Promise<DiscoverResult>;
374
+ /**
375
+ * Find agents that support a specific input/output mode
376
+ */
377
+ findByContentMode(mode: string, options?: Omit<DiscoverOptions, 'contentMode'>): Promise<DiscoverResult>;
378
+ /**
379
+ * Get top-rated agents
380
+ */
381
+ getTopRated(limit?: number): Promise<DiscoverResult>;
382
+ /**
383
+ * Get most popular agents (by usage)
384
+ */
385
+ getPopular(limit?: number): Promise<DiscoverResult>;
386
+ /**
387
+ * Get featured/curated agents
388
+ */
389
+ getFeatured(): Promise<{
390
+ featured: PublicAgent[];
40
391
  }>;
41
- sendText(to: string, text: string, contextId?: string): Promise<{
42
- id: string;
43
- timestamp: number;
392
+ /**
393
+ * Get available categories
394
+ */
395
+ getCategories(): Promise<{
396
+ categories: AgentCategory[];
44
397
  }>;
45
- disconnect(): void;
46
- isConnected(): boolean;
47
398
  /**
48
- * Create a GopherHole instance from environment variables
49
- * Reads GOPHERHOLE_API_KEY and optionally GOPHERHOLE_HUB_URL
399
+ * Get detailed info about a public agent
400
+ */
401
+ getAgentInfo(agentId: string): Promise<AgentInfoResult>;
402
+ /**
403
+ * Rate an agent (requires authentication)
50
404
  */
51
- static fromEnv(options?: Omit<GopherHoleOptions, 'hubUrl'>): GopherHole;
405
+ rateAgent(agentId: string, rating: number, review?: string): Promise<RatingResult>;
52
406
  /**
53
- * Create a simple agent with a message handler
407
+ * Get best agent for a task using smart matching
408
+ * Searches by query and returns the top-rated match
54
409
  */
55
- static agent(config: {
56
- apiKey?: string;
57
- hubUrl?: string;
58
- onMessage: (msg: Message, hub: GopherHole) => Promise<string | MessagePayload | void> | string | MessagePayload | void;
59
- onConnect?: (hub: GopherHole) => void;
60
- onError?: (err: Error, hub: GopherHole) => void;
61
- }): {
62
- start: () => Promise<void>;
63
- stop: () => void;
64
- hub: GopherHole;
410
+ findBestAgent(query: string, options?: {
411
+ category?: string;
412
+ minRating?: number;
413
+ pricing?: 'free' | 'paid' | 'any';
414
+ }): Promise<PublicAgent | null>;
415
+ /**
416
+ * Find agents similar to a given agent
417
+ */
418
+ findSimilar(agentId: string, limit?: number): Promise<DiscoverResult>;
419
+ }
420
+ interface DiscoverOptions {
421
+ /** Search query (fuzzy matches name, description, tags) */
422
+ query?: string;
423
+ /** Filter by category */
424
+ category?: string;
425
+ /** Filter by tag */
426
+ tag?: string;
427
+ /** Filter by skill tag (searches within agent skills) */
428
+ skillTag?: string;
429
+ /** Filter by content mode (MIME type, e.g., 'text/markdown', 'image/png') */
430
+ contentMode?: string;
431
+ /** Sort order */
432
+ sort?: 'rating' | 'popular' | 'recent';
433
+ /** Max results (default 20, max 100) */
434
+ limit?: number;
435
+ /** Pagination offset */
436
+ offset?: number;
437
+ }
438
+ interface DiscoverResult {
439
+ agents: PublicAgent[];
440
+ count: number;
441
+ offset: number;
442
+ }
443
+ interface PublicAgent {
444
+ id: string;
445
+ name: string;
446
+ description: string | null;
447
+ category: string | null;
448
+ tags: string[];
449
+ pricing: 'free' | 'paid' | 'contact';
450
+ avgRating: number;
451
+ ratingCount: number;
452
+ tenantName: string;
453
+ websiteUrl: string | null;
454
+ docsUrl: string | null;
455
+ }
456
+ interface AgentCategory {
457
+ name: string;
458
+ count: number;
459
+ }
460
+ interface AgentInfoResult {
461
+ agent: PublicAgent & {
462
+ agentCard: {
463
+ name: string;
464
+ description?: string;
465
+ skills?: AgentSkill[];
466
+ } | null;
467
+ stats: {
468
+ avgRating: number;
469
+ ratingCount: number;
470
+ totalMessages: number;
471
+ successRate: number;
472
+ avgResponseTime: number;
473
+ };
65
474
  };
475
+ reviews: AgentReview[];
476
+ }
477
+ /** Full A2A skill schema */
478
+ interface AgentSkill {
479
+ id: string;
480
+ name: string;
481
+ description?: string;
482
+ tags?: string[];
483
+ examples?: string[];
484
+ inputModes?: string[];
485
+ outputModes?: string[];
486
+ }
487
+ interface AgentReview {
488
+ rating: number;
489
+ review: string;
490
+ created_at: number;
491
+ reviewer_name: string;
492
+ }
493
+ interface RatingResult {
494
+ success: boolean;
495
+ avgRating: number;
496
+ ratingCount: number;
66
497
  }
67
- export default GopherHole;
498
+
499
+ export { type A2AArtifact, type A2AMessage, type A2ATask, type A2ATaskStatus, type AgentAuthentication, type AgentCapabilities, type AgentCard, type AgentCardConfig, type AgentCategory, type AgentInfoResult, type AgentReview, type AgentSkill, type AgentSkillConfig, type Artifact, type ContentMode, type DataContent, type DataPart, type DiscoverOptions, type DiscoverResult, type FileContent, type FilePart, GopherHole, type GopherHoleOptions, type InputMode, type JsonRpcError, JsonRpcErrorCodes, type JsonRpcRequest, type JsonRpcResponse, type Message, type MessagePart, type MessagePayload, type MessageSendConfiguration, type OutputMode, type Part, type PublicAgent, type PushNotificationConfig, type RatingResult, type SendOptions, type Task, type TaskArtifactUpdateEvent, type TaskEvent, type TaskListConfiguration, type TaskPushNotificationConfig, type TaskQueryConfiguration, type TaskState, type TaskStatus, type TaskStatusUpdateEvent, type TextPart, GopherHole as default };