conare 0.27.0 → 0.29.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 +44 -5
- package/dist/index.d.ts +87 -13
- package/dist/index.js +69 -14
- 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
|
|
@@ -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
|
|
|
@@ -110,6 +121,10 @@ fuses: `"vector"` (the embedding model) and `"keyword"` (BM25; alone, BM25 alone
|
|
|
110
121
|
`score` is the reranker's when `reranked` is true, else the fused rank score of a result past the
|
|
111
122
|
rerank window (or of a query not reranked); the two scales do not compare.
|
|
112
123
|
|
|
124
|
+
A search that lost a part still answers: the results carry `.degraded`, the parts it lost (`["rerank"]`
|
|
125
|
+
when the reranker did not answer, `["embed"]` when only keywords searched), empty when it lost nothing.
|
|
126
|
+
Each page of `queryPages` has the same field.
|
|
127
|
+
|
|
113
128
|
Filters match metadata values: `{ key: value }` means equals (or, for an array value,
|
|
114
129
|
contains). Operators: `$eq`, `$in`, `$ne`, `$nin` (queries only) and the ranges below. Combine with `$and` and `$or`:
|
|
115
130
|
|
|
@@ -170,6 +185,8 @@ if (out.state === "parsing") await conare.getParse(out.id); // OCR outlived
|
|
|
170
185
|
|
|
171
186
|
`parse` reads a file with the same parser as `uploadFile` and stores nothing; any key can call it, a models-only key
|
|
172
187
|
too. `uploadFile` takes the same options and answers the same `markdown`, `parts` and `withoutText` beside `ids`.
|
|
188
|
+
A page OCR could not read is in `ocrFailed` (empty when it read them all), apart from a blank page; an upload's
|
|
189
|
+
`ocrLayerOnly` lists the pages that kept their text layer alone because OCR could not read them.
|
|
173
190
|
|
|
174
191
|
### Sources
|
|
175
192
|
|
|
@@ -187,8 +204,10 @@ const { source, connectUrl } = await conare.sources.connect({
|
|
|
187
204
|
await conare.sources.types(); // [{ type, name, logoUrl }]
|
|
188
205
|
await conare.sources.list(); // [Source]
|
|
189
206
|
await conare.sources.get(source.id); // { id, type, name, namespace, status, error, documents, lastSyncedAt, createdAt }
|
|
190
|
-
await conare.sources.sync(source.id);
|
|
191
|
-
await conare.
|
|
207
|
+
const synced = await conare.sources.sync(source.id); // sync now: the Source, or a bucket's sync Run
|
|
208
|
+
if ("state" in synced) await conare.runs.get(synced.id); // a Run has `state`, a Source has `status`
|
|
209
|
+
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
|
|
210
|
+
if (!("state" in full)) full.resyncNote; // what the re-read does
|
|
192
211
|
await conare.sources.update(source.id, { syncIntervalSeconds: 3600 }); // every hour; null is automatic
|
|
193
212
|
await conare.sources.delete(source.id, { deleteDocuments: true });
|
|
194
213
|
```
|
|
@@ -198,6 +217,10 @@ picked from what each sync reads, or on one you set from 5 minutes to 30 days. `
|
|
|
198
217
|
what an estimate of a month at any interval needs: the rows the last sync read, whether syncs read
|
|
199
218
|
only changes, and the prices.
|
|
200
219
|
|
|
220
|
+
`sources.sync()` answers a connected app's `Source`. A Google Cloud Storage source answers the sync
|
|
221
|
+
`Run` it queued (409 `run_active` while one is queued or running), and a custom or files source has
|
|
222
|
+
nothing to sync (409 `push_source`).
|
|
223
|
+
|
|
201
224
|
### Custom sources
|
|
202
225
|
|
|
203
226
|
A custom source is a set of documents you push from your own system, keyed by your own ids.
|
|
@@ -231,8 +254,13 @@ await conare.users.deletePrefix("tenant-7:");
|
|
|
231
254
|
await conare.events.list({ cursor: "0", types: ["run.*"] }); // { data: [{ seq, type, runId, data }], nextCursor }
|
|
232
255
|
```
|
|
233
256
|
|
|
234
|
-
`sources.list()` and `sources.get()` answer custom sources too, with `kind: "custom"
|
|
235
|
-
|
|
257
|
+
`sources.list()` and `sources.get()` answer custom sources too, with `kind: "custom"`, and the
|
|
258
|
+
files source of each namespace you upload to (`kind: "files"`) and Google Cloud Storage buckets
|
|
259
|
+
(`kind: "gcs"`); a connected app has no `kind`. A custom source that holds an app keeps
|
|
260
|
+
`type: "custom"` and names the app in `app` (`"gmail"`; null otherwise). These carry `health` (`ok`, `degraded`, `failing`),
|
|
261
|
+
`display.state` (`needs_action` with `display.action` when you must act, such as `grant_access` on a
|
|
262
|
+
bucket) and `sync.lastError`. These calls send an `Idempotency-Key` when they create or delete
|
|
263
|
+
something, so their retries are safe.
|
|
236
264
|
|
|
237
265
|
### Errors
|
|
238
266
|
|
|
@@ -327,6 +355,17 @@ lowercased, with any character other than letters, digits, `_` and `-` as `-` (`
|
|
|
327
355
|
writes `next-js-github`). A namespace that already holds another owner's repository of the same
|
|
328
356
|
name is left alone, and that repository's sync stops with an error.
|
|
329
357
|
|
|
358
|
+
## Changes in 0.29.0
|
|
359
|
+
|
|
360
|
+
- `sources.sync()` returns `Source | Run`: a Google Cloud Storage source's sync answers its `Run`
|
|
361
|
+
(before, an object with `id` undefined and an Invalid Date). Code that reads `.status` or
|
|
362
|
+
`.resyncNote` on the result checks first: `if (!("state" in result)) result.status`.
|
|
363
|
+
- `sources.list()` and `sources.get()` decode a source by its `kind`: `FilesSource` and `GCSSource`
|
|
364
|
+
are new, a custom source carries `app`, and `sync` carries `lastSuccessAt`, `lastFailureAt`,
|
|
365
|
+
`nextRunAt` and `lastError`. `Run.kind` adds `sync` and `parse`.
|
|
366
|
+
- `parse`, `uploadFile` and `getFile` return `ocrFailed`; an upload also returns `ocrLayerOnly`.
|
|
367
|
+
- Namespaces carry their `description`, set with `describe()`.
|
|
368
|
+
|
|
330
369
|
## Development
|
|
331
370
|
|
|
332
371
|
```bash
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.29.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>;
|
|
@@ -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
|
|
@@ -338,9 +347,19 @@ export interface GrepPage {
|
|
|
338
347
|
/** Where the next page starts; null on the last page. A page can stop short of `limit`. */
|
|
339
348
|
nextCursor: string | null;
|
|
340
349
|
}
|
|
350
|
+
/**
|
|
351
|
+
* A search's results, best first, and what the search lost on the way (the values of the `Conare-Degraded`
|
|
352
|
+
* header, such as `rerank` when no result was reranked or `embed` when only keywords searched); empty when it
|
|
353
|
+
* lost nothing. A search that lost a part still answers 200: read `.degraded` before trusting the order.
|
|
354
|
+
*/
|
|
355
|
+
export type QueryResults = QueryResult[] & {
|
|
356
|
+
degraded: string[];
|
|
357
|
+
};
|
|
341
358
|
/** One page of `Namespace.queryPages`. */
|
|
342
359
|
export interface QueryPage {
|
|
343
360
|
results: QueryResult[];
|
|
361
|
+
/** What this page's search lost (see `QueryResults`); empty when it lost nothing. */
|
|
362
|
+
degraded: string[];
|
|
344
363
|
/** Where the next page starts (`queryPages`'s `cursor`); null on the last page. */
|
|
345
364
|
nextCursor: string | null;
|
|
346
365
|
}
|
|
@@ -357,6 +376,8 @@ export interface NamespaceInfo {
|
|
|
357
376
|
updatedAt: string | null;
|
|
358
377
|
/** Its last query, recorded at most once a minute; null when not queried since 2026-10-18. */
|
|
359
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;
|
|
360
381
|
}
|
|
361
382
|
export interface RerankResult {
|
|
362
383
|
index: number;
|
|
@@ -437,6 +458,8 @@ export interface CustomSource {
|
|
|
437
458
|
id: string;
|
|
438
459
|
kind: "custom";
|
|
439
460
|
type: "custom";
|
|
461
|
+
/** The app a custom source holds (`gmail`), or null. */
|
|
462
|
+
app: string | null;
|
|
440
463
|
namespace: string;
|
|
441
464
|
user: string | null;
|
|
442
465
|
name: string | null;
|
|
@@ -452,12 +475,46 @@ export interface CustomSource {
|
|
|
452
475
|
state: "idle" | "queued" | "running";
|
|
453
476
|
runId: string | null;
|
|
454
477
|
phase: string | null;
|
|
478
|
+
lastSuccessAt: Date | null;
|
|
479
|
+
lastFailureAt: Date | null;
|
|
480
|
+
nextRunAt: Date | null;
|
|
481
|
+
/** The last failed run's error, with `action` when there is something to do (`grant_access`); null once a run succeeds. */
|
|
482
|
+
lastError: {
|
|
483
|
+
code: string;
|
|
484
|
+
message?: string;
|
|
485
|
+
action?: string;
|
|
486
|
+
} | null;
|
|
455
487
|
};
|
|
456
488
|
documents: number | null;
|
|
457
489
|
documentsVerifiedAt: Date | null;
|
|
458
490
|
createdAt: Date;
|
|
459
491
|
updatedAt: Date;
|
|
460
492
|
}
|
|
493
|
+
/** The source of a namespace's uploaded files (one per namespace and user): `uploadFile` writes it. */
|
|
494
|
+
export interface FilesSource extends Omit<CustomSource, "kind" | "type" | "app"> {
|
|
495
|
+
kind: "files";
|
|
496
|
+
type: "files";
|
|
497
|
+
app: null;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* A Google Cloud Storage bucket Conare reads every `config.syncIntervalSeconds`. `display.state` is
|
|
501
|
+
* `needs_action` with `display.action` `grant_access` when the bucket's grant was taken away.
|
|
502
|
+
*/
|
|
503
|
+
export interface GCSSource extends Omit<CustomSource, "kind" | "type" | "app" | "user"> {
|
|
504
|
+
kind: "gcs";
|
|
505
|
+
type: "gcs";
|
|
506
|
+
app: null;
|
|
507
|
+
user: null;
|
|
508
|
+
config: {
|
|
509
|
+
bucket: string;
|
|
510
|
+
prefixes: string[];
|
|
511
|
+
glob?: string;
|
|
512
|
+
serviceAccount: string;
|
|
513
|
+
syncIntervalSeconds: number;
|
|
514
|
+
};
|
|
515
|
+
/** Objects it holds no current document for. */
|
|
516
|
+
failures: number;
|
|
517
|
+
}
|
|
461
518
|
/** A document of a custom source to push. */
|
|
462
519
|
export interface CustomDocumentInput {
|
|
463
520
|
/** Your id for the document; its `key` is derived from it. */
|
|
@@ -503,11 +560,12 @@ export interface CustomDocument {
|
|
|
503
560
|
text?: string;
|
|
504
561
|
metadata?: Metadata;
|
|
505
562
|
}
|
|
506
|
-
/** A run: one pass of work on a source (a snapshot, an import, a delete, a user's purge). */
|
|
563
|
+
/** 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). */
|
|
507
564
|
export interface Run {
|
|
508
565
|
id: string;
|
|
509
566
|
sourceId: string | null;
|
|
510
|
-
|
|
567
|
+
/** `sync`: a Google Cloud Storage source's listing; `parse`: a file's parse. */
|
|
568
|
+
kind: "snapshot" | "import" | "delete" | "purge" | "sync" | "parse";
|
|
511
569
|
state: "queued" | "running" | "succeeded" | "failed" | "canceled";
|
|
512
570
|
phase: string | null;
|
|
513
571
|
attempt: number;
|
|
@@ -688,8 +746,8 @@ export declare class Conare {
|
|
|
688
746
|
/**
|
|
689
747
|
* The organizations this key acts for, its own first. A multi-organization key lists each other one
|
|
690
748
|
* it still acts for; pass an `id` as the `organization` option of a client to act for it. A
|
|
691
|
-
* customer key lists every organization of your customer (every page)
|
|
692
|
-
*
|
|
749
|
+
* customer key lists every organization of your customer (every page). With `externalId`, any key
|
|
750
|
+
* lists only the organizations it acts for that were made with it: none when there is none.
|
|
693
751
|
*/
|
|
694
752
|
organizations(options?: RequestOptions & {
|
|
695
753
|
externalId?: string;
|
|
@@ -795,6 +853,12 @@ export declare class Namespace {
|
|
|
795
853
|
}): Promise<{
|
|
796
854
|
embeddingModel: string;
|
|
797
855
|
}>;
|
|
856
|
+
/**
|
|
857
|
+
* Say what the namespace holds, in one line of your own words (up to 300 characters; `""` removes
|
|
858
|
+
* it). `namespaces()` returns it, and the MCP server's `list_namespaces` shows it to an agent, which
|
|
859
|
+
* reads it to decide where to look and where to save. The namespace must exist.
|
|
860
|
+
*/
|
|
861
|
+
describe(description: string, options?: RequestOptions): Promise<void>;
|
|
798
862
|
/**
|
|
799
863
|
* Add or replace documents. Accepts one or many; sends them in batches of 100. Returns the ids.
|
|
800
864
|
* A document without an id gets one here, and each batch carries an `Idempotency-Key` reused on
|
|
@@ -845,7 +909,7 @@ export declare class Namespace {
|
|
|
845
909
|
* `userPrefix` (ending in `:`) to a group's; both combine with `filter`. An empty `user` or
|
|
846
910
|
* `userPrefix` is a 400, never "every user". `excludeIds` keeps those documents out.
|
|
847
911
|
*/
|
|
848
|
-
query(query: string, options?: QueryOptions): Promise<
|
|
912
|
+
query(query: string, options?: QueryOptions): Promise<QueryResults>;
|
|
849
913
|
/**
|
|
850
914
|
* The documents whose text matches a regular expression, or a near spelling (`{ query, max_distance }`),
|
|
851
915
|
* with the lines that match, in id order. A match lies inside one passage. Pass `nextCursor` as `cursor`
|
|
@@ -927,25 +991,35 @@ export declare class Sources {
|
|
|
927
991
|
source: Source;
|
|
928
992
|
connectUrl: string | null;
|
|
929
993
|
}>;
|
|
930
|
-
/** Set how often a
|
|
994
|
+
/** Set how often a connected app syncs: seconds from 300 (5 minutes) to 2592000 (30 days), or null for automatic. */
|
|
931
995
|
update(id: string, params: {
|
|
932
996
|
syncIntervalSeconds: number | null;
|
|
933
997
|
}, options?: RequestOptions): Promise<Source>;
|
|
934
|
-
/**
|
|
935
|
-
|
|
998
|
+
/**
|
|
999
|
+
* Every source: the connected apps, then the custom, files and Google Cloud Storage sources, which carry
|
|
1000
|
+
* their `kind` (`custom`, `files`, `gcs`); a connected app has none.
|
|
1001
|
+
*/
|
|
1002
|
+
list(options?: RequestOptions): Promise<Array<Source | CustomSource | FilesSource | GCSSource>>;
|
|
936
1003
|
/** One source by id. */
|
|
937
|
-
get(id: string, options?: RequestOptions): Promise<Source | CustomSource>;
|
|
1004
|
+
get(id: string, options?: RequestOptions): Promise<Source | CustomSource | FilesSource | GCSSource>;
|
|
938
1005
|
/**
|
|
939
1006
|
* Start a sync now. `full: true` re-reads everything the app holds instead of what changed: documents
|
|
940
1007
|
* that changed are rewritten and ones Conare no longer keeps are deleted. It is for Gmail and the apps
|
|
941
1008
|
* Conare reads itself (other apps answer 400), and Gmail's rows are billed again (`cost.usdPerMillionRows`).
|
|
1009
|
+
*
|
|
1010
|
+
* A connected app answers the `Source`, due to sync now. A Google Cloud Storage source answers the sync
|
|
1011
|
+
* `Run` it queued (409 `run_active` while one is queued or running). A custom or files source has nothing
|
|
1012
|
+
* to sync: 409 `push_source`. A `Run` has `state` and a `Source` has `status`: `"state" in result` tells
|
|
1013
|
+
* them apart.
|
|
942
1014
|
*/
|
|
943
1015
|
sync(id: string, options?: RequestOptions & {
|
|
944
1016
|
full?: boolean;
|
|
945
|
-
}): Promise<Source>;
|
|
1017
|
+
}): Promise<Source | Run>;
|
|
946
1018
|
/**
|
|
947
|
-
* Disconnect a source. Pass `deleteDocuments: true` to also delete what it synced
|
|
948
|
-
*
|
|
1019
|
+
* Disconnect a source. Pass `deleteDocuments: true` to also delete what it synced; without it a
|
|
1020
|
+
* connected app's and a custom source's documents stay. A Google Cloud Storage source's and a files
|
|
1021
|
+
* source's documents always go with it. A custom source's delete is a run, which `runs.get` follows
|
|
1022
|
+
* until the source is `deleted`.
|
|
949
1023
|
*/
|
|
950
1024
|
delete(id: string, options?: RequestOptions & {
|
|
951
1025
|
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.29.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,6 +62,8 @@ 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
|
}
|
|
66
69
|
/** The float vectors int8 embeddings stand for: values × scale. */
|
|
@@ -201,13 +204,14 @@ export class Conare {
|
|
|
201
204
|
createdAt: n.created_at ?? null,
|
|
202
205
|
updatedAt: n.updated_at ?? null,
|
|
203
206
|
lastQueryAt: n.last_query_at ?? null,
|
|
207
|
+
description: n.description ?? null,
|
|
204
208
|
}));
|
|
205
209
|
}
|
|
206
210
|
/**
|
|
207
211
|
* The organizations this key acts for, its own first. A multi-organization key lists each other one
|
|
208
212
|
* 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
|
-
*
|
|
213
|
+
* customer key lists every organization of your customer (every page). With `externalId`, any key
|
|
214
|
+
* lists only the organizations it acts for that were made with it: none when there is none.
|
|
211
215
|
*/
|
|
212
216
|
async organizations(options = {}) {
|
|
213
217
|
const out = [];
|
|
@@ -462,6 +466,14 @@ export class Namespace {
|
|
|
462
466
|
const body = await this.client.request("POST", "/namespaces", { name: this.name, embedding_model: options.embeddingModel, regex_index: options.regexIndex }, options);
|
|
463
467
|
return { embeddingModel: body.embedding_model };
|
|
464
468
|
}
|
|
469
|
+
/**
|
|
470
|
+
* Say what the namespace holds, in one line of your own words (up to 300 characters; `""` removes
|
|
471
|
+
* it). `namespaces()` returns it, and the MCP server's `list_namespaces` shows it to an agent, which
|
|
472
|
+
* reads it to decide where to look and where to save. The namespace must exist.
|
|
473
|
+
*/
|
|
474
|
+
async describe(description, options) {
|
|
475
|
+
await this.client.request("PATCH", this.path(), { description }, options);
|
|
476
|
+
}
|
|
465
477
|
/**
|
|
466
478
|
* Add or replace documents. Accepts one or many; sends them in batches of 100. Returns the ids.
|
|
467
479
|
* A document without an id gets one here, and each batch carries an `Idempotency-Key` reused on
|
|
@@ -560,7 +572,7 @@ export class Namespace {
|
|
|
560
572
|
*/
|
|
561
573
|
async query(query, options = {}) {
|
|
562
574
|
const body = await this.client.request("POST", this.path("/query"), queryBody(query, options), options);
|
|
563
|
-
return body.results;
|
|
575
|
+
return Object.assign(body.results, { degraded: body.degraded ?? [] });
|
|
564
576
|
}
|
|
565
577
|
/**
|
|
566
578
|
* The documents whose text matches a regular expression, or a near spelling (`{ query, max_distance }`),
|
|
@@ -592,12 +604,12 @@ export class Namespace {
|
|
|
592
604
|
: await this.client.request("POST", this.path("/query"), { ...queryBody(query, options), max_results: options.maxResults }, options);
|
|
593
605
|
if (!cursor) {
|
|
594
606
|
cursor = page.next_cursor ?? null;
|
|
595
|
-
yield { results: page.results, nextCursor: cursor };
|
|
607
|
+
yield { results: page.results, nextCursor: cursor, degraded: page.degraded ?? [] };
|
|
596
608
|
}
|
|
597
609
|
while (cursor) {
|
|
598
610
|
page = await this.client.request("POST", this.path("/query"), { cursor, top_k: options.topK }, options);
|
|
599
611
|
cursor = page.next_cursor ?? null;
|
|
600
|
-
yield { results: page.results, nextCursor: cursor };
|
|
612
|
+
yield { results: page.results, nextCursor: cursor, degraded: page.degraded ?? [] };
|
|
601
613
|
}
|
|
602
614
|
}
|
|
603
615
|
/** One document by id, or null if it does not exist. */
|
|
@@ -701,11 +713,14 @@ export class Sources {
|
|
|
701
713
|
}, options);
|
|
702
714
|
return { source: toSource(body.source), connectUrl: body.connect_url ?? null };
|
|
703
715
|
}
|
|
704
|
-
/** Set how often a
|
|
716
|
+
/** Set how often a connected app syncs: seconds from 300 (5 minutes) to 2592000 (30 days), or null for automatic. */
|
|
705
717
|
async update(id, params, options) {
|
|
706
718
|
return toSource(await this.client.request("PATCH", `/sources/${segment(id)}`, { sync_interval_s: params.syncIntervalSeconds }, options));
|
|
707
719
|
}
|
|
708
|
-
/**
|
|
720
|
+
/**
|
|
721
|
+
* Every source: the connected apps, then the custom, files and Google Cloud Storage sources, which carry
|
|
722
|
+
* their `kind` (`custom`, `files`, `gcs`); a connected app has none.
|
|
723
|
+
*/
|
|
709
724
|
async list(options) {
|
|
710
725
|
const body = await this.client.request("GET", "/sources", undefined, options);
|
|
711
726
|
return body.sources.map(toAnySource);
|
|
@@ -718,14 +733,22 @@ export class Sources {
|
|
|
718
733
|
* Start a sync now. `full: true` re-reads everything the app holds instead of what changed: documents
|
|
719
734
|
* that changed are rewritten and ones Conare no longer keeps are deleted. It is for Gmail and the apps
|
|
720
735
|
* Conare reads itself (other apps answer 400), and Gmail's rows are billed again (`cost.usdPerMillionRows`).
|
|
736
|
+
*
|
|
737
|
+
* A connected app answers the `Source`, due to sync now. A Google Cloud Storage source answers the sync
|
|
738
|
+
* `Run` it queued (409 `run_active` while one is queued or running). A custom or files source has nothing
|
|
739
|
+
* to sync: 409 `push_source`. A `Run` has `state` and a `Source` has `status`: `"state" in result` tells
|
|
740
|
+
* them apart.
|
|
721
741
|
*/
|
|
722
742
|
async sync(id, options = {}) {
|
|
723
743
|
const { full, ...request } = options;
|
|
724
|
-
|
|
744
|
+
const body = await this.client.request("POST", `/sources/${segment(id)}/sync`, full ? { full: true } : undefined, request);
|
|
745
|
+
return "run" in body ? toRun(body.run) : toSource(body);
|
|
725
746
|
}
|
|
726
747
|
/**
|
|
727
|
-
* Disconnect a source. Pass `deleteDocuments: true` to also delete what it synced
|
|
728
|
-
*
|
|
748
|
+
* Disconnect a source. Pass `deleteDocuments: true` to also delete what it synced; without it a
|
|
749
|
+
* connected app's and a custom source's documents stay. A Google Cloud Storage source's and a files
|
|
750
|
+
* source's documents always go with it. A custom source's delete is a run, which `runs.get` follows
|
|
751
|
+
* until the source is `deleted`.
|
|
729
752
|
*/
|
|
730
753
|
async delete(id, options = {}) {
|
|
731
754
|
const qs = options.deleteDocuments ? "?delete_documents=true" : "";
|
|
@@ -968,23 +991,55 @@ export class Events {
|
|
|
968
991
|
};
|
|
969
992
|
}
|
|
970
993
|
}
|
|
994
|
+
/** A source by its `kind`: a connected app has none; a custom, files or Google Cloud Storage source names it. */
|
|
971
995
|
function toAnySource(s) {
|
|
972
|
-
|
|
996
|
+
if (!("kind" in s))
|
|
997
|
+
return toSource(s);
|
|
998
|
+
if (s.kind === "gcs") {
|
|
999
|
+
const c = s.config;
|
|
1000
|
+
return {
|
|
1001
|
+
...toCustomSource(s),
|
|
1002
|
+
kind: "gcs",
|
|
1003
|
+
type: "gcs",
|
|
1004
|
+
app: null,
|
|
1005
|
+
user: null,
|
|
1006
|
+
config: {
|
|
1007
|
+
bucket: c?.bucket ?? "",
|
|
1008
|
+
prefixes: c?.prefixes ?? [],
|
|
1009
|
+
...(c?.glob ? { glob: c.glob } : {}),
|
|
1010
|
+
serviceAccount: c?.service_account ?? "",
|
|
1011
|
+
syncIntervalSeconds: c?.sync_interval_s ?? 0,
|
|
1012
|
+
},
|
|
1013
|
+
failures: s.failures ?? 0,
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
return s.kind === "files" ? { ...toCustomSource(s), kind: "files", type: "files", app: null } : toCustomSource(s);
|
|
973
1017
|
}
|
|
1018
|
+
/** A custom source; with a files or Google Cloud Storage source's wire, the fields they share. */
|
|
974
1019
|
function toCustomSource(s) {
|
|
1020
|
+
const date = (t) => (t ? new Date(t) : null);
|
|
975
1021
|
return {
|
|
976
1022
|
id: s.id,
|
|
977
1023
|
kind: "custom",
|
|
978
1024
|
type: "custom",
|
|
1025
|
+
app: s.type === "custom" ? null : s.type,
|
|
979
1026
|
namespace: s.namespace,
|
|
980
1027
|
user: s.user,
|
|
981
1028
|
name: s.name,
|
|
982
1029
|
status: s.status,
|
|
983
1030
|
health: s.health,
|
|
984
1031
|
display: s.display,
|
|
985
|
-
sync: {
|
|
1032
|
+
sync: {
|
|
1033
|
+
state: s.sync.state,
|
|
1034
|
+
runId: s.sync.run_id,
|
|
1035
|
+
phase: s.sync.phase,
|
|
1036
|
+
lastSuccessAt: date(s.sync.last_success_at),
|
|
1037
|
+
lastFailureAt: date(s.sync.last_failure_at),
|
|
1038
|
+
nextRunAt: date(s.sync.next_run_at),
|
|
1039
|
+
lastError: s.sync.last_error ?? null,
|
|
1040
|
+
},
|
|
986
1041
|
documents: s.documents,
|
|
987
|
-
documentsVerifiedAt:
|
|
1042
|
+
documentsVerifiedAt: date(s.documents_verified_at),
|
|
988
1043
|
createdAt: new Date(s.created_at),
|
|
989
1044
|
updatedAt: new Date(s.updated_at),
|
|
990
1045
|
};
|