conare 0.30.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 +140 -4
- package/dist/index.d.ts +412 -22
- package/dist/index.js +262 -37
- 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
|
|
|
@@ -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
|
|
|
@@ -184,12 +236,23 @@ results; its score from another call would not compare.
|
|
|
184
236
|
const out = await conare.parse(bytes, { name: "report.pdf", pages: "1-20", layout: true });
|
|
185
237
|
// { id, state: "done", markdown: "<!-- page 1 -->\n\n# Report...", parts: [{ locator: { page: 1 }, markdown, ocr, confidence, blocks }], withoutText }
|
|
186
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, ... }
|
|
187
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
|
|
188
243
|
if (out.state === "parsing") await conare.getParse(out.id); // OCR outlived `wait` (default 60 s): the result, kept 24 h
|
|
189
244
|
```
|
|
190
245
|
|
|
191
246
|
`parse` reads a file with the same parser as `uploadFile` and stores nothing; any key can call it, a models-only key
|
|
192
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.
|
|
193
256
|
A page OCR could not read is in `ocrFailed` (empty when it read them all), apart from a blank page; an upload's
|
|
194
257
|
`ocrLayerOnly` lists the pages that kept their text layer alone because OCR could not read them.
|
|
195
258
|
|
|
@@ -207,11 +270,13 @@ const { source, connectUrl } = await conare.sources.connect({
|
|
|
207
270
|
// Send the app owner to connectUrl. They sign in and come back to redirectUrl.
|
|
208
271
|
|
|
209
272
|
await conare.sources.types(); // [{ type, name, logoUrl }]
|
|
210
|
-
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 }] }] }
|
|
211
276
|
await conare.sources.get(source.id); // { id, type, name, namespace, status, error, documents, lastSyncedAt, createdAt }
|
|
212
277
|
const synced = await conare.sources.sync(source.id); // sync now: the Source, or a bucket's sync Run
|
|
213
278
|
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);
|
|
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
|
|
215
280
|
if (!("state" in full)) full.resyncNote; // what the re-read does
|
|
216
281
|
await conare.sources.update(source.id, { syncIntervalSeconds: 3600 }); // every hour; null is automatic
|
|
217
282
|
await conare.sources.delete(source.id, { deleteDocuments: true });
|
|
@@ -250,6 +315,18 @@ by default), parsing it again only when it changed. Each website is its own sour
|
|
|
250
315
|
`Run` it queued (409 `run_active` while one is queued or running), and a custom or files source has
|
|
251
316
|
nothing to sync (409 `push_source`).
|
|
252
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
|
+
|
|
253
330
|
### Custom sources
|
|
254
331
|
|
|
255
332
|
A custom source is a set of documents you push from your own system, keyed by your own ids.
|
|
@@ -293,7 +370,8 @@ something, so their retries are safe.
|
|
|
293
370
|
|
|
294
371
|
### Errors
|
|
295
372
|
|
|
296
|
-
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`)
|
|
297
375
|
(`status` is 0 when no response arrived: `timeout`, `connection_error`). 429, 5xx and network
|
|
298
376
|
errors are retried twice with backoff, honouring `Retry-After`. Every write carries an
|
|
299
377
|
`Idempotency-Key`, the same on each of its retries: the API answers a retry with the first answer
|
|
@@ -384,6 +462,64 @@ lowercased, with any character other than letters, digits, `_` and `-` as `-` (`
|
|
|
384
462
|
writes `next-js-github`). A namespace that already holds another owner's repository of the same
|
|
385
463
|
name is left alone, and that repository's sync stops with an error.
|
|
386
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
|
+
|
|
387
523
|
## Changes in 0.30.0
|
|
388
524
|
|
|
389
525
|
- `embed(..., { tokenEmbeddings: true })` returns `HybridEmbeddings`: each text's vector and a vector
|