defineTextSkillLoader
KIT · function · Runtime value
Compile a loader that validates registrations and reads their documents.
The default contract is narrow by design: ids are lower-case words joined by hyphens (up to maxIdChars, default 64), each entry lives at <id>/SKILL.md, the kind is text-workflow, and the document starts with name/description front matter.
Import
import { defineTextSkillLoader } from '@jangts/agent-core/kits/text-skills';import { defineTextSkillLoader } from '@jangts/agent-core/kits/text-skills';Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/kits/text-skills, @jangts/agent-core/kits.
Definition
Call
defineTextSkillLoader(definition: TextSkillLoaderDefinition): import("../structs/kits/text-skills.js").TextSkillLoaderCompile a loader that validates registrations and reads their documents.
The default contract is narrow by design: ids are lower-case words joined by hyphens (up to maxIdChars, default 64), each entry lives at <id>/SKILL.md, the kind is text-workflow, and the document starts with name/description front matter.
| Parameter | Type | Passing | Description |
|---|---|---|---|
definition | TextSkillLoaderDefinition | Required | — |
Fields of definition
| Field | Type | Required | Description |
|---|---|---|---|
maxInstructionChars | number | Required | Read-only. Maximum characters of the instruction body; larger documents are rejected. |
maxDescriptionChars | number | Required | Read-only. Maximum characters of the description header. |
maxIdChars | number | undefined | Optional | Read-only. Maximum id length; defaults to 64. |
entryFor | ((id: string) => string) | undefined | Optional | Read-only. Maps an id to its expected document path; defaults to <id>/SKILL.md. |
parseHeader | ((instructions: string) => TextSkillHeader | undefined) | undefined | Optional | Read-only. Default parser accepts the strict name/description header; hosts can inject a YAML parser. |
tags | readonly string[] | undefined | Optional | Read-only. Diagnostic tags attached to loader rejections. |
errors | { readonly catalog?: BreakReason; readonly registration?: BreakReason; readonly document?: BreakReason; } | undefined | Optional | Read-only. See the type definition and usage context. |
Returns: TextSkillLoader.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
load | (request: { readonly entries: unknown; }, ports: TextSkillReadPorts) => readonly TextSkill[] | Required | Reads and validates every registered skill. |
Examples
- TextSkills: read-only text Skills: Validate registered text work instructions that the App reads; code inside the files is never executed.
Read one text Skill from an explicit source
Beginner · Node.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);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);Add the application's own entry convention to the same loader
Configuration · Node.js
Entry rules and tool references are only registration checks; the actual tools still need to be registered and authorized by the application.
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);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);