@caphub/cli 0.1.5 → 0.1.6

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 (2) hide show
  1. package/bin/caphub.js +86 -8
  2. package/package.json +1 -1
package/bin/caphub.js CHANGED
@@ -256,21 +256,99 @@ function printCapabilities(payload) {
256
256
  }
257
257
 
258
258
  function printCapabilityHelp(payload) {
259
+ const title = payload.capability === "search"
260
+ ? "caphub web search"
261
+ : payload.capability === "search-ideas"
262
+ ? "caphub search ideas"
263
+ : `caphub ${payload.capability}`;
264
+ const requestExample = payload.capability === "search"
265
+ ? `caphub search '{"queries":["site:github.com awesome ai agents","awesome lists agents","codex awesome lists"]}'`
266
+ : `caphub ${payload.capability} '${JSON.stringify(payload.input_contract)}'`;
267
+ const configuredRequestExample = payload.capability === "search"
268
+ ? `caphub search '{"queries":[{"q":"EV discounts Thailand","country":"th","language":"en","from_time":"week"}]}'`
269
+ : null;
270
+ const responseShape = payload.capability === "search"
271
+ ? {
272
+ queries: [
273
+ {
274
+ q: "string",
275
+ country: "optional string",
276
+ language: "optional string",
277
+ from_time: "optional string",
278
+ num: "number",
279
+ },
280
+ ],
281
+ results: [
282
+ {
283
+ query: "string",
284
+ items: [
285
+ {
286
+ title: "string",
287
+ link: "string",
288
+ snippet: "string",
289
+ date: "optional string",
290
+ },
291
+ ],
292
+ },
293
+ ],
294
+ total_usage: {
295
+ total_credits_used: "number",
296
+ credits_remaining: "number",
297
+ },
298
+ billing: {
299
+ credits_used: "number",
300
+ },
301
+ }
302
+ : payload.output_contract;
303
+ const parameters = payload.parameters || {};
304
+ const searchParameterOrder = [
305
+ "queries",
306
+ "queries[] as string",
307
+ "queries[] as object",
308
+ "queries[].q",
309
+ "queries[].country",
310
+ "queries[].language",
311
+ "queries[].from_time",
312
+ "queries[].num",
313
+ "max_queries",
314
+ "include_meta",
315
+ "include_result_meta",
316
+ ];
317
+ const orderedParameterEntries = payload.capability === "search"
318
+ ? [
319
+ ...searchParameterOrder
320
+ .filter((name) => Object.prototype.hasOwnProperty.call(parameters, name))
321
+ .map((name) => [name, parameters[name]]),
322
+ ...Object.entries(parameters).filter(([name]) => !searchParameterOrder.includes(name)),
323
+ ]
324
+ : Object.entries(parameters);
325
+ const parameterLines = orderedParameterEntries.map(([name, description]) => `- ${name}: ${description}`);
259
326
  const lines = [
260
- payload.capability,
327
+ title,
328
+ "-".repeat(title.length),
329
+ "",
330
+ `description: ${payload.purpose}`,
261
331
  "",
262
- `purpose: ${payload.purpose}`,
263
332
  `endpoint: ${payload.endpoint}`,
264
333
  `method: ${payload.method}`,
265
334
  payload.credits ? `credits: ${payload.credits}` : null,
266
335
  payload.limits?.max_queries_per_request ? `limits: max ${payload.limits.max_queries_per_request} queries per request` : null,
267
- `auth: ${payload.auth?.env || "CAPHUB_API_KEY"} or ${CONFIG_PATH}`,
268
336
  "",
269
- "input:",
270
- JSON.stringify(payload.input_contract, null, 2),
337
+ "request:",
338
+ "format:",
339
+ `caphub ${payload.capability} '<request>'`,
340
+ "",
341
+ "default request form:",
342
+ requestExample,
343
+ configuredRequestExample ? "" : null,
344
+ configuredRequestExample ? "configured request form:" : null,
345
+ configuredRequestExample,
346
+ parameterLines.length ? "" : null,
347
+ parameterLines.length ? "configuration:" : null,
348
+ ...parameterLines,
271
349
  "",
272
- "output:",
273
- JSON.stringify(payload.output_contract, null, 2),
350
+ "response:",
351
+ JSON.stringify(responseShape, null, 2),
274
352
  payload.notes_for_agents?.length ? "" : null,
275
353
  payload.notes_for_agents?.length ? "notes:" : null,
276
354
  ...(payload.notes_for_agents || []).map((note) => `- ${note}`),
@@ -280,7 +358,7 @@ function printCapabilityHelp(payload) {
280
358
  "- auth invalid: generate a new key in https://caphub.io/dashboard/",
281
359
  "- low credits: top up in https://caphub.io/dashboard/",
282
360
  `- bad payload: caphub help ${payload.capability}`,
283
- ].filter(Boolean);
361
+ ].filter((line) => line !== null && line !== undefined);
284
362
  process.stdout.write(`${lines.join("\n")}\n`);
285
363
  }
286
364
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caphub/cli",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Root CLI for Caphub agent capabilities",
5
5
  "type": "module",
6
6
  "bin": {