codebind 0.6.9__tar.gz → 0.6.11__tar.gz

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.
Files changed (32) hide show
  1. {codebind-0.6.9 → codebind-0.6.11}/PKG-INFO +7 -6
  2. {codebind-0.6.9 → codebind-0.6.11}/README.md +6 -5
  3. {codebind-0.6.9 → codebind-0.6.11}/data/share/jupyter/labextensions/codebind-jupyterlab/package.json +2 -2
  4. codebind-0.6.11/data/share/jupyter/labextensions/codebind-jupyterlab/static/590.98c719a309e23852.js +1 -0
  5. codebind-0.6.11/data/share/jupyter/labextensions/codebind-jupyterlab/static/remoteEntry.24258c9500a0850a.js +1 -0
  6. {codebind-0.6.9 → codebind-0.6.11}/jupyterlab/package.json +1 -1
  7. {codebind-0.6.9 → codebind-0.6.11}/jupyterlab/src/index.ts +165 -72
  8. {codebind-0.6.9 → codebind-0.6.11}/pyproject.toml +1 -1
  9. {codebind-0.6.9 → codebind-0.6.11}/pyproject.toml.orig +1 -1
  10. {codebind-0.6.9 → codebind-0.6.11}/src/codebind/execution.py +39 -23
  11. {codebind-0.6.9 → codebind-0.6.11}/src/codebind/extension.py +28 -0
  12. {codebind-0.6.9 → codebind-0.6.11}/src/codebind/jupyter.py +45 -19
  13. {codebind-0.6.9 → codebind-0.6.11}/src/codebind/session.py +1 -12
  14. {codebind-0.6.9 → codebind-0.6.11}/src/codebind/terminal.py +50 -37
  15. codebind-0.6.9/data/share/jupyter/labextensions/codebind-jupyterlab/static/590.dae4561c5427a855.js +0 -1
  16. codebind-0.6.9/data/share/jupyter/labextensions/codebind-jupyterlab/static/remoteEntry.c10098fb6e87897c.js +0 -1
  17. {codebind-0.6.9 → codebind-0.6.11}/LICENSE +0 -0
  18. {codebind-0.6.9 → codebind-0.6.11}/data/share/jupyter/labextensions/codebind-jupyterlab/install.json +0 -0
  19. {codebind-0.6.9 → codebind-0.6.11}/data/share/jupyter/labextensions/codebind-jupyterlab/static/style.js +0 -0
  20. {codebind-0.6.9 → codebind-0.6.11}/data/share/jupyter/labextensions/codebind-jupyterlab/static/third-party-licenses.json +0 -0
  21. {codebind-0.6.9 → codebind-0.6.11}/jupyterlab/.yarnrc.yml +0 -0
  22. {codebind-0.6.9 → codebind-0.6.11}/jupyterlab/install.json +0 -0
  23. {codebind-0.6.9 → codebind-0.6.11}/jupyterlab/tsconfig.json +0 -0
  24. {codebind-0.6.9 → codebind-0.6.11}/jupyterlab/yarn.lock +0 -0
  25. {codebind-0.6.9 → codebind-0.6.11}/src/codebind/__init__.py +0 -0
  26. {codebind-0.6.9 → codebind-0.6.11}/src/codebind/cli.py +0 -0
  27. {codebind-0.6.9 → codebind-0.6.11}/src/codebind/configuration.py +0 -0
  28. {codebind-0.6.9 → codebind-0.6.11}/src/codebind/conversation.py +0 -0
  29. {codebind-0.6.9 → codebind-0.6.11}/src/codebind/display.py +0 -0
  30. {codebind-0.6.9 → codebind-0.6.11}/src/codebind/images.py +0 -0
  31. {codebind-0.6.9 → codebind-0.6.11}/src/codebind/instructions.md +0 -0
  32. {codebind-0.6.9 → codebind-0.6.11}/src/codebind/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codebind
3
- Version: 0.6.9
3
+ Version: 0.6.11
4
4
  Summary: A frontend-neutral model loop for persistent IPython sessions.
5
5
  Keywords: ai,ipython,llm,repl,agents
6
6
  Author: Giovanni Gravili
@@ -75,7 +75,7 @@ Inspect this project and tell me what to implement first.
75
75
  ```
76
76
 
77
77
  Terminal conversations remain live for the current IPython process. Previous terminal inputs and outputs, including Python cells you ran yourself, enter the model's context when you ask a question. Durable automatic resumption belongs to notebooks, where the notebook file provides an unambiguous conversation identity.
78
- Model-executed cells appear with IPython's native input counter, syntax highlighting, output prompts, streams, and tracebacks. Assistant Markdown appears before the following tool cell, and tool output appears as it is written. To keep terminal scrollback usable, Codebind shows at most 10 gray lines of each model-executed cell's output, then displays a notice such as `… 990 more output lines. Run %output 8 to view all.` The complete output remains available to the model and in IPython history; `%output 8` opens its full text in IPython's pager. User-entered Python cells keep IPython's normal display behavior. Assistant Markdown is rendered through IPython's terminal MIME renderer. A terminal is a stream rather than a notebook document, so these displays are not editable notebook cells.
78
+ Model-executed cells appear with IPython's native input counter, syntax highlighting, output prompts, streams, and tracebacks. Assistant Markdown appears before the following tool cell, and tool output appears as it is written. To keep terminal scrollback usable, Codebind previews at most three gray output lines, shortening each line after 60 characters with `...`. Further lines appear as `… N more output lines.` The complete output remains available to the model and in IPython history; `%output 8` opens the full text of cell 8 in IPython's pager. User-entered Python cells keep IPython's normal display behavior. Assistant Markdown is rendered through IPython's terminal MIME renderer. A terminal is a stream rather than a notebook document, so these displays are not editable notebook cells.
79
79
 
80
80
  ## JupyterLab
81
81
 
@@ -97,15 +97,16 @@ Load Codebind in a notebook:
97
97
  %load_ext codebind
98
98
  ```
99
99
 
100
- That is the complete setup. **Question** is a native toolbar toggle:
100
+ That is the complete setup. **Question** is a native toolbar toggle, also available with `Shift+Tab`:
101
101
 
102
102
  - Turning it on converts the selected cell into a Question and makes each newly created user cell a Question until the toggle is turned off.
103
- - Codebind-generated instruction, tool, and answer cells are never converted.
103
+ - Turning it off returns the selected unsent Question to a Python code cell.
104
+ - Codebind-generated tool and answer cells are never converted.
104
105
  - Write ordinary Markdown and press `Shift+Enter`.
105
106
 
106
107
  ### Instructions and notebook context
107
108
 
108
- - Loading the extension adds a locked Markdown cell containing Codebind's packaged instructions. Its exact text becomes the conversation's immutable system message and remains stable when the server or kernel restarts.
109
+ - Loading the extension stores Codebind's packaged instructions as the conversation's immutable system message in notebook metadata, without showing an instructions cell. Reopening the notebook or restarting its kernel preserves that message.
109
110
  - The whole notebook is model context. Before each Question, Codebind snapshots ordinary Markdown, raw, and code cells—including visible text and image outputs, but never the live Python namespace.
110
111
  - Images displayed by the model's IPython tool are included in that tool's result. PNG, JPEG, WebP, GIF, and SVG renditions are prepared as model-visible images; unsupported or oversized images are reported as omissions.
111
112
  - The first turn records the snapshot. Later turns append only new, changed, removed, or reordered cells. Existing Questions, tool calls, tool results, and answers in the conversation ledger are not duplicated.
@@ -123,7 +124,7 @@ That is the complete setup. **Question** is a native toolbar toggle:
123
124
  - Interrupted saves finish before a turn is cancelled, preventing a restart from turning a partial write into an orphan tool result. An interrupted tool call is closed with an explicit interrupted result.
124
125
  - Temporary model transport failures retry the same Question with a fresh connection; repeated WebSocket failures use HTTP. Invalid requests and authentication failures remain visible errors.
125
126
  - If a provider stream is cancelled or fails, Codebind discards that provider session before the next Question while retaining the notebook conversation and stable prompt-cache identity.
126
- - The instruction cell, sent Question cells, model-authored tool cells, and assistant Markdown cells are non-editable and non-deletable. Draft Questions remain editable until sent. Jupyter's standard interrupt button cancels an active Codebind question.
127
+ - Sent Question cells, model-authored tool cells, and assistant Markdown cells are non-editable and non-deletable. Draft Questions remain editable until sent. During an active question, `Ctrl+C` or Jupyter's interrupt button cancels the agent loop; a kernel interrupt is used only if cooperative cancellation does not finish.
127
128
 
128
129
  ### Markdown and other frontends
129
130
 
@@ -47,7 +47,7 @@ Inspect this project and tell me what to implement first.
47
47
  ```
48
48
 
49
49
  Terminal conversations remain live for the current IPython process. Previous terminal inputs and outputs, including Python cells you ran yourself, enter the model's context when you ask a question. Durable automatic resumption belongs to notebooks, where the notebook file provides an unambiguous conversation identity.
50
- Model-executed cells appear with IPython's native input counter, syntax highlighting, output prompts, streams, and tracebacks. Assistant Markdown appears before the following tool cell, and tool output appears as it is written. To keep terminal scrollback usable, Codebind shows at most 10 gray lines of each model-executed cell's output, then displays a notice such as `… 990 more output lines. Run %output 8 to view all.` The complete output remains available to the model and in IPython history; `%output 8` opens its full text in IPython's pager. User-entered Python cells keep IPython's normal display behavior. Assistant Markdown is rendered through IPython's terminal MIME renderer. A terminal is a stream rather than a notebook document, so these displays are not editable notebook cells.
50
+ Model-executed cells appear with IPython's native input counter, syntax highlighting, output prompts, streams, and tracebacks. Assistant Markdown appears before the following tool cell, and tool output appears as it is written. To keep terminal scrollback usable, Codebind previews at most three gray output lines, shortening each line after 60 characters with `...`. Further lines appear as `… N more output lines.` The complete output remains available to the model and in IPython history; `%output 8` opens the full text of cell 8 in IPython's pager. User-entered Python cells keep IPython's normal display behavior. Assistant Markdown is rendered through IPython's terminal MIME renderer. A terminal is a stream rather than a notebook document, so these displays are not editable notebook cells.
51
51
 
52
52
  ## JupyterLab
53
53
 
@@ -69,15 +69,16 @@ Load Codebind in a notebook:
69
69
  %load_ext codebind
70
70
  ```
71
71
 
72
- That is the complete setup. **Question** is a native toolbar toggle:
72
+ That is the complete setup. **Question** is a native toolbar toggle, also available with `Shift+Tab`:
73
73
 
74
74
  - Turning it on converts the selected cell into a Question and makes each newly created user cell a Question until the toggle is turned off.
75
- - Codebind-generated instruction, tool, and answer cells are never converted.
75
+ - Turning it off returns the selected unsent Question to a Python code cell.
76
+ - Codebind-generated tool and answer cells are never converted.
76
77
  - Write ordinary Markdown and press `Shift+Enter`.
77
78
 
78
79
  ### Instructions and notebook context
79
80
 
80
- - Loading the extension adds a locked Markdown cell containing Codebind's packaged instructions. Its exact text becomes the conversation's immutable system message and remains stable when the server or kernel restarts.
81
+ - Loading the extension stores Codebind's packaged instructions as the conversation's immutable system message in notebook metadata, without showing an instructions cell. Reopening the notebook or restarting its kernel preserves that message.
81
82
  - The whole notebook is model context. Before each Question, Codebind snapshots ordinary Markdown, raw, and code cells—including visible text and image outputs, but never the live Python namespace.
82
83
  - Images displayed by the model's IPython tool are included in that tool's result. PNG, JPEG, WebP, GIF, and SVG renditions are prepared as model-visible images; unsupported or oversized images are reported as omissions.
83
84
  - The first turn records the snapshot. Later turns append only new, changed, removed, or reordered cells. Existing Questions, tool calls, tool results, and answers in the conversation ledger are not duplicated.
@@ -95,7 +96,7 @@ That is the complete setup. **Question** is a native toolbar toggle:
95
96
  - Interrupted saves finish before a turn is cancelled, preventing a restart from turning a partial write into an orphan tool result. An interrupted tool call is closed with an explicit interrupted result.
96
97
  - Temporary model transport failures retry the same Question with a fresh connection; repeated WebSocket failures use HTTP. Invalid requests and authentication failures remain visible errors.
97
98
  - If a provider stream is cancelled or fails, Codebind discards that provider session before the next Question while retaining the notebook conversation and stable prompt-cache identity.
98
- - The instruction cell, sent Question cells, model-authored tool cells, and assistant Markdown cells are non-editable and non-deletable. Draft Questions remain editable until sent. Jupyter's standard interrupt button cancels an active Codebind question.
99
+ - Sent Question cells, model-authored tool cells, and assistant Markdown cells are non-editable and non-deletable. Draft Questions remain editable until sent. During an active question, `Ctrl+C` or Jupyter's interrupt button cancels the agent loop; a kernel interrupt is used only if cooperative cancellation does not finish.
99
100
 
100
101
  ### Markdown and other frontends
101
102
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codebind-jupyterlab",
3
- "version": "0.6.5",
3
+ "version": "0.6.11",
4
4
  "description": "Native JupyterLab cells and Question cells for Codebind.",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -31,7 +31,7 @@
31
31
  "extension": true,
32
32
  "outputDir": "../data/share/jupyter/labextensions/codebind-jupyterlab",
33
33
  "_build": {
34
- "load": "static/remoteEntry.c10098fb6e87897c.js",
34
+ "load": "static/remoteEntry.24258c9500a0850a.js",
35
35
  "extension": "./extension"
36
36
  }
37
37
  }
