Metadata-Version: 2.4
Name: beeply-native
Version: 0.1.1
Summary: Native customer API adapter for Beeply; no UI or staff API
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: httpx<1,>=0.27
Provides-Extra: test
Requires-Dist: pytest<10,>=8; extra == "test"
Requires-Dist: pytest-asyncio<2,>=0.24; extra == "test"
Requires-Dist: black<27,>=24; extra == "test"

# Beeply Native SDK

`beeply-native` 为 Python 3.11+ 宿主提供 Beeply 客户 API。它支持求助、消息、材料、会话续期以及邮箱绑定和恢复。宿主负责界面与安全存储。

包在 PyPI 发布后可通过 `pip install beeply-native` 安装。仓库开发者也可用 `pip install ./clients/python` 安装本地版本。

## 接入宿主后端

在 Beeply 工作台打开 **设置 → 产品与渠道 → 客户端接入**，获取产品 ID 和 HTTPS API 地址。每个 API origin 和产品组合在宿主进程中持有一个客户端实例。

```python
from beeply_native import NativeSupportClient, StateStore


def create_support(store: StateStore) -> NativeSupportClient:
    return NativeSupportClient("https://api.example.com", "your-product", store)
```

通用宿主实现 `StateStore.load()` 和 `StateStore.save(state)`。使用宿主的加密存储保护凭据、草稿和待处理操作，并在原子写入完成后让 `save` 返回。CogineWork 宿主可用 `CogineWorkStore(api_origin, product_id)` 沿用已有的 Secret Store。UI 通过宿主 API 访问公开结果，凭据留在宿主后端。

- 已有身份用 `await client.resume()` 读取会话。用户明确发起首次求助时，调用 `await client.create_guest()`。
- 通过 `prepare_request(text)` 保存提交意图，再调用 `await client.send_operation(operation_id)`。网络结果不明时用 `await client.operation(operation_id)` 查询原操作。
- 通过 `await client.conversations()` 和 `await client.messages(conversation_id)` 读取记录。宿主确定消息可见后，调用 `await client.mark_read(conversation_id, visible_cursor)`。
- 显式退出使用 `await client.logout()`。宿主关闭时用 `await client.close()` 释放 HTTP 客户端。

SDK 以 `SupportError.code` 返回服务错误，以 `StoreError` 报告本地状态错误。恢复和重试沿用原操作 ID，验证码仅在验证时提交。
