@selvajs/selva 4.21.0-beta.23 → 4.21.0-beta.25

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.
Files changed (56) hide show
  1. package/build/adapter-node.js +1 -1
  2. package/build/client/_app/immutable/chunks/A_2RYLH9.js +1 -0
  3. package/build/client/_app/immutable/chunks/A_2RYLH9.js.br +1 -0
  4. package/build/client/_app/immutable/chunks/A_2RYLH9.js.gz +0 -0
  5. package/build/client/_app/immutable/chunks/{DtmN00GS.js → BMp0Pt9F.js} +4 -4
  6. package/build/client/_app/immutable/chunks/BMp0Pt9F.js.br +0 -0
  7. package/build/client/_app/immutable/chunks/BMp0Pt9F.js.gz +0 -0
  8. package/build/client/_app/immutable/entry/{app.Dl3HM1mx.js → app.UvCzfP6E.js} +2 -2
  9. package/build/client/_app/immutable/entry/app.UvCzfP6E.js.br +0 -0
  10. package/build/client/_app/immutable/entry/app.UvCzfP6E.js.gz +0 -0
  11. package/build/client/_app/immutable/nodes/21.BAYqxLPV.js +1 -0
  12. package/build/client/_app/immutable/nodes/21.BAYqxLPV.js.br +1 -0
  13. package/build/client/_app/immutable/nodes/21.BAYqxLPV.js.gz +0 -0
  14. package/build/client/_app/version.json +1 -1
  15. package/build/client/_app/version.json.br +0 -0
  16. package/build/client/_app/version.json.gz +0 -0
  17. package/build/runtime-meta.json +1 -1
  18. package/build/server/.vite/manifest.json +13 -11
  19. package/build/server/chunks/compute.js +1 -1
  20. package/build/server/chunks/engine.server.js +1 -1
  21. package/build/server/chunks/errors.js +7 -30
  22. package/build/server/chunks/errors.js.map +1 -1
  23. package/build/server/chunks/handlers.js +5 -4
  24. package/build/server/chunks/handlers.js.map +1 -1
  25. package/build/server/chunks/instance.js +3 -3
  26. package/build/server/chunks/internal.js +1 -1
  27. package/build/server/chunks/ops.js +1 -1
  28. package/build/server/chunks/package.js +1 -1
  29. package/build/server/chunks/package.js.map +1 -1
  30. package/build/server/chunks/providers.server.js +48 -15
  31. package/build/server/chunks/providers.server.js.map +1 -1
  32. package/build/server/chunks/{limits.js → saved-values.js} +35 -2
  33. package/build/server/chunks/saved-values.js.map +1 -0
  34. package/build/server/chunks/server.js +5 -0
  35. package/build/server/chunks/server.js.map +1 -1
  36. package/build/server/chunks/types2.js.map +1 -1
  37. package/build/server/entries/pages/library/_guid_/_page.server.ts.js +14 -3
  38. package/build/server/entries/pages/library/_guid_/_page.server.ts.js.map +1 -1
  39. package/build/server/entries/pages/library/_guid_/_page.svelte.js +42 -8
  40. package/build/server/entries/pages/library/_guid_/_page.svelte.js.map +1 -1
  41. package/build/server/manifest-full.js +1 -1
  42. package/build/server/manifest.js +1 -1
  43. package/build/server/nodes/21.js +1 -1
  44. package/build/server/server.js +1 -1
  45. package/package.json +9 -9
  46. package/build/client/_app/immutable/chunks/B58dPMPq.js +0 -1
  47. package/build/client/_app/immutable/chunks/B58dPMPq.js.br +0 -1
  48. package/build/client/_app/immutable/chunks/B58dPMPq.js.gz +0 -0
  49. package/build/client/_app/immutable/chunks/DtmN00GS.js.br +0 -0
  50. package/build/client/_app/immutable/chunks/DtmN00GS.js.gz +0 -0
  51. package/build/client/_app/immutable/entry/app.Dl3HM1mx.js.br +0 -0
  52. package/build/client/_app/immutable/entry/app.Dl3HM1mx.js.gz +0 -0
  53. package/build/client/_app/immutable/nodes/21.BZJQikE5.js +0 -1
  54. package/build/client/_app/immutable/nodes/21.BZJQikE5.js.br +0 -0
  55. package/build/client/_app/immutable/nodes/21.BZJQikE5.js.gz +0 -0
  56. package/build/server/chunks/limits.js.map +0 -1
