codebind 0.6.0__tar.gz → 0.6.1__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.
- {codebind-0.6.0 → codebind-0.6.1}/PKG-INFO +2 -2
- {codebind-0.6.0 → codebind-0.6.1}/README.md +1 -1
- {codebind-0.6.0 → codebind-0.6.1}/data/share/jupyter/labextensions/codebind-jupyterlab/package.json +2 -2
- codebind-0.6.1/data/share/jupyter/labextensions/codebind-jupyterlab/static/590.5b773af7a27693b3.js +1 -0
- codebind-0.6.0/data/share/jupyter/labextensions/codebind-jupyterlab/static/remoteEntry.4f0137dd98629dab.js → codebind-0.6.1/data/share/jupyter/labextensions/codebind-jupyterlab/static/remoteEntry.b171b12ff4a78939.js +1 -1
- {codebind-0.6.0 → codebind-0.6.1}/jupyterlab/package.json +1 -1
- {codebind-0.6.0 → codebind-0.6.1}/jupyterlab/src/index.ts +73 -1
- {codebind-0.6.0 → codebind-0.6.1}/pyproject.toml +1 -1
- {codebind-0.6.0 → codebind-0.6.1}/pyproject.toml.orig +1 -1
- {codebind-0.6.0 → codebind-0.6.1}/src/codebind/jupyter.py +47 -0
- {codebind-0.6.0 → codebind-0.6.1}/src/codebind/session.py +113 -18
- codebind-0.6.0/data/share/jupyter/labextensions/codebind-jupyterlab/static/590.8d95476143320694.js +0 -1
- {codebind-0.6.0 → codebind-0.6.1}/LICENSE +0 -0
- {codebind-0.6.0 → codebind-0.6.1}/data/share/jupyter/labextensions/codebind-jupyterlab/install.json +0 -0
- {codebind-0.6.0 → codebind-0.6.1}/data/share/jupyter/labextensions/codebind-jupyterlab/static/style.js +0 -0
- {codebind-0.6.0 → codebind-0.6.1}/data/share/jupyter/labextensions/codebind-jupyterlab/static/third-party-licenses.json +0 -0
- {codebind-0.6.0 → codebind-0.6.1}/jupyterlab/.yarnrc.yml +0 -0
- {codebind-0.6.0 → codebind-0.6.1}/jupyterlab/install.json +0 -0
- {codebind-0.6.0 → codebind-0.6.1}/jupyterlab/tsconfig.json +0 -0
- {codebind-0.6.0 → codebind-0.6.1}/jupyterlab/yarn.lock +0 -0
- {codebind-0.6.0 → codebind-0.6.1}/src/codebind/__init__.py +0 -0
- {codebind-0.6.0 → codebind-0.6.1}/src/codebind/cli.py +0 -0
- {codebind-0.6.0 → codebind-0.6.1}/src/codebind/configuration.py +0 -0
- {codebind-0.6.0 → codebind-0.6.1}/src/codebind/conversation.py +0 -0
- {codebind-0.6.0 → codebind-0.6.1}/src/codebind/display.py +0 -0
- {codebind-0.6.0 → codebind-0.6.1}/src/codebind/execution.py +0 -0
- {codebind-0.6.0 → codebind-0.6.1}/src/codebind/extension.py +0 -0
- {codebind-0.6.0 → codebind-0.6.1}/src/codebind/instructions.md +0 -0
- {codebind-0.6.0 → codebind-0.6.1}/src/codebind/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codebind
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.1
|
|
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
|
|
@@ -97,7 +97,7 @@ Loading the extension adds a locked Markdown cell containing Codebind's packaged
|
|
|
97
97
|
|
|
98
98
|
The whole notebook is model context. Before each Question, Codebind takes a canonical snapshot of ordinary Markdown, raw, and code cells, including compact visible text outputs but never the live Python namespace. The first turn records the snapshot; later turns append only new, changed, removed, or reordered cells. Questions, tool calls, tool results, and answers already present in the conversation ledger are not duplicated. This append-only representation keeps the prior model prefix unchanged for provider caching.
|
|
99
99
|
|
|
100
|
-
Codebind stores the complete LangChain message, notebook-context, and turn ledger in notebook metadata. Reopening the notebook, restarting its kernel, and loading the extension restores the exact accumulated context automatically. Tool executions and assistant answers are always appended to the notebook end without changing the user's current selection or scroll position. Tool outputs are collapsed by default and remain expandable through JupyterLab's native output control.
|
|
100
|
+
Codebind stores the complete LangChain message, notebook-context, and turn ledger in notebook metadata. Reopening the notebook, restarting its kernel, and loading the extension restores the exact accumulated context automatically. Assistant Markdown streams into its native cell as it is generated, before a following tool call is complete. Tool executions and assistant answers are always appended to the notebook end without changing the user's current selection or scroll position. Tool outputs are collapsed by default and remain expandable through JupyterLab's native output control.
|
|
101
101
|
|
|
102
102
|
An interrupted tool call is closed with an explicit interrupted result before the turn ends. If a provider stream is cancelled or fails, Codebind discards that provider session before the next Question while retaining the notebook conversation and its stable prompt-cache identity.
|
|
103
103
|
|
|
@@ -72,7 +72,7 @@ Loading the extension adds a locked Markdown cell containing Codebind's packaged
|
|
|
72
72
|
|
|
73
73
|
The whole notebook is model context. Before each Question, Codebind takes a canonical snapshot of ordinary Markdown, raw, and code cells, including compact visible text outputs but never the live Python namespace. The first turn records the snapshot; later turns append only new, changed, removed, or reordered cells. Questions, tool calls, tool results, and answers already present in the conversation ledger are not duplicated. This append-only representation keeps the prior model prefix unchanged for provider caching.
|
|
74
74
|
|
|
75
|
-
Codebind stores the complete LangChain message, notebook-context, and turn ledger in notebook metadata. Reopening the notebook, restarting its kernel, and loading the extension restores the exact accumulated context automatically. Tool executions and assistant answers are always appended to the notebook end without changing the user's current selection or scroll position. Tool outputs are collapsed by default and remain expandable through JupyterLab's native output control.
|
|
75
|
+
Codebind stores the complete LangChain message, notebook-context, and turn ledger in notebook metadata. Reopening the notebook, restarting its kernel, and loading the extension restores the exact accumulated context automatically. Assistant Markdown streams into its native cell as it is generated, before a following tool call is complete. Tool executions and assistant answers are always appended to the notebook end without changing the user's current selection or scroll position. Tool outputs are collapsed by default and remain expandable through JupyterLab's native output control.
|
|
76
76
|
|
|
77
77
|
An interrupted tool call is closed with an explicit interrupted result before the turn ends. If a provider stream is cancelled or fails, Codebind discards that provider session before the next Question while retaining the notebook conversation and its stable prompt-cache identity.
|
|
78
78
|
|
{codebind-0.6.0 → codebind-0.6.1}/data/share/jupyter/labextensions/codebind-jupyterlab/package.json
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codebind-jupyterlab",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
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.
|
|
34
|
+
"load": "static/remoteEntry.b171b12ff4a78939.js",
|
|
35
35
|
"extension": "./extension"
|
|
36
36
|
}
|
|
37
37
|
}
|
codebind-0.6.1/data/share/jupyter/labextensions/codebind-jupyterlab/static/590.5b773af7a27693b3.js
ADDED
|
@@ -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);let r="codebind:insert-question",s="codebind:toggle-question-mode",a="codebind:run-question",u="jp-CodebindQuestionCell",c=new WeakMap,m=new WeakMap;function p(e){return 0!==e.runningQuestions.size&&(e.comm?.send({type:"cancel"}),!0)}function f(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 g(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/")||"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:y(e.data)}:d.isDisplayData(e)?{type:"display",data:y(e.data)}:{type:e.output_type}}function w(e){return e.replace(/(^|[^\\])\\([()[\]])/g,"$1\\\\$2")}function b(e){let t=c.get(e);for(let n of e.content.widgets){let e=f(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=c.get(e)??{comm:null,kernel:null,runningQuestions:new Map,questionTimers:new Map,sessionReady:!1,sessionError:null,questionMode:!1,questionButton:null,knownCellIds:new Set(e.content.widgets.map(e=>e.model.id)),pendingQuestionCellIds:new Set};c.set(e,n);n.kernel&&n.kernel!==t&&m.get(n.kernel)?.delete(n),n.kernel=t;let d=m.get(t);if(!d){d=new Set,m.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)p(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,n.sessionError=null;let i=null,r=new Map,s=new Map,a=()=>{if(!i)return;let e=i;i=null,e.parentModel&&null!==e.parentExecutionCount&&(e.parentModel.executionCount=e.parentExecutionCount)};t.registerCommTarget("codebind",(d,u)=>{d.onMsg=u=>{let c,m=u.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=!1,i=n.widgets.findIndex(e=>"instructions"===g(e.model));if(i<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"}}}),i=0,d=!0,null!==e){let t=n.widgets.findIndex(t=>t.model.id===e);t>=0&&(n.activeCellIndex=t)}}let r=n.widgets[i];r&&(r.model.sharedModel.getSource()!==t&&(r.model.sharedModel.setSource(t),d=!0),!1!==r.model.getMetadata("editable")&&(d=!0),!1!==r.model.getMetadata("deletable")&&(d=!0),r.model.setMetadata("editable",!1),r.model.setMetadata("deletable",!1),r.model.setMetadata("codebind",{kind:"instructions"}),r.readOnly=!0,r instanceof l.MarkdownCell&&(r.rendered=!0),d&&e.context.save())}(e,m.source);if("session_ready"===m.type){n.sessionReady=null===m.error,n.sessionError=m.error?.message??null,m.error&&(0,o.showErrorMessage)(`Codebind could not load: ${m.error.type}`,m.error.message);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),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=s.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&&s.delete(m.cell_id);return}if("markdown_cell_cancelled"===m.type){let t=s.get(m.cell_id);if(s.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 r.get(m.cell_id)?.outputs.add(m.output);if("code_cell_clear"===m.type)return void r.get(m.cell_id)?.outputs.clear(m.wait);if("code_cell_finished"===m.type){let e=r.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)c={type:"markdown_cell",source:m.source};else{if("markdown_cell"!==m.type&&"code_cell_started"!==m.type)return;c=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: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,c);"code_cell_started"===m.type&&p?.type==="code"&&(p.executionState="running",r.set(m.cell_id,p)),"markdown_cell_started"===m.type&&p&&s.set(m.cell_id,p)},n.comm=d,d.onClose=()=>{n.comm===d&&(n.comm=null,n.sessionReady=!1)};let c=e.content.model?.getMetadata("codebind");d.send({type:"ready",conversation:"object"==typeof c&&null!==c?c:null})})}function k(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!==g(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 M(e){let t=c.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===g(e.model)&&t.pendingQuestionCellIds.add(e.model.id);b(e),t.questionMode&&e.content.activeCell&&t.pendingQuestionCellIds.delete(e.content.activeCell.model.id)&&k(e)}function h(e,t){let n=c.get(e);n&&(n.questionMode=t,n.questionMode||n.pendingQuestionCellIds.clear(),n.questionButton&&(n.questionButton.pressed=n.questionMode),n.questionMode&&e.content.activeCell&&null===g(e.content.activeCell.model)&&k(e))}async function v(e){let t=e.content,n=t.activeCell;if(!n||!f(n.model))return;let d=c.get(e);if(!d?.comm)return void await (0,o.showErrorMessage)("Codebind is not connected","Run %load_ext codebind in this kernel before sending a Question cell.");for(let e=0;!d.sessionReady&&!d.sessionError&&d.comm&&e<600;e+=1)await new Promise(e=>window.setTimeout(e,50));if(d.sessionError)return void await (0,o.showErrorMessage)("Codebind could not load",d.sessionError);if(!d.sessionReady)return void await (0,o.showErrorMessage)("Codebind did not finish loading","Reload Codebind and send the Question again.");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 i=n.model.sharedModel.getSource().trim();if(!i)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(i)),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 r=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,r),d.comm.send({type:"question",cell_id:n.model.id,question:i,notebook:function(e){let t=[];for(let n of e.content.widgets){if(null!==g(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:[]};if("code"===e){let e=n.model.toJSON();o.execution_count=e.execution_count,o.outputs=e.outputs.map(_)}t.push(o)}return t}(e)})}function q(e,t){let n={comm:null,kernel:null,runningQuestions:new Map,questionTimers:new Map,sessionReady:!1,sessionError:null,questionMode:!1,questionButton:null,knownCellIds:new Set(e.content.widgets.map(e=>e.model.id)),pendingQuestionCellIds:new Set};c.set(e,n);let l=e=>{p(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 a=new MutationObserver(()=>{window.setTimeout(()=>M(e),0)});a.observe(e.content.node,{childList:!0,subtree:!0}),i(),e.disposed.connect(()=>{for(let e of(r.disconnect(),a.disconnect(),d?.removeEventListener("click",l,!0),n.questionTimers.values()))window.clearTimeout(e);n.questionTimers.clear()});let u=new o.ToolbarButton({label:"Question",tooltip:"Toggle Question mode for the selected and newly created cells",onClick:()=>{h(e,u.pressed),t.commands.notifyCommandChanged(s)}});n.questionButton=u,e.toolbar.insertItem(10,"codebindQuestion",u),e.content.modelContentChanged.connect(()=>{M(e),window.setTimeout(()=>M(e),0)}),e.content.activeCellChanged.connect(()=>M(e)),e.context.ready.then(()=>{e.content.model?.cells.changed.connect(()=>{M(e),window.setTimeout(()=>M(e),0)}),M(e)}),e.sessionContext.ready.then(()=>C(e)),e.sessionContext.kernelChanged.connect(()=>C(e))}let x={id:"codebind-jupyterlab:plugin",description:"Insert Codebind executions as native notebook cells.",autoStart:!0,requires:[i.INotebookTracker],activate:(e,t)=>{e.commands.addCommand(r,{label:"Use Selected Cell as Codebind Question",execute:()=>{let e=t.currentWidget;e&&k(e)}}),e.commands.addCommand(s,{label:"Toggle Codebind Question Mode",isToggled:()=>{let e=t.currentWidget;return!!e&&(c.get(e)?.questionMode??!1)},execute:()=>{let n=t.currentWidget;if(n){let t;(t=c.get(n))&&h(n,!t.questionMode),e.commands.notifyCommandChanged(s)}}}),e.commands.addCommand(a,{label:"Send Codebind Question",isEnabled:()=>{let e=t.currentWidget?.content.activeCell;return!!e&&null!==f(e.model)},execute:async()=>{let e=t.currentWidget;e&&await v(e)}}),e.commands.addKeyBinding({command:a,keys:["Shift Enter"],selector:`.jp-Notebook .${u}`}),e.contextMenu.addItem({command:r,selector:".jp-Notebook .jp-Cell",rank:8}),t.forEach(t=>q(t,e)),t.widgetAdded.connect((t,n)=>q(n,e))}};n.d(t,{},{default:x})}}]);
|
|
@@ -1 +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,A,C,O,V,q,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+".8d95476143320694.js?v=8d95476143320694",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.0",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"]},moduleIdToConsumeDataMapping:{171:{shareScope:"default",shareKey:"@jupyterlab/notebook",import:null,requiredVersion:"^4.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()}),A=b(function(e,n,r,t,o){return n&&z.o(n,r)?f(n,e,r,t):o()}),C=b(function(e,n,r,t,o){var i=n&&z.o(n,r)&&d(n,r,t);return i?m(i):o()}),O=b(function(e,n,r,t,o){return n&&z.o(n,r)?p(n,e,r,t):o()}),V=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 O.apply(null,u)}:r&&o&&i?function(){return C.apply(null,u)}:t&&o&&i?function(){return A.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)}},q={},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(q,e))return n.push(q[e]);var t=function(n){q[e]=0,z.m[e]=function(r){delete z.c[e],r.exports=n()}},o=function(n){delete q[e],z.m[e]=function(r){throw delete z.c[e],n}};try{var i=V(r[e])();i.then?n.push(q[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
|
+
var _JUPYTERLAB;(()=>{"use strict";var e,n,r,t,o,i,u,a,c,l,s,f,p,d,h,g,v,y,m,b,S,k,j,w,E,x,T,M,P,A,C,O,V,q,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+".5b773af7a27693b3.js?v=5b773af7a27693b3",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 c=u[a];if(c.getAttribute("src")==e||c.getAttribute("data-rspack")=="codebind-jupyterlab:"+r){o=c;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 l=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(l.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=l.bind(null,o.onerror),o.onload=l.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.1",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 c.push(i.then(u,t));var a=u(i);if(a&&a.then)return c.push(a.catch(t))}catch(e){t(e)}},c=[],l=z.initializeSharingData.scopeToSharingDataMapping;return(l[e]&&l[e].forEach(function(e){"object"==typeof e?u(e.name,e.version,e.factory,e.eager):a(e)}),c.length)?R[e]=Promise.all(c).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"]},moduleIdToConsumeDataMapping:{171:{shareScope:"default",shareKey:"@jupyterlab/notebook",import:null,requiredVersion:"^4.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,c=0;a=r.exec(e);){let r=a.index+1;n.push(i(e.slice(c,r).trim())),c=r}return n.push(i(e.slice(c).trim())),u(n,2)}let l=r(n[0]),s=r(n[1]);return[,t(s),o(s),1,l,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 c=[],i=1;i<e.length;i++){var u=e[i];c.push(0===u?"not("+l()+")":1===u?"("+l()+" || "+l()+")":2===u?c.pop()+" "+c.pop():o(u))}return l();function l(){return c.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,c=!0;;a++,u++){var l,s,f=a<e.length?(typeof e[a])[0]:"";if(u>=n.length||"o"==(s=(typeof(l=n[u]))[0])){if(!c)return!0;if("u"==f)return a>t&&!o;return""==f!=o}if("u"==s){if(!c||"u"!=f)return!1}else if(c)if(f==s)if(a<=t){if(l!=e[a])return!1}else{if(o?l>e[a]:l<e[a])return!1;l!=e[a]&&(c=!1)}else if("s"!=f&&"n"!=f){if(o||a<=t)return!1;c=!1,a--}else{if(a<=t||s<f!=o)return!1;c=!1}else"s"!=f&&"n"!=f&&(c=!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]},c=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)},l=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=c(e,r);return m(e[r][o])},f=function(e,n,r,t){var o=c(e,r);return i(t,o)||v(l(e,r,o,t)),m(e[r][o])},p=function(e,n,r,t){var o=c(e,r);if(!i(t,o))throw Error(l(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()}),A=b(function(e,n,r,t,o){return n&&z.o(n,r)?f(n,e,r,t):o()}),C=b(function(e,n,r,t,o){var i=n&&z.o(n,r)&&d(n,r,t);return i?m(i):o()}),O=b(function(e,n,r,t,o){return n&&z.o(n,r)?p(n,e,r,t):o()}),V=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 O.apply(null,u)}:r&&o&&i?function(){return C.apply(null,u)}:t&&o&&i?function(){return A.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)}},q={},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(q,e))return n.push(q[e]);var t=function(n){q[e]=0,z.m[e]=function(r){delete z.c[e],r.exports=n()}},o=function(n){delete q[e],z.m[e]=function(r){throw delete z.c[e],n}};try{var i=V(r[e])();i.then?n.push(q[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})();
|
|
@@ -48,6 +48,20 @@ interface MarkdownCellMessage {
|
|
|
48
48
|
source: string;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
interface MarkdownCellStreamMessage {
|
|
52
|
+
type:
|
|
53
|
+
| 'markdown_cell_started'
|
|
54
|
+
| 'markdown_cell_updated'
|
|
55
|
+
| 'markdown_cell_finished';
|
|
56
|
+
cell_id: string;
|
|
57
|
+
source: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface MarkdownCellCancelledMessage {
|
|
61
|
+
type: 'markdown_cell_cancelled';
|
|
62
|
+
cell_id: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
51
65
|
interface InstructionsCellMessage {
|
|
52
66
|
type: 'instructions_cell';
|
|
53
67
|
source: string;
|
|
@@ -82,6 +96,8 @@ type CodebindMessage =
|
|
|
82
96
|
| CodeCellOutputMessage
|
|
83
97
|
| CodeCellClearMessage
|
|
84
98
|
| MarkdownCellMessage
|
|
99
|
+
| MarkdownCellStreamMessage
|
|
100
|
+
| MarkdownCellCancelledMessage
|
|
85
101
|
| InstructionsCellMessage
|
|
86
102
|
| QuestionStartedMessage
|
|
87
103
|
| QuestionFinishedMessage
|
|
@@ -151,6 +167,18 @@ function isCodebindMessage(value: unknown): value is CodebindMessage {
|
|
|
151
167
|
) {
|
|
152
168
|
return typeof message.source === 'string';
|
|
153
169
|
}
|
|
170
|
+
if (
|
|
171
|
+
message.type === 'markdown_cell_started' ||
|
|
172
|
+
message.type === 'markdown_cell_updated' ||
|
|
173
|
+
message.type === 'markdown_cell_finished'
|
|
174
|
+
) {
|
|
175
|
+
return (
|
|
176
|
+
typeof message.cell_id === 'string' && typeof message.source === 'string'
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
if (message.type === 'markdown_cell_cancelled') {
|
|
180
|
+
return typeof message.cell_id === 'string';
|
|
181
|
+
}
|
|
154
182
|
if (message.type === 'code_cell_started') {
|
|
155
183
|
return (
|
|
156
184
|
typeof message.cell_id === 'string' &&
|
|
@@ -499,6 +527,7 @@ function registerKernel(panel: NotebookPanel): void {
|
|
|
499
527
|
|
|
500
528
|
let turn: TurnState | null = null;
|
|
501
529
|
const codeCells = new Map<string, ICodeCellModel>();
|
|
530
|
+
const markdownCells = new Map<string, ICellModel>();
|
|
502
531
|
|
|
503
532
|
const finishTurn = (): void => {
|
|
504
533
|
if (!turn) {
|
|
@@ -623,6 +652,35 @@ function registerKernel(panel: NotebookPanel): void {
|
|
|
623
652
|
}
|
|
624
653
|
return;
|
|
625
654
|
}
|
|
655
|
+
if (data.type === 'markdown_cell_updated' || data.type === 'markdown_cell_finished') {
|
|
656
|
+
const model = markdownCells.get(data.cell_id);
|
|
657
|
+
if (!model) {
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
model.sharedModel.setSource(normalizeMathDelimiters(data.source));
|
|
661
|
+
const cell = panel.content.widgets.find(widget => widget.model.id === model.id);
|
|
662
|
+
if (cell instanceof MarkdownCell) {
|
|
663
|
+
cell.rendered = true;
|
|
664
|
+
}
|
|
665
|
+
if (data.type === 'markdown_cell_finished') {
|
|
666
|
+
markdownCells.delete(data.cell_id);
|
|
667
|
+
}
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
if (data.type === 'markdown_cell_cancelled') {
|
|
671
|
+
const model = markdownCells.get(data.cell_id);
|
|
672
|
+
markdownCells.delete(data.cell_id);
|
|
673
|
+
if (!model) {
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
const index = panel.content.widgets.findIndex(
|
|
677
|
+
widget => widget.model.id === model.id
|
|
678
|
+
);
|
|
679
|
+
if (index >= 0) {
|
|
680
|
+
panel.content.model?.sharedModel.deleteCell(index);
|
|
681
|
+
}
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
626
684
|
if (data.type === 'code_cell_output') {
|
|
627
685
|
codeCells.get(data.cell_id)?.outputs.add(data.output);
|
|
628
686
|
return;
|
|
@@ -649,13 +707,27 @@ function registerKernel(panel: NotebookPanel): void {
|
|
|
649
707
|
return;
|
|
650
708
|
}
|
|
651
709
|
|
|
710
|
+
let inserted: InsertMessage;
|
|
711
|
+
if (data.type === 'markdown_cell_started') {
|
|
712
|
+
inserted = { type: 'markdown_cell', source: data.source };
|
|
713
|
+
} else if (
|
|
714
|
+
data.type === 'markdown_cell' ||
|
|
715
|
+
data.type === 'code_cell_started'
|
|
716
|
+
) {
|
|
717
|
+
inserted = data;
|
|
718
|
+
} else {
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
652
721
|
beginTurn();
|
|
653
|
-
const model = insertCell(panel,
|
|
722
|
+
const model = insertCell(panel, inserted);
|
|
654
723
|
if (data.type === 'code_cell_started' && model?.type === 'code') {
|
|
655
724
|
const code = model as ICodeCellModel;
|
|
656
725
|
code.executionState = 'running';
|
|
657
726
|
codeCells.set(data.cell_id, code);
|
|
658
727
|
}
|
|
728
|
+
if (data.type === 'markdown_cell_started' && model) {
|
|
729
|
+
markdownCells.set(data.cell_id, model);
|
|
730
|
+
}
|
|
659
731
|
};
|
|
660
732
|
panelState.comm = comm;
|
|
661
733
|
comm.onClose = () => {
|
|
@@ -153,6 +153,53 @@ class JupyterLabBridge:
|
|
|
153
153
|
self._comm.send({"type": "markdown_cell", "source": source})
|
|
154
154
|
return True
|
|
155
155
|
|
|
156
|
+
def start_markdown_cell(self, source: str) -> str | None:
|
|
157
|
+
"""Insert a Markdown cell as soon as assistant text starts streaming."""
|
|
158
|
+
if not self.ready:
|
|
159
|
+
return None
|
|
160
|
+
cell_id = str(uuid4())
|
|
161
|
+
self._comm.send(
|
|
162
|
+
{
|
|
163
|
+
"type": "markdown_cell_started",
|
|
164
|
+
"cell_id": cell_id,
|
|
165
|
+
"source": source,
|
|
166
|
+
}
|
|
167
|
+
)
|
|
168
|
+
return cell_id
|
|
169
|
+
|
|
170
|
+
def update_markdown_cell(self, cell_id: str, source: str) -> bool:
|
|
171
|
+
"""Replace the source of a streaming assistant Markdown cell."""
|
|
172
|
+
if not self.ready:
|
|
173
|
+
return False
|
|
174
|
+
self._comm.send(
|
|
175
|
+
{
|
|
176
|
+
"type": "markdown_cell_updated",
|
|
177
|
+
"cell_id": cell_id,
|
|
178
|
+
"source": source,
|
|
179
|
+
}
|
|
180
|
+
)
|
|
181
|
+
return True
|
|
182
|
+
|
|
183
|
+
def finish_markdown_cell(self, cell_id: str, source: str) -> bool:
|
|
184
|
+
"""Finalize a streaming assistant Markdown cell."""
|
|
185
|
+
if not self.ready:
|
|
186
|
+
return False
|
|
187
|
+
self._comm.send(
|
|
188
|
+
{
|
|
189
|
+
"type": "markdown_cell_finished",
|
|
190
|
+
"cell_id": cell_id,
|
|
191
|
+
"source": source,
|
|
192
|
+
}
|
|
193
|
+
)
|
|
194
|
+
return True
|
|
195
|
+
|
|
196
|
+
def cancel_markdown_cell(self, cell_id: str) -> bool:
|
|
197
|
+
"""Remove assistant Markdown from an interrupted model response."""
|
|
198
|
+
if not self.ready:
|
|
199
|
+
return False
|
|
200
|
+
self._comm.send({"type": "markdown_cell_cancelled", "cell_id": cell_id})
|
|
201
|
+
return True
|
|
202
|
+
|
|
156
203
|
def ensure_instructions_cell(self, source: str) -> bool:
|
|
157
204
|
"""Show the conversation's immutable system instructions in the notebook."""
|
|
158
205
|
if not self.ready:
|
|
@@ -14,12 +14,15 @@ from IPython.core.interactiveshell import InteractiveShell
|
|
|
14
14
|
from langchain_core.language_models import BaseChatModel
|
|
15
15
|
from langchain_core.messages import (
|
|
16
16
|
AIMessage,
|
|
17
|
+
AIMessageChunk,
|
|
17
18
|
BaseMessage,
|
|
18
19
|
HumanMessage,
|
|
19
20
|
SystemMessage,
|
|
20
21
|
ToolMessage,
|
|
22
|
+
message_chunk_to_message,
|
|
21
23
|
messages_from_dict,
|
|
22
24
|
)
|
|
25
|
+
from langchain_core.messages.ai import add_ai_message_chunks
|
|
23
26
|
from langchain_core.runnables import Runnable
|
|
24
27
|
|
|
25
28
|
from .display import display_assistant
|
|
@@ -56,7 +59,7 @@ IPYTHON_TOOL = {
|
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
|
|
59
|
-
def _message_text(message:
|
|
62
|
+
def _message_text(message: BaseMessage) -> str:
|
|
60
63
|
content = message.content
|
|
61
64
|
if isinstance(content, str):
|
|
62
65
|
return content
|
|
@@ -242,6 +245,103 @@ class Session:
|
|
|
242
245
|
for identifier in identifiers:
|
|
243
246
|
self._append_message_sync(self._interrupted_tool_message(identifier), turn_id)
|
|
244
247
|
|
|
248
|
+
def _update_assistant_stream(self, cell_id: str | None, text: str) -> str | None:
|
|
249
|
+
if self.bridge is None or not text:
|
|
250
|
+
return cell_id
|
|
251
|
+
if cell_id is None:
|
|
252
|
+
return self.bridge.start_markdown_cell(text)
|
|
253
|
+
self.bridge.update_markdown_cell(cell_id, text)
|
|
254
|
+
return cell_id
|
|
255
|
+
|
|
256
|
+
def _finish_assistant_stream(self, cell_id: str | None, response: AIMessage) -> None:
|
|
257
|
+
answer = _message_text(response)
|
|
258
|
+
if cell_id is not None and self.bridge is not None:
|
|
259
|
+
self.bridge.finish_markdown_cell(cell_id, answer)
|
|
260
|
+
elif answer:
|
|
261
|
+
self._display_assistant(answer)
|
|
262
|
+
|
|
263
|
+
def _cancel_assistant_stream(self, cell_id: str | None) -> None:
|
|
264
|
+
if cell_id is not None and self.bridge is not None:
|
|
265
|
+
self.bridge.cancel_markdown_cell(cell_id)
|
|
266
|
+
|
|
267
|
+
@staticmethod
|
|
268
|
+
def _completed_stream_message(
|
|
269
|
+
chunk: AIMessageChunk | None,
|
|
270
|
+
response: AIMessage | None,
|
|
271
|
+
) -> AIMessage:
|
|
272
|
+
if response is not None:
|
|
273
|
+
return response
|
|
274
|
+
if chunk is None:
|
|
275
|
+
raise RuntimeError("model stream returned no messages")
|
|
276
|
+
message = message_chunk_to_message(chunk)
|
|
277
|
+
if not isinstance(message, AIMessage):
|
|
278
|
+
raise TypeError("model stream must return an AIMessage")
|
|
279
|
+
return message
|
|
280
|
+
|
|
281
|
+
def _stream_model(
|
|
282
|
+
self,
|
|
283
|
+
bound_model: Runnable[Any, BaseMessage],
|
|
284
|
+
model: BaseChatModel,
|
|
285
|
+
) -> tuple[AIMessage, str | None]:
|
|
286
|
+
aggregate: AIMessageChunk | None = None
|
|
287
|
+
response: AIMessage | None = None
|
|
288
|
+
cell_id: str | None = None
|
|
289
|
+
shown = ""
|
|
290
|
+
try:
|
|
291
|
+
for message in bound_model.stream(self.messages, **self._model_kwargs(model)):
|
|
292
|
+
if isinstance(message, AIMessageChunk):
|
|
293
|
+
aggregate = (
|
|
294
|
+
message
|
|
295
|
+
if aggregate is None
|
|
296
|
+
else add_ai_message_chunks(aggregate, message)
|
|
297
|
+
)
|
|
298
|
+
current = message_chunk_to_message(aggregate)
|
|
299
|
+
elif isinstance(message, AIMessage) and aggregate is None and response is None:
|
|
300
|
+
response = message
|
|
301
|
+
current = message
|
|
302
|
+
else:
|
|
303
|
+
raise TypeError("model stream must return AIMessage chunks")
|
|
304
|
+
text = _message_text(current)
|
|
305
|
+
if text != shown:
|
|
306
|
+
cell_id = self._update_assistant_stream(cell_id, text)
|
|
307
|
+
shown = text
|
|
308
|
+
return self._completed_stream_message(aggregate, response), cell_id
|
|
309
|
+
except BaseException:
|
|
310
|
+
self._cancel_assistant_stream(cell_id)
|
|
311
|
+
raise
|
|
312
|
+
|
|
313
|
+
async def _astream_model(
|
|
314
|
+
self,
|
|
315
|
+
bound_model: Runnable[Any, BaseMessage],
|
|
316
|
+
model: BaseChatModel,
|
|
317
|
+
) -> tuple[AIMessage, str | None]:
|
|
318
|
+
aggregate: AIMessageChunk | None = None
|
|
319
|
+
response: AIMessage | None = None
|
|
320
|
+
cell_id: str | None = None
|
|
321
|
+
shown = ""
|
|
322
|
+
try:
|
|
323
|
+
async for message in bound_model.astream(self.messages, **self._model_kwargs(model)):
|
|
324
|
+
if isinstance(message, AIMessageChunk):
|
|
325
|
+
aggregate = (
|
|
326
|
+
message
|
|
327
|
+
if aggregate is None
|
|
328
|
+
else add_ai_message_chunks(aggregate, message)
|
|
329
|
+
)
|
|
330
|
+
current = message_chunk_to_message(aggregate)
|
|
331
|
+
elif isinstance(message, AIMessage) and aggregate is None and response is None:
|
|
332
|
+
response = message
|
|
333
|
+
current = message
|
|
334
|
+
else:
|
|
335
|
+
raise TypeError("model stream must return AIMessage chunks")
|
|
336
|
+
text = _message_text(current)
|
|
337
|
+
if text != shown:
|
|
338
|
+
cell_id = self._update_assistant_stream(cell_id, text)
|
|
339
|
+
shown = text
|
|
340
|
+
return self._completed_stream_message(aggregate, response), cell_id
|
|
341
|
+
except BaseException:
|
|
342
|
+
self._cancel_assistant_stream(cell_id)
|
|
343
|
+
raise
|
|
344
|
+
|
|
245
345
|
def clear(self) -> None:
|
|
246
346
|
"""Clear conversation history without clearing the shared Python namespace."""
|
|
247
347
|
try:
|
|
@@ -283,20 +383,17 @@ class Session:
|
|
|
283
383
|
self._append_event_sync("turn_started", turn_id=turn_id)
|
|
284
384
|
bound_model = self._bind(model)
|
|
285
385
|
pending_calls: list[str] = []
|
|
386
|
+
assistant_cell_id: str | None = None
|
|
286
387
|
try:
|
|
287
388
|
self._append_notebook_sync(notebook, turn_id)
|
|
288
389
|
self._append_message_sync(HumanMessage(text), turn_id)
|
|
289
390
|
while True:
|
|
290
|
-
response =
|
|
291
|
-
if not isinstance(response, AIMessage):
|
|
292
|
-
raise TypeError("model must return an AIMessage")
|
|
391
|
+
response, assistant_cell_id = self._stream_model(bound_model, model)
|
|
293
392
|
pending_calls = self._ensure_tool_call_ids(response)
|
|
294
393
|
self._append_message_sync(response, turn_id)
|
|
295
394
|
self.last_response = response
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if answer:
|
|
299
|
-
self._display_assistant(answer)
|
|
395
|
+
self._finish_assistant_stream(assistant_cell_id, response)
|
|
396
|
+
assistant_cell_id = None
|
|
300
397
|
if not response.tool_calls:
|
|
301
398
|
self._append_event_sync("turn_finished", turn_id=turn_id, status="completed")
|
|
302
399
|
return
|
|
@@ -312,10 +409,12 @@ class Session:
|
|
|
312
409
|
)
|
|
313
410
|
pending_calls.remove(identifier)
|
|
314
411
|
except KeyboardInterrupt:
|
|
412
|
+
self._cancel_assistant_stream(assistant_cell_id)
|
|
315
413
|
self._seal_interrupted_calls_sync(pending_calls, turn_id)
|
|
316
414
|
self._append_event_sync("turn_finished", turn_id=turn_id, status="cancelled")
|
|
317
415
|
raise
|
|
318
416
|
except Exception:
|
|
417
|
+
self._cancel_assistant_stream(assistant_cell_id)
|
|
319
418
|
self._seal_interrupted_calls_sync(pending_calls, turn_id)
|
|
320
419
|
self._append_event_sync("turn_finished", turn_id=turn_id, status="failed")
|
|
321
420
|
raise
|
|
@@ -337,23 +436,17 @@ class Session:
|
|
|
337
436
|
await self._append_event("turn_started", turn_id=turn_id)
|
|
338
437
|
bound_model = self._bind(model)
|
|
339
438
|
pending_calls: list[str] = []
|
|
439
|
+
assistant_cell_id: str | None = None
|
|
340
440
|
try:
|
|
341
441
|
await self._append_notebook(notebook, turn_id)
|
|
342
442
|
await self._append_message(HumanMessage(text), turn_id)
|
|
343
443
|
while True:
|
|
344
|
-
response = await
|
|
345
|
-
self.messages,
|
|
346
|
-
**self._model_kwargs(model),
|
|
347
|
-
)
|
|
348
|
-
if not isinstance(response, AIMessage):
|
|
349
|
-
raise TypeError("model must return an AIMessage")
|
|
444
|
+
response, assistant_cell_id = await self._astream_model(bound_model, model)
|
|
350
445
|
pending_calls = self._ensure_tool_call_ids(response)
|
|
351
446
|
await self._append_message(response, turn_id)
|
|
352
447
|
self.last_response = response
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
if answer:
|
|
356
|
-
self._display_assistant(answer)
|
|
448
|
+
self._finish_assistant_stream(assistant_cell_id, response)
|
|
449
|
+
assistant_cell_id = None
|
|
357
450
|
if not response.tool_calls:
|
|
358
451
|
await self._append_event("turn_finished", turn_id=turn_id, status="completed")
|
|
359
452
|
return
|
|
@@ -369,12 +462,14 @@ class Session:
|
|
|
369
462
|
)
|
|
370
463
|
pending_calls.remove(identifier)
|
|
371
464
|
except asyncio.CancelledError:
|
|
465
|
+
self._cancel_assistant_stream(assistant_cell_id)
|
|
372
466
|
await asyncio.shield(self._seal_interrupted_calls(pending_calls, turn_id))
|
|
373
467
|
await asyncio.shield(
|
|
374
468
|
self._append_event("turn_finished", turn_id=turn_id, status="cancelled")
|
|
375
469
|
)
|
|
376
470
|
raise
|
|
377
471
|
except Exception:
|
|
472
|
+
self._cancel_assistant_stream(assistant_cell_id)
|
|
378
473
|
await self._seal_interrupted_calls(pending_calls, turn_id)
|
|
379
474
|
await self._append_event("turn_finished", turn_id=turn_id, status="failed")
|
|
380
475
|
raise
|
codebind-0.6.0/data/share/jupyter/labextensions/codebind-jupyterlab/static/590.8d95476143320694.js
DELETED
|
@@ -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),i=n(343),d=n(99),l=n(171);let s="codebind:insert-question",r="codebind:toggle-question-mode",a="codebind:run-question",u="jp-CodebindQuestionCell",c=new WeakMap,m=new WeakMap;function p(e){return 0!==e.runningQuestions.size&&(e.comm?.send({type:"cancel"}),!0)}function f(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 g(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,i]of Object.entries(e))o.startsWith("text/")||"application/json"===o||"application/vnd.jupyter.stdout"===o||"application/vnd.jupyter.stderr"===o?void 0!==i&&(t[o]=i):n.push(o);return n.length>0&&(t.omitted_mime_types=n),t}function b(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 w(e){return e.replace(/(^|[^\\])\\([()[\]])/g,"$1\\\\$2")}function C(e){let t=c.get(e);for(let n of e.content.widgets){let e=f(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 _(e){let t=e.sessionContext.session?.kernel;if(!t)return;let n=c.get(e)??{comm:null,kernel:null,runningQuestions:new Map,questionTimers:new Map,sessionReady:!1,sessionError:null,questionMode:!1,questionButton:null,knownCellIds:new Set(e.content.widgets.map(e=>e.model.id)),pendingQuestionCellIds:new Set};c.set(e,n);n.kernel&&n.kernel!==t&&m.get(n.kernel)?.delete(n),n.kernel=t;let d=m.get(t);if(!d){d=new Set,m.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)p(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,n.sessionError=null;let l=null,s=new Map,r=()=>{if(!l)return;let e=l;l=null,e.parentModel&&null!==e.parentExecutionCount&&(e.parentModel.executionCount=e.parentExecutionCount)};t.registerCommTarget("codebind",(d,a)=>{d.onMsg=a=>{let u=a.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("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)}(u))return;if("conversation_save"===u.type){let t=e.content.model;return t?(t.setMetadata("codebind",u.conversation),void e.context.save().then(()=>{d.send({type:"conversation_saved",request_id:u.request_id,error:null})},e=>{d.send({type:"conversation_saved",request_id:u.request_id,error:String(e)})})):void d.send({type:"conversation_saved",request_id:u.request_id,error:"Notebook model is unavailable."})}if("instructions_cell"===u.type)return void function(e,t){let n=e.content,o=n.model;if(!o)return;let d=!1,l=n.widgets.findIndex(e=>"instructions"===g(e.model));if(l<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"}}}),l=0,d=!0,null!==e){let t=n.widgets.findIndex(t=>t.model.id===e);t>=0&&(n.activeCellIndex=t)}}let s=n.widgets[l];s&&(s.model.sharedModel.getSource()!==t&&(s.model.sharedModel.setSource(t),d=!0),!1!==s.model.getMetadata("editable")&&(d=!0),!1!==s.model.getMetadata("deletable")&&(d=!0),s.model.setMetadata("editable",!1),s.model.setMetadata("deletable",!1),s.model.setMetadata("codebind",{kind:"instructions"}),s.readOnly=!0,s instanceof i.MarkdownCell&&(s.rendered=!0),d&&e.context.save())}(e,u.source);if("session_ready"===u.type){n.sessionReady=null===u.error,n.sessionError=u.error?.message??null,u.error&&(0,o.showErrorMessage)(`Codebind could not load: ${u.error.type}`,u.error.message);return}if("question_started"===u.type){let e=n.questionTimers.get(u.cell_id);void 0!==e&&(window.clearTimeout(e),n.questionTimers.delete(u.cell_id));return}if("question_finished"===u.type){let t=n.questionTimers.get(u.cell_id);void 0!==t&&(window.clearTimeout(t),n.questionTimers.delete(u.cell_id)),n.runningQuestions.delete(u.cell_id),C(e),r(),u.error&&!u.cancelled&&(0,o.showErrorMessage)(`Codebind question: ${u.error.type}`,u.error.message);return}if("code_cell_output"===u.type)return void s.get(u.cell_id)?.outputs.add(u.output);if("code_cell_clear"===u.type)return void s.get(u.cell_id)?.outputs.clear(u.wait);if("code_cell_finished"===u.type){let e=s.get(u.cell_id);if(!e)return;e.outputs.fromJSON(u.outputs),e.executionCount=u.execution_count,e.executionState="idle",l&&null===l.parentExecutionCount&&null!==u.execution_count&&(l.parentExecutionCount=u.execution_count-1);return}(()=>{if(l)return;let n=e.content,o=n.widgets.findIndex(e=>"code"===e.model.type&&"running"===e.model.executionState);l={parentModel:o>=0?n.widgets[o].model:null,parentExecutionCount:null};let i=(e,n)=>{"idle"===n&&(t.statusChanged.disconnect(i),r())};return t.statusChanged.connect(i)})();let c=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 l=n.widgets[d]??null;return l&&(l.readOnly=!0),l instanceof i.MarkdownCell&&(l.rendered=!0),l?.model??null}(e,u);"code_cell_started"===u.type&&c?.type==="code"&&(c.executionState="running",s.set(u.cell_id,c))},n.comm=d,d.onClose=()=>{n.comm===d&&(n.comm=null,n.sessionReady=!1)};let u=e.content.model?.getMetadata("codebind");d.send({type:"ready",conversation:"object"==typeof u&&null!==u?u:null})})}function v(e){let t=e.content,n=t.model;if(!n)return;t.activeCell?"markdown"!==t.activeCell.model.type&&l.NotebookActions.changeCellType(t,"markdown"):(n.sharedModel.insertCell(0,{cell_type:"markdown",source:"",metadata:{}}),t.activeCellIndex=0);let o=t.activeCell;o&&null!==g(o.model)||(o?.model.setMetadata("codebind",{kind:"question",status:"draft"}),o instanceof i.MarkdownCell&&(o.rendered=!1),t.mode="edit",C(e),o?.editor?.focus())}function M(e){let t=c.get(e);if(!t)return;let n=e.content.widgets,o=new Set(n.map(e=>e.model.id)),i=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 i)null===g(e.model)&&t.pendingQuestionCellIds.add(e.model.id);C(e),t.questionMode&&e.content.activeCell&&t.pendingQuestionCellIds.delete(e.content.activeCell.model.id)&&v(e)}function k(e,t){let n=c.get(e);n&&(n.questionMode=t,n.questionMode||n.pendingQuestionCellIds.clear(),n.questionButton&&(n.questionButton.pressed=n.questionMode),n.questionMode&&e.content.activeCell&&null===g(e.content.activeCell.model)&&v(e))}async function h(e){let t=e.content,n=t.activeCell;if(!n||!f(n.model))return;let d=c.get(e);if(!d?.comm)return void await (0,o.showErrorMessage)("Codebind is not connected","Run %load_ext codebind in this kernel before sending a Question cell.");for(let e=0;!d.sessionReady&&!d.sessionError&&d.comm&&e<600;e+=1)await new Promise(e=>window.setTimeout(e,50));if(d.sessionError)return void await (0,o.showErrorMessage)("Codebind could not load",d.sessionError);if(!d.sessionReady)return void await (0,o.showErrorMessage)("Codebind did not finish loading","Reload Codebind and send the Question again.");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 l=n.model.sharedModel.getSource().trim();if(!l)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(l)),n.model.setMetadata("codebind",{kind:"question",status:"sent"}),n.model.setMetadata("editable",!1),n.model.setMetadata("deletable",!1),n.readOnly=!0,C(e),n instanceof i.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,C(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:l,notebook:function(e){let t=[];for(let n of e.content.widgets){if(null!==g(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:[]};if("code"===e){let e=n.model.toJSON();o.execution_count=e.execution_count,o.outputs=e.outputs.map(b)}t.push(o)}return t}(e)})}function q(e,t){let n={comm:null,kernel:null,runningQuestions:new Map,questionTimers:new Map,sessionReady:!1,sessionError:null,questionMode:!1,questionButton:null,knownCellIds:new Set(e.content.widgets.map(e=>e.model.id)),pendingQuestionCellIds:new Set};c.set(e,n);let i=e=>{p(n)&&(e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),window.setTimeout(()=>{n.runningQuestions.size>0&&n.kernel?.interrupt()},500))},d=null,l=()=>{let t=e.toolbar.node.querySelector('[data-command="notebook:interrupt-kernel"]');t!==d&&(d?.removeEventListener("click",i,!0),d=t,d?.addEventListener("click",i,!0))},s=new MutationObserver(l);s.observe(e.toolbar.node,{childList:!0,subtree:!0});let a=new MutationObserver(()=>{window.setTimeout(()=>M(e),0)});a.observe(e.content.node,{childList:!0,subtree:!0}),l(),e.disposed.connect(()=>{for(let e of(s.disconnect(),a.disconnect(),d?.removeEventListener("click",i,!0),n.questionTimers.values()))window.clearTimeout(e);n.questionTimers.clear()});let u=new o.ToolbarButton({label:"Question",tooltip:"Toggle Question mode for the selected and newly created cells",onClick:()=>{k(e,u.pressed),t.commands.notifyCommandChanged(r)}});n.questionButton=u,e.toolbar.insertItem(10,"codebindQuestion",u),e.content.modelContentChanged.connect(()=>{M(e),window.setTimeout(()=>M(e),0)}),e.content.activeCellChanged.connect(()=>M(e)),e.context.ready.then(()=>{e.content.model?.cells.changed.connect(()=>{M(e),window.setTimeout(()=>M(e),0)}),M(e)}),e.sessionContext.ready.then(()=>_(e)),e.sessionContext.kernelChanged.connect(()=>_(e))}let x={id:"codebind-jupyterlab:plugin",description:"Insert Codebind executions as native notebook cells.",autoStart:!0,requires:[l.INotebookTracker],activate:(e,t)=>{e.commands.addCommand(s,{label:"Use Selected Cell as Codebind Question",execute:()=>{let e=t.currentWidget;e&&v(e)}}),e.commands.addCommand(r,{label:"Toggle Codebind Question Mode",isToggled:()=>{let e=t.currentWidget;return!!e&&(c.get(e)?.questionMode??!1)},execute:()=>{let n=t.currentWidget;if(n){let t;(t=c.get(n))&&k(n,!t.questionMode),e.commands.notifyCommandChanged(r)}}}),e.commands.addCommand(a,{label:"Send Codebind Question",isEnabled:()=>{let e=t.currentWidget?.content.activeCell;return!!e&&null!==f(e.model)},execute:async()=>{let e=t.currentWidget;e&&await h(e)}}),e.commands.addKeyBinding({command:a,keys:["Shift Enter"],selector:`.jp-Notebook .${u}`}),e.contextMenu.addItem({command:s,selector:".jp-Notebook .jp-Cell",rank:8}),t.forEach(t=>q(t,e)),t.widgetAdded.connect((t,n)=>q(n,e))}};n.d(t,{},{default:x})}}]);
|
|
File without changes
|
{codebind-0.6.0 → codebind-0.6.1}/data/share/jupyter/labextensions/codebind-jupyterlab/install.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|