@chosengeneration/light-code 0.62.0 → 0.64.1

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/dist/cli.js CHANGED
@@ -3382,7 +3382,7 @@ var require_util2 = __commonJS({
3382
3382
  return isNonPotentiallyTrustWorthy ? "no-referrer" : referrerOrigin;
3383
3383
  }
3384
3384
  }
3385
- function stripURLForReferrer(url2, originOnly) {
3385
+ function stripURLForReferrer(url2, originOnly2) {
3386
3386
  assert2(url2 instanceof URL);
3387
3387
  if (url2.protocol === "file:" || url2.protocol === "about:" || url2.protocol === "blank:") {
3388
3388
  return "no-referrer";
@@ -3390,7 +3390,7 @@ var require_util2 = __commonJS({
3390
3390
  url2.username = "";
3391
3391
  url2.password = "";
3392
3392
  url2.hash = "";
3393
- if (originOnly) {
3393
+ if (originOnly2) {
3394
3394
  url2.pathname = "";
3395
3395
  url2.search = "";
3396
3396
  }
@@ -24303,6 +24303,49 @@ function installNodeCompat() {
24303
24303
  return { installed, nodeVersion: process.version };
24304
24304
  }
24305
24305
 
24306
+ // src/publicUrl.ts
24307
+ function publicAddressFor(port, options) {
24308
+ const env2 = options.env ?? {};
24309
+ const prefix = env2.JUPYTERHUB_SERVICE_PREFIX?.trim();
24310
+ const proxyPath = prefix === void 0 || prefix.length === 0 ? void 0 : `${withSlash(prefix)}proxy/${String(port)}/`;
24311
+ const stated = options.publicUrl?.trim();
24312
+ if (stated !== void 0 && stated.length > 0) {
24313
+ const origin = originOnly(stated);
24314
+ if (origin !== void 0 && proxyPath !== void 0) {
24315
+ return { base: `${origin}${proxyPath}`, source: "--public-url and JupyterHub" };
24316
+ }
24317
+ return { base: withSlash(stated), source: "--public-url" };
24318
+ }
24319
+ if (proxyPath === void 0) return void 0;
24320
+ const hubOrigin = (env2.JUPYTERHUB_PUBLIC_URL ?? env2.JUPYTERHUB_HOST ?? "").trim();
24321
+ if (hubOrigin.length === 0) {
24322
+ return {
24323
+ base: proxyPath,
24324
+ source: "JupyterHub \u2014 append this to the host in your browser, or give --public-url"
24325
+ };
24326
+ }
24327
+ return { base: `${trimSlash(hubOrigin)}${proxyPath}`, source: "JupyterHub" };
24328
+ }
24329
+ function originOnly(value) {
24330
+ if (!/^https?:\/\//i.test(value)) return void 0;
24331
+ try {
24332
+ const url2 = new URL(value);
24333
+ return url2.pathname === "/" || url2.pathname === "" ? url2.origin : void 0;
24334
+ } catch {
24335
+ return void 0;
24336
+ }
24337
+ }
24338
+ function publicLaunchUrl(address, adminMode, token) {
24339
+ const page = `${address.base}${adminMode ? "admin" : ""}`;
24340
+ return token.length > 0 ? `${page}#t=${token}` : page;
24341
+ }
24342
+ function withSlash(value) {
24343
+ return value.endsWith("/") ? value : `${value}/`;
24344
+ }
24345
+ function trimSlash(value) {
24346
+ return value.endsWith("/") ? value.slice(0, -1) : value;
24347
+ }
24348
+
24306
24349
  // src/cli.ts
24307
24350
  import { spawn as spawn9 } from "node:child_process";
24308
24351
  import fs26 from "node:fs/promises";
@@ -67187,6 +67230,7 @@ var NODE_ICONS = [
67187
67230
  "warning",
67188
67231
  "gear"
67189
67232
  ];
67233
+ var TEXT_SIZES = ["small", "normal", "large", "xlarge"];
67190
67234
  var NODE_SHAPES = ["box", "round", "diamond", "cylinder"];
67191
67235
  var diagramNodeSchema = external_exports.object({
67192
67236
  id: external_exports.string().min(1).max(64).describe("A short identifier, referenced by edges. Not shown."),
@@ -67195,7 +67239,10 @@ var diagramNodeSchema = external_exports.object({
67195
67239
  /** Shown under the label, smaller. For the qualifier that would otherwise bloat the label. */
67196
67240
  note: external_exports.string().max(120).optional().describe("A second, smaller line under the label."),
67197
67241
  tone: external_exports.enum(NODE_TONES).optional().describe("What the box means, as a colour: success for a good outcome, danger for a failure, warning for a risk, info for an external system, accent for the thing being explained, muted for context. Resolved against the theme, so it stays legible in light and dark."),
67198
- icon: external_exports.enum(NODE_ICONS).optional().describe("A small glyph in the corner of the box: service, database, user, file, cloud, lock, clock, queue, code, mail, check, cross, warning, gear.")
67242
+ icon: external_exports.enum(NODE_ICONS).optional().describe("A small glyph in the corner of the box: service, database, user, file, cloud, lock, clock, queue, code, mail, check, cross, warning, gear."),
67243
+ emphasis: external_exports.enum(["bold"]).optional().describe("Bold the label, for the one or two boxes the diagram is really about."),
67244
+ font: external_exports.enum(["mono"]).optional().describe("Set the label in a monospaced face. For a label that *is* an identifier \u2014 a path, a function, a table, an endpoint \u2014 where proportional text reads as prose."),
67245
+ textSize: external_exports.enum(TEXT_SIZES).optional().describe("How large this box's text is: small, normal, large or xlarge. Use it when the user asks for a particular box to be bigger, or to make the one thing the diagram is about stand out. The box grows with the text, so nothing is cut off.")
67199
67246
  });
67200
67247
  var diagramEdgeSchema = external_exports.object({
67201
67248
  from: external_exports.string().min(1).describe("The id of the node the arrow leaves."),
@@ -67212,6 +67259,7 @@ var diagramLegendSchema = external_exports.object({
67212
67259
  var DIAGRAM_MAX_LEGEND = 8;
67213
67260
  var diagramSpecSchema = external_exports.object({
67214
67261
  title: external_exports.string().max(120).optional(),
67262
+ textSize: external_exports.enum(TEXT_SIZES).optional().describe("The size for every box that does not set its own. Use it when the user says the diagram is too small or too large to read comfortably."),
67215
67263
  legend: external_exports.array(diagramLegendSchema).max(DIAGRAM_MAX_LEGEND).optional().describe("A key under the diagram. Give an entry only where the meaning is not obvious from the label \u2014 a colour that stands for something, a shape used in a particular way. Explain the diagram, not the palette."),
67216
67264
  direction: external_exports.enum(["down", "right"]).optional().describe("Which way the flow runs. down is the default and suits most flows."),
67217
67265
  nodes: external_exports.array(diagramNodeSchema).min(1).max(DIAGRAM_MAX_NODES),
@@ -67447,10 +67495,21 @@ function createShowChartTool() {
67447
67495
 
67448
67496
  // ../../packages/core/dist/diagrams/layout.js
67449
67497
  var NODE_HEIGHT = 52;
67450
- var NOTE_EXTRA = 14;
67451
67498
  var MIN_WIDTH = 96;
67452
- var MAX_WIDTH = 260;
67453
- var CHAR_WIDTH = 7.4;
67499
+ var MAX_WIDTH = 280;
67500
+ var FACE_WIDTH = { regular: 7.6, bold: 8.2, mono: 8, monoBold: 8 };
67501
+ var SIZE_SCALE = {
67502
+ small: 0.85,
67503
+ normal: 1,
67504
+ large: 1.25,
67505
+ xlarge: 1.55
67506
+ };
67507
+ var NOTE_CHAR_WIDTH = 6.4;
67508
+ var LINE_HEIGHT = 17;
67509
+ var NOTE_LINE_HEIGHT = 14;
67510
+ var LABEL_FONT_SIZE = 13;
67511
+ var NOTE_FONT_SIZE = 11;
67512
+ var PADDING_Y = 15;
67454
67513
  var PADDING_X = 28;
67455
67514
  var GAP_WITHIN_RANK = 28;
67456
67515
  var GAP_BETWEEN_RANKS = 64;
@@ -67462,9 +67521,51 @@ var SWATCH_GAP = 7;
67462
67521
  var LEGEND_ITEM_GAP = 22;
67463
67522
  var LEGEND_ROW_HEIGHT = 24;
67464
67523
  var LEGEND_TOP_GAP = 18;
67465
- function widthFor(label, note) {
67466
- const longest = Math.max(label.length, note?.length ?? 0);
67467
- return Math.min(MAX_WIDTH, Math.max(MIN_WIDTH, Math.round(longest * CHAR_WIDTH) + PADDING_X * 2));
67524
+ function wrapText(text, perLine) {
67525
+ const limit = Math.max(4, perLine);
67526
+ const lines = [];
67527
+ let current = "";
67528
+ for (const word of text.split(/\s+/).filter((part) => part.length > 0)) {
67529
+ if (current.length === 0) {
67530
+ current = word;
67531
+ } else if (current.length + 1 + word.length <= limit) {
67532
+ current = `${current} ${word}`;
67533
+ } else {
67534
+ lines.push(current);
67535
+ current = word;
67536
+ }
67537
+ while (current.length > limit) {
67538
+ lines.push(current.slice(0, limit));
67539
+ current = current.slice(limit);
67540
+ }
67541
+ }
67542
+ if (current.length > 0)
67543
+ lines.push(current);
67544
+ return lines.length > 0 ? lines : [""];
67545
+ }
67546
+ function boxFor(label, note, face = "regular", size = "normal") {
67547
+ const scale = SIZE_SCALE[size];
67548
+ const charWidth = FACE_WIDTH[face] * scale;
67549
+ const noteCharWidth = NOTE_CHAR_WIDTH * scale;
67550
+ const lineHeight = LINE_HEIGHT * scale;
67551
+ const noteLineHeight = NOTE_LINE_HEIGHT * scale;
67552
+ const ideal = Math.max(Math.round(label.length * charWidth), note === void 0 ? 0 : Math.round(note.length * noteCharWidth));
67553
+ const maxWidth = MAX_WIDTH * scale;
67554
+ const width = Math.min(maxWidth, Math.max(MIN_WIDTH, ideal + PADDING_X * 2));
67555
+ const usable = width - PADDING_X * 2;
67556
+ const lines = wrapText(label, Math.floor(usable / charWidth));
67557
+ const noteLines = note === void 0 ? [] : wrapText(note, Math.floor(usable / noteCharWidth));
67558
+ const textHeight = lines.length * lineHeight + noteLines.length * noteLineHeight;
67559
+ return {
67560
+ width,
67561
+ height: Math.max(NODE_HEIGHT * scale, textHeight + PADDING_Y * 2),
67562
+ lines,
67563
+ noteLines,
67564
+ fontSize: LABEL_FONT_SIZE * scale,
67565
+ noteFontSize: NOTE_FONT_SIZE * scale,
67566
+ lineHeight,
67567
+ noteLineHeight
67568
+ };
67468
67569
  }
67469
67570
  function backEdges(spec) {
67470
67571
  const outgoing = /* @__PURE__ */ new Map();
@@ -67557,10 +67658,10 @@ function layoutDiagram(spec) {
67557
67658
  const byId = new Map(spec.nodes.map((node) => [node.id, node]));
67558
67659
  const sizes = /* @__PURE__ */ new Map();
67559
67660
  for (const node of spec.nodes) {
67560
- sizes.set(node.id, {
67561
- width: widthFor(node.label, node.note),
67562
- height: NODE_HEIGHT + (node.note === void 0 ? 0 : NOTE_EXTRA)
67563
- });
67661
+ const bold = node.emphasis === "bold";
67662
+ const mono = node.font === "mono";
67663
+ const face = mono ? bold ? "monoBold" : "mono" : bold ? "bold" : "regular";
67664
+ sizes.set(node.id, boxFor(node.label, node.note, face, node.textSize ?? spec.textSize ?? "normal"));
67564
67665
  }
67565
67666
  const rankExtent = rows.map((row) => Math.max(...row.map((id) => sizes.get(id)?.height ?? NODE_HEIGHT)));
67566
67667
  const rowWidths = rows.map((row) => row.reduce((total, id) => total + (sizes.get(id)?.width ?? MIN_WIDTH), 0) + GAP_WITHIN_RANK * Math.max(0, row.length - 1));
@@ -67577,8 +67678,14 @@ function layoutDiagram(spec) {
67577
67678
  continue;
67578
67679
  placed.push({
67579
67680
  id,
67580
- label: node.label,
67581
- note: node.note,
67681
+ lines: size2.lines,
67682
+ noteLines: size2.noteLines,
67683
+ bold: node.emphasis === "bold",
67684
+ mono: node.font === "mono",
67685
+ fontSize: size2.fontSize,
67686
+ noteFontSize: size2.noteFontSize,
67687
+ lineHeight: size2.lineHeight,
67688
+ noteLineHeight: size2.noteLineHeight,
67582
67689
  shape: node.shape ?? "box",
67583
67690
  // A start or an end is accented unless the model said otherwise: the entry and exit of a
67584
67691
  // flow are what a reader looks for first.
@@ -67686,7 +67793,7 @@ function createShowDiagramTool() {
67686
67793
  return {
67687
67794
  name: "show_diagram",
67688
67795
  group: "always",
67689
- description: 'Draw a technical diagram for the user: a flow chart, an architecture sketch, a sequence of steps, a state machine. Give `nodes` (each with an `id` and a `label`) and `edges` between those ids \u2014 the layout is worked out for you, so do not attempt coordinates. Use it when a structure is easier seen than described: how a request travels, what calls what, where a decision branches, what happens on failure. Shapes carry the usual meanings \u2014 `round` for a start or end, `diamond` for a decision, `cylinder` for a store, and the default box for a step. Put the condition on the edge (`label: "yes"`, `label: "on timeout"`) rather than inventing a node for it, and use `style: "dashed"` for anything conditional, asynchronous or secondary. `direction: "right"` suits a pipeline; the default runs downwards and suits most flows. Loops are fine \u2014 an edge pointing back is drawn round the outside. Keep it to the boxes that earn their place: a diagram of forty is a wall, not an explanation, and the limit is a refusal rather than a truncation.',
67796
+ description: 'Draw a technical diagram for the user: a flow chart, an architecture sketch, a sequence of steps, a state machine. Give `nodes` (each with an `id` and a `label`) and `edges` between those ids \u2014 the layout is worked out for you, so do not attempt coordinates. Use it when a structure is easier seen than described: how a request travels, what calls what, where a decision branches, what happens on failure. Shapes carry the usual meanings \u2014 `round` for a start or end, `diamond` for a decision, `cylinder` for a store, and the default box for a step. Put the condition on the edge (`label: "yes"`, `label: "on timeout"`) rather than inventing a node for it, and use `style: "dashed"` for anything conditional, asynchronous or secondary. Tone colours a box by meaning \u2014 success, danger, warning, info, accent, muted \u2014 and `icon` puts a glyph in its corner. `emphasis: "bold"` for the box the diagram is really about, `font: "mono"` where the label *is* an identifier (a path, a function, a table). `textSize` is small, normal, large or xlarge, on a node for one box or on the diagram for all of them \u2014 use it when the user asks for bigger or smaller text, which they may well do; the box grows with the text so nothing is cut off. A `legend` explains what a colour or a shape stands for *in this diagram*, which is worth giving whenever the meaning is not obvious from the labels. `direction: "right"` suits a pipeline; the default runs downwards and suits most flows. Loops are fine \u2014 an edge pointing back is drawn round the outside. Keep it to the boxes that earn their place: a diagram of forty is a wall, not an explanation, and the limit is a refusal rather than a truncation.',
67690
67797
  parametersSchema: diagramSpecSchema,
67691
67798
  async execute(params) {
67692
67799
  const layout = layoutDiagram(params);
@@ -70989,7 +71096,7 @@ function respondJson(response, status, body) {
70989
71096
  }
70990
71097
 
70991
71098
  // src/cli.ts
70992
- var VERSION = true ? "0.62.0" : "unknown (not a packaged build)";
71099
+ var VERSION = true ? "0.64.1" : "unknown (not a packaged build)";
70993
71100
  var compat = installNodeCompat();
70994
71101
  function lastMeaningfulLine(problem) {
70995
71102
  const lines = problem.split(String.fromCharCode(10)).map((line) => line.trim()).filter((line) => line.length > 0 && !line.endsWith(":"));
@@ -71054,6 +71161,7 @@ Did you mean: --admin-id ${strayAdminValue.join(" --admin-id ")}
71054
71161
  const dataDir = valueOf(args, "--data-dir") ?? envPaths("light-code", { suffix: "" }).data;
71055
71162
  const port = Number.parseInt(valueOf(args, "--port") ?? "0", 10);
71056
71163
  const noToken = args.includes("--no-token");
71164
+ const publicUrl = valueOf(args, "--public-url");
71057
71165
  const allowHosts = valuesOf(args, "--allow-host");
71058
71166
  const allowOrigins = valuesOf(args, "--allow-origin");
71059
71167
  const handoffSeconds = Math.min(
@@ -71105,8 +71213,16 @@ Did you mean: --admin-id ${strayAdminValue.join(" --admin-id ")}
71105
71213
  ...credentialTool !== void 0 ? { credentialTool: { interpreter: credentialPython, file: credentialTool } } : {},
71106
71214
  handoffSeconds,
71107
71215
  noToken,
71108
- allowHosts,
71109
- allowOrigins,
71216
+ /*
71217
+ * A stated public address is trusted as a name and an origin.
71218
+ *
71219
+ * Otherwise `--public-url` would print a link that the server then refuses: the Host check
71220
+ * exists to catch DNS rebinding, and a proxy legitimately forwards the name the browser used.
71221
+ * Somebody who typed the address is telling us it is theirs, which is the same statement
71222
+ * `--allow-host` makes and this saves them making it twice.
71223
+ */
71224
+ allowHosts: [...allowHosts, ...trustedFromPublicUrl(publicUrl).hosts],
71225
+ allowOrigins: [...allowOrigins, ...trustedFromPublicUrl(publicUrl).origins],
71110
71226
  /*
71111
71227
  * A lapsed link is replaced rather than ending the session.
71112
71228
  *
@@ -71135,6 +71251,10 @@ Did you mean: --admin-id ${strayAdminValue.join(" --admin-id ")}
71135
71251
  ...bindAddress !== void 0 ? { bindAddress } : {}
71136
71252
  });
71137
71253
  const launchUrl = `${server.url}${adminMode ? "/admin" : ""}/#t=${server.launchToken ?? ""}`;
71254
+ const publicAddress = publicAddressFor(new URL(server.url).port === "" ? 80 : Number(new URL(server.url).port), {
71255
+ ...publicUrl !== void 0 ? { publicUrl } : {},
71256
+ env: process.env
71257
+ });
71138
71258
  process.stdout.write(
71139
71259
  `
71140
71260
  Light Code ${VERSION}
@@ -71143,6 +71263,14 @@ Light Code ${VERSION}
71143
71263
  listening ${server.url}
71144
71264
  `
71145
71265
  );
71266
+ const reachableUrl = publicAddress === void 0 ? noToken ? server.url : launchUrl : publicLaunchUrl(publicAddress, adminMode, noToken ? "" : server.launchToken ?? "");
71267
+ if (publicAddress !== void 0) {
71268
+ process.stdout.write(
71269
+ ` open ${reachableUrl}
71270
+ via ${publicAddress.source}
71271
+ `
71272
+ );
71273
+ }
71146
71274
  if (noToken) {
71147
71275
  process.stdout.write(
71148
71276
  ` auth none \u2014 --no-token. Any program on this machine can drive this
@@ -71211,13 +71339,20 @@ Both go through your proxy. Anyone reaching /admin directly is an administrator.
71211
71339
  * seconds sends them looking for a token that was never minted. Instructions for a
71212
71340
  * mechanism that is not running are worse than none.
71213
71341
  */
71342
+ /*
71343
+ * The *reachable* address, which on a server is not the one it binds to.
71344
+ *
71345
+ * This line is the one people copy, so printing loopback here undid the whole point of
71346
+ * working the public address out: the useful URL scrolled past above it, and the useless
71347
+ * one had the last word.
71348
+ */
71214
71349
  noToken ? `Opening ${server.url}
71215
71350
  (If the browser does not open, open this \u2014 there is no time limit:)
71216
- ${server.url}
71351
+ ${reachableUrl}
71217
71352
 
71218
71353
  ` : `Opening ${server.url}
71219
71354
  (If the browser does not open, paste this within ${String(handoffSeconds)} seconds:)
71220
- ${launchUrl}
71355
+ ${reachableUrl}
71221
71356
 
71222
71357
  ` + (handoffSeconds === 10 ? " Not long enough? Start with --handoff-seconds 120.\n If it does lapse, a fresh link is printed here \u2014 no need to restart.\n\n" : " If it does lapse, a fresh link is printed here \u2014 no need to restart.\n\n")
71223
71358
  );
@@ -71241,6 +71376,7 @@ var KNOWN_FLAGS = /* @__PURE__ */ new Set([
71241
71376
  "--data-dir",
71242
71377
  "--no-open",
71243
71378
  "--no-token",
71379
+ "--public-url",
71244
71380
  "--allow-host",
71245
71381
  "--allow-origin",
71246
71382
  "--server",
@@ -71255,6 +71391,15 @@ var KNOWN_FLAGS = /* @__PURE__ */ new Set([
71255
71391
  "--bind",
71256
71392
  "--guide"
71257
71393
  ]);
71394
+ function trustedFromPublicUrl(value) {
71395
+ if (value === void 0 || !/^https?:\/\//i.test(value.trim())) return { hosts: [], origins: [] };
71396
+ try {
71397
+ const url2 = new URL(value.trim());
71398
+ return { hosts: [url2.host], origins: [url2.origin] };
71399
+ } catch {
71400
+ return { hosts: [], origins: [] };
71401
+ }
71402
+ }
71258
71403
  function valuesOf(args, flag) {
71259
71404
  const values = [];
71260
71405
  for (let index = 0; index < args.length; index++) {
@@ -71320,6 +71465,12 @@ Usage: light-code [options]
71320
71465
  --bind <address> Interface to listen on (default: 127.0.0.1). Use 0.0.0.0 to
71321
71466
  reach it from another machine; it then answers to this
71322
71467
  machine's own hostname and addresses as well as localhost
71468
+ --public-url <u> The address this is reachable at from a browser, when that is not
71469
+ the one it binds. Printed as the link to open, and trusted as a
71470
+ host and origin.
71471
+ Under JupyterHub give only the hub's base URL \u2014 the
71472
+ /user/<you>/proxy/<port>/ part is worked out, including the
71473
+ port, which you cannot know before it starts.
71323
71474
  --allow-host <h> An extra name to answer to, e.g. a reverse proxy or a
71324
71475
  container alias (repeatable)
71325
71476
  --allow-origin <o> An extra origin allowed to call it, e.g. an app embedding