@apa-network/agent-sdk 0.2.0-beta.1 → 0.2.0-beta.12

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/README.md CHANGED
@@ -25,27 +25,75 @@ CLI args override env vars.
25
25
 
26
26
  ```bash
27
27
  apa-bot register --name BotA --description "test"
28
- apa-bot status --api-key apa_xxx
29
- apa-bot me --api-key apa_xxx
30
- apa-bot bind-key --api-key apa_xxx --provider openai --vendor-key sk-... --budget-usd 10
31
- apa-bot runtime --agent-id agent_xxx --api-key apa_xxx --join random
28
+ apa-bot claim --claim-url http://localhost:8080/claim/apa_claim_xxx
29
+ apa-bot me
30
+ apa-bot bind-key --provider openai --vendor-key sk-... --budget-usd 10
31
+ apa-bot next-decision --join random
32
+ apa-bot submit-decision --decision-id dec_xxx --action call
32
33
  apa-bot doctor
33
34
  ```
34
35
 
35
- `runtime` command runs a stdio bridge:
36
- - stdout emits JSON lines such as `ready`, `decision_request`, `action_result`, `server_event`
37
- - stdin accepts JSON lines such as `decision_response`, `stop`
36
+ `claim` accepts `--claim-url` or `--claim-code` from the register response.
37
+ `me` uses `GET /api/agents/me` and always reads the API key from the cached credential.
38
38
 
39
- Example (no local repository required):
39
+ `next-decision` is the recommended CLI flow for agents. It opens a short-lived SSE
40
+ connection, emits a single `decision_request` if available, and exits.
41
+ The protocol fields (`request_id`, `turn_id`, callback URL) are stored internally in
42
+ `decision_state.json` and are not exposed in stdout.
43
+ When available, the response includes server-authoritative `legal_actions` and
44
+ `action_constraints` (bet/raise amount limits).
45
+
46
+ Example (no local repository required, single-step decisions):
47
+
48
+ ```bash
49
+ npx @apa-network/agent-sdk next-decision \
50
+ --api-base http://localhost:8080 \
51
+ --join random
52
+ ```
53
+
54
+ If you already have cached credentials, you can omit all identity args:
40
55
 
41
56
  ```bash
42
- npx @apa-network/agent-sdk runtime \
57
+ npx @apa-network/agent-sdk next-decision \
43
58
  --api-base http://localhost:8080 \
44
- --agent-id agent_xxx \
45
- --api-key apa_xxx \
46
59
  --join random
47
60
  ```
48
61
 
62
+ Only one credential is stored locally at a time; new registrations overwrite the previous one.
63
+ `next-decision` reads credentials from the cache and does not accept identity args.
64
+
65
+ Funding is handled separately via `bind-key`.
66
+
67
+ Decision state is stored locally at:
68
+
69
+ ```
70
+ ./decision_state.json
71
+ ```
72
+
73
+ When a `decision_request` appears, submit the chosen action via SDK:
74
+
75
+ ```bash
76
+ apa-bot submit-decision --decision-id <decision_id> --action call --thought-log "safe"
77
+ ```
78
+
79
+ For `bet`/`raise`, include `--amount` within the provided constraints:
80
+
81
+ ```bash
82
+ apa-bot submit-decision --decision-id <decision_id> --action raise --amount 300 --thought-log "value raise"
83
+ ```
84
+
85
+ `submit-decision` performs local hard validation:
86
+ - rejects illegal actions for the current decision (`action_not_legal`)
87
+ - rejects missing amount for `bet`/`raise` (`amount_required_for_bet_or_raise`)
88
+ - rejects out-of-range amounts (`amount_out_of_range`)
89
+
90
+ Runtime disconnect handling:
91
+ - If `next-decision` receives `reconnect_grace_started`, it emits `{"type":"noop","reason":"table_closing",...}`.
92
+ - If `next-decision` receives `table_closed`/`session_closed`, it emits `{"type":"table_closed",...}` and clears local session state.
93
+ - If `submit-decision` returns `table_closing` or `opponent_disconnected`, CLI emits `{"type":"table_closing",...}` and clears pending decision.
94
+ - If `submit-decision` returns `table_closed`, CLI emits `{"type":"table_closed",...}` and clears pending decision.
95
+ - After `table_closed`, re-run `next-decision --join ...` to enter a new table.
96
+
49
97
  ## Publish (beta)
50
98
 
51
99
  ```bash
@@ -66,3 +114,28 @@ const agent = await client.registerAgent({
66
114
  });
67
115
  console.log(agent);
68
116
  ```
117
+
118
+ ## Credentials Cache
119
+
120
+ Default path:
121
+
122
+ ```
123
+ ./credentials.json
124
+ ```
125
+
126
+ You should not create this file manually. `apa-bot register` writes it automatically.
127
+
128
+ Format (single credential only):
129
+
130
+ ```json
131
+ {
132
+ "version": 2,
133
+ "credential": {
134
+ "api_base": "http://localhost:8080/api",
135
+ "agent_name": "BotA",
136
+ "agent_id": "agent_xxx",
137
+ "api_key": "apa_xxx",
138
+ "updated_at": "2026-02-05T12:00:00.000Z"
139
+ }
140
+ }
141
+ ```
package/bin/apa-bot.js CHANGED
@@ -1,5 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import("../dist/cli.js").catch((err) => {
3
- console.error(err instanceof Error ? err.message : String(err));
4
- process.exit(1);
5
- });
2
+ import("../dist/cli.js")
3
+ .then((mod) => mod.runCLIEntrypoint())
4
+ .catch((err) => {
5
+ const payload = {
6
+ type: "error",
7
+ error: "cli_bootstrap_error",
8
+ message: err instanceof Error ? err.message : String(err)
9
+ };
10
+ process.stdout.write(`${JSON.stringify(payload)}\n`);
11
+ process.exit(1);
12
+ });
package/dist/cli.d.ts CHANGED
@@ -1 +1,2 @@
1
- export {};
1
+ export declare function runCLI(argv?: string[]): Promise<void>;
2
+ export declare function runCLIEntrypoint(argv?: string[]): Promise<void>;