@anuma/sdk 11.2.0 → 11.3.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.
@@ -74,11 +74,14 @@ __export(index_exports, {
74
74
  auditDesign: () => auditDesign,
75
75
  buildAppFileManifest: () => buildAppFileManifest,
76
76
  buildAppSystemPrompt: () => buildAppSystemPrompt,
77
+ buildChartModel: () => buildChartModel,
77
78
  buildConnectorErrorResult: () => buildConnectorErrorResult,
78
79
  buildDocumentSystemPrompt: () => buildDocumentSystemPrompt,
79
80
  buildFontsUrl: () => buildFontsUrl,
80
81
  buildSlideSystemPrompt: () => buildSlideSystemPrompt,
81
82
  callNotionMCPTool: () => callNotionMCPTool,
83
+ chartCellText: () => chartCellText,
84
+ chartSeriesLabel: () => chartSeriesLabel,
82
85
  connectorMintErrorToToolResult: () => connectorMintErrorToToolResult,
83
86
  convertLegacyDeckJson: () => convertLegacyDeckJson,
84
87
  createAgentresClient: () => createAgentresClient,
@@ -2658,6 +2661,157 @@ function createChartTool(options) {
2658
2661
  });
2659
2662
  }
2660
2663
 
2664
+ // src/tools/chartModel.ts
2665
+ var DOT_LIMIT = 12;
2666
+ var MAX_TICKS = 8;
2667
+ var MINUS = "\u2212";
2668
+ function chartCellText(value) {
2669
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : "";
2670
+ }
2671
+ function tickDigits(ticks) {
2672
+ if (!ticks || ticks.length < 2) return 3;
2673
+ const step = ticks[1] - ticks[0];
2674
+ const magnitude = Math.max(...ticks.map(Math.abs));
2675
+ if (step <= 0 || magnitude === 0) return 3;
2676
+ const needed = Math.floor(Math.log10(magnitude)) - Math.floor(Math.log10(step)) + 1;
2677
+ return Math.min(21, Math.max(3, needed));
2678
+ }
2679
+ function keepSmall(options) {
2680
+ const small = new Intl.NumberFormat(void 0, { ...options, maximumSignificantDigits: 3 });
2681
+ const regular = new Intl.NumberFormat(void 0, { ...options, maximumFractionDigits: 2 });
2682
+ return (n, format) => format(n !== 0 && Math.abs(n) < 1 ? small : regular, n);
2683
+ }
2684
+ function buildFormatters(format, currency, ticks) {
2685
+ const digits = tickDigits(ticks);
2686
+ if (format === "currency") {
2687
+ const money = (options) => new Intl.NumberFormat(void 0, {
2688
+ style: "currency",
2689
+ currency: currency ?? "USD",
2690
+ ...options
2691
+ });
2692
+ const compact2 = money({ notation: "compact", maximumSignificantDigits: 3 });
2693
+ const tick2 = money({ notation: "compact", maximumSignificantDigits: digits });
2694
+ const small2 = money({ maximumSignificantDigits: 4 });
2695
+ const cents = money({ minimumFractionDigits: 2, maximumFractionDigits: 2 });
2696
+ const value2 = (n) => Math.abs(n) >= 1e6 ? compact2.format(n) : n !== 0 && Math.abs(n) < 1 ? small2.format(n) : cents.format(n);
2697
+ return { tick: (n) => tick2.format(n), value: value2, change: (d) => value2(Math.abs(d)) };
2698
+ }
2699
+ if (format === "percent") {
2700
+ const percent = keepSmall({ style: "percent" });
2701
+ const points = keepSmall({});
2702
+ const tick2 = new Intl.NumberFormat(void 0, {
2703
+ style: "percent",
2704
+ maximumSignificantDigits: digits
2705
+ });
2706
+ return {
2707
+ tick: (n) => tick2.format(n / 100),
2708
+ value: (n) => percent(n, (formatter) => formatter.format(n / 100)),
2709
+ change: (d) => `${points(Math.abs(d), (formatter, n) => formatter.format(n))} pts`
2710
+ };
2711
+ }
2712
+ const tick = new Intl.NumberFormat(void 0, {
2713
+ notation: "compact",
2714
+ maximumSignificantDigits: digits
2715
+ });
2716
+ const compact = new Intl.NumberFormat(void 0, {
2717
+ notation: "compact",
2718
+ maximumSignificantDigits: 3
2719
+ });
2720
+ const small = new Intl.NumberFormat(void 0, { maximumSignificantDigits: 4 });
2721
+ const plain = new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 });
2722
+ const value = (n) => Math.abs(n) >= 1e6 ? compact.format(n) : n !== 0 && Math.abs(n) < 1 ? small.format(n) : plain.format(n);
2723
+ return { tick: (n) => tick.format(n), value, change: (d) => value(Math.abs(d)) };
2724
+ }
2725
+ function seriesValues(points, keys) {
2726
+ return points.flatMap(
2727
+ (point) => keys.map((key) => point[key]).filter((v) => typeof v === "number")
2728
+ );
2729
+ }
2730
+ function niceStep(rough) {
2731
+ const exponent = Math.floor(Math.log10(rough));
2732
+ const base = 10 ** exponent;
2733
+ const fraction = rough / base;
2734
+ const nice = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 2.5 ? 2.5 : fraction <= 5 ? 5 : 10;
2735
+ return nice * base;
2736
+ }
2737
+ function niceTicks(values) {
2738
+ if (values.length === 0) return void 0;
2739
+ const min = Math.min(...values);
2740
+ const max = Math.max(...values);
2741
+ const span = max - min || Math.abs(max) * 0.02 || 1;
2742
+ const low = min - span * 0.1;
2743
+ const high = max + span * 0.1;
2744
+ const step = niceStep((high - low) / 3);
2745
+ const start = min >= 0 ? Math.max(0, Math.floor(low / step) * step) : Math.floor(low / step) * step;
2746
+ const ticks = [];
2747
+ for (let index = 0; index <= MAX_TICKS; index++) {
2748
+ const tick = Number((start + index * step).toPrecision(15));
2749
+ if (ticks.length > 0 && tick <= ticks[ticks.length - 1]) break;
2750
+ ticks.push(tick);
2751
+ if (tick >= high) break;
2752
+ }
2753
+ return ticks.length >= 2 ? ticks : void 0;
2754
+ }
2755
+ function buildTrend(values, format, formatters) {
2756
+ if (values.length < 2) return void 0;
2757
+ const first = values[0];
2758
+ const last = values[values.length - 1];
2759
+ const difference = last - first;
2760
+ const direction = difference > 0 ? "up" : difference < 0 ? "down" : "flat";
2761
+ const sign = direction === "up" ? "+" : direction === "down" ? MINUS : "";
2762
+ const percent = format !== "percent" && first !== 0 ? ` (${sign}${new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 }).format(
2763
+ Math.abs(difference / Math.abs(first) * 100)
2764
+ )}%)` : "";
2765
+ return {
2766
+ value: formatters.value(last),
2767
+ change: `${sign}${formatters.change(difference)}${percent}`,
2768
+ direction
2769
+ };
2770
+ }
2771
+ function lastValueIndex(points, key) {
2772
+ for (let index = points.length - 1; index >= 0; index--) {
2773
+ if (typeof points[index][key] === "number") return index;
2774
+ }
2775
+ return -1;
2776
+ }
2777
+ function chartSeriesLabel(key) {
2778
+ return key.charAt(0).toUpperCase() + key.slice(1);
2779
+ }
2780
+ function buildChartModel(spec) {
2781
+ const { chartType, title, data, dataKeys, xAxisKey, valueFormat, currency } = spec;
2782
+ const isTrendChart = chartType === "line" || chartType === "area";
2783
+ const plottedKeys = chartType === "pie" ? dataKeys.slice(0, 1) : dataKeys;
2784
+ const values = seriesValues(data, plottedKeys);
2785
+ const yTicks = isTrendChart ? niceTicks(values) : void 0;
2786
+ const yDomain = yTicks ? [yTicks[0], yTicks[yTicks.length - 1]] : void 0;
2787
+ const formatters = buildFormatters(valueFormat, currency, yTicks);
2788
+ const seriesLabels = Object.fromEntries(dataKeys.map((key) => [key, chartSeriesLabel(key)]));
2789
+ const trendBase = isTrendChart && dataKeys.length === 1 ? buildTrend(values, valueFormat, formatters) : void 0;
2790
+ const trendRows = trendBase ? data.filter((point) => typeof point[dataKeys[0]] === "number") : [];
2791
+ const range = trendBase && xAxisKey ? [trendRows[0], trendRows[trendRows.length - 1]].map((point) => chartCellText(point[xAxisKey])).filter(Boolean).join(" \u2013 ") || void 0 : void 0;
2792
+ const trend = trendBase ? { ...trendBase, range } : void 0;
2793
+ const tickSamples = [...yDomain ?? [], ...values].map((value) => formatters.tick(value));
2794
+ const showDots = data.length <= DOT_LIMIT;
2795
+ return {
2796
+ isTrendChart,
2797
+ plottedKeys,
2798
+ seriesLabels,
2799
+ labelKey: chartType === "pie" ? xAxisKey || "name" : xAxisKey,
2800
+ values,
2801
+ yTicks,
2802
+ yDomain,
2803
+ formatters,
2804
+ trend,
2805
+ title: title ?? (trend ? seriesLabels[dataKeys[0]] : void 0),
2806
+ showDots,
2807
+ endIndexes: Object.fromEntries(plottedKeys.map((key) => [key, lastValueIndex(data, key)])),
2808
+ curve: showDots ? "linear" : "monotone",
2809
+ hasNegative: values.some((value) => value < 0),
2810
+ longestTickLength: tickSamples.reduce((max, label) => Math.max(max, label.length), 0),
2811
+ total: values.reduce((sum, value) => sum + value, 0)
2812
+ };
2813
+ }
2814
+
2661
2815
  // src/tools/choice.ts
