@silvana-one/coordination 1.0.25 → 1.0.26
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 +43 -15
- package/dist/node/agent.js +129 -31
- package/dist/node/agent.js.map +1 -1
- package/dist/node/app_instance.d.ts +58 -0
- package/dist/node/app_instance.js +203 -0
- package/dist/node/app_instance.js.map +1 -0
- package/dist/node/execute.d.ts +1 -0
- package/dist/node/execute.js +10 -2
- package/dist/node/execute.js.map +1 -1
- package/dist/node/index.cjs +750 -27
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.js +4 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/job.d.ts +57 -0
- package/dist/node/job.js +168 -0
- package/dist/node/job.js.map +1 -0
- package/dist/node/package.d.ts +1 -0
- package/dist/node/package.js +6 -0
- package/dist/node/package.js.map +1 -0
- package/dist/node/test.d.ts +48 -0
- package/dist/node/test.js +278 -0
- package/dist/node/test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsconfig.web.tsbuildinfo +1 -1
- package/dist/web/agent.d.ts +43 -15
- package/dist/web/agent.js +129 -31
- package/dist/web/agent.js.map +1 -1
- package/dist/web/app_instance.d.ts +58 -0
- package/dist/web/app_instance.js +203 -0
- package/dist/web/app_instance.js.map +1 -0
- package/dist/web/execute.d.ts +1 -0
- package/dist/web/execute.js +10 -2
- package/dist/web/execute.js.map +1 -1
- package/dist/web/index.d.ts +4 -0
- package/dist/web/index.js +4 -0
- package/dist/web/index.js.map +1 -1
- package/dist/web/job.d.ts +57 -0
- package/dist/web/job.js +168 -0
- package/dist/web/job.js.map +1 -0
- package/dist/web/package.d.ts +1 -0
- package/dist/web/package.js +6 -0
- package/dist/web/package.js.map +1 -0
- package/dist/web/test.d.ts +48 -0
- package/dist/web/test.js +278 -0
- package/dist/web/test.js.map +1 -0
- package/package.json +5 -3
- package/src/agent.ts +204 -56
- package/src/app_instance.ts +264 -0
- package/src/execute.ts +11 -2
- package/src/index.ts +4 -0
- package/src/job.ts +223 -0
- package/src/package.ts +6 -0
- package/src/test.ts +383 -0
package/dist/node/index.cjs
CHANGED
|
@@ -31,6 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
AgentRegistry: () => AgentRegistry,
|
|
34
|
+
AppInstanceManager: () => AppInstanceManager,
|
|
35
|
+
JobManager: () => JobManager,
|
|
34
36
|
buildMovePackage: () => buildMovePackage,
|
|
35
37
|
buildPublishTx: () => buildPublishTx,
|
|
36
38
|
buildUpgradeTx: () => buildUpgradeTx,
|
|
@@ -39,6 +41,8 @@ __export(index_exports, {
|
|
|
39
41
|
convertMinaPublicKeyToFields: () => convertMinaPublicKeyToFields,
|
|
40
42
|
convertMinaSignatureFromBase58: () => convertMinaSignatureFromBase58,
|
|
41
43
|
convertMinaSignatureToBase58: () => convertMinaSignatureToBase58,
|
|
44
|
+
createTestApp: () => createTestApp,
|
|
45
|
+
createTestRegistry: () => createTestRegistry,
|
|
42
46
|
executeTx: () => executeTx,
|
|
43
47
|
fetchSuiDynamicField: () => fetchSuiDynamicField,
|
|
44
48
|
fetchSuiDynamicFieldsList: () => fetchSuiDynamicFieldsList,
|
|
@@ -58,6 +62,7 @@ __export(index_exports, {
|
|
|
58
62
|
silvanaFaucetGetKey: () => silvanaFaucetGetKey,
|
|
59
63
|
silvanaFaucetPingKey: () => silvanaFaucetPingKey,
|
|
60
64
|
silvanaFaucetReturnKey: () => silvanaFaucetReturnKey,
|
|
65
|
+
silvanaRegistryPackage: () => silvanaRegistryPackage,
|
|
61
66
|
sleep: () => sleep,
|
|
62
67
|
suiClient: () => suiClient,
|
|
63
68
|
u256ToFields: () => u256ToFields,
|
|
@@ -442,10 +447,17 @@ async function executeTx(params) {
|
|
|
442
447
|
await releaseLock({ address, id: lockId });
|
|
443
448
|
}
|
|
444
449
|
if (executedTx?.effects?.status?.status === "failure") {
|
|
450
|
+
const errorMessage = executedTx?.effects?.status?.error || "Unknown error";
|
|
445
451
|
if (showErrors) {
|
|
446
|
-
console.log(`Errors for tx ${executedTx.digest}:`,
|
|
447
|
-
throw new Error(`tx execution failed: ${executedTx.digest}`);
|
|
452
|
+
console.log(`Errors for tx ${executedTx.digest}:`, errorMessage);
|
|
448
453
|
}
|
|
454
|
+
return {
|
|
455
|
+
tx: executedTx,
|
|
456
|
+
digest: executedTx.digest,
|
|
457
|
+
events: executedTx?.events?.[0]?.parsedJson,
|
|
458
|
+
executeTime: end - start,
|
|
459
|
+
error: errorMessage
|
|
460
|
+
};
|
|
449
461
|
}
|
|
450
462
|
return {
|
|
451
463
|
tx: executedTx,
|
|
@@ -641,6 +653,9 @@ async function fetchSuiDynamicField(params) {
|
|
|
641
653
|
}
|
|
642
654
|
}
|
|
643
655
|
|
|
656
|
+
// dist/node/package.js
|
|
657
|
+
var silvanaRegistryPackage = process.env.SILVANA_REGISTRY_PACKAGE ?? process.env.NEXT_PUBLIC_SILVANA_REGISTRY_PACKAGE ?? "@silvana/agent";
|
|
658
|
+
|
|
644
659
|
// dist/node/agent.js
|
|
645
660
|
var AgentRegistry = class {
|
|
646
661
|
constructor(params) {
|
|
@@ -650,7 +665,7 @@ var AgentRegistry = class {
|
|
|
650
665
|
console.log("Creating agent registry", params.name);
|
|
651
666
|
const transaction = new import_transactions6.Transaction();
|
|
652
667
|
transaction.moveCall({
|
|
653
|
-
target:
|
|
668
|
+
target: `${silvanaRegistryPackage}::registry::create_registry`,
|
|
654
669
|
arguments: [transaction.pure.string(params.name)]
|
|
655
670
|
});
|
|
656
671
|
return transaction;
|
|
@@ -659,7 +674,7 @@ var AgentRegistry = class {
|
|
|
659
674
|
const { name, github, image, description, site } = params;
|
|
660
675
|
const tx = new import_transactions6.Transaction();
|
|
661
676
|
tx.moveCall({
|
|
662
|
-
target:
|
|
677
|
+
target: `${silvanaRegistryPackage}::registry::add_developer`,
|
|
663
678
|
arguments: [
|
|
664
679
|
tx.object(this.registry),
|
|
665
680
|
tx.pure.string(name),
|
|
@@ -676,7 +691,7 @@ var AgentRegistry = class {
|
|
|
676
691
|
const { name, github, image, description, site } = params;
|
|
677
692
|
const tx = new import_transactions6.Transaction();
|
|
678
693
|
tx.moveCall({
|
|
679
|
-
target:
|
|
694
|
+
target: `${silvanaRegistryPackage}::registry::update_developer`,
|
|
680
695
|
arguments: [
|
|
681
696
|
tx.object(this.registry),
|
|
682
697
|
tx.pure.string(name),
|
|
@@ -693,7 +708,7 @@ var AgentRegistry = class {
|
|
|
693
708
|
const { name, agentNames } = params;
|
|
694
709
|
const tx = new import_transactions6.Transaction();
|
|
695
710
|
tx.moveCall({
|
|
696
|
-
target:
|
|
711
|
+
target: `${silvanaRegistryPackage}::registry::remove_developer`,
|
|
697
712
|
arguments: [
|
|
698
713
|
tx.object(this.registry),
|
|
699
714
|
tx.pure.string(name),
|
|
@@ -704,10 +719,10 @@ var AgentRegistry = class {
|
|
|
704
719
|
return tx;
|
|
705
720
|
}
|
|
706
721
|
createAgent(params) {
|
|
707
|
-
const { developer, name, image, description, site,
|
|
722
|
+
const { developer, name, image, description, site, chains } = params;
|
|
708
723
|
const tx = new import_transactions6.Transaction();
|
|
709
724
|
tx.moveCall({
|
|
710
|
-
target:
|
|
725
|
+
target: `${silvanaRegistryPackage}::registry::add_agent`,
|
|
711
726
|
arguments: [
|
|
712
727
|
tx.object(this.registry),
|
|
713
728
|
tx.pure.string(developer),
|
|
@@ -715,11 +730,6 @@ var AgentRegistry = class {
|
|
|
715
730
|
tx.pure.option("string", image ?? null),
|
|
716
731
|
tx.pure.option("string", description ?? null),
|
|
717
732
|
tx.pure.option("string", site ?? null),
|
|
718
|
-
tx.pure.string(docker_image),
|
|
719
|
-
tx.pure.option("string", docker_sha256 ?? null),
|
|
720
|
-
tx.pure.u16(min_memory_gb),
|
|
721
|
-
tx.pure.u16(min_cpu_cores),
|
|
722
|
-
tx.pure.bool(supports_tee),
|
|
723
733
|
tx.pure.vector("string", chains),
|
|
724
734
|
tx.object(import_utils.SUI_CLOCK_OBJECT_ID)
|
|
725
735
|
]
|
|
@@ -727,10 +737,10 @@ var AgentRegistry = class {
|
|
|
727
737
|
return tx;
|
|
728
738
|
}
|
|
729
739
|
updateAgent(params) {
|
|
730
|
-
const { developer, name, image, description, site,
|
|
740
|
+
const { developer, name, image, description, site, chains } = params;
|
|
731
741
|
const tx = new import_transactions6.Transaction();
|
|
732
742
|
tx.moveCall({
|
|
733
|
-
target:
|
|
743
|
+
target: `${silvanaRegistryPackage}::registry::update_agent`,
|
|
734
744
|
arguments: [
|
|
735
745
|
tx.object(this.registry),
|
|
736
746
|
tx.pure.string(developer),
|
|
@@ -738,11 +748,6 @@ var AgentRegistry = class {
|
|
|
738
748
|
tx.pure.option("string", image ?? null),
|
|
739
749
|
tx.pure.option("string", description ?? null),
|
|
740
750
|
tx.pure.option("string", site ?? null),
|
|
741
|
-
tx.pure.string(docker_image),
|
|
742
|
-
tx.pure.option("string", docker_sha256 ?? null),
|
|
743
|
-
tx.pure.u16(min_memory_gb),
|
|
744
|
-
tx.pure.u16(min_cpu_cores),
|
|
745
|
-
tx.pure.bool(supports_tee),
|
|
746
751
|
tx.pure.vector("string", chains),
|
|
747
752
|
tx.object(import_utils.SUI_CLOCK_OBJECT_ID)
|
|
748
753
|
]
|
|
@@ -753,7 +758,91 @@ var AgentRegistry = class {
|
|
|
753
758
|
const { developer, agent } = params;
|
|
754
759
|
const tx = new import_transactions6.Transaction();
|
|
755
760
|
tx.moveCall({
|
|
756
|
-
target:
|
|
761
|
+
target: `${silvanaRegistryPackage}::registry::remove_agent`,
|
|
762
|
+
arguments: [
|
|
763
|
+
tx.object(this.registry),
|
|
764
|
+
tx.pure.string(developer),
|
|
765
|
+
tx.pure.string(agent),
|
|
766
|
+
tx.object(import_utils.SUI_CLOCK_OBJECT_ID)
|
|
767
|
+
]
|
|
768
|
+
});
|
|
769
|
+
return tx;
|
|
770
|
+
}
|
|
771
|
+
addAgentMethod(params) {
|
|
772
|
+
const { developer, agent, method, dockerImage, dockerSha256, minMemoryGb, minCpuCores, requiresTee } = params;
|
|
773
|
+
const tx = new import_transactions6.Transaction();
|
|
774
|
+
tx.moveCall({
|
|
775
|
+
target: `${silvanaRegistryPackage}::registry::add_method`,
|
|
776
|
+
arguments: [
|
|
777
|
+
tx.object(this.registry),
|
|
778
|
+
tx.pure.string(developer),
|
|
779
|
+
tx.pure.string(agent),
|
|
780
|
+
tx.pure.string(method),
|
|
781
|
+
tx.pure.string(dockerImage),
|
|
782
|
+
tx.pure.option("string", dockerSha256 ?? null),
|
|
783
|
+
tx.pure.u16(minMemoryGb),
|
|
784
|
+
tx.pure.u16(minCpuCores),
|
|
785
|
+
tx.pure.bool(requiresTee),
|
|
786
|
+
tx.object(import_utils.SUI_CLOCK_OBJECT_ID)
|
|
787
|
+
]
|
|
788
|
+
});
|
|
789
|
+
return tx;
|
|
790
|
+
}
|
|
791
|
+
updateAgentMethod(params) {
|
|
792
|
+
const { developer, agent, method, dockerImage, dockerSha256, minMemoryGb, minCpuCores, requiresTee } = params;
|
|
793
|
+
const tx = new import_transactions6.Transaction();
|
|
794
|
+
tx.moveCall({
|
|
795
|
+
target: `${silvanaRegistryPackage}::registry::update_method`,
|
|
796
|
+
arguments: [
|
|
797
|
+
tx.object(this.registry),
|
|
798
|
+
tx.pure.string(developer),
|
|
799
|
+
tx.pure.string(agent),
|
|
800
|
+
tx.pure.string(method),
|
|
801
|
+
tx.pure.string(dockerImage),
|
|
802
|
+
tx.pure.option("string", dockerSha256 ?? null),
|
|
803
|
+
tx.pure.u16(minMemoryGb),
|
|
804
|
+
tx.pure.u16(minCpuCores),
|
|
805
|
+
tx.pure.bool(requiresTee),
|
|
806
|
+
tx.object(import_utils.SUI_CLOCK_OBJECT_ID)
|
|
807
|
+
]
|
|
808
|
+
});
|
|
809
|
+
return tx;
|
|
810
|
+
}
|
|
811
|
+
removeAgentMethod(params) {
|
|
812
|
+
const { developer, agent, method } = params;
|
|
813
|
+
const tx = new import_transactions6.Transaction();
|
|
814
|
+
tx.moveCall({
|
|
815
|
+
target: `${silvanaRegistryPackage}::registry::remove_method`,
|
|
816
|
+
arguments: [
|
|
817
|
+
tx.object(this.registry),
|
|
818
|
+
tx.pure.string(developer),
|
|
819
|
+
tx.pure.string(agent),
|
|
820
|
+
tx.pure.string(method),
|
|
821
|
+
tx.object(import_utils.SUI_CLOCK_OBJECT_ID)
|
|
822
|
+
]
|
|
823
|
+
});
|
|
824
|
+
return tx;
|
|
825
|
+
}
|
|
826
|
+
setDefaultMethod(params) {
|
|
827
|
+
const { developer, agent, method } = params;
|
|
828
|
+
const tx = new import_transactions6.Transaction();
|
|
829
|
+
tx.moveCall({
|
|
830
|
+
target: `${silvanaRegistryPackage}::registry::set_default_method`,
|
|
831
|
+
arguments: [
|
|
832
|
+
tx.object(this.registry),
|
|
833
|
+
tx.pure.string(developer),
|
|
834
|
+
tx.pure.string(agent),
|
|
835
|
+
tx.pure.string(method),
|
|
836
|
+
tx.object(import_utils.SUI_CLOCK_OBJECT_ID)
|
|
837
|
+
]
|
|
838
|
+
});
|
|
839
|
+
return tx;
|
|
840
|
+
}
|
|
841
|
+
removeDefaultMethod(params) {
|
|
842
|
+
const { developer, agent } = params;
|
|
843
|
+
const tx = new import_transactions6.Transaction();
|
|
844
|
+
tx.moveCall({
|
|
845
|
+
target: `${silvanaRegistryPackage}::registry::remove_default_method`,
|
|
757
846
|
arguments: [
|
|
758
847
|
tx.object(this.registry),
|
|
759
848
|
tx.pure.string(developer),
|
|
@@ -841,22 +930,48 @@ var AgentRegistry = class {
|
|
|
841
930
|
if (!agentObject) {
|
|
842
931
|
return void 0;
|
|
843
932
|
}
|
|
933
|
+
const methods = {};
|
|
934
|
+
const methodsData = agentObject?.methods?.fields?.contents;
|
|
935
|
+
if (methodsData && Array.isArray(methodsData)) {
|
|
936
|
+
for (const entry of methodsData) {
|
|
937
|
+
const key = entry?.fields?.key;
|
|
938
|
+
const value = entry?.fields?.value;
|
|
939
|
+
if (key && value) {
|
|
940
|
+
methods[key] = {
|
|
941
|
+
dockerImage: value.docker_image,
|
|
942
|
+
dockerSha256: value.docker_sha256 ?? void 0,
|
|
943
|
+
minMemoryGb: Number(value.min_memory_gb),
|
|
944
|
+
minCpuCores: Number(value.min_cpu_cores),
|
|
945
|
+
requiresTee: Boolean(value.requires_tee)
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
let defaultMethod;
|
|
951
|
+
const defaultMethodData = agentObject?.default_method;
|
|
952
|
+
if (defaultMethodData && typeof defaultMethodData === "object" && !Array.isArray(defaultMethodData)) {
|
|
953
|
+
defaultMethod = {
|
|
954
|
+
dockerImage: defaultMethodData.docker_image,
|
|
955
|
+
dockerSha256: defaultMethodData.docker_sha256 ?? void 0,
|
|
956
|
+
minMemoryGb: Number(defaultMethodData.min_memory_gb),
|
|
957
|
+
minCpuCores: Number(defaultMethodData.min_cpu_cores),
|
|
958
|
+
requiresTee: Boolean(defaultMethodData.requires_tee)
|
|
959
|
+
};
|
|
960
|
+
}
|
|
844
961
|
const agent = {
|
|
845
962
|
id: agentObject?.id?.id,
|
|
846
963
|
name: agentObject.name,
|
|
847
964
|
image: agentObject?.image ?? void 0,
|
|
848
965
|
description: agentObject?.description ?? void 0,
|
|
849
966
|
site: agentObject?.site ?? void 0,
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
minCpuCores: Number(agentObject.min_cpu_cores),
|
|
854
|
-
supportsTEE: Boolean(agentObject.supports_tee),
|
|
967
|
+
chains: agentObject?.chains ?? [],
|
|
968
|
+
methods,
|
|
969
|
+
defaultMethod,
|
|
855
970
|
createdAt: Number(agentObject.created_at),
|
|
856
971
|
updatedAt: Number(agentObject.updated_at),
|
|
857
972
|
version: Number(agentObject.version)
|
|
858
973
|
};
|
|
859
|
-
if (!agent.id || !agent.name
|
|
974
|
+
if (!agent.id || !agent.name) {
|
|
860
975
|
return void 0;
|
|
861
976
|
}
|
|
862
977
|
return agent;
|
|
@@ -1220,9 +1335,614 @@ function verifyFields(params) {
|
|
|
1220
1335
|
const { publicKey, fields, signature } = params;
|
|
1221
1336
|
return client.verifyFields({ data: fields, publicKey, signature });
|
|
1222
1337
|
}
|
|
1338
|
+
|
|
1339
|
+
// dist/node/job.js
|
|
1340
|
+
var import_transactions7 = require("@mysten/sui/transactions");
|
|
1341
|
+
var import_utils2 = require("@mysten/sui/utils");
|
|
1342
|
+
var JobManager = class {
|
|
1343
|
+
constructor(params) {
|
|
1344
|
+
this.jobs = params.jobs;
|
|
1345
|
+
}
|
|
1346
|
+
static createJobs(maxAttempts) {
|
|
1347
|
+
const tx = new import_transactions7.Transaction();
|
|
1348
|
+
tx.moveCall({
|
|
1349
|
+
target: `${silvanaRegistryPackage}::jobs::create_jobs`,
|
|
1350
|
+
arguments: [
|
|
1351
|
+
tx.pure.option("u8", maxAttempts ?? null)
|
|
1352
|
+
]
|
|
1353
|
+
});
|
|
1354
|
+
return tx;
|
|
1355
|
+
}
|
|
1356
|
+
createJob(params) {
|
|
1357
|
+
const { description, developer, agent, agentMethod, app, appInstance, appInstanceMethod, sequences, data } = params;
|
|
1358
|
+
const tx = new import_transactions7.Transaction();
|
|
1359
|
+
tx.moveCall({
|
|
1360
|
+
target: `${silvanaRegistryPackage}::jobs::create_job`,
|
|
1361
|
+
arguments: [
|
|
1362
|
+
tx.object(this.jobs),
|
|
1363
|
+
tx.pure.option("string", description ?? null),
|
|
1364
|
+
tx.pure.string(developer),
|
|
1365
|
+
tx.pure.string(agent),
|
|
1366
|
+
tx.pure.string(agentMethod),
|
|
1367
|
+
tx.pure.string(app),
|
|
1368
|
+
tx.pure.string(appInstance),
|
|
1369
|
+
tx.pure.string(appInstanceMethod),
|
|
1370
|
+
tx.pure.option("vector<u64>", sequences ?? null),
|
|
1371
|
+
tx.pure.vector("u8", Array.from(data)),
|
|
1372
|
+
tx.object(import_utils2.SUI_CLOCK_OBJECT_ID)
|
|
1373
|
+
]
|
|
1374
|
+
});
|
|
1375
|
+
return tx;
|
|
1376
|
+
}
|
|
1377
|
+
startJob(jobId) {
|
|
1378
|
+
const tx = new import_transactions7.Transaction();
|
|
1379
|
+
tx.moveCall({
|
|
1380
|
+
target: `${silvanaRegistryPackage}::jobs::start_job`,
|
|
1381
|
+
arguments: [
|
|
1382
|
+
tx.object(this.jobs),
|
|
1383
|
+
tx.pure.u64(jobId),
|
|
1384
|
+
tx.object(import_utils2.SUI_CLOCK_OBJECT_ID)
|
|
1385
|
+
]
|
|
1386
|
+
});
|
|
1387
|
+
return tx;
|
|
1388
|
+
}
|
|
1389
|
+
completeJob(jobId) {
|
|
1390
|
+
const tx = new import_transactions7.Transaction();
|
|
1391
|
+
tx.moveCall({
|
|
1392
|
+
target: `${silvanaRegistryPackage}::jobs::complete_job`,
|
|
1393
|
+
arguments: [
|
|
1394
|
+
tx.object(this.jobs),
|
|
1395
|
+
tx.pure.u64(jobId)
|
|
1396
|
+
]
|
|
1397
|
+
});
|
|
1398
|
+
return tx;
|
|
1399
|
+
}
|
|
1400
|
+
failJob(params) {
|
|
1401
|
+
const { jobId, error } = params;
|
|
1402
|
+
const tx = new import_transactions7.Transaction();
|
|
1403
|
+
tx.moveCall({
|
|
1404
|
+
target: `${silvanaRegistryPackage}::jobs::fail_job`,
|
|
1405
|
+
arguments: [
|
|
1406
|
+
tx.object(this.jobs),
|
|
1407
|
+
tx.pure.u64(jobId),
|
|
1408
|
+
tx.pure.string(error),
|
|
1409
|
+
tx.object(import_utils2.SUI_CLOCK_OBJECT_ID)
|
|
1410
|
+
]
|
|
1411
|
+
});
|
|
1412
|
+
return tx;
|
|
1413
|
+
}
|
|
1414
|
+
updateMaxAttempts(maxAttempts) {
|
|
1415
|
+
const tx = new import_transactions7.Transaction();
|
|
1416
|
+
tx.moveCall({
|
|
1417
|
+
target: `${silvanaRegistryPackage}::jobs::update_max_attempts`,
|
|
1418
|
+
arguments: [
|
|
1419
|
+
tx.object(this.jobs),
|
|
1420
|
+
tx.pure.u64(maxAttempts)
|
|
1421
|
+
]
|
|
1422
|
+
});
|
|
1423
|
+
return tx;
|
|
1424
|
+
}
|
|
1425
|
+
async getJob(jobId) {
|
|
1426
|
+
try {
|
|
1427
|
+
const jobsObject = await fetchSuiObject(this.jobs);
|
|
1428
|
+
if (!jobsObject)
|
|
1429
|
+
return void 0;
|
|
1430
|
+
const jobsTableId = jobsObject?.jobs?.fields?.id?.id;
|
|
1431
|
+
if (!jobsTableId)
|
|
1432
|
+
return void 0;
|
|
1433
|
+
const job = await fetchSuiDynamicField({
|
|
1434
|
+
parentID: jobsTableId,
|
|
1435
|
+
fieldName: "jobs",
|
|
1436
|
+
type: "u64",
|
|
1437
|
+
key: String(jobId)
|
|
1438
|
+
});
|
|
1439
|
+
if (!job)
|
|
1440
|
+
return void 0;
|
|
1441
|
+
const parseStatus = (status) => {
|
|
1442
|
+
if (status?.Pending !== void 0)
|
|
1443
|
+
return { type: "Pending" };
|
|
1444
|
+
if (status?.Running !== void 0)
|
|
1445
|
+
return { type: "Running" };
|
|
1446
|
+
if (status?.Failed !== void 0)
|
|
1447
|
+
return { type: "Failed", error: status.Failed };
|
|
1448
|
+
return { type: "Pending" };
|
|
1449
|
+
};
|
|
1450
|
+
return {
|
|
1451
|
+
id: job?.id?.id,
|
|
1452
|
+
jobId: Number(job.job_id),
|
|
1453
|
+
description: job?.description ?? void 0,
|
|
1454
|
+
developer: job.developer,
|
|
1455
|
+
agent: job.agent,
|
|
1456
|
+
agentMethod: job.agent_method,
|
|
1457
|
+
app: job.app,
|
|
1458
|
+
appInstance: job.app_instance,
|
|
1459
|
+
appInstanceMethod: job.app_instance_method,
|
|
1460
|
+
sequences: job?.sequences?.map((s) => Number(s)) ?? void 0,
|
|
1461
|
+
data: new Uint8Array(job.data),
|
|
1462
|
+
status: parseStatus(job.status),
|
|
1463
|
+
attempts: Number(job.attempts),
|
|
1464
|
+
createdAt: Number(job.created_at),
|
|
1465
|
+
updatedAt: Number(job.updated_at)
|
|
1466
|
+
};
|
|
1467
|
+
} catch (error) {
|
|
1468
|
+
console.error("Error fetching job:", error);
|
|
1469
|
+
return void 0;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
async getPendingJobs() {
|
|
1473
|
+
try {
|
|
1474
|
+
const jobsObject = await fetchSuiObject(this.jobs);
|
|
1475
|
+
if (!jobsObject)
|
|
1476
|
+
return [];
|
|
1477
|
+
const pendingJobs = jobsObject?.pending_jobs?.fields?.contents;
|
|
1478
|
+
if (!Array.isArray(pendingJobs))
|
|
1479
|
+
return [];
|
|
1480
|
+
return pendingJobs.map((id) => Number(id));
|
|
1481
|
+
} catch (error) {
|
|
1482
|
+
console.error("Error fetching pending jobs:", error);
|
|
1483
|
+
return [];
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
async getNextPendingJob() {
|
|
1487
|
+
const pendingJobs = await this.getPendingJobs();
|
|
1488
|
+
return pendingJobs.length > 0 ? pendingJobs[0] : void 0;
|
|
1489
|
+
}
|
|
1490
|
+
async getMaxAttempts() {
|
|
1491
|
+
try {
|
|
1492
|
+
const jobsObject = await fetchSuiObject(this.jobs);
|
|
1493
|
+
if (!jobsObject)
|
|
1494
|
+
return 3;
|
|
1495
|
+
return Number(jobsObject?.max_attempts ?? 3);
|
|
1496
|
+
} catch (error) {
|
|
1497
|
+
console.error("Error fetching max attempts:", error);
|
|
1498
|
+
return 3;
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
};
|
|
1502
|
+
|
|
1503
|
+
// dist/node/app_instance.js
|
|
1504
|
+
var import_transactions8 = require("@mysten/sui/transactions");
|
|
1505
|
+
var import_utils3 = require("@mysten/sui/utils");
|
|
1506
|
+
var AppInstanceManager = class {
|
|
1507
|
+
constructor(params) {
|
|
1508
|
+
this.registry = params.registry;
|
|
1509
|
+
}
|
|
1510
|
+
// Note: update_method and remove_method functions are not available in the Move module
|
|
1511
|
+
// These would need to be implemented in app_instance.move if needed
|
|
1512
|
+
createAppJob(params) {
|
|
1513
|
+
const { appInstance, description, method, sequences, data } = params;
|
|
1514
|
+
console.log("createAppJob params:", {
|
|
1515
|
+
appInstance,
|
|
1516
|
+
description,
|
|
1517
|
+
method,
|
|
1518
|
+
sequences,
|
|
1519
|
+
data: data instanceof Uint8Array ? `Uint8Array(${data.length})` : typeof data,
|
|
1520
|
+
dataContent: data instanceof Uint8Array ? Array.from(data) : data
|
|
1521
|
+
});
|
|
1522
|
+
const tx = new import_transactions8.Transaction();
|
|
1523
|
+
tx.moveCall({
|
|
1524
|
+
target: `${silvanaRegistryPackage}::app_instance::create_app_job`,
|
|
1525
|
+
arguments: [
|
|
1526
|
+
tx.object(appInstance),
|
|
1527
|
+
tx.pure.string(method),
|
|
1528
|
+
tx.pure.option("string", description ?? null),
|
|
1529
|
+
tx.pure.option("vector<u64>", sequences ?? null),
|
|
1530
|
+
tx.pure.vector("u8", data),
|
|
1531
|
+
tx.object(import_utils3.SUI_CLOCK_OBJECT_ID)
|
|
1532
|
+
]
|
|
1533
|
+
});
|
|
1534
|
+
return tx;
|
|
1535
|
+
}
|
|
1536
|
+
startAppJob(params) {
|
|
1537
|
+
const { appInstance, jobId } = params;
|
|
1538
|
+
const tx = new import_transactions8.Transaction();
|
|
1539
|
+
tx.moveCall({
|
|
1540
|
+
target: `${silvanaRegistryPackage}::app_instance::start_app_job`,
|
|
1541
|
+
arguments: [
|
|
1542
|
+
tx.object(appInstance),
|
|
1543
|
+
tx.pure.u64(jobId),
|
|
1544
|
+
tx.object(import_utils3.SUI_CLOCK_OBJECT_ID)
|
|
1545
|
+
]
|
|
1546
|
+
});
|
|
1547
|
+
return tx;
|
|
1548
|
+
}
|
|
1549
|
+
completeAppJob(params) {
|
|
1550
|
+
const { appInstance, jobId } = params;
|
|
1551
|
+
const tx = new import_transactions8.Transaction();
|
|
1552
|
+
tx.moveCall({
|
|
1553
|
+
target: `${silvanaRegistryPackage}::app_instance::complete_app_job`,
|
|
1554
|
+
arguments: [
|
|
1555
|
+
tx.object(appInstance),
|
|
1556
|
+
tx.pure.u64(jobId),
|
|
1557
|
+
tx.object(import_utils3.SUI_CLOCK_OBJECT_ID)
|
|
1558
|
+
]
|
|
1559
|
+
});
|
|
1560
|
+
return tx;
|
|
1561
|
+
}
|
|
1562
|
+
failAppJob(params) {
|
|
1563
|
+
const { appInstance, jobId, error } = params;
|
|
1564
|
+
const tx = new import_transactions8.Transaction();
|
|
1565
|
+
tx.moveCall({
|
|
1566
|
+
target: `${silvanaRegistryPackage}::app_instance::fail_app_job`,
|
|
1567
|
+
arguments: [
|
|
1568
|
+
tx.object(appInstance),
|
|
1569
|
+
tx.pure.u64(jobId),
|
|
1570
|
+
tx.pure.string(error),
|
|
1571
|
+
tx.object(import_utils3.SUI_CLOCK_OBJECT_ID)
|
|
1572
|
+
]
|
|
1573
|
+
});
|
|
1574
|
+
return tx;
|
|
1575
|
+
}
|
|
1576
|
+
async getAppInstance(appInstanceId) {
|
|
1577
|
+
try {
|
|
1578
|
+
const appInstance = await fetchSuiObject(appInstanceId);
|
|
1579
|
+
if (!appInstance)
|
|
1580
|
+
return void 0;
|
|
1581
|
+
const fields = appInstance?.data?.content?.fields;
|
|
1582
|
+
if (!fields)
|
|
1583
|
+
return void 0;
|
|
1584
|
+
const methods = {};
|
|
1585
|
+
const methodsArray = fields?.methods?.fields?.contents;
|
|
1586
|
+
if (Array.isArray(methodsArray)) {
|
|
1587
|
+
for (const entry of methodsArray) {
|
|
1588
|
+
const key = entry?.fields?.key;
|
|
1589
|
+
const value = entry?.fields?.value;
|
|
1590
|
+
if (key && value) {
|
|
1591
|
+
const methodFields = value.fields || value;
|
|
1592
|
+
methods[key] = {
|
|
1593
|
+
description: methodFields.description ?? void 0,
|
|
1594
|
+
developer: methodFields.developer,
|
|
1595
|
+
agent: methodFields.agent,
|
|
1596
|
+
agentMethod: methodFields.agent_method || methodFields.agentMethod
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
return {
|
|
1602
|
+
id: fields?.id?.id,
|
|
1603
|
+
silvanaAppName: fields.silvana_app_name,
|
|
1604
|
+
description: fields?.description ?? void 0,
|
|
1605
|
+
metadata: fields?.metadata ?? void 0,
|
|
1606
|
+
methods,
|
|
1607
|
+
admin: fields.admin,
|
|
1608
|
+
sequence: Number(fields.sequence),
|
|
1609
|
+
blockNumber: Number(fields.block_number),
|
|
1610
|
+
previousBlockTimestamp: Number(fields.previous_block_timestamp),
|
|
1611
|
+
previousBlockLastSequence: Number(fields.previous_block_last_sequence),
|
|
1612
|
+
lastProvedBlockNumber: Number(fields.last_proved_block_number),
|
|
1613
|
+
isPaused: Boolean(fields.isPaused),
|
|
1614
|
+
jobsId: String(fields.jobs?.fields?.id?.id ?? ""),
|
|
1615
|
+
createdAt: Number(fields.created_at),
|
|
1616
|
+
updatedAt: Number(fields.updated_at)
|
|
1617
|
+
};
|
|
1618
|
+
} catch (error) {
|
|
1619
|
+
console.error("Error fetching app instance:", error);
|
|
1620
|
+
return void 0;
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
async getAppJob(params) {
|
|
1624
|
+
try {
|
|
1625
|
+
const appInstanceObj = await fetchSuiObject(params.appInstance);
|
|
1626
|
+
if (!appInstanceObj)
|
|
1627
|
+
return void 0;
|
|
1628
|
+
const jobsTableId = appInstanceObj?.data?.content?.fields?.jobs?.fields?.jobs?.fields?.id?.id;
|
|
1629
|
+
if (!jobsTableId)
|
|
1630
|
+
return void 0;
|
|
1631
|
+
const job = await fetchSuiDynamicField({
|
|
1632
|
+
parentID: jobsTableId,
|
|
1633
|
+
fieldName: "jobs",
|
|
1634
|
+
type: "u64",
|
|
1635
|
+
key: String(params.jobId)
|
|
1636
|
+
});
|
|
1637
|
+
if (!job)
|
|
1638
|
+
return void 0;
|
|
1639
|
+
const parseStatus = (status) => {
|
|
1640
|
+
if (status?.variant === "Pending")
|
|
1641
|
+
return { type: "Pending" };
|
|
1642
|
+
if (status?.variant === "Running")
|
|
1643
|
+
return { type: "Running" };
|
|
1644
|
+
if (status?.variant === "Failed") {
|
|
1645
|
+
const error = status?.fields?.error || status?.fields?.[0] || "Unknown error";
|
|
1646
|
+
return { type: "Failed", error };
|
|
1647
|
+
}
|
|
1648
|
+
if (status?.Pending !== void 0)
|
|
1649
|
+
return { type: "Pending" };
|
|
1650
|
+
if (status?.Running !== void 0)
|
|
1651
|
+
return { type: "Running" };
|
|
1652
|
+
if (status?.Failed !== void 0)
|
|
1653
|
+
return { type: "Failed", error: status.Failed };
|
|
1654
|
+
return { type: "Pending" };
|
|
1655
|
+
};
|
|
1656
|
+
return {
|
|
1657
|
+
id: job?.id?.id,
|
|
1658
|
+
jobId: Number(job.job_id),
|
|
1659
|
+
description: job?.description ?? void 0,
|
|
1660
|
+
developer: job.developer,
|
|
1661
|
+
agent: job.agent,
|
|
1662
|
+
agentMethod: job.agent_method,
|
|
1663
|
+
app: job.app,
|
|
1664
|
+
appInstance: job.app_instance,
|
|
1665
|
+
appInstanceMethod: job.app_instance_method,
|
|
1666
|
+
sequences: job?.sequences?.map((s) => Number(s)) ?? void 0,
|
|
1667
|
+
data: new Uint8Array(job.data),
|
|
1668
|
+
status: parseStatus(job.status),
|
|
1669
|
+
attempts: Number(job.attempts),
|
|
1670
|
+
createdAt: Number(job.created_at),
|
|
1671
|
+
updatedAt: Number(job.updated_at)
|
|
1672
|
+
};
|
|
1673
|
+
} catch (error) {
|
|
1674
|
+
console.error("Error fetching app job:", error);
|
|
1675
|
+
return void 0;
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
async getAppPendingJobs(appInstance) {
|
|
1679
|
+
try {
|
|
1680
|
+
const appInstanceObj = await fetchSuiObject(appInstance);
|
|
1681
|
+
if (!appInstanceObj)
|
|
1682
|
+
return [];
|
|
1683
|
+
const pendingJobs = appInstanceObj?.data?.content?.fields?.jobs?.fields?.pending_jobs?.fields?.contents;
|
|
1684
|
+
if (!Array.isArray(pendingJobs))
|
|
1685
|
+
return [];
|
|
1686
|
+
return pendingJobs.map((id) => Number(id));
|
|
1687
|
+
} catch (error) {
|
|
1688
|
+
console.error("Error fetching app pending jobs:", error);
|
|
1689
|
+
return [];
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
};
|
|
1693
|
+
|
|
1694
|
+
// dist/node/test.js
|
|
1695
|
+
var import_ed255192 = require("@mysten/sui/keypairs/ed25519");
|
|
1696
|
+
var import_transactions9 = require("@mysten/sui/transactions");
|
|
1697
|
+
async function createTestRegistry(config = {}) {
|
|
1698
|
+
const registryName = config.registryName ?? "Test Silvana Registry";
|
|
1699
|
+
const developerName = config.developerName ?? "TestDev";
|
|
1700
|
+
const developerGithub = config.developerGithub ?? "testdev";
|
|
1701
|
+
const developerImage = config.developerImage;
|
|
1702
|
+
const developerDescription = config.developerDescription ?? "Test developer for automated testing";
|
|
1703
|
+
const developerSite = config.developerSite ?? "https://test.dev";
|
|
1704
|
+
const appName = config.appName ?? "TestApp";
|
|
1705
|
+
const appDescription = config.appDescription ?? "Test application for automated testing";
|
|
1706
|
+
const appImage = config.appImage;
|
|
1707
|
+
const appSite = config.appSite ?? "https://testapp.dev";
|
|
1708
|
+
const testAgentName = config.testAgentName ?? "TestAgent";
|
|
1709
|
+
const testAgentImage = config.testAgentImage;
|
|
1710
|
+
const testAgentChains = config.testAgentChains ?? ["sui-testnet", "sui-devnet"];
|
|
1711
|
+
const key = process.env.SUI_KEY;
|
|
1712
|
+
if (!key) {
|
|
1713
|
+
throw new Error("SUI_KEY is not set in environment");
|
|
1714
|
+
}
|
|
1715
|
+
const keyPair = import_ed255192.Ed25519Keypair.fromSecretKey(key);
|
|
1716
|
+
const address = keyPair.toSuiAddress();
|
|
1717
|
+
console.log("Creating test registry with sender address:", address);
|
|
1718
|
+
console.log("Chain:", process.env.SUI_CHAIN);
|
|
1719
|
+
console.log("Step 1: Creating registry...");
|
|
1720
|
+
const createRegistryTx = AgentRegistry.createAgentRegistry({
|
|
1721
|
+
name: registryName
|
|
1722
|
+
});
|
|
1723
|
+
createRegistryTx.setSender(address);
|
|
1724
|
+
createRegistryTx.setGasBudget(1e8);
|
|
1725
|
+
const registryResult = await executeTx({
|
|
1726
|
+
tx: createRegistryTx,
|
|
1727
|
+
keyPair
|
|
1728
|
+
});
|
|
1729
|
+
if (!registryResult) {
|
|
1730
|
+
throw new Error("Failed to create registry - no result");
|
|
1731
|
+
}
|
|
1732
|
+
if (registryResult.error) {
|
|
1733
|
+
throw new Error(`Failed to create registry: ${registryResult.error}`);
|
|
1734
|
+
}
|
|
1735
|
+
if (!registryResult.tx?.objectChanges) {
|
|
1736
|
+
throw new Error("Failed to create registry - no object changes");
|
|
1737
|
+
}
|
|
1738
|
+
const registryObject = registryResult.tx.objectChanges.find((obj) => obj.type === "created" && obj.objectType?.includes("::registry::SilvanaRegistry"));
|
|
1739
|
+
if (!registryObject || !("objectId" in registryObject)) {
|
|
1740
|
+
throw new Error("Failed to find created registry object");
|
|
1741
|
+
}
|
|
1742
|
+
const registryAddress = registryObject.objectId;
|
|
1743
|
+
console.log("Registry created with address:", registryAddress);
|
|
1744
|
+
if (registryResult.digest) {
|
|
1745
|
+
await waitTx(registryResult.digest);
|
|
1746
|
+
}
|
|
1747
|
+
const registry = new AgentRegistry({ registry: registryAddress });
|
|
1748
|
+
const appInstanceManager = new AppInstanceManager({ registry: registryAddress });
|
|
1749
|
+
console.log("Step 2: Creating developer...");
|
|
1750
|
+
const createDeveloperTx = registry.createDeveloper({
|
|
1751
|
+
name: developerName,
|
|
1752
|
+
github: developerGithub,
|
|
1753
|
+
image: developerImage,
|
|
1754
|
+
description: developerDescription,
|
|
1755
|
+
site: developerSite
|
|
1756
|
+
});
|
|
1757
|
+
createDeveloperTx.setSender(address);
|
|
1758
|
+
createDeveloperTx.setGasBudget(1e8);
|
|
1759
|
+
const developerResult = await executeTx({
|
|
1760
|
+
tx: createDeveloperTx,
|
|
1761
|
+
keyPair
|
|
1762
|
+
});
|
|
1763
|
+
if (!developerResult) {
|
|
1764
|
+
throw new Error("Failed to create developer - no result");
|
|
1765
|
+
}
|
|
1766
|
+
if (developerResult.error) {
|
|
1767
|
+
throw new Error(`Failed to create developer: ${developerResult.error}`);
|
|
1768
|
+
}
|
|
1769
|
+
if (developerResult.digest) {
|
|
1770
|
+
await waitTx(developerResult.digest);
|
|
1771
|
+
}
|
|
1772
|
+
console.log("Developer created:", developerName);
|
|
1773
|
+
console.log("Step 3: Creating app...");
|
|
1774
|
+
const createAppTx = new import_transactions9.Transaction();
|
|
1775
|
+
createAppTx.moveCall({
|
|
1776
|
+
target: `${process.env.SILVANA_REGISTRY_PACKAGE ?? "@silvana/agent"}::registry::add_app`,
|
|
1777
|
+
arguments: [
|
|
1778
|
+
createAppTx.object(registryAddress),
|
|
1779
|
+
createAppTx.pure.string(appName),
|
|
1780
|
+
createAppTx.pure.option("string", appDescription),
|
|
1781
|
+
createAppTx.object("0x6")
|
|
1782
|
+
// SUI_CLOCK_OBJECT_ID
|
|
1783
|
+
]
|
|
1784
|
+
});
|
|
1785
|
+
createAppTx.setSender(address);
|
|
1786
|
+
createAppTx.setGasBudget(1e8);
|
|
1787
|
+
const appResult = await executeTx({
|
|
1788
|
+
tx: createAppTx,
|
|
1789
|
+
keyPair
|
|
1790
|
+
});
|
|
1791
|
+
if (!appResult) {
|
|
1792
|
+
throw new Error("Failed to create app - no result");
|
|
1793
|
+
}
|
|
1794
|
+
if (appResult.error) {
|
|
1795
|
+
throw new Error(`Failed to create app: ${appResult.error}`);
|
|
1796
|
+
}
|
|
1797
|
+
if (appResult.digest) {
|
|
1798
|
+
await waitTx(appResult.digest);
|
|
1799
|
+
}
|
|
1800
|
+
console.log("App created:", appName);
|
|
1801
|
+
let agentName;
|
|
1802
|
+
if (config.testAgentName && config.testAgentChains) {
|
|
1803
|
+
console.log("Step 4: Creating agent...");
|
|
1804
|
+
const createAgentTx = registry.createAgent({
|
|
1805
|
+
developer: developerName,
|
|
1806
|
+
name: testAgentName,
|
|
1807
|
+
image: testAgentImage,
|
|
1808
|
+
description: "Test agent for automated testing",
|
|
1809
|
+
chains: testAgentChains
|
|
1810
|
+
});
|
|
1811
|
+
createAgentTx.setSender(address);
|
|
1812
|
+
createAgentTx.setGasBudget(1e8);
|
|
1813
|
+
const agentResult = await executeTx({
|
|
1814
|
+
tx: createAgentTx,
|
|
1815
|
+
keyPair
|
|
1816
|
+
});
|
|
1817
|
+
if (!agentResult) {
|
|
1818
|
+
throw new Error("Failed to create agent - no result");
|
|
1819
|
+
}
|
|
1820
|
+
if (agentResult.error) {
|
|
1821
|
+
throw new Error(`Failed to create agent: ${agentResult.error}`);
|
|
1822
|
+
}
|
|
1823
|
+
if (agentResult.digest) {
|
|
1824
|
+
await waitTx(agentResult.digest);
|
|
1825
|
+
}
|
|
1826
|
+
agentName = testAgentName;
|
|
1827
|
+
console.log("Agent created:", testAgentName);
|
|
1828
|
+
}
|
|
1829
|
+
console.log("Test registry setup complete!");
|
|
1830
|
+
console.log("Registry address:", registryAddress);
|
|
1831
|
+
console.log("Developer:", developerName);
|
|
1832
|
+
console.log("App:", appName);
|
|
1833
|
+
if (agentName) {
|
|
1834
|
+
console.log("Agent:", agentName);
|
|
1835
|
+
}
|
|
1836
|
+
return {
|
|
1837
|
+
registryAddress,
|
|
1838
|
+
developerName,
|
|
1839
|
+
appName,
|
|
1840
|
+
agentName,
|
|
1841
|
+
registry,
|
|
1842
|
+
appInstanceManager,
|
|
1843
|
+
keyPair,
|
|
1844
|
+
address
|
|
1845
|
+
};
|
|
1846
|
+
}
|
|
1847
|
+
async function createTestApp(registryAddress, appName = "test_app") {
|
|
1848
|
+
const key = process.env.SUI_KEY;
|
|
1849
|
+
if (!key) {
|
|
1850
|
+
throw new Error("SUI_KEY is not set in environment");
|
|
1851
|
+
}
|
|
1852
|
+
const keyPair = import_ed255192.Ed25519Keypair.fromSecretKey(key);
|
|
1853
|
+
const address = keyPair.toSuiAddress();
|
|
1854
|
+
console.log("Creating TestApp with AppInstance...");
|
|
1855
|
+
console.log("Registry address:", registryAddress);
|
|
1856
|
+
console.log("Sender address:", address);
|
|
1857
|
+
const createAppTx = new import_transactions9.Transaction();
|
|
1858
|
+
createAppTx.moveCall({
|
|
1859
|
+
target: `${process.env.SILVANA_REGISTRY_PACKAGE ?? "@silvana/agent"}::registry::add_app`,
|
|
1860
|
+
arguments: [
|
|
1861
|
+
createAppTx.object(registryAddress),
|
|
1862
|
+
createAppTx.pure.string(appName),
|
|
1863
|
+
createAppTx.pure.option("string", "Test app for TestApp module"),
|
|
1864
|
+
createAppTx.object("0x6")
|
|
1865
|
+
// SUI_CLOCK_OBJECT_ID
|
|
1866
|
+
]
|
|
1867
|
+
});
|
|
1868
|
+
createAppTx.setSender(address);
|
|
1869
|
+
createAppTx.setGasBudget(1e8);
|
|
1870
|
+
const appResult = await executeTx({
|
|
1871
|
+
tx: createAppTx,
|
|
1872
|
+
keyPair,
|
|
1873
|
+
showErrors: false
|
|
1874
|
+
// Don't throw, we'll handle the error
|
|
1875
|
+
});
|
|
1876
|
+
if (appResult?.digest && !appResult.error) {
|
|
1877
|
+
await waitTx(appResult.digest);
|
|
1878
|
+
console.log("App created:", appName);
|
|
1879
|
+
} else if (appResult?.error?.includes("0) in command 0")) {
|
|
1880
|
+
console.log("App already exists, continuing:", appName);
|
|
1881
|
+
} else if (appResult?.error) {
|
|
1882
|
+
throw new Error(`Failed to create app for TestApp: ${appResult.error}`);
|
|
1883
|
+
}
|
|
1884
|
+
const tx = new import_transactions9.Transaction();
|
|
1885
|
+
tx.moveCall({
|
|
1886
|
+
target: `${process.env.SILVANA_REGISTRY_PACKAGE ?? "@silvana/agent"}::test_app::create_test_app`,
|
|
1887
|
+
arguments: [
|
|
1888
|
+
tx.object(registryAddress),
|
|
1889
|
+
tx.object("0x6")
|
|
1890
|
+
// SUI_CLOCK_OBJECT_ID
|
|
1891
|
+
]
|
|
1892
|
+
});
|
|
1893
|
+
tx.setSender(address);
|
|
1894
|
+
tx.setGasBudget(1e8);
|
|
1895
|
+
const result = await executeTx({
|
|
1896
|
+
tx,
|
|
1897
|
+
keyPair
|
|
1898
|
+
});
|
|
1899
|
+
if (!result) {
|
|
1900
|
+
throw new Error("Failed to create TestApp - no result");
|
|
1901
|
+
}
|
|
1902
|
+
if (result.error) {
|
|
1903
|
+
throw new Error(`Failed to create TestApp: ${result.error}`);
|
|
1904
|
+
}
|
|
1905
|
+
if (!result.tx) {
|
|
1906
|
+
throw new Error("Failed to create TestApp - no transaction result");
|
|
1907
|
+
}
|
|
1908
|
+
if (result.digest) {
|
|
1909
|
+
const confirmedTx = await waitTx(result.digest);
|
|
1910
|
+
result.tx = confirmedTx;
|
|
1911
|
+
}
|
|
1912
|
+
if (!result?.tx?.objectChanges) {
|
|
1913
|
+
throw new Error("Failed to create TestApp - no object changes");
|
|
1914
|
+
}
|
|
1915
|
+
const testAppObject = result.tx.objectChanges.find((obj) => obj.type === "created" && obj.objectType?.includes("::test_app::TestApp"));
|
|
1916
|
+
if (!testAppObject || !("objectId" in testAppObject)) {
|
|
1917
|
+
throw new Error("Failed to find created TestApp object");
|
|
1918
|
+
}
|
|
1919
|
+
const appInstanceObject = result.tx.objectChanges.find((obj) => obj.type === "created" && obj.objectType?.includes("::app_instance::AppInstance"));
|
|
1920
|
+
if (!appInstanceObject || !("objectId" in appInstanceObject)) {
|
|
1921
|
+
throw new Error("Failed to find created AppInstance object");
|
|
1922
|
+
}
|
|
1923
|
+
const testAppAddress = testAppObject.objectId;
|
|
1924
|
+
const appInstanceAddress = appInstanceObject.objectId;
|
|
1925
|
+
const appInstanceCapAddress = testAppAddress;
|
|
1926
|
+
console.log("TestApp created:", testAppAddress);
|
|
1927
|
+
console.log("AppInstance created:", appInstanceAddress);
|
|
1928
|
+
console.log("AppInstanceCap created:", appInstanceCapAddress);
|
|
1929
|
+
const appInstanceManager = new AppInstanceManager({ registry: registryAddress });
|
|
1930
|
+
return {
|
|
1931
|
+
testAppAddress,
|
|
1932
|
+
appInstanceAddress,
|
|
1933
|
+
appInstanceCapAddress,
|
|
1934
|
+
registryAddress,
|
|
1935
|
+
appName,
|
|
1936
|
+
keyPair,
|
|
1937
|
+
address,
|
|
1938
|
+
appInstanceManager
|
|
1939
|
+
};
|
|
1940
|
+
}
|
|
1223
1941
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1224
1942
|
0 && (module.exports = {
|
|
1225
1943
|
AgentRegistry,
|
|
1944
|
+
AppInstanceManager,
|
|
1945
|
+
JobManager,
|
|
1226
1946
|
buildMovePackage,
|
|
1227
1947
|
buildPublishTx,
|
|
1228
1948
|
buildUpgradeTx,
|
|
@@ -1231,6 +1951,8 @@ function verifyFields(params) {
|
|
|
1231
1951
|
convertMinaPublicKeyToFields,
|
|
1232
1952
|
convertMinaSignatureFromBase58,
|
|
1233
1953
|
convertMinaSignatureToBase58,
|
|
1954
|
+
createTestApp,
|
|
1955
|
+
createTestRegistry,
|
|
1234
1956
|
executeTx,
|
|
1235
1957
|
fetchSuiDynamicField,
|
|
1236
1958
|
fetchSuiDynamicFieldsList,
|
|
@@ -1250,6 +1972,7 @@ function verifyFields(params) {
|
|
|
1250
1972
|
silvanaFaucetGetKey,
|
|
1251
1973
|
silvanaFaucetPingKey,
|
|
1252
1974
|
silvanaFaucetReturnKey,
|
|
1975
|
+
silvanaRegistryPackage,
|
|
1253
1976
|
sleep,
|
|
1254
1977
|
suiClient,
|
|
1255
1978
|
u256ToFields,
|