@amaster.ai/runtime-cli 1.1.14-beta.0 → 1.1.14-beta.1
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/README.md +16 -1
- package/dist/cli.cjs +293 -5
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +293 -5
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +293 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +293 -5
- package/dist/index.js.map +1 -1
- package/dist/skill/SKILL.md +11 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2260,6 +2260,8 @@ async function getUserRoles(client, options) {
|
|
|
2260
2260
|
exitWithCommandError3(spinner, "Failed to fetch user roles", error);
|
|
2261
2261
|
}
|
|
2262
2262
|
}
|
|
2263
|
+
var WORKFLOW_LIST_PATH = "/api/proxy/builtin/platform/workflow/openapi/apps";
|
|
2264
|
+
var WORKFLOW_GET_PATH = (workflowId) => `/api/proxy/builtin/platform/workflow/openapi/apps/${encodeURIComponent(workflowId)}/dsl`;
|
|
2263
2265
|
function resolveInputSource4(input) {
|
|
2264
2266
|
if (!input.startsWith("@")) {
|
|
2265
2267
|
return input;
|
|
@@ -2285,6 +2287,151 @@ function parseJsonInput3(input, label) {
|
|
|
2285
2287
|
function isPlainObject4(value) {
|
|
2286
2288
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2287
2289
|
}
|
|
2290
|
+
function parseWorkflowTracing(value) {
|
|
2291
|
+
if (!value) {
|
|
2292
|
+
return null;
|
|
2293
|
+
}
|
|
2294
|
+
if (isPlainObject4(value)) {
|
|
2295
|
+
return value;
|
|
2296
|
+
}
|
|
2297
|
+
if (typeof value !== "string") {
|
|
2298
|
+
return null;
|
|
2299
|
+
}
|
|
2300
|
+
try {
|
|
2301
|
+
const parsed = JSON.parse(value);
|
|
2302
|
+
return isPlainObject4(parsed) ? parsed : null;
|
|
2303
|
+
} catch {
|
|
2304
|
+
return null;
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
function getRunnableName(summary) {
|
|
2308
|
+
const tracing = parseWorkflowTracing(summary.tracing);
|
|
2309
|
+
const baseName = tracing?.base_name;
|
|
2310
|
+
if (typeof baseName === "string" && baseName.trim()) {
|
|
2311
|
+
return baseName.trim();
|
|
2312
|
+
}
|
|
2313
|
+
return null;
|
|
2314
|
+
}
|
|
2315
|
+
function normalizeWorkflowSummary(summary) {
|
|
2316
|
+
return {
|
|
2317
|
+
...summary,
|
|
2318
|
+
id: typeof summary.id === "string" ? summary.id : "",
|
|
2319
|
+
name: typeof summary.name === "string" ? summary.name : "",
|
|
2320
|
+
runnable_name: getRunnableName(summary),
|
|
2321
|
+
description: typeof summary.description === "string" ? summary.description : null,
|
|
2322
|
+
mode: typeof summary.mode === "string" ? summary.mode : null
|
|
2323
|
+
};
|
|
2324
|
+
}
|
|
2325
|
+
function extractWorkflowInputVariables(dsl) {
|
|
2326
|
+
if (!isPlainObject4(dsl)) {
|
|
2327
|
+
return [];
|
|
2328
|
+
}
|
|
2329
|
+
const candidateNodeSets = [];
|
|
2330
|
+
if (Array.isArray(dsl.nodes)) {
|
|
2331
|
+
candidateNodeSets.push(dsl.nodes);
|
|
2332
|
+
}
|
|
2333
|
+
if (isPlainObject4(dsl.graph) && Array.isArray(dsl.graph.nodes)) {
|
|
2334
|
+
candidateNodeSets.push(dsl.graph.nodes);
|
|
2335
|
+
}
|
|
2336
|
+
const variables = [];
|
|
2337
|
+
for (const nodeSet of candidateNodeSets) {
|
|
2338
|
+
for (const node of nodeSet) {
|
|
2339
|
+
if (!isPlainObject4(node) || !isPlainObject4(node.data)) {
|
|
2340
|
+
continue;
|
|
2341
|
+
}
|
|
2342
|
+
const nodeData = node.data;
|
|
2343
|
+
if (nodeData.type !== "start" || !Array.isArray(nodeData.variables)) {
|
|
2344
|
+
continue;
|
|
2345
|
+
}
|
|
2346
|
+
for (const variable of nodeData.variables) {
|
|
2347
|
+
if (!isPlainObject4(variable) || typeof variable.variable !== "string") {
|
|
2348
|
+
continue;
|
|
2349
|
+
}
|
|
2350
|
+
variables.push({
|
|
2351
|
+
...variable,
|
|
2352
|
+
variable: variable.variable,
|
|
2353
|
+
label: typeof variable.label === "string" ? variable.label : void 0,
|
|
2354
|
+
required: typeof variable.required === "boolean" ? variable.required : void 0,
|
|
2355
|
+
type: typeof variable.type === "string" ? variable.type : void 0
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
return variables;
|
|
2361
|
+
}
|
|
2362
|
+
function normalizeWorkflowDefinition(definition) {
|
|
2363
|
+
return {
|
|
2364
|
+
...definition,
|
|
2365
|
+
workflow_id: typeof definition.workflow_id === "string" ? definition.workflow_id : "",
|
|
2366
|
+
app_id: typeof definition.app_id === "string" ? definition.app_id : "",
|
|
2367
|
+
version: typeof definition.version === "string" ? definition.version : void 0,
|
|
2368
|
+
name: typeof definition.name === "string" ? definition.name : "",
|
|
2369
|
+
dsl: isPlainObject4(definition.dsl) ? definition.dsl : void 0,
|
|
2370
|
+
context: typeof definition.context === "string" ? definition.context : void 0,
|
|
2371
|
+
input_variables: extractWorkflowInputVariables(definition.dsl)
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
2374
|
+
function invalidResponse(status, message) {
|
|
2375
|
+
return {
|
|
2376
|
+
data: null,
|
|
2377
|
+
error: {
|
|
2378
|
+
status,
|
|
2379
|
+
message
|
|
2380
|
+
},
|
|
2381
|
+
status
|
|
2382
|
+
};
|
|
2383
|
+
}
|
|
2384
|
+
function createWorkflowService(client) {
|
|
2385
|
+
return {
|
|
2386
|
+
async list(params = {}) {
|
|
2387
|
+
const response = await client.http.request({
|
|
2388
|
+
url: WORKFLOW_LIST_PATH,
|
|
2389
|
+
method: "GET",
|
|
2390
|
+
params: {
|
|
2391
|
+
page: params.page ?? 1,
|
|
2392
|
+
limit: params.limit ?? 20,
|
|
2393
|
+
mode: params.mode ?? "workflow"
|
|
2394
|
+
}
|
|
2395
|
+
});
|
|
2396
|
+
if (!response.data || !Array.isArray(response.data.data)) {
|
|
2397
|
+
return invalidResponse(
|
|
2398
|
+
response.status,
|
|
2399
|
+
response.error?.message || "Invalid workflow list response structure"
|
|
2400
|
+
);
|
|
2401
|
+
}
|
|
2402
|
+
return {
|
|
2403
|
+
...response,
|
|
2404
|
+
data: {
|
|
2405
|
+
...response.data,
|
|
2406
|
+
page: typeof response.data.page === "number" ? response.data.page : params.page ?? 1,
|
|
2407
|
+
limit: typeof response.data.limit === "number" ? response.data.limit : params.limit ?? 20,
|
|
2408
|
+
total: typeof response.data.total === "number" ? response.data.total : response.data.data.length,
|
|
2409
|
+
has_more: typeof response.data.has_more === "boolean" ? response.data.has_more : false,
|
|
2410
|
+
data: response.data.data.map(normalizeWorkflowSummary)
|
|
2411
|
+
}
|
|
2412
|
+
};
|
|
2413
|
+
},
|
|
2414
|
+
async get(workflowId) {
|
|
2415
|
+
if (!workflowId) {
|
|
2416
|
+
return invalidResponse(400, "workflowId is required");
|
|
2417
|
+
}
|
|
2418
|
+
const response = await client.http.request({
|
|
2419
|
+
url: WORKFLOW_GET_PATH(workflowId),
|
|
2420
|
+
method: "GET"
|
|
2421
|
+
});
|
|
2422
|
+
if (!response.data || !isPlainObject4(response.data)) {
|
|
2423
|
+
return invalidResponse(
|
|
2424
|
+
response.status,
|
|
2425
|
+
response.error?.message || "Invalid workflow definition response structure"
|
|
2426
|
+
);
|
|
2427
|
+
}
|
|
2428
|
+
return {
|
|
2429
|
+
...response,
|
|
2430
|
+
data: normalizeWorkflowDefinition(response.data)
|
|
2431
|
+
};
|
|
2432
|
+
}
|
|
2433
|
+
};
|
|
2434
|
+
}
|
|
2288
2435
|
function loadOptionalJsonObjectInput3(input, label) {
|
|
2289
2436
|
if (!input) {
|
|
2290
2437
|
return {};
|
|
@@ -2359,6 +2506,128 @@ async function runWorkflow(client, options) {
|
|
|
2359
2506
|
exitWithCommandError4(spinner, "Failed to run workflow", error);
|
|
2360
2507
|
}
|
|
2361
2508
|
}
|
|
2509
|
+
async function listWorkflows(client, options = {}) {
|
|
2510
|
+
const spinner = createSpinner("Fetching workflows...", options.format);
|
|
2511
|
+
try {
|
|
2512
|
+
const workflowService = createWorkflowService(client);
|
|
2513
|
+
const result = await workflowService.list({
|
|
2514
|
+
page: options.page,
|
|
2515
|
+
limit: options.limit,
|
|
2516
|
+
mode: options.mode
|
|
2517
|
+
});
|
|
2518
|
+
if (result.error) {
|
|
2519
|
+
spinner.fail("Failed to fetch workflows");
|
|
2520
|
+
console.error(chalk4.red(result.error.message));
|
|
2521
|
+
process.exit(1);
|
|
2522
|
+
}
|
|
2523
|
+
const payload = result.data;
|
|
2524
|
+
const workflows = payload?.data || [];
|
|
2525
|
+
spinner.succeed(`Found ${workflows.length} workflow${workflows.length === 1 ? "" : "s"}`);
|
|
2526
|
+
renderOutput(payload, {
|
|
2527
|
+
format: options.format,
|
|
2528
|
+
tableRows: workflows.map((workflow) => ({
|
|
2529
|
+
id: workflow.id,
|
|
2530
|
+
runnableName: workflow.runnable_name,
|
|
2531
|
+
platformName: workflow.name,
|
|
2532
|
+
mode: workflow.mode,
|
|
2533
|
+
description: workflow.description
|
|
2534
|
+
})),
|
|
2535
|
+
csvRows: workflows.map((workflow) => ({
|
|
2536
|
+
id: workflow.id,
|
|
2537
|
+
runnableName: workflow.runnable_name,
|
|
2538
|
+
platformName: workflow.name,
|
|
2539
|
+
mode: workflow.mode,
|
|
2540
|
+
description: workflow.description
|
|
2541
|
+
})),
|
|
2542
|
+
ndjsonItems: workflows,
|
|
2543
|
+
pretty: () => {
|
|
2544
|
+
console.log(chalk4.blue("\nWorkflows\n"));
|
|
2545
|
+
if (workflows.length === 0) {
|
|
2546
|
+
console.log(chalk4.gray("No workflows found."));
|
|
2547
|
+
return;
|
|
2548
|
+
}
|
|
2549
|
+
for (const workflow of workflows) {
|
|
2550
|
+
console.log(`${chalk4.green("\u2022")} ${chalk4.bold(workflow.runnable_name || workflow.name)}`);
|
|
2551
|
+
console.log(` ${chalk4.gray("ID:")} ${workflow.id}`);
|
|
2552
|
+
console.log(` ${chalk4.gray("Platform Name:")} ${workflow.name}`);
|
|
2553
|
+
console.log(` ${chalk4.gray("Mode:")} ${workflow.mode || "workflow"}`);
|
|
2554
|
+
if (workflow.description) {
|
|
2555
|
+
console.log(` ${chalk4.gray("Description:")} ${workflow.description}`);
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
});
|
|
2560
|
+
} catch (error) {
|
|
2561
|
+
exitWithCommandError4(spinner, "Failed to fetch workflows", error);
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
async function getWorkflow(client, options) {
|
|
2565
|
+
const spinner = createSpinner(`Fetching workflow: ${options.id}...`, options.format);
|
|
2566
|
+
try {
|
|
2567
|
+
const workflowService = createWorkflowService(client);
|
|
2568
|
+
const result = await workflowService.get(options.id);
|
|
2569
|
+
if (result.error) {
|
|
2570
|
+
spinner.fail("Failed to fetch workflow");
|
|
2571
|
+
console.error(chalk4.red(result.error.message));
|
|
2572
|
+
process.exit(1);
|
|
2573
|
+
}
|
|
2574
|
+
const workflow = result.data;
|
|
2575
|
+
const inputVariables = workflow?.input_variables || [];
|
|
2576
|
+
spinner.succeed("Workflow loaded");
|
|
2577
|
+
renderOutput(workflow, {
|
|
2578
|
+
format: options.format,
|
|
2579
|
+
tableRows: workflow ? [
|
|
2580
|
+
{
|
|
2581
|
+
appId: workflow.app_id,
|
|
2582
|
+
workflowId: workflow.workflow_id,
|
|
2583
|
+
runnableName: workflow.name,
|
|
2584
|
+
version: workflow.version || null,
|
|
2585
|
+
inputVariables: inputVariables.map((item) => item.variable).join(", ")
|
|
2586
|
+
}
|
|
2587
|
+
] : [],
|
|
2588
|
+
csvRows: workflow ? [
|
|
2589
|
+
{
|
|
2590
|
+
appId: workflow.app_id,
|
|
2591
|
+
workflowId: workflow.workflow_id,
|
|
2592
|
+
runnableName: workflow.name,
|
|
2593
|
+
version: workflow.version || null,
|
|
2594
|
+
inputVariables: inputVariables.map((item) => item.variable).join(", ")
|
|
2595
|
+
}
|
|
2596
|
+
] : [],
|
|
2597
|
+
ndjsonItems: workflow ? [workflow] : [],
|
|
2598
|
+
pretty: () => {
|
|
2599
|
+
if (!workflow) {
|
|
2600
|
+
console.log(chalk4.gray("No workflow found."));
|
|
2601
|
+
return;
|
|
2602
|
+
}
|
|
2603
|
+
console.log(chalk4.blue(`
|
|
2604
|
+
Workflow: ${workflow.name}
|
|
2605
|
+
`));
|
|
2606
|
+
console.log(`${chalk4.gray("App ID:")} ${workflow.app_id}`);
|
|
2607
|
+
console.log(`${chalk4.gray("Workflow ID:")} ${workflow.workflow_id}`);
|
|
2608
|
+
if (workflow.version) {
|
|
2609
|
+
console.log(`${chalk4.gray("Version:")} ${workflow.version}`);
|
|
2610
|
+
}
|
|
2611
|
+
console.log(`
|
|
2612
|
+
${chalk4.gray("Input Variables:")}`);
|
|
2613
|
+
if (inputVariables.length === 0) {
|
|
2614
|
+
console.log(chalk4.gray(" none"));
|
|
2615
|
+
} else {
|
|
2616
|
+
for (const variable of inputVariables) {
|
|
2617
|
+
const label = variable.label ? ` ${chalk4.gray(`(${variable.label})`)}` : "";
|
|
2618
|
+
const type = variable.type ? ` ${chalk4.gray(`[${variable.type}]`)}` : "";
|
|
2619
|
+
const required = variable.required ? chalk4.yellow(" required") : chalk4.gray(" optional");
|
|
2620
|
+
console.log(` - ${chalk4.bold(variable.variable)}${label}${type}${required}`);
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
console.log(`
|
|
2624
|
+
${chalk4.gray("Run With:")} amaster workflow run ${workflow.name} --app <app-code> --input '{...}'`);
|
|
2625
|
+
}
|
|
2626
|
+
});
|
|
2627
|
+
} catch (error) {
|
|
2628
|
+
exitWithCommandError4(spinner, "Failed to fetch workflow", error);
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2362
2631
|
function exitWithCommandError5(spinner, failureMessage, error) {
|
|
2363
2632
|
spinner.fail(failureMessage);
|
|
2364
2633
|
const details = error instanceof Error ? error.message : String(error);
|
|
@@ -2767,11 +3036,12 @@ function createAmasterClient(appCode) {
|
|
|
2767
3036
|
}
|
|
2768
3037
|
const client = createClient({
|
|
2769
3038
|
baseURL: appConfig.baseURL,
|
|
2770
|
-
|
|
2771
|
-
|
|
3039
|
+
headers: {
|
|
3040
|
+
"x-app-code": appCode,
|
|
3041
|
+
...token ? {
|
|
2772
3042
|
Authorization: `Bearer ${token}`
|
|
2773
|
-
}
|
|
2774
|
-
}
|
|
3043
|
+
} : {}
|
|
3044
|
+
},
|
|
2775
3045
|
onUnauthorized: () => {
|
|
2776
3046
|
if (token) {
|
|
2777
3047
|
console.error(chalk4.red("\n\u274C Session expired. Please login again."));
|
|
@@ -3324,7 +3594,25 @@ bpmCmd.command("start-form-deployed <key>").description("Get deployed start form
|
|
|
3324
3594
|
format: options.format
|
|
3325
3595
|
});
|
|
3326
3596
|
});
|
|
3327
|
-
var workflowCmd = program.command("workflow").description("
|
|
3597
|
+
var workflowCmd = program.command("workflow").description("Inspect and run workflows");
|
|
3598
|
+
workflowCmd.command("list").description("List runnable workflows").option("--app <app-code>", "App code (uses default if not specified)").option("--page <n>", "Page number").option("--limit <n>", "Page size").addOption(
|
|
3599
|
+
new Option("--mode <mode>", "Workflow app mode").choices(["workflow", "chat", "completion", "agent-chat"])
|
|
3600
|
+
).addOption(createFormatOption()).action(async (options) => {
|
|
3601
|
+
const appCode = resolveAppCode(options.app);
|
|
3602
|
+
await listWorkflows(createAmasterClient(appCode), {
|
|
3603
|
+
page: options.page ? parseInt(options.page, 10) : void 0,
|
|
3604
|
+
limit: options.limit ? parseInt(options.limit, 10) : void 0,
|
|
3605
|
+
mode: options.mode,
|
|
3606
|
+
format: options.format
|
|
3607
|
+
});
|
|
3608
|
+
});
|
|
3609
|
+
workflowCmd.command("get <id>").alias("inspect").description("Get workflow details and input variables by workflow app ID").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (id, options) => {
|
|
3610
|
+
const appCode = resolveAppCode(options.app);
|
|
3611
|
+
await getWorkflow(createAmasterClient(appCode), {
|
|
3612
|
+
id,
|
|
3613
|
+
format: options.format
|
|
3614
|
+
});
|
|
3615
|
+
});
|
|
3328
3616
|
workflowCmd.command("run <name>").alias("execute").description("Run a workflow").option("--app <app-code>", "App code (uses default if not specified)").option("-i, --input <json>", "Workflow inputs object as JSON or @file").option("-r, --request <json>", "Full WorkflowRunRequest as JSON or @file").addOption(
|
|
3329
3617
|
new Option("--response-mode <mode>", "Workflow response mode").choices(["blocking", "streaming"])
|
|
3330
3618
|
).option("--user <user>", "Workflow user identifier").option("--files <json>", "Workflow files array as JSON or @file").option("--trace-id <traceId>", "Workflow trace ID").addOption(createFormatOption()).action(async (name, options) => {
|