Skip to content
Draft
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: 0 additions & 2 deletions claude-agent-sdk/listeners/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

from .app_home_opened import handle_app_home_opened
from .app_mentioned import handle_app_mentioned
from .assistant_thread_started import handle_assistant_thread_started
from .message import handle_message


def register(app: AsyncApp):
app.event("app_home_opened")(handle_app_home_opened)
app.event("app_mention")(handle_app_mentioned)
app.event("assistant_thread_started")(handle_assistant_thread_started)
app.event("message")(handle_message)
27 changes: 24 additions & 3 deletions claude-agent-sdk/listeners/events/app_home_opened.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,33 @@

from listeners.views.app_home_builder import build_app_home_view

SUGGESTED_PROMPTS = [
{"title": "Write a Message", "message": "Help me draft a message to my team"},
{"title": "Summarize", "message": "Can you help me summarize something?"},
{"title": "Brainstorm", "message": "I need help brainstorming ideas"},
]


async def handle_app_home_opened(
client: AsyncWebClient, context: AsyncBoltContext, logger: Logger
client: AsyncWebClient, event: dict, context: AsyncBoltContext, logger: Logger
):
"""Publish the App Home view when a user opens the app's Home tab."""
"""Handle app_home_opened events.

Under agent_view, this event fires for both the Home tab and the Messages
tab (the agent DM). Branch on ``event["tab"]``:
* ``"messages"`` -- pin suggested prompts to the top of the DM.
* ``"home"`` -- publish the App Home Block Kit view.
"""
try:
if event.get("tab") == "messages":
await client.assistant_threads_setSuggestedPrompts(
channel_id=event["channel"],
title="How can I help you today?",
prompts=SUGGESTED_PROMPTS,
)
# TODO(agent-dm-messages-tab): handle app_context_changed once Bolt supports it
return

