chipzen_bot/lib.rs
1//! # chipzen-bot
2//!
3//! Build, test, and deploy poker bots for the [Chipzen](https://chipzen.ai)
4//! competition platform.
5//!
6//! Implement the [`Bot`] trait, return [`Action`]s from [`Bot::decide`],
7//! call [`run_bot`] — the SDK handles the WebSocket connection,
8//! the two-layer protocol handshake, ping/pong, `request_id` echoing,
9//! `action_rejected` retries, and reconnect.
10//!
11//! ```no_run
12//! use chipzen_bot::{Bot, Action, GameState, run_bot, RunBotOptions};
13//!
14//! struct MyBot;
15//!
16//! #[async_trait::async_trait]
17//! impl Bot for MyBot {
18//! fn decide(&mut self, state: &GameState) -> Action {
19//! if state.valid_actions.iter().any(|a| a == "check") {
20//! Action::Check
21//! } else {
22//! Action::Fold
23//! }
24//! }
25//! }
26//!
27//! # async fn _doctest() -> Result<(), chipzen_bot::Error> {
28//! let url = std::env::var("CHIPZEN_WS_URL").unwrap();
29//! let _match_end = run_bot(&url, MyBot, RunBotOptions::default()).await?;
30//! # Ok(()) }
31//! ```
32//!
33//! To run a bot on the **external-API remote-play** path (your machine,
34//! the platform matches and dispatches you), use
35//! [`run_external_bot`] with a `cz_extbot_` token — see its docs.
36//!
37//! See the [`docs/protocol/`] docs in the chipzen-sdk repo for the
38//! full two-layer protocol specification, and the
39//! [IP-PROTECTION.md](https://github.com/chipzen-ai/chipzen-sdk/blob/main/packages/rust/IP-PROTECTION.md)
40//! for what the starter Dockerfile does to your release binary.
41//!
42//! [`docs/protocol/`]: https://github.com/chipzen-ai/chipzen-sdk/tree/main/docs/protocol
43
44mod bot;
45mod client;
46mod config;
47mod conformance;
48mod connect;
49mod error;
50mod external;
51mod models;
52mod retry;
53
54pub use bot::Bot;
55pub use client::{
56 default_user_agent, run_bot, MessageReader, MessageWriter, RunBotOptions, SessionContext,
57 SUPPORTED_PROTOCOL_VERSIONS,
58};
59pub use config::{
60 discover_config_path, load_chipzen_config, resolve_token, resolve_url, ChipzenConfig,
61 CONFIG_FILENAME, SECTION_NAME,
62};
63pub use conformance::{
64 run_conformance_checks, ConformanceCheck, RunConformanceOptions,
65 Severity as ConformanceSeverity, SCENARIO_NAMES,
66};
67pub use connect::{connect_to_chipzen, ConnectionConfig, EnvName, CHIPZEN_ENV_VAR, ENV_NAMES};
68pub use error::Error;
69pub use external::{
70 bot_token_subprotocols, resolve_gateway_url, run_external_bot, run_external_cli, MatchResult,
71 RunExternalArgs, RunExternalOptions, BOT_TOKEN_SUBPROTOCOL,
72};
73pub use models::{
74 parse_card, parse_game_state, Action, ActionHistoryEntry, ActionKind, Card, GameState,
75};
76pub use retry::{default_retry_policy, RetryPolicy};
77
78// Internals used by the conformance harness + external-API tests. Not part
79// of the supported public API; the underscore prefix is a convention copied
80// from the Python and JavaScript SDKs.
81#[doc(hidden)]
82pub use client::{_extract_match_id, _run_session, _safe_fallback_action};
83#[doc(hidden)]
84pub use external::{_set_lobby_recv_timeout_ms, run_external_with_transport, LobbyTransport};