vnai 2.1.7__py3-none-any.whl → 2.1.8__py3-none-any.whl

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.
vnai/__init__.py CHANGED
@@ -1,178 +1,240 @@
1
- import os
2
- import pathlib
3
- import json
4
- import time
5
- import threading
6
- import functools
7
- from datetime import datetime
8
- from vnai.beam.quota import guardian, optimize
9
- from vnai.beam.metrics import collector, capture
10
- from vnai.beam.pulse import monitor
11
- from vnai.flow.relay import conduit, configure
12
- from vnai.flow.queue import buffer
13
- from vnai.scope.profile import inspector
14
- from vnai.scope.state import tracker, record
15
- import vnai.scope.promo
16
- from vnai.scope.promo import present
17
- TC_VAR ="ACCEPT_TC"
18
- TC_VAL ="tôi đồng ý"
19
- TC_PATH = pathlib.Path.home() /".vnstock" /"id" /"terms_agreement.txt"
20
- TERMS_AND_CONDITIONS ="""
21
- Khi tiếp tục sử dụng Vnstock, bạn xác nhận rằng bạn đã đọc, hiểu và đồng ý với Chính sách quyền riêng tư và Điều khoản, điều kiện về giấy phép sử dụng Vnstock.
22
- Chi tiết:
23
- - Giấy phép sử dụng phần mềm: https://vnstocks.com/docs/tai-lieu/giay-phep-su-dung
24
- - Chính sách quyền riêng tư: https://vnstocks.com/docs/tai-lieu/chinh-sach-quyen-rieng-tu
25
- """
26
-
27
- class Core:
28
- def __init__(self):
29
- self.initialized = False
30
- self.webhook_url = None
31
- self.init_time = datetime.now().isoformat()
32
- self.home_dir = pathlib.Path.home()
33
- self.project_dir = self.home_dir /".vnstock"
34
- self.id_dir = self.project_dir /'id'
35
- self.terms_file_path = TC_PATH
36
- self.system_info = None
37
- self.project_dir.mkdir(exist_ok=True)
38
- self.id_dir.mkdir(exist_ok=True)
39
- self.initialize()
40
-
41
- def initialize(self, webhook_url=None):
42
- if self.initialized:
43
- return True
44
- if not self._check_terms():
45
- self._accept_terms()
46
- from vnai.scope.profile import inspector
47
- inspector.setup_vnstock_environment()
48
- present()
49
- if webhook_url:
50
- self.webhook_url = webhook_url
51
- configure(webhook_url)
52
- record("initialization", {"timestamp": datetime.now().isoformat()})
53
- self.system_info = inspector.examine()
54
- conduit.queue({
55
- "type":"system_info",
56
- "data": {
57
- "commercial": inspector.detect_commercial_usage(),
58
- "packages": inspector.scan_packages()
59
- }
60
- }, priority="high")
61
- self.initialized = True
62
- return True
63
-
64
- def _check_terms(self):
65
- return os.path.exists(self.terms_file_path)
66
-
67
- def _accept_terms(self):
68
- system_info = inspector.examine()
69
- if TC_VAR in os.environ and os.environ[TC_VAR] == TC_VAL:
70
- response = TC_VAL
71
- else:
72
- response = TC_VAL
73
- os.environ[TC_VAR] = TC_VAL
74
- now = datetime.now()
75
- signed_agreement = (
76
- f"Người dùng có mã nhận dạng {system_info['machine_id']} đã chấp nhận "
77
- f"điều khoản & điều kiện sử dụng Vnstock lúc {now}\n"
78
- f"---\n\n"
79
- f"THÔNG TIN THIẾT BỊ: {json.dumps(system_info, indent=2)}\n\n"
80
- f"Đính kèm bản sao nội dung bạn đã đọc, hiểu rõ và đồng ý dưới đây:\n"
81
- f"{TERMS_AND_CONDITIONS}"
82
- )
83
- with open(self.terms_file_path,"w", encoding="utf-8") as f:
84
- f.write(signed_agreement)
85
- env_file = self.id_dir /"environment.json"
86
- env_data = {
87
- "accepted_agreement": True,
88
- "timestamp": now.isoformat(),
89
- "machine_id": system_info['machine_id']
90
- }
91
- with open(env_file,"w") as f:
92
- json.dump(env_data, f)
93
- return True
94
-
95
- def status(self):
96
- return {
97
- "initialized": self.initialized,
98
- "health": monitor.report(),
99
- "metrics": tracker.get_metrics()
100
- }
101
-
102
- def configure_privacy(self, level="standard"):
103
- from vnai.scope.state import tracker
104
- return tracker.setup_privacy(level)
105
- core = Core()
106
-
107
- def tc_init(webhook_url=None):
108
- return core.initialize(webhook_url)
109
-
110
- def setup(webhook_url=None):
111
- return core.initialize(webhook_url)
112
-
113
- def optimize_execution(resource_type="default"):
114
- return optimize(resource_type)
115
-
116
- def agg_execution(resource_type="default"):
117
- return optimize(resource_type, ad_cooldown=1500, content_trigger_threshold=100000)
118
-
119
- def measure_performance(module_type="function"):
120
- return capture(module_type)
121
-
122
- def accept_license_terms(terms_text=None):
123
- if terms_text is None:
124
- terms_text = TERMS_AND_CONDITIONS
125
- system_info = inspector.examine()
126
- terms_file = pathlib.Path.home() /".vnstock" /"id" /"terms_agreement.txt"
127
- os.makedirs(os.path.dirname(terms_file), exist_ok=True)
128
- with open(terms_file,"w", encoding="utf-8") as f:
129
- f.write(f"Terms accepted at {datetime.now().isoformat()}\n")
130
- f.write(f"System: {json.dumps(system_info)}\n\n")
131
- f.write(terms_text)
132
- return True
133
-
134
- def accept_vnstock_terms():
135
- from vnai.scope.profile import inspector
136
- system_info = inspector.examine()
137
- home_dir = pathlib.Path.home()
138
- project_dir = home_dir /".vnstock"
139
- project_dir.mkdir(exist_ok=True)
140
- id_dir = project_dir /'id'
141
- id_dir.mkdir(exist_ok=True)
142
- env_file = id_dir /"environment.json"
143
- env_data = {
144
- "accepted_agreement": True,
145
- "timestamp": datetime.now().isoformat(),
146
- "machine_id": system_info['machine_id']
147
- }
148
- try:
149
- with open(env_file,"w") as f:
150
- json.dump(env_data, f)
151
- print("Vnstock terms accepted successfully.")
152
- return True
153
- except Exception as e:
154
- print(f"Error accepting terms: {e}")
155
- return False
156
-
157
- def configure_privacy(level="standard"):
158
- from vnai.scope.state import tracker
159
- return tracker.setup_privacy(level)
160
-
161
- def check_commercial_usage():
162
- from vnai.scope.profile import inspector
163
- return inspector.detect_commercial_usage()
164
-
165
- def authenticate_for_persistence():
166
- from vnai.scope.profile import inspector
167
- return inspector.get_or_create_user_id()
168
-
169
- def display_content():
170
- return present()
171
-
172
- def configure_webhook(webhook_id=''):
173
- if not webhook_id:
174
- return False
175
- from vnai.flow.relay import configure
176
- webhook_url =f'https://botbuilder.larksuite.com/api/trigger-webhook/{webhook_id}'
177
- return configure(webhook_url)
178
- configure_webhook()
1
+ # vnai/__init__.py
2
+ # Main entry point for vnai package
3
+
4
+ import os
5
+ import pathlib
6
+ import json
7
+ import time
8
+ import threading
9
+ import functools
10
+ from datetime import datetime
11
+
12
+ # Import core functionality
13
+ from vnai.beam.quota import guardian, optimize
14
+ from vnai.beam.metrics import collector, capture
15
+ from vnai.beam.pulse import monitor
16
+ from vnai.flow.relay import conduit
17
+ from vnai.flow.queue import buffer
18
+ from vnai.scope.profile import inspector
19
+ from vnai.scope.state import tracker, record
20
+ import vnai.scope.promo
21
+ from vnai.scope.promo import present
22
+
23
+ # Constants for terms and conditions
24
+ TC_VAR = "ACCEPT_TC"
25
+ TC_VAL = "tôi đồng ý"
26
+ TC_PATH = pathlib.Path.home() / ".vnstock" / "id" / "terms_agreement.txt"
27
+
28
+ TERMS_AND_CONDITIONS = """
29
+ Khi tiếp tục sử dụng Vnstock, bạn xác nhận rằng bạn đã đọc, hiểu và đồng ý với Chính sách quyền riêng tư và Điều khoản, điều kiện về giấy phép sử dụng Vnstock.
30
+
31
+ Chi tiết:
32
+ - Giấy phép sử dụng phần mềm: https://vnstocks.com/docs/tai-lieu/giay-phep-su-dung
33
+ - Chính sách quyền riêng tư: https://vnstocks.com/docs/tai-lieu/chinh-sach-quyen-rieng-tu
34
+ """
35
+
36
+ class Core:
37
+ """Core functionality for system optimization"""
38
+
39
+ def __init__(self):
40
+ """Initialize core"""
41
+ self.initialized = False
42
+ self.webhook_url = None
43
+ self.init_time = datetime.now().isoformat()
44
+ self.home_dir = pathlib.Path.home()
45
+ self.project_dir = self.home_dir / ".vnstock"
46
+ self.id_dir = self.project_dir / 'id'
47
+ self.terms_file_path = TC_PATH
48
+ self.system_info = None
49
+
50
+ # Create necessary directories
51
+ self.project_dir.mkdir(exist_ok=True)
52
+ self.id_dir.mkdir(exist_ok=True)
53
+
54
+ # Auto-initialize
55
+ self.initialize()
56
+
57
+ def initialize(self):
58
+ """Initialize the system"""
59
+ if self.initialized:
60
+ return True
61
+
62
+ # Check terms acceptance
63
+ if not self._check_terms():
64
+ self._accept_terms()
65
+
66
+ # Set up vnstock environment
67
+ from vnai.scope.profile import inspector
68
+ inspector.setup_vnstock_environment()
69
+
70
+ # Display content during initialization
71
+ from vnai.scope.promo import ContentManager
72
+ manager = ContentManager()
73
+ # Chỉ hiện ads nếu chắc chắn là free user
74
+ if manager.is_paid_user is False and getattr(manager, 'license_checked', False):
75
+ present()
76
+
77
+ # Record initialization
78
+ record("initialization", {"timestamp": datetime.now().isoformat()})
79
+
80
+ # Get system information ONCE and store it in the class
81
+ self.system_info = inspector.examine()
82
+
83
+ # Queue system data with optimal structure
84
+ conduit.queue({
85
+ "type": "system_info",
86
+ "data": {
87
+ "commercial": inspector.detect_commercial_usage(),
88
+ "packages": inspector.scan_packages()
89
+ }
90
+ }, priority="high")
91
+
92
+ self.initialized = True
93
+ return True
94
+
95
+ def _check_terms(self):
96
+ """Check if terms have been accepted"""
97
+ return os.path.exists(self.terms_file_path)
98
+
99
+ def _accept_terms(self):
100
+ """Record terms acceptance"""
101
+ # Get system information
102
+ system_info = inspector.examine()
103
+
104
+ # Auto-accept terms
105
+ if TC_VAR in os.environ and os.environ[TC_VAR] == TC_VAL:
106
+ response = TC_VAL
107
+ else:
108
+ # For non-interactive environments, accept by default
109
+ response = TC_VAL
110
+ os.environ[TC_VAR] = TC_VAL
111
+
112
+ # Store the acceptance with hardware info
113
+ now = datetime.now()
114
+ signed_agreement = (
115
+ f"Người dùng có mã nhận dạng {system_info['machine_id']} đã chấp nhận "
116
+ f"điều khoản & điều kiện sử dụng Vnstock lúc {now}\n"
117
+ f"---\n\n"
118
+ f"THÔNG TIN THIẾT BỊ: {json.dumps(system_info, indent=2)}\n\n"
119
+ f"Đính kèm bản sao nội dung bạn đã đọc, hiểu rõ và đồng ý dưới đây:\n"
120
+ f"{TERMS_AND_CONDITIONS}"
121
+ )
122
+
123
+ # Store the acceptance
124
+ with open(self.terms_file_path, "w", encoding="utf-8") as f:
125
+ f.write(signed_agreement)
126
+
127
+ # Create the environment.json file that vnstock expects
128
+ env_file = self.id_dir / "environment.json"
129
+ env_data = {
130
+ "accepted_agreement": True,
131
+ "timestamp": now.isoformat(),
132
+ "machine_id": system_info['machine_id']
133
+ }
134
+
135
+ with open(env_file, "w") as f:
136
+ json.dump(env_data, f)
137
+
138
+ return True
139
+
140
+ def status(self):
141
+ """Get system status"""
142
+ return {
143
+ "initialized": self.initialized,
144
+ "health": monitor.report(),
145
+ "metrics": tracker.get_metrics()
146
+ # Environment information available via self.system_info
147
+ }
148
+
149
+ def configure_privacy(self, level="standard"):
150
+ """Configure privacy settings"""
151
+ from vnai.scope.state import tracker
152
+ return tracker.setup_privacy(level)
153
+
154
+
155
+ # Create singleton instance
156
+ core = Core()
157
+
158
+ # Backward support
159
+ def tc_init():
160
+ return core.initialize()
161
+
162
+ def setup():
163
+ """Setup vnai"""
164
+ return core.initialize()
165
+
166
+ def optimize_execution(resource_type="default"):
167
+ """Decorator for optimizing function execution"""
168
+ return optimize(resource_type)
169
+
170
+ def agg_execution(resource_type="default"):
171
+ """Decorator for aggregating function execution"""
172
+ return optimize(resource_type, ad_cooldown=1500, content_trigger_threshold=100000)
173
+
174
+ def measure_performance(module_type="function"):
175
+ """Decorator for measuring function performance"""
176
+ return capture(module_type)
177
+
178
+ def accept_license_terms(terms_text=None):
179
+ """Accept license terms and conditions"""
180
+ if terms_text is None:
181
+ terms_text = TERMS_AND_CONDITIONS
182
+
183
+ # Get system information
184
+ system_info = inspector.examine()
185
+
186
+ # Record acceptance
187
+ terms_file = pathlib.Path.home() / ".vnstock" / "id" / "terms_agreement.txt"
188
+ os.makedirs(os.path.dirname(terms_file), exist_ok=True)
189
+
190
+ with open(terms_file, "w", encoding="utf-8") as f:
191
+ f.write(f"Terms accepted at {datetime.now().isoformat()}\n")
192
+ f.write(f"System: {json.dumps(system_info)}\n\n")
193
+ f.write(terms_text)
194
+
195
+ return True
196
+
197
+ def accept_vnstock_terms():
198
+ """Accept vnstock terms and create necessary files"""
199
+ # Get system information
200
+ from vnai.scope.profile import inspector
201
+ system_info = inspector.examine()
202
+
203
+ # Create necessary directories
204
+ home_dir = pathlib.Path.home()
205
+ project_dir = home_dir / ".vnstock"
206
+ project_dir.mkdir(exist_ok=True)
207
+ id_dir = project_dir / 'id'
208
+ id_dir.mkdir(exist_ok=True)
209
+
210
+ # Create environment.json file that vnstock looks for
211
+ env_file = id_dir / "environment.json"
212
+ env_data = {
213
+ "accepted_agreement": True,
214
+ "timestamp": datetime.now().isoformat(),
215
+ "machine_id": system_info['machine_id']
216
+ }
217
+
218
+ try:
219
+ with open(env_file, "w") as f:
220
+ json.dump(env_data, f)
221
+ print("Vnstock terms accepted successfully.")
222
+ return True
223
+ except Exception as e:
224
+ print(f"Error accepting terms: {e}")
225
+ return False
226
+
227
+ def configure_privacy(level="standard"):
228
+ """Configure privacy level for analytics data"""
229
+ from vnai.scope.state import tracker
230
+ return tracker.setup_privacy(level)
231
+
232
+ def check_commercial_usage():
233
+ """Check if running in commercial environment"""
234
+ from vnai.scope.profile import inspector
235
+ return inspector.detect_commercial_usage()
236
+
237
+ def authenticate_for_persistence():
238
+ """Authenticate to Google Drive for persistent settings (Colab only)"""
239
+ from vnai.scope.profile import inspector
240
+ return inspector.get_or_create_user_id()
vnai/beam/__init__.py CHANGED
@@ -1,3 +1,5 @@
1
- from vnai.beam.quota import guardian, optimize
2
- from vnai.beam.metrics import collector, capture
1
+ # vnai/beam/__init__.py
2
+
3
+ from vnai.beam.quota import guardian, optimize
4
+ from vnai.beam.metrics import collector, capture
3
5
  from vnai.beam.pulse import monitor