@chosengeneration/light-code 0.60.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 +559 -19
- package/dist/client/client.js +67 -67
- package/dist/client/index.html +19 -19
- package/dist/server.js +465 -12
- 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
|
@@ -48207,15 +48207,15 @@ ${record2.preview}`.toLowerCase();
|
|
|
48207
48207
|
const hits = await options.semantic.searcher.searchByVector(options.semantic.collection, vector, {
|
|
48208
48208
|
size: Math.min(100, Math.max(limit * 4, 40))
|
|
48209
48209
|
});
|
|
48210
|
-
const
|
|
48210
|
+
const rank3 = /* @__PURE__ */ new Map();
|
|
48211
48211
|
hits.forEach((hit, position) => {
|
|
48212
48212
|
const id = hit.path.startsWith("mail:") ? hit.path.slice("mail:".length) : hit.path;
|
|
48213
|
-
if (!
|
|
48214
|
-
|
|
48213
|
+
if (!rank3.has(id))
|
|
48214
|
+
rank3.set(id, position);
|
|
48215
48215
|
});
|
|
48216
48216
|
ordered = [...candidates].sort((a, b) => {
|
|
48217
|
-
const left =
|
|
48218
|
-
const right =
|
|
48217
|
+
const left = rank3.get(a.id);
|
|
48218
|
+
const right = rank3.get(b.id);
|
|
48219
48219
|
if (left !== void 0 && right !== void 0)
|
|
48220
48220
|
return left - right;
|
|
48221
48221
|
if (left !== void 0)
|
|
@@ -60862,8 +60862,8 @@ function coerceFormValue(field, raw) {
|
|
|
60862
60862
|
if (field.required !== false && chosen.length === 0) {
|
|
60863
60863
|
return { error: `"${field.label}" needs at least one selection.` };
|
|
60864
60864
|
}
|
|
60865
|
-
const
|
|
60866
|
-
return { value:
|
|
60865
|
+
const order2 = (field.options ?? []).map((option) => option.value);
|
|
60866
|
+
return { value: order2.filter((value) => chosen.includes(value)) };
|
|
60867
60867
|
}
|
|
60868
60868
|
if (field.type === "number") {
|
|
60869
60869
|
const parsed = typeof raw === "number" ? raw : Number(String(raw ?? "").trim());
|
|
@@ -62785,6 +62785,8 @@ ${direction}` : attachMentions(text, mentions);
|
|
|
62785
62785
|
return;
|
|
62786
62786
|
if (chartFromToolCall(toolCall.name, toolCall.arguments) !== void 0)
|
|
62787
62787
|
return;
|
|
62788
|
+
if (diagramFromToolCall(toolCall.name, toolCall.arguments) !== void 0)
|
|
62789
|
+
return;
|
|
62788
62790
|
const summary = toolCallSummary(toolCall);
|
|
62789
62791
|
post({
|
|
62790
62792
|
type: "toolCall",
|
|
@@ -62797,6 +62799,15 @@ ${direction}` : attachMentions(text, mentions);
|
|
|
62797
62799
|
post({ type: "textChunk", text: result.content });
|
|
62798
62800
|
return;
|
|
62799
62801
|
}
|
|
62802
|
+
const diagram = diagramFromToolCall(toolCall.name, toolCall.arguments);
|
|
62803
|
+
if (diagram !== void 0) {
|
|
62804
|
+
post(diagram.kind === "diagram" ? {
|
|
62805
|
+
type: "diagram",
|
|
62806
|
+
diagram: diagram.diagram,
|
|
62807
|
+
...informedBy !== void 0 ? { expertInformed: true, informedBy } : {}
|
|
62808
|
+
} : { type: "diagramError", message: diagram.message });
|
|
62809
|
+
return;
|
|
62810
|
+
}
|
|
62800
62811
|
const chart = chartFromToolCall(toolCall.name, toolCall.arguments);
|
|
62801
62812
|
if (chart !== void 0) {
|
|
62802
62813
|
post(chart.kind === "chart" ? {
|
|
@@ -66450,6 +66461,22 @@ ${entry.content}`);
|
|
|
66450
66461
|
lines.push(`## Chart
|
|
66451
66462
|
|
|
66452
66463
|
Could not be drawn: ${entry.message}`);
|
|
66464
|
+
} else if (entry.kind === "diagramError") {
|
|
66465
|
+
lines.push(`## Diagram
|
|
66466
|
+
|
|
66467
|
+
Could not be drawn: ${entry.message}`);
|
|
66468
|
+
} else if (entry.kind === "diagram") {
|
|
66469
|
+
const diagram = entry.diagram;
|
|
66470
|
+
const labels = new Map(diagram.nodes.map((node) => [node.id, node.label]));
|
|
66471
|
+
lines.push([
|
|
66472
|
+
`## ${diagram.title ?? "Diagram"}`,
|
|
66473
|
+
"",
|
|
66474
|
+
...diagram.edges.map((edge) => {
|
|
66475
|
+
const via = edge.label === void 0 ? "" : ` \u2014 ${edge.label}`;
|
|
66476
|
+
return `- ${labels.get(edge.from) ?? edge.from} \u2192 ${labels.get(edge.to) ?? edge.to}${via}`;
|
|
66477
|
+
}),
|
|
66478
|
+
...diagram.note === void 0 ? [] : ["", diagram.note]
|
|
66479
|
+
].join("\n"));
|
|
66453
66480
|
} else {
|
|
66454
66481
|
const call = entry.toolCall;
|
|
66455
66482
|
lines.push([
|
|
@@ -67033,6 +67060,104 @@ function chartTotals(spec) {
|
|
|
67033
67060
|
return { series, grand: series.reduce((sum, entry) => sum + entry.total, 0) };
|
|
67034
67061
|
}
|
|
67035
67062
|
|
|
67063
|
+
// ../../packages/core/dist/diagrams/types.js
|
|
67064
|
+
var DIAGRAM_MAX_NODES = 40;
|
|
67065
|
+
var DIAGRAM_MAX_EDGES = 80;
|
|
67066
|
+
var NODE_TONES = [
|
|
67067
|
+
"neutral",
|
|
67068
|
+
"accent",
|
|
67069
|
+
"info",
|
|
67070
|
+
"success",
|
|
67071
|
+
"warning",
|
|
67072
|
+
"danger",
|
|
67073
|
+
"muted"
|
|
67074
|
+
];
|
|
67075
|
+
var NODE_ICONS = [
|
|
67076
|
+
"service",
|
|
67077
|
+
"database",
|
|
67078
|
+
"user",
|
|
67079
|
+
"file",
|
|
67080
|
+
"cloud",
|
|
67081
|
+
"lock",
|
|
67082
|
+
"clock",
|
|
67083
|
+
"queue",
|
|
67084
|
+
"code",
|
|
67085
|
+
"mail",
|
|
67086
|
+
"check",
|
|
67087
|
+
"cross",
|
|
67088
|
+
"warning",
|
|
67089
|
+
"gear"
|
|
67090
|
+
];
|
|
67091
|
+
var TEXT_SIZES = ["small", "normal", "large", "xlarge"];
|
|
67092
|
+
var NODE_SHAPES = ["box", "round", "diamond", "cylinder"];
|
|
67093
|
+
var diagramNodeSchema = external_exports.object({
|
|
67094
|
+
id: external_exports.string().min(1).max(64).describe("A short identifier, referenced by edges. Not shown."),
|
|
67095
|
+
label: external_exports.string().min(1).max(120).describe("The text in the box. Keep it to a few words."),
|
|
67096
|
+
shape: external_exports.enum(NODE_SHAPES).optional().describe("box (a step, the default), round (a start or end), diamond (a decision), cylinder (a store or database)."),
|
|
67097
|
+
/** Shown under the label, smaller. For the qualifier that would otherwise bloat the label. */
|
|
67098
|
+
note: external_exports.string().max(120).optional().describe("A second, smaller line under the label."),
|
|
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."),
|
|
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.")
|
|
67104
|
+
});
|
|
67105
|
+
var diagramEdgeSchema = external_exports.object({
|
|
67106
|
+
from: external_exports.string().min(1).describe("The id of the node the arrow leaves."),
|
|
67107
|
+
to: external_exports.string().min(1).describe("The id of the node the arrow enters."),
|
|
67108
|
+
label: external_exports.string().max(60).optional().describe('Text on the arrow \u2014 the condition, or what flows along it. "yes", "on failure".'),
|
|
67109
|
+
style: external_exports.enum(["solid", "dashed"]).optional().describe("dashed for something conditional, asynchronous or secondary.")
|
|
67110
|
+
});
|
|
67111
|
+
var diagramLegendSchema = external_exports.object({
|
|
67112
|
+
label: external_exports.string().min(1).max(80).describe("What this appearance means in this diagram."),
|
|
67113
|
+
tone: external_exports.enum(NODE_TONES).optional(),
|
|
67114
|
+
shape: external_exports.enum(NODE_SHAPES).optional(),
|
|
67115
|
+
icon: external_exports.enum(NODE_ICONS).optional()
|
|
67116
|
+
});
|
|
67117
|
+
var DIAGRAM_MAX_LEGEND = 8;
|
|
67118
|
+
var diagramSpecSchema = external_exports.object({
|
|
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."),
|
|
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."),
|
|
67122
|
+
direction: external_exports.enum(["down", "right"]).optional().describe("Which way the flow runs. down is the default and suits most flows."),
|
|
67123
|
+
nodes: external_exports.array(diagramNodeSchema).min(1).max(DIAGRAM_MAX_NODES),
|
|
67124
|
+
edges: external_exports.array(diagramEdgeSchema).max(DIAGRAM_MAX_EDGES),
|
|
67125
|
+
note: external_exports.string().max(400).optional().describe("A line under the diagram. Say what it leaves out, or where it came from.")
|
|
67126
|
+
}).superRefine((spec, context) => {
|
|
67127
|
+
const ids = /* @__PURE__ */ new Set();
|
|
67128
|
+
for (const [index, node] of spec.nodes.entries()) {
|
|
67129
|
+
if (ids.has(node.id)) {
|
|
67130
|
+
context.addIssue({
|
|
67131
|
+
code: "custom",
|
|
67132
|
+
path: ["nodes", index, "id"],
|
|
67133
|
+
/*
|
|
67134
|
+
* Named rather than de-duplicated. Two nodes sharing an id means the edges meant for one
|
|
67135
|
+
* of them are pointing at the other, and silently keeping the first would draw a diagram
|
|
67136
|
+
* that is wrong in a way nobody can see.
|
|
67137
|
+
*/
|
|
67138
|
+
message: `Two nodes share the id "${node.id}". Ids must be unique \u2014 edges are resolved by them.`
|
|
67139
|
+
});
|
|
67140
|
+
}
|
|
67141
|
+
ids.add(node.id);
|
|
67142
|
+
}
|
|
67143
|
+
for (const [index, edge] of spec.edges.entries()) {
|
|
67144
|
+
for (const [end, id] of [
|
|
67145
|
+
["from", edge.from],
|
|
67146
|
+
["to", edge.to]
|
|
67147
|
+
]) {
|
|
67148
|
+
if (!ids.has(id)) {
|
|
67149
|
+
context.addIssue({
|
|
67150
|
+
code: "custom",
|
|
67151
|
+
path: ["edges", index, end],
|
|
67152
|
+
// The available ids are listed: the usual cause is a typo, and a message that names
|
|
67153
|
+
// the candidates is one the model can act on without another round trip.
|
|
67154
|
+
message: `No node has the id "${id}". Known ids: ${[...ids].join(", ")}.`
|
|
67155
|
+
});
|
|
67156
|
+
}
|
|
67157
|
+
}
|
|
67158
|
+
}
|
|
67159
|
+
});
|
|
67160
|
+
|
|
67036
67161
|
// ../../packages/core/dist/history/transcript.js
|
|
67037
67162
|
var CONTROL_TOOLS = /* @__PURE__ */ new Set([
|
|
67038
67163
|
"attempt_completion",
|
|
@@ -67142,6 +67267,16 @@ function consultationFromToolCall(name, rawArguments) {
|
|
|
67142
67267
|
const role = typeof decoded === "object" && decoded !== null ? decoded.role : void 0;
|
|
67143
67268
|
return typeof role === "string" && role.trim().length > 0 ? role.trim().toLowerCase() : "unknown";
|
|
67144
67269
|
}
|
|
67270
|
+
function diagramFromToolCall(name, rawArguments) {
|
|
67271
|
+
const call = throughDispatch(name, rawArguments);
|
|
67272
|
+
if (call.name !== "show_diagram")
|
|
67273
|
+
return void 0;
|
|
67274
|
+
const parsed = diagramSpecSchema.safeParse(call.args);
|
|
67275
|
+
return parsed.success ? { kind: "diagram", diagram: parsed.data } : {
|
|
67276
|
+
kind: "diagramError",
|
|
67277
|
+
message: parsed.error.issues.map((issue2) => `${issue2.path.join(".")}: ${issue2.message}`).join("; ")
|
|
67278
|
+
};
|
|
67279
|
+
}
|
|
67145
67280
|
function chartFromToolCall(name, rawArguments) {
|
|
67146
67281
|
const call = throughDispatch(name, rawArguments);
|
|
67147
67282
|
if (call.name !== "show_chart")
|
|
@@ -67216,6 +67351,323 @@ function createShowChartTool() {
|
|
|
67216
67351
|
};
|
|
67217
67352
|
}
|
|
67218
67353
|
|
|
67354
|
+
// ../../packages/core/dist/diagrams/layout.js
|
|
67355
|
+
var NODE_HEIGHT = 52;
|
|
67356
|
+
var MIN_WIDTH = 96;
|
|
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;
|
|
67371
|
+
var PADDING_X = 28;
|
|
67372
|
+
var GAP_WITHIN_RANK = 28;
|
|
67373
|
+
var GAP_BETWEEN_RANKS = 64;
|
|
67374
|
+
var MARGIN = 28;
|
|
67375
|
+
var TITLE_HEIGHT = 40;
|
|
67376
|
+
var SWATCH_WIDTH = 26;
|
|
67377
|
+
var SWATCH_HEIGHT = 16;
|
|
67378
|
+
var SWATCH_GAP = 7;
|
|
67379
|
+
var LEGEND_ITEM_GAP = 22;
|
|
67380
|
+
var LEGEND_ROW_HEIGHT = 24;
|
|
67381
|
+
var LEGEND_TOP_GAP = 18;
|
|
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
|
+
};
|
|
67427
|
+
}
|
|
67428
|
+
function backEdges(spec) {
|
|
67429
|
+
const outgoing = /* @__PURE__ */ new Map();
|
|
67430
|
+
for (const [index, edge] of spec.edges.entries()) {
|
|
67431
|
+
const list = outgoing.get(edge.from) ?? [];
|
|
67432
|
+
list.push({ to: edge.to, index });
|
|
67433
|
+
outgoing.set(edge.from, list);
|
|
67434
|
+
}
|
|
67435
|
+
const back = /* @__PURE__ */ new Set();
|
|
67436
|
+
const state = /* @__PURE__ */ new Map();
|
|
67437
|
+
const visit = (id) => {
|
|
67438
|
+
state.set(id, "open");
|
|
67439
|
+
for (const edge of outgoing.get(id) ?? []) {
|
|
67440
|
+
const seen = state.get(edge.to);
|
|
67441
|
+
if (seen === "open")
|
|
67442
|
+
back.add(edge.index);
|
|
67443
|
+
else if (seen === void 0)
|
|
67444
|
+
visit(edge.to);
|
|
67445
|
+
}
|
|
67446
|
+
state.set(id, "done");
|
|
67447
|
+
};
|
|
67448
|
+
for (const node of spec.nodes)
|
|
67449
|
+
if (!state.has(node.id))
|
|
67450
|
+
visit(node.id);
|
|
67451
|
+
return back;
|
|
67452
|
+
}
|
|
67453
|
+
function rank2(spec, back) {
|
|
67454
|
+
const incoming = /* @__PURE__ */ new Map();
|
|
67455
|
+
for (const node of spec.nodes)
|
|
67456
|
+
incoming.set(node.id, []);
|
|
67457
|
+
for (const [index, edge] of spec.edges.entries()) {
|
|
67458
|
+
if (back.has(index))
|
|
67459
|
+
continue;
|
|
67460
|
+
incoming.get(edge.to)?.push(edge.from);
|
|
67461
|
+
}
|
|
67462
|
+
const ranks = /* @__PURE__ */ new Map();
|
|
67463
|
+
const resolving = /* @__PURE__ */ new Set();
|
|
67464
|
+
const rankOf = (id) => {
|
|
67465
|
+
const known = ranks.get(id);
|
|
67466
|
+
if (known !== void 0)
|
|
67467
|
+
return known;
|
|
67468
|
+
if (resolving.has(id))
|
|
67469
|
+
return 0;
|
|
67470
|
+
resolving.add(id);
|
|
67471
|
+
const parents = incoming.get(id) ?? [];
|
|
67472
|
+
const depth = parents.length === 0 ? 0 : Math.max(...parents.map((parent) => rankOf(parent) + 1));
|
|
67473
|
+
resolving.delete(id);
|
|
67474
|
+
ranks.set(id, depth);
|
|
67475
|
+
return depth;
|
|
67476
|
+
};
|
|
67477
|
+
for (const node of spec.nodes)
|
|
67478
|
+
rankOf(node.id);
|
|
67479
|
+
return ranks;
|
|
67480
|
+
}
|
|
67481
|
+
function order(spec, ranks, back) {
|
|
67482
|
+
const byRank = [];
|
|
67483
|
+
for (const node of spec.nodes) {
|
|
67484
|
+
const depth = ranks.get(node.id) ?? 0;
|
|
67485
|
+
while (byRank.length <= depth)
|
|
67486
|
+
byRank.push([]);
|
|
67487
|
+
byRank[depth]?.push(node.id);
|
|
67488
|
+
}
|
|
67489
|
+
const parents = /* @__PURE__ */ new Map();
|
|
67490
|
+
for (const [index, edge] of spec.edges.entries()) {
|
|
67491
|
+
if (back.has(index))
|
|
67492
|
+
continue;
|
|
67493
|
+
const list = parents.get(edge.to) ?? [];
|
|
67494
|
+
list.push(edge.from);
|
|
67495
|
+
parents.set(edge.to, list);
|
|
67496
|
+
}
|
|
67497
|
+
for (let depth = 1; depth < byRank.length; depth += 1) {
|
|
67498
|
+
const above = byRank[depth - 1] ?? [];
|
|
67499
|
+
const positions = new Map(above.map((id, index) => [id, index]));
|
|
67500
|
+
const row = byRank[depth] ?? [];
|
|
67501
|
+
const keyed = row.map((id, index) => {
|
|
67502
|
+
const known = (parents.get(id) ?? []).map((parent) => positions.get(parent)).filter((value) => value !== void 0);
|
|
67503
|
+
const barycentre = known.length === 0 ? index : known.reduce((a, b) => a + b, 0) / known.length;
|
|
67504
|
+
return { id, barycentre, index };
|
|
67505
|
+
});
|
|
67506
|
+
keyed.sort((a, b) => a.barycentre - b.barycentre || a.index - b.index);
|
|
67507
|
+
byRank[depth] = keyed.map((entry) => entry.id);
|
|
67508
|
+
}
|
|
67509
|
+
return byRank;
|
|
67510
|
+
}
|
|
67511
|
+
function layoutDiagram(spec) {
|
|
67512
|
+
const sideways = spec.direction === "right";
|
|
67513
|
+
const back = backEdges(spec);
|
|
67514
|
+
const ranks = rank2(spec, back);
|
|
67515
|
+
const rows = order(spec, ranks, back);
|
|
67516
|
+
const byId = new Map(spec.nodes.map((node) => [node.id, node]));
|
|
67517
|
+
const sizes = /* @__PURE__ */ new Map();
|
|
67518
|
+
for (const node of spec.nodes) {
|
|
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"));
|
|
67523
|
+
}
|
|
67524
|
+
const rankExtent = rows.map((row) => Math.max(...row.map((id) => sizes.get(id)?.height ?? NODE_HEIGHT)));
|
|
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));
|
|
67526
|
+
const widest = Math.max(...rowWidths, 1);
|
|
67527
|
+
const placed = [];
|
|
67528
|
+
let cursor = MARGIN + (spec.title === void 0 ? 0 : TITLE_HEIGHT);
|
|
67529
|
+
for (const [depth, row] of rows.entries()) {
|
|
67530
|
+
const extent = rankExtent[depth] ?? NODE_HEIGHT;
|
|
67531
|
+
let x = MARGIN + (widest - (rowWidths[depth] ?? 0)) / 2;
|
|
67532
|
+
for (const id of row) {
|
|
67533
|
+
const node = byId.get(id);
|
|
67534
|
+
const size2 = sizes.get(id);
|
|
67535
|
+
if (node === void 0 || size2 === void 0)
|
|
67536
|
+
continue;
|
|
67537
|
+
placed.push({
|
|
67538
|
+
id,
|
|
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,
|
|
67547
|
+
shape: node.shape ?? "box",
|
|
67548
|
+
// A start or an end is accented unless the model said otherwise: the entry and exit of a
|
|
67549
|
+
// flow are what a reader looks for first.
|
|
67550
|
+
tone: node.tone ?? (node.shape === "round" ? "accent" : "neutral"),
|
|
67551
|
+
icon: node.icon,
|
|
67552
|
+
x,
|
|
67553
|
+
// Centred in its rank, so a tall box beside a short one does not look misaligned.
|
|
67554
|
+
y: cursor + (extent - size2.height) / 2,
|
|
67555
|
+
width: size2.width,
|
|
67556
|
+
height: size2.height
|
|
67557
|
+
});
|
|
67558
|
+
x += size2.width + GAP_WITHIN_RANK;
|
|
67559
|
+
}
|
|
67560
|
+
cursor += extent + GAP_BETWEEN_RANKS;
|
|
67561
|
+
}
|
|
67562
|
+
const upright = {
|
|
67563
|
+
width: widest + MARGIN * 2,
|
|
67564
|
+
height: cursor - GAP_BETWEEN_RANKS + MARGIN
|
|
67565
|
+
};
|
|
67566
|
+
const nodes = sideways ? placed.map((node) => ({
|
|
67567
|
+
...node,
|
|
67568
|
+
x: node.y,
|
|
67569
|
+
y: node.x
|
|
67570
|
+
// Size is not transposed: a box swapping its width for its height would wrap its text.
|
|
67571
|
+
})) : placed;
|
|
67572
|
+
const size = sideways ? { width: upright.height, height: upright.width } : { width: upright.width, height: upright.height };
|
|
67573
|
+
const positions = new Map(nodes.map((node) => [node.id, node]));
|
|
67574
|
+
const edges = spec.edges.flatMap((edge, index) => {
|
|
67575
|
+
const from = positions.get(edge.from);
|
|
67576
|
+
const to = positions.get(edge.to);
|
|
67577
|
+
if (from === void 0 || to === void 0)
|
|
67578
|
+
return [];
|
|
67579
|
+
const start = sideways ? { x: from.x + from.width, y: from.y + from.height / 2 } : { x: from.x + from.width / 2, y: from.y + from.height };
|
|
67580
|
+
const end = sideways ? { x: to.x, y: to.y + to.height / 2 } : { x: to.x + to.width / 2, y: to.y };
|
|
67581
|
+
const isBack = back.has(index);
|
|
67582
|
+
const points = isBack ? sideways ? [
|
|
67583
|
+
{ x: from.x + from.width / 2, y: from.y + from.height },
|
|
67584
|
+
{ x: from.x + from.width / 2, y: size.height - MARGIN / 2 },
|
|
67585
|
+
{ x: to.x + to.width / 2, y: size.height - MARGIN / 2 },
|
|
67586
|
+
{ x: to.x + to.width / 2, y: to.y + to.height }
|
|
67587
|
+
] : [
|
|
67588
|
+
{ x: from.x + from.width, y: from.y + from.height / 2 },
|
|
67589
|
+
{ x: size.width - MARGIN / 2, y: from.y + from.height / 2 },
|
|
67590
|
+
{ x: size.width - MARGIN / 2, y: to.y + to.height / 2 },
|
|
67591
|
+
{ x: to.x + to.width, y: to.y + to.height / 2 }
|
|
67592
|
+
] : [start, end];
|
|
67593
|
+
const midpoint = points.length === 2 ? 0 : 1;
|
|
67594
|
+
const a = points[midpoint] ?? start;
|
|
67595
|
+
const b = points[midpoint + 1] ?? end;
|
|
67596
|
+
return [
|
|
67597
|
+
{
|
|
67598
|
+
from: edge.from,
|
|
67599
|
+
to: edge.to,
|
|
67600
|
+
label: edge.label,
|
|
67601
|
+
dashed: edge.style === "dashed",
|
|
67602
|
+
points,
|
|
67603
|
+
labelAt: { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 }
|
|
67604
|
+
}
|
|
67605
|
+
];
|
|
67606
|
+
});
|
|
67607
|
+
const legend = [];
|
|
67608
|
+
let legendHeight = 0;
|
|
67609
|
+
let canvasWidth = size.width;
|
|
67610
|
+
if (spec.legend !== void 0 && spec.legend.length > 0) {
|
|
67611
|
+
const entryWidths = spec.legend.map((entry) => SWATCH_WIDTH + SWATCH_GAP + Math.round(entry.label.length * 6.6));
|
|
67612
|
+
const available = Math.max(size.width - MARGIN * 2, Math.max(...entryWidths));
|
|
67613
|
+
let x = MARGIN;
|
|
67614
|
+
let y = size.height + LEGEND_TOP_GAP;
|
|
67615
|
+
let rows2 = 1;
|
|
67616
|
+
for (const [index, entry] of spec.legend.entries()) {
|
|
67617
|
+
const entryWidth = entryWidths[index] ?? 0;
|
|
67618
|
+
if (x > MARGIN && x + entryWidth - MARGIN > available) {
|
|
67619
|
+
x = MARGIN;
|
|
67620
|
+
y += LEGEND_ROW_HEIGHT;
|
|
67621
|
+
rows2 += 1;
|
|
67622
|
+
}
|
|
67623
|
+
legend.push({
|
|
67624
|
+
label: entry.label,
|
|
67625
|
+
shape: entry.shape ?? "box",
|
|
67626
|
+
tone: entry.tone ?? "neutral",
|
|
67627
|
+
icon: entry.icon,
|
|
67628
|
+
x,
|
|
67629
|
+
y,
|
|
67630
|
+
swatchWidth: SWATCH_WIDTH,
|
|
67631
|
+
swatchHeight: SWATCH_HEIGHT
|
|
67632
|
+
});
|
|
67633
|
+
x += entryWidth + LEGEND_ITEM_GAP;
|
|
67634
|
+
canvasWidth = Math.max(canvasWidth, x - LEGEND_ITEM_GAP + MARGIN);
|
|
67635
|
+
}
|
|
67636
|
+
legendHeight = LEGEND_TOP_GAP + rows2 * LEGEND_ROW_HEIGHT;
|
|
67637
|
+
}
|
|
67638
|
+
return {
|
|
67639
|
+
width: canvasWidth,
|
|
67640
|
+
height: size.height + legendHeight,
|
|
67641
|
+
title: spec.title,
|
|
67642
|
+
note: spec.note,
|
|
67643
|
+
nodes,
|
|
67644
|
+
edges,
|
|
67645
|
+
legend
|
|
67646
|
+
};
|
|
67647
|
+
}
|
|
67648
|
+
|
|
67649
|
+
// ../../packages/core/dist/tools/showDiagram.js
|
|
67650
|
+
function createShowDiagramTool() {
|
|
67651
|
+
return {
|
|
67652
|
+
name: "show_diagram",
|
|
67653
|
+
group: "always",
|
|
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.',
|
|
67655
|
+
parametersSchema: diagramSpecSchema,
|
|
67656
|
+
async execute(params) {
|
|
67657
|
+
const layout = layoutDiagram(params);
|
|
67658
|
+
const ranks = new Set(layout.nodes.map((node) => node.y)).size;
|
|
67659
|
+
const unreachable = params.nodes.filter((node) => node.id !== params.nodes[0]?.id && !params.edges.some((edge) => edge.to === node.id || edge.from === node.id));
|
|
67660
|
+
return {
|
|
67661
|
+
content: [
|
|
67662
|
+
`Drew a diagram${params.title === void 0 ? "" : ` titled "${params.title}"`} with ${String(params.nodes.length)} node(s) and ${String(params.edges.length)} edge(s), across ${String(ranks)} level(s), running ${params.direction ?? "down"}.`,
|
|
67663
|
+
unreachable.length === 0 ? "" : `${String(unreachable.length)} node(s) have no edges at all and float unconnected: ${unreachable.map((node) => node.id).join(", ")}. Connect them or drop them.`,
|
|
67664
|
+
"The diagram is now in the conversation. Describe what it shows rather than listing the boxes again \u2014 they are on screen."
|
|
67665
|
+
].filter((line) => line !== "").join("\n")
|
|
67666
|
+
};
|
|
67667
|
+
}
|
|
67668
|
+
};
|
|
67669
|
+
}
|
|
67670
|
+
|
|
67219
67671
|
// ../../packages/core/dist/tools/applyDiff/eol.js
|
|
67220
67672
|
function detectEol(text) {
|
|
67221
67673
|
const crlfCount = (text.match(/\r\n/g) ?? []).length;
|
|
@@ -67925,6 +68377,7 @@ function createDefaultToolRegistry() {
|
|
|
67925
68377
|
registry2.register(askFollowupQuestionTool);
|
|
67926
68378
|
registry2.register(createAskUserFormTool());
|
|
67927
68379
|
registry2.register(createShowChartTool());
|
|
68380
|
+
registry2.register(createShowDiagramTool());
|
|
67928
68381
|
registry2.register(attemptCompletionTool);
|
|
67929
68382
|
return registry2;
|
|
67930
68383
|
}
|
|
@@ -68222,14 +68675,14 @@ ${entry.record.text}`.toLowerCase();
|
|
|
68222
68675
|
const hits = await options.semantic.searcher.searchByVector(options.semantic.collection, vector, {
|
|
68223
68676
|
size: Math.min(100, Math.max(limit * 4, 40))
|
|
68224
68677
|
});
|
|
68225
|
-
const
|
|
68678
|
+
const rank3 = /* @__PURE__ */ new Map();
|
|
68226
68679
|
hits.forEach((hit, position) => {
|
|
68227
|
-
if (!
|
|
68228
|
-
|
|
68680
|
+
if (!rank3.has(hit.path))
|
|
68681
|
+
rank3.set(hit.path, position);
|
|
68229
68682
|
});
|
|
68230
68683
|
ordered = [...candidates].sort((a, b) => {
|
|
68231
|
-
const left =
|
|
68232
|
-
const right =
|
|
68684
|
+
const left = rank3.get(`data:${a.datasetId}:${a.record.id}`);
|
|
68685
|
+
const right = rank3.get(`data:${b.datasetId}:${b.record.id}`);
|
|
68233
68686
|
if (left !== void 0 && right !== void 0)
|
|
68234
68687
|
return left - right;
|
|
68235
68688
|
if (left !== void 0)
|