@feltdb/core 0.11.9 → 0.12.0
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/cli/index.js +0 -0
- package/dist/create/server-source/crates/feltdb-wasm/test.db +0 -0
- package/dist/studio-app/assets/{feltdb_wasm-DGGqm9GK.js → feltdb_wasm-DYfWAV0E.js} +1 -1
- package/dist/studio-app/assets/{feltdb_wasm_bg-BYJo87WY.wasm → feltdb_wasm_bg-DHiOUhoQ.wasm} +0 -0
- package/dist/studio-app/assets/{index-qLeZcPW_.js → index-6f6KVx5R.js} +1 -1
- package/dist/studio-app/index.html +1 -1
- package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=class e{static __wrap(t){let n=Object.create(e.prototype);return n.__wbg_ptr=t,O.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,O.unregister(this),e}free(){let e=this.__destroy_into_raw();K.__wbg_jsdb_free(e,0)}acknowledge_peer_operations(e,n){let r=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),i=G,a=K.jsdb_acknowledge_peer_operations(this.__wbg_ptr,r,i,n);return t.__wrap(a)}add_sync_peer(e){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=K.jsdb_add_sync_peer(this.__wbg_ptr,n,r);return t.__wrap(i)}delete(e){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=K.jsdb_delete(this.__wbg_ptr,n,r);return t.__wrap(i)}execute_canonical_query(e,n,r,i){let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),c=G,l=R(r,K.__wbindgen_malloc,K.__wbindgen_realloc),u=G,d=R(i,K.__wbindgen_malloc,K.__wbindgen_realloc),f=G,p=K.jsdb_execute_canonical_query(this.__wbg_ptr,a,o,s,c,l,u,d,f);return t.__wrap(p)}execute_canonical_transaction(e,n){let r=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),i=G,a=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.jsdb_execute_canonical_transaction(this.__wbg_ptr,r,i,a,o);return t.__wrap(s)}execute_semantic_decision(e){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=K.jsdb_execute_semantic_decision(this.__wbg_ptr,n,r);return t.__wrap(i)}get(e){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=K.jsdb_get(this.__wbg_ptr,n,r);return t.__wrap(i)}get_capability_records(e){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=K.jsdb_get_capability_records(this.__wbg_ptr,n,r);return t.__wrap(i)}get_pending_for_peer(e,n){let r=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),i=G,a=K.jsdb_get_pending_for_peer(this.__wbg_ptr,r,i,n);return t.__wrap(a)}get_sequence(){let e=K.jsdb_get_sequence(this.__wbg_ptr);return BigInt.asUintN(64,e)}insert(e,n){let r=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),i=G,a=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.jsdb_insert(this.__wbg_ptr,r,i,a,o);return t.__wrap(s)}instance_id(){let e,t;try{let n=K.jsdb_instance_id(this.__wbg_ptr);return e=n[0],t=n[1],P(n[0],n[1])}finally{K.__wbindgen_free(e,t,1)}}is_auto_indexed(){return K.jsdb_is_auto_indexed(this.__wbg_ptr)!==0}query(e){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=K.jsdb_query(this.__wbg_ptr,n,r);return t.__wrap(i)}remove_sync_peer(e){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=K.jsdb_remove_sync_peer(this.__wbg_ptr,n,r);return t.__wrap(i)}sync_info(){let e=K.jsdb_sync_info(this.__wbg_ptr);return t.__wrap(e)}update(e,n){let r=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),i=G,a=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.jsdb_update(this.__wbg_ptr,r,i,a,o);return t.__wrap(s)}};Symbol.dispose&&(e.prototype[Symbol.dispose]=e.prototype.free);var t=class e{static __wrap(t){let n=Object.create(e.prototype);return n.__wbg_ptr=t,k.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,k.unregister(this),e}free(){let e=this.__destroy_into_raw();K.__wbg_jsresult_free(e,0)}get data(){let e=K.jsresult_data(this.__wbg_ptr),t;return e[0]!==0&&(t=P(e[0],e[1]),K.__wbindgen_free(e[0],e[1]*1,1)),t}get error(){let e=K.jsresult_error(this.__wbg_ptr),t;return e[0]!==0&&(t=P(e[0],e[1]),K.__wbindgen_free(e[0],e[1]*1,1)),t}get success(){return K.jsresult_success(this.__wbg_ptr)!==0}};Symbol.dispose&&(t.prototype[Symbol.dispose]=t.prototype.free);var n=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,A.unregister(this),e}free(){let e=this.__destroy_into_raw();K.__wbg_wasmanalytics_free(e,0)}generate_report(e,t){let n,r;try{let o=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),s=G,c=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G,u=K.wasmanalytics_generate_report(this.__wbg_ptr,o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,z(u[2]);return n=i,r=a,P(i,a)}finally{K.__wbindgen_free(n,r,1)}}get_all_metrics(){let e,t;try{let i=K.wasmanalytics_get_all_metrics(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,z(i[2]);return e=n,t=r,P(n,r)}finally{K.__wbindgen_free(e,t,1)}}get_frequent_fields(e){let t,n;try{let a=K.wasmanalytics_get_frequent_fields(this.__wbg_ptr,e);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,z(a[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}get_index_metrics(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.wasmanalytics_get_index_metrics(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}get_slowest_queries(e){let t,n;try{let a=K.wasmanalytics_get_slowest_queries(this.__wbg_ptr,e);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,z(a[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}constructor(){let e=K.wasmanalytics_new();return this.__wbg_ptr=e,A.register(this,this.__wbg_ptr,this),this}record_index_usage(e,t,n){let r=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),i=G,a=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G;K.wasmanalytics_record_index_usage(this.__wbg_ptr,r,i,a,o,n)}record_query(e,t,n,r,i,a){let o=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),s=G,c=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G;var u=L(a)?0:R(a,K.__wbindgen_malloc,K.__wbindgen_realloc),d=G;let f=K.wasmanalytics_record_query(this.__wbg_ptr,o,s,c,l,n,r,i,u,d);if(f[1])throw z(f[0])}reset(){K.wasmanalytics_reset(this.__wbg_ptr)}};Symbol.dispose&&(n.prototype[Symbol.dispose]=n.prototype.free);var r=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,j.unregister(this),e}free(){let e=this.__destroy_into_raw();K.__wbg_wasmdistributedindexmanager_free(e,0)}create_replicated_index(e,t,n){let r=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),i=G,a=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),c=G,l=K.wasmdistributedindexmanager_create_replicated_index(this.__wbg_ptr,r,i,a,o,s,c);if(l[1])throw z(l[0])}detect_conflicts(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.wasmdistributedindexmanager_detect_conflicts(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}get_replication_status(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.wasmdistributedindexmanager_get_replication_status(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}get_replication_targets(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.wasmdistributedindexmanager_get_replication_targets(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}get_sync_status(){let e,t;try{let i=K.wasmdistributedindexmanager_get_sync_status(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,z(i[2]);return e=n,t=r,P(n,r)}finally{K.__wbindgen_free(e,t,1)}}merge_versions(e){let t=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),n=G,r=K.wasmdistributedindexmanager_merge_versions(this.__wbg_ptr,t,n);if(r[1])throw z(r[0])}constructor(e){let t=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),n=G,r=K.wasmdistributedindexmanager_new(t,n);return this.__wbg_ptr=r,j.register(this,this.__wbg_ptr,this),this}register_peer(e){let t=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),n=G;K.wasmdistributedindexmanager_register_peer(this.__wbg_ptr,t,n)}set_peer_reachable(e,t){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G;K.wasmdistributedindexmanager_set_peer_reachable(this.__wbg_ptr,n,r,t)}};Symbol.dispose&&(r.prototype[Symbol.dispose]=r.prototype.free);var i=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,M.unregister(this),e}free(){let e=this.__destroy_into_raw();K.__wbg_wasmindexmanager_free(e,0)}create_index(e){let t=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),n=G,r=K.wasmindexmanager_create_index(this.__wbg_ptr,t,n);if(r[1])throw z(r[0])}get_stats(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.wasmindexmanager_get_stats(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}list_indexes(){let e,t;try{let i=K.wasmindexmanager_list_indexes(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,z(i[2]);return e=n,t=r,P(n,r)}finally{K.__wbindgen_free(e,t,1)}}constructor(){let e=K.wasmindexmanager_new();return this.__wbg_ptr=e,M.register(this,this.__wbg_ptr,this),this}query_index(e,t,n){let r,i;try{let s=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),c=G,l=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),u=G,d=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),f=G,p=K.wasmindexmanager_query_index(this.__wbg_ptr,s,c,l,u,d,f);var a=p[0],o=p[1];if(p[3])throw a=0,o=0,z(p[2]);return r=a,i=o,P(a,o)}finally{K.__wbindgen_free(r,i,1)}}update_record(e,t,n){let r=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),i=G;var a=L(t)?0:R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G;let s=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),c=G,l=K.wasmindexmanager_update_record(this.__wbg_ptr,r,i,a,o,s,c);if(l[1])throw z(l[0])}};Symbol.dispose&&(i.prototype[Symbol.dispose]=i.prototype.free);var a=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,N.unregister(this),e}free(){let e=this.__destroy_into_raw();K.__wbg_wasmshardmanager_free(e,0)}detect_hotspots(){let e,t;try{let i=K.wasmshardmanager_detect_hotspots(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,z(i[2]);return e=n,t=r,P(n,r)}finally{K.__wbindgen_free(e,t,1)}}generate_rebalance_ops(){let e,t;try{let i=K.wasmshardmanager_generate_rebalance_ops(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,z(i[2]);return e=n,t=r,P(n,r)}finally{K.__wbindgen_free(e,t,1)}}get_all_metrics(){let e,t;try{let i=K.wasmshardmanager_get_all_metrics(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,z(i[2]);return e=n,t=r,P(n,r)}finally{K.__wbindgen_free(e,t,1)}}get_distribution_summary(){let e,t;try{let i=K.wasmshardmanager_get_distribution_summary(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,z(i[2]);return e=n,t=r,P(n,r)}finally{K.__wbindgen_free(e,t,1)}}get_shard_for_key(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.wasmshardmanager_get_shard_for_key(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}initialize_shards(e){let t=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),n=G,r=K.wasmshardmanager_initialize_shards(this.__wbg_ptr,t,n);if(r[1])throw z(r[0])}constructor(e,t){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),a=G,o=K.wasmshardmanager_new(n,r,i,a);return this.__wbg_ptr=o,N.register(this,this.__wbg_ptr,this),this}record_shard_operation(e,t,n,r,i){let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),c=G;K.wasmshardmanager_record_shard_operation(this.__wbg_ptr,a,o,s,c,n,r,i)}};Symbol.dispose&&(a.prototype[Symbol.dispose]=a.prototype.free);function o(e,t){let n,r;try{let o=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),s=G,c=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G,u=K.apply_sync_result(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,z(u[2]);return n=i,r=a,P(i,a)}finally{K.__wbindgen_free(n,r,1)}}function s(e,t,n,r,i,a){let o,s;try{let u=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),d=G,f=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),p=G,m=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),h=G,g=R(r,K.__wbindgen_malloc,K.__wbindgen_realloc),_=G,v=R(i,K.__wbindgen_malloc,K.__wbindgen_realloc),y=G,b=R(a,K.__wbindgen_malloc,K.__wbindgen_realloc),x=G,S=K.authorize_offline(u,d,f,p,m,h,g,_,v,y,b,x);var c=S[0],l=S[1];if(S[3])throw c=0,l=0,z(S[2]);return o=c,s=l,P(c,l)}finally{K.__wbindgen_free(o,s,1)}}function c(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.canonical_bundle_hash(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}function l(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.canonicalize_application_manifest(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}function u(e,t){let n,r;try{let o=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),s=G,c=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G,u=K.compare_state_schemas(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,z(u[2]);return n=i,r=a,P(i,a)}finally{K.__wbindgen_free(n,r,1)}}function d(e,t){let n,r;try{var i=L(e)?0:R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),a=G;let c=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G,u=K.diff_application_revisions(i,a,c,l);var o=u[0],s=u[1];if(u[3])throw o=0,s=0,z(u[2]);return n=o,r=s,P(o,s)}finally{K.__wbindgen_free(n,r,1)}}function f(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.execute_semantic_decision(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}function p(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.hash_application_manifest(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}function m(e,t){let n,r;try{let o=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),s=G,c=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G,u=K.hash_application_runtime(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,z(u[2]);return n=i,r=a,P(i,a)}finally{K.__wbindgen_free(n,r,1)}}function h(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.hash_state_schema(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}function g(t){let n=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=K.open(n,r);if(i[2])throw z(i[1]);return e.__wrap(i[0])}function _(e,t){let n,r;try{let o=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),s=G,c=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G,u=K.resolve_application_runtime(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,z(u[2]);return n=i,r=a,P(i,a)}finally{K.__wbindgen_free(n,r,1)}}function v(e,t,n,r){let i=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),a=G,o=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),s=G,c=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G,u=K.validate_mesh_claim(i,a,o,s,c,l,r);if(u[1])throw z(u[0])}function y(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.validate_semantic_decision_definition(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}function b(e,t){let n,r;try{let o=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),s=G,c=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G,u=K.validate_semantic_decision_result(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,z(u[2]);return n=i,r=a,P(i,a)}finally{K.__wbindgen_free(n,r,1)}}function x(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.validate_state_schema(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}function S(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.validate_sync_operation(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}function C(e,t){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),a=G,o=K.validate_worker_transition(n,r,i,a);if(o[2])throw z(o[1]);return o[0]!==0}function w(e,t){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),a=G,o=K.validate_workload_transition(n,r,i,a);if(o[2])throw z(o[1]);return o[0]!==0}function T(e){let t=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),n=G,r=K.verify_bundle_integrity(t,n);if(r[2])throw z(r[1]);return r[0]!==0}function E(e,t,n,r,i,a){let o,s;try{let u=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),d=G,f=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),p=G,m=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),h=G,g=R(r,K.__wbindgen_malloc,K.__wbindgen_realloc),_=G,v=R(i,K.__wbindgen_malloc,K.__wbindgen_realloc),y=G,b=R(a,K.__wbindgen_malloc,K.__wbindgen_realloc),x=G,S=K.verify_signed_grant(u,d,f,p,m,h,g,_,v,y,b,x);var c=S[0],l=S[1];if(S[3])throw c=0,l=0,z(S[2]);return o=c,s=l,P(c,l)}finally{K.__wbindgen_free(o,s,1)}}function D(){return{__proto__:null,"./feltdb_wasm_bg.js":{__proto__:null,__wbg___wbindgen_throw_bb96b2010945f0bc:function(e,t){throw Error(P(e,t))},__wbindgen_cast_0000000000000001:function(e,t){return P(e,t)},__wbindgen_init_externref_table:function(){let e=K.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,!0),e.set(t+3,!1)}}}}var O=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>K.__wbg_jsdb_free(e,1)),k=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>K.__wbg_jsresult_free(e,1)),A=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>K.__wbg_wasmanalytics_free(e,1)),j=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>K.__wbg_wasmdistributedindexmanager_free(e,1)),M=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>K.__wbg_wasmindexmanager_free(e,1)),N=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>K.__wbg_wasmshardmanager_free(e,1));function P(e,t){return U(e>>>0,t)}var F=null;function I(){return(F===null||F.byteLength===0)&&(F=new Uint8Array(K.memory.buffer)),F}function L(e){return e==null}function R(e,t,n){if(n===void 0){let n=W.encode(e),r=t(n.length,1)>>>0;return I().subarray(r,r+n.length).set(n),G=n.length,r}let r=e.length,i=t(r,1)>>>0,a=I(),o=0;for(;o<r;o++){let t=e.charCodeAt(o);if(t>127)break;a[i+o]=t}if(o!==r){o!==0&&(e=e.slice(o)),i=n(i,r,r=o+e.length*3,1)>>>0;let t=I().subarray(i+o,i+r),a=W.encodeInto(e,t);o+=a.written,i=n(i,r,o,1)>>>0}return G=o,i}function z(e){let t=K.__wbindgen_externrefs.get(e);return K.__externref_table_dealloc(e),t}var B=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0});B.decode();var V=2146435072,H=0;function U(e,t){return H+=t,H>=V&&(B=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0}),B.decode(),H=t),B.decode(I().subarray(e,e+t))}var W=new TextEncoder;`encodeInto`in W||(W.encodeInto=function(e,t){let n=W.encode(e);return t.set(n),{read:e.length,written:n.length}});var G=0,K;function q(e,t){return K=e.exports,F=null,K.__wbindgen_start(),K}async function J(e,t){if(typeof Response==`function`&&e instanceof Response){if(!e.ok)throw Error(`failed to fetch Wasm: ${e.status} ${e.statusText} fetching '${e.url}'`);if(typeof WebAssembly.instantiateStreaming==`function`)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if(n(e.type)&&e.headers.get(`Content-Type`)!==`application/wasm`)console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",t);else throw t}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}{let n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}function n(e){switch(e){case`basic`:case`cors`:case`default`:return!0}return!1}}function Y(e){if(K!==void 0)return K;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module:e}=e:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let t=D();return e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e)),q(new WebAssembly.Instance(e,t),e)}async function X(e){if(K!==void 0)return K;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn(`using deprecated parameters for the initialization function; pass a single object instead`)),e===void 0&&(e=new URL(`/assets/feltdb_wasm_bg-BYJo87WY.wasm`,``+import.meta.url));let t=D();(typeof e==`string`||typeof Request==`function`&&e instanceof Request||typeof URL==`function`&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:r}=await J(await e,t);return q(n,r)}export{e as JsDb,t as JsResult,n as WasmAnalytics,r as WasmDistributedIndexManager,i as WasmIndexManager,a as WasmShardManager,o as apply_sync_result,s as authorize_offline,c as canonical_bundle_hash,l as canonicalize_application_manifest,u as compare_state_schemas,X as default,d as diff_application_revisions,f as execute_semantic_decision,p as hash_application_manifest,m as hash_application_runtime,h as hash_state_schema,Y as initSync,g as open,_ as resolve_application_runtime,v as validate_mesh_claim,y as validate_semantic_decision_definition,b as validate_semantic_decision_result,x as validate_state_schema,S as validate_sync_operation,C as validate_worker_transition,w as validate_workload_transition,T as verify_bundle_integrity,E as verify_signed_grant};
|
|
1
|
+
var e=class e{static __wrap(t){let n=Object.create(e.prototype);return n.__wbg_ptr=t,O.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,O.unregister(this),e}free(){let e=this.__destroy_into_raw();K.__wbg_jsdb_free(e,0)}acknowledge_peer_operations(e,n){let r=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),i=G,a=K.jsdb_acknowledge_peer_operations(this.__wbg_ptr,r,i,n);return t.__wrap(a)}add_sync_peer(e){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=K.jsdb_add_sync_peer(this.__wbg_ptr,n,r);return t.__wrap(i)}delete(e){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=K.jsdb_delete(this.__wbg_ptr,n,r);return t.__wrap(i)}execute_canonical_query(e,n,r,i){let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),c=G,l=R(r,K.__wbindgen_malloc,K.__wbindgen_realloc),u=G,d=R(i,K.__wbindgen_malloc,K.__wbindgen_realloc),f=G,p=K.jsdb_execute_canonical_query(this.__wbg_ptr,a,o,s,c,l,u,d,f);return t.__wrap(p)}execute_canonical_transaction(e,n){let r=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),i=G,a=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.jsdb_execute_canonical_transaction(this.__wbg_ptr,r,i,a,o);return t.__wrap(s)}execute_semantic_decision(e){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=K.jsdb_execute_semantic_decision(this.__wbg_ptr,n,r);return t.__wrap(i)}get(e){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=K.jsdb_get(this.__wbg_ptr,n,r);return t.__wrap(i)}get_capability_records(e){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=K.jsdb_get_capability_records(this.__wbg_ptr,n,r);return t.__wrap(i)}get_pending_for_peer(e,n){let r=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),i=G,a=K.jsdb_get_pending_for_peer(this.__wbg_ptr,r,i,n);return t.__wrap(a)}get_sequence(){let e=K.jsdb_get_sequence(this.__wbg_ptr);return BigInt.asUintN(64,e)}insert(e,n){let r=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),i=G,a=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.jsdb_insert(this.__wbg_ptr,r,i,a,o);return t.__wrap(s)}instance_id(){let e,t;try{let n=K.jsdb_instance_id(this.__wbg_ptr);return e=n[0],t=n[1],P(n[0],n[1])}finally{K.__wbindgen_free(e,t,1)}}is_auto_indexed(){return K.jsdb_is_auto_indexed(this.__wbg_ptr)!==0}query(e){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=K.jsdb_query(this.__wbg_ptr,n,r);return t.__wrap(i)}remove_sync_peer(e){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=K.jsdb_remove_sync_peer(this.__wbg_ptr,n,r);return t.__wrap(i)}sync_info(){let e=K.jsdb_sync_info(this.__wbg_ptr);return t.__wrap(e)}update(e,n){let r=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),i=G,a=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.jsdb_update(this.__wbg_ptr,r,i,a,o);return t.__wrap(s)}};Symbol.dispose&&(e.prototype[Symbol.dispose]=e.prototype.free);var t=class e{static __wrap(t){let n=Object.create(e.prototype);return n.__wbg_ptr=t,k.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,k.unregister(this),e}free(){let e=this.__destroy_into_raw();K.__wbg_jsresult_free(e,0)}get data(){let e=K.jsresult_data(this.__wbg_ptr),t;return e[0]!==0&&(t=P(e[0],e[1]),K.__wbindgen_free(e[0],e[1]*1,1)),t}get error(){let e=K.jsresult_error(this.__wbg_ptr),t;return e[0]!==0&&(t=P(e[0],e[1]),K.__wbindgen_free(e[0],e[1]*1,1)),t}get success(){return K.jsresult_success(this.__wbg_ptr)!==0}};Symbol.dispose&&(t.prototype[Symbol.dispose]=t.prototype.free);var n=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,A.unregister(this),e}free(){let e=this.__destroy_into_raw();K.__wbg_wasmanalytics_free(e,0)}generate_report(e,t){let n,r;try{let o=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),s=G,c=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G,u=K.wasmanalytics_generate_report(this.__wbg_ptr,o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,z(u[2]);return n=i,r=a,P(i,a)}finally{K.__wbindgen_free(n,r,1)}}get_all_metrics(){let e,t;try{let i=K.wasmanalytics_get_all_metrics(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,z(i[2]);return e=n,t=r,P(n,r)}finally{K.__wbindgen_free(e,t,1)}}get_frequent_fields(e){let t,n;try{let a=K.wasmanalytics_get_frequent_fields(this.__wbg_ptr,e);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,z(a[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}get_index_metrics(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.wasmanalytics_get_index_metrics(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}get_slowest_queries(e){let t,n;try{let a=K.wasmanalytics_get_slowest_queries(this.__wbg_ptr,e);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,z(a[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}constructor(){let e=K.wasmanalytics_new();return this.__wbg_ptr=e,A.register(this,this.__wbg_ptr,this),this}record_index_usage(e,t,n){let r=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),i=G,a=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G;K.wasmanalytics_record_index_usage(this.__wbg_ptr,r,i,a,o,n)}record_query(e,t,n,r,i,a){let o=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),s=G,c=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G;var u=L(a)?0:R(a,K.__wbindgen_malloc,K.__wbindgen_realloc),d=G;let f=K.wasmanalytics_record_query(this.__wbg_ptr,o,s,c,l,n,r,i,u,d);if(f[1])throw z(f[0])}reset(){K.wasmanalytics_reset(this.__wbg_ptr)}};Symbol.dispose&&(n.prototype[Symbol.dispose]=n.prototype.free);var r=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,j.unregister(this),e}free(){let e=this.__destroy_into_raw();K.__wbg_wasmdistributedindexmanager_free(e,0)}create_replicated_index(e,t,n){let r=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),i=G,a=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),c=G,l=K.wasmdistributedindexmanager_create_replicated_index(this.__wbg_ptr,r,i,a,o,s,c);if(l[1])throw z(l[0])}detect_conflicts(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.wasmdistributedindexmanager_detect_conflicts(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}get_replication_status(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.wasmdistributedindexmanager_get_replication_status(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}get_replication_targets(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.wasmdistributedindexmanager_get_replication_targets(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}get_sync_status(){let e,t;try{let i=K.wasmdistributedindexmanager_get_sync_status(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,z(i[2]);return e=n,t=r,P(n,r)}finally{K.__wbindgen_free(e,t,1)}}merge_versions(e){let t=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),n=G,r=K.wasmdistributedindexmanager_merge_versions(this.__wbg_ptr,t,n);if(r[1])throw z(r[0])}constructor(e){let t=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),n=G,r=K.wasmdistributedindexmanager_new(t,n);return this.__wbg_ptr=r,j.register(this,this.__wbg_ptr,this),this}register_peer(e){let t=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),n=G;K.wasmdistributedindexmanager_register_peer(this.__wbg_ptr,t,n)}set_peer_reachable(e,t){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G;K.wasmdistributedindexmanager_set_peer_reachable(this.__wbg_ptr,n,r,t)}};Symbol.dispose&&(r.prototype[Symbol.dispose]=r.prototype.free);var i=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,M.unregister(this),e}free(){let e=this.__destroy_into_raw();K.__wbg_wasmindexmanager_free(e,0)}create_index(e){let t=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),n=G,r=K.wasmindexmanager_create_index(this.__wbg_ptr,t,n);if(r[1])throw z(r[0])}get_stats(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.wasmindexmanager_get_stats(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}list_indexes(){let e,t;try{let i=K.wasmindexmanager_list_indexes(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,z(i[2]);return e=n,t=r,P(n,r)}finally{K.__wbindgen_free(e,t,1)}}constructor(){let e=K.wasmindexmanager_new();return this.__wbg_ptr=e,M.register(this,this.__wbg_ptr,this),this}query_index(e,t,n){let r,i;try{let s=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),c=G,l=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),u=G,d=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),f=G,p=K.wasmindexmanager_query_index(this.__wbg_ptr,s,c,l,u,d,f);var a=p[0],o=p[1];if(p[3])throw a=0,o=0,z(p[2]);return r=a,i=o,P(a,o)}finally{K.__wbindgen_free(r,i,1)}}update_record(e,t,n){let r=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),i=G;var a=L(t)?0:R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G;let s=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),c=G,l=K.wasmindexmanager_update_record(this.__wbg_ptr,r,i,a,o,s,c);if(l[1])throw z(l[0])}};Symbol.dispose&&(i.prototype[Symbol.dispose]=i.prototype.free);var a=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,N.unregister(this),e}free(){let e=this.__destroy_into_raw();K.__wbg_wasmshardmanager_free(e,0)}detect_hotspots(){let e,t;try{let i=K.wasmshardmanager_detect_hotspots(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,z(i[2]);return e=n,t=r,P(n,r)}finally{K.__wbindgen_free(e,t,1)}}generate_rebalance_ops(){let e,t;try{let i=K.wasmshardmanager_generate_rebalance_ops(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,z(i[2]);return e=n,t=r,P(n,r)}finally{K.__wbindgen_free(e,t,1)}}get_all_metrics(){let e,t;try{let i=K.wasmshardmanager_get_all_metrics(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,z(i[2]);return e=n,t=r,P(n,r)}finally{K.__wbindgen_free(e,t,1)}}get_distribution_summary(){let e,t;try{let i=K.wasmshardmanager_get_distribution_summary(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,z(i[2]);return e=n,t=r,P(n,r)}finally{K.__wbindgen_free(e,t,1)}}get_shard_for_key(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.wasmshardmanager_get_shard_for_key(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}initialize_shards(e){let t=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),n=G,r=K.wasmshardmanager_initialize_shards(this.__wbg_ptr,t,n);if(r[1])throw z(r[0])}constructor(e,t){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),a=G,o=K.wasmshardmanager_new(n,r,i,a);return this.__wbg_ptr=o,N.register(this,this.__wbg_ptr,this),this}record_shard_operation(e,t,n,r,i){let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),c=G;K.wasmshardmanager_record_shard_operation(this.__wbg_ptr,a,o,s,c,n,r,i)}};Symbol.dispose&&(a.prototype[Symbol.dispose]=a.prototype.free);function o(e,t){let n,r;try{let o=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),s=G,c=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G,u=K.apply_sync_result(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,z(u[2]);return n=i,r=a,P(i,a)}finally{K.__wbindgen_free(n,r,1)}}function s(e,t,n,r,i,a){let o,s;try{let u=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),d=G,f=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),p=G,m=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),h=G,g=R(r,K.__wbindgen_malloc,K.__wbindgen_realloc),_=G,v=R(i,K.__wbindgen_malloc,K.__wbindgen_realloc),y=G,b=R(a,K.__wbindgen_malloc,K.__wbindgen_realloc),x=G,S=K.authorize_offline(u,d,f,p,m,h,g,_,v,y,b,x);var c=S[0],l=S[1];if(S[3])throw c=0,l=0,z(S[2]);return o=c,s=l,P(c,l)}finally{K.__wbindgen_free(o,s,1)}}function c(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.canonical_bundle_hash(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}function l(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.canonicalize_application_manifest(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}function u(e,t){let n,r;try{let o=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),s=G,c=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G,u=K.compare_state_schemas(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,z(u[2]);return n=i,r=a,P(i,a)}finally{K.__wbindgen_free(n,r,1)}}function d(e,t){let n,r;try{var i=L(e)?0:R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),a=G;let c=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G,u=K.diff_application_revisions(i,a,c,l);var o=u[0],s=u[1];if(u[3])throw o=0,s=0,z(u[2]);return n=o,r=s,P(o,s)}finally{K.__wbindgen_free(n,r,1)}}function f(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.execute_semantic_decision(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}function p(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.hash_application_manifest(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}function m(e,t){let n,r;try{let o=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),s=G,c=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G,u=K.hash_application_runtime(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,z(u[2]);return n=i,r=a,P(i,a)}finally{K.__wbindgen_free(n,r,1)}}function h(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.hash_state_schema(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}function g(t){let n=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=K.open(n,r);if(i[2])throw z(i[1]);return e.__wrap(i[0])}function _(e,t){let n,r;try{let o=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),s=G,c=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G,u=K.resolve_application_runtime(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,z(u[2]);return n=i,r=a,P(i,a)}finally{K.__wbindgen_free(n,r,1)}}function v(e,t,n,r){let i=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),a=G,o=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),s=G,c=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G,u=K.validate_mesh_claim(i,a,o,s,c,l,r);if(u[1])throw z(u[0])}function y(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.validate_semantic_decision_definition(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}function b(e,t){let n,r;try{let o=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),s=G,c=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),l=G,u=K.validate_semantic_decision_result(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,z(u[2]);return n=i,r=a,P(i,a)}finally{K.__wbindgen_free(n,r,1)}}function x(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.validate_state_schema(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}function S(e){let t,n;try{let a=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),o=G,s=K.validate_sync_operation(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,z(s[2]);return t=r,n=i,P(r,i)}finally{K.__wbindgen_free(t,n,1)}}function C(e,t){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),a=G,o=K.validate_worker_transition(n,r,i,a);if(o[2])throw z(o[1]);return o[0]!==0}function w(e,t){let n=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),r=G,i=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),a=G,o=K.validate_workload_transition(n,r,i,a);if(o[2])throw z(o[1]);return o[0]!==0}function T(e){let t=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),n=G,r=K.verify_bundle_integrity(t,n);if(r[2])throw z(r[1]);return r[0]!==0}function E(e,t,n,r,i,a){let o,s;try{let u=R(e,K.__wbindgen_malloc,K.__wbindgen_realloc),d=G,f=R(t,K.__wbindgen_malloc,K.__wbindgen_realloc),p=G,m=R(n,K.__wbindgen_malloc,K.__wbindgen_realloc),h=G,g=R(r,K.__wbindgen_malloc,K.__wbindgen_realloc),_=G,v=R(i,K.__wbindgen_malloc,K.__wbindgen_realloc),y=G,b=R(a,K.__wbindgen_malloc,K.__wbindgen_realloc),x=G,S=K.verify_signed_grant(u,d,f,p,m,h,g,_,v,y,b,x);var c=S[0],l=S[1];if(S[3])throw c=0,l=0,z(S[2]);return o=c,s=l,P(c,l)}finally{K.__wbindgen_free(o,s,1)}}function D(){return{__proto__:null,"./feltdb_wasm_bg.js":{__proto__:null,__wbg___wbindgen_throw_bb96b2010945f0bc:function(e,t){throw Error(P(e,t))},__wbindgen_cast_0000000000000001:function(e,t){return P(e,t)},__wbindgen_init_externref_table:function(){let e=K.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,!0),e.set(t+3,!1)}}}}var O=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>K.__wbg_jsdb_free(e,1)),k=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>K.__wbg_jsresult_free(e,1)),A=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>K.__wbg_wasmanalytics_free(e,1)),j=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>K.__wbg_wasmdistributedindexmanager_free(e,1)),M=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>K.__wbg_wasmindexmanager_free(e,1)),N=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>K.__wbg_wasmshardmanager_free(e,1));function P(e,t){return U(e>>>0,t)}var F=null;function I(){return(F===null||F.byteLength===0)&&(F=new Uint8Array(K.memory.buffer)),F}function L(e){return e==null}function R(e,t,n){if(n===void 0){let n=W.encode(e),r=t(n.length,1)>>>0;return I().subarray(r,r+n.length).set(n),G=n.length,r}let r=e.length,i=t(r,1)>>>0,a=I(),o=0;for(;o<r;o++){let t=e.charCodeAt(o);if(t>127)break;a[i+o]=t}if(o!==r){o!==0&&(e=e.slice(o)),i=n(i,r,r=o+e.length*3,1)>>>0;let t=I().subarray(i+o,i+r),a=W.encodeInto(e,t);o+=a.written,i=n(i,r,o,1)>>>0}return G=o,i}function z(e){let t=K.__wbindgen_externrefs.get(e);return K.__externref_table_dealloc(e),t}var B=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0});B.decode();var V=2146435072,H=0;function U(e,t){return H+=t,H>=V&&(B=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0}),B.decode(),H=t),B.decode(I().subarray(e,e+t))}var W=new TextEncoder;`encodeInto`in W||(W.encodeInto=function(e,t){let n=W.encode(e);return t.set(n),{read:e.length,written:n.length}});var G=0,K;function q(e,t){return K=e.exports,F=null,K.__wbindgen_start(),K}async function J(e,t){if(typeof Response==`function`&&e instanceof Response){if(!e.ok)throw Error(`failed to fetch Wasm: ${e.status} ${e.statusText} fetching '${e.url}'`);if(typeof WebAssembly.instantiateStreaming==`function`)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if(n(e.type)&&e.headers.get(`Content-Type`)!==`application/wasm`)console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",t);else throw t}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}{let n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}function n(e){switch(e){case`basic`:case`cors`:case`default`:return!0}return!1}}function Y(e){if(K!==void 0)return K;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module:e}=e:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let t=D();return e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e)),q(new WebAssembly.Instance(e,t),e)}async function X(e){if(K!==void 0)return K;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn(`using deprecated parameters for the initialization function; pass a single object instead`)),e===void 0&&(e=new URL(`/assets/feltdb_wasm_bg-DHiOUhoQ.wasm`,``+import.meta.url));let t=D();(typeof e==`string`||typeof Request==`function`&&e instanceof Request||typeof URL==`function`&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:r}=await J(await e,t);return q(n,r)}export{e as JsDb,t as JsResult,n as WasmAnalytics,r as WasmDistributedIndexManager,i as WasmIndexManager,a as WasmShardManager,o as apply_sync_result,s as authorize_offline,c as canonical_bundle_hash,l as canonicalize_application_manifest,u as compare_state_schemas,X as default,d as diff_application_revisions,f as execute_semantic_decision,p as hash_application_manifest,m as hash_application_runtime,h as hash_state_schema,Y as initSync,g as open,_ as resolve_application_runtime,v as validate_mesh_claim,y as validate_semantic_decision_definition,b as validate_semantic_decision_result,x as validate_state_schema,S as validate_sync_operation,C as validate_worker_transition,w as validate_workload_transition,T as verify_bundle_integrity,E as verify_signed_grant};
|
package/dist/studio-app/assets/{feltdb_wasm_bg-BYJo87WY.wasm → feltdb_wasm_bg-DHiOUhoQ.wasm}
RENAMED
|
Binary file
|
|
@@ -7,7 +7,7 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
|
|
|
7
7
|
Error generating stack: `+e.message+`
|
|
8
8
|
`+e.stack}return{value:e,source:t,stack:i,digest:null}}function Cs(e,t,n){return{value:e,source:null,stack:n??null,digest:t??null}}function ws(e,t){try{console.error(t.value)}catch(e){setTimeout(function(){throw e})}}var Ts=typeof WeakMap==`function`?WeakMap:Map;function Es(e,t,n){n=io(-1,n),n.tag=3,n.payload={element:null};var r=t.value;return n.callback=function(){nl||(nl=!0,rl=r),ws(e,t)},n}function Ds(e,t,n){n=io(-1,n),n.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r==`function`){var i=t.value;n.payload=function(){return r(i)},n.callback=function(){ws(e,t)}}var a=e.stateNode;return a!==null&&typeof a.componentDidCatch==`function`&&(n.callback=function(){ws(e,t),typeof r!=`function`&&(il===null?il=new Set([this]):il.add(this));var n=t.stack;this.componentDidCatch(t.value,{componentStack:n===null?``:n})}),n}function Os(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new Ts;var i=new Set;r.set(t,i)}else i=r.get(t),i===void 0&&(i=new Set,r.set(t,i));i.has(n)||(i.add(n),e=zl.bind(null,e,t,n),t.then(e,e))}function ks(e){do{var t;if((t=e.tag===13)&&(t=e.memoizedState,t=t===null||t.dehydrated!==null),t)return e;e=e.return}while(e!==null);return null}function As(e,t,n,r,i){return e.mode&1?(e.flags|=65536,e.lanes=i,e):(e===t?e.flags|=65536:(e.flags|=128,n.flags|=131072,n.flags&=-52805,n.tag===1&&(n.alternate===null?n.tag=17:(t=io(-1,1),t.tag=2,ao(n,t,1))),n.lanes|=1),e)}var js=C.ReactCurrentOwner,Ms=!1;function Ns(e,t,n,r){t.child=e===null?Va(t,null,n,r):Ba(t,e.child,n,r)}function Ps(e,t,n,r,i){n=n.render;var a=t.ref;return Ya(t,i),r=Fo(e,t,n,r,a,i),n=Io(),e!==null&&!Ms?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,ec(e,t,i)):(W&&n&&xa(t),t.flags|=1,Ns(e,t,r,i),t.child)}function Fs(e,t,n,r,i){if(e===null){var a=n.type;return typeof a==`function`&&!ql(a)&&a.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(t.tag=15,t.type=a,Is(e,t,a,r,i)):(e=Xl(n.type,null,r,t,t.mode,i),e.ref=t.ref,e.return=t,t.child=e)}if(a=e.child,(e.lanes&i)===0){var o=a.memoizedProps;if(n=n.compare,n=n===null?Fr:n,n(o,r)&&e.ref===t.ref)return ec(e,t,i)}return t.flags|=1,e=Yl(a,r),e.ref=t.ref,e.return=t,t.child=e}function Is(e,t,n,r,i){if(e!==null){var a=e.memoizedProps;if(Fr(a,r)&&e.ref===t.ref){if(Ms=!1,t.pendingProps=r=a,(e.lanes&i)!==0)e.flags&131072&&(Ms=!0);else return t.lanes=e.lanes,ec(e,t,i)}}return zs(e,t,n,r,i)}function Ls(e,t,n){var r=t.pendingProps,i=r.children,a=e===null?null:e.memoizedState;if(r.mode===`hidden`){if(!(t.mode&1))t.memoizedState={baseLanes:0,cachePool:null,transitions:null},U(Gc,Wc),Wc|=n;else{if(!(n&1073741824))return e=a===null?n:a.baseLanes|n,t.lanes=t.childLanes=1073741824,t.memoizedState={baseLanes:e,cachePool:null,transitions:null},t.updateQueue=null,U(Gc,Wc),Wc|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=a===null?n:a.baseLanes,U(Gc,Wc),Wc|=r}}else a===null?r=n:(r=a.baseLanes|n,t.memoizedState=null),U(Gc,Wc),Wc|=r;return Ns(e,t,i,n),t.child}function Rs(e,t){var n=t.ref;(e===null&&n!==null||e!==null&&e.ref!==n)&&(t.flags|=512,t.flags|=2097152)}function zs(e,t,n,r,i){var a=Qi(n)?Xi:Ji.current;return a=Zi(t,a),Ya(t,i),n=Fo(e,t,n,r,a,i),r=Io(),e!==null&&!Ms?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,ec(e,t,i)):(W&&r&&xa(t),t.flags|=1,Ns(e,t,n,i),t.child)}function Bs(e,t,n,r,i){if(Qi(n)){var a=!0;na(t)}else a=!1;if(Ya(t,i),t.stateNode===null)$s(e,t),ys(t,n,r),xs(t,n,r,i),r=!0;else if(e===null){var o=t.stateNode,s=t.memoizedProps;o.props=s;var c=o.context,l=n.contextType;typeof l==`object`&&l?l=Xa(l):(l=Qi(n)?Xi:Ji.current,l=Zi(t,l));var u=n.getDerivedStateFromProps,d=typeof u==`function`||typeof o.getSnapshotBeforeUpdate==`function`;d||typeof o.UNSAFE_componentWillReceiveProps!=`function`&&typeof o.componentWillReceiveProps!=`function`||(s!==r||c!==l)&&bs(t,o,r,l),to=!1;var f=t.memoizedState;o.state=f,co(t,r,o,i),c=t.memoizedState,s!==r||f!==c||Yi.current||to?(typeof u==`function`&&(gs(t,n,u,r),c=t.memoizedState),(s=to||vs(t,n,s,r,f,c,l))?(d||typeof o.UNSAFE_componentWillMount!=`function`&&typeof o.componentWillMount!=`function`||(typeof o.componentWillMount==`function`&&o.componentWillMount(),typeof o.UNSAFE_componentWillMount==`function`&&o.UNSAFE_componentWillMount()),typeof o.componentDidMount==`function`&&(t.flags|=4194308)):(typeof o.componentDidMount==`function`&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=c),o.props=r,o.state=c,o.context=l,r=s):(typeof o.componentDidMount==`function`&&(t.flags|=4194308),r=!1)}else{o=t.stateNode,ro(e,t),s=t.memoizedProps,l=t.type===t.elementType?s:hs(t.type,s),o.props=l,d=t.pendingProps,f=o.context,c=n.contextType,typeof c==`object`&&c?c=Xa(c):(c=Qi(n)?Xi:Ji.current,c=Zi(t,c));var p=n.getDerivedStateFromProps;(u=typeof p==`function`||typeof o.getSnapshotBeforeUpdate==`function`)||typeof o.UNSAFE_componentWillReceiveProps!=`function`&&typeof o.componentWillReceiveProps!=`function`||(s!==d||f!==c)&&bs(t,o,r,c),to=!1,f=t.memoizedState,o.state=f,co(t,r,o,i);var m=t.memoizedState;s!==d||f!==m||Yi.current||to?(typeof p==`function`&&(gs(t,n,p,r),m=t.memoizedState),(l=to||vs(t,n,l,r,f,m,c)||!1)?(u||typeof o.UNSAFE_componentWillUpdate!=`function`&&typeof o.componentWillUpdate!=`function`||(typeof o.componentWillUpdate==`function`&&o.componentWillUpdate(r,m,c),typeof o.UNSAFE_componentWillUpdate==`function`&&o.UNSAFE_componentWillUpdate(r,m,c)),typeof o.componentDidUpdate==`function`&&(t.flags|=4),typeof o.getSnapshotBeforeUpdate==`function`&&(t.flags|=1024)):(typeof o.componentDidUpdate!=`function`||s===e.memoizedProps&&f===e.memoizedState||(t.flags|=4),typeof o.getSnapshotBeforeUpdate!=`function`||s===e.memoizedProps&&f===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=m),o.props=r,o.state=m,o.context=c,r=l):(typeof o.componentDidUpdate!=`function`||s===e.memoizedProps&&f===e.memoizedState||(t.flags|=4),typeof o.getSnapshotBeforeUpdate!=`function`||s===e.memoizedProps&&f===e.memoizedState||(t.flags|=1024),r=!1)}return Vs(e,t,n,r,a,i)}function Vs(e,t,n,r,i,a){Rs(e,t);var o=!!(t.flags&128);if(!r&&!o)return i&&ra(t,n,!1),ec(e,t,a);r=t.stateNode,js.current=t;var s=o&&typeof n.getDerivedStateFromError!=`function`?null:r.render();return t.flags|=1,e!==null&&o?(t.child=Ba(t,e.child,null,a),t.child=Ba(t,null,s,a)):Ns(e,t,s,a),t.memoizedState=r.state,i&&ra(t,n,!0),t.child}function Hs(e){var t=e.stateNode;t.pendingContext?ea(e,t.pendingContext,t.pendingContext!==t.context):t.context&&ea(e,t.context,!1),go(e,t.containerInfo)}function Us(e,t,n,r,i){return Na(),Pa(i),t.flags|=256,Ns(e,t,n,r),t.child}var Ws={dehydrated:null,treeContext:null,retryLane:0};function Gs(e){return{baseLanes:e,cachePool:null,transitions:null}}function Ks(e,t,n){var r=t.pendingProps,i=bo.current,a=!1,o=!!(t.flags&128),s;if((s=o)||(s=e!==null&&e.memoizedState===null?!1:!!(i&2)),s?(a=!0,t.flags&=-129):(e===null||e.memoizedState!==null)&&(i|=1),U(bo,i&1),e===null)return ka(t),e=t.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(t.lanes=t.mode&1?e.data===`$!`?8:1073741824:1,null):(o=r.children,e=r.fallback,a?(r=t.mode,a=t.child,o={mode:`hidden`,children:o},!(r&1)&&a!==null?(a.childLanes=0,a.pendingProps=o):a=Ql(o,r,0,null),e=Zl(e,r,n,null),a.return=t,e.return=t,a.sibling=e,t.child=a,t.child.memoizedState=Gs(n),t.memoizedState=Ws,e):qs(t,o));if(i=e.memoizedState,i!==null&&(s=i.dehydrated,s!==null))return Ys(e,t,o,r,s,i,n);if(a){a=r.fallback,o=t.mode,i=e.child,s=i.sibling;var c={mode:`hidden`,children:r.children};return!(o&1)&&t.child!==i?(r=t.child,r.childLanes=0,r.pendingProps=c,t.deletions=null):(r=Yl(i,c),r.subtreeFlags=i.subtreeFlags&14680064),s===null?(a=Zl(a,o,n,null),a.flags|=2):a=Yl(s,a),a.return=t,r.return=t,r.sibling=a,t.child=r,r=a,a=t.child,o=e.child.memoizedState,o=o===null?Gs(n):{baseLanes:o.baseLanes|n,cachePool:null,transitions:o.transitions},a.memoizedState=o,a.childLanes=e.childLanes&~n,t.memoizedState=Ws,r}return a=e.child,e=a.sibling,r=Yl(a,{mode:`visible`,children:r.children}),!(t.mode&1)&&(r.lanes=n),r.return=t,r.sibling=null,e!==null&&(n=t.deletions,n===null?(t.deletions=[e],t.flags|=16):n.push(e)),t.child=r,t.memoizedState=null,r}function qs(e,t){return t=Ql({mode:`visible`,children:t},e.mode,0,null),t.return=e,e.child=t}function Js(e,t,n,r){return r!==null&&Pa(r),Ba(t,e.child,null,n),e=qs(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function Ys(e,t,n,i,a,o,s){if(n)return t.flags&256?(t.flags&=-257,i=Cs(Error(r(422))),Js(e,t,s,i)):t.memoizedState===null?(o=i.fallback,a=t.mode,i=Ql({mode:`visible`,children:i.children},a,0,null),o=Zl(o,a,s,null),o.flags|=2,i.return=t,o.return=t,i.sibling=o,t.child=i,t.mode&1&&Ba(t,e.child,null,s),t.child.memoizedState=Gs(s),t.memoizedState=Ws,o):(t.child=e.child,t.flags|=128,null);if(!(t.mode&1))return Js(e,t,s,null);if(a.data===`$!`){if(i=a.nextSibling&&a.nextSibling.dataset,i)var c=i.dgst;return i=c,o=Error(r(419)),i=Cs(o,i,void 0),Js(e,t,s,i)}if(c=(s&e.childLanes)!==0,Ms||c){if(i=Vc,i!==null){switch(s&-s){case 4:a=2;break;case 16:a=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:a=32;break;case 536870912:a=268435456;break;default:a=0}a=(a&(i.suspendedLanes|s))===0?a:0,a!==0&&a!==o.retryLane&&(o.retryLane=a,eo(e,a),ml(i,e,a,-1))}return Ol(),i=Cs(Error(r(421))),Js(e,t,s,i)}return a.data===`$?`?(t.flags|=128,t.child=e.child,t=Vl.bind(null,e),a._reactRetry=t,null):(e=o.treeContext,wa=Mi(a.nextSibling),Ca=t,W=!0,Ta=null,e!==null&&(ma[ha++]=_a,ma[ha++]=va,ma[ha++]=ga,_a=e.id,va=e.overflow,ga=t),t=qs(t,i.children),t.flags|=4096,t)}function Xs(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),Ja(e.return,t,n)}function Zs(e,t,n,r,i){var a=e.memoizedState;a===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:i}:(a.isBackwards=t,a.rendering=null,a.renderingStartTime=0,a.last=r,a.tail=n,a.tailMode=i)}function Qs(e,t,n){var r=t.pendingProps,i=r.revealOrder,a=r.tail;if(Ns(e,t,r.children,n),r=bo.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)a:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&Xs(e,n,t);else if(e.tag===19)Xs(e,n,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break a;for(;e.sibling===null;){if(e.return===null||e.return===t)break a;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(U(bo,r),!(t.mode&1))t.memoizedState=null;else switch(i){case`forwards`:for(n=t.child,i=null;n!==null;)e=n.alternate,e!==null&&xo(e)===null&&(i=n),n=n.sibling;n=i,n===null?(i=t.child,t.child=null):(i=n.sibling,n.sibling=null),Zs(t,!1,i,n,a);break;case`backwards`:for(n=null,i=t.child,t.child=null;i!==null;){if(e=i.alternate,e!==null&&xo(e)===null){t.child=i;break}e=i.sibling,i.sibling=n,n=i,i=e}Zs(t,!0,n,null,a);break;case`together`:Zs(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function $s(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function ec(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),Jc|=t.lanes,(n&t.childLanes)===0)return null;if(e!==null&&t.child!==e.child)throw Error(r(153));if(t.child!==null){for(e=t.child,n=Yl(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=Yl(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function tc(e,t,n){switch(t.tag){case 3:Hs(t),Na();break;case 5:vo(t);break;case 1:Qi(t.type)&&na(t);break;case 4:go(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,i=t.memoizedProps.value;U(Ha,r._currentValue),r._currentValue=i;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated===null?(n&t.child.childLanes)===0?(U(bo,bo.current&1),e=ec(e,t,n),e===null?null:e.sibling):Ks(e,t,n):(U(bo,bo.current&1),t.flags|=128,null);U(bo,bo.current&1);break;case 19:if(r=(n&t.childLanes)!==0,e.flags&128){if(r)return Qs(e,t,n);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),U(bo,bo.current),r)break;return null;case 22:case 23:return t.lanes=0,Ls(e,t,n)}return ec(e,t,n)}var nc=function(e,t){for(var n=t.child;n!==null;){if(n.tag===5||n.tag===6)e.appendChild(n.stateNode);else if(n.tag!==4&&n.child!==null){n.child.return=n,n=n.child;continue}if(n===t)break;for(;n.sibling===null;){if(n.return===null||n.return===t)return;n=n.return}n.sibling.return=n.return,n=n.sibling}},rc=function(e,t,n,r){var i=e.memoizedProps;if(i!==r){e=t.stateNode,ho(fo.current);var o=null;switch(n){case`input`:i=be(e,i),r=be(e,r),o=[];break;case`select`:i=M({},i,{value:void 0}),r=M({},r,{value:void 0}),o=[];break;case`textarea`:i=Oe(e,i),r=Oe(e,r),o=[];break;default:typeof i.onClick!=`function`&&typeof r.onClick==`function`&&(e.onclick=Si)}He(n,r);var s;for(u in n=null,i)if(!r.hasOwnProperty(u)&&i.hasOwnProperty(u)&&i[u]!=null){if(u===`style`){var c=i[u];for(s in c)c.hasOwnProperty(s)&&(n||={},n[s]=``)}else u!==`dangerouslySetInnerHTML`&&u!==`children`&&u!==`suppressContentEditableWarning`&&u!==`suppressHydrationWarning`&&u!==`autoFocus`&&(a.hasOwnProperty(u)?o||=[]:(o||=[]).push(u,null))}for(u in r){var l=r[u];if(c=i?.[u],r.hasOwnProperty(u)&&l!==c&&(l!=null||c!=null)){if(u===`style`){if(c){for(s in c)!c.hasOwnProperty(s)||l&&l.hasOwnProperty(s)||(n||={},n[s]=``);for(s in l)l.hasOwnProperty(s)&&c[s]!==l[s]&&(n||={},n[s]=l[s])}else n||(o||=[],o.push(u,n)),n=l}else u===`dangerouslySetInnerHTML`?(l=l?l.__html:void 0,c=c?c.__html:void 0,l!=null&&c!==l&&(o||=[]).push(u,l)):u===`children`?typeof l!=`string`&&typeof l!=`number`||(o||=[]).push(u,``+l):u!==`suppressContentEditableWarning`&&u!==`suppressHydrationWarning`&&(a.hasOwnProperty(u)?(l!=null&&u===`onScroll`&&B(`scroll`,e),o||c===l||(o=[])):(o||=[]).push(u,l))}}n&&(o||=[]).push(`style`,n);var u=o;(t.updateQueue=u)&&(t.flags|=4)}},ic=function(e,t,n,r){n!==r&&(t.flags|=4)};function ac(e,t){if(!W)switch(e.tailMode){case`hidden`:t=e.tail;for(var n=null;t!==null;)t.alternate!==null&&(n=t),t=t.sibling;n===null?e.tail=null:n.sibling=null;break;case`collapsed`:n=e.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function oc(e){var t=e.alternate!==null&&e.alternate.child===e.child,n=0,r=0;if(t)for(var i=e.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags&14680064,r|=i.flags&14680064,i.return=e,i=i.sibling;else for(i=e.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags,r|=i.flags,i.return=e,i=i.sibling;return e.subtreeFlags|=r,e.childLanes=n,t}function sc(e,t,n){var i=t.pendingProps;switch(Sa(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return oc(t),null;case 1:return Qi(t.type)&&$i(),oc(t),null;case 3:return i=t.stateNode,_o(),H(Yi),H(Ji),Co(),i.pendingContext&&(i.context=i.pendingContext,i.pendingContext=null),(e===null||e.child===null)&&(ja(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Ta!==null&&(vl(Ta),Ta=null))),oc(t),null;case 5:yo(t);var o=ho(mo.current);if(n=t.type,e!==null&&t.stateNode!=null)rc(e,t,n,i,o),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!i){if(t.stateNode===null)throw Error(r(166));return oc(t),null}if(e=ho(fo.current),ja(t)){i=t.stateNode,n=t.type;var s=t.memoizedProps;switch(i[Fi]=t,i[Ii]=s,e=!!(t.mode&1),n){case`dialog`:B(`cancel`,i),B(`close`,i);break;case`iframe`:case`object`:case`embed`:B(`load`,i);break;case`video`:case`audio`:for(o=0;o<oi.length;o++)B(oi[o],i);break;case`source`:B(`error`,i);break;case`img`:case`image`:case`link`:B(`error`,i),B(`load`,i);break;case`details`:B(`toggle`,i);break;case`input`:xe(i,s),B(`invalid`,i);break;case`select`:i._wrapperState={wasMultiple:!!s.multiple},B(`invalid`,i);break;case`textarea`:ke(i,s),B(`invalid`,i)}for(var c in He(n,s),o=null,s)if(s.hasOwnProperty(c)){var l=s[c];c===`children`?typeof l==`string`?i.textContent!==l&&(!0!==s.suppressHydrationWarning&&xi(i.textContent,l,e),o=[`children`,l]):typeof l==`number`&&i.textContent!==``+l&&(!0!==s.suppressHydrationWarning&&xi(i.textContent,l,e),o=[`children`,``+l]):a.hasOwnProperty(c)&&l!=null&&c===`onScroll`&&B(`scroll`,i)}switch(n){case`input`:_e(i),we(i,s,!0);break;case`textarea`:_e(i),je(i);break;case`select`:case`option`:break;default:typeof s.onClick==`function`&&(i.onclick=Si)}i=o,t.updateQueue=i,i!==null&&(t.flags|=4)}else{c=o.nodeType===9?o:o.ownerDocument,e===`http://www.w3.org/1999/xhtml`&&(e=Me(n)),e===`http://www.w3.org/1999/xhtml`?n===`script`?(e=c.createElement(`div`),e.innerHTML=`<script><\/script>`,e=e.removeChild(e.firstChild)):typeof i.is==`string`?e=c.createElement(n,{is:i.is}):(e=c.createElement(n),n===`select`&&(c=e,i.multiple?c.multiple=!0:i.size&&(c.size=i.size))):e=c.createElementNS(e,n),e[Fi]=t,e[Ii]=i,nc(e,t,!1,!1),t.stateNode=e;a:{switch(c=Ue(n,i),n){case`dialog`:B(`cancel`,e),B(`close`,e),o=i;break;case`iframe`:case`object`:case`embed`:B(`load`,e),o=i;break;case`video`:case`audio`:for(o=0;o<oi.length;o++)B(oi[o],e);o=i;break;case`source`:B(`error`,e),o=i;break;case`img`:case`image`:case`link`:B(`error`,e),B(`load`,e),o=i;break;case`details`:B(`toggle`,e),o=i;break;case`input`:xe(e,i),o=be(e,i),B(`invalid`,e);break;case`option`:o=i;break;case`select`:e._wrapperState={wasMultiple:!!i.multiple},o=M({},i,{value:void 0}),B(`invalid`,e);break;case`textarea`:ke(e,i),o=Oe(e,i),B(`invalid`,e);break;default:o=i}for(s in He(n,o),l=o,l)if(l.hasOwnProperty(s)){var u=l[s];s===`style`?Be(e,u):s===`dangerouslySetInnerHTML`?(u=u?u.__html:void 0,u!=null&&Fe(e,u)):s===`children`?typeof u==`string`?(n!==`textarea`||u!==``)&&Ie(e,u):typeof u==`number`&&Ie(e,``+u):s!==`suppressContentEditableWarning`&&s!==`suppressHydrationWarning`&&s!==`autoFocus`&&(a.hasOwnProperty(s)?u!=null&&s===`onScroll`&&B(`scroll`,e):u!=null&&S(e,s,u,c))}switch(n){case`input`:_e(e),we(e,i,!1);break;case`textarea`:_e(e),je(e);break;case`option`:i.value!=null&&e.setAttribute(`value`,``+me(i.value));break;case`select`:e.multiple=!!i.multiple,s=i.value,s==null?i.defaultValue!=null&&De(e,!!i.multiple,i.defaultValue,!0):De(e,!!i.multiple,s,!1);break;default:typeof o.onClick==`function`&&(e.onclick=Si)}switch(n){case`button`:case`input`:case`select`:case`textarea`:i=!!i.autoFocus;break a;case`img`:i=!0;break a;default:i=!1}}i&&(t.flags|=4)}t.ref!==null&&(t.flags|=512,t.flags|=2097152)}return oc(t),null;case 6:if(e&&t.stateNode!=null)ic(e,t,e.memoizedProps,i);else{if(typeof i!=`string`&&t.stateNode===null)throw Error(r(166));if(n=ho(mo.current),ho(fo.current),ja(t)){if(i=t.stateNode,n=t.memoizedProps,i[Fi]=t,(s=i.nodeValue!==n)&&(e=Ca,e!==null))switch(e.tag){case 3:xi(i.nodeValue,n,!!(e.mode&1));break;case 5:!0!==e.memoizedProps.suppressHydrationWarning&&xi(i.nodeValue,n,!!(e.mode&1))}s&&(t.flags|=4)}else i=(n.nodeType===9?n:n.ownerDocument).createTextNode(i),i[Fi]=t,t.stateNode=i}return oc(t),null;case 13:if(H(bo),i=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(W&&wa!==null&&t.mode&1&&!(t.flags&128))Ma(),Na(),t.flags|=98560,s=!1;else if(s=ja(t),i!==null&&i.dehydrated!==null){if(e===null){if(!s)throw Error(r(318));if(s=t.memoizedState,s=s===null?null:s.dehydrated,!s)throw Error(r(317));s[Fi]=t}else Na(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;oc(t),s=!1}else Ta!==null&&(vl(Ta),Ta=null),s=!0;if(!s)return t.flags&65536?t:null}return t.flags&128?(t.lanes=n,t):(i=i!==null,i!==(e!==null&&e.memoizedState!==null)&&i&&(t.child.flags|=8192,t.mode&1&&(e===null||bo.current&1?Kc===0&&(Kc=3):Ol())),t.updateQueue!==null&&(t.flags|=4),oc(t),null);case 4:return _o(),e===null&&di(t.stateNode.containerInfo),oc(t),null;case 10:return qa(t.type._context),oc(t),null;case 17:return Qi(t.type)&&$i(),oc(t),null;case 19:if(H(bo),s=t.memoizedState,s===null)return oc(t),null;if(i=!!(t.flags&128),c=s.rendering,c===null){if(i)ac(s,!1);else{if(Kc!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(c=xo(e),c!==null){for(t.flags|=128,ac(s,!1),i=c.updateQueue,i!==null&&(t.updateQueue=i,t.flags|=4),t.subtreeFlags=0,i=n,n=t.child;n!==null;)s=n,e=i,s.flags&=14680066,c=s.alternate,c===null?(s.childLanes=0,s.lanes=e,s.child=null,s.subtreeFlags=0,s.memoizedProps=null,s.memoizedState=null,s.updateQueue=null,s.dependencies=null,s.stateNode=null):(s.childLanes=c.childLanes,s.lanes=c.lanes,s.child=c.child,s.subtreeFlags=0,s.deletions=null,s.memoizedProps=c.memoizedProps,s.memoizedState=c.memoizedState,s.updateQueue=c.updateQueue,s.type=c.type,e=c.dependencies,s.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),n=n.sibling;return U(bo,bo.current&1|2),t.child}e=e.sibling}s.tail!==null&&Ct()>el&&(t.flags|=128,i=!0,ac(s,!1),t.lanes=4194304)}}else{if(!i){if(e=xo(c),e!==null){if(t.flags|=128,i=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),ac(s,!0),s.tail===null&&s.tailMode===`hidden`&&!c.alternate&&!W)return oc(t),null}else 2*Ct()-s.renderingStartTime>el&&n!==1073741824&&(t.flags|=128,i=!0,ac(s,!1),t.lanes=4194304)}s.isBackwards?(c.sibling=t.child,t.child=c):(n=s.last,n===null?t.child=c:n.sibling=c,s.last=c)}return s.tail===null?(oc(t),null):(t=s.tail,s.rendering=t,s.tail=t.sibling,s.renderingStartTime=Ct(),t.sibling=null,n=bo.current,U(bo,i?n&1|2:n&1),t);case 22:case 23:return wl(),i=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==i&&(t.flags|=8192),i&&t.mode&1?Wc&1073741824&&(oc(t),t.subtreeFlags&6&&(t.flags|=8192)):oc(t),null;case 24:return null;case 25:return null}throw Error(r(156,t.tag))}function cc(e,t){switch(Sa(t),t.tag){case 1:return Qi(t.type)&&$i(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return _o(),H(Yi),H(Ji),Co(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return yo(t),null;case 13:if(H(bo),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(r(340));Na()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return H(bo),null;case 4:return _o(),null;case 10:return qa(t.type._context),null;case 22:case 23:return wl(),null;case 24:return null;default:return null}}var lc=!1,uc=!1,dc=typeof WeakSet==`function`?WeakSet:Set,Q=null;function fc(e,t){var n=e.ref;if(n!==null){if(typeof n==`function`)try{n(null)}catch(n){Rl(e,t,n)}else n.current=null}}function pc(e,t,n){try{n()}catch(n){Rl(e,t,n)}}var mc=!1;function hc(e,t){if(Ci=bn,e=zr(),Br(e)){if(`selectionStart`in e)var n={start:e.selectionStart,end:e.selectionEnd};else a:{n=(n=e.ownerDocument)&&n.defaultView||window;var i=n.getSelection&&n.getSelection();if(i&&i.rangeCount!==0){n=i.anchorNode;var a=i.anchorOffset,o=i.focusNode;i=i.focusOffset;try{n.nodeType,o.nodeType}catch{n=null;break a}var s=0,c=-1,l=-1,u=0,d=0,f=e,p=null;b:for(;;){for(var m;f!==n||a!==0&&f.nodeType!==3||(c=s+a),f!==o||i!==0&&f.nodeType!==3||(l=s+i),f.nodeType===3&&(s+=f.nodeValue.length),(m=f.firstChild)!==null;)p=f,f=m;for(;;){if(f===e)break b;if(p===n&&++u===a&&(c=s),p===o&&++d===i&&(l=s),(m=f.nextSibling)!==null)break;f=p,p=f.parentNode}f=m}n=c===-1||l===-1?null:{start:c,end:l}}else n=null}n||={start:0,end:0}}else n=null;for(wi={focusedElem:e,selectionRange:n},bn=!1,Q=t;Q!==null;)if(t=Q,e=t.child,t.subtreeFlags&1028&&e!==null)e.return=t,Q=e;else for(;Q!==null;){t=Q;try{var h=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(h!==null){var g=h.memoizedProps,_=h.memoizedState,v=t.stateNode;v.__reactInternalSnapshotBeforeUpdate=v.getSnapshotBeforeUpdate(t.elementType===t.type?g:hs(t.type,g),_)}break;case 3:var y=t.stateNode.containerInfo;y.nodeType===1?y.textContent=``:y.nodeType===9&&y.documentElement&&y.removeChild(y.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(r(163))}}catch(e){Rl(t,t.return,e)}if(e=t.sibling,e!==null){e.return=t.return,Q=e;break}Q=t.return}return h=mc,mc=!1,h}function gc(e,t,n){var r=t.updateQueue;if(r=r===null?null:r.lastEffect,r!==null){var i=r=r.next;do{if((i.tag&e)===e){var a=i.destroy;i.destroy=void 0,a!==void 0&&pc(t,n,a)}i=i.next}while(i!==r)}}function _c(e,t){if(t=t.updateQueue,t=t===null?null:t.lastEffect,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function vc(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t==`function`?t(e):t.current=e}}function yc(e){var t=e.alternate;t!==null&&(e.alternate=null,yc(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Fi],delete t[Ii],delete t[Ri],delete t[zi],delete t[Bi])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function bc(e){return e.tag===5||e.tag===3||e.tag===4}function xc(e){a:for(;;){for(;e.sibling===null;){if(e.return===null||bc(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue a;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Sc(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=Si));else if(r!==4&&(e=e.child,e!==null))for(Sc(e,t,n),e=e.sibling;e!==null;)Sc(e,t,n),e=e.sibling}function Cc(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(Cc(e,t,n),e=e.sibling;e!==null;)Cc(e,t,n),e=e.sibling}var wc=null,Tc=!1;function Ec(e,t,n){for(n=n.child;n!==null;)Dc(e,t,n),n=n.sibling}function Dc(e,t,n){if(jt&&typeof jt.onCommitFiberUnmount==`function`)try{jt.onCommitFiberUnmount(At,n)}catch{}switch(n.tag){case 5:uc||fc(n,t);case 6:var r=wc,i=Tc;wc=null,Ec(e,t,n),wc=r,Tc=i,wc!==null&&(Tc?(e=wc,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):wc.removeChild(n.stateNode));break;case 18:wc!==null&&(Tc?(e=wc,n=n.stateNode,e.nodeType===8?ji(e.parentNode,n):e.nodeType===1&&ji(e,n),vn(e)):ji(wc,n.stateNode));break;case 4:r=wc,i=Tc,wc=n.stateNode.containerInfo,Tc=!0,Ec(e,t,n),wc=r,Tc=i;break;case 0:case 11:case 14:case 15:if(!uc&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){i=r=r.next;do{var a=i,o=a.destroy;a=a.tag,o!==void 0&&(a&2||a&4)&&pc(n,t,o),i=i.next}while(i!==r)}Ec(e,t,n);break;case 1:if(!uc&&(fc(n,t),r=n.stateNode,typeof r.componentWillUnmount==`function`))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(e){Rl(n,t,e)}Ec(e,t,n);break;case 21:Ec(e,t,n);break;case 22:n.mode&1?(uc=(r=uc)||n.memoizedState!==null,Ec(e,t,n),uc=r):Ec(e,t,n);break;default:Ec(e,t,n)}}function Oc(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new dc),t.forEach(function(t){var r=Hl.bind(null,e,t);n.has(t)||(n.add(t),t.then(r,r))})}}function kc(e,t){var n=t.deletions;if(n!==null)for(var i=0;i<n.length;i++){var a=n[i];try{var o=e,s=t,c=s;a:for(;c!==null;){switch(c.tag){case 5:wc=c.stateNode,Tc=!1;break a;case 3:wc=c.stateNode.containerInfo,Tc=!0;break a;case 4:wc=c.stateNode.containerInfo,Tc=!0;break a}c=c.return}if(wc===null)throw Error(r(160));Dc(o,s,a),wc=null,Tc=!1;var l=a.alternate;l!==null&&(l.return=null),a.return=null}catch(e){Rl(a,t,e)}}if(t.subtreeFlags&12854)for(t=t.child;t!==null;)Ac(t,e),t=t.sibling}function Ac(e,t){var n=e.alternate,i=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(kc(t,e),jc(e),i&4){try{gc(3,e,e.return),_c(3,e)}catch(t){Rl(e,e.return,t)}try{gc(5,e,e.return)}catch(t){Rl(e,e.return,t)}}break;case 1:kc(t,e),jc(e),i&512&&n!==null&&fc(n,n.return);break;case 5:if(kc(t,e),jc(e),i&512&&n!==null&&fc(n,n.return),e.flags&32){var a=e.stateNode;try{Ie(a,``)}catch(t){Rl(e,e.return,t)}}if(i&4&&(a=e.stateNode,a!=null)){var o=e.memoizedProps,s=n===null?o:n.memoizedProps,c=e.type,l=e.updateQueue;if(e.updateQueue=null,l!==null)try{c===`input`&&o.type===`radio`&&o.name!=null&&Se(a,o),Ue(c,s);var u=Ue(c,o);for(s=0;s<l.length;s+=2){var d=l[s],f=l[s+1];d===`style`?Be(a,f):d===`dangerouslySetInnerHTML`?Fe(a,f):d===`children`?Ie(a,f):S(a,d,f,u)}switch(c){case`input`:Ce(a,o);break;case`textarea`:Ae(a,o);break;case`select`:var p=a._wrapperState.wasMultiple;a._wrapperState.wasMultiple=!!o.multiple;var m=o.value;m==null?p!==!!o.multiple&&(o.defaultValue==null?De(a,!!o.multiple,o.multiple?[]:``,!1):De(a,!!o.multiple,o.defaultValue,!0)):De(a,!!o.multiple,m,!1)}a[Ii]=o}catch(t){Rl(e,e.return,t)}}break;case 6:if(kc(t,e),jc(e),i&4){if(e.stateNode===null)throw Error(r(162));a=e.stateNode,o=e.memoizedProps;try{a.nodeValue=o}catch(t){Rl(e,e.return,t)}}break;case 3:if(kc(t,e),jc(e),i&4&&n!==null&&n.memoizedState.isDehydrated)try{vn(t.containerInfo)}catch(t){Rl(e,e.return,t)}break;case 4:kc(t,e),jc(e);break;case 13:kc(t,e),jc(e),a=e.child,a.flags&8192&&(o=a.memoizedState!==null,a.stateNode.isHidden=o,!o||a.alternate!==null&&a.alternate.memoizedState!==null||($c=Ct())),i&4&&Oc(e);break;case 22:if(d=n!==null&&n.memoizedState!==null,e.mode&1?(uc=(u=uc)||d,kc(t,e),uc=u):kc(t,e),jc(e),i&8192){if(u=e.memoizedState!==null,(e.stateNode.isHidden=u)&&!d&&e.mode&1)for(Q=e,d=e.child;d!==null;){for(f=Q=d;Q!==null;){switch(p=Q,m=p.child,p.tag){case 0:case 11:case 14:case 15:gc(4,p,p.return);break;case 1:fc(p,p.return);var h=p.stateNode;if(typeof h.componentWillUnmount==`function`){i=p,n=p.return;try{t=i,h.props=t.memoizedProps,h.state=t.memoizedState,h.componentWillUnmount()}catch(e){Rl(i,n,e)}}break;case 5:fc(p,p.return);break;case 22:if(p.memoizedState!==null){Fc(f);continue}}m===null?Fc(f):(m.return=p,Q=m)}d=d.sibling}a:for(d=null,f=e;;){if(f.tag===5){if(d===null){d=f;try{a=f.stateNode,u?(o=a.style,typeof o.setProperty==`function`?o.setProperty(`display`,`none`,`important`):o.display=`none`):(c=f.stateNode,l=f.memoizedProps.style,s=l!=null&&l.hasOwnProperty(`display`)?l.display:null,c.style.display=ze(`display`,s))}catch(t){Rl(e,e.return,t)}}}else if(f.tag===6){if(d===null)try{f.stateNode.nodeValue=u?``:f.memoizedProps}catch(t){Rl(e,e.return,t)}}else if((f.tag!==22&&f.tag!==23||f.memoizedState===null||f===e)&&f.child!==null){f.child.return=f,f=f.child;continue}if(f===e)break a;for(;f.sibling===null;){if(f.return===null||f.return===e)break a;d===f&&(d=null),f=f.return}d===f&&(d=null),f.sibling.return=f.return,f=f.sibling}}break;case 19:kc(t,e),jc(e),i&4&&Oc(e);break;case 21:break;default:kc(t,e),jc(e)}}function jc(e){var t=e.flags;if(t&2){try{a:{for(var n=e.return;n!==null;){if(bc(n)){var i=n;break a}n=n.return}throw Error(r(160))}switch(i.tag){case 5:var a=i.stateNode;i.flags&32&&(Ie(a,``),i.flags&=-33),Cc(e,xc(e),a);break;case 3:case 4:var o=i.stateNode.containerInfo;Sc(e,xc(e),o);break;default:throw Error(r(161))}}catch(t){Rl(e,e.return,t)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function Mc(e,t,n){Q=e,Nc(e,t,n)}function Nc(e,t,n){for(var r=!!(e.mode&1);Q!==null;){var i=Q,a=i.child;if(i.tag===22&&r){var o=i.memoizedState!==null||lc;if(!o){var s=i.alternate,c=s!==null&&s.memoizedState!==null||uc;s=lc;var l=uc;if(lc=o,(uc=c)&&!l)for(Q=i;Q!==null;)o=Q,c=o.child,o.tag===22&&o.memoizedState!==null||c===null?Ic(i):(c.return=o,Q=c);for(;a!==null;)Q=a,Nc(a,t,n),a=a.sibling;Q=i,lc=s,uc=l}Pc(e,t,n)}else i.subtreeFlags&8772&&a!==null?(a.return=i,Q=a):Pc(e,t,n)}}function Pc(e){for(;Q!==null;){var t=Q;if(t.flags&8772){var n=t.alternate;try{if(t.flags&8772)switch(t.tag){case 0:case 11:case 15:uc||_c(5,t);break;case 1:var i=t.stateNode;if(t.flags&4&&!uc){if(n===null)i.componentDidMount();else{var a=t.elementType===t.type?n.memoizedProps:hs(t.type,n.memoizedProps);i.componentDidUpdate(a,n.memoizedState,i.__reactInternalSnapshotBeforeUpdate)}}var o=t.updateQueue;o!==null&&lo(t,o,i);break;case 3:var s=t.updateQueue;if(s!==null){if(n=null,t.child!==null)switch(t.child.tag){case 5:n=t.child.stateNode;break;case 1:n=t.child.stateNode}lo(t,s,n)}break;case 5:var c=t.stateNode;if(n===null&&t.flags&4){n=c;var l=t.memoizedProps;switch(t.type){case`button`:case`input`:case`select`:case`textarea`:l.autoFocus&&n.focus();break;case`img`:l.src&&(n.src=l.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(t.memoizedState===null){var u=t.alternate;if(u!==null){var d=u.memoizedState;if(d!==null){var f=d.dehydrated;f!==null&&vn(f)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(r(163))}uc||t.flags&512&&vc(t)}catch(e){Rl(t,t.return,e)}}if(t===e){Q=null;break}if(n=t.sibling,n!==null){n.return=t.return,Q=n;break}Q=t.return}}function Fc(e){for(;Q!==null;){var t=Q;if(t===e){Q=null;break}var n=t.sibling;if(n!==null){n.return=t.return,Q=n;break}Q=t.return}}function Ic(e){for(;Q!==null;){var t=Q;try{switch(t.tag){case 0:case 11:case 15:var n=t.return;try{_c(4,t)}catch(e){Rl(t,n,e)}break;case 1:var r=t.stateNode;if(typeof r.componentDidMount==`function`){var i=t.return;try{r.componentDidMount()}catch(e){Rl(t,i,e)}}var a=t.return;try{vc(t)}catch(e){Rl(t,a,e)}break;case 5:var o=t.return;try{vc(t)}catch(e){Rl(t,o,e)}}}catch(e){Rl(t,t.return,e)}if(t===e){Q=null;break}var s=t.sibling;if(s!==null){s.return=t.return,Q=s;break}Q=t.return}}var Lc=Math.ceil,Rc=C.ReactCurrentDispatcher,zc=C.ReactCurrentOwner,Bc=C.ReactCurrentBatchConfig,$=0,Vc=null,Hc=null,Uc=0,Wc=0,Gc=V(0),Kc=0,qc=null,Jc=0,Yc=0,Xc=0,Zc=null,Qc=null,$c=0,el=1/0,tl=null,nl=!1,rl=null,il=null,al=!1,ol=null,sl=0,cl=0,ll=null,ul=-1,dl=0;function fl(){return $&6?Ct():ul===-1?ul=Ct():ul}function pl(e){return e.mode&1?$&2&&Uc!==0?Uc&-Uc:Fa.transition===null?(e=P,e===0?(e=window.event,e=e===void 0?16:En(e.type),e):e):(dl===0&&(dl=Ut()),dl):1}function ml(e,t,n,i){if(50<cl)throw cl=0,ll=null,Error(r(185));Gt(e,n,i),(!($&2)||e!==Vc)&&(e===Vc&&(!($&2)&&(Yc|=n),Kc===4&&bl(e,Uc)),hl(e,i),n===1&&$===0&&!(t.mode&1)&&(el=Ct()+500,aa&&la()))}function hl(e,t){var n=e.callbackNode;Vt(e,t);var r=zt(e,e===Vc?Uc:0);if(r===0)n!==null&&bt(n),e.callbackNode=null,e.callbackPriority=0;else if(t=r&-r,e.callbackPriority!==t){if(n!=null&&bt(n),t===1)e.tag===0?ca(xl.bind(null,e)):sa(xl.bind(null,e)),ki(function(){!($&6)&&la()}),n=null;else{switch(Jt(r)){case 1:n=Tt;break;case 4:n=Et;break;case 16:n=Dt;break;case 536870912:n=kt;break;default:n=Dt}n=Wl(n,gl.bind(null,e))}e.callbackPriority=t,e.callbackNode=n}}function gl(e,t){if(ul=-1,dl=0,$&6)throw Error(r(327));var n=e.callbackNode;if(Il()&&e.callbackNode!==n)return null;var i=zt(e,e===Vc?Uc:0);if(i===0)return null;if(i&30||(i&e.expiredLanes)!==0||t)t=kl(e,i);else{t=i;var a=$;$|=2;var o=Dl();(Vc!==e||Uc!==t)&&(tl=null,el=Ct()+500,Tl(e,t));do try{jl();break}catch(t){El(e,t)}while(1);Ka(),Rc.current=o,$=a,Hc===null?(Vc=null,Uc=0,t=Kc):t=0}if(t!==0){if(t===2&&(a=Ht(e),a!==0&&(i=a,t=_l(e,a))),t===1)throw n=qc,Tl(e,0),bl(e,i),hl(e,Ct()),n;if(t===6)bl(e,i);else{if(a=e.current.alternate,!(i&30)&&!yl(a)&&(t=kl(e,i),t===2&&(o=Ht(e),o!==0&&(i=o,t=_l(e,o))),t===1))throw n=qc,Tl(e,0),bl(e,i),hl(e,Ct()),n;switch(e.finishedWork=a,e.finishedLanes=i,t){case 0:case 1:throw Error(r(345));case 2:Pl(e,Qc,tl);break;case 3:if(bl(e,i),(i&130023424)===i&&(t=$c+500-Ct(),10<t)){if(zt(e,0)!==0)break;if(a=e.suspendedLanes,(a&i)!==i){fl(),e.pingedLanes|=e.suspendedLanes&a;break}e.timeoutHandle=Ei(Pl.bind(null,e,Qc,tl),t);break}Pl(e,Qc,tl);break;case 4:if(bl(e,i),(i&4194240)===i)break;for(t=e.eventTimes,a=-1;0<i;){var s=31-Nt(i);o=1<<s,s=t[s],s>a&&(a=s),i&=~o}if(i=a,i=Ct()-i,i=(120>i?120:480>i?480:1080>i?1080:1920>i?1920:3e3>i?3e3:4320>i?4320:1960*Lc(i/1960))-i,10<i){e.timeoutHandle=Ei(Pl.bind(null,e,Qc,tl),i);break}Pl(e,Qc,tl);break;case 5:Pl(e,Qc,tl);break;default:throw Error(r(329))}}}return hl(e,Ct()),e.callbackNode===n?gl.bind(null,e):null}function _l(e,t){var n=Zc;return e.current.memoizedState.isDehydrated&&(Tl(e,t).flags|=256),e=kl(e,t),e!==2&&(t=Qc,Qc=n,t!==null&&vl(t)),e}function vl(e){Qc===null?Qc=e:Qc.push.apply(Qc,e)}function yl(e){for(var t=e;;){if(t.flags&16384){var n=t.updateQueue;if(n!==null&&(n=n.stores,n!==null))for(var r=0;r<n.length;r++){var i=n[r],a=i.getSnapshot;i=i.value;try{if(!Pr(a(),i))return!1}catch{return!1}}}if(n=t.child,t.subtreeFlags&16384&&n!==null)n.return=t,t=n;else{if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return!0;t=t.return}t.sibling.return=t.return,t=t.sibling}}return!0}function bl(e,t){for(t&=~Xc,t&=~Yc,e.suspendedLanes|=t,e.pingedLanes&=~t,e=e.expirationTimes;0<t;){var n=31-Nt(t),r=1<<n;e[n]=-1,t&=~r}}function xl(e){if($&6)throw Error(r(327));Il();var t=zt(e,0);if(!(t&1))return hl(e,Ct()),null;var n=kl(e,t);if(e.tag!==0&&n===2){var i=Ht(e);i!==0&&(t=i,n=_l(e,i))}if(n===1)throw n=qc,Tl(e,0),bl(e,t),hl(e,Ct()),n;if(n===6)throw Error(r(345));return e.finishedWork=e.current.alternate,e.finishedLanes=t,Pl(e,Qc,tl),hl(e,Ct()),null}function Sl(e,t){var n=$;$|=1;try{return e(t)}finally{$=n,$===0&&(el=Ct()+500,aa&&la())}}function Cl(e){ol!==null&&ol.tag===0&&!($&6)&&Il();var t=$;$|=1;var n=Bc.transition,r=P;try{if(Bc.transition=null,P=1,e)return e()}finally{P=r,Bc.transition=n,$=t,!($&6)&&la()}}function wl(){Wc=Gc.current,H(Gc)}function Tl(e,t){e.finishedWork=null,e.finishedLanes=0;var n=e.timeoutHandle;if(n!==-1&&(e.timeoutHandle=-1,Di(n)),Hc!==null)for(n=Hc.return;n!==null;){var r=n;switch(Sa(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&$i();break;case 3:_o(),H(Yi),H(Ji),Co();break;case 5:yo(r);break;case 4:_o();break;case 13:H(bo);break;case 19:H(bo);break;case 10:qa(r.type._context);break;case 22:case 23:wl()}n=n.return}if(Vc=e,Hc=e=Yl(e.current,null),Uc=Wc=t,Kc=0,qc=null,Xc=Yc=Jc=0,Qc=Zc=null,Za!==null){for(t=0;t<Za.length;t++)if(n=Za[t],r=n.interleaved,r!==null){n.interleaved=null;var i=r.next,a=n.pending;if(a!==null){var o=a.next;a.next=i,r.next=o}n.pending=r}Za=null}return e}function El(e,t){do{var n=Hc;try{if(Ka(),wo.current=ds,ko){for(var i=G.memoizedState;i!==null;){var a=i.queue;a!==null&&(a.pending=null),i=i.next}ko=!1}if(Eo=0,Oo=Do=G=null,Ao=!1,jo=0,zc.current=null,n===null||n.return===null){Kc=1,qc=t,Hc=null;break}a:{var o=e,s=n.return,c=n,l=t;if(t=Uc,c.flags|=32768,typeof l==`object`&&l&&typeof l.then==`function`){var u=l,d=c,f=d.tag;if(!(d.mode&1)&&(f===0||f===11||f===15)){var p=d.alternate;p?(d.updateQueue=p.updateQueue,d.memoizedState=p.memoizedState,d.lanes=p.lanes):(d.updateQueue=null,d.memoizedState=null)}var m=ks(s);if(m!==null){m.flags&=-257,As(m,s,c,o,t),m.mode&1&&Os(o,u,t),t=m,l=u;var h=t.updateQueue;if(h===null){var g=new Set;g.add(l),t.updateQueue=g}else h.add(l);break a}if(!(t&1)){Os(o,u,t),Ol();break a}l=Error(r(426))}else if(W&&c.mode&1){var _=ks(s);if(_!==null){!(_.flags&65536)&&(_.flags|=256),As(_,s,c,o,t),Pa(Ss(l,c));break a}}o=l=Ss(l,c),Kc!==4&&(Kc=2),Zc===null?Zc=[o]:Zc.push(o),o=s;do{switch(o.tag){case 3:o.flags|=65536,t&=-t,o.lanes|=t;var v=Es(o,l,t);so(o,v);break a;case 1:c=l;var y=o.type,b=o.stateNode;if(!(o.flags&128)&&(typeof y.getDerivedStateFromError==`function`||b!==null&&typeof b.componentDidCatch==`function`&&(il===null||!il.has(b)))){o.flags|=65536,t&=-t,o.lanes|=t;var x=Ds(o,c,t);so(o,x);break a}}o=o.return}while(o!==null)}Nl(n)}catch(e){t=e,Hc===n&&n!==null&&(Hc=n=n.return);continue}break}while(1)}function Dl(){var e=Rc.current;return Rc.current=ds,e===null?ds:e}function Ol(){(Kc===0||Kc===3||Kc===2)&&(Kc=4),Vc===null||!(Jc&268435455)&&!(Yc&268435455)||bl(Vc,Uc)}function kl(e,t){var n=$;$|=2;var i=Dl();(Vc!==e||Uc!==t)&&(tl=null,Tl(e,t));do try{Al();break}catch(t){El(e,t)}while(1);if(Ka(),$=n,Rc.current=i,Hc!==null)throw Error(r(261));return Vc=null,Uc=0,Kc}function Al(){for(;Hc!==null;)Ml(Hc)}function jl(){for(;Hc!==null&&!xt();)Ml(Hc)}function Ml(e){var t=Ul(e.alternate,e,Wc);e.memoizedProps=e.pendingProps,t===null?Nl(e):Hc=t,zc.current=null}function Nl(e){var t=e;do{var n=t.alternate;if(e=t.return,t.flags&32768){if(n=cc(n,t),n!==null){n.flags&=32767,Hc=n;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{Kc=6,Hc=null;return}}else if(n=sc(n,t,Wc),n!==null){Hc=n;return}if(t=t.sibling,t!==null){Hc=t;return}Hc=t=e}while(t!==null);Kc===0&&(Kc=5)}function Pl(e,t,n){var r=P,i=Bc.transition;try{Bc.transition=null,P=1,Fl(e,t,n,r)}finally{Bc.transition=i,P=r}return null}function Fl(e,t,n,i){do Il();while(ol!==null);if($&6)throw Error(r(327));n=e.finishedWork;var a=e.finishedLanes;if(n===null)return null;if(e.finishedWork=null,e.finishedLanes=0,n===e.current)throw Error(r(177));e.callbackNode=null,e.callbackPriority=0;var o=n.lanes|n.childLanes;if(Kt(e,o),e===Vc&&(Hc=Vc=null,Uc=0),!(n.subtreeFlags&2064)&&!(n.flags&2064)||al||(al=!0,Wl(Dt,function(){return Il(),null})),o=!!(n.flags&15990),n.subtreeFlags&15990||o){o=Bc.transition,Bc.transition=null;var s=P;P=1;var c=$;$|=4,zc.current=null,hc(e,n),Ac(n,e),Vr(wi),bn=!!Ci,wi=Ci=null,e.current=n,Mc(n,e,a),St(),$=c,P=s,Bc.transition=o}else e.current=n;if(al&&(al=!1,ol=e,sl=a),o=e.pendingLanes,o===0&&(il=null),Mt(n.stateNode,i),hl(e,Ct()),t!==null)for(i=e.onRecoverableError,n=0;n<t.length;n++)a=t[n],i(a.value,{componentStack:a.stack,digest:a.digest});if(nl)throw nl=!1,e=rl,rl=null,e;return sl&1&&e.tag!==0&&Il(),o=e.pendingLanes,o&1?e===ll?cl++:(cl=0,ll=e):cl=0,la(),null}function Il(){if(ol!==null){var e=Jt(sl),t=Bc.transition,n=P;try{if(Bc.transition=null,P=16>e?16:e,ol===null)var i=!1;else{if(e=ol,ol=null,sl=0,$&6)throw Error(r(331));var a=$;for($|=4,Q=e.current;Q!==null;){var o=Q,s=o.child;if(Q.flags&16){var c=o.deletions;if(c!==null){for(var l=0;l<c.length;l++){var u=c[l];for(Q=u;Q!==null;){var d=Q;switch(d.tag){case 0:case 11:case 15:gc(8,d,o)}var f=d.child;if(f!==null)f.return=d,Q=f;else for(;Q!==null;){d=Q;var p=d.sibling,m=d.return;if(yc(d),d===u){Q=null;break}if(p!==null){p.return=m,Q=p;break}Q=m}}}var h=o.alternate;if(h!==null){var g=h.child;if(g!==null){h.child=null;do{var _=g.sibling;g.sibling=null,g=_}while(g!==null)}}Q=o}}if(o.subtreeFlags&2064&&s!==null)s.return=o,Q=s;else b:for(;Q!==null;){if(o=Q,o.flags&2048)switch(o.tag){case 0:case 11:case 15:gc(9,o,o.return)}var v=o.sibling;if(v!==null){v.return=o.return,Q=v;break b}Q=o.return}}var y=e.current;for(Q=y;Q!==null;){s=Q;var b=s.child;if(s.subtreeFlags&2064&&b!==null)b.return=s,Q=b;else b:for(s=y;Q!==null;){if(c=Q,c.flags&2048)try{switch(c.tag){case 0:case 11:case 15:_c(9,c)}}catch(e){Rl(c,c.return,e)}if(c===s){Q=null;break b}var x=c.sibling;if(x!==null){x.return=c.return,Q=x;break b}Q=c.return}}if($=a,la(),jt&&typeof jt.onPostCommitFiberRoot==`function`)try{jt.onPostCommitFiberRoot(At,e)}catch{}i=!0}return i}finally{P=n,Bc.transition=t}}return!1}function Ll(e,t,n){t=Ss(n,t),t=Es(e,t,1),e=ao(e,t,1),t=fl(),e!==null&&(Gt(e,1,t),hl(e,t))}function Rl(e,t,n){if(e.tag===3)Ll(e,e,n);else for(;t!==null;){if(t.tag===3){Ll(t,e,n);break}if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError==`function`||typeof r.componentDidCatch==`function`&&(il===null||!il.has(r))){e=Ss(n,e),e=Ds(t,e,1),t=ao(t,e,1),e=fl(),t!==null&&(Gt(t,1,e),hl(t,e));break}}t=t.return}}function zl(e,t,n){var r=e.pingCache;r!==null&&r.delete(t),t=fl(),e.pingedLanes|=e.suspendedLanes&n,Vc===e&&(Uc&n)===n&&(Kc===4||Kc===3&&(Uc&130023424)===Uc&&500>Ct()-$c?Tl(e,0):Xc|=n),hl(e,t)}function Bl(e,t){t===0&&(e.mode&1?(t=Lt,Lt<<=1,!(Lt&130023424)&&(Lt=4194304)):t=1);var n=fl();e=eo(e,t),e!==null&&(Gt(e,t,n),hl(e,n))}function Vl(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),Bl(e,n)}function Hl(e,t){var n=0;switch(e.tag){case 13:var i=e.stateNode,a=e.memoizedState;a!==null&&(n=a.retryLane);break;case 19:i=e.stateNode;break;default:throw Error(r(314))}i!==null&&i.delete(t),Bl(e,n)}var Ul=function(e,t,n){if(e!==null){if(e.memoizedProps!==t.pendingProps||Yi.current)Ms=!0;else{if((e.lanes&n)===0&&!(t.flags&128))return Ms=!1,tc(e,t,n);Ms=!!(e.flags&131072)}}else Ms=!1,W&&t.flags&1048576&&ba(t,pa,t.index);switch(t.lanes=0,t.tag){case 2:var i=t.type;$s(e,t),e=t.pendingProps;var a=Zi(t,Ji.current);Ya(t,n),a=Fo(null,t,i,e,a,n);var o=Io();return t.flags|=1,typeof a==`object`&&a&&typeof a.render==`function`&&a.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,Qi(i)?(o=!0,na(t)):o=!1,t.memoizedState=a.state!==null&&a.state!==void 0?a.state:null,no(t),a.updater=_s,t.stateNode=a,a._reactInternals=t,xs(t,i,e,n),t=Vs(null,t,i,!0,o,n)):(t.tag=0,W&&o&&xa(t),Ns(null,t,a,n),t=t.child),t;case 16:i=t.elementType;a:{switch($s(e,t),e=t.pendingProps,a=i._init,i=a(i._payload),t.type=i,a=t.tag=Jl(i),e=hs(i,e),a){case 0:t=zs(null,t,i,e,n);break a;case 1:t=Bs(null,t,i,e,n);break a;case 11:t=Ps(null,t,i,e,n);break a;case 14:t=Fs(null,t,i,hs(i.type,e),n);break a}throw Error(r(306,i,``))}return t;case 0:return i=t.type,a=t.pendingProps,a=t.elementType===i?a:hs(i,a),zs(e,t,i,a,n);case 1:return i=t.type,a=t.pendingProps,a=t.elementType===i?a:hs(i,a),Bs(e,t,i,a,n);case 3:a:{if(Hs(t),e===null)throw Error(r(387));i=t.pendingProps,o=t.memoizedState,a=o.element,ro(e,t),co(t,i,null,n);var s=t.memoizedState;if(i=s.element,o.isDehydrated){if(o={element:i,isDehydrated:!1,cache:s.cache,pendingSuspenseBoundaries:s.pendingSuspenseBoundaries,transitions:s.transitions},t.updateQueue.baseState=o,t.memoizedState=o,t.flags&256){a=Ss(Error(r(423)),t),t=Us(e,t,i,n,a);break a}if(i!==a){a=Ss(Error(r(424)),t),t=Us(e,t,i,n,a);break a}for(wa=Mi(t.stateNode.containerInfo.firstChild),Ca=t,W=!0,Ta=null,n=Va(t,null,i,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling}else{if(Na(),i===a){t=ec(e,t,n);break a}Ns(e,t,i,n)}t=t.child}return t;case 5:return vo(t),e===null&&ka(t),i=t.type,a=t.pendingProps,o=e===null?null:e.memoizedProps,s=a.children,Ti(i,a)?s=null:o!==null&&Ti(i,o)&&(t.flags|=32),Rs(e,t),Ns(e,t,s,n),t.child;case 6:return e===null&&ka(t),null;case 13:return Ks(e,t,n);case 4:return go(t,t.stateNode.containerInfo),i=t.pendingProps,e===null?t.child=Ba(t,null,i,n):Ns(e,t,i,n),t.child;case 11:return i=t.type,a=t.pendingProps,a=t.elementType===i?a:hs(i,a),Ps(e,t,i,a,n);case 7:return Ns(e,t,t.pendingProps,n),t.child;case 8:return Ns(e,t,t.pendingProps.children,n),t.child;case 12:return Ns(e,t,t.pendingProps.children,n),t.child;case 10:a:{if(i=t.type._context,a=t.pendingProps,o=t.memoizedProps,s=a.value,U(Ha,i._currentValue),i._currentValue=s,o!==null){if(Pr(o.value,s)){if(o.children===a.children&&!Yi.current){t=ec(e,t,n);break a}}else for(o=t.child,o!==null&&(o.return=t);o!==null;){var c=o.dependencies;if(c!==null){s=o.child;for(var l=c.firstContext;l!==null;){if(l.context===i){if(o.tag===1){l=io(-1,n&-n),l.tag=2;var u=o.updateQueue;if(u!==null){u=u.shared;var d=u.pending;d===null?l.next=l:(l.next=d.next,d.next=l),u.pending=l}}o.lanes|=n,l=o.alternate,l!==null&&(l.lanes|=n),Ja(o.return,n,t),c.lanes|=n;break}l=l.next}}else if(o.tag===10)s=o.type===t.type?null:o.child;else if(o.tag===18){if(s=o.return,s===null)throw Error(r(341));s.lanes|=n,c=s.alternate,c!==null&&(c.lanes|=n),Ja(s,n,t),s=o.sibling}else s=o.child;if(s!==null)s.return=o;else for(s=o;s!==null;){if(s===t){s=null;break}if(o=s.sibling,o!==null){o.return=s.return,s=o;break}s=s.return}o=s}}Ns(e,t,a.children,n),t=t.child}return t;case 9:return a=t.type,i=t.pendingProps.children,Ya(t,n),a=Xa(a),i=i(a),t.flags|=1,Ns(e,t,i,n),t.child;case 14:return i=t.type,a=hs(i,t.pendingProps),a=hs(i.type,a),Fs(e,t,i,a,n);case 15:return Is(e,t,t.type,t.pendingProps,n);case 17:return i=t.type,a=t.pendingProps,a=t.elementType===i?a:hs(i,a),$s(e,t),t.tag=1,Qi(i)?(e=!0,na(t)):e=!1,Ya(t,n),ys(t,i,a),xs(t,i,a,n),Vs(null,t,i,!0,e,n);case 19:return Qs(e,t,n);case 22:return Ls(e,t,n)}throw Error(r(156,t.tag))};function Wl(e,t){return yt(e,t)}function Gl(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Kl(e,t,n,r){return new Gl(e,t,n,r)}function ql(e){return e=e.prototype,!(!e||!e.isReactComponent)}function Jl(e){if(typeof e==`function`)return+!!ql(e);if(e!=null){if(e=e.$$typeof,e===ne)return 11;if(e===A)return 14}return 2}function Yl(e,t){var n=e.alternate;return n===null?(n=Kl(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function Xl(e,t,n,i,a,o){var s=2;if(i=e,typeof e==`function`)ql(e)&&(s=1);else if(typeof e==`string`)s=5;else a:switch(e){case ee:return Zl(n.children,a,o,t);case te:s=8,a|=8;break;case E:return e=Kl(12,n,t,a|2),e.elementType=E,e.lanes=o,e;case re:return e=Kl(13,n,t,a),e.elementType=re,e.lanes=o,e;case k:return e=Kl(19,n,t,a),e.elementType=k,e.lanes=o,e;case ie:return Ql(n,a,o,t);default:if(typeof e==`object`&&e)switch(e.$$typeof){case D:s=10;break a;case O:s=9;break a;case ne:s=11;break a;case A:s=14;break a;case j:s=16,i=null;break a}throw Error(r(130,e==null?e:typeof e,``))}return t=Kl(s,n,t,a),t.elementType=e,t.type=i,t.lanes=o,t}function Zl(e,t,n,r){return e=Kl(7,e,r,t),e.lanes=n,e}function Ql(e,t,n,r){return e=Kl(22,e,r,t),e.elementType=ie,e.lanes=n,e.stateNode={isHidden:!1},e}function $l(e,t,n){return e=Kl(6,e,null,t),e.lanes=n,e}function eu(e,t,n){return t=Kl(4,e.children===null?[]:e.children,e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function tu(e,t,n,r,i){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Wt(0),this.expirationTimes=Wt(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Wt(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function nu(e,t,n,r,i,a,o,s,c){return e=new tu(e,t,n,s,c),t===1?(t=1,!0===a&&(t|=8)):t=0,a=Kl(3,null,null,t),e.current=a,a.stateNode=e,a.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},no(a),e}function ru(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:T,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}function iu(e){if(!e)return qi;e=e._reactInternals;a:{if(pt(e)!==e||e.tag!==1)throw Error(r(170));var t=e;do{switch(t.tag){case 3:t=t.stateNode.context;break a;case 1:if(Qi(t.type)){t=t.stateNode.__reactInternalMemoizedMergedChildContext;break a}}t=t.return}while(t!==null);throw Error(r(171))}if(e.tag===1){var n=e.type;if(Qi(n))return ta(e,n,t)}return t}function au(e,t,n,r,i,a,o,s,c){return e=nu(n,r,!0,e,i,a,o,s,c),e.context=iu(null),n=e.current,r=fl(),i=pl(n),a=io(r,i),a.callback=t??null,ao(n,a,i),e.current.lanes=i,Gt(e,i,r),hl(e,r),e}function ou(e,t,n,r){var i=t.current,a=fl(),o=pl(i);return n=iu(n),t.context===null?t.context=n:t.pendingContext=n,t=io(a,o),t.payload={element:e},r=r===void 0?null:r,r!==null&&(t.callback=r),e=ao(i,t,o),e!==null&&(ml(e,i,o,a),oo(e,i,o)),o}function su(e){if(e=e.current,!e.child)return null;switch(e.child.tag){case 5:return e.child.stateNode;default:return e.child.stateNode}}function cu(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var n=e.retryLane;e.retryLane=n!==0&&n<t?n:t}}function lu(e,t){cu(e,t),(e=e.alternate)&&cu(e,t)}function uu(){return null}var du=typeof reportError==`function`?reportError:function(e){console.error(e)};function fu(e){this._internalRoot=e}pu.prototype.render=fu.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(r(409));ou(e,t,null,null)},pu.prototype.unmount=fu.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;Cl(function(){ou(null,e,null,null)}),t[Li]=null}};function pu(e){this._internalRoot=e}pu.prototype.unstable_scheduleHydration=function(e){if(e){var t=Qt();e={blockedOn:null,target:e,priority:t};for(var n=0;n<cn.length&&t!==0&&t<cn[n].priority;n++);cn.splice(n,0,e),n===0&&pn(e)}};function mu(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function hu(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==` react-mount-point-unstable `))}function gu(){}function _u(e,t,n,r,i){if(i){if(typeof r==`function`){var a=r;r=function(){var e=su(o);a.call(e)}}var o=au(t,r,e,0,null,!1,!1,``,gu);return e._reactRootContainer=o,e[Li]=o.current,di(e.nodeType===8?e.parentNode:e),Cl(),o}for(;i=e.lastChild;)e.removeChild(i);if(typeof r==`function`){var s=r;r=function(){var e=su(c);s.call(e)}}var c=nu(e,0,!1,null,null,!1,!1,``,gu);return e._reactRootContainer=c,e[Li]=c.current,di(e.nodeType===8?e.parentNode:e),Cl(function(){ou(t,c,n,r)}),c}function vu(e,t,n,r,i){var a=n._reactRootContainer;if(a){var o=a;if(typeof i==`function`){var s=i;i=function(){var e=su(o);s.call(e)}}ou(t,o,e,i)}else o=_u(n,t,e,i,r);return su(o)}Yt=function(e){switch(e.tag){case 3:var t=e.stateNode;if(t.current.memoizedState.isDehydrated){var n=Rt(t.pendingLanes);n!==0&&(qt(t,n|1),hl(t,Ct()),!($&6)&&(el=Ct()+500,la()))}break;case 13:Cl(function(){var t=eo(e,1);t!==null&&ml(t,e,1,fl())}),lu(e,1)}},Xt=function(e){if(e.tag===13){var t=eo(e,134217728);t!==null&&ml(t,e,134217728,fl()),lu(e,134217728)}},Zt=function(e){if(e.tag===13){var t=pl(e),n=eo(e,t);n!==null&&ml(n,e,t,fl()),lu(e,t)}},Qt=function(){return P},$t=function(e,t){var n=P;try{return P=e,t()}finally{P=n}},Ke=function(e,t,n){switch(t){case`input`:if(Ce(e,n),t=n.name,n.type===`radio`&&t!=null){for(n=e;n.parentNode;)n=n.parentNode;for(n=n.querySelectorAll(`input[name=`+JSON.stringify(``+t)+`][type="radio"]`),t=0;t<n.length;t++){var i=n[t];if(i!==e&&i.form===e.form){var a=Wi(i);if(!a)throw Error(r(90));ve(i),Ce(i,a)}}}break;case`textarea`:Ae(e,n);break;case`select`:t=n.value,t!=null&&De(e,!!n.multiple,t,!1)}},Qe=Sl,$e=Cl;var yu={usingClientEntryPoint:!1,Events:[Hi,Ui,Wi,Xe,Ze,Sl]},bu={findFiberByHostInstance:Vi,bundleType:0,version:`18.3.1`,rendererPackageName:`react-dom`},xu={bundleType:bu.bundleType,version:bu.version,rendererPackageName:bu.rendererPackageName,rendererConfig:bu.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:C.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=_t(e),e===null?null:e.stateNode},findFiberByHostInstance:bu.findFiberByHostInstance||uu,findHostInstancesForRefresh:null,scheduleRefresh:null,scheduleRoot:null,setRefreshHandler:null,getCurrentFiber:null,reconcilerVersion:`18.3.1-next-f1338f8080-20240426`};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`){var Su=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Su.isDisabled&&Su.supportsFiber)try{At=Su.inject(xu),jt=Su}catch{}}e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=yu,e.createPortal=function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!mu(t))throw Error(r(200));return ru(e,t,null,n)},e.createRoot=function(e,t){if(!mu(e))throw Error(r(299));var n=!1,i=``,a=du;return t!=null&&(!0===t.unstable_strictMode&&(n=!0),t.identifierPrefix!==void 0&&(i=t.identifierPrefix),t.onRecoverableError!==void 0&&(a=t.onRecoverableError)),t=nu(e,1,!1,null,null,n,!1,i,a),e[Li]=t.current,di(e.nodeType===8?e.parentNode:e),new fu(t)},e.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var t=e._reactInternals;if(t===void 0)throw typeof e.render==`function`?Error(r(188)):(e=Object.keys(e).join(`,`),Error(r(268,e)));return e=_t(t),e=e===null?null:e.stateNode,e},e.flushSync=function(e){return Cl(e)},e.hydrate=function(e,t,n){if(!hu(t))throw Error(r(200));return vu(null,e,t,!0,n)},e.hydrateRoot=function(e,t,n){if(!mu(e))throw Error(r(405));var i=n!=null&&n.hydratedSources||null,a=!1,o=``,s=du;if(n!=null&&(!0===n.unstable_strictMode&&(a=!0),n.identifierPrefix!==void 0&&(o=n.identifierPrefix),n.onRecoverableError!==void 0&&(s=n.onRecoverableError)),t=au(t,null,e,1,n??null,a,!1,o,s),e[Li]=t.current,di(e),i)for(e=0;e<i.length;e++)n=i[e],a=n._getVersion,a=a(n._source),t.mutableSourceEagerHydrationData==null?t.mutableSourceEagerHydrationData=[n,a]:t.mutableSourceEagerHydrationData.push(n,a);return new pu(t)},e.render=function(e,t,n){if(!hu(t))throw Error(r(200));return vu(null,e,t,!1,n)},e.unmountComponentAtNode=function(e){if(!hu(e))throw Error(r(40));return e._reactRootContainer?(Cl(function(){vu(null,null,e,!1,function(){e._reactRootContainer=null,e[Li]=null})}),!0):!1},e.unstable_batchedUpdates=Sl,e.unstable_renderSubtreeIntoContainer=function(e,t,n,i){if(!hu(n))throw Error(r(200));if(e==null||e._reactInternals===void 0)throw Error(r(38));return vu(e,t,n,!1,i)},e.version=`18.3.1-next-f1338f8080-20240426`})),m=o(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=p()})),h=o((e=>{var t=m();e.createRoot=t.createRoot,e.hydrateRoot=t.hydrateRoot})),g=c(u(),1),_=c(h(),1),v=`modulepreload`,y=function(e){return`/`+e},b={},x=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=y(t,n),t=s(t),t in b)return;b[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:v,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},S=/^(?:[a-z][a-z0-9+.-]*:|[\\/]{2})/i,C=/^[\\/]{2}/;function w(e,t){return t+e.replace(/\\/g,`/`)}var T=`popstate`;function ee(e){return typeof e==`object`&&!!e&&`pathname`in e&&`search`in e&&`hash`in e&&`state`in e&&`key`in e}function te(e={}){function t(e,t){let n=t.state?.masked,{pathname:r,search:i,hash:a}=n||e.location;return re(``,{pathname:r,search:i,hash:a},t.state&&t.state.usr||null,t.state&&t.state.key||`default`,n?{pathname:e.location.pathname,search:e.location.search,hash:e.location.hash}:void 0)}function n(e,t){return typeof t==`string`?t:k(t)}return j(t,n,null,e)}function E(e,t){if(e===!1||e==null)throw Error(t)}function D(e,t){if(!e){typeof console<`u`&&console.warn(t);try{throw Error(t)}catch{}}}function O(){return Math.random().toString(36).substring(2,10)}function ne(e,t){return{usr:e.state,key:e.key,idx:t,masked:e.mask?{pathname:e.pathname,search:e.search,hash:e.hash}:void 0}}function re(e,t,n=null,r,i){return{pathname:typeof e==`string`?e:e.pathname,search:``,hash:``,...typeof t==`string`?A(t):t,state:n,key:t&&t.key||r||O(),mask:i}}function k({pathname:e=`/`,search:t=``,hash:n=``}){return t&&t!==`?`&&(e+=t.charAt(0)===`?`?t:`?`+t),n&&n!==`#`&&(e+=n.charAt(0)===`#`?n:`#`+n),e}function A(e){let t={};if(e){let n=e.indexOf(`#`);n>=0&&(t.hash=e.substring(n),e=e.substring(0,n));let r=e.indexOf(`?`);r>=0&&(t.search=e.substring(r),e=e.substring(0,r)),e&&(t.pathname=e)}return t}function j(e,t,n,r={}){let{window:i=document.defaultView,v5Compat:a=!1}=r,o=i.history,s=`POP`,c=null,l=u();l??(l=0,o.replaceState({...o.state,idx:l},``));function u(){return(o.state||{idx:null}).idx}function d(){s=`POP`;let e=u(),t=e==null?null:e-l;l=e,c&&c({action:s,location:h.location,delta:t})}function f(e,t){s=`PUSH`;let r=ee(e)?e:re(h.location,e,t);n&&n(r,e),l=u()+1;let d=ne(r,l),f=h.createHref(r.mask||r);try{o.pushState(d,``,f)}catch(e){if(e instanceof DOMException&&e.name===`DataCloneError`)throw e;i.location.assign(f)}a&&c&&c({action:s,location:h.location,delta:1})}function p(e,t){s=`REPLACE`;let r=ee(e)?e:re(h.location,e,t);n&&n(r,e),l=u();let i=ne(r,l),d=h.createHref(r.mask||r);o.replaceState(i,``,d),a&&c&&c({action:s,location:h.location,delta:0})}function m(e){return ie(i,e)}let h={get action(){return s},get location(){return e(i,o)},listen(e){if(c)throw Error(`A history only accepts one active listener`);return i.addEventListener(T,d),c=e,()=>{i.removeEventListener(T,d),c=null}},createHref(e){return t(i,e)},createURL:m,encodeLocation(e){let t=m(e);return{pathname:t.pathname,search:t.search,hash:t.hash}},push:f,replace:p,go(e){return o.go(e)}};return h}function ie(e,t,n=!1){let r=`http://localhost`;e&&(r=e.location.origin===`null`?e.location.href:e.location.origin),E(r,`No window.location.(origin|href) available to create URL`);let i=typeof t==`string`?t:k(t);return i=i.replace(/ $/,`%20`),!n&&C.test(i)&&(i=r+i),new URL(i,r)}function ae(e,t,n=`/`){return oe(e,t,n,!1)}function oe(e,t,n,r,i){let a=we((typeof t==`string`?A(t):t).pathname||`/`,n);if(a==null)return null;let o=i??M(e),s=null,c=Ce(a);for(let e=0;s==null&&e<o.length;++e)s=ye(o[e],c,r);return s}function M(e){let t=se(e);return le(t),t}function se(e,t=[],n=[],r=``,i=!1){let a=(e,a,o=i,s)=>{let c={relativePath:s===void 0?e.path||``:s,caseSensitive:e.caseSensitive===!0,childrenIndex:a,route:e};if(c.relativePath.startsWith(`/`)){if(!c.relativePath.startsWith(r)&&o)return;E(c.relativePath.startsWith(r),`Absolute route path "${c.relativePath}" nested under path "${r}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`),c.relativePath=c.relativePath.slice(r.length)}let l=Me([r,c.relativePath]),u=n.concat(c);e.children&&e.children.length>0&&(E(e.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${l}".`),se(e.children,t,u,l,o)),!(e.path==null&&!e.index)&&t.push({path:l,score:_e(l,e.index),routesMeta:u.map((e,t)=>{let[n,r]=Se(e.relativePath,e.caseSensitive,t===u.length-1);return{...e,matcher:n,compiledParams:r}})})};return e.forEach((e,t)=>{if(e.path===``||!e.path?.includes(`?`))a(e,t);else for(let n of ce(e.path))a(e,t,!0,n)}),t}function ce(e){let t=e.split(`/`);if(t.length===0)return[];let[n,...r]=t,i=n.endsWith(`?`),a=n.replace(/\?$/,``);if(r.length===0)return i?[a,``]:[a];let o=ce(r.join(`/`)),s=[];return s.push(...o.map(e=>e===``?a:[a,e].join(`/`))),i&&s.push(...o),s.map(t=>e.startsWith(`/`)&&t===``?`/`:t)}function le(e){e.sort((e,t)=>e.score===t.score?ve(e.routesMeta.map(e=>e.childrenIndex),t.routesMeta.map(e=>e.childrenIndex)):t.score-e.score)}var ue=/^:[\w-]+$/,de=3,fe=2,pe=1,me=10,he=-2,ge=e=>e===`*`;function _e(e,t){let n=e.split(`/`),r=n.length;return n.some(ge)&&(r+=he),t&&(r+=fe),n.filter(e=>!ge(e)).reduce((e,t)=>e+(ue.test(t)?de:t===``?pe:me),r)}function ve(e,t){return e.length===t.length&&e.slice(0,-1).every((e,n)=>e===t[n])?e[e.length-1]-t[t.length-1]:0}function ye(e,t,n=!1){let{routesMeta:r}=e,i={},a=`/`,o=[];for(let e=0;e<r.length;++e){let s=r[e],c=e===r.length-1,l=a===`/`?t:t.slice(a.length)||`/`,u={path:s.relativePath,caseSensitive:s.caseSensitive,end:c},d=s.matcher&&s.compiledParams?xe(u,l,s.matcher,s.compiledParams):be(u,l),f=s.route;if(!d&&c&&n&&!r[r.length-1].route.index&&(d=be({path:s.relativePath,caseSensitive:s.caseSensitive,end:!1},l)),!d)return null;Object.assign(i,d.params),o.push({params:i,pathname:Me([a,d.pathname]),pathnameBase:Pe(Me([a,d.pathnameBase])),route:f}),d.pathnameBase!==`/`&&(a=Me([a,d.pathnameBase]))}return o}function be(e,t){typeof e==`string`&&(e={path:e,caseSensitive:!1,end:!0});let[n,r]=Se(e.path,e.caseSensitive,e.end);return xe(e,t,n,r)}function xe(e,t,n,r){let i=t.match(n);if(!i)return null;let a=i[0],o=a.replace(/(.)\/+$/,`$1`),s=i.slice(1);return{params:r.reduce((e,{paramName:t,isOptional:n},r)=>{if(t===`*`){let e=s[r]||``;o=a.slice(0,a.length-e.length).replace(/(.)\/+$/,`$1`)}let i=s[r];return e[t]=n&&!i?void 0:(i||``).replace(/%2F/g,`/`),e},{}),pathname:a,pathnameBase:o,pattern:e}}function Se(e,t=!1,n=!0){D(e===`*`||!e.endsWith(`*`)||e.endsWith(`/*`),`Route path "${e}" will be treated as if it were "${e.replace(/\*$/,`/*`)}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${e.replace(/\*$/,`/*`)}".`);let r=[],i=`^`+e.replace(/\/*\*?$/,``).replace(/^\/*/,`/`).replace(/[\\.*+^${}|()[\]]/g,`\\$&`).replace(/\/:([\w-]+)(\?)?/g,(e,t,n,i,a)=>{if(r.push({paramName:t,isOptional:n!=null}),n){let t=a.charAt(i+e.length);return t&&t!==`/`?`/([^\\/]*)`:`(?:/([^\\/]*))?`}return`/([^\\/]+)`}).replace(/\/([\w-]+)\?(\/|$)/g,`(/$1)?$2`);return e.endsWith(`*`)?(r.push({paramName:`*`}),i+=e===`*`||e===`/*`?`(.*)$`:`(?:\\/(.+)|\\/*)$`):n?i+=`\\/*$`:e!==``&&e!==`/`&&(i+=`(?:(?=\\/|$))`),[new RegExp(i,t?void 0:`i`),r]}function Ce(e){try{return e.split(`/`).map(e=>decodeURIComponent(e).replace(/\//g,`%2F`)).join(`/`)}catch(t){return D(!1,`The URL path "${e}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${t}).`),e}}function we(e,t){if(t===`/`)return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let n=t.endsWith(`/`)?t.length-1:t.length,r=e.charAt(n);return r&&r!==`/`?null:e.slice(n)||`/`}function Te(e,t=`/`){let{pathname:n,search:r=``,hash:i=``}=typeof e==`string`?A(e):e,a;return n?(n=je(n),a=n.startsWith(`/`)?Ee(n.substring(1),`/`):Ee(n,t)):a=t,{pathname:a,search:Fe(r),hash:Ie(i)}}function Ee(e,t){let n=Ne(t).split(`/`);return e.split(`/`).forEach(e=>{e===`..`?n.length>1&&n.pop():e!==`.`&&n.push(e)}),n.length>1?n.join(`/`):`/`}function De(e,t,n,r){return`Cannot include a '${e}' character in a manually specified \`to.${t}\` field [${JSON.stringify(r)}]. Please separate it out to the \`to.${n}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`}function Oe(e){return e.filter((e,t)=>t===0||e.route.path&&e.route.path.length>0)}function ke(e){let t=Oe(e);return t.map((e,n)=>n===t.length-1?e.pathname:e.pathnameBase)}function Ae(e,t,n,r=!1){let i;typeof e==`string`?i=A(e):(i={...e},E(!i.pathname||!i.pathname.includes(`?`),De(`?`,`pathname`,`search`,i)),E(!i.pathname||!i.pathname.includes(`#`),De(`#`,`pathname`,`hash`,i)),E(!i.search||!i.search.includes(`#`),De(`#`,`search`,`hash`,i)));let a=e===``||i.pathname===``,o=a?`/`:i.pathname,s;if(o==null)s=n;else{let e=t.length-1;if(!r&&o.startsWith(`..`)){let t=o.split(`/`);for(;t[0]===`..`;)t.shift(),--e;i.pathname=t.join(`/`)}s=e>=0?t[e]:`/`}let c=Te(i,s),l=o&&o!==`/`&&o.endsWith(`/`),u=(a||o===`.`)&&n.endsWith(`/`);return!c.pathname.endsWith(`/`)&&(l||u)&&(c.pathname+=`/`),c}var je=e=>e.replace(/[\\/]{2,}/g,`/`),Me=e=>je(e.join(`/`)),Ne=e=>e.replace(/\/+$/,``),Pe=e=>Ne(e).replace(/^\/*/,`/`),Fe=e=>!e||e===`?`?``:e.startsWith(`?`)?e:`?`+e,Ie=e=>!e||e===`#`?``:e.startsWith(`#`)?e:`#`+e,Le=class{constructor(e,t,n,r=!1){this.status=e,this.statusText=t||``,this.internal=r,n instanceof Error?(this.data=n.toString(),this.error=n):this.data=n}};function Re(e){return e!=null&&typeof e.status==`number`&&typeof e.statusText==`string`&&typeof e.internal==`boolean`&&`data`in e}function ze(e){return Me(e.map(e=>e.route.path).filter(Boolean))||`/`}var Be=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function Ve(e,t){let n=e;if(typeof n!=`string`||!S.test(n))return{absoluteURL:void 0,isExternal:!1,to:n};let r=n,i=!1;if(Be)try{let e=new URL(window.location.href),r=C.test(n)?new URL(w(n,e.protocol)):new URL(n),a=we(r.pathname,t);r.origin===e.origin&&a!=null?n=a+r.search+r.hash:i=!0}catch{D(!1,`<Link to="${n}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`)}return{absoluteURL:r,isExternal:i,to:n}}Object.getOwnPropertyNames(Object.prototype).sort().join(`\0`);var He=[`POST`,`PUT`,`PATCH`,`DELETE`];new Set(He);var Ue=[`GET`,...He];new Set(Ue);var We=[`about:`,`blob:`,`chrome:`,`chrome-untrusted:`,`content:`,`data:`,`devtools:`,`file:`,`filesystem:`,`javascript:`];function Ge(e){try{return We.includes(new URL(e).protocol)}catch{return!1}}var Ke=g.createContext(null);Ke.displayName=`DataRouter`;var qe=g.createContext(null);qe.displayName=`DataRouterState`;var Je=g.createContext(!1);function Ye(){return g.useContext(Je)}var Xe=g.createContext({isTransitioning:!1});Xe.displayName=`ViewTransition`;var Ze=g.createContext(new Map);Ze.displayName=`Fetchers`;var Qe=g.createContext(null);Qe.displayName=`Await`;var $e=g.createContext(null);$e.displayName=`Navigation`;var et=g.createContext(null);et.displayName=`Location`;var tt=g.createContext({outlet:null,matches:[],isDataRoute:!1});tt.displayName=`Route`;var nt=g.createContext(null);nt.displayName=`RouteError`;var rt=`REACT_ROUTER_ERROR`,it=`REDIRECT`,at=`ROUTE_ERROR_RESPONSE`;function ot(e){if(e.startsWith(`${rt}:${it}:{`))try{let t=JSON.parse(e.slice(28));if(typeof t==`object`&&t&&typeof t.status==`number`&&typeof t.statusText==`string`&&typeof t.location==`string`&&typeof t.reloadDocument==`boolean`&&typeof t.replace==`boolean`)return t}catch{}}function st(e){if(e.startsWith(`${rt}:${at}:{`))try{let t=JSON.parse(e.slice(40));if(typeof t==`object`&&t&&typeof t.status==`number`&&typeof t.statusText==`string`)return new Le(t.status,t.statusText,t.data)}catch{}}function ct(e,{relative:t}={}){E(lt(),`useHref() may be used only in the context of a <Router> component.`);let{basename:n,navigator:r}=g.useContext($e),{hash:i,pathname:a,search:o}=ht(e,{relative:t}),s=a;return n!==`/`&&(s=a===`/`?n:Me([n,a])),r.createHref({pathname:s,search:o,hash:i})}function lt(){return g.useContext(et)!=null}function ut(){return E(lt(),`useLocation() may be used only in the context of a <Router> component.`),g.useContext(et).location}var dt=`You should call navigate() in a React.useEffect(), not when your component is first rendered.`;function ft(e){g.useContext($e).static||g.useLayoutEffect(e)}function pt(){let{isDataRoute:e}=g.useContext(tt);return e?Mt():mt()}function mt(){E(lt(),`useNavigate() may be used only in the context of a <Router> component.`);let e=g.useContext(Ke),{basename:t,navigator:n}=g.useContext($e),{matches:r}=g.useContext(tt),{pathname:i}=ut(),a=JSON.stringify(ke(r)),o=g.useRef(!1);return ft(()=>{o.current=!0}),g.useCallback((r,s={})=>{if(D(o.current,dt),!o.current)return;if(typeof r==`number`){n.go(r);return}let c=Ae(r,JSON.parse(a),i,s.relative===`path`);e==null&&t!==`/`&&(c.pathname=c.pathname===`/`?t:Me([t,c.pathname])),(s.replace?n.replace:n.push)(c,s.state,s)},[t,n,a,i,e])}g.createContext(null);function ht(e,{relative:t}={}){let{matches:n}=g.useContext(tt),{pathname:r}=ut(),i=JSON.stringify(ke(n));return g.useMemo(()=>Ae(e,JSON.parse(i),r,t===`path`),[e,i,r,t])}function gt(e,t){return _t(e,t)}function _t(e,t,n){E(lt(),`useRoutes() may be used only in the context of a <Router> component.`);let{navigator:r}=g.useContext($e),{matches:i}=g.useContext(tt),a=i[i.length-1],o=a?a.params:{},s=a?a.pathname:`/`,c=a?a.pathnameBase:`/`,l=a&&a.route;{let e=l&&l.path||``;Pt(s,!l||e.endsWith(`*`)||e.endsWith(`*?`),`You rendered descendant <Routes> (or called \`useRoutes()\`) at "${s}" (under <Route path="${e}">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
|
|
9
9
|
|
|
10
|
-
Please change the parent <Route path="${e}"> to <Route path="${e===`/`?`*`:`${e}/*`}">.`)}let u=ut(),d;if(t){let e=typeof t==`string`?A(t):t;E(c===`/`||e.pathname?.startsWith(c),`When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${c}" but pathname "${e.pathname}" was given in the \`location\` prop.`),d=e}else d=u;let f=d.pathname||`/`,p=f;if(c!==`/`){let e=c.replace(/^\//,``).split(`/`);p=`/`+f.replace(/^\//,``).split(`/`).slice(e.length).join(`/`)}let m=n&&n.state.matches.length?n.state.matches.map(e=>Object.assign(e,{route:n.manifest[e.route.id]||e.route})):ae(e,{pathname:p});D(l||m!=null,`No routes matched location "${d.pathname}${d.search}${d.hash}" `),D(m==null||m[m.length-1].route.element!==void 0||m[m.length-1].route.Component!==void 0||m[m.length-1].route.lazy!==void 0,`Matched leaf route at location "${d.pathname}${d.search}${d.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`);let h=wt(m&&m.map(e=>Object.assign({},e,{params:Object.assign({},o,e.params),pathname:Me([c,r.encodeLocation?r.encodeLocation(e.pathname.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathname]),pathnameBase:e.pathnameBase===`/`?c:Me([c,r.encodeLocation?r.encodeLocation(e.pathnameBase.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathnameBase])})),i,n);return t&&h?g.createElement(et.Provider,{value:{location:{pathname:`/`,search:``,hash:``,state:null,key:`default`,mask:void 0,...d},navigationType:`POP`}},h):h}function vt(){let e=jt(),t=Re(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,r=`rgba(200,200,200, 0.5)`,i={padding:`0.5rem`,backgroundColor:r},a={padding:`2px 4px`,backgroundColor:r},o=null;return console.error(`Error handled by React Router default ErrorBoundary:`,e),o=g.createElement(g.Fragment,null,g.createElement(`p`,null,`💿 Hey developer 👋`),g.createElement(`p`,null,`You can provide a way better UX than this when your app throws errors by providing your own `,g.createElement(`code`,{style:a},`ErrorBoundary`),` or`,` `,g.createElement(`code`,{style:a},`errorElement`),` prop on your route.`)),g.createElement(g.Fragment,null,g.createElement(`h2`,null,`Unexpected Application Error!`),g.createElement(`h3`,{style:{fontStyle:`italic`}},t),n?g.createElement(`pre`,{style:i},n):null,o)}var yt=g.createElement(vt,null),bt=class extends g.Component{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,t){return t.location!==e.location||t.revalidation!==`idle`&&e.revalidation===`idle`?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error===void 0?t.error:e.error,location:t.location,revalidation:e.revalidation||t.revalidation}}componentDidCatch(e,t){this.props.onError?this.props.onError(e,t):console.error(`React Router caught the following error during render`,e)}render(){let e=this.state.error;if(this.context&&typeof e==`object`&&e&&`digest`in e&&typeof e.digest==`string`){let t=st(e.digest);t&&(e=t)}let t=e===void 0?this.props.children:g.createElement(tt.Provider,{value:this.props.routeContext},g.createElement(nt.Provider,{value:e,children:this.props.component}));return this.context?g.createElement(St,{error:e},t):t}};bt.contextType=Je;var xt=new WeakMap;function St({children:e,error:t}){let{basename:n}=g.useContext($e);if(typeof t==`object`&&t&&`digest`in t&&typeof t.digest==`string`){let e=ot(t.digest);if(e){let r=xt.get(t);if(r)throw r;let i=Ve(e.location,n),a=i.absoluteURL||i.to;if(Ge(a))throw Error(`Invalid redirect location`);if(Be&&!xt.get(t)){if(i.isExternal||e.reloadDocument)window.location.href=a;else{let n=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(i.to,{replace:e.replace}));throw xt.set(t,n),n}}return g.createElement(`meta`,{httpEquiv:`refresh`,content:`0;url=${a}`})}}return e}function Ct({routeContext:e,match:t,children:n}){let r=g.useContext(Ke);return r&&r.static&&r.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(r.staticContext._deepestRenderedBoundaryId=t.route.id),g.createElement(tt.Provider,{value:e},n)}function wt(e,t=[],n){let r=n?.state;if(e==null){if(!r)return null;if(r.errors)e=r.matches;else if(t.length===0&&!r.initialized&&r.matches.length>0)e=r.matches;else return null}let i=e,a=r?.errors;if(a!=null){let e=i.findIndex(e=>e.route.id&&a?.[e.route.id]!==void 0);E(e>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(a).join(`,`)}`),i=i.slice(0,Math.min(i.length,e+1))}let o=!1,s=-1;if(n&&r){o=r.renderFallback;for(let e=0;e<i.length;e++){let t=i[e];if((t.route.HydrateFallback||t.route.hydrateFallbackElement)&&(s=e),t.route.id){let{loaderData:e,errors:a}=r,c=t.route.loader&&!e.hasOwnProperty(t.route.id)&&(!a||a[t.route.id]===void 0);if(t.route.lazy||c){n.isStatic&&(o=!0),i=s>=0?i.slice(0,s+1):[i[0]];break}}}}let c=n?.onError,l=r&&c?(e,t)=>{c(e,{location:r.location,params:r.matches?.[0]?.params??{},pattern:ze(r.matches),errorInfo:t})}:void 0;return i.reduceRight((e,n,c)=>{let u,d=!1,f=null,p=null;r&&(u=a&&n.route.id?a[n.route.id]:void 0,f=n.route.errorElement||yt,o&&(s<0&&c===0?(Pt(`route-fallback`,!1,"No `HydrateFallback` element provided to render during initial hydration"),d=!0,p=null):s===c&&(d=!0,p=n.route.hydrateFallbackElement||null)));let m=t.concat(i.slice(0,c+1)),h=()=>{let t;return t=u?f:d?p:n.route.Component?g.createElement(n.route.Component,null):n.route.element?n.route.element:e,g.createElement(Ct,{match:n,routeContext:{outlet:e,matches:m,isDataRoute:r!=null},children:t})};return r&&(n.route.ErrorBoundary||n.route.errorElement||c===0)?g.createElement(bt,{location:r.location,revalidation:r.revalidation,component:f,error:u,children:h(),routeContext:{outlet:null,matches:m,isDataRoute:!0},onError:l}):h()},null)}function Tt(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Et(e){let t=g.useContext(Ke);return E(t,Tt(e)),t}function Dt(e){let t=g.useContext(qe);return E(t,Tt(e)),t}function Ot(e){let t=g.useContext(tt);return E(t,Tt(e)),t}function kt(e){let t=Ot(e),n=t.matches[t.matches.length-1];return E(n.route.id,`${e} can only be used on routes that contain a unique "id"`),n.route.id}function At(){return kt(`useRouteId`)}function jt(){let e=g.useContext(nt),t=Dt(`useRouteError`),n=kt(`useRouteError`);return e===void 0?t.errors?.[n]:e}function Mt(){let{router:e}=Et(`useNavigate`),t=kt(`useNavigate`),n=g.useRef(!1);return ft(()=>{n.current=!0}),g.useCallback(async(r,i={})=>{D(n.current,dt),n.current&&(typeof r==`number`?await e.navigate(r):await e.navigate(r,{fromRouteId:t,...i}))},[e,t])}var Nt={};function Pt(e,t,n){!t&&!Nt[e]&&(Nt[e]=!0,D(!1,n))}g.memo(Ft);function Ft({routes:e,manifest:t,future:n,state:r,isStatic:i,onError:a}){return _t(e,void 0,{manifest:t,state:r,isStatic:i,onError:a,future:n})}function N(e){E(!1,`A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.`)}function It({basename:e=`/`,children:t=null,location:n,navigationType:r=`POP`,navigator:i,static:a=!1,useTransitions:o}){E(!lt(),`You cannot render a <Router> inside another <Router>. You should never have more than one in your app.`);let s=e.replace(/^\/*/,`/`),c=g.useMemo(()=>({basename:s,navigator:i,static:a,useTransitions:o,future:{}}),[s,i,a,o]);typeof n==`string`&&(n=A(n));let{pathname:l=`/`,search:u=``,hash:d=``,state:f=null,key:p=`default`,mask:m}=n,h=g.useMemo(()=>{let e=we(l,s);return e==null?null:{location:{pathname:e,search:u,hash:d,state:f,key:p,mask:m},navigationType:r}},[s,l,u,d,f,p,r,m]);return D(h!=null,`<Router basename="${s}"> is not able to match the URL "${l}${u}${d}" because it does not start with the basename, so the <Router> won't render anything.`),h==null?null:g.createElement($e.Provider,{value:c},g.createElement(et.Provider,{children:t,value:h}))}function Lt({children:e,location:t}){return gt(Rt(e),t)}g.Component;function Rt(e,t=[]){let n=[];return g.Children.forEach(e,(e,r)=>{if(!g.isValidElement(e))return;let i=[...t,r];if(e.type===g.Fragment){n.push.apply(n,Rt(e.props.children,i));return}E(e.type===N,`[${typeof e.type==`string`?e.type:e.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`),E(!e.props.index||!e.props.children,`An index route cannot have child routes.`);let a={id:e.props.id||i.join(`-`),caseSensitive:e.props.caseSensitive,element:e.props.element,Component:e.props.Component,index:e.props.index,path:e.props.path,middleware:e.props.middleware,loader:e.props.loader,action:e.props.action,hydrateFallbackElement:e.props.hydrateFallbackElement,HydrateFallback:e.props.HydrateFallback,errorElement:e.props.errorElement,ErrorBoundary:e.props.ErrorBoundary,hasErrorBoundary:e.props.hasErrorBoundary===!0||e.props.ErrorBoundary!=null||e.props.errorElement!=null,shouldRevalidate:e.props.shouldRevalidate,handle:e.props.handle,lazy:e.props.lazy};e.props.children&&(a.children=Rt(e.props.children,i)),n.push(a)}),n}var zt=`get`,Bt=`application/x-www-form-urlencoded`;function Vt(e){return typeof HTMLElement<`u`&&e instanceof HTMLElement}function Ht(e){return Vt(e)&&e.tagName.toLowerCase()===`button`}function Ut(e){return Vt(e)&&e.tagName.toLowerCase()===`form`}function Wt(e){return Vt(e)&&e.tagName.toLowerCase()===`input`}function Gt(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function Kt(e,t){return e.button===0&&(!t||t===`_self`)&&!Gt(e)}function qt(e=``){return new URLSearchParams(typeof e==`string`||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map(e=>[n,e]):[[n,r]])},[]))}function P(e,t){let n=qt(e);return t&&t.forEach((e,r)=>{n.has(r)||t.getAll(r).forEach(e=>{n.append(r,e)})}),n}var Jt=null;function Yt(){if(Jt===null)try{new FormData(document.createElement(`form`),0),Jt=!1}catch{Jt=!0}return Jt}var Xt=new Set([`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`]);function Zt(e){return e!=null&&!Xt.has(e)?(D(!1,`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${Bt}"`),null):e}function Qt(e,t){let n,r,i,a,o;if(Ut(e)){let o=e.getAttribute(`action`);r=o?we(o,t):null,n=e.getAttribute(`method`)||zt,i=Zt(e.getAttribute(`enctype`))||Bt,a=new FormData(e)}else if(Ht(e)||Wt(e)&&(e.type===`submit`||e.type===`image`)){let o=e.form;if(o==null)throw Error(`Cannot submit a <button> or <input type="submit"> without a <form>`);let s=e.getAttribute(`formaction`)||o.getAttribute(`action`);if(r=s?we(s,t):null,n=e.getAttribute(`formmethod`)||o.getAttribute(`method`)||zt,i=Zt(e.getAttribute(`formenctype`))||Zt(o.getAttribute(`enctype`))||Bt,a=new FormData(o,e),!Yt()){let{name:t,type:n,value:r}=e;if(n===`image`){let e=t?`${t}.`:``;a.append(`${e}x`,`0`),a.append(`${e}y`,`0`)}else t&&a.append(t,r)}}else if(Vt(e))throw Error(`Cannot submit element that is not <form>, <button>, or <input type="submit|image">`);else n=zt,r=null,i=Bt,o=e;return a&&i===`text/plain`&&(o=a,a=void 0),{action:r,method:n.toLowerCase(),encType:i,formData:a,body:o}}Object.getOwnPropertyNames(Object.prototype).sort().join(`\0`);function $t(e,t){if(e===!1||e==null)throw Error(t)}function en(e,t,n,r){let i=typeof e==`string`?new URL(e,typeof window>`u`?`server://singlefetch/`:window.location.origin):e;return i.pathname=n?i.pathname.endsWith(`/`)?`${i.pathname}_.${r}`:`${i.pathname}.${r}`:i.pathname===`/`?`_root.${r}`:t&&we(i.pathname,t)===`/`?`${Ne(t)}/_root.${r}`:`${Ne(i.pathname)}.${r}`,i}async function tn(e,t){if(e.id in t)return t[e.id];try{let n=await x(()=>import(e.module),[]);return t[e.id]=n,n}catch(t){return console.error(`Error loading route module \`${e.module}\`, reloading page...`),console.error(t),window.__reactRouterContext&&window.__reactRouterContext.isSpaMode,window.location.reload(),new Promise(()=>{})}}function nn(e){return e!=null&&typeof e.page==`string`}function rn(e){return e==null?!1:e.href==null?e.rel===`preload`&&typeof e.imageSrcSet==`string`&&typeof e.imageSizes==`string`:typeof e.rel==`string`&&typeof e.href==`string`}async function an(e,t,n){return un((await Promise.all(e.map(async e=>{let r=t.routes[e.route.id];if(r){let e=await tn(r,n);return e.links?e.links():[]}return[]}))).flat(1).filter(rn).filter(e=>e.rel===`stylesheet`||e.rel===`preload`).map(e=>e.rel===`stylesheet`?{...e,rel:`prefetch`,as:`style`}:{...e,rel:`prefetch`}))}function on(e,t,n,r,i,a){let o=(e,t)=>!n[t]||e.route.id!==n[t].route.id,s=(e,t)=>n[t].pathname!==e.pathname||n[t].route.path?.endsWith(`*`)&&n[t].params[`*`]!==e.params[`*`];return a===`assets`?t.filter((e,t)=>o(e,t)||s(e,t)):a===`data`?t.filter((t,a)=>{let c=r.routes[t.route.id];if(!c||!c.hasLoader)return!1;if(o(t,a)||s(t,a))return!0;if(t.route.shouldRevalidate){let r=t.route.shouldRevalidate({currentUrl:new URL(i.pathname+i.search+i.hash,window.origin),currentParams:n[0]?.params||{},nextUrl:new URL(e,window.origin),nextParams:t.params,defaultShouldRevalidate:!0});if(typeof r==`boolean`)return r}return!0}):[]}function sn(e,t,{includeHydrateFallback:n}={}){return cn(e.map(e=>{let r=t.routes[e.route.id];if(!r)return[];let i=[r.module];return r.clientActionModule&&(i=i.concat(r.clientActionModule)),r.clientLoaderModule&&(i=i.concat(r.clientLoaderModule)),n&&r.hydrateFallbackModule&&(i=i.concat(r.hydrateFallbackModule)),r.imports&&(i=i.concat(r.imports)),i}).flat(1))}function cn(e){return[...new Set(e)]}function ln(e){let t={},n=Object.keys(e).sort();for(let r of n)t[r]=e[r];return t}function un(e,t){let n=new Set,r=new Set(t);return e.reduce((e,i)=>{if(t&&!nn(i)&&i.as===`script`&&i.href&&r.has(i.href))return e;let a=JSON.stringify(ln(i));return n.has(a)||(n.add(a),e.push({key:a,link:i})),e},[])}function dn(){let e=g.useContext(Ke);return $t(e,`You must render this element inside a <DataRouterContext.Provider> element`),e}function fn(){let e=g.useContext(qe);return $t(e,`You must render this element inside a <DataRouterStateContext.Provider> element`),e}var pn=g.createContext(void 0);pn.displayName=`FrameworkContext`;function mn(){let e=g.useContext(pn);return $t(e,`You must render this element inside a <HydratedRouter> element`),e}function hn(e,t){let n=g.useContext(pn),[r,i]=g.useState(!1),[a,o]=g.useState(!1),{onFocus:s,onBlur:c,onMouseEnter:l,onMouseLeave:u,onTouchStart:d}=t,f=g.useRef(null);g.useEffect(()=>{if(e===`render`&&o(!0),e===`viewport`){let e=new IntersectionObserver(e=>{e.forEach(e=>{o(e.isIntersecting)})},{threshold:.5});return f.current&&e.observe(f.current),()=>{e.disconnect()}}},[e]),g.useEffect(()=>{if(r){let e=setTimeout(()=>{o(!0)},100);return()=>{clearTimeout(e)}}},[r]);let p=()=>{i(!0)},m=()=>{i(!1),o(!1)};return n?e===`intent`?[a,f,{onFocus:gn(s,p),onBlur:gn(c,m),onMouseEnter:gn(l,p),onMouseLeave:gn(u,m),onTouchStart:gn(d,p)}]:[a,f,{}]:[!1,f,{}]}function gn(e,t){return n=>{e&&e(n),n.defaultPrevented||t(n)}}function _n({page:e,...t}){let n=Ye(),{nonce:r}=mn(),{router:i}=dn(),a=g.useMemo(()=>ae(i.routes,e,i.basename),[i.routes,e,i.basename]);return a?(t.nonce==null&&r&&(t={...t,nonce:r}),n?g.createElement(yn,{page:e,matches:a,...t}):g.createElement(bn,{page:e,matches:a,...t})):null}function vn(e){let{manifest:t,routeModules:n}=mn(),[r,i]=g.useState([]);return g.useEffect(()=>{let r=!1;return an(e,t,n).then(e=>{r||i(e)}),()=>{r=!0}},[e,t,n]),r}function yn({page:e,matches:t,...n}){let r=ut(),{future:i}=mn(),{basename:a}=dn(),o=g.useMemo(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=en(e,a,i.v8_trailingSlashAwareDataRequests,`rsc`),o=!1,s=[];for(let e of t)typeof e.route.shouldRevalidate==`function`?o=!0:s.push(e.route.id);return o&&s.length>0&&n.searchParams.set(`_routes`,s.join(`,`)),[n.pathname+n.search]},[a,i.v8_trailingSlashAwareDataRequests,e,r,t]);return g.createElement(g.Fragment,null,o.map(e=>g.createElement(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})))}function bn({page:e,matches:t,...n}){let r=ut(),{future:i,manifest:a,routeModules:o}=mn(),{basename:s}=dn(),{loaderData:c,matches:l}=fn(),u=g.useMemo(()=>on(e,t,l,a,r,`data`),[e,t,l,a,r]),d=g.useMemo(()=>on(e,t,l,a,r,`assets`),[e,t,l,a,r]),f=g.useMemo(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=new Set,l=!1;if(t.forEach(e=>{let t=a.routes[e.route.id];!t||!t.hasLoader||(!u.some(t=>t.route.id===e.route.id)&&e.route.id in c&&o[e.route.id]?.shouldRevalidate||t.hasClientLoader?l=!0:n.add(e.route.id))}),n.size===0)return[];let d=en(e,s,i.v8_trailingSlashAwareDataRequests,`data`);return l&&n.size>0&&d.searchParams.set(`_routes`,t.filter(e=>n.has(e.route.id)).map(e=>e.route.id).join(`,`)),[d.pathname+d.search]},[s,i.v8_trailingSlashAwareDataRequests,c,r,a,u,t,e,o]),p=g.useMemo(()=>sn(d,a),[d,a]),m=vn(d);return g.createElement(g.Fragment,null,f.map(e=>g.createElement(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})),p.map(e=>g.createElement(`link`,{key:e,rel:`modulepreload`,href:e,...n})),m.map(({key:e,link:t})=>g.createElement(`link`,{key:e,nonce:n.nonce,...t,crossOrigin:t.crossOrigin??n.crossOrigin})))}function xn(...e){return t=>{e.forEach(e=>{typeof e==`function`?e(t):e!=null&&(e.current=t)})}}g.Component;var Sn=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;try{Sn&&(window.__reactRouterVersion=`7.18.2`)}catch{}function Cn({basename:e,children:t,useTransitions:n,window:r}){let i=g.useRef();i.current??=te({window:r,v5Compat:!0});let a=i.current,[o,s]=g.useState({action:a.action,location:a.location}),c=g.useCallback(e=>{n===!1?s(e):g.startTransition(()=>s(e))},[n]);return g.useLayoutEffect(()=>a.listen(c),[a,c]),g.createElement(It,{basename:e,children:t,location:o.location,navigationType:o.action,navigator:a,useTransitions:n})}var wn=g.forwardRef(function({onClick:e,discover:t=`render`,prefetch:n=`none`,relative:r,reloadDocument:i,replace:a,mask:o,state:s,target:c,to:l,preventScrollReset:u,viewTransition:d,defaultShouldRevalidate:f,...p},m){let{basename:h,navigator:_,useTransitions:v}=g.useContext($e),y=typeof l==`string`&&S.test(l),b=Ve(l,h);l=b.to;let x=ct(l,{relative:r}),C=ut(),w=null;if(o){let e=Ae(o,[],C.mask?C.mask.pathname:`/`,!0);h!==`/`&&(e.pathname=e.pathname===`/`?h:Me([h,e.pathname])),w=_.createHref(e)}let[T,ee,te]=hn(n,p),E=kn(l,{replace:a,mask:o,state:s,target:c,preventScrollReset:u,relative:r,viewTransition:d,defaultShouldRevalidate:f,useTransitions:v});function D(t){e&&e(t),t.defaultPrevented||E(t)}let O=!(b.isExternal||i),ne=g.createElement(`a`,{...p,...te,href:(O?w:void 0)||b.absoluteURL||x,onClick:O?D:e,ref:xn(m,ee),target:c,"data-discover":!y&&t===`render`?`true`:void 0});return T&&!y?g.createElement(g.Fragment,null,ne,g.createElement(_n,{page:x})):ne});wn.displayName=`Link`;var Tn=g.forwardRef(function({"aria-current":e=`page`,caseSensitive:t=!1,className:n=``,end:r=!1,style:i,to:a,viewTransition:o,children:s,...c},l){let u=ht(a,{relative:c.relative}),d=ut(),f=g.useContext(qe),{navigator:p,basename:m}=g.useContext($e),h=f!=null&&Fn(u)&&o===!0,_=p.encodeLocation?p.encodeLocation(u).pathname:u.pathname,v=d.pathname,y=f&&f.navigation&&f.navigation.location?f.navigation.location.pathname:null;t||(v=v.toLowerCase(),y=y?y.toLowerCase():null,_=_.toLowerCase()),y&&m&&(y=we(y,m)||y);let b=_!==`/`&&_.endsWith(`/`)?_.length-1:_.length,x=v===_||!r&&v.startsWith(_)&&v.charAt(b)===`/`,S=y!=null&&(y===_||!r&&y.startsWith(_)&&y.charAt(_.length)===`/`),C={isActive:x,isPending:S,isTransitioning:h},w=x?e:void 0,T;T=typeof n==`function`?n(C):[n,x?`active`:null,S?`pending`:null,h?`transitioning`:null].filter(Boolean).join(` `);let ee=typeof i==`function`?i(C):i;return g.createElement(wn,{...c,"aria-current":w,className:T,ref:l,style:ee,to:a,viewTransition:o},typeof s==`function`?s(C):s)});Tn.displayName=`NavLink`;var En=g.forwardRef(({discover:e=`render`,fetcherKey:t,navigate:n,reloadDocument:r,replace:i,state:a,method:o=zt,action:s,onSubmit:c,relative:l,preventScrollReset:u,viewTransition:d,defaultShouldRevalidate:f,...p},m)=>{let{useTransitions:h}=g.useContext($e),_=Nn(),v=Pn(s,{relative:l}),y=o.toLowerCase()===`get`?`get`:`post`,b=typeof s==`string`&&S.test(s);return g.createElement(`form`,{ref:m,method:y,action:v,onSubmit:r?c:e=>{if(c&&c(e),e.defaultPrevented)return;e.preventDefault();let r=e.nativeEvent.submitter,s=r?.getAttribute(`formmethod`)||o,p=()=>_(r||e.currentTarget,{fetcherKey:t,method:s,navigate:n,replace:i,state:a,relative:l,preventScrollReset:u,viewTransition:d,defaultShouldRevalidate:f});h&&n!==!1?g.startTransition(()=>p()):p()},...p,"data-discover":!b&&e===`render`?`true`:void 0})});En.displayName=`Form`;function Dn(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function On(e){let t=g.useContext(Ke);return E(t,Dn(e)),t}function kn(e,{target:t,replace:n,mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,defaultShouldRevalidate:c,useTransitions:l}={}){let u=pt(),d=ut(),f=ht(e,{relative:o});return g.useCallback(p=>{if(Kt(p,t)){p.preventDefault();let t=n===void 0?k(d)===k(f):n,m=()=>u(e,{replace:t,mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,defaultShouldRevalidate:c});l?g.startTransition(()=>m()):m()}},[d,u,f,n,r,i,t,e,a,o,s,c,l])}function An(e){D(typeof URLSearchParams<`u`,"You cannot use the `useSearchParams` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params.");let t=g.useRef(qt(e)),n=g.useRef(!1),r=ut(),i=g.useMemo(()=>P(r.search,n.current?null:t.current),[r.search]),a=pt();return[i,g.useCallback((e,t)=>{let r=qt(typeof e==`function`?e(new URLSearchParams(i)):e);n.current=!0,a(`?`+r,t)},[a,i])]}var jn=0,Mn=()=>`__${String(++jn)}__`;function Nn(){let{router:e}=On(`useSubmit`),{basename:t}=g.useContext($e),n=At(),r=e.fetch,i=e.navigate;return g.useCallback(async(e,a={})=>{let{action:o,method:s,encType:c,formData:l,body:u}=Qt(e,t);if(a.navigate===!1){let e=a.fetcherKey||Mn();await r(e,n,a.action||o,{defaultShouldRevalidate:a.defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,flushSync:a.flushSync})}else await i(a.action||o,{defaultShouldRevalidate:a.defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,replace:a.replace,state:a.state,fromRouteId:n,flushSync:a.flushSync,viewTransition:a.viewTransition})},[r,i,t,n])}function Pn(e,{relative:t}={}){let{basename:n}=g.useContext($e),r=g.useContext(tt);E(r,`useFormAction must be used inside a RouteContext`);let[i]=r.matches.slice(-1),a={...ht(e||`.`,{relative:t})},o=ut();if(e==null){a.search=o.search;let e=new URLSearchParams(a.search),t=e.getAll(`index`);if(t.some(e=>e===``)){e.delete(`index`),t.filter(e=>e).forEach(t=>e.append(`index`,t));let n=e.toString();a.search=n?`?${n}`:``}}return(!e||e===`.`)&&i.route.index&&(a.search=a.search?a.search.replace(/^\?/,`?index&`):`?index`),n!==`/`&&(a.pathname=a.pathname===`/`?n:Me([n,a.pathname])),k(a)}function Fn(e,{relative:t}={}){let n=g.useContext(Xe);E(n!=null,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:r}=On(`useViewTransitionState`),i=ht(e,{relative:t});if(!n.isTransitioning)return!1;let a=we(n.currentLocation.pathname,r)||n.currentLocation.pathname,o=we(n.nextLocation.pathname,r)||n.nextLocation.pathname;return be(i.pathname,o)!=null||be(i.pathname,a)!=null}function In(e,t=`default`){let[n,r]=(0,g.useState)(null);return(0,g.useEffect)(()=>{if(!e){r(null);return}let n=e.runtime(),i=n.runtime===`browser`?`browser`:n.runtime===`node`?`self-hosted`:`remote`;r({db:e,connected:!0,namespace:t,instanceId:e.instanceId?.()||`unknown`,environment:i})},[e,t]),n}function Ln(e,t){let[n,r]=(0,g.useState)([]),[i,a]=(0,g.useState)(!0),[o,s]=(0,g.useState)(null);return(0,g.useEffect)(()=>{if(e){a(!0),s(null);try{let n=e.collection(t).subscribe(e=>{r(e),a(!1)});return()=>n()}catch(e){s(e instanceof Error?e.message:`Failed to load collection`),a(!1)}}},[e,t]),{items:n,loading:i,error:o}}var Rn=o((e=>{var t=u(),n=Symbol.for(`react.element`),r=Symbol.for(`react.fragment`),i=Object.prototype.hasOwnProperty,a=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function s(e,t,r){var s,c={},l=null,u=null;for(s in r!==void 0&&(l=``+r),t.key!==void 0&&(l=``+t.key),t.ref!==void 0&&(u=t.ref),t)i.call(t,s)&&!o.hasOwnProperty(s)&&(c[s]=t[s]);if(e&&e.defaultProps)for(s in t=e.defaultProps,t)c[s]===void 0&&(c[s]=t[s]);return{$$typeof:n,type:e,key:l,ref:u,props:c,_owner:a.current}}e.Fragment=r,e.jsx=s,e.jsxs=s})),F=o(((e,t)=>{t.exports=Rn()}))();function zn({db:e,name:t,label:n}){let{items:r}=Ln(e,t);return r.length?(0,F.jsxs)(`section`,{children:[(0,F.jsxs)(`h2`,{children:[n,(0,F.jsx)(`span`,{children:r.length})]}),(0,F.jsx)(`div`,{className:`execution-list`,children:r.map((e,r)=>(0,F.jsxs)(`article`,{className:`execution-row`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`b`,{children:String(e.name??e.workflow??e.incident_id??e.id??n)}),(0,F.jsx)(`small`,{children:t})]}),(0,F.jsx)(`span`,{className:`event-pill put`,children:String(e.status??e.state??`materialized`)}),(0,F.jsx)(`pre`,{children:JSON.stringify(e,null,2)})]},String(e.id??r)))})]}):null}function Bn({db:e,model:t}){return(0,F.jsxs)(`div`,{className:`studio-model-page`,children:[(0,F.jsxs)(`header`,{children:[(0,F.jsx)(`span`,{className:`eyebrow`,children:`Observe`}),(0,F.jsx)(`h1`,{children:`Executions`}),(0,F.jsx)(`p`,{children:`Capability work, workflow runs, assignments, and agent decisions as inspectable state.`})]}),(0,F.jsxs)(`div`,{className:`model-summary`,children:[(0,F.jsxs)(`span`,{children:[t?.workflows.length??0,` workflow definitions`]}),(0,F.jsxs)(`span`,{children:[t?.agents.length??0,` autonomous agents`]})]}),(0,F.jsx)(zn,{db:e??null,name:`_flow_executions`,label:`Capability executions`}),(0,F.jsx)(zn,{db:e??null,name:`_flow_workflow_runs`,label:`Workflow runs`}),(0,F.jsx)(zn,{db:e??null,name:`Assignment`,label:`Materialized assignments`}),(0,F.jsx)(zn,{db:e??null,name:`Decision`,label:`Agent decisions`}),(0,F.jsx)(zn,{db:e??null,name:`_flow_agent_executions`,label:`Agent executions`}),(0,F.jsxs)(`div`,{className:`model-empty execution-empty`,children:[`Execution sections appear as soon as their state is committed. Defined workflows: `,t?.workflows.map(e=>e.name).join(`, `)||`none`,`.`]})]})}function Vn({model:e}){let t=e?.workflows??[],[n,r]=(0,g.useState)(),i=t.find(e=>e.name===n)??t[0];return(0,F.jsxs)(`div`,{className:`studio-model-page`,children:[(0,F.jsxs)(`header`,{children:[(0,F.jsx)(`span`,{className:`eyebrow`,children:`Design`}),(0,F.jsx)(`h1`,{children:`Workflows`}),(0,F.jsx)(`p`,{children:`Durable state transitions declared by the application model.`})]}),(0,F.jsxs)(`div`,{className:`split-browser`,children:[(0,F.jsx)(`aside`,{children:t.map(e=>(0,F.jsxs)(`button`,{className:e.name===i?.name?`active`:``,onClick:()=>r(e.name),children:[(0,F.jsx)(`strong`,{children:e.name}),(0,F.jsxs)(`span`,{children:[e.steps.length,` steps`]})]},e.name))}),(0,F.jsx)(`section`,{children:i?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`div`,{className:`card-kind`,children:`workflow`}),(0,F.jsx)(`h2`,{children:i.name}),i.parameters.length>0&&(0,F.jsxs)(`code`,{className:`signature`,children:[`(`,i.parameters,`)`]}),(0,F.jsx)(`div`,{className:`workflow-track`,children:i.steps.map((e,t)=>(0,F.jsxs)(g.Fragment,{children:[(0,F.jsxs)(`article`,{children:[(0,F.jsx)(`span`,{children:t+1}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`strong`,{children:e.name}),e.statements.map(e=>(0,F.jsx)(`code`,{children:e},e))]})]}),t<i.steps.length-1&&(0,F.jsx)(`i`,{children:`→`})]},e.name))})]}):(0,F.jsx)(`div`,{className:`model-empty`,children:`No workflows are declared.`})})]})]})}function Hn({model:e}){let t=e?.agents??[],[n,r]=(0,g.useState)(),i=t.find(e=>e.name===n)??t[0];return(0,F.jsxs)(`div`,{className:`studio-model-page`,children:[(0,F.jsxs)(`header`,{children:[(0,F.jsx)(`span`,{className:`eyebrow`,children:`Design`}),(0,F.jsx)(`h1`,{children:`Agents`}),(0,F.jsx)(`p`,{children:`Autonomous participants whose authority and workflows are part of the model.`})]}),(0,F.jsxs)(`div`,{className:`split-browser`,children:[(0,F.jsx)(`aside`,{children:t.map(e=>(0,F.jsxs)(`button`,{className:e.name===i?.name?`active`:``,onClick:()=>r(e.name),children:[(0,F.jsx)(`strong`,{children:e.name}),(0,F.jsxs)(`span`,{children:[e.statements.length,` bindings`]})]},e.name))}),(0,F.jsx)(`section`,{children:i?(0,F.jsx)(F.Fragment,{children:(0,F.jsxs)(`div`,{className:`agent-orbit`,children:[(0,F.jsxs)(`div`,{className:`agent-core`,children:[(0,F.jsx)(`span`,{children:`agent`}),(0,F.jsx)(`strong`,{children:i.name})]}),i.statements.map(e=>(0,F.jsxs)(`div`,{className:`agent-binding`,children:[(0,F.jsx)(`span`,{children:e.split(` `)[0]}),(0,F.jsx)(`strong`,{children:e.split(` `).slice(1).join(` `)})]},e))]})}):(0,F.jsx)(`div`,{className:`model-empty`,children:`No agents are declared.`})})]})]})}function Un(e){return e===`node`?`Node.js`:e===`browser`?`Browser`:e===`self-hosted`?`Self-hosted`:e===`managed`?`Managed`:e===`remote`?`Remote`:e||`unavailable`}function Wn({db:e,remoteUrl:t=``,token:n=``,applicationUrl:r=``,feltDBRuntime:i,authorityUrl:a=``,onConnect:o}){let[s,c]=(0,g.useState)(t),[l,u]=(0,g.useState)(n),d=e?.runtime();return(0,g.useEffect)(()=>{c(t),u(n)},[t,n]),(0,F.jsxs)(`div`,{className:`settings-panel`,children:[(0,F.jsx)(`h2`,{children:`Settings`}),(0,F.jsxs)(`div`,{className:`settings-content`,children:[(0,F.jsx)(`h3`,{children:`Application`}),(0,F.jsx)(`div`,{className:`connection-info`,children:(0,F.jsxs)(`div`,{className:`info-row`,children:[(0,F.jsx)(`label`,{children:`URL`}),(0,F.jsx)(`span`,{children:r||`unavailable`})]})}),(0,F.jsx)(`h3`,{children:`FeltDB`}),(0,F.jsxs)(`div`,{className:`connection-info`,children:[(0,F.jsxs)(`div`,{className:`info-row`,children:[(0,F.jsx)(`label`,{children:`Runtime`}),(0,F.jsx)(`span`,{children:Un(i||d?.runtime)})]}),(0,F.jsxs)(`div`,{className:`info-row`,children:[(0,F.jsx)(`label`,{children:`Studio client backend`}),(0,F.jsx)(`span`,{children:d?.storage||`unavailable`})]}),(0,F.jsxs)(`div`,{className:`info-row`,children:[(0,F.jsx)(`label`,{children:`Authority`}),(0,F.jsx)(`span`,{children:a||t||`unavailable`})]}),(0,F.jsxs)(`div`,{className:`info-row`,children:[(0,F.jsx)(`label`,{children:`Instance ID`}),(0,F.jsx)(`span`,{className:`monospace`,children:e?.instanceId?.()||`unavailable`})]})]}),(0,F.jsxs)(`form`,{className:`connection-form`,onSubmit:e=>{e.preventDefault(),o?.(s,l)},children:[(0,F.jsxs)(`label`,{children:[`FeltDB authority endpoint`,(0,F.jsx)(`input`,{type:`url`,value:s,onChange:e=>c(e.target.value),placeholder:`https://your-authority.example.com`})]}),(0,F.jsxs)(`label`,{children:[`API token`,(0,F.jsx)(`input`,{type:`password`,value:l,onChange:e=>u(e.target.value),placeholder:`fdb_live_…`,autoComplete:`off`})]}),(0,F.jsx)(`p`,{children:`Tokens are kept in this browser session and are never written to the project.`}),(0,F.jsx)(`button`,{className:`btn btn-primary`,type:`submit`,children:`Connect Studio`})]})]})]})}function Gn({db:e,model:t,onSearch:n}){let[r,i]=(0,g.useState)(``),[a,o]=(0,g.useState)([]),s=e=>{i(e),n&&n(e)};return(0,g.useEffect)(()=>{let n=!0;return(async()=>{let i=r.trim().toLowerCase();if(!i){o([]);return}let a=[...t?.collections.map(e=>({kind:`collection`,name:e.name,detail:`${e.fields.length} fields`}))??[],...t?.capabilities.map(e=>({kind:`capability`,name:e.name,detail:e.statements.join(` · `)}))??[],...t?.workflows.map(e=>({kind:`workflow`,name:e.name,detail:`${e.steps.length} steps`}))??[],...t?.agents.map(e=>({kind:`agent`,name:e.name,detail:e.statements.join(` · `)}))??[]].filter(e=>JSON.stringify(e).toLowerCase().includes(i)),s=e&&t?(await Promise.all(t.collections.map(async t=>(await e.collection(t.name).all()).filter(e=>JSON.stringify(e).toLowerCase().includes(i)).slice(0,3).map(e=>({kind:`object`,name:`${t.name}/${String(e.id??`record`)}`,detail:JSON.stringify(e)}))))).flat():[];n&&o([...a,...s].slice(0,12))})(),()=>{n=!1}},[e,t,r]),(0,F.jsxs)(`div`,{className:`global-search`,children:[(0,F.jsx)(`input`,{type:`text`,placeholder:`Search: documents/123, flow://, agent/name, etc.`,value:r,onChange:e=>s(e.target.value),className:`search-input global`}),r&&(0,F.jsx)(`div`,{className:`search-results`,children:(0,F.jsxs)(`div`,{className:`results-group`,children:[(0,F.jsx)(`h4`,{children:`Model & runtime`}),a.map((e,t)=>(0,F.jsxs)(`div`,{className:`search-result`,children:[(0,F.jsx)(`b`,{children:e.name}),(0,F.jsx)(`span`,{children:e.kind}),(0,F.jsx)(`small`,{children:e.detail})]},`${e.kind}-${e.name}-${t}`)),!a.length&&(0,F.jsx)(`div`,{className:`empty-message`,children:`No matches`})]})})]})}var Kn=Object.freeze({domain:`undeclared`,validation:`refresh`,invalidation:!1,reason:`the runtime does not declare a freshness capability`}),qn=class extends Error{constructor(e){super(e),this.name=`FreshnessContractViolation`}};function Jn(e,t){let n=typeof t.revision==`function`;if(e.validation===`revision`){if(!n)throw new qn(`a runtime advertising revision validation must implement revision()`);if(!e.revisionScope)throw new qn(`a runtime advertising revision validation must name the scope its revisions are comparable within`);if(e.domain===`replicated`||e.domain===`multi-process-file`)throw new qn(`the ${e.domain} domain has no serialization boundary that can make a scalar revision authoritative`);return e}if(!e.reason)throw new qn(`a runtime that cannot validate by revision must say why`);return e}async function Yn(e){return typeof e.freshness==`function`?Jn(await e.freshness(),e):Jn(Kn,e)}async function Xn(e){let t=await Yn(e);if(t.validation!==`revision`)throw new qn(`this runtime does not offer revision validation: ${t.reason}`);let n=await e.revision();if(n.scope!==t.revisionScope)throw new qn(`revision scope ${n.scope} does not match the advertised scope ${t.revisionScope}`);return n}function Zn(e,t){return e.scope===t.scope&&e.value===t.value}var Qn=class{dependencies=new Map;subscribers=new Map;recentChanges=new Map;registerDependency(e,t){this.dependencies.has(e)||this.dependencies.set(e,new Set),this.dependencies.get(e).add(t)}subscribe(e,t){this.subscribers.has(e)||this.subscribers.set(e,new Set);let n=this.subscribers.get(e);return n.add(t),()=>{n.delete(t),n.size===0&&this.subscribers.delete(e)}}async emitChange(e,t){this.recentChanges.has(e)||this.recentChanges.set(e,[]),this.recentChanges.get(e).push(t);let n=this.subscribers.get(e);n&&await Promise.all([...n].map(e=>e(t)));let r=this.dependencies.get(e);if(r)for(let e of r)await this.emitChange(e,t)}getRecentChanges(e){return this.recentChanges.get(e)||[]}clearRecentChanges(e){this.recentChanges.delete(e)}getSubscriberCount(e){return this.subscribers.get(e)?.size??0}hasDependents(e){let t=this.dependencies.get(e);return t!==void 0&&t.size>0}getDependents(e){let t=this.dependencies.get(e);return t?Array.from(t):[]}},$n=null;function er(){return $n||=new Qn,$n}var tr=1e3,nr=/^[A-Za-z0-9._-]{1,128}$/;function rr(e){if(!e||typeof e!=`object`)throw Error(`a read set is required`);let t=new Map;for(let n of e.records??[]){let e=String(n?.collection??``),r=String(n?.id??``);if(!nr.test(e)||!nr.test(r))throw Error(`invalid read ${e}:${r}`);t.set(`${e}:${r}`,{collection:e,id:r})}let n=new Map;for(let t of e.predicates??[]){let e=String(t?.collection??``);if(!nr.test(e))throw Error(`invalid predicate collection ${e}`);if(!Array.isArray(t.where)||t.where.length===0)throw Error(`a predicate over ${e} must name at least one field; a whole-collection read is not a narrow fence`);let r=t.where.map(t=>{if(typeof t?.field!=`string`||!t.field||!(`eq`in t))throw Error(`a predicate over ${e} takes { field, eq } conditions`);return{field:t.field,eq:t.eq}}).sort((e,t)=>e.field<t.field?-1:+(e.field>t.field));n.set(`${e}\u0000${JSON.stringify(r)}`,{collection:e,where:r})}if(t.size+n.size===0)throw Error(`a read set that names nothing fences nothing`);if(t.size+n.size>1e3)throw Error(`a read set may name at most ${tr} records and predicates`);return{records:[...t.entries()].sort(([e],[t])=>e<t?-1:1).map(([,e])=>e),predicates:[...n.entries()].sort(([e],[t])=>e<t?-1:1).map(([,e])=>e)}}var ir=class extends Error{transactionId;code;status;constructor(e,t,n,r,i){super(e,{cause:i}),this.name=`AtomicTransactionError`,this.transactionId=t,this.code=n,this.status=r}},ar=class extends ir{code=`PRECONDITION_FAILED`;failure;constructor(e,t,n){super(e,t),this.name=`ConditionalConflictError`,this.failure=n}};function or(e){let t=e;if(!t||typeof t!=`object`)return{conflict:!1};if(t.feltdbCode===`PRECONDITION_FAILED`)return{conflict:!0,failure:t.feltdbConflict};let n=t.feltdbCode??t.code;return t.status===409&&(n===`PRECONDITION_FAILED`||n===`CONFLICT`)?{conflict:!0,failure:t.feltdbConflict}:{conflict:!1}}function sr(e){let{ifVersion:t,expectedVersion:n,...r}=e;if(t!==void 0&&n!==void 0&&t!==n)throw Error(`precondition on ${e.collection}:${e.id} supplies ifVersion ${t} and expectedVersion ${n}; they are the same predicate`);let i=t??n;return i===void 0?{...r}:{...r,expectedVersion:i}}function cr(){let e=Math.random().toString(36).slice(2,10);return`tx_${Date.now().toString(36)}_${e}`}var lr=class{transactionId;staged=[];required=[];fenced=[];sealed=!1;constructor(e){this.transactionId=e||cr()}get operations(){return this.staged}collection(e){if(!e||!e.trim())throw Error(`collection name is required`);let t=e=>{let{ifVersion:t,expectedVersion:n,...r}=e;if(t!==void 0&&n!==void 0&&t!==n)throw Error(`${e.collection}:${e.id} supplies ifVersion ${t} and expectedVersion ${n}; they are the same predicate`);let i=t??n,a=i===void 0?{...r}:{...r,expectedVersion:i};if(this.sealed)throw Error(`this transaction has already been committed; start a new one`);if(this.staged.find(e=>e.collection===a.collection&&e.id===a.id))throw Error(`transaction already stages ${a.collection}:${a.id}; a transaction may write each record at most once`);this.staged.push(a)},n={set:(r,i,a)=>(t({collection:e,id:String(r),value:i,requireAbsent:a?.requireAbsent,ifVersion:a?.ifVersion,expectedVersion:a?.expectedVersion,expectedEpoch:a?.expectedEpoch,expectedLeaseId:a?.expectedLeaseId}),n),insert:(e,t,r)=>n.set(t,e,r),delete:(r,i)=>(t({collection:e,id:String(r),requireAbsent:i?.requireAbsent,ifVersion:i?.ifVersion,expectedVersion:i?.expectedVersion,expectedEpoch:i?.expectedEpoch,expectedLeaseId:i?.expectedLeaseId}),n)};return n}get preconditions(){return this.required}require(e){if(this.sealed)throw Error(`this transaction has already been committed; start a new one`);if(!e.collection?.trim()||!String(e.id??``).trim())throw Error(`a precondition requires a collection and an id`);let t=sr(e);if(t.requireAbsent!==!0&&t.expectedVersion===void 0&&t.expectedEpoch===void 0&&t.expectedLeaseId===void 0)throw Error(`precondition on ${e.collection}:${e.id} constrains nothing`);return this.required.push({...t,id:String(e.id)}),this}get fences(){return this.fenced}fence(e){if(this.sealed)throw Error(`this transaction has already been committed; start a new one`);if(!e||typeof e.token!=`string`||!e.token)throw Error(`a fence requires a read basis issued by db.readBasis()`);return this.fenced.push({reads:rr(e.reads),token:e.token}),this}seal(){return this.sealed=!0,{transactionId:this.transactionId,operations:[...this.staged],preconditions:[...this.required],...this.fenced.length?{fences:[...this.fenced]}:{}}}},ur=class{entries=new Map;field;stats={reads:0,writes:0,selectivity:0};constructor(e){this.field=e}add(e,t){let n=this.normalizeKey(t);this.entries.has(n)||this.entries.set(n,new Set),this.entries.get(n).add(e),this.stats.writes++}remove(e,t){let n=this.normalizeKey(t),r=this.entries.get(n);r&&(r.delete(e),r.size===0&&this.entries.delete(n)),this.stats.writes++}query(e){let t=this.normalizeKey(e);this.stats.reads++;let n=this.entries.get(t);return n?Array.from(n):[]}size(){return this.entries.size}getStats(){return{entries:this.entries.size,reads:this.stats.reads,writes:this.stats.writes,selectivity:this.entries.size>0?1/this.entries.size:0}}normalizeKey(e){return e==null?`__null__`:typeof e==`object`?JSON.stringify(e):String(e)}},dr=class{entries=[];field;stats={reads:0,writes:0,selectivity:0};constructor(e){this.field=e}add(e,t){let n=this.entries.find(e=>this.compareKeys(e.key,t)===0);n||(n={key:t,recordIds:new Set},this.entries.push(n),this.entries.sort((e,t)=>this.compareKeys(e.key,t.key))),n.recordIds.add(e),this.stats.writes++}remove(e,t){let n=this.entries.find(e=>this.compareKeys(e.key,t)===0);n&&(n.recordIds.delete(e),n.recordIds.size===0&&(this.entries=this.entries.filter(e=>e!==n))),this.stats.writes++}queryEqual(e){this.stats.reads++;let t=this.entries.find(t=>this.compareKeys(t.key,e)===0);return t?Array.from(t.recordIds):[]}queryRange(e,t,n=!0,r=!0){this.stats.reads++;let i=new Set;for(let a of this.entries){let o=this.compareKeys(a.key,e),s=this.compareKeys(a.key,t);(n?o>=0:o>0)&&(r?s<=0:s<0)&&a.recordIds.forEach(e=>i.add(e))}return Array.from(i)}size(){return this.entries.length}getStats(){return this.entries.reduce((e,t)=>e+t.recordIds.size,0),{entries:this.entries.length,reads:this.stats.reads,writes:this.stats.writes,selectivity:this.entries.length>0?1/this.entries.length:0}}compareKeys(e,t){return e==null?-1:t==null?1:e<t?-1:+(e>t)}},fr=class{tokenIndex=new Map;fields;stats={reads:0,writes:0,selectivity:0};constructor(e){this.fields=e}add(e,t){let n=this.extractText(t),r=this.tokenize(n);for(let t of r)this.tokenIndex.has(t)||this.tokenIndex.set(t,new Set),this.tokenIndex.get(t).add(e);this.stats.writes++}remove(e,t){let n=this.extractText(t),r=this.tokenize(n);for(let t of r){let n=this.tokenIndex.get(t);n&&(n.delete(e),n.size===0&&this.tokenIndex.delete(t))}this.stats.writes++}query(e){this.stats.reads++;let t=this.tokenize(e);if(t.length===0)return[];let n=this.tokenIndex.get(t[0]);if(!n)return[];n=new Set(n);for(let e=1;e<t.length;e++){let r=this.tokenIndex.get(t[e]);if(!r)return[];n=new Set([...n].filter(e=>r.has(e)))}return Array.from(n)}size(){return this.tokenIndex.size}getStats(){return{entries:this.tokenIndex.size,reads:this.stats.reads,writes:this.stats.writes,selectivity:this.tokenIndex.size>0?1/this.tokenIndex.size:0}}extractText(e){return this.fields.map(t=>{let n=e[t];return n?String(n):``}).join(` `)}tokenize(e){return e.toLowerCase().split(/\s+/).filter(e=>e.length>0)}},pr=class{indexes=new Map;config=new Map;indexStats=new Map;buildIndex(e){if(e.type===`hash`&&e.field)return new ur(e.field);if(e.type===`sorted`&&e.field)return new dr(e.field);if(e.type===`text`&&e.textFields)return new fr(e.textFields);throw Error(`Invalid index config: ${JSON.stringify(e)}`)}resetEntries(){for(let[e,t]of this.config){this.indexes.set(e,this.buildIndex(t));let n=this.indexStats.get(e);n&&(n.entries=0,n.size=0,n.lastUpdated=Date.now())}}createIndex(e){if(this.indexes.has(e.name))throw Error(`Index ${e.name} already exists`);let t=this.buildIndex(e);this.indexes.set(e.name,t),this.config.set(e.name,e),this.indexStats.set(e.name,{name:e.name,type:e.type,entries:0,size:0,lastUpdated:Date.now(),reads:0,writes:0,selectivity:0})}updateRecord(e,t,n){for(let[r,i]of this.indexes){let a=this.config.get(r);t&&(a.type===`hash`&&a.field||a.type===`sorted`&&a.field?i.remove(e,t[a.field]):a.type===`text`&&i.remove(e,t)),a.type===`hash`&&a.field||a.type===`sorted`&&a.field?i.add(e,n[a.field]):a.type===`text`&&i.add(e,n);let o=this.indexStats.get(r);o.lastUpdated=Date.now();let s=i.getStats();Object.assign(o,s)}}queryIndex(e,t){let n=this.indexes.get(e);if(!n)throw Error(`Index ${e} not found`);let r=this.config.get(e);if(r.type===`hash`)return n.query(t.value);if(r.type===`sorted`){let e=n;if(t.operator===`eq`)return e.queryEqual(t.value);if(t.operator===`range`)return e.queryRange(t.min,t.max);if(t.operator===`gte`)return e.queryRange(t.value,Number.MAX_VALUE);if(t.operator===`lte`)return e.queryRange(Number.MIN_VALUE,t.value)}else if(r.type===`text`)return n.query(t.value);return[]}listIndexes(){return Array.from(this.config.values())}getStats(e){return this.indexStats.get(e)||null}planQuery(e){let t=[];for(let n of e)for(let[e,r]of this.config)if(r.field===n||r.fields?.includes(n)){let n=this.indexStats.get(e);t.push({indexName:e,indexType:r.type,estimatedRows:Math.ceil(100/(n.selectivity||1)),cost:n.reads+n.writes,canPruneAll:r.type===`hash`,requiresPostFilter:r.type===`text`||r.type===`sorted`})}if(t.length===0)return{strategy:`full-scan`,indexes:[],estimatedRows:1e3,totalCost:1e3,explanation:`No suitable index found, using full collection scan`};t.sort((e,t)=>e.cost-t.cost);let n=t[0];return{strategy:`index-scan`,indexes:[n],estimatedRows:n.estimatedRows,totalCost:n.cost,explanation:`Using ${n.indexType} index on ${n.indexName}`}}},mr=null;async function hr(){if(mr!==null)return mr;try{let e=await x(()=>import(`./feltdb_wasm-DGGqm9GK.js`),[]);return mr=e,e}catch{return null}}var gr=class{tsBackend=null;wasmBackend=null;useWasm=!1;constructor(){this.tsBackend=new pr}async initializeWasm(){if(this.wasmBackend!==null)return;let e=await hr();if(e&&e.WasmIndexManager)try{this.wasmBackend=new e.WasmIndexManager,this.useWasm=!0}catch{this.useWasm=!1}}createIndex(e){if(this.useWasm&&this.wasmBackend)try{this.wasmBackend.create_index(JSON.stringify(e));return}catch{}this.tsBackend?.createIndex(e)}updateRecord(e,t,n){if(this.useWasm&&this.wasmBackend)try{let r=t?JSON.stringify(t):null,i=JSON.stringify(n);this.wasmBackend.update_record(e,r,i);return}catch{}this.tsBackend?.updateRecord(e,t,n)}resetEntries(){return this.useWasm&&this.wasmBackend?!1:(this.tsBackend?.resetEntries(),this.tsBackend!==null)}queryIndex(e,t){if(this.useWasm&&this.wasmBackend)try{let n=this.wasmBackend.query_index(e,t.operator,String(t.value||``));return JSON.parse(n)}catch{}return this.tsBackend?.queryIndex(e,t)||[]}queryCompoundIndex(e,t){if(this.useWasm&&this.wasmBackend)try{let n=Object.values(t).map(e=>String(e)).join(`\0`),r=this.wasmBackend.query_index(e,`eq`,n);return JSON.parse(r)}catch{}return[]}listIndexes(){if(this.useWasm&&this.wasmBackend)try{let e=this.wasmBackend.list_indexes();return JSON.parse(e)}catch{}return this.tsBackend?.listIndexes()||[]}},_r=class{db;collectionName;constructor(e,t){this.db=e,this.collectionName=t}async saveIndexConfig(e,t){let n=`__indexes__:${this.collectionName}:${e.name}`,r={config:e,version:1,createdAt:Date.now(),lastUpdated:Date.now(),entryCount:t},i=await this.db.insert(n,JSON.stringify(r));i.success||console.warn(`Failed to save index config for ${e.name}: ${i.error}`)}async loadIndexConfigs(){let e=await this.db.query(`__indexes__:${this.collectionName}`);if(!e.success||!e.data)return[];try{return JSON.parse(e.data).map(e=>e.config)}catch{return console.warn(`Failed to parse index configs for ${this.collectionName}`),[]}}async getIndexConfig(e){let t=`__indexes__:${this.collectionName}:${e}`,n=await this.db.get(t);if(!n.success||!n.data)return null;try{return JSON.parse(n.data).config}catch{return null}}async deleteIndexConfig(e){let t=`__indexes__:${this.collectionName}:${e}`;if(!this.db.delete){console.warn(`Failed to delete index config for ${e}: delete is not supported`);return}let n=this.db.delete(t),r=n instanceof Promise?await n:n;r?.success||console.warn(`Failed to delete index config for ${e}: ${r?.error}`)}async updateIndexStats(e,t){let n=`__indexes__:${this.collectionName}:${e}`,r=await this.db.get(n);if(!(!r.success||!r.data))try{let e=JSON.parse(r.data);e.lastUpdated=Date.now(),e.entryCount=t,await this.db.insert(n,JSON.stringify(e))}catch{console.warn(`Failed to update index stats for ${e}`)}}async getSnapshot(){let e=await this.loadIndexConfigs();return{collectionName:this.collectionName,indexes:e.map(e=>({config:e,version:1,createdAt:Date.now(),lastUpdated:Date.now(),entryCount:0})),timestamp:Date.now()}}};function vr(e){return`${e}-${typeof globalThis.crypto?.randomUUID==`function`?globalThis.crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}`}var yr=class e{db;name;collectionId;predicate=null;cache=[];subscribers=new Set;parent=null;parentId=null;isInitialized=!1;unsubscribeFunctions=new Set;graphUnsubscribe=null;runtimeUnsubscribe=null;indexBackend=new gr;declaredIndexes=new Map;indexStore;indexesLoaded=!1;cacheGeneration=0;indexedGeneration=-1;lastPlan=null;recordsById=null;lastRawSnapshot=null;cachedRevision=null;lastFreshness=null;constructor(e,t,n,r,i=!0){this.db=e,this.name=t,this.collectionId=`${t}-${Math.random().toString(36).substr(2,9)}`,this.predicate=n||null,this.parent=r||null,this.parentId=r?r.collectionId:null,this.indexStore=new _r(e,t),r&&er().registerDependency(r.collectionId,this.collectionId),i?this.loadPersistedIndexes():this.indexesLoaded=!0}async loadPersistedIndexes(){try{let e=await this.indexStore.loadIndexConfigs();for(let t of e)this.declaredIndexes.has(t.name)||(this.declaredIndexes.set(t.name,t),t.type!==`compound`&&this.indexBackend.createIndex(t));this.indexesLoaded=!0}catch(e){console.warn(`Failed to load persisted indexes for ${this.name}:`,e),this.indexesLoaded=!0}}async all(){return await this.refresh(),[...this.cache]}async list(){return this.all()}async find(e={},t){let n=Object.entries(e);if(t&&this.db.authority_query){let e=await this.db.authority_query({collection:this.name,where:n.map(([e,t])=>({field:e,eq:t})),orderBy:t.orderBy,limit:t.limit??100,cursor:t.cursor});return this.lastPlan={strategy:e.plan?.index?`index`:`scan`,...e.plan?.index?{indexName:e.plan.index}:{reason:`runtime reported no applicable index`},candidatesExamined:e.plan?.actual_rows_scanned??e.records.length,recordsReturned:e.records.length},e.records}if(n.length>0&&this.db.authority_query&&this.db.collection_queries_via_authority){let e=[],t,r=0,i;do{let a=await this.db.authority_query({collection:this.name,where:n.map(([e,t])=>({field:e,eq:t})),limit:100,...t?{cursor:t}:{}});e.push(...a.records),r+=a.plan?.actual_rows_scanned??a.records.length,i=a.plan?.index??i,t=a.nextCursor}while(t);return this.lastPlan={strategy:i?`index`:`scan`,...i?{indexName:i}:{reason:`server reported no applicable index`},candidatesExamined:r,recordsReturned:e.length},e}let r=await this.all();if(n.length===0)return this.lastPlan={strategy:`scan`,reason:`no query fields`,candidatesExamined:r.length,recordsReturned:r.length},r;let i=e=>n.every(([t,n])=>e[t]===n),a=this.indexFor(n);if(a){let e=this.indexCandidates(a.indexName,a.field,a.value);if(e){let t=e.filter(i);return this.lastPlan={strategy:`index`,indexName:a.indexName,field:a.field,candidatesExamined:e.length,recordsReturned:t.length},t}}let o=r.filter(i);return this.lastPlan={strategy:`scan`,reason:a?`index could not be trusted for this snapshot`:`no index covers the queried fields`,candidatesExamined:r.length,recordsReturned:o.length},o}async query(e={}){return this.find(e)}lastQueryPlan(){return this.lastPlan}indexFor(e){for(let t of this.indexBackend.listIndexes()){if(t.type!==`hash`||!t.field)continue;let n=e.find(([e])=>e===t.field);if(n)return{indexName:t.name,field:t.field,value:n[1]}}return null}indexCandidates(e,t,n){if(!this.ensureIndexReflectsCache())return null;let r;try{r=this.indexBackend.queryIndex(e,{field:t,operator:`eq`,value:n})}catch{return null}let i=[];for(let e of r){let t=this.recordsById?.get(e);if(t===void 0)return null;i.push(t)}return i}ensureIndexReflectsCache(){if(this.indexedGeneration===this.cacheGeneration)return this.recordsById!==null;if(!this.indexBackend.resetEntries())return this.recordsById=null,!1;let e=new Map;for(let t of this.cache){let n=t?.id;if(n==null)return this.recordsById=null,this.indexedGeneration=this.cacheGeneration,!1;let r=String(n);e.set(r,t),this.indexBackend.updateRecord(r,null,t)}return this.recordsById=e,this.indexedGeneration=this.cacheGeneration,!0}createIndex(e){if(this.declaredIndexes.has(e.name))throw Error(`Index ${e.name} already exists`);this.declaredIndexes.set(e.name,e),e.type!==`compound`&&this.indexBackend.createIndex(e);for(let e of this.cache){let t=e?.id||JSON.stringify(e);this.indexBackend.updateRecord(t,null,e)}this.indexStore.saveIndexConfig(e,this.cache.length)}listIndexes(){return[...this.declaredIndexes.values()]}async rebuildIndexes(){await this.db.rebuild_indexes?.();let e=this.indexBackend.listIndexes();if(e.length===0)return;let t=await this.all();for(let n of t){let t=n?.id||JSON.stringify(n);for(let r of e)this.indexBackend.updateRecord(t,null,n)}}async validateIndexes(){return this.listIndexes().length===0||(await this.all()).length,!0}async get(e){let t=`${this.name}:${e}`,n=await this.db.get(t);if(!n.success)throw Error(n.error||`Failed to read record ${e}`);return n.data?JSON.parse(n.data):null}where(t){return new e(this.db,this.name,e=>(!this.predicate||this.predicate(e))&&t(e),this.parent||this)}async insert(e,t){let n=t??`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,r=`${this.name}:${n}`,i=typeof e==`object`&&e?{...e,id:n,__version:1}:e,a=await this.db.insert(r,JSON.stringify(i));if(!a.success)throw Error(`Insert failed: ${a.error}`);this.indexBackend.updateRecord(String(n),null,i);let o={type:`insert`,key:r,value:i,timestamp:Date.now()};return await er().emitChange(this.name,o),String(n)}async put(e,t){return this.insert(e,t)}async update(e,t){let n=await this.get(e);if(!n)throw Error(`Record ${e} not found`);let r=(n.__version||1)+1,i={...n,...t,__version:r},a=`${this.name}:${e}`,o=await(this.db.update?this.db.update(a,JSON.stringify(i)):this.db.insert(a,JSON.stringify(i)));if(!o.success)throw Error(`Update failed: ${o.error}`);this.indexBackend.updateRecord(String(e),n,i);let s={type:`update`,key:a,value:i,timestamp:Date.now()};await er().emitChange(this.name,s)}async updateIfVersion(e,t,n,r,i,a,o){let s=o??await this.get(e);if(!s)throw Error(`Record ${e} not found`);let c={...n};delete c.__version;let l={...s,...c},u=`${this.name}:${e}`,d=this.db.cas?await this.db.cas({key:u,expectedVersion:t,expectedEpoch:r,expectedLeaseId:i,rejectIfDiverged:a,value:JSON.stringify(l)}):await this.updateIfVersionThroughTransaction(u,{expectedVersion:t,expectedEpoch:r,expectedLeaseId:i,rejectIfDiverged:a,value:l});if(!d.updated)return{updated:!1,currentVersion:d.currentVersion,conflictCode:d.conflictCode};let f=d.item?d.item:{...l,__version:d.currentVersion};this.indexBackend.updateRecord(String(e),s,f);let p={type:`update`,key:u,value:f,timestamp:Date.now()};return await er().emitChange(this.name,p),{updated:!0,item:f}}async delete(e){let t=`${this.name}:${e}`;if(!this.db.delete)throw Error(`Delete is not supported by this FeltDB runtime`);let n=await this.db.delete(t);if(!n.success)throw Error(`Delete failed: ${n.error}`);let r=await this.get(e);r&&this.indexBackend.updateRecord(String(e),r,{});let i={type:`delete`,key:t,value:null,timestamp:Date.now()};await er().emitChange(this.name,i)}async count(){return(await this.all()).length}async exists(e){return await this.get(e)!==null}addressOf(e){let t=e.indexOf(`:`);return{collection:e.slice(0,t),id:e.slice(t+1)}}async putIfAbsentThroughTransaction(e,t){let n=this.db.commit_transaction;if(!n)throw Error(`putIfAbsent is not supported by this FeltDB runtime. It provides neither durable atomic conditional creation nor an atomic transaction to carry the condition, and FeltDB will not emulate one with a read followed by a write.`);let{collection:r,id:i}=this.addressOf(e);try{await n.call(this.db,{transactionId:vr(`put-if-absent`),operations:[{collection:r,id:i,value:t,requireAbsent:!0}]})}catch(t){if(!or(t).conflict)throw t;let n=await this.db.get(e);if(!n.success)throw Error(n.error||`could not read the record that won ${e}`);if(!n.data)throw Error(`${e} was created and then removed while resolving a conditional create`);return{inserted:!1,value:n.data}}return{inserted:!0,value:JSON.stringify({...t,__version:1})}}async updateIfVersionThroughTransaction(e,t){let n=this.db.commit_transaction;if(!n)throw Error(`updateIfVersion is not supported by this FeltDB runtime. It provides neither atomic version-checked update nor an atomic transaction to carry the condition, and FeltDB will not emulate one with a read followed by a write.`);if(t.rejectIfDiverged)throw Error(`rejectIfDiverged is a replication predicate this runtime's transaction contract cannot express, so it is refused rather than silently dropped.`);let{collection:r,id:i}=this.addressOf(e),a={...t.value};delete a.__version;try{await n.call(this.db,{transactionId:vr(`update-if-version`),operations:[{collection:r,id:i,value:a,expectedVersion:t.expectedVersion,expectedEpoch:t.expectedEpoch,expectedLeaseId:t.expectedLeaseId}]})}catch(t){let n=or(t);if(!n.conflict)throw t;let r=n.failure,i=r?.predicate===`version`?`VERSION_CONFLICT`:r?.predicate===`epoch`?`AUTHORITY_CONFLICT`:r?.predicate===`lease`?`LEASE_CONFLICT`:r?.predicate===`missing`?`RECORD_MISSING`:void 0;if(r?.predicate===`version`&&typeof r.actual==`number`)return{updated:!1,currentVersion:r.actual,conflictCode:i};let a=await this.db.get(e),o=a.success&&a.data?JSON.parse(a.data):void 0;return{updated:!1,currentVersion:typeof o?.__version==`number`?o.__version:0,currentEpoch:o?.authority?.epoch,conflictCode:i}}let o=t.expectedVersion+1;return{updated:!0,currentVersion:o,currentEpoch:t.expectedEpoch,item:{...a,id:i,__version:o}}}async putIfAbsent(e,t){let n=`${this.name}:${e}`,r=typeof t==`object`&&t?{...t,id:e,__version:1}:t,i=JSON.stringify(r),a=this.db.putIfAbsent?await this.db.putIfAbsent(n,i):await this.putIfAbsentThroughTransaction(n,r);if(a.inserted){let e={type:`insert`,key:n,value:r,timestamp:Date.now()};await er().emitChange(this.name,e)}return{inserted:a.inserted,value:JSON.parse(a.value)}}subscribe(e,t){if(this.subscribers.add(e),this.isInitialized||this.refresh().catch(e=>console.error(`Failed to initialize collection:`,e)),!this.graphUnsubscribe){let e=null,t=()=>e||(e=(async()=>{await this.refresh();for(let e of this.subscribers)e([...this.cache])})().finally(()=>{e=null}),e),n=er();this.graphUnsubscribe=n.subscribe(this.name,t),this.db.subscribe_changes&&(this.runtimeUnsubscribe=this.db.subscribe_changes(e=>{e===this.name&&t()},this.name))}return()=>{if(this.subscribers.delete(e),this.subscribers.size===0){this.graphUnsubscribe?.(),this.runtimeUnsubscribe?.(),this.graphUnsubscribe=null,this.runtimeUnsubscribe=null;for(let e of this.unsubscribeFunctions)e();this.unsubscribeFunctions.clear()}}}close(){this.graphUnsubscribe?.(),this.runtimeUnsubscribe?.(),this.graphUnsubscribe=null,this.runtimeUnsubscribe=null,this.subscribers.clear();for(let e of this.unsubscribeFunctions)e();this.unsubscribeFunctions.clear()}freshness(){return Yn(this.db)}lastFreshnessCheck(){return this.lastFreshness}async currentRevision(){try{return{revision:await Xn(this.db)}}catch(e){return{reason:e instanceof Error?e.message:String(e)}}}async refresh(){try{let e=await this.currentRevision();if(`revision`in e){if(this.isInitialized&&this.cachedRevision&&Zn(this.cachedRevision,e.revision)){this.lastFreshness={validation:`revision`,servedFromCache:!0,revision:e.revision};return}}else this.cachedRevision=null;let t=await this.db.query(this.name);if(this.lastFreshness=`revision`in e?{validation:`revision`,servedFromCache:!1,revision:e.revision}:{validation:`refresh`,servedFromCache:!1,reason:e.reason},t.success&&t.data){if(this.cachedRevision=`revision`in e?e.revision:null,this.isInitialized&&t.data===this.lastRawSnapshot)return;try{let e=JSON.parse(t.data);this.predicate&&(e=e.filter(e=>{try{return this.predicate(e)}catch{return!1}})),this.cache=e,this.cacheGeneration+=1,this.lastRawSnapshot=t.data,this.isInitialized=!0}catch(e){console.error(`Failed to parse query results:`,e)}}else t.success||console.error(`Query failed:`,t.error)}catch(e){console.error(`Refresh error:`,e)}}},br=Symbol(`FELTDB_NO_CHANGE`),xr=class{id;jsDb;cellCollection;replicaCollection;failureObservationCollection;mutationQueue=[];isLocked=!1;changeHandlers=[];isReplica=!1;constructor(e,t){this.id=t,this.jsDb=e,this.cellCollection=new yr(e,`_cells`,void 0,void 0,!1),this.replicaCollection=new yr(e,`_replicas`,void 0,void 0,!1),this.failureObservationCollection=new yr(e,`_failure_observations`,void 0,void 0,!1)}setReplica(e){this.isReplica=e}isReplicaCell(){return this.isReplica}async applyReplication(e){return this.acquireLock(async()=>{let t=this.encodeKey();for(;;){let n=await this.cellCollection.get(t),r=n?this.snapshotFromState(n):null;if(r&&r.version>e.version)throw Error(`REPLICATION_CONFLICT: cannot apply version ${e.version}, current is ${r.version}`);if(r&&r.version===e.version){if(JSON.stringify(r.value)!==JSON.stringify(e.value)){let n=`version ${e.version} has divergent state`;throw await this.replicaCollection.insert({cellId:this.id,version:r.version,value:r.value,updatedAt:r.updatedAt,authority:r.authority,placement:r.placement,lease:r.lease,divergent:!0,conflictReason:n},t),Error(`REPLICATION_CONFLICT: ${n}`)}await this.clearDivergenceMarker();return}let i={id:e.cellId,version:e.version,value:e.value,updatedAt:e.updatedAt,authority:{owner:e.authority.owner,epoch:e.authority.epoch,lifecycle:e.authority.lifecycle},placement:{nodeId:e.placement.nodeId},lease:e.lease};if(!r)await this.cellCollection.insert(i,t);else{let e=n?.__version??r.version;if(!(await this.cellCollection.updateIfVersion(t,e,i,r.authority.epoch)).updated)continue}await this.clearDivergenceMarker();return}})}async clearDivergenceMarker(){try{await this.replicaCollection.delete(this.encodeKey())}catch(e){if(e instanceof Error&&/^Delete failed: record(?: .+)? not found$/i.test(e.message))return;throw e}}encodeKey(){return`${this.hashId(this.id)}`}hashId(e){let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t=(t<<5)-t+r,t&=t}return Math.abs(t).toString(16)}async get(){let e=this.encodeKey(),t=await this.cellCollection.get(e);return t?this.snapshotFromState(t):null}async set(e,t){return this.acquireLock(async()=>{if(this.isReplica)throw Error(`REPLICA_READ_ONLY: Cell ${this.id} is a read-only replica`);let n=await this.getUnlocked();if(n?.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);let r=n?.authority.epoch??0;if(t?.authorityEpoch!==void 0&&n&&t.authorityEpoch!==r)throw Error(`AUTHORITY_CONFLICT: expected epoch ${r}, got ${t.authorityEpoch}`);if(t?.leaseId!==void 0){if(!n?.lease)throw Error(`LEASE_INVALID: no active lease`);if(n.lease.leaseId!==t.leaseId)throw Error(`LEASE_INVALID: lease ID mismatch`);if(n.lease.expiresAt<=Date.now())throw Error(`LEASE_EXPIRED: lease has expired`);if(n.lease.epoch!==r)throw Error(`LEASE_INVALID: lease epoch does not match authority epoch`)}let i=n?.version??0,a=n?.authority??{owner:null,epoch:0,lifecycle:`active`},o=n?.placement??{nodeId:null},s=n?.lease??null,c={id:this.id,version:i+1,value:e,updatedAt:new Date().toISOString(),authority:a,placement:o,lease:s},l=this.encodeKey();if(i===0)await this.cellCollection.insert(c,l);else if(!(await this.cellCollection.updateIfVersion(l,i,c,r,t?.leaseId)).updated)throw Error(`Cell ${this.id} version conflict`);return this.emitChange({cellId:this.id,version:c.version,value:e,timestamp:c.updatedAt,epoch:c.authority.epoch}),this.snapshotFromState(c)})}async update(e,t){return this.acquireLock(async()=>{if(this.isReplica)throw Error(`REPLICA_READ_ONLY: Cell ${this.id} is a read-only replica`);let n=await this.getUnlocked();if(n?.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);let r=n?.authority.epoch??0;if(t?.authorityEpoch!==void 0&&n&&t.authorityEpoch!==r)throw Error(`AUTHORITY_CONFLICT: expected epoch ${r}, got ${t.authorityEpoch}`);if(t?.leaseId!==void 0){if(!n?.lease)throw Error(`LEASE_INVALID: no active lease`);if(n.lease.leaseId!==t.leaseId)throw Error(`LEASE_INVALID: lease ID mismatch`);if(n.lease.expiresAt<=Date.now())throw Error(`LEASE_EXPIRED: lease has expired`);if(n.lease.epoch!==r)throw Error(`LEASE_INVALID: lease epoch does not match authority epoch`)}let i=n?.value??null,a=n?.version??0,o=e(i);if(o===br){if(n)return this.snapshotFromState(n);throw Error(`Cell ${this.id} update returned NO_CHANGE but cell does not exist`)}let s=n?.authority??{owner:null,epoch:0,lifecycle:`active`},c=n?.placement??{nodeId:null},l=n?.lease??null,u={id:this.id,version:a+1,value:o,updatedAt:new Date().toISOString(),authority:s,placement:c,lease:l},d=this.encodeKey();if(a===0)await this.cellCollection.insert(u,d);else if(!(await this.cellCollection.updateIfVersion(d,a,u,r,t?.leaseId)).updated)throw Error(`Cell ${this.id} conflict during update`);return this.emitChange({cellId:this.id,version:u.version,value:o,timestamp:u.updatedAt,epoch:u.authority.epoch}),this.snapshotFromState(u)})}async transact(e){return this.acquireLock(async()=>e({get:()=>this.getUnlocked(),set:(e,t)=>this.setUnlocked(e,t),update:(e,t)=>this.updateUnlocked(e,t)}))}async transitionAuthority(e){return this.acquireLock(async()=>{if(this.isReplica)throw Error(`REPLICA_READ_ONLY: Cell ${this.id} is a read-only replica`);let t=await this.getUnlocked();if(!t)throw Error(`Cell ${this.id} does not exist`);if(t.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);if(t.authority.epoch!==e.expectedEpoch)throw Error(`AUTHORITY_CONFLICT: expected epoch ${e.expectedEpoch}, got ${t.authority.epoch}`);e.lifecycle!==void 0&&this.validateLifecycleTransition(t.authority.lifecycle,e.lifecycle);let n={owner:e.owner===void 0?t.authority.owner:e.owner,epoch:t.authority.epoch+1,lifecycle:e.lifecycle===void 0?t.authority.lifecycle:e.lifecycle},r={id:this.id,version:t.version+1,value:t.value,updatedAt:new Date().toISOString(),authority:n,placement:t.placement,lease:null},i=this.encodeKey();if(!(await this.cellCollection.updateIfVersion(i,t.version,r,t.authority.epoch)).updated)throw Error(`AUTHORITY_CONFLICT: epoch changed during transition`);return this.emitChange({cellId:this.id,version:r.version,value:t.value,timestamp:r.updatedAt,epoch:r.authority.epoch}),this.snapshotFromState(r)})}async delegate(e){return this.acquireLock(async()=>{if(this.isReplica)throw Error(`REPLICA_READ_ONLY: Cell ${this.id} is a read-only replica`);let t=await this.getUnlocked();if(!t)throw Error(`Cell ${this.id} does not exist`);if(t.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);if(t.authority.epoch!==e.expectedEpoch)throw Error(`AUTHORITY_CONFLICT: expected epoch ${e.expectedEpoch}, got ${t.authority.epoch}`);if(t.authority.owner!==e.from)throw Error(`AUTHORITY_CONFLICT: expected owner ${e.from}, got ${t.authority.owner}`);let n={owner:e.to,epoch:t.authority.epoch+1,lifecycle:t.authority.lifecycle},r={id:this.id,version:t.version+1,value:t.value,updatedAt:new Date().toISOString(),authority:n,placement:t.placement,lease:null},i=this.encodeKey();if(!(await this.cellCollection.updateIfVersion(i,t.version,r,t.authority.epoch)).updated)throw Error(`AUTHORITY_CONFLICT: authority changed during delegation`);return this.emitChange({cellId:this.id,version:r.version,value:t.value,timestamp:r.updatedAt,epoch:r.authority.epoch}),this.snapshotFromState(r)})}async updatePlacement(e){return this.acquireLock(async()=>{if(this.isReplica)throw Error(`REPLICA_READ_ONLY: Cell ${this.id} is a read-only replica`);let t=await this.getUnlocked();if(!t)throw Error(`Cell ${this.id} does not exist`);if(t.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);let n=t.authority.epoch,r={nodeId:e.nodeId},i={id:this.id,version:t.version+1,value:t.value,updatedAt:new Date().toISOString(),authority:t.authority,placement:r,lease:t.lease},a=this.encodeKey();if(!(await this.cellCollection.updateIfVersion(a,t.version,i,n)).updated)throw Error(`Cell ${this.id} conflict during placement update`);return this.emitChange({cellId:this.id,version:i.version,value:t.value,timestamp:i.updatedAt,epoch:i.authority.epoch}),this.snapshotFromState(i)})}async acquireLease(e){return this.acquireLock(async()=>{if(this.isReplica)throw Error(`REPLICA_READ_ONLY: Cell ${this.id} is a read-only replica`);let t=await this.getUnlocked();if(!t)throw Error(`Cell ${this.id} does not exist`);if(t.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);if(t.authority.lifecycle===`suspended`)throw Error(`Cell ${this.id} is suspended`);if(t.lease&&t.lease.expiresAt>Date.now())throw Error(`LEASE_CONFLICT: lease already held by ${t.lease.holder}`);let n=t.authority.epoch,r=`${this.id}:${Date.now()}:${Math.random().toString(36).slice(2)}`,i={holder:e.holder,leaseId:r,epoch:n,expiresAt:Date.now()+e.durationMs},a={id:this.id,version:t.version+1,value:t.value,updatedAt:new Date().toISOString(),authority:t.authority,placement:t.placement,lease:i},o=this.encodeKey();if(!(await this.cellCollection.updateIfVersion(o,t.version,a,n)).updated)throw Error(`Cell ${this.id} conflict during lease acquisition`);return this.emitChange({cellId:this.id,version:a.version,value:t.value,timestamp:a.updatedAt,epoch:a.authority.epoch}),this.snapshotFromState(a)})}async renewLease(e){return this.acquireLock(async()=>{if(this.isReplica)throw Error(`REPLICA_READ_ONLY: Cell ${this.id} is a read-only replica`);let t=await this.getUnlocked();if(!t)throw Error(`Cell ${this.id} does not exist`);if(!t.lease)throw Error(`Cell ${this.id} has no active lease`);if(t.lease.leaseId!==e.leaseId)throw Error(`LEASE_CONFLICT: lease ID mismatch`);if(t.lease.expiresAt<=Date.now())throw Error(`LEASE_EXPIRED: lease has expired`);if(t.lease.epoch!==t.authority.epoch)throw Error(`AUTHORITY_CONFLICT: authority epoch changed since lease acquisition`);let n=t.authority.epoch,r={holder:t.lease.holder,leaseId:t.lease.leaseId,epoch:t.lease.epoch,expiresAt:Date.now()+e.durationMs},i={id:this.id,version:t.version+1,value:t.value,updatedAt:new Date().toISOString(),authority:t.authority,placement:t.placement,lease:r},a=this.encodeKey();if(!(await this.cellCollection.updateIfVersion(a,t.version,i,n)).updated)throw Error(`Cell ${this.id} conflict during lease renewal`);return this.emitChange({cellId:this.id,version:i.version,value:t.value,timestamp:i.updatedAt,epoch:i.authority.epoch}),this.snapshotFromState(i)})}async releaseLease(e){return this.acquireLock(async()=>{if(this.isReplica)throw Error(`REPLICA_READ_ONLY: Cell ${this.id} is a read-only replica`);let t=await this.getUnlocked();if(!t)throw Error(`Cell ${this.id} does not exist`);if(!t.lease)throw Error(`Cell ${this.id} has no active lease`);if(t.lease.leaseId!==e.leaseId)throw Error(`LEASE_CONFLICT: lease ID mismatch`);let n=t.authority.epoch,r={id:this.id,version:t.version+1,value:t.value,updatedAt:new Date().toISOString(),authority:t.authority,placement:t.placement,lease:null},i=this.encodeKey();if(!(await this.cellCollection.updateIfVersion(i,t.version,r,n)).updated)throw Error(`Cell ${this.id} conflict during lease release`);return this.emitChange({cellId:this.id,version:r.version,value:t.value,timestamp:r.updatedAt,epoch:r.authority.epoch}),this.snapshotFromState(r)})}async promote(e){return this.acquireLock(async()=>{let t=await this.getUnlocked();if(!t)throw Error(`Cell ${this.id} does not exist`);return this.promoteSnapshot(t,e)})}async promoteSnapshot(e,t){if(e.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);if(e.version!==t.expectedVersion)throw Error(`PROMOTION_CONFLICT: expected version ${t.expectedVersion}, got ${e.version}`);if(e.authority.epoch!==t.expectedEpoch)throw Error(`PROMOTION_CONFLICT: expected epoch ${t.expectedEpoch}, got ${e.authority.epoch}`);let n={owner:t.newOwner,epoch:e.authority.epoch+1,lifecycle:e.authority.lifecycle},r={nodeId:t.newNodeId===void 0?e.placement.nodeId:t.newNodeId},i={id:this.id,version:e.version+1,value:e.value,updatedAt:new Date().toISOString(),authority:n,placement:r,lease:null},a=this.encodeKey(),o=e.lease&&e.lease.expiresAt>Date.now()?e.lease.leaseId:void 0,s=await this.cellCollection.updateIfVersion(a,e.__version??e.version,i,e.authority.epoch,o,!0,e);if(!s.updated)throw s.conflictCode===`REPLICATION_CONFLICT`?Error(`REPLICATION_CONFLICT: divergent replica cannot be promoted`):Error(`PROMOTION_CONFLICT: cell state changed during promotion`);return this.emitChange({cellId:this.id,version:i.version,value:e.value,timestamp:i.updatedAt,epoch:i.authority.epoch}),this.snapshotFromState(i)}async observeHealth(e){let t=`observation_${this.id}_${e.nodeId}`,n=await this.failureObservationCollection.get(t);if(!(n&&n.observedAt>e.observedAt)){if(n){let r=n.__version??1;if(!(await this.failureObservationCollection.updateIfVersion(t,r,e,0)).updated)return}else await this.failureObservationCollection.insert(e,t)}}async evaluateFailure(e){let t=`observation_${this.id}_${e.nodeId}`,n=await this.failureObservationCollection.get(t);if(!n)return{status:`healthy`,authorityEpoch:e.nodeId===(await this.getUnlocked())?.authority.owner?(await this.getUnlocked())?.authority.epoch??0:0,nodeId:e.nodeId};let r=await this.getUnlocked();if(r&&n.authorityEpoch<r.authority.epoch)return{status:`healthy`,authorityEpoch:r.authority.epoch,nodeId:e.nodeId};let i=e.now-n.lastSeenAt,a;return a=i<e.suspectAfterMs?`healthy`:i<e.failedAfterMs?`suspect`:`failed`,{status:a,authorityEpoch:n.authorityEpoch,nodeId:e.nodeId,ageMs:i}}async attemptAutomaticFailover(e){if(!this.isReplica)return{attempted:!1,promoted:!1,reason:`Not a replica`,diagnostics:{isReplica:!1,eligibilityChecksPassed:!1,promotionAttempted:!1,promotionSucceeded:!1}};let t=e.replicaSnapshot??await this.getUnlocked();if(!t)return{attempted:!1,promoted:!1,reason:`Replica state not found`,diagnostics:{isReplica:!0,eligibilityChecksPassed:!1,promotionAttempted:!1,promotionSucceeded:!1}};let n=`observation_${this.id}_${e.failureEvaluationOptions.nodeId}`,r=e.failureObservation??await this.failureObservationCollection.get(n),i=this.evaluateFailureSnapshot(e.failureEvaluationOptions,r,t);if(i.status!==`failed`)return{attempted:!1,promoted:!1,reason:`Current authority not failed (status: ${i.status})`,diagnostics:{isReplica:!0,failureStatus:i.status,eligibilityChecksPassed:!1,promotionAttempted:!1,promotionSucceeded:!1}};if(t.authority.lifecycle===`retired`)return{attempted:!1,promoted:!1,reason:`Cell is retired`,diagnostics:{isReplica:!0,failureStatus:i.status,eligibilityChecksPassed:!1,promotionAttempted:!1,promotionSucceeded:!1}};if(t.authority.epoch!==i.authorityEpoch)return{attempted:!1,promoted:!1,reason:`Replica authority epoch mismatch: replica=${t.authority.epoch}, observed=${i.authorityEpoch}`,diagnostics:{isReplica:!0,failureStatus:i.status,eligibilityChecksPassed:!1,promotionAttempted:!1,promotionSucceeded:!1}};try{return await this.promoteSnapshot(t,{expectedVersion:t.version,expectedEpoch:t.authority.epoch,newOwner:e.newOwner,newNodeId:t.placement.nodeId}),{attempted:!0,promoted:!0,diagnostics:{isReplica:!0,failureStatus:i.status,eligibilityChecksPassed:!0,promotionAttempted:!0,promotionSucceeded:!0}}}catch(e){return{attempted:!0,promoted:!1,reason:`Promotion failed: ${e instanceof Error?e.message:String(e)}`,diagnostics:{isReplica:!0,failureStatus:i.status,eligibilityChecksPassed:!0,promotionAttempted:!0,promotionSucceeded:!1}}}}evaluateFailureSnapshot(e,t,n){if(!t)return{status:`healthy`,authorityEpoch:e.nodeId===n.authority.owner?n.authority.epoch:0,nodeId:e.nodeId};if(t.authorityEpoch<n.authority.epoch)return{status:`healthy`,authorityEpoch:n.authority.epoch,nodeId:e.nodeId};let r=e.now-t.lastSeenAt;return{status:r<e.suspectAfterMs?`healthy`:r<e.failedAfterMs?`suspect`:`failed`,authorityEpoch:t.authorityEpoch,nodeId:e.nodeId,ageMs:r}}validateLifecycleTransition(e,t){if(!{active:[`suspended`,`retired`],suspended:[`active`,`retired`],retired:[]}[e].includes(t))throw Error(`Invalid lifecycle transition: ${e} → ${t}`)}async getUnlocked(){let e=this.encodeKey(),t=await this.cellCollection.get(e);return t?this.snapshotFromState(t):null}async setUnlocked(e,t){let n=await this.getUnlocked();if(n?.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);let r=n?.authority.epoch??0;if(t?.authorityEpoch!==void 0&&n&&t.authorityEpoch!==r)throw Error(`AUTHORITY_CONFLICT: expected epoch ${r}, got ${t.authorityEpoch}`);if(t?.leaseId!==void 0){if(!n?.lease)throw Error(`LEASE_INVALID: no active lease`);if(n.lease.leaseId!==t.leaseId)throw Error(`LEASE_INVALID: lease ID mismatch`);if(n.lease.expiresAt<=Date.now())throw Error(`LEASE_EXPIRED: lease has expired`);if(n.lease.epoch!==r)throw Error(`LEASE_INVALID: lease epoch does not match authority epoch`)}let i=n?.version??0,a=n?.authority??{owner:null,epoch:0,lifecycle:`active`},o=n?.placement??{nodeId:null},s=n?.lease??null,c={id:this.id,version:i+1,value:e,updatedAt:new Date().toISOString(),authority:a,placement:o,lease:s},l=this.encodeKey();if(i===0)await this.cellCollection.insert(c,l);else if(!(await this.cellCollection.updateIfVersion(l,i,c,r)).updated)throw Error(`Cell ${this.id} version conflict`);return this.emitChange({cellId:this.id,version:c.version,value:e,timestamp:c.updatedAt,epoch:c.authority.epoch}),this.snapshotFromState(c)}async updateUnlocked(e,t){let n=await this.getUnlocked();if(n?.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);let r=n?.authority.epoch??0;if(t?.authorityEpoch!==void 0&&n&&t.authorityEpoch!==r)throw Error(`AUTHORITY_CONFLICT: expected epoch ${r}, got ${t.authorityEpoch}`);if(t?.leaseId!==void 0){if(!n?.lease)throw Error(`LEASE_INVALID: no active lease`);if(n.lease.leaseId!==t.leaseId)throw Error(`LEASE_INVALID: lease ID mismatch`);if(n.lease.expiresAt<=Date.now())throw Error(`LEASE_EXPIRED: lease has expired`);if(n.lease.epoch!==r)throw Error(`LEASE_INVALID: lease epoch does not match authority epoch`)}let i=n?.value??null,a=n?.version??0,o=e(i);if(o===br){if(n)return this.snapshotFromState(n);throw Error(`Cell ${this.id} update returned NO_CHANGE but cell does not exist`)}let s=n?.authority??{owner:null,epoch:0,lifecycle:`active`},c=n?.placement??{nodeId:null},l=n?.lease??null,u={id:this.id,version:a+1,value:o,updatedAt:new Date().toISOString(),authority:s,placement:c,lease:l},d=this.encodeKey();if(a===0)await this.cellCollection.insert(u,d);else if(!(await this.cellCollection.updateIfVersion(d,a,u,r)).updated)throw Error(`Cell ${this.id} conflict during update`);return this.emitChange({cellId:this.id,version:u.version,value:o,timestamp:u.updatedAt,epoch:u.authority.epoch}),this.snapshotFromState(u)}snapshotFromState(e){let t={id:this.id,version:e.version,value:e.value,updatedAt:e.updatedAt,authority:e.authority,placement:e.placement,lease:e.lease},n=e.__version;return n!==void 0&&Object.defineProperty(t,"__version",{value:n,enumerable:!1}),t}on(e,t){e===`change`&&this.changeHandlers.push(t)}off(e,t){if(e===`change`){let e=this.changeHandlers.indexOf(t);e>=0&&this.changeHandlers.splice(e,1)}}emitChange(e){for(let t of this.changeHandlers)try{t(e)}catch(e){console.error(`Error in cell change handler: ${e}`)}}acquireLock(e){return new Promise((t,n)=>{this.mutationQueue.push(async()=>{try{t(await e())}catch(e){n(e)}}),this.isLocked||this.processQueue()})}async processQueue(){if(this.isLocked||this.mutationQueue.length===0)return;this.isLocked=!0;let e=this.mutationQueue.shift();if(e)try{await e()}catch{}finally{this.isLocked=!1,this.processQueue()}}},I;(function(e){e.Created=`Created`,e.Planning=`Planning`,e.Observing=`Observing`,e.Deciding=`Deciding`,e.Acting=`Acting`,e.Waiting=`Waiting`,e.Completed=`Completed`,e.Failed=`Failed`,e.Cancelled=`Cancelled`,e.Blocked=`Blocked`})(I||={});function Sr(e,t){return{name:e,version:t,toString(){return`flow://agent/${this.name}@${this.version}`}}}function Cr(e){return`exec-${e}-${Date.now()}-${Math.random().toString(36).slice(2,11)}`}var wr=class{agents=new Map;register(e,t){let n=e.toString(),r={agentRef:e,definition:t,providers:[],compatibleStateVersions:[],registeredAt:Date.now(),updatedAt:Date.now(),active:!0};this.agents.set(n,r)}unregister(e){let t=e.toString();this.agents.delete(t)}get(e){let t=e.toString();return this.agents.get(t)}getByName(e){let t;for(let n of this.agents.values())n.definition.name===e&&(!t||n.agentRef.version>t.agentRef.version)&&(t=n);return t}getAll(){return Array.from(this.agents.values())}addProvider(e,t){let n=e.toString(),r=this.agents.get(n);if(!r)throw Error(`Agent not registered: ${n}`);r.providers=r.providers.filter(e=>e.peerId!==t.peerId),r.providers.push(t),r.updatedAt=Date.now()}removeProvider(e,t){let n=e.toString(),r=this.agents.get(n);if(!r)throw Error(`Agent not registered: ${n}`);r.providers=r.providers.filter(e=>e.peerId!==t),r.updatedAt=Date.now()}getAvailableProviders(e){let t=this.get(e);return t?t.providers.filter(e=>e.available):[]}findByCapability(e){let t=[];for(let n of this.agents.values())n.definition.capabilities.includes(e)&&t.push(n);return t}updateAvailability(e,t,n){let r=this.get(e);if(!r)throw Error(`Agent not registered: ${e.toString()}`);let i=r.providers.find(e=>e.peerId===t);i&&(i.available=n,i.lastHeartbeat=Date.now(),r.updatedAt=Date.now())}clear(){this.agents.clear()}},Tr=class{ownership=new Map;locks=new Map;claim(e,t,n){let r=this.ownership.get(e);if(r===t)return!0;if(r)return!1;let i=this.locks.get(e);return i&&i.expiresAt>Date.now()?!1:(this.ownership.set(e,t),this.locks.set(e,{peerId:t,expiresAt:Date.now()+n}),!0)}release(e,t){this.ownership.get(e)===t&&(this.ownership.delete(e),this.locks.delete(e))}getOwner(e){return this.ownership.get(e)}isValid(e){let t=this.locks.get(e);return t?t.expiresAt>Date.now():!1}renew(e,t,n){return this.ownership.get(e)===t&&(this.locks.set(e,{peerId:t,expiresAt:Date.now()+n}),!0)}},Er=class{config;registry;handlers=new Map;executions=new Map;ownership;triggers=new Map;constructor(e,t){this.registry=e,this.config=t,this.ownership=new Tr}registerHandler(e,t){this.handlers.set(e,t)}async createExecution(e,t,n,r){let i=Cr(t.name),a={executionId:i,agentRef:t,status:I.Created,goal:n,inputs:r,stateVersion:0,observationIds:[],decisionIds:[],actionIds:[],attempt:1,createdMs:Date.now()};return this.executions.set(i,a),a}async start(e,t){if(!this.ownership.claim(e.executionId,t,3e4))throw Error(`Failed to claim ownership of execution ${e.executionId}`);try{return e.status=I.Planning,e.ownedBy=t,e.startedMs=Date.now(),{execution:e,status:I.Planning,resultRef:void 0}}catch(t){return e.status=I.Failed,e.error=String(t),e.completedMs=Date.now(),{execution:e,status:I.Failed,error:String(t)}}}async resume(e,t){if(!this.ownership.claim(e.executionId,t,3e4)&&this.ownership.getOwner(e.executionId)!==t)throw Error(`Cannot resume execution ${e.executionId}: owned by ${this.ownership.getOwner(e.executionId)}`);return e.ownedBy=t,e.status=I.Observing,{execution:e,status:I.Observing}}async transition(e,t){if(!({[I.Created]:[I.Planning],[I.Planning]:[I.Observing],[I.Observing]:[I.Deciding,I.Waiting],[I.Deciding]:[I.Acting],[I.Acting]:[I.Observing,I.Waiting,I.Completed],[I.Waiting]:[I.Observing,I.Blocked],[I.Completed]:[],[I.Failed]:[],[I.Cancelled]:[],[I.Blocked]:[I.Observing]}[e.status]||[]).includes(t))throw Error(`Invalid transition from ${e.status} to ${t}`);e.status=t}async complete(e,t){e.status=I.Completed,e.resultRef=t,e.completedMs=Date.now(),e.ownedBy&&this.ownership.release(e.executionId,e.ownedBy)}async fail(e,t){e.status=I.Failed,e.error=t,e.completedMs=Date.now(),e.ownedBy&&this.ownership.release(e.executionId,e.ownedBy)}getExecution(e){return this.executions.get(e)}getOwner(e){return this.ownership.getOwner(e)}registerTriggers(e,t){this.triggers.set(e,t)}getTriggers(e){return this.triggers.get(e)||[]}},Dr=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function Or(e){let t=new TextEncoder().encode(e),n=t.length*8,r=new Uint8Array(t.length+9+63>>6<<6);r.set(t),r[t.length]=128;let i=new DataView(r.buffer);i.setUint32(r.length-8,Math.floor(n/4294967296)),i.setUint32(r.length-4,n>>>0);let a=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),o=new Uint32Array(64);for(let e=0;e<r.length;e+=64){for(let t=0;t<16;t+=1)o[t]=i.getUint32(e+t*4);for(let e=16;e<64;e+=1){let t=o[e-15],n=o[e-2],r=(t>>>7|t<<25)^(t>>>18|t<<14)^t>>>3,i=(n>>>17|n<<15)^(n>>>19|n<<13)^n>>>10;o[e]=o[e-16]+r+o[e-7]+i>>>0}let[t,n,r,s,c,l,u,d]=a;for(let e=0;e<64;e+=1){let i=(c>>>6|c<<26)^(c>>>11|c<<21)^(c>>>25|c<<7),a=d+i+(c&l^~c&u)+Dr[e]+o[e]>>>0,f=((t>>>2|t<<30)^(t>>>13|t<<19)^(t>>>22|t<<10))+(t&n^t&r^n&r)>>>0;d=u,u=l,l=c,c=s+a>>>0,s=r,r=n,n=t,t=a+f>>>0}a[0]+=t,a[1]+=n,a[2]+=r,a[3]+=s,a[4]+=c,a[5]+=l,a[6]+=u,a[7]+=d}return Array.from(a,e=>e.toString(16).padStart(8,`0`)).join(``)}function kr(e){return typeof e!=`object`||!e?e===void 0?`null`:JSON.stringify(e):Array.isArray(e)?`[${e.map(kr).join(`,`)}]`:`{${Object.keys(e).filter(t=>e[t]!==void 0).sort().map(t=>`${JSON.stringify(t)}:${kr(e[t])}`).join(`,`)}}`}var Ar=`fb1:`;function jr(e){let t=e.map(e=>{let t=e.eq!==null&&typeof e.eq==`object`,n=t?kr(e.eq):e.eq;return r=>{if(!Object.prototype.hasOwnProperty.call(r,e.field))return!1;let i=r[e.field];return t?typeof i==`object`&&!!i&&kr(i)===n:i===n}});return e=>t.every(t=>t(e))}function Mr(e,t){let n=rr(e),r=[...new Set(n.predicates.map(e=>e.collection))],i=r.length?t.scan(r):new Map;return`${Ar}${Or(kr({records:n.records.map(e=>[e.collection,e.id,t.read(Pr(e.collection,e.id))??null]),predicates:n.predicates.map(e=>[e.collection,e.where,(i.get(e.collection)??[]).filter(jr(e.where)).map(e=>[String(e.id),e]).sort(([e],[t])=>String(e)<String(t)?-1:1)])}))}`}function Nr(e,t){let n=new Set(t),r=new Map(t.map(e=>[e,[]]));for(let[t,i]of e){let e=t.indexOf(`:`),a=e<0?``:t.slice(0,e);n.has(a)&&i&&typeof i==`object`&&r.get(a).push(i)}return r}function Pr(e,t){return`${e}:${t}`}var Fr=/^[A-Za-z0-9._-]{1,128}$/;function Ir(e,t){if(!e.transactionId||!e.transactionId.trim())return{kind:`reject`,reason:`transactionId is required`};if(e.operations.length===0)return{kind:`reject`,reason:`a transaction requires at least one operation`};if(t.hasApplied(e.transactionId))return{kind:`duplicate`};let n=[...(e.preconditions??[]).map(e=>({...e})),...e.operations.filter(e=>e.expectedVersion!==void 0||e.expectedEpoch!==void 0||e.expectedLeaseId!==void 0).map(e=>({collection:e.collection,id:e.id,expectedVersion:e.expectedVersion,expectedEpoch:e.expectedEpoch,expectedLeaseId:e.expectedLeaseId}))];if(n.length>0&&!t.read)return{kind:`reject`,reason:`this runtime cannot evaluate transaction preconditions, so it refuses the transaction rather than committing it unconditionally`};for(let e of n){if(!Fr.test(e.collection)||!Fr.test(String(e.id)))return{kind:`reject`,reason:`invalid collection or id: ${e.collection}:${e.id}`};if(e.requireAbsent!==!0&&e.expectedVersion===void 0&&e.expectedEpoch===void 0&&e.expectedLeaseId===void 0)return{kind:`reject`,reason:`precondition on ${e.collection}:${e.id} constrains nothing`};let n=Pr(e.collection,String(e.id)),r=t.read(n);if(e.requireAbsent){if(r!==void 0)return{kind:`reject`,reason:`PRECONDITION_FAILED:${n}:record already exists`,failure:{predicate:`present`,collection:e.collection,key:n}};continue}if(r===void 0)return{kind:`reject`,reason:`PRECONDITION_FAILED:${n}:record does not exist`,failure:{predicate:`missing`,collection:e.collection,key:n}};if(e.expectedVersion!==void 0){let t=typeof r.__version==`number`?r.__version:1;if(t!==e.expectedVersion)return{kind:`reject`,reason:`PRECONDITION_FAILED:${n}:version ${t}, expected ${e.expectedVersion}`,failure:{predicate:`version`,collection:e.collection,key:n,expected:e.expectedVersion,actual:t}}}if(e.expectedEpoch!==void 0){let t=r.authority,i=typeof t?.epoch==`number`?t.epoch:0;if(i!==e.expectedEpoch)return{kind:`reject`,reason:`PRECONDITION_FAILED:${n}:epoch ${i}, expected ${e.expectedEpoch}`,failure:{predicate:`epoch`,collection:e.collection,key:n,expected:e.expectedEpoch,actual:i}}}if(e.expectedLeaseId!==void 0){let t=r.lease,i=t?.leaseId,a=typeof t?.expiresAt==`number`&&t.expiresAt>Date.now();if(i!==e.expectedLeaseId||!a)return{kind:`reject`,reason:`PRECONDITION_FAILED:${n}:lease ${i??`none`}, expected ${e.expectedLeaseId}`,failure:{predicate:`lease`,collection:e.collection,key:n,expected:e.expectedLeaseId,actual:i??null}}}}let r=e.fences??[];if(r.length>0){if(!t.read||!t.scan)return{kind:`reject`,reason:`this runtime cannot evaluate read-basis fences inside its commit boundary, so it refuses the transaction rather than committing it unfenced`};for(let e of r){if(typeof e?.token!=`string`||!e.token.startsWith(`fb1:`))return{kind:`reject`,reason:`a read basis was not issued by this authority`};let n;try{n=Mr(e.reads,{read:t.read,scan:t.scan})}catch(e){return{kind:`reject`,reason:`invalid read basis: ${e instanceof Error?e.message:String(e)}`}}if(n!==e.token){let t=rr(e.reads);return{kind:`reject`,reason:`PRECONDITION_FAILED:read-basis:state read by this transaction has changed`,failure:{predicate:`fence`,collection:t.records[0]?.collection??t.predicates[0]?.collection??``,key:`read-basis`,expected:e.token,actual:n}}}}}let i=[],a=new Set;for(let r of e.operations){if(!Fr.test(r.collection)||!Fr.test(r.id))return{kind:`reject`,reason:`invalid collection or id: ${r.collection}:${r.id}`};let e=Pr(r.collection,r.id);if(a.has(e))return{kind:`reject`,reason:`transaction writes ${e} more than once`};if(a.add(e),r.requireAbsent&&t.exists(e))return{kind:`reject`,reason:`PRECONDITION_FAILED:${e}:record already exists`,failure:{predicate:`present`,collection:r.collection,key:e}};let o=r.requireAbsent===!0||n.some(e=>e.requireAbsent===!0&&e.collection===r.collection&&String(e.id)===r.id),s=r.value===void 0?void 0:o?{...r.value,id:r.id,__version:1}:r.expectedVersion===void 0?{...r.value,id:r.id}:{...r.value,id:r.id,__version:r.expectedVersion+1};i.push({key:e,collection:r.collection,id:r.id,value:s})}return{kind:`apply`,mutations:i}}function Lr(e,t,n,r){return{transactionId:e.transactionId,duplicate:t,operations:e.operations.length,stateBefore:n,stateAfter:r,baseRevision:n,commitRevision:r,revisionId:`revision-${r}`,operationIds:e.operations.map((t,n)=>`operation:${e.transactionId}:${n+1}`)}}var Rr=class extends Error{feltdbCode;feltdbConflict;constructor(e,t){super(e),this.name=`EmbeddedTransactionRejected`,t&&(this.feltdbCode=`PRECONDITION_FAILED`,this.feltdbConflict=t)}},zr=()=>typeof performance<`u`?performance.now():Date.now();function Br(e,t){return e===t||e==null&&t==null?0:e==null?-1:t==null?1:typeof e==`number`&&typeof t==`number`?e<t?-1:1:String(e).localeCompare(String(t))}function Vr(e){return e.fields?.length?e.fields.map((t,n)=>({field:t,direction:e.directions?.[n]??`asc`})):e.field?[{field:e.field,direction:e.direction??`asc`}]:[]}function Hr(e,t,n){return t.slice(e.length+1)}function Ur(e){return`${typeof e}:${JSON.stringify(e)}`}function Wr(e,t,n,r){for(let e of t){let t=Br(n.record[e.field],r.record[e.field]);if(t)return e.direction===`asc`?t:-t}return Hr(e,n.key,n.record).localeCompare(Hr(e,r.key,r.record))}function Gr(e,t){let n=e[t.field];return!(`eq`in t&&n!==t.eq||`neq`in t&&n===t.neq||`lt`in t&&Br(n,t.lt)>=0||`lte`in t&&Br(n,t.lte)>0||`gt`in t&&Br(n,t.gt)<=0||`gte`in t&&Br(n,t.gte)<0)}function Kr(e){let t=JSON.stringify({collection:e.collection,where:e.where??[],orderBy:e.orderBy??[],limit:e.limit}),n=14695981039346656037n;for(let e=0;e<t.length;e+=1)n^=BigInt(t.charCodeAt(e)),n=BigInt.asUintN(64,n*1099511628211n);return n.toString(16).padStart(16,`0`)}function qr(e){let t=JSON.stringify(e);return typeof Buffer<`u`?Buffer.from(t).toString(`base64url`):btoa(unescape(encodeURIComponent(t))).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function Jr(e,t){try{let n=typeof Buffer<`u`?Buffer.from(e,`base64url`).toString(`utf8`):(()=>{let t=e.replace(/-/g,`+`).replace(/_/g,`/`);return decodeURIComponent(escape(atob(t.padEnd(Math.ceil(t.length/4)*4,`=`))))})(),r=JSON.parse(n);if(r.v!==1||r.binding!==t||!Array.isArray(r.values)||typeof r.key!=`string`)throw Error();return r}catch{throw Error(`INVALID_CURSOR: cursor is malformed or does not match this query`)}}var Yr=class{allRows;indexes=new Map;constructor(e){this.allRows=e,this.rebuild()}rebuild(){this.indexes.clear();let e=[...this.allRows()];for(let[t,n]of e)this.installDefinition(t,n,e)}apply(e,t){if(e.startsWith(`__indexes__:`)){t===void 0?this.indexes.delete(e):this.installDefinition(e,t,[...this.allRows()]);return}let n=e.indexOf(`:`);if(n<1)return;let r=e.slice(0,n);for(let n of this.indexes.values()){if(n.collection!==r)continue;let i=n.byKey.get(e);if(i){let t=n.buckets.get(Ur(i.record[n.fields[0].field])),r=t?.findIndex(t=>t.key===e)??-1;r>=0&&t.splice(r,1),n.byKey.delete(e)}if(t&&typeof t==`object`&&!Array.isArray(t)){let i={key:e,record:t},a=Ur(i.record[n.fields[0].field]),o=n.buckets.get(a);o||(o=[],n.buckets.set(a,o));let s=0,c=o.length;for(;s<c;){let e=s+c>>>1;Wr(r,n.fields,o[e],i)<=0?s=e+1:c=e}o.splice(s,0,i),n.byKey.set(e,i)}n.globalDirty=!0}}installDefinition(e,t,n){let r=e.split(`:`);if(r.length<3||r[0]!==`__indexes__`||!t||typeof t!=`object`)return;let i=t.config;if(!i?.name)return;let a=r[1],o=Vr(i);if(!o.length||i.type===`text`)return;let s=`${a}:`,c=n.filter(([e,t])=>e.startsWith(s)&&t&&typeof t==`object`&&!Array.isArray(t)).map(([e,t])=>({key:e,record:t}));c.sort((e,t)=>Wr(a,o,e,t));let l=new Map;for(let e of c){let t=Ur(e.record[o[0].field]),n=l.get(t)??[];n.push(e),l.set(t,n)}this.indexes.set(e,{collection:a,config:i,fields:o,entries:c,byKey:new Map(c.map(e=>[e.key,e])),buckets:l,globalDirty:!1})}plan(e){let t=new Map((e.where??[]).filter(e=>`eq`in e).map(e=>[e.field,e.eq])),n=e.orderBy??[];for(let r of this.indexes.values()){if(r.collection!==e.collection)continue;let i=0;for(;i<r.fields.length&&t.has(r.fields[i].field);)i+=1;if(i===0&&(e.where?.length??0)>0)continue;let a=r.fields.slice(i),o=n.every((e,t)=>a[t]?.field===e.field&&a[t]?.direction===e.direction),s=a.length===n.length,c=a.length===n.length+1&&a.at(-1)?.field===`id`&&a.at(-1)?.direction===`asc`;if(!(n.length&&(!o||!s&&!c)))return{index:r,explanation:{plan:n.length?`index-range`:`index-filter`,index:r.config.name,order:this.orderDescription(e),limit:e.limit,cursor:!!e.cursor}}}return{explanation:{plan:`full-scan`,reason:`no compatible index`,order:this.orderDescription(e),limit:e.limit,cursor:!!e.cursor}}}explain(e){return this.validate(e),this.plan(e).explanation}execute(e){this.validate(e);let t=zr(),n=this.plan(e),r={scanned:0,decoded:0,matched:0,sorted:0,materialized:0,returned:0,usedIndex:!!n.index,indexName:n.index?.config.name,indexLookupMs:0,executionMs:0},i=e.where??[],a=e.orderBy??[],o=a.map(e=>({field:e.field,direction:e.direction})),s=e.cursor?Jr(e.cursor,Kr(e)):void 0,c=[],l=zr();if(!n.index){let t=`${e.collection}:`;for(let[e,n]of this.allRows()){if(!e.startsWith(t))continue;r.scanned+=1;let a=n;!a||typeof a!=`object`||!i.every(e=>Gr(a,e))||(r.matched+=1,c.push({key:e,record:a}))}}let u=n.index?this.indexRange(n.index,i):{entries:[],start:0,end:0},d=u.entries,f=u.start;if(n.index&&s){let t=u.start,n=u.end;for(;t<n;){let r=t+n>>>1;this.compareEntryCursor(e.collection,o,d[r],s)<=0?t=r+1:n=r}f=t}for(let t=f;t<u.end;t+=1){let a=d[t];if(r.scanned+=1,!(!a.record||typeof a.record!=`object`||!i.every(e=>Gr(a.record,e)))&&(r.matched+=1,c.push(a),n.index&&c.length>e.limit))break}r.indexLookupMs=n.index?zr()-l:0;let p=c.length;n.index||(c.sort((t,n)=>Wr(e.collection,o,t,n)),r.sorted=c.length,s&&(c=c.filter(t=>this.afterCursor(e.collection,o,t,s))));let m=c.length>e.limit,h=c.slice(0,e.limit),g=h.map(e=>e.record);r.materialized=n.index?g.length:p,r.returned=g.length,r.executionMs=zr()-t;let _=h.at(-1),v=m&&_?qr({v:1,binding:Kr(e),values:a.map(e=>_.record[e.field]),key:Hr(e.collection,_.key,_.record)}):void 0;return{records:g,...v?{nextCursor:v}:{},exhausted:!v,stats:r,plan:{access_method:n.explanation.plan,actual_rows_scanned:r.scanned,actual_rows_returned:r.returned,matching_records:r.matched,index:r.indexName,scan_fallback:!r.usedIndex}}}afterCursor(e,t,n,r){return this.compareEntryCursor(e,t,n,r)>0}compareEntryCursor(e,t,n,r){for(let e=0;e<t.length;e+=1){let i=Br(n.record[t[e].field],r.values[e]);if(i)return t[e].direction===`asc`?i:-i}return Hr(e,n.key,n.record).localeCompare(r.key)}indexRange(e,t){let n=new Map(t.filter(e=>`eq`in e).map(e=>[e.field,e.eq])),r=0;for(;r<e.fields.length&&n.has(e.fields[r].field);)r+=1;if(r===0)return e.globalDirty&&=(e.entries=[...e.byKey.values()].sort((t,n)=>Wr(e.collection,e.fields,t,n)),!1),{entries:e.entries,start:0,end:e.entries.length};let i=e.buckets.get(Ur(n.get(e.fields[0].field)))??[];if(r===1)return{entries:i,start:0,end:i.length};let a=t=>{for(let i=0;i<r;i+=1){let r=e.fields[i],a=Br(t.record[r.field],n.get(r.field));if(a)return r.direction===`asc`?a:-a}return 0},o=0,s=i.length;for(;o<s;){let e=o+s>>>1;a(i[e])<0?o=e+1:s=e}let c=o;for(s=i.length;o<s;){let e=o+s>>>1;a(i[e])<=0?o=e+1:s=e}return{entries:i,start:c,end:o}}orderDescription(e){return[...(e.orderBy??[]).map(e=>`${e.field} ${e.direction.toUpperCase()}`),`id ASC`].join(`, `)}validate(e){if(!e.collection?.trim()||!Number.isInteger(e.limit)||e.limit<1||e.limit>1e3)throw Error(`INVALID_QUERY: collection and a limit between 1 and 1000 are required`);for(let t of e.where??[]){let e=Object.keys(t).filter(e=>e!==`field`),n=e.filter(e=>[`eq`,`neq`,`lt`,`lte`,`gt`,`gte`].includes(e));if(!t.field||n.length!==1||e.length!==1)throw Error(`INVALID_QUERY: each condition requires a field and exactly one operator`)}if(e.semantic!==void 0)throw Error(`SEMANTIC_UNSUPPORTED: this runtime has no semantic runtime binding; semantic query composition is available through the managed authority`)}},Xr=new Map,Zr=new Map;function Qr(e){let t=Zr.get(e);return t||(t={value:0,replicated:!1},Zr.set(e,t)),t}var $r=class{rows;events=[];sequence=0;origin;revisionState;peers=new Set;applied=new Set;queryEngine;indexedRevision;constructor(e){let t=Xr.get(e);t||(t=new Map,Xr.set(e,t)),this.rows=t,this.revisionState=Qr(e),this.origin=`memory:${e}`,this.queryEngine=new Yr(()=>this.rows.entries()),this.indexedRevision=this.revisionState.value}event(e,t,n,r){this.sequence+=1,this.revisionState.value+=1;let i=Date.now();this.events.push({sequence:this.sequence,collection:e,key:t,type:n,value:r,timestamp:i,origin:this.origin,id:`${this.origin}:${i}:${this.sequence}`}),this.queryEngine.apply(t,n===`put`?this.rows.get(t):void 0),this.indexedRevision=this.revisionState.value}async read_basis(e){let t=rr(e);return{reads:t,token:Mr(t,{read:e=>this.rows.get(e),scan:e=>Nr(this.rows,e)})}}async commit_transaction(e){let t=this.sequence,n=Ir(e,{exists:e=>this.rows.has(e),hasApplied:e=>this.applied.has(e),read:e=>this.rows.get(e),scan:e=>Nr(this.rows,e)});if(n.kind===`duplicate`)return Lr(e,!0,t,this.sequence);if(n.kind===`reject`)throw new Rr(n.reason,n.failure);for(let e of n.mutations)e.value===void 0?(this.rows.delete(e.key),this.event(e.collection,e.key,`delete`)):(this.rows.set(e.key,e.value),this.event(e.collection,e.key,`put`,e.value));return this.applied.add(e.transactionId),Lr(e,!1,t,this.sequence)}insert(e,t){try{return this.rows.set(e,JSON.parse(t)),this.event(e.split(`:`)[0],e,`put`,JSON.parse(t)),{success:!0,data:e}}catch(e){return{success:!1,error:String(e)}}}update(e,t){return this.rows.has(e)?this.insert(e,t):{success:!1,error:`Record ${e} not found`}}get(e){let t=this.rows.get(e);return t===void 0?{success:!0}:{success:!0,data:JSON.stringify(t)}}delete(e){return this.rows.delete(e),this.event(e.split(`:`)[0],e,`delete`),{success:!0,data:e}}putIfAbsent(e,t){let n=this.rows.get(e);if(n!==void 0)return Promise.resolve({inserted:!1,value:JSON.stringify(n)});let r=JSON.parse(t);return this.rows.set(e,r),this.event(e.split(`:`)[0],e,`put`,r),Promise.resolve({inserted:!0,value:t})}cas(e){let t=this.rows.get(e.key),n=JSON.parse(e.value);if(t===void 0)return Promise.resolve({updated:!1,currentVersion:0});let r=t,i=r.__version??1,a=r.authority?.epoch??0;if(i!==e.expectedVersion||e.expectedEpoch!==void 0&&a!==e.expectedEpoch)return Promise.resolve({updated:!1,currentVersion:i,currentEpoch:a});let o=e.expectedVersion+1,s={...n,__version:o};return this.rows.set(e.key,s),this.event(e.key.split(`:`)[0],e.key,`put`,s),Promise.resolve({updated:!0,currentVersion:o,currentEpoch:a,item:s})}query(e){let t=`${e}:`,n=[...this.rows].filter(([e])=>e.startsWith(t)).map(([,e])=>e);return{success:!0,data:JSON.stringify(n)}}async authority_query(e){return this.indexedRevision!==this.revisionState.value&&(this.queryEngine.rebuild(),this.indexedRevision=this.revisionState.value),this.queryEngine.execute(e)}explain_query(e){return this.queryEngine.explain(e)}rebuild_indexes(){this.queryEngine.rebuild(),this.indexedRevision=this.revisionState.value}get_capability_records(e){return this.query(e)}execute_op(){return{success:!1,error:`Raw operations are unavailable in the memory runtime`}}sync_info(){return{success:!0,data:JSON.stringify({instance_id:this.origin,sequence:this.sequence,connected_peers:[...this.peers],pending_operations:0,operations_sent:0,operations_received:0,conflicts_detected:0,last_sync_ms:0,is_connected:this.peers.size>0})}}add_peer(){return{success:!0}}add_sync_peer(e){return this.peers.add(e),{success:!0}}remove_sync_peer(e){return this.peers.delete(e),{success:!0}}acknowledge_peer_operations(){return{success:!0}}get_pending_for_peer(){return{success:!0,data:`[]`}}instance_id(){return this.origin}get_sequence(){return this.sequence}freshness(){return this.revisionState.replicated||this.peers.size>0?{domain:`replicated`,validation:`refresh`,invalidation:!1,reason:`remote operations order causally across replicas, so a local counter is not an authoritative revision`}:{domain:`single-process`,validation:`revision`,invalidation:!1,revisionScope:this.origin}}async revision(){let e=this.freshness();if(e.validation!==`revision`)throw new qn(`memory runtime: ${e.reason}`);return{value:this.revisionState.value,scope:this.origin}}audit_events(){return[...this.events]}export_operations(e){return this.events.filter(t=>t.sequence>e)}apply_remote_operations(e){e.length>0&&(this.revisionState.replicated=!0);let t=0,n=0;for(let r of e){if(this.events.some(e=>e.id===r.id)){n++;continue}let e=[...this.events].reverse().find(e=>e.key===r.key),i=`${String(r.timestamp).padStart(16,`0`)}:${r.origin}:${r.id}`,a=e?`${String(e.timestamp).padStart(16,`0`)}:${e.origin}:${e.id}`:``;this.sequence+=1,this.events.push({...r,sequence:this.sequence}),i>=a?(r.type===`delete`?this.rows.delete(r.key):this.rows.set(r.key,r.value),this.queryEngine.apply(r.key,r.type===`delete`?void 0:r.value),this.revisionState.value+=1,this.indexedRevision=this.revisionState.value,t++):n++}return{applied:t,ignored:n}}},L;(function(e){e.INVALID_REQUEST=`INVALID_REQUEST`,e.UNAUTHORIZED=`UNAUTHORIZED`,e.VERSION_CONFLICT=`VERSION_CONFLICT`,e.SCOPE_VIOLATION=`SCOPE_VIOLATION`,e.INVALID_CURSOR=`INVALID_CURSOR`,e.CURSOR_SCOPE_VIOLATION=`CURSOR_SCOPE_VIOLATION`,e.DURABILITY_FAILURE=`DURABILITY_FAILURE`,e.RECOVERY_FAILURE=`RECOVERY_FAILURE`,e.CONTRACT_UNSUPPORTED=`CONTRACT_UNSUPPORTED`,e.OK=`OK`,e.CONFLICT=`CONFLICT`,e.PRECONDITION_FAILED=`PRECONDITION_FAILED`,e.TOO_BUSY=`TOO_BUSY`,e.INTERNAL_ERROR=`INTERNAL_ERROR`,e.AUTHENTICATION_REQUIRED=`AUTHENTICATION_REQUIRED`,e.AUTHENTICATION_FAILED=`AUTHENTICATION_FAILED`,e.FORBIDDEN=`FORBIDDEN`,e.NOT_FOUND=`NOT_FOUND`,e.VALIDATION_ERROR=`VALIDATION_ERROR`,e.IDEMPOTENCY_CONFLICT=`IDEMPOTENCY_CONFLICT`,e.COMMIT_OUTCOME_UNKNOWN=`COMMIT_OUTCOME_UNKNOWN`,e.QUERY_INVALID=`QUERY_INVALID`,e.QUERY_LIMIT_EXCEEDED=`QUERY_LIMIT_EXCEEDED`,e.WORKFLOW_NOT_FOUND=`WORKFLOW_NOT_FOUND`,e.AGENT_NOT_FOUND=`AGENT_NOT_FOUND`,e.CAPABILITY_NOT_FOUND=`CAPABILITY_NOT_FOUND`,e.EXECUTION_FAILED=`EXECUTION_FAILED`,e.SERVICE_UNAVAILABLE=`SERVICE_UNAVAILABLE`,e.AUTHORITY_SCOPE_REQUIRED=`AUTHORITY_SCOPE_REQUIRED`,e.AUTHORITY_SCOPE_INVALID=`AUTHORITY_SCOPE_INVALID`,e.AUTHORITY_SCOPE_MISMATCH=`AUTHORITY_SCOPE_MISMATCH`})(L||={});var R=class extends Error{code;requestId;status;constructor(e,t,n,r){super(e),this.code=t,this.requestId=n,this.status=r,this.name=`FeltDBServiceError`}};function ei(e){let t=e,n=t?.status,r=typeof t?.code==`string`?t.code:void 0;return n===401||r===`AUTHENTICATION_REQUIRED`||r===`AUTHENTICATION_FAILED`?`authentication`:n===403||r===`FORBIDDEN`?`authorization`:typeof n==`number`&&[400,404,405,409,410,422].includes(n)||r!==void 0&&[`NOT_FOUND`,`VALIDATION_ERROR`,`QUERY_INVALID`].includes(r)?`configuration`:r===`CLIENT_CLOSED`?`closed`:`transient`}function ti(e){return ei(e)===`transient`?`transient`:`permanent`}function ni(e){let t=e instanceof R?e:void 0,n=e;return{kind:ti(e),failure_class:ei(e),name:n?.name??`Error`,message:n?.message??String(e),...t?.code===void 0?{}:{code:String(t.code)},...typeof n?.status==`number`?{status:n.status}:{},at:new Date().toISOString()}}var ri=class{cached;inFlight;failures=0;lastFailure;lastSuccessAt;get value(){return this.cached}get state(){return this.cached===void 0?this.inFlight?`loading`:`unavailable`:`cached`}snapshot(){return{state:this.state,consecutive_failures:this.failures,...this.lastFailure?{last_failure:this.lastFailure}:{},...this.lastSuccessAt?{last_success_at:this.lastSuccessAt}:{}}}get(e){if(this.cached!==void 0)return Promise.resolve(this.cached);if(this.inFlight)return this.inFlight;let t=Promise.resolve().then(e).then(e=>(this.cached=e,this.failures=0,this.lastFailure=void 0,this.lastSuccessAt=new Date().toISOString(),e),e=>{throw this.failures+=1,this.lastFailure=ni(e),e}).finally(()=>{this.inFlight===t&&(this.inFlight=void 0)});return this.inFlight=t,t}seed(e){this.cached=e,this.failures=0,this.lastFailure=void 0,this.lastSuccessAt=new Date().toISOString()}reset(){this.cached=void 0,this.inFlight=void 0,this.failures=0,this.lastFailure=void 0}},ii=class{base;max;factor;random;consecutive=0;constructor(e={}){this.base=Math.max(1,e.base??500),this.max=Math.max(this.base,e.max??3e4),this.factor=Math.max(1,e.factor??2),this.random=e.random??Math.random}get attempts(){return this.consecutive}ceiling(e=this.consecutive){return Math.min(this.max,Math.round(this.base*this.factor**e))}next(){let e=this.ceiling();this.consecutive+=1;let t=e/2;return Math.round(t+this.random()*t)}reset(){this.consecutive=0}};function ai(e,t){return t.aborted?Promise.resolve():new Promise(n=>{let r=()=>{clearTimeout(i),t.removeEventListener(`abort`,r),n()},i=setTimeout(r,e);i.unref?.(),t.addEventListener(`abort`,r,{once:!0})})}function oi(e){return`${e}-${typeof crypto?.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}`}function si(e){if(!e||typeof e!=`object`||Array.isArray(e))return e;let t={...e};return delete t._id,delete t._version,t}var z=class{collection_queries_via_authority=!0;url;token;applicationId;environment;authorityScope;authWaiters=new Set;revisionCache=new ri;backoff;requestTimeoutMs;connectionState=`closed`;availabilityState=`unknown`;lastError;lastSuccessAt;nextRetryAt;streamFailures=0;authorityFailures=0;constructor(e){this.url=e.url.replace(/\/$/,``),this.token=e.token||``,this.applicationId=e.applicationId,this.environment=e.environment||`production`,this.authorityScope=e.authorityScope,this.requestTimeoutMs=Math.max(1,e.requestTimeoutMs??3e4),this.backoff=new ii(e.reconnect)}health(){let e=this.revisionCache.snapshot(),t=this.nextRetryAt===void 0?void 0:this.nextRetryAt-Date.now();return{connection_state:this.connectionState,availability_state:this.availabilityState,usable:this.availabilityState===`available`&&e.state===`cached`,recovery_possible:this.availabilityState!==`closed`&&![`authentication`,`authorization`,`configuration`].includes(this.lastError?.failure_class??``),revision_state:e.state,...this.revisionCache.value===void 0?{}:{revision_id:this.revisionCache.value},consecutive_failures:this.authorityFailures,...this.lastSuccessAt??e.last_success_at?{last_success_at:this.lastSuccessAt??e.last_success_at}:{},...this.lastError??e.last_failure?{last_error:this.lastError??e.last_failure}:{},...this.connectionState===`backoff`&&this.nextRetryAt!==void 0?{next_retry_at:new Date(this.nextRetryAt).toISOString(),next_retry_in_ms:Math.max(0,t??0)}:{}}}recordFailure(e){let t=ni(e);return this.lastError=t,this.authorityFailures+=1,this.availabilityState=t.failure_class===`closed`?`closed`:`degraded`,t}recordSuccess(){this.availabilityState=`available`,this.lastSuccessAt=new Date().toISOString(),this.lastError=void 0,this.authorityFailures=0}headers(e=!1){return{...this.token?{Authorization:`Bearer ${this.token}`}:{},"FeltDB-Protocol":`1`,...this.authorityScope?.kind===`tenant`?{"FeltDB-Tenant-Id":this.authorityScope.tenantId,...this.authorityScope.environmentId?{"FeltDB-Environment-Id":this.authorityScope.environmentId}:{}}:this.authorityScope?.kind===`platform`?{"FeltDB-Authority-Mode":`platform`}:{},...e?{"Content-Type":`application/json`}:{}}}updateToken(e){this.token=e,this.backoff.reset();for(let e of this.authWaiters)e();this.authWaiters.clear()}waitForAuthChange(e){return e.aborted?Promise.resolve():new Promise(t=>{let n=()=>{this.authWaiters.delete(r),r()},r=()=>{e.removeEventListener(`abort`,n),t()};this.authWaiters.add(r),e.addEventListener(`abort`,n,{once:!0})})}async auth_request(e,t){let n=await fetch(`${this.url}/v1/auth/${e}`,{method:e===`session`?`GET`:`POST`,headers:this.headers(t!==void 0),...t===void 0?{}:{body:JSON.stringify(e===`signup`||e===`signin`?{application_id:this.applicationId,...t}:t)}}),r=n.status===204?{}:await n.json();if(!n.ok)throw new R(r.message||r.error||`Authentication failed`,r.code||r.error||`AUTHENTICATION_FAILED`,r.request_id,n.status);return r.access_token&&this.updateToken(r.access_token),e===`signout`&&this.updateToken(``),r}splitKey(e){let t=e.indexOf(`:`);if(t<1||t===e.length-1)throw Error(`Invalid FeltDB key: ${e}`);return[e.slice(0,t),e.slice(t+1)]}async revisionId(){if(!this.applicationId)throw Error(`applicationId is required for the canonical application service`);return this.revisionCache.get(async()=>{let e=await this.application_request(`/application`);if(!e?.revision_id){let e=new R(`canonical application discovery returned no revision_id`,`VALIDATION_ERROR`,void 0,422);throw this.recordFailure(e),e}return e.revision_id})}revisionState(){return this.revisionCache.state}async canonical(e,t){let n=await this.revisionId();return this.application_request(e,{method:`POST`,body:JSON.stringify({application_id:this.applicationId,revision_id:n,environment:this.environment,...t})})}transactionDocument(e,t,n=crypto.randomUUID(),r=[],i=[]){let a=this.authorityScope?.kind===`tenant`?this.authorityScope.tenantId:``;return{transaction_id:n,tenant_id:a,application_id:this.applicationId,revision_id:e,schema_version:0,authorization:{subject:``,tenant_id:a,application_id:this.applicationId,revision_id:e,capabilities:[]},operations:t,preconditions:r,...i.length?{fences:i}:{}}}async canonicalTransaction(e,t,n=[],r=[]){let i=await this.revisionId();return this.application_request(`/transactions`,{method:`POST`,body:JSON.stringify({application_id:this.applicationId,revision_id:i,environment:this.environment,transaction:this.transactionDocument(i,e,t,n,r)})})}async get(e){try{let[t,n]=this.splitKey(e);if(this.applicationId){let e=await this.canonical(`/query`,{query:{collection:t,filter:{operator:`eq`,field:`_id`,value:n},limit:1}});return{success:!0,data:e.records.length?JSON.stringify(si(e.records[0])):void 0}}let r=await fetch(`${this.url}/collections/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{headers:this.headers()});if(r.status===404)return{success:!0};if(!r.ok)return this.failure(r);let i=await r.json();return{success:!0,data:JSON.stringify(i.value)}}catch(e){return{success:!1,error:String(e)}}}async query(e){try{if(this.applicationId){let t=[],n;do{let r=await this.canonical(`/query`,{query:{collection:e,limit:100,...n?{cursor:n}:{}}});t.push(...r.records.map(si)),n=r.next_cursor}while(n);return{success:!0,data:JSON.stringify(t)}}let t=await fetch(`${this.url}/collections/${encodeURIComponent(e)}`,{headers:this.headers()});if(!t.ok)return this.failure(t);let n=await t.json();return{success:!0,data:JSON.stringify(n.map(e=>e.value))}}catch(e){return{success:!1,error:String(e)}}}async authority_query(e){if(this.applicationId){if(e.semantic){let e=Error(`SEMANTIC_UNSUPPORTED: the canonical application query does not compose semantic decisions; use the bounded authority query`);throw e.code=`SEMANTIC_UNSUPPORTED`,e}let t=(e.where||[]).map(e=>{let t=Object.keys(e).find(e=>e!==`field`)||`eq`;return{operator:t,field:e.field,value:e[t]}}),n=await this.canonical(`/query`,{query:{collection:e.collection,filter:t.length===1?t[0]:t.length?{operator:`and`,filters:t}:void 0,order_by:e.orderBy?.map(e=>({field:e.field,direction:e.direction})),limit:e.limit,cursor:e.cursor}});return{records:n.records.map(si),nextCursor:n.next_cursor,exhausted:!n.next_cursor,plan:n.plan}}let t=await fetch(`${this.url}/query`,{method:`POST`,headers:this.headers(!0),body:JSON.stringify(e)}),n=await t.json();if(!t.ok){let e=Error(n.message||n.error||`authority query failed with HTTP ${t.status}`);throw e.code=n.code,e.status=t.status,e}return n}async insert(e,t){try{let[n,r]=this.splitKey(e),i=JSON.parse(t);if(this.applicationId)return await this.canonicalTransaction([{kind:`insert`,collection:n,id:r,value:i}]),{success:!0,data:e};let a=await fetch(`${this.url}/collections/${encodeURIComponent(n)}`,{method:`POST`,headers:this.headers(!0),body:JSON.stringify({...i,id:r})});return a.ok?{success:!0,data:e}:this.failure(a)}catch(e){return{success:!1,error:String(e)}}}async update(e,t){try{let[n,r]=this.splitKey(e);if(this.applicationId)return await this.canonicalTransaction([{kind:`update`,collection:n,id:r,value:JSON.parse(t)}]),{success:!0,data:e};let i=await fetch(`${this.url}/collections/${encodeURIComponent(n)}/${encodeURIComponent(r)}`,{method:`PATCH`,headers:this.headers(!0),body:t});return i.ok?{success:!0,data:e}:this.failure(i)}catch(e){return{success:!1,error:String(e)}}}async commit_transaction(e){if(this.applicationId){let t=e.operations.map(e=>({kind:e.value===void 0?`delete`:e.requireAbsent?`insert`:`update`,collection:e.collection,id:e.id,value:e.value&&typeof e.value==`object`&&!Array.isArray(e.value)?{...e.value,id:e.id}:e.value})),n=[...e.preconditions??[],...e.operations.filter(e=>e.expectedVersion!==void 0||e.expectedEpoch!==void 0||e.expectedLeaseId!==void 0)].map(e=>({kind:`record`,collection:e.collection,id:e.id,require_absent:e.requireAbsent??!1,expected_version:e.expectedVersion,expected_epoch:e.expectedEpoch,expected_lease_id:e.expectedLeaseId})),r=await this.canonicalTransaction(t,e.transactionId,n,e.fences??[]);return{transactionId:r.transaction_id,baseRevision:r.base_revision,commitRevision:r.commit_revision,revisionId:r.revision_id,operationIds:r.operation_ids,status:r.status,duplicate:r.duplicate,operations:t.length,stateBefore:r.state_before,stateAfter:r.state_after}}let t;try{t=await fetch(`${this.url}/transactions`,{method:`POST`,headers:this.headers(!0),body:JSON.stringify(e),signal:AbortSignal.timeout(this.requestTimeoutMs)})}catch(e){throw this.recordFailure(e),new R(e instanceof Error?e.message:String(e),L.COMMIT_OUTCOME_UNKNOWN)}if(!t.ok){let e={};try{e=await t.json()}catch{}let n=Error(e.error||`transaction failed with HTTP ${t.status}`);throw n.status=t.status,e.code&&(n.feltdbCode=e.code),e.failure&&(n.feltdbConflict=e.failure),n}return await t.json()}async read_basis(e){if(this.applicationId)return this.canonical(`/transactions/read-basis`,{reads:e});let t=await fetch(`${this.url}/transactions/read-basis`,{method:`POST`,headers:this.headers(!0),body:JSON.stringify(e),signal:AbortSignal.timeout(this.requestTimeoutMs)});if(!t.ok)throw new R(t.status===404?`This authority does not issue read bases; it cannot evaluate fences inside its commit lock.`:`read basis failed with HTTP ${t.status}: ${await t.text()}`,t.status===404?L.CONTRACT_UNSUPPORTED:L.INVALID_REQUEST,void 0,t.status);return await t.json()}async putIfAbsent(e,t){let[n,r]=this.splitKey(e),i=JSON.parse(t);try{await this.commit_transaction({transactionId:oi(`put-if-absent`),operations:[{collection:n,id:r,value:i,requireAbsent:!0}]})}catch(t){if(!or(t).conflict)throw t;let n=await this.get(e);if(!n.success)throw Error(n.error||`could not read the record that won ${e}`);if(n.data===void 0)throw Error(`${e} was created and then removed while resolving a conditional create`);return{inserted:!1,value:n.data}}return{inserted:!0,value:JSON.stringify({...i,id:r,__version:1})}}async managedCas(e){if(e.rejectIfDiverged)throw Error(`rejectIfDiverged is a replication predicate the canonical transaction contract cannot express`);let[t,n]=this.splitKey(e.key),r=JSON.parse(e.value);delete r.__version;try{await this.commit_transaction({transactionId:oi(`update-if-version`),operations:[{collection:t,id:n,value:r,expectedVersion:e.expectedVersion,expectedEpoch:e.expectedEpoch,expectedLeaseId:e.expectedLeaseId}]})}catch(t){let n=or(t);if(!n.conflict)throw t;return{updated:!1,...await this.observedConflict(e.key,n.failure)}}let i={...r,id:n,__version:e.expectedVersion+1};return{updated:!0,currentVersion:e.expectedVersion+1,currentEpoch:e.expectedEpoch,item:i}}async observedConflict(e,t){let n=t?.predicate===`version`?`VERSION_CONFLICT`:t?.predicate===`epoch`?`AUTHORITY_CONFLICT`:t?.predicate===`lease`?`LEASE_CONFLICT`:t?.predicate===`missing`?`RECORD_MISSING`:t?.predicate===`present`?`RECORD_PRESENT`:void 0;if(t?.predicate===`version`&&typeof t.actual==`number`)return{currentVersion:t.actual,conflictCode:n};let r=await this.get(e),i=r.success&&r.data?JSON.parse(r.data):void 0;return{currentVersion:typeof i?.__version==`number`?i.__version:0,currentEpoch:i?.authority?.epoch,conflictCode:n}}async cas(e){if(this.applicationId)return this.managedCas(e);try{let[t,n]=this.splitKey(e.key),r=JSON.parse(e.value),i=await fetch(`${this.url}/collections/${encodeURIComponent(t)}/${encodeURIComponent(n)}/cas`,{method:`POST`,headers:this.headers(!0),body:JSON.stringify({expectedVersion:e.expectedVersion,expectedEpoch:e.expectedEpoch,expectedLeaseId:e.expectedLeaseId,rejectIfDiverged:e.rejectIfDiverged,value:r})});if(i.status===409){let e=await i.json();if((e.code===`VERSION_CONFLICT`||e.code===`AUTHORITY_CONFLICT`||e.code===`LEASE_CONFLICT`||e.code===`REPLICATION_CONFLICT`)&&e.currentVersion!==void 0)return{updated:!1,currentVersion:e.currentVersion,currentEpoch:e.currentEpoch,conflictCode:e.code}}if(!i.ok){let e=await this.failure(i);throw Error(e.error||`HTTP CAS failed`)}return await i.json()}catch(e){throw e instanceof Error?e:Error(String(e))}}async delete(e){try{let[t,n]=this.splitKey(e);if(this.applicationId)return await this.canonicalTransaction([{kind:`delete`,collection:t,id:n}]),{success:!0,data:e};let r=await fetch(`${this.url}/collections/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:`DELETE`,headers:this.headers()});return r.ok?{success:!0,data:e}:this.failure(r)}catch(e){return{success:!1,error:String(e)}}}async acquire(e,t){let n=await fetch(`${this.url}/refs/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{headers:this.headers()});if(n.status===404)return null;if(!n.ok)throw Error((await this.failure(n)).error);return(await n.json()).value}async search(e,t,n=50){let r=await fetch(`${this.url}/capabilities/search/${encodeURIComponent(e)}`,{method:`POST`,headers:this.headers(!0),body:JSON.stringify({query:t,limit:n})});if(!r.ok)throw Error((await this.failure(r)).error);return(await r.json()).map(e=>e.value)}async provenance(e,t){let n=await fetch(`${this.url}/provenance/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{headers:this.headers()});if(!n.ok)throw Error((await this.failure(n)).error);return(await n.json()).value}async storeContent(e){let t=await fetch(`${this.url}/content`,{method:`PUT`,headers:this.headers(),body:e});if(!t.ok)throw Error((await this.failure(t)).error);return t.json()}async acquireContent(e){let t=await fetch(`${this.url}/content/${encodeURIComponent(e)}`,{headers:this.headers()});if(t.status===404)return null;if(!t.ok)throw Error((await this.failure(t)).error);return new Uint8Array(await t.arrayBuffer())}async command(e,t){let n=await fetch(`${this.url}${e}`,{method:`POST`,headers:this.headers(!0),body:JSON.stringify(t)});if(!n.ok)throw Error((await this.failure(n)).error);return n.status===204?void 0:n.json()}async application_request(e,t={}){let n=e.includes(`?`)?`&`:`?`,r=this.applicationId?`${n}application_id=${encodeURIComponent(this.applicationId)}&environment=${encodeURIComponent(this.environment)}`:``;this.availabilityState===`degraded`&&(this.availabilityState=`recovering`);let i;try{i=await fetch(`${this.url}/v1${e}${r}`,{...t,signal:t.signal??AbortSignal.timeout(this.requestTimeoutMs),headers:{...this.headers(t.body!==void 0),...t.headers||{}}})}catch(e){this.recordFailure(e);let n=![`GET`,`HEAD`,`OPTIONS`].includes((t.method??`GET`).toUpperCase());throw new R(e instanceof Error?e.message:String(e),n?L.COMMIT_OUTCOME_UNKNOWN:L.SERVICE_UNAVAILABLE)}let a=await i.text(),o;try{o=a?JSON.parse(a):void 0}catch{o={message:a}}if(!i.ok){let e=new R(o?.message||o?.error||`FeltDB service request failed: HTTP ${i.status}`,o?.code||o?.error||`REQUEST_FAILED`,o?.request_id,i.status);throw o?.failure&&(e.feltdbConflict=o.failure),this.recordFailure(e),e}return this.recordSuccess(),o}async public_request(e,t={}){let n;try{n=await fetch(`${this.url}${e}`,{...t,signal:t.signal??AbortSignal.timeout(this.requestTimeoutMs),headers:{...this.headers(t.body!==void 0),...t.headers||{}}})}catch(e){this.recordFailure(e);let n=![`GET`,`HEAD`,`OPTIONS`].includes((t.method??`GET`).toUpperCase());throw new R(e instanceof Error?e.message:String(e),n?L.COMMIT_OUTCOME_UNKNOWN:L.SERVICE_UNAVAILABLE)}let r=await n.text(),i;try{i=r?JSON.parse(r):void 0}catch{i={message:r}}if(!n.ok){let e=new R(i?.message||i?.error||`FeltDB request failed: HTTP ${n.status}`,i?.code||(n.status===401?L.UNAUTHORIZED:n.status===403?L.FORBIDDEN:n.status===404?L.NOT_FOUND:`INVALID_REQUEST`),i?.request_id,n.status);throw this.recordFailure(e),e}return this.recordSuccess(),i}async execute_semantic_decision(e){return this.application_request(`/experimental/semantic-decisions`,{method:`POST`,body:JSON.stringify(e)})}subscribe_changes(e){let t=new AbortController;return this.connectionState=`connecting`,this.consumeEvents(t,e),()=>{t.abort(),this.connectionState=`closed`,this.nextRetryAt=void 0}}async consumeEvents(e,t){for(;!e.signal.aborted;){if(!this.token){this.connectionState=`failed`,this.availabilityState=`degraded`,await this.waitForAuthChange(e.signal);continue}let n=!1,r;try{this.connectionState=`connecting`;let i=this.applicationId?`/v1/events?application_id=${encodeURIComponent(this.applicationId)}&environment=${encodeURIComponent(this.environment)}`:`/events`,a=await fetch(`${this.url}${i}`,{headers:this.headers(),signal:e.signal});if(a.status===401||a.status===403){this.recordFailure(new R(`Event stream rejected: HTTP ${a.status}`,a.status===401?`AUTHENTICATION_REQUIRED`:`FORBIDDEN`,void 0,a.status)),this.connectionState=`failed`,this.availabilityState=`degraded`,await this.waitForAuthChange(e.signal);continue}if(!a.ok||!a.body)throw new R(`Event stream failed: HTTP ${a.status}`,`SERVICE_UNAVAILABLE`,void 0,a.status);n=!0,this.connectionState=`connected`,this.streamFailures=0,this.recordSuccess(),this.backoff.reset(),r=a.body.getReader();let o=new TextDecoder,s=``;for(;!e.signal.aborted;){let{done:e,value:n}=await r.read();if(e)break;s+=o.decode(n,{stream:!0}).replace(/\r\n/g,`
|
|
10
|
+
Please change the parent <Route path="${e}"> to <Route path="${e===`/`?`*`:`${e}/*`}">.`)}let u=ut(),d;if(t){let e=typeof t==`string`?A(t):t;E(c===`/`||e.pathname?.startsWith(c),`When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${c}" but pathname "${e.pathname}" was given in the \`location\` prop.`),d=e}else d=u;let f=d.pathname||`/`,p=f;if(c!==`/`){let e=c.replace(/^\//,``).split(`/`);p=`/`+f.replace(/^\//,``).split(`/`).slice(e.length).join(`/`)}let m=n&&n.state.matches.length?n.state.matches.map(e=>Object.assign(e,{route:n.manifest[e.route.id]||e.route})):ae(e,{pathname:p});D(l||m!=null,`No routes matched location "${d.pathname}${d.search}${d.hash}" `),D(m==null||m[m.length-1].route.element!==void 0||m[m.length-1].route.Component!==void 0||m[m.length-1].route.lazy!==void 0,`Matched leaf route at location "${d.pathname}${d.search}${d.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`);let h=wt(m&&m.map(e=>Object.assign({},e,{params:Object.assign({},o,e.params),pathname:Me([c,r.encodeLocation?r.encodeLocation(e.pathname.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathname]),pathnameBase:e.pathnameBase===`/`?c:Me([c,r.encodeLocation?r.encodeLocation(e.pathnameBase.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathnameBase])})),i,n);return t&&h?g.createElement(et.Provider,{value:{location:{pathname:`/`,search:``,hash:``,state:null,key:`default`,mask:void 0,...d},navigationType:`POP`}},h):h}function vt(){let e=jt(),t=Re(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,r=`rgba(200,200,200, 0.5)`,i={padding:`0.5rem`,backgroundColor:r},a={padding:`2px 4px`,backgroundColor:r},o=null;return console.error(`Error handled by React Router default ErrorBoundary:`,e),o=g.createElement(g.Fragment,null,g.createElement(`p`,null,`💿 Hey developer 👋`),g.createElement(`p`,null,`You can provide a way better UX than this when your app throws errors by providing your own `,g.createElement(`code`,{style:a},`ErrorBoundary`),` or`,` `,g.createElement(`code`,{style:a},`errorElement`),` prop on your route.`)),g.createElement(g.Fragment,null,g.createElement(`h2`,null,`Unexpected Application Error!`),g.createElement(`h3`,{style:{fontStyle:`italic`}},t),n?g.createElement(`pre`,{style:i},n):null,o)}var yt=g.createElement(vt,null),bt=class extends g.Component{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,t){return t.location!==e.location||t.revalidation!==`idle`&&e.revalidation===`idle`?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error===void 0?t.error:e.error,location:t.location,revalidation:e.revalidation||t.revalidation}}componentDidCatch(e,t){this.props.onError?this.props.onError(e,t):console.error(`React Router caught the following error during render`,e)}render(){let e=this.state.error;if(this.context&&typeof e==`object`&&e&&`digest`in e&&typeof e.digest==`string`){let t=st(e.digest);t&&(e=t)}let t=e===void 0?this.props.children:g.createElement(tt.Provider,{value:this.props.routeContext},g.createElement(nt.Provider,{value:e,children:this.props.component}));return this.context?g.createElement(St,{error:e},t):t}};bt.contextType=Je;var xt=new WeakMap;function St({children:e,error:t}){let{basename:n}=g.useContext($e);if(typeof t==`object`&&t&&`digest`in t&&typeof t.digest==`string`){let e=ot(t.digest);if(e){let r=xt.get(t);if(r)throw r;let i=Ve(e.location,n),a=i.absoluteURL||i.to;if(Ge(a))throw Error(`Invalid redirect location`);if(Be&&!xt.get(t)){if(i.isExternal||e.reloadDocument)window.location.href=a;else{let n=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(i.to,{replace:e.replace}));throw xt.set(t,n),n}}return g.createElement(`meta`,{httpEquiv:`refresh`,content:`0;url=${a}`})}}return e}function Ct({routeContext:e,match:t,children:n}){let r=g.useContext(Ke);return r&&r.static&&r.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(r.staticContext._deepestRenderedBoundaryId=t.route.id),g.createElement(tt.Provider,{value:e},n)}function wt(e,t=[],n){let r=n?.state;if(e==null){if(!r)return null;if(r.errors)e=r.matches;else if(t.length===0&&!r.initialized&&r.matches.length>0)e=r.matches;else return null}let i=e,a=r?.errors;if(a!=null){let e=i.findIndex(e=>e.route.id&&a?.[e.route.id]!==void 0);E(e>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(a).join(`,`)}`),i=i.slice(0,Math.min(i.length,e+1))}let o=!1,s=-1;if(n&&r){o=r.renderFallback;for(let e=0;e<i.length;e++){let t=i[e];if((t.route.HydrateFallback||t.route.hydrateFallbackElement)&&(s=e),t.route.id){let{loaderData:e,errors:a}=r,c=t.route.loader&&!e.hasOwnProperty(t.route.id)&&(!a||a[t.route.id]===void 0);if(t.route.lazy||c){n.isStatic&&(o=!0),i=s>=0?i.slice(0,s+1):[i[0]];break}}}}let c=n?.onError,l=r&&c?(e,t)=>{c(e,{location:r.location,params:r.matches?.[0]?.params??{},pattern:ze(r.matches),errorInfo:t})}:void 0;return i.reduceRight((e,n,c)=>{let u,d=!1,f=null,p=null;r&&(u=a&&n.route.id?a[n.route.id]:void 0,f=n.route.errorElement||yt,o&&(s<0&&c===0?(Pt(`route-fallback`,!1,"No `HydrateFallback` element provided to render during initial hydration"),d=!0,p=null):s===c&&(d=!0,p=n.route.hydrateFallbackElement||null)));let m=t.concat(i.slice(0,c+1)),h=()=>{let t;return t=u?f:d?p:n.route.Component?g.createElement(n.route.Component,null):n.route.element?n.route.element:e,g.createElement(Ct,{match:n,routeContext:{outlet:e,matches:m,isDataRoute:r!=null},children:t})};return r&&(n.route.ErrorBoundary||n.route.errorElement||c===0)?g.createElement(bt,{location:r.location,revalidation:r.revalidation,component:f,error:u,children:h(),routeContext:{outlet:null,matches:m,isDataRoute:!0},onError:l}):h()},null)}function Tt(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Et(e){let t=g.useContext(Ke);return E(t,Tt(e)),t}function Dt(e){let t=g.useContext(qe);return E(t,Tt(e)),t}function Ot(e){let t=g.useContext(tt);return E(t,Tt(e)),t}function kt(e){let t=Ot(e),n=t.matches[t.matches.length-1];return E(n.route.id,`${e} can only be used on routes that contain a unique "id"`),n.route.id}function At(){return kt(`useRouteId`)}function jt(){let e=g.useContext(nt),t=Dt(`useRouteError`),n=kt(`useRouteError`);return e===void 0?t.errors?.[n]:e}function Mt(){let{router:e}=Et(`useNavigate`),t=kt(`useNavigate`),n=g.useRef(!1);return ft(()=>{n.current=!0}),g.useCallback(async(r,i={})=>{D(n.current,dt),n.current&&(typeof r==`number`?await e.navigate(r):await e.navigate(r,{fromRouteId:t,...i}))},[e,t])}var Nt={};function Pt(e,t,n){!t&&!Nt[e]&&(Nt[e]=!0,D(!1,n))}g.memo(Ft);function Ft({routes:e,manifest:t,future:n,state:r,isStatic:i,onError:a}){return _t(e,void 0,{manifest:t,state:r,isStatic:i,onError:a,future:n})}function N(e){E(!1,`A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.`)}function It({basename:e=`/`,children:t=null,location:n,navigationType:r=`POP`,navigator:i,static:a=!1,useTransitions:o}){E(!lt(),`You cannot render a <Router> inside another <Router>. You should never have more than one in your app.`);let s=e.replace(/^\/*/,`/`),c=g.useMemo(()=>({basename:s,navigator:i,static:a,useTransitions:o,future:{}}),[s,i,a,o]);typeof n==`string`&&(n=A(n));let{pathname:l=`/`,search:u=``,hash:d=``,state:f=null,key:p=`default`,mask:m}=n,h=g.useMemo(()=>{let e=we(l,s);return e==null?null:{location:{pathname:e,search:u,hash:d,state:f,key:p,mask:m},navigationType:r}},[s,l,u,d,f,p,r,m]);return D(h!=null,`<Router basename="${s}"> is not able to match the URL "${l}${u}${d}" because it does not start with the basename, so the <Router> won't render anything.`),h==null?null:g.createElement($e.Provider,{value:c},g.createElement(et.Provider,{children:t,value:h}))}function Lt({children:e,location:t}){return gt(Rt(e),t)}g.Component;function Rt(e,t=[]){let n=[];return g.Children.forEach(e,(e,r)=>{if(!g.isValidElement(e))return;let i=[...t,r];if(e.type===g.Fragment){n.push.apply(n,Rt(e.props.children,i));return}E(e.type===N,`[${typeof e.type==`string`?e.type:e.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`),E(!e.props.index||!e.props.children,`An index route cannot have child routes.`);let a={id:e.props.id||i.join(`-`),caseSensitive:e.props.caseSensitive,element:e.props.element,Component:e.props.Component,index:e.props.index,path:e.props.path,middleware:e.props.middleware,loader:e.props.loader,action:e.props.action,hydrateFallbackElement:e.props.hydrateFallbackElement,HydrateFallback:e.props.HydrateFallback,errorElement:e.props.errorElement,ErrorBoundary:e.props.ErrorBoundary,hasErrorBoundary:e.props.hasErrorBoundary===!0||e.props.ErrorBoundary!=null||e.props.errorElement!=null,shouldRevalidate:e.props.shouldRevalidate,handle:e.props.handle,lazy:e.props.lazy};e.props.children&&(a.children=Rt(e.props.children,i)),n.push(a)}),n}var zt=`get`,Bt=`application/x-www-form-urlencoded`;function Vt(e){return typeof HTMLElement<`u`&&e instanceof HTMLElement}function Ht(e){return Vt(e)&&e.tagName.toLowerCase()===`button`}function Ut(e){return Vt(e)&&e.tagName.toLowerCase()===`form`}function Wt(e){return Vt(e)&&e.tagName.toLowerCase()===`input`}function Gt(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function Kt(e,t){return e.button===0&&(!t||t===`_self`)&&!Gt(e)}function qt(e=``){return new URLSearchParams(typeof e==`string`||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map(e=>[n,e]):[[n,r]])},[]))}function P(e,t){let n=qt(e);return t&&t.forEach((e,r)=>{n.has(r)||t.getAll(r).forEach(e=>{n.append(r,e)})}),n}var Jt=null;function Yt(){if(Jt===null)try{new FormData(document.createElement(`form`),0),Jt=!1}catch{Jt=!0}return Jt}var Xt=new Set([`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`]);function Zt(e){return e!=null&&!Xt.has(e)?(D(!1,`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${Bt}"`),null):e}function Qt(e,t){let n,r,i,a,o;if(Ut(e)){let o=e.getAttribute(`action`);r=o?we(o,t):null,n=e.getAttribute(`method`)||zt,i=Zt(e.getAttribute(`enctype`))||Bt,a=new FormData(e)}else if(Ht(e)||Wt(e)&&(e.type===`submit`||e.type===`image`)){let o=e.form;if(o==null)throw Error(`Cannot submit a <button> or <input type="submit"> without a <form>`);let s=e.getAttribute(`formaction`)||o.getAttribute(`action`);if(r=s?we(s,t):null,n=e.getAttribute(`formmethod`)||o.getAttribute(`method`)||zt,i=Zt(e.getAttribute(`formenctype`))||Zt(o.getAttribute(`enctype`))||Bt,a=new FormData(o,e),!Yt()){let{name:t,type:n,value:r}=e;if(n===`image`){let e=t?`${t}.`:``;a.append(`${e}x`,`0`),a.append(`${e}y`,`0`)}else t&&a.append(t,r)}}else if(Vt(e))throw Error(`Cannot submit element that is not <form>, <button>, or <input type="submit|image">`);else n=zt,r=null,i=Bt,o=e;return a&&i===`text/plain`&&(o=a,a=void 0),{action:r,method:n.toLowerCase(),encType:i,formData:a,body:o}}Object.getOwnPropertyNames(Object.prototype).sort().join(`\0`);function $t(e,t){if(e===!1||e==null)throw Error(t)}function en(e,t,n,r){let i=typeof e==`string`?new URL(e,typeof window>`u`?`server://singlefetch/`:window.location.origin):e;return i.pathname=n?i.pathname.endsWith(`/`)?`${i.pathname}_.${r}`:`${i.pathname}.${r}`:i.pathname===`/`?`_root.${r}`:t&&we(i.pathname,t)===`/`?`${Ne(t)}/_root.${r}`:`${Ne(i.pathname)}.${r}`,i}async function tn(e,t){if(e.id in t)return t[e.id];try{let n=await x(()=>import(e.module),[]);return t[e.id]=n,n}catch(t){return console.error(`Error loading route module \`${e.module}\`, reloading page...`),console.error(t),window.__reactRouterContext&&window.__reactRouterContext.isSpaMode,window.location.reload(),new Promise(()=>{})}}function nn(e){return e!=null&&typeof e.page==`string`}function rn(e){return e==null?!1:e.href==null?e.rel===`preload`&&typeof e.imageSrcSet==`string`&&typeof e.imageSizes==`string`:typeof e.rel==`string`&&typeof e.href==`string`}async function an(e,t,n){return un((await Promise.all(e.map(async e=>{let r=t.routes[e.route.id];if(r){let e=await tn(r,n);return e.links?e.links():[]}return[]}))).flat(1).filter(rn).filter(e=>e.rel===`stylesheet`||e.rel===`preload`).map(e=>e.rel===`stylesheet`?{...e,rel:`prefetch`,as:`style`}:{...e,rel:`prefetch`}))}function on(e,t,n,r,i,a){let o=(e,t)=>!n[t]||e.route.id!==n[t].route.id,s=(e,t)=>n[t].pathname!==e.pathname||n[t].route.path?.endsWith(`*`)&&n[t].params[`*`]!==e.params[`*`];return a===`assets`?t.filter((e,t)=>o(e,t)||s(e,t)):a===`data`?t.filter((t,a)=>{let c=r.routes[t.route.id];if(!c||!c.hasLoader)return!1;if(o(t,a)||s(t,a))return!0;if(t.route.shouldRevalidate){let r=t.route.shouldRevalidate({currentUrl:new URL(i.pathname+i.search+i.hash,window.origin),currentParams:n[0]?.params||{},nextUrl:new URL(e,window.origin),nextParams:t.params,defaultShouldRevalidate:!0});if(typeof r==`boolean`)return r}return!0}):[]}function sn(e,t,{includeHydrateFallback:n}={}){return cn(e.map(e=>{let r=t.routes[e.route.id];if(!r)return[];let i=[r.module];return r.clientActionModule&&(i=i.concat(r.clientActionModule)),r.clientLoaderModule&&(i=i.concat(r.clientLoaderModule)),n&&r.hydrateFallbackModule&&(i=i.concat(r.hydrateFallbackModule)),r.imports&&(i=i.concat(r.imports)),i}).flat(1))}function cn(e){return[...new Set(e)]}function ln(e){let t={},n=Object.keys(e).sort();for(let r of n)t[r]=e[r];return t}function un(e,t){let n=new Set,r=new Set(t);return e.reduce((e,i)=>{if(t&&!nn(i)&&i.as===`script`&&i.href&&r.has(i.href))return e;let a=JSON.stringify(ln(i));return n.has(a)||(n.add(a),e.push({key:a,link:i})),e},[])}function dn(){let e=g.useContext(Ke);return $t(e,`You must render this element inside a <DataRouterContext.Provider> element`),e}function fn(){let e=g.useContext(qe);return $t(e,`You must render this element inside a <DataRouterStateContext.Provider> element`),e}var pn=g.createContext(void 0);pn.displayName=`FrameworkContext`;function mn(){let e=g.useContext(pn);return $t(e,`You must render this element inside a <HydratedRouter> element`),e}function hn(e,t){let n=g.useContext(pn),[r,i]=g.useState(!1),[a,o]=g.useState(!1),{onFocus:s,onBlur:c,onMouseEnter:l,onMouseLeave:u,onTouchStart:d}=t,f=g.useRef(null);g.useEffect(()=>{if(e===`render`&&o(!0),e===`viewport`){let e=new IntersectionObserver(e=>{e.forEach(e=>{o(e.isIntersecting)})},{threshold:.5});return f.current&&e.observe(f.current),()=>{e.disconnect()}}},[e]),g.useEffect(()=>{if(r){let e=setTimeout(()=>{o(!0)},100);return()=>{clearTimeout(e)}}},[r]);let p=()=>{i(!0)},m=()=>{i(!1),o(!1)};return n?e===`intent`?[a,f,{onFocus:gn(s,p),onBlur:gn(c,m),onMouseEnter:gn(l,p),onMouseLeave:gn(u,m),onTouchStart:gn(d,p)}]:[a,f,{}]:[!1,f,{}]}function gn(e,t){return n=>{e&&e(n),n.defaultPrevented||t(n)}}function _n({page:e,...t}){let n=Ye(),{nonce:r}=mn(),{router:i}=dn(),a=g.useMemo(()=>ae(i.routes,e,i.basename),[i.routes,e,i.basename]);return a?(t.nonce==null&&r&&(t={...t,nonce:r}),n?g.createElement(yn,{page:e,matches:a,...t}):g.createElement(bn,{page:e,matches:a,...t})):null}function vn(e){let{manifest:t,routeModules:n}=mn(),[r,i]=g.useState([]);return g.useEffect(()=>{let r=!1;return an(e,t,n).then(e=>{r||i(e)}),()=>{r=!0}},[e,t,n]),r}function yn({page:e,matches:t,...n}){let r=ut(),{future:i}=mn(),{basename:a}=dn(),o=g.useMemo(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=en(e,a,i.v8_trailingSlashAwareDataRequests,`rsc`),o=!1,s=[];for(let e of t)typeof e.route.shouldRevalidate==`function`?o=!0:s.push(e.route.id);return o&&s.length>0&&n.searchParams.set(`_routes`,s.join(`,`)),[n.pathname+n.search]},[a,i.v8_trailingSlashAwareDataRequests,e,r,t]);return g.createElement(g.Fragment,null,o.map(e=>g.createElement(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})))}function bn({page:e,matches:t,...n}){let r=ut(),{future:i,manifest:a,routeModules:o}=mn(),{basename:s}=dn(),{loaderData:c,matches:l}=fn(),u=g.useMemo(()=>on(e,t,l,a,r,`data`),[e,t,l,a,r]),d=g.useMemo(()=>on(e,t,l,a,r,`assets`),[e,t,l,a,r]),f=g.useMemo(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=new Set,l=!1;if(t.forEach(e=>{let t=a.routes[e.route.id];!t||!t.hasLoader||(!u.some(t=>t.route.id===e.route.id)&&e.route.id in c&&o[e.route.id]?.shouldRevalidate||t.hasClientLoader?l=!0:n.add(e.route.id))}),n.size===0)return[];let d=en(e,s,i.v8_trailingSlashAwareDataRequests,`data`);return l&&n.size>0&&d.searchParams.set(`_routes`,t.filter(e=>n.has(e.route.id)).map(e=>e.route.id).join(`,`)),[d.pathname+d.search]},[s,i.v8_trailingSlashAwareDataRequests,c,r,a,u,t,e,o]),p=g.useMemo(()=>sn(d,a),[d,a]),m=vn(d);return g.createElement(g.Fragment,null,f.map(e=>g.createElement(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})),p.map(e=>g.createElement(`link`,{key:e,rel:`modulepreload`,href:e,...n})),m.map(({key:e,link:t})=>g.createElement(`link`,{key:e,nonce:n.nonce,...t,crossOrigin:t.crossOrigin??n.crossOrigin})))}function xn(...e){return t=>{e.forEach(e=>{typeof e==`function`?e(t):e!=null&&(e.current=t)})}}g.Component;var Sn=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;try{Sn&&(window.__reactRouterVersion=`7.18.2`)}catch{}function Cn({basename:e,children:t,useTransitions:n,window:r}){let i=g.useRef();i.current??=te({window:r,v5Compat:!0});let a=i.current,[o,s]=g.useState({action:a.action,location:a.location}),c=g.useCallback(e=>{n===!1?s(e):g.startTransition(()=>s(e))},[n]);return g.useLayoutEffect(()=>a.listen(c),[a,c]),g.createElement(It,{basename:e,children:t,location:o.location,navigationType:o.action,navigator:a,useTransitions:n})}var wn=g.forwardRef(function({onClick:e,discover:t=`render`,prefetch:n=`none`,relative:r,reloadDocument:i,replace:a,mask:o,state:s,target:c,to:l,preventScrollReset:u,viewTransition:d,defaultShouldRevalidate:f,...p},m){let{basename:h,navigator:_,useTransitions:v}=g.useContext($e),y=typeof l==`string`&&S.test(l),b=Ve(l,h);l=b.to;let x=ct(l,{relative:r}),C=ut(),w=null;if(o){let e=Ae(o,[],C.mask?C.mask.pathname:`/`,!0);h!==`/`&&(e.pathname=e.pathname===`/`?h:Me([h,e.pathname])),w=_.createHref(e)}let[T,ee,te]=hn(n,p),E=kn(l,{replace:a,mask:o,state:s,target:c,preventScrollReset:u,relative:r,viewTransition:d,defaultShouldRevalidate:f,useTransitions:v});function D(t){e&&e(t),t.defaultPrevented||E(t)}let O=!(b.isExternal||i),ne=g.createElement(`a`,{...p,...te,href:(O?w:void 0)||b.absoluteURL||x,onClick:O?D:e,ref:xn(m,ee),target:c,"data-discover":!y&&t===`render`?`true`:void 0});return T&&!y?g.createElement(g.Fragment,null,ne,g.createElement(_n,{page:x})):ne});wn.displayName=`Link`;var Tn=g.forwardRef(function({"aria-current":e=`page`,caseSensitive:t=!1,className:n=``,end:r=!1,style:i,to:a,viewTransition:o,children:s,...c},l){let u=ht(a,{relative:c.relative}),d=ut(),f=g.useContext(qe),{navigator:p,basename:m}=g.useContext($e),h=f!=null&&Fn(u)&&o===!0,_=p.encodeLocation?p.encodeLocation(u).pathname:u.pathname,v=d.pathname,y=f&&f.navigation&&f.navigation.location?f.navigation.location.pathname:null;t||(v=v.toLowerCase(),y=y?y.toLowerCase():null,_=_.toLowerCase()),y&&m&&(y=we(y,m)||y);let b=_!==`/`&&_.endsWith(`/`)?_.length-1:_.length,x=v===_||!r&&v.startsWith(_)&&v.charAt(b)===`/`,S=y!=null&&(y===_||!r&&y.startsWith(_)&&y.charAt(_.length)===`/`),C={isActive:x,isPending:S,isTransitioning:h},w=x?e:void 0,T;T=typeof n==`function`?n(C):[n,x?`active`:null,S?`pending`:null,h?`transitioning`:null].filter(Boolean).join(` `);let ee=typeof i==`function`?i(C):i;return g.createElement(wn,{...c,"aria-current":w,className:T,ref:l,style:ee,to:a,viewTransition:o},typeof s==`function`?s(C):s)});Tn.displayName=`NavLink`;var En=g.forwardRef(({discover:e=`render`,fetcherKey:t,navigate:n,reloadDocument:r,replace:i,state:a,method:o=zt,action:s,onSubmit:c,relative:l,preventScrollReset:u,viewTransition:d,defaultShouldRevalidate:f,...p},m)=>{let{useTransitions:h}=g.useContext($e),_=Nn(),v=Pn(s,{relative:l}),y=o.toLowerCase()===`get`?`get`:`post`,b=typeof s==`string`&&S.test(s);return g.createElement(`form`,{ref:m,method:y,action:v,onSubmit:r?c:e=>{if(c&&c(e),e.defaultPrevented)return;e.preventDefault();let r=e.nativeEvent.submitter,s=r?.getAttribute(`formmethod`)||o,p=()=>_(r||e.currentTarget,{fetcherKey:t,method:s,navigate:n,replace:i,state:a,relative:l,preventScrollReset:u,viewTransition:d,defaultShouldRevalidate:f});h&&n!==!1?g.startTransition(()=>p()):p()},...p,"data-discover":!b&&e===`render`?`true`:void 0})});En.displayName=`Form`;function Dn(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function On(e){let t=g.useContext(Ke);return E(t,Dn(e)),t}function kn(e,{target:t,replace:n,mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,defaultShouldRevalidate:c,useTransitions:l}={}){let u=pt(),d=ut(),f=ht(e,{relative:o});return g.useCallback(p=>{if(Kt(p,t)){p.preventDefault();let t=n===void 0?k(d)===k(f):n,m=()=>u(e,{replace:t,mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,defaultShouldRevalidate:c});l?g.startTransition(()=>m()):m()}},[d,u,f,n,r,i,t,e,a,o,s,c,l])}function An(e){D(typeof URLSearchParams<`u`,"You cannot use the `useSearchParams` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params.");let t=g.useRef(qt(e)),n=g.useRef(!1),r=ut(),i=g.useMemo(()=>P(r.search,n.current?null:t.current),[r.search]),a=pt();return[i,g.useCallback((e,t)=>{let r=qt(typeof e==`function`?e(new URLSearchParams(i)):e);n.current=!0,a(`?`+r,t)},[a,i])]}var jn=0,Mn=()=>`__${String(++jn)}__`;function Nn(){let{router:e}=On(`useSubmit`),{basename:t}=g.useContext($e),n=At(),r=e.fetch,i=e.navigate;return g.useCallback(async(e,a={})=>{let{action:o,method:s,encType:c,formData:l,body:u}=Qt(e,t);if(a.navigate===!1){let e=a.fetcherKey||Mn();await r(e,n,a.action||o,{defaultShouldRevalidate:a.defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,flushSync:a.flushSync})}else await i(a.action||o,{defaultShouldRevalidate:a.defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,replace:a.replace,state:a.state,fromRouteId:n,flushSync:a.flushSync,viewTransition:a.viewTransition})},[r,i,t,n])}function Pn(e,{relative:t}={}){let{basename:n}=g.useContext($e),r=g.useContext(tt);E(r,`useFormAction must be used inside a RouteContext`);let[i]=r.matches.slice(-1),a={...ht(e||`.`,{relative:t})},o=ut();if(e==null){a.search=o.search;let e=new URLSearchParams(a.search),t=e.getAll(`index`);if(t.some(e=>e===``)){e.delete(`index`),t.filter(e=>e).forEach(t=>e.append(`index`,t));let n=e.toString();a.search=n?`?${n}`:``}}return(!e||e===`.`)&&i.route.index&&(a.search=a.search?a.search.replace(/^\?/,`?index&`):`?index`),n!==`/`&&(a.pathname=a.pathname===`/`?n:Me([n,a.pathname])),k(a)}function Fn(e,{relative:t}={}){let n=g.useContext(Xe);E(n!=null,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:r}=On(`useViewTransitionState`),i=ht(e,{relative:t});if(!n.isTransitioning)return!1;let a=we(n.currentLocation.pathname,r)||n.currentLocation.pathname,o=we(n.nextLocation.pathname,r)||n.nextLocation.pathname;return be(i.pathname,o)!=null||be(i.pathname,a)!=null}function In(e,t=`default`){let[n,r]=(0,g.useState)(null);return(0,g.useEffect)(()=>{if(!e){r(null);return}let n=e.runtime(),i=n.runtime===`browser`?`browser`:n.runtime===`node`?`self-hosted`:`remote`;r({db:e,connected:!0,namespace:t,instanceId:e.instanceId?.()||`unknown`,environment:i})},[e,t]),n}function Ln(e,t){let[n,r]=(0,g.useState)([]),[i,a]=(0,g.useState)(!0),[o,s]=(0,g.useState)(null);return(0,g.useEffect)(()=>{if(e){a(!0),s(null);try{let n=e.collection(t).subscribe(e=>{r(e),a(!1)});return()=>n()}catch(e){s(e instanceof Error?e.message:`Failed to load collection`),a(!1)}}},[e,t]),{items:n,loading:i,error:o}}var Rn=o((e=>{var t=u(),n=Symbol.for(`react.element`),r=Symbol.for(`react.fragment`),i=Object.prototype.hasOwnProperty,a=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function s(e,t,r){var s,c={},l=null,u=null;for(s in r!==void 0&&(l=``+r),t.key!==void 0&&(l=``+t.key),t.ref!==void 0&&(u=t.ref),t)i.call(t,s)&&!o.hasOwnProperty(s)&&(c[s]=t[s]);if(e&&e.defaultProps)for(s in t=e.defaultProps,t)c[s]===void 0&&(c[s]=t[s]);return{$$typeof:n,type:e,key:l,ref:u,props:c,_owner:a.current}}e.Fragment=r,e.jsx=s,e.jsxs=s})),F=o(((e,t)=>{t.exports=Rn()}))();function zn({db:e,name:t,label:n}){let{items:r}=Ln(e,t);return r.length?(0,F.jsxs)(`section`,{children:[(0,F.jsxs)(`h2`,{children:[n,(0,F.jsx)(`span`,{children:r.length})]}),(0,F.jsx)(`div`,{className:`execution-list`,children:r.map((e,r)=>(0,F.jsxs)(`article`,{className:`execution-row`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`b`,{children:String(e.name??e.workflow??e.incident_id??e.id??n)}),(0,F.jsx)(`small`,{children:t})]}),(0,F.jsx)(`span`,{className:`event-pill put`,children:String(e.status??e.state??`materialized`)}),(0,F.jsx)(`pre`,{children:JSON.stringify(e,null,2)})]},String(e.id??r)))})]}):null}function Bn({db:e,model:t}){return(0,F.jsxs)(`div`,{className:`studio-model-page`,children:[(0,F.jsxs)(`header`,{children:[(0,F.jsx)(`span`,{className:`eyebrow`,children:`Observe`}),(0,F.jsx)(`h1`,{children:`Executions`}),(0,F.jsx)(`p`,{children:`Capability work, workflow runs, assignments, and agent decisions as inspectable state.`})]}),(0,F.jsxs)(`div`,{className:`model-summary`,children:[(0,F.jsxs)(`span`,{children:[t?.workflows.length??0,` workflow definitions`]}),(0,F.jsxs)(`span`,{children:[t?.agents.length??0,` autonomous agents`]})]}),(0,F.jsx)(zn,{db:e??null,name:`_flow_executions`,label:`Capability executions`}),(0,F.jsx)(zn,{db:e??null,name:`_flow_workflow_runs`,label:`Workflow runs`}),(0,F.jsx)(zn,{db:e??null,name:`Assignment`,label:`Materialized assignments`}),(0,F.jsx)(zn,{db:e??null,name:`Decision`,label:`Agent decisions`}),(0,F.jsx)(zn,{db:e??null,name:`_flow_agent_executions`,label:`Agent executions`}),(0,F.jsxs)(`div`,{className:`model-empty execution-empty`,children:[`Execution sections appear as soon as their state is committed. Defined workflows: `,t?.workflows.map(e=>e.name).join(`, `)||`none`,`.`]})]})}function Vn({model:e}){let t=e?.workflows??[],[n,r]=(0,g.useState)(),i=t.find(e=>e.name===n)??t[0];return(0,F.jsxs)(`div`,{className:`studio-model-page`,children:[(0,F.jsxs)(`header`,{children:[(0,F.jsx)(`span`,{className:`eyebrow`,children:`Design`}),(0,F.jsx)(`h1`,{children:`Workflows`}),(0,F.jsx)(`p`,{children:`Durable state transitions declared by the application model.`})]}),(0,F.jsxs)(`div`,{className:`split-browser`,children:[(0,F.jsx)(`aside`,{children:t.map(e=>(0,F.jsxs)(`button`,{className:e.name===i?.name?`active`:``,onClick:()=>r(e.name),children:[(0,F.jsx)(`strong`,{children:e.name}),(0,F.jsxs)(`span`,{children:[e.steps.length,` steps`]})]},e.name))}),(0,F.jsx)(`section`,{children:i?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`div`,{className:`card-kind`,children:`workflow`}),(0,F.jsx)(`h2`,{children:i.name}),i.parameters.length>0&&(0,F.jsxs)(`code`,{className:`signature`,children:[`(`,i.parameters,`)`]}),(0,F.jsx)(`div`,{className:`workflow-track`,children:i.steps.map((e,t)=>(0,F.jsxs)(g.Fragment,{children:[(0,F.jsxs)(`article`,{children:[(0,F.jsx)(`span`,{children:t+1}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`strong`,{children:e.name}),e.statements.map(e=>(0,F.jsx)(`code`,{children:e},e))]})]}),t<i.steps.length-1&&(0,F.jsx)(`i`,{children:`→`})]},e.name))})]}):(0,F.jsx)(`div`,{className:`model-empty`,children:`No workflows are declared.`})})]})]})}function Hn({model:e}){let t=e?.agents??[],[n,r]=(0,g.useState)(),i=t.find(e=>e.name===n)??t[0];return(0,F.jsxs)(`div`,{className:`studio-model-page`,children:[(0,F.jsxs)(`header`,{children:[(0,F.jsx)(`span`,{className:`eyebrow`,children:`Design`}),(0,F.jsx)(`h1`,{children:`Agents`}),(0,F.jsx)(`p`,{children:`Autonomous participants whose authority and workflows are part of the model.`})]}),(0,F.jsxs)(`div`,{className:`split-browser`,children:[(0,F.jsx)(`aside`,{children:t.map(e=>(0,F.jsxs)(`button`,{className:e.name===i?.name?`active`:``,onClick:()=>r(e.name),children:[(0,F.jsx)(`strong`,{children:e.name}),(0,F.jsxs)(`span`,{children:[e.statements.length,` bindings`]})]},e.name))}),(0,F.jsx)(`section`,{children:i?(0,F.jsx)(F.Fragment,{children:(0,F.jsxs)(`div`,{className:`agent-orbit`,children:[(0,F.jsxs)(`div`,{className:`agent-core`,children:[(0,F.jsx)(`span`,{children:`agent`}),(0,F.jsx)(`strong`,{children:i.name})]}),i.statements.map(e=>(0,F.jsxs)(`div`,{className:`agent-binding`,children:[(0,F.jsx)(`span`,{children:e.split(` `)[0]}),(0,F.jsx)(`strong`,{children:e.split(` `).slice(1).join(` `)})]},e))]})}):(0,F.jsx)(`div`,{className:`model-empty`,children:`No agents are declared.`})})]})]})}function Un(e){return e===`node`?`Node.js`:e===`browser`?`Browser`:e===`self-hosted`?`Self-hosted`:e===`managed`?`Managed`:e===`remote`?`Remote`:e||`unavailable`}function Wn({db:e,remoteUrl:t=``,token:n=``,applicationUrl:r=``,feltDBRuntime:i,authorityUrl:a=``,onConnect:o}){let[s,c]=(0,g.useState)(t),[l,u]=(0,g.useState)(n),d=e?.runtime();return(0,g.useEffect)(()=>{c(t),u(n)},[t,n]),(0,F.jsxs)(`div`,{className:`settings-panel`,children:[(0,F.jsx)(`h2`,{children:`Settings`}),(0,F.jsxs)(`div`,{className:`settings-content`,children:[(0,F.jsx)(`h3`,{children:`Application`}),(0,F.jsx)(`div`,{className:`connection-info`,children:(0,F.jsxs)(`div`,{className:`info-row`,children:[(0,F.jsx)(`label`,{children:`URL`}),(0,F.jsx)(`span`,{children:r||`unavailable`})]})}),(0,F.jsx)(`h3`,{children:`FeltDB`}),(0,F.jsxs)(`div`,{className:`connection-info`,children:[(0,F.jsxs)(`div`,{className:`info-row`,children:[(0,F.jsx)(`label`,{children:`Runtime`}),(0,F.jsx)(`span`,{children:Un(i||d?.runtime)})]}),(0,F.jsxs)(`div`,{className:`info-row`,children:[(0,F.jsx)(`label`,{children:`Studio client backend`}),(0,F.jsx)(`span`,{children:d?.storage||`unavailable`})]}),(0,F.jsxs)(`div`,{className:`info-row`,children:[(0,F.jsx)(`label`,{children:`Authority`}),(0,F.jsx)(`span`,{children:a||t||`unavailable`})]}),(0,F.jsxs)(`div`,{className:`info-row`,children:[(0,F.jsx)(`label`,{children:`Instance ID`}),(0,F.jsx)(`span`,{className:`monospace`,children:e?.instanceId?.()||`unavailable`})]})]}),(0,F.jsxs)(`form`,{className:`connection-form`,onSubmit:e=>{e.preventDefault(),o?.(s,l)},children:[(0,F.jsxs)(`label`,{children:[`FeltDB authority endpoint`,(0,F.jsx)(`input`,{type:`url`,value:s,onChange:e=>c(e.target.value),placeholder:`https://your-authority.example.com`})]}),(0,F.jsxs)(`label`,{children:[`API token`,(0,F.jsx)(`input`,{type:`password`,value:l,onChange:e=>u(e.target.value),placeholder:`fdb_live_…`,autoComplete:`off`})]}),(0,F.jsx)(`p`,{children:`Tokens are kept in this browser session and are never written to the project.`}),(0,F.jsx)(`button`,{className:`btn btn-primary`,type:`submit`,children:`Connect Studio`})]})]})]})}function Gn({db:e,model:t,onSearch:n}){let[r,i]=(0,g.useState)(``),[a,o]=(0,g.useState)([]),s=e=>{i(e),n&&n(e)};return(0,g.useEffect)(()=>{let n=!0;return(async()=>{let i=r.trim().toLowerCase();if(!i){o([]);return}let a=[...t?.collections.map(e=>({kind:`collection`,name:e.name,detail:`${e.fields.length} fields`}))??[],...t?.capabilities.map(e=>({kind:`capability`,name:e.name,detail:e.statements.join(` · `)}))??[],...t?.workflows.map(e=>({kind:`workflow`,name:e.name,detail:`${e.steps.length} steps`}))??[],...t?.agents.map(e=>({kind:`agent`,name:e.name,detail:e.statements.join(` · `)}))??[]].filter(e=>JSON.stringify(e).toLowerCase().includes(i)),s=e&&t?(await Promise.all(t.collections.map(async t=>(await e.collection(t.name).all()).filter(e=>JSON.stringify(e).toLowerCase().includes(i)).slice(0,3).map(e=>({kind:`object`,name:`${t.name}/${String(e.id??`record`)}`,detail:JSON.stringify(e)}))))).flat():[];n&&o([...a,...s].slice(0,12))})(),()=>{n=!1}},[e,t,r]),(0,F.jsxs)(`div`,{className:`global-search`,children:[(0,F.jsx)(`input`,{type:`text`,placeholder:`Search: documents/123, flow://, agent/name, etc.`,value:r,onChange:e=>s(e.target.value),className:`search-input global`}),r&&(0,F.jsx)(`div`,{className:`search-results`,children:(0,F.jsxs)(`div`,{className:`results-group`,children:[(0,F.jsx)(`h4`,{children:`Model & runtime`}),a.map((e,t)=>(0,F.jsxs)(`div`,{className:`search-result`,children:[(0,F.jsx)(`b`,{children:e.name}),(0,F.jsx)(`span`,{children:e.kind}),(0,F.jsx)(`small`,{children:e.detail})]},`${e.kind}-${e.name}-${t}`)),!a.length&&(0,F.jsx)(`div`,{className:`empty-message`,children:`No matches`})]})})]})}var Kn=Object.freeze({domain:`undeclared`,validation:`refresh`,invalidation:!1,reason:`the runtime does not declare a freshness capability`}),qn=class extends Error{constructor(e){super(e),this.name=`FreshnessContractViolation`}};function Jn(e,t){let n=typeof t.revision==`function`;if(e.validation===`revision`){if(!n)throw new qn(`a runtime advertising revision validation must implement revision()`);if(!e.revisionScope)throw new qn(`a runtime advertising revision validation must name the scope its revisions are comparable within`);if(e.domain===`replicated`||e.domain===`multi-process-file`)throw new qn(`the ${e.domain} domain has no serialization boundary that can make a scalar revision authoritative`);return e}if(!e.reason)throw new qn(`a runtime that cannot validate by revision must say why`);return e}async function Yn(e){return typeof e.freshness==`function`?Jn(await e.freshness(),e):Jn(Kn,e)}async function Xn(e){let t=await Yn(e);if(t.validation!==`revision`)throw new qn(`this runtime does not offer revision validation: ${t.reason}`);let n=await e.revision();if(n.scope!==t.revisionScope)throw new qn(`revision scope ${n.scope} does not match the advertised scope ${t.revisionScope}`);return n}function Zn(e,t){return e.scope===t.scope&&e.value===t.value}var Qn=class{dependencies=new Map;subscribers=new Map;recentChanges=new Map;registerDependency(e,t){this.dependencies.has(e)||this.dependencies.set(e,new Set),this.dependencies.get(e).add(t)}subscribe(e,t){this.subscribers.has(e)||this.subscribers.set(e,new Set);let n=this.subscribers.get(e);return n.add(t),()=>{n.delete(t),n.size===0&&this.subscribers.delete(e)}}async emitChange(e,t){this.recentChanges.has(e)||this.recentChanges.set(e,[]),this.recentChanges.get(e).push(t);let n=this.subscribers.get(e);n&&await Promise.all([...n].map(e=>e(t)));let r=this.dependencies.get(e);if(r)for(let e of r)await this.emitChange(e,t)}getRecentChanges(e){return this.recentChanges.get(e)||[]}clearRecentChanges(e){this.recentChanges.delete(e)}getSubscriberCount(e){return this.subscribers.get(e)?.size??0}hasDependents(e){let t=this.dependencies.get(e);return t!==void 0&&t.size>0}getDependents(e){let t=this.dependencies.get(e);return t?Array.from(t):[]}},$n=null;function er(){return $n||=new Qn,$n}var tr=1e3,nr=/^[A-Za-z0-9._-]{1,128}$/;function rr(e){if(!e||typeof e!=`object`)throw Error(`a read set is required`);let t=new Map;for(let n of e.records??[]){let e=String(n?.collection??``),r=String(n?.id??``);if(!nr.test(e)||!nr.test(r))throw Error(`invalid read ${e}:${r}`);t.set(`${e}:${r}`,{collection:e,id:r})}let n=new Map;for(let t of e.predicates??[]){let e=String(t?.collection??``);if(!nr.test(e))throw Error(`invalid predicate collection ${e}`);if(!Array.isArray(t.where)||t.where.length===0)throw Error(`a predicate over ${e} must name at least one field; a whole-collection read is not a narrow fence`);let r=t.where.map(t=>{if(typeof t?.field!=`string`||!t.field||!(`eq`in t))throw Error(`a predicate over ${e} takes { field, eq } conditions`);return{field:t.field,eq:t.eq}}).sort((e,t)=>e.field<t.field?-1:+(e.field>t.field));n.set(`${e}\u0000${JSON.stringify(r)}`,{collection:e,where:r})}if(t.size+n.size===0)throw Error(`a read set that names nothing fences nothing`);if(t.size+n.size>1e3)throw Error(`a read set may name at most ${tr} records and predicates`);return{records:[...t.entries()].sort(([e],[t])=>e<t?-1:1).map(([,e])=>e),predicates:[...n.entries()].sort(([e],[t])=>e<t?-1:1).map(([,e])=>e)}}var ir=class extends Error{transactionId;code;status;constructor(e,t,n,r,i){super(e,{cause:i}),this.name=`AtomicTransactionError`,this.transactionId=t,this.code=n,this.status=r}},ar=class extends ir{code=`PRECONDITION_FAILED`;failure;constructor(e,t,n){super(e,t),this.name=`ConditionalConflictError`,this.failure=n}};function or(e){let t=e;if(!t||typeof t!=`object`)return{conflict:!1};if(t.feltdbCode===`PRECONDITION_FAILED`)return{conflict:!0,failure:t.feltdbConflict};let n=t.feltdbCode??t.code;return t.status===409&&(n===`PRECONDITION_FAILED`||n===`CONFLICT`)?{conflict:!0,failure:t.feltdbConflict}:{conflict:!1}}function sr(e){let{ifVersion:t,expectedVersion:n,...r}=e;if(t!==void 0&&n!==void 0&&t!==n)throw Error(`precondition on ${e.collection}:${e.id} supplies ifVersion ${t} and expectedVersion ${n}; they are the same predicate`);let i=t??n;return i===void 0?{...r}:{...r,expectedVersion:i}}function cr(){let e=Math.random().toString(36).slice(2,10);return`tx_${Date.now().toString(36)}_${e}`}var lr=class{transactionId;staged=[];required=[];fenced=[];sealed=!1;constructor(e){this.transactionId=e||cr()}get operations(){return this.staged}collection(e){if(!e||!e.trim())throw Error(`collection name is required`);let t=e=>{let{ifVersion:t,expectedVersion:n,...r}=e;if(t!==void 0&&n!==void 0&&t!==n)throw Error(`${e.collection}:${e.id} supplies ifVersion ${t} and expectedVersion ${n}; they are the same predicate`);let i=t??n,a=i===void 0?{...r}:{...r,expectedVersion:i};if(this.sealed)throw Error(`this transaction has already been committed; start a new one`);if(this.staged.find(e=>e.collection===a.collection&&e.id===a.id))throw Error(`transaction already stages ${a.collection}:${a.id}; a transaction may write each record at most once`);this.staged.push(a)},n={set:(r,i,a)=>(t({collection:e,id:String(r),value:i,requireAbsent:a?.requireAbsent,ifVersion:a?.ifVersion,expectedVersion:a?.expectedVersion,expectedEpoch:a?.expectedEpoch,expectedLeaseId:a?.expectedLeaseId}),n),insert:(e,t,r)=>n.set(t,e,r),delete:(r,i)=>(t({collection:e,id:String(r),requireAbsent:i?.requireAbsent,ifVersion:i?.ifVersion,expectedVersion:i?.expectedVersion,expectedEpoch:i?.expectedEpoch,expectedLeaseId:i?.expectedLeaseId}),n)};return n}get preconditions(){return this.required}require(e){if(this.sealed)throw Error(`this transaction has already been committed; start a new one`);if(!e.collection?.trim()||!String(e.id??``).trim())throw Error(`a precondition requires a collection and an id`);let t=sr(e);if(t.requireAbsent!==!0&&t.expectedVersion===void 0&&t.expectedEpoch===void 0&&t.expectedLeaseId===void 0)throw Error(`precondition on ${e.collection}:${e.id} constrains nothing`);return this.required.push({...t,id:String(e.id)}),this}get fences(){return this.fenced}fence(e){if(this.sealed)throw Error(`this transaction has already been committed; start a new one`);if(!e||typeof e.token!=`string`||!e.token)throw Error(`a fence requires a read basis issued by db.readBasis()`);return this.fenced.push({reads:rr(e.reads),token:e.token}),this}seal(){return this.sealed=!0,{transactionId:this.transactionId,operations:[...this.staged],preconditions:[...this.required],...this.fenced.length?{fences:[...this.fenced]}:{}}}},ur=class{entries=new Map;field;stats={reads:0,writes:0,selectivity:0};constructor(e){this.field=e}add(e,t){let n=this.normalizeKey(t);this.entries.has(n)||this.entries.set(n,new Set),this.entries.get(n).add(e),this.stats.writes++}remove(e,t){let n=this.normalizeKey(t),r=this.entries.get(n);r&&(r.delete(e),r.size===0&&this.entries.delete(n)),this.stats.writes++}query(e){let t=this.normalizeKey(e);this.stats.reads++;let n=this.entries.get(t);return n?Array.from(n):[]}size(){return this.entries.size}getStats(){return{entries:this.entries.size,reads:this.stats.reads,writes:this.stats.writes,selectivity:this.entries.size>0?1/this.entries.size:0}}normalizeKey(e){return e==null?`__null__`:typeof e==`object`?JSON.stringify(e):String(e)}},dr=class{entries=[];field;stats={reads:0,writes:0,selectivity:0};constructor(e){this.field=e}add(e,t){let n=this.entries.find(e=>this.compareKeys(e.key,t)===0);n||(n={key:t,recordIds:new Set},this.entries.push(n),this.entries.sort((e,t)=>this.compareKeys(e.key,t.key))),n.recordIds.add(e),this.stats.writes++}remove(e,t){let n=this.entries.find(e=>this.compareKeys(e.key,t)===0);n&&(n.recordIds.delete(e),n.recordIds.size===0&&(this.entries=this.entries.filter(e=>e!==n))),this.stats.writes++}queryEqual(e){this.stats.reads++;let t=this.entries.find(t=>this.compareKeys(t.key,e)===0);return t?Array.from(t.recordIds):[]}queryRange(e,t,n=!0,r=!0){this.stats.reads++;let i=new Set;for(let a of this.entries){let o=this.compareKeys(a.key,e),s=this.compareKeys(a.key,t);(n?o>=0:o>0)&&(r?s<=0:s<0)&&a.recordIds.forEach(e=>i.add(e))}return Array.from(i)}size(){return this.entries.length}getStats(){return this.entries.reduce((e,t)=>e+t.recordIds.size,0),{entries:this.entries.length,reads:this.stats.reads,writes:this.stats.writes,selectivity:this.entries.length>0?1/this.entries.length:0}}compareKeys(e,t){return e==null?-1:t==null?1:e<t?-1:+(e>t)}},fr=class{tokenIndex=new Map;fields;stats={reads:0,writes:0,selectivity:0};constructor(e){this.fields=e}add(e,t){let n=this.extractText(t),r=this.tokenize(n);for(let t of r)this.tokenIndex.has(t)||this.tokenIndex.set(t,new Set),this.tokenIndex.get(t).add(e);this.stats.writes++}remove(e,t){let n=this.extractText(t),r=this.tokenize(n);for(let t of r){let n=this.tokenIndex.get(t);n&&(n.delete(e),n.size===0&&this.tokenIndex.delete(t))}this.stats.writes++}query(e){this.stats.reads++;let t=this.tokenize(e);if(t.length===0)return[];let n=this.tokenIndex.get(t[0]);if(!n)return[];n=new Set(n);for(let e=1;e<t.length;e++){let r=this.tokenIndex.get(t[e]);if(!r)return[];n=new Set([...n].filter(e=>r.has(e)))}return Array.from(n)}size(){return this.tokenIndex.size}getStats(){return{entries:this.tokenIndex.size,reads:this.stats.reads,writes:this.stats.writes,selectivity:this.tokenIndex.size>0?1/this.tokenIndex.size:0}}extractText(e){return this.fields.map(t=>{let n=e[t];return n?String(n):``}).join(` `)}tokenize(e){return e.toLowerCase().split(/\s+/).filter(e=>e.length>0)}},pr=class{indexes=new Map;config=new Map;indexStats=new Map;buildIndex(e){if(e.type===`hash`&&e.field)return new ur(e.field);if(e.type===`sorted`&&e.field)return new dr(e.field);if(e.type===`text`&&e.textFields)return new fr(e.textFields);throw Error(`Invalid index config: ${JSON.stringify(e)}`)}resetEntries(){for(let[e,t]of this.config){this.indexes.set(e,this.buildIndex(t));let n=this.indexStats.get(e);n&&(n.entries=0,n.size=0,n.lastUpdated=Date.now())}}createIndex(e){if(this.indexes.has(e.name))throw Error(`Index ${e.name} already exists`);let t=this.buildIndex(e);this.indexes.set(e.name,t),this.config.set(e.name,e),this.indexStats.set(e.name,{name:e.name,type:e.type,entries:0,size:0,lastUpdated:Date.now(),reads:0,writes:0,selectivity:0})}updateRecord(e,t,n){for(let[r,i]of this.indexes){let a=this.config.get(r);t&&(a.type===`hash`&&a.field||a.type===`sorted`&&a.field?i.remove(e,t[a.field]):a.type===`text`&&i.remove(e,t)),a.type===`hash`&&a.field||a.type===`sorted`&&a.field?i.add(e,n[a.field]):a.type===`text`&&i.add(e,n);let o=this.indexStats.get(r);o.lastUpdated=Date.now();let s=i.getStats();Object.assign(o,s)}}queryIndex(e,t){let n=this.indexes.get(e);if(!n)throw Error(`Index ${e} not found`);let r=this.config.get(e);if(r.type===`hash`)return n.query(t.value);if(r.type===`sorted`){let e=n;if(t.operator===`eq`)return e.queryEqual(t.value);if(t.operator===`range`)return e.queryRange(t.min,t.max);if(t.operator===`gte`)return e.queryRange(t.value,Number.MAX_VALUE);if(t.operator===`lte`)return e.queryRange(Number.MIN_VALUE,t.value)}else if(r.type===`text`)return n.query(t.value);return[]}listIndexes(){return Array.from(this.config.values())}getStats(e){return this.indexStats.get(e)||null}planQuery(e){let t=[];for(let n of e)for(let[e,r]of this.config)if(r.field===n||r.fields?.includes(n)){let n=this.indexStats.get(e);t.push({indexName:e,indexType:r.type,estimatedRows:Math.ceil(100/(n.selectivity||1)),cost:n.reads+n.writes,canPruneAll:r.type===`hash`,requiresPostFilter:r.type===`text`||r.type===`sorted`})}if(t.length===0)return{strategy:`full-scan`,indexes:[],estimatedRows:1e3,totalCost:1e3,explanation:`No suitable index found, using full collection scan`};t.sort((e,t)=>e.cost-t.cost);let n=t[0];return{strategy:`index-scan`,indexes:[n],estimatedRows:n.estimatedRows,totalCost:n.cost,explanation:`Using ${n.indexType} index on ${n.indexName}`}}},mr=null;async function hr(){if(mr!==null)return mr;try{let e=await x(()=>import(`./feltdb_wasm-DYfWAV0E.js`),[]);return mr=e,e}catch{return null}}var gr=class{tsBackend=null;wasmBackend=null;useWasm=!1;constructor(){this.tsBackend=new pr}async initializeWasm(){if(this.wasmBackend!==null)return;let e=await hr();if(e&&e.WasmIndexManager)try{this.wasmBackend=new e.WasmIndexManager,this.useWasm=!0}catch{this.useWasm=!1}}createIndex(e){if(this.useWasm&&this.wasmBackend)try{this.wasmBackend.create_index(JSON.stringify(e));return}catch{}this.tsBackend?.createIndex(e)}updateRecord(e,t,n){if(this.useWasm&&this.wasmBackend)try{let r=t?JSON.stringify(t):null,i=JSON.stringify(n);this.wasmBackend.update_record(e,r,i);return}catch{}this.tsBackend?.updateRecord(e,t,n)}resetEntries(){return this.useWasm&&this.wasmBackend?!1:(this.tsBackend?.resetEntries(),this.tsBackend!==null)}queryIndex(e,t){if(this.useWasm&&this.wasmBackend)try{let n=this.wasmBackend.query_index(e,t.operator,String(t.value||``));return JSON.parse(n)}catch{}return this.tsBackend?.queryIndex(e,t)||[]}queryCompoundIndex(e,t){if(this.useWasm&&this.wasmBackend)try{let n=Object.values(t).map(e=>String(e)).join(`\0`),r=this.wasmBackend.query_index(e,`eq`,n);return JSON.parse(r)}catch{}return[]}listIndexes(){if(this.useWasm&&this.wasmBackend)try{let e=this.wasmBackend.list_indexes();return JSON.parse(e)}catch{}return this.tsBackend?.listIndexes()||[]}},_r=class{db;collectionName;constructor(e,t){this.db=e,this.collectionName=t}async saveIndexConfig(e,t){let n=`__indexes__:${this.collectionName}:${e.name}`,r={config:e,version:1,createdAt:Date.now(),lastUpdated:Date.now(),entryCount:t},i=await this.db.insert(n,JSON.stringify(r));i.success||console.warn(`Failed to save index config for ${e.name}: ${i.error}`)}async loadIndexConfigs(){let e=await this.db.query(`__indexes__:${this.collectionName}`);if(!e.success||!e.data)return[];try{return JSON.parse(e.data).map(e=>e.config)}catch{return console.warn(`Failed to parse index configs for ${this.collectionName}`),[]}}async getIndexConfig(e){let t=`__indexes__:${this.collectionName}:${e}`,n=await this.db.get(t);if(!n.success||!n.data)return null;try{return JSON.parse(n.data).config}catch{return null}}async deleteIndexConfig(e){let t=`__indexes__:${this.collectionName}:${e}`;if(!this.db.delete){console.warn(`Failed to delete index config for ${e}: delete is not supported`);return}let n=this.db.delete(t),r=n instanceof Promise?await n:n;r?.success||console.warn(`Failed to delete index config for ${e}: ${r?.error}`)}async updateIndexStats(e,t){let n=`__indexes__:${this.collectionName}:${e}`,r=await this.db.get(n);if(!(!r.success||!r.data))try{let e=JSON.parse(r.data);e.lastUpdated=Date.now(),e.entryCount=t,await this.db.insert(n,JSON.stringify(e))}catch{console.warn(`Failed to update index stats for ${e}`)}}async getSnapshot(){let e=await this.loadIndexConfigs();return{collectionName:this.collectionName,indexes:e.map(e=>({config:e,version:1,createdAt:Date.now(),lastUpdated:Date.now(),entryCount:0})),timestamp:Date.now()}}};function vr(e){return`${e}-${typeof globalThis.crypto?.randomUUID==`function`?globalThis.crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}`}var yr=class e{db;name;collectionId;predicate=null;cache=[];subscribers=new Set;parent=null;parentId=null;isInitialized=!1;unsubscribeFunctions=new Set;graphUnsubscribe=null;runtimeUnsubscribe=null;indexBackend=new gr;declaredIndexes=new Map;indexStore;indexesLoaded=!1;cacheGeneration=0;indexedGeneration=-1;lastPlan=null;recordsById=null;lastRawSnapshot=null;cachedRevision=null;lastFreshness=null;constructor(e,t,n,r,i=!0){this.db=e,this.name=t,this.collectionId=`${t}-${Math.random().toString(36).substr(2,9)}`,this.predicate=n||null,this.parent=r||null,this.parentId=r?r.collectionId:null,this.indexStore=new _r(e,t),r&&er().registerDependency(r.collectionId,this.collectionId),i?this.loadPersistedIndexes():this.indexesLoaded=!0}async loadPersistedIndexes(){try{let e=await this.indexStore.loadIndexConfigs();for(let t of e)this.declaredIndexes.has(t.name)||(this.declaredIndexes.set(t.name,t),t.type!==`compound`&&this.indexBackend.createIndex(t));this.indexesLoaded=!0}catch(e){console.warn(`Failed to load persisted indexes for ${this.name}:`,e),this.indexesLoaded=!0}}async all(){return await this.refresh(),[...this.cache]}async list(){return this.all()}async find(e={},t){let n=Object.entries(e);if(t&&this.db.authority_query){let e=await this.db.authority_query({collection:this.name,where:n.map(([e,t])=>({field:e,eq:t})),orderBy:t.orderBy,limit:t.limit??100,cursor:t.cursor});return this.lastPlan={strategy:e.plan?.index?`index`:`scan`,...e.plan?.index?{indexName:e.plan.index}:{reason:`runtime reported no applicable index`},candidatesExamined:e.plan?.actual_rows_scanned??e.records.length,recordsReturned:e.records.length},e.records}if(n.length>0&&this.db.authority_query&&this.db.collection_queries_via_authority){let e=[],t,r=0,i;do{let a=await this.db.authority_query({collection:this.name,where:n.map(([e,t])=>({field:e,eq:t})),limit:100,...t?{cursor:t}:{}});e.push(...a.records),r+=a.plan?.actual_rows_scanned??a.records.length,i=a.plan?.index??i,t=a.nextCursor}while(t);return this.lastPlan={strategy:i?`index`:`scan`,...i?{indexName:i}:{reason:`server reported no applicable index`},candidatesExamined:r,recordsReturned:e.length},e}let r=await this.all();if(n.length===0)return this.lastPlan={strategy:`scan`,reason:`no query fields`,candidatesExamined:r.length,recordsReturned:r.length},r;let i=e=>n.every(([t,n])=>e[t]===n),a=this.indexFor(n);if(a){let e=this.indexCandidates(a.indexName,a.field,a.value);if(e){let t=e.filter(i);return this.lastPlan={strategy:`index`,indexName:a.indexName,field:a.field,candidatesExamined:e.length,recordsReturned:t.length},t}}let o=r.filter(i);return this.lastPlan={strategy:`scan`,reason:a?`index could not be trusted for this snapshot`:`no index covers the queried fields`,candidatesExamined:r.length,recordsReturned:o.length},o}async query(e={}){return this.find(e)}lastQueryPlan(){return this.lastPlan}indexFor(e){for(let t of this.indexBackend.listIndexes()){if(t.type!==`hash`||!t.field)continue;let n=e.find(([e])=>e===t.field);if(n)return{indexName:t.name,field:t.field,value:n[1]}}return null}indexCandidates(e,t,n){if(!this.ensureIndexReflectsCache())return null;let r;try{r=this.indexBackend.queryIndex(e,{field:t,operator:`eq`,value:n})}catch{return null}let i=[];for(let e of r){let t=this.recordsById?.get(e);if(t===void 0)return null;i.push(t)}return i}ensureIndexReflectsCache(){if(this.indexedGeneration===this.cacheGeneration)return this.recordsById!==null;if(!this.indexBackend.resetEntries())return this.recordsById=null,!1;let e=new Map;for(let t of this.cache){let n=t?.id;if(n==null)return this.recordsById=null,this.indexedGeneration=this.cacheGeneration,!1;let r=String(n);e.set(r,t),this.indexBackend.updateRecord(r,null,t)}return this.recordsById=e,this.indexedGeneration=this.cacheGeneration,!0}createIndex(e){if(this.declaredIndexes.has(e.name))throw Error(`Index ${e.name} already exists`);this.declaredIndexes.set(e.name,e),e.type!==`compound`&&this.indexBackend.createIndex(e);for(let e of this.cache){let t=e?.id||JSON.stringify(e);this.indexBackend.updateRecord(t,null,e)}this.indexStore.saveIndexConfig(e,this.cache.length)}listIndexes(){return[...this.declaredIndexes.values()]}async rebuildIndexes(){await this.db.rebuild_indexes?.();let e=this.indexBackend.listIndexes();if(e.length===0)return;let t=await this.all();for(let n of t){let t=n?.id||JSON.stringify(n);for(let r of e)this.indexBackend.updateRecord(t,null,n)}}async validateIndexes(){return this.listIndexes().length===0||(await this.all()).length,!0}async get(e){let t=`${this.name}:${e}`,n=await this.db.get(t);if(!n.success)throw Error(n.error||`Failed to read record ${e}`);return n.data?JSON.parse(n.data):null}where(t){return new e(this.db,this.name,e=>(!this.predicate||this.predicate(e))&&t(e),this.parent||this)}async insert(e,t){let n=t??`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,r=`${this.name}:${n}`,i=typeof e==`object`&&e?{...e,id:n,__version:1}:e,a=await this.db.insert(r,JSON.stringify(i));if(!a.success)throw Error(`Insert failed: ${a.error}`);this.indexBackend.updateRecord(String(n),null,i);let o={type:`insert`,key:r,value:i,timestamp:Date.now()};return await er().emitChange(this.name,o),String(n)}async put(e,t){return this.insert(e,t)}async update(e,t){let n=await this.get(e);if(!n)throw Error(`Record ${e} not found`);let r=(n.__version||1)+1,i={...n,...t,__version:r},a=`${this.name}:${e}`,o=await(this.db.update?this.db.update(a,JSON.stringify(i)):this.db.insert(a,JSON.stringify(i)));if(!o.success)throw Error(`Update failed: ${o.error}`);this.indexBackend.updateRecord(String(e),n,i);let s={type:`update`,key:a,value:i,timestamp:Date.now()};await er().emitChange(this.name,s)}async updateIfVersion(e,t,n,r,i,a,o){let s=o??await this.get(e);if(!s)throw Error(`Record ${e} not found`);let c={...n};delete c.__version;let l={...s,...c},u=`${this.name}:${e}`,d=this.db.cas?await this.db.cas({key:u,expectedVersion:t,expectedEpoch:r,expectedLeaseId:i,rejectIfDiverged:a,value:JSON.stringify(l)}):await this.updateIfVersionThroughTransaction(u,{expectedVersion:t,expectedEpoch:r,expectedLeaseId:i,rejectIfDiverged:a,value:l});if(!d.updated)return{updated:!1,currentVersion:d.currentVersion,conflictCode:d.conflictCode};let f=d.item?d.item:{...l,__version:d.currentVersion};this.indexBackend.updateRecord(String(e),s,f);let p={type:`update`,key:u,value:f,timestamp:Date.now()};return await er().emitChange(this.name,p),{updated:!0,item:f}}async delete(e){let t=`${this.name}:${e}`;if(!this.db.delete)throw Error(`Delete is not supported by this FeltDB runtime`);let n=await this.db.delete(t);if(!n.success)throw Error(`Delete failed: ${n.error}`);let r=await this.get(e);r&&this.indexBackend.updateRecord(String(e),r,{});let i={type:`delete`,key:t,value:null,timestamp:Date.now()};await er().emitChange(this.name,i)}async count(){return(await this.all()).length}async exists(e){return await this.get(e)!==null}addressOf(e){let t=e.indexOf(`:`);return{collection:e.slice(0,t),id:e.slice(t+1)}}async putIfAbsentThroughTransaction(e,t){let n=this.db.commit_transaction;if(!n)throw Error(`putIfAbsent is not supported by this FeltDB runtime. It provides neither durable atomic conditional creation nor an atomic transaction to carry the condition, and FeltDB will not emulate one with a read followed by a write.`);let{collection:r,id:i}=this.addressOf(e);try{await n.call(this.db,{transactionId:vr(`put-if-absent`),operations:[{collection:r,id:i,value:t,requireAbsent:!0}]})}catch(t){if(!or(t).conflict)throw t;let n=await this.db.get(e);if(!n.success)throw Error(n.error||`could not read the record that won ${e}`);if(!n.data)throw Error(`${e} was created and then removed while resolving a conditional create`);return{inserted:!1,value:n.data}}return{inserted:!0,value:JSON.stringify({...t,__version:1})}}async updateIfVersionThroughTransaction(e,t){let n=this.db.commit_transaction;if(!n)throw Error(`updateIfVersion is not supported by this FeltDB runtime. It provides neither atomic version-checked update nor an atomic transaction to carry the condition, and FeltDB will not emulate one with a read followed by a write.`);if(t.rejectIfDiverged)throw Error(`rejectIfDiverged is a replication predicate this runtime's transaction contract cannot express, so it is refused rather than silently dropped.`);let{collection:r,id:i}=this.addressOf(e),a={...t.value};delete a.__version;try{await n.call(this.db,{transactionId:vr(`update-if-version`),operations:[{collection:r,id:i,value:a,expectedVersion:t.expectedVersion,expectedEpoch:t.expectedEpoch,expectedLeaseId:t.expectedLeaseId}]})}catch(t){let n=or(t);if(!n.conflict)throw t;let r=n.failure,i=r?.predicate===`version`?`VERSION_CONFLICT`:r?.predicate===`epoch`?`AUTHORITY_CONFLICT`:r?.predicate===`lease`?`LEASE_CONFLICT`:r?.predicate===`missing`?`RECORD_MISSING`:void 0;if(r?.predicate===`version`&&typeof r.actual==`number`)return{updated:!1,currentVersion:r.actual,conflictCode:i};let a=await this.db.get(e),o=a.success&&a.data?JSON.parse(a.data):void 0;return{updated:!1,currentVersion:typeof o?.__version==`number`?o.__version:0,currentEpoch:o?.authority?.epoch,conflictCode:i}}let o=t.expectedVersion+1;return{updated:!0,currentVersion:o,currentEpoch:t.expectedEpoch,item:{...a,id:i,__version:o}}}async putIfAbsent(e,t){let n=`${this.name}:${e}`,r=typeof t==`object`&&t?{...t,id:e,__version:1}:t,i=JSON.stringify(r),a=this.db.putIfAbsent?await this.db.putIfAbsent(n,i):await this.putIfAbsentThroughTransaction(n,r);if(a.inserted){let e={type:`insert`,key:n,value:r,timestamp:Date.now()};await er().emitChange(this.name,e)}return{inserted:a.inserted,value:JSON.parse(a.value)}}subscribe(e,t){if(this.subscribers.add(e),this.isInitialized||this.refresh().catch(e=>console.error(`Failed to initialize collection:`,e)),!this.graphUnsubscribe){let e=null,t=()=>e||(e=(async()=>{await this.refresh();for(let e of this.subscribers)e([...this.cache])})().finally(()=>{e=null}),e),n=er();this.graphUnsubscribe=n.subscribe(this.name,t),this.db.subscribe_changes&&(this.runtimeUnsubscribe=this.db.subscribe_changes(e=>{e===this.name&&t()},this.name))}return()=>{if(this.subscribers.delete(e),this.subscribers.size===0){this.graphUnsubscribe?.(),this.runtimeUnsubscribe?.(),this.graphUnsubscribe=null,this.runtimeUnsubscribe=null;for(let e of this.unsubscribeFunctions)e();this.unsubscribeFunctions.clear()}}}close(){this.graphUnsubscribe?.(),this.runtimeUnsubscribe?.(),this.graphUnsubscribe=null,this.runtimeUnsubscribe=null,this.subscribers.clear();for(let e of this.unsubscribeFunctions)e();this.unsubscribeFunctions.clear()}freshness(){return Yn(this.db)}lastFreshnessCheck(){return this.lastFreshness}async currentRevision(){try{return{revision:await Xn(this.db)}}catch(e){return{reason:e instanceof Error?e.message:String(e)}}}async refresh(){try{let e=await this.currentRevision();if(`revision`in e){if(this.isInitialized&&this.cachedRevision&&Zn(this.cachedRevision,e.revision)){this.lastFreshness={validation:`revision`,servedFromCache:!0,revision:e.revision};return}}else this.cachedRevision=null;let t=await this.db.query(this.name);if(this.lastFreshness=`revision`in e?{validation:`revision`,servedFromCache:!1,revision:e.revision}:{validation:`refresh`,servedFromCache:!1,reason:e.reason},t.success&&t.data){if(this.cachedRevision=`revision`in e?e.revision:null,this.isInitialized&&t.data===this.lastRawSnapshot)return;try{let e=JSON.parse(t.data);this.predicate&&(e=e.filter(e=>{try{return this.predicate(e)}catch{return!1}})),this.cache=e,this.cacheGeneration+=1,this.lastRawSnapshot=t.data,this.isInitialized=!0}catch(e){console.error(`Failed to parse query results:`,e)}}else t.success||console.error(`Query failed:`,t.error)}catch(e){console.error(`Refresh error:`,e)}}},br=Symbol(`FELTDB_NO_CHANGE`),xr=class{id;jsDb;cellCollection;replicaCollection;failureObservationCollection;mutationQueue=[];isLocked=!1;changeHandlers=[];isReplica=!1;constructor(e,t){this.id=t,this.jsDb=e,this.cellCollection=new yr(e,`_cells`,void 0,void 0,!1),this.replicaCollection=new yr(e,`_replicas`,void 0,void 0,!1),this.failureObservationCollection=new yr(e,`_failure_observations`,void 0,void 0,!1)}setReplica(e){this.isReplica=e}isReplicaCell(){return this.isReplica}async applyReplication(e){return this.acquireLock(async()=>{let t=this.encodeKey();for(;;){let n=await this.cellCollection.get(t),r=n?this.snapshotFromState(n):null;if(r&&r.version>e.version)throw Error(`REPLICATION_CONFLICT: cannot apply version ${e.version}, current is ${r.version}`);if(r&&r.version===e.version){if(JSON.stringify(r.value)!==JSON.stringify(e.value)){let n=`version ${e.version} has divergent state`;throw await this.replicaCollection.insert({cellId:this.id,version:r.version,value:r.value,updatedAt:r.updatedAt,authority:r.authority,placement:r.placement,lease:r.lease,divergent:!0,conflictReason:n},t),Error(`REPLICATION_CONFLICT: ${n}`)}await this.clearDivergenceMarker();return}let i={id:e.cellId,version:e.version,value:e.value,updatedAt:e.updatedAt,authority:{owner:e.authority.owner,epoch:e.authority.epoch,lifecycle:e.authority.lifecycle},placement:{nodeId:e.placement.nodeId},lease:e.lease};if(!r)await this.cellCollection.insert(i,t);else{let e=n?.__version??r.version;if(!(await this.cellCollection.updateIfVersion(t,e,i,r.authority.epoch)).updated)continue}await this.clearDivergenceMarker();return}})}async clearDivergenceMarker(){try{await this.replicaCollection.delete(this.encodeKey())}catch(e){if(e instanceof Error&&/^Delete failed: record(?: .+)? not found$/i.test(e.message))return;throw e}}encodeKey(){return`${this.hashId(this.id)}`}hashId(e){let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t=(t<<5)-t+r,t&=t}return Math.abs(t).toString(16)}async get(){let e=this.encodeKey(),t=await this.cellCollection.get(e);return t?this.snapshotFromState(t):null}async set(e,t){return this.acquireLock(async()=>{if(this.isReplica)throw Error(`REPLICA_READ_ONLY: Cell ${this.id} is a read-only replica`);let n=await this.getUnlocked();if(n?.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);let r=n?.authority.epoch??0;if(t?.authorityEpoch!==void 0&&n&&t.authorityEpoch!==r)throw Error(`AUTHORITY_CONFLICT: expected epoch ${r}, got ${t.authorityEpoch}`);if(t?.leaseId!==void 0){if(!n?.lease)throw Error(`LEASE_INVALID: no active lease`);if(n.lease.leaseId!==t.leaseId)throw Error(`LEASE_INVALID: lease ID mismatch`);if(n.lease.expiresAt<=Date.now())throw Error(`LEASE_EXPIRED: lease has expired`);if(n.lease.epoch!==r)throw Error(`LEASE_INVALID: lease epoch does not match authority epoch`)}let i=n?.version??0,a=n?.authority??{owner:null,epoch:0,lifecycle:`active`},o=n?.placement??{nodeId:null},s=n?.lease??null,c={id:this.id,version:i+1,value:e,updatedAt:new Date().toISOString(),authority:a,placement:o,lease:s},l=this.encodeKey();if(i===0)await this.cellCollection.insert(c,l);else if(!(await this.cellCollection.updateIfVersion(l,i,c,r,t?.leaseId)).updated)throw Error(`Cell ${this.id} version conflict`);return this.emitChange({cellId:this.id,version:c.version,value:e,timestamp:c.updatedAt,epoch:c.authority.epoch}),this.snapshotFromState(c)})}async update(e,t){return this.acquireLock(async()=>{if(this.isReplica)throw Error(`REPLICA_READ_ONLY: Cell ${this.id} is a read-only replica`);let n=await this.getUnlocked();if(n?.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);let r=n?.authority.epoch??0;if(t?.authorityEpoch!==void 0&&n&&t.authorityEpoch!==r)throw Error(`AUTHORITY_CONFLICT: expected epoch ${r}, got ${t.authorityEpoch}`);if(t?.leaseId!==void 0){if(!n?.lease)throw Error(`LEASE_INVALID: no active lease`);if(n.lease.leaseId!==t.leaseId)throw Error(`LEASE_INVALID: lease ID mismatch`);if(n.lease.expiresAt<=Date.now())throw Error(`LEASE_EXPIRED: lease has expired`);if(n.lease.epoch!==r)throw Error(`LEASE_INVALID: lease epoch does not match authority epoch`)}let i=n?.value??null,a=n?.version??0,o=e(i);if(o===br){if(n)return this.snapshotFromState(n);throw Error(`Cell ${this.id} update returned NO_CHANGE but cell does not exist`)}let s=n?.authority??{owner:null,epoch:0,lifecycle:`active`},c=n?.placement??{nodeId:null},l=n?.lease??null,u={id:this.id,version:a+1,value:o,updatedAt:new Date().toISOString(),authority:s,placement:c,lease:l},d=this.encodeKey();if(a===0)await this.cellCollection.insert(u,d);else if(!(await this.cellCollection.updateIfVersion(d,a,u,r,t?.leaseId)).updated)throw Error(`Cell ${this.id} conflict during update`);return this.emitChange({cellId:this.id,version:u.version,value:o,timestamp:u.updatedAt,epoch:u.authority.epoch}),this.snapshotFromState(u)})}async transact(e){return this.acquireLock(async()=>e({get:()=>this.getUnlocked(),set:(e,t)=>this.setUnlocked(e,t),update:(e,t)=>this.updateUnlocked(e,t)}))}async transitionAuthority(e){return this.acquireLock(async()=>{if(this.isReplica)throw Error(`REPLICA_READ_ONLY: Cell ${this.id} is a read-only replica`);let t=await this.getUnlocked();if(!t)throw Error(`Cell ${this.id} does not exist`);if(t.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);if(t.authority.epoch!==e.expectedEpoch)throw Error(`AUTHORITY_CONFLICT: expected epoch ${e.expectedEpoch}, got ${t.authority.epoch}`);e.lifecycle!==void 0&&this.validateLifecycleTransition(t.authority.lifecycle,e.lifecycle);let n={owner:e.owner===void 0?t.authority.owner:e.owner,epoch:t.authority.epoch+1,lifecycle:e.lifecycle===void 0?t.authority.lifecycle:e.lifecycle},r={id:this.id,version:t.version+1,value:t.value,updatedAt:new Date().toISOString(),authority:n,placement:t.placement,lease:null},i=this.encodeKey();if(!(await this.cellCollection.updateIfVersion(i,t.version,r,t.authority.epoch)).updated)throw Error(`AUTHORITY_CONFLICT: epoch changed during transition`);return this.emitChange({cellId:this.id,version:r.version,value:t.value,timestamp:r.updatedAt,epoch:r.authority.epoch}),this.snapshotFromState(r)})}async delegate(e){return this.acquireLock(async()=>{if(this.isReplica)throw Error(`REPLICA_READ_ONLY: Cell ${this.id} is a read-only replica`);let t=await this.getUnlocked();if(!t)throw Error(`Cell ${this.id} does not exist`);if(t.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);if(t.authority.epoch!==e.expectedEpoch)throw Error(`AUTHORITY_CONFLICT: expected epoch ${e.expectedEpoch}, got ${t.authority.epoch}`);if(t.authority.owner!==e.from)throw Error(`AUTHORITY_CONFLICT: expected owner ${e.from}, got ${t.authority.owner}`);let n={owner:e.to,epoch:t.authority.epoch+1,lifecycle:t.authority.lifecycle},r={id:this.id,version:t.version+1,value:t.value,updatedAt:new Date().toISOString(),authority:n,placement:t.placement,lease:null},i=this.encodeKey();if(!(await this.cellCollection.updateIfVersion(i,t.version,r,t.authority.epoch)).updated)throw Error(`AUTHORITY_CONFLICT: authority changed during delegation`);return this.emitChange({cellId:this.id,version:r.version,value:t.value,timestamp:r.updatedAt,epoch:r.authority.epoch}),this.snapshotFromState(r)})}async updatePlacement(e){return this.acquireLock(async()=>{if(this.isReplica)throw Error(`REPLICA_READ_ONLY: Cell ${this.id} is a read-only replica`);let t=await this.getUnlocked();if(!t)throw Error(`Cell ${this.id} does not exist`);if(t.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);let n=t.authority.epoch,r={nodeId:e.nodeId},i={id:this.id,version:t.version+1,value:t.value,updatedAt:new Date().toISOString(),authority:t.authority,placement:r,lease:t.lease},a=this.encodeKey();if(!(await this.cellCollection.updateIfVersion(a,t.version,i,n)).updated)throw Error(`Cell ${this.id} conflict during placement update`);return this.emitChange({cellId:this.id,version:i.version,value:t.value,timestamp:i.updatedAt,epoch:i.authority.epoch}),this.snapshotFromState(i)})}async acquireLease(e){return this.acquireLock(async()=>{if(this.isReplica)throw Error(`REPLICA_READ_ONLY: Cell ${this.id} is a read-only replica`);let t=await this.getUnlocked();if(!t)throw Error(`Cell ${this.id} does not exist`);if(t.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);if(t.authority.lifecycle===`suspended`)throw Error(`Cell ${this.id} is suspended`);if(t.lease&&t.lease.expiresAt>Date.now())throw Error(`LEASE_CONFLICT: lease already held by ${t.lease.holder}`);let n=t.authority.epoch,r=`${this.id}:${Date.now()}:${Math.random().toString(36).slice(2)}`,i={holder:e.holder,leaseId:r,epoch:n,expiresAt:Date.now()+e.durationMs},a={id:this.id,version:t.version+1,value:t.value,updatedAt:new Date().toISOString(),authority:t.authority,placement:t.placement,lease:i},o=this.encodeKey();if(!(await this.cellCollection.updateIfVersion(o,t.version,a,n)).updated)throw Error(`Cell ${this.id} conflict during lease acquisition`);return this.emitChange({cellId:this.id,version:a.version,value:t.value,timestamp:a.updatedAt,epoch:a.authority.epoch}),this.snapshotFromState(a)})}async renewLease(e){return this.acquireLock(async()=>{if(this.isReplica)throw Error(`REPLICA_READ_ONLY: Cell ${this.id} is a read-only replica`);let t=await this.getUnlocked();if(!t)throw Error(`Cell ${this.id} does not exist`);if(!t.lease)throw Error(`Cell ${this.id} has no active lease`);if(t.lease.leaseId!==e.leaseId)throw Error(`LEASE_CONFLICT: lease ID mismatch`);if(t.lease.expiresAt<=Date.now())throw Error(`LEASE_EXPIRED: lease has expired`);if(t.lease.epoch!==t.authority.epoch)throw Error(`AUTHORITY_CONFLICT: authority epoch changed since lease acquisition`);let n=t.authority.epoch,r={holder:t.lease.holder,leaseId:t.lease.leaseId,epoch:t.lease.epoch,expiresAt:Date.now()+e.durationMs},i={id:this.id,version:t.version+1,value:t.value,updatedAt:new Date().toISOString(),authority:t.authority,placement:t.placement,lease:r},a=this.encodeKey();if(!(await this.cellCollection.updateIfVersion(a,t.version,i,n)).updated)throw Error(`Cell ${this.id} conflict during lease renewal`);return this.emitChange({cellId:this.id,version:i.version,value:t.value,timestamp:i.updatedAt,epoch:i.authority.epoch}),this.snapshotFromState(i)})}async releaseLease(e){return this.acquireLock(async()=>{if(this.isReplica)throw Error(`REPLICA_READ_ONLY: Cell ${this.id} is a read-only replica`);let t=await this.getUnlocked();if(!t)throw Error(`Cell ${this.id} does not exist`);if(!t.lease)throw Error(`Cell ${this.id} has no active lease`);if(t.lease.leaseId!==e.leaseId)throw Error(`LEASE_CONFLICT: lease ID mismatch`);let n=t.authority.epoch,r={id:this.id,version:t.version+1,value:t.value,updatedAt:new Date().toISOString(),authority:t.authority,placement:t.placement,lease:null},i=this.encodeKey();if(!(await this.cellCollection.updateIfVersion(i,t.version,r,n)).updated)throw Error(`Cell ${this.id} conflict during lease release`);return this.emitChange({cellId:this.id,version:r.version,value:t.value,timestamp:r.updatedAt,epoch:r.authority.epoch}),this.snapshotFromState(r)})}async promote(e){return this.acquireLock(async()=>{let t=await this.getUnlocked();if(!t)throw Error(`Cell ${this.id} does not exist`);return this.promoteSnapshot(t,e)})}async promoteSnapshot(e,t){if(e.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);if(e.version!==t.expectedVersion)throw Error(`PROMOTION_CONFLICT: expected version ${t.expectedVersion}, got ${e.version}`);if(e.authority.epoch!==t.expectedEpoch)throw Error(`PROMOTION_CONFLICT: expected epoch ${t.expectedEpoch}, got ${e.authority.epoch}`);let n={owner:t.newOwner,epoch:e.authority.epoch+1,lifecycle:e.authority.lifecycle},r={nodeId:t.newNodeId===void 0?e.placement.nodeId:t.newNodeId},i={id:this.id,version:e.version+1,value:e.value,updatedAt:new Date().toISOString(),authority:n,placement:r,lease:null},a=this.encodeKey(),o=e.lease&&e.lease.expiresAt>Date.now()?e.lease.leaseId:void 0,s=await this.cellCollection.updateIfVersion(a,e.__version??e.version,i,e.authority.epoch,o,!0,e);if(!s.updated)throw s.conflictCode===`REPLICATION_CONFLICT`?Error(`REPLICATION_CONFLICT: divergent replica cannot be promoted`):Error(`PROMOTION_CONFLICT: cell state changed during promotion`);return this.emitChange({cellId:this.id,version:i.version,value:e.value,timestamp:i.updatedAt,epoch:i.authority.epoch}),this.snapshotFromState(i)}async observeHealth(e){let t=`observation_${this.id}_${e.nodeId}`,n=await this.failureObservationCollection.get(t);if(!(n&&n.observedAt>e.observedAt)){if(n){let r=n.__version??1;if(!(await this.failureObservationCollection.updateIfVersion(t,r,e,0)).updated)return}else await this.failureObservationCollection.insert(e,t)}}async evaluateFailure(e){let t=`observation_${this.id}_${e.nodeId}`,n=await this.failureObservationCollection.get(t);if(!n)return{status:`healthy`,authorityEpoch:e.nodeId===(await this.getUnlocked())?.authority.owner?(await this.getUnlocked())?.authority.epoch??0:0,nodeId:e.nodeId};let r=await this.getUnlocked();if(r&&n.authorityEpoch<r.authority.epoch)return{status:`healthy`,authorityEpoch:r.authority.epoch,nodeId:e.nodeId};let i=e.now-n.lastSeenAt,a;return a=i<e.suspectAfterMs?`healthy`:i<e.failedAfterMs?`suspect`:`failed`,{status:a,authorityEpoch:n.authorityEpoch,nodeId:e.nodeId,ageMs:i}}async attemptAutomaticFailover(e){if(!this.isReplica)return{attempted:!1,promoted:!1,reason:`Not a replica`,diagnostics:{isReplica:!1,eligibilityChecksPassed:!1,promotionAttempted:!1,promotionSucceeded:!1}};let t=e.replicaSnapshot??await this.getUnlocked();if(!t)return{attempted:!1,promoted:!1,reason:`Replica state not found`,diagnostics:{isReplica:!0,eligibilityChecksPassed:!1,promotionAttempted:!1,promotionSucceeded:!1}};let n=`observation_${this.id}_${e.failureEvaluationOptions.nodeId}`,r=e.failureObservation??await this.failureObservationCollection.get(n),i=this.evaluateFailureSnapshot(e.failureEvaluationOptions,r,t);if(i.status!==`failed`)return{attempted:!1,promoted:!1,reason:`Current authority not failed (status: ${i.status})`,diagnostics:{isReplica:!0,failureStatus:i.status,eligibilityChecksPassed:!1,promotionAttempted:!1,promotionSucceeded:!1}};if(t.authority.lifecycle===`retired`)return{attempted:!1,promoted:!1,reason:`Cell is retired`,diagnostics:{isReplica:!0,failureStatus:i.status,eligibilityChecksPassed:!1,promotionAttempted:!1,promotionSucceeded:!1}};if(t.authority.epoch!==i.authorityEpoch)return{attempted:!1,promoted:!1,reason:`Replica authority epoch mismatch: replica=${t.authority.epoch}, observed=${i.authorityEpoch}`,diagnostics:{isReplica:!0,failureStatus:i.status,eligibilityChecksPassed:!1,promotionAttempted:!1,promotionSucceeded:!1}};try{return await this.promoteSnapshot(t,{expectedVersion:t.version,expectedEpoch:t.authority.epoch,newOwner:e.newOwner,newNodeId:t.placement.nodeId}),{attempted:!0,promoted:!0,diagnostics:{isReplica:!0,failureStatus:i.status,eligibilityChecksPassed:!0,promotionAttempted:!0,promotionSucceeded:!0}}}catch(e){return{attempted:!0,promoted:!1,reason:`Promotion failed: ${e instanceof Error?e.message:String(e)}`,diagnostics:{isReplica:!0,failureStatus:i.status,eligibilityChecksPassed:!0,promotionAttempted:!0,promotionSucceeded:!1}}}}evaluateFailureSnapshot(e,t,n){if(!t)return{status:`healthy`,authorityEpoch:e.nodeId===n.authority.owner?n.authority.epoch:0,nodeId:e.nodeId};if(t.authorityEpoch<n.authority.epoch)return{status:`healthy`,authorityEpoch:n.authority.epoch,nodeId:e.nodeId};let r=e.now-t.lastSeenAt;return{status:r<e.suspectAfterMs?`healthy`:r<e.failedAfterMs?`suspect`:`failed`,authorityEpoch:t.authorityEpoch,nodeId:e.nodeId,ageMs:r}}validateLifecycleTransition(e,t){if(!{active:[`suspended`,`retired`],suspended:[`active`,`retired`],retired:[]}[e].includes(t))throw Error(`Invalid lifecycle transition: ${e} → ${t}`)}async getUnlocked(){let e=this.encodeKey(),t=await this.cellCollection.get(e);return t?this.snapshotFromState(t):null}async setUnlocked(e,t){let n=await this.getUnlocked();if(n?.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);let r=n?.authority.epoch??0;if(t?.authorityEpoch!==void 0&&n&&t.authorityEpoch!==r)throw Error(`AUTHORITY_CONFLICT: expected epoch ${r}, got ${t.authorityEpoch}`);if(t?.leaseId!==void 0){if(!n?.lease)throw Error(`LEASE_INVALID: no active lease`);if(n.lease.leaseId!==t.leaseId)throw Error(`LEASE_INVALID: lease ID mismatch`);if(n.lease.expiresAt<=Date.now())throw Error(`LEASE_EXPIRED: lease has expired`);if(n.lease.epoch!==r)throw Error(`LEASE_INVALID: lease epoch does not match authority epoch`)}let i=n?.version??0,a=n?.authority??{owner:null,epoch:0,lifecycle:`active`},o=n?.placement??{nodeId:null},s=n?.lease??null,c={id:this.id,version:i+1,value:e,updatedAt:new Date().toISOString(),authority:a,placement:o,lease:s},l=this.encodeKey();if(i===0)await this.cellCollection.insert(c,l);else if(!(await this.cellCollection.updateIfVersion(l,i,c,r)).updated)throw Error(`Cell ${this.id} version conflict`);return this.emitChange({cellId:this.id,version:c.version,value:e,timestamp:c.updatedAt,epoch:c.authority.epoch}),this.snapshotFromState(c)}async updateUnlocked(e,t){let n=await this.getUnlocked();if(n?.authority.lifecycle===`retired`)throw Error(`Cell ${this.id} is retired`);let r=n?.authority.epoch??0;if(t?.authorityEpoch!==void 0&&n&&t.authorityEpoch!==r)throw Error(`AUTHORITY_CONFLICT: expected epoch ${r}, got ${t.authorityEpoch}`);if(t?.leaseId!==void 0){if(!n?.lease)throw Error(`LEASE_INVALID: no active lease`);if(n.lease.leaseId!==t.leaseId)throw Error(`LEASE_INVALID: lease ID mismatch`);if(n.lease.expiresAt<=Date.now())throw Error(`LEASE_EXPIRED: lease has expired`);if(n.lease.epoch!==r)throw Error(`LEASE_INVALID: lease epoch does not match authority epoch`)}let i=n?.value??null,a=n?.version??0,o=e(i);if(o===br){if(n)return this.snapshotFromState(n);throw Error(`Cell ${this.id} update returned NO_CHANGE but cell does not exist`)}let s=n?.authority??{owner:null,epoch:0,lifecycle:`active`},c=n?.placement??{nodeId:null},l=n?.lease??null,u={id:this.id,version:a+1,value:o,updatedAt:new Date().toISOString(),authority:s,placement:c,lease:l},d=this.encodeKey();if(a===0)await this.cellCollection.insert(u,d);else if(!(await this.cellCollection.updateIfVersion(d,a,u,r)).updated)throw Error(`Cell ${this.id} conflict during update`);return this.emitChange({cellId:this.id,version:u.version,value:o,timestamp:u.updatedAt,epoch:u.authority.epoch}),this.snapshotFromState(u)}snapshotFromState(e){let t={id:this.id,version:e.version,value:e.value,updatedAt:e.updatedAt,authority:e.authority,placement:e.placement,lease:e.lease},n=e.__version;return n!==void 0&&Object.defineProperty(t,"__version",{value:n,enumerable:!1}),t}on(e,t){e===`change`&&this.changeHandlers.push(t)}off(e,t){if(e===`change`){let e=this.changeHandlers.indexOf(t);e>=0&&this.changeHandlers.splice(e,1)}}emitChange(e){for(let t of this.changeHandlers)try{t(e)}catch(e){console.error(`Error in cell change handler: ${e}`)}}acquireLock(e){return new Promise((t,n)=>{this.mutationQueue.push(async()=>{try{t(await e())}catch(e){n(e)}}),this.isLocked||this.processQueue()})}async processQueue(){if(this.isLocked||this.mutationQueue.length===0)return;this.isLocked=!0;let e=this.mutationQueue.shift();if(e)try{await e()}catch{}finally{this.isLocked=!1,this.processQueue()}}},I;(function(e){e.Created=`Created`,e.Planning=`Planning`,e.Observing=`Observing`,e.Deciding=`Deciding`,e.Acting=`Acting`,e.Waiting=`Waiting`,e.Completed=`Completed`,e.Failed=`Failed`,e.Cancelled=`Cancelled`,e.Blocked=`Blocked`})(I||={});function Sr(e,t){return{name:e,version:t,toString(){return`flow://agent/${this.name}@${this.version}`}}}function Cr(e){return`exec-${e}-${Date.now()}-${Math.random().toString(36).slice(2,11)}`}var wr=class{agents=new Map;register(e,t){let n=e.toString(),r={agentRef:e,definition:t,providers:[],compatibleStateVersions:[],registeredAt:Date.now(),updatedAt:Date.now(),active:!0};this.agents.set(n,r)}unregister(e){let t=e.toString();this.agents.delete(t)}get(e){let t=e.toString();return this.agents.get(t)}getByName(e){let t;for(let n of this.agents.values())n.definition.name===e&&(!t||n.agentRef.version>t.agentRef.version)&&(t=n);return t}getAll(){return Array.from(this.agents.values())}addProvider(e,t){let n=e.toString(),r=this.agents.get(n);if(!r)throw Error(`Agent not registered: ${n}`);r.providers=r.providers.filter(e=>e.peerId!==t.peerId),r.providers.push(t),r.updatedAt=Date.now()}removeProvider(e,t){let n=e.toString(),r=this.agents.get(n);if(!r)throw Error(`Agent not registered: ${n}`);r.providers=r.providers.filter(e=>e.peerId!==t),r.updatedAt=Date.now()}getAvailableProviders(e){let t=this.get(e);return t?t.providers.filter(e=>e.available):[]}findByCapability(e){let t=[];for(let n of this.agents.values())n.definition.capabilities.includes(e)&&t.push(n);return t}updateAvailability(e,t,n){let r=this.get(e);if(!r)throw Error(`Agent not registered: ${e.toString()}`);let i=r.providers.find(e=>e.peerId===t);i&&(i.available=n,i.lastHeartbeat=Date.now(),r.updatedAt=Date.now())}clear(){this.agents.clear()}},Tr=class{ownership=new Map;locks=new Map;claim(e,t,n){let r=this.ownership.get(e);if(r===t)return!0;if(r)return!1;let i=this.locks.get(e);return i&&i.expiresAt>Date.now()?!1:(this.ownership.set(e,t),this.locks.set(e,{peerId:t,expiresAt:Date.now()+n}),!0)}release(e,t){this.ownership.get(e)===t&&(this.ownership.delete(e),this.locks.delete(e))}getOwner(e){return this.ownership.get(e)}isValid(e){let t=this.locks.get(e);return t?t.expiresAt>Date.now():!1}renew(e,t,n){return this.ownership.get(e)===t&&(this.locks.set(e,{peerId:t,expiresAt:Date.now()+n}),!0)}},Er=class{config;registry;handlers=new Map;executions=new Map;ownership;triggers=new Map;constructor(e,t){this.registry=e,this.config=t,this.ownership=new Tr}registerHandler(e,t){this.handlers.set(e,t)}async createExecution(e,t,n,r){let i=Cr(t.name),a={executionId:i,agentRef:t,status:I.Created,goal:n,inputs:r,stateVersion:0,observationIds:[],decisionIds:[],actionIds:[],attempt:1,createdMs:Date.now()};return this.executions.set(i,a),a}async start(e,t){if(!this.ownership.claim(e.executionId,t,3e4))throw Error(`Failed to claim ownership of execution ${e.executionId}`);try{return e.status=I.Planning,e.ownedBy=t,e.startedMs=Date.now(),{execution:e,status:I.Planning,resultRef:void 0}}catch(t){return e.status=I.Failed,e.error=String(t),e.completedMs=Date.now(),{execution:e,status:I.Failed,error:String(t)}}}async resume(e,t){if(!this.ownership.claim(e.executionId,t,3e4)&&this.ownership.getOwner(e.executionId)!==t)throw Error(`Cannot resume execution ${e.executionId}: owned by ${this.ownership.getOwner(e.executionId)}`);return e.ownedBy=t,e.status=I.Observing,{execution:e,status:I.Observing}}async transition(e,t){if(!({[I.Created]:[I.Planning],[I.Planning]:[I.Observing],[I.Observing]:[I.Deciding,I.Waiting],[I.Deciding]:[I.Acting],[I.Acting]:[I.Observing,I.Waiting,I.Completed],[I.Waiting]:[I.Observing,I.Blocked],[I.Completed]:[],[I.Failed]:[],[I.Cancelled]:[],[I.Blocked]:[I.Observing]}[e.status]||[]).includes(t))throw Error(`Invalid transition from ${e.status} to ${t}`);e.status=t}async complete(e,t){e.status=I.Completed,e.resultRef=t,e.completedMs=Date.now(),e.ownedBy&&this.ownership.release(e.executionId,e.ownedBy)}async fail(e,t){e.status=I.Failed,e.error=t,e.completedMs=Date.now(),e.ownedBy&&this.ownership.release(e.executionId,e.ownedBy)}getExecution(e){return this.executions.get(e)}getOwner(e){return this.ownership.getOwner(e)}registerTriggers(e,t){this.triggers.set(e,t)}getTriggers(e){return this.triggers.get(e)||[]}},Dr=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function Or(e){let t=new TextEncoder().encode(e),n=t.length*8,r=new Uint8Array(t.length+9+63>>6<<6);r.set(t),r[t.length]=128;let i=new DataView(r.buffer);i.setUint32(r.length-8,Math.floor(n/4294967296)),i.setUint32(r.length-4,n>>>0);let a=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),o=new Uint32Array(64);for(let e=0;e<r.length;e+=64){for(let t=0;t<16;t+=1)o[t]=i.getUint32(e+t*4);for(let e=16;e<64;e+=1){let t=o[e-15],n=o[e-2],r=(t>>>7|t<<25)^(t>>>18|t<<14)^t>>>3,i=(n>>>17|n<<15)^(n>>>19|n<<13)^n>>>10;o[e]=o[e-16]+r+o[e-7]+i>>>0}let[t,n,r,s,c,l,u,d]=a;for(let e=0;e<64;e+=1){let i=(c>>>6|c<<26)^(c>>>11|c<<21)^(c>>>25|c<<7),a=d+i+(c&l^~c&u)+Dr[e]+o[e]>>>0,f=((t>>>2|t<<30)^(t>>>13|t<<19)^(t>>>22|t<<10))+(t&n^t&r^n&r)>>>0;d=u,u=l,l=c,c=s+a>>>0,s=r,r=n,n=t,t=a+f>>>0}a[0]+=t,a[1]+=n,a[2]+=r,a[3]+=s,a[4]+=c,a[5]+=l,a[6]+=u,a[7]+=d}return Array.from(a,e=>e.toString(16).padStart(8,`0`)).join(``)}function kr(e){return typeof e!=`object`||!e?e===void 0?`null`:JSON.stringify(e):Array.isArray(e)?`[${e.map(kr).join(`,`)}]`:`{${Object.keys(e).filter(t=>e[t]!==void 0).sort().map(t=>`${JSON.stringify(t)}:${kr(e[t])}`).join(`,`)}}`}var Ar=`fb1:`;function jr(e){let t=e.map(e=>{let t=e.eq!==null&&typeof e.eq==`object`,n=t?kr(e.eq):e.eq;return r=>{if(!Object.prototype.hasOwnProperty.call(r,e.field))return!1;let i=r[e.field];return t?typeof i==`object`&&!!i&&kr(i)===n:i===n}});return e=>t.every(t=>t(e))}function Mr(e,t){let n=rr(e),r=[...new Set(n.predicates.map(e=>e.collection))],i=r.length?t.scan(r):new Map;return`${Ar}${Or(kr({records:n.records.map(e=>[e.collection,e.id,t.read(Pr(e.collection,e.id))??null]),predicates:n.predicates.map(e=>[e.collection,e.where,(i.get(e.collection)??[]).filter(jr(e.where)).map(e=>[String(e.id),e]).sort(([e],[t])=>String(e)<String(t)?-1:1)])}))}`}function Nr(e,t){let n=new Set(t),r=new Map(t.map(e=>[e,[]]));for(let[t,i]of e){let e=t.indexOf(`:`),a=e<0?``:t.slice(0,e);n.has(a)&&i&&typeof i==`object`&&r.get(a).push(i)}return r}function Pr(e,t){return`${e}:${t}`}var Fr=/^[A-Za-z0-9._-]{1,128}$/;function Ir(e,t){if(!e.transactionId||!e.transactionId.trim())return{kind:`reject`,reason:`transactionId is required`};if(e.operations.length===0)return{kind:`reject`,reason:`a transaction requires at least one operation`};if(t.hasApplied(e.transactionId))return{kind:`duplicate`};let n=[...(e.preconditions??[]).map(e=>({...e})),...e.operations.filter(e=>e.expectedVersion!==void 0||e.expectedEpoch!==void 0||e.expectedLeaseId!==void 0).map(e=>({collection:e.collection,id:e.id,expectedVersion:e.expectedVersion,expectedEpoch:e.expectedEpoch,expectedLeaseId:e.expectedLeaseId}))];if(n.length>0&&!t.read)return{kind:`reject`,reason:`this runtime cannot evaluate transaction preconditions, so it refuses the transaction rather than committing it unconditionally`};for(let e of n){if(!Fr.test(e.collection)||!Fr.test(String(e.id)))return{kind:`reject`,reason:`invalid collection or id: ${e.collection}:${e.id}`};if(e.requireAbsent!==!0&&e.expectedVersion===void 0&&e.expectedEpoch===void 0&&e.expectedLeaseId===void 0)return{kind:`reject`,reason:`precondition on ${e.collection}:${e.id} constrains nothing`};let n=Pr(e.collection,String(e.id)),r=t.read(n);if(e.requireAbsent){if(r!==void 0)return{kind:`reject`,reason:`PRECONDITION_FAILED:${n}:record already exists`,failure:{predicate:`present`,collection:e.collection,key:n}};continue}if(r===void 0)return{kind:`reject`,reason:`PRECONDITION_FAILED:${n}:record does not exist`,failure:{predicate:`missing`,collection:e.collection,key:n}};if(e.expectedVersion!==void 0){let t=typeof r.__version==`number`?r.__version:1;if(t!==e.expectedVersion)return{kind:`reject`,reason:`PRECONDITION_FAILED:${n}:version ${t}, expected ${e.expectedVersion}`,failure:{predicate:`version`,collection:e.collection,key:n,expected:e.expectedVersion,actual:t}}}if(e.expectedEpoch!==void 0){let t=r.authority,i=typeof t?.epoch==`number`?t.epoch:0;if(i!==e.expectedEpoch)return{kind:`reject`,reason:`PRECONDITION_FAILED:${n}:epoch ${i}, expected ${e.expectedEpoch}`,failure:{predicate:`epoch`,collection:e.collection,key:n,expected:e.expectedEpoch,actual:i}}}if(e.expectedLeaseId!==void 0){let t=r.lease,i=t?.leaseId,a=typeof t?.expiresAt==`number`&&t.expiresAt>Date.now();if(i!==e.expectedLeaseId||!a)return{kind:`reject`,reason:`PRECONDITION_FAILED:${n}:lease ${i??`none`}, expected ${e.expectedLeaseId}`,failure:{predicate:`lease`,collection:e.collection,key:n,expected:e.expectedLeaseId,actual:i??null}}}}let r=e.fences??[];if(r.length>0){if(!t.read||!t.scan)return{kind:`reject`,reason:`this runtime cannot evaluate read-basis fences inside its commit boundary, so it refuses the transaction rather than committing it unfenced`};for(let e of r){if(typeof e?.token!=`string`||!e.token.startsWith(`fb1:`))return{kind:`reject`,reason:`a read basis was not issued by this authority`};let n;try{n=Mr(e.reads,{read:t.read,scan:t.scan})}catch(e){return{kind:`reject`,reason:`invalid read basis: ${e instanceof Error?e.message:String(e)}`}}if(n!==e.token){let t=rr(e.reads);return{kind:`reject`,reason:`PRECONDITION_FAILED:read-basis:state read by this transaction has changed`,failure:{predicate:`fence`,collection:t.records[0]?.collection??t.predicates[0]?.collection??``,key:`read-basis`,expected:e.token,actual:n}}}}}let i=[],a=new Set;for(let r of e.operations){if(!Fr.test(r.collection)||!Fr.test(r.id))return{kind:`reject`,reason:`invalid collection or id: ${r.collection}:${r.id}`};let e=Pr(r.collection,r.id);if(a.has(e))return{kind:`reject`,reason:`transaction writes ${e} more than once`};if(a.add(e),r.requireAbsent&&t.exists(e))return{kind:`reject`,reason:`PRECONDITION_FAILED:${e}:record already exists`,failure:{predicate:`present`,collection:r.collection,key:e}};let o=r.requireAbsent===!0||n.some(e=>e.requireAbsent===!0&&e.collection===r.collection&&String(e.id)===r.id),s=r.value===void 0?void 0:o?{...r.value,id:r.id,__version:1}:r.expectedVersion===void 0?{...r.value,id:r.id}:{...r.value,id:r.id,__version:r.expectedVersion+1};i.push({key:e,collection:r.collection,id:r.id,value:s})}return{kind:`apply`,mutations:i}}function Lr(e,t,n,r){return{transactionId:e.transactionId,duplicate:t,operations:e.operations.length,stateBefore:n,stateAfter:r,baseRevision:n,commitRevision:r,revisionId:`revision-${r}`,operationIds:e.operations.map((t,n)=>`operation:${e.transactionId}:${n+1}`)}}var Rr=class extends Error{feltdbCode;feltdbConflict;constructor(e,t){super(e),this.name=`EmbeddedTransactionRejected`,t&&(this.feltdbCode=`PRECONDITION_FAILED`,this.feltdbConflict=t)}},zr=()=>typeof performance<`u`?performance.now():Date.now();function Br(e,t){return e===t||e==null&&t==null?0:e==null?-1:t==null?1:typeof e==`number`&&typeof t==`number`?e<t?-1:1:String(e).localeCompare(String(t))}function Vr(e){return e.fields?.length?e.fields.map((t,n)=>({field:t,direction:e.directions?.[n]??`asc`})):e.field?[{field:e.field,direction:e.direction??`asc`}]:[]}function Hr(e,t,n){return t.slice(e.length+1)}function Ur(e){return`${typeof e}:${JSON.stringify(e)}`}function Wr(e,t,n,r){for(let e of t){let t=Br(n.record[e.field],r.record[e.field]);if(t)return e.direction===`asc`?t:-t}return Hr(e,n.key,n.record).localeCompare(Hr(e,r.key,r.record))}function Gr(e,t){let n=e[t.field];return!(`eq`in t&&n!==t.eq||`neq`in t&&n===t.neq||`lt`in t&&Br(n,t.lt)>=0||`lte`in t&&Br(n,t.lte)>0||`gt`in t&&Br(n,t.gt)<=0||`gte`in t&&Br(n,t.gte)<0)}function Kr(e){let t=JSON.stringify({collection:e.collection,where:e.where??[],orderBy:e.orderBy??[],limit:e.limit}),n=14695981039346656037n;for(let e=0;e<t.length;e+=1)n^=BigInt(t.charCodeAt(e)),n=BigInt.asUintN(64,n*1099511628211n);return n.toString(16).padStart(16,`0`)}function qr(e){let t=JSON.stringify(e);return typeof Buffer<`u`?Buffer.from(t).toString(`base64url`):btoa(unescape(encodeURIComponent(t))).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function Jr(e,t){try{let n=typeof Buffer<`u`?Buffer.from(e,`base64url`).toString(`utf8`):(()=>{let t=e.replace(/-/g,`+`).replace(/_/g,`/`);return decodeURIComponent(escape(atob(t.padEnd(Math.ceil(t.length/4)*4,`=`))))})(),r=JSON.parse(n);if(r.v!==1||r.binding!==t||!Array.isArray(r.values)||typeof r.key!=`string`)throw Error();return r}catch{throw Error(`INVALID_CURSOR: cursor is malformed or does not match this query`)}}var Yr=class{allRows;indexes=new Map;constructor(e){this.allRows=e,this.rebuild()}rebuild(){this.indexes.clear();let e=[...this.allRows()];for(let[t,n]of e)this.installDefinition(t,n,e)}apply(e,t){if(e.startsWith(`__indexes__:`)){t===void 0?this.indexes.delete(e):this.installDefinition(e,t,[...this.allRows()]);return}let n=e.indexOf(`:`);if(n<1)return;let r=e.slice(0,n);for(let n of this.indexes.values()){if(n.collection!==r)continue;let i=n.byKey.get(e);if(i){let t=n.buckets.get(Ur(i.record[n.fields[0].field])),r=t?.findIndex(t=>t.key===e)??-1;r>=0&&t.splice(r,1),n.byKey.delete(e)}if(t&&typeof t==`object`&&!Array.isArray(t)){let i={key:e,record:t},a=Ur(i.record[n.fields[0].field]),o=n.buckets.get(a);o||(o=[],n.buckets.set(a,o));let s=0,c=o.length;for(;s<c;){let e=s+c>>>1;Wr(r,n.fields,o[e],i)<=0?s=e+1:c=e}o.splice(s,0,i),n.byKey.set(e,i)}n.globalDirty=!0}}installDefinition(e,t,n){let r=e.split(`:`);if(r.length<3||r[0]!==`__indexes__`||!t||typeof t!=`object`)return;let i=t.config;if(!i?.name)return;let a=r[1],o=Vr(i);if(!o.length||i.type===`text`)return;let s=`${a}:`,c=n.filter(([e,t])=>e.startsWith(s)&&t&&typeof t==`object`&&!Array.isArray(t)).map(([e,t])=>({key:e,record:t}));c.sort((e,t)=>Wr(a,o,e,t));let l=new Map;for(let e of c){let t=Ur(e.record[o[0].field]),n=l.get(t)??[];n.push(e),l.set(t,n)}this.indexes.set(e,{collection:a,config:i,fields:o,entries:c,byKey:new Map(c.map(e=>[e.key,e])),buckets:l,globalDirty:!1})}plan(e){let t=new Map((e.where??[]).filter(e=>`eq`in e).map(e=>[e.field,e.eq])),n=e.orderBy??[];for(let r of this.indexes.values()){if(r.collection!==e.collection)continue;let i=0;for(;i<r.fields.length&&t.has(r.fields[i].field);)i+=1;if(i===0&&(e.where?.length??0)>0)continue;let a=r.fields.slice(i),o=n.every((e,t)=>a[t]?.field===e.field&&a[t]?.direction===e.direction),s=a.length===n.length,c=a.length===n.length+1&&a.at(-1)?.field===`id`&&a.at(-1)?.direction===`asc`;if(!(n.length&&(!o||!s&&!c)))return{index:r,explanation:{plan:n.length?`index-range`:`index-filter`,index:r.config.name,order:this.orderDescription(e),limit:e.limit,cursor:!!e.cursor}}}return{explanation:{plan:`full-scan`,reason:`no compatible index`,order:this.orderDescription(e),limit:e.limit,cursor:!!e.cursor}}}explain(e){return this.validate(e),this.plan(e).explanation}execute(e){this.validate(e);let t=zr(),n=this.plan(e),r={scanned:0,decoded:0,matched:0,sorted:0,materialized:0,returned:0,usedIndex:!!n.index,indexName:n.index?.config.name,indexLookupMs:0,executionMs:0},i=e.where??[],a=e.orderBy??[],o=a.map(e=>({field:e.field,direction:e.direction})),s=e.cursor?Jr(e.cursor,Kr(e)):void 0,c=[],l=zr();if(!n.index){let t=`${e.collection}:`;for(let[e,n]of this.allRows()){if(!e.startsWith(t))continue;r.scanned+=1;let a=n;!a||typeof a!=`object`||!i.every(e=>Gr(a,e))||(r.matched+=1,c.push({key:e,record:a}))}}let u=n.index?this.indexRange(n.index,i):{entries:[],start:0,end:0},d=u.entries,f=u.start;if(n.index&&s){let t=u.start,n=u.end;for(;t<n;){let r=t+n>>>1;this.compareEntryCursor(e.collection,o,d[r],s)<=0?t=r+1:n=r}f=t}for(let t=f;t<u.end;t+=1){let a=d[t];if(r.scanned+=1,!(!a.record||typeof a.record!=`object`||!i.every(e=>Gr(a.record,e)))&&(r.matched+=1,c.push(a),n.index&&c.length>e.limit))break}r.indexLookupMs=n.index?zr()-l:0;let p=c.length;n.index||(c.sort((t,n)=>Wr(e.collection,o,t,n)),r.sorted=c.length,s&&(c=c.filter(t=>this.afterCursor(e.collection,o,t,s))));let m=c.length>e.limit,h=c.slice(0,e.limit),g=h.map(e=>e.record);r.materialized=n.index?g.length:p,r.returned=g.length,r.executionMs=zr()-t;let _=h.at(-1),v=m&&_?qr({v:1,binding:Kr(e),values:a.map(e=>_.record[e.field]),key:Hr(e.collection,_.key,_.record)}):void 0;return{records:g,...v?{nextCursor:v}:{},exhausted:!v,stats:r,plan:{access_method:n.explanation.plan,actual_rows_scanned:r.scanned,actual_rows_returned:r.returned,matching_records:r.matched,index:r.indexName,scan_fallback:!r.usedIndex}}}afterCursor(e,t,n,r){return this.compareEntryCursor(e,t,n,r)>0}compareEntryCursor(e,t,n,r){for(let e=0;e<t.length;e+=1){let i=Br(n.record[t[e].field],r.values[e]);if(i)return t[e].direction===`asc`?i:-i}return Hr(e,n.key,n.record).localeCompare(r.key)}indexRange(e,t){let n=new Map(t.filter(e=>`eq`in e).map(e=>[e.field,e.eq])),r=0;for(;r<e.fields.length&&n.has(e.fields[r].field);)r+=1;if(r===0)return e.globalDirty&&=(e.entries=[...e.byKey.values()].sort((t,n)=>Wr(e.collection,e.fields,t,n)),!1),{entries:e.entries,start:0,end:e.entries.length};let i=e.buckets.get(Ur(n.get(e.fields[0].field)))??[];if(r===1)return{entries:i,start:0,end:i.length};let a=t=>{for(let i=0;i<r;i+=1){let r=e.fields[i],a=Br(t.record[r.field],n.get(r.field));if(a)return r.direction===`asc`?a:-a}return 0},o=0,s=i.length;for(;o<s;){let e=o+s>>>1;a(i[e])<0?o=e+1:s=e}let c=o;for(s=i.length;o<s;){let e=o+s>>>1;a(i[e])<=0?o=e+1:s=e}return{entries:i,start:c,end:o}}orderDescription(e){return[...(e.orderBy??[]).map(e=>`${e.field} ${e.direction.toUpperCase()}`),`id ASC`].join(`, `)}validate(e){if(!e.collection?.trim()||!Number.isInteger(e.limit)||e.limit<1||e.limit>1e3)throw Error(`INVALID_QUERY: collection and a limit between 1 and 1000 are required`);for(let t of e.where??[]){let e=Object.keys(t).filter(e=>e!==`field`),n=e.filter(e=>[`eq`,`neq`,`lt`,`lte`,`gt`,`gte`].includes(e));if(!t.field||n.length!==1||e.length!==1)throw Error(`INVALID_QUERY: each condition requires a field and exactly one operator`)}if(e.semantic!==void 0)throw Error(`SEMANTIC_UNSUPPORTED: this runtime has no semantic runtime binding; semantic query composition is available through the managed authority`)}},Xr=new Map,Zr=new Map;function Qr(e){let t=Zr.get(e);return t||(t={value:0,replicated:!1},Zr.set(e,t)),t}var $r=class{rows;events=[];sequence=0;origin;revisionState;peers=new Set;applied=new Set;queryEngine;indexedRevision;constructor(e){let t=Xr.get(e);t||(t=new Map,Xr.set(e,t)),this.rows=t,this.revisionState=Qr(e),this.origin=`memory:${e}`,this.queryEngine=new Yr(()=>this.rows.entries()),this.indexedRevision=this.revisionState.value}event(e,t,n,r){this.sequence+=1,this.revisionState.value+=1;let i=Date.now();this.events.push({sequence:this.sequence,collection:e,key:t,type:n,value:r,timestamp:i,origin:this.origin,id:`${this.origin}:${i}:${this.sequence}`}),this.queryEngine.apply(t,n===`put`?this.rows.get(t):void 0),this.indexedRevision=this.revisionState.value}async read_basis(e){let t=rr(e);return{reads:t,token:Mr(t,{read:e=>this.rows.get(e),scan:e=>Nr(this.rows,e)})}}async commit_transaction(e){let t=this.sequence,n=Ir(e,{exists:e=>this.rows.has(e),hasApplied:e=>this.applied.has(e),read:e=>this.rows.get(e),scan:e=>Nr(this.rows,e)});if(n.kind===`duplicate`)return Lr(e,!0,t,this.sequence);if(n.kind===`reject`)throw new Rr(n.reason,n.failure);for(let e of n.mutations)e.value===void 0?(this.rows.delete(e.key),this.event(e.collection,e.key,`delete`)):(this.rows.set(e.key,e.value),this.event(e.collection,e.key,`put`,e.value));return this.applied.add(e.transactionId),Lr(e,!1,t,this.sequence)}insert(e,t){try{return this.rows.set(e,JSON.parse(t)),this.event(e.split(`:`)[0],e,`put`,JSON.parse(t)),{success:!0,data:e}}catch(e){return{success:!1,error:String(e)}}}update(e,t){return this.rows.has(e)?this.insert(e,t):{success:!1,error:`Record ${e} not found`}}get(e){let t=this.rows.get(e);return t===void 0?{success:!0}:{success:!0,data:JSON.stringify(t)}}delete(e){return this.rows.delete(e),this.event(e.split(`:`)[0],e,`delete`),{success:!0,data:e}}putIfAbsent(e,t){let n=this.rows.get(e);if(n!==void 0)return Promise.resolve({inserted:!1,value:JSON.stringify(n)});let r=JSON.parse(t);return this.rows.set(e,r),this.event(e.split(`:`)[0],e,`put`,r),Promise.resolve({inserted:!0,value:t})}cas(e){let t=this.rows.get(e.key),n=JSON.parse(e.value);if(t===void 0)return Promise.resolve({updated:!1,currentVersion:0});let r=t,i=r.__version??1,a=r.authority?.epoch??0;if(i!==e.expectedVersion||e.expectedEpoch!==void 0&&a!==e.expectedEpoch)return Promise.resolve({updated:!1,currentVersion:i,currentEpoch:a});let o=e.expectedVersion+1,s={...n,__version:o};return this.rows.set(e.key,s),this.event(e.key.split(`:`)[0],e.key,`put`,s),Promise.resolve({updated:!0,currentVersion:o,currentEpoch:a,item:s})}query(e){let t=`${e}:`,n=[...this.rows].filter(([e])=>e.startsWith(t)).map(([,e])=>e);return{success:!0,data:JSON.stringify(n)}}async authority_query(e){return this.indexedRevision!==this.revisionState.value&&(this.queryEngine.rebuild(),this.indexedRevision=this.revisionState.value),this.queryEngine.execute(e)}explain_query(e){return this.queryEngine.explain(e)}rebuild_indexes(){this.queryEngine.rebuild(),this.indexedRevision=this.revisionState.value}get_capability_records(e){return this.query(e)}execute_op(){return{success:!1,error:`Raw operations are unavailable in the memory runtime`}}sync_info(){return{success:!0,data:JSON.stringify({instance_id:this.origin,sequence:this.sequence,connected_peers:[...this.peers],pending_operations:0,operations_sent:0,operations_received:0,conflicts_detected:0,last_sync_ms:0,is_connected:this.peers.size>0})}}add_peer(){return{success:!0}}add_sync_peer(e){return this.peers.add(e),{success:!0}}remove_sync_peer(e){return this.peers.delete(e),{success:!0}}acknowledge_peer_operations(){return{success:!0}}get_pending_for_peer(){return{success:!0,data:`[]`}}instance_id(){return this.origin}get_sequence(){return this.sequence}freshness(){return this.revisionState.replicated||this.peers.size>0?{domain:`replicated`,validation:`refresh`,invalidation:!1,reason:`remote operations order causally across replicas, so a local counter is not an authoritative revision`}:{domain:`single-process`,validation:`revision`,invalidation:!1,revisionScope:this.origin}}async revision(){let e=this.freshness();if(e.validation!==`revision`)throw new qn(`memory runtime: ${e.reason}`);return{value:this.revisionState.value,scope:this.origin}}audit_events(){return[...this.events]}export_operations(e){return this.events.filter(t=>t.sequence>e)}apply_remote_operations(e){e.length>0&&(this.revisionState.replicated=!0);let t=0,n=0;for(let r of e){if(this.events.some(e=>e.id===r.id)){n++;continue}let e=[...this.events].reverse().find(e=>e.key===r.key),i=`${String(r.timestamp).padStart(16,`0`)}:${r.origin}:${r.id}`,a=e?`${String(e.timestamp).padStart(16,`0`)}:${e.origin}:${e.id}`:``;this.sequence+=1,this.events.push({...r,sequence:this.sequence}),i>=a?(r.type===`delete`?this.rows.delete(r.key):this.rows.set(r.key,r.value),this.queryEngine.apply(r.key,r.type===`delete`?void 0:r.value),this.revisionState.value+=1,this.indexedRevision=this.revisionState.value,t++):n++}return{applied:t,ignored:n}}},L;(function(e){e.INVALID_REQUEST=`INVALID_REQUEST`,e.UNAUTHORIZED=`UNAUTHORIZED`,e.VERSION_CONFLICT=`VERSION_CONFLICT`,e.SCOPE_VIOLATION=`SCOPE_VIOLATION`,e.INVALID_CURSOR=`INVALID_CURSOR`,e.CURSOR_SCOPE_VIOLATION=`CURSOR_SCOPE_VIOLATION`,e.DURABILITY_FAILURE=`DURABILITY_FAILURE`,e.RECOVERY_FAILURE=`RECOVERY_FAILURE`,e.CONTRACT_UNSUPPORTED=`CONTRACT_UNSUPPORTED`,e.OK=`OK`,e.CONFLICT=`CONFLICT`,e.PRECONDITION_FAILED=`PRECONDITION_FAILED`,e.TOO_BUSY=`TOO_BUSY`,e.INTERNAL_ERROR=`INTERNAL_ERROR`,e.AUTHENTICATION_REQUIRED=`AUTHENTICATION_REQUIRED`,e.AUTHENTICATION_FAILED=`AUTHENTICATION_FAILED`,e.FORBIDDEN=`FORBIDDEN`,e.NOT_FOUND=`NOT_FOUND`,e.VALIDATION_ERROR=`VALIDATION_ERROR`,e.IDEMPOTENCY_CONFLICT=`IDEMPOTENCY_CONFLICT`,e.COMMIT_OUTCOME_UNKNOWN=`COMMIT_OUTCOME_UNKNOWN`,e.QUERY_INVALID=`QUERY_INVALID`,e.QUERY_LIMIT_EXCEEDED=`QUERY_LIMIT_EXCEEDED`,e.WORKFLOW_NOT_FOUND=`WORKFLOW_NOT_FOUND`,e.AGENT_NOT_FOUND=`AGENT_NOT_FOUND`,e.CAPABILITY_NOT_FOUND=`CAPABILITY_NOT_FOUND`,e.EXECUTION_FAILED=`EXECUTION_FAILED`,e.SERVICE_UNAVAILABLE=`SERVICE_UNAVAILABLE`,e.AUTHORITY_SCOPE_REQUIRED=`AUTHORITY_SCOPE_REQUIRED`,e.AUTHORITY_SCOPE_INVALID=`AUTHORITY_SCOPE_INVALID`,e.AUTHORITY_SCOPE_MISMATCH=`AUTHORITY_SCOPE_MISMATCH`})(L||={});var R=class extends Error{code;requestId;status;constructor(e,t,n,r){super(e),this.code=t,this.requestId=n,this.status=r,this.name=`FeltDBServiceError`}};function ei(e){let t=e,n=t?.status,r=typeof t?.code==`string`?t.code:void 0;return n===401||r===`AUTHENTICATION_REQUIRED`||r===`AUTHENTICATION_FAILED`?`authentication`:n===403||r===`FORBIDDEN`?`authorization`:typeof n==`number`&&[400,404,405,409,410,422].includes(n)||r!==void 0&&[`NOT_FOUND`,`VALIDATION_ERROR`,`QUERY_INVALID`].includes(r)?`configuration`:r===`CLIENT_CLOSED`?`closed`:`transient`}function ti(e){return ei(e)===`transient`?`transient`:`permanent`}function ni(e){let t=e instanceof R?e:void 0,n=e;return{kind:ti(e),failure_class:ei(e),name:n?.name??`Error`,message:n?.message??String(e),...t?.code===void 0?{}:{code:String(t.code)},...typeof n?.status==`number`?{status:n.status}:{},at:new Date().toISOString()}}var ri=class{cached;inFlight;failures=0;lastFailure;lastSuccessAt;get value(){return this.cached}get state(){return this.cached===void 0?this.inFlight?`loading`:`unavailable`:`cached`}snapshot(){return{state:this.state,consecutive_failures:this.failures,...this.lastFailure?{last_failure:this.lastFailure}:{},...this.lastSuccessAt?{last_success_at:this.lastSuccessAt}:{}}}get(e){if(this.cached!==void 0)return Promise.resolve(this.cached);if(this.inFlight)return this.inFlight;let t=Promise.resolve().then(e).then(e=>(this.cached=e,this.failures=0,this.lastFailure=void 0,this.lastSuccessAt=new Date().toISOString(),e),e=>{throw this.failures+=1,this.lastFailure=ni(e),e}).finally(()=>{this.inFlight===t&&(this.inFlight=void 0)});return this.inFlight=t,t}seed(e){this.cached=e,this.failures=0,this.lastFailure=void 0,this.lastSuccessAt=new Date().toISOString()}reset(){this.cached=void 0,this.inFlight=void 0,this.failures=0,this.lastFailure=void 0}},ii=class{base;max;factor;random;consecutive=0;constructor(e={}){this.base=Math.max(1,e.base??500),this.max=Math.max(this.base,e.max??3e4),this.factor=Math.max(1,e.factor??2),this.random=e.random??Math.random}get attempts(){return this.consecutive}ceiling(e=this.consecutive){return Math.min(this.max,Math.round(this.base*this.factor**e))}next(){let e=this.ceiling();this.consecutive+=1;let t=e/2;return Math.round(t+this.random()*t)}reset(){this.consecutive=0}};function ai(e,t){return t.aborted?Promise.resolve():new Promise(n=>{let r=()=>{clearTimeout(i),t.removeEventListener(`abort`,r),n()},i=setTimeout(r,e);i.unref?.(),t.addEventListener(`abort`,r,{once:!0})})}function oi(e){return`${e}-${typeof crypto?.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}`}function si(e){if(!e||typeof e!=`object`||Array.isArray(e))return e;let t={...e};return delete t._id,delete t._version,t}var z=class{collection_queries_via_authority=!0;url;token;applicationId;environment;authorityScope;authWaiters=new Set;revisionCache=new ri;backoff;requestTimeoutMs;connectionState=`closed`;availabilityState=`unknown`;lastError;lastSuccessAt;nextRetryAt;streamFailures=0;authorityFailures=0;constructor(e){this.url=e.url.replace(/\/$/,``),this.token=e.token||``,this.applicationId=e.applicationId,this.environment=e.environment||`production`,this.authorityScope=e.authorityScope,this.requestTimeoutMs=Math.max(1,e.requestTimeoutMs??3e4),this.backoff=new ii(e.reconnect)}health(){let e=this.revisionCache.snapshot(),t=this.nextRetryAt===void 0?void 0:this.nextRetryAt-Date.now();return{connection_state:this.connectionState,availability_state:this.availabilityState,usable:this.availabilityState===`available`&&e.state===`cached`,recovery_possible:this.availabilityState!==`closed`&&![`authentication`,`authorization`,`configuration`].includes(this.lastError?.failure_class??``),revision_state:e.state,...this.revisionCache.value===void 0?{}:{revision_id:this.revisionCache.value},consecutive_failures:this.authorityFailures,...this.lastSuccessAt??e.last_success_at?{last_success_at:this.lastSuccessAt??e.last_success_at}:{},...this.lastError??e.last_failure?{last_error:this.lastError??e.last_failure}:{},...this.connectionState===`backoff`&&this.nextRetryAt!==void 0?{next_retry_at:new Date(this.nextRetryAt).toISOString(),next_retry_in_ms:Math.max(0,t??0)}:{}}}recordFailure(e){let t=ni(e);return this.lastError=t,this.authorityFailures+=1,this.availabilityState=t.failure_class===`closed`?`closed`:`degraded`,t}recordSuccess(){this.availabilityState=`available`,this.lastSuccessAt=new Date().toISOString(),this.lastError=void 0,this.authorityFailures=0}headers(e=!1){return{...this.token?{Authorization:`Bearer ${this.token}`}:{},"FeltDB-Protocol":`1`,...this.authorityScope?.kind===`tenant`?{"FeltDB-Tenant-Id":this.authorityScope.tenantId,...this.authorityScope.environmentId?{"FeltDB-Environment-Id":this.authorityScope.environmentId}:{}}:this.authorityScope?.kind===`platform`?{"FeltDB-Authority-Mode":`platform`}:{},...e?{"Content-Type":`application/json`}:{}}}updateToken(e){this.token=e,this.backoff.reset();for(let e of this.authWaiters)e();this.authWaiters.clear()}waitForAuthChange(e){return e.aborted?Promise.resolve():new Promise(t=>{let n=()=>{this.authWaiters.delete(r),r()},r=()=>{e.removeEventListener(`abort`,n),t()};this.authWaiters.add(r),e.addEventListener(`abort`,n,{once:!0})})}async auth_request(e,t){let n=await fetch(`${this.url}/v1/auth/${e}`,{method:e===`session`?`GET`:`POST`,headers:this.headers(t!==void 0),...t===void 0?{}:{body:JSON.stringify(e===`signup`||e===`signin`?{application_id:this.applicationId,...t}:t)}}),r=n.status===204?{}:await n.json();if(!n.ok)throw new R(r.message||r.error||`Authentication failed`,r.code||r.error||`AUTHENTICATION_FAILED`,r.request_id,n.status);return r.access_token&&this.updateToken(r.access_token),e===`signout`&&this.updateToken(``),r}splitKey(e){let t=e.indexOf(`:`);if(t<1||t===e.length-1)throw Error(`Invalid FeltDB key: ${e}`);return[e.slice(0,t),e.slice(t+1)]}async revisionId(){if(!this.applicationId)throw Error(`applicationId is required for the canonical application service`);return this.revisionCache.get(async()=>{let e=await this.application_request(`/application`);if(!e?.revision_id){let e=new R(`canonical application discovery returned no revision_id`,`VALIDATION_ERROR`,void 0,422);throw this.recordFailure(e),e}return e.revision_id})}revisionState(){return this.revisionCache.state}async canonical(e,t){let n=await this.revisionId();return this.application_request(e,{method:`POST`,body:JSON.stringify({application_id:this.applicationId,revision_id:n,environment:this.environment,...t})})}transactionDocument(e,t,n=crypto.randomUUID(),r=[],i=[]){let a=this.authorityScope?.kind===`tenant`?this.authorityScope.tenantId:``;return{transaction_id:n,tenant_id:a,application_id:this.applicationId,revision_id:e,schema_version:0,authorization:{subject:``,tenant_id:a,application_id:this.applicationId,revision_id:e,capabilities:[]},operations:t,preconditions:r,...i.length?{fences:i}:{}}}async canonicalTransaction(e,t,n=[],r=[]){let i=await this.revisionId();return this.application_request(`/transactions`,{method:`POST`,body:JSON.stringify({application_id:this.applicationId,revision_id:i,environment:this.environment,transaction:this.transactionDocument(i,e,t,n,r)})})}async get(e){try{let[t,n]=this.splitKey(e);if(this.applicationId){let e=await this.canonical(`/query`,{query:{collection:t,filter:{operator:`eq`,field:`_id`,value:n},limit:1}});return{success:!0,data:e.records.length?JSON.stringify(si(e.records[0])):void 0}}let r=await fetch(`${this.url}/collections/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{headers:this.headers()});if(r.status===404)return{success:!0};if(!r.ok)return this.failure(r);let i=await r.json();return{success:!0,data:JSON.stringify(i.value)}}catch(e){return{success:!1,error:String(e)}}}async query(e){try{if(this.applicationId){let t=[],n;do{let r=await this.canonical(`/query`,{query:{collection:e,limit:100,...n?{cursor:n}:{}}});t.push(...r.records.map(si)),n=r.next_cursor}while(n);return{success:!0,data:JSON.stringify(t)}}let t=await fetch(`${this.url}/collections/${encodeURIComponent(e)}`,{headers:this.headers()});if(!t.ok)return this.failure(t);let n=await t.json();return{success:!0,data:JSON.stringify(n.map(e=>e.value))}}catch(e){return{success:!1,error:String(e)}}}async authority_query(e){if(this.applicationId){if(e.semantic){let e=Error(`SEMANTIC_UNSUPPORTED: the canonical application query does not compose semantic decisions; use the bounded authority query`);throw e.code=`SEMANTIC_UNSUPPORTED`,e}let t=(e.where||[]).map(e=>{let t=Object.keys(e).find(e=>e!==`field`)||`eq`;return{operator:t,field:e.field,value:e[t]}}),n=await this.canonical(`/query`,{query:{collection:e.collection,filter:t.length===1?t[0]:t.length?{operator:`and`,filters:t}:void 0,order_by:e.orderBy?.map(e=>({field:e.field,direction:e.direction})),limit:e.limit,cursor:e.cursor}});return{records:n.records.map(si),nextCursor:n.next_cursor,exhausted:!n.next_cursor,plan:n.plan}}let t=await fetch(`${this.url}/query`,{method:`POST`,headers:this.headers(!0),body:JSON.stringify(e)}),n=await t.json();if(!t.ok){let e=Error(n.message||n.error||`authority query failed with HTTP ${t.status}`);throw e.code=n.code,e.status=t.status,e}return n}async insert(e,t){try{let[n,r]=this.splitKey(e),i=JSON.parse(t);if(this.applicationId)return await this.canonicalTransaction([{kind:`insert`,collection:n,id:r,value:i}]),{success:!0,data:e};let a=await fetch(`${this.url}/collections/${encodeURIComponent(n)}`,{method:`POST`,headers:this.headers(!0),body:JSON.stringify({...i,id:r})});return a.ok?{success:!0,data:e}:this.failure(a)}catch(e){return{success:!1,error:String(e)}}}async update(e,t){try{let[n,r]=this.splitKey(e);if(this.applicationId)return await this.canonicalTransaction([{kind:`update`,collection:n,id:r,value:JSON.parse(t)}]),{success:!0,data:e};let i=await fetch(`${this.url}/collections/${encodeURIComponent(n)}/${encodeURIComponent(r)}`,{method:`PATCH`,headers:this.headers(!0),body:t});return i.ok?{success:!0,data:e}:this.failure(i)}catch(e){return{success:!1,error:String(e)}}}async commit_transaction(e){if(this.applicationId){let t=e.operations.map(e=>({kind:e.value===void 0?`delete`:e.requireAbsent?`insert`:`update`,collection:e.collection,id:e.id,value:e.value&&typeof e.value==`object`&&!Array.isArray(e.value)?{...e.value,id:e.id}:e.value})),n=[...e.preconditions??[],...e.operations.filter(e=>e.expectedVersion!==void 0||e.expectedEpoch!==void 0||e.expectedLeaseId!==void 0)].map(e=>({kind:`record`,collection:e.collection,id:e.id,require_absent:e.requireAbsent??!1,expected_version:e.expectedVersion,expected_epoch:e.expectedEpoch,expected_lease_id:e.expectedLeaseId})),r=await this.canonicalTransaction(t,e.transactionId,n,e.fences??[]);return{transactionId:r.transaction_id,baseRevision:r.base_revision,commitRevision:r.commit_revision,revisionId:r.revision_id,operationIds:r.operation_ids,status:r.status,duplicate:r.duplicate,operations:t.length,stateBefore:r.state_before,stateAfter:r.state_after}}let t;try{t=await fetch(`${this.url}/transactions`,{method:`POST`,headers:this.headers(!0),body:JSON.stringify(e),signal:AbortSignal.timeout(this.requestTimeoutMs)})}catch(e){throw this.recordFailure(e),new R(e instanceof Error?e.message:String(e),L.COMMIT_OUTCOME_UNKNOWN)}if(!t.ok){let e={};try{e=await t.json()}catch{}let n=Error(e.error||`transaction failed with HTTP ${t.status}`);throw n.status=t.status,e.code&&(n.feltdbCode=e.code),e.failure&&(n.feltdbConflict=e.failure),n}return await t.json()}async read_basis(e){if(this.applicationId)return this.canonical(`/transactions/read-basis`,{reads:e});let t=await fetch(`${this.url}/transactions/read-basis`,{method:`POST`,headers:this.headers(!0),body:JSON.stringify(e),signal:AbortSignal.timeout(this.requestTimeoutMs)});if(!t.ok)throw new R(t.status===404?`This authority does not issue read bases; it cannot evaluate fences inside its commit lock.`:`read basis failed with HTTP ${t.status}: ${await t.text()}`,t.status===404?L.CONTRACT_UNSUPPORTED:L.INVALID_REQUEST,void 0,t.status);return await t.json()}async putIfAbsent(e,t){let[n,r]=this.splitKey(e),i=JSON.parse(t);try{await this.commit_transaction({transactionId:oi(`put-if-absent`),operations:[{collection:n,id:r,value:i,requireAbsent:!0}]})}catch(t){if(!or(t).conflict)throw t;let n=await this.get(e);if(!n.success)throw Error(n.error||`could not read the record that won ${e}`);if(n.data===void 0)throw Error(`${e} was created and then removed while resolving a conditional create`);return{inserted:!1,value:n.data}}return{inserted:!0,value:JSON.stringify({...i,id:r,__version:1})}}async managedCas(e){if(e.rejectIfDiverged)throw Error(`rejectIfDiverged is a replication predicate the canonical transaction contract cannot express`);let[t,n]=this.splitKey(e.key),r=JSON.parse(e.value);delete r.__version;try{await this.commit_transaction({transactionId:oi(`update-if-version`),operations:[{collection:t,id:n,value:r,expectedVersion:e.expectedVersion,expectedEpoch:e.expectedEpoch,expectedLeaseId:e.expectedLeaseId}]})}catch(t){let n=or(t);if(!n.conflict)throw t;return{updated:!1,...await this.observedConflict(e.key,n.failure)}}let i={...r,id:n,__version:e.expectedVersion+1};return{updated:!0,currentVersion:e.expectedVersion+1,currentEpoch:e.expectedEpoch,item:i}}async observedConflict(e,t){let n=t?.predicate===`version`?`VERSION_CONFLICT`:t?.predicate===`epoch`?`AUTHORITY_CONFLICT`:t?.predicate===`lease`?`LEASE_CONFLICT`:t?.predicate===`missing`?`RECORD_MISSING`:t?.predicate===`present`?`RECORD_PRESENT`:void 0;if(t?.predicate===`version`&&typeof t.actual==`number`)return{currentVersion:t.actual,conflictCode:n};let r=await this.get(e),i=r.success&&r.data?JSON.parse(r.data):void 0;return{currentVersion:typeof i?.__version==`number`?i.__version:0,currentEpoch:i?.authority?.epoch,conflictCode:n}}async cas(e){if(this.applicationId)return this.managedCas(e);try{let[t,n]=this.splitKey(e.key),r=JSON.parse(e.value),i=await fetch(`${this.url}/collections/${encodeURIComponent(t)}/${encodeURIComponent(n)}/cas`,{method:`POST`,headers:this.headers(!0),body:JSON.stringify({expectedVersion:e.expectedVersion,expectedEpoch:e.expectedEpoch,expectedLeaseId:e.expectedLeaseId,rejectIfDiverged:e.rejectIfDiverged,value:r})});if(i.status===409){let e=await i.json();if((e.code===`VERSION_CONFLICT`||e.code===`AUTHORITY_CONFLICT`||e.code===`LEASE_CONFLICT`||e.code===`REPLICATION_CONFLICT`)&&e.currentVersion!==void 0)return{updated:!1,currentVersion:e.currentVersion,currentEpoch:e.currentEpoch,conflictCode:e.code}}if(!i.ok){let e=await this.failure(i);throw Error(e.error||`HTTP CAS failed`)}return await i.json()}catch(e){throw e instanceof Error?e:Error(String(e))}}async delete(e){try{let[t,n]=this.splitKey(e);if(this.applicationId)return await this.canonicalTransaction([{kind:`delete`,collection:t,id:n}]),{success:!0,data:e};let r=await fetch(`${this.url}/collections/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:`DELETE`,headers:this.headers()});return r.ok?{success:!0,data:e}:this.failure(r)}catch(e){return{success:!1,error:String(e)}}}async acquire(e,t){let n=await fetch(`${this.url}/refs/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{headers:this.headers()});if(n.status===404)return null;if(!n.ok)throw Error((await this.failure(n)).error);return(await n.json()).value}async search(e,t,n=50){let r=await fetch(`${this.url}/capabilities/search/${encodeURIComponent(e)}`,{method:`POST`,headers:this.headers(!0),body:JSON.stringify({query:t,limit:n})});if(!r.ok)throw Error((await this.failure(r)).error);return(await r.json()).map(e=>e.value)}async provenance(e,t){let n=await fetch(`${this.url}/provenance/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{headers:this.headers()});if(!n.ok)throw Error((await this.failure(n)).error);return(await n.json()).value}async storeContent(e){let t=await fetch(`${this.url}/content`,{method:`PUT`,headers:this.headers(),body:e});if(!t.ok)throw Error((await this.failure(t)).error);return t.json()}async acquireContent(e){let t=await fetch(`${this.url}/content/${encodeURIComponent(e)}`,{headers:this.headers()});if(t.status===404)return null;if(!t.ok)throw Error((await this.failure(t)).error);return new Uint8Array(await t.arrayBuffer())}async command(e,t){let n=await fetch(`${this.url}${e}`,{method:`POST`,headers:this.headers(!0),body:JSON.stringify(t)});if(!n.ok)throw Error((await this.failure(n)).error);return n.status===204?void 0:n.json()}async application_request(e,t={}){let n=e.includes(`?`)?`&`:`?`,r=this.applicationId?`${n}application_id=${encodeURIComponent(this.applicationId)}&environment=${encodeURIComponent(this.environment)}`:``;this.availabilityState===`degraded`&&(this.availabilityState=`recovering`);let i;try{i=await fetch(`${this.url}/v1${e}${r}`,{...t,signal:t.signal??AbortSignal.timeout(this.requestTimeoutMs),headers:{...this.headers(t.body!==void 0),...t.headers||{}}})}catch(e){this.recordFailure(e);let n=![`GET`,`HEAD`,`OPTIONS`].includes((t.method??`GET`).toUpperCase());throw new R(e instanceof Error?e.message:String(e),n?L.COMMIT_OUTCOME_UNKNOWN:L.SERVICE_UNAVAILABLE)}let a=await i.text(),o;try{o=a?JSON.parse(a):void 0}catch{o={message:a}}if(!i.ok){let e=new R(o?.message||o?.error||`FeltDB service request failed: HTTP ${i.status}`,o?.code||o?.error||`REQUEST_FAILED`,o?.request_id,i.status);throw o?.failure&&(e.feltdbConflict=o.failure),this.recordFailure(e),e}return this.recordSuccess(),o}async public_request(e,t={}){let n;try{n=await fetch(`${this.url}${e}`,{...t,signal:t.signal??AbortSignal.timeout(this.requestTimeoutMs),headers:{...this.headers(t.body!==void 0),...t.headers||{}}})}catch(e){this.recordFailure(e);let n=![`GET`,`HEAD`,`OPTIONS`].includes((t.method??`GET`).toUpperCase());throw new R(e instanceof Error?e.message:String(e),n?L.COMMIT_OUTCOME_UNKNOWN:L.SERVICE_UNAVAILABLE)}let r=await n.text(),i;try{i=r?JSON.parse(r):void 0}catch{i={message:r}}if(!n.ok){let e=new R(i?.message||i?.error||`FeltDB request failed: HTTP ${n.status}`,i?.code||(n.status===401?L.UNAUTHORIZED:n.status===403?L.FORBIDDEN:n.status===404?L.NOT_FOUND:`INVALID_REQUEST`),i?.request_id,n.status);throw this.recordFailure(e),e}return this.recordSuccess(),i}async execute_semantic_decision(e){return this.application_request(`/experimental/semantic-decisions`,{method:`POST`,body:JSON.stringify(e)})}subscribe_changes(e){let t=new AbortController;return this.connectionState=`connecting`,this.consumeEvents(t,e),()=>{t.abort(),this.connectionState=`closed`,this.nextRetryAt=void 0}}async consumeEvents(e,t){for(;!e.signal.aborted;){if(!this.token){this.connectionState=`failed`,this.availabilityState=`degraded`,await this.waitForAuthChange(e.signal);continue}let n=!1,r;try{this.connectionState=`connecting`;let i=this.applicationId?`/v1/events?application_id=${encodeURIComponent(this.applicationId)}&environment=${encodeURIComponent(this.environment)}`:`/events`,a=await fetch(`${this.url}${i}`,{headers:this.headers(),signal:e.signal});if(a.status===401||a.status===403){this.recordFailure(new R(`Event stream rejected: HTTP ${a.status}`,a.status===401?`AUTHENTICATION_REQUIRED`:`FORBIDDEN`,void 0,a.status)),this.connectionState=`failed`,this.availabilityState=`degraded`,await this.waitForAuthChange(e.signal);continue}if(!a.ok||!a.body)throw new R(`Event stream failed: HTTP ${a.status}`,`SERVICE_UNAVAILABLE`,void 0,a.status);n=!0,this.connectionState=`connected`,this.streamFailures=0,this.recordSuccess(),this.backoff.reset(),r=a.body.getReader();let o=new TextDecoder,s=``;for(;!e.signal.aborted;){let{done:e,value:n}=await r.read();if(e)break;s+=o.decode(n,{stream:!0}).replace(/\r\n/g,`
|
|
11
11
|
`);let i=s.split(`
|
|
12
12
|
|
|
13
13
|
`);s=i.pop()??``;for(let e of i){let n=e.split(`
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#17211b"/><title>FeltDB Studio</title> <script type="module" crossorigin src="/assets/index-
|
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#17211b"/><title>FeltDB Studio</title> <script type="module" crossorigin src="/assets/index-6f6KVx5R.js"></script>
|
|
2
2
|
<link rel="stylesheet" crossorigin href="/assets/index-BrsF-kWL.css">
|
|
3
3
|
</head><body><div id="root"></div></body></html>
|
|
Binary file
|
package/package.json
CHANGED