@anvia/react-ui 1.3.0 → 1.3.1

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 (131) hide show
  1. package/dist/attachment/index.d.ts +3 -21
  2. package/dist/attachment/index.js +3 -12
  3. package/dist/attachment-DsKTPumt.js +89 -0
  4. package/dist/attachment-DsKTPumt.js.map +1 -0
  5. package/dist/chat/index.d.ts +3 -152
  6. package/dist/chat/index.js +3 -25
  7. package/dist/chat-CAnvUEAv.js +1210 -0
  8. package/dist/chat-CAnvUEAv.js.map +1 -0
  9. package/dist/completion/index.d.ts +3 -29
  10. package/dist/completion/index.js +3 -16
  11. package/dist/completion-DDTKoZRJ.js +124 -0
  12. package/dist/completion-DDTKoZRJ.js.map +1 -0
  13. package/dist/connection-DeNq8wHS.js +203 -0
  14. package/dist/connection-DeNq8wHS.js.map +1 -0
  15. package/dist/contexts-B4ijG24z.js +212 -0
  16. package/dist/contexts-B4ijG24z.js.map +1 -0
  17. package/dist/elements-D4vmkkF8.js +19 -0
  18. package/dist/elements-D4vmkkF8.js.map +1 -0
  19. package/dist/graph-explorer/index.d.ts +54 -73
  20. package/dist/graph-explorer/index.d.ts.map +1 -0
  21. package/dist/graph-explorer/index.js +181 -248
  22. package/dist/graph-explorer/index.js.map +1 -1
  23. package/dist/human-input/index.d.ts +3 -78
  24. package/dist/human-input/index.js +3 -21
  25. package/dist/human-input-CsCbZomZ.js +314 -0
  26. package/dist/human-input-CsCbZomZ.js.map +1 -0
  27. package/dist/image/index.d.ts +3 -40
  28. package/dist/image/index.js +3 -12
  29. package/dist/image-D_7vaQCR.js +302 -0
  30. package/dist/image-D_7vaQCR.js.map +1 -0
  31. package/dist/index-B1Qs2Cjv.d.ts +145 -0
  32. package/dist/index-B1Qs2Cjv.d.ts.map +1 -0
  33. package/dist/index-BCBVcl0D.d.ts +277 -0
  34. package/dist/index-BCBVcl0D.d.ts.map +1 -0
  35. package/dist/index-CE22tsua.d.ts +20 -0
  36. package/dist/index-CE22tsua.d.ts.map +1 -0
  37. package/dist/index-CGqtpc6b.d.ts +25 -0
  38. package/dist/index-CGqtpc6b.d.ts.map +1 -0
  39. package/dist/index-DqdyM0Jm.d.ts +7 -0
  40. package/dist/index-DqdyM0Jm.d.ts.map +1 -0
  41. package/dist/index-Mw3ltwSG.d.ts +318 -0
  42. package/dist/index-Mw3ltwSG.d.ts.map +1 -0
  43. package/dist/index.d.ts +7 -40
  44. package/dist/index.js +34 -118
  45. package/dist/index.js.map +1 -1
  46. package/dist/message/index.d.ts +3 -105
  47. package/dist/message/index.js +3 -20
  48. package/dist/message-Dn3wW6yy.js +783 -0
  49. package/dist/message-Dn3wW6yy.js.map +1 -0
  50. package/dist/primitives-xfE7zfwJ.js +15 -0
  51. package/dist/primitives-xfE7zfwJ.js.map +1 -0
  52. package/dist/refs-Djj9rSvB.js +10 -0
  53. package/dist/refs-Djj9rSvB.js.map +1 -0
  54. package/dist/sandbox-desktop/index.d.ts +100 -104
  55. package/dist/sandbox-desktop/index.d.ts.map +1 -0
  56. package/dist/sandbox-desktop/index.js +344 -342
  57. package/dist/sandbox-desktop/index.js.map +1 -1
  58. package/dist/sandbox-terminal/index.d.ts +52 -56
  59. package/dist/sandbox-terminal/index.d.ts.map +1 -0
  60. package/dist/sandbox-terminal/index.js +217 -208
  61. package/dist/sandbox-terminal/index.js.map +1 -1
  62. package/dist/selection-toolbar/index.d.ts +3 -21
  63. package/dist/selection-toolbar/index.js +3 -13
  64. package/dist/selection-toolbar-CIkOoM-7.js +171 -0
  65. package/dist/selection-toolbar-CIkOoM-7.js.map +1 -0
  66. package/dist/shared-BSYElFU2.d.ts +2 -0
  67. package/dist/shared.d.ts +4 -14
  68. package/dist/shared.js +1 -43
  69. package/dist/stream/index.d.ts +2 -22
  70. package/dist/stream/index.js +1 -8
  71. package/dist/stream-CAO0x8_1.js +298 -0
  72. package/dist/stream-CAO0x8_1.js.map +1 -0
  73. package/dist/thread-list/index.d.ts +3 -47
  74. package/dist/thread-list/index.js +3 -18
  75. package/dist/thread-list-xJbGXFrE.js +228 -0
  76. package/dist/thread-list-xJbGXFrE.js.map +1 -0
  77. package/dist/ticket-CoJHBpdF.d.ts +32 -0
  78. package/dist/ticket-CoJHBpdF.d.ts.map +1 -0
  79. package/dist/value-BGGrx72L.js +13 -0
  80. package/dist/value-BGGrx72L.js.map +1 -0
  81. package/package.json +22 -22
  82. package/dist/attachment/index.js.map +0 -1
  83. package/dist/attachment-mbjsroli.d.ts +0 -9
  84. package/dist/chat/index.js.map +0 -1
  85. package/dist/chat-PSj1Fo4W.d.ts +0 -88
  86. package/dist/chunk-22EZJUPM.js +0 -120
  87. package/dist/chunk-22EZJUPM.js.map +0 -1
  88. package/dist/chunk-5FZKTDZR.js +0 -201
  89. package/dist/chunk-5FZKTDZR.js.map +0 -1
  90. package/dist/chunk-6XOJFLX4.js +0 -22
  91. package/dist/chunk-6XOJFLX4.js.map +0 -1
  92. package/dist/chunk-CKA4CE26.js +0 -25
  93. package/dist/chunk-CKA4CE26.js.map +0 -1
  94. package/dist/chunk-DLBNFBXQ.js +0 -425
  95. package/dist/chunk-DLBNFBXQ.js.map +0 -1
  96. package/dist/chunk-E73S3SOF.js +0 -404
  97. package/dist/chunk-E73S3SOF.js.map +0 -1
  98. package/dist/chunk-F6AKBUO3.js +0 -380
  99. package/dist/chunk-F6AKBUO3.js.map +0 -1
  100. package/dist/chunk-HGOPGZNQ.js +0 -195
  101. package/dist/chunk-HGOPGZNQ.js.map +0 -1
  102. package/dist/chunk-KHB5CHAU.js +0 -220
  103. package/dist/chunk-KHB5CHAU.js.map +0 -1
  104. package/dist/chunk-LHABOAOP.js +0 -316
  105. package/dist/chunk-LHABOAOP.js.map +0 -1
  106. package/dist/chunk-N5XQU36W.js +0 -410
  107. package/dist/chunk-N5XQU36W.js.map +0 -1
  108. package/dist/chunk-T3ZFZ3NP.js +0 -30
  109. package/dist/chunk-T3ZFZ3NP.js.map +0 -1
  110. package/dist/chunk-T4IYUEPH.js +0 -1612
  111. package/dist/chunk-T4IYUEPH.js.map +0 -1
  112. package/dist/chunk-W2AHKMRS.js +0 -1092
  113. package/dist/chunk-W2AHKMRS.js.map +0 -1
  114. package/dist/completion/index.js.map +0 -1
  115. package/dist/completion-input-DHlwrhxB.d.ts +0 -24
  116. package/dist/composer-6iCSIq6L.d.ts +0 -111
  117. package/dist/human-input/index.js.map +0 -1
  118. package/dist/human-input-CkLrZ8IC.d.ts +0 -27
  119. package/dist/image/index.js.map +0 -1
  120. package/dist/image-VZv6Ddsn.d.ts +0 -14
  121. package/dist/message/index.js.map +0 -1
  122. package/dist/message-CNRnZQwU.d.ts +0 -14
  123. package/dist/render-CRKWam2v.d.ts +0 -8
  124. package/dist/selection-toolbar/index.js.map +0 -1
  125. package/dist/selection-toolbar-Cwjbuv5S.d.ts +0 -14
  126. package/dist/shared.js.map +0 -1
  127. package/dist/stream/index.js.map +0 -1
  128. package/dist/thread-Bz6-1zaJ.d.ts +0 -12
  129. package/dist/thread-list/index.js.map +0 -1
  130. package/dist/thread-list-On8db4XL.d.ts +0 -34
  131. package/dist/ticket-pexI1zIa.d.ts +0 -33
