@ai2aim.ai/hivemind-sdk 1.0.15 → 3.1.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"cli-config.d.ts","sourceRoot":"","sources":["../src/cli-config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAsBpD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,SAAgB,GAAG,oBAAoB,GAAG,IAAI,CA4C9E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAahF;AAED,eAAO,MAAM,kBAAkB,qBAAc,CAAC"}
1
+ {"version":3,"file":"cli-config.d.ts","sourceRoot":"","sources":["../src/cli-config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAsBpD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,SAAgB,GAAG,oBAAoB,GAAG,IAAI,CAyC9E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYhF;AAED,eAAO,MAAM,kBAAkB,qBAAc,CAAC"}
@@ -57,8 +57,6 @@ function loadCliConfig(cwd = process.cwd()) {
57
57
  fileConfig.adminKey,
58
58
  webhookSecret: env("WEBHOOK_SECRET") ??
59
59
  fileConfig.webhookSecret,
60
- employeeId: env("EMPLOYEE_ID") ??
61
- fileConfig.employeeId,
62
60
  timeoutMs: envInt("TIMEOUT_MS") ??
63
61
  fileConfig.timeoutMs ??
64
62
  30_000,
@@ -77,7 +75,6 @@ function maskConfig(config) {
77
75
  apiKey: config.apiKey ? mask(config.apiKey) : undefined,
78
76
  adminKey: config.adminKey ? "[set]" : undefined,
79
77
  webhookSecret: config.webhookSecret ? "[set]" : undefined,
80
- employeeId: config.employeeId,
81
78
  timeoutMs: config.timeoutMs,
82
79
  insecure: config.insecure,
83
80
  };
@@ -1 +1 @@
1
- {"version":3,"file":"cli-config.js","sourceRoot":"","sources":["../src/cli-config.ts"],"names":[],"mappings":";;;;;;AA4BA,sCA4CC;AAKD,gCAaC;AA1FD,sDAAyB;AACzB,0DAA6B;AAG7B,MAAM,WAAW,GAAG,kBAAkB,CAAC;AACvC,MAAM,UAAU,GAAG,WAAW,CAAC;AAE/B,SAAS,GAAG,CAAC,GAAW;IACtB,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,UAAU,GAAG,GAAG,EAAE,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,OAAO,CAAC,GAAW;IAC1B,MAAM,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACnB,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACtC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,MAAM,IAAI,CAAC,KAAK,KAAK,CAAC;AAChE,CAAC;AAED,SAAS,MAAM,CAAC,GAAW;IACzB,MAAM,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACnB,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACtC,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC1B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AACzC,CAAC;AAED;;;GAGG;AACH,SAAgB,aAAa,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE;IAC/C,MAAM,MAAM,GAAG,mBAAI,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IAC3C,IAAI,UA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commander_1.Command();
14
14
  program
15
15
  .name("hivemind")
16
16
  .description("CLI for the Hivemind API")
17
- .version("1.0.0");
18
- // ---------------------------------------------------------------------------
19
- // init
20
- // ---------------------------------------------------------------------------
17
+ .version("3.1.0");
18
+ function parseCsvList(value) {
19
+ if (!value)
20
+ return [];
21
+ const seen = new Set();
22
+ const items = [];
23
+ for (const part of value.split(",")) {
24
+ const item = part.trim();
25
+ if (!item)
26
+ continue;
27
+ const key = item.toLowerCase();
28
+ if (seen.has(key))
29
+ continue;
30
+ seen.add(key);
31
+ items.push(item);
32
+ }
33
+ return items;
34
+ }
35
+ function exitWithError(label, err) {
36
+ if (err instanceof client_1.HivemindError) {
37
+ console.error(`${label}:`, err.statusCode, err.detail);
38
+ }
39
+ else {
40
+ console.error(`${label}:`, err);
41
+ }
42
+ process.exit(1);
43
+ }
21
44
  program
22
45
  .command("init")
23
46
  .description("Initialize Hivemind config in the current directory")
@@ -35,7 +58,7 @@ program
35
58
  const rcTemplate = {
36
59
  baseUrl: "https://your-api-url.com",
37
60
  apiPrefix: "/v1",
38
- apiKey: "vtx_org_xxx",
61
+ apiKey: "vtx_xxx",
39
62
  // adminKey: "your-admin-key",
40
63
  // insecure: false,
41
64
  // timeoutMs: 30000,
@@ -53,7 +76,7 @@ program
53
76
  const envLines = [
54
77
  "# Hivemind API",
55
78
  "HIVEMIND_BASE_URL=https://your-api-url.com",
56
- "HIVEMIND_API_KEY=vtx_org_xxx",
79
+ "HIVEMIND_API_KEY=vtx_xxx",
57
80
  "# HIVEMIND_ADMIN_KEY=your-admin-key",
58
81
  "# HIVEMIND_API_PREFIX=/v1",
59
82
  "# HIVEMIND_INSECURE=false",
@@ -67,11 +90,8 @@ program
67
90
  console.log("Created:", envExamplePath);
68
91
  }
69
92
  }
70
- console.log("\nNext: set HIVEMIND_BASE_URL (and HIVEMIND_API_KEY for org calls), then run: hivemind health");
93
+ console.log("\nNext: set HIVEMIND_BASE_URL, then run: hivemind health");
71
94
  });
72
- // ---------------------------------------------------------------------------
73
- // config
74
- // ---------------------------------------------------------------------------
75
95
  program
76
96
  .command("config")
77
97
  .description("Show resolved config (secrets masked)")
@@ -79,14 +99,11 @@ program
79
99
  .action((opts) => {
80
100
  const config = (0, cli_config_1.loadCliConfig)(node_path_1.default.resolve(opts.dir));
81
101
  if (!config) {
82
- console.error("No config found. Set HIVEMIND_BASE_URL (or run hivemind init and edit .hivemindrc.json).");
102
+ console.error("No config found. Set HIVEMIND_BASE_URL or run hivemind init.");
83
103
  process.exit(1);
84
104
  }
85
105
  console.log(JSON.stringify((0, cli_config_1.maskConfig)(config), null, 2));
86
106
  });
87
- // ---------------------------------------------------------------------------
88
- // health
89
- // ---------------------------------------------------------------------------
90
107
  program
91
108
  .command("health")
92
109
  .description("Call the API health endpoint")
@@ -95,35 +112,19 @@ program
95
112
  .action(async (opts) => {
96
113
  let config = (0, cli_config_1.loadCliConfig)(node_path_1.default.resolve(opts.dir));
97
114
  if (opts.url) {
98
- if (config) {
99
- config = { ...config, baseUrl: opts.url };
100
- }
101
- else {
102
- config = { baseUrl: opts.url };
103
- }
115
+ config = config ? { ...config, baseUrl: opts.url } : { baseUrl: opts.url };
104
116
  }
105
117
  if (!config?.baseUrl) {
106
118
  console.error("Set HIVEMIND_BASE_URL or use --url <url>.");
107
119
  process.exit(1);
108
120
  }
109
- const client = new client_1.HivemindClient(config);
110
121
  try {
111
- const result = await client.health();
112
- console.log(JSON.stringify(result, null, 2));
122
+ console.log(JSON.stringify(await new client_1.HivemindClient(config).health(), null, 2));
113
123
  }
114
124
  catch (err) {
115
- if (err instanceof client_1.HivemindError) {
116
- console.error("Health check failed:", err.statusCode, err.detail);
117
- }
118
- else {
119
- console.error("Health check failed:", err);
120
- }
121
- process.exit(1);
125
+ exitWithError("Health check failed", err);
122
126
  }
123
127
  });
124
- // ---------------------------------------------------------------------------
125
- // helper
126
- // ---------------------------------------------------------------------------
127
128
  const helper = program
128
129
  .command("helper")
129
130
  .description("Helper utilities for config and connection");
@@ -139,189 +140,222 @@ helper
139
140
  process.exit(1);
140
141
  }
