@selvajs/selva 4.21.0-beta.18 → 4.21.0-beta.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/build/adapter-node.js +2 -2
  2. package/build/client/_app/version.json +1 -1
  3. package/build/client/_app/version.json.br +0 -0
  4. package/build/client/_app/version.json.gz +0 -0
  5. package/build/server/.vite/manifest.json +8 -34
  6. package/build/server/chunks/baseHDR.js +2 -2
  7. package/build/server/chunks/baseHDR.js.map +1 -1
  8. package/build/server/chunks/functions.js +1 -1
  9. package/build/server/chunks/grasshopper.js +23 -1
  10. package/build/server/chunks/grasshopper.js.map +1 -1
  11. package/build/server/chunks/instance.js +5 -5
  12. package/build/server/chunks/internal.js +3 -3
  13. package/build/server/chunks/package.js +1 -1
  14. package/build/server/chunks/package.js.map +1 -1
  15. package/build/server/chunks/rhino3dm.js.map +1 -1
  16. package/build/server/chunks/server-errors.js +1 -19
  17. package/build/server/chunks/server-errors.js.map +1 -1
  18. package/build/server/chunks/solve.js +1 -1
  19. package/build/server/entries/endpoints/mcp/_server.ts.js +160 -14
  20. package/build/server/entries/endpoints/mcp/_server.ts.js.map +1 -1
  21. package/build/server/index.js +1 -1
  22. package/build/server/remote-entry.js +1559 -1
  23. package/build/server/remote-entry.js.map +1 -0
  24. package/package.json +3 -3
  25. package/build/client/_app/immutable/assets/baseHDR.Dkr46J8-.hdr +0 -0
  26. package/build/server/_app/immutable/assets/baseHDR.Dkr46J8-.hdr +0 -0
  27. package/build/server/chunks/remote.js +0 -1559
  28. package/build/server/chunks/remote.js.map +0 -1
  29. package/build/server/chunks/server5.js +0 -52
  30. package/build/server/chunks/server5.js.map +0 -1
