conare 0.29.0 → 0.33.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 +178 -8
- package/dist/index.d.ts +536 -26
- package/dist/index.js +347 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,8 +62,9 @@ const acme = await platform.createOrganization({ name: "Acme", externalId: "acme
|
|
|
62
62
|
const { secret } = await new Conare({ apiKey: CUSTOMER_KEY, organization: acme.id }).createKey({ name: "acme" })
|
|
63
63
|
// Acme's traffic runs on `secret`, which reaches Acme's organization alone.
|
|
64
64
|
await platform.organizations({ externalId: "acme" }) // every organization of your customer, or the one with this id
|
|
65
|
-
await platform.spendByOrganization() // this month's bill by organization: { total, rows: [{ id, name, externalId, charges }] }
|
|
65
|
+
await platform.spendByOrganization() // this month's bill by organization: { total, rows: [{ id, name, externalId, charges, spendCapMicros }] }
|
|
66
66
|
await platform.renameOrganization(acme.id, "Acme Capital")
|
|
67
|
+
await platform.setOrganizationSpendCap(acme.id, 500) // its own monthly cap in dollars (null removes it): past it, Acme's billed calls get 402 spend_cap_reached
|
|
67
68
|
await platform.deleteOrganization(acme.id) // 409 until its namespaces and sources are deleted
|
|
68
69
|
```
|
|
69
70
|
|
|
@@ -82,7 +83,7 @@ await docs.add({ id, text, user: "tenant-7:u_42", seq: 1759698843000 }); // a us
|
|
|
82
83
|
// than stored is "stale" and writes nothing
|
|
83
84
|
await docs.query("refunds", { userPrefix: "tenant-7:" }); // one user's documents (user) or a group's (userPrefix)
|
|
84
85
|
await docs.get("refunds"); // { id, text, metadata, updatedAt, version, user?, seq? } or null
|
|
85
|
-
for await (const doc of docs.list()) {} // every document, page by page ({ limit } per page: 1-100, default 50)
|
|
86
|
+
for await (const doc of docs.list()) {} // every document, page by page ({ limit } per page: 1-100, default 50; { order: "newest" } newest first)
|
|
86
87
|
await docs.delete("refunds"); // 404 document_not_found if it does not exist
|
|
87
88
|
await docs.deleteMany(["a", "b"]); // up to 1000 ids in one call; missing ids are skipped. Returns the count
|
|
88
89
|
await docs.deleteWhere({ team: "support" }); // every document matching the filter, whole documents. Returns the count
|
|
@@ -143,6 +144,57 @@ compare numbers, string bounds compare strings by their UTF-8 bytes, so ISO date
|
|
|
143
144
|
|
|
144
145
|
`$ne` and `$nin` work in queries; a delete by filter with one answers 400 `invalid_filter`.
|
|
145
146
|
|
|
147
|
+
### Records
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
const { record, sources, results, sourcePassages } = await docs.queryRecord("When do applications close, and is there an interview?", {
|
|
151
|
+
type: "object",
|
|
152
|
+
properties: {
|
|
153
|
+
closes: { type: "string", description: "The date applications close, as YYYY-MM-DD" },
|
|
154
|
+
interview: { type: "string", enum: ["live", "recorded", "none"] },
|
|
155
|
+
essays: { type: "integer", description: "How many essays an applicant writes" },
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
record?.interview; // "live" | "recorded" | "none" | null, typed from the schema
|
|
159
|
+
sources.closes; // { id, url, quote }: the document, its address and the words that state the value
|
|
160
|
+
sourcePassages; // a source's passage that results do not hold (the record reads past topK)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
A search answered as a record: every field of the schema, its value or null when no passage the search read
|
|
164
|
+
states it, never guessed. A field is a string (with or without an `enum`), a number, an integer, a boolean or a
|
|
165
|
+
list of strings; 1-32 fields. Say in a field's `description` what it holds and in what form. `record` is null when
|
|
166
|
+
the answer model was unavailable; `results` are the search's, and every `query` option applies.
|
|
167
|
+
|
|
168
|
+
### Changes
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
let cursor = await loadCursor(); // undefined the first time: every document from the start
|
|
172
|
+
for (;;) {
|
|
173
|
+
const page = await docs.changes({ cursor, limit: 1000 });
|
|
174
|
+
for (const c of page.changes) {} // { id, change: "created" | "changed" | "deleted", at, url?, metadata?, diff? }
|
|
175
|
+
cursor = page.nextCursor;
|
|
176
|
+
await saveCursor(cursor);
|
|
177
|
+
if (!page.hasMore) break;
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
What changed in a namespace, oldest first: each page and file its website, Cloud Storage and file sources read
|
|
182
|
+
(created or changed; one read again unchanged adds nothing) and each of their documents deleted. Documents written
|
|
183
|
+
with `add` or `write` are not listed. Rows are kept 90 days, a live document's latest whatever its age; a cursor
|
|
184
|
+
whose unread rows were dropped throws 410 `cursor_expired`: list again without one.
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
const page = await docs.changes({ source: "src_769140bdee3ce44fc52ddb86", since: lastSyncStart });
|
|
188
|
+
for (const c of page.changes) {
|
|
189
|
+
if (c.diff?.cause === "content") for (const h of c.diff.hunks ?? []) console.log(h.removed, "->", h.added);
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
`source` keeps the rows to one source's documents, `since` and `until` to a time window. A web page's `changed`
|
|
194
|
+
row says how it changed (`diff`): `content` with the lines removed and added (`["Application deadline: 14 January
|
|
195
|
+
2026"]` -> `["Application deadline: 13 January 2027"]`), `reader` when the page reads as it did and only how Conare
|
|
196
|
+
reads web pages changed, `fields` when only its fields did. A file's row has none.
|
|
197
|
+
|
|
146
198
|
|
|
147
199
|
### Grep
|
|
148
200
|
|
|
@@ -161,6 +213,11 @@ order. `docs.create({ regexIndex: true })` before a namespace's first write make
|
|
|
161
213
|
await conare.embed(["some text"], { type: "query" }); // number[][]; type defaults to "document"
|
|
162
214
|
await conare.embed(["some text"], { outputDtype: "int8" }); // { values: Int8Array[], scales }; dequantize() gives floats
|
|
163
215
|
await conare.rerank("refund window", ["a", "b"], { topK: 1 }); // [{ index, score, document }], plus .unscored
|
|
216
|
+
|
|
217
|
+
// Both parts of the model: a vector per text and a vector per token. Blend the two scores with hybridScore().
|
|
218
|
+
const query = await conare.embed("refund window", { type: "query", tokenEmbeddings: true });
|
|
219
|
+
const documents = await conare.embed(["a", "b"], { tokenEmbeddings: true }); // up to 16 texts a call
|
|
220
|
+
hybridScore(query, documents, 0, 1); // the query against documents[1]
|
|
164
221
|
```
|
|
165
222
|
|
|
166
223
|
`outputDtype: "int8"` returns each vector as int8 values plus one scale (vector ≈ values × scale, scale = max|x| / 127):
|
|
@@ -179,12 +236,23 @@ results; its score from another call would not compare.
|
|
|
179
236
|
const out = await conare.parse(bytes, { name: "report.pdf", pages: "1-20", layout: true });
|
|
180
237
|
// { id, state: "done", markdown: "<!-- page 1 -->\n\n# Report...", parts: [{ locator: { page: 1 }, markdown, ocr, confidence, blocks }], withoutText }
|
|
181
238
|
await conare.parse({ url: "https://example.com/deck.pptx" }); // fetched by the API
|
|
239
|
+
await conare.parse({ url: "https://example.com/" }); // a page: { title, sourceUrl, markdown, ... }
|
|
182
240
|
await conare.parse(locked, { name: "minutes.pdf", password: "..." });
|
|
241
|
+
await conare.parse(xlsx, { name: "model.xlsx", sheets: ["Q3"], range: "A1:F40", formulas: true }); // "110 `=B2*1.1`"; .sheets names all
|
|
242
|
+
await conare.parse(deck, { name: "deck.pptx", vision: true }); // charts and pictures described; parts carry .vision
|
|
183
243
|
if (out.state === "parsing") await conare.getParse(out.id); // OCR outlived `wait` (default 60 s): the result, kept 24 h
|
|
184
244
|
```
|
|
185
245
|
|
|
186
246
|
`parse` reads a file with the same parser as `uploadFile` and stores nothing; any key can call it, a models-only key
|
|
187
247
|
too. `uploadFile` takes the same options and answers the same `markdown`, `parts` and `withoutText` beside `ids`.
|
|
248
|
+
A URL is `http` or `https` on a public address; the API reads the one page you name and does not consult robots.txt.
|
|
249
|
+
Its result carries `sourceUrl`, where the fetch landed after redirects, and a page's `title`. A URL that does not
|
|
250
|
+
answer its file throws what its site did (`gone`, `refused`, `sign_in_required`, `slow_down`, `site_error`,
|
|
251
|
+
`unreachable`, `unexpected_status`) with `err.details.status`, the site's HTTP status, and on `slow_down`
|
|
252
|
+
`err.details.retryAfterSeconds`. A page that holds no text until a browser runs its scripts throws 422
|
|
253
|
+
`needs_javascript`; `render: true` asks for it to be read through a browser (not available yet: the error says so).
|
|
254
|
+
`links: true` writes a web page's links as Markdown links, its menus' and footer's too; `mainContent: true` reads
|
|
255
|
+
the page's main content alone.
|
|
188
256
|
A page OCR could not read is in `ocrFailed` (empty when it read them all), apart from a blank page; an upload's
|
|
189
257
|
`ocrLayerOnly` lists the pages that kept their text layer alone because OCR could not read them.
|
|
190
258
|
|
|
@@ -202,11 +270,13 @@ const { source, connectUrl } = await conare.sources.connect({
|
|
|
202
270
|
// Send the app owner to connectUrl. They sign in and come back to redirectUrl.
|
|
203
271
|
|
|
204
272
|
await conare.sources.types(); // [{ type, name, logoUrl }]
|
|
205
|
-
await conare.sources.list(); // [Source]
|
|
273
|
+
await conare.sources.list(); // { data: [Source, ...], nextCursor }: a page, the connected apps first
|
|
274
|
+
for await (const s of conare.sources.all()) {} // every source, page by page
|
|
275
|
+
await conare.sources.summary(); // { sources, failing, syncing, namespaces: [{ namespace, types: [{ type, sources, failing }] }] }
|
|
206
276
|
await conare.sources.get(source.id); // { id, type, name, namespace, status, error, documents, lastSyncedAt, createdAt }
|
|
207
277
|
const synced = await conare.sources.sync(source.id); // sync now: the Source, or a bucket's sync Run
|
|
208
278
|
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);
|
|
279
|
+
const full = await conare.sources.sync(source.id, { full: true }); // re-read everything (Gmail and apps Conare reads itself); only documents that changed are indexed again
|
|
210
280
|
if (!("state" in full)) full.resyncNote; // what the re-read does
|
|
211
281
|
await conare.sources.update(source.id, { syncIntervalSeconds: 3600 }); // every hour; null is automatic
|
|
212
282
|
await conare.sources.delete(source.id, { deleteDocuments: true });
|
|
@@ -217,10 +287,46 @@ picked from what each sync reads, or on one you set from 5 minutes to 30 days. `
|
|
|
217
287
|
what an estimate of a month at any interval needs: the rows the last sync read, whether syncs read
|
|
218
288
|
only changes, and the prices.
|
|
219
289
|
|
|
220
|
-
|
|
290
|
+
Pages of public websites are a source too:
|
|
291
|
+
|
|
292
|
+
```ts
|
|
293
|
+
const site = await conare.sources.create({
|
|
294
|
+
type: "web",
|
|
295
|
+
namespace: "admissions",
|
|
296
|
+
urls: ["https://www.example.edu/admissions/dates", "https://www.example.edu/admissions/guide.pdf"],
|
|
297
|
+
});
|
|
298
|
+
const { data } = await conare.sources.failures(site.id); // [{ externalId, code: "refused", message, attempts }]
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Or give a website's address and Conare finds its pages itself, new ones included, at every sync:
|
|
302
|
+
|
|
303
|
+
```ts
|
|
304
|
+
const rival = await conare.sources.create({ type: "web", namespace: "competitors", site: "https://www.example.com" });
|
|
305
|
+
await conare.sources.update<WebSource>(rival.id, { syncIntervalSeconds: 3600 }); // an hour to a week; null is a day
|
|
306
|
+
await conare.namespace("competitors").query("enterprise plan price", { filter: { page_type: "pricing" } });
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Conare reads each page as the crawler `ConareBot` (robots.txt and a site's Crawl-delay obeyed, a site asked
|
|
310
|
+
only as fast as it answers), keeps it in the namespace with its address as `source_url` and its kind as
|
|
311
|
+
`page_type` (`pricing`, `blog`, `changelog`, `docs`, ...), and reads it again every `syncIntervalSeconds` (a day
|
|
312
|
+
by default), parsing it again only when it changed. Each website is its own source with its own interval.
|
|
313
|
+
|
|
314
|
+
`sources.sync()` answers a connected app's `Source`. A Google Cloud Storage or web source answers the sync
|
|
221
315
|
`Run` it queued (409 `run_active` while one is queued or running), and a custom or files source has
|
|
222
316
|
nothing to sync (409 `push_source`).
|
|
223
317
|
|
|
318
|
+
A deleted Google Cloud Storage, web or files source stops syncing at once but keeps its documents, searchable,
|
|
319
|
+
for an hour: `deletesAt` says when they go, and `sources.restore()` brings it back until then.
|
|
320
|
+
|
|
321
|
+
```ts
|
|
322
|
+
await conare.sources.delete(site.id); // deleting; its documents go in an hour
|
|
323
|
+
await conare.sources.delete(site.id, { graceSeconds: 0 }); // now (0 to 86,400), also in its grace
|
|
324
|
+
await conare.sources.restore(site.id); // active again, with its documents
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
While a source is in its grace, connecting the same bucket or site, or uploading to a namespace whose files source
|
|
328
|
+
it is, throws `source_deleting` with `details.sourceId` and `details.deletesAt`: restore it, or delete it now.
|
|
329
|
+
|
|
224
330
|
### Custom sources
|
|
225
331
|
|
|
226
332
|
A custom source is a set of documents you push from your own system, keyed by your own ids.
|
|
@@ -255,8 +361,8 @@ await conare.events.list({ cursor: "0", types: ["run.*"] }); // { data: [{ seq,
|
|
|
255
361
|
```
|
|
256
362
|
|
|
257
363
|
`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"`)
|
|
259
|
-
(`kind: "gcs"`); a connected app has no `kind`. A custom source that holds an app keeps
|
|
364
|
+
files source of each namespace you upload to (`kind: "files"`), Google Cloud Storage buckets
|
|
365
|
+
(`kind: "gcs"`) and web sources (`kind: "web"`); a connected app has no `kind`. A custom source that holds an app keeps
|
|
260
366
|
`type: "custom"` and names the app in `app` (`"gmail"`; null otherwise). These carry `health` (`ok`, `degraded`, `failing`),
|
|
261
367
|
`display.state` (`needs_action` with `display.action` when you must act, such as `grant_access` on a
|
|
262
368
|
bucket) and `sync.lastError`. These calls send an `Idempotency-Key` when they create or delete
|
|
@@ -264,7 +370,8 @@ something, so their retries are safe.
|
|
|
264
370
|
|
|
265
371
|
### Errors
|
|
266
372
|
|
|
267
|
-
Every failure is a `ConareError` with `status`, `code`, `message` and `
|
|
373
|
+
Every failure is a `ConareError` with `status`, `code`, `message`, `requestId` and `details` (null unless
|
|
374
|
+
the error carries facts beside its message, such as a fetched URL's `status`)
|
|
268
375
|
(`status` is 0 when no response arrived: `timeout`, `connection_error`). 429, 5xx and network
|
|
269
376
|
errors are retried twice with backoff, honouring `Retry-After`. Every write carries an
|
|
270
377
|
`Idempotency-Key`, the same on each of its retries: the API answers a retry with the first answer
|
|
@@ -355,6 +462,69 @@ lowercased, with any character other than letters, digits, `_` and `-` as `-` (`
|
|
|
355
462
|
writes `next-js-github`). A namespace that already holds another owner's repository of the same
|
|
356
463
|
name is left alone, and that repository's sync stops with an error.
|
|
357
464
|
|
|
465
|
+
## Changes in 0.33.0
|
|
466
|
+
|
|
467
|
+
0.31.0 and 0.32.0 were never published: coming from 0.30.0, read their notes below too. What breaks code
|
|
468
|
+
written for 0.30.0:
|
|
469
|
+
|
|
470
|
+
- `sources.list()` answers one page, `{ data, nextCursor }`, not an array of every source: the connected apps on
|
|
471
|
+
the first page, then up to `limit` (default 100, at most 200) custom, files, Google Cloud Storage and web
|
|
472
|
+
sources, newest first. Pass `nextCursor` as `cursor` for the next page, or iterate `sources.all()` for every
|
|
473
|
+
source. Both take `namespace`, `user` and `type`. Code that read the array reads `.data`, or iterates `all()`
|
|
474
|
+
to keep every source.
|
|
475
|
+
- `sources.list(options)` became `sources.list(params, options)`: request options (`signal`, `timeout`,
|
|
476
|
+
`idempotencyKey`) passed first, as 0.30.0 took them, are now read as filters and do nothing. Pass them second:
|
|
477
|
+
`sources.list({}, { timeout: 5000 })`.
|
|
478
|
+
- `sources.delete(id)` of a Google Cloud Storage, web or files source leaves an hour to take it back: the source
|
|
479
|
+
stops syncing at once and shows `deletesAt`, its documents stay searchable until then, and `sources.restore(id)`
|
|
480
|
+
brings it back. `sources.delete(id, { graceSeconds })` sets the wait (0 to 86,400); `0` deletes at once, as before,
|
|
481
|
+
and also deletes now a source already in its grace.
|
|
482
|
+
- Types that gained required fields, which code building such objects itself (a test double) must now fill:
|
|
483
|
+
`ApiKey.readOnly` and `ApiKey.rateLimitPercent`, and `OrganizationSpend.capped` and each of its
|
|
484
|
+
rows' `spendCapMicros`, and `WebSource.config.pages`.
|
|
485
|
+
- The list no longer carries a site's page addresses: read the source. A web source from `sources.list()` has how
|
|
486
|
+
many pages it has (`config.pages`) and no `config.urls`; `sources.get(id)` answers them (one site can hold 5,000,
|
|
487
|
+
and a page of 124 sites weighed 214 MB). 0.30.0's `sources.list()` reads the missing key as `config.urls: []`: it
|
|
488
|
+
does not throw, but its sources look empty of pages, so read each with `sources.get(id)`.
|
|
489
|
+
|
|
490
|
+
New, nothing to change:
|
|
491
|
+
|
|
492
|
+
- `sources.list()` answers `total` on the first page, how many sources every page holds: `list({ limit: 1 })` reads
|
|
493
|
+
how many there are. `sources.list({ health: "failing" })` (and `all()`) keeps the sources that need you.
|
|
494
|
+
- `sources.summary()` counts the sources by namespace and type, and how many of them fail or sync now, in one read
|
|
495
|
+
however many sources there are (`{ namespace }` for one): which apps feed a namespace, without listing them.
|
|
496
|
+
|
|
497
|
+
- A `source_deleting` error (connecting a bucket or site whose source is in its grace, uploading to a namespace
|
|
498
|
+
whose files source is) carries `details.sourceId` and, while it can still be restored, `details.deletesAt`:
|
|
499
|
+
`sources.restore(details.sourceId)`, or `sources.delete(details.sourceId, { graceSeconds: 0 })` to delete it now.
|
|
500
|
+
- `sources.restore()` takes what `sources.delete()` takes: in the console, an organization admin.
|
|
501
|
+
- `parse` and `uploadFile` take a workbook's `sheets` (names), `range` (`"A1:F40"`) and `formulas: true` (an
|
|
502
|
+
.xlsx's formulas beside their values); `parse`'s result names a workbook's `sheets`, all of them.
|
|
503
|
+
- `parse` and `uploadFile` take `vision: true`: each chart, diagram and picture is described in one line
|
|
504
|
+
`> **Figure description:** ...`, every part carries `vision` (and with `layout`, a figure block its `description`),
|
|
505
|
+
and a picture with no text but a description is a part, not 422 `no_text`. A description is written by a model: it
|
|
506
|
+
describes what the chart, diagram or picture shows and is not text from the page; it can be wrong, and two reads of
|
|
507
|
+
the same file may word it differently; numbers a chart prints are in the page's text as before. A deployment that
|
|
508
|
+
does not offer it answers 400 `invalid_request`.
|
|
509
|
+
|
|
510
|
+
## Changes in 0.32.0
|
|
511
|
+
|
|
512
|
+
- `changes({ source, since, until })` keeps a page of changes to one source and a time window, and a web page's
|
|
513
|
+
`changed` row says how it changed (`diff`: the lines removed and added, or that only the reader or its fields
|
|
514
|
+
changed).
|
|
515
|
+
|
|
516
|
+
## Changes in 0.31.0
|
|
517
|
+
|
|
518
|
+
- `queryRecord(query, schema)` answers a search as a record of the fields the schema names, each value typed from
|
|
519
|
+
the schema and with the document, address and words it is from (`sources`).
|
|
520
|
+
- `changes({ cursor, limit })` reads a page of a namespace's changes: the documents its sources created, changed
|
|
521
|
+
and deleted, from a cursor.
|
|
522
|
+
|
|
523
|
+
## Changes in 0.30.0
|
|
524
|
+
|
|
525
|
+
- `embed(..., { tokenEmbeddings: true })` returns `HybridEmbeddings`: each text's vector and a vector
|
|
526
|
+
per token, with `denseWeight`; `hybridScore(query, documents, q, d)` blends the two scores.
|
|
527
|
+
|
|
358
528
|
## Changes in 0.29.0
|
|
359
529
|
|
|
360
530
|
- `sources.sync()` returns `Source | Run`: a Google Cloud Storage source's sync answers its `Run`
|