@selvajs/solve 1.0.0-beta.7 → 1.0.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,8 @@ One owner for the solve flow — **from an input change to a solve result, on bo
4
4
  with no transport and no UI.**
5
5
 
6
6
  Before this package the solve flow was scattered across four packages and owned by none of them, so
7
- both apps hand-wrote a solve coordinator — one of them paid for it with a poisoned-cache bug.
7
+ both apps hand-wrote a solve coordinator — and one of them ended up serving results from the wrong
8
+ definition out of its cache.
8
9
 
9
10
  ## Layout
10
11
 
@@ -25,7 +26,7 @@ tiers.
25
26
  ## What it must never know
26
27
 
27
28
  - **No UI framework.** No Svelte, no runes, no DOM. `client/` is a state machine, not a component.
28
- - **No renderer.** No `three`. `SolveResult<TMesh>` keeps meshes opaque — the app that parses a
29
+ - **No renderer.** No `three`. `SolveResult<TMesh>` never inspects a mesh — the app that parses a
29
30
  response into `THREE.Object3D[]` is the only place that knows the concrete type. This is what lets
30
31
  a headless CLI solve without dragging in a parse layer. See
31
32
  [`src/client/README.md`](./src/client/README.md#mesh-ownership-is-injected-not-known-here) for how
package/dist/client.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _schemas = require('@selvajs/schemas');var H="external";function k(e,r){return`${H}:${e}:${r}`}function L(e){let{scopeKey:r,inputId:s,value:n}=e;!r||!s||typeof sessionStorage>"u"||sessionStorage.setItem(k(r,s),JSON.stringify(n))}function y(e){let{scopeKey:r,inputId:s}=e;if(!r||!s||typeof sessionStorage>"u")return;let n=sessionStorage.getItem(k(r,s));if(n!==null)try{return JSON.parse(n)}catch (e2){return}}function _(e){let{scopeKey:r,inputId:s}=e;!r||!s||typeof sessionStorage>"u"||sessionStorage.removeItem(k(r,s))}function E(e){return _schemas.getInputItems.call(void 0, e).filter(r=>_optionalChain([r, 'access', _2 => _2.source, 'optionalAccess', _3 => _3.kind])==="client").map(r=>({paramId:r.paramId,displayName:_nullishCoalesce(r.displayName, () => (r.paramId))}))}function R(e,r,s){let n=new Set(E(e).map(t=>t.paramId)),a={};for(let t of e.inputs){if(n.has(t.id)){let i=s({scopeKey:r,inputId:t.id});i!==void 0&&(a[t.id]=i);continue}a[t.id]=_nullishCoalesce(t.default, () => (_schemas.getDefaultValue.call(void 0, t.paramType)))}for(let t of e.outputs)a[t.id]=null;return a}function x(e){let r=e===!1;return{hasPendingChanges:r,hasNeverSolved:r}}function I(e,r,s,n){return e.values[r]=s,n===!1?(e.pendingValues[r]=s,e.hasPendingChanges=!0,{state:e,shouldSolve:!1}):{state:e,shouldSolve:!0}}function C(e,r){if(!_optionalChain([e, 'optionalAccess', _4 => _4.inputs]))return r;let s={};for(let n of e.inputs)n.id in r&&(s[n.id]=r[n.id]);return s}function V(e,r){e.error="",e.computeErrors=_nullishCoalesce(r.errors, () => ([])),e.computeWarnings=_nullishCoalesce(r.warnings, () => ([])),e.meshes=_nullishCoalesce(r.meshes, () => ([]));let{meshes:s,...n}=r;return e.lastResult=n,Object.assign(e.values,r.outputs),e.pendingValues={},e.hasPendingChanges=!1,e.hasNeverSolved=!1,e}function Y(e){let r=e.schema,s=x(_optionalChain([r, 'optionalAccess', _5 => _5.instanceSolve])),n={values:R(r,e.scopeKey,y),error:"",computeErrors:[],computeWarnings:[],meshes:[],pendingValues:{},hasPendingChanges:s.hasPendingChanges,hasNeverSolved:s.hasNeverSolved,lastResult:null},a=new Set,t=()=>a.forEach(o=>o());function i(){e.driver.solve({...C(r,n.values)}),t()}return{get values(){return n.values},get error(){return n.error},get computeErrors(){return n.computeErrors},get computeWarnings(){return n.computeWarnings},get meshes(){return n.meshes},get lastResult(){return n.lastResult},get hasPendingChanges(){return n.hasPendingChanges},get hasNeverSolved(){return n.hasNeverSolved},get isSolving(){return e.driver.isSolving},setValue(o,l,u=!1){let{shouldSolve:f}=I(n,o,l,_optionalChain([r, 'optionalAccess', _6 => _6.instanceSolve]));f||u?(u&&!f&&(n.pendingValues={},n.hasPendingChanges=!1),i()):t()},solve(){i()},loadValues(o){Object.assign(n.values,o),_optionalChain([r, 'optionalAccess', _7 => _7.instanceSolve])!==!1?i():(n.hasPendingChanges=!0,t())},rebuild(o,l){r=o,_optionalChain([e, 'access', _8 => _8.driver, 'access', _9 => _9.clearCache, 'optionalCall', _10 => _10()]),n.meshes=[],n.lastResult=null,n.error="",n.computeErrors=[],n.computeWarnings=[],n.pendingValues={},n.values=R(o,l,y);let u=x(_optionalChain([o, 'optionalAccess', _11 => _11.instanceSolve]));n.hasPendingChanges=u.hasPendingChanges,n.hasNeverSolved=u.hasNeverSolved,o&&Object.keys(n.values).length>0&&o.instanceSolve!==!1?i():t()},report(o){V(n,o),t()},reportError(o){n.error=o,t()},subscribe(o){return a.add(o),()=>a.delete(o)},notify:t}}function P(e,r){let{runDeadlineMs:s,onChange:n}=r,a=!1,t=null,i=null;function o(p){a!==p&&(a=p,_optionalChain([n, 'optionalCall', _12 => _12()]))}function l(){_optionalChain([i, 'optionalAccess', _13 => _13.abort, 'call', _14 => _14()]),i=null}async function u(p){l(),i=new AbortController;let{signal:b}=i,d=setTimeout(()=>{console.warn(`[Solve/throttle] run exceeded ${s}ms \u2014 aborting`),_optionalChain([i, 'optionalAccess', _15 => _15.abort, 'call', _16 => _16()])},s);o(!0);try{await e(p,b)}catch(v){(!(v instanceof Error)||v.name!=="AbortError"&&v.name!=="TimeoutError")&&console.error("[Solve/throttle] unhandled error in run:",v)}finally{if(clearTimeout(d),o(!1),i=null,t!==null){let v=t;t=null,u(v)}}}function f(p){a?(t!==null&&console.debug("[Solve/throttle] superseded pending run (latest-wins)"),t=p):u(p)}function m(){t=null,l()}return{trigger:f,get isRunning(){return a},get hasPending(){return t!==null},cancel:m}}function F(e){return O(e)}function O(e){if(e===null||typeof e!="object")return _nullishCoalesce(JSON.stringify(e), () => ("null"));if(Array.isArray(e))return`[${e.map(O).join(",")}]`;let r=e;return`{${Object.keys(r).sort().map(n=>`${JSON.stringify(n)}:${O(r[n])}`).join(",")}}`}function $(e={}){let{max:r=16,meshPolicy:s}=e,n=new Map;function a(o){_optionalChain([o, 'access', _17 => _17.meshes, 'optionalAccess', _18 => _18.length])&&_optionalChain([s, 'optionalAccess', _19 => _19.release, 'call', _20 => _20(o.meshes)])}function t(o){return!s||!_optionalChain([o, 'access', _21 => _21.meshes, 'optionalAccess', _22 => _22.length])?o:{...o,meshes:s.clone(o.meshes)}}function i(o){let l=n.get(o);l!==void 0&&(n.delete(o),a(l))}return{get(o){let l=F(o),u=n.get(l);if(u!==void 0)return n.delete(l),n.set(l,u),console.info(`[Solve/memo] HIT \u2014 served from client memo (${n.size}/${r})`),t(u)},set(o,l){let u=F(o);for(i(u),n.set(u,t(l));n.size>r;){let f=n.keys().next().value;if(f===void 0)break;i(f),console.info(`[Solve/memo] evicted LRU entry (cap ${r})`)}},clear(){n.size>0&&console.info(`[Solve/memo] cleared ${n.size} entries (definition changed)`),n.forEach(a),n.clear()}}}function Q(e,r,s){let{meshPolicy:n,solveDeadlineMs:a,onChange:t}=s,i=$({meshPolicy:n}),o=P(async(l,u)=>{let f=i.get(l);if(f!==void 0){if(u.aborted)return;r().report(f);return}try{let m=await e(l,u);if(u.aborted){console.debug("[Solve/driver] solve completed after abort \u2014 result discarded");return}let p={...m,values:l};i.set(l,p),r().report(p)}catch(m){if(u.aborted){console.debug("[Solve/driver] solve aborted (superseded, cancelled, or timed out)");return}console.warn("[Solve/driver] solve failed:",m),r().reportError(m instanceof Error?m.message:String(m))}},{runDeadlineMs:a,onChange:t});return{solve(l){o.trigger(l)},cancel(){o.cancel()},get isSolving(){return o.isRunning},clearCache(){i.clear()}}}var _grasshopper = require('@selvajs/compute/grasshopper');function ee(e){let r={};if(!e)return r;for(let s of e.split(",")){let[n,...a]=s.split(";").map(o=>o.trim()),t=a.find(o=>o.startsWith("dur="));if(!n||!t)continue;let i=Number(t.slice(4));Number.isFinite(i)&&(r[n]=i)}return r}var ne=e=>{throw new Error(`Rate limit reached. Try again in ${Math.ceil(e)}s.`)},re=()=>{throw new Error("Your session has expired. Sign in again in a new tab, then re-run \u2014 your inputs are preserved.")};function oe(e){let r=_nullishCoalesce(e.debug, () => (!1)),s=(...a)=>{r&&console.info(...a)},n=0;return async(a,t)=>{let i=n-Date.now();if(i>0)throw new Error(`Rate limit reached. Try again in ${Math.ceil(i/1e3)}s.`);let o=performance.now(),l=e.inputs(),u=e.outputs(),f=_optionalChain([e, 'access', _23 => _23.channel, 'optionalCall', _24 => _24()]),m=_optionalChain([e, 'access', _25 => _25.versionId, 'optionalCall', _26 => _26()]),p=JSON.stringify({inputs:l,values:a,definitionUrl:e.definitionUrl(),...m?{versionId:m}:f==="draft"?{channel:"draft"}:{}}),b=JSON.stringify(a).length,d;try{d=await fetch(e.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:p,signal:t})}catch(c){if(t.aborted)return s("[Compute] solve aborted during fetch \u2014 empty result discarded"),{outputs:{}};throw new Error("Request blocked \u2014 your session may have expired. Reload the page to sign in again.",{cause:c})}if(t.aborted)return s("[Compute] solve aborted after headers \u2014 empty result discarded"),{outputs:{}};let v=d.redirected&&new URL(d.url).pathname==="/login";if((d.status===401||v)&&(_nullishCoalesce(e.onSessionExpired, () => (re)))(),!d.ok){if(d.status===503)throw new Error("Compute server is offline or unreachable. Please try again later.");let c=await d.text().catch(()=>""),h={};try{h=JSON.parse(c)}catch (e3){c&&console.warn(`[Compute] non-JSON error body (HTTP ${d.status}):`,c.slice(0,300))}if(d.status===429){let S=Number(d.headers.get("Retry-After"))||Number(h.retryAfter)||5;n=Date.now()+S*1e3,(_nullishCoalesce(e.onRateLimited, () => (ne)))(S)}throw new Error(h.message||`Compute error (HTTP ${d.status})`)}let j=performance.now()-o,K=performance.now(),N=await d.text();if(t.aborted)return s("[Compute] solve aborted mid-download \u2014 empty result discarded"),{outputs:{}};let w=performance.now()-K,A=N.length,g;try{g=JSON.parse(N)}catch(c){throw new Error("Received an invalid response from the server. Reload the page and try again.",{cause:c})}let T=new (0, _grasshopper.GrasshopperResponseProcessor)(g,!1),J=e.meshes?await e.meshes.extract(T.response,{debug:r}):[],D={};for(let c of u){let h=T.getValue({byId:c.id},{parseValues:!0});D[c.id]=_nullishCoalesce(h, () => ((c.nickname?T.getValue({byName:c.nickname},{parseValues:!0}):void 0)))}if(r){let c=ee(d.headers.get("Server-Timing")),h=_nullishCoalesce(c.total, () => (0)),S=Math.max(0,j-h),M=A/(1024*1024),B=M>=1?`${M.toFixed(2)} MB`:`${(A/1024).toFixed(0)} KB`,z=w>0?(M/(w/1e3)).toFixed(1):"\u221E",U=_optionalChain([performance, 'access', _27 => _27.memory, 'optionalAccess', _28 => _28.usedJSHeapSize]),q=U!==void 0?` | heap=${(U/(1024*1024)).toFixed(0)} MB`:"";if(s(`[Compute] req=${(p.length/1024).toFixed(0)}KB (values ${(b/1024).toFixed(0)}KB) | ttfb=${j.toFixed(0)}ms (network\u2248${S.toFixed(0)} + server ${h.toFixed(0)}) | download=${w.toFixed(0)}ms (${B} @ ${z} MB/s)${q}`),c.selva_cache!==void 0){let W=c.selva_cache?"HIT \u2014 served without calling compute":"miss \u2014 solved on Rhino.Compute";s(`[Compute] \u2514\u2500 cache: ${W}`)}}return{outputs:D,meshes:J,errors:_nullishCoalesce(g.errors, () => ([])),warnings:_nullishCoalesce(g.warnings, () => ([])),source:g}}}exports.applySolveResult = V; exports.applyValueChange = I; exports.buildInitialValues = R; exports.clearExternalValue = _; exports.createAsyncThrottle = P; exports.createComputeFetchSolveFn = oe; exports.createRequestResponseDriver = Q; exports.createSolveMemo = $; exports.createSolveSession = Y; exports.getExternalInputs = E; exports.makeInitialFlags = x; exports.pickInputValues = C; exports.readExternalValue = y; exports.stableInputKey = F; exports.writeExternalValue = L;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@selvajs/schemas"),t=require("@selvajs/compute/grasshopper");function n(e,t){return`external:${e}:${t}`}function r(e){let{scopeKey:t,inputId:r,value:i}=e;!t||!r||typeof sessionStorage>`u`||sessionStorage.setItem(n(t,r),JSON.stringify(i))}function i(e){let{scopeKey:t,inputId:r}=e;if(!t||!r||typeof sessionStorage>`u`)return;let i=sessionStorage.getItem(n(t,r));if(i!==null)try{return JSON.parse(i)}catch{return}}function a(e){let{scopeKey:t,inputId:r}=e;!t||!r||typeof sessionStorage>`u`||sessionStorage.removeItem(n(t,r))}function o(t){return(0,e.getInputItems)(t).filter(e=>e.source?.kind===`client`).map(e=>({paramId:e.paramId,displayName:e.displayName??e.paramId}))}function s(t,n,r){let i=new Set(o(t).map(e=>e.paramId)),a={};for(let o of t.inputs){if(i.has(o.id)){let e=r({scopeKey:n,inputId:o.id});e!==void 0&&(a[o.id]=e);continue}a[o.id]=o.default??(0,e.getDefaultValue)(o.paramType)}for(let e of t.outputs)a[e.id]=null;return a}function c(e){let t=e===!1;return{hasPendingChanges:t,hasNeverSolved:t}}function l(e,t,n,r){return e.values[t]=n,r===!1?(e.pendingValues[t]=n,e.hasPendingChanges=!0,{state:e,shouldSolve:!1}):{state:e,shouldSolve:!0}}function u(e,t){if(!e?.inputs)return t;let n={};for(let r of e.inputs)r.id in t&&(n[r.id]=t[r.id]);return n}function d(e,t){e.error=``,e.computeErrors=t.errors??[],e.computeWarnings=t.warnings??[],e.meshes=t.meshes??[];let{meshes:n,...r}=t;return e.lastResult=r,Object.assign(e.values,t.outputs),e.pendingValues={},e.hasPendingChanges=!1,e.hasNeverSolved=!1,e}function f(e){let t=e.schema,n=c(t?.instanceSolve),r={values:s(t,e.scopeKey,i),error:``,computeErrors:[],computeWarnings:[],meshes:[],pendingValues:{},hasPendingChanges:n.hasPendingChanges,hasNeverSolved:n.hasNeverSolved,lastResult:null},a=new Set,o=()=>a.forEach(e=>e());function f(){e.driver.solve({...u(t,r.values)}),o()}return{get values(){return r.values},get error(){return r.error},get computeErrors(){return r.computeErrors},get computeWarnings(){return r.computeWarnings},get meshes(){return r.meshes},get lastResult(){return r.lastResult},get hasPendingChanges(){return r.hasPendingChanges},get hasNeverSolved(){return r.hasNeverSolved},get isSolving(){return e.driver.isSolving},setValue(e,n,i=!1){let{shouldSolve:a}=l(r,e,n,t?.instanceSolve);a||i?(i&&!a&&(r.pendingValues={},r.hasPendingChanges=!1),f()):o()},solve(){f()},loadValues(e){Object.assign(r.values,e),t?.instanceSolve===!1?(r.hasPendingChanges=!0,o()):f()},rebuild(n,a){t=n,e.driver.clearCache?.(),r.meshes=[],r.lastResult=null,r.error=``,r.computeErrors=[],r.computeWarnings=[],r.pendingValues={},r.values=s(n,a,i);let l=c(n?.instanceSolve);r.hasPendingChanges=l.hasPendingChanges,r.hasNeverSolved=l.hasNeverSolved,n&&Object.keys(r.values).length>0&&n.instanceSolve!==!1?f():o()},report(e){d(r,e),o()},reportError(e){r.error=e,o()},subscribe(e){return a.add(e),()=>a.delete(e)},notify:o}}function p(e,t){let{runDeadlineMs:n,onChange:r}=t,i=!1,a=null,o=null;function s(e){i!==e&&(i=e,r?.())}function c(){o?.abort(),o=null}async function l(t){c(),o=new AbortController;let{signal:r}=o,i=setTimeout(()=>{console.warn(`[Solve/throttle] run exceeded ${n}ms — aborting`),o?.abort()},n);s(!0);try{await e(t,r)}catch(e){(!(e instanceof Error)||e.name!==`AbortError`&&e.name!==`TimeoutError`)&&console.error(`[Solve/throttle] unhandled error in run:`,e)}finally{if(clearTimeout(i),s(!1),o=null,a!==null){let e=a;a=null,l(e)}}}function u(e){i?(a!==null&&console.debug(`[Solve/throttle] superseded pending run (latest-wins)`),a=e):l(e)}function d(){a=null,c()}return{trigger:u,get isRunning(){return i},get hasPending(){return a!==null},cancel:d}}function m(e){return h(e)}function h(e){if(typeof e!=`object`||!e)return JSON.stringify(e)??`null`;if(Array.isArray(e))return`[${e.map(h).join(`,`)}]`;let t=e;return`{${Object.keys(t).sort().map(e=>`${JSON.stringify(e)}:${h(t[e])}`).join(`,`)}}`}function g(e={}){let{max:t=16,meshPolicy:n}=e,r=new Map;function i(e){e.meshes?.length&&n?.release(e.meshes)}function a(e){return!n||!e.meshes?.length?e:{...e,meshes:n.clone(e.meshes)}}function o(e){let t=r.get(e);t!==void 0&&(r.delete(e),i(t))}return{get(e){let n=m(e),i=r.get(n);if(i!==void 0)return r.delete(n),r.set(n,i),console.info(`[Solve/memo] HIT — served from client memo (${r.size}/${t})`),a(i)},set(e,n){let i=m(e);for(o(i),r.set(i,a(n));r.size>t;){let e=r.keys().next().value;if(e===void 0)break;o(e),console.info(`[Solve/memo] evicted LRU entry (cap ${t})`)}},clear(){r.size>0&&console.info(`[Solve/memo] cleared ${r.size} entries (definition changed)`),r.forEach(i),r.clear()}}}function _(e,t,n){let{meshPolicy:r,solveDeadlineMs:i,onChange:a}=n,o=g({meshPolicy:r}),s=p(async(n,r)=>{let i=o.get(n);if(i!==void 0){if(r.aborted)return;t().report(i);return}try{let i=await e(n,r);if(r.aborted){console.debug(`[Solve/driver] solve completed after abort — result discarded`);return}let a={...i,values:n};o.set(n,a),t().report(a)}catch(e){if(r.aborted){console.debug(`[Solve/driver] solve aborted (superseded, cancelled, or timed out)`);return}console.warn(`[Solve/driver] solve failed:`,e),t().reportError(e instanceof Error?e.message:String(e))}},{runDeadlineMs:i,onChange:a});return{solve(e){s.trigger(e)},cancel(){s.cancel()},get isSolving(){return s.isRunning},clearCache(){o.clear()}}}function v(e){let t={};if(!e)return t;for(let n of e.split(`,`)){let[e,...r]=n.split(`;`).map(e=>e.trim()),i=r.find(e=>e.startsWith(`dur=`));if(!e||!i)continue;let a=Number(i.slice(4));Number.isFinite(a)&&(t[e]=a)}return t}const y=e=>{throw Error(`Rate limit reached. Try again in ${Math.ceil(e)}s.`)},b=()=>{throw Error(`Your session has expired. Sign in again in a new tab, then re-run — your inputs are preserved.`)};function x(e){let n=e.debug??!1,r=(...e)=>{n&&console.info(...e)},i=0;return async(a,o)=>{let s=i-Date.now();if(s>0)throw Error(`Rate limit reached. Try again in ${Math.ceil(s/1e3)}s.`);let c=performance.now(),l=e.inputs(),u=e.outputs(),d=e.channel?.(),f=e.versionId?.(),p=JSON.stringify({inputs:l,values:a,definitionUrl:e.definitionUrl(),...f?{versionId:f}:d===`draft`?{channel:`draft`}:{}}),m=JSON.stringify(a).length,h;try{h=await fetch(e.endpoint,{method:`POST`,headers:{"Content-Type":`application/json`},body:p,signal:o})}catch(e){if(o.aborted)return r(`[Compute] solve aborted during fetch — empty result discarded`),{outputs:{}};throw Error(`Request blocked — your session may have expired. Reload the page to sign in again.`,{cause:e})}if(o.aborted)return r(`[Compute] solve aborted after headers — empty result discarded`),{outputs:{}};let g=h.redirected&&new URL(h.url).pathname===`/login`;if((h.status===401||g)&&(e.onSessionExpired??b)(),!h.ok){if(h.status===503)throw Error(`Compute server is offline or unreachable. Please try again later.`);let t=await h.text().catch(()=>``),n={};try{n=JSON.parse(t)}catch{t&&console.warn(`[Compute] non-JSON error body (HTTP ${h.status}):`,t.slice(0,300))}if(h.status===429){let t=Number(h.headers.get(`Retry-After`))||Number(n.retryAfter)||5;i=Date.now()+t*1e3,(e.onRateLimited??y)(t)}throw Error(n.message||`Compute error (HTTP ${h.status})`)}let _=performance.now()-c,x=performance.now(),S=await h.text();if(o.aborted)return r(`[Compute] solve aborted mid-download — empty result discarded`),{outputs:{}};let C=performance.now()-x,w=S.length,T;try{T=JSON.parse(S)}catch(e){throw Error(`Received an invalid response from the server. Reload the page and try again.`,{cause:e})}let E=new t.GrasshopperResponseProcessor(T,!1),D=e.meshes?await e.meshes.extract(E.response,{debug:n}):[],O={};for(let e of u){let t=E.getValue({byId:e.id},{parseValues:!0});O[e.id]=t??(e.nickname?E.getValue({byName:e.nickname},{parseValues:!0}):void 0)}if(n){let e=v(h.headers.get(`Server-Timing`)),t=e.total??0,n=Math.max(0,_-t),i=w/1048576,a=i>=1?`${i.toFixed(2)} MB`:`${(w/1024).toFixed(0)} KB`,o=C>0?(i/(C/1e3)).toFixed(1):`∞`,s=performance.memory?.usedJSHeapSize,c=s===void 0?``:` | heap=${(s/1048576).toFixed(0)} MB`;if(r(`[Compute] req=${(p.length/1024).toFixed(0)}KB (values ${(m/1024).toFixed(0)}KB) | ttfb=${_.toFixed(0)}ms (network≈${n.toFixed(0)} + server ${t.toFixed(0)}) | download=${C.toFixed(0)}ms (${a} @ ${o} MB/s)${c}`),e.selva_cache!==void 0){let t=e.selva_cache?`HIT — served without calling compute`:`miss — solved on Rhino.Compute`;r(`[Compute] └─ cache: ${t}`)}}return{outputs:O,meshes:D,errors:T.errors??[],warnings:T.warnings??[],source:T}}}exports.applySolveResult=d,exports.applyValueChange=l,exports.buildInitialValues=s,exports.clearExternalValue=a,exports.createAsyncThrottle=p,exports.createComputeFetchSolveFn=x,exports.createRequestResponseDriver=_,exports.createSolveMemo=g,exports.createSolveSession=f,exports.getExternalInputs=o,exports.makeInitialFlags=c,exports.pickInputValues=u,exports.readExternalValue=i,exports.stableInputKey=m,exports.writeExternalValue=r;
2
2
  //# sourceMappingURL=client.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client/external-storage.ts"],"names":["STORAGE_PREFIX","makeKey","scopeKey","inputId"],"mappings":"AAMA,4tBAA8B,IAExBA,CAAAA,CAAiB,UAAA,CAEvB,SAASC,CAAAA,CAAQC,CAAAA,CAAkBC,CAAAA,CAAyB,CAC3D,MAAO,CAAA,EAAA","file":"/home/runner/work/selva/selva/packages/solve/dist/client.cjs","sourcesContent":["// Transit storage for inputs with source.kind === 'client': a producer route writes the\n// value here, the solver route reads it back. Keyed by (scopeKey, inputId) so values\n// don't bleed across solver contexts — scopeKey is whatever uniquely identifies one\n// (sessionId in plugin-ui/preview, definition guid in selva/library).\n\nimport type { UISchema } from '@selvajs/schemas';\nimport { getInputItems } from '@selvajs/schemas';\n\nconst STORAGE_PREFIX = 'external';\n\nfunction makeKey(scopeKey: string, inputId: string): string {\n\treturn `${STORAGE_PREFIX}:${scopeKey}:${inputId}`;\n}\n\nexport interface ExternalValueRef {\n\tscopeKey: string;\n\tinputId: string;\n}\n\nexport function writeExternalValue(args: ExternalValueRef & { value: unknown }): void {\n\tconst { scopeKey, inputId, value } = args;\n\tif (!scopeKey || !inputId) return;\n\tif (typeof sessionStorage === 'undefined') return;\n\tsessionStorage.setItem(makeKey(scopeKey, inputId), JSON.stringify(value));\n}\n\nexport function readExternalValue(ref: ExternalValueRef): unknown | undefined {\n\tconst { scopeKey, inputId } = ref;\n\tif (!scopeKey || !inputId) return undefined;\n\tif (typeof sessionStorage === 'undefined') return undefined;\n\tconst raw = sessionStorage.getItem(makeKey(scopeKey, inputId));\n\tif (raw === null) return undefined;\n\ttry {\n\t\treturn JSON.parse(raw);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport function clearExternalValue(ref: ExternalValueRef): void {\n\tconst { scopeKey, inputId } = ref;\n\tif (!scopeKey || !inputId) return;\n\tif (typeof sessionStorage === 'undefined') return;\n\tsessionStorage.removeItem(makeKey(scopeKey, inputId));\n}\n\nexport interface ExternalInput {\n\tparamId: string;\n\tdisplayName: string;\n}\n\nexport function getExternalInputs(schema: UISchema): ExternalInput[] {\n\treturn getInputItems(schema)\n\t\t.filter((item) => item.source?.kind === 'client')\n\t\t.map((item) => ({\n\t\t\tparamId: item.paramId,\n\t\t\tdisplayName: item.displayName ?? item.paramId\n\t\t}));\n}\n"]}
