jupyterlab-codex-sidebar 0.1.4 → 0.1.6
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/.claude/settings.local.json +9 -0
- package/.github/workflows/unit-tests.yml +27 -0
- package/.jupyterlab-playwright.log +0 -0
- package/README.md +83 -9
- package/docs/images/codex-sidebar-screenshot.png +0 -0
- package/jupyterlab_codex/handlers.py +938 -297
- package/jupyterlab_codex/labextension/package.json +13 -3
- package/jupyterlab_codex/labextension/static/525.224526d045c727069de6.js +2 -0
- package/jupyterlab_codex/labextension/static/737.e7de3ad9dd6ded798340.js +1 -0
- package/jupyterlab_codex/labextension/static/remoteEntry.6ef5e7167763a316c000.js +1 -0
- package/jupyterlab_codex/protocol.py +297 -0
- package/jupyterlab_codex/runner.py +58 -15
- package/jupyterlab_codex/sessions.py +582 -97
- package/lib/codexChat.d.ts +13 -0
- package/lib/codexChat.js +2506 -0
- package/lib/codexChat.js.map +1 -0
- package/lib/codexChatAttachmentDedup.d.ts +10 -0
- package/lib/codexChatAttachmentDedup.js +35 -0
- package/lib/codexChatAttachmentDedup.js.map +1 -0
- package/lib/codexChatAttachmentLimit.d.ts +18 -0
- package/lib/codexChatAttachmentLimit.js +50 -0
- package/lib/codexChatAttachmentLimit.js.map +1 -0
- package/lib/codexChatAttachmentState.d.ts +15 -0
- package/lib/codexChatAttachmentState.js +16 -0
- package/lib/codexChatAttachmentState.js.map +1 -0
- package/lib/codexChatDocumentUtils.d.ts +70 -0
- package/lib/codexChatDocumentUtils.js +506 -0
- package/lib/codexChatDocumentUtils.js.map +1 -0
- package/lib/codexChatFormatting.d.ts +11 -0
- package/lib/codexChatFormatting.js +83 -0
- package/lib/codexChatFormatting.js.map +1 -0
- package/lib/codexChatNotice.d.ts +3 -0
- package/lib/codexChatNotice.js +74 -0
- package/lib/codexChatNotice.js.map +1 -0
- package/lib/codexChatPersistence.d.ts +35 -0
- package/lib/codexChatPersistence.js +158 -0
- package/lib/codexChatPersistence.js.map +1 -0
- package/lib/codexChatPrimitives.d.ts +44 -0
- package/lib/codexChatPrimitives.js +156 -0
- package/lib/codexChatPrimitives.js.map +1 -0
- package/lib/codexChatRender.d.ts +24 -0
- package/lib/codexChatRender.js +293 -0
- package/lib/codexChatRender.js.map +1 -0
- package/lib/codexChatSessionFactory.d.ts +15 -0
- package/lib/codexChatSessionFactory.js +45 -0
- package/lib/codexChatSessionFactory.js.map +1 -0
- package/lib/codexChatSessionKey.d.ts +3 -0
- package/lib/codexChatSessionKey.js +14 -0
- package/lib/codexChatSessionKey.js.map +1 -0
- package/lib/codexChatStorage.d.ts +4 -0
- package/lib/codexChatStorage.js +37 -0
- package/lib/codexChatStorage.js.map +1 -0
- package/lib/codexSessionResolver.d.ts +12 -0
- package/lib/codexSessionResolver.js +38 -0
- package/lib/codexSessionResolver.js.map +1 -0
- package/lib/handlers/activitySummarizer.d.ts +15 -0
- package/lib/handlers/activitySummarizer.js +327 -0
- package/lib/handlers/activitySummarizer.js.map +1 -0
- package/lib/handlers/codexMessageTypes.d.ts +30 -0
- package/lib/handlers/codexMessageTypes.js +2 -0
- package/lib/handlers/codexMessageTypes.js.map +1 -0
- package/lib/handlers/codexMessageUtils.d.ts +46 -0
- package/lib/handlers/codexMessageUtils.js +144 -0
- package/lib/handlers/codexMessageUtils.js.map +1 -0
- package/lib/handlers/handleCodexSocketMessage.d.ts +107 -0
- package/lib/handlers/handleCodexSocketMessage.js +78 -0
- package/lib/handlers/handleCodexSocketMessage.js.map +1 -0
- package/lib/handlers/sessionSyncHandler.d.ts +34 -0
- package/lib/handlers/sessionSyncHandler.js +181 -0
- package/lib/handlers/sessionSyncHandler.js.map +1 -0
- package/lib/hooks/useCodexSocket.d.ts +15 -0
- package/lib/hooks/useCodexSocket.js +84 -0
- package/lib/hooks/useCodexSocket.js.map +1 -0
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/panel.d.ts +1 -11
- package/lib/panel.js +1 -2815
- package/lib/panel.js.map +1 -1
- package/lib/protocol.d.ts +235 -0
- package/lib/protocol.js +278 -0
- package/lib/protocol.js.map +1 -0
- package/package.json +13 -3
- package/playwright.config.cjs +27 -0
- package/playwright.unit.config.cjs +19 -0
- package/pyproject.toml +1 -1
- package/release.sh +52 -14
- package/scripts/run_playwright_e2e.sh +96 -0
- package/scripts/run_playwright_freeze_repro.sh +58 -0
- package/scripts/run_playwright_queue_repro.sh +60 -0
- package/scripts/run_playwright_repro.sh +55 -0
- package/src/codexChat.tsx +3914 -0
- package/src/codexChatAttachmentDedup.ts +47 -0
- package/src/codexChatAttachmentLimit.ts +81 -0
- package/src/codexChatAttachmentState.ts +37 -0
- package/src/codexChatDocumentUtils.ts +644 -0
- package/src/codexChatFormatting.ts +94 -0
- package/src/codexChatNotice.ts +95 -0
- package/src/codexChatPersistence.ts +191 -0
- package/src/codexChatPrimitives.tsx +446 -0
- package/src/codexChatRender.tsx +376 -0
- package/src/codexChatSessionFactory.ts +79 -0
- package/src/codexChatSessionKey.ts +16 -0
- package/src/codexChatStorage.ts +36 -0
- package/src/codexSessionResolver.ts +56 -0
- package/src/handlers/activitySummarizer.ts +369 -0
- package/src/handlers/codexMessageTypes.ts +34 -0
- package/src/handlers/codexMessageUtils.ts +217 -0
- package/src/handlers/handleCodexSocketMessage.ts +204 -0
- package/src/handlers/sessionSyncHandler.ts +308 -0
- package/src/hooks/useCodexSocket.ts +109 -0
- package/src/index.ts +1 -1
- package/src/panel.tsx +1 -4184
- package/src/protocol.ts +582 -0
- package/style/index.css +480 -11
- package/test-results/.last-run.json +4 -0
- package/test.py +0 -0
- package/tests/e2e/cell-output-error-tail.spec.js +156 -0
- package/tests/e2e/codex-ui-test-helpers.js +138 -0
- package/tests/e2e/fixtures/notebooks/error-output-tail.ipynb +58 -0
- package/tests/e2e/fixtures/notebooks/error-output-tail.py +19 -0
- package/tests/e2e/fixtures/notebooks/tab1.ipynb +322 -0
- package/tests/e2e/fixtures/notebooks/tab1.py +272 -0
- package/tests/e2e/fixtures/notebooks/tab2.ipynb +252 -0
- package/tests/e2e/fixtures/notebooks/tab2.py +231 -0
- package/tests/e2e/fixtures/notebooks/tab3.ipynb +403 -0
- package/tests/e2e/fixtures/notebooks/tab3.py +331 -0
- package/tests/e2e/fixtures/notebooks/tab4.py +339 -0
- package/tests/e2e/freeze-notebook-tabs-repro.spec.js +295 -0
- package/tests/e2e/mock-codex-cli-flood.py +127 -0
- package/tests/e2e/mock-codex-cli-prompt-echo.py +88 -0
- package/tests/e2e/mock-codex-cli.py +95 -0
- package/tests/e2e/queue-multitab-repro.spec.js +189 -0
- package/tests/test_handlers.py +116 -0
- package/tests/test_protocol.py +169 -0
- package/tests/test_session_store_limits.py +50 -0
- package/tests/unit/codexChatAttachmentDedup.spec.ts +56 -0
- package/tests/unit/codexChatAttachmentLimit.spec.ts +57 -0
- package/tests/unit/codexChatAttachmentState.spec.ts +71 -0
- package/tests/unit/codexChatDocumentUtils.spec.ts +63 -0
- package/tests/unit/codexChatLimit.spec.ts +18 -0
- package/tests/unit/codexChatNotice.spec.ts +45 -0
- package/tests/unit/codexChatPersistence.spec.ts +199 -0
- package/tests/unit/codexChatSessionFactory.spec.ts +94 -0
- package/tests/unit/codexChatSessionKey.spec.ts +18 -0
- package/tests/unit/codexMessageUtils.spec.ts +89 -0
- package/tests/unit/codexSessionResolver.spec.ts +92 -0
- package/tests/unit/handleCodexSocketMessage.spec.ts +476 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/webpack.config.js +6 -0
- package/jupyterlab_codex/labextension/static/504.335f3447c84ba3d74517.js +0 -2
- package/jupyterlab_codex/labextension/static/972.8e856719e40acc1ef4cb.js +0 -1
- package/jupyterlab_codex/labextension/static/remoteEntry.a2982f776a1f0f515640.js +0 -1
- /package/jupyterlab_codex/labextension/static/{504.335f3447c84ba3d74517.js.LICENSE.txt → 525.224526d045c727069de6.js.LICENSE.txt} +0 -0
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
import { truncateEnd as truncateEndShared } from './handlers/codexMessageUtils';
|
|
2
|
+
const truncateEnd = truncateEndShared;
|
|
3
|
+
export const MESSAGE_SELECTION_PREVIEW_DISPLAY_MAX_CHARS = 500;
|
|
4
|
+
export const MESSAGE_SELECTION_PREVIEW_STORED_MAX_CHARS = 500;
|
|
5
|
+
export function getDocumentContext(widget) {
|
|
6
|
+
return widget && widget.context ? widget.context : null;
|
|
7
|
+
}
|
|
8
|
+
export function getSupportedDocumentPath(widget) {
|
|
9
|
+
const rawPath = typeof widget?.context?.path === 'string' ? widget.context.path.trim() : '';
|
|
10
|
+
if (!rawPath) {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
const lower = rawPath.toLowerCase();
|
|
14
|
+
if (lower.endsWith('.ipynb') || lower.endsWith('.py')) {
|
|
15
|
+
return rawPath;
|
|
16
|
+
}
|
|
17
|
+
return '';
|
|
18
|
+
}
|
|
19
|
+
export function getActiveDocumentWidget(app, fallbackWidget) {
|
|
20
|
+
const current = app.shell.currentWidget;
|
|
21
|
+
const currentPath = getSupportedDocumentPath(current);
|
|
22
|
+
if (currentPath) {
|
|
23
|
+
return current;
|
|
24
|
+
}
|
|
25
|
+
if (fallbackWidget && !fallbackWidget.isDisposed && getSupportedDocumentPath(fallbackWidget)) {
|
|
26
|
+
return fallbackWidget;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
export function findDocumentWidgetByPath(app, path, fallbackWidget = null) {
|
|
31
|
+
const normalizedPath = (path || '').trim();
|
|
32
|
+
if (!normalizedPath) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const current = app.shell.currentWidget;
|
|
36
|
+
if (getSupportedDocumentPath(current) === normalizedPath) {
|
|
37
|
+
return current;
|
|
38
|
+
}
|
|
39
|
+
if (fallbackWidget &&
|
|
40
|
+
!fallbackWidget.isDisposed &&
|
|
41
|
+
getSupportedDocumentPath(fallbackWidget) === normalizedPath) {
|
|
42
|
+
return fallbackWidget;
|
|
43
|
+
}
|
|
44
|
+
const iterator = app.shell.widgets('main');
|
|
45
|
+
if (iterator && typeof iterator.next === 'function') {
|
|
46
|
+
while (true) {
|
|
47
|
+
const candidate = iterator.next();
|
|
48
|
+
if (!candidate) {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
if (getSupportedDocumentPath(candidate) === normalizedPath) {
|
|
52
|
+
return candidate;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
export function normalizeSelectionPreviewText(text) {
|
|
59
|
+
return (text || '').replace(/\r\n/g, '\n').replace(/\r/g, '\n').trim();
|
|
60
|
+
}
|
|
61
|
+
export function isNotebookWidget(widget) {
|
|
62
|
+
return Boolean(widget && widget.content && 'activeCell' in widget.content);
|
|
63
|
+
}
|
|
64
|
+
export function isScrollableElement(element) {
|
|
65
|
+
if (!element) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return element.scrollHeight > element.clientHeight + 1 || element.scrollWidth > element.clientWidth + 1;
|
|
69
|
+
}
|
|
70
|
+
export function isHTMLElement(value) {
|
|
71
|
+
return Boolean(value && value instanceof HTMLElement);
|
|
72
|
+
}
|
|
73
|
+
export function querySelectorIncludingSelf(root, selector) {
|
|
74
|
+
if (root.matches(selector)) {
|
|
75
|
+
return root;
|
|
76
|
+
}
|
|
77
|
+
return root.querySelector(selector);
|
|
78
|
+
}
|
|
79
|
+
export function getPrimaryDocumentScrollContainer(widget) {
|
|
80
|
+
const contentNode = widget?.content?.node;
|
|
81
|
+
const widgetNode = widget?.node;
|
|
82
|
+
const roots = [contentNode, widgetNode].filter(isHTMLElement);
|
|
83
|
+
if (roots.length === 0) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
const candidates = [
|
|
87
|
+
'.jp-WindowedPanel-outer',
|
|
88
|
+
'.jp-Notebook .jp-WindowedPanel-outer',
|
|
89
|
+
'.jp-NotebookPanel-notebook .jp-WindowedPanel-outer',
|
|
90
|
+
'.jp-FileEditor .cm-scroller',
|
|
91
|
+
'.jp-FileEditor .jp-CodeMirrorEditor',
|
|
92
|
+
'.cm-scroller',
|
|
93
|
+
'.jp-FileEditor'
|
|
94
|
+
];
|
|
95
|
+
for (const root of roots) {
|
|
96
|
+
for (const selector of candidates) {
|
|
97
|
+
const node = querySelectorIncludingSelf(root, selector);
|
|
98
|
+
if (isScrollableElement(node)) {
|
|
99
|
+
return node;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
for (const root of roots) {
|
|
104
|
+
if (isScrollableElement(root)) {
|
|
105
|
+
return root;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
export function captureDocumentViewState(widget) {
|
|
111
|
+
const scrollContainer = getPrimaryDocumentScrollContainer(widget);
|
|
112
|
+
const notebookContent = isNotebookWidget(widget) ? widget.content : null;
|
|
113
|
+
const rawActiveCellIndex = Number(notebookContent?.activeCellIndex);
|
|
114
|
+
const activeCellIndex = Number.isFinite(rawActiveCellIndex) ? Math.max(0, Math.floor(rawActiveCellIndex)) : null;
|
|
115
|
+
return {
|
|
116
|
+
scrollTop: scrollContainer?.scrollTop ?? 0,
|
|
117
|
+
scrollLeft: scrollContainer?.scrollLeft ?? 0,
|
|
118
|
+
activeCellIndex
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
export function restoreDocumentViewState(widget, viewState) {
|
|
122
|
+
if (isNotebookWidget(widget) && viewState.activeCellIndex !== null) {
|
|
123
|
+
try {
|
|
124
|
+
const notebookContent = widget.content;
|
|
125
|
+
const cellsLengthRaw = Number(notebookContent?.widgets?.length);
|
|
126
|
+
if (Number.isFinite(cellsLengthRaw) && cellsLengthRaw > 0) {
|
|
127
|
+
const maxIndex = Math.floor(cellsLengthRaw) - 1;
|
|
128
|
+
notebookContent.activeCellIndex = Math.max(0, Math.min(viewState.activeCellIndex, maxIndex));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// Ignore active-cell restore failures.
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const applyScroll = () => {
|
|
136
|
+
const scrollContainer = getPrimaryDocumentScrollContainer(widget);
|
|
137
|
+
if (!scrollContainer) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
scrollContainer.scrollTop = viewState.scrollTop;
|
|
141
|
+
scrollContainer.scrollLeft = viewState.scrollLeft;
|
|
142
|
+
};
|
|
143
|
+
applyScroll();
|
|
144
|
+
window.requestAnimationFrame(() => {
|
|
145
|
+
applyScroll();
|
|
146
|
+
window.requestAnimationFrame(applyScroll);
|
|
147
|
+
});
|
|
148
|
+
window.setTimeout(applyScroll, 120);
|
|
149
|
+
}
|
|
150
|
+
export function getActiveCellText(widget) {
|
|
151
|
+
if (!isNotebookWidget(widget)) {
|
|
152
|
+
return '';
|
|
153
|
+
}
|
|
154
|
+
const activeCell = widget.content.activeCell;
|
|
155
|
+
if (!activeCell) {
|
|
156
|
+
return '';
|
|
157
|
+
}
|
|
158
|
+
const source = typeof activeCell.model?.sharedModel?.getSource === 'function' ? activeCell.model.sharedModel.getSource() : '';
|
|
159
|
+
return typeof source === 'string' ? source : '';
|
|
160
|
+
}
|
|
161
|
+
export function getSelectionFromCodeEditor(editor, source) {
|
|
162
|
+
if (!editor || typeof editor.getSelection !== 'function' || typeof editor.getOffsetAt !== 'function') {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
const range = editor.getSelection();
|
|
166
|
+
if (!range || !range.start || !range.end) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
const startOffset = Number(editor.getOffsetAt(range.start));
|
|
170
|
+
const endOffset = Number(editor.getOffsetAt(range.end));
|
|
171
|
+
if (!Number.isFinite(startOffset) || !Number.isFinite(endOffset)) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
const from = Math.max(0, Math.min(startOffset, endOffset));
|
|
175
|
+
const to = Math.max(0, Math.max(startOffset, endOffset));
|
|
176
|
+
if (to <= from || !source) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
const text = source.slice(from, to);
|
|
180
|
+
if (!text) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
const startLineRaw = Number(range.start.line);
|
|
184
|
+
const endLineRaw = Number(range.end.line);
|
|
185
|
+
const startLine = Number.isFinite(startLineRaw) && Number.isFinite(endLineRaw)
|
|
186
|
+
? Math.max(1, Math.min(startLineRaw, endLineRaw) + 1)
|
|
187
|
+
: null;
|
|
188
|
+
return { text, startLine };
|
|
189
|
+
}
|
|
190
|
+
export function getSelectedTextFromCodeEditor(editor, source) {
|
|
191
|
+
const selection = getSelectionFromCodeEditor(editor, source);
|
|
192
|
+
return selection?.text || '';
|
|
193
|
+
}
|
|
194
|
+
export function getSelectedTextFromActiveCell(widget) {
|
|
195
|
+
if (!isNotebookWidget(widget)) {
|
|
196
|
+
return '';
|
|
197
|
+
}
|
|
198
|
+
const activeCell = widget.content.activeCell;
|
|
199
|
+
if (!activeCell) {
|
|
200
|
+
return '';
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
const source = typeof activeCell.model?.sharedModel?.getSource === 'function' ? activeCell.model.sharedModel.getSource() : '';
|
|
204
|
+
return getSelectedTextFromCodeEditor(activeCell.editor, typeof source === 'string' ? source : '');
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
return '';
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
export function getSelectedContextFromActiveCell(widget) {
|
|
211
|
+
if (!isNotebookWidget(widget)) {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
const notebookContent = widget.content;
|
|
215
|
+
const activeCell = notebookContent?.activeCell;
|
|
216
|
+
if (!activeCell) {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
const source = typeof activeCell.model?.sharedModel?.getSource === 'function' ? activeCell.model.sharedModel.getSource() : '';
|
|
221
|
+
const selection = getSelectionFromCodeEditor(activeCell.editor, typeof source === 'string' ? source : '');
|
|
222
|
+
if (!selection?.text) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
const rawCellIndex = Number(notebookContent?.activeCellIndex);
|
|
226
|
+
const cellNumber = Number.isFinite(rawCellIndex) ? Math.max(1, Math.floor(rawCellIndex) + 1) : 1;
|
|
227
|
+
return {
|
|
228
|
+
kind: 'cell',
|
|
229
|
+
number: cellNumber,
|
|
230
|
+
text: selection.text
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
export function getSelectedTextFromFileEditor(widget) {
|
|
238
|
+
if (!widget || isNotebookWidget(widget)) {
|
|
239
|
+
return '';
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
const editor = widget.content?.editor;
|
|
243
|
+
if (!editor) {
|
|
244
|
+
return '';
|
|
245
|
+
}
|
|
246
|
+
const source = typeof editor.model?.sharedModel?.getSource === 'function' ? editor.model.sharedModel.getSource() : '';
|
|
247
|
+
return getSelectedTextFromCodeEditor(editor, typeof source === 'string' ? source : '');
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
return '';
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
export function getSelectedContextFromFileEditor(widget) {
|
|
254
|
+
if (!widget || isNotebookWidget(widget)) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
const editor = widget.content?.editor;
|
|
259
|
+
if (!editor) {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
const source = typeof editor.model?.sharedModel?.getSource === 'function' ? editor.model.sharedModel.getSource() : '';
|
|
263
|
+
const selection = getSelectionFromCodeEditor(editor, typeof source === 'string' ? source : '');
|
|
264
|
+
if (!selection?.text) {
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
const lineNumber = selection.startLine ?? 1;
|
|
268
|
+
return {
|
|
269
|
+
kind: 'line',
|
|
270
|
+
number: lineNumber,
|
|
271
|
+
text: selection.text
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
export function getSelectedContext(widget, notebookMode) {
|
|
279
|
+
if (notebookMode === 'plain_py') {
|
|
280
|
+
return getSelectedContextFromFileEditor(widget) ?? getSelectedContextFromActiveCell(widget);
|
|
281
|
+
}
|
|
282
|
+
return getSelectedContextFromActiveCell(widget) ?? getSelectedContextFromFileEditor(widget);
|
|
283
|
+
}
|
|
284
|
+
export function inferLocationLabelFromWidget(widget, notebookMode) {
|
|
285
|
+
if (isNotebookWidget(widget) || notebookMode === 'ipynb' || notebookMode === 'jupytext_py') {
|
|
286
|
+
const rawCellIndex = Number(widget?.content?.activeCellIndex);
|
|
287
|
+
if (Number.isFinite(rawCellIndex)) {
|
|
288
|
+
return `Cell ${Math.max(1, Math.floor(rawCellIndex) + 1)}`;
|
|
289
|
+
}
|
|
290
|
+
return 'Cell';
|
|
291
|
+
}
|
|
292
|
+
try {
|
|
293
|
+
const editor = widget && !isNotebookWidget(widget) ? widget.content?.editor : null;
|
|
294
|
+
if (editor && typeof editor.getCursorPosition === 'function') {
|
|
295
|
+
const cursor = editor.getCursorPosition();
|
|
296
|
+
const lineRaw = Number(cursor?.line);
|
|
297
|
+
if (Number.isFinite(lineRaw)) {
|
|
298
|
+
return `Line ${Math.max(1, Math.floor(lineRaw) + 1)}`;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
// Ignore location inference errors and fallback to a generic label.
|
|
304
|
+
}
|
|
305
|
+
return notebookMode === 'plain_py' ? 'Line' : 'Selection';
|
|
306
|
+
}
|
|
307
|
+
export function toSelectionPreview(context) {
|
|
308
|
+
if (!context) {
|
|
309
|
+
return undefined;
|
|
310
|
+
}
|
|
311
|
+
const normalized = normalizeSelectionPreviewText(context.text);
|
|
312
|
+
if (!normalized) {
|
|
313
|
+
return undefined;
|
|
314
|
+
}
|
|
315
|
+
const locationLabel = context.kind === 'cell' ? `Cell ${context.number}` : `Line ${context.number}`;
|
|
316
|
+
return {
|
|
317
|
+
locationLabel,
|
|
318
|
+
previewText: truncateEnd(normalized, MESSAGE_SELECTION_PREVIEW_STORED_MAX_CHARS)
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
export function toMessageSelectionPreview(context, widget, notebookMode, text) {
|
|
322
|
+
const normalized = normalizeSelectionPreviewText(text);
|
|
323
|
+
if (!normalized) {
|
|
324
|
+
return undefined;
|
|
325
|
+
}
|
|
326
|
+
if (context) {
|
|
327
|
+
const locationLabel = context.kind === 'cell' ? `Cell ${context.number}` : `Line ${context.number}`;
|
|
328
|
+
return {
|
|
329
|
+
locationLabel,
|
|
330
|
+
previewText: truncateEnd(normalized, MESSAGE_SELECTION_PREVIEW_STORED_MAX_CHARS)
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
return toFallbackSelectionPreview(widget, notebookMode, normalized);
|
|
334
|
+
}
|
|
335
|
+
export function formatSelectionPreviewTextForDisplay(previewText) {
|
|
336
|
+
return truncateEnd(normalizeSelectionPreviewText(previewText), MESSAGE_SELECTION_PREVIEW_DISPLAY_MAX_CHARS);
|
|
337
|
+
}
|
|
338
|
+
export function toFallbackSelectionPreview(widget, notebookMode, text) {
|
|
339
|
+
const normalized = normalizeSelectionPreviewText(text);
|
|
340
|
+
if (!normalized) {
|
|
341
|
+
return undefined;
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
locationLabel: inferLocationLabelFromWidget(widget, notebookMode),
|
|
345
|
+
previewText: truncateEnd(normalized, MESSAGE_SELECTION_PREVIEW_STORED_MAX_CHARS)
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
export function toCellOutputPreview(context, widget, notebookMode, outputText) {
|
|
349
|
+
const normalized = normalizeSelectionPreviewText(outputText);
|
|
350
|
+
if (!normalized) {
|
|
351
|
+
return undefined;
|
|
352
|
+
}
|
|
353
|
+
const locationBase = context?.kind === 'cell'
|
|
354
|
+
? `Cell ${context.number}`
|
|
355
|
+
: inferLocationLabelFromWidget(widget, notebookMode);
|
|
356
|
+
return {
|
|
357
|
+
locationLabel: `${locationBase} Output`,
|
|
358
|
+
previewText: truncateEnd(normalized, MESSAGE_SELECTION_PREVIEW_STORED_MAX_CHARS)
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
export const ACTIVE_CELL_OUTPUT_MAX_CHARS = 20000;
|
|
362
|
+
export const ACTIVE_CELL_OUTPUT_MAX_ITEMS = 24;
|
|
363
|
+
const CELL_OUTPUT_TRUNCATED_MARKER = '... (truncated)';
|
|
364
|
+
export function stripAnsi(value) {
|
|
365
|
+
// Best-effort removal of ANSI escape codes (tracebacks sometimes include them).
|
|
366
|
+
return value.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, '');
|
|
367
|
+
}
|
|
368
|
+
export function coerceText(value) {
|
|
369
|
+
if (typeof value === 'string') {
|
|
370
|
+
return value;
|
|
371
|
+
}
|
|
372
|
+
if (Array.isArray(value)) {
|
|
373
|
+
return value.filter(item => typeof item === 'string').join('');
|
|
374
|
+
}
|
|
375
|
+
return '';
|
|
376
|
+
}
|
|
377
|
+
export function formatJupyterOutput(output) {
|
|
378
|
+
if (!output || typeof output !== 'object') {
|
|
379
|
+
return '';
|
|
380
|
+
}
|
|
381
|
+
const outputType = typeof output.output_type === 'string' ? output.output_type : '';
|
|
382
|
+
if (!outputType) {
|
|
383
|
+
return '';
|
|
384
|
+
}
|
|
385
|
+
if (outputType === 'stream') {
|
|
386
|
+
const text = coerceText(output.text);
|
|
387
|
+
if (!text) {
|
|
388
|
+
return '';
|
|
389
|
+
}
|
|
390
|
+
const name = typeof output.name === 'string' ? output.name : '';
|
|
391
|
+
const cleaned = stripAnsi(text).replace(/\s+$/, '');
|
|
392
|
+
if (!cleaned) {
|
|
393
|
+
return '';
|
|
394
|
+
}
|
|
395
|
+
return name === 'stderr' ? `[stderr]\n${cleaned}` : cleaned;
|
|
396
|
+
}
|
|
397
|
+
if (outputType === 'error') {
|
|
398
|
+
const traceback = Array.isArray(output.traceback)
|
|
399
|
+
? output.traceback.filter((line) => typeof line === 'string')
|
|
400
|
+
: [];
|
|
401
|
+
const tbText = stripAnsi(traceback.join('\n')).replace(/\s+$/, '');
|
|
402
|
+
if (tbText) {
|
|
403
|
+
return tbText;
|
|
404
|
+
}
|
|
405
|
+
const ename = typeof output.ename === 'string' ? output.ename : '';
|
|
406
|
+
const evalue = typeof output.evalue === 'string' ? output.evalue : '';
|
|
407
|
+
const summary = [ename, evalue].filter(Boolean).join(': ').trim();
|
|
408
|
+
return summary;
|
|
409
|
+
}
|
|
410
|
+
if (outputType === 'execute_result' || outputType === 'display_data' || outputType === 'update_display_data') {
|
|
411
|
+
const data = output.data && typeof output.data === 'object' ? output.data : null;
|
|
412
|
+
if (!data) {
|
|
413
|
+
return '';
|
|
414
|
+
}
|
|
415
|
+
const textPlain = coerceText(data['text/plain']);
|
|
416
|
+
if (textPlain) {
|
|
417
|
+
const cleaned = stripAnsi(textPlain).replace(/\s+$/, '');
|
|
418
|
+
if (!cleaned) {
|
|
419
|
+
return '';
|
|
420
|
+
}
|
|
421
|
+
if (outputType === 'execute_result' && typeof output.execution_count === 'number') {
|
|
422
|
+
return `Out[${output.execution_count}]:\n${cleaned}`;
|
|
423
|
+
}
|
|
424
|
+
return cleaned;
|
|
425
|
+
}
|
|
426
|
+
const mimeTypes = Object.keys(data).filter(mime => mime && mime !== 'text/plain');
|
|
427
|
+
if (mimeTypes.length > 0) {
|
|
428
|
+
return `[non-text output omitted: ${mimeTypes.slice(0, 6).join(', ')}${mimeTypes.length > 6 ? ', ...' : ''}]`;
|
|
429
|
+
}
|
|
430
|
+
return '';
|
|
431
|
+
}
|
|
432
|
+
return '';
|
|
433
|
+
}
|
|
434
|
+
export function isJupyterErrorOutput(output) {
|
|
435
|
+
return Boolean(output && typeof output === 'object' && output.output_type === 'error');
|
|
436
|
+
}
|
|
437
|
+
function truncateCellOutput(text, maxChars, fromEnd) {
|
|
438
|
+
if (text.length <= maxChars) {
|
|
439
|
+
return text;
|
|
440
|
+
}
|
|
441
|
+
if (maxChars <= CELL_OUTPUT_TRUNCATED_MARKER.length) {
|
|
442
|
+
return fromEnd ? text.slice(text.length - maxChars) : text.slice(0, maxChars);
|
|
443
|
+
}
|
|
444
|
+
const sliceLength = maxChars - CELL_OUTPUT_TRUNCATED_MARKER.length - 2;
|
|
445
|
+
if (fromEnd) {
|
|
446
|
+
return `${CELL_OUTPUT_TRUNCATED_MARKER}\n\n${text.slice(text.length - sliceLength)}`;
|
|
447
|
+
}
|
|
448
|
+
return `${text.slice(0, sliceLength)}\n\n${CELL_OUTPUT_TRUNCATED_MARKER}`;
|
|
449
|
+
}
|
|
450
|
+
export function summarizeJupyterOutputs(outputs) {
|
|
451
|
+
if (!Array.isArray(outputs) || outputs.length === 0) {
|
|
452
|
+
return '';
|
|
453
|
+
}
|
|
454
|
+
let appended = 0;
|
|
455
|
+
let exceededMaxItems = false;
|
|
456
|
+
let hasErrorOutput = false;
|
|
457
|
+
const chunks = [];
|
|
458
|
+
for (const output of outputs) {
|
|
459
|
+
if (appended >= ACTIVE_CELL_OUTPUT_MAX_ITEMS) {
|
|
460
|
+
exceededMaxItems = true;
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
const chunk = formatJupyterOutput(output);
|
|
464
|
+
if (!chunk) {
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
appended += 1;
|
|
468
|
+
if (isJupyterErrorOutput(output)) {
|
|
469
|
+
hasErrorOutput = true;
|
|
470
|
+
}
|
|
471
|
+
chunks.push(chunk);
|
|
472
|
+
}
|
|
473
|
+
let combined = chunks.join('\n\n').replace(/\s+$/, '');
|
|
474
|
+
if (!combined) {
|
|
475
|
+
return '';
|
|
476
|
+
}
|
|
477
|
+
if (exceededMaxItems) {
|
|
478
|
+
combined = `${combined}\n\n${CELL_OUTPUT_TRUNCATED_MARKER}`;
|
|
479
|
+
}
|
|
480
|
+
combined = truncateCellOutput(combined, ACTIVE_CELL_OUTPUT_MAX_CHARS, hasErrorOutput);
|
|
481
|
+
combined = combined.replace(/\s+$/, '');
|
|
482
|
+
return combined;
|
|
483
|
+
}
|
|
484
|
+
export function getActiveCellOutput(widget) {
|
|
485
|
+
if (!isNotebookWidget(widget)) {
|
|
486
|
+
return '';
|
|
487
|
+
}
|
|
488
|
+
const activeCell = widget.content.activeCell;
|
|
489
|
+
if (!activeCell) {
|
|
490
|
+
return '';
|
|
491
|
+
}
|
|
492
|
+
try {
|
|
493
|
+
const model = activeCell.model;
|
|
494
|
+
const cellType = typeof model?.type === 'string' ? model.type : '';
|
|
495
|
+
if (cellType && cellType !== 'code') {
|
|
496
|
+
return '';
|
|
497
|
+
}
|
|
498
|
+
const json = typeof model?.toJSON === 'function' ? model.toJSON() : null;
|
|
499
|
+
const outputs = json && Array.isArray(json.outputs) ? json.outputs : [];
|
|
500
|
+
return summarizeJupyterOutputs(outputs);
|
|
501
|
+
}
|
|
502
|
+
catch {
|
|
503
|
+
return '';
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
//# sourceMappingURL=codexChatDocumentUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codexChatDocumentUtils.js","sourceRoot":"","sources":["../src/codexChatDocumentUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAChF,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAMtC,MAAM,CAAC,MAAM,2CAA2C,GAAG,GAAG,CAAC;AAC/D,MAAM,CAAC,MAAM,0CAA0C,GAAG,GAAG,CAAC;AAa9D,MAAM,UAAU,kB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AQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACxC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAAiC;IACnE,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE;QAC7B,OAAO,EAAE,CAAC;KACX;IACD,MAAM,UAAU,GAAI,MAAc,CAAC,OAAO,CAAC,UAAU,CAAC;IACtD,IAAI,CAAC,UAAU,EAAE;QACf,OAAO,EAAE,CAAC;KACX;IAED,IAAI;QACF,MAAM,KAAK,GAAQ,UAAU,CAAC,KAAY,CAAC;QAC3C,MAAM,QAAQ,GAAG,OAAO,KAAK,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACnE,IAAI,QAAQ,IAAI,QAAQ,KAAK,MAAM,EAAE;YACnC,OAAO,EAAE,CAAC;SACX;QACD,MAAM,IAAI,GAAG,OAAO,KAAK,EAAE,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACzE,MAAM,OAAO,GAAG,IAAI,IAAI,KAAK,CAAC,OAAO,CAAE,IAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAE,IAAY,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1F,OAAO,uBAAuB,CAAC,OAAO,CAAC,CAAC;KACzC;IAAC,MAAM;QACN,OAAO,EAAE,CAAC;KACX;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CodexRateLimitsSnapshot } from './handlers/codexMessageTypes';
|
|
2
|
+
export declare function truncateMiddle(value: string, max: number): string;
|
|
3
|
+
export declare function coerceRateLimitsSnapshot(raw: any): CodexRateLimitsSnapshot | null;
|
|
4
|
+
export declare function clampNumber(value: number, min: number, max: number): number;
|
|
5
|
+
export declare function percentLeftFromUsed(usedPercent: number | null): number | null;
|
|
6
|
+
export declare function safeParseDateMs(value: string | null): number | null;
|
|
7
|
+
export declare function formatDurationShort(ms: number): string;
|
|
8
|
+
export declare function formatRunDuration(ms: number): string;
|
|
9
|
+
export declare function formatResetsIn(resetsAtSec: number | null, nowMs: number): string;
|
|
10
|
+
export declare function formatTokenCount(value: number | null): string;
|
|
11
|
+
export declare function getBrowserNotificationPermission(): NotificationPermission | 'unsupported';
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { coerceRateLimitsSnapshot as coerceRateLimitsSnapshotShared } from './handlers/codexMessageUtils';
|
|
2
|
+
export function truncateMiddle(value, max) {
|
|
3
|
+
if (value.length <= max) {
|
|
4
|
+
return value;
|
|
5
|
+
}
|
|
6
|
+
const ellipsis = '...';
|
|
7
|
+
if (max <= ellipsis.length) {
|
|
8
|
+
return value.slice(0, max);
|
|
9
|
+
}
|
|
10
|
+
const head = Math.max(0, Math.floor((max - ellipsis.length) * 0.6));
|
|
11
|
+
const tail = Math.max(0, max - head - ellipsis.length);
|
|
12
|
+
return `${value.slice(0, head)}${ellipsis}${value.slice(value.length - tail)}`;
|
|
13
|
+
}
|
|
14
|
+
export function coerceRateLimitsSnapshot(raw) {
|
|
15
|
+
return coerceRateLimitsSnapshotShared(raw);
|
|
16
|
+
}
|
|
17
|
+
export function clampNumber(value, min, max) {
|
|
18
|
+
return Math.min(max, Math.max(min, value));
|
|
19
|
+
}
|
|
20
|
+
export function percentLeftFromUsed(usedPercent) {
|
|
21
|
+
if (typeof usedPercent !== 'number' || !Number.isFinite(usedPercent)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return Math.round(clampNumber(100 - usedPercent, 0, 100));
|
|
25
|
+
}
|
|
26
|
+
export function safeParseDateMs(value) {
|
|
27
|
+
if (!value) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const ms = Date.parse(value);
|
|
31
|
+
return Number.isFinite(ms) ? ms : null;
|
|
32
|
+
}
|
|
33
|
+
export function formatDurationShort(ms) {
|
|
34
|
+
if (!Number.isFinite(ms)) {
|
|
35
|
+
return '0m';
|
|
36
|
+
}
|
|
37
|
+
const totalMinutes = Math.max(0, Math.floor(ms / 60000));
|
|
38
|
+
const days = Math.floor(totalMinutes / (60 * 24));
|
|
39
|
+
const hours = Math.floor((totalMinutes % (60 * 24)) / 60);
|
|
40
|
+
const minutes = totalMinutes % 60;
|
|
41
|
+
if (days > 0) {
|
|
42
|
+
return `${days}d ${hours}h`;
|
|
43
|
+
}
|
|
44
|
+
if (hours > 0) {
|
|
45
|
+
return `${hours}h ${minutes}m`;
|
|
46
|
+
}
|
|
47
|
+
return `${minutes}m`;
|
|
48
|
+
}
|
|
49
|
+
export function formatRunDuration(ms) {
|
|
50
|
+
if (!Number.isFinite(ms)) {
|
|
51
|
+
return '0s';
|
|
52
|
+
}
|
|
53
|
+
const totalSeconds = Math.max(0, Math.round(ms / 1000));
|
|
54
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
55
|
+
const seconds = totalSeconds % 60;
|
|
56
|
+
if (minutes > 0) {
|
|
57
|
+
return `${minutes}m ${seconds}s`;
|
|
58
|
+
}
|
|
59
|
+
return `${seconds}s`;
|
|
60
|
+
}
|
|
61
|
+
export function formatResetsIn(resetsAtSec, nowMs) {
|
|
62
|
+
if (typeof resetsAtSec !== 'number' || !Number.isFinite(resetsAtSec)) {
|
|
63
|
+
return 'Unknown';
|
|
64
|
+
}
|
|
65
|
+
const diffMs = resetsAtSec * 1000 - nowMs;
|
|
66
|
+
if (diffMs <= 0) {
|
|
67
|
+
return 'Overdue';
|
|
68
|
+
}
|
|
69
|
+
return formatDurationShort(diffMs);
|
|
70
|
+
}
|
|
71
|
+
export function formatTokenCount(value) {
|
|
72
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
73
|
+
return '--';
|
|
74
|
+
}
|
|
75
|
+
return value.toLocaleString();
|
|
76
|
+
}
|
|
77
|
+
export function getBrowserNotificationPermission() {
|
|
78
|
+
if (typeof window === 'undefined' || typeof window.Notification === 'undefined') {
|
|
79
|
+
return 'unsupported';
|
|
80
|
+
}
|
|
81
|
+
return window.Notification.permission;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=codexChatFormatting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codexChatFormatting.js","sourceRoot":"","sources":["../src/codexChatFormatting.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,IAAI,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AAE1G,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,GAAW;IACvD,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,EAAE;QACvB,OAAO,KAAK,CAAC;KACd;IACD,MAAM,QAAQ,GAAG,KAAK,CAAC;IACvB,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,EAAE;QAC1B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;KAC5B;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IACpE,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvD,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;AACjF,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,GAAQ;IAC/C,OAAO,8BAA8B,CAAC,GAAG,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW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