@adcp/client 2.7.1 → 3.0.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.
Files changed (116) hide show
  1. package/bin/adcp-async-handler.js +10 -8
  2. package/bin/adcp-config.js +13 -6
  3. package/bin/adcp.js +113 -40
  4. package/dist/lib/advanced.d.ts +41 -0
  5. package/dist/lib/advanced.d.ts.map +1 -0
  6. package/dist/lib/advanced.js +49 -0
  7. package/dist/lib/advanced.js.map +1 -0
  8. package/dist/lib/auth/index.d.ts +4 -0
  9. package/dist/lib/auth/index.d.ts.map +1 -1
  10. package/dist/lib/auth/index.js +13 -14
  11. package/dist/lib/auth/index.js.map +1 -1
  12. package/dist/lib/core/ADCPMultiAgentClient.d.ts +54 -7
  13. package/dist/lib/core/ADCPMultiAgentClient.d.ts.map +1 -1
  14. package/dist/lib/core/ADCPMultiAgentClient.js +84 -10
  15. package/dist/lib/core/ADCPMultiAgentClient.js.map +1 -1
  16. package/dist/lib/core/AgentClient.d.ts +11 -2
  17. package/dist/lib/core/AgentClient.d.ts.map +1 -1
  18. package/dist/lib/core/AgentClient.js +57 -13
  19. package/dist/lib/core/AgentClient.js.map +1 -1
  20. package/dist/lib/core/AsyncHandler.d.ts +2 -1
  21. package/dist/lib/core/AsyncHandler.d.ts.map +1 -1
  22. package/dist/lib/core/AsyncHandler.js +3 -3
  23. package/dist/lib/core/AsyncHandler.js.map +1 -1
  24. package/dist/lib/core/ConfigurationManager.d.ts.map +1 -1
  25. package/dist/lib/core/ConfigurationManager.js +8 -17
  26. package/dist/lib/core/ConfigurationManager.js.map +1 -1
  27. package/dist/lib/core/ConversationTypes.d.ts.map +1 -1
  28. package/dist/lib/core/CreativeAgentClient.d.ts +5 -5
  29. package/dist/lib/core/CreativeAgentClient.d.ts.map +1 -1
  30. package/dist/lib/core/CreativeAgentClient.js +6 -6
  31. package/dist/lib/core/CreativeAgentClient.js.map +1 -1
  32. package/dist/lib/core/ProtocolResponseParser.d.ts +1 -1
  33. package/dist/lib/core/ProtocolResponseParser.d.ts.map +1 -1
  34. package/dist/lib/core/ProtocolResponseParser.js +4 -4
  35. package/dist/lib/core/ProtocolResponseParser.js.map +1 -1
  36. package/dist/lib/core/ResponseValidator.d.ts.map +1 -1
  37. package/dist/lib/core/ResponseValidator.js +1 -1
  38. package/dist/lib/core/ResponseValidator.js.map +1 -1
  39. package/dist/lib/core/{ADCPClient.d.ts → SingleAgentClient.d.ts} +22 -13
  40. package/dist/lib/core/SingleAgentClient.d.ts.map +1 -0
  41. package/dist/lib/core/{ADCPClient.js → SingleAgentClient.js} +125 -105
  42. package/dist/lib/core/SingleAgentClient.js.map +1 -0
  43. package/dist/lib/core/TaskEventTypes.js +1 -1
  44. package/dist/lib/core/TaskExecutor.d.ts.map +1 -1
  45. package/dist/lib/core/TaskExecutor.js +76 -57
  46. package/dist/lib/core/TaskExecutor.js.map +1 -1
  47. package/dist/lib/discovery/property-crawler.d.ts.map +1 -1
  48. package/dist/lib/discovery/property-crawler.js +24 -21
  49. package/dist/lib/discovery/property-crawler.js.map +1 -1
  50. package/dist/lib/discovery/property-index.d.ts.map +1 -1
  51. package/dist/lib/discovery/property-index.js +5 -5
  52. package/dist/lib/discovery/property-index.js.map +1 -1
  53. package/dist/lib/discovery/types.d.ts.map +1 -1
  54. package/dist/lib/errors/index.d.ts.map +1 -1
  55. package/dist/lib/errors/index.js +3 -3
  56. package/dist/lib/errors/index.js.map +1 -1
  57. package/dist/lib/handlers/types.d.ts.map +1 -1
  58. package/dist/lib/handlers/types.js.map +1 -1
  59. package/dist/lib/index.d.ts +18 -42
  60. package/dist/lib/index.d.ts.map +1 -1
  61. package/dist/lib/index.js +14 -50
  62. package/dist/lib/index.js.map +1 -1
  63. package/dist/lib/protocols/a2a.js +20 -20
  64. package/dist/lib/protocols/a2a.js.map +1 -1
  65. package/dist/lib/protocols/index.d.ts.map +1 -1
  66. package/dist/lib/protocols/index.js +5 -5
  67. package/dist/lib/protocols/index.js.map +1 -1
  68. package/dist/lib/protocols/mcp.d.ts.map +1 -1
  69. package/dist/lib/protocols/mcp.js +30 -69
  70. package/dist/lib/protocols/mcp.js.map +1 -1
  71. package/dist/lib/storage/MemoryStorage.d.ts.map +1 -1
  72. package/dist/lib/storage/MemoryStorage.js +4 -4
  73. package/dist/lib/storage/MemoryStorage.js.map +1 -1
  74. package/dist/lib/storage/interfaces.d.ts.map +1 -1
  75. package/dist/lib/testing/index.d.ts +2 -0
  76. package/dist/lib/testing/index.d.ts.map +1 -0
  77. package/dist/lib/testing/index.js +22 -0
  78. package/dist/lib/testing/index.js.map +1 -0
  79. package/dist/lib/testing/test-helpers.d.ts +217 -0
  80. package/dist/lib/testing/test-helpers.d.ts.map +1 -0
  81. package/dist/lib/testing/test-helpers.js +258 -0
  82. package/dist/lib/testing/test-helpers.js.map +1 -0
  83. package/dist/lib/types/adcp.d.ts.map +1 -1
  84. package/dist/lib/types/core.generated.d.ts +146 -58
  85. package/dist/lib/types/core.generated.d.ts.map +1 -1
  86. package/dist/lib/types/core.generated.js +1 -1
  87. package/dist/lib/types/index.d.ts +1 -1
  88. package/dist/lib/types/index.d.ts.map +1 -1
  89. package/dist/lib/types/schemas.generated.d.ts +2608 -1536
  90. package/dist/lib/types/schemas.generated.d.ts.map +1 -1
  91. package/dist/lib/types/schemas.generated.js +361 -259
  92. package/dist/lib/types/schemas.generated.js.map +1 -1
  93. package/dist/lib/types/tools.generated.d.ts +688 -359
  94. package/dist/lib/types/tools.generated.d.ts.map +1 -1
  95. package/dist/lib/types/tools.generated.js +1 -1
  96. package/dist/lib/types/tools.generated.js.map +1 -1
  97. package/dist/lib/utils/index.d.ts +1 -0
  98. package/dist/lib/utils/index.d.ts.map +1 -1
  99. package/dist/lib/utils/index.js +15 -10
  100. package/dist/lib/utils/index.js.map +1 -1
  101. package/dist/lib/utils/logger.js +6 -6
  102. package/dist/lib/utils/preview-utils.d.ts +87 -0
  103. package/dist/lib/utils/preview-utils.d.ts.map +1 -0
  104. package/dist/lib/utils/preview-utils.js +322 -0
  105. package/dist/lib/utils/preview-utils.js.map +1 -0
  106. package/dist/lib/utils/protocol-detection.d.ts.map +1 -1
  107. package/dist/lib/utils/protocol-detection.js +4 -4
  108. package/dist/lib/utils/protocol-detection.js.map +1 -1
  109. package/dist/lib/validation/index.d.ts.map +1 -1
  110. package/dist/lib/validation/index.js +5 -5
  111. package/dist/lib/validation/index.js.map +1 -1
  112. package/dist/lib/version.d.ts +3 -3
  113. package/dist/lib/version.js +3 -3
  114. package/package.json +18 -5
  115. package/dist/lib/core/ADCPClient.d.ts.map +0 -1
  116. package/dist/lib/core/ADCPClient.js.map +0 -1