1
+ {"version":3,"file":"client.cjs","names":["getInputItems","getDefaultValue","GrasshopperResponseProcessor"],"sources":["../src/client/external-storage.ts","../src/client/solve-session-core.ts","../src/client/solve-session.ts","../src/client/async-throttle.ts","../src/client/solve-memo.ts","../src/client/drivers/request-response.ts","../src/client/compute-fetch-solve-fn.ts"],"sourcesContent":["// Transit storage for inputs with source.kind === 'client': a producer route writes the\n// value here, the solver route reads it back. Keyed by (scopeKey, inputId) so values\n// don't bleed across solver contexts — scopeKey is whatever uniquely identifies one\n// (sessionId in plugin-ui/preview, definition guid in selva/library).\n\nimport type { UISchema } from '@selvajs/schemas';\nimport { getInputItems } from '@selvajs/schemas';\n\nconst STORAGE_PREFIX = 'external';\n\nfunction makeKey(scopeKey: string, inputId: string): string {\n\treturn `${STORAGE_PREFIX}:${scopeKey}:${inputId}`;\n}\n\nexport interface ExternalValueRef {\n\tscopeKey: string;\n\tinputId: string;\n}\n\nexport function writeExternalValue(args: ExternalValueRef & { value: unknown }): void {\n\tconst { scopeKey, inputId, value } = args;\n\tif (!scopeKey || !inputId) return;\n\tif (typeof sessionStorage === 'undefined') return;\n\tsessionStorage.setItem(makeKey(scopeKey, inputId), JSON.stringify(value));\n}\n\nexport function readExternalValue(ref: ExternalValueRef): unknown | undefined {\n\tconst { scopeKey, inputId } = ref;\n\tif (!scopeKey || !inputId) return undefined;\n\tif (typeof sessionStorage === 'undefined') return undefined;\n\tconst raw = sessionStorage.getItem(makeKey(scopeKey, inputId));\n\tif (raw === null) return undefined;\n\ttry {\n\t\treturn JSON.parse(raw);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport function clearExternalValue(ref: ExternalValueRef): void {\n\tconst { scopeKey, inputId } = ref;\n\tif (!scopeKey || !inputId) return;\n\tif (typeof sessionStorage === 'undefined') return;\n\tsessionStorage.removeItem(makeKey(scopeKey, inputId));\n}\n\nexport interface ExternalInput {\n\tparamId: string;\n\tdisplayName: string;\n}\n\nexport function getExternalInputs(schema: UISchema): ExternalInput[] {\n\treturn getInputItems(schema)\n\t\t.filter((item) => item.source?.kind === 'client')\n\t\t.map((item) => ({\n\t\t\tparamId: item.paramId,\n\t\t\tdisplayName: item.displayName ?? item.paramId\n\t\t}));\n}\n","// Pure transition logic for a Solve Session.\n//\n// This module holds the value/lifecycle state machine with no transport and no state\n// ownership: how values are seeded (including client-sourced hydration), when a value\n// change should dispatch a solve vs. defer it, and what a reported solve result does to\n// the flags. `solve-session.ts` is a thin shell that owns the state object and the\n// subscriber set; every decision lives here, which is what makes it directly testable.\n\nimport type { UISchema } from '@selvajs/schemas';\nimport { getDefaultValue } from '@selvajs/schemas';\nimport { getExternalInputs, type ExternalValueRef } from './external-storage.js';\nimport type { SolveResult } from '../shared/solve-fn.js';\n\n/**\n * The slice of a reported result the session keeps addressable, so a host can commit exactly\n * what the viewer is showing — `source` and `values` included, already memo-correct.\n *\n * Mesh-free by construction. `SolveResult.meshes` are GPU-backed and the viewer disposes what\n * it renders on the next scene update, which is why the memo carries a `MeshPolicy`\n * clone/release contract at all. Retaining them here would hand out disposed instances after\n * the next solve, with no policy governing them and no owner. Everything left is inert JSON;\n * live meshes stay on `session.meshes`.\n */\nexport type RetainedSolveResult<TSource = unknown> = Omit<SolveResult<never, TSource>, 'meshes'>;\n\nexport interface SolveSessionState {\n\tvalues: Record<string, unknown>;\n\terror: string;\n\tcomputeErrors: string[];\n\tcomputeWarnings: string[];\n\tmeshes: unknown[];\n\t/** Values changed since the last solve, in manual (instanceSolve === false) mode. */\n\tpendingValues: Record<string, unknown>;\n\thasPendingChanges: boolean;\n\thasNeverSolved: boolean;\n\t/**\n\t * The last result reported, minus its meshes. Null before the first solve.\n\t *\n\t * Lags `values` by design: nothing updates it on `setValue` or `loadValues`, so between a\n\t * value change and the next report it describes the *previous* input set. That is what a\n\t * commit gate wants — what is on screen, not what is pending — so `lastResult.values`\n\t * disagreeing with `state.values` mid-scrub is the feature, not a bug.\n\t */\n\tlastResult: RetainedSolveResult | null;\n}\n\nexport type ExternalReader = (ref: ExternalValueRef) => unknown | undefined;\n\n/**\n * Client-sourced inputs are hydrated from `read` and left absent when no stored value\n * exists, so the missing-inputs panel can detect them. Other inputs fall back to their\n * declared default, then the paramType default.\n */\nexport function buildInitialValues(\n\tschema: UISchema,\n\tscopeKey: string,\n\tread: ExternalReader\n): Record<string, unknown> {\n\tconst clientSet = new Set(getExternalInputs(schema).map((e) => e.paramId));\n\tconst values: Record<string, unknown> = {};\n\tfor (const input of schema.inputs) {\n\t\tif (clientSet.has(input.id)) {\n\t\t\tconst stored = read({ scopeKey, inputId: input.id });\n\t\t\tif (stored !== undefined) values[input.id] = stored;\n\t\t\tcontinue;\n\t\t}\n\t\tvalues[input.id] = input.default ?? getDefaultValue(input.paramType);\n\t}\n\tfor (const output of schema.outputs) {\n\t\tvalues[output.id] = null;\n\t}\n\treturn values;\n}\n\n/** Manual-solve schemas (instanceSolve === false) start dirty; auto-solve schemas start clean. */\nexport function makeInitialFlags(instanceSolve: boolean | undefined): {\n\thasPendingChanges: boolean;\n\thasNeverSolved: boolean;\n} {\n\tconst manual = instanceSolve === false;\n\treturn { hasPendingChanges: manual, hasNeverSolved: manual };\n}\n\n/** Manual mode defers (records the pending value, raises the dirty flag) instead of solving. */\nexport function applyValueChange(\n\tstate: SolveSessionState,\n\tid: string,\n\tvalue: unknown,\n\tinstanceSolve: boolean | undefined\n): { state: SolveSessionState; shouldSolve: boolean } {\n\tstate.values[id] = value;\n\tif (instanceSolve === false) {\n\t\tstate.pendingValues[id] = value;\n\t\tstate.hasPendingChanges = true;\n\t\treturn { state, shouldSolve: false };\n\t}\n\treturn { state, shouldSolve: true };\n}\n\n/**\n * Solve outputs live in the same `values` map as inputs (so widgets like dynamic value\n * lists can read them) but must not be echoed back to the driver: a measured 6.4 MB\n * options-list output showed this can re-upload a multi-MB payload no backend reads.\n */\nexport function pickInputValues(\n\tschema: UISchema | undefined,\n\tvalues: Record<string, unknown>\n): Record<string, unknown> {\n\tif (!schema?.inputs) return values;\n\tconst picked: Record<string, unknown> = {};\n\tfor (const input of schema.inputs) {\n\t\tif (input.id in values) picked[input.id] = values[input.id];\n\t}\n\treturn picked;\n}\n\nexport function applySolveResult(state: SolveSessionState, result: SolveResult): SolveSessionState {\n\tstate.error = '';\n\tstate.computeErrors = result.errors ?? [];\n\tstate.computeWarnings = result.warnings ?? [];\n\tstate.meshes = result.meshes ?? [];\n\tconst { meshes: _meshes, ...retained } = result;\n\tstate.lastResult = retained;\n\tObject.assign(state.values, result.outputs);\n\tstate.pendingValues = {};\n\tstate.hasPendingChanges = false;\n\tstate.hasNeverSolved = false;\n\treturn state;\n}\n","// A framework-free shell over the pure transition logic in solve-session-core.ts: owns the\n// live values/flags, delegates every transition to the core, and drives solves through a\n// transport-agnostic SolveDriver.\n//\n// State is exposed as plain getters; it carries no framework reactivity of its own, so a\n// Svelte host must wrap it — see `useSolveSession.svelte.ts` in `@selvajs/ui`, which\n// republishes these getters as $state. Reading a getter without subscribing gives a\n// correct value but will not re-render.\n\nimport type { UISchema } from '@selvajs/schemas';\nimport { readExternalValue } from './external-storage.js';\nimport type { SolveResult } from '../shared/solve-fn.js';\nimport type { SolveDriver } from './drivers/driver.js';\nimport {\n\tbuildInitialValues,\n\tmakeInitialFlags,\n\tapplyValueChange,\n\tapplySolveResult,\n\tpickInputValues,\n\ttype SolveSessionState,\n\ttype RetainedSolveResult\n} from './solve-session-core.js';\n\nexport interface SolveSession {\n\treadonly values: Record<string, unknown>;\n\treadonly error: string;\n\treadonly computeErrors: string[];\n\treadonly computeWarnings: string[];\n\treadonly meshes: unknown[];\n\t/**\n\t * The last reported result without its meshes — what the viewer is currently showing,\n\t * including the `source`/`values` pair a commit path needs. Null before the first solve,\n\t * and again after `rebuild()`. Survives `reportError`: a failed solve leaves the last good\n\t * geometry on screen, so a host committing what it sees should still see what produced it.\n\t */\n\treadonly lastResult: RetainedSolveResult | null;\n\treadonly hasPendingChanges: boolean;\n\treadonly hasNeverSolved: boolean;\n\treadonly isSolving: boolean;\n\t/** `forceSolve` overrides manual mode for system-initiated reconciliation (e.g. a dynamic value list pruning a vanished selection), so the output can't lag behind the new value. */\n\tsetValue(id: string, value: unknown, forceSolve?: boolean): void;\n\tsolve(): void;\n\t/** Merges incoming values, then solves (auto) or marks dirty (manual). */\n\tloadValues(incoming: Record<string, unknown>): void;\n\trebuild(schema: UISchema, scopeKey: string): void;\n\treport(result: SolveResult): void;\n\treportError(message: string): void;\n\t/** Fires after any mutation of the getters above, including driver-reported `isSolving` transitions. */\n\tsubscribe(listener: () => void): () => void;\n\t/** For driver-owned state the session only forwards: `isSolving` lives on the driver, so wire this to its `onChange`. */\n\tnotify(): void;\n}\n\nexport interface SolveSessionArgs {\n\tschema: UISchema;\n\tscopeKey: string;\n\tdriver: SolveDriver;\n}\n\nexport function createSolveSession(args: SolveSessionArgs): SolveSession {\n\tlet currentSchema = args.schema;\n\n\tconst flags = makeInitialFlags(currentSchema?.instanceSolve);\n\tconst state: SolveSessionState = {\n\t\tvalues: buildInitialValues(currentSchema, args.scopeKey, readExternalValue),\n\t\terror: '',\n\t\tcomputeErrors: [],\n\t\tcomputeWarnings: [],\n\t\tmeshes: [],\n\t\tpendingValues: {},\n\t\thasPendingChanges: flags.hasPendingChanges,\n\t\thasNeverSolved: flags.hasNeverSolved,\n\t\tlastResult: null\n\t};\n\n\tconst listeners = new Set<() => void>();\n\tconst emit = () => listeners.forEach((l) => l());\n\n\tfunction dispatch() {\n\t\t// Copy: state.values is the live map, and a driver may hold the payload across an\n\t\t// async solve — a later setValue must not mutate what's already in flight.\n\t\targs.driver.solve({ ...pickInputValues(currentSchema, state.values) });\n\t\temit();\n\t}\n\n\treturn {\n\t\tget values() {\n\t\t\treturn state.values;\n\t\t},\n\t\tget error() {\n\t\t\treturn state.error;\n\t\t},\n\t\tget computeErrors() {\n\t\t\treturn state.computeErrors;\n\t\t},\n\t\tget computeWarnings() {\n\t\t\treturn state.computeWarnings;\n\t\t},\n\t\tget meshes() {\n\t\t\treturn state.meshes;\n\t\t},\n\t\tget lastResult() {\n\t\t\treturn state.lastResult;\n\t\t},\n\t\tget hasPendingChanges() {\n\t\t\treturn state.hasPendingChanges;\n\t\t},\n\t\tget hasNeverSolved() {\n\t\t\treturn state.hasNeverSolved;\n\t\t},\n\t\tget isSolving() {\n\t\t\treturn args.driver.isSolving;\n\t\t},\n\n\t\tsetValue(id, value, forceSolve = false) {\n\t\t\tconst { shouldSolve } = applyValueChange(state, id, value, currentSchema?.instanceSolve);\n\t\t\tif (shouldSolve || forceSolve) {\n\t\t\t\tif (forceSolve && !shouldSolve) {\n\t\t\t\t\tstate.pendingValues = {};\n\t\t\t\t\tstate.hasPendingChanges = false;\n\t\t\t\t}\n\t\t\t\tdispatch();\n\t\t\t} else {\n\t\t\t\temit();\n\t\t\t}\n\t\t},\n\n\t\tsolve() {\n\t\t\tdispatch();\n\t\t},\n\n\t\tloadValues(incoming) {\n\t\t\tObject.assign(state.values, incoming);\n\t\t\tif (currentSchema?.instanceSolve !== false) {\n\t\t\t\tdispatch();\n\t\t\t} else {\n\t\t\t\tstate.hasPendingChanges = true;\n\t\t\t\temit();\n\t\t\t}\n\t\t},\n\n\t\trebuild(schema, scopeKey) {\n\t\t\tcurrentSchema = schema;\n\t\t\t// The new definition has its own input space; a matching input key from the prior\n\t\t\t// one must not serve that definition's cached result.\n\t\t\targs.driver.clearCache?.();\n\t\t\tstate.meshes = [];\n\t\t\t// Same reason as clearCache: a retained result belongs to the previous definition.\n\t\t\tstate.lastResult = null;\n\t\t\tstate.error = '';\n\t\t\tstate.computeErrors = [];\n\t\t\tstate.computeWarnings = [];\n\t\t\tstate.pendingValues = {};\n\t\t\tstate.values = buildInitialValues(schema, scopeKey, readExternalValue);\n\t\t\tconst f = makeInitialFlags(schema?.instanceSolve);\n\t\t\tstate.hasPendingChanges = f.hasPendingChanges;\n\t\t\tstate.hasNeverSolved = f.hasNeverSolved;\n\t\t\tif (schema && Object.keys(state.values).length > 0 && schema.instanceSolve !== false) {\n\t\t\t\tdispatch();\n\t\t\t} else {\n\t\t\t\temit();\n\t\t\t}\n\t\t},\n\n\t\treport(result) {\n\t\t\tapplySolveResult(state, result);\n\t\t\temit();\n\t\t},\n\n\t\treportError(message) {\n\t\t\tstate.error = message;\n\t\t\temit();\n\t\t},\n\n\t\tsubscribe(listener) {\n\t\t\tlisteners.add(listener);\n\t\t\treturn () => listeners.delete(listener);\n\t\t},\n\n\t\tnotify: emit\n\t};\n}\n","/**\n * Single-in-flight, latest-wins throttle for any async operation: only one run at a\n * time, a newly triggered value overwrites the single pending slot (no queue), and a\n * stale run can be aborted via `AbortController` or timeout.\n *\n * Framework-free: `isRunning` is a plain getter, not a store. A reactive host must\n * subscribe via `onChange` (see `@selvajs/ui`'s rune adapter) — polling the getter\n * directly reads correct values but won't trigger a re-render.\n */\ninterface AsyncThrottleOptions {\n\t/**\n\t * How long one run may take before it is aborted (ms). Required and deliberately\n\t * undefaulted: this is a generic throttle, so it has no basis for guessing what\n\t * the caller's work costs. Callers driving a Selva solve pass the deadline the\n\t * server enforces (`COMPUTE_SOLVE_DEADLINE_MS`) — a shorter local guess would abort\n\t * solves the server would have finished.\n\t */\n\trunDeadlineMs: number;\n\tonChange?: () => void;\n}\n\nexport interface AsyncThrottle<T> {\n\ttrigger: (values: T) => void;\n\treadonly isRunning: boolean;\n\treadonly hasPending: boolean;\n\tcancel: () => void;\n}\n\nexport function createAsyncThrottle<T>(\n\trun: (values: T, signal: AbortSignal) => Promise<void>,\n\toptions: AsyncThrottleOptions\n): AsyncThrottle<T> {\n\tconst { runDeadlineMs, onChange } = options;\n\n\tlet isRunning = false;\n\tlet pendingValues: T | null = null;\n\tlet currentAbortController: AbortController | null = null;\n\n\tfunction setRunning(next: boolean) {\n\t\tif (isRunning === next) return;\n\t\tisRunning = next;\n\t\tonChange?.();\n\t}\n\n\tfunction abortCurrent() {\n\t\tcurrentAbortController?.abort();\n\t\tcurrentAbortController = null;\n\t}\n\n\tasync function execute(values: T) {\n\t\tabortCurrent();\n\n\t\tcurrentAbortController = new AbortController();\n\t\tconst { signal } = currentAbortController;\n\t\tconst deadlineId = setTimeout(() => {\n\t\t\t// Cleared in `finally` on every other path, so firing means a genuine\n\t\t\t// timeout — the only signal for it (the abort itself is swallowed below).\n\t\t\tconsole.warn(`[Solve/throttle] run exceeded ${runDeadlineMs}ms — aborting`);\n\t\t\tcurrentAbortController?.abort();\n\t\t}, runDeadlineMs);\n\n\t\tsetRunning(true);\n\t\ttry {\n\t\t\tawait run(values, signal);\n\t\t} catch (err) {\n\t\t\t// AbortError is expected (timeout or cancel). Non-abort errors must be\n\t\t\t// handled inside `run` — re-throwing here would produce an unhandled\n\t\t\t// rejection because `execute` is always called fire-and-forget.\n\t\t\tif (!(err instanceof Error) || (err.name !== 'AbortError' && err.name !== 'TimeoutError')) {\n\t\t\t\tconsole.error('[Solve/throttle] unhandled error in run:', err);\n\t\t\t}\n\t\t} finally {\n\t\t\tclearTimeout(deadlineId);\n\t\t\tsetRunning(false);\n\t\t\tcurrentAbortController = null;\n\n\t\t\tif (pendingValues !== null) {\n\t\t\t\tconst next = pendingValues;\n\t\t\t\tpendingValues = null;\n\t\t\t\texecute(next);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction trigger(values: T) {\n\t\tif (isRunning) {\n\t\t\tif (pendingValues !== null) {\n\t\t\t\t// Latest-wins: the previously-queued values are dropped, not run.\n\t\t\t\t// `debug`, not `info`: a slider scrub fires this per frame, and it is a trace of\n\t\t\t\t// normal operation. Promoting it would spam a host's console on every drag.\n\t\t\t\t// eslint-disable-next-line no-console -- see above\n\t\t\t\tconsole.debug('[Solve/throttle] superseded pending run (latest-wins)');\n\t\t\t}\n\t\t\tpendingValues = values;\n\t\t} else {\n\t\t\texecute(values);\n\t\t}\n\t}\n\n\tfunction cancel() {\n\t\tpendingValues = null;\n\t\tabortCurrent();\n\t}\n\n\treturn {\n\t\ttrigger,\n\t\tget isRunning() {\n\t\t\treturn isRunning;\n\t\t},\n\t\tget hasPending() {\n\t\t\treturn pendingValues !== null;\n\t\t},\n\t\tcancel\n\t};\n}\n","// LRU cache of solve results keyed on a stable serialization of the inputs, so re-solving\n// something already seen this session (e.g. dragging a slider back) returns instantly\n// instead of round-tripping.\n//\n// A viewer typically takes ownership of every mesh it renders, disposing the previous\n// content on the next update. So the memo can't hand out its own stored instances (they'd\n// get disposed under it) or drop entries silently (their GPU buffers would leak): it keeps\n// private copies via an injected clone/release policy, which also keeps `three` out of this\n// package — `TMesh` stays opaque here.\n\nimport type { SolveResult } from '../shared/solve-fn.js';\n\n/**\n * Deterministic string key for a set of input values. Sorts object keys at every level so\n * two logically-equal inputs built in different key order collide.\n */\nexport function stableInputKey(values: Record<string, unknown>): string {\n\treturn serialize(values);\n}\n\nfunction serialize(value: unknown): string {\n\tif (value === null || typeof value !== 'object') return JSON.stringify(value) ?? 'null';\n\tif (Array.isArray(value)) return `[${value.map(serialize).join(',')}]`;\n\tconst obj = value as Record<string, unknown>;\n\tconst keys = Object.keys(obj).sort();\n\treturn `{${keys.map((k) => `${JSON.stringify(k)}:${serialize(obj[k])}`).join(',')}}`;\n}\n\n/**\n * Omit when results are mesh-free or nothing takes ownership of the meshes — the memo then\n * stores and serves them by reference, which is safe only because nothing frees them behind\n * its back.\n */\nexport interface MeshPolicy<TMesh> {\n\t/** Called on the way in and on every hit, so the stored entry and a served copy are never the same instance. */\n\tclone(meshes: TMesh[]): TMesh[];\n\t/** Must not free anything shared with live content (e.g. materials another object still uses). */\n\trelease(meshes: TMesh[]): void;\n}\n\nexport interface SolveMemoOptions<TMesh> {\n\t/** Entry cap, not a byte cap. Kept small on purpose: this targets the slider-scrub loop, not a durable cache. */\n\tmax?: number;\n\tmeshPolicy?: MeshPolicy<TMesh>;\n}\n\nexport interface SolveMemo<TMesh = unknown> {\n\tget(values: Record<string, unknown>): SolveResult<TMesh> | undefined;\n\tset(values: Record<string, unknown>, result: SolveResult<TMesh>): void;\n\tclear(): void;\n}\n\nexport function createSolveMemo<TMesh = unknown>(\n\toptions: SolveMemoOptions<TMesh> = {}\n): SolveMemo<TMesh> {\n\tconst { max = 16, meshPolicy } = options;\n\tconst entries = new Map<string, SolveResult<TMesh>>();\n\n\tfunction release(result: SolveResult<TMesh>): void {\n\t\tif (result.meshes?.length) meshPolicy?.release(result.meshes);\n\t}\n\n\tfunction copy(result: SolveResult<TMesh>): SolveResult<TMesh> {\n\t\tif (!meshPolicy || !result.meshes?.length) return result;\n\t\treturn { ...result, meshes: meshPolicy.clone(result.meshes) };\n\t}\n\n\tfunction evict(key: string): void {\n\t\tconst entry = entries.get(key);\n\t\tif (entry === undefined) return;\n\t\tentries.delete(key);\n\t\trelease(entry);\n\t}\n\n\treturn {\n\t\tget(values) {\n\t\t\tconst key = stableInputKey(values);\n\t\t\tconst hit = entries.get(key);\n\t\t\tif (hit === undefined) return undefined;\n\t\t\tentries.delete(key);\n\t\t\tentries.set(key, hit);\n\t\t\tconsole.info(`[Solve/memo] HIT — served from client memo (${entries.size}/${max})`);\n\t\t\treturn copy(hit);\n\t\t},\n\t\tset(values, result) {\n\t\t\tconst key = stableInputKey(values);\n\t\t\tevict(key);\n\t\t\tentries.set(key, copy(result));\n\t\t\twhile (entries.size > max) {\n\t\t\t\tconst oldest = entries.keys().next().value;\n\t\t\t\tif (oldest === undefined) break;\n\t\t\t\tevict(oldest);\n\t\t\t\tconsole.info(`[Solve/memo] evicted LRU entry (cap ${max})`);\n\t\t\t}\n\t\t},\n\t\tclear() {\n\t\t\tif (entries.size > 0) {\n\t\t\t\tconsole.info(`[Solve/memo] cleared ${entries.size} entries (definition changed)`);\n\t\t\t}\n\t\t\tentries.forEach(release);\n\t\t\tentries.clear();\n\t\t}\n\t};\n}\n","import { createAsyncThrottle } from '../async-throttle.js';\nimport { createSolveMemo, type MeshPolicy } from '../solve-memo.js';\nimport type { SolveFn } from '../../shared/solve-fn.js';\nimport type { SolveDriver, SolveReporter } from './driver.js';\n\nexport interface RequestResponseDriverOptions<TMesh> {\n\t/** How long one solve may take before the client aborts it (ms). Pass the server's `COMPUTE_SOLVE_DEADLINE_MS` so the two agree. */\n\tsolveDeadlineMs: number;\n\tonChange?: () => void;\n\t/** Mesh ownership policy for the result memo — see `MeshPolicy` (solve-memo.ts). */\n\tmeshPolicy?: MeshPolicy<TMesh>;\n}\n\n/**\n * `getReporter` is lazy (`() => session`) because the session and driver reference each\n * other — the host builds the driver first, then the session, then can hand this back.\n */\nexport function createRequestResponseDriver<TMesh = unknown>(\n\tonSolve: SolveFn<TMesh>,\n\tgetReporter: () => SolveReporter<TMesh>,\n\toptions: RequestResponseDriverOptions<TMesh>\n): SolveDriver {\n\tconst { meshPolicy, solveDeadlineMs, onChange } = options;\n\n\t// Checked inside the throttled run, not before triggering it, so a hit only serves\n\t// after the throttle's latest-wins ordering has picked these values to run.\n\tconst memo = createSolveMemo<TMesh>({ meshPolicy });\n\n\tconst throttle = createAsyncThrottle<Record<string, unknown>>(\n\t\tasync (values, signal) => {\n\t\t\tconst cached = memo.get(values);\n\t\t\tif (cached !== undefined) {\n\t\t\t\tif (signal.aborted) return;\n\t\t\t\tgetReporter().report(cached);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst result = await onSolve(values, signal);\n\t\t\t\tif (signal.aborted) {\n\t\t\t\t\t// eslint-disable-next-line no-console -- normal during a slider scrub; not a warning\n\t\t\t\t\tconsole.debug('[Solve/driver] solve completed after abort — result discarded');\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Stamped here rather than in the SolveFn: a memo hit never calls it, so values\n\t\t\t\t// captured inside would pair the served result with whatever solved last.\n\t\t\t\tconst stamped = { ...result, values };\n\t\t\t\tmemo.set(values, stamped);\n\t\t\t\tgetReporter().report(stamped);\n\t\t\t} catch (err) {\n\t\t\t\tif (signal.aborted) {\n\t\t\t\t\t// eslint-disable-next-line no-console -- normal during a slider scrub; not a warning\n\t\t\t\t\tconsole.debug('[Solve/driver] solve aborted (superseded, cancelled, or timed out)');\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconsole.warn('[Solve/driver] solve failed:', err);\n\t\t\t\tgetReporter().reportError(err instanceof Error ? err.message : String(err));\n\t\t\t}\n\t\t},\n\t\t// The throttle is generic, so the solve deadline is what bounds one of its runs.\n\t\t{ runDeadlineMs: solveDeadlineMs, onChange }\n\t);\n\n\treturn {\n\t\tsolve(values) {\n\t\t\tthrottle.trigger(values);\n\t\t},\n\t\tcancel() {\n\t\t\tthrottle.cancel();\n\t\t},\n\t\tget isSolving() {\n\t\t\treturn throttle.isRunning;\n\t\t},\n\t\tclearCache() {\n\t\t\tmemo.clear();\n\t\t}\n\t};\n}\n","/**\n * `createComputeFetchSolveFn` — a ready-made `SolveFn` that POSTs to a\n * `/api/compute`-shaped HTTP endpoint (the wire contract `runSolvePipeline` +\n * `SolveEngine` produce server-side) and unpacks the result.\n *\n * Ports the resilience behavior an interactive solve endpoint needs regardless\n * of app — 429 cooldown, session-expiry/redirect detection, non-JSON-response\n * guarding, and abort handling at every await point — so a new consumer gets it\n * for free instead of re-deriving it by hand. Mesh decoding is NOT built in:\n * this package stays renderer-agnostic (see `shared/solve-fn.ts`), so a\n * viewer-enabled consumer supplies its own `meshes.extract` hook (typically\n * `getThreeMeshesFromComputeResponse` from `@selvajs/visualization/parse`).\n */\n\nimport {\n\tGrasshopperResponseProcessor,\n\ttype GrasshopperComputeResponse\n} from '@selvajs/compute/grasshopper';\nimport type { SolveFn, SolveResult } from '../shared/solve-fn.js';\n\nexport interface ComputeFetchSolveFnOptions<TMesh = unknown> {\n\t/** The compute endpoint to POST to, e.g. `/api/compute`. */\n\tendpoint: string;\n\t/** Definition URL (or `local:<guid>`) to solve — read per-solve so it can track a route param. */\n\tdefinitionUrl: () => string;\n\t/** Schema input params, sent as the request body's `inputs`. */\n\tinputs: () => Array<{ id: string }>;\n\t/** Schema output params — drives byId/byName output extraction after a solve. */\n\toutputs: () => Array<{ id: string; nickname?: string }>;\n\tchannel?: () => 'live' | 'draft' | undefined;\n\tversionId?: () => string | null | undefined;\n\t/** Omit entirely for a non-viewer consumer — `meshes` on the result stays `[]`. */\n\tmeshes?: {\n\t\textract: (\n\t\t\tresponse: GrasshopperComputeResponse,\n\t\t\topts: { debug: boolean }\n\t\t) => TMesh[] | Promise<TMesh[]>;\n\t};\n\t/** Gates ALL console telemetry (timing, cache verdicts, whales, heap). Default `false`. */\n\tdebug?: boolean;\n\t/** Called on a 429. Default: throws a cooldown-aware Error; the cooldown itself is tracked either way. */\n\tonRateLimited?: (retryAfterSeconds: number) => void;\n\t/** Called on a 401 or a login-page redirect. Default: throws an actionable \"reload to sign in again\" Error. */\n\tonSessionExpired?: () => void;\n}\n\nfunction parseServerTiming(header: string | null): Record<string, number> {\n\tconst out: Record<string, number> = {};\n\tif (!header) return out;\n\tfor (const part of header.split(',')) {\n\t\tconst [name, ...params] = part.split(';').map((s) => s.trim());\n\t\tconst dur = params.find((p) => p.startsWith('dur='));\n\t\tif (!name || !dur) continue;\n\t\tconst ms = Number(dur.slice(4));\n\t\tif (Number.isFinite(ms)) out[name] = ms;\n\t}\n\treturn out;\n}\n\nconst defaultOnRateLimited = (retryAfterSeconds: number): never => {\n\tthrow new Error(`Rate limit reached. Try again in ${Math.ceil(retryAfterSeconds)}s.`);\n};\n\nconst defaultOnSessionExpired = (): never => {\n\tthrow new Error(\n\t\t'Your session has expired. Sign in again in a new tab, then re-run — your inputs are preserved.'\n\t);\n};\n\nexport function createComputeFetchSolveFn<TMesh = unknown>(\n\topts: ComputeFetchSolveFnOptions<TMesh>\n): SolveFn<TMesh, GrasshopperComputeResponse> {\n\tconst debug = opts.debug ?? false;\n\tconst log = (...args: unknown[]) => {\n\t\tif (debug) console.info(...args);\n\t};\n\n\tlet cooldownUntil = 0;\n\n\treturn async (values, signal): Promise<SolveResult<TMesh, GrasshopperComputeResponse>> => {\n\t\tconst remainingMs = cooldownUntil - Date.now();\n\t\tif (remainingMs > 0) {\n\t\t\tthrow new Error(`Rate limit reached. Try again in ${Math.ceil(remainingMs / 1000)}s.`);\n\t\t}\n\n\t\tconst solveStart = performance.now();\n\t\tconst inputs = opts.inputs();\n\t\tconst outputs = opts.outputs();\n\t\tconst channel = opts.channel?.();\n\t\tconst versionId = opts.versionId?.();\n\n\t\tconst payload = JSON.stringify({\n\t\t\tinputs,\n\t\t\tvalues,\n\t\t\tdefinitionUrl: opts.definitionUrl(),\n\t\t\t...(versionId ? { versionId } : channel === 'draft' ? { channel: 'draft' } : {})\n\t\t});\n\t\tconst valuesBytes = JSON.stringify(values).length;\n\n\t\tlet res: Response;\n\t\ttry {\n\t\t\tres = await fetch(opts.endpoint, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\t\tbody: payload,\n\t\t\t\tsignal\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tif (signal.aborted) {\n\t\t\t\tlog('[Compute] solve aborted during fetch — empty result discarded');\n\t\t\t\treturn { outputs: {} };\n\t\t\t}\n\t\t\tthrow new Error(\n\t\t\t\t'Request blocked — your session may have expired. Reload the page to sign in again.',\n\t\t\t\t{ cause: err }\n\t\t\t);\n\t\t}\n\n\t\tif (signal.aborted) {\n\t\t\tlog('[Compute] solve aborted after headers — empty result discarded');\n\t\t\treturn { outputs: {} };\n\t\t}\n\n\t\tconst redirectedToLogin = res.redirected && new URL(res.url).pathname === '/login';\n\t\tif (res.status === 401 || redirectedToLogin) {\n\t\t\t(opts.onSessionExpired ?? defaultOnSessionExpired)();\n\t\t}\n\n\t\tif (!res.ok) {\n\t\t\tif (res.status === 503) {\n\t\t\t\tthrow new Error('Compute server is offline or unreachable. Please try again later.');\n\t\t\t}\n\t\t\tconst errorBody = await res.text().catch(() => '');\n\t\t\tlet d: { message?: string; retryAfter?: number } = {};\n\t\t\ttry {\n\t\t\t\td = JSON.parse(errorBody);\n\t\t\t} catch {\n\t\t\t\tif (errorBody) {\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`[Compute] non-JSON error body (HTTP ${res.status}):`,\n\t\t\t\t\t\terrorBody.slice(0, 300)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (res.status === 429) {\n\t\t\t\tconst retryAfter = Number(res.headers.get('Retry-After')) || Number(d.retryAfter) || 5;\n\t\t\t\tcooldownUntil = Date.now() + retryAfter * 1000;\n\t\t\t\t(opts.onRateLimited ?? defaultOnRateLimited)(retryAfter);\n\t\t\t}\n\t\t\tthrow new Error(d.message || `Compute error (HTTP ${res.status})`);\n\t\t}\n\n\t\tconst ttfbMs = performance.now() - solveStart;\n\n\t\tconst downloadStart = performance.now();\n\t\tconst bodyText = await res.text();\n\t\tif (signal.aborted) {\n\t\t\tlog('[Compute] solve aborted mid-download — empty result discarded');\n\t\t\treturn { outputs: {} };\n\t\t}\n\t\tconst downloadMs = performance.now() - downloadStart;\n\t\tconst bytes = bodyText.length;\n\n\t\tlet solved: GrasshopperComputeResponse;\n\t\ttry {\n\t\t\tsolved = JSON.parse(bodyText);\n\t\t} catch (err) {\n\t\t\tthrow new Error(\n\t\t\t\t'Received an invalid response from the server. Reload the page and try again.',\n\t\t\t\t{\n\t\t\t\t\tcause: err\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t\tconst processor = new GrasshopperResponseProcessor(solved, false);\n\n\t\tconst meshes = opts.meshes ? await opts.meshes.extract(processor.response, { debug }) : [];\n\n\t\tconst resultOutputs: Record<string, unknown> = {};\n\t\tfor (const o of outputs) {\n\t\t\tconst byId = processor.getValue({ byId: o.id }, { parseValues: true });\n\t\t\tresultOutputs[o.id] =\n\t\t\t\tbyId ??\n\t\t\t\t(o.nickname\n\t\t\t\t\t? processor.getValue({ byName: o.nickname }, { parseValues: true })\n\t\t\t\t\t: undefined);\n\t\t}\n\n\t\tif (debug) {\n\t\t\tconst serverTiming = parseServerTiming(res.headers.get('Server-Timing'));\n\t\t\tconst serverTotal = serverTiming.total ?? 0;\n\t\t\tconst networkMs = Math.max(0, ttfbMs - serverTotal);\n\t\t\tconst sizeMB = bytes / (1024 * 1024);\n\t\t\tconst size = sizeMB >= 1 ? `${sizeMB.toFixed(2)} MB` : `${(bytes / 1024).toFixed(0)} KB`;\n\t\t\tconst mbps = downloadMs > 0 ? (sizeMB / (downloadMs / 1000)).toFixed(1) : '∞';\n\t\t\tconst heapMB = (performance as Performance & { memory?: { usedJSHeapSize: number } }).memory\n\t\t\t\t?.usedJSHeapSize;\n\t\t\tconst heap = heapMB !== undefined ? ` | heap=${(heapMB / (1024 * 1024)).toFixed(0)} MB` : '';\n\t\t\tlog(\n\t\t\t\t`[Compute] req=${(payload.length / 1024).toFixed(0)}KB (values ${(valuesBytes / 1024).toFixed(0)}KB) | ` +\n\t\t\t\t\t`ttfb=${ttfbMs.toFixed(0)}ms (network≈${networkMs.toFixed(0)} + server ${serverTotal.toFixed(0)}) | ` +\n\t\t\t\t\t`download=${downloadMs.toFixed(0)}ms (${size} @ ${mbps} MB/s)${heap}`\n\t\t\t);\n\t\t\tif (serverTiming.selva_cache !== undefined) {\n\t\t\t\tconst cacheMsg = serverTiming.selva_cache\n\t\t\t\t\t? 'HIT — served without calling compute'\n\t\t\t\t\t: 'miss — solved on Rhino.Compute';\n\t\t\t\tlog(`[Compute] └─ cache: ${cacheMsg}`);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\toutputs: resultOutputs,\n\t\t\tmeshes,\n\t\t\terrors: solved.errors ?? [],\n\t\t\twarnings: solved.warnings ?? [],\n\t\t\tsource: solved\n\t\t};\n\t};\n}\n"],"mappings":"+IAUA,SAAS,EAAQ,EAAkB,EAAyB,CAC3D,MAAO,YAAqB,EAAS,GAAG,GACzC,CAOA,SAAgB,EAAmB,EAAmD,CACrF,GAAM,CAAE,WAAU,UAAS,SAAU,EACjC,CAAC,GAAY,CAAC,GACd,OAAO,eAAmB,KAC9B,eAAe,QAAQ,EAAQ,EAAU,CAAO,EAAG,KAAK,UAAU,CAAK,CAAC,CACzE,CAEA,SAAgB,EAAkB,EAA4C,CAC7E,GAAM,CAAE,WAAU,WAAY,EAE9B,GADI,CAAC,GAAY,CAAC,GACd,OAAO,eAAmB,IAAa,OAC3C,IAAM,EAAM,eAAe,QAAQ,EA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AAU,EAAO,UAAY,CAAC,EAC9B,OAAQ,CACT,CACD,CACD"}
package/dist/client.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- import { UISchema } from '@selvajs/schemas';
2
- import { a as SolveResult, S as SolveFn } from './solve-fn-DrRgaPZ5.cjs';
3
- import { GrasshopperComputeResponse } from '@selvajs/compute/grasshopper';
4
-
1
+ import { n as SolveResult, t as SolveFn } from "./solve-fn-lsWj61m5.cjs";
2
+ import { UISchema } from "@selvajs/schemas";
3
+ import { GrasshopperComputeResponse } from "@selvajs/compute/grasshopper";
4
+ //#region src/client/drivers/driver.d.ts
5
5
  /**
6
6
  * Transport behind a solve session. `solve()` never returns outputs directly — results
7
7
  * go through the session's `report()` instead, so a push transport (e.g. a WebSocket
@@ -18,38 +18,40 @@ import { GrasshopperComputeResponse } from '@selvajs/compute/grasshopper';
18
18
  * pairing the field exists to prevent.
19
19
  */
