fix: sync-example implementation

This commit is contained in:
tusharmagar 2025-11-21 10:32:24 +05:30
parent 55d9f80074
commit 532065dc0b
4 changed files with 197 additions and 150 deletions

View file

@ -1,8 +1,7 @@
#!/usr/bin/env node
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { app, modelConfig, updateState } from '../dist/app.js';
import { importExample, listAvailableExamples } from '../dist/application/examples/import-example.js';
import { app, modelConfig, updateState, importExample, listExamples } from '../dist/app.js';
yargs(hideBin(process.argv))
@ -26,41 +25,9 @@ yargs(hideBin(process.argv))
type: "boolean",
description: "Do not interact with the user",
default: false,
})
.option("sync-example", {
type: "string",
description: "Import an example workflow by name (use 'all' for every example) before running",
}),
async (argv) => {
let agent = argv.agent ?? "copilot";
if (argv["sync-example"]) {
const requested = String(argv["sync-example"]).trim();
const isAll = requested.toLowerCase() === "all";
try {
const examplesToImport = isAll ? await listAvailableExamples() : [requested];
if (examplesToImport.length === 0) {
console.error("No packaged examples are available to import.");
process.exit(1);
}
for (const exampleName of examplesToImport) {
const imported = await importExample(exampleName);
const agentList = imported.importedAgents.join(", ");
console.error(`Imported example '${exampleName}' with agents: ${agentList}`);
console.error(`Primary agent: ${imported.entryAgent}`);
if (imported.addedServers.length > 0) {
console.error(`Configured new MCP servers: ${imported.addedServers.join(", ")}`);
}
if (imported.skippedServers.length > 0) {
console.error(`Skipped existing MCP servers (already configured): ${imported.skippedServers.join(", ")}`);
}
}
} catch (error) {
console.error(error?.message ?? error);
process.exit(1);
}
console.error("Examples imported. Re-run rowboatx without --sync-example (or with --agent <name>) when you're ready to chat.");
return;
}
await app({
agent,
runId: argv.run_id,
@ -69,6 +36,69 @@ yargs(hideBin(process.argv))
});
}
)
.command(
"sync-example <example>",
"Import an example workflow by name",
(y) => y.positional("example", {
type: "string",
description: "The example to import",
}),
async (argv) => {
const exampleName = String(argv.example).trim();
try {
const imported = await importExample(exampleName);
// Build output message
const output = [
`✓ Imported example '${exampleName}'`,
` Agents: ${imported.importedAgents.join(", ")}`,
` Primary: ${imported.entryAgent}`,
];
if (imported.addedServers.length > 0) {
output.push(` MCP servers added: ${imported.addedServers.join(", ")}`);
}
if (imported.skippedServers.length > 0) {
output.push(` MCP servers skipped (already configured): ${imported.skippedServers.join(", ")}`);
}
console.log(output.join("\n"));
if (imported.postInstallInstructions) {
console.log("\n" + "=".repeat(60));
console.log("POST-INSTALL INSTRUCTIONS");
console.log("=".repeat(60));
console.log(imported.postInstallInstructions);
console.log("=".repeat(60) + "\n");
}
console.log(`\nRun: rowboatx --agent ${imported.entryAgent}`);
} catch (error) {
console.error("Error:", error?.message ?? error);
process.exit(1);
}
}
)
.command(
"list-example",
"List all available example workflows",
(y) => y,
async () => {
try {
const examples = await listExamples();
if (examples.length === 0) {
console.error("No packaged examples are available to list.");
return;
}
for (const example of examples) {
console.log(example);
}
} catch (error) {
console.error(error?.message ?? error);
process.exit(1);
}
}
)
.command(
"model-config",
"Select model",