@neta-art/cohub 2.7.1 → 2.8.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/chunks/http.d.ts +73 -1433
- package/dist/chunks/http.js +89 -110
- package/dist/chunks/transport.js +143 -0
- package/dist/chunks/websocket.d.ts +1593 -8
- package/dist/chunks/websocket.js +818 -0
- package/dist/http.d.ts +3 -3
- package/dist/http.js +2 -1
- package/dist/index.d.ts +21 -3
- package/dist/index.js +103 -27
- package/dist/websocket.js +1 -780
- package/docs/work-runtime-guide.md +35 -3
- package/package.json +1 -1
- package/dist/chunks/types.js +0 -37
|
@@ -97,9 +97,11 @@ a direct static-asset URL not wrapped in the Cohub iframe. The SDK opens a
|
|
|
97
97
|
`${brokerOrigin}/work-auth?work=${workId}`.
|
|
98
98
|
|
|
99
99
|
> **Broker mode requires configuration.** You must pass `work: { brokerOrigin,
|
|
100
|
-
> workId }`
|
|
101
|
-
>
|
|
102
|
-
>
|
|
100
|
+
> workId }` — or `work: { brokerOrigin, ownerUsername, spaceSlug, workSlug }`
|
|
101
|
+
> when the workId isn't known yet — to `createCohubClient` for broker mode to
|
|
102
|
+
> activate. Without it, a standalone page gets `ParentBridgeTransport` which
|
|
103
|
+
> has no parent to talk to, so `context()` returns `null`. See
|
|
104
|
+
> [Initialization recipe](#4-initialization-recipe).
|
|
103
105
|
|
|
104
106
|
### Detecting the mode at runtime
|
|
105
107
|
|
|
@@ -308,6 +310,36 @@ When inside the Cohub iframe, the SDK auto-detects bridge mode and ignores
|
|
|
308
310
|
broker config. When standalone, it uses broker mode. **One codebase, both
|
|
309
311
|
deployments.**
|
|
310
312
|
|
|
313
|
+
#### Broker mode without a pre-known workId
|
|
314
|
+
|
|
315
|
+
The `workId` is only generated at publish time, so you often cannot hardcode
|
|
316
|
+
it while writing the Work. In standalone deployments you can omit `workId` and
|
|
317
|
+
instead pass the Work's public **slug triple**. The SDK resolves the workId at
|
|
318
|
+
runtime via the public `works.getBySlug` API (anonymous, no auth required),
|
|
319
|
+
caches it, and starts broker mode with it.
|
|
320
|
+
|
|
321
|
+
All three values are known before publishing:
|
|
322
|
+
|
|
323
|
+
- `workSlug` — the slug you chose when creating the Work.
|
|
324
|
+
- `ownerUsername` — the space owner's username (`cohub auth whoami`).
|
|
325
|
+
- `spaceSlug` — the space's slug (`cohub spaces get <spaceId>`).
|
|
326
|
+
|
|
327
|
+
```js
|
|
328
|
+
const client = createCohubClient({
|
|
329
|
+
env: isDevWork ? "dev" : "prod",
|
|
330
|
+
work: {
|
|
331
|
+
brokerOrigin: isDevWork ? "https://dev.cohub.run" : "https://cohub.run",
|
|
332
|
+
ownerUsername,
|
|
333
|
+
spaceSlug,
|
|
334
|
+
workSlug,
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
Either `workId` or the full slug triple is enough to activate broker mode. If
|
|
340
|
+
you pass both, the explicit `workId` wins and no lookup is performed. Inside
|
|
341
|
+
the Cohub iframe both are ignored (bridge mode).
|
|
342
|
+
|
|
311
343
|
### Standard initialization sequence
|
|
312
344
|
|
|
313
345
|
```js
|
package/package.json
CHANGED
package/dist/chunks/types.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
//#region ../protocol/src/realtime/types.ts
|
|
2
|
-
const WS_COMPACT_STREAM_CAPABILITY = "session.compact_stream.v1";
|
|
3
|
-
const WS_ROOM_SUBSCRIPTION_CAPABILITY = "realtime.rooms.v1";
|
|
4
|
-
const getRealtimeSpaceRoom = (spaceId) => `space:${spaceId}`;
|
|
5
|
-
const parseRealtimeRoom = (room) => {
|
|
6
|
-
const trimmed = room.trim();
|
|
7
|
-
const separatorIndex = trimmed.indexOf(":");
|
|
8
|
-
if (separatorIndex <= 0) return null;
|
|
9
|
-
const kind = trimmed.slice(0, separatorIndex);
|
|
10
|
-
const id = trimmed.slice(separatorIndex + 1).trim();
|
|
11
|
-
if (!id) return null;
|
|
12
|
-
if (kind !== "space" && kind !== "user") return null;
|
|
13
|
-
return {
|
|
14
|
-
kind,
|
|
15
|
-
id
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
const normalizeRealtimeRooms = (rooms) => {
|
|
19
|
-
const normalized = /* @__PURE__ */ new Set();
|
|
20
|
-
for (const room of rooms) {
|
|
21
|
-
const parsed = typeof room === "string" ? parseRealtimeRoom(room) : null;
|
|
22
|
-
if (!parsed) continue;
|
|
23
|
-
normalized.add(`${parsed.kind}:${parsed.id}`);
|
|
24
|
-
}
|
|
25
|
-
return [...normalized];
|
|
26
|
-
};
|
|
27
|
-
const getNonEmptyString = (value) => typeof value === "string" && value.trim() ? value : null;
|
|
28
|
-
const getSessionTurnPatchStreamKey = (input, options = {}) => {
|
|
29
|
-
const turnId = getNonEmptyString(input.turnId);
|
|
30
|
-
const messageKey = getNonEmptyString(input.messageId) ?? getNonEmptyString(input.sourceMessageId) ?? getNonEmptyString(input.anchorUserMessageId) ?? (typeof input.messageOrdinal === "number" && Number.isFinite(input.messageOrdinal) ? `ordinal:${input.messageOrdinal}` : null);
|
|
31
|
-
if (turnId && messageKey) return `${turnId}:${messageKey}`;
|
|
32
|
-
const streamKey = messageKey ?? turnId;
|
|
33
|
-
if (streamKey) return streamKey;
|
|
34
|
-
return options.includeSessionFallback ? getNonEmptyString(input.sessionId) : null;
|
|
35
|
-
};
|
|
36
|
-
//#endregion
|
|
37
|
-
export { normalizeRealtimeRooms as a, getSessionTurnPatchStreamKey as i, WS_ROOM_SUBSCRIPTION_CAPABILITY as n, getRealtimeSpaceRoom as r, WS_COMPACT_STREAM_CAPABILITY as t };
|