Skip to content

Commit ae9ffdd

Browse files
lxfu1福晋
andauthored
chore: skill rename to doc (#92)
* chore: skill rename to doc * chore: code opt --------- Co-authored-by: 福晋 <liufu.lf@antgroup.com>
1 parent 782409c commit ae9ffdd

18 files changed

Lines changed: 495 additions & 320 deletions

__tests__/info.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ import { describe, it, expect } from 'vitest';
22
import { info } from '../src/api';
33

44
describe('info API', () => {
5-
it('should return skill info for default library', () => {
5+
it('should return doc info for default library', () => {
66
const result = info();
77
expect(result).toBeDefined();
88
expect(result!.name).toBe('antv-g2-chart');
99
expect(result!.description.length).toBeGreaterThan(0);
1010
expect(result!.content.length).toBeGreaterThan(0);
1111
});
1212

13-
it('should return skill info for g2 library', () => {
13+
it('should return doc info for g2 library', () => {
1414
const result = info('g2');
1515
expect(result).toBeDefined();
1616
expect(result).toHaveProperty('name');
1717
expect(result).toHaveProperty('description');
1818
expect(result).toHaveProperty('content');
1919
});
2020

21-
it('should return undefined for library without SKILL.md', () => {
21+
it('should return undefined for library without DOC.md', () => {
2222
const result = info('g6');
2323
// g6 may or may not have a SKILL.md
2424
expect(result === undefined || typeof result.name === 'string').toBe(true);

__tests__/retrieve.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('retrieve API', () => {
1616
}
1717
};
1818

19-
it('should retrieve skills with default parameters', async () => {
19+
it('should retrieve docs with default parameters', async () => {
2020
const results = await retrieve('折线图');
2121
// Defaults: content=true, includeConstraints=true
2222
if (zvecReady) {

__tests__/token-budget.test.ts

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
formatForBudget,
77
applyTokenBudget
88
} from '../src/core/token-budget';
9-
import type { Skill } from '../src/core/types';
9+
import type { Doc } from '../src/core/types';
1010

1111
describe('token-budget', () => {
1212
describe('estimateTokens', () => {
@@ -34,7 +34,8 @@ describe('token-budget', () => {
3434

3535
describe('extractCodeBlocks', () => {
3636
it('should extract fenced code blocks from markdown', () => {
37-
const content = 'Some text\n```js\nconst x = 1;\n```\nMore text\n```ts\nconst y = 2;\n```';
37+
const content =
38+
'Some text\n```js\nconst x = 1;\n```\nMore text\n```ts\nconst y = 2;\n```';
3839
const blocks = extractCodeBlocks(content);
3940
expect(blocks).toHaveLength(2);
4041
expect(blocks[0]).toContain('const x = 1');
@@ -70,10 +71,9 @@ describe('token-budget', () => {
7071
});
7172

7273
describe('formatForBudget', () => {
73-
const baseSkill: Skill = {
74-
id: 'test-skill',
75-
title: 'Test Skill',
76-
title_en: 'Test Skill',
74+
const baseDoc: Doc = {
75+
id: 'test-doc',
76+
title: 'Test Doc',
7777
description: 'A test description',
7878
library: 'g2',
7979
version: '5.x',
@@ -83,47 +83,47 @@ describe('token-budget', () => {
8383
use_cases: [],
8484
anti_patterns: [],
8585
related: [],
86-
content: '## Intro\nSome text\n```js\nconst x = 1;\n```\nMore details here.'
86+
content:
87+
'## Intro\nSome text\n```js\nconst x = 1;\n```\nMore details here.'
8788
};
8889

8990
it('level 0: should return full content', () => {
90-
const result = formatForBudget(baseSkill, 0, 500);
91-
expect(result).toContain('Test Skill');
91+
const result = formatForBudget(baseDoc, 0, 500);
92+
expect(result).toContain('Test Doc');
9293
expect(result).toContain('Some text');
9394
expect(result).toContain('const x = 1');
9495
expect(result).toContain('More details');
9596
});
9697

9798
it('level 1: should return summary + code blocks only', () => {
98-
const result = formatForBudget(baseSkill, 1, 500);
99-
expect(result).toContain('Test Skill');
99+
const result = formatForBudget(baseDoc, 1, 500);
100+
expect(result).toContain('Test Doc');
100101
expect(result).toContain('A test description');
101102
expect(result).toContain('const x = 1');
102103
// Should NOT contain the prose "More details" (it's not in a code block)
103104
expect(result).not.toContain('More details');
104105
});
105106

106107
it('level 2: should return summary only', () => {
107-
const result = formatForBudget(baseSkill, 2, 500);
108-
expect(result).toContain('Test Skill');
108+
const result = formatForBudget(baseDoc, 2, 500);
109+
expect(result).toContain('Test Doc');
109110
expect(result).toContain('A test description');
110111
// Should NOT contain any body content
111112
expect(result).not.toContain('Some text');
112113
expect(result).not.toContain('const x = 1');
113114
});
114115

115116
it('should truncate when budget is too small for code blocks', () => {
116-
const result = formatForBudget(baseSkill, 1, 5);
117+
const result = formatForBudget(baseDoc, 1, 5);
117118
// Very small budget — should fallback to truncateContent
118119
expect(result.length).toBeGreaterThan(0);
119120
});
120121
});
121122

122123
describe('applyTokenBudget', () => {
123-
const makeSkill = (id: string, content: string): Skill => ({
124+
const makeDoc = (id: string, content: string): Doc => ({
124125
id,
125-
title: `Skill ${id}`,
126-
title_en: `Skill ${id}`,
126+
title: `Doc ${id}`,
127127
description: '',
128128
library: 'g2',
129129
version: '',
@@ -136,44 +136,45 @@ describe('token-budget', () => {
136136
content
137137
});
138138

139-
it('should give full budget to __info__ and trim remaining skills', () => {
140-
const skills: Skill[] = [
139+
it('should give full budget to __info__ and trim remaining docs', () => {
140+
const docs: Doc[] = [
141141
{
142-
...makeSkill('__info__g2', 'Core constraints text that is important'),
142+
...makeDoc('__info__g2', 'Core constraints text that is important'),
143143
category: '__info__'
144144
},
145-
makeSkill('skill-1', 'Content for skill one'),
146-
makeSkill('skill-2', 'Content for skill two'),
145+
makeDoc('doc-1', 'Content for doc one'),
146+
makeDoc('doc-2', 'Content for doc two')
147147
];
148148

149-
const result = applyTokenBudget(skills, 20, 1);
149+
const result = applyTokenBudget(docs, 20, 1);
150150
// __info__ should keep its content
151151
expect(result[0].content).toBeDefined();
152152
});
153153

154154
it('should set content to undefined when budget exhausted', () => {
155-
const skills: Skill[] = [
155+
const docs: Doc[] = [
156156
{
157-
...makeSkill('__info__g2', 'Very long constraints content eating all budget'),
157+
...makeDoc(
158+
'__info__g2',
159+
'Very long constraints content eating all budget'
160+
),
158161
category: '__info__'
159162
},
160-
makeSkill('skill-1', 'Short content'),
161-
makeSkill('skill-2', 'Another content'),
163+
makeDoc('doc-1', 'Short content'),
164+
makeDoc('doc-2', 'Another content')
162165
];
163166

164167
// Very small budget — info consumes it all
165-
const result = applyTokenBudget(skills, 5, 1);
166-
// Skills after info should have no content
168+
const result = applyTokenBudget(docs, 5, 1);
169+
// Docs after info should have no content
167170
expect(result[1].content).toBeUndefined();
168171
expect(result[2].content).toBeUndefined();
169172
});
170173

171-
it('should handle no __info__ skill gracefully', () => {
172-
const skills: Skill[] = [
173-
makeSkill('skill-1', 'Content for skill one'),
174-
];
174+
it('should handle no __info__ doc gracefully', () => {
175+
const docs: Doc[] = [makeDoc('doc-1', 'Content for doc one')];
175176

176-
const result = applyTokenBudget(skills, 50, 0);
177+
const result = applyTokenBudget(docs, 50, 0);
177178
expect(result[0].content).toBeDefined();
178179
});
179180
});

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/chart-visualization-skills",
3-
"version": "0.1.3",
3+
"version": "0.1.4-beta.1",
44
"description": "Chart visualization skills for AntV, can be used in various scenarios such as data analysis, business intelligence, and dashboard development. Skills and CLI are included.",
55
"type": "commonjs",
66
"main": "dist/api.js",
@@ -48,5 +48,9 @@
4848
},
4949
"author": "AntV AI Team",
5050
"license": "MIT",
51-
"repository": "git@github.com:antvis/chart-visualization-skills.git"
51+
"repository": "git@github.com:antvis/chart-visualization-skills.git",
52+
"publishConfig": {
53+
"registry": "https://registry.npmjs.org/",
54+
"access": "public"
55+
}
5256
}

src/api.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
11
import {
22
retrieve as _retrieve,
3-
getSkillById as _getSkillById,
4-
getSkillInfo,
3+
getDocById as _getDocById,
4+
getDocInfo,
55
availableLibraries,
6-
listSkills as _listSkills
6+
listDocs as _listDocs
77
} from './core/retriever';
88
import type {
9-
Skill,
10-
SkillInfo,
9+
Doc,
10+
DocInfo,
1111
RetrieveOptions,
1212
ListOptions
1313
} from './core/types';
1414

15-
export type { Skill, SkillInfo, RetrieveOptions, ListOptions };
15+
export type { Doc, DocInfo, RetrieveOptions, ListOptions };
1616

1717
/**
18-
* Retrieve skills based on a query. Returns skill content by default.
18+
* Retrieve docs based on a query. Returns doc content by default.
1919
*
2020
* @example retrieve('bar chart', { library: 'g2', topK: 5 })
2121
* @example retrieve('bar chart', { library: 'g2', content: false }) // metadata only
2222
*
2323
* Legacy positional signature still supported for backwards compatibility.
2424
* @example retrieve('bar chart', 'g2', 5, true)
2525
*/
26-
export function retrieve(query: string, options?: RetrieveOptions): Promise<Skill[]>;
26+
export function retrieve(query: string, options?: RetrieveOptions): Promise<Doc[]>;
2727
/** @deprecated Use the options-object overload instead. */
2828
export function retrieve(
2929
query: string,
3030
library?: string,
3131
topk?: number,
3232
content?: boolean
33-
): Promise<Skill[]>;
33+
): Promise<Doc[]>;
3434
export async function retrieve(
3535
query: string,
3636
libraryOrOpts?: string | RetrieveOptions,
3737
topk = 7,
3838
content = true
39-
): Promise<Skill[]> {
39+
): Promise<Doc[]> {
4040
if (typeof libraryOrOpts === 'string' || libraryOrOpts === undefined) {
4141
return await _retrieve(query, { library: libraryOrOpts, topK: topk, content });
4242
}
4343
return await _retrieve(query, libraryOrOpts);
4444
}
4545

4646
/**
47-
* Get a single skill by its exact ID.
47+
* Get a single doc by its exact ID.
4848
*
49-
* @param id The skill ID (e.g. 'g2-mark-bar').
49+
* @param id The doc ID (e.g. 'g2-mark-bar').
5050
* @param library Optional: restrict the search to a specific library.
51-
* @returns The skill with full content, or undefined if not found.
52-
* @example getSkillById('g2-mark-bar')
51+
* @returns The doc with full content, or undefined if not found.
52+
* @example getDocById('g2-mark-bar')
5353
*/
54-
export function getSkillById(id: string, library?: string): Skill | undefined {
55-
return _getSkillById(id, library);
54+
export function getDocById(id: string, library?: string): Doc | undefined {
55+
return _getDocById(id, library);
5656
}
5757

5858
/**
59-
* Get skill info embedded in the library index.
59+
* Get doc info embedded in the library index.
6060
*
6161
* @param library The library to get info for (default: 'g2').
6262
* @example info('g2')
63-
* @returns The skill info, or undefined if not available.
63+
* @returns The doc info, or undefined if not available.
6464
*/
65-
export function info(library = 'g2'): SkillInfo | undefined {
66-
return getSkillInfo(library);
65+
export function info(library = 'g2'): DocInfo | undefined {
66+
return getDocInfo(library);
6767
}
6868

6969
/**
@@ -75,10 +75,10 @@ export function libraries(): string[] {
7575
}
7676

7777
/**
78-
* List available skills, optionally filtered by library, category or tags.
78+
* List available docs, optionally filtered by library, category or tags.
7979
* @param options Filter options.
80-
* @example listSkills({ library: 'g2', tags: ['bar'] })
80+
* @example listDocs({ library: 'g2', tags: ['bar'] })
8181
*/
82-
export function listSkills(options: ListOptions = {}): Skill[] {
83-
return _listSkills(options);
82+
export function listDocs(options: ListOptions = {}): Doc[] {
83+
return _listDocs(options);
8484
}

src/commands/get.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
import { Command } from 'commander';
2-
import { getSkillById } from '../core/retriever';
2+
import { getDocById } from '../core/retriever';
33

44
export function registerGetCommand(program: Command): void {
55
program
66
.command('get <id>')
7-
.description('Get a skill by its exact ID')
7+
.description('Get a doc by its exact ID')
88
.option('--library <lib>', 'Restrict search to a specific library')
99
.option('--output <format>', 'Output format: json | text', 'text')
1010
.action((id: string, opts: { library?: string; output: string }) => {
11-
const skill = getSkillById(id, opts.library);
11+
const doc = getDocById(id, opts.library);
1212

13-
if (!skill) {
13+
if (!doc) {
1414
const hint = opts.library ? ` in library "${opts.library}"` : '';
15-
console.error(`Skill not found: "${id}"${hint}`);
16-
console.error('Tip: run `antv list` to browse available skill IDs.');
15+
console.error(`Doc not found: "${id}"${hint}`);
16+
console.error('Tip: run `antv list` to browse available doc IDs.');
1717
process.exit(1);
1818
}
1919

2020
if (opts.output === 'json') {
21-
console.log(JSON.stringify(skill, null, 2));
21+
console.log(JSON.stringify(doc, null, 2));
2222
return;
2323
}
2424

2525
console.log(`${'─'.repeat(50)}`);
26-
console.log(`${skill.title} (${skill.id})`);
27-
console.log(`Library : ${skill.library} v${skill.version}`);
26+
console.log(`${doc.title} (${doc.id})`);
27+
console.log(`Library : ${doc.library} v${doc.version}`);
2828
console.log(
29-
`Category : ${skill.category}${skill.subcategory ? '/' + skill.subcategory : ''}`
29+
`Category : ${doc.category}${doc.subcategory ? '/' + doc.subcategory : ''}`
3030
);
31-
console.log(`Tags : ${skill.tags.join(', ')}`);
32-
console.log(`Desc : ${skill.description}`);
33-
if (skill.use_cases.length)
34-
console.log(`Cases : ${skill.use_cases.join(' / ')}`);
35-
if (skill.anti_patterns.length)
36-
console.log(`Avoid : ${skill.anti_patterns.join(' / ')}`);
37-
if (skill.related.length)
38-
console.log(`Related : ${skill.related.join(', ')}`);
39-
if (skill.content) {
40-
console.log(`\n${skill.content}`);
31+
console.log(`Tags : ${doc.tags.join(', ')}`);
32+
console.log(`Desc : ${doc.description}`);
33+
if (doc.use_cases.length)
34+
console.log(`Cases : ${doc.use_cases.join(' / ')}`);
35+
if (doc.anti_patterns.length)
36+
console.log(`Avoid : ${doc.anti_patterns.join(' / ')}`);
37+
if (doc.related.length)
38+
console.log(`Related : ${doc.related.join(', ')}`);
39+
if (doc.content) {
40+
console.log(`\n${doc.content}`);
4141
}
4242
});
4343
}

0 commit comments

Comments
 (0)