@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.
- package/AGENTS.md +278 -0
- package/README.md +96 -61
- package/bin/adcp.js +342 -4
- package/dist/lib/agents/index.generated.d.ts +9 -1
- package/dist/lib/agents/index.generated.d.ts.map +1 -1
- package/dist/lib/agents/index.generated.js +12 -0
- package/dist/lib/agents/index.generated.js.map +1 -1
- package/dist/lib/core/AgentClient.d.ts.map +1 -1
- package/dist/lib/core/SingleAgentClient.d.ts +2 -1
- package/dist/lib/core/SingleAgentClient.d.ts.map +1 -1
- package/dist/lib/core/SingleAgentClient.js +10 -1
- package/dist/lib/core/SingleAgentClient.js.map +1 -1
- package/dist/lib/discovery/property-crawler.d.ts +4 -0
- package/dist/lib/discovery/property-crawler.d.ts.map +1 -1
- package/dist/lib/discovery/property-crawler.js +10 -2
- package/dist/lib/discovery/property-crawler.js.map +1 -1
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +6 -4
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/protocols/index.d.ts.map +1 -1
- package/dist/lib/protocols/index.js +8 -6
- package/dist/lib/protocols/index.js.map +1 -1
- package/dist/lib/protocols/mcp.d.ts.map +1 -1
- package/dist/lib/protocols/mcp.js +24 -11
- package/dist/lib/protocols/mcp.js.map +1 -1
- package/dist/lib/server/index.d.ts +2 -0
- package/dist/lib/server/index.d.ts.map +1 -1
- package/dist/lib/server/index.js +3 -1
- package/dist/lib/server/index.js.map +1 -1
- package/dist/lib/server/serve.d.ts +45 -0
- package/dist/lib/server/serve.d.ts.map +1 -0
- package/dist/lib/server/serve.js +86 -0
- package/dist/lib/server/serve.js.map +1 -0
- package/dist/lib/testing/client.d.ts.map +1 -1
- package/dist/lib/testing/client.js +1 -0
- package/dist/lib/testing/client.js.map +1 -1
- package/dist/lib/testing/compliance/comply.d.ts.map +1 -1
- package/dist/lib/testing/compliance/comply.js +48 -63
- package/dist/lib/testing/compliance/comply.js.map +1 -1
- package/dist/lib/testing/compliance/storyboard-tracks.d.ts +24 -0
- package/dist/lib/testing/compliance/storyboard-tracks.d.ts.map +1 -0
- package/dist/lib/testing/compliance/storyboard-tracks.js +157 -0
- package/dist/lib/testing/compliance/storyboard-tracks.js.map +1 -0
- package/dist/lib/testing/compliance/types.d.ts +1 -1
- package/dist/lib/testing/compliance/types.d.ts.map +1 -1
- package/dist/lib/testing/index.d.ts +1 -0
- package/dist/lib/testing/index.d.ts.map +1 -1
- package/dist/lib/testing/index.js +23 -1
- package/dist/lib/testing/index.js.map +1 -1
- package/dist/lib/testing/orchestrator.d.ts +8 -0
- package/dist/lib/testing/orchestrator.d.ts.map +1 -1
- package/dist/lib/testing/orchestrator.js +8 -0
- package/dist/lib/testing/orchestrator.js.map +1 -1
- package/dist/lib/testing/storyboard/context.d.ts +34 -0
- package/dist/lib/testing/storyboard/context.d.ts.map +1 -0
- package/dist/lib/testing/storyboard/context.js +257 -0
- package/dist/lib/testing/storyboard/context.js.map +1 -0
- package/dist/lib/testing/storyboard/index.d.ts +15 -0
- package/dist/lib/testing/storyboard/index.d.ts.map +1 -0
- package/dist/lib/testing/storyboard/index.js +48 -0
- package/dist/lib/testing/storyboard/index.js.map +1 -0
- package/dist/lib/testing/storyboard/loader.d.ts +53 -0
- package/dist/lib/testing/storyboard/loader.d.ts.map +1 -0
- package/dist/lib/testing/storyboard/loader.js +114 -0
- package/dist/lib/testing/storyboard/loader.js.map +1 -0
- package/dist/lib/testing/storyboard/path.d.ts +29 -0
- package/dist/lib/testing/storyboard/path.d.ts.map +1 -0
- package/dist/lib/testing/storyboard/path.js +121 -0
- package/dist/lib/testing/storyboard/path.js.map +1 -0
- package/dist/lib/testing/storyboard/request-builder.d.ts +28 -0
- package/dist/lib/testing/storyboard/request-builder.d.ts.map +1 -0
- package/dist/lib/testing/storyboard/request-builder.js +410 -0
- package/dist/lib/testing/storyboard/request-builder.js.map +1 -0
- package/dist/lib/testing/storyboard/runner.d.ts +24 -0
- package/dist/lib/testing/storyboard/runner.d.ts.map +1 -0
- package/dist/lib/testing/storyboard/runner.js +280 -0
- package/dist/lib/testing/storyboard/runner.js.map +1 -0
- package/dist/lib/testing/storyboard/task-map.d.ts +21 -0
- package/dist/lib/testing/storyboard/task-map.d.ts.map +1 -0
- package/dist/lib/testing/storyboard/task-map.js +84 -0
- package/dist/lib/testing/storyboard/task-map.js.map +1 -0
- package/dist/lib/testing/storyboard/types.d.ts +156 -0
- package/dist/lib/testing/storyboard/types.d.ts.map +1 -0
- package/dist/lib/testing/storyboard/types.js +10 -0
- package/dist/lib/testing/storyboard/types.js.map +1 -0
- package/dist/lib/testing/storyboard/validations.d.ts +17 -0
- package/dist/lib/testing/storyboard/validations.d.ts.map +1 -0
- package/dist/lib/testing/storyboard/validations.js +166 -0
- package/dist/lib/testing/storyboard/validations.js.map +1 -0
- package/dist/lib/testing/types.d.ts +2 -0
- package/dist/lib/testing/types.d.ts.map +1 -1
- package/dist/lib/types/core.generated.d.ts +2 -2
- package/dist/lib/types/core.generated.d.ts.map +1 -1
- package/dist/lib/types/core.generated.js +1 -1
- package/dist/lib/types/schemas.generated.d.ts +193 -34
- package/dist/lib/types/schemas.generated.d.ts.map +1 -1
- package/dist/lib/types/schemas.generated.js +87 -5
- package/dist/lib/types/schemas.generated.js.map +1 -1
- package/dist/lib/types/tools.generated.d.ts +280 -3
- package/dist/lib/types/tools.generated.d.ts.map +1 -1
- package/dist/lib/utils/response-schemas.d.ts.map +1 -1
- package/dist/lib/utils/response-schemas.js +34 -3
- package/dist/lib/utils/response-schemas.js.map +1 -1
- package/dist/lib/utils/validate-user-agent.d.ts +8 -0
- package/dist/lib/utils/validate-user-agent.d.ts.map +1 -0
- package/dist/lib/utils/validate-user-agent.js +15 -0
- package/dist/lib/utils/validate-user-agent.js.map +1 -0
- package/dist/lib/version.d.ts +6 -0
- package/dist/lib/version.d.ts.map +1 -1
- package/dist/lib/version.js +7 -1
- package/dist/lib/version.js.map +1 -1
- package/docs/README.md +42 -0
- package/docs/guides/BUILD-AN-AGENT.md +292 -0
- package/docs/llms.txt +634 -0
- package/examples/README.md +106 -0
- package/examples/adcp.config.json +30 -0
- package/examples/basic-a2a.ts +76 -0
- package/examples/basic-mcp.ts +50 -0
- package/examples/batch-preview-test.ts +266 -0
- package/examples/conversation-client.ts +291 -0
- package/examples/debug-preview-response.ts +73 -0
- package/examples/debug-preview-with-logging.ts +50 -0
- package/examples/easy-config-demo.ts +242 -0
- package/examples/env-config.ts +51 -0
- package/examples/error-compliant-server.ts +237 -0
- package/examples/generative-creative-demo.ts +205 -0
- package/examples/inspect-card-formats.ts +161 -0
- package/examples/logger-usage.ts +165 -0
- package/examples/oauth-cli-example.ts +154 -0
- package/examples/pr78-async-patterns-demo.ts +247 -0
- package/examples/signals-agent.ts +162 -0
- package/examples/simple-getting-started.ts +225 -0
- package/examples/simple-protocol-demo.ts +75 -0
- package/examples/test-helpers-demo.ts +239 -0
- package/examples/zod-validation-example.ts +126 -0
- package/package.json +12 -2
- package/skills/adcp/SKILL.md +13 -2
- package/storyboards/audience_sync.yaml +199 -0
- package/storyboards/behavioral_analysis.yaml +244 -0
- package/storyboards/brand_rights.yaml +131 -0
- package/storyboards/creative_ad_server.yaml +171 -0
- package/storyboards/creative_sales_agent.yaml +169 -0
- package/storyboards/creative_template.yaml +306 -0
- package/storyboards/deterministic_testing.yaml +925 -0
- package/storyboards/error_compliance.yaml +231 -0
- package/storyboards/governance_content_standards.yaml +213 -0
- package/storyboards/governance_property_lists.yaml +372 -0
- package/storyboards/media_buy_catalog_creative.yaml +457 -0
- package/storyboards/media_buy_governance_escalation.yaml +467 -0
- package/storyboards/media_buy_guaranteed_approval.yaml +396 -0
- package/storyboards/media_buy_non_guaranteed.yaml +288 -0
- package/storyboards/media_buy_proposal_mode.yaml +369 -0
- package/storyboards/media_buy_seller.yaml +560 -0
- package/storyboards/media_buy_state_machine.yaml +254 -0
- package/storyboards/schema.yaml +65 -0
- package/storyboards/schema_validation.yaml +166 -0
- package/storyboards/si_session.yaml +384 -0
- package/storyboards/signal_marketplace.yaml +283 -0
- 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 };
|