@gopherhole/sdk 0.2.1 → 0.2.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/dist/index.d.mts CHANGED
@@ -304,6 +304,8 @@ interface GopherHoleOptions {
304
304
  maxReconnectAttempts?: number;
305
305
  /** Default request timeout in ms (default: 30000) */
306
306
  requestTimeout?: number;
307
+ /** Default message response timeout in ms (default: 30000) */
308
+ messageTimeout?: number;
307
309
  }
308
310
  /** Agent card configuration for registration */
309
311
  interface AgentCardConfig {
@@ -397,12 +399,17 @@ declare class GopherHole extends EventEmitter<EventMap> {
397
399
  private reconnectDelay;
398
400
  private maxReconnectAttempts;
399
401
  private requestTimeout;
402
+ private messageTimeout;
400
403
  private reconnectAttempts;
401
404
  private reconnectTimer;
402
405
  private pingInterval;
403
406
  private agentId;
404
407
  private agentCard;
405
408
  constructor(apiKeyOrOptions: string | GopherHoleOptions);
409
+ /**
410
+ * Get the configured message timeout
411
+ */
412
+ getMessageTimeout(): number;
406
413
  /**
407
414
  * Update agent card (sends to hub if connected)
408
415
  */
@@ -457,12 +464,28 @@ declare class GopherHole extends EventEmitter<EventMap> {
457
464
  * Cancel a task
458
465
  */
459
466
  cancelTask(taskId: string): Promise<Task>;
467
+ /**
468
+ * Respond to an incoming task via WebSocket (completes the task)
469
+ * Use this when you receive a 'message' event and want to send back a response
470
+ * that completes the original task.
471
+ */
472
+ respond(taskId: string, text: string, options?: {
473
+ status?: 'completed' | 'failed';
474
+ message?: string;
475
+ }): void;
476
+ /**
477
+ * Respond with a failure to an incoming task
478
+ */
479
+ respondError(taskId: string, errorMessage: string): void;
460
480
  /**
461
481
  * Reply to a message/task (sends back to the original caller)
482
+ * Note: This creates a NEW task via HTTP. For completing an existing task,
483
+ * use respond() instead.
462
484
  */
463
485
  reply(taskId: string, payload: MessagePayload, toAgentId?: string): Promise<Task>;
464
486
  /**
465
- * Reply with text
487
+ * Reply with text (creates new task)
488
+ * Note: For completing an existing task, use respond() instead.
466
489
  */
467
490
  replyText(taskId: string, text: string): Promise<Task>;
468
491
  /**
package/dist/index.d.ts CHANGED
@@ -304,6 +304,8 @@ interface GopherHoleOptions {
304
304
  maxReconnectAttempts?: number;
305
305
  /** Default request timeout in ms (default: 30000) */
306
306
  requestTimeout?: number;
307
+ /** Default message response timeout in ms (default: 30000) */
308
+ messageTimeout?: number;
307
309
  }
308
310
  /** Agent card configuration for registration */
309
311
  interface AgentCardConfig {
@@ -397,12 +399,17 @@ declare class GopherHole extends EventEmitter<EventMap> {
397
399
  private reconnectDelay;
398
400
  private maxReconnectAttempts;
399
401
  private requestTimeout;
402
+ private messageTimeout;
400
403
  private reconnectAttempts;
401
404
  private reconnectTimer;
402
405
  private pingInterval;
403
406
  private agentId;
404
407
  private agentCard;
405
408
  constructor(apiKeyOrOptions: string | GopherHoleOptions);
409
+ /**
410
+ * Get the configured message timeout
411
+ */
412
+ getMessageTimeout(): number;
406
413
  /**
407
414
  * Update agent card (sends to hub if connected)
408
415
  */
@@ -457,12 +464,28 @@ declare class GopherHole extends EventEmitter<EventMap> {
457
464
  * Cancel a task
458
465
  */
459
466
  cancelTask(taskId: string): Promise<Task>;
467
+ /**
468
+ * Respond to an incoming task via WebSocket (completes the task)
469
+ * Use this when you receive a 'message' event and want to send back a response
470
+ * that completes the original task.
471
+ */
472
+ respond(taskId: string, text: string, options?: {
473
+ status?: 'completed' | 'failed';
474
+ message?: string;
475
+ }): void;
476
+ /**
477
+ * Respond with a failure to an incoming task
478
+ */
479
+ respondError(taskId: string, errorMessage: string): void;
460
480
  /**
461
481
  * Reply to a message/task (sends back to the original caller)
482
+ * Note: This creates a NEW task via HTTP. For completing an existing task,
483
+ * use respond() instead.
462
484
  */
463
485
  reply(taskId: string, payload: MessagePayload, toAgentId?: string): Promise<Task>;
464
486
  /**
465
- * Reply with text
487
+ * Reply with text (creates new task)
488
+ * Note: For completing an existing task, use respond() instead.
466
489
  */
467
490
  replyText(taskId: string, text: string): Promise<Task>;
468
491
  /**
package/dist/index.js CHANGED
@@ -259,6 +259,13 @@ var GopherHole = class extends import_eventemitter3.EventEmitter {
259
259
  this.reconnectDelay = options.reconnectDelay ?? 1e3;
260
260
  this.maxReconnectAttempts = options.maxReconnectAttempts ?? 10;
261
261
  this.requestTimeout = options.requestTimeout ?? 3e4;
262
+ this.messageTimeout = options.messageTimeout ?? 3e4;
263
+ }
264
+ /**
265
+ * Get the configured message timeout
266
+ */
267
+ getMessageTimeout() {
268
+ return this.messageTimeout;
262
269
  }
263
270
  /**
264
271
  * Update agent card (sends to hub if connected)
@@ -407,8 +414,41 @@ var GopherHole = class extends import_eventemitter3.EventEmitter {
407
414
  const response = await this.rpc("tasks/cancel", { id: taskId });
408
415
  return response;
409
416
  }
417
+ /**
418
+ * Respond to an incoming task via WebSocket (completes the task)
419
+ * Use this when you receive a 'message' event and want to send back a response
420
+ * that completes the original task.
421
+ */
422
+ respond(taskId, text, options) {
423
+ if (!this.ws || this.ws.readyState !== 1) {
424
+ throw new Error("WebSocket not connected");
425
+ }
426
+ const response = {
427
+ type: "task_response",
428
+ taskId,
429
+ status: {
430
+ state: options?.status ?? "completed",
431
+ message: options?.message
432
+ },
433
+ artifact: {
434
+ artifactId: `response-${Date.now()}`,
435
+ mimeType: "text/plain",
436
+ parts: [{ kind: "text", text }]
437
+ },
438
+ lastChunk: true
439
+ };
440
+ this.ws.send(JSON.stringify(response));
441
+ }
442
+ /**
443
+ * Respond with a failure to an incoming task
444
+ */
445
+ respondError(taskId, errorMessage) {
446
+ this.respond(taskId, errorMessage, { status: "failed", message: errorMessage });
447
+ }
410
448
  /**
411
449
  * Reply to a message/task (sends back to the original caller)
450
+ * Note: This creates a NEW task via HTTP. For completing an existing task,
451
+ * use respond() instead.
412
452
  */
413
453
  async reply(taskId, payload, toAgentId) {
414
454
  if (!toAgentId) {
@@ -431,7 +471,8 @@ var GopherHole = class extends import_eventemitter3.EventEmitter {
431
471
  return response;
432
472
  }
433
473
  /**
434
- * Reply with text
474
+ * Reply with text (creates new task)
475
+ * Note: For completing an existing task, use respond() instead.
435
476
  */
436
477
  async replyText(taskId, text) {
437
478
  return this.reply(taskId, {
package/dist/index.mjs CHANGED
@@ -238,6 +238,13 @@ var GopherHole = class extends EventEmitter {
238
238
  this.reconnectDelay = options.reconnectDelay ?? 1e3;
239
239
  this.maxReconnectAttempts = options.maxReconnectAttempts ?? 10;
240
240
  this.requestTimeout = options.requestTimeout ?? 3e4;
241
+ this.messageTimeout = options.messageTimeout ?? 3e4;
242
+ }
243
+ /**
244
+ * Get the configured message timeout
245
+ */
246
+ getMessageTimeout() {
247
+ return this.messageTimeout;
241
248
  }
242
249
  /**
243
250
  * Update agent card (sends to hub if connected)
@@ -386,8 +393,41 @@ var GopherHole = class extends EventEmitter {
386
393
  const response = await this.rpc("tasks/cancel", { id: taskId });
387
394
  return response;
388
395
  }
396
+ /**
397
+ * Respond to an incoming task via WebSocket (completes the task)
398
+ * Use this when you receive a 'message' event and want to send back a response
399
+ * that completes the original task.
400
+ */
401
+ respond(taskId, text, options) {
402
+ if (!this.ws || this.ws.readyState !== 1) {
403
+ throw new Error("WebSocket not connected");
404
+ }
405
+ const response = {
406
+ type: "task_response",
407
+ taskId,
408
+ status: {
409
+ state: options?.status ?? "completed",
410
+ message: options?.message
411
+ },
412
+ artifact: {
413
+ artifactId: `response-${Date.now()}`,
414
+ mimeType: "text/plain",
415
+ parts: [{ kind: "text", text }]
416
+ },
417
+ lastChunk: true
418
+ };
419
+ this.ws.send(JSON.stringify(response));
420
+ }
421
+ /**
422
+ * Respond with a failure to an incoming task
423
+ */
424
+ respondError(taskId, errorMessage) {
425
+ this.respond(taskId, errorMessage, { status: "failed", message: errorMessage });
426
+ }
389
427
  /**
390
428
  * Reply to a message/task (sends back to the original caller)
429
+ * Note: This creates a NEW task via HTTP. For completing an existing task,
430
+ * use respond() instead.
391
431
  */
392
432
  async reply(taskId, payload, toAgentId) {
393
433
  if (!toAgentId) {
@@ -410,7 +450,8 @@ var GopherHole = class extends EventEmitter {
410
450
  return response;
411
451
  }
412
452
  /**
413
- * Reply with text
453
+ * Reply with text (creates new task)
454
+ * Note: For completing an existing task, use respond() instead.
414
455
  */
415
456
  async replyText(taskId, text) {
416
457
  return this.reply(taskId, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gopherhole/sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "GopherHole SDK - Connect AI agents via the A2A protocol",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/index.ts CHANGED
@@ -34,6 +34,8 @@ export interface GopherHoleOptions {
34
34
  maxReconnectAttempts?: number;
35
35
  /** Default request timeout in ms (default: 30000) */
36
36
  requestTimeout?: number;
37
+ /** Default message response timeout in ms (default: 30000) */
38
+ messageTimeout?: number;
37
39
  }
38
40
 
39
41
  /** Agent card configuration for registration */
@@ -178,6 +180,7 @@ export class GopherHole extends EventEmitter<EventMap> {
178
180
  private reconnectDelay: number;
179
181
  private maxReconnectAttempts: number;
180
182
  private requestTimeout: number;
183
+ private messageTimeout: number;
181
184
  private reconnectAttempts = 0;
182
185
  private reconnectTimer: ReturnType<typeof setTimeout> | null = null;
183
186
  private pingInterval: ReturnType<typeof setInterval> | null = null;
@@ -199,6 +202,14 @@ export class GopherHole extends EventEmitter<EventMap> {
199
202
  this.reconnectDelay = options.reconnectDelay ?? 1000;
200
203
  this.maxReconnectAttempts = options.maxReconnectAttempts ?? 10;
201
204
  this.requestTimeout = options.requestTimeout ?? 30000;
205
+ this.messageTimeout = options.messageTimeout ?? 30000;
206
+ }
207
+
208
+ /**
209
+ * Get the configured message timeout
210
+ */
211
+ getMessageTimeout(): number {
212
+ return this.messageTimeout;
202
213
  }
203
214
 
204
215
  /**
@@ -378,8 +389,45 @@ export class GopherHole extends EventEmitter<EventMap> {
378
389
  return response as Task;
379
390
  }
380
391
 
392
+ /**
393
+ * Respond to an incoming task via WebSocket (completes the task)
394
+ * Use this when you receive a 'message' event and want to send back a response
395
+ * that completes the original task.
396
+ */
397
+ respond(taskId: string, text: string, options?: { status?: 'completed' | 'failed'; message?: string }): void {
398
+ if (!this.ws || this.ws.readyState !== 1) {
399
+ throw new Error('WebSocket not connected');
400
+ }
401
+
402
+ const response = {
403
+ type: 'task_response',
404
+ taskId,
405
+ status: {
406
+ state: options?.status ?? 'completed',
407
+ message: options?.message,
408
+ },
409
+ artifact: {
410
+ artifactId: `response-${Date.now()}`,
411
+ mimeType: 'text/plain',
412
+ parts: [{ kind: 'text', text }],
413
+ },
414
+ lastChunk: true,
415
+ };
416
+
417
+ this.ws.send(JSON.stringify(response));
418
+ }
419
+
420
+ /**
421
+ * Respond with a failure to an incoming task
422
+ */
423
+ respondError(taskId: string, errorMessage: string): void {
424
+ this.respond(taskId, errorMessage, { status: 'failed', message: errorMessage });
425
+ }
426
+
381
427
  /**
382
428
  * Reply to a message/task (sends back to the original caller)
429
+ * Note: This creates a NEW task via HTTP. For completing an existing task,
430
+ * use respond() instead.
383
431
  */
384
432
  async reply(taskId: string, payload: MessagePayload, toAgentId?: string): Promise<Task> {
385
433
  // If toAgentId not provided, we need to figure out who to reply to
@@ -410,7 +458,8 @@ export class GopherHole extends EventEmitter<EventMap> {
410
458
  }
411
459
 
412
460
  /**
413
- * Reply with text
461
+ * Reply with text (creates new task)
462
+ * Note: For completing an existing task, use respond() instead.
414
463
  */
415
464
  async replyText(taskId: string, text: string): Promise<Task> {
416
465
  return this.reply(taskId, {