@celljs/ta-relay 4.10.0 → 4.12.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.
Files changed (118) hide show
  1. package/README.en.md +13 -1
  2. package/README.md +13 -1
  3. package/esm/common/index.d.ts +11 -0
  4. package/esm/common/index.js +11 -0
  5. package/esm/common/relay-blobs.d.ts +54 -0
  6. package/esm/common/relay-blobs.js +153 -0
  7. package/esm/common/relay-card.d.ts +23 -0
  8. package/esm/common/relay-card.js +30 -0
  9. package/esm/common/relay-content.d.ts +104 -0
  10. package/esm/common/relay-content.js +316 -0
  11. package/esm/common/relay-conversation.d.ts +59 -0
  12. package/esm/common/relay-conversation.js +9 -0
  13. package/esm/common/relay-faces.d.ts +32 -0
  14. package/esm/common/relay-faces.js +208 -0
  15. package/esm/common/relay-hub-util.d.ts +91 -0
  16. package/esm/common/relay-hub-util.js +164 -0
  17. package/esm/common/relay-hub.d.ts +125 -0
  18. package/esm/common/relay-hub.js +438 -0
  19. package/esm/common/relay-hubs-connection.d.ts +98 -0
  20. package/esm/common/relay-hubs-connection.js +505 -0
  21. package/esm/common/relay-hubs-protocol.d.ts +130 -0
  22. package/esm/common/relay-hubs-protocol.js +2 -0
  23. package/esm/common/relay-hubs.d.ts +61 -0
  24. package/esm/common/relay-hubs.js +351 -0
  25. package/esm/common/relay-identity.d.ts +46 -0
  26. package/esm/common/relay-identity.js +126 -0
  27. package/esm/common/relay-protocol.d.ts +211 -2
  28. package/esm/common/relay-protocol.js +53 -0
  29. package/esm/common/relay-room-chat.d.ts +109 -0
  30. package/esm/common/relay-room-chat.js +176 -0
  31. package/esm/common/relay-socket.d.ts +8 -0
  32. package/esm/common/relay-socket.js +23 -2
  33. package/esm/guest/guest-i18n.d.ts +50 -0
  34. package/esm/guest/guest-i18n.js +103 -0
  35. package/esm/guest/guest-style.d.ts +1 -0
  36. package/esm/guest/guest-style.js +85 -0
  37. package/esm/guest/guest.d.ts +1 -0
  38. package/esm/guest/guest.js +384 -0
  39. package/esm/node/index.d.ts +2 -0
  40. package/esm/node/index.js +2 -0
  41. package/esm/node/relay-host.d.ts +25 -3
  42. package/esm/node/relay-host.js +115 -4
  43. package/esm/node/relay-hub-files.d.ts +12 -0
  44. package/esm/node/relay-hub-files.js +39 -0
  45. package/esm/node/relay-server.d.ts +46 -1
  46. package/esm/node/relay-server.js +227 -1
  47. package/esm/node/relay-store.d.ts +72 -0
  48. package/esm/node/relay-store.js +123 -2
  49. package/esm/node/relay-viewer.d.ts +7 -0
  50. package/esm/node/relay-viewer.js +33 -0
  51. package/esm/viewer/viewer-i18n.d.ts +56 -0
  52. package/esm/viewer/viewer-i18n.js +117 -0
  53. package/esm/viewer/viewer-markdown.d.ts +7 -0
  54. package/esm/viewer/viewer-markdown.js +198 -0
  55. package/esm/viewer/viewer-style.d.ts +1 -0
  56. package/esm/viewer/viewer-style.js +72 -0
  57. package/esm/viewer/viewer.d.ts +8 -0
  58. package/esm/viewer/viewer.js +378 -0
  59. package/lib/common/index.d.ts +11 -0
  60. package/lib/common/index.js +11 -0
  61. package/lib/common/relay-blobs.d.ts +55 -0
  62. package/lib/common/relay-blobs.js +157 -0
  63. package/lib/common/relay-card.d.ts +24 -0
  64. package/lib/common/relay-card.js +33 -0
  65. package/lib/common/relay-content.d.ts +105 -0
  66. package/lib/common/relay-content.js +320 -0
  67. package/lib/common/relay-conversation.d.ts +60 -0
  68. package/lib/common/relay-conversation.js +12 -0
  69. package/lib/common/relay-faces.d.ts +33 -0
  70. package/lib/common/relay-faces.js +211 -0
  71. package/lib/common/relay-hub-util.d.ts +92 -0
  72. package/lib/common/relay-hub-util.js +167 -0
  73. package/lib/common/relay-hub.d.ts +126 -0
  74. package/lib/common/relay-hub.js +442 -0
  75. package/lib/common/relay-hubs-connection.d.ts +99 -0
  76. package/lib/common/relay-hubs-connection.js +510 -0
  77. package/lib/common/relay-hubs-protocol.d.ts +131 -0
  78. package/lib/common/relay-hubs-protocol.js +3 -0
  79. package/lib/common/relay-hubs.d.ts +62 -0
  80. package/lib/common/relay-hubs.js +355 -0
  81. package/lib/common/relay-identity.d.ts +47 -0
  82. package/lib/common/relay-identity.js +129 -0
  83. package/lib/common/relay-protocol.d.ts +211 -2
  84. package/lib/common/relay-protocol.js +54 -1
  85. package/lib/common/relay-room-chat.d.ts +110 -0
  86. package/lib/common/relay-room-chat.js +180 -0
  87. package/lib/common/relay-socket.d.ts +8 -0
  88. package/lib/common/relay-socket.js +23 -2
  89. package/lib/guest/guest-i18n.d.ts +51 -0
  90. package/lib/guest/guest-i18n.js +106 -0
  91. package/lib/guest/guest-style.d.ts +2 -0
  92. package/lib/guest/guest-style.js +88 -0
  93. package/lib/guest/guest.d.ts +2 -0
  94. package/lib/guest/guest.js +386 -0
  95. package/lib/node/index.d.ts +2 -0
  96. package/lib/node/index.js +2 -0
  97. package/lib/node/relay-host.d.ts +25 -3
  98. package/lib/node/relay-host.js +115 -4
  99. package/lib/node/relay-hub-files.d.ts +13 -0
  100. package/lib/node/relay-hub-files.js +43 -0
  101. package/lib/node/relay-server.d.ts +46 -1
  102. package/lib/node/relay-server.js +226 -0
  103. package/lib/node/relay-store.d.ts +72 -0
  104. package/lib/node/relay-store.js +121 -0
  105. package/lib/node/relay-viewer.d.ts +8 -0
  106. package/lib/node/relay-viewer.js +32 -0
  107. package/lib/viewer/viewer-i18n.d.ts +57 -0
  108. package/lib/viewer/viewer-i18n.js +120 -0
  109. package/lib/viewer/viewer-markdown.d.ts +8 -0
  110. package/lib/viewer/viewer-markdown.js +201 -0
  111. package/lib/viewer/viewer-style.d.ts +2 -0
  112. package/lib/viewer/viewer-style.js +75 -0
  113. package/lib/viewer/viewer.d.ts +9 -0
  114. package/lib/viewer/viewer.js +381 -0
  115. package/package.json +5 -4
  116. package/viewer/frame.html +1 -0
  117. package/viewer/page.html +80 -0
  118. package/viewer/room.html +94 -0