20
20
  interface SolveDriver {
21
- solve(values: Record<string, unknown>): void;
22
- cancel(): void;
23
- readonly isSolving: boolean;
24
- /**
25
- * Drops cached solve results. Optional — only the request/response driver has a
26
- * client-side memo to clear. Call on rebuild: a definition swap must not serve a
27
- * stale result from the prior definition's input space.
28
- */
29
- clearCache?(): void;
21
+ solve(values: Record<string, unknown>): void;
22
+ cancel(): void;
23
+ readonly isSolving: boolean;
24
+ /**
25
+ * Drops cached solve results. Optional — only the request/response driver has a
26
+ * client-side memo to clear. Call on rebuild: a definition swap must not serve a
27
+ * stale result from the prior definition's input space.
28
+ */
29
+ clearCache?(): void;
30
30
  }
31
31
  /** `TMesh` defaults to `unknown`: nothing here inspects meshes. A host with a concrete
32
32
  * mesh type (e.g. a three.js viewer) narrows it at its own seam. */
33
33
  interface SolveReporter<TMesh = unknown> {
34
- report(result: SolveResult<TMesh>): void;
35
- reportError(message: string): void;
34
+ report(result: SolveResult<TMesh>): void;
35
+ reportError(message: string): void;
36
36
  }
