@capytale/iframe-react 1.1.18 → 1.1.19
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/dist/index.cjs.js +1 -1
- package/dist/index.es.js +196 -186
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=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 r(o){if(!o||!o.data)return;if(!ve(n,o.origin)){console.warn(`Invalid origin '${o.origin}' for comlink proxy`);return}const{id:s,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=se(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:s}),C),f==="RELEASE"&&(t.removeEventListener("message",r),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:s}),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:s}=o;if(!s||!s.id)return;const f=n.get(s.id);if(f)try{f(s)}finally{n.delete(s.id)}}),H(e,n,[],t)}function L(e){if(e)throw new Error("Proxy has been released and is not useable")}function oe(e){return x(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=[],r=function(){}){let o=!1;const s=new Proxy(r,{get(f,c){if(L(o),c===pe)return()=>{be(s),oe(e),t.clear(),o=!0};if(c==="then"){if(n.length===0)return{then:()=>s};const g=x(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){L(o);const[d,u]=$(g);return x(e,t,{type:"SET",path:[...n,c].map(m=>m.toString()),value:d},u).then(R)},apply(f,c,g){L(o);const d=n[n.length-1];if(d===me)return x(e,t,{type:"ENDPOINT"}).then(R);if(d==="bind")return H(e,t,n.slice(0,-1));const[u,m]=U(g);return x(e,t,{type:"APPLY",path:n.map(C=>C.toString()),argumentList:u},m).then(R)},construct(f,c){L(o);const[g,d]=U(c);return x(e,t,{type:"CONSTRUCT",path:n.map(u=>u.toString()),argumentList:g},d).then(R)}});return Ae(s,e),s}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 re=new WeakMap;function he(e,t){return re.set(e,t),e}function se(e){return Object.assign(e,{[X]:!0})}function Ee(e,t=globalThis,n="*"){return{postMessage:(r,o)=>e.postMessage(r,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[r,o]=n.serialize(e);return[{type:"HANDLER",name:t,value:r},o]}return[{type:"RAW",value:e},re.get(e)||[]]}function R(e){switch(e.type){case"HANDLER":return ee.get(e.name).deserialize(e.value);case"RAW":return e.value}}function x(e,t,n,r){return new Promise(o=>{const s=Fe();t.set(s,o),e.start&&e.start(),e.postMessage(Object.assign({id:s},n),r)})}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,r,o,s;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(r==null)throw new Error(f("No handler for declare"));r(m)},done(){if(o==null)throw new Error(f("No handler for done"));o()},provide(m,C,S){if(s==null)throw new Error(f("No handler for provide"));s(m,C,S)}},u),c=ne(u),g=!0}const d=()=>{if(!n){if(r==null||o==null||s==null)return;n=!0,c.ready()}};return{declare:u=>c.declare(u),done:()=>c.done(),provide:(u,m,C)=>c.provide(u,m,se(C)),get name(){return e},get isReady(){return g},set onDeclare(u){r=u,d()},set onDone(u){o=u,d()},set onProvide(u){s=u,d()}}}function ke(e){return function(t){let n,r=!1,o=!1,s,f,c=!1,g=!1,d,u,m,C;function S(){if(s!=null&&s!==0&&f!=null)return f}function E(a){if(s!=null&&f!=null&&!(a>s))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 s},get i(){return S()},v:a=>E(a)}),d}function T(){return u===void 0&&(u={get name(){return t},get version(){return g?s:void 0},get i(){return g?S():void 0},v:a=>g?E(a):void 0,get promise(){return s===0?Promise.reject(e("Remote interface not provided")):w().then(()=>{if(s===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 r},set localVersionSent(a){if(!a&&r)throw new Error(e("Local version already notified"));r=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(s!=null)return s},set remoteVersion(a){if(s!=null&&s!==a)throw new Error(e("A different remote version is already set for "+t+`(${s} -> ${a})`));s=a,a===0&&(c=!0)},get remoteVersionReceived(){return s!=null},setRemoteInterface:a=>{if(s==null)throw new Error(e("Remote version not set"));if(s===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:()=>T(),get activationPromise(){return w()}}}}function xe(e){return function(t,n,r,o){let s=r,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?s(d):s(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,s=null,u}}}}function Te(e){return function(t,n,r,o){let s=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=r?t.map(u=>u.getRemote()):t[0].getRemote();let d;try{d=s(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 Me(e){function t(a){return ie(e.name,a)}const n=Te(t),r=ke(t),o=xe(t),s={},f=[];let c=[],g;const d=()=>(g==null?g=0:g++,g);function u(a){let l=s[a];return l==null&&(l=r(a),l.localVersion==null&&(w&&(l.localVersion=0),J&&(l.localVersionSent=!0)),l.remoteVersion==null&&T&&(l.remoteVersion=0),s[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(s).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=()=>{T||(T=!0,Object.values(s).forEach(a=>{a.remoteVersion==null&&(a.remoteVersion=0)}),F())},e.onProvide=(a,l,p)=>{let v=s[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,T=!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(s).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 s){const p=s[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 s){const p=s[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(s).forEach(l=>{l.localVersion==null&&(l.localVersion=0)}),F())}}}const Le=/^\d+$/;function Ge(e){const[t,n,r]=e.split(":",3);if(n==null||r!=null||!Le.test(n))return null;const o=parseInt(n);return isNaN(o)||o===0?null:{name:t,version:o}}function Pe(e){const t=Me(e);function n(r){return ie(e.name,r)}return{plug(r,o,s=void 0){if(t.done)throw new Error(n("Cannot plug after plugsDone."));s==null&&(s=o,o=[]);let f=!0;Array.isArray(r)||(r=[r],f=!1);const c=r.map(g=>{const d=Ge(g);if(d==null)throw new Error(n("Invalid contract id : "+g));return d});t.declareFactory(c,o,s,f)},plugsDone(){t.done=!0},use(r,o){let s=!0;Array.isArray(r)||(r=[r],s=!1),t.declareCallback(r,o,s)},exec(r,o){let s=!0;return Array.isArray(r)||(r=[r],s=!1),new Promise((...f)=>{t.declareCallback(r,o,s,f)})},get(r){return r.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,r=(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:r,getState:o,getInitialState:()=>g,subscribe:d=>(n.add(d),()=>n.delete(d))},g=t=e(r,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=r=>je(t,r);return Object.assign(n,t),n},ce=e=>e?_(e):_,$e=e=>(t,n,r)=>{const o=r.subscribe;return r.subscribe=(f,c,g)=>{let d=f;if(c){const u=g?.equalityFn||Object.is;let m=f(r.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,r)},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:r})=>{i.setState({loadedJsonActivityContent:e,loadedJsonAssignmentContent:t,loadedJsonActivityBinaryData:n,loadedJsonAssignmentBinaryData:r})},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 r=i.getState().quickActions[e];r?r(t):console.error(`[React bindings] Quick action not found: ${e}`)}else{const r=i.getState().sidebarActions[e];r?r(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],([r])=>{i.subscribe(o=>o.isDirtyCount,()=>{r.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,[]),rt=()=>y.useCallback(()=>({content:i.getState().loadedJsonActivityContent,binaryData:i.getState().loadedJsonActivityBinaryData}),[]),st=()=>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),r=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 s=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(s),r(f)}),()=>{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 P=0,W=0;const Ct=(e,t)=>{const n=y.useMemo(e,t),r=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 s=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(s),r(f)}),()=>{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 V=0;const le=(e,t,n)=>{const r=y.useMemo(e,n),o=i(s=>s.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"],([s])=>{if(s.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),s.i?.setSettingsUI(r)}),o(t),()=>{o(null)}),[r])},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(),r=de();return y.useEffect(()=>{if(e==null)return;const o=n(e);return()=>{o.then(s=>{s!=null&&r(s)})}},[n,r,...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(r=>r.setLlmGetFirstMessageContextFunction);y.useEffect(()=>(n(e),()=>{n(null)}),[t,n])},bt=(e,t)=>{const n=i(r=>r.setLlmGetAllMessagesContextFunction);y.useEffect(()=>(n(e),()=>{n(null)}),[t,n])};function wt(e){const t={};for(const n of e.fields)t[n.name]=n.defaultValue;return t}function ht(e){return{[e.name]:e.defaultValues}}function Et(e){return{[e.name]:e.defaultValue}}function Ft(e){switch(e.type){case"form":return wt(e);case"checkboxes":case"switches":return ht(e);case"radio":return Et(e);default:return{}}}function Rt(e){const t={};for(const n of e)Object.assign(t,Ft(n));return t}function Jt(e){const n=ce()(r=>({...Rt(e)}));return n.activitySettings=e,n}function kt(e){le(()=>e.activitySettings,t=>{e.setState(t)},[])}function xt({store:e}){return kt(e),null}const Tt=["meta-player-events:1","meta-player-ui:1","mode:1","workflow:1"];function Mt({children:e,contracts:t,loadOnlyWhenReady:n=!0,activitySettingsStore:r}){const o=i(s=>s.ready);return y.useEffect(()=>{const s=[...t];for(const f of Tt)s.includes(f)||s.push(f);qe(s)},[]),n&&!o?M.jsx("div",{className:"capy-loading-container",children:"Chargement en cours..."}):M.jsxs(M.Fragment,{children:[r&&M.jsx(xt,{store:r}),e]})}function Lt({message:e}){return ge(e,[e]),null}exports.Capytale=Mt;exports.TemporaryToast=Lt;exports.createActivitySettingsStore=Jt;exports.useAfterSaveAction=gt;exports.useCanSave=St;exports.useClearToast=de;exports.useClearToasts=yt;exports.useGetLoadedJsonActivityContent=nt;exports.useGetLoadedJsonActivitySplitContent=rt;exports.useGetLoadedJsonAssignmentContent=ot;exports.useGetLoadedJsonAssignmentSplitContent=st;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.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"),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;
|
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as Q, jsxs as ft, Fragment as
|
|
2
|
-
import
|
|
3
|
-
const et = Symbol("Comlink.proxy"),
|
|
1
|
+
import { jsx as Q, jsxs as ft, Fragment as mt } from "react/jsx-runtime";
|
|
2
|
+
import L, { useCallback as A, useEffect as w, useMemo as U } from "react";
|
|
3
|
+
const et = Symbol("Comlink.proxy"), pt = Symbol("Comlink.endpoint"), yt = Symbol("Comlink.releaseProxy"), q = Symbol("Comlink.finalizer"), I = Symbol("Comlink.thrown"), nt = (t) => typeof t == "object" && t !== null || typeof t == "function", vt = {
|
|
4
4
|
canHandle: (t) => nt(t) && t[et],
|
|
5
5
|
serialize(t) {
|
|
6
6
|
const { port1: e, port2: n } = new MessageChannel();
|
|
@@ -43,30 +43,30 @@ function _(t, e = globalThis, n = ["*"]) {
|
|
|
43
43
|
console.warn(`Invalid origin '${o.origin}' for comlink proxy`);
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
|
-
const { id: s, type: f, path:
|
|
46
|
+
const { id: s, type: f, path: l } = Object.assign({ path: [] }, o.data), g = (o.data.argumentList || []).map(x);
|
|
47
47
|
let d;
|
|
48
48
|
try {
|
|
49
|
-
const u =
|
|
49
|
+
const u = l.slice(0, -1).reduce((y, C) => y[C], t), m = l.reduce((y, C) => y[C], t);
|
|
50
50
|
switch (f) {
|
|
51
51
|
case "GET":
|
|
52
|
-
d =
|
|
52
|
+
d = m;
|
|
53
53
|
break;
|
|
54
54
|
case "SET":
|
|
55
|
-
u[
|
|
55
|
+
u[l.slice(-1)[0]] = x(o.data.value), d = !0;
|
|
56
56
|
break;
|
|
57
57
|
case "APPLY":
|
|
58
|
-
d =
|
|
58
|
+
d = m.apply(u, g);
|
|
59
59
|
break;
|
|
60
60
|
case "CONSTRUCT":
|
|
61
61
|
{
|
|
62
|
-
const y = new
|
|
63
|
-
d =
|
|
62
|
+
const y = new m(...g);
|
|
63
|
+
d = lt(y);
|
|
64
64
|
}
|
|
65
65
|
break;
|
|
66
66
|
case "ENDPOINT":
|
|
67
67
|
{
|
|
68
68
|
const { port1: y, port2: C } = new MessageChannel();
|
|
69
|
-
_(t, C), d =
|
|
69
|
+
_(t, C), d = Ft(y, [y]);
|
|
70
70
|
}
|
|
71
71
|
break;
|
|
72
72
|
case "RELEASE":
|
|
@@ -79,14 +79,14 @@ function _(t, e = globalThis, n = ["*"]) {
|
|
|
79
79
|
d = { value: u, [I]: 0 };
|
|
80
80
|
}
|
|
81
81
|
Promise.resolve(d).catch((u) => ({ value: u, [I]: 0 })).then((u) => {
|
|
82
|
-
const [
|
|
83
|
-
e.postMessage(Object.assign(Object.assign({},
|
|
82
|
+
const [m, y] = O(u);
|
|
83
|
+
e.postMessage(Object.assign(Object.assign({}, m), { id: s }), y), f === "RELEASE" && (e.removeEventListener("message", r), rt(e), q in t && typeof t[q] == "function" && t[q]());
|
|
84
84
|
}).catch((u) => {
|
|
85
|
-
const [
|
|
85
|
+
const [m, y] = O({
|
|
86
86
|
value: new TypeError("Unserializable return value"),
|
|
87
87
|
[I]: 0
|
|
88
88
|
});
|
|
89
|
-
e.postMessage(Object.assign(Object.assign({},
|
|
89
|
+
e.postMessage(Object.assign(Object.assign({}, m), { id: s }), y);
|
|
90
90
|
});
|
|
91
91
|
}), e.start && e.start();
|
|
92
92
|
}
|
|
@@ -111,7 +111,7 @@ function st(t, e) {
|
|
|
111
111
|
}
|
|
112
112
|
}), z(t, n, [], e);
|
|
113
113
|
}
|
|
114
|
-
function
|
|
114
|
+
function G(t) {
|
|
115
115
|
if (t)
|
|
116
116
|
throw new Error("Proxy has been released and is not useable");
|
|
117
117
|
}
|
|
@@ -137,12 +137,12 @@ function z(t, e, n = [], r = function() {
|
|
|
137
137
|
}) {
|
|
138
138
|
let o = !1;
|
|
139
139
|
const s = new Proxy(r, {
|
|
140
|
-
get(f,
|
|
141
|
-
if (
|
|
140
|
+
get(f, l) {
|
|
141
|
+
if (G(o), l === yt)
|
|
142
142
|
return () => {
|
|
143
143
|
At(s), it(t), e.clear(), o = !0;
|
|
144
144
|
};
|
|
145
|
-
if (
|
|
145
|
+
if (l === "then") {
|
|
146
146
|
if (n.length === 0)
|
|
147
147
|
return { then: () => s };
|
|
148
148
|
const g = T(t, e, {
|
|
@@ -151,36 +151,36 @@ function z(t, e, n = [], r = function() {
|
|
|
151
151
|
}).then(x);
|
|
152
152
|
return g.then.bind(g);
|
|
153
153
|
}
|
|
154
|
-
return z(t, e, [...n,
|
|
154
|
+
return z(t, e, [...n, l]);
|
|
155
155
|
},
|
|
156
|
-
set(f,
|
|
157
|
-
|
|
156
|
+
set(f, l, g) {
|
|
157
|
+
G(o);
|
|
158
158
|
const [d, u] = O(g);
|
|
159
159
|
return T(t, e, {
|
|
160
160
|
type: "SET",
|
|
161
|
-
path: [...n,
|
|
161
|
+
path: [...n, l].map((m) => m.toString()),
|
|
162
162
|
value: d
|
|
163
163
|
}, u).then(x);
|
|
164
164
|
},
|
|
165
|
-
apply(f,
|
|
166
|
-
|
|
165
|
+
apply(f, l, g) {
|
|
166
|
+
G(o);
|
|
167
167
|
const d = n[n.length - 1];
|
|
168
|
-
if (d ===
|
|
168
|
+
if (d === pt)
|
|
169
169
|
return T(t, e, {
|
|
170
170
|
type: "ENDPOINT"
|
|
171
171
|
}).then(x);
|
|
172
172
|
if (d === "bind")
|
|
173
173
|
return z(t, e, n.slice(0, -1));
|
|
174
|
-
const [u,
|
|
174
|
+
const [u, m] = Y(g);
|
|
175
175
|
return T(t, e, {
|
|
176
176
|
type: "APPLY",
|
|
177
177
|
path: n.map((y) => y.toString()),
|
|
178
178
|
argumentList: u
|
|
179
|
-
},
|
|
179
|
+
}, m).then(x);
|
|
180
180
|
},
|
|
181
|
-
construct(f,
|
|
182
|
-
|
|
183
|
-
const [g, d] = Y(
|
|
181
|
+
construct(f, l) {
|
|
182
|
+
G(o);
|
|
183
|
+
const [g, d] = Y(l);
|
|
184
184
|
return T(t, e, {
|
|
185
185
|
type: "CONSTRUCT",
|
|
186
186
|
path: n.map((u) => u.toString()),
|
|
@@ -198,13 +198,13 @@ function Y(t) {
|
|
|
198
198
|
return [e.map((n) => n[0]), ht(e.map((n) => n[1]))];
|
|
199
199
|
}
|
|
200
200
|
const at = /* @__PURE__ */ new WeakMap();
|
|
201
|
-
function
|
|
201
|
+
function Ft(t, e) {
|
|
202
202
|
return at.set(t, e), t;
|
|
203
203
|
}
|
|
204
|
-
function
|
|
204
|
+
function lt(t) {
|
|
205
205
|
return Object.assign(t, { [et]: !0 });
|
|
206
206
|
}
|
|
207
|
-
function
|
|
207
|
+
function Rt(t, e = globalThis, n = "*") {
|
|
208
208
|
return {
|
|
209
209
|
postMessage: (r, o) => t.postMessage(r, n, o),
|
|
210
210
|
addEventListener: e.addEventListener.bind(e),
|
|
@@ -257,9 +257,9 @@ function kt(t, e) {
|
|
|
257
257
|
function f(u) {
|
|
258
258
|
return xt(t, u);
|
|
259
259
|
}
|
|
260
|
-
let
|
|
260
|
+
let l, g = !1;
|
|
261
261
|
if (window.parent === window)
|
|
262
|
-
console.warn(f("Contract link is not supported in standalone mode")),
|
|
262
|
+
console.warn(f("Contract link is not supported in standalone mode")), l = {
|
|
263
263
|
ready() {
|
|
264
264
|
return Promise.resolve();
|
|
265
265
|
},
|
|
@@ -269,37 +269,37 @@ function kt(t, e) {
|
|
|
269
269
|
done() {
|
|
270
270
|
return Promise.resolve();
|
|
271
271
|
},
|
|
272
|
-
provide(u,
|
|
272
|
+
provide(u, m, y) {
|
|
273
273
|
return Promise.resolve();
|
|
274
274
|
}
|
|
275
275
|
};
|
|
276
276
|
else {
|
|
277
|
-
const u =
|
|
277
|
+
const u = Rt(window.parent, void 0, e);
|
|
278
278
|
_({
|
|
279
|
-
declare(
|
|
279
|
+
declare(m) {
|
|
280
280
|
if (r == null) throw new Error(f("No handler for declare"));
|
|
281
|
-
r(
|
|
281
|
+
r(m);
|
|
282
282
|
},
|
|
283
283
|
done() {
|
|
284
284
|
if (o == null) throw new Error(f("No handler for done"));
|
|
285
285
|
o();
|
|
286
286
|
},
|
|
287
|
-
provide(
|
|
287
|
+
provide(m, y, C) {
|
|
288
288
|
if (s == null) throw new Error(f("No handler for provide"));
|
|
289
|
-
s(
|
|
289
|
+
s(m, y, C);
|
|
290
290
|
}
|
|
291
|
-
}, u),
|
|
291
|
+
}, u), l = st(u), g = !0;
|
|
292
292
|
}
|
|
293
293
|
const d = () => {
|
|
294
294
|
if (!n) {
|
|
295
295
|
if (r == null || o == null || s == null) return;
|
|
296
|
-
n = !0,
|
|
296
|
+
n = !0, l.ready();
|
|
297
297
|
}
|
|
298
298
|
};
|
|
299
299
|
return {
|
|
300
|
-
declare: (u) =>
|
|
301
|
-
done: () =>
|
|
302
|
-
provide: (u,
|
|
300
|
+
declare: (u) => l.declare(u),
|
|
301
|
+
done: () => l.done(),
|
|
302
|
+
provide: (u, m, y) => l.provide(u, m, lt(y)),
|
|
303
303
|
get name() {
|
|
304
304
|
return t;
|
|
305
305
|
},
|
|
@@ -319,17 +319,17 @@ function kt(t, e) {
|
|
|
319
319
|
}
|
|
320
320
|
function Jt(t) {
|
|
321
321
|
return function(e) {
|
|
322
|
-
let n, r = !1, o = !1, s, f,
|
|
322
|
+
let n, r = !1, o = !1, s, f, l = !1, g = !1, d, u, m, y;
|
|
323
323
|
function C() {
|
|
324
324
|
if (s != null && s !== 0 && f != null)
|
|
325
325
|
return f;
|
|
326
326
|
}
|
|
327
|
-
function
|
|
327
|
+
function R(a) {
|
|
328
328
|
if (s != null && f != null && !(a > s))
|
|
329
329
|
return f;
|
|
330
330
|
}
|
|
331
331
|
function h() {
|
|
332
|
-
return
|
|
332
|
+
return m ?? (g ? m = Promise.resolve() : m = new Promise((a, c) => {
|
|
333
333
|
y = a;
|
|
334
334
|
}));
|
|
335
335
|
}
|
|
@@ -344,7 +344,7 @@ function Jt(t) {
|
|
|
344
344
|
get i() {
|
|
345
345
|
return C();
|
|
346
346
|
},
|
|
347
|
-
v: (a) =>
|
|
347
|
+
v: (a) => R(a)
|
|
348
348
|
}), d;
|
|
349
349
|
}
|
|
350
350
|
function M() {
|
|
@@ -358,7 +358,7 @@ function Jt(t) {
|
|
|
358
358
|
get i() {
|
|
359
359
|
return g ? C() : void 0;
|
|
360
360
|
},
|
|
361
|
-
v: (a) => g ?
|
|
361
|
+
v: (a) => g ? R(a) : void 0,
|
|
362
362
|
get promise() {
|
|
363
363
|
return s === 0 ? Promise.reject(t("Remote interface not provided")) : h().then(() => {
|
|
364
364
|
if (s === 0) throw new Error(t("Remote interface not provided"));
|
|
@@ -403,7 +403,7 @@ function Jt(t) {
|
|
|
403
403
|
},
|
|
404
404
|
set remoteVersion(a) {
|
|
405
405
|
if (s != null && s !== a) throw new Error(t("A different remote version is already set for " + e + `(${s} -> ${a})`));
|
|
406
|
-
s = a, a === 0 && (
|
|
406
|
+
s = a, a === 0 && (l = !0);
|
|
407
407
|
},
|
|
408
408
|
get remoteVersionReceived() {
|
|
409
409
|
return s != null;
|
|
@@ -414,22 +414,22 @@ function Jt(t) {
|
|
|
414
414
|
console.warn(t("Remote version is 0, remote interface is ignored."));
|
|
415
415
|
return;
|
|
416
416
|
}
|
|
417
|
-
if (
|
|
418
|
-
f = a,
|
|
417
|
+
if (l) throw new Error(t("Interface already provided."));
|
|
418
|
+
f = a, l = !0;
|
|
419
419
|
},
|
|
420
420
|
get remoteInterfaceReceived() {
|
|
421
|
-
return
|
|
421
|
+
return l;
|
|
422
422
|
},
|
|
423
423
|
depGroup: void 0,
|
|
424
424
|
get isActivable() {
|
|
425
|
-
return
|
|
425
|
+
return l && o;
|
|
426
426
|
},
|
|
427
427
|
get isActivated() {
|
|
428
428
|
return g;
|
|
429
429
|
},
|
|
430
430
|
activate() {
|
|
431
431
|
if (!g) {
|
|
432
|
-
if (!
|
|
432
|
+
if (!l) throw new Error(t("Remote interface not provided."));
|
|
433
433
|
if (!o) throw new Error(t("Local interface not sent"));
|
|
434
434
|
g = !0, E();
|
|
435
435
|
}
|
|
@@ -444,18 +444,18 @@ function Jt(t) {
|
|
|
444
444
|
}
|
|
445
445
|
function Tt(t) {
|
|
446
446
|
return function(e, n, r, o) {
|
|
447
|
-
let s = r, f = !1,
|
|
447
|
+
let s = r, f = !1, l = !1;
|
|
448
448
|
function g() {
|
|
449
449
|
return e.every((d) => d.remoteVersionReceived && d.localVersionSent) && n.every((d) => d.remoteVersionReceived);
|
|
450
450
|
}
|
|
451
451
|
return {
|
|
452
452
|
get isDeclared() {
|
|
453
|
-
return
|
|
453
|
+
return l;
|
|
454
454
|
},
|
|
455
455
|
set isDeclared(d) {
|
|
456
|
-
if (!d &&
|
|
456
|
+
if (!d && l)
|
|
457
457
|
throw new Error(t("Factory already declared"));
|
|
458
|
-
|
|
458
|
+
l = d;
|
|
459
459
|
},
|
|
460
460
|
get isReady() {
|
|
461
461
|
return g();
|
|
@@ -477,9 +477,9 @@ function Tt(t) {
|
|
|
477
477
|
let d;
|
|
478
478
|
o ? d = e.map((y) => y.getRemote()) : d = e[0].getRemote();
|
|
479
479
|
let u;
|
|
480
|
-
const
|
|
480
|
+
const m = n.length > 0 ? n.map((y) => y.getRemote()) : null;
|
|
481
481
|
try {
|
|
482
|
-
u =
|
|
482
|
+
u = m == null ? s(d) : s(d, m);
|
|
483
483
|
} catch (y) {
|
|
484
484
|
throw new Error(t("error in factory:"), { cause: y });
|
|
485
485
|
}
|
|
@@ -493,12 +493,12 @@ function Tt(t) {
|
|
|
493
493
|
function Mt(t) {
|
|
494
494
|
return function(e, n, r, o) {
|
|
495
495
|
let s = n, f = !1;
|
|
496
|
-
function
|
|
496
|
+
function l() {
|
|
497
497
|
return e.every((g) => g.isActivated);
|
|
498
498
|
}
|
|
499
499
|
return {
|
|
500
500
|
get isReady() {
|
|
501
|
-
return
|
|
501
|
+
return l();
|
|
502
502
|
},
|
|
503
503
|
get isDone() {
|
|
504
504
|
return f;
|
|
@@ -507,7 +507,7 @@ function Mt(t) {
|
|
|
507
507
|
return e;
|
|
508
508
|
},
|
|
509
509
|
invoke() {
|
|
510
|
-
if (f || !
|
|
510
|
+
if (f || !l()) {
|
|
511
511
|
const u = new Error(t(f ? "callback already invoked" : "callback parameters are not ready"));
|
|
512
512
|
throw o?.[1](u), u;
|
|
513
513
|
}
|
|
@@ -525,103 +525,103 @@ function Mt(t) {
|
|
|
525
525
|
};
|
|
526
526
|
};
|
|
527
527
|
}
|
|
528
|
-
function
|
|
528
|
+
function ct(t, e) {
|
|
529
529
|
return t == null || t.length === 0 ? e : `[${t}] ${e}`;
|
|
530
530
|
}
|
|
531
|
-
function
|
|
531
|
+
function Lt(t) {
|
|
532
532
|
function e(a) {
|
|
533
|
-
return
|
|
533
|
+
return ct(t.name, a);
|
|
534
534
|
}
|
|
535
535
|
const n = Mt(e), r = Jt(e), o = Tt(e), s = {}, f = [];
|
|
536
|
-
let
|
|
536
|
+
let l = [], g;
|
|
537
537
|
const d = () => (g == null ? g = 0 : g++, g);
|
|
538
538
|
function u(a) {
|
|
539
|
-
let
|
|
540
|
-
return
|
|
539
|
+
let c = s[a];
|
|
540
|
+
return c == null && (c = r(a), c.localVersion == null && (h && (c.localVersion = 0), k && (c.localVersionSent = !0)), c.remoteVersion == null && M && (c.remoteVersion = 0), s[a] = c), c;
|
|
541
541
|
}
|
|
542
|
-
function
|
|
542
|
+
function m(a) {
|
|
543
543
|
return a.map(u);
|
|
544
544
|
}
|
|
545
545
|
function y(...a) {
|
|
546
|
-
const
|
|
546
|
+
const c = d(), p = Array(c).fill(!1);
|
|
547
547
|
a.forEach((v) => {
|
|
548
548
|
v.forEach((S) => {
|
|
549
|
-
S.depGroup != null && (
|
|
549
|
+
S.depGroup != null && (p[S.depGroup] = !0), S.depGroup = c;
|
|
550
550
|
});
|
|
551
551
|
}), Object.values(s).forEach((v) => {
|
|
552
|
-
v.depGroup != null && v.depGroup !==
|
|
552
|
+
v.depGroup != null && v.depGroup !== c && p[v.depGroup] && (v.depGroup = c);
|
|
553
553
|
});
|
|
554
554
|
}
|
|
555
555
|
t.onDeclare = (a) => {
|
|
556
|
-
const
|
|
557
|
-
for (let
|
|
558
|
-
a[
|
|
559
|
-
y(
|
|
556
|
+
const c = m(a.map((p) => p.name));
|
|
557
|
+
for (let p = 0; p < a.length; p++)
|
|
558
|
+
a[p].version != null && (c[p].remoteVersion = a[p].version);
|
|
559
|
+
y(c), E();
|
|
560
560
|
}, t.onDone = () => {
|
|
561
561
|
M || (M = !0, Object.values(s).forEach((a) => {
|
|
562
562
|
a.remoteVersion == null && (a.remoteVersion = 0);
|
|
563
563
|
}), E());
|
|
564
|
-
}, t.onProvide = (a,
|
|
564
|
+
}, t.onProvide = (a, c, p) => {
|
|
565
565
|
let v = s[a];
|
|
566
566
|
if (v == null)
|
|
567
567
|
throw new Error(e(`Contract not declared : ${a}`));
|
|
568
|
-
if (v.remoteVersion !=
|
|
569
|
-
throw new Error(e(`Remote declared version ${v.remoteVersion} of contract "${a}" but provided version ${
|
|
568
|
+
if (v.remoteVersion != c)
|
|
569
|
+
throw new Error(e(`Remote declared version ${v.remoteVersion} of contract "${a}" but provided version ${c}.`));
|
|
570
570
|
if (v.remoteInterfaceReceived)
|
|
571
571
|
throw new Error(e(`Remote contract "${a}" is already provided.`));
|
|
572
|
-
v.setRemoteInterface(
|
|
572
|
+
v.setRemoteInterface(p), E();
|
|
573
573
|
};
|
|
574
|
-
let C = !1,
|
|
574
|
+
let C = !1, R = !1, h = !1, k = !1, M = !1;
|
|
575
575
|
async function E() {
|
|
576
|
-
if (
|
|
577
|
-
for (C = !0;
|
|
578
|
-
if (
|
|
579
|
-
const a = f.filter((
|
|
576
|
+
if (R = !0, !C) {
|
|
577
|
+
for (C = !0; R; ) {
|
|
578
|
+
if (R = !1, t.isReady) {
|
|
579
|
+
const a = f.filter((c) => !c.isDeclared);
|
|
580
580
|
if (a.length > 0)
|
|
581
|
-
for (const
|
|
582
|
-
const
|
|
583
|
-
|
|
581
|
+
for (const c of a) {
|
|
582
|
+
const p = Array(c.args.length + c.deps.length);
|
|
583
|
+
c.args.forEach((v, S) => p[S] = v), c.deps.forEach((v, S) => p[S + c.args.length] = v), await t.declare(p.map((v) => ({ name: v.name, version: v.localVersion }))), p.forEach((v) => {
|
|
584
584
|
v.localVersion != null && (v.localVersionSent = !0);
|
|
585
|
-
}),
|
|
585
|
+
}), c.isDeclared = !0;
|
|
586
586
|
}
|
|
587
587
|
}
|
|
588
588
|
if (t.isReady && h && f.every((a) => a.isDeclared)) {
|
|
589
|
-
const a = Object.values(s).filter((
|
|
589
|
+
const a = Object.values(s).filter((c) => !c.localVersionSent && c.localVersion != null);
|
|
590
590
|
if (a.length > 0)
|
|
591
|
-
for (const
|
|
592
|
-
await t.declare([{ name:
|
|
591
|
+
for (const c of a)
|
|
592
|
+
await t.declare([{ name: c.name, version: c.localVersion }]), c.localVersionSent = !0;
|
|
593
593
|
k || (k = !0, await t.done());
|
|
594
594
|
}
|
|
595
595
|
if (t.isReady) {
|
|
596
|
-
const a = f.filter((
|
|
596
|
+
const a = f.filter((c) => !c.isDone && c.isReady);
|
|
597
597
|
if (a.length > 0)
|
|
598
|
-
for (const
|
|
599
|
-
const
|
|
600
|
-
for (let v = 0; v <
|
|
601
|
-
const S =
|
|
602
|
-
await t.provide(S.name, S.localVersion,
|
|
598
|
+
for (const c of a) {
|
|
599
|
+
const p = c.invoke();
|
|
600
|
+
for (let v = 0; v < c.args.length; v++) {
|
|
601
|
+
const S = c.args[v];
|
|
602
|
+
await t.provide(S.name, S.localVersion, p[v]), S.localInterfaceSent = !0;
|
|
603
603
|
}
|
|
604
604
|
}
|
|
605
605
|
}
|
|
606
606
|
if (g != null) {
|
|
607
607
|
const a = Array(g + 1).fill(null);
|
|
608
|
-
for (const
|
|
609
|
-
const
|
|
610
|
-
|
|
608
|
+
for (const c in s) {
|
|
609
|
+
const p = s[c];
|
|
610
|
+
p.depGroup != null && (p.isActivable ? a[p.depGroup] == null && !p.isActivated && (a[p.depGroup] = !0) : a[p.depGroup] = !1);
|
|
611
611
|
}
|
|
612
|
-
if (a.some((
|
|
613
|
-
for (const
|
|
614
|
-
const
|
|
615
|
-
|
|
612
|
+
if (a.some((c) => c === !0))
|
|
613
|
+
for (const c in s) {
|
|
614
|
+
const p = s[c];
|
|
615
|
+
p.depGroup != null && a[p.depGroup] && p.activate();
|
|
616
616
|
}
|
|
617
617
|
}
|
|
618
618
|
if (t.isReady) {
|
|
619
|
-
const a =
|
|
620
|
-
|
|
621
|
-
const
|
|
622
|
-
for (const
|
|
623
|
-
!
|
|
624
|
-
|
|
619
|
+
const a = l;
|
|
620
|
+
l = [];
|
|
621
|
+
const c = [];
|
|
622
|
+
for (const p of a)
|
|
623
|
+
!p.isDone && p.isReady ? p.invoke() : c.push(p);
|
|
624
|
+
c.push(...l), l = c;
|
|
625
625
|
}
|
|
626
626
|
}
|
|
627
627
|
C = !1;
|
|
@@ -631,24 +631,24 @@ function Gt(t) {
|
|
|
631
631
|
get(a) {
|
|
632
632
|
return u(a);
|
|
633
633
|
},
|
|
634
|
-
declareFactory: (a,
|
|
634
|
+
declareFactory: (a, c, p, v) => {
|
|
635
635
|
if (h) throw new Error(e("Cannot declare a factory after done has been set to true."));
|
|
636
|
-
const S =
|
|
636
|
+
const S = m(a.map((F) => F.name));
|
|
637
637
|
{
|
|
638
|
-
const
|
|
639
|
-
if (
|
|
640
|
-
throw new Error(e("Cannot declare a factory for already implemented contracts : " +
|
|
638
|
+
const F = S.filter((N) => N.localVersion != null);
|
|
639
|
+
if (F.length > 0)
|
|
640
|
+
throw new Error(e("Cannot declare a factory for already implemented contracts : " + F.map((N) => N.name).join(", ")));
|
|
641
641
|
}
|
|
642
|
-
for (let
|
|
643
|
-
S[
|
|
644
|
-
const J =
|
|
642
|
+
for (let F = 0; F < a.length; F++)
|
|
643
|
+
S[F].localVersion = a[F].version;
|
|
644
|
+
const J = m(c);
|
|
645
645
|
y(S, J);
|
|
646
|
-
const gt = o(S, J,
|
|
646
|
+
const gt = o(S, J, p, v);
|
|
647
647
|
f.push(gt), E();
|
|
648
648
|
},
|
|
649
|
-
declareCallback(a,
|
|
650
|
-
const S =
|
|
651
|
-
!C &&
|
|
649
|
+
declareCallback(a, c, p, v) {
|
|
650
|
+
const S = m(a), J = n(S, c, p, v);
|
|
651
|
+
!C && l.length === 0 && J.isReady ? J.invoke() : (l.push(J), E());
|
|
652
652
|
},
|
|
653
653
|
get done() {
|
|
654
654
|
return h;
|
|
@@ -657,23 +657,23 @@ function Gt(t) {
|
|
|
657
657
|
if (h) {
|
|
658
658
|
if (!a) throw new Error(e("Cannot set done to false after it has been set to true."));
|
|
659
659
|
} else
|
|
660
|
-
a && (h = !0, Object.values(s).forEach((
|
|
661
|
-
|
|
660
|
+
a && (h = !0, Object.values(s).forEach((c) => {
|
|
661
|
+
c.localVersion == null && (c.localVersion = 0);
|
|
662
662
|
}), E());
|
|
663
663
|
}
|
|
664
664
|
};
|
|
665
665
|
}
|
|
666
|
-
const
|
|
666
|
+
const Gt = /^\d+$/;
|
|
667
667
|
function Pt(t) {
|
|
668
668
|
const [e, n, r] = t.split(":", 3);
|
|
669
|
-
if (n == null || r != null || !
|
|
669
|
+
if (n == null || r != null || !Gt.test(n)) return null;
|
|
670
670
|
const o = parseInt(n);
|
|
671
671
|
return isNaN(o) || o === 0 ? null : { name: e, version: o };
|
|
672
672
|
}
|
|
673
673
|
function Vt(t) {
|
|
674
|
-
const e =
|
|
674
|
+
const e = Lt(t);
|
|
675
675
|
function n(r) {
|
|
676
|
-
return
|
|
676
|
+
return ct(t.name, r);
|
|
677
677
|
}
|
|
678
678
|
return {
|
|
679
679
|
plug(r, o, s = void 0) {
|
|
@@ -681,13 +681,13 @@ function Vt(t) {
|
|
|
681
681
|
s == null && (s = o, o = []);
|
|
682
682
|
let f = !0;
|
|
683
683
|
Array.isArray(r) || (r = [r], f = !1);
|
|
684
|
-
const
|
|
684
|
+
const l = r.map((g) => {
|
|
685
685
|
const d = Pt(g);
|
|
686
686
|
if (d == null)
|
|
687
687
|
throw new Error(n("Invalid contract id : " + g));
|
|
688
688
|
return d;
|
|
689
689
|
});
|
|
690
|
-
e.declareFactory(
|
|
690
|
+
e.declareFactory(l, o, s, f);
|
|
691
691
|
},
|
|
692
692
|
plugsDone() {
|
|
693
693
|
e.done = !0;
|
|
@@ -716,39 +716,39 @@ console.log(`[${ut}@1.0.12] loaded`);
|
|
|
716
716
|
const K = (t) => {
|
|
717
717
|
let e;
|
|
718
718
|
const n = /* @__PURE__ */ new Set(), r = (d, u) => {
|
|
719
|
-
const
|
|
720
|
-
if (!Object.is(
|
|
719
|
+
const m = typeof d == "function" ? d(e) : d;
|
|
720
|
+
if (!Object.is(m, e)) {
|
|
721
721
|
const y = e;
|
|
722
|
-
e = u ?? (typeof
|
|
722
|
+
e = u ?? (typeof m != "object" || m === null) ? m : Object.assign({}, e, m), n.forEach((C) => C(e, y));
|
|
723
723
|
}
|
|
724
|
-
}, o = () => e,
|
|
725
|
-
return
|
|
724
|
+
}, o = () => e, l = { setState: r, getState: o, getInitialState: () => g, subscribe: (d) => (n.add(d), () => n.delete(d)) }, g = e = t(r, o, l);
|
|
725
|
+
return l;
|
|
726
726
|
}, It = (t) => t ? K(t) : K, jt = (t) => t;
|
|
727
727
|
function $t(t, e = jt) {
|
|
728
|
-
const n =
|
|
728
|
+
const n = L.useSyncExternalStore(
|
|
729
729
|
t.subscribe,
|
|
730
|
-
|
|
731
|
-
|
|
730
|
+
L.useCallback(() => e(t.getState()), [t, e]),
|
|
731
|
+
L.useCallback(() => e(t.getInitialState()), [t, e])
|
|
732
732
|
);
|
|
733
|
-
return
|
|
733
|
+
return L.useDebugValue(n), n;
|
|
734
734
|
}
|
|
735
735
|
const X = (t) => {
|
|
736
736
|
const e = It(t), n = (r) => $t(e, r);
|
|
737
737
|
return Object.assign(n, e), n;
|
|
738
738
|
}, dt = (t) => t ? X(t) : X, Ot = (t) => (e, n, r) => {
|
|
739
739
|
const o = r.subscribe;
|
|
740
|
-
return r.subscribe = (f,
|
|
740
|
+
return r.subscribe = (f, l, g) => {
|
|
741
741
|
let d = f;
|
|
742
|
-
if (
|
|
742
|
+
if (l) {
|
|
743
743
|
const u = g?.equalityFn || Object.is;
|
|
744
|
-
let
|
|
744
|
+
let m = f(r.getState());
|
|
745
745
|
d = (y) => {
|
|
746
746
|
const C = f(y);
|
|
747
|
-
if (!u(
|
|
748
|
-
const
|
|
749
|
-
|
|
747
|
+
if (!u(m, C)) {
|
|
748
|
+
const R = m;
|
|
749
|
+
l(m = C, R);
|
|
750
750
|
}
|
|
751
|
-
}, g?.fireImmediately &&
|
|
751
|
+
}, g?.fireImmediately && l(m, m);
|
|
752
752
|
}
|
|
753
753
|
return o(d);
|
|
754
754
|
}, t(e, n, r);
|
|
@@ -1169,7 +1169,7 @@ const re = () => i((t) => {
|
|
|
1169
1169
|
if (t.theme === null)
|
|
1170
1170
|
throw new Error("Theme is not set. Have you used contract 'theme'?");
|
|
1171
1171
|
return t.theme;
|
|
1172
|
-
}), ae = () => i((t) => t.incSaveCount),
|
|
1172
|
+
}), ae = () => i((t) => t.incSaveCount), le = () => i((t) => t.incDirtyCount), ce = () => i((t) => t.loadedTextContent), ue = () => i((t) => t.loadedJsonContent), de = () => i((t) => t.loadedJsonActivityContent), ge = () => i((t) => t.loadedJsonAssignmentContent), fe = () => i((t) => t.loadedJsonActivityBinaryData), me = () => i((t) => t.loadedJsonAssignmentBinaryData), pe = () => A(() => i.getState().loadedTextContent, []), ye = () => A(() => i.getState().loadedJsonContent, []), ve = () => A(() => i.getState().loadedJsonActivityContent, []), Ce = () => A(() => i.getState().loadedJsonAssignmentContent, []), Se = () => A(
|
|
1173
1173
|
() => ({
|
|
1174
1174
|
content: i.getState().loadedJsonActivityContent,
|
|
1175
1175
|
binaryData: i.getState().loadedJsonActivityBinaryData
|
|
@@ -1202,14 +1202,14 @@ const re = () => i((t) => {
|
|
|
1202
1202
|
w(() => {
|
|
1203
1203
|
e(t);
|
|
1204
1204
|
}, [t, e]);
|
|
1205
|
-
},
|
|
1205
|
+
}, Fe = (t) => {
|
|
1206
1206
|
const e = i(
|
|
1207
1207
|
(n) => n.setGetJsonAssignmentContentFunction
|
|
1208
1208
|
);
|
|
1209
1209
|
w(() => {
|
|
1210
1210
|
e(t);
|
|
1211
1211
|
}, [t, e]);
|
|
1212
|
-
},
|
|
1212
|
+
}, Re = (t) => {
|
|
1213
1213
|
const e = i(
|
|
1214
1214
|
(n) => n.setGetJsonActivitySplitContentFunction
|
|
1215
1215
|
);
|
|
@@ -1265,15 +1265,15 @@ const Te = (t, e) => {
|
|
|
1265
1265
|
return;
|
|
1266
1266
|
}
|
|
1267
1267
|
W++;
|
|
1268
|
-
const s = n.map((
|
|
1269
|
-
type:
|
|
1270
|
-
title:
|
|
1271
|
-
icon:
|
|
1268
|
+
const s = n.map((l, g) => ({
|
|
1269
|
+
type: l.type,
|
|
1270
|
+
title: l.title,
|
|
1271
|
+
icon: l.icon,
|
|
1272
1272
|
id: `sa-${W}-${g}`,
|
|
1273
|
-
...
|
|
1273
|
+
...l.type === "file-upload" ? { accept: l.accept } : {}
|
|
1274
1274
|
})), f = {};
|
|
1275
|
-
n.forEach((
|
|
1276
|
-
f[`sa-${W}-${g}`] =
|
|
1275
|
+
n.forEach((l, g) => {
|
|
1276
|
+
f[`sa-${W}-${g}`] = l.action;
|
|
1277
1277
|
}), o.i?.setSidebarActionButtons(s), r(f);
|
|
1278
1278
|
}), () => {
|
|
1279
1279
|
r({}), b.use(["meta-player-ui"], ([o]) => {
|
|
@@ -1303,15 +1303,15 @@ const Me = (t, e) => {
|
|
|
1303
1303
|
return;
|
|
1304
1304
|
}
|
|
1305
1305
|
H++;
|
|
1306
|
-
const s = n.map((
|
|
1307
|
-
type:
|
|
1308
|
-
title:
|
|
1309
|
-
icon:
|
|
1306
|
+
const s = n.map((l, g) => ({
|
|
1307
|
+
type: l.type,
|
|
1308
|
+
title: l.title,
|
|
1309
|
+
icon: l.icon,
|
|
1310
1310
|
id: `qa-${H}-${g}`,
|
|
1311
|
-
...
|
|
1311
|
+
...l.type === "file-upload" ? { accept: l.accept } : {}
|
|
1312
1312
|
})), f = {};
|
|
1313
|
-
n.forEach((
|
|
1314
|
-
f[`qa-${H}-${g}`] =
|
|
1313
|
+
n.forEach((l, g) => {
|
|
1314
|
+
f[`qa-${H}-${g}`] = l.action;
|
|
1315
1315
|
}), o.i?.setQuickActionButtons(s), r(f);
|
|
1316
1316
|
}), () => {
|
|
1317
1317
|
r({}), b.use(["meta-player-ui"], ([o]) => {
|
|
@@ -1370,7 +1370,7 @@ const Wt = (t, e, n) => {
|
|
|
1370
1370
|
return n.i?.clearToast(e);
|
|
1371
1371
|
}),
|
|
1372
1372
|
[]
|
|
1373
|
-
),
|
|
1373
|
+
), Le = () => A(
|
|
1374
1374
|
() => b.exec(["meta-player-ui"], ([e]) => {
|
|
1375
1375
|
if (e.version === 0)
|
|
1376
1376
|
throw console.error(
|
|
@@ -1393,7 +1393,7 @@ const Wt = (t, e, n) => {
|
|
|
1393
1393
|
});
|
|
1394
1394
|
};
|
|
1395
1395
|
}, [n, r, ...e]), null;
|
|
1396
|
-
},
|
|
1396
|
+
}, Ge = () => A(() => b.exec(["trigger-save"], ([e]) => {
|
|
1397
1397
|
if (e.version === 0)
|
|
1398
1398
|
throw console.error(
|
|
1399
1399
|
"[React bindings] Le MétaPlayer ne supporte pas le contrat trigger-save"
|
|
@@ -1415,6 +1415,15 @@ const Wt = (t, e, n) => {
|
|
|
1415
1415
|
w(() => (n(t), () => {
|
|
1416
1416
|
n(null);
|
|
1417
1417
|
}), [e, n]);
|
|
1418
|
+
}, Ie = (t, e, n) => {
|
|
1419
|
+
const r = i(
|
|
1420
|
+
(s) => s.setLlmGetAvailableToolsFunction
|
|
1421
|
+
), o = i(
|
|
1422
|
+
(s) => s.setLlmCallToolFunction
|
|
1423
|
+
);
|
|
1424
|
+
w(() => (r(t), o(e), () => {
|
|
1425
|
+
r(null), o(null);
|
|
1426
|
+
}), [n, r, o]);
|
|
1418
1427
|
};
|
|
1419
1428
|
function _t(t) {
|
|
1420
1429
|
const e = {};
|
|
@@ -1447,7 +1456,7 @@ function Xt(t) {
|
|
|
1447
1456
|
Object.assign(e, Kt(n));
|
|
1448
1457
|
return e;
|
|
1449
1458
|
}
|
|
1450
|
-
function
|
|
1459
|
+
function je(t) {
|
|
1451
1460
|
const n = dt()((r) => ({
|
|
1452
1461
|
...Xt(t)
|
|
1453
1462
|
}));
|
|
@@ -1473,7 +1482,7 @@ const ee = [
|
|
|
1473
1482
|
"mode:1",
|
|
1474
1483
|
"workflow:1"
|
|
1475
1484
|
];
|
|
1476
|
-
function
|
|
1485
|
+
function $e({
|
|
1477
1486
|
children: t,
|
|
1478
1487
|
contracts: e,
|
|
1479
1488
|
loadOnlyWhenReady: n = !0,
|
|
@@ -1485,43 +1494,44 @@ function je({
|
|
|
1485
1494
|
for (const f of ee)
|
|
1486
1495
|
s.includes(f) || s.push(f);
|
|
1487
1496
|
Bt(s);
|
|
1488
|
-
}, []), n && !o ? /* @__PURE__ */ Q("div", { className: "capy-loading-container", children: "Chargement en cours..." }) : /* @__PURE__ */ ft(
|
|
1497
|
+
}, []), n && !o ? /* @__PURE__ */ Q("div", { className: "capy-loading-container", children: "Chargement en cours..." }) : /* @__PURE__ */ ft(mt, { children: [
|
|
1489
1498
|
r && /* @__PURE__ */ Q(te, { store: r }),
|
|
1490
1499
|
t
|
|
1491
1500
|
] });
|
|
1492
1501
|
}
|
|
1493
|
-
function
|
|
1502
|
+
function Oe({ message: t }) {
|
|
1494
1503
|
return Ut(t, [t]), null;
|
|
1495
1504
|
}
|
|
1496
1505
|
export {
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1506
|
+
$e as Capytale,
|
|
1507
|
+
Oe as TemporaryToast,
|
|
1508
|
+
je as createActivitySettingsStore,
|
|
1500
1509
|
xe as useAfterSaveAction,
|
|
1501
1510
|
Pe as useCanSave,
|
|
1502
1511
|
zt as useClearToast,
|
|
1503
|
-
|
|
1512
|
+
Le as useClearToasts,
|
|
1504
1513
|
ve as useGetLoadedJsonActivityContent,
|
|
1505
1514
|
Se as useGetLoadedJsonActivitySplitContent,
|
|
1506
1515
|
Ce as useGetLoadedJsonAssignmentContent,
|
|
1507
1516
|
we as useGetLoadedJsonAssignmentSplitContent,
|
|
1508
1517
|
ye as useGetLoadedJsonContent,
|
|
1509
|
-
|
|
1518
|
+
pe as useGetLoadedTextContent,
|
|
1510
1519
|
he as useJsonActivityContentSaveFunction,
|
|
1511
|
-
|
|
1512
|
-
|
|
1520
|
+
Re as useJsonActivitySplitContentSaveFunction,
|
|
1521
|
+
Fe as useJsonAssignmentContentSaveFunction,
|
|
1513
1522
|
Ee as useJsonAssignmentSplitContentSaveFunction,
|
|
1514
1523
|
Ae as useJsonContentSaveFunction,
|
|
1515
1524
|
De as useLLMAllMessagesContext,
|
|
1516
1525
|
Ve as useLLMFirstMessageContext,
|
|
1526
|
+
Ie as useLLMTools,
|
|
1517
1527
|
fe as useLoadedJsonActivityBinaryData,
|
|
1518
1528
|
de as useLoadedJsonActivityContent,
|
|
1519
|
-
|
|
1529
|
+
me as useLoadedJsonAssignmentBinaryData,
|
|
1520
1530
|
ge as useLoadedJsonAssignmentContent,
|
|
1521
1531
|
ue as useLoadedJsonContent,
|
|
1522
|
-
|
|
1532
|
+
ce as useLoadedTextContent,
|
|
1523
1533
|
re as useMode,
|
|
1524
|
-
|
|
1534
|
+
le as useNotifyIsDirty,
|
|
1525
1535
|
Je as usePreviewImageFile,
|
|
1526
1536
|
ke as usePreviewTextFile,
|
|
1527
1537
|
Me as useQuickActions,
|
|
@@ -1532,6 +1542,6 @@ export {
|
|
|
1532
1542
|
be as useTextContentSaveFunction,
|
|
1533
1543
|
ie as useTheme,
|
|
1534
1544
|
Ut as useToast,
|
|
1535
|
-
|
|
1545
|
+
Ge as useTriggerSave,
|
|
1536
1546
|
se as useWorkflow
|
|
1537
1547
|
};
|