Include handler_agent_id in command websocket events#48
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for tracking agent identifiers in websocket events by introducing handler_agent_id for command invocations and agent_id for message payloads. The changes ensure parity between TypeScript and Rust SDK implementations while maintaining backward compatibility where appropriate.
Changes:
- Added required
handler_agent_idfield tocommand.invokedevent schemas and transformations - Added optional
agent_idfield to message payload types in Rust SDK (MessageEventPayload, MessageUpdatedPayload, ThreadReplyPayload, DmEventPayload) - Added comprehensive parity tests in Rust SDK to validate the new fields
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/types/src/events.ts | Added required handler_agent_id field to CommandInvokedEventSchema |
| packages/server/src/engine/wsTransform.ts | Updated command.invoked transformation to include handler_agent_id |
| packages/server/src/engine/tests/wsTransform.test.ts | Updated test to verify handler_agent_id is correctly transformed |
| packages/sdk-rust/src/types.rs | Added optional agent_id to message payloads and required handler_agent_id to CommandInvokedEvent |
| packages/sdk-rust/tests/parity.rs | Added tests for agent_id deserialization and handler_agent_id requirement |
| packages/sdk-rust/Cargo.toml | Bumped version to 0.2.4 |
| packages/sdk-rust/CHANGELOG.md | Added changelog entry for 0.2.4 release |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| } | ||
|
|
||
| #[test] |
There was a problem hiding this comment.
The test verifies that agent_id can be deserialized when present, but doesn't verify that it's truly optional. Consider adding a test case that deserializes a message.created event without the agent_id field to ensure the serde(default) annotation works correctly and the field is genuinely optional.
| #[test] | |
| #[test] | |
| fn ws_message_created_allows_missing_agent_id() { | |
| let event = serde_json::from_value::<WsEvent>(json!({ | |
| "type": "message.created", | |
| "channel": "general", | |
| "message": { | |
| "id": "m_2", | |
| "agent_name": "bob", | |
| "text": "hi", | |
| "attachments": [] | |
| } | |
| })) | |
| .expect("failed to parse ws message.created without agent_id"); | |
| match event { | |
| WsEvent::MessageCreated(msg) => { | |
| assert_eq!(msg.message.agent_id.as_deref(), None); | |
| assert_eq!(msg.message.agent_name, "bob"); | |
| } | |
| other => panic!("unexpected event variant: {other:?}"), | |
| } | |
| } | |
| #[test] |
|
Preview deployed!
This preview shares the staging database and will be cleaned up when the PR is merged or closed. Run E2E testsnpm run e2e -- https://pr48-api.relaycast.dev --ciOpen observer dashboard |
Changed
agent_idparsing for websocket message payloads.handler_agent_idparsing forcommand.invokedwebsocket events.agent_idandhandler_agent_idfields.