agentkey-ai 1.2.1 → 1.3.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.
Files changed (3) hide show
  1. package/README.md +51 -16
  2. package/agentkey.js +2 -2
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -35,39 +35,74 @@ The CLI never prints your key. `agentkey init` saves a pasted key to a local con
35
35
  2. Open the Connect wizard (or Agents, then create an agent).
36
36
  3. Generate an API key. It is shown once. Run `agentkey init` to save it to the local config file, or export it as `AGENTKEY_API_KEY`. Never hard-code it.
37
37
 
38
- ## First authorization (Python)
38
+ ## First authorization (guided)
39
+
40
+ Run this right after `agentkey init` (or with `AGENTKEY_API_KEY` exported). It performs ONE real, least-privilege authorization: `sandbox.send_test`, an isolated test capability every new agent ships with. It can only ever return allow or deny; it never performs a real external side effect, never touches a real tool, and grants nothing beyond that single permission. The decision is made by the real policy engine and recorded as hash-chained evidence.
41
+
42
+ Python:
39
43
 
40
44
  ```python
41
45
  from agentkey import AgentKeyClient
42
46
 
43
- ak = AgentKeyClient(api_key="agent_live_xxxxx") # production API by default
47
+ ak = AgentKeyClient() # reads AGENTKEY_API_KEY, or the config file from `agentkey init`
48
+
49
+ result = ak.check_permission(action="send_test", resource="sandbox")
44
50
 
45
- result = ak.check_permission(action="send_email", resource="gmail", arguments={"to": "x@company.com"})
46
- if result["allowed"]:
47
- send_email(...) # your code
51
+ print("session_id: ", result.get("session_id"))
52
+ decision = "ALLOW" if result.get("allowed") else ("APPROVAL REQUIRED" if result.get("approval_required") else "DENY")
53
+ print("decision: ", decision, "-", result.get("reason"))
54
+ if result.get("event_id"):
55
+ print("evidence_event_id:", result["event_id"])
56
+ print()
57
+ print("YOU'RE DONE - your first real authorization was decided by the policy")
58
+ print("engine and recorded as verifiable evidence. See it in the dashboard:")
59
+ print("https://agentkey.us/sessions/" + str(result.get("session_id")))
48
60
  else:
49
- print("Blocked:", result["reason"], "approval_required:", result.get("approval_required", False))
61
+ reason = str(result.get("reason") or "")
62
+ if "Invalid API key" in reason:
63
+ print("Your key is invalid - create one at https://agentkey.us/connect")
64
+ elif "No permission configured" in reason:
65
+ print("This agent has no sandbox.send_test permission yet. Add one in the")
66
+ print("dashboard (Agents -> Permissions): resource 'sandbox', action")
67
+ print("'send_test', decision allow - then run this again.")
68
+ else:
69
+ print("Denied by policy:", reason)
50
70
  ```
51
71
 
52
- ## First authorization (JavaScript / TypeScript)
72
+ JavaScript / TypeScript (save as `first-authorization.mjs`, run with `node first-authorization.mjs`):
53
73
 
54
74
  ```js
55
75
  import { AgentKeyClient } from "agentkey-ai";
56
76
 
57
- const ak = new AgentKeyClient({ apiKey: "agent_live_xxxxx" }); // production API by default
77
+ const ak = new AgentKeyClient(); // reads AGENTKEY_API_KEY, or the config file from `npx agentkey init`
58
78
 
59
- const result = await ak.checkPermission({
60
- action: "send_email",
61
- resource: "gmail",
62
- arguments: { to: "x@company.com" },
63
- });
64
- if (result.allowed) {
65
- await sendEmail(); // your code
79
+ const result = await ak.checkPermission({ action: "send_test", resource: "sandbox" });
80
+
81
+ console.log("session_id: ", result.session_id);
82
+ const decision = result.allowed ? "ALLOW" : (result.approval_required ? "APPROVAL REQUIRED" : "DENY");
83
+ console.log("decision: ", decision, "-", result.reason);
84
+ if (result.event_id) {
85
+ console.log("evidence_event_id:", result.event_id);
86
+ console.log();
87
+ console.log("YOU'RE DONE - your first real authorization was decided by the policy");
88
+ console.log("engine and recorded as verifiable evidence. See it in the dashboard:");
89
+ console.log("https://agentkey.us/sessions/" + result.session_id);
66
90
  } else {
67
- console.log("Blocked:", result.reason, "approval_required:", result.approval_required ?? false);
91
+ const reason = String(result.reason || "");
92
+ if (reason.includes("Invalid API key")) {
93
+ console.log("Your key is invalid - create one at https://agentkey.us/connect");
94
+ } else if (reason.includes("No permission configured")) {
95
+ console.log("This agent has no sandbox.send_test permission yet. Add one in the");
96
+ console.log("dashboard (Agents -> Permissions): resource 'sandbox', action");
97
+ console.log("'send_test', decision allow - then run this again.");
98
+ } else {
99
+ console.log("Denied by policy:", reason);
100
+ }
68
101
  }
69
102
  ```
70
103
 
104
+ A wrong, expired, or revoked key fails closed exactly like any other call (`allowed: false`); the scripts above tell you which case you are in.
105
+
71
106
  ## Decisions: allow, deny, ask
72
107
 
73
108
  `check_permission` / `checkPermission` evaluates the permissions you configured for the agent:
package/agentkey.js CHANGED
@@ -19,8 +19,8 @@ const FAIL_CLOSED = { allowed: false, reason: "agentkey_unreachable", fail_close
19
19
  const TIMEOUT_MS = 5000;
20
20
 
21
21
  // Production API. Override with baseUrl only if you self-host.
22
- export const DEFAULT_BASE_URL = "https://agentkey.base44.app";
23
- export const VERSION = "1.2.1";
22
+ export const DEFAULT_BASE_URL = "https://agentkey.us";
23
+ export const VERSION = "1.3.0";
24
24
  const USER_AGENT = `agentkey-sdk-js/${VERSION}`;
25
25
 
26
26
  // Process-wide flag so the first-run info block prints once per process.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentkey-ai",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "Authorization and evidence SDK for AI agents: check permissions before every action, record what agents actually did.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -36,5 +36,5 @@
36
36
  "llm"
37
37
  ],
38
38
  "license": "MIT",
39
- "homepage": "https://agentkey.base44.app"
40
- }
39
+ "homepage": "https://agentkey.us"
40
+ }