@acontext/acontext 0.0.19 → 0.0.20
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.
- package/dist/agent/skill.d.ts +45 -4
- package/dist/agent/skill.js +96 -22
- package/dist/resources/skills.d.ts +21 -3
- package/dist/resources/skills.js +24 -24
- package/package.json +1 -1
package/dist/agent/skill.d.ts
CHANGED
|
@@ -2,15 +2,49 @@
|
|
|
2
2
|
* Skill tools for agent operations.
|
|
3
3
|
*/
|
|
4
4
|
import { AcontextClient } from '../client';
|
|
5
|
+
import { Skill } from '../types';
|
|
5
6
|
import { AbstractBaseTool, BaseContext, BaseToolPool } from './base';
|
|
7
|
+
/**
|
|
8
|
+
* Context for skill tools with preloaded skill name mapping.
|
|
9
|
+
*/
|
|
6
10
|
export interface SkillContext extends BaseContext {
|
|
7
11
|
client: AcontextClient;
|
|
12
|
+
skills: Map<string, Skill>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a SkillContext by preloading skills from a list of skill IDs.
|
|
16
|
+
*
|
|
17
|
+
* @param client - The Acontext client instance.
|
|
18
|
+
* @param skillIds - List of skill UUIDs to preload.
|
|
19
|
+
* @returns SkillContext with preloaded skills mapped by name.
|
|
20
|
+
* @throws Error if duplicate skill names are found.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createSkillContext(client: AcontextClient, skillIds: string[]): Promise<SkillContext>;
|
|
23
|
+
/**
|
|
24
|
+
* Get a skill by name from the preloaded skills.
|
|
25
|
+
*
|
|
26
|
+
* @param ctx - The skill context.
|
|
27
|
+
* @param skillName - The name of the skill.
|
|
28
|
+
* @returns The Skill object.
|
|
29
|
+
* @throws Error if the skill is not found in the context.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getSkillFromContext(ctx: SkillContext, skillName: string): Skill;
|
|
32
|
+
/**
|
|
33
|
+
* Return list of available skill names in this context.
|
|
34
|
+
*/
|
|
35
|
+
export declare function listSkillNamesFromContext(ctx: SkillContext): string[];
|
|
36
|
+
export declare class ListSkillsTool extends AbstractBaseTool {
|
|
37
|
+
readonly name = "list_skills";
|
|
38
|
+
readonly description = "List all available skills in the current context with their names and descriptions.";
|
|
39
|
+
readonly arguments: {};
|
|
40
|
+
readonly requiredArguments: string[];
|
|
41
|
+
execute(ctx: SkillContext, _llmArguments: Record<string, unknown>): Promise<string>;
|
|
8
42
|
}
|
|
9
43
|
export declare class GetSkillTool extends AbstractBaseTool {
|
|
10
44
|
readonly name = "get_skill";
|
|
11
|
-
readonly description = "Get a skill by its name.
|
|
45
|
+
readonly description = "Get a skill by its name. Returns the skill information including the relative paths of the files and their mime type categories.";
|
|
12
46
|
readonly arguments: {
|
|
13
|
-
|
|
47
|
+
skill_name: {
|
|
14
48
|
type: string;
|
|
15
49
|
description: string;
|
|
16
50
|
};
|
|
@@ -20,7 +54,7 @@ export declare class GetSkillTool extends AbstractBaseTool {
|
|
|
20
54
|
}
|
|
21
55
|
export declare class GetSkillFileTool extends AbstractBaseTool {
|
|
22
56
|
readonly name = "get_skill_file";
|
|
23
|
-
readonly description
|
|
57
|
+
readonly description: string;
|
|
24
58
|
readonly arguments: {
|
|
25
59
|
skill_name: {
|
|
26
60
|
type: string;
|
|
@@ -39,6 +73,13 @@ export declare class GetSkillFileTool extends AbstractBaseTool {
|
|
|
39
73
|
execute(ctx: SkillContext, llmArguments: Record<string, unknown>): Promise<string>;
|
|
40
74
|
}
|
|
41
75
|
export declare class SkillToolPool extends BaseToolPool {
|
|
42
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Create a SkillContext by preloading skills from a list of skill IDs.
|
|
78
|
+
*
|
|
79
|
+
* @param client - The Acontext client instance.
|
|
80
|
+
* @param skillIds - List of skill UUIDs to preload.
|
|
81
|
+
* @returns Promise resolving to SkillContext with preloaded skills mapped by name.
|
|
82
|
+
*/
|
|
83
|
+
formatContext(client: AcontextClient, skillIds: string[]): Promise<SkillContext>;
|
|
43
84
|
}
|
|
44
85
|
export declare const SKILL_TOOLS: SkillToolPool;
|
package/dist/agent/skill.js
CHANGED
|
@@ -3,27 +3,95 @@
|
|
|
3
3
|
* Skill tools for agent operations.
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SKILL_TOOLS = exports.SkillToolPool = exports.GetSkillFileTool = exports.GetSkillTool = void 0;
|
|
6
|
+
exports.SKILL_TOOLS = exports.SkillToolPool = exports.GetSkillFileTool = exports.GetSkillTool = exports.ListSkillsTool = void 0;
|
|
7
|
+
exports.createSkillContext = createSkillContext;
|
|
8
|
+
exports.getSkillFromContext = getSkillFromContext;
|
|
9
|
+
exports.listSkillNamesFromContext = listSkillNamesFromContext;
|
|
7
10
|
const base_1 = require("./base");
|
|
11
|
+
/**
|
|
12
|
+
* Create a SkillContext by preloading skills from a list of skill IDs.
|
|
13
|
+
*
|
|
14
|
+
* @param client - The Acontext client instance.
|
|
15
|
+
* @param skillIds - List of skill UUIDs to preload.
|
|
16
|
+
* @returns SkillContext with preloaded skills mapped by name.
|
|
17
|
+
* @throws Error if duplicate skill names are found.
|
|
18
|
+
*/
|
|
19
|
+
async function createSkillContext(client, skillIds) {
|
|
20
|
+
const skills = new Map();
|
|
21
|
+
for (const skillId of skillIds) {
|
|
22
|
+
const skill = await client.skills.get(skillId);
|
|
23
|
+
if (skills.has(skill.name)) {
|
|
24
|
+
const existingSkill = skills.get(skill.name);
|
|
25
|
+
throw new Error(`Duplicate skill name '${skill.name}' found. ` +
|
|
26
|
+
`Existing ID: ${existingSkill.id}, New ID: ${skill.id}`);
|
|
27
|
+
}
|
|
28
|
+
skills.set(skill.name, skill);
|
|
29
|
+
}
|
|
30
|
+
return { client, skills };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get a skill by name from the preloaded skills.
|
|
34
|
+
*
|
|
35
|
+
* @param ctx - The skill context.
|
|
36
|
+
* @param skillName - The name of the skill.
|
|
37
|
+
* @returns The Skill object.
|
|
38
|
+
* @throws Error if the skill is not found in the context.
|
|
39
|
+
*/
|
|
40
|
+
function getSkillFromContext(ctx, skillName) {
|
|
41
|
+
const skill = ctx.skills.get(skillName);
|
|
42
|
+
if (!skill) {
|
|
43
|
+
const available = ctx.skills.size > 0 ? Array.from(ctx.skills.keys()).join(', ') : '[none]';
|
|
44
|
+
throw new Error(`Skill '${skillName}' not found in context. Available skills: ${available}`);
|
|
45
|
+
}
|
|
46
|
+
return skill;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Return list of available skill names in this context.
|
|
50
|
+
*/
|
|
51
|
+
function listSkillNamesFromContext(ctx) {
|
|
52
|
+
return Array.from(ctx.skills.keys());
|
|
53
|
+
}
|
|
54
|
+
class ListSkillsTool extends base_1.AbstractBaseTool {
|
|
55
|
+
constructor() {
|
|
56
|
+
super(...arguments);
|
|
57
|
+
this.name = 'list_skills';
|
|
58
|
+
this.description = 'List all available skills in the current context with their names and descriptions.';
|
|
59
|
+
this.arguments = {};
|
|
60
|
+
this.requiredArguments = [];
|
|
61
|
+
}
|
|
62
|
+
async execute(ctx,
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
64
|
+
_llmArguments) {
|
|
65
|
+
if (ctx.skills.size === 0) {
|
|
66
|
+
return 'No skills available in the current context.';
|
|
67
|
+
}
|
|
68
|
+
const skillList = [];
|
|
69
|
+
for (const [skillName, skill] of ctx.skills.entries()) {
|
|
70
|
+
skillList.push(`- ${skillName}: ${skill.description}`);
|
|
71
|
+
}
|
|
72
|
+
return `Available skills (${ctx.skills.size}):\n${skillList.join('\n')}`;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.ListSkillsTool = ListSkillsTool;
|
|
8
76
|
class GetSkillTool extends base_1.AbstractBaseTool {
|
|
9
77
|
constructor() {
|
|
10
78
|
super(...arguments);
|
|
11
79
|
this.name = 'get_skill';
|
|
12
|
-
this.description = 'Get a skill by its name.
|
|
80
|
+
this.description = 'Get a skill by its name. Returns the skill information including the relative paths of the files and their mime type categories.';
|
|
13
81
|
this.arguments = {
|
|
14
|
-
|
|
82
|
+
skill_name: {
|
|
15
83
|
type: 'string',
|
|
16
|
-
description: 'The name of the skill
|
|
84
|
+
description: 'The name of the skill.',
|
|
17
85
|
},
|
|
18
86
|
};
|
|
19
|
-
this.requiredArguments = ['
|
|
87
|
+
this.requiredArguments = ['skill_name'];
|
|
20
88
|
}
|
|
21
89
|
async execute(ctx, llmArguments) {
|
|
22
|
-
const
|
|
23
|
-
if (!
|
|
24
|
-
throw new Error('
|
|
90
|
+
const skillName = llmArguments.skill_name;
|
|
91
|
+
if (!skillName) {
|
|
92
|
+
throw new Error('skill_name is required');
|
|
25
93
|
}
|
|
26
|
-
const skill =
|
|
94
|
+
const skill = getSkillFromContext(ctx, skillName);
|
|
27
95
|
const fileCount = skill.file_index.length;
|
|
28
96
|
// Format all files with path and MIME type
|
|
29
97
|
let fileList;
|
|
@@ -38,9 +106,7 @@ class GetSkillTool extends base_1.AbstractBaseTool {
|
|
|
38
106
|
return (`Skill: ${skill.name} (ID: ${skill.id})\n` +
|
|
39
107
|
`Description: ${skill.description}\n` +
|
|
40
108
|
`Files: ${fileCount} file(s)\n` +
|
|
41
|
-
`${fileList}
|
|
42
|
-
`Created: ${skill.created_at}\n` +
|
|
43
|
-
`Updated: ${skill.updated_at}`);
|
|
109
|
+
`${fileList}`);
|
|
44
110
|
}
|
|
45
111
|
}
|
|
46
112
|
exports.GetSkillTool = GetSkillTool;
|
|
@@ -48,7 +114,8 @@ class GetSkillFileTool extends base_1.AbstractBaseTool {
|
|
|
48
114
|
constructor() {
|
|
49
115
|
super(...arguments);
|
|
50
116
|
this.name = 'get_skill_file';
|
|
51
|
-
this.description = "Get a file from a skill by name. The file_path should be a relative path within the skill (e.g., 'scripts/extract_text.json').
|
|
117
|
+
this.description = "Get a file from a skill by name. The file_path should be a relative path within the skill (e.g., 'scripts/extract_text.json')." +
|
|
118
|
+
'Tips: SKILL.md is the first file you should read to understand the full picture of this skill\'s content.';
|
|
52
119
|
this.arguments = {
|
|
53
120
|
skill_name: {
|
|
54
121
|
type: 'string',
|
|
@@ -69,14 +136,15 @@ class GetSkillFileTool extends base_1.AbstractBaseTool {
|
|
|
69
136
|
const skillName = llmArguments.skill_name;
|
|
70
137
|
const filePath = llmArguments.file_path;
|
|
71
138
|
const expire = llmArguments.expire;
|
|
72
|
-
if (!filePath) {
|
|
73
|
-
throw new Error('file_path is required');
|
|
74
|
-
}
|
|
75
139
|
if (!skillName) {
|
|
76
140
|
throw new Error('skill_name is required');
|
|
77
141
|
}
|
|
78
|
-
|
|
79
|
-
|
|
142
|
+
if (!filePath) {
|
|
143
|
+
throw new Error('file_path is required');
|
|
144
|
+
}
|
|
145
|
+
const skill = getSkillFromContext(ctx, skillName);
|
|
146
|
+
const result = await ctx.client.skills.getFile({
|
|
147
|
+
skillId: skill.id,
|
|
80
148
|
filePath,
|
|
81
149
|
expire: expire || null,
|
|
82
150
|
});
|
|
@@ -100,13 +168,19 @@ class GetSkillFileTool extends base_1.AbstractBaseTool {
|
|
|
100
168
|
}
|
|
101
169
|
exports.GetSkillFileTool = GetSkillFileTool;
|
|
102
170
|
class SkillToolPool extends base_1.BaseToolPool {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Create a SkillContext by preloading skills from a list of skill IDs.
|
|
173
|
+
*
|
|
174
|
+
* @param client - The Acontext client instance.
|
|
175
|
+
* @param skillIds - List of skill UUIDs to preload.
|
|
176
|
+
* @returns Promise resolving to SkillContext with preloaded skills mapped by name.
|
|
177
|
+
*/
|
|
178
|
+
async formatContext(client, skillIds) {
|
|
179
|
+
return createSkillContext(client, skillIds);
|
|
107
180
|
}
|
|
108
181
|
}
|
|
109
182
|
exports.SkillToolPool = SkillToolPool;
|
|
110
183
|
exports.SKILL_TOOLS = new SkillToolPool();
|
|
184
|
+
exports.SKILL_TOOLS.addTool(new ListSkillsTool());
|
|
111
185
|
exports.SKILL_TOOLS.addTool(new GetSkillTool());
|
|
112
186
|
exports.SKILL_TOOLS.addTool(new GetSkillFileTool());
|
|
@@ -29,10 +29,28 @@ export declare class SkillsAPI {
|
|
|
29
29
|
cursor?: string | null;
|
|
30
30
|
timeDesc?: boolean | null;
|
|
31
31
|
}): Promise<ListSkillsOutput>;
|
|
32
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Get a skill by its ID.
|
|
34
|
+
*
|
|
35
|
+
* @param skillId - The UUID of the skill
|
|
36
|
+
* @returns Skill containing the full skill information including file_index
|
|
37
|
+
*/
|
|
38
|
+
get(skillId: string): Promise<Skill>;
|
|
33
39
|
delete(skillId: string): Promise<void>;
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Get a file from a skill by skill ID.
|
|
42
|
+
*
|
|
43
|
+
* The backend automatically returns content for parseable text files, or a presigned URL
|
|
44
|
+
* for non-parseable files (binary, images, etc.).
|
|
45
|
+
*
|
|
46
|
+
* @param options - File retrieval options
|
|
47
|
+
* @param options.skillId - The UUID of the skill
|
|
48
|
+
* @param options.filePath - Relative path to the file within the skill (e.g., 'scripts/extract_text.json')
|
|
49
|
+
* @param options.expire - URL expiration time in seconds (defaults to 900 / 15 minutes)
|
|
50
|
+
* @returns GetSkillFileResp containing the file path, MIME type, and either content or URL
|
|
51
|
+
*/
|
|
52
|
+
getFile(options: {
|
|
53
|
+
skillId: string;
|
|
36
54
|
filePath: string;
|
|
37
55
|
expire?: number | null;
|
|
38
56
|
}): Promise<GetSkillFileResp>;
|
package/dist/resources/skills.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SkillsAPI = void 0;
|
|
7
|
-
const zod_1 = require("zod");
|
|
8
7
|
const uploads_1 = require("../uploads");
|
|
9
8
|
const utils_1 = require("../utils");
|
|
10
9
|
const types_1 = require("../types");
|
|
@@ -42,12 +41,6 @@ class SkillsAPI {
|
|
|
42
41
|
* along with pagination information (next_cursor and has_more)
|
|
43
42
|
*/
|
|
44
43
|
async list_catalog(options) {
|
|
45
|
-
// Parse API response (contains full Skill objects)
|
|
46
|
-
const apiResponseSchema = zod_1.z.object({
|
|
47
|
-
items: zod_1.z.array(types_1.SkillSchema),
|
|
48
|
-
next_cursor: zod_1.z.string().nullable().optional(),
|
|
49
|
-
has_more: zod_1.z.boolean(),
|
|
50
|
-
});
|
|
51
44
|
// Use 100 as default for catalog listing (only name and description, lightweight)
|
|
52
45
|
const effectiveLimit = options?.limit ?? 100;
|
|
53
46
|
const params = (0, utils_1.buildParams)({
|
|
@@ -59,29 +52,36 @@ class SkillsAPI {
|
|
|
59
52
|
const data = await this.requester.request('GET', '/agent_skills', {
|
|
60
53
|
params: Object.keys(params).length > 0 ? params : undefined,
|
|
61
54
|
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return types_1.ListSkillsOutputSchema.parse({
|
|
65
|
-
items: apiResponse.items.map((skill) => ({
|
|
66
|
-
name: skill.name,
|
|
67
|
-
description: skill.description,
|
|
68
|
-
})),
|
|
69
|
-
next_cursor: apiResponse.next_cursor ?? null,
|
|
70
|
-
has_more: apiResponse.has_more,
|
|
71
|
-
});
|
|
55
|
+
// Zod strips unknown keys, so ListSkillsOutputSchema extracts only name/description
|
|
56
|
+
return types_1.ListSkillsOutputSchema.parse(data);
|
|
72
57
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Get a skill by its ID.
|
|
60
|
+
*
|
|
61
|
+
* @param skillId - The UUID of the skill
|
|
62
|
+
* @returns Skill containing the full skill information including file_index
|
|
63
|
+
*/
|
|
64
|
+
async get(skillId) {
|
|
65
|
+
const data = await this.requester.request('GET', `/agent_skills/${skillId}`);
|
|
78
66
|
return types_1.SkillSchema.parse(data);
|
|
79
67
|
}
|
|
80
68
|
async delete(skillId) {
|
|
81
69
|
await this.requester.request('DELETE', `/agent_skills/${skillId}`);
|
|
82
70
|
}
|
|
83
|
-
|
|
84
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Get a file from a skill by skill ID.
|
|
73
|
+
*
|
|
74
|
+
* The backend automatically returns content for parseable text files, or a presigned URL
|
|
75
|
+
* for non-parseable files (binary, images, etc.).
|
|
76
|
+
*
|
|
77
|
+
* @param options - File retrieval options
|
|
78
|
+
* @param options.skillId - The UUID of the skill
|
|
79
|
+
* @param options.filePath - Relative path to the file within the skill (e.g., 'scripts/extract_text.json')
|
|
80
|
+
* @param options.expire - URL expiration time in seconds (defaults to 900 / 15 minutes)
|
|
81
|
+
* @returns GetSkillFileResp containing the file path, MIME type, and either content or URL
|
|
82
|
+
*/
|
|
83
|
+
async getFile(options) {
|
|
84
|
+
const endpoint = `/agent_skills/${options.skillId}/file`;
|
|
85
85
|
const params = {
|
|
86
86
|
file_path: options.filePath,
|
|
87
87
|
};
|