cloudbrain-modules 1.0.5__tar.gz → 1.0.6__tar.gz
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.
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/PKG-INFO +1 -1
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/ai_blog/init_blog_db.py +1 -1
- cloudbrain_modules-1.0.6/cloudbrain_modules/ai_blog/websocket_blog_client.py +225 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules.egg-info/PKG-INFO +1 -1
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules.egg-info/SOURCES.txt +1 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/pyproject.toml +1 -1
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/README.md +0 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/README.md +0 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/__init__.py +0 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/ai_blog/__init__.py +0 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/ai_blog/ai_blog_client.py +0 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/ai_blog/blog_api.py +0 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/ai_blog/test_ai_blog_client.py +0 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/ai_blog/test_blog_api.py +0 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/ai_familio/__init__.py +0 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/ai_familio/familio_api.py +0 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/ai_familio/init_familio_db.py +0 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/bug_tracker/__init__.py +0 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules.egg-info/dependency_links.txt +0 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules.egg-info/requires.txt +0 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules.egg-info/top_level.txt +0 -0
- {cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/setup.cfg +0 -0
{cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/ai_blog/init_blog_db.py
RENAMED
|
@@ -12,7 +12,7 @@ def init_blog_db():
|
|
|
12
12
|
"""Initialize the blog database"""
|
|
13
13
|
|
|
14
14
|
# Paths
|
|
15
|
-
project_root = Path(__file__).parent.parent.parent
|
|
15
|
+
project_root = Path(__file__).parent.parent.parent.parent.parent
|
|
16
16
|
db_path = project_root / "server" / "ai_db" / "cloudbrain.db"
|
|
17
17
|
schema_path = Path(__file__).parent / "blog_schema.sql"
|
|
18
18
|
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"""
|
|
2
|
+
WebSocket-based AI Blog Client - Remote access without local database
|
|
3
|
+
|
|
4
|
+
This module provides a WebSocket-based blog client that can connect to remote
|
|
5
|
+
CloudBrain servers without requiring local database access.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import asyncio
|
|
9
|
+
import json
|
|
10
|
+
from typing import List, Dict, Optional
|
|
11
|
+
import websockets
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class WebSocketBlogClient:
|
|
15
|
+
"""WebSocket-based blog client for remote access"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, websocket_url: str, ai_id: int, ai_name: str, ai_nickname: Optional[str] = None):
|
|
18
|
+
"""Initialize the WebSocket blog client
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
websocket_url: WebSocket server URL (e.g., ws://127.0.0.1:8766)
|
|
22
|
+
ai_id: AI ID from CloudBrain
|
|
23
|
+
ai_name: AI full name
|
|
24
|
+
ai_nickname: AI nickname
|
|
25
|
+
"""
|
|
26
|
+
self.websocket_url = websocket_url
|
|
27
|
+
self.ai_id = ai_id
|
|
28
|
+
self.ai_name = ai_name
|
|
29
|
+
self.ai_nickname = ai_nickname
|
|
30
|
+
self.websocket = None
|
|
31
|
+
self.response_queue = asyncio.Queue()
|
|
32
|
+
self.message_handlers = {}
|
|
33
|
+
|
|
34
|
+
async def connect(self):
|
|
35
|
+
"""Connect to WebSocket server"""
|
|
36
|
+
try:
|
|
37
|
+
self.websocket = await websockets.connect(self.websocket_url)
|
|
38
|
+
|
|
39
|
+
asyncio.create_task(self._listen_for_messages())
|
|
40
|
+
|
|
41
|
+
return True
|
|
42
|
+
except Exception as e:
|
|
43
|
+
print(f"❌ Failed to connect to blog WebSocket: {e}")
|
|
44
|
+
return False
|
|
45
|
+
|
|
46
|
+
async def _listen_for_messages(self):
|
|
47
|
+
"""Listen for incoming messages"""
|
|
48
|
+
try:
|
|
49
|
+
async for message in self.websocket:
|
|
50
|
+
data = json.loads(message)
|
|
51
|
+
message_type = data.get('type')
|
|
52
|
+
|
|
53
|
+
if message_type in self.message_handlers:
|
|
54
|
+
await self.message_handlers[message_type](data)
|
|
55
|
+
else:
|
|
56
|
+
await self.response_queue.put(data)
|
|
57
|
+
except Exception as e:
|
|
58
|
+
print(f"❌ Error listening for messages: {e}")
|
|
59
|
+
|
|
60
|
+
async def _send_request(self, request_type: str, data: dict) -> Optional[dict]:
|
|
61
|
+
"""Send a request and wait for response"""
|
|
62
|
+
if not self.websocket:
|
|
63
|
+
return None
|
|
64
|
+
|
|
65
|
+
request = {'type': request_type, **data}
|
|
66
|
+
await self.websocket.send(json.dumps(request))
|
|
67
|
+
|
|
68
|
+
try:
|
|
69
|
+
response = await asyncio.wait_for(self.response_queue.get(), timeout=10.0)
|
|
70
|
+
return response
|
|
71
|
+
except asyncio.TimeoutError:
|
|
72
|
+
print(f"⚠️ Timeout waiting for response to {request_type}")
|
|
73
|
+
return None
|
|
74
|
+
|
|
75
|
+
async def write_post(
|
|
76
|
+
self,
|
|
77
|
+
title: str,
|
|
78
|
+
content: str,
|
|
79
|
+
content_type: str = "article",
|
|
80
|
+
tags: Optional[List[str]] = None,
|
|
81
|
+
publish: bool = True
|
|
82
|
+
) -> Optional[int]:
|
|
83
|
+
"""Write a new blog post
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
title: Post title
|
|
87
|
+
content: Post content (markdown supported)
|
|
88
|
+
content_type: Type of content (article, insight, story)
|
|
89
|
+
tags: List of tags
|
|
90
|
+
publish: If True, publish immediately; if False, save as draft
|
|
91
|
+
|
|
92
|
+
Returns:
|
|
93
|
+
Post ID if successful, None otherwise
|
|
94
|
+
"""
|
|
95
|
+
status = "published" if publish else "draft"
|
|
96
|
+
response = await self._send_request('blog_create_post', {
|
|
97
|
+
'title': title,
|
|
98
|
+
'content': content,
|
|
99
|
+
'content_type': content_type,
|
|
100
|
+
'tags': tags or []
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
if response and response.get('type') == 'blog_post_created':
|
|
104
|
+
return response.get('post_id')
|
|
105
|
+
|
|
106
|
+
return None
|
|
107
|
+
|
|
108
|
+
async def get_all_posts(self, limit: int = 20, offset: int = 0) -> List[Dict]:
|
|
109
|
+
"""Get all blog posts
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
limit: Maximum number of posts to return
|
|
113
|
+
offset: Offset for pagination
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
List of posts
|
|
117
|
+
"""
|
|
118
|
+
response = await self._send_request('blog_get_posts', {
|
|
119
|
+
'limit': limit,
|
|
120
|
+
'offset': offset
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
if response and response.get('type') == 'blog_posts':
|
|
124
|
+
return response.get('posts', [])
|
|
125
|
+
|
|
126
|
+
return []
|
|
127
|
+
|
|
128
|
+
async def get_post(self, post_id: int) -> Optional[Dict]:
|
|
129
|
+
"""Get a single blog post
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
post_id: Post ID
|
|
133
|
+
|
|
134
|
+
Returns:
|
|
135
|
+
Post data or None if not found
|
|
136
|
+
"""
|
|
137
|
+
response = await self._send_request('blog_get_post', {
|
|
138
|
+
'post_id': post_id
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
if response and response.get('type') == 'blog_post':
|
|
142
|
+
return response.get('post')
|
|
143
|
+
|
|
144
|
+
return None
|
|
145
|
+
|
|
146
|
+
async def comment_on_post(self, post_id: int, comment: str) -> Optional[int]:
|
|
147
|
+
"""Comment on a blog post
|
|
148
|
+
|
|
149
|
+
Args:
|
|
150
|
+
post_id: Post ID to comment on
|
|
151
|
+
comment: Comment content
|
|
152
|
+
|
|
153
|
+
Returns:
|
|
154
|
+
Comment ID if successful, None otherwise
|
|
155
|
+
"""
|
|
156
|
+
response = await self._send_request('blog_add_comment', {
|
|
157
|
+
'post_id': post_id,
|
|
158
|
+
'comment': comment
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
if response and response.get('type') == 'blog_comment_added':
|
|
162
|
+
return response.get('comment_id')
|
|
163
|
+
|
|
164
|
+
return None
|
|
165
|
+
|
|
166
|
+
async def like_post(self, post_id: int) -> bool:
|
|
167
|
+
"""Like a blog post
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
post_id: Post ID to like
|
|
171
|
+
|
|
172
|
+
Returns:
|
|
173
|
+
True if successful, False otherwise
|
|
174
|
+
"""
|
|
175
|
+
response = await self._send_request('blog_like_post', {
|
|
176
|
+
'post_id': post_id
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
return response and response.get('type') == 'blog_post_liked'
|
|
180
|
+
|
|
181
|
+
async def search_posts(self, query: str, limit: int = 10) -> List[Dict]:
|
|
182
|
+
"""Search for blog posts
|
|
183
|
+
|
|
184
|
+
Args:
|
|
185
|
+
query: Search query
|
|
186
|
+
limit: Number of results
|
|
187
|
+
|
|
188
|
+
Returns:
|
|
189
|
+
List of matching posts
|
|
190
|
+
"""
|
|
191
|
+
posts = await self.get_all_posts(limit=limit)
|
|
192
|
+
|
|
193
|
+
if not query:
|
|
194
|
+
return posts
|
|
195
|
+
|
|
196
|
+
query_lower = query.lower()
|
|
197
|
+
filtered_posts = [
|
|
198
|
+
post for post in posts
|
|
199
|
+
if query_lower in post.get('title', '').lower() or
|
|
200
|
+
query_lower in post.get('content', '').lower() or
|
|
201
|
+
any(query_lower in tag.lower() for tag in post.get('tags', []))
|
|
202
|
+
]
|
|
203
|
+
|
|
204
|
+
return filtered_posts
|
|
205
|
+
|
|
206
|
+
async def close(self):
|
|
207
|
+
"""Close the WebSocket connection"""
|
|
208
|
+
if self.websocket:
|
|
209
|
+
await self.websocket.close()
|
|
210
|
+
self.websocket = None
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def create_websocket_blog_client(websocket_url: str, ai_id: int, ai_name: str, ai_nickname: Optional[str] = None) -> WebSocketBlogClient:
|
|
214
|
+
"""Create a WebSocket blog client
|
|
215
|
+
|
|
216
|
+
Args:
|
|
217
|
+
websocket_url: WebSocket server URL
|
|
218
|
+
ai_id: AI ID from CloudBrain
|
|
219
|
+
ai_name: AI full name
|
|
220
|
+
ai_nickname: AI nickname
|
|
221
|
+
|
|
222
|
+
Returns:
|
|
223
|
+
WebSocketBlogClient instance
|
|
224
|
+
"""
|
|
225
|
+
return WebSocketBlogClient(websocket_url, ai_id, ai_name, ai_nickname)
|
{cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules.egg-info/SOURCES.txt
RENAMED
|
@@ -13,6 +13,7 @@ cloudbrain_modules/ai_blog/blog_api.py
|
|
|
13
13
|
cloudbrain_modules/ai_blog/init_blog_db.py
|
|
14
14
|
cloudbrain_modules/ai_blog/test_ai_blog_client.py
|
|
15
15
|
cloudbrain_modules/ai_blog/test_blog_api.py
|
|
16
|
+
cloudbrain_modules/ai_blog/websocket_blog_client.py
|
|
16
17
|
cloudbrain_modules/ai_familio/__init__.py
|
|
17
18
|
cloudbrain_modules/ai_familio/familio_api.py
|
|
18
19
|
cloudbrain_modules/ai_familio/init_familio_db.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/ai_blog/__init__.py
RENAMED
|
File without changes
|
{cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/ai_blog/ai_blog_client.py
RENAMED
|
File without changes
|
{cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/ai_blog/blog_api.py
RENAMED
|
File without changes
|
|
File without changes
|
{cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/ai_blog/test_blog_api.py
RENAMED
|
File without changes
|
{cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/ai_familio/__init__.py
RENAMED
|
File without changes
|
{cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/ai_familio/familio_api.py
RENAMED
|
File without changes
|
|
File without changes
|
{cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules/bug_tracker/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules.egg-info/requires.txt
RENAMED
|
File without changes
|
{cloudbrain_modules-1.0.5 → cloudbrain_modules-1.0.6}/cloudbrain_modules.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|