PR that allows you to pass `proxy` (of the type ProxyTypes) when calling
methods in the SDK that send requests. Also, if you pass `proxy` when
creating a sandbox, all the sandbox requests (called on the
Sandbox/AsyncSandbox instance) will automatically use the same proxy.
The PR also contains a small bugfix—adding missing passing of limits and
passing these directly instead of through transport to be able to pass
the proxy parameter properly.
This change should also be compatible with the code interpreter—it uses
the client transport, which uses the passed proxy if there is any.
# Description
This PR allows to codegen without worrying about your environment and
dependencies for consistent outcomes in what code is generated from
openapi and envd protobuf spec. Will generate files for `js-sdk` and
`python-sdk`
- [x] create Docker image with all the pinned deps needed to codegen
- [x] create codegen script using this container with mapped volumes
- [x] adapt Makefiles to this new approach
- [x] adapt where we install the connect-python protobuf binary for this
to work
# Test
```sh
make codegen # this command is similar to `make generate` but w/o the hassle
Generating SDK code from openapi and envd spec
cd packages/js-sdk && pnpm generate
> e2b@1.2.1 generate /workspace/packages/js-sdk
> python ./../../spec/remove_extra_tags.py sandboxes templates && openapi-typescript ../../spec/openapi_generated.yml -x api_key --arr
ay-length --alphabetize --output src/api/schema.gen.ts
✨ openapi-typescript 7.6.1
🚀 ../../spec/openapi_generated.yml → src/api/schema.gen.ts [44.2ms]
cd packages/js-sdk && pnpm generate-envd-api
> e2b@1.2.1 generate-envd-api /workspace/packages/js-sdk
> openapi-typescript ../../spec/envd/envd.yaml -x api_key --array-length --alphabetize --output src/envd/schema.gen.ts
✨ openapi-typescript 7.6.1
🚀 ../../spec/envd/envd.yaml → src/envd/schema.gen.ts [22.7ms]
[...]
cd packages/python-sdk && make generate-api
All done! ✨🍰✨
```
---------
Co-authored-by: Jiri Sveceny <jiri.sveceny@icloud.com>
This feature allows passing custom headers in the Python and JS SDK. One
use-case for it currently is passing custom authorization (Supabase)
headers with the request.
# Description
Current solution didn't work well with in sync Python. If you're unsure
whether a file has been created, you might end up waiting for a timeout
to exit the loop.
New implementation uses polling, you can ask for events whenever you
want and it will request envd to send all events (or only new ones).
This should make it much better for users with sync Python SDK
Example of a problematic usage before and after:
## Before
```python
sbx = Sandbox()
watcher = sbx.files.watch("/home/user")
sbx.files.make_dir("test")
for event in watcher:
print(event)
# !!! if you don't exit, you would be stuck for the rest of the timeout (default 60 seconds)
break
watcher.close()
```
## After
```python
sbx = Sandbox()
watcher = sbx.files.watch("/home/user")
sbx.files.make_dir("test")
events = watcher.get_new_events()
watcher.stop()
for event in events:
print(event)
```
Even worse case was if you don't know if anything will happen:
## Before
```python
sbx = Sandbox()
watcher = sbx.files.watch("/home/user")
if random.random() > 0.5:
sbx.files.make_dir("test")
# There's 50% chance you will get stuck. The only workaround is to run in in separate thread and you kill it after a while (you aren't really sure when it's safe)
for event in watcher:
print(event)
# !!! if you don't exit, you would be stuck for the rest of the timeout (default 60 seconds)
break
watcher.close()
```
## After
```python
sbx = Sandbox()
watcher = sbx.files.watch("/home/user")
if random.random() > 0.5:
sbx.files.make_dir("test")
events = watcher.get_new_events()
watcher.stop()
for event in events:
print(event)
```