CLI API client. The ZIP deployment methods live here as well as in newer crewai-core versions so editable CLI installs still work when an older crewai-core is present in the runtime environment.
| 14 | |
| 15 | |
| 16 | class PlusAPI(_CorePlusAPI): |
| 17 | """CLI API client. |
| 18 | |
| 19 | The ZIP deployment methods live here as well as in newer crewai-core |
| 20 | versions so editable CLI installs still work when an older crewai-core is |
| 21 | present in the runtime environment. |
| 22 | """ |
| 23 | |
| 24 | def _make_multipart_request( |
| 25 | self, |
| 26 | method: HttpMethod, |
| 27 | endpoint: str, |
| 28 | *, |
| 29 | zip_file_path: str | Path, |
| 30 | data: dict[str, str] | None = None, |
| 31 | timeout: float | None = None, |
| 32 | verify: bool = True, |
| 33 | ) -> httpx.Response: |
| 34 | """Send an authenticated multipart request containing a project ZIP.""" |
| 35 | url = urljoin(self.base_url, endpoint) |
| 36 | headers = dict(cast(dict[str, str], self.headers)) |
| 37 | headers.pop("Content-Type", None) |
| 38 | path = Path(zip_file_path) |
| 39 | request_kwargs: dict[str, Any] = {"headers": headers} |
| 40 | if data is not None: |
| 41 | request_kwargs["data"] = data |
| 42 | if timeout is not None: |
| 43 | request_kwargs["timeout"] = timeout |
| 44 | |
| 45 | with ( |
| 46 | path.open("rb") as file_handle, |
| 47 | httpx.Client(trust_env=False, verify=verify) as client, |
| 48 | ): |
| 49 | files = { |
| 50 | "zip_file": (path.name, file_handle, "application/zip"), |
| 51 | } |
| 52 | return client.request(method, url, files=files, **request_kwargs) |
| 53 | |
| 54 | def create_crew_from_zip( |
| 55 | self, |
| 56 | zip_file_path: str | Path, |
| 57 | *, |
| 58 | name: str | None = None, |
| 59 | env: dict[str, str] | None = None, |
| 60 | ) -> httpx.Response: |
| 61 | """Create a crew deployment from a local project ZIP archive.""" |
| 62 | data: dict[str, str] = {} |
| 63 | if name: |
| 64 | data["name"] = name |
| 65 | if env: |
| 66 | data.update({f"env[{key}]": value for key, value in env.items()}) |
| 67 | return self._make_multipart_request( |
| 68 | "POST", |
| 69 | f"{self.CREWS_RESOURCE}/zip", |
| 70 | zip_file_path=zip_file_path, |
| 71 | data=data or None, |
| 72 | timeout=300, |
| 73 | ) |
no outgoing calls
searching dependent graphs…