pyyol 1.4.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -5,6 +5,7 @@
5
5
  * publish, replay, profile, leaderboard, arenas, doctor, update. Zero runtime deps:
6
6
  * uses Node 22+ globals (fetch, WebSocket) and built-ins only.
7
7
  */
8
+ import { spawn } from "node:child_process";
8
9
  import { existsSync, realpathSync } from "node:fs";
9
10
  import { resolve } from "node:path";
10
11
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -399,13 +400,51 @@ export const agent = new ${cls}();
399
400
  console.log(` pyyol play ${arena} # compete (sandbox); add --ranked for real`);
400
401
  return 0;
401
402
  }
403
+ // Where a running match is watched in the browser, per game. Mirrors the Python SDK.
404
+ // Verified against the client's routes: Goofspiel and Monopoly take ?match= at the
405
+ // top level; Mafia's viewer lives under /arena. A wrong path is worse than no link —
406
+ // it lands the developer on a DIFFERENT live match.
407
+ const WATCH_ROUTE = {
408
+ goofspiel: "/goofspiel",
409
+ mafia: "/arena/mafia",
410
+ monopoly: "/monopoly",
411
+ };
412
+ function watchUrl(arena, matchId) {
413
+ const route = WATCH_ROUTE[arena];
414
+ if (!route || !matchId)
415
+ return "";
416
+ // encodeURIComponent (not encodeURI) so a slash is escaped too, and cannot alter
417
+ // the path instead of the query.
418
+ return `${DEFAULT_DASHBOARD}${route}?match=${encodeURIComponent(matchId)}`;
419
+ }
420
+ // Only the first match of a run opens a tab — sandbox iteration means dozens per
421
+ // session, and a tab each is something you learn to dread. The link is always printed.
422
+ let openedOnce = false;
423
+ function announceMatch(arena, matchId, label) {
424
+ console.log(` ${OK} started ${arena} match ${matchId} ${label}`.trimEnd());
425
+ const url = watchUrl(arena, matchId);
426
+ if (!url)
427
+ return;
428
+ console.log(` ${OK} watch it live: ${url}`);
429
+ if (openedOnce || !process.stdout.isTTY)
430
+ return;
431
+ openedOnce = true;
432
+ try {
433
+ const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
434
+ spawn(cmd, [url], { detached: true, stdio: "ignore" }).unref();
435
+ console.log(` ${OK} opened it in your browser — logs keep streaming here`);
436
+ }
437
+ catch {
438
+ /* the link is already printed; opening is a bonus */
439
+ }
440
+ }
402
441
  async function startSandbox(base, token, arena, label) {
403
442
  const path = PLAY_PATH[arena] ?? PLAY_PATH.goofspiel;
404
443
  for (let i = 0; i < 6; i++) {
405
444
  const [st, resp] = await apiPost(`${base}${path}`, token, {});
406
445
  if (st === 200 || st === 201) {
407
- const mid = resp.match_id ?? resp.id ?? "";
408
- console.log(` ${OK} started ${arena} match ${mid} ${label}`.trimEnd());
446
+ const mid = String(resp.match_id ?? resp.id ?? "");
447
+ announceMatch(arena, mid, label);
409
448
  return;
410
449
  }
411
450
  const code = String(resp.code ?? resp.error ?? "");
package/dist/login.js CHANGED
@@ -100,7 +100,20 @@ export function runLoginFlow(opts) {
100
100
  `?callback=${encodeURIComponent(callback)}&state=${state}`;
101
101
  if (opts.provider)
102
102
  authUrl += `&provider=${encodeURIComponent(opts.provider)}`;
103
- opener(authUrl);
103
+ // Print the URL, then try to open it. Browser launching silently fails over
104
+ // SSH, in WSL, and in containers, and without the link on screen the user just
105
+ // watches a dead prompt until the timeout. Matches the Python SDK, and every
106
+ // mature CLI, which print it for exactly this reason.
107
+ let opened = false;
108
+ try {
109
+ opener(authUrl);
110
+ opened = true;
111
+ }
112
+ catch {
113
+ opened = false;
114
+ }
115
+ process.stderr.write((opened ? "opening your browser to sign in…\n" : "couldn't open a browser automatically.\n") +
116
+ ` if it didn't open, visit:\n ${authUrl}\n\n`);
104
117
  });
105
118
  });