@@ -1,120 +0,0 @@
1
- import {
2
- renderPrimitive
3
- } from "./chunk-T3ZFZ3NP.js";
4
- import {
5
- useAttachment
6
- } from "./chunk-E73S3SOF.js";
7
-
8
- // src/attachment/parts.tsx
9
- import { forwardRef, useCallback } from "react";
10
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
11
- var AttachmentRoot = forwardRef(function AttachmentRoot2({ children, ...props }, ref) {
12
- const { attachment, remove } = useAttachment();
13
- const renderedChildren = typeof children === "function" ? children(attachment) : children ?? defaultAttachment(remove);
14
- return renderPrimitive(
15
- "div",
16
- {
17
- ...props,
18
- children: renderedChildren
19
- },
20
- ref
21
- );
22
- });
23
- var AttachmentName = forwardRef(
24
- function AttachmentName2(props, ref) {
25
- const { attachment } = useAttachment();
26
- return renderPrimitive(
27
- "span",
28
- {
29
- ...props,
30
- children: props.children ?? attachmentLabel(attachment)
31
- },
32
- ref
33
- );
34
- }
35
- );
36
- var AttachmentPreview = forwardRef(
37
- function AttachmentPreview2(props, ref) {
38
- const { attachment } = useAttachment();
39
- return renderPrimitive(
40
- "div",
41
- {
42
- ...props,
43
- children: props.children ?? defaultPreview(attachment)
44
- },
45
- ref
46
- );
47
- }
48
- );
49
- var AttachmentRemove = forwardRef(
50
- function AttachmentRemove2({ onClick, ...props }, ref) {
51
- const { remove } = useAttachment();
52
- const disabled = props.disabled ?? remove === void 0;
53
- const handleClick = useCallback(
54
- (event) => {
55
- onClick?.(event);
56
- if (event.defaultPrevented || disabled) {
57
- return;
58
- }
59
- remove?.();
60
- },
61
- [disabled, onClick, remove]
62
- );
63
- return renderPrimitive(
64
- "button",
65
- {
66
- ...props,
67
- children: props.children ?? "Remove",
68
- disabled,
69
- onClick: handleClick,
70
- type: props.type ?? "button",
71
- "data-state": disabled ? "disabled" : "enabled"
72
- },
73
- ref
74
- );
75
- }
76
- );
77
- function defaultAttachment(remove) {
78
- return /* @__PURE__ */ jsxs(Fragment, { children: [
79
- /* @__PURE__ */ jsx(AttachmentPreview, {}),
80
- /* @__PURE__ */ jsx(AttachmentName, {}),
81
- remove === void 0 ? null : /* @__PURE__ */ jsx(AttachmentRemove, {})
82
- ] });
83
- }
84
- function defaultPreview(attachment) {
85
- if (isImageAttachment(attachment)) {
86
- const source = attachment.url ?? attachmentDataUrl(attachment);
87
- if (source !== void 0) {
88
- return /* @__PURE__ */ jsx("img", { alt: attachment.name ?? "Attachment", src: source });
89
- }
90
- }
91
- if (attachment.url !== void 0) {
92
- return /* @__PURE__ */ jsx("a", { href: attachment.url, children: attachmentLabel(attachment) });
93
- }
94
- return /* @__PURE__ */ jsx("span", { children: attachment.mediaType ?? attachment.type });
95
- }
96
- function attachmentLabel(attachment) {
97
- return attachment.name ?? attachment.mediaType ?? attachment.type;
98
- }
99
- function isImageAttachment(attachment) {
100
- return attachment.type === "image" || attachment.mediaType?.startsWith("image/") === true;
101
- }
102
- function attachmentDataUrl(attachment) {
103
- if (attachment.data === void 0 || attachment.mediaType === void 0) {
104
- return void 0;
105
- }
106
- return `data:${attachment.mediaType};base64,${attachment.data}`;
107
- }
108
-
109
- // src/attachment/index.ts
110
- var AttachmentPrimitive = {
111
- Root: AttachmentRoot,
112
- Name: AttachmentName,
113
- Preview: AttachmentPreview,
114
- Remove: AttachmentRemove
115
- };
116
-
117
- export {
118
- AttachmentPrimitive
119
- };
120
- //# sourceMappingURL=chunk-22EZJUPM.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/attachment/parts.tsx","../src/attachment/index.ts"],"sourcesContent":["import type { UIAttachment } from \"@anvia/client\";\nimport { forwardRef, type MouseEvent, type ReactNode, useCallback } from \"react\";\n\nimport { useAttachment } from \"../contexts\";\nimport { type PrimitiveProps, renderPrimitive } from \"../primitives\";\n\ntype AttachmentChildren = ReactNode | ((attachment: UIAttachment) => ReactNode);\n\ntype AttachmentRootProps = Omit<PrimitiveProps<\"div\">, \"children\"> & {\n children?: AttachmentChildren;\n};\n\nconst AttachmentRoot = forwardRef<HTMLDivElement, AttachmentRootProps>(function AttachmentRoot(\n { children, ...props },\n ref,\n) {\n const { attachment, remove } = useAttachment();\n const renderedChildren =\n typeof children === \"function\" ? children(attachment) : (children ?? defaultAttachment(remove));\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: renderedChildren,\n } as PrimitiveProps<\"div\">,\n ref,\n );\n});\n\nconst AttachmentName = forwardRef<HTMLSpanElement, PrimitiveProps<\"span\">>(\n function AttachmentName(props, ref) {\n const { attachment } = useAttachment();\n\n return renderPrimitive(\n \"span\",\n {\n ...props,\n children: props.children ?? attachmentLabel(attachment),\n } as PrimitiveProps<\"span\">,\n ref,\n );\n },\n);\n\nconst AttachmentPreview = forwardRef<HTMLDivElement, PrimitiveProps<\"div\">>(\n function AttachmentPreview(props, ref) {\n const { attachment } = useAttachment();\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: props.children ?? defaultPreview(attachment),\n } as PrimitiveProps<\"div\">,\n ref,\n );\n },\n);\n\nconst AttachmentRemove = forwardRef<HTMLButtonElement, PrimitiveProps<\"button\">>(\n function AttachmentRemove({ onClick, ...props }, ref) {\n const { remove } = useAttachment();\n const disabled = props.disabled ?? remove === undefined;\n\n const handleClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event);\n if (event.defaultPrevented || disabled) {\n return;\n }\n remove?.();\n },\n [disabled, onClick, remove],\n );\n\n return renderPrimitive(\n \"button\",\n {\n ...props,\n children: props.children ?? \"Remove\",\n disabled,\n onClick: handleClick,\n type: props.type ?? \"button\",\n \"data-state\": disabled ? \"disabled\" : \"enabled\",\n } as PrimitiveProps<\"button\">,\n ref,\n );\n },\n);\n\nfunction defaultAttachment(remove: (() => void) | undefined): ReactNode {\n return (\n <>\n <AttachmentPreview />\n <AttachmentName />\n {remove === undefined ? null : <AttachmentRemove />}\n </>\n );\n}\n\nfunction defaultPreview(attachment: UIAttachment): ReactNode {\n if (isImageAttachment(attachment)) {\n const source = attachment.url ?? attachmentDataUrl(attachment);\n if (source !== undefined) {\n return <img alt={attachment.name ?? \"Attachment\"} src={source} />;\n }\n }\n\n if (attachment.url !== undefined) {\n return <a href={attachment.url}>{attachmentLabel(attachment)}</a>;\n }\n\n return <span>{attachment.mediaType ?? attachment.type}</span>;\n}\n\nfunction attachmentLabel(attachment: UIAttachment): string {\n return attachment.name ?? attachment.mediaType ?? attachment.type;\n}\n\nfunction isImageAttachment(attachment: UIAttachment): boolean {\n return attachment.type === \"image\" || attachment.mediaType?.startsWith(\"image/\") === true;\n}\n\nfunction attachmentDataUrl(attachment: UIAttachment): string | undefined {\n if (attachment.data === undefined || attachment.mediaType === undefined) {\n return undefined;\n }\n return `data:${attachment.mediaType};base64,${attachment.data}`;\n}\n\nexport { AttachmentName, AttachmentPreview, AttachmentRemove, AttachmentRoot };\n","import { AttachmentName, AttachmentPreview, AttachmentRemove, AttachmentRoot } from \"./parts\";\n\nexport const AttachmentPrimitive = {\n Root: AttachmentRoot,\n Name: AttachmentName,\n Preview: AttachmentPreview,\n Remove: AttachmentRemove,\n} as const;\n\nexport type { AttachmentContextValue } from \"../contexts\";\nexport { useAttachment } from \"../contexts\";\n"],"mappings":";;;;;;;;AACA,SAAS,YAA6C,mBAAmB;AA4FrE,mBACE,KADF;AAjFJ,IAAM,iBAAiB,WAAgD,SAASA,gBAC9E,EAAE,UAAU,GAAG,MAAM,GACrB,KACA;AACA,QAAM,EAAE,YAAY,OAAO,IAAI,cAAc;AAC7C,QAAM,mBACJ,OAAO,aAAa,aAAa,SAAS,UAAU,IAAK,YAAY,kBAAkB,MAAM;AAE/F,SAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,GAAG;AAAA,MACH,UAAU;AAAA,IACZ;AAAA,IACA;AAAA,EACF;AACF,CAAC;AAED,IAAM,iBAAiB;AAAA,EACrB,SAASC,gBAAe,OAAO,KAAK;AAClC,UAAM,EAAE,WAAW,IAAI,cAAc;AAErC,WAAO;AAAA,MACL;AAAA,MACA;AAAA,QACE,GAAG;AAAA,QACH,UAAU,MAAM,YAAY,gBAAgB,UAAU;AAAA,MACxD;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAM,oBAAoB;AAAA,EACxB,SAASC,mBAAkB,OAAO,KAAK;AACrC,UAAM,EAAE,WAAW,IAAI,cAAc;AAErC,WAAO;AAAA,MACL;AAAA,MACA;AAAA,QACE,GAAG;AAAA,QACH,UAAU,MAAM,YAAY,eAAe,UAAU;AAAA,MACvD;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAM,mBAAmB;AAAA,EACvB,SAASC,kBAAiB,EAAE,SAAS,GAAG,MAAM,GAAG,KAAK;AACpD,UAAM,EAAE,OAAO,IAAI,cAAc;AACjC,UAAM,WAAW,MAAM,YAAY,WAAW;AAE9C,UAAM,cAAc;AAAA,MAClB,CAAC,UAAyC;AACxC,k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BAAsB;AAAA,EACjC,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AACV;","names":["AttachmentRoot","AttachmentName","AttachmentPreview","AttachmentRemove"]}
@@ -1,201 +0,0 @@
1
- // src/relay/connection.ts
2
- var ticketSubprotocolPrefix = "anvia.ticket.";
3
- var defaultInitialDelayMs = 500;
4
- var defaultMaxDelayMs = 15e3;
5
- var defaultMaxAttempts = 10;
6
- var subprotocolToken = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
7
- var RelayConnection = class {
8
- constructor(options) {
9
- this.options = options;
10
- }
11
- options;
12
- socketInUse;
13
- timer;
14
- attempt = 0;
15
- everReady = false;
16
- disposed = false;
17
- finished = false;
18
- fatalMessage;
19
- start() {
20
- void this.connect();
21
- }
22
- /** Try again now, for a link that gave up. */
23
- retry() {
24
- if (this.disposed || !this.finished) return;
25
- clearTimeout(this.timer);
26
- this.finished = false;
27
- this.attempt = 0;
28
- void this.connect();
29
- }
30
- /** Send a JSON message, if the socket is open. */
31
- sendJson(value) {
32
- if (this.socketInUse?.readyState === WebSocket.OPEN) {
33
- this.socketInUse.send(JSON.stringify(value));
34
- }
35
- }
36
- /** Send bytes, if the socket is open. */
37
- sendBinary(data) {
38
- if (this.socketInUse?.readyState === WebSocket.OPEN) this.socketInUse.send(data);
39
- }
40
- dispose() {
41
- this.disposed = true;
42
- clearTimeout(this.timer);
43
- const socket = this.socketInUse;
44
- this.socketInUse = void 0;
45
- socket?.close(1e3);
46
- }
47
- async connect() {
48
- if (this.disposed) return;
49
- const { label } = this.options.protocol;
50
- this.options.onStatus({ state: "connecting" });
51
- this.fatalMessage = void 0;
52
- let ticket;
53
- try {
54
- ticket = await this.options.getTicket?.();
55
- } catch (error) {
56
- if (this.disposed) return;
57
- const detail = error instanceof Error ? `: ${error.message}` : "";
58
- this.scheduleReconnect(`Could not get a ${label} ticket${detail}`);
59
- return;
60
- }
61
- if (this.disposed) return;
62
- let socket;
63
- try {
64
- socket = new WebSocket(this.resolveUrl(), this.resolveProtocols(ticket));
65
- } catch (error) {
66
- this.fail(error instanceof Error ? error.message : `Could not open the ${label}.`);
67
- return;
68
- }
69
- if (this.disposed) {
70
- socket.close(1e3);
71
- return;
72
- }
73
- this.socketInUse = socket;
74
- socket.binaryType = "arraybuffer";
75
- const session = {
76
- ready: () => {
77
- const reconnected = this.everReady;
78
- this.everReady = true;
79
- this.attempt = 0;
80
- this.options.onStatus({ state: "open" });
81
- return reconnected;
82
- },
83
- ended: (info) => {
84
- this.finished = true;
85
- const status = { state: "ended", message: info.message ?? "ended" };
86
- if (info.exitCode !== void 0) status.exitCode = info.exitCode;
87
- this.options.onStatus(status);
88
- },
89
- fatal: (message) => {
90
- this.fatalMessage = message;
91
- }
92
- };
93
- const { protocol } = this.options;
94
- socket.addEventListener("open", () => protocol.open(socket, session));
95
- socket.addEventListener("message", (event) => protocol.message(event, session));
96
- socket.addEventListener("close", (event) => {
97
- if (this.socketInUse === socket) this.socketInUse = void 0;
98
- protocol.close?.(event, session);
99
- if (this.disposed || this.finished) return;
100
- if (this.fatalMessage !== void 0) this.fail(this.fatalMessage);
101
- else this.scheduleReconnect();
102
- });
103
- }
104
- scheduleReconnect(reason) {
105
- const { initialDelayMs, maxDelayMs, maxAttempts } = {
106
- initialDelayMs: defaultInitialDelayMs,
107
- maxDelayMs: defaultMaxDelayMs,
108
- maxAttempts: defaultMaxAttempts,
109
- ...this.options.reconnect
110
- };
111
- if (this.attempt >= maxAttempts) {
112
- this.fail(reason ?? `The connection to the ${this.options.protocol.label} was lost.`);
113
- return;
114
- }
115
- const delay = Math.min(maxDelayMs, initialDelayMs * 2 ** this.attempt) * (0.8 + Math.random() * 0.4);
116
- this.attempt += 1;
117
- this.options.onStatus({
118
- state: "reconnecting",
119
- attempt: this.attempt,
120
- retryInMs: Math.round(delay)
121
- });
122
- this.timer = setTimeout(() => void this.connect(), delay);
123
- }
124
- fail(message) {
125
- this.finished = true;
126
- this.options.onStatus({ state: "failed", message });
127
- }
128
- resolveUrl() {
129
- const url = new URL(this.options.url, globalThis.location?.href);
130
- if (url.protocol === "http:") url.protocol = "ws:";
131
- else if (url.protocol === "https:") url.protocol = "wss:";
132
- if (this.options.sessionName !== void 0) {
133
- url.searchParams.set("session", this.options.sessionName);
134
- }
135
- return url.toString();
136
- }
137
- /** The subprotocols to offer: the relay's, plus the ticket when there is one. */
138
- resolveProtocols(ticket) {
139
- const { subprotocol, label } = this.options.protocol;
140
- if (ticket === void 0) return [subprotocol];
141
- if (!subprotocolToken.test(ticket)) {
142
- throw new Error(`The ${label} ticket must use only URL-safe characters (A-Z a-z 0-9 - _ .).`);
143
- }
144
- return [subprotocol, `${ticketSubprotocolPrefix}${ticket}`];
145
- }
146
- };
147
-
148
- // src/relay/status.tsx
149
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
150
- var statusStyle = {
151
- position: "absolute",
152
- top: 8,
153
- right: 8,
154
- padding: "2px 8px",
155
- borderRadius: 4,
156
- fontSize: 12,
157
- background: "rgba(0, 0, 0, 0.7)",
158
- color: "#fff"
159
- };
160
- function DefaultStatus({ status, retry }) {
161
- if (status.state === "open") return null;
162
- return /* @__PURE__ */ jsxs("div", { role: "status", "data-relay-status": status.state, style: statusStyle, children: [
163
- describe(status),
164
- status.state === "failed" ? /* @__PURE__ */ jsxs(Fragment, { children: [
165
- " ",
166
- /* @__PURE__ */ jsx("button", { type: "button", onClick: retry, children: "Retry" })
167
- ] }) : null
168
- ] });
169
- }
170
- function describe(status) {
171
- switch (status.state) {
172
- case "loading":
173
- case "connecting":
174
- return "Connecting\u2026";
175
- case "reconnecting":
176
- return `Reconnecting in ${Math.max(1, Math.round((status.retryInMs ?? 0) / 1e3))}s\u2026`;
177
- case "ended":
178
- return status.exitCode === void 0 ? "Session ended" : `Session ended (exit ${status.exitCode})`;
179
- case "failed":
180
- return status.message ?? "Disconnected";
181
- case "open":
182
- return "";
183
- }
184
- }
185
-
186
- // src/relay/ticket.ts
187
- function resolveTicket(read) {
188
- if (read() === void 0) return void 0;
189
- return () => {
190
- const ticket = read();
191
- return typeof ticket === "function" ? ticket() : ticket;
192
- };
193
- }
194
-
195
- export {
196
- DefaultStatus,
197
- resolveTicket,
198
- ticketSubprotocolPrefix,
199
- RelayConnection
200
- };
201
- //# sourceMappingURL=chunk-5FZKTDZR.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/relay/connection.ts","../src/relay/status.tsx","../src/relay/ticket.ts"],"sourcesContent":["/** The prefix a ticket travels under in `Sec-WebSocket-Protocol`. */\nexport const ticketSubprotocolPrefix = \"anvia.ticket.\";\n\nexport type RelayState =\n /** The viewer library is still loading. */\n | \"loading\"\n | \"connecting\"\n | \"open\"\n /** The link dropped and another attempt is scheduled. */\n | \"reconnecting\"\n /** The session itself ended; reconnecting would not help. */\n | \"ended\"\n /** Gave up: a fatal error, or reconnect attempts ran out. */\n | \"failed\";\n\nexport interface RelayStatus {\n state: RelayState;\n /** Reconnect attempt number while `reconnecting`. */\n attempt?: number;\n /** Delay before the next attempt while `reconnecting`. */\n retryInMs?: number;\n /** Exit code when the session ended with one. */\n exitCode?: number;\n /** Human-readable cause for `ended` and `failed`. */\n message?: string;\n}\n\nexport interface RelayReconnectOptions {\n initialDelayMs?: number;\n maxDelayMs?: number;\n /** Consecutive failed attempts before giving up. Default 10. */\n maxAttempts?: number;\n}\n\n/** What a relay protocol can tell the connection about the socket it is driving. */\nexport interface RelaySession {\n /**\n * The relay accepted this attachment. Returns whether an earlier attachment had also been\n * accepted, so a viewer knows to start clean after a reconnect.\n */\n ready(): boolean;\n /** The session itself is over, so the socket closing is not a reason to reconnect. */\n ended(info: { message?: string | undefined; exitCode?: number | undefined }): void;\n /** Something retrying cannot fix. It takes effect when the socket closes. */\n fatal(message: string): void;\n}\n\n/** The part of a relay connection that differs between a terminal and a desktop. */\nexport interface RelayProtocol {\n /** The subprotocol the hub's upgrade handler selects. */\n subprotocol: string;\n /** Names the thing in error messages: \"terminal\", \"desktop\". */\n label: string;\n /** The socket opened. */\n open(socket: WebSocket, session: RelaySession): void;\n message(event: MessageEvent, session: RelaySession): void;\n /** The socket closed. A protocol that learns why from the close frame can call `fatal` here. */\n close?(event: CloseEvent, session: RelaySession): void;\n}\n\nexport interface RelayConnectionOptions {\n /** `ws:`, `wss:`, `http:`, `https:`, or a path relative to the page. */\n url: string;\n /** Appended as `?session=` so the server can pick the session. The server stays in charge. */\n sessionName?: string | undefined;\n /** Called for every attempt, because tickets are single use. */\n getTicket?: (() => string | Promise<string>) | undefined;\n onStatus: (status: RelayStatus) => void;\n reconnect?: RelayReconnectOptions | undefined;\n protocol: RelayProtocol;\n}\n\nconst defaultInitialDelayMs = 500;\nconst defaultMaxDelayMs = 15_000;\nconst defaultMaxAttempts = 10;\n/** Characters a ticket may use, since it travels as a WebSocket subprotocol (an HTTP token). */\nconst subprotocolToken = /^[!#$%&'*+\\-.^_`|~0-9A-Za-z]+$/;\n\n/**\n * One browser link to a hub relay: opens the socket with a fresh ticket, reconnects with backoff,\n * and reports its state. What the socket carries is the protocol's business, so this knows nothing\n * about terminals or desktops and is shared by both.\n */\nexport class RelayConnection {\n private socketInUse: WebSocket | undefined;\n private timer: ReturnType<typeof setTimeout> | undefined;\n private attempt = 0;\n private everReady = false;\n private disposed = false;\n private finished = false;\n private fatalMessage: string | undefined;\n\n constructor(private readonly options: RelayConnectionOptions) {}\n\n start(): void {\n void this.connect();\n }\n\n /** Try again now, for a link that gave up. */\n retry(): void {\n // Only a link that gave up needs this; otherwise an attempt is already under way.\n if (this.disposed || !this.finished) return;\n clearTimeout(this.timer);\n this.finished = false;\n this.attempt = 0;\n void this.connect();\n }\n\n /** Send a JSON message, if the socket is open. */\n sendJson(value: Record<string, unknown>): void {\n if (this.socketInUse?.readyState === WebSocket.OPEN) {\n this.socketInUse.send(JSON.stringify(value));\n }\n }\n\n /** Send bytes, if the socket is open. */\n sendBinary(data: ArrayBufferLike | ArrayBufferView): void {\n if (this.socketInUse?.readyState === WebSocket.OPEN) this.socketInUse.send(data);\n }\n\n dispose(): void {\n this.disposed = true;\n clearTimeout(this.timer);\n const socket = this.socketInUse;\n this.socketInUse = undefined;\n socket?.close(1000);\n }\n\n private async connect(): Promise<void> {\n if (this.disposed) return;\n const { label } = this.options.protocol;\n this.options.onStatus({ state: \"connecting\" });\n // A fatal error belongs to the attempt that hit it. Without this, one that was retried away\n // would fail every later drop.\n this.fatalMessage = undefined;\n\n let ticket: string | undefined;\n try {\n ticket = await this.options.getTicket?.();\n } catch (error) {\n // Fetching a ticket usually fails because the control plane is restarting, which is exactly\n // when reconnecting is wanted, so it backs off like a dropped socket.\n if (this.disposed) return;\n const detail = error instanceof Error ? `: ${error.message}` : \"\";\n this.scheduleReconnect(`Could not get a ${label} ticket${detail}`);\n return;\n }\n if (this.disposed) return;\n\n let socket: WebSocket;\n try {\n socket = new WebSocket(this.resolveUrl(), this.resolveProtocols(ticket));\n } catch (error) {\n // A bad URL or a malformed ticket: trying again cannot fix either.\n this.fail(error instanceof Error ? error.message : `Could not open the ${label}.`);\n return;\n }\n if (this.disposed) {\n socket.close(1000);\n return;\n }\n this.socketInUse = socket;\n socket.binaryType = \"arraybuffer\";\n\n const session: RelaySession = {\n ready: () => {\n const reconnected = this.everReady;\n this.everReady = true;\n this.attempt = 0;\n this.options.onStatus({ state: \"open\" });\n return reconnected;\n },\n ended: (info) => {\n this.finished = true;\n const status: RelayStatus = { state: \"ended\", message: info.message ?? \"ended\" };\n if (info.exitCode !== undefined) status.exitCode = info.exitCode;\n this.options.onStatus(status);\n },\n fatal: (message) => {\n this.fatalMessage = message;\n },\n };\n const { protocol } = this.options;\n socket.addEventListener(\"open\", () => protocol.open(socket, session));\n socket.addEventListener(\"message\", (event: MessageEvent) => protocol.message(event, session));\n socket.addEventListener(\"close\", (event: CloseEvent) => {\n if (this.socketInUse === socket) this.socketInUse = undefined;\n protocol.close?.(event, session);\n if (this.disposed || this.finished) return;\n if (this.fatalMessage !== undefined) this.fail(this.fatalMessage);\n else this.scheduleReconnect();\n });\n }\n\n private scheduleReconnect(reason?: string): void {\n const { initialDelayMs, maxDelayMs, maxAttempts } = {\n initialDelayMs: defaultInitialDelayMs,\n maxDelayMs: defaultMaxDelayMs,\n maxAttempts: defaultMaxAttempts,\n ...this.options.reconnect,\n };\n if (this.attempt >= maxAttempts) {\n this.fail(reason ?? `The connection to the ${this.options.protocol.label} was lost.`);\n return;\n }\n const delay =\n Math.min(maxDelayMs, initialDelayMs * 2 ** this.attempt) * (0.8 + Math.random() * 0.4);\n this.attempt += 1;\n this.options.onStatus({\n state: \"reconnecting\",\n attempt: this.attempt,\n retryInMs: Math.round(delay),\n });\n this.timer = setTimeout(() => void this.connect(), delay);\n }\n\n private fail(message: string): void {\n this.finished = true;\n this.options.onStatus({ state: \"failed\", message });\n }\n\n private resolveUrl(): string {\n const url = new URL(this.options.url, globalThis.location?.href);\n if (url.protocol === \"http:\") url.protocol = \"ws:\";\n else if (url.protocol === \"https:\") url.protocol = \"wss:\";\n if (this.options.sessionName !== undefined) {\n url.searchParams.set(\"session\", this.options.sessionName);\n }\n return url.toString();\n }\n\n /** The subprotocols to offer: the relay's, plus the ticket when there is one. */\n private resolveProtocols(ticket: string | undefined): string[] {\n const { subprotocol, label } = this.options.protocol;\n if (ticket === undefined) return [subprotocol];\n if (!subprotocolToken.test(ticket)) {\n throw new Error(`The ${label} ticket must use only URL-safe characters (A-Z a-z 0-9 - _ .).`);\n }\n return [subprotocol, `${ticketSubprotocolPrefix}${ticket}`];\n }\n}\n","import type { CSSProperties } from \"react\";\n\nimport type { RelayStatus } from \"./connection\";\n\nconst statusStyle: CSSProperties = {\n position: \"absolute\",\n top: 8,\n right: 8,\n padding: \"2px 8px\",\n borderRadius: 4,\n fontSize: 12,\n background: \"rgba(0, 0, 0, 0.7)\",\n color: \"#fff\",\n};\n\nexport function DefaultStatus({ status, retry }: { status: RelayStatus; retry: () => void }) {\n if (status.state === \"open\") return null;\n return (\n <div role=\"status\" data-relay-status={status.state} style={statusStyle}>\n {describe(status)}\n {status.state === \"failed\" ? (\n <>\n {\" \"}\n <button type=\"button\" onClick={retry}>\n Retry\n </button>\n </>\n ) : null}\n </div>\n );\n}\n\nfunction describe(status: RelayStatus): string {\n switch (status.state) {\n case \"loading\":\n case \"connecting\":\n return \"Connecting…\";\n case \"reconnecting\":\n return `Reconnecting in ${Math.max(1, Math.round((status.retryInMs ?? 0) / 1_000))}s…`;\n case \"ended\":\n return status.exitCode === undefined\n ? \"Session ended\"\n : `Session ended (exit ${status.exitCode})`;\n case \"failed\":\n return status.message ?? \"Disconnected\";\n case \"open\":\n return \"\";\n }\n}\n","/** What a viewer's `ticket` prop can be: a ticket, or a function returning one per connection. */\nexport type TicketSource = string | (() => string | Promise<string>);\n\n/**\n * Turn the latest `ticket` prop into the per-attempt function a connection wants. The prop is read\n * on every attempt, so a function is called afresh each time: tickets are single use.\n */\nexport function resolveTicket(\n read: () => TicketSource | undefined,\n): (() => string | Promise<string>) | undefined {\n if (read() === undefined) return undefined;\n return () => {\n const ticket = read();\n return typeof ticket === \"function\" ? ticket() : (ticket as string);\n };\n}\n"],"mappings":";AACO,IAAM,0BAA0B;AAuEvC,IAAM,wBAAwB;AAC9B,IAAM,oBAAoB;AAC1B,IAAM,qBAAqB;AAE3B,IAAM,mBAAmB;AAOlB,IAAM,kBAAN,MAAsB;AAAA,EAS3B,YAA6B,SAAiC;AAAjC;AAAA,EAAkC;AAAA,EAAlC;AAAA,EARrB;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,WAAW;AAAA,EACX;AAAA,EAIR,QAAc;AACZ,SAAK,KAAK,QAAQ;AAAA,EACpB;AAAA;AAAA,EAGA,QAAc;AAEZ,QAAI,KAAK,YAAY,CAAC,KAAK,SAAU;AACrC,iBAAa,KAAK,KAAK;AACvB,SAAK,WAAW;AAChB,SAAK,UAAU;AACf,SAAK,KAAK,QAAQ;AAAA,EACpB;AAAA;AAAA,EAG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B,iCACG;AAAA;AAAA,MACD,oBAAC,YAAO,MAAK,UAAS,SAAS,OAAO,mBAEtC;AAAA,OACF,IACE;AAAA,KACN;AAEJ;AAEA,SAAS,SAAS,QAA6B;AAC7C,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO,mBAAmB,KAAK,IAAI,GAAG,KAAK,OAAO,OAAO,aAAa,KAAK,GAAK,CAAC,CAAC;AAAA,IACpF,KAAK;AACH,aAAO,OAAO,aAAa,SACvB,kBACA,uBAAuB,OAAO,QAAQ;AAAA,IAC5C,KAAK;AACH,aAAO,OAAO,WAAW;AAAA,IAC3B,KAAK;AACH,aAAO;AAAA,EACX;AACF;;;ACzCO,SAAS,cACd,MAC8C;AAC9C,MAAI,KAAK,MAAM,OAAW,QAAO;AACjC,SAAO,MAAM;AACX,UAAM,SAAS,KAAK;AACpB,WAAO,OAAO,WAAW,aAAa,OAAO,IAAK;AAAA,EACpD;AACF;","names":[]}
@@ -1,22 +0,0 @@
1
- // src/message/elements.ts
2
- var messageIds = /* @__PURE__ */ new WeakMap();
3
- function registerMessageElement(element, messageId) {
4
- messageIds.set(element, messageId);
5
- }
6
- function messageElementFromNode(node) {
7
- let element = node?.nodeType === Node.ELEMENT_NODE ? node : node?.parentElement ?? void 0;
8
- while (element !== void 0 && element !== null) {
9
- const messageId = messageIds.get(element);
10
- if (messageId !== void 0) {
11
- return { element, messageId };
12
- }
13
- element = element.parentElement ?? void 0;
14
- }
15
- return void 0;
16
- }
17
-
18
- export {
19
- registerMessageElement,
20
- messageElementFromNode
21
- };
22
- //# sourceMappingURL=chunk-6XOJFLX4.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/message/elements.ts"],"sourcesContent":["const messageIds = new WeakMap<HTMLElement, string>();\n\nexport function registerMessageElement(element: HTMLElement, messageId: string): void {\n messageIds.set(element, messageId);\n}\n\nexport function messageElementFromNode(\n node: Node | null,\n): { element: HTMLElement; messageId: string } | undefined {\n let element =\n node?.nodeType === Node.ELEMENT_NODE\n ? (node as HTMLElement)\n : (node?.parentElement ?? undefined);\n\n while (element !== undefined && element !== null) {\n const messageId = messageIds.get(element);\n if (messageId !== undefined) {\n return { element, messageId };\n }\n element = element.parentElement ?? undefined;\n }\n return undefined;\n}\n"],"mappings":";AAAA,IAAM,aAAa,oBAAI,QAA6B;AAE7C,SAAS,uBAAuB,SAAsB,WAAyB;AACpF,aAAW,IAAI,SAAS,SAAS;AACnC;AAEO,SAAS,uBACd,MACyD;AACzD,MAAI,UACF,MAAM,aAAa,KAAK,eACnB,OACA,MAAM,iBAAiB;AAE9B,SAAO,YAAY,UAAa,YAAY,MAAM;AAChD,UAAM,YAAY,WAAW,IAAI,OAAO;AACxC,QAAI,cAAc,QAAW;AAC3B,aAAO,EAAE,SAAS,UAAU;AAAA,IAC9B;AACA,cAAU,QAAQ,iBAAiB;AAAA,EACrC;AACA,SAAO;AACT;","names":[]}
@@ -1,25 +0,0 @@
1
- // src/format/message.ts
2
- function messageText(message) {
3
- return message.parts.filter((part) => part.type === "text").map((part) => part.text).join("");
4
- }
5
-
6
- // src/format/value.ts
7
- function stringifyValue(value) {
8
- if (value === void 0) {
9
- return "";
10
- }
11
- if (typeof value === "string") {
12
- return value;
13
- }
14
- try {
15
- return JSON.stringify(value, null, 2);
16
- } catch {
17
- return String(value);
18
- }
19
- }
20
-
21
- export {
22
- messageText,
23
- stringifyValue
24
- };
25
- //# sourceMappingURL=chunk-CKA4CE26.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/format/message.ts","../src/format/value.ts"],"sourcesContent":["import type { UIMessage, UIMessagePart } from \"@anvia/client\";\n\nexport function messageText(message: UIMessage): string {\n return message.parts\n .filter((part): part is Extract<UIMessagePart, { type: \"text\" }> => part.type === \"text\")\n .map((part) => part.text)\n .join(\"\");\n}\n","export function stringifyValue(value: unknown): string {\n if (value === undefined) {\n return \"\";\n }\n if (typeof value === \"string\") {\n return value;\n }\n try {\n return JSON.stringify(value, null, 2);\n } catch {\n return String(value);\n }\n}\n"],"mappings":";AAEO,SAAS,YAAY,SAA4B;AACtD,SAAO,QAAQ,MACZ,OAAO,CAAC,SAA2D,KAAK,SAAS,MAAM,EACvF,IAAI,CAAC,SAAS,KAAK,IAAI,EACvB,KAAK,EAAE;AACZ;;;ACPO,SAAS,eAAe,OAAwB;AACrD,MAAI,UAAU,QAAW;AACvB,WAAO;AAAA,EACT;AACA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO;AAAA,EACT;AACA,MAAI;AACF,WAAO,KAAK,UAAU,OAAO,MAAM,CAAC;AAAA,EACtC,QAAQ;AACN,WAAO,OAAO,KAAK;AAAA,EACrB;AACF;","names":[]}