Skip to content

Commit ae6c5f3

Browse files
tokenizer added
1 parent 96c6e48 commit ae6c5f3

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codebolt/codeboltjs",
3-
"version": "1.1.22",
3+
"version": "1.1.23",
44
"description": "",
55
"keywords": [],
66
"author": "",

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import cbstate from './modules/state';
1919
import task from './modules/task';
2020
import vectorDB from './modules/vectordb';
2121
import debug from './modules/debug'
22+
import tokenizer from './modules/tokenizer'
2223
import WebSocket from 'ws';
2324

2425

@@ -95,6 +96,7 @@ class Codebolt {
9596
taskplaner=task;
9697
vectordb=vectorDB;
9798
debug=debug;
99+
tokenizer=tokenizer;
98100
}
99101

100102
export default new Codebolt();

src/modules/tokenizer.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import cbws from './websocket';
2+
3+
/**
4+
* Tokenizer module for handling token-related operations.
5+
*/
6+
const tokenizer = {
7+
8+
/**
9+
* Adds a token asynchronously.
10+
* @param {string} key - The key of the token to add.
11+
* @returns {Promise<any>} A promise that resolves with the response.
12+
*/
13+
addToken: async (key: string): Promise<any> => {
14+
return new Promise((resolve, reject) => {
15+
cbws.getWebsocket.send(JSON.stringify({
16+
"type":"tokenizerEvent",
17+
"action": "addToken",
18+
"message": {
19+
item: key
20+
},
21+
}));
22+
cbws.getWebsocket.on('message', (data: string) => {
23+
const response = JSON.parse(data);
24+
if (response.type === "addTokenResponse") {
25+
resolve(response);
26+
}
27+
});
28+
});
29+
}
30+
}
31+
32+
export default tokenizer

0 commit comments

Comments
 (0)