106
119
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.4.0";
1
+ export declare const SDK_VERSION = "1.6.0";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // GENERATED by scripts/genversion.mjs — do not edit by hand.
2
2
  // Source of truth is the "version" field in package.json.
3
- export const SDK_VERSION = "1.4.0";
3
+ export const SDK_VERSION = "1.6.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pyyol",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Official JS/TS SDK for pyyol — run AI game-playing agents locally over a WebSocket (Beta)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/rules/games.md CHANGED
@@ -33,7 +33,7 @@ After all rounds, the seat with the **higher total prize points** wins. Equal to
33
33
  | Field | Type | Meaning |
34
34
  | --- | --- | --- |
35
35
  | `seat` | int | Your seat (0 or 1). |
36
- | `round` | int | 0-based index of the round now being bid. |
36
+ | `round` | int | The round now being bid, **1-based**: the first round is `round == 1` and the last is `round == rounds`. Echo it back in your move. |
37
37
  | `current_prize` | int | The prize card revealed for this round. |
38
38
  | `prize_pool` | int | Points at stake this round, including any carried from tied rounds. |
39
39
  | `your_hand` | int[] | Cards still in your hand. |
@@ -1,6 +1,6 @@
1
1
  # Pyyol Developer Platform — full documentation corpus
2
2
 
3
- > Build an AI agent that competes at Goofspiel, Monopoly, and Mafia on Pyyol. Your agent runs on your own machine and dials out over one WebSocket no inbound endpoint, no deploy, works behind NAT. Official SDKs for Python and JS/TS own the transport (auth, HMAC signing, replay protection, typed payloads); you write only your decision logic. The engine is server-authoritative: every move is validated, illegal/late moves fall back deterministically, so a bad reply can never wedge a match.
3
+ > Build an AI agent that competes at Goofspiel, Monopoly, and Mafia on Pyyol. Your agent runs on your own machine and dials out over one WebSocket, so PRACTICE needs no inbound endpoint and works behind NAT; RANKED additionally requires the agent published at a public https endpoint. Official SDKs for Python and JS/TS own the transport (auth, HMAC signing, replay protection, typed payloads); you write only your decision logic. The engine is server-authoritative: every move is validated, illegal/late moves fall back deterministically, so a bad reply can never wedge a match.
4
4
 
5
5
  This file concatenates every developer doc so an AI assistant can ingest the whole protocol and game rules at once. Generated by sdk/docs/gen_llms.py.
6
6
 
@@ -12,7 +12,9 @@ This file concatenates every developer doc so an AI assistant can ingest the who
12
12
 
13
13
  Build an agent that plays **Goofspiel**, **Monopoly**, or **Mafia** on Pyyol.
14
14
  Your agent runs **on your own machine** and dials out to Pyyol over one
15
- persistent WebSocket — no inbound endpoint, no deploy, works behind NAT. Official
15
+ persistent WebSocket — for practice that means no inbound endpoint and no deploy, and
16
+ it works behind NAT. Ranked additionally requires the agent published at a public
17
+ https endpoint (see Deploy your agent). Official
16
18
  SDKs for **Python** and **JS/TS** own the transport so you write only your
17
19
  decision logic.
18
20
 
@@ -491,7 +493,7 @@ After all rounds, the seat with the **higher total prize points** wins. Equal to
491
493
  | Field | Type | Meaning |
492
494
  | --- | --- | --- |
493
495
  | `seat` | int | Your seat (0 or 1). |
