@marimo-team/islands 0.22.1-dev19 → 0.22.1-dev20

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.
@@ -5,7 +5,7 @@ import { s as __toESM, t as __commonJSMin } from "./chunk-BNovOVIE.js";
5
5
  import { t as require_react } from "./react-Bs6Z0kvn.js";
6
6
  import { t as require_compiler_runtime } from "./compiler-runtime-B_OLMU9S.js";
7
7
  import { r as toast } from "./copy-CBo9JcJW.js";
8
- import { A as AccordionItem, Bn as CircleX, C as Boosts, D as AIContextRegistry, Dn as Wrench, E as AIContextProvider, Et as displayCellName, Fn as File$1, Gt as PluralWord, H as ChatBubbleIcon, I as MarimoIncomingMessageEvent, It as moveToEndOfEditor, Mn as LoaderCircle, Nt as createVariableInfoElement, O as Accordion, On as Trash2, Pn as Info, Qt as getTableType, T as contextToXml, Tn as atomWithStorage, Ut as jotaiJsonStorage, Wt as variablesAtom, X as base64ToDataURL, Xt as allTablesAtom, Y as deserializeBlob, Zt as dataSourceConnectionsAtom, a as toPng, ct as notebookAtom, d as Spinner, en as getRequestClient, f as Popover, g as PopoverAnchor, h as PopoverTrigger, in as singleFacet, it as cellErrorsAtom, j as AccordionTrigger, k as AccordionContent, ln as ZodLocalStorage, m as PopoverContent, mn as CellOutputId, n as blobToString, o as MarkdownRenderer, rt as renderHTML, t as processOutput, v as isOutputEmpty, w as Sections, x as DatasourceContextProvider } from "./process-output-KyzWazB-.js";
8
+ import { A as AccordionItem, Bn as CircleX, C as Boosts, D as AIContextRegistry, Dn as Wrench, E as AIContextProvider, Et as displayCellName, Fn as File$1, Gt as PluralWord, H as ChatBubbleIcon, I as MarimoIncomingMessageEvent, It as moveToEndOfEditor, Mn as LoaderCircle, Nt as createVariableInfoElement, O as Accordion, On as Trash2, Pn as Info, Qt as getTableType, T as contextToXml, Tn as atomWithStorage, Ut as jotaiJsonStorage, Wt as variablesAtom, X as base64ToDataURL, Xt as allTablesAtom, Y as deserializeBlob, Zt as dataSourceConnectionsAtom, a as toPng, ct as notebookAtom, d as Spinner, en as getRequestClient, f as Popover, g as PopoverAnchor, h as PopoverTrigger, in as singleFacet, it as cellErrorsAtom, j as AccordionTrigger, k as AccordionContent, ln as ZodLocalStorage, m as PopoverContent, mn as CellOutputId, n as blobToString, o as MarkdownRenderer, rt as renderHTML, t as processOutput, v as isOutputEmpty, w as Sections, x as DatasourceContextProvider } from "./process-output-CzWMmQcQ.js";
9
9
  import "./chunk-5FQGJX7Z-C428iZBW.js";
10
10
  import { l as createLucideIcon } from "./dist-D2Rk1j4R.js";
11
11
  import { A as logNever, L as X, r as Strings, t as Label } from "./label-DTNqw9tv.js";
