conare 0.20.0 → 0.22.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/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
- export declare const VERSION = "0.20.0";
1
+ export declare const VERSION = "0.22.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` and the ranges `$gt` `$gte` `$lt` `$lte`. A range
8
- * compares a number or string value (not an array item): number bounds compare numbers, string
9
- * bounds compare strings by their UTF-8 bytes (ISO dates sort as dates). The API answers 400
10
- * invalid_filter for the operators typed `never` here, so they do not compile.
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?: never;
20
- $nin?: never;
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);
@@ -69,23 +70,42 @@ export interface WriteResult {
69
70
  chunksEmbedded?: number;
70
71
  storedSeq?: number;
71
72
  }
73
+ /** A file type `uploadFile` can declare: the file is read as that type (`jpg` and `tif` are accepted too). */
74
+ export type FileType = "pdf" | "xlsx" | "docx" | "pptx" | "csv" | "tsv" | "txt" | "md" | "png" | "jpeg" | "webp" | "tiff";
72
75
  /** What `uploadFile` stored. */
73
76
  export interface FileUpload {
74
77
  fileId: string;
75
- type: "pdf" | "xlsx";
78
+ /** The type it was read as: an image of any format is `image`. */
79
+ type: "pdf" | "xlsx" | "docx" | "pptx" | "csv" | "tsv" | "txt" | "md" | "image";
76
80
  /** The documents it made, in reading order. */
77
81
  ids: string[];
78
- /** A PDF's pages (null for a workbook). */
82
+ /** A PDF's pages (null for any other file). */
79
83
  pages: number | null;
80
- /** A workbook's sheets (null for a PDF). */
84
+ /** A workbook's sheets (null for any other file). */
81
85
  sheets: number | null;
82
- /** PDF pages read by OCR before the answer (`wait: true`); stored like the rest. */
86
+ /** A deck's slides (null for any other file). */
87
+ slides: number | null;
88
+ /** A deck's slides with no text (pictures only): not stored. */
89
+ slidesWithoutText: number[];
90
+ /** PDF or image pages read by OCR before the answer (`wait: true`); stored like the rest. */
83
91
  pagesOcr: number;
92
+ /** Pictures of a Word document or deck read by OCR before the answer (`wait: true`), each a document of its own. */
93
+ imagesOcr: number;
84
94
  /** PDF pages with no text even after OCR (blank, or OCR could not read them): not stored. */
85
95
  pagesWithoutText: number[];
86
- /** PDF pages OCR reads after the answer (without `wait`): each is stored, marked `ocr`, within about a minute. */
96
+ /**
97
+ * PDF pages OCR reads after the answer (without `wait`): each is stored, marked `ocr`, within about a minute.
98
+ * `getFile(fileId)` says when OCR ended and which of them it could not read.
99
+ */
87
100
  ocrPending: number[];
88
101
  }
