Skip to content

Commit 87b5ff3

Browse files
viambotgithub-actions[bot]
authored andcommitted
[WORKFLOW] AI update based on proto changes from commit 88b9747
1 parent 386e035 commit 87b5ff3

File tree

5 files changed

+217
-17
lines changed

5 files changed

+217
-17
lines changed

src/viam/app/app_client.py

Lines changed: 145 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -473,14 +473,95 @@ def from_proto(cls, robot_part_history_entry: RobotPartHistoryEntryPB) -> Self:
473473

474474
@property
475475
def proto(self) -> RobotPartHistoryEntryPB:
476-
return RobotPartHistoryEntryPB(
476+
return RobotPartPiecePB(
477477
part=self.part,
478478
robot=self.robot,
479479
when=datetime_to_timestamp(self.when) if self.when else None,
480480
old=self.old.proto if self.old else None,
481481
)
482482

483483

484+
class ModuleSourceType(str, Enum):
485+
"""
486+
ModuleSourceType specifies the source of the module.
487+
"""
488+
489+
MODULE_SOURCE_TYPE_UNSPECIFIED = "unspecified"
490+
"""
491+
Uninitialized source type.
492+
"""
493+
494+
MODULE_SOURCE_TYPE_LOCAL = "local"
495+
"""
496+
Module is local to the machine.
497+
"""
498+
499+
MODULE_SOURCE_TYPE_REGISTRY = "registry"
500+
"""
501+
Module is from the Viam registry.
502+
"""
503+
504+
@classmethod
505+
def from_proto(cls, source_type: "viam.proto.app.packages_pb2.ModuleSourceType.ValueType") -> "ModuleSourceType":
506+
if source_type == viam.proto.app.packages_pb2.ModuleSourceType.MODULE_SOURCE_TYPE_LOCAL:
507+
return cls.MODULE_SOURCE_TYPE_LOCAL
508+
if source_type == viam.proto.app.packages_pb2.ModuleSourceType.MODULE_SOURCE_TYPE_REGISTRY:
509+
return cls.MODULE_SOURCE_TYPE_REGISTRY
510+
return cls.MODULE_SOURCE_TYPE_UNSPECIFIED
511+
512+
def to_proto(self) -> "viam.proto.app.packages_pb2.ModuleSourceType.ValueType":
513+
if self == self.MODULE_SOURCE_TYPE_LOCAL:
514+
return viam.proto.app.packages_pb2.ModuleSourceType.MODULE_SOURCE_TYPE_LOCAL
515+
if self == self.MODULE_SOURCE_TYPE_REGISTRY:
516+
return viam.proto.app.packages_pb2.ModuleSourceType.MODULE_SOURCE_TYPE_REGISTRY
517+
return viam.proto.app.packages_pb2.ModuleSourceType.MODULE_SOURCE_TYPE_UNSPECIFIED
518+
519+
520+
class ModuleLanguage(str, Enum):
521+
"""
522+
ModuleLanguage specifies the language the module is written in.
523+
"""
524+
525+
MODULE_LANGUAGE_UNSPECIFIED = "unspecified"
526+
"""
527+
Uninitialized language.
528+
"""
529+
530+
MODULE_LANGUAGE_GO = "go"
531+
"""
532+
Module is written in Go.
533+
"""
534+
535+
MODULE_LANGUAGE_PYTHON = "python"
536+
"""
537+
Module is written in Python.
538+
"""
539+
540+
MODULE_LANGUAGE_OTHER = "other"
541+
"""
542+
Module is written in another language.
543+
"""
544+
545+
@classmethod
546+
def from_proto(cls, language: "viam.proto.app.packages_pb2.ModuleLanguage.ValueType") -> "ModuleLanguage":
547+
if language == viam.proto.app.packages_pb2.ModuleLanguage.MODULE_LANGUAGE_GO:
548+
return cls.MODULE_LANGUAGE_GO
549+
if language == viam.proto.app.packages_pb2.ModuleLanguage.MODULE_LANGUAGE_PYTHON:
550+
return cls.MODULE_LANGUAGE_PYTHON
551+
if language == viam.proto.app.packages_pb2.ModuleLanguage.MODULE_LANGUAGE_OTHER:
552+
return cls.MODULE_LANGUAGE_OTHER
553+
return cls.MODULE_LANGUAGE_UNSPECIFIED
554+
555+
def to_proto(self) -> "viam.proto.app.packages_pb2.ModuleLanguage.ValueType":
556+
if self == self.MODULE_LANGUAGE_GO:
557+
return viam.proto.app.packages_pb2.ModuleLanguage.MODULE_LANGUAGE_GO
558+
if self == self.MODULE_LANGUAGE_PYTHON:
559+
return viam.proto.app.packages_pb2.ModuleLanguage.MODULE_LANGUAGE_PYTHON
560+
if self == self.MODULE_LANGUAGE_OTHER:
561+
return viam.proto.app.packages_pb2.ModuleLanguage.MODULE_LANGUAGE_OTHER
562+
return viam.proto.app.packages_pb2.ModuleLanguage.MODULE_LANGUAGE_UNSPECIFIED
563+
564+
484565
class APIKeyAuthorization:
485566
"""A class with the necessary authorization data for creating an API key.
486567
@@ -1406,7 +1487,7 @@ async def tail_robot_part_logs(
14061487
no filter).
14071488
14081489
Returns:
1409-
_LogsStream[List[LogEntry]]: The asynchronous iterator receiving live machine part logs.
1490+
_LogsStream[List[LogEntry]]: The asynchronous iterator receiving machine part logs.
14101491
"""
14111492

14121493
async def read() -> AsyncIterator[List[LogEntry]]:
@@ -2138,6 +2219,7 @@ async def get_registry_item(self, item_id: str, include_markdown_documentation:
21382219
form `namespace:name`. For example, `Viam's csi-cam-pi module's <https://app.viam.com/module/viam/csi-cam-pi>`_ item ID
21392220
would be `viam:csi-cam-pi`. You can also use `org-id:name`. For example,
21402221
`abc01234-0123-4567-ab12-a11a00a2aa22:training-script`.
2222+
include_markdown_documentation (bool): Whether or not to include markdown documentation in the response. Defaults to False.
21412223
21422224
Returns:
21432225
RegistryItem: The registry item.
@@ -2168,20 +2250,38 @@ async def create_registry_item(self, organization_id: str, name: str, type: Pack
21682250
await self._app_client.CreateRegistryItem(request, metadata=self._metadata)
21692251

21702252
async def update_registry_item(
2171-
self, item_id: str, type: PackageType.ValueType, description: str, visibility: Visibility.ValueType
2253+
self,
2254+
item_id: str,
2255+
type: PackageType.ValueType,
2256+
description: str,
2257+
visibility: Visibility.ValueType,
2258+
module_source_type: Optional[ModuleSourceType] = None,
2259+
module_language: Optional[ModuleLanguage] = None,
21722260
) -> None:
21732261
"""Update a registry item.
21742262
21752263
::
21762264
21772265
from viam.proto.app.packages import PackageType
21782266
from viam.proto.app import Visibility
2267+
from viam.proto.app import ModuleSourceType, ModuleLanguage
21792268
2269+
# Update a module's description and visibility
21802270
await cloud.update_registry_item(
21812271
"your-namespace:your-name",
2182-
PackageType.PACKAGE_TYPE_ML_TRAINING,
2183-
"description",
2184-
Visibility.VISIBILITY_PUBLIC
2272+
PackageType.PACKAGE_TYPE_MODULE,
2273+
"A new description for my module.",
2274+
Visibility.VISIBILITY_PUBLIC,
2275+
module_source_type=ModuleSourceType.MODULE_SOURCE_TYPE_REGISTRY,
2276+
module_language=ModuleLanguage.MODULE_LANGUAGE_PYTHON
2277+
)
2278+
2279+
# Update an ML model's description and visibility
2280+
await cloud.update_registry_item(
2281+
"your-namespace:your-model",
2282+
PackageType.PACKAGE_TYPE_ML_MODEL,
2283+
"An updated description for my ML model.",
2284+
Visibility.VISIBILITY_PRIVATE
21852285
)
21862286
21872287
Args:
@@ -2190,11 +2290,25 @@ async def update_registry_item(
21902290
type (PackageType.ValueType): The type of the item in the registry.
21912291
description (str): The description of the registry item.
21922292
visibility (Visibility.ValueType): The visibility of the registry item.
2293+
module_source_type (Optional[ModuleSourceType]): The source type of the module. Only applicable if type is PACKAGE_TYPE_MODULE.
2294+
module_language (Optional[ModuleLanguage]): The language of the module. Only applicable if type is PACKAGE_TYPE_MODULE.
21932295
21942296
For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#updateregistryitem>`_.
21952297
"""
2298+
update_module_metadata = None
2299+
if type == PackageType.PACKAGE_TYPE_MODULE and (module_source_type or module_language):
2300+
update_module_metadata = UpdateModuleMetadata(
2301+
module_source_type=module_source_type.to_proto() if module_source_type else None,
2302+
module_language=module_language.to_proto() if module_language else None,
2303+
)
21962304

2197-
request = UpdateRegistryItemRequest(item_id=item_id, type=type, description=description, visibility=visibility)
2305+
request = UpdateRegistryItemRequest(
2306+
item_id=item_id,
2307+
type=type,
2308+
description=description,
2309+
visibility=visibility,
2310+
update_module_metadata=update_module_metadata,
2311+
)
21982312
await self._app_client.UpdateRegistryItem(request, metadata=self._metadata)
21992313

22002314
async def list_registry_items(
@@ -2206,30 +2320,38 @@ async def list_registry_items(
22062320
statuses: List[RegistryItemStatus.ValueType],
22072321
search_term: Optional[str] = None,
22082322
page_token: Optional[str] = None,
2323+
public_namespaces: Optional[List[str]] = None,
2324+
include_markdown_documentation: Optional[bool] = None,
2325+
module_source_types: Optional[List[ModuleSourceType]] = None,
2326+
module_languages: Optional[List[ModuleLanguage]] = None,
22092327
) -> List[RegistryItem]:
22102328
"""List the registry items in an organization.
22112329
22122330
::
22132331
22142332
from viam.proto.app.packages import PackageType
22152333
from viam.proto.app import Visibility, RegistryItemStatus
2334+
from viam.proto.app import ModuleSourceType, ModuleLanguage
22162335
2217-
# List private, published ml training scripts in your organization
2336+
# List private, published linux modules in your organization
22182337
registry_items = await cloud.list_registry_items(
22192338
organization_id="<YOUR-ORG-ID>",
2220-
types=[PackageType.PACKAGE_TYPE_ML_TRAINING],
2339+
types=[PackageType.PACKAGE_TYPE_MODULE],
22212340
visibilities=[Visibility.VISIBILITY_PRIVATE],
2222-
platforms=[""],
2223-
statuses=[RegistryItemStatus.REGISTRY_ITEM_STATUS_PUBLISHED]
2341+
platforms=["linux/amd64"],
2342+
statuses=[RegistryItemStatus.REGISTRY_ITEM_STATUS_PUBLISHED],
2343+
module_source_types=[ModuleSourceType.MODULE_SOURCE_TYPE_REGISTRY],
2344+
module_languages=[ModuleLanguage.MODULE_LANGUAGE_GO]
22242345
)
22252346
2226-
# List public, published linux modules in all organizations
2347+
# List public, published ml training scripts in all organizations
22272348
registry_items = await cloud.list_registry_items(
22282349
organization_id="",
2229-
types=[PackageType.PACKAGE_TYPE_MODULE],
2350+
types=[PackageType.PACKAGE_TYPE_ML_TRAINING],
22302351
visibilities=[Visibility.VISIBILITY_PUBLIC],
2231-
platforms=["linux/any"],
2232-
statuses=[RegistryItemStatus.REGISTRY_ITEM_STATUS_PUBLISHED]
2352+
platforms=[""],
2353+
statuses=[RegistryItemStatus.REGISTRY_ITEM_STATUS_PUBLISHED],
2354+
public_namespaces=["viam"]
22332355
)
22342356
22352357
Args:
@@ -2240,6 +2362,10 @@ async def list_registry_items(
22402362
statuses (List[RegistryItemStatus.ValueType]): The types of the items in the registry.
22412363
search_term (Optional[str]): The search term of the registry items.
22422364
page_token (Optional[str]): The page token of the registry items.
2365+
public_namespaces (Optional[List[str]]): List of public namespaces to filter by.
2366+
include_markdown_documentation (Optional[bool]): Whether or not to include markdown documentation in the response.
2367+
module_source_types (Optional[List[ModuleSourceType]]): List of module source types to filter by.
2368+
module_languages (Optional[List[ModuleLanguage]]): List of module languages to filter by.
22432369
22442370
Returns:
22452371
List[RegistryItem]: The list of registry items.
@@ -2254,6 +2380,10 @@ async def list_registry_items(
22542380
statuses=statuses,
22552381
search_term=search_term if search_term is not None else "",
22562382
page_token=page_token if page_token is not None else "",
2383+
public_namespaces=public_namespaces,
2384+
include_markdown_documentation=include_markdown_documentation,
2385+
module_source_types=[source_type.to_proto() for source_type in module_source_types] if module_source_types else None,
2386+
module_languages=[language.to_proto() for language in module_languages] if module_languages else None,
22572387
)
22582388
response: ListRegistryItemsResponse = await self._app_client.ListRegistryItems(request, metadata=self._metadata)
22592389
return list(response.items)

src/viam/app/provisioning_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from viam import logging
66
from viam.proto.provisioning import (
7+
APIKey,
78
CloudConfig,
89
GetNetworkListRequest,
910
GetNetworkListResponse,

tests/mocks/services.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@
128128
MarkPartForRestartRequest,
129129
MarkPartForRestartResponse,
130130
Module,
131+
ModuleLanguagePB,
132+
ModuleSourceTypePB,
131133
NewRobotPartRequest,
132134
NewRobotPartResponse,
133135
NewRobotRequest,
@@ -181,6 +183,7 @@
181183
UpdateRobotResponse,
182184
UploadModuleFileRequest,
183185
UploadModuleFileResponse,
186+
UpdateModuleMetadata,
184187
)
185188
from viam.proto.app.billing import (
186189
CreateInvoiceAndChargeImmediatelyRequest,
@@ -328,6 +331,7 @@
328331
Transform,
329332
)
330333
from viam.proto.provisioning import (
334+
APIKey,
331335
GetNetworkListRequest,
332336
GetNetworkListResponse,
333337
GetSmartMachineStatusRequest,
@@ -813,6 +817,7 @@ def __init__(
813817
):
814818
self.smart_machine_status = smart_machine_status
815819
self.network_info = network_info
820+
self.cloud_config: Optional[CloudConfig] = None
816821

817822
async def GetNetworkList(self, stream: Stream[GetNetworkListRequest, GetNetworkListResponse]) -> None:
818823
request = await stream.recv_message()
@@ -1388,6 +1393,11 @@ def __init__(
13881393
api_keys_with_authorizations: List[APIKeyWithAuthorizations],
13891394
items: List[RegistryItem],
13901395
package_type: PackageType.ValueType,
1396+
public_namespaces: Optional[List[str]] = None,
1397+
include_markdown_documentation: Optional[bool] = None,
1398+
module_source_types: Optional[List[ModuleSourceTypePB.ValueType]] = None,
1399+
module_languages: Optional[List[ModuleLanguagePB.ValueType]] = None,
1400+
update_module_metadata: Optional[UpdateModuleMetadata] = None,
13911401
):
13921402
self.organizations = organizations
13931403
self.location = location
@@ -1411,6 +1421,11 @@ def __init__(
14111421
self.api_keys_with_authorizations = api_keys_with_authorizations
14121422
self.items = items
14131423
self.package_type = package_type
1424+
self.public_namespaces = public_namespaces
1425+
self.include_markdown_documentation = include_markdown_documentation
1426+
self.module_source_types = module_source_types
1427+
self.module_languages = module_languages
1428+
self.update_module_metadata = update_module_metadata
14141429
self.send_email_invite = False
14151430
self.organization_metadata = {}
14161431
self.location_metadata = {}
@@ -1857,6 +1872,10 @@ async def GetOrganizationsWithAccessToLocation(
18571872
async def ListRegistryItems(self, stream: Stream[ListRegistryItemsRequest, ListRegistryItemsResponse]) -> None:
18581873
request = await stream.recv_message()
18591874
assert request is not None
1875+
self.public_namespaces = request.public_namespaces
1876+
self.include_markdown_documentation = request.include_markdown_documentation
1877+
self.module_source_types = request.module_source_types
1878+
self.module_languages = request.module_languages
18601879
await stream.send_message(ListRegistryItemsResponse(items=self.items))
18611880

18621881
async def UpdateRegistryItem(self, stream: Stream[UpdateRegistryItemRequest, UpdateRegistryItemResponse]) -> None:
@@ -1866,6 +1885,7 @@ async def UpdateRegistryItem(self, stream: Stream[UpdateRegistryItemRequest, Upd
18661885
self.package_type = request.type
18671886
self.description = request.description
18681887
self.visibility = request.visibility
1888+
self.update_module_metadata = request.update_module_metadata
18691889
await stream.send_message(UpdateRegistryItemResponse())
18701890

18711891
async def DeleteRegistryItem(self, stream: Stream[DeleteRegistryItemRequest, DeleteRegistryItemResponse]) -> None:

0 commit comments

Comments
 (0)