@@ -66,6 +66,39 @@ function resolveComputeLimits(env, logger = noop) {
66
66
  computeSolveCacheBytes: int("COMPUTE_SOLVE_CACHE_MB") * MB
67
67
  };
68
68
  }
69
- export { readBool as n, resolveComputeLimits as r, COMPUTE_REQUEST_MAX_BYTES as t };
69
+ // ../server/src/definitions/saved-values.ts
70
+ function savedValuesFrom(inputs) {
71
+ const values = /* @__PURE__ */ new Map();
72
+ for (const input of inputs) {
73
+ if (input.id === void 0 || input.default === void 0) continue;
74
+ values.set(input.id, input.paramType === "Color" ? colorToHex(input.default) : input.default);
75
+ }
76
+ return values;
77
+ }
78
+ /** As stored on the version (`DefinitionVersion.savedValues`). */
79
+ function savedValuesToRecord(values) {
80
+ return Object.fromEntries(values);
81
+ }
82
+ function savedValuesFromRecord(record) {
83
+ return new Map(Object.entries(record));
84
+ }
85
+ /** `schema` with each input's `default` replaced by its saved value, where it has one. */
86
+ function applySavedValues(schema, values) {
87
+ return {
88
+ ...schema,
89
+ inputs: schema.inputs.map((input) => values.has(input.id) ? {
90
+ ...input,
91
+ default: values.get(input.id)
92
+ } : input)
93
+ };
94
+ }
95
+ function colorToHex(value) {
96
+ const parts = String(value).split(",").map((s) => parseInt(s.trim(), 10));
97
+ const hex = (n) => n.toString(16).padStart(2, "0");
98
+ if (parts.length === 3) return `#${hex(parts[0])}${hex(parts[1])}${hex(parts[2])}`;
99
+ if (parts.length === 4) return `#${hex(parts[1])}${hex(parts[2])}${hex(parts[3])}`;
100
+ return value;
101
+ }
102
+ export { COMPUTE_REQUEST_MAX_BYTES as a, savedValuesToRecord as i, savedValuesFrom as n, readBool as o, savedValuesFromRecord as r, resolveComputeLimits as s, applySavedValues as t };
70
103
 
