@notebook-intelligence/notebook-intelligence 2.3.1 → 2.3.2

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/lib/index.js CHANGED
@@ -21,6 +21,7 @@ import sparklesSvgstr from '../style/icons/sparkles.svg';
21
21
  import copilotSvgstr from '../style/icons/copilot.svg';
22
22
  import { applyCodeToSelectionInEditor, cellOutputAsText, compareSelections, extractLLMGeneratedCode, getSelectionInEditor, getTokenCount, getWholeNotebookContent, isSelectionEmpty, markdownToComment, waitForDuration } from './utils';
23
23
  import { UUID } from '@lumino/coreutils';
24
+ import * as path from 'path';
24
25
  var CommandIDs;
25
26
  (function (CommandIDs) {
26
27
  CommandIDs.chatuserInput = 'notebook-intelligence:chat-user-input';
@@ -28,6 +29,7 @@ var CommandIDs;
28
29
  CommandIDs.addCodeAsNewCell = 'notebook-intelligence:add-code-as-new-cell';
29
30
  CommandIDs.createNewFile = 'notebook-intelligence:create-new-file';
30
31
  CommandIDs.createNewNotebookFromPython = 'notebook-intelligence:create-new-notebook-from-py';
32
+ CommandIDs.renameNotebook = 'notebook-intelligence:rename-notebook';
31
33
  CommandIDs.addCodeCellToNotebook = 'notebook-intelligence:add-code-cell-to-notebook';
32
34
  CommandIDs.addMarkdownCellToNotebook = 'notebook-intelligence:add-markdown-cell-to-notebook';
33
35
  CommandIDs.editorGenerateCode = 'notebook-intelligence:editor-generate-code';
@@ -577,6 +579,32 @@ const plugin = {
577
579
  return newNBFile;
578
580
  }
579
581
  });
582
+ app.commands.addCommand(CommandIDs.renameNotebook, {
583
+ execute: async (args) => {
584
+ const activeWidget = app.shell.currentWidget;
585
+ if (activeWidget instanceof NotebookPanel) {
586
+ const oldPath = activeWidget.context.path;
587
+ const oldParentPath = path.dirname(oldPath);
588
+ let newPath = path.join(oldParentPath, args.newName);
589
+ if (path.extname(newPath) !== '.ipynb') {
590
+ newPath += '.ipynb';
591
+ }
592
+ if (path.dirname(newPath) !== oldParentPath) {
593
+ return 'Failed to rename notebook. New path is outside the old parent directory';
594
+ }
595
+ try {
596
+ await app.serviceManager.contents.rename(oldPath, newPath);
597
+ return 'Successfully renamed notebook';
598
+ }
599
+ catch (error) {
600
+ return `Failed to rename notebook: ${error}`;
601
+ }
602
+ }
603
+ else {
604
+ return 'Cannot rename non notebook files';
605
+ }
606
+ }
607
+ });
580
608
  const isNewEmptyNotebook = (model) => {
581
609
  return (model.cells.length === 1 &&
582
610
  model.cells[0].cell_type === 'code' &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notebook-intelligence/notebook-intelligence",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "AI coding assistant for JupyterLab",
5
5
  "keywords": [
6
6
  "AI",
package/src/index.ts CHANGED
@@ -80,6 +80,8 @@ import {
80
80
  } from './utils';
81
81
  import { UUID } from '@lumino/coreutils';
82
82
 
83
+ import * as path from 'path';
84
+
83
85
  namespace CommandIDs {
84
86
  export const chatuserInput = 'notebook-intelligence:chat-user-input';
85
87
  export const insertAtCursor = 'notebook-intelligence:insert-at-cursor';
@@ -87,6 +89,7 @@ namespace CommandIDs {
87
89
  export const createNewFile = 'notebook-intelligence:create-new-file';
88
90
  export const createNewNotebookFromPython =
89
91
  'notebook-intelligence:create-new-notebook-from-py';
92
+ export const renameNotebook = 'notebook-intelligence:rename-notebook';
90
93
  export const addCodeCellToNotebook =
91
94
  'notebook-intelligence:add-code-cell-to-notebook';
92
95
  export const addMarkdownCellToNotebook =
@@ -786,6 +789,33 @@ const plugin: JupyterFrontEndPlugin<INotebookIntelligence> = {
786
789
  }
787
790
  });
788
791
 
792
+ app.commands.addCommand(CommandIDs.renameNotebook, {
793
+ execute: async args => {
794
+ const activeWidget = app.shell.currentWidget;
795
+ if (activeWidget instanceof NotebookPanel) {
796
+ const oldPath = activeWidget.context.path;
797
+ const oldParentPath = path.dirname(oldPath);
798
+ let newPath = path.join(oldParentPath, args.newName as string);
799
+ if (path.extname(newPath) !== '.ipynb') {
800
+ newPath += '.ipynb';
801
+ }
802
+
803
+ if (path.dirname(newPath) !== oldParentPath) {
804
+ return 'Failed to rename notebook. New path is outside the old parent directory';
805
+ }
806
+
807
+ try {
808
+ await app.serviceManager.contents.rename(oldPath, newPath);
809
+ return 'Successfully renamed notebook';
810
+ } catch (error) {
811
+ return `Failed to rename notebook: ${error}`;
812
+ }
813
+ } else {
814
+ return 'Cannot rename non notebook files';
815
+ }
816
+ }
817
+ });
818
+
789
819
  const isNewEmptyNotebook = (model: ISharedNotebook) => {
790
820
  return (
791
821
  model.cells.length === 1 &&