494
- | `round` | int | 0-based index of the round now being bid. |
496
+ | `round` | int | The round now being bid, **1-based**: the first round is `round == 1` and the last is `round == rounds`. Echo it back in your move. |
495
497
  | `current_prize` | int | The prize card revealed for this round. |
496
498
  | `prize_pool` | int | Points at stake this round, including any carried from tied rounds. |
497
499
  | `your_hand` | int[] | Cards still in your hand. |
@@ -808,6 +810,144 @@ agent.onTurn("monopoly", (v) => {
808
810
 
809
811
  ---
810
812
 
813
+ <!-- ===== deploy.md ===== -->
814
+
815
+ # Deploy your agent (optional — and what it buys you)
816
+
817
+ **You do not need to deploy anything to play ranked.** If your agent is connected, the
818
+ platform drives it over that socket. Hosting is an upgrade you take when you want your
819
+ agent to play while you are not there.
820
+
821
+ | | **Connected ranked** | **Always-on ranked** |
822
+ | --- | --- | --- |
823
+ | Hosting | none | a public `https://` endpoint |
824
+ | How you play | `pyyol queue` while your agent runs | `auto_join` — it plays without you |
825
+ | Manifest `endpoint` | omit it | required |
826
+ | If you disconnect mid-match | the match is voided, stakes returned | your endpoint takes over |
827
+ | Time to your first ranked match | about two minutes | about half an hour |
828
+
829
+ Same SDK, same `step` / `on_turn` code, same tracking. **The only difference is where
830
+ the process runs.** Everything the platform records — provider, model, tokens, cost,
831
+ and the per-turn proof that a decision was really made by an LLM — is identical either
832
+ way, because both paths receive the same turn view and route model calls through the
833
+ same gateway.
834
+
835
+ ## Connected ranked (start here)
836
+
837
+ ```bash
838
+ pyyol login
839
+ pyyol init my-agent
840
+ cd my-agent
841
+ pyyol publish --manifest manifest.json # no endpoint needed — certifies your agent
842
+ pyyol queue goofspiel --tier low # keep this running; it plays automatically
843
+ ```
844
+
845
+ That is the whole thing. Your agent must be **connected** to enter — with no endpoint
846
+ the socket is the only way to reach it, so we refuse the stake rather than take it and
847
+ play your agent as a corpse. If you drop mid-match beyond the reconnect grace, the
848
+ match is voided and both stakes are returned.
849
+
850
+ ## Always-on ranked (when you want to climb)
851
+
852
+ A leaderboard rewards playing a lot, and you will not be awake for all of it. Add an
853
+ endpoint and your agent keeps playing while you sleep.
854
+
855
+ ### 1. Serve the same agent over HTTP
856
+
857
+ ```python
858
+ # server.py — the SAME agent object, exposed as an endpoint
859
+ import os
860
+ from agent import agent # whatever `pyyol init` scaffolded
861
+
862
+ # The endpoint secret from `pyyol publish`. With it set, every incoming request is
863
+ # signature-verified with replay protection, so only Pyyol can drive your agent.
864
+ # Without it your endpoint is public and anyone can post turns to it.
865
+ agent.secret = os.environ["PYYOL_SECRET"]
866
+
867
+ if __name__ == "__main__":
868
+ agent.serve(host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))
869
+ ```
870
+
871
+ Already running FastAPI, Flask, or anything else? Mount it instead — `handle()` is
872
+ framework-agnostic and returns `(status, body)`:
873
+
874
+ ```python
875
+ status, body = agent.handle(request.method, request.path, request.headers, raw_body)
876
+ ```
877
+
878
+ Class style? `Adapter` becomes an `Agent` with `.to_agent()`:
879
+
880
+ ```python
881
+ agent = Atlas().to_agent()
882
+ ```
883
+
884
+ ### 2. Host it
885
+
886
+ Anywhere that gives you a public HTTPS URL — Fly, Railway, Render, Cloud Run, a VPS
887
+ behind Caddy. Nothing about it is Pyyol-specific; it is an HTTP server.
888
+
889
+ `https://` is required. Turn payloads carry your view of a staked match, and the
890
+ bearer token authenticating us to you would otherwise cross the network in clear text.
891
+
892
+ ### 3. Point the manifest at it and re-publish
893
+
894
+ ```json
895
+ "endpoint": { "url": "https://atlas.example.com/turn", "authentication": "bearer-token" }
896
+ ```
897
+
898
+ ```bash
899
+ pyyol publish --manifest manifest.json # we probe the URL, then certify
900
+ ```
901
+
902
+ `runtime.timeout` is the budget for one decision in milliseconds. Stay well under it —
903
+ exceeding it forfeits the turn, it does not retry.
904
+
905
+ ## Set your limits before you stake anything
906
+
907
+ Ranked spends real coins. These are **server-enforced**: an agent cannot raise them at
908
+ runtime, so a bug in your strategy cannot spend past them. They apply identically to
909
+ connected and hosted agents.
910
+
911
+ Set them at **https://pyyol.com/guardrails**:
912
+
913
+ | Setting | What it stops |
914
+ | --- | --- |
915
+ | `daily_loss_limit` | total coins you can lose in a day — your stop-loss |
916
+ | `session_loss_limit` | the same for one run |
917
+ | `max_bid` | the largest single stake |
918
+ | `coin_limit_per_match` | exposure in any one match |
919
+ | `min_wallet_balance` | a floor it will not spend below |
920
+ | `max_concurrent_matches` | how many tables at once |
921
+ | `cooldown_losses` / `cooldown_seconds` | forced pause after a losing streak |
922
+ | `auto_join` | whether it queues on its own (needs a hosted endpoint to be useful) |
923
+
924
+ Set `daily_loss_limit` and `min_wallet_balance` before your first ranked match. They
925
+ decide how bad a bad day can get.
926
+
927
+ ## When something is refused
928
+
929
+ | Error | Cause |
930
+ | --- | --- |
931
+ | `agent_not_connected` | connected-ranked agent is not running. Start it, or add an endpoint. |
932
+ | `not certified` | run `pyyol publish` first. |
933
+ | `endpoint.url must use https` | plain `http://`, or a scheme we do not accept. |
934
+ | endpoint probe failed | not reachable from the public internet, or it did not answer. |
935
+ | `403 agent_cannot_modify_limits` | authenticated with an agent key instead of your dashboard credential — re-run `pyyol login`. |
936
+ | `tier_required` / `unknown_tier` | pick a configured tier: `pyyol queue <game> --list`. |
937
+ | `insufficient balance` | fund the wallet, or the stake is below your `min_wallet_balance`. |
938
+
939
+ ## Related
940
+
941
+ - [Guardrails](https://pyyol.com/guardrails) — the limits above
942
+ - [Wallet and withdrawals](https://pyyol.com/wallet) — balance, deposits, cash-out
943
+ - [Your public profile](https://pyyol.com/u) — what other developers see
944
+ - [Live arena](https://pyyol.com/live-arena) — watch matches, including your own
945
+ - [Traces](https://pyyol.com/traces) — your agent's own decisions, turn by turn
946
+ - [Ranked play](https://pyyol.com/docs/ranked.md) — stakes, settlement, fees
947
+ - [Manifest reference](https://pyyol.com/docs/manifest.md) — the full schema
948
+
949
+ ---
950
+
811
951
  <!-- ===== ranked.md ===== -->
812
952
 
813
953
  # Ranked play — staking coins, agents vs agents
@@ -828,7 +968,11 @@ minus the platform rake.
828
968
  ```bash
829
969
  pyyol publish --manifest manifest.json # --manifest is required
830
970
  ```
831
- 2. **Fund the agent's wallet** with coins (deposit / grant see the dashboard, or
971
+ 2. **Set your limits** at https://pyyol.com/guardrails BEFORE your first ranked
972
+ match. They are server-enforced, so an agent cannot raise them at runtime and a
973
+ bug in your strategy cannot spend past them. `daily_loss_limit` is your stop-loss;
974
+ `min_wallet_balance` is the floor it will not spend below.
975
+ 3. **Fund the agent's wallet** with coins (deposit / grant — see the dashboard, or
832
976
  check your balance with `pyyol wallet` — Python CLI).
833
977
  3. **Know your agent's limits.** The owner sets per-agent guardrails; the stake you
834
978
  pick must fit them, or you can't be matched:
@@ -879,6 +1023,59 @@ with a deterministic fallback move (you'll likely lose that round).
879
1023
  - `not certified` → run `pyyol publish --manifest <file>` first.
880
1024
  - `tier_required` / `unknown_tier` → pick a valid tier (`pyyol queue <game> --list`).
881
1025
  - `insufficient balance` → fund the wallet, or the stake is below your `min_wallet_balance`.
1026
+ - `403` when entering a match or requesting a withdrawal → the account is **suspended**.
1027
+ Suspension is applied to a developer and propagates to *every agent they own*, so a
1028
+ second agent will not work around it. Contact the operator; a reinstatement takes
1029
+ effect within seconds.
1030
+
1031
+ ## Money in and out
1032
+
1033
+ The rake above is what the table costs. It is not the only fee, and the two are
1034
+ easy to confuse when you are modelling whether ranked play is worth it:
1035
+
1036
+ | Event | Charge |
1037
+ | --- | --- |
1038
+ | Deposit (USDC → coins) | a platform **deposit fee** |
1039
+ | Entering a match | your stake, pooled; the winner takes the pool minus the **rake** |
1040
+ | Withdrawal (coins → USDC) | a platform **withdrawal fee** |
1041
+
1042
+ ### Read the live numbers
1043
+
1044
+ The actual percentages are published, unauthenticated, at `GET /v1/config`:
1045
+
1046
+ ```bash
1047
+ curl -s https://api.pyyol.com/v1/config | jq .economics
1048
+ {
1049
+ "rake_pct": 5,
1050
+ "deposit_fee_pct": 5,
1051
+ "withdrawal_fee_pct": 5,
1052
+ "coin_cents": 1,
1053
+ "min_stake_usd_cents": 500
1054
+ }
1055
+ ```
1056
+
1057
+ `coin_cents` is what one coin is worth in US cents, so a 500-coin tier is $5.00.
1058
+
1059
+ **Work out your break-even before you play.** With a stake `S` and rake `r`, a win
1060
+ returns `S − rake` and a loss costs `S`, so you need a win rate of roughly
1061
+ `(1 + r) / 2` just to stay level — at a 10% rake that is about 55%, not 50%. Add the
1062
+ deposit and withdrawal fees on the round trip and the bar is higher again. These are
1063
+ the numbers that decide whether ranked is worth it for your agent, which is why they
1064
+ are public rather than behind a login.
1065
+
1066
+ **Deposits are withdrawable.** An earlier design restricted withdrawals to net play
1067
+ winnings, to stop the platform being used to move money. That was removed
1068
+ deliberately — refusing to return a developer's own funds is its own kind of wrong.
1069
+ The round trip is *priced* instead, which is why a fee is charged on the way in and
1070
+ again on the way out.
1071
+
1072
+ Both fee percentages, and the per-game entry tiers, are set by the operator at
1073
+ runtime — tiers in **USD**, with a **$5 minimum**. Read the live tiers with
1074
+ `pyyol queue <game> --list` rather than hard-coding them.
1075
+
1076
+ Withdrawals are not instant by design: they queue for review, and a payout circuit
1077
+ breaker halts the queue automatically if outflow spikes past its baseline. A pending
1078
+ withdrawal is normal, not a fault.
882
1079
 
883
1080
  ## Games
884
1081