@neta-art/cohub-cli 6.5.0 → 6.6.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.
package/dist/client.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { CohubClient, CohubHttpClient } from "@neta-art/cohub";
2
2
  export declare function createClient(): CohubHttpClient;
3
+ export declare function createClientWithAccessToken(token: string): CohubHttpClient;
3
4
  export declare function createRealtimeClient(): CohubClient;
package/dist/client.js CHANGED
@@ -10,6 +10,9 @@ const clientOptions = () => ({
10
10
  export function createClient() {
11
11
  return new CohubHttpClient(clientOptions());
12
12
  }
13
+ export function createClientWithAccessToken(token) {
14
+ return new CohubHttpClient({ ...clientOptions(), getAccessToken: () => token });
15
+ }
13
16
  export function createRealtimeClient() {
14
17
  return new CohubClient(clientOptions());
15
18
  }
@@ -1,3 +1,4 @@
1
+ import { resolveExecutionAppId, } from "@neta-art/cohub";
1
2
  import { createClient } from "../client.js";
2
3
  import { error, handleHttp, json as outJson, jsonRequested, ok, table } from "../output.js";
3
4
  function collectOption(value, previous = []) {
@@ -9,6 +10,9 @@ function requireText(value, label, flag) {
9
10
  return text;
10
11
  return error(`Missing ${label}`, `Pass ${flag}.`);
11
12
  }
13
+ function requireAppId(value) {
14
+ return requireText(value ?? resolveExecutionAppId() ?? undefined, "app ID", "--app-id <id>");
15
+ }
12
16
  function requireList(values, label, flag) {
13
17
  const items = [...new Set((values ?? []).map((value) => value.trim()).filter(Boolean))];
14
18
  if (items.length > 0)
@@ -89,7 +93,7 @@ Examples:
89
93
  .option("--product-key <key>", "Product key", collectOption)
90
94
  .option("--json", "Output as JSON")
91
95
  .action(async (opts) => {
92
- const appId = requireText(opts.appId, "app ID", "--app-id <id>");
96
+ const appId = requireAppId(opts.appId);
93
97
  const productKeys = requireList(opts.productKey, "product key", "--product-key <key>");
94
98
  const client = createClient();
95
99
  try {
@@ -108,7 +112,7 @@ Examples:
108
112
  .option("--app-id <id>", "App ID")
109
113
  .option("--json", "Output as JSON")
110
114
  .action(async (opts) => {
111
- const appId = requireText(opts.appId, "app ID", "--app-id <id>");
115
+ const appId = requireAppId(opts.appId);
112
116
  const client = createClient();
113
117
  try {
114
118
  const result = await client.appCommerce.getEntitlements(appId);
@@ -132,7 +136,7 @@ Examples:
132
136
  .option("--reason <text>", "Reason for the consumption")
133
137
  .option("--json", "Output as JSON")
134
138
  .action(async (opts) => {
135
- const appId = requireText(opts.appId, "app ID", "--app-id <id>");
139
+ const appId = requireAppId(opts.appId);
136
140
  const amountText = requireText(opts.amount, "amount", "--amount <n>");
137
141
  const amount = Number.parseInt(amountText, 10);
138
142
  if (!Number.isSafeInteger(amount) || amount <= 0) {
@@ -172,7 +176,7 @@ Examples:
172
176
  .option("--product-key <key>", "Product key")
173
177
  .option("--json", "Output as JSON")
174
178
  .action(async (opts) => {
175
- const appId = requireText(opts.appId, "app ID", "--app-id <id>");
179
+ const appId = requireAppId(opts.appId);
176
180
  const productKey = requireText(opts.productKey, "product key", "--product-key <key>");
177
181
  const client = createClient();
178
182
  try {
@@ -210,7 +214,7 @@ Examples:
210
214
  .option("--order-id <id>", "Order ID")
211
215
  .option("--json", "Output as JSON")
212
216
  .action(async (opts) => {
213
- const appId = requireText(opts.appId, "app ID", "--app-id <id>");
217
+ const appId = requireAppId(opts.appId);
214
218
  const orderId = requireText(opts.orderId, "order ID", "--order-id <id>");
215
219
  const client = createClient();
216
220
  try {
@@ -1,5 +1,5 @@
1
1
  import { HttpError } from "@neta-art/cohub";
2
- import { createClient } from "../client.js";
2
+ import { createClient, createClientWithAccessToken } from "../client.js";
3
3
  import { error, handleHttp, json as outJson, jsonRequested, ok, table } from "../output.js";
4
4
  import { resolveSpace } from "../space.js";
5
5
  import { downloadApp } from "../app-download.js";
@@ -27,6 +27,16 @@ function parseJsonObject(value, name) {
27
27
  }
28
28
  return error(`Invalid ${name}`, `${name} must be a JSON object`);
29
29
  }
30
+ function parseJsonValue(value, name) {
31
+ if (!value)
32
+ return null;
33
+ try {
34
+ return JSON.parse(value);
35
+ }
36
+ catch {
37
+ return error(`Invalid ${name}`, `${name} must be valid JSON`);
38
+ }
39
+ }
30
40
  function compactObject(input) {
31
41
  return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== undefined));
32
42
  }
@@ -259,6 +269,32 @@ export function registerApps(program) {
259
269
  handleHttp(e);
260
270
  }
261
271
  });
272
+ const actionsCmd = appsCmd
273
+ .command("actions")
274
+ .description("Run published App Actions");
275
+ actionsCmd
276
+ .command("run <app> <action>")
277
+ .description("Run an App Action")
278
+ .option("--input <json>", "JSON input", "null")
279
+ .option("--json", "Output as JSON")
280
+ .action(async (appRef, action, opts) => {
281
+ const client = createClient();
282
+ try {
283
+ const ref = parseAppRef(appRef);
284
+ const detail = "id" in ref
285
+ ? await client.apps.getPublicById(ref.id)
286
+ : await client.apps.getBySlug(ref.username, ref.spaceSlug, ref.appSlug);
287
+ const session = await client.apps.createSession(detail.app.id);
288
+ const appClient = createClientWithAccessToken(session.token);
289
+ const result = await appClient.apps.runAction(detail.app.id, action, parseJsonValue(opts.input, "input"));
290
+ if (jsonRequested(opts))
291
+ return outJson(result);
292
+ ok(`App Action queued: ${result.taskRunId}`);
293
+ }
294
+ catch (e) {
295
+ handleHttp(e);
296
+ }
297
+ });
262
298
  appsCmd
263
299
  .command("resolve <appSlug>")
264
300
  .description("Resolve a published app by owner and space slug")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neta-art/cohub-cli",
3
- "version": "6.5.0",
3
+ "version": "6.6.0",
4
4
  "description": "CLI for Cohub — spaces, sessions, and agent collaboration.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -15,11 +15,11 @@
15
15
  "NOTICE"
16
16
  ],
17
17
  "dependencies": {
18
- "@neta-art/generation": "^0.1.23",
18
+ "@neta-art/generation": "^0.1.25",
19
19
  "commander": "^15.0.0",
20
20
  "pixi.js": "^8.20.1",
21
21
  "sharp": "^0.35.4",
22
- "@neta-art/cohub": "8.8.0"
22
+ "@neta-art/cohub": "8.9.0"
23
23
  },
24
24
  "publishConfig": {
25
25
  "access": "public"