@@ -12,18 +12,20 @@ import {
1212 * Invokes an alias of a flow to run the inputs that you specify and return
1313 * the output of each node as a stream.
1414 *
15- * @param {string } flowIdentifier - The unique identifier of the flow.
16- * @param {string } flowAliasIdentifier - The unique identifier of the flow alias.
17- * @param {string } prompt - The input to send to the prompt flow input node.
18- * @param {string } [region='us-east-1'] - The AWS region in use.
15+ * @param {{
16+ * flowIdentifier: string,
17+ * flowAliasIdentifier: string,
18+ * prompt?: string,
19+ * region?: string
20+ * }} options
1921 * @returns {Promise<import("@aws-sdk/client-bedrock-agent").FlowNodeOutput> } An object containing information about the output from flow invocation.
2022 */
21- export const invokeBedrockFlow = async (
23+ export const invokeBedrockFlow = async ( {
2224 flowIdentifier,
2325 flowAliasIdentifier,
24- prompt ,
26+ prompt = "Hi, how are you?" ,
2527 region = "us-east-1" ,
26- ) => {
28+ } ) => {
2729 const client = new BedrockAgentRuntimeClient ( { region } ) ;
2830
2931 const command = new InvokeFlowCommand ( {
@@ -59,15 +61,39 @@ export const invokeBedrockFlow = async (
5961} ;
6062
6163// Call function if run directly
62- if ( process . argv [ 1 ] === fileURLToPath ( import . meta. url ) ) {
63- const flowIdentifier = "[YOUR_FLOW_ID]" ;
64- const flowAliasIdentifier = "[YOUR_FLOW_ALIAS_ID]" ;
65- const prompt = "Hi, how are you?" ;
64+ import { parseArgs } from "node:util" ;
65+ import {
66+ isMain ,
67+ validateArgs ,
68+ } from "@aws-doc-sdk-examples/lib/utils/util-node.js" ;
6669
67- const result = await invokeBedrockFlow (
68- flowIdentifier ,
69- flowAliasIdentifier ,
70- prompt ,
71- ) ;
72- console . log ( "Final flow output: " , result ) ;
70+ const loadArgs = ( ) => {
71+ const options = {
72+ flowIdentifier : {
73+ type : "string" ,
74+ required : true ,
75+ } ,
76+ flowAliasIdentifier : {
77+ type : "string" ,
78+ required : true ,
79+ } ,
80+ prompt : {
81+ type : "string" ,
82+ } ,
83+ region : {
84+ type : "string" ,
85+ } ,
86+ } ;
87+ const results = parseArgs ( { options } ) ;
88+ const { errors } = validateArgs ( { options } , results ) ;
89+ return { errors, results } ;
90+ } ;
91+
92+ if ( isMain ( import . meta. url ) ) {
93+ const { errors, results } = loadArgs ( ) ;
94+ if ( ! errors ) {
95+ invokeBedrockFlow ( results . values ) ;
96+ } else {
97+ console . error ( errors . join ( "\n" ) ) ;
98+ }
7399}
0 commit comments