@toothfairyai/cli 1.2.0 → 1.5.0
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/bin/toothfairy.js +4648 -72
- package/package.json +7 -5
- package/src/api.js +625 -15
- package/src/config.js +7 -3
package/src/api.js
CHANGED
|
@@ -367,6 +367,8 @@ class ToothFairyAPI {
|
|
|
367
367
|
* @param {Function} onEvent - Callback function called for each event
|
|
368
368
|
* @param {Object} attachments - File attachments (images, audios, videos, files)
|
|
369
369
|
* @param {boolean} showProgress - Show all progress events from SSE endpoint (default: false)
|
|
370
|
+
* @param {string|null} chatId - Existing chat ID to continue conversation (default: null, creates new chat)
|
|
371
|
+
* @param {boolean} rawStream - Enable raw streaming mode for chunk-by-chunk output (default: false)
|
|
370
372
|
* @returns {Promise<void>} - Promise resolves when streaming is complete
|
|
371
373
|
*
|
|
372
374
|
* Event Types Explained:
|
|
@@ -399,7 +401,8 @@ class ToothFairyAPI {
|
|
|
399
401
|
onEvent,
|
|
400
402
|
attachments = {},
|
|
401
403
|
showProgress = false,
|
|
402
|
-
chatId = null
|
|
404
|
+
chatId = null,
|
|
405
|
+
rawStream = false
|
|
403
406
|
) {
|
|
404
407
|
try {
|
|
405
408
|
// Use defaults for optional parameters
|
|
@@ -463,6 +466,7 @@ class ToothFairyAPI {
|
|
|
463
466
|
chatid: chatId,
|
|
464
467
|
messages: [messageData],
|
|
465
468
|
agentid: agentId,
|
|
469
|
+
raw_stream: rawStream,
|
|
466
470
|
};
|
|
467
471
|
|
|
468
472
|
// Stream the agent response using the dedicated streaming URL
|
|
@@ -511,7 +515,14 @@ class ToothFairyAPI {
|
|
|
511
515
|
}
|
|
512
516
|
|
|
513
517
|
// Standard event processing (always executed for backward compatibility)
|
|
514
|
-
|
|
518
|
+
// Handle raw_stream token events (streaming text chunks)
|
|
519
|
+
if (eventData.type === 'token' && eventData.chunk !== undefined) {
|
|
520
|
+
// Token streaming event - emit as 'data' with text field for compatibility
|
|
521
|
+
onEvent('data', {
|
|
522
|
+
...eventData,
|
|
523
|
+
text: eventData.chunk,
|
|
524
|
+
});
|
|
525
|
+
} else if (eventData.status) {
|
|
515
526
|
if (eventData.status === 'connected') {
|
|
516
527
|
onEvent('status', eventData);
|
|
517
528
|
} else if (eventData.status === 'complete') {
|
|
@@ -520,10 +531,15 @@ class ToothFairyAPI {
|
|
|
520
531
|
// Parse metadata to understand what's happening
|
|
521
532
|
let metadata = {};
|
|
522
533
|
if (eventData.metadata) {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
534
|
+
// metadata can be an object or a JSON string
|
|
535
|
+
if (typeof eventData.metadata === 'object') {
|
|
536
|
+
metadata = eventData.metadata;
|
|
537
|
+
} else {
|
|
538
|
+
try {
|
|
539
|
+
metadata = JSON.parse(eventData.metadata);
|
|
540
|
+
} catch (e) {
|
|
541
|
+
metadata = { raw_metadata: eventData.metadata };
|
|
542
|
+
}
|
|
527
543
|
}
|
|
528
544
|
}
|
|
529
545
|
|
|
@@ -550,8 +566,17 @@ class ToothFairyAPI {
|
|
|
550
566
|
eventData.text &&
|
|
551
567
|
eventData.type === 'message'
|
|
552
568
|
) {
|
|
553
|
-
// This is streaming text data
|
|
569
|
+
// This is streaming text data (non-raw_stream mode)
|
|
554
570
|
onEvent('data', eventData);
|
|
571
|
+
} else if (
|
|
572
|
+
eventData.type === 'message' &&
|
|
573
|
+
eventData.chat_created === true
|
|
574
|
+
) {
|
|
575
|
+
// Chat creation event from raw_stream mode
|
|
576
|
+
onEvent('chat_created', {
|
|
577
|
+
...eventData,
|
|
578
|
+
chatId: eventData.chatid,
|
|
579
|
+
});
|
|
555
580
|
} else if (
|
|
556
581
|
eventData.type === 'message' &&
|
|
557
582
|
eventData.images !== undefined
|
|
@@ -568,7 +593,7 @@ class ToothFairyAPI {
|
|
|
568
593
|
eventData.type === 'chat_created' ||
|
|
569
594
|
eventData.event === 'chat_created'
|
|
570
595
|
) {
|
|
571
|
-
// Chat creation event
|
|
596
|
+
// Chat creation event (legacy format)
|
|
572
597
|
onEvent('chat_created', eventData);
|
|
573
598
|
} else {
|
|
574
599
|
// Generic event data
|
|
@@ -660,6 +685,7 @@ class ToothFairyAPI {
|
|
|
660
685
|
customerId: customerId,
|
|
661
686
|
providerId: providerId,
|
|
662
687
|
customerInfo: customerInfo,
|
|
688
|
+
raw_stream: rawStream,
|
|
663
689
|
};
|
|
664
690
|
|
|
665
691
|
// Stream the agent response using the dedicated streaming URL
|
|
@@ -708,7 +734,14 @@ class ToothFairyAPI {
|
|
|
708
734
|
}
|
|
709
735
|
|
|
710
736
|
// Standard event processing (always executed for backward compatibility)
|
|
711
|
-
|
|
737
|
+
// Handle raw_stream token events (streaming text chunks)
|
|
738
|
+
if (eventData.type === 'token' && eventData.chunk !== undefined) {
|
|
739
|
+
// Token streaming event - emit as 'data' with text field for compatibility
|
|
740
|
+
onEvent('data', {
|
|
741
|
+
...eventData,
|
|
742
|
+
text: eventData.chunk,
|
|
743
|
+
});
|
|
744
|
+
} else if (eventData.status) {
|
|
712
745
|
if (eventData.status === 'connected') {
|
|
713
746
|
onEvent('status', eventData);
|
|
714
747
|
} else if (eventData.status === 'complete') {
|
|
@@ -717,10 +750,15 @@ class ToothFairyAPI {
|
|
|
717
750
|
// Parse metadata to understand what's happening
|
|
718
751
|
let metadata = {};
|
|
719
752
|
if (eventData.metadata) {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
753
|
+
// metadata can be an object or a JSON string
|
|
754
|
+
if (typeof eventData.metadata === 'object') {
|
|
755
|
+
metadata = eventData.metadata;
|
|
756
|
+
} else {
|
|
757
|
+
try {
|
|
758
|
+
metadata = JSON.parse(eventData.metadata);
|
|
759
|
+
} catch (e) {
|
|
760
|
+
metadata = { raw_metadata: eventData.metadata };
|
|
761
|
+
}
|
|
724
762
|
}
|
|
725
763
|
}
|
|
726
764
|
|
|
@@ -747,8 +785,17 @@ class ToothFairyAPI {
|
|
|
747
785
|
eventData.text &&
|
|
748
786
|
eventData.type === 'message'
|
|
749
787
|
) {
|
|
750
|
-
// This is streaming text data
|
|
788
|
+
// This is streaming text data (non-raw_stream mode)
|
|
751
789
|
onEvent('data', eventData);
|
|
790
|
+
} else if (
|
|
791
|
+
eventData.type === 'message' &&
|
|
792
|
+
eventData.chat_created === true
|
|
793
|
+
) {
|
|
794
|
+
// Chat creation event from raw_stream mode
|
|
795
|
+
onEvent('chat_created', {
|
|
796
|
+
...eventData,
|
|
797
|
+
chatId: eventData.chatid,
|
|
798
|
+
});
|
|
752
799
|
} else if (
|
|
753
800
|
eventData.type === 'message' &&
|
|
754
801
|
eventData.images !== undefined
|
|
@@ -765,7 +812,7 @@ class ToothFairyAPI {
|
|
|
765
812
|
eventData.type === 'chat_created' ||
|
|
766
813
|
eventData.event === 'chat_created'
|
|
767
814
|
) {
|
|
768
|
-
// Chat creation event
|
|
815
|
+
// Chat creation event (legacy format)
|
|
769
816
|
onEvent('chat_created', eventData);
|
|
770
817
|
} else {
|
|
771
818
|
// Generic event data
|
|
@@ -2058,6 +2105,569 @@ class ToothFairyAPI {
|
|
|
2058
2105
|
throw error;
|
|
2059
2106
|
}
|
|
2060
2107
|
}
|
|
2108
|
+
|
|
2109
|
+
// Agent Management Methods
|
|
2110
|
+
|
|
2111
|
+
/**
|
|
2112
|
+
* Create a new agent
|
|
2113
|
+
*
|
|
2114
|
+
* @param {Object} agentData - Agent configuration
|
|
2115
|
+
* @param {string} agentData.label - Agent display name (required)
|
|
2116
|
+
* @param {string} agentData.mode - Agent mode: retriever, coder, chatter, planner, computer, voice (required)
|
|
2117
|
+
* @param {string} agentData.interpolationString - System prompt template (required)
|
|
2118
|
+
* @param {string} agentData.goals - Primary objectives (required)
|
|
2119
|
+
* @param {number} agentData.temperature - Response creativity level (required)
|
|
2120
|
+
* @param {number} agentData.maxTokens - Maximum tokens in response (required)
|
|
2121
|
+
* @param {number} agentData.maxHistory - Maximum conversation history (required)
|
|
2122
|
+
* @param {number} agentData.topK - Number of top results for retrieval (required)
|
|
2123
|
+
* @param {number} agentData.docTopK - Number of top documents to retrieve (required)
|
|
2124
|
+
* @returns {Promise<Object>} Created agent data
|
|
2125
|
+
*/
|
|
2126
|
+
async createAgent(agentData) {
|
|
2127
|
+
try {
|
|
2128
|
+
return await this._makeRequest('POST', 'agent/create', agentData);
|
|
2129
|
+
} catch (error) {
|
|
2130
|
+
console.error(`Error creating agent: ${error.message}`);
|
|
2131
|
+
throw error;
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
/**
|
|
2136
|
+
* Get a specific agent by ID
|
|
2137
|
+
*
|
|
2138
|
+
* @param {string} agentId - Agent ID to retrieve
|
|
2139
|
+
* @returns {Promise<Object>} Agent data
|
|
2140
|
+
*/
|
|
2141
|
+
async getAgent(agentId) {
|
|
2142
|
+
try {
|
|
2143
|
+
return await this._makeRequest('GET', `agent/get/${agentId}`);
|
|
2144
|
+
} catch (error) {
|
|
2145
|
+
console.error(`Error getting agent: ${error.message}`);
|
|
2146
|
+
throw error;
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
/**
|
|
2151
|
+
* List all agents in the workspace
|
|
2152
|
+
*
|
|
2153
|
+
* @param {number} limit - Maximum number of agents to return (optional)
|
|
2154
|
+
* @param {number} offset - Number of agents to skip (optional)
|
|
2155
|
+
* @returns {Promise<Object>} List of agents
|
|
2156
|
+
*/
|
|
2157
|
+
async listAgents(limit = null, offset = null) {
|
|
2158
|
+
try {
|
|
2159
|
+
const params = { workspaceid: this.workspaceId };
|
|
2160
|
+
if (limit) params.limit = limit;
|
|
2161
|
+
if (offset) params.offset = offset;
|
|
2162
|
+
return await this._makeRequest('GET', 'agent/list', params);
|
|
2163
|
+
} catch (error) {
|
|
2164
|
+
console.error(`Error listing agents: ${error.message}`);
|
|
2165
|
+
throw error;
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
/**
|
|
2170
|
+
* Update an existing agent
|
|
2171
|
+
*
|
|
2172
|
+
* @param {string} agentId - Agent ID to update
|
|
2173
|
+
* @param {Object} fields - Fields to update
|
|
2174
|
+
* @returns {Promise<Object>} Updated agent data
|
|
2175
|
+
*/
|
|
2176
|
+
async updateAgent(agentId, fields) {
|
|
2177
|
+
try {
|
|
2178
|
+
const updateData = {
|
|
2179
|
+
id: agentId,
|
|
2180
|
+
...fields,
|
|
2181
|
+
};
|
|
2182
|
+
return await this._makeRequest('POST', `agent/update/${agentId}`, updateData);
|
|
2183
|
+
} catch (error) {
|
|
2184
|
+
console.error(`Error updating agent: ${error.message}`);
|
|
2185
|
+
throw error;
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
/**
|
|
2190
|
+
* Delete an agent
|
|
2191
|
+
*
|
|
2192
|
+
* @param {string} agentId - Agent ID to delete
|
|
2193
|
+
* @returns {Promise<Object>} Deletion result
|
|
2194
|
+
*/
|
|
2195
|
+
async deleteAgent(agentId) {
|
|
2196
|
+
try {
|
|
2197
|
+
return await this._makeRequest('DELETE', `agent/delete/${agentId}`);
|
|
2198
|
+
} catch (error) {
|
|
2199
|
+
console.error(`Error deleting agent: ${error.message}`);
|
|
2200
|
+
throw error;
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
|
|
2204
|
+
// Authorization Management Methods
|
|
2205
|
+
|
|
2206
|
+
/**
|
|
2207
|
+
* Create a new authorization
|
|
2208
|
+
*
|
|
2209
|
+
* @param {Object} authData - Authorization configuration
|
|
2210
|
+
* @returns {Promise<Object>} Created authorization data
|
|
2211
|
+
*/
|
|
2212
|
+
async createAuthorization(authData) {
|
|
2213
|
+
try {
|
|
2214
|
+
return await this._makeRequest('POST', 'authorisation/create', authData);
|
|
2215
|
+
} catch (error) {
|
|
2216
|
+
console.error(`Error creating authorization: ${error.message}`);
|
|
2217
|
+
throw error;
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
/**
|
|
2222
|
+
* Get a specific authorization by ID
|
|
2223
|
+
*
|
|
2224
|
+
* @param {string} authId - Authorization ID to retrieve
|
|
2225
|
+
* @returns {Promise<Object>} Authorization data
|
|
2226
|
+
*/
|
|
2227
|
+
async getAuthorization(authId) {
|
|
2228
|
+
try {
|
|
2229
|
+
return await this._makeRequest('GET', `authorisation/get/${authId}`);
|
|
2230
|
+
} catch (error) {
|
|
2231
|
+
console.error(`Error getting authorization: ${error.message}`);
|
|
2232
|
+
throw error;
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
|
|
2236
|
+
/**
|
|
2237
|
+
* List all authorizations in the workspace
|
|
2238
|
+
*
|
|
2239
|
+
* @param {number} limit - Maximum number of authorizations to return (optional)
|
|
2240
|
+
* @param {number} offset - Number of authorizations to skip (optional)
|
|
2241
|
+
* @returns {Promise<Object>} List of authorizations
|
|
2242
|
+
*/
|
|
2243
|
+
async listAuthorizations(limit = null, offset = null) {
|
|
2244
|
+
try {
|
|
2245
|
+
const params = { workspaceid: this.workspaceId };
|
|
2246
|
+
if (limit) params.limit = limit;
|
|
2247
|
+
if (offset) params.offset = offset;
|
|
2248
|
+
return await this._makeRequest('GET', 'authorisation/list', params);
|
|
2249
|
+
} catch (error) {
|
|
2250
|
+
console.error(`Error listing authorizations: ${error.message}`);
|
|
2251
|
+
throw error;
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
/**
|
|
2256
|
+
* Update an existing authorization
|
|
2257
|
+
*
|
|
2258
|
+
* @param {Object} fields - Fields to update
|
|
2259
|
+
* @returns {Promise<Object>} Updated authorization data
|
|
2260
|
+
*/
|
|
2261
|
+
async updateAuthorization(fields) {
|
|
2262
|
+
try {
|
|
2263
|
+
return await this._makeRequest('POST', 'authorisation/update', fields);
|
|
2264
|
+
} catch (error) {
|
|
2265
|
+
console.error(`Error updating authorization: ${error.message}`);
|
|
2266
|
+
throw error;
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
/**
|
|
2271
|
+
* Delete an authorization
|
|
2272
|
+
*
|
|
2273
|
+
* @param {string} authId - Authorization ID to delete
|
|
2274
|
+
* @returns {Promise<Object>} Deletion result
|
|
2275
|
+
*/
|
|
2276
|
+
async deleteAuthorization(authId) {
|
|
2277
|
+
try {
|
|
2278
|
+
return await this._makeRequest('DELETE', `authorisation/delete/${authId}`);
|
|
2279
|
+
} catch (error) {
|
|
2280
|
+
console.error(`Error deleting authorization: ${error.message}`);
|
|
2281
|
+
throw error;
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
// Benchmark Management Methods
|
|
2286
|
+
|
|
2287
|
+
/**
|
|
2288
|
+
* Create a new benchmark
|
|
2289
|
+
*
|
|
2290
|
+
* @param {Object} benchmarkData - Benchmark configuration
|
|
2291
|
+
* @returns {Promise<Object>} Created benchmark data
|
|
2292
|
+
*/
|
|
2293
|
+
async createBenchmark(benchmarkData) {
|
|
2294
|
+
try {
|
|
2295
|
+
return await this._makeRequest('POST', 'benchmark/create', benchmarkData);
|
|
2296
|
+
} catch (error) {
|
|
2297
|
+
console.error(`Error creating benchmark: ${error.message}`);
|
|
2298
|
+
throw error;
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
|
|
2302
|
+
/**
|
|
2303
|
+
* Get a specific benchmark by ID
|
|
2304
|
+
*
|
|
2305
|
+
* @param {string} benchmarkId - Benchmark ID to retrieve
|
|
2306
|
+
* @returns {Promise<Object>} Benchmark data
|
|
2307
|
+
*/
|
|
2308
|
+
async getBenchmark(benchmarkId) {
|
|
2309
|
+
try {
|
|
2310
|
+
return await this._makeRequest('GET', `benchmark/get/${benchmarkId}`);
|
|
2311
|
+
} catch (error) {
|
|
2312
|
+
console.error(`Error getting benchmark: ${error.message}`);
|
|
2313
|
+
throw error;
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
|
|
2317
|
+
/**
|
|
2318
|
+
* List all benchmarks in the workspace
|
|
2319
|
+
*
|
|
2320
|
+
* @param {number} limit - Maximum number of benchmarks to return (optional)
|
|
2321
|
+
* @param {number} offset - Number of benchmarks to skip (optional)
|
|
2322
|
+
* @returns {Promise<Object>} List of benchmarks
|
|
2323
|
+
*/
|
|
2324
|
+
async listBenchmarks(limit = null, offset = null) {
|
|
2325
|
+
try {
|
|
2326
|
+
const params = { workspaceid: this.workspaceId };
|
|
2327
|
+
if (limit) params.limit = limit;
|
|
2328
|
+
if (offset) params.offset = offset;
|
|
2329
|
+
return await this._makeRequest('GET', 'benchmark/list', params);
|
|
2330
|
+
} catch (error) {
|
|
2331
|
+
console.error(`Error listing benchmarks: ${error.message}`);
|
|
2332
|
+
throw error;
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
/**
|
|
2337
|
+
* Update an existing benchmark
|
|
2338
|
+
*
|
|
2339
|
+
* @param {Object} fields - Fields to update
|
|
2340
|
+
* @returns {Promise<Object>} Updated benchmark data
|
|
2341
|
+
*/
|
|
2342
|
+
async updateBenchmark(fields) {
|
|
2343
|
+
try {
|
|
2344
|
+
return await this._makeRequest('POST', 'benchmark/update', fields);
|
|
2345
|
+
} catch (error) {
|
|
2346
|
+
console.error(`Error updating benchmark: ${error.message}`);
|
|
2347
|
+
throw error;
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2351
|
+
/**
|
|
2352
|
+
* Delete a benchmark
|
|
2353
|
+
*
|
|
2354
|
+
* @param {string} benchmarkId - Benchmark ID to delete
|
|
2355
|
+
* @returns {Promise<Object>} Deletion result
|
|
2356
|
+
*/
|
|
2357
|
+
async deleteBenchmark(benchmarkId) {
|
|
2358
|
+
try {
|
|
2359
|
+
return await this._makeRequest('DELETE', `benchmark/delete/${benchmarkId}`);
|
|
2360
|
+
} catch (error) {
|
|
2361
|
+
console.error(`Error deleting benchmark: ${error.message}`);
|
|
2362
|
+
throw error;
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
|
|
2366
|
+
// Billing Methods
|
|
2367
|
+
|
|
2368
|
+
/**
|
|
2369
|
+
* Get monthly usage and cost information
|
|
2370
|
+
*
|
|
2371
|
+
* @param {number} month - Month number (1-12)
|
|
2372
|
+
* @param {number} year - Year (4-digit)
|
|
2373
|
+
* @returns {Promise<Object>} Monthly cost data
|
|
2374
|
+
*/
|
|
2375
|
+
async getMonthCosts(month, year) {
|
|
2376
|
+
try {
|
|
2377
|
+
const params = {
|
|
2378
|
+
workspaceId: this.workspaceId,
|
|
2379
|
+
month: month,
|
|
2380
|
+
year: year,
|
|
2381
|
+
};
|
|
2382
|
+
return await this._makeRequest('GET', 'billing/monthCosts', params);
|
|
2383
|
+
} catch (error) {
|
|
2384
|
+
console.error(`Error getting month costs: ${error.message}`);
|
|
2385
|
+
throw error;
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
// Channel Management Methods
|
|
2390
|
+
|
|
2391
|
+
/**
|
|
2392
|
+
* Create a new communication channel
|
|
2393
|
+
*
|
|
2394
|
+
* @param {Object} channelData - Channel configuration
|
|
2395
|
+
* @returns {Promise<Object>} Created channel data
|
|
2396
|
+
*/
|
|
2397
|
+
async createChannel(channelData) {
|
|
2398
|
+
try {
|
|
2399
|
+
return await this._makeRequest('POST', 'channel/create', channelData);
|
|
2400
|
+
} catch (error) {
|
|
2401
|
+
console.error(`Error creating channel: ${error.message}`);
|
|
2402
|
+
throw error;
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
|
|
2406
|
+
/**
|
|
2407
|
+
* Get a specific channel by ID
|
|
2408
|
+
*
|
|
2409
|
+
* @param {string} channelId - Channel ID to retrieve
|
|
2410
|
+
* @returns {Promise<Object>} Channel data
|
|
2411
|
+
*/
|
|
2412
|
+
async getChannel(channelId) {
|
|
2413
|
+
try {
|
|
2414
|
+
return await this._makeRequest('GET', `channel/get/${channelId}`);
|
|
2415
|
+
} catch (error) {
|
|
2416
|
+
console.error(`Error getting channel: ${error.message}`);
|
|
2417
|
+
throw error;
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
/**
|
|
2422
|
+
* List all channels in the workspace
|
|
2423
|
+
*
|
|
2424
|
+
* @param {number} limit - Maximum number of channels to return (optional)
|
|
2425
|
+
* @param {number} offset - Number of channels to skip (optional)
|
|
2426
|
+
* @returns {Promise<Object>} List of channels
|
|
2427
|
+
*/
|
|
2428
|
+
async listChannels(limit = null, offset = null) {
|
|
2429
|
+
try {
|
|
2430
|
+
const params = { workspaceid: this.workspaceId };
|
|
2431
|
+
if (limit) params.limit = limit;
|
|
2432
|
+
if (offset) params.offset = offset;
|
|
2433
|
+
return await this._makeRequest('GET', 'channel/list', params);
|
|
2434
|
+
} catch (error) {
|
|
2435
|
+
console.error(`Error listing channels: ${error.message}`);
|
|
2436
|
+
throw error;
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
|
|
2440
|
+
/**
|
|
2441
|
+
* Update an existing channel
|
|
2442
|
+
*
|
|
2443
|
+
* @param {Object} fields - Fields to update
|
|
2444
|
+
* @returns {Promise<Object>} Updated channel data
|
|
2445
|
+
*/
|
|
2446
|
+
async updateChannel(fields) {
|
|
2447
|
+
try {
|
|
2448
|
+
return await this._makeRequest('POST', 'channel/update', fields);
|
|
2449
|
+
} catch (error) {
|
|
2450
|
+
console.error(`Error updating channel: ${error.message}`);
|
|
2451
|
+
throw error;
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
|
|
2455
|
+
/**
|
|
2456
|
+
* Delete a channel
|
|
2457
|
+
*
|
|
2458
|
+
* @param {string} channelId - Channel ID to delete
|
|
2459
|
+
* @returns {Promise<Object>} Deletion result
|
|
2460
|
+
*/
|
|
2461
|
+
async deleteChannel(channelId) {
|
|
2462
|
+
try {
|
|
2463
|
+
return await this._makeRequest('DELETE', `channel/delete/${channelId}`);
|
|
2464
|
+
} catch (error) {
|
|
2465
|
+
console.error(`Error deleting channel: ${error.message}`);
|
|
2466
|
+
throw error;
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
|
|
2470
|
+
// Connection Management Methods
|
|
2471
|
+
|
|
2472
|
+
/**
|
|
2473
|
+
* Get a specific connection by ID
|
|
2474
|
+
*
|
|
2475
|
+
* @param {string} connectionId - Connection ID to retrieve
|
|
2476
|
+
* @returns {Promise<Object>} Connection data
|
|
2477
|
+
*/
|
|
2478
|
+
async getConnection(connectionId) {
|
|
2479
|
+
try {
|
|
2480
|
+
return await this._makeRequest('GET', `connection/get/${connectionId}`);
|
|
2481
|
+
} catch (error) {
|
|
2482
|
+
console.error(`Error getting connection: ${error.message}`);
|
|
2483
|
+
throw error;
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2486
|
+
|
|
2487
|
+
/**
|
|
2488
|
+
* List all connections in the workspace
|
|
2489
|
+
*
|
|
2490
|
+
* @param {number} limit - Maximum number of connections to return (optional)
|
|
2491
|
+
* @param {number} offset - Number of connections to skip (optional)
|
|
2492
|
+
* @returns {Promise<Object>} List of connections
|
|
2493
|
+
*/
|
|
2494
|
+
async listConnections(limit = null, offset = null) {
|
|
2495
|
+
try {
|
|
2496
|
+
const params = { workspaceid: this.workspaceId };
|
|
2497
|
+
if (limit) params.limit = limit;
|
|
2498
|
+
if (offset) params.offset = offset;
|
|
2499
|
+
return await this._makeRequest('GET', 'connection/list', params);
|
|
2500
|
+
} catch (error) {
|
|
2501
|
+
console.error(`Error listing connections: ${error.message}`);
|
|
2502
|
+
throw error;
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2506
|
+
/**
|
|
2507
|
+
* Delete a connection
|
|
2508
|
+
*
|
|
2509
|
+
* @param {string} connectionId - Connection ID to delete
|
|
2510
|
+
* @returns {Promise<Object>} Deletion result
|
|
2511
|
+
*/
|
|
2512
|
+
async deleteConnection(connectionId) {
|
|
2513
|
+
try {
|
|
2514
|
+
return await this._makeRequest('DELETE', `connection/delete/${connectionId}`);
|
|
2515
|
+
} catch (error) {
|
|
2516
|
+
console.error(`Error deleting connection: ${error.message}`);
|
|
2517
|
+
throw error;
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2521
|
+
// Dictionary Management Methods
|
|
2522
|
+
|
|
2523
|
+
/**
|
|
2524
|
+
* Get a specific dictionary entry by ID
|
|
2525
|
+
*
|
|
2526
|
+
* @param {string} dictionaryId - Dictionary entry ID to retrieve
|
|
2527
|
+
* @returns {Promise<Object>} Dictionary entry data
|
|
2528
|
+
*/
|
|
2529
|
+
async getDictionary(dictionaryId) {
|
|
2530
|
+
try {
|
|
2531
|
+
return await this._makeRequest('GET', `dictionary/get/${dictionaryId}`);
|
|
2532
|
+
} catch (error) {
|
|
2533
|
+
console.error(`Error getting dictionary: ${error.message}`);
|
|
2534
|
+
throw error;
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
/**
|
|
2539
|
+
* List all dictionary entries in the workspace
|
|
2540
|
+
*
|
|
2541
|
+
* @param {number} limit - Maximum number of entries to return (optional)
|
|
2542
|
+
* @param {number} offset - Number of entries to skip (optional)
|
|
2543
|
+
* @returns {Promise<Object>} List of dictionary entries
|
|
2544
|
+
*/
|
|
2545
|
+
async listDictionaries(limit = null, offset = null) {
|
|
2546
|
+
try {
|
|
2547
|
+
const params = { workspaceid: this.workspaceId };
|
|
2548
|
+
if (limit) params.limit = limit;
|
|
2549
|
+
if (offset) params.offset = offset;
|
|
2550
|
+
return await this._makeRequest('GET', 'dictionary/list', params);
|
|
2551
|
+
} catch (error) {
|
|
2552
|
+
console.error(`Error listing dictionaries: ${error.message}`);
|
|
2553
|
+
throw error;
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2557
|
+
// Embedding Management Methods
|
|
2558
|
+
|
|
2559
|
+
/**
|
|
2560
|
+
* Get a specific embedding by ID
|
|
2561
|
+
*
|
|
2562
|
+
* @param {string} embeddingId - Embedding ID to retrieve
|
|
2563
|
+
* @returns {Promise<Object>} Embedding data
|
|
2564
|
+
*/
|
|
2565
|
+
async getEmbedding(embeddingId) {
|
|
2566
|
+
try {
|
|
2567
|
+
return await this._makeRequest('GET', `embedding/get/${embeddingId}`);
|
|
2568
|
+
} catch (error) {
|
|
2569
|
+
console.error(`Error getting embedding: ${error.message}`);
|
|
2570
|
+
throw error;
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
|
|
2574
|
+
// Settings Management Methods
|
|
2575
|
+
|
|
2576
|
+
/**
|
|
2577
|
+
* Get charting settings for the workspace
|
|
2578
|
+
*
|
|
2579
|
+
* @param {string} settingsId - Settings ID to retrieve
|
|
2580
|
+
* @returns {Promise<Object>} Charting settings data
|
|
2581
|
+
*/
|
|
2582
|
+
async getChartingSettings(settingsId) {
|
|
2583
|
+
try {
|
|
2584
|
+
return await this._makeRequest('GET', `charting_settings/get/${settingsId}`);
|
|
2585
|
+
} catch (error) {
|
|
2586
|
+
console.error(`Error getting charting settings: ${error.message}`);
|
|
2587
|
+
throw error;
|
|
2588
|
+
}
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2591
|
+
/**
|
|
2592
|
+
* Update charting settings for the workspace
|
|
2593
|
+
*
|
|
2594
|
+
* @param {Object} fields - Fields to update
|
|
2595
|
+
* @returns {Promise<Object>} Updated charting settings data
|
|
2596
|
+
*/
|
|
2597
|
+
async updateChartingSettings(fields) {
|
|
2598
|
+
try {
|
|
2599
|
+
return await this._makeRequest('POST', 'charting_settings/update', fields);
|
|
2600
|
+
} catch (error) {
|
|
2601
|
+
console.error(`Error updating charting settings: ${error.message}`);
|
|
2602
|
+
throw error;
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
/**
|
|
2607
|
+
* Get embeddings settings for the workspace
|
|
2608
|
+
*
|
|
2609
|
+
* @param {string} settingsId - Settings ID to retrieve
|
|
2610
|
+
* @returns {Promise<Object>} Embeddings settings data
|
|
2611
|
+
*/
|
|
2612
|
+
async getEmbeddingsSettings(settingsId) {
|
|
2613
|
+
try {
|
|
2614
|
+
return await this._makeRequest('GET', `embeddings_settings/get/${settingsId}`);
|
|
2615
|
+
} catch (error) {
|
|
2616
|
+
console.error(`Error getting embeddings settings: ${error.message}`);
|
|
2617
|
+
throw error;
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
|
|
2621
|
+
/**
|
|
2622
|
+
* Update embeddings settings for the workspace
|
|
2623
|
+
*
|
|
2624
|
+
* @param {Object} fields - Fields to update
|
|
2625
|
+
* @returns {Promise<Object>} Updated embeddings settings data
|
|
2626
|
+
*/
|
|
2627
|
+
async updateEmbeddingsSettings(fields) {
|
|
2628
|
+
try {
|
|
2629
|
+
return await this._makeRequest('POST', 'embeddings_settings/update', fields);
|
|
2630
|
+
} catch (error) {
|
|
2631
|
+
console.error(`Error updating embeddings settings: ${error.message}`);
|
|
2632
|
+
throw error;
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
|
|
2636
|
+
// Stream Management Methods
|
|
2637
|
+
|
|
2638
|
+
/**
|
|
2639
|
+
* Get a specific stream by ID
|
|
2640
|
+
*
|
|
2641
|
+
* @param {string} streamId - Stream ID to retrieve
|
|
2642
|
+
* @returns {Promise<Object>} Stream data
|
|
2643
|
+
*/
|
|
2644
|
+
async getStream(streamId) {
|
|
2645
|
+
try {
|
|
2646
|
+
return await this._makeRequest('GET', `stream/get/${streamId}`);
|
|
2647
|
+
} catch (error) {
|
|
2648
|
+
console.error(`Error getting stream: ${error.message}`);
|
|
2649
|
+
throw error;
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
|
|
2653
|
+
/**
|
|
2654
|
+
* List all streams in the workspace
|
|
2655
|
+
*
|
|
2656
|
+
* @param {number} limit - Maximum number of streams to return (optional)
|
|
2657
|
+
* @param {number} offset - Number of streams to skip (optional)
|
|
2658
|
+
* @returns {Promise<Object>} List of streams
|
|
2659
|
+
*/
|
|
2660
|
+
async listStreams(limit = null, offset = null) {
|
|
2661
|
+
try {
|
|
2662
|
+
const params = { workspaceid: this.workspaceId };
|
|
2663
|
+
if (limit) params.limit = limit;
|
|
2664
|
+
if (offset) params.offset = offset;
|
|
2665
|
+
return await this._makeRequest('GET', 'stream/list', params);
|
|
2666
|
+
} catch (error) {
|
|
2667
|
+
console.error(`Error listing streams: ${error.message}`);
|
|
2668
|
+
throw error;
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2061
2671
|
}
|
|
2062
2672
|
|
|
2063
2673
|
module.exports = ToothFairyAPI;
|