@agentled/cli
Version:
CLI for Agentled — manage workflows, apps, and knowledge from the command line. Zero context-window cost for AI agents.
107 lines • 4.41 kB
JavaScript
/* eslint-disable no-console */
import { AgentledClient } from '../client.js';
import { printOutput, printError } from '../utils/output.js';
import { BASE_FIELD_KEYS, CONTEXT_FIELD_TYPES, CONTEXT_FIELD_TYPE_ALIASES, } from '../context-schema.js';
function filterByStepType(schema, stepType) {
const groups = schema.groups
.map(g => ({
...g,
fields: g.fields.filter(f => !f.stepTypes || f.stepTypes.includes(stepType)),
}))
.filter(g => g.fields.length > 0);
const fieldCount = groups.reduce((n, g) => n + g.fields.length, 0);
return { ...schema, groups, fieldCount };
}
function renderTable(schema) {
const lines = [];
lines.push(schema.description);
lines.push(`(${schema.fieldCount} fields in ${schema.groups.length} categories)`);
lines.push('');
for (const g of schema.groups) {
lines.push(`## ${g.category}`);
lines.push(` ${g.description}`);
for (const f of g.fields) {
const req = f.required ? ' *' : '';
const types = f.stepTypes ? ` [${f.stepTypes.join(', ')}]` : '';
lines.push(` - ${f.name}${req}: ${f.type}${types}`);
lines.push(` ${f.description}`);
if (f.example)
lines.push(` example: ${f.example}`);
}
lines.push('');
}
return lines.join('\n');
}
function buildContextSchema() {
return {
description: 'Valid field types for pipeline.context input pages (`executionInputConfig.fields[]`, ' +
'`inputPages[].configuration.fields[]`). Unknown `type` values fall back to a plain text ' +
'input at render time but lose type-aware validation and pickers.',
scope: 'context',
baseKeys: [...BASE_FIELD_KEYS],
fieldTypes: CONTEXT_FIELD_TYPES,
aliases: { ...CONTEXT_FIELD_TYPE_ALIASES },
};
}
function renderContextTable(schema) {
const lines = [];
lines.push(schema.description);
lines.push(`(${schema.fieldTypes.length} valid field types)`);
lines.push('');
lines.push(`Base keys (every field): ${schema.baseKeys.join(', ')}`);
lines.push('');
lines.push('Field types:');
for (const t of schema.fieldTypes) {
const extras = t.extraKeys?.length ? ` [+ ${t.extraKeys.join(', ')}]` : '';
lines.push(` - ${t.value}${extras}`);
lines.push(` ${t.description}`);
if (t.example) {
lines.push(` example: ${JSON.stringify(t.example)}`);
}
}
const aliasEntries = Object.entries(schema.aliases);
if (aliasEntries.length > 0) {
lines.push('');
lines.push('Legacy aliases (accepted but prefer the canonical name):');
for (const [alias, canonical] of aliasEntries) {
lines.push(` - ${alias} → ${canonical}`);
}
}
return lines.join('\n');
}
export function registerSchemaCommand(program) {
program
.command('schema')
.description('Show the canonical PipelineStep field schema, or the context/input-page field schema with --context.')
.option('--step-type <type>', 'Filter fields applicable to this step type (trigger, appAction, aiAction, code, …)')
.option('--context', 'Show the context / input-page field schema (pipeline.context.*.fields[].type) instead of the step schema')
.option('--format <format>', 'Output format: json (default), table, minimal', 'json')
.action(async (opts) => {
try {
const format = opts.format;
if (opts.context) {
const ctx = buildContextSchema();
if (format === 'table' || format === 'minimal') {
console.log(renderContextTable(ctx));
}
else {
printOutput(ctx, format);
}
return;
}
const client = new AgentledClient();
const schema = await client.getStepSchema();
const filtered = opts.stepType ? filterByStepType(schema, opts.stepType) : schema;
if (format === 'table' || format === 'minimal') {
console.log(renderTable(filtered));
}
else {
printOutput(filtered, format);
}
}
catch (e) {
printError(e.message);
}
});
}
//# sourceMappingURL=schema.js.map