-
Notifications
You must be signed in to change notification settings - Fork 2
feat(sdk): add axons to OO SDK #766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """Axon resource class for asynchronous operations.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing_extensions import Unpack, override | ||
|
|
||
| from ._types import ( | ||
| BaseRequestOptions, | ||
| SDKAxonPublishParams, | ||
| ) | ||
| from .._client import AsyncRunloop | ||
| from .._streaming import AsyncStream | ||
| from ..types.axon_view import AxonView | ||
| from ..types.axon_event_view import AxonEventView | ||
| from ..types.publish_result_view import PublishResultView | ||
|
|
||
|
|
||
| class AsyncAxon: | ||
| """[Beta] Wrapper around asynchronous axon operations. | ||
|
|
||
| Axons are event communication channels that support publishing events | ||
| and subscribing to event streams via server-sent events (SSE). | ||
| Obtain instances via ``runloop.axon.create()`` or ``runloop.axon.from_id()``. | ||
|
|
||
| Example: | ||
| >>> runloop = AsyncRunloopSDK() | ||
| >>> axon = await runloop.axon.create() | ||
| >>> await axon.publish(event_type="task_done", origin="AGENT_EVENT", payload="{}", source="my-agent") | ||
| """ | ||
|
|
||
| def __init__(self, client: AsyncRunloop, axon_id: str) -> None: | ||
| self._client = client | ||
| self._id = axon_id | ||
|
|
||
| @override | ||
| def __repr__(self) -> str: | ||
| return f"<AsyncAxon id={self._id!r}>" | ||
|
|
||
| @property | ||
| def id(self) -> str: | ||
| return self._id | ||
|
|
||
| async def get_info(self, **options: Unpack[BaseRequestOptions]) -> AxonView: | ||
| """[Beta] Retrieve the latest axon information.""" | ||
| return await self._client.axons.retrieve(self._id, **options) | ||
|
|
||
| async def publish(self, **params: Unpack[SDKAxonPublishParams]) -> PublishResultView: | ||
| """[Beta] Publish an event to this axon.""" | ||
| return await self._client.axons.publish(self._id, **params) | ||
|
|
||
| async def subscribe_sse(self, **options: Unpack[BaseRequestOptions]) -> AsyncStream[AxonEventView]: | ||
| """[Beta] Subscribe to this axon's event stream via SSE.""" | ||
| return await self._client.axons.subscribe_sse(self._id, **options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """Axon resource class for synchronous operations.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing_extensions import Unpack, override | ||
|
|
||
| from ._types import ( | ||
| BaseRequestOptions, | ||
| SDKAxonPublishParams, | ||
| ) | ||
| from .._client import Runloop | ||
| from .._streaming import Stream | ||
| from ..types.axon_view import AxonView | ||
| from ..types.axon_event_view import AxonEventView | ||
| from ..types.publish_result_view import PublishResultView | ||
|
|
||
|
|
||
| class Axon: | ||
| """[Beta] Wrapper around synchronous axon operations. | ||
|
|
||
| Axons are event communication channels that support publishing events | ||
| and subscribing to event streams via server-sent events (SSE). | ||
| Obtain instances via ``runloop.axon.create()`` or ``runloop.axon.from_id()``. | ||
|
|
||
| Example: | ||
| >>> runloop = RunloopSDK() | ||
| >>> axon = runloop.axon.create() | ||
| >>> axon.publish(event_type="task_done", origin="AGENT_EVENT", payload="{}", source="my-agent") | ||
| """ | ||
|
|
||
| def __init__(self, client: Runloop, axon_id: str) -> None: | ||
| self._client = client | ||
| self._id = axon_id | ||
|
|
||
| @override | ||
| def __repr__(self) -> str: | ||
| return f"<Axon id={self._id!r}>" | ||
|
|
||
| @property | ||
| def id(self) -> str: | ||
| return self._id | ||
|
|
||
| def get_info(self, **options: Unpack[BaseRequestOptions]) -> AxonView: | ||
| """[Beta] Retrieve the latest axon information.""" | ||
| return self._client.axons.retrieve(self._id, **options) | ||
|
|
||
| def publish(self, **params: Unpack[SDKAxonPublishParams]) -> PublishResultView: | ||
| """[Beta] Publish an event to this axon.""" | ||
| return self._client.axons.publish(self._id, **params) | ||
|
|
||
| def subscribe_sse(self, **options: Unpack[BaseRequestOptions]) -> Stream[AxonEventView]: | ||
| """[Beta] Subscribe to this axon's event stream via SSE.""" | ||
| return self._client.axons.subscribe_sse(self._id, **options) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
show how to listen on it too