37
-
37
+ //#endregion
38
+ //#region src/client/external-storage.d.ts
38
39
  interface ExternalValueRef {
39
- scopeKey: string;
40
- inputId: string;
40
+ scopeKey: string;
41
+ inputId: string;
41
42
  }
42
43
  declare function writeExternalValue(args: ExternalValueRef & {
43
- value: unknown;
44
+ value: unknown;
44
45
  }): void;
45
46
  declare function readExternalValue(ref: ExternalValueRef): unknown | undefined;
46
47
  declare function clearExternalValue(ref: ExternalValueRef): void;
47
48
  interface ExternalInput {
48
- paramId: string;
49
- displayName: string;
49
+ paramId: string;
50
+ displayName: string;
50
51
  }
51
52
  declare function getExternalInputs(schema: UISchema): ExternalInput[];
52
-
53
+ //#endregion
54
+ //#region src/client/solve-session-core.d.ts
53
55
  /**
54
56
  * The slice of a reported result the session keeps addressable, so a host can commit exactly
55
57
  * what the viewer is showing — `source` and `values` included, already memo-correct.
@@ -62,24 +64,24 @@ declare function getExternalInputs(schema: UISchema): ExternalInput[];
62
64
  */
63
65
  type RetainedSolveResult<TSource = unknown> = Omit<SolveResult<never, TSource>, 'meshes'>;