@@ -30,9 +30,9 @@ class AsyncWebhookHandler {
30
30
  * Check if ngrok is installed
31
31
  */
32
32
  static isNgrokAvailable() {
33
- return new Promise((resolve) => {
33
+ return new Promise(resolve => {
34
34
  const check = spawn('which', ['ngrok']);
35
- check.on('close', (code) => resolve(code === 0));
35
+ check.on('close', code => resolve(code === 0));
36
36
  });
37
37
  }
38
38
 
@@ -61,7 +61,9 @@ class AsyncWebhookHandler {
61
61
  if (ngrokAvailable) {
62
62
  await this.startNgrok();
63
63
  } else {
64
- throw new Error('ngrok is not installed. Install it with: brew install ngrok (Mac) or download from https://ngrok.com');
64
+ throw new Error(
65
+ 'ngrok is not installed. Install it with: brew install ngrok (Mac) or download from https://ngrok.com'
66
+ );
65
67
  }
66
68
  } else {
67
69
  // Use local URL (for local agents)
@@ -150,7 +152,7 @@ class AsyncWebhookHandler {
150
152
  let ngrokStarted = false;
151
153
  let buffer = '';
152
154
 
153
- this.ngrokProcess.stdout.on('data', (data) => {
155
+ this.ngrokProcess.stdout.on('data', data => {
154
156
  buffer += data.toString();
155
157
  const lines = buffer.split('\n');
156
158
  buffer = lines.pop() || ''; // Keep incomplete line in buffer
@@ -190,17 +192,17 @@ class AsyncWebhookHandler {
190
192
  }
191
193
  });
192
194
 
193
- this.ngrokProcess.stderr.on('data', (data) => {
195
+ this.ngrokProcess.stderr.on('data', data => {
194
196
  if (this.debug) {
195
197
  console.error('ngrok stderr:', data.toString());
196
198
  }
197
199
  });
198
200
 
199
- this.ngrokProcess.on('error', (error) => {
201
+ this.ngrokProcess.on('error', error => {
200
202
  reject(new Error(`Failed to start ngrok: ${error.message}`));
201
203
  });
202
204
 
203
- this.ngrokProcess.on('close', (code) => {
205
+ this.ngrokProcess.on('close', code => {
204
206
  if (!ngrokStarted && code !== 0) {
205
207
  reject(new Error(`ngrok exited with code ${code}`));
206
208
  }
@@ -244,7 +246,7 @@ class AsyncWebhookHandler {
244
246
 
245
247
  // Close HTTP server
246
248
  if (this.server) {
247
- await new Promise((resolve) => {
249
+ await new Promise(resolve => {
248
250
  this.server.close(() => resolve());
249
251
  });
250
252
  }
@@ -126,10 +126,10 @@ function isAlias(str) {
126
126
  async function promptSecure(prompt, hidden = true) {
127
127
  const readline = require('readline');
128
128
 
129
- return new Promise((resolve) => {
129
+ return new Promise(resolve => {
130
130
  const rl = readline.createInterface({
131
131
  input: process.stdin,
132
- output: process.stdout
132
+ output: process.stdout,
133
133
  });
134
134
 
135
135
  if (hidden) {
@@ -146,7 +146,7 @@ async function promptSecure(prompt, hidden = true) {
146
146
  };
147
147
  }
148
148
 
149
- rl.question(prompt, (answer) => {
149
+ rl.question(prompt, answer => {
150
150
  rl.close();
151
151
  if (hidden) {
152
152
  console.log(''); // New line after hidden input
@@ -165,7 +165,14 @@ async function promptSecure(prompt, hidden = true) {
165
165
  * @param {boolean} nonInteractive Skip prompts if all required args provided
166
166
  * @param {boolean} noAuth Explicitly skip auth (--no-auth flag)
167
167
  */
168
- async function interactiveSetup(alias, url = null, protocol = null, authToken = null, nonInteractive = false, noAuth = false) {
168
+ async function interactiveSetup(
169
+ alias,
170
+ url = null,
171
+ protocol = null,
172
+ authToken = null,
173
+ nonInteractive = false,
174
+ noAuth = false
175
+ ) {
169
176
  // Non-interactive mode: save immediately without prompts
170
177
  if (nonInteractive && url) {
171
178
  const agentConfig = { url };
@@ -201,7 +208,7 @@ async function interactiveSetup(alias, url = null, protocol = null, authToken =
201
208
 
202
209
  // Build config
203
210
  const agentConfig = {
204
- url: url
211
+ url: url,
205
212
  };
206
213
 
207
214
  if (protocol) {
@@ -229,5 +236,5 @@ module.exports = {
229
236
  removeAgent,
230
237
  isAlias,
231
238
  promptSecure,
232
- interactiveSetup
239
+ interactiveSetup,
233
240
  };
package/bin/adcp.js CHANGED
@@ -14,17 +14,10 @@
14
14
  * adcp mcp https://agent.example.com/mcp create_media_buy @payload.json --auth $AGENT_TOKEN
15
15
  */
16
16
 
17
- const { ADCPClient, detectProtocol } = require('../dist/lib/index.js');
17
+ const { AdCPClient, detectProtocol } = require('../dist/lib/index.js');
18
18
  const { readFileSync } = require('fs');
19
19
  const { AsyncWebhookHandler } = require('./adcp-async-handler.js');
20
- const {
21
- getAgent,
22
- listAgents,
23
- isAlias,
24
- interactiveSetup,
25
- removeAgent,
26
- getConfigPath
27
- } = require('./adcp-config.js');
20
+ const { getAgent, listAgents, isAlias, interactiveSetup, removeAgent, getConfigPath } = require('./adcp-config.js');
28
21
 
29
22
  /**
30
23
  * Extract human-readable protocol message from conversation
@@ -72,7 +65,7 @@ function extractProtocolMessage(conversation, protocol) {
72
65
  * Display agent info - just calls library method
73
66
  */
74
67
  async function displayAgentInfo(agentConfig, jsonOutput) {
75
- const client = new ADCPClient(agentConfig);
68
+ const client = new AdCPClient(agentConfig);
76
69
  const info = await client.getAgentInfo();
77
70
 
78
71
  if (jsonOutput) {
@@ -109,7 +102,7 @@ function printUsage() {
109
102
  AdCP CLI Tool - Direct Agent Communication
110
103
 
111
104
  USAGE:
112
- adcp <agent-alias|url> [tool-name] [payload] [options]
105
+ npx @adcp/client <agent-alias|url> [tool-name] [payload] [options]
113
106
 
114
107
  ARGUMENTS:
115
108
  agent-alias|url Saved agent alias (e.g., 'test') or full URL to agent endpoint
@@ -129,6 +122,13 @@ OPTIONS:
129
122
  --json Output raw JSON response (default: pretty print)
130
123
  --debug Show debug information
131
124
 
125
+ BUILT-IN TEST AGENTS:
126
+ test AdCP public test agent (MCP, with auth)
127
+ test-a2a AdCP public test agent (A2A, with auth)
128
+ test-no-auth AdCP public test agent (MCP, no auth - demonstrates errors)
129
+ test-a2a-no-auth AdCP public test agent (A2A, no auth - demonstrates errors)
130
+ creative Official AdCP creative agent (MCP only)
131
+
132
132
  AGENT MANAGEMENT:
133
133
  --save-auth <alias> [url] [protocol] [--auth token | --no-auth]
134
134
  Save agent configuration with an alias name
@@ -138,6 +138,17 @@ AGENT MANAGEMENT:
138
138
  --show-config Show config file location
139
139
 
140
140
  EXAMPLES:
141
+ # Use built-in test agent (zero config!)
142
+ npx @adcp/client test
143
+ npx @adcp/client test get_products '{"brief":"coffee brands"}'
144
+ npx @adcp/client creative list_creative_formats
145
+
146
+ # Use built-in test agent with A2A protocol
147
+ npx @adcp/client test-a2a get_products '{"brief":"travel packages"}'
148
+
149
+ # Compare authenticated vs unauthenticated (demonstrates auth errors)
150
+ npx @adcp/client test-no-auth get_products '{"brief":"test"}'
151
+
141
152
  # Non-interactive: save with auth token
142
153
  adcp --save-auth myagent https://test-agent.adcontextprotocol.org --auth your_token
143
154
 
@@ -206,11 +217,9 @@ async function main() {
206
217
  const providedAuthToken = authFlagIndex !== -1 ? args[authFlagIndex + 1] : null;
207
218
 
208
219
  // Filter out flags to get positional args
209
- const saveAuthPositional = args.slice(1).filter(arg =>
210
- arg !== '--auth' &&
211
- arg !== '--no-auth' &&
212
- arg !== providedAuthToken
213
- );
220
+ const saveAuthPositional = args
221
+ .slice(1)
222
+ .filter(arg => arg !== '--auth' && arg !== '--no-auth' && arg !== providedAuthToken);
214
223
 
215
224
  let alias = saveAuthPositional[0];
216
225
  let url = saveAuthPositional[1] || null;
@@ -325,11 +334,12 @@ async function main() {
325
334
  }
326
335
 
327
336
  // Filter out flag arguments to find positional arguments
328
- const positionalArgs = args.filter(arg =>
329
- !arg.startsWith('--') &&
330
- arg !== authToken && // Don't include the auth token value
331
- arg !== protocolFlag && // Don't include the protocol value
332
- arg !== (timeoutIndex !== -1 ? args[timeoutIndex + 1] : null) // Don't include timeout value
337
+ const positionalArgs = args.filter(
338
+ arg =>
339
+ !arg.startsWith('--') &&
340
+ arg !== authToken && // Don't include the auth token value
341
+ arg !== protocolFlag && // Don't include the protocol value
342
+ arg !== (timeoutIndex !== -1 ? args[timeoutIndex + 1] : null) // Don't include timeout value
333
343
  );
334
344
 
335
345
  // Determine if first arg is alias or URL
@@ -341,8 +351,64 @@ async function main() {
341
351
 
342
352
  const firstArg = positionalArgs[0];
343
353
 
344
- // Check if first arg is a saved alias
345
- if (isAlias(firstArg)) {
354
+ // Built-in test helper aliases
355
+ const BUILT_IN_AGENTS = {
356
+ test: {
357
+ url: 'https://test-agent.adcontextprotocol.org/mcp/',
358
+ protocol: 'mcp',
359
+ auth_token: '1v8tAhASaUYYp4odoQ1PnMpdqNaMiTrCRqYo9OJp6IQ',
360
+ description: 'AdCP public test agent (MCP, with auth)',
361
+ },
362
+ 'test-a2a': {
363
+ url: 'https://test-agent.adcontextprotocol.org',
364
+ protocol: 'a2a',
365
+ auth_token: '1v8tAhASaUYYp4odoQ1PnMpdqNaMiTrCRqYo9OJp6IQ',
366
+ description: 'AdCP public test agent (A2A, with auth)',
367
+ },
368
+ 'test-no-auth': {
369
+ url: 'https://test-agent.adcontextprotocol.org/mcp/',
370
+ protocol: 'mcp',
371
+ description: 'AdCP public test agent (MCP, no auth - demonstrates auth errors)',
372
+ },
373
+ 'test-a2a-no-auth': {
374
+ url: 'https://test-agent.adcontextprotocol.org',
375
+ protocol: 'a2a',
376
+ description: 'AdCP public test agent (A2A, no auth - demonstrates auth errors)',
377
+ },
378
+ creative: {
379
+ url: 'https://creative.adcontextprotocol.org/mcp',
380
+ protocol: 'mcp',
381
+ description: 'Official AdCP creative agent (MCP only)',
382
+ },
383
+ };
384
+
385
+ // Check if first arg is a built-in alias or saved alias
386
+ if (BUILT_IN_AGENTS[firstArg]) {
387
+ // Built-in test helper mode
388
+ savedAgent = BUILT_IN_AGENTS[firstArg];
389
+ agentUrl = savedAgent.url;
390
+
391
+ // Protocol priority: --protocol flag > built-in config
392
+ if (!protocol) {
393
+ protocol = savedAgent.protocol;
394
+ }
395
+
396
+ toolName = positionalArgs[1];
397
+ payloadArg = positionalArgs[2] || '{}';
398
+
399
+ // Use built-in auth token if not overridden and available
400
+ if (!authToken && savedAgent.auth_token) {
401
+ authToken = savedAgent.auth_token;
402
+ }
403
+
404
+ if (debug) {
405
+ console.error(`DEBUG: Using built-in agent '${firstArg}'`);
406
+ console.error(` ${savedAgent.description}`);
407
+ console.error(` URL: ${agentUrl}`);
408
+ console.error(` Protocol: ${protocol}`);
409
+ console.error('');
410
+ }
411
+ } else if (isAlias(firstArg)) {
346
412
  // Alias mode - load saved agent config
347
413
  savedAgent = getAgent(firstArg);
348
414
  agentUrl = savedAgent.url;
@@ -436,7 +502,7 @@ async function main() {
436
502
  name: 'CLI Agent',
437
503
  agent_uri: agentUrl,
438
504
  protocol: protocol,
439
- ...(authToken && { auth_token_env: authToken })
505
+ ...(authToken && { auth_token_env: authToken, requiresAuth: true }),
440
506
  };
441
507
 
442
508
  try {
@@ -477,7 +543,7 @@ async function main() {
477
543
 
478
544
  webhookHandler = new AsyncWebhookHandler({
479
545
  timeout: timeout,
480
- debug: debug
546
+ debug: debug,
481
547
  });
482
548
 
483
549
  try {
@@ -504,12 +570,12 @@ async function main() {
504
570
  }
505
571
 
506
572
  // Create ADCP client with optional webhook configuration
507
- const client = new ADCPClient(agentConfig, {
573
+ const client = new AdCPClient(agentConfig, {
508
574
  debug: debug,
509
575
  ...(webhookUrl && {
510
576
  webhookUrlTemplate: webhookUrl,
511
- webhookSecret: 'cli-webhook-secret'
512
- })
577
+ webhookSecret: 'cli-webhook-secret',
578
+ }),
513
579
  });
514
580
 
515
581
  if (debug) {
@@ -558,18 +624,25 @@ async function main() {
558
624
  if (result.success) {
559
625
  if (jsonOutput) {
560
626
  // Raw JSON output - include protocol metadata
561
- console.log(JSON.stringify({
562
- data: result.data,
563
- metadata: {
564
- taskId: result.metadata.taskId,
565
- protocol: result.metadata.agent.protocol,
566
- responseTimeMs: result.metadata.responseTimeMs,
567
- ...(result.conversation && result.conversation.length > 0 && {
568
- protocolMessage: extractProtocolMessage(result.conversation, result.metadata.agent.protocol),
569
- contextId: result.metadata.taskId // Using taskId as context identifier
570
- })
571
- }
572
- }, null, 2));
627
+ console.log(
628
+ JSON.stringify(
629
+ {
630
+ data: result.data,
631
+ metadata: {
632
+ taskId: result.metadata.taskId,
633
+ protocol: result.metadata.agent.protocol,
634
+ responseTimeMs: result.metadata.responseTimeMs,
635
+ ...(result.conversation &&
636
+ result.conversation.length > 0 && {
637
+ protocolMessage: extractProtocolMessage(result.conversation, result.metadata.agent.protocol),
638
+ contextId: result.metadata.taskId, // Using taskId as context identifier
639
+ }),
640
+ },
641
+ },
642
+ null,
643
+ 2
644
+ )
645
+ );
573
646
  } else {
574
647
  // Pretty output
575
648
  console.log('\n✅ SUCCESS\n');
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Advanced exports for library authors building custom protocol implementations
3
+ *
4
+ * @remarks
5
+ * **Most developers should use AdCPClient from the main export**, which provides:
6
+ * - Single-agent access via `client.agent(id)` with conversation context
7
+ * - Multi-agent parallel operations via `client.agents([ids])`
8
+ * - All AdCP tools with full type safety
9
+ *
10
+ * These low-level protocol clients are only needed if you're:
11
+ * - Building custom protocol handlers
12
+ * - Integrating AdCP with other frameworks
13
+ * - Implementing custom agent orchestration
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // ❌ Don't do this - use main AdCPClient instead:
18
+ * import { callA2ATool } from '@adcp/client/advanced';
19
+ *
20
+ * // ✅ Do this - use the main client:
21
+ * import { AdCPClient } from '@adcp/client';
22
+ * const client = new AdCPClient([agentConfig]);
23
+ * const agent = client.agent('agent-id');
24
+ * await agent.getProducts({ brief: '...' });
25
+ * ```
26
+ */
27
+ /**
28
+ * Protocol-level clients for direct protocol interaction
29
+ *
30
+ * @remarks
31
+ * Low-level clients for MCP and A2A protocols. Used internally by AdCPClient.
32
+ * Only use these if you need to build custom protocol handlers or integrations.
33
+ *
34
+ * For normal usage, prefer AdCPClient which wraps these and provides:
35
+ * - Automatic agent configuration
36
+ * - Conversation context management
37
+ * - Type-safe tool methods
38
+ * - Error handling and validation
39
+ */
40
+ export { ProtocolClient, callMCPTool, callA2ATool, createMCPClient, createA2AClient } from './protocols';
41
+ //# sourceMappingURL=advanced.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/lib/advanced.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ /**
3
+ * Advanced exports for library authors building custom protocol implementations
4
+ *
5
+ * @remarks
6
+ * **Most developers should use AdCPClient from the main export**, which provides:
7
+ * - Single-agent access via `client.agent(id)` with conversation context
8
+ * - Multi-agent parallel operations via `client.agents([ids])`
9
+ * - All AdCP tools with full type safety
10
+ *
11
+ * These low-level protocol clients are only needed if you're:
12
+ * - Building custom protocol handlers
13
+ * - Integrating AdCP with other frameworks
14
+ * - Implementing custom agent orchestration
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // ❌ Don't do this - use main AdCPClient instead:
19
+ * import { callA2ATool } from '@adcp/client/advanced';
20
+ *
21
+ * // ✅ Do this - use the main client:
22
+ * import { AdCPClient } from '@adcp/client';
23
+ * const client = new AdCPClient([agentConfig]);
24
+ * const agent = client.agent('agent-id');
25
+ * await agent.getProducts({ brief: '...' });
26
+ * ```
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.createA2AClient = exports.createMCPClient = exports.callA2ATool = exports.callMCPTool = exports.ProtocolClient = void 0;
30
+ /**
31
+ * Protocol-level clients for direct protocol interaction
32
+ *
33
+ * @remarks
34
+ * Low-level clients for MCP and A2A protocols. Used internally by AdCPClient.
35
+ * Only use these if you need to build custom protocol handlers or integrations.
36
+ *
37
+ * For normal usage, prefer AdCPClient which wraps these and provides:
38
+ * - Automatic agent configuration
39
+ * - Conversation context management
40
+ * - Type-safe tool methods
41
+ * - Error handling and validation
42
+ */
43
+ var protocols_1 = require("./protocols");
44
+ Object.defineProperty(exports, "ProtocolClient", { enumerable: true, get: function () { return protocols_1.ProtocolClient; } });
45
+ Object.defineProperty(exports, "callMCPTool", { enumerable: true, get: function () { return protocols_1.callMCPTool; } });
46
+ Object.defineProperty(exports, "callA2ATool", { enumerable: true, get: function () { return protocols_1.callA2ATool; } });
47
+ Object.defineProperty(exports, "createMCPClient", { enumerable: true, get: function () { return protocols_1.createMCPClient; } });
48
+ Object.defineProperty(exports, "createA2AClient", { enumerable: true, get: function () { return protocols_1.createA2AClient; } });
49
+ //# sourceMappingURL=advanced.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"advanced.js","sourceRoot":"","sources":["../../src/lib/advanced.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAEH;;;;;;;;;;;;GAYG;AACH,yCAAyG;AAAhG,2GAAA,cAAc,OAAA;AAAE,wGAAA,WAAW,OAAA;AAAE,wGAAA,WAAW,OAAA;AAAE,4GAAA,eAAe,OAAA;AAAE,4GAAA,eAAe,OAAA"}
@@ -5,6 +5,10 @@ import type { AgentConfig } from '../types';
5
5
  export declare function generateUUID(): string;
6
6
  /**
7
7
  * Get authentication token for an agent
8
+ *
9
+ * The auth_token_env field should contain the actual token value.
10
+ * For environment variable expansion, use shell substitution when calling the CLI:
11
+ * `--auth $MY_TOKEN` or `--auth "$MY_TOKEN"`
8
12
  */
9
13
  export declare function getAuthToken(agent: AgentConfig): string | undefined;
10
14
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAMrC;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAanE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,GAAE,OAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CASpG;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,IAC1C,KAAK,MAAM,GAAG,GAAG,GAAG,OAAO,EAAE,UAAU,WAAW,uBAWjE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAU/E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAMrC;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAOnE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,GAAE,OAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CASpG;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,IAC1C,KAAK,MAAM,GAAG,GAAG,GAAG,OAAO,EAAE,UAAU,WAAW,uBAWjE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAU/E"}
@@ -10,25 +10,24 @@ exports.createMCPAuthHeaders = createMCPAuthHeaders;
10
10
  */
11
11
  function generateUUID() {
12
12
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
13
- const r = Math.random() * 16 | 0;
14
- const v = c == 'x' ? r : (r & 0x3 | 0x8);
13
+ const r = (Math.random() * 16) | 0;
14
+ const v = c == 'x' ? r : (r & 0x3) | 0x8;
15
15
  return v.toString(16);
16
16
  });
17
17
  }
18
18
  /**
19
19
  * Get authentication token for an agent
20
+ *
21
+ * The auth_token_env field should contain the actual token value.
22
+ * For environment variable expansion, use shell substitution when calling the CLI:
23
+ * `--auth $MY_TOKEN` or `--auth "$MY_TOKEN"`
20
24
  */
21
25
  function getAuthToken(agent) {
22
26
  if (!agent.requiresAuth || !agent.auth_token_env) {
23
27
  return undefined;
24
28
  }
25
- // If auth_token_env looks like a direct token (not an env var name), use it directly
26
- // Base64-like tokens are typically 40+ chars and contain mixed case/symbols
27
- if (agent.auth_token_env.length > 20 && !agent.auth_token_env.match(/^[A-Z_][A-Z0-9_]*$/)) {
28
- return agent.auth_token_env;
29
- }
30
- // Otherwise, look up the environment variable
31
- return process.env[agent.auth_token_env];
29
+ // Always treat auth_token_env as a direct token value
30
+ return agent.auth_token_env;
32
31
  }
33
32
  /**
34
33
  * Create AdCP-compliant headers
@@ -39,8 +38,8 @@ function createAdCPHeaders(authToken, isMCP = false) {
39
38
  'AdCP-Version': '1.0',
40
39
  'AdCP-Request-ID': generateUUID(),
41
40
  'User-Agent': 'AdCP-Testing-Framework/1.0.0',
42
- 'Accept': isMCP ? 'application/json, text/event-stream' : 'application/vnd.adcp+json, application/json',
43
- ...(authToken && { 'Authorization': `Bearer ${authToken}` })
41
+ Accept: isMCP ? 'application/json, text/event-stream' : 'application/vnd.adcp+json, application/json',
42
+ ...(authToken && { Authorization: `Bearer ${authToken}` }),
44
43
  };
45
44
  }
46
45
  /**
@@ -53,8 +52,8 @@ function createAuthenticatedFetch(authToken) {
53
52
  ...options,
54
53
  headers: {
55
54
  ...headers,
56
- ...(options?.headers || {})
57
- }
55
+ ...(options?.headers || {}),
56
+ },
58
57
  });
59
58
  };
60
59
  }
@@ -63,7 +62,7 @@ function createAuthenticatedFetch(authToken) {
63
62
  */
64
63
  function createMCPAuthHeaders(authToken) {
65
64
  const headers = {
66
- 'Accept': 'application/json, text/event-stream'
65
+ Accept: 'application/json, text/event-stream',
67
66
  };
68
67
  if (authToken) {
69
68
  headers['x-adcp-auth'] = authToken;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/auth/index.ts"],"names":[],"mappings":";;AAKA,oCAMC;AAKD,oCAaC;AAKD,8CASC;AAKD,4DAYC;AAKD,oDAUC;AAzED;;GAEG;AACH,SAAgB,YAAY;IAC1B,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,UAAS,CAAC;QACvE,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACjC,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;QACzC,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,KAAkB;IAC7C,IAAI,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;QACjD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,qFAAqF;IACrF,4EAA4E;IAC5E,IAAI,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,oBAA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EAAE;QAClE,MAAM,OAAO,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAE7C,OAAO,KAAK,CAAC,GAAG,EAAE;YAChB,GAAG,OAAO;YACV,OAAO,EAAE;gBACP,GAAG,OAAO;gBACV,GAAG,CAAC,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC;aAC5B;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,SAAkB;IACrD,MAAM,OAAO,GAA2B;QACtC,MAAM,EAAE,qCAAqC;KAC9C,CAAC;IAEF,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC;IACrC,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { AgentConfig } from '../types';
2
2
  import { AgentClient } from './AgentClient';
3
- import type { ADCPClientConfig } from './ADCPClient';
3
+ import type { SingleAgentClientConfig } from './SingleAgentClient';
4
4
  import { CreativeAgentClient } from './CreativeAgentClient';
5
5
  import type { CreativeFormat } from './CreativeAgentClient';
6
6
  import type { InputHandler, TaskOptions, TaskResult, TaskInfo } from './ConversationTypes';
@@ -12,7 +12,7 @@ export declare class AgentCollection {
12
12
  private agents;
13
13
  private config;
14
14
  private clients;
15
- constructor(agents: AgentConfig[], config?: ADCPClientConfig);
15
+ constructor(agents: AgentConfig[], config?: SingleAgentClientConfig);
16
16
  /**
17
17
  * Execute getProducts on all agents in parallel
18
18
  */
@@ -116,7 +116,7 @@ export declare class AgentCollection {
116
116
  export declare class ADCPMultiAgentClient {
117
117
  private config;
118
118
  private agentClients;
119
- constructor(agentConfigs: AgentConfig[], config?: ADCPClientConfig);
119
+ constructor(agentConfigs?: AgentConfig[], config?: SingleAgentClientConfig);
120
120
  /**
121
121
  * Create client by auto-discovering agent configuration
122
122
  *
@@ -139,7 +139,7 @@ export declare class ADCPMultiAgentClient {
139
139
  * });
140
140
  * ```
141
141
  */
142
- static fromConfig(config?: ADCPClientConfig): ADCPMultiAgentClient;
142
+ static fromConfig(config?: SingleAgentClientConfig): ADCPMultiAgentClient;
143
143
  /**
144
144
  * Create client from environment variables only
145
145
  *
@@ -152,7 +152,7 @@ export declare class ADCPMultiAgentClient {
152
152
  * const client = ADCPMultiAgentClient.fromEnv();
153
153
  * ```
154
154
  */
155
- static fromEnv(config?: ADCPClientConfig): ADCPMultiAgentClient;
155
+ static fromEnv(config?: SingleAgentClientConfig): ADCPMultiAgentClient;
156
156
  /**
157
157
  * Create client from a specific config file
158
158
  *
@@ -169,7 +169,7 @@ export declare class ADCPMultiAgentClient {
169
169
  * const client = ADCPMultiAgentClient.fromFile();
170
170
  * ```
171
171
  */
172
- static fromFile(configPath?: string, config?: ADCPClientConfig): ADCPMultiAgentClient;
172
+ static fromFile(configPath?: string, config?: SingleAgentClientConfig): ADCPMultiAgentClient;
173
173
  /**
174
174
  * Create a simple client with minimal configuration
175
175
  *
@@ -386,6 +386,53 @@ export declare class ADCPMultiAgentClient {
386
386
  * ```
387
387
  */
388
388
  getTaskCountsByStatus(): Promise<Record<string, number>>;
389
+ /**
390
+ * Generate webhook URL for a specific agent, task type, and operation
391
+ *
392
+ * @param agentId - ID of the agent
393
+ * @param taskType - Type of task (e.g., 'get_products', 'media_buy_delivery')
394
+ * @param operationId - Operation ID for this request
395
+ * @returns Full webhook URL with macros replaced
396
+ *
397
+ * @example
398
+ * ```typescript
399
+ * const webhookUrl = client.getWebhookUrl('agent1', 'sync_creatives', 'op_123');
400
+ * // Returns: https://myapp.com/webhook/sync_creatives/agent1/op_123
401
+ * ```
402
+ */
403
+ getWebhookUrl(agentId: string, taskType: string, operationId: string): string;
404
+ /**
405
+ * Handle webhook from any agent (async task completion or notifications)
406
+ *
407
+ * Automatically routes webhook to the correct agent based on agent_id in payload.
408
+ *
409
+ * @param payload - Webhook payload from agent (must contain agent_id or operation_id)
410
+ * @param signature - Optional signature for verification (X-ADCP-Signature)
411
+ * @param timestamp - Optional timestamp for verification (X-ADCP-Timestamp)
412
+ * @returns Whether webhook was handled successfully
413
+ *
414
+ * @example
415
+ * ```typescript
416
+ * app.post('/webhook', async (req, res) => {
417
+ * const signature = req.headers['x-adcp-signature'];
418
+ * const timestamp = req.headers['x-adcp-timestamp'];
419
+ *
420
+ * try {
421
+ * const handled = await client.handleWebhook(req.body, signature, timestamp);
422
+ * res.status(200).json({ received: handled });
423
+ * } catch (error) {
424
+ * res.status(401).json({ error: error.message });
425
+ * }
426
+ * });
427
+ * ```
428
+ */
429
+ handleWebhook(payload: any, signature?: string, timestamp?: string | number): Promise<boolean>;
430
+ /**
431
+ * Infer agent ID from webhook payload when not explicitly provided
432
+ *
433
+ * Looks for patterns in operation_id or context_id that may contain agent information
434
+ */
435
+ private inferAgentIdFromPayload;
389
436
  /**
390
437
  * Create a creative agent client
391
438
  *
@@ -470,5 +517,5 @@ export declare class ADCPMultiAgentClient {
470
517
  * @param config - Client configuration
471
518
  * @returns Configured ADCPMultiAgentClient instance
472
519
  */
473
- export declare function createADCPMultiAgentClient(agents: AgentConfig[], config?: ADCPClientConfig): ADCPMultiAgentClient;
520
+ export declare function createADCPMultiAgentClient(agents: AgentConfig[], config?: SingleAgentClientConfig): ADCPMultiAgentClient;
474
521
  //# sourceMappingURL=ADCPMultiAgentClient.d.ts.map