@mastra/core
Version:
116 lines • 4.11 kB
TypeScript
/**
* Validation for Skills following the Agent Skills specification.
* @see https://agentskills.io/specification
*
* This module uses plain validation functions instead of Zod to avoid
* version compatibility issues between Zod 3 and Zod 4.
*/
/**
* Recommended limits from the Agent Skills spec
*/
export declare const SKILL_LIMITS: {
/** Recommended max tokens for instructions */
readonly MAX_INSTRUCTION_TOKENS: 5000;
/** Recommended max lines for SKILL.md */
readonly MAX_INSTRUCTION_LINES: 500;
/** Max characters for name field */
readonly MAX_NAME_LENGTH: 64;
/** Max characters for description field */
readonly MAX_DESCRIPTION_LENGTH: 1024;
/** Max characters for compatibility field */
readonly MAX_COMPATIBILITY_LENGTH: 500;
};
/**
* Skill metadata input type (what users provide)
*/
export interface SkillMetadataInput {
/** Skill name (1-64 chars, lowercase letters/numbers/hyphens only, must match directory name) */
name: string;
/** Description of what the skill does and when to use it (1-1024 characters) */
description: string;
/** License for the skill (e.g., "Apache-2.0", "MIT") */
license?: string;
/** Environment requirements or compatibility notes (string or object for flexibility) */
compatibility?: unknown;
/** Whether this skill should be directly invokable by users. Defaults to true. */
'user-invocable'?: boolean;
/** Arbitrary key-value metadata - values can be strings, arrays, objects, etc. */
metadata?: Record<string, unknown>;
}
/**
* Skill metadata output type (after validation)
*/
export type SkillMetadataOutput = SkillMetadataInput;
/**
* Validation result with warnings
*/
export interface SkillValidationResult {
valid: boolean;
errors: string[];
warnings: string[];
}
/**
* Validate skill metadata with optional content warnings.
*
* @param options.metadata - The skill metadata to validate
* @param options.directoryName - The directory name (must match skill name)
* @param options.instructions - Optional instructions content for token/line warnings
* @returns Validation result with errors and warnings
*
* @example
* ```typescript
* const result = validateSkillMetadata({
* metadata: { name: 'my-skill', description: 'A helpful skill' },
* directoryName: 'my-skill',
* instructions: '# Instructions\n...',
* });
*
* if (!result.valid) {
* console.error('Validation errors:', result.errors);
* }
* if (result.warnings.length > 0) {
* console.warn('Warnings:', result.warnings);
* }
* ```
*/
export declare function validateSkillMetadata({ metadata, directoryName, instructions, }: {
metadata: unknown;
directoryName?: string;
instructions?: string;
}): SkillValidationResult;
/**
* Result of validating raw SKILL.md content
*/
export interface SkillContentValidationResult extends SkillValidationResult {
/** Raw parsed frontmatter fields (present when frontmatter could be parsed; may be invalid) */
metadata?: Record<string, unknown>;
/** Markdown body after the frontmatter, trimmed */
instructions?: string;
}
/**
* Parse SKILL.md content into frontmatter fields and body.
* Throws if the frontmatter is not valid YAML.
* @internal
*/
export declare function extractSkillFrontmatter(content: string): {
metadata: SkillMetadataInput;
instructions: string;
};
/**
* Validate raw SKILL.md content (frontmatter + body) using the same rules
* applied when skills are loaded. Pure: no filesystem access or logging.
*
* @param options.content - Full SKILL.md file content
* @param options.directoryName - Name of the directory the skill will live in (name must match)
*
* @example
* ```typescript
* const result = validateSkillContent({ content: skillMd, directoryName: 'my-skill' });
* if (!result.valid) throw new Error(result.errors.join('\n'));
* ```
*/
export declare function validateSkillContent({ content, directoryName, }: {
content: string;
directoryName?: string;
}): SkillContentValidationResult;
//# sourceMappingURL=schemas.d.ts.map