@celljs/ta-relay 4.9.1 → 4.11.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.en.md +29 -2
- package/README.md +29 -2
- package/esm/common/index.d.ts +10 -0
- package/esm/common/index.js +10 -0
- package/esm/common/relay-blobs.d.ts +54 -0
- package/esm/common/relay-blobs.js +153 -0
- package/esm/common/relay-card.d.ts +23 -0
- package/esm/common/relay-card.js +30 -0
- package/esm/common/relay-cipher.d.ts +15 -0
- package/esm/common/relay-cipher.js +62 -2
- package/esm/common/relay-content.d.ts +104 -0
- package/esm/common/relay-content.js +316 -0
- package/esm/common/relay-conversation.d.ts +59 -0
- package/esm/common/relay-conversation.js +9 -0
- package/esm/common/relay-files.d.ts +108 -0
- package/esm/common/relay-files.js +170 -0
- package/esm/common/relay-hub-util.d.ts +91 -0
- package/esm/common/relay-hub-util.js +164 -0
- package/esm/common/relay-hub.d.ts +125 -0
- package/esm/common/relay-hub.js +438 -0
- package/esm/common/relay-hubs.d.ts +271 -0
- package/esm/common/relay-hubs.js +844 -0
- package/esm/common/relay-identity.d.ts +46 -0
- package/esm/common/relay-identity.js +126 -0
- package/esm/common/relay-protocol.d.ts +217 -2
- package/esm/common/relay-protocol.js +53 -0
- package/esm/common/relay-room-chat.d.ts +80 -0
- package/esm/common/relay-room-chat.js +152 -0
- package/esm/common/relay-socket.d.ts +8 -0
- package/esm/common/relay-socket.js +33 -4
- package/esm/guest/guest-i18n.d.ts +47 -0
- package/esm/guest/guest-i18n.js +97 -0
- package/esm/guest/guest-style.d.ts +1 -0
- package/esm/guest/guest-style.js +78 -0
- package/esm/guest/guest.d.ts +1 -0
- package/esm/guest/guest.js +371 -0
- package/esm/node/index.d.ts +3 -0
- package/esm/node/index.js +3 -0
- package/esm/node/relay-files-host.d.ts +27 -0
- package/esm/node/relay-files-host.js +130 -0
- package/esm/node/relay-host.d.ts +35 -2
- package/esm/node/relay-host.js +150 -13
- package/esm/node/relay-hub-files.d.ts +12 -0
- package/esm/node/relay-hub-files.js +39 -0
- package/esm/node/relay-server.d.ts +46 -1
- package/esm/node/relay-server.js +227 -1
- package/esm/node/relay-store.d.ts +72 -0
- package/esm/node/relay-store.js +123 -2
- package/esm/node/relay-viewer.d.ts +7 -0
- package/esm/node/relay-viewer.js +33 -0
- package/esm/viewer/viewer-i18n.d.ts +56 -0
- package/esm/viewer/viewer-i18n.js +117 -0
- package/esm/viewer/viewer-markdown.d.ts +7 -0
- package/esm/viewer/viewer-markdown.js +198 -0
- package/esm/viewer/viewer-style.d.ts +1 -0
- package/esm/viewer/viewer-style.js +72 -0
- package/esm/viewer/viewer.d.ts +8 -0
- package/esm/viewer/viewer.js +378 -0
- package/lib/common/index.d.ts +10 -0
- package/lib/common/index.js +10 -0
- package/lib/common/relay-blobs.d.ts +55 -0
- package/lib/common/relay-blobs.js +157 -0
- package/lib/common/relay-card.d.ts +24 -0
- package/lib/common/relay-card.js +33 -0
- package/lib/common/relay-cipher.d.ts +15 -0
- package/lib/common/relay-cipher.js +63 -3
- package/lib/common/relay-content.d.ts +105 -0
- package/lib/common/relay-content.js +320 -0
- package/lib/common/relay-conversation.d.ts +60 -0
- package/lib/common/relay-conversation.js +12 -0
- package/lib/common/relay-files.d.ts +109 -0
- package/lib/common/relay-files.js +174 -0
- package/lib/common/relay-hub-util.d.ts +92 -0
- package/lib/common/relay-hub-util.js +167 -0
- package/lib/common/relay-hub.d.ts +126 -0
- package/lib/common/relay-hub.js +442 -0
- package/lib/common/relay-hubs.d.ts +272 -0
- package/lib/common/relay-hubs.js +848 -0
- package/lib/common/relay-identity.d.ts +47 -0
- package/lib/common/relay-identity.js +129 -0
- package/lib/common/relay-protocol.d.ts +217 -2
- package/lib/common/relay-protocol.js +54 -1
- package/lib/common/relay-room-chat.d.ts +81 -0
- package/lib/common/relay-room-chat.js +156 -0
- package/lib/common/relay-socket.d.ts +8 -0
- package/lib/common/relay-socket.js +32 -3
- package/lib/guest/guest-i18n.d.ts +48 -0
- package/lib/guest/guest-i18n.js +100 -0
- package/lib/guest/guest-style.d.ts +2 -0
- package/lib/guest/guest-style.js +81 -0
- package/lib/guest/guest.d.ts +2 -0
- package/lib/guest/guest.js +373 -0
- package/lib/node/index.d.ts +3 -0
- package/lib/node/index.js +3 -0
- package/lib/node/relay-files-host.d.ts +28 -0
- package/lib/node/relay-files-host.js +134 -0
- package/lib/node/relay-host.d.ts +35 -2
- package/lib/node/relay-host.js +149 -12
- package/lib/node/relay-hub-files.d.ts +13 -0
- package/lib/node/relay-hub-files.js +43 -0
- package/lib/node/relay-server.d.ts +46 -1
- package/lib/node/relay-server.js +226 -0
- package/lib/node/relay-store.d.ts +72 -0
- package/lib/node/relay-store.js +121 -0
- package/lib/node/relay-viewer.d.ts +8 -0
- package/lib/node/relay-viewer.js +32 -0
- package/lib/viewer/viewer-i18n.d.ts +57 -0
- package/lib/viewer/viewer-i18n.js +120 -0
- package/lib/viewer/viewer-markdown.d.ts +8 -0
- package/lib/viewer/viewer-markdown.js +201 -0
- package/lib/viewer/viewer-style.d.ts +2 -0
- package/lib/viewer/viewer-style.js +75 -0
- package/lib/viewer/viewer.d.ts +9 -0
- package/lib/viewer/viewer.js +381 -0
- package/package.json +5 -4
- package/viewer/frame.html +1 -0
- package/viewer/page.html +80 -0
- package/viewer/room.html +87 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VIEWER_STYLE = "\n:root{color-scheme:light dark;--bg:#fff;--fg:#1f1f1f;--muted:#737373;--faint:#a3a3a3;--line:#ececec;--soft:#f5f5f5;--bubble:#f2f2f2;--code:#f6f6f6;--accent:#16a34a;--warn:#d97706;--radius:14px}\n@media (prefers-color-scheme:dark){:root{--bg:#191919;--fg:#ececec;--muted:#a3a3a3;--faint:#6b6b6b;--line:#2c2c2c;--soft:#222;--bubble:#2a2a2a;--code:#232323;--accent:#4ade80;--warn:#fbbf24}}\n*{box-sizing:border-box}\nhtml,body{margin:0;background:var(--bg);color:var(--fg);font:15px/1.65 -apple-system,BlinkMacSystemFont,\"Segoe UI\",\"PingFang SC\",\"Hiragino Sans GB\",\"Microsoft YaHei\",sans-serif;-webkit-font-smoothing:antialiased}\n.top{position:sticky;top:0;z-index:2;display:flex;align-items:center;gap:10px;padding:10px 16px;background:color-mix(in srgb,var(--bg) 88%,transparent);backdrop-filter:saturate(1.6) blur(12px);-webkit-backdrop-filter:saturate(1.6) blur(12px);border-bottom:1px solid var(--line)}\n.logo{width:26px;height:26px;border-radius:8px;background:var(--fg);color:var(--bg);display:grid;place-items:center;font-weight:700;font-size:13px;flex:none}\n.top .name{font-weight:600;font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex:1;min-width:0}\n.top button{flex:none}\nmain{max-width:760px;margin:0 auto;padding:28px 18px 40px}\nmain.wide{max-width:none;padding:0}\nh1.title{font-size:22px;line-height:1.35;margin:0 0 6px;letter-spacing:-.01em;word-break:break-word}\n.meta{color:var(--muted);font-size:13px;margin:0 0 22px;display:flex;flex-wrap:wrap;gap:4px 12px}\n.notes{color:var(--muted);font-size:12.5px;margin:-10px 0 22px;display:flex;flex-direction:column;gap:2px}\n.msg{margin:0 0 18px}\n.msg.user{display:flex;justify-content:flex-end}\n.msg.user .bubble{background:var(--bubble);border-radius:var(--radius) var(--radius) 4px var(--radius);padding:9px 14px;max-width:85%;white-space:pre-wrap;word-break:break-word}\n.msg.ta .text>:first-child{margin-top:0}.msg.ta .text>:last-child{margin-bottom:0}\n.text{word-break:break-word}\n.text p{margin:0 0 .75em}\n.text h2,.text h3,.text h4,.text h5,.text h6{margin:1.2em 0 .5em;line-height:1.35}\n.text h2{font-size:1.25em}.text h3{font-size:1.1em}.text h4,.text h5,.text h6{font-size:1em}\n.text ul,.text ol{margin:0 0 .75em;padding-left:1.4em}.text li{margin:.2em 0}\n.text blockquote{margin:0 0 .75em;padding:2px 0 2px 12px;border-left:3px solid var(--line);color:var(--muted)}\n.text a{color:inherit;text-decoration:underline;text-decoration-color:var(--faint);text-underline-offset:2px}\n.text code{font:12.5px/1.5 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;background:var(--code);padding:1px 5px;border-radius:5px}\n.text pre{background:var(--code);border-radius:10px;padding:12px 14px;overflow:auto;margin:0 0 .85em}\n.text pre code{background:none;padding:0;font-size:12.5px;white-space:pre}\n.text hr{border:0;border-top:1px solid var(--line);margin:1.2em 0}\n.text .table{overflow:auto;margin:0 0 .85em}\n.text table{border-collapse:collapse;font-size:14px}\n.text th,.text td{border:1px solid var(--line);padding:5px 10px;text-align:left;vertical-align:top}\n.text th{background:var(--soft);font-weight:600}\n.tools{margin:4px 0 10px;display:flex;flex-direction:column;gap:1px}\n.tool{display:flex;align-items:baseline;gap:8px;color:var(--muted);font-size:13.5px;min-width:0;padding:2px 0}\n.tool .dot{width:6px;height:6px;border-radius:50%;background:var(--accent);flex:none;transform:translateY(-2px)}\n.tool.failed .dot{background:var(--faint)}\n.tool .verb{flex:none}\n.tool .target{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--fg);opacity:.8}\n.tool .target.code{font:12.5px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}\ndetails.out{margin:0 0 6px 14px}\ndetails.out summary{cursor:pointer;color:var(--faint);font-size:12.5px;list-style:none}\ndetails.out summary::-webkit-details-marker{display:none}\ndetails.out pre{margin:6px 0 0;background:var(--code);border-radius:8px;padding:10px 12px;max-height:280px;overflow:auto;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap;word-break:break-word}\n.err{color:var(--warn);font-size:13.5px}\n.card{max-width:380px;margin:12vh auto 0;padding:28px 24px;border:1px solid var(--line);border-radius:18px;text-align:center}\n.card h2{font-size:17px;margin:12px 0 6px}\n.card p{color:var(--muted);font-size:13.5px;margin:0 0 16px}\n.card .icon{width:44px;height:44px;border-radius:50%;background:var(--soft);color:var(--muted);display:grid;place-items:center;margin:0 auto}\n.card form{display:flex;gap:8px}\n.card input{flex:1;min-width:0;font:inherit;padding:9px 12px;border-radius:10px;border:1px solid var(--line);background:var(--bg);color:var(--fg);outline:none}\n.card input:focus{border-color:var(--muted)}\n.card .error{color:var(--warn);font-size:13px;margin:10px 0 0;min-height:1em}\nbutton{font:inherit;font-size:13.5px;padding:8px 14px;border-radius:10px;border:1px solid var(--line);background:var(--bg);color:var(--fg);cursor:pointer}\nbutton.primary{background:var(--fg);color:var(--bg);border-color:var(--fg)}\nbutton:disabled{opacity:.5;cursor:default}\n.spin{width:22px;height:22px;border:2px solid var(--line);border-top-color:var(--muted);border-radius:50%;margin:0 auto;animation:spin .8s linear infinite}\n@keyframes spin{to{transform:rotate(360deg)}}\n@media (prefers-reduced-motion:reduce){.spin{animation-duration:3s}}\n.agent-head{display:flex;flex-direction:column;align-items:center;text-align:center;gap:4px;margin:8px 0 22px}\n.agent-face{width:64px;height:64px;border-radius:50%;background:var(--soft);color:#fff;display:grid;place-items:center;font-size:24px;font-weight:700;margin-bottom:8px;box-shadow:0 0 0 1px var(--line)}\n.agent-head h1.title{margin:0}.agent-head .meta{margin:0;justify-content:center}\n.agent-role{border:1px solid var(--line);border-radius:var(--radius);padding:14px 16px;background:var(--soft)}\n.agent-role>:first-child{margin-top:0}.agent-role>:last-child{margin-bottom:0}\n.agent .notes{margin:10px 0 0}\n.agent-hint{color:var(--muted);font-size:13.5px;text-align:center;margin:18px 0 0}\n.foot{max-width:760px;margin:0 auto;padding:18px 18px 40px;color:var(--faint);font-size:12.5px;border-top:1px solid var(--line);display:flex;flex-direction:column;gap:4px}\n.page{display:block;width:100%;height:calc(100vh - 48px);height:calc(100dvh - 48px);border:0;background:#fff}\n.file img{max-width:100%;border-radius:10px;display:block;margin:0 auto}\n.file pre{white-space:pre-wrap;word-break:break-word;background:var(--code);border-radius:10px;padding:14px;font:12.5px/1.55 ui-monospace,SFMono-Regular,Menlo,monospace}\n";
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export const VIEWER_STYLE = `
|
|
2
|
+
:root{color-scheme:light dark;--bg:#fff;--fg:#1f1f1f;--muted:#737373;--faint:#a3a3a3;--line:#ececec;--soft:#f5f5f5;--bubble:#f2f2f2;--code:#f6f6f6;--accent:#16a34a;--warn:#d97706;--radius:14px}
|
|
3
|
+
@media (prefers-color-scheme:dark){:root{--bg:#191919;--fg:#ececec;--muted:#a3a3a3;--faint:#6b6b6b;--line:#2c2c2c;--soft:#222;--bubble:#2a2a2a;--code:#232323;--accent:#4ade80;--warn:#fbbf24}}
|
|
4
|
+
*{box-sizing:border-box}
|
|
5
|
+
html,body{margin:0;background:var(--bg);color:var(--fg);font:15px/1.65 -apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Hiragino Sans GB","Microsoft YaHei",sans-serif;-webkit-font-smoothing:antialiased}
|
|
6
|
+
.top{position:sticky;top:0;z-index:2;display:flex;align-items:center;gap:10px;padding:10px 16px;background:color-mix(in srgb,var(--bg) 88%,transparent);backdrop-filter:saturate(1.6) blur(12px);-webkit-backdrop-filter:saturate(1.6) blur(12px);border-bottom:1px solid var(--line)}
|
|
7
|
+
.logo{width:26px;height:26px;border-radius:8px;background:var(--fg);color:var(--bg);display:grid;place-items:center;font-weight:700;font-size:13px;flex:none}
|
|
8
|
+
.top .name{font-weight:600;font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex:1;min-width:0}
|
|
9
|
+
.top button{flex:none}
|
|
10
|
+
main{max-width:760px;margin:0 auto;padding:28px 18px 40px}
|
|
11
|
+
main.wide{max-width:none;padding:0}
|
|
12
|
+
h1.title{font-size:22px;line-height:1.35;margin:0 0 6px;letter-spacing:-.01em;word-break:break-word}
|
|
13
|
+
.meta{color:var(--muted);font-size:13px;margin:0 0 22px;display:flex;flex-wrap:wrap;gap:4px 12px}
|
|
14
|
+
.notes{color:var(--muted);font-size:12.5px;margin:-10px 0 22px;display:flex;flex-direction:column;gap:2px}
|
|
15
|
+
.msg{margin:0 0 18px}
|
|
16
|
+
.msg.user{display:flex;justify-content:flex-end}
|
|
17
|
+
.msg.user .bubble{background:var(--bubble);border-radius:var(--radius) var(--radius) 4px var(--radius);padding:9px 14px;max-width:85%;white-space:pre-wrap;word-break:break-word}
|
|
18
|
+
.msg.ta .text>:first-child{margin-top:0}.msg.ta .text>:last-child{margin-bottom:0}
|
|
19
|
+
.text{word-break:break-word}
|
|
20
|
+
.text p{margin:0 0 .75em}
|
|
21
|
+
.text h2,.text h3,.text h4,.text h5,.text h6{margin:1.2em 0 .5em;line-height:1.35}
|
|
22
|
+
.text h2{font-size:1.25em}.text h3{font-size:1.1em}.text h4,.text h5,.text h6{font-size:1em}
|
|
23
|
+
.text ul,.text ol{margin:0 0 .75em;padding-left:1.4em}.text li{margin:.2em 0}
|
|
24
|
+
.text blockquote{margin:0 0 .75em;padding:2px 0 2px 12px;border-left:3px solid var(--line);color:var(--muted)}
|
|
25
|
+
.text a{color:inherit;text-decoration:underline;text-decoration-color:var(--faint);text-underline-offset:2px}
|
|
26
|
+
.text code{font:12.5px/1.5 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;background:var(--code);padding:1px 5px;border-radius:5px}
|
|
27
|
+
.text pre{background:var(--code);border-radius:10px;padding:12px 14px;overflow:auto;margin:0 0 .85em}
|
|
28
|
+
.text pre code{background:none;padding:0;font-size:12.5px;white-space:pre}
|
|
29
|
+
.text hr{border:0;border-top:1px solid var(--line);margin:1.2em 0}
|
|
30
|
+
.text .table{overflow:auto;margin:0 0 .85em}
|
|
31
|
+
.text table{border-collapse:collapse;font-size:14px}
|
|
32
|
+
.text th,.text td{border:1px solid var(--line);padding:5px 10px;text-align:left;vertical-align:top}
|
|
33
|
+
.text th{background:var(--soft);font-weight:600}
|
|
34
|
+
.tools{margin:4px 0 10px;display:flex;flex-direction:column;gap:1px}
|
|
35
|
+
.tool{display:flex;align-items:baseline;gap:8px;color:var(--muted);font-size:13.5px;min-width:0;padding:2px 0}
|
|
36
|
+
.tool .dot{width:6px;height:6px;border-radius:50%;background:var(--accent);flex:none;transform:translateY(-2px)}
|
|
37
|
+
.tool.failed .dot{background:var(--faint)}
|
|
38
|
+
.tool .verb{flex:none}
|
|
39
|
+
.tool .target{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--fg);opacity:.8}
|
|
40
|
+
.tool .target.code{font:12.5px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
|
41
|
+
details.out{margin:0 0 6px 14px}
|
|
42
|
+
details.out summary{cursor:pointer;color:var(--faint);font-size:12.5px;list-style:none}
|
|
43
|
+
details.out summary::-webkit-details-marker{display:none}
|
|
44
|
+
details.out pre{margin:6px 0 0;background:var(--code);border-radius:8px;padding:10px 12px;max-height:280px;overflow:auto;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap;word-break:break-word}
|
|
45
|
+
.err{color:var(--warn);font-size:13.5px}
|
|
46
|
+
.card{max-width:380px;margin:12vh auto 0;padding:28px 24px;border:1px solid var(--line);border-radius:18px;text-align:center}
|
|
47
|
+
.card h2{font-size:17px;margin:12px 0 6px}
|
|
48
|
+
.card p{color:var(--muted);font-size:13.5px;margin:0 0 16px}
|
|
49
|
+
.card .icon{width:44px;height:44px;border-radius:50%;background:var(--soft);color:var(--muted);display:grid;place-items:center;margin:0 auto}
|
|
50
|
+
.card form{display:flex;gap:8px}
|
|
51
|
+
.card input{flex:1;min-width:0;font:inherit;padding:9px 12px;border-radius:10px;border:1px solid var(--line);background:var(--bg);color:var(--fg);outline:none}
|
|
52
|
+
.card input:focus{border-color:var(--muted)}
|
|
53
|
+
.card .error{color:var(--warn);font-size:13px;margin:10px 0 0;min-height:1em}
|
|
54
|
+
button{font:inherit;font-size:13.5px;padding:8px 14px;border-radius:10px;border:1px solid var(--line);background:var(--bg);color:var(--fg);cursor:pointer}
|
|
55
|
+
button.primary{background:var(--fg);color:var(--bg);border-color:var(--fg)}
|
|
56
|
+
button:disabled{opacity:.5;cursor:default}
|
|
57
|
+
.spin{width:22px;height:22px;border:2px solid var(--line);border-top-color:var(--muted);border-radius:50%;margin:0 auto;animation:spin .8s linear infinite}
|
|
58
|
+
@keyframes spin{to{transform:rotate(360deg)}}
|
|
59
|
+
@media (prefers-reduced-motion:reduce){.spin{animation-duration:3s}}
|
|
60
|
+
.agent-head{display:flex;flex-direction:column;align-items:center;text-align:center;gap:4px;margin:8px 0 22px}
|
|
61
|
+
.agent-face{width:64px;height:64px;border-radius:50%;background:var(--soft);color:#fff;display:grid;place-items:center;font-size:24px;font-weight:700;margin-bottom:8px;box-shadow:0 0 0 1px var(--line)}
|
|
62
|
+
.agent-head h1.title{margin:0}.agent-head .meta{margin:0;justify-content:center}
|
|
63
|
+
.agent-role{border:1px solid var(--line);border-radius:var(--radius);padding:14px 16px;background:var(--soft)}
|
|
64
|
+
.agent-role>:first-child{margin-top:0}.agent-role>:last-child{margin-bottom:0}
|
|
65
|
+
.agent .notes{margin:10px 0 0}
|
|
66
|
+
.agent-hint{color:var(--muted);font-size:13.5px;text-align:center;margin:18px 0 0}
|
|
67
|
+
.foot{max-width:760px;margin:0 auto;padding:18px 18px 40px;color:var(--faint);font-size:12.5px;border-top:1px solid var(--line);display:flex;flex-direction:column;gap:4px}
|
|
68
|
+
.page{display:block;width:100%;height:calc(100vh - 48px);height:calc(100dvh - 48px);border:0;background:#fff}
|
|
69
|
+
.file img{max-width:100%;border-radius:10px;display:block;margin:0 auto}
|
|
70
|
+
.file pre{white-space:pre-wrap;word-break:break-word;background:var(--code);border-radius:10px;padding:14px;font:12.5px/1.55 ui-monospace,SFMono-Regular,Menlo,monospace}
|
|
71
|
+
`;
|
|
72
|
+
//# sourceMappingURL=viewer-style.js.map
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import { RELAY_AGENT_KIND, RelayAgentCards } from '../common/relay-card.js';
|
|
2
|
+
import { RelayContentError, RelayContentUtil } from '../common/relay-content.js';
|
|
3
|
+
import { RELAY_CONVERSATION_KIND } from '../common/relay-conversation.js';
|
|
4
|
+
import { RELAY_FRAME_PATH } from '../common/relay-protocol.js';
|
|
5
|
+
import { ViewerI18n } from './viewer-i18n.js';
|
|
6
|
+
import { ViewerMarkdown } from './viewer-markdown.js';
|
|
7
|
+
import { VIEWER_STYLE } from './viewer-style.js';
|
|
8
|
+
const { t } = ViewerI18n;
|
|
9
|
+
const el = ViewerMarkdown.el;
|
|
10
|
+
/** A call of a tool in a line, as Ta reads it: what it does, and on what. */
|
|
11
|
+
export var ViewerTools;
|
|
12
|
+
(function (ViewerTools) {
|
|
13
|
+
const VERBS = {
|
|
14
|
+
read: ['read', ['path', 'file_path']],
|
|
15
|
+
write: ['write', ['path', 'file_path']],
|
|
16
|
+
edit: ['edit', ['path', 'file_path']],
|
|
17
|
+
bash: ['run', ['command'], true],
|
|
18
|
+
grep: ['search', ['pattern'], true],
|
|
19
|
+
find: ['find', ['pattern', 'path']],
|
|
20
|
+
ls: ['list', ['path']],
|
|
21
|
+
web_fetch: ['fetch', ['url']],
|
|
22
|
+
fetch: ['fetch', ['url']],
|
|
23
|
+
web_search: ['webSearch', ['query']],
|
|
24
|
+
codemode: ['script', []],
|
|
25
|
+
};
|
|
26
|
+
function line(name, args) {
|
|
27
|
+
const known = VERBS[name];
|
|
28
|
+
const first = (keys) => keys.map(key => args === null || args === void 0 ? void 0 : args[key]).find(value => typeof value === 'string' && value);
|
|
29
|
+
if (known) {
|
|
30
|
+
return { verb: t(known[0]), target: first(known[1]), code: known[2] };
|
|
31
|
+
}
|
|
32
|
+
const target = Object.values(args !== null && args !== void 0 ? args : {}).find(value => typeof value === 'string' && value.length < 200);
|
|
33
|
+
return { verb: t('use', { name }), target };
|
|
34
|
+
}
|
|
35
|
+
ViewerTools.line = line;
|
|
36
|
+
})(ViewerTools || (ViewerTools = {}));
|
|
37
|
+
function text(content) {
|
|
38
|
+
if (typeof content === 'string') {
|
|
39
|
+
return { words: content, images: 0 };
|
|
40
|
+
}
|
|
41
|
+
const words = content.flatMap(part => (part.type === 'text' ? [part.text] : [])).join('\n');
|
|
42
|
+
return { words, images: content.filter(part => part.type === 'image').length };
|
|
43
|
+
}
|
|
44
|
+
function toolLine(part, result) {
|
|
45
|
+
const { verb, target, code } = ViewerTools.line(part.name, part.arguments);
|
|
46
|
+
const row = el('div');
|
|
47
|
+
row.className = `tool${(result === null || result === void 0 ? void 0 : result.isError) ? ' failed' : ''}`;
|
|
48
|
+
const dot = el('span');
|
|
49
|
+
dot.className = 'dot';
|
|
50
|
+
row.append(dot, Object.assign(el('span', verb), { className: 'verb' }));
|
|
51
|
+
if (target) {
|
|
52
|
+
const span = el('span', target.split('\n')[0]);
|
|
53
|
+
span.className = `target${code ? ' code' : ''}`;
|
|
54
|
+
span.title = target;
|
|
55
|
+
row.append(span);
|
|
56
|
+
}
|
|
57
|
+
const output = result ? text(result.content).words.trim() : '';
|
|
58
|
+
if (!output) {
|
|
59
|
+
return [row];
|
|
60
|
+
}
|
|
61
|
+
const details = el('details');
|
|
62
|
+
details.className = 'out';
|
|
63
|
+
details.append(el('summary', (result === null || result === void 0 ? void 0 : result.isError) ? t('error') : t('output')), el('pre', output));
|
|
64
|
+
return [row, details];
|
|
65
|
+
}
|
|
66
|
+
function conversation(main, item) {
|
|
67
|
+
var _a, _b, _c;
|
|
68
|
+
const doc = JSON.parse(new TextDecoder().decode(item.data));
|
|
69
|
+
document.title = `${doc.title || item.title} · Ta`;
|
|
70
|
+
main.append(el('h1', doc.title || item.title));
|
|
71
|
+
(_a = main.lastElementChild) === null || _a === void 0 ? void 0 : _a.classList.add('title');
|
|
72
|
+
const meta = el('p');
|
|
73
|
+
meta.className = 'meta';
|
|
74
|
+
const visible = doc.messages.filter(message => message.role !== 'toolResult').length;
|
|
75
|
+
meta.append(...[doc.place, t('sharedAt', { date: ViewerI18n.date(item.createdAt) }), t('messages', { n: visible })]
|
|
76
|
+
.filter(Boolean)
|
|
77
|
+
.map(part => el('span', part)));
|
|
78
|
+
main.append(meta);
|
|
79
|
+
const notes = [
|
|
80
|
+
((_b = doc.omitted) === null || _b === void 0 ? void 0 : _b.outputs) ? t('outputsOmitted') : '',
|
|
81
|
+
((_c = doc.omitted) === null || _c === void 0 ? void 0 : _c.images) ? t('imagesOmitted', { n: doc.omitted.images }) : '',
|
|
82
|
+
doc.redacted ? t('redacted', { n: doc.redacted }) : '',
|
|
83
|
+
].filter(Boolean);
|
|
84
|
+
if (notes.length) {
|
|
85
|
+
const box = el('div');
|
|
86
|
+
box.className = 'notes';
|
|
87
|
+
box.append(...notes.map(note => el('span', note)));
|
|
88
|
+
main.append(box);
|
|
89
|
+
}
|
|
90
|
+
const results = new Map();
|
|
91
|
+
for (const message of doc.messages) {
|
|
92
|
+
if (message.role === 'toolResult') {
|
|
93
|
+
results.set(message.toolCallId, message);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (const message of doc.messages) {
|
|
97
|
+
if (message.role === 'user') {
|
|
98
|
+
const { words, images } = text(message.content);
|
|
99
|
+
const said = [words.trim(), images ? Array.from({ length: images }, () => t('image')).join(' ') : ''].filter(Boolean).join('\n');
|
|
100
|
+
if (!said) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const row = el('div');
|
|
104
|
+
row.className = 'msg user';
|
|
105
|
+
row.append(Object.assign(el('div', said), { className: 'bubble' }));
|
|
106
|
+
main.append(row);
|
|
107
|
+
}
|
|
108
|
+
else if (message.role === 'assistant') {
|
|
109
|
+
const row = el('div');
|
|
110
|
+
row.className = 'msg ta';
|
|
111
|
+
let tools;
|
|
112
|
+
for (const part of message.content) {
|
|
113
|
+
if (part.type === 'text' && part.text.trim()) {
|
|
114
|
+
tools = undefined;
|
|
115
|
+
const block = el('div');
|
|
116
|
+
block.className = 'text';
|
|
117
|
+
block.append(ViewerMarkdown.render(part.text));
|
|
118
|
+
row.append(block);
|
|
119
|
+
}
|
|
120
|
+
else if (part.type === 'toolCall') {
|
|
121
|
+
if (!tools) {
|
|
122
|
+
tools = el('div');
|
|
123
|
+
tools.className = 'tools';
|
|
124
|
+
row.append(tools);
|
|
125
|
+
}
|
|
126
|
+
tools.append(...toolLine(part, results.get(part.id)));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (message.errorMessage) {
|
|
130
|
+
row.append(Object.assign(el('p', message.errorMessage), { className: 'err' }));
|
|
131
|
+
}
|
|
132
|
+
if (row.childNodes.length) {
|
|
133
|
+
main.append(row);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function file(main, item) {
|
|
139
|
+
var _a;
|
|
140
|
+
document.title = `${item.title} · Ta`;
|
|
141
|
+
const type = (_a = item.type) !== null && _a !== void 0 ? _a : 'application/octet-stream';
|
|
142
|
+
if (/^text\/html\b/.test(type)) {
|
|
143
|
+
main.classList.add('wide');
|
|
144
|
+
const frame = el('iframe');
|
|
145
|
+
frame.className = 'page';
|
|
146
|
+
frame.title = item.title;
|
|
147
|
+
// Its own origin, opaque: it reaches neither this page nor the key in its address.
|
|
148
|
+
frame.setAttribute('sandbox', 'allow-scripts allow-popups allow-popups-to-escape-sandbox');
|
|
149
|
+
frame.referrerPolicy = 'no-referrer';
|
|
150
|
+
const html = new TextDecoder().decode(item.data);
|
|
151
|
+
addEventListener('message', event => {
|
|
152
|
+
var _a, _b;
|
|
153
|
+
if (event.source === frame.contentWindow && ((_a = event.data) === null || _a === void 0 ? void 0 : _a.ready)) {
|
|
154
|
+
(_b = frame.contentWindow) === null || _b === void 0 ? void 0 : _b.postMessage({ html }, '*');
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
frame.src = RELAY_FRAME_PATH;
|
|
158
|
+
main.append(frame);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
main.append(Object.assign(el('h1', item.title), { className: 'title' }));
|
|
162
|
+
const meta = el('p', t('sharedAt', { date: ViewerI18n.date(item.createdAt) }));
|
|
163
|
+
meta.className = 'meta';
|
|
164
|
+
main.append(meta);
|
|
165
|
+
const box = el('div');
|
|
166
|
+
box.className = 'file';
|
|
167
|
+
const blob = new Blob([item.data], { type });
|
|
168
|
+
if (/^image\/(png|jpe?g|gif|webp|avif|bmp)$/.test(type)) {
|
|
169
|
+
const image = el('img');
|
|
170
|
+
image.src = URL.createObjectURL(blob);
|
|
171
|
+
image.alt = item.title;
|
|
172
|
+
box.append(image);
|
|
173
|
+
}
|
|
174
|
+
else if (/markdown/.test(type) || /\.(md|markdown)$/i.test(item.title)) {
|
|
175
|
+
const block = el('div');
|
|
176
|
+
block.className = 'text';
|
|
177
|
+
block.append(ViewerMarkdown.render(new TextDecoder().decode(item.data)));
|
|
178
|
+
box.append(block);
|
|
179
|
+
}
|
|
180
|
+
else if (/^text\/|json|xml|yaml|javascript|typescript/.test(type)) {
|
|
181
|
+
box.append(el('pre', new TextDecoder().decode(item.data)));
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
const a = el('a', t('download', { name: item.title }));
|
|
185
|
+
a.href = URL.createObjectURL(blob);
|
|
186
|
+
a.download = item.title;
|
|
187
|
+
const button = el('button');
|
|
188
|
+
button.className = 'primary';
|
|
189
|
+
button.append(a);
|
|
190
|
+
a.style.color = 'inherit';
|
|
191
|
+
a.style.textDecoration = 'none';
|
|
192
|
+
box.append(button);
|
|
193
|
+
}
|
|
194
|
+
main.append(box);
|
|
195
|
+
}
|
|
196
|
+
/** An agent's card: its face as its mark in its colour, its name and role, and how to add it. */
|
|
197
|
+
function agent(main, item) {
|
|
198
|
+
const found = RelayAgentCards.parse(item.data);
|
|
199
|
+
if (!found) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
document.title = `${found.name} · Ta`;
|
|
203
|
+
const box = el('div');
|
|
204
|
+
box.className = 'agent';
|
|
205
|
+
const face = el('div', found.mark);
|
|
206
|
+
face.className = 'agent-face';
|
|
207
|
+
if (found.color) {
|
|
208
|
+
face.style.background = found.color;
|
|
209
|
+
}
|
|
210
|
+
const head = el('div');
|
|
211
|
+
head.className = 'agent-head';
|
|
212
|
+
head.append(face, Object.assign(el('h1', `@${found.name}`), { className: 'title' }), Object.assign(el('p', t('agentKind')), { className: 'meta' }));
|
|
213
|
+
const role = el('div');
|
|
214
|
+
role.className = 'text agent-role';
|
|
215
|
+
role.append(ViewerMarkdown.render(found.role));
|
|
216
|
+
box.append(head, role);
|
|
217
|
+
if (found.redacted) {
|
|
218
|
+
box.append(Object.assign(el('p', t('redacted', { n: found.redacted })), { className: 'notes' }));
|
|
219
|
+
}
|
|
220
|
+
box.append(Object.assign(el('p', t('agentHint')), { className: 'agent-hint' }));
|
|
221
|
+
main.append(box);
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
/** Lucide's lock, user, moon and circle-alert as paths, drawn as the rest of Ta draws its icons (stroke 2, round). */
|
|
225
|
+
const ICONS = {
|
|
226
|
+
lock: 'M5 11h14a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2zM7 11V7a5 5 0 0 1 10 0v4',
|
|
227
|
+
self: 'M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2M12 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8z',
|
|
228
|
+
offline: 'M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9z',
|
|
229
|
+
alert: 'M12 8v4M12 16h.01M12 22a10 10 0 1 0 0-20 10 10 0 0 0 0 20z',
|
|
230
|
+
};
|
|
231
|
+
function svgIcon(name) {
|
|
232
|
+
const ns = 'http://www.w3.org/2000/svg';
|
|
233
|
+
const svg = document.createElementNS(ns, 'svg');
|
|
234
|
+
for (const [key, value] of Object.entries({
|
|
235
|
+
viewBox: '0 0 24 24',
|
|
236
|
+
width: '20',
|
|
237
|
+
height: '20',
|
|
238
|
+
fill: 'none',
|
|
239
|
+
stroke: 'currentColor',
|
|
240
|
+
'stroke-width': '2',
|
|
241
|
+
'stroke-linecap': 'round',
|
|
242
|
+
'stroke-linejoin': 'round',
|
|
243
|
+
})) {
|
|
244
|
+
svg.setAttribute(key, value);
|
|
245
|
+
}
|
|
246
|
+
const path = document.createElementNS(ns, 'path');
|
|
247
|
+
path.setAttribute('d', ICONS[name]);
|
|
248
|
+
svg.append(path);
|
|
249
|
+
return svg;
|
|
250
|
+
}
|
|
251
|
+
function card(main, icon, title, hint) {
|
|
252
|
+
main.replaceChildren();
|
|
253
|
+
const box = el('div');
|
|
254
|
+
box.className = 'card';
|
|
255
|
+
const mark = el('div');
|
|
256
|
+
mark.className = 'icon';
|
|
257
|
+
mark.append(svgIcon(icon));
|
|
258
|
+
box.append(mark, el('h2', title));
|
|
259
|
+
if (hint) {
|
|
260
|
+
box.append(el('p', hint));
|
|
261
|
+
}
|
|
262
|
+
main.append(box);
|
|
263
|
+
return box;
|
|
264
|
+
}
|
|
265
|
+
function askPassword(main, error) {
|
|
266
|
+
const box = card(main, 'lock', t('passwordTitle'), t('passwordHint'));
|
|
267
|
+
const form = el('form');
|
|
268
|
+
const input = el('input');
|
|
269
|
+
input.type = 'password';
|
|
270
|
+
input.placeholder = t('password');
|
|
271
|
+
input.autocomplete = 'off';
|
|
272
|
+
input.required = true;
|
|
273
|
+
const button = el('button', t('open'));
|
|
274
|
+
button.className = 'primary';
|
|
275
|
+
form.append(input, button);
|
|
276
|
+
const message = el('p', error !== null && error !== void 0 ? error : '');
|
|
277
|
+
message.className = 'error';
|
|
278
|
+
box.append(form, message);
|
|
279
|
+
input.focus();
|
|
280
|
+
return new Promise(resolve => form.addEventListener('submit', event => {
|
|
281
|
+
event.preventDefault();
|
|
282
|
+
if (input.value) {
|
|
283
|
+
button.setAttribute('disabled', '');
|
|
284
|
+
message.textContent = '';
|
|
285
|
+
box.append(Object.assign(el('div'), { className: 'spin' }));
|
|
286
|
+
resolve(input.value);
|
|
287
|
+
}
|
|
288
|
+
}));
|
|
289
|
+
}
|
|
290
|
+
function chrome(name) {
|
|
291
|
+
const style = el('style', VIEWER_STYLE);
|
|
292
|
+
document.head.append(style);
|
|
293
|
+
const top = el('header');
|
|
294
|
+
top.className = 'top';
|
|
295
|
+
const copy = el('button', t('copy'));
|
|
296
|
+
copy.addEventListener('click', () => {
|
|
297
|
+
var _a;
|
|
298
|
+
void ((_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText(location.href).then(() => {
|
|
299
|
+
copy.textContent = t('copied');
|
|
300
|
+
setTimeout(() => (copy.textContent = t('copy')), 1600);
|
|
301
|
+
}));
|
|
302
|
+
});
|
|
303
|
+
const title = el('span', name);
|
|
304
|
+
title.className = 'name';
|
|
305
|
+
top.append(Object.assign(el('span', 'Ta'), { className: 'logo' }), title, copy);
|
|
306
|
+
const main = el('main');
|
|
307
|
+
document.body.replaceChildren(top, main);
|
|
308
|
+
return main;
|
|
309
|
+
}
|
|
310
|
+
function footer(card) {
|
|
311
|
+
const foot = el('footer');
|
|
312
|
+
foot.className = 'foot';
|
|
313
|
+
// A card says how to add it above.
|
|
314
|
+
foot.append(...(card ? [] : [el('span', t('footer'))]), el('span', t('secure')));
|
|
315
|
+
document.body.append(foot);
|
|
316
|
+
}
|
|
317
|
+
async function show() {
|
|
318
|
+
var _a;
|
|
319
|
+
const main = chrome(t('title'));
|
|
320
|
+
let link;
|
|
321
|
+
try {
|
|
322
|
+
link = RelayContentUtil.parse(location.href);
|
|
323
|
+
}
|
|
324
|
+
catch (_b) {
|
|
325
|
+
card(main, 'alert', t('invalid'));
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
if (link.access === 'self' || link.access === 'people') {
|
|
329
|
+
card(main, 'self', t(link.access));
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
let password;
|
|
333
|
+
let error;
|
|
334
|
+
for (;;) {
|
|
335
|
+
if (link.access === 'password') {
|
|
336
|
+
password = await askPassword(main, error);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
main.replaceChildren(Object.assign(el('div'), { className: 'spin' }));
|
|
340
|
+
(_a = main.firstElementChild) === null || _a === void 0 ? void 0 : _a.setAttribute('style', 'margin-top:20vh');
|
|
341
|
+
}
|
|
342
|
+
try {
|
|
343
|
+
const item = await RelayContentUtil.fetch(link, { password });
|
|
344
|
+
main.replaceChildren();
|
|
345
|
+
const name = document.querySelector('.top .name');
|
|
346
|
+
if (name) {
|
|
347
|
+
name.textContent = item.title;
|
|
348
|
+
}
|
|
349
|
+
if (item.kind === RELAY_CONVERSATION_KIND) {
|
|
350
|
+
conversation(main, item);
|
|
351
|
+
}
|
|
352
|
+
else if (!(item.kind === RELAY_AGENT_KIND && agent(main, item))) {
|
|
353
|
+
file(main, item);
|
|
354
|
+
}
|
|
355
|
+
if (!main.classList.contains('wide')) {
|
|
356
|
+
footer(item.kind === RELAY_AGENT_KIND);
|
|
357
|
+
}
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
catch (failure) {
|
|
361
|
+
const reason = failure instanceof RelayContentError ? failure.reason : 'failed';
|
|
362
|
+
if (link.access === 'password' && (reason === 'wrong' || reason === 'password')) {
|
|
363
|
+
error = t('wrong');
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (link.access === 'password' && reason === 'busy') {
|
|
367
|
+
error = t('busy');
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
const known = ['busy', 'gone', 'offline', 'self', 'invalid', 'timeout', 'large'];
|
|
371
|
+
card(main, reason === 'offline' ? 'offline' : 'alert', t(known.includes(reason) ? reason : 'failed'));
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
addEventListener('hashchange', () => location.reload());
|
|
377
|
+
void show();
|
|
378
|
+
//# sourceMappingURL=viewer.js.map
|
package/lib/common/index.d.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
export * from './qr-code';
|
|
2
|
+
export * from './relay-blobs';
|
|
2
3
|
export * from './relay-bytes';
|
|
4
|
+
export * from './relay-card';
|
|
3
5
|
export * from './relay-cipher';
|
|
6
|
+
export * from './relay-content';
|
|
7
|
+
export * from './relay-conversation';
|
|
8
|
+
export * from './relay-files';
|
|
9
|
+
export * from './relay-hub';
|
|
10
|
+
export * from './relay-hub-util';
|
|
11
|
+
export * from './relay-hubs';
|
|
12
|
+
export * from './relay-identity';
|
|
4
13
|
export * from './relay-pairing';
|
|
5
14
|
export * from './relay-protocol';
|
|
6
15
|
export * from './relay-room';
|
|
16
|
+
export * from './relay-room-chat';
|
|
7
17
|
export * from './relay-share';
|
|
8
18
|
export * from './relay-socket';
|
|
9
19
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/common/index.js
CHANGED
|
@@ -15,11 +15,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./qr-code"), exports);
|
|
18
|
+
__exportStar(require("./relay-blobs"), exports);
|
|
18
19
|
__exportStar(require("./relay-bytes"), exports);
|
|
20
|
+
__exportStar(require("./relay-card"), exports);
|
|
19
21
|
__exportStar(require("./relay-cipher"), exports);
|
|
22
|
+
__exportStar(require("./relay-content"), exports);
|
|
23
|
+
__exportStar(require("./relay-conversation"), exports);
|
|
24
|
+
__exportStar(require("./relay-files"), exports);
|
|
25
|
+
__exportStar(require("./relay-hub"), exports);
|
|
26
|
+
__exportStar(require("./relay-hub-util"), exports);
|
|
27
|
+
__exportStar(require("./relay-hubs"), exports);
|
|
28
|
+
__exportStar(require("./relay-identity"), exports);
|
|
20
29
|
__exportStar(require("./relay-pairing"), exports);
|
|
21
30
|
__exportStar(require("./relay-protocol"), exports);
|
|
22
31
|
__exportStar(require("./relay-room"), exports);
|
|
32
|
+
__exportStar(require("./relay-room-chat"), exports);
|
|
23
33
|
__exportStar(require("./relay-share"), exports);
|
|
24
34
|
__exportStar(require("./relay-socket"), exports);
|
|
25
35
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Where a copy is kept: a Durable Object's storage, or a map in `ta relay`. Values are structured-cloned. */
|
|
2
|
+
export interface RelayBlobStorage {
|
|
3
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
4
|
+
put(key: string, value: unknown): Promise<void>;
|
|
5
|
+
deleteAll(): Promise<void>;
|
|
6
|
+
/** When the copy runs out: the storage deletes it then (an alarm), or the relay finds it so on the next request. */
|
|
7
|
+
setAlarm?(at: number): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
interface BlobMeta {
|
|
10
|
+
/** SHA-256 of the token of the host that wrote it first, who alone writes or deletes it. */
|
|
11
|
+
writeHash: string;
|
|
12
|
+
/** SHA-256 of what reads it (RelayContentUtil.authToken). */
|
|
13
|
+
authHash: string;
|
|
14
|
+
expiresAt: number;
|
|
15
|
+
size: number;
|
|
16
|
+
chunks: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* One copy of content shared, sealed, on the relay (docs/design/ta-link.md 2.5): the host that shared it puts and
|
|
20
|
+
* deletes it with its token; a viewer reads it with the token of its key. The relay can read neither the copy
|
|
21
|
+
* nor what opens it. Runs the same in a Durable Object (one for each share) and in `ta relay`.
|
|
22
|
+
*/
|
|
23
|
+
export declare class RelayBlobs {
|
|
24
|
+
protected readonly storage: RelayBlobStorage;
|
|
25
|
+
protected readonly now: () => number;
|
|
26
|
+
/** The bytes of a copy at most, sealed. */
|
|
27
|
+
static readonly MAX_BYTES: number;
|
|
28
|
+
constructor(storage: RelayBlobStorage, now?: () => number);
|
|
29
|
+
handle(request: Request): Promise<Response>;
|
|
30
|
+
protected read(request: Request): Promise<Response>;
|
|
31
|
+
protected write(request: Request): Promise<Response>;
|
|
32
|
+
protected remove(request: Request): Promise<Response>;
|
|
33
|
+
/** The copy while it lasts; past its time it is deleted, should the alarm not have run. */
|
|
34
|
+
protected meta(): Promise<BlobMeta | undefined>;
|
|
35
|
+
protected static bearer(request: Request): string;
|
|
36
|
+
protected static hash(text: string): Promise<string>;
|
|
37
|
+
protected static answer(status: number, text: string, headers?: Record<string, string>): Response;
|
|
38
|
+
}
|
|
39
|
+
/** What the host that shared content does with its copy on the relay. */
|
|
40
|
+
export declare namespace RelayBlobClient {
|
|
41
|
+
interface Copy {
|
|
42
|
+
relay: string;
|
|
43
|
+
share: string;
|
|
44
|
+
/** The host's token of the copy. */
|
|
45
|
+
token: string;
|
|
46
|
+
/** SHA-256 of the token that reads it. */
|
|
47
|
+
authHash: string;
|
|
48
|
+
expiresAt: number;
|
|
49
|
+
bytes: Uint8Array;
|
|
50
|
+
}
|
|
51
|
+
function put(copy: Copy): Promise<void>;
|
|
52
|
+
function remove(relay: string, share: string, token: string): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=relay-blobs.d.ts.map
|