@agentskit/cli 0.10.1 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -23,6 +23,7 @@ var kleur = require('kleur');
23
23
  var chokidar = require('chokidar');
24
24
  var rag = require('@agentskit/rag');
25
25
  var agentSchema = require('@agentskit/core/agent-schema');
26
+ var yaml = require('yaml');
26
27
 
27
28
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
28
29
 
@@ -4092,6 +4093,81 @@ function registerAiCommand(program) {
4092
4093
  `);
4093
4094
  });
4094
4095
  }
4096
+ async function loadDefinition(file) {
4097
+ const raw = await promises.readFile(path.resolve(file), "utf8");
4098
+ const parsed = file.endsWith(".json") ? JSON.parse(raw) : yaml.parse(raw);
4099
+ if (!parsed || typeof parsed !== "object") throw new Error("flow file must be an object");
4100
+ const def = parsed;
4101
+ if (!def.name || !Array.isArray(def.nodes)) {
4102
+ throw new Error("flow file must have `name` and `nodes[]`");
4103
+ }
4104
+ return def;
4105
+ }
4106
+ async function loadRegistry(modulePath) {
4107
+ const url$1 = url.pathToFileURL(path.resolve(modulePath)).href;
4108
+ const mod = await import(url$1);
4109
+ const registry = mod.default ?? mod.registry;
4110
+ if (!registry || typeof registry !== "object") {
4111
+ throw new Error(`registry module "${modulePath}" must default-export a FlowRegistry`);
4112
+ }
4113
+ return registry;
4114
+ }
4115
+ function registerFlowCommand(program) {
4116
+ const flow = program.command("flow").description("Compile and run visual YAML flows as durable DAGs.");
4117
+ flow.command("validate <file>").description("Type-check a flow file: ids, handlers (when --registry given), deps, cycles.").option("--registry <module>", "JS/TS module exporting FlowRegistry as default").action(async (file, options) => {
4118
+ try {
4119
+ const def = await loadDefinition(file);
4120
+ const registry = options.registry ? await loadRegistry(options.registry) : void 0;
4121
+ const result = runtime.validateFlow(def, registry);
4122
+ if (result.ok) {
4123
+ process.stdout.write(`flow "${def.name}" ok \u2014 ${result.order.length} node(s), order: ${result.order.join(" \u2192 ")}
4124
+ `);
4125
+ return;
4126
+ }
4127
+ for (const issue of result.issues) {
4128
+ process.stderr.write(` \u2717 [${issue.code}] ${issue.message}
4129
+ `);
4130
+ }
4131
+ process.exit(1);
4132
+ } catch (err) {
4133
+ process.stderr.write(`Error: ${err instanceof Error ? err.message : String(err)}
4134
+ `);
4135
+ process.exit(1);
4136
+ }
4137
+ });
4138
+ flow.command("render <file>").description("Emit a Mermaid flowchart for the flow.").action(async (file) => {
4139
+ try {
4140
+ const def = await loadDefinition(file);
4141
+ process.stdout.write(runtime.flowToMermaid(def) + "\n");
4142
+ } catch (err) {
4143
+ process.stderr.write(`Error: ${err instanceof Error ? err.message : String(err)}
4144
+ `);
4145
+ process.exit(1);
4146
+ }
4147
+ });
4148
+ flow.command("run <file>").description("Compile and execute a flow with a handler registry.").requiredOption("--registry <module>", "JS/TS module exporting FlowRegistry as default").option("--input <json>", "JSON string passed to handlers as ctx.input").option("--store <path>", "Persist durable step log as JSONL at <path>").option("--run-id <id>", "Resume a previous run by reusing its id").option("--max-attempts <n>", "Retries per node (default 1)", "1").option("--retry-delay <ms>", "Delay between attempts in ms", "0").option("--verbose", "Stream node events to stderr").action(async (file, options) => {
4149
+ try {
4150
+ const def = await loadDefinition(file);
4151
+ const registry = await loadRegistry(options.registry);
4152
+ const compiled = runtime.compileFlow({ definition: def, registry });
4153
+ const input2 = options.input ? JSON.parse(options.input) : void 0;
4154
+ const store = options.store ? await runtime.createFileStepLog(path.resolve(options.store)) : void 0;
4155
+ const onEvent = options.verbose ? (e) => process.stderr.write(JSON.stringify(e) + "\n") : void 0;
4156
+ const outputs = await compiled.run(input2, {
4157
+ runId: options.runId,
4158
+ store,
4159
+ maxAttempts: Number(options.maxAttempts),
4160
+ retryDelayMs: Number(options.retryDelay),
4161
+ onEvent
4162
+ });
4163
+ process.stdout.write(JSON.stringify(outputs, null, 2) + "\n");
4164
+ } catch (err) {
4165
+ process.stderr.write(`Error: ${err instanceof Error ? err.message : String(err)}
4166
+ `);
4167
+ process.exit(1);
4168
+ }
4169
+ });
4170
+ }
4095
4171
 
4096
4172
  // src/commands/index.ts
4097
4173
  function createCli() {
@@ -4106,6 +4182,7 @@ function createCli() {
4106
4182
  registerTunnelCommand(program);
4107
4183
  registerRagCommand(program);
4108
4184
  registerAiCommand(program);
4185
+ registerFlowCommand(program);
4109
4186
  return program;
4110
4187
  }
4111
4188