diff --git a/jest.config.js b/jest.config.js index 6b9713756..6c21d4d3b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -16,6 +16,6 @@ module.exports = { coverageDirectory: "coverage", moduleNameMapper: { "^vscode$": "/src/test/mock/vscode.ts", - "^@lib$": "/src/test/mock/lib.ts", + "^@altimateai/extension-components$": "/src/test/mock/lib.ts", }, }; diff --git a/package-lock.json b/package-lock.json index 45a1f451c..7d5c4ef17 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "hasInstallScript": true, "license": "MIT", "dependencies": { + "@altimateai/extension-components": "0.0.10-beta.3", "@jupyterlab/coreutils": "^6.2.4", "@jupyterlab/nbformat": "^4.2.4", "@jupyterlab/services": "^6.6.7", @@ -54,6 +55,7 @@ "@vscode/debugprotocol": "^1.68.0", "@vscode/test-electron": "^2.4.1", "@vscode/zeromq": "^0.2.1", + "babel-loader": "^10.0.0", "chai": "^4.3.10", "concurrently": "^8.2.2", "copy-webpack-plugin": "^11.0.0", @@ -88,6 +90,15 @@ "vscode": "^1.95.0" } }, + "node_modules/@altimateai/extension-components": { + "version": "0.0.10-beta.3", + "resolved": "https://registry.npmjs.org/@altimateai/extension-components/-/extension-components-0.0.10-beta.3.tgz", + "integrity": "sha512-PCa8qNaWjIMrreswOmDSFEj7pGm2AtqFWFANGDk7nRJXcAVodXC35mOFAwW1yg9jbJyl61psqGAj4pUkERnxNQ==", + "hasInstallScript": true, + "peerDependencies": { + "@jupyterlab/services": "^6.6.7" + } + }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", @@ -6190,6 +6201,23 @@ "node": ">=8" } }, + "node_modules/babel-loader": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/babel-loader/-/babel-loader-10.0.0.tgz", + "integrity": "sha512-z8jt+EdS61AMw22nSfoNJAZ0vrtmhPRVi6ghL3rCeRZI8cdNYFiV5xeV3HbE7rlZZNmGH8BVccwWt8/ED0QOHA==", + "dev": true, + "license": "MIT", + "dependencies": { + "find-up": "^5.0.0" + }, + "engines": { + "node": "^18.20.0 || ^20.10.0 || >=22.0.0" + }, + "peerDependencies": { + "@babel/core": "^7.12.0", + "webpack": ">=5.61.0" + } + }, "node_modules/babel-plugin-istanbul": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/babel-plugin-istanbul/-/babel-plugin-istanbul-6.1.1.tgz", diff --git a/package.json b/package.json index 180f85530..21997a0fa 100644 --- a/package.json +++ b/package.json @@ -2057,6 +2057,7 @@ "@vscode/debugprotocol": "^1.68.0", "@vscode/test-electron": "^2.4.1", "@vscode/zeromq": "^0.2.1", + "babel-loader": "^10.0.0", "chai": "^4.3.10", "concurrently": "^8.2.2", "copy-webpack-plugin": "^11.0.0", @@ -2092,6 +2093,7 @@ "ms-python.python" ], "dependencies": { + "@altimateai/extension-components": "0.0.10-beta.3", "@jupyterlab/coreutils": "^6.2.4", "@jupyterlab/nbformat": "^4.2.4", "@jupyterlab/services": "^6.6.7", diff --git a/postInstall.js b/postInstall.js index a5ba60700..b4f5f6211 100644 --- a/postInstall.js +++ b/postInstall.js @@ -1,51 +1,5 @@ // Copied from https://github.com/microsoft/vscode-jupyter/blob/main/build/ci/postInstall.js -const fs = require("fs"); const { downloadZMQ } = require("@vscode/zeromq"); -const path = require("path"); - -/** - * In order to get raw kernels working, we reuse the default kernel that jupyterlab ships. - * However it expects to be talking to a websocket which is serializing the messages to strings. - * Our raw kernel is not a web socket and needs to do its own serialization. To do so, we make a copy - * of the default kernel with the serialization stripped out. This is simpler than making a copy of the module - * at runtime. - */ -function createJupyterKernelWithoutSerialization() { - var relativePath = path.join( - "node_modules", - "@jupyterlab", - "services", - "lib", - "kernel", - "default.js", - ); - var filePath = path.join("", relativePath); - if (!fs.existsSync(filePath)) { - throw new Error( - "Jupyter lab default kernel not found '" + - filePath + - "' (Jupyter Extension post install script)", - ); - } - var fileContents = fs.readFileSync(filePath, { encoding: "utf8" }); - var replacedContents = fileContents - .replace( - /^const serialize =.*$/gm, - "const serialize = { serialize: (a) => a, deserialize: (a) => a };", - ) - .replace( - "const owned = team.session === this.clientId;", - "const owned = parentHeader.session === this.clientId;", - ); - if (replacedContents === fileContents) { - throw new Error( - "Jupyter lab default kernel cannot be made non serializing", - ); - } - var destPath = path.join(path.dirname(filePath), "nonSerializingKernel.js"); - fs.writeFileSync(destPath, replacedContents); - console.log(destPath + " file generated (by Jupyter VSC)"); -} async function downloadZmqBinaries() { // if (common.getBundleConfiguration() === common.bundleConfiguration.web) { @@ -55,7 +9,6 @@ async function downloadZmqBinaries() { await downloadZMQ(); } -createJupyterKernelWithoutSerialization(); downloadZmqBinaries() .then(() => process.exit(0)) .catch((ex) => { diff --git a/src/altimate.ts b/src/altimate.ts index c2ac7c901..2930127ae 100644 --- a/src/altimate.ts +++ b/src/altimate.ts @@ -10,8 +10,11 @@ import { RateLimitException, ExecutionsExhaustedException } from "./exceptions"; import { DBTProject } from "./manifest/dbtProject"; import { DBTTerminal } from "./dbt_client/dbtTerminal"; import { PythonEnvironment } from "./manifest/pythonEnvironment"; -import { PreconfiguredNotebookItem, NotebookItem, NotebookSchema } from "@lib"; -import * as vscode from "vscode"; +import { + PreconfiguredNotebookItem, + NotebookItem, + NotebookSchema, +} from "@altimateai/extension-components"; export class NoCredentialsError extends Error {} diff --git a/src/code_lens_provider/virtualSqlCodeLensProvider.ts b/src/code_lens_provider/virtualSqlCodeLensProvider.ts index 665886a72..34f1d8430 100644 --- a/src/code_lens_provider/virtualSqlCodeLensProvider.ts +++ b/src/code_lens_provider/virtualSqlCodeLensProvider.ts @@ -11,7 +11,7 @@ import { import { provideSingleton } from "../utils"; import { QueryManifestService } from "../services/queryManifestService"; import { DBTProjectContainer } from "../manifest/dbtProjectContainer"; -import { NotebookService } from "@lib"; +import { NotebookService } from "@altimateai/extension-components"; @provideSingleton(VirtualSqlCodeLensProvider) export class VirtualSqlCodeLensProvider diff --git a/src/commands/index.ts b/src/commands/index.ts index b595a61a2..5406214bf 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -48,7 +48,10 @@ import { DBTProject } from "../manifest/dbtProject"; import { SQLLineagePanel } from "../webview_provider/sqlLineagePanel"; import { QueryManifestService } from "../services/queryManifestService"; import { AltimateRequest } from "../altimate"; -import { DatapilotNotebookController, OpenNotebookRequest } from "@lib"; +import { + DatapilotNotebookController, + OpenNotebookRequest, +} from "@altimateai/extension-components"; import { NotebookQuickPick } from "../quickpick/notebookQuickPick"; @provideSingleton(VSCodeCommands) diff --git a/src/dbtPowerUserExtension.ts b/src/dbtPowerUserExtension.ts index 9f026393a..f5f0ac8a3 100644 --- a/src/dbtPowerUserExtension.ts +++ b/src/dbtPowerUserExtension.ts @@ -21,7 +21,7 @@ import { HoverProviders } from "./hover_provider"; import { DbtPowerUserActionsCenter } from "./quickpick"; import { ValidationProvider } from "./validation_provider"; import { CommentProviders } from "./comment_provider"; -import { NotebookProviders } from "@lib"; +import { NotebookProviders } from "@altimateai/extension-components"; enum PromptAnswer { YES = "Yes", diff --git a/src/inversify.config.ts b/src/inversify.config.ts index 408f020bb..826b4635b 100755 --- a/src/inversify.config.ts +++ b/src/inversify.config.ts @@ -39,7 +39,10 @@ import { AltimateRequest } from "./altimate"; import { ValidationProvider } from "./validation_provider"; import { DeferToProdService } from "./services/deferToProdService"; import { SharedStateService } from "./services/sharedStateService"; -import { NotebookKernelClient, NotebookDependencies } from "@lib"; +import { + NotebookKernelClient, + NotebookDependencies, +} from "@altimateai/extension-components"; import { DBTCoreCommandProjectIntegration } from "./dbt_client/dbtCoreCommandIntegration"; export const container = new Container(); diff --git a/src/lib/index.d.ts b/src/lib/index.d.ts deleted file mode 100644 index 434d5cd5b..000000000 --- a/src/lib/index.d.ts +++ /dev/null @@ -1,443 +0,0 @@ -import { AltimateRequest } from "../dependencies.d.ts"; -import { CancellationToken } from "vscode"; -import { CommandProcessExecutionFactory } from "../../dependencies.d.ts"; -import { DBTCommandExecutionInfrastructure } from "../dependencies.d.ts"; -import { DBTCommandExecutionInfrastructure as DBTCommandExecutionInfrastructure_2 } from "../../dependencies.d.ts"; -import { DBTProject } from "../../dependencies.d.ts"; -import { DBTTerminal } from "../../dependencies.d.ts"; -import { DBTTerminal as DBTTerminal_2 } from "../dependencies.d.ts"; -import { Disposable as Disposable_2 } from "vscode"; -import { Event as Event_2 } from "vscode"; -import { ExecuteSQLResult } from "../dependencies.d.ts"; -import { FileChangeEvent } from "vscode"; -import { FileStat } from "vscode"; -import { FileSystemProvider } from "vscode"; -import { FileType } from "vscode"; -import { KernelConnection } from "@jupyterlab/services"; -import { NotebookCell } from "vscode"; -import { NotebookCellKind } from "vscode"; -import { NotebookCellOutput } from "vscode"; -import { NotebookData } from "vscode"; -import { NotebookSerializer } from "vscode"; -import { PythonEnvironment } from "../../dependencies.d.ts"; -import { QueryManifestService } from "../dependencies.d.ts"; -import { TelemetryService } from "../../dependencies.d.ts"; -import { TelemetryService as TelemetryService_2 } from "../dependencies.d.ts"; -import { Uri } from "vscode"; - -declare class ClientMapper { - private executionInfrastructure; - private notebookDependencies; - private dbtTerminal; - private clientMap; - constructor( - executionInfrastructure: DBTCommandExecutionInfrastructure, - notebookDependencies: NotebookDependencies, - dbtTerminal: DBTTerminal_2, - ); - initializeNotebookClient(notebookUri: Uri): Promise; - getNotebookClient(notebookUri: Uri): Promise; -} - -declare interface ColumnConfig { - name: string; - tests: string[]; - [key: string]: any; -} - -declare interface ConnectionSettings { - control_port: number; - hb_port: number; - iopub_port: number; - ip: string; - key: string; - kernel_name: string; - shell_port: number; - signature_scheme: string; - stdin_port: number; - transport: string; -} - -export declare const CustomNotebooks: { - notebooks: PreconfiguredNotebookItem[]; -}; - -export declare class DatapilotNotebookController implements Disposable_2 { - private clientMapper; - private queryManifestService; - private telemetry; - private dbtTerminal; - private notebookDependencies; - private altimate; - private readonly id; - private readonly label; - private _onNotebookCellEvent; - readonly onNotebookCellChangeEvent: Event_2; - private readonly disposables; - private associatedNotebooks; - private executionOrder; - private readonly controller; - constructor( - clientMapper: ClientMapper, - queryManifestService: QueryManifestService, - telemetry: TelemetryService_2, - dbtTerminal: DBTTerminal_2, - notebookDependencies: NotebookDependencies, - altimate: AltimateRequest, - ); - private getNotebookByTemplate; - modelTestSuggestions(args: any): Promise; - generateDbtSourceYaml(args: any): Promise; - generateDbtDbtModelSql(args: any): Promise; - generateDbtDbtModelYaml(args: any): Promise; - generateDbtDbtModelCTE(args: any): Promise; - extractExposuresFromMetabase(args: any): Promise; - extractExposuresFromTableau(args: any): Promise; - private getFileName; - createNotebook(args: OpenNotebookRequest | undefined): Promise; - private sendMessageToPreloadScript; - private getRandomString; - private genUniqueId; - private updateCellId; - private onNotebookClose; - private onDidChangeSelectedNotebooks; - private onNotebookOpen; - private waitForControllerAssociation; - private isControllerAssociatedWithNotebook; - dispose(): void; - private _executeAll; - private filterIPyWidgets; - private updateContextVariablesInKernel; - private _doExecution; -} - -declare class DatapilotNotebookSerializer - implements NotebookSerializer, Disposable_2 -{ - dispose(): void; - deserializeNotebook( - content: Uint8Array, - _token: CancellationToken, - ): Promise; - serializeNotebook( - data: NotebookData, - _token: CancellationToken, - ): Promise; -} - -declare interface DBColumn { - column: string; - dtype: string; -} - -export declare interface DbtConfig { - [key: string]: Model[]; -} - -export declare const getTestSuggestions: ({ - tableRelation, - sample, - limit, - resourceType, - columnConfig, - excludeTypes, - excludeCols, - tests, - uniquenessCompositeKeyLength, - acceptedValuesMaxCardinality, - rangeStddevs, - stringLengthStddevs, - recencyStddevs, - dbtConfig, - returnObject, - columnsInRelation, - adapter, - queryFn, -}: Props) => Promise; - -export declare interface IPyWidgetMessage { - type: string; - payload: any; -} - -export declare interface Model { - name: string; - columns: ColumnConfig[]; - tests?: any[]; -} - -export declare interface NotebookCellEvent { - cellId: string; - notebook: string; - result?: any; - event: "add" | "update" | "delete"; - fragment?: string; - languageId: string; -} - -export declare interface NotebookCellSchema { - source: string[]; - cell_type: NotebookCellKind; - languageId: string; - metadata?: Record; - outputs?: NotebookCellOutput[]; -} - -export declare class NotebookDependencies { - private readonly dbtTerminal; - private readonly telemetry; - private commandProcessExecutionFactory; - private pythonEnvironment; - constructor( - dbtTerminal: DBTTerminal, - telemetry: TelemetryService, - commandProcessExecutionFactory: CommandProcessExecutionFactory, - pythonEnvironment: PythonEnvironment, - ); - private checkPythonDependencies; - private checkDbtDependencies; - private installMissingPythonPackages; - private installMissingDbtPackages; - verifyAndInstallDependenciesIfNeeded( - dependencies: NotebookDependency[], - project: DBTProject, - ): Promise; - getDependenciesVersion(): Promise>; - validateAndInstallNotebookDependencies(): Promise; - private notebookDependenciesAreInstalled; -} - -export declare interface NotebookDependency { - type: "dbt" | "python"; - package: string; - name?: string; - version?: string; -} - -export declare class NotebookFileSystemProvider implements FileSystemProvider { - private dbtTerminal; - private altimate; - private _emitter; - readonly onDidChangeFile: Event_2; - private notebookDataMap; - constructor(dbtTerminal: DBTTerminal_2, altimate: AltimateRequest); - watch( - _uri: Uri, - _options: { - recursive: boolean; - excludes: string[]; - }, - ): Disposable_2; - stat(_uri: Uri): FileStat; - readDirectory(_uri: Uri): [string, FileType][]; - createDirectory(_uri: Uri): void; - private getNotebookData; - readFile(uri: Uri): Promise; - writeFile( - uri: Uri, - content: Uint8Array, - _options: { - create: boolean; - overwrite: boolean; - }, - ): Promise; - delete( - uri: Uri, - _options: { - recursive: boolean; - }, - ): void; - rename( - oldUri: Uri, - newUri: Uri, - _options: { - overwrite: boolean; - }, - ): void; - private getFileNameFromUri; - private customSave; - private saveNotebook; -} - -export declare interface NotebookItem { - id: number; - name: string; - data: NotebookSchema; - description: string; - created_on: string; - updated_on: string; - tags: { - id: number; - tag: string; - }[]; - privacy: boolean; -} - -export declare class NotebookKernelClient implements Disposable_2 { - private executionInfrastructure; - private notebookDependencies; - private dbtTerminal; - get postMessage(): Event_2; - private _postMessageEmitter; - private disposables; - private lastUsedStreamOutput?; - private static modelIdsOwnedByCells; - private python; - private kernel; - private isInitializing; - private readonly ownedCommIds; - private readonly commIdsMappedToWidgetOutputModels; - private readonly ownedRequestMsgIds; - private commIdsMappedToParentWidgetModel; - private streamsReAttachedToExecutingCell; - private registerdCommTargets; - private outputsAreSpecificToAWidget; - private versions?; - constructor( - notebookPath: string, - executionInfrastructure: DBTCommandExecutionInfrastructure_2, - notebookDependencies: NotebookDependencies, - dbtTerminal: DBTTerminal, - ); - isInitialized(): Promise; - dispose(): Promise; - get jupyterPackagesVersions(): Record | undefined; - private getDependenciesVersion; - getKernel(): Promise; - private initializeNotebookKernel; - onKernelSocketResponse(payload: { id: string }): void; - storeContext(context: any): Promise; - storeDataInKernel(cellId: string, data: any): Promise; - registerCommTarget(payload: string): Promise; - getPythonCodeByType(type: string, cellId: string): Promise; - executePython( - code: string, - cell: NotebookCell, - onOutput: (output: NotebookCellOutput) => void, - ): Promise; - private handleUpdateDisplayDataMessage; - private handleCommOpen; - private handleCommMsg; - private handleExecuteResult; - private addToCellData; - private canMimeTypeBeRenderedByWidgetManager; - private handleExecuteInput; - private handleStatusMessage; - private handleStreamMessage; - private handleDisplayData; - private handleClearOutput; - private handleError; -} - -export declare class NotebookProviders implements Disposable_2 { - private notebookProvider; - private notebookController; - private notebookFileSystemProvider; - private dbtTerminal; - private disposables; - constructor( - notebookProvider: DatapilotNotebookSerializer, - notebookController: DatapilotNotebookController, - notebookFileSystemProvider: NotebookFileSystemProvider, - dbtTerminal: DBTTerminal_2, - ); - private bindNotebookActions; - dispose(): void; -} - -export declare interface NotebookSchema { - cells: NotebookCellSchema[]; - metadata?: Record; -} - -export declare class NotebookService implements Disposable_2 { - private notebookKernel; - private disposables; - private cellByNotebookAutocompleteMap; - constructor(notebookKernel: DatapilotNotebookController); - dispose(): void; - getCellByNotebookAutocompleteMap(): Map< - string, - { - cellId: string; - fragment: string; - languageId: string; - }[] - >; - private onNotebookCellChanged; -} - -export declare interface OpenNotebookRequest { - notebookId?: string; - template?: string; - context?: Record; - notebookSchema?: NotebookSchema; -} - -export declare interface PreconfiguredNotebookItem { - name: string; - description: string; - created_at: string; - updated_at: string; - id: string; - tags: string[]; - data: NotebookSchema; -} - -declare interface Props { - tableRelation: string; - sample?: boolean; - limit?: number; - resourceType?: string; - columnConfig?: Record; - excludeTypes?: string[]; - excludeCols?: string[]; - tests?: ( - | "uniqueness" - | "accepted_values" - | "range" - | "string_length" - | "recency" - )[]; - uniquenessCompositeKeyLength?: number; - acceptedValuesMaxCardinality?: number; - rangeStddevs?: number; - stringLengthStddevs?: number; - recencyStddevs?: number; - dbtConfig?: Record; - returnObject?: boolean; - columnsInRelation: DBColumn[]; - adapter: string; - queryFn: QueryFn; -} - -declare type QueryFn = (query: string) => Promise; - -declare interface RawKernelType { - realKernel: KernelConnection; - socket: any; - kernelProcess: { - connection: ConnectionSettings; - pid: number; - }; -} - -export {}; - -export declare namespace Identifiers { - const GeneratedThemeName = "ipython-theme"; - const MatplotLibDefaultParams = "_VSCode_defaultMatplotlib_Params"; - const MatplotLibFigureFormats = "_VSCode_matplotLib_FigureFormats"; - const DefaultCodeCellMarker = "# %%"; - const DefaultCommTarget = "jupyter.widget"; - const ALL_VARIABLES = "ALL_VARIABLES"; - const KERNEL_VARIABLES = "KERNEL_VARIABLES"; - const DEBUGGER_VARIABLES = "DEBUGGER_VARIABLES"; - const PYTHON_VARIABLES_REQUESTER = "PYTHON_VARIABLES_REQUESTER"; - const MULTIPLEXING_DEBUGSERVICE = "MULTIPLEXING_DEBUGSERVICE"; - const RUN_BY_LINE_DEBUGSERVICE = "RUN_BY_LINE_DEBUGSERVICE"; - const REMOTE_URI = "https://remote/"; - const REMOTE_URI_ID_PARAM = "id"; - const REMOTE_URI_HANDLE_PARAM = "uriHandle"; - const REMOTE_URI_EXTENSION_ID_PARAM = "extensionId"; -} diff --git a/src/lib/index.js b/src/lib/index.js deleted file mode 100644 index d135bd7bf..000000000 --- a/src/lib/index.js +++ /dev/null @@ -1,3649 +0,0 @@ -"use strict"; -Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); -const l = require("vscode"), - p = require("@extension"), - ie = require("python-bridge"), - ue = require("fs"), - de = require("@nteract/messaging/lib/wire-protocol"); -function pe(o) { - const e = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } }); - if (o) { - for (const t in o) - if (t !== "default") { - const n = Object.getOwnPropertyDescriptor(o, t); - Object.defineProperty( - e, - t, - n.get ? n : { enumerable: !0, get: () => o[t] }, - ); - } - } - return (e.default = o), Object.freeze(e); -} -const te = pe(de), - he = (o) => ("getCells" in o ? o.getCells() : o.cells), - me = (o) => - o instanceof l.NotebookCellData ? o.value : o.document.getText(), - fe = (o) => - o instanceof l.NotebookCellData ? o.languageId : o.document.languageId, - X = (o, e, t) => { - var r; - const n = []; - for (const s of he(o)) - n.push({ - cell_type: s.kind, - source: me(s).split(/\r?\n/g), - languageId: fe(s), - metadata: s.metadata, - outputs: t ? s.outputs : void 0, - }); - return { - cells: n, - metadata: { - ...o.metadata, - name: e, - createdAt: - ((r = o.metadata) == null ? void 0 : r.createdAt) || - new Date().toISOString(), - updatedAt: new Date().toISOString(), - }, - }; - }, - A = () => Math.random().toString(36).substr(2, 9); -function be() { - const o = new Date(), - e = o.toLocaleDateString("en-GB").replace(/\//g, "-"), - t = o.toLocaleTimeString("en-GB", { hour12: !1 }).replace(/:/g, "-"); - return `${e}-${t}`; -} -var ge = function (o, e, t, n) { - var r = arguments.length, - s = - r < 3 ? e : n === null ? (n = Object.getOwnPropertyDescriptor(e, t)) : n, - a; - if (typeof Reflect == "object" && typeof Reflect.decorate == "function") - s = Reflect.decorate(o, e, t, n); - else - for (var i = o.length - 1; i >= 0; i--) - (a = o[i]) && (s = (r < 3 ? a(s) : r > 3 ? a(e, t, s) : a(e, t)) || s); - return r > 3 && s && Object.defineProperty(e, t, s), s; -}; -let U = class { - dispose() { - throw new Error("Method not implemented."); - } - async deserializeNotebook(e, t) { - const n = new TextDecoder().decode(e); - let r; - try { - r = JSON.parse(n); - } catch { - r = { cells: [] }; - } - const s = r.cells.map((i) => { - var u; - const c = new l.NotebookCellData( - i.cell_type, - (u = i.source) == null - ? void 0 - : u.join(` -`), - i.languageId, - ); - return (c.metadata = i.metadata), (c.outputs = i.outputs), c; - }), - a = new l.NotebookData(s); - return (a.metadata = r.metadata), a; - } - async serializeNotebook(e, t) { - const n = X(e); - return new TextEncoder().encode(JSON.stringify(n)); - } -}; -U = ge([p.provideSingleton(U)], U); -var P; -(function (o) { - (o.error = "application/vnd.code.notebook.error"), - (o.stderr = "application/vnd.code.notebook.stderr"), - (o.stdout = "application/vnd.code.notebook.stdout"); -})(P || (P = {})); -const ye = ["text/plain", "text/markdown", P.stderr, P.stdout], - ne = [ - "application/vnd.*", - "application/vdom.*", - "application/geo+json", - "application/x-nteract-model-debug+json", - "text/html", - "application/javascript", - "image/gif", - "text/latex", - "text/markdown", - "image/png", - "image/svg+xml", - "image/jpeg", - "application/json", - "text/plain", - ], - D = new Map(); -D.set("display_data", G); -D.set("error", Ce); -D.set("execute_result", G); -D.set("stream", Se); -D.set("update_display_data", G); -function Y(o) { - const e = D.get(o.output_type); - let t; - return ( - e - ? (t = e(o)) - : (console.warn( - `Unable to translate cell from ${o.output_type} to NotebookCellData for VS Code.`, - ), - (t = G(o))), - t - ); -} -function ee(o) { - const e = { outputType: o.output_type }; - switch ((o.transient && (e.transient = o.transient), o.output_type)) { - case "display_data": - case "execute_result": - case "update_display_data": { - (e.executionCount = o.execution_count), - (e.metadata = o.metadata ? JSON.parse(JSON.stringify(o.metadata)) : {}); - break; - } - } - return e; -} -function G(o) { - const e = ee(o); - ("image/svg+xml" in o.data || "image/png" in o.data) && - (e.__displayOpenPlotIcon = !0); - const t = []; - if (o.data) for (const n in o.data) t.push(ke(n, o.data[n])); - return new l.NotebookCellOutput(we(t), e); -} -function we(o) { - return o.sort((e, t) => { - const n = (a, i) => ( - a.endsWith(".*") && (a = a.substr(0, a.indexOf(".*"))), i.startsWith(a) - ); - let r = ne.findIndex((a) => n(a, e.mime)), - s = ne.findIndex((a) => n(a, t.mime)); - return ( - oe(e) && (r = -1), - oe(t) && (s = -1), - (r = r === -1 ? 100 : r), - (s = s === -1 ? 100 : s), - r - s - ); - }); -} -function oe(o) { - if (o.mime.startsWith("application/vnd.")) - try { - return new TextDecoder().decode(o.data).length === 0; - } catch {} - return !1; -} -function ke(o, e) { - if (!e) return l.NotebookCellOutputItem.text("", o); - try { - if ( - (o.startsWith("text/") || ye.includes(o)) && - (Array.isArray(e) || typeof e == "string") - ) { - const t = Array.isArray(e) ? z(e) : e; - return l.NotebookCellOutputItem.text(t, o); - } else - return o.startsWith("image/") && - typeof e == "string" && - o !== "image/svg+xml" - ? new l.NotebookCellOutputItem(_e(e), o) - : typeof e == "object" && e !== null && !Array.isArray(e) - ? l.NotebookCellOutputItem.text(JSON.stringify(e), o) - : ((e = Array.isArray(e) ? z(e) : e), - l.NotebookCellOutputItem.text(e, o)); - } catch (t) { - return ( - console.error( - `Failed to convert ${o} output to a buffer ${typeof e}, ${e}`, - t, - ), - l.NotebookCellOutputItem.text("") - ); - } -} -function _e(o) { - return typeof Buffer < "u" && typeof Buffer.from == "function" - ? Buffer.from(o, "base64") - : Uint8Array.from(atob(o), (e) => e.charCodeAt(0)); -} -function z(o) { - if (Array.isArray(o)) { - let e = ""; - for (let t = 0; t < o.length; t += 1) { - const n = o[t]; - t < o.length - 1 && - !n.endsWith(` -`) - ? (e = e.concat(`${n} -`)) - : (e = e.concat(n)); - } - return e; - } - return o.toString(); -} -function ve(o) { - let e = o; - do (o = e), (e = o.replace(/[^\n]\x08/gm, "")); - while (e.length < o.length); - return o; -} -function Te(o) { - for ( - o = o.replace( - /\r+\n/gm, - ` -`, - ); - o.search(/\r[^$]/g) > -1; - - ) { - const e = o.match(/^(.*)\r+/m)[1]; - let t = o.match(/\r+(.*)$/m)[1]; - (t = t + e.slice(t.length, e.length)), - (o = o.replace(/\r+.*$/m, "\r").replace(/^.*\r/m, t)); - } - return o; -} -function Ee(o) { - return Te(ve(o)); -} -function B(o) { - if (o.parent_header && "msg_id" in o.parent_header) - return o.parent_header.msg_id; -} -function Ne(o) { - if (o.hasOwnProperty("text/html")) { - const e = o["text/html"]; - typeof e == "string" && - e.includes('