@opengeni/react 7.4.0 → 7.5.0-canary.36919050519001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +124 -27
- package/dist/artifacts-document.js +3 -2
- package/dist/artifacts-presentation.js +3 -2
- package/dist/artifacts-spreadsheet.js +2 -2
- package/dist/artifacts.d.ts +1 -0
- package/dist/artifacts.js +516 -1413
- package/dist/artifacts.js.map +1 -1
- package/dist/{browser-viewer-2E6R2Y4W.js → browser-viewer-Z7S7QEJL.js} +6 -5
- package/dist/chat-interactive-block-UGBTNB3L.js +11 -0
- package/dist/{chunk-Y3QTZN2F.js → chunk-2VFNCX4E.js} +6 -6
- package/dist/{chunk-UDD6DLLT.js → chunk-3IJJEYW4.js} +15 -3
- package/dist/chunk-3IJJEYW4.js.map +1 -0
- package/dist/chunk-4RVYOY4O.js +379 -0
- package/dist/chunk-4RVYOY4O.js.map +1 -0
- package/dist/chunk-5CVXZA3Y.js +292 -0
- package/dist/chunk-5CVXZA3Y.js.map +1 -0
- package/dist/{chunk-5YK2ZDIG.js → chunk-5J4FOW6Q.js} +2 -10
- package/dist/chunk-5J4FOW6Q.js.map +1 -0
- package/dist/{chunk-KVERXCFY.js → chunk-5KYZIQFY.js} +40 -3
- package/dist/chunk-5KYZIQFY.js.map +1 -0
- package/dist/{chunk-KNDIXZN6.js → chunk-7UAMYXJY.js} +25 -18
- package/dist/{chunk-KNDIXZN6.js.map → chunk-7UAMYXJY.js.map} +1 -1
- package/dist/{chunk-SEEVCT36.js → chunk-A4UJB2MM.js} +2 -2
- package/dist/{chunk-X4HIN6TV.js → chunk-AFLPWUQ7.js} +71 -162
- package/dist/chunk-AFLPWUQ7.js.map +1 -0
- package/dist/chunk-B3V6TG77.js +41 -0
- package/dist/chunk-B3V6TG77.js.map +1 -0
- package/dist/{chunk-XEJEOAOV.js → chunk-B7WMS3CS.js} +51 -40
- package/dist/chunk-B7WMS3CS.js.map +1 -0
- package/dist/{chunk-S5JQ4R22.js → chunk-BDKR6BAR.js} +54 -24
- package/dist/chunk-BDKR6BAR.js.map +1 -0
- package/dist/{chunk-4MDLEHXL.js → chunk-DYWBUX5Q.js} +24 -12
- package/dist/chunk-DYWBUX5Q.js.map +1 -0
- package/dist/{chunk-YZ3YYMOM.js → chunk-E3G7SAYZ.js} +252 -624
- package/dist/chunk-E3G7SAYZ.js.map +1 -0
- package/dist/chunk-JT4JW7BC.js +54 -0
- package/dist/chunk-JT4JW7BC.js.map +1 -0
- package/dist/{chunk-5AZSK6MV.js → chunk-LWNLETQT.js} +5 -5
- package/dist/{chunk-USXVQACU.js → chunk-M7LBYP63.js} +5 -4
- package/dist/{chunk-USXVQACU.js.map → chunk-M7LBYP63.js.map} +1 -1
- package/dist/{chunk-L4OSXQ6H.js → chunk-NBOHNRLJ.js} +1289 -1060
- package/dist/chunk-NBOHNRLJ.js.map +1 -0
- package/dist/chunk-RHREZ7BO.js +11 -0
- package/dist/chunk-RHREZ7BO.js.map +1 -0
- package/dist/chunk-SCOTPE2I.js +589 -0
- package/dist/chunk-SCOTPE2I.js.map +1 -0
- package/dist/chunk-WEHMPOXK.js +39 -0
- package/dist/chunk-WEHMPOXK.js.map +1 -0
- package/dist/chunk-WRHIZYZF.js +988 -0
- package/dist/chunk-WRHIZYZF.js.map +1 -0
- package/dist/{chunk-3E2AITTZ.js → chunk-WUISZ3WU.js} +32 -28
- package/dist/{chunk-3E2AITTZ.js.map → chunk-WUISZ3WU.js.map} +1 -1
- package/dist/chunk-XCHWDJ22.js +107 -0
- package/dist/chunk-XCHWDJ22.js.map +1 -0
- package/dist/{chunk-DUEBTL3N.js → chunk-Y2PRMYLC.js} +4 -3
- package/dist/{chunk-DUEBTL3N.js.map → chunk-Y2PRMYLC.js.map} +1 -1
- package/dist/chunk-YBXQDQFX.js +1772 -0
- package/dist/chunk-YBXQDQFX.js.map +1 -0
- package/dist/chunk-YV4L3ILF.js +9 -0
- package/dist/chunk-YV4L3ILF.js.map +1 -0
- package/dist/{chunk-V2ABIVYJ.js → chunk-ZXSEDZP7.js} +70 -6
- package/dist/chunk-ZXSEDZP7.js.map +1 -0
- package/dist/components/artifacts/artifact-chrome.d.ts +120 -0
- package/dist/components/artifacts/artifact-sandbox.d.ts +27 -0
- package/dist/components/artifacts/chat-interactive-block.d.ts +29 -0
- package/dist/components/artifacts/deferred-chat-media.d.ts +15 -0
- package/dist/components/artifacts/editable-artifact-ui.d.ts +2 -1
- package/dist/components/artifacts/editable-artifact-view.d.ts +46 -0
- package/dist/components/artifacts/index.d.ts +7 -0
- package/dist/components/artifacts/latest-task-runner.d.ts +15 -0
- package/dist/components/artifacts/session-artifact-viewer.d.ts +39 -0
- package/dist/components/artifacts/site-view.d.ts +23 -0
- package/dist/components/browser-select-control.d.ts +3 -1
- package/dist/components/code-editor.d.ts +1 -4
- package/dist/components/desktop-viewer.d.ts +1 -1
- package/dist/components/message-timeline.d.ts +20 -3
- package/dist/components/open-geni-links.d.ts +16 -0
- package/dist/components/session-conversation.d.ts +20 -1
- package/dist/components/timeline-pill-geometry.d.ts +8 -0
- package/dist/components/timeline-pill-placement.d.ts +24 -0
- package/dist/components/usage-limit-notice.d.ts +49 -0
- package/dist/components/usage-member-list.d.ts +91 -0
- package/dist/components/usage-meter.d.ts +73 -0
- package/dist/composer.js +5 -5
- package/dist/{computer-viewer-WMJE6OA3.js → computer-viewer-KJWLH3GI.js} +7 -5
- package/dist/connect.js +7 -6
- package/dist/connect.js.map +1 -1
- package/dist/conversation-timeline.d.ts +1 -1
- package/dist/desktop.d.ts +7 -0
- package/dist/desktop.js +26 -0
- package/dist/desktop.js.map +1 -0
- package/dist/editor.d.ts +7 -0
- package/dist/editor.js +21 -0
- package/dist/editor.js.map +1 -0
- package/dist/hooks/latest-question.d.ts +1 -1
- package/dist/hooks/use-composer.d.ts +4 -0
- package/dist/hooks/use-desktop-stream.d.ts +1 -1
- package/dist/hooks/use-usage.d.ts +40 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +460 -1386
- package/dist/index.js.map +1 -1
- package/dist/interaction.js +8 -6
- package/dist/interaction.js.map +1 -1
- package/dist/{latest-question-QB4EUCW5.js → latest-question-IS445HOW.js} +3 -3
- package/dist/lib/format.d.ts +6 -1
- package/dist/lib/workbench-peers.d.ts +36 -0
- package/dist/machines.js +2 -2
- package/dist/{markdown-table-layout-PFUEZ2U4.js → markdown-table-layout-QXSLK4BY.js} +37 -5
- package/dist/markdown-table-layout-QXSLK4BY.js.map +1 -0
- package/dist/{queue-surface-implementation-IM2HD3SK.js → queue-surface-implementation-2CAQAIHM.js} +2 -2
- package/dist/realtime.js +3 -3
- package/dist/{sandbox-files-PXPIZAFG.js → sandbox-files-AEJTWGT4.js} +8 -5
- package/dist/sandbox-files-AEJTWGT4.js.map +1 -0
- package/dist/session-ui.d.ts +9 -2
- package/dist/session-ui.js +39 -20
- package/dist/session-ui.js.map +1 -1
- package/dist/session.js +4 -4
- package/dist/sites.js +4 -289
- package/dist/sites.js.map +1 -1
- package/dist/terminal.d.ts +8 -0
- package/dist/terminal.js +31 -0
- package/dist/terminal.js.map +1 -0
- package/dist/timeline/allowance-exhausted-row.d.ts +24 -0
- package/dist/timeline/genie-loading.d.ts +3 -1
- package/dist/timeline/types.d.ts +8 -1
- package/dist/{timeline-annotation-selection-ODLVF4OI.js → timeline-annotation-selection-DMLMM2TX.js} +6 -1
- package/dist/timeline-annotation-selection-DMLMM2TX.js.map +1 -0
- package/dist/timeline-pill-geometry-Z23V243M.js +110 -0
- package/dist/timeline-pill-geometry-Z23V243M.js.map +1 -0
- package/dist/usage/allowance-copy.d.ts +25 -0
- package/dist/usage/summary.d.ts +35 -0
- package/dist/usage.d.ts +13 -0
- package/dist/usage.js +1073 -0
- package/dist/usage.js.map +1 -0
- package/package.json +19 -3
- package/src/artifacts.ts +37 -0
- package/src/components/artifacts/artifact-chrome.tsx +413 -0
- package/src/components/artifacts/artifact-sandbox.tsx +185 -0
- package/src/components/artifacts/chat-interactive-block.tsx +260 -0
- package/src/components/artifacts/deferred-chat-media.tsx +67 -0
- package/src/components/artifacts/editable-artifact-ui.tsx +3 -1
- package/src/components/artifacts/editable-artifact-view.tsx +187 -0
- package/src/components/artifacts/editable-artifact-workbench.tsx +5 -2
- package/src/components/artifacts/editable-document.tsx +34 -36
- package/src/components/artifacts/editable-presentation.tsx +21 -16
- package/src/components/artifacts/index.ts +41 -0
- package/src/components/artifacts/latest-task-runner.ts +49 -0
- package/src/components/artifacts/session-artifact-viewer.tsx +376 -0
- package/src/components/artifacts/site-view.tsx +116 -0
- package/src/components/browser-select-control.tsx +4 -1
- package/src/components/browser-viewer.tsx +81 -22
- package/src/components/code-editor.tsx +13 -16
- package/src/components/computer-viewer.tsx +51 -23
- package/src/components/desktop-viewer.tsx +1 -1
- package/src/components/markdown-table-layout.ts +49 -5
- package/src/components/markdown.tsx +5 -2
- package/src/components/message-timeline.tsx +557 -516
- package/src/components/open-geni-links.tsx +24 -0
- package/src/components/sandbox-terminal.tsx +48 -11
- package/src/components/session-chrome.tsx +22 -3
- package/src/components/session-conversation.tsx +195 -102
- package/src/components/timeline-annotation-selection.tsx +7 -0
- package/src/components/timeline-pill-geometry.ts +169 -0
- package/src/components/timeline-pill-placement.ts +99 -0
- package/src/components/usage-limit-notice.tsx +179 -0
- package/src/components/usage-member-list.tsx +792 -0
- package/src/components/usage-meter.tsx +382 -0
- package/src/conversation-timeline.ts +10 -2
- package/src/desktop.ts +24 -0
- package/src/editor.ts +13 -0
- package/src/hooks/use-available-models.ts +1 -1
- package/src/hooks/use-composer.ts +57 -2
- package/src/hooks/use-desktop-stream.ts +19 -28
- package/src/hooks/use-usage.ts +100 -0
- package/src/index.ts +22 -0
- package/src/lib/format.ts +32 -6
- package/src/lib/workbench-peers.ts +62 -0
- package/src/session-ui.ts +22 -0
- package/src/terminal.ts +26 -0
- package/src/timeline/activity-rail.tsx +5 -3
- package/src/timeline/allowance-exhausted-row.tsx +86 -0
- package/src/timeline/genie-loading.tsx +16 -6
- package/src/timeline/projection.ts +78 -4
- package/src/timeline/types.ts +8 -0
- package/src/usage/allowance-copy.ts +64 -0
- package/src/usage/summary.ts +93 -0
- package/src/usage.ts +50 -0
- package/styles/compiled.css +325 -0
- package/dist/chunk-4MDLEHXL.js.map +0 -1
- package/dist/chunk-5YK2ZDIG.js.map +0 -1
- package/dist/chunk-KVERXCFY.js.map +0 -1
- package/dist/chunk-L4OSXQ6H.js.map +0 -1
- package/dist/chunk-S5JQ4R22.js.map +0 -1
- package/dist/chunk-UDD6DLLT.js.map +0 -1
- package/dist/chunk-UGMKPUEM.js +0 -299
- package/dist/chunk-UGMKPUEM.js.map +0 -1
- package/dist/chunk-V2ABIVYJ.js.map +0 -1
- package/dist/chunk-X4HIN6TV.js.map +0 -1
- package/dist/chunk-XEJEOAOV.js.map +0 -1
- package/dist/chunk-YZ3YYMOM.js.map +0 -1
- package/dist/markdown-table-layout-PFUEZ2U4.js.map +0 -1
- package/dist/timeline-annotation-selection-ODLVF4OI.js.map +0 -1
- /package/dist/{browser-viewer-2E6R2Y4W.js.map → browser-viewer-Z7S7QEJL.js.map} +0 -0
- /package/dist/{computer-viewer-WMJE6OA3.js.map → chat-interactive-block-UGBTNB3L.js.map} +0 -0
- /package/dist/{chunk-Y3QTZN2F.js.map → chunk-2VFNCX4E.js.map} +0 -0
- /package/dist/{chunk-SEEVCT36.js.map → chunk-A4UJB2MM.js.map} +0 -0
- /package/dist/{chunk-5AZSK6MV.js.map → chunk-LWNLETQT.js.map} +0 -0
- /package/dist/{sandbox-files-PXPIZAFG.js.map → computer-viewer-KJWLH3GI.js.map} +0 -0
- /package/dist/{latest-question-QB4EUCW5.js.map → latest-question-IS445HOW.js.map} +0 -0
- /package/dist/{queue-surface-implementation-IM2HD3SK.js.map → queue-surface-implementation-2CAQAIHM.js.map} +0 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { TimelinePillPlacement, TimelinePillPosition } from "./timeline-pill-placement";
|
|
2
|
+
|
|
3
|
+
const INTERACTIVE =
|
|
4
|
+
'a[href], button, input, select, textarea, summary, [role="button"], [role="link"], [role="menuitem"], [role="tab"], [role="switch"], [role="checkbox"], [contenteditable="true"]';
|
|
5
|
+
|
|
6
|
+
/** A control this wide is a row (a disclosure header); only what it draws counts. */
|
|
7
|
+
const ROW_WIDTH_RATIO = 0.8;
|
|
8
|
+
|
|
9
|
+
/** The full contextual label may not fit beside a compact toolbar on phones. */
|
|
10
|
+
export function chooseQuestionPosition(
|
|
11
|
+
pill: HTMLElement,
|
|
12
|
+
frame: HTMLElement,
|
|
13
|
+
scroller: HTMLElement,
|
|
14
|
+
preference: readonly TimelinePillPlacement[],
|
|
15
|
+
current: TimelinePillPosition,
|
|
16
|
+
): TimelinePillPosition {
|
|
17
|
+
const rect = pill.getBoundingClientRect();
|
|
18
|
+
const bounds = frame.getBoundingClientRect();
|
|
19
|
+
const view = scroller.getBoundingClientRect();
|
|
20
|
+
if (!rect.width || !view.width) return current;
|
|
21
|
+
const style = getComputedStyle(frame);
|
|
22
|
+
const baseTop = bounds.top - current.offsetY;
|
|
23
|
+
const left = (placement: TimelinePillPlacement) =>
|
|
24
|
+
placement === "start"
|
|
25
|
+
? bounds.left + parseFloat(style.paddingLeft || "0")
|
|
26
|
+
: placement === "end"
|
|
27
|
+
? bounds.right - parseFloat(style.paddingRight || "0") - rect.width
|
|
28
|
+
: bounds.left + (bounds.width - rect.width) / 2;
|
|
29
|
+
const controls: DOMRect[] = [];
|
|
30
|
+
for (const control of scroller.querySelectorAll<HTMLElement>(INTERACTIVE)) {
|
|
31
|
+
const box = control.getBoundingClientRect();
|
|
32
|
+
if (!box.width || !box.height || box.bottom <= baseTop || box.top >= view.bottom) continue;
|
|
33
|
+
if (box.width < view.width * ROW_WIDTH_RATIO) controls.push(box);
|
|
34
|
+
else {
|
|
35
|
+
for (const icon of control.querySelectorAll("svg, img, canvas, video"))
|
|
36
|
+
controls.push(icon.getBoundingClientRect());
|
|
37
|
+
const walker = scroller.ownerDocument.createTreeWalker(control, NodeFilter.SHOW_TEXT);
|
|
38
|
+
for (let text = walker.nextNode(); text; text = walker.nextNode()) {
|
|
39
|
+
if (!text.textContent?.trim()) continue;
|
|
40
|
+
const range = scroller.ownerDocument.createRange();
|
|
41
|
+
range.selectNodeContents(text);
|
|
42
|
+
controls.push(...range.getClientRects());
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const clear = (placement: TimelinePillPlacement, offsetY: number) =>
|
|
47
|
+
!controls.some(
|
|
48
|
+
(control) =>
|
|
49
|
+
control.right > left(placement) &&
|
|
50
|
+
control.left < left(placement) + rect.width &&
|
|
51
|
+
control.bottom > baseTop + offsetY &&
|
|
52
|
+
control.top < baseTop + offsetY + rect.height,
|
|
53
|
+
);
|
|
54
|
+
const order = [current.placement, ...preference.filter((value) => value !== current.placement)];
|
|
55
|
+
// Return to the normal strip once it is clear, without touching scroll geometry.
|
|
56
|
+
for (const placement of order) if (clear(placement, 0)) return { placement, offsetY: 0 };
|
|
57
|
+
const offsets = [...new Set(controls.map((control) => control.bottom + 4 - baseTop))]
|
|
58
|
+
.filter((offset) => offset > 0 && baseTop + offset + rect.height <= view.bottom)
|
|
59
|
+
.sort((a, b) => a - b);
|
|
60
|
+
for (const offsetY of offsets) {
|
|
61
|
+
for (const placement of order) if (clear(placement, offsetY)) return { placement, offsetY };
|
|
62
|
+
}
|
|
63
|
+
return current;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Hit-testing for useTimelinePillPlacement, loaded only once a pill shows so it
|
|
68
|
+
* stays out of a session's first load.
|
|
69
|
+
*/
|
|
70
|
+
export function choosePlacement(
|
|
71
|
+
pill: HTMLElement,
|
|
72
|
+
frame: HTMLElement,
|
|
73
|
+
scroller: HTMLElement,
|
|
74
|
+
preference: readonly TimelinePillPlacement[],
|
|
75
|
+
current: TimelinePillPlacement,
|
|
76
|
+
): TimelinePillPlacement {
|
|
77
|
+
const pillRect = pill.getBoundingClientRect();
|
|
78
|
+
const frameRect = frame.getBoundingClientRect();
|
|
79
|
+
const view = scroller.getBoundingClientRect();
|
|
80
|
+
if (pillRect.width === 0 || view.width === 0) return current;
|
|
81
|
+
const inset = Math.max(0, pillRect.left - frameRect.left, frameRect.right - pillRect.right);
|
|
82
|
+
const gutter = Math.min(inset, parseFloat(getComputedStyle(scroller).paddingLeft) || 16);
|
|
83
|
+
const left = (placement: TimelinePillPlacement) =>
|
|
84
|
+
placement === "start"
|
|
85
|
+
? frameRect.left + gutter
|
|
86
|
+
: placement === "end"
|
|
87
|
+
? frameRect.right - gutter - pillRect.width
|
|
88
|
+
: frameRect.left + (frameRect.width - pillRect.width) / 2;
|
|
89
|
+
const collisions = (placement: TimelinePillPlacement) =>
|
|
90
|
+
countCollisions(
|
|
91
|
+
pill,
|
|
92
|
+
scroller,
|
|
93
|
+
view,
|
|
94
|
+
left(placement),
|
|
95
|
+
pillRect.top,
|
|
96
|
+
pillRect.width,
|
|
97
|
+
pillRect.height,
|
|
98
|
+
);
|
|
99
|
+
// Stay put while the current spot is clear, so the pill does not wander.
|
|
100
|
+
if (collisions(current) === 0) return current;
|
|
101
|
+
let best = current;
|
|
102
|
+
let fewest = Number.POSITIVE_INFINITY;
|
|
103
|
+
for (const candidate of preference) {
|
|
104
|
+
const count = candidate === current ? collisions(current) : collisions(candidate);
|
|
105
|
+
if (count === 0) return candidate;
|
|
106
|
+
if (count < fewest) {
|
|
107
|
+
fewest = count;
|
|
108
|
+
best = candidate;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return best;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function countCollisions(
|
|
115
|
+
pill: HTMLElement,
|
|
116
|
+
scroller: HTMLElement,
|
|
117
|
+
view: DOMRect,
|
|
118
|
+
left: number,
|
|
119
|
+
top: number,
|
|
120
|
+
width: number,
|
|
121
|
+
height: number,
|
|
122
|
+
): number {
|
|
123
|
+
const document = scroller.ownerDocument;
|
|
124
|
+
let count = 0;
|
|
125
|
+
for (const fx of [0.06, 0.3, 0.5, 0.7, 0.94]) {
|
|
126
|
+
for (const fy of [0.2, 0.5, 0.8]) {
|
|
127
|
+
const x = left + width * fx;
|
|
128
|
+
const y = top + height * fy;
|
|
129
|
+
if (x < view.left || x > view.right || y < view.top || y > view.bottom) continue;
|
|
130
|
+
if (coversControl(document.elementsFromPoint(x, y), pill, scroller, view, x, y)) count += 1;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return count;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function coversControl(
|
|
137
|
+
stack: Element[],
|
|
138
|
+
pill: HTMLElement,
|
|
139
|
+
scroller: HTMLElement,
|
|
140
|
+
view: DOMRect,
|
|
141
|
+
x: number,
|
|
142
|
+
y: number,
|
|
143
|
+
): boolean {
|
|
144
|
+
for (const element of stack) {
|
|
145
|
+
if (pill.contains(element)) continue;
|
|
146
|
+
if (!scroller.contains(element) || element === scroller) return false;
|
|
147
|
+
const control = element.closest(INTERACTIVE);
|
|
148
|
+
if (!control || !scroller.contains(control)) return false;
|
|
149
|
+
// A compact control (a link, an icon button) is covered anywhere on its box.
|
|
150
|
+
if (control.getBoundingClientRect().width < view.width * ROW_WIDTH_RATIO) return true;
|
|
151
|
+
// A full-width row (a disclosure header) only where it draws something: an
|
|
152
|
+
// icon or the glyphs of its label, never its empty background.
|
|
153
|
+
if (element.closest("svg, img, canvas, video")) return true;
|
|
154
|
+
return textUnderPoint(element, x, y);
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function textUnderPoint(element: Element, x: number, y: number): boolean {
|
|
160
|
+
const range = element.ownerDocument.createRange();
|
|
161
|
+
for (const node of element.childNodes) {
|
|
162
|
+
if (node.nodeType !== Node.TEXT_NODE || !node.textContent?.trim()) continue;
|
|
163
|
+
range.selectNodeContents(node);
|
|
164
|
+
for (const rect of range.getClientRects()) {
|
|
165
|
+
if (x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom) return true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { type RefObject, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
/** Where a floating timeline pill sits along its edge of the conversation. */
|
|
4
|
+
export type TimelinePillPlacement = "start" | "center" | "end";
|
|
5
|
+
export type TimelinePillPosition = { placement: TimelinePillPlacement; offsetY: number };
|
|
6
|
+
|
|
7
|
+
const RECHECK_MS = 1000;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Floating pills (Jump to latest, Back to your message) sit over the scrolling
|
|
11
|
+
* conversation. Prefer sliding one sideways when its spot would cover
|
|
12
|
+
* a control: a link, a button, or the label and chevron of a full-width row
|
|
13
|
+
* such as the active turn's "Working" header. Plain prose may sit under a pill;
|
|
14
|
+
* controls may not. The top contextual pill can also move below a toolbar when
|
|
15
|
+
* no horizontal slot fits. Only the pill moves — the scroller's size, padding, and
|
|
16
|
+
* scroll position never change — so timeline anchoring stays untouched.
|
|
17
|
+
*/
|
|
18
|
+
export function useTimelinePillPlacement({
|
|
19
|
+
pillRef,
|
|
20
|
+
scrollerRef,
|
|
21
|
+
active,
|
|
22
|
+
preference,
|
|
23
|
+
allowDownwardFallback = false,
|
|
24
|
+
}: {
|
|
25
|
+
pillRef: RefObject<HTMLElement | null>;
|
|
26
|
+
scrollerRef: RefObject<HTMLElement | null>;
|
|
27
|
+
active: boolean;
|
|
28
|
+
/** Placements in order of preference; the first is the resting position. */
|
|
29
|
+
preference: readonly TimelinePillPlacement[];
|
|
30
|
+
allowDownwardFallback?: boolean;
|
|
31
|
+
}): TimelinePillPosition {
|
|
32
|
+
const [position, setPosition] = useState<TimelinePillPosition>({
|
|
33
|
+
placement: preference[0]!,
|
|
34
|
+
offsetY: 0,
|
|
35
|
+
});
|
|
36
|
+
const key = preference.join(",");
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!active) {
|
|
40
|
+
setPosition({ placement: preference[0]!, offsetY: 0 });
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const scroller = scrollerRef.current;
|
|
44
|
+
if (!scroller) return;
|
|
45
|
+
let frame = 0;
|
|
46
|
+
let current: TimelinePillPosition = { placement: preference[0]!, offsetY: 0 };
|
|
47
|
+
let geometry: typeof import("./timeline-pill-geometry") | null = null;
|
|
48
|
+
let disposed = false;
|
|
49
|
+
void import("./timeline-pill-geometry").then((loaded) => {
|
|
50
|
+
if (disposed) return;
|
|
51
|
+
geometry = loaded;
|
|
52
|
+
schedule();
|
|
53
|
+
});
|
|
54
|
+
const evaluate = () => {
|
|
55
|
+
frame = 0;
|
|
56
|
+
const pill = pillRef.current;
|
|
57
|
+
const frameElement = pill?.offsetParent;
|
|
58
|
+
if (!geometry || !pill || !(frameElement instanceof HTMLElement)) return;
|
|
59
|
+
const next = allowDownwardFallback
|
|
60
|
+
? geometry.chooseQuestionPosition(pill, frameElement, scroller, preference, current)
|
|
61
|
+
: {
|
|
62
|
+
placement: geometry.choosePlacement(
|
|
63
|
+
pill,
|
|
64
|
+
frameElement,
|
|
65
|
+
scroller,
|
|
66
|
+
preference,
|
|
67
|
+
current.placement,
|
|
68
|
+
),
|
|
69
|
+
offsetY: 0,
|
|
70
|
+
};
|
|
71
|
+
if (next.placement !== current.placement || next.offsetY !== current.offsetY) {
|
|
72
|
+
current = next;
|
|
73
|
+
setPosition(next);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const schedule = () => {
|
|
77
|
+
if (frame === 0) frame = requestAnimationFrame(evaluate);
|
|
78
|
+
};
|
|
79
|
+
schedule();
|
|
80
|
+
const view = scroller.ownerDocument.defaultView;
|
|
81
|
+
scroller.addEventListener("scroll", schedule, { passive: true });
|
|
82
|
+
view?.addEventListener("resize", schedule);
|
|
83
|
+
// Content and panel width can change under a stationary reader (a streaming
|
|
84
|
+
// row, a ticking elapsed time, a resized host panel), so look again now and
|
|
85
|
+
// then while the pill is shown.
|
|
86
|
+
const timer = setInterval(schedule, RECHECK_MS);
|
|
87
|
+
return () => {
|
|
88
|
+
disposed = true;
|
|
89
|
+
if (frame !== 0) cancelAnimationFrame(frame);
|
|
90
|
+
scroller.removeEventListener("scroll", schedule);
|
|
91
|
+
view?.removeEventListener("resize", schedule);
|
|
92
|
+
clearInterval(timer);
|
|
93
|
+
};
|
|
94
|
+
// `key` stands in for the preference array's contents.
|
|
95
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
96
|
+
}, [active, key, pillRef, scrollerRef, allowDownwardFallback]);
|
|
97
|
+
|
|
98
|
+
return active ? position : { placement: preference[0]!, offsetY: 0 };
|
|
99
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { UsageAllowancePeriod, WorkspaceUsageResponse } from "@opengeni/sdk/usage-allowances";
|
|
2
|
+
import { GaugeIcon, XIcon } from "lucide-react";
|
|
3
|
+
import { useEffect, useState, type ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
import { useUsage, type UsageClientLike } from "../hooks/use-usage";
|
|
6
|
+
import { cn } from "../lib/cn";
|
|
7
|
+
import {
|
|
8
|
+
allowanceLabels,
|
|
9
|
+
allowanceResetSentence,
|
|
10
|
+
formatAllowanceInstant,
|
|
11
|
+
type AllowanceLabels,
|
|
12
|
+
} from "../usage/allowance-copy";
|
|
13
|
+
import { summarizeUsage, usagePercentLabel, type UsageSummary } from "../usage/summary";
|
|
14
|
+
|
|
15
|
+
export type UsageLimitNoticeLabels = AllowanceLabels & {
|
|
16
|
+
/** "You've used 85% of your usage limit." */
|
|
17
|
+
memberWarning: (percent: string) => string;
|
|
18
|
+
/** "This workspace has used 85% of its usage budget." */
|
|
19
|
+
workspaceWarning: (percent: string) => string;
|
|
20
|
+
memberExhausted: string;
|
|
21
|
+
workspaceExhausted: string;
|
|
22
|
+
dismiss: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const DEFAULT_USAGE_LIMIT_NOTICE_LABELS: UsageLimitNoticeLabels = {
|
|
26
|
+
...allowanceLabels(),
|
|
27
|
+
memberWarning: (percent) => `You've used ${percent}% of your usage limit.`,
|
|
28
|
+
workspaceWarning: (percent) => `This workspace has used ${percent}% of its usage budget.`,
|
|
29
|
+
memberExhausted: "You've reached your usage limit.",
|
|
30
|
+
workspaceExhausted: "This workspace has reached its usage limit.",
|
|
31
|
+
dismiss: "Dismiss",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type NoticeBaseProps = {
|
|
35
|
+
labels?: Partial<UsageLimitNoticeLabels> | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Your own next step beside the message, for example an "Upgrade" or
|
|
38
|
+
* "Request more" button. Receives the summary so it can differ by scope.
|
|
39
|
+
*/
|
|
40
|
+
action?: ((summary: UsageSummary) => ReactNode) | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Remember a dismissed warning for this browser tab. The key should name the
|
|
43
|
+
* workspace; the period and scope are added for you, so a new warning (or a
|
|
44
|
+
* new period) shows again. Reaching the limit is never dismissible.
|
|
45
|
+
*/
|
|
46
|
+
dismissStorageKey?: string | undefined;
|
|
47
|
+
className?: string | undefined;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type UsageLimitNoticeProps = NoticeBaseProps & {
|
|
51
|
+
/** A usage response you already loaded; omit it to read `/usage/me`. */
|
|
52
|
+
usage?: WorkspaceUsageResponse | null | undefined;
|
|
53
|
+
client?: UsageClientLike | undefined;
|
|
54
|
+
workspaceId?: string | undefined;
|
|
55
|
+
period?: UsageAllowancePeriod | undefined;
|
|
56
|
+
refreshKey?: unknown;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A calm line for the composer when a member is close to, or at, a usage
|
|
61
|
+
* limit: what happened, who can raise it, and when it resets. Renders nothing
|
|
62
|
+
* while usage is comfortable, unlimited, loading, or unreadable.
|
|
63
|
+
*/
|
|
64
|
+
export function UsageLimitNotice({
|
|
65
|
+
usage,
|
|
66
|
+
client,
|
|
67
|
+
workspaceId,
|
|
68
|
+
period,
|
|
69
|
+
refreshKey,
|
|
70
|
+
...view
|
|
71
|
+
}: UsageLimitNoticeProps) {
|
|
72
|
+
if (usage !== undefined) {
|
|
73
|
+
return <UsageLimitNoticeView {...view} summary={usage ? summarizeUsage(usage) : null} />;
|
|
74
|
+
}
|
|
75
|
+
return (
|
|
76
|
+
<LoadingNotice
|
|
77
|
+
{...view}
|
|
78
|
+
client={client}
|
|
79
|
+
workspaceId={workspaceId}
|
|
80
|
+
period={period}
|
|
81
|
+
refreshKey={refreshKey}
|
|
82
|
+
/>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function LoadingNotice({
|
|
87
|
+
client,
|
|
88
|
+
workspaceId,
|
|
89
|
+
period,
|
|
90
|
+
refreshKey,
|
|
91
|
+
...view
|
|
92
|
+
}: NoticeBaseProps &
|
|
93
|
+
Pick<UsageLimitNoticeProps, "client" | "workspaceId" | "period" | "refreshKey">) {
|
|
94
|
+
const { summary } = useUsage({ client, workspaceId, period, refreshKey });
|
|
95
|
+
return <UsageLimitNoticeView {...view} summary={summary} />;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function readDismissed(key: string | null): boolean {
|
|
99
|
+
if (!key || typeof sessionStorage === "undefined") return false;
|
|
100
|
+
try {
|
|
101
|
+
return sessionStorage.getItem(key) === "1";
|
|
102
|
+
} catch {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Presentational notice for a summary you computed (`summarizeUsage`). */
|
|
108
|
+
export function UsageLimitNoticeView({
|
|
109
|
+
summary,
|
|
110
|
+
labels: overrides,
|
|
111
|
+
action,
|
|
112
|
+
dismissStorageKey,
|
|
113
|
+
className,
|
|
114
|
+
}: NoticeBaseProps & { summary: UsageSummary | null }) {
|
|
115
|
+
const labels = { ...DEFAULT_USAGE_LIMIT_NOTICE_LABELS, ...overrides };
|
|
116
|
+
const binding = summary?.binding ?? null;
|
|
117
|
+
const state = summary?.state;
|
|
118
|
+
const key =
|
|
119
|
+
dismissStorageKey && binding && state === "warning"
|
|
120
|
+
? `${dismissStorageKey}:warning:${binding.scope}:${binding.resetsAt ?? "none"}`
|
|
121
|
+
: null;
|
|
122
|
+
const [dismissed, setDismissed] = useState(() => readDismissed(key));
|
|
123
|
+
useEffect(() => setDismissed(readDismissed(key)), [key]);
|
|
124
|
+
if (!summary || !binding || (state !== "warning" && state !== "exhausted")) return null;
|
|
125
|
+
if (state === "warning" && dismissed) return null;
|
|
126
|
+
const workspace = binding.scope === "workspace";
|
|
127
|
+
const exhausted = state === "exhausted";
|
|
128
|
+
const headline = exhausted
|
|
129
|
+
? workspace
|
|
130
|
+
? labels.workspaceExhausted
|
|
131
|
+
: labels.memberExhausted
|
|
132
|
+
: workspace
|
|
133
|
+
? labels.workspaceWarning(usagePercentLabel(binding.fraction))
|
|
134
|
+
: labels.memberWarning(usagePercentLabel(binding.fraction));
|
|
135
|
+
const reset = allowanceResetSentence(labels, binding.resetsAt);
|
|
136
|
+
const dismiss = () => {
|
|
137
|
+
setDismissed(true);
|
|
138
|
+
if (!key) return;
|
|
139
|
+
try {
|
|
140
|
+
sessionStorage.setItem(key, "1");
|
|
141
|
+
} catch {
|
|
142
|
+
// Storage can be unavailable (privacy mode); the in-memory dismissal holds.
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
return (
|
|
146
|
+
<div
|
|
147
|
+
role="status"
|
|
148
|
+
data-og-usage-notice={exhausted ? "exhausted" : "warning"}
|
|
149
|
+
data-og-usage-scope={binding.scope}
|
|
150
|
+
className={cn(
|
|
151
|
+
"og-root flex min-w-0 items-start gap-2 px-3.5 pt-2.5 text-og-sm md:px-4",
|
|
152
|
+
className,
|
|
153
|
+
)}
|
|
154
|
+
>
|
|
155
|
+
<GaugeIcon aria-hidden className="mt-0.5 size-3.5 shrink-0 text-og-status-waiting" />
|
|
156
|
+
<p className="min-w-0 flex-1 text-og-fg-muted">
|
|
157
|
+
<span className={cn(exhausted && "font-medium text-og-fg")}>{headline}</span>{" "}
|
|
158
|
+
{exhausted ? <>{workspace ? labels.workspaceRemedy : labels.memberRemedy} </> : null}
|
|
159
|
+
<span
|
|
160
|
+
className="whitespace-nowrap"
|
|
161
|
+
title={binding.resetsAt ? formatAllowanceInstant(binding.resetsAt) : undefined}
|
|
162
|
+
>
|
|
163
|
+
{reset}
|
|
164
|
+
</span>
|
|
165
|
+
</p>
|
|
166
|
+
{action ? <div className="shrink-0">{action(summary)}</div> : null}
|
|
167
|
+
{!exhausted ? (
|
|
168
|
+
<button
|
|
169
|
+
type="button"
|
|
170
|
+
aria-label={labels.dismiss}
|
|
171
|
+
onClick={dismiss}
|
|
172
|
+
className="-mt-0.5 -mr-1 grid size-6 shrink-0 place-items-center rounded-og-sm text-og-fg-subtle transition hover:bg-og-surface-2 hover:text-og-fg focus-visible:outline-2 focus-visible:outline-og-accent pointer-coarse:size-9"
|
|
173
|
+
>
|
|
174
|
+
<XIcon aria-hidden className="size-3.5" />
|
|
175
|
+
</button>
|
|
176
|
+
) : null}
|
|
177
|
+
</div>
|
|
178
|
+
);
|
|
179
|
+
}
|