Skip to content

Commit 6f6a09e

Browse files
committed
feat(visualization): generate requested T8 summaries
1 parent a961be8 commit 6f6a09e

13 files changed

Lines changed: 51 additions & 28 deletions

File tree

‎__tests__/chart-contracts.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ describe('native chart contracts', () => {
2626
}
2727
});
2828

29-
it('accepts native summary strings without adding summaries to automatic chart recommendations', async () => {
29+
it('renders native summary strings', async () => {
3030
const ava = new AVA({ llm: { model: 'unused' } });
3131
const spec = { chartType: 'summary' as const, config: '# Sales report\nRevenue increased by 10%.' };
3232
const html = await ava.viz(spec);
3333
expect(runInNewContext(`(${html.match(/const visConfig = (.+);/)![1]})`, {}, { timeout: 1000 })).toBe(spec.config);
34-
expect(chartDefinitions.some((chart) => chart.type === 'summary')).toBe(false);
3534
expect(() => vizInputSchema.parse({ ...spec, config: { type: 'summary', text: 'Report' } })).toThrow();
3635
for (const config of ['', ' ', 'vis column\ndata\n - category A\n value 1']) {
3736
expect(() => vizInputSchema.parse({ ...spec, config })).toThrow();

‎__tests__/visualization.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ describe('chart recommendation', () => {
5656
await expect(ava['recommend'](result)).rejects.toThrow('Model unavailable');
5757
});
5858

59+
it('generates and renders a requested T8 summary through visualize', async () => {
60+
const query = 'Create a T8 summary of revenue by city';
61+
const summary = '# Revenue\nHangzhou earned [100](metric_value, origin=100).';
62+
reply('summary');
63+
reply(`\`\`\`t8\n${summary}\n\`\`\``);
64+
65+
const visualization = await ava.visualize({ ...result, query });
66+
67+
expect(visualization).toMatchObject({ chartType: 'summary', config: summary });
68+
expect(vi.mocked(generateText).mock.calls[0][0].prompt).toContain('"summary"');
69+
expect(vi.mocked(generateText).mock.calls[1][0].prompt).toContain('metric_value');
70+
expect(
71+
runInNewContext(`(${visualization!.html.match(/const visConfig = (.+);/)![1]})`, {}, { timeout: 1000 })
72+
).toBe(summary);
73+
});
74+
5975
it('renders the recommended specification through visualize', async () => {
6076
const onEvent = vi.fn();
6177
ava.on('visualizestart', onEvent);

‎site/content/docs/en/reference/api.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ Neither requires a loaded source. Both use the model and return `null` for empty
373373

374374
`ChartType` values: `line`, `column`, `bar`, `pie`, `area`, `scatter`, `dual-axes`, `histogram`, `boxplot`, `radar`, `funnel`, `waterfall`, `liquid`, `word-cloud`, `violin`, `venn`, `treemap`, `sankey`, `table`, `summary`.
375375

376-
GPT-Vis supports 26 visualization types. AVA recommends the 19 JSON chart types above and additionally accepts native summary strings through `viz({ chartType: 'summary', config: '# Sales report' })`. The six relationship graph types are outside AVA's current contract. `ChartSpec` describes the normalized result, with `config.type` filled for JSON charts.
376+
GPT-Vis supports 26 visualization types. AVA recommends the 19 JSON chart types above. When the query explicitly requests a T8 summary, `recommend()` and `visualize()` use `chartType: 'summary'` with T8 text in `config`. You can also render T8 text directly through `viz({ chartType: 'summary', config: '# Sales report' })`. The six relationship graph types are outside AVA's current contract. `ChartSpec` describes the normalized result, with `config.type` filled for JSON charts.
377377

378378
`spec.html?: string` accepts the complete result from `visualize()`. Rendering always uses `config` to generate fresh HTML; an existing `html` value is not reused. Other unknown envelope fields are rejected.
379379

‎site/content/docs/en/visualization/overview.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@ if (spec) {
9494
| Composition & flow | `pie`, `treemap`, `sankey`, `waterfall`, `funnel` |
9595
| Other | `radar`, `liquid`, `word-cloud`, `venn`, `table` |
9696

97-
The table lists AVA's 19 recommended JSON chart types. GPT-Vis itself supports 26 types; AVA additionally accepts native summary strings through `viz({ chartType: 'summary', config: '# Sales report' })`. Its six relationship graph types are outside AVA's current contract. A chart's suitability depends on its data requirements and the user's question. The recommendation module supplies the 19 chart definitions to the model.
97+
The table lists AVA's 19 recommended JSON chart types. For an explicit T8 summary request, `recommend()` and `visualize()` return `chartType: 'summary'` with a T8 string in `config`. You can also render a T8 string through `viz({ chartType: 'summary', config: '# Sales report' })`. The six GPT-Vis relationship graph types are outside AVA's current contract. A chart's suitability depends on its data requirements and the user's question. The recommendation module supplies the 19 chart definitions to the model.
9898

9999
See [recommend parameters](/documentation/reference/api/#visualize-and-recommend) and [viz parameters](/documentation/reference/api/#viz) for all fields and chart types.

‎site/content/docs/zh/reference/api.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ Setter 接收选项对象,同步返回 `Semantic`。AVA 验证并复制结果
375375

376376
`ChartType` 可选值:`line`、`column`、`bar`、`pie`、`area`、`scatter`、`dual-axes`、`histogram`、`boxplot`、`radar`、`funnel`、`waterfall`、`liquid`、`word-cloud`、`violin`、`venn`、`treemap`、`sankey`、`table`、`summary`。
377377

378-
GPT-Vis 支持 26 种可视化类型。AVA 自动推荐上述 19 种 JSON 图表,也允许通过 `viz({ chartType: 'summary', config: '# 销售报告' })` 渲染原生摘要字符串。6 种关系图暂不在 AVA 契约范围内。`ChartSpec` 描述规范化后的结果,其中 JSON 图表的 `config.type` 已补齐。
378+
GPT-Vis 支持 26 种可视化类型。AVA 自动推荐上述 19 种 JSON 图表。查询明确要求 T8 摘要时,`recommend()` 和 `visualize()` 返回 `chartType: 'summary'`,`config` 为 T8 文本。也可以通过 `viz({ chartType: 'summary', config: '# 销售报告' })` 渲染原生摘要字符串。6 种关系图暂不在 AVA 契约范围内。`ChartSpec` 描述规范化后的结果,其中 JSON 图表的 `config.type` 已补齐。
379379

380380
`spec.html?: string` 用于接收 `visualize()` 的完整返回值。渲染始终根据 `config` 生成新的 HTML,不复用已有 `html`;外层其他未知字段会被拒绝。
381381

‎site/content/docs/zh/visualization/overview.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,6 @@ if (spec) {
9696
| 构成与流向 | `pie`, `treemap`, `sankey`, `waterfall`, `funnel` |
9797
| 其他 | `radar`, `liquid`, `word-cloud`, `venn`, `table` |
9898

99-
上表列出 AVA 自动推荐的 19 种 JSON 图表。GPT-Vis 本身支持 26 种类型;AVA 还支持通过 `viz({ chartType: 'summary', config: '# 销售报告' })` 渲染原生摘要字符串,其余 6 种关系图暂不在 AVA 契约范围内。图表是否合适,取决于数据要求和用户问题。推荐模块会将 19 种图表的定义提供给模型。
99+
上表列出 AVA 自动推荐的 19 种 JSON 图表。查询明确要求 T8 摘要时,`recommend()` 和 `visualize()` 返回 `chartType: 'summary'`,`config` 为 T8 字符串。也可以通过 `viz({ chartType: 'summary', config: '# 销售报告' })` 渲染 T8 字符串。GPT-Vis 的 6 种关系图暂不在 AVA 契约范围内。图表是否合适,取决于数据要求和用户问题。推荐模块会将 19 种图表的定义提供给模型。
100100

101101
完整字段与图表类型见 [recommend 参数](/documentation/reference/api/#visualize-and-recommend)和 [viz 参数](/documentation/reference/api/#viz)。

‎skills/ava/references/visualization.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Visualization
22

3-
Verified against the published `@antv/gpt-vis` **1.3.1** package (2026-11-09). Use the [official chart reference](https://gpt-vis.antv.vision/docs/charts) for native options. AVA accepts a JSON Spec; SDK Syntax strings and T8 Summary text are not CLI inputs.
3+
Verified against the published `@antv/gpt-vis` **1.3.1** package (2026-11-09). Use the [official chart reference](https://gpt-vis.antv.vision/docs/charts) for native options. AVA accepts a JSON spec; use a T8 string as `config` when `chartType` is `summary`.
44

55
## Spec and Field Mapping
66

7-
A Spec has exactly two keys: `{ "chartType": "…", "config": {…} }`. Put the fields below directly in `config`; most types use `config.data` as an array of row objects. `value`, `x`, and `y` must be numbers. Map a second dimension to row field `group`.
7+
A chart spec uses `{ "chartType": "…", "config": {…} }`. Put the fields below directly in `config`; most types use `config.data` as an array of row objects. `value`, `x`, and `y` must be numbers. Map a second dimension to row field `group`.
88

9-
GPT-Vis supports 26 types; AVA currently accepts the 19 below. Its CLI does not register `flow-diagram`, `network-graph`, `mindmap`, `indented-tree`, `organization-chart`, `fishbone-diagram`, or `summary`.
9+
The table lists the 19 JSON chart types. A query that explicitly requests a T8 summary can also produce `{ "chartType": "summary", "config": "# Sales report" }`.
1010

1111
| `chartType` | Data fields or structure |
1212
| --- | --- |

‎src/ava.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,11 @@ export class AVA extends EventEmitter {
313313
}
314314

315315
/**
316-
* Visualize analysis data by recommending a chart type and generating chart HTML.
316+
* Visualize analysis data as a chart or T8 summary with standalone HTML.
317317
* Accepts the result from analyze() — the query and data are read from it.
318318
*
319319
* @param analysisResult - The result returned from analyze()
320-
* @returns VisualizeResponse, or null if no chart is needed. Generation errors propagate to the caller.
320+
* @returns VisualizeResponse, or null if no visualization is recommended. Generation errors propagate to the caller.
321321
*/
322322
async visualize(analysisResult: Pick<AnalysisResponse, 'query' | 'data'>): Promise<VisualizeResponse | null> {
323323
emit(this, new LifecycleEvent(LifecycleEventType.VISUALIZE_START, { query: analysisResult.query }));
@@ -338,8 +338,7 @@ export class AVA extends EventEmitter {
338338
}
339339

340340
/**
341-
* Recommend a chart specification for the analysis result.
342-
* Combine a suitable chart type with GPT-Vis JSON config for rendering.
341+
* Recommend a chart or T8 summary specification for the analysis result.
343342
*/
344343
async recommend(analysisResult: Pick<AnalysisResponse, 'query' | 'data'>): Promise<ChartSpec | null> {
345344
const { data, query } = analysisResult;

‎src/cli/commands/recommend.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { option } from '../options';
77

88
import type { Options } from '../options';
99

10-
export const description = 'Recommend a chart specification';
10+
export const description = 'Recommend a chart or T8 summary';
1111

1212
export const definition = {
1313
positionals: 0,
@@ -35,7 +35,8 @@ export const help = `${description}.
3535
Usage:
3636
ava recommend --query "<text>" --data <json|@file|->
3737
38-
Returns { "chartType": "...", "config": {...} }, or null if no chart is recommended.
38+
Returns { chartType, config }, or null if no visualization is recommended.
39+
The config is a JSON object for charts or a T8 string for summaries.
3940
A non-null result can be passed to ava viz --spec.
4041
4142
Options:

‎src/cli/commands/visualize.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { option } from '../options';
77

88
import type { Options } from '../options';
99

10-
export const description = 'Generate a chart from query and data';
10+
export const description = 'Generate a chart or T8 summary from query and data';
1111

1212
export const definition = {
1313
positionals: 0,
@@ -41,7 +41,7 @@ export const help = `${description}.
4141
Usage:
4242
ava visualize --query "<text>" --data <json|@file|-> [options]
4343
44-
Returns { chartType, config, html } as JSON, or null if no chart is recommended.
44+
Returns { chartType, config, html } as JSON, or null if no visualization is recommended.
4545
With --output, also writes HTML and includes its absolute path in output.
4646
4747
Options:

0 commit comments

Comments
 (0)