Comparing version 6.5.1 to 6.6.0
@@ -6,4 +6,4 @@ /** | ||
module.exports = { | ||
DEFAULT_API_VERSION: 20220801, | ||
DEFAULT_API_VERSION: 20230215, | ||
DEFAULT_WIT_URL: 'https://api.wit.ai', | ||
}; |
@@ -16,2 +16,3 @@ /** | ||
const LIVE_UNDERSTANDING_API_VERSION = 20220608; | ||
const MULTI_RESPONSES_API_VERSION = 20230215; | ||
@@ -49,3 +50,3 @@ class Wit extends EventEmitter { | ||
const {apiVersion, headers, logger, proxy, witURL} = this.config; | ||
const {actions, apiVersion, headers, logger, proxy, witURL} = this.config; | ||
@@ -65,2 +66,4 @@ const params = { | ||
const multi_responses_enabled = apiVersion >= MULTI_RESPONSES_API_VERSION; | ||
const req = fetch(fullURL, { | ||
@@ -79,6 +82,6 @@ body, | ||
.then( | ||
response => | ||
resp => | ||
new Promise((resolve, reject) => { | ||
logger.debug('status', response.status); | ||
const bodyStream = response.body; | ||
logger.debug('status', resp.status); | ||
const bodyStream = resp.body; | ||
@@ -93,3 +96,4 @@ bodyStream.on('readable', () => { | ||
for (const rsp of parseResponse(contents)) { | ||
const {error, is_final, text} = rsp; | ||
const {action, context_map, error, is_final, response, text} = | ||
rsp; | ||
@@ -101,2 +105,19 @@ // Live transcription | ||
} | ||
// Multi-responses | ||
if ( | ||
multi_responses_enabled && | ||
!(error || is_final) && | ||
(action || response) | ||
) { | ||
if (response) { | ||
logger.debug('[converse] partialResponse:', response); | ||
this.emit('response', response); | ||
} | ||
if (action) { | ||
logger.debug('[converse] got partial action:', action); | ||
runAction(logger, actions, action, context_map); | ||
} | ||
} | ||
} | ||
@@ -130,3 +151,3 @@ }); | ||
const {apiVersion, headers, logger, proxy, witURL} = this.config; | ||
const {actions, apiVersion, headers, logger, proxy, witURL} = this.config; | ||
@@ -152,4 +173,52 @@ const params = { | ||
return fetch(fullURL, {body: JSON.stringify(body), method, headers, proxy}) | ||
.then(response => Promise.all([response.json(), response.status])) | ||
const req = fetch(fullURL, { | ||
body: JSON.stringify(body), | ||
method, | ||
headers, | ||
proxy, | ||
}); | ||
// Multi-responses | ||
if (apiVersion >= MULTI_RESPONSES_API_VERSION) { | ||
const _partialResponses = req | ||
.then( | ||
resp => | ||
new Promise((resolve, reject) => { | ||
logger.debug('status', resp.status); | ||
const bodyStream = resp.body; | ||
bodyStream.on('readable', () => { | ||
let chunk; | ||
let contents = ''; | ||
while (null !== (chunk = bodyStream.read())) { | ||
contents += chunk.toString(); | ||
} | ||
for (const rsp of parseResponse(contents)) { | ||
const {action, context_map, error, is_final, response} = rsp; | ||
if (!(error || is_final) && (action || response)) { | ||
if (response) { | ||
logger.debug('[event] partialResponse:', response); | ||
this.emit('response', response); | ||
} | ||
if (action) { | ||
logger.debug('[event] got partial action:', action); | ||
runAction(logger, actions, action, context_map); | ||
} | ||
} | ||
} | ||
}); | ||
}), | ||
) | ||
.catch(e => | ||
logger.error('[event] could not parse partial response', e), | ||
); | ||
} | ||
return req | ||
.then(response => Promise.all([response.text(), response.status])) | ||
.then(([contents, status]) => ([parseResponse(contents).pop(), status])) | ||
.catch(e => e) | ||
.then(makeWitResponseHandler(logger, 'event')); | ||
@@ -375,3 +444,3 @@ } | ||
if (typeof voice !== 'string') { | ||
throw new Error('Please provide a voice input. (string)'); | ||
throw new Error('Please provide a voice input (string).'); | ||
} | ||
@@ -378,0 +447,0 @@ |
{ | ||
"name": "node-wit", | ||
"version": "6.5.1", | ||
"version": "6.6.0", | ||
"description": "Wit.ai Node.js SDK", | ||
@@ -12,3 +12,4 @@ "keywords": [ | ||
"nlp", | ||
"automation" | ||
"automation", | ||
"composer" | ||
], | ||
@@ -15,0 +16,0 @@ "main": "index.js", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
42944
10
1318
15
14