64
66
  interface SolveSessionState {
65
- values: Record<string, unknown>;
66
- error: string;
67
- computeErrors: string[];
68
- computeWarnings: string[];
69
- meshes: unknown[];
70
- /** Values changed since the last solve, in manual (instanceSolve === false) mode. */
71
- pendingValues: Record<string, unknown>;
72
- hasPendingChanges: boolean;
73
- hasNeverSolved: boolean;
74
- /**
75
- * The last result reported, minus its meshes. Null before the first solve.
76
- *
77
- * Lags `values` by design: nothing updates it on `setValue` or `loadValues`, so between a
78
- * value change and the next report it describes the *previous* input set. That is what a
79
- * commit gate wants — what is on screen, not what is pending — so `lastResult.values`
80
- * disagreeing with `state.values` mid-scrub is the feature, not a bug.
81
- */
82
- lastResult: RetainedSolveResult | null;
67
+ values: Record<string, unknown>;
68
+ error: string;
69
+ computeErrors: string[];
70
+ computeWarnings: string[];
71
+ meshes: unknown[];
72
+ /** Values changed since the last solve, in manual (instanceSolve === false) mode. */
73
+ pendingValues: Record<string, unknown>;
74
+ hasPendingChanges: boolean;
75
+ hasNeverSolved: boolean;
76
+ /**
77
+ * The last result reported, minus its meshes. Null before the first solve.
78
+ *
79
+ * Lags `values` by design: nothing updates it on `setValue` or `loadValues`, so between a
80
+ * value change and the next report it describes the *previous* input set. That is what a
81
+ * commit gate wants — what is on screen, not what is pending — so `lastResult.values`
82
+ * disagreeing with `state.values` mid-scrub is the feature, not a bug.
83
+ */
84
+ lastResult: RetainedSolveResult | null;
83
85
  }
