@adcp/client 4.21.0 โ†’ 4.22.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 (160) hide show
  1. package/AGENTS.md +278 -0
  2. package/README.md +96 -61
  3. package/bin/adcp.js +342 -4
  4. package/dist/lib/agents/index.generated.d.ts +9 -1
  5. package/dist/lib/agents/index.generated.d.ts.map +1 -1
  6. package/dist/lib/agents/index.generated.js +12 -0
  7. package/dist/lib/agents/index.generated.js.map +1 -1
  8. package/dist/lib/core/AgentClient.d.ts.map +1 -1
  9. package/dist/lib/core/SingleAgentClient.d.ts +2 -1
  10. package/dist/lib/core/SingleAgentClient.d.ts.map +1 -1
  11. package/dist/lib/core/SingleAgentClient.js +10 -1
  12. package/dist/lib/core/SingleAgentClient.js.map +1 -1
  13. package/dist/lib/discovery/property-crawler.d.ts +4 -0
  14. package/dist/lib/discovery/property-crawler.d.ts.map +1 -1
  15. package/dist/lib/discovery/property-crawler.js +10 -2
  16. package/dist/lib/discovery/property-crawler.js.map +1 -1
  17. package/dist/lib/index.d.ts +4 -4
  18. package/dist/lib/index.d.ts.map +1 -1
  19. package/dist/lib/index.js +6 -4
  20. package/dist/lib/index.js.map +1 -1
  21. package/dist/lib/protocols/index.d.ts.map +1 -1
  22. package/dist/lib/protocols/index.js +8 -6
  23. package/dist/lib/protocols/index.js.map +1 -1
  24. package/dist/lib/protocols/mcp.d.ts.map +1 -1
  25. package/dist/lib/protocols/mcp.js +24 -11
  26. package/dist/lib/protocols/mcp.js.map +1 -1
  27. package/dist/lib/server/index.d.ts +2 -0
  28. package/dist/lib/server/index.d.ts.map +1 -1
  29. package/dist/lib/server/index.js +3 -1
  30. package/dist/lib/server/index.js.map +1 -1
  31. package/dist/lib/server/serve.d.ts +45 -0
  32. package/dist/lib/server/serve.d.ts.map +1 -0
  33. package/dist/lib/server/serve.js +86 -0
  34. package/dist/lib/server/serve.js.map +1 -0
  35. package/dist/lib/testing/client.d.ts.map +1 -1
  36. package/dist/lib/testing/client.js +1 -0
  37. package/dist/lib/testing/client.js.map +1 -1
  38. package/dist/lib/testing/compliance/comply.d.ts.map +1 -1
  39. package/dist/lib/testing/compliance/comply.js +48 -63
  40. package/dist/lib/testing/compliance/comply.js.map +1 -1
  41. package/dist/lib/testing/compliance/storyboard-tracks.d.ts +24 -0
  42. package/dist/lib/testing/compliance/storyboard-tracks.d.ts.map +1 -0
  43. package/dist/lib/testing/compliance/storyboard-tracks.js +157 -0
  44. package/dist/lib/testing/compliance/storyboard-tracks.js.map +1 -0
  45. package/dist/lib/testing/compliance/types.d.ts +1 -1
  46. package/dist/lib/testing/compliance/types.d.ts.map +1 -1
  47. package/dist/lib/testing/index.d.ts +1 -0
  48. package/dist/lib/testing/index.d.ts.map +1 -1
  49. package/dist/lib/testing/index.js +23 -1
  50. package/dist/lib/testing/index.js.map +1 -1
  51. package/dist/lib/testing/orchestrator.d.ts +8 -0
  52. package/dist/lib/testing/orchestrator.d.ts.map +1 -1
  53. package/dist/lib/testing/orchestrator.js +8 -0
  54. package/dist/lib/testing/orchestrator.js.map +1 -1
  55. package/dist/lib/testing/storyboard/context.d.ts +34 -0
  56. package/dist/lib/testing/storyboard/context.d.ts.map +1 -0
  57. package/dist/lib/testing/storyboard/context.js +257 -0
  58. package/dist/lib/testing/storyboard/context.js.map +1 -0
  59. package/dist/lib/testing/storyboard/index.d.ts +15 -0
  60. package/dist/lib/testing/storyboard/index.d.ts.map +1 -0
  61. package/dist/lib/testing/storyboard/index.js +48 -0
  62. package/dist/lib/testing/storyboard/index.js.map +1 -0
  63. package/dist/lib/testing/storyboard/loader.d.ts +53 -0
  64. package/dist/lib/testing/storyboard/loader.d.ts.map +1 -0
  65. package/dist/lib/testing/storyboard/loader.js +114 -0
  66. package/dist/lib/testing/storyboard/loader.js.map +1 -0
  67. package/dist/lib/testing/storyboard/path.d.ts +29 -0
  68. package/dist/lib/testing/storyboard/path.d.ts.map +1 -0
  69. package/dist/lib/testing/storyboard/path.js +121 -0
  70. package/dist/lib/testing/storyboard/path.js.map +1 -0
  71. package/dist/lib/testing/storyboard/request-builder.d.ts +28 -0
  72. package/dist/lib/testing/storyboard/request-builder.d.ts.map +1 -0
  73. package/dist/lib/testing/storyboard/request-builder.js +410 -0
  74. package/dist/lib/testing/storyboard/request-builder.js.map +1 -0
  75. package/dist/lib/testing/storyboard/runner.d.ts +24 -0
  76. package/dist/lib/testing/storyboard/runner.d.ts.map +1 -0
  77. package/dist/lib/testing/storyboard/runner.js +280 -0
  78. package/dist/lib/testing/storyboard/runner.js.map +1 -0
  79. package/dist/lib/testing/storyboard/task-map.d.ts +21 -0
  80. package/dist/lib/testing/storyboard/task-map.d.ts.map +1 -0
  81. package/dist/lib/testing/storyboard/task-map.js +84 -0
  82. package/dist/lib/testing/storyboard/task-map.js.map +1 -0
  83. package/dist/lib/testing/storyboard/types.d.ts +156 -0
  84. package/dist/lib/testing/storyboard/types.d.ts.map +1 -0
  85. package/dist/lib/testing/storyboard/types.js +10 -0
  86. package/dist/lib/testing/storyboard/types.js.map +1 -0
  87. package/dist/lib/testing/storyboard/validations.d.ts +17 -0
  88. package/dist/lib/testing/storyboard/validations.d.ts.map +1 -0
  89. package/dist/lib/testing/storyboard/validations.js +166 -0
  90. package/dist/lib/testing/storyboard/validations.js.map +1 -0
  91. package/dist/lib/testing/types.d.ts +2 -0
  92. package/dist/lib/testing/types.d.ts.map +1 -1
  93. package/dist/lib/types/core.generated.d.ts +2 -2
  94. package/dist/lib/types/core.generated.d.ts.map +1 -1
  95. package/dist/lib/types/core.generated.js +1 -1
  96. package/dist/lib/types/schemas.generated.d.ts +193 -34
  97. package/dist/lib/types/schemas.generated.d.ts.map +1 -1
  98. package/dist/lib/types/schemas.generated.js +87 -5
  99. package/dist/lib/types/schemas.generated.js.map +1 -1
  100. package/dist/lib/types/tools.generated.d.ts +280 -3
  101. package/dist/lib/types/tools.generated.d.ts.map +1 -1
  102. package/dist/lib/utils/response-schemas.d.ts.map +1 -1
  103. package/dist/lib/utils/response-schemas.js +34 -3
  104. package/dist/lib/utils/response-schemas.js.map +1 -1
  105. package/dist/lib/utils/validate-user-agent.d.ts +8 -0
  106. package/dist/lib/utils/validate-user-agent.d.ts.map +1 -0
  107. package/dist/lib/utils/validate-user-agent.js +15 -0
  108. package/dist/lib/utils/validate-user-agent.js.map +1 -0
  109. package/dist/lib/version.d.ts +6 -0
  110. package/dist/lib/version.d.ts.map +1 -1
  111. package/dist/lib/version.js +7 -1
  112. package/dist/lib/version.js.map +1 -1
  113. package/docs/README.md +42 -0
  114. package/docs/guides/BUILD-AN-AGENT.md +292 -0
  115. package/docs/llms.txt +634 -0
  116. package/examples/README.md +106 -0
  117. package/examples/adcp.config.json +30 -0
  118. package/examples/basic-a2a.ts +76 -0
  119. package/examples/basic-mcp.ts +50 -0
  120. package/examples/batch-preview-test.ts +266 -0
  121. package/examples/conversation-client.ts +291 -0
  122. package/examples/debug-preview-response.ts +73 -0
  123. package/examples/debug-preview-with-logging.ts +50 -0
  124. package/examples/easy-config-demo.ts +242 -0
  125. package/examples/env-config.ts +51 -0
  126. package/examples/error-compliant-server.ts +237 -0
  127. package/examples/generative-creative-demo.ts +205 -0
  128. package/examples/inspect-card-formats.ts +161 -0
  129. package/examples/logger-usage.ts +165 -0
  130. package/examples/oauth-cli-example.ts +154 -0
  131. package/examples/pr78-async-patterns-demo.ts +247 -0
  132. package/examples/signals-agent.ts +162 -0
  133. package/examples/simple-getting-started.ts +225 -0
  134. package/examples/simple-protocol-demo.ts +75 -0
  135. package/examples/test-helpers-demo.ts +239 -0
  136. package/examples/zod-validation-example.ts +126 -0
  137. package/package.json +12 -2
  138. package/skills/adcp/SKILL.md +13 -2
  139. package/storyboards/audience_sync.yaml +199 -0
  140. package/storyboards/behavioral_analysis.yaml +244 -0
  141. package/storyboards/brand_rights.yaml +131 -0
  142. package/storyboards/creative_ad_server.yaml +171 -0
  143. package/storyboards/creative_sales_agent.yaml +169 -0
  144. package/storyboards/creative_template.yaml +306 -0
  145. package/storyboards/deterministic_testing.yaml +925 -0
  146. package/storyboards/error_compliance.yaml +231 -0
  147. package/storyboards/governance_content_standards.yaml +213 -0
  148. package/storyboards/governance_property_lists.yaml +372 -0
  149. package/storyboards/media_buy_catalog_creative.yaml +457 -0
  150. package/storyboards/media_buy_governance_escalation.yaml +467 -0
  151. package/storyboards/media_buy_guaranteed_approval.yaml +396 -0
  152. package/storyboards/media_buy_non_guaranteed.yaml +288 -0
  153. package/storyboards/media_buy_proposal_mode.yaml +369 -0
  154. package/storyboards/media_buy_seller.yaml +560 -0
  155. package/storyboards/media_buy_state_machine.yaml +254 -0
  156. package/storyboards/schema.yaml +65 -0
  157. package/storyboards/schema_validation.yaml +166 -0
  158. package/storyboards/si_session.yaml +384 -0
  159. package/storyboards/signal_marketplace.yaml +283 -0
  160. package/storyboards/signal_owned.yaml +211 -0
