conare 0.9.0 → 0.11.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 +8 -39
- package/dist/index.d.ts +13 -2
- package/dist/index.js +24 -3
- package/package.json +4 -5
- package/dist/cli/args.js +0 -69
- package/dist/cli/config.js +0 -37
- package/dist/cli/documents.js +0 -82
- package/dist/cli/main.js +0 -127
- package/dist/cli/project.js +0 -61
- package/dist/cli/render.js +0 -69
- package/dist/cli/schedule.js +0 -177
- package/dist/cli/scrub.js +0 -102
- package/dist/cli/sources/claude.js +0 -313
- package/dist/cli/sources/codex.js +0 -266
- package/dist/cli/state.js +0 -87
- package/dist/cli/sync.js +0 -186
- package/dist/cli/transcript.js +0 -103
- package/dist/cli/upload.js +0 -137
package/dist/cli/upload.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
// Sending documents through the SDK client. The client retries 429, 5xx and network errors
|
|
2
|
-
// with backoff, honouring Retry-After (bounded by its maxRetries); what still fails here is
|
|
3
|
-
// either one bad document (sent again alone, then left for the next run) or a server or
|
|
4
|
-
// auth problem that stops the run.
|
|
5
|
-
import { ConareError } from "../index.js";
|
|
6
|
-
import { partId } from "./documents.js";
|
|
7
|
-
/** The API takes 1-100 documents per write; a byte budget keeps each request's embedding work small. */
|
|
8
|
-
export const BATCH_DOCUMENTS = 100;
|
|
9
|
-
export const BATCH_BYTES = 1_000_000;
|
|
10
|
-
export const WRITE_TIMEOUT_MS = 120_000;
|
|
11
|
-
/** Groups documents in order into batches within both limits. */
|
|
12
|
-
export function batches(docs, maxDocs = BATCH_DOCUMENTS, maxBytes = BATCH_BYTES) {
|
|
13
|
-
const out = [];
|
|
14
|
-
let current = [];
|
|
15
|
-
let bytes = 0;
|
|
16
|
-
for (const doc of docs) {
|
|
17
|
-
const size = Buffer.byteLength(doc.text);
|
|
18
|
-
if (current.length > 0 && (current.length >= maxDocs || bytes + size > maxBytes)) {
|
|
19
|
-
out.push(current);
|
|
20
|
-
current = [];
|
|
21
|
-
bytes = 0;
|
|
22
|
-
}
|
|
23
|
-
current.push(doc);
|
|
24
|
-
bytes += size;
|
|
25
|
-
}
|
|
26
|
-
if (current.length > 0)
|
|
27
|
-
out.push(current);
|
|
28
|
-
return out;
|
|
29
|
-
}
|
|
30
|
-
/** A request the API refused because of what one of its documents holds. */
|
|
31
|
-
function isDocumentError(err) {
|
|
32
|
-
return err instanceof ConareError && (err.status === 400 || err.status === 413 || err.status === 422);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Write one batch. When the API refuses the batch for its content, each document is sent
|
|
36
|
-
* alone so one bad document does not hold back the others. Any other failure throws.
|
|
37
|
-
*/
|
|
38
|
-
export async function sendBatch(ns, batch) {
|
|
39
|
-
try {
|
|
40
|
-
await ns.add(batch, { timeout: WRITE_TIMEOUT_MS });
|
|
41
|
-
return { accepted: batch, rejected: [] };
|
|
42
|
-
}
|
|
43
|
-
catch (err) {
|
|
44
|
-
if (!isDocumentError(err))
|
|
45
|
-
throw err;
|
|
46
|
-
if (batch.length === 1)
|
|
47
|
-
return { accepted: [], rejected: [{ doc: batch[0], error: err }] };
|
|
48
|
-
}
|
|
49
|
-
const result = { accepted: [], rejected: [] };
|
|
50
|
-
for (const doc of batch) {
|
|
51
|
-
try {
|
|
52
|
-
await ns.add(doc, { timeout: WRITE_TIMEOUT_MS });
|
|
53
|
-
result.accepted.push(doc);
|
|
54
|
-
}
|
|
55
|
-
catch (err) {
|
|
56
|
-
if (!isDocumentError(err))
|
|
57
|
-
throw err;
|
|
58
|
-
result.rejected.push({ doc, error: err });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return result;
|
|
62
|
-
}
|
|
63
|
-
/** Delete one document; false when it does not exist (404 document_not_found). */
|
|
64
|
-
export async function deleteIfPresent(ns, id) {
|
|
65
|
-
try {
|
|
66
|
-
await ns.delete(id);
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
if (err instanceof ConareError && err.status === 404)
|
|
71
|
-
return false;
|
|
72
|
-
throw err;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/** Loop guard for the part probe; a 256 KB-per-part session would need to exceed 25 GB. */
|
|
76
|
-
const MAX_PARTS = 100_000;
|
|
77
|
-
const PART_ID = /^(.+):part:(\d{6})$/;
|
|
78
|
-
/** List every id in the namespace once and group them by session; an absent namespace holds nothing. */
|
|
79
|
-
export async function listLayouts(ns) {
|
|
80
|
-
const layouts = new Map();
|
|
81
|
-
try {
|
|
82
|
-
for await (const doc of ns.list({ limit: 100 })) {
|
|
83
|
-
const m = PART_ID.exec(doc.id);
|
|
84
|
-
const base = m ? m[1] : doc.id;
|
|
85
|
-
const held = layouts.get(base) ?? { whole: false, parts: [] };
|
|
86
|
-
if (m)
|
|
87
|
-
held.parts.push(Number(m[2]));
|
|
88
|
-
else
|
|
89
|
-
held.whole = true;
|
|
90
|
-
layouts.set(base, held);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
catch (err) {
|
|
94
|
-
if (!(err instanceof ConareError && err.status === 404))
|
|
95
|
-
throw err;
|
|
96
|
-
}
|
|
97
|
-
return layouts;
|
|
98
|
-
}
|
|
99
|
-
/** The layout of a session this tool stored as `count` documents. */
|
|
100
|
-
export function heldAs(count) {
|
|
101
|
-
return count > 1 ? { whole: false, parts: Array.from({ length: count }, (_, i) => i + 1) } : { whole: true, parts: [] };
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Remove what an earlier layout of a session left behind, once its k new documents are
|
|
105
|
-
* accepted. A session is stored as the single document <base> or as the parts
|
|
106
|
-
* <base>:part:000001..k (this tool and the migration of older history both write that):
|
|
107
|
-
* with parts, <base> is stale; otherwise every part is; with parts, those after k are.
|
|
108
|
-
*
|
|
109
|
-
* When the old layout is known (`held`: what this tool stored last, or a listing of the
|
|
110
|
-
* namespace), exactly its stale ids are deleted, gaps included. Otherwise the parts are
|
|
111
|
-
* probed from the first stale number until the first 404. Returns the ids deleted.
|
|
112
|
-
*/
|
|
113
|
-
export async function removeStaleParts(ns, base, k, held) {
|
|
114
|
-
const deleted = [];
|
|
115
|
-
const remove = async (id) => {
|
|
116
|
-
if (await deleteIfPresent(ns, id))
|
|
117
|
-
deleted.push(id);
|
|
118
|
-
};
|
|
119
|
-
const firstStale = k > 1 ? k + 1 : 1;
|
|
120
|
-
if (held) {
|
|
121
|
-
if (k > 1 && held.whole)
|
|
122
|
-
await remove(base);
|
|
123
|
-
for (const n of [...held.parts].sort((a, b) => a - b))
|
|
124
|
-
if (n >= firstStale)
|
|
125
|
-
await remove(partId(base, n));
|
|
126
|
-
return deleted;
|
|
127
|
-
}
|
|
128
|
-
if (k > 1)
|
|
129
|
-
await remove(base);
|
|
130
|
-
for (let n = firstStale; n <= MAX_PARTS; n++) {
|
|
131
|
-
const id = partId(base, n);
|
|
132
|
-
if (!(await deleteIfPresent(ns, id)))
|
|
133
|
-
break;
|
|
134
|
-
deleted.push(id);
|
|
135
|
-
}
|
|
136
|
-
return deleted;
|
|
137
|
-
}
|