71
- //# sourceMappingURL=limits.js.map
104
+ //# sourceMappingURL=saved-values.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saved-values.js","names":[],"sources":["../../../../server/src/compute/limits.ts","../../../../server/src/definitions/saved-values.ts"],"sourcesContent":["/**\n * Compute/solve server limits, resolved from an injected env map.\n *\n * Env comes in as a parameter — nothing ambient is read — so this is importable\n * from any runtime and testable without env plumbing. Defaults are sized for\n * typical interactive use (sliders + small uploads).\n *\n * Client-side counterparts (the in-flight compute throttle and slider debounce)\n * are bundled into the client in `@selvajs/ui` and can't read env — they carry\n * their own defaults.\n */\n\nimport { NoopLogger, type ILogger } from '@selvajs/platform';\nimport type { EnvRecord } from '@selvajs/platform/config';\nimport { readSettings } from '../config/read-settings.js';\nimport { COMPUTE_LIMIT_SETTINGS } from '../config/settings.js';\n\nexport type { EnvRecord };\n\nconst MB = 1024 * 1024;\n\n/**\n * Cap on a solve request body. A `file` input embeds geometry as base64, so the\n * client's 150 MB raw file is ~200 MB on the wire, plus JSON envelope slack.\n * adapter-node's `BODY_SIZE_LIMIT` must be at least this, or it rejects first.\n */\nexport const COMPUTE_REQUEST_MAX_BYTES = 256 * MB;\n\n/**\n * Default logger for the env-parsing warnings below. This is library code, so an\n * embedder that wires nothing gets silence rather than unsolicited stdout writes.\n */\nconst noop = new NoopLogger();\n\n/**\n * Parse a positive integer env value; absent, or present but not finite and positive, falls back.\n *\n * @deprecated Looser than the manifest (`0.5` floors to 0): declare the key and read it with\n * `readSetting` from `@selvajs/platform/config`, so the config report shows what runs.\n */\nexport function readPositiveInt(\n\tenv: EnvRecord,\n\tname: string,\n\tfallback: number,\n\tlogger: ILogger = noop\n): number {\n\tconst raw = env[name];\n\tif (!raw) return fallback;\n\tconst parsed = Number(raw);\n\tif (!Number.isFinite(parsed) || parsed <= 0) {\n\t\tlogger.warn('Invalid env value, falling back to default', {\n\t\t\tcomponent: 'selva',\n\t\t\tenvVar: name,\n\t\t\tvalue: raw,\n\t\t\tfallback\n\t\t});\n\t\treturn fallback;\n\t}\n\treturn Math.floor(parsed);\n}\n\n/**\n * Like {@link readPositiveInt}, but `0` is valid — knobs where it means \"disable\".\n *\n * @deprecated Same reason as {@link readPositiveInt}.\n */\nexport function readNonNegativeInt(\n\tenv: EnvRecord,\n\tname: string,\n\tfallback: number,\n\tlogger: ILogger = noop\n): number {\n\tconst raw = env[name];\n\tif (!raw) return fallback;\n\tconst parsed = Number(raw);\n\tif (!Number.isFinite(parsed) || parsed < 0) {\n\t\tlogger.warn('Invalid env value, falling back to default', {\n\t\t\tcomponent: 'selva',\n\t\t\tenvVar: name,\n\t\t\tvalue: raw,\n\t\t\tfallback\n\t\t});\n\t\treturn fallback;\n\t}\n\treturn Math.floor(parsed);\n}\n\n/**\n * Parse a boolean env flag. Accepts `true/1/yes/on` and `false/0/no/off`\n * (case-insensitive); any other spelling warns and falls back.\n */\nexport function readBool(\n\tenv: EnvRecord,\n\tname: string,\n\tfallback: boolean,\n\tlogger: ILogger = noop\n): boolean {\n\tconst raw = env[name];\n\tif (raw == null || raw === '') return fallback;\n\tconst v = raw.trim().toLowerCase();\n\tif (v === 'true' || v === '1' || v === 'yes' || v === 'on') return true;\n\tif (v === 'false' || v === '0' || v === 'no' || v === 'off') return false;\n\tlogger.warn('Invalid env value, falling back to default', {\n\t\tcomponent: 'selva',\n\t\tenvVar: name,\n\t\tvalue: raw,\n\t\tfallback\n\t});\n\treturn fallback;\n}\n\n/** Fully-resolved server-side compute limits. */\nexport interface ComputeLimits {\n\t/** Fixed-window cap on /api/v1/compute: window length + max requests per window. */\n\trateLimitWindowMs: number;\n\trateLimitMaxRequests: number;\n\t/**\n\t * Largest .gh definition accepted on upload. 50 MB matches Rhino.Compute's own\n\t * `RHINO_COMPUTE_MAX_REQUEST_SIZE` default — a larger file 413s at compute\n\t * regardless, so accepting it here only defers the failure.\n\t */\n\tmaxDefinitionFileSize: number;\n\t/** Largest cover image accepted on upload. */\n\tmaxImageFileSize: number;\n\t/** /api/v1/compute JSON *request* body cap: {@link COMPUTE_REQUEST_MAX_BYTES}. */\n\tcomputeRequestMaxBytes: number;\n\t/**\n\t * /api/v1/compute JSON *response* cap. A `file`-typed output is base64-embedded\n\t * in the response; this guards V8's ~512 MB single-string wall (a\n\t * `JSON.stringify` `RangeError`) and browser-tab OOM, turning an opaque crash\n\t * into a clear 413. The real fix is out-of-band streaming.\n\t *\n\t * 300 MB is deliberate, not a dev leftover — above any legitimate inline\n\t * payload, below the V8 string wall. Unlike the request cap it is not bounded\n\t * by `BODY_SIZE_LIMIT`, which only covers inbound bodies.\n\t */\n\tcomputeResponseMaxBytes: number;\n\t/**\n\t * Hard cap on fetching a remote definition. Tracks `maxDefinitionFileSize` so a\n\t * remote URL can't smuggle a file past the upload cap.\n\t */\n\tremoteDefinitionMaxBytes: number;\n\t/** Deadline on fetching a remote definition (slow-loris protection). */\n\tremoteDefinitionFetchTimeoutMs: number;\n\t/**\n\t * TTL for the in-process cache of .gh bytes fetched from a REMOTE URL.\n\t *\n\t * Only the remote path is TTL'd, and the name says so deliberately: the other\n\t * definition cache is keyed on an immutable version id, where expiry could only\n\t * ever throw away valid work. A URL's owner can swap the file underneath us, so\n\t * that path needs a freshness bound and this is it.\n\t */\n\tremoteDefinitionCacheTtlMs: number;\n\t/**\n\t * Ask Rhino.Compute to cache solve RESULTS keyed on the full request and\n\t * return a cached result on an identical repeat. Server-wide (survives Selva\n\t * restarts, spans instances). Only helps IDENTICAL re-solves.\n\t */\n\tcomputeServerCachesolve: boolean;\n\t/**\n\t * Backpressure — max solves allowed to WAIT in the per-server FIFO queue. This\n\t * excludes in-flight solves, which the scheduler caps at `maxConcurrent`,\n\t * auto-detected from the compute server's active child count. A solve arriving\n\t * at a full queue is rejected on the spot (scheduler `QUEUE_FULL` → HTTP 503 +\n\t * `Retry-After`) instead of piling up. `0` = unbounded, the default.\n\t *\n\t * Size it to roughly 2–3× the compute server's child count once you know the\n\t * Rhino pool's real capacity — rejecting fast beats a hung request.\n\t */\n\tcomputeMaxQueueDepth: number;\n\t/**\n\t * Backpressure — longest (ms) a solve may sit QUEUED before it starts\n\t * executing. Still waiting past this, it's rejected (scheduler `QUEUE_TIMEOUT`\n\t * → HTTP 503 + `Retry-After`) rather than burning compute on a stale request.\n\t * `0` = no queue deadline, the default.\n\t *\n\t * Bounds tail latency: the scheduler's `timeoutMs` clock starts at execution,\n\t * so without this a solve's total wait is unbounded and invisible. Tune it to\n\t * about the compute server's own timeout.\n\t */\n\tcomputeQueueWaitMs: number;\n\t/**\n\t * **Definition cache** — total-byte budget for the in-process cache of .gh bytes\n\t * keyed on immutable version id. A warm entry lets a solve skip `storage.get`;\n\t * `0` disables it, so every solve re-reads storage. A byte LRU rather than an\n\t * entry count because definitions span KB→hundreds of MB. Env value is MB.\n\t */\n\tcomputeDefinitionCacheBytes: number;\n\t/**\n\t * **Solve cache** — total-byte budget for EACH warm client's in-process cache of\n\t * solve results (the `fromCache` layer in front of Rhino.Compute). `0` disables\n\t * it, so every solve goes to compute. Results span KB→100s of MB\n\t * (`computeResponseMaxBytes` allows 300 MB), so an entry count alone can't bound\n\t * heap; this adds a byte LRU on top. Env value is MB.\n\t *\n\t * **Per warm client, so the worst case multiplies.** Selva keeps up to\n\t * `maxWarmComputeServers` (default 16) compute servers warm, making the real\n\t * ceiling this × 16 — 4 GB at the default. Most deployments run 1–2 servers,\n\t * which is why the default is comfortable; a fan-out across many servers on a\n\t * small VPS is the case this knob exists for.\n\t */\n\tcomputeSolveCacheBytes: number;\n}\n\n/**\n * Resolve every server-side compute limit from an env map. The app calls this\n * once at its composition root with `$env/dynamic/private`.\n */\nexport function resolveComputeLimits(env: EnvRecord, logger: ILogger = noop): ComputeLimits {\n\tconst values = readSettings(COMPUTE_LIMIT_SETTINGS, env, logger);\n\tconst int = (key: string) => values[key] as number;\n\n\tconst maxDefinitionFileSize = int('MAX_DEFINITION_FILE_SIZE_BYTES');\n\treturn {\n\t\trateLimitWindowMs: 100_000,\n\t\trateLimitMaxRequests: int('COMPUTE_RATE_LIMIT_MAX'),\n\t\tmaxDefinitionFileSize,\n\t\tmaxImageFileSize: 10 * MB,\n\t\tcomputeRequestMaxBytes: COMPUTE_REQUEST_MAX_BYTES,\n\t\tcomputeResponseMaxBytes: 300 * MB,\n\t\tremoteDefinitionMaxBytes: maxDefinitionFileSize,\n\t\tremoteDefinitionFetchTimeoutMs: 30_000,\n\t\tremoteDefinitionCacheTtlMs: 5 * 60 * 1000,\n\t\tcomputeServerCachesolve: values.COMPUTE_SERVER_CACHESOLVE as boolean,\n\t\tcomputeMaxQueueDepth: int('COMPUTE_MAX_QUEUE_DEPTH'),\n\t\tcomputeQueueWaitMs: int('COMPUTE_QUEUE_WAIT_MS'),\n\t\tcomputeDefinitionCacheBytes: int('COMPUTE_DEFINITION_CACHE_MB') * MB,\n\t\tcomputeSolveCacheBytes: int('COMPUTE_SOLVE_CACHE_MB') * MB\n\t};\n}\n","// The embedded schema carries input values from the author's last schema sync. Compute's `/io`\n// reads the values saved in the file, which can be newer, and those are what a form must start\n// from. A version's bytes never change, so neither do its saved values.\n\nimport type { UISchema } from '@selvajs/schemas';\n\n/** Each input's saved value, keyed by param id. */\nexport type SavedValues = ReadonlyMap<string, unknown>;\n\nexport function savedValuesFrom(\n\tinputs: ReadonlyArray<{ id?: string; paramType?: string; default?: unknown }>\n): SavedValues {\n\tconst values = new Map<string, unknown>();\n\tfor (const input of inputs) {\n\t\tif (input.id === undefined || input.default === undefined) continue;\n\t\tvalues.set(input.id, input.paramType === 'Color' ? colorToHex(input.default) : input.default);\n\t}\n\treturn values;\n}\n\n/** As stored on the version (`DefinitionVersion.savedValues`). */\nexport function savedValuesToRecord(values: SavedValues): Record<string, unknown> {\n\treturn Object.fromEntries(values);\n}\n\nexport function savedValuesFromRecord(record: Record<string, unknown>): SavedValues {\n\treturn new Map(Object.entries(record));\n}\n\n/** `schema` with each input's `default` replaced by its saved value, where it has one. */\nexport function applySavedValues(schema: UISchema, values: SavedValues): UISchema {\n\treturn {\n\t\t...schema,\n\t\tinputs: schema.inputs.map((input) =>\n\t\t\tvalues.has(input.id) ? { ...input, default: values.get(input.id) } : input\n\t\t)\n\t};\n}\n\n// Compute sends colors as \"r,g,b\" or \"a,r,g,b\"; the color picker takes hex.\nfunction colorToHex(value: unknown): unknown {\n\tconst parts = String(value)\n\t\t.split(',')\n\t\t.map((s) => parseInt(s.trim(), 10));\n\tconst hex = (n: number) => n.toString(16).padStart(2, '0');\n\tif (parts.length === 3) return `#${hex(parts[0])}${hex(parts[1])}${hex(parts[2])}`;\n\tif (parts.length === 4) return `#${hex(parts[1])}${hex(parts[2])}${hex(parts[3])}`;\n\treturn value;\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,IAAM,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B,QAA8C;CACjF,OAAO,OAAO,YAAY,MAAM;AACjC;AAEA,SAAgB,sBAAsB,QAA8C;CACnF,OAAO,IAAI,IAAI,OAAO,QAAQ,MAAM,CAAC;AACtC;;AAGA,SAAgB,iBAAiB,QAAkB,QAA+B;CACjF,OAAO;EACN,GAAG;EACH,QAAQ,OAAO,OAAO,KAAK,UAC1B,OAAO,IAAI,MAAM,EAAE,IAAI;GAAE,GAAG;GAAO,SAAS,OAAO,IAAI,MAAM,EAAE;EAAE,IAAI,KACtE;CACD;AACD;AAGA,SAAS,WAAW,OAAyB;CAC5C,MAAM,QAAQ,OAAO,KAAK,CAAC,CACzB,MAAM,GAAG,CAAC,CACV,KAAK,MAAM,SAAS,EAAE,KAAK,GAAG,EAAE,CAAC;CACnC,MAAM,OAAO,MAAc,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG;CACzD,IAAI,MAAM,WAAW,GAAG,OAAO,IAAI,IAAI,MAAM,EAAE,IAAI,IAAI,MAAM,EAAE,IAAI,IAAI,MAAM,EAAE;CAC/E,IAAI,MAAM,WAAW,GAAG,OAAO,IAAI,IAAI,MAAM,EAAE,IAAI,IAAI,MAAM,EAAE,IAAI,IAAI,MAAM,EAAE;CAC/E,OAAO;AACR"}
@@ -27785,6 +27785,11 @@ function classifyFailure(err, durationMs, args) {
27785
27785
  message: `The inputs are larger than the compute server accepts` + (cap ? ` (${Math.round(cap / 1048576)} MB)` : "") + ". Its admin can raise RHINO_COMPUTE_MAX_REQUEST_SIZE."
27786
27786
  };
27787
27787
  }
27788
+ if (err.statusCode === 504) return {
27789
+ kind: "timeout",
27790
+ durationMs,
27791
+ message: "The solve ran past the compute server's time limit. Its admin can raise RHINO_COMPUTE_TIMEOUT."
27792
+ };
27788
27793
  switch (err.code) {
27789
27794
  case ErrorCodes.TIMEOUT_ERROR: return {
27790
27795
  kind: "timeout",