@silvana-one/agent 1.0.36 → 1.0.38

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/grpc.ts CHANGED
@@ -28,6 +28,10 @@ import {
28
28
  UpdateBlockSettlementTxIncludedInBlockRequestSchema,
29
29
  CreateAppJobRequestSchema,
30
30
  RejectProofRequestSchema,
31
+ ProofEventRequestSchema,
32
+ AgentMessageRequestSchema,
33
+ LogLevel,
34
+ ProofEventType,
31
35
  type GetJobResponse,
32
36
  type CompleteJobResponse,
33
37
  type FailJobResponse,
@@ -57,6 +61,8 @@ import {
57
61
  type UpdateBlockSettlementTxIncludedInBlockResponse,
58
62
  type CreateAppJobResponse,
59
63
  type RejectProofResponse,
64
+ type ProofEventResponse,
65
+ type AgentMessageResponse,
60
66
  } from "./proto/silvana/coordinator/v1/coordinator_pb.js";
61
67
  import { create } from "@bufbuild/protobuf";
62
68
 
@@ -748,6 +754,135 @@ export async function updateBlockSettlement(
748
754
  return await client.updateBlockSettlement(request);
749
755
  }
750
756
 
757
+ /**
758
+ * Sends a proof event to the coordinator
759
+ */
760
+ export async function proofEvent(params: {
761
+ dataAvailability: string;
762
+ blockNumber: bigint;
763
+ proofEventType: ProofEventType;
764
+ sequences: bigint[];
765
+ blockProof?: boolean;
766
+ mergedSequences1?: bigint[];
767
+ mergedSequences2?: bigint[];
768
+ }): Promise<ProofEventResponse> {
769
+ const { client } = getCoordinatorClient();
770
+
771
+ const request = create(ProofEventRequestSchema, {
772
+ dataAvailability: params.dataAvailability,
773
+ blockNumber: params.blockNumber,
774
+ proofEventType: params.proofEventType,
775
+ sequences: params.sequences,
776
+ blockProof: params.blockProof,
777
+ mergedSequences1: params.mergedSequences1 || [],
778
+ mergedSequences2: params.mergedSequences2 || [],
779
+ });
780
+
781
+ return await client.proofEvent(request);
782
+ }
783
+
784
+ /**
785
+ * Sends an agent message to the coordinator with a specific log level
786
+ */
787
+ export async function agentMessage(
788
+ level: LogLevel,
789
+ message: string
790
+ ): Promise<AgentMessageResponse> {
791
+ const { client } = getCoordinatorClient();
792
+
793
+ const request = create(AgentMessageRequestSchema, {
794
+ level,
795
+ message,
796
+ });
797
+
798
+ return await client.agentMessage(request);
799
+ }
800
+
801
+ /**
802
+ * Logs a debug message to the coordinator and console
803
+ */
804
+ export async function debug(...args: any[]): Promise<void> {
805
+ const message = args
806
+ .map((arg) => (typeof arg === "object" ? JSON.stringify(arg) : String(arg)))
807
+ .join(" ");
808
+
809
+ console.log(...args);
810
+
811
+ try {
812
+ await agentMessage(LogLevel.DEBUG, message);
813
+ } catch (error) {
814
+ console.error("Failed to send debug message to coordinator:", error);
815
+ }
816
+ }
817
+
818
+ /**
819
+ * Logs an info message to the coordinator and console
820
+ */
821
+ export async function info(...args: any[]): Promise<void> {
822
+ const message = args
823
+ .map((arg) => (typeof arg === "object" ? JSON.stringify(arg) : String(arg)))
824
+ .join(" ");
825
+
826
+ console.log(...args);
827
+
828
+ try {
829
+ await agentMessage(LogLevel.INFO, message);
830
+ } catch (error) {
831
+ console.error("Failed to send info message to coordinator:", error);
832
+ }
833
+ }
834
+
835
+ /**
836
+ * Logs a warning message to the coordinator and console
837
+ */
838
+ export async function warn(...args: any[]): Promise<void> {
839
+ const message = args
840
+ .map((arg) => (typeof arg === "object" ? JSON.stringify(arg) : String(arg)))
841
+ .join(" ");
842
+
843
+ console.warn(...args);
844
+
845
+ try {
846
+ await agentMessage(LogLevel.WARN, message);
847
+ } catch (error) {
848
+ console.error("Failed to send warn message to coordinator:", error);
849
+ }
850
+ }
851
+
852
+ /**
853
+ * Logs an error message to the coordinator and console
854
+ */
855
+ export async function error(...args: any[]): Promise<void> {
856
+ const message = args
857
+ .map((arg) => (typeof arg === "object" ? JSON.stringify(arg) : String(arg)))
858
+ .join(" ");
859
+
860
+ console.error(...args);
861
+
862
+ try {
863
+ await agentMessage(LogLevel.ERROR, message);
864
+ } catch (error) {
865
+ console.error("Failed to send error message to coordinator:", error);
866
+ }
867
+ }
868
+
869
+ /**
870
+ * Logs a fatal message to the coordinator and console
871
+ */
872
+ export async function fatal(...args: any[]): Promise<void> {
873
+ const message = args
874
+ .map((arg) => (typeof arg === "object" ? JSON.stringify(arg) : String(arg)))
875
+ .join(" ");
876
+
877
+ console.error(...args);
878
+
879
+ try {
880
+ await agentMessage(LogLevel.FATAL, message);
881
+ } catch (error) {
882
+ console.error("Failed to send fatal message to coordinator:", error);
883
+ }
884
+ }
885
+
751
886
  // Re-export types for users to access
752
887
  export type {
753
888
  Block,
@@ -759,4 +894,9 @@ export type {
759
894
  GetBlockSettlementResponse,
760
895
  UpdateBlockSettlementResponse,
761
896
  RejectProofResponse,
897
+ ProofEventResponse,
898
+ AgentMessageResponse,
762
899
  };
900
+
901
+ // Re-export enums
902
+ export { LogLevel, ProofEventType };