141
142
  console.log("Config: baseUrl =", config.baseUrl, "apiKey =", config.apiKey ? "[set]" : "[not set]");
142
- if (!opts.skipPing) {
143
- const client = new client_1.HivemindClient(config);
144
- try {
145
- const result = await client.health();
146
- console.log("Connection OK:", result.service, result.status);
147
- }
148
- catch (err) {
149
- console.error("Connection failed:", err instanceof Error ? err.message : err);
150
- process.exit(1);
151
- }
152
- }
153
- else {
143
+ if (opts.skipPing) {
154
144
  console.log("Skipped connection test (--skip-ping)");
145
+ return;
146
+ }
147
+ try {
148
+ const result = await new client_1.HivemindClient(config).health();
149
+ console.log("Connection OK:", result.service, result.status);
150
+ }
151
+ catch (err) {
152
+ exitWithError("Connection failed", err);
155
153
  }
156
154
  });
157
155
  helper
158
156
  .command("env")
159
157
  .description("Print env var template for copy-paste")
160
158
  .action(() => {
161
- const lines = [
159
+ console.log([
162
160
  "export HIVEMIND_BASE_URL=https://your-api-url.com",
163
- "export HIVEMIND_API_KEY=vtx_org_xxx",
161
+ "export HIVEMIND_API_KEY=vtx_xxx",
164
162
  "# export HIVEMIND_ADMIN_KEY=your-admin-key",
165
163
  "# export HIVEMIND_INSECURE=false",
166
- ];
167
- console.log(lines.join("\n"));
164
+ ].join("\n"));
168
165
  });
