@deepraxis/sdk 0.2.0-dev.229e1e5 → 0.2.0-dev.2659553
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/dist/core/client.js
CHANGED
|
@@ -22,6 +22,7 @@ export class Praxis {
|
|
|
22
22
|
const host = globalThis.process;
|
|
23
23
|
Object.assign(resource, { connect: (options) => connectBrowser({
|
|
24
24
|
contexts: resource.contexts,
|
|
25
|
+
sessions: resource.sessions,
|
|
25
26
|
env: host?.env ?? {},
|
|
26
27
|
builtin: host?.getBuiltinModule?.bind(host),
|
|
27
28
|
}, options) });
|
|
@@ -9,8 +9,14 @@
|
|
|
9
9
|
* service was holding (services/browser/src/api/rpc-contract.ts:208) as an outage it cannot act on.
|
|
10
10
|
*
|
|
11
11
|
* Owner of the status -> code mapping is the domain exit (services/browser/src/api/rpc-contract.ts), which the
|
|
12
|
-
* SDK mirrors by status only where the status is unambiguous on the connect path:
|
|
13
|
-
*
|
|
12
|
+
* SDK mirrors by status only where the status is unambiguous on the connect path: 503 alone is SERVICE_UNAVAILABLE
|
|
13
|
+
* (:219). A body that names a code always wins over that mirror.
|
|
14
|
+
*
|
|
15
|
+
* #5147 — 409 is NOT one of those statuses. The connect path answers SESSION_ENDED (a session that was released
|
|
16
|
+
* before the attach), SESSION_INVALID_STATE, SESSION_NAME_IN_USE and CONTEXT_LOCKED alike with 409, so reading the
|
|
17
|
+
* status alone told an agent its saved sign-in state was held by another session when the session had simply ended.
|
|
18
|
+
* A body-less 409 stays a CONFLICT, and a caller that already holds the session id asks the session itself
|
|
19
|
+
* ({@link nameConnectConflict}).
|
|
14
20
|
*/
|
|
15
21
|
/** A refusal read as the fields the SDK raises it with. */
|
|
16
22
|
export interface ConnectRefusal {
|
|
@@ -29,6 +35,12 @@ export declare function byobRefusalBody(code: ByobRefusalCode, body: Record<stri
|
|
|
29
35
|
/**
|
|
30
36
|
* The refusal a Playwright connect failure stands for. Total and pure: the same message always yields the same
|
|
31
37
|
* classification. The body's own code wins (the domain code crosses the boundary unchanged); with no readable
|
|
32
|
-
* body
|
|
38
|
+
* body an unambiguous status names it, and a 409 — which is several codes — stays a CONFLICT rather than a 503.
|
|
33
39
|
*/
|
|
34
40
|
export declare function classifyConnectRefusal(message: string): ConnectRefusal;
|
|
41
|
+
/**
|
|
42
|
+
* #5147 — give a body-less 409 the name its session already has. A connect that carried a session id knows which
|
|
43
|
+
* session refused it, so the reader's `status` (RUNNING, ENDED, …) says what the handshake could not carry: a
|
|
44
|
+
* session that is over refuses as SESSION_ENDED, never as a locked sign-in context. Pure: the caller does the read.
|
|
45
|
+
*/
|
|
46
|
+
export declare function nameConnectConflict(refusal: ConnectRefusal, sessionStatus: string | null | undefined): ConnectRefusal;
|
|
@@ -9,8 +9,14 @@
|
|
|
9
9
|
* service was holding (services/browser/src/api/rpc-contract.ts:208) as an outage it cannot act on.
|
|
10
10
|
*
|
|
11
11
|
* Owner of the status -> code mapping is the domain exit (services/browser/src/api/rpc-contract.ts), which the
|
|
12
|
-
* SDK mirrors by status only where the status is unambiguous on the connect path:
|
|
13
|
-
*
|
|
12
|
+
* SDK mirrors by status only where the status is unambiguous on the connect path: 503 alone is SERVICE_UNAVAILABLE
|
|
13
|
+
* (:219). A body that names a code always wins over that mirror.
|
|
14
|
+
*
|
|
15
|
+
* #5147 — 409 is NOT one of those statuses. The connect path answers SESSION_ENDED (a session that was released
|
|
16
|
+
* before the attach), SESSION_INVALID_STATE, SESSION_NAME_IN_USE and CONTEXT_LOCKED alike with 409, so reading the
|
|
17
|
+
* status alone told an agent its saved sign-in state was held by another session when the session had simply ended.
|
|
18
|
+
* A body-less 409 stays a CONFLICT, and a caller that already holds the session id asks the session itself
|
|
19
|
+
* ({@link nameConnectConflict}).
|
|
14
20
|
*/
|
|
15
21
|
/** ADR-205: the refusals of a user's own browser (BYOB). Their codes travel as themselves; only these say whether a retry can help. */
|
|
16
22
|
export const BYOB_REFUSAL_CODES = ['BROWSER_OFFLINE', 'BROWSER_REVOKED', 'BROWSER_NOT_FOUND'];
|
|
@@ -32,11 +38,12 @@ const CODE_BY_STATUS = {
|
|
|
32
38
|
402: 'QUOTA_EXHAUSTED',
|
|
33
39
|
403: 'FORBIDDEN',
|
|
34
40
|
404: 'NOT_FOUND',
|
|
35
|
-
409: 'CONTEXT_LOCKED',
|
|
36
41
|
429: 'RATE_LIMITED',
|
|
37
42
|
};
|
|
38
|
-
/**
|
|
39
|
-
const
|
|
43
|
+
/** What a body-less 409 says when nothing can name it better: the facts, and the two readings that fit them. */
|
|
44
|
+
const CONFLICT_MESSAGE = 'The cloud browser refused the connection (409 Conflict) without naming a reason; the session may have ended, or its sign-in context may be held by another session.';
|
|
45
|
+
/** The session states a CDP attach accepts; anything else means the session is over. */
|
|
46
|
+
const ATTACHABLE_STATUSES = ['RUNNING', 'PENDING'];
|
|
40
47
|
/** 503 is the outage: the service answered 503, or the SDK holds nothing that names the failure. */
|
|
41
48
|
const outage = (message) => ({ status: 503, code: 'BROWSER_UNAVAILABLE', message });
|
|
42
49
|
/** The object a body text parses to, or undefined when it is not a JSON object. */
|
|
@@ -63,7 +70,7 @@ function refusalFromMessage(message) {
|
|
|
63
70
|
/**
|
|
64
71
|
* The refusal a Playwright connect failure stands for. Total and pure: the same message always yields the same
|
|
65
72
|
* classification. The body's own code wins (the domain code crosses the boundary unchanged); with no readable
|
|
66
|
-
* body
|
|
73
|
+
* body an unambiguous status names it, and a 409 — which is several codes — stays a CONFLICT rather than a 503.
|
|
67
74
|
*/
|
|
68
75
|
export function classifyConnectRefusal(message) {
|
|
69
76
|
const firstLine = message.split('\n')[0] ?? message;
|
|
@@ -80,6 +87,24 @@ export function classifyConnectRefusal(message) {
|
|
|
80
87
|
}
|
|
81
88
|
const byStatus = CODE_BY_STATUS[refusal.status];
|
|
82
89
|
if (byStatus === undefined)
|
|
83
|
-
return
|
|
84
|
-
|
|
90
|
+
return refusal.status === 409
|
|
91
|
+
? { status: 409, code: 'CONFLICT', message: CONFLICT_MESSAGE }
|
|
92
|
+
: outage(`Connecting to the cloud browser failed: ${firstLine}`);
|
|
93
|
+
return { status: refusal.status, code: byStatus, message: firstLine };
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* #5147 — give a body-less 409 the name its session already has. A connect that carried a session id knows which
|
|
97
|
+
* session refused it, so the reader's `status` (RUNNING, ENDED, …) says what the handshake could not carry: a
|
|
98
|
+
* session that is over refuses as SESSION_ENDED, never as a locked sign-in context. Pure: the caller does the read.
|
|
99
|
+
*/
|
|
100
|
+
export function nameConnectConflict(refusal, sessionStatus) {
|
|
101
|
+
if (refusal.status !== 409 || refusal.code !== 'CONFLICT' || typeof sessionStatus !== 'string')
|
|
102
|
+
return refusal;
|
|
103
|
+
if (ATTACHABLE_STATUSES.includes(sessionStatus))
|
|
104
|
+
return refusal;
|
|
105
|
+
return {
|
|
106
|
+
...refusal,
|
|
107
|
+
code: 'SESSION_ENDED',
|
|
108
|
+
message: `The cloud browser session has ended (${sessionStatus}); create a new session or attach one that is still running.`,
|
|
109
|
+
};
|
|
85
110
|
}
|
|
@@ -88,6 +88,16 @@ interface ContextsApi {
|
|
|
88
88
|
};
|
|
89
89
|
}): Promise<ContextLike>;
|
|
90
90
|
}
|
|
91
|
+
/** #5147 — one read of the session a connect named, so a body-less 409 can be answered by the session's own state. */
|
|
92
|
+
interface SessionsApi {
|
|
93
|
+
retrieve(args: {
|
|
94
|
+
path: {
|
|
95
|
+
sessionId: string;
|
|
96
|
+
};
|
|
97
|
+
}): Promise<{
|
|
98
|
+
status?: unknown;
|
|
99
|
+
}>;
|
|
100
|
+
}
|
|
91
101
|
/** The playwright-core module shape the helper uses. */
|
|
92
102
|
export interface PlaywrightModule {
|
|
93
103
|
chromium: {
|
|
@@ -100,6 +110,8 @@ export interface PlaywrightModule {
|
|
|
100
110
|
/** What connect() needs from the platform client and the process. All of it is injectable for tests. */
|
|
101
111
|
export interface BrowserConnectDeps {
|
|
102
112
|
contexts: ContextsApi;
|
|
113
|
+
/** #5147 — `browser.sessions`; the platform client passes it so connect({ sessionId }) can name a body-less 409. */
|
|
114
|
+
sessions?: SessionsApi;
|
|
103
115
|
env: Readonly<Record<string, string | undefined>>;
|
|
104
116
|
/** process.getBuiltinModule; undefined on runtimes without it. */
|
|
105
117
|
builtin: ((name: string) => unknown) | undefined;
|
|
@@ -7,7 +7,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
7
7
|
return path;
|
|
8
8
|
};
|
|
9
9
|
import { PraxisError } from "../core/errors.js";
|
|
10
|
-
import { classifyConnectRefusal } from "./browser-connect-error.js";
|
|
10
|
+
import { classifyConnectRefusal, nameConnectConflict } from "./browser-connect-error.js";
|
|
11
11
|
import { BROWSER_DOCUMENTATION } from "./browser-documentation.js";
|
|
12
12
|
import { createBrowserActions } from "./browser-actions.js";
|
|
13
13
|
import { agentContextName, browserSessionName, buildConnectUrl, buildSessionConnectUrl, decideBrowserDriver, decideTabReuse, isDuplicateNameError, matchTargetsToPages, pickAgentContext, pickContextByName } from "./browser-decisions.js";
|
|
@@ -36,6 +36,19 @@ export function checkConnectOptions(options) {
|
|
|
36
36
|
return options;
|
|
37
37
|
}
|
|
38
38
|
export const unavailable = (message) => new PraxisError({ status: 503, code: 'BROWSER_UNAVAILABLE', message });
|
|
39
|
+
/**
|
|
40
|
+
* #5147 — a body-less 409 on a session this connect named asks that session what it is: a session that has ended
|
|
41
|
+
* refuses as SESSION_ENDED, not as a sign-in context held by another session. A read that fails says nothing about
|
|
42
|
+
* the session, so the conflict stays the honest answer.
|
|
43
|
+
*/
|
|
44
|
+
async function nameTheRefusal(refusal, sessionId, sessions) {
|
|
45
|
+
if (sessionId === undefined || sessions === undefined || refusal.status !== 409 || refusal.code !== 'CONFLICT')
|
|
46
|
+
return refusal;
|
|
47
|
+
const session = await sessions.retrieve({ path: { sessionId } }).catch(() => undefined);
|
|
48
|
+
if (session === undefined)
|
|
49
|
+
return refusal;
|
|
50
|
+
return nameConnectConflict(refusal, typeof session.status === 'string' ? session.status : undefined);
|
|
51
|
+
}
|
|
39
52
|
/** The shape of a tab-id argument that is not a non-empty string, in the words the message uses. */
|
|
40
53
|
const argumentShape = (value) => typeof value === 'string' ? 'an empty string'
|
|
41
54
|
: value === null ? 'null'
|
|
@@ -285,7 +298,7 @@ export async function connectBrowser(deps, given) {
|
|
|
285
298
|
catch (cause) {
|
|
286
299
|
// A refusal that named itself travels as itself (ADR-024: a locked context is 409 CONTEXT_LOCKED, not a 503);
|
|
287
300
|
// only a real 503, or a failure with no status to read, is the outage it looks like (ticket-834, ticket-3252).
|
|
288
|
-
const refusal = classifyConnectRefusal(cause instanceof Error ? cause.message : String(cause));
|
|
301
|
+
const refusal = await nameTheRefusal(classifyConnectRefusal(cause instanceof Error ? cause.message : String(cause)), existing, deps.sessions);
|
|
289
302
|
throw new PraxisError({ status: refusal.status, code: refusal.code, message: refusal.message, raw: refusal.raw });
|
|
290
303
|
}
|
|
291
304
|
const fs = node(deps, 'node:fs');
|