@antfly/sdk 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +79 -6
- package/dist/index.d.cts +524 -80
- package/dist/index.d.ts +524 -80
- package/dist/index.js +79 -6
- package/package.json +35 -26
package/dist/index.cjs
CHANGED
|
@@ -161,14 +161,87 @@ var AntflyClient = class {
|
|
|
161
161
|
},
|
|
162
162
|
/**
|
|
163
163
|
* Lookup a specific key in a table
|
|
164
|
+
* @param tableName - Name of the table
|
|
165
|
+
* @param key - Key of the record to lookup
|
|
166
|
+
* @param options - Optional parameters
|
|
167
|
+
* @param options.fields - Comma-separated list of fields to include (e.g., "title,author,metadata.tags")
|
|
164
168
|
*/
|
|
165
|
-
lookup: async (tableName, key) => {
|
|
169
|
+
lookup: async (tableName, key, options) => {
|
|
166
170
|
const { data, error } = await this.client.GET("/tables/{tableName}/lookup/{key}", {
|
|
167
|
-
params: {
|
|
171
|
+
params: {
|
|
172
|
+
path: { tableName, key },
|
|
173
|
+
query: options?.fields ? { fields: options.fields } : void 0
|
|
174
|
+
}
|
|
168
175
|
});
|
|
169
176
|
if (error) throw new Error(`Key lookup failed: ${error.error}`);
|
|
170
177
|
return data;
|
|
171
178
|
},
|
|
179
|
+
/**
|
|
180
|
+
* Scan keys in a table within a key range
|
|
181
|
+
* Returns documents as an async iterable, streaming results as NDJSON.
|
|
182
|
+
* @param tableName - Name of the table
|
|
183
|
+
* @param request - Scan request with optional key range, field projection, and filtering
|
|
184
|
+
* @returns AsyncGenerator yielding documents with their keys
|
|
185
|
+
*/
|
|
186
|
+
scan: (tableName, request) => {
|
|
187
|
+
const config = this.config;
|
|
188
|
+
async function* scanGenerator() {
|
|
189
|
+
const headers = {
|
|
190
|
+
"Content-Type": "application/json",
|
|
191
|
+
Accept: "application/x-ndjson"
|
|
192
|
+
};
|
|
193
|
+
if (config.auth) {
|
|
194
|
+
const auth = btoa(`${config.auth.username}:${config.auth.password}`);
|
|
195
|
+
headers["Authorization"] = `Basic ${auth}`;
|
|
196
|
+
}
|
|
197
|
+
Object.assign(headers, config.headers);
|
|
198
|
+
const response = await fetch(`${config.baseUrl}/tables/${tableName}/lookup`, {
|
|
199
|
+
method: "POST",
|
|
200
|
+
headers,
|
|
201
|
+
body: JSON.stringify(request || {})
|
|
202
|
+
});
|
|
203
|
+
if (!response.ok) {
|
|
204
|
+
const errorText = await response.text();
|
|
205
|
+
throw new Error(`Scan failed: ${response.status} ${errorText}`);
|
|
206
|
+
}
|
|
207
|
+
if (!response.body) {
|
|
208
|
+
throw new Error("Response body is null");
|
|
209
|
+
}
|
|
210
|
+
const reader = response.body.getReader();
|
|
211
|
+
const decoder = new TextDecoder();
|
|
212
|
+
let buffer = "";
|
|
213
|
+
while (true) {
|
|
214
|
+
const { done, value } = await reader.read();
|
|
215
|
+
if (done) break;
|
|
216
|
+
buffer += decoder.decode(value, { stream: true });
|
|
217
|
+
const lines = buffer.split("\n");
|
|
218
|
+
buffer = lines.pop() || "";
|
|
219
|
+
for (const line of lines) {
|
|
220
|
+
if (line.trim()) {
|
|
221
|
+
yield JSON.parse(line);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (buffer.trim()) {
|
|
226
|
+
yield JSON.parse(buffer);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return scanGenerator();
|
|
230
|
+
},
|
|
231
|
+
/**
|
|
232
|
+
* Scan keys in a table and collect all results into an array
|
|
233
|
+
* Convenience method that consumes the scan AsyncGenerator
|
|
234
|
+
* @param tableName - Name of the table
|
|
235
|
+
* @param request - Scan request with optional key range, field projection, and filtering
|
|
236
|
+
* @returns Promise with array of all matching documents
|
|
237
|
+
*/
|
|
238
|
+
scanAll: async (tableName, request) => {
|
|
239
|
+
const results = [];
|
|
240
|
+
for await (const doc of this.tables.scan(tableName, request)) {
|
|
241
|
+
results.push(doc);
|
|
242
|
+
}
|
|
243
|
+
return results;
|
|
244
|
+
},
|
|
172
245
|
/**
|
|
173
246
|
* RAG (Retrieval-Augmented Generation) query on a specific table with streaming or citations
|
|
174
247
|
* @param tableName - Name of the table to query
|
|
@@ -610,7 +683,7 @@ var AntflyClient = class {
|
|
|
610
683
|
break;
|
|
611
684
|
case "reasoning":
|
|
612
685
|
if (callbacks.onReasoning) {
|
|
613
|
-
callbacks.onReasoning(data);
|
|
686
|
+
callbacks.onReasoning(JSON.parse(data));
|
|
614
687
|
}
|
|
615
688
|
break;
|
|
616
689
|
case "hits_start":
|
|
@@ -633,7 +706,7 @@ var AntflyClient = class {
|
|
|
633
706
|
break;
|
|
634
707
|
case "answer":
|
|
635
708
|
if (callbacks.onAnswer) {
|
|
636
|
-
callbacks.onAnswer(data);
|
|
709
|
+
callbacks.onAnswer(JSON.parse(data));
|
|
637
710
|
}
|
|
638
711
|
break;
|
|
639
712
|
case "confidence":
|
|
@@ -644,7 +717,7 @@ var AntflyClient = class {
|
|
|
644
717
|
break;
|
|
645
718
|
case "followup_question":
|
|
646
719
|
if (callbacks.onFollowUpQuestion) {
|
|
647
|
-
callbacks.onFollowUpQuestion(data);
|
|
720
|
+
callbacks.onFollowUpQuestion(JSON.parse(data));
|
|
648
721
|
}
|
|
649
722
|
break;
|
|
650
723
|
case "done":
|
|
@@ -808,7 +881,7 @@ var AntflyClient = class {
|
|
|
808
881
|
break;
|
|
809
882
|
case "answer":
|
|
810
883
|
if (callbacks.onAnswer) {
|
|
811
|
-
callbacks.onAnswer(data);
|
|
884
|
+
callbacks.onAnswer(JSON.parse(data));
|
|
812
885
|
}
|
|
813
886
|
break;
|
|
814
887
|
case "done":
|