@agentproto/collect 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +642 -2
- package/dist/chunk-FQLYZIVI.mjs +405 -0
- package/dist/chunk-FQLYZIVI.mjs.map +1 -0
- package/dist/chunk-SOLT3HJH.mjs +213 -0
- package/dist/chunk-SOLT3HJH.mjs.map +1 -0
- package/dist/chunk-SYTQ6RN6.mjs +98 -0
- package/dist/chunk-SYTQ6RN6.mjs.map +1 -0
- package/dist/connector-DUNy3vSU.d.ts +981 -0
- package/dist/connectors.d.ts +104 -0
- package/dist/connectors.mjs +1197 -0
- package/dist/connectors.mjs.map +1 -0
- package/dist/engine-BRXHKg5A.d.ts +384 -0
- package/dist/index.d.ts +134 -0
- package/dist/index.mjs +1494 -0
- package/dist/index.mjs.map +1 -0
- package/dist/node.d.ts +526 -0
- package/dist/node.mjs +2322 -0
- package/dist/node.mjs.map +1 -0
- package/package.json +71 -3
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { F as FailureCause, o as CollectItem, O as Observation, e as Actor, W as Pickup, R as Recipe, $ as RunReport, a7 as TransportSet, b as SecretsPort, C as Connector, c as ConnectorRegistry } from './connector-DUNy3vSU.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/** One line of `raw/index.jsonl`: where a fetched body lives and how it was fetched. */
|
|
5
|
+
declare const RawIndexEntry: z.ZodObject<{
|
|
6
|
+
ref: z.ZodString;
|
|
7
|
+
connector: z.ZodString;
|
|
8
|
+
hash: z.ZodString;
|
|
9
|
+
ext: z.ZodString;
|
|
10
|
+
bytes: z.ZodNumber;
|
|
11
|
+
url: z.ZodString;
|
|
12
|
+
fetchedAt: z.ZodISODateTime;
|
|
13
|
+
httpStatus: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
contentType: z.ZodOptional<z.ZodString>;
|
|
15
|
+
transport: z.ZodString;
|
|
16
|
+
runId: z.ZodOptional<z.ZodString>;
|
|
17
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
18
|
+
failure: z.ZodOptional<z.ZodEnum<{
|
|
19
|
+
blocked: "blocked";
|
|
20
|
+
empty: "empty";
|
|
21
|
+
network: "network";
|
|
22
|
+
http: "http";
|
|
23
|
+
challenge: "challenge";
|
|
24
|
+
parse: "parse";
|
|
25
|
+
other: "other";
|
|
26
|
+
}>>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
type RawIndexEntry = z.infer<typeof RawIndexEntry>;
|
|
29
|
+
/** One line of `plan.jsonl`: a root task of the run, written once and atomically before anything runs. */
|
|
30
|
+
declare const PlanEntry: z.ZodObject<{
|
|
31
|
+
taskId: z.ZodString;
|
|
32
|
+
connector: z.ZodString;
|
|
33
|
+
order: z.ZodArray<z.ZodNumber>;
|
|
34
|
+
payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
type PlanEntry = z.infer<typeof PlanEntry>;
|
|
37
|
+
declare const TaskStatus: z.ZodEnum<{
|
|
38
|
+
failed: "failed";
|
|
39
|
+
skipped: "skipped";
|
|
40
|
+
done: "done";
|
|
41
|
+
pending: "pending";
|
|
42
|
+
started: "started";
|
|
43
|
+
}>;
|
|
44
|
+
type TaskStatus = z.infer<typeof TaskStatus>;
|
|
45
|
+
/** One line of `tasks.jsonl`. The last line for a task id is its current state. */
|
|
46
|
+
declare const TaskRecord: z.ZodObject<{
|
|
47
|
+
taskId: z.ZodString;
|
|
48
|
+
connector: z.ZodString;
|
|
49
|
+
status: z.ZodEnum<{
|
|
50
|
+
failed: "failed";
|
|
51
|
+
skipped: "skipped";
|
|
52
|
+
done: "done";
|
|
53
|
+
pending: "pending";
|
|
54
|
+
started: "started";
|
|
55
|
+
}>;
|
|
56
|
+
transport: z.ZodOptional<z.ZodString>;
|
|
57
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
58
|
+
cause: z.ZodOptional<z.ZodEnum<{
|
|
59
|
+
blocked: "blocked";
|
|
60
|
+
empty: "empty";
|
|
61
|
+
network: "network";
|
|
62
|
+
http: "http";
|
|
63
|
+
challenge: "challenge";
|
|
64
|
+
parse: "parse";
|
|
65
|
+
other: "other";
|
|
66
|
+
}>>;
|
|
67
|
+
order: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
68
|
+
counters: z.ZodOptional<z.ZodObject<{
|
|
69
|
+
items: z.ZodNumber;
|
|
70
|
+
newItems: z.ZodNumber;
|
|
71
|
+
duplicates: z.ZodNumber;
|
|
72
|
+
observations: z.ZodNumber;
|
|
73
|
+
metricValues: z.ZodNumber;
|
|
74
|
+
durationMs: z.ZodNumber;
|
|
75
|
+
}, z.core.$strip>>;
|
|
76
|
+
charged: z.ZodOptional<z.ZodBoolean>;
|
|
77
|
+
escalations: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
78
|
+
from: z.ZodString;
|
|
79
|
+
to: z.ZodString;
|
|
80
|
+
}, z.core.$strip>>>;
|
|
81
|
+
payload: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
82
|
+
updatedAt: z.ZodISODateTime;
|
|
83
|
+
}, z.core.$strip>;
|
|
84
|
+
type TaskRecord = z.infer<typeof TaskRecord>;
|
|
85
|
+
/** One line of `sampling.jsonl`: a candidate seen, and whether the sampling kept it. */
|
|
86
|
+
declare const SamplingRecord: z.ZodObject<{
|
|
87
|
+
candidate: z.ZodString;
|
|
88
|
+
decision: z.ZodEnum<{
|
|
89
|
+
kept: "kept";
|
|
90
|
+
dropped: "dropped";
|
|
91
|
+
}>;
|
|
92
|
+
rule: z.ZodOptional<z.ZodString>;
|
|
93
|
+
band: z.ZodOptional<z.ZodNumber>;
|
|
94
|
+
url: z.ZodOptional<z.ZodString>;
|
|
95
|
+
domain: z.ZodOptional<z.ZodString>;
|
|
96
|
+
seed: z.ZodOptional<z.ZodNumber>;
|
|
97
|
+
connector: z.ZodOptional<z.ZodString>;
|
|
98
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
99
|
+
at: z.ZodISODateTime;
|
|
100
|
+
}, z.core.$strip>;
|
|
101
|
+
type SamplingRecord = z.infer<typeof SamplingRecord>;
|
|
102
|
+
/** One line of `events.jsonl`. */
|
|
103
|
+
declare const EventRecord: z.ZodObject<{
|
|
104
|
+
at: z.ZodISODateTime;
|
|
105
|
+
type: z.ZodString;
|
|
106
|
+
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
107
|
+
}, z.core.$strip>;
|
|
108
|
+
type EventRecord = z.infer<typeof EventRecord>;
|
|
109
|
+
/** Content of `runs/<runId>/recipe.json`: the recipe as it was when the run started, and its hash. */
|
|
110
|
+
declare const RunRecord: z.ZodObject<{
|
|
111
|
+
runId: z.ZodString;
|
|
112
|
+
createdAt: z.ZodISODateTime;
|
|
113
|
+
recipeHash: z.ZodString;
|
|
114
|
+
recipe: z.ZodObject<{
|
|
115
|
+
name: z.ZodOptional<z.ZodString>;
|
|
116
|
+
sources: z.ZodArray<z.ZodObject<{
|
|
117
|
+
connector: z.ZodString;
|
|
118
|
+
instance: z.ZodOptional<z.ZodString>;
|
|
119
|
+
queries: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
120
|
+
text: z.ZodString;
|
|
121
|
+
subject: z.ZodString;
|
|
122
|
+
}, z.core.$strip>>>;
|
|
123
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
124
|
+
}, z.core.$strip>>;
|
|
125
|
+
window: z.ZodOptional<z.ZodObject<{
|
|
126
|
+
from: z.ZodOptional<z.ZodISODateTime>;
|
|
127
|
+
to: z.ZodOptional<z.ZodISODateTime>;
|
|
128
|
+
}, z.core.$strip>>;
|
|
129
|
+
sampling: z.ZodOptional<z.ZodObject<{
|
|
130
|
+
bands: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
131
|
+
metric: z.ZodOptional<z.ZodEnum<{
|
|
132
|
+
views: "views";
|
|
133
|
+
likes: "likes";
|
|
134
|
+
reposts: "reposts";
|
|
135
|
+
replies: "replies";
|
|
136
|
+
bookmarks: "bookmarks";
|
|
137
|
+
points: "points";
|
|
138
|
+
comments: "comments";
|
|
139
|
+
reactions: "reactions";
|
|
140
|
+
score: "score";
|
|
141
|
+
rating: "rating";
|
|
142
|
+
helpfulVotes: "helpfulVotes";
|
|
143
|
+
}>>;
|
|
144
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
145
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
146
|
+
quota: z.ZodOptional<z.ZodNumber>;
|
|
147
|
+
}, z.core.$strip>>>;
|
|
148
|
+
keepMissingMetric: z.ZodOptional<z.ZodBoolean>;
|
|
149
|
+
perDomainCap: z.ZodOptional<z.ZodNumber>;
|
|
150
|
+
seed: z.ZodOptional<z.ZodNumber>;
|
|
151
|
+
}, z.core.$strip>>;
|
|
152
|
+
caps: z.ZodOptional<z.ZodObject<{
|
|
153
|
+
perConnector: z.ZodOptional<z.ZodNumber>;
|
|
154
|
+
total: z.ZodOptional<z.ZodNumber>;
|
|
155
|
+
}, z.core.$strip>>;
|
|
156
|
+
workers: z.ZodDefault<z.ZodNumber>;
|
|
157
|
+
lookahead: z.ZodOptional<z.ZodNumber>;
|
|
158
|
+
sinks: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
159
|
+
}, z.core.$strip>;
|
|
160
|
+
connectorModules: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
161
|
+
origin: z.ZodOptional<z.ZodLiteral<"reparse">>;
|
|
162
|
+
}, z.core.$strip>;
|
|
163
|
+
type RunRecord = z.infer<typeof RunRecord>;
|
|
164
|
+
interface PutRawInput {
|
|
165
|
+
connector: string;
|
|
166
|
+
/** File extension without the dot, e.g. `json`, `html`. */
|
|
167
|
+
ext: string;
|
|
168
|
+
bytes: Uint8Array;
|
|
169
|
+
url: string;
|
|
170
|
+
fetchedAt: string;
|
|
171
|
+
httpStatus?: number;
|
|
172
|
+
contentType?: string;
|
|
173
|
+
transport: string;
|
|
174
|
+
runId?: string;
|
|
175
|
+
/** `<connector>/<task id>`: the task that fetched this body. */
|
|
176
|
+
taskId?: string;
|
|
177
|
+
failure?: FailureCause;
|
|
178
|
+
}
|
|
179
|
+
interface PutRawResult {
|
|
180
|
+
ref: string;
|
|
181
|
+
hash: string;
|
|
182
|
+
/** False when a body with the same bytes already sat at the same path; the index line is still appended. */
|
|
183
|
+
stored: boolean;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* A streaming read. `skipped` counts the lines that were unreadable (not JSON,
|
|
187
|
+
* or failing schema validation) and were left out; it is final once the
|
|
188
|
+
* iteration is over and restarts at 0 on each new iteration.
|
|
189
|
+
*/
|
|
190
|
+
interface Reader<T> extends AsyncIterable<T> {
|
|
191
|
+
readonly skipped: number;
|
|
192
|
+
}
|
|
193
|
+
interface StoreLock {
|
|
194
|
+
release(): Promise<void>;
|
|
195
|
+
}
|
|
196
|
+
/** Where records are kept, as seen by the engine. Same contract for the memory and the disk store. */
|
|
197
|
+
interface CollectStore {
|
|
198
|
+
/** Version of the stored shapes this store holds (after any migration). */
|
|
199
|
+
schemaVersion(): Promise<number>;
|
|
200
|
+
putRaw(input: PutRawInput): Promise<PutRawResult>;
|
|
201
|
+
getRaw(ref: string): Promise<Uint8Array | undefined>;
|
|
202
|
+
rawIndex(): Reader<RawIndexEntry>;
|
|
203
|
+
/** Insert or replace an item: the last write for an id wins. */
|
|
204
|
+
upsertItem(item: CollectItem): Promise<void>;
|
|
205
|
+
getItem(id: string): Promise<CollectItem | undefined>;
|
|
206
|
+
/** Current version of each item. `source` is the prefix of the item id (`hn` for `hn:1`), which is also the file the item is kept in. */
|
|
207
|
+
items(source?: string): Reader<CollectItem>;
|
|
208
|
+
/** Observations, actors: filed by the id prefix (`itemId` / `ref`), and `source` filters on that prefix. */
|
|
209
|
+
appendObservation(observation: Observation): Promise<void>;
|
|
210
|
+
observations(source?: string): Reader<Observation>;
|
|
211
|
+
appendActor(actor: Actor): Promise<void>;
|
|
212
|
+
actors(source?: string): Reader<Actor>;
|
|
213
|
+
appendPickup(pickup: Pickup): Promise<void>;
|
|
214
|
+
pickups(): Reader<Pickup>;
|
|
215
|
+
/** Dedup keys, see `seenKey`. */
|
|
216
|
+
seenHas(key: string): Promise<boolean>;
|
|
217
|
+
/** The item id that owns a key. `undefined` when the key is unknown or was recorded without an owner. */
|
|
218
|
+
seenGet(key: string): Promise<string | undefined>;
|
|
219
|
+
/** Record a key. `itemId` is the item that owns it; adding an owner to a key that had none sets it, an existing owner is kept. */
|
|
220
|
+
seenAdd(key: string, itemId?: string): Promise<void>;
|
|
221
|
+
seenKeys(): Promise<string[]>;
|
|
222
|
+
/** Recompute the seen keys, with their owners, from the stored items (current version of each). */
|
|
223
|
+
rebuildSeenIndex(): Promise<void>;
|
|
224
|
+
createRun(runId: string, recipe: Recipe, extra?: {
|
|
225
|
+
connectorModules?: string[];
|
|
226
|
+
origin?: "reparse";
|
|
227
|
+
}): Promise<RunRecord>;
|
|
228
|
+
getRun(runId: string): Promise<RunRecord | undefined>;
|
|
229
|
+
listRuns(): Promise<string[]>;
|
|
230
|
+
/** The run-log writers below throw when the run was not created. Append a task state; the last line for a task id is its current state. */
|
|
231
|
+
appendTask(runId: string, task: TaskRecord): Promise<void>;
|
|
232
|
+
tasks(runId: string): Reader<TaskRecord>;
|
|
233
|
+
/** Write the whole root plan of a run in one atomic write. A second call replaces it. */
|
|
234
|
+
writePlan(runId: string, plan: PlanEntry[]): Promise<void>;
|
|
235
|
+
readPlan(runId: string): Promise<PlanEntry[] | undefined>;
|
|
236
|
+
appendSampling(runId: string, record: SamplingRecord): Promise<void>;
|
|
237
|
+
/** Append all the records in one write: a crash leaves a prefix of them, never a reordered or interleaved set. Every record is validated first. */
|
|
238
|
+
appendSamplingBatch(runId: string, records: SamplingRecord[]): Promise<void>;
|
|
239
|
+
sampling(runId: string): Reader<SamplingRecord>;
|
|
240
|
+
appendEvent(runId: string, event: EventRecord): Promise<void>;
|
|
241
|
+
events(runId: string): Reader<EventRecord>;
|
|
242
|
+
writeReport(runId: string, report: RunReport): Promise<void>;
|
|
243
|
+
readReport(runId: string): Promise<RunReport | undefined>;
|
|
244
|
+
/** Take the store-wide writer lock. Throws `StoreLockedError` when it is held. */
|
|
245
|
+
acquireLock(): Promise<StoreLock>;
|
|
246
|
+
}
|
|
247
|
+
declare class StoreLockedError extends Error {
|
|
248
|
+
readonly holder?: {
|
|
249
|
+
pid: number;
|
|
250
|
+
at: string;
|
|
251
|
+
host?: string;
|
|
252
|
+
} | undefined;
|
|
253
|
+
readonly code = "STORE_LOCKED";
|
|
254
|
+
constructor(message: string, holder?: {
|
|
255
|
+
pid: number;
|
|
256
|
+
at: string;
|
|
257
|
+
host?: string;
|
|
258
|
+
} | undefined);
|
|
259
|
+
}
|
|
260
|
+
/** The store was written by a newer version than this reader understands. */
|
|
261
|
+
declare class StoreVersionError extends Error {
|
|
262
|
+
readonly found: number;
|
|
263
|
+
readonly supported: number;
|
|
264
|
+
readonly code = "STORE_VERSION";
|
|
265
|
+
constructor(found: number, supported: number);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Drop the copy a task writes again when it is redone after a crash: records
|
|
269
|
+
* with a `recordKey` are kept once per key, the first write wins (a retry that
|
|
270
|
+
* reads other values for the same raw and index is the same record); records
|
|
271
|
+
* without one always pass. Two distinct readings with equal values have
|
|
272
|
+
* different keys and are both kept.
|
|
273
|
+
*/
|
|
274
|
+
declare function dropRedone<T>(source: Reader<T>, tag: (r: T) => string | undefined): Reader<T>;
|
|
275
|
+
/** Records without a `recordKey` (not written by the engine) are never dropped. */
|
|
276
|
+
declare const observationRedoKey: (o: Observation) => string | undefined;
|
|
277
|
+
declare const pickupRedoKey: (p: Pickup) => string | undefined;
|
|
278
|
+
declare const actorRedoKey: (a: Actor) => string | undefined;
|
|
279
|
+
/** Dedup key kinds. Keys are `<kind>:<value>`. */
|
|
280
|
+
declare function seenKey(kind: "id" | "url" | "content", value: string): string;
|
|
281
|
+
/** The keys an item contributes to the seen index: native id, canonical URL, content id. */
|
|
282
|
+
declare function itemSeenKeys(item: CollectItem): string[];
|
|
283
|
+
/** Names that become a path segment (connector, source, run id, extension) are restricted to a safe alphabet. */
|
|
284
|
+
declare function assertSafeName(kind: string, value: string): string;
|
|
285
|
+
/** Source prefix of an id or ref of the form `source:rest`. */
|
|
286
|
+
declare function sourceOf(idOrRef: string): string;
|
|
287
|
+
/** `yyyy-mm` (UTC) of a timestamp. */
|
|
288
|
+
declare function monthOf(timestamp: string): string;
|
|
289
|
+
declare function sha256Bytes(bytes: Uint8Array): Promise<string>;
|
|
290
|
+
/** JSON with object keys sorted, so equal values give equal text. */
|
|
291
|
+
declare function stableStringify(value: unknown): string;
|
|
292
|
+
declare function recipeHash(recipe: Recipe): Promise<string>;
|
|
293
|
+
/** Strict parser of a raw ref. Throws on anything that is not exactly `raw/<connector>/<yyyy-mm>/<sha256>.<ext>.gz`. */
|
|
294
|
+
declare function parseRawRef(ref: string): {
|
|
295
|
+
connector: string;
|
|
296
|
+
month: string;
|
|
297
|
+
hash: string;
|
|
298
|
+
ext: string;
|
|
299
|
+
};
|
|
300
|
+
/** Relative path of a stored raw body. */
|
|
301
|
+
declare function rawRef(connector: string, fetchedAt: string, hash: string, ext: string): string;
|
|
302
|
+
/** Build a `Reader` from a generator that reports each skipped line through `onSkip`. */
|
|
303
|
+
declare function makeReader<T>(gen: (onSkip: () => void) => AsyncGenerator<T>): Reader<T>;
|
|
304
|
+
/** Drain a reader into an array, with the skipped count. */
|
|
305
|
+
declare function readAll<T>(reader: Reader<T>): Promise<{
|
|
306
|
+
records: T[];
|
|
307
|
+
skipped: number;
|
|
308
|
+
}>;
|
|
309
|
+
/** Keep the last record of each key, in order of first appearance. */
|
|
310
|
+
declare function lastWins<T>(source: AsyncIterable<T>, key: (r: T) => string): AsyncGenerator<T>;
|
|
311
|
+
|
|
312
|
+
interface Clock {
|
|
313
|
+
/** Milliseconds since the epoch. */
|
|
314
|
+
now(): number;
|
|
315
|
+
sleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
316
|
+
}
|
|
317
|
+
interface CollectorOptions {
|
|
318
|
+
store: CollectStore;
|
|
319
|
+
transports: TransportSet;
|
|
320
|
+
/**
|
|
321
|
+
* Where secrets come from. Every value resolved through it during a run is
|
|
322
|
+
* scrubbed from events, task records and reports before they are stored or
|
|
323
|
+
* handed to `onEvent`, and from the message of a `CollectRunError`. Pass a
|
|
324
|
+
* `recordSecrets(port)` recorder and give the same one to anything else that
|
|
325
|
+
* resolves secrets (an API transport) so they share one redaction set.
|
|
326
|
+
*/
|
|
327
|
+
secrets?: SecretsPort;
|
|
328
|
+
/**
|
|
329
|
+
* After `signal` aborts, how long to wait for tasks that do not settle (a
|
|
330
|
+
* connector that ignores the abort signal) before the run gives up on them,
|
|
331
|
+
* releases the store lock and returns. Their tasks stay `started` in the run
|
|
332
|
+
* log (so `resume` redoes them) and whatever they do later is not written.
|
|
333
|
+
* Default 10000.
|
|
334
|
+
*/
|
|
335
|
+
abortGraceMs?: number;
|
|
336
|
+
/** A list, or a registry. Defaults to the process-wide registry (`registerConnector`). */
|
|
337
|
+
connectors?: Connector[] | ConnectorRegistry;
|
|
338
|
+
clock?: Clock;
|
|
339
|
+
/** Source of randomness for run ids: returns a number in [0, 1). */
|
|
340
|
+
random?: () => number;
|
|
341
|
+
}
|
|
342
|
+
interface RunEvent extends EventRecord {
|
|
343
|
+
runId: string;
|
|
344
|
+
}
|
|
345
|
+
interface RunOptions {
|
|
346
|
+
/** Paths of the connector modules the host loaded for this run; kept in the run record so `resume` can load them again. */
|
|
347
|
+
connectorModules?: string[];
|
|
348
|
+
/** Stop taking tasks when aborted; pending tasks stay pending and a partial report is written. */
|
|
349
|
+
signal?: AbortSignal;
|
|
350
|
+
onEvent?: (event: RunEvent) => void;
|
|
351
|
+
runId?: string;
|
|
352
|
+
}
|
|
353
|
+
/** The run stopped on an error of its own (the store failed, a connector could not plan). The run is left resumable. */
|
|
354
|
+
declare class CollectRunError extends Error {
|
|
355
|
+
readonly runId: string;
|
|
356
|
+
readonly cause: unknown;
|
|
357
|
+
readonly code = "RUN_ERROR";
|
|
358
|
+
constructor(runId: string, cause: unknown);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* One collector drives one store: the store lock allows a single run at a
|
|
362
|
+
* time, so the host gate and the browser lane below are per collector and
|
|
363
|
+
* per run by construction. Do not share a browser between two collectors.
|
|
364
|
+
*/
|
|
365
|
+
interface Collector {
|
|
366
|
+
/** Plan the recipe and run it. Creates a new run. */
|
|
367
|
+
run(recipe: Recipe | unknown, options?: RunOptions): Promise<RunReport>;
|
|
368
|
+
/**
|
|
369
|
+
* Continue a run from its log. Reloads the frozen recipe, the plan and every
|
|
370
|
+
* task as last recorded; `done` tasks are skipped and never fetched again,
|
|
371
|
+
* `pending`, `failed` and `skipped` tasks are redone (a skipped task is
|
|
372
|
+
* re-checked against the transports and secrets available now; a connector
|
|
373
|
+
* that is no longer registered has its tasks reported skipped). Tasks come
|
|
374
|
+
* back in their recorded global order. The per-connector and total caps are
|
|
375
|
+
* restored from the task states: a task that was `done` or `failed` already
|
|
376
|
+
* used its budget, so retrying it takes none, while a task that never
|
|
377
|
+
* started does. The report covers the whole run, earlier attempts included.
|
|
378
|
+
* A challenge stop does not carry over: the connector is tried again.
|
|
379
|
+
*/
|
|
380
|
+
resume(runId: string, options?: Omit<RunOptions, "runId">): Promise<RunReport>;
|
|
381
|
+
}
|
|
382
|
+
declare function createCollector(options: CollectorOptions): Collector;
|
|
383
|
+
|
|
384
|
+
export { readAll as A, recipeHash as B, type CollectStore as C, seenKey as D, EventRecord as E, sha256Bytes as F, sourceOf as G, stableStringify as H, PlanEntry as P, RawIndexEntry as R, SamplingRecord as S, TaskRecord as T, type Clock as a, CollectRunError as b, type Collector as c, type CollectorOptions as d, type PutRawInput as e, type PutRawResult as f, type Reader as g, type RunEvent as h, type RunOptions as i, RunRecord as j, type StoreLock as k, StoreLockedError as l, StoreVersionError as m, TaskStatus as n, actorRedoKey as o, assertSafeName as p, createCollector as q, dropRedone as r, itemSeenKeys as s, lastWins as t, makeReader as u, monthOf as v, observationRedoKey as w, parseRawRef as x, pickupRedoKey as y, rawRef as z };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { b as SecretsPort, M as MetricName, R as Recipe, c as ConnectorRegistry, C as Connector, d as Coverage } from './connector-DUNy3vSU.js';
|
|
2
|
+
export { A as AccessDeclaration, e as Actor, f as ApiConnectorInfo, g as ApiTransportFactory, h as AudienceKind, i as AudienceReading, j as AudienceUnknownReason, B as BrowserPage, k as BrowserScrollOptions, l as BrowserTransport, m as BrowserWaitOptions, n as Capability, o as CollectItem, a as CollectTask, p as ConnectorDeclaration, q as ConnectorDeclarationInput, r as ConnectorDefinition, s as ConnectorReport, t as CounterDeclaration, u as CoverageCell, F as FailureCause, v as FetchContext, w as FetchResult, x as FetchTransport, y as FetchedRaw, H as HttpRequest, z as HttpResponse, D as HttpTransport, I as ItemKind, E as ItemLinks, G as ItemPart, J as MissingReason, K as MissingSecretError, O as Observation, L as ObservationBase, P as Pace, N as ParseInput, Q as ParseResult, T as ParsedItem, U as ParsedObservation, V as ParsedPickup, W as Pickup, X as PickupBase, Y as PickupKind, Z as PickupMethod, _ as RecipeSource, $ as RunReport, a0 as SampledReport, a1 as SessionCheck, S as Subject, a2 as TransportError, a3 as TransportErrorCause, a4 as TransportErrorOptions, a5 as TransportName, a6 as TransportNameSchema, a7 as TransportSet, a8 as VERIFIED_PICKUP_METHODS, a9 as createConnectorRegistry, aa as defineConnector, ab as getConnector, ac as listConnectors, ad as registerConnector } from './connector-DUNy3vSU.js';
|
|
3
|
+
import { C as CollectStore, S as SamplingRecord } from './engine-BRXHKg5A.js';
|
|
4
|
+
export { a as Clock, b as CollectRunError, c as Collector, d as CollectorOptions, E as EventRecord, P as PlanEntry, e as PutRawInput, f as PutRawResult, R as RawIndexEntry, g as Reader, h as RunEvent, i as RunOptions, j as RunRecord, k as StoreLock, l as StoreLockedError, m as StoreVersionError, T as TaskRecord, n as TaskStatus, o as actorRedoKey, p as assertSafeName, q as createCollector, r as dropRedone, s as itemSeenKeys, t as lastWins, u as makeReader, v as monthOf, w as observationRedoKey, x as parseRawRef, y as pickupRedoKey, z as rawRef, A as readAll, B as recipeHash, D as seenKey, F as sha256Bytes, G as sourceOf, H as stableStringify } from './engine-BRXHKg5A.js';
|
|
5
|
+
import 'zod';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Stable ids, URL canonicalisation and text fingerprints.
|
|
9
|
+
*
|
|
10
|
+
* Hashing uses Web Crypto (`crypto.subtle`, async), which exists in Node 20+,
|
|
11
|
+
* browsers and edge runtimes. No Node built-in is imported.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Clean an http(s) URL into a dedup key: lowercase scheme and host (the path
|
|
15
|
+
* keeps its case), no credentials, no fragment, no default port, tracking
|
|
16
|
+
* parameters removed, remaining parameters ordered by key only (the relative
|
|
17
|
+
* order of a repeated key is kept, so `?a=2&a=1` differs from `?a=1&a=2`), no
|
|
18
|
+
* trailing slash (root included, so `/a/` and `/a` are the same key, and
|
|
19
|
+
* `https://example.com/?a=1` becomes `https://example.com?a=1`).
|
|
20
|
+
*
|
|
21
|
+
* The result is only a key for deduplication: the original URL is always
|
|
22
|
+
* kept next to it. Callers pass the final URL; redirects are not followed
|
|
23
|
+
* here, so a known redirect target must be resolved before calling.
|
|
24
|
+
*
|
|
25
|
+
* Any non-http(s) scheme (`mailto:`, `urn:`, `data:`, ...) and any input that
|
|
26
|
+
* is not an absolute URL is returned trimmed and otherwise unchanged.
|
|
27
|
+
*/
|
|
28
|
+
declare function canonicalUrl(input: string): string;
|
|
29
|
+
/** SHA-256 of a UTF-8 string, lowercase hex. */
|
|
30
|
+
declare function sha256Hex(text: string): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Id of an item that has a platform id: `source:nativeId`. Strings are used
|
|
33
|
+
* as given; a number must be a safe integer (larger ids lose digits, so pass
|
|
34
|
+
* them as strings) or this throws.
|
|
35
|
+
*/
|
|
36
|
+
declare function itemId(source: string, nativeId: string | number): string;
|
|
37
|
+
/** Id of an item without a platform id: `source:` plus a hash of its canonical URL. */
|
|
38
|
+
declare function itemIdFromUrl(source: string, url: string): Promise<string>;
|
|
39
|
+
/** Text reduced to lowercase words separated by single spaces. */
|
|
40
|
+
declare function normalizeText(text: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Exact-content id: SHA-256 of the normalised text. Same words, same
|
|
43
|
+
* fingerprint. Text that normalises to nothing (empty, only punctuation or
|
|
44
|
+
* symbols) has no content id: returns `undefined`, so unrelated empty items
|
|
45
|
+
* never share one.
|
|
46
|
+
*/
|
|
47
|
+
declare function textFingerprint(text: string): Promise<string | undefined>;
|
|
48
|
+
|
|
49
|
+
/** In-memory store: same behaviour as the disk store, nothing persisted. */
|
|
50
|
+
declare function memoryStore(options?: {
|
|
51
|
+
now?: () => string;
|
|
52
|
+
}): CollectStore;
|
|
53
|
+
|
|
54
|
+
/** Version written to `collect.json` at a store root. Bump on any change to the stored shapes. */
|
|
55
|
+
declare const STORE_SCHEMA_VERSION = 1;
|
|
56
|
+
|
|
57
|
+
/** A `SecretsPort` that remembers every value it hands out, and can scrub them from text and JSON. */
|
|
58
|
+
interface SecretRecorder extends SecretsPort {
|
|
59
|
+
/** Text with every value seen so far (raw, percent-encoded, form-encoded, JSON-escaped) replaced by `[redacted]`. */
|
|
60
|
+
redact(text: string): string;
|
|
61
|
+
/** The same applied to every string inside a JSON-like value (keys included). Returns a copy. */
|
|
62
|
+
redactJson<T>(value: T): T;
|
|
63
|
+
}
|
|
64
|
+
declare function isSecretRecorder(port: SecretsPort | undefined): port is SecretRecorder;
|
|
65
|
+
/**
|
|
66
|
+
* Wrap a secrets port so every value it resolves during a run is added to a
|
|
67
|
+
* redaction set. Pass the recorder to the collector and to anything else that
|
|
68
|
+
* resolves secrets (an API transport), so they share one set.
|
|
69
|
+
*/
|
|
70
|
+
declare function recordSecrets(port: SecretsPort): SecretRecorder;
|
|
71
|
+
|
|
72
|
+
type SamplingConfig = NonNullable<Recipe["sampling"]>;
|
|
73
|
+
/** What the sampler needs to know about one candidate item. */
|
|
74
|
+
interface SamplingCandidate {
|
|
75
|
+
/** Stable item id. */
|
|
76
|
+
id: string;
|
|
77
|
+
kind?: string;
|
|
78
|
+
/** Metric values the parse returned for this item. */
|
|
79
|
+
metrics: Partial<Record<MetricName, number>>;
|
|
80
|
+
/** Canonical URL of the item. */
|
|
81
|
+
url?: string;
|
|
82
|
+
/** `links.target` of the item, when set. */
|
|
83
|
+
target?: string;
|
|
84
|
+
outboundLinks?: string[];
|
|
85
|
+
}
|
|
86
|
+
type SamplingDecision = Omit<SamplingRecord, "at" | "connector" | "taskId">;
|
|
87
|
+
/** Small seeded PRNG: the same seed always gives the same sequence in [0, 1). */
|
|
88
|
+
declare function mulberry32(seed: number): () => number;
|
|
89
|
+
/** Host of a URL, lower-cased, without a trailing DNS root dot and without a leading `www.`. No public-suffix list. */
|
|
90
|
+
declare function domainOf(url: string | undefined): string | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* The host a candidate counts against: for a submission, the host of the
|
|
93
|
+
* article it points to (`links.target` when it is a URL, else the first
|
|
94
|
+
* outbound link); otherwise, or when neither is a URL, the host of its own URL.
|
|
95
|
+
*/
|
|
96
|
+
declare function candidateDomain(c: SamplingCandidate): string | undefined;
|
|
97
|
+
interface SamplingPlan {
|
|
98
|
+
/** New decisions to persist, one per distinct candidate, in decision order. */
|
|
99
|
+
lines: SamplingDecision[];
|
|
100
|
+
/** Ids (representatives and their repeats or URL aliases) whose records must not be written. */
|
|
101
|
+
dropped: Set<string>;
|
|
102
|
+
}
|
|
103
|
+
interface Sampler {
|
|
104
|
+
/**
|
|
105
|
+
* Decide a batch without changing any counter. Candidates already decided
|
|
106
|
+
* (in this run or in the journal) reuse their decision and produce no line.
|
|
107
|
+
* `known` holds the ids of candidates whose item already exists: they are not
|
|
108
|
+
* sampled and use no budget. Repeats of an id, and candidates sharing a URL,
|
|
109
|
+
* form one group that gets one decision, taken on the member with the highest
|
|
110
|
+
* metric value (ties: smaller URL, then smaller id).
|
|
111
|
+
*/
|
|
112
|
+
plan(batchKey: string, candidates: SamplingCandidate[], known?: ReadonlySet<string>): SamplingPlan;
|
|
113
|
+
/** Take a plan's lines into the counters. Call it once they are persisted. */
|
|
114
|
+
apply(lines: SamplingDecision[]): void;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Counters live in the sampler and are rebuilt from `prior` (the lines of
|
|
118
|
+
* `sampling.jsonl`), so a resumed run takes the same decisions.
|
|
119
|
+
*/
|
|
120
|
+
declare function createSampler(config: SamplingConfig, primary: MetricName | undefined, prior: SamplingDecision[]): Sampler;
|
|
121
|
+
|
|
122
|
+
/** The connectors whose declared primary counters decide `withPrimaryMetric`. */
|
|
123
|
+
type CoverageConnectors = ConnectorRegistry | readonly Connector[];
|
|
124
|
+
/**
|
|
125
|
+
* Coverage of what a store holds: platform (item source) x format x language x
|
|
126
|
+
* subject. `withPrimaryMetric` uses the primary counter each connector
|
|
127
|
+
* declares (matched on the item source); a source with no connector, or one
|
|
128
|
+
* that declares no primary counter, never counts. An item with several
|
|
129
|
+
* subjects counts in each subject's cell, one with none in the `none` cell. Missing format or language reads `unknown`.
|
|
130
|
+
* Streams the store; memory is proportional to the number of items.
|
|
131
|
+
*/
|
|
132
|
+
declare function computeCoverage(store: CollectStore, connectors?: CoverageConnectors): Promise<Coverage>;
|
|
133
|
+
|
|
134
|
+
export { CollectStore, Connector, ConnectorRegistry, Coverage, type CoverageConnectors, MetricName, Recipe, STORE_SCHEMA_VERSION, type Sampler, type SamplingCandidate, type SamplingConfig, type SamplingDecision, SamplingRecord, type SecretRecorder, SecretsPort, candidateDomain, canonicalUrl, computeCoverage, createSampler, domainOf, isSecretRecorder, itemId, itemIdFromUrl, memoryStore, mulberry32, normalizeText, recordSecrets, sha256Hex, textFingerprint };
|