@ragable/sdk 0.0.2 → 0.0.3
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.d.mts +121 -19
- package/dist/index.d.ts +121 -19
- package/dist/index.js +223 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +215 -45
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -4,6 +4,30 @@ interface RagableClientOptions {
|
|
|
4
4
|
fetch?: typeof fetch;
|
|
5
5
|
headers?: HeadersInit;
|
|
6
6
|
}
|
|
7
|
+
type RequestOptions = Omit<RequestInit, "body"> & {
|
|
8
|
+
body?: unknown;
|
|
9
|
+
};
|
|
10
|
+
declare class RagableError extends Error {
|
|
11
|
+
readonly status: number;
|
|
12
|
+
readonly body: unknown;
|
|
13
|
+
constructor(message: string, status: number, body: unknown);
|
|
14
|
+
}
|
|
15
|
+
declare function extractErrorMessage(payload: unknown, fallback: string): string;
|
|
16
|
+
declare class RagableRequestClient {
|
|
17
|
+
private readonly apiKey;
|
|
18
|
+
private readonly baseUrl;
|
|
19
|
+
private readonly fetchImpl;
|
|
20
|
+
private readonly defaultHeaders;
|
|
21
|
+
constructor(options: RagableClientOptions);
|
|
22
|
+
toUrl(path: string): string;
|
|
23
|
+
request<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Low-level fetch with API key and JSON body encoding. Caller handles status and body.
|
|
26
|
+
*/
|
|
27
|
+
rawFetch(path: string, options?: RequestOptions): Promise<Response>;
|
|
28
|
+
private parseResponseBody;
|
|
29
|
+
}
|
|
30
|
+
|
|
7
31
|
interface ShiftIndex {
|
|
8
32
|
id: string;
|
|
9
33
|
name: string;
|
|
@@ -70,24 +94,6 @@ interface ShiftListEntriesResponse {
|
|
|
70
94
|
entries: ShiftEntry[];
|
|
71
95
|
total: number;
|
|
72
96
|
}
|
|
73
|
-
declare class RagableError extends Error {
|
|
74
|
-
readonly status: number;
|
|
75
|
-
readonly body: unknown;
|
|
76
|
-
constructor(message: string, status: number, body: unknown);
|
|
77
|
-
}
|
|
78
|
-
type RequestOptions = Omit<RequestInit, "body"> & {
|
|
79
|
-
body?: unknown;
|
|
80
|
-
};
|
|
81
|
-
declare class RagableRequestClient {
|
|
82
|
-
private readonly apiKey;
|
|
83
|
-
private readonly baseUrl;
|
|
84
|
-
private readonly fetchImpl;
|
|
85
|
-
private readonly defaultHeaders;
|
|
86
|
-
constructor(options: RagableClientOptions);
|
|
87
|
-
request<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
88
|
-
private toUrl;
|
|
89
|
-
private parseResponseBody;
|
|
90
|
-
}
|
|
91
97
|
declare class ShiftClient {
|
|
92
98
|
private readonly client;
|
|
93
99
|
readonly indexes: {
|
|
@@ -116,8 +122,104 @@ declare class ShiftClient {
|
|
|
116
122
|
results: ShiftSearchResult[];
|
|
117
123
|
}>;
|
|
118
124
|
}
|
|
125
|
+
|
|
126
|
+
interface AgentSummary {
|
|
127
|
+
id: string;
|
|
128
|
+
name: string;
|
|
129
|
+
description: string | null;
|
|
130
|
+
active: boolean;
|
|
131
|
+
createdAt: string;
|
|
132
|
+
updatedAt: string;
|
|
133
|
+
}
|
|
134
|
+
interface AgentChatMessage {
|
|
135
|
+
role: "user" | "assistant";
|
|
136
|
+
content: string;
|
|
137
|
+
}
|
|
138
|
+
interface AgentChatParams {
|
|
139
|
+
message: string;
|
|
140
|
+
history?: AgentChatMessage[];
|
|
141
|
+
}
|
|
142
|
+
/** Mirrors backend ExecutionResult JSON shape (traces are opaque in the SDK). */
|
|
143
|
+
interface AgentChatResult {
|
|
144
|
+
response: string;
|
|
145
|
+
traces: unknown[];
|
|
146
|
+
totalDurationMs: number;
|
|
147
|
+
httpResponse?: unknown;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Loose SSE event from POST /v1/agents/:id/chat/stream — narrows with `type` at runtime.
|
|
151
|
+
*/
|
|
152
|
+
type AgentStreamEvent = Record<string, unknown> & {
|
|
153
|
+
type: string;
|
|
154
|
+
};
|
|
155
|
+
declare class AgentsClient {
|
|
156
|
+
private readonly client;
|
|
157
|
+
constructor(client: RagableRequestClient);
|
|
158
|
+
list(): Promise<{
|
|
159
|
+
agents: AgentSummary[];
|
|
160
|
+
}>;
|
|
161
|
+
get(agentId: string): Promise<AgentSummary>;
|
|
162
|
+
chat(agentId: string, params: AgentChatParams): Promise<AgentChatResult>;
|
|
163
|
+
/**
|
|
164
|
+
* Stream agent execution as SSE (`data: {json}` lines). Yields parsed JSON objects.
|
|
165
|
+
*/
|
|
166
|
+
chatStream(agentId: string, params: AgentChatParams): AsyncGenerator<AgentStreamEvent, void, undefined>;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Minimal client surface for {@link createRagPipeline} (implemented by {@link Ragable}). */
|
|
170
|
+
interface RagClientForPipeline {
|
|
171
|
+
shift: {
|
|
172
|
+
documents: {
|
|
173
|
+
create: (indexId: string, params: ShiftAddDocumentParams) => Promise<ShiftIngestResponse>;
|
|
174
|
+
upload: (indexId: string, params: ShiftUploadFileParams) => Promise<ShiftIngestResponse>;
|
|
175
|
+
};
|
|
176
|
+
search: (indexId: string, params: ShiftSearchParams) => Promise<{
|
|
177
|
+
results: ShiftSearchResult[];
|
|
178
|
+
}>;
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
interface FormatContextOptions {
|
|
182
|
+
/** Prepended before numbered passages (default: "Relevant passages:\\n") */
|
|
183
|
+
header?: string;
|
|
184
|
+
/** Joiner between passages (default: "\\n\\n") */
|
|
185
|
+
separator?: string;
|
|
186
|
+
/** Omit results with similarity score below this (default: no filter) */
|
|
187
|
+
minScore?: number;
|
|
188
|
+
/** Truncate total context string to this UTF-16 length (default: no limit) */
|
|
189
|
+
maxChars?: number;
|
|
190
|
+
/** Include similarity score in each block (default: false) */
|
|
191
|
+
includeScores?: boolean;
|
|
192
|
+
}
|
|
193
|
+
interface RagPipelineOptions {
|
|
194
|
+
indexId: string;
|
|
195
|
+
}
|
|
196
|
+
type RetrieveParams = ShiftSearchParams & {
|
|
197
|
+
format?: FormatContextOptions;
|
|
198
|
+
};
|
|
199
|
+
interface RagPipeline {
|
|
200
|
+
readonly indexId: string;
|
|
201
|
+
ingestText(params: ShiftAddDocumentParams): Promise<ShiftIngestResponse>;
|
|
202
|
+
ingestFile(params: ShiftUploadFileParams): Promise<ShiftIngestResponse>;
|
|
203
|
+
search(params: ShiftSearchParams): Promise<{
|
|
204
|
+
results: ShiftSearchResult[];
|
|
205
|
+
}>;
|
|
206
|
+
retrieve(params: RetrieveParams): Promise<{
|
|
207
|
+
results: ShiftSearchResult[];
|
|
208
|
+
context: string;
|
|
209
|
+
}>;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Turn vector search hits into a single block of text for system prompts or RAG user messages.
|
|
213
|
+
*/
|
|
214
|
+
declare function formatRetrievalContext(results: ShiftSearchResult[], options?: FormatContextOptions): string;
|
|
215
|
+
/**
|
|
216
|
+
* High-level RAG helpers bound to one Shift index: ingest, search, retrieve with prompt-ready context.
|
|
217
|
+
*/
|
|
218
|
+
declare function createRagPipeline(client: RagClientForPipeline, options: RagPipelineOptions): RagPipeline;
|
|
219
|
+
|
|
119
220
|
declare class Ragable {
|
|
120
221
|
readonly shift: ShiftClient;
|
|
222
|
+
readonly agents: AgentsClient;
|
|
121
223
|
readonly infrastructure: {
|
|
122
224
|
shift: ShiftClient;
|
|
123
225
|
};
|
|
@@ -125,4 +227,4 @@ declare class Ragable {
|
|
|
125
227
|
}
|
|
126
228
|
declare function createClient(options: RagableClientOptions): Ragable;
|
|
127
229
|
|
|
128
|
-
export { Ragable, type RagableClientOptions, RagableError, type ShiftAddDocumentParams, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, createClient };
|
|
230
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentStreamEvent, type AgentSummary, AgentsClient, type FormatContextOptions, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, type RagableClientOptions, RagableError, RagableRequestClient, type RequestOptions, type RetrieveParams, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, createClient, createRagPipeline, extractErrorMessage, formatRetrievalContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,30 @@ interface RagableClientOptions {
|
|
|
4
4
|
fetch?: typeof fetch;
|
|
5
5
|
headers?: HeadersInit;
|
|
6
6
|
}
|
|
7
|
+
type RequestOptions = Omit<RequestInit, "body"> & {
|
|
8
|
+
body?: unknown;
|
|
9
|
+
};
|
|
10
|
+
declare class RagableError extends Error {
|
|
11
|
+
readonly status: number;
|
|
12
|
+
readonly body: unknown;
|
|
13
|
+
constructor(message: string, status: number, body: unknown);
|
|
14
|
+
}
|
|
15
|
+
declare function extractErrorMessage(payload: unknown, fallback: string): string;
|
|
16
|
+
declare class RagableRequestClient {
|
|
17
|
+
private readonly apiKey;
|
|
18
|
+
private readonly baseUrl;
|
|
19
|
+
private readonly fetchImpl;
|
|
20
|
+
private readonly defaultHeaders;
|
|
21
|
+
constructor(options: RagableClientOptions);
|
|
22
|
+
toUrl(path: string): string;
|
|
23
|
+
request<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Low-level fetch with API key and JSON body encoding. Caller handles status and body.
|
|
26
|
+
*/
|
|
27
|
+
rawFetch(path: string, options?: RequestOptions): Promise<Response>;
|
|
28
|
+
private parseResponseBody;
|
|
29
|
+
}
|
|
30
|
+
|
|
7
31
|
interface ShiftIndex {
|
|
8
32
|
id: string;
|
|
9
33
|
name: string;
|
|
@@ -70,24 +94,6 @@ interface ShiftListEntriesResponse {
|
|
|
70
94
|
entries: ShiftEntry[];
|
|
71
95
|
total: number;
|
|
72
96
|
}
|
|
73
|
-
declare class RagableError extends Error {
|
|
74
|
-
readonly status: number;
|
|
75
|
-
readonly body: unknown;
|
|
76
|
-
constructor(message: string, status: number, body: unknown);
|
|
77
|
-
}
|
|
78
|
-
type RequestOptions = Omit<RequestInit, "body"> & {
|
|
79
|
-
body?: unknown;
|
|
80
|
-
};
|
|
81
|
-
declare class RagableRequestClient {
|
|
82
|
-
private readonly apiKey;
|
|
83
|
-
private readonly baseUrl;
|
|
84
|
-
private readonly fetchImpl;
|
|
85
|
-
private readonly defaultHeaders;
|
|
86
|
-
constructor(options: RagableClientOptions);
|
|
87
|
-
request<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
88
|
-
private toUrl;
|
|
89
|
-
private parseResponseBody;
|
|
90
|
-
}
|
|
91
97
|
declare class ShiftClient {
|
|
92
98
|
private readonly client;
|
|
93
99
|
readonly indexes: {
|
|
@@ -116,8 +122,104 @@ declare class ShiftClient {
|
|
|
116
122
|
results: ShiftSearchResult[];
|
|
117
123
|
}>;
|
|
118
124
|
}
|
|
125
|
+
|
|
126
|
+
interface AgentSummary {
|
|
127
|
+
id: string;
|
|
128
|
+
name: string;
|
|
129
|
+
description: string | null;
|
|
130
|
+
active: boolean;
|
|
131
|
+
createdAt: string;
|
|
132
|
+
updatedAt: string;
|
|
133
|
+
}
|
|
134
|
+
interface AgentChatMessage {
|
|
135
|
+
role: "user" | "assistant";
|
|
136
|
+
content: string;
|
|
137
|
+
}
|
|
138
|
+
interface AgentChatParams {
|
|
139
|
+
message: string;
|
|
140
|
+
history?: AgentChatMessage[];
|
|
141
|
+
}
|
|
142
|
+
/** Mirrors backend ExecutionResult JSON shape (traces are opaque in the SDK). */
|
|
143
|
+
interface AgentChatResult {
|
|
144
|
+
response: string;
|
|
145
|
+
traces: unknown[];
|
|
146
|
+
totalDurationMs: number;
|
|
147
|
+
httpResponse?: unknown;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Loose SSE event from POST /v1/agents/:id/chat/stream — narrows with `type` at runtime.
|
|
151
|
+
*/
|
|
152
|
+
type AgentStreamEvent = Record<string, unknown> & {
|
|
153
|
+
type: string;
|
|
154
|
+
};
|
|
155
|
+
declare class AgentsClient {
|
|
156
|
+
private readonly client;
|
|
157
|
+
constructor(client: RagableRequestClient);
|
|
158
|
+
list(): Promise<{
|
|
159
|
+
agents: AgentSummary[];
|
|
160
|
+
}>;
|
|
161
|
+
get(agentId: string): Promise<AgentSummary>;
|
|
162
|
+
chat(agentId: string, params: AgentChatParams): Promise<AgentChatResult>;
|
|
163
|
+
/**
|
|
164
|
+
* Stream agent execution as SSE (`data: {json}` lines). Yields parsed JSON objects.
|
|
165
|
+
*/
|
|
166
|
+
chatStream(agentId: string, params: AgentChatParams): AsyncGenerator<AgentStreamEvent, void, undefined>;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Minimal client surface for {@link createRagPipeline} (implemented by {@link Ragable}). */
|
|
170
|
+
interface RagClientForPipeline {
|
|
171
|
+
shift: {
|
|
172
|
+
documents: {
|
|
173
|
+
create: (indexId: string, params: ShiftAddDocumentParams) => Promise<ShiftIngestResponse>;
|
|
174
|
+
upload: (indexId: string, params: ShiftUploadFileParams) => Promise<ShiftIngestResponse>;
|
|
175
|
+
};
|
|
176
|
+
search: (indexId: string, params: ShiftSearchParams) => Promise<{
|
|
177
|
+
results: ShiftSearchResult[];
|
|
178
|
+
}>;
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
interface FormatContextOptions {
|
|
182
|
+
/** Prepended before numbered passages (default: "Relevant passages:\\n") */
|
|
183
|
+
header?: string;
|
|
184
|
+
/** Joiner between passages (default: "\\n\\n") */
|
|
185
|
+
separator?: string;
|
|
186
|
+
/** Omit results with similarity score below this (default: no filter) */
|
|
187
|
+
minScore?: number;
|
|
188
|
+
/** Truncate total context string to this UTF-16 length (default: no limit) */
|
|
189
|
+
maxChars?: number;
|
|
190
|
+
/** Include similarity score in each block (default: false) */
|
|
191
|
+
includeScores?: boolean;
|
|
192
|
+
}
|
|
193
|
+
interface RagPipelineOptions {
|
|
194
|
+
indexId: string;
|
|
195
|
+
}
|
|
196
|
+
type RetrieveParams = ShiftSearchParams & {
|
|
197
|
+
format?: FormatContextOptions;
|
|
198
|
+
};
|
|
199
|
+
interface RagPipeline {
|
|
200
|
+
readonly indexId: string;
|
|
201
|
+
ingestText(params: ShiftAddDocumentParams): Promise<ShiftIngestResponse>;
|
|
202
|
+
ingestFile(params: ShiftUploadFileParams): Promise<ShiftIngestResponse>;
|
|
203
|
+
search(params: ShiftSearchParams): Promise<{
|
|
204
|
+
results: ShiftSearchResult[];
|
|
205
|
+
}>;
|
|
206
|
+
retrieve(params: RetrieveParams): Promise<{
|
|
207
|
+
results: ShiftSearchResult[];
|
|
208
|
+
context: string;
|
|
209
|
+
}>;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Turn vector search hits into a single block of text for system prompts or RAG user messages.
|
|
213
|
+
*/
|
|
214
|
+
declare function formatRetrievalContext(results: ShiftSearchResult[], options?: FormatContextOptions): string;
|
|
215
|
+
/**
|
|
216
|
+
* High-level RAG helpers bound to one Shift index: ingest, search, retrieve with prompt-ready context.
|
|
217
|
+
*/
|
|
218
|
+
declare function createRagPipeline(client: RagClientForPipeline, options: RagPipelineOptions): RagPipeline;
|
|
219
|
+
|
|
119
220
|
declare class Ragable {
|
|
120
221
|
readonly shift: ShiftClient;
|
|
222
|
+
readonly agents: AgentsClient;
|
|
121
223
|
readonly infrastructure: {
|
|
122
224
|
shift: ShiftClient;
|
|
123
225
|
};
|
|
@@ -125,4 +227,4 @@ declare class Ragable {
|
|
|
125
227
|
}
|
|
126
228
|
declare function createClient(options: RagableClientOptions): Ragable;
|
|
127
229
|
|
|
128
|
-
export { Ragable, type RagableClientOptions, RagableError, type ShiftAddDocumentParams, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, createClient };
|
|
230
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentStreamEvent, type AgentSummary, AgentsClient, type FormatContextOptions, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, type RagableClientOptions, RagableError, RagableRequestClient, type RequestOptions, type RetrieveParams, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, createClient, createRagPipeline, extractErrorMessage, formatRetrievalContext };
|
package/dist/index.js
CHANGED
|
@@ -22,11 +22,19 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
22
22
|
// src/index.ts
|
|
23
23
|
var index_exports = {};
|
|
24
24
|
__export(index_exports, {
|
|
25
|
+
AgentsClient: () => AgentsClient,
|
|
25
26
|
Ragable: () => Ragable,
|
|
26
27
|
RagableError: () => RagableError,
|
|
27
|
-
|
|
28
|
+
RagableRequestClient: () => RagableRequestClient,
|
|
29
|
+
ShiftClient: () => ShiftClient,
|
|
30
|
+
createClient: () => createClient,
|
|
31
|
+
createRagPipeline: () => createRagPipeline,
|
|
32
|
+
extractErrorMessage: () => extractErrorMessage,
|
|
33
|
+
formatRetrievalContext: () => formatRetrievalContext
|
|
28
34
|
});
|
|
29
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/request-client.ts
|
|
30
38
|
var RagableError = class extends Error {
|
|
31
39
|
constructor(message, status, body) {
|
|
32
40
|
super(message);
|
|
@@ -37,6 +45,20 @@ var RagableError = class extends Error {
|
|
|
37
45
|
this.body = body;
|
|
38
46
|
}
|
|
39
47
|
};
|
|
48
|
+
function extractErrorMessage(payload, fallback) {
|
|
49
|
+
if (payload && typeof payload === "object") {
|
|
50
|
+
if ("error" in payload && typeof payload.error === "string") {
|
|
51
|
+
return payload.error;
|
|
52
|
+
}
|
|
53
|
+
if ("message" in payload && typeof payload.message === "string") {
|
|
54
|
+
return payload.message;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (typeof payload === "string" && payload.length > 0) {
|
|
58
|
+
return payload;
|
|
59
|
+
}
|
|
60
|
+
return fallback || "Request failed";
|
|
61
|
+
}
|
|
40
62
|
var RagableRequestClient = class {
|
|
41
63
|
constructor(options) {
|
|
42
64
|
__publicField(this, "apiKey");
|
|
@@ -48,7 +70,24 @@ var RagableRequestClient = class {
|
|
|
48
70
|
this.fetchImpl = options.fetch ?? fetch;
|
|
49
71
|
this.defaultHeaders = options.headers;
|
|
50
72
|
}
|
|
73
|
+
toUrl(path) {
|
|
74
|
+
const normalizedBase = this.baseUrl.replace(/\/+$/, "");
|
|
75
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
76
|
+
return `${normalizedBase}${normalizedPath}`;
|
|
77
|
+
}
|
|
51
78
|
async request(path, options = {}) {
|
|
79
|
+
const response = await this.rawFetch(path, options);
|
|
80
|
+
const payload = await this.parseResponseBody(response);
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
const message = extractErrorMessage(payload, response.statusText);
|
|
83
|
+
throw new RagableError(message, response.status, payload);
|
|
84
|
+
}
|
|
85
|
+
return payload;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Low-level fetch with API key and JSON body encoding. Caller handles status and body.
|
|
89
|
+
*/
|
|
90
|
+
async rawFetch(path, options = {}) {
|
|
52
91
|
const headers = new Headers(this.defaultHeaders);
|
|
53
92
|
headers.set("Authorization", `Bearer ${this.apiKey}`);
|
|
54
93
|
let body = options.body;
|
|
@@ -56,22 +95,11 @@ var RagableRequestClient = class {
|
|
|
56
95
|
headers.set("Content-Type", "application/json");
|
|
57
96
|
body = JSON.stringify(body);
|
|
58
97
|
}
|
|
59
|
-
|
|
98
|
+
return this.fetchImpl(this.toUrl(path), {
|
|
60
99
|
...options,
|
|
61
100
|
headers,
|
|
62
101
|
body
|
|
63
102
|
});
|
|
64
|
-
const payload = await this.parseResponseBody(response);
|
|
65
|
-
if (!response.ok) {
|
|
66
|
-
const message = extractErrorMessage(payload, response.statusText);
|
|
67
|
-
throw new RagableError(message, response.status, payload);
|
|
68
|
-
}
|
|
69
|
-
return payload;
|
|
70
|
-
}
|
|
71
|
-
toUrl(path) {
|
|
72
|
-
const normalizedBase = this.baseUrl.replace(/\/+$/, "");
|
|
73
|
-
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
74
|
-
return `${normalizedBase}${normalizedPath}`;
|
|
75
103
|
}
|
|
76
104
|
async parseResponseBody(response) {
|
|
77
105
|
if (response.status === 204) {
|
|
@@ -84,6 +112,11 @@ var RagableRequestClient = class {
|
|
|
84
112
|
return response.text();
|
|
85
113
|
}
|
|
86
114
|
};
|
|
115
|
+
function isBodyInit(value) {
|
|
116
|
+
return typeof value === "string" || value instanceof Blob || value instanceof FormData || value instanceof URLSearchParams || value instanceof ArrayBuffer || ArrayBuffer.isView(value);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/shift.ts
|
|
87
120
|
var ShiftClient = class {
|
|
88
121
|
constructor(client) {
|
|
89
122
|
this.client = client;
|
|
@@ -186,34 +219,6 @@ var ShiftClient = class {
|
|
|
186
219
|
);
|
|
187
220
|
}
|
|
188
221
|
};
|
|
189
|
-
var Ragable = class {
|
|
190
|
-
constructor(options) {
|
|
191
|
-
__publicField(this, "shift");
|
|
192
|
-
__publicField(this, "infrastructure");
|
|
193
|
-
const client = new RagableRequestClient(options);
|
|
194
|
-
this.shift = new ShiftClient(client);
|
|
195
|
-
this.infrastructure = {
|
|
196
|
-
shift: this.shift
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
function createClient(options) {
|
|
201
|
-
return new Ragable(options);
|
|
202
|
-
}
|
|
203
|
-
function extractErrorMessage(payload, fallback) {
|
|
204
|
-
if (payload && typeof payload === "object") {
|
|
205
|
-
if ("error" in payload && typeof payload.error === "string") {
|
|
206
|
-
return payload.error;
|
|
207
|
-
}
|
|
208
|
-
if ("message" in payload && typeof payload.message === "string") {
|
|
209
|
-
return payload.message;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
if (typeof payload === "string" && payload.length > 0) {
|
|
213
|
-
return payload;
|
|
214
|
-
}
|
|
215
|
-
return fallback || "Request failed";
|
|
216
|
-
}
|
|
217
222
|
function resolveUploadFileName(params) {
|
|
218
223
|
if (params.fileName) {
|
|
219
224
|
return params.fileName;
|
|
@@ -244,18 +249,191 @@ function normalizeUploadFile(file, contentType) {
|
|
|
244
249
|
function isNamedBlob(value) {
|
|
245
250
|
return value instanceof Blob && "name" in value && typeof value.name === "string";
|
|
246
251
|
}
|
|
247
|
-
function isBodyInit(value) {
|
|
248
|
-
return typeof value === "string" || value instanceof Blob || value instanceof FormData || value instanceof URLSearchParams || value instanceof ArrayBuffer || ArrayBuffer.isView(value);
|
|
249
|
-
}
|
|
250
252
|
function toArrayBuffer(value) {
|
|
251
253
|
const copy = new Uint8Array(value.byteLength);
|
|
252
254
|
copy.set(value);
|
|
253
255
|
return copy.buffer;
|
|
254
256
|
}
|
|
257
|
+
|
|
258
|
+
// src/agents.ts
|
|
259
|
+
var AgentsClient = class {
|
|
260
|
+
constructor(client) {
|
|
261
|
+
this.client = client;
|
|
262
|
+
}
|
|
263
|
+
async list() {
|
|
264
|
+
return this.client.request("/v1/agents");
|
|
265
|
+
}
|
|
266
|
+
async get(agentId) {
|
|
267
|
+
return this.client.request(`/v1/agents/${agentId}`);
|
|
268
|
+
}
|
|
269
|
+
async chat(agentId, params) {
|
|
270
|
+
return this.client.request(`/v1/agents/${agentId}/chat`, {
|
|
271
|
+
method: "POST",
|
|
272
|
+
body: {
|
|
273
|
+
message: params.message,
|
|
274
|
+
...params.history !== void 0 ? { history: params.history } : {}
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Stream agent execution as SSE (`data: {json}` lines). Yields parsed JSON objects.
|
|
280
|
+
*/
|
|
281
|
+
async *chatStream(agentId, params) {
|
|
282
|
+
const response = await this.client.rawFetch(
|
|
283
|
+
`/v1/agents/${agentId}/chat/stream`,
|
|
284
|
+
{
|
|
285
|
+
method: "POST",
|
|
286
|
+
body: {
|
|
287
|
+
message: params.message,
|
|
288
|
+
...params.history !== void 0 ? { history: params.history } : {}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
);
|
|
292
|
+
if (!response.ok) {
|
|
293
|
+
const payload = await parseMaybeJsonBody(response);
|
|
294
|
+
const message = extractErrorMessage(payload, response.statusText);
|
|
295
|
+
throw new RagableError(message, response.status, payload);
|
|
296
|
+
}
|
|
297
|
+
const body = response.body;
|
|
298
|
+
if (!body) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const reader = body.getReader();
|
|
302
|
+
const decoder = new TextDecoder();
|
|
303
|
+
let buffer = "";
|
|
304
|
+
try {
|
|
305
|
+
while (true) {
|
|
306
|
+
const { done, value } = await reader.read();
|
|
307
|
+
if (done) {
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
buffer += decoder.decode(value, { stream: true });
|
|
311
|
+
let boundary = buffer.indexOf("\n\n");
|
|
312
|
+
while (boundary !== -1) {
|
|
313
|
+
const block = buffer.slice(0, boundary);
|
|
314
|
+
buffer = buffer.slice(boundary + 2);
|
|
315
|
+
for (const line of block.split("\n")) {
|
|
316
|
+
const evt = parseSseDataLine(line);
|
|
317
|
+
if (evt) {
|
|
318
|
+
yield evt;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
boundary = buffer.indexOf("\n\n");
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (buffer.trim().length > 0) {
|
|
325
|
+
for (const line of buffer.split("\n")) {
|
|
326
|
+
const evt = parseSseDataLine(line);
|
|
327
|
+
if (evt) {
|
|
328
|
+
yield evt;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
} finally {
|
|
333
|
+
reader.releaseLock();
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
async function parseMaybeJsonBody(response) {
|
|
338
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
339
|
+
if (contentType.includes("application/json")) {
|
|
340
|
+
try {
|
|
341
|
+
return await response.json();
|
|
342
|
+
} catch {
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
try {
|
|
347
|
+
return await response.text();
|
|
348
|
+
} catch {
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
function parseSseDataLine(line) {
|
|
353
|
+
const dataPrefix = "data: ";
|
|
354
|
+
if (!line.startsWith(dataPrefix)) {
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
const json = line.slice(dataPrefix.length).trim();
|
|
358
|
+
if (json.length === 0 || json === "[DONE]") {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
try {
|
|
362
|
+
return JSON.parse(json);
|
|
363
|
+
} catch {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// src/rag.ts
|
|
369
|
+
function formatRetrievalContext(results, options = {}) {
|
|
370
|
+
const header = options.header ?? "Relevant passages:\n";
|
|
371
|
+
const separator = options.separator ?? "\n\n";
|
|
372
|
+
const minScore = options.minScore;
|
|
373
|
+
let filtered = results;
|
|
374
|
+
if (typeof minScore === "number") {
|
|
375
|
+
filtered = results.filter((r) => r.score >= minScore);
|
|
376
|
+
}
|
|
377
|
+
const blocks = filtered.map((r, i) => {
|
|
378
|
+
const scoreSuffix = options.includeScores === true ? ` (score: ${r.score.toFixed(4)})` : "";
|
|
379
|
+
return `[${i + 1}]${scoreSuffix}
|
|
380
|
+
${r.content.trim()}`;
|
|
381
|
+
});
|
|
382
|
+
let text = (blocks.length > 0 ? header : "") + blocks.join(separator);
|
|
383
|
+
if (typeof options.maxChars === "number" && text.length > options.maxChars) {
|
|
384
|
+
text = text.slice(0, options.maxChars).trimEnd() + "\n\u2026";
|
|
385
|
+
}
|
|
386
|
+
return text;
|
|
387
|
+
}
|
|
388
|
+
function createRagPipeline(client, options) {
|
|
389
|
+
const { indexId } = options;
|
|
390
|
+
return {
|
|
391
|
+
indexId,
|
|
392
|
+
ingestText(params) {
|
|
393
|
+
return client.shift.documents.create(indexId, params);
|
|
394
|
+
},
|
|
395
|
+
ingestFile(params) {
|
|
396
|
+
return client.shift.documents.upload(indexId, params);
|
|
397
|
+
},
|
|
398
|
+
search(params) {
|
|
399
|
+
return client.shift.search(indexId, params);
|
|
400
|
+
},
|
|
401
|
+
async retrieve(params) {
|
|
402
|
+
const { format: formatOpts, ...searchParams } = params;
|
|
403
|
+
const { results } = await client.shift.search(indexId, searchParams);
|
|
404
|
+
const context = formatRetrievalContext(results, formatOpts ?? {});
|
|
405
|
+
return { results, context };
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// src/index.ts
|
|
411
|
+
var Ragable = class {
|
|
412
|
+
constructor(options) {
|
|
413
|
+
__publicField(this, "shift");
|
|
414
|
+
__publicField(this, "agents");
|
|
415
|
+
__publicField(this, "infrastructure");
|
|
416
|
+
const client = new RagableRequestClient(options);
|
|
417
|
+
this.shift = new ShiftClient(client);
|
|
418
|
+
this.agents = new AgentsClient(client);
|
|
419
|
+
this.infrastructure = {
|
|
420
|
+
shift: this.shift
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
function createClient(options) {
|
|
425
|
+
return new Ragable(options);
|
|
426
|
+
}
|
|
255
427
|
// Annotate the CommonJS export names for ESM import in node:
|
|
256
428
|
0 && (module.exports = {
|
|
429
|
+
AgentsClient,
|
|
257
430
|
Ragable,
|
|
258
431
|
RagableError,
|
|
259
|
-
|
|
432
|
+
RagableRequestClient,
|
|
433
|
+
ShiftClient,
|
|
434
|
+
createClient,
|
|
435
|
+
createRagPipeline,
|
|
436
|
+
extractErrorMessage,
|
|
437
|
+
formatRetrievalContext
|
|
260
438
|
});
|
|
261
439
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export interface RagableClientOptions {\n apiKey: string;\n baseUrl?: string;\n fetch?: typeof fetch;\n headers?: HeadersInit;\n}\n\nexport interface ShiftIndex {\n id: string;\n name: string;\n description: string | null;\n dimensions: number;\n embeddingModel: string;\n status: string;\n entryCount?: number;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface ShiftEntry {\n id: string;\n content: string;\n metadata: unknown;\n chunkIndex: number;\n createdAt: string;\n}\n\nexport interface ShiftSearchResult {\n content: string;\n score: number;\n metadata: unknown;\n}\n\nexport interface ShiftCreateIndexParams {\n name: string;\n description?: string;\n dimensions?: number;\n embeddingModel?: string;\n}\n\nexport interface ShiftUpdateIndexParams {\n name?: string;\n description?: string;\n}\n\nexport interface ShiftAddDocumentParams {\n content: string;\n metadata?: Record<string, unknown>;\n chunkSize?: number;\n chunkOverlap?: number;\n}\n\nexport type ShiftUploadableFile = Blob | ArrayBuffer | Uint8Array;\n\nexport interface ShiftUploadFileParams {\n file: ShiftUploadableFile;\n fileName?: string;\n contentType?: string;\n metadata?: Record<string, unknown>;\n chunkSize?: number;\n chunkOverlap?: number;\n}\n\nexport interface ShiftListEntriesParams {\n take?: number;\n skip?: number;\n}\n\nexport interface ShiftSearchParams {\n query: string;\n topK?: number;\n}\n\nexport interface ShiftIngestResponse {\n chunksCreated: number;\n entries: string[];\n extractedText?: string;\n message?: string;\n}\n\nexport interface ShiftListEntriesResponse {\n entries: ShiftEntry[];\n total: number;\n}\n\nexport class RagableError extends Error {\n readonly status: number;\n readonly body: unknown;\n\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = \"RagableError\";\n this.status = status;\n this.body = body;\n }\n}\n\ntype RequestOptions = Omit<RequestInit, \"body\"> & {\n body?: unknown;\n};\n\nclass RagableRequestClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof fetch;\n private readonly defaultHeaders: HeadersInit | undefined;\n\n constructor(options: RagableClientOptions) {\n this.apiKey = options.apiKey;\n this.baseUrl = options.baseUrl ?? \"http://localhost:8080/api\";\n this.fetchImpl = options.fetch ?? fetch;\n this.defaultHeaders = options.headers;\n }\n\n async request<T>(path: string, options: RequestOptions = {}): Promise<T> {\n const headers = new Headers(this.defaultHeaders);\n headers.set(\"Authorization\", `Bearer ${this.apiKey}`);\n\n let body = options.body;\n if (body !== undefined && !isBodyInit(body)) {\n headers.set(\"Content-Type\", \"application/json\");\n body = JSON.stringify(body);\n }\n\n const response = await this.fetchImpl(this.toUrl(path), {\n ...options,\n headers,\n body: body as BodyInit | undefined,\n });\n\n const payload = await this.parseResponseBody(response);\n if (!response.ok) {\n const message = extractErrorMessage(payload, response.statusText);\n throw new RagableError(message, response.status, payload);\n }\n\n return payload as T;\n }\n\n private toUrl(path: string) {\n const normalizedBase = this.baseUrl.replace(/\\/+$/, \"\");\n const normalizedPath = path.startsWith(\"/\") ? path : `/${path}`;\n return `${normalizedBase}${normalizedPath}`;\n }\n\n private async parseResponseBody(response: Response): Promise<unknown> {\n if (response.status === 204) {\n return null;\n }\n\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (contentType.includes(\"application/json\")) {\n return response.json();\n }\n\n return response.text();\n }\n}\n\nclass ShiftClient {\n readonly indexes: {\n list: () => Promise<{ indexes: ShiftIndex[] }>;\n create: (params: ShiftCreateIndexParams) => Promise<ShiftIndex>;\n get: (indexId: string) => Promise<ShiftIndex>;\n update: (indexId: string, params: ShiftUpdateIndexParams) => Promise<ShiftIndex>;\n delete: (indexId: string) => Promise<{ success: true }>;\n };\n\n readonly documents: {\n create: (\n indexId: string,\n params: ShiftAddDocumentParams,\n ) => Promise<ShiftIngestResponse>;\n upload: (\n indexId: string,\n params: ShiftUploadFileParams,\n ) => Promise<ShiftIngestResponse>;\n };\n\n readonly entries: {\n list: (\n indexId: string,\n params?: ShiftListEntriesParams,\n ) => Promise<ShiftListEntriesResponse>;\n delete: (indexId: string, entryId: string) => Promise<{ success: true }>;\n };\n\n constructor(private readonly client: RagableRequestClient) {\n this.indexes = {\n list: async () => {\n return this.client.request<{ indexes: ShiftIndex[] }>(\"/v1/shift/indexes\");\n },\n create: async (params) => {\n return this.client.request<ShiftIndex>(\"/v1/shift/indexes\", {\n method: \"POST\",\n body: params,\n });\n },\n get: async (indexId) => {\n return this.client.request<ShiftIndex>(`/v1/shift/indexes/${indexId}`);\n },\n update: async (indexId, params) => {\n return this.client.request<ShiftIndex>(`/v1/shift/indexes/${indexId}`, {\n method: \"PUT\",\n body: params,\n });\n },\n delete: async (indexId) => {\n return this.client.request<{ success: true }>(\n `/v1/shift/indexes/${indexId}`,\n {\n method: \"DELETE\",\n },\n );\n },\n };\n\n this.documents = {\n create: async (indexId, params) => {\n return this.client.request<ShiftIngestResponse>(\n `/v1/shift/indexes/${indexId}/documents`,\n {\n method: \"POST\",\n body: params,\n },\n );\n },\n upload: async (indexId, params) => {\n const formData = new FormData();\n const fileName = resolveUploadFileName(params);\n const contentType = resolveUploadContentType(params);\n const file = normalizeUploadFile(params.file, contentType);\n\n formData.set(\"file\", file, fileName);\n\n if (params.metadata) {\n formData.set(\"metadata\", JSON.stringify(params.metadata));\n }\n if (typeof params.chunkSize === \"number\") {\n formData.set(\"chunkSize\", String(params.chunkSize));\n }\n if (typeof params.chunkOverlap === \"number\") {\n formData.set(\"chunkOverlap\", String(params.chunkOverlap));\n }\n\n return this.client.request<ShiftIngestResponse>(\n `/v1/shift/indexes/${indexId}/files`,\n {\n method: \"POST\",\n body: formData,\n },\n );\n },\n };\n\n this.entries = {\n list: async (indexId, params = {}) => {\n const search = new URLSearchParams();\n if (typeof params.take === \"number\") {\n search.set(\"take\", String(params.take));\n }\n if (typeof params.skip === \"number\") {\n search.set(\"skip\", String(params.skip));\n }\n\n const suffix = search.size > 0 ? `?${search.toString()}` : \"\";\n return this.client.request<ShiftListEntriesResponse>(\n `/v1/shift/indexes/${indexId}/entries${suffix}`,\n );\n },\n delete: async (indexId, entryId) => {\n return this.client.request<{ success: true }>(\n `/v1/shift/indexes/${indexId}/entries/${entryId}`,\n {\n method: \"DELETE\",\n },\n );\n },\n };\n }\n\n async search(indexId: string, params: ShiftSearchParams) {\n return this.client.request<{ results: ShiftSearchResult[] }>(\n `/v1/shift/indexes/${indexId}/search`,\n {\n method: \"POST\",\n body: params,\n },\n );\n }\n}\n\nexport class Ragable {\n readonly shift: ShiftClient;\n readonly infrastructure: {\n shift: ShiftClient;\n };\n\n constructor(options: RagableClientOptions) {\n const client = new RagableRequestClient(options);\n this.shift = new ShiftClient(client);\n this.infrastructure = {\n shift: this.shift,\n };\n }\n}\n\nexport function createClient(options: RagableClientOptions) {\n return new Ragable(options);\n}\n\nfunction extractErrorMessage(payload: unknown, fallback: string) {\n if (payload && typeof payload === \"object\") {\n if (\"error\" in payload && typeof payload.error === \"string\") {\n return payload.error;\n }\n if (\"message\" in payload && typeof payload.message === \"string\") {\n return payload.message;\n }\n }\n\n if (typeof payload === \"string\" && payload.length > 0) {\n return payload;\n }\n\n return fallback || \"Request failed\";\n}\n\nfunction resolveUploadFileName(params: ShiftUploadFileParams) {\n if (params.fileName) {\n return params.fileName;\n }\n\n if (isNamedBlob(params.file)) {\n return params.file.name;\n }\n\n return \"upload.bin\";\n}\n\nfunction resolveUploadContentType(params: ShiftUploadFileParams) {\n if (params.contentType) {\n return params.contentType;\n }\n\n if (params.file instanceof Blob && params.file.type) {\n return params.file.type;\n }\n\n return \"application/octet-stream\";\n}\n\nfunction normalizeUploadFile(file: ShiftUploadableFile, contentType: string) {\n if (file instanceof Blob) {\n return file;\n }\n\n if (file instanceof Uint8Array) {\n return new Blob([toArrayBuffer(file)], { type: contentType });\n }\n\n return new Blob([file], { type: contentType });\n}\n\nfunction isNamedBlob(value: ShiftUploadableFile): value is Blob & { name: string } {\n return value instanceof Blob && \"name\" in value && typeof value.name === \"string\";\n}\n\nfunction isBodyInit(value: unknown): value is BodyInit {\n return (\n typeof value === \"string\" ||\n value instanceof Blob ||\n value instanceof FormData ||\n value instanceof URLSearchParams ||\n value instanceof ArrayBuffer ||\n ArrayBuffer.isView(value)\n );\n}\n\nfunction toArrayBuffer(value: Uint8Array) {\n const copy = new Uint8Array(value.byteLength);\n copy.set(value);\n return copy.buffer;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqFO,IAAM,eAAN,cAA2B,MAAM;AAAA,EAItC,YAAY,SAAiB,QAAgB,MAAe;AAC1D,UAAM,OAAO;AAJf,wBAAS;AACT,wBAAS;AAIP,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACd;AACF;AAMA,IAAM,uBAAN,MAA2B;AAAA,EAMzB,YAAY,SAA+B;AAL3C,wBAAiB;AACjB,wBAAiB;AACjB,wBAAiB;AACjB,wBAAiB;AAGf,SAAK,SAAS,QAAQ;AACtB,SAAK,UAAU,QAAQ,WAAW;AAClC,SAAK,YAAY,QAAQ,SAAS;AAClC,SAAK,iBAAiB,QAAQ;AAAA,EAChC;AAAA,EAEA,MAAM,QAAW,MAAc,UAA0B,CAAC,GAAe;AACvE,UAAM,UAAU,IAAI,QAAQ,KAAK,cAAc;AAC/C,YAAQ,IAAI,iBAAiB,UAAU,KAAK,MAAM,EAAE;AAEpD,Q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+
{"version":3,"sources":["../src/index.ts","../src/request-client.ts","../src/shift.ts","../src/agents.ts","../src/rag.ts"],"sourcesContent":["export type { RagableClientOptions, RequestOptions } from \"./request-client\";\nexport {\n extractErrorMessage,\n RagableError,\n RagableRequestClient,\n} from \"./request-client\";\n\nexport type {\n ShiftAddDocumentParams,\n ShiftCreateIndexParams,\n ShiftEntry,\n ShiftIndex,\n ShiftIngestResponse,\n ShiftListEntriesParams,\n ShiftListEntriesResponse,\n ShiftSearchParams,\n ShiftSearchResult,\n ShiftUpdateIndexParams,\n ShiftUploadableFile,\n ShiftUploadFileParams,\n} from \"./shift\";\nexport { ShiftClient } from \"./shift\";\n\nexport type {\n AgentChatMessage,\n AgentChatParams,\n AgentChatResult,\n AgentStreamEvent,\n AgentSummary,\n} from \"./agents\";\nexport { AgentsClient } from \"./agents\";\n\nexport type {\n FormatContextOptions,\n RagClientForPipeline,\n RagPipeline,\n RagPipelineOptions,\n RetrieveParams,\n} from \"./rag\";\nexport { createRagPipeline, formatRetrievalContext } from \"./rag\";\n\nimport { AgentsClient } from \"./agents\";\nimport {\n RagableRequestClient,\n type RagableClientOptions,\n} from \"./request-client\";\nimport { ShiftClient } from \"./shift\";\n\nexport class Ragable {\n readonly shift: ShiftClient;\n readonly agents: AgentsClient;\n readonly infrastructure: {\n shift: ShiftClient;\n };\n\n constructor(options: RagableClientOptions) {\n const client = new RagableRequestClient(options);\n this.shift = new ShiftClient(client);\n this.agents = new AgentsClient(client);\n this.infrastructure = {\n shift: this.shift,\n };\n }\n}\n\nexport function createClient(options: RagableClientOptions) {\n return new Ragable(options);\n}\n","export interface RagableClientOptions {\n apiKey: string;\n baseUrl?: string;\n fetch?: typeof fetch;\n headers?: HeadersInit;\n}\n\nexport type RequestOptions = Omit<RequestInit, \"body\"> & {\n body?: unknown;\n};\n\nexport class RagableError extends Error {\n readonly status: number;\n readonly body: unknown;\n\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = \"RagableError\";\n this.status = status;\n this.body = body;\n }\n}\n\nexport function extractErrorMessage(payload: unknown, fallback: string) {\n if (payload && typeof payload === \"object\") {\n if (\"error\" in payload && typeof payload.error === \"string\") {\n return payload.error;\n }\n if (\"message\" in payload && typeof payload.message === \"string\") {\n return payload.message;\n }\n }\n\n if (typeof payload === \"string\" && payload.length > 0) {\n return payload;\n }\n\n return fallback || \"Request failed\";\n}\n\nexport class RagableRequestClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof fetch;\n private readonly defaultHeaders: HeadersInit | undefined;\n\n constructor(options: RagableClientOptions) {\n this.apiKey = options.apiKey;\n this.baseUrl = options.baseUrl ?? \"http://localhost:8080/api\";\n this.fetchImpl = options.fetch ?? fetch;\n this.defaultHeaders = options.headers;\n }\n\n toUrl(path: string) {\n const normalizedBase = this.baseUrl.replace(/\\/+$/, \"\");\n const normalizedPath = path.startsWith(\"/\") ? path : `/${path}`;\n return `${normalizedBase}${normalizedPath}`;\n }\n\n async request<T>(path: string, options: RequestOptions = {}): Promise<T> {\n const response = await this.rawFetch(path, options);\n const payload = await this.parseResponseBody(response);\n if (!response.ok) {\n const message = extractErrorMessage(payload, response.statusText);\n throw new RagableError(message, response.status, payload);\n }\n\n return payload as T;\n }\n\n /**\n * Low-level fetch with API key and JSON body encoding. Caller handles status and body.\n */\n async rawFetch(path: string, options: RequestOptions = {}): Promise<Response> {\n const headers = new Headers(this.defaultHeaders);\n headers.set(\"Authorization\", `Bearer ${this.apiKey}`);\n\n let body = options.body;\n if (body !== undefined && !isBodyInit(body)) {\n headers.set(\"Content-Type\", \"application/json\");\n body = JSON.stringify(body);\n }\n\n return this.fetchImpl(this.toUrl(path), {\n ...options,\n headers,\n body: body as BodyInit | undefined,\n });\n }\n\n private async parseResponseBody(response: Response): Promise<unknown> {\n if (response.status === 204) {\n return null;\n }\n\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (contentType.includes(\"application/json\")) {\n return response.json();\n }\n\n return response.text();\n }\n}\n\nexport function isBodyInit(value: unknown): value is BodyInit {\n return (\n typeof value === \"string\" ||\n value instanceof Blob ||\n value instanceof FormData ||\n value instanceof URLSearchParams ||\n value instanceof ArrayBuffer ||\n ArrayBuffer.isView(value)\n );\n}\n","import { RagableRequestClient } from \"./request-client\";\n\nexport interface ShiftIndex {\n id: string;\n name: string;\n description: string | null;\n dimensions: number;\n embeddingModel: string;\n status: string;\n entryCount?: number;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface ShiftEntry {\n id: string;\n content: string;\n metadata: unknown;\n chunkIndex: number;\n createdAt: string;\n}\n\nexport interface ShiftSearchResult {\n content: string;\n score: number;\n metadata: unknown;\n}\n\nexport interface ShiftCreateIndexParams {\n name: string;\n description?: string;\n dimensions?: number;\n embeddingModel?: string;\n}\n\nexport interface ShiftUpdateIndexParams {\n name?: string;\n description?: string;\n}\n\nexport interface ShiftAddDocumentParams {\n content: string;\n metadata?: Record<string, unknown>;\n chunkSize?: number;\n chunkOverlap?: number;\n}\n\nexport type ShiftUploadableFile = Blob | ArrayBuffer | Uint8Array;\n\nexport interface ShiftUploadFileParams {\n file: ShiftUploadableFile;\n fileName?: string;\n contentType?: string;\n metadata?: Record<string, unknown>;\n chunkSize?: number;\n chunkOverlap?: number;\n}\n\nexport interface ShiftListEntriesParams {\n take?: number;\n skip?: number;\n}\n\nexport interface ShiftSearchParams {\n query: string;\n topK?: number;\n}\n\nexport interface ShiftIngestResponse {\n chunksCreated: number;\n entries: string[];\n extractedText?: string;\n message?: string;\n}\n\nexport interface ShiftListEntriesResponse {\n entries: ShiftEntry[];\n total: number;\n}\n\nexport class ShiftClient {\n readonly indexes: {\n list: () => Promise<{ indexes: ShiftIndex[] }>;\n create: (params: ShiftCreateIndexParams) => Promise<ShiftIndex>;\n get: (indexId: string) => Promise<ShiftIndex>;\n update: (indexId: string, params: ShiftUpdateIndexParams) => Promise<ShiftIndex>;\n delete: (indexId: string) => Promise<{ success: true }>;\n };\n\n readonly documents: {\n create: (\n indexId: string,\n params: ShiftAddDocumentParams,\n ) => Promise<ShiftIngestResponse>;\n upload: (\n indexId: string,\n params: ShiftUploadFileParams,\n ) => Promise<ShiftIngestResponse>;\n };\n\n readonly entries: {\n list: (\n indexId: string,\n params?: ShiftListEntriesParams,\n ) => Promise<ShiftListEntriesResponse>;\n delete: (indexId: string, entryId: string) => Promise<{ success: true }>;\n };\n\n constructor(private readonly client: RagableRequestClient) {\n this.indexes = {\n list: async () => {\n return this.client.request<{ indexes: ShiftIndex[] }>(\"/v1/shift/indexes\");\n },\n create: async (params) => {\n return this.client.request<ShiftIndex>(\"/v1/shift/indexes\", {\n method: \"POST\",\n body: params,\n });\n },\n get: async (indexId) => {\n return this.client.request<ShiftIndex>(`/v1/shift/indexes/${indexId}`);\n },\n update: async (indexId, params) => {\n return this.client.request<ShiftIndex>(`/v1/shift/indexes/${indexId}`, {\n method: \"PUT\",\n body: params,\n });\n },\n delete: async (indexId) => {\n return this.client.request<{ success: true }>(\n `/v1/shift/indexes/${indexId}`,\n {\n method: \"DELETE\",\n },\n );\n },\n };\n\n this.documents = {\n create: async (indexId, params) => {\n return this.client.request<ShiftIngestResponse>(\n `/v1/shift/indexes/${indexId}/documents`,\n {\n method: \"POST\",\n body: params,\n },\n );\n },\n upload: async (indexId, params) => {\n const formData = new FormData();\n const fileName = resolveUploadFileName(params);\n const contentType = resolveUploadContentType(params);\n const file = normalizeUploadFile(params.file, contentType);\n\n formData.set(\"file\", file, fileName);\n\n if (params.metadata) {\n formData.set(\"metadata\", JSON.stringify(params.metadata));\n }\n if (typeof params.chunkSize === \"number\") {\n formData.set(\"chunkSize\", String(params.chunkSize));\n }\n if (typeof params.chunkOverlap === \"number\") {\n formData.set(\"chunkOverlap\", String(params.chunkOverlap));\n }\n\n return this.client.request<ShiftIngestResponse>(\n `/v1/shift/indexes/${indexId}/files`,\n {\n method: \"POST\",\n body: formData,\n },\n );\n },\n };\n\n this.entries = {\n list: async (indexId, params = {}) => {\n const search = new URLSearchParams();\n if (typeof params.take === \"number\") {\n search.set(\"take\", String(params.take));\n }\n if (typeof params.skip === \"number\") {\n search.set(\"skip\", String(params.skip));\n }\n\n const suffix = search.size > 0 ? `?${search.toString()}` : \"\";\n return this.client.request<ShiftListEntriesResponse>(\n `/v1/shift/indexes/${indexId}/entries${suffix}`,\n );\n },\n delete: async (indexId, entryId) => {\n return this.client.request<{ success: true }>(\n `/v1/shift/indexes/${indexId}/entries/${entryId}`,\n {\n method: \"DELETE\",\n },\n );\n },\n };\n }\n\n async search(indexId: string, params: ShiftSearchParams) {\n return this.client.request<{ results: ShiftSearchResult[] }>(\n `/v1/shift/indexes/${indexId}/search`,\n {\n method: \"POST\",\n body: params,\n },\n );\n }\n}\n\nfunction resolveUploadFileName(params: ShiftUploadFileParams) {\n if (params.fileName) {\n return params.fileName;\n }\n\n if (isNamedBlob(params.file)) {\n return params.file.name;\n }\n\n return \"upload.bin\";\n}\n\nfunction resolveUploadContentType(params: ShiftUploadFileParams) {\n if (params.contentType) {\n return params.contentType;\n }\n\n if (params.file instanceof Blob && params.file.type) {\n return params.file.type;\n }\n\n return \"application/octet-stream\";\n}\n\nfunction normalizeUploadFile(file: ShiftUploadableFile, contentType: string) {\n if (file instanceof Blob) {\n return file;\n }\n\n if (file instanceof Uint8Array) {\n return new Blob([toArrayBuffer(file)], { type: contentType });\n }\n\n return new Blob([file], { type: contentType });\n}\n\nfunction isNamedBlob(value: ShiftUploadableFile): value is Blob & { name: string } {\n return value instanceof Blob && \"name\" in value && typeof value.name === \"string\";\n}\n\nfunction toArrayBuffer(value: Uint8Array) {\n const copy = new Uint8Array(value.byteLength);\n copy.set(value);\n return copy.buffer;\n}\n","import {\n extractErrorMessage,\n RagableError,\n RagableRequestClient,\n} from \"./request-client\";\n\nexport interface AgentSummary {\n id: string;\n name: string;\n description: string | null;\n active: boolean;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface AgentChatMessage {\n role: \"user\" | \"assistant\";\n content: string;\n}\n\nexport interface AgentChatParams {\n message: string;\n history?: AgentChatMessage[];\n}\n\n/** Mirrors backend ExecutionResult JSON shape (traces are opaque in the SDK). */\nexport interface AgentChatResult {\n response: string;\n traces: unknown[];\n totalDurationMs: number;\n httpResponse?: unknown;\n}\n\n/**\n * Loose SSE event from POST /v1/agents/:id/chat/stream — narrows with `type` at runtime.\n */\nexport type AgentStreamEvent = Record<string, unknown> & { type: string };\n\nexport class AgentsClient {\n constructor(private readonly client: RagableRequestClient) {}\n\n async list(): Promise<{ agents: AgentSummary[] }> {\n return this.client.request(\"/v1/agents\");\n }\n\n async get(agentId: string): Promise<AgentSummary> {\n return this.client.request(`/v1/agents/${agentId}`);\n }\n\n async chat(\n agentId: string,\n params: AgentChatParams,\n ): Promise<AgentChatResult> {\n return this.client.request<AgentChatResult>(`/v1/agents/${agentId}/chat`, {\n method: \"POST\",\n body: {\n message: params.message,\n ...(params.history !== undefined ? { history: params.history } : {}),\n },\n });\n }\n\n /**\n * Stream agent execution as SSE (`data: {json}` lines). Yields parsed JSON objects.\n */\n async *chatStream(\n agentId: string,\n params: AgentChatParams,\n ): AsyncGenerator<AgentStreamEvent, void, undefined> {\n const response = await this.client.rawFetch(\n `/v1/agents/${agentId}/chat/stream`,\n {\n method: \"POST\",\n body: {\n message: params.message,\n ...(params.history !== undefined ? { history: params.history } : {}),\n },\n },\n );\n\n if (!response.ok) {\n const payload = await parseMaybeJsonBody(response);\n const message = extractErrorMessage(payload, response.statusText);\n throw new RagableError(message, response.status, payload);\n }\n\n const body = response.body;\n if (!body) {\n return;\n }\n\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n buffer += decoder.decode(value, { stream: true });\n\n let boundary = buffer.indexOf(\"\\n\\n\");\n while (boundary !== -1) {\n const block = buffer.slice(0, boundary);\n buffer = buffer.slice(boundary + 2);\n for (const line of block.split(\"\\n\")) {\n const evt = parseSseDataLine(line);\n if (evt) {\n yield evt;\n }\n }\n boundary = buffer.indexOf(\"\\n\\n\");\n }\n }\n\n if (buffer.trim().length > 0) {\n for (const line of buffer.split(\"\\n\")) {\n const evt = parseSseDataLine(line);\n if (evt) {\n yield evt;\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n\nasync function parseMaybeJsonBody(response: Response): Promise<unknown> {\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (contentType.includes(\"application/json\")) {\n try {\n return await response.json();\n } catch {\n return null;\n }\n }\n try {\n return await response.text();\n } catch {\n return null;\n }\n}\n\nfunction parseSseDataLine(line: string): AgentStreamEvent | null {\n const dataPrefix = \"data: \";\n if (!line.startsWith(dataPrefix)) {\n return null;\n }\n const json = line.slice(dataPrefix.length).trim();\n if (json.length === 0 || json === \"[DONE]\") {\n return null;\n }\n try {\n return JSON.parse(json) as AgentStreamEvent;\n } catch {\n return null;\n }\n}\n","import type {\n ShiftAddDocumentParams,\n ShiftIngestResponse,\n ShiftSearchParams,\n ShiftSearchResult,\n ShiftUploadFileParams,\n} from \"./shift\";\n\n/** Minimal client surface for {@link createRagPipeline} (implemented by {@link Ragable}). */\nexport interface RagClientForPipeline {\n shift: {\n documents: {\n create: (\n indexId: string,\n params: ShiftAddDocumentParams,\n ) => Promise<ShiftIngestResponse>;\n upload: (\n indexId: string,\n params: ShiftUploadFileParams,\n ) => Promise<ShiftIngestResponse>;\n };\n search: (\n indexId: string,\n params: ShiftSearchParams,\n ) => Promise<{ results: ShiftSearchResult[] }>;\n };\n}\n\nexport interface FormatContextOptions {\n /** Prepended before numbered passages (default: \"Relevant passages:\\\\n\") */\n header?: string;\n /** Joiner between passages (default: \"\\\\n\\\\n\") */\n separator?: string;\n /** Omit results with similarity score below this (default: no filter) */\n minScore?: number;\n /** Truncate total context string to this UTF-16 length (default: no limit) */\n maxChars?: number;\n /** Include similarity score in each block (default: false) */\n includeScores?: boolean;\n}\n\nexport interface RagPipelineOptions {\n indexId: string;\n}\n\nexport type RetrieveParams = ShiftSearchParams & {\n format?: FormatContextOptions;\n};\n\nexport interface RagPipeline {\n readonly indexId: string;\n ingestText(params: ShiftAddDocumentParams): Promise<ShiftIngestResponse>;\n ingestFile(params: ShiftUploadFileParams): Promise<ShiftIngestResponse>;\n search(params: ShiftSearchParams): Promise<{ results: ShiftSearchResult[] }>;\n retrieve(params: RetrieveParams): Promise<{\n results: ShiftSearchResult[];\n context: string;\n }>;\n}\n\n/**\n * Turn vector search hits into a single block of text for system prompts or RAG user messages.\n */\nexport function formatRetrievalContext(\n results: ShiftSearchResult[],\n options: FormatContextOptions = {},\n): string {\n const header = options.header ?? \"Relevant passages:\\n\";\n const separator = options.separator ?? \"\\n\\n\";\n const minScore = options.minScore;\n\n let filtered = results;\n if (typeof minScore === \"number\") {\n filtered = results.filter((r) => r.score >= minScore);\n }\n\n const blocks = filtered.map((r, i) => {\n const scoreSuffix =\n options.includeScores === true ? ` (score: ${r.score.toFixed(4)})` : \"\";\n return `[${i + 1}]${scoreSuffix}\\n${r.content.trim()}`;\n });\n\n let text = (blocks.length > 0 ? header : \"\") + blocks.join(separator);\n\n if (typeof options.maxChars === \"number\" && text.length > options.maxChars) {\n text = text.slice(0, options.maxChars).trimEnd() + \"\\n…\";\n }\n\n return text;\n}\n\n/**\n * High-level RAG helpers bound to one Shift index: ingest, search, retrieve with prompt-ready context.\n */\nexport function createRagPipeline(\n client: RagClientForPipeline,\n options: RagPipelineOptions,\n): RagPipeline {\n const { indexId } = options;\n\n return {\n indexId,\n\n ingestText(params) {\n return client.shift.documents.create(indexId, params);\n },\n\n ingestFile(params) {\n return client.shift.documents.upload(indexId, params);\n },\n\n search(params) {\n return client.shift.search(indexId, params);\n },\n\n async retrieve(params) {\n const { format: formatOpts, ...searchParams } = params;\n const { results } = await client.shift.search(indexId, searchParams);\n const context = formatRetrievalContext(results, formatOpts ?? {});\n return { results, context };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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EA,WAAW,QAAQ;AACjB,aAAO,OAAO,MAAM,UAAU,OAAO,SAAS,MAAM;AAAA,IACtD;AAAA,IAEA,WAAW,QAAQ;AACjB,aAAO,OAAO,MAAM,UAAU,OAAO,SAAS,MAAM;AAAA,IACtD;AAAA,IAEA,OAAO,QAAQ;AACb,aAAO,OAAO,MAAM,OAAO,SAAS,MAAM;AAAA,IAC5C;AAAA,IAEA,MAAM,SAAS,QAAQ;AACrB,YAAM,EAAE,QAAQ,YAAY,GAAG,aAAa,IAAI;AAChD,YAAM,EAAE,QAAQ,IAAI,MAAM,OAAO,MAAM,OAAO,SAAS,YAAY;AACnE,YAAM,UAAU,uBAAuB,SAAS,cAAc,CAAC,CAAC;AAChE,aAAO,EAAE,SAAS,QAAQ;AAAA,IAC5B;AAAA,EACF;AACF;;;AJ1EO,IAAM,UAAN,MAAc;AAAA,EAOnB,YAAY,SAA+B;AAN3C,wBAAS;AACT,wBAAS;AACT,wBAAS;AAKP,UAAM,SAAS,IAAI,qBAAqB,OAAO;AAC/C,SAAK,QAAQ,IAAI,YAAY,MAAM;AACnC,SAAK,SAAS,IAAI,aAAa,MAAM;AACrC,SAAK,iBAAiB;AAAA,MACpB,OAAO,KAAK;AAAA,IACd;AAAA,EACF;AACF;AAEO,SAAS,aAAa,SAA+B;AAC1D,SAAO,IAAI,QAAQ,OAAO;AAC5B;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
|
|
5
|
-
// src/
|
|
5
|
+
// src/request-client.ts
|
|
6
6
|
var RagableError = class extends Error {
|
|
7
7
|
constructor(message, status, body) {
|
|
8
8
|
super(message);
|
|
@@ -13,6 +13,20 @@ var RagableError = class extends Error {
|
|
|
13
13
|
this.body = body;
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
+
function extractErrorMessage(payload, fallback) {
|
|
17
|
+
if (payload && typeof payload === "object") {
|
|
18
|
+
if ("error" in payload && typeof payload.error === "string") {
|
|
19
|
+
return payload.error;
|
|
20
|
+
}
|
|
21
|
+
if ("message" in payload && typeof payload.message === "string") {
|
|
22
|
+
return payload.message;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (typeof payload === "string" && payload.length > 0) {
|
|
26
|
+
return payload;
|
|
27
|
+
}
|
|
28
|
+
return fallback || "Request failed";
|
|
29
|
+
}
|
|
16
30
|
var RagableRequestClient = class {
|
|
17
31
|
constructor(options) {
|
|
18
32
|
__publicField(this, "apiKey");
|
|
@@ -24,7 +38,24 @@ var RagableRequestClient = class {
|
|
|
24
38
|
this.fetchImpl = options.fetch ?? fetch;
|
|
25
39
|
this.defaultHeaders = options.headers;
|
|
26
40
|
}
|
|
41
|
+
toUrl(path) {
|
|
42
|
+
const normalizedBase = this.baseUrl.replace(/\/+$/, "");
|
|
43
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
44
|
+
return `${normalizedBase}${normalizedPath}`;
|
|
45
|
+
}
|
|
27
46
|
async request(path, options = {}) {
|
|
47
|
+
const response = await this.rawFetch(path, options);
|
|
48
|
+
const payload = await this.parseResponseBody(response);
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
const message = extractErrorMessage(payload, response.statusText);
|
|
51
|
+
throw new RagableError(message, response.status, payload);
|
|
52
|
+
}
|
|
53
|
+
return payload;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Low-level fetch with API key and JSON body encoding. Caller handles status and body.
|
|
57
|
+
*/
|
|
58
|
+
async rawFetch(path, options = {}) {
|
|
28
59
|
const headers = new Headers(this.defaultHeaders);
|
|
29
60
|
headers.set("Authorization", `Bearer ${this.apiKey}`);
|
|
30
61
|
let body = options.body;
|
|
@@ -32,22 +63,11 @@ var RagableRequestClient = class {
|
|
|
32
63
|
headers.set("Content-Type", "application/json");
|
|
33
64
|
body = JSON.stringify(body);
|
|
34
65
|
}
|
|
35
|
-
|
|
66
|
+
return this.fetchImpl(this.toUrl(path), {
|
|
36
67
|
...options,
|
|
37
68
|
headers,
|
|
38
69
|
body
|
|
39
70
|
});
|
|
40
|
-
const payload = await this.parseResponseBody(response);
|
|
41
|
-
if (!response.ok) {
|
|
42
|
-
const message = extractErrorMessage(payload, response.statusText);
|
|
43
|
-
throw new RagableError(message, response.status, payload);
|
|
44
|
-
}
|
|
45
|
-
return payload;
|
|
46
|
-
}
|
|
47
|
-
toUrl(path) {
|
|
48
|
-
const normalizedBase = this.baseUrl.replace(/\/+$/, "");
|
|
49
|
-
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
50
|
-
return `${normalizedBase}${normalizedPath}`;
|
|
51
71
|
}
|
|
52
72
|
async parseResponseBody(response) {
|
|
53
73
|
if (response.status === 204) {
|
|
@@ -60,6 +80,11 @@ var RagableRequestClient = class {
|
|
|
60
80
|
return response.text();
|
|
61
81
|
}
|
|
62
82
|
};
|
|
83
|
+
function isBodyInit(value) {
|
|
84
|
+
return typeof value === "string" || value instanceof Blob || value instanceof FormData || value instanceof URLSearchParams || value instanceof ArrayBuffer || ArrayBuffer.isView(value);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/shift.ts
|
|
63
88
|
var ShiftClient = class {
|
|
64
89
|
constructor(client) {
|
|
65
90
|
this.client = client;
|
|
@@ -162,34 +187,6 @@ var ShiftClient = class {
|
|
|
162
187
|
);
|
|
163
188
|
}
|
|
164
189
|
};
|
|
165
|
-
var Ragable = class {
|
|
166
|
-
constructor(options) {
|
|
167
|
-
__publicField(this, "shift");
|
|
168
|
-
__publicField(this, "infrastructure");
|
|
169
|
-
const client = new RagableRequestClient(options);
|
|
170
|
-
this.shift = new ShiftClient(client);
|
|
171
|
-
this.infrastructure = {
|
|
172
|
-
shift: this.shift
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
function createClient(options) {
|
|
177
|
-
return new Ragable(options);
|
|
178
|
-
}
|
|
179
|
-
function extractErrorMessage(payload, fallback) {
|
|
180
|
-
if (payload && typeof payload === "object") {
|
|
181
|
-
if ("error" in payload && typeof payload.error === "string") {
|
|
182
|
-
return payload.error;
|
|
183
|
-
}
|
|
184
|
-
if ("message" in payload && typeof payload.message === "string") {
|
|
185
|
-
return payload.message;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
if (typeof payload === "string" && payload.length > 0) {
|
|
189
|
-
return payload;
|
|
190
|
-
}
|
|
191
|
-
return fallback || "Request failed";
|
|
192
|
-
}
|
|
193
190
|
function resolveUploadFileName(params) {
|
|
194
191
|
if (params.fileName) {
|
|
195
192
|
return params.fileName;
|
|
@@ -220,17 +217,190 @@ function normalizeUploadFile(file, contentType) {
|
|
|
220
217
|
function isNamedBlob(value) {
|
|
221
218
|
return value instanceof Blob && "name" in value && typeof value.name === "string";
|
|
222
219
|
}
|
|
223
|
-
function isBodyInit(value) {
|
|
224
|
-
return typeof value === "string" || value instanceof Blob || value instanceof FormData || value instanceof URLSearchParams || value instanceof ArrayBuffer || ArrayBuffer.isView(value);
|
|
225
|
-
}
|
|
226
220
|
function toArrayBuffer(value) {
|
|
227
221
|
const copy = new Uint8Array(value.byteLength);
|
|
228
222
|
copy.set(value);
|
|
229
223
|
return copy.buffer;
|
|
230
224
|
}
|
|
225
|
+
|
|
226
|
+
// src/agents.ts
|
|
227
|
+
var AgentsClient = class {
|
|
228
|
+
constructor(client) {
|
|
229
|
+
this.client = client;
|
|
230
|
+
}
|
|
231
|
+
async list() {
|
|
232
|
+
return this.client.request("/v1/agents");
|
|
233
|
+
}
|
|
234
|
+
async get(agentId) {
|
|
235
|
+
return this.client.request(`/v1/agents/${agentId}`);
|
|
236
|
+
}
|
|
237
|
+
async chat(agentId, params) {
|
|
238
|
+
return this.client.request(`/v1/agents/${agentId}/chat`, {
|
|
239
|
+
method: "POST",
|
|
240
|
+
body: {
|
|
241
|
+
message: params.message,
|
|
242
|
+
...params.history !== void 0 ? { history: params.history } : {}
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Stream agent execution as SSE (`data: {json}` lines). Yields parsed JSON objects.
|
|
248
|
+
*/
|
|
249
|
+
async *chatStream(agentId, params) {
|
|
250
|
+
const response = await this.client.rawFetch(
|
|
251
|
+
`/v1/agents/${agentId}/chat/stream`,
|
|
252
|
+
{
|
|
253
|
+
method: "POST",
|
|
254
|
+
body: {
|
|
255
|
+
message: params.message,
|
|
256
|
+
...params.history !== void 0 ? { history: params.history } : {}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
);
|
|
260
|
+
if (!response.ok) {
|
|
261
|
+
const payload = await parseMaybeJsonBody(response);
|
|
262
|
+
const message = extractErrorMessage(payload, response.statusText);
|
|
263
|
+
throw new RagableError(message, response.status, payload);
|
|
264
|
+
}
|
|
265
|
+
const body = response.body;
|
|
266
|
+
if (!body) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const reader = body.getReader();
|
|
270
|
+
const decoder = new TextDecoder();
|
|
271
|
+
let buffer = "";
|
|
272
|
+
try {
|
|
273
|
+
while (true) {
|
|
274
|
+
const { done, value } = await reader.read();
|
|
275
|
+
if (done) {
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
buffer += decoder.decode(value, { stream: true });
|
|
279
|
+
let boundary = buffer.indexOf("\n\n");
|
|
280
|
+
while (boundary !== -1) {
|
|
281
|
+
const block = buffer.slice(0, boundary);
|
|
282
|
+
buffer = buffer.slice(boundary + 2);
|
|
283
|
+
for (const line of block.split("\n")) {
|
|
284
|
+
const evt = parseSseDataLine(line);
|
|
285
|
+
if (evt) {
|
|
286
|
+
yield evt;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
boundary = buffer.indexOf("\n\n");
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (buffer.trim().length > 0) {
|
|
293
|
+
for (const line of buffer.split("\n")) {
|
|
294
|
+
const evt = parseSseDataLine(line);
|
|
295
|
+
if (evt) {
|
|
296
|
+
yield evt;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
} finally {
|
|
301
|
+
reader.releaseLock();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
async function parseMaybeJsonBody(response) {
|
|
306
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
307
|
+
if (contentType.includes("application/json")) {
|
|
308
|
+
try {
|
|
309
|
+
return await response.json();
|
|
310
|
+
} catch {
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
try {
|
|
315
|
+
return await response.text();
|
|
316
|
+
} catch {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function parseSseDataLine(line) {
|
|
321
|
+
const dataPrefix = "data: ";
|
|
322
|
+
if (!line.startsWith(dataPrefix)) {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
const json = line.slice(dataPrefix.length).trim();
|
|
326
|
+
if (json.length === 0 || json === "[DONE]") {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
try {
|
|
330
|
+
return JSON.parse(json);
|
|
331
|
+
} catch {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// src/rag.ts
|
|
337
|
+
function formatRetrievalContext(results, options = {}) {
|
|
338
|
+
const header = options.header ?? "Relevant passages:\n";
|
|
339
|
+
const separator = options.separator ?? "\n\n";
|
|
340
|
+
const minScore = options.minScore;
|
|
341
|
+
let filtered = results;
|
|
342
|
+
if (typeof minScore === "number") {
|
|
343
|
+
filtered = results.filter((r) => r.score >= minScore);
|
|
344
|
+
}
|
|
345
|
+
const blocks = filtered.map((r, i) => {
|
|
346
|
+
const scoreSuffix = options.includeScores === true ? ` (score: ${r.score.toFixed(4)})` : "";
|
|
347
|
+
return `[${i + 1}]${scoreSuffix}
|
|
348
|
+
${r.content.trim()}`;
|
|
349
|
+
});
|
|
350
|
+
let text = (blocks.length > 0 ? header : "") + blocks.join(separator);
|
|
351
|
+
if (typeof options.maxChars === "number" && text.length > options.maxChars) {
|
|
352
|
+
text = text.slice(0, options.maxChars).trimEnd() + "\n\u2026";
|
|
353
|
+
}
|
|
354
|
+
return text;
|
|
355
|
+
}
|
|
356
|
+
function createRagPipeline(client, options) {
|
|
357
|
+
const { indexId } = options;
|
|
358
|
+
return {
|
|
359
|
+
indexId,
|
|
360
|
+
ingestText(params) {
|
|
361
|
+
return client.shift.documents.create(indexId, params);
|
|
362
|
+
},
|
|
363
|
+
ingestFile(params) {
|
|
364
|
+
return client.shift.documents.upload(indexId, params);
|
|
365
|
+
},
|
|
366
|
+
search(params) {
|
|
367
|
+
return client.shift.search(indexId, params);
|
|
368
|
+
},
|
|
369
|
+
async retrieve(params) {
|
|
370
|
+
const { format: formatOpts, ...searchParams } = params;
|
|
371
|
+
const { results } = await client.shift.search(indexId, searchParams);
|
|
372
|
+
const context = formatRetrievalContext(results, formatOpts ?? {});
|
|
373
|
+
return { results, context };
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// src/index.ts
|
|
379
|
+
var Ragable = class {
|
|
380
|
+
constructor(options) {
|
|
381
|
+
__publicField(this, "shift");
|
|
382
|
+
__publicField(this, "agents");
|
|
383
|
+
__publicField(this, "infrastructure");
|
|
384
|
+
const client = new RagableRequestClient(options);
|
|
385
|
+
this.shift = new ShiftClient(client);
|
|
386
|
+
this.agents = new AgentsClient(client);
|
|
387
|
+
this.infrastructure = {
|
|
388
|
+
shift: this.shift
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
function createClient(options) {
|
|
393
|
+
return new Ragable(options);
|
|
394
|
+
}
|
|
231
395
|
export {
|
|
396
|
+
AgentsClient,
|
|
232
397
|
Ragable,
|
|
233
398
|
RagableError,
|
|
234
|
-
|
|
399
|
+
RagableRequestClient,
|
|
400
|
+
ShiftClient,
|
|
401
|
+
createClient,
|
|
402
|
+
createRagPipeline,
|
|
403
|
+
extractErrorMessage,
|
|
404
|
+
formatRetrievalContext
|
|
235
405
|
};
|
|
236
406
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export interface RagableClientOptions {\n apiKey: string;\n baseUrl?: string;\n fetch?: typeof fetch;\n headers?: HeadersInit;\n}\n\nexport interface ShiftIndex {\n id: string;\n name: string;\n description: string | null;\n dimensions: number;\n embeddingModel: string;\n status: string;\n entryCount?: number;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface ShiftEntry {\n id: string;\n content: string;\n metadata: unknown;\n chunkIndex: number;\n createdAt: string;\n}\n\nexport interface ShiftSearchResult {\n content: string;\n score: number;\n metadata: unknown;\n}\n\nexport interface ShiftCreateIndexParams {\n name: string;\n description?: string;\n dimensions?: number;\n embeddingModel?: string;\n}\n\nexport interface ShiftUpdateIndexParams {\n name?: string;\n description?: string;\n}\n\nexport interface ShiftAddDocumentParams {\n content: string;\n metadata?: Record<string, unknown>;\n chunkSize?: number;\n chunkOverlap?: number;\n}\n\nexport type ShiftUploadableFile = Blob | ArrayBuffer | Uint8Array;\n\nexport interface ShiftUploadFileParams {\n file: ShiftUploadableFile;\n fileName?: string;\n contentType?: string;\n metadata?: Record<string, unknown>;\n chunkSize?: number;\n chunkOverlap?: number;\n}\n\nexport interface ShiftListEntriesParams {\n take?: number;\n skip?: number;\n}\n\nexport interface ShiftSearchParams {\n query: string;\n topK?: number;\n}\n\nexport interface ShiftIngestResponse {\n chunksCreated: number;\n entries: string[];\n extractedText?: string;\n message?: string;\n}\n\nexport interface ShiftListEntriesResponse {\n entries: ShiftEntry[];\n total: number;\n}\n\nexport class RagableError extends Error {\n readonly status: number;\n readonly body: unknown;\n\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = \"RagableError\";\n this.status = status;\n this.body = body;\n }\n}\n\ntype RequestOptions = Omit<RequestInit, \"body\"> & {\n body?: unknown;\n};\n\nclass RagableRequestClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof fetch;\n private readonly defaultHeaders: HeadersInit | undefined;\n\n constructor(options: RagableClientOptions) {\n this.apiKey = options.apiKey;\n this.baseUrl = options.baseUrl ?? \"http://localhost:8080/api\";\n this.fetchImpl = options.fetch ?? fetch;\n this.defaultHeaders = options.headers;\n }\n\n async request<T>(path: string, options: RequestOptions = {}): Promise<T> {\n const headers = new Headers(this.defaultHeaders);\n headers.set(\"Authorization\", `Bearer ${this.apiKey}`);\n\n let body = options.body;\n if (body !== undefined && !isBodyInit(body)) {\n headers.set(\"Content-Type\", \"application/json\");\n body = JSON.stringify(body);\n }\n\n const response = await this.fetchImpl(this.toUrl(path), {\n ...options,\n headers,\n body: body as BodyInit | undefined,\n });\n\n const payload = await this.parseResponseBody(response);\n if (!response.ok) {\n const message = extractErrorMessage(payload, response.statusText);\n throw new RagableError(message, response.status, payload);\n }\n\n return payload as T;\n }\n\n private toUrl(path: string) {\n const normalizedBase = this.baseUrl.replace(/\\/+$/, \"\");\n const normalizedPath = path.startsWith(\"/\") ? path : `/${path}`;\n return `${normalizedBase}${normalizedPath}`;\n }\n\n private async parseResponseBody(response: Response): Promise<unknown> {\n if (response.status === 204) {\n return null;\n }\n\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (contentType.includes(\"application/json\")) {\n return response.json();\n }\n\n return response.text();\n }\n}\n\nclass ShiftClient {\n readonly indexes: {\n list: () => Promise<{ indexes: ShiftIndex[] }>;\n create: (params: ShiftCreateIndexParams) => Promise<ShiftIndex>;\n get: (indexId: string) => Promise<ShiftIndex>;\n update: (indexId: string, params: ShiftUpdateIndexParams) => Promise<ShiftIndex>;\n delete: (indexId: string) => Promise<{ success: true }>;\n };\n\n readonly documents: {\n create: (\n indexId: string,\n params: ShiftAddDocumentParams,\n ) => Promise<ShiftIngestResponse>;\n upload: (\n indexId: string,\n params: ShiftUploadFileParams,\n ) => Promise<ShiftIngestResponse>;\n };\n\n readonly entries: {\n list: (\n indexId: string,\n params?: ShiftListEntriesParams,\n ) => Promise<ShiftListEntriesResponse>;\n delete: (indexId: string, entryId: string) => Promise<{ success: true }>;\n };\n\n constructor(private readonly client: RagableRequestClient) {\n this.indexes = {\n list: async () => {\n return this.client.request<{ indexes: ShiftIndex[] }>(\"/v1/shift/indexes\");\n },\n create: async (params) => {\n return this.client.request<ShiftIndex>(\"/v1/shift/indexes\", {\n method: \"POST\",\n body: params,\n });\n },\n get: async (indexId) => {\n return this.client.request<ShiftIndex>(`/v1/shift/indexes/${indexId}`);\n },\n update: async (indexId, params) => {\n return this.client.request<ShiftIndex>(`/v1/shift/indexes/${indexId}`, {\n method: \"PUT\",\n body: params,\n });\n },\n delete: async (indexId) => {\n return this.client.request<{ success: true }>(\n `/v1/shift/indexes/${indexId}`,\n {\n method: \"DELETE\",\n },\n );\n },\n };\n\n this.documents = {\n create: async (indexId, params) => {\n return this.client.request<ShiftIngestResponse>(\n `/v1/shift/indexes/${indexId}/documents`,\n {\n method: \"POST\",\n body: params,\n },\n );\n },\n upload: async (indexId, params) => {\n const formData = new FormData();\n const fileName = resolveUploadFileName(params);\n const contentType = resolveUploadContentType(params);\n const file = normalizeUploadFile(params.file, contentType);\n\n formData.set(\"file\", file, fileName);\n\n if (params.metadata) {\n formData.set(\"metadata\", JSON.stringify(params.metadata));\n }\n if (typeof params.chunkSize === \"number\") {\n formData.set(\"chunkSize\", String(params.chunkSize));\n }\n if (typeof params.chunkOverlap === \"number\") {\n formData.set(\"chunkOverlap\", String(params.chunkOverlap));\n }\n\n return this.client.request<ShiftIngestResponse>(\n `/v1/shift/indexes/${indexId}/files`,\n {\n method: \"POST\",\n body: formData,\n },\n );\n },\n };\n\n this.entries = {\n list: async (indexId, params = {}) => {\n const search = new URLSearchParams();\n if (typeof params.take === \"number\") {\n search.set(\"take\", String(params.take));\n }\n if (typeof params.skip === \"number\") {\n search.set(\"skip\", String(params.skip));\n }\n\n const suffix = search.size > 0 ? `?${search.toString()}` : \"\";\n return this.client.request<ShiftListEntriesResponse>(\n `/v1/shift/indexes/${indexId}/entries${suffix}`,\n );\n },\n delete: async (indexId, entryId) => {\n return this.client.request<{ success: true }>(\n `/v1/shift/indexes/${indexId}/entries/${entryId}`,\n {\n method: \"DELETE\",\n },\n );\n },\n };\n }\n\n async search(indexId: string, params: ShiftSearchParams) {\n return this.client.request<{ results: ShiftSearchResult[] }>(\n `/v1/shift/indexes/${indexId}/search`,\n {\n method: \"POST\",\n body: params,\n },\n );\n }\n}\n\nexport class Ragable {\n readonly shift: ShiftClient;\n readonly infrastructure: {\n shift: ShiftClient;\n };\n\n constructor(options: RagableClientOptions) {\n const client = new RagableRequestClient(options);\n this.shift = new ShiftClient(client);\n this.infrastructure = {\n shift: this.shift,\n };\n }\n}\n\nexport function createClient(options: RagableClientOptions) {\n return new Ragable(options);\n}\n\nfunction extractErrorMessage(payload: unknown, fallback: string) {\n if (payload && typeof payload === \"object\") {\n if (\"error\" in payload && typeof payload.error === \"string\") {\n return payload.error;\n }\n if (\"message\" in payload && typeof payload.message === \"string\") {\n return payload.message;\n }\n }\n\n if (typeof payload === \"string\" && payload.length > 0) {\n return payload;\n }\n\n return fallback || \"Request failed\";\n}\n\nfunction resolveUploadFileName(params: ShiftUploadFileParams) {\n if (params.fileName) {\n return params.fileName;\n }\n\n if (isNamedBlob(params.file)) {\n return params.file.name;\n }\n\n return \"upload.bin\";\n}\n\nfunction resolveUploadContentType(params: ShiftUploadFileParams) {\n if (params.contentType) {\n return params.contentType;\n }\n\n if (params.file instanceof Blob && params.file.type) {\n return params.file.type;\n }\n\n return \"application/octet-stream\";\n}\n\nfunction normalizeUploadFile(file: ShiftUploadableFile, contentType: string) {\n if (file instanceof Blob) {\n return file;\n }\n\n if (file instanceof Uint8Array) {\n return new Blob([toArrayBuffer(file)], { type: contentType });\n }\n\n return new Blob([file], { type: contentType });\n}\n\nfunction isNamedBlob(value: ShiftUploadableFile): value is Blob & { name: string } {\n return value instanceof Blob && \"name\" in value && typeof value.name === \"string\";\n}\n\nfunction isBodyInit(value: unknown): value is BodyInit {\n return (\n typeof value === \"string\" ||\n value instanceof Blob ||\n value instanceof FormData ||\n value instanceof URLSearchParams ||\n value instanceof ArrayBuffer ||\n ArrayBuffer.isView(value)\n );\n}\n\nfunction toArrayBuffer(value: Uint8Array) {\n const copy = new Uint8Array(value.byteLength);\n copy.set(value);\n return copy.buffer;\n}\n"],"mappings":";;;;;AAqFO,IAAM,eAAN,cAA2B,MAAM;AAAA,EAItC,YAAY,SAAiB,QAAgB,MAAe;AAC1D,UAAM,OAAO;AAJf,wBAAS;AACT,wBAAS;AAIP,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACd;AACF;AAMA,IAAM,uBAAN,MAA2B;AAAA,EAMzB,YAAY,SAA+B;AAL3C,wBAAiB;AACjB,wBAAiB;AACjB,wBAAiB;AACjB,wBAAiB;AAGf,SAAK,SAAS,QAAQ;AACtB,SAAK,UAAU,QAAQ,WAAW;AAClC,SAAK,YAAY,QAAQ,SAAS;AAClC,SAAK,iBAAiB,QAAQ;AAAA,EAChC;AAAA,EAEA,MAAM,QAAW,MAAc,UAA0B,CAAC,GAAe;AACvE,UAAM,UAAU,IAAI,QAAQ,KAAK,cAAc;AAC/C,YAAQ,IAAI,iBAAiB,UAAU,KAAK,MAAM,EAAE;AAEpD,QAAI,OAAO,QAAQ;AACnB,QAAI,SAAS,UAAa,CAAC,WAAW,IAAI,GAAG;AAC3C,cAAQ,IAAI,gBAAgB,kBAAkB;AAC9C,aAAO,KAAK,UAAU,IAAI;AAAA,IAC5B;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OAAO,YAAY,YAAY,QAAQ,SAAS,GAAG;AACrD,WAAO;AAAA,EACT;AAEA,SAAO,YAAY;AACrB;AAEA,SAAS,sBAAsB,QAA+B;AAC5D,MAAI,OAAO,UAAU;AACnB,WAAO,OAAO;AAAA,EAChB;AAEA,MAAI,YAAY,OAAO,IAAI,GAAG;AAC5B,WAAO,OAAO,KAAK;AAAA,EACrB;AAEA,SAAO;AACT;AAEA,SAAS,yBAAyB,QAA+B;AAC/D,MAAI,OAAO,aAAa;AACtB,WAAO,OAAO;AAAA,EAChB;AAEA,MAAI,OAAO,gBAAgB,QAAQ,OAAO,KAAK,MAAM;AACnD,WAAO,OAAO,KAAK;AAAA,EACrB;AAEA,SAAO;AACT;AAEA,SAAS,oBAAoB,MAA2B,aAAqB;AAC3E,MAAI,gBAAgB,MAAM;AACxB,WAAO;AAAA,EACT;AAEA,MAAI,gBAAgB,YAAY;AAC9B,WAAO,IAAI,KAAK,CAAC,cAAc,IAAI,CAAC,GAAG,EAAE,MAAM,YAAY,CAAC;AAAA,EAC9D;AAEA,SAAO,IAAI,KAAK,CAAC,IAAI,GAAG,EAAE,MAAM,YAAY,CAAC;AAC/C;AAEA,SAAS,YAAY,OAA8D;AACjF,SAAO,iBAAiB,QAAQ,UAAU,SAAS,OAAO,MAAM,SAAS;AAC3E;AAEA,SAAS,WAAW,OAAmC;AACrD,SACE,OAAO,UAAU,YACjB,iBAAiB,QACjB,iBAAiB,YACjB,iBAAiB,mBACjB,iBAAiB,eACjB,YAAY,OAAO,KAAK;AAE5B;AAEA,SAAS,cAAc,OAAmB;AACxC,QAAM,OAAO,IAAI,WAAW,MAAM,UAAU;AAC5C,OAAK,IAAI,KAAK;AACd,SAAO,KAAK;AACd;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/request-client.ts","../src/shift.ts","../src/agents.ts","../src/rag.ts","../src/index.ts"],"sourcesContent":["export interface RagableClientOptions {\n apiKey: string;\n baseUrl?: string;\n fetch?: typeof fetch;\n headers?: HeadersInit;\n}\n\nexport type RequestOptions = Omit<RequestInit, \"body\"> & {\n body?: unknown;\n};\n\nexport class RagableError extends Error {\n readonly status: number;\n readonly body: unknown;\n\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = \"RagableError\";\n this.status = status;\n this.body = body;\n }\n}\n\nexport function extractErrorMessage(payload: unknown, fallback: string) {\n if (payload && typeof payload === \"object\") {\n if (\"error\" in payload && typeof payload.error === \"string\") {\n return payload.error;\n }\n if (\"message\" in payload && typeof payload.message === \"string\") {\n return payload.message;\n }\n }\n\n if (typeof payload === \"string\" && payload.length > 0) {\n return payload;\n }\n\n return fallback || \"Request failed\";\n}\n\nexport class RagableRequestClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof fetch;\n private readonly defaultHeaders: HeadersInit | undefined;\n\n constructor(options: RagableClientOptions) {\n this.apiKey = options.apiKey;\n this.baseUrl = options.baseUrl ?? \"http://localhost:8080/api\";\n this.fetchImpl = options.fetch ?? fetch;\n this.defaultHeaders = options.headers;\n }\n\n toUrl(path: string) {\n const normalizedBase = this.baseUrl.replace(/\\/+$/, \"\");\n const normalizedPath = path.startsWith(\"/\") ? path : `/${path}`;\n return `${normalizedBase}${normalizedPath}`;\n }\n\n async request<T>(path: string, options: RequestOptions = {}): Promise<T> {\n const response = await this.rawFetch(path, options);\n const payload = await this.parseResponseBody(response);\n if (!response.ok) {\n const message = extractErrorMessage(payload, response.statusText);\n throw new RagableError(message, response.status, payload);\n }\n\n return payload as T;\n }\n\n /**\n * Low-level fetch with API key and JSON body encoding. Caller handles status and body.\n */\n async rawFetch(path: string, options: RequestOptions = {}): Promise<Response> {\n const headers = new Headers(this.defaultHeaders);\n headers.set(\"Authorization\", `Bearer ${this.apiKey}`);\n\n let body = options.body;\n if (body !== undefined && !isBodyInit(body)) {\n headers.set(\"Content-Type\", \"application/json\");\n body = JSON.stringify(body);\n }\n\n return this.fetchImpl(this.toUrl(path), {\n ...options,\n headers,\n body: body as BodyInit | undefined,\n });\n }\n\n private async parseResponseBody(response: Response): Promise<unknown> {\n if (response.status === 204) {\n return null;\n }\n\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (contentType.includes(\"application/json\")) {\n return response.json();\n }\n\n return response.text();\n }\n}\n\nexport function isBodyInit(value: unknown): value is BodyInit {\n return (\n typeof value === \"string\" ||\n value instanceof Blob ||\n value instanceof FormData ||\n value instanceof URLSearchParams ||\n value instanceof ArrayBuffer ||\n ArrayBuffer.isView(value)\n );\n}\n","import { RagableRequestClient } from \"./request-client\";\n\nexport interface ShiftIndex {\n id: string;\n name: string;\n description: string | null;\n dimensions: number;\n embeddingModel: string;\n status: string;\n entryCount?: number;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface ShiftEntry {\n id: string;\n content: string;\n metadata: unknown;\n chunkIndex: number;\n createdAt: string;\n}\n\nexport interface ShiftSearchResult {\n content: string;\n score: number;\n metadata: unknown;\n}\n\nexport interface ShiftCreateIndexParams {\n name: string;\n description?: string;\n dimensions?: number;\n embeddingModel?: string;\n}\n\nexport interface ShiftUpdateIndexParams {\n name?: string;\n description?: string;\n}\n\nexport interface ShiftAddDocumentParams {\n content: string;\n metadata?: Record<string, unknown>;\n chunkSize?: number;\n chunkOverlap?: number;\n}\n\nexport type ShiftUploadableFile = Blob | ArrayBuffer | Uint8Array;\n\nexport interface ShiftUploadFileParams {\n file: ShiftUploadableFile;\n fileName?: string;\n contentType?: string;\n metadata?: Record<string, unknown>;\n chunkSize?: number;\n chunkOverlap?: number;\n}\n\nexport interface ShiftListEntriesParams {\n take?: number;\n skip?: number;\n}\n\nexport interface ShiftSearchParams {\n query: string;\n topK?: number;\n}\n\nexport interface ShiftIngestResponse {\n chunksCreated: number;\n entries: string[];\n extractedText?: string;\n message?: string;\n}\n\nexport interface ShiftListEntriesResponse {\n entries: ShiftEntry[];\n total: number;\n}\n\nexport class ShiftClient {\n readonly indexes: {\n list: () => Promise<{ indexes: ShiftIndex[] }>;\n create: (params: ShiftCreateIndexParams) => Promise<ShiftIndex>;\n get: (indexId: string) => Promise<ShiftIndex>;\n update: (indexId: string, params: ShiftUpdateIndexParams) => Promise<ShiftIndex>;\n delete: (indexId: string) => Promise<{ success: true }>;\n };\n\n readonly documents: {\n create: (\n indexId: string,\n params: ShiftAddDocumentParams,\n ) => Promise<ShiftIngestResponse>;\n upload: (\n indexId: string,\n params: ShiftUploadFileParams,\n ) => Promise<ShiftIngestResponse>;\n };\n\n readonly entries: {\n list: (\n indexId: string,\n params?: ShiftListEntriesParams,\n ) => Promise<ShiftListEntriesResponse>;\n delete: (indexId: string, entryId: string) => Promise<{ success: true }>;\n };\n\n constructor(private readonly client: RagableRequestClient) {\n this.indexes = {\n list: async () => {\n return this.client.request<{ indexes: ShiftIndex[] }>(\"/v1/shift/indexes\");\n },\n create: async (params) => {\n return this.client.request<ShiftIndex>(\"/v1/shift/indexes\", {\n method: \"POST\",\n body: params,\n });\n },\n get: async (indexId) => {\n return this.client.request<ShiftIndex>(`/v1/shift/indexes/${indexId}`);\n },\n update: async (indexId, params) => {\n return this.client.request<ShiftIndex>(`/v1/shift/indexes/${indexId}`, {\n method: \"PUT\",\n body: params,\n });\n },\n delete: async (indexId) => {\n return this.client.request<{ success: true }>(\n `/v1/shift/indexes/${indexId}`,\n {\n method: \"DELETE\",\n },\n );\n },\n };\n\n this.documents = {\n create: async (indexId, params) => {\n return this.client.request<ShiftIngestResponse>(\n `/v1/shift/indexes/${indexId}/documents`,\n {\n method: \"POST\",\n body: params,\n },\n );\n },\n upload: async (indexId, params) => {\n const formData = new FormData();\n const fileName = resolveUploadFileName(params);\n const contentType = resolveUploadContentType(params);\n const file = normalizeUploadFile(params.file, contentType);\n\n formData.set(\"file\", file, fileName);\n\n if (params.metadata) {\n formData.set(\"metadata\", JSON.stringify(params.metadata));\n }\n if (typeof params.chunkSize === \"number\") {\n formData.set(\"chunkSize\", String(params.chunkSize));\n }\n if (typeof params.chunkOverlap === \"number\") {\n formData.set(\"chunkOverlap\", String(params.chunkOverlap));\n }\n\n return this.client.request<ShiftIngestResponse>(\n `/v1/shift/indexes/${indexId}/files`,\n {\n method: \"POST\",\n body: formData,\n },\n );\n },\n };\n\n this.entries = {\n list: async (indexId, params = {}) => {\n const search = new URLSearchParams();\n if (typeof params.take === \"number\") {\n search.set(\"take\", String(params.take));\n }\n if (typeof params.skip === \"number\") {\n search.set(\"skip\", String(params.skip));\n }\n\n const suffix = search.size > 0 ? `?${search.toString()}` : \"\";\n return this.client.request<ShiftListEntriesResponse>(\n `/v1/shift/indexes/${indexId}/entries${suffix}`,\n );\n },\n delete: async (indexId, entryId) => {\n return this.client.request<{ success: true }>(\n `/v1/shift/indexes/${indexId}/entries/${entryId}`,\n {\n method: \"DELETE\",\n },\n );\n },\n };\n }\n\n async search(indexId: string, params: ShiftSearchParams) {\n return this.client.request<{ results: ShiftSearchResult[] }>(\n `/v1/shift/indexes/${indexId}/search`,\n {\n method: \"POST\",\n body: params,\n },\n );\n }\n}\n\nfunction resolveUploadFileName(params: ShiftUploadFileParams) {\n if (params.fileName) {\n return params.fileName;\n }\n\n if (isNamedBlob(params.file)) {\n return params.file.name;\n }\n\n return \"upload.bin\";\n}\n\nfunction resolveUploadContentType(params: ShiftUploadFileParams) {\n if (params.contentType) {\n return params.contentType;\n }\n\n if (params.file instanceof Blob && params.file.type) {\n return params.file.type;\n }\n\n return \"application/octet-stream\";\n}\n\nfunction normalizeUploadFile(file: ShiftUploadableFile, contentType: string) {\n if (file instanceof Blob) {\n return file;\n }\n\n if (file instanceof Uint8Array) {\n return new Blob([toArrayBuffer(file)], { type: contentType });\n }\n\n return new Blob([file], { type: contentType });\n}\n\nfunction isNamedBlob(value: ShiftUploadableFile): value is Blob & { name: string } {\n return value instanceof Blob && \"name\" in value && typeof value.name === \"string\";\n}\n\nfunction toArrayBuffer(value: Uint8Array) {\n const copy = new Uint8Array(value.byteLength);\n copy.set(value);\n return copy.buffer;\n}\n","import {\n extractErrorMessage,\n RagableError,\n RagableRequestClient,\n} from \"./request-client\";\n\nexport interface AgentSummary {\n id: string;\n name: string;\n description: string | null;\n active: boolean;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface AgentChatMessage {\n role: \"user\" | \"assistant\";\n content: string;\n}\n\nexport interface AgentChatParams {\n message: string;\n history?: AgentChatMessage[];\n}\n\n/** Mirrors backend ExecutionResult JSON shape (traces are opaque in the SDK). */\nexport interface AgentChatResult {\n response: string;\n traces: unknown[];\n totalDurationMs: number;\n httpResponse?: unknown;\n}\n\n/**\n * Loose SSE event from POST /v1/agents/:id/chat/stream — narrows with `type` at runtime.\n */\nexport type AgentStreamEvent = Record<string, unknown> & { type: string };\n\nexport class AgentsClient {\n constructor(private readonly client: RagableRequestClient) {}\n\n async list(): Promise<{ agents: AgentSummary[] }> {\n return this.client.request(\"/v1/agents\");\n }\n\n async get(agentId: string): Promise<AgentSummary> {\n return this.client.request(`/v1/agents/${agentId}`);\n }\n\n async chat(\n agentId: string,\n params: AgentChatParams,\n ): Promise<AgentChatResult> {\n return this.client.request<AgentChatResult>(`/v1/agents/${agentId}/chat`, {\n method: \"POST\",\n body: {\n message: params.message,\n ...(params.history !== undefined ? { history: params.history } : {}),\n },\n });\n }\n\n /**\n * Stream agent execution as SSE (`data: {json}` lines). Yields parsed JSON objects.\n */\n async *chatStream(\n agentId: string,\n params: AgentChatParams,\n ): AsyncGenerator<AgentStreamEvent, void, undefined> {\n const response = await this.client.rawFetch(\n `/v1/agents/${agentId}/chat/stream`,\n {\n method: \"POST\",\n body: {\n message: params.message,\n ...(params.history !== undefined ? { history: params.history } : {}),\n },\n },\n );\n\n if (!response.ok) {\n const payload = await parseMaybeJsonBody(response);\n const message = extractErrorMessage(payload, response.statusText);\n throw new RagableError(message, response.status, payload);\n }\n\n const body = response.body;\n if (!body) {\n return;\n }\n\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n buffer += decoder.decode(value, { stream: true });\n\n let boundary = buffer.indexOf(\"\\n\\n\");\n while (boundary !== -1) {\n const block = buffer.slice(0, boundary);\n buffer = buffer.slice(boundary + 2);\n for (const line of block.split(\"\\n\")) {\n const evt = parseSseDataLine(line);\n if (evt) {\n yield evt;\n }\n }\n boundary = buffer.indexOf(\"\\n\\n\");\n }\n }\n\n if (buffer.trim().length > 0) {\n for (const line of buffer.split(\"\\n\")) {\n const evt = parseSseDataLine(line);\n if (evt) {\n yield evt;\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n\nasync function parseMaybeJsonBody(response: Response): Promise<unknown> {\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (contentType.includes(\"application/json\")) {\n try {\n return await response.json();\n } catch {\n return null;\n }\n }\n try {\n return await response.text();\n } catch {\n return null;\n }\n}\n\nfunction parseSseDataLine(line: string): AgentStreamEvent | null {\n const dataPrefix = \"data: \";\n if (!line.startsWith(dataPrefix)) {\n return null;\n }\n const json = line.slice(dataPrefix.length).trim();\n if (json.length === 0 || json === \"[DONE]\") {\n return null;\n }\n try {\n return JSON.parse(json) as AgentStreamEvent;\n } catch {\n return null;\n }\n}\n","import type {\n ShiftAddDocumentParams,\n ShiftIngestResponse,\n ShiftSearchParams,\n ShiftSearchResult,\n ShiftUploadFileParams,\n} from \"./shift\";\n\n/** Minimal client surface for {@link createRagPipeline} (implemented by {@link Ragable}). */\nexport interface RagClientForPipeline {\n shift: {\n documents: {\n create: (\n indexId: string,\n params: ShiftAddDocumentParams,\n ) => Promise<ShiftIngestResponse>;\n upload: (\n indexId: string,\n params: ShiftUploadFileParams,\n ) => Promise<ShiftIngestResponse>;\n };\n search: (\n indexId: string,\n params: ShiftSearchParams,\n ) => Promise<{ results: ShiftSearchResult[] }>;\n };\n}\n\nexport interface FormatContextOptions {\n /** Prepended before numbered passages (default: \"Relevant passages:\\\\n\") */\n header?: string;\n /** Joiner between passages (default: \"\\\\n\\\\n\") */\n separator?: string;\n /** Omit results with similarity score below this (default: no filter) */\n minScore?: number;\n /** Truncate total context string to this UTF-16 length (default: no limit) */\n maxChars?: number;\n /** Include similarity score in each block (default: false) */\n includeScores?: boolean;\n}\n\nexport interface RagPipelineOptions {\n indexId: string;\n}\n\nexport type RetrieveParams = ShiftSearchParams & {\n format?: FormatContextOptions;\n};\n\nexport interface RagPipeline {\n readonly indexId: string;\n ingestText(params: ShiftAddDocumentParams): Promise<ShiftIngestResponse>;\n ingestFile(params: ShiftUploadFileParams): Promise<ShiftIngestResponse>;\n search(params: ShiftSearchParams): Promise<{ results: ShiftSearchResult[] }>;\n retrieve(params: RetrieveParams): Promise<{\n results: ShiftSearchResult[];\n context: string;\n }>;\n}\n\n/**\n * Turn vector search hits into a single block of text for system prompts or RAG user messages.\n */\nexport function formatRetrievalContext(\n results: ShiftSearchResult[],\n options: FormatContextOptions = {},\n): string {\n const header = options.header ?? \"Relevant passages:\\n\";\n const separator = options.separator ?? \"\\n\\n\";\n const minScore = options.minScore;\n\n let filtered = results;\n if (typeof minScore === \"number\") {\n filtered = results.filter((r) => r.score >= minScore);\n }\n\n const blocks = filtered.map((r, i) => {\n const scoreSuffix =\n options.includeScores === true ? ` (score: ${r.score.toFixed(4)})` : \"\";\n return `[${i + 1}]${scoreSuffix}\\n${r.content.trim()}`;\n });\n\n let text = (blocks.length > 0 ? header : \"\") + blocks.join(separator);\n\n if (typeof options.maxChars === \"number\" && text.length > options.maxChars) {\n text = text.slice(0, options.maxChars).trimEnd() + \"\\n…\";\n }\n\n return text;\n}\n\n/**\n * High-level RAG helpers bound to one Shift index: ingest, search, retrieve with prompt-ready context.\n */\nexport function createRagPipeline(\n client: RagClientForPipeline,\n options: RagPipelineOptions,\n): RagPipeline {\n const { indexId } = options;\n\n return {\n indexId,\n\n ingestText(params) {\n return client.shift.documents.create(indexId, params);\n },\n\n ingestFile(params) {\n return client.shift.documents.upload(indexId, params);\n },\n\n search(params) {\n return client.shift.search(indexId, params);\n },\n\n async retrieve(params) {\n const { format: formatOpts, ...searchParams } = params;\n const { results } = await client.shift.search(indexId, searchParams);\n const context = formatRetrievalContext(results, formatOpts ?? {});\n return { results, context };\n },\n };\n}\n","export type { RagableClientOptions, RequestOptions } from \"./request-client\";\nexport {\n extractErrorMessage,\n RagableError,\n RagableRequestClient,\n} from \"./request-client\";\n\nexport type {\n ShiftAddDocumentParams,\n ShiftCreateIndexParams,\n ShiftEntry,\n ShiftIndex,\n ShiftIngestResponse,\n ShiftListEntriesParams,\n ShiftListEntriesResponse,\n ShiftSearchParams,\n ShiftSearchResult,\n ShiftUpdateIndexParams,\n ShiftUploadableFile,\n ShiftUploadFileParams,\n} from \"./shift\";\nexport { ShiftClient } from \"./shift\";\n\nexport type {\n AgentChatMessage,\n AgentChatParams,\n AgentChatResult,\n AgentStreamEvent,\n AgentSummary,\n} from \"./agents\";\nexport { AgentsClient } from \"./agents\";\n\nexport type {\n FormatContextOptions,\n RagClientForPipeline,\n RagPipeline,\n RagPipelineOptions,\n RetrieveParams,\n} from \"./rag\";\nexport { createRagPipeline, formatRetrievalContext } from \"./rag\";\n\nimport { AgentsClient } from \"./agents\";\nimport {\n RagableRequestClient,\n type RagableClientOptions,\n} from \"./request-client\";\nimport { ShiftClient } from \"./shift\";\n\nexport class Ragable {\n readonly shift: ShiftClient;\n readonly agents: AgentsClient;\n readonly infrastructure: {\n shift: ShiftClient;\n };\n\n constructor(options: RagableClientOptions) {\n const client = new RagableRequestClient(options);\n this.shift = new ShiftClient(client);\n this.agents = new AgentsClient(client);\n this.infrastructure = {\n shift: this.shift,\n };\n }\n}\n\nexport function createClient(options: RagableClientOptions) {\n return new Ragable(options);\n}\n"],"mappings":";;;;;AAWO,IAAM,eAAN,cAA2B,MAAM;AAAA,EAItC,YAAY,SAAiB,QAAgB,MAAe;AAC1D,UAAM,OAAO;AAJf,wBAAS;AACT,wBAAS;AAIP,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACd;AACF;AAEO,SAAS,oBAAoB,SAAkB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AEA,MAAM,SAAS,QAAQ;AACrB,YAAM,EAAE,QAAQ,YAAY,GAAG,aAAa,IAAI;AAChD,YAAM,EAAE,QAAQ,IAAI,MAAM,OAAO,MAAM,OAAO,SAAS,YAAY;AACnE,YAAM,UAAU,uBAAuB,SAAS,cAAc,CAAC,CAAC;AAChE,aAAO,EAAE,SAAS,QAAQ;AAAA,IAC5B;AAAA,EACF;AACF;;;AC1EO,IAAM,UAAN,MAAc;AAAA,EAOnB,YAAY,SAA+B;AAN3C,wBAAS;AACT,wBAAS;AACT,wBAAS;AAKP,UAAM,SAAS,IAAI,qBAAqB,OAAO;AAC/C,SAAK,QAAQ,IAAI,YAAY,MAAM;AACnC,SAAK,SAAS,IAAI,aAAa,MAAM;AACrC,SAAK,iBAAiB;AAAA,MACpB,OAAO,KAAK;AAAA,IACd;AAAA,EACF;AACF;AAEO,SAAS,aAAa,SAA+B;AAC1D,SAAO,IAAI,QAAQ,OAAO;AAC5B;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ragable/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "The official SDK for Ragable - The Operating System for AI Agents",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"test": "vitest run",
|
|
23
23
|
"example:shift:smoke": "node ./examples/shift-smoke.mjs",
|
|
24
24
|
"example:shift:file": "node ./examples/shift-file-upload.mjs",
|
|
25
|
+
"example:rag": "node ./examples/rag-pipeline.mjs",
|
|
25
26
|
"prepublishOnly": "npm run build"
|
|
26
27
|
},
|
|
27
28
|
"keywords": [
|