@apa-network/agent-sdk 0.2.0-beta.10 → 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
@@ -123,6 +123,8 @@ Default path:
123
123
  ./credentials.json
124
124
  ```
125
125
 
126
+ You should not create this file manually. `apa-bot register` writes it automatically.
127
+
126
128
  Format (single credential only):
127
129
 
128
130
  ```json
package/bin/apa-bot.js CHANGED
@@ -1,7 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import("../dist/cli.js")
3
- .then((mod) => mod.runCLI())
3
+ .then((mod) => mod.runCLIEntrypoint())
4
4
  .catch((err) => {
5
- console.error(err instanceof Error ? err.message : String(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`);
6
11
  process.exit(1);
7
12
  });
package/dist/cli.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare function runCLI(argv?: string[]): Promise<void>;
2
+ export declare function runCLIEntrypoint(argv?: string[]): Promise<void>;
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { APAHttpClient } from "./http/client.js";
2
2
  import { resolveApiBase, requireArg } from "./utils/config.js";
3
- import { loadCredential, saveCredential } from "./loop/credentials.js";
3
+ import { defaultCredentialPath, loadCredential, saveCredential } from "./loop/credentials.js";
4
4
  import { loadDecisionState, saveDecisionState } from "./loop/decision_state.js";
5
5
  import { TurnTracker } from "./loop/state.js";
6
6
  import { buildCredentialFromRegisterResult } from "./commands/register.js";
@@ -65,7 +65,8 @@ Config priority: CLI args > env (API_BASE) > defaults.`);
65
65
  async function requireApiKey(apiBase) {
66
66
  const cached = await loadCredential(apiBase, undefined);
67
67
  if (!cached?.api_key) {
68
- throw new Error("api_key_not_found (run apa-bot register)");
68
+ const path = defaultCredentialPath();
69
+ throw new Error(`api_key_not_found for api_base=${apiBase} (run apa-bot register). path=${path}`);
69
70
  }
70
71
  return cached.api_key;
71
72
  }
@@ -82,6 +83,16 @@ function claimCodeFromUrl(raw) {
82
83
  function emit(message) {
83
84
  process.stdout.write(`${JSON.stringify(message)}\n`);
84
85
  }
86
+ function toErrorPayload(err) {
87
+ const apiErr = err;
88
+ const code = apiErr?.code || "cli_error";
89
+ const message = err instanceof Error ? err.message : String(err);
90
+ return {
91
+ type: "error",
92
+ error: code,
93
+ message
94
+ };
95
+ }
85
96
  function readLegalActions(state) {
86
97
  const raw = state["legal_actions"];
87
98
  if (!Array.isArray(raw)) {
@@ -591,3 +602,12 @@ export async function runCLI(argv = process.argv.slice(2)) {
591
602
  throw new Error(`unknown command: ${command}`);
592
603
  }
593
604
  }
605
+ export async function runCLIEntrypoint(argv = process.argv.slice(2)) {
606
+ try {
607
+ await runCLI(argv);
608
+ }
609
+ catch (err) {
610
+ emit(toErrorPayload(err));
611
+ process.exitCode = 1;
612
+ }
613
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apa-network/agent-sdk",
3
- "version": "0.2.0-beta.10",
3
+ "version": "0.2.0-beta.12",
4
4
  "description": "APA Agent SDK and CLI",
5
5
  "type": "module",
6
6
  "bin": {