@powerformer/refly-cli 0.1.8 → 0.1.10

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/refly.js CHANGED
@@ -11298,15 +11298,104 @@ init_cjs_shims();
11298
11298
 
11299
11299
  // src/commands/workflow/create.ts
11300
11300
  init_cjs_shims();
11301
+ var SUPPORTED_NODE_TYPES = ["skill", "agent"];
11302
+ var UNSUPPORTED_NODE_FIELDS = ["prompt", "instruction", "content", "input"];
11303
+ var VARIABLE_PATTERN = /\{\{[^}]+\}\}/;
11304
+ function validateSimplifiedSpec(spec) {
11305
+ if (spec.version !== void 0) {
11306
+ return 'Field "version" is not supported in simplified format';
11307
+ }
11308
+ if (spec.metadata !== void 0) {
11309
+ return 'Field "metadata" is not supported in simplified format';
11310
+ }
11311
+ const nodes = spec.nodes;
11312
+ if (!nodes || !Array.isArray(nodes)) {
11313
+ return 'Spec must contain a "nodes" array';
11314
+ }
11315
+ if (nodes.length === 0) {
11316
+ return "Spec must contain at least one node";
11317
+ }
11318
+ for (const node of nodes) {
11319
+ if (!node.id || typeof node.id !== "string") {
11320
+ return 'Each node must have a string "id" field';
11321
+ }
11322
+ if (!node.type || typeof node.type !== "string") {
11323
+ return `Node "${node.id}": must have a string "type" field`;
11324
+ }
11325
+ if (node.type.startsWith("tool:")) {
11326
+ return `Node "${node.id}": type "tool:xxx" is not supported. Use type "skill" with toolsetKeys instead. Example: {"type":"skill","toolsetKeys":["${node.type.replace("tool:", "")}"]}`;
11327
+ }
11328
+ if (node.type === "start") {
11329
+ return `Node "${node.id}": type "start" is not supported. Start node is automatically created`;
11330
+ }
11331
+ if (!SUPPORTED_NODE_TYPES.includes(node.type)) {
11332
+ return `Node "${node.id}": type "${node.type}" is not supported. Use one of: ${SUPPORTED_NODE_TYPES.join(", ")}`;
11333
+ }
11334
+ for (const field of UNSUPPORTED_NODE_FIELDS) {
11335
+ if (node[field] !== void 0) {
11336
+ if (field === "prompt") {
11337
+ return `Node "${node.id}": field "prompt" is not supported. Use "query" instead`;
11338
+ }
11339
+ if (field === "input") {
11340
+ return `Node "${node.id}": field "input" is not supported. Use top-level "query" and "toolsetKeys" instead`;
11341
+ }
11342
+ return `Node "${node.id}": field "${field}" is not supported in simplified format`;
11343
+ }
11344
+ }
11345
+ if (node.query && typeof node.query === "string" && VARIABLE_PATTERN.test(node.query)) {
11346
+ return `Node "${node.id}": variable syntax "{{...}}" is not supported in query field`;
11347
+ }
11348
+ if (node.toolsetKeys !== void 0) {
11349
+ if (!Array.isArray(node.toolsetKeys)) {
11350
+ return `Node "${node.id}": "toolsetKeys" must be an array`;
11351
+ }
11352
+ for (const key of node.toolsetKeys) {
11353
+ if (typeof key !== "string") {
11354
+ return `Node "${node.id}": each item in "toolsetKeys" must be a string`;
11355
+ }
11356
+ }
11357
+ }
11358
+ if (node.dependsOn !== void 0) {
11359
+ if (!Array.isArray(node.dependsOn)) {
11360
+ return `Node "${node.id}": "dependsOn" must be an array`;
11361
+ }
11362
+ for (const dep of node.dependsOn) {
11363
+ if (typeof dep !== "string") {
11364
+ return `Node "${node.id}": each item in "dependsOn" must be a string`;
11365
+ }
11366
+ }
11367
+ }
11368
+ }
11369
+ const nodeIds = new Set(nodes.map((n) => n.id));
11370
+ for (const node of nodes) {
11371
+ if (node.dependsOn) {
11372
+ for (const dep of node.dependsOn) {
11373
+ if (!nodeIds.has(dep)) {
11374
+ return `Node "${node.id}": dependsOn references unknown node "${dep}"`;
11375
+ }
11376
+ }
11377
+ }
11378
+ }
11379
+ return null;
11380
+ }
11301
11381
  var workflowCreateCommand = new Command("create").description("Create a workflow from a spec").requiredOption("--name <name>", "Workflow name").requiredOption("--spec <json>", "Workflow spec as JSON").option("--description <description>", "Workflow description").action(async (options) => {
11302
11382
  try {
11303
11383
  let spec;
11304
11384
  try {
11305
- spec = JSON.parse(options.spec);
11385
+ const parsed = JSON.parse(options.spec);
11386
+ spec = Array.isArray(parsed) ? { nodes: parsed } : parsed;
11306
11387
  } catch {
11307
11388
  fail(ErrorCodes.INVALID_INPUT, "Invalid JSON in --spec", {
11308
11389
  hint: "Ensure the spec is valid JSON"
11309
11390
  });
11391
+ return;
11392
+ }
11393
+ const validationError = validateSimplifiedSpec(spec);
11394
+ if (validationError) {
11395
+ fail(ErrorCodes.INVALID_INPUT, validationError, {
11396
+ hint: 'Use simplified format: [{"id":"node1","type":"skill","query":"...","toolsetKeys":["tool_name"],"dependsOn":["other_node"]}]'
11397
+ });
11398
+ return;
11310
11399
  }
11311
11400
  const result = await apiRequest("/v1/cli/workflow", {
11312
11401
  method: "POST",