Skip to content

Commit

Permalink
feat(jupyter): add args to notebook metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshinesmilelk committed Jan 31, 2024
1 parent f7c6839 commit 3eacc16
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/libro-jupyter/src/libro-jupyter-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { VirtualizedManager } from '@difizen/libro-core';
import {
ContentsManager,
ExecutableNotebookModel,
isDisplayDataMsg,
LibroKernelConnectionManager,
ServerConnection,
ServerManager,
Expand All @@ -16,6 +17,7 @@ import { l10n } from '@difizen/mana-l10n';

import {
ExecutedWithKernelCellModel,
libroArgsMimetype,
LibroFileService,
} from './libro-jupyter-protocol.js';
import { SaveFileErrorModal } from './toolbar/save-file-error.js';
Expand Down Expand Up @@ -81,6 +83,21 @@ export class LibroJupyterModel extends LibroModel implements ExecutableNotebookM
this.modalService = modalService;
this.dndAreaNullEnable = true;
this.virtualizedManager = virtualizedManagerHelper.getOrCreate(this);
this.kcReady
.then(() => {
this.kernelConnection?.futureMessage((msg) => {
if (isDisplayDataMsg(msg) && libroArgsMimetype in msg.content.data) {
this.metadata = {
...this.metadata,
args: msg.content.data[libroArgsMimetype],
};
}
});
return;
})
.catch(() => {
return;
});
}

get isKernelIdle() {
Expand Down
2 changes: 2 additions & 0 deletions packages/libro-jupyter/src/libro-jupyter-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ export const ServerLaunchManager = Symbol('ServerLaunchManager');
export interface ServerLaunchManager {
launch: () => Promise<any>;
}

export const libroArgsMimetype = 'application/vnd.libro.args+json';
9 changes: 9 additions & 0 deletions packages/libro-kernel/src/kernel/kernel-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ export class KernelConnection implements IKernelConnection {
return this.iopubMessageEmitter.event;
}

get futureMessage(): ManaEvent<KernelMessage.IMessage<KernelMessage.MessageType>> {
return this.futureMessageEmitter.event;
}

/**
* A signal emitted for unhandled kernel message.
*
Expand Down Expand Up @@ -381,6 +385,7 @@ export class KernelConnection implements IKernelConnection {
this.statusChangedEmitter.dispose();
this.onDisposedEmitter.dispose();
this.iopubMessageEmitter.dispose();
this.futureMessageEmitter.dispose();
this.anyMessageEmitter.dispose();
this.pendingInputEmitter.dispose();
this.unhandledMessageEmitter.dispose();
Expand Down Expand Up @@ -1529,6 +1534,7 @@ export class KernelConnection implements IKernelConnection {
const future = this._futures?.get(parentHeader.msg_id);
if (future) {
await future.handleMsg(msg);
this.futureMessageEmitter.fire(msg);
this._assertCurrentMessage(msg);
} else {
// If the message was sent by us and was not iopub, it is orphaned.
Expand Down Expand Up @@ -1756,6 +1762,9 @@ export class KernelConnection implements IKernelConnection {
protected connectionStatusChangedEmitter = new Emitter<ConnectionStatus>();
protected onDisposedEmitter = new Emitter<void>();
protected iopubMessageEmitter = new Emitter<KernelMessage.IIOPubMessage>();
protected futureMessageEmitter = new Emitter<
KernelMessage.IMessage<KernelMessage.MessageType>
>();
protected anyMessageEmitter = new Emitter<IAnyMessageArgs>();
protected pendingInputEmitter = new Emitter<boolean>();
protected unhandledMessageEmitter = new Emitter<KernelMessage.IMessage>();
Expand Down
1 change: 1 addition & 0 deletions packages/libro-kernel/src/kernel/libro-kernel-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ export interface IKernelConnection extends ObservableDisposable {
*/
iopubMessage: Event<KernelMessage.IIOPubMessage>;

futureMessage: Event<KernelMessage.IMessage<KernelMessage.MessageType>>;
/**
* A signal emitted for unhandled non-iopub kernel messages that claimed to
* be responses for messages we sent using this kernel object.
Expand Down

0 comments on commit 3eacc16

Please sign in to comment.