@selvajs/selva 4.21.0-beta.20 → 4.21.0-beta.22
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/{D2C9ht__.js → 4yJQa0sB.js} +59 -59
- package/build/client/_app/immutable/chunks/4yJQa0sB.js.br +0 -0
- package/build/client/_app/immutable/chunks/4yJQa0sB.js.gz +0 -0
- package/build/client/_app/immutable/chunks/D6XUYEYz.js +1 -0
- package/build/client/_app/immutable/chunks/D6XUYEYz.js.br +1 -0
- package/build/client/_app/immutable/chunks/D6XUYEYz.js.gz +0 -0
- package/build/client/_app/immutable/entry/{app.D3YN7-nC.js → app.S4XqZiwS.js} +2 -2
- package/build/client/_app/immutable/entry/app.S4XqZiwS.js.br +0 -0
- package/build/client/_app/immutable/entry/app.S4XqZiwS.js.gz +0 -0
- package/build/client/_app/immutable/nodes/21.CYY9kOE5.js +1 -0
- package/build/client/_app/immutable/nodes/21.CYY9kOE5.js.br +0 -0
- package/build/client/_app/immutable/nodes/21.CYY9kOE5.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 +9 -0
- package/build/server/chunks/capture.js +1 -1
- package/build/server/chunks/dynamic-value-list.js +301 -0
- package/build/server/chunks/dynamic-value-list.js.map +1 -0
- package/build/server/chunks/instance.js +3 -3
- package/build/server/chunks/internal.js +1 -1
- package/build/server/chunks/package.js +2 -2
- package/build/server/chunks/package.js.map +1 -1
- package/build/server/chunks/providers.server.js +1 -1
- package/build/server/chunks/providers.server.js.map +1 -1
- package/build/server/chunks/schema.js +1 -1
- package/build/server/chunks/schema.js.map +1 -1
- package/build/server/chunks/solve.js +1 -1
- package/build/server/entries/endpoints/mcp/_server.ts.js +246 -39
- package/build/server/entries/endpoints/mcp/_server.ts.js.map +1 -1
- package/build/server/entries/pages/library/_guid_/_page.svelte.js +6 -300
- 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/21.js +1 -1
- package/build/server/server.js +1 -1
- package/package.json +9 -9
- package/templates/.env.example +3 -2
- package/build/client/_app/immutable/chunks/D2C9ht__.js.br +0 -0
- package/build/client/_app/immutable/chunks/D2C9ht__.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DIMAEw3m.js +0 -1
- package/build/client/_app/immutable/chunks/DIMAEw3m.js.br +0 -1
- package/build/client/_app/immutable/chunks/DIMAEw3m.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.D3YN7-nC.js.br +0 -0
- package/build/client/_app/immutable/entry/app.D3YN7-nC.js.gz +0 -0
- package/build/client/_app/immutable/nodes/21.BA-9DMG6.js +0 -1
- package/build/client/_app/immutable/nodes/21.BA-9DMG6.js.br +0 -0
- package/build/client/_app/immutable/nodes/21.BA-9DMG6.js.gz +0 -0
|
@@ -7,6 +7,7 @@ import { r as GuidSchema } from "../../../chunks/schemas.js";
|
|
|
7
7
|
import { q as ProjectVisibilitySchema } from "../../../chunks/api.js";
|
|
8
8
|
import { r as getLayoutItems, t as getGroups } from "../../../chunks/traversal.js";
|
|
9
9
|
import { n as schemaDiffToMarkdown } from "../../../chunks/diff.js";
|
|
10
|
+
import { t as buildFormModel } from "../../../chunks/dynamic-value-list.js";
|
|
10
11
|
import { s as resourceMetadataUrl } from "../../../chunks/oauth.js";
|
|
11
12
|
import { i as oauthServer } from "../../../chunks/server2.js";
|
|
12
13
|
import { t as publicUrl } from "../../../chunks/origin.js";
|
|
@@ -14,6 +15,7 @@ import { t as buildOpenApiDocument } from "../../../chunks/openapi.js";
|
|
|
14
15
|
import { t as MCP_FILES_PREFIX } from "../../../chunks/path.js";
|
|
15
16
|
import { i as jsonBytes, r as fromJsonBytes, t as mcpStash } from "../../../chunks/stash-instance.js";
|
|
16
17
|
import { z } from "zod";
|
|
18
|
+
import { existsSync } from "node:fs";
|
|
17
19
|
import { readFile } from "node:fs/promises";
|
|
18
20
|
import * as z$1 from "zod/v4";
|
|
19
21
|
import process$1 from "node:process";
|
|
@@ -21106,6 +21108,12 @@ new URL("../dist/views/solve.html", import.meta.url);
|
|
|
21106
21108
|
var CaptureUnavailableError = class extends Error {
|
|
21107
21109
|
name = "CaptureUnavailableError";
|
|
21108
21110
|
};
|
|
21111
|
+
var FALLBACK_PATHS = [
|
|
21112
|
+
"/usr/bin/chromium",
|
|
21113
|
+
"/usr/bin/chromium-browser",
|
|
21114
|
+
"/snap/bin/chromium",
|
|
21115
|
+
"/usr/bin/google-chrome"
|
|
21116
|
+
];
|
|
21109
21117
|
var CAPTURE_FILE = new URL("../dist/views/capture.html", import.meta.url);
|
|
21110
21118
|
var ARGS = [
|
|
21111
21119
|
"--use-angle=swiftshader",
|
|
@@ -21127,17 +21135,25 @@ async function launch(executablePath, timeout) {
|
|
|
21127
21135
|
} catch {
|
|
21128
21136
|
throw new CaptureUnavailableError("Rendering needs the `playwright-core` package on the server, which is not installed.");
|
|
21129
21137
|
}
|
|
21130
|
-
|
|
21138
|
+
const candidates = executablePath ? [{ executablePath }] : [
|
|
21139
|
+
{},
|
|
21140
|
+
{ channel: "chrome" },
|
|
21141
|
+
{ channel: "msedge" },
|
|
21142
|
+
...FALLBACK_PATHS.filter((p) => existsSync(p)).map((p) => ({ executablePath: p }))
|
|
21143
|
+
];
|
|
21144
|
+
let first;
|
|
21145
|
+
for (const candidate of candidates) try {
|
|
21131
21146
|
const launched = await chromium.launch({
|
|
21132
|
-
|
|
21147
|
+
...candidate,
|
|
21133
21148
|
args: ARGS,
|
|
21134
21149
|
timeout
|
|
21135
21150
|
});
|
|
21136
21151
|
launched.on("disconnected", () => browser = void 0);
|
|
21137
21152
|
return launched;
|
|
21138
21153
|
} catch (err) {
|
|
21139
|
-
|
|
21154
|
+
first ??= err;
|
|
21140
21155
|
}
|
|
21156
|
+
throw new CaptureUnavailableError(`No browser to render with: ${first instanceof Error ? first.message.split("\n")[0] : String(first)}. Install Chrome or Chromium on the server (\`npx playwright install --with-deps chromium\`, or the system package), or point the server at one.`);
|
|
21141
21157
|
}
|
|
21142
21158
|
/**
|
|
21143
21159
|
* Draws a Rhino.Compute response in Selva's viewer, in a headless Chromium, and returns a PNG.
|
|
@@ -21179,18 +21195,23 @@ async function capture(response, options) {
|
|
|
21179
21195
|
});
|
|
21180
21196
|
await page.setContent(html, { waitUntil: "load" });
|
|
21181
21197
|
const hdr = options.hdr ? await options.hdr() : void 0;
|
|
21182
|
-
const
|
|
21198
|
+
const presets = options.views?.length ? options.views : [options.view ?? "default"];
|
|
21199
|
+
const result = await page.evaluate((req) => globalThis.selvaCapture(req), {
|
|
21183
21200
|
response,
|
|
21184
|
-
|
|
21201
|
+
cameras: options.cameras?.length ? options.cameras : presets.map((view) => ({ view })),
|
|
21185
21202
|
grid: options.grid ?? true,
|
|
21186
21203
|
look: options.look,
|
|
21187
21204
|
background: options.background,
|
|
21188
|
-
|
|
21205
|
+
camera: options.camera,
|
|
21206
|
+
hdr,
|
|
21207
|
+
hide: options.hide,
|
|
21208
|
+
cutaway: options.cutaway,
|
|
21209
|
+
frame: options.frame,
|
|
21210
|
+
sheet: options.sheet
|
|
21189
21211
|
});
|
|
21190
21212
|
return {
|
|
21191
|
-
|
|
21192
|
-
|
|
21193
|
-
drawn
|
|
21213
|
+
...result,
|
|
21214
|
+
png: result.images[0]?.png ?? ""
|
|
21194
21215
|
};
|
|
21195
21216
|
} finally {
|
|
21196
21217
|
options.signal?.removeEventListener("abort", closePage);
|
|
@@ -21253,7 +21274,7 @@ function conditionText(condition, labelOf) {
|
|
|
21253
21274
|
if (action === "disable") return `disabled when ${joined}`;
|
|
21254
21275
|
return `shown only when ${joined}`;
|
|
21255
21276
|
}
|
|
21256
|
-
function inputLine({ input, item, label }, labelOf) {
|
|
21277
|
+
function inputLine({ input, item, label }, labelOf, filledBy) {
|
|
21257
21278
|
const parts = [`- "${label}" (id ${input.id}): ${input.paramType}`];
|
|
21258
21279
|
if (input.inputStructure && input.inputStructure !== "item") parts.push(`, ${input.inputStructure} of them`);
|
|
21259
21280
|
if (item?.widgetType === "number") {
|
|
@@ -21267,8 +21288,9 @@ function inputLine({ input, item, label }, labelOf) {
|
|
|
21267
21288
|
if (item?.widgetType === "checkbox" && item.config?.displayAs === "button") parts.push(", a button: true runs it once");
|
|
21268
21289
|
const options = optionsOf(item);
|
|
21269
21290
|
if (item?.widgetType === "dynamicValueList") {
|
|
21270
|
-
const
|
|
21271
|
-
parts.push(", options computed
|
|
21291
|
+
const sources = filledBy(input.id);
|
|
21292
|
+
parts.push(", its options are computed in the solve" + (sources.length ? ` by ${sources.map((s) => `"${s}"`).join(", ")}` : "") + " and can change with other inputs; selva_solve lists them");
|
|
21293
|
+
if (options && Object.keys(options).length) parts.push(`; before a solve: ${Object.keys(options).map((k) => `"${k}"`).join(", ")}`);
|
|
21272
21294
|
} else if (options) parts.push(`, one of: ${Object.keys(options).map((k) => `"${k}"`).join(", ")}`);
|
|
21273
21295
|
if (input.default !== void 0) parts.push(`, default ${JSON.stringify(input.default)}`);
|
|
21274
21296
|
const condition = conditionText(item?.visibilityCondition, labelOf);
|
|
@@ -21293,6 +21315,8 @@ function outputLine(schema, item, id) {
|
|
|
21293
21315
|
function formText(schema) {
|
|
21294
21316
|
const described = describeInputs(schema);
|
|
21295
21317
|
const labelOf = (id) => described.find((d) => d.input.id === id)?.label ?? id;
|
|
21318
|
+
const filledBy = (id) => schema.outputs.filter((o) => o.type === "dynamicValueList" && o.targetInputId === id).map((o) => o.nickname);
|
|
21319
|
+
const line = (d) => inputLine(d, labelOf, filledBy);
|
|
21296
21320
|
const lines = [];
|
|
21297
21321
|
const placedInputs = /* @__PURE__ */ new Set();
|
|
21298
21322
|
const placedOutputs = /* @__PURE__ */ new Set();
|
|
@@ -21303,7 +21327,7 @@ function formText(schema) {
|
|
|
21303
21327
|
const d = described.find((x) => x.input.id === item.paramId);
|
|
21304
21328
|
if (!d) continue;
|
|
21305
21329
|
placedInputs.add(d.input.id);
|
|
21306
|
-
inputs.push(
|
|
21330
|
+
inputs.push(line(d));
|
|
21307
21331
|
} else if (item.type === "output" && item.paramId) {
|
|
21308
21332
|
const line = outputLine(schema, item, item.paramId);
|
|
21309
21333
|
if (!line) continue;
|
|
@@ -21319,9 +21343,10 @@ function formText(schema) {
|
|
|
21319
21343
|
};
|
|
21320
21344
|
for (const group of getGroups(schema)) groupBlock(group);
|
|
21321
21345
|
const looseInputs = described.filter((d) => !placedInputs.has(d.input.id));
|
|
21322
|
-
if (looseInputs.length) lines.push("", "## Not on the form", "Inputs:", ...looseInputs.map(
|
|
21346
|
+
if (looseInputs.length) lines.push("", "## Not on the form", "Inputs:", ...looseInputs.map(line));
|
|
21323
21347
|
const looseOutputs = schema.outputs.filter((o) => !placedOutputs.has(o.id)).map((o) => outputLine(schema, void 0, o.id));
|
|
21324
21348
|
if (looseOutputs.length) lines.push("", "Other outputs:", ...looseOutputs);
|
|
21349
|
+
if (schema.outputs.some((o) => o.type === "dynamicValueList")) lines.push("", "Some lists are computed in the solve: what they offer depends on other inputs, and an output can repeat an input once per row (a cabinet, a bay). selva_solve returns each list's options and the pick it used; an input repeated per row takes an object of row key to option name.");
|
|
21325
21350
|
return lines;
|
|
21326
21351
|
}
|
|
21327
21352
|
/** Values keyed by what the model saw: label, nickname or id. Dropdown labels become their values. */
|
|
@@ -21342,7 +21367,7 @@ function resolveValues(described, given) {
|
|
|
21342
21367
|
}
|
|
21343
21368
|
const options = optionsOf(match.item);
|
|
21344
21369
|
const pick = (v) => typeof v === "string" && options && Object.hasOwn(options, v) && options[v] !== void 0 ? options[v] : v;
|
|
21345
|
-
values[match.input.id] = Array.isArray(value) ? value.map(pick) : pick(value);
|
|
21370
|
+
values[match.input.id] = Array.isArray(value) ? value.map(pick) : typeof value === "object" && value !== null ? JSON.stringify(Object.fromEntries(Object.entries(value).map(([row, v]) => [row, pick(v)]))) : pick(value);
|
|
21346
21371
|
}
|
|
21347
21372
|
if (unknown.length) {
|
|
21348
21373
|
const known = described.map((d) => `"${d.label}"`).join(", ");
|
|
@@ -21422,7 +21447,7 @@ function decode(data) {
|
|
|
21422
21447
|
}
|
|
21423
21448
|
return value;
|
|
21424
21449
|
}
|
|
21425
|
-
var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
21450
|
+
var isRecord$1 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
21426
21451
|
/**
|
|
21427
21452
|
* Each input's options as this solve computed them, name to value, keyed by input id. Only plain
|
|
21428
21453
|
* lists: an Options Table narrows by the picks on screen, which a static form can't follow.
|
|
@@ -21434,7 +21459,7 @@ function solvedOptions(schema, trees) {
|
|
|
21434
21459
|
for (const item of Object.values(tree.InnerTree ?? {}).flat()) {
|
|
21435
21460
|
if (!isValueListType(item.type)) continue;
|
|
21436
21461
|
const payload = decode(item.data);
|
|
21437
|
-
if (!isRecord(payload) || !isRecord(payload.options)) continue;
|
|
21462
|
+
if (!isRecord$1(payload) || !isRecord$1(payload.options)) continue;
|
|
21438
21463
|
const target = typeof payload.targetInputId === "string" ? payload.targetInputId : schemaTarget;
|
|
21439
21464
|
const options = Object.entries(payload.options).filter((e) => typeof e[1] === "string");
|
|
21440
21465
|
if (target && options.length) found.set(target, Object.fromEntries(options));
|
|
@@ -21464,9 +21489,9 @@ function readValueLists(schema, paramName, items) {
|
|
|
21464
21489
|
const combinations = [];
|
|
21465
21490
|
for (const item of items) {
|
|
21466
21491
|
const payload = decode(item.data);
|
|
21467
|
-
if (!isRecord(payload)) continue;
|
|
21492
|
+
if (!isRecord$1(payload)) continue;
|
|
21468
21493
|
const target = typeof payload.targetInputId === "string" ? payload.targetInputId : schemaTarget;
|
|
21469
|
-
const names = isRecord(payload.options) ? Object.keys(payload.options) : [];
|
|
21494
|
+
const names = isRecord$1(payload.options) ? Object.keys(payload.options) : [];
|
|
21470
21495
|
if (target && names.length) {
|
|
21471
21496
|
const label = labelOf(target);
|
|
21472
21497
|
const { shown, more } = head(names);
|
|
@@ -21474,7 +21499,7 @@ function readValueLists(schema, paramName, items) {
|
|
|
21474
21499
|
parts.push(`options for "${label}": ${quoted(shown)}${andMore(more)}`);
|
|
21475
21500
|
}
|
|
21476
21501
|
const table = payload.pickTable;
|
|
21477
|
-
if (isRecord(table) && Array.isArray(table.inputs) && Array.isArray(table.rows)) {
|
|
21502
|
+
if (isRecord$1(table) && Array.isArray(table.inputs) && Array.isArray(table.rows)) {
|
|
21478
21503
|
const columns = [...Array.isArray(table.by) ? table.by : [], ...table.inputs].map((id) => labelOf(String(id)));
|
|
21479
21504
|
const rows = table.rows.filter(Array.isArray).map((r) => r.map(String));
|
|
21480
21505
|
const { shown, more } = head(rows);
|
|
@@ -21511,12 +21536,12 @@ function readCharts(items) {
|
|
|
21511
21536
|
const charts = [];
|
|
21512
21537
|
for (const item of items) {
|
|
21513
21538
|
const figure = decode(item.data);
|
|
21514
|
-
if (!isRecord(figure) || !Array.isArray(figure.data)) continue;
|
|
21515
|
-
const rawTitle = (isRecord(figure.layout) ? figure.layout : {}).title;
|
|
21516
|
-
const title = typeof rawTitle === "string" ? rawTitle : isRecord(rawTitle) && typeof rawTitle.text === "string" ? rawTitle.text : void 0;
|
|
21539
|
+
if (!isRecord$1(figure) || !Array.isArray(figure.data)) continue;
|
|
21540
|
+
const rawTitle = (isRecord$1(figure.layout) ? figure.layout : {}).title;
|
|
21541
|
+
const title = typeof rawTitle === "string" ? rawTitle : isRecord$1(rawTitle) && typeof rawTitle.text === "string" ? rawTitle.text : void 0;
|
|
21517
21542
|
const series = [];
|
|
21518
21543
|
const traces = [];
|
|
21519
|
-
for (const trace of figure.data.filter(isRecord)) {
|
|
21544
|
+
for (const trace of figure.data.filter(isRecord$1)) {
|
|
21520
21545
|
const pairs = pointsOf(trace);
|
|
21521
21546
|
if (!pairs) continue;
|
|
21522
21547
|
const [labels, values] = pairs;
|
|
@@ -21693,6 +21718,110 @@ async function fileLinks(items, origin, stash) {
|
|
|
21693
21718
|
}
|
|
21694
21719
|
return links;
|
|
21695
21720
|
}
|
|
21721
|
+
/** Parses an item, unwrapping the JSON strings Compute may wrap it in. */
|
|
21722
|
+
function parseDeep(data) {
|
|
21723
|
+
let value = data;
|
|
21724
|
+
for (let i = 0; i < 3 && typeof value === "string"; i++) try {
|
|
21725
|
+
value = JSON.parse(value);
|
|
21726
|
+
} catch {
|
|
21727
|
+
break;
|
|
21728
|
+
}
|
|
21729
|
+
return value;
|
|
21730
|
+
}
|
|
21731
|
+
var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
21732
|
+
/** A Plotly figure's title and data, or null when `value` is not one. */
|
|
21733
|
+
function readFigure(value) {
|
|
21734
|
+
if (!isRecord(value) || !Array.isArray(value.data)) return null;
|
|
21735
|
+
const layout = isRecord(value.layout) ? value.layout : {};
|
|
21736
|
+
const title = isRecord(layout.title) ? layout.title.text : layout.title;
|
|
21737
|
+
const array = (v) => Array.isArray(v) ? v.slice(0, MAX_SCALARS) : void 0;
|
|
21738
|
+
const traces = value.data.filter(isRecord).map((t) => {
|
|
21739
|
+
const trace = { type: typeof t.type === "string" ? t.type : "scatter" };
|
|
21740
|
+
if (typeof t.name === "string" && t.name) trace.name = t.name;
|
|
21741
|
+
for (const key of [
|
|
21742
|
+
"labels",
|
|
21743
|
+
"values",
|
|
21744
|
+
"x",
|
|
21745
|
+
"y"
|
|
21746
|
+
]) {
|
|
21747
|
+
const data = array(t[key]);
|
|
21748
|
+
if (data) trace[key] = data;
|
|
21749
|
+
}
|
|
21750
|
+
return trace;
|
|
21751
|
+
});
|
|
21752
|
+
return {
|
|
21753
|
+
...typeof title === "string" && title && { title },
|
|
21754
|
+
traces
|
|
21755
|
+
};
|
|
21756
|
+
}
|
|
21757
|
+
var numberText = (v) => typeof v === "number" ? v.toLocaleString("en-US", { maximumFractionDigits: 2 }) : String(v);
|
|
21758
|
+
function chartText(chart) {
|
|
21759
|
+
const parts = chart.traces.map((t) => {
|
|
21760
|
+
const keys = t.labels ?? t.x;
|
|
21761
|
+
const values = t.values ?? t.y;
|
|
21762
|
+
const head = `${t.type}${t.name ? ` "${t.name}"` : ""}`;
|
|
21763
|
+
if (!keys || !values) return head;
|
|
21764
|
+
const pairs = keys.map((k, i) => `${String(k)} ${numberText(values[i])}`);
|
|
21765
|
+
const numbers = values.filter((v) => typeof v === "number");
|
|
21766
|
+
const sum = t.type === "pie" && numbers.length === values.length ? ` (sum ${numberText(numbers.reduce((a, b) => a + b, 0))})` : "";
|
|
21767
|
+
return `${head}: ${pairs.join("; ")}${sum}`;
|
|
21768
|
+
});
|
|
21769
|
+
return `chart${chart.title ? ` "${chart.title}"` : ""}, ${parts.join(" | ")}`;
|
|
21770
|
+
}
|
|
21771
|
+
function readListPayload(value) {
|
|
21772
|
+
return isRecord(value) && ("targetInputId" in value || "options" in value) ? value : null;
|
|
21773
|
+
}
|
|
21774
|
+
/** Option names for values, in the form's words. */
|
|
21775
|
+
var namesOf = (options) => Object.keys(options);
|
|
21776
|
+
var nameOf = (options, value) => (options && Object.keys(options).find((n) => options[n] === value)) ?? value;
|
|
21777
|
+
/** What one computed list output does, in the form's labels. */
|
|
21778
|
+
function listOutputText(payload, labelOf) {
|
|
21779
|
+
const quoted = (ids) => ids.map((id) => `"${labelOf(id)}"`).join(", ");
|
|
21780
|
+
if (payload.rows && payload.members) {
|
|
21781
|
+
const rows = payload.rows.map((r) => `${r.label || r.key}${r.section ? ` (${r.section})` : ""}`);
|
|
21782
|
+
return `${rows.length} rows, each with ${quoted(payload.members)}: ${rows.join(", ")}`;
|
|
21783
|
+
}
|
|
21784
|
+
if (payload.pickTable) {
|
|
21785
|
+
const by = payload.pickTable.by?.length ? `, narrowed by ${quoted(payload.pickTable.by)}` : "";
|
|
21786
|
+
return `fills ${quoted(payload.pickTable.inputs)}${by}`;
|
|
21787
|
+
}
|
|
21788
|
+
const options = payload.options ?? {};
|
|
21789
|
+
return `${payload.targetInputId ? `options for "${labelOf(payload.targetInputId)}"` : "options"}: ${namesOf(options).join(", ") || "none"}`;
|
|
21790
|
+
}
|
|
21791
|
+
/** Each computed list's options and the pick the solve used, as the form would show them. */
|
|
21792
|
+
function listsText(schema, values, labelOf) {
|
|
21793
|
+
const model = buildFormModel(schema, values);
|
|
21794
|
+
const lines = [];
|
|
21795
|
+
const structured = {};
|
|
21796
|
+
for (const [id, options] of Object.entries(model.options)) {
|
|
21797
|
+
const pick = nameOf(options, model.shown[id] ?? values[id]);
|
|
21798
|
+
const label = labelOf(id);
|
|
21799
|
+
structured[label] = {
|
|
21800
|
+
options: namesOf(options),
|
|
21801
|
+
...pick !== void 0 && { pick }
|
|
21802
|
+
};
|
|
21803
|
+
lines.push(`- "${label}": one of ${namesOf(options).map((n) => `"${n}"`).join(", ")}${pick !== void 0 && pick !== "" ? `; the solve used "${String(pick)}"` : ""}`);
|
|
21804
|
+
}
|
|
21805
|
+
for (const repeat of model.repeats) for (const member of repeat.members) {
|
|
21806
|
+
const label = labelOf(member);
|
|
21807
|
+
const shown = model.shown[member];
|
|
21808
|
+
const rows = repeat.rows.map((row, i) => {
|
|
21809
|
+
const options = model.rowOptions[member]?.[i] ?? {};
|
|
21810
|
+
return {
|
|
21811
|
+
row: row.key,
|
|
21812
|
+
label: row.label ?? row.key,
|
|
21813
|
+
options: namesOf(options),
|
|
21814
|
+
pick: nameOf(options, shown?.[i])
|
|
21815
|
+
};
|
|
21816
|
+
});
|
|
21817
|
+
structured[label] = { rows };
|
|
21818
|
+
lines.push(`- "${label}", per row as a JSON object of row key to option name:`, ...rows.map((r) => ` - ${r.row} (${r.label}): ${r.options.map((n) => `"${n}"`).join(", ")}; the solve used "${String(r.pick)}"`));
|
|
21819
|
+
}
|
|
21820
|
+
return {
|
|
21821
|
+
lines,
|
|
21822
|
+
structured
|
|
21823
|
+
};
|
|
21824
|
+
}
|
|
21696
21825
|
function sizeText(bytes) {
|
|
21697
21826
|
if (bytes < 1024) return `${bytes} B`;
|
|
21698
21827
|
if (bytes < 1048576) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
@@ -21702,10 +21831,40 @@ async function summarizeSolve(res, schema, options) {
|
|
|
21702
21831
|
const lines = [];
|
|
21703
21832
|
const structured = {};
|
|
21704
21833
|
const declared = new Map(schema.outputs.map((o) => [o.nickname, o.type]));
|
|
21834
|
+
const outputId = new Map(schema.outputs.map((o) => [o.nickname, o.id]));
|
|
21835
|
+
const described = describeInputs(schema);
|
|
21836
|
+
const labelOf = (id) => described.find((d) => d.input.id === id)?.label ?? id;
|
|
21837
|
+
const formValues = Object.fromEntries(schema.inputs.filter((i) => i.default !== void 0).map((i) => [i.id, i.default]));
|
|
21838
|
+
Object.assign(formValues, options.values);
|
|
21839
|
+
let anyLists = false;
|
|
21705
21840
|
let anyFiles = false;
|
|
21706
21841
|
for (const tree of res.values ?? []) {
|
|
21707
21842
|
if (isPlumbing(tree)) continue;
|
|
21708
21843
|
const items = Object.values(tree.InnerTree ?? {}).flat();
|
|
21844
|
+
const kind = declared.get(tree.ParamName);
|
|
21845
|
+
const lists = kind === "dynamicValueList" || items.some((i) => /DynamicValueList/.test(i.type)) ? items.map((i) => readListPayload(parseDeep(i.data))) : [];
|
|
21846
|
+
if (lists.length && lists.every(Boolean)) {
|
|
21847
|
+
const payload = lists[0];
|
|
21848
|
+
const id = outputId.get(tree.ParamName);
|
|
21849
|
+
if (id) formValues[id] = payload;
|
|
21850
|
+
anyLists = true;
|
|
21851
|
+
structured[tree.ParamName] = payload.pickTable ? {
|
|
21852
|
+
fills: payload.pickTable.inputs.map(labelOf),
|
|
21853
|
+
by: (payload.pickTable.by ?? []).map(labelOf)
|
|
21854
|
+
} : payload.rows ? {
|
|
21855
|
+
rows: payload.rows,
|
|
21856
|
+
members: (payload.members ?? []).map(labelOf)
|
|
21857
|
+
} : { options: namesOf(payload.options ?? {}) };
|
|
21858
|
+
lines.push(`${tree.ParamName}: ${listOutputText(payload, labelOf)}`);
|
|
21859
|
+
continue;
|
|
21860
|
+
}
|
|
21861
|
+
const charts = kind === "chart" || items.some((i) => /Plotly/i.test(i.type)) ? items.map((i) => readFigure(parseDeep(i.data))) : [];
|
|
21862
|
+
if (charts.length && charts.every(Boolean)) {
|
|
21863
|
+
const read = charts;
|
|
21864
|
+
structured[tree.ParamName] = read.length === 1 ? read[0] : read;
|
|
21865
|
+
lines.push(`${tree.ParamName}: ${read.map(chartText).join(" || ")}`);
|
|
21866
|
+
continue;
|
|
21867
|
+
}
|
|
21709
21868
|
const asNumber = declared.get(tree.ParamName) === "number";
|
|
21710
21869
|
const scalars = items.filter((i) => SCALAR.test(i.type)).map((i) => {
|
|
21711
21870
|
const v = parseItem(i.data);
|
|
@@ -21751,6 +21910,14 @@ async function summarizeSolve(res, schema, options) {
|
|
|
21751
21910
|
lines.push(`${tree.ParamName}: ${items.length ? parts.join(", ") : "empty"}`);
|
|
21752
21911
|
}
|
|
21753
21912
|
if (!lines.length) lines.push("The solve returned no outputs.");
|
|
21913
|
+
let lists;
|
|
21914
|
+
if (anyLists) {
|
|
21915
|
+
const text = listsText(schema, formValues, labelOf);
|
|
21916
|
+
if (text.lines.length) {
|
|
21917
|
+
lines.push("", "Lists computed in this solve, and what they offer now:", ...text.lines, "");
|
|
21918
|
+
lists = text.structured;
|
|
21919
|
+
}
|
|
21920
|
+
}
|
|
21754
21921
|
if (anyFiles) lines.push("File links download the file and expire within the hour.");
|
|
21755
21922
|
if (res.selva?.outcome) lines.push(`Outcome: ${JSON.stringify(res.selva.outcome)}`);
|
|
21756
21923
|
for (const e of res.errors ?? []) lines.push(`Error: ${e}`);
|
|
@@ -21761,6 +21928,7 @@ async function summarizeSolve(res, schema, options) {
|
|
|
21761
21928
|
text: lines.join("\n"),
|
|
21762
21929
|
structured: {
|
|
21763
21930
|
outputs: structured,
|
|
21931
|
+
...lists && { lists },
|
|
21764
21932
|
errors: res.errors ?? [],
|
|
21765
21933
|
warnings: res.warnings ?? [],
|
|
21766
21934
|
link: options.link
|
|
@@ -21800,7 +21968,7 @@ var captureHdr = () => import("../../../chunks/baseHDR.js").then((m) => m.defaul
|
|
|
21800
21968
|
* render it, check what it needs from Compute, upload and compare versions, edit its details and
|
|
21801
21969
|
* cover, publish a version, and list or create projects. No deletes, share links, tokens or admin.
|
|
21802
21970
|
*/
|
|
21803
|
-
var valuesArg = z.record(z.string(), z.unknown()).default({}).describe("Input values keyed by the names selva_describe_definition lists. Dropdowns take an option name.");
|
|
21971
|
+
var valuesArg = z.record(z.string(), z.unknown()).default({}).describe("Input values keyed by the names selva_describe_definition lists. Dropdowns take an option name; an input repeated per row takes an object of row key to option name.");
|
|
21804
21972
|
async function schemaFor(api, guid, version, signal) {
|
|
21805
21973
|
if (!version || version === "live") return { schema: await api.call("getDefinitionsByGuidSchema", {
|
|
21806
21974
|
params: { guid },
|
|
@@ -21823,6 +21991,7 @@ async function schemaFor(api, guid, version, signal) {
|
|
|
21823
21991
|
async function runSolve(api, definition, values, version, signal) {
|
|
21824
21992
|
const guid = await resolveDefinition(api, definition, signal);
|
|
21825
21993
|
const { schema, versionId } = await schemaFor(api, guid, version, signal);
|
|
21994
|
+
const resolved = resolveValues(describeInputs(schema), values);
|
|
21826
21995
|
return {
|
|
21827
21996
|
guid,
|
|
21828
21997
|
schema,
|
|
@@ -21830,11 +21999,12 @@ async function runSolve(api, definition, values, version, signal) {
|
|
|
21830
21999
|
params: { guid },
|
|
21831
22000
|
body: {
|
|
21832
22001
|
inputs: schema.inputs,
|
|
21833
|
-
values:
|
|
22002
|
+
values: resolved,
|
|
21834
22003
|
...versionId && { versionId }
|
|
21835
22004
|
},
|
|
21836
22005
|
signal
|
|
21837
|
-
})
|
|
22006
|
+
}),
|
|
22007
|
+
resolved
|
|
21838
22008
|
};
|
|
21839
22009
|
}
|
|
21840
22010
|
var SOLVE_CALLS = [
|
|
@@ -21918,6 +22088,7 @@ async function readCover(api, guid, signal) {
|
|
|
21918
22088
|
};
|
|
21919
22089
|
}
|
|
21920
22090
|
var CAPTURE_VIEWS = [
|
|
22091
|
+
"default",
|
|
21921
22092
|
"iso",
|
|
21922
22093
|
"top",
|
|
21923
22094
|
"front",
|
|
@@ -21937,6 +22108,19 @@ var PREVIEW_LOOKS = [
|
|
|
21937
22108
|
"night"
|
|
21938
22109
|
];
|
|
21939
22110
|
var DEFAULT_BACKGROUND = "#E6E6E6";
|
|
22111
|
+
var MAX_CAPTURE_CAMERAS = 6;
|
|
22112
|
+
var CaptureCameraArg = z.object({
|
|
22113
|
+
view: z.enum(CAPTURE_VIEWS).optional().describe("A preset direction. Ignored when azimuth is set."),
|
|
22114
|
+
azimuth: z.number().optional().describe("Degrees around the up axis: 0 from the front, 90 from the right, 180 from the back."),
|
|
22115
|
+
elevation: z.number().min(-89).max(89).optional().describe("Degrees above the horizon. Default 30 when azimuth is set; 90 is nearly top-down."),
|
|
22116
|
+
zoom: z.number().min(.1).max(20).optional().describe("1 fits the geometry, 2 is twice as close, 0.5 shows more around it."),
|
|
22117
|
+
target: z.tuple([
|
|
22118
|
+
z.number(),
|
|
22119
|
+
z.number(),
|
|
22120
|
+
z.number()
|
|
22121
|
+
]).optional().describe("World point to look at, in the model's units. Default the middle of what is drawn."),
|
|
22122
|
+
label: z.string().max(80).optional()
|
|
22123
|
+
});
|
|
21940
22124
|
var ListOutput = z.object({
|
|
21941
22125
|
items: z.array(z.record(z.string(), z.unknown())),
|
|
21942
22126
|
nextCursor: z.string().optional()
|
|
@@ -21944,6 +22128,8 @@ var ListOutput = z.object({
|
|
|
21944
22128
|
/** `outputs` is keyed by the definition's own output names, so it can't be closed. */
|
|
21945
22129
|
var SolveOutput = z.object({
|
|
21946
22130
|
outputs: z.record(z.string(), z.unknown()),
|
|
22131
|
+
/** Each computed list by input label: its options now and the pick the solve used. */
|
|
22132
|
+
lists: z.record(z.string(), z.unknown()).optional(),
|
|
21947
22133
|
errors: z.array(z.string()),
|
|
21948
22134
|
warnings: z.array(z.string()),
|
|
21949
22135
|
link: z.string(),
|
|
@@ -22207,11 +22393,12 @@ function selvaTools(origin, options) {
|
|
|
22207
22393
|
calls: SOLVE_CALLS,
|
|
22208
22394
|
ui: { resourceUri: SOLVE_VIEW_URI },
|
|
22209
22395
|
async run(api, { definition, values, version, detail }, { signal, apps }) {
|
|
22210
|
-
const { guid, schema, res } = await runSolve(api, definition, values, version, signal);
|
|
22396
|
+
const { guid, schema, res, resolved } = await runSolve(api, definition, values, version, signal);
|
|
22211
22397
|
const summary = await summarizeSolve(res, schema, {
|
|
22212
22398
|
origin,
|
|
22213
22399
|
link: pageOf(guid),
|
|
22214
|
-
stash
|
|
22400
|
+
stash,
|
|
22401
|
+
values: resolved
|
|
22215
22402
|
});
|
|
22216
22403
|
const solveId = await stash.put({
|
|
22217
22404
|
kind: "solve",
|
|
@@ -22228,6 +22415,7 @@ function selvaTools(origin, options) {
|
|
|
22228
22415
|
title: schema.name,
|
|
22229
22416
|
look: schema.viewerOptions?.look,
|
|
22230
22417
|
background: schema.viewerOptions?.backgroundColor ?? DEFAULT_BACKGROUND,
|
|
22418
|
+
camera: schema.viewerOptions?.camera,
|
|
22231
22419
|
load: {
|
|
22232
22420
|
tool: "selva_solve_geometry",
|
|
22233
22421
|
arguments: { token: solveId }
|
|
@@ -22283,13 +22471,18 @@ function selvaTools(origin, options) {
|
|
|
22283
22471
|
tool({
|
|
22284
22472
|
name: "selva_capture_preview",
|
|
22285
22473
|
title: "Render a preview",
|
|
22286
|
-
description: "Draws a solve in Selva's own 3D viewer and returns a picture per view, with the look and background the definition opens in unless `look` says otherwise. Pass `solve`, the solve id selva_solve returned, to draw that result without solving again; otherwise it solves `values` first and spends compute like selva_solve. Extra views cost no compute. Each picture is kept for an hour under a preview id: pass one to selva_set_cover_image to make it the cover.",
|
|
22474
|
+
description: "Draws a solve in Selva's own 3D viewer and returns a picture per view, with the look and background the definition opens in unless `look` says otherwise. Pass `solve`, the solve id selva_solve returned, to draw that result without solving again; otherwise it solves `values` first and spends compute like selva_solve. Extra views cost no compute. Aim with preset `views`, or with `cameras` (azimuth, elevation, zoom, target); `sheet` joins them into one labelled grid. The camera fits what is drawn. `hide` leaves out layers or objects by name (the solve's geometry outputs name them); `cutaway` leaves out the walls between each camera and the middle of the scene. Each picture is kept for an hour under a preview id: pass one to selva_set_cover_image to make it the cover.",
|
|
22287
22475
|
input: z.object({
|
|
22288
22476
|
definition: definitionArg,
|
|
22289
22477
|
solve: z.string().optional().describe("A solve id from selva_solve. When given, `values` is ignored."),
|
|
22290
22478
|
values: valuesArg,
|
|
22291
22479
|
version: versionArg,
|
|
22292
|
-
views: z.array(z.enum(CAPTURE_VIEWS)).min(1).max(4).default(["
|
|
22480
|
+
views: z.array(z.enum(CAPTURE_VIEWS)).min(1).max(4).default(["default"]).describe("Camera directions, a picture each, when `cameras` is not given. `default` is the view the definition opens in, or iso when it saves none."),
|
|
22481
|
+
cameras: z.array(CaptureCameraArg).max(MAX_CAPTURE_CAMERAS).optional().describe("One picture per camera, all from the same solve."),
|
|
22482
|
+
sheet: z.boolean().default(false).describe("Return the pictures as one labelled grid instead of one each."),
|
|
22483
|
+
hide: z.array(z.string()).max(50).optional().describe("Layers or object names to leave out. A layer hides its sublayers: \"Room\" hides \"Room/Walls\"."),
|
|
22484
|
+
cutaway: z.boolean().default(false).describe("Leave out tall thin walls standing between each camera and the middle of the scene."),
|
|
22485
|
+
fit: z.boolean().default(true).describe("Fit the camera tightly to what is drawn. False keeps the viewer's looser framing."),
|
|
22293
22486
|
look: z.enum(PREVIEW_LOOKS).optional().describe("The viewer look. Default: the definition's own. `night` lights lamps."),
|
|
22294
22487
|
width: z.number().int().min(256).max(2048).default(1200),
|
|
22295
22488
|
height: z.number().int().min(256).max(2048).default(800),
|
|
@@ -22297,7 +22490,8 @@ function selvaTools(origin, options) {
|
|
|
22297
22490
|
}),
|
|
22298
22491
|
calls: SOLVE_CALLS,
|
|
22299
22492
|
async run(api, args, { signal }) {
|
|
22300
|
-
const { definition, solve, values, version, views,
|
|
22493
|
+
const { definition, solve, values, version, views, cameras, sheet, hide, cutaway, fit } = args;
|
|
22494
|
+
const { look, width, height, grid } = args;
|
|
22301
22495
|
let schema;
|
|
22302
22496
|
let res;
|
|
22303
22497
|
if (solve) {
|
|
@@ -22307,16 +22501,26 @@ function selvaTools(origin, options) {
|
|
|
22307
22501
|
({schema} = await schemaFor(api, guid, version, signal));
|
|
22308
22502
|
res = fromJsonBytes(held.data);
|
|
22309
22503
|
} else ({schema, res} = await runSolve(api, definition, values, version, signal));
|
|
22504
|
+
let hdrMissing;
|
|
22505
|
+
const hdr = () => captureHdr().catch((err) => {
|
|
22506
|
+
hdrMissing = err instanceof Error ? err.message : String(err);
|
|
22507
|
+
});
|
|
22310
22508
|
let capture;
|
|
22311
22509
|
try {
|
|
22312
22510
|
capture = await captureSolve(res, {
|
|
22313
22511
|
views,
|
|
22512
|
+
cameras,
|
|
22513
|
+
sheet,
|
|
22514
|
+
hide,
|
|
22515
|
+
cutaway,
|
|
22516
|
+
frame: fit,
|
|
22314
22517
|
width,
|
|
22315
22518
|
height,
|
|
22316
22519
|
grid,
|
|
22317
22520
|
look: look ?? schema.viewerOptions?.look,
|
|
22318
22521
|
background: schema.viewerOptions?.backgroundColor ?? DEFAULT_BACKGROUND,
|
|
22319
|
-
|
|
22522
|
+
camera: schema.viewerOptions?.camera,
|
|
22523
|
+
hdr,
|
|
22320
22524
|
html: captureHtml,
|
|
22321
22525
|
executablePath: options.previewBrowser || void 0,
|
|
22322
22526
|
signal
|
|
@@ -22325,21 +22529,24 @@ function selvaTools(origin, options) {
|
|
|
22325
22529
|
if (err instanceof CaptureUnavailableError) throw new Error(`${err.message} An operator sets this up. The solve itself worked: selva_solve still returns its numbers.`, { cause: err });
|
|
22326
22530
|
throw err;
|
|
22327
22531
|
}
|
|
22328
|
-
if (!capture.drawn) return `${schema.name} solved, but drew nothing: it has no Display output with geometry for these values.`;
|
|
22532
|
+
if (!capture.drawn || !capture.images.length) return `${schema.name} solved, but drew nothing: it has no Display output with geometry for these values.`;
|
|
22329
22533
|
const lines = [`${schema.name}, ${width}×${height}${look ? `, ${look} look` : ""}.`];
|
|
22330
|
-
for (const [i,
|
|
22534
|
+
for (const [i, image] of capture.images.entries()) {
|
|
22331
22535
|
const previewId = await stash.put({
|
|
22332
22536
|
kind: "preview",
|
|
22333
22537
|
name: `${schema.name}.png`,
|
|
22334
22538
|
contentType: "image/png",
|
|
22335
|
-
data: new Uint8Array(Buffer.from(png, "base64"))
|
|
22539
|
+
data: new Uint8Array(Buffer.from(image.png, "base64"))
|
|
22336
22540
|
});
|
|
22337
|
-
lines.push(`${
|
|
22541
|
+
lines.push(`${i + 1}. ${image.label}: preview id ${previewId}` + (image.cut.length ? `, cut away: ${image.cut.join(", ")}` : "") + ".");
|
|
22338
22542
|
}
|
|
22543
|
+
if (hide?.length) lines.push(`Hidden: ${hide.join(", ")}.`);
|
|
22544
|
+
if (capture.layers.length) lines.push(`Layers drawn: ${capture.layers.join(", ")}.`);
|
|
22545
|
+
if (hdrMissing) lines.push(`Lit without the HDR environment, which could not be read: ${hdrMissing}`);
|
|
22339
22546
|
return {
|
|
22340
22547
|
text: lines.join("\n"),
|
|
22341
|
-
images: capture.
|
|
22342
|
-
data,
|
|
22548
|
+
images: capture.images.map((image) => ({
|
|
22549
|
+
data: image.png,
|
|
22343
22550
|
mimeType: "image/png"
|
|
22344
22551
|
}))
|
|
22345
22552
|
};
|