@an-sdk/cli 0.0.8 → 0.0.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.
package/src/index.ts ADDED
@@ -0,0 +1,100 @@
1
+ import { login } from "./login.js"
2
+ import { deploy } from "./deploy.js"
3
+ import { envList, envSet, envRemove } from "./env.js"
4
+ import { createRequire } from "module"
5
+
6
+ const require = createRequire(import.meta.url)
7
+ const { version } = require("../package.json")
8
+
9
+ const command = process.argv[2]
10
+ const args = process.argv.slice(3)
11
+ const hasFlag = (flag: string) => args.includes(flag)
12
+ function getFlagValue(flag: string): string | undefined {
13
+ const idx = args.indexOf(flag)
14
+ if (idx === -1 || idx + 1 >= args.length) return undefined
15
+ return args[idx + 1]
16
+ }
17
+
18
+ function showHelp() {
19
+ console.log(`AN CLI v${version} — deploy AI agents\n`)
20
+ console.log("Usage: an <command>\n")
21
+ console.log("Commands:")
22
+ console.log(" an login Authenticate with AN platform")
23
+ console.log(" an deploy Bundle and deploy your agent")
24
+ console.log(" an env list <agent> List environment variables")
25
+ console.log(" an env set <agent> K V Set an environment variable")
26
+ console.log(" an env remove <agent> K Remove an environment variable")
27
+ console.log("\nOptions:")
28
+ console.log(" --help, -h Show help")
29
+ console.log(" --version, -v Show version")
30
+ console.log("\nEnvironment variables:")
31
+ console.log(" AN_API_KEY API key (skips login prompt)")
32
+ console.log(" AN_API_URL API base URL override")
33
+ console.log("\nGet started: an login")
34
+ console.log("Docs: https://an.dev/docs")
35
+ }
36
+
37
+ function showLoginHelp() {
38
+ console.log("Usage: an login [options]\n")
39
+ console.log("Authenticate with the AN platform using an API key.\n")
40
+ console.log("Options:")
41
+ console.log(" --api-key KEY Pass API key directly (non-interactive)")
42
+ console.log("\nGet your API key at https://an.dev/api-keys")
43
+ }
44
+
45
+ function showDeployHelp() {
46
+ console.log("Usage: an deploy\n")
47
+ console.log("Bundle and deploy agents from the ./agents/ directory.\n")
48
+ console.log("Agent structure:")
49
+ console.log(" agents/")
50
+ console.log(" my-agent/")
51
+ console.log(" index.ts agent entry point")
52
+ console.log(" another.ts single-file agent")
53
+ console.log("\nDocs: https://an.dev/docs")
54
+ }
55
+
56
+ function showEnvHelp() {
57
+ console.log("Usage: an env <subcommand> <agent-slug>\n")
58
+ console.log("Manage environment variables for an agent.\n")
59
+ console.log("Subcommands:")
60
+ console.log(" an env list <agent> List all env vars (masked)")
61
+ console.log(" an env list <agent> --show-values List all env vars (plain text)")
62
+ console.log(" an env set <agent> KEY VALUE Set or update an env var")
63
+ console.log(" an env remove <agent> KEY Remove an env var")
64
+ }
65
+
66
+ if (command === "login") {
67
+ if (hasFlag("--help") || hasFlag("-h")) {
68
+ showLoginHelp()
69
+ } else {
70
+ await login({ apiKey: getFlagValue("--api-key") })
71
+ }
72
+ } else if (command === "deploy") {
73
+ if (hasFlag("--help") || hasFlag("-h")) {
74
+ showDeployHelp()
75
+ } else {
76
+ if (hasFlag("--project")) {
77
+ console.log("Warning: --project flag is no longer used and will be ignored.")
78
+ }
79
+ await deploy()
80
+ }
81
+ } else if (command === "env") {
82
+ const subcommand = args[0]
83
+ const subArgs = args.slice(1)
84
+ if (!subcommand || subcommand === "--help" || subcommand === "-h") {
85
+ showEnvHelp()
86
+ } else if (subcommand === "list") {
87
+ await envList(subArgs)
88
+ } else if (subcommand === "set") {
89
+ await envSet(subArgs)
90
+ } else if (subcommand === "remove") {
91
+ await envRemove(subArgs)
92
+ } else {
93
+ console.log(`Unknown env subcommand: ${subcommand}`)
94
+ showEnvHelp()
95
+ }
96
+ } else if (command === "--version" || command === "-v") {
97
+ console.log(version)
98
+ } else {
99
+ showHelp()
100
+ }
package/src/login.ts ADDED
@@ -0,0 +1,77 @@
1
+ import * as p from "@clack/prompts"
2
+ import { getApiKey, saveApiKey } from "./config.js"
3
+ import { isInteractive } from "./detect.js"
4
+
5
+ const API_BASE = process.env.AN_API_URL || "https://an.dev/api/v1"
6
+
7
+ async function verifyKey(apiKey: string): Promise<{ user: any; team: any }> {
8
+ const res = await fetch(`${API_BASE}/me`, {
9
+ headers: { Authorization: `Bearer ${apiKey.trim()}` },
10
+ })
11
+ if (!res.ok) {
12
+ throw new Error("Invalid API key")
13
+ }
14
+ return res.json()
15
+ }
16
+
17
+ export async function login(opts?: { apiKey?: string }) {
18
+ const key = opts?.apiKey
19
+
20
+ // Non-interactive: --api-key flag passed directly
21
+ if (key) {
22
+ try {
23
+ const { user, team } = await verifyKey(key)
24
+ saveApiKey(key.trim())
25
+ console.log(`Authenticated as ${user.displayName || user.email} (team: ${team.name})`)
26
+ console.log("Key saved to ~/.an/credentials")
27
+ } catch {
28
+ console.error("Error: Invalid API key. Get a new one at https://an.dev/api-keys")
29
+ process.exit(1)
30
+ }
31
+ return
32
+ }
33
+
34
+ // Non-interactive without key: can't prompt
35
+ if (!isInteractive()) {
36
+ console.error("Error: No API key provided. Use --api-key KEY or set AN_API_KEY env var.")
37
+ console.error("Get your API key at https://an.dev/api-keys")
38
+ process.exit(1)
39
+ }
40
+
41
+ // Interactive flow
42
+ p.intro("an login")
43
+
44
+ const existing = getApiKey()
45
+ if (existing) {
46
+ p.log.info("Already logged in. Continuing will re-authenticate.")
47
+ }
48
+ p.log.info("Get your API key at https://an.dev/api-keys")
49
+
50
+ const apiKey = await p.text({
51
+ message: "Enter your API key",
52
+ validate: (val) => {
53
+ if (!val.trim()) return "API key cannot be empty"
54
+ },
55
+ })
56
+
57
+ if (p.isCancel(apiKey)) {
58
+ p.cancel("Login cancelled.")
59
+ process.exit(0)
60
+ }
61
+
62
+ const s = p.spinner()
63
+ s.start("Verifying API key...")
64
+
65
+ try {
66
+ const { user, team } = await verifyKey(apiKey)
67
+ saveApiKey(apiKey.trim())
68
+ s.stop("Verified")
69
+ p.log.success(`Authenticated as ${user.displayName || user.email} (team: ${team.name})`)
70
+ p.log.info("Key saved to ~/.an/credentials")
71
+ p.outro("Done")
72
+ } catch {
73
+ s.stop("Invalid API key")
74
+ p.log.error("Invalid API key. Get a new one at https://an.dev/api-keys")
75
+ process.exit(1)
76
+ }
77
+ }