@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 +172 -21
- package/dist/client/client.js +36 -36
- package/dist/client/index.html +19 -19
- package/dist/server.js +78 -14
- package/package.json +1 -1
package/dist/client/index.html
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<title>Light Code</title>
|
|
7
|
-
<link rel="stylesheet" href="
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<!--
|
|
11
|
-
The theme variables the UI styles against are supplied by VS Code in the extension.
|
|
12
|
-
In a browser there is no host to supply them, so client.css defines the same names.
|
|
13
|
-
That keeps packages/ui identical across both hosts rather than branching on it.
|
|
14
|
-
-->
|
|
15
|
-
<div id="status" role="status"></div>
|
|
16
|
-
<div id="root"></div>
|
|
17
|
-
<script src="
|
|
18
|
-
</body>
|
|
19
|
-
</html>
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Light Code</title>
|
|
7
|
+
<link rel="stylesheet" href="client.css" />
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<!--
|
|
11
|
+
The theme variables the UI styles against are supplied by VS Code in the extension.
|
|
12
|
+
In a browser there is no host to supply them, so client.css defines the same names.
|
|
13
|
+
That keeps packages/ui identical across both hosts rather than branching on it.
|
|
14
|
+
-->
|
|
15
|
+
<div id="status" role="status"></div>
|
|
16
|
+
<div id="root"></div>
|
|
17
|
+
<script src="client.js"></script>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
package/dist/server.js
CHANGED
|
@@ -67088,6 +67088,7 @@ var NODE_ICONS = [
|
|
|
67088
67088
|
"warning",
|
|
67089
67089
|
"gear"
|
|
67090
67090
|
];
|
|
67091
|
+
var TEXT_SIZES = ["small", "normal", "large", "xlarge"];
|
|
67091
67092
|
var NODE_SHAPES = ["box", "round", "diamond", "cylinder"];
|
|
67092
67093
|
var diagramNodeSchema = external_exports.object({
|
|
67093
67094
|
id: external_exports.string().min(1).max(64).describe("A short identifier, referenced by edges. Not shown."),
|
|
@@ -67096,7 +67097,10 @@ var diagramNodeSchema = external_exports.object({
|
|
|
67096
67097
|
/** Shown under the label, smaller. For the qualifier that would otherwise bloat the label. */
|
|
67097
67098
|
note: external_exports.string().max(120).optional().describe("A second, smaller line under the label."),
|
|
67098
67099
|
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."),
|
|
67099
|
-
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.")
|
|
67100
|
+
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."),
|
|
67101
|
+
emphasis: external_exports.enum(["bold"]).optional().describe("Bold the label, for the one or two boxes the diagram is really about."),
|
|
67102
|
+
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."),
|
|
67103
|
+
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.")
|
|
67100
67104
|
});
|
|
67101
67105
|
var diagramEdgeSchema = external_exports.object({
|
|
67102
67106
|
from: external_exports.string().min(1).describe("The id of the node the arrow leaves."),
|
|
@@ -67113,6 +67117,7 @@ var diagramLegendSchema = external_exports.object({
|
|
|
67113
67117
|
var DIAGRAM_MAX_LEGEND = 8;
|
|
67114
67118
|
var diagramSpecSchema = external_exports.object({
|
|
67115
67119
|
title: external_exports.string().max(120).optional(),
|
|
67120
|
+
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."),
|
|
67116
67121
|
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."),
|
|
67117
67122
|
direction: external_exports.enum(["down", "right"]).optional().describe("Which way the flow runs. down is the default and suits most flows."),
|
|
67118
67123
|
nodes: external_exports.array(diagramNodeSchema).min(1).max(DIAGRAM_MAX_NODES),
|
|
@@ -67348,10 +67353,21 @@ function createShowChartTool() {
|
|
|
67348
67353
|
|
|
67349
67354
|
// ../../packages/core/dist/diagrams/layout.js
|
|
67350
67355
|
var NODE_HEIGHT = 52;
|
|
67351
|
-
var NOTE_EXTRA = 14;
|
|
67352
67356
|
var MIN_WIDTH = 96;
|
|
67353
|
-
var MAX_WIDTH =
|
|
67354
|
-
var
|
|
67357
|
+
var MAX_WIDTH = 280;
|
|
67358
|
+
var FACE_WIDTH = { regular: 7.6, bold: 8.2, mono: 8, monoBold: 8 };
|
|
67359
|
+
var SIZE_SCALE = {
|
|
67360
|
+
small: 0.85,
|
|
67361
|
+
normal: 1,
|
|
67362
|
+
large: 1.25,
|
|
67363
|
+
xlarge: 1.55
|
|
67364
|
+
};
|
|
67365
|
+
var NOTE_CHAR_WIDTH = 6.4;
|
|
67366
|
+
var LINE_HEIGHT = 17;
|
|
67367
|
+
var NOTE_LINE_HEIGHT = 14;
|
|
67368
|
+
var LABEL_FONT_SIZE = 13;
|
|
67369
|
+
var NOTE_FONT_SIZE = 11;
|
|
67370
|
+
var PADDING_Y = 15;
|
|
67355
67371
|
var PADDING_X = 28;
|
|
67356
67372
|
var GAP_WITHIN_RANK = 28;
|
|
67357
67373
|
var GAP_BETWEEN_RANKS = 64;
|
|
@@ -67363,9 +67379,51 @@ var SWATCH_GAP = 7;
|
|
|
67363
67379
|
var LEGEND_ITEM_GAP = 22;
|
|
67364
67380
|
var LEGEND_ROW_HEIGHT = 24;
|
|
67365
67381
|
var LEGEND_TOP_GAP = 18;
|
|
67366
|
-
function
|
|
67367
|
-
const
|
|
67368
|
-
|
|
67382
|
+
function wrapText(text, perLine) {
|
|
67383
|
+
const limit = Math.max(4, perLine);
|
|
67384
|
+
const lines = [];
|
|
67385
|
+
let current = "";
|
|
67386
|
+
for (const word of text.split(/\s+/).filter((part) => part.length > 0)) {
|
|
67387
|
+
if (current.length === 0) {
|
|
67388
|
+
current = word;
|
|
67389
|
+
} else if (current.length + 1 + word.length <= limit) {
|
|
67390
|
+
current = `${current} ${word}`;
|
|
67391
|
+
} else {
|
|
67392
|
+
lines.push(current);
|
|
67393
|
+
current = word;
|
|
67394
|
+
}
|
|
67395
|
+
while (current.length > limit) {
|
|
67396
|
+
lines.push(current.slice(0, limit));
|
|
67397
|
+
current = current.slice(limit);
|
|
67398
|
+
}
|
|
67399
|
+
}
|
|
67400
|
+
if (current.length > 0)
|
|
67401
|
+
lines.push(current);
|
|
67402
|
+
return lines.length > 0 ? lines : [""];
|
|
67403
|
+
}
|
|
67404
|
+
function boxFor(label, note, face = "regular", size = "normal") {
|
|
67405
|
+
const scale = SIZE_SCALE[size];
|
|
67406
|
+
const charWidth = FACE_WIDTH[face] * scale;
|
|
67407
|
+
const noteCharWidth = NOTE_CHAR_WIDTH * scale;
|
|
67408
|
+
const lineHeight = LINE_HEIGHT * scale;
|
|
67409
|
+
const noteLineHeight = NOTE_LINE_HEIGHT * scale;
|
|
67410
|
+
const ideal = Math.max(Math.round(label.length * charWidth), note === void 0 ? 0 : Math.round(note.length * noteCharWidth));
|
|
67411
|
+
const maxWidth = MAX_WIDTH * scale;
|
|
67412
|
+
const width = Math.min(maxWidth, Math.max(MIN_WIDTH, ideal + PADDING_X * 2));
|
|
67413
|
+
const usable = width - PADDING_X * 2;
|
|
67414
|
+
const lines = wrapText(label, Math.floor(usable / charWidth));
|
|
67415
|
+
const noteLines = note === void 0 ? [] : wrapText(note, Math.floor(usable / noteCharWidth));
|
|
67416
|
+
const textHeight = lines.length * lineHeight + noteLines.length * noteLineHeight;
|
|
67417
|
+
return {
|
|
67418
|
+
width,
|
|
67419
|
+
height: Math.max(NODE_HEIGHT * scale, textHeight + PADDING_Y * 2),
|
|
67420
|
+
lines,
|
|
67421
|
+
noteLines,
|
|
67422
|
+
fontSize: LABEL_FONT_SIZE * scale,
|
|
67423
|
+
noteFontSize: NOTE_FONT_SIZE * scale,
|
|
67424
|
+
lineHeight,
|
|
67425
|
+
noteLineHeight
|
|
67426
|
+
};
|
|
67369
67427
|
}
|
|
67370
67428
|
function backEdges(spec) {
|
|
67371
67429
|
const outgoing = /* @__PURE__ */ new Map();
|
|
@@ -67458,10 +67516,10 @@ function layoutDiagram(spec) {
|
|
|
67458
67516
|
const byId = new Map(spec.nodes.map((node) => [node.id, node]));
|
|
67459
67517
|
const sizes = /* @__PURE__ */ new Map();
|
|
67460
67518
|
for (const node of spec.nodes) {
|
|
67461
|
-
|
|
67462
|
-
|
|
67463
|
-
|
|
67464
|
-
|
|
67519
|
+
const bold = node.emphasis === "bold";
|
|
67520
|
+
const mono = node.font === "mono";
|
|
67521
|
+
const face = mono ? bold ? "monoBold" : "mono" : bold ? "bold" : "regular";
|
|
67522
|
+
sizes.set(node.id, boxFor(node.label, node.note, face, node.textSize ?? spec.textSize ?? "normal"));
|
|
67465
67523
|
}
|
|
67466
67524
|
const rankExtent = rows.map((row) => Math.max(...row.map((id) => sizes.get(id)?.height ?? NODE_HEIGHT)));
|
|
67467
67525
|
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));
|
|
@@ -67478,8 +67536,14 @@ function layoutDiagram(spec) {
|
|
|
67478
67536
|
continue;
|
|
67479
67537
|
placed.push({
|
|
67480
67538
|
id,
|
|
67481
|
-
|
|
67482
|
-
|
|
67539
|
+
lines: size2.lines,
|
|
67540
|
+
noteLines: size2.noteLines,
|
|
67541
|
+
bold: node.emphasis === "bold",
|
|
67542
|
+
mono: node.font === "mono",
|
|
67543
|
+
fontSize: size2.fontSize,
|
|
67544
|
+
noteFontSize: size2.noteFontSize,
|
|
67545
|
+
lineHeight: size2.lineHeight,
|
|
67546
|
+
noteLineHeight: size2.noteLineHeight,
|
|
67483
67547
|
shape: node.shape ?? "box",
|
|
67484
67548
|
// A start or an end is accented unless the model said otherwise: the entry and exit of a
|
|
67485
67549
|
// flow are what a reader looks for first.
|
|
@@ -67587,7 +67651,7 @@ function createShowDiagramTool() {
|
|
|
67587
67651
|
return {
|
|
67588
67652
|
name: "show_diagram",
|
|
67589
67653
|
group: "always",
|
|
67590
|
-
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.',
|
|
67654
|
+
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.',
|
|
67591
67655
|
parametersSchema: diagramSpecSchema,
|
|
67592
67656
|
async execute(params) {
|
|
67593
67657
|
const layout = layoutDiagram(params);
|