yamchart 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. package/dist/{advisor-23GCWKME.js → advisor-CXXGXZ5V.js} +5 -5
  2. package/dist/{describe-SYP5GZ3H.js → describe-Y4VD4JQX.js} +4 -4
  3. package/dist/{dev-OHAXDNXA.js → dev-7SWSX2X7.js} +152 -8
  4. package/dist/dev-7SWSX2X7.js.map +1 -0
  5. package/dist/index.js +4 -4
  6. package/dist/public/assets/{LoginPage-9NYRvxVz.js → LoginPage-BhzP7Hkq.js} +1 -1
  7. package/dist/public/assets/{PublicViewer-BvdaHgNU.js → PublicViewer-owhT_M21.js} +1 -1
  8. package/dist/public/assets/{SetupWizard-CCD0gtbP.js → SetupWizard-BbV-9haQ.js} +1 -1
  9. package/dist/public/assets/{ShareManagement-NI9qZCP4.js → ShareManagement-BWDdV-hd.js} +1 -1
  10. package/dist/public/assets/{UserManagement-C6b2NxPn.js → UserManagement-DGGk6XAr.js} +1 -1
  11. package/dist/public/assets/index-Ce_q4or4.js +174 -0
  12. package/dist/public/assets/{index-DRmWl7fw.css → index-D7Le1t6t.css} +1 -1
  13. package/dist/public/assets/{index.es-DUIKH8bd.js → index.es-DZ9bSPjd.js} +1 -1
  14. package/dist/public/assets/{jspdf.es.min-rwipvTDM.js → jspdf.es.min-BZhCusuH.js} +3 -3
  15. package/dist/public/index.html +2 -2
  16. package/dist/templates/default/docs/yamchart-reference.md +25 -0
  17. package/dist/{test-NKYO32Y5.js → test-AJM3CBYW.js} +5 -5
  18. package/package.json +1 -1
  19. package/dist/dev-OHAXDNXA.js.map +0 -1
  20. package/dist/public/assets/index-BVpbXzlM.js +0 -165
  21. /package/dist/{advisor-23GCWKME.js.map → advisor-CXXGXZ5V.js.map} +0 -0
  22. /package/dist/{describe-SYP5GZ3H.js.map → describe-Y4VD4JQX.js.map} +0 -0
  23. /package/dist/{test-NKYO32Y5.js.map → test-AJM3CBYW.js.map} +0 -0