user_id = context.user_id
install_url = None
is_connected = False
Expand All @@ -27,4 +48,4 @@ async def handle_app_home_opened(
view = build_app_home_view(install_url=install_url, is_connected=is_connected)
await client.views_publish(user_id=user_id, view=view)
except Exception as e:
logger.exception(f"Failed to publish App Home: {e}")
logger.exception(f"Failed to handle app_home_opened: {e}")
24 changes: 0 additions & 24 deletions claude-agent-sdk/listeners/events/assistant_thread_started.py

This file was deleted.

5 changes: 2 additions & 3 deletions claude-agent-sdk/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"name": "Starter Agent - Claude SDK"
},
"features": {
"assistant_view": {
"assistant_description": "Hi, I am an agent built using Bolt for Python. I am here to help you out!",
"agent_view": {
"agent_description": "Hi, I am an agent built using Bolt for Python. I am here to help you out!",
"suggested_prompts": []
},
"app_home": {
Expand Down Expand Up @@ -63,7 +63,6 @@
"bot_events": [
"app_home_opened",
"app_mention",
"assistant_thread_started",
"message.channels",
"message.groups",
"message.im"
Expand Down
21 changes: 20 additions & 1 deletion claude-agent-sdk/tests/test_app_home_opened.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ class TestAppHomeOpened:
def setup_method(self):
self.fake_client = Mock(AsyncWebClient)
self.fake_client.views_publish = AsyncMock()
self.fake_client.assistant_threads_setSuggestedPrompts = AsyncMock()
self.fake_context = Mock(AsyncBoltContext)
self.fake_context.user_id = "U123"

@pytest.mark.asyncio
async def test_publishes_home_view(self):
async def test_publishes_home_view_when_tab_is_home(self):
await handle_app_home_opened(
client=self.fake_client,
event={"tab": "home", "channel": "D123"},
context=self.fake_context,
logger=test_logger,
)
Expand All @@ -29,13 +31,30 @@ async def test_publishes_home_view(self):
kwargs = self.fake_client.views_publish.call_args.kwargs
assert kwargs["user_id"] == "U123"
assert kwargs["view"]["type"] == "home"
self.fake_client.assistant_threads_setSuggestedPrompts.assert_not_called()

@pytest.mark.asyncio
async def test_sets_suggested_prompts_when_tab_is_messages(self):
await handle_app_home_opened(
client=self.fake_client,
event={"tab": "messages", "channel": "D123"},
context=self.fake_context,
logger=test_logger,
)

self.fake_client.assistant_threads_setSuggestedPrompts.assert_called_once()
kwargs = self.fake_client.assistant_threads_setSuggestedPrompts.call_args.kwargs
assert kwargs["channel_id"] == "D123"
assert isinstance(kwargs["prompts"], list)
self.fake_client.views_publish.assert_not_called()

@pytest.mark.asyncio
async def test_views_publish_exception(self, caplog):
self.fake_client.views_publish.side_effect = Exception("test exception")

await handle_app_home_opened(
client=self.fake_client,
event={"tab": "home", "channel": "D123"},
context=self.fake_context,
logger=test_logger,
)
Expand Down
2 changes: 0 additions & 2 deletions openai-agents-sdk/listeners/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

from .app_home_opened import handle_app_home_opened
from .app_mentioned import handle_app_mentioned
from .assistant_thread_started import handle_assistant_thread_started
from .message import handle_message


def register(app: App):
app.event("app_home_opened")(handle_app_home_opened)
app.event("app_mention")(handle_app_mentioned)
app.event("assistant_thread_started")(handle_assistant_thread_started)
app.event("message")(handle_message)
29 changes: 26 additions & 3 deletions openai-agents-sdk/listeners/events/app_home_opened.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,33 @@

from listeners.views.app_home_builder import build_app_home_view

SUGGESTED_PROMPTS = [
{"title": "Write a Message", "message": "Help me draft a message to my team"},
{"title": "Summarize", "message": "Can you help me summarize something?"},
{"title": "Brainstorm", "message": "I need help brainstorming ideas"},
]

def handle_app_home_opened(client: WebClient, context: BoltContext, logger: Logger):
"""Publish the App Home view when a user opens the app's Home tab."""

def handle_app_home_opened(
client: WebClient, event: dict, context: BoltContext, logger: Logger
):
"""Handle app_home_opened events.

Under agent_view, this event fires for both the Home tab and the Messages
tab (the agent DM). Branch on ``event["tab"]``:
* ``"messages"`` -- pin suggested prompts to the top of the DM.
* ``"home"`` -- publish the App Home Block Kit view.
"""
try:
if event.get("tab") == "messages":
client.assistant_threads_setSuggestedPrompts(
channel_id=event["channel"],
title="How can I help you today?",
prompts=SUGGESTED_PROMPTS,
)
# TODO(agent-dm-messages-tab): handle app_context_changed once Bolt supports it
return

user_id = context.user_id
install_url = None
is_connected = False
Expand All @@ -25,4 +48,4 @@ def handle_app_home_opened(client: WebClient, context: BoltContext, logger: Logg
view = build_app_home_view(install_url=install_url, is_connected=is_connected)
client.views_publish(user_id=user_id, view=view)
except Exception as e:
logger.exception(f"Failed to publish App Home: {e}")
logger.exception(f"Failed to handle app_home_opened: {e}")
22 changes: 0 additions & 22 deletions openai-agents-sdk/listeners/events/assistant_thread_started.py

This file was deleted.

5 changes: 2 additions & 3 deletions openai-agents-sdk/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"name": "Starter Agent - OpenAI SDK"
},
"features": {
"assistant_view": {
"assistant_description": "Hi, I am an agent built using Bolt for Python. I am here to help you out!",
"agent_view": {
"agent_description": "Hi, I am an agent built using Bolt for Python. I am here to help you out!",
"suggested_prompts": []
},
"app_home": {
Expand Down Expand Up @@ -63,7 +63,6 @@
"bot_events": [
"app_home_opened",
"app_mention",
"assistant_thread_started",
"message.channels",
"message.groups",
"message.im"
Expand Down
19 changes: 18 additions & 1 deletion openai-agents-sdk/tests/test_app_home_opened.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ def setup_method(self):
self.fake_context = Mock(BoltContext)
self.fake_context.user_id = "U123"

def test_publishes_home_view(self):
def test_publishes_home_view_when_tab_is_home(self):
handle_app_home_opened(
client=self.fake_client,
event={"tab": "home", "channel": "D123"},
context=self.fake_context,
logger=test_logger,
)
Expand All @@ -26,12 +27,28 @@ def test_publishes_home_view(self):
kwargs = self.fake_client.views_publish.call_args.kwargs
assert kwargs["user_id"] == "U123"
assert kwargs["view"]["type"] == "home"
self.fake_client.assistant_threads_setSuggestedPrompts.assert_not_called()

def test_sets_suggested_prompts_when_tab_is_messages(self):
handle_app_home_opened(
client=self.fake_client,
event={"tab": "messages", "channel": "D123"},
context=self.fake_context,
logger=test_logger,
)

self.fake_client.assistant_threads_setSuggestedPrompts.assert_called_once()
kwargs = self.fake_client.assistant_threads_setSuggestedPrompts.call_args.kwargs
assert kwargs["channel_id"] == "D123"
assert isinstance(kwargs["prompts"], list)
self.fake_client.views_publish.assert_not_called()

def test_views_publish_exception(self, caplog):
self.fake_client.views_publish.side_effect = Exception("test exception")

handle_app_home_opened(
client=self.fake_client,
event={"tab": "home", "channel": "D123"},
context=self.fake_context,
logger=test_logger,
)
Expand Down
2 changes: 0 additions & 2 deletions pydantic-ai/listeners/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

from .app_home_opened import handle_app_home_opened
from .app_mentioned import handle_app_mentioned
from .assistant_thread_started import handle_assistant_thread_started
from .message import handle_message


def register(app: App):
app.event("app_home_opened")(handle_app_home_opened)
app.event("app_mention")(handle_app_mentioned)
app.event("assistant_thread_started")(handle_assistant_thread_started)
app.event("message")(handle_message)
29 changes: 26 additions & 3 deletions pydantic-ai/listeners/events/app_home_opened.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,33 @@

from listeners.views.app_home_builder import build_app_home_view

SUGGESTED_PROMPTS = [
{"title": "Write a Message", "message": "Help me draft a message to my team"},
{"title": "Summarize", "message": "Can you help me summarize something?"},
{"title": "Brainstorm", "message": "I need help brainstorming ideas"},
]

def handle_app_home_opened(client: WebClient, context: BoltContext, logger: Logger):
"""Publish the App Home view when a user opens the app's Home tab."""

def handle_app_home_opened(
client: WebClient, event: dict, context: BoltContext, logger: Logger
):
"""Handle app_home_opened events.

Under agent_view, this event fires for both the Home tab and the Messages
tab (the agent DM). Branch on ``event["tab"]``:
* ``"messages"`` -- pin suggested prompts to the top of the DM.
* ``"home"`` -- publish the App Home Block Kit view.
"""
try:
if event.get("tab") == "messages":
client.assistant_threads_setSuggestedPrompts(
channel_id=event["channel"],
title="How can I help you today?",
prompts=SUGGESTED_PROMPTS,
)
# TODO(agent-dm-messages-tab): handle app_context_changed once Bolt supports it
return

user_id = context.user_id
install_url = None
is_connected = False
Expand All @@ -25,4 +48,4 @@ def handle_app_home_opened(client: WebClient, context: BoltContext, logger: Logg
view = build_app_home_view(install_url=install_url, is_connected=is_connected)
client.views_publish(user_id=user_id, view=view)
except Exception as e:
logger.exception(f"Failed to publish App Home: {e}")
logger.exception(f"Failed to handle app_home_opened: {e}")
22 changes: 0 additions & 22 deletions pydantic-ai/listeners/events/assistant_thread_started.py

This file was deleted.

5 changes: 2 additions & 3 deletions pydantic-ai/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"name": "Starter Agent - Pydantic AI"
},
"features": {
"assistant_view": {
"assistant_description": "Hi, I am an agent built using Bolt for Python. I am here to help you out!",
"agent_view": {
"agent_description": "Hi, I am an agent built using Bolt for Python. I am here to help you out!",
"suggested_prompts": []
},
"app_home": {
Expand Down Expand Up @@ -63,7 +63,6 @@
"bot_events": [
"app_home_opened",
"app_mention",
"assistant_thread_started",
"message.channels",
"message.groups",
"message.im"
Expand Down
Loading