@@ -0,0 +1,60 @@
1
+ /**
2
+ * A conversation shared by a link (RelayContentHeader.kind `ta-conversation`): pi's messages of its branch, as
3
+ * the one who shared it chose to hand on (docs/design/ta-link.md 2.8). The viewer of the relay draws it; Ta
4
+ * draws it too, and imports it as a conversation of its own.
5
+ */
6
+ export declare const RELAY_CONVERSATION_KIND = "ta-conversation";
7
+ /** A file or a page: its bytes, with RelayContentHeader.type. */
8
+ export declare const RELAY_FILE_KIND = "file";
9
+ export type RelayConversationPart = {
10
+ type: 'text';
11
+ text: string;
12
+ } | {
13
+ type: 'thinking';
14
+ thinking: string;
15
+ } | {
16
+ type: 'image';
17
+ data?: string;
18
+ mimeType?: string;
19
+ } | {
20
+ type: 'toolCall';
21
+ id: string;
22
+ name: string;
23
+ arguments: Record<string, unknown>;
24
+ };
25
+ /** pi's AgentMessage, the parts a conversation shows; the rest of what pi keeps passes through untouched. */
26
+ export type RelayConversationMessage = {
27
+ role: 'user';
28
+ content: string | RelayConversationPart[];
29
+ timestamp?: number;
30
+ } | {
31
+ role: 'assistant';
32
+ content: RelayConversationPart[];
33
+ model?: string;
34
+ provider?: string;
35
+ stopReason?: string;
36
+ errorMessage?: string;
37
+ timestamp?: number;
38
+ } | {
39
+ role: 'toolResult';
40
+ toolCallId: string;
41
+ toolName: string;
42
+ content: RelayConversationPart[];
43
+ isError?: boolean;
44
+ timestamp?: number;
45
+ };
46
+ export interface RelayConversation {
47
+ v: 1;
48
+ title: string;
49
+ /** The name of its directory, for a line under the title. */
50
+ place?: string;
51
+ messages: RelayConversationMessage[];
52
+ /** What was left out when it was shared: the outputs of its tools, and how many images. */
53
+ omitted?: {
54
+ outputs?: boolean;
55
+ images?: number;
56
+ };
57
+ /** How many places looked like a secret, and were taken out. */
58
+ redacted?: number;
59
+ }
60
+ //# sourceMappingURL=relay-conversation.d.ts.map
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RELAY_FILE_KIND = exports.RELAY_CONVERSATION_KIND = void 0;
4
+ /**
5
+ * A conversation shared by a link (RelayContentHeader.kind `ta-conversation`): pi's messages of its branch, as
6
+ * the one who shared it chose to hand on (docs/design/ta-link.md 2.8). The viewer of the relay draws it; Ta
7
+ * draws it too, and imports it as a conversation of its own.
8
+ */
9
+ exports.RELAY_CONVERSATION_KIND = 'ta-conversation';
10
+ /** A file or a page: its bytes, with RelayContentHeader.type. */
11
+ exports.RELAY_FILE_KIND = 'file';
12
+ //# sourceMappingURL=relay-conversation.js.map
@@ -0,0 +1,33 @@
1
+ /** How many faces there are. */
2
+ export declare const FACE_COUNT = 16;
3
+ /** An element of SVG: its tag, its attributes as written in SVG (`stroke-width`, `class`), what is in it. */
4
+ export interface FaceNode {
5
+ tag: string;
6
+ attrs: Record<string, string | number>;
7
+ children?: FaceNode[];
8
+ }
9
+ export interface Look {
10
+ color: string;
11
+ /** Eyes and mouth. */
12
+ eye: string;
13
+ cheek: string;
14
+ /** A second colour of the shape: ears, a stem, an antenna. */
15
+ accent?: string;
16
+ /** The height of the eyes and how far apart they are. */
17
+ eyeY: number;
18
+ gap: number;
19
+ mouth?: string;
20
+ /** Brows pressed in, a grin. */
21
+ brows?: boolean;
22
+ }
23
+ export declare namespace FaceUtil {
24
+ /** The face of an id: the same for the same id, on every device. */
25
+ function of(seed: string): number;
26
+ /** The face given, if it is one, else that of `seed`. */
27
+ function pick(face: number | undefined, seed?: string): number;
28
+ /** Its colour, for what draws no faces. */
29
+ function color(face: number): string;
30
+ /** What is in the `<svg viewBox="0 0 40 40">` of a face: its shape, then its cheeks, brows, eyes and mouth. */
31
+ function art(face: number): FaceNode;
32
+ }
33
+ //# sourceMappingURL=relay-faces.d.ts.map
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ /*
3
+ * The faces of those who are not Ta (agents, the people of rooms), framework-free so that Ta Web (ui.Face, React) and
4
+ * the page of web guests of the relay (src/guest, the DOM) draw the same: a small coloured shape with two eyes, cheeks
5
+ * and a mouth, one of FACE_COUNT, on a 40 × 40 grid. Their styles (`ta-face-eyes` blinks, `ta-face-look` looks
6
+ * about while at work) are those of the page that draws them.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.FaceUtil = exports.FACE_COUNT = void 0;
10
+ /** How many faces there are. */
11
+ exports.FACE_COUNT = 16;
12
+ const BLUE = '#4285F4';
13
+ const RED = '#EA4335';
14
+ const YELLOW = '#FBBC05';
15
+ const GREEN = '#34A853';
16
+ const MINT = '#5CC27F';
17
+ const ORANGE = '#EE7B3B';
18
+ const VIOLET = '#8C5CF0';
19
+ const CREAM = '#F1DFC0';
20
+ const TEAL = '#26B0A9';
21
+ const PINK = '#F27BA6';
22
+ const LILAC = '#B49CF5';
23
+ const SKY = '#45B5E8';
24
+ const INDIGO = '#5C6BC0';
25
+ const MIST = '#DCE3F0';
26
+ const INK = '#202124';
27
+ const WHITE = '#FFFFFF';
28
+ const CHEEK = 'rgba(255, 160, 185, 0.55)';
29
+ /** The edge of a light face. */
30
+ const EDGE = 'rgba(0, 0, 0, 0.14)';
31
+ const CHEEK_DEEP = 'rgba(120, 10, 30, 0.35)';
32
+ const CHEEK_WARM = 'rgba(234, 67, 53, 0.4)';
33
+ /** By face: the order is that of the shapes drawn in {@link shape}. */
34
+ const LOOKS = [
35
+ { color: MINT, eye: '#1D3B27', cheek: CHEEK, eyeY: 21, gap: 8 }, // round
36
+ { color: BLUE, eye: WHITE, cheek: CHEEK, eyeY: 23, gap: 8 }, // cat
37
+ { color: RED, eye: WHITE, cheek: CHEEK_DEEP, eyeY: 22, gap: 8 }, // pentagon
38
+ { color: CREAM, eye: '#4A3420', cheek: 'rgba(240, 120, 120, 0.5)', accent: '#DDBF8E', eyeY: 22, gap: 7.6 }, // bear
39
+ { color: GREEN, eye: WHITE, cheek: CHEEK, eyeY: 19, gap: 7.2 }, // capsule
40
+ { color: INDIGO, eye: WHITE, cheek: CHEEK, eyeY: 20, gap: 7.4 }, // diamond
41
+ { color: YELLOW, eye: INK, cheek: CHEEK_WARM, accent: '#F29900', eyeY: 24, gap: 8.4 }, // bun
42
+ { color: VIOLET, eye: '#22134A', cheek: CHEEK, eyeY: 20, gap: 8 }, // hexagon
43
+ { color: MIST, eye: '#2B3245', cheek: CHEEK, eyeY: 19, gap: 7.6 }, // ghost
44
+ { color: SKY, eye: WHITE, cheek: CHEEK, eyeY: 21, gap: 6.4 }, // star
45
+ { color: ORANGE, eye: '#3D1C08', cheek: CHEEK, accent: GREEN, eyeY: 22, gap: 8.6, brows: true }, // pumpkin
46
+ { color: WHITE, eye: WHITE, cheek: CHEEK, accent: INK, mouth: INK, eyeY: 22, gap: 10 }, // panda
47
+ { color: TEAL, eye: WHITE, cheek: CHEEK, accent: '#1B8A84', eyeY: 22.5, gap: 8.4 }, // screen
48
+ { color: PINK, eye: '#4A1428', cheek: 'rgba(160, 20, 70, 0.3)', eyeY: 24, gap: 7.4 }, // drop
49
+ { color: LILAC, eye: '#2A1A5E', cheek: CHEEK, eyeY: 25, gap: 8 }, // rabbit
50
+ { color: YELLOW, eye: INK, cheek: CHEEK_WARM, eyeY: 25, gap: 7.4 }, // triangle
51
+ ];
52
+ /** The corners of a polygon of `count` sides around (cx, cy), the first straight up; `inner` makes it a star. */
53
+ function corners(count, radius, cx, cy, inner) {
54
+ const points = [];
55
+ const steps = inner ? count * 2 : count;
56
+ for (let index = 0; index < steps; index++) {
57
+ const r = inner && index % 2 === 1 ? inner : radius;
58
+ const angle = -Math.PI / 2 + (index * 2 * Math.PI) / steps;
59
+ points.push(`${(cx + r * Math.cos(angle)).toFixed(2)},${(cy + r * Math.sin(angle)).toFixed(2)}`);
60
+ }
61
+ return points.join(' ');
62
+ }
63
+ const PENTAGON = corners(5, 13.5, 20, 21.5);
64
+ const HEXAGON = corners(6, 14, 20, 20);
65
+ const STAR = corners(5, 15.5, 20, 21.5, 8.6);
66
+ function node(tag, attrs, children) {
67
+ return children ? { tag, attrs, children } : { tag, attrs };
68
+ }
69
+ /** A polygon with round corners: filled and stroked in the same colour. */
70
+ function rounded(points, color, width = 5) {
71
+ return node('polygon', { points, fill: color, stroke: color, 'stroke-width': width, 'stroke-linejoin': 'round' });
72
+ }
73
+ function shape(face, look) {
74
+ const { color, accent = color } = look;
75
+ switch (face) {
76
+ case 1:
77
+ return node('g', {}, [
78
+ rounded('7.5,6.5 17,12 8.5,18', color, 4),
79
+ rounded('32.5,6.5 23,12 31.5,18', color, 4),
80
+ node('ellipse', { cx: 20, cy: 23, rx: 14.5, ry: 12.5, fill: color }),
81
+ ]);
82
+ case 2:
83
+ return rounded(PENTAGON, color);
84
+ case 3:
85
+ return node('g', {}, [
86
+ node('circle', { cx: 9.5, cy: 10.5, r: 5.5, fill: color }),
87
+ node('circle', { cx: 30.5, cy: 10.5, r: 5.5, fill: color }),
88
+ node('circle', { cx: 9.5, cy: 10.5, r: 2.6, fill: accent }),
89
+ node('circle', { cx: 30.5, cy: 10.5, r: 2.6, fill: accent }),
90
+ node('ellipse', { cx: 20, cy: 22.5, rx: 14.5, ry: 13, fill: color }),
91
+ ]);
92
+ case 4:
93
+ return node('rect', { x: 8.5, y: 4, width: 23, height: 32, rx: 11.5, fill: color });
94
+ case 5:
95
+ return rounded('20,5.5 34.5,20 20,34.5 5.5,20', color, 5.5);
96
+ case 6:
97
+ return node('g', {}, [
98
+ node('ellipse', { cx: 20, cy: 11, rx: 3.2, ry: 3.6, fill: accent }),
99
+ node('path', { d: 'M20 12.5c9.2 0 15.5 5.6 15.5 12.4 0 6.4-6.9 10.1-15.5 10.1S4.5 31.3 4.5 24.9C4.5 18.1 10.8 12.5 20 12.5Z', fill: color }),
100
+ ]);
101
+ case 7:
102
+ return rounded(HEXAGON, color);
103
+ case 8:
104
+ return node('path', {
105
+ d: 'M8 19a12 12 0 0 1 24 0v14l-4-3-4 3-4-3-4 3-4-3-4 3Z',
106
+ fill: color,
107
+ stroke: EDGE,
108
+ 'stroke-width': 0.8,
109
+ 'stroke-linejoin': 'round',
110
+ });
111
+ case 9:
112
+ return rounded(STAR, color, 4.5);
113
+ case 10:
114
+ return node('g', {}, [
115
+ node('rect', { x: 18.6, y: 4.5, width: 2.8, height: 7, rx: 1.4, fill: accent }),
116
+ node('ellipse', { cx: 12.5, cy: 23, rx: 8.5, ry: 11, fill: color }),
117
+ node('ellipse', { cx: 27.5, cy: 23, rx: 8.5, ry: 11, fill: color }),
118
+ node('ellipse', { cx: 20, cy: 22.5, rx: 9.5, ry: 12, fill: color }),
119
+ ]);
120
+ case 11:
121
+ return node('g', {}, [
122
+ node('circle', { cx: 9.5, cy: 10, r: 5, fill: accent }),
123
+ node('circle', { cx: 30.5, cy: 10, r: 5, fill: accent }),
124
+ node('ellipse', { cx: 20, cy: 22.5, rx: 14.5, ry: 13, fill: color, stroke: EDGE, 'stroke-width': 0.8 }),
125
+ node('ellipse', { cx: 14.6, cy: 22, rx: 3.6, ry: 4.4, transform: 'rotate(20 14.6 22)', fill: accent }),
126
+ node('ellipse', { cx: 25.4, cy: 22, rx: 3.6, ry: 4.4, transform: 'rotate(-20 25.4 22)', fill: accent }),
127
+ ]);
128
+ case 12:
129
+ return node('g', {}, [
130
+ node('rect', { x: 19.1, y: 6, width: 1.8, height: 7, fill: accent }),
131
+ node('circle', { cx: 20, cy: 5, r: 2.2, fill: accent }),
132
+ node('rect', { x: 5.5, y: 12, width: 29, height: 22.5, rx: 6.5, fill: color }),
133
+ ]);
134
+ case 13:
135
+ return node('path', { d: 'M20 4.5c2 0 13 11.6 13 20.2 0 6.4-5.8 10.8-13 10.8S7 31.1 7 24.7C7 16.1 18 4.5 20 4.5Z', fill: color });
136
+ case 14:
137
+ return node('g', {}, [
138
+ node('ellipse', { cx: 14, cy: 10.5, rx: 3.6, ry: 8, transform: 'rotate(-8 14 10.5)', fill: color }),
139
+ node('ellipse', { cx: 26, cy: 10.5, rx: 3.6, ry: 8, transform: 'rotate(8 26 10.5)', fill: color }),
140
+ node('ellipse', { cx: 20, cy: 25, rx: 14, ry: 11, fill: color }),
141
+ ]);
142
+ case 15:
143
+ return rounded('20,7 35,33 5,33', color, 6);
144
+ default:
145
+ return node('circle', { cx: 20, cy: 21, r: 14.5, fill: color });
146
+ }
147
+ }
148
+ var FaceUtil;
149
+ (function (FaceUtil) {
150
+ /** The face of an id: the same for the same id, on every device. */
151
+ function of(seed) {
152
+ let hash = 0;
153
+ for (const char of seed) {
154
+ hash = (hash * 31 + char.charCodeAt(0)) | 0;
155
+ }
156
+ return Math.abs(hash) % exports.FACE_COUNT;
157
+ }
158
+ FaceUtil.of = of;
159
+ /** The face given, if it is one, else that of `seed`. */
160
+ function pick(face, seed = '') {
161
+ return face !== undefined && face >= 0 && face < exports.FACE_COUNT ? Math.floor(face) : of(seed);
162
+ }
163
+ FaceUtil.pick = pick;
164
+ /** Its colour, for what draws no faces. */
165
+ function color(face) {
166
+ var _a;
167
+ return ((_a = LOOKS[face]) !== null && _a !== void 0 ? _a : LOOKS[0]).color;
168
+ }
169
+ FaceUtil.color = color;
170
+ /** What is in the `<svg viewBox="0 0 40 40">` of a face: its shape, then its cheeks, brows, eyes and mouth. */
171
+ function art(face) {
172
+ var _a, _b;
173
+ const look = (_a = LOOKS[face]) !== null && _a !== void 0 ? _a : LOOKS[0];
174
+ const half = look.gap / 2;
175
+ const eyeW = 4.1;
176
+ const eyeH = 4.9;
177
+ const top = look.eyeY - eyeH / 2;
178
+ const cheekY = look.eyeY + 3.6;
179
+ const cheekX = half + 2.2;
180
+ const mouthY = look.eyeY + 3.4;
181
+ const features = [
182
+ node('g', { fill: look.cheek }, [
183
+ node('ellipse', { cx: 20 - cheekX, cy: cheekY, rx: 2.2, ry: 1.25 }),
184
+ node('ellipse', { cx: 20 + cheekX, cy: cheekY, rx: 2.2, ry: 1.25 }),
185
+ ]),
186
+ ];
187
+ if (look.brows) {
188
+ features.push(node('path', {
189
+ d: `M${20 - half - 3.4} ${top - 2.6}l3.6 1.6M${20 + half + 3.4} ${top - 2.6}l-3.6 1.6`,
190
+ stroke: look.eye,
191
+ 'stroke-width': 1.4,
192
+ 'stroke-linecap': 'round',
193
+ fill: 'none',
194
+ }));
195
+ }
196
+ features.push(node('g', { class: 'ta-face-eyes', fill: look.eye }, [
197
+ node('rect', { x: 20 - half - eyeW / 2, y: top, width: eyeW, height: eyeH, rx: eyeW / 2 }),
198
+ node('rect', { x: 20 + half - eyeW / 2, y: top, width: eyeW, height: eyeH, rx: eyeW / 2 }),
199
+ ]), node('path', {
200
+ d: `M18.1 ${mouthY}q.95 1.25 1.9 0q.95 1.25 1.9 0`,
201
+ fill: 'none',
202
+ stroke: (_b = look.mouth) !== null && _b !== void 0 ? _b : look.eye,
203
+ 'stroke-width': 1.1,
204
+ 'stroke-linecap': 'round',
205
+ 'stroke-linejoin': 'round',
206
+ }));
207
+ return node('g', { class: 'ta-face-body' }, [shape(face, look), node('g', { class: 'ta-face-look' }, features)]);
208
+ }
209
+ FaceUtil.art = art;
210
+ })(FaceUtil || (exports.FaceUtil = FaceUtil = {}));
211
+ //# sourceMappingURL=relay-faces.js.map
@@ -0,0 +1,92 @@
1
+ import { type RelayIdentity, type RelayPublicIdentity } from './relay-identity';
2
+ /** What a link inviting into a room names (docs/design/ta-link.md 3.3); all of it in the fragment, which a browser does not send. */
3
+ export interface RelayHubLink {
4
+ relay: string;
5
+ room: string;
6
+ /** base64url, 32 bytes: what an ask proves and is sealed with. */
7
+ invite: string;
8
+ /** The identity id of the owner: the answer must be signed by it. */
9
+ owner: string;
10
+ title: string;
11
+ /** The owner's name, as they gave it. */
12
+ by: string;
13
+ }
14
+ /** One of a room, as its owner lists them in the roster. */
15
+ export interface RelayHubMember extends RelayPublicIdentity {
16
+ /** The id of the member in this room alone (not its identity). */
17
+ member: string;
18
+ owner?: boolean;
19
+ /** A guest in a browser (docs/design/ta-link.md 3.8): the others hear only what it says. */
20
+ guest?: boolean;
21
+ at: number;
22
+ }
23
+ export interface RelayHubRosterBody {
24
+ v: number;
25
+ members: RelayHubMember[];
26
+ }
27
+ /** What one asking to join says of itself, sealed with the key of the invitation and signed. */
28
+ export interface RelayHubAskBody extends RelayPublicIdentity {
29
+ member: string;
30
+ at: number;
31
+ /** Asks from a browser, without Ta: for the owner to know, and to admit as a guest. */
32
+ guest?: boolean;
33
+ }
34
+ /** What the owner gives one it admits, sealed for it alone: the key of the room, and what the room is. */
35
+ export interface RelayHubAnswerBody {
36
+ key: string;
37
+ kind: string;
38
+ title: string;
39
+ view?: string;
40
+ }
41
+ export interface RelayHubSigned<T> {
42
+ /** The member who signed it. */
43
+ m: string;
44
+ at: number;
45
+ b: T;
46
+ }
47
+ /** The keys of a room, made from its key `R` once. */
48
+ export interface RelayHubKeys {
49
+ seal: CryptoKey;
50
+ names: Uint8Array;
51
+ }
52
+ /** Links, keys, sealing and signatures of rooms (docs/design/ta-link.md 3.2, 3.3). */
53
+ export declare namespace RelayHubUtil {
54
+ /** `https://<relay>/r#v=1&r=<room>&i=<invite>&o=<owner>&n=<title>&by=<name>`. */
55
+ function link(link: RelayHubLink): string;
56
+ function is(text: string): boolean;
57
+ /** Throws on what is not a link of {@link link}. */
58
+ function parse(text: string): RelayHubLink;
59
+ function randomId(): string;
60
+ function randomKey(): string;
61
+ function keys(roomKey: string): Promise<RelayHubKeys>;
62
+ /** What the relay knows a key of the state by: HMAC of its name, 22 characters. */
63
+ function keyId(keys: RelayHubKeys, name: string): Promise<string>;
64
+ /** What proves an ask comes from one with the invitation; the relay keeps its {@link RelayKeys.hash}. */
65
+ function inviteProof(invite: string): Promise<string>;
66
+ function inviteKey(invite: string): Promise<CryptoKey>;
67
+ /** Signed by `identity` as `member`, then sealed with `key`. */
68
+ function seal<T>(key: CryptoKey, identity: RelayIdentity, member: string, body: T, at?: number): Promise<string>;
69
+ /**
70
+ * What {@link seal} sealed, once its signature checks with the signing key `signOf` gives for its member;
71
+ * undefined when it does not open, is not signed by that member, or is of another time than `now` (with `skewMs`).
72
+ */
73
+ function open<T>(key: CryptoKey, sealed: string, signOf: (member: string) => string | undefined, options?: {
74
+ now?: number;
75
+ skewMs?: number;
76
+ }): Promise<RelayHubSigned<T> | undefined>;
77
+ /** An ask: sealed with the key of the invitation, signed by the one who asks (its keys inside), whom the owner checks. */
78
+ function sealAsk(invite: string, identity: RelayIdentity, member: string, at?: number, guest?: boolean): Promise<string>;
79
+ /** Undefined for an ask that does not open with this invitation, or is not signed by the keys it gives. */
80
+ function openAsk(invite: string, sealed: string): Promise<RelayHubAskBody | undefined>;
81
+ /**
82
+ * The owner's answer to an ask: what the room is and its key, for the one who asked alone (ECDH of the two), signed by
83
+ * the owner; all of it sealed with the invitation the ask came with, so that the relay does not see who the owner is.
84
+ */
85
+ function sealAnswer(owner: RelayIdentity, room: string, ask: RelayHubAskBody, body: RelayHubAnswerBody, invite: string): Promise<string>;
86
+ /** Undefined unless it is signed by the owner the link names, and opens for this identity. */
87
+ function openAnswer(identity: RelayIdentity, room: string, member: string, ownerId: string, answer: string, invite: string): Promise<{
88
+ owner: RelayPublicIdentity;
89
+ body: RelayHubAnswerBody;
90
+ } | undefined>;
91
+ }
92
+ //# sourceMappingURL=relay-hub-util.d.ts.map
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RelayHubUtil = void 0;
4
+ const relay_bytes_1 = require("./relay-bytes");
5
+ const relay_identity_1 = require("./relay-identity");
6
+ const relay_protocol_1 = require("./relay-protocol");
7
+ /** Links, keys, sealing and signatures of rooms (docs/design/ta-link.md 3.2, 3.3). */
8
+ var RelayHubUtil;
9
+ (function (RelayHubUtil) {
10
+ /** `https://<relay>/r#v=1&r=<room>&i=<invite>&o=<owner>&n=<title>&by=<name>`. */
11
+ function link(link) {
12
+ const fragment = new URLSearchParams({ v: '1', r: link.room, i: link.invite, o: link.owner, n: link.title, by: link.by });
13
+ return `${link.relay}${relay_protocol_1.RELAY_ROOM_PATH}#${fragment}`;
14
+ }
15
+ RelayHubUtil.link = link;
16
+ function is(text) {
17
+ try {
18
+ parse(text);
19
+ return true;
20
+ }
21
+ catch (_a) {
22
+ return false;
23
+ }
24
+ }
25
+ RelayHubUtil.is = is;
26
+ /** Throws on what is not a link of {@link link}. */
27
+ function parse(text) {
28
+ var _a, _b;
29
+ const url = new URL(text.trim());
30
+ const fragment = new URLSearchParams(url.hash.slice(1));
31
+ const [room, invite, owner] = ['r', 'i', 'o'].map(name => { var _a; return (_a = fragment.get(name)) !== null && _a !== void 0 ? _a : ''; });
32
+ if (!/^https?:$/.test(url.protocol) ||
33
+ url.pathname !== relay_protocol_1.RELAY_ROOM_PATH ||
34
+ fragment.get('v') !== '1' ||
35
+ !relay_protocol_1.RELAY_ID.test(room) ||
36
+ !/^[A-Za-z0-9_-]{43}$/.test(invite) ||
37
+ !/^[A-Za-z0-9_-]{22}$/.test(owner)) {
38
+ throw new Error('Not a link inviting into a room of Ta.');
39
+ }
40
+ return { relay: url.origin, room, invite, owner, title: ((_a = fragment.get('n')) !== null && _a !== void 0 ? _a : '').slice(0, 200), by: ((_b = fragment.get('by')) !== null && _b !== void 0 ? _b : '').slice(0, 100) };
41
+ }
42
+ RelayHubUtil.parse = parse;
43
+ function randomId() {
44
+ return relay_bytes_1.RelayBytes.toBase64(relay_bytes_1.RelayBytes.random(16));
45
+ }
46
+ RelayHubUtil.randomId = randomId;
47
+ function randomKey() {
48
+ return relay_bytes_1.RelayBytes.toBase64(relay_bytes_1.RelayBytes.random(32));
49
+ }
50
+ RelayHubUtil.randomKey = randomKey;
51
+ async function keys(roomKey) {
52
+ const key = relay_bytes_1.RelayBytes.fromBase64(roomKey);
53
+ const none = new Uint8Array(0);
54
+ return {
55
+ seal: await relay_identity_1.RelayKeys.aesKey(await relay_identity_1.RelayKeys.hkdf(key, none, 'ta-room/1 seal')),
56
+ names: await relay_identity_1.RelayKeys.hkdf(key, none, 'ta-room/1 key'),
57
+ };
58
+ }
59
+ RelayHubUtil.keys = keys;
60
+ /** What the relay knows a key of the state by: HMAC of its name, 22 characters. */
61
+ async function keyId(keys, name) {
62
+ return (await relay_identity_1.RelayKeys.hmac(keys.names, name)).slice(0, 22);
63
+ }
64
+ RelayHubUtil.keyId = keyId;
65
+ /** What proves an ask comes from one with the invitation; the relay keeps its {@link RelayKeys.hash}. */
66
+ async function inviteProof(invite) {
67
+ return relay_bytes_1.RelayBytes.toBase64(await relay_identity_1.RelayKeys.hkdf(relay_bytes_1.RelayBytes.fromBase64(invite), new Uint8Array(0), 'ta-room/1 ask auth'));
68
+ }
69
+ RelayHubUtil.inviteProof = inviteProof;
70
+ async function inviteKey(invite) {
71
+ return relay_identity_1.RelayKeys.aesKey(await relay_identity_1.RelayKeys.hkdf(relay_bytes_1.RelayBytes.fromBase64(invite), new Uint8Array(0), 'ta-room/1 ask seal'));
72
+ }
73
+ RelayHubUtil.inviteKey = inviteKey;
74
+ /** Signed by `identity` as `member`, then sealed with `key`. */
75
+ async function seal(key, identity, member, body, at = Date.now()) {
76
+ const p = JSON.stringify({ m: member, at, b: body });
77
+ return relay_identity_1.RelayKeys.seal(key, JSON.stringify({ p, s: await relay_identity_1.RelayIdentityUtil.sign(identity, p) }));
78
+ }
79
+ RelayHubUtil.seal = seal;
80
+ /**
81
+ * What {@link seal} sealed, once its signature checks with the signing key `signOf` gives for its member;
82
+ * undefined when it does not open, is not signed by that member, or is of another time than `now` (with `skewMs`).
83
+ */
84
+ async function open(key, sealed, signOf, options = {}) {
85
+ var _a;
86
+ try {
87
+ const envelope = JSON.parse(await relay_identity_1.RelayKeys.open(key, sealed));
88
+ const signed = JSON.parse(envelope.p);
89
+ const sign = typeof signed.m === 'string' ? signOf(signed.m) : undefined;
90
+ if (!sign || !(await relay_identity_1.RelayIdentityUtil.verify(sign, envelope.p, envelope.s))) {
91
+ return undefined;
92
+ }
93
+ if (options.skewMs !== undefined && Math.abs(((_a = options.now) !== null && _a !== void 0 ? _a : Date.now()) - Number(signed.at)) > options.skewMs) {
94
+ return undefined;
95
+ }
96
+ return signed;
97
+ }
98
+ catch (_b) {
99
+ return undefined;
100
+ }
101
+ }
102
+ RelayHubUtil.open = open;
103
+ /** An ask: sealed with the key of the invitation, signed by the one who asks (its keys inside), whom the owner checks. */
104
+ async function sealAsk(invite, identity, member, at = Date.now(), guest = false) {
105
+ const body = { ...relay_identity_1.RelayIdentityUtil.publicOf(identity), member, at, ...(guest ? { guest: true } : {}) };
106
+ return seal(await inviteKey(invite), identity, member, body, at);
107
+ }
108
+ RelayHubUtil.sealAsk = sealAsk;
109
+ /** Undefined for an ask that does not open with this invitation, or is not signed by the keys it gives. */
110
+ async function openAsk(invite, sealed) {
111
+ try {
112
+ const envelope = JSON.parse(await relay_identity_1.RelayKeys.open(await inviteKey(invite), sealed));
113
+ const signed = JSON.parse(envelope.p);
114
+ const body = signed.b;
115
+ if (!body ||
116
+ signed.m !== body.member ||
117
+ !relay_protocol_1.RELAY_ID.test(String(body.member)) ||
118
+ !(await relay_identity_1.RelayIdentityUtil.check(body)) ||
119
+ !(await relay_identity_1.RelayIdentityUtil.verify(body.sign, envelope.p, envelope.s))) {
120
+ return undefined;
121
+ }
122
+ return {
123
+ ...relay_identity_1.RelayIdentityUtil.publicOf(body),
124
+ name: String(body.name).slice(0, 100),
125
+ member: body.member,
126
+ at: Number(body.at),
127
+ ...(body.guest === true ? { guest: true } : {}),
128
+ };
129
+ }
130
+ catch (_a) {
131
+ return undefined;
132
+ }
133
+ }
134
+ RelayHubUtil.openAsk = openAsk;
135
+ /**
136
+ * The owner's answer to an ask: what the room is and its key, for the one who asked alone (ECDH of the two), signed by
137
+ * the owner; all of it sealed with the invitation the ask came with, so that the relay does not see who the owner is.
138
+ */
139
+ async function sealAnswer(owner, room, ask, body, invite) {
140
+ const key = await relay_identity_1.RelayKeys.aesKey(await relay_identity_1.RelayIdentityUtil.agree(owner, ask.box, room, 'ta-room/1 answer'));
141
+ const d = await relay_identity_1.RelayKeys.seal(key, JSON.stringify(body));
142
+ const signed = `${room}\n${ask.member}\n${d}`;
143
+ const answer = JSON.stringify({ owner: relay_identity_1.RelayIdentityUtil.publicOf(owner), d, s: await relay_identity_1.RelayIdentityUtil.sign(owner, signed) });
144
+ return relay_identity_1.RelayKeys.seal(await inviteKey(invite), answer);
145
+ }
146
+ RelayHubUtil.sealAnswer = sealAnswer;
147
+ /** Undefined unless it is signed by the owner the link names, and opens for this identity. */
148
+ async function openAnswer(identity, room, member, ownerId, answer, invite) {
149
+ try {
150
+ const { owner, d, s } = JSON.parse(await relay_identity_1.RelayKeys.open(await inviteKey(invite), answer));
151
+ if (owner.id !== ownerId ||
152
+ !(await relay_identity_1.RelayIdentityUtil.check(owner)) ||
153
+ !(await relay_identity_1.RelayIdentityUtil.verify(owner.sign, `${room}\n${member}\n${d}`, s))) {
154
+ return undefined;
155
+ }
156
+ const key = await relay_identity_1.RelayKeys.aesKey(await relay_identity_1.RelayIdentityUtil.agree(identity, owner.box, room, 'ta-room/1 answer'));
157
+ const body = JSON.parse(await relay_identity_1.RelayKeys.open(key, d));
158
+ relay_bytes_1.RelayBytes.fromBase64(body.key);
159
+ return { owner: { ...relay_identity_1.RelayIdentityUtil.publicOf(owner), name: String(owner.name).slice(0, 100) }, body };
160
+ }
161
+ catch (_a) {
162
+ return undefined;
163
+ }
164
+ }
165
+ RelayHubUtil.openAnswer = openAnswer;
166
+ })(RelayHubUtil || (exports.RelayHubUtil = RelayHubUtil = {}));
167
+ //# sourceMappingURL=relay-hub-util.js.map