@silvana-one/coordination 1.0.32 → 1.0.34
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/dist/node/agent.d.ts +34 -1
- package/dist/node/agent.js +103 -33
- package/dist/node/agent.js.map +1 -1
- package/dist/node/index.cjs +96 -31
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsconfig.web.tsbuildinfo +1 -1
- package/dist/web/agent.d.ts +34 -1
- package/dist/web/agent.js +103 -33
- package/dist/web/agent.js.map +1 -1
- package/package.json +1 -1
- package/src/agent.ts +176 -73
package/src/agent.ts
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
import { Transaction } from "@mysten/sui/transactions";
|
|
2
2
|
import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils";
|
|
3
|
-
import {
|
|
4
|
-
fetchSuiDynamicField,
|
|
5
|
-
fetchSuiDynamicFieldsList,
|
|
6
|
-
fetchSuiObject,
|
|
7
|
-
} from "./fetch.js";
|
|
3
|
+
import { fetchSuiDynamicField, fetchSuiDynamicFieldsList } from "./fetch.js";
|
|
8
4
|
import { silvanaRegistryPackage } from "./package.js";
|
|
5
|
+
import { AppMethod } from "./app_instance.js";
|
|
9
6
|
|
|
10
7
|
type AgentChain =
|
|
11
|
-
| "ethereum
|
|
12
|
-
| "ethereum
|
|
13
|
-
| "ethereum
|
|
14
|
-
| "ethereum
|
|
15
|
-
| "mina
|
|
16
|
-
| "mina
|
|
17
|
-
| "zeko
|
|
18
|
-
| "zeko
|
|
19
|
-
| "sui
|
|
20
|
-
| "sui
|
|
21
|
-
| "sui
|
|
22
|
-
| "solana
|
|
23
|
-
| "solana
|
|
24
|
-
| "solana
|
|
25
|
-
| "
|
|
26
|
-
| "walrus
|
|
27
|
-
| "walrus-testnet"
|
|
8
|
+
| "ethereum:mainnet"
|
|
9
|
+
| "ethereum:seplolia"
|
|
10
|
+
| "ethereum:holesky"
|
|
11
|
+
| "ethereum:hoodi"
|
|
12
|
+
| "mina:mainnet"
|
|
13
|
+
| "mina:devnet"
|
|
14
|
+
| "zeko:testnet"
|
|
15
|
+
| "zeko:alphanet"
|
|
16
|
+
| "sui:mainnet"
|
|
17
|
+
| "sui:testnet"
|
|
18
|
+
| "sui:devnet"
|
|
19
|
+
| "solana:mainnet"
|
|
20
|
+
| "solana:testnet"
|
|
21
|
+
| "solana:devnet"
|
|
22
|
+
| "walrus:mainnet"
|
|
23
|
+
| "walrus:testnet"
|
|
28
24
|
| string; // other chains
|
|
29
25
|
|
|
30
26
|
export interface AgentMethod {
|
|
@@ -70,6 +66,18 @@ export interface DeveloperNames {
|
|
|
70
66
|
version: number;
|
|
71
67
|
}
|
|
72
68
|
|
|
69
|
+
export interface SilvanaApp {
|
|
70
|
+
id: string;
|
|
71
|
+
name: string;
|
|
72
|
+
description?: string;
|
|
73
|
+
methods: Record<string, AppMethod>;
|
|
74
|
+
owner: string;
|
|
75
|
+
createdAt: number;
|
|
76
|
+
updatedAt: number;
|
|
77
|
+
version: number;
|
|
78
|
+
instances: string[];
|
|
79
|
+
}
|
|
80
|
+
|
|
73
81
|
export class AgentRegistry {
|
|
74
82
|
private readonly registry: string;
|
|
75
83
|
|
|
@@ -77,15 +85,19 @@ export class AgentRegistry {
|
|
|
77
85
|
this.registry = params.registry;
|
|
78
86
|
}
|
|
79
87
|
|
|
80
|
-
static createAgentRegistry(params: {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
static createAgentRegistry(params: {
|
|
89
|
+
name: string;
|
|
90
|
+
transaction?: Transaction;
|
|
91
|
+
}): Transaction {
|
|
92
|
+
const { name, transaction } = params;
|
|
93
|
+
console.log("Creating agent registry", name);
|
|
94
|
+
const tx = transaction ?? new Transaction();
|
|
95
|
+
tx.moveCall({
|
|
84
96
|
target: `${silvanaRegistryPackage}::registry::create_registry`,
|
|
85
|
-
arguments: [
|
|
97
|
+
arguments: [tx.pure.string(name)],
|
|
86
98
|
});
|
|
87
99
|
|
|
88
|
-
return
|
|
100
|
+
return tx;
|
|
89
101
|
}
|
|
90
102
|
|
|
91
103
|
createDeveloper(params: {
|
|
@@ -94,9 +106,10 @@ export class AgentRegistry {
|
|
|
94
106
|
image?: string;
|
|
95
107
|
description?: string;
|
|
96
108
|
site?: string;
|
|
109
|
+
transaction?: Transaction;
|
|
97
110
|
}): Transaction {
|
|
98
|
-
const { name, github, image, description, site } = params;
|
|
99
|
-
const tx = new Transaction();
|
|
111
|
+
const { name, github, image, description, site, transaction } = params;
|
|
112
|
+
const tx = transaction ?? new Transaction();
|
|
100
113
|
|
|
101
114
|
tx.moveCall({
|
|
102
115
|
target: `${silvanaRegistryPackage}::registry::add_developer`,
|
|
@@ -120,9 +133,10 @@ export class AgentRegistry {
|
|
|
120
133
|
image?: string;
|
|
121
134
|
description?: string;
|
|
122
135
|
site?: string;
|
|
136
|
+
transaction?: Transaction;
|
|
123
137
|
}): Transaction {
|
|
124
|
-
const { name, github, image, description, site } = params;
|
|
125
|
-
const tx = new Transaction();
|
|
138
|
+
const { name, github, image, description, site, transaction } = params;
|
|
139
|
+
const tx = transaction ?? new Transaction();
|
|
126
140
|
|
|
127
141
|
tx.moveCall({
|
|
128
142
|
target: `${silvanaRegistryPackage}::registry::update_developer`,
|
|
@@ -140,9 +154,13 @@ export class AgentRegistry {
|
|
|
140
154
|
return tx;
|
|
141
155
|
}
|
|
142
156
|
|
|
143
|
-
removeDeveloper(params: {
|
|
144
|
-
|
|
145
|
-
|
|
157
|
+
removeDeveloper(params: {
|
|
158
|
+
name: string;
|
|
159
|
+
agentNames: string[];
|
|
160
|
+
transaction?: Transaction;
|
|
161
|
+
}): Transaction {
|
|
162
|
+
const { name, agentNames, transaction } = params;
|
|
163
|
+
const tx = transaction ?? new Transaction();
|
|
146
164
|
|
|
147
165
|
tx.moveCall({
|
|
148
166
|
target: `${silvanaRegistryPackage}::registry::remove_developer`,
|
|
@@ -164,16 +182,11 @@ export class AgentRegistry {
|
|
|
164
182
|
description?: string;
|
|
165
183
|
site?: string;
|
|
166
184
|
chains: AgentChain[];
|
|
185
|
+
transaction?: Transaction;
|
|
167
186
|
}): Transaction {
|
|
168
|
-
const {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
image,
|
|
172
|
-
description,
|
|
173
|
-
site,
|
|
174
|
-
chains,
|
|
175
|
-
} = params;
|
|
176
|
-
const tx = new Transaction();
|
|
187
|
+
const { developer, name, image, description, site, chains, transaction } =
|
|
188
|
+
params;
|
|
189
|
+
const tx = transaction ?? new Transaction();
|
|
177
190
|
|
|
178
191
|
tx.moveCall({
|
|
179
192
|
target: `${silvanaRegistryPackage}::registry::add_agent`,
|
|
@@ -199,16 +212,11 @@ export class AgentRegistry {
|
|
|
199
212
|
description?: string;
|
|
200
213
|
site?: string;
|
|
201
214
|
chains: AgentChain[];
|
|
215
|
+
transaction?: Transaction;
|
|
202
216
|
}): Transaction {
|
|
203
|
-
const {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
image,
|
|
207
|
-
description,
|
|
208
|
-
site,
|
|
209
|
-
chains,
|
|
210
|
-
} = params;
|
|
211
|
-
const tx = new Transaction();
|
|
217
|
+
const { developer, name, image, description, site, chains, transaction } =
|
|
218
|
+
params;
|
|
219
|
+
const tx = transaction ?? new Transaction();
|
|
212
220
|
|
|
213
221
|
tx.moveCall({
|
|
214
222
|
target: `${silvanaRegistryPackage}::registry::update_agent`,
|
|
@@ -227,9 +235,13 @@ export class AgentRegistry {
|
|
|
227
235
|
return tx;
|
|
228
236
|
}
|
|
229
237
|
|
|
230
|
-
removeAgent(params: {
|
|
231
|
-
|
|
232
|
-
|
|
238
|
+
removeAgent(params: {
|
|
239
|
+
developer: string;
|
|
240
|
+
agent: string;
|
|
241
|
+
transaction?: Transaction;
|
|
242
|
+
}): Transaction {
|
|
243
|
+
const { developer, agent, transaction } = params;
|
|
244
|
+
const tx = transaction ?? new Transaction();
|
|
233
245
|
|
|
234
246
|
tx.moveCall({
|
|
235
247
|
target: `${silvanaRegistryPackage}::registry::remove_agent`,
|
|
@@ -253,6 +265,7 @@ export class AgentRegistry {
|
|
|
253
265
|
minMemoryGb: number;
|
|
254
266
|
minCpuCores: number;
|
|
255
267
|
requiresTee: boolean;
|
|
268
|
+
transaction?: Transaction;
|
|
256
269
|
}): Transaction {
|
|
257
270
|
const {
|
|
258
271
|
developer,
|
|
@@ -263,8 +276,9 @@ export class AgentRegistry {
|
|
|
263
276
|
minMemoryGb,
|
|
264
277
|
minCpuCores,
|
|
265
278
|
requiresTee,
|
|
279
|
+
transaction,
|
|
266
280
|
} = params;
|
|
267
|
-
const tx = new Transaction();
|
|
281
|
+
const tx = transaction ?? new Transaction();
|
|
268
282
|
|
|
269
283
|
tx.moveCall({
|
|
270
284
|
target: `${silvanaRegistryPackage}::registry::add_method`,
|
|
@@ -294,6 +308,7 @@ export class AgentRegistry {
|
|
|
294
308
|
minMemoryGb: number;
|
|
295
309
|
minCpuCores: number;
|
|
296
310
|
requiresTee: boolean;
|
|
311
|
+
transaction?: Transaction;
|
|
297
312
|
}): Transaction {
|
|
298
313
|
const {
|
|
299
314
|
developer,
|
|
@@ -304,8 +319,9 @@ export class AgentRegistry {
|
|
|
304
319
|
minMemoryGb,
|
|
305
320
|
minCpuCores,
|
|
306
321
|
requiresTee,
|
|
322
|
+
transaction,
|
|
307
323
|
} = params;
|
|
308
|
-
const tx = new Transaction();
|
|
324
|
+
const tx = transaction ?? new Transaction();
|
|
309
325
|
|
|
310
326
|
tx.moveCall({
|
|
311
327
|
target: `${silvanaRegistryPackage}::registry::update_method`,
|
|
@@ -330,9 +346,10 @@ export class AgentRegistry {
|
|
|
330
346
|
developer: string;
|
|
331
347
|
agent: string;
|
|
332
348
|
method: string;
|
|
349
|
+
transaction?: Transaction;
|
|
333
350
|
}): Transaction {
|
|
334
|
-
const { developer, agent, method } = params;
|
|
335
|
-
const tx = new Transaction();
|
|
351
|
+
const { developer, agent, method, transaction } = params;
|
|
352
|
+
const tx = transaction ?? new Transaction();
|
|
336
353
|
|
|
337
354
|
tx.moveCall({
|
|
338
355
|
target: `${silvanaRegistryPackage}::registry::remove_method`,
|
|
@@ -355,6 +372,7 @@ export class AgentRegistry {
|
|
|
355
372
|
developerName: string;
|
|
356
373
|
agentName: string;
|
|
357
374
|
agentMethod: string;
|
|
375
|
+
transaction?: Transaction;
|
|
358
376
|
}): Transaction {
|
|
359
377
|
const {
|
|
360
378
|
appName,
|
|
@@ -363,8 +381,9 @@ export class AgentRegistry {
|
|
|
363
381
|
developerName,
|
|
364
382
|
agentName,
|
|
365
383
|
agentMethod,
|
|
384
|
+
transaction,
|
|
366
385
|
} = params;
|
|
367
|
-
const tx = new Transaction();
|
|
386
|
+
const tx = transaction ?? new Transaction();
|
|
368
387
|
|
|
369
388
|
// Create the app method using app_method::new
|
|
370
389
|
const appMethod = tx.moveCall({
|
|
@@ -395,9 +414,10 @@ export class AgentRegistry {
|
|
|
395
414
|
appInstanceId: string;
|
|
396
415
|
key: string;
|
|
397
416
|
value: string;
|
|
417
|
+
transaction?: Transaction;
|
|
398
418
|
}): Transaction {
|
|
399
|
-
const { appInstanceId, key, value } = params;
|
|
400
|
-
const tx = new Transaction();
|
|
419
|
+
const { appInstanceId, key, value, transaction } = params;
|
|
420
|
+
const tx = transaction ?? new Transaction();
|
|
401
421
|
|
|
402
422
|
tx.moveCall({
|
|
403
423
|
target: `${silvanaRegistryPackage}::app_instance::add_metadata`,
|
|
@@ -415,9 +435,10 @@ export class AgentRegistry {
|
|
|
415
435
|
developer: string;
|
|
416
436
|
agent: string;
|
|
417
437
|
method: string;
|
|
438
|
+
transaction?: Transaction;
|
|
418
439
|
}): Transaction {
|
|
419
|
-
const { developer, agent, method } = params;
|
|
420
|
-
const tx = new Transaction();
|
|
440
|
+
const { developer, agent, method, transaction } = params;
|
|
441
|
+
const tx = transaction ?? new Transaction();
|
|
421
442
|
|
|
422
443
|
tx.moveCall({
|
|
423
444
|
target: `${silvanaRegistryPackage}::registry::set_default_method`,
|
|
@@ -436,9 +457,10 @@ export class AgentRegistry {
|
|
|
436
457
|
removeDefaultMethod(params: {
|
|
437
458
|
developer: string;
|
|
438
459
|
agent: string;
|
|
460
|
+
transaction?: Transaction;
|
|
439
461
|
}): Transaction {
|
|
440
|
-
const { developer, agent } = params;
|
|
441
|
-
const tx = new Transaction();
|
|
462
|
+
const { developer, agent, transaction } = params;
|
|
463
|
+
const tx = transaction ?? new Transaction();
|
|
442
464
|
|
|
443
465
|
tx.moveCall({
|
|
444
466
|
target: `${silvanaRegistryPackage}::registry::remove_default_method`,
|
|
@@ -552,7 +574,7 @@ export class AgentRegistry {
|
|
|
552
574
|
if (!agentObject) {
|
|
553
575
|
return undefined;
|
|
554
576
|
}
|
|
555
|
-
|
|
577
|
+
|
|
556
578
|
// Parse methods from VecMap structure
|
|
557
579
|
const methods: Record<string, AgentMethod> = {};
|
|
558
580
|
const methodsData = (agentObject as any)?.methods?.fields?.contents;
|
|
@@ -571,11 +593,15 @@ export class AgentRegistry {
|
|
|
571
593
|
}
|
|
572
594
|
}
|
|
573
595
|
}
|
|
574
|
-
|
|
596
|
+
|
|
575
597
|
// Parse default method if it exists
|
|
576
598
|
let defaultMethod: AgentMethod | undefined;
|
|
577
599
|
const defaultMethodData = (agentObject as any)?.default_method;
|
|
578
|
-
if (
|
|
600
|
+
if (
|
|
601
|
+
defaultMethodData &&
|
|
602
|
+
typeof defaultMethodData === "object" &&
|
|
603
|
+
!Array.isArray(defaultMethodData)
|
|
604
|
+
) {
|
|
579
605
|
defaultMethod = {
|
|
580
606
|
dockerImage: defaultMethodData.docker_image,
|
|
581
607
|
dockerSha256: defaultMethodData.docker_sha256 ?? undefined,
|
|
@@ -584,7 +610,7 @@ export class AgentRegistry {
|
|
|
584
610
|
requiresTee: Boolean(defaultMethodData.requires_tee),
|
|
585
611
|
};
|
|
586
612
|
}
|
|
587
|
-
|
|
613
|
+
|
|
588
614
|
const agent = {
|
|
589
615
|
id: (agentObject as any)?.id?.id,
|
|
590
616
|
name: (agentObject as any).name,
|
|
@@ -598,15 +624,92 @@ export class AgentRegistry {
|
|
|
598
624
|
updatedAt: Number((agentObject as any).updated_at),
|
|
599
625
|
version: Number((agentObject as any).version),
|
|
600
626
|
};
|
|
601
|
-
|
|
627
|
+
|
|
602
628
|
// Only check for essential fields
|
|
603
629
|
if (!agent.id || !agent.name) {
|
|
604
630
|
return undefined;
|
|
605
631
|
}
|
|
606
|
-
|
|
632
|
+
|
|
607
633
|
return agent as Agent;
|
|
608
634
|
}
|
|
609
635
|
|
|
636
|
+
async getApp(params: { name: string }): Promise<SilvanaApp | undefined> {
|
|
637
|
+
const appObject = await fetchSuiDynamicField({
|
|
638
|
+
objectID: this.registry,
|
|
639
|
+
fieldName: "apps",
|
|
640
|
+
type: "0x1::string::String",
|
|
641
|
+
key: params.name,
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
if (!appObject) {
|
|
645
|
+
return undefined;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// Parse methods from VecMap structure
|
|
649
|
+
const methods: Record<string, AppMethod> = {};
|
|
650
|
+
const methodsData = (appObject as any)?.methods?.fields?.contents;
|
|
651
|
+
if (methodsData && Array.isArray(methodsData)) {
|
|
652
|
+
for (const entry of methodsData) {
|
|
653
|
+
const key = entry?.fields?.key;
|
|
654
|
+
const value = entry?.fields?.value;
|
|
655
|
+
if (key && value) {
|
|
656
|
+
methods[key] = {
|
|
657
|
+
description: value.description ?? undefined,
|
|
658
|
+
developer: value.developer,
|
|
659
|
+
agent: value.agent,
|
|
660
|
+
agentMethod: value.agent_method,
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// Parse instances from VecSet structure
|
|
667
|
+
const instances: string[] = [];
|
|
668
|
+
const instancesData = (appObject as any)?.instances?.fields?.contents;
|
|
669
|
+
if (instancesData && Array.isArray(instancesData)) {
|
|
670
|
+
for (const instance of instancesData) {
|
|
671
|
+
if (instance?.fields?.key) {
|
|
672
|
+
instances.push(instance.fields.key);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
const app = {
|
|
678
|
+
id: (appObject as any)?.id?.id,
|
|
679
|
+
name: (appObject as any).name,
|
|
680
|
+
description: (appObject as any)?.description ?? undefined,
|
|
681
|
+
methods,
|
|
682
|
+
owner: (appObject as any).owner,
|
|
683
|
+
createdAt: Number((appObject as any).created_at),
|
|
684
|
+
updatedAt: Number((appObject as any).updated_at),
|
|
685
|
+
version: Number((appObject as any).version),
|
|
686
|
+
instances,
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
// Check for essential fields
|
|
690
|
+
if (!app.id || !app.name || !app.owner) {
|
|
691
|
+
return undefined;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
return app as SilvanaApp;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
removeApp(params: { name: string; transaction?: Transaction }): Transaction {
|
|
698
|
+
const { name, transaction } = params;
|
|
699
|
+
const tx = transaction ?? new Transaction();
|
|
700
|
+
|
|
701
|
+
tx.moveCall({
|
|
702
|
+
target: `${silvanaRegistryPackage}::registry::remove_app`,
|
|
703
|
+
arguments: [
|
|
704
|
+
tx.object(this.registry),
|
|
705
|
+
tx.pure.string(name),
|
|
706
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
707
|
+
],
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
return tx;
|
|
711
|
+
}
|
|
712
|
+
|
|
610
713
|
static async getDockerImageDetails(params: { dockerImage: string }): Promise<
|
|
611
714
|
| {
|
|
612
715
|
sha256: string;
|