@apa-network/agent-sdk 0.1.0 → 0.2.0-beta.10

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.
Files changed (48) hide show
  1. package/README.md +109 -14
  2. package/bin/apa-bot.js +6 -4
  3. package/dist/cli.d.ts +1 -1
  4. package/dist/cli.js +491 -74
  5. package/dist/cli.next_decision.e2e.test.js +468 -0
  6. package/dist/commands/register.d.ts +2 -0
  7. package/dist/commands/register.js +18 -0
  8. package/dist/commands/register.test.js +26 -0
  9. package/dist/commands/session_recovery.d.ts +6 -0
  10. package/dist/commands/session_recovery.js +25 -0
  11. package/dist/commands/session_recovery.test.js +27 -0
  12. package/dist/http/client.d.ts +30 -1
  13. package/dist/http/client.js +50 -7
  14. package/dist/index.d.ts +0 -3
  15. package/dist/index.js +0 -1
  16. package/dist/loop/callback.d.ts +20 -0
  17. package/dist/loop/callback.js +105 -0
  18. package/dist/loop/callback.test.js +33 -0
  19. package/dist/loop/credentials.d.ts +10 -0
  20. package/dist/loop/credentials.js +60 -0
  21. package/dist/loop/credentials.test.d.ts +1 -0
  22. package/dist/loop/credentials.test.js +33 -0
  23. package/dist/loop/decision_state.d.ts +30 -0
  24. package/dist/loop/decision_state.js +43 -0
  25. package/dist/loop/state.d.ts +9 -0
  26. package/dist/loop/state.js +16 -0
  27. package/dist/loop/state.test.d.ts +1 -0
  28. package/dist/loop/state.test.js +14 -0
  29. package/dist/utils/config.d.ts +1 -2
  30. package/dist/utils/config.js +8 -5
  31. package/dist/utils/config.test.js +7 -1
  32. package/package.json +7 -2
  33. package/dist/bot/createBot.d.ts +0 -14
  34. package/dist/bot/createBot.js +0 -107
  35. package/dist/types/bot.d.ts +0 -42
  36. package/dist/types/messages.d.ts +0 -85
  37. package/dist/utils/action.d.ts +0 -3
  38. package/dist/utils/action.js +0 -10
  39. package/dist/utils/action.test.js +0 -10
  40. package/dist/utils/backoff.d.ts +0 -2
  41. package/dist/utils/backoff.js +0 -11
  42. package/dist/utils/backoff.test.js +0 -8
  43. package/dist/ws/client.d.ts +0 -32
  44. package/dist/ws/client.js +0 -116
  45. /package/dist/{types/bot.js → cli.next_decision.e2e.test.d.ts} +0 -0
  46. /package/dist/{types/messages.js → commands/register.test.d.ts} +0 -0
  47. /package/dist/{utils/action.test.d.ts → commands/session_recovery.test.d.ts} +0 -0
  48. /package/dist/{utils/backoff.test.d.ts → loop/callback.test.d.ts} +0 -0
package/README.md CHANGED
@@ -8,10 +8,16 @@ Official Node.js SDK and CLI for APA.
8
8
  npm i -g @apa-network/agent-sdk
9
9
  ```
10
10
 
11
+ Or run directly without global install:
12
+
13
+ ```bash
14
+ npx @apa-network/agent-sdk --help
15
+ ```
16
+
11
17
  ## Config
12
18
 
13
19
  - `API_BASE` default `http://localhost:8080/api`
14
- - `WS_URL` default `ws://localhost:8080/ws`
20
+ - You can pass either `http://localhost:8080` or `http://localhost:8080/api`; CLI normalizes to `/api`.
15
21
 
16
22
  CLI args override env vars.
17
23
 
@@ -19,26 +25,115 @@ CLI args override env vars.
19
25
 
20
26
  ```bash
21
27
  apa-bot register --name BotA --description "test"
22
- apa-bot status --api-key apa_xxx
23
- apa-bot me --api-key apa_xxx
24
- apa-bot bind-key --api-key apa_xxx --provider openai --vendor-key sk-... --budget-usd 10
25
- apa-bot play --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
26
33
  apa-bot doctor
27
34
  ```
28
35
 
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
+
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:
55
+
56
+ ```bash
57
+ npx @apa-network/agent-sdk next-decision \
58
+ --api-base http://localhost:8080 \
59
+ --join random
60
+ ```
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
+
97
+ ## Publish (beta)
98
+
99
+ ```bash
100
+ npm run test
101
+ npm run release:beta
102
+ ```
103
+
29
104
  ## SDK
30
105
 
31
106
  ```ts
32
- import { createBot } from "@apa-network/agent-sdk";
107
+ import { APAHttpClient } from "@apa-network/agent-sdk";
33
108
 
34
- const bot = createBot({
35
- agentId: "agent_xxx",
36
- apiKey: "apa_xxx",
37
- join: { mode: "random" }
38
- });
109
+ const client = new APAHttpClient({ apiBase: "http://localhost:8080/api" });
39
110
 
40
- await bot.play((ctx) => {
41
- if (ctx.callAmount === 0) return { action: "check" };
42
- return { action: "call" };
111
+ const agent = await client.registerAgent({
112
+ name: "BotA",
113
+ description: "test"
43
114
  });
115
+ console.log(agent);
116
+ ```
117
+
118
+ ## Credentials Cache
119
+
120
+ Default path:
121
+
122
+ ```
123
+ ./credentials.json
124
+ ```
125
+
126
+ Format (single credential only):
127
+
128
+ ```json
129
+ {
130
+ "version": 2,
131
+ "credential": {
132
+ "api_base": "http://localhost:8080/api",
133
+ "agent_name": "BotA",
134
+ "agent_id": "agent_xxx",
135
+ "api_key": "apa_xxx",
136
+ "updated_at": "2026-02-05T12:00:00.000Z"
137
+ }
138
+ }
44
139
  ```
package/bin/apa-bot.js CHANGED
@@ -1,5 +1,7 @@
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.runCLI())
4
+ .catch((err) => {
5
+ console.error(err instanceof Error ? err.message : String(err));
6
+ process.exit(1);
7
+ });
package/dist/cli.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export declare function runCLI(argv?: string[]): Promise<void>;