conare 0.28.0 → 0.30.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 +75 -6
- package/dist/index.d.ts +201 -17
- package/dist/index.js +150 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,6 +24,15 @@ const results = await docs.query("how do refunds work?", { topK: 5 });
|
|
|
24
24
|
|
|
25
25
|
A namespace is created by its first write. Writing the same id again replaces the document.
|
|
26
26
|
|
|
27
|
+
## For coding agents
|
|
28
|
+
|
|
29
|
+
An agent writing against Conare (Claude Code, Cursor, Codex) reads the docs as they are today:
|
|
30
|
+
|
|
31
|
+
- The Conare skill: `npx skills add https://docs.conare.ai`
|
|
32
|
+
- Search the docs over MCP: `https://docs.conare.ai/mcp`
|
|
33
|
+
- Every page, listed: `https://docs.conare.ai/llms.txt` (in full: `/llms-full.txt`). Any page as Markdown: add `.md` to its URL.
|
|
34
|
+
- Every route, field and bound: `https://api.conare.ai/openapi.yaml`
|
|
35
|
+
|
|
27
36
|
## Reference
|
|
28
37
|
|
|
29
38
|
### Client
|
|
@@ -73,7 +82,7 @@ await docs.add({ id, text, user: "tenant-7:u_42", seq: 1759698843000 }); // a us
|
|
|
73
82
|
// than stored is "stale" and writes nothing
|
|
74
83
|
await docs.query("refunds", { userPrefix: "tenant-7:" }); // one user's documents (user) or a group's (userPrefix)
|
|
75
84
|
await docs.get("refunds"); // { id, text, metadata, updatedAt, version, user?, seq? } or null
|
|
76
|
-
for await (const doc of docs.list()) {} // every document, page by page ({ limit } per page: 1-100, default 50)
|
|
85
|
+
for await (const doc of docs.list()) {} // every document, page by page ({ limit } per page: 1-100, default 50; { order: "newest" } newest first)
|
|
77
86
|
await docs.delete("refunds"); // 404 document_not_found if it does not exist
|
|
78
87
|
await docs.deleteMany(["a", "b"]); // up to 1000 ids in one call; missing ids are skipped. Returns the count
|
|
79
88
|
await docs.deleteWhere({ team: "support" }); // every document matching the filter, whole documents. Returns the count
|
|
@@ -85,7 +94,9 @@ await docs.uploadFile(bytes, "report.pdf"); // any file up to 512 MiB in one
|
|
|
85
94
|
await docs.getFile("report.pdf"); // its state; once ready, its document and parse
|
|
86
95
|
await docs.drop(); // delete the namespace and its documents (succeeds if already emptied; 404 namespace_not_found if never written)
|
|
87
96
|
|
|
88
|
-
await
|
|
97
|
+
await docs.describe("Product docs, one page each"); // what it holds, in one line: namespaces() and an agent's list_namespaces show it
|
|
98
|
+
|
|
99
|
+
await conare.namespaces(); // [{ name, documents, description, ... }]
|
|
89
100
|
await conare.namespaces({ prefix: "u7f3a9c-" }); // one user's namespaces
|
|
90
101
|
```
|
|
91
102
|
|
|
@@ -150,6 +161,11 @@ order. `docs.create({ regexIndex: true })` before a namespace's first write make
|
|
|
150
161
|
await conare.embed(["some text"], { type: "query" }); // number[][]; type defaults to "document"
|
|
151
162
|
await conare.embed(["some text"], { outputDtype: "int8" }); // { values: Int8Array[], scales }; dequantize() gives floats
|
|
152
163
|
await conare.rerank("refund window", ["a", "b"], { topK: 1 }); // [{ index, score, document }], plus .unscored
|
|
164
|
+
|
|
165
|
+
// Both parts of the model: a vector per text and a vector per token. Blend the two scores with hybridScore().
|
|
166
|
+
const query = await conare.embed("refund window", { type: "query", tokenEmbeddings: true });
|
|
167
|
+
const documents = await conare.embed(["a", "b"], { tokenEmbeddings: true }); // up to 16 texts a call
|
|
168
|
+
hybridScore(query, documents, 0, 1); // the query against documents[1]
|
|
153
169
|
```
|
|
154
170
|
|
|
155
171
|
`outputDtype: "int8"` returns each vector as int8 values plus one scale (vector ≈ values × scale, scale = max|x| / 127):
|
|
@@ -174,6 +190,8 @@ if (out.state === "parsing") await conare.getParse(out.id); // OCR outlived
|
|
|
174
190
|
|
|
175
191
|
`parse` reads a file with the same parser as `uploadFile` and stores nothing; any key can call it, a models-only key
|
|
176
192
|
too. `uploadFile` takes the same options and answers the same `markdown`, `parts` and `withoutText` beside `ids`.
|
|
193
|
+
A page OCR could not read is in `ocrFailed` (empty when it read them all), apart from a blank page; an upload's
|
|
194
|
+
`ocrLayerOnly` lists the pages that kept their text layer alone because OCR could not read them.
|
|
177
195
|
|
|
178
196
|
### Sources
|
|
179
197
|
|
|
@@ -191,8 +209,10 @@ const { source, connectUrl } = await conare.sources.connect({
|
|
|
191
209
|
await conare.sources.types(); // [{ type, name, logoUrl }]
|
|
192
210
|
await conare.sources.list(); // [Source]
|
|
193
211
|
await conare.sources.get(source.id); // { id, type, name, namespace, status, error, documents, lastSyncedAt, createdAt }
|
|
194
|
-
await conare.sources.sync(source.id);
|
|
195
|
-
await conare.
|
|
212
|
+
const synced = await conare.sources.sync(source.id); // sync now: the Source, or a bucket's sync Run
|
|
213
|
+
if ("state" in synced) await conare.runs.get(synced.id); // a Run has `state`, a Source has `status`
|
|
214
|
+
const full = await conare.sources.sync(source.id, { full: true }); // re-read everything (Gmail and apps Conare reads itself); Gmail's rows are billed again
|
|
215
|
+
if (!("state" in full)) full.resyncNote; // what the re-read does
|
|
196
216
|
await conare.sources.update(source.id, { syncIntervalSeconds: 3600 }); // every hour; null is automatic
|
|
197
217
|
await conare.sources.delete(source.id, { deleteDocuments: true });
|
|
198
218
|
```
|
|
@@ -202,6 +222,34 @@ picked from what each sync reads, or on one you set from 5 minutes to 30 days. `
|
|
|
202
222
|
what an estimate of a month at any interval needs: the rows the last sync read, whether syncs read
|
|
203
223
|
only changes, and the prices.
|
|
204
224
|
|
|
225
|
+
Pages of public websites are a source too:
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
const site = await conare.sources.create({
|
|
229
|
+
type: "web",
|
|
230
|
+
namespace: "admissions",
|
|
231
|
+
urls: ["https://www.example.edu/admissions/dates", "https://www.example.edu/admissions/guide.pdf"],
|
|
232
|
+
});
|
|
233
|
+
const { data } = await conare.sources.failures(site.id); // [{ externalId, code: "refused", message, attempts }]
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Or give a website's address and Conare finds its pages itself, new ones included, at every sync:
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
const rival = await conare.sources.create({ type: "web", namespace: "competitors", site: "https://www.example.com" });
|
|
240
|
+
await conare.sources.update<WebSource>(rival.id, { syncIntervalSeconds: 3600 }); // an hour to a week; null is a day
|
|
241
|
+
await conare.namespace("competitors").query("enterprise plan price", { filter: { page_type: "pricing" } });
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Conare reads each page as the crawler `ConareBot` (robots.txt and a site's Crawl-delay obeyed, a site asked
|
|
245
|
+
only as fast as it answers), keeps it in the namespace with its address as `source_url` and its kind as
|
|
246
|
+
`page_type` (`pricing`, `blog`, `changelog`, `docs`, ...), and reads it again every `syncIntervalSeconds` (a day
|
|
247
|
+
by default), parsing it again only when it changed. Each website is its own source with its own interval.
|
|
248
|
+
|
|
249
|
+
`sources.sync()` answers a connected app's `Source`. A Google Cloud Storage or web source answers the sync
|
|
250
|
+
`Run` it queued (409 `run_active` while one is queued or running), and a custom or files source has
|
|
251
|
+
nothing to sync (409 `push_source`).
|
|
252
|
+
|
|
205
253
|
### Custom sources
|
|
206
254
|
|
|
207
255
|
A custom source is a set of documents you push from your own system, keyed by your own ids.
|
|
@@ -235,8 +283,13 @@ await conare.users.deletePrefix("tenant-7:");
|
|
|
235
283
|
await conare.events.list({ cursor: "0", types: ["run.*"] }); // { data: [{ seq, type, runId, data }], nextCursor }
|
|
236
284
|
```
|
|
237
285
|
|
|
238
|
-
`sources.list()` and `sources.get()` answer custom sources too, with `kind: "custom"
|
|
239
|
-
|
|
286
|
+
`sources.list()` and `sources.get()` answer custom sources too, with `kind: "custom"`, and the
|
|
287
|
+
files source of each namespace you upload to (`kind: "files"`), Google Cloud Storage buckets
|
|
288
|
+
(`kind: "gcs"`) and web sources (`kind: "web"`); a connected app has no `kind`. A custom source that holds an app keeps
|
|
289
|
+
`type: "custom"` and names the app in `app` (`"gmail"`; null otherwise). These carry `health` (`ok`, `degraded`, `failing`),
|
|
290
|
+
`display.state` (`needs_action` with `display.action` when you must act, such as `grant_access` on a
|
|
291
|
+
bucket) and `sync.lastError`. These calls send an `Idempotency-Key` when they create or delete
|
|
292
|
+
something, so their retries are safe.
|
|
240
293
|
|
|
241
294
|
### Errors
|
|
242
295
|
|
|
@@ -331,6 +384,22 @@ lowercased, with any character other than letters, digits, `_` and `-` as `-` (`
|
|
|
331
384
|
writes `next-js-github`). A namespace that already holds another owner's repository of the same
|
|
332
385
|
name is left alone, and that repository's sync stops with an error.
|
|
333
386
|
|
|
387
|
+
## Changes in 0.30.0
|
|
388
|
+
|
|
389
|
+
- `embed(..., { tokenEmbeddings: true })` returns `HybridEmbeddings`: each text's vector and a vector
|
|
390
|
+
per token, with `denseWeight`; `hybridScore(query, documents, q, d)` blends the two scores.
|
|
391
|
+
|
|
392
|
+
## Changes in 0.29.0
|
|
393
|
+
|
|
394
|
+
- `sources.sync()` returns `Source | Run`: a Google Cloud Storage source's sync answers its `Run`
|
|
395
|
+
(before, an object with `id` undefined and an Invalid Date). Code that reads `.status` or
|
|
396
|
+
`.resyncNote` on the result checks first: `if (!("state" in result)) result.status`.
|
|
397
|
+
- `sources.list()` and `sources.get()` decode a source by its `kind`: `FilesSource` and `GCSSource`
|
|
398
|
+
are new, a custom source carries `app`, and `sync` carries `lastSuccessAt`, `lastFailureAt`,
|
|
399
|
+
`nextRunAt` and `lastError`. `Run.kind` adds `sync` and `parse`.
|
|
400
|
+
- `parse`, `uploadFile` and `getFile` return `ocrFailed`; an upload also returns `ocrLayerOnly`.
|
|
401
|
+
- Namespaces carry their `description`, set with `describe()`.
|
|
402
|
+
|
|
334
403
|
## Development
|
|
335
404
|
|
|
336
405
|
```bash
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.30.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>;
|
|
@@ -104,7 +104,7 @@ export interface WriteResult {
|
|
|
104
104
|
imageEmbedded?: boolean;
|
|
105
105
|
}
|
|
106
106
|
/** A file type `uploadFile` can declare: the file is read as that type (`jpg` and `tif` are accepted too). */
|
|
107
|
-
export type FileType = "pdf" | "xlsx" | "docx" | "pptx" | "csv" | "tsv" | "txt" | "md" | "png" | "jpeg" | "webp" | "tiff" | "gif" | "bmp" | "heic";
|
|
107
|
+
export type FileType = "pdf" | "xlsx" | "docx" | "pptx" | "csv" | "tsv" | "txt" | "md" | "html" | "png" | "jpeg" | "webp" | "tiff" | "gif" | "bmp" | "heic";
|
|
108
108
|
/**
|
|
109
109
|
* A picture of a Word document or deck that OCR did not turn into text. Every raster picture is read except an
|
|
110
110
|
* icon or a decoration: under 64 pixels on both sides, under 16 pixels on its shorter side, or drawn under half
|
|
@@ -185,6 +185,11 @@ export interface ParseResult {
|
|
|
185
185
|
markdown: string;
|
|
186
186
|
parts: ParsePart[];
|
|
187
187
|
withoutText: WithoutText;
|
|
188
|
+
/**
|
|
189
|
+
* Pages, frames or slides OCR could not read, 1-based: they are not in the text and, unlike a blank page,
|
|
190
|
+
* parsing the file again can read them. Empty when OCR read them all.
|
|
191
|
+
*/
|
|
192
|
+
ocrFailed: number[];
|
|
188
193
|
}
|
|
189
194
|
/** A parse OCR was still reading after `wait`: `getParse(id)` answers the result (kept 24 hours). */
|
|
190
195
|
export interface ParsePending {
|
|
@@ -236,6 +241,10 @@ export interface FileUpload {
|
|
|
236
241
|
pagesWithImage: number[];
|
|
237
242
|
/** Pages waiting for OCR to try them again (`state: "ocr"`). */
|
|
238
243
|
ocrPending: number[];
|
|
244
|
+
/** A PDF's or image's pages OCR could not read after its retries, 1-based: in `pagesWithoutText` too, where a blank page is alone. */
|
|
245
|
+
ocrFailed: number[];
|
|
246
|
+
/** A PDF's or image's pages OCR could not read that hold their text layer alone, 1-based; uploading the same bytes again reads them again. */
|
|
247
|
+
ocrLayerOnly: number[];
|
|
239
248
|
/**
|
|
240
249
|
* `queued`, `parsing`: the parse runs; follow it with `getFile(fileId)`. `ocr`: stored, with pages OCR tries
|
|
241
250
|
* again (`ocrPending`). `ready`: every document is stored. `failed`: the parse failed or parts of it could not be
|
|
@@ -367,6 +376,8 @@ export interface NamespaceInfo {
|
|
|
367
376
|
updatedAt: string | null;
|
|
368
377
|
/** Its last query, recorded at most once a minute; null when not queried since 2026-10-18. */
|
|
369
378
|
lastQueryAt: string | null;
|
|
379
|
+
/** What it holds, in your own words (`namespace(name).describe()` sets it); null when it has none. */
|
|
380
|
+
description: string | null;
|
|
370
381
|
}
|
|
371
382
|
export interface RerankResult {
|
|
372
383
|
index: number;
|
|
@@ -389,6 +400,26 @@ export interface Int8Embeddings {
|
|
|
389
400
|
values: Int8Array[];
|
|
390
401
|
scales: number[];
|
|
391
402
|
}
|
|
403
|
+
/**
|
|
404
|
+
* Both parts of the embedding model (`embed(..., { tokenEmbeddings: true })`): each text's vector and, beside
|
|
405
|
+
* it, a vector per token. Rank a document for a query with `hybridScore`, which blends the two scores by
|
|
406
|
+
* `denseWeight`; either part also ranks alone.
|
|
407
|
+
*/
|
|
408
|
+
export interface HybridEmbeddings {
|
|
409
|
+
/** One vector per text, unit length. */
|
|
410
|
+
embeddings: number[][];
|
|
411
|
+
/** Per text, its token embeddings: rows of `tokenDimensions` floats. */
|
|
412
|
+
tokenEmbeddings: number[][][];
|
|
413
|
+
tokenDimensions: number;
|
|
414
|
+
/** The share of the `embeddings` score in the blended score, between 0 and 1. */
|
|
415
|
+
denseWeight: number;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Text `d` of `documents` scored for text `q` of `query` (one embedded with type "query", the other with
|
|
419
|
+
* "document", both with `tokenEmbeddings: true`): denseWeight × dot(the two vectors) + (1 − denseWeight) ×
|
|
420
|
+
* the mean, over the query's token embeddings, of each one's best dot product among the document's.
|
|
421
|
+
*/
|
|
422
|
+
export declare function hybridScore(query: HybridEmbeddings, documents: HybridEmbeddings, q?: number, d?: number): number;
|
|
392
423
|
/** The float vectors int8 embeddings stand for: values × scale. */
|
|
393
424
|
export declare function dequantize(embeddings: Int8Embeddings): number[][];
|
|
394
425
|
export type SourceStatus = "connecting" | "syncing" | "ready" | "error";
|
|
@@ -447,6 +478,8 @@ export interface CustomSource {
|
|
|
447
478
|
id: string;
|
|
448
479
|
kind: "custom";
|
|
449
480
|
type: "custom";
|
|
481
|
+
/** The app a custom source holds (`gmail`), or null. */
|
|
482
|
+
app: string | null;
|
|
450
483
|
namespace: string;
|
|
451
484
|
user: string | null;
|
|
452
485
|
name: string | null;
|
|
@@ -462,12 +495,91 @@ export interface CustomSource {
|
|
|
462
495
|
state: "idle" | "queued" | "running";
|
|
463
496
|
runId: string | null;
|
|
464
497
|
phase: string | null;
|
|
498
|
+
lastSuccessAt: Date | null;
|
|
499
|
+
lastFailureAt: Date | null;
|
|
500
|
+
nextRunAt: Date | null;
|
|
501
|
+
/** The last failed run's error, with `action` when there is something to do (`grant_access`); null once a run succeeds. */
|
|
502
|
+
lastError: {
|
|
503
|
+
code: string;
|
|
504
|
+
message?: string;
|
|
505
|
+
action?: string;
|
|
506
|
+
} | null;
|
|
465
507
|
};
|
|
466
508
|
documents: number | null;
|
|
467
509
|
documentsVerifiedAt: Date | null;
|
|
468
510
|
createdAt: Date;
|
|
469
511
|
updatedAt: Date;
|
|
470
512
|
}
|
|
513
|
+
/** The source of a namespace's uploaded files (one per namespace and user): `uploadFile` writes it. */
|
|
514
|
+
export interface FilesSource extends Omit<CustomSource, "kind" | "type" | "app"> {
|
|
515
|
+
kind: "files";
|
|
516
|
+
type: "files";
|
|
517
|
+
app: null;
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* A Google Cloud Storage bucket Conare reads every `config.syncIntervalSeconds`. `display.state` is
|
|
521
|
+
* `needs_action` with `display.action` `grant_access` when the bucket's grant was taken away.
|
|
522
|
+
*/
|
|
523
|
+
export interface GCSSource extends Omit<CustomSource, "kind" | "type" | "app" | "user"> {
|
|
524
|
+
kind: "gcs";
|
|
525
|
+
type: "gcs";
|
|
526
|
+
app: null;
|
|
527
|
+
user: null;
|
|
528
|
+
config: {
|
|
529
|
+
bucket: string;
|
|
530
|
+
prefixes: string[];
|
|
531
|
+
glob?: string;
|
|
532
|
+
serviceAccount: string;
|
|
533
|
+
syncIntervalSeconds: number;
|
|
534
|
+
};
|
|
535
|
+
/** Objects it holds no current document for. */
|
|
536
|
+
failures: number;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Pages of public websites Conare keeps in step with their sites: each is read again every
|
|
540
|
+
* `config.syncIntervalSeconds`, and parsed again only when it changed. `failures` counts the pages it could not
|
|
541
|
+
* read (the site refuses crawlers, wants a sign-in, or the page needs a browser to show its text).
|
|
542
|
+
*/
|
|
543
|
+
/** A page of a web source: its address, or its address with your fields, which every document of the page carries. */
|
|
544
|
+
export type WebPage = string | {
|
|
545
|
+
url: string;
|
|
546
|
+
metadata?: Record<string, string | number | boolean | string[]>;
|
|
547
|
+
};
|
|
548
|
+
export interface WebSource extends Omit<CustomSource, "kind" | "type" | "app" | "user"> {
|
|
549
|
+
kind: "web";
|
|
550
|
+
type: "web";
|
|
551
|
+
app: null;
|
|
552
|
+
user: null;
|
|
553
|
+
/**
|
|
554
|
+
* `urls`: the source's pages. For a source of a `site`, the pages its last sync found there, of at most `maxPages`.
|
|
555
|
+
*/
|
|
556
|
+
config: {
|
|
557
|
+
urls: string[];
|
|
558
|
+
syncIntervalSeconds: number;
|
|
559
|
+
site?: string;
|
|
560
|
+
maxPages?: number;
|
|
561
|
+
};
|
|
562
|
+
/** Pages it could not read or holds no current document for. */
|
|
563
|
+
failures: number;
|
|
564
|
+
}
|
|
565
|
+
/** One object of a Google Cloud Storage source, or one page of a web source, it could not keep, whole or in part. */
|
|
566
|
+
export interface SourceFailure {
|
|
567
|
+
/** The object (`gs://...`) or the page's address. */
|
|
568
|
+
externalId: string;
|
|
569
|
+
key: string;
|
|
570
|
+
/** The version that failed; empty for a page that was not read. */
|
|
571
|
+
version: string;
|
|
572
|
+
/**
|
|
573
|
+
* Why: a parse's code (`unsupported_file`, `too_large`, `pages_unread`, ...), or for a page what its site did
|
|
574
|
+
* (`refused`, `slow_down`, `robots_disallowed`, `sign_in_required`, `gone`, `unreachable`, `needs_javascript`).
|
|
575
|
+
*/
|
|
576
|
+
code: string;
|
|
577
|
+
message: string;
|
|
578
|
+
runId: string | null;
|
|
579
|
+
/** How many times in a row it failed this way. */
|
|
580
|
+
attempts: number;
|
|
581
|
+
failedAt: Date;
|
|
582
|
+
}
|
|
471
583
|
/** A document of a custom source to push. */
|
|
472
584
|
export interface CustomDocumentInput {
|
|
473
585
|
/** Your id for the document; its `key` is derived from it. */
|
|
@@ -513,11 +625,12 @@ export interface CustomDocument {
|
|
|
513
625
|
text?: string;
|
|
514
626
|
metadata?: Metadata;
|
|
515
627
|
}
|
|
516
|
-
/** A run: one pass of work on a source (a snapshot, an import, a delete, a user's purge). */
|
|
628
|
+
/** A run: one pass of work on a source (a snapshot, an import, a delete, a bucket's sync, a file's parse, a user's purge). */
|
|
517
629
|
export interface Run {
|
|
518
630
|
id: string;
|
|
519
631
|
sourceId: string | null;
|
|
520
|
-
|
|
632
|
+
/** `sync`: a Google Cloud Storage source's listing; `parse`: a file's parse. */
|
|
633
|
+
kind: "snapshot" | "import" | "delete" | "purge" | "sync" | "parse";
|
|
521
634
|
state: "queued" | "running" | "succeeded" | "failed" | "canceled";
|
|
522
635
|
phase: string | null;
|
|
523
636
|
attempt: number;
|
|
@@ -698,8 +811,8 @@ export declare class Conare {
|
|
|
698
811
|
/**
|
|
699
812
|
* The organizations this key acts for, its own first. A multi-organization key lists each other one
|
|
700
813
|
* it still acts for; pass an `id` as the `organization` option of a client to act for it. A
|
|
701
|
-
* customer key lists every organization of your customer (every page)
|
|
702
|
-
*
|
|
814
|
+
* customer key lists every organization of your customer (every page). With `externalId`, any key
|
|
815
|
+
* lists only the organizations it acts for that were made with it: none when there is none.
|
|
703
816
|
*/
|
|
704
817
|
organizations(options?: RequestOptions & {
|
|
705
818
|
externalId?: string;
|
|
@@ -756,14 +869,21 @@ export declare class Conare {
|
|
|
756
869
|
/**
|
|
757
870
|
* Embed texts. Use type "query" for search queries and "document" (default) for stored text.
|
|
758
871
|
* `outputDtype: "int8"` returns each vector as int8 values and one scale (vector ≈ values × scale),
|
|
759
|
-
* a quarter of the bytes; `dequantize` turns them back into floats.
|
|
872
|
+
* a quarter of the bytes; `dequantize` turns them back into floats. `tokenEmbeddings: true` returns both
|
|
873
|
+
* parts of the model, for up to 16 texts a call (`HybridEmbeddings`, scored with `hybridScore`).
|
|
760
874
|
*/
|
|
761
875
|
embed(input: string | string[], options?: RequestOptions & EmbedOptions & {
|
|
762
876
|
outputDtype?: "float";
|
|
877
|
+
tokenEmbeddings?: false;
|
|
763
878
|
}): Promise<number[][]>;
|
|
764
879
|
embed(input: string | string[], options: RequestOptions & EmbedOptions & {
|
|
765
880
|
outputDtype: "int8";
|
|
881
|
+
tokenEmbeddings?: false;
|
|
766
882
|
}): Promise<Int8Embeddings>;
|
|
883
|
+
embed(input: string | string[], options: RequestOptions & EmbedOptions & {
|
|
884
|
+
outputDtype?: "float";
|
|
885
|
+
tokenEmbeddings: true;
|
|
886
|
+
}): Promise<HybridEmbeddings>;
|
|
767
887
|
/**
|
|
768
888
|
* Rerank 1-100 documents against a query, best first. Each document is 1-24,000 characters, the query at
|
|
769
889
|
* most 8,192, and all of them together at most 256,000; more than 100 documents is a 400 `invalid_request`.
|
|
@@ -805,6 +925,12 @@ export declare class Namespace {
|
|
|
805
925
|
}): Promise<{
|
|
806
926
|
embeddingModel: string;
|
|
807
927
|
}>;
|
|
928
|
+
/**
|
|
929
|
+
* Say what the namespace holds, in one line of your own words (up to 300 characters; `""` removes
|
|
930
|
+
* it). `namespaces()` returns it, and the MCP server's `list_namespaces` shows it to an agent, which
|
|
931
|
+
* reads it to decide where to look and where to save. The namespace must exist.
|
|
932
|
+
*/
|
|
933
|
+
describe(description: string, options?: RequestOptions): Promise<void>;
|
|
808
934
|
/**
|
|
809
935
|
* Add or replace documents. Accepts one or many; sends them in batches of 100. Returns the ids.
|
|
810
936
|
* A document without an id gets one here, and each batch carries an `Idempotency-Key` reused on
|
|
@@ -875,9 +1001,15 @@ export declare class Namespace {
|
|
|
875
1001
|
}): AsyncGenerator<QueryPage>;
|
|
876
1002
|
/** One document by id, or null if it does not exist. */
|
|
877
1003
|
get(id: string, options?: RequestOptions): Promise<Document | null>;
|
|
878
|
-
/**
|
|
1004
|
+
/**
|
|
1005
|
+
* Every document (id, metadata, updatedAt), fetched page by page as you iterate. `limit` is the page size: 1-100, default 50.
|
|
1006
|
+
* `order` is `"id"` (the default) or `"newest"`: newest first by the document's date (its `date`, else its `created_at`),
|
|
1007
|
+
* else when it was last written. A namespace of more than 10,000 documents that holds documents written before
|
|
1008
|
+
* 2026-11-14 and not indexed by date since throws 400 `order_unavailable`: list it by `"id"`.
|
|
1009
|
+
*/
|
|
879
1010
|
list(options?: RequestOptions & {
|
|
880
1011
|
limit?: number;
|
|
1012
|
+
order?: "id" | "newest";
|
|
881
1013
|
}): AsyncGenerator<DocumentSummary>;
|
|
882
1014
|
/** Delete one document. Throws a ConareError with status 404 (`document_not_found`) if it does not exist. */
|
|
883
1015
|
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
@@ -909,6 +1041,17 @@ export declare class Sources {
|
|
|
909
1041
|
/**
|
|
910
1042
|
* Create a custom source: a set of documents you push into `namespace`, keyed by your own ids.
|
|
911
1043
|
* With `user`, `users.delete(user)` deletes it with the user's documents.
|
|
1044
|
+
*
|
|
1045
|
+
* With `type: "web"`, create a web source instead: Conare reads the pages at `urls` (HTML pages, PDFs and the
|
|
1046
|
+
* other file types it parses), keeps them in `namespace` and reads each again every `syncIntervalSeconds`
|
|
1047
|
+
* (a day by default, an hour at least). `failures(id)` lists the pages it could not read.
|
|
1048
|
+
* A page is never followed: the source is the pages you name.
|
|
1049
|
+
*
|
|
1050
|
+
* With `site` in place of `urls`, the source is a whole website: every sync finds the site's pages itself (its
|
|
1051
|
+
* sitemaps, feeds and links, on the site and its `docs.`, `blog.` and like hosts; an address with a path keeps
|
|
1052
|
+
* to the pages under it), new ones included, and keeps at most `maxPages` (2,000 by default, 5,000 at most).
|
|
1053
|
+
* Each page's documents carry `page_type` (`pricing`, `blog`, `changelog`, `docs` ...) and, when the page states
|
|
1054
|
+
* one, a `published` date, so `filter` can keep a search to them.
|
|
912
1055
|
*/
|
|
913
1056
|
create(params: {
|
|
914
1057
|
type: "custom";
|
|
@@ -916,6 +1059,21 @@ export declare class Sources {
|
|
|
916
1059
|
name?: string;
|
|
917
1060
|
user?: string;
|
|
918
1061
|
}, options?: RequestOptions): Promise<CustomSource>;
|
|
1062
|
+
create(params: {
|
|
1063
|
+
type: "web";
|
|
1064
|
+
namespace: string;
|
|
1065
|
+
urls: WebPage[];
|
|
1066
|
+
name?: string;
|
|
1067
|
+
syncIntervalSeconds?: number;
|
|
1068
|
+
}, options?: RequestOptions): Promise<WebSource>;
|
|
1069
|
+
create(params: {
|
|
1070
|
+
type: "web";
|
|
1071
|
+
namespace: string;
|
|
1072
|
+
site: string;
|
|
1073
|
+
maxPages?: number;
|
|
1074
|
+
name?: string;
|
|
1075
|
+
syncIntervalSeconds?: number;
|
|
1076
|
+
}, options?: RequestOptions): Promise<WebSource>;
|
|
919
1077
|
/**
|
|
920
1078
|
* Start connecting an app. Send the app owner to `connectUrl`; they come back to `redirectUrl`.
|
|
921
1079
|
* For your own users, connect each one into their own namespace, e.g. "user-42".
|
|
@@ -937,25 +1095,51 @@ export declare class Sources {
|
|
|
937
1095
|
source: Source;
|
|
938
1096
|
connectUrl: string | null;
|
|
939
1097
|
}>;
|
|
940
|
-
/**
|
|
941
|
-
|
|
1098
|
+
/**
|
|
1099
|
+
* Set how often a source syncs. A connected app: seconds from 300 (5 minutes) to 2592000 (30 days), or null for
|
|
1100
|
+
* automatic. A web source (`update<WebSource>`): 3600 to 604800, or null for a day; each website is its own
|
|
1101
|
+
* source with its own interval. A Google Cloud Storage source (`update<GCSSource>`): 900 to 604800, or null for
|
|
1102
|
+
* an hour.
|
|
1103
|
+
*/
|
|
1104
|
+
update<T extends Source | GCSSource | WebSource = Source>(id: string, params: {
|
|
942
1105
|
syncIntervalSeconds: number | null;
|
|
943
|
-
}, options?: RequestOptions): Promise<
|
|
944
|
-
/**
|
|
945
|
-
|
|
1106
|
+
}, options?: RequestOptions): Promise<T>;
|
|
1107
|
+
/**
|
|
1108
|
+
* Every source: the connected apps, then the custom, files and Google Cloud Storage sources, which carry
|
|
1109
|
+
* their `kind` (`custom`, `files`, `gcs`); a connected app has none.
|
|
1110
|
+
*/
|
|
1111
|
+
list(options?: RequestOptions): Promise<Array<Source | CustomSource | FilesSource | GCSSource | WebSource>>;
|
|
946
1112
|
/** One source by id. */
|
|
947
|
-
get(id: string, options?: RequestOptions): Promise<Source | CustomSource>;
|
|
1113
|
+
get(id: string, options?: RequestOptions): Promise<Source | CustomSource | FilesSource | GCSSource | WebSource>;
|
|
948
1114
|
/**
|
|
949
1115
|
* Start a sync now. `full: true` re-reads everything the app holds instead of what changed: documents
|
|
950
1116
|
* that changed are rewritten and ones Conare no longer keeps are deleted. It is for Gmail and the apps
|
|
951
1117
|
* Conare reads itself (other apps answer 400), and Gmail's rows are billed again (`cost.usdPerMillionRows`).
|
|
1118
|
+
*
|
|
1119
|
+
* A connected app answers the `Source`, due to sync now. A Google Cloud Storage or web source answers the sync
|
|
1120
|
+
* `Run` it queued (409 `run_active` while one is queued or running). A custom or files source has nothing
|
|
1121
|
+
* to sync: 409 `push_source`. A `Run` has `state` and a `Source` has `status`: `"state" in result` tells
|
|
1122
|
+
* them apart.
|
|
952
1123
|
*/
|
|
953
1124
|
sync(id: string, options?: RequestOptions & {
|
|
954
1125
|
full?: boolean;
|
|
955
|
-
}): Promise<Source>;
|
|
1126
|
+
}): Promise<Source | Run>;
|
|
1127
|
+
/**
|
|
1128
|
+
* What a Google Cloud Storage or web source could not keep, in key order: `nextCursor` is the next page's
|
|
1129
|
+
* `cursor`, null at the end.
|
|
1130
|
+
*/
|
|
1131
|
+
failures(id: string, params?: {
|
|
1132
|
+
cursor?: string;
|
|
1133
|
+
limit?: number;
|
|
1134
|
+
}, options?: RequestOptions): Promise<{
|
|
1135
|
+
data: SourceFailure[];
|
|
1136
|
+
nextCursor: string | null;
|
|
1137
|
+
}>;
|
|
956
1138
|
/**
|
|
957
|
-
* Disconnect a source. Pass `deleteDocuments: true` to also delete what it synced
|
|
958
|
-
*
|
|
1139
|
+
* Disconnect a source. Pass `deleteDocuments: true` to also delete what it synced; without it a
|
|
1140
|
+
* connected app's and a custom source's documents stay. A Google Cloud Storage, web or files
|
|
1141
|
+
* source's documents always go with it. A custom source's delete is a run, which `runs.get` follows
|
|
1142
|
+
* until the source is `deleted`.
|
|
959
1143
|
*/
|
|
960
1144
|
delete(id: string, options?: RequestOptions & {
|
|
961
1145
|
deleteDocuments?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// conare: TypeScript client for the Conare API. Zero dependencies; uses global fetch.
|
|
2
|
-
export const VERSION = "0.
|
|
2
|
+
export const VERSION = "0.30.0";
|
|
3
3
|
const DEFAULT_BASE_URL = "https://api.conare.ai";
|
|
4
4
|
const BATCH_SIZE = 100;
|
|
5
5
|
/** Above the API's 110 s deadline for a write: a call given up sooner is retried while the first still runs. */
|
|
@@ -22,6 +22,7 @@ function toParse(body) {
|
|
|
22
22
|
markdown: body.markdown,
|
|
23
23
|
parts: body.parts,
|
|
24
24
|
withoutText: body.without_text,
|
|
25
|
+
ocrFailed: body.ocr_failed ?? [],
|
|
25
26
|
};
|
|
26
27
|
}
|
|
27
28
|
/** The query parameters of `ParseOptions`. */
|
|
@@ -61,8 +62,25 @@ function toFileUpload(body) {
|
|
|
61
62
|
pagesWithoutText: body.pages_without_text ?? [],
|
|
62
63
|
pagesWithImage: body.pages_with_image ?? [],
|
|
63
64
|
ocrPending: body.ocr_pending ?? [],
|
|
65
|
+
ocrFailed: body.ocr_failed ?? [],
|
|
66
|
+
ocrLayerOnly: body.ocr_layer_only ?? [],
|
|
64
67
|
};
|
|
65
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Text `d` of `documents` scored for text `q` of `query` (one embedded with type "query", the other with
|
|
71
|
+
* "document", both with `tokenEmbeddings: true`): denseWeight × dot(the two vectors) + (1 − denseWeight) ×
|
|
72
|
+
* the mean, over the query's token embeddings, of each one's best dot product among the document's.
|
|
73
|
+
*/
|
|
74
|
+
export function hybridScore(query, documents, q = 0, d = 0) {
|
|
75
|
+
const dot = (a, b) => a.reduce((sum, x, i) => sum + x * (b[i] ?? 0), 0);
|
|
76
|
+
const queryRows = query.tokenEmbeddings[q] ?? [];
|
|
77
|
+
const documentRows = documents.tokenEmbeddings[d] ?? [];
|
|
78
|
+
const tokens = queryRows.reduce((sum, row) => sum + documentRows.reduce((best, other) => Math.max(best, dot(row, other)), -Infinity), 0);
|
|
79
|
+
const dense = dot(query.embeddings[q] ?? [], documents.embeddings[d] ?? []);
|
|
80
|
+
if (queryRows.length === 0 || documentRows.length === 0)
|
|
81
|
+
return query.denseWeight * dense;
|
|
82
|
+
return query.denseWeight * dense + (1 - query.denseWeight) * (tokens / queryRows.length);
|
|
83
|
+
}
|
|
66
84
|
/** The float vectors int8 embeddings stand for: values × scale. */
|
|
67
85
|
export function dequantize(embeddings) {
|
|
68
86
|
return embeddings.values.map((v, i) => Array.from(v, (x) => x * (embeddings.scales[i] ?? 0)));
|
|
@@ -201,13 +219,14 @@ export class Conare {
|
|
|
201
219
|
createdAt: n.created_at ?? null,
|
|
202
220
|
updatedAt: n.updated_at ?? null,
|
|
203
221
|
lastQueryAt: n.last_query_at ?? null,
|
|
222
|
+
description: n.description ?? null,
|
|
204
223
|
}));
|
|
205
224
|
}
|
|
206
225
|
/**
|
|
207
226
|
* The organizations this key acts for, its own first. A multi-organization key lists each other one
|
|
208
227
|
* it still acts for; pass an `id` as the `organization` option of a client to act for it. A
|
|
209
|
-
* customer key lists every organization of your customer (every page)
|
|
210
|
-
*
|
|
228
|
+
* customer key lists every organization of your customer (every page). With `externalId`, any key
|
|
229
|
+
* lists only the organizations it acts for that were made with it: none when there is none.
|
|
211
230
|
*/
|
|
212
231
|
async organizations(options = {}) {
|
|
213
232
|
const out = [];
|
|
@@ -312,7 +331,17 @@ export class Conare {
|
|
|
312
331
|
const request = { input: Array.isArray(input) ? input : [input], type: options.type ?? "document" };
|
|
313
332
|
if (options.outputDtype)
|
|
314
333
|
request.output_dtype = options.outputDtype;
|
|
334
|
+
if (options.tokenEmbeddings)
|
|
335
|
+
request.token_embeddings = true;
|
|
315
336
|
const body = await this.request("POST", "/embed", request, options);
|
|
337
|
+
if (options.tokenEmbeddings) {
|
|
338
|
+
return {
|
|
339
|
+
embeddings: body.embeddings,
|
|
340
|
+
tokenEmbeddings: body.token_embeddings ?? [],
|
|
341
|
+
tokenDimensions: body.token_dimensions ?? 0,
|
|
342
|
+
denseWeight: body.dense_weight ?? 0,
|
|
343
|
+
};
|
|
344
|
+
}
|
|
316
345
|
if (options.outputDtype === "int8") {
|
|
317
346
|
return { values: body.embeddings.map((v) => Int8Array.from(v)), scales: body.scales ?? [] };
|
|
318
347
|
}
|
|
@@ -462,6 +491,14 @@ export class Namespace {
|
|
|
462
491
|
const body = await this.client.request("POST", "/namespaces", { name: this.name, embedding_model: options.embeddingModel, regex_index: options.regexIndex }, options);
|
|
463
492
|
return { embeddingModel: body.embedding_model };
|
|
464
493
|
}
|
|
494
|
+
/**
|
|
495
|
+
* Say what the namespace holds, in one line of your own words (up to 300 characters; `""` removes
|
|
496
|
+
* it). `namespaces()` returns it, and the MCP server's `list_namespaces` shows it to an agent, which
|
|
497
|
+
* reads it to decide where to look and where to save. The namespace must exist.
|
|
498
|
+
*/
|
|
499
|
+
async describe(description, options) {
|
|
500
|
+
await this.client.request("PATCH", this.path(), { description }, options);
|
|
501
|
+
}
|
|
465
502
|
/**
|
|
466
503
|
* Add or replace documents. Accepts one or many; sends them in batches of 100. Returns the ids.
|
|
467
504
|
* A document without an id gets one here, and each batch carries an `Idempotency-Key` reused on
|
|
@@ -612,13 +649,20 @@ export class Namespace {
|
|
|
612
649
|
throw err;
|
|
613
650
|
}
|
|
614
651
|
}
|
|
615
|
-
/**
|
|
652
|
+
/**
|
|
653
|
+
* Every document (id, metadata, updatedAt), fetched page by page as you iterate. `limit` is the page size: 1-100, default 50.
|
|
654
|
+
* `order` is `"id"` (the default) or `"newest"`: newest first by the document's date (its `date`, else its `created_at`),
|
|
655
|
+
* else when it was last written. A namespace of more than 10,000 documents that holds documents written before
|
|
656
|
+
* 2026-11-14 and not indexed by date since throws 400 `order_unavailable`: list it by `"id"`.
|
|
657
|
+
*/
|
|
616
658
|
async *list(options = {}) {
|
|
617
659
|
let cursor = null;
|
|
618
660
|
do {
|
|
619
661
|
const params = new URLSearchParams();
|
|
620
662
|
if (options.limit)
|
|
621
663
|
params.set("limit", String(options.limit));
|
|
664
|
+
if (options.order)
|
|
665
|
+
params.set("order", options.order);
|
|
622
666
|
if (cursor)
|
|
623
667
|
params.set("cursor", cursor);
|
|
624
668
|
const qs = params.toString();
|
|
@@ -675,11 +719,12 @@ export class Sources {
|
|
|
675
719
|
this.client = client;
|
|
676
720
|
this.documents = new SourceDocuments(client);
|
|
677
721
|
}
|
|
678
|
-
/**
|
|
679
|
-
* Create a custom source: a set of documents you push into `namespace`, keyed by your own ids.
|
|
680
|
-
* With `user`, `users.delete(user)` deletes it with the user's documents.
|
|
681
|
-
*/
|
|
682
722
|
async create(params, options) {
|
|
723
|
+
if (params.type === "web") {
|
|
724
|
+
const pages = "site" in params ? { site: params.site, max_pages: params.maxPages } : { urls: params.urls };
|
|
725
|
+
const body = await this.client.request("POST", "/sources", { type: "web", namespace: params.namespace, ...pages, name: params.name, sync_interval_s: params.syncIntervalSeconds }, options);
|
|
726
|
+
return toAnySource(body);
|
|
727
|
+
}
|
|
683
728
|
const body = await this.client.request("POST", "/sources", { type: params.type, namespace: params.namespace, name: params.name, user: params.user }, options);
|
|
684
729
|
return toCustomSource(body);
|
|
685
730
|
}
|
|
@@ -701,11 +746,19 @@ export class Sources {
|
|
|
701
746
|
}, options);
|
|
702
747
|
return { source: toSource(body.source), connectUrl: body.connect_url ?? null };
|
|
703
748
|
}
|
|
704
|
-
/**
|
|
749
|
+
/**
|
|
750
|
+
* Set how often a source syncs. A connected app: seconds from 300 (5 minutes) to 2592000 (30 days), or null for
|
|
751
|
+
* automatic. A web source (`update<WebSource>`): 3600 to 604800, or null for a day; each website is its own
|
|
752
|
+
* source with its own interval. A Google Cloud Storage source (`update<GCSSource>`): 900 to 604800, or null for
|
|
753
|
+
* an hour.
|
|
754
|
+
*/
|
|
705
755
|
async update(id, params, options) {
|
|
706
|
-
return
|
|
756
|
+
return toAnySource(await this.client.request("PATCH", `/sources/${segment(id)}`, { sync_interval_s: params.syncIntervalSeconds }, options));
|
|
707
757
|
}
|
|
708
|
-
/**
|
|
758
|
+
/**
|
|
759
|
+
* Every source: the connected apps, then the custom, files and Google Cloud Storage sources, which carry
|
|
760
|
+
* their `kind` (`custom`, `files`, `gcs`); a connected app has none.
|
|
761
|
+
*/
|
|
709
762
|
async list(options) {
|
|
710
763
|
const body = await this.client.request("GET", "/sources", undefined, options);
|
|
711
764
|
return body.sources.map(toAnySource);
|
|
@@ -718,14 +771,47 @@ export class Sources {
|
|
|
718
771
|
* Start a sync now. `full: true` re-reads everything the app holds instead of what changed: documents
|
|
719
772
|
* that changed are rewritten and ones Conare no longer keeps are deleted. It is for Gmail and the apps
|
|
720
773
|
* Conare reads itself (other apps answer 400), and Gmail's rows are billed again (`cost.usdPerMillionRows`).
|
|
774
|
+
*
|
|
775
|
+
* A connected app answers the `Source`, due to sync now. A Google Cloud Storage or web source answers the sync
|
|
776
|
+
* `Run` it queued (409 `run_active` while one is queued or running). A custom or files source has nothing
|
|
777
|
+
* to sync: 409 `push_source`. A `Run` has `state` and a `Source` has `status`: `"state" in result` tells
|
|
778
|
+
* them apart.
|
|
721
779
|
*/
|
|
722
780
|
async sync(id, options = {}) {
|
|
723
781
|
const { full, ...request } = options;
|
|
724
|
-
|
|
782
|
+
const body = await this.client.request("POST", `/sources/${segment(id)}/sync`, full ? { full: true } : undefined, request);
|
|
783
|
+
return "run" in body ? toRun(body.run) : toSource(body);
|
|
725
784
|
}
|
|
726
785
|
/**
|
|
727
|
-
*
|
|
728
|
-
*
|
|
786
|
+
* What a Google Cloud Storage or web source could not keep, in key order: `nextCursor` is the next page's
|
|
787
|
+
* `cursor`, null at the end.
|
|
788
|
+
*/
|
|
789
|
+
async failures(id, params = {}, options) {
|
|
790
|
+
const query = [];
|
|
791
|
+
if (params.cursor)
|
|
792
|
+
query.push(`cursor=${encodeURIComponent(params.cursor)}`);
|
|
793
|
+
if (params.limit !== undefined)
|
|
794
|
+
query.push(`limit=${params.limit}`);
|
|
795
|
+
const body = await this.client.request("GET", `/sources/${segment(id)}/failures${query.length ? `?${query.join("&")}` : ""}`, undefined, options);
|
|
796
|
+
return {
|
|
797
|
+
data: body.data.map((f) => ({
|
|
798
|
+
externalId: f.external_id,
|
|
799
|
+
key: f.key,
|
|
800
|
+
version: f.version,
|
|
801
|
+
code: f.code,
|
|
802
|
+
message: f.message,
|
|
803
|
+
runId: f.run_id,
|
|
804
|
+
attempts: f.attempts,
|
|
805
|
+
failedAt: new Date(f.failed_at),
|
|
806
|
+
})),
|
|
807
|
+
nextCursor: body.next_cursor,
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Disconnect a source. Pass `deleteDocuments: true` to also delete what it synced; without it a
|
|
812
|
+
* connected app's and a custom source's documents stay. A Google Cloud Storage, web or files
|
|
813
|
+
* source's documents always go with it. A custom source's delete is a run, which `runs.get` follows
|
|
814
|
+
* until the source is `deleted`.
|
|
729
815
|
*/
|
|
730
816
|
async delete(id, options = {}) {
|
|
731
817
|
const qs = options.deleteDocuments ? "?delete_documents=true" : "";
|
|
@@ -968,23 +1054,70 @@ export class Events {
|
|
|
968
1054
|
};
|
|
969
1055
|
}
|
|
970
1056
|
}
|
|
1057
|
+
/** A source by its `kind`: a connected app has none; a custom, files, Google Cloud Storage or web source names it. */
|
|
971
1058
|
function toAnySource(s) {
|
|
972
|
-
|
|
1059
|
+
if (!("kind" in s))
|
|
1060
|
+
return toSource(s);
|
|
1061
|
+
if (s.kind === "web") {
|
|
1062
|
+
return {
|
|
1063
|
+
...toCustomSource(s),
|
|
1064
|
+
kind: "web",
|
|
1065
|
+
type: "web",
|
|
1066
|
+
app: null,
|
|
1067
|
+
user: null,
|
|
1068
|
+
config: {
|
|
1069
|
+
urls: s.config?.urls ?? [],
|
|
1070
|
+
syncIntervalSeconds: s.config?.sync_interval_s ?? 0,
|
|
1071
|
+
...(s.config?.site ? { site: s.config.site, maxPages: s.config.max_pages } : {}),
|
|
1072
|
+
},
|
|
1073
|
+
failures: s.failures ?? 0,
|
|
1074
|
+
};
|
|
1075
|
+
}
|
|
1076
|
+
if (s.kind === "gcs") {
|
|
1077
|
+
const c = s.config;
|
|
1078
|
+
return {
|
|
1079
|
+
...toCustomSource(s),
|
|
1080
|
+
kind: "gcs",
|
|
1081
|
+
type: "gcs",
|
|
1082
|
+
app: null,
|
|
1083
|
+
user: null,
|
|
1084
|
+
config: {
|
|
1085
|
+
bucket: c?.bucket ?? "",
|
|
1086
|
+
prefixes: c?.prefixes ?? [],
|
|
1087
|
+
...(c?.glob ? { glob: c.glob } : {}),
|
|
1088
|
+
serviceAccount: c?.service_account ?? "",
|
|
1089
|
+
syncIntervalSeconds: c?.sync_interval_s ?? 0,
|
|
1090
|
+
},
|
|
1091
|
+
failures: s.failures ?? 0,
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1094
|
+
return s.kind === "files" ? { ...toCustomSource(s), kind: "files", type: "files", app: null } : toCustomSource(s);
|
|
973
1095
|
}
|
|
1096
|
+
/** A custom source; with a files or Google Cloud Storage source's wire, the fields they share. */
|
|
974
1097
|
function toCustomSource(s) {
|
|
1098
|
+
const date = (t) => (t ? new Date(t) : null);
|
|
975
1099
|
return {
|
|
976
1100
|
id: s.id,
|
|
977
1101
|
kind: "custom",
|
|
978
1102
|
type: "custom",
|
|
1103
|
+
app: s.type === "custom" ? null : s.type,
|
|
979
1104
|
namespace: s.namespace,
|
|
980
1105
|
user: s.user,
|
|
981
1106
|
name: s.name,
|
|
982
1107
|
status: s.status,
|
|
983
1108
|
health: s.health,
|
|
984
1109
|
display: s.display,
|
|
985
|
-
sync: {
|
|
1110
|
+
sync: {
|
|
1111
|
+
state: s.sync.state,
|
|
1112
|
+
runId: s.sync.run_id,
|
|
1113
|
+
phase: s.sync.phase,
|
|
1114
|
+
lastSuccessAt: date(s.sync.last_success_at),
|
|
1115
|
+
lastFailureAt: date(s.sync.last_failure_at),
|
|
1116
|
+
nextRunAt: date(s.sync.next_run_at),
|
|
1117
|
+
lastError: s.sync.last_error ?? null,
|
|
1118
|
+
},
|
|
986
1119
|
documents: s.documents,
|
|
987
|
-
documentsVerifiedAt:
|
|
1120
|
+
documentsVerifiedAt: date(s.documents_verified_at),
|
|
988
1121
|
createdAt: new Date(s.created_at),
|
|
989
1122
|
updatedAt: new Date(s.updated_at),
|
|
990
1123
|
};
|