@parcha/pi-browser 0.0.0-bootstrap.0 → 0.1.0-beta.13
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/CHANGELOG.md +16 -0
- package/LICENSE +202 -0
- package/NOTICE +33 -0
- package/README.md +328 -1
- package/dist/coding-agent-local.d.ts +16 -0
- package/dist/coding-agent-local.js +138 -0
- package/dist/coding-agent.d.ts +78 -0
- package/dist/coding-agent.js +446 -0
- package/dist/core/contract.d.ts +26 -0
- package/dist/core/contract.js +154 -0
- package/dist/core/custody.d.ts +111 -0
- package/dist/core/custody.js +122 -0
- package/dist/core/decisions.d.ts +43 -0
- package/dist/core/decisions.js +4 -0
- package/dist/core/downloads.d.ts +35 -0
- package/dist/core/downloads.js +131 -0
- package/dist/core/effects.d.ts +63 -0
- package/dist/core/effects.js +256 -0
- package/dist/core/evidence.d.ts +43 -0
- package/dist/core/evidence.js +6 -0
- package/dist/core/failures.d.ts +28 -0
- package/dist/core/failures.js +59 -0
- package/dist/core/find.d.ts +32 -0
- package/dist/core/find.js +179 -0
- package/dist/core/guard.d.ts +6 -0
- package/dist/core/guard.js +24 -0
- package/dist/core/host.d.ts +279 -0
- package/dist/core/host.js +2 -0
- package/dist/core/images.d.ts +37 -0
- package/dist/core/images.js +60 -0
- package/dist/core/lease.d.ts +16 -0
- package/dist/core/lease.js +30 -0
- package/dist/core/receipts.d.ts +19 -0
- package/dist/core/receipts.js +22 -0
- package/dist/core/redact.d.ts +13 -0
- package/dist/core/redact.js +83 -0
- package/dist/core/session-control.d.ts +25 -0
- package/dist/core/session-control.js +75 -0
- package/dist/core/sites.d.ts +33 -0
- package/dist/core/sites.js +102 -0
- package/dist/core/tools.d.ts +37 -0
- package/dist/core/tools.js +170 -0
- package/dist/core/uri.d.ts +11 -0
- package/dist/core/uri.js +37 -0
- package/dist/core/usage.d.ts +38 -0
- package/dist/core/usage.js +44 -0
- package/dist/core/web.d.ts +98 -0
- package/dist/core/web.js +327 -0
- package/dist/driver/stagehand.d.ts +25 -0
- package/dist/driver/stagehand.js +141 -0
- package/dist/durable-result.d.ts +6 -0
- package/dist/durable-result.js +2 -0
- package/dist/durable.d.ts +75 -0
- package/dist/durable.js +484 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +19 -0
- package/dist/providers/browserbase-net.d.ts +13 -0
- package/dist/providers/browserbase-net.js +96 -0
- package/dist/providers/browserbase.d.ts +152 -0
- package/dist/providers/browserbase.js +262 -0
- package/dist/providers/cdp-call.d.ts +6 -0
- package/dist/providers/cdp-call.js +25 -0
- package/dist/providers/cdp.d.ts +48 -0
- package/dist/providers/cdp.js +353 -0
- package/dist/providers/http.d.ts +2 -0
- package/dist/providers/http.js +21 -0
- package/dist/providers/kernel.d.ts +49 -0
- package/dist/providers/kernel.js +246 -0
- package/dist/providers/shared.d.ts +47 -0
- package/dist/providers/shared.js +82 -0
- package/dist/recorder/credential.d.ts +9 -0
- package/dist/recorder/credential.js +49 -0
- package/dist/recorder/follow.d.ts +26 -0
- package/dist/recorder/follow.js +138 -0
- package/dist/recorder/frames.d.ts +80 -0
- package/dist/recorder/frames.js +309 -0
- package/dist/recorder/index.d.ts +3 -0
- package/dist/recorder/index.js +6 -0
- package/dist/recorder/jpeg.d.ts +5 -0
- package/dist/recorder/jpeg.js +34 -0
- package/dist/store.d.ts +56 -0
- package/dist/store.js +196 -0
- package/dist/testing/backend.d.ts +231 -0
- package/dist/testing/backend.js +414 -0
- package/dist/testing/driver.d.ts +28 -0
- package/dist/testing/driver.js +32 -0
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.js +4 -0
- package/dist/testing/pages.d.ts +3 -0
- package/dist/testing/pages.js +10 -0
- package/dist/testing/sentinels.d.ts +29 -0
- package/dist/testing/sentinels.js +38 -0
- package/dist/vendor/stagehand-facade/contract.d.ts +348 -0
- package/dist/vendor/stagehand-facade/contract.js +155 -0
- package/dist/vendor/stagehand-facade/runtime.d.ts +90 -0
- package/dist/vendor/stagehand-facade/runtime.js +1640 -0
- package/dist/vendor/stagehand-facade/screenshot-transport.d.ts +15 -0
- package/dist/vendor/stagehand-facade/screenshot-transport.js +51 -0
- package/dist/vendor/stagehand-facade/tools.d.ts +31 -0
- package/dist/vendor/stagehand-facade/tools.js +139 -0
- package/dist/web.d.ts +41 -0
- package/dist/web.js +38 -0
- package/package.json +125 -1
- package/src/vendor/stagehand-facade/UPSTREAM.json +24 -0
package/dist/store.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { defineDoc, defineTask } from "@earendil-works/pi-durable";
|
|
2
|
+
import { moveRecord, notices } from "./core/custody.js";
|
|
3
|
+
export const now = () => new Date().toISOString();
|
|
4
|
+
const iso = (ms) => new Date(ms).toISOString();
|
|
5
|
+
const cidOf = (row) => row.conversationId;
|
|
6
|
+
/** Release attempts before custody is given up as `lost`, and status polls before a release is sent again. */
|
|
7
|
+
export const RELEASE_ATTEMPTS = 6;
|
|
8
|
+
export const CONFIRM_POLLS = 5;
|
|
9
|
+
const backoffMs = (n) => Math.min(30_000, 500 * 2 ** n);
|
|
10
|
+
export function custodyStore({ name, Config, Sessions, providerOf, emit, meter, scrubbed, createDeadlineMs }) {
|
|
11
|
+
const Inventory = defineDoc({ kind: `${name}.inventory`, version: 1, scope: "session", initial: () => ({ rows: {} }) });
|
|
12
|
+
/** One state change: the record and the open-session inventory move in the same commit. */
|
|
13
|
+
async function move(tx, row, next) {
|
|
14
|
+
const inventory = await tx.doc(Inventory);
|
|
15
|
+
// A lost one stays: custody gave up releasing it, not looking for it (reconcile releases it again at run open).
|
|
16
|
+
if (next.state === "released")
|
|
17
|
+
delete inventory.rows[row.tag];
|
|
18
|
+
else
|
|
19
|
+
inventory.rows[row.tag] = { ...row, state: next.state, resourceId: next.resourceId ?? row.resourceId };
|
|
20
|
+
const state = await tx.doc(Sessions, cidOf(row));
|
|
21
|
+
const record = state.sessions.find((r) => r.tag === row.tag);
|
|
22
|
+
if (!record)
|
|
23
|
+
return;
|
|
24
|
+
moveRecord(record, next);
|
|
25
|
+
if (next.state === "released" && record.resourceId !== null)
|
|
26
|
+
record.spent = meter(record.spent, next.at, true).spent;
|
|
27
|
+
if (next.notice) {
|
|
28
|
+
for (const stale of [notices.kept(record.lastUrl), notices.lost(record.lastUrl)])
|
|
29
|
+
state.notice = state.notice?.replace(stale, "").replace(/\s+/g, " ").trim() || null;
|
|
30
|
+
addNotice(state, notices[next.notice](record.lastUrl));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** A later notice never erases one not yet told, and the same one is never added twice (a second restart before any
|
|
34
|
+
* call). */
|
|
35
|
+
const addNotice = (state, text) => { if (!state.notice?.includes(text))
|
|
36
|
+
state.notice = [state.notice, text].filter(Boolean).join(" "); };
|
|
37
|
+
const begin = async (tx, row) => { (await tx.doc(Inventory)).rows[row.tag] = { ...row, state: "creating", resourceId: null }; };
|
|
38
|
+
async function requestRelease(tx, row, reason, at, notBefore) {
|
|
39
|
+
await move(tx, row, { state: "releasing", reason, at });
|
|
40
|
+
await tx.createTask(ReleaseTask, { row: { ...row, state: "releasing" }, ...(notBefore ? { notBefore } : {}) }, { ownership: { kind: "conversation" }, conversationId: cidOf(row), background: true });
|
|
41
|
+
}
|
|
42
|
+
/** A create no tag lookup finds may still land (a crashed or fenced holder's call in flight): the release task looks
|
|
43
|
+
* again by tag after the create deadline and releases whatever landed. */
|
|
44
|
+
const unknownCreate = (tx, row, at) => requestRelease(tx, row, "create_failed", at, Date.now() + createDeadlineMs);
|
|
45
|
+
async function releaseAll(row, provider, signal) {
|
|
46
|
+
const ids = [...new Set([row.resourceId, ...(await provider.findByTag(row.tag, signal)).map((ref) => ref.id)].filter((id) => id !== null))];
|
|
47
|
+
for (const id of ids)
|
|
48
|
+
await provider.release({ id, tag: row.tag }, signal);
|
|
49
|
+
return ids;
|
|
50
|
+
}
|
|
51
|
+
const anyRunning = async (provider, row, ids, signal) => {
|
|
52
|
+
for (const id of ids)
|
|
53
|
+
if (["pending", "running"].includes(await provider.status({ id, tag: row.tag }, signal)))
|
|
54
|
+
return true;
|
|
55
|
+
return false;
|
|
56
|
+
};
|
|
57
|
+
const releasedAll = async (provider, row, signal) => !(await anyRunning(provider, row, await releaseAll(row, provider, signal), signal));
|
|
58
|
+
/** Its error goes to the host's report, scrubbed, and `fallback` stands in; an abort is rethrown. */
|
|
59
|
+
async function step(runtime, run, fallback) {
|
|
60
|
+
try {
|
|
61
|
+
return await run();
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
if (runtime.signal.aborted)
|
|
65
|
+
throw error;
|
|
66
|
+
runtime.report(scrubbed(error));
|
|
67
|
+
return fallback;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** A create whose answer never came, settled by its tag: the first session found is kept and committed `live`; extras
|
|
71
|
+
* (a create retried behind the provider's API) are released. */
|
|
72
|
+
async function bindByTag(provider, row, commit, signal, found) {
|
|
73
|
+
const refs = found ?? await provider.findByTag(row.tag, signal);
|
|
74
|
+
for (const extra of refs.slice(1))
|
|
75
|
+
await provider.release(extra, signal).catch(() => undefined);
|
|
76
|
+
const kept = refs[0] ?? null;
|
|
77
|
+
await commit((tx) => kept ? move(tx, row, { state: "live", resourceId: kept.id, at: now() }) : unknownCreate(tx, row, now()));
|
|
78
|
+
return kept;
|
|
79
|
+
}
|
|
80
|
+
async function emitReleased(cid, tag, read, context, at = now()) {
|
|
81
|
+
const [state, config] = await Promise.all([read.snapshot(Sessions, cid, context), read.snapshot(Config, cid, context)]);
|
|
82
|
+
const record = state?.sessions.find((r) => r.tag === tag);
|
|
83
|
+
const spent = record && record.resourceId !== null ? meter(record.spent, at, true).spent : record?.spent;
|
|
84
|
+
if (record && spent)
|
|
85
|
+
await emit(cid, config?.label ?? "", { ...record, state: "released", endedAt: record.endedAt ?? at, spent }, "released");
|
|
86
|
+
}
|
|
87
|
+
/** The row stays in the inventory until a run open's reconcile sees nothing under its tag running. */
|
|
88
|
+
async function retry(runtime, row, attempt, context) {
|
|
89
|
+
if (attempt + 1 >= RELEASE_ATTEMPTS) {
|
|
90
|
+
await runtime.commit(async (tx) => {
|
|
91
|
+
await move(tx, row, { state: "lost", reason: "lost", at: iso(runtime.now()) });
|
|
92
|
+
return { status: "terminal", outcome: { status: "failed", error: { code: "release_failed", message: `${row.tag}: not released after ${RELEASE_ATTEMPTS} attempts` } } };
|
|
93
|
+
}, context);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
await runtime.sleep(runtime.now() + backoffMs(attempt), context);
|
|
97
|
+
await runtime.commit(() => ({ status: "running", checkpoint: { phase: "release", attempt: attempt + 1 } }), context);
|
|
98
|
+
}
|
|
99
|
+
const ReleaseTask = defineTask({
|
|
100
|
+
name: `${name}.release`,
|
|
101
|
+
version: 1,
|
|
102
|
+
initial: () => ({ phase: "release", attempt: 0 }),
|
|
103
|
+
phases: {
|
|
104
|
+
release: async (task, runtime, context) => {
|
|
105
|
+
const { row, notBefore } = task.input;
|
|
106
|
+
const { attempt } = task.state.checkpoint;
|
|
107
|
+
if (attempt === 0 && notBefore && runtime.now() < notBefore)
|
|
108
|
+
await runtime.sleep(notBefore, context);
|
|
109
|
+
const ids = await step(runtime, async () => releaseAll(row, await providerOf(runtime, cidOf(row), row.plane, context), runtime.signal), null);
|
|
110
|
+
if (!ids)
|
|
111
|
+
return retry(runtime, row, attempt, context);
|
|
112
|
+
await runtime.commit(() => ({ status: "running", checkpoint: { phase: "confirm", attempt, ids, polls: 0 } }), context);
|
|
113
|
+
},
|
|
114
|
+
confirm: async (task, runtime, context) => {
|
|
115
|
+
const { row } = task.input;
|
|
116
|
+
const { attempt, ids, polls } = task.state.checkpoint;
|
|
117
|
+
const running = await step(runtime, async () => anyRunning(await providerOf(runtime, cidOf(row), row.plane, context), row, ids, runtime.signal), true);
|
|
118
|
+
if (running && polls + 1 < CONFIRM_POLLS) {
|
|
119
|
+
await runtime.sleep(runtime.now() + backoffMs(polls), context);
|
|
120
|
+
await runtime.commit(() => ({ status: "running", checkpoint: { phase: "confirm", attempt, ids, polls: polls + 1 } }), context);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (running)
|
|
124
|
+
return retry(runtime, row, attempt, context);
|
|
125
|
+
// The host hears the release before the task's last commit, so at least once, with the bill that commit
|
|
126
|
+
// records.
|
|
127
|
+
const at = iso(runtime.now());
|
|
128
|
+
await emitReleased(cidOf(row), row.tag, runtime, context, at);
|
|
129
|
+
await runtime.commit(async (tx) => {
|
|
130
|
+
await move(tx, row, { state: "released", at });
|
|
131
|
+
return { status: "terminal", outcome: { status: "completed", result: { released: ids.length } } };
|
|
132
|
+
}, context);
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
// After the abort mark: release and check once. It cannot wait or retry, so a release it cannot confirm is handed
|
|
136
|
+
// to a successor task in the same commit.
|
|
137
|
+
abort: async (task, runtime, context) => {
|
|
138
|
+
const { row, notBefore } = task.input;
|
|
139
|
+
let stopped = false;
|
|
140
|
+
// Before the create deadline nothing found is proof of nothing: the successor keeps the delayed lookup.
|
|
141
|
+
if (!(notBefore && runtime.now() < notBefore))
|
|
142
|
+
stopped = await providerOf(runtime, cidOf(row), row.plane, context).then((provider) => releasedAll(provider, row, context.abortSignal)).catch(() => false);
|
|
143
|
+
await runtime.commit(async (tx) => {
|
|
144
|
+
if (stopped)
|
|
145
|
+
await move(tx, row, { state: "released", at: iso(runtime.now()) });
|
|
146
|
+
else
|
|
147
|
+
await tx.createTask(ReleaseTask, task.input, { ownership: { kind: "conversation" }, conversationId: cidOf(row), background: true });
|
|
148
|
+
return { status: "terminal", outcome: { status: "aborted", reason: stopped ? "released by the abort handler" : "release handed to a successor task" } };
|
|
149
|
+
}, context);
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
async function reconcileAll(harness, isActive, context) {
|
|
153
|
+
const report = { released: [], kept: [], lost: [], unreachable: [] };
|
|
154
|
+
for (const row of Object.values((await harness.snapshot(Inventory, context))?.rows ?? {})) {
|
|
155
|
+
if (row.state === "releasing")
|
|
156
|
+
continue;
|
|
157
|
+
const at = now();
|
|
158
|
+
const commit = (change) => harness.commit(change, context);
|
|
159
|
+
const outcome = async (kind, change) => { if (change)
|
|
160
|
+
await commit(change); report[kind].push(row.tag); };
|
|
161
|
+
try {
|
|
162
|
+
const provider = await providerOf(harness, cidOf(row), row.plane, context);
|
|
163
|
+
if (row.state === "lost") {
|
|
164
|
+
await ((await releasedAll(provider, row)) ? outcome("released", async (tx) => {
|
|
165
|
+
delete (await tx.doc(Inventory)).rows[row.tag];
|
|
166
|
+
const record = (await tx.doc(Sessions, cidOf(row))).sessions.find((r) => r.tag === row.tag);
|
|
167
|
+
if (record && record.resourceId !== null)
|
|
168
|
+
record.spent = meter(record.spent, at, true).spent;
|
|
169
|
+
}) : outcome("lost"));
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
let live = row;
|
|
173
|
+
if (row.state === "creating") {
|
|
174
|
+
const kept = await bindByTag(provider, row, commit);
|
|
175
|
+
if (!kept) {
|
|
176
|
+
await outcome("lost");
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
live = { ...row, state: "live", resourceId: kept.id };
|
|
180
|
+
}
|
|
181
|
+
const status = await provider.status({ id: live.resourceId, tag: live.tag });
|
|
182
|
+
if (status === "gone" || status === "stopped")
|
|
183
|
+
await outcome("lost", (tx) => move(tx, live, { state: "released", reason: "ended", at, notice: "lost" }));
|
|
184
|
+
else if (isActive(cidOf(row)))
|
|
185
|
+
await outcome("kept", (tx) => move(tx, live, { state: "live", at, notice: "kept" }));
|
|
186
|
+
else
|
|
187
|
+
await outcome("released", (tx) => requestRelease(tx, live, "lost", at));
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
report.unreachable.push(row.tag);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return report;
|
|
194
|
+
}
|
|
195
|
+
return { Inventory, move, addNotice, begin, requestRelease, bindByTag, emitReleased, ReleaseTask, reconcileAll };
|
|
196
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import type { AttachTarget, BrowserProvider, ProviderCaps, RemoteFile, SearchResult } from "../core/host.js";
|
|
3
|
+
import { type Sentinels } from "./sentinels.js";
|
|
4
|
+
export type FakeFetchByFormat = {
|
|
5
|
+
markdown?: {
|
|
6
|
+
contentType: string;
|
|
7
|
+
content: string;
|
|
8
|
+
} | {
|
|
9
|
+
status: number;
|
|
10
|
+
};
|
|
11
|
+
raw?: {
|
|
12
|
+
contentType: string;
|
|
13
|
+
content: string;
|
|
14
|
+
} | {
|
|
15
|
+
status: number;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/** A vendor SDK's failure: the HTTP status is on the error, never inside the text. */
|
|
19
|
+
export declare class FakeProviderError extends Error {
|
|
20
|
+
readonly status: number;
|
|
21
|
+
constructor(message: string, status?: number);
|
|
22
|
+
}
|
|
23
|
+
export type LedgerRow = {
|
|
24
|
+
n: number;
|
|
25
|
+
op: string;
|
|
26
|
+
[field: string]: unknown;
|
|
27
|
+
};
|
|
28
|
+
export type FixturePage = {
|
|
29
|
+
url: string;
|
|
30
|
+
title: string;
|
|
31
|
+
text: string;
|
|
32
|
+
html: string;
|
|
33
|
+
};
|
|
34
|
+
export declare const fixturePage: (url: string, text: string, title?: string) => FixturePage;
|
|
35
|
+
export type BrokerConnection = {
|
|
36
|
+
name: string;
|
|
37
|
+
startUrl: string | null;
|
|
38
|
+
fields: Array<{
|
|
39
|
+
name: string;
|
|
40
|
+
type: "text" | "email" | "password" | "totp";
|
|
41
|
+
}>;
|
|
42
|
+
allowedOrigins: string[];
|
|
43
|
+
enrollment: boolean;
|
|
44
|
+
};
|
|
45
|
+
export type FillRequest = {
|
|
46
|
+
pageUrl: string;
|
|
47
|
+
fields: Array<{
|
|
48
|
+
field: string;
|
|
49
|
+
selector: string;
|
|
50
|
+
}>;
|
|
51
|
+
};
|
|
52
|
+
export type FillResult = {
|
|
53
|
+
status: "completed" | "failed" | "unknown";
|
|
54
|
+
fields: Array<{
|
|
55
|
+
index: number;
|
|
56
|
+
status: string;
|
|
57
|
+
errorCode?: string;
|
|
58
|
+
}>;
|
|
59
|
+
};
|
|
60
|
+
export type FakeBackendOptions = {
|
|
61
|
+
sentinels?: Sentinels;
|
|
62
|
+
name?: string;
|
|
63
|
+
caps?: Partial<ProviderCaps>;
|
|
64
|
+
start?: string;
|
|
65
|
+
pages?: Record<string, FixturePage>;
|
|
66
|
+
/** A URL not listed is a 404; an object answers markdown and raw apart. */
|
|
67
|
+
fetches?: Record<string, string | FakeFetchByFormat>;
|
|
68
|
+
search?: SearchResult["results"];
|
|
69
|
+
/** Every ledger row is also appended here as JSONL, so a killed process leaves its calls behind. */
|
|
70
|
+
logFile?: string;
|
|
71
|
+
connections?: BrokerConnection[];
|
|
72
|
+
downloads?: Record<string, string>;
|
|
73
|
+
viewport?: {
|
|
74
|
+
width: number;
|
|
75
|
+
height: number;
|
|
76
|
+
};
|
|
77
|
+
fullPageHeight?: number;
|
|
78
|
+
/** Device pixels per CSS pixel; a screenshot is this many times larger unless it asks for `scale: "css"`. */
|
|
79
|
+
deviceScale?: number;
|
|
80
|
+
};
|
|
81
|
+
export type FakeScreenshotOptions = {
|
|
82
|
+
fullPage?: boolean;
|
|
83
|
+
type?: "png" | "jpeg";
|
|
84
|
+
quality?: number;
|
|
85
|
+
scale?: "css" | "device";
|
|
86
|
+
};
|
|
87
|
+
/** A PNG or JPEG whose header declares `width` x `height`: enough for a reader that decodes the header, not a picture. */
|
|
88
|
+
export declare function fakeImage(type: "png" | "jpeg", width: number, height: number): Buffer;
|
|
89
|
+
type Session = {
|
|
90
|
+
id: string;
|
|
91
|
+
tag: string;
|
|
92
|
+
metadata: Record<string, string>;
|
|
93
|
+
state: "running" | "stopped";
|
|
94
|
+
url: string;
|
|
95
|
+
broker: boolean;
|
|
96
|
+
plane: string;
|
|
97
|
+
};
|
|
98
|
+
export declare class FakeBackend {
|
|
99
|
+
readonly sentinels: Sentinels;
|
|
100
|
+
readonly pages: Record<string, FixturePage>;
|
|
101
|
+
readonly ledger: LedgerRow[];
|
|
102
|
+
/** Every call the driver made on a page, in order; a read answered from a receipt never shows up here. */
|
|
103
|
+
readonly dispatched: Array<{
|
|
104
|
+
op: string;
|
|
105
|
+
session: string;
|
|
106
|
+
url: string | null;
|
|
107
|
+
[field: string]: unknown;
|
|
108
|
+
}>;
|
|
109
|
+
/** Emits `held` with the op name when a held call has been applied and will never be answered. */
|
|
110
|
+
readonly events: EventEmitter<[never]>;
|
|
111
|
+
readonly sessions: Map<string, Session>;
|
|
112
|
+
readonly provider: BrowserProvider;
|
|
113
|
+
readonly broker: FakeBroker;
|
|
114
|
+
readonly driverFace: FakeDriverFace;
|
|
115
|
+
private seq;
|
|
116
|
+
private holdOp;
|
|
117
|
+
private loseOp;
|
|
118
|
+
private failures;
|
|
119
|
+
private delays;
|
|
120
|
+
private peak;
|
|
121
|
+
private echoOn;
|
|
122
|
+
readonly opts: Required<Pick<FakeBackendOptions, "start" | "fetches" | "search" | "connections" | "downloads">> & FakeBackendOptions;
|
|
123
|
+
constructor(options?: FakeBackendOptions);
|
|
124
|
+
/** The next call of `op` is applied and recorded, then never answered. */
|
|
125
|
+
hold(op: string): void;
|
|
126
|
+
/** The next call of `op` is applied and recorded, then fails: the provider did the work and the answer was lost. */
|
|
127
|
+
lose(op: string): void;
|
|
128
|
+
/** The next `times` calls of `op` fail before they take effect. */
|
|
129
|
+
fail(op: string, times?: number): void;
|
|
130
|
+
/** `op` sleeps `ms` before it takes effect; a caller that hangs up meanwhile is not served. */
|
|
131
|
+
delay(op: string, ms: number): void;
|
|
132
|
+
/** Failure text repeats the request and every secret the backend holds. */
|
|
133
|
+
echo(on?: boolean): void;
|
|
134
|
+
endAll(): void;
|
|
135
|
+
goto(url: string): void;
|
|
136
|
+
reset(): void;
|
|
137
|
+
live(): Array<{
|
|
138
|
+
id: string;
|
|
139
|
+
tag: string;
|
|
140
|
+
}>;
|
|
141
|
+
liveCount(): number;
|
|
142
|
+
tally(): {
|
|
143
|
+
creates: number;
|
|
144
|
+
findByTag: number;
|
|
145
|
+
status: number;
|
|
146
|
+
attaches: number;
|
|
147
|
+
releases: number;
|
|
148
|
+
releaseNoops: number;
|
|
149
|
+
fetches: number;
|
|
150
|
+
searches: number;
|
|
151
|
+
dispatches: number;
|
|
152
|
+
reads: number;
|
|
153
|
+
peakLive: number;
|
|
154
|
+
liveAtEnd: number;
|
|
155
|
+
};
|
|
156
|
+
/** A failing vendor's error text: the request's credentials and the connect URLs the backend holds. */
|
|
157
|
+
echoText(op: string): string;
|
|
158
|
+
record(op: string, fields?: Record<string, unknown>): LedgerRow;
|
|
159
|
+
before(op: string, signal?: AbortSignal): Promise<void>;
|
|
160
|
+
after(op: string): Promise<void>;
|
|
161
|
+
noteLive(): void;
|
|
162
|
+
newId(prefix: string): string;
|
|
163
|
+
running(id: string): Session | null;
|
|
164
|
+
targetOf(session: Session): AttachTarget;
|
|
165
|
+
private makeProvider;
|
|
166
|
+
/** For a child's `remoteProvider` and `remoteDriver`; a held call stays open until the child dies. */
|
|
167
|
+
serve(): Promise<{
|
|
168
|
+
url: string;
|
|
169
|
+
close(): Promise<void>;
|
|
170
|
+
}>;
|
|
171
|
+
}
|
|
172
|
+
/** A held call never returns; an aborted one stops its request. */
|
|
173
|
+
export declare function remoteProvider(url: string, options?: {
|
|
174
|
+
name?: string;
|
|
175
|
+
caps?: Partial<ProviderCaps>;
|
|
176
|
+
}): BrowserProvider;
|
|
177
|
+
/** Counts a fill before the provider is touched and never repeats an unknown one; its failures carry only codes. */
|
|
178
|
+
export declare class FakeBroker {
|
|
179
|
+
private readonly b;
|
|
180
|
+
constructor(b: FakeBackend);
|
|
181
|
+
connections(): Promise<BrokerConnection[]>;
|
|
182
|
+
acquire(name: string): Promise<{
|
|
183
|
+
session: string;
|
|
184
|
+
attach: AttachTarget;
|
|
185
|
+
leaseExpiresAt: string;
|
|
186
|
+
recording: boolean | null;
|
|
187
|
+
}>;
|
|
188
|
+
heartbeat(session: string): Promise<{
|
|
189
|
+
leaseExpiresAt: string;
|
|
190
|
+
}>;
|
|
191
|
+
release(session: string): Promise<void>;
|
|
192
|
+
fill(session: string, request: FillRequest): Promise<FillResult>;
|
|
193
|
+
captureTotpSeed(session: string, request: {
|
|
194
|
+
pageUrl: string;
|
|
195
|
+
selector: string;
|
|
196
|
+
}): Promise<{
|
|
197
|
+
stored: boolean;
|
|
198
|
+
field: string;
|
|
199
|
+
}>;
|
|
200
|
+
downloads(): Promise<RemoteFile[]>;
|
|
201
|
+
}
|
|
202
|
+
export declare class FakeDriverFace {
|
|
203
|
+
private readonly b;
|
|
204
|
+
constructor(b: FakeBackend);
|
|
205
|
+
private session;
|
|
206
|
+
private pageOf;
|
|
207
|
+
private call;
|
|
208
|
+
connect(target: AttachTarget): Promise<string>;
|
|
209
|
+
snapshot(id: string): Promise<string>;
|
|
210
|
+
/** A `goto` action moves the page; any other code returns what it was given. */
|
|
211
|
+
run(id: string, input: {
|
|
212
|
+
code?: string;
|
|
213
|
+
actions?: Array<{
|
|
214
|
+
op: string;
|
|
215
|
+
url?: string;
|
|
216
|
+
[field: string]: unknown;
|
|
217
|
+
}>;
|
|
218
|
+
}): Promise<unknown>;
|
|
219
|
+
/** No `dispatched` row: a read of the URL is not a read of the page. */
|
|
220
|
+
url(id: string): Promise<string>;
|
|
221
|
+
/** Header-only image of the viewport (or full page) times the device scale; each capture is a dispatched row. */
|
|
222
|
+
screenshot(id: string, options?: FakeScreenshotOptions): Promise<{
|
|
223
|
+
data: string;
|
|
224
|
+
mimeType: string;
|
|
225
|
+
width: number;
|
|
226
|
+
height: number;
|
|
227
|
+
}>;
|
|
228
|
+
page(id: string): Promise<FixturePage>;
|
|
229
|
+
close(id: string): Promise<void>;
|
|
230
|
+
}
|
|
231
|
+
export {};
|