@@ -0,0 +1 @@
1
+ "use strict";(self.rspackChunkcodebind_jupyterlab=self.rspackChunkcodebind_jupyterlab||[]).push([[590],{509(e,t,n){n.r(t);var o=n(511),l=n(343),d=n(99),i=n(171),r=n(241);let s="codebind:insert-question",c="codebind:toggle-question-mode",a="codebind:run-question",u="jp-CodebindQuestionCell",m=new WeakMap,p=new WeakMap;function g(e){let t=e.getMetadata("codebind");return"object"!=typeof t||null===t||"question"!==t.kind?null:{kind:"question",status:"draft"===t.status?"draft":"sent"}}function f(e){let t=e.getMetadata("codebind");if("object"!=typeof t||null===t)return null;let n=t.kind;return"string"==typeof n?n:null}function y(e){let t={},n=[];for(let[o,l]of Object.entries(e))o.startsWith("text/")||["image/png","image/jpeg","image/webp","image/gif","image/svg+xml"].includes(o)||"application/json"===o||"application/vnd.jupyter.stdout"===o||"application/vnd.jupyter.stderr"===o?void 0!==l&&(t[o]=l):n.push(o);return n.length>0&&(t.omitted_mime_types=n),t}function w(e){return d.isStream(e)?{type:"stream",name:e.name,text:e.text}:d.isError(e)?{type:"error",name:e.ename,message:e.evalue,traceback:e.traceback}:d.isExecuteResult(e)?{type:"result",execution_count:e.execution_count,data:y(e.data)}:d.isDisplayData(e)?{type:"display",data:y(e.data)}:{type:e.output_type}}function _(e){return e.replace(/(^|[^\\])\\([()[\]])/g,"$1\\\\$2")}function b(e){let t=m.get(e);for(let n of e.content.widgets){let e=g(n.model);n.node.classList.toggle(u,null!==e);let o=n.node.querySelector(".jp-InputPrompt");o&&(e?(n.readOnly="sent"===e.status,o.dataset.codebindQuestion="true",o.style.color="#a855f7",o.textContent=t?.runningQuestions.has(n.model.id)?"[*]:":"[ ]:"):o.dataset.codebindQuestion&&(delete o.dataset.codebindQuestion,o.style.removeProperty("color"),o.textContent=""))}}function k(e){let t=e.content;for(let e of t.widgets)"instructions"===f(e.model)&&(e.node.hidden=!0);if(t.activeCell&&"instructions"===f(t.activeCell.model)){let e=t.widgets.findIndex(e=>"instructions"!==f(e.model));e>=0&&(t.activeCellIndex=e)}}function C(e){let t=e.sessionContext.session?.kernel;if(!t)return;let n=m.get(e)??{comm:null,kernel:null,registeredKernel:null,connectKernel:null,disconnectKernel:null,ready:null,resolveReady:null,rejectReady:null,connectOnIdle:!1,runningQuestions:new Map,questionTimers:new Map,sessionReady:!1,cancelAcknowledged:!1,questionMode:!1,questionButton:null,knownCellIds:new Set(e.content.widgets.map(e=>e.model.id)),pendingQuestionCellIds:new Set};if(m.set(e,n),n.registeredKernel===t)return;n.disconnectKernel?.(),n.rejectReady?.(Error("The notebook kernel changed.")),n.comm?.close(),n.registeredKernel=t,n.connectKernel=null,n.disconnectKernel=null,n.ready=null,n.resolveReady=null,n.rejectReady=null,n.connectOnIdle=!1;n.kernel&&n.kernel!==t&&p.get(n.kernel)?.delete(n),n.kernel=t;let d=p.get(t);if(!d){d=new Set,p.set(t,d);let e=t.interrupt.bind(t);t.interrupt=async()=>{let n=[...d??[]].filter(e=>e.runningQuestions.size>0);for(let e of n)e.cancelAcknowledged=!1;if(n.length>0)try{let e=r.KernelMessage.createMessage({session:t.clientId,username:t.username,channel:"control",msgType:"interrupt_request",content:{}});t.sendControlMessage(e,!0).done.catch(()=>void 0)}catch{}for(let e=0;n.length>0&&e<150;e+=1){if(n.every(e=>0===e.runningQuestions.size||e.cancelAcknowledged))return;await new Promise(e=>setTimeout(e,20))}return e()}}for(let e of(d.add(n),n.comm=null,n.runningQuestions.clear(),n.questionTimers.values()))window.clearTimeout(e);n.questionTimers.clear(),n.sessionReady=!1,n.cancelAcknowledged=!1;let i=null,s=new Map,c=new Map,a=()=>{if(!i)return;let e=i;i=null,e.parentModel&&null!==e.parentExecutionCount&&(e.parentModel.executionCount=e.parentExecutionCount)},u=()=>{if(n.comm||"idle"!==t.status||!e.content.model)return;let d=t.createComm("codebind");d.commsOverSubshells=r.CommsOverSubshells.Disabled,n.comm=d,n.sessionReady=!1,n.ready=new Promise((e,t)=>{n.resolveReady=e,n.rejectReady=t}),n.ready.catch(()=>void 0),d.onMsg=r=>{let u,m=r.content.data;if(!function(e){if("object"!=typeof e||null===e)return!1;if("markdown_cell"===e.type)return"string"==typeof e.source;if("markdown_cell_started"===e.type||"markdown_cell_updated"===e.type||"markdown_cell_finished"===e.type)return"string"==typeof e.cell_id&&"string"==typeof e.source;if("markdown_cell_cancelled"===e.type)return"string"==typeof e.cell_id;if("code_cell_started"===e.type)return"string"==typeof e.cell_id&&"string"==typeof e.source;if("code_cell_cancelled"===e.type)return"string"==typeof e.cell_id;if("code_cell_output"===e.type)return"string"==typeof e.cell_id&&"object"==typeof e.output&&null!==e.output;if("code_cell_clear"===e.type)return"string"==typeof e.cell_id&&"boolean"==typeof e.wait;if("question_finished"===e.type){let t=e.error;return"string"==typeof e.cell_id&&"boolean"==typeof e.cancelled&&(null===t||"object"==typeof t&&"string"==typeof t.type&&"string"==typeof t.message)}if("question_started"===e.type)return"string"==typeof e.cell_id;if("cancel_acknowledged"===e.type)return!0;if("session_ready"===e.type){let t=e.error;return null===t||"object"==typeof t&&"string"==typeof t.type&&"string"==typeof t.message}return"conversation_save"===e.type?"string"==typeof e.request_id&&"object"==typeof e.conversation&&null!==e.conversation:"code_cell_finished"===e.type&&"string"==typeof e.cell_id&&("number"==typeof e.execution_count||null===e.execution_count)&&Array.isArray(e.outputs)}(m))return;if("conversation_save"===m.type){let t=e.content.model;return t?(t.setMetadata("codebind",m.conversation),void e.context.save().then(()=>{d.send({type:"conversation_saved",request_id:m.request_id,error:null})},e=>{d.send({type:"conversation_saved",request_id:m.request_id,error:String(e)})})):void d.send({type:"conversation_saved",request_id:m.request_id,error:"Notebook model is unavailable."})}if("session_ready"===m.type){n.sessionReady=null===m.error,m.error?(n.rejectReady?.(Error(m.error.message)),(0,o.showErrorMessage)(`Codebind could not load: ${m.error.type}`,m.error.message)):n.resolveReady?.(),n.resolveReady=null,n.rejectReady=null;return}if("question_started"===m.type){let e=n.questionTimers.get(m.cell_id);void 0!==e&&(window.clearTimeout(e),n.questionTimers.delete(m.cell_id));return}if("cancel_acknowledged"===m.type){n.cancelAcknowledged=!0;return}if("question_finished"===m.type){let t=n.questionTimers.get(m.cell_id);void 0!==t&&(window.clearTimeout(t),n.questionTimers.delete(m.cell_id)),n.runningQuestions.delete(m.cell_id),0===n.runningQuestions.size&&(n.cancelAcknowledged=!1),b(e),a(),m.error&&!m.cancelled&&(0,o.showErrorMessage)(`Codebind question: ${m.error.type}`,m.error.message);return}if("markdown_cell_updated"===m.type||"markdown_cell_finished"===m.type){let t=c.get(m.cell_id);if(!t)return;t.sharedModel.setSource(_(m.source));let n=e.content.widgets.find(e=>e.model.id===t.id);n instanceof l.MarkdownCell&&(n.rendered=!0),"markdown_cell_finished"===m.type&&c.delete(m.cell_id);return}if("markdown_cell_cancelled"===m.type){let t=c.get(m.cell_id);if(c.delete(m.cell_id),!t)return;let n=e.content.widgets.findIndex(e=>e.model.id===t.id);n>=0&&e.content.model?.sharedModel.deleteCell(n);return}if("code_cell_output"===m.type)return void s.get(m.cell_id)?.outputs.add(m.output);if("code_cell_clear"===m.type)return void s.get(m.cell_id)?.outputs.clear(m.wait);if("code_cell_finished"===m.type){let e=s.get(m.cell_id);if(s.delete(m.cell_id),!e)return;e.outputs.fromJSON(m.outputs),e.executionCount=m.execution_count,e.executionState="idle",i&&null===i.parentExecutionCount&&null!==m.execution_count&&(i.parentExecutionCount=m.execution_count-1);return}if("code_cell_cancelled"===m.type){let e=s.get(m.cell_id);s.delete(m.cell_id),e&&(e.executionState="idle");return}if("markdown_cell_started"===m.type)u={type:"markdown_cell",source:m.source};else{if("markdown_cell"!==m.type&&"code_cell_started"!==m.type)return;u=m}(()=>{if(i)return;let n=e.content,o=n.widgets.findIndex(e=>"code"===e.model.type&&"running"===e.model.executionState);i={parentModel:o>=0?n.widgets[o].model:null,parentExecutionCount:null};let l=(e,n)=>{"idle"===n&&(t.statusChanged.disconnect(l),a())};return t.statusChanged.connect(l)})();let p=function(e,t){let n=e.content,o=n.model;if(!o)return null;let d=n.widgets.length;"code_cell_started"===t.type?o.sharedModel.insertCell(d,{cell_type:"code",source:t.source,metadata:{trusted:!0,collapsed:!0,editable:!1,deletable:!1,codebind:{kind:"tool"}},execution_count:null,outputs:[]}):o.sharedModel.insertCell(d,{cell_type:"markdown",source:_(t.source),metadata:{editable:!1,deletable:!1,codebind:{kind:"assistant"}}});let i=n.widgets[d]??null;return i&&(i.readOnly=!0),i instanceof l.MarkdownCell&&(i.rendered=!0),i?.model??null}(e,u);"code_cell_started"===m.type&&p?.type==="code"&&(p.executionState="running",s.set(m.cell_id,p)),"markdown_cell_started"===m.type&&p&&c.set(m.cell_id,p)},d.onClose=()=>{if(n.comm===d){let t=n.sessionReady;for(let e of s.values())e.executionState="idle";for(let e of(s.clear(),n.runningQuestions.clear(),n.cancelAcknowledged=!1,n.questionTimers.values()))window.clearTimeout(e);n.questionTimers.clear(),b(e),n.rejectReady?.(Error("Codebind is not loaded in this kernel. Run %load_ext codebind.")),n.comm=null,n.sessionReady=!1,n.ready=null,n.resolveReady=null,n.rejectReady=null,n.connectOnIdle=t}};let u=e.content.model?.getMetadata("codebind");d.open({conversation:"object"==typeof u&&null!==u?u:null})};n.connectKernel=u;let g=(e,t)=>{"idle"===t&&n.connectOnIdle&&(n.connectOnIdle=!1,u())},f=(e,t)=>{r.KernelMessage.isExecuteInputMsg(t)&&/(?:^|\n)\s*%(?:re)?load_ext\s+codebind(?:\s|$)/.test(t.content.code)&&(n.connectOnIdle=!0)};t.statusChanged.connect(g),t.iopubMessage.connect(f),n.disconnectKernel=()=>{t.statusChanged.disconnect(g),t.iopubMessage.disconnect(f)},e.context.ready.then(()=>{e.content.model?.getMetadata("codebind")&&(n.connectOnIdle=!0,u())})}function h(e){let t=e.content,n=t.model;if(!n)return;t.activeCell?"markdown"!==t.activeCell.model.type&&i.NotebookActions.changeCellType(t,"markdown"):(n.sharedModel.insertCell(0,{cell_type:"markdown",source:"",metadata:{}}),t.activeCellIndex=0);let o=t.activeCell;o&&null!==f(o.model)||(o?.model.setMetadata("codebind",{kind:"question",status:"draft"}),o instanceof l.MarkdownCell&&(o.rendered=!1),t.mode="edit",b(e),o?.editor?.focus())}function v(e){let t=m.get(e);if(!t)return;k(e);let n=e.content.widgets,o=new Set(n.map(e=>e.model.id)),l=n.filter(e=>!t.knownCellIds.has(e.model.id));for(let e of(t.knownCellIds=o,t.pendingQuestionCellIds))o.has(e)||t.pendingQuestionCellIds.delete(e);if(t.questionMode)for(let e of l)null===f(e.model)&&t.pendingQuestionCellIds.add(e.model.id);b(e),t.questionMode&&e.content.activeCell&&t.pendingQuestionCellIds.delete(e.content.activeCell.model.id)&&h(e)}function M(e){let t=m.get(e);t&&q(e,!t.questionMode)}function q(e,t){let n=m.get(e);if(n){if(n.questionMode=t,!n.questionMode){n.pendingQuestionCellIds.clear();let t=e.content.activeCell;t&&g(t.model)?.status==="draft"&&(t.model.deleteMetadata("codebind"),i.NotebookActions.changeCellType(e.content,"code"),e.content.mode="edit",e.content.activeCell?.editor?.focus())}n.questionButton&&(n.questionButton.pressed=n.questionMode),n.questionMode&&e.content.activeCell&&null===f(e.content.activeCell.model)&&h(e)}}async function x(e){let t=e.content,n=t.activeCell;if(!n||!g(n.model))return;await e.sessionContext.ready,C(e);let d=m.get(e),i=d?.registeredKernel;if(!d||!i)return void await (0,o.showErrorMessage)("Codebind is not connected","Start the notebook kernel before sending a Question cell.");try{if("dead"===i.status)throw Error("The notebook kernel stopped.");if("idle"!==i.status&&await new Promise((e,t)=>{let n=(o,l)=>{("idle"===l||"dead"===l)&&(i.statusChanged.disconnect(n),"idle"===l?e():t(Error("The notebook kernel stopped.")))};i.statusChanged.connect(n)}),d.connectKernel?.(),!d.ready)throw Error("Run %load_ext codebind in this kernel.");await d.ready}catch(e){await (0,o.showErrorMessage)("Codebind could not load",String(e));return}if(!d.sessionReady||!d.comm)return void await (0,o.showErrorMessage)("Codebind is not connected","Run %load_ext codebind in this kernel before sending a Question cell.");if(d.runningQuestions.size>0)return void await (0,o.showErrorMessage)("Codebind is busy","Wait for the current question to finish before sending another.");let r=n.model.sharedModel.getSource().trim();if(!r)return void await (0,o.showErrorMessage)("Empty Codebind question","Write a question before sending it.");d.runningQuestions.set(n.model.id,n.model),d.cancelAcknowledged=!1,n.model.sharedModel.setSource(_(r)),n.model.setMetadata("codebind",{kind:"question",status:"sent"}),n.model.setMetadata("editable",!1),n.model.setMetadata("deletable",!1),n.readOnly=!0,b(e),n instanceof l.MarkdownCell&&(n.rendered=!0),t.mode="command";let s=window.setTimeout(()=>{d.questionTimers.has(n.model.id)&&(d.questionTimers.delete(n.model.id),d.runningQuestions.delete(n.model.id),n.model.setMetadata("codebind",{kind:"question",status:"draft"}),n.model.setMetadata("editable",!0),n.model.setMetadata("deletable",!0),n.readOnly=!1,b(e),(0,o.showErrorMessage)("Codebind did not receive the Question","The kernel did not acknowledge it. Reload Codebind and send it again."))},1e4);d.questionTimers.set(n.model.id,s),d.comm.send({type:"question",cell_id:n.model.id,question:r,notebook:function(e){let t=[];for(let n of e.content.widgets){if(null!==f(n.model))continue;let e=n.model.type;if("code"!==e&&"markdown"!==e&&"raw"!==e)continue;let o={id:n.model.id,type:e,source:n.model.sharedModel.getSource(),execution_count:null,outputs:[],attachments:{}};if("code"===e){let e=n.model.toJSON();o.execution_count=e.execution_count,o.outputs=e.outputs.map(w)}else{let e=n.model.toJSON().attachments;if(e){let t={};for(let[n,o]of Object.entries(e))o&&(t[n]=y(o));o.attachments=t}}t.push(o)}return t}(e)})}function T(e,t){let n={comm:null,kernel:null,registeredKernel:null,connectKernel:null,disconnectKernel:null,ready:null,resolveReady:null,rejectReady:null,connectOnIdle:!1,runningQuestions:new Map,questionTimers:new Map,sessionReady:!1,cancelAcknowledged:!1,questionMode:!1,questionButton:null,knownCellIds:new Set(e.content.widgets.map(e=>e.model.id)),pendingQuestionCellIds:new Set};m.set(e,n);let l=!1,d=()=>{if(!l){if(!n.kernel){n.runningQuestions.size>0&&(n.cancelAcknowledged=!1,n.comm?.send({type:"cancel"}));return}l=!0,n.kernel.interrupt().catch(e=>{n.runningQuestions.size>0&&(0,o.showErrorMessage)("Codebind could not interrupt",String(e))}).finally(()=>{l=!1})}},i=e=>{0!==n.runningQuestions.size&&(e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),d())},r=n=>{"Tab"===n.key&&n.shiftKey&&!n.ctrlKey&&!n.altKey&&!n.metaKey&&n.target instanceof Node&&e.content.node.contains(n.target)&&(n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation(),M(e),t.commands.notifyCommandChanged(c))},s=o=>{0===n.runningQuestions.size||t.shell.currentWidget!==e||"c"!==o.key.toLowerCase()||!o.ctrlKey||o.altKey||o.metaKey||o.shiftKey||(o.preventDefault(),o.stopPropagation(),o.stopImmediatePropagation(),d())};e.node.addEventListener("keydown",r,!0),window.addEventListener("keydown",s,!0);let a=null,u=()=>{let t=e.toolbar.node.querySelector('[data-command="notebook:interrupt-kernel"]');t!==a&&(a?.removeEventListener("click",i,!0),a=t,a?.addEventListener("click",i,!0))},g=new MutationObserver(u);g.observe(e.toolbar.node,{childList:!0,subtree:!0});let f=new MutationObserver(()=>{window.setTimeout(()=>v(e),0)});f.observe(e.content.node,{childList:!0,subtree:!0}),u(),e.disposed.connect(()=>{for(let t of(g.disconnect(),f.disconnect(),a?.removeEventListener("click",i,!0),e.node.removeEventListener("keydown",r,!0),window.removeEventListener("keydown",s,!0),n.disconnectKernel?.(),n.rejectReady?.(Error("The notebook closed.")),n.comm?.close(),n.kernel&&p.get(n.kernel)?.delete(n),n.questionTimers.values()))window.clearTimeout(t);n.questionTimers.clear()});let y=new o.ToolbarButton({label:"Question",tooltip:"Toggle Question mode for the selected and newly created cells",onClick:()=>{q(e,y.pressed),t.commands.notifyCommandChanged(c)}});n.questionButton=y,e.toolbar.insertItem(10,"codebindQuestion",y),e.content.modelContentChanged.connect(()=>{v(e),window.setTimeout(()=>v(e),0)}),e.content.activeCellChanged.connect(()=>v(e)),e.context.ready.then(()=>{k(e),e.content.model?.cells.changed.connect(()=>{v(e),window.setTimeout(()=>v(e),0)}),v(e)}),e.sessionContext.ready.then(()=>C(e)),e.sessionContext.kernelChanged.connect(()=>C(e))}let E={id:"codebind-jupyterlab:plugin",description:"Insert Codebind executions as native notebook cells.",autoStart:!0,requires:[i.INotebookTracker],activate:(e,t)=>{e.commands.addCommand(s,{label:"Use Selected Cell as Codebind Question",execute:()=>{let e=t.currentWidget;e&&h(e)}}),e.commands.addCommand(c,{label:"Toggle Codebind Question Mode",isToggled:()=>{let e=t.currentWidget;return!!e&&(m.get(e)?.questionMode??!1)},execute:()=>{let n=t.currentWidget;n&&(M(n),e.commands.notifyCommandChanged(c))}}),e.commands.addCommand(a,{label:"Send Codebind Question",isEnabled:()=>{let e=t.currentWidget?.content.activeCell;return!!e&&null!==g(e.model)},execute:async()=>{let e=t.currentWidget;e&&await x(e)}}),e.commands.addKeyBinding({command:a,keys:["Shift Enter"],selector:`.jp-Notebook.jp-mod-editMode .${u}`}),e.commands.addKeyBinding({command:a,keys:["Shift Enter"],selector:`.jp-Notebook.jp-mod-commandMode .${u}`}),e.contextMenu.addItem({command:s,selector:".jp-Notebook .jp-Cell",rank:8}),t.forEach(t=>T(t,e)),t.widgetAdded.connect((t,n)=>T(n,e))}};n.d(t,{},{default:E})}}]);
@@ -0,0 +1 @@
1
+ var _JUPYTERLAB;(()=>{"use strict";var e,n,r,t,o,i,u,a,l,c,s,f,p,d,h,g,v,y,m,b,S,k,j,w,E,x,T,M,P,V,q,A,C,O,D,_,L,N={457(e,n,r){var t={"./index":()=>r.e(590).then(()=>()=>r(509)),"./extension":()=>r.e(590).then(()=>()=>r(509))},o=function(e,n){return r.R=n,n=r.o(t,e)?t[e]():Promise.resolve().then(()=>{throw Error('Module "'+e+'" does not exist in container.')}),r.R=void 0,n},i=function(e,n){if(r.S){var t="default",o=r.S[t];if(o&&o!==e)throw Error("Container initialization failed as it has already been initialized with a different share scope");return r.S[t]=e,r.I(t,n)}};r.d(n,{get:()=>o,init:()=>i})}},$={};function z(e){var n=$[e];if(void 0!==n)return n.exports;var r=$[e]={exports:{}};return N[e](r,r.exports,z),r.exports}z.m=N,z.c=$,z.n=e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return z.d(n,{a:n}),n},z.d=(e,n,r)=>{var t=(n,r)=>{for(var t in n)z.o(n,t)&&!z.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,[r]:n[t]})};t(n,"get"),t(r,"value")},z.f={},z.e=e=>Promise.all(Object.keys(z.f).reduce((n,r)=>(z.f[r](e,n),n),[])),z.u=e=>""+e+".98c719a309e23852.js?v=98c719a309e23852",z.g=(()=>{if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}})(),z.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),I={},z.l=function(e,n,r,t){if(I[e])return void I[e].push(n);if(void 0!==r)for(var o,i,u=document.getElementsByTagName("script"),a=0;a<u.length;a++){var l=u[a];if(l.getAttribute("src")==e||l.getAttribute("data-rspack")=="codebind-jupyterlab:"+r){o=l;break}}o||(i=!0,(o=document.createElement("script")).timeout=120,z.nc&&o.setAttribute("nonce",z.nc),o.setAttribute("data-rspack","codebind-jupyterlab:"+r),o.src=e),I[e]=[n];var c=function(n,r){o.onerror=o.onload=null,clearTimeout(s);var t=I[e];if(delete I[e],o.parentNode&&o.parentNode.removeChild(o),t&&t.forEach(function(e){return e(r)}),n)return n(r)},s=setTimeout(c.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=c.bind(null,o.onerror),o.onload=c.bind(null,o.onload),i&&document.head.appendChild(o)},z.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},z.S={},z.initializeSharingData={scopeToSharingDataMapping:{default:[{name:"codebind-jupyterlab",version:"0.6.11",factory:()=>z.e(590).then(()=>()=>z(509)),eager:0,treeShakingMode:null}]},uniqueName:"codebind-jupyterlab"},R={},U={},z.I=function(e,n){n||(n=[]);var r=U[e];if(r||(r=U[e]={}),!(n.indexOf(r)>=0)){if(n.push(r),R[e])return R[e];z.o(z.S,e)||(z.S[e]={});var t=z.S[e],o=function(e){"u">typeof console&&console.warn&&console.warn(e)},i=z.initializeSharingData.uniqueName,u=function(e,n,r,o){var u=t[e]=t[e]||{},a=u[n];(!a||!a.loaded&&(!o!=!a.eager?o:i>a.from))&&(u[n]={get:r,from:i,eager:!!o})},a=function(r){var t=function(e){o("Initialization of sharing external failed: "+e)};try{var i=z(r);if(!i)return;var u=function(r){return r&&r.init&&r.init(z.S[e],n)};if(i.then)return l.push(i.then(u,t));var a=u(i);if(a&&a.then)return l.push(a.catch(t))}catch(e){t(e)}},l=[],c=z.initializeSharingData.scopeToSharingDataMapping;return(c[e]&&c[e].forEach(function(e){"object"==typeof e?u(e.name,e.version,e.factory,e.eager):a(e)}),l.length)?R[e]=Promise.all(l).then(function(){return R[e]=1}):R[e]=1}},z.g.importScripts&&(B=z.g.location+"");var I,R,U,B,K=z.g.document;if(!B&&K&&(K.currentScript&&"SCRIPT"===K.currentScript.tagName.toUpperCase()&&(B=K.currentScript.src),!B)){var J=K.getElementsByTagName("script");if(J.length)for(var Y=J.length-1;Y>-1&&(!B||!/^http(s?):/.test(B));)B=J[Y--].src}if(!B)throw Error("Automatic publicPath is not supported in this browser");z.p=B=B.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),z.consumesLoadingData={chunkMapping:{590:["511","343","99","171","241"]},moduleIdToConsumeDataMapping:{171:{shareScope:"default",shareKey:"@jupyterlab/notebook",import:null,requiredVersion:"^4.6.3",strictVersion:!1,singleton:!0,eager:!1,fallback:void 0,treeShakingMode:null},241:{shareScope:"default",shareKey:"@jupyterlab/services",import:null,requiredVersion:"^7.6.3",strictVersion:!1,singleton:!0,eager:!1,fallback:void 0,treeShakingMode:null},343:{shareScope:"default",shareKey:"@jupyterlab/cells",import:null,requiredVersion:"^4.6.3",strictVersion:!1,singleton:!1,eager:!1,fallback:void 0,treeShakingMode:null},511:{shareScope:"default",shareKey:"@jupyterlab/apputils",import:null,requiredVersion:"^4.7.3",strictVersion:!1,singleton:!0,eager:!1,fallback:void 0,treeShakingMode:null},99:{shareScope:"default",shareKey:"@jupyterlab/nbformat",import:null,requiredVersion:"^4.6.3",strictVersion:!1,singleton:!1,eager:!1,fallback:void 0,treeShakingMode:null}},initialConsumes:[]},e=function(e){return e.split(".").map(function(e){return+e==e?+e:e})},n=function(n){var r=function(n){var r=/^([^-+]+)?(?:-([^+]+))?(?:\+(.+))?$/.exec(n),t=r[1]?[0].concat(e(r[1])):[0];r[2]&&(t.length++,t.push.apply(t,e(r[2])));let o=t[t.length-1];for(;t.length&&(void 0===o||/^[*xX]$/.test(o));)t.pop(),o=t[t.length-1];return t},t=function(e){return 1===e.length?[0]:2===e.length?[1].concat(e.slice(1)):3===e.length?[2].concat(e.slice(1)):[e.length].concat(e.slice(1))},o=function(e){return[-e[0]-1].concat(e.slice(1))},i=function(e){let n=/^(\^|~|<=|<|>=|>|=|v|!)/.exec(e),i=n?n[0]:"",u=r(i.length?e.slice(i.length).trim():e.trim());switch(i){case"^":if(u.length>1&&0===u[1]){if(u.length>2&&0===u[2])return[3].concat(u.slice(1));return[2].concat(u.slice(1))}return[1].concat(u.slice(1));case"~":return[2].concat(u.slice(1));case">=":return u;case"=":case"v":case"":return t(u);case"<":return o(u);case">":return[,t(u),0,u,2];case"<=":return[,t(u),o(u),1];case"!":return[,t(u),0];default:throw Error("Unexpected start value")}},u=function(e,n){if(1===e.length)return e[0];let r=[];for(let n of e.slice().reverse())0 in n?r.push(n):r.push.apply(r,n.slice(1));return[,].concat(r,e.slice(1).map(()=>n))};return u(n.split(/\s*\|\|\s*/).map(function(e){let n=e.split(/\s+-\s+/);if(1===n.length){e=e.trim();let n=[],r=/[-0-9A-Za-z]\s+/g;for(var a,l=0;a=r.exec(e);){let r=a.index+1;n.push(i(e.slice(l,r).trim())),l=r}return n.push(i(e.slice(l).trim())),u(n,2)}let c=r(n[0]),s=r(n[1]);return[,t(s),o(s),1,c,2]}),1)},r=function(n){var r=/^([^-+]+)?(?:-([^+]+))?(?:\+(.+))?$/.exec(n),t=r[1]?e(r[1]):[];return r[2]&&(t.length++,t.push.apply(t,e(r[2]))),r[3]&&(t.push([]),t.push.apply(t,e(r[3]))),t},t=function(e,n){e=r(e),n=r(n);for(var t=0;;){if(t>=e.length)return t<n.length&&"u"!=(typeof n[t])[0];var o=e[t],i=(typeof o)[0];if(t>=n.length)return"u"==i;var u=n[t],a=(typeof u)[0];if(i==a){if("o"!=i&&"u"!=i&&o!=u)return o<u;t++}else{if("o"==i&&"n"==a)return!0;return"s"==a||"u"==i}}},o=function(e){var n=e[0],r="";if(1===e.length)return"*";if(n+.5){r+=0==n?">=":-1==n?"<":1==n?"^":2==n?"~":n>0?"=":"!=";for(var t=1,i=1;i<e.length;i++){var u=e[i],a=(typeof u)[0];t--,r+="u"==a?"-":(t>0?".":"")+(t=2,u)}return r}for(var l=[],i=1;i<e.length;i++){var u=e[i];l.push(0===u?"not("+c()+")":1===u?"("+c()+" || "+c()+")":2===u?l.pop()+" "+l.pop():o(u))}return c();function c(){return l.pop().replace(/^\((.+)\)$/,"$1")}},i=function(e,n){if(0 in e){n=r(n);var t=e[0],o=t<0;o&&(t=-t-1);for(var u=0,a=1,l=!0;;a++,u++){var c,s,f=a<e.length?(typeof e[a])[0]:"";if(u>=n.length||"o"==(s=(typeof(c=n[u]))[0])){if(!l)return!0;if("u"==f)return a>t&&!o;return""==f!=o}if("u"==s){if(!l||"u"!=f)return!1}else if(l)if(f==s)if(a<=t){if(c!=e[a])return!1}else{if(o?c>e[a]:c<e[a])return!1;c!=e[a]&&(l=!1)}else if("s"!=f&&"n"!=f){if(o||a<=t)return!1;l=!1,a--}else{if(a<=t||s<f!=o)return!1;l=!1}else"s"!=f&&"n"!=f&&(l=!1,a--)}}for(var p=[],d=p.pop.bind(p),u=1;u<e.length;u++){var h=e[u];p.push(1==h?d()|d():2==h?d()&d():h?i(h,n):!d())}return!!d()},u=function(e,n){var r=z.S[e];if(!r||!z.o(r,n))throw Error("Shared module "+n+" doesn't exist in shared scope "+e);return r},a=function(e,n){var r=e[n],n=Object.keys(r).reduce(function(e,n){return!e||t(e,n)?n:e},0);return n&&r[n]},l=function(e,n){var r=e[n];return Object.keys(r).reduce(function(e,n){return!e||!r[e].loaded&&t(e,n)?n:e},0)},c=function(e,n,r,t){return"Unsatisfied version "+r+" from "+(r&&e[n][r].from)+" of shared singleton module "+n+" (required "+o(t)+")"},s=function(e,n,r,t){var o=l(e,r);return m(e[r][o])},f=function(e,n,r,t){var o=l(e,r);return i(t,o)||v(c(e,r,o,t)),m(e[r][o])},p=function(e,n,r,t){var o=l(e,r);if(!i(t,o))throw Error(c(e,r,o,t));return m(e[r][o])},d=function(e,n,r){var o=e[n],n=Object.keys(o).reduce(function(e,n){return i(r,n)&&(!e||t(e,n))?n:e},0);return n&&o[n]},h=function(e,n,r,t){var i=e[r];return"No satisfying version ("+o(t)+") of shared module "+r+" found in shared scope "+n+".\nAvailable versions: "+Object.keys(i).map(function(e){return e+" from "+i[e].from}).join(", ")},g=function(e,n,r,t){var o=d(e,r,t);if(o)return m(o);throw Error(h(e,n,r,t))},v=function(e){"u">typeof console&&console.warn&&console.warn(e)},y=function(e,n,r,t){v(h(e,n,r,t))},m=function(e){return e.loaded=1,e.get()},S=(b=function(e){return function(n,r,t,o){var i=z.I(n);return i&&i.then?i.then(e.bind(e,n,z.S[n],r,t,o)):e(n,z.S[n],r,t,o)}})(function(e,n,r){return u(e,r),m(a(n,r))}),k=b(function(e,n,r,t){return n&&z.o(n,r)?m(a(n,r)):t()}),j=b(function(e,n,r,t){return u(e,r),m(d(n,r,t)||y(n,e,r,t)||a(n,r))}),w=b(function(e,n,r){return u(e,r),s(n,e,r)}),E=b(function(e,n,r,t){return u(e,r),f(n,e,r,t)}),x=b(function(e,n,r,t){return u(e,r),g(n,e,r,t)}),T=b(function(e,n,r,t){return u(e,r),p(n,e,r,t)}),M=b(function(e,n,r,t,o){return n&&z.o(n,r)?m(d(n,r,t)||y(n,e,r,t)||a(n,r)):o()}),P=b(function(e,n,r,t){return n&&z.o(n,r)?s(n,e,r):t()}),V=b(function(e,n,r,t,o){return n&&z.o(n,r)?f(n,e,r,t):o()}),q=b(function(e,n,r,t,o){var i=n&&z.o(n,r)&&d(n,r,t);return i?m(i):o()}),A=b(function(e,n,r,t,o){return n&&z.o(n,r)?p(n,e,r,t):o()}),C=function(e){var r=!1,t=!1,o=!1,i=!1,u=[e.shareScope,e.shareKey];return(e.requiredVersion?(e.strictVersion&&(r=!0),e.singleton&&(t=!0),u.push(n(e.requiredVersion)),o=!0):e.singleton&&(t=!0),e.fallback&&(i=!0,u.push(e.fallback)),r&&t&&o&&i)?function(){return A.apply(null,u)}:r&&o&&i?function(){return q.apply(null,u)}:t&&o&&i?function(){return V.apply(null,u)}:r&&t&&o?function(){return T.apply(null,u)}:t&&i?function(){return P.apply(null,u)}:o&&i?function(){return M.apply(null,u)}:r&&o?function(){return x.apply(null,u)}:t&&o?function(){return E.apply(null,u)}:t?function(){return w.apply(null,u)}:o?function(){return j.apply(null,u)}:i?function(){return k.apply(null,u)}:function(){return S.apply(null,u)}},O={},z.f.consumes=function(e,n){var r=z.consumesLoadingData.moduleIdToConsumeDataMapping,t=z.consumesLoadingData.chunkMapping;z.o(t,e)&&t[e].forEach(function(e){if(z.o(O,e))return n.push(O[e]);var t=function(n){O[e]=0,z.m[e]=function(r){delete z.c[e],r.exports=n()}},o=function(n){delete O[e],z.m[e]=function(r){throw delete z.c[e],n}};try{var i=C(r[e])();i.then?n.push(O[e]=i.then(t).catch(o)):t(i)}catch(e){o(e)}})},D={871:0},z.f.j=function(e,n){var r=z.o(D,e)?D[e]:void 0;if(0!==r)if(r)n.push(r[2]);else{var t=new Promise((n,t)=>r=D[e]=[n,t]);n.push(r[2]=t);var o=z.p+z.u(e),i=Error();z.l(o,function(n){if(z.o(D,e)&&(0!==(r=D[e])&&(D[e]=void 0),r)){var t=n&&("load"===n.type?"missing":n.type),o=n&&n.target&&n.target.src;i.message="Loading chunk "+e+" failed.\n("+t+": "+o+")",i.name="ChunkLoadError",i.type=t,i.request=o,r[1](i)}},"chunk-"+e,e)}},_=(e,n)=>{var r,t,[o,i,u]=n,a=0;if(o.some(e=>0!==D[e])){for(r in i)z.o(i,r)&&(z.m[r]=i[r]);u&&u(z)}for(e&&e(n);a<o.length;a++)t=o[a],z.o(D,t)&&D[t]&&D[t][0](),D[t]=0},(L=self.rspackChunkcodebind_jupyterlab=self.rspackChunkcodebind_jupyterlab||[]).forEach(_.bind(null,0)),L.push=_.bind(null,L.push.bind(L));var F=z(457);(_JUPYTERLAB=void 0===_JUPYTERLAB?{}:_JUPYTERLAB)["codebind-jupyterlab"]=F})();
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codebind-jupyterlab",
3
- "version": "0.6.5",
3
+ "version": "0.6.11",
4
4
  "description": "Native JupyterLab cells and Question cells for Codebind.",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -21,6 +21,7 @@ const INSERT_QUESTION = 'codebind:insert-question';
