Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add sync watch handler

Jakub Novak81db2b146667
diff --git a/packages/python-sdk/e2b/envd/filesystem/filesystem_connect.py b/packages/python-sdk/e2b/envd/filesystem/filesystem_connect.py
index 8204899b5..fd52acf68 100644
--- a/packages/python-sdk/e2b/envd/filesystem/filesystem_connect.py
+++ b/packages/python-sdk/e2b/envd/filesystem/filesystem_connect.py
@@ -10,7 +10,16 @@ FilesystemName = "filesystem.Filesystem"
class FilesystemClient:
- def __init__(self, base_url: str, *, pool: Optional[ConnectionPool] = None, async_pool: Optional[AsyncConnectionPool] = None, compressor=None, json=False, **opts):
+ def __init__(
+ self,
+ base_url: str,
+ *,
+ pool: Optional[ConnectionPool] = None,
+ async_pool: Optional[AsyncConnectionPool] = None,
+ compressor=None,
+ json=False,
+ **opts,
+ ):
self._stat = connect.Client(
pool=pool,
async_pool=async_pool,
@@ -18,7 +27,7 @@ class FilesystemClient:
response_type=filesystem_dot_filesystem__pb2.StatResponse,
compressor=compressor,
json=json,
- **opts
+ **opts,
)
self._make_dir = connect.Client(
pool=pool,
@@ -27,7 +36,7 @@ class FilesystemClient:
response_type=filesystem_dot_filesystem__pb2.MakeDirResponse,
compressor=compressor,
json=json,
- **opts
+ **opts,
)
self._move = connect.Client(
pool=pool,
@@ -36,7 +45,7 @@ class FilesystemClient:
response_type=filesystem_dot_filesystem__pb2.MoveResponse,
compressor=compressor,
json=json,
- **opts
+ **opts,
)
self._list_dir = connect.Client(
pool=pool,
@@ -45,7 +54,16 @@ class FilesystemClient:
response_type=filesystem_dot_filesystem__pb2.ListDirResponse,
compressor=compressor,
json=json,
- **opts
+ **opts,
+ )
+ self._remove = connect.Client(
+ pool=pool,
+ async_pool=async_pool,
+ url=f"{base_url}/{FilesystemName}/Remove",
+ response_type=filesystem_dot_filesystem__pb2.RemoveResponse,
+ compressor=compressor,
+ json=json,
+ **opts,
)
self._watch_dir = connect.Client(
pool=pool,
@@ -54,50 +72,122 @@ class FilesystemClient:
response_type=filesystem_dot_filesystem__pb2.WatchDirResponse,
compressor=compressor,
json=json,
- **opts
+ **opts,
)
- self._remove = connect.Client(
+ self._watch_dir_start = connect.Client(
pool=pool,
async_pool=async_pool,
- url=f"{base_url}/{FilesystemName}/Remove",
- response_type=filesystem_dot_filesystem__pb2.RemoveResponse,
+ url=f"{base_url}/{FilesystemName}/WatchDirStart",
+ response_type=filesystem_dot_filesystem__pb2.WatchDirStartResponse,
+ compressor=compressor,
+ json=json,
+ **opts,
+ )
+ self._watch_dir_poll = connect.Client(
+ pool=pool,
+ async_pool=async_pool,
+ url=f"{base_url}/{FilesystemName}/WatchDirPoll",
+ response_type=filesystem_dot_filesystem__pb2.WatchDirPollResponse,
+ compressor=compressor,
+ json=json,
+ **opts,
+ )
+ self._watch_dir_stop = connect.Client(
+ pool=pool,
+ async_pool=async_pool,
+ url=f"{base_url}/{FilesystemName}/WatchDirStop",
+ response_type=filesystem_dot_filesystem__pb2.WatchDirStopResponse,
compressor=compressor,
json=json,
- **opts
+ **opts,
)
- def stat(self, req: filesystem_dot_filesystem__pb2.StatRequest, **opts) -> filesystem_dot_filesystem__pb2.StatResponse:
+ def stat(
+ self, req: filesystem_dot_filesystem__pb2.StatRequest, **opts
+ ) -> filesystem_dot_filesystem__pb2.StatResponse:
return self._stat.call_unary(req, **opts)
- def astat(self, req: filesystem_dot_filesystem__pb2.StatRequest, **opts) -> Coroutine[Any, Any, filesystem_dot_filesystem__pb2.StatResponse]:
+ def astat(
+ self, req: filesystem_dot_filesystem__pb2.StatRequest, **opts
+ ) -> Coroutine[Any, Any, filesystem_dot_filesystem__pb2.StatResponse]:
return self._stat.acall_unary(req, **opts)
- def make_dir(self, req: filesystem_dot_filesystem__pb2.MakeDirRequest, **opts) -> filesystem_dot_filesystem__pb2.MakeDirResponse:
+ def make_dir(
+ self, req: filesystem_dot_filesystem__pb2.MakeDirRequest, **opts
+ ) -> filesystem_dot_filesystem__pb2.MakeDirResponse:
return self._make_dir.call_unary(req, **opts)
- def amake_dir(self, req: filesystem_dot_filesystem__pb2.MakeDirRequest, **opts) -> Coroutine[Any, Any, filesystem_dot_filesystem__pb2.MakeDirResponse]:
+ def amake_dir(
+ self, req: filesystem_dot_filesystem__pb2.MakeDirRequest, **opts
+ ) -> Coroutine[Any, Any, filesystem_dot_filesystem__pb2.MakeDirResponse]:
return self._make_dir.acall_unary(req, **opts)
- def move(self, req: filesystem_dot_filesystem__pb2.MoveRequest, **opts) -> filesystem_dot_filesystem__pb2.MoveResponse:
+ def move(
+ self, req: filesystem_dot_filesystem__pb2.MoveRequest, **opts
+ ) -> filesystem_dot_filesystem__pb2.MoveResponse:
return self._move.call_unary(req, **opts)
- def amove(self, req: filesystem_dot_filesystem__pb2.MoveRequest, **opts) -> Coroutine[Any, Any, filesystem_dot_filesystem__pb2.MoveResponse]:
+ def amove(
+ self, req: filesystem_dot_filesystem__pb2.MoveRequest, **opts
+ ) -> Coroutine[Any, Any, filesystem_dot_filesystem__pb2.MoveResponse]:
return self._move.acall_unary(req, **opts)
- def list_dir(self, req: filesystem_dot_filesystem__pb2.ListDirRequest, **opts) -> filesystem_dot_filesystem__pb2.ListDirResponse:
+ def list_dir(
+ self, req: filesystem_dot_filesystem__pb2.ListDirRequest, **opts
+ ) -> filesystem_dot_filesystem__pb2.ListDirResponse:
return self._list_dir.call_unary(req, **opts)
- def alist_dir(self, req: filesystem_dot_filesystem__pb2.ListDirRequest, **opts) -> Coroutine[Any, Any, filesystem_dot_filesystem__pb2.ListDirResponse]:
+ def alist_dir(
+ self, req: filesystem_dot_filesystem__pb2.ListDirRequest, **opts
+ ) -> Coroutine[Any, Any, filesystem_dot_filesystem__pb2.ListDirResponse]:
return self._list_dir.acall_unary(req, **opts)
- def watch_dir(self, req: filesystem_dot_filesystem__pb2.WatchDirRequest , **opts) -> Generator[filesystem_dot_filesystem__pb2.WatchDirResponse, Any, None]:
+ def remove(
+ self, req: filesystem_dot_filesystem__pb2.RemoveRequest, **opts
+ ) -> filesystem_dot_filesystem__pb2.RemoveResponse:
+ return self._remove.call_unary(req, **opts)
+
+ def aremove(
+ self, req: filesystem_dot_filesystem__pb2.RemoveRequest, **opts
+ ) -> Coroutine[Any, Any, filesystem_dot_filesystem__pb2.RemoveResponse]:
+ return self._remove.acall_unary(req, **opts)
+
+ def watch_dir(
+ self, req: filesystem_dot_filesystem__pb2.WatchDirRequest, **opts
+ ) -> Generator[filesystem_dot_filesystem__pb2.WatchDirResponse, Any, None]:
return self._watch_dir.call_server_stream(req, **opts)
- def awatch_dir(self, req: filesystem_dot_filesystem__pb2.WatchDirRequest , **opts) -> AsyncGenerator[filesystem_dot_filesystem__pb2.WatchDirResponse, Any]:
+ def awatch_dir(
+ self, req: filesystem_dot_filesystem__pb2.WatchDirRequest, **opts
+ ) -> AsyncGenerator[filesystem_dot_filesystem__pb2.WatchDirResponse, Any]:
return self._watch_dir.acall_server_stream(req, **opts)
- def remove(self, req: filesystem_dot_filesystem__pb2.RemoveRequest, **opts) -> filesystem_dot_filesystem__pb2.RemoveResponse:
- return self._remove.call_unary(req, **opts)
-
- def aremove(self, req: filesystem_dot_filesystem__pb2.RemoveRequest, **opts) -> Coroutine[Any, Any, filesystem_dot_filesystem__pb2.RemoveResponse]:
- return self._remove.acall_unary(req, **opts)
+ def watch_dir_start(
+ self, req: filesystem_dot_filesystem__pb2.WatchDirRequest, **opts
+ ) -> filesystem_dot_filesystem__pb2.WatchDirStartResponse:
+ return self._watch_dir_start.call_unary(req, **opts)
+
+ def awatch_dir_start(
+ self, req: filesystem_dot_filesystem__pb2.WatchDirRequest, **opts
+ ) -> Coroutine[Any, Any, filesystem_dot_filesystem__pb2.WatchDirStartResponse]:
+ return self._watch_dir_start.acall_unary(req, **opts)
+
+ def watch_dir_poll(
+ self, req: filesystem_dot_filesystem__pb2.WatchDirPollRequest, **opts
+ ) -> filesystem_dot_filesystem__pb2.WatchDirPollResponse:
+ return self._watch_dir_poll.call_unary(req, **opts)
+
+ def awatch_dir_poll(
+ self, req: filesystem_dot_filesystem__pb2.WatchDirPollRequest, **opts
+ ) -> Coroutine[Any, Any, filesystem_dot_filesystem__pb2.WatchDirPollResponse]:
+ return self._watch_dir_poll.acall_unary(req, **opts)
+
+ def watch_dir_stop(
+ self, req: filesystem_dot_filesystem__pb2.WatchDirStopRequest, **opts
+ ) -> filesystem_dot_filesystem__pb2.WatchDirStopResponse:
+ return self._watch_dir_stop.call_unary(req, **opts)
+
+ def awatch_dir_stop(
+ self, req: filesystem_dot_filesystem__pb2.WatchDirStopRequest, **opts
+ ) -> Coroutine[Any, Any, filesystem_dot_filesystem__pb2.WatchDirStopResponse]:
+ return self._watch_dir_stop.acall_unary(req, **opts)
diff --git a/packages/python-sdk/e2b/envd/filesystem/filesystem_pb2.py b/packages/python-sdk/e2b/envd/filesystem/filesystem_pb2.py
index 43288a9f9..3d5968d13 100644
--- a/packages/python-sdk/e2b/envd/filesystem/filesystem_pb2.py
+++ b/packages/python-sdk/e2b/envd/filesystem/filesystem_pb2.py
@@ -7,57 +7,72 @@ from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder
+
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
-
-
-DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1b\x66ilesystem/filesystem.proto\x12\nfilesystem\"G\n\x0bMoveRequest\x12\x16\n\x06source\x18\x01 \x01(\tR\x06source\x12 \n\x0b\x64\x65stination\x18\x02 \x01(\tR\x0b\x64\x65stination\";\n\x0cMoveResponse\x12+\n\x05\x65ntry\x18\x01 \x01(\x0b\x32\x15.filesystem.EntryInfoR\x05\x65ntry\"$\n\x0eMakeDirRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path\">\n\x0fMakeDirResponse\x12+\n\x05\x65ntry\x18\x01 \x01(\x0b\x32\x15.filesystem.EntryInfoR\x05\x65ntry\"#\n\rRemoveRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path\"\x10\n\x0eRemoveResponse\"!\n\x0bStatRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path\";\n\x0cStatResponse\x12+\n\x05\x65ntry\x18\x01 \x01(\x0b\x32\x15.filesystem.EntryInfoR\x05\x65ntry\"]\n\tEntryInfo\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12(\n\x04type\x18\x02 \x01(\x0e\x32\x14.filesystem.FileTypeR\x04type\x12\x12\n\x04path\x18\x03 \x01(\tR\x04path\"$\n\x0eListDirRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path\"B\n\x0fListDirResponse\x12/\n\x07\x65ntries\x18\x01 \x03(\x0b\x32\x15.filesystem.EntryInfoR\x07\x65ntries\"%\n\x0fWatchDirRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path\"\xe1\x02\n\x10WatchDirResponse\x12?\n\x05start\x18\x01 \x01(\x0b\x32\'.filesystem.WatchDirResponse.StartEventH\x00R\x05start\x12N\n\nfilesystem\x18\x02 \x01(\x0b\x32,.filesystem.WatchDirResponse.FilesystemEventH\x00R\nfilesystem\x12\x46\n\tkeepalive\x18\x03 \x01(\x0b\x32&.filesystem.WatchDirResponse.KeepAliveH\x00R\tkeepalive\x1a\x0c\n\nStartEvent\x1aP\n\x0f\x46ilesystemEvent\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12)\n\x04type\x18\x02 \x01(\x0e\x32\x15.filesystem.EventTypeR\x04type\x1a\x0b\n\tKeepAliveB\x07\n\x05\x65vent*R\n\x08\x46ileType\x12\x19\n\x15\x46ILE_TYPE_UNSPECIFIED\x10\x00\x12\x12\n\x0e\x46ILE_TYPE_FILE\x10\x01\x12\x17\n\x13\x46ILE_TYPE_DIRECTORY\x10\x02*\x98\x01\n\tEventType\x12\x1a\n\x16\x45VENT_TYPE_UNSPECIFIED\x10\x00\x12\x15\n\x11\x45VENT_TYPE_CREATE\x10\x01\x12\x14\n\x10\x45VENT_TYPE_WRITE\x10\x02\x12\x15\n\x11\x45VENT_TYPE_REMOVE\x10\x03\x12\x15\n\x11\x45VENT_TYPE_RENAME\x10\x04\x12\x14\n\x10\x45VENT_TYPE_CHMOD\x10\x05\x32\x94\x03\n\nFilesystem\x12\x39\n\x04Stat\x12\x17.filesystem.StatRequest\x1a\x18.filesystem.StatResponse\x12\x42\n\x07MakeDir\x12\x1a.filesystem.MakeDirRequest\x1a\x1b.filesystem.MakeDirResponse\x12\x39\n\x04Move\x12\x17.filesystem.MoveRequest\x1a\x18.filesystem.MoveResponse\x12\x42\n\x07ListDir\x12\x1a.filesystem.ListDirRequest\x1a\x1b.filesystem.ListDirResponse\x12G\n\x08WatchDir\x12\x1b.filesystem.WatchDirRequest\x1a\x1c.filesystem.WatchDirResponse0\x01\x12?\n\x06Remove\x12\x19.filesystem.RemoveRequest\x1a\x1a.filesystem.RemoveResponseBi\n\x0e\x63om.filesystemB\x0f\x46ilesystemProtoP\x01\xa2\x02\x03\x46XX\xaa\x02\nFilesystem\xca\x02\nFilesystem\xe2\x02\x16\x46ilesystem\\GPBMetadata\xea\x02\nFilesystemb\x06proto3')
+DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(
+ b'\n%spec/envd/filesystem/filesystem.proto\x12\nfilesystem"G\n\x0bMoveRequest\x12\x16\n\x06source\x18\x01 \x01(\tR\x06source\x12 \n\x0b\x64\x65stination\x18\x02 \x01(\tR\x0b\x64\x65stination";\n\x0cMoveResponse\x12+\n\x05\x65ntry\x18\x01 \x01(\x0b\x32\x15.filesystem.EntryInfoR\x05\x65ntry"$\n\x0eMakeDirRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path">\n\x0fMakeDirResponse\x12+\n\x05\x65ntry\x18\x01 \x01(\x0b\x32\x15.filesystem.EntryInfoR\x05\x65ntry"#\n\rRemoveRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path"\x10\n\x0eRemoveResponse"!\n\x0bStatRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path";\n\x0cStatResponse\x12+\n\x05\x65ntry\x18\x01 \x01(\x0b\x32\x15.filesystem.EntryInfoR\x05\x65ntry"]\n\tEntryInfo\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12(\n\x04type\x18\x02 \x01(\x0e\x32\x14.filesystem.FileTypeR\x04type\x12\x12\n\x04path\x18\x03 \x01(\tR\x04path"$\n\x0eListDirRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path"B\n\x0fListDirResponse\x12/\n\x07\x65ntries\x18\x01 \x03(\x0b\x32\x15.filesystem.EntryInfoR\x07\x65ntries"%\n\x0fWatchDirRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path"P\n\x0f\x46ilesystemEvent\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12)\n\x04type\x18\x02 \x01(\x0e\x32\x15.filesystem.EventTypeR\x04type"\xfe\x01\n\x10WatchDirResponse\x12?\n\x05start\x18\x01 \x01(\x0b\x32\'.filesystem.WatchDirResponse.StartEventH\x00R\x05start\x12=\n\nfilesystem\x18\x02 \x01(\x0b\x32\x1b.filesystem.FilesystemEventH\x00R\nfilesystem\x12\x46\n\tkeepalive\x18\x03 \x01(\x0b\x32&.filesystem.WatchDirResponse.KeepAliveH\x00R\tkeepalive\x1a\x0c\n\nStartEvent\x1a\x0b\n\tKeepAliveB\x07\n\x05\x65vent"5\n\x15WatchDirStartResponse\x12\x1c\n\twatcherId\x18\x01 \x01(\tR\twatcherId"K\n\x13WatchDirPollRequest\x12\x1c\n\twatcherId\x18\x01 \x01(\tR\twatcherId\x12\x16\n\x06offset\x18\x02 \x01(\rR\x06offset"K\n\x14WatchDirPollResponse\x12\x33\n\x06\x65vents\x18\x01 \x03(\x0b\x32\x1b.filesystem.FilesystemEventR\x06\x65vents"3\n\x13WatchDirStopRequest\x12\x1c\n\twatcherId\x18\x01 \x01(\tR\twatcherId"\x16\n\x14WatchDirStopResponse*R\n\x08\x46ileType\x12\x19\n\x15\x46ILE_TYPE_UNSPECIFIED\x10\x00\x12\x12\n\x0e\x46ILE_TYPE_FILE\x10\x01\x12\x17\n\x13\x46ILE_TYPE_DIRECTORY\x10\x02*\x98\x01\n\tEventType\x12\x1a\n\x16\x45VENT_TYPE_UNSPECIFIED\x10\x00\x12\x15\n\x11\x45VENT_TYPE_CREATE\x10\x01\x12\x14\n\x10\x45VENT_TYPE_WRITE\x10\x02\x12\x15\n\x11\x45VENT_TYPE_REMOVE\x10\x03\x12\x15\n\x11\x45VENT_TYPE_RENAME\x10\x04\x12\x14\n\x10\x45VENT_TYPE_CHMOD\x10\x05\x32\x8b\x05\n\nFilesystem\x12\x39\n\x04Stat\x12\x17.filesystem.StatRequest\x1a\x18.filesystem.StatResponse\x12\x42\n\x07MakeDir\x12\x1a.filesystem.MakeDirRequest\x1a\x1b.filesystem.MakeDirResponse\x12\x39\n\x04Move\x12\x17.filesystem.MoveRequest\x1a\x18.filesystem.MoveResponse\x12\x42\n\x07ListDir\x12\x1a.filesystem.ListDirRequest\x1a\x1b.filesystem.ListDirResponse\x12?\n\x06Remove\x12\x19.filesystem.RemoveRequest\x1a\x1a.filesystem.RemoveResponse\x12G\n\x08WatchDir\x12\x1b.filesystem.WatchDirRequest\x1a\x1c.filesystem.WatchDirResponse0\x01\x12O\n\rWatchDirStart\x12\x1b.filesystem.WatchDirRequest\x1a!.filesystem.WatchDirStartResponse\x12Q\n\x0cWatchDirPoll\x12\x1f.filesystem.WatchDirPollRequest\x1a .filesystem.WatchDirPollResponse\x12Q\n\x0cWatchDirStop\x12\x1f.filesystem.WatchDirStopRequest\x1a .filesystem.WatchDirStopResponseBi\n\x0e\x63om.filesystemB\x0f\x46ilesystemProtoP\x01\xa2\x02\x03\x46XX\xaa\x02\nFilesystem\xca\x02\nFilesystem\xe2\x02\x16\x46ilesystem\\GPBMetadata\xea\x02\nFilesystemb\x06proto3'
+)
_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
-_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'filesystem.filesystem_pb2', _globals)
+_builder.BuildTopDescriptorsAndMessages(
+ DESCRIPTOR, "spec.envd.filesystem.filesystem_pb2", _globals
+)
if not _descriptor._USE_C_DESCRIPTORS:
- _globals['DESCRIPTOR']._loaded_options = None
- _globals['DESCRIPTOR']._serialized_options = b'\n\016com.filesystemB\017FilesystemProtoP\001\242\002\003FXX\252\002\nFilesystem\312\002\nFilesystem\342\002\026Filesystem\\GPBMetadata\352\002\nFilesystem'
- _globals['_FILETYPE']._serialized_start=1026
- _globals['_FILETYPE']._serialized_end=1108
- _globals['_EVENTTYPE']._serialized_start=1111
- _globals['_EVENTTYPE']._serialized_end=1263
- _globals['_MOVEREQUEST']._serialized_start=43
- _globals['_MOVEREQUEST']._serialized_end=114
- _globals['_MOVERESPONSE']._serialized_start=116
- _globals['_MOVERESPONSE']._serialized_end=175
- _globals['_MAKEDIRREQUEST']._serialized_start=177
- _globals['_MAKEDIRREQUEST']._serialized_end=213
- _globals['_MAKEDIRRESPONSE']._serialized_start=215
- _globals['_MAKEDIRRESPONSE']._serialized_end=277
- _globals['_REMOVEREQUEST']._serialized_start=279
- _globals['_REMOVEREQUEST']._serialized_end=314
- _globals['_REMOVERESPONSE']._serialized_start=316
- _globals['_REMOVERESPONSE']._serialized_end=332
- _globals['_STATREQUEST']._serialized_start=334
- _globals['_STATREQUEST']._serialized_end=367
- _globals['_STATRESPONSE']._serialized_start=369
- _globals['_STATRESPONSE']._serialized_end=428
- _globals['_ENTRYINFO']._serialized_start=430
- _globals['_ENTRYINFO']._serialized_end=523
- _globals['_LISTDIRREQUEST']._serialized_start=525
- _globals['_LISTDIRREQUEST']._serialized_end=561
- _globals['_LISTDIRRESPONSE']._serialized_start=563
- _globals['_LISTDIRRESPONSE']._serialized_end=629
- _globals['_WATCHDIRREQUEST']._serialized_start=631
- _globals['_WATCHDIRREQUEST']._serialized_end=668
- _globals['_WATCHDIRRESPONSE']._serialized_start=671
- _globals['_WATCHDIRRESPONSE']._serialized_end=1024
- _globals['_WATCHDIRRESPONSE_STARTEVENT']._serialized_start=908
- _globals['_WATCHDIRRESPONSE_STARTEVENT']._serialized_end=920
- _globals['_WATCHDIRRESPONSE_FILESYSTEMEVENT']._serialized_start=922
- _globals['_WATCHDIRRESPONSE_FILESYSTEMEVENT']._serialized_end=1002
- _globals['_WATCHDIRRESPONSE_KEEPALIVE']._serialized_start=1004
- _globals['_WATCHDIRRESPONSE_KEEPALIVE']._serialized_end=1015
- _globals['_FILESYSTEM']._serialized_start=1266
- _globals['_FILESYSTEM']._serialized_end=1670
+ _globals["DESCRIPTOR"]._loaded_options = None
+ _globals["DESCRIPTOR"]._serialized_options = (
+ b"\n\016com.filesystemB\017FilesystemProtoP\001\242\002\003FXX\252\002\nFilesystem\312\002\nFilesystem\342\002\026Filesystem\\GPBMetadata\352\002\nFilesystem"
+ )
+ _globals["_FILETYPE"]._serialized_start = 1305
+ _globals["_FILETYPE"]._serialized_end = 1387
+ _globals["_EVENTTYPE"]._serialized_start = 1390
+ _globals["_EVENTTYPE"]._serialized_end = 1542
+ _globals["_MOVEREQUEST"]._serialized_start = 53
+ _globals["_MOVEREQUEST"]._serialized_end = 124
+ _globals["_MOVERESPONSE"]._serialized_start = 126
+ _globals["_MOVERESPONSE"]._serialized_end = 185
+ _globals["_MAKEDIRREQUEST"]._serialized_start = 187
+ _globals["_MAKEDIRREQUEST"]._serialized_end = 223
+ _globals["_MAKEDIRRESPONSE"]._serialized_start = 225
+ _globals["_MAKEDIRRESPONSE"]._serialized_end = 287
+ _globals["_REMOVEREQUEST"]._serialized_start = 289
+ _globals["_REMOVEREQUEST"]._serialized_end = 324
+ _globals["_REMOVERESPONSE"]._serialized_start = 326
+ _globals["_REMOVERESPONSE"]._serialized_end = 342
+ _globals["_STATREQUEST"]._serialized_start = 344
+ _globals["_STATREQUEST"]._serialized_end = 377
+ _globals["_STATRESPONSE"]._serialized_start = 379
+ _globals["_STATRESPONSE"]._serialized_end = 438
+ _globals["_ENTRYINFO"]._serialized_start = 440
+ _globals["_ENTRYINFO"]._serialized_end = 533
+ _globals["_LISTDIRREQUEST"]._serialized_start = 535
+ _globals["_LISTDIRREQUEST"]._serialized_end = 571
+ _globals["_LISTDIRRESPONSE"]._serialized_start = 573
+ _globals["_LISTDIRRESPONSE"]._serialized_end = 639
+ _globals["_WATCHDIRREQUEST"]._serialized_start = 641
+ _globals["_WATCHDIRREQUEST"]._serialized_end = 678
+ _globals["_FILESYSTEMEVENT"]._serialized_start = 680
+ _globals["_FILESYSTEMEVENT"]._serialized_end = 760
+ _globals["_WATCHDIRRESPONSE"]._serialized_start = 763
+ _globals["_WATCHDIRRESPONSE"]._serialized_end = 1017
+ _globals["_WATCHDIRRESPONSE_STARTEVENT"]._serialized_start = 983
+ _globals["_WATCHDIRRESPONSE_STARTEVENT"]._serialized_end = 995
+ _globals["_WATCHDIRRESPONSE_KEEPALIVE"]._serialized_start = 997
+ _globals["_WATCHDIRRESPONSE_KEEPALIVE"]._serialized_end = 1008
+ _globals["_WATCHDIRSTARTRESPONSE"]._serialized_start = 1019
+ _globals["_WATCHDIRSTARTRESPONSE"]._serialized_end = 1072
+ _globals["_WATCHDIRPOLLREQUEST"]._serialized_start = 1074
+ _globals["_WATCHDIRPOLLREQUEST"]._serialized_end = 1149
+ _globals["_WATCHDIRPOLLRESPONSE"]._serialized_start = 1151
+ _globals["_WATCHDIRPOLLRESPONSE"]._serialized_end = 1226
+ _globals["_WATCHDIRSTOPREQUEST"]._serialized_start = 1228
+ _globals["_WATCHDIRSTOPREQUEST"]._serialized_end = 1279
+ _globals["_WATCHDIRSTOPRESPONSE"]._serialized_start = 1281
+ _globals["_WATCHDIRSTOPRESPONSE"]._serialized_end = 1303
+ _globals["_FILESYSTEM"]._serialized_start = 1545
+ _globals["_FILESYSTEM"]._serialized_end = 2196
# @@protoc_insertion_point(module_scope)
diff --git a/packages/python-sdk/e2b/envd/filesystem/filesystem_pb2.pyi b/packages/python-sdk/e2b/envd/filesystem/filesystem_pb2.pyi
index 8d05ef81d..647a4d2ee 100644
--- a/packages/python-sdk/e2b/envd/filesystem/filesystem_pb2.pyi
+++ b/packages/python-sdk/e2b/envd/filesystem/filesystem_pb2.pyi
@@ -106,18 +106,19 @@ class WatchDirRequest(_message.Message):
path: str
def __init__(self, path: _Optional[str] = ...) -> None: ...
+class FilesystemEvent(_message.Message):
+ __slots__ = ("name", "type")
+ NAME_FIELD_NUMBER: _ClassVar[int]
+ TYPE_FIELD_NUMBER: _ClassVar[int]
+ name: str
+ type: EventType
+ def __init__(self, name: _Optional[str] = ..., type: _Optional[_Union[EventType, str]] = ...) -> None: ...
+
class WatchDirResponse(_message.Message):
__slots__ = ("start", "filesystem", "keepalive")
class StartEvent(_message.Message):
__slots__ = ()
def __init__(self) -> None: ...
- class FilesystemEvent(_message.Message):
- __slots__ = ("name", "type")
- NAME_FIELD_NUMBER: _ClassVar[int]
- TYPE_FIELD_NUMBER: _ClassVar[int]
- name: str
- type: EventType
- def __init__(self, name: _Optional[str] = ..., type: _Optional[_Union[EventType, str]] = ...) -> None: ...
class KeepAlive(_message.Message):
__slots__ = ()
def __init__(self) -> None: ...
@@ -125,6 +126,36 @@ class WatchDirResponse(_message.Message):
FILESYSTEM_FIELD_NUMBER: _ClassVar[int]
KEEPALIVE_FIELD_NUMBER: _ClassVar[int]
start: WatchDirResponse.StartEvent
- filesystem: WatchDirResponse.FilesystemEvent
+ filesystem: FilesystemEvent
keepalive: WatchDirResponse.KeepAlive
- def __init__(self, start: _Optional[_Union[WatchDirResponse.StartEvent, _Mapping]] = ..., filesystem: _Optional[_Union[WatchDirResponse.FilesystemEvent, _Mapping]] = ..., keepalive: _Optional[_Union[WatchDirResponse.KeepAlive, _Mapping]] = ...) -> None: ...
+ def __init__(self, start: _Optional[_Union[WatchDirResponse.StartEvent, _Mapping]] = ..., filesystem: _Optional[_Union[FilesystemEvent, _Mapping]] = ..., keepalive: _Optional[_Union[WatchDirResponse.KeepAlive, _Mapping]] = ...) -> None: ...
+
+class WatchDirStartResponse(_message.Message):
+ __slots__ = ("watcherId",)
+ WATCHERID_FIELD_NUMBER: _ClassVar[int]
+ watcherId: str
+ def __init__(self, watcherId: _Optional[str] = ...) -> None: ...
+
+class WatchDirPollRequest(_message.Message):
+ __slots__ = ("watcherId", "offset")
+ WATCHERID_FIELD_NUMBER: _ClassVar[int]
+ OFFSET_FIELD_NUMBER: _ClassVar[int]
+ watcherId: str
+ offset: int
+ def __init__(self, watcherId: _Optional[str] = ..., offset: _Optional[int] = ...) -> None: ...
+
+class WatchDirPollResponse(_message.Message):
+ __slots__ = ("events",)
+ EVENTS_FIELD_NUMBER: _ClassVar[int]
+ events: _containers.RepeatedCompositeFieldContainer[FilesystemEvent]
+ def __init__(self, events: _Optional[_Iterable[_Union[FilesystemEvent, _Mapping]]] = ...) -> None: ...
+
+class WatchDirStopRequest(_message.Message):
+ __slots__ = ("watcherId",)
+ WATCHERID_FIELD_NUMBER: _ClassVar[int]
+ watcherId: str
+ def __init__(self, watcherId: _Optional[str] = ...) -> None: ...
+
+class WatchDirStopResponse(_message.Message):
+ __slots__ = ()
+ def __init__(self) -> None: ...
diff --git a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
index fac8eca58..09010a794 100644
--- a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
+++ b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
@@ -13,7 +13,6 @@ from e2b.connection_config import (
from e2b.envd.api import ENVD_API_FILES_ROUTE, handle_envd_api_exception
from e2b.envd.filesystem import filesystem_connect, filesystem_pb2
from e2b.envd.rpc import authentication_header, handle_rpc_exception
-from e2b.exceptions import SandboxException
from e2b.sandbox.filesystem.filesystem import EntryInfo, map_file_type
from e2b.sandbox_sync.filesystem.watch_handle import WatchHandle
@@ -316,26 +315,19 @@ class Filesystem:
:param timeout: Timeout for the watch, after which the watch will be closed
:return: Watcher handle
"""
- events = self._rpc.watch_dir(
- filesystem_pb2.WatchDirRequest(path=path),
- request_timeout=self._connection_config.get_request_timeout(
- request_timeout
- ),
- timeout=timeout,
- headers={
- **authentication_header(user),
- KEEPALIVE_PING_HEADER: str(KEEPALIVE_PING_INTERVAL_SEC),
- },
- )
-
try:
- start_event = events.__next__()
-
- if not start_event.HasField("start"):
- raise SandboxException(
- f"Failed to start watch: expected start event, got {start_event}",
- )
-
- return WatchHandle(events=events)
+ r = self._rpc.watch_dir_start(
+ filesystem_pb2.WatchDirRequest(path=path),
+ request_timeout=self._connection_config.get_request_timeout(
+ request_timeout
+ ),
+ timeout=timeout,
+ headers={
+ **authentication_header(user),
+ KEEPALIVE_PING_HEADER: str(KEEPALIVE_PING_INTERVAL_SEC),
+ },
+ )
except Exception as e:
raise handle_rpc_exception(e)
+
+ return WatchHandle(self._rpc, r.watcherId)
diff --git a/packages/python-sdk/e2b/sandbox_sync/filesystem/watch_handle.py b/packages/python-sdk/e2b/sandbox_sync/filesystem/watch_handle.py
index b88f10b31..99637e306 100644
--- a/packages/python-sdk/e2b/sandbox_sync/filesystem/watch_handle.py
+++ b/packages/python-sdk/e2b/sandbox_sync/filesystem/watch_handle.py
@@ -1,7 +1,9 @@
-from typing import Any, Generator
+from typing import List
+from e2b import SandboxException
+from e2b.envd.filesystem import filesystem_connect
+from e2b.envd.filesystem.filesystem_pb2 import WatchDirStopRequest, WatchDirPollRequest
from e2b.envd.rpc import handle_rpc_exception
-from e2b.envd.filesystem.filesystem_pb2 import EventType, WatchDirResponse
from e2b.sandbox.filesystem.watch_handle import FilesystemEvent, map_event_type
@@ -12,31 +14,51 @@ class WatchHandle:
def __init__(
self,
- events: Generator[WatchDirResponse, Any, None],
+ rpc: filesystem_connect.FilesystemClient,
+ watcher_id: str,
):
- self._events = events
-
- def __iter__(self):
- return self._handle_events()
+ self._rpc = rpc
+ self._watcher_id = watcher_id
+ self._closed = False
def close(self):
"""
- Stop watching the directory.
+ Stop watching the directory. After you close the watcher you won't be able to get the events anymore.
+ """
+ try:
+ self._rpc.watch_dir_stop(WatchDirStopRequest(watcherId=self._watcher_id))
+ except Exception as e:
+ raise handle_rpc_exception(e)
- Warning:
- You won't get any event if you don't iterate over the handle before closing it.
+ self._closed = True
+
+ def get_events(self, offset: int = 0) -> List[FilesystemEvent]:
+ """
+ Get the events that occurred in the watched directory till now.
+ If you are calling it multiple times, you can pass the offset to get the new events only.
"""
- self._events.close()
+ if self._closed:
+ raise SandboxException("The watcher is already closed")
- def _handle_events(self):
try:
- for event in self._events:
- if event.HasField("filesystem"):
- event_type = map_event_type(event.filesystem.type)
- if event_type:
- yield FilesystemEvent(
- name=event.filesystem.name,
- type=event_type,
- )
+ r = self._rpc.watch_dir_poll(
+ WatchDirPollRequest(
+ watcherId=self._watcher_id,
+ offset=offset,
+ )
+ )
except Exception as e:
raise handle_rpc_exception(e)
+
+ events = []
+ for event in r.events:
+ event_type = map_event_type(event.type)
+ if event_type:
+ events.append(
+ FilesystemEvent(
+ name=event.name,
+ type=event_type,
+ )
+ )
+
+ return events
diff --git a/spec/envd/filesystem/filesystem.proto b/spec/envd/filesystem/filesystem.proto
index 10a2cdf20..23e9ab3a5 100644
--- a/spec/envd/filesystem/filesystem.proto
+++ b/spec/envd/filesystem/filesystem.proto
@@ -7,8 +7,14 @@ service Filesystem {
rpc MakeDir(MakeDirRequest) returns (MakeDirResponse);
rpc Move(MoveRequest) returns (MoveResponse);
rpc ListDir(ListDirRequest) returns (ListDirResponse);
- rpc WatchDir(WatchDirRequest) returns (stream WatchDirResponse);
rpc Remove(RemoveRequest) returns (RemoveResponse);
+
+ rpc WatchDir(WatchDirRequest) returns (stream WatchDirResponse);
+
+ // Non-streaming versions of WatchDir
+ rpc WatchDirStart(WatchDirRequest) returns (WatchDirStartResponse);
+ rpc WatchDirPoll(WatchDirPollRequest) returns (WatchDirPollResponse);
+ rpc WatchDirStop(WatchDirStopRequest) returns (WatchDirStopResponse);
}
message MoveRequest {
@@ -66,6 +72,11 @@ message WatchDirRequest {
string path = 1;
}
+message FilesystemEvent {
+ string name = 1;
+ EventType type = 2;
+}
+
message WatchDirResponse {
oneof event {
StartEvent start = 1;
@@ -75,14 +86,28 @@ message WatchDirResponse {
message StartEvent {}
- message FilesystemEvent {
- string name = 1;
- EventType type = 2;
- }
-
message KeepAlive {}
}
+message WatchDirStartResponse {
+ string watcherId = 1;
+}
+
+message WatchDirPollRequest {
+ string watcherId = 1;
+ uint32 offset = 2;
+}
+
+message WatchDirPollResponse {
+ repeated FilesystemEvent events = 1;
+}
+
+message WatchDirStopRequest {
+ string watcherId = 1;
+}
+
+message WatchDirStopResponse {}
+
enum EventType {
EVENT_TYPE_UNSPECIFIED = 0;
EVENT_TYPE_CREATE = 1;