|
1 | 1 | import logging |
2 | 2 | from datetime import datetime, timezone |
| 3 | +from typing import Any |
3 | 4 | from uuid import uuid4 |
4 | 5 |
|
5 | 6 | from llama_index.core.agent.workflow.workflow_events import ( |
@@ -40,6 +41,38 @@ def __init__(self, runtime_id: str) -> None: |
40 | 41 | # tool_id -> message_id for correlating ToolCallResult with its parent AI message |
41 | 42 | self._tool_id_to_message_id: dict[str, str] = {} |
42 | 43 |
|
| 44 | + @staticmethod |
| 45 | + def map_input(input: dict[str, Any]) -> dict[str, Any]: |
| 46 | + """Map UiPath chat message format to LlamaIndex expected format. |
| 47 | +
|
| 48 | + If the input already has 'user_msg', return it unchanged. |
| 49 | + If the input has a 'messages' array (UiPath chat format), extract the |
| 50 | + text content from the first message's contentParts and map it to |
| 51 | + 'user_msg'. |
| 52 | + """ |
| 53 | + if "user_msg" in input: |
| 54 | + return input |
| 55 | + |
| 56 | + messages = input.get("messages") |
| 57 | + if not messages or not isinstance(messages, list): |
| 58 | + return input |
| 59 | + |
| 60 | + first_message = messages[0] |
| 61 | + content_parts = first_message.get("contentParts", []) |
| 62 | + |
| 63 | + text_parts = [ |
| 64 | + part["data"]["inline"] |
| 65 | + for part in content_parts |
| 66 | + if part.get("mimeType") == "text/plain" |
| 67 | + and isinstance(part.get("data"), dict) |
| 68 | + and part["data"].get("inline") |
| 69 | + ] |
| 70 | + |
| 71 | + if text_parts: |
| 72 | + return {"user_msg": " ".join(text_parts)} |
| 73 | + |
| 74 | + return input |
| 75 | + |
43 | 76 | def get_timestamp(self) -> str: |
44 | 77 | """Format current time as ISO 8601 UTC with milliseconds: 2025-01-04T10:30:00.123Z""" |
45 | 78 | return ( |
|
0 commit comments