nexus_sdk/move_bindings/extensions/
tap.rs1use {
8 crate::{
9 move_bindings::{
10 interface::{
11 agent::{
12 Agent,
13 AgentInnerV1,
14 AgentPaymentVault,
15 AgentPaymentVaultInnerV1,
16 AgentVaultFieldKey,
17 FixedTool,
18 SkillDagBinding,
19 SkillRequirement,
20 SkillSchedulePolicy,
21 },
22 payment::{PaymentSourceKind, SkillPaymentPolicy},
23 version::InterfaceVersion,
24 },
25 registry::agent_registry::{
26 DefaultDagExecutor,
27 DefaultDagExecutorFieldKey,
28 SkillRecord,
29 },
30 sui_framework::object::{ID, UID},
31 workflow::execution::DagExecutionPaymentFieldKey,
32 },
33 sui,
34 types::{AgentId, DefaultDagExecutorTarget},
35 },
36 std::fmt,
37};
38
39impl PartialOrd for InterfaceVersion {
40 fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
41 Some(self.cmp(other))
42 }
43}
44
45impl Ord for InterfaceVersion {
46 fn cmp(&self, other: &Self) -> std::cmp::Ordering {
47 self.inner.cmp(&other.inner)
48 }
49}
50
51impl fmt::Display for InterfaceVersion {
52 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53 write!(f, "{}", self.inner)
54 }
55}
56
57#[allow(clippy::derivable_impls)]
58impl Default for SkillPaymentPolicy {
59 fn default() -> Self {
60 Self::UserFunded
61 }
62}
63
64impl SkillPaymentPolicy {
65 pub fn user_funded() -> Self {
66 Self::UserFunded
67 }
68
69 pub fn agent_funded(max_budget_mist: u64) -> Self {
70 Self::AgentFunded { max_budget_mist }
71 }
72
73 pub fn max_budget_mist(&self) -> u64 {
74 match self {
75 Self::UserFunded => 0,
76 Self::AgentFunded { max_budget_mist } => *max_budget_mist,
77 }
78 }
79}
80
81impl PaymentSourceKind {
82 pub fn user_funded(user: sui::types::Address) -> Self {
83 Self::UserFunded { user }
84 }
85
86 pub fn agent_funded(agent_id: AgentId) -> Self {
87 Self::AgentFunded {
88 agent_id: ID::new(agent_id),
89 }
90 }
91
92 pub fn identity(&self) -> sui::types::Address {
93 match self {
94 Self::UserFunded { user } => *user,
95 Self::AgentFunded { agent_id } => (*agent_id).into(),
96 }
97 }
98}
99
100impl SkillDagBinding {
101 pub fn pinned(dag_id: sui::types::Address) -> Self {
102 Self::Pinned { dag_id }
103 }
104
105 pub fn runtime_selected() -> Self {
106 Self::RuntimeSelected
107 }
108
109 pub fn pinned_dag_id(&self) -> Option<sui::types::Address> {
110 match self {
111 Self::Pinned { dag_id } => Some(*dag_id),
112 Self::RuntimeSelected => None,
113 }
114 }
115}
116
117#[allow(clippy::derivable_impls)]
118impl Default for SkillSchedulePolicy {
119 fn default() -> Self {
120 Self::Once
121 }
122}
123
124impl FixedTool {
125 pub fn tool_registry_address(&self) -> sui::types::Address {
126 self.tool_registry_id.into()
127 }
128
129 pub fn tool_fqn_string(&self) -> String {
130 self.tool_fqn.clone().into()
131 }
132}
133
134#[allow(clippy::derivable_impls)]
135impl Default for SkillRequirement {
136 fn default() -> Self {
137 Self {
138 input_commitment: Vec::new(),
139 payment_policy: SkillPaymentPolicy::default(),
140 schedule_policy: SkillSchedulePolicy::default(),
141 fixed_tools: Vec::new(),
142 }
143 }
144}
145
146impl SkillRecord {
147 pub fn description_bytes(&self) -> &[u8] {
148 &self.description
149 }
150}
151
152impl Agent {
153 pub fn object_id(&self) -> AgentId {
154 self.id.clone().into()
155 }
156
157 pub fn from_anchor(agent_id: AgentId) -> Self {
159 Self {
160 id: UID::new(agent_id),
161 }
162 }
163}
164
165impl AgentInnerV1 {
166 pub fn registry_id(&self) -> Option<sui::types::Address> {
167 self.registry_id.as_option().map(|id| id.bytes)
168 }
169}
170
171impl DefaultDagExecutor {
172 pub fn target(&self) -> DefaultDagExecutorTarget {
173 DefaultDagExecutorTarget {
174 agent_id: self.agent.object_id(),
175 skill_id: self.skill_id,
176 }
177 }
178}
179
180#[allow(clippy::derivable_impls)]
181impl Default for DefaultDagExecutorFieldKey {
182 fn default() -> Self {
183 Self { dummy_field: false }
184 }
185}
186
187impl AgentPaymentVault {
188 pub fn object_id(&self) -> AgentId {
189 self.id.id.bytes
190 }
191}
192
193impl AgentPaymentVaultInnerV1 {
194 pub fn agent_id_address(&self) -> AgentId {
195 self.agent_id.bytes
196 }
197
198 pub fn available_balance_value(&self) -> u64 {
199 self.available_balance.value
200 }
201}
202
203#[allow(clippy::derivable_impls)]
204impl Default for DagExecutionPaymentFieldKey {
205 fn default() -> Self {
206 Self { dummy_field: false }
207 }
208}
209
210#[allow(clippy::derivable_impls)]
211impl Default for AgentVaultFieldKey {
212 fn default() -> Self {
213 Self { dummy_field: false }
214 }
215}