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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[project]
name = "uipath-dev"
version = "0.0.1"
version = "0.0.2"
description = "UiPath Developer Console"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
dependencies = [
"uipath-runtime>=0.0.4",
"uipath-runtime>=0.0.5, <0.1.0",
"textual>=6.5.0",
"pyperclip>=1.11.0",
]
Expand Down
12 changes: 9 additions & 3 deletions src/uipath/dev/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from uipath.dev.models.messages import LogMessage, TraceMessage

from ._utils._exporter import RunContextExporter
from ._utils._logger import patch_textual_stderr
from ._utils._logger import RunContextLogHandler, patch_textual_stderr


class UiPathDeveloperConsole(App[Any]):
Expand Down Expand Up @@ -203,10 +203,16 @@ async def _execute_runtime(self, run: ExecutionRun):

run.status = "running"
run.start_time = datetime.now()

log_handler = RunContextLogHandler(
run_id=run.id,
callback=self._handle_log_message,
)
runtime = self.runtime_factory.new_runtime(entrypoint=run.entrypoint)
execution_runtime = UiPathExecutionRuntime(
delegate=runtime, trace_manager=self.trace_manager, execution_id=run.id
delegate=runtime,
trace_manager=self.trace_manager,
log_handler=log_handler,
execution_id=run.id,
)
result = await execution_runtime.execute(execution_input, execution_options)

Expand Down
19 changes: 2 additions & 17 deletions src/uipath/dev/_demo/mock_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ async def execute(

tracer = trace.get_tracer("uipath.dev.mock-runtime")

execution_id = getattr(self.context, "job_id", None) or "mock-execution"
entrypoint = getattr(self.context, "entrypoint", None) or "mock-entrypoint"
entrypoint = "mock-entrypoint"
message = str(payload.get("message", ""))
message_length = len(message)

Expand All @@ -56,7 +55,6 @@ async def execute(
attributes={
"uipath.runtime.name": "MockRuntime",
"uipath.runtime.type": "agent",
"uipath.execution.id": execution_id,
"uipath.runtime.entrypoint": entrypoint,
"uipath.input.message.length": message_length,
"uipath.input.has_message": "message" in payload,
Expand All @@ -65,19 +63,17 @@ async def execute(
logger.info(
"MockRuntime: starting execution",
extra={
"uipath.execution.id": execution_id,
"uipath.runtime.entrypoint": entrypoint,
},
)
print(f"[MockRuntime] Starting execution (execution_id={execution_id})")
print(f"[MockRuntime] Starting execution with payload={payload!r}")

# Stage 1: Initialization
with tracer.start_as_current_span(
"initialize.environment",
attributes={
"uipath.step.name": "initialize-environment",
"uipath.step.kind": "init",
"uipath.execution.id": execution_id,
},
):
logger.info("MockRuntime: initializing environment")
Expand All @@ -90,7 +86,6 @@ async def execute(
attributes={
"uipath.step.name": "validate-input",
"uipath.step.kind": "validation",
"uipath.execution.id": execution_id,
"uipath.input.has_message": "message" in payload,
},
) as validate_span:
Expand All @@ -110,7 +105,6 @@ async def execute(
attributes={
"uipath.step.name": "preprocess-data",
"uipath.step.kind": "preprocess",
"uipath.execution.id": execution_id,
"uipath.input.size.bytes": len(str(payload).encode("utf-8")),
},
):
Expand All @@ -124,7 +118,6 @@ async def execute(
attributes={
"uipath.step.name": "compute-result",
"uipath.step.kind": "compute",
"uipath.execution.id": execution_id,
},
):
logger.info("MockRuntime: compute phase started")
Expand All @@ -136,7 +129,6 @@ async def execute(
attributes={
"uipath.step.name": "compute-embeddings",
"uipath.step.kind": "compute-subtask",
"uipath.execution.id": execution_id,
},
):
logger.info("MockRuntime: computing embeddings")
Expand All @@ -149,7 +141,6 @@ async def execute(
attributes={
"uipath.step.name": "query-knowledgebase",
"uipath.step.kind": "io",
"uipath.execution.id": execution_id,
"uipath.kb.query.length": message_length,
},
):
Expand All @@ -163,7 +154,6 @@ async def execute(
attributes={
"uipath.step.name": "postprocess-results",
"uipath.step.kind": "postprocess",
"uipath.execution.id": execution_id,
},
):
logger.info("MockRuntime: post-processing results")
Expand All @@ -175,7 +165,6 @@ async def execute(
attributes={
"uipath.step.name": "generate-output",
"uipath.step.kind": "postprocess-subtask",
"uipath.execution.id": execution_id,
},
):
logger.info("MockRuntime: generating structured output")
Expand All @@ -188,7 +177,6 @@ async def execute(
attributes={
"uipath.step.name": "persist-artifacts",
"uipath.step.kind": "io",
"uipath.execution.id": execution_id,
"uipath.persistence.enabled": False,
},
):
Expand All @@ -202,7 +190,6 @@ async def execute(
attributes={
"uipath.step.name": "cleanup-resources",
"uipath.step.kind": "cleanup",
"uipath.execution.id": execution_id,
},
):
logger.info("MockRuntime: cleaning up resources")
Expand All @@ -212,7 +199,6 @@ async def execute(
result_payload = {
"result": f"Mock runtime processed: {payload.get('message', '<no message>')}",
"metadata": {
"execution_id": execution_id,
"entrypoint": entrypoint,
"message_length": message_length,
},
Expand All @@ -228,7 +214,6 @@ async def execute(
logger.info(
"MockRuntime: execution completed successfully",
extra={
"uipath.execution.id": execution_id,
"uipath.runtime.status": "success",
},
)
Expand Down
7 changes: 5 additions & 2 deletions src/uipath/dev/_utils/_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@
from datetime import datetime
from typing import Callable, Pattern

from uipath.runtime.logging import UiPathRuntimeExecutionLogHandler

from uipath.dev.models.messages import LogMessage


class RunContextLogHandler(logging.Handler):
class RunContextLogHandler(UiPathRuntimeExecutionLogHandler):
"""Custom log handler that sends logs to CLI UI."""

def __init__(
self,
run_id: str,
callback: Callable[[LogMessage], None],
):
super().__init__()
super().__init__(run_id)
self.run_id = run_id
self.callback = callback
self.setFormatter(logging.Formatter("%(message)s"))

def emit(self, record: logging.LogRecord):
"""Emit a log record to CLI UI."""
Expand Down
10 changes: 5 additions & 5 deletions uv.lock

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