Skip to content
Closed
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 examples/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
22 changes: 21 additions & 1 deletion packages/narada-pyodide/src/narada/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
22 changes: 12 additions & 10 deletions packages/narada/src/narada/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -63,6 +63,8 @@

_ResponseModel = TypeVar("_ResponseModel", bound=BaseModel)

_AttachmentVariableInput: TypeAlias = dict[str, File]


class _PresignedPost(BaseModel):
url: str
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down