84
86
  type ExternalReader = (ref: ExternalValueRef) => unknown | undefined;
85
87
  /**
@@ -90,13 +92,13 @@ type ExternalReader = (ref: ExternalValueRef) => unknown | undefined;
90
92
  declare function buildInitialValues(schema: UISchema, scopeKey: string, read: ExternalReader): Record<string, unknown>;
91
93
  /** Manual-solve schemas (instanceSolve === false) start dirty; auto-solve schemas start clean. */
92
94
  declare function makeInitialFlags(instanceSolve: boolean | undefined): {
93
- hasPendingChanges: boolean;
94
- hasNeverSolved: boolean;
95
+ hasPendingChanges: boolean;
96
+ hasNeverSolved: boolean;
95
97
  };
96
98
  /** Manual mode defers (records the pending value, raises the dirty flag) instead of solving. */
97
99
  declare function applyValueChange(state: SolveSessionState, id: string, value: unknown, instanceSolve: boolean | undefined): {
98
- state: SolveSessionState;
99
- shouldSolve: boolean;
100
+ state: SolveSessionState;
101
+ shouldSolve: boolean;
100
102
  };
101
103
  /**
102
104
  * Solve outputs live in the same `values` map as inputs (so widgets like dynamic value
@@ -105,43 +107,45 @@ declare function applyValueChange(state: SolveSessionState, id: string, value: u
105
107
  */
