@effect-agent/platform-cloudflare 0.1.0-beta.52 → 0.1.0-beta.54

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.
Files changed (33) hide show
  1. package/dist/Alarm.d.mts +45 -6
  2. package/dist/Alarm.mjs +111 -47
  3. package/dist/Alarm.mjs.map +1 -1
  4. package/dist/BrowserRestCapture.mjs +1 -1
  5. package/dist/{CloudflareBrowser-1jeZx3_g.mjs → CloudflareBrowser-Bj22nNUT.mjs} +12 -13
  6. package/dist/CloudflareBrowser-Bj22nNUT.mjs.map +1 -0
  7. package/dist/CloudflareBrowser.mjs +1 -1
  8. package/dist/CloudflareThreadClient.d.mts +18 -17
  9. package/dist/CloudflareThreadClient.mjs +2 -1
  10. package/dist/CloudflareThreadClient.mjs.map +1 -1
  11. package/dist/ProtectedBrowser.d.mts +5 -3
  12. package/dist/ProtectedBrowser.mjs +180 -36
  13. package/dist/ProtectedBrowser.mjs.map +1 -1
  14. package/dist/{ThreadObject-BSRVxtPI.d.mts → ThreadObject-6_j7YgMV.d.mts} +48 -37
  15. package/dist/{ThreadObject-BY8axaWT.mjs → ThreadObject-D2eP-tEO.mjs} +44 -20
  16. package/dist/ThreadObject-D2eP-tEO.mjs.map +1 -0
  17. package/dist/ThreadObject.d.mts +2 -2
  18. package/dist/ThreadObject.mjs +1 -1
  19. package/dist/index.d.mts +1 -1
  20. package/dist/index.mjs +2 -2
  21. package/package.json +1 -1
  22. package/src/Alarm.ts +242 -72
  23. package/src/CloudflareThreadClient.ts +6 -0
  24. package/src/ThreadObject.ts +1 -0
  25. package/src/internal/browser-quick-action.ts +14 -11
  26. package/src/internal/layers.ts +93 -9
  27. package/src/internal/progress-wait.ts +17 -13
  28. package/src/protected-browser/binding.ts +2 -1
  29. package/src/protected-browser/inspect-frame.ts +62 -19
  30. package/src/protected-browser/native.ts +50 -5
  31. package/src/protected-browser/policy.ts +138 -13
  32. package/dist/CloudflareBrowser-1jeZx3_g.mjs.map +0 -1
  33. package/dist/ThreadObject-BY8axaWT.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CloudflareBrowser-Bj22nNUT.mjs","names":[],"sources":["../src/internal/browser-quick-action.ts","../src/CloudflareBrowser.ts"],"sourcesContent":["/// <reference types=\"@cloudflare/workers-types\" />\n\nimport {\n PageCapture,\n PageCaptureInferenceUse,\n PageCaptureInferencePolicyError,\n PageCaptureNavigationError,\n PageCaptureOutputLimitError,\n PageCaptureProtocolError,\n PageCaptureRateLimitedError,\n PageCaptureResourceUse,\n PageCaptureResult,\n PageCaptureUnsupportedError,\n PageContentCaptured,\n PageLinksCaptured,\n PageMarkdownCaptured,\n PageScrapeCaptured,\n PageStructuredCaptured,\n type PageCaptureAction,\n type PageCaptureCapture,\n type PageCaptureError,\n type PageCaptureOutput,\n type PageCaptureRequest,\n} from \"@effect-agent/sandbox/PageCapture\";\nimport {\n PageScreenshot,\n PageScreenshotOutputLimitError,\n PageScreenshotResult,\n type PageScreenshotCapture,\n type PageScreenshotError,\n type PageScreenshotRequest,\n} from \"@effect-agent/sandbox/PageScreenshot\";\nimport { SandboxImplementation } from \"@effect-agent/sandbox/Sandbox\";\nimport { Context, Effect, Layer, Option, Schema } from \"effect\";\n\n/**\n * The Cloudflare Browser Run Quick Action `PageCapture` adapter (capability\n * spec §9.2). Each capture is one stateless `quickAction()` RPC on the\n * Wrangler `browser` binding: the platform renders the target in a managed\n * headless browser and returns one bounded output; the adapter holds no\n * session and no state between passes. The binding requires a Worker\n * compatibility date of `2026-03-24` or later, and local `wrangler dev` needs\n * remote mode (`\"remote\": true` on the binding) because `quickAction` has no\n * local implementation.\n *\n * Rendered output is untrusted, attacker-influenced content; this adapter\n * only bounds and types it. Deployment class `E` only: no durability claim.\n */\nexport const browserQuickActionImplementation = SandboxImplementation.make({\n isolation: \"isolated\",\n identity: \"cloudflare-browser-quick-action\",\n});\n\n/**\n * Effect-native client captured by the binding service. Its option types come\n * directly from the pinned Workers declarations rather than a local copy.\n */\nexport interface BrowserQuickActionClient {\n readonly screenshot: (\n options: BrowserRunScreenshotOptions,\n ) => Effect.Effect<Response, BrowserQuickActionRpcError>;\n readonly content: (\n options: BrowserRunContentOptions,\n ) => Effect.Effect<Response, BrowserQuickActionRpcError>;\n readonly markdown: (\n options: BrowserRunMarkdownOptions,\n ) => Effect.Effect<Response, BrowserQuickActionRpcError>;\n readonly links: (\n options: BrowserRunLinksOptions,\n ) => Effect.Effect<Response, BrowserQuickActionRpcError>;\n readonly scrape: (\n options: BrowserRunScrapeOptions,\n ) => Effect.Effect<Response, BrowserQuickActionRpcError>;\n readonly json: (\n options: BrowserRunJsonOptions,\n ) => Effect.Effect<Response, BrowserQuickActionRpcError>;\n}\n\n/** A native binding RPC rejected before it returned an HTTP response. */\nexport class BrowserQuickActionRpcError extends Schema.TaggedError<BrowserQuickActionRpcError>()(\n \"BrowserQuickActionRpcError\",\n {\n action: Schema.Literals([\"screenshot\", \"content\", \"markdown\", \"links\", \"scrape\", \"json\"]),\n cause: Schema.Defect(),\n },\n) {}\n\nexport interface BrowserQuickActionCaptureOptions {\n /** The resolved Wrangler `browser` binding (DEPLOY-014: supplied, never ambient). */\n readonly browser: BrowserRun;\n}\n\n/** Host-owned browser binding authority, supplied explicitly at the composition root. */\nexport class BrowserQuickActionBrowserBinding extends Context.Service<\n BrowserQuickActionBrowserBinding,\n BrowserQuickActionClient\n>()(\"@effect-agent/platform-cloudflare/BrowserQuickActionBrowserBinding\") {\n static layer(\n options: BrowserQuickActionCaptureOptions,\n ): Layer.Layer<BrowserQuickActionBrowserBinding> {\n const browser = options.browser;\n\n const invoke = Effect.fn(\"BrowserQuickActionBrowserBinding.invoke\")(function* (\n action: \"screenshot\" | \"content\" | \"markdown\" | \"links\" | \"scrape\" | \"json\",\n evaluate: () => Promise<Response>,\n ): Effect.fn.Return<Response, BrowserQuickActionRpcError> {\n return yield* Effect.tryPromise({\n try: evaluate,\n catch: (cause) => BrowserQuickActionRpcError.make({ action, cause }),\n });\n });\n\n return Layer.succeed(BrowserQuickActionBrowserBinding)({\n screenshot: (request) =>\n invoke(\"screenshot\", () => browser.quickAction(\"screenshot\", request)),\n content: (request) => invoke(\"content\", () => browser.quickAction(\"content\", request)),\n markdown: (request) => invoke(\"markdown\", () => browser.quickAction(\"markdown\", request)),\n links: (request) => invoke(\"links\", () => browser.quickAction(\"links\", request)),\n scrape: (request) => invoke(\"scrape\", () => browser.quickAction(\"scrape\", request)),\n json: (request) => invoke(\"json\", () => browser.quickAction(\"json\", request)),\n });\n }\n}\n\n/** Host-owned authorization and accounting for one Workers AI extraction. */\nexport interface BrowserQuickActionWorkersAiPolicy {\n readonly authorizeAndAccount: (\n request: PageCaptureRequest,\n ) => Effect.Effect<void, BrowserQuickActionWorkersAiPolicyError>;\n}\n\n/** Host-only diagnostic for a denied or unaccounted Workers AI extraction. */\nexport class BrowserQuickActionWorkersAiPolicyError extends Schema.TaggedError<BrowserQuickActionWorkersAiPolicyError>()(\n \"BrowserQuickActionWorkersAiPolicyError\",\n {\n reason: Schema.Literals([\"authorization\", \"accounting\"]),\n message: Schema.String.check(Schema.isMaxLength(8_000)),\n cause: Schema.optionalKey(Schema.Defect()),\n },\n) {}\n\n/** Explicit host-owned authority and accounting for separately billed Workers AI extraction. */\nexport class BrowserQuickActionWorkersAi extends Context.Service<\n BrowserQuickActionWorkersAi,\n BrowserQuickActionWorkersAiPolicy\n>()(\"@effect-agent/platform-cloudflare/BrowserQuickActionWorkersAi\") {\n static layer(\n policy: BrowserQuickActionWorkersAiPolicy,\n ): Layer.Layer<BrowserQuickActionWorkersAi> {\n return Layer.succeed(BrowserQuickActionWorkersAi)(policy);\n }\n}\n\nconst MAX_DIAGNOSTIC_LENGTH = 8_000;\nconst boundedDiagnostic = (message: string): string => message.slice(0, MAX_DIAGNOSTIC_LENGTH);\n\nconst QuickActionSuccessEnvelope = Schema.Struct({\n success: Schema.Literal(true),\n result: Schema.Json,\n});\n\nconst QuickActionErrorEnvelope = Schema.Struct({\n success: Schema.Literal(false),\n errors: Schema.Array(\n Schema.Struct({\n message: Schema.String,\n code: Schema.optionalKey(Schema.Number),\n detail: Schema.optionalKey(Schema.String),\n path: Schema.optionalKey(Schema.String),\n }),\n ),\n rawAiResponse: Schema.optionalKey(Schema.String),\n});\n\nconst QuickActionEnvelope = Schema.Union([QuickActionSuccessEnvelope, QuickActionErrorEnvelope]);\nconst decodeEnvelope = Schema.decodeUnknownOption(Schema.fromJsonString(QuickActionEnvelope));\n\n/** Project the schema-validated request onto Cloudflare's native common options. */\nconst quickActionCommonOptions = (request: PageCaptureRequest): BrowserRunCommonOptions => {\n const options: BrowserRunBaseOptions = {};\n const navigation = request.navigation;\n\n if (navigation !== undefined) {\n const goto: NonNullable<BrowserRunBaseOptions[\"gotoOptions\"]> = {};\n\n if (navigation.waitUntil !== undefined) goto.waitUntil = navigation.waitUntil;\n if (navigation.timeoutMillis !== undefined) goto.timeout = navigation.timeoutMillis;\n if (Object.keys(goto).length > 0) options.gotoOptions = goto;\n if (navigation.waitForSelector !== undefined) {\n options.waitForSelector = {\n selector: navigation.waitForSelector.selector,\n ...(navigation.waitForSelector.timeoutMillis === undefined\n ? {}\n : { timeout: navigation.waitForSelector.timeoutMillis }),\n };\n }\n }\n if (request.viewport !== undefined) {\n options.viewport = { width: request.viewport.width, height: request.viewport.height };\n }\n if (request.resourcePolicy !== undefined) {\n if (request.resourcePolicy.rejectResourceTypes !== undefined) {\n options.rejectResourceTypes = [...request.resourcePolicy.rejectResourceTypes];\n }\n if (request.resourcePolicy.allowRequestPatterns !== undefined) {\n options.allowRequestPattern = [...request.resourcePolicy.allowRequestPatterns];\n }\n }\n\n return request.target._tag === \"PageUrlTarget\"\n ? { ...options, url: request.target.url }\n : { ...options, html: request.target.html };\n};\n\n/** Dispatch through Cloudflare's native action-specific overloads. */\nconst executeQuickAction = (\n browser: BrowserQuickActionClient,\n request: PageCaptureRequest,\n): Effect.Effect<Response, BrowserQuickActionRpcError> => {\n const options = quickActionCommonOptions(request);\n\n switch (request.action._tag) {\n case \"CapturePageContent\": {\n return browser.content(options);\n }\n case \"CapturePageMarkdown\": {\n return browser.markdown(options);\n }\n case \"CapturePageLinks\": {\n return browser.links({\n ...options,\n ...(request.action.visibleLinksOnly === undefined\n ? {}\n : { visibleLinksOnly: request.action.visibleLinksOnly }),\n });\n }\n case \"CapturePageScrape\": {\n return browser.scrape({\n ...options,\n elements: request.action.selectors.map((selector) => ({ selector })),\n });\n }\n case \"CapturePageStructured\": {\n return browser.json({\n ...options,\n response_format: {\n type: \"json_schema\",\n json_schema: request.action.responseFormat,\n },\n ...(request.action.prompt === undefined ? {} : { prompt: request.action.prompt }),\n });\n }\n }\n};\n\nconst protocolError = (message: string, cause?: unknown): PageCaptureProtocolError =>\n PageCaptureProtocolError.make({\n implementation: browserQuickActionImplementation,\n message: boundedDiagnostic(message),\n ...(cause === undefined ? {} : { cause }),\n });\n\nconst navigationError = (message: string, cause?: unknown): PageCaptureNavigationError =>\n PageCaptureNavigationError.make({\n implementation: browserQuickActionImplementation,\n message: boundedDiagnostic(message),\n ...(cause === undefined ? {} : { cause }),\n });\n\n/** Preserve bounded remote diagnostics for the host without exposing their text to a model. */\nconst privateResponseCause = (bodyText: string): Error | undefined =>\n bodyText.length === 0 ? undefined : new Error(boundedDiagnostic(bodyText));\n\n/** Foreign cancellation must not keep a response Scope open indefinitely. */\nconst cancelResponse = (cancel: () => Promise<void>, warning: string): Effect.Effect<void> =>\n Effect.tryPromise({ try: cancel, catch: () => undefined }).pipe(\n Effect.interruptible,\n Effect.timeoutOrElse({\n duration: \"1 second\",\n orElse: () => Effect.fail(undefined),\n }),\n Effect.catch(() => Effect.logWarning(warning)),\n );\n\nconst releaseResponseReader = (\n reader: ReadableStreamDefaultReader<Uint8Array>,\n): Effect.Effect<void> =>\n cancelResponse(() => reader.cancel(), \"Canceling the Quick Action response failed\").pipe(\n Effect.ensuring(\n Effect.try({\n try: () => reader.releaseLock(),\n catch: (cause) => protocolError(\"Releasing the Quick Action response failed\", cause),\n }).pipe(Effect.catch((error) => Effect.logWarning(error.message))),\n ),\n );\n\nconst readBoundedResponse = Effect.fn(\"BrowserQuickActionCapture.readResponse\")(function* (\n response: Response,\n request: PageCaptureRequest,\n) {\n const body = response.body;\n\n if (body === null) return \"\";\n\n const reader = yield* Effect.acquireRelease(\n Effect.try({\n try: () => body.getReader(),\n catch: (cause) => protocolError(\"Opening the Quick Action response failed\", cause),\n }),\n releaseResponseReader,\n );\n\n const decoder = new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: false });\n let observedBytes = 0;\n let bodyText = \"\";\n\n while (true) {\n const chunk = yield* Effect.tryPromise({\n try: () => reader.read(),\n catch: (cause) => protocolError(\"Reading the Quick Action response failed\", cause),\n });\n\n if (chunk.done) break;\n\n observedBytes += chunk.value.byteLength;\n if (observedBytes > request.limits.maxOutputBytes) {\n return yield* PageCaptureOutputLimitError.make({\n implementation: browserQuickActionImplementation,\n limit: request.limits.maxOutputBytes,\n observed: observedBytes,\n });\n }\n\n bodyText += yield* Effect.try({\n try: () => decoder.decode(chunk.value, { stream: true }),\n catch: (cause) => protocolError(\"Decoding the Quick Action response failed\", cause),\n });\n }\n\n return (\n bodyText +\n (yield* Effect.try({\n try: () => decoder.decode(),\n catch: (cause) => protocolError(\"Decoding the Quick Action response failed\", cause),\n }))\n );\n}, Effect.scoped);\n\n/**\n * Retry-After arrives in whole seconds; a non-integer form (an HTTP date) is\n * dropped rather than guessed at.\n */\nconst retryAfterMillis = (response: Response): number | undefined => {\n const header = response.headers.get(\"Retry-After\");\n\n if (header === null) return undefined;\n const seconds = Number(header);\n\n if (!Number.isSafeInteger(seconds) || seconds < 0) return undefined;\n const millis = seconds * 1_000;\n\n return Number.isSafeInteger(millis) ? millis : undefined;\n};\n\nconst browserMillis = (response: Response): number | undefined => {\n const header = response.headers.get(\"X-Browser-Ms-Used\");\n\n if (header === null) return undefined;\n const millis = Number(header);\n\n return Number.isSafeInteger(millis) && millis >= 0 ? millis : undefined;\n};\n\n/** Only trusted response metadata chooses transport framing; page text never does. */\nconst isJsonResponse = (response: Response): boolean => {\n const contentType = response.headers.get(\"Content-Type\");\n\n if (contentType === null) return false;\n const mediaType = contentType.split(\";\", 1)[0]?.trim().toLowerCase();\n\n return mediaType === \"application/json\" || mediaType?.endsWith(\"+json\") === true;\n};\n\nconst parseOutput = (\n action: PageCaptureAction,\n bodyText: string,\n response: Response,\n): PageCaptureOutput | PageCaptureNavigationError | PageCaptureProtocolError => {\n if (!isJsonResponse(response)) {\n return protocolError(\n \"The Quick Action success response was not a JSON response envelope\",\n privateResponseCause(bodyText),\n );\n }\n const envelope = decodeEnvelope(bodyText);\n\n if (Option.isNone(envelope)) {\n return protocolError(\n \"The JSON Quick Action response did not carry a valid response envelope\",\n privateResponseCause(bodyText),\n );\n }\n if (!envelope.value.success) {\n return navigationError(\n \"The Quick Action reported a navigation failure\",\n privateResponseCause(bodyText),\n );\n }\n switch (action._tag) {\n case \"CapturePageContent\":\n case \"CapturePageMarkdown\": {\n if (typeof envelope.value.result !== \"string\") {\n return protocolError(\"The Quick Action envelope carried a non-text result\");\n }\n\n return action._tag === \"CapturePageContent\"\n ? PageContentCaptured.make({ html: envelope.value.result })\n : PageMarkdownCaptured.make({ markdown: envelope.value.result });\n }\n case \"CapturePageLinks\": {\n const decoded = Schema.decodeUnknownOption(PageLinksCaptured)({\n _tag: \"PageLinksCaptured\",\n links: envelope.value.result,\n });\n\n if (Option.isNone(decoded)) {\n return protocolError(\"The links Quick Action did not return a bounded array of valid URLs\");\n }\n\n return decoded.value;\n }\n case \"CapturePageScrape\": {\n const decoded = Schema.decodeUnknownOption(PageScrapeCaptured)({\n _tag: \"PageScrapeCaptured\",\n groups: envelope.value.result,\n });\n\n if (Option.isNone(decoded)) {\n return protocolError(\n \"The scrape Quick Action did not return bounded grouped element records\",\n );\n }\n\n return decoded.value;\n }\n case \"CapturePageStructured\": {\n return PageStructuredCaptured.make({ value: envelope.value.result });\n }\n }\n};\n\nconst isQuotaMessage = (text: string): boolean => /time limit|daily|quota/i.test(text);\n\nconst makeCapture = (\n browser: BrowserQuickActionClient,\n workersAi?: BrowserQuickActionWorkersAiPolicy,\n): PageCaptureCapture =>\n Effect.fn(\"BrowserQuickActionCapture.capture\")(function* (\n request: PageCaptureRequest,\n ): Effect.fn.Return<PageCaptureResult, PageCaptureError> {\n if (request.engine !== \"chromium\") {\n return yield* PageCaptureUnsupportedError.make({\n implementation: browserQuickActionImplementation,\n feature: \"engine\",\n message:\n \"The browser binding's quickAction() exposes no engine selector; kitesurf requires the REST or CDP surface\",\n });\n }\n\n const usesWorkersAi = request.action._tag === \"CapturePageStructured\";\n\n if (usesWorkersAi) {\n if (workersAi === undefined) {\n return yield* PageCaptureUnsupportedError.make({\n implementation: browserQuickActionImplementation,\n feature: \"action\",\n message:\n \"Structured capture invokes separately billed Workers AI and requires an explicit authorization and accounting policy\",\n });\n }\n yield* workersAi.authorizeAndAccount(request).pipe(\n Effect.mapError((cause) =>\n PageCaptureInferencePolicyError.make({\n implementation: browserQuickActionImplementation,\n provider: \"cloudflare-workers-ai\",\n reason: cause.reason,\n message:\n cause.reason === \"authorization\"\n ? \"Workers AI extraction was not authorized\"\n : \"Workers AI extraction could not be accounted for\",\n cause,\n }),\n ),\n );\n }\n\n const response = yield* executeQuickAction(browser, request).pipe(\n Effect.mapError((error) =>\n protocolError(\"The browser binding rejected the Quick Action\", error.cause),\n ),\n );\n\n const bodyText = yield* readBoundedResponse(response, request);\n\n if (response.status === 429) {\n const retryAfter = retryAfterMillis(response);\n const reason = isQuotaMessage(bodyText) ? \"quota\" : \"rate\";\n const cause = privateResponseCause(bodyText);\n\n return yield* PageCaptureRateLimitedError.make({\n implementation: browserQuickActionImplementation,\n reason,\n ...(retryAfter === undefined ? {} : { retryAfterMillis: retryAfter }),\n ...(cause === undefined ? {} : { cause }),\n message:\n reason === \"quota\"\n ? \"The Quick Action exceeded its browser quota\"\n : \"The Quick Action was rate limited\",\n });\n }\n if (!response.ok) {\n const message = `The Quick Action answered HTTP ${response.status}`;\n const cause = privateResponseCause(bodyText);\n\n if (response.status >= 500) {\n return yield* protocolError(message, cause);\n }\n\n return yield* navigationError(message, cause);\n }\n const output = parseOutput(request.action, bodyText, response);\n\n if (\n output._tag === \"PageCaptureNavigationError\" ||\n output._tag === \"PageCaptureProtocolError\"\n ) {\n return yield* output;\n }\n const millis = browserMillis(response);\n\n return PageCaptureResult.make({\n implementation: browserQuickActionImplementation,\n output,\n resourceUse: PageCaptureResourceUse.make({\n ...(millis === undefined ? {} : { browserMillis: millis }),\n ...(usesWorkersAi\n ? {\n inference: PageCaptureInferenceUse.make({\n provider: \"cloudflare-workers-ai\",\n modelCalls: 1,\n }),\n }\n : {}),\n }),\n });\n });\n\n/**\n * Ordinary Quick Actions require host-owned browser binding authority. Workers\n * AI stays unavailable unless the host deliberately selects its separate Layer.\n */\nexport const browserQuickActionCaptureLayer = (): Layer.Layer<\n PageCapture,\n never,\n BrowserQuickActionBrowserBinding\n> =>\n Layer.effect(\n PageCapture,\n Effect.map(BrowserQuickActionBrowserBinding, (browser) =>\n PageCapture.of({ capture: makeCapture(browser) }),\n ),\n );\n\n/** Structured Quick Actions require host-owned browser and Workers AI authority. */\nexport const browserQuickActionWorkersAiCaptureLayer = (): Layer.Layer<\n PageCapture,\n never,\n BrowserQuickActionBrowserBinding | BrowserQuickActionWorkersAi\n> =>\n Layer.effect(\n PageCapture,\n Effect.gen(function* () {\n const browser = yield* BrowserQuickActionBrowserBinding;\n const workersAi = yield* BrowserQuickActionWorkersAi;\n\n return PageCapture.of({ capture: makeCapture(browser, workersAi) });\n }),\n );\n\n/** Host-owned Quick Action binding and optional, separately billed extraction authority. */\nexport interface CloudflareBrowserOptions extends BrowserQuickActionCaptureOptions {\n readonly workersAi?: BrowserQuickActionWorkersAiPolicy;\n}\n\n/** Compose WebCapture handlers with the Cloudflare Quick Action adapter. */\nexport const CloudflareBrowser = {\n /**\n * Supply a WebCapture definition and the resolved Worker browser binding.\n * Supports capture, scrape, and extraction definitions without importing capabilities.\n * Only PageCapture is provided; other handler requirements and errors stay visible.\n * Extraction fails closed unless workersAi explicitly authorizes and accounts for it.\n * Capture limits, typed failures, tracing, and scoped response cleanup are unchanged.\n */\n layer: <A, E, R>(\n definition: { readonly handlers: Layer.Layer<A, E, R> },\n options: CloudflareBrowserOptions,\n ): Layer.Layer<A, E, Exclude<R, PageCapture>> => {\n const capture =\n options.workersAi === undefined\n ? browserQuickActionCaptureLayer()\n : browserQuickActionWorkersAiCaptureLayer().pipe(\n Layer.provide(BrowserQuickActionWorkersAi.layer(options.workersAi)),\n );\n\n return definition.handlers.pipe(\n Layer.provide(capture.pipe(Layer.provide(BrowserQuickActionBrowserBinding.layer(options)))),\n );\n },\n};\n\nconst screenshotOptions = (request: PageScreenshotRequest): BrowserRunScreenshotOptions => {\n const options: BrowserRunBaseOptions = {};\n\n if (\n request.navigation?.waitUntil !== undefined ||\n request.navigation?.timeoutMillis !== undefined\n ) {\n options.gotoOptions = {\n ...(request.navigation.waitUntil === undefined\n ? {}\n : { waitUntil: request.navigation.waitUntil }),\n ...(request.navigation.timeoutMillis === undefined\n ? {}\n : { timeout: request.navigation.timeoutMillis }),\n };\n }\n if (request.navigation?.waitForSelector !== undefined) {\n options.waitForSelector = {\n selector: request.navigation.waitForSelector.selector,\n ...(request.navigation.waitForSelector.timeoutMillis === undefined\n ? {}\n : { timeout: request.navigation.waitForSelector.timeoutMillis }),\n };\n }\n if (request.viewport !== undefined) {\n options.viewport = { width: request.viewport.width, height: request.viewport.height };\n }\n if (request.resourcePolicy?.rejectResourceTypes !== undefined) {\n options.rejectResourceTypes = [...request.resourcePolicy.rejectResourceTypes];\n }\n if (request.resourcePolicy?.allowRequestPatterns !== undefined) {\n options.allowRequestPattern = [...request.resourcePolicy.allowRequestPatterns];\n }\n\n return {\n ...options,\n ...(request.target._tag === \"PageUrlTarget\"\n ? { url: request.target.url }\n : { html: request.target.html }),\n screenshotOptions: { type: \"png\", encoding: \"binary\", fullPage: request.fullPage },\n };\n};\n\nconst cancelBody = (body: ReadableStream<Uint8Array>): Effect.Effect<void> =>\n cancelResponse(() => body.cancel(), \"Canceling the screenshot response failed\");\n\nconst releaseScreenshotReader = (\n reader: ReadableStreamDefaultReader<Uint8Array>,\n): Effect.Effect<void> =>\n cancelResponse(() => reader.cancel(), \"Canceling the screenshot response failed\").pipe(\n Effect.ensuring(\n Effect.try({\n try: () => reader.releaseLock(),\n catch: () => undefined,\n }).pipe(Effect.catch(() => Effect.logWarning(\"Releasing the screenshot response failed\"))),\n ),\n );\n\nconst pngResponse = (response: Response): boolean =>\n response.headers.get(\"Content-Type\")?.split(\";\", 1)[0]?.trim().toLowerCase() === \"image/png\";\n\nconst declaredLength = (response: Response): number | undefined => {\n const raw = response.headers.get(\"Content-Length\");\n\n if (raw === null || !/^(0|[1-9][0-9]*)$/.test(raw)) return undefined;\n const length = Number(raw);\n\n return Number.isSafeInteger(length) ? length : undefined;\n};\n\nconst readScreenshot = Effect.fn(\"BrowserQuickActionScreenshot.read\")(function* (\n response: Response,\n request: PageScreenshotRequest,\n) {\n const body = response.body;\n\n if (body === null) {\n return yield* protocolError(\"The screenshot response had no body\");\n }\n if (!pngResponse(response)) {\n yield* cancelBody(body);\n\n return yield* protocolError(\"The screenshot response was not image/png\");\n }\n const length = declaredLength(response);\n\n if (length !== undefined && length > request.limits.maxOutputBytes) {\n yield* cancelBody(body);\n\n return yield* PageScreenshotOutputLimitError.make({\n implementation: browserQuickActionImplementation,\n limit: request.limits.maxOutputBytes,\n observed: length,\n });\n }\n\n const reader = yield* Effect.acquireRelease(\n Effect.try({\n try: () => body.getReader(),\n catch: (cause) => protocolError(\"Opening the screenshot response failed\", cause),\n }),\n releaseScreenshotReader,\n );\n\n const chunks: Array<Uint8Array> = [];\n let observed = 0;\n\n while (true) {\n const next = yield* Effect.tryPromise({\n try: () => reader.read(),\n catch: (cause) => protocolError(\"Reading the screenshot response failed\", cause),\n });\n\n if (next.done) break;\n observed += next.value.byteLength;\n if (observed > request.limits.maxOutputBytes) {\n return yield* PageScreenshotOutputLimitError.make({\n implementation: browserQuickActionImplementation,\n limit: request.limits.maxOutputBytes,\n observed,\n });\n }\n chunks.push(next.value);\n }\n const bytes = new Uint8Array(observed);\n let offset = 0;\n\n for (const chunk of chunks) {\n bytes.set(chunk, offset);\n offset += chunk.byteLength;\n }\n\n return bytes;\n}, Effect.scoped);\n\nconst makeScreenshot = (browser: BrowserQuickActionClient): PageScreenshotCapture =>\n Effect.fn(\"BrowserQuickActionScreenshot.capture\")(function* (\n request: PageScreenshotRequest,\n ): Effect.fn.Return<PageScreenshotResult, PageScreenshotError> {\n if (request.engine !== \"chromium\") {\n return yield* PageCaptureUnsupportedError.make({\n implementation: browserQuickActionImplementation,\n feature: \"engine\",\n message: \"The browser binding's screenshot action exposes no engine selector\",\n });\n }\n\n const response = yield* browser\n .screenshot(screenshotOptions(request))\n .pipe(\n Effect.mapError((error) =>\n protocolError(\"The browser binding rejected the screenshot\", error.cause),\n ),\n );\n\n if (response.status === 429) {\n const body = response.body;\n\n if (body !== null) yield* cancelBody(body);\n\n return yield* PageCaptureRateLimitedError.make({\n implementation: browserQuickActionImplementation,\n reason: \"rate\",\n ...(retryAfterMillis(response) === undefined\n ? {}\n : { retryAfterMillis: retryAfterMillis(response) }),\n message: \"The screenshot Quick Action was rate limited\",\n });\n }\n if (!response.ok) {\n const body = response.body;\n\n if (body !== null) yield* cancelBody(body);\n const message = `The screenshot Quick Action answered HTTP ${response.status}`;\n\n return yield* response.status >= 500 ? protocolError(message) : navigationError(message);\n }\n const bytes = yield* readScreenshot(response, request);\n\n return PageScreenshotResult.make({\n implementation: browserQuickActionImplementation,\n mediaType: \"image/png\",\n bytes,\n });\n });\n\n/** Native Browser Run screenshot adapter. It retains PNG bytes only for the caller's result. */\nexport const browserQuickActionScreenshotLayer = (): Layer.Layer<\n PageScreenshot,\n never,\n BrowserQuickActionBrowserBinding\n> =>\n Layer.effect(\n PageScreenshot,\n Effect.map(BrowserQuickActionBrowserBinding, (browser) =>\n PageScreenshot.of({ capture: makeScreenshot(browser) }),\n ),\n );\n","/** Public CloudflareBrowser API. Implementation helpers remain private. */\nexport {\n BrowserQuickActionBrowserBinding,\n BrowserQuickActionRpcError,\n BrowserQuickActionWorkersAi,\n BrowserQuickActionWorkersAiPolicyError,\n browserQuickActionCaptureLayer,\n browserQuickActionWorkersAiCaptureLayer,\n browserQuickActionScreenshotLayer,\n CloudflareBrowser,\n type BrowserQuickActionCaptureOptions,\n type BrowserQuickActionClient,\n type BrowserQuickActionWorkersAiPolicy,\n type CloudflareBrowserOptions,\n} from \"./internal/browser-quick-action.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgDA,MAAa,mCAAmC,sBAAsB,KAAK;CACzE,WAAW;CACX,UAAU;AACZ,CAAC;;AA4BD,IAAa,6BAAb,cAAgD,OAAO,YAAwC,CAAC,CAC9F,8BACA;CACE,QAAQ,OAAO,SAAS;EAAC;EAAc;EAAW;EAAY;EAAS;EAAU;CAAM,CAAC;CACxF,OAAO,OAAO,OAAO;AACvB,CACF,CAAC,CAAC,CAAC;;AAQH,IAAa,mCAAb,MAAa,yCAAyC,QAAQ,QAG5D,CAAC,CAAC,oEAAoE,CAAC,CAAC;CACxE,OAAO,MACL,SAC+C;EAC/C,MAAM,UAAU,QAAQ;EAExB,MAAM,SAAS,OAAO,GAAG,yCAAyC,CAAC,CAAC,WAClE,QACA,UACwD;GACxD,OAAO,OAAO,OAAO,WAAW;IAC9B,KAAK;IACL,QAAQ,UAAU,2BAA2B,KAAK;KAAE;KAAQ;IAAM,CAAC;GACrE,CAAC;EACH,CAAC;EAED,OAAO,MAAM,QAAQ,gCAAgC,CAAC,CAAC;GACrD,aAAa,YACX,OAAO,oBAAoB,QAAQ,YAAY,cAAc,OAAO,CAAC;GACvE,UAAU,YAAY,OAAO,iBAAiB,QAAQ,YAAY,WAAW,OAAO,CAAC;GACrF,WAAW,YAAY,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AC,IACD,EAAE,kBAAkB,iBAAiB,QAAQ,EAAE;GACnD,SAAS;EACX,CAAC;CACH;CACA,IAAI,CAAC,SAAS,IAAI;EAChB,MAAM,OAAO,SAAS;EAEtB,IAAI,SAAS,MAAM,OAAO,WAAW,IAAI;EACzC,MAAM,UAAU,6CAA6C,SAAS;EAEtE,OAAO,OAAO,SAAS,UAAU,MAAM,cAAc,OAAO,IAAI,gBAAgB,OAAO;CACzF;CACA,MAAM,QAAQ,OAAO,eAAe,UAAU,OAAO;CAErD,OAAO,qBAAqB,KAAK;EAC/B,gBAAgB;EAChB,WAAW;EACX;CACF,CAAC;AACH,CAAC;;AAGH,MAAa,0CAKX,MAAM,OACJ,gBACA,OAAO,IAAI,mCAAmC,YAC5C,eAAe,GAAG,EAAE,SAAS,eAAe,OAAO,EAAE,CAAC,CACxD,CACF"}
