TextSkillLoader
KIT · interface · 类型合同
Compiled loader.
导入
ts
import type { TextSkillLoader } from '@jangts/agent-core/kits/text-skills';js
/** @typedef {import('@jangts/agent-core/kits/text-skills').TextSkillLoader} TextSkillLoader */其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/kits/text-skills、@jangts/agent-core/kits。
定义
ts
interface TextSkillLoader字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
load | (request: { readonly entries: unknown; }, ports: TextSkillReadPorts) => readonly TextSkill[] | 必需 | Reads and validates every registered skill. |
成员目录
| 成员 | 用途 |
|---|---|
load | Reads and validates every registered skill. |
成员详情
load
Reads and validates every registered skill.
ts
TextSkillLoader.load(request: { readonly entries: unknown; }, ports: TextSkillReadPorts): readonly TextSkill[]Reads and validates every registered skill.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | { readonly entries: unknown; } | 必需 | — |
ports | TextSkillReadPorts | 必需 | — |
request 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
entries | unknown | 必需 | 只读。见类型定义及调用场景。 |
ports 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
read | (entry: string) => string | 必需 | Returns the document text; throwing aborts the load. |
返回: readonly TextSkill[]。
使用示例
- 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);