@ekodb/ekodb-client 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +27 -0
- package/dist/client.js +41 -0
- package/dist/functions.d.ts +195 -0
- package/dist/functions.js +154 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -1
- package/package.json +1 -1
- package/src/client.ts +60 -0
- package/src/functions.ts +420 -0
- package/src/index.ts +11 -0
package/dist/client.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { QueryBuilder } from "./query-builder";
|
|
5
5
|
import { SearchQuery, SearchQueryBuilder, SearchResponse } from "./search";
|
|
6
6
|
import { Schema, SchemaBuilder, CollectionMetadata } from "./schema";
|
|
7
|
+
import { Script, FunctionResult } from "./functions";
|
|
7
8
|
export interface Record {
|
|
8
9
|
[key: string]: any;
|
|
9
10
|
}
|
|
@@ -395,6 +396,32 @@ export declare class EkoDBClient {
|
|
|
395
396
|
* Merge multiple chat sessions into one
|
|
396
397
|
*/
|
|
397
398
|
mergeChatSessions(request: MergeSessionsRequest): Promise<ChatSessionResponse>;
|
|
399
|
+
/**
|
|
400
|
+
* Save a new script definition
|
|
401
|
+
*/
|
|
402
|
+
saveScript(script: Script): Promise<string>;
|
|
403
|
+
/**
|
|
404
|
+
* Get a script by ID
|
|
405
|
+
*/
|
|
406
|
+
getScript(id: string): Promise<Script>;
|
|
407
|
+
/**
|
|
408
|
+
* List all scripts, optionally filtered by tags
|
|
409
|
+
*/
|
|
410
|
+
listScripts(tags?: string[]): Promise<Script[]>;
|
|
411
|
+
/**
|
|
412
|
+
* Update an existing script by ID
|
|
413
|
+
*/
|
|
414
|
+
updateScript(id: string, script: Script): Promise<void>;
|
|
415
|
+
/**
|
|
416
|
+
* Delete a script by ID
|
|
417
|
+
*/
|
|
418
|
+
deleteScript(id: string): Promise<void>;
|
|
419
|
+
/**
|
|
420
|
+
* Call a saved script by ID or label
|
|
421
|
+
*/
|
|
422
|
+
callScript(idOrLabel: string, params?: {
|
|
423
|
+
[key: string]: any;
|
|
424
|
+
}): Promise<FunctionResult>;
|
|
398
425
|
/**
|
|
399
426
|
* Create a WebSocket client
|
|
400
427
|
*/
|
package/dist/client.js
CHANGED
|
@@ -548,6 +548,47 @@ class EkoDBClient {
|
|
|
548
548
|
async mergeChatSessions(request) {
|
|
549
549
|
return this.makeRequest("POST", "/api/chat/merge", request, 0, true);
|
|
550
550
|
}
|
|
551
|
+
// ========================================================================
|
|
552
|
+
// SCRIPTS API
|
|
553
|
+
// ========================================================================
|
|
554
|
+
/**
|
|
555
|
+
* Save a new script definition
|
|
556
|
+
*/
|
|
557
|
+
async saveScript(script) {
|
|
558
|
+
const result = await this.makeRequest("POST", "/api/functions", script);
|
|
559
|
+
return result.id;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Get a script by ID
|
|
563
|
+
*/
|
|
564
|
+
async getScript(id) {
|
|
565
|
+
return this.makeRequest("GET", `/api/functions/${id}`);
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* List all scripts, optionally filtered by tags
|
|
569
|
+
*/
|
|
570
|
+
async listScripts(tags) {
|
|
571
|
+
const params = tags ? `?tags=${tags.join(",")}` : "";
|
|
572
|
+
return this.makeRequest("GET", `/api/functions${params}`);
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Update an existing script by ID
|
|
576
|
+
*/
|
|
577
|
+
async updateScript(id, script) {
|
|
578
|
+
await this.makeRequest("PUT", `/api/functions/${id}`, script);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Delete a script by ID
|
|
582
|
+
*/
|
|
583
|
+
async deleteScript(id) {
|
|
584
|
+
await this.makeRequest("DELETE", `/api/functions/${id}`);
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Call a saved script by ID or label
|
|
588
|
+
*/
|
|
589
|
+
async callScript(idOrLabel, params) {
|
|
590
|
+
return this.makeRequest("POST", `/api/functions/${idOrLabel}`, params || {});
|
|
591
|
+
}
|
|
551
592
|
/**
|
|
552
593
|
* Create a WebSocket client
|
|
553
594
|
*/
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scripts API for ekoDB TypeScript client
|
|
3
|
+
*/
|
|
4
|
+
export interface Script {
|
|
5
|
+
label: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
version: string;
|
|
9
|
+
parameters: {
|
|
10
|
+
[key: string]: ParameterDefinition;
|
|
11
|
+
};
|
|
12
|
+
functions: FunctionStageConfig[];
|
|
13
|
+
tags: string[];
|
|
14
|
+
created_at?: string;
|
|
15
|
+
updated_at?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ParameterDefinition {
|
|
18
|
+
required: boolean;
|
|
19
|
+
default?: any;
|
|
20
|
+
description?: string;
|
|
21
|
+
param_type?: string;
|
|
22
|
+
}
|
|
23
|
+
export type FunctionStageConfig = {
|
|
24
|
+
type: "FindAll";
|
|
25
|
+
collection: string;
|
|
26
|
+
} | {
|
|
27
|
+
type: "Query";
|
|
28
|
+
collection: string;
|
|
29
|
+
filter?: Record<string, any>;
|
|
30
|
+
sort?: SortFieldConfig[];
|
|
31
|
+
limit?: number;
|
|
32
|
+
skip?: number;
|
|
33
|
+
} | {
|
|
34
|
+
type: "Project";
|
|
35
|
+
fields: string[];
|
|
36
|
+
exclude: boolean;
|
|
37
|
+
} | {
|
|
38
|
+
type: "Group";
|
|
39
|
+
by_fields: string[];
|
|
40
|
+
functions: GroupFunctionConfig[];
|
|
41
|
+
} | {
|
|
42
|
+
type: "Count";
|
|
43
|
+
output_field: string;
|
|
44
|
+
} | {
|
|
45
|
+
type: "Filter";
|
|
46
|
+
filter: Record<string, any>;
|
|
47
|
+
} | {
|
|
48
|
+
type: "Sort";
|
|
49
|
+
sort: SortFieldConfig[];
|
|
50
|
+
} | {
|
|
51
|
+
type: "Limit";
|
|
52
|
+
limit: number;
|
|
53
|
+
} | {
|
|
54
|
+
type: "Skip";
|
|
55
|
+
skip: number;
|
|
56
|
+
} | {
|
|
57
|
+
type: "Insert";
|
|
58
|
+
collection: string;
|
|
59
|
+
record: Record<string, any>;
|
|
60
|
+
bypass_ripple?: boolean;
|
|
61
|
+
ttl?: number;
|
|
62
|
+
} | {
|
|
63
|
+
type: "Update";
|
|
64
|
+
collection: string;
|
|
65
|
+
filter: Record<string, any>;
|
|
66
|
+
updates: Record<string, any>;
|
|
67
|
+
bypass_ripple?: boolean;
|
|
68
|
+
ttl?: number;
|
|
69
|
+
} | {
|
|
70
|
+
type: "UpdateById";
|
|
71
|
+
collection: string;
|
|
72
|
+
record_id: string;
|
|
73
|
+
updates: Record<string, any>;
|
|
74
|
+
bypass_ripple?: boolean;
|
|
75
|
+
ttl?: number;
|
|
76
|
+
} | {
|
|
77
|
+
type: "Delete";
|
|
78
|
+
collection: string;
|
|
79
|
+
filter: Record<string, any>;
|
|
80
|
+
bypass_ripple?: boolean;
|
|
81
|
+
} | {
|
|
82
|
+
type: "DeleteById";
|
|
83
|
+
collection: string;
|
|
84
|
+
record_id: string;
|
|
85
|
+
bypass_ripple?: boolean;
|
|
86
|
+
} | {
|
|
87
|
+
type: "BatchInsert";
|
|
88
|
+
collection: string;
|
|
89
|
+
records: Record<string, any>[];
|
|
90
|
+
bypass_ripple?: boolean;
|
|
91
|
+
} | {
|
|
92
|
+
type: "BatchDelete";
|
|
93
|
+
collection: string;
|
|
94
|
+
record_ids: string[];
|
|
95
|
+
bypass_ripple?: boolean;
|
|
96
|
+
} | {
|
|
97
|
+
type: "HttpRequest";
|
|
98
|
+
url: string;
|
|
99
|
+
method?: string;
|
|
100
|
+
headers?: Record<string, string>;
|
|
101
|
+
body?: any;
|
|
102
|
+
} | {
|
|
103
|
+
type: "VectorSearch";
|
|
104
|
+
collection: string;
|
|
105
|
+
query_vector: number[];
|
|
106
|
+
limit?: number;
|
|
107
|
+
threshold?: number;
|
|
108
|
+
} | {
|
|
109
|
+
type: "TextSearch";
|
|
110
|
+
collection: string;
|
|
111
|
+
query_text: string;
|
|
112
|
+
fields?: string[];
|
|
113
|
+
limit?: number;
|
|
114
|
+
fuzzy?: boolean;
|
|
115
|
+
} | {
|
|
116
|
+
type: "HybridSearch";
|
|
117
|
+
collection: string;
|
|
118
|
+
query_text: string;
|
|
119
|
+
query_vector?: number[];
|
|
120
|
+
limit?: number;
|
|
121
|
+
} | {
|
|
122
|
+
type: "Chat";
|
|
123
|
+
messages: ChatMessage[];
|
|
124
|
+
model?: string;
|
|
125
|
+
temperature?: number;
|
|
126
|
+
max_tokens?: number;
|
|
127
|
+
} | {
|
|
128
|
+
type: "Embed";
|
|
129
|
+
input_field: string;
|
|
130
|
+
output_field: string;
|
|
131
|
+
model?: string;
|
|
132
|
+
};
|
|
133
|
+
export interface ChatMessage {
|
|
134
|
+
role: string;
|
|
135
|
+
content: string;
|
|
136
|
+
}
|
|
137
|
+
export declare const ChatMessage: {
|
|
138
|
+
system: (content: string) => ChatMessage;
|
|
139
|
+
user: (content: string) => ChatMessage;
|
|
140
|
+
assistant: (content: string) => ChatMessage;
|
|
141
|
+
};
|
|
142
|
+
export interface GroupFunctionConfig {
|
|
143
|
+
output_field: string;
|
|
144
|
+
operation: "Sum" | "Average" | "Count" | "Min" | "Max" | "First" | "Last" | "Push";
|
|
145
|
+
input_field?: string;
|
|
146
|
+
}
|
|
147
|
+
export interface SortFieldConfig {
|
|
148
|
+
field: string;
|
|
149
|
+
ascending: boolean;
|
|
150
|
+
}
|
|
151
|
+
export interface FunctionResult {
|
|
152
|
+
records: Record<string, any>[];
|
|
153
|
+
stats: FunctionStats;
|
|
154
|
+
}
|
|
155
|
+
export interface FunctionStats {
|
|
156
|
+
input_count: number;
|
|
157
|
+
output_count: number;
|
|
158
|
+
execution_time_ms: number;
|
|
159
|
+
stages_executed: number;
|
|
160
|
+
stage_stats: StageStats[];
|
|
161
|
+
}
|
|
162
|
+
export interface StageStats {
|
|
163
|
+
stage: string;
|
|
164
|
+
input_count: number;
|
|
165
|
+
output_count: number;
|
|
166
|
+
execution_time_ms: number;
|
|
167
|
+
}
|
|
168
|
+
export declare const Stage: {
|
|
169
|
+
findAll: (collection: string) => FunctionStageConfig;
|
|
170
|
+
query: (collection: string, filter?: Record<string, any>, sort?: SortFieldConfig[], limit?: number, skip?: number) => FunctionStageConfig;
|
|
171
|
+
project: (fields: string[], exclude?: boolean) => FunctionStageConfig;
|
|
172
|
+
group: (by_fields: string[], functions: GroupFunctionConfig[]) => FunctionStageConfig;
|
|
173
|
+
count: (output_field?: string) => FunctionStageConfig;
|
|
174
|
+
insert: (collection: string, record: Record<string, any>, bypassRipple?: boolean, ttl?: number) => FunctionStageConfig;
|
|
175
|
+
update: (collection: string, filter: Record<string, any>, updates: Record<string, any>, bypassRipple?: boolean, ttl?: number) => FunctionStageConfig;
|
|
176
|
+
updateById: (collection: string, record_id: string, updates: Record<string, any>, bypassRipple?: boolean, ttl?: number) => FunctionStageConfig;
|
|
177
|
+
delete: (collection: string, filter: Record<string, any>, bypassRipple?: boolean) => FunctionStageConfig;
|
|
178
|
+
deleteById: (collection: string, record_id: string, bypassRipple?: boolean) => FunctionStageConfig;
|
|
179
|
+
batchInsert: (collection: string, records: Record<string, any>[], bypassRipple?: boolean) => FunctionStageConfig;
|
|
180
|
+
batchDelete: (collection: string, record_ids: string[], bypassRipple?: boolean) => FunctionStageConfig;
|
|
181
|
+
filter: (filter: Record<string, any>) => FunctionStageConfig;
|
|
182
|
+
sort: (sort: SortFieldConfig[]) => FunctionStageConfig;
|
|
183
|
+
limit: (limit: number) => FunctionStageConfig;
|
|
184
|
+
skip: (skip: number) => FunctionStageConfig;
|
|
185
|
+
httpRequest: (url: string, method?: string, headers?: Record<string, string>, body?: any) => FunctionStageConfig;
|
|
186
|
+
vectorSearch: (collection: string, query_vector: number[], limit?: number, threshold?: number) => FunctionStageConfig;
|
|
187
|
+
textSearch: (collection: string, query_text: string, options?: {
|
|
188
|
+
fields?: string[];
|
|
189
|
+
limit?: number;
|
|
190
|
+
fuzzy?: boolean;
|
|
191
|
+
}) => FunctionStageConfig;
|
|
192
|
+
hybridSearch: (collection: string, query_text: string, query_vector?: number[], limit?: number) => FunctionStageConfig;
|
|
193
|
+
chat: (messages: ChatMessage[], model?: string, temperature?: number, max_tokens?: number) => FunctionStageConfig;
|
|
194
|
+
embed: (input_field: string, output_field: string, model?: string) => FunctionStageConfig;
|
|
195
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Scripts API for ekoDB TypeScript client
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Stage = exports.ChatMessage = void 0;
|
|
7
|
+
exports.ChatMessage = {
|
|
8
|
+
system: (content) => ({
|
|
9
|
+
role: "system",
|
|
10
|
+
content: content,
|
|
11
|
+
}),
|
|
12
|
+
user: (content) => ({
|
|
13
|
+
role: "user",
|
|
14
|
+
content: content,
|
|
15
|
+
}),
|
|
16
|
+
assistant: (content) => ({
|
|
17
|
+
role: "assistant",
|
|
18
|
+
content: content,
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
// Stage builder functions
|
|
22
|
+
exports.Stage = {
|
|
23
|
+
findAll: (collection) => ({
|
|
24
|
+
type: "FindAll",
|
|
25
|
+
collection,
|
|
26
|
+
}),
|
|
27
|
+
query: (collection, filter, sort, limit, skip) => ({
|
|
28
|
+
type: "Query",
|
|
29
|
+
collection,
|
|
30
|
+
filter,
|
|
31
|
+
sort,
|
|
32
|
+
limit,
|
|
33
|
+
skip,
|
|
34
|
+
}),
|
|
35
|
+
project: (fields, exclude = false) => ({
|
|
36
|
+
type: "Project",
|
|
37
|
+
fields,
|
|
38
|
+
exclude,
|
|
39
|
+
}),
|
|
40
|
+
group: (by_fields, functions) => ({
|
|
41
|
+
type: "Group",
|
|
42
|
+
by_fields,
|
|
43
|
+
functions,
|
|
44
|
+
}),
|
|
45
|
+
count: (output_field = "count") => ({
|
|
46
|
+
type: "Count",
|
|
47
|
+
output_field,
|
|
48
|
+
}),
|
|
49
|
+
insert: (collection, record, bypassRipple = false, ttl) => ({
|
|
50
|
+
type: "Insert",
|
|
51
|
+
collection,
|
|
52
|
+
record,
|
|
53
|
+
bypass_ripple: bypassRipple,
|
|
54
|
+
ttl,
|
|
55
|
+
}),
|
|
56
|
+
update: (collection, filter, updates, bypassRipple = false, ttl) => ({
|
|
57
|
+
type: "Update",
|
|
58
|
+
collection,
|
|
59
|
+
filter,
|
|
60
|
+
updates,
|
|
61
|
+
bypass_ripple: bypassRipple,
|
|
62
|
+
ttl,
|
|
63
|
+
}),
|
|
64
|
+
updateById: (collection, record_id, updates, bypassRipple = false, ttl) => ({
|
|
65
|
+
type: "UpdateById",
|
|
66
|
+
collection,
|
|
67
|
+
record_id,
|
|
68
|
+
updates,
|
|
69
|
+
bypass_ripple: bypassRipple,
|
|
70
|
+
ttl,
|
|
71
|
+
}),
|
|
72
|
+
delete: (collection, filter, bypassRipple = false) => ({
|
|
73
|
+
type: "Delete",
|
|
74
|
+
collection,
|
|
75
|
+
filter,
|
|
76
|
+
bypass_ripple: bypassRipple,
|
|
77
|
+
}),
|
|
78
|
+
deleteById: (collection, record_id, bypassRipple = false) => ({
|
|
79
|
+
type: "DeleteById",
|
|
80
|
+
collection,
|
|
81
|
+
record_id,
|
|
82
|
+
bypass_ripple: bypassRipple,
|
|
83
|
+
}),
|
|
84
|
+
batchInsert: (collection, records, bypassRipple = false) => ({
|
|
85
|
+
type: "BatchInsert",
|
|
86
|
+
collection,
|
|
87
|
+
records,
|
|
88
|
+
bypass_ripple: bypassRipple,
|
|
89
|
+
}),
|
|
90
|
+
batchDelete: (collection, record_ids, bypassRipple = false) => ({
|
|
91
|
+
type: "BatchDelete",
|
|
92
|
+
collection,
|
|
93
|
+
record_ids,
|
|
94
|
+
bypass_ripple: bypassRipple,
|
|
95
|
+
}),
|
|
96
|
+
filter: (filter) => ({
|
|
97
|
+
type: "Filter",
|
|
98
|
+
filter,
|
|
99
|
+
}),
|
|
100
|
+
sort: (sort) => ({
|
|
101
|
+
type: "Sort",
|
|
102
|
+
sort,
|
|
103
|
+
}),
|
|
104
|
+
limit: (limit) => ({
|
|
105
|
+
type: "Limit",
|
|
106
|
+
limit,
|
|
107
|
+
}),
|
|
108
|
+
skip: (skip) => ({
|
|
109
|
+
type: "Skip",
|
|
110
|
+
skip,
|
|
111
|
+
}),
|
|
112
|
+
httpRequest: (url, method = "GET", headers, body) => ({
|
|
113
|
+
type: "HttpRequest",
|
|
114
|
+
url,
|
|
115
|
+
method,
|
|
116
|
+
headers,
|
|
117
|
+
body,
|
|
118
|
+
}),
|
|
119
|
+
vectorSearch: (collection, query_vector, limit, threshold) => ({
|
|
120
|
+
type: "VectorSearch",
|
|
121
|
+
collection,
|
|
122
|
+
query_vector,
|
|
123
|
+
limit,
|
|
124
|
+
threshold,
|
|
125
|
+
}),
|
|
126
|
+
textSearch: (collection, query_text, options) => ({
|
|
127
|
+
type: "TextSearch",
|
|
128
|
+
collection,
|
|
129
|
+
query_text,
|
|
130
|
+
fields: options?.fields,
|
|
131
|
+
limit: options?.limit,
|
|
132
|
+
fuzzy: options?.fuzzy,
|
|
133
|
+
}),
|
|
134
|
+
hybridSearch: (collection, query_text, query_vector, limit) => ({
|
|
135
|
+
type: "HybridSearch",
|
|
136
|
+
collection,
|
|
137
|
+
query_text,
|
|
138
|
+
query_vector,
|
|
139
|
+
limit,
|
|
140
|
+
}),
|
|
141
|
+
chat: (messages, model, temperature, max_tokens) => ({
|
|
142
|
+
type: "Chat",
|
|
143
|
+
messages,
|
|
144
|
+
model,
|
|
145
|
+
temperature,
|
|
146
|
+
max_tokens,
|
|
147
|
+
}),
|
|
148
|
+
embed: (input_field, output_field, model) => ({
|
|
149
|
+
type: "Embed",
|
|
150
|
+
input_field,
|
|
151
|
+
output_field,
|
|
152
|
+
model,
|
|
153
|
+
}),
|
|
154
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ export { QueryBuilder, SortOrder } from "./query-builder";
|
|
|
3
3
|
export { SearchQueryBuilder } from "./search";
|
|
4
4
|
export { SchemaBuilder, FieldTypeSchemaBuilder, VectorIndexAlgorithm, DistanceMetric, } from "./schema";
|
|
5
5
|
export { JoinBuilder } from "./join";
|
|
6
|
+
export { Stage, ChatMessage } from "./functions";
|
|
6
7
|
export type { SearchQuery, SearchResult, SearchResponse } from "./search";
|
|
7
8
|
export type { Schema, FieldTypeSchema, IndexConfig, CollectionMetadata, } from "./schema";
|
|
8
9
|
export type { JoinConfig } from "./join";
|
|
10
|
+
export type { Script, ParameterDefinition, FunctionStageConfig, GroupFunctionConfig, SortFieldConfig, FunctionResult, FunctionStats, StageStats, } from "./functions";
|
|
9
11
|
export type { Record, Query, BatchOperationResult, ClientConfig, RateLimitInfo, CollectionConfig, ChatRequest, CreateChatSessionRequest, ChatMessageRequest, TokenUsage, ChatResponse, ChatSession, ChatSessionResponse, ListSessionsQuery, ListSessionsResponse, GetMessagesQuery, GetMessagesResponse, UpdateSessionRequest, MergeSessionsRequest, } from "./client";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JoinBuilder = exports.DistanceMetric = exports.VectorIndexAlgorithm = exports.FieldTypeSchemaBuilder = exports.SchemaBuilder = exports.SearchQueryBuilder = exports.SortOrder = exports.QueryBuilder = exports.RateLimitError = exports.MergeStrategy = exports.SerializationFormat = exports.WebSocketClient = exports.EkoDBClient = void 0;
|
|
3
|
+
exports.ChatMessage = exports.Stage = exports.JoinBuilder = exports.DistanceMetric = exports.VectorIndexAlgorithm = exports.FieldTypeSchemaBuilder = exports.SchemaBuilder = exports.SearchQueryBuilder = exports.SortOrder = exports.QueryBuilder = exports.RateLimitError = exports.MergeStrategy = exports.SerializationFormat = exports.WebSocketClient = exports.EkoDBClient = void 0;
|
|
4
4
|
var client_1 = require("./client");
|
|
5
5
|
Object.defineProperty(exports, "EkoDBClient", { enumerable: true, get: function () { return client_1.EkoDBClient; } });
|
|
6
6
|
Object.defineProperty(exports, "WebSocketClient", { enumerable: true, get: function () { return client_1.WebSocketClient; } });
|
|
@@ -19,3 +19,6 @@ Object.defineProperty(exports, "VectorIndexAlgorithm", { enumerable: true, get:
|
|
|
19
19
|
Object.defineProperty(exports, "DistanceMetric", { enumerable: true, get: function () { return schema_1.DistanceMetric; } });
|
|
20
20
|
var join_1 = require("./join");
|
|
21
21
|
Object.defineProperty(exports, "JoinBuilder", { enumerable: true, get: function () { return join_1.JoinBuilder; } });
|
|
22
|
+
var functions_1 = require("./functions");
|
|
23
|
+
Object.defineProperty(exports, "Stage", { enumerable: true, get: function () { return functions_1.Stage; } });
|
|
24
|
+
Object.defineProperty(exports, "ChatMessage", { enumerable: true, get: function () { return functions_1.ChatMessage; } });
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { encode, decode } from "@msgpack/msgpack";
|
|
|
6
6
|
import { QueryBuilder, Query as QueryBuilderQuery } from "./query-builder";
|
|
7
7
|
import { SearchQuery, SearchQueryBuilder, SearchResponse } from "./search";
|
|
8
8
|
import { Schema, SchemaBuilder, CollectionMetadata } from "./schema";
|
|
9
|
+
import { Script, FunctionResult } from "./functions";
|
|
9
10
|
|
|
10
11
|
export interface Record {
|
|
11
12
|
[key: string]: any;
|
|
@@ -954,6 +955,65 @@ export class EkoDBClient {
|
|
|
954
955
|
);
|
|
955
956
|
}
|
|
956
957
|
|
|
958
|
+
// ========================================================================
|
|
959
|
+
// SCRIPTS API
|
|
960
|
+
// ========================================================================
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* Save a new script definition
|
|
964
|
+
*/
|
|
965
|
+
async saveScript(script: Script): Promise<string> {
|
|
966
|
+
const result = await this.makeRequest<{ id: string }>(
|
|
967
|
+
"POST",
|
|
968
|
+
"/api/functions",
|
|
969
|
+
script,
|
|
970
|
+
);
|
|
971
|
+
return result.id;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* Get a script by ID
|
|
976
|
+
*/
|
|
977
|
+
async getScript(id: string): Promise<Script> {
|
|
978
|
+
return this.makeRequest<Script>("GET", `/api/functions/${id}`);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* List all scripts, optionally filtered by tags
|
|
983
|
+
*/
|
|
984
|
+
async listScripts(tags?: string[]): Promise<Script[]> {
|
|
985
|
+
const params = tags ? `?tags=${tags.join(",")}` : "";
|
|
986
|
+
return this.makeRequest<Script[]>("GET", `/api/functions${params}`);
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
/**
|
|
990
|
+
* Update an existing script by ID
|
|
991
|
+
*/
|
|
992
|
+
async updateScript(id: string, script: Script): Promise<void> {
|
|
993
|
+
await this.makeRequest<void>("PUT", `/api/functions/${id}`, script);
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* Delete a script by ID
|
|
998
|
+
*/
|
|
999
|
+
async deleteScript(id: string): Promise<void> {
|
|
1000
|
+
await this.makeRequest<void>("DELETE", `/api/functions/${id}`);
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
/**
|
|
1004
|
+
* Call a saved script by ID or label
|
|
1005
|
+
*/
|
|
1006
|
+
async callScript(
|
|
1007
|
+
idOrLabel: string,
|
|
1008
|
+
params?: { [key: string]: any },
|
|
1009
|
+
): Promise<FunctionResult> {
|
|
1010
|
+
return this.makeRequest<FunctionResult>(
|
|
1011
|
+
"POST",
|
|
1012
|
+
`/api/functions/${idOrLabel}`,
|
|
1013
|
+
params || {},
|
|
1014
|
+
);
|
|
1015
|
+
}
|
|
1016
|
+
|
|
957
1017
|
/**
|
|
958
1018
|
* Create a WebSocket client
|
|
959
1019
|
*/
|
package/src/functions.ts
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scripts API for ekoDB TypeScript client
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface Script {
|
|
6
|
+
label: string;
|
|
7
|
+
name: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
version: string;
|
|
10
|
+
parameters: { [key: string]: ParameterDefinition };
|
|
11
|
+
functions: FunctionStageConfig[];
|
|
12
|
+
tags: string[];
|
|
13
|
+
created_at?: string;
|
|
14
|
+
updated_at?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ParameterDefinition {
|
|
18
|
+
required: boolean;
|
|
19
|
+
default?: any;
|
|
20
|
+
description?: string;
|
|
21
|
+
param_type?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// ParameterValue removed - use plain values instead
|
|
25
|
+
|
|
26
|
+
export type FunctionStageConfig =
|
|
27
|
+
| { type: "FindAll"; collection: string }
|
|
28
|
+
| {
|
|
29
|
+
type: "Query";
|
|
30
|
+
collection: string;
|
|
31
|
+
filter?: Record<string, any>;
|
|
32
|
+
sort?: SortFieldConfig[];
|
|
33
|
+
limit?: number;
|
|
34
|
+
skip?: number;
|
|
35
|
+
}
|
|
36
|
+
| { type: "Project"; fields: string[]; exclude: boolean }
|
|
37
|
+
| {
|
|
38
|
+
type: "Group";
|
|
39
|
+
by_fields: string[];
|
|
40
|
+
functions: GroupFunctionConfig[];
|
|
41
|
+
}
|
|
42
|
+
| { type: "Count"; output_field: string }
|
|
43
|
+
| { type: "Filter"; filter: Record<string, any> }
|
|
44
|
+
| { type: "Sort"; sort: SortFieldConfig[] }
|
|
45
|
+
| { type: "Limit"; limit: number }
|
|
46
|
+
| { type: "Skip"; skip: number }
|
|
47
|
+
| {
|
|
48
|
+
type: "Insert";
|
|
49
|
+
collection: string;
|
|
50
|
+
record: Record<string, any>;
|
|
51
|
+
bypass_ripple?: boolean;
|
|
52
|
+
ttl?: number;
|
|
53
|
+
}
|
|
54
|
+
| {
|
|
55
|
+
type: "Update";
|
|
56
|
+
collection: string;
|
|
57
|
+
filter: Record<string, any>;
|
|
58
|
+
updates: Record<string, any>;
|
|
59
|
+
bypass_ripple?: boolean;
|
|
60
|
+
ttl?: number;
|
|
61
|
+
}
|
|
62
|
+
| {
|
|
63
|
+
type: "UpdateById";
|
|
64
|
+
collection: string;
|
|
65
|
+
record_id: string;
|
|
66
|
+
updates: Record<string, any>;
|
|
67
|
+
bypass_ripple?: boolean;
|
|
68
|
+
ttl?: number;
|
|
69
|
+
}
|
|
70
|
+
| {
|
|
71
|
+
type: "Delete";
|
|
72
|
+
collection: string;
|
|
73
|
+
filter: Record<string, any>;
|
|
74
|
+
bypass_ripple?: boolean;
|
|
75
|
+
}
|
|
76
|
+
| {
|
|
77
|
+
type: "DeleteById";
|
|
78
|
+
collection: string;
|
|
79
|
+
record_id: string;
|
|
80
|
+
bypass_ripple?: boolean;
|
|
81
|
+
}
|
|
82
|
+
| {
|
|
83
|
+
type: "BatchInsert";
|
|
84
|
+
collection: string;
|
|
85
|
+
records: Record<string, any>[];
|
|
86
|
+
bypass_ripple?: boolean;
|
|
87
|
+
}
|
|
88
|
+
| {
|
|
89
|
+
type: "BatchDelete";
|
|
90
|
+
collection: string;
|
|
91
|
+
record_ids: string[];
|
|
92
|
+
bypass_ripple?: boolean;
|
|
93
|
+
}
|
|
94
|
+
| {
|
|
95
|
+
type: "HttpRequest";
|
|
96
|
+
url: string;
|
|
97
|
+
method?: string;
|
|
98
|
+
headers?: Record<string, string>;
|
|
99
|
+
body?: any;
|
|
100
|
+
}
|
|
101
|
+
| {
|
|
102
|
+
type: "VectorSearch";
|
|
103
|
+
collection: string;
|
|
104
|
+
query_vector: number[];
|
|
105
|
+
limit?: number;
|
|
106
|
+
threshold?: number;
|
|
107
|
+
}
|
|
108
|
+
| {
|
|
109
|
+
type: "TextSearch";
|
|
110
|
+
collection: string;
|
|
111
|
+
query_text: string;
|
|
112
|
+
fields?: string[];
|
|
113
|
+
limit?: number;
|
|
114
|
+
fuzzy?: boolean;
|
|
115
|
+
}
|
|
116
|
+
| {
|
|
117
|
+
type: "HybridSearch";
|
|
118
|
+
collection: string;
|
|
119
|
+
query_text: string;
|
|
120
|
+
query_vector?: number[];
|
|
121
|
+
limit?: number;
|
|
122
|
+
}
|
|
123
|
+
| {
|
|
124
|
+
type: "Chat";
|
|
125
|
+
messages: ChatMessage[];
|
|
126
|
+
model?: string;
|
|
127
|
+
temperature?: number;
|
|
128
|
+
max_tokens?: number;
|
|
129
|
+
}
|
|
130
|
+
| {
|
|
131
|
+
type: "Embed";
|
|
132
|
+
input_field: string;
|
|
133
|
+
output_field: string;
|
|
134
|
+
model?: string;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export interface ChatMessage {
|
|
138
|
+
role: string;
|
|
139
|
+
content: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const ChatMessage = {
|
|
143
|
+
system: (content: string): ChatMessage => ({
|
|
144
|
+
role: "system",
|
|
145
|
+
content: content,
|
|
146
|
+
}),
|
|
147
|
+
user: (content: string): ChatMessage => ({
|
|
148
|
+
role: "user",
|
|
149
|
+
content: content,
|
|
150
|
+
}),
|
|
151
|
+
assistant: (content: string): ChatMessage => ({
|
|
152
|
+
role: "assistant",
|
|
153
|
+
content: content,
|
|
154
|
+
}),
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export interface GroupFunctionConfig {
|
|
158
|
+
output_field: string;
|
|
159
|
+
operation:
|
|
160
|
+
| "Sum"
|
|
161
|
+
| "Average"
|
|
162
|
+
| "Count"
|
|
163
|
+
| "Min"
|
|
164
|
+
| "Max"
|
|
165
|
+
| "First"
|
|
166
|
+
| "Last"
|
|
167
|
+
| "Push";
|
|
168
|
+
input_field?: string;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface SortFieldConfig {
|
|
172
|
+
field: string;
|
|
173
|
+
ascending: boolean;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface FunctionResult {
|
|
177
|
+
records: Record<string, any>[];
|
|
178
|
+
stats: FunctionStats;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface FunctionStats {
|
|
182
|
+
input_count: number;
|
|
183
|
+
output_count: number;
|
|
184
|
+
execution_time_ms: number;
|
|
185
|
+
stages_executed: number;
|
|
186
|
+
stage_stats: StageStats[];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export interface StageStats {
|
|
190
|
+
stage: string;
|
|
191
|
+
input_count: number;
|
|
192
|
+
output_count: number;
|
|
193
|
+
execution_time_ms: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Stage builder functions
|
|
197
|
+
export const Stage = {
|
|
198
|
+
findAll: (collection: string): FunctionStageConfig => ({
|
|
199
|
+
type: "FindAll",
|
|
200
|
+
collection,
|
|
201
|
+
}),
|
|
202
|
+
|
|
203
|
+
query: (
|
|
204
|
+
collection: string,
|
|
205
|
+
filter?: Record<string, any>,
|
|
206
|
+
sort?: SortFieldConfig[],
|
|
207
|
+
limit?: number,
|
|
208
|
+
skip?: number,
|
|
209
|
+
): FunctionStageConfig => ({
|
|
210
|
+
type: "Query",
|
|
211
|
+
collection,
|
|
212
|
+
filter,
|
|
213
|
+
sort,
|
|
214
|
+
limit,
|
|
215
|
+
skip,
|
|
216
|
+
}),
|
|
217
|
+
|
|
218
|
+
project: (fields: string[], exclude = false): FunctionStageConfig => ({
|
|
219
|
+
type: "Project",
|
|
220
|
+
fields,
|
|
221
|
+
exclude,
|
|
222
|
+
}),
|
|
223
|
+
|
|
224
|
+
group: (
|
|
225
|
+
by_fields: string[],
|
|
226
|
+
functions: GroupFunctionConfig[],
|
|
227
|
+
): FunctionStageConfig => ({
|
|
228
|
+
type: "Group",
|
|
229
|
+
by_fields,
|
|
230
|
+
functions,
|
|
231
|
+
}),
|
|
232
|
+
|
|
233
|
+
count: (output_field = "count"): FunctionStageConfig => ({
|
|
234
|
+
type: "Count",
|
|
235
|
+
output_field,
|
|
236
|
+
}),
|
|
237
|
+
|
|
238
|
+
insert: (
|
|
239
|
+
collection: string,
|
|
240
|
+
record: Record<string, any>,
|
|
241
|
+
bypassRipple = false,
|
|
242
|
+
ttl?: number,
|
|
243
|
+
): FunctionStageConfig => ({
|
|
244
|
+
type: "Insert",
|
|
245
|
+
collection,
|
|
246
|
+
record,
|
|
247
|
+
bypass_ripple: bypassRipple,
|
|
248
|
+
ttl,
|
|
249
|
+
}),
|
|
250
|
+
|
|
251
|
+
update: (
|
|
252
|
+
collection: string,
|
|
253
|
+
filter: Record<string, any>,
|
|
254
|
+
updates: Record<string, any>,
|
|
255
|
+
bypassRipple = false,
|
|
256
|
+
ttl?: number,
|
|
257
|
+
): FunctionStageConfig => ({
|
|
258
|
+
type: "Update",
|
|
259
|
+
collection,
|
|
260
|
+
filter,
|
|
261
|
+
updates,
|
|
262
|
+
bypass_ripple: bypassRipple,
|
|
263
|
+
ttl,
|
|
264
|
+
}),
|
|
265
|
+
|
|
266
|
+
updateById: (
|
|
267
|
+
collection: string,
|
|
268
|
+
record_id: string,
|
|
269
|
+
updates: Record<string, any>,
|
|
270
|
+
bypassRipple = false,
|
|
271
|
+
ttl?: number,
|
|
272
|
+
): FunctionStageConfig => ({
|
|
273
|
+
type: "UpdateById",
|
|
274
|
+
collection,
|
|
275
|
+
record_id,
|
|
276
|
+
updates,
|
|
277
|
+
bypass_ripple: bypassRipple,
|
|
278
|
+
ttl,
|
|
279
|
+
}),
|
|
280
|
+
|
|
281
|
+
delete: (
|
|
282
|
+
collection: string,
|
|
283
|
+
filter: Record<string, any>,
|
|
284
|
+
bypassRipple = false,
|
|
285
|
+
): FunctionStageConfig => ({
|
|
286
|
+
type: "Delete",
|
|
287
|
+
collection,
|
|
288
|
+
filter,
|
|
289
|
+
bypass_ripple: bypassRipple,
|
|
290
|
+
}),
|
|
291
|
+
|
|
292
|
+
deleteById: (
|
|
293
|
+
collection: string,
|
|
294
|
+
record_id: string,
|
|
295
|
+
bypassRipple = false,
|
|
296
|
+
): FunctionStageConfig => ({
|
|
297
|
+
type: "DeleteById",
|
|
298
|
+
collection,
|
|
299
|
+
record_id,
|
|
300
|
+
bypass_ripple: bypassRipple,
|
|
301
|
+
}),
|
|
302
|
+
|
|
303
|
+
batchInsert: (
|
|
304
|
+
collection: string,
|
|
305
|
+
records: Record<string, any>[],
|
|
306
|
+
bypassRipple = false,
|
|
307
|
+
): FunctionStageConfig => ({
|
|
308
|
+
type: "BatchInsert",
|
|
309
|
+
collection,
|
|
310
|
+
records,
|
|
311
|
+
bypass_ripple: bypassRipple,
|
|
312
|
+
}),
|
|
313
|
+
|
|
314
|
+
batchDelete: (
|
|
315
|
+
collection: string,
|
|
316
|
+
record_ids: string[],
|
|
317
|
+
bypassRipple = false,
|
|
318
|
+
): FunctionStageConfig => ({
|
|
319
|
+
type: "BatchDelete",
|
|
320
|
+
collection,
|
|
321
|
+
record_ids,
|
|
322
|
+
bypass_ripple: bypassRipple,
|
|
323
|
+
}),
|
|
324
|
+
|
|
325
|
+
filter: (filter: Record<string, any>): FunctionStageConfig => ({
|
|
326
|
+
type: "Filter",
|
|
327
|
+
filter,
|
|
328
|
+
}),
|
|
329
|
+
|
|
330
|
+
sort: (sort: SortFieldConfig[]): FunctionStageConfig => ({
|
|
331
|
+
type: "Sort",
|
|
332
|
+
sort,
|
|
333
|
+
}),
|
|
334
|
+
|
|
335
|
+
limit: (limit: number): FunctionStageConfig => ({
|
|
336
|
+
type: "Limit",
|
|
337
|
+
limit,
|
|
338
|
+
}),
|
|
339
|
+
|
|
340
|
+
skip: (skip: number): FunctionStageConfig => ({
|
|
341
|
+
type: "Skip",
|
|
342
|
+
skip,
|
|
343
|
+
}),
|
|
344
|
+
|
|
345
|
+
httpRequest: (
|
|
346
|
+
url: string,
|
|
347
|
+
method = "GET",
|
|
348
|
+
headers?: Record<string, string>,
|
|
349
|
+
body?: any,
|
|
350
|
+
): FunctionStageConfig => ({
|
|
351
|
+
type: "HttpRequest",
|
|
352
|
+
url,
|
|
353
|
+
method,
|
|
354
|
+
headers,
|
|
355
|
+
body,
|
|
356
|
+
}),
|
|
357
|
+
|
|
358
|
+
vectorSearch: (
|
|
359
|
+
collection: string,
|
|
360
|
+
query_vector: number[],
|
|
361
|
+
limit?: number,
|
|
362
|
+
threshold?: number,
|
|
363
|
+
): FunctionStageConfig => ({
|
|
364
|
+
type: "VectorSearch",
|
|
365
|
+
collection,
|
|
366
|
+
query_vector,
|
|
367
|
+
limit,
|
|
368
|
+
threshold,
|
|
369
|
+
}),
|
|
370
|
+
|
|
371
|
+
textSearch: (
|
|
372
|
+
collection: string,
|
|
373
|
+
query_text: string,
|
|
374
|
+
options?: { fields?: string[]; limit?: number; fuzzy?: boolean },
|
|
375
|
+
): FunctionStageConfig => ({
|
|
376
|
+
type: "TextSearch",
|
|
377
|
+
collection,
|
|
378
|
+
query_text,
|
|
379
|
+
fields: options?.fields,
|
|
380
|
+
limit: options?.limit,
|
|
381
|
+
fuzzy: options?.fuzzy,
|
|
382
|
+
}),
|
|
383
|
+
|
|
384
|
+
hybridSearch: (
|
|
385
|
+
collection: string,
|
|
386
|
+
query_text: string,
|
|
387
|
+
query_vector?: number[],
|
|
388
|
+
limit?: number,
|
|
389
|
+
): FunctionStageConfig => ({
|
|
390
|
+
type: "HybridSearch",
|
|
391
|
+
collection,
|
|
392
|
+
query_text,
|
|
393
|
+
query_vector,
|
|
394
|
+
limit,
|
|
395
|
+
}),
|
|
396
|
+
|
|
397
|
+
chat: (
|
|
398
|
+
messages: ChatMessage[],
|
|
399
|
+
model?: string,
|
|
400
|
+
temperature?: number,
|
|
401
|
+
max_tokens?: number,
|
|
402
|
+
): FunctionStageConfig => ({
|
|
403
|
+
type: "Chat",
|
|
404
|
+
messages,
|
|
405
|
+
model,
|
|
406
|
+
temperature,
|
|
407
|
+
max_tokens,
|
|
408
|
+
}),
|
|
409
|
+
|
|
410
|
+
embed: (
|
|
411
|
+
input_field: string,
|
|
412
|
+
output_field: string,
|
|
413
|
+
model?: string,
|
|
414
|
+
): FunctionStageConfig => ({
|
|
415
|
+
type: "Embed",
|
|
416
|
+
input_field,
|
|
417
|
+
output_field,
|
|
418
|
+
model,
|
|
419
|
+
}),
|
|
420
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export {
|
|
|
14
14
|
DistanceMetric,
|
|
15
15
|
} from "./schema";
|
|
16
16
|
export { JoinBuilder } from "./join";
|
|
17
|
+
export { Stage, ChatMessage } from "./functions";
|
|
17
18
|
export type { SearchQuery, SearchResult, SearchResponse } from "./search";
|
|
18
19
|
export type {
|
|
19
20
|
Schema,
|
|
@@ -22,6 +23,16 @@ export type {
|
|
|
22
23
|
CollectionMetadata,
|
|
23
24
|
} from "./schema";
|
|
24
25
|
export type { JoinConfig } from "./join";
|
|
26
|
+
export type {
|
|
27
|
+
Script,
|
|
28
|
+
ParameterDefinition,
|
|
29
|
+
FunctionStageConfig,
|
|
30
|
+
GroupFunctionConfig,
|
|
31
|
+
SortFieldConfig,
|
|
32
|
+
FunctionResult,
|
|
33
|
+
FunctionStats,
|
|
34
|
+
StageStats,
|
|
35
|
+
} from "./functions";
|
|
25
36
|
export type {
|
|
26
37
|
Record,
|
|
27
38
|
Query,
|