@@ -21261,7 +21261,10 @@ function inputLine({ input, item, label }, labelOf) {
21261
21261
  if (item?.widgetType === "text" && item.config?.maxLength) parts.push(`, at most ${item.config.maxLength} characters`);
21262
21262
  if (item?.widgetType === "checkbox" && item.config?.displayAs === "button") parts.push(", a button: true runs it once");
21263
21263
  const options = optionsOf(item);
21264
- if (options) parts.push(`, one of: ${Object.keys(options).map((k) => `"${k}"`).join(", ")}`);
21264
+ if (item?.widgetType === "dynamicValueList") {
21265
+ const defaults = Object.keys(options ?? {});
21266
+ parts.push(", options computed by the solve from other inputs: selva_solve lists the current ones" + (defaults.length ? ` (defaults: ${defaults.map((k) => `"${k}"`).join(", ")})` : ""));
21267
+ } else if (options) parts.push(`, one of: ${Object.keys(options).map((k) => `"${k}"`).join(", ")}`);
21265
21268
  if (input.default !== void 0) parts.push(`, default ${JSON.stringify(input.default)}`);
21266
21269
  const condition = conditionText(item?.visibilityCondition, labelOf);
21267
21270
  if (condition) parts.push(`, ${condition}`);
@@ -21347,7 +21350,7 @@ function resolveValues(described, given) {
21347
21350
  * them, holding `given` where the model set it and the default otherwise. Geometry, files,
21348
21351
  * colours and lists stay as the definition has them.
21349
21352
  */
21350
- function viewInputs(schema, given) {
21353
+ function viewInputs(schema, given, solved = /* @__PURE__ */ new Map()) {
21351
21354
  const inputs = [];
21352
21355
  for (const d of describeInputs(schema)) {
21353
21356
  const { input, item, label } = d;
@@ -21355,10 +21358,12 @@ function viewInputs(schema, given) {
21355
21358
  if (item?.visible === false) continue;
21356
21359
  const value = given[label] ?? given[input.nickname] ?? given[input.id] ?? input.default;
21357
21360
  const description = item?.description || input.description || void 0;
21358
- const options = optionsOf(item);
21361
+ const computed = solved.get(input.id);
21362
+ const options = computed ?? optionsOf(item);
21359
21363
  if (options) {
21360
21364
  const names = Object.keys(options);
21361
- const name = names.find((n) => n === value) ?? names.find((n) => options[n] === value);
21365
+ const same = (a, b) => typeof a === "string" && typeof b === "string" && a.toLowerCase() === b.toLowerCase();
21366
+ const name = names.find((n) => same(n, value) || same(options[n], value)) ?? (computed ? names[0] : void 0);
21362
21367
  inputs.push({
21363
21368
  name: label,
21364
21369
  kind: "choice",
@@ -21397,6 +21402,144 @@ function viewInputs(schema, given) {
21397
21402
  }
21398
21403
  return inputs;
21399
21404
  }
21405
+ // src/lib/server/mcp/readable-outputs.ts
21406
+ /** Past this many entries a list or table shows its head. */
21407
+ var MAX_ENTRIES = 50;
21408
+ var isValueListType = (type) => type.endsWith(".DynamicValueListGoo");
21409
+ var isChartType = (type) => /(^|\.)PlotlyFigure$/.test(type);
21410
+ /** Compute may quote a goo's JSON once more. */
21411
+ function decode(data) {
21412
+ let value = data;
21413
+ for (let i = 0; i < 2 && typeof value === "string"; i++) try {
21414
+ value = JSON.parse(value);
21415
+ } catch {
21416
+ return;
21417
+ }
21418
+ return value;
21419
+ }
21420
+ var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
21421
+ /**
21422
+ * Each input's options as this solve computed them, name to value, keyed by input id. Only plain
21423
+ * lists: an Options Table narrows by the picks on screen, which a static form can't follow.
21424
+ */
21425
+ function solvedOptions(schema, trees) {
21426
+ const found = /* @__PURE__ */ new Map();
21427
+ for (const tree of trees) {
21428
+ const schemaTarget = schema.outputs.find((o) => o.nickname === tree.ParamName)?.targetInputId;
21429
+ for (const item of Object.values(tree.InnerTree ?? {}).flat()) {
21430
+ if (!isValueListType(item.type)) continue;
21431
+ const payload = decode(item.data);
21432
+ if (!isRecord(payload) || !isRecord(payload.options)) continue;
21433
+ const target = typeof payload.targetInputId === "string" ? payload.targetInputId : schemaTarget;
21434
+ const options = Object.entries(payload.options).filter((e) => typeof e[1] === "string");
21435
+ if (target && options.length) found.set(target, Object.fromEntries(options));
21436
+ }
21437
+ }
21438
+ return found;
21439
+ }
21440
+ function head(list) {
21441
+ return {
21442
+ shown: list.slice(0, MAX_ENTRIES),
21443
+ more: Math.max(0, list.length - MAX_ENTRIES)
21444
+ };
21445
+ }
21446
+ var quoted = (names) => names.map((n) => JSON.stringify(n)).join(", ");
21447
+ var andMore = (more) => more ? `, and ${more} more` : "";
21448
+ /**
21449
+ * The options a Dynamic Value List output computed, by the label of the input they fill, and an
21450
+ * Options Table's valid combinations. These change with other inputs, so the form's own list is
21451
+ * only the author's defaults.
21452
+ */
21453
+ function readValueLists(schema, paramName, items) {
21454
+ const labels = new Map(describeInputs(schema).map((d) => [d.input.id, d.label]));
21455
+ const schemaTarget = schema.outputs.find((o) => o.nickname === paramName)?.targetInputId;
21456
+ const labelOf = (id) => labels.get(id) ?? id;
21457
+ const parts = [];
21458
+ const options = {};
21459
+ const combinations = [];
21460
+ for (const item of items) {
21461
+ const payload = decode(item.data);
21462
+ if (!isRecord(payload)) continue;
21463
+ const target = typeof payload.targetInputId === "string" ? payload.targetInputId : schemaTarget;
21464
+ const names = isRecord(payload.options) ? Object.keys(payload.options) : [];
21465
+ if (target && names.length) {
21466
+ const label = labelOf(target);
21467
+ const { shown, more } = head(names);
21468
+ options[label] = shown;
21469
+ parts.push(`options for "${label}": ${quoted(shown)}${andMore(more)}`);
21470
+ }
21471
+ const table = payload.pickTable;
21472
+ if (isRecord(table) && Array.isArray(table.inputs) && Array.isArray(table.rows)) {
21473
+ const columns = [...Array.isArray(table.by) ? table.by : [], ...table.inputs].map((id) => labelOf(String(id)));
21474
+ const rows = table.rows.filter(Array.isArray).map((r) => r.map(String));
21475
+ const { shown, more } = head(rows);
21476
+ combinations.push({
21477
+ inputs: columns,
21478
+ rows: shown,
21479
+ count: rows.length
21480
+ });
21481
+ parts.push(`valid combinations of ${quoted(columns)}: ` + shown.map((r) => `[${quoted(r)}]`).join(", ") + andMore(more));
21482
+ }
21483
+ }
21484
+ if (!parts.length) return void 0;
21485
+ return {
21486
+ text: parts.join("; "),
21487
+ structured: {
21488
+ ...Object.keys(options).length && { options },
21489
+ ...combinations.length && { combinations }
21490
+ }
21491
+ };
21492
+ }
21493
+ /** A trace's data as label/value pairs: pie labels, else x against y (or y against x for horizontal bars). */
21494
+ function pointsOf(trace) {
21495
+ const list = (key) => Array.isArray(trace[key]) ? trace[key] : void 0;
21496
+ if (list("labels") && list("values")) return [list("labels"), list("values")];
21497
+ const x = list("x");
21498
+ const y = list("y");
21499
+ if (x && y) return trace.orientation === "h" ? [y, x] : [x, y];
21500
+ if (y) return [y.map((_, i) => i), y];
21501
+ if (x) return [x.map((_, i) => i), x];
21502
+ }
21503
+ /** A Plotly figure's title and each trace's data. */
21504
+ function readCharts(items) {
21505
+ const parts = [];
21506
+ const charts = [];
21507
+ for (const item of items) {
21508
+ const figure = decode(item.data);
21509
+ if (!isRecord(figure) || !Array.isArray(figure.data)) continue;
21510
+ const rawTitle = (isRecord(figure.layout) ? figure.layout : {}).title;
21511
+ const title = typeof rawTitle === "string" ? rawTitle : isRecord(rawTitle) && typeof rawTitle.text === "string" ? rawTitle.text : void 0;
21512
+ const series = [];
21513
+ const traces = [];
21514
+ for (const trace of figure.data.filter(isRecord)) {
21515
+ const pairs = pointsOf(trace);
21516
+ if (!pairs) continue;
21517
+ const [labels, values] = pairs;
21518
+ const all = labels.map((l, i) => [String(l), values[i]]);
21519
+ const { shown, more } = head(all);
21520
+ const name = typeof trace.name === "string" && trace.name ? trace.name : void 0;
21521
+ const type = typeof trace.type === "string" ? trace.type : "scatter";
21522
+ series.push({
21523
+ name,
21524
+ type,
21525
+ points: shown,
21526
+ count: all.length
21527
+ });
21528
+ traces.push(`${name ? `"${name}" ` : ""}(${type}): ` + shown.map(([l, v]) => `${l} = ${JSON.stringify(v)}`).join(", ") + andMore(more));
21529
+ }
21530
+ charts.push({
21531
+ ...title && { title },
21532
+ series
21533
+ });
21534
+ const body = traces.length ? traces.join("; ") : "no data";
21535
+ parts.push(title ? `chart "${title}": ${body}` : body);
21536
+ }
21537
+ if (!charts.length) return void 0;
21538
+ return {
21539
+ text: parts.join(" | "),
21540
+ structured: { charts }
21541
+ };
21542
+ }
21400
21543
  // src/lib/server/mcp/lookup.ts
21401
21544
  var NAME_LOOKUP_PAGES = 5;
21402
21545
  var definitionArg = z.string().describe("A guid from selva_list_definitions, or the exact display name.");
@@ -21578,6 +21721,12 @@ async function summarizeSolve(res, schema, options) {
21578
21721
  lines.push(`${tree.ParamName}: ${JSON.stringify(value)}`);
21579
21722
  continue;
21580
21723
  }
21724
+ const read = items.every((i) => isValueListType(i.type)) ? readValueLists(schema, tree.ParamName, items) : items.every((i) => isChartType(i.type)) ? readCharts(items) : void 0;
21725
+ if (items.length && read) {
21726
+ structured[tree.ParamName] = read.structured;
21727
+ lines.push(`${tree.ParamName}: ${read.text}`);
21728
+ continue;
21729
+ }
21581
21730
  const counts = /* @__PURE__ */ new Map();
21582
21731
  for (const i of items) {
21583
21732
  const name = i.type.split(".").pop() ?? i.type;
@@ -21633,18 +21782,13 @@ function selvaViews() {
21633
21782
  prefersBorder: true
21634
21783
  })];
21635
21784
  }
21636
- var hdr;
21637
21785
  /**
21638
21786
  * The environment Selva's viewer lights with, as a `data:` URL: the capture page loads nothing
21639
- * from Selva's origin, which the server may not be able to reach from inside.
21787
+ * from Selva's origin, which the server may not be able to reach from inside. Inlined at build
21788
+ * time, not read with `$app/server`'s `read`: a lazily imported asset never reaches the
21789
+ * production manifest, so `read` fails there and only there.
21640
21790
  */
21641
- function captureHdr() {
21642
- hdr ??= Promise.all([import("../../../chunks/server5.js"), import("../../../chunks/baseHDR.js")]).then(async ([{ read }, { default: url }]) => {
21643
- return `data:application/octet-stream;base64,${Buffer.from(await read(url).arrayBuffer()).toString("base64")}`;
21644
- });
21645
- hdr.catch(() => hdr = void 0);
21646
- return hdr;
21647
- }
21791
+ var captureHdr = () => import("../../../chunks/baseHDR.js").then((m) => m.default);
21648
21792
  // src/lib/server/mcp/tools.ts
21649
21793
  /**
21650
21794
  * Selva's MCP tools: find a definition, read its form, solve it, read back numbers and files,
@@ -22054,6 +22198,8 @@ function selvaTools(origin, options) {
22054
22198
  });
22055
22199
  const meta = apps ? { [SOLVE_VIEW_KEY]: {
22056
22200
  title: schema.name,
22201
+ look: schema.viewerOptions?.look,
22202
+ background: schema.viewerOptions?.backgroundColor ?? DEFAULT_BACKGROUND,
22057
22203
  load: {
22058
22204
  tool: "selva_solve_geometry",
22059
22205
  arguments: { token: await stash.put({
@@ -22070,7 +22216,7 @@ function selvaTools(origin, options) {
22070
22216
  ...version && { version }
22071
22217
  },
22072
22218
  valuesKey: "values",
22073
- inputs: viewInputs(schema, values)
22219
+ inputs: viewInputs(schema, values, solvedOptions(schema, res.values ?? []))
22074
22220
  }
22075
22221
  } } : void 0;
22076
22222
  if (detail !== "full") return {