Skip to content

Commit 2a29e92

Browse files
authored
feat: fix examples (#27)
1 parent 026342d commit 2a29e92

18 files changed

Lines changed: 638 additions & 156 deletions

File tree

examples/all_providers.rs

Lines changed: 220 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,25 @@ async fn demo_http() -> Result<()> {
7373

7474
println!(" ▶️ HTTP -> {url}");
7575
let client = common::client_from_providers(json!({
76-
"manual_call_templates": [{
77-
"call_template_type": "http",
78-
"name": "http_demo",
79-
"url": url,
80-
"http_method": "POST"
76+
"manual_version": "1.0.0",
77+
"utcp_version": "0.3.0",
78+
"allowed_communication_protocols": ["http"],
79+
"info": {
80+
"title": "HTTP Demo",
81+
"version": "1.0.0",
82+
"description": "HTTP Demo Manual"
83+
},
84+
"tools": [{
85+
"name": "echo",
86+
"description": "HTTP echo tool",
87+
"inputs": { "type": "object" },
88+
"outputs": { "type": "object" },
89+
"tool_call_template": {
90+
"call_template_type": "http",
91+
"name": "http_demo",
92+
"url": url,
93+
"http_method": "POST"
94+
}
8195
}]
8296
}))
8397
.await?;
@@ -96,10 +110,24 @@ async fn demo_cli() -> Result<()> {
96110
};
97111
println!(" ▶️ CLI -> {cmd}");
98112
let client = common::client_from_providers(json!({
99-
"manual_call_templates": [{
100-
"call_template_type": "cli",
101-
"name": "cli_demo",
102-
"command": cmd
113+
"manual_version": "1.0.0",
114+
"utcp_version": "0.3.0",
115+
"allowed_communication_protocols": ["cli"],
116+
"info": {
117+
"title": "CLI Demo",
118+
"version": "1.0.0",
119+
"description": "CLI Demo Manual"
120+
},
121+
"tools": [{
122+
"name": "echo",
123+
"description": "CLI echo tool",
124+
"inputs": { "type": "object" },
125+
"outputs": { "type": "object" },
126+
"tool_call_template": {
127+
"call_template_type": "cli",
128+
"name": "cli_demo",
129+
"command": cmd
130+
}
103131
}]
104132
}))
105133
.await?;
@@ -118,10 +146,24 @@ async fn demo_websocket() -> Result<()> {
118146
};
119147
println!(" ▶️ WebSocket -> {url}");
120148
let client = common::client_from_providers(json!({
121-
"manual_call_templates": [{
122-
"call_template_type": "websocket",
123-
"name": "ws_demo",
124-
"url": url
149+
"manual_version": "1.0.0",
150+
"utcp_version": "0.3.0",
151+
"allowed_communication_protocols": ["websocket"],
152+
"info": {
153+
"title": "WebSocket Demo",
154+
"version": "1.0.0",
155+
"description": "WebSocket Demo Manual"
156+
},
157+
"tools": [{
158+
"name": "echo",
159+
"description": "WebSocket echo tool",
160+
"inputs": { "type": "object" },
161+
"outputs": { "type": "object" },
162+
"tool_call_template": {
163+
"call_template_type": "websocket",
164+
"name": "ws_demo",
165+
"url": url
166+
}
125167
}]
126168
}))
127169
.await?;
@@ -140,10 +182,24 @@ async fn demo_graphql() -> Result<()> {
140182
};
141183
println!(" ▶️ GraphQL -> {url}");
142184
let client = common::client_from_providers(json!({
143-
"manual_call_templates": [{
144-
"call_template_type": "graphql",
145-
"name": "graphql_demo",
146-
"url": url
185+
"manual_version": "1.0.0",
186+
"utcp_version": "0.3.0",
187+
"allowed_communication_protocols": ["graphql"],
188+
"info": {
189+
"title": "GraphQL Demo",
190+
"version": "1.0.0",
191+
"description": "GraphQL Demo Manual"
192+
},
193+
"tools": [{
194+
"name": "hello",
195+
"description": "GraphQL hello tool",
196+
"inputs": { "type": "object" },
197+
"outputs": { "type": "object" },
198+
"tool_call_template": {
199+
"call_template_type": "graphql",
200+
"name": "graphql_demo",
201+
"url": url
202+
}
147203
}]
148204
}))
149205
.await?;
@@ -163,11 +219,25 @@ async fn demo_grpc() -> Result<()> {
163219
let port: u16 = port.parse().unwrap_or(50051);
164220
println!(" ▶️ gRPC -> {host}:{port}");
165221
let client = common::client_from_providers(json!({
166-
"manual_call_templates": [{
167-
"call_template_type": "grpc",
168-
"name": "grpc_demo",
169-
"host": host,
170-
"port": port
222+
"manual_version": "1.0.0",
223+
"utcp_version": "0.3.0",
224+
"allowed_communication_protocols": ["grpc"],
225+
"info": {
226+
"title": "gRPC Demo",
227+
"version": "1.0.0",
228+
"description": "gRPC Demo Manual"
229+
},
230+
"tools": [{
231+
"name": "echo",
232+
"description": "gRPC echo tool",
233+
"inputs": { "type": "object" },
234+
"outputs": { "type": "object" },
235+
"tool_call_template": {
236+
"call_template_type": "grpc",
237+
"name": "grpc_demo",
238+
"host": host,
239+
"port": port
240+
}
171241
}]
172242
}))
173243
.await?;
@@ -187,11 +257,25 @@ async fn demo_tcp() -> Result<()> {
187257
let (host, port) = split_host_port(&addr)?;
188258
println!(" ▶️ TCP -> {addr}");
189259
let client = common::client_from_providers(json!({
190-
"manual_call_templates": [{
191-
"call_template_type": "tcp",
192-
"name": "tcp_demo",
193-
"host": host,
194-
"port": port
260+
"manual_version": "1.0.0",
261+
"utcp_version": "0.3.0",
262+
"allowed_communication_protocols": ["tcp"],
263+
"info": {
264+
"title": "TCP Demo",
265+
"version": "1.0.0",
266+
"description": "TCP Demo Manual"
267+
},
268+
"tools": [{
269+
"name": "echo",
270+
"description": "TCP echo tool",
271+
"inputs": { "type": "object" },
272+
"outputs": { "type": "object" },
273+
"tool_call_template": {
274+
"call_template_type": "tcp",
275+
"name": "tcp_demo",
276+
"host": host,
277+
"port": port
278+
}
195279
}]
196280
}))
197281
.await?;
@@ -211,11 +295,25 @@ async fn demo_udp() -> Result<()> {
211295
let (host, port) = split_host_port(&addr)?;
212296
println!(" ▶️ UDP -> {addr}");
213297
let client = common::client_from_providers(json!({
214-
"manual_call_templates": [{
215-
"call_template_type": "udp",
216-
"name": "udp_demo",
217-
"host": host,
218-
"port": port
298+
"manual_version": "1.0.0",
299+
"utcp_version": "0.3.0",
300+
"allowed_communication_protocols": ["udp"],
301+
"info": {
302+
"title": "UDP Demo",
303+
"version": "1.0.0",
304+
"description": "UDP Demo Manual"
305+
},
306+
"tools": [{
307+
"name": "echo",
308+
"description": "UDP echo tool",
309+
"inputs": { "type": "object" },
310+
"outputs": { "type": "object" },
311+
"tool_call_template": {
312+
"call_template_type": "udp",
313+
"name": "udp_demo",
314+
"host": host,
315+
"port": port
316+
}
219317
}]
220318
}))
221319
.await?;
@@ -234,10 +332,24 @@ async fn demo_sse() -> Result<()> {
234332
};
235333
println!(" ▶️ SSE -> {url}");
236334
let client = common::client_from_providers(json!({
237-
"manual_call_templates": [{
238-
"call_template_type": "sse",
239-
"name": "sse_demo",
240-
"url": url
335+
"manual_version": "1.0.0",
336+
"utcp_version": "0.3.0",
337+
"allowed_communication_protocols": ["sse"],
338+
"info": {
339+
"title": "SSE Demo",
340+
"version": "1.0.0",
341+
"description": "SSE Demo Manual"
342+
},
343+
"tools": [{
344+
"name": "stream",
345+
"description": "SSE stream tool",
346+
"inputs": { "type": "object" },
347+
"outputs": { "type": "object" },
348+
"tool_call_template": {
349+
"call_template_type": "sse",
350+
"name": "sse_demo",
351+
"url": url
352+
}
241353
}]
242354
}))
243355
.await?;
@@ -258,10 +370,24 @@ async fn demo_http_stream() -> Result<()> {
258370
};
259371
println!(" ▶️ HTTP Stream -> {url}");
260372
let client = common::client_from_providers(json!({
261-
"manual_call_templates": [{
262-
"call_template_type": "http_stream",
263-
"name": "http_stream_demo",
264-
"url": url
373+
"manual_version": "1.0.0",
374+
"utcp_version": "0.3.0",
375+
"allowed_communication_protocols": ["http_stream"],
376+
"info": {
377+
"title": "HTTP Stream Demo",
378+
"version": "1.0.0",
379+
"description": "HTTP Stream Demo Manual"
380+
},
381+
"tools": [{
382+
"name": "stream",
383+
"description": "HTTP stream tool",
384+
"inputs": { "type": "object" },
385+
"outputs": { "type": "object" },
386+
"tool_call_template": {
387+
"call_template_type": "http_stream",
388+
"name": "http_stream_demo",
389+
"url": url
390+
}
265391
}]
266392
}))
267393
.await?;
@@ -284,10 +410,24 @@ async fn demo_mcp() -> Result<()> {
284410
};
285411
println!(" ▶️ MCP -> {url}");
286412
let client = common::client_from_providers(json!({
287-
"manual_call_templates": [{
288-
"call_template_type": "mcp",
289-
"name": "mcp_demo",
290-
"url": url
413+
"manual_version": "1.0.0",
414+
"utcp_version": "0.3.0",
415+
"allowed_communication_protocols": ["mcp"],
416+
"info": {
417+
"title": "MCP Demo",
418+
"version": "1.0.0",
419+
"description": "MCP Demo Manual"
420+
},
421+
"tools": [{
422+
"name": "echo",
423+
"description": "MCP echo tool",
424+
"inputs": { "type": "object" },
425+
"outputs": { "type": "object" },
426+
"tool_call_template": {
427+
"call_template_type": "mcp",
428+
"name": "mcp_demo",
429+
"url": url
430+
}
291431
}]
292432
}))
293433
.await?;
@@ -311,10 +451,24 @@ async fn demo_text() -> Result<()> {
311451
let base_path = PathBuf::from(path);
312452
println!(" ▶️ Text -> {}", base_path.display());
313453
let client = common::client_from_providers(json!({
314-
"manual_call_templates": [{
315-
"call_template_type": "text",
316-
"name": "text_demo",
317-
"base_path": base_path
454+
"manual_version": "1.0.0",
455+
"utcp_version": "0.3.0",
456+
"allowed_communication_protocols": ["text"],
457+
"info": {
458+
"title": "Text Demo",
459+
"version": "1.0.0",
460+
"description": "Text Demo Manual"
461+
},
462+
"tools": [{
463+
"name": "hello",
464+
"description": "Text hello tool",
465+
"inputs": { "type": "object" },
466+
"outputs": { "type": "object" },
467+
"tool_call_template": {
468+
"call_template_type": "text",
469+
"name": "text_demo",
470+
"base_path": base_path
471+
}
318472
}]
319473
}))
320474
.await?;
@@ -335,10 +489,24 @@ async fn demo_webrtc() -> Result<()> {
335489
};
336490
println!(" ▶️ WebRTC -> {sig}");
337491
let client = common::client_from_providers(json!({
338-
"manual_call_templates": [{
339-
"call_template_type": "webrtc",
340-
"name": "webrtc_demo",
341-
"signaling_server": sig
492+
"manual_version": "1.0.0",
493+
"utcp_version": "0.3.0",
494+
"allowed_communication_protocols": ["webrtc"],
495+
"info": {
496+
"title": "WebRTC Demo",
497+
"version": "1.0.0",
498+
"description": "WebRTC Demo Manual"
499+
},
500+
"tools": [{
501+
"name": "echo",
502+
"description": "WebRTC echo tool",
503+
"inputs": { "type": "object" },
504+
"outputs": { "type": "object" },
505+
"tool_call_template": {
506+
"call_template_type": "webrtc",
507+
"name": "webrtc_demo",
508+
"signaling_server": sig
509+
}
342510
}]
343511
}))
344512
.await?;

examples/basic_usage.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,27 @@ async fn main() -> anyhow::Result<()> {
1616
let addr = spawn_demo_server().await?;
1717
println!("Started demo HTTP provider at http://{addr}/tools");
1818

19-
// Load providers via create() factory method using a temp JSON file.
20-
// v1.0: uses manual_call_templates instead of providers
19+
// Load providers via create() factory method using a temp JSON file (manual v1.0 with tools).
2120
let client = common::client_from_providers(json!({
22-
"manual_call_templates": [{
23-
"call_template_type": "http",
24-
"name": "weather_api",
25-
"url": format!("http://{addr}/tools"),
26-
"http_method": "POST"
21+
"manual_version": "1.0.0",
22+
"utcp_version": "0.3.0",
23+
"allowed_communication_protocols": ["http"],
24+
"info": {
25+
"title": "Basic Usage Demo",
26+
"version": "1.0.0",
27+
"description": "Basic Usage Demo Manual"
28+
},
29+
"tools": [{
30+
"name": "get_current_weather",
31+
"description": "Return a mock weather payload",
32+
"inputs": { "type": "object" },
33+
"outputs": { "type": "object" },
34+
"tool_call_template": {
35+
"call_template_type": "http",
36+
"name": "weather_api",
37+
"url": format!("http://{addr}/tools"),
38+
"http_method": "POST"
39+
}
2740
}]
2841
}))
2942
.await?;

0 commit comments

Comments
 (0)