conare 0.20.0 → 0.21.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/README.md +61 -36
- package/dist/index.d.ts +453 -45
- package/dist/index.js +565 -52
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.21.0";
|
|
2
2
|
/** A metadata value: string, number, boolean or an array of strings. */
|
|
3
3
|
export type MetadataValue = string | number | boolean | string[];
|
|
4
4
|
export type Metadata = Record<string, MetadataValue>;
|
|
5
5
|
type Scalar = string | number | boolean;
|
|
6
6
|
/**
|
|
7
|
-
* Operators for one metadata key: `$eq`, `$in
|
|
8
|
-
* compares a number or string value (not an array item): number
|
|
9
|
-
* bounds compare strings by their UTF-8 bytes (ISO dates sort as
|
|
10
|
-
*
|
|
7
|
+
* Operators for one metadata key: `$eq`, `$in`, the ranges `$gt` `$gte` `$lt` `$lte`, and in a
|
|
8
|
+
* query `$ne` and `$nin`. A range compares a number or string value (not an array item): number
|
|
9
|
+
* bounds compare numbers, string bounds compare strings by their UTF-8 bytes (ISO dates sort as
|
|
10
|
+
* dates). `$ne` / `$nin` match a document without the key, or whose array holds none of the
|
|
11
|
+
* values; `deleteWhere` refuses them (400 invalid_filter).
|
|
11
12
|
*/
|
|
12
13
|
export interface FilterOperators {
|
|
13
14
|
$eq?: Scalar;
|
|
@@ -16,8 +17,8 @@ export interface FilterOperators {
|
|
|
16
17
|
$gte?: number | string;
|
|
17
18
|
$lt?: number | string;
|
|
18
19
|
$lte?: number | string;
|
|
19
|
-
$ne?:
|
|
20
|
-
$nin?:
|
|
20
|
+
$ne?: Scalar;
|
|
21
|
+
$nin?: Scalar[];
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
24
|
* A metadata filter. `{ team: "support" }` means equals (or, for an array value, contains);
|
|
@@ -83,9 +84,19 @@ export interface FileUpload {
|
|
|
83
84
|
pagesOcr: number;
|
|
84
85
|
/** PDF pages with no text even after OCR (blank, or OCR could not read them): not stored. */
|
|
85
86
|
pagesWithoutText: number[];
|
|
86
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* PDF pages OCR reads after the answer (without `wait`): each is stored, marked `ocr`, within about a minute.
|
|
89
|
+
* `getFile(fileId)` says when OCR ended and which of them it could not read.
|
|
90
|
+
*/
|
|
87
91
|
ocrPending: number[];
|
|
88
92
|
}
|
|
93
|
+
/** What `getFile` reads: an upload's outcome, with OCR after the answer folded in as it ends. */
|
|
94
|
+
export interface FileStatus extends FileUpload {
|
|
95
|
+
/** The file's name as uploaded. */
|
|
96
|
+
name: string;
|
|
97
|
+
/** When it was uploaded. */
|
|
98
|
+
uploadedAt: Date;
|
|
99
|
+
}
|
|
89
100
|
export interface Document {
|
|
90
101
|
id: string;
|
|
91
102
|
text: string;
|
|
@@ -119,11 +130,33 @@ export interface QueryResult {
|
|
|
119
130
|
/** The document's user, when it has one. */
|
|
120
131
|
user?: string;
|
|
121
132
|
}
|
|
122
|
-
/** What a query fuses: the embedding model
|
|
123
|
-
export type Retriever = "vector" | "keyword"
|
|
133
|
+
/** What a query fuses: the embedding model and BM25 keywords. */
|
|
134
|
+
export type Retriever = "vector" | "keyword";
|
|
135
|
+
/** The options of `Namespace.query` and `Namespace.queryPages`. */
|
|
136
|
+
export interface QueryOptions extends RequestOptions {
|
|
137
|
+
topK?: number;
|
|
138
|
+
filter?: Filter;
|
|
139
|
+
rerank?: boolean;
|
|
140
|
+
rerankDepth?: number;
|
|
141
|
+
retrievers?: Retriever[];
|
|
142
|
+
user?: string;
|
|
143
|
+
userPrefix?: string;
|
|
144
|
+
/** Documents (ids) no result may be: up to 10,000. */
|
|
145
|
+
excludeIds?: string[];
|
|
146
|
+
}
|
|
147
|
+
/** One page of `Namespace.queryPages`. */
|
|
148
|
+
export interface QueryPage {
|
|
149
|
+
results: QueryResult[];
|
|
150
|
+
/** Where the next page starts (`queryPages`'s `cursor`); null on the last page. */
|
|
151
|
+
nextCursor: string | null;
|
|
152
|
+
}
|
|
124
153
|
export interface NamespaceInfo {
|
|
125
154
|
name: string;
|
|
126
155
|
documents: number;
|
|
156
|
+
/** The model that embeds the namespace's documents and queries. */
|
|
157
|
+
embeddingModel: string;
|
|
158
|
+
/** The model that reranks its queries. */
|
|
159
|
+
rerankModel: string;
|
|
127
160
|
}
|
|
128
161
|
export interface RerankResult {
|
|
129
162
|
index: number;
|
|
@@ -134,6 +167,20 @@ export interface RerankResult {
|
|
|
134
167
|
export type RerankResults = RerankResult[] & {
|
|
135
168
|
unscored: number[];
|
|
136
169
|
};
|
|
170
|
+
export interface EmbedOptions {
|
|
171
|
+
type?: "document" | "query";
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Embeddings as int8 (`embed(..., { outputDtype: "int8" })`): vector i ≈ values[i] × scales[i], where
|
|
175
|
+
* scales[i] = max|x| / 127. Cosine on `values[i]` alone equals cosine on the floats it stands for (the
|
|
176
|
+
* scale cancels), so they can be stored and searched as they are.
|
|
177
|
+
*/
|
|
178
|
+
export interface Int8Embeddings {
|
|
179
|
+
values: Int8Array[];
|
|
180
|
+
scales: number[];
|
|
181
|
+
}
|
|
182
|
+
/** The float vectors int8 embeddings stand for: values × scale. */
|
|
183
|
+
export declare function dequantize(embeddings: Int8Embeddings): number[][];
|
|
137
184
|
export type SourceStatus = "connecting" | "syncing" | "ready" | "error";
|
|
138
185
|
export interface Source {
|
|
139
186
|
id: string;
|
|
@@ -147,11 +194,153 @@ export interface Source {
|
|
|
147
194
|
createdAt: Date;
|
|
148
195
|
/** While syncing: records read from the app so far in the run in flight. */
|
|
149
196
|
recordsPulled?: number;
|
|
197
|
+
/** Seconds between syncs in force, yours or the automatic one; null while automatic and before the first sync. */
|
|
198
|
+
syncIntervalSeconds: number | null;
|
|
199
|
+
/** True when Conare picks the interval from what each sync reads. */
|
|
200
|
+
syncIntervalAuto: boolean;
|
|
201
|
+
/** When the next sync starts; null while connecting or syncing. */
|
|
202
|
+
nextSyncAt: Date | null;
|
|
203
|
+
/** What a month of syncs costs, to estimate any interval; null from a gateway that does not send it. */
|
|
204
|
+
cost: SourceCost | null;
|
|
205
|
+
/** After `sources.sync(id, { full: true })`: that the sync re-reads everything, and whether its rows are billed. */
|
|
206
|
+
resyncNote?: string;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* What a source's syncs read, and what each frequency costs a month: every row a sync reads is priced
|
|
210
|
+
* at `usdPerMillionRows`. A source Conare reads itself (`rowsBilled` false) is free.
|
|
211
|
+
*/
|
|
212
|
+
export interface SourceCost {
|
|
213
|
+
rowsPerRun: number | null;
|
|
214
|
+
windowSeconds: number | null;
|
|
215
|
+
reads: "changes" | "everything" | null;
|
|
216
|
+
autoIntervalSeconds: number | null;
|
|
217
|
+
usdPerMillionRows: number;
|
|
218
|
+
/** The automatic frequency first, then each frequency on offer. */
|
|
219
|
+
options: Array<{
|
|
220
|
+
intervalSeconds: number;
|
|
221
|
+
auto: boolean;
|
|
222
|
+
rowsMonth: number | null;
|
|
223
|
+
usdMonth: number | null;
|
|
224
|
+
}>;
|
|
225
|
+
/** False when Conare reads the app directly and its rows cost nothing. */
|
|
226
|
+
rowsBilled: boolean;
|
|
150
227
|
}
|
|
151
228
|
export interface SourceType {
|
|
152
229
|
type: string;
|
|
153
230
|
name: string;
|
|
154
231
|
logoUrl: string;
|
|
232
|
+
/** "apiKey" for an app Conare reads itself (Twenty, Granola): connect it with `config.apiKey`, no sign-in page. */
|
|
233
|
+
auth?: "apiKey";
|
|
234
|
+
}
|
|
235
|
+
/** A custom source: documents you push, keyed by your own `externalId` (`sources.create({ type: "custom" })`). */
|
|
236
|
+
export interface CustomSource {
|
|
237
|
+
id: string;
|
|
238
|
+
kind: "custom";
|
|
239
|
+
type: "custom";
|
|
240
|
+
namespace: string;
|
|
241
|
+
user: string | null;
|
|
242
|
+
name: string | null;
|
|
243
|
+
status: "active" | "deleting" | "deleted";
|
|
244
|
+
/** `degraded`: the last snapshot was held or blocked, or the document count was corrected. */
|
|
245
|
+
health: "ok" | "degraded" | "failing";
|
|
246
|
+
display: {
|
|
247
|
+
state: string;
|
|
248
|
+
warning?: string;
|
|
249
|
+
action?: string;
|
|
250
|
+
};
|
|
251
|
+
sync: {
|
|
252
|
+
state: "idle" | "queued" | "running";
|
|
253
|
+
runId: string | null;
|
|
254
|
+
phase: string | null;
|
|
255
|
+
};
|
|
256
|
+
documents: number;
|
|
257
|
+
documentsVerifiedAt: Date | null;
|
|
258
|
+
createdAt: Date;
|
|
259
|
+
updatedAt: Date;
|
|
260
|
+
}
|
|
261
|
+
/** A document of a custom source to push. */
|
|
262
|
+
export interface CustomDocumentInput {
|
|
263
|
+
/** Your id for the document; its `key` is derived from it. */
|
|
264
|
+
externalId: string;
|
|
265
|
+
text?: string;
|
|
266
|
+
title?: string;
|
|
267
|
+
url?: string;
|
|
268
|
+
/** RFC 3339. */
|
|
269
|
+
eventAt?: string;
|
|
270
|
+
metadata?: Metadata;
|
|
271
|
+
/** Who the document belongs to (see `DocumentInput.user`); `users.delete` removes it. */
|
|
272
|
+
user?: string;
|
|
273
|
+
/** Orders your versions of the document and its deletes: a lower one than stored is `stale`. */
|
|
274
|
+
seq?: number;
|
|
275
|
+
/** Your version tag (an etag, a content hash), which `check` compares. */
|
|
276
|
+
tag?: string;
|
|
277
|
+
/** Delete the document instead. */
|
|
278
|
+
deleted?: boolean;
|
|
279
|
+
}
|
|
280
|
+
/** What a push did with one document, once it is stored. */
|
|
281
|
+
export interface PushResult {
|
|
282
|
+
externalId: string;
|
|
283
|
+
key: string;
|
|
284
|
+
result: "created" | "updated" | "unchanged" | "stale" | "deleted" | "rejected";
|
|
285
|
+
/** With `rejected`: too_large, invalid, invalid_metadata, excluded, user_purging, source_deleting. */
|
|
286
|
+
code?: string;
|
|
287
|
+
message?: string;
|
|
288
|
+
/** With `stale`: the seq Conare holds (the document's, or its delete's). */
|
|
289
|
+
storedSeq?: number;
|
|
290
|
+
version?: number;
|
|
291
|
+
chunks?: number;
|
|
292
|
+
chunksEmbedded?: number;
|
|
293
|
+
}
|
|
294
|
+
export interface CustomDocument {
|
|
295
|
+
externalId: string;
|
|
296
|
+
key: string;
|
|
297
|
+
tag: string | null;
|
|
298
|
+
seq: number | null;
|
|
299
|
+
user: string | null;
|
|
300
|
+
version: number;
|
|
301
|
+
updatedAt: Date | null;
|
|
302
|
+
/** `documents.get` only. */
|
|
303
|
+
text?: string;
|
|
304
|
+
metadata?: Metadata;
|
|
305
|
+
}
|
|
306
|
+
/** A run: one pass of work on a source (a snapshot, an import, a delete, a user's purge). */
|
|
307
|
+
export interface Run {
|
|
308
|
+
id: string;
|
|
309
|
+
sourceId: string | null;
|
|
310
|
+
kind: "snapshot" | "import" | "delete" | "purge";
|
|
311
|
+
state: "queued" | "running" | "succeeded" | "failed" | "canceled";
|
|
312
|
+
phase: string | null;
|
|
313
|
+
attempt: number;
|
|
314
|
+
/** A snapshot's deletes: applied; held (too many at once, until a run 24 h later agrees); blocked (none). */
|
|
315
|
+
sweep: "none" | "applied" | "held" | "blocked";
|
|
316
|
+
sweepReason: string | null;
|
|
317
|
+
expected: number | null;
|
|
318
|
+
counts: Record<string, number>;
|
|
319
|
+
error: {
|
|
320
|
+
code: string;
|
|
321
|
+
message?: string;
|
|
322
|
+
} | null;
|
|
323
|
+
/** A running import's progress, measured over the last minute; `etaS` is an estimate. */
|
|
324
|
+
progress: {
|
|
325
|
+
done: number;
|
|
326
|
+
expected?: number;
|
|
327
|
+
ratePerS?: number;
|
|
328
|
+
etaS?: number;
|
|
329
|
+
} | null;
|
|
330
|
+
createdAt: Date;
|
|
331
|
+
startedAt: Date | null;
|
|
332
|
+
finishedAt: Date | null;
|
|
333
|
+
}
|
|
334
|
+
export interface SyncEvent {
|
|
335
|
+
id: string;
|
|
336
|
+
seq: number;
|
|
337
|
+
type: string;
|
|
338
|
+
sourceId: string | null;
|
|
339
|
+
runId: string | null;
|
|
340
|
+
user: string | null;
|
|
341
|
+
/** The run of a `run.*` event, the source of a `source.*` one (as the API answers them, snake_case). */
|
|
342
|
+
data: Record<string, unknown>;
|
|
343
|
+
createdAt: Date;
|
|
155
344
|
}
|
|
156
345
|
export interface ConareOptions {
|
|
157
346
|
/** Defaults to the CONARE_API_KEY environment variable. */
|
|
@@ -164,6 +353,20 @@ export interface ConareOptions {
|
|
|
164
353
|
maxRetries?: number;
|
|
165
354
|
/** Custom fetch, e.g. for proxies or tests. */
|
|
166
355
|
fetch?: (url: string, init: RequestInit) => Promise<Response>;
|
|
356
|
+
/**
|
|
357
|
+
* The organization every request acts for, sent as `X-Conare-Org`. A multi-organization key needs
|
|
358
|
+
* it on every call but `organizations()`; a single-organization key needs none, and one sent must
|
|
359
|
+
* be its own. Make one client per organization.
|
|
360
|
+
*/
|
|
361
|
+
organization?: string;
|
|
362
|
+
}
|
|
363
|
+
/** An organization the key acts for (`organizations()`). */
|
|
364
|
+
export interface Organization {
|
|
365
|
+
/** The value of the `organization` option. */
|
|
366
|
+
id: string;
|
|
367
|
+
/** Empty when it cannot be read right now. */
|
|
368
|
+
name: string;
|
|
369
|
+
role: "admin" | "member";
|
|
167
370
|
}
|
|
168
371
|
export interface RequestOptions {
|
|
169
372
|
signal?: AbortSignal;
|
|
@@ -175,7 +378,9 @@ export interface RequestOptions {
|
|
|
175
378
|
* job restarted after a crash) the same call: within 24 hours its repeat gets the first answer and
|
|
176
379
|
* writes nothing. A key is 1-255 visible ASCII characters, kept per API key; `write()` and `add()`
|
|
177
380
|
* send batch `n` after the first as `<key>:<n>` and leave documents without an id to the API, which
|
|
178
|
-
* derives their ids from the key; `deleteWhere()` sends round `n` after the first as `<key>:<n
|
|
381
|
+
* derives their ids from the key; `deleteWhere()` sends round `n` after the first as `<key>:<n>`, and
|
|
382
|
+
* so do `sources.documents.check()`, `delete()` and `restore()` with batch `n`; `imports.create()`
|
|
383
|
+
* sends its upload's parts as `<key>:part-<n>`, then `<key>:complete` and `<key>:import`.
|
|
179
384
|
* The same key with another request is a 422 `idempotency_key_reused`.
|
|
180
385
|
*/
|
|
181
386
|
idempotencyKey?: string;
|
|
@@ -196,6 +401,16 @@ export declare class ConareError extends Error {
|
|
|
196
401
|
export declare class Conare {
|
|
197
402
|
readonly baseURL: string;
|
|
198
403
|
readonly sources: Sources;
|
|
404
|
+
/** Snapshot runs of custom sources, and any run by id. */
|
|
405
|
+
readonly runs: Runs;
|
|
406
|
+
/** Files of documents written into a custom source. */
|
|
407
|
+
readonly imports: Imports;
|
|
408
|
+
/** Delete everything Conare holds of one of your users. */
|
|
409
|
+
readonly users: Users;
|
|
410
|
+
/** What changed, in order. */
|
|
411
|
+
readonly events: Events;
|
|
412
|
+
/** The organization requests act for (`X-Conare-Org`); undefined: the key's own. */
|
|
413
|
+
readonly organization: string | undefined;
|
|
199
414
|
private readonly apiKey;
|
|
200
415
|
private readonly timeout;
|
|
201
416
|
private readonly maxRetries;
|
|
@@ -205,15 +420,27 @@ export declare class Conare {
|
|
|
205
420
|
namespace(name: string): Namespace;
|
|
206
421
|
/**
|
|
207
422
|
* Every namespace in the organization (a scoped key: every one it reaches) with its document
|
|
208
|
-
* count; with `prefix`, only those whose name starts with it, e.g. one user's `"u7f3a9c-"`.
|
|
423
|
+
* count and models; with `prefix`, only those whose name starts with it, e.g. one user's `"u7f3a9c-"`.
|
|
209
424
|
*/
|
|
210
425
|
namespaces(options?: RequestOptions & {
|
|
211
426
|
prefix?: string;
|
|
212
427
|
}): Promise<NamespaceInfo[]>;
|
|
213
|
-
/**
|
|
214
|
-
|
|
215
|
-
|
|
428
|
+
/**
|
|
429
|
+
* The organizations this key acts for, its own first. A multi-organization key lists each other one
|
|
430
|
+
* it still acts for; pass an `id` as the `organization` option of a client to act for it.
|
|
431
|
+
*/
|
|
432
|
+
organizations(options?: RequestOptions): Promise<Organization[]>;
|
|
433
|
+
/**
|
|
434
|
+
* Embed texts. Use type "query" for search queries and "document" (default) for stored text.
|
|
435
|
+
* `outputDtype: "int8"` returns each vector as int8 values and one scale (vector ≈ values × scale),
|
|
436
|
+
* a quarter of the bytes; `dequantize` turns them back into floats.
|
|
437
|
+
*/
|
|
438
|
+
embed(input: string | string[], options?: RequestOptions & EmbedOptions & {
|
|
439
|
+
outputDtype?: "float";
|
|
216
440
|
}): Promise<number[][]>;
|
|
441
|
+
embed(input: string | string[], options: RequestOptions & EmbedOptions & {
|
|
442
|
+
outputDtype: "int8";
|
|
443
|
+
}): Promise<Int8Embeddings>;
|
|
217
444
|
/**
|
|
218
445
|
* Rerank 1-100 documents against a query, best first. Each document is 1-24,000 characters, the query at
|
|
219
446
|
* most 8,192, and all of them together at most 256,000; more than 100 documents is a 400 `invalid_request`.
|
|
@@ -231,14 +458,15 @@ export declare class Namespace {
|
|
|
231
458
|
constructor(client: Conare, name: string);
|
|
232
459
|
private path;
|
|
233
460
|
/**
|
|
234
|
-
* Create the namespace before its first write. Only a namespace
|
|
235
|
-
*
|
|
236
|
-
*
|
|
461
|
+
* Create the namespace before its first write. Only a namespace embedded by `embeddingModel`
|
|
462
|
+
* (one of your organization's models from `GET /models`) needs this: a write creates one with the
|
|
463
|
+
* default model. Its model never changes: creating it again with another one is a 409. Returns
|
|
464
|
+
* the model that embeds it.
|
|
237
465
|
*/
|
|
238
466
|
create(options?: RequestOptions & {
|
|
239
|
-
|
|
467
|
+
embeddingModel?: string;
|
|
240
468
|
}): Promise<{
|
|
241
|
-
|
|
469
|
+
embeddingModel: string;
|
|
242
470
|
}>;
|
|
243
471
|
/**
|
|
244
472
|
* Add or replace documents. Accepts one or many; sends them in batches of 100. Returns the ids.
|
|
@@ -259,7 +487,9 @@ export declare class Namespace {
|
|
|
259
487
|
* Store a PDF or an Excel workbook (.xlsx), at most 20 MiB: one document per PDF page with a
|
|
260
488
|
* text layer (`<fileId>:page-3`) and Markdown tables per worksheet (`<fileId>:Sheet1-1`), each
|
|
261
489
|
* with `file`, `file_id`, `file_type` and `page` or `sheet` metadata. `fileId` defaults to the
|
|
262
|
-
* name in id characters
|
|
490
|
+
* name in id characters (a name with characters outside ASCII also gets 8 hex digits of its hash, so
|
|
491
|
+
* such names do not collide); uploading the same one again replaces every document it made, and two
|
|
492
|
+
* uploads of one id run one at a time. Pages
|
|
263
493
|
* without a text layer (scans, images) are read by OCR: by default after the answer
|
|
264
494
|
* (`ocrPending`, stored within about a minute), with `wait: true` before it (`pagesOcr`). Pages
|
|
265
495
|
* with no text even then are listed in `pagesWithoutText` and not stored.
|
|
@@ -269,22 +499,31 @@ export declare class Namespace {
|
|
|
269
499
|
wait?: boolean;
|
|
270
500
|
}): Promise<FileUpload>;
|
|
271
501
|
/**
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
* that many in windows of 20 passages, then reads the best 20 of them together in one final
|
|
276
|
-
* window that sets their order; unset, it reads one window of 20. `user` keeps the search to one user's documents and
|
|
277
|
-
* `userPrefix` (ending in `:`) to a group's; both combine with `filter`.
|
|
502
|
+
* An upload's outcome: the last upload of `fileId` here in the last 7 days. While OCR reads after the
|
|
503
|
+
* answer, `ocrPending` lists its pages; once it ended, the pages it read are in `ids` and `pagesOcr`, and
|
|
504
|
+
* those it could not read in `pagesWithoutText`. A file id with no upload throws 404 `file_not_found`.
|
|
278
505
|
*/
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
506
|
+
getFile(fileId: string, options?: RequestOptions): Promise<FileStatus>;
|
|
507
|
+
/**
|
|
508
|
+
* Hybrid search, reranked. One result per document: its best passage; `topK` documents when that
|
|
509
|
+
* many match. `retrievers` picks what the search fuses (default `["vector", "keyword"]`; listed
|
|
510
|
+
* retrievers run as listed, also on a vector-only custom model). `rerankDepth` (1-500) is how many of the
|
|
511
|
+
* first passages the reranker ranks; unset, the first 20. `user` keeps the search to one user's documents and
|
|
512
|
+
* `userPrefix` (ending in `:`) to a group's; both combine with `filter`. An empty `user` or
|
|
513
|
+
* `userPrefix` is a 400, never "every user". `excludeIds` keeps those documents out.
|
|
514
|
+
*/
|
|
515
|
+
query(query: string, options?: QueryOptions): Promise<QueryResult[]>;
|
|
516
|
+
/**
|
|
517
|
+
* A deep search, page by page: ranks `maxResults` documents once (at least `topK`; at most 1,000,
|
|
518
|
+
* or 5,000 on a custom model's engine) and yields them `topK` at a time. Later pages are read from
|
|
519
|
+
* that ranking (kept 15 minutes) without searching again, so they never repeat or skip a
|
|
520
|
+
* document; past `rerankDepth` results keep retrieval order (`reranked: false`). Pass a page's
|
|
521
|
+
* `nextCursor` as `cursor` to go on from it in another call (`query` is then ignored).
|
|
522
|
+
*/
|
|
523
|
+
queryPages(query: string, options: QueryOptions & {
|
|
524
|
+
maxResults: number;
|
|
525
|
+
cursor?: string;
|
|
526
|
+
}): AsyncGenerator<QueryPage>;
|
|
288
527
|
/** One document by id, or null if it does not exist. */
|
|
289
528
|
get(id: string, options?: RequestOptions): Promise<Document | null>;
|
|
290
529
|
/** Every document (id, metadata, updatedAt), fetched page by page as you iterate. `limit` is the page size: 1-100, default 50. */
|
|
@@ -293,41 +532,210 @@ export declare class Namespace {
|
|
|
293
532
|
}): AsyncGenerator<DocumentSummary>;
|
|
294
533
|
/** Delete one document. Throws a ConareError with status 404 (`document_not_found`) if it does not exist. */
|
|
295
534
|
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
296
|
-
/**
|
|
535
|
+
/**
|
|
536
|
+
* Delete up to 1000 documents by id in one call. Ids that do not exist are skipped; a namespace that
|
|
537
|
+
* does not exist throws ConareError 404 `namespace_not_found`. Returns how many were deleted.
|
|
538
|
+
*/
|
|
297
539
|
deleteMany(ids: string[], options?: RequestOptions): Promise<number>;
|
|
298
540
|
/** Delete every document matching filter (at least one condition), calling until none match. Returns how many were deleted. */
|
|
299
541
|
deleteWhere(filter: Filter, options?: RequestOptions): Promise<number>;
|
|
300
542
|
/** Delete the namespace and every document in it. Succeeds as well when it was already deleted or emptied; throws ConareError 404 `namespace_not_found` for a name never written. */
|
|
301
543
|
drop(options?: RequestOptions): Promise<void>;
|
|
302
544
|
}
|
|
303
|
-
/** Apps connected through Conare that keep syncing into a namespace. */
|
|
545
|
+
/** Apps connected through Conare that keep syncing into a namespace, and custom sources you push to. */
|
|
304
546
|
export declare class Sources {
|
|
305
547
|
private readonly client;
|
|
548
|
+
/** The documents of a custom source. */
|
|
549
|
+
readonly documents: SourceDocuments;
|
|
306
550
|
constructor(client: Conare);
|
|
551
|
+
/**
|
|
552
|
+
* Create a custom source: a set of documents you push into `namespace`, keyed by your own ids.
|
|
553
|
+
* With `user`, `users.delete(user)` deletes it with the user's documents.
|
|
554
|
+
*/
|
|
555
|
+
create(params: {
|
|
556
|
+
type: "custom";
|
|
557
|
+
namespace: string;
|
|
558
|
+
name?: string;
|
|
559
|
+
user?: string;
|
|
560
|
+
}, options?: RequestOptions): Promise<CustomSource>;
|
|
307
561
|
/**
|
|
308
562
|
* Start connecting an app. Send the app owner to `connectUrl`; they come back to `redirectUrl`.
|
|
309
563
|
* For your own users, connect each one into their own namespace, e.g. "user-42".
|
|
564
|
+
* Twenty and Granola (`auth: "apiKey"` in `types()`) take `config` instead: `apiKey`, and for
|
|
565
|
+
* Twenty `baseUrl` when self-hosted. Conare checks the key, the source starts syncing at once,
|
|
566
|
+
* and `connectUrl` is null.
|
|
310
567
|
*/
|
|
311
568
|
connect(params: {
|
|
312
569
|
type: string;
|
|
313
570
|
namespace: string;
|
|
314
571
|
name?: string;
|
|
315
572
|
redirectUrl?: string;
|
|
573
|
+
syncIntervalSeconds?: number;
|
|
574
|
+
config?: {
|
|
575
|
+
baseUrl?: string;
|
|
576
|
+
apiKey: string;
|
|
577
|
+
};
|
|
316
578
|
}, options?: RequestOptions): Promise<{
|
|
317
579
|
source: Source;
|
|
318
|
-
connectUrl: string;
|
|
580
|
+
connectUrl: string | null;
|
|
319
581
|
}>;
|
|
320
|
-
/**
|
|
321
|
-
|
|
582
|
+
/** Set how often a source syncs: seconds from 300 (5 minutes) to 2592000 (30 days), or null for automatic. */
|
|
583
|
+
update(id: string, params: {
|
|
584
|
+
syncIntervalSeconds: number | null;
|
|
585
|
+
}, options?: RequestOptions): Promise<Source>;
|
|
586
|
+
/** Every source: the connected apps, then the custom sources (`kind: "custom"`). */
|
|
587
|
+
list(options?: RequestOptions): Promise<Array<Source | CustomSource>>;
|
|
322
588
|
/** One source by id. */
|
|
323
|
-
get(id: string, options?: RequestOptions): Promise<Source>;
|
|
324
|
-
/**
|
|
325
|
-
|
|
326
|
-
|
|
589
|
+
get(id: string, options?: RequestOptions): Promise<Source | CustomSource>;
|
|
590
|
+
/**
|
|
591
|
+
* Start a sync now. `full: true` re-reads everything the app holds instead of what changed: documents
|
|
592
|
+
* that changed are rewritten and ones Conare no longer keeps are deleted. It is for Gmail and the apps
|
|
593
|
+
* Conare reads itself (other apps answer 400), and Gmail's rows are billed again (`cost.usdPerMillionRows`).
|
|
594
|
+
*/
|
|
595
|
+
sync(id: string, options?: RequestOptions & {
|
|
596
|
+
full?: boolean;
|
|
597
|
+
}): Promise<Source>;
|
|
598
|
+
/**
|
|
599
|
+
* Disconnect a source. Pass `deleteDocuments: true` to also delete what it synced. A custom
|
|
600
|
+
* source's documents are deleted by a run, which `runs.get` follows until the source is `deleted`.
|
|
601
|
+
*/
|
|
327
602
|
delete(id: string, options?: RequestOptions & {
|
|
328
603
|
deleteDocuments?: boolean;
|
|
329
604
|
}): Promise<void>;
|
|
330
605
|
/** The apps you can connect. */
|
|
331
606
|
types(options?: RequestOptions): Promise<SourceType[]>;
|
|
332
607
|
}
|
|
608
|
+
/** The documents of a custom source, by source id. */
|
|
609
|
+
export declare class SourceDocuments {
|
|
610
|
+
private readonly client;
|
|
611
|
+
constructor(client: Conare);
|
|
612
|
+
/**
|
|
613
|
+
* Push documents (sent 100 at a time): what each write did, in order, once it is stored. Pushes
|
|
614
|
+
* of one source may run concurrently. With `runId`, they belong to that snapshot run.
|
|
615
|
+
*/
|
|
616
|
+
put(sourceId: string, documents: CustomDocumentInput | CustomDocumentInput[], options?: RequestOptions & {
|
|
617
|
+
runId?: string;
|
|
618
|
+
}): Promise<PushResult[]>;
|
|
619
|
+
/**
|
|
620
|
+
* Which documents need a push: `need` are those the source does not hold with that `tag`,
|
|
621
|
+
* `excluded` those deleted with `exclude`. With `runId`, each one counts as seen by the run.
|
|
622
|
+
*/
|
|
623
|
+
check(sourceId: string, documents: Array<{
|
|
624
|
+
externalId: string;
|
|
625
|
+
tag?: string;
|
|
626
|
+
}>, options?: RequestOptions & {
|
|
627
|
+
runId?: string;
|
|
628
|
+
}): Promise<{
|
|
629
|
+
need: string[];
|
|
630
|
+
excluded: string[];
|
|
631
|
+
}>;
|
|
632
|
+
/** Every document of the source in key order, page by page. `limit` is the page size: 1-100, default 50. */
|
|
633
|
+
list(sourceId: string, options?: RequestOptions & {
|
|
634
|
+
limit?: number;
|
|
635
|
+
}): AsyncGenerator<CustomDocument>;
|
|
636
|
+
/** One document with its text and metadata, by its `key` (or an external id that is its own key), or null. */
|
|
637
|
+
get(sourceId: string, key: string, options?: RequestOptions): Promise<CustomDocument | null>;
|
|
638
|
+
/**
|
|
639
|
+
* Delete documents by external id (1,000 a call). A tombstone at `seq` makes older pushes of each
|
|
640
|
+
* `stale` (one already writing too); one holding a higher `seq` is `kept`; `exclude` keeps it out until
|
|
641
|
+
* restored.
|
|
642
|
+
*/
|
|
643
|
+
delete(sourceId: string, externalIds: string[], options?: RequestOptions & {
|
|
644
|
+
exclude?: boolean;
|
|
645
|
+
seq?: number;
|
|
646
|
+
}): Promise<{
|
|
647
|
+
deleted: number;
|
|
648
|
+
kept: number;
|
|
649
|
+
excluded: number;
|
|
650
|
+
}>;
|
|
651
|
+
/** Let excluded documents be pushed again. Returns how many were excluded. */
|
|
652
|
+
restore(sourceId: string, externalIds: string[], options?: RequestOptions): Promise<number>;
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* An open snapshot run: push or check the source's whole set through it, then complete it. The
|
|
656
|
+
* documents it never saw are deleted, unless that is over 10% (and over 1,000) at once: then the run
|
|
657
|
+
* is `held` until a second run at least 24 h later agrees.
|
|
658
|
+
*/
|
|
659
|
+
export declare class SnapshotRun {
|
|
660
|
+
private readonly client;
|
|
661
|
+
readonly sourceId: string;
|
|
662
|
+
readonly run: Run;
|
|
663
|
+
constructor(client: Conare, sourceId: string, run: Run);
|
|
664
|
+
get id(): string;
|
|
665
|
+
put(documents: CustomDocumentInput | CustomDocumentInput[], options?: RequestOptions): Promise<PushResult[]>;
|
|
666
|
+
check(documents: Array<{
|
|
667
|
+
externalId: string;
|
|
668
|
+
tag?: string;
|
|
669
|
+
}>, options?: RequestOptions): Promise<{
|
|
670
|
+
need: string[];
|
|
671
|
+
excluded: string[];
|
|
672
|
+
}>;
|
|
673
|
+
/**
|
|
674
|
+
* Stop taking pushes and sweep. Waits up to `wait` seconds (default 100) for the run to finish,
|
|
675
|
+
* then follows it until it did (`runs.get`); `allowMassDelete` applies a sweep of any size.
|
|
676
|
+
*/
|
|
677
|
+
complete(options?: RequestOptions & {
|
|
678
|
+
wait?: number;
|
|
679
|
+
allowMassDelete?: boolean;
|
|
680
|
+
poll?: number;
|
|
681
|
+
}): Promise<Run>;
|
|
682
|
+
}
|
|
683
|
+
export declare class Runs {
|
|
684
|
+
private readonly client;
|
|
685
|
+
constructor(client: Conare);
|
|
686
|
+
/**
|
|
687
|
+
* Open a snapshot run of a custom source (one active run at a time). `expected`, your count of
|
|
688
|
+
* the set, blocks the sweep of a run that saw under 90% of it; a run with no push for
|
|
689
|
+
* `idleTimeoutS` (60-86,400, default 3,600) is canceled.
|
|
690
|
+
*/
|
|
691
|
+
open(sourceId: string, params?: {
|
|
692
|
+
expected?: number;
|
|
693
|
+
idleTimeoutS?: number;
|
|
694
|
+
}, options?: RequestOptions): Promise<SnapshotRun>;
|
|
695
|
+
get(id: string, options?: RequestOptions): Promise<Run>;
|
|
696
|
+
}
|
|
697
|
+
export declare class Imports {
|
|
698
|
+
private readonly client;
|
|
699
|
+
constructor(client: Conare);
|
|
700
|
+
/**
|
|
701
|
+
* Write a file of JSON lines (one `CustomDocumentInput` a line, snake_case, up to 1 GiB) into a
|
|
702
|
+
* custom source: it is uploaded in parts, each checked by its MD5, then imported by a run, which
|
|
703
|
+
* `runs.get` follows. `snapshot` also deletes what the file does not hold.
|
|
704
|
+
*/
|
|
705
|
+
create(sourceId: string, file: Blob | Uint8Array | ArrayBuffer | string, params?: {
|
|
706
|
+
mode?: "delta" | "snapshot";
|
|
707
|
+
expected?: number;
|
|
708
|
+
allowMassDelete?: boolean;
|
|
709
|
+
filename?: string;
|
|
710
|
+
}, options?: RequestOptions): Promise<Run>;
|
|
711
|
+
}
|
|
712
|
+
export declare class Users {
|
|
713
|
+
private readonly client;
|
|
714
|
+
constructor(client: Conare);
|
|
715
|
+
/**
|
|
716
|
+
* Delete everything Conare holds of a user: their documents in every namespace and their
|
|
717
|
+
* sources. A purge run does it (writes for the user are refused meanwhile); it finishes once a
|
|
718
|
+
* second check 10 minutes after the first finds nothing. Asking again returns the same run.
|
|
719
|
+
*/
|
|
720
|
+
delete(user: string, options?: RequestOptions): Promise<Run>;
|
|
721
|
+
/** `delete` for every user starting with `prefix` (at least 3 characters, ending in `:`). */
|
|
722
|
+
deletePrefix(prefix: string, options?: RequestOptions): Promise<Run>;
|
|
723
|
+
}
|
|
724
|
+
export declare class Events {
|
|
725
|
+
private readonly client;
|
|
726
|
+
constructor(client: Conare);
|
|
727
|
+
/**
|
|
728
|
+
* The events after `cursor`, oldest first (100 by default, at most 1,000): `seq` counts up by one
|
|
729
|
+
* with no gap, so pass `nextCursor` as the next `cursor`. `types` takes groups such as `"run.*"`.
|
|
730
|
+
*/
|
|
731
|
+
list(params?: {
|
|
732
|
+
cursor?: string;
|
|
733
|
+
types?: string[];
|
|
734
|
+
userPrefix?: string;
|
|
735
|
+
limit?: number;
|
|
736
|
+
}, options?: RequestOptions): Promise<{
|
|
737
|
+
data: SyncEvent[];
|
|
738
|
+
nextCursor: string;
|
|
739
|
+
}>;
|
|
740
|
+
}
|
|
333
741
|
export {};
|