@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 +17 -9
- package/dist/chunks/environment.d.ts +525 -5
- package/dist/chunks/environment.js +1 -0
- package/dist/chunks/http.d.ts +51 -2
- package/dist/chunks/http.js +975 -943
- package/dist/chunks/websocket.d.ts +1 -1
- package/dist/http.d.ts +2 -2
- package/dist/index.d.ts +35 -4
- package/dist/index.js +834 -30
- package/dist/protocol/dist/app-authorization.d.ts +1 -0
- package/dist/protocol/dist/index.d.ts +4 -0
- package/dist/protocol/dist/model/session.d.ts +1 -0
- package/dist/protocol/dist/model/turn.d.ts +1 -0
- package/dist/protocol/dist/realtime/types.d.ts +2 -0
- package/dist/protocol/dist/runtime/archive.d.ts +1 -0
- package/dist/protocol/dist/runtime/context.d.ts +1 -0
- package/dist/protocol/dist/runtime/index.d.ts +3 -0
- package/dist/types.d.ts +1 -0
- package/docs/app-runtime-guide.md +145 -92
- package/package.json +1 -1
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.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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?.
|
|
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
|
|
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.
|
|
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.
|
|
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
|