Skip to content

Commit 09259eb

Browse files
committed
add type annotations for agent create sources
1 parent 6cb2aa1 commit 09259eb

2 files changed

Lines changed: 26 additions & 40 deletions

File tree

src/runloop_api_client/sdk/async_.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from ..lib.context_loader import TarFilter, build_directory_tar
3939
from .async_storage_object import AsyncStorageObject
4040
from ..types.object_create_params import ContentType
41+
from ..types.shared_params.agent_source import Git, Npm, Pip, Object
4142

4243

4344
class AsyncDevboxOps:
@@ -622,18 +623,16 @@ async def create_from_npm(
622623
"Cannot specify 'source' when using create_from_npm(); source is automatically set to npm configuration"
623624
)
624625

625-
npm_config: dict = {"package_name": package_name}
626+
npm_config: Npm = {"package_name": package_name}
626627
if npm_version is not None:
627628
npm_config["npm_version"] = npm_version
628629
if registry_url is not None:
629630
npm_config["registry_url"] = registry_url
630631
if agent_setup is not None:
631632
npm_config["agent_setup"] = agent_setup
632633

633-
return await self.create(
634-
source={"type": "npm", "npm": npm_config},
635-
**params,
636-
)
634+
params["source"] = {"type": "npm", "npm": npm_config}
635+
return await self.create(**params)
637636

638637
async def create_from_pip(
639638
self,
@@ -664,18 +663,16 @@ async def create_from_pip(
664663
"Cannot specify 'source' when using create_from_pip(); source is automatically set to pip configuration"
665664
)
666665

667-
pip_config: dict = {"package_name": package_name}
666+
pip_config: Pip = {"package_name": package_name}
668667
if pip_version is not None:
669668
pip_config["pip_version"] = pip_version
670669
if registry_url is not None:
671670
pip_config["registry_url"] = registry_url
672671
if agent_setup is not None:
673672
pip_config["agent_setup"] = agent_setup
674673

675-
return await self.create(
676-
source={"type": "pip", "pip": pip_config},
677-
**params,
678-
)
674+
params["source"] = {"type": "pip", "pip": pip_config}
675+
return await self.create(**params)
679676

680677
async def create_from_git(
681678
self,
@@ -703,16 +700,14 @@ async def create_from_git(
703700
"Cannot specify 'source' when using create_from_git(); source is automatically set to git configuration"
704701
)
705702

706-
git_config: dict = {"repository": repository}
703+
git_config: Git = {"repository": repository}
707704
if ref is not None:
708705
git_config["ref"] = ref
709706
if agent_setup is not None:
710707
git_config["agent_setup"] = agent_setup
711708

712-
return await self.create(
713-
source={"type": "git", "git": git_config},
714-
**params,
715-
)
709+
params["source"] = {"type": "git", "git": git_config}
710+
return await self.create(**params)
716711

717712
async def create_from_object(
718713
self,
@@ -737,14 +732,12 @@ async def create_from_object(
737732
"Cannot specify 'source' when using create_from_object(); source is automatically set to object configuration"
738733
)
739734

740-
object_config: dict = {"object_id": object_id}
735+
object_config: Object = {"object_id": object_id}
741736
if agent_setup is not None:
742737
object_config["agent_setup"] = agent_setup
743738

744-
return await self.create(
745-
source={"type": "object", "object": object_config},
746-
**params,
747-
)
739+
params["source"] = {"type": "object", "object": object_config}
740+
return await self.create(**params)
748741

749742
def from_id(self, agent_id: str) -> AsyncAgent:
750743
"""Attach to an existing agent by ID.

src/runloop_api_client/sdk/sync.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from .storage_object import StorageObject
3838
from ..lib.context_loader import TarFilter, build_directory_tar
3939
from ..types.object_create_params import ContentType
40+
from ..types.shared_params.agent_source import Git, Npm, Pip, Object
4041

4142

4243
class DevboxOps:
@@ -622,18 +623,16 @@ def create_from_npm(
622623
"Cannot specify 'source' when using create_from_npm(); source is automatically set to npm configuration"
623624
)
624625

625-
npm_config: dict = {"package_name": package_name}
626+
npm_config: Npm = {"package_name": package_name}
626627
if npm_version is not None:
627628
npm_config["npm_version"] = npm_version
628629
if registry_url is not None:
629630
npm_config["registry_url"] = registry_url
630631
if agent_setup is not None:
631632
npm_config["agent_setup"] = agent_setup
632633

633-
return self.create(
634-
source={"type": "npm", "npm": npm_config},
635-
**params,
636-
)
634+
params["source"] = {"type": "npm", "npm": npm_config}
635+
return self.create(**params)
637636

638637
def create_from_pip(
639638
self,
@@ -669,18 +668,16 @@ def create_from_pip(
669668
"Cannot specify 'source' when using create_from_pip(); source is automatically set to pip configuration"
670669
)
671670

672-
pip_config: dict = {"package_name": package_name}
671+
pip_config: Pip = {"package_name": package_name}
673672
if pip_version is not None:
674673
pip_config["pip_version"] = pip_version
675674
if registry_url is not None:
676675
pip_config["registry_url"] = registry_url
677676
if agent_setup is not None:
678677
pip_config["agent_setup"] = agent_setup
679678

680-
return self.create(
681-
source={"type": "pip", "pip": pip_config},
682-
**params,
683-
)
679+
params["source"] = {"type": "pip", "pip": pip_config}
680+
return self.create(**params)
684681

685682
def create_from_git(
686683
self,
@@ -716,16 +713,14 @@ def create_from_git(
716713
"Cannot specify 'source' when using create_from_git(); source is automatically set to git configuration"
717714
)
718715

719-
git_config: dict = {"repository": repository}
716+
git_config: Git = {"repository": repository}
720717
if ref is not None:
721718
git_config["ref"] = ref
722719
if agent_setup is not None:
723720
git_config["agent_setup"] = agent_setup
724721

725-
return self.create(
726-
source={"type": "git", "git": git_config},
727-
**params,
728-
)
722+
params["source"] = {"type": "git", "git": git_config}
723+
return self.create(**params)
729724

730725
def create_from_object(
731726
self,
@@ -758,14 +753,12 @@ def create_from_object(
758753
"Cannot specify 'source' when using create_from_object(); source is automatically set to object configuration"
759754
)
760755

761-
object_config: dict = {"object_id": object_id}
756+
object_config: Object = {"object_id": object_id}
762757
if agent_setup is not None:
763758
object_config["agent_setup"] = agent_setup
764759

765-
return self.create(
766-
source={"type": "object", "object": object_config},
767-
**params,
768-
)
760+
params["source"] = {"type": "object", "object": object_config}
761+
return self.create(**params)
769762

770763
def from_id(self, agent_id: str) -> Agent:
771764
"""Attach to an existing agent by ID.

0 commit comments

Comments
 (0)