102
+ /** What `getFile` reads: an upload's outcome, with OCR after the answer folded in as it ends. */
103
+ export interface FileStatus extends FileUpload {
104
+ /** The file's name as uploaded. */
105
+ name: string;
106
+ /** When it was uploaded. */
107
+ uploadedAt: Date;
108
+ }
89
109
  export interface Document {
90
110
  id: string;
91
111
  text: string;
@@ -119,11 +139,33 @@ export interface QueryResult {
119
139
  /** The document's user, when it has one. */
120
140
  user?: string;
121
141
  }
122
- /** What a query fuses: the embedding model, BM25 keywords, or the learned-sparse (SPLADE) model. */
123
- export type Retriever = "vector" | "keyword" | "sparse";
142
+ /** What a query fuses: the embedding model and BM25 keywords. */
143
+ export type Retriever = "vector" | "keyword";
144
+ /** The options of `Namespace.query` and `Namespace.queryPages`. */
145
+ export interface QueryOptions extends RequestOptions {
146
+ topK?: number;
147
+ filter?: Filter;
148
+ rerank?: boolean;
149
+ rerankDepth?: number;
150
+ retrievers?: Retriever[];
151
+ user?: string;
152
+ userPrefix?: string;
153
+ /** Documents (ids) no result may be: up to 10,000. */
154
+ excludeIds?: string[];
155
+ }
156
+ /** One page of `Namespace.queryPages`. */
157
+ export interface QueryPage {
158
+ results: QueryResult[];
159
+ /** Where the next page starts (`queryPages`'s `cursor`); null on the last page. */
160
+ nextCursor: string | null;
161
+ }
124
162
  export interface NamespaceInfo {
125
163
  name: string;
126
164
  documents: number;
165
+ /** The model that embeds the namespace's documents and queries. */
166
+ embeddingModel: string;
167
+ /** The model that reranks its queries. */
168
+ rerankModel: string;
127
169
  }
128
170
  export interface RerankResult {
129
171
  index: number;
@@ -134,6 +176,20 @@ export interface RerankResult {
134
176
  export type RerankResults = RerankResult[] & {
135
177
  unscored: number[];
136
178
  };
179
+ export interface EmbedOptions {
180
+ type?: "document" | "query";
181
+ }
182
+ /**
183
+ * Embeddings as int8 (`embed(..., { outputDtype: "int8" })`): vector i ≈ values[i] × scales[i], where
184
+ * scales[i] = max|x| / 127. Cosine on `values[i]` alone equals cosine on the floats it stands for (the
185
+ * scale cancels), so they can be stored and searched as they are.
186
+ */
187
+ export interface Int8Embeddings {
188
+ values: Int8Array[];
189
+ scales: number[];
190
+ }
191
+ /** The float vectors int8 embeddings stand for: values × scale. */
192
+ export declare function dequantize(embeddings: Int8Embeddings): number[][];
137
193
  export type SourceStatus = "connecting" | "syncing" | "ready" | "error";
138
194
  export interface Source {
139
195
  id: string;
@@ -147,11 +203,153 @@ export interface Source {
147
203
  createdAt: Date;
148
204
  /** While syncing: records read from the app so far in the run in flight. */
149
205
  recordsPulled?: number;
206
+ /** Seconds between syncs in force, yours or the automatic one; null while automatic and before the first sync. */
207
+ syncIntervalSeconds: number | null;
208
+ /** True when Conare picks the interval from what each sync reads. */
209
+ syncIntervalAuto: boolean;
210
+ /** When the next sync starts; null while connecting or syncing. */
211
+ nextSyncAt: Date | null;
212
+ /** What a month of syncs costs, to estimate any interval; null from a gateway that does not send it. */
213
+ cost: SourceCost | null;
214
+ /** After `sources.sync(id, { full: true })`: that the sync re-reads everything, and whether its rows are billed. */
215
+ resyncNote?: string;
216
+ }
217
+ /**
218
+ * What a source's syncs read, and what each frequency costs a month: every row a sync reads is priced
219
+ * at `usdPerMillionRows`. A source Conare reads itself (`rowsBilled` false) is free.
220
+ */
221
+ export interface SourceCost {
222
+ rowsPerRun: number | null;
223
+ windowSeconds: number | null;
224
+ reads: "changes" | "everything" | null;
225
+ autoIntervalSeconds: number | null;
226
+ usdPerMillionRows: number;
227
+ /** The automatic frequency first, then each frequency on offer. */
228
+ options: Array<{
229
+ intervalSeconds: number;
230
+ auto: boolean;
231
+ rowsMonth: number | null;
232
+ usdMonth: number | null;
233
+ }>;
234
+ /** False when Conare reads the app directly and its rows cost nothing. */
235
+ rowsBilled: boolean;
150
236
  }
151
237
  export interface SourceType {
152
238
  type: string;
153
239
  name: string;
154
240
  logoUrl: string;
241
+ /** "apiKey" for an app Conare reads itself (Twenty, Granola): connect it with `config.apiKey`, no sign-in page. */
242
+ auth?: "apiKey";
243
+ }
244
+ /** A custom source: documents you push, keyed by your own `externalId` (`sources.create({ type: "custom" })`). */
245
+ export interface CustomSource {
246
+ id: string;
247
+ kind: "custom";
248
+ type: "custom";
249
+ namespace: string;
250
+ user: string | null;
251
+ name: string | null;
252
+ status: "active" | "deleting" | "deleted";
253
+ /** `degraded`: the last snapshot was held or blocked, or the document count was corrected. */
254
+ health: "ok" | "degraded" | "failing";
255
+ display: {
256
+ state: string;
257
+ warning?: string;
258
+ action?: string;
259
+ };
260
+ sync: {
261
+ state: "idle" | "queued" | "running";
262
+ runId: string | null;
263
+ phase: string | null;
264
+ };
265
+ documents: number;
266
+ documentsVerifiedAt: Date | null;
267
+ createdAt: Date;
268
+ updatedAt: Date;
269
+ }
270
+ /** A document of a custom source to push. */
271
+ export interface CustomDocumentInput {
272
+ /** Your id for the document; its `key` is derived from it. */
273
+ externalId: string;
274
+ text?: string;
275
+ title?: string;
276
+ url?: string;
277
+ /** RFC 3339. */
278
+ eventAt?: string;
279
+ metadata?: Metadata;
280
+ /** Who the document belongs to (see `DocumentInput.user`); `users.delete` removes it. */
281
+ user?: string;
282
+ /** Orders your versions of the document and its deletes: a lower one than stored is `stale`. */
283
+ seq?: number;
284
+ /** Your version tag (an etag, a content hash), which `check` compares. */
285
+ tag?: string;
286
+ /** Delete the document instead. */
287
+ deleted?: boolean;
288
+ }
289
+ /** What a push did with one document, once it is stored. */
290
+ export interface PushResult {
291
+ externalId: string;
292
+ key: string;
293
+ result: "created" | "updated" | "unchanged" | "stale" | "deleted" | "rejected";
294
+ /** With `rejected`: too_large, invalid, invalid_metadata, excluded, user_purging, source_deleting. */
295
+ code?: string;
296
+ message?: string;
297
+ /** With `stale`: the seq Conare holds (the document's, or its delete's). */
298
+ storedSeq?: number;
299
+ version?: number;
300
+ chunks?: number;
301
+ chunksEmbedded?: number;
302
+ }
303
+ export interface CustomDocument {
304
+ externalId: string;
305
+ key: string;
306
+ tag: string | null;
307
+ seq: number | null;
308
+ user: string | null;
309
+ version: number;
310
+ updatedAt: Date | null;
311
+ /** `documents.get` only. */
312
+ text?: string;
313
+ metadata?: Metadata;
314
+ }
315
+ /** A run: one pass of work on a source (a snapshot, an import, a delete, a user's purge). */
316
+ export interface Run {
317
+ id: string;
318
+ sourceId: string | null;
319
+ kind: "snapshot" | "import" | "delete" | "purge";
320
+ state: "queued" | "running" | "succeeded" | "failed" | "canceled";
321
+ phase: string | null;
322
+ attempt: number;
323
+ /** A snapshot's deletes: applied; held (too many at once, until a run 24 h later agrees); blocked (none). */
324
+ sweep: "none" | "applied" | "held" | "blocked";
325
+ sweepReason: string | null;
326
+ expected: number | null;
327
+ counts: Record<string, number>;
328
+ error: {
329
+ code: string;
330
+ message?: string;
331
+ } | null;
332
+ /** A running import's progress, measured over the last minute; `etaS` is an estimate. */
333
+ progress: {
334
+ done: number;
335
+ expected?: number;
336
+ ratePerS?: number;
337
+ etaS?: number;
338
+ } | null;
339
+ createdAt: Date;
340
+ startedAt: Date | null;
341
+ finishedAt: Date | null;
342
+ }
343
+ export interface SyncEvent {
344
+ id: string;
345
+ seq: number;
346
+ type: string;
347
+ sourceId: string | null;
348
+ runId: string | null;
349
+ user: string | null;
350
+ /** The run of a `run.*` event, the source of a `source.*` one (as the API answers them, snake_case). */
351
+ data: Record<string, unknown>;
352
+ createdAt: Date;
155
353
  }
156
354
  export interface ConareOptions {
157
355
  /** Defaults to the CONARE_API_KEY environment variable. */
@@ -164,6 +362,20 @@ export interface ConareOptions {
164
362
  maxRetries?: number;
165
363
  /** Custom fetch, e.g. for proxies or tests. */
166
364
  fetch?: (url: string, init: RequestInit) => Promise<Response>;
365
+ /**
366
+ * The organization every request acts for, sent as `X-Conare-Org`. A multi-organization key needs
367
+ * it on every call but `organizations()`; a single-organization key needs none, and one sent must
368
+ * be its own. Make one client per organization.
369
+ */
370
+ organization?: string;
371
+ }
372
+ /** An organization the key acts for (`organizations()`). */
373
+ export interface Organization {
374
+ /** The value of the `organization` option. */
375
+ id: string;
376
+ /** Empty when it cannot be read right now. */
377
+ name: string;
378
+ role: "admin" | "member";
167
379
  }
168
380
  export interface RequestOptions {
169
381
  signal?: AbortSignal;
@@ -175,7 +387,9 @@ export interface RequestOptions {
175
387
  * job restarted after a crash) the same call: within 24 hours its repeat gets the first answer and
176
388
  * writes nothing. A key is 1-255 visible ASCII characters, kept per API key; `write()` and `add()`
177
389
  * 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>`.
390
+ * derives their ids from the key; `deleteWhere()` sends round `n` after the first as `<key>:<n>`, and
391
+ * so do `sources.documents.check()`, `delete()` and `restore()` with batch `n`; `imports.create()`
392
+ * sends its upload's parts as `<key>:part-<n>`, then `<key>:complete` and `<key>:import`.
179
393
  * The same key with another request is a 422 `idempotency_key_reused`.
180
394
  */
181
395
  idempotencyKey?: string;
@@ -187,6 +401,71 @@ export declare class ConareError extends Error {
187
401
  readonly requestId: string | null;
188
402
  constructor(status: number, code: string, message: string, requestId?: string | null);
189
403
  }
404
+ /** A file of `files.upload`, as `files.status` reads it. */
405
+ export interface StoredFile {
406
+ /** The file's id in its namespace (and user). */
407
+ id: string;
408
+ name: string;
409
+ namespace: string;
410
+ user: string | null;
411
+ /** The namespace's files source: the file's documents are `<sourceId>:<id>:<part>`. */
412
+ sourceId: string;
413
+ /** What it was parsed as: pdf, xlsx, docx, pptx, csv, tsv, txt, md or image. */
414
+ type: string | null;
415
+ /** Whether the type was declared rather than recognized. */
416
+ declared: boolean;
417
+ bytes: number;
418
+ sha256: string | null;
419
+ metadata: Metadata;
420
+ /** `ocr`: pages are being read by OCR, or wait to be tried again. */
421
+ state: "queued" | "parsing" | "ocr" | "ready" | "failed";
422
+ /** PDF pages, sheets, slides, Word parts or image frames. */
423
+ pages: number;
424
+ /** Pages stored from their text layer. */
425
+ pagesText: number;
426
+ /** Pages read by OCR with text. */
427
+ pagesOcr: number;
428
+ /** Blank pages, and pages OCR read as empty. */
429
+ pagesWithoutText: number[];
430
+ /** Pages waiting for OCR. */
431
+ ocrPending: number;
432
+ /** Pages OCR could not read after its retries; each keeps what an earlier upload stored for it. */
433
+ ocrFailed: number[];
434
+ documents: number;
435
+ /** Parts the write refused, each with why. */
436
+ rejected: {
437
+ id: string;
438
+ code: string;
439
+ message: string;
440
+ }[];
441
+ /** The locator fields its documents carry: page, sheet, rows, slide, heading, part, frame. */
442
+ locators: string[];
443
+ chunksEmbedded: number;
444
+ /** The file's latest parse. */
445
+ run: {
446
+ id: string;
447
+ kind: "parse" | "reparse";
448
+ state: string;
449
+ phase: string | null;
450
+ error: unknown;
451
+ retryAt?: Date;
452
+ };
453
+ /** When `failed`: `{ code, message }`. */
454
+ error: {
455
+ code: string;
456
+ message: string;
457
+ } | null;
458
+ updatedAt: Date;
459
+ }
460
+ /** What `files.upload` and `files.reparse` answer. */
461
+ export interface FileQueued {
462
+ /** `unchanged`: the same bytes and metadata as the file's last parse; nothing was queued. */
463
+ result?: "unchanged";
464
+ file: StoredFile;
465
+ run?: Run;
466
+ }
467
+ /** The largest file `files.upload` sends in one request; a larger one (up to 512 MiB) goes in parts. */
468
+ export declare const MAX_FILE_REQUEST_BYTES: number;
190
469
  /**
191
470
  * The Conare client.
192
471
  *
@@ -196,6 +475,18 @@ export declare class ConareError extends Error {
196
475
  export declare class Conare {
197
476
  readonly baseURL: string;
198
477
  readonly sources: Sources;
478
+ /** Snapshot runs of custom sources, and any run by id. */
479
+ readonly runs: Runs;
480
+ /** Files of documents written into a custom source. */
481
+ readonly imports: Imports;
482
+ /** Files (PDF, Word, PowerPoint, Excel, CSV, text, images) kept as documents, a page each. */
483
+ readonly files: Files;
484
+ /** Delete everything Conare holds of one of your users. */
485
+ readonly users: Users;
486
+ /** What changed, in order. */
487
+ readonly events: Events;
488
+ /** The organization requests act for (`X-Conare-Org`); undefined: the key's own. */
489
+ readonly organization: string | undefined;
199
490
  private readonly apiKey;
200
491
  private readonly timeout;
201
492
  private readonly maxRetries;
@@ -205,15 +496,27 @@ export declare class Conare {
205
496
  namespace(name: string): Namespace;
206
497
  /**
207
498
  * 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-"`.
499
+ * count and models; with `prefix`, only those whose name starts with it, e.g. one user's `"u7f3a9c-"`.
209
500
  */
210
501
  namespaces(options?: RequestOptions & {
211
502
  prefix?: string;
212
503
  }): Promise<NamespaceInfo[]>;
213
- /** Embed texts. Use type "query" for search queries and "document" (default) for stored text. */
214
- embed(input: string | string[], options?: RequestOptions & {
215
- type?: "document" | "query";
504
+ /**
505
+ * The organizations this key acts for, its own first. A multi-organization key lists each other one
506
+ * it still acts for; pass an `id` as the `organization` option of a client to act for it.
507
+ */
508
+ organizations(options?: RequestOptions): Promise<Organization[]>;
509
+ /**
510
+ * Embed texts. Use type "query" for search queries and "document" (default) for stored text.
511
+ * `outputDtype: "int8"` returns each vector as int8 values and one scale (vector ≈ values × scale),
512
+ * a quarter of the bytes; `dequantize` turns them back into floats.
513
+ */
514
+ embed(input: string | string[], options?: RequestOptions & EmbedOptions & {
515
+ outputDtype?: "float";
216
516
  }): Promise<number[][]>;
517
+ embed(input: string | string[], options: RequestOptions & EmbedOptions & {
518
+ outputDtype: "int8";
519
+ }): Promise<Int8Embeddings>;
217
520
  /**
218
521
  * Rerank 1-100 documents against a query, best first. Each document is 1-24,000 characters, the query at
219
522
  * most 8,192, and all of them together at most 256,000; more than 100 documents is a 400 `invalid_request`.
@@ -231,14 +534,15 @@ export declare class Namespace {
231
534
  constructor(client: Conare, name: string);
232
535
  private path;
233
536
  /**
234
- * Create the namespace before its first write. Only a namespace with a sparse (SPLADE) index
235
- * needs this: a write creates one without. Its index never changes: creating it again with the
236
- * other setting is a 409. Returns whether it has a sparse index.
537
+ * Create the namespace before its first write. Only a namespace embedded by `embeddingModel`
538
+ * (one of your organization's models from `GET /models`) needs this: a write creates one with the
539
+ * default model. Its model never changes: creating it again with another one is a 409. Returns
540
+ * the model that embeds it.
237
541
  */
238
542
  create(options?: RequestOptions & {
239
- sparse?: boolean;
543
+ embeddingModel?: string;
240
544
  }): Promise<{
241
- sparse: boolean;
545
+ embeddingModel: string;
242
546
  }>;
243
547
  /**
244
548
  * Add or replace documents. Accepts one or many; sends them in batches of 100. Returns the ids.
@@ -256,10 +560,19 @@ export declare class Namespace {
256
560
  */
257
561
  write(documents: DocumentInput | DocumentInput[], options?: RequestOptions): Promise<WriteResult[]>;
258
562
  /**
259
- * Store a PDF or an Excel workbook (.xlsx), at most 20 MiB: one document per PDF page with a
260
- * text layer (`<fileId>:page-3`) and Markdown tables per worksheet (`<fileId>:Sheet1-1`), each
261
- * with `file`, `file_id`, `file_type` and `page` or `sheet` metadata. `fileId` defaults to the
262
- * name in id characters; uploading the same one again replaces every document it made. Pages
563
+ * Store a PDF, a Word document (.docx), a PowerPoint deck (.pptx), an Excel workbook (.xlsx), a CSV or
564
+ * TSV, a text or Markdown file, or an image (PNG, JPEG, WebP, TIFF), at most 20 MiB. Say its type with
565
+ * `type`: it is read as that type, and bytes of another type are refused (415) rather than misread;
566
+ * without it the type comes from the bytes, then the name. One document per PDF page with a text
567
+ * layer (`<fileId>:page-3`), per image page (read by OCR), a CSV as Markdown tables with its header
568
+ * on every part and the rows each holds in `rows` metadata, a Word document as
569
+ * Markdown (`<fileId>:part-1`, more parts past 240 KiB), one per slide with text (`<fileId>:slide-2`:
570
+ * title, shapes in reading order, tables, speaker notes) and Markdown tables per worksheet
571
+ * (`<fileId>:Sheet1-1`), each with `file`, `file_id`, `file_type` and `page`, `part`, `slide` or
572
+ * `sheet` metadata. Slides with no text are listed in `slidesWithoutText`. `fileId` defaults to the
573
+ * name in id characters (a name with characters outside ASCII also gets 8 hex digits of its hash, so
574
+ * such names do not collide); uploading the same one again replaces every document it made, and two
575
+ * uploads of one id run one at a time. Pages
263
576
  * without a text layer (scans, images) are read by OCR: by default after the answer
264
577
  * (`ocrPending`, stored within about a minute), with `wait: true` before it (`pagesOcr`). Pages
265
578
  * with no text even then are listed in `pagesWithoutText` and not stored.
@@ -267,24 +580,34 @@ export declare class Namespace {
267
580
  uploadFile(file: Blob | Uint8Array | ArrayBuffer, name: string, options?: RequestOptions & {
268
581
  id?: string;
269
582
  wait?: boolean;
583
+ type?: FileType;
270
584
  }): Promise<FileUpload>;
271
585
  /**
272
- * Hybrid search, reranked. One result per document: its best passage. `retrievers` picks what
273
- * the search fuses (default `["vector", "keyword"]`); `"sparse"` needs a namespace created with
274
- * a sparse index. `rerankDepth` (1-100) has the reranker rank every passage among the first
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`.
586
+ * An upload's outcome: the last upload of `fileId` here in the last 7 days. While OCR reads after the
587
+ * answer, `ocrPending` lists its pages; once it ended, the pages it read are in `ids` and `pagesOcr`, and
588
+ * those it could not read in `pagesWithoutText`. A file id with no upload throws 404 `file_not_found`.
278
589
  */
279
- query(query: string, options?: RequestOptions & {
280
- topK?: number;
281
- filter?: Filter;
282
- rerank?: boolean;
283
- rerankDepth?: number;
284
- retrievers?: Retriever[];
285
- user?: string;
286
- userPrefix?: string;
287
- }): Promise<QueryResult[]>;
590
+ getFile(fileId: string, options?: RequestOptions): Promise<FileStatus>;
591
+ /**
592
+ * Hybrid search, reranked. One result per document: its best passage; `topK` documents when that
593
+ * many match. `retrievers` picks what the search fuses (default `["vector", "keyword"]`; listed
594
+ * retrievers run as listed, also on a vector-only custom model). `rerankDepth` (1-1000) is how many of the
595
+ * first passages the reranker ranks; unset, the first 20. `user` keeps the search to one user's documents and
596
+ * `userPrefix` (ending in `:`) to a group's; both combine with `filter`. An empty `user` or
597
+ * `userPrefix` is a 400, never "every user". `excludeIds` keeps those documents out.
598
+ */
599
+ query(query: string, options?: QueryOptions): Promise<QueryResult[]>;
600
+ /**
601
+ * A deep search, page by page: ranks `maxResults` documents once (at least `topK`; at most 1,000,
602
+ * or 5,000 on a custom model's engine) and yields them `topK` at a time. Later pages are read from
603
+ * that ranking (kept 15 minutes) without searching again, so they never repeat or skip a
604
+ * document; past `rerankDepth` results keep retrieval order (`reranked: false`). Pass a page's
605
+ * `nextCursor` as `cursor` to go on from it in another call (`query` is then ignored).
606
+ */
607
+ queryPages(query: string, options: QueryOptions & {
608
+ maxResults: number;
609
+ cursor?: string;
610
+ }): AsyncGenerator<QueryPage>;
288
611
  /** One document by id, or null if it does not exist. */
289
612
  get(id: string, options?: RequestOptions): Promise<Document | null>;
290
613
  /** Every document (id, metadata, updatedAt), fetched page by page as you iterate. `limit` is the page size: 1-100, default 50. */
@@ -293,41 +616,254 @@ export declare class Namespace {
293
616
  }): AsyncGenerator<DocumentSummary>;
294
617
  /** Delete one document. Throws a ConareError with status 404 (`document_not_found`) if it does not exist. */
295
618
  delete(id: string, options?: RequestOptions): Promise<void>;
296
- /** Delete up to 1000 documents by id in one call. Ids that do not exist are skipped. Returns how many were deleted. */
619
+ /**
620
+ * Delete up to 1000 documents by id in one call. Ids that do not exist are skipped; a namespace that
621
+ * does not exist throws ConareError 404 `namespace_not_found`. Returns how many were deleted.
622
+ */
297
623
  deleteMany(ids: string[], options?: RequestOptions): Promise<number>;
298
624
  /** Delete every document matching filter (at least one condition), calling until none match. Returns how many were deleted. */
299
625
  deleteWhere(filter: Filter, options?: RequestOptions): Promise<number>;
300
626
  /** 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
627
  drop(options?: RequestOptions): Promise<void>;
302
628
  }
303
- /** Apps connected through Conare that keep syncing into a namespace. */
629
+ /** Apps connected through Conare that keep syncing into a namespace, and custom sources you push to. */
304
630
  export declare class Sources {
305
631
  private readonly client;
632
+ /** The documents of a custom source. */
633
+ readonly documents: SourceDocuments;
306
634
  constructor(client: Conare);
635
+ /**
636
+ * Create a custom source: a set of documents you push into `namespace`, keyed by your own ids.
637
+ * With `user`, `users.delete(user)` deletes it with the user's documents.
638
+ */
639
+ create(params: {
640
+ type: "custom";
641
+ namespace: string;
642
+ name?: string;
643
+ user?: string;
644
+ }, options?: RequestOptions): Promise<CustomSource>;
307
645
  /**
308
646
  * Start connecting an app. Send the app owner to `connectUrl`; they come back to `redirectUrl`.
309
647
  * For your own users, connect each one into their own namespace, e.g. "user-42".
648
+ * Twenty and Granola (`auth: "apiKey"` in `types()`) take `config` instead: `apiKey`, and for
649
+ * Twenty `baseUrl` when self-hosted. Conare checks the key, the source starts syncing at once,
650
+ * and `connectUrl` is null.
310
651
  */
311
652
  connect(params: {
312
653
  type: string;
313
654
  namespace: string;
314
655
  name?: string;
315
656
  redirectUrl?: string;
657
+ syncIntervalSeconds?: number;
658
+ config?: {
659
+ baseUrl?: string;
660
+ apiKey: string;
661
+ };
316
662
  }, options?: RequestOptions): Promise<{
317
663
  source: Source;
318
- connectUrl: string;
664
+ connectUrl: string | null;
319
665
  }>;
320
- /** Every connected source. */
321
- list(options?: RequestOptions): Promise<Source[]>;
666
+ /** Set how often a source syncs: seconds from 300 (5 minutes) to 2592000 (30 days), or null for automatic. */
667
+ update(id: string, params: {
668
+ syncIntervalSeconds: number | null;
669
+ }, options?: RequestOptions): Promise<Source>;
670
+ /** Every source: the connected apps, then the custom sources (`kind: "custom"`). */
671
+ list(options?: RequestOptions): Promise<Array<Source | CustomSource>>;
322
672
  /** One source by id. */
323
- get(id: string, options?: RequestOptions): Promise<Source>;
324
- /** Start a sync now. */
325
- sync(id: string, options?: RequestOptions): Promise<Source>;
326
- /** Disconnect a source. Pass `deleteDocuments: true` to also delete what it synced. */
673
+ get(id: string, options?: RequestOptions): Promise<Source | CustomSource>;
674
+ /**
675
+ * Start a sync now. `full: true` re-reads everything the app holds instead of what changed: documents
676
+ * that changed are rewritten and ones Conare no longer keeps are deleted. It is for Gmail and the apps
677
+ * Conare reads itself (other apps answer 400), and Gmail's rows are billed again (`cost.usdPerMillionRows`).
678
+ */
679
+ sync(id: string, options?: RequestOptions & {
680
+ full?: boolean;
681
+ }): Promise<Source>;
682
+ /**
683
+ * Disconnect a source. Pass `deleteDocuments: true` to also delete what it synced. A custom
684
+ * source's documents are deleted by a run, which `runs.get` follows until the source is `deleted`.
685
+ */
327
686
  delete(id: string, options?: RequestOptions & {
328
687
  deleteDocuments?: boolean;
329
688
  }): Promise<void>;
330
689
  /** The apps you can connect. */
331
690
  types(options?: RequestOptions): Promise<SourceType[]>;
332
691
  }
692
+ /** The documents of a custom source, by source id. */
693
+ export declare class SourceDocuments {
694
+ private readonly client;
695
+ constructor(client: Conare);
696
+ /**
697
+ * Push documents (sent 100 at a time): what each write did, in order, once it is stored. Pushes
698
+ * of one source may run concurrently. With `runId`, they belong to that snapshot run.
699
+ */
700
+ put(sourceId: string, documents: CustomDocumentInput | CustomDocumentInput[], options?: RequestOptions & {
701
+ runId?: string;
702
+ }): Promise<PushResult[]>;
703
+ /**
704
+ * Which documents need a push: `need` are those the source does not hold with that `tag`,
705
+ * `excluded` those deleted with `exclude`. With `runId`, each one counts as seen by the run.
706
+ */
707
+ check(sourceId: string, documents: Array<{
708
+ externalId: string;
709
+ tag?: string;
710
+ }>, options?: RequestOptions & {
711
+ runId?: string;
712
+ }): Promise<{
713
+ need: string[];
714
+ excluded: string[];
715
+ }>;
716
+ /** Every document of the source in key order, page by page. `limit` is the page size: 1-100, default 50. */
717
+ list(sourceId: string, options?: RequestOptions & {
718
+ limit?: number;
719
+ }): AsyncGenerator<CustomDocument>;
720
+ /** One document with its text and metadata, by its `key` (or an external id that is its own key), or null. */
721
+ get(sourceId: string, key: string, options?: RequestOptions): Promise<CustomDocument | null>;
722
+ /**
723
+ * Delete documents by external id (1,000 a call). A tombstone at `seq` makes older pushes of each
724
+ * `stale` (one already writing too); one holding a higher `seq` is `kept`; `exclude` keeps it out until
725
+ * restored.
726
+ */
727
+ delete(sourceId: string, externalIds: string[], options?: RequestOptions & {
728
+ exclude?: boolean;
729
+ seq?: number;
730
+ }): Promise<{
731
+ deleted: number;
732
+ kept: number;
733
+ excluded: number;
734
+ }>;
735
+ /** Let excluded documents be pushed again. Returns how many were excluded. */
736
+ restore(sourceId: string, externalIds: string[], options?: RequestOptions): Promise<number>;
737
+ }
738
+ /**
739
+ * An open snapshot run: push or check the source's whole set through it, then complete it. The
740
+ * documents it never saw are deleted, unless that is over 10% (and over 1,000) at once: then the run
741
+ * is `held` until a second run at least 24 h later agrees.
742
+ */
743
+ export declare class SnapshotRun {
744
+ private readonly client;
745
+ readonly sourceId: string;
746
+ readonly run: Run;
747
+ constructor(client: Conare, sourceId: string, run: Run);
748
+ get id(): string;
749
+ put(documents: CustomDocumentInput | CustomDocumentInput[], options?: RequestOptions): Promise<PushResult[]>;
750
+ check(documents: Array<{
751
+ externalId: string;
752
+ tag?: string;
753
+ }>, options?: RequestOptions): Promise<{
754
+ need: string[];
755
+ excluded: string[];
756
+ }>;
757
+ /**
758
+ * Stop taking pushes and sweep. Waits up to `wait` seconds (default 100) for the run to finish,
759
+ * then follows it until it did (`runs.get`); `allowMassDelete` applies a sweep of any size.
760
+ */
761
+ complete(options?: RequestOptions & {
762
+ wait?: number;
763
+ allowMassDelete?: boolean;
764
+ poll?: number;
765
+ }): Promise<Run>;
766
+ }
767
+ export declare class Runs {
768
+ private readonly client;
769
+ constructor(client: Conare);
770
+ /**
771
+ * Open a snapshot run of a custom source (one active run at a time). `expected`, your count of
772
+ * the set, blocks the sweep of a run that saw under 90% of it; a run with no push for
773
+ * `idleTimeoutS` (60-86,400, default 3,600) is canceled.
774
+ */
775
+ open(sourceId: string, params?: {
776
+ expected?: number;
777
+ idleTimeoutS?: number;
778
+ }, options?: RequestOptions): Promise<SnapshotRun>;
779
+ get(id: string, options?: RequestOptions): Promise<Run>;
780
+ }
781
+ export declare class Imports {
782
+ private readonly client;
783
+ constructor(client: Conare);
784
+ /**
785
+ * Write a file of JSON lines (one `CustomDocumentInput` a line, snake_case, up to 1 GiB) into a
786
+ * custom source: it is uploaded in parts, each checked by its MD5, then imported by a run, which
787
+ * `runs.get` follows. `snapshot` also deletes what the file does not hold.
788
+ */
789
+ create(sourceId: string, file: Blob | Uint8Array | ArrayBuffer | string, params?: {
790
+ mode?: "delta" | "snapshot";
791
+ expected?: number;
792
+ allowMassDelete?: boolean;
793
+ filename?: string;
794
+ }, options?: RequestOptions): Promise<Run>;
795
+ }
796
+ export declare class Files {
797
+ private readonly client;
798
+ constructor(client: Conare);
799
+ /**
800
+ * Upload a file: it is stored and parsed in the background into a document per page, sheet part,
801
+ * slide or Word part, each citing where it came from; pages without text are read by OCR. Declare
802
+ * its `type` when you know it: it is then parsed as that type, and bytes of another type are a
803
+ * ConareError 415 `type_mismatch`. Up to 64 MiB goes in one request, larger files (up to 512 MiB)
804
+ * in parts of 16 MiB. `wait` (seconds, at most 100) holds the answer until the file is ready.
805
+ */
806
+ upload(params: {
807
+ file: Blob | Uint8Array | ArrayBuffer | string;
808
+ name: string;
809
+ namespace: string;
810
+ user?: string;
811
+ id?: string;
812
+ type?: FileType;
813
+ metadata?: Metadata;
814
+ wait?: number;
815
+ }, options?: RequestOptions): Promise<FileQueued>;
816
+ /** The files `ids` of a namespace (and user), or, without ids, its first 100 files. */
817
+ status(params: {
818
+ namespace: string;
819
+ user?: string;
820
+ ids?: string[];
821
+ }, options?: RequestOptions): Promise<StoredFile[]>;
822
+ /** Parse a file again from its stored original. */
823
+ reparse(id: string, params: {
824
+ namespace: string;
825
+ user?: string;
826
+ wait?: number;
827
+ }, options?: RequestOptions): Promise<FileQueued>;
828
+ /**
829
+ * Wait until every file of `ids` is ready or failed (polling `status` every `interval` ms), at most
830
+ * `timeout` ms (10 minutes by default): the files as they ended, or a ConareError `timeout`.
831
+ */
832
+ waitUntilReady(params: {
833
+ namespace: string;
834
+ user?: string;
835
+ ids: string[];
836
+ timeout?: number;
837
+ interval?: number;
838
+ }, options?: RequestOptions): Promise<StoredFile[]>;
839
+ }
840
+ export declare class Users {
841
+ private readonly client;
842
+ constructor(client: Conare);
843
+ /**
844
+ * Delete everything Conare holds of a user: their documents in every namespace and their
845
+ * sources. A purge run does it (writes for the user are refused meanwhile); it finishes once a
846
+ * second check 10 minutes after the first finds nothing. Asking again returns the same run.
847
+ */
848
+ delete(user: string, options?: RequestOptions): Promise<Run>;
849
+ /** `delete` for every user starting with `prefix` (at least 3 characters, ending in `:`). */
850
+ deletePrefix(prefix: string, options?: RequestOptions): Promise<Run>;
851
+ }
852
+ export declare class Events {
853
+ private readonly client;
854
+ constructor(client: Conare);
855
+ /**
856
+ * The events after `cursor`, oldest first (100 by default, at most 1,000): `seq` counts up by one
857
+ * with no gap, so pass `nextCursor` as the next `cursor`. `types` takes groups such as `"run.*"`.
858
+ */
859
+ list(params?: {
860
+ cursor?: string;
861
+ types?: string[];
862
+ userPrefix?: string;
863
+ limit?: number;
864
+ }, options?: RequestOptions): Promise<{
865
+ data: SyncEvent[];
866
+ nextCursor: string;
867
+ }>;
868
+ }
333
869
  export {};