106
108
  declare function pickInputValues(schema: UISchema | undefined, values: Record<string, unknown>): Record<string, unknown>;
107
109
  declare function applySolveResult(state: SolveSessionState, result: SolveResult): SolveSessionState;
108
-
110
+ //#endregion
111
+ //#region src/client/solve-session.d.ts
109
112
  interface SolveSession {
110
- readonly values: Record<string, unknown>;
111
- readonly error: string;
112
- readonly computeErrors: string[];
113
- readonly computeWarnings: string[];
114
- readonly meshes: unknown[];
115
- /**
116
- * The last reported result without its meshes — what the viewer is currently showing,
117
- * including the `source`/`values` pair a commit path needs. Null before the first solve,
118
- * and again after `rebuild()`. Survives `reportError`: a failed solve leaves the last good
119
- * geometry on screen, so a host committing what it sees should still see what produced it.
120
- */
121
- readonly lastResult: RetainedSolveResult | null;
122
- readonly hasPendingChanges: boolean;
123
- readonly hasNeverSolved: boolean;
124
- readonly isSolving: boolean;
125
- /** `forceSolve` overrides manual mode for system-initiated reconciliation (e.g. a dynamic value list pruning a vanished selection), so the output can't lag behind the new value. */
126
- setValue(id: string, value: unknown, forceSolve?: boolean): void;
127
- solve(): void;
128
- /** Merges incoming values, then solves (auto) or marks dirty (manual). */
129
- loadValues(incoming: Record<string, unknown>): void;
130
- rebuild(schema: UISchema, scopeKey: string): void;
131
- report(result: SolveResult): void;
132
- reportError(message: string): void;
133
- /** Fires after any mutation of the getters above, including driver-reported `isSolving` transitions. */
134
- subscribe(listener: () => void): () => void;
135
- /** For driver-owned state the session only forwards: `isSolving` lives on the driver, so wire this to its `onChange`. */
136
- notify(): void;
113
+ readonly values: Record<string, unknown>;
114
+ readonly error: string;
115
+ readonly computeErrors: string[];
116
+ readonly computeWarnings: string[];
117
+ readonly meshes: unknown[];
118
+ /**
119
+ * The last reported result without its meshes — what the viewer is currently showing,
120
+ * including the `source`/`values` pair a commit path needs. Null before the first solve,
121
+ * and again after `rebuild()`. Survives `reportError`: a failed solve leaves the last good
122
+ * geometry on screen, so a host committing what it sees should still see what produced it.
123
+ */
124
+ readonly lastResult: RetainedSolveResult | null;
125
+ readonly hasPendingChanges: boolean;
126
+ readonly hasNeverSolved: boolean;
127
+ readonly isSolving: boolean;
128
+ /** `forceSolve` overrides manual mode for system-initiated reconciliation (e.g. a dynamic value list pruning a vanished selection), so the output can't lag behind the new value. */
129
+ setValue(id: string, value: unknown, forceSolve?: boolean): void;
130
+ solve(): void;
131
+ /** Merges incoming values, then solves (auto) or marks dirty (manual). */
132
+ loadValues(incoming: Record<string, unknown>): void;
133
+ rebuild(schema: UISchema, scopeKey: string): void;
134
+ report(result: SolveResult): void;
135
+ reportError(message: string): void;
136
+ /** Fires after any mutation of the getters above, including driver-reported `isSolving` transitions. */
137
+ subscribe(listener: () => void): () => void;
138
+ /** For driver-owned state the session only forwards: `isSolving` lives on the driver, so wire this to its `onChange`. */
139
+ notify(): void;
137
140
  }
138
141
  interface SolveSessionArgs {
139
- schema: UISchema;
140
- scopeKey: string;
141
- driver: SolveDriver;
142
+ schema: UISchema;
143
+ scopeKey: string;
144
+ driver: SolveDriver;
142
145
  }
143
146
  declare function createSolveSession(args: SolveSessionArgs): SolveSession;
