@h-rig/collab-session-browser-plugin 0.0.6-alpha.158

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 ADDED
@@ -0,0 +1 @@
1
+ # @h-rig/collab-session-browser-plugin
@@ -0,0 +1,2 @@
1
+ export { COLLAB_SESSION_BROWSER_PLUGIN_NAME, collabSessionBrowserPlugin, createCollabSessionBrowserPlugin, } from "./plugin";
2
+ export { default } from "./plugin";
@@ -0,0 +1,88 @@
1
+ // @bun
2
+ // packages/collab-session-browser-plugin/src/plugin.ts
3
+ import { fileURLToPath } from "url";
4
+ import { definePlugin } from "@rig/core/config";
5
+ import { defineCapability } from "@rig/core/capability";
6
+ import {
7
+ COLLAB_SESSION_VIEWER_CAPABILITY
8
+ } from "@rig/contracts";
9
+ var COLLAB_SESSION_BROWSER_PLUGIN_NAME = "@rig/collab-session-browser-plugin";
10
+ var DEFAULT_RELAY_URL = "wss://where.rig-does.work";
11
+ var CollabSessionViewerCap = defineCapability(COLLAB_SESSION_VIEWER_CAPABILITY);
12
+ var LOCAL_HOSTNAMES = { localhost: true, "127.0.0.1": true, "::1": true, "[::1]": true };
13
+ function encodeBase64Url(bytes) {
14
+ return Buffer.from(bytes).toString("base64").replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
15
+ }
16
+ function normalizeRelayOrigin(relayUrl) {
17
+ let url;
18
+ try {
19
+ url = new URL(relayUrl);
20
+ } catch {
21
+ return { error: `Invalid relay URL: ${relayUrl}` };
22
+ }
23
+ let scheme;
24
+ switch (url.protocol) {
25
+ case "wss:":
26
+ case "https:":
27
+ scheme = "wss:";
28
+ break;
29
+ case "ws:":
30
+ case "http:":
31
+ scheme = "ws:";
32
+ break;
33
+ default:
34
+ return { error: `Unsupported relay URL scheme: ${url.protocol}` };
35
+ }
36
+ if (scheme === "ws:" && !LOCAL_HOSTNAMES[url.hostname]) {
37
+ return { error: "relay link must be wss:// (plain ws:// is only allowed for localhost)" };
38
+ }
39
+ const port = url.port ? `:${url.port}` : "";
40
+ return { origin: `${scheme}//${url.hostname}${port}` };
41
+ }
42
+ function formatCollabLink(relayUrl, roomId, key, writeToken) {
43
+ const normalized = normalizeRelayOrigin(relayUrl);
44
+ if ("error" in normalized)
45
+ throw new Error(normalized.error);
46
+ let secret = key;
47
+ if (writeToken) {
48
+ secret = new Uint8Array(key.byteLength + writeToken.byteLength);
49
+ secret.set(key, 0);
50
+ secret.set(writeToken, key.byteLength);
51
+ }
52
+ const keyText = encodeBase64Url(secret);
53
+ if (normalized.origin === DEFAULT_RELAY_URL)
54
+ return `${roomId}.${keyText}`;
55
+ const compact = normalized.origin.startsWith("wss://") ? normalized.origin.slice("wss://".length) : normalized.origin;
56
+ return `${compact}/r/${roomId}.${keyText}`;
57
+ }
58
+ var collabSessionBrowserPlugin = definePlugin({
59
+ name: COLLAB_SESSION_BROWSER_PLUGIN_NAME,
60
+ version: "0.0.0-alpha.1",
61
+ contributes: {
62
+ capabilities: [
63
+ CollabSessionViewerCap.provide(async () => {
64
+ return {
65
+ distDir() {
66
+ return fileURLToPath(new URL("../../collab-web/dist", import.meta.url));
67
+ },
68
+ formatViewerLink(input) {
69
+ return formatCollabLink(input.relayUrl, input.roomId, input.key, input.writeToken);
70
+ }
71
+ };
72
+ }, {
73
+ title: "Collab session browser viewer",
74
+ description: "Serve the collab-web live-session SPA (paste a roomId.key link \u2192 streaming transcript + tool cards + composer) and format shareable pi-wire viewer links."
75
+ })
76
+ ]
77
+ }
78
+ });
79
+ function createCollabSessionBrowserPlugin() {
80
+ return collabSessionBrowserPlugin;
81
+ }
82
+ var plugin_default = collabSessionBrowserPlugin;
83
+ export {
84
+ plugin_default as default,
85
+ createCollabSessionBrowserPlugin,
86
+ collabSessionBrowserPlugin,
87
+ COLLAB_SESSION_BROWSER_PLUGIN_NAME
88
+ };
@@ -0,0 +1,4 @@
1
+ export declare const COLLAB_SESSION_BROWSER_PLUGIN_NAME = "@rig/collab-session-browser-plugin";
2
+ export declare const collabSessionBrowserPlugin: import("@rig/core/config").RigPlugin;
3
+ export declare function createCollabSessionBrowserPlugin(): import("@rig/core/config").RigPlugin;
4
+ export default collabSessionBrowserPlugin;
@@ -0,0 +1,88 @@
1
+ // @bun
2
+ // packages/collab-session-browser-plugin/src/plugin.ts
3
+ import { fileURLToPath } from "url";
4
+ import { definePlugin } from "@rig/core/config";
5
+ import { defineCapability } from "@rig/core/capability";
6
+ import {
7
+ COLLAB_SESSION_VIEWER_CAPABILITY
8
+ } from "@rig/contracts";
9
+ var COLLAB_SESSION_BROWSER_PLUGIN_NAME = "@rig/collab-session-browser-plugin";
10
+ var DEFAULT_RELAY_URL = "wss://where.rig-does.work";
11
+ var CollabSessionViewerCap = defineCapability(COLLAB_SESSION_VIEWER_CAPABILITY);
12
+ var LOCAL_HOSTNAMES = { localhost: true, "127.0.0.1": true, "::1": true, "[::1]": true };
13
+ function encodeBase64Url(bytes) {
14
+ return Buffer.from(bytes).toString("base64").replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
15
+ }
16
+ function normalizeRelayOrigin(relayUrl) {
17
+ let url;
18
+ try {
19
+ url = new URL(relayUrl);
20
+ } catch {
21
+ return { error: `Invalid relay URL: ${relayUrl}` };
22
+ }
23
+ let scheme;
24
+ switch (url.protocol) {
25
+ case "wss:":
26
+ case "https:":
27
+ scheme = "wss:";
28
+ break;
29
+ case "ws:":
30
+ case "http:":
31
+ scheme = "ws:";
32
+ break;
33
+ default:
34
+ return { error: `Unsupported relay URL scheme: ${url.protocol}` };
35
+ }
36
+ if (scheme === "ws:" && !LOCAL_HOSTNAMES[url.hostname]) {
37
+ return { error: "relay link must be wss:// (plain ws:// is only allowed for localhost)" };
38
+ }
39
+ const port = url.port ? `:${url.port}` : "";
40
+ return { origin: `${scheme}//${url.hostname}${port}` };
41
+ }
42
+ function formatCollabLink(relayUrl, roomId, key, writeToken) {
43
+ const normalized = normalizeRelayOrigin(relayUrl);
44
+ if ("error" in normalized)
45
+ throw new Error(normalized.error);
46
+ let secret = key;
47
+ if (writeToken) {
48
+ secret = new Uint8Array(key.byteLength + writeToken.byteLength);
49
+ secret.set(key, 0);
50
+ secret.set(writeToken, key.byteLength);
51
+ }
52
+ const keyText = encodeBase64Url(secret);
53
+ if (normalized.origin === DEFAULT_RELAY_URL)
54
+ return `${roomId}.${keyText}`;
55
+ const compact = normalized.origin.startsWith("wss://") ? normalized.origin.slice("wss://".length) : normalized.origin;
56
+ return `${compact}/r/${roomId}.${keyText}`;
57
+ }
58
+ var collabSessionBrowserPlugin = definePlugin({
59
+ name: COLLAB_SESSION_BROWSER_PLUGIN_NAME,
60
+ version: "0.0.0-alpha.1",
61
+ contributes: {
62
+ capabilities: [
63
+ CollabSessionViewerCap.provide(async () => {
64
+ return {
65
+ distDir() {
66
+ return fileURLToPath(new URL("../../collab-web/dist", import.meta.url));
67
+ },
68
+ formatViewerLink(input) {
69
+ return formatCollabLink(input.relayUrl, input.roomId, input.key, input.writeToken);
70
+ }
71
+ };
72
+ }, {
73
+ title: "Collab session browser viewer",
74
+ description: "Serve the collab-web live-session SPA (paste a roomId.key link \u2192 streaming transcript + tool cards + composer) and format shareable pi-wire viewer links."
75
+ })
76
+ ]
77
+ }
78
+ });
79
+ function createCollabSessionBrowserPlugin() {
80
+ return collabSessionBrowserPlugin;
81
+ }
82
+ var plugin_default = collabSessionBrowserPlugin;
83
+ export {
84
+ plugin_default as default,
85
+ createCollabSessionBrowserPlugin,
86
+ collabSessionBrowserPlugin,
87
+ COLLAB_SESSION_BROWSER_PLUGIN_NAME
88
+ };
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@h-rig/collab-session-browser-plugin",
3
+ "version": "0.0.6-alpha.158",
4
+ "type": "module",
5
+ "description": "Owns the collab-web browser SPA as the collab-session-viewer surface: serve the live transcript viewer + format pi-wire roomId.key links.",
6
+ "license": "UNLICENSED",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/src/index.d.ts",
14
+ "import": "./dist/src/index.js"
15
+ },
16
+ "./plugin": {
17
+ "types": "./dist/src/plugin.d.ts",
18
+ "import": "./dist/src/plugin.js"
19
+ }
20
+ },
21
+ "engines": {
22
+ "bun": ">=1.3.11"
23
+ },
24
+ "main": "./dist/src/index.js",
25
+ "module": "./dist/src/index.js",
26
+ "types": "./dist/src/index.d.ts",
27
+ "dependencies": {
28
+ "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.158",
29
+ "@rig/core": "npm:@h-rig/core@0.0.6-alpha.158"
30
+ }
31
+ }