Skip to content

Commit 87a97a4

Browse files
leondt1xueren.dthustcc
authored
chore(ava): optimise ckb folder structure (#844)
* chore(ava): optimise ckb folder structure * chore(ava): update eslint rule and fix test ts problem * fix(ava): fix auto ci problem --------- Co-authored-by: xueren.dt <xueren.dt@antgroup.com> Co-authored-by: hustcc <i@hust.cc>
1 parent 37da4ac commit 87a97a4

47 files changed

Lines changed: 77 additions & 4934 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.js

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -79,33 +79,7 @@ module.exports = {
7979
'@typescript-eslint/no-explicit-any': 0,
8080
'@typescript-eslint/type-annotation-spacing': 0,
8181
'no-await-in-loop': 0,
82-
'import/order': [
83-
2,
84-
{
85-
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object', 'type', 'unknown'],
86-
pathGroups: [
87-
{
88-
pattern: 'react',
89-
group: 'external',
90-
position: 'before',
91-
},
92-
{
93-
pattern: '@/**',
94-
group: 'internal',
95-
position: 'before',
96-
},
97-
{
98-
pattern: '*.{less,css}',
99-
patternOptions: { matchBase: true },
100-
group: 'unknown',
101-
position: 'after',
102-
},
103-
],
104-
pathGroupsExcludedImportTypes: ['builtin', 'type'],
105-
warnOnUnassignedImports: true,
106-
'newlines-between': 'always',
107-
},
108-
],
82+
'import/order': 0,
10983
'no-param-reassign': 1,
11084
'no-continue': 1,
11185
'no-bitwise': 1,
@@ -123,5 +97,7 @@ module.exports = {
12397
project: ['./tsconfig.json']
12498
},
12599
},
100+
// 兼容 exports 子路径导入,避免旧版插件误报为非依赖
101+
'import/core-modules': ['@antv/mcp-server-chart/sdk'],
126102
},
127103
};

.fatherrc.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ export default defineConfig({
55
umd: {
66
name: 'AVA',
77
output: 'dist',
8+
externals: {
9+
'@antv/mcp-server-chart/sdk': '@antv/mcp-server-chart/sdk',
10+
},
811
},
912
alias: {
10-
'@ava': path.resolve(__dirname, 'src'),
11-
'@advisor': path.resolve(__dirname, 'src/advisor'),
13+
'@antv/mcp-server-chart/sdk': path.resolve(
14+
__dirname,
15+
'node_modules/@antv/mcp-server-chart/build/sdk.js'
16+
),
1217
}
1318
});

__tests__/global.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
declare global {
2+
namespace jest {
3+
interface Matchers<R, _T = {}> {
4+
toBeCloseToArray(expected: number[] | number[][]): R;
5+
toBeCloseToObject(expected: Record<string, any>): R;
6+
}
7+
}
8+
}
9+
10+
export {};