144
-
147
+ //#endregion
148
+ //#region src/client/solve-memo.d.ts
145
149
  /**
146
150
  * Deterministic string key for a set of input values. Sorts object keys at every level so
147
151
  * two logically-equal inputs built in different key order collide.
@@ -153,36 +157,38 @@ declare function stableInputKey(values: Record<string, unknown>): string;
153
157
  * its back.
154
158
  */
155
159
  interface MeshPolicy<TMesh> {
156
- /** Called on the way in and on every hit, so the stored entry and a served copy are never the same instance. */
157
- clone(meshes: TMesh[]): TMesh[];
158
- /** Must not free anything shared with live content (e.g. materials another object still uses). */
159
- release(meshes: TMesh[]): void;
160
+ /** Called on the way in and on every hit, so the stored entry and a served copy are never the same instance. */
161
+ clone(meshes: TMesh[]): TMesh[];
162
+ /** Must not free anything shared with live content (e.g. materials another object still uses). */
163
+ release(meshes: TMesh[]): void;
160
164
  }
161
165
  interface SolveMemoOptions<TMesh> {
162
- /** Entry cap, not a byte cap. Kept small on purpose: this targets the slider-scrub loop, not a durable cache. */
163
- max?: number;
164
- meshPolicy?: MeshPolicy<TMesh>;
166
+ /** Entry cap, not a byte cap. Kept small on purpose: this targets the slider-scrub loop, not a durable cache. */
167
+ max?: number;
168
+ meshPolicy?: MeshPolicy<TMesh>;
165
169
  }
166
170
  interface SolveMemo<TMesh = unknown> {
167
- get(values: Record<string, unknown>): SolveResult<TMesh> | undefined;
168
- set(values: Record<string, unknown>, result: SolveResult<TMesh>): void;
169
- clear(): void;
171
+ get(values: Record<string, unknown>): SolveResult<TMesh> | undefined;
172
+ set(values: Record<string, unknown>, result: SolveResult<TMesh>): void;
173
+ clear(): void;
170
174
  }
171
175
  declare function createSolveMemo<TMesh = unknown>(options?: SolveMemoOptions<TMesh>): SolveMemo<TMesh>;
172
-
176
+ //#endregion
177
+ //#region src/client/drivers/request-response.d.ts
173
178
  interface RequestResponseDriverOptions<TMesh> {
174
- /** How long one solve may take before the client aborts it (ms). Pass the server's `COMPUTE_SOLVE_DEADLINE_MS` so the two agree. */
175
- solveDeadlineMs: number;
176
- onChange?: () => void;
177
- /** Mesh ownership policy for the result memo — see `MeshPolicy` (solve-memo.ts). */
178
- meshPolicy?: MeshPolicy<TMesh>;
179
+ /** How long one solve may take before the client aborts it (ms). Pass the server's `COMPUTE_SOLVE_DEADLINE_MS` so the two agree. */
180
+ solveDeadlineMs: number;
181
+ onChange?: () => void;
182
+ /** Mesh ownership policy for the result memo — see `MeshPolicy` (solve-memo.ts). */
183
+ meshPolicy?: MeshPolicy<TMesh>;
179
184
  }
180
185
  /**
181
186
  * `getReporter` is lazy (`() => session`) because the session and driver reference each
182
187
  * other — the host builds the driver first, then the session, then can hand this back.
183
188
  */
184
189
  declare function createRequestResponseDriver<TMesh = unknown>(onSolve: SolveFn<TMesh>, getReporter: () => SolveReporter<TMesh>, options: RequestResponseDriverOptions<TMesh>): SolveDriver;
185
-
190
+ //#endregion
191
+ //#region src/client/async-throttle.d.ts
186
192
  /**
187
193
  * Single-in-flight, latest-wins throttle for any async operation: only one run at a
188
194
  * time, a newly triggered value overwrites the single pending slot (no queue), and a
@@ -193,67 +199,55 @@ declare function createRequestResponseDriver<TMesh = unknown>(onSolve: SolveFn<T
193
199
  * directly reads correct values but won't trigger a re-render.
194
200
  */
195
201
  interface AsyncThrottleOptions {
196
- /**
197
- * How long one run may take before it is aborted (ms). Required and deliberately
198
- * undefaulted: this is a generic throttle, so it has no basis for guessing what
199
- * the caller's work costs. Callers driving a Selva solve pass the deadline the
200
- * server enforces (`COMPUTE_SOLVE_DEADLINE_MS`) — a shorter local guess would abort
201
- * solves the server would have finished.
202
- */
203
- runDeadlineMs: number;
204
- onChange?: () => void;
202
+ /**
203
+ * How long one run may take before it is aborted (ms). Required and deliberately
204
+ * undefaulted: this is a generic throttle, so it has no basis for guessing what
205
+ * the caller's work costs. Callers driving a Selva solve pass the deadline the
206
+ * server enforces (`COMPUTE_SOLVE_DEADLINE_MS`) — a shorter local guess would abort
207
+ * solves the server would have finished.
208
+ */
209
+ runDeadlineMs: number;
210
+ onChange?: () => void;
205
211
  }
206
212
  interface AsyncThrottle<T> {
207
- trigger: (values: T) => void;
208
- readonly isRunning: boolean;
209
- readonly hasPending: boolean;
210
- cancel: () => void;
213
+ trigger: (values: T) => void;
214
+ readonly isRunning: boolean;
215
+ readonly hasPending: boolean;
216
+ cancel: () => void;
211
217
  }
212
218
  declare function createAsyncThrottle<T>(run: (values: T, signal: AbortSignal) => Promise<void>, options: AsyncThrottleOptions): AsyncThrottle<T>;
213
-
214
- /**
215
- * `createComputeFetchSolveFn` — a ready-made `SolveFn` that POSTs to a
216
- * `/api/compute`-shaped HTTP endpoint (the wire contract `runSolvePipeline` +
217
- * `SolveEngine` produce server-side) and unpacks the result.
218
- *
219
- * Ports the resilience behavior an interactive solve endpoint needs regardless
220
- * of app — 429 cooldown, session-expiry/redirect detection, non-JSON-response
221
- * guarding, and abort handling at every await point — so a new consumer gets it
222
- * for free instead of re-deriving it by hand. Mesh decoding is NOT built in:
223
- * this package stays renderer-agnostic (see `shared/solve-fn.ts`), so a
224
- * viewer-enabled consumer supplies its own `meshes.extract` hook (typically
225
- * `getThreeMeshesFromComputeResponse` from `@selvajs/visualization/parse`).
226
- */
227
-
219
+ //#endregion
220
+ //#region src/client/compute-fetch-solve-fn.d.ts
228
221
  interface ComputeFetchSolveFnOptions<TMesh = unknown> {
229
- /** The compute endpoint to POST to, e.g. `/api/compute`. */
230
- endpoint: string;
231
- /** Definition URL (or `local:<guid>`) to solve — read per-solve so it can track a route param. */
232
- definitionUrl: () => string;
233
- /** Schema input params, sent as the request body's `inputs`. */
234
- inputs: () => Array<{
235
- id: string;
236
- }>;
237
- /** Schema output params — drives byId/byName output extraction after a solve. */
238
- outputs: () => Array<{
239
- id: string;
240
- nickname?: string;
241
- }>;
242
- channel?: () => 'live' | 'draft' | undefined;
243
- versionId?: () => string | null | undefined;
244
- /** Omit entirely for a non-viewer consumer — `meshes` on the result stays `[]`. */
245
- meshes?: {
246
- extract: (response: GrasshopperComputeResponse, opts: {
247
- debug: boolean;
248
- }) => TMesh[] | Promise<TMesh[]>;
249
- };
250
- /** Gates ALL console telemetry (timing, cache verdicts, whales, heap). Default `false`. */
251
- debug?: boolean;
252
- /** Called on a 429. Default: throws a cooldown-aware Error; the cooldown itself is tracked either way. */
253
- onRateLimited?: (retryAfterSeconds: number) => void;
254
- /** Called on a 401 or a login-page redirect. Default: throws an actionable "reload to sign in again" Error. */
255
- onSessionExpired?: () => void;
222
+ /** The compute endpoint to POST to, e.g. `/api/compute`. */
223
+ endpoint: string;
224
+ /** Definition URL (or `local:<guid>`) to solve — read per-solve so it can track a route param. */
225
+ definitionUrl: () => string;
226
+ /** Schema input params, sent as the request body's `inputs`. */
227
+ inputs: () => Array<{
228
+ id: string;
229
+ }>;
230
+ /** Schema output params — drives byId/byName output extraction after a solve. */
231
+ outputs: () => Array<{
232
+ id: string;
233
+ nickname?: string;
234
+ }>;
235
+ channel?: () => 'live' | 'draft' | undefined;
236
+ versionId?: () => string | null | undefined;
237
+ /** Omit entirely for a non-viewer consumer — `meshes` on the result stays `[]`. */
238
+ meshes?: {
239
+ extract: (response: GrasshopperComputeResponse, opts: {
240
+ debug: boolean;
241
+ }) => TMesh[] | Promise<TMesh[]>;
242
+ };
243
+ /** Gates ALL console telemetry (timing, cache verdicts, whales, heap). Default `false`. */
244
+ debug?: boolean;
245
+ /** Called on a 429. Default: throws a cooldown-aware Error; the cooldown itself is tracked either way. */
246
+ onRateLimited?: (retryAfterSeconds: number) => void;
247
+ /** Called on a 401 or a login-page redirect. Default: throws an actionable "reload to sign in again" Error. */
248
+ onSessionExpired?: () => void;
256
249
  }
257
250
  declare function createComputeFetchSolveFn<TMesh = unknown>(opts: ComputeFetchSolveFnOptions<TMesh>): SolveFn<TMesh, GrasshopperComputeResponse>;
258
-
259
- export { type AsyncThrottle, type ComputeFetchSolveFnOptions, type ExternalInput, type ExternalReader, type ExternalValueRef, type MeshPolicy, type RequestResponseDriverOptions, type RetainedSolveResult, type SolveDriver, SolveFn, type SolveMemo, type SolveMemoOptions, type SolveReporter, SolveResult, type SolveSession, type SolveSessionArgs, type SolveSessionState, applySolveResult, applyValueChange, buildInitialValues, clearExternalValue, createAsyncThrottle, createComputeFetchSolveFn, createRequestResponseDriver, createSolveMemo, createSolveSession, getExternalInputs, makeInitialFlags, pickInputValues, readExternalValue, stableInputKey, writeExternalValue };
251
+ //#endregion
252
+ export { type AsyncThrottle, type ComputeFetchSolveFnOptions, type ExternalInput, type ExternalReader, type ExternalValueRef, type MeshPolicy, type RequestResponseDriverOptions, type RetainedSolveResult, type SolveDriver, type SolveFn, type SolveMemo, type SolveMemoOptions, type SolveReporter, type SolveResult, type SolveSession, type SolveSessionArgs, type SolveSessionState, applySolveResult, applyValueChange, buildInitialValues, clearExternalValue, createAsyncThrottle, createComputeFetchSolveFn, createRequestResponseDriver, createSolveMemo, createSolveSession, getExternalInputs, makeInitialFlags, pickInputValues, readExternalValue, stableInputKey, writeExternalValue };
253
+ //# sourceMappingURL=client.d.cts.map