@@ -1,2 +1,2 @@
1
- import { a as BrowserQuickActionWorkersAiPolicyError, c as browserQuickActionScreenshotLayer, i as BrowserQuickActionWorkersAi, l as browserQuickActionWorkersAiCaptureLayer, n as BrowserQuickActionBrowserBinding, o as CloudflareBrowser, r as BrowserQuickActionRpcError, s as browserQuickActionCaptureLayer } from "./CloudflareBrowser-1jeZx3_g.mjs";
1
+ import { a as BrowserQuickActionWorkersAiPolicyError, c as browserQuickActionScreenshotLayer, i as BrowserQuickActionWorkersAi, l as browserQuickActionWorkersAiCaptureLayer, n as BrowserQuickActionBrowserBinding, o as CloudflareBrowser, r as BrowserQuickActionRpcError, s as browserQuickActionCaptureLayer } from "./CloudflareBrowser-Bj22nNUT.mjs";
2
2
  export { BrowserQuickActionBrowserBinding, BrowserQuickActionRpcError, BrowserQuickActionWorkersAi, BrowserQuickActionWorkersAiPolicyError, CloudflareBrowser, browserQuickActionCaptureLayer, browserQuickActionScreenshotLayer, browserQuickActionWorkersAiCaptureLayer };
@@ -182,13 +182,13 @@ declare const encodeUnknownResolutionCommand: (input: UnknownResolutionCommand,
182
182
  readonly author: string;
183
183
  readonly reason: string;
184
184
  readonly resolution: {
185
- readonly _tag: "SafeToRetry";
186
- } | {
187
185
  readonly _tag: "CompletedWithResult";
188
186
  readonly result: Schema.Json;
189
187
  readonly isFailure: boolean;
190
188
  } | {
191
189
  readonly _tag: "NeverHappened";
190
+ } | {
191
+ readonly _tag: "SafeToRetry";
192
192
  } | {
193
193
  readonly _tag: "AbortSubmission";
194
194
  };
@@ -316,14 +316,6 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
316
316
  readonly createdAt: string;
317
317
  readonly deploymentId: string;
318
318
  readonly payload: {
319
- readonly _tag: "SubagentStarted";
320
- readonly runId: string;
321
- readonly toolCallId: string;
322
- readonly childThreadId: string;
323
- readonly childSubmissionId: string;
324
- readonly childReceiptId: string;
325
- readonly childRunId: string;
326
- } | {
327
319
  readonly _tag: "AbortRequested";
328
320
  readonly submissionId: string;
329
321
  readonly author: string;
@@ -557,6 +549,14 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
557
549
  readonly resultBytes: number;
558
550
  };
559
551
  } | undefined;
