webscout 8.3.1__py3-none-any.whl → 8.3.3__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.

Potentially problematic release.


This version of webscout might be problematic. Click here for more details.

Files changed (114) hide show
  1. webscout/AIutel.py +180 -78
  2. webscout/Bing_search.py +417 -0
  3. webscout/Extra/gguf.py +706 -177
  4. webscout/Provider/AISEARCH/__init__.py +1 -0
  5. webscout/Provider/AISEARCH/genspark_search.py +7 -7
  6. webscout/Provider/AISEARCH/stellar_search.py +132 -0
  7. webscout/Provider/ExaChat.py +84 -58
  8. webscout/Provider/GeminiProxy.py +140 -0
  9. webscout/Provider/HeckAI.py +85 -80
  10. webscout/Provider/Jadve.py +56 -50
  11. webscout/Provider/MCPCore.py +78 -75
  12. webscout/Provider/MiniMax.py +207 -0
  13. webscout/Provider/Nemotron.py +41 -13
  14. webscout/Provider/Netwrck.py +34 -51
  15. webscout/Provider/OPENAI/BLACKBOXAI.py +0 -4
  16. webscout/Provider/OPENAI/GeminiProxy.py +328 -0
  17. webscout/Provider/OPENAI/MiniMax.py +298 -0
  18. webscout/Provider/OPENAI/README.md +32 -29
  19. webscout/Provider/OPENAI/README_AUTOPROXY.md +238 -0
  20. webscout/Provider/OPENAI/TogetherAI.py +4 -17
  21. webscout/Provider/OPENAI/__init__.py +17 -1
  22. webscout/Provider/OPENAI/autoproxy.py +1067 -39
  23. webscout/Provider/OPENAI/base.py +17 -76
  24. webscout/Provider/OPENAI/deepinfra.py +42 -108
  25. webscout/Provider/OPENAI/e2b.py +0 -1
  26. webscout/Provider/OPENAI/flowith.py +179 -166
  27. webscout/Provider/OPENAI/friendli.py +233 -0
  28. webscout/Provider/OPENAI/mcpcore.py +109 -70
  29. webscout/Provider/OPENAI/monochat.py +329 -0
  30. webscout/Provider/OPENAI/pydantic_imports.py +1 -172
  31. webscout/Provider/OPENAI/scirachat.py +59 -51
  32. webscout/Provider/OPENAI/toolbaz.py +3 -9
  33. webscout/Provider/OPENAI/typegpt.py +1 -1
  34. webscout/Provider/OPENAI/utils.py +19 -42
  35. webscout/Provider/OPENAI/x0gpt.py +14 -2
  36. webscout/Provider/OPENAI/xenai.py +514 -0
  37. webscout/Provider/OPENAI/yep.py +8 -2
  38. webscout/Provider/OpenGPT.py +54 -32
  39. webscout/Provider/PI.py +58 -84
  40. webscout/Provider/StandardInput.py +32 -13
  41. webscout/Provider/TTI/README.md +9 -9
  42. webscout/Provider/TTI/__init__.py +3 -1
  43. webscout/Provider/TTI/aiarta.py +92 -78
  44. webscout/Provider/TTI/bing.py +231 -0
  45. webscout/Provider/TTI/infip.py +212 -0
  46. webscout/Provider/TTI/monochat.py +220 -0
  47. webscout/Provider/TTS/speechma.py +45 -39
  48. webscout/Provider/TeachAnything.py +11 -3
  49. webscout/Provider/TextPollinationsAI.py +78 -70
  50. webscout/Provider/TogetherAI.py +350 -0
  51. webscout/Provider/Venice.py +37 -46
  52. webscout/Provider/VercelAI.py +27 -24
  53. webscout/Provider/WiseCat.py +35 -35
  54. webscout/Provider/WrDoChat.py +22 -26
  55. webscout/Provider/WritingMate.py +26 -22
  56. webscout/Provider/XenAI.py +324 -0
  57. webscout/Provider/__init__.py +10 -5
  58. webscout/Provider/deepseek_assistant.py +378 -0
  59. webscout/Provider/granite.py +48 -57
  60. webscout/Provider/koala.py +51 -39
  61. webscout/Provider/learnfastai.py +49 -64
  62. webscout/Provider/llmchat.py +79 -93
  63. webscout/Provider/llmchatco.py +63 -78
  64. webscout/Provider/multichat.py +51 -40
  65. webscout/Provider/oivscode.py +1 -1
  66. webscout/Provider/scira_chat.py +159 -96
  67. webscout/Provider/scnet.py +13 -13
  68. webscout/Provider/searchchat.py +13 -13
  69. webscout/Provider/sonus.py +12 -11
  70. webscout/Provider/toolbaz.py +25 -8
  71. webscout/Provider/turboseek.py +41 -42
  72. webscout/Provider/typefully.py +27 -12
  73. webscout/Provider/typegpt.py +41 -46
  74. webscout/Provider/uncovr.py +55 -90
  75. webscout/Provider/x0gpt.py +33 -17
  76. webscout/Provider/yep.py +79 -96
  77. webscout/auth/__init__.py +55 -0
  78. webscout/auth/api_key_manager.py +189 -0
  79. webscout/auth/auth_system.py +100 -0
  80. webscout/auth/config.py +76 -0
  81. webscout/auth/database.py +400 -0
  82. webscout/auth/exceptions.py +67 -0
  83. webscout/auth/middleware.py +248 -0
  84. webscout/auth/models.py +130 -0
  85. webscout/auth/providers.py +279 -0
  86. webscout/auth/rate_limiter.py +254 -0
  87. webscout/auth/request_models.py +127 -0
  88. webscout/auth/request_processing.py +226 -0
  89. webscout/auth/routes.py +550 -0
  90. webscout/auth/schemas.py +103 -0
  91. webscout/auth/server.py +367 -0
  92. webscout/client.py +121 -70
  93. webscout/litagent/Readme.md +68 -55
  94. webscout/litagent/agent.py +99 -9
  95. webscout/scout/core/scout.py +104 -26
  96. webscout/scout/element.py +139 -18
  97. webscout/swiftcli/core/cli.py +14 -3
  98. webscout/swiftcli/decorators/output.py +59 -9
  99. webscout/update_checker.py +31 -49
  100. webscout/version.py +1 -1
  101. webscout/webscout_search.py +4 -12
  102. webscout/webscout_search_async.py +3 -10
  103. webscout/yep_search.py +2 -11
  104. {webscout-8.3.1.dist-info → webscout-8.3.3.dist-info}/METADATA +141 -99
  105. {webscout-8.3.1.dist-info → webscout-8.3.3.dist-info}/RECORD +109 -83
  106. {webscout-8.3.1.dist-info → webscout-8.3.3.dist-info}/entry_points.txt +1 -1
  107. webscout/Provider/HF_space/__init__.py +0 -0
  108. webscout/Provider/HF_space/qwen_qwen2.py +0 -206
  109. webscout/Provider/OPENAI/api.py +0 -1320
  110. webscout/Provider/TTI/fastflux.py +0 -233
  111. webscout/Provider/Writecream.py +0 -246
  112. {webscout-8.3.1.dist-info → webscout-8.3.3.dist-info}/WHEEL +0 -0
  113. {webscout-8.3.1.dist-info → webscout-8.3.3.dist-info}/licenses/LICENSE.md +0 -0
  114. {webscout-8.3.1.dist-info → webscout-8.3.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,55 @@
1
+ # webscout/auth/__init__.py
2
+
3
+ from .models import User, APIKey
4
+ from .database import DatabaseManager
5
+ from .api_key_manager import APIKeyManager
6
+ from .rate_limiter import RateLimiter
7
+ from .middleware import AuthMiddleware
8
+ from .schemas import (
9
+ APIKeyCreateRequest,
10
+ APIKeyCreateResponse,
11
+ APIKeyValidationResponse,
12
+ UserCreateRequest,
13
+ UserResponse,
14
+ HealthCheckResponse
15
+ )
16
+ # Import server functions lazily to avoid module execution issues
17
+ def create_app():
18
+ from .server import create_app as _create_app
19
+ return _create_app()
20
+
21
+ def run_api(*args, **kwargs):
22
+ from .server import run_api as _run_api
23
+ return _run_api(*args, **kwargs)
24
+
25
+ def start_server(*args, **kwargs):
26
+ from .server import start_server as _start_server
27
+ return _start_server(*args, **kwargs)
28
+ from .routes import Api
29
+ from .config import ServerConfig, AppConfig
30
+ from .exceptions import APIError
31
+ from .providers import initialize_provider_map, initialize_tti_provider_map
32
+
33
+ __all__ = [
34
+ "User",
35
+ "APIKey",
36
+ "DatabaseManager",
37
+ "APIKeyManager",
38
+ "RateLimiter",
39
+ "AuthMiddleware",
40
+ "APIKeyCreateRequest",
41
+ "APIKeyCreateResponse",
42
+ "APIKeyValidationResponse",
43
+ "UserCreateRequest",
44
+ "UserResponse",
45
+ "HealthCheckResponse",
46
+ "create_app",
47
+ "run_api",
48
+ "start_server",
49
+ "Api",
50
+ "ServerConfig",
51
+ "AppConfig",
52
+ "APIError",
53
+ "initialize_provider_map",
54
+ "initialize_tti_provider_map"
55
+ ]
@@ -0,0 +1,189 @@
1
+ # webscout/auth/api_key_manager.py
2
+
3
+ import secrets
4
+ import string
5
+ from datetime import datetime, timezone, timedelta
6
+ from typing import Optional, Tuple
7
+ import hashlib
8
+ import logging
9
+
10
+ from .models import User, APIKey
11
+ from .database import DatabaseManager
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ class APIKeyManager:
17
+ """Manages API key generation, validation, and lifecycle."""
18
+
19
+ def __init__(self, database_manager: DatabaseManager):
20
+ self.db = database_manager
21
+ self.key_prefix = "ws_" # webscout prefix
22
+ self.key_length = 32 # Length of the random part
23
+
24
+ def generate_api_key(self) -> str:
25
+ """Generate a secure API key."""
26
+ # Generate random string
27
+ alphabet = string.ascii_letters + string.digits
28
+ random_part = ''.join(secrets.choice(alphabet) for _ in range(self.key_length))
29
+
30
+ # Add prefix
31
+ api_key = f"{self.key_prefix}{random_part}"
32
+
33
+ return api_key
34
+
35
+ def hash_api_key(self, api_key: str) -> str:
36
+ """Hash an API key for secure storage (optional, for extra security)."""
37
+ return hashlib.sha256(api_key.encode()).hexdigest()
38
+
39
+ async def create_api_key(
40
+ self,
41
+ username: str,
42
+ telegram_id: str,
43
+ name: Optional[str] = None,
44
+ rate_limit: int = 10,
45
+ expires_in_days: Optional[int] = None
46
+ ) -> Tuple[APIKey, User]:
47
+ """Create a new API key and associated user if needed. Only one API key per user allowed."""
48
+
49
+ # Check if user already exists by telegram_id
50
+ user = await self.db.get_user_by_telegram_id(telegram_id)
51
+
52
+ if user:
53
+ # Check if user already has an API key
54
+ existing_keys = await self.db.get_api_keys_by_user(user.id)
55
+ active_keys = [key for key in existing_keys if key.is_active and not key.is_expired()]
56
+
57
+ if active_keys:
58
+ raise ValueError(f"User with Telegram ID {telegram_id} already has an active API key. Only one API key per user is allowed.")
59
+ else:
60
+ # Check if username is already taken
61
+ existing_user = await self.db.get_user_by_username(username)
62
+ if existing_user:
63
+ raise ValueError(f"Username '{username}' is already taken")
64
+
65
+ # Create new user
66
+ user = User(
67
+ username=username,
68
+ telegram_id=telegram_id,
69
+ created_at=datetime.now(timezone.utc),
70
+ updated_at=datetime.now(timezone.utc)
71
+ )
72
+ try:
73
+ user = await self.db.create_user(user)
74
+ logger.info(f"Created new user: {user.username} (Telegram ID: {telegram_id})")
75
+ except ValueError as e:
76
+ # User might already exist, try to get it
77
+ if "already exists" in str(e):
78
+ user = await self.db.get_user_by_telegram_id(telegram_id)
79
+ if not user:
80
+ raise e
81
+ else:
82
+ raise e
83
+
84
+ # Generate API key
85
+ api_key_value = self.generate_api_key()
86
+
87
+ # Calculate expiration
88
+ expires_at = None
89
+ if expires_in_days:
90
+ expires_at = datetime.now(timezone.utc) + timedelta(days=expires_in_days)
91
+
92
+ # Create API key object
93
+ api_key = APIKey(
94
+ key=api_key_value,
95
+ user_id=user.id,
96
+ name=name,
97
+ created_at=datetime.now(timezone.utc),
98
+ expires_at=expires_at,
99
+ rate_limit=rate_limit,
100
+ is_active=True
101
+ )
102
+
103
+ # Store in database
104
+ try:
105
+ api_key = await self.db.create_api_key(api_key)
106
+ logger.info(f"Created API key for user {user.username}: {api_key.id}")
107
+ return api_key, user
108
+ except ValueError as e:
109
+ # Key collision (very unlikely), try again
110
+ if "already exists" in str(e):
111
+ logger.warning("API key collision detected, regenerating...")
112
+ return await self.create_api_key(username, telegram_id, name, rate_limit, expires_in_days)
113
+ raise e
114
+
115
+ async def validate_api_key(self, api_key: str) -> Tuple[bool, Optional[APIKey], Optional[str]]:
116
+ """
117
+ Validate an API key.
118
+
119
+ Returns:
120
+ Tuple of (is_valid, api_key_object, error_message)
121
+ """
122
+ if not api_key:
123
+ return False, None, "API key is required"
124
+
125
+ if not api_key.startswith(self.key_prefix):
126
+ return False, None, "Invalid API key format"
127
+
128
+ try:
129
+ # Get API key from database
130
+ key_obj = await self.db.get_api_key(api_key)
131
+
132
+ if not key_obj:
133
+ return False, None, "API key not found"
134
+
135
+ if not key_obj.is_active:
136
+ return False, None, "API key is inactive"
137
+
138
+ if key_obj.is_expired():
139
+ return False, None, "API key has expired"
140
+
141
+ # Update last used timestamp
142
+ key_obj.last_used_at = datetime.now(timezone.utc)
143
+ key_obj.usage_count += 1
144
+
145
+ try:
146
+ await self.db.update_api_key(key_obj)
147
+ except Exception as e:
148
+ logger.warning(f"Failed to update API key usage: {e}")
149
+
150
+ return True, key_obj, None
151
+
152
+ except Exception as e:
153
+ logger.error(f"Error validating API key: {e}")
154
+ return False, None, "Internal error during validation"
155
+
156
+ async def revoke_api_key(self, api_key: str) -> bool:
157
+ """Revoke an API key by marking it as inactive."""
158
+ try:
159
+ key_obj = await self.db.get_api_key(api_key)
160
+
161
+ if not key_obj:
162
+ return False
163
+
164
+ key_obj.is_active = False
165
+ key_obj.updated_at = datetime.now(timezone.utc)
166
+
167
+ await self.db.update_api_key(key_obj)
168
+ logger.info(f"Revoked API key: {key_obj.id}")
169
+ return True
170
+
171
+ except Exception as e:
172
+ logger.error(f"Error revoking API key: {e}")
173
+ return False
174
+
175
+ async def get_user_api_keys(self, user_id: str) -> list[APIKey]:
176
+ """Get all API keys for a user."""
177
+ try:
178
+ return await self.db.get_api_keys_by_user(user_id)
179
+ except Exception as e:
180
+ logger.error(f"Error getting user API keys: {e}")
181
+ return []
182
+
183
+ async def cleanup_expired_keys(self) -> int:
184
+ """Clean up expired API keys (mark as inactive)."""
185
+ # This would require a method to get all API keys, which we haven't implemented
186
+ # For now, we'll just return 0
187
+ # In a production system, you'd want to implement this properly
188
+ logger.info("Cleanup expired keys called (not implemented)")
189
+ return 0
@@ -0,0 +1,100 @@
1
+ """
2
+ Authentication system initialization for the Webscout API.
3
+ """
4
+
5
+ import os
6
+ import sys
7
+ from typing import Optional
8
+ from fastapi import FastAPI
9
+
10
+ from webscout.Litlogger import Logger, LogLevel, LogFormat, ConsoleHandler
11
+ from .database import DatabaseManager
12
+ from .api_key_manager import APIKeyManager
13
+ from .rate_limiter import RateLimiter
14
+ from .middleware import AuthMiddleware
15
+
16
+ # Setup logger
17
+ logger = Logger(
18
+ name="webscout.api",
19
+ level=LogLevel.INFO,
20
+ handlers=[ConsoleHandler(stream=sys.stdout)],
21
+ fmt=LogFormat.DEFAULT
22
+ )
23
+
24
+ # Global authentication system instances
25
+ db_manager: Optional[DatabaseManager] = None
26
+ api_key_manager: Optional[APIKeyManager] = None
27
+ rate_limiter: Optional[RateLimiter] = None
28
+ auth_middleware: Optional[AuthMiddleware] = None
29
+
30
+
31
+ def initialize_auth_system(app: FastAPI, auth_required: bool = True, rate_limit_enabled: bool = True) -> None:
32
+ """Initialize the authentication system."""
33
+ global db_manager, api_key_manager, rate_limiter, auth_middleware
34
+
35
+ if not auth_required:
36
+ logger.info("Auth system is disabled (no-auth mode): skipping DB and API key manager initialization.")
37
+ db_manager = None
38
+ api_key_manager = None
39
+ rate_limiter = None
40
+ auth_middleware = None
41
+ return
42
+
43
+ try:
44
+ # Initialize database manager
45
+ mongo_url = os.getenv("MONGODB_URL")
46
+ data_dir = os.getenv("WEBSCOUT_DATA_DIR", "data")
47
+
48
+ db_manager = DatabaseManager(mongo_url, data_dir)
49
+
50
+ # Initialize API key manager
51
+ api_key_manager = APIKeyManager(db_manager)
52
+
53
+ # Initialize rate limiter
54
+ rate_limiter = RateLimiter(db_manager)
55
+
56
+ # Initialize auth middleware with configuration
57
+ auth_middleware = AuthMiddleware(
58
+ api_key_manager,
59
+ rate_limiter,
60
+ auth_required=auth_required,
61
+ rate_limit_enabled=rate_limit_enabled
62
+ )
63
+
64
+ # Add auth middleware to app
65
+ app.middleware("http")(auth_middleware)
66
+
67
+ # Add startup event to initialize database
68
+ async def startup_event():
69
+ if db_manager:
70
+ await db_manager.initialize()
71
+ logger.info("Authentication system initialized successfully")
72
+ logger.info(f"Auth required: {auth_required}, Rate limiting: {rate_limit_enabled}")
73
+
74
+ # Store startup function for later use
75
+ app.state.startup_event = startup_event
76
+
77
+ logger.info("Authentication system setup completed")
78
+
79
+ except Exception as e:
80
+ logger.error(f"Failed to initialize authentication system: {e}")
81
+ # Fall back to legacy auth if new system fails
82
+ logger.warning("Falling back to legacy authentication system")
83
+
84
+
85
+ def get_auth_components():
86
+ """Get the initialized authentication components."""
87
+ if db_manager is None:
88
+ return {
89
+ "db_manager": None,
90
+ "api_key_manager": None,
91
+ "rate_limiter": None,
92
+ "auth_middleware": None
93
+ }
94
+
95
+ return {
96
+ "db_manager": db_manager,
97
+ "api_key_manager": api_key_manager,
98
+ "rate_limiter": rate_limiter,
99
+ "auth_middleware": auth_middleware
100
+ }
@@ -0,0 +1,76 @@
1
+ """
2
+ Configuration management for the Webscout API server.
3
+ """
4
+
5
+ from typing import List, Dict, Optional, Any
6
+ from webscout.Litlogger import Logger, LogLevel, LogFormat, ConsoleHandler
7
+ import sys
8
+
9
+ # Configuration constants
10
+ DEFAULT_PORT = 8000
11
+ DEFAULT_HOST = "0.0.0.0"
12
+
13
+ # Setup logger
14
+ logger = Logger(
15
+ name="webscout.api",
16
+ level=LogLevel.INFO,
17
+ handlers=[ConsoleHandler(stream=sys.stdout)],
18
+ fmt=LogFormat.DEFAULT
19
+ )
20
+
21
+
22
+ class ServerConfig:
23
+ """Centralized configuration management for the API server."""
24
+
25
+ def __init__(self):
26
+ self.api_key: Optional[str] = None
27
+ self.provider_map: Dict[str, Any] = {}
28
+ self.default_provider: str = "ChatGPT"
29
+ self.base_url: Optional[str] = None
30
+ self.host: str = DEFAULT_HOST
31
+ self.port: int = DEFAULT_PORT
32
+ self.debug: bool = False
33
+ self.cors_origins: List[str] = ["*"]
34
+ self.max_request_size: int = 10 * 1024 * 1024 # 10MB
35
+ self.request_timeout: int = 300 # 5 minutes
36
+ self.auth_required: bool = True # New: Enable/disable authentication
37
+ self.rate_limit_enabled: bool = True # New: Enable/disable rate limiting
38
+ self.default_rate_limit: int = 60 # Default rate limit for no-auth mode
39
+
40
+ def update(self, **kwargs) -> None:
41
+ """Update configuration with provided values."""
42
+ for key, value in kwargs.items():
43
+ if hasattr(self, key) and value is not None:
44
+ setattr(self, key, value)
45
+ logger.info(f"Config updated: {key} = {value}")
46
+
47
+ def validate(self) -> None:
48
+ """Validate configuration settings."""
49
+ if self.port < 1 or self.port > 65535:
50
+ raise ValueError(f"Invalid port number: {self.port}")
51
+
52
+ if self.default_provider not in self.provider_map and self.provider_map:
53
+ available_providers = list(set(v.__name__ for v in self.provider_map.values()))
54
+ logger.warning(f"Default provider '{self.default_provider}' not found. Available: {available_providers}")
55
+
56
+
57
+ class AppConfig:
58
+ """Legacy configuration class for backward compatibility."""
59
+ api_key: Optional[str] = None
60
+ provider_map = {}
61
+ tti_provider_map = {} # Add TTI provider map
62
+ default_provider = "ChatGPT"
63
+ default_tti_provider = "PollinationsAI" # Add default TTI provider
64
+ base_url: Optional[str] = None
65
+ auth_required: bool = True # New: Enable/disable authentication
66
+ rate_limit_enabled: bool = True # New: Enable/disable rate limiting
67
+ default_rate_limit: int = 60 # Default rate limit for no-auth mode
68
+
69
+ @classmethod
70
+ def set_config(cls, **data):
71
+ """Set configuration values."""
72
+ for key, value in data.items():
73
+ setattr(cls, key, value)
74
+ # Sync with new config system
75
+ from .server import config
76
+ config.update(**data)