@larkup-rag/client-js 1.0.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/dist/index.cjs +127 -0
- package/dist/index.d.cts +98 -0
- package/dist/index.d.ts +98 -0
- package/dist/index.js +100 -0
- package/package.json +30 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
LarkupRAGClient: () => LarkupRAGClient
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/client.ts
|
|
28
|
+
var LarkupRAGClient = class {
|
|
29
|
+
baseUrl;
|
|
30
|
+
apiKey;
|
|
31
|
+
constructor(options = {}) {
|
|
32
|
+
this.baseUrl = (options.baseUrl ?? process.env.LARKUP_RAG_API_URL ?? "http://localhost:8080").replace(/\/$/, "");
|
|
33
|
+
this.apiKey = options.apiKey ?? process.env.LARKUP_RAG_API_KEY;
|
|
34
|
+
}
|
|
35
|
+
async fetchApi(path, options = {}) {
|
|
36
|
+
const url = `${this.baseUrl}${path}`;
|
|
37
|
+
const headers = new Headers(options.headers || {});
|
|
38
|
+
if (this.apiKey) {
|
|
39
|
+
headers.set("Authorization", `Bearer ${this.apiKey}`);
|
|
40
|
+
}
|
|
41
|
+
if (!(options.body instanceof FormData)) {
|
|
42
|
+
headers.set("Content-Type", "application/json");
|
|
43
|
+
}
|
|
44
|
+
const response = await fetch(url, { ...options, headers });
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
let errorMsg = response.statusText;
|
|
47
|
+
try {
|
|
48
|
+
const errBody = await response.json();
|
|
49
|
+
if (errBody.error) {
|
|
50
|
+
errorMsg = errBody.error;
|
|
51
|
+
}
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
54
|
+
throw new Error(`LarkupRAG API Error (${response.status}): ${errorMsg}`);
|
|
55
|
+
}
|
|
56
|
+
return response.json();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Health check
|
|
60
|
+
*/
|
|
61
|
+
async health() {
|
|
62
|
+
return this.fetchApi("/health");
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Query the RAG knowledge base
|
|
66
|
+
*/
|
|
67
|
+
async query(request, topK) {
|
|
68
|
+
const body = typeof request === "string" ? { query: request, topK } : request;
|
|
69
|
+
return this.fetchApi("/query", {
|
|
70
|
+
method: "POST",
|
|
71
|
+
body: JSON.stringify(body)
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* List documents with pagination
|
|
76
|
+
*/
|
|
77
|
+
async listDocuments(page = 1, limit = 20) {
|
|
78
|
+
return this.fetchApi(
|
|
79
|
+
`/documents?page=${page}&limit=${limit}`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get a specific document by ID
|
|
84
|
+
*/
|
|
85
|
+
async getDocument(id) {
|
|
86
|
+
return this.fetchApi(`/documents/${id}`);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Add a new document to the vector store
|
|
90
|
+
*/
|
|
91
|
+
async addDocument(document) {
|
|
92
|
+
return this.fetchApi("/documents", {
|
|
93
|
+
method: "POST",
|
|
94
|
+
body: JSON.stringify(document)
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Update an existing document
|
|
99
|
+
*/
|
|
100
|
+
async updateDocument(id, document) {
|
|
101
|
+
return this.fetchApi(`/documents/${id}`, {
|
|
102
|
+
method: "PUT",
|
|
103
|
+
body: JSON.stringify(document)
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Delete a document
|
|
108
|
+
*/
|
|
109
|
+
async deleteDocument(id) {
|
|
110
|
+
return this.fetchApi(`/documents/${id}`, {
|
|
111
|
+
method: "DELETE"
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Scrape a URL and add it to the corpus
|
|
116
|
+
*/
|
|
117
|
+
async scrape(url) {
|
|
118
|
+
return this.fetchApi("/scrape", {
|
|
119
|
+
method: "POST",
|
|
120
|
+
body: JSON.stringify({ url })
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
125
|
+
0 && (module.exports = {
|
|
126
|
+
LarkupRAGClient
|
|
127
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
interface LarkupRAGClientOptions {
|
|
2
|
+
/** The URL of the Larkup RAG Server (e.g. http://localhost:8080) */
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
/** The server API key, required if the server is protected */
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
}
|
|
7
|
+
interface Document {
|
|
8
|
+
id: string;
|
|
9
|
+
text: string;
|
|
10
|
+
title?: string;
|
|
11
|
+
url?: string;
|
|
12
|
+
documentId?: string;
|
|
13
|
+
}
|
|
14
|
+
interface QueryRequest {
|
|
15
|
+
query: string;
|
|
16
|
+
topK?: number;
|
|
17
|
+
}
|
|
18
|
+
interface QueryHit {
|
|
19
|
+
id: string;
|
|
20
|
+
score: number;
|
|
21
|
+
text: string;
|
|
22
|
+
title: string;
|
|
23
|
+
url?: string;
|
|
24
|
+
documentId: string;
|
|
25
|
+
}
|
|
26
|
+
interface QueryResponse {
|
|
27
|
+
query: string;
|
|
28
|
+
hits: QueryHit[];
|
|
29
|
+
}
|
|
30
|
+
interface PaginatedDocuments {
|
|
31
|
+
documents: Document[];
|
|
32
|
+
total: number;
|
|
33
|
+
page: number;
|
|
34
|
+
limit: number;
|
|
35
|
+
totalPages: number;
|
|
36
|
+
}
|
|
37
|
+
interface ScrapeRequest {
|
|
38
|
+
url: string;
|
|
39
|
+
}
|
|
40
|
+
interface ScrapeResponse {
|
|
41
|
+
success: boolean;
|
|
42
|
+
documentId?: string;
|
|
43
|
+
error?: string;
|
|
44
|
+
}
|
|
45
|
+
interface HealthResponse {
|
|
46
|
+
ok: boolean;
|
|
47
|
+
service?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare class LarkupRAGClient {
|
|
51
|
+
private baseUrl;
|
|
52
|
+
private apiKey?;
|
|
53
|
+
constructor(options?: LarkupRAGClientOptions);
|
|
54
|
+
private fetchApi;
|
|
55
|
+
/**
|
|
56
|
+
* Health check
|
|
57
|
+
*/
|
|
58
|
+
health(): Promise<HealthResponse>;
|
|
59
|
+
/**
|
|
60
|
+
* Query the RAG knowledge base
|
|
61
|
+
*/
|
|
62
|
+
query(request: QueryRequest | string, topK?: number): Promise<QueryResponse>;
|
|
63
|
+
/**
|
|
64
|
+
* List documents with pagination
|
|
65
|
+
*/
|
|
66
|
+
listDocuments(page?: number, limit?: number): Promise<PaginatedDocuments>;
|
|
67
|
+
/**
|
|
68
|
+
* Get a specific document by ID
|
|
69
|
+
*/
|
|
70
|
+
getDocument(id: string): Promise<Document>;
|
|
71
|
+
/**
|
|
72
|
+
* Add a new document to the vector store
|
|
73
|
+
*/
|
|
74
|
+
addDocument(document: Omit<Document, "id"> & {
|
|
75
|
+
id?: string;
|
|
76
|
+
}): Promise<{
|
|
77
|
+
success: boolean;
|
|
78
|
+
id: string;
|
|
79
|
+
}>;
|
|
80
|
+
/**
|
|
81
|
+
* Update an existing document
|
|
82
|
+
*/
|
|
83
|
+
updateDocument(id: string, document: Omit<Document, "id">): Promise<{
|
|
84
|
+
success: boolean;
|
|
85
|
+
}>;
|
|
86
|
+
/**
|
|
87
|
+
* Delete a document
|
|
88
|
+
*/
|
|
89
|
+
deleteDocument(id: string): Promise<{
|
|
90
|
+
success: boolean;
|
|
91
|
+
}>;
|
|
92
|
+
/**
|
|
93
|
+
* Scrape a URL and add it to the corpus
|
|
94
|
+
*/
|
|
95
|
+
scrape(url: string): Promise<ScrapeResponse>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { type Document, type HealthResponse, LarkupRAGClient, type LarkupRAGClientOptions, type PaginatedDocuments, type QueryHit, type QueryRequest, type QueryResponse, type ScrapeRequest, type ScrapeResponse };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
interface LarkupRAGClientOptions {
|
|
2
|
+
/** The URL of the Larkup RAG Server (e.g. http://localhost:8080) */
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
/** The server API key, required if the server is protected */
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
}
|
|
7
|
+
interface Document {
|
|
8
|
+
id: string;
|
|
9
|
+
text: string;
|
|
10
|
+
title?: string;
|
|
11
|
+
url?: string;
|
|
12
|
+
documentId?: string;
|
|
13
|
+
}
|
|
14
|
+
interface QueryRequest {
|
|
15
|
+
query: string;
|
|
16
|
+
topK?: number;
|
|
17
|
+
}
|
|
18
|
+
interface QueryHit {
|
|
19
|
+
id: string;
|
|
20
|
+
score: number;
|
|
21
|
+
text: string;
|
|
22
|
+
title: string;
|
|
23
|
+
url?: string;
|
|
24
|
+
documentId: string;
|
|
25
|
+
}
|
|
26
|
+
interface QueryResponse {
|
|
27
|
+
query: string;
|
|
28
|
+
hits: QueryHit[];
|
|
29
|
+
}
|
|
30
|
+
interface PaginatedDocuments {
|
|
31
|
+
documents: Document[];
|
|
32
|
+
total: number;
|
|
33
|
+
page: number;
|
|
34
|
+
limit: number;
|
|
35
|
+
totalPages: number;
|
|
36
|
+
}
|
|
37
|
+
interface ScrapeRequest {
|
|
38
|
+
url: string;
|
|
39
|
+
}
|
|
40
|
+
interface ScrapeResponse {
|
|
41
|
+
success: boolean;
|
|
42
|
+
documentId?: string;
|
|
43
|
+
error?: string;
|
|
44
|
+
}
|
|
45
|
+
interface HealthResponse {
|
|
46
|
+
ok: boolean;
|
|
47
|
+
service?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare class LarkupRAGClient {
|
|
51
|
+
private baseUrl;
|
|
52
|
+
private apiKey?;
|
|
53
|
+
constructor(options?: LarkupRAGClientOptions);
|
|
54
|
+
private fetchApi;
|
|
55
|
+
/**
|
|
56
|
+
* Health check
|
|
57
|
+
*/
|
|
58
|
+
health(): Promise<HealthResponse>;
|
|
59
|
+
/**
|
|
60
|
+
* Query the RAG knowledge base
|
|
61
|
+
*/
|
|
62
|
+
query(request: QueryRequest | string, topK?: number): Promise<QueryResponse>;
|
|
63
|
+
/**
|
|
64
|
+
* List documents with pagination
|
|
65
|
+
*/
|
|
66
|
+
listDocuments(page?: number, limit?: number): Promise<PaginatedDocuments>;
|
|
67
|
+
/**
|
|
68
|
+
* Get a specific document by ID
|
|
69
|
+
*/
|
|
70
|
+
getDocument(id: string): Promise<Document>;
|
|
71
|
+
/**
|
|
72
|
+
* Add a new document to the vector store
|
|
73
|
+
*/
|
|
74
|
+
addDocument(document: Omit<Document, "id"> & {
|
|
75
|
+
id?: string;
|
|
76
|
+
}): Promise<{
|
|
77
|
+
success: boolean;
|
|
78
|
+
id: string;
|
|
79
|
+
}>;
|
|
80
|
+
/**
|
|
81
|
+
* Update an existing document
|
|
82
|
+
*/
|
|
83
|
+
updateDocument(id: string, document: Omit<Document, "id">): Promise<{
|
|
84
|
+
success: boolean;
|
|
85
|
+
}>;
|
|
86
|
+
/**
|
|
87
|
+
* Delete a document
|
|
88
|
+
*/
|
|
89
|
+
deleteDocument(id: string): Promise<{
|
|
90
|
+
success: boolean;
|
|
91
|
+
}>;
|
|
92
|
+
/**
|
|
93
|
+
* Scrape a URL and add it to the corpus
|
|
94
|
+
*/
|
|
95
|
+
scrape(url: string): Promise<ScrapeResponse>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { type Document, type HealthResponse, LarkupRAGClient, type LarkupRAGClientOptions, type PaginatedDocuments, type QueryHit, type QueryRequest, type QueryResponse, type ScrapeRequest, type ScrapeResponse };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
var LarkupRAGClient = class {
|
|
3
|
+
baseUrl;
|
|
4
|
+
apiKey;
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
this.baseUrl = (options.baseUrl ?? process.env.LARKUP_RAG_API_URL ?? "http://localhost:8080").replace(/\/$/, "");
|
|
7
|
+
this.apiKey = options.apiKey ?? process.env.LARKUP_RAG_API_KEY;
|
|
8
|
+
}
|
|
9
|
+
async fetchApi(path, options = {}) {
|
|
10
|
+
const url = `${this.baseUrl}${path}`;
|
|
11
|
+
const headers = new Headers(options.headers || {});
|
|
12
|
+
if (this.apiKey) {
|
|
13
|
+
headers.set("Authorization", `Bearer ${this.apiKey}`);
|
|
14
|
+
}
|
|
15
|
+
if (!(options.body instanceof FormData)) {
|
|
16
|
+
headers.set("Content-Type", "application/json");
|
|
17
|
+
}
|
|
18
|
+
const response = await fetch(url, { ...options, headers });
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
let errorMsg = response.statusText;
|
|
21
|
+
try {
|
|
22
|
+
const errBody = await response.json();
|
|
23
|
+
if (errBody.error) {
|
|
24
|
+
errorMsg = errBody.error;
|
|
25
|
+
}
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
28
|
+
throw new Error(`LarkupRAG API Error (${response.status}): ${errorMsg}`);
|
|
29
|
+
}
|
|
30
|
+
return response.json();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Health check
|
|
34
|
+
*/
|
|
35
|
+
async health() {
|
|
36
|
+
return this.fetchApi("/health");
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Query the RAG knowledge base
|
|
40
|
+
*/
|
|
41
|
+
async query(request, topK) {
|
|
42
|
+
const body = typeof request === "string" ? { query: request, topK } : request;
|
|
43
|
+
return this.fetchApi("/query", {
|
|
44
|
+
method: "POST",
|
|
45
|
+
body: JSON.stringify(body)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* List documents with pagination
|
|
50
|
+
*/
|
|
51
|
+
async listDocuments(page = 1, limit = 20) {
|
|
52
|
+
return this.fetchApi(
|
|
53
|
+
`/documents?page=${page}&limit=${limit}`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get a specific document by ID
|
|
58
|
+
*/
|
|
59
|
+
async getDocument(id) {
|
|
60
|
+
return this.fetchApi(`/documents/${id}`);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Add a new document to the vector store
|
|
64
|
+
*/
|
|
65
|
+
async addDocument(document) {
|
|
66
|
+
return this.fetchApi("/documents", {
|
|
67
|
+
method: "POST",
|
|
68
|
+
body: JSON.stringify(document)
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Update an existing document
|
|
73
|
+
*/
|
|
74
|
+
async updateDocument(id, document) {
|
|
75
|
+
return this.fetchApi(`/documents/${id}`, {
|
|
76
|
+
method: "PUT",
|
|
77
|
+
body: JSON.stringify(document)
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Delete a document
|
|
82
|
+
*/
|
|
83
|
+
async deleteDocument(id) {
|
|
84
|
+
return this.fetchApi(`/documents/${id}`, {
|
|
85
|
+
method: "DELETE"
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Scrape a URL and add it to the corpus
|
|
90
|
+
*/
|
|
91
|
+
async scrape(url) {
|
|
92
|
+
return this.fetchApi("/scrape", {
|
|
93
|
+
method: "POST",
|
|
94
|
+
body: JSON.stringify({ url })
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
export {
|
|
99
|
+
LarkupRAGClient
|
|
100
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@larkup-rag/client-js",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "JavaScript/TypeScript SDK for Larkup RAG servers",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^26.0.0",
|
|
21
|
+
"tsup": "^8.5.1",
|
|
22
|
+
"typescript": "^5.7.3",
|
|
23
|
+
"vitest": "^1.6.1"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
27
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
28
|
+
"test": "vitest run"
|
|
29
|
+
}
|
|
30
|
+
}
|