21
21
  const TOGGLE_QUESTION_MODE = 'codebind:toggle-question-mode';
22
22
  const RUN_QUESTION = 'codebind:run-question';
23
23
  const QUESTION_CLASS = 'jp-CodebindQuestionCell';
24
+ const CANCEL_GRACE_MILLISECONDS = 3000;
24
25
 
25
26
  interface CodeCellStartedMessage {
26
27
  type: 'code_cell_started';
@@ -35,6 +36,11 @@ interface CodeCellFinishedMessage {
35
36
  outputs: nbformat.IOutput[];
36
37
  }
37
38
 
39
+ interface CodeCellCancelledMessage {
40
+ type: 'code_cell_cancelled';
41
+ cell_id: string;
42
+ }
43
+
38
44
  interface CodeCellOutputMessage {
39
45
  type: 'code_cell_output';
40
46
  cell_id: string;
@@ -66,11 +72,6 @@ interface MarkdownCellCancelledMessage {
66
72
  cell_id: string;
67
73
  }
68
74
 
69
- interface InstructionsCellMessage {
70
- type: 'instructions_cell';
71
- source: string;
72
- }
73
-
74
75
  interface QuestionFinishedMessage {
75
76
  type: 'question_finished';
76
77
  cell_id: string;
@@ -83,6 +84,10 @@ interface QuestionStartedMessage {
83
84
  cell_id: string;
84
85
  }
85
86
 
87
+ interface CancelAcknowledgedMessage {
88
+ type: 'cancel_acknowledged';
89
+ }
90
+
86
91
  interface SessionReadyMessage {
87
92
  type: 'session_ready';
88
93
  error: { type: string; message: string } | null;
@@ -97,13 +102,14 @@ interface ConversationSaveMessage {
97
102
  type CodebindMessage =
98
103
  | CodeCellStartedMessage
99
104
  | CodeCellFinishedMessage
105
+ | CodeCellCancelledMessage
100
106
  | CodeCellOutputMessage
101
107
  | CodeCellClearMessage
102
108
  | MarkdownCellMessage
103
109
  | MarkdownCellStreamMessage
104
110
  | MarkdownCellCancelledMessage
105
- | InstructionsCellMessage
106
111
  | QuestionStartedMessage
112
+ | CancelAcknowledgedMessage
107
113
  | QuestionFinishedMessage
108
114
  | SessionReadyMessage
109
115
  | ConversationSaveMessage;
@@ -127,6 +133,7 @@ interface PanelState {
127
133
  runningQuestions: Map<string, ICellModel>;
128
134
  questionTimers: Map<string, number>;
129
135
  sessionReady: boolean;
136
+ cancelAcknowledged: boolean;
130
137
  questionMode: boolean;
131
138
  questionButton: ToolbarButton | null;
132
139
  knownCellIds: Set<string>;
@@ -159,23 +166,12 @@ const kernelStates = new WeakMap<
159
166
  Set<PanelState>
160
167
  >();
161
168
 
162
- function cancelQuestions(state: PanelState): boolean {
163
- if (state.runningQuestions.size === 0) {
164
- return false;
165
- }
166
- state.comm?.send({ type: 'cancel' });
167
- return true;
168
- }
169
-
170
169
  function isCodebindMessage(value: unknown): value is CodebindMessage {
171
170
  if (typeof value !== 'object' || value === null) {
172
171
  return false;
173
172
  }
174
173
  const message = value as Record<string, unknown>;
175
- if (
176
- message.type === 'markdown_cell' ||
177
- message.type === 'instructions_cell'
178
- ) {
174
+ if (message.type === 'markdown_cell') {
179
175
  return typeof message.source === 'string';
180
176
  }
181
177
  if (
@@ -196,6 +192,9 @@ function isCodebindMessage(value: unknown): value is CodebindMessage {
196
192
  typeof message.source === 'string'
197
193
  );
198
194
  }
195
+ if (message.type === 'code_cell_cancelled') {
196
+ return typeof message.cell_id === 'string';
197
+ }
199
198
  if (message.type === 'code_cell_output') {
200
199
  return (
201
200
  typeof message.cell_id === 'string' &&
@@ -220,6 +219,9 @@ function isCodebindMessage(value: unknown): value is CodebindMessage {
220
219
  if (message.type === 'question_started') {
221
220
  return typeof message.cell_id === 'string';
222
221
  }
222
+ if (message.type === 'cancel_acknowledged') {
223
+ return true;
224
+ }
223
225
  if (message.type === 'session_ready') {
224
226
  const error = message.error;
225
227
  return (
@@ -263,13 +265,37 @@ function connectInterrupt(
263
265
  connected => connected.runningQuestions.size > 0
264
266
  );
265
267
  for (const connected of active) {
266
- cancelQuestions(connected);
268
+ connected.cancelAcknowledged = false;
267
269
  }
268
- for (let attempt = 0; active.length > 0 && attempt < 50; attempt += 1) {
269
- if (active.every(connected => connected.runningQuestions.size === 0)) {
270
+ if (active.length > 0) {
271
+ try {
272
+ const request = KernelMessage.createMessage<KernelMessage.IInterruptRequestMsg>({
273
+ session: kernel.clientId,
274
+ username: kernel.username,
275
+ channel: 'control',
276
+ msgType: 'interrupt_request',
277
+ content: {}
278
+ });
279
+ const future = kernel.sendControlMessage(request, true);
280
+ void future.done.catch(() => undefined);
281
+ } catch {
282
+ // The standard kernel interrupt below remains the fallback.
283
+ }
284
+ }
285
+ for (
286
+ let attempt = 0;
287
+ active.length > 0 && attempt < CANCEL_GRACE_MILLISECONDS / 20;
288
+ attempt += 1
289
+ ) {
290
+ if (
291
+ active.every(
292
+ connected =>
293
+ connected.runningQuestions.size === 0 || connected.cancelAcknowledged
294
+ )
295
+ ) {
270
296
  return;
271
297
  }
272
- await new Promise<void>(resolve => setTimeout(resolve, 10));
298
+ await new Promise<void>(resolve => setTimeout(resolve, 20));
273
299
  }
274
300
  return interrupt();
275
301
  };
@@ -412,11 +438,13 @@ function refreshQuestionCells(panel: NotebookPanel): void {
412
438
  if (question) {
413
439
  cell.readOnly = question.status === 'sent';
414
440
  prompt.dataset.codebindQuestion = 'true';
441
+ prompt.style.color = '#a855f7';
415
442
  prompt.textContent = state?.runningQuestions.has(cell.model.id)
416
443
  ? '[*]:'
417
444
  : '[ ]:';
418
445
  } else if (prompt.dataset.codebindQuestion) {
419
446
  delete prompt.dataset.codebindQuestion;
447
+ prompt.style.removeProperty('color');
420
448
  prompt.textContent = '';
421
449
  }
422
450
  }
@@ -469,49 +497,20 @@ function insertCell(
469
497
  return cell?.model ?? null;
470
498
  }
471
499
 
472
- function ensureInstructionsCell(panel: NotebookPanel, source: string): void {
500
+ function hideInstructionsCells(panel: NotebookPanel): void {
473
501
  const notebook = panel.content;
474
- const model = notebook.model;
475
- if (!model) {
476
- return;
477
- }
478
- let index = notebook.widgets.findIndex(
479
- widget => codebindKind(widget.model) === 'instructions'
480
- );
481
- if (index < 0) {
482
- const activeId = notebook.activeCell?.model.id ?? null;
483
- model.sharedModel.insertCell(0, {
484
- cell_type: 'markdown',
485
- source,
486
- metadata: {
487
- editable: false,
488
- deletable: false,
489
- codebind: { kind: 'instructions' }
490
- }
491
- });
492
- index = 0;
493
- if (activeId !== null) {
494
- const activeIndex = notebook.widgets.findIndex(
495
- widget => widget.model.id === activeId
496
- );
497
- if (activeIndex >= 0) {
498
- notebook.activeCellIndex = activeIndex;
499
- }
502
+ for (const cell of notebook.widgets) {
503
+ if (codebindKind(cell.model) === 'instructions') {
504
+ cell.node.hidden = true;
500
505
  }
501
506
  }
502
- const cell = notebook.widgets[index];
503
- if (!cell) {
504
- return;
505
- }
506
- if (cell.model.sharedModel.getSource() !== source) {
507
- cell.model.sharedModel.setSource(source);
508
- }
509
- cell.model.setMetadata('editable', false);
510
- cell.model.setMetadata('deletable', false);
511
- cell.model.setMetadata('codebind', { kind: 'instructions' });
512
- cell.readOnly = true;
513
- if (cell instanceof MarkdownCell) {
514
- cell.rendered = true;
507
+ if (notebook.activeCell && codebindKind(notebook.activeCell.model) === 'instructions') {
508
+ const next = notebook.widgets.findIndex(
509
+ cell => codebindKind(cell.model) !== 'instructions'
510
+ );
511
+ if (next >= 0) {
512
+ notebook.activeCellIndex = next;
513
+ }
515
514
  }
516
515
  }
517
516
 
@@ -534,6 +533,7 @@ function registerKernel(panel: NotebookPanel): void {
534
533
  runningQuestions: new Map<string, ICellModel>(),
535
534
  questionTimers: new Map<string, number>(),
536
535
  sessionReady: false,
536
+ cancelAcknowledged: false,
537
537
  questionMode: false,
538
538
  questionButton: null,
539
539
  knownCellIds: new Set(panel.content.widgets.map(widget => widget.model.id)),
@@ -561,6 +561,7 @@ function registerKernel(panel: NotebookPanel): void {
561
561
  }
562
562
  panelState.questionTimers.clear();
563
563
  panelState.sessionReady = false;
564
+ panelState.cancelAcknowledged = false;
564
565
 
565
566
  let turn: TurnState | null = null;
566
567
  const codeCells = new Map<string, ICodeCellModel>();
@@ -659,10 +660,6 @@ function registerKernel(panel: NotebookPanel): void {
659
660
  );
660
661
  return;
661
662
  }
662
- if (data.type === 'instructions_cell') {
663
- ensureInstructionsCell(panel, data.source);
664
- return;
665
- }
666
663
  if (data.type === 'session_ready') {
667
664
  panelState.sessionReady = data.error === null;
668
665
  if (data.error) {
@@ -686,6 +683,10 @@ function registerKernel(panel: NotebookPanel): void {
686
683
  }
687
684
  return;
688
685
  }
686
+ if (data.type === 'cancel_acknowledged') {
687
+ panelState.cancelAcknowledged = true;
688
+ return;
689
+ }
689
690
  if (data.type === 'question_finished') {
690
691
  const timer = panelState.questionTimers.get(data.cell_id);
691
692
  if (timer !== undefined) {
@@ -693,6 +694,9 @@ function registerKernel(panel: NotebookPanel): void {
693
694
  panelState.questionTimers.delete(data.cell_id);
694
695
  }
695
696
  panelState.runningQuestions.delete(data.cell_id);
697
+ if (panelState.runningQuestions.size === 0) {
698
+ panelState.cancelAcknowledged = false;
699
+ }
696
700
  refreshQuestionCells(panel);
697
701
  finishTurn();
698
702
  if (data.error && !data.cancelled) {
@@ -747,6 +751,7 @@ function registerKernel(panel: NotebookPanel): void {
747
751
  }
748
752
  if (data.type === 'code_cell_finished') {
749
753
  const model = codeCells.get(data.cell_id);
754
+ codeCells.delete(data.cell_id);
750
755
  if (!model) {
751
756
  return;
752
757
  }
@@ -762,6 +767,14 @@ function registerKernel(panel: NotebookPanel): void {
762
767
  }
763
768
  return;
764
769
  }
770
+ if (data.type === 'code_cell_cancelled') {
771
+ const model = codeCells.get(data.cell_id);
772
+ codeCells.delete(data.cell_id);
773
+ if (model) {
774
+ model.executionState = 'idle';
775
+ }
776
+ return;
777
+ }
765
778
 
766
779
  let inserted: InsertMessage;
767
780
  if (data.type === 'markdown_cell_started') {
@@ -788,6 +801,17 @@ function registerKernel(panel: NotebookPanel): void {
788
801
  comm.onClose = () => {
789
802
  if (panelState.comm === comm) {
790
803
  const wasReady = panelState.sessionReady;
804
+ for (const model of codeCells.values()) {
805
+ model.executionState = 'idle';
806
+ }
807
+ codeCells.clear();
808
+ panelState.runningQuestions.clear();
809
+ panelState.cancelAcknowledged = false;
810
+ for (const timer of panelState.questionTimers.values()) {
811
+ window.clearTimeout(timer);
812
+ }
813
+ panelState.questionTimers.clear();
814
+ refreshQuestionCells(panel);
791
815
  panelState.rejectReady?.(
792
816
  new Error(
793
817
  'Codebind is not loaded in this kernel. Run %load_ext codebind.'
@@ -878,6 +902,7 @@ function refreshQuestionMode(panel: NotebookPanel): void {
878
902
  if (!state) {
879
903
  return;
880
904
  }
905
+ hideInstructionsCells(panel);
881
906
  const widgets = panel.content.widgets;
882
907
  const currentIds = new Set(widgets.map(widget => widget.model.id));
883
908
  const added = widgets.filter(widget => !state.knownCellIds.has(widget.model.id));
@@ -919,6 +944,13 @@ function setQuestionMode(panel: NotebookPanel, enabled: boolean): void {
919
944
  state.questionMode = enabled;
920
945
  if (!state.questionMode) {
921
946
  state.pendingQuestionCellIds.clear();
947
+ const active = panel.content.activeCell;
948
+ if (active && questionMetadata(active.model)?.status === 'draft') {
949
+ active.model.deleteMetadata('codebind');
950
+ NotebookActions.changeCellType(panel.content, 'code');
951
+ panel.content.mode = 'edit';
952
+ panel.content.activeCell?.editor?.focus();
953
+ }
922
954
  }
923
955
  if (state.questionButton) {
924
956
  state.questionButton.pressed = state.questionMode;
@@ -1004,6 +1036,7 @@ async function runQuestion(panel: NotebookPanel): Promise<void> {
1004
1036
  return;
1005
1037
  }
1006
1038
  state.runningQuestions.set(cell.model.id, cell.model);
1039
+ state.cancelAcknowledged = false;
1007
1040
  cell.model.sharedModel.setSource(normalizeMathDelimiters(question));
1008
1041
  cell.model.setMetadata('codebind', { kind: 'question', status: 'sent' });
1009
1042
  cell.model.setMetadata('editable', false);
@@ -1053,25 +1086,82 @@ function connectPanel(panel: NotebookPanel, app: JupyterFrontEnd): void {
1053
1086
  runningQuestions: new Map<string, ICellModel>(),
1054
1087
  questionTimers: new Map<string, number>(),
1055
1088
  sessionReady: false,
1089
+ cancelAcknowledged: false,
1056
1090
  questionMode: false,
1057
1091
  questionButton: null,
1058
1092
  knownCellIds: new Set(panel.content.widgets.map(widget => widget.model.id)),
1059
1093
  pendingQuestionCellIds: new Set<string>()
1060
1094
  };
1061
1095
  panelStates.set(panel, state);
1096
+ let interruptPending = false;
1097
+ const requestInterrupt = (): void => {
1098
+ if (interruptPending) {
1099
+ return;
1100
+ }
1101
+ if (!state.kernel) {
1102
+ if (state.runningQuestions.size > 0) {
1103
+ state.cancelAcknowledged = false;
1104
+ state.comm?.send({ type: 'cancel' });
1105
+ }
1106
+ return;
1107
+ }
1108
+ interruptPending = true;
1109
+ void state.kernel
1110
+ .interrupt()
1111
+ .catch(error => {
1112
+ if (state.runningQuestions.size > 0) {
1113
+ void showErrorMessage('Codebind could not interrupt', String(error));
1114
+ }
1115
+ })
1116
+ .finally(() => {
1117
+ interruptPending = false;
1118
+ });
1119
+ };
1062
1120
  const onInterrupt = (event: Event): void => {
1063
- if (!cancelQuestions(state)) {
1121
+ if (state.runningQuestions.size === 0) {
1064
1122
  return;
1065
1123
  }
1066
1124
  event.preventDefault();
1067
1125
  event.stopPropagation();
1068
1126
  event.stopImmediatePropagation();
1069
- window.setTimeout(() => {
1070
- if (state.runningQuestions.size > 0) {
1071
- void state.kernel?.interrupt();
1072
- }
1073
- }, 500);
1127
+ requestInterrupt();
1128
+ };
1129
+ const onKeyDown = (event: KeyboardEvent): void => {
1130
+ if (
1131
+ event.key === 'Tab' &&
1132
+ event.shiftKey &&
1133
+ !event.ctrlKey &&
1134
+ !event.altKey &&
1135
+ !event.metaKey &&
1136
+ event.target instanceof Node &&
1137
+ panel.content.node.contains(event.target)
1138
+ ) {
1139
+ event.preventDefault();
1140
+ event.stopPropagation();
1141
+ event.stopImmediatePropagation();
1142
+ toggleQuestionMode(panel);
1143
+ app.commands.notifyCommandChanged(TOGGLE_QUESTION_MODE);
1144
+ }
1145
+ };
1146
+ const onGlobalKeyDown = (event: KeyboardEvent): void => {
1147
+ if (
1148
+ state.runningQuestions.size === 0 ||
1149
+ app.shell.currentWidget !== panel ||
1150
+ event.key.toLowerCase() !== 'c' ||
1151
+ !event.ctrlKey ||
1152
+ event.altKey ||
1153
+ event.metaKey ||
1154
+ event.shiftKey
1155
+ ) {
1156
+ return;
1157
+ }
1158
+ event.preventDefault();
1159
+ event.stopPropagation();
1160
+ event.stopImmediatePropagation();
1161
+ requestInterrupt();
1074
1162
  };
1163
+ panel.node.addEventListener('keydown', onKeyDown, true);
1164
+ window.addEventListener('keydown', onGlobalKeyDown, true);
1075
1165
  let interruptButton: HTMLElement | null = null;
1076
1166
  const connectInterruptButton = (): void => {
1077
1167
  const button = panel.toolbar.node.querySelector<HTMLElement>(
@@ -1095,6 +1185,8 @@ function connectPanel(panel: NotebookPanel, app: JupyterFrontEnd): void {
1095
1185
  toolbarObserver.disconnect();
1096
1186
  cellObserver.disconnect();
1097
1187
  interruptButton?.removeEventListener('click', onInterrupt, true);
1188
+ panel.node.removeEventListener('keydown', onKeyDown, true);
1189
+ window.removeEventListener('keydown', onGlobalKeyDown, true);
1098
1190
  state.disconnectKernel?.();
1099
1191
  state.rejectReady?.(new Error('The notebook closed.'));
1100
1192
  state.comm?.close();
@@ -1126,6 +1218,7 @@ function connectPanel(panel: NotebookPanel, app: JupyterFrontEnd): void {
1126
1218
  });
1127
1219
  panel.content.activeCellChanged.connect(() => refreshQuestionMode(panel));
1128
1220
  void panel.context.ready.then(() => {
1221
+ hideInstructionsCells(panel);
1129
1222
  panel.content.model?.cells.changed.connect(() => {
1130
1223
  refreshQuestionMode(panel);
1131
1224
  window.setTimeout(() => refreshQuestionMode(panel), 0);
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "codebind"
3
- version = "0.6.9"
3
+ version = "0.6.11"
4
4
  description = "A frontend-neutral model loop for persistent IPython sessions."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.13"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "codebind"
3
- version = "0.6.9"
3
+ version = "0.6.11"
4
4
  description = "A frontend-neutral model loop for persistent IPython sessions."
5
5
  readme = "README.md"
6
6
  authors = [
@@ -2,6 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import asyncio
5
6
  import sys
6
7
  from collections.abc import Callable, Iterator
7
8
  from contextlib import contextmanager
@@ -222,7 +223,7 @@ class IPythonExecutor:
222
223
  with preview_tool_output() as preview, record_tool_output(self.shell):
223
224
  result = self.shell.run_cell(cell, store_history=True)
224
225
  report = self._native_report(result)
225
- preview.show_notice(result.execution_count, report.error)
226
+ preview.show_notice(report.error)
226
227
  return report
227
228
 
228
229
  bridge = self.bridge
@@ -277,7 +278,7 @@ class IPythonExecutor:
277
278
  self.shell.events.trigger("post_execute")
278
279
  self.shell.events.trigger("post_run_cell", result)
279
280
  report = self._native_report(result)
280
- preview.show_notice(result.execution_count, report.error)
281
+ preview.show_notice(report.error)
281
282
  return report
282
283
 
283
284
  bridge = self.bridge
@@ -288,27 +289,42 @@ class IPythonExecutor:
288
289
  display_cell(cell)
289
290
  transformed = self.shell.transform_cell(cell)
290
291
  expression_outputs: list[dict[str, Any]] = []
291
- with _captured_execution(
292
- self.shell,
293
- expression_outputs,
294
- bridged=bridged,
295
- on_output=on_output,
296
- on_clear=on_clear,
297
- ) as captured:
298
- result = await self.shell.run_cell_async(
299
- cell,
300
- store_history=True,
301
- transformed_cell=transformed,
302
- )
303
- if bridged:
304
- assert bridge is not None and cell_id is not None
305
- bridge.finish_code_cell(
306
- cell_id,
307
- result.execution_count,
308
- self._notebook_outputs(result, captured, expression_outputs),
309
- )
310
- else:
311
- captured.show()
292
+ try:
293
+ with _captured_execution(
294
+ self.shell,
295
+ expression_outputs,
296
+ bridged=bridged,
297
+ on_output=on_output,
298
+ on_clear=on_clear,
299
+ ) as captured:
300
+ result = await self.shell.run_cell_async(
301
+ cell,
302
+ store_history=True,
303
+ transformed_cell=transformed,
304
+ )
305
+ # IPython records a cancellation raised inside the cell as an execution
306
+ # error. Keep it as a tool error unless this agent task was cancelled.
307
+ if asyncio.current_task() and asyncio.current_task().cancelling():
308
+ raise asyncio.CancelledError
309
+ if isinstance(result.error_before_exec or result.error_in_exec, KeyboardInterrupt):
310
+ raise KeyboardInterrupt
311
+ if bridged:
312
+ assert bridge is not None and cell_id is not None
313
+ bridge.finish_code_cell(
314
+ cell_id,
315
+ result.execution_count,
316
+ self._notebook_outputs(result, captured, expression_outputs),
317
+ )
318
+ else:
319
+ captured.show()
320
+ except BaseException:
321
+ if bridged:
322
+ assert bridge is not None and cell_id is not None
323
+ try:
324
+ bridge.cancel_code_cell(cell_id)
325
+ except Exception:
326
+ pass
327
+ raise
312
328
 
313
329
  return self._report(result, captured, expression_outputs)
314
330
 
@@ -3,6 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import asyncio
6
+ import inspect
6
7
  import sys
7
8
  from typing import Any
8
9
 
@@ -22,6 +23,9 @@ _STATE_ATTRIBUTE = "_codebind_extension_state"
22
23
 
23
24
 
24
25
  def _close_state(state: dict[str, Any]) -> None:
26
+ restore_control_interrupt = state.get("restore_control_interrupt")
27
+ if callable(restore_control_interrupt):
28
+ restore_control_interrupt()
25
29
  restore_output_magic = state.get("restore_output_magic")
26
30
  if callable(restore_output_magic):
27
31
  restore_output_magic()
@@ -95,6 +99,7 @@ def load_ipython_extension(ipython: InteractiveShell) -> None:
95
99
  "restore_terminal_question_mode": None,
96
100
  "terminal_history": None,
97
101
  "restore_output_magic": None,
102
+ "restore_control_interrupt": None,
98
103
  }
99
104
 
100
105
  if manager is None:
@@ -192,6 +197,29 @@ def load_ipython_extension(ipython: InteractiveShell) -> None:
192
197
 
193
198
  manager.register_target(TARGET_NAME, accept_comm)
194
199
  state["comm_target"] = accept_comm
200
+ control_handlers = getattr(ipython.kernel, "control_handlers", None)
201
+ if isinstance(control_handlers, dict):
202
+ previous_interrupt = control_handlers.get("interrupt_request")
203
+
204
+ async def interrupt_request(stream: Any, ident: Any, parent: Any) -> None:
205
+ bridge = state.get("bridge")
206
+ if isinstance(bridge, JupyterLabBridge):
207
+ bridge.request_cancel()
208
+ if callable(previous_interrupt):
209
+ result = previous_interrupt(stream, ident, parent)
210
+ if inspect.isawaitable(result):
211
+ await result
212
+
213
+ control_handlers["interrupt_request"] = interrupt_request
214
+
215
+ def restore_control_interrupt() -> None:
216
+ if control_handlers.get("interrupt_request") is interrupt_request:
217
+ if previous_interrupt is None:
218
+ control_handlers.pop("interrupt_request", None)
219
+ else:
220
+ control_handlers["interrupt_request"] = previous_interrupt
221
+
222
+ state["restore_control_interrupt"] = restore_control_interrupt
195
223
 
196
224
  def question_magic(line: str, cell: str | None = None) -> None:
197
225
  session = state.get("session")
@@ -17,6 +17,7 @@ class JupyterLabBridge:
17
17
 
18
18
  def __init__(self, comm: Any, conversation: dict[str, Any] | None) -> None:
19
19
  self._comm = comm
20
+ self._loop = asyncio.get_running_loop()
20
21
  self._question_handler: _QuestionHandler | None = None
21
22
  self._tasks: set[asyncio.Task[None]] = set()
22
23
  self._conversation = conversation
@@ -35,7 +36,8 @@ class JupyterLabBridge:
35
36
 
36
37
  def _stop(self) -> None:
37
38
  for task in self._tasks:
38
- task.cancel()
39
+ if not task.done() and not task.cancelling():
40
+ task.cancel()
39
41
  self._tasks.clear()
40
42
  for future in self._save_waiters.values():
41
43
  future.cancel()
@@ -46,6 +48,28 @@ class JupyterLabBridge:
46
48
  """Handle questions submitted by Codebind cells."""
47
49
  self._question_handler = handler
48
50
 
51
+ def request_cancel(self) -> None:
52
+ """Cancel active questions safely from shell or control-channel callbacks."""
53
+ if not self.ready:
54
+ return
55
+
56
+ def cancel_on_loop() -> None:
57
+ if not self.ready:
58
+ return
59
+ for task in tuple(self._tasks):
60
+ if not task.done() and not task.cancelling():
61
+ task.cancel()
62
+ self._comm.send({"type": "cancel_acknowledged"})
63
+
64
+ try:
65
+ current = asyncio.get_running_loop()
66
+ except RuntimeError:
67
+ current = None
68
+ if current is self._loop:
69
+ cancel_on_loop()
70
+ else:
71
+ self._loop.call_soon_threadsafe(cancel_on_loop)
72
+
49
73
  async def load_conversation(self) -> dict[str, Any] | None:
50
74
  return self._conversation
51
75
 
@@ -100,6 +124,13 @@ class JupyterLabBridge:
100
124
  )
101
125
  return True
102
126
 
127
+ def cancel_code_cell(self, cell_id: str) -> bool:
128
+ """Return an interrupted code cell to JupyterLab's idle state."""
129
+ if not self.ready:
130
+ return False
131
+ self._comm.send({"type": "code_cell_cancelled", "cell_id": cell_id})
132
+ return True
133
+
103
134
  def append_code_output(self, cell_id: str, output: dict[str, Any]) -> bool:
104
135
  """Append one live output to a running code cell."""
105
136
  if not self.ready:
@@ -180,13 +211,6 @@ class JupyterLabBridge:
180
211
  self._comm.send({"type": "markdown_cell_cancelled", "cell_id": cell_id})
181
212
  return True
182
213
 
183
- def ensure_instructions_cell(self, source: str) -> bool:
184
- """Show the conversation's immutable system instructions in the notebook."""
185
- if not self.ready:
186
- return False
187
- self._comm.send({"type": "instructions_cell", "source": source})
188
- return True
189
-
190
214
  def report_session_ready(self, error: BaseException | None = None) -> None:
191
215
  """Tell JupyterLab whether persisted conversation state is ready."""
192
216
  self._comm.send(
@@ -201,6 +225,8 @@ class JupyterLabBridge:
201
225
  )
202
226
 
203
227
  def _on_message(self, message: dict[str, Any]) -> None:
228
+ if not self.ready:
229
+ return
204
230
  data = message.get("content", {}).get("data", {})
205
231
  if not isinstance(data, dict):
206
232
  return
@@ -216,8 +242,7 @@ class JupyterLabBridge:
216
242
  future.set_result(None)
217
243
  return
218
244
  if data.get("type") == "cancel":
219
- for task in tuple(self._tasks):
220
- task.cancel()
245
+ self.request_cancel()
221
246
  return
222
247
  if data.get("type") != "question":
223
248
  return
@@ -245,15 +270,16 @@ class JupyterLabBridge:
245
270
  if self._question_handler is None:
246
271
  raise RuntimeError("Codebind is not ready to receive questions.")
247
272
  await self._question_handler(question, notebook)
248
- except asyncio.CancelledError:
273
+ except (asyncio.CancelledError, KeyboardInterrupt):
249
274
  cancelled = True
250
275
  except Exception as exception:
251
276
  error = {"type": type(exception).__name__, "message": str(exception)}
252
- self._comm.send(
253
- {
254
- "type": "question_finished",
255
- "cell_id": cell_id,
256
- "error": error,
257
- "cancelled": cancelled,
258
- }
259
- )
277
+ if self.ready:
278
+ self._comm.send(
279
+ {
280
+ "type": "question_finished",
281
+ "cell_id": cell_id,
282
+ "error": error,
283
+ "cancelled": cancelled,
284
+ }
285
+ )
@@ -130,12 +130,8 @@ class Session:
130
130
  conversation.append_message(message, turn_id)
131
131
  for turn_id in unfinished:
132
132
  conversation.append("turn_finished", turn_id=turn_id, status="interrupted")
133
- sent_instructions = False
134
133
  if not conversation.events:
135
134
  conversation.append_message(SystemMessage(self.instructions), "system")
136
- if self.bridge is not None:
137
- self.bridge.ensure_instructions_cell(self.instructions)
138
- sent_instructions = True
139
135
  if unfinished or value is None:
140
136
  await self._await_durable(self.store.save(conversation.as_dict()))
141
137
  self.conversation = conversation
@@ -144,13 +140,6 @@ class Session:
144
140
  (message for message in reversed(self._messages) if isinstance(message, AIMessage)),
145
141
  None,
146
142
  )
147
- if self.bridge is not None and not sent_instructions:
148
- system = next(
149
- (message for message in self._messages if isinstance(message, SystemMessage)),
150
- None,
151
- )
152
- if system is not None and isinstance(system.content, str):
153
- self.bridge.ensure_instructions_cell(system.content)
154
143
 
155
144
  async def aload(self) -> None:
156
145
  """Load persisted state and prepare the frontend without starting a turn."""
@@ -553,7 +542,7 @@ class Session:
553
542
  self._tool_message(report, identifier),
554
543
  turn_id,
555
544
  )
556
- except asyncio.CancelledError:
545
+ except (asyncio.CancelledError, KeyboardInterrupt):
557
546
  self._cancel_assistant_stream(assistant_cell_id)
558
547
  await self._seal_interrupted_calls(turn_id)
559
548
  await self._append_event("turn_finished", turn_id=turn_id, status="cancelled")
@@ -3,7 +3,6 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import ast
6
- import shutil
7
6
  import sys
8
7
  from collections.abc import Callable, Iterator
9
8
  from contextlib import contextmanager
@@ -23,7 +22,8 @@ from rich.markdown import Markdown
23
22
 
24
23
  _MISSING = object()
25
24
  _IMAGE_FORMATS = ("image/png", "image/jpeg", "image/svg+xml")
26
- _MAXIMUM_VISIBLE_OUTPUT_LINES = 10
25
+ _MAXIMUM_VISIBLE_OUTPUT_LINES = 3
26
+ _MAXIMUM_VISIBLE_OUTPUT_CHARACTERS_PER_LINE = 80
27
27
 
28
28
 
29
29
  def _plain_ansi(value: str) -> str:
@@ -192,66 +192,80 @@ class TerminalCellHistory:
192
192
  class _OutputPreview:
193
193
  """Limit only terminal painting; IPython still records every written byte."""
194
194
 
195
- def __init__(self, maximum_lines: int, maximum_characters: int) -> None:
195
+ def __init__(self, maximum_lines: int, maximum_characters_per_line: int) -> None:
196
196
  self.maximum_lines = maximum_lines
197
- self.maximum_characters = maximum_characters
197
+ self.maximum_characters_per_line = maximum_characters_per_line
198
198
  self.visible_lines = 0
199
+ self.characters_on_line = 0
200
+ self.line_truncated = False
199
201
  self.visible_characters = 0
200
202
  self.hidden_line_breaks = 0
201
203
  self.hidden_has_tail = False
202
204
  self.hidden_characters = 0
203
- self.truncated = False
204
205
  self.visible_ends_line = True
205
206
 
206
207
  def _hide(self, data: str) -> None:
207
- self.truncated = True
208
208
  self.hidden_characters += len(data)
209
209
  self.hidden_line_breaks += data.count("\n") + data.count("\r") - data.count("\r\n")
210
210
  self.hidden_has_tail = not data.endswith(("\n", "\r"))
211
211
 
212
+ def _paint(self, stream, text: str) -> None:
213
+ if not text:
214
+ return
215
+ if stream.isatty():
216
+ stream.write("\x1b[90m")
217
+ stream.write(text)
218
+ if stream.isatty():
219
+ stream.write("\x1b[0m")
220
+ self.visible_characters += len(text)
221
+
212
222
  def write(self, stream, data: str) -> int:
213
223
  for piece in data.splitlines(keepends=True):
214
- remaining = self.maximum_characters - self.visible_characters
215
- if self.truncated or self.visible_lines >= self.maximum_lines or remaining <= 0:
224
+ if self.visible_lines >= self.maximum_lines:
216
225
  self._hide(piece)
217
226
  continue
218
- visible = piece[:remaining]
219
- if len(visible) < len(piece) and "\x1b" in visible:
220
- # Never leave a partially printed ANSI escape sequence on screen.
221
- visible = ""
227
+
228
+ if piece.endswith("\r\n"):
229
+ body, ending = piece[:-2], "\r\n"
230
+ elif piece.endswith(("\n", "\r")):
231
+ body, ending = piece[:-1], piece[-1]
232
+ else:
233
+ body, ending = piece, ""
234
+
235
+ visible = ""
236
+ if not self.line_truncated:
237
+ remaining = self.maximum_characters_per_line - self.characters_on_line
238
+ visible = body[:remaining]
239
+ self.characters_on_line += len(visible)
240
+ if len(body) > remaining:
241
+ visible += "…"
242
+ self.line_truncated = True
243
+ if ending:
244
+ visible += ending
245
+ self.visible_lines += 1
246
+ self.characters_on_line = 0
247
+ self.line_truncated = False
222
248
  if visible:
223
- if stream.isatty():
224
- stream.write("\x1b[90m")
225
- stream.write(visible)
226
- if stream.isatty():
227
- stream.write("\x1b[0m")
228
- self.visible_characters += len(visible)
229
- self.visible_ends_line = visible.endswith(("\n", "\r"))
230
- if self.visible_ends_line:
231
- self.visible_lines += 1
232
- if len(visible) < len(piece):
233
- self._hide(piece[len(visible) :])
249
+ self._paint(stream, visible)
250
+ self.visible_ends_line = bool(ending)
234
251
  return len(data)
235
252
 
236
- def show_notice(self, number: int, error: dict[str, str] | None = None) -> None:
253
+ def show_notice(self, error: dict[str, str] | None = None) -> None:
237
254
  if self.visible_characters and not self.visible_ends_line:
238
255
  sys.stdout.write("\n")
239
256
  self.visible_ends_line = True
240
257
  if not self.hidden_characters:
241
258
  return
242
- if sys.stdout.isatty():
243
- sys.stdout.write("\x1b[0m")
259
+ terminal = sys.stdout.isatty()
260
+ if terminal:
261
+ sys.stdout.write("\x1b[90m")
244
262
  hidden_lines = self.hidden_line_breaks + int(self.hidden_has_tail)
245
263
  label = "line" if hidden_lines == 1 else "lines"
246
- sys.stdout.write(
247
- f"… {hidden_lines:,} more output {label}. Run %output {number} to view all.\n"
248
- )
264
+ sys.stdout.write(f"… {hidden_lines:,} more output {label}\n")
249
265
  if error is not None:
250
- if sys.stdout.isatty():
251
- sys.stdout.write("\x1b[90m")
252
266
  sys.stdout.write(f"{error['type']}: {error['message']}\n")
253
- if sys.stdout.isatty():
254
- sys.stdout.write("\x1b[0m")
267
+ if terminal:
268
+ sys.stdout.write("\x1b[0m")
255
269
 
256
270
 
257
271
  class _PreviewStream:
@@ -276,10 +290,10 @@ class _PreviewStream:
276
290
  @contextmanager
277
291
  def preview_tool_output(
278
292
  maximum_lines: int = _MAXIMUM_VISIBLE_OUTPUT_LINES,
293
+ maximum_characters_per_line: int = _MAXIMUM_VISIBLE_OUTPUT_CHARACTERS_PER_LINE,
279
294
  ) -> Iterator[_OutputPreview]:
280
295
  """Show a compact preview while keeping the tool cell's complete native output."""
281
- columns = shutil.get_terminal_size(fallback=(80, 24)).columns
282
- preview = _OutputPreview(maximum_lines, maximum_lines * max(20, columns))
296
+ preview = _OutputPreview(maximum_lines, maximum_characters_per_line)
283
297
  stdout, stderr = sys.stdout, sys.stderr
284
298
  preview_stdout = _PreviewStream(stdout, preview)
285
299
  preview_stderr = _PreviewStream(stderr, preview)
@@ -395,7 +409,6 @@ def show_input(shell: TerminalInteractiveShell, cell: str) -> None:
395
409
  style=style,
396
410
  color_depth=shell.color_depth,
397
411
  )
398
- sys.stdout.write("\n")
399
412
 
400
413
 
401
414
  def install_markdown_renderer(shell: TerminalInteractiveShell) -> Callable[[], None]:
@@ -408,7 +421,7 @@ def install_markdown_renderer(shell: TerminalInteractiveShell) -> Callable[[], N
408
421
 
409
422
  def render(text: str, _metadata: object) -> None:
410
423
  sys.stdout.write("\n")
411
- Console(file=sys.stdout, soft_wrap=True, no_color=shell.colors.lower() == "nocolor").print(
424
+ Console(file=sys.stdout, no_color=shell.colors.lower() == "nocolor").print(
412
425
  Markdown(text)
413
426
  )
414
427
 
@@ -1 +0,0 @@
1
- "use strict";(self.rspackChunkcodebind_jupyterlab=self.rspackChunkcodebind_jupyterlab||[]).push([[590],{509(e,t,n){n.r(t);var o=n(511),l=n(343),d=n(99),i=n(171),r=n(241);let s="codebind:insert-question",a="codebind:toggle-question-mode",c="codebind:run-question",u="jp-CodebindQuestionCell",m=new WeakMap,p=new WeakMap;function f(e){return 0!==e.runningQuestions.size&&(e.comm?.send({type:"cancel"}),!0)}function g(e){let t=e.getMetadata("codebind");return"object"!=typeof t||null===t||"question"!==t.kind?null:{kind:"question",status:"draft"===t.status?"draft":"sent"}}function y(e){let t=e.getMetadata("codebind");if("object"!=typeof t||null===t)return null;let n=t.kind;return"string"==typeof n?n:null}function b(e){let t={},n=[];for(let[o,l]of Object.entries(e))o.startsWith("text/")||["image/png","image/jpeg","image/webp","image/gif","image/svg+xml"].includes(o)||"application/json"===o||"application/vnd.jupyter.stdout"===o||"application/vnd.jupyter.stderr"===o?void 0!==l&&(t[o]=l):n.push(o);return n.length>0&&(t.omitted_mime_types=n),t}function _(e){return d.isStream(e)?{type:"stream",name:e.name,text:e.text}:d.isError(e)?{type:"error",name:e.ename,message:e.evalue,traceback:e.traceback}:d.isExecuteResult(e)?{type:"result",execution_count:e.execution_count,data:b(e.data)}:d.isDisplayData(e)?{type:"display",data:b(e.data)}:{type:e.output_type}}function w(e){return e.replace(/(^|[^\\])\\([()[\]])/g,"$1\\\\$2")}function k(e){let t=m.get(e);for(let n of e.content.widgets){let e=g(n.model);n.node.classList.toggle(u,null!==e);let o=n.node.querySelector(".jp-InputPrompt");o&&(e?(n.readOnly="sent"===e.status,o.dataset.codebindQuestion="true",o.textContent=t?.runningQuestions.has(n.model.id)?"[*]:":"[ ]:"):o.dataset.codebindQuestion&&(delete o.dataset.codebindQuestion,o.textContent=""))}}function C(e){let t=e.sessionContext.session?.kernel;if(!t)return;let n=m.get(e)??{comm:null,kernel:null,registeredKernel:null,connectKernel:null,disconnectKernel:null,ready:null,resolveReady:null,rejectReady:null,connectOnIdle:!1,runningQuestions:new Map,questionTimers:new Map,sessionReady:!1,questionMode:!1,questionButton:null,knownCellIds:new Set(e.content.widgets.map(e=>e.model.id)),pendingQuestionCellIds:new Set};if(m.set(e,n),n.registeredKernel===t)return;n.disconnectKernel?.(),n.rejectReady?.(Error("The notebook kernel changed.")),n.comm?.close(),n.registeredKernel=t,n.connectKernel=null,n.disconnectKernel=null,n.ready=null,n.resolveReady=null,n.rejectReady=null,n.connectOnIdle=!1;n.kernel&&n.kernel!==t&&p.get(n.kernel)?.delete(n),n.kernel=t;let d=p.get(t);if(!d){d=new Set,p.set(t,d);let e=t.interrupt.bind(t);t.interrupt=async()=>{let t=[...d??[]].filter(e=>e.runningQuestions.size>0);for(let e of t)f(e);for(let e=0;t.length>0&&e<50;e+=1){if(t.every(e=>0===e.runningQuestions.size))return;await new Promise(e=>setTimeout(e,10))}return e()}}for(let e of(d.add(n),n.comm=null,n.runningQuestions.clear(),n.questionTimers.values()))window.clearTimeout(e);n.questionTimers.clear(),n.sessionReady=!1;let i=null,s=new Map,a=new Map,c=()=>{if(!i)return;let e=i;i=null,e.parentModel&&null!==e.parentExecutionCount&&(e.parentModel.executionCount=e.parentExecutionCount)},u=()=>{if(n.comm||"idle"!==t.status||!e.content.model)return;let d=t.createComm("codebind");d.commsOverSubshells=r.CommsOverSubshells.Disabled,n.comm=d,n.sessionReady=!1,n.ready=new Promise((e,t)=>{n.resolveReady=e,n.rejectReady=t}),n.ready.catch(()=>void 0),d.onMsg=r=>{let u,m=r.content.data;if(!function(e){if("object"!=typeof e||null===e)return!1;if("markdown_cell"===e.type||"instructions_cell"===e.type)return"string"==typeof e.source;if("markdown_cell_started"===e.type||"markdown_cell_updated"===e.type||"markdown_cell_finished"===e.type)return"string"==typeof e.cell_id&&"string"==typeof e.source;if("markdown_cell_cancelled"===e.type)return"string"==typeof e.cell_id;if("code_cell_started"===e.type)return"string"==typeof e.cell_id&&"string"==typeof e.source;if("code_cell_output"===e.type)return"string"==typeof e.cell_id&&"object"==typeof e.output&&null!==e.output;if("code_cell_clear"===e.type)return"string"==typeof e.cell_id&&"boolean"==typeof e.wait;if("question_finished"===e.type){let t=e.error;return"string"==typeof e.cell_id&&"boolean"==typeof e.cancelled&&(null===t||"object"==typeof t&&"string"==typeof t.type&&"string"==typeof t.message)}if("question_started"===e.type)return"string"==typeof e.cell_id;if("session_ready"===e.type){let t=e.error;return null===t||"object"==typeof t&&"string"==typeof t.type&&"string"==typeof t.message}return"conversation_save"===e.type?"string"==typeof e.request_id&&"object"==typeof e.conversation&&null!==e.conversation:"code_cell_finished"===e.type&&"string"==typeof e.cell_id&&("number"==typeof e.execution_count||null===e.execution_count)&&Array.isArray(e.outputs)}(m))return;if("conversation_save"===m.type){let t=e.content.model;return t?(t.setMetadata("codebind",m.conversation),void e.context.save().then(()=>{d.send({type:"conversation_saved",request_id:m.request_id,error:null})},e=>{d.send({type:"conversation_saved",request_id:m.request_id,error:String(e)})})):void d.send({type:"conversation_saved",request_id:m.request_id,error:"Notebook model is unavailable."})}if("instructions_cell"===m.type)return void function(e,t){let n=e.content,o=n.model;if(!o)return;let d=n.widgets.findIndex(e=>"instructions"===y(e.model));if(d<0){let e=n.activeCell?.model.id??null;if(o.sharedModel.insertCell(0,{cell_type:"markdown",source:t,metadata:{editable:!1,deletable:!1,codebind:{kind:"instructions"}}}),d=0,null!==e){let t=n.widgets.findIndex(t=>t.model.id===e);t>=0&&(n.activeCellIndex=t)}}let i=n.widgets[d];i&&(i.model.sharedModel.getSource()!==t&&i.model.sharedModel.setSource(t),i.model.setMetadata("editable",!1),i.model.setMetadata("deletable",!1),i.model.setMetadata("codebind",{kind:"instructions"}),i.readOnly=!0,i instanceof l.MarkdownCell&&(i.rendered=!0))}(e,m.source);if("session_ready"===m.type){n.sessionReady=null===m.error,m.error?(n.rejectReady?.(Error(m.error.message)),(0,o.showErrorMessage)(`Codebind could not load: ${m.error.type}`,m.error.message)):n.resolveReady?.(),n.resolveReady=null,n.rejectReady=null;return}if("question_started"===m.type){let e=n.questionTimers.get(m.cell_id);void 0!==e&&(window.clearTimeout(e),n.questionTimers.delete(m.cell_id));return}if("question_finished"===m.type){let t=n.questionTimers.get(m.cell_id);void 0!==t&&(window.clearTimeout(t),n.questionTimers.delete(m.cell_id)),n.runningQuestions.delete(m.cell_id),k(e),c(),m.error&&!m.cancelled&&(0,o.showErrorMessage)(`Codebind question: ${m.error.type}`,m.error.message);return}if("markdown_cell_updated"===m.type||"markdown_cell_finished"===m.type){let t=a.get(m.cell_id);if(!t)return;t.sharedModel.setSource(w(m.source));let n=e.content.widgets.find(e=>e.model.id===t.id);n instanceof l.MarkdownCell&&(n.rendered=!0),"markdown_cell_finished"===m.type&&a.delete(m.cell_id);return}if("markdown_cell_cancelled"===m.type){let t=a.get(m.cell_id);if(a.delete(m.cell_id),!t)return;let n=e.content.widgets.findIndex(e=>e.model.id===t.id);n>=0&&e.content.model?.sharedModel.deleteCell(n);return}if("code_cell_output"===m.type)return void s.get(m.cell_id)?.outputs.add(m.output);if("code_cell_clear"===m.type)return void s.get(m.cell_id)?.outputs.clear(m.wait);if("code_cell_finished"===m.type){let e=s.get(m.cell_id);if(!e)return;e.outputs.fromJSON(m.outputs),e.executionCount=m.execution_count,e.executionState="idle",i&&null===i.parentExecutionCount&&null!==m.execution_count&&(i.parentExecutionCount=m.execution_count-1);return}if("markdown_cell_started"===m.type)u={type:"markdown_cell",source:m.source};else{if("markdown_cell"!==m.type&&"code_cell_started"!==m.type)return;u=m}(()=>{if(i)return;let n=e.content,o=n.widgets.findIndex(e=>"code"===e.model.type&&"running"===e.model.executionState);i={parentModel:o>=0?n.widgets[o].model:null,parentExecutionCount:null};let l=(e,n)=>{"idle"===n&&(t.statusChanged.disconnect(l),c())};return t.statusChanged.connect(l)})();let p=function(e,t){let n=e.content,o=n.model;if(!o)return null;let d=n.widgets.length;"code_cell_started"===t.type?o.sharedModel.insertCell(d,{cell_type:"code",source:t.source,metadata:{trusted:!0,collapsed:!0,editable:!1,deletable:!1,codebind:{kind:"tool"}},execution_count:null,outputs:[]}):o.sharedModel.insertCell(d,{cell_type:"markdown",source:w(t.source),metadata:{editable:!1,deletable:!1,codebind:{kind:"assistant"}}});let i=n.widgets[d]??null;return i&&(i.readOnly=!0),i instanceof l.MarkdownCell&&(i.rendered=!0),i?.model??null}(e,u);"code_cell_started"===m.type&&p?.type==="code"&&(p.executionState="running",s.set(m.cell_id,p)),"markdown_cell_started"===m.type&&p&&a.set(m.cell_id,p)},d.onClose=()=>{if(n.comm===d){let e=n.sessionReady;n.rejectReady?.(Error("Codebind is not loaded in this kernel. Run %load_ext codebind.")),n.comm=null,n.sessionReady=!1,n.ready=null,n.resolveReady=null,n.rejectReady=null,n.connectOnIdle=e}};let u=e.content.model?.getMetadata("codebind");d.open({conversation:"object"==typeof u&&null!==u?u:null})};n.connectKernel=u;let g=(e,t)=>{"idle"===t&&n.connectOnIdle&&(n.connectOnIdle=!1,u())},b=(e,t)=>{r.KernelMessage.isExecuteInputMsg(t)&&/(?:^|\n)\s*%(?:re)?load_ext\s+codebind(?:\s|$)/.test(t.content.code)&&(n.connectOnIdle=!0)};t.statusChanged.connect(g),t.iopubMessage.connect(b),n.disconnectKernel=()=>{t.statusChanged.disconnect(g),t.iopubMessage.disconnect(b)},e.context.ready.then(()=>{e.content.model?.getMetadata("codebind")&&(n.connectOnIdle=!0,u())})}function h(e){let t=e.content,n=t.model;if(!n)return;t.activeCell?"markdown"!==t.activeCell.model.type&&i.NotebookActions.changeCellType(t,"markdown"):(n.sharedModel.insertCell(0,{cell_type:"markdown",source:"",metadata:{}}),t.activeCellIndex=0);let o=t.activeCell;o&&null!==y(o.model)||(o?.model.setMetadata("codebind",{kind:"question",status:"draft"}),o instanceof l.MarkdownCell&&(o.rendered=!1),t.mode="edit",k(e),o?.editor?.focus())}function v(e){let t=m.get(e);if(!t)return;let n=e.content.widgets,o=new Set(n.map(e=>e.model.id)),l=n.filter(e=>!t.knownCellIds.has(e.model.id));for(let e of(t.knownCellIds=o,t.pendingQuestionCellIds))o.has(e)||t.pendingQuestionCellIds.delete(e);if(t.questionMode)for(let e of l)null===y(e.model)&&t.pendingQuestionCellIds.add(e.model.id);k(e),t.questionMode&&e.content.activeCell&&t.pendingQuestionCellIds.delete(e.content.activeCell.model.id)&&h(e)}function M(e,t){let n=m.get(e);n&&(n.questionMode=t,n.questionMode||n.pendingQuestionCellIds.clear(),n.questionButton&&(n.questionButton.pressed=n.questionMode),n.questionMode&&e.content.activeCell&&null===y(e.content.activeCell.model)&&h(e))}async function q(e){let t=e.content,n=t.activeCell;if(!n||!g(n.model))return;await e.sessionContext.ready,C(e);let d=m.get(e),i=d?.registeredKernel;if(!d||!i)return void await (0,o.showErrorMessage)("Codebind is not connected","Start the notebook kernel before sending a Question cell.");try{if("dead"===i.status)throw Error("The notebook kernel stopped.");if("idle"!==i.status&&await new Promise((e,t)=>{let n=(o,l)=>{("idle"===l||"dead"===l)&&(i.statusChanged.disconnect(n),"idle"===l?e():t(Error("The notebook kernel stopped.")))};i.statusChanged.connect(n)}),d.connectKernel?.(),!d.ready)throw Error("Run %load_ext codebind in this kernel.");await d.ready}catch(e){await (0,o.showErrorMessage)("Codebind could not load",String(e));return}if(!d.sessionReady||!d.comm)return void await (0,o.showErrorMessage)("Codebind is not connected","Run %load_ext codebind in this kernel before sending a Question cell.");if(d.runningQuestions.size>0)return void await (0,o.showErrorMessage)("Codebind is busy","Wait for the current question to finish before sending another.");let r=n.model.sharedModel.getSource().trim();if(!r)return void await (0,o.showErrorMessage)("Empty Codebind question","Write a question before sending it.");d.runningQuestions.set(n.model.id,n.model),n.model.sharedModel.setSource(w(r)),n.model.setMetadata("codebind",{kind:"question",status:"sent"}),n.model.setMetadata("editable",!1),n.model.setMetadata("deletable",!1),n.readOnly=!0,k(e),n instanceof l.MarkdownCell&&(n.rendered=!0),t.mode="command";let s=window.setTimeout(()=>{d.questionTimers.has(n.model.id)&&(d.questionTimers.delete(n.model.id),d.runningQuestions.delete(n.model.id),n.model.setMetadata("codebind",{kind:"question",status:"draft"}),n.model.setMetadata("editable",!0),n.model.setMetadata("deletable",!0),n.readOnly=!1,k(e),(0,o.showErrorMessage)("Codebind did not receive the Question","The kernel did not acknowledge it. Reload Codebind and send it again."))},1e4);d.questionTimers.set(n.model.id,s),d.comm.send({type:"question",cell_id:n.model.id,question:r,notebook:function(e){let t=[];for(let n of e.content.widgets){if(null!==y(n.model))continue;let e=n.model.type;if("code"!==e&&"markdown"!==e&&"raw"!==e)continue;let o={id:n.model.id,type:e,source:n.model.sharedModel.getSource(),execution_count:null,outputs:[],attachments:{}};if("code"===e){let e=n.model.toJSON();o.execution_count=e.execution_count,o.outputs=e.outputs.map(_)}else{let e=n.model.toJSON().attachments;if(e){let t={};for(let[n,o]of Object.entries(e))o&&(t[n]=b(o));o.attachments=t}}t.push(o)}return t}(e)})}function x(e,t){let n={comm:null,kernel:null,registeredKernel:null,connectKernel:null,disconnectKernel:null,ready:null,resolveReady:null,rejectReady:null,connectOnIdle:!1,runningQuestions:new Map,questionTimers:new Map,sessionReady:!1,questionMode:!1,questionButton:null,knownCellIds:new Set(e.content.widgets.map(e=>e.model.id)),pendingQuestionCellIds:new Set};m.set(e,n);let l=e=>{f(n)&&(e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),window.setTimeout(()=>{n.runningQuestions.size>0&&n.kernel?.interrupt()},500))},d=null,i=()=>{let t=e.toolbar.node.querySelector('[data-command="notebook:interrupt-kernel"]');t!==d&&(d?.removeEventListener("click",l,!0),d=t,d?.addEventListener("click",l,!0))},r=new MutationObserver(i);r.observe(e.toolbar.node,{childList:!0,subtree:!0});let s=new MutationObserver(()=>{window.setTimeout(()=>v(e),0)});s.observe(e.content.node,{childList:!0,subtree:!0}),i(),e.disposed.connect(()=>{for(let e of(r.disconnect(),s.disconnect(),d?.removeEventListener("click",l,!0),n.disconnectKernel?.(),n.rejectReady?.(Error("The notebook closed.")),n.comm?.close(),n.kernel&&p.get(n.kernel)?.delete(n),n.questionTimers.values()))window.clearTimeout(e);n.questionTimers.clear()});let c=new o.ToolbarButton({label:"Question",tooltip:"Toggle Question mode for the selected and newly created cells",onClick:()=>{M(e,c.pressed),t.commands.notifyCommandChanged(a)}});n.questionButton=c,e.toolbar.insertItem(10,"codebindQuestion",c),e.content.modelContentChanged.connect(()=>{v(e),window.setTimeout(()=>v(e),0)}),e.content.activeCellChanged.connect(()=>v(e)),e.context.ready.then(()=>{e.content.model?.cells.changed.connect(()=>{v(e),window.setTimeout(()=>v(e),0)}),v(e)}),e.sessionContext.ready.then(()=>C(e)),e.sessionContext.kernelChanged.connect(()=>C(e))}let j={id:"codebind-jupyterlab:plugin",description:"Insert Codebind executions as native notebook cells.",autoStart:!0,requires:[i.INotebookTracker],activate:(e,t)=>{e.commands.addCommand(s,{label:"Use Selected Cell as Codebind Question",execute:()=>{let e=t.currentWidget;e&&h(e)}}),e.commands.addCommand(a,{label:"Toggle Codebind Question Mode",isToggled:()=>{let e=t.currentWidget;return!!e&&(m.get(e)?.questionMode??!1)},execute:()=>{let n=t.currentWidget;if(n){let t;(t=m.get(n))&&M(n,!t.questionMode),e.commands.notifyCommandChanged(a)}}}),e.commands.addCommand(c,{label:"Send Codebind Question",isEnabled:()=>{let e=t.currentWidget?.content.activeCell;return!!e&&null!==g(e.model)},execute:async()=>{let e=t.currentWidget;e&&await q(e)}}),e.commands.addKeyBinding({command:c,keys:["Shift Enter"],selector:`.jp-Notebook.jp-mod-editMode .${u}`}),e.commands.addKeyBinding({command:c,keys:["Shift Enter"],selector:`.jp-Notebook.jp-mod-commandMode .${u}`}),e.contextMenu.addItem({command:s,selector:".jp-Notebook .jp-Cell",rank:8}),t.forEach(t=>x(t,e)),t.widgetAdded.connect((t,n)=>x(n,e))}};n.d(t,{},{default:j})}}]);
@@ -1 +0,0 @@
1
- var _JUPYTERLAB;(()=>{"use strict";var e,n,r,t,o,i,u,a,l,c,s,f,p,d,h,g,v,y,b,m,S,k,j,w,E,x,T,M,P,V,q,A,C,O,D,_,L,N={457(e,n,r){var t={"./index":()=>r.e(590).then(()=>()=>r(509)),"./extension":()=>r.e(590).then(()=>()=>r(509))},o=function(e,n){return r.R=n,n=r.o(t,e)?t[e]():Promise.resolve().then(()=>{throw Error('Module "'+e+'" does not exist in container.')}),r.R=void 0,n},i=function(e,n){if(r.S){var t="default",o=r.S[t];if(o&&o!==e)throw Error("Container initialization failed as it has already been initialized with a different share scope");return r.S[t]=e,r.I(t,n)}};r.d(n,{get:()=>o,init:()=>i})}},$={};function z(e){var n=$[e];if(void 0!==n)return n.exports;var r=$[e]={exports:{}};return N[e](r,r.exports,z),r.exports}z.m=N,z.c=$,z.n=e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return z.d(n,{a:n}),n},z.d=(e,n,r)=>{var t=(n,r)=>{for(var t in n)z.o(n,t)&&!z.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,[r]:n[t]})};t(n,"get"),t(r,"value")},z.f={},z.e=e=>Promise.all(Object.keys(z.f).reduce((n,r)=>(z.f[r](e,n),n),[])),z.u=e=>""+e+".dae4561c5427a855.js?v=dae4561c5427a855",z.g=(()=>{if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}})(),z.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),I={},z.l=function(e,n,r,t){if(I[e])return void I[e].push(n);if(void 0!==r)for(var o,i,u=document.getElementsByTagName("script"),a=0;a<u.length;a++){var l=u[a];if(l.getAttribute("src")==e||l.getAttribute("data-rspack")=="codebind-jupyterlab:"+r){o=l;break}}o||(i=!0,(o=document.createElement("script")).timeout=120,z.nc&&o.setAttribute("nonce",z.nc),o.setAttribute("data-rspack","codebind-jupyterlab:"+r),o.src=e),I[e]=[n];var c=function(n,r){o.onerror=o.onload=null,clearTimeout(s);var t=I[e];if(delete I[e],o.parentNode&&o.parentNode.removeChild(o),t&&t.forEach(function(e){return e(r)}),n)return n(r)},s=setTimeout(c.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=c.bind(null,o.onerror),o.onload=c.bind(null,o.onload),i&&document.head.appendChild(o)},z.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},z.S={},z.initializeSharingData={scopeToSharingDataMapping:{default:[{name:"codebind-jupyterlab",version:"0.6.5",factory:()=>z.e(590).then(()=>()=>z(509)),eager:0,treeShakingMode:null}]},uniqueName:"codebind-jupyterlab"},R={},U={},z.I=function(e,n){n||(n=[]);var r=U[e];if(r||(r=U[e]={}),!(n.indexOf(r)>=0)){if(n.push(r),R[e])return R[e];z.o(z.S,e)||(z.S[e]={});var t=z.S[e],o=function(e){"u">typeof console&&console.warn&&console.warn(e)},i=z.initializeSharingData.uniqueName,u=function(e,n,r,o){var u=t[e]=t[e]||{},a=u[n];(!a||!a.loaded&&(!o!=!a.eager?o:i>a.from))&&(u[n]={get:r,from:i,eager:!!o})},a=function(r){var t=function(e){o("Initialization of sharing external failed: "+e)};try{var i=z(r);if(!i)return;var u=function(r){return r&&r.init&&r.init(z.S[e],n)};if(i.then)return l.push(i.then(u,t));var a=u(i);if(a&&a.then)return l.push(a.catch(t))}catch(e){t(e)}},l=[],c=z.initializeSharingData.scopeToSharingDataMapping;return(c[e]&&c[e].forEach(function(e){"object"==typeof e?u(e.name,e.version,e.factory,e.eager):a(e)}),l.length)?R[e]=Promise.all(l).then(function(){return R[e]=1}):R[e]=1}},z.g.importScripts&&(B=z.g.location+"");var I,R,U,B,K=z.g.document;if(!B&&K&&(K.currentScript&&"SCRIPT"===K.currentScript.tagName.toUpperCase()&&(B=K.currentScript.src),!B)){var J=K.getElementsByTagName("script");if(J.length)for(var Y=J.length-1;Y>-1&&(!B||!/^http(s?):/.test(B));)B=J[Y--].src}if(!B)throw Error("Automatic publicPath is not supported in this browser");z.p=B=B.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),z.consumesLoadingData={chunkMapping:{590:["511","343","99","171","241"]},moduleIdToConsumeDataMapping:{171:{shareScope:"default",shareKey:"@jupyterlab/notebook",import:null,requiredVersion:"^4.6.3",strictVersion:!1,singleton:!0,eager:!1,fallback:void 0,treeShakingMode:null},241:{shareScope:"default",shareKey:"@jupyterlab/services",import:null,requiredVersion:"^7.6.3",strictVersion:!1,singleton:!0,eager:!1,fallback:void 0,treeShakingMode:null},343:{shareScope:"default",shareKey:"@jupyterlab/cells",import:null,requiredVersion:"^4.6.3",strictVersion:!1,singleton:!1,eager:!1,fallback:void 0,treeShakingMode:null},511:{shareScope:"default",shareKey:"@jupyterlab/apputils",import:null,requiredVersion:"^4.7.3",strictVersion:!1,singleton:!0,eager:!1,fallback:void 0,treeShakingMode:null},99:{shareScope:"default",shareKey:"@jupyterlab/nbformat",import:null,requiredVersion:"^4.6.3",strictVersion:!1,singleton:!1,eager:!1,fallback:void 0,treeShakingMode:null}},initialConsumes:[]},e=function(e){return e.split(".").map(function(e){return+e==e?+e:e})},n=function(n){var r=function(n){var r=/^([^-+]+)?(?:-([^+]+))?(?:\+(.+))?$/.exec(n),t=r[1]?[0].concat(e(r[1])):[0];r[2]&&(t.length++,t.push.apply(t,e(r[2])));let o=t[t.length-1];for(;t.length&&(void 0===o||/^[*xX]$/.test(o));)t.pop(),o=t[t.length-1];return t},t=function(e){return 1===e.length?[0]:2===e.length?[1].concat(e.slice(1)):3===e.length?[2].concat(e.slice(1)):[e.length].concat(e.slice(1))},o=function(e){return[-e[0]-1].concat(e.slice(1))},i=function(e){let n=/^(\^|~|<=|<|>=|>|=|v|!)/.exec(e),i=n?n[0]:"",u=r(i.length?e.slice(i.length).trim():e.trim());switch(i){case"^":if(u.length>1&&0===u[1]){if(u.length>2&&0===u[2])return[3].concat(u.slice(1));return[2].concat(u.slice(1))}return[1].concat(u.slice(1));case"~":return[2].concat(u.slice(1));case">=":return u;case"=":case"v":case"":return t(u);case"<":return o(u);case">":return[,t(u),0,u,2];case"<=":return[,t(u),o(u),1];case"!":return[,t(u),0];default:throw Error("Unexpected start value")}},u=function(e,n){if(1===e.length)return e[0];let r=[];for(let n of e.slice().reverse())0 in n?r.push(n):r.push.apply(r,n.slice(1));return[,].concat(r,e.slice(1).map(()=>n))};return u(n.split(/\s*\|\|\s*/).map(function(e){let n=e.split(/\s+-\s+/);if(1===n.length){e=e.trim();let n=[],r=/[-0-9A-Za-z]\s+/g;for(var a,l=0;a=r.exec(e);){let r=a.index+1;n.push(i(e.slice(l,r).trim())),l=r}return n.push(i(e.slice(l).trim())),u(n,2)}let c=r(n[0]),s=r(n[1]);return[,t(s),o(s),1,c,2]}),1)},r=function(n){var r=/^([^-+]+)?(?:-([^+]+))?(?:\+(.+))?$/.exec(n),t=r[1]?e(r[1]):[];return r[2]&&(t.length++,t.push.apply(t,e(r[2]))),r[3]&&(t.push([]),t.push.apply(t,e(r[3]))),t},t=function(e,n){e=r(e),n=r(n);for(var t=0;;){if(t>=e.length)return t<n.length&&"u"!=(typeof n[t])[0];var o=e[t],i=(typeof o)[0];if(t>=n.length)return"u"==i;var u=n[t],a=(typeof u)[0];if(i==a){if("o"!=i&&"u"!=i&&o!=u)return o<u;t++}else{if("o"==i&&"n"==a)return!0;return"s"==a||"u"==i}}},o=function(e){var n=e[0],r="";if(1===e.length)return"*";if(n+.5){r+=0==n?">=":-1==n?"<":1==n?"^":2==n?"~":n>0?"=":"!=";for(var t=1,i=1;i<e.length;i++){var u=e[i],a=(typeof u)[0];t--,r+="u"==a?"-":(t>0?".":"")+(t=2,u)}return r}for(var l=[],i=1;i<e.length;i++){var u=e[i];l.push(0===u?"not("+c()+")":1===u?"("+c()+" || "+c()+")":2===u?l.pop()+" "+l.pop():o(u))}return c();function c(){return l.pop().replace(/^\((.+)\)$/,"$1")}},i=function(e,n){if(0 in e){n=r(n);var t=e[0],o=t<0;o&&(t=-t-1);for(var u=0,a=1,l=!0;;a++,u++){var c,s,f=a<e.length?(typeof e[a])[0]:"";if(u>=n.length||"o"==(s=(typeof(c=n[u]))[0])){if(!l)return!0;if("u"==f)return a>t&&!o;return""==f!=o}if("u"==s){if(!l||"u"!=f)return!1}else if(l)if(f==s)if(a<=t){if(c!=e[a])return!1}else{if(o?c>e[a]:c<e[a])return!1;c!=e[a]&&(l=!1)}else if("s"!=f&&"n"!=f){if(o||a<=t)return!1;l=!1,a--}else{if(a<=t||s<f!=o)return!1;l=!1}else"s"!=f&&"n"!=f&&(l=!1,a--)}}for(var p=[],d=p.pop.bind(p),u=1;u<e.length;u++){var h=e[u];p.push(1==h?d()|d():2==h?d()&d():h?i(h,n):!d())}return!!d()},u=function(e,n){var r=z.S[e];if(!r||!z.o(r,n))throw Error("Shared module "+n+" doesn't exist in shared scope "+e);return r},a=function(e,n){var r=e[n],n=Object.keys(r).reduce(function(e,n){return!e||t(e,n)?n:e},0);return n&&r[n]},l=function(e,n){var r=e[n];return Object.keys(r).reduce(function(e,n){return!e||!r[e].loaded&&t(e,n)?n:e},0)},c=function(e,n,r,t){return"Unsatisfied version "+r+" from "+(r&&e[n][r].from)+" of shared singleton module "+n+" (required "+o(t)+")"},s=function(e,n,r,t){var o=l(e,r);return b(e[r][o])},f=function(e,n,r,t){var o=l(e,r);return i(t,o)||v(c(e,r,o,t)),b(e[r][o])},p=function(e,n,r,t){var o=l(e,r);if(!i(t,o))throw Error(c(e,r,o,t));return b(e[r][o])},d=function(e,n,r){var o=e[n],n=Object.keys(o).reduce(function(e,n){return i(r,n)&&(!e||t(e,n))?n:e},0);return n&&o[n]},h=function(e,n,r,t){var i=e[r];return"No satisfying version ("+o(t)+") of shared module "+r+" found in shared scope "+n+".\nAvailable versions: "+Object.keys(i).map(function(e){return e+" from "+i[e].from}).join(", ")},g=function(e,n,r,t){var o=d(e,r,t);if(o)return b(o);throw Error(h(e,n,r,t))},v=function(e){"u">typeof console&&console.warn&&console.warn(e)},y=function(e,n,r,t){v(h(e,n,r,t))},b=function(e){return e.loaded=1,e.get()},S=(m=function(e){return function(n,r,t,o){var i=z.I(n);return i&&i.then?i.then(e.bind(e,n,z.S[n],r,t,o)):e(n,z.S[n],r,t,o)}})(function(e,n,r){return u(e,r),b(a(n,r))}),k=m(function(e,n,r,t){return n&&z.o(n,r)?b(a(n,r)):t()}),j=m(function(e,n,r,t){return u(e,r),b(d(n,r,t)||y(n,e,r,t)||a(n,r))}),w=m(function(e,n,r){return u(e,r),s(n,e,r)}),E=m(function(e,n,r,t){return u(e,r),f(n,e,r,t)}),x=m(function(e,n,r,t){return u(e,r),g(n,e,r,t)}),T=m(function(e,n,r,t){return u(e,r),p(n,e,r,t)}),M=m(function(e,n,r,t,o){return n&&z.o(n,r)?b(d(n,r,t)||y(n,e,r,t)||a(n,r)):o()}),P=m(function(e,n,r,t){return n&&z.o(n,r)?s(n,e,r):t()}),V=m(function(e,n,r,t,o){return n&&z.o(n,r)?f(n,e,r,t):o()}),q=m(function(e,n,r,t,o){var i=n&&z.o(n,r)&&d(n,r,t);return i?b(i):o()}),A=m(function(e,n,r,t,o){return n&&z.o(n,r)?p(n,e,r,t):o()}),C=function(e){var r=!1,t=!1,o=!1,i=!1,u=[e.shareScope,e.shareKey];return(e.requiredVersion?(e.strictVersion&&(r=!0),e.singleton&&(t=!0),u.push(n(e.requiredVersion)),o=!0):e.singleton&&(t=!0),e.fallback&&(i=!0,u.push(e.fallback)),r&&t&&o&&i)?function(){return A.apply(null,u)}:r&&o&&i?function(){return q.apply(null,u)}:t&&o&&i?function(){return V.apply(null,u)}:r&&t&&o?function(){return T.apply(null,u)}:t&&i?function(){return P.apply(null,u)}:o&&i?function(){return M.apply(null,u)}:r&&o?function(){return x.apply(null,u)}:t&&o?function(){return E.apply(null,u)}:t?function(){return w.apply(null,u)}:o?function(){return j.apply(null,u)}:i?function(){return k.apply(null,u)}:function(){return S.apply(null,u)}},O={},z.f.consumes=function(e,n){var r=z.consumesLoadingData.moduleIdToConsumeDataMapping,t=z.consumesLoadingData.chunkMapping;z.o(t,e)&&t[e].forEach(function(e){if(z.o(O,e))return n.push(O[e]);var t=function(n){O[e]=0,z.m[e]=function(r){delete z.c[e],r.exports=n()}},o=function(n){delete O[e],z.m[e]=function(r){throw delete z.c[e],n}};try{var i=C(r[e])();i.then?n.push(O[e]=i.then(t).catch(o)):t(i)}catch(e){o(e)}})},D={871:0},z.f.j=function(e,n){var r=z.o(D,e)?D[e]:void 0;if(0!==r)if(r)n.push(r[2]);else{var t=new Promise((n,t)=>r=D[e]=[n,t]);n.push(r[2]=t);var o=z.p+z.u(e),i=Error();z.l(o,function(n){if(z.o(D,e)&&(0!==(r=D[e])&&(D[e]=void 0),r)){var t=n&&("load"===n.type?"missing":n.type),o=n&&n.target&&n.target.src;i.message="Loading chunk "+e+" failed.\n("+t+": "+o+")",i.name="ChunkLoadError",i.type=t,i.request=o,r[1](i)}},"chunk-"+e,e)}},_=(e,n)=>{var r,t,[o,i,u]=n,a=0;if(o.some(e=>0!==D[e])){for(r in i)z.o(i,r)&&(z.m[r]=i[r]);u&&u(z)}for(e&&e(n);a<o.length;a++)t=o[a],z.o(D,t)&&D[t]&&D[t][0](),D[t]=0},(L=self.rspackChunkcodebind_jupyterlab=self.rspackChunkcodebind_jupyterlab||[]).forEach(_.bind(null,0)),L.push=_.bind(null,L.push.bind(L));var F=z(457);(_JUPYTERLAB=void 0===_JUPYTERLAB?{}:_JUPYTERLAB)["codebind-jupyterlab"]=F})();
File without changes
File without changes
File without changes