"use strict";(self.webpackChunkjupyterlab_codestral=self.webpackChunkjupyterlab_codestral||[]).push([[787],{8787:(e,t,s)=>{s.r(t),s.d(t,{default:()=>C});var i=s(2435),n=s(3495),r=s(4583);class o{constructor(e){this.identifier="Codestral",this.name="Codestral",this._mistralClient=e.mistralClient,this._debouncer=new r.Debouncer((async e=>({items:(await this._mistralClient.completion(e)).choices.map((e=>({insertText:e.message.content})))})),1e3)}async fetch(e,t){const{text:s,offset:i}=e,n={prompt:s.slice(0,i),suffix:s.slice(i),model:"codestral-latest",stream:!1,stop:[]};try{return this._debouncer.invoke(n)}catch(e){return console.error("Error fetching completions",e),{items:[]}}}}var a=s(9596),d=s(1381),c=s(3918),l=s(9180),h=s.n(l),m=s(7262);class g extends a.ChatModel{constructor(e){super(e),this._history={messages:[]},this._mistralClient=e.mistralClient}async addMessage(e){e.id=m.UUID.uuid4();const t={id:e.id,body:e.body,sender:"User",time:Date.now(),type:"msg"};this.messageAdded(t),this._history.messages.push(t);const s=await this._mistralClient.chat({model:"codestral-latest",messages:this._history.messages.map((e=>({role:"User"===e.sender?"user":"assistant",content:e.body})))});if(0===s.choices.length)return!1;const i=s.choices[0].message,n={id:m.UUID.uuid4(),body:i.content,sender:"Codestral",time:Date.now(),type:"msg"};return this.messageAdded(n),!0}async getHistory(){return this._history}dispose(){super.dispose()}messageAdded(e){super.messageAdded(e)}}const u=new(h()),p={id:"jupyterlab-codestral:inline-provider",autoStart:!0,requires:[i.ICompletionProviderManager,n.ISettingRegistry],activate:(e,t,s)=>{const i=new o({mistralClient:u});t.registerInlineProvider(i),s.load(p.id).then((e=>{const t=()=>{const t=e.get("apiKey").composite;u.apiKey=t};e.changed.connect((()=>t())),t()})).catch((e=>{console.error(`Failed to load settings for ${p.id}`,e)}))}},y={id:"jupyterlab-codestral:chat",description:"Codestral chat extension",autoStart:!0,optional:[n.ISettingRegistry,d.IThemeManager],requires:[c.IRenderMimeRegistry],activate:async(e,t,s,i)=>{const n=new g({mistralClient:u});let r=!1;function o(e){r=e.get("sendWithShiftEnter").composite,n.config={sendWithShiftEnter:r}}Promise.all([e.restored,null==s?void 0:s.load(y.id)]).then((([,e])=>{e?(o(e),e.changed.connect(o)):console.warn("The SettingsRegistry is not loaded for the chat extension")})).catch((e=>{console.error(`Something went wrong when reading the settings.\n${e}`)}));let d=null;try{d=(0,a.buildChatSidebar)(n,i,t),d.title.caption="Codestral Chat"}catch(e){d=(0,a.buildErrorWidget)(i)}e.shell.add(d,"left",{rank:2e3}),console.log("Chat extension initialized")}},C=[p,y]}}]);