sycommon-python-lib 0.2.2a4__py3-none-any.whl → 0.2.2a6__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.
- sycommon/agent/sandbox/file_ops.py +24 -53
- sycommon/agent/sandbox/http_sandbox_backend.py +317 -205
- sycommon/middleware/sandbox.py +641 -349
- sycommon/models/sandbox.py +91 -0
- {sycommon_python_lib-0.2.2a4.dist-info → sycommon_python_lib-0.2.2a6.dist-info}/METADATA +4 -4
- {sycommon_python_lib-0.2.2a4.dist-info → sycommon_python_lib-0.2.2a6.dist-info}/RECORD +9 -10
- command/templates/__pycache__/__init__.cpython-311.pyc +0 -0
- {sycommon_python_lib-0.2.2a4.dist-info → sycommon_python_lib-0.2.2a6.dist-info}/WHEEL +0 -0
- {sycommon_python_lib-0.2.2a4.dist-info → sycommon_python_lib-0.2.2a6.dist-info}/entry_points.txt +0 -0
- {sycommon_python_lib-0.2.2a4.dist-info → sycommon_python_lib-0.2.2a6.dist-info}/top_level.txt +0 -0
|
@@ -149,11 +149,11 @@ class FileOperationsMixin:
|
|
|
149
149
|
def _check_workspace_exists_sync(self: "HTTPSandboxBackend") -> bool:
|
|
150
150
|
"""检查沙箱工作空间是否存在(同步版本)"""
|
|
151
151
|
try:
|
|
152
|
-
self._post_sync(f"{SANDBOX_API_PREFIX}/
|
|
152
|
+
result = self._post_sync(f"{SANDBOX_API_PREFIX}/stat", {
|
|
153
153
|
"path": "/",
|
|
154
154
|
"user_id": self.user_id
|
|
155
155
|
})
|
|
156
|
-
return
|
|
156
|
+
return result.get("exists", False)
|
|
157
157
|
except Exception as e:
|
|
158
158
|
SYLogger.warning(f"[Sandbox] 检查工作空间失败: {e}")
|
|
159
159
|
return False
|
|
@@ -161,11 +161,11 @@ class FileOperationsMixin:
|
|
|
161
161
|
async def _check_workspace_exists_async(self: "HTTPSandboxBackend") -> bool:
|
|
162
162
|
"""检查沙箱工作空间是否存在(异步版本)"""
|
|
163
163
|
try:
|
|
164
|
-
await self._post_async_with_failover(f"{SANDBOX_API_PREFIX}/
|
|
164
|
+
result = await self._post_async_with_failover(f"{SANDBOX_API_PREFIX}/stat", {
|
|
165
165
|
"path": "/",
|
|
166
166
|
"user_id": self.user_id
|
|
167
167
|
})
|
|
168
|
-
return
|
|
168
|
+
return result.get("exists", False)
|
|
169
169
|
except Exception as e:
|
|
170
170
|
SYLogger.warning(f"[Sandbox] 检查工作空间失败: {e}")
|
|
171
171
|
return False
|
|
@@ -184,47 +184,31 @@ class FileOperationsMixin:
|
|
|
184
184
|
"""列出目录内容"""
|
|
185
185
|
try:
|
|
186
186
|
self._ensure_synced_sync()
|
|
187
|
-
print(
|
|
188
|
-
f"[Sandbox-DEBUG] ls() called with path={repr(path)}, user_id={repr(self.user_id)}", flush=True)
|
|
189
187
|
SYLogger.info(f"[Sandbox] 列出目录: {path}")
|
|
190
188
|
result = self._post_sync(f"{SANDBOX_API_PREFIX}/ls", {
|
|
191
189
|
"path": path,
|
|
192
190
|
"user_id": self.user_id
|
|
193
191
|
})
|
|
194
|
-
print(
|
|
195
|
-
f"[Sandbox-DEBUG] ls() raw result type={type(result).__name__}, repr={repr(result)[:500]}", flush=True)
|
|
196
192
|
entries = [FileInfo(**item) for item in result]
|
|
197
|
-
print(
|
|
198
|
-
f"[Sandbox-DEBUG] ls() parsed entries={len(entries)}", flush=True)
|
|
199
193
|
SYLogger.info(f"[Sandbox] 目录内容: {len(entries)} 项")
|
|
200
194
|
return LsResult(entries=entries)
|
|
201
195
|
except Exception as e:
|
|
202
|
-
print(
|
|
203
|
-
f"[Sandbox-DEBUG] ls() EXCEPTION: {type(e).__name__}: {e}", flush=True)
|
|
204
196
|
SYLogger.error(f"[Sandbox] 列出目录失败: {e}")
|
|
205
197
|
return LsResult(error=str(e))
|
|
206
198
|
|
|
207
199
|
async def als(self: "HTTPSandboxBackend", path: str) -> LsResult:
|
|
208
|
-
"""
|
|
200
|
+
"""异步列出目录内容"""
|
|
209
201
|
try:
|
|
210
202
|
await self._ensure_synced_async()
|
|
211
|
-
print(
|
|
212
|
-
f"[Sandbox-DEBUG] als() called with path={repr(path)}, user_id={repr(self.user_id)}, base_url={repr(self._base_url if hasattr(self, '_base_url') else 'N/A')}", flush=True)
|
|
213
203
|
SYLogger.info(f"[Sandbox] 异步列出目录: {path}")
|
|
214
204
|
result = await self._post_async_with_failover(f"{SANDBOX_API_PREFIX}/ls", {
|
|
215
205
|
"path": path,
|
|
216
206
|
"user_id": self.user_id
|
|
217
207
|
})
|
|
218
|
-
print(
|
|
219
|
-
f"[Sandbox-DEBUG] als() raw result type={type(result).__name__}, repr={repr(result)[:500]}", flush=True)
|
|
220
208
|
entries = [FileInfo(**item) for item in result]
|
|
221
|
-
print(
|
|
222
|
-
f"[Sandbox-DEBUG] als() parsed entries={len(entries)}, first 3 paths={[e.get('path','?') if isinstance(e, dict) else getattr(e, 'path','?') for e in entries[:3]]}", flush=True)
|
|
223
209
|
SYLogger.info(f"[Sandbox] 目录内容: {len(entries)} 项")
|
|
224
210
|
return LsResult(entries=entries)
|
|
225
211
|
except Exception as e:
|
|
226
|
-
print(
|
|
227
|
-
f"[Sandbox-DEBUG] als() EXCEPTION: {type(e).__name__}: {e}", flush=True)
|
|
228
212
|
SYLogger.error(f"[Sandbox] 异步列出目录失败: {e}")
|
|
229
213
|
return LsResult(error=str(e))
|
|
230
214
|
|
|
@@ -251,15 +235,11 @@ class FileOperationsMixin:
|
|
|
251
235
|
SYLogger.error(f"[Sandbox] 读取文件失败: {result['error']}")
|
|
252
236
|
return ReadResult(error=result["error"])
|
|
253
237
|
content = result.get("content", "")
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
from datetime import datetime
|
|
257
|
-
now = datetime.now().isoformat()
|
|
238
|
+
encoding = result.get("encoding", "utf-8")
|
|
239
|
+
SYLogger.info(f"[Sandbox] 读取完成: {len(content)} 字符, encoding={encoding}")
|
|
258
240
|
file_data = FileData(
|
|
259
241
|
content=content,
|
|
260
|
-
encoding=
|
|
261
|
-
created_at=result.get("created_at", now),
|
|
262
|
-
modified_at=result.get("modified_at", now),
|
|
242
|
+
encoding=encoding,
|
|
263
243
|
)
|
|
264
244
|
return ReadResult(file_data=file_data)
|
|
265
245
|
except Exception as e:
|
|
@@ -287,14 +267,11 @@ class FileOperationsMixin:
|
|
|
287
267
|
SYLogger.error(f"[Sandbox] 异步读取文件失败: {result['error']}")
|
|
288
268
|
return ReadResult(error=result["error"])
|
|
289
269
|
content = result.get("content", "")
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
now = datetime.now().isoformat()
|
|
270
|
+
encoding = result.get("encoding", "utf-8")
|
|
271
|
+
SYLogger.info(f"[Sandbox] 异步读取完成: {len(content)} 字符, encoding={encoding}")
|
|
293
272
|
file_data = FileData(
|
|
294
273
|
content=content,
|
|
295
|
-
encoding=
|
|
296
|
-
created_at=result.get("created_at", now),
|
|
297
|
-
modified_at=result.get("modified_at", now),
|
|
274
|
+
encoding=encoding,
|
|
298
275
|
)
|
|
299
276
|
return ReadResult(file_data=file_data)
|
|
300
277
|
except Exception as e:
|
|
@@ -602,29 +579,23 @@ class FileOperationsMixin:
|
|
|
602
579
|
# ============== 文件存在检查 ==============
|
|
603
580
|
|
|
604
581
|
async def astat(self: "HTTPSandboxBackend", path: str) -> "StatResult":
|
|
605
|
-
"""
|
|
582
|
+
"""异步检查文件或目录状态(使用 /stat 端点)"""
|
|
606
583
|
try:
|
|
607
584
|
await self._ensure_synced_async()
|
|
608
|
-
SYLogger.info(f"[Sandbox]
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
"
|
|
612
|
-
"user_id": self.user_id,
|
|
613
|
-
"offset": 0,
|
|
614
|
-
"limit": 1,
|
|
585
|
+
SYLogger.info(f"[Sandbox] 异步查询文件状态: {path}")
|
|
586
|
+
result = await self._post_async_with_failover(f"{SANDBOX_API_PREFIX}/stat", {
|
|
587
|
+
"path": path,
|
|
588
|
+
"user_id": self.user_id
|
|
615
589
|
})
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
return StatResult(path=path, exists=True, is_dir=True, size=0)
|
|
624
|
-
|
|
625
|
-
return StatResult(path=path, exists=False)
|
|
590
|
+
return StatResult(
|
|
591
|
+
path=result.get("path", path),
|
|
592
|
+
exists=result.get("exists", False),
|
|
593
|
+
is_dir=result.get("is_dir", False),
|
|
594
|
+
size=result.get("size", 0),
|
|
595
|
+
error=result.get("error")
|
|
596
|
+
)
|
|
626
597
|
except Exception as e:
|
|
627
|
-
SYLogger.error(f"[Sandbox]
|
|
598
|
+
SYLogger.error(f"[Sandbox] 异步查询文件状态异常: {e}")
|
|
628
599
|
return StatResult(path=path, error=str(e))
|
|
629
600
|
|
|
630
601
|
|