169
- // ---------------------------------------------------------------------------
170
- // query (quick RAG query from CLI)
171
- // ---------------------------------------------------------------------------
172
166
  program
173
- .command("query <org_id> <question>")
174
- .description("Run a RAG query (requires API key)")
167
+ .command("search <query>")
168
+ .description("Run source discovery search with the configured API key")
175
169
  .option("-d, --dir <path>", "Directory for config", process.cwd())
176
- .action(async (orgId, question, opts) => {
170
+ .option("-t, --type <type>", "Optional search type hint")
171
+ .option("-n, --num <num>", "Max results to return", "10")
172
+ .action(async (query, opts) => {
177
173
  const config = (0, cli_config_1.loadCliConfig)(node_path_1.default.resolve(opts.dir));
178
- if (!config?.baseUrl) {
179
- console.error("No config. Set HIVEMIND_BASE_URL and HIVEMIND_API_KEY for query.");
180
- process.exit(1);
181
- }
182
- if (!config.apiKey) {
183
- console.error("HIVEMIND_API_KEY required for query.");
174
+ if (!config?.baseUrl || !config.apiKey) {
175
+ console.error("Set HIVEMIND_BASE_URL and HIVEMIND_API_KEY for search.");
184
176
  process.exit(1);
185
177
  }
186
- const client = new client_1.HivemindClient(config);
187
178
  try {
188
- const result = await client.query(orgId, { query: question });
189
- console.log(result.answer ?? JSON.stringify(result, null, 2));
179
+ const result = await new client_1.HivemindClient(config).search({
180
+ query,
181
+ type: opts.type,
182
+ num: parseInt(opts.num, 10),
183
+ });
184
+ console.log(JSON.stringify(result, null, 2));
190
185
  }
191
186
  catch (err) {
192
- if (err instanceof client_1.HivemindError) {
193
- console.error("Query failed:", err.statusCode, err.detail);
194
- }
195
- else {
196
- console.error("Query failed:", err);
197
- }
198
- process.exit(1);
187
+ exitWithError("Search failed", err);
199
188
  }
200
189
  });
201
- // ---------------------------------------------------------------------------
202
- // search
203
- // ---------------------------------------------------------------------------
204
190
  program
205
- .command("search <org_id> <query>")
206
- .description("Run source discovery search (requires API key)")
191
+ .command("api-key:issue [name]")
192
+ .description("Issue a new API key scope (admin key required)")
207
193
  .option("-d, --dir <path>", "Directory for config", process.cwd())
208
- .option("-t, --type <type>", "Optional search type hint (news, images, videos, shopping)")
209
- .option("-n, --num <num>", "Max results to return", "10")
210
- .action(async (orgId, query, opts) => {
194
+ .option("-s, --settings <json>", "Optional JSON settings payload", "{}")
195
+ .action(async (name, opts) => {
211
196
  const config = (0, cli_config_1.loadCliConfig)(node_path_1.default.resolve(opts.dir));
212
- if (!config?.baseUrl) {
213
- console.error("No config. Set HIVEMIND_BASE_URL and HIVEMIND_API_KEY for search.");
197
+ if (!config?.baseUrl || !config.adminKey) {
198
+ console.error("Set HIVEMIND_BASE_URL and HIVEMIND_ADMIN_KEY.");
214
199
  process.exit(1);
215
200
  }
216
- if (!config.apiKey) {
217
- console.error("HIVEMIND_API_KEY required for search.");
201
+ let settings = {};
202
+ try {
203
+ settings = JSON.parse(opts.settings);
204
+ }
205
+ catch {
206
+ console.error("settings must be valid JSON.");
218
207
  process.exit(1);
219
208
  }
220
- const client = new client_1.HivemindClient(config);
221
209
  try {
222
- const result = await client.search(orgId, {
223
- query,
224
- type: opts.type,
225
- num: parseInt(opts.num, 10),
226
- });
227
- console.log(JSON.stringify(result, null, 2));
210
+ const result = await new client_1.HivemindClient(config).issueApiKey({ name, settings });
211
+ console.log("API key issued.");
212
+ console.log("API Key (save securely):", result.api_key);
213
+ console.log(JSON.stringify(result.scope, null, 2));
228
214
  }
229
215
  catch (err) {
230
- if (err instanceof client_1.HivemindError) {
231
- console.error("Search failed:", err.statusCode, err.detail);
232
- }
233
- else {
234
- console.error("Search failed:", err);
235
- }
236
- process.exit(1);
216
+ exitWithError("API key issue failed", err);
237
217
  }
238
218
  });
239
- // ---------------------------------------------------------------------------
240
- // org (admin: create org from CLI)
241
- // ---------------------------------------------------------------------------
242
219
  program
243
- .command("org:create <org_id> <name>")
244
- .description("Create an organization (admin key required)")
220
+ .command("api-key:scope")
221
+ .description("Get the current API key scope")
245
222
  .option("-d, --dir <path>", "Directory for config", process.cwd())
246
- .option("-t, --tier <tier>", "Tier: free | standard | premium | enterprise", "standard")
247
- .action(async (orgId, name, opts) => {
223
+ .action(async (opts) => {
248
224
  const config = (0, cli_config_1.loadCliConfig)(node_path_1.default.resolve(opts.dir));
249
- if (!config?.baseUrl || !config.adminKey) {
250
- console.error("Set HIVEMIND_BASE_URL and HIVEMIND_ADMIN_KEY (or adminKey in .hivemindrc.json).");
225
+ if (!config?.baseUrl || !config.apiKey) {
226
+ console.error("Set HIVEMIND_BASE_URL and HIVEMIND_API_KEY.");
251
227
  process.exit(1);
252
228
  }
253
- const client = new client_1.HivemindClient(config);
254
229
  try {
255
- const result = await client.createOrganization({
256
- org_id: orgId,
257
- name,
258
- tier: opts.tier,
259
- });
260
- console.log(result.created ? "Organization created." : "Organization already exists.");
261
- if (result.api_key) {
262
- console.log("API Key (save securely):", result.api_key);
263
- }
264
- console.log(JSON.stringify(result.organization, null, 2));
230
+ console.log(JSON.stringify(await new client_1.HivemindClient(config).getCurrentScope(), null, 2));
265
231
  }
266
232
  catch (err) {
267
- if (err instanceof client_1.HivemindError) {
268
- console.error("Create failed:", err.statusCode, err.detail);
269
- }
270
- else {
271
- console.error("Create failed:", err);
272
- }
233
+ exitWithError("API key scope failed", err);
234
+ }
235
+ });
236
+ program
237
+ .command("api-key:rotate")
238
+ .description("Rotate the current API key")
239
+ .option("-d, --dir <path>", "Directory for config", process.cwd())
240
+ .action(async (opts) => {
241
+ const config = (0, cli_config_1.loadCliConfig)(node_path_1.default.resolve(opts.dir));
242
+ if (!config?.baseUrl || !config.apiKey) {
243
+ console.error("Set HIVEMIND_BASE_URL and HIVEMIND_API_KEY.");
273
244
  process.exit(1);
274
245
  }
246
+ try {
247
+ console.log(JSON.stringify(await new client_1.HivemindClient(config).rotateApiKey(), null, 2));
248
+ }
249
+ catch (err) {
250
+ exitWithError("API key rotate failed", err);
251
+ }
275
252
  });
276
- // ---------------------------------------------------------------------------
277
- // music
278
- // ---------------------------------------------------------------------------
279
253
  program
280
- .command("music <org_id> <genre> <mood>")
281
- .description("Generate music (requires API key)")
254
+ .command("music <genre> <mood>")
255
+ .description("Generate music with the configured API key")
282
256
  .option("-d, --dir <path>", "Directory for config", process.cwd())
283
257
  .option("--duration <seconds>", "Duration in seconds", "30")
284
258
  .option("--wait", "Wait for the async music job to complete")
285
259
  .option("--timeout <ms>", "Max wait time in ms when using --wait", "300000")
286
- .action(async (orgId, genre, mood, opts) => {
260
+ .action(async (genre, mood, opts) => {
287
261
  const config = (0, cli_config_1.loadCliConfig)(node_path_1.default.resolve(opts.dir));
288
- if (!config?.baseUrl) {
289
- console.error("No config. Set HIVEMIND_BASE_URL and HIVEMIND_API_KEY for music generation.");
290
- process.exit(1);
291
- }
292
- if (!config.apiKey) {
293
- console.error("HIVEMIND_API_KEY required for music generation.");
262
+ if (!config?.baseUrl || !config.apiKey) {
263
+ console.error("Set HIVEMIND_BASE_URL and HIVEMIND_API_KEY for music generation.");
294
264
  process.exit(1);
295
265
  }
296
- const client = new client_1.HivemindClient(config);
297
266
  try {
298
- const job = await client.generateMusic(orgId, {
267
+ const client = new client_1.HivemindClient(config);
268
+ const job = await client.generateMusic({
299
269
  genre,
300
270
  mood,
301
271
  duration: parseInt(opts.duration, 10),
302
272
  });
303
273
  if (opts.wait) {
304
- const result = await client.waitForJob(orgId, job.job_id, 2000, parseInt(opts.timeout, 10));
305
- console.log(JSON.stringify(result, null, 2));
274
+ console.log(JSON.stringify(await client.waitForJob(job.job_id, 2000, parseInt(opts.timeout, 10)), null, 2));
306
275
  }
307
276
  else {
308
277
  console.log("Job ID:", job.job_id, "Status:", job.status);
309
- console.log("Check: hivemind music", orgId, genre, mood, "--wait");
278
+ console.log("Check: hivemind music", genre, mood, "--wait");
310
279
  }
311
280
  }
312
281
  catch (err) {
313
- if (err instanceof client_1.HivemindError) {
314
- console.error("Music generation failed:", err.statusCode, err.detail);
315
- }
316
- else {
317
- console.error("Music generation failed:", err);
318
- }
282
+ exitWithError("Music generation failed", err);
283
+ }
284
+ });
285
+ program
286
+ .command("social <prompt>")
287
+ .description("Generate social content variants for X, LinkedIn, Facebook, Instagram, TikTok, and YouTube")
288
+ .option("-d, --dir <path>", "Directory for config", process.cwd())
289
+ .option("--platforms <items>", "Comma-separated platforms", "x,linkedin")
290
+ .option("--objective <goal>", "Content objective", "engagement")
291
+ .option("--audience <text>", "Target audience")
292
+ .option("--brand <name>", "Brand or product name")
293
+ .option("--tone <tone>", "Tone", "professional")
294
+ .option("--style <style>", "Writing style", "conversational")
295
+ .option("--length <size>", "Length", "short")
296
+ .option("--cta <text>", "Call to action")
297
+ .option("--keyword <text>", "Primary keyword")
298
+ .option("--secondary <items>", "Comma-separated secondary keywords")
299
+ .option("--hashtags <items>", "Comma-separated preferred hashtags")
300
+ .option("--hashtag-count <num>", "Requested hashtag count", "3")
301
+ .option("--emojis", "Allow emojis in the output")
302
+ .option("--emoji-density <density>", "Emoji density when emojis are enabled", "none")
303
+ .option("--variations <num>", "Variants per platform", "1")
304
+ .option("--language <code>", "Language code or label", "en")
305
+ .option("--script", "Include a script block for video-first platforms")
306
+ .option("--must-include <items>", "Comma-separated required phrases")
307
+ .option("--avoid <items>", "Comma-separated avoided terms")
308
+ .option("--compliance <items>", "Comma-separated compliance notes")
309
+ .option("--url <url>", "Landing page URL")
310
+ .option("--no-title", "Do not include a title field")
311
+ .option("--no-hook", "Do not include a hook field")
312
+ .option("--no-short-description", "Do not include a short description field")
313
+ .action(async (prompt, opts) => {
314
+ const config = (0, cli_config_1.loadCliConfig)(node_path_1.default.resolve(opts.dir));
315
+ if (!config?.baseUrl || !config.apiKey) {
316
+ console.error("Set HIVEMIND_BASE_URL and HIVEMIND_API_KEY for social generation.");
317
+ process.exit(1);
318
+ }
319
+ const platforms = parseCsvList(opts.platforms).map((item) => item.toLowerCase());
320
+ if (platforms.length === 0) {
321
+ console.error("Provide at least one platform via --platforms.");
319
322
  process.exit(1);
320
323
  }
324
+ try {
325
+ const result = await new client_1.HivemindClient(config).generateSocialContent({
326
+ prompt,
327
+ platforms: platforms,
328
+ objective: opts.objective,
329
+ target_audience: opts.audience,
330
+ brand_name: opts.brand,
331
+ tone: opts.tone,
332
+ writing_style: opts.style,
333
+ length: opts.length,
334
+ call_to_action: opts.cta,
335
+ primary_keyword: opts.keyword,
336
+ secondary_keywords: parseCsvList(opts.secondary),
337
+ include_hashtags: true,
338
+ hashtags: parseCsvList(opts.hashtags).map((item) => item.replace(/^#/, "")),
339
+ hashtag_count: parseInt(opts.hashtagCount, 10),
340
+ include_emojis: Boolean(opts.emojis),
341
+ emoji_density: opts.emojiDensity,
342
+ variation_count: parseInt(opts.variations, 10),
343
+ include_title: opts.title,
344
+ include_hook: opts.hook,
345
+ include_short_description: opts.shortDescription,
346
+ include_script: Boolean(opts.script),
347
+ must_include: parseCsvList(opts.mustInclude),
348
+ avoid_terms: parseCsvList(opts.avoid),
349
+ compliance_notes: parseCsvList(opts.compliance),
350
+ landing_page_url: opts.url,
351
+ language: opts.language,
352
+ });
353
+ console.log(JSON.stringify(result, null, 2));
354
+ }
355
+ catch (err) {
356
+ exitWithError("Social generation failed", err);
357
+ }
321
358
  });
322
- // ---------------------------------------------------------------------------
323
- // scrape
324
- // ---------------------------------------------------------------------------
325
359
  program
326
360
  .command("scrape <urls...>")
327
361
  .description("Submit URLs to scrape and optionally wait for results")
@@ -331,14 +365,13 @@ program
331
365
  .action(async (urls, opts) => {
332
366
  const config = (0, cli_config_1.loadCliConfig)(node_path_1.default.resolve(opts.dir));
333
367
  if (!config?.baseUrl) {
334
- console.error("No config. Set HIVEMIND_BASE_URL.");
368
+ console.error("Set HIVEMIND_BASE_URL.");
335
369
  process.exit(1);
336
370
  }
337
- const client = new client_1.HivemindClient(config);
338
371
  try {
372
+ const client = new client_1.HivemindClient(config);
339
373
  if (opts.wait) {
340
- const result = await client.scrapeAndWait(urls, 2000, parseInt(opts.timeout, 10));
341
- console.log(JSON.stringify(result, null, 2));
374
+ console.log(JSON.stringify(await client.scrapeAndWait(urls, 2000, parseInt(opts.timeout, 10)), null, 2));
342
375
  }
343
376
  else {
344
377
  const result = await client.scrape({ urls });
@@ -347,13 +380,7 @@ program
347
380
  }
348
381
  }
349
382
  catch (err) {
350
- if (err instanceof client_1.HivemindError) {
351
- console.error("Scrape failed:", err.statusCode, err.detail);
352
- }
353
- else {
354
- console.error("Scrape failed:", err);
355
- }
356
- process.exit(1);
383
+ exitWithError("Scrape failed", err);
357
384
  }
358
385
  });
359
386
  program
@@ -363,58 +390,19 @@ program
363
390
  .action(async (taskId, opts) => {
364
391
  const config = (0, cli_config_1.loadCliConfig)(node_path_1.default.resolve(opts.dir));
365
392
  if (!config?.baseUrl) {
366
- console.error("No config. Set HIVEMIND_BASE_URL.");
393
+ console.error("Set HIVEMIND_BASE_URL.");
367
394
  process.exit(1);
368
395
  }
369
- const client = new client_1.HivemindClient(config);
370
396
  try {
371
- const result = await client.getScrapeStatus(taskId);
372
- console.log(JSON.stringify(result, null, 2));
397
+ console.log(JSON.stringify(await new client_1.HivemindClient(config).getScrapeStatus(taskId), null, 2));
373
398
  }
374
399
  catch (err) {
375
- if (err instanceof client_1.HivemindError) {
376
- console.error("Status failed:", err.statusCode, err.detail);
377
- }
378
- else {
379
- console.error("Status failed:", err);
380
- }
381
- process.exit(1);
382
- }
383
- });
384
- // ---------------------------------------------------------------------------
385
- // content creator schedules
386
- // ---------------------------------------------------------------------------
387
- program
388
- .command("schedule:run-due")
389
- .description("Manually run due Content Creator schedules (admin key required)")
390
- .option("-d, --dir <path>", "Directory for config", process.cwd())
391
- .action(async (opts) => {
392
- const config = (0, cli_config_1.loadCliConfig)(node_path_1.default.resolve(opts.dir));
393
- if (!config?.baseUrl || !config.adminKey) {
394
- console.error("Set HIVEMIND_BASE_URL and HIVEMIND_ADMIN_KEY for schedule:run-due.");
395
- process.exit(1);
396
- }
397
- const client = new client_1.HivemindClient(config);
398
- try {
399
- const result = await client.runDueSchedules();
400
- console.log(JSON.stringify(result, null, 2));
401
- }
402
- catch (err) {
403
- if (err instanceof client_1.HivemindError) {
404
- console.error("Run due schedules failed:", err.statusCode, err.detail);
405
- }
406
- else {
407
- console.error("Run due schedules failed:", err);
408
- }
409
- process.exit(1);
400
+ exitWithError("Status failed", err);
410
401
  }
411
402
  });
412
- // ---------------------------------------------------------------------------
413
- // start-web (interactive dashboard)
414
- // ---------------------------------------------------------------------------
415
403
  program
416
404
  .command("start-web")
417
- .description("Launch interactive web dashboard for all API functions")
405
+ .description("Launch interactive web dashboard for the API-key-scoped SDK")
418
406
  .option("-d, --dir <path>", "Directory for config", process.cwd())
419
407
  .option("-p, --port <port>", "Port to listen on", "3333")
420
408
  .option("--no-open", "Do not auto-open browser")
@@ -427,7 +415,6 @@ program
427
415
  apiKey: config?.apiKey ?? "",
428
416
  adminKey: config?.adminKey ?? "",
429
417
  webhookSecret: config?.webhookSecret ?? "",
430
- employeeId: config?.employeeId ?? "",
431
418
  open: opts.open,
432
419
  });
433
420
  });