TextSkillLoaderDefinition
KIT · interface · 类型合同
Loader limits, parsing hooks and rejection wording.
导入
ts
import type { TextSkillLoaderDefinition } from '@jangts/agent-core/kits/text-skills';js
/** @typedef {import('@jangts/agent-core/kits/text-skills').TextSkillLoaderDefinition} TextSkillLoaderDefinition */其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/kits/text-skills、@jangts/agent-core/kits。
定义
ts
interface TextSkillLoaderDefinition字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
maxInstructionChars | number | 必需 | 只读。Maximum characters of the instruction body; larger documents are rejected. |
maxDescriptionChars | number | 必需 | 只读。Maximum characters of the description header. |
maxIdChars | number | undefined | 可省略 | 只读。Maximum id length; defaults to 64. |
entryFor | ((id: string) => string) | undefined | 可省略 | 只读。Maps an id to its expected document path; defaults to <id>/SKILL.md. |
parseHeader | ((instructions: string) => TextSkillHeader | undefined) | undefined | 可省略 | 只读。Default parser accepts the strict name/description header; hosts can inject a YAML parser. |
tags | readonly string[] | undefined | 可省略 | 只读。Diagnostic tags attached to loader rejections. |
errors | { readonly catalog?: BreakReason; readonly registration?: BreakReason; readonly document?: BreakReason; } | undefined | 可省略 | 只读。见类型定义及调用场景。 |
使用示例
- TextSkills:只读文本 Skill:校验已登记的文本工作说明,读取由 App 提供;不运行文件里的代码。
从明确来源读取一份文本 Skill
入门 · Node.js
ts
import { TextSkills } from '@jangts/agent-core/kits/text-skills';
const documents = new Map([['summarize/SKILL.md', '---\nname: summarize\ndescription: 汇总已读取资料\n---\n只根据已确认资料总结。']]);
const loader = TextSkills.defineTextSkillLoader({ maxInstructionChars: 2000, maxDescriptionChars: 120 });
const skills = loader.load({ entries: [{ id: 'summarize', entry: 'summarize/SKILL.md', kind: 'text-workflow', toolIds: [] }] }, {
read(entry) { const text = documents.get(entry); if (!text) throw new Error('来源未登记'); return text; },
});
console.log(skills[0].description);js
import { TextSkills } from '@jangts/agent-core/kits/text-skills';
const documents = new Map([['summarize/SKILL.md', '---\nname: summarize\ndescription: 汇总已读取资料\n---\n只根据已确认资料总结。']]);
const loader = TextSkills.defineTextSkillLoader({ maxInstructionChars: 2000, maxDescriptionChars: 120 });
const skills = loader.load({ entries: [{ id: 'summarize', entry: 'summarize/SKILL.md', kind: 'text-workflow', toolIds: [] }] }, {
read(entry) { const text = documents.get(entry); if (!text)
throw new Error('来源未登记'); return text; },
});
console.log(skills[0].description);同一 loader 增加应用自己的入口约定
配置 · Node.js
入口规则和工具引用只做登记校验;实际工具仍需应用注册和授权。
ts
import { TextSkills } from '@jangts/agent-core/kits/text-skills';
const documents = new Map([['skills/summarize.md', '---\nname: summarize\ndescription: 汇总已读取资料\n---\n只根据已确认资料总结。']]);
const loader = TextSkills.defineTextSkillLoader({ maxInstructionChars: 2000, maxDescriptionChars: 120, maxIdChars: 32, entryFor: id => 'skills/' + id + '.md' });
const skills = loader.load({ entries: [{ id: 'summarize', entry: 'skills/summarize.md', kind: 'text-workflow', toolIds: ['read-source'] }] }, {
read(entry) { const text = documents.get(entry); if (!text) throw new Error('来源未登记'); return text; },
});
console.log(skills[0].toolIds);js
import { TextSkills } from '@jangts/agent-core/kits/text-skills';
const documents = new Map([['skills/summarize.md', '---\nname: summarize\ndescription: 汇总已读取资料\n---\n只根据已确认资料总结。']]);
const loader = TextSkills.defineTextSkillLoader({ maxInstructionChars: 2000, maxDescriptionChars: 120, maxIdChars: 32, entryFor: id => 'skills/' + id + '.md' });
const skills = loader.load({ entries: [{ id: 'summarize', entry: 'skills/summarize.md', kind: 'text-workflow', toolIds: ['read-source'] }] }, {
read(entry) { const text = documents.get(entry); if (!text)
throw new Error('来源未登记'); return text; },
});
console.log(skills[0].toolIds);