@capytale/iframe-react 1.1.19 → 1.2.1

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"),y=require("react");const X=Symbol("Comlink.proxy"),me=Symbol("Comlink.endpoint"),pe=Symbol("Comlink.releaseProxy"),N=Symbol("Comlink.finalizer"),D=Symbol("Comlink.thrown"),Z=e=>typeof e=="object"&&e!==null||typeof e=="function",Ce={canHandle:e=>Z(e)&&e[X],serialize(e){const{port1:t,port2:n}=new MessageChannel;return z(e,t),[n,[n]]},deserialize(e){return e.start(),ne(e)}},ye={canHandle:e=>Z(e)&&D in e,serialize({value:e}){let t;return e instanceof Error?t={isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:t={isError:!1,value:e},[t,[]]},deserialize(e){throw e.isError?Object.assign(new Error(e.value.message),e.value):e.value}},ee=new Map([["proxy",Ce],["throw",ye]]);function ve(e,t){for(const n of e)if(t===n||n==="*"||n instanceof RegExp&&n.test(t))return!0;return!1}function z(e,t=globalThis,n=["*"]){t.addEventListener("message",function s(o){if(!o||!o.data)return;if(!ve(n,o.origin)){console.warn(`Invalid origin '${o.origin}' for comlink proxy`);return}const{id:r,type:f,path:c}=Object.assign({path:[]},o.data),g=(o.data.argumentList||[]).map(R);let d;try{const u=c.slice(0,-1).reduce((C,S)=>C[S],e),m=c.reduce((C,S)=>C[S],e);switch(f){case"GET":d=m;break;case"SET":u[c.slice(-1)[0]]=R(o.data.value),d=!0;break;case"APPLY":d=m.apply(u,g);break;case"CONSTRUCT":{const C=new m(...g);d=re(C)}break;case"ENDPOINT":{const{port1:C,port2:S}=new MessageChannel;z(e,S),d=he(C,[C])}break;case"RELEASE":d=void 0;break;default:return}}catch(u){d={value:u,[D]:0}}Promise.resolve(d).catch(u=>({value:u,[D]:0})).then(u=>{const[m,C]=$(u);t.postMessage(Object.assign(Object.assign({},m),{id:r}),C),f==="RELEASE"&&(t.removeEventListener("message",s),te(t),N in e&&typeof e[N]=="function"&&e[N]())}).catch(u=>{const[m,C]=$({value:new TypeError("Unserializable return value"),[D]:0});t.postMessage(Object.assign(Object.assign({},m),{id:r}),C)})}),t.start&&t.start()}function Se(e){return e.constructor.name==="MessagePort"}function te(e){Se(e)&&e.close()}function ne(e,t){const n=new Map;return e.addEventListener("message",function(o){const{data:r}=o;if(!r||!r.id)return;const f=n.get(r.id);if(f)try{f(r)}finally{n.delete(r.id)}}),H(e,n,[],t)}function M(e){if(e)throw new Error("Proxy has been released and is not useable")}function oe(e){return T(e,new Map,{type:"RELEASE"}).then(()=>{te(e)})}const I=new WeakMap,j="FinalizationRegistry"in globalThis&&new FinalizationRegistry(e=>{const t=(I.get(e)||0)-1;I.set(e,t),t===0&&oe(e)});function Ae(e,t){const n=(I.get(t)||0)+1;I.set(t,n),j&&j.register(e,t,e)}function be(e){j&&j.unregister(e)}function H(e,t,n=[],s=function(){}){let o=!1;const r=new Proxy(s,{get(f,c){if(M(o),c===pe)return()=>{be(r),oe(e),t.clear(),o=!0};if(c==="then"){if(n.length===0)return{then:()=>r};const g=T(e,t,{type:"GET",path:n.map(d=>d.toString())}).then(R);return g.then.bind(g)}return H(e,t,[...n,c])},set(f,c,g){M(o);const[d,u]=$(g);return T(e,t,{type:"SET",path:[...n,c].map(m=>m.toString()),value:d},u).then(R)},apply(f,c,g){M(o);const d=n[n.length-1];if(d===me)return T(e,t,{type:"ENDPOINT"}).then(R);if(d==="bind")return H(e,t,n.slice(0,-1));const[u,m]=U(g);return T(e,t,{type:"APPLY",path:n.map(C=>C.toString()),argumentList:u},m).then(R)},construct(f,c){M(o);const[g,d]=U(c);return T(e,t,{type:"CONSTRUCT",path:n.map(u=>u.toString()),argumentList:g},d).then(R)}});return Ae(r,e),r}function we(e){return Array.prototype.concat.apply([],e)}function U(e){const t=e.map($);return[t.map(n=>n[0]),we(t.map(n=>n[1]))]}const se=new WeakMap;function he(e,t){return se.set(e,t),e}function re(e){return Object.assign(e,{[X]:!0})}function Ee(e,t=globalThis,n="*"){return{postMessage:(s,o)=>e.postMessage(s,n,o),addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}function $(e){for(const[t,n]of ee)if(n.canHandle(e)){const[s,o]=n.serialize(e);return[{type:"HANDLER",name:t,value:s},o]}return[{type:"RAW",value:e},se.get(e)||[]]}function R(e){switch(e.type){case"HANDLER":return ee.get(e.name).deserialize(e.value);case"RAW":return e.value}}function T(e,t,n,s){return new Promise(o=>{const r=Fe();t.set(r,o),e.start&&e.start(),e.postMessage(Object.assign({id:r},n),s)})}function Fe(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function Re(e,t){return e.length===0?t:`[${e}] ${t}`}function Je(e,t){let n=!1,s,o,r;function f(u){return Re(e,u)}let c,g=!1;if(window.parent===window)console.warn(f("Contract link is not supported in standalone mode")),c={ready(){return Promise.resolve()},declare(){return Promise.resolve()},done(){return Promise.resolve()},provide(u,m,C){return Promise.resolve()}};else{const u=Ee(window.parent,void 0,t);z({declare(m){if(s==null)throw new Error(f("No handler for declare"));s(m)},done(){if(o==null)throw new Error(f("No handler for done"));o()},provide(m,C,S){if(r==null)throw new Error(f("No handler for provide"));r(m,C,S)}},u),c=ne(u),g=!0}const d=()=>{if(!n){if(s==null||o==null||r==null)return;n=!0,c.ready()}};return{declare:u=>c.declare(u),done:()=>c.done(),provide:(u,m,C)=>c.provide(u,m,re(C)),get name(){return e},get isReady(){return g},set onDeclare(u){s=u,d()},set onDone(u){o=u,d()},set onProvide(u){r=u,d()}}}function ke(e){return function(t){let n,s=!1,o=!1,r,f,c=!1,g=!1,d,u,m,C;function S(){if(r!=null&&r!==0&&f!=null)return f}function E(a){if(r!=null&&f!=null&&!(a>r))return f}function w(){return m??(g?m=Promise.resolve():m=new Promise((a,l)=>{C=a}))}function J(){return d===void 0&&(d={get name(){return t},get version(){return r},get i(){return S()},v:a=>E(a)}),d}function x(){return u===void 0&&(u={get name(){return t},get version(){return g?r:void 0},get i(){return g?S():void 0},v:a=>g?E(a):void 0,get promise(){return r===0?Promise.reject(e("Remote interface not provided")):w().then(()=>{if(r===0)throw new Error(e("Remote interface not provided"));return J()})}}),u}function F(){C!=null&&(C(),C=void 0)}return{get name(){return t},get localVersion(){if(n!=null)return n},set localVersion(a){if(n!=null&&n!==a)throw new Error(e("A different local version is already set"));n=a},get localVersionSent(){return s},set localVersionSent(a){if(!a&&s)throw new Error(e("Local version already notified"));s=a,a&&n===0&&(o=!0)},get localInterfaceSent(){return o},set localInterfaceSent(a){if(n==null)throw new Error(e("Local version not set"));if(!a&&o)throw new Error(e("Local interface already sent."));o=a},get remoteVersion(){if(r!=null)return r},set remoteVersion(a){if(r!=null&&r!==a)throw new Error(e("A different remote version is already set for "+t+`(${r} -> ${a})`));r=a,a===0&&(c=!0)},get remoteVersionReceived(){return r!=null},setRemoteInterface:a=>{if(r==null)throw new Error(e("Remote version not set"));if(r===0){console.warn(e("Remote version is 0, remote interface is ignored."));return}if(c)throw new Error(e("Interface already provided."));f=a,c=!0},get remoteInterfaceReceived(){return c},depGroup:void 0,get isActivable(){return c&&o},get isActivated(){return g},activate(){if(!g){if(!c)throw new Error(e("Remote interface not provided."));if(!o)throw new Error(e("Local interface not sent"));g=!0,F()}},getRemote:()=>J(),getLazyRemote:()=>x(),get activationPromise(){return w()}}}}function Te(e){return function(t,n,s,o){let r=s,f=!1,c=!1;function g(){return t.every(d=>d.remoteVersionReceived&&d.localVersionSent)&&n.every(d=>d.remoteVersionReceived)}return{get isDeclared(){return c},set isDeclared(d){if(!d&&c)throw new Error(e("Factory already declared"));c=d},get isReady(){return g()},get isDone(){return f},get args(){return t},get deps(){return n},invoke(){if(f)throw new Error(e("Factory already invoked"));if(!g())throw new Error(e("Factory is not ready"));let d;o?d=t.map(C=>C.getRemote()):d=t[0].getRemote();let u;const m=n.length>0?n.map(C=>C.getRemote()):null;try{u=m==null?r(d):r(d,m)}catch(C){throw new Error(e("error in factory:"),{cause:C})}if(o||(u=[u]),u.length!=t.length)throw new Error(e("Invalid factory result"));return f=!0,r=null,u}}}}function xe(e){return function(t,n,s,o){let r=n,f=!1;function c(){return t.every(g=>g.isActivated)}return{get isReady(){return c()},get isDone(){return f},get args(){return t},invoke(){if(f||!c()){const u=new Error(e(f?"callback already invoked":"callback parameters are not ready"));throw o?.[1](u),u}const g=s?t.map(u=>u.getRemote()):t[0].getRemote();let d;try{d=r(g)}catch(u){o==null?console.error(e("error in callback:"),u):o[1](u)}finally{f=!0}o?.[0](d)}}}}function ie(e,t){return e==null||e.length===0?t:`[${e}] ${t}`}function Le(e){function t(a){return ie(e.name,a)}const n=xe(t),s=ke(t),o=Te(t),r={},f=[];let c=[],g;const d=()=>(g==null?g=0:g++,g);function u(a){let l=r[a];return l==null&&(l=s(a),l.localVersion==null&&(w&&(l.localVersion=0),J&&(l.localVersionSent=!0)),l.remoteVersion==null&&x&&(l.remoteVersion=0),r[a]=l),l}function m(a){return a.map(u)}function C(...a){const l=d(),p=Array(l).fill(!1);a.forEach(v=>{v.forEach(A=>{A.depGroup!=null&&(p[A.depGroup]=!0),A.depGroup=l})}),Object.values(r).forEach(v=>{v.depGroup!=null&&v.depGroup!==l&&p[v.depGroup]&&(v.depGroup=l)})}e.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),F()},e.onDone=()=>{x||(x=!0,Object.values(r).forEach(a=>{a.remoteVersion==null&&(a.remoteVersion=0)}),F())},e.onProvide=(a,l,p)=>{let v=r[a];if(v==null)throw new Error(t(`Contract not declared : ${a}`));if(v.remoteVersion!=l)throw new Error(t(`Remote declared version ${v.remoteVersion} of contract "${a}" but provided version ${l}.`));if(v.remoteInterfaceReceived)throw new Error(t(`Remote contract "${a}" is already provided.`));v.setRemoteInterface(p),F()};let S=!1,E=!1,w=!1,J=!1,x=!1;async function F(){if(E=!0,!S){for(S=!0;E;){if(E=!1,e.isReady){const a=f.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((v,A)=>p[A]=v),l.deps.forEach((v,A)=>p[A+l.args.length]=v),await e.declare(p.map(v=>({name:v.name,version:v.localVersion}))),p.forEach(v=>{v.localVersion!=null&&(v.localVersionSent=!0)}),l.isDeclared=!0}}if(e.isReady&&w&&f.every(a=>a.isDeclared)){const a=Object.values(r).filter(l=>!l.localVersionSent&&l.localVersion!=null);if(a.length>0)for(const l of a)await e.declare([{name:l.name,version:l.localVersion}]),l.localVersionSent=!0;J||(J=!0,await e.done())}if(e.isReady){const a=f.filter(l=>!l.isDone&&l.isReady);if(a.length>0)for(const l of a){const p=l.invoke();for(let v=0;v<l.args.length;v++){const A=l.args[v];await e.provide(A.name,A.localVersion,p[v]),A.localInterfaceSent=!0}}}if(g!=null){const a=Array(g+1).fill(null);for(const l in r){const p=r[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 r){const p=r[l];p.depGroup!=null&&a[p.depGroup]&&p.activate()}}if(e.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 u(a)},declareFactory:(a,l,p,v)=>{if(w)throw new Error(t("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(t("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 k=m(l);C(A,k);const fe=o(A,k,p,v);f.push(fe),F()},declareCallback(a,l,p,v){const A=m(a),k=n(A,l,p,v);!S&&c.length===0&&k.isReady?k.invoke():(c.push(k),F())},get done(){return w},set done(a){if(w){if(!a)throw new Error(t("Cannot set done to false after it has been set to true."))}else a&&(w=!0,Object.values(r).forEach(l=>{l.localVersion==null&&(l.localVersion=0)}),F())}}}const Me=/^\d+$/;function Ge(e){const[t,n,s]=e.split(":",3);if(n==null||s!=null||!Me.test(n))return null;const o=parseInt(n);return isNaN(o)||o===0?null:{name:t,version:o}}function Pe(e){const t=Le(e);function n(s){return ie(e.name,s)}return{plug(s,o,r=void 0){if(t.done)throw new Error(n("Cannot plug after plugsDone."));r==null&&(r=o,o=[]);let f=!0;Array.isArray(s)||(s=[s],f=!1);const c=s.map(g=>{const d=Ge(g);if(d==null)throw new Error(n("Invalid contract id : "+g));return d});t.declareFactory(c,o,r,f)},plugsDone(){t.done=!0},use(s,o){let r=!0;Array.isArray(s)||(s=[s],r=!1),t.declareCallback(s,o,r)},exec(s,o){let r=!0;return Array.isArray(s)||(s=[s],r=!1),new Promise((...f)=>{t.declareCallback(s,o,r,f)})},get(s){return s.map(o=>t.get(o).getLazyRemote())}}}const ae="app-agent";let q;function Ve(e){return q!=null||(q=Pe(Je(ae,e))),q}console.log(`[${ae}@1.0.12] loaded`);const Q=e=>{let t;const n=new Set,s=(d,u)=>{const m=typeof d=="function"?d(t):d;if(!Object.is(m,t)){const C=t;t=u??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(S=>S(t,C))}},o=()=>t,c={setState:s,getState:o,getInitialState:()=>g,subscribe:d=>(n.add(d),()=>n.delete(d))},g=t=e(s,o,c);return c},De=e=>e?Q(e):Q,Ie=e=>e;function je(e,t=Ie){const n=y.useSyncExternalStore(e.subscribe,y.useCallback(()=>t(e.getState()),[e,t]),y.useCallback(()=>t(e.getInitialState()),[e,t]));return y.useDebugValue(n),n}const _=e=>{const t=De(e),n=s=>je(t,s);return Object.assign(n,t),n},ce=e=>e?_(e):_,$e=e=>(t,n,s)=>{const o=s.subscribe;return s.subscribe=(f,c,g)=>{let d=f;if(c){const u=g?.equalityFn||Object.is;let m=f(s.getState());d=C=>{const S=f(C);if(!u(m,S)){const E=m;c(m=S,E)}},g?.fireImmediately&&c(m,m)}return o(d)},e(t,n,s)},Oe=$e,i=ce()(Oe(e=>({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:t=>{e({llmGetFirstMessageContextFunction:t})},llmGetAllMessagesContextFunction:null,setLlmGetAllMessagesContextFunction:t=>{e({llmGetAllMessagesContextFunction:t})},llmGetAvailableToolsFunction:null,setLlmGetAvailableToolsFunction:t=>{e({llmGetAvailableToolsFunction:t})},llmCallToolFunction:null,setLlmCallToolFunction:t=>{e({llmCallToolFunction:t})},setGetTextContentFunction:t=>{e({getTextContentFunction:t})},setGetJsonContentFunction:t=>{e({getJsonContentFunction:t})},setGetJsonActivityContentFunction:t=>{e({getJsonActivityContentFunction:t})},setGetJsonAssignmentContentFunction:t=>{e({getJsonAssignmentContentFunction:t})},setGetJsonActivitySplitContentFunction:t=>{e({getJsonActivitySplitContentFunction:t})},setGetJsonAssignmentSplitContentFunction:t=>{e({getJsonAssignmentSplitContentFunction:t})},setSidebarActions:t=>{e({sidebarActions:t})},setQuickActions:t=>{e({quickActions:t})},setActivitySettingsCallback:t=>{e({activitySettingsCallback:t})},incSaveCount:()=>e(t=>({saveCount:t.saveCount+1})),incDirtyCount:()=>e(t=>({isDirtyCount:t.isDirtyCount+1}))})));let Y=!1;const Ne=["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:e=>{i.setState({mode:e})}},"reload:1":{reloaded:e=>{console.log("[React bindings] Reloaded with state:",e),console.error("[React bindings] Not implemented yet")}},"theme:1":{setTheme:e=>{if(e===null){i.setState({theme:null});return}if(e!=="light"&&e!=="dark"){console.warn(`[React bindings] Invalid theme: ${e}. Expected 'light' or 'dark'.`),i.setState({theme:null});return}i.setState({theme:e})}},"workflow:1":{setWorkflow:e=>{i.setState({workflow:e})}},"trigger-save:1":{setCanSave(e){i.setState({canSave:e})}},"simple-content(text):1":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},getContent:()=>i.getState().getTextContentFunction(),loadContent:e=>{i.setState({loadedTextContent:e})}},"simple-content(json):1":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},getContent:()=>i.getState().getJsonContentFunction(),loadContent:e=>{i.setState({loadedJsonContent:e})}},"simple-binary-data(text):1":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},getContent:()=>i.getState().getTextContentFunction(),loadContent:e=>{i.setState({loadedTextContent:e})}},"simple-content-eval(text):1":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},getContent:()=>i.getState().getTextContentFunction(),loadContent:e=>{i.setState({loadedTextContent:e})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"simple-content-eval(json):1":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},getContent:()=>i.getState().getJsonContentFunction(),loadContent:e=>{i.setState({loadedJsonContent:e})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(json):2":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},getContent:()=>i.getState().getJsonContentFunction(),loadContent:e=>{i.setState({loadedJsonContent:e})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(text):2":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},getContent:()=>i.getState().getTextContentFunction(),loadContent:e=>{i.setState({loadedTextContent:e})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"separate-contents(json):1":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},loadContent:(e,t)=>{i.setState({loadedJsonActivityContent:e,loadedJsonAssignmentContent:t})},getActivityContent:()=>i.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>i.getState().getJsonAssignmentContentFunction()},"separate-dual-contents(json):1":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},loadContent:({activityContent:e,assignmentContent:t,activityBinaryData:n,assignmentBinaryData:s})=>{i.setState({loadedJsonActivityContent:e,loadedJsonAssignmentContent:t,loadedJsonActivityBinaryData:n,loadedJsonAssignmentBinaryData:s})},getActivityContentAndData:()=>(console.log("[React bindings] Getting activity content and data"),i.getState().getJsonActivitySplitContentFunction()),getAssignmentContentAndData:()=>(console.log("[React bindings] Getting assignment content and data"),i.getState().getJsonAssignmentSplitContentFunction())},"meta-player-anti-cheat:1":{lock:()=>{},unlock:()=>{}},"meta-player-ui:1":{executeAction(e){if(console.log("[React bindings] Executing action:",e),e.startsWith("qa")){const n=i.getState().quickActions[e];n?n():console.error(`[React bindings] Quick action not found: ${e}`)}else{const n=i.getState().sidebarActions[e];n?n():console.error(`[React bindings] Sidebar action not found: ${e}`)}},executeFileUpload(e,t){if(e.startsWith("qa")){const s=i.getState().quickActions[e];s?s(t):console.error(`[React bindings] Quick action not found: ${e}`)}else{const s=i.getState().sidebarActions[e];s?s(t):console.error(`[React bindings] Sidebar action not found: ${e}`)}},updateSettings(e){const t=i.getState().activitySettingsCallback;t?t(e):console.warn("activitySettingsCallback is not set. Changes:",e)}},"meta-player-events:1":{handleEvent(e){e==="all-loaded"&&i.setState({ready:!0})}},"llm:1":{getFirstMessageContext:e=>{const t=i.getState().llmGetFirstMessageContextFunction;return t?t(e):""},getAllMessagesContext:e=>{const t=i.getState().llmGetAllMessagesContextFunction;return t?t(e):""},getAvailableTools:e=>{const t=i.getState().llmGetAvailableToolsFunction;return t?t(e):[]},callTool:(e,t)=>{const n=i.getState().llmCallToolFunction;if(!n)throw new Error("LLM call tool function is not set");return n(e,t)}}},b=Ve();function qe(e){if(console.log("[React bindings] Contracts to plug:",e),Y){console.warn("[React bindings] Contracts have already been plugged. Skipping.");return}Y=!0;for(const t of e){if(!Ne.includes(t)){console.warn(`[React bindings] Contract ${t} is not implemented in Capytale. Skipping plug.`);continue}if(!(t in K)){console.warn(`[React bindings] Contract handler for ${t} is not defined. Skipping plug.`);continue}const n=K[t];console.log(`[React bindings] Plugging contract ${t}...`),b.plug([t],([])=>(console.log(`[React bindings] Contract ${t} plugged.`),[n]))}b.plugsDone();for(const t 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 ${t} is being subscribed to content changes.`),e.includes(t)){console.log(`[React bindings] Subscribing to content changes for contract ${t}`);const n=t.split(":")[0];b.use([n],([s])=>{i.subscribe(o=>o.isDirtyCount,()=>{s.i?.contentChanged(),console.log(`[React bindings] Content changed for contract ${n}`)})})}}const Be=()=>i(e=>{if(e.mode===null)throw new Error("Mode is not set. Have you used contract 'mode'?");return e.mode}),We=()=>i(e=>{if(e.workflow===null)throw new Error("Workflow is not set. Have you used contract 'workflow'?");return e.workflow}),He=()=>i(e=>{if(e.theme===null)throw new Error("Theme is not set. Have you used contract 'theme'?");return e.theme}),ze=()=>i(e=>e.incSaveCount),Ue=()=>i(e=>e.incDirtyCount),Qe=()=>i(e=>e.loadedTextContent),_e=()=>i(e=>e.loadedJsonContent),Ye=()=>i(e=>e.loadedJsonActivityContent),Ke=()=>i(e=>e.loadedJsonAssignmentContent),Xe=()=>i(e=>e.loadedJsonActivityBinaryData),Ze=()=>i(e=>e.loadedJsonAssignmentBinaryData),et=()=>y.useCallback(()=>i.getState().loadedTextContent,[]),tt=()=>y.useCallback(()=>i.getState().loadedJsonContent,[]),nt=()=>y.useCallback(()=>i.getState().loadedJsonActivityContent,[]),ot=()=>y.useCallback(()=>i.getState().loadedJsonAssignmentContent,[]),st=()=>y.useCallback(()=>({content:i.getState().loadedJsonActivityContent,binaryData:i.getState().loadedJsonActivityBinaryData}),[]),rt=()=>y.useCallback(()=>({content:i.getState().loadedJsonAssignmentContent,binaryData:i.getState().loadedJsonAssignmentBinaryData}),[]),it=e=>{const t=i(n=>n.setGetTextContentFunction);y.useEffect(()=>{t(e)},[e,t])},at=e=>{const t=i(n=>n.setGetJsonContentFunction);y.useEffect(()=>{t(e)},[e,t])},ct=e=>{const t=i(n=>n.setGetJsonActivityContentFunction);y.useEffect(()=>{t(e)},[e,t])},lt=e=>{const t=i(n=>n.setGetJsonAssignmentContentFunction);y.useEffect(()=>{t(e)},[e,t])},ut=e=>{const t=i(n=>n.setGetJsonActivitySplitContentFunction);y.useEffect(()=>{t(e)},[e,t])},dt=e=>{const t=i(n=>n.setGetJsonAssignmentSplitContentFunction);y.useEffect(()=>{t(e)},[e,t])},gt=e=>{const t=i(n=>n.afterSaveCount);y.useEffect(()=>{t>0&&e()},[t])},ft=()=>(e,t)=>{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(e,t)})},mt=()=>(e,t)=>{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(e,t)})};let G=0,B=0;const pt=(e,t)=>{const n=y.useMemo(e,t),s=i(o=>o.setSidebarActions);y.useEffect(()=>(G++,G>1&&console.error("[React bindings] Capytale iframe React: Multiple sidebar actions registered: ",G),()=>{G--}),[]),y.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 r=n.map((c,g)=>({type:c.type,title:c.title,icon:c.icon,id:`sa-${B}-${g}`,...c.type==="file-upload"?{accept:c.accept}:{}})),f={};n.forEach((c,g)=>{f[`sa-${B}-${g}`]=c.action}),o.i?.setSidebarActionButtons(r),s(f)}),()=>{s({}),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 P=0,W=0;const Ct=(e,t)=>{const n=y.useMemo(e,t),s=i(o=>o.setQuickActions);y.useEffect(()=>(P++,P>1&&console.error("[React bindings] Capytale iframe React: Multiple quick actions registered: ",P),()=>{P--}),[]),y.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 r=n.map((c,g)=>({type:c.type,title:c.title,icon:c.icon,id:`qa-${W}-${g}`,...c.type==="file-upload"?{accept:c.accept}:{}})),f={};n.forEach((c,g)=>{f[`qa-${W}-${g}`]=c.action}),o.i?.setQuickActionButtons(r),s(f)}),()=>{s({}),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 V=0;const le=(e,t,n)=>{const s=y.useMemo(e,n),o=i(r=>r.setActivitySettingsCallback);y.useEffect(()=>(console.log("[React bindings] Mounting useSettings"),V++,V>1&&console.error("[React bindings] Capytale iframe React: Multiple settings registered: ",V),()=>{console.log("[React bindings] Unmounting useSettings"),V--}),[]),y.useEffect(()=>(b.use(["meta-player-ui"],([r])=>{if(r.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",s),r.i?.setSettingsUI(s)}),o(t),()=>{o(null)}),[s])},ue=()=>y.useCallback(t=>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(t)}),[]),de=()=>y.useCallback(t=>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(t)}),[]),yt=()=>y.useCallback(()=>b.exec(["meta-player-ui"],([t])=>{if(t.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 t.i?.clearToasts()}),[]),ge=(e,t)=>{const n=ue(),s=de();return y.useEffect(()=>{if(e==null)return;const o=n(e);return()=>{o.then(r=>{r!=null&&s(r)})}},[n,s,...t]),null},vt=()=>y.useCallback(()=>b.exec(["trigger-save"],([t])=>{if(t.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 t.i?.triggerSave()}),[]),St=()=>i(e=>e.canSave),At=(e,t)=>{const n=i(s=>s.setLlmGetFirstMessageContextFunction);y.useEffect(()=>(n(e),()=>{n(null)}),[t,n])},bt=(e,t)=>{const n=i(s=>s.setLlmGetAllMessagesContextFunction);y.useEffect(()=>(n(e),()=>{n(null)}),[t,n])},wt=(e,t,n)=>{const s=i(r=>r.setLlmGetAvailableToolsFunction),o=i(r=>r.setLlmCallToolFunction);y.useEffect(()=>(s(e),o(t),()=>{s(null),o(null)}),[n,s,o])};function ht(e){const t={};for(const n of e.fields)t[n.name]=n.defaultValue;return t}function Et(e){return{[e.name]:e.defaultValues}}function Ft(e){return{[e.name]:e.defaultValue}}function Rt(e){switch(e.type){case"form":return ht(e);case"checkboxes":case"switches":return Et(e);case"radio":return Ft(e);default:return{}}}function Jt(e){const t={};for(const n of e)Object.assign(t,Rt(n));return t}function kt(e){const n=ce()(s=>({...Jt(e)}));return n.activitySettings=e,n}function Tt(e){le(()=>e.activitySettings,t=>{e.setState(t)},[])}function xt({store:e}){return Tt(e),null}const Lt=["meta-player-events:1","meta-player-ui:1","mode:1","workflow:1"];function Mt({children:e,contracts:t,loadOnlyWhenReady:n=!0,activitySettingsStore:s}){const o=i(r=>r.ready);return y.useEffect(()=>{const r=[...t];for(const f of Lt)r.includes(f)||r.push(f);qe(r)},[]),n&&!o?L.jsx("div",{className:"capy-loading-container",children:"Chargement en cours..."}):L.jsxs(L.Fragment,{children:[s&&L.jsx(xt,{store:s}),e]})}function Gt({message:e}){return ge(e,[e]),null}exports.Capytale=Mt;exports.TemporaryToast=Gt;exports.createActivitySettingsStore=kt;exports.useAfterSaveAction=gt;exports.useCanSave=St;exports.useClearToast=de;exports.useClearToasts=yt;exports.useGetLoadedJsonActivityContent=nt;exports.useGetLoadedJsonActivitySplitContent=st;exports.useGetLoadedJsonAssignmentContent=ot;exports.useGetLoadedJsonAssignmentSplitContent=rt;exports.useGetLoadedJsonContent=tt;exports.useGetLoadedTextContent=et;exports.useJsonActivityContentSaveFunction=ct;exports.useJsonActivitySplitContentSaveFunction=ut;exports.useJsonAssignmentContentSaveFunction=lt;exports.useJsonAssignmentSplitContentSaveFunction=dt;exports.useJsonContentSaveFunction=at;exports.useLLMAllMessagesContext=bt;exports.useLLMFirstMessageContext=At;exports.useLLMTools=wt;exports.useLoadedJsonActivityBinaryData=Xe;exports.useLoadedJsonActivityContent=Ye;exports.useLoadedJsonAssignmentBinaryData=Ze;exports.useLoadedJsonAssignmentContent=Ke;exports.useLoadedJsonContent=_e;exports.useLoadedTextContent=Qe;exports.useMode=Be;exports.useNotifyIsDirty=Ue;exports.usePreviewImageFile=mt;exports.usePreviewTextFile=ft;exports.useQuickActions=Ct;exports.useRequestSave=ze;exports.useSettings=le;exports.useShowToast=ue;exports.useSidebarActions=pt;exports.useTextContentSaveFunction=it;exports.useTheme=He;exports.useToast=ge;exports.useTriggerSave=vt;exports.useWorkflow=We;
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;
package/dist/index.d.ts CHANGED
@@ -269,7 +269,15 @@ export declare type InferValue<T> = T extends readonly (infer Section)[] ? Union
269
269
 
270
270
  declare type LLMFunction = ((mode: "create" | "assignment" | "review" | "view") => string) | ((mode: "create" | "assignment" | "review" | "view") => Promise<string>);
271
271
 
272
- declare type LLMToolExecuteFunction = (toolName: string, toolArguments: any) => any;
272
+ declare type LLMToolCallDescriptionFunction = (toolName: string, toolArguments: any) => string | Promise<string>;
273
+
274
+ declare type LLMToolExecuteFunction = (toolName: string, toolArguments: any) => {
275
+ result: any;
276
+ success: boolean;
277
+ } | Promise<{
278
+ result: any;
279
+ success: boolean;
280
+ }>;
273
281
 
274
282
  declare type LLMToolFunction = ((mode: "create" | "assignment" | "review" | "view") => ChatCompletionTool[]) | ((mode: "create" | "assignment" | "review" | "view") => Promise<ChatCompletionTool[]>);
275
283
 
@@ -301,10 +309,20 @@ declare type LLMV1 = {
301
309
  */
302
310
  getAvailableTools(mode: "create" | "assignment" | "review" | "view"): ChatCompletionTool[];
303
311
  /**
304
- * Le *MetaPlayer* appelle cette méthode pour demander à l'*Application* d'exécuter un outil. La réponse doit être
305
- * sérializable en JSON.
312
+ * Le *MetaPlayer* appelle cette méthode pour demander à l'*Application* d'exécuter un outil. Doit renvoyer le
313
+ * résultat sous forme d'objet (qui doit être sérializable en JSON) ainsi qu'un booléen indiquant si l'opération a
314
+ * réussi (uniquement utilisé pour l'interface utilisateur, la communication de l'échec au LLM doit être gérée
315
+ * dans le résultat, en accord avec la description de l'outil).
316
+ */
317
+ callTool(toolName: string, toolArguments: any): {
318
+ result: any;
319
+ success: boolean;
320
+ };
321
+ /**
322
+ * Le *MetaPlayer* appelle cette méthode pour demander à l'*Application* la description courte d'un appel
323
+ * d'outil (à afficher à l'utilisateur dans la fenêtre de chat).
306
324
  */
307
- callTool(toolName: string, toolArguments: any): any;
325
+ getToolCallDescription(toolName: string, toolArguments: any): string;
308
326
  };
309
327
  };
310
328
 
@@ -387,11 +405,17 @@ export declare const useGetLoadedTextContent: () => () => string | null;
387
405
 
388
406
  export declare const useJsonActivityContentSaveFunction: (fn: () => any) => void;
389
407
 
390
- export declare const useJsonActivitySplitContentSaveFunction: (fn: () => any) => void;
408
+ export declare const useJsonActivitySplitContentSaveFunction: (fn: () => {
409
+ content: any;
410
+ binaryData: any;
411
+ }) => void;
391
412
 
392
413
  export declare const useJsonAssignmentContentSaveFunction: (fn: () => any) => void;
393
414
 
394
- export declare const useJsonAssignmentSplitContentSaveFunction: (fn: () => any) => void;
415
+ export declare const useJsonAssignmentSplitContentSaveFunction: (fn: () => {
416
+ content: any;
417
+ binaryData: any;
418
+ }) => void;
395
419
 
396
420
  export declare const useJsonContentSaveFunction: (fn: () => any) => void;
397
421
 
@@ -399,7 +423,7 @@ export declare const useLLMAllMessagesContext: (fn: LLMFunction, deps: readonly
399
423
 
400
424
  export declare const useLLMFirstMessageContext: (fn: LLMFunction, deps: readonly unknown[]) => void;
401
425
 
402
- export declare const useLLMTools: (available: LLMToolFunction, execute: LLMToolExecuteFunction, deps: readonly unknown[]) => void;
426
+ export declare const useLLMTools: (available: LLMToolFunction, execute: LLMToolExecuteFunction, describe: LLMToolCallDescriptionFunction, deps: readonly unknown[]) => void;
403
427
 
404
428
  export declare const useLoadedJsonActivityBinaryData: () => any;
405
429