@exulu/backend 0.1.6
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/README.md +71 -0
- package/dist/index.cjs +3763 -0
- package/dist/index.d.cts +450 -0
- package/dist/index.d.ts +450 -0
- package/dist/index.js +3721 -0
- package/git-conventional-commits.yaml +43 -0
- package/license.md +81 -0
- package/package.json +82 -0
- package/types/enums/field-types.ts +1 -0
- package/types/enums/statistics.ts +13 -0
- package/types/models/agent-backend.ts +15 -0
- package/types/models/agent-session.ts +17 -0
- package/types/models/agent.ts +23 -0
- package/types/models/context.ts +35 -0
- package/types/models/embedder-backend.ts +15 -0
- package/types/models/embedding.ts +17 -0
- package/types/models/item.ts +21 -0
- package/types/models/job.ts +8 -0
- package/types/models/tool.ts +8 -0
- package/types/models/user-role.ts +6 -0
- package/types/models/user.ts +10 -0
- package/types/models/vector-methods.ts +10 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import * as bullmq from 'bullmq';
|
|
2
|
+
import { Queue } from 'bullmq';
|
|
3
|
+
import * as redis from 'redis';
|
|
4
|
+
import * as _mastra_core from '@mastra/core';
|
|
5
|
+
import { ToolAction, Workflow, Agent } from '@mastra/core';
|
|
6
|
+
import { ZodSchema, z } from 'zod';
|
|
7
|
+
import { LanguageModelV1 } from 'ai';
|
|
8
|
+
import { Express } from 'express';
|
|
9
|
+
import { Knex } from 'knex';
|
|
10
|
+
|
|
11
|
+
type STATISTICS_TYPE = "context.retrieve" | "source.update" | "embedder.upsert" | "embedder.delete" | "workflow.run" | "context.upsert" | "tool.call" | "agent.run";
|
|
12
|
+
declare const STATISTICS_TYPE_ENUM: {
|
|
13
|
+
CONTEXT_RETRIEVE: string;
|
|
14
|
+
SOURCE_UPDATE: string;
|
|
15
|
+
EMBEDDER_UPSERT: string;
|
|
16
|
+
EMBEDDER_GENERATE: string;
|
|
17
|
+
EMBEDDER_DELETE: string;
|
|
18
|
+
WORKFLOW_RUN: string;
|
|
19
|
+
CONTEXT_UPSERT: string;
|
|
20
|
+
TOOL_CALL: string;
|
|
21
|
+
AGENT_RUN: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type ExuluFieldTypes = "text" | "longText" | "shortText" | "number" | "boolean" | "code" | "json";
|
|
25
|
+
|
|
26
|
+
interface Item {
|
|
27
|
+
id?: string;
|
|
28
|
+
name?: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
createdAt?: string;
|
|
31
|
+
updatedAt?: string;
|
|
32
|
+
external_id?: string;
|
|
33
|
+
source?: string;
|
|
34
|
+
tags?: string[];
|
|
35
|
+
textLength?: number;
|
|
36
|
+
chunks?: {
|
|
37
|
+
id: string;
|
|
38
|
+
index: number;
|
|
39
|
+
content: string;
|
|
40
|
+
source: string;
|
|
41
|
+
embedding: number;
|
|
42
|
+
createdAt: string;
|
|
43
|
+
updatedAt: string;
|
|
44
|
+
}[];
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
declare const VectorMethodEnum: {
|
|
49
|
+
readonly cosineDistance: "cosineDistance";
|
|
50
|
+
readonly l1Distance: "l1Distance";
|
|
51
|
+
readonly l2Distance: "l2Distance";
|
|
52
|
+
readonly hammingDistance: "hammingDistance";
|
|
53
|
+
readonly jaccardDistance: "jaccardDistance";
|
|
54
|
+
readonly maxInnerProduct: "maxInnerProduct";
|
|
55
|
+
};
|
|
56
|
+
type VectorMethod = (typeof VectorMethodEnum)[keyof typeof VectorMethodEnum];
|
|
57
|
+
|
|
58
|
+
interface RateLimiterRule {
|
|
59
|
+
name?: string;
|
|
60
|
+
rate_limit: {
|
|
61
|
+
time: number;
|
|
62
|
+
limit: number;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
declare const ExuluZodFileType: ({ name, label, description, allowedFileTypes }: {
|
|
66
|
+
name: string;
|
|
67
|
+
label: string;
|
|
68
|
+
description: string;
|
|
69
|
+
allowedFileTypes: (".mp4" | ".m4a" | ".mp3" | ".pdf" | ".jpeg" | ".png" | ".plain" | ".mpeg" | ".wav" | ".docx" | ".xlsx" | ".xls" | ".csv" | ".pptx" | ".ppt")[];
|
|
70
|
+
}) => z.ZodObject<{
|
|
71
|
+
[x: string]: z.ZodString;
|
|
72
|
+
}, "strip", z.ZodTypeAny, {
|
|
73
|
+
[x: string]: string;
|
|
74
|
+
}, {
|
|
75
|
+
[x: string]: string;
|
|
76
|
+
}>;
|
|
77
|
+
type ExuluAgentConfig = {
|
|
78
|
+
name: string;
|
|
79
|
+
instructions: string;
|
|
80
|
+
model: LanguageModelV1;
|
|
81
|
+
memory?: {
|
|
82
|
+
lastMessages: number;
|
|
83
|
+
vector: boolean;
|
|
84
|
+
semanticRecall: {
|
|
85
|
+
topK: number;
|
|
86
|
+
messageRange: number;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
declare class ExuluAgent {
|
|
91
|
+
id: string;
|
|
92
|
+
name: string;
|
|
93
|
+
description: string;
|
|
94
|
+
slug: string;
|
|
95
|
+
streaming: boolean;
|
|
96
|
+
type: "agent" | "workflow";
|
|
97
|
+
outputSchema?: ZodSchema;
|
|
98
|
+
rateLimit?: RateLimiterRule;
|
|
99
|
+
config: ExuluAgentConfig;
|
|
100
|
+
private memory;
|
|
101
|
+
tools?: ExuluTool[];
|
|
102
|
+
capabilities: {
|
|
103
|
+
tools: boolean;
|
|
104
|
+
images: string[];
|
|
105
|
+
files: string[];
|
|
106
|
+
audio: string[];
|
|
107
|
+
video: string[];
|
|
108
|
+
};
|
|
109
|
+
constructor({ id, name, description, outputSchema, config, rateLimit, type, capabilities, tools }: {
|
|
110
|
+
id: string;
|
|
111
|
+
name: string;
|
|
112
|
+
type: "agent" | "workflow";
|
|
113
|
+
description: string;
|
|
114
|
+
config: ExuluAgentConfig;
|
|
115
|
+
outputSchema?: ZodSchema;
|
|
116
|
+
rateLimit?: RateLimiterRule;
|
|
117
|
+
capabilities: {
|
|
118
|
+
tools: boolean;
|
|
119
|
+
images: string[];
|
|
120
|
+
files: string[];
|
|
121
|
+
audio: string[];
|
|
122
|
+
video: string[];
|
|
123
|
+
};
|
|
124
|
+
tools?: ExuluTool[];
|
|
125
|
+
});
|
|
126
|
+
chat: (id: string) => Promise<Agent<string, {}, Record<string, _mastra_core.Metric>>>;
|
|
127
|
+
}
|
|
128
|
+
type VectorOperationResponse = Promise<{
|
|
129
|
+
count: number;
|
|
130
|
+
results: any;
|
|
131
|
+
errors?: string[];
|
|
132
|
+
}>;
|
|
133
|
+
type VectorGenerateOperation = (inputs: ChunkerResponse) => VectorGenerationResponse;
|
|
134
|
+
type ChunkerOperation = (item: Item & {
|
|
135
|
+
id: string;
|
|
136
|
+
}, maxChunkSize: number) => Promise<ChunkerResponse>;
|
|
137
|
+
type ChunkerResponse = {
|
|
138
|
+
item: Item & {
|
|
139
|
+
id: string;
|
|
140
|
+
};
|
|
141
|
+
chunks: {
|
|
142
|
+
content: string;
|
|
143
|
+
index: number;
|
|
144
|
+
}[];
|
|
145
|
+
};
|
|
146
|
+
type VectorGenerationResponse = Promise<{
|
|
147
|
+
id: string;
|
|
148
|
+
chunks: {
|
|
149
|
+
content: string;
|
|
150
|
+
index: number;
|
|
151
|
+
vector: number[];
|
|
152
|
+
}[];
|
|
153
|
+
}>;
|
|
154
|
+
declare class ExuluEmbedder {
|
|
155
|
+
id: string;
|
|
156
|
+
name: string;
|
|
157
|
+
slug: string;
|
|
158
|
+
queue?: Queue;
|
|
159
|
+
private generateEmbeddings;
|
|
160
|
+
vectorDimensions: number;
|
|
161
|
+
maxChunkSize: number;
|
|
162
|
+
chunker: ChunkerOperation;
|
|
163
|
+
constructor({ id, name, description, generateEmbeddings, queue, vectorDimensions, maxChunkSize, chunker }: {
|
|
164
|
+
id: string;
|
|
165
|
+
name: string;
|
|
166
|
+
description: string;
|
|
167
|
+
generateEmbeddings: VectorGenerateOperation;
|
|
168
|
+
chunker: ChunkerOperation;
|
|
169
|
+
queue?: Queue;
|
|
170
|
+
vectorDimensions: number;
|
|
171
|
+
maxChunkSize: number;
|
|
172
|
+
});
|
|
173
|
+
generateFromQuery(query: string, statistics?: {
|
|
174
|
+
label: string;
|
|
175
|
+
trigger: string;
|
|
176
|
+
}): VectorGenerationResponse;
|
|
177
|
+
generateFromDocument(input: Item, statistics?: {
|
|
178
|
+
label: string;
|
|
179
|
+
trigger: string;
|
|
180
|
+
}): VectorGenerationResponse;
|
|
181
|
+
}
|
|
182
|
+
declare class ExuluWorkflow {
|
|
183
|
+
id: string;
|
|
184
|
+
name: string;
|
|
185
|
+
description: string;
|
|
186
|
+
enable_batch: boolean;
|
|
187
|
+
slug: string;
|
|
188
|
+
queue: Queue | undefined;
|
|
189
|
+
workflow: Workflow;
|
|
190
|
+
inputSchema?: ZodSchema;
|
|
191
|
+
constructor({ id, name, description, workflow, queue, enable_batch, inputSchema }: {
|
|
192
|
+
id: string;
|
|
193
|
+
name: string;
|
|
194
|
+
description: string;
|
|
195
|
+
workflow: Workflow;
|
|
196
|
+
queue?: Queue;
|
|
197
|
+
inputSchema?: ZodSchema;
|
|
198
|
+
enable_batch: boolean;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
type AddSourceArgs = Omit<ExuluSourceConstructorArgs, "context">;
|
|
202
|
+
declare class ExuluTool {
|
|
203
|
+
id: string;
|
|
204
|
+
name: string;
|
|
205
|
+
description: string;
|
|
206
|
+
inputSchema?: ZodSchema;
|
|
207
|
+
outputSchema?: ZodSchema;
|
|
208
|
+
type: "context" | "function";
|
|
209
|
+
private _execute;
|
|
210
|
+
constructor({ id, name, description, inputSchema, outputSchema, type, execute }: {
|
|
211
|
+
id: string;
|
|
212
|
+
name: string;
|
|
213
|
+
description: string;
|
|
214
|
+
inputSchema?: ZodSchema;
|
|
215
|
+
outputSchema?: ZodSchema;
|
|
216
|
+
type: "context" | "function";
|
|
217
|
+
execute: ToolAction['execute'];
|
|
218
|
+
});
|
|
219
|
+
execute: (inputs: any) => Promise<unknown>;
|
|
220
|
+
}
|
|
221
|
+
type ExuluContextFieldDefinition = {
|
|
222
|
+
name: string;
|
|
223
|
+
type: ExuluFieldTypes;
|
|
224
|
+
};
|
|
225
|
+
declare class ExuluContext {
|
|
226
|
+
id: string;
|
|
227
|
+
name: string;
|
|
228
|
+
active: boolean;
|
|
229
|
+
fields: ExuluContextFieldDefinition[];
|
|
230
|
+
rateLimit?: RateLimiterRule;
|
|
231
|
+
description: string;
|
|
232
|
+
embedder: ExuluEmbedder;
|
|
233
|
+
queryRewriter?: (query: string) => Promise<string>;
|
|
234
|
+
resultReranker?: (results: any[]) => Promise<any[]>;
|
|
235
|
+
private _sources;
|
|
236
|
+
private configuration;
|
|
237
|
+
constructor({ id, name, description, embedder, active, rateLimit, fields, queryRewriter, resultReranker, configuration }: {
|
|
238
|
+
id: string;
|
|
239
|
+
name: string;
|
|
240
|
+
fields: ExuluContextFieldDefinition[];
|
|
241
|
+
description: string;
|
|
242
|
+
embedder: ExuluEmbedder;
|
|
243
|
+
active: boolean;
|
|
244
|
+
rateLimit?: RateLimiterRule;
|
|
245
|
+
queryRewriter?: (query: string) => Promise<string>;
|
|
246
|
+
resultReranker?: (results: any[]) => Promise<any[]>;
|
|
247
|
+
configuration?: {
|
|
248
|
+
calculateVectors: "manual" | "onUpdate" | "onInsert" | "always";
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
deleteOne: (id: string) => VectorOperationResponse;
|
|
252
|
+
deleteAll: () => VectorOperationResponse;
|
|
253
|
+
getTableName: () => string;
|
|
254
|
+
getChunksTableName: () => string;
|
|
255
|
+
tableExists: () => Promise<boolean>;
|
|
256
|
+
updateItem(user: string, id: string, item: Item): Promise<{
|
|
257
|
+
id: string;
|
|
258
|
+
job?: string;
|
|
259
|
+
}>;
|
|
260
|
+
insertItem(user: string, item: Item, upsert?: boolean): Promise<{
|
|
261
|
+
id: string;
|
|
262
|
+
job?: string;
|
|
263
|
+
}>;
|
|
264
|
+
getItems: ({ statistics, limit, page, name, archived, query, method }: {
|
|
265
|
+
statistics?: {
|
|
266
|
+
label: string;
|
|
267
|
+
trigger: string;
|
|
268
|
+
};
|
|
269
|
+
page: number;
|
|
270
|
+
limit: number;
|
|
271
|
+
name?: string;
|
|
272
|
+
archived?: boolean;
|
|
273
|
+
query?: string;
|
|
274
|
+
method?: VectorMethod;
|
|
275
|
+
}) => Promise<{
|
|
276
|
+
pagination: {
|
|
277
|
+
totalCount: number;
|
|
278
|
+
currentPage: number;
|
|
279
|
+
limit: number;
|
|
280
|
+
from: number;
|
|
281
|
+
pageCount: number;
|
|
282
|
+
to: number;
|
|
283
|
+
lastPage: number;
|
|
284
|
+
nextPage: number | null;
|
|
285
|
+
previousPage: number | null;
|
|
286
|
+
};
|
|
287
|
+
filters: {
|
|
288
|
+
archived: boolean | undefined;
|
|
289
|
+
name: string | undefined;
|
|
290
|
+
query: string | undefined;
|
|
291
|
+
};
|
|
292
|
+
context: {
|
|
293
|
+
name: string;
|
|
294
|
+
id: string;
|
|
295
|
+
embedder: string;
|
|
296
|
+
};
|
|
297
|
+
items: any[];
|
|
298
|
+
} | {
|
|
299
|
+
filters: {
|
|
300
|
+
archived: boolean | undefined;
|
|
301
|
+
name: string | undefined;
|
|
302
|
+
query: string;
|
|
303
|
+
};
|
|
304
|
+
context: {
|
|
305
|
+
name: string;
|
|
306
|
+
id: string;
|
|
307
|
+
embedder: string;
|
|
308
|
+
};
|
|
309
|
+
items: any[];
|
|
310
|
+
pagination?: undefined;
|
|
311
|
+
} | undefined>;
|
|
312
|
+
createItemsTable: () => Promise<void>;
|
|
313
|
+
createChunksTable: () => Promise<void>;
|
|
314
|
+
tool: () => ExuluTool;
|
|
315
|
+
sources: {
|
|
316
|
+
add: (inputs: AddSourceArgs) => ExuluSource;
|
|
317
|
+
get: (id?: string) => ExuluSource[] | (ExuluSource | undefined);
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* @param updaters - Defines how this source decides when and which data to send to the embedder for updating vectors
|
|
322
|
+
* @param updaters.type - The type of update mechanism:
|
|
323
|
+
* - "manual": Will be shown in the Exulu frontend UI via a Button for manual triggering
|
|
324
|
+
* - "cron": Will automatically update on a schedule
|
|
325
|
+
* - "webhook": Will update when triggered by an external webhook
|
|
326
|
+
* @param updaters.fn - The function that handles the update logic
|
|
327
|
+
* @param configuration - Defines fields shown in the UI that admins can set for each instance of the Source
|
|
328
|
+
* This allows reusing logic while exposing configurable variables (e.g. a "query" field)
|
|
329
|
+
* that admins can set differently for different instances in the UI
|
|
330
|
+
*/
|
|
331
|
+
type ExuluSourceConstructorArgs = {
|
|
332
|
+
id: string;
|
|
333
|
+
name: string;
|
|
334
|
+
description: string;
|
|
335
|
+
updaters: ExuluSourceUpdaterArgs[];
|
|
336
|
+
context: string;
|
|
337
|
+
};
|
|
338
|
+
type SourceDocument = {
|
|
339
|
+
id: string;
|
|
340
|
+
content: string;
|
|
341
|
+
metadata?: Record<string, any>;
|
|
342
|
+
};
|
|
343
|
+
type ExuluSourceUpdaterArgs = {
|
|
344
|
+
id: string;
|
|
345
|
+
type: "manual" | "cron" | "webhook";
|
|
346
|
+
fn: (configuration: Record<string, any>) => Promise<SourceDocument[]>;
|
|
347
|
+
configuration: Record<string, {
|
|
348
|
+
type: "string" | "number" | "query";
|
|
349
|
+
example: string;
|
|
350
|
+
}>;
|
|
351
|
+
};
|
|
352
|
+
type ExuluSourceUpdater = ExuluSourceUpdaterArgs & {
|
|
353
|
+
slug?: string;
|
|
354
|
+
};
|
|
355
|
+
declare class ExuluSource {
|
|
356
|
+
id: string;
|
|
357
|
+
name: string;
|
|
358
|
+
description: string;
|
|
359
|
+
updaters: ExuluSourceUpdater[];
|
|
360
|
+
context: string;
|
|
361
|
+
constructor({ id, name, description, updaters, context }: ExuluSourceConstructorArgs);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
type ExuluConfig = {
|
|
365
|
+
workers: {
|
|
366
|
+
enabled: boolean;
|
|
367
|
+
logsDir?: string;
|
|
368
|
+
};
|
|
369
|
+
};
|
|
370
|
+
declare class ExuluApp {
|
|
371
|
+
private _agents;
|
|
372
|
+
private _workflows;
|
|
373
|
+
private _config;
|
|
374
|
+
private _embedders;
|
|
375
|
+
private _queues;
|
|
376
|
+
private _contexts?;
|
|
377
|
+
private _tools;
|
|
378
|
+
constructor({ contexts, embedders, agents, workflows, config, tools }: {
|
|
379
|
+
contexts?: Record<string, ExuluContext>;
|
|
380
|
+
config: ExuluConfig;
|
|
381
|
+
embedders?: ExuluEmbedder[];
|
|
382
|
+
agents?: ExuluAgent[];
|
|
383
|
+
workflows?: ExuluWorkflow[];
|
|
384
|
+
tools?: ExuluTool[];
|
|
385
|
+
});
|
|
386
|
+
embedder(id: string): ExuluEmbedder | undefined;
|
|
387
|
+
tool(id: string): ExuluTool | undefined;
|
|
388
|
+
tools(): ExuluTool[];
|
|
389
|
+
context(id: string): ExuluContext | undefined;
|
|
390
|
+
agent(id: string): ExuluAgent | undefined;
|
|
391
|
+
workflow(id: string): ExuluWorkflow | undefined;
|
|
392
|
+
get embedders(): ExuluEmbedder[];
|
|
393
|
+
get contexts(): ExuluContext[];
|
|
394
|
+
get workflows(): ExuluWorkflow[];
|
|
395
|
+
get agents(): ExuluAgent[];
|
|
396
|
+
bullmq: {
|
|
397
|
+
workers: {
|
|
398
|
+
create: () => Promise<bullmq.Worker<any, any, string>[]>;
|
|
399
|
+
};
|
|
400
|
+
};
|
|
401
|
+
server: {
|
|
402
|
+
express: {
|
|
403
|
+
init: (app: Express) => Promise<void>;
|
|
404
|
+
};
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
type User = {
|
|
409
|
+
id: string;
|
|
410
|
+
email: string;
|
|
411
|
+
emailVerified?: string;
|
|
412
|
+
type?: "api" | "user";
|
|
413
|
+
roles?: {
|
|
414
|
+
id: string;
|
|
415
|
+
role: string;
|
|
416
|
+
}[];
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
declare const authentication: ({ apikey, authtoken, internalkey, db, }: {
|
|
420
|
+
authtoken?: any;
|
|
421
|
+
apikey?: string;
|
|
422
|
+
internalkey?: string;
|
|
423
|
+
db: Knex;
|
|
424
|
+
}) => Promise<{
|
|
425
|
+
error: boolean;
|
|
426
|
+
message?: string;
|
|
427
|
+
code?: number;
|
|
428
|
+
user?: User;
|
|
429
|
+
}>;
|
|
430
|
+
|
|
431
|
+
declare class ExuluQueues {
|
|
432
|
+
queues: Queue[];
|
|
433
|
+
constructor();
|
|
434
|
+
queue(name: string): Queue | undefined;
|
|
435
|
+
use(name: string): Queue;
|
|
436
|
+
}
|
|
437
|
+
declare const queues: ExuluQueues;
|
|
438
|
+
|
|
439
|
+
declare const ExuluJobs: {
|
|
440
|
+
redis: redis.RedisClientType | null;
|
|
441
|
+
jobs: {
|
|
442
|
+
validate: (job: bullmq.Job) => bullmq.Job<any, any, string>;
|
|
443
|
+
};
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
declare const ExuluDatabase: {
|
|
447
|
+
init: () => Promise<void>;
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
export { type STATISTICS_TYPE as EXULU_STATISTICS_TYPE, STATISTICS_TYPE_ENUM as EXULU_STATISTICS_TYPE_ENUM, ExuluAgent, ExuluApp, authentication as ExuluAuthentication, ExuluContext, ExuluDatabase, ExuluEmbedder, ExuluJobs, queues as ExuluQueues, ExuluSource, ExuluTool, ExuluWorkflow, ExuluZodFileType };
|