@silvana-one/coordination 1.0.31 → 1.0.33

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/src/agent.ts CHANGED
@@ -77,15 +77,19 @@ export class AgentRegistry {
77
77
  this.registry = params.registry;
78
78
  }
79
79
 
80
- static createAgentRegistry(params: { name: string }): Transaction {
81
- console.log("Creating agent registry", params.name);
82
- const transaction = new Transaction();
83
- transaction.moveCall({
80
+ static createAgentRegistry(params: {
81
+ name: string;
82
+ transaction?: Transaction;
83
+ }): Transaction {
84
+ const { name, transaction } = params;
85
+ console.log("Creating agent registry", name);
86
+ const tx = transaction ?? new Transaction();
87
+ tx.moveCall({
84
88
  target: `${silvanaRegistryPackage}::registry::create_registry`,
85
- arguments: [transaction.pure.string(params.name)],
89
+ arguments: [tx.pure.string(name)],
86
90
  });
87
91
 
88
- return transaction;
92
+ return tx;
89
93
  }
90
94
 
91
95
  createDeveloper(params: {
@@ -94,9 +98,10 @@ export class AgentRegistry {
94
98
  image?: string;
95
99
  description?: string;
96
100
  site?: string;
101
+ transaction?: Transaction;
97
102
  }): Transaction {
98
- const { name, github, image, description, site } = params;
99
- const tx = new Transaction();
103
+ const { name, github, image, description, site, transaction } = params;
104
+ const tx = transaction ?? new Transaction();
100
105
 
101
106
  tx.moveCall({
102
107
  target: `${silvanaRegistryPackage}::registry::add_developer`,
@@ -120,9 +125,10 @@ export class AgentRegistry {
120
125
  image?: string;
121
126
  description?: string;
122
127
  site?: string;
128
+ transaction?: Transaction;
123
129
  }): Transaction {
124
- const { name, github, image, description, site } = params;
125
- const tx = new Transaction();
130
+ const { name, github, image, description, site, transaction } = params;
131
+ const tx = transaction ?? new Transaction();
126
132
 
127
133
  tx.moveCall({
128
134
  target: `${silvanaRegistryPackage}::registry::update_developer`,
@@ -140,9 +146,13 @@ export class AgentRegistry {
140
146
  return tx;
141
147
  }
142
148
 
143
- removeDeveloper(params: { name: string; agentNames: string[] }): Transaction {
144
- const { name, agentNames } = params;
145
- const tx = new Transaction();
149
+ removeDeveloper(params: {
150
+ name: string;
151
+ agentNames: string[];
152
+ transaction?: Transaction;
153
+ }): Transaction {
154
+ const { name, agentNames, transaction } = params;
155
+ const tx = transaction ?? new Transaction();
146
156
 
147
157
  tx.moveCall({
148
158
  target: `${silvanaRegistryPackage}::registry::remove_developer`,
@@ -164,16 +174,11 @@ export class AgentRegistry {
164
174
  description?: string;
165
175
  site?: string;
166
176
  chains: AgentChain[];
177
+ transaction?: Transaction;
167
178
  }): Transaction {
168
- const {
169
- developer,
170
- name,
171
- image,
172
- description,
173
- site,
174
- chains,
175
- } = params;
176
- const tx = new Transaction();
179
+ const { developer, name, image, description, site, chains, transaction } =
180
+ params;
181
+ const tx = transaction ?? new Transaction();
177
182
 
178
183
  tx.moveCall({
179
184
  target: `${silvanaRegistryPackage}::registry::add_agent`,
@@ -199,16 +204,11 @@ export class AgentRegistry {
199
204
  description?: string;
200
205
  site?: string;
201
206
  chains: AgentChain[];
207
+ transaction?: Transaction;
202
208
  }): Transaction {
203
- const {
204
- developer,
205
- name,
206
- image,
207
- description,
208
- site,
209
- chains,
210
- } = params;
211
- const tx = new Transaction();
209
+ const { developer, name, image, description, site, chains, transaction } =
210
+ params;
211
+ const tx = transaction ?? new Transaction();
212
212
 
213
213
  tx.moveCall({
214
214
  target: `${silvanaRegistryPackage}::registry::update_agent`,
@@ -227,9 +227,13 @@ export class AgentRegistry {
227
227
  return tx;
228
228
  }
229
229
 
230
- removeAgent(params: { developer: string; agent: string }): Transaction {
231
- const { developer, agent } = params;
232
- const tx = new Transaction();
230
+ removeAgent(params: {
231
+ developer: string;
232
+ agent: string;
233
+ transaction?: Transaction;
234
+ }): Transaction {
235
+ const { developer, agent, transaction } = params;
236
+ const tx = transaction ?? new Transaction();
233
237
 
234
238
  tx.moveCall({
235
239
  target: `${silvanaRegistryPackage}::registry::remove_agent`,
@@ -253,6 +257,7 @@ export class AgentRegistry {
253
257
  minMemoryGb: number;
254
258
  minCpuCores: number;
255
259
  requiresTee: boolean;
260
+ transaction?: Transaction;
256
261
  }): Transaction {
257
262
  const {
258
263
  developer,
@@ -263,8 +268,9 @@ export class AgentRegistry {
263
268
  minMemoryGb,
264
269
  minCpuCores,
265
270
  requiresTee,
271
+ transaction,
266
272
  } = params;
267
- const tx = new Transaction();
273
+ const tx = transaction ?? new Transaction();
268
274
 
269
275
  tx.moveCall({
270
276
  target: `${silvanaRegistryPackage}::registry::add_method`,
@@ -294,6 +300,7 @@ export class AgentRegistry {
294
300
  minMemoryGb: number;
295
301
  minCpuCores: number;
296
302
  requiresTee: boolean;
303
+ transaction?: Transaction;
297
304
  }): Transaction {
298
305
  const {
299
306
  developer,
@@ -304,8 +311,9 @@ export class AgentRegistry {
304
311
  minMemoryGb,
305
312
  minCpuCores,
306
313
  requiresTee,
314
+ transaction,
307
315
  } = params;
308
- const tx = new Transaction();
316
+ const tx = transaction ?? new Transaction();
309
317
 
310
318
  tx.moveCall({
311
319
  target: `${silvanaRegistryPackage}::registry::update_method`,
@@ -330,9 +338,10 @@ export class AgentRegistry {
330
338
  developer: string;
331
339
  agent: string;
332
340
  method: string;
341
+ transaction?: Transaction;
333
342
  }): Transaction {
334
- const { developer, agent, method } = params;
335
- const tx = new Transaction();
343
+ const { developer, agent, method, transaction } = params;
344
+ const tx = transaction ?? new Transaction();
336
345
 
337
346
  tx.moveCall({
338
347
  target: `${silvanaRegistryPackage}::registry::remove_method`,
@@ -348,13 +357,80 @@ export class AgentRegistry {
348
357
  return tx;
349
358
  }
350
359
 
360
+ addMethodToApp(params: {
361
+ appName: string;
362
+ methodName: string;
363
+ description?: string;
364
+ developerName: string;
365
+ agentName: string;
366
+ agentMethod: string;
367
+ transaction?: Transaction;
368
+ }): Transaction {
369
+ const {
370
+ appName,
371
+ methodName,
372
+ description,
373
+ developerName,
374
+ agentName,
375
+ agentMethod,
376
+ transaction,
377
+ } = params;
378
+ const tx = transaction ?? new Transaction();
379
+
380
+ // Create the app method using app_method::new
381
+ const appMethod = tx.moveCall({
382
+ target: `${silvanaRegistryPackage}::app_method::new`,
383
+ arguments: [
384
+ tx.pure.option("string", description ?? null),
385
+ tx.pure.string(developerName),
386
+ tx.pure.string(agentName),
387
+ tx.pure.string(agentMethod),
388
+ ],
389
+ });
390
+
391
+ // Add the method to the app
392
+ tx.moveCall({
393
+ target: `${silvanaRegistryPackage}::registry::add_method_to_app`,
394
+ arguments: [
395
+ tx.object(this.registry),
396
+ tx.pure.string(appName),
397
+ tx.pure.string(methodName),
398
+ appMethod,
399
+ ],
400
+ });
401
+
402
+ return tx;
403
+ }
404
+
405
+ addMetadata(params: {
406
+ appInstanceId: string;
407
+ key: string;
408
+ value: string;
409
+ transaction?: Transaction;
410
+ }): Transaction {
411
+ const { appInstanceId, key, value, transaction } = params;
412
+ const tx = transaction ?? new Transaction();
413
+
414
+ tx.moveCall({
415
+ target: `${silvanaRegistryPackage}::app_instance::add_metadata`,
416
+ arguments: [
417
+ tx.object(appInstanceId),
418
+ tx.pure.string(key),
419
+ tx.pure.string(value),
420
+ ],
421
+ });
422
+
423
+ return tx;
424
+ }
425
+
351
426
  setDefaultMethod(params: {
352
427
  developer: string;
353
428
  agent: string;
354
429
  method: string;
430
+ transaction?: Transaction;
355
431
  }): Transaction {
356
- const { developer, agent, method } = params;
357
- const tx = new Transaction();
432
+ const { developer, agent, method, transaction } = params;
433
+ const tx = transaction ?? new Transaction();
358
434
 
359
435
  tx.moveCall({
360
436
  target: `${silvanaRegistryPackage}::registry::set_default_method`,
@@ -373,9 +449,10 @@ export class AgentRegistry {
373
449
  removeDefaultMethod(params: {
374
450
  developer: string;
375
451
  agent: string;
452
+ transaction?: Transaction;
376
453
  }): Transaction {
377
- const { developer, agent } = params;
378
- const tx = new Transaction();
454
+ const { developer, agent, transaction } = params;
455
+ const tx = transaction ?? new Transaction();
379
456
 
380
457
  tx.moveCall({
381
458
  target: `${silvanaRegistryPackage}::registry::remove_default_method`,
@@ -489,7 +566,7 @@ export class AgentRegistry {
489
566
  if (!agentObject) {
490
567
  return undefined;
491
568
  }
492
-
569
+
493
570
  // Parse methods from VecMap structure
494
571
  const methods: Record<string, AgentMethod> = {};
495
572
  const methodsData = (agentObject as any)?.methods?.fields?.contents;
@@ -508,11 +585,15 @@ export class AgentRegistry {
508
585
  }
509
586
  }
510
587
  }
511
-
588
+
512
589
  // Parse default method if it exists
513
590
  let defaultMethod: AgentMethod | undefined;
514
591
  const defaultMethodData = (agentObject as any)?.default_method;
515
- if (defaultMethodData && typeof defaultMethodData === 'object' && !Array.isArray(defaultMethodData)) {
592
+ if (
593
+ defaultMethodData &&
594
+ typeof defaultMethodData === "object" &&
595
+ !Array.isArray(defaultMethodData)
596
+ ) {
516
597
  defaultMethod = {
517
598
  dockerImage: defaultMethodData.docker_image,
518
599
  dockerSha256: defaultMethodData.docker_sha256 ?? undefined,
@@ -521,7 +602,7 @@ export class AgentRegistry {
521
602
  requiresTee: Boolean(defaultMethodData.requires_tee),
522
603
  };
523
604
  }
524
-
605
+
525
606
  const agent = {
526
607
  id: (agentObject as any)?.id?.id,
527
608
  name: (agentObject as any).name,
@@ -535,12 +616,12 @@ export class AgentRegistry {
535
616
  updatedAt: Number((agentObject as any).updated_at),
536
617
  version: Number((agentObject as any).version),
537
618
  };
538
-
619
+
539
620
  // Only check for essential fields
540
621
  if (!agent.id || !agent.name) {
541
622
  return undefined;
542
623
  }
543
-
624
+
544
625
  return agent as Agent;
545
626
  }
546
627
 
package/src/balance.ts ADDED
@@ -0,0 +1,29 @@
1
+ import { CoinBalance } from "@mysten/sui/client";
2
+ import { suiClient } from "@silvana-one/coordination";
3
+ import { MIST_PER_SUI } from "@mysten/sui/utils";
4
+ import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
5
+
6
+ export function suiBalance(balance: CoinBalance): number {
7
+ return Number.parseInt(balance.totalBalance) / Number(MIST_PER_SUI);
8
+ }
9
+
10
+ export async function getSuiBalance(address: string): Promise<number> {
11
+ try {
12
+ const balance = await suiClient.getBalance({
13
+ owner: address,
14
+ coinType: "0x2::sui::SUI",
15
+ });
16
+ return suiBalance(balance);
17
+ } catch (error: any) {
18
+ console.error("getSuiBalance error:", error?.message);
19
+ return 0;
20
+ }
21
+ }
22
+
23
+ export async function getSuiAddress(params: {
24
+ secretKey: string;
25
+ }): Promise<string> {
26
+ return Ed25519Keypair.fromSecretKey(params.secretKey)
27
+ .getPublicKey()
28
+ .toSuiAddress();
29
+ }
package/src/index.ts CHANGED
@@ -16,3 +16,5 @@ export * from "./job.js";
16
16
  export * from "./app_instance.js";
17
17
  export * from "./package.js";
18
18
  export * from "./test.js";
19
+ export * from "./balance.js";
20
+ export * from "./state.js";
package/src/state.ts ADDED
@@ -0,0 +1,37 @@
1
+ import {
2
+ fetchSuiDynamicFieldsList,
3
+ fetchSuiObject,
4
+ suiClient,
5
+ } from "@silvana-one/coordination";
6
+
7
+ export async function getState(
8
+ params: { appInstanceID?: string } = {}
9
+ ): Promise<bigint[]> {
10
+ const { appInstanceID = process.env.APP_INSTANCE_ID } = params;
11
+ if (!appInstanceID) {
12
+ throw new Error("APP_INSTANCE_ID is not set");
13
+ }
14
+ // Get the AppInstance object
15
+ const appInstance = await fetchSuiObject(appInstanceID);
16
+ if (appInstance?.data?.content?.dataType !== "moveObject")
17
+ throw new Error("AppInstance not found");
18
+
19
+ // The state is inside the AppInstance
20
+ const stateObjectID = (appInstance?.data?.content?.fields as any).state.fields
21
+ .state.fields.id.id;
22
+ const state: bigint[] = [];
23
+ const fields = await fetchSuiDynamicFieldsList(stateObjectID);
24
+ const names = fields.data.map((field) => field.name);
25
+
26
+ for (const name of names) {
27
+ const element = await suiClient.getDynamicFieldObject({
28
+ parentId: stateObjectID,
29
+ name,
30
+ });
31
+ if (element.data?.content?.dataType !== "moveObject")
32
+ throw new Error("Element not found");
33
+ const value = BigInt((element.data?.content.fields as any).state[0]);
34
+ state.push(value);
35
+ }
36
+ return state;
37
+ }