@@ -0,0 +1,291 @@
1
+ #!/usr/bin/env tsx
2
+ // Example: Using the new conversation-aware ADCP client library
3
+
4
+ import {
5
+ ADCPMultiAgentClient,
6
+ AgentClient,
7
+ createFieldHandler,
8
+ createConditionalHandler,
9
+ autoApproveHandler,
10
+ deferAllHandler,
11
+ type AgentConfig,
12
+ type InputHandler,
13
+ type ConversationContext,
14
+ } from '@adcp/client';
15
+
16
+ // Example agent configurations
17
+ const agents: AgentConfig[] = [
18
+ {
19
+ id: 'premium-agent',
20
+ name: 'Premium Ad Agent',
21
+ agent_uri: 'https://premium-agent.example.com/mcp/',
22
+ protocol: 'mcp',
23
+ auth_token: process.env.PREMIUM_AGENT_TOKEN,
24
+ },
25
+ {
26
+ id: 'budget-agent',
27
+ name: 'Budget Ad Agent',
28
+ agent_uri: 'https://budget-agent.example.com/a2a/',
29
+ protocol: 'a2a',
30
+ },
31
+ ];
32
+
33
+ /**
34
+ * Example 1: Single agent with conversation context
35
+ */
36
+ async function singleAgentExample() {
37
+ console.log('\n=== Single Agent Example ===');
38
+
39
+ const client = new ADCPMultiAgentClient(agents);
40
+ const agent = client.agent('premium-agent');
41
+
42
+ // Create a smart input handler that can handle different fields
43
+ const smartHandler: InputHandler = createFieldHandler(
44
+ {
45
+ budget: 50000,
46
+ targeting: ['US', 'CA', 'UK'],
47
+ approval: (context: ConversationContext) => {
48
+ // Auto-approve on first attempt, defer on subsequent attempts
49
+ return context.attempt === 1 ? true : context.deferToHuman();
50
+ },
51
+ },
52
+ deferAllHandler
53
+ ); // Default to defer for unmapped fields
54
+
55
+ try {
56
+ // Initial request
57
+ console.log('๐Ÿ” Getting products...');
58
+ const products = await agent.getProducts(
59
+ {
60
+ brief: 'Premium coffee brands for millennials',
61
+ promoted_offering: 'Artisan coffee blends',
62
+ },
63
+ smartHandler
64
+ );
65
+
66
+ if (products.success) {
67
+ console.log(`โœ… Found ${products.data.products?.length || 0} products`);
68
+ console.log(`โฑ๏ธ Response time: ${products.metadata.responseTimeMs}ms`);
69
+ console.log(`๐Ÿ”„ Clarification rounds: ${products.metadata.clarificationRounds}`);
70
+
71
+ // Continue the conversation
72
+ console.log('\n๐Ÿ’ฌ Continuing conversation...');
73
+ const refined = await agent.continueConversation(
74
+ 'Focus only on premium organic brands with sustainability certifications',
75
+ smartHandler
76
+ );
77
+
78
+ if (refined.success) {
79
+ console.log(`โœ… Refined search returned ${refined.data.products?.length || 0} products`);
80
+ }
81
+ } else {
82
+ console.error(`โŒ Error: ${products.error}`);
83
+ }
84
+ } catch (error) {
85
+ console.error('โŒ Failed:', error.message);
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Example 2: Multi-agent parallel execution
91
+ */
92
+ async function multiAgentExample() {
93
+ console.log('\n=== Multi-Agent Example ===');
94
+
95
+ const client = new ADCPMultiAgentClient(agents);
96
+
97
+ // Simple auto-approve handler for bulk operations
98
+ const autoHandler: InputHandler = context => {
99
+ console.log(`๐Ÿค– Auto-responding to ${context.agent.name}: ${context.inputRequest.question}`);
100
+
101
+ // Use suggestions if available, otherwise use sensible defaults
102
+ if (context.inputRequest.suggestions?.length) {
103
+ return context.inputRequest.suggestions[0];
104
+ }
105
+
106
+ // Field-specific defaults
107
+ switch (context.inputRequest.field) {
108
+ case 'budget':
109
+ return 25000;
110
+ case 'targeting':
111
+ return ['US'];
112
+ case 'approval':
113
+ return true;
114
+ default:
115
+ return true;
116
+ }
117
+ };
118
+
119
+ try {
120
+ console.log('๐Ÿš€ Querying all agents in parallel...');
121
+ const results = await client.allAgents().getProducts(
122
+ {
123
+ brief: 'Tech gadgets for remote work',
124
+ promoted_offering: 'Productivity tools and accessories',
125
+ },
126
+ autoHandler
127
+ );
128
+
129
+ console.log(`๐Ÿ“Š Got ${results.length} responses:`);
130
+ results.forEach(result => {
131
+ if (result.success) {
132
+ console.log(
133
+ ` โœ… ${result.metadata.agent.name}: ${result.data.products?.length || 0} products (${
134
+ result.metadata.responseTimeMs
135
+ }ms)`
136
+ );
137
+ } else {
138
+ console.log(` โŒ ${result.metadata.agent.name}: ${result.error}`);
139
+ }
140
+ });
141
+
142
+ // Find the best result
143
+ const successful = results.filter(r => r.success);
144
+ if (successful.length > 0) {
145
+ const best = successful.sort((a, b) => (b.data.products?.length || 0) - (a.data.products?.length || 0))[0];
146
+ console.log(`๐Ÿ† Best result: ${best.metadata.agent.name} with ${best.data.products?.length || 0} products`);
147
+ }
148
+ } catch (error) {
149
+ console.error('โŒ Multi-agent query failed:', error.message);
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Example 3: Advanced input handling patterns
155
+ */
156
+ async function advancedHandlersExample() {
157
+ console.log('\n=== Advanced Input Handlers Example ===');
158
+
159
+ const client = new ADCPMultiAgentClient(agents);
160
+ const agent = client.agent('premium-agent');
161
+
162
+ // Conditional handler based on agent type and context
163
+ const conditionalHandler = createConditionalHandler(
164
+ [
165
+ {
166
+ condition: ctx => ctx.agent.name.includes('Premium'),
167
+ handler: createFieldHandler({
168
+ budget: 100000, // Higher budget for premium agents
169
+ targeting: ['US', 'CA', 'UK', 'AU'],
170
+ approval: true,
171
+ }),
172
+ },
173
+ {
174
+ condition: ctx => ctx.attempt > 2,
175
+ handler: deferAllHandler, // Defer if too many clarifications
176
+ },
177
+ ],
178
+ autoApproveHandler
179
+ );
180
+
181
+ try {
182
+ console.log('๐ŸŽฏ Testing advanced input handling...');
183
+ const result = await agent.listCreativeFormats(
184
+ {
185
+ type: 'video',
186
+ },
187
+ conditionalHandler
188
+ );
189
+
190
+ if (result.success) {
191
+ console.log(`โœ… Got ${result.data.formats?.length || 0} video formats`);
192
+ console.log(`๐Ÿ”„ Clarifications: ${result.metadata.clarificationRounds}`);
193
+ } else {
194
+ console.log(`โŒ Error: ${result.error}`);
195
+ }
196
+ } catch (error) {
197
+ console.error('โŒ Advanced handler failed:', error.message);
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Example 4: Conversation history and context management
203
+ */
204
+ async function conversationHistoryExample() {
205
+ console.log('\n=== Conversation History Example ===');
206
+
207
+ const client = new ADCPMultiAgentClient(agents);
208
+ const agent = client.agent('budget-agent');
209
+
210
+ // Handler that uses conversation history
211
+ const historyAwareHandler: InputHandler = context => {
212
+ console.log(`๐Ÿ“œ Conversation has ${context.messages.length} messages`);
213
+
214
+ // Check if budget was previously discussed
215
+ if (context.wasFieldDiscussed('budget')) {
216
+ const previousBudget = context.getPreviousResponse('budget');
217
+ console.log(`๐Ÿ’ฐ Previously discussed budget: ${previousBudget}`);
218
+ return previousBudget;
219
+ }
220
+
221
+ return context.inputRequest.field === 'budget' ? 15000 : true;
222
+ };
223
+
224
+ try {
225
+ console.log('๐Ÿ“– Starting conversation with history tracking...');
226
+
227
+ // First request
228
+ await agent.getProducts(
229
+ {
230
+ brief: 'Affordable marketing tools',
231
+ },
232
+ historyAwareHandler
233
+ );
234
+
235
+ console.log('๐Ÿ“ Conversation history:');
236
+ const history = agent.getHistory();
237
+ history?.forEach((msg, i) => {
238
+ console.log(` ${i + 1}. ${msg.role}: ${JSON.stringify(msg.content).slice(0, 100)}...`);
239
+ });
240
+
241
+ // Second request in same conversation
242
+ await agent.listCreativeFormats(
243
+ {
244
+ type: 'display',
245
+ },
246
+ historyAwareHandler
247
+ );
248
+
249
+ console.log(`๐Ÿ“Š Total messages in conversation: ${agent.getHistory()?.length || 0}`);
250
+ } catch (error) {
251
+ console.error('โŒ History example failed:', error.message);
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Main example runner
257
+ */
258
+ async function main() {
259
+ console.log('๐ŸŽฏ ADCP Conversation-Aware Client Library Examples');
260
+ console.log('================================================');
261
+
262
+ // Note: These examples will fail with real network calls since we're using example URLs
263
+ // In a real scenario, you'd have actual agent endpoints
264
+
265
+ try {
266
+ await singleAgentExample();
267
+ await multiAgentExample();
268
+ await advancedHandlersExample();
269
+ await conversationHistoryExample();
270
+ } catch (error) {
271
+ console.log('\n๐Ÿ’ก Note: Examples use mock URLs and will fail with real network calls');
272
+ console.log(' In production, configure with real agent endpoints');
273
+ console.log(` Error: ${error.message}`);
274
+ }
275
+
276
+ console.log('\nโœจ Examples completed! Check the source code for implementation details.');
277
+ console.log('\n๐Ÿ“š Key Features Demonstrated:');
278
+ console.log(' โ€ข Conversation-aware single agent operations');
279
+ console.log(' โ€ข Parallel multi-agent execution');
280
+ console.log(' โ€ข Smart input handlers with field mapping');
281
+ console.log(' โ€ข Conditional logic and retry patterns');
282
+ console.log(' โ€ข Conversation history and context preservation');
283
+ console.log(' โ€ข Type-safe task execution with full IntelliSense');
284
+ }
285
+
286
+ // Run examples if this file is executed directly
287
+ if (require.main === module) {
288
+ main().catch(console.error);
289
+ }
290
+
291
+ export { singleAgentExample, multiAgentExample, advancedHandlersExample, conversationHistoryExample };
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env tsx
2
+
3
+ /**
4
+ * Debug: Inspect actual preview_creative response
5
+ */
6
+
7
+ import { AdCPClient } from '../src/lib/core/AdCPClient';
8
+
9
+ const CREATIVE_AGENT_URL = process.env.CREATIVE_AGENT_URL || 'https://creative.adcontextprotocol.org/mcp';
10
+ const CREATIVE_AGENT_PROTOCOL = (process.env.CREATIVE_AGENT_PROTOCOL || 'mcp') as 'mcp' | 'a2a';
11
+
12
+ async function main() {
13
+ console.log('๐Ÿ› Debugging Preview Creative Response\n');
14
+
15
+ const creativeAgent = new AdCPClient({
16
+ id: 'creative_agent',
17
+ name: 'Creative Agent',
18
+ agent_uri: CREATIVE_AGENT_URL,
19
+ protocol: CREATIVE_AGENT_PROTOCOL,
20
+ });
21
+
22
+ // Simple preview_creative request
23
+ // Note: Using type assertion to bypass strict TypeScript validation
24
+ // The actual creative agent expects plain strings for text assets
25
+ const response = await creativeAgent.previewCreative({
26
+ format_id: {
27
+ agent_url: 'https://creative.adcontextprotocol.org/',
28
+ id: 'product_card_standard',
29
+ },
30
+ creative_manifest: {
31
+ format_id: {
32
+ agent_url: 'https://creative.adcontextprotocol.org/',
33
+ id: 'product_card_standard',
34
+ },
35
+ assets: {
36
+ product_image: {
37
+ url: 'https://images.unsplash.com/photo-1460925895917-afdab827c52f?w=400&h=300',
38
+ },
39
+ product_name: {
40
+ content: 'Premium Display Package',
41
+ },
42
+ product_description: {
43
+ content: 'High-visibility display advertising with guaranteed impressions and premium placements',
44
+ },
45
+ pricing_model: {
46
+ content: 'CPM',
47
+ },
48
+ pricing_amount: {
49
+ content: '5,000',
50
+ },
51
+ pricing_currency: {
52
+ content: 'USD',
53
+ },
54
+ delivery_type: {
55
+ content: 'Guaranteed',
56
+ },
57
+ primary_asset_type: {
58
+ content: 'Display Banners',
59
+ },
60
+ },
61
+ },
62
+ } as any);
63
+
64
+ console.log('Response success:', response.success);
65
+ console.log('Response error:', response.error);
66
+ console.log('\nFull response data:');
67
+ console.log(JSON.stringify(response.data, null, 2));
68
+ }
69
+
70
+ main().catch(error => {
71
+ console.error('Fatal error:', error);
72
+ process.exit(1);
73
+ });
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env tsx
2
+
3
+ /**
4
+ * Debug with detailed logging
5
+ */
6
+
7
+ import { AdCPClient } from '../src/lib/core/AdCPClient';
8
+ import { batchPreviewProducts } from '../src/lib/utils/preview-utils';
9
+ import type { Product } from '../src/lib/types/tools.generated';
10
+
11
+ const CREATIVE_AGENT_URL = process.env.CREATIVE_AGENT_URL || 'https://creative.adcontextprotocol.org/mcp';
12
+
13
+ async function main() {
14
+ const creativeAgent = new AdCPClient({
15
+ id: 'creative_agent',
16
+ name: 'Creative Agent',
17
+ agent_uri: CREATIVE_AGENT_URL,
18
+ protocol: 'mcp',
19
+ });
20
+
21
+ const testProduct: Product = {
22
+ product_id: 'test1',
23
+ name: 'Test Product',
24
+ product_card: {
25
+ format_id: {
26
+ agent_url: 'https://creative.adcontextprotocol.org/',
27
+ id: 'product_card_standard',
28
+ },
29
+ manifest: {
30
+ product_image: {
31
+ url: 'https://images.unsplash.com/photo-1460925895917-afdab827c52f?w=400&h=300',
32
+ },
33
+ product_name: {
34
+ content: 'Test Product',
35
+ },
36
+ product_description: {
37
+ content: 'A test product for debugging',
38
+ },
39
+ } as any,
40
+ },
41
+ };
42
+
43
+ console.log('๐Ÿ“ฆ Calling batchPreviewProducts...\n');
44
+ const results = await batchPreviewProducts([testProduct], creativeAgent);
45
+
46
+ console.log('\n๐Ÿ“Š Results:');
47
+ console.log(JSON.stringify(results, null, 2));
48
+ }
49
+
50
+ main().catch(console.error);
@@ -0,0 +1,242 @@
1
+ #!/usr/bin/env tsx
2
+ // Easy Configuration Demo - Show how simple it is to configure ADCP agents
3
+
4
+ import { ADCPMultiAgentClient, ConfigurationManager, createFieldHandler } from '../src/lib';
5
+
6
+ /**
7
+ * Demo 1: Environment Variable Configuration
8
+ */
9
+ async function envConfigDemo() {
10
+ console.log('๐ŸŒ Environment Variable Configuration Demo');
11
+ console.log('==========================================\n');
12
+
13
+ // In real usage, you'd set this in your shell or .env file:
14
+ // export SALES_AGENTS_CONFIG='{"agents":[{"id":"demo","name":"Demo Agent","agent_uri":"https://demo.example.com","protocol":"mcp"}]}'
15
+
16
+ // For demo purposes, set it programmatically
17
+ process.env.SALES_AGENTS_CONFIG = JSON.stringify({
18
+ agents: [
19
+ {
20
+ id: 'demo-env-agent',
21
+ name: 'Demo Environment Agent',
22
+ agent_uri: 'https://demo-env.example.com',
23
+ protocol: 'mcp',
24
+ },
25
+ ],
26
+ });
27
+
28
+ try {
29
+ // Super simple - just one line!
30
+ console.log('๐Ÿš€ Creating client from environment...');
31
+ const client = ADCPMultiAgentClient.fromEnv();
32
+
33
+ console.log(`โœ… Success! Loaded ${client.agentCount} agent(s)`);
34
+ console.log(` Available agents: ${client.getAgentIds().join(', ')}`);
35
+
36
+ // Use the agent
37
+ const agent = client.agent('demo-env-agent');
38
+ console.log(` Agent name: ${agent.getAgentName()}`);
39
+ console.log(` Protocol: ${agent.getProtocol()}\n`);
40
+ } catch (error) {
41
+ console.log(`โŒ Error: ${error.message}\n`);
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Demo 2: One-Liner Simple Setup
47
+ */
48
+ async function simpleConfigDemo() {
49
+ console.log('โšก One-Liner Simple Configuration Demo');
50
+ console.log('====================================\n');
51
+
52
+ try {
53
+ // Simplest possible setup
54
+ console.log('๐Ÿš€ Creating client with one-liner...');
55
+ const client = ADCPMultiAgentClient.simple('https://simple-agent.example.com');
56
+
57
+ console.log(`โœ… Success! Created client with default agent`);
58
+ console.log(` Agent ID: ${client.getAgentIds()[0]}`);
59
+ console.log(` Agent count: ${client.agentCount}`);
60
+
61
+ // Access the default agent
62
+ const agent = client.agent('default-agent');
63
+ console.log(` Agent name: ${agent.getAgentName()}`);
64
+ console.log(` Protocol: ${agent.getProtocol()} (default)\n`);
65
+ } catch (error) {
66
+ console.log(`โŒ Error: ${error.message}\n`);
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Demo 3: Simple Setup with Options
72
+ */
73
+ async function simpleWithOptionsDemo() {
74
+ console.log('๐Ÿ”ง Simple Setup with Custom Options');
75
+ console.log('=================================\n');
76
+
77
+ try {
78
+ console.log('๐Ÿš€ Creating client with custom options...');
79
+ const client = ADCPMultiAgentClient.simple('https://custom-agent.example.com', {
80
+ agentId: 'my-custom-agent',
81
+ agentName: 'My Custom Agent',
82
+ protocol: 'a2a',
83
+ requiresAuth: true,
84
+ authTokenEnv: 'MY_AGENT_TOKEN',
85
+ debug: true,
86
+ timeout: 45000,
87
+ });
88
+
89
+ console.log(`โœ… Success! Created customized client`);
90
+ console.log(` Agent ID: ${client.getAgentIds()[0]}`);
91
+
92
+ const agent = client.agent('my-custom-agent');
93
+ console.log(` Agent name: ${agent.getAgentName()}`);
94
+ console.log(` Protocol: ${agent.getProtocol()}`);
95
+ console.log(` Requires auth: true`);
96
+ console.log(` Debug enabled: true\n`);
97
+ } catch (error) {
98
+ console.log(`โŒ Error: ${error.message}\n`);
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Demo 4: Configuration Help
104
+ */
105
+ async function configHelpDemo() {
106
+ console.log('๐Ÿ“š Configuration Help Demo');
107
+ console.log('=========================\n');
108
+
109
+ console.log('๐Ÿ’ก Configuration options available:');
110
+ console.log(' Environment variables:', ConfigurationManager.getEnvVars().join(', '));
111
+ console.log(
112
+ ' Config files:',
113
+ ConfigurationManager.getConfigPaths()
114
+ .map(p => p.split('/').pop())
115
+ .join(', ')
116
+ );
117
+
118
+ console.log('\n๐Ÿ“– Full configuration help:');
119
+ console.log(ConfigurationManager.getConfigurationHelp());
120
+ }
121
+
122
+ /**
123
+ * Demo 5: Configuration Validation
124
+ */
125
+ async function validationDemo() {
126
+ console.log('๐Ÿ›ก๏ธ Configuration Validation Demo');
127
+ console.log('================================\n');
128
+
129
+ // Test invalid configuration
130
+ try {
131
+ console.log('๐Ÿงช Testing invalid agent configuration...');
132
+ const client = ADCPMultiAgentClient.simple('not-a-valid-url');
133
+ } catch (error) {
134
+ console.log(`โœ… Validation caught error: ${error.message}\n`);
135
+ }
136
+
137
+ // Test duplicate agent IDs
138
+ try {
139
+ console.log('๐Ÿงช Testing duplicate agent IDs...');
140
+ const client = new ADCPMultiAgentClient([
141
+ { id: 'agent1', name: 'Agent 1', agent_uri: 'https://agent1.example.com', protocol: 'mcp' },
142
+ { id: 'agent1', name: 'Agent 1 Duplicate', agent_uri: 'https://agent1-dup.example.com', protocol: 'mcp' },
143
+ ]);
144
+ } catch (error) {
145
+ console.log(`โœ… Validation caught duplicate ID: ${error.message}\n`);
146
+ }
147
+
148
+ // Test missing required fields
149
+ try {
150
+ console.log('๐Ÿงช Testing missing required fields...');
151
+ const client = new ADCPMultiAgentClient([{ id: 'incomplete', name: 'Incomplete Agent' } as any]);
152
+ } catch (error) {
153
+ console.log(`โœ… Validation caught missing field: ${error.message}\n`);
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Demo 6: Real-World Usage Pattern
159
+ */
160
+ async function realWorldDemo() {
161
+ console.log('๐ŸŒŸ Real-World Usage Pattern Demo');
162
+ console.log('===============================\n');
163
+
164
+ // This is how you'd typically use it in production
165
+ try {
166
+ console.log('๐Ÿญ Production-style setup...');
167
+
168
+ // Option 1: Environment-based (recommended for production)
169
+ let client;
170
+ try {
171
+ client = ADCPMultiAgentClient.fromConfig(); // Auto-discovers env or config file
172
+ console.log('โœ… Loaded configuration automatically');
173
+ } catch (error) {
174
+ // Fallback to simple setup for development
175
+ console.log('โš ๏ธ No configuration found, using development fallback');
176
+ client = ADCPMultiAgentClient.simple(process.env.ADCP_AGENT_URL || 'https://dev-agent.example.com', {
177
+ agentName: 'Development Agent',
178
+ debug: true,
179
+ });
180
+ }
181
+
182
+ console.log(`๐Ÿ“Š Client stats:`);
183
+ console.log(` Agent count: ${client.agentCount}`);
184
+ console.log(` Agent IDs: ${client.getAgentIds().join(', ')}`);
185
+
186
+ // Create a smart handler for production use
187
+ const handler = createFieldHandler({
188
+ budget: parseInt(process.env.DEFAULT_BUDGET || '25000'),
189
+ targeting: (process.env.DEFAULT_TARGETING || 'US,CA').split(','),
190
+ approval: process.env.AUTO_APPROVE === 'true',
191
+ });
192
+
193
+ console.log(`๐ŸŽฏ Created production-ready handler with defaults`);
194
+
195
+ // Use the first available agent
196
+ const agentId = client.getAgentIds()[0];
197
+ const agent = client.agent(agentId);
198
+
199
+ console.log(`๐Ÿš€ Ready to use agent: ${agent.getAgentName()}`);
200
+ console.log(` Protocol: ${agent.getProtocol()}`);
201
+
202
+ // In real usage, you'd make actual calls here:
203
+ // const products = await agent.getProducts({ brief: 'Coffee brands' }, handler);
204
+ } catch (error) {
205
+ console.log(`โŒ Setup failed: ${error.message}`);
206
+ }
207
+
208
+ console.log('\n๐ŸŽ‰ Production setup complete!\n');
209
+ }
210
+
211
+ /**
212
+ * Main demo runner
213
+ */
214
+ async function main() {
215
+ console.log('๐ŸŽฏ ADCP Easy Configuration Demo');
216
+ console.log('===============================\n');
217
+
218
+ console.log('This demo shows how easy it is to configure ADCP agents using the new configuration methods.\n');
219
+
220
+ await envConfigDemo();
221
+ await simpleConfigDemo();
222
+ await simpleWithOptionsDemo();
223
+ await configHelpDemo();
224
+ await validationDemo();
225
+ await realWorldDemo();
226
+
227
+ console.log('๐ŸŽ“ Key Takeaways:');
228
+ console.log(' โ€ข ADCPMultiAgentClient.fromConfig() - Auto-discovers configuration');
229
+ console.log(' โ€ข ADCPMultiAgentClient.fromEnv() - Loads from environment variables');
230
+ console.log(' โ€ข ADCPMultiAgentClient.simple(url) - One-liner setup');
231
+ console.log(' โ€ข Automatic validation prevents configuration errors');
232
+ console.log(' โ€ข Multiple configuration sources (env, files, programmatic)');
233
+ console.log(' โ€ข Production-ready with fallback strategies');
234
+ console.log('\n๐Ÿ“š See the README for more configuration examples!');
235
+ }
236
+
237
+ // Run demo if this file is executed directly
238
+ if (require.main === module) {
239
+ main().catch(console.error);
240
+ }
241
+
242
+ export { envConfigDemo, simpleConfigDemo, simpleWithOptionsDemo, configHelpDemo, validationDemo, realWorldDemo };