@chosengeneration/light-code 0.59.8 → 0.62.0
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 +422 -13
- package/dist/client/client.js +67 -67
- package/dist/server.js +421 -12
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -48306,15 +48306,15 @@ ${record2.preview}`.toLowerCase();
|
|
|
48306
48306
|
const hits = await options.semantic.searcher.searchByVector(options.semantic.collection, vector, {
|
|
48307
48307
|
size: Math.min(100, Math.max(limit * 4, 40))
|
|
48308
48308
|
});
|
|
48309
|
-
const
|
|
48309
|
+
const rank3 = /* @__PURE__ */ new Map();
|
|
48310
48310
|
hits.forEach((hit, position) => {
|
|
48311
48311
|
const id = hit.path.startsWith("mail:") ? hit.path.slice("mail:".length) : hit.path;
|
|
48312
|
-
if (!
|
|
48313
|
-
|
|
48312
|
+
if (!rank3.has(id))
|
|
48313
|
+
rank3.set(id, position);
|
|
48314
48314
|
});
|
|
48315
48315
|
ordered = [...candidates].sort((a, b) => {
|
|
48316
|
-
const left =
|
|
48317
|
-
const right =
|
|
48316
|
+
const left = rank3.get(a.id);
|
|
48317
|
+
const right = rank3.get(b.id);
|
|
48318
48318
|
if (left !== void 0 && right !== void 0)
|
|
48319
48319
|
return left - right;
|
|
48320
48320
|
if (left !== void 0)
|
|
@@ -60961,8 +60961,8 @@ function coerceFormValue(field, raw) {
|
|
|
60961
60961
|
if (field.required !== false && chosen.length === 0) {
|
|
60962
60962
|
return { error: `"${field.label}" needs at least one selection.` };
|
|
60963
60963
|
}
|
|
60964
|
-
const
|
|
60965
|
-
return { value:
|
|
60964
|
+
const order2 = (field.options ?? []).map((option) => option.value);
|
|
60965
|
+
return { value: order2.filter((value) => chosen.includes(value)) };
|
|
60966
60966
|
}
|
|
60967
60967
|
if (field.type === "number") {
|
|
60968
60968
|
const parsed = typeof raw === "number" ? raw : Number(String(raw ?? "").trim());
|
|
@@ -62884,6 +62884,8 @@ ${direction}` : attachMentions(text, mentions);
|
|
|
62884
62884
|
return;
|
|
62885
62885
|
if (chartFromToolCall(toolCall.name, toolCall.arguments) !== void 0)
|
|
62886
62886
|
return;
|
|
62887
|
+
if (diagramFromToolCall(toolCall.name, toolCall.arguments) !== void 0)
|
|
62888
|
+
return;
|
|
62887
62889
|
const summary = toolCallSummary(toolCall);
|
|
62888
62890
|
post({
|
|
62889
62891
|
type: "toolCall",
|
|
@@ -62896,6 +62898,15 @@ ${direction}` : attachMentions(text, mentions);
|
|
|
62896
62898
|
post({ type: "textChunk", text: result.content });
|
|
62897
62899
|
return;
|
|
62898
62900
|
}
|
|
62901
|
+
const diagram = diagramFromToolCall(toolCall.name, toolCall.arguments);
|
|
62902
|
+
if (diagram !== void 0) {
|
|
62903
|
+
post(diagram.kind === "diagram" ? {
|
|
62904
|
+
type: "diagram",
|
|
62905
|
+
diagram: diagram.diagram,
|
|
62906
|
+
...informedBy !== void 0 ? { expertInformed: true, informedBy } : {}
|
|
62907
|
+
} : { type: "diagramError", message: diagram.message });
|
|
62908
|
+
return;
|
|
62909
|
+
}
|
|
62899
62910
|
const chart = chartFromToolCall(toolCall.name, toolCall.arguments);
|
|
62900
62911
|
if (chart !== void 0) {
|
|
62901
62912
|
post(chart.kind === "chart" ? {
|
|
@@ -66549,6 +66560,22 @@ ${entry.content}`);
|
|
|
66549
66560
|
lines.push(`## Chart
|
|
66550
66561
|
|
|
66551
66562
|
Could not be drawn: ${entry.message}`);
|
|
66563
|
+
} else if (entry.kind === "diagramError") {
|
|
66564
|
+
lines.push(`## Diagram
|
|
66565
|
+
|
|
66566
|
+
Could not be drawn: ${entry.message}`);
|
|
66567
|
+
} else if (entry.kind === "diagram") {
|
|
66568
|
+
const diagram = entry.diagram;
|
|
66569
|
+
const labels = new Map(diagram.nodes.map((node) => [node.id, node.label]));
|
|
66570
|
+
lines.push([
|
|
66571
|
+
`## ${diagram.title ?? "Diagram"}`,
|
|
66572
|
+
"",
|
|
66573
|
+
...diagram.edges.map((edge) => {
|
|
66574
|
+
const via = edge.label === void 0 ? "" : ` \u2014 ${edge.label}`;
|
|
66575
|
+
return `- ${labels.get(edge.from) ?? edge.from} \u2192 ${labels.get(edge.to) ?? edge.to}${via}`;
|
|
66576
|
+
}),
|
|
66577
|
+
...diagram.note === void 0 ? [] : ["", diagram.note]
|
|
66578
|
+
].join("\n"));
|
|
66552
66579
|
} else {
|
|
66553
66580
|
const call = entry.toolCall;
|
|
66554
66581
|
lines.push([
|
|
@@ -67132,6 +67159,99 @@ function chartTotals(spec) {
|
|
|
67132
67159
|
return { series, grand: series.reduce((sum, entry) => sum + entry.total, 0) };
|
|
67133
67160
|
}
|
|
67134
67161
|
|
|
67162
|
+
// ../../packages/core/dist/diagrams/types.js
|
|
67163
|
+
var DIAGRAM_MAX_NODES = 40;
|
|
67164
|
+
var DIAGRAM_MAX_EDGES = 80;
|
|
67165
|
+
var NODE_TONES = [
|
|
67166
|
+
"neutral",
|
|
67167
|
+
"accent",
|
|
67168
|
+
"info",
|
|
67169
|
+
"success",
|
|
67170
|
+
"warning",
|
|
67171
|
+
"danger",
|
|
67172
|
+
"muted"
|
|
67173
|
+
];
|
|
67174
|
+
var NODE_ICONS = [
|
|
67175
|
+
"service",
|
|
67176
|
+
"database",
|
|
67177
|
+
"user",
|
|
67178
|
+
"file",
|
|
67179
|
+
"cloud",
|
|
67180
|
+
"lock",
|
|
67181
|
+
"clock",
|
|
67182
|
+
"queue",
|
|
67183
|
+
"code",
|
|
67184
|
+
"mail",
|
|
67185
|
+
"check",
|
|
67186
|
+
"cross",
|
|
67187
|
+
"warning",
|
|
67188
|
+
"gear"
|
|
67189
|
+
];
|
|
67190
|
+
var NODE_SHAPES = ["box", "round", "diamond", "cylinder"];
|
|
67191
|
+
var diagramNodeSchema = external_exports.object({
|
|
67192
|
+
id: external_exports.string().min(1).max(64).describe("A short identifier, referenced by edges. Not shown."),
|
|
67193
|
+
label: external_exports.string().min(1).max(120).describe("The text in the box. Keep it to a few words."),
|
|
67194
|
+
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)."),
|
|
67195
|
+
/** Shown under the label, smaller. For the qualifier that would otherwise bloat the label. */
|
|
67196
|
+
note: external_exports.string().max(120).optional().describe("A second, smaller line under the label."),
|
|
67197
|
+
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.")
|
|
67199
|
+
});
|
|
67200
|
+
var diagramEdgeSchema = external_exports.object({
|
|
67201
|
+
from: external_exports.string().min(1).describe("The id of the node the arrow leaves."),
|
|
67202
|
+
to: external_exports.string().min(1).describe("The id of the node the arrow enters."),
|
|
67203
|
+
label: external_exports.string().max(60).optional().describe('Text on the arrow \u2014 the condition, or what flows along it. "yes", "on failure".'),
|
|
67204
|
+
style: external_exports.enum(["solid", "dashed"]).optional().describe("dashed for something conditional, asynchronous or secondary.")
|
|
67205
|
+
});
|
|
67206
|
+
var diagramLegendSchema = external_exports.object({
|
|
67207
|
+
label: external_exports.string().min(1).max(80).describe("What this appearance means in this diagram."),
|
|
67208
|
+
tone: external_exports.enum(NODE_TONES).optional(),
|
|
67209
|
+
shape: external_exports.enum(NODE_SHAPES).optional(),
|
|
67210
|
+
icon: external_exports.enum(NODE_ICONS).optional()
|
|
67211
|
+
});
|
|
67212
|
+
var DIAGRAM_MAX_LEGEND = 8;
|
|
67213
|
+
var diagramSpecSchema = external_exports.object({
|
|
67214
|
+
title: external_exports.string().max(120).optional(),
|
|
67215
|
+
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
|
+
direction: external_exports.enum(["down", "right"]).optional().describe("Which way the flow runs. down is the default and suits most flows."),
|
|
67217
|
+
nodes: external_exports.array(diagramNodeSchema).min(1).max(DIAGRAM_MAX_NODES),
|
|
67218
|
+
edges: external_exports.array(diagramEdgeSchema).max(DIAGRAM_MAX_EDGES),
|
|
67219
|
+
note: external_exports.string().max(400).optional().describe("A line under the diagram. Say what it leaves out, or where it came from.")
|
|
67220
|
+
}).superRefine((spec, context) => {
|
|
67221
|
+
const ids = /* @__PURE__ */ new Set();
|
|
67222
|
+
for (const [index, node] of spec.nodes.entries()) {
|
|
67223
|
+
if (ids.has(node.id)) {
|
|
67224
|
+
context.addIssue({
|
|
67225
|
+
code: "custom",
|
|
67226
|
+
path: ["nodes", index, "id"],
|
|
67227
|
+
/*
|
|
67228
|
+
* Named rather than de-duplicated. Two nodes sharing an id means the edges meant for one
|
|
67229
|
+
* of them are pointing at the other, and silently keeping the first would draw a diagram
|
|
67230
|
+
* that is wrong in a way nobody can see.
|
|
67231
|
+
*/
|
|
67232
|
+
message: `Two nodes share the id "${node.id}". Ids must be unique \u2014 edges are resolved by them.`
|
|
67233
|
+
});
|
|
67234
|
+
}
|
|
67235
|
+
ids.add(node.id);
|
|
67236
|
+
}
|
|
67237
|
+
for (const [index, edge] of spec.edges.entries()) {
|
|
67238
|
+
for (const [end, id] of [
|
|
67239
|
+
["from", edge.from],
|
|
67240
|
+
["to", edge.to]
|
|
67241
|
+
]) {
|
|
67242
|
+
if (!ids.has(id)) {
|
|
67243
|
+
context.addIssue({
|
|
67244
|
+
code: "custom",
|
|
67245
|
+
path: ["edges", index, end],
|
|
67246
|
+
// The available ids are listed: the usual cause is a typo, and a message that names
|
|
67247
|
+
// the candidates is one the model can act on without another round trip.
|
|
67248
|
+
message: `No node has the id "${id}". Known ids: ${[...ids].join(", ")}.`
|
|
67249
|
+
});
|
|
67250
|
+
}
|
|
67251
|
+
}
|
|
67252
|
+
}
|
|
67253
|
+
});
|
|
67254
|
+
|
|
67135
67255
|
// ../../packages/core/dist/history/transcript.js
|
|
67136
67256
|
var CONTROL_TOOLS = /* @__PURE__ */ new Set([
|
|
67137
67257
|
"attempt_completion",
|
|
@@ -67241,6 +67361,16 @@ function consultationFromToolCall(name, rawArguments) {
|
|
|
67241
67361
|
const role = typeof decoded === "object" && decoded !== null ? decoded.role : void 0;
|
|
67242
67362
|
return typeof role === "string" && role.trim().length > 0 ? role.trim().toLowerCase() : "unknown";
|
|
67243
67363
|
}
|
|
67364
|
+
function diagramFromToolCall(name, rawArguments) {
|
|
67365
|
+
const call = throughDispatch(name, rawArguments);
|
|
67366
|
+
if (call.name !== "show_diagram")
|
|
67367
|
+
return void 0;
|
|
67368
|
+
const parsed = diagramSpecSchema.safeParse(call.args);
|
|
67369
|
+
return parsed.success ? { kind: "diagram", diagram: parsed.data } : {
|
|
67370
|
+
kind: "diagramError",
|
|
67371
|
+
message: parsed.error.issues.map((issue2) => `${issue2.path.join(".")}: ${issue2.message}`).join("; ")
|
|
67372
|
+
};
|
|
67373
|
+
}
|
|
67244
67374
|
function chartFromToolCall(name, rawArguments) {
|
|
67245
67375
|
const call = throughDispatch(name, rawArguments);
|
|
67246
67376
|
if (call.name !== "show_chart")
|
|
@@ -67315,6 +67445,264 @@ function createShowChartTool() {
|
|
|
67315
67445
|
};
|
|
67316
67446
|
}
|
|
67317
67447
|
|
|
67448
|
+
// ../../packages/core/dist/diagrams/layout.js
|
|
67449
|
+
var NODE_HEIGHT = 52;
|
|
67450
|
+
var NOTE_EXTRA = 14;
|
|
67451
|
+
var MIN_WIDTH = 96;
|
|
67452
|
+
var MAX_WIDTH = 260;
|
|
67453
|
+
var CHAR_WIDTH = 7.4;
|
|
67454
|
+
var PADDING_X = 28;
|
|
67455
|
+
var GAP_WITHIN_RANK = 28;
|
|
67456
|
+
var GAP_BETWEEN_RANKS = 64;
|
|
67457
|
+
var MARGIN = 28;
|
|
67458
|
+
var TITLE_HEIGHT = 40;
|
|
67459
|
+
var SWATCH_WIDTH = 26;
|
|
67460
|
+
var SWATCH_HEIGHT = 16;
|
|
67461
|
+
var SWATCH_GAP = 7;
|
|
67462
|
+
var LEGEND_ITEM_GAP = 22;
|
|
67463
|
+
var LEGEND_ROW_HEIGHT = 24;
|
|
67464
|
+
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));
|
|
67468
|
+
}
|
|
67469
|
+
function backEdges(spec) {
|
|
67470
|
+
const outgoing = /* @__PURE__ */ new Map();
|
|
67471
|
+
for (const [index, edge] of spec.edges.entries()) {
|
|
67472
|
+
const list = outgoing.get(edge.from) ?? [];
|
|
67473
|
+
list.push({ to: edge.to, index });
|
|
67474
|
+
outgoing.set(edge.from, list);
|
|
67475
|
+
}
|
|
67476
|
+
const back = /* @__PURE__ */ new Set();
|
|
67477
|
+
const state = /* @__PURE__ */ new Map();
|
|
67478
|
+
const visit = (id) => {
|
|
67479
|
+
state.set(id, "open");
|
|
67480
|
+
for (const edge of outgoing.get(id) ?? []) {
|
|
67481
|
+
const seen = state.get(edge.to);
|
|
67482
|
+
if (seen === "open")
|
|
67483
|
+
back.add(edge.index);
|
|
67484
|
+
else if (seen === void 0)
|
|
67485
|
+
visit(edge.to);
|
|
67486
|
+
}
|
|
67487
|
+
state.set(id, "done");
|
|
67488
|
+
};
|
|
67489
|
+
for (const node of spec.nodes)
|
|
67490
|
+
if (!state.has(node.id))
|
|
67491
|
+
visit(node.id);
|
|
67492
|
+
return back;
|
|
67493
|
+
}
|
|
67494
|
+
function rank2(spec, back) {
|
|
67495
|
+
const incoming = /* @__PURE__ */ new Map();
|
|
67496
|
+
for (const node of spec.nodes)
|
|
67497
|
+
incoming.set(node.id, []);
|
|
67498
|
+
for (const [index, edge] of spec.edges.entries()) {
|
|
67499
|
+
if (back.has(index))
|
|
67500
|
+
continue;
|
|
67501
|
+
incoming.get(edge.to)?.push(edge.from);
|
|
67502
|
+
}
|
|
67503
|
+
const ranks = /* @__PURE__ */ new Map();
|
|
67504
|
+
const resolving = /* @__PURE__ */ new Set();
|
|
67505
|
+
const rankOf = (id) => {
|
|
67506
|
+
const known = ranks.get(id);
|
|
67507
|
+
if (known !== void 0)
|
|
67508
|
+
return known;
|
|
67509
|
+
if (resolving.has(id))
|
|
67510
|
+
return 0;
|
|
67511
|
+
resolving.add(id);
|
|
67512
|
+
const parents = incoming.get(id) ?? [];
|
|
67513
|
+
const depth = parents.length === 0 ? 0 : Math.max(...parents.map((parent) => rankOf(parent) + 1));
|
|
67514
|
+
resolving.delete(id);
|
|
67515
|
+
ranks.set(id, depth);
|
|
67516
|
+
return depth;
|
|
67517
|
+
};
|
|
67518
|
+
for (const node of spec.nodes)
|
|
67519
|
+
rankOf(node.id);
|
|
67520
|
+
return ranks;
|
|
67521
|
+
}
|
|
67522
|
+
function order(spec, ranks, back) {
|
|
67523
|
+
const byRank = [];
|
|
67524
|
+
for (const node of spec.nodes) {
|
|
67525
|
+
const depth = ranks.get(node.id) ?? 0;
|
|
67526
|
+
while (byRank.length <= depth)
|
|
67527
|
+
byRank.push([]);
|
|
67528
|
+
byRank[depth]?.push(node.id);
|
|
67529
|
+
}
|
|
67530
|
+
const parents = /* @__PURE__ */ new Map();
|
|
67531
|
+
for (const [index, edge] of spec.edges.entries()) {
|
|
67532
|
+
if (back.has(index))
|
|
67533
|
+
continue;
|
|
67534
|
+
const list = parents.get(edge.to) ?? [];
|
|
67535
|
+
list.push(edge.from);
|
|
67536
|
+
parents.set(edge.to, list);
|
|
67537
|
+
}
|
|
67538
|
+
for (let depth = 1; depth < byRank.length; depth += 1) {
|
|
67539
|
+
const above = byRank[depth - 1] ?? [];
|
|
67540
|
+
const positions = new Map(above.map((id, index) => [id, index]));
|
|
67541
|
+
const row = byRank[depth] ?? [];
|
|
67542
|
+
const keyed = row.map((id, index) => {
|
|
67543
|
+
const known = (parents.get(id) ?? []).map((parent) => positions.get(parent)).filter((value) => value !== void 0);
|
|
67544
|
+
const barycentre = known.length === 0 ? index : known.reduce((a, b) => a + b, 0) / known.length;
|
|
67545
|
+
return { id, barycentre, index };
|
|
67546
|
+
});
|
|
67547
|
+
keyed.sort((a, b) => a.barycentre - b.barycentre || a.index - b.index);
|
|
67548
|
+
byRank[depth] = keyed.map((entry) => entry.id);
|
|
67549
|
+
}
|
|
67550
|
+
return byRank;
|
|
67551
|
+
}
|
|
67552
|
+
function layoutDiagram(spec) {
|
|
67553
|
+
const sideways = spec.direction === "right";
|
|
67554
|
+
const back = backEdges(spec);
|
|
67555
|
+
const ranks = rank2(spec, back);
|
|
67556
|
+
const rows = order(spec, ranks, back);
|
|
67557
|
+
const byId = new Map(spec.nodes.map((node) => [node.id, node]));
|
|
67558
|
+
const sizes = /* @__PURE__ */ new Map();
|
|
67559
|
+
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
|
+
});
|
|
67564
|
+
}
|
|
67565
|
+
const rankExtent = rows.map((row) => Math.max(...row.map((id) => sizes.get(id)?.height ?? NODE_HEIGHT)));
|
|
67566
|
+
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));
|
|
67567
|
+
const widest = Math.max(...rowWidths, 1);
|
|
67568
|
+
const placed = [];
|
|
67569
|
+
let cursor = MARGIN + (spec.title === void 0 ? 0 : TITLE_HEIGHT);
|
|
67570
|
+
for (const [depth, row] of rows.entries()) {
|
|
67571
|
+
const extent = rankExtent[depth] ?? NODE_HEIGHT;
|
|
67572
|
+
let x = MARGIN + (widest - (rowWidths[depth] ?? 0)) / 2;
|
|
67573
|
+
for (const id of row) {
|
|
67574
|
+
const node = byId.get(id);
|
|
67575
|
+
const size2 = sizes.get(id);
|
|
67576
|
+
if (node === void 0 || size2 === void 0)
|
|
67577
|
+
continue;
|
|
67578
|
+
placed.push({
|
|
67579
|
+
id,
|
|
67580
|
+
label: node.label,
|
|
67581
|
+
note: node.note,
|
|
67582
|
+
shape: node.shape ?? "box",
|
|
67583
|
+
// A start or an end is accented unless the model said otherwise: the entry and exit of a
|
|
67584
|
+
// flow are what a reader looks for first.
|
|
67585
|
+
tone: node.tone ?? (node.shape === "round" ? "accent" : "neutral"),
|
|
67586
|
+
icon: node.icon,
|
|
67587
|
+
x,
|
|
67588
|
+
// Centred in its rank, so a tall box beside a short one does not look misaligned.
|
|
67589
|
+
y: cursor + (extent - size2.height) / 2,
|
|
67590
|
+
width: size2.width,
|
|
67591
|
+
height: size2.height
|
|
67592
|
+
});
|
|
67593
|
+
x += size2.width + GAP_WITHIN_RANK;
|
|
67594
|
+
}
|
|
67595
|
+
cursor += extent + GAP_BETWEEN_RANKS;
|
|
67596
|
+
}
|
|
67597
|
+
const upright = {
|
|
67598
|
+
width: widest + MARGIN * 2,
|
|
67599
|
+
height: cursor - GAP_BETWEEN_RANKS + MARGIN
|
|
67600
|
+
};
|
|
67601
|
+
const nodes = sideways ? placed.map((node) => ({
|
|
67602
|
+
...node,
|
|
67603
|
+
x: node.y,
|
|
67604
|
+
y: node.x
|
|
67605
|
+
// Size is not transposed: a box swapping its width for its height would wrap its text.
|
|
67606
|
+
})) : placed;
|
|
67607
|
+
const size = sideways ? { width: upright.height, height: upright.width } : { width: upright.width, height: upright.height };
|
|
67608
|
+
const positions = new Map(nodes.map((node) => [node.id, node]));
|
|
67609
|
+
const edges = spec.edges.flatMap((edge, index) => {
|
|
67610
|
+
const from = positions.get(edge.from);
|
|
67611
|
+
const to = positions.get(edge.to);
|
|
67612
|
+
if (from === void 0 || to === void 0)
|
|
67613
|
+
return [];
|
|
67614
|
+
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 };
|
|
67615
|
+
const end = sideways ? { x: to.x, y: to.y + to.height / 2 } : { x: to.x + to.width / 2, y: to.y };
|
|
67616
|
+
const isBack = back.has(index);
|
|
67617
|
+
const points = isBack ? sideways ? [
|
|
67618
|
+
{ x: from.x + from.width / 2, y: from.y + from.height },
|
|
67619
|
+
{ x: from.x + from.width / 2, y: size.height - MARGIN / 2 },
|
|
67620
|
+
{ x: to.x + to.width / 2, y: size.height - MARGIN / 2 },
|
|
67621
|
+
{ x: to.x + to.width / 2, y: to.y + to.height }
|
|
67622
|
+
] : [
|
|
67623
|
+
{ x: from.x + from.width, y: from.y + from.height / 2 },
|
|
67624
|
+
{ x: size.width - MARGIN / 2, y: from.y + from.height / 2 },
|
|
67625
|
+
{ x: size.width - MARGIN / 2, y: to.y + to.height / 2 },
|
|
67626
|
+
{ x: to.x + to.width, y: to.y + to.height / 2 }
|
|
67627
|
+
] : [start, end];
|
|
67628
|
+
const midpoint = points.length === 2 ? 0 : 1;
|
|
67629
|
+
const a = points[midpoint] ?? start;
|
|
67630
|
+
const b = points[midpoint + 1] ?? end;
|
|
67631
|
+
return [
|
|
67632
|
+
{
|
|
67633
|
+
from: edge.from,
|
|
67634
|
+
to: edge.to,
|
|
67635
|
+
label: edge.label,
|
|
67636
|
+
dashed: edge.style === "dashed",
|
|
67637
|
+
points,
|
|
67638
|
+
labelAt: { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 }
|
|
67639
|
+
}
|
|
67640
|
+
];
|
|
67641
|
+
});
|
|
67642
|
+
const legend = [];
|
|
67643
|
+
let legendHeight = 0;
|
|
67644
|
+
let canvasWidth = size.width;
|
|
67645
|
+
if (spec.legend !== void 0 && spec.legend.length > 0) {
|
|
67646
|
+
const entryWidths = spec.legend.map((entry) => SWATCH_WIDTH + SWATCH_GAP + Math.round(entry.label.length * 6.6));
|
|
67647
|
+
const available = Math.max(size.width - MARGIN * 2, Math.max(...entryWidths));
|
|
67648
|
+
let x = MARGIN;
|
|
67649
|
+
let y = size.height + LEGEND_TOP_GAP;
|
|
67650
|
+
let rows2 = 1;
|
|
67651
|
+
for (const [index, entry] of spec.legend.entries()) {
|
|
67652
|
+
const entryWidth = entryWidths[index] ?? 0;
|
|
67653
|
+
if (x > MARGIN && x + entryWidth - MARGIN > available) {
|
|
67654
|
+
x = MARGIN;
|
|
67655
|
+
y += LEGEND_ROW_HEIGHT;
|
|
67656
|
+
rows2 += 1;
|
|
67657
|
+
}
|
|
67658
|
+
legend.push({
|
|
67659
|
+
label: entry.label,
|
|
67660
|
+
shape: entry.shape ?? "box",
|
|
67661
|
+
tone: entry.tone ?? "neutral",
|
|
67662
|
+
icon: entry.icon,
|
|
67663
|
+
x,
|
|
67664
|
+
y,
|
|
67665
|
+
swatchWidth: SWATCH_WIDTH,
|
|
67666
|
+
swatchHeight: SWATCH_HEIGHT
|
|
67667
|
+
});
|
|
67668
|
+
x += entryWidth + LEGEND_ITEM_GAP;
|
|
67669
|
+
canvasWidth = Math.max(canvasWidth, x - LEGEND_ITEM_GAP + MARGIN);
|
|
67670
|
+
}
|
|
67671
|
+
legendHeight = LEGEND_TOP_GAP + rows2 * LEGEND_ROW_HEIGHT;
|
|
67672
|
+
}
|
|
67673
|
+
return {
|
|
67674
|
+
width: canvasWidth,
|
|
67675
|
+
height: size.height + legendHeight,
|
|
67676
|
+
title: spec.title,
|
|
67677
|
+
note: spec.note,
|
|
67678
|
+
nodes,
|
|
67679
|
+
edges,
|
|
67680
|
+
legend
|
|
67681
|
+
};
|
|
67682
|
+
}
|
|
67683
|
+
|
|
67684
|
+
// ../../packages/core/dist/tools/showDiagram.js
|
|
67685
|
+
function createShowDiagramTool() {
|
|
67686
|
+
return {
|
|
67687
|
+
name: "show_diagram",
|
|
67688
|
+
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.',
|
|
67690
|
+
parametersSchema: diagramSpecSchema,
|
|
67691
|
+
async execute(params) {
|
|
67692
|
+
const layout = layoutDiagram(params);
|
|
67693
|
+
const ranks = new Set(layout.nodes.map((node) => node.y)).size;
|
|
67694
|
+
const unreachable = params.nodes.filter((node) => node.id !== params.nodes[0]?.id && !params.edges.some((edge) => edge.to === node.id || edge.from === node.id));
|
|
67695
|
+
return {
|
|
67696
|
+
content: [
|
|
67697
|
+
`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"}.`,
|
|
67698
|
+
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.`,
|
|
67699
|
+
"The diagram is now in the conversation. Describe what it shows rather than listing the boxes again \u2014 they are on screen."
|
|
67700
|
+
].filter((line) => line !== "").join("\n")
|
|
67701
|
+
};
|
|
67702
|
+
}
|
|
67703
|
+
};
|
|
67704
|
+
}
|
|
67705
|
+
|
|
67318
67706
|
// ../../packages/core/dist/tools/applyDiff/eol.js
|
|
67319
67707
|
function detectEol(text) {
|
|
67320
67708
|
const crlfCount = (text.match(/\r\n/g) ?? []).length;
|
|
@@ -68024,6 +68412,7 @@ function createDefaultToolRegistry() {
|
|
|
68024
68412
|
registry2.register(askFollowupQuestionTool);
|
|
68025
68413
|
registry2.register(createAskUserFormTool());
|
|
68026
68414
|
registry2.register(createShowChartTool());
|
|
68415
|
+
registry2.register(createShowDiagramTool());
|
|
68027
68416
|
registry2.register(attemptCompletionTool);
|
|
68028
68417
|
return registry2;
|
|
68029
68418
|
}
|
|
@@ -68321,14 +68710,14 @@ ${entry.record.text}`.toLowerCase();
|
|
|
68321
68710
|
const hits = await options.semantic.searcher.searchByVector(options.semantic.collection, vector, {
|
|
68322
68711
|
size: Math.min(100, Math.max(limit * 4, 40))
|
|
68323
68712
|
});
|
|
68324
|
-
const
|
|
68713
|
+
const rank3 = /* @__PURE__ */ new Map();
|
|
68325
68714
|
hits.forEach((hit, position) => {
|
|
68326
|
-
if (!
|
|
68327
|
-
|
|
68715
|
+
if (!rank3.has(hit.path))
|
|
68716
|
+
rank3.set(hit.path, position);
|
|
68328
68717
|
});
|
|
68329
68718
|
ordered = [...candidates].sort((a, b) => {
|
|
68330
|
-
const left =
|
|
68331
|
-
const right =
|
|
68719
|
+
const left = rank3.get(`data:${a.datasetId}:${a.record.id}`);
|
|
68720
|
+
const right = rank3.get(`data:${b.datasetId}:${b.record.id}`);
|
|
68332
68721
|
if (left !== void 0 && right !== void 0)
|
|
68333
68722
|
return left - right;
|
|
68334
68723
|
if (left !== void 0)
|
|
@@ -70167,6 +70556,17 @@ async function startServer(options) {
|
|
|
70167
70556
|
detach: (response) => {
|
|
70168
70557
|
if (sink === response) sink = void 0;
|
|
70169
70558
|
},
|
|
70559
|
+
drain: () => {
|
|
70560
|
+
return missed.splice(0, missed.length).flatMap((frame) => {
|
|
70561
|
+
const body = frame.startsWith("data: ") ? frame.slice(6).trimEnd() : "";
|
|
70562
|
+
if (body.length === 0) return [];
|
|
70563
|
+
try {
|
|
70564
|
+
return [JSON.parse(body)];
|
|
70565
|
+
} catch {
|
|
70566
|
+
return [];
|
|
70567
|
+
}
|
|
70568
|
+
});
|
|
70569
|
+
},
|
|
70170
70570
|
dispose: () => {
|
|
70171
70571
|
const open = sink;
|
|
70172
70572
|
sink = void 0;
|
|
@@ -70361,6 +70761,15 @@ async function startServer(options) {
|
|
|
70361
70761
|
request.on("close", cleanup);
|
|
70362
70762
|
return;
|
|
70363
70763
|
}
|
|
70764
|
+
if (url2.pathname === "/api/poll" && request.method === "GET") {
|
|
70765
|
+
let connection = connections.get(principal.id);
|
|
70766
|
+
if (connection === void 0) {
|
|
70767
|
+
connection = await openConnection(principal);
|
|
70768
|
+
connections.set(principal.id, connection);
|
|
70769
|
+
}
|
|
70770
|
+
respondJson(response, 200, { messages: connection.drain() });
|
|
70771
|
+
return;
|
|
70772
|
+
}
|
|
70364
70773
|
if (url2.pathname === "/api/message" && request.method === "POST") {
|
|
70365
70774
|
const connection = connections.get(principal.id);
|
|
70366
70775
|
if (connection === void 0) {
|
|
@@ -70580,7 +70989,7 @@ function respondJson(response, status, body) {
|
|
|
70580
70989
|
}
|
|
70581
70990
|
|
|
70582
70991
|
// src/cli.ts
|
|
70583
|
-
var VERSION = true ? "0.
|
|
70992
|
+
var VERSION = true ? "0.62.0" : "unknown (not a packaged build)";
|
|
70584
70993
|
var compat = installNodeCompat();
|
|
70585
70994
|
function lastMeaningfulLine(problem) {
|
|
70586
70995
|
const lines = problem.split(String.fromCharCode(10)).map((line) => line.trim()).filter((line) => line.length > 0 && !line.endsWith(":"));
|