argus-media-cli 0.1.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.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
3
+ import { join } from "path";
4
+ import { homedir } from "os";
5
+ const BASE_URL = process.env.ARGUS_BASE_URL || "https://argus.build";
6
+ const CONFIG_DIR = join(homedir(), ".argus");
7
+ const CONFIG_FILE = join(CONFIG_DIR, "config.json");
8
+ // ── Config ────────────────────────────────────────────────────────────────────
9
+ function loadConfig() {
10
+ try {
11
+ return JSON.parse(readFileSync(CONFIG_FILE, "utf8"));
12
+ }
13
+ catch {
14
+ return {};
15
+ }
16
+ }
17
+ function saveConfig(config) {
18
+ mkdirSync(CONFIG_DIR, { recursive: true });
19
+ writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
20
+ }
21
+ function getApiKey() {
22
+ const key = process.env.ARGUS_API_KEY || loadConfig().apiKey;
23
+ if (!key) {
24
+ console.error("No API key found. Run: argus login <api-key>");
25
+ console.error("Or set ARGUS_API_KEY in your environment.");
26
+ process.exit(1);
27
+ }
28
+ return key;
29
+ }
30
+ // ── HTTP ──────────────────────────────────────────────────────────────────────
31
+ async function api(method, path, body) {
32
+ const res = await fetch(`${BASE_URL}${path}`, {
33
+ method,
34
+ headers: {
35
+ Authorization: `Bearer ${getApiKey()}`,
36
+ ...(body ? { "Content-Type": "application/json" } : {}),
37
+ },
38
+ ...(body ? { body: JSON.stringify(body) } : {}),
39
+ });
40
+ const data = await res.json().catch(() => ({}));
41
+ if (!res.ok) {
42
+ const err = data.error || res.statusText;
43
+ console.error(`Error: ${err}`);
44
+ process.exit(1);
45
+ }
46
+ return data;
47
+ }
48
+ // ── Output ────────────────────────────────────────────────────────────────────
49
+ function output(data, json) {
50
+ if (json) {
51
+ console.log(JSON.stringify(data, null, 2));
52
+ return;
53
+ }
54
+ const asset = data.asset;
55
+ const assets = data.assets;
56
+ if (asset)
57
+ printAsset(asset);
58
+ else if (assets)
59
+ assets.forEach(printAsset);
60
+ else
61
+ console.log(JSON.stringify(data, null, 2));
62
+ }
63
+ function printAsset(a) {
64
+ const analysis = a.analysis;
65
+ console.log(`\n${a.id}`);
66
+ console.log(` File: ${a.filename}`);
67
+ console.log(` URL: ${a.url}`);
68
+ console.log(` Status: ${a.status}`);
69
+ if (a.project)
70
+ console.log(` Project: ${a.project}`);
71
+ if (a.tags && Array.isArray(a.tags) && a.tags.length)
72
+ console.log(` Tags: ${a.tags.join(", ")}`);
73
+ if (analysis?.description)
74
+ console.log(` Desc: ${analysis.description}`);
75
+ if (analysis?.mood)
76
+ console.log(` Mood: ${analysis.mood}`);
77
+ }
78
+ // ── Commands ──────────────────────────────────────────────────────────────────
79
+ const args = process.argv.slice(2);
80
+ const jsonFlag = args.includes("--json");
81
+ const filteredArgs = args.filter((a) => a !== "--json");
82
+ const [command, ...rest] = filteredArgs;
83
+ async function main() {
84
+ switch (command) {
85
+ case "login": {
86
+ const key = rest[0];
87
+ if (!key) {
88
+ console.error("Usage: argus login <api-key>");
89
+ process.exit(1);
90
+ }
91
+ saveConfig({ ...loadConfig(), apiKey: key });
92
+ console.log("API key saved to ~/.argus/config.json");
93
+ break;
94
+ }
95
+ case "upload": {
96
+ const file = rest[0];
97
+ const project = rest[1];
98
+ if (!file || !existsSync(file)) {
99
+ console.error("Usage: argus upload <file> [project]");
100
+ process.exit(1);
101
+ }
102
+ const { createReadStream, statSync } = await import("fs");
103
+ const { basename } = await import("path");
104
+ const fd = new FormData();
105
+ const bytes = readFileSync(file);
106
+ fd.append("file", new Blob([bytes]), basename(file));
107
+ if (project)
108
+ fd.append("project", project);
109
+ const res = await fetch(`${BASE_URL}/assets/upload`, {
110
+ method: "POST",
111
+ headers: { Authorization: `Bearer ${getApiKey()}` },
112
+ body: fd,
113
+ });
114
+ const data = await res.json().catch(() => ({}));
115
+ if (!res.ok) {
116
+ console.error(`Error: ${data.error || res.statusText}`);
117
+ process.exit(1);
118
+ }
119
+ output(data, jsonFlag);
120
+ break;
121
+ }
122
+ case "search": {
123
+ const query = rest.join(" ");
124
+ if (!query) {
125
+ console.error("Usage: argus search <query>");
126
+ process.exit(1);
127
+ }
128
+ const data = await api("GET", `/assets?q=${encodeURIComponent(query)}`);
129
+ output(data, jsonFlag);
130
+ break;
131
+ }
132
+ case "list": {
133
+ const project = rest[0];
134
+ const qs = project ? `?project=${encodeURIComponent(project)}` : "";
135
+ const data = await api("GET", `/assets${qs}`);
136
+ output(data, jsonFlag);
137
+ break;
138
+ }
139
+ case "get": {
140
+ const id = rest[0];
141
+ if (!id) {
142
+ console.error("Usage: argus get <id>");
143
+ process.exit(1);
144
+ }
145
+ const data = await api("GET", `/assets/${id}`);
146
+ output(data, jsonFlag);
147
+ break;
148
+ }
149
+ case "usage": {
150
+ const data = await api("GET", "/usage");
151
+ output(data, jsonFlag);
152
+ break;
153
+ }
154
+ default:
155
+ console.log(`argus <command> [options]
156
+
157
+ Commands:
158
+ login <api-key> Save API key to ~/.argus/config.json
159
+ upload <file> [project] Upload an image
160
+ search <query> Search assets by keyword
161
+ list [project] List assets
162
+ get <id> Get asset by ID
163
+ usage Show credit and asset usage
164
+
165
+ Options:
166
+ --json Output raw JSON
167
+
168
+ Environment:
169
+ ARGUS_API_KEY API key (overrides saved config)
170
+ ARGUS_BASE_URL API base URL (default: https://argus.build)
171
+
172
+ Get an API key at https://argus.build/ui/settings
173
+ `);
174
+ process.exit(command ? 1 : 0);
175
+ }
176
+ }
177
+ main().catch((err) => {
178
+ console.error(err.message || err);
179
+ process.exit(1);
180
+ });
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "argus-media-cli",
3
+ "version": "0.1.0",
4
+ "description": "CLI for Argus — AI-powered media catalog. Upload, search, and manage media assets from the terminal.",
5
+ "keywords": ["argus", "media", "assets", "cli", "ai", "mcp"],
6
+ "license": "MIT",
7
+ "author": "Brookfield Digital",
8
+ "homepage": "https://argus.build",
9
+ "type": "module",
10
+ "bin": {
11
+ "argus": "./dist/index.js"
12
+ },
13
+ "main": "./dist/index.js",
14
+ "files": ["dist", "README.md"],
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "prepublishOnly": "npm run build"
18
+ },
19
+ "devDependencies": {
20
+ "@types/node": "^20.0.0",
21
+ "typescript": "^5.4.0"
22
+ },
23
+ "engines": { "node": ">=18" }
24
+ }