@caruuto/caruuto-js 0.8.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +3 -0
- package/lib/extensions/ai.js +38 -16
- package/lib/helpers.js +1 -1
- package/lib/performFetch.js +3 -1
- package/lib/terminators.js +1 -1
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const CaruutoClient = function (caruutoUrl, caruutoApiKey, options = {}) {
|
|
2
2
|
this.options = options
|
|
3
3
|
this.options.caruutoUrl = caruutoUrl
|
|
4
|
+
.replace(/\/api\/?$/, '')
|
|
5
|
+
.replace(/\/$/, '')
|
|
6
|
+
+ '/api'
|
|
4
7
|
this.options.caruutoApiKey = caruutoApiKey
|
|
5
8
|
|
|
6
9
|
this.options.version = '1'
|
package/lib/extensions/ai.js
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = function (CaruutoClient, clientInstance) {
|
|
|
28
28
|
const body = buildRequestBody(opts, false)
|
|
29
29
|
const response = await doFetch(
|
|
30
30
|
this,
|
|
31
|
-
`${this.options.caruutoUrl}/
|
|
31
|
+
`${this.options.caruutoUrl}/ai/external`,
|
|
32
32
|
body
|
|
33
33
|
)
|
|
34
34
|
return response.status === 204 ? undefined : response.json()
|
|
@@ -49,7 +49,7 @@ module.exports = function (CaruutoClient, clientInstance) {
|
|
|
49
49
|
const body = buildRequestBody(opts, true)
|
|
50
50
|
const response = await doFetch(
|
|
51
51
|
this,
|
|
52
|
-
`${this.options.caruutoUrl}/
|
|
52
|
+
`${this.options.caruutoUrl}/ai/external`,
|
|
53
53
|
body
|
|
54
54
|
)
|
|
55
55
|
|
|
@@ -117,7 +117,7 @@ module.exports = function (CaruutoClient, clientInstance) {
|
|
|
117
117
|
throw new Error('projectId is required')
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
const url = `${this.options.caruutoUrl}/
|
|
120
|
+
const url = `${this.options.caruutoUrl}/ai/conversations/${conversationId}/end`
|
|
121
121
|
const response = await doFetch(this, url, { project_id: projectId })
|
|
122
122
|
return response.json()
|
|
123
123
|
}.bind(clientInstance),
|
|
@@ -167,7 +167,7 @@ module.exports = function (CaruutoClient, clientInstance) {
|
|
|
167
167
|
|
|
168
168
|
const response = await doFetch(
|
|
169
169
|
this,
|
|
170
|
-
`${this.options.caruutoUrl}/
|
|
170
|
+
`${this.options.caruutoUrl}/ai/context`,
|
|
171
171
|
body
|
|
172
172
|
)
|
|
173
173
|
return response.json()
|
|
@@ -220,21 +220,35 @@ module.exports = function (CaruutoClient, clientInstance) {
|
|
|
220
220
|
* @param {'conversation'|'question_cache'} opts.source
|
|
221
221
|
* @returns {Promise<{ id: string }>} New conversation ID
|
|
222
222
|
*/
|
|
223
|
-
forkConversation: async function ({
|
|
223
|
+
forkConversation: async function ({
|
|
224
|
+
sourceId,
|
|
225
|
+
projectId,
|
|
226
|
+
source = 'conversation'
|
|
227
|
+
} = {}) {
|
|
224
228
|
if (!sourceId) throw new Error('sourceId is required')
|
|
225
229
|
if (!projectId) throw new Error('projectId is required')
|
|
226
230
|
|
|
227
|
-
const url = `${this.options.caruutoUrl}/
|
|
228
|
-
const response = await doFetch(this, url, {
|
|
231
|
+
const url = `${this.options.caruutoUrl}/ai/conversations/${sourceId}/fork`
|
|
232
|
+
const response = await doFetch(this, url, {
|
|
233
|
+
project_id: projectId,
|
|
234
|
+
source
|
|
235
|
+
})
|
|
229
236
|
return response.json()
|
|
230
237
|
}.bind(clientInstance),
|
|
231
238
|
|
|
232
|
-
shareConversation: async function ({
|
|
239
|
+
shareConversation: async function ({
|
|
240
|
+
conversationId,
|
|
241
|
+
projectId,
|
|
242
|
+
visibility = 'public'
|
|
243
|
+
} = {}) {
|
|
233
244
|
if (!conversationId) throw new Error('conversationId is required')
|
|
234
245
|
if (!projectId) throw new Error('projectId is required')
|
|
235
246
|
|
|
236
|
-
const url = `${this.options.caruutoUrl}/
|
|
237
|
-
const response = await doFetch(this, url, {
|
|
247
|
+
const url = `${this.options.caruutoUrl}/ai/conversations/${conversationId}/share`
|
|
248
|
+
const response = await doFetch(this, url, {
|
|
249
|
+
project_id: projectId,
|
|
250
|
+
visibility
|
|
251
|
+
})
|
|
238
252
|
return response.json()
|
|
239
253
|
}.bind(clientInstance),
|
|
240
254
|
|
|
@@ -250,7 +264,7 @@ module.exports = function (CaruutoClient, clientInstance) {
|
|
|
250
264
|
if (!conversationId) throw new Error('conversationId is required')
|
|
251
265
|
|
|
252
266
|
const fetch = this.options.fetch || undici.fetch
|
|
253
|
-
const url = `${this.options.caruutoUrl}/
|
|
267
|
+
const url = `${this.options.caruutoUrl}/ai/conversations/${conversationId}/public`
|
|
254
268
|
|
|
255
269
|
const response = await fetch(url, { method: 'GET' })
|
|
256
270
|
|
|
@@ -276,7 +290,11 @@ module.exports = function (CaruutoClient, clientInstance) {
|
|
|
276
290
|
throw new Error('projectId is required')
|
|
277
291
|
}
|
|
278
292
|
|
|
279
|
-
const url = `${
|
|
293
|
+
const url = `${
|
|
294
|
+
this.options.caruutoUrl
|
|
295
|
+
}/ai/conversations/${conversationId}?project_id=${encodeURIComponent(
|
|
296
|
+
projectId
|
|
297
|
+
)}`
|
|
280
298
|
const response = await doGet(this, url)
|
|
281
299
|
return response.json()
|
|
282
300
|
}.bind(clientInstance),
|
|
@@ -316,7 +334,7 @@ module.exports = function (CaruutoClient, clientInstance) {
|
|
|
316
334
|
if (leadEmail) body.lead_email = leadEmail
|
|
317
335
|
if (leadName) body.lead_name = leadName
|
|
318
336
|
|
|
319
|
-
const url = `${this.options.caruutoUrl}/
|
|
337
|
+
const url = `${this.options.caruutoUrl}/ai/conversations/${conversationId}/turn`
|
|
320
338
|
const response = await doFetch(this, url, body)
|
|
321
339
|
return response.json()
|
|
322
340
|
}.bind(clientInstance),
|
|
@@ -359,7 +377,7 @@ module.exports = function (CaruutoClient, clientInstance) {
|
|
|
359
377
|
if (linkLabel) body.link_label = linkLabel
|
|
360
378
|
if (messageIndex !== undefined) body.message_index = messageIndex
|
|
361
379
|
|
|
362
|
-
const trackUrl = `${this.options.caruutoUrl}/
|
|
380
|
+
const trackUrl = `${this.options.caruutoUrl}/ai/conversations/${conversationId}/link-click`
|
|
363
381
|
const response = await doFetch(this, trackUrl, body)
|
|
364
382
|
return response.json()
|
|
365
383
|
}.bind(clientInstance)
|
|
@@ -427,7 +445,9 @@ async function doGet(client, url) {
|
|
|
427
445
|
if (data.error) {
|
|
428
446
|
err.message = data.error
|
|
429
447
|
}
|
|
430
|
-
} catch (_) {
|
|
448
|
+
} catch (_) {
|
|
449
|
+
// Ignore JSON parsing errors and use the default error message
|
|
450
|
+
}
|
|
431
451
|
|
|
432
452
|
throw err
|
|
433
453
|
}
|
|
@@ -456,7 +476,9 @@ async function doFetch(client, url, body) {
|
|
|
456
476
|
if (data.error) {
|
|
457
477
|
err.message = data.error
|
|
458
478
|
}
|
|
459
|
-
} catch (_) {
|
|
479
|
+
} catch (_) {
|
|
480
|
+
// Ignore JSON parsing errors and use the default error message
|
|
481
|
+
}
|
|
460
482
|
|
|
461
483
|
throw err
|
|
462
484
|
}
|
package/lib/helpers.js
CHANGED
package/lib/performFetch.js
CHANGED
|
@@ -67,7 +67,9 @@ module.exports = function (CaruutoClient) {
|
|
|
67
67
|
if (responseData.errors) {
|
|
68
68
|
err.errors = responseData.errors
|
|
69
69
|
}
|
|
70
|
-
} catch (_) {
|
|
70
|
+
} catch (_) {
|
|
71
|
+
// Ignore JSON parsing errors and use the default error message
|
|
72
|
+
}
|
|
71
73
|
|
|
72
74
|
return Promise.reject(err)
|
|
73
75
|
}
|
package/lib/terminators.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caruuto/caruuto-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "A high-level library for interacting with Caruuto",
|
|
5
5
|
"exports": "./index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "eslint --ext js,jsx . && prettier --write '**/*.{js,jsx,md,html,css}' && NODE_ENV=test mocha
|
|
7
|
+
"test": "eslint --ext js,jsx . && prettier --write '**/*.{js,jsx,md,html,css}' && NODE_ENV=test mocha test/**/*.js",
|
|
8
8
|
"posttest": "./scripts/coverage.js"
|
|
9
9
|
},
|
|
10
10
|
"author": "Jim Lambie <jim@27.works>",
|
|
@@ -50,4 +50,4 @@
|
|
|
50
50
|
"should": "^9.0.2",
|
|
51
51
|
"sinon": "^4.5.0"
|
|
52
52
|
}
|
|
53
|
-
}
|
|
53
|
+
}
|