-
Notifications
You must be signed in to change notification settings - Fork 22
feat(rust-sdk): contacts parity — unblock + stats, typed responses & tests #228
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
senamakel
merged 1 commit into
tinyhumansai:main
from
senamakel:fix/rust-sdk-contacts-parity
Jul 7, 2026
+326
−15
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| //! Contact-graph types. Mirrors `sdk/typescript/src/types/contacts.ts`. | ||
| //! | ||
| //! A contact is a single mutual edge between two agents: one side sends a | ||
| //! request (`pending`), the other accepts (`accepted`). Either side may block | ||
| //! the other (`blocked`). An **accepted** contact is the prerequisite for | ||
| //! direct messaging (the relay refuses DMs between non-contacts). | ||
| //! | ||
| //! The single agent identifier on the wire is `cryptoId` (spec rule 8 dropped | ||
| //! the legacy `agentId`); we accept both via `#[serde(alias)]` and expose it as | ||
| //! `agent_id` to match the TS SDK's normalized surface. | ||
|
|
||
| #[allow(unused_imports)] | ||
| use super::*; | ||
| use serde::{Deserialize, Serialize}; // sibling types share a flat namespace, like the TS barrel | ||
|
|
||
| /// A first-level relationship as stored by the backend. There is at most one | ||
| /// `Contact` per unordered pair of agents; `requester`/`addressee` record who | ||
| /// initiated it (relevant while pending). When `status` is `blocked`, | ||
| /// `blocked_by` names the agent who blocked. | ||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct Contact { | ||
| #[serde(default)] | ||
| pub requester: String, | ||
| #[serde(default)] | ||
| pub addressee: String, | ||
| /// One of `pending` | `accepted` | `blocked`. | ||
| #[serde(default)] | ||
| pub status: String, | ||
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| pub blocked_by: Option<String>, | ||
| #[serde(default)] | ||
| pub created_at: String, | ||
| #[serde(default)] | ||
| pub updated_at: String, | ||
| } | ||
|
|
||
| /// A relationship as seen from the requesting agent's perspective. `direction` | ||
| /// is present only for pending relationships (`incoming`/`outgoing`). | ||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct ContactView { | ||
| /// The other party's cryptoId. Accepts the legacy `agentId` wire name too. | ||
| #[serde(rename = "cryptoId", alias = "agentId", default)] | ||
| pub agent_id: String, | ||
| #[serde(default)] | ||
| pub status: String, | ||
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| pub direction: Option<String>, | ||
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| pub contact: Option<Contact>, | ||
| } | ||
|
|
||
| /// Pagination parameters for contact/request listings. | ||
| #[derive(Debug, Clone, Default, Serialize, Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct ContactListParams { | ||
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| pub limit: Option<i64>, | ||
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| pub offset: Option<i64>, | ||
| } | ||
|
|
||
| /// Response listing the acting agent's accepted contacts. | ||
| #[derive(Debug, Clone, Default, Serialize, Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct ContactsResponse { | ||
| #[serde(default)] | ||
| pub contacts: Vec<ContactView>, | ||
| } | ||
|
|
||
| /// Response listing pending incoming and outgoing requests. | ||
| #[derive(Debug, Clone, Default, Serialize, Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct ContactRequestsResponse { | ||
| #[serde(default)] | ||
| pub incoming: Vec<ContactView>, | ||
| #[serde(default)] | ||
| pub outgoing: Vec<ContactView>, | ||
| } | ||
|
|
||
| /// Contact-graph counts for the acting agent. | ||
| #[derive(Debug, Clone, Default, Serialize, Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct ContactStats { | ||
| /// The acting agent's cryptoId. Accepts the legacy `agentId` wire name too. | ||
| #[serde(rename = "cryptoId", alias = "agentId", default)] | ||
| pub agent_id: String, | ||
| #[serde(default)] | ||
| pub contact_count: i64, | ||
| #[serde(default)] | ||
| pub pending_incoming: i64, | ||
| #[serde(default)] | ||
| pub pending_outgoing: i64, | ||
| } |
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.
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.
When
/contacts/{id}/statusreturns the status response shape (agentId,status, optionaldirection) exposed by the TS SDK insdk/typescript/src/types/contacts.ts:42-45and used by the test mock insdk/typescript/tests/codex-cli.test.ts:603-609, deserializing it asContactsilently dropsagentId/directionand fillsrequester/addresseewith empty defaults. Rust callers then cannot distinguish pending incoming vs outgoing (or read the returned peer), so the typed surface is lossy; add aContactStatusResponsetype and return it here.Useful? React with 👍 / 👎.