@yielded/agent-platform-cloudflare 0.1.0-beta.183 → 0.1.0-beta.185
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/{BrowserCredentials-C5IWfi7f.d.mts → BrowserCredentials-C2rBhlUI.d.mts} +30 -5
- package/dist/BrowserCredentials.d.mts +2 -2
- package/dist/BrowserCredentials.mjs +28 -8
- package/dist/BrowserCredentials.mjs.map +1 -1
- package/dist/{BrowserSession-aovMjfL4.mjs → BrowserSession-CfivQ5JY.mjs} +150 -65
- package/dist/BrowserSession-CfivQ5JY.mjs.map +1 -0
- package/dist/{BrowserSession-Cojp7nth.d.mts → BrowserSession-mKnLSc3p.d.mts} +8 -2
- package/dist/BrowserSession.d.mts +1 -1
- package/dist/BrowserSession.mjs +2 -2
- package/dist/BrowserUse.d.mts +1 -1
- package/dist/BrowserUse.mjs +31 -4
- package/dist/BrowserUse.mjs.map +1 -1
- package/dist/{CloudflareThreadClient-DNsFhgVu.d.mts → CloudflareThreadClient-CmlojpjC.d.mts} +184 -184
- package/dist/CloudflareThreadClient.d.mts +1 -1
- package/dist/{InteractiveBrowser-BHNlwjZL.mjs → InteractiveBrowser-nukKxc87.mjs} +4 -45
- package/dist/InteractiveBrowser-nukKxc87.mjs.map +1 -0
- package/dist/InteractiveBrowser.mjs +1 -1
- package/dist/{ThreadObject-BVoyFKHN.d.mts → ThreadObject-Osn-FmcF.d.mts} +2 -2
- package/dist/ThreadObject.d.mts +1 -1
- package/dist/browser-failure-DECzRY3H.mjs +50 -0
- package/dist/browser-failure-DECzRY3H.mjs.map +1 -0
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/BrowserCredentials.ts +42 -9
- package/src/BrowserSession.ts +88 -8
- package/src/BrowserUse.ts +51 -4
- package/src/internal/browser-credentials.ts +205 -98
- package/src/internal/browser-failure.ts +3 -0
- package/dist/BrowserSession-aovMjfL4.mjs.map +0 -1
- package/dist/InteractiveBrowser-BHNlwjZL.mjs.map +0 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Cause, Data, ErrorReporter, Predicate, Schema } from "effect";
|
|
2
|
+
//#region src/internal/browser-failure.ts
|
|
3
|
+
/** Source-authored stages and classifications only; never retain SDK text or session capabilities. */
|
|
4
|
+
var BrowserRunFailure = class extends Data.TaggedError("BrowserRunFailure") {
|
|
5
|
+
[ErrorReporter.severity] = "Error";
|
|
6
|
+
};
|
|
7
|
+
/** A public projection of an already reported private failure must not produce another issue. */
|
|
8
|
+
const reportedBrowserError = (error) => Object.assign(error, { [ErrorReporter.ignore]: true });
|
|
9
|
+
const inheritBrowserReport = (original, error) => ErrorReporter.isIgnored(original) ? reportedBrowserError(error) : error;
|
|
10
|
+
const reasonSchema = Schema.Literals([
|
|
11
|
+
"provider",
|
|
12
|
+
"timeout",
|
|
13
|
+
"malformed",
|
|
14
|
+
"configuration",
|
|
15
|
+
"authorization",
|
|
16
|
+
"rate-limited",
|
|
17
|
+
"pending"
|
|
18
|
+
]);
|
|
19
|
+
const statusSchema = Schema.Int.check(Schema.isBetween({
|
|
20
|
+
minimum: 100,
|
|
21
|
+
maximum: 599
|
|
22
|
+
}));
|
|
23
|
+
const failureNames = /* @__PURE__ */ new Set([
|
|
24
|
+
"TypeError",
|
|
25
|
+
"RangeError",
|
|
26
|
+
"SyntaxError",
|
|
27
|
+
"TimeoutError",
|
|
28
|
+
"SchemaError",
|
|
29
|
+
"ProtocolError",
|
|
30
|
+
"TargetCloseError",
|
|
31
|
+
"ConnectionClosedError"
|
|
32
|
+
]);
|
|
33
|
+
const browserFailure = (operation, cause) => cause instanceof BrowserRunFailure ? cause : new BrowserRunFailure({
|
|
34
|
+
operation,
|
|
35
|
+
reason: Predicate.isObject(cause) && "reason" in cause && Schema.is(reasonSchema)(cause.reason) ? cause.reason : "provider",
|
|
36
|
+
...Predicate.isObject(cause) && "status" in cause && Schema.is(statusSchema)(cause.status) ? { status: cause.status } : {},
|
|
37
|
+
...Predicate.isObject(cause) && "cause" in cause && cause.cause instanceof BrowserRunFailure ? { cause: cause.cause } : Predicate.isObject(cause) && "name" in cause && typeof cause.name === "string" && failureNames.has(cause.name) ? { cause: { name: cause.name } } : {}
|
|
38
|
+
});
|
|
39
|
+
/** Keep mixed defects and interruptions distinct while discarding all foreign diagnostic content. */
|
|
40
|
+
const reportBrowserCause = (operation, cause) => ErrorReporter.report(Cause.fromReasons(cause.reasons.filter((reason) => !Cause.isFailReason(reason) || !ErrorReporter.isIgnored(reason.error)).map((reason) => {
|
|
41
|
+
switch (reason._tag) {
|
|
42
|
+
case "Fail": return Cause.makeFailReason(browserFailure(operation, reason.error));
|
|
43
|
+
case "Die": return Cause.makeDieReason(browserFailure(operation, reason.defect));
|
|
44
|
+
case "Interrupt": return reason;
|
|
45
|
+
}
|
|
46
|
+
})));
|
|
47
|
+
//#endregion
|
|
48
|
+
export { reportedBrowserError as a, reportBrowserCause as i, browserFailure as n, inheritBrowserReport as r, BrowserRunFailure as t };
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=browser-failure-DECzRY3H.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-failure-DECzRY3H.mjs","names":[],"sources":["../src/internal/browser-failure.ts"],"sourcesContent":["import type { Effect } from \"effect\";\nimport { Cause, Data, ErrorReporter, Predicate, Schema } from \"effect\";\n\n/** Source-authored stages and classifications only; never retain SDK text or session capabilities. */\nexport class BrowserRunFailure extends Data.TaggedError(\"BrowserRunFailure\")<{\n readonly operation: string;\n readonly reason:\n | \"provider\"\n | \"timeout\"\n | \"malformed\"\n | \"configuration\"\n | \"authorization\"\n | \"rate-limited\"\n | \"pending\";\n readonly status?: number;\n readonly cause?: BrowserRunFailure | { readonly name: string };\n}> {\n readonly [ErrorReporter.severity] = \"Error\" as const;\n}\n\n/** A public projection of an already reported private failure must not produce another issue. */\nexport const reportedBrowserError = <A extends object>(error: A): A =>\n Object.assign(error, { [ErrorReporter.ignore]: true });\n\nexport const inheritBrowserReport = <A extends object>(original: unknown, error: A): A =>\n ErrorReporter.isIgnored(original) ? reportedBrowserError(error) : error;\n\nconst reasonSchema = Schema.Literals([\n \"provider\",\n \"timeout\",\n \"malformed\",\n \"configuration\",\n \"authorization\",\n \"rate-limited\",\n \"pending\",\n]);\n\nconst statusSchema = Schema.Int.check(Schema.isBetween({ minimum: 100, maximum: 599 }));\n\nconst failureNames = new Set([\n \"TypeError\",\n \"RangeError\",\n \"SyntaxError\",\n \"TimeoutError\",\n \"SchemaError\",\n \"ProtocolError\",\n \"TargetCloseError\",\n \"ConnectionClosedError\",\n]);\n\nexport const browserFailure = (operation: string, cause?: unknown): BrowserRunFailure =>\n cause instanceof BrowserRunFailure\n ? cause\n : new BrowserRunFailure({\n operation,\n reason:\n Predicate.isObject(cause) && \"reason\" in cause && Schema.is(reasonSchema)(cause.reason)\n ? cause.reason\n : \"provider\",\n ...(Predicate.isObject(cause) && \"status\" in cause && Schema.is(statusSchema)(cause.status)\n ? { status: cause.status }\n : {}),\n ...(Predicate.isObject(cause) &&\n \"cause\" in cause &&\n cause.cause instanceof BrowserRunFailure\n ? { cause: cause.cause }\n : Predicate.isObject(cause) &&\n \"name\" in cause &&\n typeof cause.name === \"string\" &&\n failureNames.has(cause.name)\n ? { cause: { name: cause.name } }\n : {}),\n });\n\n/** Keep mixed defects and interruptions distinct while discarding all foreign diagnostic content. */\nexport const reportBrowserCause = <E>(\n operation: string,\n cause: Cause.Cause<E>,\n): Effect.Effect<void> =>\n ErrorReporter.report(\n Cause.fromReasons(\n cause.reasons\n .filter((reason) => !Cause.isFailReason(reason) || !ErrorReporter.isIgnored(reason.error))\n .map((reason) => {\n switch (reason._tag) {\n case \"Fail\":\n return Cause.makeFailReason(browserFailure(operation, reason.error));\n case \"Die\":\n return Cause.makeDieReason(browserFailure(operation, reason.defect));\n case \"Interrupt\":\n return reason;\n }\n }),\n ),\n );\n"],"mappings":";;;AAIA,IAAa,oBAAb,cAAuC,KAAK,YAAY,mBAAmB,CAAC,CAYzE;CACD,CAAU,cAAc,YAAY;AACtC;;AAGA,MAAa,wBAA0C,UACrD,OAAO,OAAO,OAAO,GAAG,cAAc,SAAS,KAAK,CAAC;AAEvD,MAAa,wBAA0C,UAAmB,UACxE,cAAc,UAAU,QAAQ,IAAI,qBAAqB,KAAK,IAAI;AAEpE,MAAM,eAAe,OAAO,SAAS;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,eAAe,OAAO,IAAI,MAAM,OAAO,UAAU;CAAE,SAAS;CAAK,SAAS;AAAI,CAAC,CAAC;AAEtF,MAAM,+BAAe,IAAI,IAAI;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,kBAAkB,WAAmB,UAChD,iBAAiB,oBACb,QACA,IAAI,kBAAkB;CACpB;CACA,QACE,UAAU,SAAS,KAAK,KAAK,YAAY,SAAS,OAAO,GAAG,YAAY,CAAC,CAAC,MAAM,MAAM,IAClF,MAAM,SACN;CACN,GAAI,UAAU,SAAS,KAAK,KAAK,YAAY,SAAS,OAAO,GAAG,YAAY,CAAC,CAAC,MAAM,MAAM,IACtF,EAAE,QAAQ,MAAM,OAAO,IACvB,CAAC;CACL,GAAI,UAAU,SAAS,KAAK,KAC5B,WAAW,SACX,MAAM,iBAAiB,oBACnB,EAAE,OAAO,MAAM,MAAM,IACrB,UAAU,SAAS,KAAK,KACtB,UAAU,SACV,OAAO,MAAM,SAAS,YACtB,aAAa,IAAI,MAAM,IAAI,IAC3B,EAAE,OAAO,EAAE,MAAM,MAAM,KAAK,EAAE,IAC9B,CAAC;AACT,CAAC;;AAGP,MAAa,sBACX,WACA,UAEA,cAAc,OACZ,MAAM,YACJ,MAAM,QACH,QAAQ,WAAW,CAAC,MAAM,aAAa,MAAM,KAAK,CAAC,cAAc,UAAU,OAAO,KAAK,CAAC,CAAC,CACzF,KAAK,WAAW;CACf,QAAQ,OAAO,MAAf;EACE,KAAK,QACH,OAAO,MAAM,eAAe,eAAe,WAAW,OAAO,KAAK,CAAC;EACrE,KAAK,OACH,OAAO,MAAM,cAAc,eAAe,WAAW,OAAO,MAAM,CAAC;EACrE,KAAK,aACH,OAAO;CACX;AACF,CAAC,CACL,CACF"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { t as CloudflareBindings_d_exports } from "./CloudflareBindings.mjs";
|
|
2
2
|
import { o as CloudflareConfig_d_exports } from "./CloudflareConfig-C9MvPbX8.mjs";
|
|
3
3
|
import { t as Alarm_d_exports } from "./Alarm.mjs";
|
|
4
|
-
import { r as BrowserCredentials_d_exports } from "./BrowserCredentials-
|
|
4
|
+
import { r as BrowserCredentials_d_exports } from "./BrowserCredentials-C2rBhlUI.mjs";
|
|
5
5
|
import { t as CloudflareBrowser_d_exports } from "./CloudflareBrowser-gu7gma0Y.mjs";
|
|
6
|
-
import { a as BrowserSession_d_exports } from "./BrowserSession-
|
|
6
|
+
import { a as BrowserSession_d_exports } from "./BrowserSession-mKnLSc3p.mjs";
|
|
7
7
|
import { t as BrowserUse_d_exports } from "./BrowserUse.mjs";
|
|
8
8
|
import { t as CloudflareAiGateway_d_exports } from "./CloudflareAiGateway.mjs";
|
|
9
9
|
import { t as CloudflareCodeMode_d_exports } from "./CloudflareCodeMode.mjs";
|
|
10
10
|
import { t as CloudflareMemory_d_exports } from "./CloudflareMemory.mjs";
|
|
11
11
|
import { t as CloudflareScheduling_d_exports } from "./CloudflareScheduling.mjs";
|
|
12
12
|
import { t as CloudflareSubscriptions_d_exports } from "./CloudflareSubscriptions.mjs";
|
|
13
|
-
import { m as CloudflareThreadClient_d_exports } from "./CloudflareThreadClient-
|
|
14
|
-
import { f as ThreadObject_d_exports } from "./ThreadObject-
|
|
13
|
+
import { m as CloudflareThreadClient_d_exports } from "./CloudflareThreadClient-CmlojpjC.mjs";
|
|
14
|
+
import { f as ThreadObject_d_exports } from "./ThreadObject-Osn-FmcF.mjs";
|
|
15
15
|
import { t as WakeScheduler_d_exports } from "./WakeScheduler.mjs";
|
|
16
16
|
export { Alarm_d_exports as Alarm, BrowserCredentials_d_exports as BrowserCredentials, BrowserSession_d_exports as BrowserSession, BrowserUse_d_exports as BrowserUse, CloudflareAiGateway_d_exports as CloudflareAiGateway, CloudflareBindings_d_exports as CloudflareBindings, CloudflareBrowser_d_exports as CloudflareBrowser, CloudflareCodeMode_d_exports as CloudflareCodeMode, CloudflareConfig_d_exports as CloudflareConfig, CloudflareMemory_d_exports as CloudflareMemory, CloudflareScheduling_d_exports as CloudflareScheduling, CloudflareSubscriptions_d_exports as CloudflareSubscriptions, CloudflareThreadClient_d_exports as CloudflareThreadClient, ThreadObject_d_exports as ThreadObject, WakeScheduler_d_exports as WakeScheduler };
|
package/dist/index.mjs
CHANGED
|
@@ -11,6 +11,6 @@ import { t as WakeScheduler_exports } from "./WakeScheduler.mjs";
|
|
|
11
11
|
import { l as ThreadObject_exports } from "./ThreadObject-Cr1CFWXb.mjs";
|
|
12
12
|
import { t as CloudflareAiGateway_exports } from "./CloudflareAiGateway.mjs";
|
|
13
13
|
import { t as BrowserCredentials_exports } from "./BrowserCredentials.mjs";
|
|
14
|
-
import { i as BrowserSession_exports } from "./BrowserSession-
|
|
14
|
+
import { i as BrowserSession_exports } from "./BrowserSession-CfivQ5JY.mjs";
|
|
15
15
|
import { t as BrowserUse_exports } from "./BrowserUse.mjs";
|
|
16
16
|
export { Alarm_exports as Alarm, BrowserCredentials_exports as BrowserCredentials, BrowserSession_exports as BrowserSession, BrowserUse_exports as BrowserUse, CloudflareAiGateway_exports as CloudflareAiGateway, CloudflareBindings_exports as CloudflareBindings, CloudflareBrowser_exports as CloudflareBrowser, CloudflareCodeMode_exports as CloudflareCodeMode, CloudflareConfig_exports as CloudflareConfig, CloudflareMemory_exports as CloudflareMemory, CloudflareScheduling_exports as CloudflareScheduling, CloudflareSubscriptions_exports as CloudflareSubscriptions, CloudflareThreadClient_exports as CloudflareThreadClient, ThreadObject_exports as ThreadObject, WakeScheduler_exports as WakeScheduler };
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@yielded/agent-platform-cloudflare","version":"0.1.0-beta.
|
|
1
|
+
{"name":"@yielded/agent-platform-cloudflare","version":"0.1.0-beta.185","dependencies":{"@effect/platform-browser":"4.0.5","@effect/sql-sqlite-do":"4.0.5","@yielded/agent":"0.1.0-beta.185","@yielded/agent-storage-cloudflare":"0.1.0-beta.185","@yielded/agent-storage-sql":"0.1.0-beta.185","puppeteer-core":"24.29.0"},"devDependencies":{"@cloudflare/vitest-plugin":"1.4.0","@cloudflare/workers-types":"5.20260926.1","@effect/platform-node":"4.0.5","@effect/sql-d1":"4.0.5","@effect/vitest":"4.0.5","@yielded/agent-testing":"0.1.0-beta.185","effect":"4.0.5","effect-cf":"0.56.6","esbuild":"0.28.1","miniflare":"5.20260811.1-alpha","typescript":"7.0.2","vite":"npm:@voidzero-dev/vite-plus-core@1.1.0","vite-plus":"1.1.0","vitest":"5.0.3"},"peerDependencies":{"effect":"^4.0.3","effect-cf":"^0.56.0"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./alarm":{"types":"./dist/Alarm.d.mts","default":"./dist/Alarm.mjs"},"./browser-rest-capture":{"types":"./dist/BrowserRestCapture.d.mts","default":"./dist/BrowserRestCapture.mjs"},"./browser-rest-crawl":{"types":"./dist/BrowserRestCrawl.d.mts","default":"./dist/BrowserRestCrawl.mjs"},"./cloudflare-bindings":{"types":"./dist/CloudflareBindings.d.mts","default":"./dist/CloudflareBindings.mjs"},"./cloudflare-browser":{"types":"./dist/CloudflareBrowser.d.mts","default":"./dist/CloudflareBrowser.mjs"},"./cloudflare-code-mode":{"types":"./dist/CloudflareCodeMode.d.mts","default":"./dist/CloudflareCodeMode.mjs"},"./cloudflare-config":{"types":"./dist/CloudflareConfig.d.mts","default":"./dist/CloudflareConfig.mjs"},"./cloudflare-memory":{"types":"./dist/CloudflareMemory.d.mts","default":"./dist/CloudflareMemory.mjs"},"./cloudflare-scheduling":{"types":"./dist/CloudflareScheduling.d.mts","default":"./dist/CloudflareScheduling.mjs"},"./cloudflare-subscriptions":{"types":"./dist/CloudflareSubscriptions.d.mts","default":"./dist/CloudflareSubscriptions.mjs"},"./cloudflare-thread-client":{"types":"./dist/CloudflareThreadClient.d.mts","default":"./dist/CloudflareThreadClient.mjs"},"./interactive-browser":{"types":"./dist/InteractiveBrowser.d.mts","default":"./dist/InteractiveBrowser.mjs"},"./browser-session":{"types":"./dist/BrowserSession.d.mts","default":"./dist/BrowserSession.mjs"},"./browser-credentials":{"types":"./dist/BrowserCredentials.d.mts","default":"./dist/BrowserCredentials.mjs"},"./thread-object":{"types":"./dist/ThreadObject.d.mts","default":"./dist/ThreadObject.mjs"},"./wake-scheduler":{"types":"./dist/WakeScheduler.d.mts","default":"./dist/WakeScheduler.mjs"},"./cloudflare-ai-gateway":{"types":"./dist/CloudflareAiGateway.d.mts","default":"./dist/CloudflareAiGateway.mjs"},"./browser-use":{"types":"./dist/BrowserUse.d.mts","default":"./dist/BrowserUse.mjs"}},"description":"Cloudflare Layer assembly for Effect Agent: Durable Objects and Browser Run adapters.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/yielded-dev/agent.git","directory":"packages/platform-cloudflare"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json"}}
|
|
@@ -36,10 +36,7 @@ export class CredentialTarget extends Schema.Class<CredentialTarget>("Credential
|
|
|
36
36
|
}) {}
|
|
37
37
|
|
|
38
38
|
/** Selectors identify one native form. Roles explicitly select material; no field inference occurs. */
|
|
39
|
-
export class
|
|
40
|
-
"FillCredentialRequest",
|
|
41
|
-
)({
|
|
42
|
-
credential: Schema.NonEmptyString.check(Schema.isMaxLength(256)),
|
|
39
|
+
export class CredentialForm extends Schema.Class<CredentialForm>("CredentialForm")({
|
|
43
40
|
kind: CredentialKind,
|
|
44
41
|
frame: Schema.optionalKey(Schema.Array(Selector).check(Schema.isMaxLength(8))),
|
|
45
42
|
fields: Schema.Array(Schema.Struct({ selector: Selector, role: CredentialFieldRole })).check(
|
|
@@ -48,7 +45,35 @@ export class FillCredentialRequest extends Schema.Class<FillCredentialRequest>(
|
|
|
48
45
|
),
|
|
49
46
|
}) {}
|
|
50
47
|
|
|
51
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Private, persistable evidence for an exact page, document and native form controls.
|
|
50
|
+
* Keep it with the host's one-use request, never accept a binding from a model or submitter.
|
|
51
|
+
* A detached document or replaced control requires a fresh user request.
|
|
52
|
+
*/
|
|
53
|
+
export class CredentialBinding extends Schema.Class<CredentialBinding>("CredentialBinding")({
|
|
54
|
+
version: Schema.Literal(1),
|
|
55
|
+
pageId: Schema.NonEmptyString.check(Schema.isMaxLength(256)),
|
|
56
|
+
frameId: Schema.NonEmptyString.check(Schema.isMaxLength(256)),
|
|
57
|
+
target: CredentialTarget,
|
|
58
|
+
nodes: Schema.Array(Schema.Int.check(Schema.isGreaterThan(0))).check(
|
|
59
|
+
Schema.isMinLength(3),
|
|
60
|
+
Schema.isMaxLength(10),
|
|
61
|
+
),
|
|
62
|
+
shape: Schema.String.check(Schema.isPattern(/^[a-f0-9]{64}$/)),
|
|
63
|
+
}) {}
|
|
64
|
+
|
|
65
|
+
export class FillCredentialRequest extends Schema.Class<FillCredentialRequest>(
|
|
66
|
+
"FillCredentialRequest",
|
|
67
|
+
)({
|
|
68
|
+
...CredentialForm.fields,
|
|
69
|
+
credential: Schema.NonEmptyString.check(Schema.isMaxLength(256)),
|
|
70
|
+
/** Required for delayed user entry; omitted for immediate, host-authorized vault fills. */
|
|
71
|
+
binding: Schema.optionalKey(CredentialBinding),
|
|
72
|
+
}) {}
|
|
73
|
+
|
|
74
|
+
const SecretText = Schema.Redacted(Schema.NonEmptyString.check(Schema.isMaxLength(1024)), {
|
|
75
|
+
disallowJsonEncode: true,
|
|
76
|
+
});
|
|
52
77
|
|
|
53
78
|
/** Host-only material. Never return or encode it through a Tool, log, trace, or checkpoint. */
|
|
54
79
|
export const LoginCredential = Schema.TaggedStruct("LoginCredential", {
|
|
@@ -59,12 +84,20 @@ export const LoginCredential = Schema.TaggedStruct("LoginCredential", {
|
|
|
59
84
|
/** Security codes are transient; the host must not persist them. */
|
|
60
85
|
export const CardCredential = Schema.TaggedStruct("CardCredential", {
|
|
61
86
|
name: SecretText,
|
|
62
|
-
number: Schema.Redacted(Schema.String.check(Schema.isPattern(/^\d{12,19}$/))
|
|
87
|
+
number: Schema.Redacted(Schema.String.check(Schema.isPattern(/^\d{12,19}$/)), {
|
|
88
|
+
disallowJsonEncode: true,
|
|
89
|
+
}),
|
|
63
90
|
expiry: SecretText,
|
|
64
|
-
expiryMonth: Schema.Redacted(Schema.String.check(Schema.isPattern(/^(0[1-9]|1[0-2])$/))
|
|
65
|
-
|
|
91
|
+
expiryMonth: Schema.Redacted(Schema.String.check(Schema.isPattern(/^(0[1-9]|1[0-2])$/)), {
|
|
92
|
+
disallowJsonEncode: true,
|
|
93
|
+
}),
|
|
94
|
+
expiryYear: Schema.Redacted(Schema.String.check(Schema.isPattern(/^\d{4}$/)), {
|
|
95
|
+
disallowJsonEncode: true,
|
|
96
|
+
}),
|
|
66
97
|
securityCode: Schema.optionalKey(
|
|
67
|
-
Schema.Redacted(Schema.String.check(Schema.isPattern(/^\d{3,4}$/))
|
|
98
|
+
Schema.Redacted(Schema.String.check(Schema.isPattern(/^\d{3,4}$/)), {
|
|
99
|
+
disallowJsonEncode: true,
|
|
100
|
+
}),
|
|
68
101
|
),
|
|
69
102
|
});
|
|
70
103
|
|
package/src/BrowserSession.ts
CHANGED
|
@@ -16,6 +16,8 @@ import type { Browser, Page } from "puppeteer-core/lib/esm/puppeteer/puppeteer-c
|
|
|
16
16
|
|
|
17
17
|
import {
|
|
18
18
|
CredentialFillError,
|
|
19
|
+
type CredentialBinding,
|
|
20
|
+
type CredentialForm,
|
|
19
21
|
type BrowserCredentialAccess,
|
|
20
22
|
type CredentialFillResult,
|
|
21
23
|
type FillCredentialRequest,
|
|
@@ -28,8 +30,16 @@ import {
|
|
|
28
30
|
BrowserRunLiveViewResult,
|
|
29
31
|
} from "./InteractiveBrowser.ts";
|
|
30
32
|
import { BrowserRunBinding, type BrowserRunAttachment } from "./internal/browser-binding.ts";
|
|
31
|
-
import {
|
|
32
|
-
|
|
33
|
+
import {
|
|
34
|
+
BrowserSessionPage,
|
|
35
|
+
fillCredential,
|
|
36
|
+
prepareCredential,
|
|
37
|
+
} from "./internal/browser-credentials.ts";
|
|
38
|
+
import {
|
|
39
|
+
inheritBrowserReport,
|
|
40
|
+
reportBrowserCause,
|
|
41
|
+
reportedBrowserError,
|
|
42
|
+
} from "./internal/browser-failure.ts";
|
|
33
43
|
import { BrowserRunReadonlyLiveView } from "./internal/browser-readonly-live-view.ts";
|
|
34
44
|
import {
|
|
35
45
|
BrowserRunSessionLifecycle,
|
|
@@ -111,6 +121,13 @@ export interface BrowserSession {
|
|
|
111
121
|
action: (page: Page) => Promise<A>,
|
|
112
122
|
options?: { readonly timeoutMillis: number },
|
|
113
123
|
) => Effect.Effect<A, E | BrowserSessionError, R>;
|
|
124
|
+
/**
|
|
125
|
+
* Prepare a delayed private-entry request within the command/session deadline; timeout closes
|
|
126
|
+
* the browser. The host owns persistence, expiry and one-use consumption.
|
|
127
|
+
*/
|
|
128
|
+
readonly prepareCredential: (
|
|
129
|
+
request: CredentialForm,
|
|
130
|
+
) => Effect.Effect<CredentialBinding, CredentialFillError | BrowserSessionError>;
|
|
114
131
|
/**
|
|
115
132
|
* Resolves host-owned material under fresh credential grants. Never submits or retries a write.
|
|
116
133
|
* Credential timeouts retain acknowledged writes and dispatch evidence alongside cleanup.
|
|
@@ -217,6 +234,7 @@ export class BrowserSessions extends Context.Service<
|
|
|
217
234
|
* No session is exposed before retain succeeds. Failed acquisition releases its attachment
|
|
218
235
|
* immediately; after retention the application owns remote cleanup. The 30-second acquisition
|
|
219
236
|
* timeout ends before use; each command retains its own timeout and the fixed session expiry.
|
|
237
|
+
* Failed acquisition reports confirmed cleanup only after exact-session termination succeeds.
|
|
220
238
|
*/
|
|
221
239
|
readonly createAttached: <E, R>(
|
|
222
240
|
options: BrowserSessionOptions,
|
|
@@ -294,6 +312,7 @@ export class BrowserSessions extends Context.Service<
|
|
|
294
312
|
const allocate = Effect.fnUntraced(function* <E, R>(
|
|
295
313
|
input: BrowserSessionOptions,
|
|
296
314
|
retain: (reference: BrowserSessionReference) => Effect.Effect<void, E, R>,
|
|
315
|
+
cleanupState: { result: BrowserSessionError["cleanup"] },
|
|
297
316
|
) {
|
|
298
317
|
const options = yield* decode(BrowserSessionOptions, input);
|
|
299
318
|
const expiresAt = (yield* Clock.currentTimeMillis) + options.maxElapsedMillis;
|
|
@@ -304,8 +323,17 @@ export class BrowserSessions extends Context.Service<
|
|
|
304
323
|
const runCleanup = Effect.runPromiseWith(yield* Effect.context<never>());
|
|
305
324
|
|
|
306
325
|
yield* Effect.addFinalizer(() =>
|
|
307
|
-
sessionId === undefined || retained
|
|
326
|
+
sessionId === undefined || retained
|
|
327
|
+
? Effect.void
|
|
328
|
+
: cleanup(sessionId).pipe(
|
|
329
|
+
Effect.tap((result) =>
|
|
330
|
+
Effect.sync(() => {
|
|
331
|
+
cleanupState.result = result;
|
|
332
|
+
}),
|
|
333
|
+
),
|
|
334
|
+
),
|
|
308
335
|
);
|
|
336
|
+
cleanupState.result = "unconfirmed";
|
|
309
337
|
sessionId = yield* native("session.acquire", async (signal) => {
|
|
310
338
|
const id = Redacted.make(
|
|
311
339
|
await binding.acquire(options.keepAliveMillis ?? 600_000, "session.acquire"),
|
|
@@ -340,6 +368,7 @@ export class BrowserSessions extends Context.Service<
|
|
|
340
368
|
Effect.tap(() =>
|
|
341
369
|
Effect.sync(() => {
|
|
342
370
|
retained = true;
|
|
371
|
+
cleanupState.result = "not-requested";
|
|
343
372
|
}),
|
|
344
373
|
),
|
|
345
374
|
),
|
|
@@ -348,19 +377,36 @@ export class BrowserSessions extends Context.Service<
|
|
|
348
377
|
return { reference, page, ...connection };
|
|
349
378
|
});
|
|
350
379
|
|
|
351
|
-
const create = <E, R>(
|
|
380
|
+
const create = Effect.fnUntraced(function* <E, R>(
|
|
352
381
|
input: BrowserSessionOptions,
|
|
353
382
|
retain: (reference: BrowserSessionReference) => Effect.Effect<void, E, R>,
|
|
354
|
-
)
|
|
355
|
-
|
|
383
|
+
) {
|
|
384
|
+
const cleanupState: { result: BrowserSessionError["cleanup"] } = {
|
|
385
|
+
result: "not-requested",
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
return yield* allocate(input, retain, cleanupState).pipe(
|
|
356
389
|
Effect.map(({ reference }) => reference),
|
|
357
|
-
Effect.scoped,
|
|
358
390
|
Effect.timeoutOrElse({
|
|
359
391
|
duration: "30 seconds",
|
|
360
392
|
orElse: () => Effect.fail(failure("timeout")),
|
|
361
393
|
}),
|
|
394
|
+
Effect.scoped,
|
|
395
|
+
Effect.catchCause((cause) =>
|
|
396
|
+
Effect.failCause(
|
|
397
|
+
Cause.map(cause, (error) =>
|
|
398
|
+
error instanceof BrowserSessionError
|
|
399
|
+
? inheritBrowserReport(
|
|
400
|
+
error,
|
|
401
|
+
BrowserSessionError.make({ ...error, cleanup: cleanupState.result }),
|
|
402
|
+
)
|
|
403
|
+
: error,
|
|
404
|
+
),
|
|
405
|
+
),
|
|
406
|
+
),
|
|
362
407
|
Effect.withTracerEnabled(false),
|
|
363
408
|
);
|
|
409
|
+
});
|
|
364
410
|
|
|
365
411
|
const makeSession = Effect.fnUntraced(function* (
|
|
366
412
|
reference: BrowserSessionReference,
|
|
@@ -476,6 +522,24 @@ export class BrowserSessions extends Context.Service<
|
|
|
476
522
|
: decode(PositiveMillis, options.timeoutMillis).pipe(
|
|
477
523
|
Effect.flatMap((timeoutMillis) => run(authorize, action, false, timeoutMillis)),
|
|
478
524
|
),
|
|
525
|
+
prepareCredential: (request) =>
|
|
526
|
+
runEffect((commandTimeoutMillis) =>
|
|
527
|
+
prepareCredential(request).pipe(
|
|
528
|
+
Effect.provideService(BrowserSessionPage, {
|
|
529
|
+
page: currentPage,
|
|
530
|
+
commandTimeoutMillis,
|
|
531
|
+
}),
|
|
532
|
+
Effect.timeoutOrElse({
|
|
533
|
+
duration: commandTimeoutMillis,
|
|
534
|
+
orElse: () =>
|
|
535
|
+
terminate.pipe(
|
|
536
|
+
Effect.flatMap((closed) =>
|
|
537
|
+
Effect.fail(failure("timeout", "not-dispatched", closed)),
|
|
538
|
+
),
|
|
539
|
+
),
|
|
540
|
+
}),
|
|
541
|
+
),
|
|
542
|
+
),
|
|
479
543
|
fillCredential: (request) =>
|
|
480
544
|
runEffect((commandTimeoutMillis) =>
|
|
481
545
|
fillCredential(request).pipe(
|
|
@@ -581,7 +645,11 @@ export class BrowserSessions extends Context.Service<
|
|
|
581
645
|
) {
|
|
582
646
|
const scope = yield* Scope.fork(yield* Effect.scope);
|
|
583
647
|
|
|
584
|
-
|
|
648
|
+
const cleanupState: { result: BrowserSessionError["cleanup"] } = {
|
|
649
|
+
result: "not-requested",
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
return yield* allocate(input, retain, cleanupState).pipe(
|
|
585
653
|
Effect.flatMap(({ reference, browser, page, retire }) =>
|
|
586
654
|
makeSession(reference, browser, page, retire),
|
|
587
655
|
),
|
|
@@ -591,6 +659,18 @@ export class BrowserSessions extends Context.Service<
|
|
|
591
659
|
orElse: () => Effect.fail(failure("timeout")),
|
|
592
660
|
}),
|
|
593
661
|
Effect.onExit((exit) => (Exit.isFailure(exit) ? Scope.close(scope, exit) : Effect.void)),
|
|
662
|
+
Effect.catchCause((cause) =>
|
|
663
|
+
Effect.failCause(
|
|
664
|
+
Cause.map(cause, (error) =>
|
|
665
|
+
error instanceof BrowserSessionError
|
|
666
|
+
? inheritBrowserReport(
|
|
667
|
+
error,
|
|
668
|
+
BrowserSessionError.make({ ...error, cleanup: cleanupState.result }),
|
|
669
|
+
)
|
|
670
|
+
: error,
|
|
671
|
+
),
|
|
672
|
+
),
|
|
673
|
+
),
|
|
594
674
|
Effect.withTracerEnabled(false),
|
|
595
675
|
);
|
|
596
676
|
});
|
package/src/BrowserUse.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
SendRequest,
|
|
8
8
|
Tab,
|
|
9
9
|
} from "@yielded/agent/browser-use";
|
|
10
|
-
import { Effect, Layer, Schema, Semaphore } from "effect";
|
|
10
|
+
import { Cause, Effect, Layer, Schema, Semaphore } from "effect";
|
|
11
11
|
import type {
|
|
12
12
|
CDPSession,
|
|
13
13
|
Frame,
|
|
@@ -15,6 +15,11 @@ import type {
|
|
|
15
15
|
} from "puppeteer-core/lib/esm/puppeteer/puppeteer-core-browser.js";
|
|
16
16
|
|
|
17
17
|
import type { BrowserSession, BrowserSessionError } from "./BrowserSession.ts";
|
|
18
|
+
import {
|
|
19
|
+
browserFailure,
|
|
20
|
+
reportBrowserCause,
|
|
21
|
+
reportedBrowserError,
|
|
22
|
+
} from "./internal/browser-failure.ts";
|
|
18
23
|
|
|
19
24
|
export type Command =
|
|
20
25
|
| { readonly kind: "connect" | "tabs" | "new-tab" }
|
|
@@ -252,6 +257,8 @@ export const make = Effect.fnUntraced(function* <R>(
|
|
|
252
257
|
invalid("Browser lifecycle commands belong to the host; use the tab helpers"),
|
|
253
258
|
);
|
|
254
259
|
|
|
260
|
+
const runReport = Effect.runPromiseWith(yield* Effect.context<never>());
|
|
261
|
+
|
|
255
262
|
const result: unknown = yield* run(
|
|
256
263
|
{ kind: "send", request: value },
|
|
257
264
|
async ({ cdp, page }, frame): Promise<unknown> => {
|
|
@@ -269,10 +276,42 @@ export const make = Effect.fnUntraced(function* <R>(
|
|
|
269
276
|
const connection = source.connection();
|
|
270
277
|
|
|
271
278
|
if (connection === undefined) return invalid("Frame connection is closed");
|
|
272
|
-
|
|
279
|
+
|
|
280
|
+
let lookup: Awaited<ReturnType<typeof source.send<"Target.getTargetInfo">>>;
|
|
281
|
+
|
|
282
|
+
try {
|
|
283
|
+
lookup = await source.send("Target.getTargetInfo");
|
|
284
|
+
} catch (cause) {
|
|
285
|
+
await runReport(
|
|
286
|
+
reportBrowserCause("browser-use.frame.target-info", Cause.fail(cause)),
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
return reportedBrowserError(
|
|
290
|
+
BrowserUseError.make({
|
|
291
|
+
code: "browser",
|
|
292
|
+
message: "Frame inspection failed before the requested command was sent",
|
|
293
|
+
dispatch: "not-dispatched",
|
|
294
|
+
}),
|
|
295
|
+
);
|
|
296
|
+
}
|
|
273
297
|
|
|
274
298
|
// Keep arbitrary commands off Puppeteer's own event-tracking session.
|
|
275
|
-
|
|
299
|
+
let attached: CDPSession;
|
|
300
|
+
|
|
301
|
+
try {
|
|
302
|
+
attached = await connection.createSession(lookup.targetInfo);
|
|
303
|
+
} catch (cause) {
|
|
304
|
+
await runReport(reportBrowserCause("browser-use.frame.attach", Cause.fail(cause)));
|
|
305
|
+
|
|
306
|
+
return reportedBrowserError(
|
|
307
|
+
BrowserUseError.make({
|
|
308
|
+
code: "browser",
|
|
309
|
+
message: "Frame attachment failed before the requested command was sent",
|
|
310
|
+
dispatch: "not-dispatched",
|
|
311
|
+
}),
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
target = attached;
|
|
276
315
|
connections.set(source, target);
|
|
277
316
|
}
|
|
278
317
|
if (
|
|
@@ -286,7 +325,15 @@ export const make = Effect.fnUntraced(function* <R>(
|
|
|
286
325
|
}
|
|
287
326
|
|
|
288
327
|
// Bind the native receiver explicitly; decode the foreign response below.
|
|
289
|
-
|
|
328
|
+
try {
|
|
329
|
+
return await Reflect.apply(target.send.bind(target), undefined, [
|
|
330
|
+
value.method,
|
|
331
|
+
value.params,
|
|
332
|
+
]);
|
|
333
|
+
} catch (cause) {
|
|
334
|
+
// oxlint-disable-next-line effect/no-untyped-throw -- This native Promise preserves existing tab failures and reports sanitized frame stages through BrowserSession.run.
|
|
335
|
+
throw frame === undefined ? cause : browserFailure("browser-use.frame.send", cause);
|
|
336
|
+
}
|
|
290
337
|
},
|
|
291
338
|
value.targetId,
|
|
292
339
|
value.frameId,
|