@@ -12,7 +12,9 @@ function createPiaUrl(itemId, parameters, options, questionPath) {
1212 userId,
1313 version,
1414 agentServiceUrl,
15+ assistantServiceUrl,
1516 } = options ;
17+ const serviceUrl = agentServiceUrl || assistantServiceUrl ;
1618 let queryParams = { c : version } ;
1719
1820 queryParams . key = apiKey ;
@@ -57,7 +59,7 @@ function createPiaUrl(itemId, parameters, options, questionPath) {
5759
5860 const queryString = helpers . stringify ( queryParams ) ;
5961
60- return `${ agentServiceUrl } /v1/item_questions${ questionPath } ?${ queryString } ` ;
62+ return `${ serviceUrl } /v1/item_questions${ questionPath } ?${ queryString } ` ;
6163}
6264
6365/**
@@ -95,17 +97,22 @@ class Pia {
9597 getSuggestedQuestions ( itemId , parameters , networkParameters = { } ) {
9698 let requestUrl ;
9799 const { fetch } = this . options ;
98- const controller = new AbortController ( ) ;
99- const { signal } = controller ;
100+ let signal ;
101+
102+ if ( typeof AbortController === 'function' ) {
103+ const controller = new AbortController ( ) ;
104+
105+ signal = controller && controller . signal ;
106+
107+ helpers . applyNetworkTimeout ( this . options , networkParameters , controller ) ;
108+ }
100109
101110 try {
102111 requestUrl = createPiaUrl ( itemId , parameters , this . options , '' ) ;
103112 } catch ( e ) {
104113 return Promise . reject ( e ) ;
105114 }
106115
107- helpers . applyNetworkTimeout ( this . options , networkParameters , controller ) ;
108-
109116 return fetch ( requestUrl , { signal } )
110117 . then ( helpers . convertResponseToJson )
111118 . then ( ( json ) => {
@@ -140,8 +147,15 @@ class Pia {
140147 getAnswerResults ( itemId , question , parameters , networkParameters = { } ) {
141148 let requestUrl ;
142149 const { fetch } = this . options ;
143- const controller = new AbortController ( ) ;
144- const { signal } = controller ;
150+ let signal ;
151+
152+ if ( typeof AbortController === 'function' ) {
153+ const controller = new AbortController ( ) ;
154+
155+ signal = controller && controller . signal ;
156+
157+ helpers . applyNetworkTimeout ( this . options , networkParameters , controller ) ;
158+ }
145159
146160 if ( ! question || typeof question !== 'string' ) {
147161 return Promise . reject ( new Error ( 'question is a required parameter of type string' ) ) ;
@@ -154,8 +168,6 @@ class Pia {
154168 return Promise . reject ( e ) ;
155169 }
156170
157- helpers . applyNetworkTimeout ( this . options , networkParameters , controller ) ;
158-
159171 return fetch ( requestUrl , { signal } )
160172 . then ( helpers . convertResponseToJson )
161173 . then ( ( json ) => {
0 commit comments