Open zerolethanh opened 1 week ago
currently, we resolved this issue by this solution:
// read all flows in /flows dir
const allFlowsDir = path.resolve(devEnv ? "src" : "lib", "flows");
type IFlows = FlowServerOptions['flows']
const allFlows: IFlows = []
fs.readdirSync(allFlowsDir).forEach((name) => {
const flowDir = path.join(allFlowsDir, name);
// logInfo("loading flow:", flowDir);
try {
const flowList = require(path.join(flowDir, "flows")); // require flows.ts|.js
if (flowList) {
const flows = Object.values(flowList) as IFlows
allFlows.push(...flows)
}
// logSuccess(`loaded flow: ${flowDir}`);
} catch (e: any) {
logError(e);
}
});
ai.startFlowServer(
{
flows: allFlows
}
);
@pavelgj Exposing Genkit.registeredFlows
seems reasonable even if we were to deprecate/not recommend Genkit.startFlowServer
anymore since users may still want to iterate through all of them to add to their own server.
Thanks for the suggestion, @zerolethanh!
Is your feature request related to a problem? Please describe. I have to import many flows when run
ai.startFlowServer
Describe the solution you'd like public this
registeredFlows
prop? or something like optionalflows
prop onai.startFlowServer
, e.g: ai.startFlowServer({flows?:[...ai.registeredFlows]})Describe alternatives you've considered We have designed flows system by read flows.ts|.js in sub-folders like:
Additional context