-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
1195 lines (995 loc) · 38.5 KB
/
example.py
File metadata and controls
1195 lines (995 loc) · 38.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
SailBE SDK API Example - Python
This script demonstrates how to:
1. Authenticate using direct or SIWE wallet signatures
2. Use JWT tokens for subsequent API requests
3. Call all available SDK endpoints
Requirements:
pip install eth-account requests
"""
import os
import requests
from eth_account import Account
from eth_account.messages import encode_defunct
from typing import Optional, Dict, Any, List
import json
try:
from dotenv import load_dotenv
load_dotenv()
except ImportError:
pass
# ============================================================================
# CONFIGURATION
# ============================================================================
# Base URL of the Sail API server
# Production API URL: https://app.sail.money/prod
BASE_URL = os.getenv("SAIL_API_URL", "https://app.sail.money/prod")
# Project and Page IDs
# Default values for Sail production
PROJECT_ID = os.getenv("SAIL_PROJECT_ID", "sail")
PAGE_ID = os.getenv("SAIL_PAGE_ID", "home")
# Wallet configuration
# IMPORTANT: Never commit private keys to version control!
# Get your private key from: https://sail.money/manage-wallet/7702
# Use environment variables or secure key management in production
PRIVATE_KEY = os.getenv("SAIL_PRIVATE_KEY", "0x" + "0" * 64) # Replace with your private key
WALLET_ADDRESS = None # Will be derived from private key
# ============================================================================
# HELPER FUNCTIONS
# ============================================================================
def sign_message(message: str, private_key: str) -> str:
"""
Sign a message using Ethereum private key.
Args:
message: The message to sign
private_key: Private key in hex format (with or without 0x prefix)
Returns:
Signature in hex format
"""
# Ensure private key has 0x prefix
if not private_key.startswith("0x"):
private_key = "0x" + private_key
# Create account from private key
account = Account.from_key(private_key)
# Encode message for signing
message_encoded = encode_defunct(text=message)
# Sign message
signed_message = account.sign_message(message_encoded)
# Return signature
return signed_message.signature.hex()
def get_wallet_address(private_key: str) -> str:
"""
Get wallet address from private key.
Args:
private_key: Private key in hex format
Returns:
Wallet address in hex format
"""
if not private_key.startswith("0x"):
private_key = "0x" + private_key
account = Account.from_key(private_key)
return account.address
# ============================================================================
# API CLIENT CLASS
# ============================================================================
class SailAPIClient:
"""Client for interacting with SailBE SDK API."""
def __init__(self, base_url: str, project_id: str, page_id: str, token: Optional[str] = None):
"""
Initialize the API client.
Args:
base_url: Base URL of the API server
project_id: Project ID
page_id: Page ID
token: Optional JWT token (if already authenticated)
"""
self.base_url = base_url.rstrip("/")
self.project_id = project_id
self.page_id = page_id
self.token = token
self.base_path = f"/api/v1/projects/{project_id}/pages/{page_id}"
def _get_headers(self) -> Dict[str, str]:
"""Get request headers with authentication."""
headers = {"Content-Type": "application/json"}
if self.token:
headers["Authorization"] = f"Bearer {self.token}"
return headers
def _request(self, method: str, endpoint: str, **kwargs) -> Dict[str, Any]:
"""
Make an API request.
Args:
method: HTTP method (GET, POST, PUT, etc.)
endpoint: API endpoint path
**kwargs: Additional arguments to pass to requests
Returns:
Response JSON as dictionary
"""
url = f"{self.base_url}{self.base_path}{endpoint}"
headers = self._get_headers()
if "headers" in kwargs:
headers.update(kwargs.pop("headers"))
response = requests.request(method, url, headers=headers, **kwargs)
response.raise_for_status()
return response.json()
# ========================================================================
# AUTHENTICATION
# ========================================================================
def authenticate(
self,
wallet_address: str,
signature: Optional[str] = None,
auth_payload: Optional[str] = None,
domain: Optional[str] = None
) -> Dict[str, Any]:
"""
Authenticate using wallet signature.
Args:
wallet_address: Wallet address
signature: Signature of the authentication payload
auth_payload: Authentication payload returned from the first direct-auth step
domain: Optional SIWE domain override
Returns:
Authentication response with token
"""
url = f"{self.base_url}{self.base_path}/authenticate"
payload = {
"walletAddress": wallet_address,
}
if signature:
payload["signature"] = signature
if auth_payload:
payload["payload"] = auth_payload
if domain:
payload["domain"] = domain
response = requests.post(url, json=payload)
response.raise_for_status()
result = response.json()
# Store token for future requests
if result.get("token"):
self.token = result.get("token")
return result
def request_direct_auth_payload(
self,
wallet_address: str,
domain: Optional[str] = None
) -> Dict[str, Any]:
"""
Request the unique direct-auth payload for a smart account wallet.
Args:
wallet_address: Smart account wallet address
domain: Optional SIWE domain override
Returns:
Direct-auth payload response containing `payload` and optional `instructionMessage`
"""
return self.authenticate(wallet_address=wallet_address, domain=domain)
def complete_direct_auth(
self,
wallet_address: str,
signature: str,
auth_payload: str,
domain: Optional[str] = None
) -> Dict[str, Any]:
"""
Complete direct authentication with the signed direct-auth payload.
Args:
wallet_address: Smart account wallet address
signature: Signature over the direct-auth payload
auth_payload: Payload returned by `request_direct_auth_payload`
domain: Optional SIWE domain override
Returns:
Authentication response with token
"""
return self.authenticate(
wallet_address=wallet_address,
signature=signature,
auth_payload=auth_payload,
domain=domain,
)
def initiate_siwe_auth(
self,
address: str,
chain_id: int = 8453,
domain: Optional[str] = None,
identity_mode: str = "byWallet"
) -> Dict[str, Any]:
"""
Start custom SIWE authentication.
Args:
address: Admin signer wallet address
chain_id: Chain ID used to render the SIWE message
domain: Optional SIWE domain override
identity_mode: Identity mode (`byWallet` recommended, `byUser` legacy only)
Returns:
SIWE auth session containing `sessionId` and `message`
"""
url = f"{self.base_url}{self.base_path}/auth/initiate"
payload: Dict[str, Any] = {
"method": "siwe",
"address": address,
"chainId": chain_id,
"identityMode": identity_mode,
}
if domain:
payload["domain"] = domain
response = requests.post(url, json=payload)
response.raise_for_status()
return response.json()
def complete_siwe_auth(
self,
session_id: str,
signature: str,
wallet_address: str,
identity_mode: str = "byWallet"
) -> Dict[str, Any]:
"""
Complete custom SIWE authentication.
Args:
session_id: Session ID returned by `initiate_siwe_auth`
signature: Signature over the SIWE message
wallet_address: Admin signer wallet address
identity_mode: Identity mode used during initiation
Returns:
Authentication response with token
"""
url = f"{self.base_url}{self.base_path}/auth/complete"
payload = {
"method": "siwe",
"sessionId": session_id,
"signature": signature,
"walletAddress": wallet_address,
"identityMode": identity_mode,
}
response = requests.post(url, json=payload)
response.raise_for_status()
result = response.json()
self.token = result.get("token")
return result
# ========================================================================
# BALANCE
# ========================================================================
def get_balance(
self,
token_address: Optional[str] = None,
chain_id: Optional[int] = None
) -> Dict[str, Any]:
"""
Get balance for a wallet.
Wallet address is extracted from JWT token, not from parameters.
Args:
token_address: Optional token address
chain_id: Optional chain ID
Returns:
Balance information
"""
params = {}
if token_address:
params["tokenAddress"] = token_address
if chain_id:
params["chainId"] = chain_id
return self._request("GET", "/balance", params=params)
# ========================================================================
# METRICS
# ========================================================================
def get_metrics(
self,
endpoint_id: str,
params: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]:
"""
Execute a configured metrics endpoint.
Args:
endpoint_id: Metrics endpoint ID
params: Optional query params passed through to the configured tool/graph
Returns:
Metrics response shaped like {"message": str, "result": object}
"""
return self._request("GET", f"/metrics/{endpoint_id}", params=params or {})
def get_metrics_balance(self, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
return self.get_metrics("balance", params=params)
def get_metrics_earnings(self, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
return self.get_metrics("earnings", params=params)
def get_metrics_history(self, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
return self.get_metrics("history", params=params)
def get_metrics_portfolio(self, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
return self.get_metrics("portfolio", params=params)
def get_metrics_user_metrics(self, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
return self.get_metrics("user-metrics", params=params)
def get_metrics_yield(self, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
return self.get_metrics("yield", params=params)
# ========================================================================
# DEPOSIT
# ========================================================================
def deposit(
self,
amount: str,
token_address: Optional[str] = None,
chain_id: Optional[int] = None
) -> Dict[str, Any]:
"""
Deposit funds.
Wallet address is extracted from JWT token, not from parameters.
Args:
amount: Amount to deposit (human-readable format, e.g., '1' for 1 ETH, '10' for 10 USDC)
token_address: Optional token address
chain_id: Optional chain ID
Returns:
Deposit response
"""
payload = {
"amount": amount
}
if token_address:
payload["tokenAddress"] = token_address
if chain_id:
payload["chainId"] = chain_id
return self._request("POST", "/deposit", json=payload)
def get_deposit_info(self) -> Dict[str, Any]:
"""
Get deposit information.
Wallet address is extracted from JWT token, not from parameters.
Returns:
Deposit info including balance, permitted tokens, etc.
"""
return self._request("GET", "/deposit-info")
def pre_deposit_hooks(
self,
amount: str,
token_address: Optional[str] = None,
chain_id: Optional[int] = None
) -> Dict[str, Any]:
"""
Execute pre-deposit hooks.
Wallet address is extracted from JWT token, not from parameters.
Args:
amount: Amount to deposit (human-readable format, e.g., '1' for 1 ETH, '10' for 10 USDC)
token_address: Optional token address
chain_id: Optional chain ID
Returns:
Pre-deposit hooks response
"""
payload = {
"amount": amount
}
if token_address:
payload["tokenAddress"] = token_address
if chain_id:
payload["chainId"] = chain_id
return self._request("POST", "/deposit/pre-hooks", json=payload)
def post_deposit_hooks(
self,
amount: str,
tx_hash: str,
token_address: Optional[str] = None,
chain_id: Optional[int] = None,
status: str = "success"
) -> Dict[str, Any]:
"""
Execute post-deposit hooks.
Wallet address is extracted from JWT token, not from parameters.
Args:
amount: Amount that was deposited (human-readable format, e.g., '1' for 1 ETH, '10' for 10 USDC)
tx_hash: Transaction hash
token_address: Optional token address
chain_id: Optional chain ID
status: Transaction status ("success" or "error")
Returns:
Post-deposit hooks response
"""
payload = {
"amount": amount,
"txHash": tx_hash,
"status": status
}
if token_address:
payload["tokenAddress"] = token_address
if chain_id:
payload["chainId"] = chain_id
return self._request("POST", "/deposit/post-hooks", json=payload)
# ========================================================================
# WITHDRAW
# ========================================================================
def withdraw(
self,
amount: str,
token_address: Optional[str] = None,
chain_id: Optional[int] = None
) -> Dict[str, Any]:
"""
Withdraw funds.
Wallet address is extracted from JWT token, not from parameters.
Args:
amount: Amount to withdraw (human-readable format, e.g., '1' for 1 ETH, '10' for 10 USDC)
token_address: Optional token address
chain_id: Optional chain ID
Returns:
Withdraw response
"""
payload = {
"amount": amount
}
if token_address:
payload["tokenAddress"] = token_address
if chain_id:
payload["chainId"] = chain_id
return self._request("POST", "/withdraw", json=payload)
def get_withdraw_info(self) -> Dict[str, Any]:
"""
Get withdraw information.
Wallet address is extracted from JWT token, not from parameters.
Returns:
Withdraw info including balance, permitted tokens, etc.
"""
return self._request("GET", "/withdraw-info")
def pre_withdraw_hooks(
self,
amount: str,
recipient: str,
token_address: Optional[str] = None,
chain_id: Optional[int] = None
) -> Dict[str, Any]:
"""
Execute pre-withdraw hooks.
Wallet address is extracted from JWT token, not from parameters.
Args:
amount: Amount to withdraw (human-readable format, e.g., '1' for 1 ETH, '10' for 10 USDC)
recipient: Recipient address for the withdrawal
token_address: Optional token address
chain_id: Optional chain ID
Returns:
Pre-withdraw hooks response
"""
payload = {
"amount": amount,
"recipient": recipient
}
if token_address:
payload["tokenAddress"] = token_address
if chain_id:
payload["chainId"] = chain_id
return self._request("POST", "/withdraw/pre-hooks", json=payload)
def post_withdraw_hooks(
self,
amount: str,
tx_hash: str,
recipient: str,
token_address: Optional[str] = None,
chain_id: Optional[int] = None,
status: str = "success"
) -> Dict[str, Any]:
"""
Execute post-withdraw hooks.
Wallet address is extracted from JWT token, not from parameters.
Args:
amount: Amount that was withdrawn (human-readable format, e.g., '1' for 1 ETH, '10' for 10 USDC)
tx_hash: Transaction hash
recipient: Recipient address for the withdrawal
token_address: Optional token address
chain_id: Optional chain ID
status: Transaction status ("success" or "error")
Returns:
Post-withdraw hooks response
"""
payload = {
"amount": amount,
"txHash": tx_hash,
"recipient": recipient,
"status": status
}
if token_address:
payload["tokenAddress"] = token_address
if chain_id:
payload["chainId"] = chain_id
return self._request("POST", "/withdraw/post-hooks", json=payload)
# ========================================================================
# PORTFOLIO
# ========================================================================
def get_portfolio_total_balance(self) -> Dict[str, Any]:
"""
Get total portfolio balance.
Wallet address is extracted from JWT token, not from parameters.
Returns:
Total portfolio balance
"""
return self._request("GET", "/portfolio/total-balance")
def get_portfolio_tokens(self) -> Dict[str, Any]:
"""
Get portfolio token balances.
Wallet address is extracted from JWT token, not from parameters.
Returns:
List of token balances
"""
return self._request("GET", "/portfolio/tokens")
# ========================================================================
# SESSION KEYS
# ========================================================================
def sign_permitted_keys(
self,
wallet_address: str,
signatures: Dict[str, str],
session_specs: Dict[str, Dict[str, Any]],
owner_eoa: Optional[str] = None,
backend_wallet_transaction_hashes: Optional[Dict[str, str]] = None,
approval_transaction_hashes: Optional[Dict[str, str]] = None,
approvals: Optional[List[Dict[str, Any]]] = None
) -> Dict[str, Any]:
"""
Sign permitted session keys.
Args:
wallet_address: Smart account address
signatures: Dictionary mapping sessionKeyId to signature
session_specs: Dictionary mapping sessionKeyId to sessionSpec
owner_eoa: Optional EOA owner address (for ERC-7702)
backend_wallet_transaction_hashes: Optional transaction hashes
approval_transaction_hashes: Optional approval transaction hashes
approvals: Optional list of approvals
Returns:
Sign permitted keys response
"""
payload = {
"walletAddress": wallet_address,
"signatures": signatures,
"sessionSpecs": session_specs
}
if owner_eoa:
payload["ownerEOA"] = owner_eoa
if backend_wallet_transaction_hashes:
payload["backendWalletTransactionHashes"] = backend_wallet_transaction_hashes
if approval_transaction_hashes:
payload["approvalTransactionHashes"] = approval_transaction_hashes
if approvals:
payload["approvals"] = approvals
return self._request("POST", "/sign-permitted-keys", json=payload)
def get_permitted_keys_for_signing(self) -> Dict[str, Any]:
"""
Get permitted keys available for signing.
Wallet address is extracted from JWT token, not from parameters.
Returns:
Permitted keys information
"""
return self._request("GET", "/get-permitted-keys-for-signing")
def check_remaining_authorizations(self) -> Dict[str, Any]:
"""
Check remaining authorizations.
Wallet address is extracted from JWT token, not from parameters.
Returns:
Remaining authorizations information
"""
return self._request("GET", "/check-remaining-authorizations")
def get_session_keys_display(self) -> Dict[str, Any]:
"""
Get session keys display information.
Wallet address is extracted from JWT token, not from parameters.
Returns:
Session keys display information
"""
return self._request("GET", "/session-keys-display")
def enable_delegation(
self,
chain_id: int,
delegation_data: str
) -> Dict[str, Any]:
"""
Enable delegation.
Wallet address is extracted from JWT token, not from parameters.
Args:
chain_id: Chain ID
delegation_data: Encoded enableDelegation transaction data (hex string with 0x prefix)
Returns:
Enable delegation response
"""
payload = {
"chainId": chain_id,
"delegationData": delegation_data
}
return self._request("POST", "/enable-delegation", json=payload)
def check_bulk_authorization_status(
self,
session_key_ids: List[str]
) -> Dict[str, Any]:
"""
Check bulk authorization status for session keys.
Wallet address is extracted from JWT token, not from parameters.
Args:
session_key_ids: List of session key IDs
Returns:
Bulk authorization status
"""
payload = {
"sessionKeyIds": session_key_ids
}
# This endpoint is at a different path
url = f"{self.base_url}/api/v1/session-key/check-bulk-authorization-status"
headers = self._get_headers()
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
return response.json()
# ========================================================================
# AUTOMATION
# ========================================================================
def get_automation_status(self) -> Dict[str, Any]:
"""
Get automation job status.
Wallet address is extracted from JWT token, not from parameters.
Returns:
Automation status
"""
return self._request("GET", "/automation/status")
def start_automation(
self,
graph_id: str,
prompt: str,
param_values: Optional[Dict[str, Any]] = None,
iterations: Optional[int] = 1,
branch_id: Optional[str] = None
) -> Dict[str, Any]:
"""
Start automation job.
Wallet address is extracted from JWT token, not from parameters.
Args:
graph_id: Graph ID to run
prompt: Prompt/message for the graph
param_values: Optional parameter values
iterations: Number of iterations
branch_id: Optional branch ID
Returns:
Start automation response
"""
payload = {
"graphId": graph_id,
"prompt": prompt,
"iterations": iterations
}
if param_values:
payload["paramValues"] = param_values
if branch_id:
payload["branchId"] = branch_id
return self._request("POST", "/automation/start", json=payload)
def pause_automation(self) -> Dict[str, Any]:
"""
Pause automation job.
Wallet address is extracted from JWT token, not from parameters.
Returns:
Pause automation response
"""
return self._request("POST", "/automation/pause")
def resume_automation(self) -> Dict[str, Any]:
"""
Resume automation job.
Wallet address is extracted from JWT token, not from parameters.
Returns:
Resume automation response
"""
return self._request("POST", "/automation/resume")
def stop_automation(self) -> Dict[str, Any]:
"""
Stop automation job.
Wallet address is extracted from JWT token, not from parameters.
Returns:
Stop automation response
"""
return self._request("POST", "/automation/stop")
# ========================================================================
# CHATBOT
# ========================================================================
def get_chatbots(self) -> Dict[str, Any]:
"""
Get list of chatbots.
Wallet address is extracted from JWT token, not from parameters.
Returns:
List of chatbots
"""
return self._request("GET", "/chatbots")
def get_chatbot_memories(
self,
graph_id: str,
page: Optional[int] = 1,
limit: Optional[int] = 20
) -> Dict[str, Any]:
"""
Get chatbot memories.
Wallet address is extracted from JWT token, not from parameters.
Args:
graph_id: Graph ID (chatbot graph ID)
page: Page number (default: 1)
limit: Items per page (default: 20)
Returns:
Chatbot memories
"""
params = {
"graphId": graph_id,
"page": page,
"limit": limit
}
return self._request("GET", "/chatbot-memories", params=params)
# ========================================================================
# GRAPH
# ========================================================================
def run_graph(
self,
graph_id: str,
prompt: str,
param_values: Optional[Dict[str, Any]] = None,
iterations: Optional[int] = 1,
branch_id: Optional[str] = None,
include_context_report: Optional[bool] = False,
context_data: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]:
"""
Run a graph execution.
Wallet address is extracted from JWT token, not from parameters.
Args:
graph_id: Graph ID
prompt: User prompt/message
param_values: Optional parameter values
iterations: Number of iterations (default: 1)
branch_id: Optional branch ID
include_context_report: Include context report
context_data: Optional context data
Returns:
Graph execution results
"""
payload = {
"id": graph_id,
"prompt": prompt,
"iterations": iterations,
"includeContextReport": include_context_report
}
if param_values:
payload["paramValues"] = param_values
if branch_id:
payload["branchId"] = branch_id
if context_data:
payload["contextData"] = context_data
return self._request("POST", "/run-graph", json=payload)
# ========================================================================
# PROFILE
# ========================================================================
def get_profile(self) -> Dict[str, Any]:
"""
Get user profile.
Wallet address is extracted from JWT token, not from parameters.
Returns:
User profile
"""
return self._request("GET", "/profile")
def update_profile(
self,
profile_data: Dict[str, Any]
) -> Dict[str, Any]:
"""
Update user profile.
Wallet address is extracted from JWT token, not from parameters.
Args:
profile_data: Profile data to update
Returns:
Updated profile
"""
return self._request("PUT", "/profile", json=profile_data)
def upload_profile_avatar(
self,
file_path: str
) -> Dict[str, Any]:
"""
Upload profile avatar.
Wallet address is extracted from JWT token, not from parameters.
Args:
file_path: Path to image file
Returns:
Upload response
"""
url = f"{self.base_url}{self.base_path}/profile/avatar"
headers = {}
if self.token:
headers["Authorization"] = f"Bearer {self.token}"
with open(file_path, "rb") as f:
files = {"file": f}
response = requests.post(url, headers=headers, files=files)
response.raise_for_status()
return response.json()
def upload_profile_banner(
self,
file_path: str
) -> Dict[str, Any]:
"""
Upload profile banner.
Wallet address is extracted from JWT token, not from parameters.
Args:
file_path: Path to image file
Returns:
Upload response
"""
url = f"{self.base_url}{self.base_path}/profile/banner"
headers = {}
if self.token:
headers["Authorization"] = f"Bearer {self.token}"
with open(file_path, "rb") as f:
files = {"file": f}
response = requests.post(url, headers=headers, files=files)
response.raise_for_status()
return response.json()
# ========================================================================
# PAGE
# ========================================================================
def get_page(self) -> Dict[str, Any]:
"""
Get page information.
Returns:
Page data including title, project info, authConfig, themeConfig
"""
return self._request("GET", "/page")
def get_pages(
self,
project_id: Optional[str] = None,
limit: Optional[int] = 100,
offset: Optional[int] = 0
) -> Dict[str, Any]:
"""
Get list of pages.
Args:
project_id: Optional project ID filter
limit: Maximum number of results (default: 100)
offset: Offset for pagination (default: 0)