@whitesands/agent-player 0.0.0-stage → 0.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 46faef6: Publish the agent player SDK: typed actions, turn results, reconnect, and an offline testing entry.
8
+
9
+ ## 0.1.0
10
+
11
+ First public SDK release.
12
+
13
+ - `AgentServer` reads `WSI_PLATFORM_KEY` and `WSI_PLATFORM_URL`.
14
+ - Player classes can declare zod argument schemas and descriptions.
15
+ - `turn()` returns the action, arguments, result, attempt count, and token usage.
16
+ - Typed errors, event listeners, turn timeouts, and `await using`.
17
+ - Reconnect with session resume, heartbeat, and a protocol version handshake.
18
+ - `@whitesands/agent-player/testing` runs the production loop offline.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 White Sands Interactive
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,118 @@
1
- # Temporary Holding Version
1
+ # @whitesands/agent-player
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Start a remote game agent from a player class. You call `start` and `turn`. The SDK owns the MCP server. The model stays on the platform, so the game never sees the model key.
4
+
5
+ ```bash
6
+ npm install @whitesands/agent-player
7
+ export WSI_PLATFORM_KEY=pk_...
8
+ export WSI_PLATFORM_URL=wss://your-platform.example
9
+ ```
10
+
11
+ ```ts
12
+ import { AgentServer } from "@whitesands/agent-player";
13
+
14
+ const agents = new AgentServer();
15
+ const ada = await agents.start(new Villager(world, "Ada"), {
16
+ goal: "Collect all the wood",
17
+ });
18
+
19
+ const result = await ada.turn();
20
+ // { action: "move", args: { dx: 1, dy: 0 }, result, attempts: 1, usage }
21
+ ```
22
+
23
+ `new AgentServer()` reads `WSI_PLATFORM_KEY` and `WSI_PLATFORM_URL`. Until a hosted URL is the default, set `WSI_PLATFORM_URL` (it falls back to `ws://127.0.0.1:8787`).
24
+
25
+ ## Player class
26
+
27
+ - `see()` is the state tool. It must be public and return JSON-safe data.
28
+ - Every other public method is an action. The model calls one per turn.
29
+ - Methods whose names start with `_`, and the constructor, are not tools.
30
+ - Throw to reject an action. The platform asks the model once more, then `turn()` rejects with `TurnFailedError`.
31
+
32
+ Optional static metadata adds descriptions and argument types. Undeclared public methods are still tools. Without metadata, arguments accept any JSON value.
33
+
34
+ ```ts
35
+ import { z } from "zod";
36
+
37
+ class Villager {
38
+ static agent = {
39
+ description: "A villager who gathers wood",
40
+ actions: {
41
+ move: {
42
+ description: "Step by dx, dy",
43
+ args: { dx: z.number().int(), dy: z.number().int() },
44
+ },
45
+ chop: { description: "Chop the tree on your tile" },
46
+ },
47
+ };
48
+ }
49
+ ```
50
+
51
+ Use the same Zod major version the SDK depends on (`zod@3`).
52
+
53
+ ## Turns
54
+
55
+ `turn()` does not choose the action. It unblocks that session's `wait`, then resolves when the platform has called one action (or retried once).
56
+
57
+ ```ts
58
+ const result = await ada.turn({ timeoutMs: 30_000, signal });
59
+ ```
60
+
61
+ | Field | Meaning |
62
+ | --- | --- |
63
+ | `action` | Tool the model called |
64
+ | `args` | Arguments it passed |
65
+ | `result` | What your method returned |
66
+ | `attempts` | `1`, or `2` when the first call failed |
67
+ | `usage` | Prompt and completion tokens for that turn |
68
+
69
+ ## Errors
70
+
71
+ | Error | When |
72
+ | --- | --- |
73
+ | `PlatformAuthError` | The platform key was rejected |
74
+ | `ProtocolVersionError` | The SDK and platform disagree on the protocol |
75
+ | `TurnFailedError` | Both the action and the retry failed. `error.attempts` lists both |
76
+ | `TurnTimeoutError` | The platform did not finish within `timeoutMs` (default 60s) |
77
+ | `ConnectionLostError` | The socket dropped and could not be resumed |
78
+
79
+ The SDK reconnects with backoff and resumes sessions for 30 seconds. Subscribe with `agents.on(listener)` or `handle.on(listener)` for `action`, `retry`, `turnFailed`, `disconnected`, and `reconnected`.
80
+
81
+ ```ts
82
+ await using agents = new AgentServer();
83
+ ```
84
+
85
+ `await using` calls `close()`, which stops every session. The platform process keeps running.
86
+
87
+ ## Testing without a network
88
+
89
+ ```ts
90
+ import { AgentServer } from "@whitesands/agent-player";
91
+ import { createTestPlatform } from "@whitesands/agent-player/testing";
92
+
93
+ const agents = new AgentServer({
94
+ inline: createTestPlatform([
95
+ { name: "move", arguments: { dx: 1, dy: 0 } },
96
+ ]),
97
+ });
98
+ ```
99
+
100
+ `createTestPlatform` runs the same wait / act / retry loop in memory. No key, no socket.
101
+
102
+ ## What runs where
103
+
104
+ | | Game process | Platform |
105
+ | --- | --- | --- |
106
+ | World and player methods | yes | no |
107
+ | MCP tools (`see`, actions, `wait`) | yes | calls them |
108
+ | Whose turn it is | `turn()` | no |
109
+ | Which action to take | no | the model |
110
+ | Model API key | no | yes |
111
+
112
+ ## API reference
113
+
114
+ ```bash
115
+ npm run docs -w @whitesands/agent-player
116
+ ```
117
+
118
+ TypeDoc writes HTML to `packages/agent-player/docs`.