__tests__/unit/utils/statictics.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ test.skip('statistics', () => {
9898
expect(valueMap([1, null])).toEqual({ 1: 1, null: 1 });
9999
expect(median([1, 3, 2, 4, 5])).toBe(3);
100100
expect(median([1, 2, 3, 4])).toBe(2.5);
101-
expect(() => quartile([1])).toThrowError('The length of value cannot be less than 3.');
101+
expect(() => quartile([1])).toThrow('The length of value cannot be less than 3.');
102102
expect(quartile([1, 2, 3, 4, 5, 6, 7, 8, 9])).toEqual([2.5, 5, 7.5]);
103103
expect(quartile([1, 2, 3, 4, 5, 6, 7, 8, 9], true)).toEqual([2.5, 5, 7.5]);
104104
expect(quartile([1, 2, 3, 4, 5, 6, 7, 8])).toEqual([2.5, 4.5, 6.5]);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@antv/algorithm": "^0.1.26",
4242
"@antv/color-schema": "^0.2.3",
4343
"@antv/gpt-vis": "^0.5.9",
44+
"@antv/mcp-server-chart": "^0.9.3",
4445
"@antv/smart-color": "^0.2.1",
4546
"axios": "^1.12.2",
4647
"bayesian-changepoint": "^1.0.1",

src/advisor/advise-chart-pipeline/plugins/advisePlugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
import { AdviseChartPluginEnum } from '../../../constants/pipeline';
1111
import { DATA_SHAPE } from '../../../extract/constants';
1212
import { getChartAdvisePrompt, getSpecGeneratePrompt } from '../../chartAdvise/prompt';
13-
import { CHART_ID_MAP } from '../../../ckb';
1413
import { Spec } from '../../../bind';
1514

1615
export class AdvisePlugin implements AdvisorPlugin<AdviseChartParams> {
@@ -53,7 +52,7 @@ export class AdvisePlugin implements AdvisorPlugin<AdviseChartParams> {
5352
const adviseInputs = getChartAdvisePrompt(params);
5453
const recommendationStr = await requestLLM({ config: llm, prompt: adviseInputs });
5554
const recommendation = safeJsonParse(recommendationStr, []);
56-
const bestCharts = recommendation.map((item) => CHART_ID_MAP[item[0]]) as string[];
55+
const bestCharts = recommendation.map((item) => item[0]) as string[];
5756
const specGenerateInputs = dataShards.map((shard, index) => {
5857
const { data } = shard;
5958
return {

src/advisor/chartAdvise/prompt/index.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { CKB, VISUAL_CHANNEL_DESCRIPTION } from '../../../ckb/ckb-v2';
22
import { CHART_NAME, CHART_PURPOSE_NAME_MAP, FULL_AND_ABBR_CHART_NAME_MAP } from '../../../constants';
3-
import { ChartConfig, ChartKnowledgeMap, Data, Meta, PlainLikeDataType } from '../../../types';
4-
import { CHART_ID_LIST } from '../../../ckb';
5-
import * as CHARTS from '../../../ckb/charts';
3+
import { ChartConfig, Data, Meta, PlainLikeDataType } from '../../../types';
4+
import { CHARTS } from '../../../ckb';
65

76
const ROLE_CONTEXT = `
87
# 角色设定
@@ -181,31 +180,34 @@ export const getGraphAdvisePrompt = (params: {
181180
};
182181

183182
export const getChartAdvisePrompt = (params: { metas: Meta[]; data: PlainLikeDataType; purpose: string }[]) => {
184-
const chartDescriptions = Object.entries(CHARTS as ChartKnowledgeMap)
185-
.map(([chartId, item]) => `${chartId}: ${item.description}`)
183+
const chartIds = Object.keys(CHARTS);
184+
const chartDescriptions = Object.entries(CHARTS)
185+
.map(([chartId, item]) => {
186+
return `${chartId}: ${item.tool.description}`;
187+
})
186188
.join('\n\n');
187189
return `
188190
# Role
189-
You are a chart recommendation and configuration generation expert, capable of selecting the most suitable chart type from the given Chart Knowledge Base (CKB) based on data and requirements.
191+
You are a chart recommendation and configuration generation expert, capable of selecting the most suitable chart type from the given Chart Knowledge Base based on data and requirements.
190192
191193
# Objective
192-
Output the “best chart type (chartId)” with the rationale for selection, and provide 1–2 alternative chart types with reasons why they are not chosen as the primary chart. Only choose types from the provided CKB.
194+
Output the “best chart type (chartId)” with the rationale for selection, and provide 1–2 alternative chart types with reasons why they are not chosen as the primary chart. Only choose types from the provided Chart Knowledge Base.
193195
194196
# Inputs
195197
- data: raw data (array) used to draw charts.
196198
- meta: field metadata (array), each item includes id, name, dataType (number/string/date/geo).
197199
- purpose: visualization intent (a sentence or several bullet points).
198-
- CKB: the collection of knowledge definitions for all available charts (including chart names, usage descriptions, etc.).
200+
- Chart Knowledge Base: the collection of knowledge definitions for all available charts (including chart names, usage descriptions, etc.).
199201
- Batch input support: The input may be an array containing multiple items, each with data, meta, and purpose. When the input is an array, you must make a recommendation for each item independently and output results in the same order as the input.
200202
201203
# Output
202-
- chartCodesList: a two-dimensional array. Each item is a string array whose elements are chart “short codes” (see “Chart Types and Codes”), ordered from best to worst match, up to 3 items.
204+
- chartIdsList: a two-dimensional array. Each item is a string array whose elements are chartId (from the provided CKB list), ordered from best to worst match, up to 3 items.
203205
- If candidates are fewer than 3, output the actual number; do not exceed 3.
204-
- When the input is a single item, still output a two-dimensional array (e.g., [["l", "a", "c"]]).
206+
- When the input is a single item, still output a two-dimensional array (e.g., [["line", "area", "column"]]).
205207
- Only output a JSON two-dimensional array, without any explanatory text, object keys, or code block markers.
206208
207209
# Strict Constraints (Must Follow)
208-
- Only select chart types from the provided CKB; do not add or remove types.
210+
- Only select chart types from the provided Chart Knowledge Base; do not add or remove types.
209211
- The output must be a strict JSON string; do not include any extra text, explanations, prefixes/suffixes, or code block markers.
210212
- Determine fitness based on data and meta; avoid subjective guessing; do not fabricate fields or change data.
211213
- If multiple chart types satisfy the needs, prefer the one that “clearly expresses the core intent with lower cognitive load”.
@@ -235,12 +237,12 @@ Output the “best chart type (chartId)” with the rationale for selection, and
235237
4. Selection and ranking: sort by evaluation dimensions, determine the primary chart and alternatives, and explain trade-offs (readability, order preservation, intent alignment, data match).
236238
237239
# Response Format (JSON)
238-
- Only output a JSON two-dimensional array of “short codes”. Each item is a string array (up to 3, ordered from highest to lowest match). Do not output any extra text, e.g., [["l", "a", "c"], ["b", "c"]].
240+
- Only output a JSON two-dimensional array of chartId. Each item is a string array (up to 3, ordered from highest to lowest match). Do not output any extra text, e.g., [["line", "area", "column"], ["bar", "scatter"]].
239241
- Output MUST be a plain JSON string; do not use Markdown code fences (e.g., \`\`\`JSON).
240242
241-
# Chart Knowledge Base (CKB)
242-
## Chart Types and Codes (object array)
243-
${JSON.stringify(CHART_ID_LIST)}
243+
# Chart Knowledge Base
244+
## Chart Types (chartId list)
245+
${JSON.stringify(chartIds)}
244246
245247
## Chart Function Descriptions
246248
${chartDescriptions}
@@ -253,9 +255,7 @@ ${JSON.stringify(params)}
253255
export const getSpecGeneratePrompt = (params: { chartId: string; data: PlainLikeDataType }[]) => {
254256
const inputSchema = params
255257
.map((item) => {
256-
return `ChartId: ${item.chartId}\nInputSchema: ${JSON.stringify(
257-
(CHARTS as ChartKnowledgeMap)[item.chartId].inputSchema
258-
)}`;
258+
return `ChartId: ${item.chartId}\nInputSchema: ${JSON.stringify(CHARTS[item.chartId].tool.inputSchema)}`;
259259
})
260260
.join('\n\n');
261261
return `

0 commit comments

Comments
 (0)