@capytale/iframe-react 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
- # Capytale iframe React
2
-
3
- Une bibliothèque React pour intégrer une application React à la plateforme Capytale.
4
-
5
- Elle gère la communication entre l'application React et le conteneur Capytale, en utilisant des contrats metaplayer-rpc.
1
+ # Capytale iframe React
2
+
3
+ Une bibliothèque React pour intégrer une application React à la plateforme Capytale.
4
+
5
+ Elle gère la communication entre l'application React et le conteneur Capytale, en utilisant des contrats metaplayer-rpc.
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react/jsx-runtime"),v=require("react");const X=Symbol("Comlink.proxy"),mt=Symbol("Comlink.endpoint"),pt=Symbol("Comlink.releaseProxy"),N=Symbol("Comlink.finalizer"),V=Symbol("Comlink.thrown"),Z=t=>typeof t=="object"&&t!==null||typeof t=="function",Ct={canHandle:t=>Z(t)&&t[X],serialize(t){const{port1:e,port2:n}=new MessageChannel;return z(t,e),[n,[n]]},deserialize(t){return t.start(),nt(t)}},vt={canHandle:t=>Z(t)&&V in t,serialize({value:t}){let e;return t instanceof Error?e={isError:!0,value:{message:t.message,name:t.name,stack:t.stack}}:e={isError:!1,value:t},[e,[]]},deserialize(t){throw t.isError?Object.assign(new Error(t.value.message),t.value):t.value}},tt=new Map([["proxy",Ct],["throw",vt]]);function yt(t,e){for(const n of t)if(e===n||n==="*"||n instanceof RegExp&&n.test(e))return!0;return!1}function z(t,e=globalThis,n=["*"]){e.addEventListener("message",function r(o){if(!o||!o.data)return;if(!yt(n,o.origin)){console.warn(`Invalid origin '${o.origin}' for comlink proxy`);return}const{id:i,type:u,path:c}=Object.assign({path:[]},o.data),f=(o.data.argumentList||[]).map(R);let g;try{const d=c.slice(0,-1).reduce((C,S)=>C[S],t),m=c.reduce((C,S)=>C[S],t);switch(u){case"GET":g=m;break;case"SET":d[c.slice(-1)[0]]=R(o.data.value),g=!0;break;case"APPLY":g=m.apply(d,f);break;case"CONSTRUCT":{const C=new m(...f);g=rt(C)}break;case"ENDPOINT":{const{port1:C,port2:S}=new MessageChannel;z(t,S),g=ht(C,[C])}break;case"RELEASE":g=void 0;break;default:return}}catch(d){g={value:d,[V]:0}}Promise.resolve(g).catch(d=>({value:d,[V]:0})).then(d=>{const[m,C]=$(d);e.postMessage(Object.assign(Object.assign({},m),{id:i}),C),u==="RELEASE"&&(e.removeEventListener("message",r),et(e),N in t&&typeof t[N]=="function"&&t[N]())}).catch(d=>{const[m,C]=$({value:new TypeError("Unserializable return value"),[V]:0});e.postMessage(Object.assign(Object.assign({},m),{id:i}),C)})}),e.start&&e.start()}function St(t){return t.constructor.name==="MessagePort"}function et(t){St(t)&&t.close()}function nt(t,e){const n=new Map;return t.addEventListener("message",function(o){const{data:i}=o;if(!i||!i.id)return;const u=n.get(i.id);if(u)try{u(i)}finally{n.delete(i.id)}}),H(t,n,[],e)}function M(t){if(t)throw new Error("Proxy has been released and is not useable")}function ot(t){return k(t,new Map,{type:"RELEASE"}).then(()=>{et(t)})}const I=new WeakMap,j="FinalizationRegistry"in globalThis&&new FinalizationRegistry(t=>{const e=(I.get(t)||0)-1;I.set(t,e),e===0&&ot(t)});function At(t,e){const n=(I.get(e)||0)+1;I.set(e,n),j&&j.register(t,e,t)}function bt(t){j&&j.unregister(t)}function H(t,e,n=[],r=function(){}){let o=!1;const i=new Proxy(r,{get(u,c){if(M(o),c===pt)return()=>{bt(i),ot(t),e.clear(),o=!0};if(c==="then"){if(n.length===0)return{then:()=>i};const f=k(t,e,{type:"GET",path:n.map(g=>g.toString())}).then(R);return f.then.bind(f)}return H(t,e,[...n,c])},set(u,c,f){M(o);const[g,d]=$(f);return k(t,e,{type:"SET",path:[...n,c].map(m=>m.toString()),value:g},d).then(R)},apply(u,c,f){M(o);const g=n[n.length-1];if(g===mt)return k(t,e,{type:"ENDPOINT"}).then(R);if(g==="bind")return H(t,e,n.slice(0,-1));const[d,m]=U(f);return k(t,e,{type:"APPLY",path:n.map(C=>C.toString()),argumentList:d},m).then(R)},construct(u,c){M(o);const[f,g]=U(c);return k(t,e,{type:"CONSTRUCT",path:n.map(d=>d.toString()),argumentList:f},g).then(R)}});return At(i,t),i}function wt(t){return Array.prototype.concat.apply([],t)}function U(t){const e=t.map($);return[e.map(n=>n[0]),wt(e.map(n=>n[1]))]}const st=new WeakMap;function ht(t,e){return st.set(t,e),t}function rt(t){return Object.assign(t,{[X]:!0})}function Ft(t,e=globalThis,n="*"){return{postMessage:(r,o)=>t.postMessage(r,n,o),addEventListener:e.addEventListener.bind(e),removeEventListener:e.removeEventListener.bind(e)}}function $(t){for(const[e,n]of tt)if(n.canHandle(t)){const[r,o]=n.serialize(t);return[{type:"HANDLER",name:e,value:r},o]}return[{type:"RAW",value:t},st.get(t)||[]]}function R(t){switch(t.type){case"HANDLER":return tt.get(t.name).deserialize(t.value);case"RAW":return t.value}}function k(t,e,n,r){return new Promise(o=>{const i=Et();e.set(i,o),t.start&&t.start(),t.postMessage(Object.assign({id:i},n),r)})}function Et(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function Rt(t,e){return t.length===0?e:`[${t}] ${e}`}function Jt(t,e){let n=!1,r,o,i;function u(d){return Rt(t,d)}let c,f=!1;if(window.parent===window)console.warn(u("Contract link is not supported in standalone mode")),c={ready(){return Promise.resolve()},declare(){return Promise.resolve()},done(){return Promise.resolve()},provide(d,m,C){return Promise.resolve()}};else{const d=Ft(window.parent,void 0,e);z({declare(m){if(r==null)throw new Error(u("No handler for declare"));r(m)},done(){if(o==null)throw new Error(u("No handler for done"));o()},provide(m,C,S){if(i==null)throw new Error(u("No handler for provide"));i(m,C,S)}},d),c=nt(d),f=!0}const g=()=>{if(!n){if(r==null||o==null||i==null)return;n=!0,c.ready()}};return{declare:d=>c.declare(d),done:()=>c.done(),provide:(d,m,C)=>c.provide(d,m,rt(C)),get name(){return t},get isReady(){return f},set onDeclare(d){r=d,g()},set onDone(d){o=d,g()},set onProvide(d){i=d,g()}}}function Tt(t){return function(e){let n,r=!1,o=!1,i,u,c=!1,f=!1,g,d,m,C;function S(){if(i!=null&&i!==0&&u!=null)return u}function F(a){if(i!=null&&u!=null&&!(a>i))return u}function w(){return m??(f?m=Promise.resolve():m=new Promise((a,l)=>{C=a}))}function J(){return g===void 0&&(g={get name(){return e},get version(){return i},get i(){return S()},v:a=>F(a)}),g}function x(){return d===void 0&&(d={get name(){return e},get version(){return f?i:void 0},get i(){return f?S():void 0},v:a=>f?F(a):void 0,get promise(){return i===0?Promise.reject(t("Remote interface not provided")):w().then(()=>{if(i===0)throw new Error(t("Remote interface not provided"));return J()})}}),d}function E(){C!=null&&(C(),C=void 0)}return{get name(){return e},get localVersion(){if(n!=null)return n},set localVersion(a){if(n!=null&&n!==a)throw new Error(t("A different local version is already set"));n=a},get localVersionSent(){return r},set localVersionSent(a){if(!a&&r)throw new Error(t("Local version already notified"));r=a,a&&n===0&&(o=!0)},get localInterfaceSent(){return o},set localInterfaceSent(a){if(n==null)throw new Error(t("Local version not set"));if(!a&&o)throw new Error(t("Local interface already sent."));o=a},get remoteVersion(){if(i!=null)return i},set remoteVersion(a){if(i!=null&&i!==a)throw new Error(t("A different remote version is already set for "+e+`(${i} -> ${a})`));i=a,a===0&&(c=!0)},get remoteVersionReceived(){return i!=null},setRemoteInterface:a=>{if(i==null)throw new Error(t("Remote version not set"));if(i===0){console.warn(t("Remote version is 0, remote interface is ignored."));return}if(c)throw new Error(t("Interface already provided."));u=a,c=!0},get remoteInterfaceReceived(){return c},depGroup:void 0,get isActivable(){return c&&o},get isActivated(){return f},activate(){if(!f){if(!c)throw new Error(t("Remote interface not provided."));if(!o)throw new Error(t("Local interface not sent"));f=!0,E()}},getRemote:()=>J(),getLazyRemote:()=>x(),get activationPromise(){return w()}}}}function kt(t){return function(e,n,r,o){let i=r,u=!1,c=!1;function f(){return e.every(g=>g.remoteVersionReceived&&g.localVersionSent)&&n.every(g=>g.remoteVersionReceived)}return{get isDeclared(){return c},set isDeclared(g){if(!g&&c)throw new Error(t("Factory already declared"));c=g},get isReady(){return f()},get isDone(){return u},get args(){return e},get deps(){return n},invoke(){if(u)throw new Error(t("Factory already invoked"));if(!f())throw new Error(t("Factory is not ready"));let g;o?g=e.map(C=>C.getRemote()):g=e[0].getRemote();let d;const m=n.length>0?n.map(C=>C.getRemote()):null;try{d=m==null?i(g):i(g,m)}catch(C){throw new Error(t("error in factory:"),{cause:C})}if(o||(d=[d]),d.length!=e.length)throw new Error(t("Invalid factory result"));return u=!0,i=null,d}}}}function xt(t){return function(e,n,r,o){let i=n,u=!1;function c(){return e.every(f=>f.isActivated)}return{get isReady(){return c()},get isDone(){return u},get args(){return e},invoke(){if(u||!c()){const d=new Error(t(u?"callback already invoked":"callback parameters are not ready"));throw o?.[1](d),d}const f=r?e.map(d=>d.getRemote()):e[0].getRemote();let g;try{g=i(f)}catch(d){o==null?console.error(t("error in callback:"),d):o[1](d)}finally{u=!0}o?.[0](g)}}}}function it(t,e){return t==null||t.length===0?e:`[${t}] ${e}`}function Lt(t){function e(a){return it(t.name,a)}const n=xt(e),r=Tt(e),o=kt(e),i={},u=[];let c=[],f;const g=()=>(f==null?f=0:f++,f);function d(a){let l=i[a];return l==null&&(l=r(a),l.localVersion==null&&(w&&(l.localVersion=0),J&&(l.localVersionSent=!0)),l.remoteVersion==null&&x&&(l.remoteVersion=0),i[a]=l),l}function m(a){return a.map(d)}function C(...a){const l=g(),p=Array(l).fill(!1);a.forEach(y=>{y.forEach(A=>{A.depGroup!=null&&(p[A.depGroup]=!0),A.depGroup=l})}),Object.values(i).forEach(y=>{y.depGroup!=null&&y.depGroup!==l&&p[y.depGroup]&&(y.depGroup=l)})}t.onDeclare=a=>{const l=m(a.map(p=>p.name));for(let p=0;p<a.length;p++)a[p].version!=null&&(l[p].remoteVersion=a[p].version);C(l),E()},t.onDone=()=>{x||(x=!0,Object.values(i).forEach(a=>{a.remoteVersion==null&&(a.remoteVersion=0)}),E())},t.onProvide=(a,l,p)=>{let y=i[a];if(y==null)throw new Error(e(`Contract not declared : ${a}`));if(y.remoteVersion!=l)throw new Error(e(`Remote declared version ${y.remoteVersion} of contract "${a}" but provided version ${l}.`));if(y.remoteInterfaceReceived)throw new Error(e(`Remote contract "${a}" is already provided.`));y.setRemoteInterface(p),E()};let S=!1,F=!1,w=!1,J=!1,x=!1;async function E(){if(F=!0,!S){for(S=!0;F;){if(F=!1,t.isReady){const a=u.filter(l=>!l.isDeclared);if(a.length>0)for(const l of a){const p=Array(l.args.length+l.deps.length);l.args.forEach((y,A)=>p[A]=y),l.deps.forEach((y,A)=>p[A+l.args.length]=y),await t.declare(p.map(y=>({name:y.name,version:y.localVersion}))),p.forEach(y=>{y.localVersion!=null&&(y.localVersionSent=!0)}),l.isDeclared=!0}}if(t.isReady&&w&&u.every(a=>a.isDeclared)){const a=Object.values(i).filter(l=>!l.localVersionSent&&l.localVersion!=null);if(a.length>0)for(const l of a)await t.declare([{name:l.name,version:l.localVersion}]),l.localVersionSent=!0;J||(J=!0,await t.done())}if(t.isReady){const a=u.filter(l=>!l.isDone&&l.isReady);if(a.length>0)for(const l of a){const p=l.invoke();for(let y=0;y<l.args.length;y++){const A=l.args[y];await t.provide(A.name,A.localVersion,p[y]),A.localInterfaceSent=!0}}}if(f!=null){const a=Array(f+1).fill(null);for(const l in i){const p=i[l];p.depGroup!=null&&(p.isActivable?a[p.depGroup]==null&&!p.isActivated&&(a[p.depGroup]=!0):a[p.depGroup]=!1)}if(a.some(l=>l===!0))for(const l in i){const p=i[l];p.depGroup!=null&&a[p.depGroup]&&p.activate()}}if(t.isReady){const a=c;c=[];const l=[];for(const p of a)!p.isDone&&p.isReady?p.invoke():l.push(p);l.push(...c),c=l}}S=!1}}return{get(a){return d(a)},declareFactory:(a,l,p,y)=>{if(w)throw new Error(e("Cannot declare a factory after done has been set to true."));const A=m(a.map(h=>h.name));{const h=A.filter(O=>O.localVersion!=null);if(h.length>0)throw new Error(e("Cannot declare a factory for already implemented contracts : "+h.map(O=>O.name).join(", ")))}for(let h=0;h<a.length;h++)A[h].localVersion=a[h].version;const T=m(l);C(A,T);const ft=o(A,T,p,y);u.push(ft),E()},declareCallback(a,l,p,y){const A=m(a),T=n(A,l,p,y);!S&&c.length===0&&T.isReady?T.invoke():(c.push(T),E())},get done(){return w},set done(a){if(w){if(!a)throw new Error(e("Cannot set done to false after it has been set to true."))}else a&&(w=!0,Object.values(i).forEach(l=>{l.localVersion==null&&(l.localVersion=0)}),E())}}}const Mt=/^\d+$/;function Gt(t){const[e,n,r]=t.split(":",3);if(n==null||r!=null||!Mt.test(n))return null;const o=parseInt(n);return isNaN(o)||o===0?null:{name:e,version:o}}function Dt(t){const e=Lt(t);function n(r){return it(t.name,r)}return{plug(r,o,i=void 0){if(e.done)throw new Error(n("Cannot plug after plugsDone."));i==null&&(i=o,o=[]);let u=!0;Array.isArray(r)||(r=[r],u=!1);const c=r.map(f=>{const g=Gt(f);if(g==null)throw new Error(n("Invalid contract id : "+f));return g});e.declareFactory(c,o,i,u)},plugsDone(){e.done=!0},use(r,o){let i=!0;Array.isArray(r)||(r=[r],i=!1),e.declareCallback(r,o,i)},exec(r,o){let i=!0;return Array.isArray(r)||(r=[r],i=!1),new Promise((...u)=>{e.declareCallback(r,o,i,u)})},get(r){return r.map(o=>e.get(o).getLazyRemote())}}}const at="app-agent";let q;function Pt(t){return q!=null||(q=Dt(Jt(at,t))),q}console.log(`[${at}@1.0.12] loaded`);const Q=t=>{let e;const n=new Set,r=(g,d)=>{const m=typeof g=="function"?g(e):g;if(!Object.is(m,e)){const C=e;e=d??(typeof m!="object"||m===null)?m:Object.assign({},e,m),n.forEach(S=>S(e,C))}},o=()=>e,c={setState:r,getState:o,getInitialState:()=>f,subscribe:g=>(n.add(g),()=>n.delete(g))},f=e=t(r,o,c);return c},Vt=(t=>t?Q(t):Q),It=t=>t;function jt(t,e=It){const n=v.useSyncExternalStore(t.subscribe,v.useCallback(()=>e(t.getState()),[t,e]),v.useCallback(()=>e(t.getInitialState()),[t,e]));return v.useDebugValue(n),n}const _=t=>{const e=Vt(t),n=r=>jt(e,r);return Object.assign(n,e),n},ct=(t=>t?_(t):_),$t=t=>(e,n,r)=>{const o=r.subscribe;return r.subscribe=((u,c,f)=>{let g=u;if(c){const d=f?.equalityFn||Object.is;let m=u(r.getState());g=C=>{const S=u(C);if(!d(m,S)){const F=m;c(m=S,F)}},f?.fireImmediately&&c(m,m)}return o(g)}),t(e,n,r)},Ot=$t,s=ct()(Ot(t=>({ready:!1,workflow:"current",mode:"assignment",theme:"light",saveCount:0,canSave:!1,afterSaveCount:0,isDirtyCount:0,loadedTextContent:null,loadedJsonContent:null,loadedJsonActivityContent:null,loadedJsonAssignmentContent:null,loadedJsonActivityBinaryData:null,loadedJsonAssignmentBinaryData:null,getTextContentFunction:()=>{throw console.error("[React bindings] getTextContentFunction is not set"),new Error("[React bindings] getTextContentFunction is not set")},getJsonContentFunction:()=>{throw console.error("[React bindings] getJsonContentFunction is not set"),new Error("[React bindings] getJsonContentFunction is not set")},getJsonActivityContentFunction:()=>{throw console.error("[React bindings] getJsonActivityContentFunction is not set"),new Error("[React bindings] getJsonActivityContentFunction is not set")},getJsonAssignmentContentFunction:()=>{throw console.error("[React bindings] getJsonAssignmentContentFunction is not set"),new Error("[React bindings] getJsonAssignmentContentFunction is not set")},getJsonActivitySplitContentFunction:()=>{throw console.error("[React bindings] getJsonActivitySplitContentFunction is not set"),new Error("[React bindings] getJsonActivitySplitContentFunction is not set")},getJsonAssignmentSplitContentFunction:()=>{throw console.error("[React bindings] getJsonAssignmentSplitContentFunction is not set"),new Error("[React bindings] getJsonAssignmentSplitContentFunction is not set")},sidebarActions:{},quickActions:{},activitySettingsCallback:null,llmGetFirstMessageContextFunction:null,setLlmGetFirstMessageContextFunction:e=>{t({llmGetFirstMessageContextFunction:e})},llmGetAllMessagesContextFunction:null,setLlmGetAllMessagesContextFunction:e=>{t({llmGetAllMessagesContextFunction:e})},llmGetAvailableToolsFunction:null,setLlmGetAvailableToolsFunction:e=>{t({llmGetAvailableToolsFunction:e})},llmCallToolFunction:null,setLlmCallToolFunction:e=>{t({llmCallToolFunction:e})},setGetTextContentFunction:e=>{t({getTextContentFunction:e})},llmDescribeToolFunction:null,setLlmDescribeToolFunction:e=>{t({llmDescribeToolFunction:e})},setGetJsonContentFunction:e=>{t({getJsonContentFunction:e})},setGetJsonActivityContentFunction:e=>{t({getJsonActivityContentFunction:e})},setGetJsonAssignmentContentFunction:e=>{t({getJsonAssignmentContentFunction:e})},setGetJsonActivitySplitContentFunction:e=>{t({getJsonActivitySplitContentFunction:e})},setGetJsonAssignmentSplitContentFunction:e=>{t({getJsonAssignmentSplitContentFunction:e})},setSidebarActions:e=>{t({sidebarActions:e})},setQuickActions:e=>{t({quickActions:e})},setActivitySettingsCallback:e=>{t({activitySettingsCallback:e})},incSaveCount:()=>t(e=>({saveCount:e.saveCount+1})),incDirtyCount:()=>t(e=>({isDirtyCount:e.isDirtyCount+1}))})));let Y=!1;const Nt=["meta-player-events:1","meta-player-ui:1","mode:1","reload:1","theme:1","workflow:1","trigger-save:1","simple-content(text):1","simple-content(json):1","simple-binary-data(text):1","simple-content-eval(text):1","simple-content-eval(json):1","separate-contents(json):1","separate-dual-contents(json):1","llm:1"],K={"mode:1":{setMode:t=>{s.setState({mode:t})}},"reload:1":{reloaded:t=>{console.log("[React bindings] Reloaded with state:",t),console.error("[React bindings] Not implemented yet")}},"theme:1":{setTheme:t=>{if(t===null){s.setState({theme:null});return}if(t!=="light"&&t!=="dark"){console.warn(`[React bindings] Invalid theme: ${t}. Expected 'light' or 'dark'.`),s.setState({theme:null});return}s.setState({theme:t})}},"workflow:1":{setWorkflow:t=>{s.setState({workflow:t})}},"workflow:2":{setWorkflow:t=>{s.setState({workflow:t})}},"trigger-save:1":{setCanSave(t){s.setState({canSave:t})}},"simple-content(text):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getTextContentFunction(),loadContent:t=>{s.setState({loadedTextContent:t})}},"simple-content(json):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getJsonContentFunction(),loadContent:t=>{s.setState({loadedJsonContent:t})}},"simple-binary-data(text):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getTextContentFunction(),loadContent:t=>{s.setState({loadedTextContent:t})}},"simple-content-eval(text):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getTextContentFunction(),loadContent:t=>{s.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"simple-content-eval(json):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getJsonContentFunction(),loadContent:t=>{s.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(json):2":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getJsonContentFunction(),loadContent:t=>{s.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(text):2":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getTextContentFunction(),loadContent:t=>{s.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"separate-contents(json):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:(t,e)=>{s.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e})},getActivityContent:()=>s.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>s.getState().getJsonAssignmentContentFunction()},"separate-contents-eval(json):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:(t,e)=>{s.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e})},getActivityContent:()=>s.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>s.getState().getJsonAssignmentContentFunction()},"separate-contents-eval(json):2":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:(t,e)=>{s.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e})},getActivityContent:()=>s.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>s.getState().getJsonAssignmentContentFunction()},"separate-dual-contents(json):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:({activityContent:t,assignmentContent:e,activityBinaryData:n,assignmentBinaryData:r})=>{s.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e,loadedJsonActivityBinaryData:n,loadedJsonAssignmentBinaryData:r})},getActivityContentAndData:()=>(console.log("[React bindings] Getting activity content and data"),s.getState().getJsonActivitySplitContentFunction()),getAssignmentContentAndData:()=>(console.log("[React bindings] Getting assignment content and data"),s.getState().getJsonAssignmentSplitContentFunction())},"meta-player-anti-cheat:1":{lock:()=>{},unlock:()=>{}},"meta-player-ui:1":{executeAction(t){if(console.log("[React bindings] Executing action:",t),t.startsWith("qa")){const n=s.getState().quickActions[t];n?n():console.error(`[React bindings] Quick action not found: ${t}`)}else{const n=s.getState().sidebarActions[t];n?n():console.error(`[React bindings] Sidebar action not found: ${t}`)}},executeFileUpload(t,e){if(t.startsWith("qa")){const r=s.getState().quickActions[t];r?r(e):console.error(`[React bindings] Quick action not found: ${t}`)}else{const r=s.getState().sidebarActions[t];r?r(e):console.error(`[React bindings] Sidebar action not found: ${t}`)}},updateSettings(t){const e=s.getState().activitySettingsCallback;e?e(t):console.warn("activitySettingsCallback is not set. Changes:",t)}},"meta-player-events:1":{handleEvent(t){t==="all-loaded"&&s.setState({ready:!0})}},"llm:1":{getFirstMessageContext:t=>{const e=s.getState().llmGetFirstMessageContextFunction;return e?e(t):""},getAllMessagesContext:t=>{const e=s.getState().llmGetAllMessagesContextFunction;return e?e(t):""},getAvailableTools:t=>{const e=s.getState().llmGetAvailableToolsFunction;return e?e(t):[]},callTool:(t,e)=>{const n=s.getState().llmCallToolFunction;if(!n)throw new Error("LLM call tool function is not set");return n(t,e)},getToolCallDescription:(t,e)=>{const n=s.getState().llmDescribeToolFunction;if(!n)throw new Error("LLM describe tool function is not set");return n(t,e)}}},b=Pt();function qt(t){if(console.log("[React bindings] Contracts to plug:",t),Y){console.warn("[React bindings] Contracts have already been plugged. Skipping.");return}Y=!0;for(const e of t){if(!Nt.includes(e)){console.warn(`[React bindings] Contract ${e} is not implemented in Capytale. Skipping plug.`);continue}if(!(e in K)){console.warn(`[React bindings] Contract handler for ${e} is not defined. Skipping plug.`);continue}const n=K[e];console.log(`[React bindings] Plugging contract ${e}...`),b.plug([e],([])=>(console.log(`[React bindings] Contract ${e} plugged.`),[n]))}b.plugsDone();for(const e of["simple-content(text):1","simple-content(json):1","simple-binary-data(text):1","simple-content-eval(text):1","simple-content-eval(json):1","simple-content-eval(json):2","simple-content-eval(text):2","separate-contents(json):1","separate-dual-contents(json):1"])if(console.log(`[React bindings] Contract ${e} is being subscribed to content changes.`),t.includes(e)){console.log(`[React bindings] Subscribing to content changes for contract ${e}`);const n=e.split(":")[0];b.use([n],([r])=>{s.subscribe(o=>o.isDirtyCount,()=>{r.i?.contentChanged(),console.log(`[React bindings] Content changed for contract ${n}`)})})}}const Bt=()=>s(t=>{if(t.mode===null)throw new Error("Mode is not set. Have you used contract 'mode'?");return t.mode}),Wt=()=>s(t=>{if(t.workflow===null)throw new Error("Workflow is not set. Have you used contract 'workflow'?");return t.workflow}),Ht=()=>s(t=>{if(t.theme===null)throw new Error("Theme is not set. Have you used contract 'theme'?");return t.theme}),zt=()=>s(t=>t.incSaveCount),Ut=()=>s(t=>t.incDirtyCount),Qt=()=>s(t=>t.loadedTextContent),_t=()=>s(t=>t.loadedJsonContent),Yt=()=>s(t=>t.loadedJsonActivityContent),Kt=()=>s(t=>t.loadedJsonAssignmentContent),Xt=()=>s(t=>t.loadedJsonActivityBinaryData),Zt=()=>s(t=>t.loadedJsonAssignmentBinaryData),te=()=>v.useCallback(()=>s.getState().loadedTextContent,[]),ee=()=>v.useCallback(()=>s.getState().loadedJsonContent,[]),ne=()=>v.useCallback(()=>s.getState().loadedJsonActivityContent,[]),oe=()=>v.useCallback(()=>s.getState().loadedJsonAssignmentContent,[]),se=()=>v.useCallback(()=>({content:s.getState().loadedJsonActivityContent,binaryData:s.getState().loadedJsonActivityBinaryData}),[]),re=()=>v.useCallback(()=>({content:s.getState().loadedJsonAssignmentContent,binaryData:s.getState().loadedJsonAssignmentBinaryData}),[]),ie=t=>{const e=s(n=>n.setGetTextContentFunction);v.useEffect(()=>{e(t)},[t,e])},ae=t=>{const e=s(n=>n.setGetJsonContentFunction);v.useEffect(()=>{e(t)},[t,e])},ce=t=>{const e=s(n=>n.setGetJsonActivityContentFunction);v.useEffect(()=>{e(t)},[t,e])},le=t=>{const e=s(n=>n.setGetJsonAssignmentContentFunction);v.useEffect(()=>{e(t)},[t,e])},ue=t=>{const e=s(n=>n.setGetJsonActivitySplitContentFunction);v.useEffect(()=>{e(t)},[t,e])},de=t=>{const e=s(n=>n.setGetJsonAssignmentSplitContentFunction);v.useEffect(()=>{e(t)},[t,e])},ge=t=>{const e=s(n=>n.afterSaveCount);v.useEffect(()=>{e>0&&t()},[e])},fe=()=>(t,e)=>{b.use(["meta-player-ui"],([n])=>{if(n.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}n.i?.previewTextFile(t,e)})},me=()=>(t,e)=>{b.use(["meta-player-ui"],([n])=>{if(n.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}n.i?.previewImageFile(t,e)})};let G=0,B=0;const pe=(t,e)=>{const n=v.useMemo(t,e),r=s(o=>o.setSidebarActions);v.useEffect(()=>(G++,G>1&&console.error("[React bindings] Capytale iframe React: Multiple sidebar actions registered: ",G),()=>{G--}),[]),v.useEffect(()=>(b.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}B++;const i=n.map((c,f)=>({type:c.type,title:c.title,icon:c.icon,id:`sa-${B}-${f}`,...c.type==="file-upload"?{accept:c.accept}:{}})),u={};n.forEach((c,f)=>{u[`sa-${B}-${f}`]=c.action}),o.i?.setSidebarActionButtons(i),r(u)}),()=>{r({}),b.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}o.i?.setSidebarActionButtons([])})}),[n])};let D=0,W=0;const Ce=(t,e)=>{const n=v.useMemo(t,e),r=s(o=>o.setQuickActions);v.useEffect(()=>(D++,D>1&&console.error("[React bindings] Capytale iframe React: Multiple quick actions registered: ",D),()=>{D--}),[]),v.useEffect(()=>(b.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}W++;const i=n.map((c,f)=>({type:c.type,title:c.title,icon:c.icon,id:`qa-${W}-${f}`,...c.type==="file-upload"?{accept:c.accept}:{}})),u={};n.forEach((c,f)=>{u[`qa-${W}-${f}`]=c.action}),o.i?.setQuickActionButtons(i),r(u)}),()=>{r({}),b.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}o.i?.setQuickActionButtons([])})}),[n])};let P=0;const lt=(t,e,n)=>{const r=v.useMemo(t,n),o=s(i=>i.setActivitySettingsCallback);v.useEffect(()=>(console.log("[React bindings] Mounting useSettings"),P++,P>1&&console.error("[React bindings] Capytale iframe React: Multiple settings registered: ",P),()=>{console.log("[React bindings] Unmounting useSettings"),P--}),[]),v.useEffect(()=>(b.use(["meta-player-ui"],([i])=>{if(i.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}console.log("[React bindings] Updating settings UI in MetaPlayer",r),i.i?.setSettingsUI(r)}),o(e),()=>{o(null)}),[r])},ut=()=>v.useCallback(e=>b.exec(["meta-player-ui"],([n])=>{if(n.version===0)throw console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui"),new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return n.i?.showToast(e)}),[]),dt=()=>v.useCallback(e=>b.exec(["meta-player-ui"],([n])=>{if(n.version===0)throw console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui"),new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return n.i?.clearToast(e)}),[]),ve=()=>v.useCallback(()=>b.exec(["meta-player-ui"],([e])=>{if(e.version===0)throw console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui"),new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return e.i?.clearToasts()}),[]),gt=(t,e)=>{const n=ut(),r=dt();return v.useEffect(()=>{if(t==null)return;const o=n(t);return()=>{o.then(i=>{i!=null&&r(i)})}},[n,r,...e]),null},ye=()=>v.useCallback(()=>b.exec(["trigger-save"],([e])=>{if(e.version===0)throw console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat trigger-save"),new Error("Le MétaPlayer ne supporte pas le contrat trigger-save");return e.i?.triggerSave()}),[]),Se=()=>s(t=>t.canSave),Ae=(t,e)=>{const n=s(r=>r.setLlmGetFirstMessageContextFunction);v.useEffect(()=>(n(t),()=>{n(null)}),[e,n])},be=(t,e)=>{const n=s(r=>r.setLlmGetAllMessagesContextFunction);v.useEffect(()=>(n(t),()=>{n(null)}),[e,n])},we=(t,e,n,r)=>{const o=s(c=>c.setLlmGetAvailableToolsFunction),i=s(c=>c.setLlmCallToolFunction),u=s(c=>c.setLlmDescribeToolFunction);v.useEffect(()=>(o(t),i(e),u(n),()=>{o(null),i(null),u(null)}),[r,o,i,u])};function he(t){const e={};for(const n of t.fields)e[n.name]=n.defaultValue;return e}function Fe(t){return{[t.name]:t.defaultValues}}function Ee(t){return{[t.name]:t.defaultValue}}function Re(t){switch(t.type){case"form":return he(t);case"checkboxes":case"switches":return Fe(t);case"radio":return Ee(t);default:return{}}}function Je(t){const e={};for(const n of t)Object.assign(e,Re(n));return e}function Te(t){const n=ct()(r=>({...Je(t)}));return n.activitySettings=t,n}function ke(t){lt(()=>t.activitySettings,e=>{t.setState(e)},[])}function xe({store:t}){return ke(t),null}const Le=["meta-player-events:1","meta-player-ui:1","mode:1","workflow:1"];function Me({children:t,contracts:e,loadOnlyWhenReady:n=!0,activitySettingsStore:r}){const o=s(i=>i.ready);return v.useEffect(()=>{const i=[...e];for(const u of Le)i.includes(u)||i.push(u);qt(i)},[]),n&&!o?L.jsx("div",{className:"capy-loading-container",children:"Chargement en cours..."}):L.jsxs(L.Fragment,{children:[r&&L.jsx(xe,{store:r}),t]})}function Ge({message:t}){return gt(t,[t]),null}exports.Capytale=Me;exports.TemporaryToast=Ge;exports.createActivitySettingsStore=Te;exports.useAfterSaveAction=ge;exports.useCanSave=Se;exports.useClearToast=dt;exports.useClearToasts=ve;exports.useGetLoadedJsonActivityContent=ne;exports.useGetLoadedJsonActivitySplitContent=se;exports.useGetLoadedJsonAssignmentContent=oe;exports.useGetLoadedJsonAssignmentSplitContent=re;exports.useGetLoadedJsonContent=ee;exports.useGetLoadedTextContent=te;exports.useJsonActivityContentSaveFunction=ce;exports.useJsonActivitySplitContentSaveFunction=ue;exports.useJsonAssignmentContentSaveFunction=le;exports.useJsonAssignmentSplitContentSaveFunction=de;exports.useJsonContentSaveFunction=ae;exports.useLLMAllMessagesContext=be;exports.useLLMFirstMessageContext=Ae;exports.useLLMTools=we;exports.useLoadedJsonActivityBinaryData=Xt;exports.useLoadedJsonActivityContent=Yt;exports.useLoadedJsonAssignmentBinaryData=Zt;exports.useLoadedJsonAssignmentContent=Kt;exports.useLoadedJsonContent=_t;exports.useLoadedTextContent=Qt;exports.useMode=Bt;exports.useNotifyIsDirty=Ut;exports.usePreviewImageFile=me;exports.usePreviewTextFile=fe;exports.useQuickActions=Ce;exports.useRequestSave=zt;exports.useSettings=lt;exports.useShowToast=ut;exports.useSidebarActions=pe;exports.useTextContentSaveFunction=ie;exports.useTheme=Ht;exports.useToast=gt;exports.useTriggerSave=ye;exports.useWorkflow=Wt;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react/jsx-runtime"),v=require("react");const X=Symbol("Comlink.proxy"),mt=Symbol("Comlink.endpoint"),Ct=Symbol("Comlink.releaseProxy"),N=Symbol("Comlink.finalizer"),V=Symbol("Comlink.thrown"),Z=t=>typeof t=="object"&&t!==null||typeof t=="function",pt={canHandle:t=>Z(t)&&t[X],serialize(t){const{port1:e,port2:n}=new MessageChannel;return z(t,e),[n,[n]]},deserialize(t){return t.start(),nt(t)}},vt={canHandle:t=>Z(t)&&V in t,serialize({value:t}){let e;return t instanceof Error?e={isError:!0,value:{message:t.message,name:t.name,stack:t.stack}}:e={isError:!1,value:t},[e,[]]},deserialize(t){throw t.isError?Object.assign(new Error(t.value.message),t.value):t.value}},tt=new Map([["proxy",pt],["throw",vt]]);function yt(t,e){for(const n of t)if(e===n||n==="*"||n instanceof RegExp&&n.test(e))return!0;return!1}function z(t,e=globalThis,n=["*"]){e.addEventListener("message",function i(o){if(!o||!o.data)return;if(!yt(n,o.origin)){console.warn(`Invalid origin '${o.origin}' for comlink proxy`);return}const{id:s,type:u,path:l}=Object.assign({path:[]},o.data),g=(o.data.argumentList||[]).map(J);let f;try{const d=l.slice(0,-1).reduce((p,S)=>p[S],t),m=l.reduce((p,S)=>p[S],t);switch(u){case"GET":f=m;break;case"SET":d[l.slice(-1)[0]]=J(o.data.value),f=!0;break;case"APPLY":f=m.apply(d,g);break;case"CONSTRUCT":{const p=new m(...g);f=st(p)}break;case"ENDPOINT":{const{port1:p,port2:S}=new MessageChannel;z(t,S),f=ht(p,[p])}break;case"RELEASE":f=void 0;break;default:return}}catch(d){f={value:d,[V]:0}}Promise.resolve(f).catch(d=>({value:d,[V]:0})).then(d=>{const[m,p]=O(d);e.postMessage(Object.assign(Object.assign({},m),{id:s}),p),u==="RELEASE"&&(e.removeEventListener("message",i),et(e),N in t&&typeof t[N]=="function"&&t[N]())}).catch(d=>{const[m,p]=O({value:new TypeError("Unserializable return value"),[V]:0});e.postMessage(Object.assign(Object.assign({},m),{id:s}),p)})}),e.start&&e.start()}function St(t){return t.constructor.name==="MessagePort"}function et(t){St(t)&&t.close()}function nt(t,e){const n=new Map;return t.addEventListener("message",function(o){const{data:s}=o;if(!s||!s.id)return;const u=n.get(s.id);if(u)try{u(s)}finally{n.delete(s.id)}}),H(t,n,[],e)}function M(t){if(t)throw new Error("Proxy has been released and is not useable")}function ot(t){return k(t,new Map,{type:"RELEASE"}).then(()=>{et(t)})}const j=new WeakMap,I="FinalizationRegistry"in globalThis&&new FinalizationRegistry(t=>{const e=(j.get(t)||0)-1;j.set(t,e),e===0&&ot(t)});function At(t,e){const n=(j.get(e)||0)+1;j.set(e,n),I&&I.register(t,e,t)}function wt(t){I&&I.unregister(t)}function H(t,e,n=[],i=function(){}){let o=!1;const s=new Proxy(i,{get(u,l){if(M(o),l===Ct)return()=>{wt(s),ot(t),e.clear(),o=!0};if(l==="then"){if(n.length===0)return{then:()=>s};const g=k(t,e,{type:"GET",path:n.map(f=>f.toString())}).then(J);return g.then.bind(g)}return H(t,e,[...n,l])},set(u,l,g){M(o);const[f,d]=O(g);return k(t,e,{type:"SET",path:[...n,l].map(m=>m.toString()),value:f},d).then(J)},apply(u,l,g){M(o);const f=n[n.length-1];if(f===mt)return k(t,e,{type:"ENDPOINT"}).then(J);if(f==="bind")return H(t,e,n.slice(0,-1));const[d,m]=Q(g);return k(t,e,{type:"APPLY",path:n.map(p=>p.toString()),argumentList:d},m).then(J)},construct(u,l){M(o);const[g,f]=Q(l);return k(t,e,{type:"CONSTRUCT",path:n.map(d=>d.toString()),argumentList:g},f).then(J)}});return At(s,t),s}function bt(t){return Array.prototype.concat.apply([],t)}function Q(t){const e=t.map(O);return[e.map(n=>n[0]),bt(e.map(n=>n[1]))]}const rt=new WeakMap;function ht(t,e){return rt.set(t,e),t}function st(t){return Object.assign(t,{[X]:!0})}function Ft(t,e=globalThis,n="*"){return{postMessage:(i,o)=>t.postMessage(i,n,o),addEventListener:e.addEventListener.bind(e),removeEventListener:e.removeEventListener.bind(e)}}function O(t){for(const[e,n]of tt)if(n.canHandle(t)){const[i,o]=n.serialize(t);return[{type:"HANDLER",name:e,value:i},o]}return[{type:"RAW",value:t},rt.get(t)||[]]}function J(t){switch(t.type){case"HANDLER":return tt.get(t.name).deserialize(t.value);case"RAW":return t.value}}function k(t,e,n,i){return new Promise(o=>{const s=Et();e.set(s,o),t.start&&t.start(),t.postMessage(Object.assign({id:s},n),i)})}function Et(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function Jt(t,e){return t.length===0?e:`[${t}] ${e}`}function Tt(t,e){let n=!1,i,o,s;function u(d){return Jt(t,d)}let l,g=!1;if(window.parent===window)console.warn(u("Contract link is not supported in standalone mode")),l={ready(){return Promise.resolve()},declare(){return Promise.resolve()},done(){return Promise.resolve()},provide(d,m,p){return Promise.resolve()}};else{const d=Ft(window.parent,void 0,e);z({declare(m){if(i==null)throw new Error(u("No handler for declare"));i(m)},done(){if(o==null)throw new Error(u("No handler for done"));o()},provide(m,p,S){if(s==null)throw new Error(u("No handler for provide"));s(m,p,S)}},d),l=nt(d),g=!0}const f=()=>{if(!n){if(i==null||o==null||s==null)return;n=!0,l.ready()}};return{declare:d=>l.declare(d),done:()=>l.done(),provide:(d,m,p)=>l.provide(d,m,st(p)),get name(){return t},get isReady(){return g},set onDeclare(d){i=d,f()},set onDone(d){o=d,f()},set onProvide(d){s=d,f()}}}function Rt(t){return function(e){let n,i=!1,o=!1,s,u,l=!1,g=!1,f,d,m,p;function S(){if(s!=null&&s!==0&&u!=null)return u}function F(a){if(s!=null&&u!=null&&!(a>s))return u}function b(){return m??(g?m=Promise.resolve():m=new Promise((a,c)=>{p=a}))}function T(){return f===void 0&&(f={get name(){return e},get version(){return s},get i(){return S()},v:a=>F(a)}),f}function x(){return d===void 0&&(d={get name(){return e},get version(){return g?s:void 0},get i(){return g?S():void 0},v:a=>g?F(a):void 0,get promise(){return s===0?Promise.reject(t("Remote interface not provided")):b().then(()=>{if(s===0)throw new Error(t("Remote interface not provided"));return T()})}}),d}function E(){p!=null&&(p(),p=void 0)}return{get name(){return e},get localVersion(){if(n!=null)return n},set localVersion(a){if(n!=null&&n!==a)throw new Error(t("A different local version is already set"));n=a},get localVersionSent(){return i},set localVersionSent(a){if(!a&&i)throw new Error(t("Local version already notified"));i=a,a&&n===0&&(o=!0)},get localInterfaceSent(){return o},set localInterfaceSent(a){if(n==null)throw new Error(t("Local version not set"));if(!a&&o)throw new Error(t("Local interface already sent."));o=a},get remoteVersion(){if(s!=null)return s},set remoteVersion(a){if(s!=null&&s!==a)throw new Error(t("A different remote version is already set for "+e+`(${s} -> ${a})`));s=a,a===0&&(l=!0)},get remoteVersionReceived(){return s!=null},setRemoteInterface:a=>{if(s==null)throw new Error(t("Remote version not set"));if(s===0){console.warn(t("Remote version is 0, remote interface is ignored."));return}if(l)throw new Error(t("Interface already provided."));u=a,l=!0},get remoteInterfaceReceived(){return l},depGroup:void 0,get isActivable(){return l&&o},get isActivated(){return g},activate(){if(!g){if(!l)throw new Error(t("Remote interface not provided."));if(!o)throw new Error(t("Local interface not sent"));g=!0,E()}},getRemote:()=>T(),getLazyRemote:()=>x(),get activationPromise(){return b()}}}}function kt(t){return function(e,n,i,o){let s=i,u=!1,l=!1;function g(){return e.every(f=>f.remoteVersionReceived&&f.localVersionSent)&&n.every(f=>f.remoteVersionReceived)}return{get isDeclared(){return l},set isDeclared(f){if(!f&&l)throw new Error(t("Factory already declared"));l=f},get isReady(){return g()},get isDone(){return u},get args(){return e},get deps(){return n},invoke(){if(u)throw new Error(t("Factory already invoked"));if(!g())throw new Error(t("Factory is not ready"));let f;o?f=e.map(p=>p.getRemote()):f=e[0].getRemote();let d;const m=n.length>0?n.map(p=>p.getRemote()):null;try{d=m==null?s(f):s(f,m)}catch(p){throw new Error(t("error in factory:"),{cause:p})}if(o||(d=[d]),d.length!=e.length)throw new Error(t("Invalid factory result"));return u=!0,s=null,d}}}}function xt(t){return function(e,n,i,o){let s=n,u=!1;function l(){return e.every(g=>g.isActivated)}return{get isReady(){return l()},get isDone(){return u},get args(){return e},invoke(){if(u||!l()){const d=new Error(t(u?"callback already invoked":"callback parameters are not ready"));throw o?.[1](d),d}const g=i?e.map(d=>d.getRemote()):e[0].getRemote();let f;try{f=s(g)}catch(d){o==null?console.error(t("error in callback:"),d):o[1](d)}finally{u=!0}o?.[0](f)}}}}function it(t,e){return t==null||t.length===0?e:`[${t}] ${e}`}function Lt(t){function e(a){return it(t.name,a)}const n=xt(e),i=Rt(e),o=kt(e),s={},u=[];let l=[],g;const f=()=>(g==null?g=0:g++,g);function d(a){let c=s[a];return c==null&&(c=i(a),c.localVersion==null&&(b&&(c.localVersion=0),T&&(c.localVersionSent=!0)),c.remoteVersion==null&&x&&(c.remoteVersion=0),s[a]=c),c}function m(a){return a.map(d)}function p(...a){const c=f(),C=Array(c).fill(!1);a.forEach(y=>{y.forEach(A=>{A.depGroup!=null&&(C[A.depGroup]=!0),A.depGroup=c})}),Object.values(s).forEach(y=>{y.depGroup!=null&&y.depGroup!==c&&C[y.depGroup]&&(y.depGroup=c)})}t.onDeclare=a=>{const c=m(a.map(C=>C.name));for(let C=0;C<a.length;C++)a[C].version!=null&&(c[C].remoteVersion=a[C].version);p(c),E()},t.onDone=()=>{x||(x=!0,Object.values(s).forEach(a=>{a.remoteVersion==null&&(a.remoteVersion=0)}),E())},t.onProvide=(a,c,C)=>{let y=s[a];if(y==null)throw new Error(e(`Contract not declared : ${a}`));if(y.remoteVersion!=c)throw new Error(e(`Remote declared version ${y.remoteVersion} of contract "${a}" but provided version ${c}.`));if(y.remoteInterfaceReceived)throw new Error(e(`Remote contract "${a}" is already provided.`));y.setRemoteInterface(C),E()};let S=!1,F=!1,b=!1,T=!1,x=!1;async function E(){if(F=!0,!S){for(S=!0;F;){if(F=!1,t.isReady){const a=u.filter(c=>!c.isDeclared);if(a.length>0)for(const c of a){const C=Array(c.args.length+c.deps.length);c.args.forEach((y,A)=>C[A]=y),c.deps.forEach((y,A)=>C[A+c.args.length]=y),await t.declare(C.map(y=>({name:y.name,version:y.localVersion}))),C.forEach(y=>{y.localVersion!=null&&(y.localVersionSent=!0)}),c.isDeclared=!0}}if(t.isReady&&b&&u.every(a=>a.isDeclared)){const a=Object.values(s).filter(c=>!c.localVersionSent&&c.localVersion!=null);if(a.length>0)for(const c of a)await t.declare([{name:c.name,version:c.localVersion}]),c.localVersionSent=!0;T||(T=!0,await t.done())}if(t.isReady){const a=u.filter(c=>!c.isDone&&c.isReady);if(a.length>0)for(const c of a){const C=c.invoke();for(let y=0;y<c.args.length;y++){const A=c.args[y];await t.provide(A.name,A.localVersion,C[y]),A.localInterfaceSent=!0}}}if(g!=null){const a=Array(g+1).fill(null);for(const c in s){const C=s[c];C.depGroup!=null&&(C.isActivable?a[C.depGroup]==null&&!C.isActivated&&(a[C.depGroup]=!0):a[C.depGroup]=!1)}if(a.some(c=>c===!0))for(const c in s){const C=s[c];C.depGroup!=null&&a[C.depGroup]&&C.activate()}}if(t.isReady){const a=l;l=[];const c=[];for(const C of a)!C.isDone&&C.isReady?C.invoke():c.push(C);c.push(...l),l=c}}S=!1}}return{get(a){return d(a)},declareFactory:(a,c,C,y)=>{if(b)throw new Error(e("Cannot declare a factory after done has been set to true."));const A=m(a.map(h=>h.name));{const h=A.filter($=>$.localVersion!=null);if(h.length>0)throw new Error(e("Cannot declare a factory for already implemented contracts : "+h.map($=>$.name).join(", ")))}for(let h=0;h<a.length;h++)A[h].localVersion=a[h].version;const R=m(c);p(A,R);const gt=o(A,R,C,y);u.push(gt),E()},declareCallback(a,c,C,y){const A=m(a),R=n(A,c,C,y);!S&&l.length===0&&R.isReady?R.invoke():(l.push(R),E())},get done(){return b},set done(a){if(b){if(!a)throw new Error(e("Cannot set done to false after it has been set to true."))}else a&&(b=!0,Object.values(s).forEach(c=>{c.localVersion==null&&(c.localVersion=0)}),E())}}}const Mt=/^\d+$/;function Gt(t){const[e,n,i]=t.split(":",3);if(n==null||i!=null||!Mt.test(n))return null;const o=parseInt(n);return isNaN(o)||o===0?null:{name:e,version:o}}function Dt(t){const e=Lt(t);function n(i){return it(t.name,i)}return{plug(i,o,s=void 0){if(e.done)throw new Error(n("Cannot plug after plugsDone."));s==null&&(s=o,o=[]);let u=!0;Array.isArray(i)||(i=[i],u=!1);const l=i.map(g=>{const f=Gt(g);if(f==null)throw new Error(n("Invalid contract id : "+g));return f});e.declareFactory(l,o,s,u)},plugsDone(){e.done=!0},use(i,o){let s=!0;Array.isArray(i)||(i=[i],s=!1),e.declareCallback(i,o,s)},exec(i,o){let s=!0;return Array.isArray(i)||(i=[i],s=!1),new Promise((...u)=>{e.declareCallback(i,o,s,u)})},get(i){return i.map(o=>e.get(o).getLazyRemote())}}}const at="app-agent";let q;function Pt(t){return q!=null||(q=Dt(Tt(at,t))),q}console.log(`[${at}@1.0.12] loaded`);const _=t=>{let e;const n=new Set,i=(f,d)=>{const m=typeof f=="function"?f(e):f;if(!Object.is(m,e)){const p=e;e=d??(typeof m!="object"||m===null)?m:Object.assign({},e,m),n.forEach(S=>S(e,p))}},o=()=>e,l={setState:i,getState:o,getInitialState:()=>g,subscribe:f=>(n.add(f),()=>n.delete(f))},g=e=t(i,o,l);return l},Vt=(t=>t?_(t):_),jt=t=>t;function It(t,e=jt){const n=v.useSyncExternalStore(t.subscribe,v.useCallback(()=>e(t.getState()),[t,e]),v.useCallback(()=>e(t.getInitialState()),[t,e]));return v.useDebugValue(n),n}const U=t=>{const e=Vt(t),n=i=>It(e,i);return Object.assign(n,e),n},lt=(t=>t?U(t):U),Ot=t=>(e,n,i)=>{const o=i.subscribe;return i.subscribe=((u,l,g)=>{let f=u;if(l){const d=g?.equalityFn||Object.is;let m=u(i.getState());f=p=>{const S=u(p);if(!d(m,S)){const F=m;l(m=S,F)}},g?.fireImmediately&&l(m,m)}return o(f)}),t(e,n,i)},$t=Ot,r=lt()($t(t=>({ready:!1,workflow:"current",mode:"assignment",theme:"light",saveCount:0,canSave:!1,afterSaveCount:0,isDirtyCount:0,loadedTextContent:null,loadedJsonContent:null,loadedJsonActivityContent:null,loadedJsonAssignmentContent:null,loadedJsonActivityBinaryData:null,loadedJsonAssignmentBinaryData:null,getTextContentFunction:()=>{throw console.error("[React bindings] getTextContentFunction is not set"),new Error("[React bindings] getTextContentFunction is not set")},getJsonContentFunction:()=>{throw console.error("[React bindings] getJsonContentFunction is not set"),new Error("[React bindings] getJsonContentFunction is not set")},getJsonActivityContentFunction:()=>{throw console.error("[React bindings] getJsonActivityContentFunction is not set"),new Error("[React bindings] getJsonActivityContentFunction is not set")},getJsonAssignmentContentFunction:()=>{throw console.error("[React bindings] getJsonAssignmentContentFunction is not set"),new Error("[React bindings] getJsonAssignmentContentFunction is not set")},getJsonActivitySplitContentFunction:()=>{throw console.error("[React bindings] getJsonActivitySplitContentFunction is not set"),new Error("[React bindings] getJsonActivitySplitContentFunction is not set")},getJsonAssignmentSplitContentFunction:()=>{throw console.error("[React bindings] getJsonAssignmentSplitContentFunction is not set"),new Error("[React bindings] getJsonAssignmentSplitContentFunction is not set")},sidebarActions:{},quickActions:{},activitySettingsCallback:null,llmGetFirstMessageContextFunction:null,setLlmGetFirstMessageContextFunction:e=>{t({llmGetFirstMessageContextFunction:e})},llmGetAllMessagesContextFunction:null,setLlmGetAllMessagesContextFunction:e=>{t({llmGetAllMessagesContextFunction:e})},llmGetAvailableToolsFunction:null,setLlmGetAvailableToolsFunction:e=>{t({llmGetAvailableToolsFunction:e})},llmCallToolFunction:null,setLlmCallToolFunction:e=>{t({llmCallToolFunction:e})},setGetTextContentFunction:e=>{t({getTextContentFunction:e})},llmDescribeToolFunction:null,setLlmDescribeToolFunction:e=>{t({llmDescribeToolFunction:e})},setGetJsonContentFunction:e=>{t({getJsonContentFunction:e})},setGetJsonActivityContentFunction:e=>{t({getJsonActivityContentFunction:e})},setGetJsonAssignmentContentFunction:e=>{t({getJsonAssignmentContentFunction:e})},setGetJsonActivitySplitContentFunction:e=>{t({getJsonActivitySplitContentFunction:e})},setGetJsonAssignmentSplitContentFunction:e=>{t({getJsonAssignmentSplitContentFunction:e})},setSidebarActions:e=>{t({sidebarActions:e})},setQuickActions:e=>{t({quickActions:e})},setActivitySettingsCallback:e=>{t({activitySettingsCallback:e})},incSaveCount:()=>t(e=>({saveCount:e.saveCount+1})),incDirtyCount:()=>t(e=>({isDirtyCount:e.isDirtyCount+1}))})));let Y=!1;const Nt=["meta-player-events:1","meta-player-ui:1","mode:1","reload:1","theme:1","workflow:1","trigger-save:1","simple-content(text):1","simple-content(json):1","simple-binary-data(text):1","simple-content-eval(text):1","simple-content-eval(json):1","separate-contents(json):1","separate-dual-contents(json):1","llm:1"],K={"mode:1":{setMode:t=>{r.setState({mode:t})}},"reload:1":{reloaded:t=>{console.log("[React bindings] Reloaded with state:",t),console.error("[React bindings] Not implemented yet")}},"theme:1":{setTheme:t=>{if(t===null){r.setState({theme:null});return}if(t!=="light"&&t!=="dark"){console.warn(`[React bindings] Invalid theme: ${t}. Expected 'light' or 'dark'.`),r.setState({theme:null});return}r.setState({theme:t})}},"workflow:1":{setWorkflow:t=>{r.setState({workflow:t})}},"workflow:2":{setWorkflow:t=>{r.setState({workflow:t})}},"trigger-save:1":{setCanSave(t){r.setState({canSave:t})}},"simple-content(text):1":{contentSaved:()=>{r.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>r.getState().getTextContentFunction(),loadContent:t=>{r.setState({loadedTextContent:t})}},"simple-content(json):1":{contentSaved:()=>{r.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>r.getState().getJsonContentFunction(),loadContent:t=>{r.setState({loadedJsonContent:t})}},"simple-binary-data(text):1":{contentSaved:()=>{r.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>r.getState().getTextContentFunction(),loadContent:t=>{r.setState({loadedTextContent:t})}},"simple-content-eval(text):1":{contentSaved:()=>{r.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>r.getState().getTextContentFunction(),loadContent:t=>{r.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"simple-content-eval(json):1":{contentSaved:()=>{r.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>r.getState().getJsonContentFunction(),loadContent:t=>{r.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(json):2":{contentSaved:()=>{r.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>r.getState().getJsonContentFunction(),loadContent:t=>{r.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(text):2":{contentSaved:()=>{r.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>r.getState().getTextContentFunction(),loadContent:t=>{r.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"separate-contents(json):1":{contentSaved:()=>{r.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:(t,e)=>{r.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e})},getActivityContent:()=>r.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>r.getState().getJsonAssignmentContentFunction()},"separate-contents-eval(json):1":{contentSaved:()=>{r.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:(t,e)=>{r.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e})},getActivityContent:()=>r.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>r.getState().getJsonAssignmentContentFunction()},"separate-contents-eval(json):2":{contentSaved:()=>{r.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:(t,e)=>{r.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e})},getActivityContent:()=>r.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>r.getState().getJsonAssignmentContentFunction()},"separate-dual-contents(json):1":{contentSaved:()=>{r.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:({activityContent:t,assignmentContent:e,activityBinaryData:n,assignmentBinaryData:i})=>{r.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e,loadedJsonActivityBinaryData:n,loadedJsonAssignmentBinaryData:i})},getActivityContentAndData:()=>r.getState().getJsonActivitySplitContentFunction(),getAssignmentContentAndData:()=>r.getState().getJsonAssignmentSplitContentFunction()},"meta-player-anti-cheat:1":{lock:()=>{},unlock:()=>{}},"meta-player-ui:1":{executeAction(t){if(t.startsWith("qa")){const n=r.getState().quickActions[t];n?n():console.error(`[React bindings] Quick action not found: ${t}`)}else{const n=r.getState().sidebarActions[t];n?n():console.error(`[React bindings] Sidebar action not found: ${t}`)}},executeFileUpload(t,e){if(t.startsWith("qa")){const i=r.getState().quickActions[t];i?i(e):console.error(`[React bindings] Quick action not found: ${t}`)}else{const i=r.getState().sidebarActions[t];i?i(e):console.error(`[React bindings] Sidebar action not found: ${t}`)}},updateSettings(t){const e=r.getState().activitySettingsCallback;e?e(t):console.warn("activitySettingsCallback is not set. Changes:",t)}},"meta-player-events:1":{handleEvent(t){t==="all-loaded"&&r.setState({ready:!0})}},"llm:1":{getFirstMessageContext:t=>{const e=r.getState().llmGetFirstMessageContextFunction;return e?e(t):""},getAllMessagesContext:t=>{const e=r.getState().llmGetAllMessagesContextFunction;return e?e(t):""},getAvailableTools:t=>{const e=r.getState().llmGetAvailableToolsFunction;return e?e(t):[]},callTool:(t,e)=>{const n=r.getState().llmCallToolFunction;if(!n)throw new Error("LLM call tool function is not set");return n(t,e)},getToolCallDescription:(t,e)=>{const n=r.getState().llmDescribeToolFunction;if(!n)throw new Error("LLM describe tool function is not set");return n(t,e)}}},w=Pt();function qt(t){if(!Y){Y=!0;for(const e of t){if(!Nt.includes(e))continue;if(!(e in K)){console.warn(`[React bindings] Contract handler for ${e} is not defined. Skipping plug.`);continue}const n=K[e];w.plug([e],([])=>[n])}w.plugsDone();for(const e of["simple-content(text):1","simple-content(json):1","simple-binary-data(text):1","simple-content-eval(text):1","simple-content-eval(json):1","simple-content-eval(json):2","simple-content-eval(text):2","separate-contents(json):1","separate-dual-contents(json):1"])if(t.includes(e)){const n=e.split(":")[0];w.use([n],([i])=>{r.subscribe(o=>o.isDirtyCount,()=>{i.i?.contentChanged()})})}}}const Bt=()=>r(t=>{if(t.mode===null)throw new Error("Mode is not set. Have you used contract 'mode'?");return t.mode}),Wt=()=>r(t=>{if(t.workflow===null)throw new Error("Workflow is not set. Have you used contract 'workflow'?");return t.workflow}),Ht=()=>r(t=>{if(t.theme===null)throw new Error("Theme is not set. Have you used contract 'theme'?");return t.theme}),zt=()=>r(t=>t.incSaveCount),Qt=()=>r(t=>t.incDirtyCount),_t=()=>r(t=>t.loadedTextContent),Ut=()=>r(t=>t.loadedJsonContent),Yt=()=>r(t=>t.loadedJsonActivityContent),Kt=()=>r(t=>t.loadedJsonAssignmentContent),Xt=()=>r(t=>t.loadedJsonActivityBinaryData),Zt=()=>r(t=>t.loadedJsonAssignmentBinaryData),te=()=>v.useCallback(()=>r.getState().loadedTextContent,[]),ee=()=>v.useCallback(()=>r.getState().loadedJsonContent,[]),ne=()=>v.useCallback(()=>r.getState().loadedJsonActivityContent,[]),oe=()=>v.useCallback(()=>r.getState().loadedJsonAssignmentContent,[]),re=()=>v.useCallback(()=>({content:r.getState().loadedJsonActivityContent,binaryData:r.getState().loadedJsonActivityBinaryData}),[]),se=()=>v.useCallback(()=>({content:r.getState().loadedJsonAssignmentContent,binaryData:r.getState().loadedJsonAssignmentBinaryData}),[]),ie=t=>{const e=r(n=>n.setGetTextContentFunction);v.useEffect(()=>{e(t)},[t,e])},ae=t=>{const e=r(n=>n.setGetJsonContentFunction);v.useEffect(()=>{e(t)},[t,e])},le=t=>{const e=r(n=>n.setGetJsonActivityContentFunction);v.useEffect(()=>{e(t)},[t,e])},ce=t=>{const e=r(n=>n.setGetJsonAssignmentContentFunction);v.useEffect(()=>{e(t)},[t,e])},ue=t=>{const e=r(n=>n.setGetJsonActivitySplitContentFunction);v.useEffect(()=>{e(t)},[t,e])},de=t=>{const e=r(n=>n.setGetJsonAssignmentSplitContentFunction);v.useEffect(()=>{e(t)},[t,e])},fe=t=>{const e=r(n=>n.afterSaveCount);v.useEffect(()=>{e>0&&t()},[e])},ge=()=>(t,e)=>{w.use(["meta-player-ui"],([n])=>{if(n.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}n.i?.previewTextFile(t,e)})},me=()=>(t,e)=>{w.use(["meta-player-ui"],([n])=>{if(n.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}n.i?.previewImageFile(t,e)})};let G=0,B=0;const Ce=(t,e)=>{const n=v.useMemo(t,e),i=r(o=>o.setSidebarActions);v.useEffect(()=>(G++,G>1&&console.error("[React bindings] Capytale iframe React: Multiple sidebar actions registered: ",G),()=>{G--}),[]),v.useEffect(()=>(w.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}B++;const s=n.map((l,g)=>({type:l.type,title:l.title,icon:l.icon,id:`sa-${B}-${g}`,...l.type==="file-upload"?{accept:l.accept}:{}})),u={};n.forEach((l,g)=>{u[`sa-${B}-${g}`]=l.action}),o.i?.setSidebarActionButtons(s),i(u)}),()=>{i({}),w.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}o.i?.setSidebarActionButtons([])})}),[n])};let D=0,W=0;const pe=(t,e)=>{const n=v.useMemo(t,e),i=r(o=>o.setQuickActions);v.useEffect(()=>(D++,D>1&&console.error("[React bindings] Capytale iframe React: Multiple quick actions registered: ",D),()=>{D--}),[]),v.useEffect(()=>(w.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}W++;const s=n.map((l,g)=>({type:l.type,title:l.title,icon:l.icon,id:`qa-${W}-${g}`,...l.type==="file-upload"?{accept:l.accept}:{}})),u={};n.forEach((l,g)=>{u[`qa-${W}-${g}`]=l.action}),o.i?.setQuickActionButtons(s),i(u)}),()=>{i({}),w.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}o.i?.setQuickActionButtons([])})}),[n])};let P=0;const ct=(t,e,n)=>{const i=v.useMemo(t,n),o=r(s=>s.setActivitySettingsCallback);v.useEffect(()=>(P++,P>1&&console.error("[React bindings] Capytale iframe React: Multiple settings registered: ",P),()=>{P--}),[]),v.useEffect(()=>(w.use(["meta-player-ui"],([s])=>{if(s.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}s.i?.setSettingsUI(i)}),o(e),()=>{o(null)}),[i])},ut=()=>v.useCallback(e=>w.exec(["meta-player-ui"],([n])=>{if(n.version===0)throw console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui"),new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return n.i?.showToast(e)}),[]),dt=()=>v.useCallback(e=>w.exec(["meta-player-ui"],([n])=>{if(n.version===0)throw console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui"),new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return n.i?.clearToast(e)}),[]),ve=()=>v.useCallback(()=>w.exec(["meta-player-ui"],([e])=>{if(e.version===0)throw console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui"),new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return e.i?.clearToasts()}),[]),ft=(t,e)=>{const n=ut(),i=dt();return v.useEffect(()=>{if(t==null)return;const o=n(t);return()=>{o.then(s=>{s!=null&&i(s)})}},[n,i,...e]),null},ye=()=>v.useCallback(()=>w.exec(["trigger-save"],([e])=>{if(e.version===0)throw console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat trigger-save"),new Error("Le MétaPlayer ne supporte pas le contrat trigger-save");return e.i?.triggerSave()}),[]),Se=()=>r(t=>t.canSave),Ae=(t,e)=>{const n=r(i=>i.setLlmGetFirstMessageContextFunction);v.useEffect(()=>(n(t),()=>{n(null)}),[e,n])},we=(t,e)=>{const n=r(i=>i.setLlmGetAllMessagesContextFunction);v.useEffect(()=>(n(t),()=>{n(null)}),[e,n])},be=(t,e,n,i)=>{const o=r(l=>l.setLlmGetAvailableToolsFunction),s=r(l=>l.setLlmCallToolFunction),u=r(l=>l.setLlmDescribeToolFunction);v.useEffect(()=>(o(t),s(e),u(n),()=>{o(null),s(null),u(null)}),[i,o,s,u])};function he(t){const e={};for(const n of t.fields)e[n.name]=n.defaultValue;return e}function Fe(t){return{[t.name]:t.defaultValues}}function Ee(t){return{[t.name]:t.defaultValue}}function Je(t){switch(t.type){case"form":return he(t);case"checkboxes":case"switches":return Fe(t);case"radio":return Ee(t);default:return{}}}function Te(t){const e={};for(const n of t)Object.assign(e,Je(n));return e}function Re(t){const n=lt()(i=>({...Te(t)}));return n.activitySettings=t,n}function ke(t){ct(()=>t.activitySettings,e=>{t.setState(e)},[])}function xe({store:t}){return ke(t),null}const Le=["meta-player-events:1","meta-player-ui:1","mode:1","workflow:1"];function Me({children:t,contracts:e,loadOnlyWhenReady:n=!0,activitySettingsStore:i}){const o=r(s=>s.ready);return v.useEffect(()=>{const s=[...e];for(const u of Le)s.includes(u)||s.push(u);qt(s)},[]),n&&!o?L.jsx("div",{className:"capy-loading-container",children:"Chargement en cours..."}):L.jsxs(L.Fragment,{children:[i&&L.jsx(xe,{store:i}),t]})}function Ge({message:t}){return ft(t,[t]),null}exports.Capytale=Me;exports.TemporaryToast=Ge;exports.createActivitySettingsStore=Re;exports.useAfterSaveAction=fe;exports.useCanSave=Se;exports.useClearToast=dt;exports.useClearToasts=ve;exports.useGetLoadedJsonActivityContent=ne;exports.useGetLoadedJsonActivitySplitContent=re;exports.useGetLoadedJsonAssignmentContent=oe;exports.useGetLoadedJsonAssignmentSplitContent=se;exports.useGetLoadedJsonContent=ee;exports.useGetLoadedTextContent=te;exports.useJsonActivityContentSaveFunction=le;exports.useJsonActivitySplitContentSaveFunction=ue;exports.useJsonAssignmentContentSaveFunction=ce;exports.useJsonAssignmentSplitContentSaveFunction=de;exports.useJsonContentSaveFunction=ae;exports.useLLMAllMessagesContext=we;exports.useLLMFirstMessageContext=Ae;exports.useLLMTools=be;exports.useLoadedJsonActivityBinaryData=Xt;exports.useLoadedJsonActivityContent=Yt;exports.useLoadedJsonAssignmentBinaryData=Zt;exports.useLoadedJsonAssignmentContent=Kt;exports.useLoadedJsonContent=Ut;exports.useLoadedTextContent=_t;exports.useMode=Bt;exports.useNotifyIsDirty=Qt;exports.usePreviewImageFile=me;exports.usePreviewTextFile=ge;exports.useQuickActions=pe;exports.useRequestSave=zt;exports.useSettings=ct;exports.useShowToast=ut;exports.useSidebarActions=Ce;exports.useTextContentSaveFunction=ie;exports.useTheme=Ht;exports.useToast=ft;exports.useTriggerSave=ye;exports.useWorkflow=Wt;