2662
2816
  var CHOICE_TOOL_NAME = "prompt_user_choice";
2663
2817
  function createChoiceTool(options) {
@@ -14141,11 +14295,14 @@ function createXTools(callProxy) {
14141
14295
  auditDesign,
14142
14296
  buildAppFileManifest,
14143
14297
  buildAppSystemPrompt,
14298
+ buildChartModel,
14144
14299
  buildConnectorErrorResult,
14145
14300
  buildDocumentSystemPrompt,
14146
14301
  buildFontsUrl,
14147
14302
  buildSlideSystemPrompt,
14148
14303
  callNotionMCPTool,
14304
+ chartCellText,
14305
+ chartSeriesLabel,
14149
14306
  connectorMintErrorToToolResult,
14150
14307
  convertLegacyDeckJson,
14151
14308
  createAgentresClient,
@@ -1426,6 +1426,46 @@ type DisplayChartResult = {
1426
1426
  */
1427
1427
  declare function createChartTool(options: CreateUIToolsOptions): ToolConfig;
1428
1428
 
1429
+ type ChartSpec = Exclude<DisplayChartResult, {
1430
+ error: string;
1431
+ }>;
1432
+ type ChartFormatters = {
1433
+ tick: (value: number) => string;
1434
+ value: (value: number) => string;
1435
+ change: (difference: number) => string;
1436
+ };
1437
+ type ChartTrendDirection = "up" | "down" | "flat";
1438
+ type ChartTrend = {
1439
+ value: string;
1440
+ change: string;
1441
+ direction: ChartTrendDirection;
1442
+ range?: string;
1443
+ };
1444
+ type ChartModel = {
1445
+ isTrendChart: boolean;
1446
+ plottedKeys: string[];
1447
+ seriesLabels: Record<string, string>;
1448
+ labelKey?: string;
1449
+ values: number[];
1450
+ yTicks?: number[];
1451
+ yDomain?: [number, number];
1452
+ formatters: ChartFormatters;
1453
+ trend?: ChartTrend;
1454
+ title?: string;
1455
+ showDots: boolean;
1456
+ endIndexes: Record<string, number>;
1457
+ curve: "linear" | "monotone";
1458
+ hasNegative: boolean;
1459
+ longestTickLength: number;
1460
+ total: number;
1461
+ };
1462
+ /** Returns a chart cell value as display text, or an empty string for non-primitive values. */
1463
+ declare function chartCellText(value: unknown): string;
1464
+ /** Returns the display label for a series key. */
1465
+ declare function chartSeriesLabel(key: string): string;
1466
+ /** Computes a renderer-agnostic layout for a `display_chart` result: axis ticks, formatters, headline trend and mark policy. */
1467
+ declare function buildChartModel(spec: ChartSpec): ChartModel;
1468
+
1429
1469
  /** Tool name surfaced to the LLM. */
1430
1470
  declare const CHOICE_TOOL_NAME = "prompt_user_choice";
1431
1471
  type ChoiceOption = {
@@ -2940,4 +2980,4 @@ interface XGetMyPostsArgs {
2940
2980
  */
2941
2981
  declare function createXTools(callProxy: XProxyCaller): Record<string, ToolConfig>;
2942
2982
 
2943
- export { ADD_SLIDE_SCHEMA, APP_BUILDER_PROMPT, APP_COMPLETE_CONNECT_ACK_TYPE, APP_COMPLETE_CONNECT_TYPE, APP_COMPLETE_DEFAULT_TIMEOUT_MS, APP_COMPLETE_IFRAME_SHIM_SCRIPT, APP_COMPLETE_REQUEST_TYPE, APP_COMPLETE_RESPONSE_TYPE, APP_COMPLETE_STUB_SCRIPT, APP_FILE_TOOL_NAMES, APP_PREVIEW_BASELINE_CSS, AUDIT_DESIGN_SCHEMA, type AgentresAccount, type AgentresClient, type AgentresClientOptions, AgentresError, type AgentresErrorCode, type AgentresLinkStatus, type AgentresLinkStep, AgentresPathError, type AnchorMatch, type AnumaChild, AnumaJsxError, type AnumaNode, type AppCompleteBridge, type AppCompleteBridgeOptions, type AppFileRecord, type AppFileStorage, type AttrValue, type AuditIssue, type AuditIssueType, type AuditResult, type AuditSeverity, type AuditTokens, type BuildSlideSystemPromptOptions, CHOICE_TOOL_NAME, CONNECTOR_ERROR_MARKER, CREATE_DOCUMENT_SCHEMA, CREATE_FILE_SCHEMA, CRITIQUE_DESIGN_SCHEMA, type CalendarEvent, type ChartDataPoint, type ChartValueFormat, type ChoiceOption, type ConfirmParameter, type ConfirmToolResult, type ConnectorErrorCode, type ConnectorMintError, type ConnectorMintResult, type ConnectorTokenGetterOpts, type ConnectorTokenSource, type CreateAppGenerationToolsOptions, type CreateDocumentToolsOptions, type CreateEventArgs, type CreateFileArgs, type CreateSelectPaymentWalletToolOptions, type CreateSlideToolsOptions, type CreateUIToolsOptions, type CreateWalletPaymentToolOptions, type CreateWeatherToolOptions, DEFAULT_DESIGN_CRITIQUE_RUBRIC, DEFAULT_DOCUMENT_ID, DEFAULT_MAX_CONVERSATIONS, DEFAULT_MAX_DOCUMENT_CONVERSATIONS, DELETE_FILE_SCHEMA, DOCUMENT_BUILDER_PROMPT, DOCUMENT_TOOL_NAMES, type DisplayChartResult, type DisplayConnectorResult, type DisplayPhoneCallOfferResult, type DisplayToolConfig, type DisplayToolMigrations, type DisplayWeatherResult, type DocAttrValue, type DocChild, DocDslError, type DocNode, type DriveFile, type DropboxRequestAccess, type DropboxTokenGetter, type ExportAppOptions, FONT_LIBRARY, FONT_PRESETS, type FileChangeEvent, type FileSnippet, type FontCategory, type FontPreset, type FontSpec, type ForecastDay, type FormField, type FormFieldOption, type FormFieldType, type GetFileContentArgs, type GmailGetMessageArgs, type GmailMessageDetail, type GmailMessageSummary, type GmailRequestAccess, type GmailSearchArgs, type GmailSendConfirmation, type GmailSendMessageArgs, type GmailTokenGetter, type InteractiveToolConfig, type KnownTag, LAYOUT_MODES, LIST_FILES_SCHEMA, type LayoutMode, type LegacyDeckJson, type ListEventsArgs, type ListRecentFilesArgs, MapFileStorage, type NotionCreatePagesArgs, type NotionFetchArgs, type NotionMcpCaller, type NotionMovePagesArgs, type NotionSearchArgs, type NotionUpdatePageArgs, PATCH_DOCUMENT_SCHEMA, PATCH_FILE_SCHEMA, PATCH_SLIDES_SCHEMA, PLAN_DECK_SCHEMA, type PatchFailure, type PatchFailureReason, type PaymentWallet, type PdfTag, READ_DOCUMENT_SCHEMA, READ_FILE_SCHEMA, READ_SLIDES_SCHEMA, RUNTIME_ERROR_OVERLAY_SCRIPT, SELECT_PAYMENT_WALLET_TOOL_NAME, SLIDES_FILE_PATH, SLIDE_CANVAS_HEIGHT, SLIDE_CANVAS_WIDTH, type SearchFilesArgs, type SelectPaymentWalletResult, SiwxChallengeError, SiwxUnsupportedError, type SlackGetChannelHistoryArgs, type SlackGetThreadRepliesArgs, type SlackListChannelsArgs, type SlackListDmsArgs, type SlackListUsersArgs, type SlackPostMessageArgs, type SlackProxyCaller, type SlackSearchMessagesArgs, type SlideToolSet, type SolanaSignMessageFn, THEME_ATTRS, type ThemeAttr, type ToolConfig, type ToolExecutionErrorType, type ToolExecutionResult, type UIInteractionContext, type UpdateEventArgs, type UpdateFileArgs, VERIFY_APP_SCHEMA, type VerifyAppResult, WALLET_PAYMENT_TOOL_NAME, type WalletPaymentOutcome, type WalletPaymentPassenger, type WalletPaymentRequest, type WalletPaymentResult, type XGetMeArgs, type XGetMyPostsArgs, type XProxyCaller, applyPatches, auditDesign, buildAppFileManifest, buildAppSystemPrompt, buildConnectorErrorResult, buildDocumentSystemPrompt, buildFontsUrl, buildSlideSystemPrompt, callNotionMCPTool, connectorMintErrorToToolResult, convertLegacyDeckJson, createAgentresClient, createAppCompleteBridge, createAppGenerationTools, createChartTool, createChatTools, createChoiceTool, createConfirmTool, createConnectorOfferTool, createConnectorTokenGetter, createDisplayTool, createDocumentTools, createDriveTools, createDropboxTools, createFormTool, createGitHubTools, createGmailTools, createGoogleCalendarCreateEventTool, createGoogleCalendarTool, createGoogleCalendarUpdateEventTool, createGoogleDriveCreateFileTool, createGoogleDriveGetContentTool, createGoogleDriveListRecentTool, createGoogleDriveSearchTool, createGoogleDriveUpdateFileTool, createInteractiveTool, createNotionCreateCommentTool, createNotionCreateDatabaseTool, createNotionCreatePagesTool, createNotionDuplicatePageTool, createNotionFetchTool, createNotionGetCommentsTool, createNotionGetTeamsTool, createNotionGetUsersTool, createNotionMovePagesTool, createNotionProxyTools, createNotionSearchTool, createNotionTools, createNotionUpdateDataSourceTool, createNotionUpdatePageTool, createPhoneCallOfferTool, createSelectPaymentWalletTool, createSlackTools, createSlideTools, createWalletPaymentTool, createWeatherTool, createXTools, documentPath, exportAppToHtml, findById, findParentOfId, getFontByName, getId, getMCPEndpoints, getNumberAttr, getStringAttr, insertAfterId, insertChild, installAppCompleteIframeShim, isAnumaTag, isHtmlTag, isKnownFont, isLegacyDeckJson, isPdfTag, migrateDisplayResult, normalizePath, parseDocumentDsl, parseJsx, pdfStyleKeys, pdfTags, removeById, replaceById, serializeJsx, truncateContent, updateAttrs, walk };
2983
+ export { ADD_SLIDE_SCHEMA, APP_BUILDER_PROMPT, APP_COMPLETE_CONNECT_ACK_TYPE, APP_COMPLETE_CONNECT_TYPE, APP_COMPLETE_DEFAULT_TIMEOUT_MS, APP_COMPLETE_IFRAME_SHIM_SCRIPT, APP_COMPLETE_REQUEST_TYPE, APP_COMPLETE_RESPONSE_TYPE, APP_COMPLETE_STUB_SCRIPT, APP_FILE_TOOL_NAMES, APP_PREVIEW_BASELINE_CSS, AUDIT_DESIGN_SCHEMA, type AgentresAccount, type AgentresClient, type AgentresClientOptions, AgentresError, type AgentresErrorCode, type AgentresLinkStatus, type AgentresLinkStep, AgentresPathError, type AnchorMatch, type AnumaChild, AnumaJsxError, type AnumaNode, type AppCompleteBridge, type AppCompleteBridgeOptions, type AppFileRecord, type AppFileStorage, type AttrValue, type AuditIssue, type AuditIssueType, type AuditResult, type AuditSeverity, type AuditTokens, type BuildSlideSystemPromptOptions, CHOICE_TOOL_NAME, CONNECTOR_ERROR_MARKER, CREATE_DOCUMENT_SCHEMA, CREATE_FILE_SCHEMA, CRITIQUE_DESIGN_SCHEMA, type CalendarEvent, type ChartDataPoint, type ChartFormatters, type ChartModel, type ChartSpec, type ChartTrend, type ChartTrendDirection, type ChartValueFormat, type ChoiceOption, type ConfirmParameter, type ConfirmToolResult, type ConnectorErrorCode, type ConnectorMintError, type ConnectorMintResult, type ConnectorTokenGetterOpts, type ConnectorTokenSource, type CreateAppGenerationToolsOptions, type CreateDocumentToolsOptions, type CreateEventArgs, type CreateFileArgs, type CreateSelectPaymentWalletToolOptions, type CreateSlideToolsOptions, type CreateUIToolsOptions, type CreateWalletPaymentToolOptions, type CreateWeatherToolOptions, DEFAULT_DESIGN_CRITIQUE_RUBRIC, DEFAULT_DOCUMENT_ID, DEFAULT_MAX_CONVERSATIONS, DEFAULT_MAX_DOCUMENT_CONVERSATIONS, DELETE_FILE_SCHEMA, DOCUMENT_BUILDER_PROMPT, DOCUMENT_TOOL_NAMES, type DisplayChartResult, type DisplayConnectorResult, type DisplayPhoneCallOfferResult, type DisplayToolConfig, type DisplayToolMigrations, type DisplayWeatherResult, type DocAttrValue, type DocChild, DocDslError, type DocNode, type DriveFile, type DropboxRequestAccess, type DropboxTokenGetter, type ExportAppOptions, FONT_LIBRARY, FONT_PRESETS, type FileChangeEvent, type FileSnippet, type FontCategory, type FontPreset, type FontSpec, type ForecastDay, type FormField, type FormFieldOption, type FormFieldType, type GetFileContentArgs, type GmailGetMessageArgs, type GmailMessageDetail, type GmailMessageSummary, type GmailRequestAccess, type GmailSearchArgs, type GmailSendConfirmation, type GmailSendMessageArgs, type GmailTokenGetter, type InteractiveToolConfig, type KnownTag, LAYOUT_MODES, LIST_FILES_SCHEMA, type LayoutMode, type LegacyDeckJson, type ListEventsArgs, type ListRecentFilesArgs, MapFileStorage, type NotionCreatePagesArgs, type NotionFetchArgs, type NotionMcpCaller, type NotionMovePagesArgs, type NotionSearchArgs, type NotionUpdatePageArgs, PATCH_DOCUMENT_SCHEMA, PATCH_FILE_SCHEMA, PATCH_SLIDES_SCHEMA, PLAN_DECK_SCHEMA, type PatchFailure, type PatchFailureReason, type PaymentWallet, type PdfTag, READ_DOCUMENT_SCHEMA, READ_FILE_SCHEMA, READ_SLIDES_SCHEMA, RUNTIME_ERROR_OVERLAY_SCRIPT, SELECT_PAYMENT_WALLET_TOOL_NAME, SLIDES_FILE_PATH, SLIDE_CANVAS_HEIGHT, SLIDE_CANVAS_WIDTH, type SearchFilesArgs, type SelectPaymentWalletResult, SiwxChallengeError, SiwxUnsupportedError, type SlackGetChannelHistoryArgs, type SlackGetThreadRepliesArgs, type SlackListChannelsArgs, type SlackListDmsArgs, type SlackListUsersArgs, type SlackPostMessageArgs, type SlackProxyCaller, type SlackSearchMessagesArgs, type SlideToolSet, type SolanaSignMessageFn, THEME_ATTRS, type ThemeAttr, type ToolConfig, type ToolExecutionErrorType, type ToolExecutionResult, type UIInteractionContext, type UpdateEventArgs, type UpdateFileArgs, VERIFY_APP_SCHEMA, type VerifyAppResult, WALLET_PAYMENT_TOOL_NAME, type WalletPaymentOutcome, type WalletPaymentPassenger, type WalletPaymentRequest, type WalletPaymentResult, type XGetMeArgs, type XGetMyPostsArgs, type XProxyCaller, applyPatches, auditDesign, buildAppFileManifest, buildAppSystemPrompt, buildChartModel, buildConnectorErrorResult, buildDocumentSystemPrompt, buildFontsUrl, buildSlideSystemPrompt, callNotionMCPTool, chartCellText, chartSeriesLabel, connectorMintErrorToToolResult, convertLegacyDeckJson, createAgentresClient, createAppCompleteBridge, createAppGenerationTools, createChartTool, createChatTools, createChoiceTool, createConfirmTool, createConnectorOfferTool, createConnectorTokenGetter, createDisplayTool, createDocumentTools, createDriveTools, createDropboxTools, createFormTool, createGitHubTools, createGmailTools, createGoogleCalendarCreateEventTool, createGoogleCalendarTool, createGoogleCalendarUpdateEventTool, createGoogleDriveCreateFileTool, createGoogleDriveGetContentTool, createGoogleDriveListRecentTool, createGoogleDriveSearchTool, createGoogleDriveUpdateFileTool, createInteractiveTool, createNotionCreateCommentTool, createNotionCreateDatabaseTool, createNotionCreatePagesTool, createNotionDuplicatePageTool, createNotionFetchTool, createNotionGetCommentsTool, createNotionGetTeamsTool, createNotionGetUsersTool, createNotionMovePagesTool, createNotionProxyTools, createNotionSearchTool, createNotionTools, createNotionUpdateDataSourceTool, createNotionUpdatePageTool, createPhoneCallOfferTool, createSelectPaymentWalletTool, createSlackTools, createSlideTools, createWalletPaymentTool, createWeatherTool, createXTools, documentPath, exportAppToHtml, findById, findParentOfId, getFontByName, getId, getMCPEndpoints, getNumberAttr, getStringAttr, insertAfterId, insertChild, installAppCompleteIframeShim, isAnumaTag, isHtmlTag, isKnownFont, isLegacyDeckJson, isPdfTag, migrateDisplayResult, normalizePath, parseDocumentDsl, parseJsx, pdfStyleKeys, pdfTags, removeById, replaceById, serializeJsx, truncateContent, updateAttrs, walk };
@@ -1426,6 +1426,46 @@ type DisplayChartResult = {
1426
1426
  */
1427
1427
  declare function createChartTool(options: CreateUIToolsOptions): ToolConfig;
1428
1428
 
1429
+ type ChartSpec = Exclude<DisplayChartResult, {
1430
+ error: string;
1431
+ }>;
1432
+ type ChartFormatters = {
1433
+ tick: (value: number) => string;
1434
+ value: (value: number) => string;
1435
+ change: (difference: number) => string;
1436
+ };
1437
+ type ChartTrendDirection = "up" | "down" | "flat";
1438
+ type ChartTrend = {
1439
+ value: string;
1440
+ change: string;
1441
+ direction: ChartTrendDirection;
1442
+ range?: string;
1443
+ };
1444
+ type ChartModel = {
1445
+ isTrendChart: boolean;
1446
+ plottedKeys: string[];
1447
+ seriesLabels: Record<string, string>;
1448
+ labelKey?: string;
1449
+ values: number[];
1450
+ yTicks?: number[];
1451
+ yDomain?: [number, number];
1452
+ formatters: ChartFormatters;
1453
+ trend?: ChartTrend;
1454
+ title?: string;
1455
+ showDots: boolean;
1456
+ endIndexes: Record<string, number>;
1457
+ curve: "linear" | "monotone";
1458
+ hasNegative: boolean;
1459
+ longestTickLength: number;
1460
+ total: number;
1461
+ };
1462
+ /** Returns a chart cell value as display text, or an empty string for non-primitive values. */
1463
+ declare function chartCellText(value: unknown): string;
1464
+ /** Returns the display label for a series key. */
1465
+ declare function chartSeriesLabel(key: string): string;
1466
+ /** Computes a renderer-agnostic layout for a `display_chart` result: axis ticks, formatters, headline trend and mark policy. */
1467
+ declare function buildChartModel(spec: ChartSpec): ChartModel;
1468
+
1429
1469
  /** Tool name surfaced to the LLM. */
1430
1470
  declare const CHOICE_TOOL_NAME = "prompt_user_choice";
1431
1471
  type ChoiceOption = {
@@ -2940,4 +2980,4 @@ interface XGetMyPostsArgs {
2940
2980
  */
2941
2981
  declare function createXTools(callProxy: XProxyCaller): Record<string, ToolConfig>;
2942
2982
 
2943
- export { ADD_SLIDE_SCHEMA, APP_BUILDER_PROMPT, APP_COMPLETE_CONNECT_ACK_TYPE, APP_COMPLETE_CONNECT_TYPE, APP_COMPLETE_DEFAULT_TIMEOUT_MS, APP_COMPLETE_IFRAME_SHIM_SCRIPT, APP_COMPLETE_REQUEST_TYPE, APP_COMPLETE_RESPONSE_TYPE, APP_COMPLETE_STUB_SCRIPT, APP_FILE_TOOL_NAMES, APP_PREVIEW_BASELINE_CSS, AUDIT_DESIGN_SCHEMA, type AgentresAccount, type AgentresClient, type AgentresClientOptions, AgentresError, type AgentresErrorCode, type AgentresLinkStatus, type AgentresLinkStep, AgentresPathError, type AnchorMatch, type AnumaChild, AnumaJsxError, type AnumaNode, type AppCompleteBridge, type AppCompleteBridgeOptions, type AppFileRecord, type AppFileStorage, type AttrValue, type AuditIssue, type AuditIssueType, type AuditResult, type AuditSeverity, type AuditTokens, type BuildSlideSystemPromptOptions, CHOICE_TOOL_NAME, CONNECTOR_ERROR_MARKER, CREATE_DOCUMENT_SCHEMA, CREATE_FILE_SCHEMA, CRITIQUE_DESIGN_SCHEMA, type CalendarEvent, type ChartDataPoint, type ChartValueFormat, type ChoiceOption, type ConfirmParameter, type ConfirmToolResult, type ConnectorErrorCode, type ConnectorMintError, type ConnectorMintResult, type ConnectorTokenGetterOpts, type ConnectorTokenSource, type CreateAppGenerationToolsOptions, type CreateDocumentToolsOptions, type CreateEventArgs, type CreateFileArgs, type CreateSelectPaymentWalletToolOptions, type CreateSlideToolsOptions, type CreateUIToolsOptions, type CreateWalletPaymentToolOptions, type CreateWeatherToolOptions, DEFAULT_DESIGN_CRITIQUE_RUBRIC, DEFAULT_DOCUMENT_ID, DEFAULT_MAX_CONVERSATIONS, DEFAULT_MAX_DOCUMENT_CONVERSATIONS, DELETE_FILE_SCHEMA, DOCUMENT_BUILDER_PROMPT, DOCUMENT_TOOL_NAMES, type DisplayChartResult, type DisplayConnectorResult, type DisplayPhoneCallOfferResult, type DisplayToolConfig, type DisplayToolMigrations, type DisplayWeatherResult, type DocAttrValue, type DocChild, DocDslError, type DocNode, type DriveFile, type DropboxRequestAccess, type DropboxTokenGetter, type ExportAppOptions, FONT_LIBRARY, FONT_PRESETS, type FileChangeEvent, type FileSnippet, type FontCategory, type FontPreset, type FontSpec, type ForecastDay, type FormField, type FormFieldOption, type FormFieldType, type GetFileContentArgs, type GmailGetMessageArgs, type GmailMessageDetail, type GmailMessageSummary, type GmailRequestAccess, type GmailSearchArgs, type GmailSendConfirmation, type GmailSendMessageArgs, type GmailTokenGetter, type InteractiveToolConfig, type KnownTag, LAYOUT_MODES, LIST_FILES_SCHEMA, type LayoutMode, type LegacyDeckJson, type ListEventsArgs, type ListRecentFilesArgs, MapFileStorage, type NotionCreatePagesArgs, type NotionFetchArgs, type NotionMcpCaller, type NotionMovePagesArgs, type NotionSearchArgs, type NotionUpdatePageArgs, PATCH_DOCUMENT_SCHEMA, PATCH_FILE_SCHEMA, PATCH_SLIDES_SCHEMA, PLAN_DECK_SCHEMA, type PatchFailure, type PatchFailureReason, type PaymentWallet, type PdfTag, READ_DOCUMENT_SCHEMA, READ_FILE_SCHEMA, READ_SLIDES_SCHEMA, RUNTIME_ERROR_OVERLAY_SCRIPT, SELECT_PAYMENT_WALLET_TOOL_NAME, SLIDES_FILE_PATH, SLIDE_CANVAS_HEIGHT, SLIDE_CANVAS_WIDTH, type SearchFilesArgs, type SelectPaymentWalletResult, SiwxChallengeError, SiwxUnsupportedError, type SlackGetChannelHistoryArgs, type SlackGetThreadRepliesArgs, type SlackListChannelsArgs, type SlackListDmsArgs, type SlackListUsersArgs, type SlackPostMessageArgs, type SlackProxyCaller, type SlackSearchMessagesArgs, type SlideToolSet, type SolanaSignMessageFn, THEME_ATTRS, type ThemeAttr, type ToolConfig, type ToolExecutionErrorType, type ToolExecutionResult, type UIInteractionContext, type UpdateEventArgs, type UpdateFileArgs, VERIFY_APP_SCHEMA, type VerifyAppResult, WALLET_PAYMENT_TOOL_NAME, type WalletPaymentOutcome, type WalletPaymentPassenger, type WalletPaymentRequest, type WalletPaymentResult, type XGetMeArgs, type XGetMyPostsArgs, type XProxyCaller, applyPatches, auditDesign, buildAppFileManifest, buildAppSystemPrompt, buildConnectorErrorResult, buildDocumentSystemPrompt, buildFontsUrl, buildSlideSystemPrompt, callNotionMCPTool, connectorMintErrorToToolResult, convertLegacyDeckJson, createAgentresClient, createAppCompleteBridge, createAppGenerationTools, createChartTool, createChatTools, createChoiceTool, createConfirmTool, createConnectorOfferTool, createConnectorTokenGetter, createDisplayTool, createDocumentTools, createDriveTools, createDropboxTools, createFormTool, createGitHubTools, createGmailTools, createGoogleCalendarCreateEventTool, createGoogleCalendarTool, createGoogleCalendarUpdateEventTool, createGoogleDriveCreateFileTool, createGoogleDriveGetContentTool, createGoogleDriveListRecentTool, createGoogleDriveSearchTool, createGoogleDriveUpdateFileTool, createInteractiveTool, createNotionCreateCommentTool, createNotionCreateDatabaseTool, createNotionCreatePagesTool, createNotionDuplicatePageTool, createNotionFetchTool, createNotionGetCommentsTool, createNotionGetTeamsTool, createNotionGetUsersTool, createNotionMovePagesTool, createNotionProxyTools, createNotionSearchTool, createNotionTools, createNotionUpdateDataSourceTool, createNotionUpdatePageTool, createPhoneCallOfferTool, createSelectPaymentWalletTool, createSlackTools, createSlideTools, createWalletPaymentTool, createWeatherTool, createXTools, documentPath, exportAppToHtml, findById, findParentOfId, getFontByName, getId, getMCPEndpoints, getNumberAttr, getStringAttr, insertAfterId, insertChild, installAppCompleteIframeShim, isAnumaTag, isHtmlTag, isKnownFont, isLegacyDeckJson, isPdfTag, migrateDisplayResult, normalizePath, parseDocumentDsl, parseJsx, pdfStyleKeys, pdfTags, removeById, replaceById, serializeJsx, truncateContent, updateAttrs, walk };
2983
+ export { ADD_SLIDE_SCHEMA, APP_BUILDER_PROMPT, APP_COMPLETE_CONNECT_ACK_TYPE, APP_COMPLETE_CONNECT_TYPE, APP_COMPLETE_DEFAULT_TIMEOUT_MS, APP_COMPLETE_IFRAME_SHIM_SCRIPT, APP_COMPLETE_REQUEST_TYPE, APP_COMPLETE_RESPONSE_TYPE, APP_COMPLETE_STUB_SCRIPT, APP_FILE_TOOL_NAMES, APP_PREVIEW_BASELINE_CSS, AUDIT_DESIGN_SCHEMA, type AgentresAccount, type AgentresClient, type AgentresClientOptions, AgentresError, type AgentresErrorCode, type AgentresLinkStatus, type AgentresLinkStep, AgentresPathError, type AnchorMatch, type AnumaChild, AnumaJsxError, type AnumaNode, type AppCompleteBridge, type AppCompleteBridgeOptions, type AppFileRecord, type AppFileStorage, type AttrValue, type AuditIssue, type AuditIssueType, type AuditResult, type AuditSeverity, type AuditTokens, type BuildSlideSystemPromptOptions, CHOICE_TOOL_NAME, CONNECTOR_ERROR_MARKER, CREATE_DOCUMENT_SCHEMA, CREATE_FILE_SCHEMA, CRITIQUE_DESIGN_SCHEMA, type CalendarEvent, type ChartDataPoint, type ChartFormatters, type ChartModel, type ChartSpec, type ChartTrend, type ChartTrendDirection, type ChartValueFormat, type ChoiceOption, type ConfirmParameter, type ConfirmToolResult, type ConnectorErrorCode, type ConnectorMintError, type ConnectorMintResult, type ConnectorTokenGetterOpts, type ConnectorTokenSource, type CreateAppGenerationToolsOptions, type CreateDocumentToolsOptions, type CreateEventArgs, type CreateFileArgs, type CreateSelectPaymentWalletToolOptions, type CreateSlideToolsOptions, type CreateUIToolsOptions, type CreateWalletPaymentToolOptions, type CreateWeatherToolOptions, DEFAULT_DESIGN_CRITIQUE_RUBRIC, DEFAULT_DOCUMENT_ID, DEFAULT_MAX_CONVERSATIONS, DEFAULT_MAX_DOCUMENT_CONVERSATIONS, DELETE_FILE_SCHEMA, DOCUMENT_BUILDER_PROMPT, DOCUMENT_TOOL_NAMES, type DisplayChartResult, type DisplayConnectorResult, type DisplayPhoneCallOfferResult, type DisplayToolConfig, type DisplayToolMigrations, type DisplayWeatherResult, type DocAttrValue, type DocChild, DocDslError, type DocNode, type DriveFile, type DropboxRequestAccess, type DropboxTokenGetter, type ExportAppOptions, FONT_LIBRARY, FONT_PRESETS, type FileChangeEvent, type FileSnippet, type FontCategory, type FontPreset, type FontSpec, type ForecastDay, type FormField, type FormFieldOption, type FormFieldType, type GetFileContentArgs, type GmailGetMessageArgs, type GmailMessageDetail, type GmailMessageSummary, type GmailRequestAccess, type GmailSearchArgs, type GmailSendConfirmation, type GmailSendMessageArgs, type GmailTokenGetter, type InteractiveToolConfig, type KnownTag, LAYOUT_MODES, LIST_FILES_SCHEMA, type LayoutMode, type LegacyDeckJson, type ListEventsArgs, type ListRecentFilesArgs, MapFileStorage, type NotionCreatePagesArgs, type NotionFetchArgs, type NotionMcpCaller, type NotionMovePagesArgs, type NotionSearchArgs, type NotionUpdatePageArgs, PATCH_DOCUMENT_SCHEMA, PATCH_FILE_SCHEMA, PATCH_SLIDES_SCHEMA, PLAN_DECK_SCHEMA, type PatchFailure, type PatchFailureReason, type PaymentWallet, type PdfTag, READ_DOCUMENT_SCHEMA, READ_FILE_SCHEMA, READ_SLIDES_SCHEMA, RUNTIME_ERROR_OVERLAY_SCRIPT, SELECT_PAYMENT_WALLET_TOOL_NAME, SLIDES_FILE_PATH, SLIDE_CANVAS_HEIGHT, SLIDE_CANVAS_WIDTH, type SearchFilesArgs, type SelectPaymentWalletResult, SiwxChallengeError, SiwxUnsupportedError, type SlackGetChannelHistoryArgs, type SlackGetThreadRepliesArgs, type SlackListChannelsArgs, type SlackListDmsArgs, type SlackListUsersArgs, type SlackPostMessageArgs, type SlackProxyCaller, type SlackSearchMessagesArgs, type SlideToolSet, type SolanaSignMessageFn, THEME_ATTRS, type ThemeAttr, type ToolConfig, type ToolExecutionErrorType, type ToolExecutionResult, type UIInteractionContext, type UpdateEventArgs, type UpdateFileArgs, VERIFY_APP_SCHEMA, type VerifyAppResult, WALLET_PAYMENT_TOOL_NAME, type WalletPaymentOutcome, type WalletPaymentPassenger, type WalletPaymentRequest, type WalletPaymentResult, type XGetMeArgs, type XGetMyPostsArgs, type XProxyCaller, applyPatches, auditDesign, buildAppFileManifest, buildAppSystemPrompt, buildChartModel, buildConnectorErrorResult, buildDocumentSystemPrompt, buildFontsUrl, buildSlideSystemPrompt, callNotionMCPTool, chartCellText, chartSeriesLabel, connectorMintErrorToToolResult, convertLegacyDeckJson, createAgentresClient, createAppCompleteBridge, createAppGenerationTools, createChartTool, createChatTools, createChoiceTool, createConfirmTool, createConnectorOfferTool, createConnectorTokenGetter, createDisplayTool, createDocumentTools, createDriveTools, createDropboxTools, createFormTool, createGitHubTools, createGmailTools, createGoogleCalendarCreateEventTool, createGoogleCalendarTool, createGoogleCalendarUpdateEventTool, createGoogleDriveCreateFileTool, createGoogleDriveGetContentTool, createGoogleDriveListRecentTool, createGoogleDriveSearchTool, createGoogleDriveUpdateFileTool, createInteractiveTool, createNotionCreateCommentTool, createNotionCreateDatabaseTool, createNotionCreatePagesTool, createNotionDuplicatePageTool, createNotionFetchTool, createNotionGetCommentsTool, createNotionGetTeamsTool, createNotionGetUsersTool, createNotionMovePagesTool, createNotionProxyTools, createNotionSearchTool, createNotionTools, createNotionUpdateDataSourceTool, createNotionUpdatePageTool, createPhoneCallOfferTool, createSelectPaymentWalletTool, createSlackTools, createSlideTools, createWalletPaymentTool, createWeatherTool, createXTools, documentPath, exportAppToHtml, findById, findParentOfId, getFontByName, getId, getMCPEndpoints, getNumberAttr, getStringAttr, insertAfterId, insertChild, installAppCompleteIframeShim, isAnumaTag, isHtmlTag, isKnownFont, isLegacyDeckJson, isPdfTag, migrateDisplayResult, normalizePath, parseDocumentDsl, parseJsx, pdfStyleKeys, pdfTags, removeById, replaceById, serializeJsx, truncateContent, updateAttrs, walk };
@@ -2497,6 +2497,157 @@ function createChartTool(options) {
2497
2497
  });
2498
2498
  }
2499
2499
 
2500
+ // src/tools/chartModel.ts
2501
+ var DOT_LIMIT = 12;
2502
+ var MAX_TICKS = 8;
2503
+ var MINUS = "\u2212";
2504
+ function chartCellText(value) {
2505
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : "";
2506
+ }
2507
+ function tickDigits(ticks) {
2508
+ if (!ticks || ticks.length < 2) return 3;
2509
+ const step = ticks[1] - ticks[0];
2510
+ const magnitude = Math.max(...ticks.map(Math.abs));
2511
+ if (step <= 0 || magnitude === 0) return 3;
2512
+ const needed = Math.floor(Math.log10(magnitude)) - Math.floor(Math.log10(step)) + 1;
2513
+ return Math.min(21, Math.max(3, needed));
2514
+ }
2515
+ function keepSmall(options) {
2516
+ const small = new Intl.NumberFormat(void 0, { ...options, maximumSignificantDigits: 3 });
2517
+ const regular = new Intl.NumberFormat(void 0, { ...options, maximumFractionDigits: 2 });
2518
+ return (n, format) => format(n !== 0 && Math.abs(n) < 1 ? small : regular, n);
2519
+ }
2520
+ function buildFormatters(format, currency, ticks) {
2521
+ const digits = tickDigits(ticks);
2522
+ if (format === "currency") {
2523
+ const money = (options) => new Intl.NumberFormat(void 0, {
2524
+ style: "currency",
2525
+ currency: currency ?? "USD",
2526
+ ...options
2527
+ });
2528
+ const compact2 = money({ notation: "compact", maximumSignificantDigits: 3 });
2529
+ const tick2 = money({ notation: "compact", maximumSignificantDigits: digits });
2530
+ const small2 = money({ maximumSignificantDigits: 4 });
2531
+ const cents = money({ minimumFractionDigits: 2, maximumFractionDigits: 2 });
2532
+ const value2 = (n) => Math.abs(n) >= 1e6 ? compact2.format(n) : n !== 0 && Math.abs(n) < 1 ? small2.format(n) : cents.format(n);
2533
+ return { tick: (n) => tick2.format(n), value: value2, change: (d) => value2(Math.abs(d)) };
2534
+ }
2535
+ if (format === "percent") {
2536
+ const percent = keepSmall({ style: "percent" });
2537
+ const points = keepSmall({});
2538
+ const tick2 = new Intl.NumberFormat(void 0, {
2539
+ style: "percent",
2540
+ maximumSignificantDigits: digits
2541
+ });
2542
+ return {
2543
+ tick: (n) => tick2.format(n / 100),
2544
+ value: (n) => percent(n, (formatter) => formatter.format(n / 100)),
2545
+ change: (d) => `${points(Math.abs(d), (formatter, n) => formatter.format(n))} pts`
2546
+ };
2547
+ }
2548
+ const tick = new Intl.NumberFormat(void 0, {
2549
+ notation: "compact",
2550
+ maximumSignificantDigits: digits
2551
+ });
2552
+ const compact = new Intl.NumberFormat(void 0, {
2553
+ notation: "compact",
2554
+ maximumSignificantDigits: 3
2555
+ });
2556
+ const small = new Intl.NumberFormat(void 0, { maximumSignificantDigits: 4 });
2557
+ const plain = new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 });
2558
+ const value = (n) => Math.abs(n) >= 1e6 ? compact.format(n) : n !== 0 && Math.abs(n) < 1 ? small.format(n) : plain.format(n);
2559
+ return { tick: (n) => tick.format(n), value, change: (d) => value(Math.abs(d)) };
2560
+ }
2561
+ function seriesValues(points, keys) {
2562
+ return points.flatMap(
2563
+ (point) => keys.map((key) => point[key]).filter((v) => typeof v === "number")
2564
+ );
2565
+ }
2566
+ function niceStep(rough) {
2567
+ const exponent = Math.floor(Math.log10(rough));
2568
+ const base = 10 ** exponent;
2569
+ const fraction = rough / base;
2570
+ const nice = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 2.5 ? 2.5 : fraction <= 5 ? 5 : 10;
2571
+ return nice * base;
2572
+ }
2573
+ function niceTicks(values) {
2574
+ if (values.length === 0) return void 0;
2575
+ const min = Math.min(...values);
2576
+ const max = Math.max(...values);
2577
+ const span = max - min || Math.abs(max) * 0.02 || 1;
2578
+ const low = min - span * 0.1;
2579
+ const high = max + span * 0.1;
2580
+ const step = niceStep((high - low) / 3);
2581
+ const start = min >= 0 ? Math.max(0, Math.floor(low / step) * step) : Math.floor(low / step) * step;
2582
+ const ticks = [];
2583
+ for (let index = 0; index <= MAX_TICKS; index++) {
2584
+ const tick = Number((start + index * step).toPrecision(15));
2585
+ if (ticks.length > 0 && tick <= ticks[ticks.length - 1]) break;
2586
+ ticks.push(tick);
2587
+ if (tick >= high) break;
2588
+ }
2589
+ return ticks.length >= 2 ? ticks : void 0;
2590
+ }
2591
+ function buildTrend(values, format, formatters) {
2592
+ if (values.length < 2) return void 0;
2593
+ const first = values[0];
2594
+ const last = values[values.length - 1];
2595
+ const difference = last - first;
2596
+ const direction = difference > 0 ? "up" : difference < 0 ? "down" : "flat";
2597
+ const sign = direction === "up" ? "+" : direction === "down" ? MINUS : "";
2598
+ const percent = format !== "percent" && first !== 0 ? ` (${sign}${new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 }).format(
2599
+ Math.abs(difference / Math.abs(first) * 100)
2600
+ )}%)` : "";
2601
+ return {
2602
+ value: formatters.value(last),
2603
+ change: `${sign}${formatters.change(difference)}${percent}`,
2604
+ direction
2605
+ };
2606
+ }
2607
+ function lastValueIndex(points, key) {
2608
+ for (let index = points.length - 1; index >= 0; index--) {
2609
+ if (typeof points[index][key] === "number") return index;
2610
+ }
2611
+ return -1;
2612
+ }
2613
+ function chartSeriesLabel(key) {
2614
+ return key.charAt(0).toUpperCase() + key.slice(1);
2615
+ }
2616
+ function buildChartModel(spec) {
2617
+ const { chartType, title, data, dataKeys, xAxisKey, valueFormat, currency } = spec;
2618
+ const isTrendChart = chartType === "line" || chartType === "area";
2619
+ const plottedKeys = chartType === "pie" ? dataKeys.slice(0, 1) : dataKeys;
2620
+ const values = seriesValues(data, plottedKeys);
2621
+ const yTicks = isTrendChart ? niceTicks(values) : void 0;
2622
+ const yDomain = yTicks ? [yTicks[0], yTicks[yTicks.length - 1]] : void 0;
2623
+ const formatters = buildFormatters(valueFormat, currency, yTicks);
2624
+ const seriesLabels = Object.fromEntries(dataKeys.map((key) => [key, chartSeriesLabel(key)]));
2625
+ const trendBase = isTrendChart && dataKeys.length === 1 ? buildTrend(values, valueFormat, formatters) : void 0;
2626
+ const trendRows = trendBase ? data.filter((point) => typeof point[dataKeys[0]] === "number") : [];
2627
+ const range = trendBase && xAxisKey ? [trendRows[0], trendRows[trendRows.length - 1]].map((point) => chartCellText(point[xAxisKey])).filter(Boolean).join(" \u2013 ") || void 0 : void 0;
2628
+ const trend = trendBase ? { ...trendBase, range } : void 0;
2629
+ const tickSamples = [...yDomain ?? [], ...values].map((value) => formatters.tick(value));
2630
+ const showDots = data.length <= DOT_LIMIT;
2631
+ return {
2632
+ isTrendChart,
2633
+ plottedKeys,
2634
+ seriesLabels,
2635
+ labelKey: chartType === "pie" ? xAxisKey || "name" : xAxisKey,
2636
+ values,
2637
+ yTicks,
2638
+ yDomain,
2639
+ formatters,
2640
+ trend,
2641
+ title: title ?? (trend ? seriesLabels[dataKeys[0]] : void 0),
2642
+ showDots,
2643
+ endIndexes: Object.fromEntries(plottedKeys.map((key) => [key, lastValueIndex(data, key)])),
2644
+ curve: showDots ? "linear" : "monotone",
2645
+ hasNegative: values.some((value) => value < 0),
2646
+ longestTickLength: tickSamples.reduce((max, label) => Math.max(max, label.length), 0),
2647
+ total: values.reduce((sum, value) => sum + value, 0)
2648
+ };
2649
+ }
2650
+
2500
2651
  // src/tools/choice.ts
2501
2652
  var CHOICE_TOOL_NAME = "prompt_user_choice";
2502
2653
  function createChoiceTool(options) {
@@ -13979,11 +14130,14 @@ export {
13979
14130
  auditDesign,
13980
14131
  buildAppFileManifest,
13981
14132
  buildAppSystemPrompt,
14133
+ buildChartModel,
13982
14134
  buildConnectorErrorResult,
13983
14135
  buildDocumentSystemPrompt,
13984
14136
  buildFontsUrl,
13985
14137
  buildSlideSystemPrompt,
13986
14138
  callNotionMCPTool,
14139
+ chartCellText,
14140
+ chartSeriesLabel,
13987
14141
  connectorMintErrorToToolResult,
13988
14142
  convertLegacyDeckJson,
13989
14143
  createAgentresClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "11.2.0",
3
+ "version": "11.3.1",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",