MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / convertStreamOutput

Function convertStreamOutput

src/kernels/execution/helpers.ts:452–486  ·  view source on GitHub ↗
(output: NotebookCellOutput)

Source from the content-addressed store, hash-verified

450 }
451}
452function convertStreamOutput(output: NotebookCellOutput): JupyterOutput {
453 const outputs: string[] = [];
454 output.items
455 .filter((opit) => opit.mime === CellOutputMimeTypes.stderr || opit.mime === CellOutputMimeTypes.stdout)
456 .map((opit) => textDecoder.decode(opit.data))
457 .forEach((value) => {
458 // Ensure each line is a seprate entry in an array (ending with \n).
459 const lines = value.split('\n');
460 // If the last item in `outputs` is not empty and the first item in `lines` is not empty, then concate them.
461 // As they are part of the same line.
462 if (outputs.length && lines.length && lines[0].length > 0) {
463 outputs[outputs.length - 1] = `${outputs[outputs.length - 1]}${lines.shift()!}`;
464 }
465 for (const line of lines) {
466 outputs.push(line);
467 }
468 });
469
470 for (let index = 0; index < outputs.length - 1; index++) {
471 outputs[index] = `${outputs[index]}\n`;
472 }
473
474 // Skip last one if empty (it's the only one that could be length 0)
475 if (outputs.length && outputs[outputs.length - 1].length === 0) {
476 outputs.pop();
477 }
478
479 const streamType = getOutputStreamType(output) || 'stdout';
480
481 return {
482 output_type: 'stream',
483 name: streamType,
484 text: outputs
485 };
486}
487export function translateCellDisplayOutput(output: NotebookCellOutput): JupyterOutput {
488 const customMetadata = output.metadata as CellOutputMetadata | undefined;
489 let result: JupyterOutput;

Callers 1

Calls 7

getOutputStreamTypeFunction · 0.85
mapMethod · 0.80
filterMethod · 0.80
shiftMethod · 0.80
decodeMethod · 0.65
pushMethod · 0.65
forEachMethod · 0.45

Tested by

no test coverage detected