@neta-art/cohub 8.17.0 → 8.19.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/README.md CHANGED
@@ -240,11 +240,13 @@ These runtime-only APIs are available **exclusively inside a published App**:
240
240
  null); `invocation.spaceId` is the same Space for compatibility.
241
241
  Returns `null` outside an App runtime. `client.app.onContextChanged()` pushes
242
242
  fresh state.
243
- - `client.auth.request({ scopes, reason, spaceId?, alwaysAsk? })` — ensures
244
- the app holds these scopes; silent when a grant covers them, consent dialog
245
- otherwise.
246
- - `client.auth.requestSpace({ scopes, reason })` — one consent: the viewer
247
- picks a Space and grants the scopes on it.
243
+ - `client.auth.authorize({ target, scopes, reason?, alwaysAsk?, fallback? })`
244
+ — requests consent for an account, a specific Space, or a viewer-picked
245
+ Space. Silent when a grant covers the scopes. Returns the actual target,
246
+ how it was resolved, and the authoritative grant; see the
247
+ [authorization contract](../../docs/app-authorization.md).
248
+ `client.auth.request()` / `requestSpace()` / `requestCreateSpace()` remain
249
+ available for older Apps.
248
250
  - `client.context().permissions.viewerGrants` — render the viewer's current
249
251
  per-space grants. Grant management uses an account-authenticated client or
250
252
  the CLI; an App session cannot manage its own grants.
@@ -260,19 +262,25 @@ These runtime-only APIs are available **exclusively inside a published App**:
260
262
  const client = createCohubClient({ env: "prod" });
261
263
 
262
264
  const ctx = await client.context();
263
- if (!ctx?.space?.id) throw new Error("Not inside a published app.");
265
+ if (!ctx?.app?.id) throw new Error("Not inside a published app.");
264
266
 
265
267
  const sourceSessionId = ctx.invocation?.sessionId ?? null;
266
268
  // `shell.space` is the current Cohub location. `app.homeSpace` is the App's
267
269
  // owning Space. A new chat background also has `invocation.spaceId`.
268
- const spaceId = ctx.shell?.space?.id ?? ctx.invocation?.spaceId ?? ctx.app.homeSpace?.id ?? ctx.space.id;
270
+ const spaceId = ctx.shell?.space?.id ?? ctx.invocation?.spaceId ?? ctx.app.homeSpace?.id;
269
271
  const space = client.space(spaceId);
270
272
 
271
273
  // Request viewer grants from a user gesture (button click)
272
- await client.auth.request({
274
+ const consent = await client.auth.authorize({
275
+ target: { kind: "space", spaceId },
273
276
  scopes: ["session.prompt.fullaccess", "generation.create"],
274
277
  reason: "This app sends prompts and generates images.",
275
278
  });
279
+ if (consent.status !== "granted") return;
280
+ // Act on the granted target, which may differ from the request.
281
+ const activeSpace = consent.target.kind === "space"
282
+ ? client.space(consent.target.spaceId)
283
+ : space;
276
284
  ```
277
285
 
278
286
  ### The permission model (critical)
@@ -297,7 +305,7 @@ lets you send a prompt but does NOT let you read the reply — that needs
297
305
  polling its result needs `taskrun.view`.
298
306
 
299
307
  Render grant state from `ctx.permissions.viewerGrants`; act through
300
- `auth.request` (silent when covered). `allowedViewerScopes` is deprecated —
308
+ `auth.authorize()` (silent when covered). `allowedViewerScopes` is deprecated —
301
309
  viewer grants are no longer gated by the app configuration.
302
310
 
303
311
  ### Realtime rooms