conare 0.28.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 +40 -5
- package/dist/index.d.ts +76 -12
- package/dist/index.js +66 -11
- 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
|
|
|
@@ -174,6 +185,8 @@ if (out.state === "parsing") await conare.getParse(out.id); // OCR outlived
|
|
|
174
185
|
|
|
175
186
|
`parse` reads a file with the same parser as `uploadFile` and stores nothing; any key can call it, a models-only key
|
|
176
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.
|
|
177
190
|
|
|
178
191
|
### Sources
|
|
179
192
|
|
|
@@ -191,8 +204,10 @@ const { source, connectUrl } = await conare.sources.connect({
|
|
|
191
204
|
await conare.sources.types(); // [{ type, name, logoUrl }]
|
|
192
205
|
await conare.sources.list(); // [Source]
|
|
193
206
|
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.
|
|
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
|
|
196
211
|
await conare.sources.update(source.id, { syncIntervalSeconds: 3600 }); // every hour; null is automatic
|
|
197
212
|
await conare.sources.delete(source.id, { deleteDocuments: true });
|
|
198
213
|
```
|
|
@@ -202,6 +217,10 @@ picked from what each sync reads, or on one you set from 5 minutes to 30 days. `
|
|
|
202
217
|
what an estimate of a month at any interval needs: the rows the last sync read, whether syncs read
|
|
203
218
|
only changes, and the prices.
|
|
204
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
|
+
|
|
205
224
|
### Custom sources
|
|
206
225
|
|
|
207
226
|
A custom source is a set of documents you push from your own system, keyed by your own ids.
|
|
@@ -235,8 +254,13 @@ await conare.users.deletePrefix("tenant-7:");
|
|
|
235
254
|
await conare.events.list({ cursor: "0", types: ["run.*"] }); // { data: [{ seq, type, runId, data }], nextCursor }
|
|
236
255
|
```
|
|
237
256
|
|
|
238
|
-
`sources.list()` and `sources.get()` answer custom sources too, with `kind: "custom"
|
|
239
|
-
|
|
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.
|
|
240
264
|
|
|
241
265
|
### Errors
|
|
242
266
|
|
|
@@ -331,6 +355,17 @@ lowercased, with any character other than letters, digits, `_` and `-` as `-` (`
|
|
|
331
355
|
writes `next-js-github`). A namespace that already holds another owner's repository of the same
|
|
332
356
|
name is left alone, and that repository's sync stops with an error.
|
|
333
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
|
+
|
|
334
369
|
## Development
|
|
335
370
|
|
|
336
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
|
|
@@ -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;
|
|
@@ -447,6 +458,8 @@ export interface CustomSource {
|
|
|
447
458
|
id: string;
|
|
448
459
|
kind: "custom";
|
|
449
460
|
type: "custom";
|
|
461
|
+
/** The app a custom source holds (`gmail`), or null. */
|
|
462
|
+
app: string | null;
|
|
450
463
|
namespace: string;
|
|
451
464
|
user: string | null;
|
|
452
465
|
name: string | null;
|
|
@@ -462,12 +475,46 @@ export interface CustomSource {
|
|
|
462
475
|
state: "idle" | "queued" | "running";
|
|
463
476
|
runId: string | null;
|
|
464
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;
|
|
465
487
|
};
|
|
466
488
|
documents: number | null;
|
|
467
489
|
documentsVerifiedAt: Date | null;
|
|
468
490
|
createdAt: Date;
|
|
469
491
|
updatedAt: Date;
|
|
470
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
|
+
}
|
|
471
518
|
/** A document of a custom source to push. */
|
|
472
519
|
export interface CustomDocumentInput {
|
|
473
520
|
/** Your id for the document; its `key` is derived from it. */
|
|
@@ -513,11 +560,12 @@ export interface CustomDocument {
|
|
|
513
560
|
text?: string;
|
|
514
561
|
metadata?: Metadata;
|
|
515
562
|
}
|
|
516
|
-
/** 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). */
|
|
517
564
|
export interface Run {
|
|
518
565
|
id: string;
|
|
519
566
|
sourceId: string | null;
|
|
520
|
-
|
|
567
|
+
/** `sync`: a Google Cloud Storage source's listing; `parse`: a file's parse. */
|
|
568
|
+
kind: "snapshot" | "import" | "delete" | "purge" | "sync" | "parse";
|
|
521
569
|
state: "queued" | "running" | "succeeded" | "failed" | "canceled";
|
|
522
570
|
phase: string | null;
|
|
523
571
|
attempt: number;
|
|
@@ -698,8 +746,8 @@ export declare class Conare {
|
|
|
698
746
|
/**
|
|
699
747
|
* The organizations this key acts for, its own first. A multi-organization key lists each other one
|
|
700
748
|
* 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
|
-
*
|
|
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.
|
|
703
751
|
*/
|
|
704
752
|
organizations(options?: RequestOptions & {
|
|
705
753
|
externalId?: string;
|
|
@@ -805,6 +853,12 @@ export declare class Namespace {
|
|
|
805
853
|
}): Promise<{
|
|
806
854
|
embeddingModel: string;
|
|
807
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>;
|
|
808
862
|
/**
|
|
809
863
|
* Add or replace documents. Accepts one or many; sends them in batches of 100. Returns the ids.
|
|
810
864
|
* A document without an id gets one here, and each batch carries an `Idempotency-Key` reused on
|
|
@@ -937,25 +991,35 @@ export declare class Sources {
|
|
|
937
991
|
source: Source;
|
|
938
992
|
connectUrl: string | null;
|
|
939
993
|
}>;
|
|
940
|
-
/** 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. */
|
|
941
995
|
update(id: string, params: {
|
|
942
996
|
syncIntervalSeconds: number | null;
|
|
943
997
|
}, options?: RequestOptions): Promise<Source>;
|
|
944
|
-
/**
|
|
945
|
-
|
|
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>>;
|
|
946
1003
|
/** One source by id. */
|
|
947
|
-
get(id: string, options?: RequestOptions): Promise<Source | CustomSource>;
|
|
1004
|
+
get(id: string, options?: RequestOptions): Promise<Source | CustomSource | FilesSource | GCSSource>;
|
|
948
1005
|
/**
|
|
949
1006
|
* Start a sync now. `full: true` re-reads everything the app holds instead of what changed: documents
|
|
950
1007
|
* that changed are rewritten and ones Conare no longer keeps are deleted. It is for Gmail and the apps
|
|
951
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.
|
|
952
1014
|
*/
|
|
953
1015
|
sync(id: string, options?: RequestOptions & {
|
|
954
1016
|
full?: boolean;
|
|
955
|
-
}): Promise<Source>;
|
|
1017
|
+
}): Promise<Source | Run>;
|
|
956
1018
|
/**
|
|
957
|
-
* Disconnect a source. Pass `deleteDocuments: true` to also delete what it synced
|
|
958
|
-
*
|
|
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`.
|
|
959
1023
|
*/
|
|
960
1024
|
delete(id: string, options?: RequestOptions & {
|
|
961
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
|
|
@@ -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
|
};
|