552
+ } | {
553
+ readonly _tag: "SubagentStarted";
554
+ readonly runId: string;
555
+ readonly toolCallId: string;
556
+ readonly childThreadId: string;
557
+ readonly childSubmissionId: string;
558
+ readonly childReceiptId: string;
559
+ readonly childRunId: string;
560
560
  } | {
561
561
  readonly _tag: "SubagentJoined";
562
562
  readonly runId: string;
@@ -628,13 +628,13 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
628
628
  readonly author: string;
629
629
  readonly reason: string;
630
630
  readonly resolution: {
631
- readonly _tag: "SafeToRetry";
632
- } | {
633
631
  readonly _tag: "CompletedWithResult";
634
632
  readonly result: Schema.Json;
635
633
  readonly isFailure: boolean;
636
634
  } | {
637
635
  readonly _tag: "NeverHappened";
636
+ } | {
637
+ readonly _tag: "SafeToRetry";
638
638
  } | {
639
639
  readonly _tag: "AbortSubmission";
640
640
  };
@@ -687,11 +687,6 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
687
687
  readonly threadId: string;
688
688
  readonly actualEpoch: number;
689
689
  readonly attemptedEpoch: number;
690
- } | {
691
- readonly _tag: "DurableAlarmError";
692
- readonly operation: string;
693
- readonly message: string;
694
- readonly cause?: Schema.Json | undefined;
695
690
  } | {
696
691
  readonly _tag: "HostProtocolError";
697
692
  readonly message: string;
@@ -719,6 +714,11 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
719
714
  readonly limit: "database-bytes" | "input-bytes" | "queue-depth";
720
715
  readonly actual: number;
721
716
  readonly maximum: number;
717
+ } | {
718
+ readonly _tag: "DurableAlarmError";
719
+ readonly operation: string;
720
+ readonly message: string;
721
+ readonly cause?: Schema.Json | undefined;
722
722
  } | {
723
723
  readonly _tag: "OperationDenied";
724
724
  readonly operation: "abort" | "awaitSettlement" | "explain" | "observe" | "resolveApproval" | "resolveUnknown" | "retry" | "scanObligations" | "verify" | "wake";
@@ -751,6 +751,7 @@ declare const CloudflareThreadClient_base: Context.ServiceClass<CloudflareThread
751
751
  /**
752
752
  * Wait without polling until progress after `afterSequence` is already durable or hinted.
753
753
  * The result is deliberately void: canonical records remain authoritative and must be read.
754
+ * Interruption waits at most one second for best-effort remote cancellation.
754
755
  */
755
756
  readonly awaitProgress: (threadId: ThreadId, afterSequence: CanonicalSequence) => Effect.Effect<void, ClientProgressFailure>;
756
757
  /** One bounded page of canonical records. */
@@ -67,6 +67,7 @@ var CloudflareThreadClient_exports = /* @__PURE__ */ __exportAll({
67
67
  */
68
68
  /** Ceiling for host protocol diagnostic strings. */
69
69
  const MAX_HOST_DIAGNOSTIC_LENGTH = 4096;
70
+ const PROGRESS_CANCELLATION_TIMEOUT = "1 second";
70
71
  const BoundedDiagnostic = Schema.String.check(Schema.isMaxLength(MAX_HOST_DIAGNOSTIC_LENGTH));
71
72
  /** Truncate a diagnostic string to the host protocol's bounded length. */
72
73
  const boundHostDiagnostic = (value) => value.length > MAX_HOST_DIAGNOSTIC_LENGTH ? `${value.slice(0, 4093)}...` : value;
@@ -303,7 +304,7 @@ var CloudflareThreadClient = class CloudflareThreadClient extends Context.Servic
303
304
  const response = yield* call(threadId, "observePage", encoded);
304
305
  return (yield* expect(threadId, "observePage", ObservedPage, ClientObserveHostFailure)(response)).records;
305
306
  });
306
- const cancelProgress = (threadId, waiterId) => encodeCancelProgressRequest(CancelProgressRequest.make({ waiterId })).pipe(Effect.mapError(() => void 0), Effect.flatMap((encoded) => call(threadId, "cancelProgress", encoded)), Effect.asVoid, Effect.ignore);
307
+ const cancelProgress = (threadId, waiterId) => encodeCancelProgressRequest(CancelProgressRequest.make({ waiterId })).pipe(Effect.mapError(() => void 0), Effect.flatMap((encoded) => call(threadId, "cancelProgress", encoded)), Effect.interruptible, Effect.timeout(PROGRESS_CANCELLATION_TIMEOUT), Effect.asVoid, Effect.ignore);
307
308
  return CloudflareThreadClient.of({
308
309
  submit: (agent, input, options) => Effect.gen(function* () {
309
310
  const encodedInput = yield* Schema.encodeEffect(agent.definition.input)(input).pipe(Effect.mapError((cause) => AgentInputError.make({ message: `Unable to encode Agent input: ${cause.message}` })));
@@ -1 +1 @@
1
- {"version":3,"file":"CloudflareThreadClient.mjs","names":[],"sources":["../src/CloudflareThreadClient.ts"],"sourcesContent":["import { AgentInputError } from \"@effect-agent/core/AgentError\";\nimport { AgentId, type ThreadId } from \"@effect-agent/core/Identifiers\";\nimport { DigestError } from \"@effect-agent/thread/Digest\";\nimport {\n Receipt,\n type DurableSubmitAgent,\n type DurableSubmitOptions,\n} from \"@effect-agent/thread/DurableAgentRuntime\";\nimport { DurableRuntimeFailpointError } from \"@effect-agent/thread/DurableFailpoint\";\nimport { OperationDenied } from \"@effect-agent/thread/OperationAuthorizer\";\nimport {\n CanonicalRecordEnvelope,\n CanonicalSequence,\n DefinitionDigests,\n PersistedJson,\n} from \"@effect-agent/thread/Records\";\nimport {\n AdmissionFence,\n AdmissionGroup,\n AbortCommand,\n AbortIntent,\n AdmissionConflict,\n AdmissionPolicyError,\n ApprovalConflict,\n ApprovalDecisionCommand,\n ApprovalDecisionIntent,\n IdempotencyKey,\n JoinedToHost,\n LedgerError,\n Principal,\n Settlement,\n SettlementConflict,\n UnknownResolutionCommand,\n UnknownResolutionConflict,\n UnknownResolutionIntent,\n} from \"@effect-agent/thread/SubmissionLedger\";\nimport { SubmissionStatus } from \"@effect-agent/thread/SubmissionStatus\";\nimport {\n AppendConflict,\n ThreadNotMaterialized,\n ThreadStoreError,\n FenceRejected,\n} from \"@effect-agent/thread/ThreadStore\";\nimport { BrowserCrypto } from \"@effect/platform-browser\";\nimport { Context, Crypto, Duration, Effect, Layer, Schema } from \"effect\";\nimport { RpcTracing } from \"effect-cf\";\n\nimport { DurableAlarmError } from \"./Alarm.ts\";\nimport { ThreadObjectNamespace, type ThreadObjectRpc } from \"./CloudflareBindings.ts\";\nimport { AdmissionLimitExceeded } from \"./CloudflareConfig.ts\";\nimport { cloudflareFailureSignals, safeCauseMessage } from \"./internal/boundary.ts\";\n\n/**\n * The Worker↔Thread-Object host protocol (plan §1.4): Schema envelopes for the host\n * entry points (`submitEncoded`, `awaitSettlementEncoded`, `observePage`, `abortEncoded`,\n * `resolveApprovalEncoded`, `resolveUnknownEncoded`) plus the Worker-side client that speaks\n * it. Mirrors the WP2 port protocol: requests and responses are closed Schema unions, typed\n * failures travel as their own tagged classes and RE-DECODE to identical tags on the caller\n * (error-tag fidelity), and protocol anomalies are answered typed instead of thrown.\n */\n\n/** Ceiling for host protocol diagnostic strings. */\nconst MAX_HOST_DIAGNOSTIC_LENGTH = 4_096;\n\nconst BoundedDiagnostic = Schema.String.check(Schema.isMaxLength(MAX_HOST_DIAGNOSTIC_LENGTH));\n\n/** Truncate a diagnostic string to the host protocol's bounded length. */\nexport const boundHostDiagnostic = (value: string): string =>\n value.length > MAX_HOST_DIAGNOSTIC_LENGTH\n ? `${value.slice(0, MAX_HOST_DIAGNOSTIC_LENGTH - 3)}...`\n : value;\n\n/**\n * The envelope itself could not be honored: the Object could not decode the request, or a\n * response could not be encoded/decoded. Never carries operation semantics.\n */\nexport class HostProtocolError extends Schema.TaggedError<HostProtocolError>()(\n \"HostProtocolError\",\n {\n message: BoundedDiagnostic,\n },\n) {}\n\n/** The Worker-side stub call itself failed (RPC rejection, overload, eviction mid-call). */\nexport class ThreadClientError extends Schema.TaggedError<ThreadClientError>()(\n \"ThreadClientError\",\n {\n threadId: Schema.String,\n message: Schema.String,\n cause: Schema.optionalKey(Schema.Defect()),\n /** Cloudflare's own classification for a failure safe to retry with a fresh stub. */\n retryable: Schema.optionalKey(Schema.Boolean),\n /** Cloudflare overloads are surfaced immediately instead of adding retry pressure. */\n overloaded: Schema.optionalKey(Schema.Boolean),\n },\n) {}\n\n// ---------------------------------------------------------------------------\n// Requests\n// ---------------------------------------------------------------------------\n\n/**\n * One durable submission, input ALREADY encoded by the caller through the Agent Binding's\n * input schema (the Worker bundles the same Agent definitions as the Object, so schema\n * validation happens client-side; the resolved Binding re-validates at claim time). The\n * Thread identity is deliberately absent — the addressed Object IS the lane.\n */\nexport class SubmitRequest extends Schema.Class<SubmitRequest>(\n \"@effect-agent/platform-cloudflare/SubmitRequest\",\n)({\n agentId: AgentId,\n principal: Principal,\n idempotencyKey: IdempotencyKey,\n admissionGroup: Schema.optionalKey(AdmissionGroup),\n admissionFence: Schema.optionalKey(AdmissionFence),\n definitions: DefinitionDigests,\n inputPayload: PersistedJson,\n}) {}\n\n/** One bounded page of canonical records after an optional sequence. */\nexport class ObservePageRequest extends Schema.Class<ObservePageRequest>(\n \"@effect-agent/platform-cloudflare/ObservePageRequest\",\n)({\n afterSequence: Schema.optionalKey(CanonicalSequence),\n limit: Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(1_024)),\n}) {}\n\n/** One event-driven wait for canonical progress strictly after this sequence. */\nexport class AwaitProgressRequest extends Schema.Class<AwaitProgressRequest>(\n \"@effect-agent/platform-cloudflare/AwaitProgressRequest\",\n)({\n afterSequence: CanonicalSequence,\n waiterId: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(256)),\n}) {}\n\n/** Best-effort cancellation of one in-flight progress RPC. */\nexport class CancelProgressRequest extends Schema.Class<CancelProgressRequest>(\n \"@effect-agent/platform-cloudflare/CancelProgressRequest\",\n)({\n waiterId: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(256)),\n}) {}\n\n// ---------------------------------------------------------------------------\n// Responses\n// ---------------------------------------------------------------------------\n\n/**\n * Every typed failure a host entry point can produce, plus the protocol's own errors. Same\n * closed-union discipline as the WP2 `PortFailure`: members re-decode to the SAME tagged\n * classes on the Worker side; `cause` chains travel as Schema defects without instance\n * fidelity (plan §2.8).\n */\nexport const HostFailure = Schema.Union([\n AgentInputError,\n DigestError,\n AdmissionConflict,\n AdmissionPolicyError,\n SettlementConflict,\n ApprovalConflict,\n UnknownResolutionConflict,\n JoinedToHost,\n LedgerError,\n ThreadStoreError,\n ThreadNotMaterialized,\n AppendConflict,\n FenceRejected,\n DurableRuntimeFailpointError,\n AdmissionLimitExceeded,\n DurableAlarmError,\n OperationDenied,\n HostProtocolError,\n]);\n\nexport type HostFailure = typeof HostFailure.Type;\n\nexport class SubmitSucceeded extends Schema.TaggedClass<SubmitSucceeded>(\n \"@effect-agent/platform-cloudflare/SubmitSucceeded\",\n)(\"SubmitSucceeded\", {\n receipt: Receipt,\n}) {}\n\nexport class SubmissionStatusResponse extends Schema.TaggedClass<SubmissionStatusResponse>(\n \"@effect-agent/platform-cloudflare/SubmissionStatusResponse\",\n)(\"SubmissionStatusResponse\", { status: SubmissionStatus }) {}\n\nexport class SettlementReached extends Schema.TaggedClass<SettlementReached>(\n \"@effect-agent/platform-cloudflare/SettlementReached\",\n)(\"SettlementReached\", {\n settlement: Settlement,\n}) {}\n\nexport class ObservedPage extends Schema.TaggedClass<ObservedPage>(\n \"@effect-agent/platform-cloudflare/ObservedPage\",\n)(\"ObservedPage\", {\n records: Schema.Array(CanonicalRecordEnvelope).check(Schema.isMaxLength(1_024)),\n}) {}\n\n/** A record was already committed or an incarnation-local hint says the caller should re-read. */\nexport class ProgressObserved extends Schema.TaggedClass<ProgressObserved>(\n \"@effect-agent/platform-cloudflare/ProgressObserved\",\n)(\"ProgressObserved\", {}) {}\n\nexport class ProgressCancelled extends Schema.TaggedClass<ProgressCancelled>(\n \"@effect-agent/platform-cloudflare/ProgressCancelled\",\n)(\"ProgressCancelled\", {}) {}\n\nexport class AbortRecorded extends Schema.TaggedClass<AbortRecorded>(\n \"@effect-agent/platform-cloudflare/AbortRecorded\",\n)(\"AbortRecorded\", {\n intent: AbortIntent,\n}) {}\n\nexport class ApprovalRecorded extends Schema.TaggedClass<ApprovalRecorded>(\n \"@effect-agent/platform-cloudflare/ApprovalRecorded\",\n)(\"ApprovalRecorded\", {\n intent: ApprovalDecisionIntent,\n}) {}\n\nexport class UnknownResolutionRecorded extends Schema.TaggedClass<UnknownResolutionRecorded>(\n \"@effect-agent/platform-cloudflare/UnknownResolutionRecorded\",\n)(\"UnknownResolutionRecorded\", {\n intent: UnknownResolutionIntent,\n}) {}\n\n/** The entry point failed TYPED on the Object; the failure re-decodes verbatim. */\nexport class HostFailed extends Schema.TaggedClass<HostFailed>(\n \"@effect-agent/platform-cloudflare/HostFailed\",\n)(\"HostFailed\", {\n failure: HostFailure,\n}) {}\n\n/** The uniform answer of one host entry point. Callers narrow by the tag their call implies. */\nexport const HostResponse = Schema.Union([\n SubmitSucceeded,\n SettlementReached,\n SubmissionStatusResponse,\n ObservedPage,\n ProgressObserved,\n ProgressCancelled,\n AbortRecorded,\n ApprovalRecorded,\n UnknownResolutionRecorded,\n HostFailed,\n]);\n\nexport type HostResponse = typeof HostResponse.Type;\n\n// ---------------------------------------------------------------------------\n// Codecs (shared by the Object endpoints and the Worker client)\n// ---------------------------------------------------------------------------\n\nexport const decodeSubmitRequest = Schema.decodeUnknownEffect(SubmitRequest);\nexport const encodeSubmitRequest = Schema.encodeEffect(SubmitRequest);\nexport const decodeReceipt = Schema.decodeUnknownEffect(Receipt);\nexport const encodeReceipt = Schema.encodeEffect(Receipt);\nexport const decodeObservePageRequest = Schema.decodeUnknownEffect(ObservePageRequest);\nexport const encodeObservePageRequest = Schema.encodeEffect(ObservePageRequest);\nexport const decodeAwaitProgressRequest = Schema.decodeUnknownEffect(AwaitProgressRequest);\nexport const encodeAwaitProgressRequest = Schema.encodeEffect(AwaitProgressRequest);\nexport const decodeCancelProgressRequest = Schema.decodeUnknownEffect(CancelProgressRequest);\nexport const encodeCancelProgressRequest = Schema.encodeEffect(CancelProgressRequest);\nexport const decodeAbortCommand = Schema.decodeUnknownEffect(AbortCommand);\nexport const encodeAbortCommand = Schema.encodeEffect(AbortCommand);\nexport const decodeApprovalDecisionCommand = Schema.decodeUnknownEffect(ApprovalDecisionCommand);\nexport const encodeApprovalDecisionCommand = Schema.encodeEffect(ApprovalDecisionCommand);\nexport const decodeUnknownResolutionCommand = Schema.decodeUnknownEffect(UnknownResolutionCommand);\nexport const encodeUnknownResolutionCommand = Schema.encodeEffect(UnknownResolutionCommand);\nexport const encodeHostResponse = Schema.encodeEffect(HostResponse);\nexport const decodeHostResponse = Schema.decodeUnknownEffect(HostResponse);\n\n// ---------------------------------------------------------------------------\n// Worker-side client\n// ---------------------------------------------------------------------------\n\n/** Failure surface of `CloudflareThreadClient.submit`. */\nconst ClientSubmitHostFailure = Schema.Union([\n AgentInputError,\n DigestError,\n AdmissionConflict,\n AdmissionPolicyError,\n LedgerError,\n ThreadStoreError,\n ThreadNotMaterialized,\n AppendConflict,\n FenceRejected,\n DurableRuntimeFailpointError,\n AdmissionLimitExceeded,\n DurableAlarmError,\n HostProtocolError,\n]);\n\nconst ClientAwaitHostFailure = Schema.Union([\n LedgerError,\n SettlementConflict,\n OperationDenied,\n HostProtocolError,\n]);\n\nconst ClientObserveHostFailure = Schema.Union([\n ThreadStoreError,\n ThreadNotMaterialized,\n OperationDenied,\n HostProtocolError,\n]);\n\nconst ClientAbortHostFailure = Schema.Union([\n OperationDenied,\n LedgerError,\n SettlementConflict,\n JoinedToHost,\n DurableRuntimeFailpointError,\n DurableAlarmError,\n HostProtocolError,\n]);\n\nconst ClientApprovalHostFailure = Schema.Union([\n LedgerError,\n SettlementConflict,\n ApprovalConflict,\n OperationDenied,\n DurableAlarmError,\n HostProtocolError,\n]);\n\nconst ClientUnknownHostFailure = Schema.Union([\n LedgerError,\n SettlementConflict,\n UnknownResolutionConflict,\n JoinedToHost,\n DurableRuntimeFailpointError,\n OperationDenied,\n DurableAlarmError,\n HostProtocolError,\n]);\n\nexport type ClientSubmitFailure = typeof ClientSubmitHostFailure.Type | ThreadClientError;\nexport type ClientAwaitFailure = typeof ClientAwaitHostFailure.Type | ThreadClientError;\nexport type ClientObserveFailure = typeof ClientObserveHostFailure.Type | ThreadClientError;\nexport type ClientProgressFailure = ClientObserveFailure;\nexport type ClientAbortFailure = typeof ClientAbortHostFailure.Type | ThreadClientError;\nexport type ClientApprovalFailure = typeof ClientApprovalHostFailure.Type | ThreadClientError;\nexport type ClientUnknownFailure = typeof ClientUnknownHostFailure.Type | ThreadClientError;\n\nconst outOfContract = (threadId: string, operation: string, observed: string): ThreadClientError =>\n ThreadClientError.make({\n threadId,\n message: boundHostDiagnostic(\n `The Thread Object answered ${operation} with the out-of-contract ${observed}.`,\n ),\n });\n\nconst hostRpcMethods = {\n submit: \"submitEncoded\",\n awaitSettlement: \"awaitSettlementEncoded\",\n submissionStatus: \"submissionStatusEncoded\",\n awaitProgress: \"awaitProgressEncoded\",\n cancelProgress: \"cancelProgressEncoded\",\n observePage: \"observePage\",\n abort: \"abortEncoded\",\n resolveApproval: \"resolveApprovalEncoded\",\n resolveUnknown: \"resolveUnknownEncoded\",\n} as const satisfies Record<string, keyof ThreadObjectRpc>;\n\n/** Worker-side client over the Thread Object namespace (DEPLOY-010). */\nexport class CloudflareThreadClient extends Context.Service<\n CloudflareThreadClient,\n {\n /** Encode the input client-side, then durably submit to the owning Object. */\n readonly submit: <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: DurableSubmitOptions,\n ) => Effect.Effect<Receipt, ClientSubmitFailure, InputSchema[\"EncodingServices\"]>;\n /** Wake-hinted, poll-guaranteed settlement wait executed inside the owning Object. */\n readonly submissionStatus: (\n receipt: Receipt,\n ) => Effect.Effect<SubmissionStatus, ClientAwaitFailure>;\n readonly awaitSettlement: (receipt: Receipt) => Effect.Effect<Settlement, ClientAwaitFailure>;\n /**\n * Wait without polling until progress after `afterSequence` is already durable or hinted.\n * The result is deliberately void: canonical records remain authoritative and must be read.\n */\n readonly awaitProgress: (\n threadId: ThreadId,\n afterSequence: CanonicalSequence,\n ) => Effect.Effect<void, ClientProgressFailure>;\n /** One bounded page of canonical records. */\n readonly readPage: (\n threadId: ThreadId,\n options?: {\n readonly afterSequence?: CanonicalSequence | undefined;\n readonly limit?: number | undefined;\n },\n ) => Effect.Effect<ReadonlyArray<CanonicalRecordEnvelope>, ClientObserveFailure>;\n /**\n * Every canonical record up to the CURRENT committed tail, via repeated pages. A\n * snapshot read, not a live observation — callers wanting liveness re-read after\n * `awaitSettlement`.\n */\n readonly readAll: (\n threadId: ThreadId,\n ) => Effect.Effect<ReadonlyArray<CanonicalRecordEnvelope>, ClientObserveFailure>;\n /**\n * Submission-addressed operations take the owning Thread explicitly (from the\n * Receipt): minted Submission identities stay OPAQUE outside the storage adapter that\n * minted them (D-P6-5), so the client never parses one to find the lane.\n */\n readonly abort: (\n threadId: ThreadId,\n command: AbortCommand,\n ) => Effect.Effect<AbortIntent, ClientAbortFailure>;\n readonly resolveApproval: (\n threadId: ThreadId,\n command: ApprovalDecisionCommand,\n ) => Effect.Effect<ApprovalDecisionIntent, ClientApprovalFailure>;\n readonly resolveUnknown: (\n threadId: ThreadId,\n command: UnknownResolutionCommand,\n ) => Effect.Effect<UnknownResolutionIntent, ClientUnknownFailure>;\n }\n>()(\"@effect-agent/platform-cloudflare/CloudflareThreadClient\") {\n /**\n * Assemble the client from a resolved namespace and the platform Crypto implementation.\n * rpcTracing is the binding name and remains opt-in. Caller authentication, principals,\n * idempotency keys, and definition digests are still explicit submission inputs.\n */\n static layerFromBinding(options: {\n readonly namespace: DurableObjectNamespace<ThreadObjectRpc>;\n readonly rpcTracing?: string;\n }): Layer.Layer<CloudflareThreadClient> {\n return CloudflareThreadClient.layer.pipe(\n Layer.provide([ThreadObjectNamespace.layer(options.namespace, options), BrowserCrypto.layer]),\n );\n }\n\n static readonly layer: Layer.Layer<\n CloudflareThreadClient,\n never,\n ThreadObjectNamespace | Crypto.Crypto\n > = Layer.effect(CloudflareThreadClient)(\n Effect.gen(function* () {\n const { namespace, rpcTracing } = yield* ThreadObjectNamespace;\n const crypto = yield* Crypto.Crypto;\n\n const call = Effect.fn(\n function* (\n threadId: string,\n operation: keyof typeof hostRpcMethods,\n encoded: unknown,\n ): Effect.fn.Return<HostResponse, ThreadClientError | HostProtocolError> {\n // Empty arguments preserve native arity. Passing `undefined` still adds an argument.\n const traceArgs =\n rpcTracing === undefined ? [] : yield* RpcTracing.withRpcTraceContext([]);\n\n const raw = yield* Effect.tryPromise({\n try: () => {\n const stub = namespace.get(namespace.idFromName(threadId));\n\n return stub[hostRpcMethods[operation]](encoded, ...traceArgs);\n },\n catch: (cause) =>\n ThreadClientError.make({\n threadId,\n message: boundHostDiagnostic(\n `${operation} did not reach the Thread Object: ${safeCauseMessage(\n cause,\n \"the RPC failed without a diagnostic\",\n )}`,\n ),\n cause,\n ...cloudflareFailureSignals(cause),\n }),\n });\n\n return yield* decodeHostResponse(raw).pipe(\n Effect.mapError((error): HostProtocolError =>\n HostProtocolError.make({\n message: boundHostDiagnostic(\n `The ${operation} answer could not be decoded: ${error.message}`,\n ),\n }),\n ),\n );\n },\n (effect, threadId, operation) =>\n rpcTracing === undefined\n ? Effect.withSpan(effect, \"CloudflareThreadClient.call\", {\n attributes: { threadId, operation },\n })\n : RpcTracing.withRpcClientSpan(effect, rpcTracing, hostRpcMethods[operation]),\n );\n\n const expect = <ResultSchema extends Schema.Top, FailureSchema extends Schema.Top>(\n threadId: string,\n operation: string,\n resultSchema: ResultSchema,\n failureSchema: FailureSchema,\n ) => {\n const isExpectedResult = Schema.is(resultSchema);\n const isExpectedFailure = Schema.is(failureSchema);\n\n return (\n response: HostResponse,\n ): Effect.Effect<ResultSchema[\"Type\"], FailureSchema[\"Type\"] | ThreadClientError> => {\n if (response._tag === \"HostFailed\") {\n const failure = response.failure;\n\n return isExpectedFailure(failure)\n ? Effect.fail(failure)\n : Effect.fail(outOfContract(threadId, operation, `failure ${failure._tag}`));\n }\n if (!isExpectedResult(response)) {\n return Effect.fail(outOfContract(threadId, operation, `result ${response._tag}`));\n }\n\n return Effect.succeed(response);\n };\n };\n\n const readPage = (\n threadId: ThreadId,\n options?: {\n readonly afterSequence?: CanonicalSequence | undefined;\n readonly limit?: number | undefined;\n },\n ) =>\n Effect.gen(function* () {\n const request = ObservePageRequest.make({\n ...(options?.afterSequence === undefined\n ? {}\n : { afterSequence: options.afterSequence }),\n limit: options?.limit ?? 256,\n });\n\n const encoded = yield* encodeObservePageRequest(request).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(`observePage request encode failed: ${error.message}`),\n }),\n ),\n );\n\n const response = yield* call(threadId, \"observePage\", encoded);\n\n const page = yield* expect(\n threadId,\n \"observePage\",\n ObservedPage,\n ClientObserveHostFailure,\n )(response);\n\n return page.records;\n });\n\n const cancelProgress = (threadId: ThreadId, waiterId: string): Effect.Effect<void> =>\n encodeCancelProgressRequest(CancelProgressRequest.make({ waiterId })).pipe(\n Effect.mapError(() => undefined),\n Effect.flatMap((encoded) => call(threadId, \"cancelProgress\", encoded)),\n Effect.asVoid,\n Effect.ignore,\n );\n\n return CloudflareThreadClient.of({\n submit: <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: DurableSubmitOptions,\n ) =>\n Effect.gen(function* () {\n // Client-side half of `DurableAgentRuntime.submit`'s input boundary: encode\n // through the Agent's input schema and prove the canonical persistence bounds.\n const encodedInput = yield* Schema.encodeEffect(agent.definition.input)(input).pipe(\n Effect.mapError((cause) =>\n AgentInputError.make({ message: `Unable to encode Agent input: ${cause.message}` }),\n ),\n );\n\n const inputPayload = yield* Schema.decodeUnknownEffect(PersistedJson)(\n encodedInput,\n ).pipe(\n Effect.mapError(() =>\n AgentInputError.make({\n message: \"Agent input does not satisfy the canonical persistence bounds\",\n }),\n ),\n );\n\n const request = SubmitRequest.make({\n agentId: agent.definition.id,\n principal: options.principal,\n idempotencyKey: options.idempotencyKey,\n ...(options.admissionGroup === undefined\n ? {}\n : { admissionGroup: options.admissionGroup }),\n ...(options.admissionFence === undefined\n ? {}\n : { admissionFence: options.admissionFence }),\n definitions: options.definitions,\n inputPayload,\n });\n\n const encoded = yield* encodeSubmitRequest(request).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(`submit request encode failed: ${error.message}`),\n }),\n ),\n );\n\n const response = yield* call(options.threadId, \"submit\", encoded);\n\n const succeeded = yield* expect(\n options.threadId,\n \"submit\",\n SubmitSucceeded,\n ClientSubmitHostFailure,\n )(response);\n\n return succeeded.receipt;\n }),\n\n submissionStatus: (receipt) =>\n Effect.gen(function* () {\n const encoded = yield* encodeReceipt(receipt).pipe(\n Effect.mapError(() => HostProtocolError.make({ message: \"Invalid receipt\" })),\n );\n\n const response = yield* call(receipt.threadId, \"submissionStatus\", encoded);\n\n const result = yield* expect(\n receipt.threadId,\n \"submissionStatus\",\n SubmissionStatusResponse,\n ClientAwaitHostFailure,\n )(response);\n\n return result.status;\n }),\n awaitSettlement: (receipt) =>\n Effect.gen(function* () {\n const encoded = yield* encodeReceipt(receipt).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(`receipt encode failed: ${error.message}`),\n }),\n ),\n );\n\n const response = yield* call(receipt.threadId, \"awaitSettlement\", encoded);\n\n const settled = yield* expect(\n receipt.threadId,\n \"awaitSettlement\",\n SettlementReached,\n ClientAwaitHostFailure,\n )(response);\n\n return settled.settlement;\n }),\n\n awaitProgress: (threadId, afterSequence) =>\n Effect.gen(function* () {\n const waiterId = yield* crypto.randomUUIDv4.pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(\n `awaitProgress cancellation identity generation failed: ${error.message}`,\n ),\n }),\n ),\n );\n\n const request = AwaitProgressRequest.make({ afterSequence, waiterId });\n\n const encoded = yield* encodeAwaitProgressRequest(request).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(\n `awaitProgress request encode failed: ${error.message}`,\n ),\n }),\n ),\n );\n\n const attempt = (retry: number): Effect.Effect<void, ClientProgressFailure> =>\n call(threadId, \"awaitProgress\", encoded).pipe(\n Effect.flatMap(\n expect(threadId, \"awaitProgress\", ProgressObserved, ClientObserveHostFailure),\n ),\n Effect.asVoid,\n Effect.catchTag(\"ThreadClientError\", (error) =>\n error.retryable === true && error.overloaded !== true && retry < 5\n ? Effect.sleep(Duration.millis(10 * 2 ** retry)).pipe(\n Effect.andThen(attempt(retry + 1)),\n )\n : Effect.fail(error),\n ),\n );\n\n yield* attempt(0).pipe(Effect.onInterrupt(() => cancelProgress(threadId, waiterId)));\n }),\n\n readPage,\n\n readAll: (threadId) =>\n Effect.gen(function* () {\n const all: Array<CanonicalRecordEnvelope> = [];\n let after: CanonicalSequence | undefined;\n\n for (;;) {\n const page = yield* readPage(threadId, { afterSequence: after, limit: 1_024 });\n\n all.push(...page);\n const last = page.at(-1);\n\n if (page.length < 1_024 || last === undefined) return all;\n after = last.sequence;\n }\n }),\n\n abort: (threadId, command) =>\n Effect.gen(function* () {\n const encoded = yield* encodeAbortCommand(command).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(`abort command encode failed: ${error.message}`),\n }),\n ),\n );\n\n const response = yield* call(threadId, \"abort\", encoded);\n\n const recorded = yield* expect(\n threadId,\n \"abort\",\n AbortRecorded,\n ClientAbortHostFailure,\n )(response);\n\n return recorded.intent;\n }),\n\n resolveApproval: (threadId, command) =>\n Effect.gen(function* () {\n const encoded = yield* encodeApprovalDecisionCommand(command).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(`approval command encode failed: ${error.message}`),\n }),\n ),\n );\n\n const response = yield* call(threadId, \"resolveApproval\", encoded);\n\n const recorded = yield* expect(\n threadId,\n \"resolveApproval\",\n ApprovalRecorded,\n ClientApprovalHostFailure,\n )(response);\n\n return recorded.intent;\n }),\n\n resolveUnknown: (threadId, command) =>\n Effect.gen(function* () {\n const encoded = yield* encodeUnknownResolutionCommand(command).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(\n `resolution command encode failed: ${error.message}`,\n ),\n }),\n ),\n );\n\n const response = yield* call(threadId, \"resolveUnknown\", encoded);\n\n const recorded = yield* expect(\n threadId,\n \"resolveUnknown\",\n UnknownResolutionRecorded,\n ClientUnknownHostFailure,\n )(response);\n\n return recorded.intent;\n }),\n });\n }),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,MAAM,6BAA6B;AAEnC,MAAM,oBAAoB,OAAO,OAAO,MAAM,OAAO,YAAY,0BAA0B,CAAC;;AAG5F,MAAa,uBAAuB,UAClC,MAAM,SAAS,6BACX,GAAG,MAAM,MAAM,GAAG,IAA8B,EAAE,OAClD;;;;;AAMN,IAAa,oBAAb,cAAuC,OAAO,YAA+B,CAAC,CAC5E,qBACA,EACE,SAAS,kBACX,CACF,CAAC,CAAC,CAAC;;AAGH,IAAa,oBAAb,cAAuC,OAAO,YAA+B,CAAC,CAC5E,qBACA;CACE,UAAU,OAAO;CACjB,SAAS,OAAO;CAChB,OAAO,OAAO,YAAY,OAAO,OAAO,CAAC;;CAEzC,WAAW,OAAO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names":[],"sources":["../src/CloudflareThreadClient.ts"],"sourcesContent":["import { AgentInputError } from \"@effect-agent/core/AgentError\";\nimport { AgentId, type ThreadId } from \"@effect-agent/core/Identifiers\";\nimport { DigestError } from \"@effect-agent/thread/Digest\";\nimport {\n Receipt,\n type DurableSubmitAgent,\n type DurableSubmitOptions,\n} from \"@effect-agent/thread/DurableAgentRuntime\";\nimport { DurableRuntimeFailpointError } from \"@effect-agent/thread/DurableFailpoint\";\nimport { OperationDenied } from \"@effect-agent/thread/OperationAuthorizer\";\nimport {\n CanonicalRecordEnvelope,\n CanonicalSequence,\n DefinitionDigests,\n PersistedJson,\n} from \"@effect-agent/thread/Records\";\nimport {\n AdmissionFence,\n AdmissionGroup,\n AbortCommand,\n AbortIntent,\n AdmissionConflict,\n AdmissionPolicyError,\n ApprovalConflict,\n ApprovalDecisionCommand,\n ApprovalDecisionIntent,\n IdempotencyKey,\n JoinedToHost,\n LedgerError,\n Principal,\n Settlement,\n SettlementConflict,\n UnknownResolutionCommand,\n UnknownResolutionConflict,\n UnknownResolutionIntent,\n} from \"@effect-agent/thread/SubmissionLedger\";\nimport { SubmissionStatus } from \"@effect-agent/thread/SubmissionStatus\";\nimport {\n AppendConflict,\n ThreadNotMaterialized,\n ThreadStoreError,\n FenceRejected,\n} from \"@effect-agent/thread/ThreadStore\";\nimport { BrowserCrypto } from \"@effect/platform-browser\";\nimport { Context, Crypto, Duration, Effect, Layer, Schema } from \"effect\";\nimport { RpcTracing } from \"effect-cf\";\n\nimport { DurableAlarmError } from \"./Alarm.ts\";\nimport { ThreadObjectNamespace, type ThreadObjectRpc } from \"./CloudflareBindings.ts\";\nimport { AdmissionLimitExceeded } from \"./CloudflareConfig.ts\";\nimport { cloudflareFailureSignals, safeCauseMessage } from \"./internal/boundary.ts\";\n\n/**\n * The Worker↔Thread-Object host protocol (plan §1.4): Schema envelopes for the host\n * entry points (`submitEncoded`, `awaitSettlementEncoded`, `observePage`, `abortEncoded`,\n * `resolveApprovalEncoded`, `resolveUnknownEncoded`) plus the Worker-side client that speaks\n * it. Mirrors the WP2 port protocol: requests and responses are closed Schema unions, typed\n * failures travel as their own tagged classes and RE-DECODE to identical tags on the caller\n * (error-tag fidelity), and protocol anomalies are answered typed instead of thrown.\n */\n\n/** Ceiling for host protocol diagnostic strings. */\nconst MAX_HOST_DIAGNOSTIC_LENGTH = 4_096;\nconst PROGRESS_CANCELLATION_TIMEOUT = \"1 second\";\n\nconst BoundedDiagnostic = Schema.String.check(Schema.isMaxLength(MAX_HOST_DIAGNOSTIC_LENGTH));\n\n/** Truncate a diagnostic string to the host protocol's bounded length. */\nexport const boundHostDiagnostic = (value: string): string =>\n value.length > MAX_HOST_DIAGNOSTIC_LENGTH\n ? `${value.slice(0, MAX_HOST_DIAGNOSTIC_LENGTH - 3)}...`\n : value;\n\n/**\n * The envelope itself could not be honored: the Object could not decode the request, or a\n * response could not be encoded/decoded. Never carries operation semantics.\n */\nexport class HostProtocolError extends Schema.TaggedError<HostProtocolError>()(\n \"HostProtocolError\",\n {\n message: BoundedDiagnostic,\n },\n) {}\n\n/** The Worker-side stub call itself failed (RPC rejection, overload, eviction mid-call). */\nexport class ThreadClientError extends Schema.TaggedError<ThreadClientError>()(\n \"ThreadClientError\",\n {\n threadId: Schema.String,\n message: Schema.String,\n cause: Schema.optionalKey(Schema.Defect()),\n /** Cloudflare's own classification for a failure safe to retry with a fresh stub. */\n retryable: Schema.optionalKey(Schema.Boolean),\n /** Cloudflare overloads are surfaced immediately instead of adding retry pressure. */\n overloaded: Schema.optionalKey(Schema.Boolean),\n },\n) {}\n\n// ---------------------------------------------------------------------------\n// Requests\n// ---------------------------------------------------------------------------\n\n/**\n * One durable submission, input ALREADY encoded by the caller through the Agent Binding's\n * input schema (the Worker bundles the same Agent definitions as the Object, so schema\n * validation happens client-side; the resolved Binding re-validates at claim time). The\n * Thread identity is deliberately absent — the addressed Object IS the lane.\n */\nexport class SubmitRequest extends Schema.Class<SubmitRequest>(\n \"@effect-agent/platform-cloudflare/SubmitRequest\",\n)({\n agentId: AgentId,\n principal: Principal,\n idempotencyKey: IdempotencyKey,\n admissionGroup: Schema.optionalKey(AdmissionGroup),\n admissionFence: Schema.optionalKey(AdmissionFence),\n definitions: DefinitionDigests,\n inputPayload: PersistedJson,\n}) {}\n\n/** One bounded page of canonical records after an optional sequence. */\nexport class ObservePageRequest extends Schema.Class<ObservePageRequest>(\n \"@effect-agent/platform-cloudflare/ObservePageRequest\",\n)({\n afterSequence: Schema.optionalKey(CanonicalSequence),\n limit: Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(1_024)),\n}) {}\n\n/** One event-driven wait for canonical progress strictly after this sequence. */\nexport class AwaitProgressRequest extends Schema.Class<AwaitProgressRequest>(\n \"@effect-agent/platform-cloudflare/AwaitProgressRequest\",\n)({\n afterSequence: CanonicalSequence,\n waiterId: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(256)),\n}) {}\n\n/** Best-effort cancellation of one in-flight progress RPC. */\nexport class CancelProgressRequest extends Schema.Class<CancelProgressRequest>(\n \"@effect-agent/platform-cloudflare/CancelProgressRequest\",\n)({\n waiterId: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(256)),\n}) {}\n\n// ---------------------------------------------------------------------------\n// Responses\n// ---------------------------------------------------------------------------\n\n/**\n * Every typed failure a host entry point can produce, plus the protocol's own errors. Same\n * closed-union discipline as the WP2 `PortFailure`: members re-decode to the SAME tagged\n * classes on the Worker side; `cause` chains travel as Schema defects without instance\n * fidelity (plan §2.8).\n */\nexport const HostFailure = Schema.Union([\n AgentInputError,\n DigestError,\n AdmissionConflict,\n AdmissionPolicyError,\n SettlementConflict,\n ApprovalConflict,\n UnknownResolutionConflict,\n JoinedToHost,\n LedgerError,\n ThreadStoreError,\n ThreadNotMaterialized,\n AppendConflict,\n FenceRejected,\n DurableRuntimeFailpointError,\n AdmissionLimitExceeded,\n DurableAlarmError,\n OperationDenied,\n HostProtocolError,\n]);\n\nexport type HostFailure = typeof HostFailure.Type;\n\nexport class SubmitSucceeded extends Schema.TaggedClass<SubmitSucceeded>(\n \"@effect-agent/platform-cloudflare/SubmitSucceeded\",\n)(\"SubmitSucceeded\", {\n receipt: Receipt,\n}) {}\n\nexport class SubmissionStatusResponse extends Schema.TaggedClass<SubmissionStatusResponse>(\n \"@effect-agent/platform-cloudflare/SubmissionStatusResponse\",\n)(\"SubmissionStatusResponse\", { status: SubmissionStatus }) {}\n\nexport class SettlementReached extends Schema.TaggedClass<SettlementReached>(\n \"@effect-agent/platform-cloudflare/SettlementReached\",\n)(\"SettlementReached\", {\n settlement: Settlement,\n}) {}\n\nexport class ObservedPage extends Schema.TaggedClass<ObservedPage>(\n \"@effect-agent/platform-cloudflare/ObservedPage\",\n)(\"ObservedPage\", {\n records: Schema.Array(CanonicalRecordEnvelope).check(Schema.isMaxLength(1_024)),\n}) {}\n\n/** A record was already committed or an incarnation-local hint says the caller should re-read. */\nexport class ProgressObserved extends Schema.TaggedClass<ProgressObserved>(\n \"@effect-agent/platform-cloudflare/ProgressObserved\",\n)(\"ProgressObserved\", {}) {}\n\nexport class ProgressCancelled extends Schema.TaggedClass<ProgressCancelled>(\n \"@effect-agent/platform-cloudflare/ProgressCancelled\",\n)(\"ProgressCancelled\", {}) {}\n\nexport class AbortRecorded extends Schema.TaggedClass<AbortRecorded>(\n \"@effect-agent/platform-cloudflare/AbortRecorded\",\n)(\"AbortRecorded\", {\n intent: AbortIntent,\n}) {}\n\nexport class ApprovalRecorded extends Schema.TaggedClass<ApprovalRecorded>(\n \"@effect-agent/platform-cloudflare/ApprovalRecorded\",\n)(\"ApprovalRecorded\", {\n intent: ApprovalDecisionIntent,\n}) {}\n\nexport class UnknownResolutionRecorded extends Schema.TaggedClass<UnknownResolutionRecorded>(\n \"@effect-agent/platform-cloudflare/UnknownResolutionRecorded\",\n)(\"UnknownResolutionRecorded\", {\n intent: UnknownResolutionIntent,\n}) {}\n\n/** The entry point failed TYPED on the Object; the failure re-decodes verbatim. */\nexport class HostFailed extends Schema.TaggedClass<HostFailed>(\n \"@effect-agent/platform-cloudflare/HostFailed\",\n)(\"HostFailed\", {\n failure: HostFailure,\n}) {}\n\n/** The uniform answer of one host entry point. Callers narrow by the tag their call implies. */\nexport const HostResponse = Schema.Union([\n SubmitSucceeded,\n SettlementReached,\n SubmissionStatusResponse,\n ObservedPage,\n ProgressObserved,\n ProgressCancelled,\n AbortRecorded,\n ApprovalRecorded,\n UnknownResolutionRecorded,\n HostFailed,\n]);\n\nexport type HostResponse = typeof HostResponse.Type;\n\n// ---------------------------------------------------------------------------\n// Codecs (shared by the Object endpoints and the Worker client)\n// ---------------------------------------------------------------------------\n\nexport const decodeSubmitRequest = Schema.decodeUnknownEffect(SubmitRequest);\nexport const encodeSubmitRequest = Schema.encodeEffect(SubmitRequest);\nexport const decodeReceipt = Schema.decodeUnknownEffect(Receipt);\nexport const encodeReceipt = Schema.encodeEffect(Receipt);\nexport const decodeObservePageRequest = Schema.decodeUnknownEffect(ObservePageRequest);\nexport const encodeObservePageRequest = Schema.encodeEffect(ObservePageRequest);\nexport const decodeAwaitProgressRequest = Schema.decodeUnknownEffect(AwaitProgressRequest);\nexport const encodeAwaitProgressRequest = Schema.encodeEffect(AwaitProgressRequest);\nexport const decodeCancelProgressRequest = Schema.decodeUnknownEffect(CancelProgressRequest);\nexport const encodeCancelProgressRequest = Schema.encodeEffect(CancelProgressRequest);\nexport const decodeAbortCommand = Schema.decodeUnknownEffect(AbortCommand);\nexport const encodeAbortCommand = Schema.encodeEffect(AbortCommand);\nexport const decodeApprovalDecisionCommand = Schema.decodeUnknownEffect(ApprovalDecisionCommand);\nexport const encodeApprovalDecisionCommand = Schema.encodeEffect(ApprovalDecisionCommand);\nexport const decodeUnknownResolutionCommand = Schema.decodeUnknownEffect(UnknownResolutionCommand);\nexport const encodeUnknownResolutionCommand = Schema.encodeEffect(UnknownResolutionCommand);\nexport const encodeHostResponse = Schema.encodeEffect(HostResponse);\nexport const decodeHostResponse = Schema.decodeUnknownEffect(HostResponse);\n\n// ---------------------------------------------------------------------------\n// Worker-side client\n// ---------------------------------------------------------------------------\n\n/** Failure surface of `CloudflareThreadClient.submit`. */\nconst ClientSubmitHostFailure = Schema.Union([\n AgentInputError,\n DigestError,\n AdmissionConflict,\n AdmissionPolicyError,\n LedgerError,\n ThreadStoreError,\n ThreadNotMaterialized,\n AppendConflict,\n FenceRejected,\n DurableRuntimeFailpointError,\n AdmissionLimitExceeded,\n DurableAlarmError,\n HostProtocolError,\n]);\n\nconst ClientAwaitHostFailure = Schema.Union([\n LedgerError,\n SettlementConflict,\n OperationDenied,\n HostProtocolError,\n]);\n\nconst ClientObserveHostFailure = Schema.Union([\n ThreadStoreError,\n ThreadNotMaterialized,\n OperationDenied,\n HostProtocolError,\n]);\n\nconst ClientAbortHostFailure = Schema.Union([\n OperationDenied,\n LedgerError,\n SettlementConflict,\n JoinedToHost,\n DurableRuntimeFailpointError,\n DurableAlarmError,\n HostProtocolError,\n]);\n\nconst ClientApprovalHostFailure = Schema.Union([\n LedgerError,\n SettlementConflict,\n ApprovalConflict,\n OperationDenied,\n DurableAlarmError,\n HostProtocolError,\n]);\n\nconst ClientUnknownHostFailure = Schema.Union([\n LedgerError,\n SettlementConflict,\n UnknownResolutionConflict,\n JoinedToHost,\n DurableRuntimeFailpointError,\n OperationDenied,\n DurableAlarmError,\n HostProtocolError,\n]);\n\nexport type ClientSubmitFailure = typeof ClientSubmitHostFailure.Type | ThreadClientError;\nexport type ClientAwaitFailure = typeof ClientAwaitHostFailure.Type | ThreadClientError;\nexport type ClientObserveFailure = typeof ClientObserveHostFailure.Type | ThreadClientError;\nexport type ClientProgressFailure = ClientObserveFailure;\nexport type ClientAbortFailure = typeof ClientAbortHostFailure.Type | ThreadClientError;\nexport type ClientApprovalFailure = typeof ClientApprovalHostFailure.Type | ThreadClientError;\nexport type ClientUnknownFailure = typeof ClientUnknownHostFailure.Type | ThreadClientError;\n\nconst outOfContract = (threadId: string, operation: string, observed: string): ThreadClientError =>\n ThreadClientError.make({\n threadId,\n message: boundHostDiagnostic(\n `The Thread Object answered ${operation} with the out-of-contract ${observed}.`,\n ),\n });\n\nconst hostRpcMethods = {\n submit: \"submitEncoded\",\n awaitSettlement: \"awaitSettlementEncoded\",\n submissionStatus: \"submissionStatusEncoded\",\n awaitProgress: \"awaitProgressEncoded\",\n cancelProgress: \"cancelProgressEncoded\",\n observePage: \"observePage\",\n abort: \"abortEncoded\",\n resolveApproval: \"resolveApprovalEncoded\",\n resolveUnknown: \"resolveUnknownEncoded\",\n} as const satisfies Record<string, keyof ThreadObjectRpc>;\n\n/** Worker-side client over the Thread Object namespace (DEPLOY-010). */\nexport class CloudflareThreadClient extends Context.Service<\n CloudflareThreadClient,\n {\n /** Encode the input client-side, then durably submit to the owning Object. */\n readonly submit: <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: DurableSubmitOptions,\n ) => Effect.Effect<Receipt, ClientSubmitFailure, InputSchema[\"EncodingServices\"]>;\n /** Wake-hinted, poll-guaranteed settlement wait executed inside the owning Object. */\n readonly submissionStatus: (\n receipt: Receipt,\n ) => Effect.Effect<SubmissionStatus, ClientAwaitFailure>;\n readonly awaitSettlement: (receipt: Receipt) => Effect.Effect<Settlement, ClientAwaitFailure>;\n /**\n * Wait without polling until progress after `afterSequence` is already durable or hinted.\n * The result is deliberately void: canonical records remain authoritative and must be read.\n * Interruption waits at most one second for best-effort remote cancellation.\n */\n readonly awaitProgress: (\n threadId: ThreadId,\n afterSequence: CanonicalSequence,\n ) => Effect.Effect<void, ClientProgressFailure>;\n /** One bounded page of canonical records. */\n readonly readPage: (\n threadId: ThreadId,\n options?: {\n readonly afterSequence?: CanonicalSequence | undefined;\n readonly limit?: number | undefined;\n },\n ) => Effect.Effect<ReadonlyArray<CanonicalRecordEnvelope>, ClientObserveFailure>;\n /**\n * Every canonical record up to the CURRENT committed tail, via repeated pages. A\n * snapshot read, not a live observation — callers wanting liveness re-read after\n * `awaitSettlement`.\n */\n readonly readAll: (\n threadId: ThreadId,\n ) => Effect.Effect<ReadonlyArray<CanonicalRecordEnvelope>, ClientObserveFailure>;\n /**\n * Submission-addressed operations take the owning Thread explicitly (from the\n * Receipt): minted Submission identities stay OPAQUE outside the storage adapter that\n * minted them (D-P6-5), so the client never parses one to find the lane.\n */\n readonly abort: (\n threadId: ThreadId,\n command: AbortCommand,\n ) => Effect.Effect<AbortIntent, ClientAbortFailure>;\n readonly resolveApproval: (\n threadId: ThreadId,\n command: ApprovalDecisionCommand,\n ) => Effect.Effect<ApprovalDecisionIntent, ClientApprovalFailure>;\n readonly resolveUnknown: (\n threadId: ThreadId,\n command: UnknownResolutionCommand,\n ) => Effect.Effect<UnknownResolutionIntent, ClientUnknownFailure>;\n }\n>()(\"@effect-agent/platform-cloudflare/CloudflareThreadClient\") {\n /**\n * Assemble the client from a resolved namespace and the platform Crypto implementation.\n * rpcTracing is the binding name and remains opt-in. Caller authentication, principals,\n * idempotency keys, and definition digests are still explicit submission inputs.\n */\n static layerFromBinding(options: {\n readonly namespace: DurableObjectNamespace<ThreadObjectRpc>;\n readonly rpcTracing?: string;\n }): Layer.Layer<CloudflareThreadClient> {\n return CloudflareThreadClient.layer.pipe(\n Layer.provide([ThreadObjectNamespace.layer(options.namespace, options), BrowserCrypto.layer]),\n );\n }\n\n static readonly layer: Layer.Layer<\n CloudflareThreadClient,\n never,\n ThreadObjectNamespace | Crypto.Crypto\n > = Layer.effect(CloudflareThreadClient)(\n Effect.gen(function* () {\n const { namespace, rpcTracing } = yield* ThreadObjectNamespace;\n const crypto = yield* Crypto.Crypto;\n\n const call = Effect.fn(\n function* (\n threadId: string,\n operation: keyof typeof hostRpcMethods,\n encoded: unknown,\n ): Effect.fn.Return<HostResponse, ThreadClientError | HostProtocolError> {\n // Empty arguments preserve native arity. Passing `undefined` still adds an argument.\n const traceArgs =\n rpcTracing === undefined ? [] : yield* RpcTracing.withRpcTraceContext([]);\n\n const raw = yield* Effect.tryPromise({\n try: () => {\n const stub = namespace.get(namespace.idFromName(threadId));\n\n return stub[hostRpcMethods[operation]](encoded, ...traceArgs);\n },\n catch: (cause) =>\n ThreadClientError.make({\n threadId,\n message: boundHostDiagnostic(\n `${operation} did not reach the Thread Object: ${safeCauseMessage(\n cause,\n \"the RPC failed without a diagnostic\",\n )}`,\n ),\n cause,\n ...cloudflareFailureSignals(cause),\n }),\n });\n\n return yield* decodeHostResponse(raw).pipe(\n Effect.mapError((error): HostProtocolError =>\n HostProtocolError.make({\n message: boundHostDiagnostic(\n `The ${operation} answer could not be decoded: ${error.message}`,\n ),\n }),\n ),\n );\n },\n (effect, threadId, operation) =>\n rpcTracing === undefined\n ? Effect.withSpan(effect, \"CloudflareThreadClient.call\", {\n attributes: { threadId, operation },\n })\n : RpcTracing.withRpcClientSpan(effect, rpcTracing, hostRpcMethods[operation]),\n );\n\n const expect = <ResultSchema extends Schema.Top, FailureSchema extends Schema.Top>(\n threadId: string,\n operation: string,\n resultSchema: ResultSchema,\n failureSchema: FailureSchema,\n ) => {\n const isExpectedResult = Schema.is(resultSchema);\n const isExpectedFailure = Schema.is(failureSchema);\n\n return (\n response: HostResponse,\n ): Effect.Effect<ResultSchema[\"Type\"], FailureSchema[\"Type\"] | ThreadClientError> => {\n if (response._tag === \"HostFailed\") {\n const failure = response.failure;\n\n return isExpectedFailure(failure)\n ? Effect.fail(failure)\n : Effect.fail(outOfContract(threadId, operation, `failure ${failure._tag}`));\n }\n if (!isExpectedResult(response)) {\n return Effect.fail(outOfContract(threadId, operation, `result ${response._tag}`));\n }\n\n return Effect.succeed(response);\n };\n };\n\n const readPage = (\n threadId: ThreadId,\n options?: {\n readonly afterSequence?: CanonicalSequence | undefined;\n readonly limit?: number | undefined;\n },\n ) =>\n Effect.gen(function* () {\n const request = ObservePageRequest.make({\n ...(options?.afterSequence === undefined\n ? {}\n : { afterSequence: options.afterSequence }),\n limit: options?.limit ?? 256,\n });\n\n const encoded = yield* encodeObservePageRequest(request).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(`observePage request encode failed: ${error.message}`),\n }),\n ),\n );\n\n const response = yield* call(threadId, \"observePage\", encoded);\n\n const page = yield* expect(\n threadId,\n \"observePage\",\n ObservedPage,\n ClientObserveHostFailure,\n )(response);\n\n return page.records;\n });\n\n const cancelProgress = (threadId: ThreadId, waiterId: string): Effect.Effect<void> =>\n encodeCancelProgressRequest(CancelProgressRequest.make({ waiterId })).pipe(\n Effect.mapError(() => undefined),\n Effect.flatMap((encoded) => call(threadId, \"cancelProgress\", encoded)),\n // Finalizers are uninterruptible; only the foreign RPC branch must remain\n // interruptible so a lost cancellation reply cannot prevent local shutdown.\n Effect.interruptible,\n Effect.timeout(PROGRESS_CANCELLATION_TIMEOUT),\n Effect.asVoid,\n Effect.ignore,\n );\n\n return CloudflareThreadClient.of({\n submit: <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: DurableSubmitOptions,\n ) =>\n Effect.gen(function* () {\n // Client-side half of `DurableAgentRuntime.submit`'s input boundary: encode\n // through the Agent's input schema and prove the canonical persistence bounds.\n const encodedInput = yield* Schema.encodeEffect(agent.definition.input)(input).pipe(\n Effect.mapError((cause) =>\n AgentInputError.make({ message: `Unable to encode Agent input: ${cause.message}` }),\n ),\n );\n\n const inputPayload = yield* Schema.decodeUnknownEffect(PersistedJson)(\n encodedInput,\n ).pipe(\n Effect.mapError(() =>\n AgentInputError.make({\n message: \"Agent input does not satisfy the canonical persistence bounds\",\n }),\n ),\n );\n\n const request = SubmitRequest.make({\n agentId: agent.definition.id,\n principal: options.principal,\n idempotencyKey: options.idempotencyKey,\n ...(options.admissionGroup === undefined\n ? {}\n : { admissionGroup: options.admissionGroup }),\n ...(options.admissionFence === undefined\n ? {}\n : { admissionFence: options.admissionFence }),\n definitions: options.definitions,\n inputPayload,\n });\n\n const encoded = yield* encodeSubmitRequest(request).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(`submit request encode failed: ${error.message}`),\n }),\n ),\n );\n\n const response = yield* call(options.threadId, \"submit\", encoded);\n\n const succeeded = yield* expect(\n options.threadId,\n \"submit\",\n SubmitSucceeded,\n ClientSubmitHostFailure,\n )(response);\n\n return succeeded.receipt;\n }),\n\n submissionStatus: (receipt) =>\n Effect.gen(function* () {\n const encoded = yield* encodeReceipt(receipt).pipe(\n Effect.mapError(() => HostProtocolError.make({ message: \"Invalid receipt\" })),\n );\n\n const response = yield* call(receipt.threadId, \"submissionStatus\", encoded);\n\n const result = yield* expect(\n receipt.threadId,\n \"submissionStatus\",\n SubmissionStatusResponse,\n ClientAwaitHostFailure,\n )(response);\n\n return result.status;\n }),\n awaitSettlement: (receipt) =>\n Effect.gen(function* () {\n const encoded = yield* encodeReceipt(receipt).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(`receipt encode failed: ${error.message}`),\n }),\n ),\n );\n\n const response = yield* call(receipt.threadId, \"awaitSettlement\", encoded);\n\n const settled = yield* expect(\n receipt.threadId,\n \"awaitSettlement\",\n SettlementReached,\n ClientAwaitHostFailure,\n )(response);\n\n return settled.settlement;\n }),\n\n awaitProgress: (threadId, afterSequence) =>\n Effect.gen(function* () {\n const waiterId = yield* crypto.randomUUIDv4.pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(\n `awaitProgress cancellation identity generation failed: ${error.message}`,\n ),\n }),\n ),\n );\n\n const request = AwaitProgressRequest.make({ afterSequence, waiterId });\n\n const encoded = yield* encodeAwaitProgressRequest(request).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(\n `awaitProgress request encode failed: ${error.message}`,\n ),\n }),\n ),\n );\n\n const attempt = (retry: number): Effect.Effect<void, ClientProgressFailure> =>\n call(threadId, \"awaitProgress\", encoded).pipe(\n Effect.flatMap(\n expect(threadId, \"awaitProgress\", ProgressObserved, ClientObserveHostFailure),\n ),\n Effect.asVoid,\n Effect.catchTag(\"ThreadClientError\", (error) =>\n error.retryable === true && error.overloaded !== true && retry < 5\n ? Effect.sleep(Duration.millis(10 * 2 ** retry)).pipe(\n Effect.andThen(attempt(retry + 1)),\n )\n : Effect.fail(error),\n ),\n );\n\n yield* attempt(0).pipe(Effect.onInterrupt(() => cancelProgress(threadId, waiterId)));\n }),\n\n readPage,\n\n readAll: (threadId) =>\n Effect.gen(function* () {\n const all: Array<CanonicalRecordEnvelope> = [];\n let after: CanonicalSequence | undefined;\n\n for (;;) {\n const page = yield* readPage(threadId, { afterSequence: after, limit: 1_024 });\n\n all.push(...page);\n const last = page.at(-1);\n\n if (page.length < 1_024 || last === undefined) return all;\n after = last.sequence;\n }\n }),\n\n abort: (threadId, command) =>\n Effect.gen(function* () {\n const encoded = yield* encodeAbortCommand(command).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(`abort command encode failed: ${error.message}`),\n }),\n ),\n );\n\n const response = yield* call(threadId, \"abort\", encoded);\n\n const recorded = yield* expect(\n threadId,\n \"abort\",\n AbortRecorded,\n ClientAbortHostFailure,\n )(response);\n\n return recorded.intent;\n }),\n\n resolveApproval: (threadId, command) =>\n Effect.gen(function* () {\n const encoded = yield* encodeApprovalDecisionCommand(command).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(`approval command encode failed: ${error.message}`),\n }),\n ),\n );\n\n const response = yield* call(threadId, \"resolveApproval\", encoded);\n\n const recorded = yield* expect(\n threadId,\n \"resolveApproval\",\n ApprovalRecorded,\n ClientApprovalHostFailure,\n )(response);\n\n return recorded.intent;\n }),\n\n resolveUnknown: (threadId, command) =>\n Effect.gen(function* () {\n const encoded = yield* encodeUnknownResolutionCommand(command).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(\n `resolution command encode failed: ${error.message}`,\n ),\n }),\n ),\n );\n\n const response = yield* call(threadId, \"resolveUnknown\", encoded);\n\n const recorded = yield* expect(\n threadId,\n \"resolveUnknown\",\n UnknownResolutionRecorded,\n ClientUnknownHostFailure,\n )(response);\n\n return recorded.intent;\n }),\n });\n }),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,MAAM,6BAA6B;AACnC,MAAM,gCAAgC;AAEtC,MAAM,oBAAoB,OAAO,OAAO,MAAM,OAAO,YAAY,0BAA0B,CAAC;;AAG5F,MAAa,uBAAuB,UAClC,MAAM,SAAS,6BACX,GAAG,MAAM,MAAM,GAAG,IAA8B,EAAE,OAClD;;;;;AAMN,IAAa,oBAAb,cAAuC,OAAO,YAA+B,CAAC,CAC5E,qBACA,EACE,SAAS,kBACX,CACF,CAAC,CAAC,CAAC;;AAGH,IAAa,oBAAb,cAAuC,OAAO,YAA+B,CAAC,CAC5E,qBACA;CACE,UAAU,OAAO;CACjB,SAAS,OAAO;CAChB,OAAO,OAAO,YAAY,OAAO,OAAO,CAAC;;CAEzC,WAAW,OAAO,YAAY,OAAO,OAAO;;CAE5C,YAAY,OAAO,YAAY,OAAO,OAAO;AAC/C,CACF,CAAC,CAAC,CAAC;;;;;;;AAYH,IAAa,gBAAb,cAAmC,OAAO,MACxC,iDACF,CAAC,CAAC;CACA,SAAS;CACT,WAAW;CACX,gBAAgB;CAChB,gBAAgB,OAAO,YAAY,cAAc;CACjD,gBAAgB,OAAO,YAAY,cAAc;CACjD,aAAa;CACb,cAAc;AAChB,CAAC,CAAC,CAAC,CAAC;;AAGJ,IAAa,qBAAb,cAAwC,OAAO,MAC7C,sDACF,CAAC,CAAC;CACA,eAAe,OAAO,YAAY,iBAAiB;CACnD,OAAO,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,GAAG,OAAO,oBAAoB,IAAK,CAAC;AACpF,CAAC,CAAC,CAAC,CAAC;;AAGJ,IAAa,uBAAb,cAA0C,OAAO,MA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UAAU,YAC1B,OAAO,IAAI,aAAa;IACtB,MAAM,UAAU,OAAO,8BAA8B,OAAO,CAAC,CAAC,KAC5D,OAAO,UAAU,UACf,kBAAkB,KAAK,EACrB,SAAS,oBAAoB,mCAAmC,MAAM,SAAS,EACjF,CAAC,CACH,CACF;IAEA,MAAM,WAAW,OAAO,KAAK,UAAU,mBAAmB,OAAO;IASjE,QAAO,OAPiB,OACtB,UACA,mBACA,kBACA,yBACF,CAAC,CAAC,QAAQ,EAAA,CAEM;GAClB,CAAC;GAEH,iBAAiB,UAAU,YACzB,OAAO,IAAI,aAAa;IACtB,MAAM,UAAU,OAAO,+BAA+B,OAAO,CAAC,CAAC,KAC7D,OAAO,UAAU,UACf,kBAAkB,KAAK,EACrB,SAAS,oBACP,qCAAqC,MAAM,SAC7C,EACF,CAAC,CACH,CACF;IAEA,MAAM,WAAW,OAAO,KAAK,UAAU,kBAAkB,OAAO;IAShE,QAAO,OAPiB,OACtB,UACA,kBACA,2BACA,wBACF,CAAC,CAAC,QAAQ,EAAA,CAEM;GAClB,CAAC;EACL,CAAC;CACH,CAAC,CACH;AACF"}
@@ -1,7 +1,7 @@
1
1
  import { r as BrowserRunSessionLifecycle } from "./browser-session-lifecycle-DJpqLXy_.mjs";
2
2
  import { Context, Crypto, Effect, Layer, Redacted, Schema, Scope } from "effect";
3
3
  import { InteractiveBrowserPolicy } from "@effect-agent/sandbox/InteractiveBrowser";
4
- import { CredentialFieldRole, ProtectedBrowser, ProtectedBrowserControl, ProtectedBrowserError, ProtectedCleanup } from "@effect-agent/sandbox/ProtectedBrowser";
4
+ import { CredentialFieldRole, CredentialOrigin, ProtectedBrowser, ProtectedBrowserControl, ProtectedBrowserError, ProtectedCleanup } from "@effect-agent/sandbox/ProtectedBrowser";
5
5
  //#region src/protected-browser/policy.d.ts
6
6
  declare const ProtectedTransportError_base: Schema.Class<ProtectedTransportError, Schema.TaggedStruct<"ProtectedTransportError", {
7
7
  readonly reason: Schema.Literals<readonly ["stale-reference", "needs-attention", "unsupported", "provider"]>;
@@ -14,12 +14,14 @@ declare const ProtectedBrowserDispatch_base: Context.ServiceClass<ProtectedBrows
14
14
  declare class ProtectedBrowserDispatch extends ProtectedBrowserDispatch_base {}
15
15
  /** Decoded adapter boundary. SDK exceptions and page diagnostics never cross this port. */
16
16
  interface ProtectedBrowserTransport {
17
+ /** Select observation/target origins; undefined restores all network-permitted HTTPS frames. */
18
+ readonly restrictObservation: (origins: ReadonlyArray<typeof CredentialOrigin.Type> | undefined) => Effect.Effect<void, ProtectedTransportError>;
17
19
  readonly context: Effect.Effect<typeof ProtectedPageContext.Type, ProtectedTransportError>;
18
20
  readonly discover: Effect.Effect<typeof ProtectedDiscovery.Type, ProtectedTransportError>;
19
21
  readonly target: (ref: string) => Effect.Effect<ProtectedBrowserControl, ProtectedTransportError>;
20
22
  readonly navigate: (url: string) => Effect.Effect<void, ProtectedTransportError>;
21
23
  readonly click: (ref: string) => Effect.Effect<void, ProtectedTransportError>;
22
- readonly fill: (ref: string, role: typeof CredentialFieldRole.Type, value: Redacted.Redacted<string>) => Effect.Effect<void, ProtectedTransportError, ProtectedBrowserDispatch>;
24
+ readonly fill: (ref: string, role: typeof CredentialFieldRole.Type | "text" | "select", value: Redacted.Redacted<string>) => Effect.Effect<void, ProtectedTransportError, ProtectedBrowserDispatch>;
23
25
  /** Invalidates local references synchronously before bounded exact-session cleanup. */
24
26
  readonly invalidate: () => void;
25
27
  readonly close: Effect.Effect<typeof ProtectedCleanup.Type>;
@@ -44,7 +46,7 @@ declare const ProtectedDiscovery: Schema.Struct<{
44
46
  }>;
45
47
  /**
46
48
  * Fresh private passes only. Account administrators and Browser Rendering token holders are
47
- * trusted operators. No viewer, handoff, raw JavaScript, screenshot or plaintext-fill API exists.
49
+ * trusted operators. No viewer, handoff, raw JavaScript, screenshot or plaintext credential API exists.
48
50
  * Hosts explicitly authorize post-exposure observations for recipients they trust not to echo.
49
51
  */
50
52
  declare const browserRunProtectedLayer: () => Layer.Layer<ProtectedBrowser, never, BrowserRunProtectedTransport | Crypto.Crypto>;