@selvajs/selva 4.21.0-beta.24 → 4.21.0-beta.26
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/build/adapter-node.js +1 -1
- package/build/client/_app/immutable/assets/0.Ct4dsf2W.css +2 -0
- package/build/client/_app/immutable/assets/0.Ct4dsf2W.css.br +0 -0
- package/build/client/_app/immutable/assets/0.Ct4dsf2W.css.gz +0 -0
- package/build/client/_app/immutable/chunks/BUxAHI7i.js +1 -0
- package/build/client/_app/immutable/chunks/BUxAHI7i.js.br +1 -0
- package/build/client/_app/immutable/chunks/BUxAHI7i.js.gz +0 -0
- package/build/client/_app/immutable/chunks/C4PDTpD1.js +6085 -0
- package/build/client/_app/immutable/chunks/C4PDTpD1.js.br +0 -0
- package/build/client/_app/immutable/chunks/C4PDTpD1.js.gz +0 -0
- package/build/client/_app/immutable/entry/{app.Dl3HM1mx.js → app.Bqmne5hV.js} +2 -2
- package/build/client/_app/immutable/entry/app.Bqmne5hV.js.br +0 -0
- package/build/client/_app/immutable/entry/app.Bqmne5hV.js.gz +0 -0
- package/build/client/_app/immutable/nodes/21.Dv262ba8.js +1 -0
- package/build/client/_app/immutable/nodes/21.Dv262ba8.js.br +1 -0
- package/build/client/_app/immutable/nodes/21.Dv262ba8.js.gz +0 -0
- package/build/client/_app/version.json +1 -1
- package/build/client/_app/version.json.br +0 -0
- package/build/client/_app/version.json.gz +0 -0
- package/build/runtime-meta.json +1 -1
- package/build/server/.vite/manifest.json +24 -21
- package/build/server/_app/immutable/assets/_layout.Ct4dsf2W.css +2 -0
- package/build/server/chunks/capture.js +1 -1
- package/build/server/chunks/compute-profile-D3g1Tuyd.js +92 -0
- package/build/server/chunks/compute-profile-D3g1Tuyd.js.map +1 -0
- package/build/server/chunks/compute.js +1 -1
- package/build/server/chunks/engine.server.js +1 -1
- package/build/server/chunks/errors.js +7 -30
- package/build/server/chunks/errors.js.map +1 -1
- package/build/server/chunks/grasshopper.js +6 -1
- package/build/server/chunks/grasshopper.js.map +1 -1
- package/build/server/chunks/handlers.js +5 -4
- package/build/server/chunks/handlers.js.map +1 -1
- package/build/server/chunks/instance.js +3 -3
- package/build/server/chunks/internal.js +1 -1
- package/build/server/chunks/ops.js +1 -1
- package/build/server/chunks/package.js +1 -1
- package/build/server/chunks/package.js.map +1 -1
- package/build/server/chunks/providers.server.js +48 -15
- package/build/server/chunks/providers.server.js.map +1 -1
- package/build/server/chunks/{limits.js → saved-values.js} +35 -2
- package/build/server/chunks/saved-values.js.map +1 -0
- package/build/server/chunks/server.js +134 -17
- package/build/server/chunks/server.js.map +1 -1
- package/build/server/chunks/solve.js +1 -1
- package/build/server/chunks/solve.server.js +8 -3
- package/build/server/chunks/solve.server.js.map +1 -1
- package/build/server/chunks/types2.js.map +1 -1
- package/build/server/entries/endpoints/api/v1/compute/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/solve/_server.ts.js +5 -2
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/solve/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/v1/solves/_solveId_/_server.ts.js +1 -1
- package/build/server/entries/pages/library/_guid_/_page.server.ts.js +14 -3
- package/build/server/entries/pages/library/_guid_/_page.server.ts.js.map +1 -1
- package/build/server/entries/pages/library/_guid_/_page.svelte.js +164 -38
- package/build/server/entries/pages/library/_guid_/_page.svelte.js.map +1 -1
- package/build/server/manifest-full.js +1 -1
- package/build/server/manifest.js +1 -1
- package/build/server/nodes/0.js +2 -2
- package/build/server/nodes/21.js +1 -1
- package/build/server/server.js +1 -1
- package/package.json +11 -11
- package/build/client/_app/immutable/assets/0.DOeouCe4.css +0 -2
- package/build/client/_app/immutable/assets/0.DOeouCe4.css.br +0 -0
- package/build/client/_app/immutable/assets/0.DOeouCe4.css.gz +0 -0
- package/build/client/_app/immutable/chunks/B58dPMPq.js +0 -1
- package/build/client/_app/immutable/chunks/B58dPMPq.js.br +0 -1
- package/build/client/_app/immutable/chunks/B58dPMPq.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DtmN00GS.js +0 -6085
- package/build/client/_app/immutable/chunks/DtmN00GS.js.br +0 -0
- package/build/client/_app/immutable/chunks/DtmN00GS.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.Dl3HM1mx.js.br +0 -0
- package/build/client/_app/immutable/entry/app.Dl3HM1mx.js.gz +0 -0
- package/build/client/_app/immutable/nodes/21.BZJQikE5.js +0 -1
- package/build/client/_app/immutable/nodes/21.BZJQikE5.js.br +0 -0
- package/build/client/_app/immutable/nodes/21.BZJQikE5.js.gz +0 -0
- package/build/server/_app/immutable/assets/_layout.DOeouCe4.css +0 -2
- package/build/server/chunks/async-solve-Doflh4BJ.js +0 -27
- package/build/server/chunks/async-solve-Doflh4BJ.js.map +0 -1
- package/build/server/chunks/limits.js.map +0 -1
- /package/build/client/_app/immutable/nodes/{0.BQ4J6cqX.js → 0.BsaBi01M.js} +0 -0
- /package/build/client/_app/immutable/nodes/{0.BQ4J6cqX.js.br → 0.BsaBi01M.js.br} +0 -0
- /package/build/client/_app/immutable/nodes/{0.BQ4J6cqX.js.gz → 0.BsaBi01M.js.gz} +0 -0
|
@@ -66,6 +66,39 @@ function resolveComputeLimits(env, logger = noop) {
|
|
|
66
66
|
computeSolveCacheBytes: int("COMPUTE_SOLVE_CACHE_MB") * MB
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
|
-
|
|
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=
|
|
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,KAAK;;;;;;AAOX,IAAa,4BAA4B,MAAM;;;;;AAM/C,IAAM,OAAO,IAAI,WAAW;;;;;AA2D5B,SAAgB,SACf,KACA,MACA,UACA,SAAkB,MACR;CACV,MAAM,MAAM,IAAI;CAChB,IAAI,OAAO,QAAQ,QAAQ,IAAI,OAAO;CACtC,MAAM,IAAI,IAAI,KAAK,CAAC,CAAC,YAAY;CACjC,IAAI,MAAM,UAAU,MAAM,OAAO,MAAM,SAAS,MAAM,MAAM,OAAO;CACnE,IAAI,MAAM,WAAW,MAAM,OAAO,MAAM,QAAQ,MAAM,OAAO,OAAO;CACpE,OAAO,KAAK,8CAA8C;EACzD,WAAW;EACX,QAAQ;EACR,OAAO;EACP;CACD,CAAC;CACD,OAAO;AACR;;;;;AAmGA,SAAgB,qBAAqB,KAAgB,SAAkB,MAAqB;CAC3F,MAAM,SAAS,aAAa,wBAAwB,KAAK,MAAM;CAC/D,MAAM,OAAO,QAAgB,OAAO;CAEpC,MAAM,wBAAwB,IAAI,gCAAgC;CAClE,OAAO;EACN,mBAAmB;EACnB,sBAAsB,IAAI,wBAAwB;EAClD;EACA,kBAAkB,KAAK;EACvB,wBAAwB;EACxB,yBAAyB,MAAM;EAC/B,0BAA0B;EAC1B,gCAAgC;EAChC,4BAA4B;EAC5B,yBAAyB,OAAO;EAChC,sBAAsB,IAAI,yBAAyB;EACnD,oBAAoB,IAAI,uBAAuB;EAC/C,6BAA6B,IAAI,6BAA6B,IAAI;EAClE,wBAAwB,IAAI,wBAAwB,IAAI;CACzD;AACD;;AC5NA,SAAgB,gBACf,QACc;CACd,MAAM,yBAAS,IAAI,IAAqB;CACxC,KAAK,MAAM,SAAS,QAAQ;EAC3B,IAAI,MAAM,OAAO,KAAA,KAAa,MAAM,YAAY,KAAA,GAAW;EAC3D,OAAO,IAAI,MAAM,IAAI,MAAM,cAAc,UAAU,WAAW,MAAM,OAAO,IAAI,MAAM,OAAO;CAC7F;CACA,OAAO;AACR;;AAGA,SAAgB,oBAAoB,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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as getInputItems } from "./traversal.js";
|
|
2
2
|
import { c as stableStringify, d as ErrorCodes, g as isDefinitionRef, h as enableDebugLogging, i as TreeBuilder, l as withSolveMode, n as GrasshopperClient, u as ComputeError } from "./grasshopper.js";
|
|
3
|
-
import { a as
|
|
3
|
+
import { a as raceAbort, c as align8, d as isDisplayItemType, i as KEEPALIVE_PREFERENCE, l as headerBytes, o as serverSourcedInputIds, p as writeHeader, r as KEEPALIVE_INTERVAL_MS, s as BINARY_SOLVE_MEDIA_TYPE, t as ASYNC_PREFERENCE } from "./compute-profile-D3g1Tuyd.js";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { randomUUID } from "node:crypto";
|
|
6
6
|
import { promisify } from "node:util";
|
|
@@ -27117,6 +27117,7 @@ function buildServerTiming(parts) {
|
|
|
27117
27117
|
const computeLinkMs = Math.max(0, parts.solveMs - decode - solve - encode);
|
|
27118
27118
|
header += `, rhino_decode;dur=${decode.toFixed(1)}, rhino_solve;dur=${solve.toFixed(1)}, rhino_encode;dur=${encode.toFixed(1)}, compute_link;dur=${computeLinkMs.toFixed(1)}, rhino_cache;dur=${rhino.cacheHit ? 1 : 0}`;
|
|
27119
27119
|
if (rhino.gh !== void 0) header += `, rhino_gh;dur=${rhino.gh.toFixed(1)}`;
|
|
27120
|
+
if (rhino.wait !== void 0) header += `, rhino_wait;dur=${rhino.wait.toFixed(1)}`;
|
|
27120
27121
|
if (rhino.recomputed) header += `, rhino_recomputed;desc="${rhino.recomputed.ran}/${rhino.recomputed.total}"`;
|
|
27121
27122
|
}
|
|
27122
27123
|
if (rhino?.affinity) header += `, rhino_affinity;desc=${rhino.affinity}`;
|
|
@@ -27127,6 +27128,13 @@ function buildServerTiming(parts) {
|
|
|
27127
27128
|
if (parts.defBytes) header += `, def_bytes;desc=${parts.defBytes}`;
|
|
27128
27129
|
return header;
|
|
27129
27130
|
}
|
|
27131
|
+
/**
|
|
27132
|
+
* The fork's slowest-objects profile as an `X-Compute-Profile` value. Names come from the
|
|
27133
|
+
* definition and can be any script; a header value must be ASCII.
|
|
27134
|
+
*/
|
|
27135
|
+
function computeProfileHeader(profile) {
|
|
27136
|
+
return JSON.stringify(profile).replace(/[\u007f-\uffff]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
27137
|
+
}
|
|
27130
27138
|
/** Rhino.Compute's own default `--timeout`, for a server that can't report its own. */
|
|
27131
27139
|
var DEFAULT_SOLVE_DEADLINE_MS = 1e5;
|
|
27132
27140
|
/**
|
|
@@ -27570,32 +27578,41 @@ var GZIP_LEVEL = 1;
|
|
|
27570
27578
|
var GZIP_MIN_BYTES = 1024;
|
|
27571
27579
|
var COMPUTE_VERSION_HEADER = "X-Selva-Compute-Version";
|
|
27572
27580
|
function buildEnvelope(encoded, result, serverTiming, metrics) {
|
|
27581
|
+
const { body, variant } = encoded;
|
|
27573
27582
|
const headers = {
|
|
27574
|
-
"Content-Type": "application/json",
|
|
27583
|
+
"Content-Type": variant === "binary" ? BINARY_SOLVE_MEDIA_TYPE : "application/json",
|
|
27575
27584
|
"Server-Timing": serverTiming,
|
|
27576
27585
|
[COMPUTE_VERSION_HEADER]: String(1),
|
|
27577
|
-
Vary: "Accept-Encoding"
|
|
27586
|
+
Vary: "Accept, Accept-Encoding"
|
|
27578
27587
|
};
|
|
27579
|
-
|
|
27580
|
-
if (encoding === "gzip") headers["Content-Encoding"] = "gzip";
|
|
27588
|
+
if (variant === "gzip") headers["Content-Encoding"] = "gzip";
|
|
27581
27589
|
headers["Content-Length"] = String(typeof body === "string" ? Buffer.byteLength(body) : body.byteLength);
|
|
27582
27590
|
return {
|
|
27583
27591
|
body,
|
|
27584
|
-
|
|
27592
|
+
variant,
|
|
27585
27593
|
headers,
|
|
27586
27594
|
result,
|
|
27587
27595
|
metrics
|
|
27588
27596
|
};
|
|
27589
27597
|
}
|
|
27590
|
-
/** Whether
|
|
27591
|
-
function
|
|
27592
|
-
return
|
|
27593
|
-
const [
|
|
27594
|
-
if (
|
|
27598
|
+
/** Whether a comma-separated header lists `token` without `q=0`, which is a client refusing it. */
|
|
27599
|
+
function listsToken(header, token) {
|
|
27600
|
+
return header.split(",").some((part) => {
|
|
27601
|
+
const [value, ...params] = part.split(";").map((s) => s.trim().toLowerCase());
|
|
27602
|
+
if (value !== token) return false;
|
|
27595
27603
|
const q = params.find((p) => p.startsWith("q="));
|
|
27596
27604
|
return q === void 0 || Number(q.slice(2)) > 0;
|
|
27597
27605
|
});
|
|
27598
27606
|
}
|
|
27607
|
+
/** Whether an `Accept-Encoding` header takes gzip. */
|
|
27608
|
+
function acceptsGzip(acceptEncoding) {
|
|
27609
|
+
return listsToken(acceptEncoding, "gzip");
|
|
27610
|
+
}
|
|
27611
|
+
/** The form a request with these headers is answered in. Only an explicit `Accept` gets binary. */
|
|
27612
|
+
function responseVariant(headers) {
|
|
27613
|
+
if (listsToken(headers.accept ?? "", "application/vnd.selva.solve+binary")) return "binary";
|
|
27614
|
+
return acceptsGzip(headers.acceptEncoding ?? "") ? "gzip" : "identity";
|
|
27615
|
+
}
|
|
27599
27616
|
/**
|
|
27600
27617
|
* A scheduler cache hit returns the same response object, so a repeat solve reuses its bytes rather
|
|
27601
27618
|
* than paying to serialize and compress them again. Entries live exactly as long as the response.
|
|
@@ -27603,6 +27620,7 @@ function acceptsGzip(acceptEncoding) {
|
|
|
27603
27620
|
* Holds the promise, so callers arriving during the compression share it.
|
|
27604
27621
|
*/
|
|
27605
27622
|
var gzippedBodies = /* @__PURE__ */ new WeakMap();
|
|
27623
|
+
var binaryBodies = /* @__PURE__ */ new WeakMap();
|
|
27606
27624
|
function gzipOnce(response, json, serializedBytes) {
|
|
27607
27625
|
const pending = gzipAsync(Buffer.from(json), { level: GZIP_LEVEL }).then((body) => ({
|
|
27608
27626
|
body,
|
|
@@ -27613,6 +27631,83 @@ function gzipOnce(response, json, serializedBytes) {
|
|
|
27613
27631
|
return pending;
|
|
27614
27632
|
}
|
|
27615
27633
|
/**
|
|
27634
|
+
* Splits every display batch's base64 blob out of `response` and frames the rest (wire format in
|
|
27635
|
+
* `shared/binary-response.ts`). The blobs are already deflated, so only the JSON section is gzipped.
|
|
27636
|
+
*/
|
|
27637
|
+
async function encodeBinary(response, maxBytes) {
|
|
27638
|
+
const serializeStart = performance.now();
|
|
27639
|
+
const blobs = [];
|
|
27640
|
+
let jsonBuffer;
|
|
27641
|
+
try {
|
|
27642
|
+
jsonBuffer = Buffer.from(JSON.stringify(withBlobsSplit(response, blobs)));
|
|
27643
|
+
} catch (err) {
|
|
27644
|
+
if (!(err instanceof RangeError)) throw err;
|
|
27645
|
+
return "too_large";
|
|
27646
|
+
}
|
|
27647
|
+
const blobBytes = blobs.reduce((sum, blob) => sum + blob.byteLength, 0);
|
|
27648
|
+
const serializedBytes = jsonBuffer.byteLength + blobBytes;
|
|
27649
|
+
if (serializedBytes > maxBytes) return "too_large";
|
|
27650
|
+
const serializeMs = performance.now() - serializeStart;
|
|
27651
|
+
const gzipJson = jsonBuffer.byteLength > GZIP_MIN_BYTES;
|
|
27652
|
+
const gzipStart = performance.now();
|
|
27653
|
+
const json = gzipJson ? await gzipAsync(jsonBuffer, { level: GZIP_LEVEL }) : jsonBuffer;
|
|
27654
|
+
const gzipMs = gzipJson ? performance.now() - gzipStart : 0;
|
|
27655
|
+
const lengths = blobs.map((blob) => blob.byteLength);
|
|
27656
|
+
let total = headerBytes(blobs.length) + align8(json.byteLength);
|
|
27657
|
+
for (const length of lengths) total += align8(length);
|
|
27658
|
+
const body = new Uint8Array(total);
|
|
27659
|
+
writeHeader(body, gzipJson ? 1 : 0, json.byteLength, lengths);
|
|
27660
|
+
let offset = headerBytes(blobs.length);
|
|
27661
|
+
body.set(json, offset);
|
|
27662
|
+
offset += align8(json.byteLength);
|
|
27663
|
+
for (const blob of blobs) {
|
|
27664
|
+
body.set(blob, offset);
|
|
27665
|
+
offset += align8(blob.byteLength);
|
|
27666
|
+
}
|
|
27667
|
+
return {
|
|
27668
|
+
body,
|
|
27669
|
+
serializedBytes,
|
|
27670
|
+
serializeMs,
|
|
27671
|
+
gzipMs
|
|
27672
|
+
};
|
|
27673
|
+
}
|
|
27674
|
+
/** A copy of `response` whose display batches point into `blobs`. Leaves `response` untouched: the solve cache still holds it. */
|
|
27675
|
+
function withBlobsSplit(response, blobs) {
|
|
27676
|
+
const { values } = response;
|
|
27677
|
+
if (!Array.isArray(values)) return response;
|
|
27678
|
+
return {
|
|
27679
|
+
...response,
|
|
27680
|
+
values: values.map((value) => {
|
|
27681
|
+
const out = { ...value };
|
|
27682
|
+
for (const key of ["InnerTree", "innerTree"]) {
|
|
27683
|
+
const tree = value[key];
|
|
27684
|
+
if (!tree || typeof tree !== "object") continue;
|
|
27685
|
+
out[key] = Object.fromEntries(Object.entries(tree).map(([path, branch]) => [path, Array.isArray(branch) ? branch.map((item) => splitDisplayItem(item, blobs)) : branch]));
|
|
27686
|
+
}
|
|
27687
|
+
return out;
|
|
27688
|
+
})
|
|
27689
|
+
};
|
|
27690
|
+
}
|
|
27691
|
+
function splitDisplayItem(item, blobs) {
|
|
27692
|
+
const { type, data } = item ?? {};
|
|
27693
|
+
if (typeof type !== "string" || typeof data !== "string" || !isDisplayItemType(type)) return item;
|
|
27694
|
+
let batch;
|
|
27695
|
+
try {
|
|
27696
|
+
batch = JSON.parse(data);
|
|
27697
|
+
} catch {
|
|
27698
|
+
return item;
|
|
27699
|
+
}
|
|
27700
|
+
if (typeof batch?.compressedData !== "string" || batch.compressedData === "") return item;
|
|
27701
|
+
blobs.push(Buffer.from(batch.compressedData, "base64"));
|
|
27702
|
+
return {
|
|
27703
|
+
...item,
|
|
27704
|
+
data: JSON.stringify({
|
|
27705
|
+
...batch,
|
|
27706
|
+
compressedData: { $blob: blobs.length - 1 }
|
|
27707
|
+
})
|
|
27708
|
+
};
|
|
27709
|
+
}
|
|
27710
|
+
/**
|
|
27616
27711
|
* One per solve. The JSON is kept here rather than beside the gzip body: it only has to outlive the
|
|
27617
27712
|
* callers of this flight, who would otherwise each stringify the same response and hold a copy.
|
|
27618
27713
|
*/
|
|
@@ -27633,8 +27728,26 @@ function createResponseEncoder(response, maxBytes) {
|
|
|
27633
27728
|
}
|
|
27634
27729
|
return serialized;
|
|
27635
27730
|
}
|
|
27636
|
-
return { async encode(
|
|
27637
|
-
|
|
27731
|
+
return { async encode(variant) {
|
|
27732
|
+
if (variant === "binary") {
|
|
27733
|
+
let pending = binaryBodies.get(response);
|
|
27734
|
+
const cached = pending !== void 0;
|
|
27735
|
+
if (!pending) {
|
|
27736
|
+
pending = encodeBinary(response, maxBytes);
|
|
27737
|
+
binaryBodies.set(response, pending);
|
|
27738
|
+
pending.catch(() => binaryBodies.delete(response));
|
|
27739
|
+
}
|
|
27740
|
+
const verdict = await pending;
|
|
27741
|
+
if (verdict === "too_large") return verdict;
|
|
27742
|
+
return {
|
|
27743
|
+
body: verdict.body,
|
|
27744
|
+
variant: "binary",
|
|
27745
|
+
serializedBytes: verdict.serializedBytes,
|
|
27746
|
+
serializeMs: cached ? 0 : verdict.serializeMs,
|
|
27747
|
+
gzipMs: cached ? 0 : verdict.gzipMs
|
|
27748
|
+
};
|
|
27749
|
+
}
|
|
27750
|
+
const wantsGzip = variant === "gzip";
|
|
27638
27751
|
let gzipped = wantsGzip ? gzippedBodies.get(response) : void 0;
|
|
27639
27752
|
let serializeMs = 0;
|
|
27640
27753
|
if (!gzipped) {
|
|
@@ -27647,6 +27760,7 @@ function createResponseEncoder(response, maxBytes) {
|
|
|
27647
27760
|
}
|
|
27648
27761
|
if (!wantsGzip || plain.bytes <= GZIP_MIN_BYTES) return {
|
|
27649
27762
|
body: plain.json,
|
|
27763
|
+
variant: "identity",
|
|
27650
27764
|
serializedBytes: plain.bytes,
|
|
27651
27765
|
serializeMs,
|
|
27652
27766
|
gzipMs: 0
|
|
@@ -27658,7 +27772,7 @@ function createResponseEncoder(response, maxBytes) {
|
|
|
27658
27772
|
if (verdict === "too_large") return verdict;
|
|
27659
27773
|
return {
|
|
27660
27774
|
body: verdict.body,
|
|
27661
|
-
|
|
27775
|
+
variant: "gzip",
|
|
27662
27776
|
serializedBytes: verdict.serializedBytes,
|
|
27663
27777
|
serializeMs,
|
|
27664
27778
|
gzipMs: performance.now() - gzipStart
|
|
@@ -27989,7 +28103,10 @@ var SolveEngine = class {
|
|
|
27989
28103
|
if (flight.kind !== "solved") return flight;
|
|
27990
28104
|
let encoded;
|
|
27991
28105
|
try {
|
|
27992
|
-
encoded = await flight.encoder.encode(
|
|
28106
|
+
encoded = await flight.encoder.encode(responseVariant({
|
|
28107
|
+
accept: args.accept,
|
|
28108
|
+
acceptEncoding: args.acceptEncoding
|
|
28109
|
+
}));
|
|
27993
28110
|
} catch (error) {
|
|
27994
28111
|
return {
|
|
27995
28112
|
kind: "compute_error",
|
|
@@ -28021,7 +28138,7 @@ var SolveEngine = class {
|
|
|
28021
28138
|
envelope: buildEnvelope(encoded, response, serverTiming, {
|
|
28022
28139
|
...timing,
|
|
28023
28140
|
serializedBytes,
|
|
28024
|
-
compressedBytes: encoded.
|
|
28141
|
+
compressedBytes: encoded.variant === "identity" ? null : body.byteLength
|
|
28025
28142
|
}),
|
|
28026
28143
|
solveMs,
|
|
28027
28144
|
errorCount: response.errors?.length ?? 0,
|
|
@@ -28301,6 +28418,6 @@ function waitFor(done, ms, signal) {
|
|
|
28301
28418
|
}
|
|
28302
28419
|
});
|
|
28303
28420
|
}
|
|
28304
|
-
export { acceptedResponse as a, respondWithKeepalive as c,
|
|
28421
|
+
export { acceptedResponse as a, respondWithKeepalive as c, storedToResponse as d, wantsAsync as f, SolveEngine as i, responseVariant as l, DEFAULT_SOLVE_DEADLINE_MS as n, computeProfileHeader as o, wantsKeepalive as p, MAX_SOLVE_DEADLINE_MS as r, postedServerSourcedIds as s, AsyncSolveStore as t, solveInputsFromSchema as u };
|
|
28305
28422
|
|
|
28306
28423
|
//# sourceMappingURL=server.js.map
|