package/dist/main.js CHANGED
@@ -21,7 +21,7 @@ import { a as __toCommonJS, n as __esmMin, r as __export, s as __toESM, t as __c
21
21
  import { t as require_react } from "./react-Bs6Z0kvn.js";
22
22
  import { t as require_compiler_runtime } from "./compiler-runtime-B_OLMU9S.js";
23
23
  import { n as Copy, r as toast, t as copyToClipboard } from "./copy-CBo9JcJW.js";
24
- import { $ as dataViewToBase64, $t as convertStatsName, A as AccordionItem, An as PaintRoller, At as Checkbox, B as createInputEvent, Bn as CircleX, Bt as useChromeActions, Cn as jsonToTSV, Ct as headingToIdentifier, Dn as Wrench, Dt as getValidName, En as selectAtom, Et as displayCellName, F as AccordionTrigger$1, Fn as File, Ft as Paths, G as ChevronRightIcon, Gt as PluralWord, Hn as Braces, Ht as adaptForLocalStorage, I as MarimoIncomingMessageEvent, In as FileText, J as PinRightIcon, Jt as getDataTypeColor, K as DotFilledIcon, Kt as PluralWords, L as MarimoValueInputEvent, Ln as Eye, Lt as goToCellLine, M as Accordion$1, Mn as LoaderCircle, Mt as MarkdownLanguageAdapter, N as AccordionContent$1, Nn as Layers, O as Accordion, On as Trash2, Ot as isInternalCellName, P as AccordionItem$1, Pn as Info, Pt as PathBuilder, Q as base64ToUint8Array, R as MarimoValueReadyEvent, Rn as Database, Rt as DeferredRequestRegistry, S as getDatasourceContext, Sn as jsonToMarkdown, St as isErrorMime, Tn as atomWithStorage, Tt as getCellDomProps, U as CheckIcon, Un as esm_default$1, Ut as jotaiJsonStorage, V as BorderAllIcon, Vn as CircleAlert, Vt as repl, W as ChevronDownIcon, Wn as import_lib, Y as deserializeBlob, Yt as require_client, Z as base64ToDataView, _ as PopoverClose, _n as UIElementId, _t as initialModeAtom, a as toPng, an as elementContainsMarimoCellFile, at as createActions, b as useExpandedOutput, bn as RANDOM_ID_ATTR, bt as outputIsLoading, c as useCellFocusActions, cn as NotebookScopedLocalStorage, ct as notebookAtom, d as Spinner, dn as parseAttrValue, dt as useCellActions, en as getRequestClient, et as extractBase64FromDataURL, f as Popover$1, fn as parseDataset, ft as useCellIds, gn as SCRATCH_CELL_ID, gt as getInitialAppMode, h as PopoverTrigger, hn as HTMLCellId, ht as AnsiUp, i as PythonIcon, j as AccordionTrigger, jn as NotebookPen, jt as customPythonLanguageSupport, k as AccordionContent, kn as Table2, kt as normalizeName, l as useLastFocusedCellId, lt as notebookOutline, m as PopoverContent, mn as CellOutputId, mt as createCell, n as blobToString, nn as useRequestClient, nt as safeExtractSetUIElementMessageBuffers, o as MarkdownRenderer, on as extractAllTracebackInfo, ot as getCellEditorView, p as PopoverClose$1, pn as parseInitialValue, pt as useCellNames, q as PinLeftIcon, qt as DATA_TYPE_ICON, r as filesToBase64, rn as isUninstantiated, rt as renderHTML, s as LazyAnyLanguageCodeMirror, sn as getTracebackInfo, st as getCellNames, t as processOutput, tn as requestClientAtom, tt as isDataURLString, u as maybeAddAltairImport, un as filenameAtom, ut as reducer, v as isOutputEmpty, vn as findCellId, vt as kioskModeAtom, wn as atomWithReducer, wt as DATA_CELL_ID, xn as jsonParseWithSpecialChar, xt as outputIsStale, y as useExpandedConsoleOutput, yn as OBJECT_ID_ATTR, yt as viewStateAtom, z as MarimoValueUpdateEvent, zn as Columns2, zt as generateUUID, __tla as __tla_0 } from "./process-output-KyzWazB-.js";
24
+ import { $ as dataViewToBase64, $t as convertStatsName, A as AccordionItem, An as PaintRoller, At as Checkbox, B as createInputEvent, Bn as CircleX, Bt as useChromeActions, Cn as jsonToTSV, Ct as headingToIdentifier, Dn as Wrench, Dt as getValidName, En as selectAtom, Et as displayCellName, F as AccordionTrigger$1, Fn as File, Ft as Paths, G as ChevronRightIcon, Gt as PluralWord, Hn as Braces, Ht as adaptForLocalStorage, I as MarimoIncomingMessageEvent, In as FileText, J as PinRightIcon, Jt as getDataTypeColor, K as DotFilledIcon, Kt as PluralWords, L as MarimoValueInputEvent, Ln as Eye, Lt as goToCellLine, M as Accordion$1, Mn as LoaderCircle, Mt as MarkdownLanguageAdapter, N as AccordionContent$1, Nn as Layers, O as Accordion, On as Trash2, Ot as isInternalCellName, P as AccordionItem$1, Pn as Info, Pt as PathBuilder, Q as base64ToUint8Array, R as MarimoValueReadyEvent, Rn as Database, Rt as DeferredRequestRegistry, S as getDatasourceContext, Sn as jsonToMarkdown, St as isErrorMime, Tn as atomWithStorage, Tt as getCellDomProps, U as CheckIcon, Un as esm_default$1, Ut as jotaiJsonStorage, V as BorderAllIcon, Vn as CircleAlert, Vt as repl, W as ChevronDownIcon, Wn as import_lib, Y as deserializeBlob, Yt as require_client, Z as base64ToDataView, _ as PopoverClose, _n as UIElementId, _t as initialModeAtom, a as toPng, an as elementContainsMarimoCellFile, at as createActions, b as useExpandedOutput, bn as RANDOM_ID_ATTR, bt as outputIsLoading, c as useCellFocusActions, cn as NotebookScopedLocalStorage, ct as notebookAtom, d as Spinner, dn as parseAttrValue, dt as useCellActions, en as getRequestClient, et as extractBase64FromDataURL, f as Popover$1, fn as parseDataset, ft as useCellIds, gn as SCRATCH_CELL_ID, gt as getInitialAppMode, h as PopoverTrigger, hn as HTMLCellId, ht as AnsiUp, i as PythonIcon, j as AccordionTrigger, jn as NotebookPen, jt as customPythonLanguageSupport, k as AccordionContent, kn as Table2, kt as normalizeName, l as useLastFocusedCellId, lt as notebookOutline, m as PopoverContent, mn as CellOutputId, mt as createCell, n as blobToString, nn as useRequestClient, nt as safeExtractSetUIElementMessageBuffers, o as MarkdownRenderer, on as extractAllTracebackInfo, ot as getCellEditorView, p as PopoverClose$1, pn as parseInitialValue, pt as useCellNames, q as PinLeftIcon, qt as DATA_TYPE_ICON, r as filesToBase64, rn as isUninstantiated, rt as renderHTML, s as LazyAnyLanguageCodeMirror, sn as getTracebackInfo, st as getCellNames, t as processOutput, tn as requestClientAtom, tt as isDataURLString, u as maybeAddAltairImport, un as filenameAtom, ut as reducer, v as isOutputEmpty, vn as findCellId, vt as kioskModeAtom, wn as atomWithReducer, wt as DATA_CELL_ID, xn as jsonParseWithSpecialChar, xt as outputIsStale, y as useExpandedConsoleOutput, yn as OBJECT_ID_ATTR, yt as viewStateAtom, z as MarimoValueUpdateEvent, zn as Columns2, zt as generateUUID, __tla as __tla_0 } from "./process-output-CzWMmQcQ.js";
25
25
  import { __tla as __tla_1 } from "./chunk-5FQGJX7Z-C428iZBW.js";
26
26
  import { c as useSize, l as createLucideIcon, t as Root$4 } from "./dist-D2Rk1j4R.js";
27
27
  import { A as $896ba0a80a8f4d36$export$85fd5fdf27bacc79, C as DEFAULT_COLOR_SCHEME, D as SCALE_TYPE_DESCRIPTIONS, E as EMPTY_VALUE$1, F as ListFilter, I as ChartPie, L as ChartColumn, M as $5a387cc49350e6db$export$722debc0e56fea39, N as Table$1, O as TIME_UNIT_DESCRIPTIONS, P as SquareFunction, S as DEFAULT_AGGREGATION, T as DEFAULT_TIME_UNIT, _ as AGGREGATION_TYPE_DESCRIPTIONS, a as AGGREGATION_FNS$1, b as COLOR_SCHEMES, c as COLOR_BY_FIELDS, d as NONE_VALUE, f as SELECTABLE_DATA_TYPES, g as TIME_UNITS, h as STRING_AGGREGATION_FNS, i as convertDataTypeToSelectable, j as $fb18d541ea1ad717$export$ad991b66133851cf, k as escapeFieldName, l as COMBINED_TIME_UNITS, m as SORT_TYPES, n as createSpecWithoutData, o as BIN_AGGREGATION, p as SINGLE_TIME_UNITS, r as isFieldSet, s as CHART_TYPES, t as augmentSpecWithData, u as ChartType, v as AGGREGATION_TYPE_ICON, w as DEFAULT_MAX_BINS_FACET, x as COUNT_FIELD, y as CHART_TYPE_ICON } from "./spec-DYaR1rJh.js";
@@ -36346,7 +36346,7 @@ ${E}`,
36346
36346
  };
36347
36347
  }
36348
36348
  };
36349
- var LazyChatbot = import_react.lazy(() => import("./chat-ui-CtqUthFR.js").then((e) => ({
36349
+ var LazyChatbot = import_react.lazy(() => import("./chat-ui-C1HWLRKN.js").then((e) => ({
36350
36350
  default: e.Chatbot
36351
36351
  }))), messageSchema = array(object({
36352
36352
  id: string(),
@@ -65425,7 +65425,7 @@ ${c}
65425
65425
  return Logger.warn("Failed to get version from mount config"), null;
65426
65426
  }
65427
65427
  }
65428
- const marimoVersionAtom = atom(getVersionFromMountConfig() || "0.22.1-dev19"), showCodeInRunModeAtom = atom(true);
65428
+ const marimoVersionAtom = atom(getVersionFromMountConfig() || "0.22.1-dev20"), showCodeInRunModeAtom = atom(true);
65429
65429
  atom(null);
65430
65430
  var VIRTUAL_FILE_REGEX = /\/@file\/([^\s"&'/]+)\.([\dA-Za-z]+)/g, VirtualFileTracker = class e {
65431
65431
  constructor() {
@@ -25818,7 +25818,7 @@ ${n.sqlString}
25818
25818
  for (let r = 0; r < n; r++) t += String.fromCharCode(e[r]);
25819
25819
  return globalThis.btoa(t);
25820
25820
  }
25821
- const uint8ArrayToBase64 = Uint8Array.prototype.toBase64 ? (e) => e.toBase64() : uint8ArrayToBase64Fallback;
25821
+ const uint8ArrayToBase64 = "toBase64" in Uint8Array.prototype ? (e) => e.toBase64() : uint8ArrayToBase64Fallback;
25822
25822
  dataViewToBase64 = function(e) {
25823
25823
  return uint8ArrayToBase64(new Uint8Array(e.buffer, e.byteOffset, e.byteLength));
25824
25824
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.22.1-dev19",
3
+ "version": "0.22.1-dev20",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -365,7 +365,7 @@ describe("LazyWebsocketTransport", () => {
365
365
  expect(delegate.connect).toHaveBeenCalled();
366
366
  });
367
367
 
368
- it("should clamp timeout to maxTimeoutMs", async () => {
368
+ it("should use maxTimeoutMs as default when no timeout is provided", async () => {
369
369
  const transport = new LazyWebsocketTransport({
370
370
  getWsUrl: mockGetWsUrl,
371
371
  waitForReady: mockWaitForReady,
@@ -376,12 +376,29 @@ describe("LazyWebsocketTransport", () => {
376
376
  await transport.connect();
377
377
 
378
378
  const data: any = { method: "test", params: [] };
379
- await transport.sendData(data, 10_000);
379
+ await transport.sendData(data, undefined);
380
380
 
381
381
  const delegate = (transport as any).delegate;
382
382
  expect(delegate.sendData).toHaveBeenCalledWith(data, 5000);
383
383
  });
384
384
 
385
+ it("should respect caller-provided timeout without clamping", async () => {
386
+ const transport = new LazyWebsocketTransport({
387
+ getWsUrl: mockGetWsUrl,
388
+ waitForReady: mockWaitForReady,
389
+ showError: mockShowError,
390
+ maxTimeoutMs: 5000,
391
+ });
392
+
393
+ await transport.connect();
394
+
395
+ const data: any = { method: "test", params: [] };
396
+ await transport.sendData(data, 30_000);
397
+
398
+ const delegate = (transport as any).delegate;
399
+ expect(delegate.sendData).toHaveBeenCalledWith(data, 30_000);
400
+ });
401
+
385
402
  it("should throw error if reconnection fails", async () => {
386
403
  const connectionError = new Error("Connection failed");
387
404
  (WebSocketTransport as any).mockImplementation(function (this: any) {
@@ -407,6 +424,115 @@ describe("LazyWebsocketTransport", () => {
407
424
  });
408
425
  });
409
426
 
427
+ describe("onReconnect", () => {
428
+ it("should call onReconnect after close + sendData reconnection", async () => {
429
+ const transport = new LazyWebsocketTransport({
430
+ getWsUrl: mockGetWsUrl,
431
+ waitForReady: mockWaitForReady,
432
+ showError: mockShowError,
433
+ });
434
+
435
+ const onReconnect = vi.fn().mockResolvedValue(undefined);
436
+ transport.onReconnect = onReconnect;
437
+
438
+ // Initial connect
439
+ await transport.connect();
440
+ expect(onReconnect).not.toHaveBeenCalled();
441
+
442
+ // Close the transport (simulates failure handling)
443
+ transport.close();
444
+
445
+ // sendData should reconnect and call onReconnect
446
+ const data: any = { method: "test", params: [] };
447
+ await transport.sendData(data, 5000);
448
+
449
+ expect(onReconnect).toHaveBeenCalledTimes(1);
450
+ });
451
+
452
+ it("should NOT call onReconnect on initial sendData connection", async () => {
453
+ const transport = new LazyWebsocketTransport({
454
+ getWsUrl: mockGetWsUrl,
455
+ waitForReady: mockWaitForReady,
456
+ showError: mockShowError,
457
+ });
458
+
459
+ const onReconnect = vi.fn().mockResolvedValue(undefined);
460
+ transport.onReconnect = onReconnect;
461
+
462
+ // sendData without prior connect — this is the initial connection
463
+ const data: any = { method: "test", params: [] };
464
+ await transport.sendData(data, 5000);
465
+
466
+ expect(onReconnect).not.toHaveBeenCalled();
467
+ });
468
+
469
+ it("should call onReconnect after tryConnect failure + retry via sendData", async () => {
470
+ let connectAttempt = 0;
471
+ (WebSocketTransport as any).mockImplementation(function (this: any) {
472
+ this.connect = vi.fn().mockImplementation(() => {
473
+ connectAttempt++;
474
+ // First 2 attempts fail (retries=2 exhausted), then succeed on next sendData
475
+ if (connectAttempt <= 2) {
476
+ return Promise.reject(new Error("Connection failed"));
477
+ }
478
+ return Promise.resolve(undefined);
479
+ });
480
+ this.close = vi.fn();
481
+ this.sendData = vi.fn().mockResolvedValue({ result: "success" });
482
+ this.subscribe = vi.fn();
483
+ this.unsubscribe = vi.fn();
484
+ });
485
+
486
+ const transport = new LazyWebsocketTransport({
487
+ getWsUrl: mockGetWsUrl,
488
+ waitForReady: mockWaitForReady,
489
+ showError: mockShowError,
490
+ retries: 2,
491
+ retryDelayMs: 10,
492
+ });
493
+
494
+ const onReconnect = vi.fn().mockResolvedValue(undefined);
495
+ transport.onReconnect = onReconnect;
496
+
497
+ // Initial connect fails (all retries exhausted)
498
+ await expect(transport.connect()).rejects.toThrow("Connection failed");
499
+ expect(onReconnect).not.toHaveBeenCalled();
500
+
501
+ // Now sendData reconnects successfully
502
+ const data: any = { method: "test", params: [] };
503
+ await transport.sendData(data, 5000);
504
+
505
+ expect(onReconnect).toHaveBeenCalledTimes(1);
506
+ });
507
+
508
+ it("should propagate onReconnect rejection and allow retry", async () => {
509
+ const transport = new LazyWebsocketTransport({
510
+ getWsUrl: mockGetWsUrl,
511
+ waitForReady: mockWaitForReady,
512
+ showError: mockShowError,
513
+ });
514
+
515
+ const reconnectError = new Error("Re-initialization failed");
516
+ const onReconnect = vi.fn().mockRejectedValueOnce(reconnectError);
517
+ transport.onReconnect = onReconnect;
518
+
519
+ await transport.connect();
520
+ transport.close();
521
+
522
+ const data: any = { method: "test", params: [] };
523
+ await expect(transport.sendData(data, 5000)).rejects.toThrow(
524
+ "Re-initialization failed",
525
+ );
526
+ expect(onReconnect).toHaveBeenCalledTimes(1);
527
+
528
+ // needsReInitialization should still be true, so a subsequent retry
529
+ // will attempt onReconnect again
530
+ onReconnect.mockResolvedValueOnce(undefined);
531
+ await transport.sendData(data, 5000);
532
+ expect(onReconnect).toHaveBeenCalledTimes(2);
533
+ });
534
+ });
535
+
410
536
  describe("close", () => {
411
537
  it("should close delegate and clear it", async () => {
412
538
  const transport = new LazyWebsocketTransport({
@@ -37,13 +37,20 @@ export const createWSTransport = once(() => {
37
37
  export const getCopilotClient = once(() => {
38
38
  const userConfig = store.get(resolvedMarimoConfigAtom);
39
39
  const copilotSettings = userConfig.ai?.github?.copilot_settings ?? {};
40
+ const transport = createWSTransport();
40
41
 
41
- return new CopilotLanguageServerClient({
42
+ const client = new CopilotLanguageServerClient({
42
43
  rootUri: FILE_URI,
43
44
  workspaceFolders: null,
44
- transport: createWSTransport(),
45
+ transport,
45
46
  copilotSettings,
46
47
  });
48
+
49
+ // Re-run the LSP initialize handshake when the transport reconnects
50
+ // after a close or connection failure.
51
+ transport.onReconnect = () => client.reInitialize();
52
+
53
+ return client;
47
54
  });
48
55
 
49
56
  export function copilotServer() {
@@ -86,6 +86,17 @@ export class CopilotLanguageServerClient extends LanguageServerClient {
86
86
  });
87
87
  }
88
88
 
89
+ /**
90
+ * Re-run the LSP initialize handshake and send configuration.
91
+ * Called by the transport's onReconnect callback after reconnecting.
92
+ */
93
+ async reInitialize(): Promise<void> {
94
+ logger.log("#reInitialize: Re-initializing LSP connection");
95
+ this.initializePromise = this.initialize();
96
+ await this.initializePromise;
97
+ await this.sendConfiguration();
98
+ }
99
+
89
100
  private async sendConfiguration() {
90
101
  const settings = this.copilotSettings;
91
102
  // Skip if no settings are provided
@@ -36,7 +36,8 @@ export interface LazyWebsocketTransportOptions {
36
36
  retryDelayMs?: number;
37
37
 
38
38
  /**
39
- * Maximum timeout for sendData operations in milliseconds.
39
+ * Default timeout for sendData operations in milliseconds.
40
+ * Used when the caller does not provide an explicit timeout.
40
41
  * @default 5000
41
42
  */
42
43
  maxTimeoutMs?: number;
@@ -60,6 +61,13 @@ export class LazyWebsocketTransport extends Transport {
60
61
  private delegate: WebSocketTransport | undefined;
61
62
  private pendingSubscriptions: Subscription[] = [];
62
63
  private readonly options: Required<LazyWebsocketTransportOptions>;
64
+ private needsReInitialization = false;
65
+
66
+ /**
67
+ * Callback invoked after the transport reconnects following a close or connection failure.
68
+ * Used by the LSP client to re-run the initialize handshake on the new connection.
69
+ */
70
+ onReconnect?: () => Promise<void>;
63
71
 
64
72
  constructor(options: LazyWebsocketTransportOptions) {
65
73
  super();
@@ -157,6 +165,7 @@ export class LazyWebsocketTransport extends Transport {
157
165
  );
158
166
  if (attempt === this.options.retries) {
159
167
  this.delegate = undefined;
168
+ this.needsReInitialization = true;
160
169
  // Show error toast on final retry
161
170
  this.options.showError(
162
171
  "GitHub Copilot Connection Error",
@@ -183,6 +192,7 @@ export class LazyWebsocketTransport extends Transport {
183
192
  override close(): void {
184
193
  this.delegate?.close();
185
194
  this.delegate = undefined;
195
+ this.needsReInitialization = true;
186
196
  }
187
197
 
188
198
  override async sendData(
@@ -202,6 +212,25 @@ export class LazyWebsocketTransport extends Transport {
202
212
  "Unable to connect to GitHub Copilot. Please check your settings and try again.",
203
213
  );
204
214
  }
215
+
216
+ // Re-run LSP initialization handshake after reconnecting
217
+ if (this.needsReInitialization && this.onReconnect) {
218
+ Logger.log(
219
+ "Copilot#sendData: Re-initializing LSP after reconnection...",
220
+ );
221
+ try {
222
+ await this.onReconnect();
223
+ this.needsReInitialization = false;
224
+ } catch (error) {
225
+ // Close the uninitialized connection so the next attempt starts fresh
226
+ this.close();
227
+ Logger.error(
228
+ "Copilot#sendData: LSP re-initialization after reconnection failed",
229
+ error,
230
+ );
231
+ throw error;
232
+ }
233
+ }
205
234
  }
206
235
 
207
236
  // After reconnection, delegate should be initialized
@@ -211,11 +240,8 @@ export class LazyWebsocketTransport extends Transport {
211
240
  );
212
241
  }
213
242
 
214
- // Clamp timeout to maxTimeoutMs
215
- timeout = Math.min(
216
- timeout ?? this.options.maxTimeoutMs,
217
- this.options.maxTimeoutMs,
218
- );
243
+ // Use maxTimeoutMs as default when no timeout is provided
244
+ timeout = timeout ?? this.options.maxTimeoutMs;
219
245
  return this.delegate.sendData(data, timeout);
220
246
  }
221
247
  }
@@ -30,6 +30,8 @@ function createConnectionTransport(
30
30
  // Create a connection transport using the ReconnectingWebSocket from partysocket
31
31
  // This handles reconnecting when the connection is lost.
32
32
  const urlProvider = options.url; // We don't call the URL provider now since it may change (i.e. if the runtime redirects)
33
+ // Cast needed: ReconnectingWebSocket types readyState as `number`
34
+ // but IConnectionTransport expects `0 | 1 | 2 | 3`
33
35
  return new ReconnectingWebSocket(urlProvider, undefined, {
34
36
  // We don't want Infinity retries
35
37
  maxRetries: 10,
@@ -38,7 +40,7 @@ function createConnectionTransport(
38
40
  // long timeout -- the server can become slow when many notebooks
39
41
  // are open.
40
42
  connectionTimeout: 10_000,
41
- });
43
+ }) as unknown as IConnectionTransport;
42
44
  }
43
45
 
44
46
  /**
@@ -71,7 +71,6 @@ function base64ToUint8ArrayFallback(bytes: string): Uint8Array {
71
71
  * Uses native Uint8Array.fromBase64 if available, otherwise falls back to manual implementation.
72
72
  */
73
73
  export const base64ToUint8Array: (bytes: Base64String) => Uint8Array =
74
- // @ts-expect-error - Uint8Array.fromBase64 types coming in TypeScript 5.10+
75
74
  Uint8Array.fromBase64 ?? base64ToUint8ArrayFallback;
76
75
 
77
76
  /**
@@ -100,10 +99,8 @@ function uint8ArrayToBase64Fallback(binary: Uint8Array): Base64String {
100
99
  * Uses native Uint8Array.prototype.toBase64 if available, otherwise falls back to manual implementation.
101
100
  */
102
101
  export const uint8ArrayToBase64: (binary: Uint8Array) => Base64String =
103
- // @ts-expect-error - Uint8Array.prototype.toBase64 types coming in TypeScript 5.10+
104
- Uint8Array.prototype.toBase64
105
- ? // @ts-expect-error - Uint8Array.prototype.toBase64 types coming in TypeScript 5.10+
106
- (binary) => binary.toBase64()
102
+ "toBase64" in Uint8Array.prototype
103
+ ? (binary) => binary.toBase64() as Base64String
107
104
  : uint8ArrayToBase64Fallback;
108
105
 
109
106
  /**