diff --git a/examples/attachment.py b/examples/attachment.py index 8568cdd..5cadcde 100644 --- a/examples/attachment.py +++ b/examples/attachment.py @@ -17,7 +17,7 @@ async def main() -> None: response = await window.agent( prompt="Summarize the attached file.", agent=Agent.GENERALIST, - attachment=file, + attachments={"file": file}, ) print("Response:", response.model_dump_json(indent=2)) diff --git a/packages/narada-pyodide/src/narada/window.py b/packages/narada-pyodide/src/narada/window.py index 95aa4ba..b23bec1 100644 --- a/packages/narada-pyodide/src/narada/window.py +++ b/packages/narada-pyodide/src/narada/window.py @@ -4,7 +4,17 @@ import time from abc import ABC from http import HTTPStatus -from typing import IO, TYPE_CHECKING, Any, Literal, Optional, TypeVar, cast, overload +from typing import ( + IO, + TYPE_CHECKING, + Any, + Literal, + Optional, + TypeAlias, + TypeVar, + cast, + overload, +) from js import AbortController, setTimeout # type: ignore from narada_core.actions.models import ( @@ -78,6 +88,7 @@ async def _narada_get_id_token() -> str: ... _StructuredOutput = TypeVar("_StructuredOutput", bound=BaseModel) _ResponseModel = TypeVar("_ResponseModel", bound=BaseModel) +_AttachmentVariableInput: TypeAlias = dict[str, File] class BaseBrowserWindow(ABC): @@ -133,6 +144,7 @@ async def dispatch_request( previous_request_id: str | None = None, chat_history: list[RemoteDispatchChatHistoryItem] | None = None, additional_context: dict[str, str] | None = None, + attachments: _AttachmentVariableInput | None = None, time_zone: str = "America/Los_Angeles", user_resource_credentials: UserResourceCredentials | None = None, mcp_servers: list[McpServer] | None = None, @@ -155,6 +167,7 @@ async def dispatch_request( previous_request_id: str | None = None, chat_history: list[RemoteDispatchChatHistoryItem] | None = None, additional_context: dict[str, str] | None = None, + attachments: _AttachmentVariableInput | None = None, time_zone: str = "America/Los_Angeles", user_resource_credentials: UserResourceCredentials | None = None, mcp_servers: list[McpServer] | None = None, @@ -176,6 +189,7 @@ async def dispatch_request( previous_request_id: str | None = None, chat_history: list[RemoteDispatchChatHistoryItem] | None = None, additional_context: dict[str, str] | None = None, + attachments: _AttachmentVariableInput | None = None, time_zone: str = "America/Los_Angeles", user_resource_credentials: UserResourceCredentials | None = None, mcp_servers: list[McpServer] | None = None, @@ -226,6 +240,8 @@ async def dispatch_request( body["chatHistory"] = chat_history if additional_context is not None: body["additionalContext"] = additional_context + if attachments is not None and len(attachments) > 0: + body["attachmentVariables"] = attachments if user_resource_credentials is not None: body["userResourceCredentials"] = user_resource_credentials if mcp_servers is not None: @@ -315,6 +331,7 @@ async def agent( clear_chat: bool | None = None, generate_gif: bool | None = None, output_schema: None = None, + attachments: _AttachmentVariableInput | None = None, time_zone: str = "America/Los_Angeles", mcp_servers: list[McpServer] | None = None, variables: dict[str, str] | None = None, @@ -330,6 +347,7 @@ async def agent( clear_chat: bool | None = None, generate_gif: bool | None = None, output_schema: type[_StructuredOutput], + attachments: _AttachmentVariableInput | None = None, time_zone: str = "America/Los_Angeles", mcp_servers: list[McpServer] | None = None, variables: dict[str, str] | None = None, @@ -344,6 +362,7 @@ async def agent( clear_chat: bool | None = None, generate_gif: bool | None = None, output_schema: type[BaseModel] | None = None, + attachments: _AttachmentVariableInput | None = None, time_zone: str = "America/Los_Angeles", mcp_servers: list[McpServer] | None = None, variables: dict[str, str] | None = None, @@ -356,6 +375,7 @@ async def agent( clear_chat=clear_chat, generate_gif=generate_gif, output_schema=output_schema, + attachments=attachments, time_zone=time_zone, mcp_servers=mcp_servers, variables=variables, diff --git a/packages/narada/src/narada/window.py b/packages/narada/src/narada/window.py index 1919839..d1adfb4 100644 --- a/packages/narada/src/narada/window.py +++ b/packages/narada/src/narada/window.py @@ -5,7 +5,7 @@ from abc import ABC from http import HTTPStatus from pathlib import Path -from typing import IO, Any, TypeVar, overload, override +from typing import IO, Any, TypeAlias, TypeVar, overload, override import aiohttp from narada_core.actions.models import ( @@ -63,6 +63,8 @@ _ResponseModel = TypeVar("_ResponseModel", bound=BaseModel) +_AttachmentVariableInput: TypeAlias = dict[str, File] + class _PresignedPost(BaseModel): url: str @@ -134,7 +136,7 @@ async def dispatch_request( previous_request_id: str | None = None, chat_history: list[RemoteDispatchChatHistoryItem] | None = None, additional_context: dict[str, str] | None = None, - attachment: File | None = None, + attachments: _AttachmentVariableInput | None = None, time_zone: str = "America/Los_Angeles", user_resource_credentials: UserResourceCredentials | None = None, mcp_servers: list[McpServer] | None = None, @@ -157,7 +159,7 @@ async def dispatch_request( previous_request_id: str | None = None, chat_history: list[RemoteDispatchChatHistoryItem] | None = None, additional_context: dict[str, str] | None = None, - attachment: File | None = None, + attachments: _AttachmentVariableInput | None = None, time_zone: str = "America/Los_Angeles", user_resource_credentials: UserResourceCredentials | None = None, mcp_servers: list[McpServer] | None = None, @@ -179,7 +181,7 @@ async def dispatch_request( previous_request_id: str | None = None, chat_history: list[RemoteDispatchChatHistoryItem] | None = None, additional_context: dict[str, str] | None = None, - attachment: File | None = None, + attachments: _AttachmentVariableInput | None = None, time_zone: str = "America/Los_Angeles", user_resource_credentials: UserResourceCredentials | None = None, mcp_servers: list[McpServer] | None = None, @@ -218,8 +220,8 @@ async def dispatch_request( body["chatHistory"] = chat_history if additional_context is not None: body["additionalContext"] = additional_context - if attachment is not None: - body["attachment"] = attachment + if attachments is not None and len(attachments) > 0: + body["attachmentVariables"] = attachments if user_resource_credentials is not None: body["userResourceCredentials"] = user_resource_credentials if mcp_servers is not None: @@ -289,7 +291,7 @@ async def agent( clear_chat: bool | None = None, generate_gif: bool | None = None, output_schema: None = None, - attachment: File | None = None, + attachments: _AttachmentVariableInput | None = None, time_zone: str = "America/Los_Angeles", mcp_servers: list[McpServer] | None = None, variables: dict[str, str] | None = None, @@ -305,7 +307,7 @@ async def agent( clear_chat: bool | None = None, generate_gif: bool | None = None, output_schema: type[_StructuredOutput], - attachment: File | None = None, + attachments: _AttachmentVariableInput | None = None, time_zone: str = "America/Los_Angeles", mcp_servers: list[McpServer] | None = None, variables: dict[str, str] | None = None, @@ -320,7 +322,7 @@ async def agent( clear_chat: bool | None = None, generate_gif: bool | None = None, output_schema: type[BaseModel] | None = None, - attachment: File | None = None, + attachments: _AttachmentVariableInput | None = None, time_zone: str = "America/Los_Angeles", mcp_servers: list[McpServer] | None = None, variables: dict[str, str] | None = None, @@ -333,7 +335,7 @@ async def agent( clear_chat=clear_chat, generate_gif=generate_gif, output_schema=output_schema, - attachment=attachment, + attachments=attachments, time_zone=time_zone, mcp_servers=mcp_servers, variables=variables,