Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath-runtime"
version = "0.3.4"
version = "0.4.0"
description = "Runtime abstractions and interfaces for building agents and automation scripts in the UiPath ecosystem"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
Expand Down
2 changes: 1 addition & 1 deletion src/uipath/runtime/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class UiPathRuntimeCreatorProtocol(Protocol):
"""Protocol for creating a UiPath runtime given an entrypoint."""

async def new_runtime(
self, entrypoint: str, runtime_id: str
self, entrypoint: str, runtime_id: str, **kwargs
) -> UiPathRuntimeProtocol:
"""Create a new runtime instance."""
...
Expand Down
74 changes: 74 additions & 0 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from typing import Any, AsyncGenerator

import pytest

from uipath.runtime import (
UiPathExecuteOptions,
UiPathRuntimeEvent,
UiPathRuntimeProtocol,
UiPathRuntimeResult,
UiPathRuntimeSchema,
UiPathStreamOptions,
)
from uipath.runtime.factory import UiPathRuntimeCreatorProtocol


class MockRuntime:
"""Mock runtime that implements UiPathRuntimeProtocol."""

def __init__(self, settings: dict[str, Any] | None = None) -> None:
self.settings = settings

async def execute(
self,
input: dict[str, Any] | None = None,
options: UiPathExecuteOptions | None = None,
) -> UiPathRuntimeResult:
return UiPathRuntimeResult(output={})

async def stream(
self,
input: dict[str, Any] | None = None,
options: UiPathStreamOptions | None = None,
) -> AsyncGenerator[UiPathRuntimeEvent, None]:
yield UiPathRuntimeResult(output={})

async def get_schema(self) -> UiPathRuntimeSchema:
return UiPathRuntimeSchema(
filePath="agent.json",
type="agent",
uniqueId="unique-id",
input={},
output={},
)

async def dispose(self) -> None:
pass


class CreatorWithKwargs:
"""Implementation with kwargs."""

async def new_runtime(
self, entrypoint: str, runtime_id: str, **kwargs
) -> UiPathRuntimeProtocol:
return MockRuntime(kwargs.get("settings"))


@pytest.mark.asyncio
async def test_protocol_works_with_kwargs_not_specified():
"""Test protocol works with implementation that has kwargs."""
creator: UiPathRuntimeCreatorProtocol = CreatorWithKwargs()
runtime = await creator.new_runtime("main.py", "runtime-123")
assert isinstance(runtime, MockRuntime)


@pytest.mark.asyncio
async def test_protocol_works_with_kwargs_specified():
"""Test protocol works with implementation that has kwargs."""
creator: UiPathRuntimeCreatorProtocol = CreatorWithKwargs()
runtime = await creator.new_runtime(
"main.py", "runtime-123", settings={"timeout": 30, "model": "gpt-4"}
)
assert isinstance(runtime, MockRuntime)
assert runtime.settings == {"timeout": 30, "model": "gpt-4"}
6 changes: 3 additions & 3 deletions tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async def discover_runtimes(self) -> list[UiPathRuntimeProtocol]:
return []

async def new_runtime(
self, entrypoint: str, runtime_id: str
self, entrypoint: str, runtime_id: str, **kwargs
) -> UiPathRuntimeProtocol:
return cast(UiPathRuntimeProtocol, MockRuntime(f"functions-{entrypoint}"))

Expand All @@ -85,7 +85,7 @@ async def discover_runtimes(self) -> list[UiPathRuntimeProtocol]:
return []

async def new_runtime(
self, entrypoint: str, runtime_id: str
self, entrypoint: str, runtime_id: str, **kwargs
) -> UiPathRuntimeProtocol:
return cast(UiPathRuntimeProtocol, MockRuntime(f"langgraph-{entrypoint}"))

Expand All @@ -107,7 +107,7 @@ async def discover_runtimes(self) -> list[UiPathRuntimeProtocol]:
return []

async def new_runtime(
self, entrypoint: str, runtime_id: str
self, entrypoint: str, runtime_id: str, **kwargs
) -> UiPathRuntimeProtocol:
return cast(UiPathRuntimeProtocol, MockRuntime(f"llamaindex-{entrypoint}"))

Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.