-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
144 lines (132 loc) · 3.55 KB
/
Copy pathexample.js
File metadata and controls
144 lines (132 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright AGNTCY Contributors (https://github.com/agntcy)
// SPDX-License-Identifier: Apache-2.0
import { Client, Config, models } from "agntcy-dir";
function generateRecords(names) {
return names.map((name) =>
JSON.parse(`
{
"data": {
"name": "${name}",
"version": "v1.0.0",
"schema_version": "0.8.0",
"description": "My example agent",
"authors": ["AGNTCY"],
"created_at": "2025-03-19T17:06:37Z",
"skills": [
{
"name": "natural_language_processing/natural_language_generation/text_completion",
"id": 10201
},
{
"name": "natural_language_processing/analytical_reasoning/problem_solving",
"id": 10702
}
],
"locators": [
{
"type": "docker_image",
"url": "https://ghcr.io/agntcy/marketing-strategy"
}
],
"domains": [
{
"name": "technology/networking",
"id": 103
}
],
"modules": [
{
"name": "integration/a2a",
"id": 203,
"data": {
"protocol_version": "lightweight orchestra moral",
"card_data": "centres",
"capabilities": [
"state_transition_history",
"push_notifications"
],
"transports": [
"grpc",
"http"
],
"output_modes": [
"text/html"
]
}
}
]
}
}
`),
);
}
(async () => {
// Create client
const config = Config.loadFromEnv();
let t = await Client.createGRPCTransport(config);
const client = new Client(config, t);
// Create record objects
const records = generateRecords(["example-record", "example-record2"]);
// Push objects
const pushed_refs = await client.push(records);
pushed_refs.forEach((ref) => {
console.log("Pushed object ref:", ref);
});
// Pull objects
const pulled_records = await client.pull(pushed_refs);
pulled_records.forEach((pulled_record) => {
console.log("Pulled object:", pulled_record);
});
// Lookup objects
const metadatas = await client.lookup(pushed_refs);
metadatas.forEach((metadata) => {
console.log("Lookup result:", metadata);
});
// Search objects
const search_response = await client.searchCIDs({
queries: [
{
type: models.search_v1.RecordQueryType.SKILL_ID,
value: "10201",
},
],
limit: 3,
});
console.log("Search result:", search_response);
// Publish objects
await client.publish({
request: {
case: "recordRefs",
value: {
refs: pushed_refs,
},
},
});
console.log("Objects published.");
// List objects in the routing table
const list_response = await client.list({
queries: [
{
type: models.routing_v1.RecordQueryType.SKILL,
value:
"natural_language_processing/analytical_reasoning/problem_solving",
},
],
});
list_response.forEach((r) => {
console.log("Listed objects:", r);
});
// Unpublish objects
await client.unpublish({
request: {
case: "recordRefs",
value: {
refs: pushed_refs,
},
},
});
console.log("Objects unpublished.");
// Delete objects
await client.delete(pushed_refs);
console.log("Objects deleted.");
})();