@opencraw/driver 0.0.0-stage → 0.2.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.
@@ -0,0 +1,354 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * The driver protocol's version, separate from the package's: a client pins a major and the driver refuses
4
+ * another. Additions (methods, optional fields) raise the minor; anything a client could break on, the major.
5
+ */
6
+ export declare const PROTOCOL_VERSION = "1.1.0";
7
+ export declare const initializeParamsSchema: z.ZodObject<{
8
+ clientName: z.ZodString;
9
+ clientVersion: z.ZodString;
10
+ protocolVersion: z.ZodString;
11
+ }, z.core.$strict>;
12
+ export type InitializeParams = z.infer<typeof initializeParamsSchema>;
13
+ export declare const initializeResultSchema: z.ZodObject<{
14
+ driverVersion: z.ZodString;
15
+ protocolVersion: z.ZodString;
16
+ methods: z.ZodArray<z.ZodString>;
17
+ }, z.core.$strict>;
18
+ export type InitializeResult = z.infer<typeof initializeResultSchema>;
19
+ export declare const validateParamsSchema: z.ZodObject<{
20
+ paths: z.ZodOptional<z.ZodArray<z.ZodString>>;
21
+ recipes: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
22
+ only: z.ZodOptional<z.ZodArray<z.ZodString>>;
23
+ }, z.core.$strict>;
24
+ export type ValidateParams = z.infer<typeof validateParamsSchema>;
25
+ export declare const validateResultSchema: z.ZodObject<{
26
+ ok: z.ZodBoolean;
27
+ inputs: z.ZodArray<z.ZodString>;
28
+ hooks: z.ZodArray<z.ZodString>;
29
+ issues: z.ZodArray<z.ZodObject<{
30
+ source: z.ZodOptional<z.ZodString>;
31
+ recipeId: z.ZodOptional<z.ZodString>;
32
+ path: z.ZodString;
33
+ message: z.ZodString;
34
+ }, z.core.$strict>>;
35
+ }, z.core.$strict>;
36
+ export type ValidateResult = z.infer<typeof validateResultSchema>;
37
+ export declare const runParamsSchema: z.ZodObject<{
38
+ accessConfig: z.ZodOptional<z.ZodString>;
39
+ access: z.ZodOptional<z.ZodString>;
40
+ accessPlugins: z.ZodOptional<z.ZodArray<z.ZodString>>;
41
+ paths: z.ZodOptional<z.ZodArray<z.ZodString>>;
42
+ recipes: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
43
+ only: z.ZodOptional<z.ZodArray<z.ZodString>>;
44
+ out: z.ZodOptional<z.ZodString>;
45
+ append: z.ZodOptional<z.ZodBoolean>;
46
+ resume: z.ZodOptional<z.ZodBoolean>;
47
+ dryRun: z.ZodOptional<z.ZodBoolean>;
48
+ parallel: z.ZodOptional<z.ZodNumber>;
49
+ browser: z.ZodOptional<z.ZodObject<{
50
+ headless: z.ZodOptional<z.ZodBoolean>;
51
+ executablePath: z.ZodOptional<z.ZodString>;
52
+ ignoreHTTPSErrors: z.ZodOptional<z.ZodBoolean>;
53
+ }, z.core.$strict>>;
54
+ hooks: z.ZodOptional<z.ZodArray<z.ZodString>>;
55
+ captchaSolvers: z.ZodOptional<z.ZodArray<z.ZodString>>;
56
+ }, z.core.$strict>;
57
+ export type RunParams = z.infer<typeof runParamsSchema>;
58
+ export declare const runResultSchema: z.ZodObject<{
59
+ runId: z.ZodString;
60
+ }, z.core.$strict>;
61
+ export type RunResult = z.infer<typeof runResultSchema>;
62
+ export declare const cancelParamsSchema: z.ZodObject<{
63
+ runId: z.ZodString;
64
+ }, z.core.$strict>;
65
+ export type CancelParams = z.infer<typeof cancelParamsSchema>;
66
+ export declare const cancelResultSchema: z.ZodObject<{
67
+ cancelled: z.ZodBoolean;
68
+ }, z.core.$strict>;
69
+ export type CancelResult = z.infer<typeof cancelResultSchema>;
70
+ export declare const probeParamsSchema: z.ZodObject<{
71
+ accessConfig: z.ZodOptional<z.ZodString>;
72
+ access: z.ZodOptional<z.ZodString>;
73
+ accessPlugins: z.ZodOptional<z.ZodArray<z.ZodString>>;
74
+ url: z.ZodString;
75
+ browser: z.ZodOptional<z.ZodBoolean>;
76
+ browserPath: z.ZodOptional<z.ZodString>;
77
+ insecureTls: z.ZodOptional<z.ZodBoolean>;
78
+ userAgent: z.ZodOptional<z.ZodString>;
79
+ }, z.core.$strict>;
80
+ export type ProbeParams = z.infer<typeof probeParamsSchema>;
81
+ /** What the page holds and how a recipe could reach it (`ProbeResult`); its shape is the probe's, versioned with it. */
82
+ export declare const probeResultSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
83
+ export declare const diffParamsSchema: z.ZodObject<{
84
+ previous: z.ZodString;
85
+ current: z.ZodString;
86
+ key: z.ZodOptional<z.ZodArray<z.ZodString>>;
87
+ ignore: z.ZodOptional<z.ZodArray<z.ZodString>>;
88
+ limit: z.ZodOptional<z.ZodNumber>;
89
+ }, z.core.$strict>;
90
+ export type DiffParams = z.infer<typeof diffParamsSchema>;
91
+ export declare const diffResultSchema: z.ZodObject<{
92
+ added: z.ZodNumber;
93
+ removed: z.ZodNumber;
94
+ changed: z.ZodNumber;
95
+ unchanged: z.ZodNumber;
96
+ shrunk: z.ZodOptional<z.ZodObject<{
97
+ previous: z.ZodNumber;
98
+ current: z.ZodNumber;
99
+ }, z.core.$strict>>;
100
+ summary: z.ZodArray<z.ZodString>;
101
+ changes: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
102
+ truncated: z.ZodBoolean;
103
+ }, z.core.$strict>;
104
+ export type DiffResult = z.infer<typeof diffResultSchema>;
105
+ export declare const exportParamsSchema: z.ZodObject<{
106
+ records: z.ZodString;
107
+ output: z.ZodString;
108
+ out: z.ZodString;
109
+ }, z.core.$strict>;
110
+ export type ExportParams = z.infer<typeof exportParamsSchema>;
111
+ export declare const exportResultSchema: z.ZodObject<{
112
+ written: z.ZodNumber;
113
+ location: z.ZodString;
114
+ }, z.core.$strict>;
115
+ export type ExportResult = z.infer<typeof exportResultSchema>;
116
+ export declare const shutdownResultSchema: z.ZodObject<{}, z.core.$strict>;
117
+ /** Every crawl event, as core reports it (`CrawlEvent`); its shape is core's, versioned with core. */
118
+ export declare const eventParamsSchema: z.ZodObject<{
119
+ runId: z.ZodString;
120
+ event: z.ZodRecord<z.ZodString, z.ZodUnknown>;
121
+ }, z.core.$strict>;
122
+ export type EventParams = z.infer<typeof eventParamsSchema>;
123
+ export declare const recordParamsSchema: z.ZodObject<{
124
+ runId: z.ZodString;
125
+ recipeId: z.ZodString;
126
+ key: z.ZodNullable<z.ZodString>;
127
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
128
+ }, z.core.$strict>;
129
+ export type RecordParams = z.infer<typeof recordParamsSchema>;
130
+ export declare const finishedParamsSchema: z.ZodObject<{
131
+ runId: z.ZodString;
132
+ report: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
133
+ error: z.ZodOptional<z.ZodString>;
134
+ }, z.core.$strict>;
135
+ export type FinishedParams = z.infer<typeof finishedParamsSchema>;
136
+ /** A hook, captcha solver or access plugin the client serves (`request.kind`): core's own callout request, answered with core's callout response. */
137
+ export declare const calloutParamsSchema: z.ZodObject<{
138
+ runId: z.ZodString;
139
+ request: z.ZodObject<{
140
+ kind: z.ZodEnum<{
141
+ access: "access";
142
+ captcha: "captcha";
143
+ hook: "hook";
144
+ }>;
145
+ name: z.ZodString;
146
+ input: z.ZodOptional<z.ZodUnknown>;
147
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
148
+ context: z.ZodObject<{
149
+ recipeId: z.ZodString;
150
+ scope: z.ZodRecord<z.ZodString, z.ZodUnknown>;
151
+ }, z.core.$strict>;
152
+ idempotencyKey: z.ZodString;
153
+ callback: z.ZodOptional<z.ZodObject<{
154
+ url: z.ZodString;
155
+ }, z.core.$strict>>;
156
+ }, z.core.$strict>;
157
+ }, z.core.$strict>;
158
+ export type CalloutParams = z.infer<typeof calloutParamsSchema>;
159
+ export declare const calloutResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
160
+ status: z.ZodLiteral<"ok">;
161
+ output: z.ZodOptional<z.ZodUnknown>;
162
+ }, z.core.$strict>, z.ZodObject<{
163
+ status: z.ZodLiteral<"error">;
164
+ error: z.ZodString;
165
+ }, z.core.$strict>, z.ZodObject<{
166
+ status: z.ZodLiteral<"pending">;
167
+ retryAfterMs: z.ZodOptional<z.ZodNumber>;
168
+ }, z.core.$strict>], "status">;
169
+ /** Every method and notification, by name: what the generated schema and the clients' models are made from. */
170
+ export declare const MESSAGES: {
171
+ readonly initialize: {
172
+ readonly direction: 'client-to-driver';
173
+ readonly params: z.ZodObject<{
174
+ clientName: z.ZodString;
175
+ clientVersion: z.ZodString;
176
+ protocolVersion: z.ZodString;
177
+ }, z.core.$strict>;
178
+ readonly result: z.ZodObject<{
179
+ driverVersion: z.ZodString;
180
+ protocolVersion: z.ZodString;
181
+ methods: z.ZodArray<z.ZodString>;
182
+ }, z.core.$strict>;
183
+ };
184
+ readonly validate: {
185
+ readonly direction: 'client-to-driver';
186
+ readonly params: z.ZodObject<{
187
+ paths: z.ZodOptional<z.ZodArray<z.ZodString>>;
188
+ recipes: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
189
+ only: z.ZodOptional<z.ZodArray<z.ZodString>>;
190
+ }, z.core.$strict>;
191
+ readonly result: z.ZodObject<{
192
+ ok: z.ZodBoolean;
193
+ inputs: z.ZodArray<z.ZodString>;
194
+ hooks: z.ZodArray<z.ZodString>;
195
+ issues: z.ZodArray<z.ZodObject<{
196
+ source: z.ZodOptional<z.ZodString>;
197
+ recipeId: z.ZodOptional<z.ZodString>;
198
+ path: z.ZodString;
199
+ message: z.ZodString;
200
+ }, z.core.$strict>>;
201
+ }, z.core.$strict>;
202
+ };
203
+ readonly run: {
204
+ readonly direction: 'client-to-driver';
205
+ readonly params: z.ZodObject<{
206
+ accessConfig: z.ZodOptional<z.ZodString>;
207
+ access: z.ZodOptional<z.ZodString>;
208
+ accessPlugins: z.ZodOptional<z.ZodArray<z.ZodString>>;
209
+ paths: z.ZodOptional<z.ZodArray<z.ZodString>>;
210
+ recipes: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
211
+ only: z.ZodOptional<z.ZodArray<z.ZodString>>;
212
+ out: z.ZodOptional<z.ZodString>;
213
+ append: z.ZodOptional<z.ZodBoolean>;
214
+ resume: z.ZodOptional<z.ZodBoolean>;
215
+ dryRun: z.ZodOptional<z.ZodBoolean>;
216
+ parallel: z.ZodOptional<z.ZodNumber>;
217
+ browser: z.ZodOptional<z.ZodObject<{
218
+ headless: z.ZodOptional<z.ZodBoolean>;
219
+ executablePath: z.ZodOptional<z.ZodString>;
220
+ ignoreHTTPSErrors: z.ZodOptional<z.ZodBoolean>;
221
+ }, z.core.$strict>>;
222
+ hooks: z.ZodOptional<z.ZodArray<z.ZodString>>;
223
+ captchaSolvers: z.ZodOptional<z.ZodArray<z.ZodString>>;
224
+ }, z.core.$strict>;
225
+ readonly result: z.ZodObject<{
226
+ runId: z.ZodString;
227
+ }, z.core.$strict>;
228
+ };
229
+ readonly cancel: {
230
+ readonly direction: 'client-to-driver';
231
+ readonly params: z.ZodObject<{
232
+ runId: z.ZodString;
233
+ }, z.core.$strict>;
234
+ readonly result: z.ZodObject<{
235
+ cancelled: z.ZodBoolean;
236
+ }, z.core.$strict>;
237
+ };
238
+ readonly probe: {
239
+ readonly direction: 'client-to-driver';
240
+ readonly params: z.ZodObject<{
241
+ accessConfig: z.ZodOptional<z.ZodString>;
242
+ access: z.ZodOptional<z.ZodString>;
243
+ accessPlugins: z.ZodOptional<z.ZodArray<z.ZodString>>;
244
+ url: z.ZodString;
245
+ browser: z.ZodOptional<z.ZodBoolean>;
246
+ browserPath: z.ZodOptional<z.ZodString>;
247
+ insecureTls: z.ZodOptional<z.ZodBoolean>;
248
+ userAgent: z.ZodOptional<z.ZodString>;
249
+ }, z.core.$strict>;
250
+ readonly result: z.ZodRecord<z.ZodString, z.ZodUnknown>;
251
+ };
252
+ readonly diff: {
253
+ readonly direction: 'client-to-driver';
254
+ readonly params: z.ZodObject<{
255
+ previous: z.ZodString;
256
+ current: z.ZodString;
257
+ key: z.ZodOptional<z.ZodArray<z.ZodString>>;
258
+ ignore: z.ZodOptional<z.ZodArray<z.ZodString>>;
259
+ limit: z.ZodOptional<z.ZodNumber>;
260
+ }, z.core.$strict>;
261
+ readonly result: z.ZodObject<{
262
+ added: z.ZodNumber;
263
+ removed: z.ZodNumber;
264
+ changed: z.ZodNumber;
265
+ unchanged: z.ZodNumber;
266
+ shrunk: z.ZodOptional<z.ZodObject<{
267
+ previous: z.ZodNumber;
268
+ current: z.ZodNumber;
269
+ }, z.core.$strict>>;
270
+ summary: z.ZodArray<z.ZodString>;
271
+ changes: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
272
+ truncated: z.ZodBoolean;
273
+ }, z.core.$strict>;
274
+ };
275
+ readonly export: {
276
+ readonly direction: 'client-to-driver';
277
+ readonly params: z.ZodObject<{
278
+ records: z.ZodString;
279
+ output: z.ZodString;
280
+ out: z.ZodString;
281
+ }, z.core.$strict>;
282
+ readonly result: z.ZodObject<{
283
+ written: z.ZodNumber;
284
+ location: z.ZodString;
285
+ }, z.core.$strict>;
286
+ };
287
+ readonly shutdown: {
288
+ readonly direction: 'client-to-driver';
289
+ readonly params: undefined;
290
+ readonly result: z.ZodObject<{}, z.core.$strict>;
291
+ };
292
+ readonly callout: {
293
+ readonly direction: 'driver-to-client';
294
+ readonly params: z.ZodObject<{
295
+ runId: z.ZodString;
296
+ request: z.ZodObject<{
297
+ kind: z.ZodEnum<{
298
+ access: "access";
299
+ captcha: "captcha";
300
+ hook: "hook";
301
+ }>;
302
+ name: z.ZodString;
303
+ input: z.ZodOptional<z.ZodUnknown>;
304
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
305
+ context: z.ZodObject<{
306
+ recipeId: z.ZodString;
307
+ scope: z.ZodRecord<z.ZodString, z.ZodUnknown>;
308
+ }, z.core.$strict>;
309
+ idempotencyKey: z.ZodString;
310
+ callback: z.ZodOptional<z.ZodObject<{
311
+ url: z.ZodString;
312
+ }, z.core.$strict>>;
313
+ }, z.core.$strict>;
314
+ }, z.core.$strict>;
315
+ readonly result: z.ZodDiscriminatedUnion<[z.ZodObject<{
316
+ status: z.ZodLiteral<"ok">;
317
+ output: z.ZodOptional<z.ZodUnknown>;
318
+ }, z.core.$strict>, z.ZodObject<{
319
+ status: z.ZodLiteral<"error">;
320
+ error: z.ZodString;
321
+ }, z.core.$strict>, z.ZodObject<{
322
+ status: z.ZodLiteral<"pending">;
323
+ retryAfterMs: z.ZodOptional<z.ZodNumber>;
324
+ }, z.core.$strict>], "status">;
325
+ };
326
+ readonly event: {
327
+ readonly direction: 'driver-to-client';
328
+ readonly params: z.ZodObject<{
329
+ runId: z.ZodString;
330
+ event: z.ZodRecord<z.ZodString, z.ZodUnknown>;
331
+ }, z.core.$strict>;
332
+ readonly result: undefined;
333
+ };
334
+ readonly record: {
335
+ readonly direction: 'driver-to-client';
336
+ readonly params: z.ZodObject<{
337
+ runId: z.ZodString;
338
+ recipeId: z.ZodString;
339
+ key: z.ZodNullable<z.ZodString>;
340
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
341
+ }, z.core.$strict>;
342
+ readonly result: undefined;
343
+ };
344
+ readonly finished: {
345
+ readonly direction: 'driver-to-client';
346
+ readonly params: z.ZodObject<{
347
+ runId: z.ZodString;
348
+ report: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
349
+ error: z.ZodOptional<z.ZodString>;
350
+ }, z.core.$strict>;
351
+ readonly result: undefined;
352
+ };
353
+ };
354
+ //# sourceMappingURL=driver-message.contract.d.ts.map
@@ -0,0 +1,4 @@
1
+ export { PROTOCOL_VERSION, MESSAGES, initializeParamsSchema, initializeResultSchema, validateParamsSchema, validateResultSchema, runParamsSchema, runResultSchema, cancelParamsSchema, cancelResultSchema, shutdownResultSchema, eventParamsSchema, recordParamsSchema, finishedParamsSchema, calloutParamsSchema, calloutResultSchema, probeParamsSchema, probeResultSchema, diffParamsSchema, diffResultSchema, exportParamsSchema, exportResultSchema, } from './driver-message.contract.js';
2
+ export type { InitializeParams, InitializeResult, ValidateParams, ValidateResult, RunParams, RunResult, CancelParams, CancelResult, EventParams, RecordParams, FinishedParams, CalloutParams, ProbeParams, DiffParams, DiffResult, ExportParams, ExportResult, } from './driver-message.contract.js';
3
+ export { driverProtocolJsonSchema } from './driver-json-schema.mapper.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,10 @@
1
+ import type { DiffParams, DiffResult } from '../protocol/index.js';
2
+ /**
3
+ * Compares two runs' JSON Lines files by key: how many records were added, removed, changed and left
4
+ * alone, the report a person reads, and the changes themselves, up to `limit`.
5
+ *
6
+ * @param params - The two files, the key fields, the fields to ignore and the limit.
7
+ * @returns The comparison.
8
+ */
9
+ export declare function diffRecordFiles(params: DiffParams): Promise<DiffResult>;
10
+ //# sourceMappingURL=diff-record-files.use-case.d.ts.map
@@ -0,0 +1,11 @@
1
+ import type { ExportParams, ExportResult } from '../protocol/index.js';
2
+ /**
3
+ * Writes a finished run's JSON Lines file again in another format, the extension of `out` naming it, as
4
+ * the CLI's `export` does. The output recipe gives the columns: its fields, in order, with their types.
5
+ *
6
+ * @param params - The records, the output recipe and the file to write.
7
+ * @returns How many records were written, and where.
8
+ * @throws RecipeValidationError When `output` is not an output recipe.
9
+ */
10
+ export declare function exportRecordFiles(params: ExportParams): Promise<ExportResult>;
11
+ //# sourceMappingURL=export-record-files.use-case.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { diffRecordFiles } from './diff-record-files.use-case.js';
2
+ export { exportRecordFiles } from './export-record-files.use-case.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { serveDriver } from './serve-driver.use-case.js';
2
+ export type { DriverIdentity } from './serve-driver.use-case.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,17 @@
1
+ import type { Readable, Writable } from 'node:stream';
2
+ /** What the driver says about itself in `initialize`. */
3
+ export interface DriverIdentity {
4
+ driverVersion: string;
5
+ }
6
+ /**
7
+ * Serves the driver protocol on a stream pair until the client closes its end or asks for `shutdown`.
8
+ * Every method but `initialize` is refused until the client has initialized with a protocol of the same
9
+ * major. On close, every run still going is closed.
10
+ *
11
+ * @param input - Where the client's messages arrive (stdin).
12
+ * @param output - Where the driver's go (stdout). Nothing else may write to it.
13
+ * @param identity - The driver's version, for `initialize`.
14
+ * @returns Settles once the driver has stopped.
15
+ */
16
+ export declare function serveDriver(input: Readable, output: Writable, identity: DriverIdentity): Promise<void>;
17
+ //# sourceMappingURL=serve-driver.use-case.d.ts.map
@@ -0,0 +1,5 @@
1
+ export { runSessions } from './run-session.use-case.js';
2
+ export type { NotifyClient, RunSessions } from './run-session.use-case.js';
3
+ export { validateRecipes, hooksOf, loadRecipes, sourceOf } from './recipe-loading.use-case.js';
4
+ export { streamingSink } from './streaming-sink.repository.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,23 @@
1
+ import type { RecipeSet, RecipeSource } from '@opencraw/core';
2
+ import type { ValidateParams, ValidateResult } from '../protocol/index.js';
3
+ /** The recipes a method names: files and folders, or the recipes themselves. Exactly one of the two. */
4
+ export declare function sourceOf(params: {
5
+ paths?: string[];
6
+ recipes?: Record<string, unknown>[];
7
+ }): RecipeSource;
8
+ /** Loads and binds a method's recipes, keeping the input ids in `only`. */
9
+ export declare function loadRecipes(params: {
10
+ paths?: string[];
11
+ recipes?: Record<string, unknown>[];
12
+ only?: string[];
13
+ }): Promise<RecipeSet>;
14
+ /** Every hook the set's input recipes call, once each, sorted. */
15
+ export declare function hooksOf(set: RecipeSet): string[];
16
+ /**
17
+ * Checks recipes the way `run` would load them, without running them.
18
+ *
19
+ * @param params - The recipes and the input ids to keep.
20
+ * @returns Whether they load, the inputs and hooks a run would have, and every problem with its path.
21
+ */
22
+ export declare function validateRecipes(params: ValidateParams): Promise<ValidateResult>;
23
+ //# sourceMappingURL=recipe-loading.use-case.d.ts.map
@@ -0,0 +1,24 @@
1
+ import type { AskClient } from '../callout-bridge/index.js';
2
+ import type { RunParams } from '../protocol/index.js';
3
+ /** Sends a notification to the client. */
4
+ export type NotifyClient = (method: string, params: unknown) => void;
5
+ /** The runs a driver has going, by id, so `cancel` can reach them and `shutdown` close them all. */
6
+ export interface RunSessions {
7
+ start: (params: RunParams) => Promise<string>;
8
+ cancel: (runId: string) => Promise<boolean>;
9
+ closeAll: () => Promise<void>;
10
+ }
11
+ /**
12
+ * Starts and tracks runs. `start` loads and binds the recipes (a bad recipe fails the `run` request
13
+ * itself, with its problems), answers with a run id at once, and crawls in the background: every crawl
14
+ * event goes to the client as an `event` notification, every record as a `record` one unless `out`
15
+ * names a file, and the end as `finished` with the report. A hook the client serves is asked back with
16
+ * a `callout` request, and so are the captcha solvers and access plugins it serves. `cancel` closes the run's crawler, which stops its recipes; the run still ends
17
+ * with `finished`.
18
+ *
19
+ * @param notify - The channel's notify.
20
+ * @param ask - The channel's request, for callouts.
21
+ * @returns The sessions.
22
+ */
23
+ export declare function runSessions(notify: NotifyClient, ask: AskClient): RunSessions;
24
+ //# sourceMappingURL=run-session.use-case.d.ts.map
@@ -0,0 +1,8 @@
1
+ import type { RecordSink } from '@opencraw/core';
2
+ /**
3
+ * The sink of a run with no `out` file: it keeps nothing, since each record already reached the client
4
+ * as a `record` notification from its `record:emit` event, and only counts them for the report. A long
5
+ * crawl therefore streams in constant memory.
6
+ */
7
+ export declare function streamingSink(): RecordSink;
8
+ //# sourceMappingURL=streaming-sink.repository.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { resolveSiteAccess } from './resolve-site-access.use-case.js';
2
+ export type { SiteAccess, SiteAccessParams } from './resolve-site-access.use-case.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,26 @@
1
+ import type { AccessConfig, AccessPlugin } from '@opencraw/core';
2
+ import type { AskClient } from '../callout-bridge/index.js';
3
+ /** What a run or a probe asks of access: the config file, the profile, and the plugins the client serves. */
4
+ export interface SiteAccessParams {
5
+ accessConfig?: string;
6
+ access?: string;
7
+ accessPlugins?: string[];
8
+ }
9
+ /** How a run or a probe reaches sites. */
10
+ export interface SiteAccess {
11
+ access?: AccessConfig;
12
+ accessPlugins: AccessPlugin[];
13
+ }
14
+ /**
15
+ * Loads the access config (the file the client names, else `OPENCRAW_ACCESS`), with `access` as its
16
+ * default profile, and builds a plugin for each one the client serves.
17
+ *
18
+ * @param params - The method's access fields.
19
+ * @param runId - The run, or the probe, the plugins' callouts belong to.
20
+ * @param ask - The channel's request.
21
+ * @param env - Where `OPENCRAW_ACCESS` is read.
22
+ * @returns The config and the plugins.
23
+ * @throws Error When a profile is named without a config, or the config has no such profile.
24
+ */
25
+ export declare function resolveSiteAccess(params: SiteAccessParams, runId: string, ask: AskClient, env?: NodeJS.ProcessEnv): Promise<SiteAccess>;
26
+ //# sourceMappingURL=resolve-site-access.use-case.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { probeSite } from './probe-site.use-case.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,13 @@
1
+ import type { AskClient } from '../callout-bridge/index.js';
2
+ import type { ProbeParams } from '../protocol/index.js';
3
+ /**
4
+ * Fetches a page, or renders it with `browser`, and says where its data lives: the probe the CLI and the
5
+ * MCP server use, through the access the client names (its plugins served by the client).
6
+ *
7
+ * @param params - The page and how to reach it.
8
+ * @param probeId - What the plugins' callouts carry as their `runId`.
9
+ * @param ask - The channel's request.
10
+ * @returns The probe's findings.
11
+ */
12
+ export declare function probeSite(params: ProbeParams, probeId: string, ask: AskClient): Promise<Record<string, unknown>>;
13
+ //# sourceMappingURL=probe-site.use-case.d.ts.map
@@ -0,0 +1,5 @@
1
+ export { openLineChannel } from './line-channel.client.js';
2
+ export type { LineChannel, RequestHandler } from './line-channel.client.js';
3
+ export { RPC_ERRORS, RpcFailure } from './json-rpc.contract.js';
4
+ export type { RpcError, RpcMessage } from './json-rpc.contract.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,31 @@
1
+ /** JSON-RPC 2.0 error codes the driver answers with. */
2
+ export declare const RPC_ERRORS: {
3
+ readonly parse: -32700;
4
+ readonly invalidRequest: -32600;
5
+ readonly methodNotFound: -32601;
6
+ readonly invalidParams: -32602;
7
+ readonly internal: -32603;
8
+ /** A failure the caller must act on: the message says what to do. */
9
+ readonly server: -32000;
10
+ };
11
+ export interface RpcError {
12
+ code: number;
13
+ message: string;
14
+ data?: unknown;
15
+ }
16
+ /** A request (it has an id and wants a response) or a notification (no id). */
17
+ export interface RpcMessage {
18
+ jsonrpc: '2.0';
19
+ id?: number | string | null;
20
+ method?: string;
21
+ params?: unknown;
22
+ result?: unknown;
23
+ error?: RpcError;
24
+ }
25
+ /** An error a method handler throws to answer with a code other than `server`. */
26
+ export declare class RpcFailure extends Error {
27
+ readonly code: number;
28
+ readonly data: unknown;
29
+ constructor(code: number, message: string, data?: unknown);
30
+ }
31
+ //# sourceMappingURL=json-rpc.contract.d.ts.map
@@ -0,0 +1,27 @@
1
+ import type { Readable, Writable } from 'node:stream';
2
+ /** Answers a request: its result, or a thrown error (an `RpcFailure` for a specific code). */
3
+ export type RequestHandler = (method: string, params: unknown) => Promise<unknown>;
4
+ /** JSON-RPC 2.0 both ways over a stream pair, one message per line. */
5
+ export interface LineChannel {
6
+ /** Sends a request to the other side and waits for its result; rejects with its error. */
7
+ request: (method: string, params: unknown) => Promise<unknown>;
8
+ /** Sends a notification: no answer is expected. */
9
+ notify: (method: string, params: unknown) => void;
10
+ /** Settles when the input ends (the other side closed it, or went away). */
11
+ closed: Promise<void>;
12
+ /** Settles once every request read so far has been answered: what to wait for before stopping. */
13
+ drained: () => Promise<void>;
14
+ }
15
+ /**
16
+ * Opens a channel: every line read from `input` is a JSON-RPC message. A request goes to `handle` and its
17
+ * answer is written back; a response settles the matching `request`. A line that is not JSON gets a parse
18
+ * error, a message without `jsonrpc: "2.0"` an invalid-request error, and nothing it does stops the channel.
19
+ * Writes are one line each, never interleaved.
20
+ *
21
+ * @param input - Where messages arrive (the driver's stdin).
22
+ * @param output - Where they go (the driver's stdout).
23
+ * @param handle - What answers the other side's requests and notifications.
24
+ * @returns The channel.
25
+ */
26
+ export declare function openLineChannel(input: Readable, output: Writable, handle: RequestHandler): LineChannel;
27
+ //# sourceMappingURL=line-channel.client.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@opencraw/driver",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "OpenCraw's driver: the engine over JSON-RPC on stdio, for clients in other languages",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "smith": {
8
+ "kind": "package",
9
+ "stack": "node-vitest"
10
+ },
11
+ "main": "./dist/index.esm.js",
12
+ "module": "./dist/index.esm.js",
13
+ "types": "./dist/src/index.d.ts",
14
+ "exports": {
15
+ "./package.json": "./package.json",
16
+ ".": {
17
+ "types": "./dist/src/index.d.ts",
18
+ "import": "./dist/index.esm.js",
19
+ "default": "./dist/index.esm.js"
20
+ }
21
+ },
22
+ "bin": {
23
+ "opencraw-driver": "./dist/main.esm.js"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "schemas",
28
+ "!**/*.tsbuildinfo",
29
+ "!**/*.d.ts.map",
30
+ "!**/*.js.map"
31
+ ],
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "scripts": {
36
+ "build": "esbuild src/index.ts src/main.ts --bundle --packages=external --platform=node --format=esm --outdir=dist --out-extension:.js=.esm.js --sourcemap && tsc -p tsconfig.build.json && node ../../declaration-specifiers.mjs dist/src",
37
+ "typecheck": "tsc -p tsconfig.json",
38
+ "lint": "eslint .",
39
+ "test": "vitest run",
40
+ "schemas": "node tools/emit-protocol-schema.mjs"
41
+ },
42
+ "dependencies": {
43
+ "@opencraw/cli": "^0.1.56",
44
+ "@opencraw/core": "^0.3.0",
45
+ "zod": "^4.6.5"
46
+ }
47
+ }