Metadata-Version: 2.4
Name: magic-campus-im
Version: 0.1.0
Summary: Magic Campus channel communication SDK
License-Expression: AGPL-3.0-or-later
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: httpx<1,>=0.27
Requires-Dist: protobuf<7,>=6.32.0
Requires-Dist: websocket-client<2,>=1.8.0
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: build>=1; extra == "dev"
Requires-Dist: twine>=6; extra == "dev"

# magic-campus-im

Channel-only communication SDK. It has no CLI, business clients, group-management
methods or public history/synchronization API. HTTP is retained for IM credentials,
profiles, media upload and channel reactions. It does not depend on either business
distribution.

```python
from magiccampus_im import MagicCampusWSConfig, MagicCampusWSSDK

sdk = MagicCampusWSSDK(
    MagicCampusWSConfig(apiurl="https://campus.example", apikey="...", data_dir="./channel-state"),
    on_recv_new_message=handle_message,
    on_recv_offline_new_message=handle_recovered_message,
)
sdk.login()
sdk.start()
# sdk.send_text("hello", recv_id="...")
# sdk.add_message_reaction(...), sdk.delete_message_reaction(...)
# sdk.logout() closes connection and state storage
```

## Receive recovery

A new installation establishes a current receive baseline, without pulling old
history. `auto_sync_on_connect=False` skips previously missed messages on startup;
set it to true to resume existing checkpoints after a process restart or controlled
handoff. `auto_sync_on_reconnect=True` recovers gaps after a connection interruption.
These switches control internal recovery only; there is no public `sync_once`.

Recovery pages are delivered through `on_recv_offline_new_message`. Live pushes are
buffered during recovery and deduplicated against recovered messages. A live push
ahead of the snapshot cannot advance the checkpoint over a gap. The startup
baseline is established once per connection, so retrying cannot skip later messages.
Each successful callback atomically records its message ID and receive cursor;
a failed callback leaves that message unacknowledged. Acknowledged sequences are
not replayed after the bounded ID cache is evicted.

Errors are reported through `on_error` and recovery retries use the configured
backoff/attempt limit. A failed conversation does not prevent healthy conversations
from recovering or receiving live messages. Server minimum-sequence and confirmed
range boundaries are honored when supplied. Unavailable sequences are reported as
recovery gaps; only server-confirmed progress is skipped. An absent/unconfirmed
range remains pending rather than silently advancing its cursor. Stop wakes pending
requests, and workers/sockets from an old connection cannot commit into a new one.

`channel-progress_<user>.db` stores only checkpoints, initialization state and a
bounded set of message IDs (10,000). It contains no searchable chat bodies. State
belongs to one user/environment/platform data directory. Its metadata binds the
endpoint/user/platform context and rejects a mismatched context; token rotation
keeps the same context. Do not share a directory between unrelated instances. Callbacks must return successfully to record
receipt. This is not an acknowledgment that an Agent finished processing a message.

The implementation uses the existing OpenIM protocol. Real server retention and
notification behavior still require staging validation before online migration.
