@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/bin.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
 
@@ -4084,6 +4085,81 @@ function registerAiCommand(program) {
4084
4085
  `);
4085
4086
  });
4086
4087
  }
4088
+ async function loadDefinition(file) {
4089
+ const raw = await promises.readFile(path.resolve(file), "utf8");
4090
+ const parsed = file.endsWith(".json") ? JSON.parse(raw) : yaml.parse(raw);
4091
+ if (!parsed || typeof parsed !== "object") throw new Error("flow file must be an object");
4092
+ const def = parsed;
4093
+ if (!def.name || !Array.isArray(def.nodes)) {
4094
+ throw new Error("flow file must have `name` and `nodes[]`");
4095
+ }
4096
+ return def;
4097
+ }
4098
+ async function loadRegistry(modulePath) {
4099
+ const url$1 = url.pathToFileURL(path.resolve(modulePath)).href;
4100
+ const mod = await import(url$1);
4101
+ const registry = mod.default ?? mod.registry;
4102
+ if (!registry || typeof registry !== "object") {
4103
+ throw new Error(`registry module "${modulePath}" must default-export a FlowRegistry`);
4104
+ }
4105
+ return registry;
4106
+ }
4107
+ function registerFlowCommand(program) {
4108
+ const flow = program.command("flow").description("Compile and run visual YAML flows as durable DAGs.");
4109
+ 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) => {
4110
+ try {
4111
+ const def = await loadDefinition(file);
4112
+ const registry = options.registry ? await loadRegistry(options.registry) : void 0;
4113
+ const result = runtime.validateFlow(def, registry);
4114
+ if (result.ok) {
4115
+ process.stdout.write(`flow "${def.name}" ok \u2014 ${result.order.length} node(s), order: ${result.order.join(" \u2192 ")}
4116
+ `);
4117
+ return;
4118
+ }
4119
+ for (const issue of result.issues) {
4120
+ process.stderr.write(` \u2717 [${issue.code}] ${issue.message}
4121
+ `);
4122
+ }
4123
+ process.exit(1);
4124
+ } catch (err) {
4125
+ process.stderr.write(`Error: ${err instanceof Error ? err.message : String(err)}
4126
+ `);
4127
+ process.exit(1);
4128
+ }
4129
+ });
4130
+ flow.command("render <file>").description("Emit a Mermaid flowchart for the flow.").action(async (file) => {
4131
+ try {
4132
+ const def = await loadDefinition(file);
4133
+ process.stdout.write(runtime.flowToMermaid(def) + "\n");
4134
+ } catch (err) {
4135
+ process.stderr.write(`Error: ${err instanceof Error ? err.message : String(err)}
4136
+ `);
4137
+ process.exit(1);
4138
+ }
4139
+ });
4140
+ 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) => {
4141
+ try {
4142
+ const def = await loadDefinition(file);
4143
+ const registry = await loadRegistry(options.registry);
4144
+ const compiled = runtime.compileFlow({ definition: def, registry });
4145
+ const input2 = options.input ? JSON.parse(options.input) : void 0;
4146
+ const store = options.store ? await runtime.createFileStepLog(path.resolve(options.store)) : void 0;
4147
+ const onEvent = options.verbose ? (e) => process.stderr.write(JSON.stringify(e) + "\n") : void 0;
4148
+ const outputs = await compiled.run(input2, {
4149
+ runId: options.runId,
4150
+ store,
4151
+ maxAttempts: Number(options.maxAttempts),
4152
+ retryDelayMs: Number(options.retryDelay),
4153
+ onEvent
4154
+ });
4155
+ process.stdout.write(JSON.stringify(outputs, null, 2) + "\n");
4156
+ } catch (err) {
4157
+ process.stderr.write(`Error: ${err instanceof Error ? err.message : String(err)}
4158
+ `);
4159
+ process.exit(1);
4160
+ }
4161
+ });
4162
+ }
4087
4163
 
4088
4164
  // src/commands/index.ts
4089
4165
  function createCli() {
@@ -4098,6 +4174,7 @@ function createCli() {
4098
4174
  registerTunnelCommand(program);
4099
4175
  registerRagCommand(program);
4100
4176
  registerAiCommand(program);
4177
+ registerFlowCommand(program);
4101
4178
  return program;
4102
4179
  }
4103
4180