cheshirecat-typescript-client 1.1.2 → 1.1.4
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/dist/clients/wsclient.js +4 -9
- package/dist/clients/wsclient.js.map +1 -1
- package/dist/endpoints/rabbitHole.d.ts +99 -25
- package/dist/endpoints/rabbitHole.js +152 -69
- package/dist/endpoints/rabbitHole.js.map +1 -1
- package/dist/utils/environment.d.ts +9 -0
- package/dist/utils/environment.js +17 -0
- package/dist/utils/environment.js.map +1 -0
- package/dist/utils/file-reader.d.ts +29 -0
- package/dist/utils/file-reader.js +107 -0
- package/dist/utils/file-reader.js.map +1 -0
- package/package.json +1 -1
package/dist/clients/wsclient.js
CHANGED
|
@@ -91,7 +91,7 @@ class WebSocketClient extends events_1.EventEmitter {
|
|
|
91
91
|
}
|
|
92
92
|
this.pingInterval = setInterval(() => {
|
|
93
93
|
if (this.ws.readyState === isomorphic_ws_1.default.OPEN) {
|
|
94
|
-
this.ws.send(JSON.stringify({ text:
|
|
94
|
+
this.ws.send(JSON.stringify({ text: "ping" }));
|
|
95
95
|
this.pongTimeout = setTimeout(() => {
|
|
96
96
|
this.handleConnectionLost();
|
|
97
97
|
}, this.pongTimeoutMs);
|
|
@@ -132,16 +132,11 @@ class WebSocketClient extends events_1.EventEmitter {
|
|
|
132
132
|
return;
|
|
133
133
|
const data = JSON.parse(event.data);
|
|
134
134
|
const message = data;
|
|
135
|
-
if ("text" in data &&
|
|
136
|
-
this.ws.send(JSON.stringify({
|
|
137
|
-
text: {
|
|
138
|
-
type: "pong",
|
|
139
|
-
timestamp: data.timestamp
|
|
140
|
-
}
|
|
141
|
-
}));
|
|
135
|
+
if ("text" in data && data.text === "ping") {
|
|
136
|
+
this.ws.send(JSON.stringify({ text: "pong" }));
|
|
142
137
|
return;
|
|
143
138
|
}
|
|
144
|
-
if ("text" in data &&
|
|
139
|
+
if ("text" in data && data.text === "pong") {
|
|
145
140
|
if (this.pongTimeout) {
|
|
146
141
|
clearTimeout(this.pongTimeout);
|
|
147
142
|
this.pongTimeout = undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsclient.js","sourceRoot":"","sources":["../../src/clients/wsclient.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAsC;AACtC,+BAA0B;AAC1B,mCAAoC;AAGpC,MAAa,QAAQ;IACP,IAAI,CAAS;IACb,IAAI,GAAmB,IAAI,CAAC;IAC5B,MAAM,GAAmB,IAAI,CAAC;IAC9B,KAAK,GAAmB,IAAI,CAAC;IAC7B,KAAK,CAAU;IACf,QAAQ,CAAmB;IAErC,YACI,IAAY,EACZ,IAAoB,EACpB,MAAsB,EACtB,QAAiB,KAAK;QAEtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAEM,QAAQ,CAAC,KAAa;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,SAAS,CAAC,OAAuB,EAAE,MAAsB;QAC5D,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC7D,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACjB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACzD,CAAC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAEM,QAAQ,CAAC,OAAuB,EAAE,MAAsB;QAC3D,MAAM,KAAK,GAA2B,EAAE,CAAC;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U,CAAC,GAAG,EAAE;gBACZ,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;gBACpC,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC9B,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACtC,CAAC;IACL,CAAC;IAEM,IAAI,CAAC,IAAyB;QACjC,IAAI,IAAI,CAAC,EAAE,CAAC,UAAU,KAAK,uBAAS,CAAC,IAAI,EAAE,CAAC;YACxC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;aAAM,CAAC;YACJ,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC7C,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,IAAa,EAAE,MAAe;QACvC,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACrC,CAAC;QACD,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAChC,CAAC;CACJ;AA7JD,0CA6JC"}
|
|
@@ -1,38 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file RabbitHoleEndpoint.ts
|
|
3
|
+
*
|
|
4
|
+
* Isomorphic implementation of the RabbitHoleEndpoint that works in both
|
|
5
|
+
* Node.js (server) and browser (client) environments. This class handles
|
|
6
|
+
* file uploads to the RabbitHole API with environment-specific file handling.
|
|
7
|
+
*/
|
|
1
8
|
import { AbstractEndpoint } from "./abstract";
|
|
9
|
+
import { FileSource } from "../utils/file-reader";
|
|
2
10
|
import { AllowedMimeTypesOutput } from "../models/api/rabbitholes";
|
|
3
11
|
export declare class RabbitHoleEndpoint extends AbstractEndpoint {
|
|
4
12
|
protected prefix: string;
|
|
13
|
+
private throwError;
|
|
14
|
+
private appendFileToForm;
|
|
15
|
+
private appendQueryDataToForm;
|
|
16
|
+
private submitForm;
|
|
5
17
|
/**
|
|
6
|
-
*
|
|
7
|
-
* the RAG system. The file is then processed by the RAG system and the results are stored in the RAG database.
|
|
8
|
-
* The process is asynchronous and the results are returned in a batch.
|
|
9
|
-
* The CheshireCat processes the injection in background and the client will be informed at the end of the process.
|
|
18
|
+
* Posts a file to the RabbitHole API for ingestion into the RAG system.
|
|
10
19
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* @param chunkOverlap The size of the overlap between chunks. If not provided, the default overlap size will be used.
|
|
15
|
-
* @param agentId The ID of the agent to be used for the upload. If not provided, the default agent will be used.
|
|
16
|
-
* @param metadata Additional metadata to be associated with the file.
|
|
20
|
+
* This method works in both Node.js and browser environments:
|
|
21
|
+
* - In Node.js: Pass a file path string as `fileSource`
|
|
22
|
+
* - In browser: Pass a File object as `fileSource`
|
|
17
23
|
*
|
|
18
|
-
*
|
|
24
|
+
* The file is uploaded to the RabbitHole server and processed asynchronously.
|
|
25
|
+
* The CheshireCat processes the injection in background, and the client will be informed when processing completes.
|
|
26
|
+
*
|
|
27
|
+
* @param fileSource The source of the file to upload:
|
|
28
|
+
* - In Node.js: A string path to the file
|
|
29
|
+
* - In browser: A File object
|
|
30
|
+
* @param fileName Optional custom name for the file. If not provided:
|
|
31
|
+
* - In Node.js: The basename of the file path is used
|
|
32
|
+
* - In browser: The name property of the File object is used
|
|
33
|
+
* @param chunkSize Optional size of chunks for RAG processing
|
|
34
|
+
* @param chunkOverlap Optional overlap between chunks
|
|
35
|
+
* @param agentId Optional ID of the agent to associate with this upload
|
|
36
|
+
* @param metadata Optional additional metadata to associate with the file
|
|
37
|
+
*
|
|
38
|
+
* @returns Promise resolving to the API response data
|
|
39
|
+
*
|
|
40
|
+
* @example Browser usage:
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // In a Vue.js or React component
|
|
43
|
+
* const fileInput = document.getElementById('fileInput');
|
|
44
|
+
* const file = fileInput.files[0];
|
|
45
|
+
* const response = await rabbitHoleEndpoint.postFile(file);
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example Node.js usage:
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // In a Node.js application
|
|
51
|
+
* const response = await rabbitHoleEndpoint.postFile('/path/to/document.pdf');
|
|
52
|
+
* ```
|
|
19
53
|
*/
|
|
20
|
-
postFile(
|
|
54
|
+
postFile(fileSource: FileSource, fileName?: string | null, chunkSize?: number | null, chunkOverlap?: number | null, agentId?: string | null, metadata?: Record<string, any> | null): Promise<any>;
|
|
21
55
|
/**
|
|
22
56
|
* This method posts a number of files to the RabbitHole API. The files are uploaded to the RabbitHole server and
|
|
23
|
-
* ingested into the RAG system.
|
|
24
|
-
* RAG database. The files are processed in a batch. The process is asynchronous.
|
|
25
|
-
* The CheshireCat processes the injection in background and the client will be informed at the end of the process.
|
|
57
|
+
* ingested into the RAG system.
|
|
26
58
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* @param agentId The ID of the agent to be used for the upload. If not provided, the default agent will be used.
|
|
31
|
-
* @param metadata Additional metadata to be associated with the files.
|
|
59
|
+
* This method works in both Node.js and browser environments:
|
|
60
|
+
* - In Node.js: Pass an array of file path strings as `fileSource`
|
|
61
|
+
* - In browser: Pass an array of File objects as `fileSource`
|
|
32
62
|
*
|
|
33
|
-
*
|
|
63
|
+
* The files are then processed by the RAG system, and the results are stored in the RAG database. The files are
|
|
64
|
+
* processed in a batch. The process is asynchronous.
|
|
65
|
+
* The CheshireCat processes the injection in the background, and the client will be informed at the end of the
|
|
66
|
+
* process.
|
|
67
|
+
*
|
|
68
|
+
* @param fileSources The sources of the file to upload:
|
|
69
|
+
* - In Node.js: An array of strings path to the file
|
|
70
|
+
* - In browser: An array of File objects
|
|
71
|
+
* @param chunkSize Optional size of chunks for RAG processing
|
|
72
|
+
* @param chunkOverlap Optional overlap between chunks
|
|
73
|
+
* @param agentId Optional ID of the agent to associate with this upload
|
|
74
|
+
* @param metadata Optional additional metadata to associate with the file
|
|
75
|
+
*
|
|
76
|
+
* @returns Promise resolving to the API response data
|
|
77
|
+
*
|
|
78
|
+
* @example Browser usage:
|
|
79
|
+
* ```typescript
|
|
80
|
+
* // In a Vue.js or React component
|
|
81
|
+
* const fileInputs = document.getElementById('fileInput');
|
|
82
|
+
* const files = fileInputs.files;
|
|
83
|
+
* const response = await rabbitHoleEndpoint.postFiles(files);
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @example Node.js usage:
|
|
87
|
+
* ```typescript
|
|
88
|
+
* // In a Node.js application
|
|
89
|
+
* const response = await rabbitHoleEndpoint.postFiles(['/path/to/first/document.pdf', '/path/to/second/document.pdf']);
|
|
90
|
+
* ```
|
|
34
91
|
*/
|
|
35
|
-
postFiles(
|
|
92
|
+
postFiles(fileSources: FileSource[], chunkSize?: number | null, chunkOverlap?: number | null, agentId?: string | null, metadata?: Record<string, any> | null): Promise<any>;
|
|
36
93
|
/**
|
|
37
94
|
* This method posts a web URL to the RabbitHole API. The web URL is ingested into the RAG system. The web URL is
|
|
38
95
|
* processed by the RAG system by Web scraping and the results are stored in the RAG database. The process is
|
|
@@ -52,15 +109,32 @@ export declare class RabbitHoleEndpoint extends AbstractEndpoint {
|
|
|
52
109
|
* This method posts a memory point, either for the agent identified by the agentId parameter (for multi-agent
|
|
53
110
|
* installations) or for the default agent (for single-agent installations). The memory point is ingested into the
|
|
54
111
|
* RAG system. The process is asynchronous. The provided file must be in JSON format.
|
|
55
|
-
* The CheshireCat processes the injection in background and the client will be informed at the end of the
|
|
112
|
+
* The CheshireCat processes the injection in the background, and the client will be informed at the end of the
|
|
113
|
+
* process.
|
|
56
114
|
*
|
|
57
|
-
* @param
|
|
115
|
+
* @param fileSource The source of the file to upload:
|
|
116
|
+
* - In Node.js: A string path to the file
|
|
117
|
+
* - In browser: A File object
|
|
58
118
|
* @param fileName The name of the file to be uploaded. If not provided, the name of the file will be used.
|
|
59
119
|
* @param agentId The ID of the agent to be used for the upload. If not provided, the default agent will be used.
|
|
60
120
|
*
|
|
61
121
|
* @returns The response from the RabbitHole API.
|
|
122
|
+
*
|
|
123
|
+
* @example Browser usage:
|
|
124
|
+
* ```typescript
|
|
125
|
+
* // In a Vue.js or React component
|
|
126
|
+
* const fileInput = document.getElementById('fileInput');
|
|
127
|
+
* const file = fileInput.files[0];
|
|
128
|
+
* const response = await rabbitHoleEndpoint.postMemory(file);
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @example Node.js usage:
|
|
132
|
+
* ```typescript
|
|
133
|
+
* // In a Node.js application
|
|
134
|
+
* const response = await rabbitHoleEndpoint.postMemory('/path/to/document.json');
|
|
135
|
+
* ```
|
|
62
136
|
*/
|
|
63
|
-
postMemory(
|
|
137
|
+
postMemory(fileSource: FileSource, fileName?: string | null, agentId?: string | null): Promise<any>;
|
|
64
138
|
/**
|
|
65
139
|
* This method retrieves the allowed MIME types for the RabbitHole API. The allowed MIME types are the MIME types
|
|
66
140
|
* that are allowed to be uploaded to the RabbitHole API. The allowed MIME types are returned in a list.
|
|
@@ -37,36 +37,42 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.RabbitHoleEndpoint = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
/**
|
|
41
|
+
* @file RabbitHoleEndpoint.ts
|
|
42
|
+
*
|
|
43
|
+
* Isomorphic implementation of the RabbitHoleEndpoint that works in both
|
|
44
|
+
* Node.js (server) and browser (client) environments. This class handles
|
|
45
|
+
* file uploads to the RabbitHole API with environment-specific file handling.
|
|
46
|
+
*/
|
|
47
|
+
const abstract_1 = require("./abstract");
|
|
42
48
|
const form_data_1 = __importDefault(require("form-data"));
|
|
43
49
|
const mime = __importStar(require("mime-types"));
|
|
44
|
-
const
|
|
50
|
+
const environment_1 = require("../utils/environment");
|
|
51
|
+
const file_reader_1 = require("../utils/file-reader");
|
|
45
52
|
class RabbitHoleEndpoint extends abstract_1.AbstractEndpoint {
|
|
46
53
|
prefix = "/rabbithole";
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const finalFileName = fileName || path.basename(filePath);
|
|
65
|
-
const fileBuffer = fs.readFileSync(filePath);
|
|
66
|
-
form.append("file", fileBuffer, {
|
|
54
|
+
throwError(fileSource, error) {
|
|
55
|
+
// Provide more helpful error messages based on environment
|
|
56
|
+
if (!(0, environment_1.isNodeEnvironment)() && typeof fileSource === "string") {
|
|
57
|
+
throw new Error("In browser environments, fileSource must be a File object, not a file path string.");
|
|
58
|
+
}
|
|
59
|
+
else if ((0, environment_1.isNodeEnvironment)() && typeof fileSource !== 'string') {
|
|
60
|
+
throw new Error("In Node.js environments, fileSource must be a file path string.");
|
|
61
|
+
}
|
|
62
|
+
// Re-throw the original error
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
async appendFileToForm(form, fileSource, formKey, fileName) {
|
|
66
|
+
// Read file content in an environment-appropriate way
|
|
67
|
+
const fileBuffer = await (0, file_reader_1.readFile)(fileSource);
|
|
68
|
+
// Get appropriate filename
|
|
69
|
+
const finalFileName = fileName || await (0, file_reader_1.getFileName)(fileSource);
|
|
70
|
+
form.append(formKey, fileBuffer, {
|
|
67
71
|
filename: finalFileName,
|
|
68
72
|
contentType: mime.contentType(finalFileName) || "application/octet-stream"
|
|
69
73
|
});
|
|
74
|
+
}
|
|
75
|
+
appendQueryDataToForm(form, chunkSize, chunkOverlap, metadata) {
|
|
70
76
|
if (chunkSize) {
|
|
71
77
|
form.append("chunk_size", chunkSize.toString());
|
|
72
78
|
}
|
|
@@ -76,49 +82,115 @@ class RabbitHoleEndpoint extends abstract_1.AbstractEndpoint {
|
|
|
76
82
|
if (metadata) {
|
|
77
83
|
form.append("metadata", JSON.stringify(metadata));
|
|
78
84
|
}
|
|
79
|
-
|
|
85
|
+
}
|
|
86
|
+
async submitForm(form, url, agentId) {
|
|
87
|
+
const response = await this.getHttpClient(agentId).post(url, form, {
|
|
80
88
|
headers: {
|
|
81
89
|
...form.getHeaders(),
|
|
82
|
-
|
|
83
|
-
}
|
|
90
|
+
"Content-Type": `multipart/form-data; boundary=${form.getBoundary()}`
|
|
91
|
+
}
|
|
84
92
|
});
|
|
85
93
|
return response.data;
|
|
86
94
|
}
|
|
87
95
|
/**
|
|
88
|
-
*
|
|
89
|
-
* ingested into the RAG system. The files are then processed by the RAG system and the results are stored in the
|
|
90
|
-
* RAG database. The files are processed in a batch. The process is asynchronous.
|
|
91
|
-
* The CheshireCat processes the injection in background and the client will be informed at the end of the process.
|
|
96
|
+
* Posts a file to the RabbitHole API for ingestion into the RAG system.
|
|
92
97
|
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* @param agentId The ID of the agent to be used for the upload. If not provided, the default agent will be used.
|
|
97
|
-
* @param metadata Additional metadata to be associated with the files.
|
|
98
|
+
* This method works in both Node.js and browser environments:
|
|
99
|
+
* - In Node.js: Pass a file path string as `fileSource`
|
|
100
|
+
* - In browser: Pass a File object as `fileSource`
|
|
98
101
|
*
|
|
99
|
-
*
|
|
102
|
+
* The file is uploaded to the RabbitHole server and processed asynchronously.
|
|
103
|
+
* The CheshireCat processes the injection in background, and the client will be informed when processing completes.
|
|
104
|
+
*
|
|
105
|
+
* @param fileSource The source of the file to upload:
|
|
106
|
+
* - In Node.js: A string path to the file
|
|
107
|
+
* - In browser: A File object
|
|
108
|
+
* @param fileName Optional custom name for the file. If not provided:
|
|
109
|
+
* - In Node.js: The basename of the file path is used
|
|
110
|
+
* - In browser: The name property of the File object is used
|
|
111
|
+
* @param chunkSize Optional size of chunks for RAG processing
|
|
112
|
+
* @param chunkOverlap Optional overlap between chunks
|
|
113
|
+
* @param agentId Optional ID of the agent to associate with this upload
|
|
114
|
+
* @param metadata Optional additional metadata to associate with the file
|
|
115
|
+
*
|
|
116
|
+
* @returns Promise resolving to the API response data
|
|
117
|
+
*
|
|
118
|
+
* @example Browser usage:
|
|
119
|
+
* ```typescript
|
|
120
|
+
* // In a Vue.js or React component
|
|
121
|
+
* const fileInput = document.getElementById('fileInput');
|
|
122
|
+
* const file = fileInput.files[0];
|
|
123
|
+
* const response = await rabbitHoleEndpoint.postFile(file);
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @example Node.js usage:
|
|
127
|
+
* ```typescript
|
|
128
|
+
* // In a Node.js application
|
|
129
|
+
* const response = await rabbitHoleEndpoint.postFile('/path/to/document.pdf');
|
|
130
|
+
* ```
|
|
100
131
|
*/
|
|
101
|
-
async
|
|
132
|
+
async postFile(fileSource, fileName, chunkSize, chunkOverlap, agentId, metadata) {
|
|
102
133
|
const form = new form_data_1.default();
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
contentType: mime.contentType(fileName) || "application/octet-stream"
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
if (chunkSize) {
|
|
112
|
-
form.append("chunk_size", chunkSize.toString());
|
|
134
|
+
try {
|
|
135
|
+
await this.appendFileToForm(form, fileSource, "file", fileName);
|
|
136
|
+
this.appendQueryDataToForm(form, chunkSize, chunkOverlap, metadata);
|
|
137
|
+
// Send the request
|
|
138
|
+
return await this.submitForm(form, this.prefix, agentId);
|
|
113
139
|
}
|
|
114
|
-
|
|
115
|
-
|
|
140
|
+
catch (error) {
|
|
141
|
+
this.throwError(fileSource, error);
|
|
116
142
|
}
|
|
117
|
-
|
|
118
|
-
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* This method posts a number of files to the RabbitHole API. The files are uploaded to the RabbitHole server and
|
|
146
|
+
* ingested into the RAG system.
|
|
147
|
+
*
|
|
148
|
+
* This method works in both Node.js and browser environments:
|
|
149
|
+
* - In Node.js: Pass an array of file path strings as `fileSource`
|
|
150
|
+
* - In browser: Pass an array of File objects as `fileSource`
|
|
151
|
+
*
|
|
152
|
+
* The files are then processed by the RAG system, and the results are stored in the RAG database. The files are
|
|
153
|
+
* processed in a batch. The process is asynchronous.
|
|
154
|
+
* The CheshireCat processes the injection in the background, and the client will be informed at the end of the
|
|
155
|
+
* process.
|
|
156
|
+
*
|
|
157
|
+
* @param fileSources The sources of the file to upload:
|
|
158
|
+
* - In Node.js: An array of strings path to the file
|
|
159
|
+
* - In browser: An array of File objects
|
|
160
|
+
* @param chunkSize Optional size of chunks for RAG processing
|
|
161
|
+
* @param chunkOverlap Optional overlap between chunks
|
|
162
|
+
* @param agentId Optional ID of the agent to associate with this upload
|
|
163
|
+
* @param metadata Optional additional metadata to associate with the file
|
|
164
|
+
*
|
|
165
|
+
* @returns Promise resolving to the API response data
|
|
166
|
+
*
|
|
167
|
+
* @example Browser usage:
|
|
168
|
+
* ```typescript
|
|
169
|
+
* // In a Vue.js or React component
|
|
170
|
+
* const fileInputs = document.getElementById('fileInput');
|
|
171
|
+
* const files = fileInputs.files;
|
|
172
|
+
* const response = await rabbitHoleEndpoint.postFiles(files);
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* @example Node.js usage:
|
|
176
|
+
* ```typescript
|
|
177
|
+
* // In a Node.js application
|
|
178
|
+
* const response = await rabbitHoleEndpoint.postFiles(['/path/to/first/document.pdf', '/path/to/second/document.pdf']);
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
async postFiles(fileSources, chunkSize, chunkOverlap, agentId, metadata) {
|
|
182
|
+
const form = new form_data_1.default();
|
|
183
|
+
try {
|
|
184
|
+
await Promise.all(fileSources.map(async (fileSource) => {
|
|
185
|
+
await this.appendFileToForm(form, fileSource, "files");
|
|
186
|
+
}));
|
|
187
|
+
// Append additional query parameters
|
|
188
|
+
this.appendQueryDataToForm(form, chunkSize, chunkOverlap, metadata);
|
|
189
|
+
return await this.submitForm(form, this.formatUrl("/batch"), agentId);
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
this.throwError(fileSources[0], error);
|
|
119
193
|
}
|
|
120
|
-
const response = await this.getHttpClient(agentId).post(this.formatUrl("/batch"), form);
|
|
121
|
-
return response.data;
|
|
122
194
|
}
|
|
123
195
|
/**
|
|
124
196
|
* This method posts a web URL to the RabbitHole API. The web URL is ingested into the RAG system. The web URL is
|
|
@@ -152,29 +224,40 @@ class RabbitHoleEndpoint extends abstract_1.AbstractEndpoint {
|
|
|
152
224
|
* This method posts a memory point, either for the agent identified by the agentId parameter (for multi-agent
|
|
153
225
|
* installations) or for the default agent (for single-agent installations). The memory point is ingested into the
|
|
154
226
|
* RAG system. The process is asynchronous. The provided file must be in JSON format.
|
|
155
|
-
* The CheshireCat processes the injection in background and the client will be informed at the end of the
|
|
227
|
+
* The CheshireCat processes the injection in the background, and the client will be informed at the end of the
|
|
228
|
+
* process.
|
|
156
229
|
*
|
|
157
|
-
* @param
|
|
230
|
+
* @param fileSource The source of the file to upload:
|
|
231
|
+
* - In Node.js: A string path to the file
|
|
232
|
+
* - In browser: A File object
|
|
158
233
|
* @param fileName The name of the file to be uploaded. If not provided, the name of the file will be used.
|
|
159
234
|
* @param agentId The ID of the agent to be used for the upload. If not provided, the default agent will be used.
|
|
160
235
|
*
|
|
161
236
|
* @returns The response from the RabbitHole API.
|
|
237
|
+
*
|
|
238
|
+
* @example Browser usage:
|
|
239
|
+
* ```typescript
|
|
240
|
+
* // In a Vue.js or React component
|
|
241
|
+
* const fileInput = document.getElementById('fileInput');
|
|
242
|
+
* const file = fileInput.files[0];
|
|
243
|
+
* const response = await rabbitHoleEndpoint.postMemory(file);
|
|
244
|
+
* ```
|
|
245
|
+
*
|
|
246
|
+
* @example Node.js usage:
|
|
247
|
+
* ```typescript
|
|
248
|
+
* // In a Node.js application
|
|
249
|
+
* const response = await rabbitHoleEndpoint.postMemory('/path/to/document.json');
|
|
250
|
+
* ```
|
|
162
251
|
*/
|
|
163
|
-
async postMemory(
|
|
252
|
+
async postMemory(fileSource, fileName, agentId) {
|
|
164
253
|
const form = new form_data_1.default();
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
headers: {
|
|
173
|
-
...form.getHeaders(),
|
|
174
|
-
'Content-Type': `multipart/form-data; boundary=${form.getBoundary()}`
|
|
175
|
-
},
|
|
176
|
-
});
|
|
177
|
-
return response.data;
|
|
254
|
+
try {
|
|
255
|
+
await this.appendFileToForm(form, fileSource, "file", fileName);
|
|
256
|
+
return this.submitForm(form, this.formatUrl("/memory"), agentId);
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
this.throwError(fileSource, error);
|
|
260
|
+
}
|
|
178
261
|
}
|
|
179
262
|
/**
|
|
180
263
|
* This method retrieves the allowed MIME types for the RabbitHole API. The allowed MIME types are the MIME types
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rabbitHole.js","sourceRoot":"","sources":["../../src/endpoints/rabbitHole.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"rabbitHole.js","sourceRoot":"","sources":["../../src/endpoints/rabbitHole.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;GAMG;AACH,yCAA4C;AAC5C,0DAAiC;AACjC,iDAAmC;AACnC,sDAAwD;AACxD,sDAAuE;AAGvE,MAAa,kBAAmB,SAAQ,2BAAgB;IAC1C,MAAM,GAAG,aAAa,CAAC;IAEzB,UAAU,CAAC,UAAsB,EAAE,KAAU;QACjD,2DAA2D;QAC3D,IAAI,CAAC,IAAA,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AsB,EACtB,QAAwB,EACxB,OAAuB;QAEvB,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;QAE5B,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;YAEhE,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC;QACrE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;QACtC,CAAC;IACL,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,mBAAmB,CAAC,OAAuB;QAC7C,OAAO,IAAI,CAAC,GAAG,CAAyB,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC,CAAC;IAC3F,CAAC;CACJ;AA9QD,gDA8QC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file environment.ts
|
|
4
|
+
*
|
|
5
|
+
* Utility functions for detecting the current JavaScript environment.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.isNodeEnvironment = isNodeEnvironment;
|
|
9
|
+
/**
|
|
10
|
+
* Determines if the code is running in a Node.js environment.
|
|
11
|
+
*/
|
|
12
|
+
function isNodeEnvironment() {
|
|
13
|
+
return typeof process !== 'undefined' &&
|
|
14
|
+
process.versions != null &&
|
|
15
|
+
process.versions.node != null;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAKH,8CAIC;AAPD;;GAEG;AACH,SAAgB,iBAAiB;IAC7B,OAAO,OAAO,OAAO,KAAK,WAAW;QACjC,OAAO,CAAC,QAAQ,IAAI,IAAI;QACxB,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file file-reader.ts
|
|
3
|
+
*
|
|
4
|
+
* Isomorphic (Node.js and browser) utilities for file operations.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Type representing the source of a file, which differs by environment:
|
|
8
|
+
* - In Node.js: A string path to the file
|
|
9
|
+
* - In browser: A File object
|
|
10
|
+
*/
|
|
11
|
+
export type FileSource = string | File | Blob;
|
|
12
|
+
/**
|
|
13
|
+
* Reads file content in an environment-appropriate way.
|
|
14
|
+
*
|
|
15
|
+
* @param fileSource The source of the file:
|
|
16
|
+
* - In Node.js: A string path to the file
|
|
17
|
+
* - In browser: A File or Blob object
|
|
18
|
+
* @returns Promise resolving to the file buffer/blob
|
|
19
|
+
* @throws Error if file reading fails or if using an inappropriate
|
|
20
|
+
* file source type for the current environment
|
|
21
|
+
*/
|
|
22
|
+
export declare function readFile(fileSource: FileSource): Promise<Buffer | Blob>;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the appropriate filename from the file source based on the environment.
|
|
25
|
+
*
|
|
26
|
+
* @param fileSource The source of the file
|
|
27
|
+
* @returns Promise resolving to the filename
|
|
28
|
+
*/
|
|
29
|
+
export declare function getFileName(fileSource: FileSource): Promise<string>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file file-reader.ts
|
|
4
|
+
*
|
|
5
|
+
* Isomorphic (Node.js and browser) utilities for file operations.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.readFile = readFile;
|
|
42
|
+
exports.getFileName = getFileName;
|
|
43
|
+
const environment_1 = require("./environment");
|
|
44
|
+
/**
|
|
45
|
+
* Reads file content in an environment-appropriate way.
|
|
46
|
+
*
|
|
47
|
+
* @param fileSource The source of the file:
|
|
48
|
+
* - In Node.js: A string path to the file
|
|
49
|
+
* - In browser: A File or Blob object
|
|
50
|
+
* @returns Promise resolving to the file buffer/blob
|
|
51
|
+
* @throws Error if file reading fails or if using an inappropriate
|
|
52
|
+
* file source type for the current environment
|
|
53
|
+
*/
|
|
54
|
+
async function readFile(fileSource) {
|
|
55
|
+
if ((0, environment_1.isNodeEnvironment)()) {
|
|
56
|
+
// Node.js environment
|
|
57
|
+
if (typeof fileSource !== 'string') {
|
|
58
|
+
throw new Error('In Node.js environment, fileSource must be a file path string');
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
// Dynamic import to avoid bundling issues in browser
|
|
62
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
63
|
+
return fs.readFileSync(fileSource);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
throw new Error(`Failed to read file at path ${fileSource}: ${error.message}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// Browser environment
|
|
71
|
+
if (typeof fileSource === 'string') {
|
|
72
|
+
throw new Error('In browser environment, fileSource must be a File or Blob object, not a path string');
|
|
73
|
+
}
|
|
74
|
+
// File or Blob are already the data we need
|
|
75
|
+
return fileSource;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Gets the appropriate filename from the file source based on the environment.
|
|
80
|
+
*
|
|
81
|
+
* @param fileSource The source of the file
|
|
82
|
+
* @returns Promise resolving to the filename
|
|
83
|
+
*/
|
|
84
|
+
async function getFileName(fileSource) {
|
|
85
|
+
if ((0, environment_1.isNodeEnvironment)()) {
|
|
86
|
+
// In Node.js, extract the basename from the path
|
|
87
|
+
if (typeof fileSource !== 'string') {
|
|
88
|
+
throw new Error('Expected file path string in Node.js environment');
|
|
89
|
+
}
|
|
90
|
+
const path = await Promise.resolve().then(() => __importStar(require('path')));
|
|
91
|
+
return path.basename(fileSource);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// In browser, use the name property of the File object
|
|
95
|
+
if (fileSource instanceof File) {
|
|
96
|
+
return fileSource.name;
|
|
97
|
+
}
|
|
98
|
+
else if (fileSource instanceof Blob) {
|
|
99
|
+
// For generic blobs, generate a name
|
|
100
|
+
return `blob-${Date.now()}.bin`;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
throw new Error('Expected File or Blob in browser environment');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=file-reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-reader.js","sourceRoot":"","sources":["../../src/utils/file-reader.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBH,4BAuBC;AAQD,kCAoBC;AAtED,+CAAkD;AASlD;;;;;;;;;GASG;AACI,KAAK,UAAU,QAAQ,CAAC,UAAsB;IACjD,IAAI,IAAA,+BAAiB,GAAE,EAAE,CAAC;QACtB,sBAAsB;QACtB,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;QACrF,CAAC;QAED,IAAI,CAAC;YACD,qDAAqD;YACrD,MAAM,EAAE,GAAG,wDAAa,IAAI,GAAC,CAAC;YAC9B,OAAO,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QACvC,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,+BAA+B,UAAU,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACnF,CAAC;IACL,CAAC;SAAM,CAAC;QACJ,sBAAsB;QACtB,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,qFAAqF,CAAC,CAAC;QAC3G,CAAC;QAED,4CAA4C;QAC5C,OAAO,UAAU,CAAC;IACtB,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,WAAW,CAA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