conare 0.25.1 → 0.26.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 +14 -1
- package/dist/cli/sync.js +20 -1
- package/dist/cli/upload.js +8 -4
- package/dist/index.d.ts +60 -5
- package/dist/index.js +20 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -112,6 +112,18 @@ compare numbers, string bounds compare strings by their UTF-8 bytes, so ISO date
|
|
|
112
112
|
|
|
113
113
|
`$ne` and `$nin` work in queries; a delete by filter with one answers 400 `invalid_filter`.
|
|
114
114
|
|
|
115
|
+
|
|
116
|
+
### Grep
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
const { matches, nextCursor } = await docs.grep("MAX_FILE_[A-Z]+", { limit: 20 });
|
|
120
|
+
await docs.grep({ query: "turbopufer", max_distance: 1, case_sensitive: false });
|
|
121
|
+
await docs.query("upload limits", { filter: { $text: { $regex: "(?i)max_file" } } });
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The documents whose text matches a regular expression, or nearly matches a spelling, with the lines that match, in id
|
|
125
|
+
order. `docs.create({ regexIndex: true })` before a namespace's first write makes it fast at any size.
|
|
126
|
+
|
|
115
127
|
### Embed and rerank
|
|
116
128
|
|
|
117
129
|
```ts
|
|
@@ -278,7 +290,8 @@ await sessions.query("why did we drop the Redis cache?", { filter: { project: "s
|
|
|
278
290
|
|
|
279
291
|
It reads `~/.claude/projects` (or `$CLAUDE_CONFIG_DIR`) and `~/.codex/sessions` (or `$CODEX_HOME`).
|
|
280
292
|
The key comes from `--key`, else `CONARE_API_KEY`, else `~/.conare/sync.json`. What the server
|
|
281
|
-
already has is kept in `~/.conare/sync-state.json
|
|
293
|
+
already has is kept in `~/.conare/sync-state.json` and checked against the namespace's listing at the start of a run (what
|
|
294
|
+
the server lost goes up again), and one run at a time holds `~/.conare/sync.lock`.
|
|
282
295
|
`--install` copies the command to `~/.conare/sync/<version>/`, checks the copy file by file, runs
|
|
283
296
|
it once, and only then adds a launchd agent (`ai.conare.sync`) on macOS or a systemd user timer on
|
|
284
297
|
Linux. Every run adds a line to `~/.conare/sync.log` (uploaded, skipped and failed counts, duration).
|
package/dist/cli/sync.js
CHANGED
|
@@ -6,7 +6,7 @@ import { projectName } from "./project.js";
|
|
|
6
6
|
import { findClaudeFiles, readClaudeFile } from "./sources/claude.js";
|
|
7
7
|
import { findCodexFiles, readCodexFile } from "./sources/codex.js";
|
|
8
8
|
import { isStamped, loadState, saveState } from "./state.js";
|
|
9
|
-
import { BATCH_BYTES, BATCH_DOCUMENTS, UPLOADS_IN_FLIGHT, heldAs, listLayouts, removeStaleParts, sendBatch } from "./upload.js";
|
|
9
|
+
import { BATCH_BYTES, BATCH_DOCUMENTS, UPLOADS_IN_FLIGHT, heldAs, listLayouts, removeStaleParts, sendBatch, splitPart } from "./upload.js";
|
|
10
10
|
export function findTranscripts(paths) {
|
|
11
11
|
return [
|
|
12
12
|
...findClaudeFiles(paths.claudeDir).map((f) => ({ path: f.path, read: () => readClaudeFile(f) })),
|
|
@@ -97,6 +97,10 @@ export async function runSync(opts) {
|
|
|
97
97
|
log(`Uploaded ${report.documents} documents (${formatBytes(report.bytes)})`);
|
|
98
98
|
};
|
|
99
99
|
try {
|
|
100
|
+
// What the state says the server holds and it no longer does (a delete in the console,
|
|
101
|
+
// an erased namespace, a restore) goes up again: only those, since the rest still match.
|
|
102
|
+
if (ns && Object.keys(state.documents).length > 0)
|
|
103
|
+
forgetGone(state, await (layouts ??= listLayouts(ns)));
|
|
100
104
|
const files = newestFirst(opts.files);
|
|
101
105
|
for (const file of files)
|
|
102
106
|
await visit(file);
|
|
@@ -202,6 +206,21 @@ async function settle(ns, state, entry, report, held) {
|
|
|
202
206
|
}
|
|
203
207
|
state.files[entry.path] = entry.stamp;
|
|
204
208
|
}
|
|
209
|
+
/** Drop what the server no longer holds from the state; every file is then read again, as its stamp says nothing of that. */
|
|
210
|
+
function forgetGone(state, listed) {
|
|
211
|
+
let gone = false;
|
|
212
|
+
for (const id of Object.keys(state.documents)) {
|
|
213
|
+
const { base, part } = splitPart(id);
|
|
214
|
+
const held = listed.get(base);
|
|
215
|
+
if (part === undefined ? held?.whole : held?.parts.includes(part))
|
|
216
|
+
continue;
|
|
217
|
+
delete state.documents[id];
|
|
218
|
+
state.parts[base] = 0;
|
|
219
|
+
gone = true;
|
|
220
|
+
}
|
|
221
|
+
if (gone)
|
|
222
|
+
state.files = {};
|
|
223
|
+
}
|
|
205
224
|
/** Stat every file (skipping ones that vanished) and order newest first, so a cut-short run keeps the recent work. */
|
|
206
225
|
function newestFirst(files) {
|
|
207
226
|
const out = [];
|
package/dist/cli/upload.js
CHANGED
|
@@ -78,16 +78,20 @@ async function deleteIfPresent(ns, id) {
|
|
|
78
78
|
/** Loop guard for the part probe; a session in parts of PART_BYTES would need to exceed 25 GB. */
|
|
79
79
|
const MAX_PARTS = 100_000;
|
|
80
80
|
const PART_ID = /^(.+):part:(\d{6})$/;
|
|
81
|
+
/** A document id as its session and, for one stored in parts, its part. */
|
|
82
|
+
export function splitPart(id) {
|
|
83
|
+
const m = PART_ID.exec(id);
|
|
84
|
+
return m ? { base: m[1], part: Number(m[2]) } : { base: id };
|
|
85
|
+
}
|
|
81
86
|
/** List every id in the namespace once and group them by session; an absent namespace holds nothing. */
|
|
82
87
|
export async function listLayouts(ns) {
|
|
83
88
|
const layouts = new Map();
|
|
84
89
|
try {
|
|
85
90
|
for await (const doc of ns.list({ limit: 100 })) {
|
|
86
|
-
const
|
|
87
|
-
const base = m ? m[1] : doc.id;
|
|
91
|
+
const { base, part } = splitPart(doc.id);
|
|
88
92
|
const held = layouts.get(base) ?? { whole: false, parts: [] };
|
|
89
|
-
if (
|
|
90
|
-
held.parts.push(
|
|
93
|
+
if (part !== undefined)
|
|
94
|
+
held.parts.push(part);
|
|
91
95
|
else
|
|
92
96
|
held.whole = true;
|
|
93
97
|
layouts.set(base, held);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.26.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>;
|
|
@@ -20,16 +20,40 @@ export interface FilterOperators {
|
|
|
20
20
|
$ne?: Scalar;
|
|
21
21
|
$nin?: Scalar[];
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Text within `maxDistance` edits of `query`, anywhere in a passage: `query` holds at least
|
|
25
|
+
* 3 x (`maxDistance` + 1) characters and at most 64. The wire form, as `Filter`'s `$text` takes it.
|
|
26
|
+
*/
|
|
27
|
+
export interface FuzzyText {
|
|
28
|
+
query: string;
|
|
29
|
+
/** 0, 1 or 2; default 1. */
|
|
30
|
+
max_distance?: number;
|
|
31
|
+
/** Default true. */
|
|
32
|
+
case_sensitive?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** A test on each passage's text: a regular expression matched anywhere, or a near spelling. */
|
|
35
|
+
export type TextFilter = {
|
|
36
|
+
$regex: string;
|
|
37
|
+
} | {
|
|
38
|
+
$fuzzy: FuzzyText;
|
|
39
|
+
};
|
|
23
40
|
/**
|
|
24
41
|
* A metadata filter. `{ team: "support" }` means equals (or, for an array value, contains);
|
|
25
42
|
* use `$eq` / `$in` / ranges per key and `$and` / `$or` to combine:
|
|
26
|
-
* `{ $or: [{ team: "support" }, { year: { $gte: 2024 } }] }`.
|
|
43
|
+
* `{ $or: [{ team: "support" }, { year: { $gte: 2024 } }] }`. `$text` tests the text instead,
|
|
44
|
+
* in queries and `grep`, not beside `$ne` or `$nin`.
|
|
27
45
|
*/
|
|
28
|
-
export
|
|
46
|
+
export type Filter = FieldFilter | TextClause;
|
|
47
|
+
interface FieldFilter {
|
|
29
48
|
$and?: Filter[];
|
|
30
49
|
$or?: Filter[];
|
|
31
50
|
[key: string]: Scalar | FilterOperators | Filter[] | undefined;
|
|
32
51
|
}
|
|
52
|
+
interface TextClause {
|
|
53
|
+
$and?: Filter[];
|
|
54
|
+
$or?: Filter[];
|
|
55
|
+
$text: TextFilter;
|
|
56
|
+
}
|
|
33
57
|
export interface DocumentInput {
|
|
34
58
|
/** 1-256 characters of [A-Za-z0-9._:-]. Omit to let Conare generate one. Same id replaces. */
|
|
35
59
|
id?: string;
|
|
@@ -200,7 +224,8 @@ export interface FileUpload {
|
|
|
200
224
|
ocrPending: number[];
|
|
201
225
|
/**
|
|
202
226
|
* `queued`, `parsing`: the parse runs; follow it with `getFile(fileId)`. `ocr`: stored, with pages OCR tries
|
|
203
|
-
* again (`ocrPending`). `ready`: every document is stored. `failed`: the parse failed
|
|
227
|
+
* again (`ocrPending`). `ready`: every document is stored. `failed`: the parse failed or parts of it could not be
|
|
228
|
+
* stored (`error`); what `ids` lists stays searchable.
|
|
204
229
|
*/
|
|
205
230
|
state: "queued" | "parsing" | "ocr" | "ready" | "failed";
|
|
206
231
|
/** The files source of the namespace (and user): the file's document is `<sourceId>:<fileId>`. */
|
|
@@ -272,6 +297,28 @@ export interface QueryOptions extends RequestOptions {
|
|
|
272
297
|
/** 2 searches again from the best results, for answers that span documents (not with `queryPages`). */
|
|
273
298
|
hops?: 1 | 2;
|
|
274
299
|
}
|
|
300
|
+
export interface GrepOptions extends RequestOptions {
|
|
301
|
+
filter?: Filter;
|
|
302
|
+
user?: string;
|
|
303
|
+
userPrefix?: string;
|
|
304
|
+
/** At most this many documents: 1-100, default 20. */
|
|
305
|
+
limit?: number;
|
|
306
|
+
/** A page's `nextCursor`, to go on. */
|
|
307
|
+
cursor?: string;
|
|
308
|
+
}
|
|
309
|
+
/** A document whose text matches, with the lines that do. */
|
|
310
|
+
export interface GrepMatch {
|
|
311
|
+
namespace: string;
|
|
312
|
+
id: string;
|
|
313
|
+
date?: string;
|
|
314
|
+
lines: string[];
|
|
315
|
+
}
|
|
316
|
+
/** One page of `Namespace.grep`. */
|
|
317
|
+
export interface GrepPage {
|
|
318
|
+
matches: GrepMatch[];
|
|
319
|
+
/** Where the next page starts; null on the last page. A page can stop short of `limit`. */
|
|
320
|
+
nextCursor: string | null;
|
|
321
|
+
}
|
|
275
322
|
/** One page of `Namespace.queryPages`. */
|
|
276
323
|
export interface QueryPage {
|
|
277
324
|
results: QueryResult[];
|
|
@@ -615,10 +662,12 @@ export declare class Namespace {
|
|
|
615
662
|
* Create the namespace before its first write. Only a namespace embedded by `embeddingModel`
|
|
616
663
|
* (one of your organization's models from `GET /models`) needs this: a write creates one with the
|
|
617
664
|
* default model. Its model never changes: creating it again with another one is a 409. Returns
|
|
618
|
-
* the model that embeds it.
|
|
665
|
+
* the model that embeds it. `regexIndex` makes `grep` and `$text` filters answer from an index,
|
|
666
|
+
* chosen once: over a namespace that exists without one it is a 409.
|
|
619
667
|
*/
|
|
620
668
|
create(options?: RequestOptions & {
|
|
621
669
|
embeddingModel?: string;
|
|
670
|
+
regexIndex?: boolean;
|
|
622
671
|
}): Promise<{
|
|
623
672
|
embeddingModel: string;
|
|
624
673
|
}>;
|
|
@@ -673,6 +722,12 @@ export declare class Namespace {
|
|
|
673
722
|
* `userPrefix` is a 400, never "every user". `excludeIds` keeps those documents out.
|
|
674
723
|
*/
|
|
675
724
|
query(query: string, options?: QueryOptions): Promise<QueryResult[]>;
|
|
725
|
+
/**
|
|
726
|
+
* The documents whose text matches a regular expression, or a near spelling (`{ query, max_distance }`),
|
|
727
|
+
* with the lines that match, in id order. A match lies inside one passage. Pass `nextCursor` as `cursor`
|
|
728
|
+
* to go on; a namespace created without `regexIndex` reads its passages, so a page can stop short of `limit`.
|
|
729
|
+
*/
|
|
730
|
+
grep(pattern: string | FuzzyText, options?: GrepOptions): Promise<GrepPage>;
|
|
676
731
|
/**
|
|
677
732
|
* A deep search, page by page: ranks `maxResults` documents once (at least `topK`; at most 1,000,
|
|
678
733
|
* or 5,000 on a custom model's engine) and yields them `topK` at a time. Later pages are read from
|
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.26.0";
|
|
3
3
|
const DEFAULT_BASE_URL = "https://api.conare.ai";
|
|
4
4
|
const BATCH_SIZE = 100;
|
|
5
5
|
// A JSON body this long or longer goes gzip-encoded: past the first ~14 KB a new connection may send,
|
|
@@ -330,10 +330,11 @@ export class Namespace {
|
|
|
330
330
|
* Create the namespace before its first write. Only a namespace embedded by `embeddingModel`
|
|
331
331
|
* (one of your organization's models from `GET /models`) needs this: a write creates one with the
|
|
332
332
|
* default model. Its model never changes: creating it again with another one is a 409. Returns
|
|
333
|
-
* the model that embeds it.
|
|
333
|
+
* the model that embeds it. `regexIndex` makes `grep` and `$text` filters answer from an index,
|
|
334
|
+
* chosen once: over a namespace that exists without one it is a 409.
|
|
334
335
|
*/
|
|
335
336
|
async create(options = {}) {
|
|
336
|
-
const body = await this.client.request("POST", "/namespaces", { name: this.name, embedding_model: options.embeddingModel }, options);
|
|
337
|
+
const body = await this.client.request("POST", "/namespaces", { name: this.name, embedding_model: options.embeddingModel, regex_index: options.regexIndex }, options);
|
|
337
338
|
return { embeddingModel: body.embedding_model };
|
|
338
339
|
}
|
|
339
340
|
/**
|
|
@@ -433,6 +434,22 @@ export class Namespace {
|
|
|
433
434
|
const body = await this.client.request("POST", this.path("/query"), queryBody(query, options), options);
|
|
434
435
|
return body.results;
|
|
435
436
|
}
|
|
437
|
+
/**
|
|
438
|
+
* The documents whose text matches a regular expression, or a near spelling (`{ query, max_distance }`),
|
|
439
|
+
* with the lines that match, in id order. A match lies inside one passage. Pass `nextCursor` as `cursor`
|
|
440
|
+
* to go on; a namespace created without `regexIndex` reads its passages, so a page can stop short of `limit`.
|
|
441
|
+
*/
|
|
442
|
+
async grep(pattern, options = {}) {
|
|
443
|
+
const body = await this.client.request("POST", this.path("/grep"), {
|
|
444
|
+
...(typeof pattern === "string" ? { pattern } : { fuzzy: pattern }),
|
|
445
|
+
filter: options.filter,
|
|
446
|
+
user: options.user,
|
|
447
|
+
user_prefix: options.userPrefix,
|
|
448
|
+
limit: options.limit,
|
|
449
|
+
cursor: options.cursor,
|
|
450
|
+
}, options);
|
|
451
|
+
return { matches: body.matches, nextCursor: body.next_cursor ?? null };
|
|
452
|
+
}
|
|
436
453
|
/**
|
|
437
454
|
* A deep search, page by page: ranks `maxResults` documents once (at least `topK`; at most 1,000,
|
|
438
455
|
* or 5,000 on a custom model's engine) and yields them `topK` at a time. Later pages are read from
|