@selvajs/selva 4.20.1-beta.4 → 4.21.0-beta.6
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/chunks/{CzfnuBzq.js → BAhtiTKe.js} +1 -1
- package/build/client/_app/immutable/chunks/BAhtiTKe.js.br +0 -0
- package/build/client/_app/immutable/chunks/BAhtiTKe.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{D-uUm_OB.js → BepzH9eI.js} +4 -4
- package/build/client/_app/immutable/chunks/BepzH9eI.js.br +0 -0
- package/build/client/_app/immutable/chunks/{D-uUm_OB.js.gz → BepzH9eI.js.gz} +0 -0
- package/build/client/_app/immutable/chunks/BmoT9ksD.js +1 -0
- package/build/client/_app/immutable/chunks/BmoT9ksD.js.br +1 -0
- package/build/client/_app/immutable/chunks/BmoT9ksD.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{qi43d-TM.js → CKbHmAlc.js} +1 -1
- package/build/client/_app/immutable/chunks/CKbHmAlc.js.br +0 -0
- package/build/client/_app/immutable/chunks/CKbHmAlc.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{C6Y_BUwr.js → CmlXAF26.js} +1 -1
- package/build/client/_app/immutable/chunks/CmlXAF26.js.br +0 -0
- package/build/client/_app/immutable/chunks/CmlXAF26.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{BDYCH-_Q.js → D5j4-ZO1.js} +1 -1
- package/build/client/_app/immutable/chunks/D5j4-ZO1.js.br +0 -0
- package/build/client/_app/immutable/chunks/D5j4-ZO1.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DW5EJMC7.js +1 -0
- package/build/client/_app/immutable/chunks/DW5EJMC7.js.br +0 -0
- package/build/client/_app/immutable/chunks/DW5EJMC7.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{DzxE3j6C.js → qXnHMKD9.js} +1 -1
- package/build/client/_app/immutable/chunks/qXnHMKD9.js.br +0 -0
- package/build/client/_app/immutable/chunks/qXnHMKD9.js.gz +0 -0
- package/build/client/_app/immutable/entry/{app.BpT6WkO1.js → app.DblLep9O.js} +2 -2
- package/build/client/_app/immutable/entry/app.DblLep9O.js.br +0 -0
- package/build/client/_app/immutable/entry/app.DblLep9O.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{1.D3kiiIk_.js → 1.DWd6YbcT.js} +1 -1
- package/build/client/_app/immutable/nodes/1.DWd6YbcT.js.br +0 -0
- package/build/client/_app/immutable/nodes/1.DWd6YbcT.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{2.CUNbzjI_.js → 2.CS32Eh9m.js} +1 -1
- package/build/client/_app/immutable/nodes/2.CS32Eh9m.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.CS32Eh9m.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{20.9OIre0ah.js → 20.CUK41A3B.js} +1 -1
- package/build/client/_app/immutable/nodes/20.CUK41A3B.js.br +0 -0
- package/build/client/_app/immutable/nodes/20.CUK41A3B.js.gz +0 -0
- package/build/client/_app/immutable/nodes/21.DvC40Ypm.js +1 -0
- package/build/client/_app/immutable/nodes/21.DvC40Ypm.js.br +0 -0
- package/build/client/_app/immutable/nodes/21.DvC40Ypm.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{25.DW1_vMxq.js → 25.D6EkgNRa.js} +1 -1
- package/build/client/_app/immutable/nodes/25.D6EkgNRa.js.br +0 -0
- package/build/client/_app/immutable/nodes/25.D6EkgNRa.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{3.3Z4QUsQQ.js → 3.Ctd9OGCk.js} +1 -1
- package/build/client/_app/immutable/nodes/3.Ctd9OGCk.js.br +0 -0
- package/build/client/_app/immutable/nodes/3.Ctd9OGCk.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{5.DmA9lTA-.js → 5.Wh_w3RkZ.js} +1 -1
- package/build/client/_app/immutable/nodes/5.Wh_w3RkZ.js.br +2 -0
- package/build/client/_app/immutable/nodes/5.Wh_w3RkZ.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{6.D6WLqCgl.js → 6.C-DiUI5R.js} +1 -1
- package/build/client/_app/immutable/nodes/6.C-DiUI5R.js.br +0 -0
- package/build/client/_app/immutable/nodes/6.C-DiUI5R.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{7.CNuRjkv2.js → 7.B8yubYrv.js} +1 -1
- package/build/client/_app/immutable/nodes/7.B8yubYrv.js.br +0 -0
- package/build/client/_app/immutable/nodes/7.B8yubYrv.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/server/.vite/manifest.json +7 -5
- package/build/server/chunks/api.js +9 -2
- package/build/server/chunks/api.js.map +1 -1
- package/build/server/chunks/computeRateLimit.server.js +1 -1
- package/build/server/chunks/engine.server.js +2 -2
- package/build/server/chunks/engine.server.js.map +1 -1
- package/build/server/chunks/grasshopper.js +217 -162
- package/build/server/chunks/grasshopper.js.map +1 -1
- package/build/server/chunks/handlers.js +1 -1
- package/build/server/chunks/instance.js +3 -3
- package/build/server/chunks/internal.js +1 -1
- package/build/server/chunks/liveSolve.server.js +1 -1
- package/build/server/chunks/localeContext.svelte.js +14 -0
- package/build/server/chunks/localeContext.svelte.js.map +1 -1
- package/build/server/chunks/{outcome-DNrffAXp.js → outcome-D28FgvFK.js} +9 -6
- package/build/server/chunks/outcome-D28FgvFK.js.map +1 -0
- package/build/server/chunks/package.js +1 -1
- package/build/server/chunks/package.js.map +1 -1
- package/build/server/chunks/providers.server.js +59 -40
- package/build/server/chunks/providers.server.js.map +1 -1
- package/build/server/chunks/registry.js +1 -1
- package/build/server/chunks/schema.js +1 -1
- package/build/server/chunks/schema.js.map +1 -1
- package/build/server/chunks/serverStats.server.js +1 -1
- package/build/server/chunks/solve.server.js +31 -4
- package/build/server/chunks/solve.server.js.map +1 -1
- package/build/server/chunks/sveltekit.js +1 -1
- package/build/server/entries/endpoints/api/admin/compute/status/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/orgs/_id_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/orgs/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/projects/_id_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/projects/_id_/grants/_grantId_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/projects/_id_/grants/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/projects/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/users/_id_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/users/_id_/disable/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/users/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/compute/_server.ts.js +5 -1
- package/build/server/entries/endpoints/api/v1/compute/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/v1/compute/schema/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/image/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/publish/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/schema/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/share-links/_linkId_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/share-links/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/solve/_server.ts.js +2 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/solve/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/versions/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/versions/_versionId_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/versions/_versionId_/schema/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/projects/_id_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/projects/_id_/members/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/projects/_id_/members/_userId_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/projects/_id_/reclaim/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/solve/_solveId_/cancel/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/solve-events/_server.ts.js +1 -1
- package/build/server/entries/endpoints/docs/api/openapi.yaml/_server.ts.js +1 -1
- package/build/server/entries/pages/library/_guid_/_page.server.ts.js +4 -4
- package/build/server/entries/pages/library/_guid_/_page.server.ts.js.map +1 -1
- package/build/server/entries/pages/library/_guid_/_page.svelte.js +232 -11
- 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/1.js +1 -1
- package/build/server/nodes/2.js +1 -1
- package/build/server/nodes/20.js +1 -1
- package/build/server/nodes/21.js +1 -1
- package/build/server/nodes/25.js +1 -1
- package/build/server/nodes/3.js +1 -1
- package/build/server/nodes/5.js +1 -1
- package/build/server/nodes/6.js +1 -1
- package/build/server/nodes/7.js +1 -1
- package/build/server/server.js +1 -1
- package/package.json +10 -10
- package/build/client/_app/immutable/chunks/BDYCH-_Q.js.br +0 -0
- package/build/client/_app/immutable/chunks/BDYCH-_Q.js.gz +0 -0
- package/build/client/_app/immutable/chunks/C6Y_BUwr.js.br +0 -0
- package/build/client/_app/immutable/chunks/C6Y_BUwr.js.gz +0 -0
- package/build/client/_app/immutable/chunks/CzfnuBzq.js.br +0 -0
- package/build/client/_app/immutable/chunks/CzfnuBzq.js.gz +0 -0
- package/build/client/_app/immutable/chunks/D-uUm_OB.js.br +0 -0
- package/build/client/_app/immutable/chunks/D84F7w9g.js +0 -1
- package/build/client/_app/immutable/chunks/D84F7w9g.js.br +0 -1
- package/build/client/_app/immutable/chunks/D84F7w9g.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DQsP4nZb.js +0 -1
- package/build/client/_app/immutable/chunks/DQsP4nZb.js.br +0 -0
- package/build/client/_app/immutable/chunks/DQsP4nZb.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DzxE3j6C.js.br +0 -0
- package/build/client/_app/immutable/chunks/DzxE3j6C.js.gz +0 -0
- package/build/client/_app/immutable/chunks/qi43d-TM.js.br +0 -0
- package/build/client/_app/immutable/chunks/qi43d-TM.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.BpT6WkO1.js.br +0 -0
- package/build/client/_app/immutable/entry/app.BpT6WkO1.js.gz +0 -0
- package/build/client/_app/immutable/nodes/1.D3kiiIk_.js.br +0 -0
- package/build/client/_app/immutable/nodes/1.D3kiiIk_.js.gz +0 -0
- package/build/client/_app/immutable/nodes/2.CUNbzjI_.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.CUNbzjI_.js.gz +0 -0
- package/build/client/_app/immutable/nodes/20.9OIre0ah.js.br +0 -0
- package/build/client/_app/immutable/nodes/20.9OIre0ah.js.gz +0 -0
- package/build/client/_app/immutable/nodes/21.BkNlRItr.js +0 -1
- package/build/client/_app/immutable/nodes/21.BkNlRItr.js.br +0 -0
- package/build/client/_app/immutable/nodes/21.BkNlRItr.js.gz +0 -0
- package/build/client/_app/immutable/nodes/25.DW1_vMxq.js.br +0 -0
- package/build/client/_app/immutable/nodes/25.DW1_vMxq.js.gz +0 -0
- package/build/client/_app/immutable/nodes/3.3Z4QUsQQ.js.br +0 -0
- package/build/client/_app/immutable/nodes/3.3Z4QUsQQ.js.gz +0 -0
- package/build/client/_app/immutable/nodes/5.DmA9lTA-.js.br +0 -1
- package/build/client/_app/immutable/nodes/5.DmA9lTA-.js.gz +0 -0
- package/build/client/_app/immutable/nodes/6.D6WLqCgl.js.br +0 -0
- package/build/client/_app/immutable/nodes/6.D6WLqCgl.js.gz +0 -0
- package/build/client/_app/immutable/nodes/7.CNuRjkv2.js.br +0 -0
- package/build/client/_app/immutable/nodes/7.CNuRjkv2.js.gz +0 -0
- package/build/server/chunks/outcome-DNrffAXp.js.map +0 -1
|
@@ -56,7 +56,7 @@ function createDefinitionLoader(deps) {
|
|
|
56
56
|
}
|
|
57
57
|
let client;
|
|
58
58
|
try {
|
|
59
|
-
client = (await getClient(computeServer
|
|
59
|
+
client = (await getClient(computeServer)).client;
|
|
60
60
|
} catch (err) {
|
|
61
61
|
throw new DefinitionLoadError("connect", `Failed to connect to Rhino Compute server: ${err instanceof Error ? err.message : String(err)}`, err);
|
|
62
62
|
}
|
|
@@ -64,7 +64,7 @@ function createDefinitionLoader(deps) {
|
|
|
64
64
|
const cachedSchema = version.schema;
|
|
65
65
|
const freshCache = cachedSchema && isUsableCachedSchema(cachedSchema) ? cachedSchema : null;
|
|
66
66
|
const [definition, fetchedSchema] = await Promise.all([client.getIO(definitionSource), freshCache ? Promise.resolve(freshCache) : fetchSchema(definitionSource, computeServer)]);
|
|
67
|
-
if (!freshCache && fetchedSchema.schemaVersion === "2.
|
|
67
|
+
if (!freshCache && fetchedSchema.schemaVersion === "2.20.0") definitions.setVersionSchema(ctx, version.id, fetchedSchema).catch((err) => {
|
|
68
68
|
if (onWarn) {
|
|
69
69
|
onWarn(`[loadForRender] schema cache refresh failed for version ${version.id}: ${err instanceof Error ? err.message : String(err)}`);
|
|
70
70
|
return;
|
|
@@ -124,7 +124,7 @@ function createDefinitionLoader(deps) {
|
|
|
124
124
|
* after the server was fixed. See `assertCamelCaseSchema`.
|
|
125
125
|
*/
|
|
126
126
|
function isUsableCachedSchema(schema) {
|
|
127
|
-
return schema.schemaVersion === "2.
|
|
127
|
+
return schema.schemaVersion === "2.20.0" && Array.isArray(schema.inputs);
|
|
128
128
|
}
|
|
129
129
|
function mergeComputeDefaults(schema, computeInputs) {
|
|
130
130
|
if (!Array.isArray(schema.inputs)) throw new DefinitionLoadError("schema", `Schema has no 'inputs' array (keys: ${Object.keys(schema).slice(0, 12).join(", ")}). A PascalCase shape here means compute serialized it with the wrong Newtonsoft — see assertCamelCaseSchema.`);
|
|
@@ -179,7 +179,7 @@ var load = (async ({ params, locals, request, url }) => {
|
|
|
179
179
|
await asHttpError(() => requireEditableDefinition(scoped(locals), guid));
|
|
180
180
|
}
|
|
181
181
|
const [loaded, orgLogoUrl] = await Promise.all([loadDefinitionForRender(ctx, record, channel, explicitVersionId), resolveOrgLogo(ctx, record.projectId, locals.log)]);
|
|
182
|
-
const { limits } = await getClient(loaded.computeServer
|
|
182
|
+
const { limits } = await getClient(loaded.computeServer);
|
|
183
183
|
return {
|
|
184
184
|
schema: loaded.schema,
|
|
185
185
|
ghDefinition: clientDefUrl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_page.server.ts.js","names":[],"sources":["../../../../../../../server/src/definitions/load-for-render.ts","../../../../../../src/lib/server/definitions/loadForRender.server.ts","../../../../../../src/routes/library/[guid]/+page.server.ts"],"sourcesContent":["// Given a definition record, produces everything the client needs to render its\n// form and solve it.\n//\n// Access gating is deliberately NOT done here — the calling route decides\n// whether `ctx` may load this definition, since gates differ across routes\n// (project membership, segment ownership, share-token, admin override).\n//\n// Everything stateful is injected, so any app on the engine can wire its own\n// composition root.\n\nimport type { GrasshopperClient } from '@selvajs/compute/grasshopper';\nimport { UI_SCHEMA_VERSION, type UISchema } from '@selvajs/schemas';\nimport type {\n\tComputeServerConfig,\n\tDefinitionRecord,\n\tDefinitionVersion,\n\tIDefinitionStore,\n\tIProjectStore,\n\tIStorageProvider,\n\tRequestContext\n} from '@selvajs/platform';\nimport { NoopLogger, type ILogger } from '@selvajs/platform';\nimport { fetchSchemaFromCompute } from './schema-extraction.js';\n\nexport type DefinitionChannel = 'live' | 'draft';\n\nexport interface LoadedDefinition {\n\tversion: DefinitionVersion;\n\tdefinitionSource: Uint8Array;\n\tcomputeServer: ComputeServerConfig;\n\tschema: UISchema;\n}\n\n/**\n * Classified failure modes so callers can map to appropriate HTTP status:\n * - 'data': record references a version/blob that isn't there. (400)\n * - 'missing-config': no compute server resolvable for this org/definition. (503)\n * - 'connect': compute server is configured but unreachable. (503)\n * - 'schema': compute responded but IO/schema phase failed. (500)\n */\nexport type DefinitionLoadErrorKind = 'data' | 'missing-config' | 'connect' | 'schema';\n\nexport class DefinitionLoadError extends Error {\n\tconstructor(\n\t\tpublic readonly kind: DefinitionLoadErrorKind,\n\t\tmessage: string,\n\t\tpublic readonly cause?: unknown\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'DefinitionLoadError';\n\t}\n}\n\nexport interface DefinitionLoaderDeps {\n\tstorage: Pick<IStorageProvider, 'get'>;\n\tdefinitions: Pick<IDefinitionStore, 'getVersion' | 'setVersionSchema'>;\n\tprojects: Pick<IProjectStore, 'getProject'>;\n\t/** Resolution order: definition pin → org default override → global default. */\n\tresolveServer: (\n\t\tctx: RequestContext,\n\t\torgId: string | null,\n\t\topts: { definitionPin: string | null }\n\t) => Promise<ComputeServerConfig>;\n\t/** Shared warm-client cache, keyed by server id with a definition-guid affinity header. */\n\tgetClient: (\n\t\tserver: ComputeServerConfig,\n\t\topts: { definitionGuid: string }\n\t) => Promise<{ client: GrasshopperClient }>;\n\t/** Schema extraction; defaults to `fetchSchemaFromCompute`. Injectable for tests. */\n\tfetchSchema?: (bytes: Uint8Array, server: ComputeServerConfig) => Promise<UISchema>;\n\t/**\n\t * When set, an unhealthy IO result also dumps the raw /io wire shape, making\n\t * casing/serialization mismatches visible.\n\t */\n\tcomputeDebug?: boolean;\n\t/** Legacy diagnostic sink. When set it takes the warnings below instead of `logger`. */\n\tonWarn?: (message: string, detail?: string) => void;\n\t/**\n\t * Defaults to `NoopLogger`, so a consumer that wires nothing gets silence\n\t * rather than unsolicited stdout.\n\t */\n\tlogger?: ILogger;\n}\n\nexport interface DefinitionLoadOptions {\n\t/**\n\t * For callers that read only schema STRUCTURE (input ids, `source.key`,\n\t * widget types — anything persisted at upload). A fresh cached schema then\n\t * returns without touching compute, whose multi-second connect otherwise\n\t * dominates a page resolving several definitions.\n\t *\n\t * Leave unset (the default) for anything that RENDERS a form — without\n\t * compute defaults the form shows the wrong initial values.\n\t */\n\tskipComputeDefaults?: boolean;\n}\n\nexport type DefinitionLoader = (\n\tctx: RequestContext,\n\trecord: DefinitionRecord,\n\tchannel: DefinitionChannel,\n\texplicitVersionId?: string | null,\n\toptions?: DefinitionLoadOptions\n) => Promise<LoadedDefinition>;\n\n/**\n * The returned loader resolves the `channel` pointer (live/draft) by default.\n * `explicitVersionId` renders an arbitrary historical version instead — the\n * caller MUST gate that behind edit permission, as with the draft channel.\n */\nexport function createDefinitionLoader(deps: DefinitionLoaderDeps): DefinitionLoader {\n\tconst {\n\t\tstorage,\n\t\tdefinitions,\n\t\tprojects,\n\t\tresolveServer,\n\t\tgetClient,\n\t\tfetchSchema = fetchSchemaFromCompute,\n\t\tcomputeDebug = false,\n\t\tonWarn,\n\t\tlogger = new NoopLogger()\n\t} = deps;\n\n\treturn async function loadDefinitionForRender(ctx, record, channel, explicitVersionId, options) {\n\t\tconst versionId =\n\t\t\texplicitVersionId ?? (channel === 'draft' ? record.draftVersionId : record.liveVersionId);\n\t\tif (!versionId)\n\t\t\tthrow new DefinitionLoadError(\n\t\t\t\t'data',\n\t\t\t\t`Definition '${record.guid}' has no ${channel} version`\n\t\t\t);\n\n\t\t// The server needs only the record, so it resolves while the version and file are read.\n\t\t// It is awaited after them, so a definition missing its data still fails as 'data'.\n\t\tconst pendingServer = (async (): Promise<ComputeServerConfig> => {\n\t\t\tconst project = await projects.getProject(ctx, record.projectId);\n\t\t\ttry {\n\t\t\t\treturn await resolveServer(ctx, project?.orgId ?? null, {\n\t\t\t\t\tdefinitionPin: record.computeServerId ?? null\n\t\t\t\t});\n\t\t\t} catch (err) {\n\t\t\t\tthrow new DefinitionLoadError(\n\t\t\t\t\t'missing-config',\n\t\t\t\t\t'No compute server configured for this definition',\n\t\t\t\t\terr\n\t\t\t\t);\n\t\t\t}\n\t\t})();\n\t\tpendingServer.catch(() => {});\n\n\t\tconst version = await definitions.getVersion(ctx, versionId);\n\t\tif (!version) throw new DefinitionLoadError('data', `version missing for '${record.guid}'`);\n\t\t// An explicitly requested version must belong to this definition.\n\t\tif (version.definitionId !== record.guid)\n\t\t\tthrow new DefinitionLoadError('data', `version does not belong to '${record.guid}'`);\n\n\t\tconst definitionSource = await storage.get(version.fileKey);\n\t\tif (!definitionSource)\n\t\t\tthrow new DefinitionLoadError(\n\t\t\t\t'data',\n\t\t\t\t`Definition file for '${record.guid}' not found on disk`\n\t\t\t);\n\n\t\tconst computeServer = await pendingServer;\n\n\t\t// Returning before `getClient` is the point — the connect is the cost, not\n\t\t// the `getIO` it carries. A missing or stale-format cache falls through to\n\t\t// the full path below, so the result is always a valid schema.\n\t\tif (options?.skipComputeDefaults) {\n\t\t\tconst cachedSchema = version.schema as UISchema | undefined;\n\t\t\tif (cachedSchema && isUsableCachedSchema(cachedSchema)) {\n\t\t\t\treturn { version, definitionSource, computeServer, schema: cachedSchema };\n\t\t\t}\n\t\t}\n\n\t\t// Only the client is used here (getIO); the entry's solve scheduler rides\n\t\t// along unused.\n\t\tlet client: GrasshopperClient;\n\t\ttry {\n\t\t\tclient = (await getClient(computeServer, { definitionGuid: record.guid })).client;\n\t\t} catch (err) {\n\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\tthrow new DefinitionLoadError(\n\t\t\t\t'connect',\n\t\t\t\t`Failed to connect to Rhino Compute server: ${message}`,\n\t\t\t\terr\n\t\t\t);\n\t\t}\n\n\t\ttry {\n\t\t\t// The stored schema is a disposable cache, used ONLY when its format\n\t\t\t// version matches the app's. On a mismatch (or a pre-caching row with no\n\t\t\t// schema) re-extract from compute, whose C# SchemaMigrator emits the\n\t\t\t// current format — the web side never migrates schemas itself. `getIO`\n\t\t\t// runs either way, to merge compute default values in.\n\t\t\tconst cachedSchema = version.schema as UISchema | undefined;\n\t\t\tconst freshCache = cachedSchema && isUsableCachedSchema(cachedSchema) ? cachedSchema : null;\n\t\t\tconst [definition, fetchedSchema] = await Promise.all([\n\t\t\t\tclient.getIO(definitionSource),\n\t\t\t\tfreshCache ? Promise.resolve(freshCache) : fetchSchema(definitionSource, computeServer)\n\t\t\t]);\n\n\t\t\t// Best-effort — a viewer context may lack write access, and the next\n\t\t\t// editor render or the solve-time backfill will land it. Guarded on the\n\t\t\t// current version because persisting an older format (compute plugin\n\t\t\t// behind the app) would just go stale again next render.\n\t\t\tif (!freshCache && fetchedSchema.schemaVersion === UI_SCHEMA_VERSION) {\n\t\t\t\tdefinitions.setVersionSchema(ctx, version.id, fetchedSchema).catch((err) => {\n\t\t\t\t\tif (onWarn) {\n\t\t\t\t\t\tonWarn(\n\t\t\t\t\t\t\t`[loadForRender] schema cache refresh failed for version ${version.id}: ` +\n\t\t\t\t\t\t\t\t`${err instanceof Error ? err.message : String(err)}`\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlogger.warn('Schema cache refresh failed', {\n\t\t\t\t\t\tcomponent: 'loadForRender',\n\t\t\t\t\t\tversionId: version.id,\n\t\t\t\t\t\terr: err instanceof Error ? (err.stack ?? err.message) : String(err)\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!definition) {\n\t\t\t\tthrow new Error(`Failed to get definition IO — server returned undefined`);\n\t\t\t}\n\n\t\t\t// Zero inputs or reported parse/load problems mean a definition that will\n\t\t\t// render wrong without saying why: an empty ValueList whose backing GH\n\t\t\t// component didn't resolve (\"Missing Definition Objects\"), or a PascalCase\n\t\t\t// /io response the parser silently dropped to []. Warning is always on —\n\t\t\t// it only fires on the unhappy path — while the raw wire dump costs an\n\t\t\t// extra round-trip and stays behind `computeDebug`.\n\t\t\tconst ioParseErrors = (definition as { parseErrors?: unknown[] }).parseErrors ?? [];\n\t\t\tconst ioLoadErrors = (definition as { loadErrors?: unknown[] }).loadErrors ?? [];\n\t\t\tconst ioLooksBroken =\n\t\t\t\tdefinition.inputs.length === 0 || ioParseErrors.length > 0 || ioLoadErrors.length > 0;\n\t\t\tif (ioLooksBroken) {\n\t\t\t\tconst health = {\n\t\t\t\t\tinputCount: definition.inputs.length,\n\t\t\t\t\toutputCount: definition.outputs?.length,\n\t\t\t\t\tparseErrors: ioParseErrors,\n\t\t\t\t\tloadErrors: ioLoadErrors,\n\t\t\t\t\tloadWarnings: (definition as { loadWarnings?: unknown }).loadWarnings\n\t\t\t\t};\n\t\t\t\tif (onWarn) {\n\t\t\t\t\tonWarn(`[loadForRender] IO health for '${record.guid}':`, JSON.stringify(health));\n\t\t\t\t} else {\n\t\t\t\t\tlogger.warn('Definition IO looks unhealthy', {\n\t\t\t\t\t\tcomponent: 'loadForRender',\n\t\t\t\t\t\tdefinitionGuid: record.guid,\n\t\t\t\t\t\t...health\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (computeDebug) {\n\t\t\t\t\tconst rawIO = await client\n\t\t\t\t\t\t.getRawIO(definitionSource)\n\t\t\t\t\t\t.catch((e) => ({ error: String(e) }));\n\t\t\t\t\tconst rendered = JSON.stringify(rawIO).slice(0, 3000);\n\t\t\t\t\tif (onWarn) onWarn('[loadForRender] raw /io:', rendered);\n\t\t\t\t\telse\n\t\t\t\t\t\tlogger.debug('Raw /io wire shape', {\n\t\t\t\t\t\t\tcomponent: 'loadForRender',\n\t\t\t\t\t\t\tdefinitionGuid: record.guid,\n\t\t\t\t\t\t\trawIO: rendered\n\t\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tversion,\n\t\t\t\tdefinitionSource,\n\t\t\t\tcomputeServer,\n\t\t\t\tschema: mergeComputeDefaults(fetchedSchema, definition.inputs)\n\t\t\t};\n\t\t} catch (err) {\n\t\t\tif (err instanceof DefinitionLoadError) throw err;\n\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\tthrow new DefinitionLoadError('schema', message, err);\n\t\t}\n\t};\n}\n\n/**\n * A cached schema is usable only if it is BOTH the current format version and\n * structurally sound. The version check alone is not enough: a compute server\n * that serialized the schema with the wrong Newtonsoft emits PascalCase keys, so\n * `schemaVersion` reads as undefined while `SchemaVersion` holds the value —\n * and a row cached during that window would otherwise be served forever, long\n * after the server was fixed. See `assertCamelCaseSchema`.\n */\nexport function isUsableCachedSchema(schema: UISchema): boolean {\n\treturn schema.schemaVersion === UI_SCHEMA_VERSION && Array.isArray(schema.inputs);\n}\n\n// Colors come back from Compute as \"r,g,b\" or \"a,r,g,b\" strings — converted to\n// hex here so the color picker can consume them directly.\nfunction mergeComputeDefaults(\n\tschema: UISchema,\n\tcomputeInputs: Array<{ id?: string; paramType?: string; default?: unknown }>\n): UISchema {\n\tif (!Array.isArray(schema.inputs)) {\n\t\tthrow new DefinitionLoadError(\n\t\t\t'schema',\n\t\t\t`Schema has no 'inputs' array (keys: ${Object.keys(schema as object)\n\t\t\t\t.slice(0, 12)\n\t\t\t\t.join(', ')}). A PascalCase shape here means compute serialized it with the wrong ` +\n\t\t\t\t`Newtonsoft — see assertCamelCaseSchema.`\n\t\t);\n\t}\n\n\tconst byParamId = new Map(computeInputs.map((input) => [input.id, input]));\n\n\treturn {\n\t\t...schema,\n\t\tinputs: schema.inputs.map((schemaInput) => {\n\t\t\tconst computeInput = byParamId.get(schemaInput.id);\n\n\t\t\tif (computeInput?.paramType === 'Color' && computeInput.default !== undefined) {\n\t\t\t\tconst toHex = (value: number) => value.toString(16).padStart(2, '0');\n\t\t\t\tconst parts = String(computeInput.default)\n\t\t\t\t\t.split(',')\n\t\t\t\t\t.map((s) => parseInt(s.trim(), 10));\n\n\t\t\t\tif (parts.length === 3) {\n\t\t\t\t\tcomputeInput.default = `#${toHex(parts[0])}${toHex(parts[1])}${toHex(parts[2])}`;\n\t\t\t\t} else if (parts.length === 4) {\n\t\t\t\t\tcomputeInput.default = `#${toHex(parts[1])}${toHex(parts[2])}${toHex(parts[3])}`;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (computeInput && computeInput.default !== undefined) {\n\t\t\t\treturn { ...schemaInput, default: computeInput.default };\n\t\t\t}\n\t\t\treturn schemaInput;\n\t\t})\n\t};\n}\n","// `@selvajs/server/definitions` owns the loading pipeline (version resolution,\n// blob fetch, schema staleness check, default merging); this wires in the\n// app's providers, compute-server resolution, and warm-client cache. Access\n// gating stays with the calling route.\n\nimport {\n\tcreateDefinitionLoader,\n\tDefinitionLoadError,\n\ttype DefinitionChannel,\n\ttype DefinitionLoadErrorKind,\n\ttype LoadedDefinition\n} from '@selvajs/server/definitions';\nimport type { DefinitionRecord, RequestContext } from '@selvajs/platform';\nimport {\n\tgetStorageProvider,\n\tgetDefinitionMeta,\n\tgetProjectProvider,\n\tgetComputeServerConfigStore\n} from '../providers.server';\nimport { serverResolver } from '../compute/serverResolver.server';\nimport { getClient, COMPUTE_DEBUG } from '../compute/engine.server';\n\nexport { DefinitionLoadError };\nexport type { DefinitionChannel, DefinitionLoadErrorKind, LoadedDefinition };\n\nexport async function loadDefinitionForRender(\n\tctx: RequestContext,\n\trecord: DefinitionRecord,\n\tchannel: DefinitionChannel,\n\texplicitVersionId?: string | null\n): Promise<LoadedDefinition> {\n\tconst load = createDefinitionLoader({\n\t\tstorage: getStorageProvider(),\n\t\tdefinitions: getDefinitionMeta(),\n\t\tprojects: getProjectProvider(),\n\t\tresolveServer: (ctx, orgId, opts) =>\n\t\t\tserverResolver.resolve(ctx, orgId, getComputeServerConfigStore(), opts),\n\t\tgetClient,\n\t\tcomputeDebug: COMPUTE_DEBUG\n\t});\n\treturn load(ctx, record, channel, explicitVersionId);\n}\n","import type { PageServerLoad } from './$types';\nimport { error } from '@sveltejs/kit';\nimport type { ILogger, RequestContext } from '@selvajs/platform';\nimport { renderThrown } from '@selvajs/server/logging';\nimport {\n\tgetDefinitionMeta,\n\tgetProjectProvider,\n\tgetOrganizationProvider\n} from '#lib/server/providers.server.js';\nimport { isApiError } from '@selvajs/server/api';\nimport { asHttpError, requireCanSolve, scoped } from '#lib/server/access.server.js';\nimport { readShareToken, tryResolveShareToken } from '#lib/server/shareLinks/resolve.server.js';\nimport { getClient } from '#lib/server/compute/engine.server.js';\nimport {\n\tloadDefinitionForRender,\n\tDefinitionLoadError\n} from '#lib/server/definitions/loadForRender.server.js';\n\nexport const load = (async ({ params, locals, request, url }) => {\n\tconst meta = getDefinitionMeta();\n\n\tconst guid = params.guid;\n\tconst channel = url.searchParams.get('channel') === 'draft' ? 'draft' : 'live';\n\t// Explicit version pick (versioning tab \"Run\"): render an arbitrary version,\n\t// not just the live/draft pointer. Editor-only, never share-token accessible.\n\tconst explicitVersionId = url.searchParams.get('version');\n\tconst clientDefUrl = `local:${guid}`;\n\t// `shareToken` is forwarded to the page so the client can include it on\n\t// subsequent /api/compute/solve calls. null = user-authenticated session.\n\tlet shareToken: string | null = null;\n\n\ttry {\n\t\t// Draft channel and explicit-version picks are editor-only — share tokens\n\t\t// are always live channel on the pointer. A signed-in viewer who can solve\n\t\t// anyway ignores the token: a share-token solve gets no live events and\n\t\t// counts against the link's solve cap.\n\t\tconst sharedAccess =\n\t\t\tchannel === 'live' &&\n\t\t\t!explicitVersionId &&\n\t\t\treadShareToken(request, url) !== null &&\n\t\t\t!(await sessionCanSolve(locals, guid))\n\t\t\t\t? await tryResolveShareToken(request, url, guid, 'live', { requireSolve: false })\n\t\t\t\t: null;\n\t\tif (sharedAccess) {\n\t\t\tshareToken = url.searchParams.get('token');\n\t\t} else if (!locals.ctx || !locals.user) {\n\t\t\tthrow error(401, 'Unauthorized: You must be logged in to access definitions');\n\t\t}\n\n\t\tconst ctx: RequestContext = sharedAccess?.ctx ?? locals.ctx!;\n\n\t\tconst record = await meta.get(ctx, guid);\n\t\tif (!record) throw new Error(`Definition '${guid}' not found`);\n\n\t\t// User-auth path needs the canSolve gate; token-auth was already gated.\n\t\tif (!sharedAccess) await asHttpError(() => requireCanSolve(scoped(locals), record.projectId));\n\n\t\t// Draft channel and explicit-version picks require edit permission on top\n\t\t// of solve.\n\t\tif (channel === 'draft' || explicitVersionId) {\n\t\t\tconst { requireEditableDefinition } = await import('#lib/server/access.server.js');\n\t\t\tawait asHttpError(() => requireEditableDefinition(scoped(locals), guid));\n\t\t}\n\n\t\t// Owning org's logo, for viewer branding, read beside the definition load. Same\n\t\t// `ctx` already authorized to load this definition (user session or share-token\n\t\t// ctx, which carries actingOrgId). Best-effort: a missing project/org or read\n\t\t// failure just yields no logo — branding is non-essential and must never break a solve.\n\t\tconst [loaded, orgLogoUrl] = await Promise.all([\n\t\t\tloadDefinitionForRender(ctx, record, channel, explicitVersionId),\n\t\t\tresolveOrgLogo(ctx, record.projectId, locals.log)\n\t\t]);\n\n\t\t// Warm already: loading the definition read its inputs through this client.\n\t\tconst { limits } = await getClient(loaded.computeServer, { definitionGuid: guid });\n\n\t\treturn {\n\t\t\tschema: loaded.schema,\n\t\t\tghDefinition: clientDefUrl,\n\t\t\tcurrentDefinition: guid,\n\t\t\tserverLabel: loaded.computeServer.label,\n\t\t\torgLogoUrl,\n\t\t\tchannel,\n\t\t\t// When rendering an explicit version, forward its id (so solve calls\n\t\t\t// target the same version) and number (for the preview badge).\n\t\t\tversionId: explicitVersionId,\n\t\t\tversionNumber: loaded.version.versionNumber,\n\t\t\t// Forward to the client so /api/compute/solve calls can include it.\n\t\t\t// Null when the request was user-authenticated (session cookie carries auth).\n\t\t\tshareToken,\n\t\t\t// The deadline this definition's compute server sets, so the browser's\n\t\t\t// AbortController doesn't stop a solve the server would still finish.\n\t\t\tsolveDeadlineMs: limits.solveDeadlineMs\n\t\t};\n\t} catch (err) {\n\t\t// Let HttpError (from error() calls) bubble up.\n\t\tif (err instanceof Error && 'status' in err) throw err;\n\n\t\t// Translate classified load errors to the same HTTP statuses the route\n\t\t// used pre-extraction:\n\t\t// missing-config | connect → 503 (operator action needed)\n\t\t// schema → 500 (compute responded but IO/schema failed)\n\t\t// data → 400 (definition references missing version/blob)\n\t\tif (err instanceof DefinitionLoadError) {\n\t\t\tif (err.kind === 'missing-config') {\n\t\t\t\tthrow error(\n\t\t\t\t\t503,\n\t\t\t\t\t'No compute server configured. Ask an admin to add one in /admin/compute.'\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (err.kind === 'connect') {\n\t\t\t\tlocals.log.error('Compute server connection failed', {\n\t\t\t\t\tcomponent: 'PageLoad',\n\t\t\t\t\tguid,\n\t\t\t\t\terr: renderThrown(err)\n\t\t\t\t});\n\t\t\t\tthrow error(503, err.message);\n\t\t\t}\n\t\t\tif (err.kind === 'schema') {\n\t\t\t\tlocals.log.error('Definition loading failed', {\n\t\t\t\t\tcomponent: 'PageLoad',\n\t\t\t\t\tguid,\n\t\t\t\t\terr: renderThrown(err)\n\t\t\t\t});\n\n\t\t\t\tif (process.env.NODE_ENV === 'development') {\n\t\t\t\t\tconst hint = `\\n\\nTroubleshooting:\\n1. Check /api/health/compute to diagnose server connectivity\\n2. Check the browser console for more details`;\n\t\t\t\t\tthrow error(500, `Failed to load definition from ${clientDefUrl}: ${err.message}${hint}`);\n\t\t\t\t}\n\t\t\t\tthrow error(500, `Failed to load definition: ${err.message}`);\n\t\t\t}\n\t\t\t// kind === 'data' falls through to the 400 wrap below.\n\t\t}\n\n\t\tif (err instanceof Error) {\n\t\t\tlocals.log.warn('Failed to load definition', {\n\t\t\t\tcomponent: 'App Load',\n\t\t\t\tguid,\n\t\t\t\terr: renderThrown(err)\n\t\t\t});\n\t\t\tthrow error(400, `Failed to load definition '${guid}': ${err.message}`);\n\t\t}\n\t\tthrow err;\n\t}\n}) satisfies PageServerLoad;\n\nasync function sessionCanSolve(locals: App.Locals, guid: string): Promise<boolean> {\n\tif (!locals.ctx || !locals.user) return false;\n\tconst record = await getDefinitionMeta().get(locals.ctx, guid);\n\tif (!record) return false;\n\ttry {\n\t\tawait requireCanSolve(scoped(locals), record.projectId);\n\t\treturn true;\n\t} catch (err) {\n\t\tif (isApiError(err)) return false;\n\t\tthrow err;\n\t}\n}\n\n/**\n * Resolve the owning org's logo URL for viewer branding. definition → project →\n * org. Best-effort and self-contained: any miss or read error returns null so a\n * branding lookup can never fail the render path.\n */\nasync function resolveOrgLogo(\n\tctx: RequestContext,\n\tprojectId: string,\n\tlog: ILogger\n): Promise<string | null> {\n\ttry {\n\t\tconst project = await getProjectProvider().getProject(ctx, projectId);\n\t\tif (!project?.orgId) return null;\n\t\tconst org = await getOrganizationProvider().getOrg(ctx, project.orgId);\n\t\treturn org?.assets?.logo ?? null;\n\t} catch (err) {\n\t\tlog.warn('Failed to resolve org logo', {\n\t\t\tcomponent: 'App Load',\n\t\t\tprojectId,\n\t\t\terr: renderThrown(err)\n\t\t});\n\t\treturn null;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AA0CA,IAAa,sBAAb,cAAyC,MAAM;CAE7B;CAEA;CAHjB,YACC,MACA,SACA,OACC;EACD,MAAM,OAAO;EAJG,KAAA,OAAA;EAEA,KAAA,QAAA;EAGhB,KAAK,OAAO;CACb;AACD;;;;;;AA2DA,SAAgB,uBAAuB,MAA8C;CACpF,MAAM,EACL,SACA,aACA,UACA,eACA,WACA,cAAc,wBACd,eAAe,OACf,QACA,SAAS,IAAI,WAAW,MACrB;CAEJ,OAAO,eAAe,wBAAwB,KAAK,QAAQ,SAAS,mBAAmB,SAAS;EAC/F,MAAM,YACL,sBAAsB,YAAY,UAAU,OAAO,iBAAiB,OAAO;EAC5E,IAAI,CAAC,WACJ,MAAM,IAAI,oBACT,QACA,eAAe,OAAO,KAAK,WAAW,QAAQ,SAC/C;EAID,MAAM,iBAAiB,YAA0C;GAChE,MAAM,UAAU,MAAM,SAAS,WAAW,KAAK,OAAO,SAAS;GAC/D,IAAI;IACH,OAAO,MAAM,cAAc,KAAK,SAAS,SAAS,MAAM,EACvD,eAAe,OAAO,mBAAmB,KAC1C,CAAC;GACF,SAAS,KAAK;IACb,MAAM,IAAI,oBACT,kBACA,oDACA,GACD;GACD;EACD,EAAA,CAAG;EACH,cAAc,YAAY,CAAC,CAAC;EAE5B,MAAM,UAAU,MAAM,YAAY,WAAW,KAAK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zB,IAAI;EACH,MAAM,UAAU,MAAM,mBAAmB,CAAC,CAAC,WAAW,KAAK,SAAS;EACpE,IAAI,CAAC,SAAS,OAAO,OAAO;EAE5B,QAAO,MADW,wBAAwB,CAAC,CAAC,OAAO,KAAK,QAAQ,KAAK,EAAA,EACzD,QAAQ,QAAQ;CAC7B,SAAS,KAAK;EACb,IAAI,KAAK,8BAA8B;GACtC,WAAW;GACX;GACA,KAAK,aAAa,GAAG;EACtB,CAAC;EACD,OAAO;CACR;AACD"}
|
|
1
|
+
{"version":3,"file":"_page.server.ts.js","names":[],"sources":["../../../../../../../server/src/definitions/load-for-render.ts","../../../../../../src/lib/server/definitions/loadForRender.server.ts","../../../../../../src/routes/library/[guid]/+page.server.ts"],"sourcesContent":["// Given a definition record, produces everything the client needs to render its\n// form and solve it.\n//\n// Access gating is deliberately NOT done here — the calling route decides\n// whether `ctx` may load this definition, since gates differ across routes\n// (project membership, segment ownership, share-token, admin override).\n//\n// Everything stateful is injected, so any app on the engine can wire its own\n// composition root.\n\nimport type { GrasshopperClient } from '@selvajs/compute/grasshopper';\nimport { UI_SCHEMA_VERSION, type UISchema } from '@selvajs/schemas';\nimport type {\n\tComputeServerConfig,\n\tDefinitionRecord,\n\tDefinitionVersion,\n\tIDefinitionStore,\n\tIProjectStore,\n\tIStorageProvider,\n\tRequestContext\n} from '@selvajs/platform';\nimport { NoopLogger, type ILogger } from '@selvajs/platform';\nimport { fetchSchemaFromCompute } from './schema-extraction.js';\n\nexport type DefinitionChannel = 'live' | 'draft';\n\nexport interface LoadedDefinition {\n\tversion: DefinitionVersion;\n\tdefinitionSource: Uint8Array;\n\tcomputeServer: ComputeServerConfig;\n\tschema: UISchema;\n}\n\n/**\n * Classified failure modes so callers can map to appropriate HTTP status:\n * - 'data': record references a version/blob that isn't there. (400)\n * - 'missing-config': no compute server resolvable for this org/definition. (503)\n * - 'connect': compute server is configured but unreachable. (503)\n * - 'schema': compute responded but IO/schema phase failed. (500)\n */\nexport type DefinitionLoadErrorKind = 'data' | 'missing-config' | 'connect' | 'schema';\n\nexport class DefinitionLoadError extends Error {\n\tconstructor(\n\t\tpublic readonly kind: DefinitionLoadErrorKind,\n\t\tmessage: string,\n\t\tpublic readonly cause?: unknown\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'DefinitionLoadError';\n\t}\n}\n\nexport interface DefinitionLoaderDeps {\n\tstorage: Pick<IStorageProvider, 'get'>;\n\tdefinitions: Pick<IDefinitionStore, 'getVersion' | 'setVersionSchema'>;\n\tprojects: Pick<IProjectStore, 'getProject'>;\n\t/** Resolution order: definition pin → org default override → global default. */\n\tresolveServer: (\n\t\tctx: RequestContext,\n\t\torgId: string | null,\n\t\topts: { definitionPin: string | null }\n\t) => Promise<ComputeServerConfig>;\n\t/** Shared warm-client cache, keyed by server id. */\n\tgetClient: (server: ComputeServerConfig) => Promise<{ client: GrasshopperClient }>;\n\t/** Schema extraction; defaults to `fetchSchemaFromCompute`. Injectable for tests. */\n\tfetchSchema?: (bytes: Uint8Array, server: ComputeServerConfig) => Promise<UISchema>;\n\t/**\n\t * When set, an unhealthy IO result also dumps the raw /io wire shape, making\n\t * casing/serialization mismatches visible.\n\t */\n\tcomputeDebug?: boolean;\n\t/** Legacy diagnostic sink. When set it takes the warnings below instead of `logger`. */\n\tonWarn?: (message: string, detail?: string) => void;\n\t/**\n\t * Defaults to `NoopLogger`, so a consumer that wires nothing gets silence\n\t * rather than unsolicited stdout.\n\t */\n\tlogger?: ILogger;\n}\n\nexport interface DefinitionLoadOptions {\n\t/**\n\t * For callers that read only schema STRUCTURE (input ids, `source.key`,\n\t * widget types — anything persisted at upload). A fresh cached schema then\n\t * returns without touching compute, whose multi-second connect otherwise\n\t * dominates a page resolving several definitions.\n\t *\n\t * Leave unset (the default) for anything that RENDERS a form — without\n\t * compute defaults the form shows the wrong initial values.\n\t */\n\tskipComputeDefaults?: boolean;\n}\n\nexport type DefinitionLoader = (\n\tctx: RequestContext,\n\trecord: DefinitionRecord,\n\tchannel: DefinitionChannel,\n\texplicitVersionId?: string | null,\n\toptions?: DefinitionLoadOptions\n) => Promise<LoadedDefinition>;\n\n/**\n * The returned loader resolves the `channel` pointer (live/draft) by default.\n * `explicitVersionId` renders an arbitrary historical version instead — the\n * caller MUST gate that behind edit permission, as with the draft channel.\n */\nexport function createDefinitionLoader(deps: DefinitionLoaderDeps): DefinitionLoader {\n\tconst {\n\t\tstorage,\n\t\tdefinitions,\n\t\tprojects,\n\t\tresolveServer,\n\t\tgetClient,\n\t\tfetchSchema = fetchSchemaFromCompute,\n\t\tcomputeDebug = false,\n\t\tonWarn,\n\t\tlogger = new NoopLogger()\n\t} = deps;\n\n\treturn async function loadDefinitionForRender(ctx, record, channel, explicitVersionId, options) {\n\t\tconst versionId =\n\t\t\texplicitVersionId ?? (channel === 'draft' ? record.draftVersionId : record.liveVersionId);\n\t\tif (!versionId)\n\t\t\tthrow new DefinitionLoadError(\n\t\t\t\t'data',\n\t\t\t\t`Definition '${record.guid}' has no ${channel} version`\n\t\t\t);\n\n\t\t// The server needs only the record, so it resolves while the version and file are read.\n\t\t// It is awaited after them, so a definition missing its data still fails as 'data'.\n\t\tconst pendingServer = (async (): Promise<ComputeServerConfig> => {\n\t\t\tconst project = await projects.getProject(ctx, record.projectId);\n\t\t\ttry {\n\t\t\t\treturn await resolveServer(ctx, project?.orgId ?? null, {\n\t\t\t\t\tdefinitionPin: record.computeServerId ?? null\n\t\t\t\t});\n\t\t\t} catch (err) {\n\t\t\t\tthrow new DefinitionLoadError(\n\t\t\t\t\t'missing-config',\n\t\t\t\t\t'No compute server configured for this definition',\n\t\t\t\t\terr\n\t\t\t\t);\n\t\t\t}\n\t\t})();\n\t\tpendingServer.catch(() => {});\n\n\t\tconst version = await definitions.getVersion(ctx, versionId);\n\t\tif (!version) throw new DefinitionLoadError('data', `version missing for '${record.guid}'`);\n\t\t// An explicitly requested version must belong to this definition.\n\t\tif (version.definitionId !== record.guid)\n\t\t\tthrow new DefinitionLoadError('data', `version does not belong to '${record.guid}'`);\n\n\t\tconst definitionSource = await storage.get(version.fileKey);\n\t\tif (!definitionSource)\n\t\t\tthrow new DefinitionLoadError(\n\t\t\t\t'data',\n\t\t\t\t`Definition file for '${record.guid}' not found on disk`\n\t\t\t);\n\n\t\tconst computeServer = await pendingServer;\n\n\t\t// Returning before `getClient` is the point — the connect is the cost, not\n\t\t// the `getIO` it carries. A missing or stale-format cache falls through to\n\t\t// the full path below, so the result is always a valid schema.\n\t\tif (options?.skipComputeDefaults) {\n\t\t\tconst cachedSchema = version.schema as UISchema | undefined;\n\t\t\tif (cachedSchema && isUsableCachedSchema(cachedSchema)) {\n\t\t\t\treturn { version, definitionSource, computeServer, schema: cachedSchema };\n\t\t\t}\n\t\t}\n\n\t\t// Only the client is used here (getIO); the entry's solve scheduler rides\n\t\t// along unused.\n\t\tlet client: GrasshopperClient;\n\t\ttry {\n\t\t\tclient = (await getClient(computeServer)).client;\n\t\t} catch (err) {\n\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\tthrow new DefinitionLoadError(\n\t\t\t\t'connect',\n\t\t\t\t`Failed to connect to Rhino Compute server: ${message}`,\n\t\t\t\terr\n\t\t\t);\n\t\t}\n\n\t\ttry {\n\t\t\t// The stored schema is a disposable cache, used ONLY when its format\n\t\t\t// version matches the app's. On a mismatch (or a pre-caching row with no\n\t\t\t// schema) re-extract from compute, whose C# SchemaMigrator emits the\n\t\t\t// current format — the web side never migrates schemas itself. `getIO`\n\t\t\t// runs either way, to merge compute default values in.\n\t\t\tconst cachedSchema = version.schema as UISchema | undefined;\n\t\t\tconst freshCache = cachedSchema && isUsableCachedSchema(cachedSchema) ? cachedSchema : null;\n\t\t\tconst [definition, fetchedSchema] = await Promise.all([\n\t\t\t\tclient.getIO(definitionSource),\n\t\t\t\tfreshCache ? Promise.resolve(freshCache) : fetchSchema(definitionSource, computeServer)\n\t\t\t]);\n\n\t\t\t// Best-effort — a viewer context may lack write access, and the next\n\t\t\t// editor render or the solve-time backfill will land it. Guarded on the\n\t\t\t// current version because persisting an older format (compute plugin\n\t\t\t// behind the app) would just go stale again next render.\n\t\t\tif (!freshCache && fetchedSchema.schemaVersion === UI_SCHEMA_VERSION) {\n\t\t\t\tdefinitions.setVersionSchema(ctx, version.id, fetchedSchema).catch((err) => {\n\t\t\t\t\tif (onWarn) {\n\t\t\t\t\t\tonWarn(\n\t\t\t\t\t\t\t`[loadForRender] schema cache refresh failed for version ${version.id}: ` +\n\t\t\t\t\t\t\t\t`${err instanceof Error ? err.message : String(err)}`\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlogger.warn('Schema cache refresh failed', {\n\t\t\t\t\t\tcomponent: 'loadForRender',\n\t\t\t\t\t\tversionId: version.id,\n\t\t\t\t\t\terr: err instanceof Error ? (err.stack ?? err.message) : String(err)\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!definition) {\n\t\t\t\tthrow new Error(`Failed to get definition IO — server returned undefined`);\n\t\t\t}\n\n\t\t\t// Zero inputs or reported parse/load problems mean a definition that will\n\t\t\t// render wrong without saying why: an empty ValueList whose backing GH\n\t\t\t// component didn't resolve (\"Missing Definition Objects\"), or a PascalCase\n\t\t\t// /io response the parser silently dropped to []. Warning is always on —\n\t\t\t// it only fires on the unhappy path — while the raw wire dump costs an\n\t\t\t// extra round-trip and stays behind `computeDebug`.\n\t\t\tconst ioParseErrors = (definition as { parseErrors?: unknown[] }).parseErrors ?? [];\n\t\t\tconst ioLoadErrors = (definition as { loadErrors?: unknown[] }).loadErrors ?? [];\n\t\t\tconst ioLooksBroken =\n\t\t\t\tdefinition.inputs.length === 0 || ioParseErrors.length > 0 || ioLoadErrors.length > 0;\n\t\t\tif (ioLooksBroken) {\n\t\t\t\tconst health = {\n\t\t\t\t\tinputCount: definition.inputs.length,\n\t\t\t\t\toutputCount: definition.outputs?.length,\n\t\t\t\t\tparseErrors: ioParseErrors,\n\t\t\t\t\tloadErrors: ioLoadErrors,\n\t\t\t\t\tloadWarnings: (definition as { loadWarnings?: unknown }).loadWarnings\n\t\t\t\t};\n\t\t\t\tif (onWarn) {\n\t\t\t\t\tonWarn(`[loadForRender] IO health for '${record.guid}':`, JSON.stringify(health));\n\t\t\t\t} else {\n\t\t\t\t\tlogger.warn('Definition IO looks unhealthy', {\n\t\t\t\t\t\tcomponent: 'loadForRender',\n\t\t\t\t\t\tdefinitionGuid: record.guid,\n\t\t\t\t\t\t...health\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (computeDebug) {\n\t\t\t\t\tconst rawIO = await client\n\t\t\t\t\t\t.getRawIO(definitionSource)\n\t\t\t\t\t\t.catch((e) => ({ error: String(e) }));\n\t\t\t\t\tconst rendered = JSON.stringify(rawIO).slice(0, 3000);\n\t\t\t\t\tif (onWarn) onWarn('[loadForRender] raw /io:', rendered);\n\t\t\t\t\telse\n\t\t\t\t\t\tlogger.debug('Raw /io wire shape', {\n\t\t\t\t\t\t\tcomponent: 'loadForRender',\n\t\t\t\t\t\t\tdefinitionGuid: record.guid,\n\t\t\t\t\t\t\trawIO: rendered\n\t\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tversion,\n\t\t\t\tdefinitionSource,\n\t\t\t\tcomputeServer,\n\t\t\t\tschema: mergeComputeDefaults(fetchedSchema, definition.inputs)\n\t\t\t};\n\t\t} catch (err) {\n\t\t\tif (err instanceof DefinitionLoadError) throw err;\n\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\tthrow new DefinitionLoadError('schema', message, err);\n\t\t}\n\t};\n}\n\n/**\n * A cached schema is usable only if it is BOTH the current format version and\n * structurally sound. The version check alone is not enough: a compute server\n * that serialized the schema with the wrong Newtonsoft emits PascalCase keys, so\n * `schemaVersion` reads as undefined while `SchemaVersion` holds the value —\n * and a row cached during that window would otherwise be served forever, long\n * after the server was fixed. See `assertCamelCaseSchema`.\n */\nexport function isUsableCachedSchema(schema: UISchema): boolean {\n\treturn schema.schemaVersion === UI_SCHEMA_VERSION && Array.isArray(schema.inputs);\n}\n\n// Colors come back from Compute as \"r,g,b\" or \"a,r,g,b\" strings — converted to\n// hex here so the color picker can consume them directly.\nfunction mergeComputeDefaults(\n\tschema: UISchema,\n\tcomputeInputs: Array<{ id?: string; paramType?: string; default?: unknown }>\n): UISchema {\n\tif (!Array.isArray(schema.inputs)) {\n\t\tthrow new DefinitionLoadError(\n\t\t\t'schema',\n\t\t\t`Schema has no 'inputs' array (keys: ${Object.keys(schema as object)\n\t\t\t\t.slice(0, 12)\n\t\t\t\t.join(', ')}). A PascalCase shape here means compute serialized it with the wrong ` +\n\t\t\t\t`Newtonsoft — see assertCamelCaseSchema.`\n\t\t);\n\t}\n\n\tconst byParamId = new Map(computeInputs.map((input) => [input.id, input]));\n\n\treturn {\n\t\t...schema,\n\t\tinputs: schema.inputs.map((schemaInput) => {\n\t\t\tconst computeInput = byParamId.get(schemaInput.id);\n\n\t\t\tif (computeInput?.paramType === 'Color' && computeInput.default !== undefined) {\n\t\t\t\tconst toHex = (value: number) => value.toString(16).padStart(2, '0');\n\t\t\t\tconst parts = String(computeInput.default)\n\t\t\t\t\t.split(',')\n\t\t\t\t\t.map((s) => parseInt(s.trim(), 10));\n\n\t\t\t\tif (parts.length === 3) {\n\t\t\t\t\tcomputeInput.default = `#${toHex(parts[0])}${toHex(parts[1])}${toHex(parts[2])}`;\n\t\t\t\t} else if (parts.length === 4) {\n\t\t\t\t\tcomputeInput.default = `#${toHex(parts[1])}${toHex(parts[2])}${toHex(parts[3])}`;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (computeInput && computeInput.default !== undefined) {\n\t\t\t\treturn { ...schemaInput, default: computeInput.default };\n\t\t\t}\n\t\t\treturn schemaInput;\n\t\t})\n\t};\n}\n","// `@selvajs/server/definitions` owns the loading pipeline (version resolution,\n// blob fetch, schema staleness check, default merging); this wires in the\n// app's providers, compute-server resolution, and warm-client cache. Access\n// gating stays with the calling route.\n\nimport {\n\tcreateDefinitionLoader,\n\tDefinitionLoadError,\n\ttype DefinitionChannel,\n\ttype DefinitionLoadErrorKind,\n\ttype LoadedDefinition\n} from '@selvajs/server/definitions';\nimport type { DefinitionRecord, RequestContext } from '@selvajs/platform';\nimport {\n\tgetStorageProvider,\n\tgetDefinitionMeta,\n\tgetProjectProvider,\n\tgetComputeServerConfigStore\n} from '../providers.server';\nimport { serverResolver } from '../compute/serverResolver.server';\nimport { getClient, COMPUTE_DEBUG } from '../compute/engine.server';\n\nexport { DefinitionLoadError };\nexport type { DefinitionChannel, DefinitionLoadErrorKind, LoadedDefinition };\n\nexport async function loadDefinitionForRender(\n\tctx: RequestContext,\n\trecord: DefinitionRecord,\n\tchannel: DefinitionChannel,\n\texplicitVersionId?: string | null\n): Promise<LoadedDefinition> {\n\tconst load = createDefinitionLoader({\n\t\tstorage: getStorageProvider(),\n\t\tdefinitions: getDefinitionMeta(),\n\t\tprojects: getProjectProvider(),\n\t\tresolveServer: (ctx, orgId, opts) =>\n\t\t\tserverResolver.resolve(ctx, orgId, getComputeServerConfigStore(), opts),\n\t\tgetClient,\n\t\tcomputeDebug: COMPUTE_DEBUG\n\t});\n\treturn load(ctx, record, channel, explicitVersionId);\n}\n","import type { PageServerLoad } from './$types';\nimport { error } from '@sveltejs/kit';\nimport type { ILogger, RequestContext } from '@selvajs/platform';\nimport { renderThrown } from '@selvajs/server/logging';\nimport {\n\tgetDefinitionMeta,\n\tgetProjectProvider,\n\tgetOrganizationProvider\n} from '#lib/server/providers.server.js';\nimport { isApiError } from '@selvajs/server/api';\nimport { asHttpError, requireCanSolve, scoped } from '#lib/server/access.server.js';\nimport { readShareToken, tryResolveShareToken } from '#lib/server/shareLinks/resolve.server.js';\nimport { getClient } from '#lib/server/compute/engine.server.js';\nimport {\n\tloadDefinitionForRender,\n\tDefinitionLoadError\n} from '#lib/server/definitions/loadForRender.server.js';\n\nexport const load = (async ({ params, locals, request, url }) => {\n\tconst meta = getDefinitionMeta();\n\n\tconst guid = params.guid;\n\tconst channel = url.searchParams.get('channel') === 'draft' ? 'draft' : 'live';\n\t// Explicit version pick (versioning tab \"Run\"): render an arbitrary version,\n\t// not just the live/draft pointer. Editor-only, never share-token accessible.\n\tconst explicitVersionId = url.searchParams.get('version');\n\tconst clientDefUrl = `local:${guid}`;\n\t// `shareToken` is forwarded to the page so the client can include it on\n\t// subsequent /api/compute/solve calls. null = user-authenticated session.\n\tlet shareToken: string | null = null;\n\n\ttry {\n\t\t// Draft channel and explicit-version picks are editor-only — share tokens\n\t\t// are always live channel on the pointer. A signed-in viewer who can solve\n\t\t// anyway ignores the token: a share-token solve gets no live events and\n\t\t// counts against the link's solve cap.\n\t\tconst sharedAccess =\n\t\t\tchannel === 'live' &&\n\t\t\t!explicitVersionId &&\n\t\t\treadShareToken(request, url) !== null &&\n\t\t\t!(await sessionCanSolve(locals, guid))\n\t\t\t\t? await tryResolveShareToken(request, url, guid, 'live', { requireSolve: false })\n\t\t\t\t: null;\n\t\tif (sharedAccess) {\n\t\t\tshareToken = url.searchParams.get('token');\n\t\t} else if (!locals.ctx || !locals.user) {\n\t\t\tthrow error(401, 'Unauthorized: You must be logged in to access definitions');\n\t\t}\n\n\t\tconst ctx: RequestContext = sharedAccess?.ctx ?? locals.ctx!;\n\n\t\tconst record = await meta.get(ctx, guid);\n\t\tif (!record) throw new Error(`Definition '${guid}' not found`);\n\n\t\t// User-auth path needs the canSolve gate; token-auth was already gated.\n\t\tif (!sharedAccess) await asHttpError(() => requireCanSolve(scoped(locals), record.projectId));\n\n\t\t// Draft channel and explicit-version picks require edit permission on top\n\t\t// of solve.\n\t\tif (channel === 'draft' || explicitVersionId) {\n\t\t\tconst { requireEditableDefinition } = await import('#lib/server/access.server.js');\n\t\t\tawait asHttpError(() => requireEditableDefinition(scoped(locals), guid));\n\t\t}\n\n\t\t// Owning org's logo, for viewer branding, read beside the definition load. Same\n\t\t// `ctx` already authorized to load this definition (user session or share-token\n\t\t// ctx, which carries actingOrgId). Best-effort: a missing project/org or read\n\t\t// failure just yields no logo — branding is non-essential and must never break a solve.\n\t\tconst [loaded, orgLogoUrl] = await Promise.all([\n\t\t\tloadDefinitionForRender(ctx, record, channel, explicitVersionId),\n\t\t\tresolveOrgLogo(ctx, record.projectId, locals.log)\n\t\t]);\n\n\t\t// Warm already: loading the definition read its inputs through this client.\n\t\tconst { limits } = await getClient(loaded.computeServer);\n\n\t\treturn {\n\t\t\tschema: loaded.schema,\n\t\t\tghDefinition: clientDefUrl,\n\t\t\tcurrentDefinition: guid,\n\t\t\tserverLabel: loaded.computeServer.label,\n\t\t\torgLogoUrl,\n\t\t\tchannel,\n\t\t\t// When rendering an explicit version, forward its id (so solve calls\n\t\t\t// target the same version) and number (for the preview badge).\n\t\t\tversionId: explicitVersionId,\n\t\t\tversionNumber: loaded.version.versionNumber,\n\t\t\t// Forward to the client so /api/compute/solve calls can include it.\n\t\t\t// Null when the request was user-authenticated (session cookie carries auth).\n\t\t\tshareToken,\n\t\t\t// The deadline this definition's compute server sets, so the browser's\n\t\t\t// AbortController doesn't stop a solve the server would still finish.\n\t\t\tsolveDeadlineMs: limits.solveDeadlineMs\n\t\t};\n\t} catch (err) {\n\t\t// Let HttpError (from error() calls) bubble up.\n\t\tif (err instanceof Error && 'status' in err) throw err;\n\n\t\t// Translate classified load errors to the same HTTP statuses the route\n\t\t// used pre-extraction:\n\t\t// missing-config | connect → 503 (operator action needed)\n\t\t// schema → 500 (compute responded but IO/schema failed)\n\t\t// data → 400 (definition references missing version/blob)\n\t\tif (err instanceof DefinitionLoadError) {\n\t\t\tif (err.kind === 'missing-config') {\n\t\t\t\tthrow error(\n\t\t\t\t\t503,\n\t\t\t\t\t'No compute server configured. Ask an admin to add one in /admin/compute.'\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (err.kind === 'connect') {\n\t\t\t\tlocals.log.error('Compute server connection failed', {\n\t\t\t\t\tcomponent: 'PageLoad',\n\t\t\t\t\tguid,\n\t\t\t\t\terr: renderThrown(err)\n\t\t\t\t});\n\t\t\t\tthrow error(503, err.message);\n\t\t\t}\n\t\t\tif (err.kind === 'schema') {\n\t\t\t\tlocals.log.error('Definition loading failed', {\n\t\t\t\t\tcomponent: 'PageLoad',\n\t\t\t\t\tguid,\n\t\t\t\t\terr: renderThrown(err)\n\t\t\t\t});\n\n\t\t\t\tif (process.env.NODE_ENV === 'development') {\n\t\t\t\t\tconst hint = `\\n\\nTroubleshooting:\\n1. Check /api/health/compute to diagnose server connectivity\\n2. Check the browser console for more details`;\n\t\t\t\t\tthrow error(500, `Failed to load definition from ${clientDefUrl}: ${err.message}${hint}`);\n\t\t\t\t}\n\t\t\t\tthrow error(500, `Failed to load definition: ${err.message}`);\n\t\t\t}\n\t\t\t// kind === 'data' falls through to the 400 wrap below.\n\t\t}\n\n\t\tif (err instanceof Error) {\n\t\t\tlocals.log.warn('Failed to load definition', {\n\t\t\t\tcomponent: 'App Load',\n\t\t\t\tguid,\n\t\t\t\terr: renderThrown(err)\n\t\t\t});\n\t\t\tthrow error(400, `Failed to load definition '${guid}': ${err.message}`);\n\t\t}\n\t\tthrow err;\n\t}\n}) satisfies PageServerLoad;\n\nasync function sessionCanSolve(locals: App.Locals, guid: string): Promise<boolean> {\n\tif (!locals.ctx || !locals.user) return false;\n\tconst record = await getDefinitionMeta().get(locals.ctx, guid);\n\tif (!record) return false;\n\ttry {\n\t\tawait requireCanSolve(scoped(locals), record.projectId);\n\t\treturn true;\n\t} catch (err) {\n\t\tif (isApiError(err)) return false;\n\t\tthrow err;\n\t}\n}\n\n/**\n * Resolve the owning org's logo URL for viewer branding. definition → project →\n * org. Best-effort and self-contained: any miss or read error returns null so a\n * branding lookup can never fail the render path.\n */\nasync function resolveOrgLogo(\n\tctx: RequestContext,\n\tprojectId: string,\n\tlog: ILogger\n): Promise<string | null> {\n\ttry {\n\t\tconst project = await getProjectProvider().getProject(ctx, projectId);\n\t\tif (!project?.orgId) return null;\n\t\tconst org = await getOrganizationProvider().getOrg(ctx, project.orgId);\n\t\treturn org?.assets?.logo ?? null;\n\t} catch (err) {\n\t\tlog.warn('Failed to resolve org logo', {\n\t\t\tcomponent: 'App Load',\n\t\t\tprojectId,\n\t\t\terr: renderThrown(err)\n\t\t});\n\t\treturn null;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AA0CA,IAAa,sBAAb,cAAyC,MAAM;CAE7B;CAEA;CAHjB,YACC,MACA,SACA,OACC;EACD,MAAM,OAAO;EAJG,KAAA,OAAA;EAEA,KAAA,QAAA;EAGhB,KAAK,OAAO;CACb;AACD;;;;;;AAwDA,SAAgB,uBAAuB,MAA8C;CACpF,MAAM,EACL,SACA,aACA,UACA,eACA,WACA,cAAc,wBACd,eAAe,OACf,QACA,SAAS,IAAI,WAAW,MACrB;CAEJ,OAAO,eAAe,wBAAwB,KAAK,QAAQ,SAAS,mBAAmB,SAAS;EAC/F,MAAM,YACL,sBAAsB,YAAY,UAAU,OAAO,iBAAiB,OAAO;EAC5E,IAAI,CAAC,WACJ,MAAM,IAAI,oBACT,QACA,eAAe,OAAO,KAAK,WAAW,QAAQ,SAC/C;EAID,MAAM,iBAAiB,YAA0C;GAChE,MAAM,UAAU,MAAM,SAAS,WAAW,KAAK,OAAO,SAAS;GAC/D,IAAI;IACH,OAAO,MAAM,cAAc,KAAK,SAAS,SAAS,MAAM,EACvD,eAAe,OAAO,mBAAmB,KAC1C,CAAC;GACF,SAAS,KAAK;IACb,MAAM,IAAI,oBACT,kBACA,oDACA,GACD;GACD;EACD,EAAA,CAAG;EACH,cAAc,YAAY,CAAC,CAAC;EAE5B,MAAM,UAAU,MAAM,YAAY,WAAW,KAAK,SAAS;EAC3D,IAAI,CAAC,SAAS,MAAM,IAAI,oBAAoB,QAAQ,wBAAwB,OAAO,KAAK,EAAE;EAE1F,IAAI,QAAQ,iBAAiB,OAAO,MACnC,MAAM,IAAI,oBAAoB,QAAQ,+BAA+B,OAAO,KAAK,EAAE;EAEpF,MAAM,mBAAmB,MAAM,QA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AAa,GAAG;EACtB,CAAC;EACD,OAAO;CACR;AACD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as decodeBase64ToBinary$1, g as subFolderSegments, p as downloadFileDataByRoot, r as GrasshopperResponseProcessor } from "../../../../chunks/grasshopper.js";
|
|
2
2
|
import { a as isDynamicValueListWidget, c as isTextWidget, i as isDropdownWidget, n as isCheckboxWidget, o as isFileWidget, r as isColorWidget, s as isNumberWidget } from "../../../../chunks/schema.js";
|
|
3
3
|
import { a as getLayoutItems, i as getInputItems, n as serverSourcedInputIds, r as getGroups, t as raceAbort } from "../../../../chunks/abort-Bfrdupaj.js";
|
|
4
|
-
import { i as outcomeFromComputeMessages, n as decodeOutcome, r as finalizeResult, t as decodeDiagnostic } from "../../../../chunks/outcome-
|
|
4
|
+
import { i as outcomeFromComputeMessages, n as decodeOutcome, r as finalizeResult, t as decodeDiagnostic } from "../../../../chunks/outcome-D28FgvFK.js";
|
|
5
5
|
import { Ft as run, Lt as escape_html, Ot as attr, _ as setContext, a as derived, d as spread_props, f as stringify, h as getContext, i as bind_props, kt as clsx$1, l as props_id, n as attr_style, o as element$1, ot as snapshot, p as html, r as attributes, s as ensure_array_like, t as attr_class } from "../../../../chunks/server3.js";
|
|
6
6
|
import { c as watch$1, s as Context, t as FOOTER_CONTEXT_KEY } from "../../../../chunks/footerContext.svelte.js";
|
|
7
7
|
import { r as on } from "../../../../chunks/events.js";
|
|
@@ -10150,6 +10150,104 @@ function getExternalInputs(schema) {
|
|
|
10150
10150
|
displayName: item.displayName ?? item.paramId
|
|
10151
10151
|
}));
|
|
10152
10152
|
}
|
|
10153
|
+
var NO_DEFERRED_FILES = { status: "none" };
|
|
10154
|
+
function hasFile(value) {
|
|
10155
|
+
return Array.isArray(value) ? value.length > 0 : value != null && value !== "";
|
|
10156
|
+
}
|
|
10157
|
+
function createDeferredFiles(solveFiles, onChange) {
|
|
10158
|
+
let state = NO_DEFERRED_FILES;
|
|
10159
|
+
let shown = null;
|
|
10160
|
+
let running = null;
|
|
10161
|
+
function set(next) {
|
|
10162
|
+
state = next;
|
|
10163
|
+
onChange();
|
|
10164
|
+
}
|
|
10165
|
+
function stop() {
|
|
10166
|
+
running?.controller.abort();
|
|
10167
|
+
running = null;
|
|
10168
|
+
}
|
|
10169
|
+
async function run(owner, ids, controller) {
|
|
10170
|
+
const startedAt = Date.now();
|
|
10171
|
+
set({
|
|
10172
|
+
status: "making",
|
|
10173
|
+
ids,
|
|
10174
|
+
startedAt
|
|
10175
|
+
});
|
|
10176
|
+
try {
|
|
10177
|
+
const result = await solveFiles(owner.values ?? {}, controller.signal);
|
|
10178
|
+
if (controller.signal.aborted || shown !== owner) return;
|
|
10179
|
+
if (result.aborted) return set({
|
|
10180
|
+
status: "waiting",
|
|
10181
|
+
ids
|
|
10182
|
+
});
|
|
10183
|
+
if (result.blocked) {
|
|
10184
|
+
const diagnostics = result.diagnostics ?? [];
|
|
10185
|
+
return set({
|
|
10186
|
+
status: "failed",
|
|
10187
|
+
ids,
|
|
10188
|
+
error: diagnostics.find((d) => d.level === "error")?.message ?? result.errors?.[0] ?? "The definition refused to make the files.",
|
|
10189
|
+
diagnostics
|
|
10190
|
+
});
|
|
10191
|
+
}
|
|
10192
|
+
const outputs = {};
|
|
10193
|
+
for (const id of ids) if (hasFile(result.outputs[id])) outputs[id] = result.outputs[id];
|
|
10194
|
+
set(Object.keys(outputs).length === 0 ? {
|
|
10195
|
+
status: "empty",
|
|
10196
|
+
ids
|
|
10197
|
+
} : {
|
|
10198
|
+
status: "ready",
|
|
10199
|
+
ids,
|
|
10200
|
+
outputs,
|
|
10201
|
+
durationMs: Date.now() - startedAt
|
|
10202
|
+
});
|
|
10203
|
+
} catch (err) {
|
|
10204
|
+
if (controller.signal.aborted || shown !== owner) return;
|
|
10205
|
+
set({
|
|
10206
|
+
status: "failed",
|
|
10207
|
+
ids,
|
|
10208
|
+
error: err instanceof Error ? err.message : String(err),
|
|
10209
|
+
diagnostics: []
|
|
10210
|
+
});
|
|
10211
|
+
} finally {
|
|
10212
|
+
if (running?.controller === controller) running = null;
|
|
10213
|
+
}
|
|
10214
|
+
}
|
|
10215
|
+
return {
|
|
10216
|
+
get state() {
|
|
10217
|
+
return state;
|
|
10218
|
+
},
|
|
10219
|
+
show(result) {
|
|
10220
|
+
if (result === shown) return;
|
|
10221
|
+
stop();
|
|
10222
|
+
shown = result;
|
|
10223
|
+
const ids = result?.deferred ?? [];
|
|
10224
|
+
state = ids.length > 0 && solveFiles ? {
|
|
10225
|
+
status: "waiting",
|
|
10226
|
+
ids
|
|
10227
|
+
} : NO_DEFERRED_FILES;
|
|
10228
|
+
},
|
|
10229
|
+
make() {
|
|
10230
|
+
if (running) return running.done;
|
|
10231
|
+
if (!shown || state.status !== "waiting" && state.status !== "failed") return Promise.resolve();
|
|
10232
|
+
const controller = new AbortController();
|
|
10233
|
+
const done = run(shown, state.ids, controller);
|
|
10234
|
+
running = {
|
|
10235
|
+
controller,
|
|
10236
|
+
done
|
|
10237
|
+
};
|
|
10238
|
+
return done;
|
|
10239
|
+
},
|
|
10240
|
+
cancel() {
|
|
10241
|
+
if (!running || state.status !== "making") return;
|
|
10242
|
+
const { ids } = state;
|
|
10243
|
+
stop();
|
|
10244
|
+
set({
|
|
10245
|
+
status: "waiting",
|
|
10246
|
+
ids
|
|
10247
|
+
});
|
|
10248
|
+
}
|
|
10249
|
+
};
|
|
10250
|
+
}
|
|
10153
10251
|
var EMPTY_LIVE_SOLVE = Object.freeze({
|
|
10154
10252
|
solveId: null,
|
|
10155
10253
|
running: false,
|
|
@@ -10411,6 +10509,9 @@ function createSolveSession(args) {
|
|
|
10411
10509
|
let disposed = false;
|
|
10412
10510
|
const listeners = /* @__PURE__ */ new Set();
|
|
10413
10511
|
const emit = () => notifyAll(listeners, void 0);
|
|
10512
|
+
const driverSolveFiles = args.driver.solveFiles;
|
|
10513
|
+
const files = createDeferredFiles(driverSolveFiles && ((values, signal) => driverSolveFiles.call(args.driver, values, signal)), emit);
|
|
10514
|
+
const showFiles = () => files.show(state.lastResult);
|
|
10414
10515
|
const settledListeners = /* @__PURE__ */ new Set();
|
|
10415
10516
|
let waiters = [];
|
|
10416
10517
|
const ABORTED = {
|
|
@@ -10486,7 +10587,8 @@ function createSolveSession(args) {
|
|
|
10486
10587
|
dropHeld();
|
|
10487
10588
|
lastSent = { ...pickInputValues(currentSchema, state.values) };
|
|
10488
10589
|
lastDispatched = lastSent;
|
|
10489
|
-
|
|
10590
|
+
files.cancel();
|
|
10591
|
+
args.driver.solve(lastSent, currentSchema.previewSolves === true ? { solveMode: "preview" } : void 0);
|
|
10490
10592
|
emit();
|
|
10491
10593
|
}
|
|
10492
10594
|
return {
|
|
@@ -10516,6 +10618,7 @@ function createSolveSession(args) {
|
|
|
10516
10618
|
if (!held) return;
|
|
10517
10619
|
state.heldResult = null;
|
|
10518
10620
|
commitSolveResult(state, held, editedSinceSent());
|
|
10621
|
+
showFiles();
|
|
10519
10622
|
land(() => settlementOf(held));
|
|
10520
10623
|
},
|
|
10521
10624
|
discard() {
|
|
@@ -10539,6 +10642,15 @@ function createSolveSession(args) {
|
|
|
10539
10642
|
get meshes() {
|
|
10540
10643
|
return state.meshes;
|
|
10541
10644
|
},
|
|
10645
|
+
get files() {
|
|
10646
|
+
return files.state;
|
|
10647
|
+
},
|
|
10648
|
+
makeFiles() {
|
|
10649
|
+
return disposed ? Promise.resolve() : files.make();
|
|
10650
|
+
},
|
|
10651
|
+
cancelFiles() {
|
|
10652
|
+
files.cancel();
|
|
10653
|
+
},
|
|
10542
10654
|
get lastResult() {
|
|
10543
10655
|
return state.lastResult;
|
|
10544
10656
|
},
|
|
@@ -10588,6 +10700,7 @@ function createSolveSession(args) {
|
|
|
10588
10700
|
lastDispatched = null;
|
|
10589
10701
|
args.driver.reset?.();
|
|
10590
10702
|
Object.assign(state, createInitialState(schema, scopeKey, readExternalValue));
|
|
10703
|
+
showFiles();
|
|
10591
10704
|
if (Object.keys(state.values).length > 0 && schema.instanceSolve !== false) dispatch();
|
|
10592
10705
|
else emit();
|
|
10593
10706
|
},
|
|
@@ -10600,6 +10713,7 @@ function createSolveSession(args) {
|
|
|
10600
10713
|
outputs: blankOutputs(currentSchema),
|
|
10601
10714
|
meshes: []
|
|
10602
10715
|
} : result, edited);
|
|
10716
|
+
showFiles();
|
|
10603
10717
|
if (args.driver.hasQueued) state.heldResult = null;
|
|
10604
10718
|
if (state.heldResult) return emit();
|
|
10605
10719
|
land(() => settlementOf(result));
|
|
@@ -10628,6 +10742,7 @@ function createSolveSession(args) {
|
|
|
10628
10742
|
disposed = true;
|
|
10629
10743
|
stopEvents?.();
|
|
10630
10744
|
listeners.clear();
|
|
10745
|
+
files.show(null);
|
|
10631
10746
|
settledListeners.clear();
|
|
10632
10747
|
args.driver.reset?.();
|
|
10633
10748
|
abandon();
|
|
@@ -10777,6 +10892,8 @@ function createSolveMemo(options = {}) {
|
|
|
10777
10892
|
function createRequestResponseDriver(onSolve, getReporter, options) {
|
|
10778
10893
|
const { meshPolicy, solveDeadlineMs, onChange, events } = options;
|
|
10779
10894
|
const memo = createSolveMemo({ meshPolicy });
|
|
10895
|
+
let memoMode = "full";
|
|
10896
|
+
let nextMode = "full";
|
|
10780
10897
|
let generation = 0;
|
|
10781
10898
|
function reportStopped(signal) {
|
|
10782
10899
|
console.debug("[Solve/driver] solve stopped (cancelled or timed out)");
|
|
@@ -10785,13 +10902,18 @@ function createRequestResponseDriver(onSolve, getReporter, options) {
|
|
|
10785
10902
|
}
|
|
10786
10903
|
const throttle = createAsyncThrottle(async (values, signal) => {
|
|
10787
10904
|
const startedIn = generation;
|
|
10905
|
+
const solveMode = nextMode;
|
|
10906
|
+
if (solveMode !== memoMode) {
|
|
10907
|
+
memo.clear();
|
|
10908
|
+
memoMode = solveMode;
|
|
10909
|
+
}
|
|
10788
10910
|
let result;
|
|
10789
10911
|
try {
|
|
10790
10912
|
const cached = memo.get(values);
|
|
10791
10913
|
if (cached !== void 0) result = cached;
|
|
10792
10914
|
else {
|
|
10793
10915
|
result = {
|
|
10794
|
-
...await raceAbort(onSolve(values, signal), signal),
|
|
10916
|
+
...await raceAbort(onSolve(values, signal, solveMode === "preview" ? { solveMode } : void 0), signal),
|
|
10795
10917
|
values
|
|
10796
10918
|
};
|
|
10797
10919
|
if (!result.aborted && startedIn === generation) memo.set(values, result);
|
|
@@ -10814,9 +10936,24 @@ function createRequestResponseDriver(onSolve, getReporter, options) {
|
|
|
10814
10936
|
events?.cancelCurrent?.();
|
|
10815
10937
|
}
|
|
10816
10938
|
return {
|
|
10817
|
-
solve(values) {
|
|
10939
|
+
solve(values, solveOptions) {
|
|
10940
|
+
nextMode = solveOptions?.solveMode ?? "full";
|
|
10818
10941
|
throttle.trigger(values);
|
|
10819
10942
|
},
|
|
10943
|
+
async solveFiles(values, signal) {
|
|
10944
|
+
const startedIn = generation;
|
|
10945
|
+
const bounded = AbortSignal.any([signal, AbortSignal.timeout(solveDeadlineMs)]);
|
|
10946
|
+
const result = await raceAbort(onSolve(values, bounded, {
|
|
10947
|
+
solveMode: "full",
|
|
10948
|
+
skipMeshes: true,
|
|
10949
|
+
liveEvents: false
|
|
10950
|
+
}), bounded);
|
|
10951
|
+
if (startedIn !== generation) return {
|
|
10952
|
+
outputs: {},
|
|
10953
|
+
aborted: true
|
|
10954
|
+
};
|
|
10955
|
+
return result;
|
|
10956
|
+
},
|
|
10820
10957
|
cancel,
|
|
10821
10958
|
get isSolving() {
|
|
10822
10959
|
return throttle.isRunning;
|
|
@@ -10970,7 +11107,7 @@ function createComputeFetchSolveFn(opts) {
|
|
|
10970
11107
|
opts.onRateLimited?.(retryAfterSeconds);
|
|
10971
11108
|
return rateLimitedError(retryAfterSeconds);
|
|
10972
11109
|
}
|
|
10973
|
-
return async (values, signal) => {
|
|
11110
|
+
return async (values, signal, call = {}) => {
|
|
10974
11111
|
const remainingMs = cooldownUntil - Date.now();
|
|
10975
11112
|
if (remainingMs > 0) throw rateLimited(remainingMs / 1e3);
|
|
10976
11113
|
const solveStart = performance.now();
|
|
@@ -10978,14 +11115,15 @@ function createComputeFetchSolveFn(opts) {
|
|
|
10978
11115
|
const outputs = opts.outputs();
|
|
10979
11116
|
const channel = opts.channel?.();
|
|
10980
11117
|
const versionId = opts.versionId?.();
|
|
10981
|
-
const streamId = opts.streamId?.();
|
|
11118
|
+
const streamId = call.liveEvents === false ? null : opts.streamId?.();
|
|
10982
11119
|
const bearerToken = opts.bearerToken?.();
|
|
10983
11120
|
const payload = JSON.stringify({
|
|
10984
11121
|
inputs,
|
|
10985
11122
|
values,
|
|
10986
11123
|
definitionUrl: opts.definitionUrl(),
|
|
10987
11124
|
...versionId ? { versionId } : channel === "draft" ? { channel: "draft" } : {},
|
|
10988
|
-
...streamId ? { streamId } : {}
|
|
11125
|
+
...streamId ? { streamId } : {},
|
|
11126
|
+
...call.solveMode === "preview" ? { mode: "preview" } : {}
|
|
10989
11127
|
});
|
|
10990
11128
|
let res;
|
|
10991
11129
|
try {
|
|
@@ -11054,7 +11192,7 @@ function createComputeFetchSolveFn(opts) {
|
|
|
11054
11192
|
const processor = new GrasshopperResponseProcessor(solved);
|
|
11055
11193
|
const outcome = decodeOutcome(solved.selva?.outcome) ?? outcomeFromComputeMessages(solved.errors ?? [], solved.warnings ?? []);
|
|
11056
11194
|
const rejected = outcome.blocked || outcome.aborted;
|
|
11057
|
-
const meshes = opts.meshes && !rejected ? await opts.meshes.extract(processor.response, {
|
|
11195
|
+
const meshes = opts.meshes && !rejected && !call.skipMeshes ? await opts.meshes.extract(processor.response, {
|
|
11058
11196
|
debug,
|
|
11059
11197
|
signal
|
|
11060
11198
|
}) : [];
|
|
@@ -14973,6 +15111,14 @@ function ImageOutput($$renderer, $$props) {
|
|
|
14973
15111
|
$$renderer.push(`<!--]-->`);
|
|
14974
15112
|
});
|
|
14975
15113
|
}
|
|
15114
|
+
// ../ui/src/lib/contexts/deferredFilesContext.svelte.ts
|
|
15115
|
+
var DEFERRED_FILES_CONTEXT_KEY = Symbol("deferred-files-context");
|
|
15116
|
+
function setDeferredFilesContext(ctx) {
|
|
15117
|
+
setContext(DEFERRED_FILES_CONTEXT_KEY, ctx);
|
|
15118
|
+
}
|
|
15119
|
+
function getDeferredFilesContext() {
|
|
15120
|
+
return getContext(DEFERRED_FILES_CONTEXT_KEY);
|
|
15121
|
+
}
|
|
14976
15122
|
// ../ui/src/lib/components/preview/OutputDisplay.svelte
|
|
14977
15123
|
function OutputDisplay($$renderer, $$props) {
|
|
14978
15124
|
$$renderer.component(($$renderer) => {
|
|
@@ -14997,7 +15143,19 @@ function OutputDisplay($$renderer, $$props) {
|
|
|
14997
15143
|
}
|
|
14998
15144
|
let downloading = false;
|
|
14999
15145
|
let downloadError = null;
|
|
15000
|
-
const
|
|
15146
|
+
const deferredContext = getDeferredFilesContext();
|
|
15147
|
+
const deferred = derived(() => {
|
|
15148
|
+
const files = deferredContext?.files;
|
|
15149
|
+
return files && files.status !== "none" && files.ids.includes(item.paramId) ? files : null;
|
|
15150
|
+
});
|
|
15151
|
+
const fileValue = derived(() => deferred()?.status === "ready" ? deferred().outputs[item.paramId] : value);
|
|
15152
|
+
let now = Date.now();
|
|
15153
|
+
const elapsed = derived(() => {
|
|
15154
|
+
if (deferred()?.status !== "making") return "";
|
|
15155
|
+
const s = Math.max(0, Math.floor((now - deferred().startedAt) / 1e3));
|
|
15156
|
+
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
|
|
15157
|
+
});
|
|
15158
|
+
const filesArray = derived(() => !fileValue() ? [] : Array.isArray(fileValue()) ? fileValue().filter(isFileData) : isFileData(fileValue()) ? [fileValue()] : []);
|
|
15001
15159
|
const fileCount = derived(() => filesArray().length);
|
|
15002
15160
|
const totalSize = derived(() => filesArray().reduce((sum, f) => sum + getBase64FileSize(f.data), 0));
|
|
15003
15161
|
function buildTree(files) {
|
|
@@ -15126,8 +15284,53 @@ function OutputDisplay($$renderer, $$props) {
|
|
|
15126
15284
|
}
|
|
15127
15285
|
$$renderer.push(`<!--]-->`);
|
|
15128
15286
|
}
|
|
15287
|
+
function deferredDisplay($$renderer) {
|
|
15288
|
+
if (deferred()?.status === "waiting") {
|
|
15289
|
+
$$renderer.push(`<!--[0--><div class="gap-2 flex flex-col"><div class="px-3 py-3 text-sm rounded-md border border-border-strong bg-muted text-muted-foreground">${escape_html(t().filesMadeOnDownload)}</div> `);
|
|
15290
|
+
Button($$renderer, {
|
|
15291
|
+
onclick: () => deferredContext?.make(),
|
|
15292
|
+
disabled: deferredContext?.isSolving,
|
|
15293
|
+
class: "w-full",
|
|
15294
|
+
children: ($$renderer) => {
|
|
15295
|
+
$$renderer.push(`<!---->${escape_html(t().download)}`);
|
|
15296
|
+
},
|
|
15297
|
+
$$slots: { default: true }
|
|
15298
|
+
});
|
|
15299
|
+
$$renderer.push(`<!----></div>`);
|
|
15300
|
+
} else if (deferred()?.status === "making") {
|
|
15301
|
+
$$renderer.push(`<!--[1--><div class="gap-2 flex flex-col"><div class="gap-2 px-3 py-3 flex flex-col rounded-md border border-border-strong bg-muted" role="status"><div class="gap-2 flex items-center justify-between"><span class="text-sm font-medium text-foreground">${escape_html(t().makingFiles)}</span> <span class="text-xs shrink-0 text-muted-foreground tabular-nums">${escape_html(elapsed())}</span></div> <div class="h-1 overflow-hidden rounded-full bg-selected"><div class="animate-pulse h-full w-full rounded-full bg-primary"></div></div></div> `);
|
|
15302
|
+
Button($$renderer, {
|
|
15303
|
+
variant: "outline",
|
|
15304
|
+
onclick: () => deferredContext?.cancel(),
|
|
15305
|
+
class: "w-full",
|
|
15306
|
+
children: ($$renderer) => {
|
|
15307
|
+
$$renderer.push(`<!---->${escape_html(t().cancel)}`);
|
|
15308
|
+
},
|
|
15309
|
+
$$slots: { default: true }
|
|
15310
|
+
});
|
|
15311
|
+
$$renderer.push(`<!----></div>`);
|
|
15312
|
+
} else if (deferred()?.status === "empty") $$renderer.push(`<!--[2--><div class="px-3 py-3 text-sm rounded-md border border-border-strong bg-muted text-muted-foreground">${escape_html(t().noFilesForInputs)}</div>`);
|
|
15313
|
+
else if (deferred()?.status === "failed") {
|
|
15314
|
+
$$renderer.push(`<!--[3--><div class="gap-2 flex flex-col"><div class="px-3 py-2 text-sm rounded-md border border-destructive bg-destructive/10 text-destructive">${escape_html(deferred().error)}</div> `);
|
|
15315
|
+
Button($$renderer, {
|
|
15316
|
+
variant: "outline",
|
|
15317
|
+
onclick: () => deferredContext?.make(),
|
|
15318
|
+
disabled: deferredContext?.isSolving,
|
|
15319
|
+
class: "w-full",
|
|
15320
|
+
children: ($$renderer) => {
|
|
15321
|
+
$$renderer.push(`<!---->${escape_html(t().tryAgain)}`);
|
|
15322
|
+
},
|
|
15323
|
+
$$slots: { default: true }
|
|
15324
|
+
});
|
|
15325
|
+
$$renderer.push(`<!----></div>`);
|
|
15326
|
+
} else $$renderer.push("<!--[-1-->");
|
|
15327
|
+
$$renderer.push(`<!--]-->`);
|
|
15328
|
+
}
|
|
15129
15329
|
function fileDisplay($$renderer) {
|
|
15130
|
-
if (
|
|
15330
|
+
if (deferred() && deferred().status !== "ready") {
|
|
15331
|
+
$$renderer.push("<!--[0-->");
|
|
15332
|
+
deferredDisplay($$renderer);
|
|
15333
|
+
} else if (fileCount() === 0) $$renderer.push(`<!--[1--><div class="px-3 py-3 text-sm rounded-md border border-border-strong bg-muted text-muted-foreground">${escape_html(t().waitingForFiles)}</div>`);
|
|
15131
15334
|
else {
|
|
15132
15335
|
$$renderer.push(`<!--[-1--><div class="gap-2 flex flex-col"><div class="px-3 py-2 rounded-md border border-border-strong bg-muted"><div class="gap-2 flex items-center justify-between"><span class="min-w-0 text-sm font-medium truncate text-foreground">${escape_html(fileCount() === 1 ? `${filesArray()[0].fileName}${filesArray()[0].fileType}` : formatMessage(t().fileCount, { count: fileCount() }))}</span> <span class="text-xs shrink-0 text-muted-foreground">${escape_html(formatFileSize(totalSize()))}</span></div> `);
|
|
15133
15336
|
if (fileCount() > 1) {
|
|
@@ -15147,6 +15350,9 @@ function OutputDisplay($$renderer, $$props) {
|
|
|
15147
15350
|
$$renderer.push(`<!--]--></div>`);
|
|
15148
15351
|
} else $$renderer.push("<!--[-1-->");
|
|
15149
15352
|
$$renderer.push(`<!--]--></div> `);
|
|
15353
|
+
if (deferred()?.status === "ready") $$renderer.push(`<!--[0--><span class="text-xs text-muted-foreground">${escape_html(formatMessage(t().filesMadeIn, { seconds: Math.max(1, Math.round(deferred().durationMs / 1e3)) }))}</span>`);
|
|
15354
|
+
else $$renderer.push("<!--[-1-->");
|
|
15355
|
+
$$renderer.push(`<!--]--> `);
|
|
15150
15356
|
if (hasDuplicates()) {
|
|
15151
15357
|
$$renderer.push(`<!--[0--><div class="px-3 py-2 text-sm rounded-md border border-destructive bg-destructive/10 text-destructive"><div class="font-medium">${escape_html(t().duplicateFilesTitle)}</div> <div class="mt-1 text-xs">${escape_html(formatCount(duplicatePaths().length, t().duplicatePathsOne, t().duplicatePathsOther))}</div> <ul class="mt-1 ml-4 text-xs list-disc"><!--[-->`);
|
|
15152
15358
|
const each_array_2 = ensure_array_like(duplicatePaths());
|
|
@@ -17030,6 +17236,11 @@ function useSolveSession(args) {
|
|
|
17030
17236
|
get meshes() {
|
|
17031
17237
|
return track(() => session.meshes);
|
|
17032
17238
|
},
|
|
17239
|
+
get files() {
|
|
17240
|
+
return track(() => session.files);
|
|
17241
|
+
},
|
|
17242
|
+
makeFiles: () => session.makeFiles(),
|
|
17243
|
+
cancelFiles: () => session.cancelFiles(),
|
|
17033
17244
|
get lastResult() {
|
|
17034
17245
|
return track(() => session.lastResult);
|
|
17035
17246
|
},
|
|
@@ -17148,6 +17359,16 @@ function ComputeApp($$renderer, $$props) {
|
|
|
17148
17359
|
scopeKey: externalScopeKey || definitionKey || schema?.id || "",
|
|
17149
17360
|
driver
|
|
17150
17361
|
});
|
|
17362
|
+
setDeferredFilesContext({
|
|
17363
|
+
get files() {
|
|
17364
|
+
return session.files;
|
|
17365
|
+
},
|
|
17366
|
+
get isSolving() {
|
|
17367
|
+
return session.isSolving;
|
|
17368
|
+
},
|
|
17369
|
+
make: () => session.makeFiles(),
|
|
17370
|
+
cancel: () => session.cancelFiles()
|
|
17371
|
+
});
|
|
17151
17372
|
let isViewerFullscreen = false;
|
|
17152
17373
|
const solvingIndicator = createSolvingIndicator(() => session.isSolving);
|
|
17153
17374
|
function handleValueChange(id, val, forceSolve = false) {
|