@@ -1,3 +1,7 @@
1
+ import {
2
+ createConnector,
3
+ resolveConnection
4
+ } from "./chunk-45SP26I2.js";
1
5
  import {
2
6
  detail,
3
7
  error,
@@ -6,10 +10,6 @@ import {
6
10
  success,
7
11
  warning
8
12
  } from "./chunk-HJVVHYVN.js";
9
- import {
10
- createConnector,
11
- resolveConnection
12
- } from "./chunk-45SP26I2.js";
13
13
  import "./chunk-UDRJFEJU.js";
14
14
  import "./chunk-23E6YT4S.js";
15
15
  import "./chunk-DGUM43GV.js";
@@ -370,4 +370,4 @@ async function offerApply(context, proposals) {
370
370
  export {
371
371
  runAdvisor
372
372
  };
373
- //# sourceMappingURL=advisor-23GCWKME.js.map
373
+ //# sourceMappingURL=advisor-CXXGXZ5V.js.map
@@ -1,9 +1,9 @@
1
- import {
2
- resolveTableName
3
- } from "./chunk-VJC24RKT.js";
4
1
  import {
5
2
  getDescribeQuery
6
3
  } from "./chunk-ZN3AJM76.js";
4
+ import {
5
+ resolveTableName
6
+ } from "./chunk-VJC24RKT.js";
7
7
  import {
8
8
  createConnector,
9
9
  resolveConnection
@@ -40,4 +40,4 @@ async function describeTable(projectDir, table, options) {
40
40
  export {
41
41
  describeTable
42
42
  };
43
- //# sourceMappingURL=describe-SYP5GZ3H.js.map
43
+ //# sourceMappingURL=describe-Y4VD4JQX.js.map
@@ -12,13 +12,6 @@ import {
12
12
  spinner,
13
13
  success
14
14
  } from "./chunk-HJVVHYVN.js";
15
- import {
16
- AuthDatabase,
17
- generateSessionToken,
18
- hashPassword,
19
- parseTtl,
20
- verifyPassword
21
- } from "./chunk-4P5UHWYK.js";
22
15
  import {
23
16
  ChartSchema,
24
17
  ConnectionSchema,
@@ -48,6 +41,13 @@ import {
48
41
  resolvePostgresAuth,
49
42
  resolveSnowflakeAuth
50
43
  } from "./chunk-23E6YT4S.js";
44
+ import {
45
+ AuthDatabase,
46
+ generateSessionToken,
47
+ hashPassword,
48
+ parseTtl,
49
+ verifyPassword
50
+ } from "./chunk-4P5UHWYK.js";
51
51
  import "./chunk-DGUM43GV.js";
52
52
 
53
53
  // src/commands/dev.ts
@@ -13485,6 +13485,147 @@ async function publicRoutes(fastify, options) {
13485
13485
  });
13486
13486
  }
13487
13487
 
13488
+ // ../server/dist/routes/chat.js
13489
+ async function chatRoutes(fastify, options) {
13490
+ const { configLoader, queryService } = options;
13491
+ fastify.post("/api/chat/generate-text", async (request, reply) => {
13492
+ const { prompt, mode, dashboard: dashboardName, existingContent, filters } = request.body ?? {};
13493
+ if (!prompt || !mode || !dashboardName) {
13494
+ return reply.status(400).send({
13495
+ error: "Missing required fields: prompt, mode, dashboard"
13496
+ });
13497
+ }
13498
+ if (mode !== "insert" && mode !== "replace") {
13499
+ return reply.status(400).send({ error: 'mode must be "insert" or "replace"' });
13500
+ }
13501
+ const apiKey = process.env.ANTHROPIC_API_KEY;
13502
+ if (!apiKey) {
13503
+ return reply.status(400).send({
13504
+ error: "AI text generation requires an API key. Set ANTHROPIC_API_KEY in your environment."
13505
+ });
13506
+ }
13507
+ const dashboard = configLoader.getDashboardByName(dashboardName);
13508
+ if (!dashboard) {
13509
+ return reply.status(404).send({ error: `Dashboard not found: ${dashboardName}` });
13510
+ }
13511
+ try {
13512
+ const chartRefs = [];
13513
+ const extractRefs = (layout) => {
13514
+ for (const row of layout.rows ?? []) {
13515
+ for (const widget of row.widgets ?? []) {
13516
+ if (widget.type === "chart" && widget.ref) {
13517
+ chartRefs.push(widget.ref);
13518
+ }
13519
+ }
13520
+ }
13521
+ };
13522
+ if (dashboard.layout)
13523
+ extractRefs(dashboard.layout);
13524
+ if (dashboard.tabs) {
13525
+ for (const tab of dashboard.tabs) {
13526
+ if (tab.layout)
13527
+ extractRefs(tab.layout);
13528
+ }
13529
+ }
13530
+ const kpiContext = [];
13531
+ const otherCharts = [];
13532
+ const userContext = getUserContext(request);
13533
+ const kpiCharts = [];
13534
+ for (const ref of chartRefs) {
13535
+ const chart = configLoader.getChartByName(ref);
13536
+ if (!chart)
13537
+ continue;
13538
+ if (chart.chart?.type === "kpi" && chart.chart?.value?.field) {
13539
+ kpiCharts.push({ ref, chart });
13540
+ } else {
13541
+ otherCharts.push(`- ${ref} (${chart.chart?.type ?? "unknown"}) \u2014 ${chart.title ?? ref}`);
13542
+ }
13543
+ }
13544
+ const kpiResults = await Promise.allSettled(kpiCharts.map(({ ref, chart }) => queryService.executeChart(chart, filters ?? {}, userContext).then((result) => ({ ref, chart, result }))));
13545
+ for (const settled of kpiResults) {
13546
+ if (settled.status === "fulfilled") {
13547
+ const { ref, chart, result } = settled.value;
13548
+ const row = result.rows[0];
13549
+ if (row && chart.chart?.type === "kpi") {
13550
+ const kpiConfig = chart.chart;
13551
+ const rawValue = row[kpiConfig.value.field];
13552
+ const format = kpiConfig.format;
13553
+ let formatted = String(rawValue);
13554
+ if (typeof rawValue === "number" && format) {
13555
+ if (format.type === "currency") {
13556
+ formatted = new Intl.NumberFormat("en-US", {
13557
+ style: "currency",
13558
+ currency: format.currency || "USD",
13559
+ minimumFractionDigits: format.decimals ?? 0,
13560
+ maximumFractionDigits: format.decimals ?? 0
13561
+ }).format(rawValue);
13562
+ } else if (format.type === "percent") {
13563
+ formatted = new Intl.NumberFormat("en-US", {
13564
+ style: "percent",
13565
+ minimumFractionDigits: format.decimals ?? 0,
13566
+ maximumFractionDigits: format.decimals ?? 0
13567
+ }).format(rawValue / 100);
13568
+ } else {
13569
+ formatted = rawValue.toLocaleString();
13570
+ }
13571
+ }
13572
+ kpiContext.push(`- ${ref}: ${formatted} (${chart.title ?? ref}) \u2014 use {{${ref}}} to embed`);
13573
+ }
13574
+ } else {
13575
+ const idx = kpiResults.indexOf(settled);
13576
+ const ref = kpiCharts[idx]?.ref ?? "unknown";
13577
+ kpiContext.push(`- ${ref}: (data unavailable) \u2014 use {{${ref}}} to embed`);
13578
+ }
13579
+ }
13580
+ const systemParts = [
13581
+ "You write concise markdown for a BI dashboard text widget.",
13582
+ "",
13583
+ "## Available KPI Charts",
13584
+ "Use {{chartName}} syntax to reference live KPI values (they update automatically with filters):",
13585
+ ...kpiContext.length > 0 ? kpiContext : ["(no KPI charts on this dashboard)"],
13586
+ "",
13587
+ "## Other Charts on this Dashboard",
13588
+ ...otherCharts.length > 0 ? otherCharts : ["(none)"],
13589
+ "",
13590
+ "## Active Filters",
13591
+ filters && Object.keys(filters).length > 0 ? Object.entries(filters).map(([k, v]) => `- ${k}: ${JSON.stringify(v)}`).join("\n") : "No filters active.",
13592
+ "",
13593
+ "## Rules",
13594
+ "- Use {{chartName}} syntax to reference KPI values (they resolve to live numbers)",
13595
+ "- Write clean markdown: headings, bold, lists as appropriate",
13596
+ "- Be concise \u2014 dashboard text should be scannable, not verbose",
13597
+ "- Do not wrap output in code fences or backticks",
13598
+ "- Do not explain what you did \u2014 just output the markdown content",
13599
+ "- Do not include the prompt in your output"
13600
+ ];
13601
+ if (mode === "insert" && existingContent) {
13602
+ systemParts.push("");
13603
+ systemParts.push("## Existing Widget Content");
13604
+ systemParts.push("The widget already contains this content. Write text that fits naturally alongside it:");
13605
+ systemParts.push("```");
13606
+ systemParts.push(existingContent);
13607
+ systemParts.push("```");
13608
+ systemParts.push("Output ONLY the new text to insert. Do NOT repeat the existing content.");
13609
+ }
13610
+ const systemPrompt = systemParts.join("\n");
13611
+ const { AnthropicProvider } = await import("./dist-ZRRM3OWF.js");
13612
+ const provider = new AnthropicProvider(apiKey);
13613
+ const response = await provider.chat({
13614
+ system: systemPrompt,
13615
+ messages: [{ role: "user", content: prompt }],
13616
+ tools: [],
13617
+ maxTokens: 1024
13618
+ });
13619
+ const textContent = response.content.filter((b) => b.type === "text").map((b) => b.text).join("\n").trim();
13620
+ return { content: textContent };
13621
+ } catch (err) {
13622
+ const message = err instanceof Error ? err.message : "Text generation failed";
13623
+ fastify.log.error(err, "Generate text error");
13624
+ return reply.status(500).send({ error: message });
13625
+ }
13626
+ });
13627
+ }
13628
+
13488
13629
  // ../server/dist/routes/events.js
13489
13630
  var clients = /* @__PURE__ */ new Set();
13490
13631
  async function eventsRoute(fastify) {
@@ -13646,6 +13787,7 @@ async function createServer(options) {
13646
13787
  await protectedRoutes.register(configRoutes, { configLoader, projectDir, queryService });
13647
13788
  await protectedRoutes.register(chartRoutes, { configLoader, queryService });
13648
13789
  await protectedRoutes.register(dashboardRoutes, { configLoader, gitService, projectDir, queryService });
13790
+ await protectedRoutes.register(chatRoutes, { configLoader, queryService, projectDir });
13649
13791
  });
13650
13792
  } else if (authDb) {
13651
13793
  const localMiddleware = createLocalAuthMiddleware(authDb);
@@ -13654,12 +13796,14 @@ async function createServer(options) {
13654
13796
  await protectedRoutes.register(configRoutes, { configLoader, projectDir, queryService });
13655
13797
  await protectedRoutes.register(chartRoutes, { configLoader, queryService });
13656
13798
  await protectedRoutes.register(dashboardRoutes, { configLoader, gitService, projectDir, queryService });
13799
+ await protectedRoutes.register(chatRoutes, { configLoader, queryService, projectDir });
13657
13800
  await protectedRoutes.register(sharesRoutes, { authDb });
13658
13801
  });
13659
13802
  } else {
13660
13803
  await fastify.register(configRoutes, { configLoader, projectDir, queryService });
13661
13804
  await fastify.register(chartRoutes, { configLoader, queryService });
13662
13805
  await fastify.register(dashboardRoutes, { configLoader, gitService, projectDir, queryService });
13806
+ await fastify.register(chatRoutes, { configLoader, queryService, projectDir });
13663
13807
  }
13664
13808
  const assetsDir = join4(projectDir, "assets");
13665
13809
  try {
@@ -13863,4 +14007,4 @@ async function runDevServer(projectDir, options) {
13863
14007
  export {
13864
14008
  runDevServer
13865
14009
  };
13866
- //# sourceMappingURL=dev-OHAXDNXA.js.map
14010
+ //# sourceMappingURL=dev-7SWSX2X7.js.map