@effect-agent/platform-cloudflare 0.1.0-beta.8 → 0.1.0-beta.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Alarm.d.mts +183 -0
- package/dist/Alarm.mjs +454 -0
- package/dist/Alarm.mjs.map +1 -0
- package/dist/BrowserRestCapture.d.mts +35 -0
- package/dist/BrowserRestCapture.mjs +238 -0
- package/dist/BrowserRestCapture.mjs.map +1 -0
- package/dist/BrowserRestCrawl.d.mts +17 -0
- package/dist/BrowserRestCrawl.mjs +244 -0
- package/dist/BrowserRestCrawl.mjs.map +1 -0
- package/dist/CloudflareAiGateway.d.mts +64 -0
- package/dist/CloudflareAiGateway.mjs +70 -0
- package/dist/CloudflareAiGateway.mjs.map +1 -0
- package/dist/CloudflareBindings.d.mts +112 -0
- package/dist/CloudflareBindings.mjs +101 -0
- package/dist/CloudflareBindings.mjs.map +1 -0
- package/dist/CloudflareBrowser-D4YqaTAl.mjs +495 -0
- package/dist/CloudflareBrowser-D4YqaTAl.mjs.map +1 -0
- package/dist/CloudflareBrowser-DJq53niJ.d.mts +80 -0
- package/dist/CloudflareBrowser.d.mts +2 -0
- package/dist/CloudflareBrowser.mjs +2 -0
- package/dist/CloudflareCodeMode.d.mts +44 -0
- package/dist/CloudflareCodeMode.mjs +616 -0
- package/dist/CloudflareCodeMode.mjs.map +1 -0
- package/dist/CloudflareConfig-f3CqTel1.d.mts +101 -0
- package/dist/CloudflareConfig.d.mts +2 -0
- package/dist/CloudflareConfig.mjs +122 -0
- package/dist/CloudflareConfig.mjs.map +1 -0
- package/dist/CloudflareMemory.d.mts +142 -0
- package/dist/CloudflareMemory.mjs +195 -0
- package/dist/CloudflareMemory.mjs.map +1 -0
- package/dist/CloudflareScheduling.d.mts +52 -0
- package/dist/CloudflareScheduling.mjs +389 -0
- package/dist/CloudflareScheduling.mjs.map +1 -0
- package/dist/CloudflareSubscriptions.d.mts +87 -0
- package/dist/CloudflareSubscriptions.mjs +524 -0
- package/dist/CloudflareSubscriptions.mjs.map +1 -0
- package/dist/CloudflareThreadClient.d.mts +1286 -0
- package/dist/CloudflareThreadClient.mjs +386 -0
- package/dist/CloudflareThreadClient.mjs.map +1 -0
- package/dist/InteractiveBrowser.d.mts +144 -0
- package/dist/InteractiveBrowser.mjs +1090 -0
- package/dist/InteractiveBrowser.mjs.map +1 -0
- package/dist/ProtectedBrowser.d.mts +65 -0
- package/dist/ProtectedBrowser.mjs +859 -0
- package/dist/ProtectedBrowser.mjs.map +1 -0
- package/dist/ThreadObject-3uDpKfB3.d.mts +816 -0
- package/dist/ThreadObject-DGkXv41C.mjs +836 -0
- package/dist/ThreadObject-DGkXv41C.mjs.map +1 -0
- package/dist/ThreadObject.d.mts +2 -0
- package/dist/ThreadObject.mjs +3 -0
- package/dist/WakeScheduler.d.mts +23 -0
- package/dist/WakeScheduler.mjs +60 -0
- package/dist/WakeScheduler.mjs.map +1 -0
- package/dist/boundary-BguazVkh.mjs +42 -0
- package/dist/boundary-BguazVkh.mjs.map +1 -0
- package/dist/browser-session-lifecycle-CUbVfEgP.mjs +84 -0
- package/dist/browser-session-lifecycle-CUbVfEgP.mjs.map +1 -0
- package/dist/browser-session-lifecycle-DJpqLXy_.d.mts +21 -0
- package/dist/index.d.mts +13 -1547
- package/dist/index.mjs +13 -1636
- package/dist/prepared-admission-DSi55W-7.mjs +73 -0
- package/dist/prepared-admission-DSi55W-7.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/package.json +1 -53
- package/src/Alarm.ts +953 -0
- package/src/BrowserRestCapture.ts +477 -0
- package/src/BrowserRestCrawl.ts +540 -0
- package/src/CloudflareAiGateway.ts +170 -0
- package/src/CloudflareBindings.ts +180 -0
- package/src/CloudflareBrowser.ts +15 -0
- package/src/{code-mode-executor.ts → CloudflareCodeMode.ts} +372 -204
- package/src/{config.ts → CloudflareConfig.ts} +9 -8
- package/src/CloudflareMemory.ts +406 -0
- package/src/CloudflareScheduling.ts +733 -0
- package/src/CloudflareSubscriptions.ts +1045 -0
- package/src/CloudflareThreadClient.ts +807 -0
- package/src/InteractiveBrowser.ts +2357 -0
- package/src/ProtectedBrowser.ts +2 -0
- package/src/ThreadObject.ts +1179 -0
- package/src/{wake-scheduler.ts → WakeScheduler.ts} +23 -23
- package/src/index.ts +12 -23
- package/src/internal/boundary.ts +55 -0
- package/src/internal/browser-quick-action.ts +857 -0
- package/src/internal/browser-session-lifecycle.ts +160 -0
- package/src/internal/layers.ts +751 -0
- package/src/internal/message-delivery.ts +148 -0
- package/src/internal/prepared-admission.ts +116 -0
- package/src/internal/progress-wait.ts +121 -0
- package/src/internal/transport.ts +42 -0
- package/src/protected-browser/binding.ts +187 -0
- package/src/protected-browser/inspect-frame.ts +125 -0
- package/src/protected-browser/native.ts +429 -0
- package/src/protected-browser/policy.ts +719 -0
- package/dist/index.mjs.map +0 -1
- package/src/alarm.ts +0 -334
- package/src/bindings.ts +0 -145
- package/src/client.ts +0 -646
- package/src/conversation-object.ts +0 -768
- package/src/layers.ts +0 -376
- package/src/transport.ts +0 -38
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudflareCodeMode.mjs","names":["#dispatch"],"sources":["../src/CloudflareCodeMode.ts"],"sourcesContent":["import {\n CodeExecutionHost,\n CodeExecutionResourceUse,\n CodeExecutionResult,\n CodeExecutionTimeoutError,\n CodeExecutor,\n CodeExecutorStartError,\n CodeExecutorTerminatedError,\n CodeExecutorUnsupportedError,\n CodeExecutionProtocolError,\n CodeHostCall,\n CodeHostCallLimitError,\n CodeHostCallResult,\n CodeOutputLimitError,\n CodeProgramFailedError,\n CodeSourceError,\n type CodeExecutorExecute,\n type CodeExecutionRequest,\n} from \"@effect-agent/sandbox/CodeExecutor\";\nimport { SandboxImplementation } from \"@effect-agent/sandbox/Sandbox\";\nimport { RpcTarget } from \"cloudflare:workers\";\nimport { Clock, Duration, Effect, Exit, Fiber, Layer, Option, Queue, Schema } from \"effect\";\n\nimport { safeCauseDiagnostic, safeCauseMessage } from \"./internal/boundary.ts\";\n\n/**\n * The Cloudflare Dynamic Worker `CodeExecutor` adapter (C4 of ADR-0017;\n * DEPLOY-011). Each pass loads one fresh Worker through the Worker Loader\n * with `globalOutbound: null`, so generated code has no ambient network,\n * bindings, or secrets; its only authority is the pass-scoped RPC target that\n * routes back into the owning event's `CodeExecutionHost` service. Platform\n * CPU limits stop synchronous runaway programs; the executor-owned wall-clock\n * deadline interrupts asynchronously suspended passes. Deployment class `E`\n * only: the adapter records no persistent state and a later pass may run in a\n * completely different isolate.\n */\nexport const dynamicWorkerImplementation = SandboxImplementation.make({\n isolation: \"isolated\",\n identity: \"cloudflare-dynamic-worker\",\n});\n\ninterface CodeModePassHost extends Rpc.RpcTargetBranded {\n readonly call: (hostCall: unknown) => Promise<unknown>;\n}\n\ninterface CodeModeHarnessEntrypoint extends Rpc.WorkerEntrypointBranded {\n readonly run: (host: CodeModePassHost) => Promise<unknown>;\n}\n\n/**\n * One object-capability endpoint for one execution pass. Workers RPC invokes\n * the target in the request context where it was created, so the native\n * Promise returned by `dispatch` and the Effect fiber that settles it share\n * one I/O owner. Passing the target as `run()`'s argument also scopes the\n * remote stub to that RPC call; no request state lives at module scope.\n */\nclass CodeModePassHostTarget extends RpcTarget implements CodeModePassHost {\n readonly #dispatch: (hostCall: unknown) => Promise<unknown>;\n\n constructor(dispatch: (hostCall: unknown) => Promise<unknown>) {\n super();\n this.#dispatch = dispatch;\n }\n\n call(hostCall: unknown): Promise<unknown> {\n return this.#dispatch(hostCall);\n }\n}\n\n/**\n * The fixed harness loaded as the dynamic worker's main module. The generated\n * source becomes `program.mjs` (`export default (<expression>);`) — a module,\n * never `eval`. The harness installs namespace globals and a bounded console,\n * imports the program, invokes it exactly once, and returns one envelope the\n * host validates through Effect Schema.\n */\nconst HARNESS_MODULE = String.raw`\nimport { WorkerEntrypoint } from \"cloudflare:workers\";\nimport programDefault from \"./program.js\";\n\nconst encoder = new TextEncoder();\nconst utf8 = (text) => encoder.encode(text).byteLength;\nconst safeText = (value) => {\n try {\n if (value instanceof Error) return (value.name + \": \" + value.message).slice(0, 4000);\n if (typeof value === \"string\") return value.slice(0, 4000);\n const encoded = JSON.stringify(value);\n return (encoded === undefined ? String(value) : encoded).slice(0, 4000);\n } catch {\n return \"[unserializable value]\";\n }\n};\nconst safeJson = (value) => {\n try {\n const encoded = JSON.stringify(value);\n if (encoded !== undefined && encoded.length <= 4000) return JSON.parse(encoded);\n } catch {}\n return safeText(value);\n};\n\nexport default class CodeModeHarness extends WorkerEntrypoint {\n async run(host) {\n const config = this.env.CODE_MODE_PASS;\n const limits = config.limits;\n const logs = [];\n let logBytes = 0;\n let fatal;\n const boundedLogs = () => logs.slice(0, 4096);\n const write = (...values) => {\n const joined = values.map(safeText).join(\" \");\n const line = joined.length > 16000 ? joined.slice(0, 15999) + \"…\" : joined;\n const bytes = utf8(line);\n if (logs.length >= 4096 || logBytes + bytes > limits.maxLogBytes) {\n fatal = fatal ?? { _tag: \"log-limit\", observed: logBytes + bytes, logs: boundedLogs() };\n throw new Error(\"code-mode log limit exceeded\");\n }\n logs.push(line);\n logBytes += bytes;\n };\n globalThis.console = { log: write, info: write, warn: write, error: write, debug: write };\n\n let hostCalls = 0;\n const makeMethod = (namespace, method) => async (argument) => {\n hostCalls += 1;\n if (hostCalls > limits.maxHostCalls) {\n fatal = fatal ?? { _tag: \"host-call-limit\", logs: boundedLogs() };\n throw new Error(\"code-mode host-call limit exceeded\");\n }\n let argText;\n try {\n argText = JSON.stringify(argument);\n } catch {}\n if (argText === undefined || utf8(argText) > limits.maxHostCallArgumentBytes) {\n fatal = fatal ?? {\n _tag: \"argument-limit\",\n observed: argText === undefined ? 0 : utf8(argText),\n logs: boundedLogs(),\n };\n throw new Error(\"code-mode host-call argument limit exceeded\");\n }\n const outcome = await host.call({\n namespace,\n method,\n argument: JSON.parse(argText),\n });\n if (outcome !== null && typeof outcome === \"object\" && outcome._tag === \"CodeHostCallSuccess\") {\n return outcome.value;\n }\n if (outcome !== null && typeof outcome === \"object\" && outcome._tag === \"CodeHostCallFailure\") {\n throw outcome.error;\n }\n fatal = fatal ?? { _tag: \"protocol\", message: \"host returned an unrecognized outcome\" };\n throw new Error(\"code-mode host protocol violation\");\n };\n for (const namespace of config.namespaces) {\n const methods = {};\n for (const method of namespace.methods) {\n methods[method] = makeMethod(namespace.name, method);\n }\n globalThis[namespace.name] = methods;\n }\n\n // program.js is imported statically at the top of this module, so a\n // syntactically invalid program fails the whole harness at load (mapped\n // to a source error by the host). Using a static import keeps this module\n // free of dynamic-import expressions, which single-script Miniflare hosts\n // reject. The isolation boundary does NOT depend on the ordering of this\n // import versus the console/namespace shims installed below: the loaded\n // Worker has globalOutbound: null and no bindings, secrets, or env from\n // the Worker Loader config BEFORE any module in the graph evaluates, so\n // module-level program code has no ambient authority regardless. The\n // shims below are usability wrappers (bounded console, namespace globals),\n // and the accepted program is a single async-function expression whose\n // body runs only when invoked here — after the shims exist.\n const program = programDefault;\n if (typeof program !== \"function\") {\n return { _tag: \"source-not-a-function\", actual: typeof program };\n }\n try {\n const value = await program();\n if (fatal !== undefined) return fatal;\n let text;\n try {\n text = JSON.stringify(value);\n } catch {}\n if (text === undefined) {\n return {\n _tag: \"program-failed\",\n reason: \"non-json-result\",\n thrown: null,\n message: \"The program must return a JSON value\",\n logs: boundedLogs(),\n };\n }\n const resultBytes = utf8(text);\n if (resultBytes > limits.maxResultBytes) {\n return { _tag: \"result-limit\", observed: resultBytes, logs: boundedLogs() };\n }\n return {\n _tag: \"completed\",\n value: JSON.parse(text),\n logs: boundedLogs(),\n hostCalls,\n logBytes,\n resultBytes,\n };\n } catch (cause) {\n if (fatal !== undefined) return fatal;\n return {\n _tag: \"program-failed\",\n reason: cause instanceof Error ? \"threw\" : \"rejected\",\n thrown: safeJson(cause),\n message: safeText(cause),\n logs: boundedLogs(),\n };\n }\n }\n}\n`;\n\nconst BoundedLogs = Schema.Array(Schema.String.check(Schema.isMaxLength(16 * 1024))).check(\n Schema.isMaxLength(4_096),\n);\n\nconst HarnessCompleted = Schema.TaggedStruct(\"completed\", {\n value: Schema.Json,\n logs: BoundedLogs,\n hostCalls: Schema.Natural,\n logBytes: Schema.Natural,\n resultBytes: Schema.Natural,\n});\n\nconst HarnessNotAFunction = Schema.TaggedStruct(\"source-not-a-function\", {\n actual: Schema.String,\n});\n\nconst HarnessProgramFailed = Schema.TaggedStruct(\"program-failed\", {\n reason: Schema.Literals([\"threw\", \"rejected\", \"non-json-result\"]),\n thrown: Schema.Json,\n message: Schema.String,\n logs: BoundedLogs,\n});\n\nconst HarnessLogLimit = Schema.TaggedStruct(\"log-limit\", {\n observed: Schema.Natural,\n logs: BoundedLogs,\n});\n\nconst HarnessArgumentLimit = Schema.TaggedStruct(\"argument-limit\", {\n observed: Schema.Natural,\n logs: BoundedLogs,\n});\n\nconst HarnessResultLimit = Schema.TaggedStruct(\"result-limit\", {\n observed: Schema.Natural,\n logs: BoundedLogs,\n});\n\nconst HarnessHostCallLimit = Schema.TaggedStruct(\"host-call-limit\", {\n logs: BoundedLogs,\n});\n\nconst HarnessProtocol = Schema.TaggedStruct(\"protocol\", {\n message: Schema.String,\n});\n\nconst HarnessOutcome = Schema.Union([\n HarnessCompleted,\n HarnessNotAFunction,\n HarnessProgramFailed,\n HarnessLogLimit,\n HarnessArgumentLimit,\n HarnessResultLimit,\n HarnessHostCallLimit,\n HarnessProtocol,\n]);\n\nconst HarnessPassConfig = Schema.Struct({\n namespaces: Schema.Array(\n Schema.Struct({\n name: Schema.NonEmptyString,\n methods: Schema.Array(Schema.NonEmptyString).check(Schema.isMaxLength(64)),\n }),\n ).check(Schema.isMaxLength(32)),\n limits: Schema.Struct({\n maxLogBytes: Schema.Natural,\n maxResultBytes: Schema.Natural,\n maxHostCalls: Schema.Natural,\n maxHostCallArgumentBytes: Schema.Natural,\n }),\n});\n\nconst encodeHarnessPassConfig = Schema.encodeSync(HarnessPassConfig);\nconst encodeJsonPayload = Schema.encodeSync(Schema.fromJsonString(Schema.Json));\nconst decodeJsonPayload = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Json));\n\nconst decodeHarnessOutcome = (value: unknown) => {\n try {\n return Schema.decodeUnknownOption(HarnessOutcome)(value);\n } catch {\n return Option.none<typeof HarnessOutcome.Type>();\n }\n};\n\nconst decodeHostCall = (value: unknown) => {\n try {\n return Schema.decodeUnknownOption(CodeHostCall)(value);\n } catch {\n return Option.none<CodeHostCall>();\n }\n};\n\nconst decodeHostCallResult = (value: unknown) => {\n try {\n return Schema.decodeUnknownOption(CodeHostCallResult)(value);\n } catch {\n return Option.none<CodeHostCallResult>();\n }\n};\n\n/** Dispose a Cloudflare RPC handle when the runtime supplies its untyped disposal hook. @internal */\nexport const disposeRpcHandle = (handle: unknown): Effect.Effect<void> =>\n Effect.try({\n try: () => {\n if ((typeof handle !== \"object\" && typeof handle !== \"function\") || handle === null) return;\n if (!(Symbol.dispose in handle)) return;\n const dispose = Reflect.get(handle, Symbol.dispose);\n\n if (typeof dispose === \"function\") {\n Reflect.apply(dispose, handle, []);\n }\n },\n catch: (cause) =>\n safeCauseDiagnostic(cause, \"The Cloudflare RPC disposal hook failed without a diagnostic\"),\n }).pipe(\n Effect.catch((diagnostic) =>\n Effect.logWarning(`Cloudflare RPC handle disposal failed: ${diagnostic}`).pipe(\n Effect.ignoreCause,\n ),\n ),\n );\n\n/**\n * Project a host outcome to the plain JSON envelope the harness reads. A\n * `CodeExecutionHost` may return either real `CodeHostCallResult` instances\n * (the substitute and conformance kit) or plain-object equivalents (the Code\n * Mode capability's broker route), so this reads the shared fields rather than\n * `Schema.encodeSync`, which would reject a plain object.\n */\ninterface EncodedHostResultPayload {\n readonly encodedPayload: string;\n readonly resultBytes: number;\n}\n\nconst encodeHostResultPayload = (\n outcome: CodeHostCallResult,\n): EncodedHostResultPayload | undefined => {\n try {\n const payload = outcome._tag === \"CodeHostCallSuccess\" ? outcome.value : outcome.error;\n const encodedPayload = encodeJsonPayload(payload);\n\n return {\n encodedPayload,\n resultBytes: utf8ByteLength(encodedPayload),\n };\n } catch {\n return undefined;\n }\n};\n\nconst utf8ByteLength = (value: string): number => {\n let total = 0;\n\n for (const character of value) {\n const codePoint = character.codePointAt(0) ?? 0;\n\n total += codePoint <= 0x7f ? 1 : codePoint <= 0x7ff ? 2 : codePoint <= 0xffff ? 3 : 4;\n }\n\n return total;\n};\n\ninterface QueuedHostCall {\n readonly call: CodeHostCall;\n readonly resolve: (value: unknown) => void;\n readonly reject: (reason: unknown) => void;\n}\n\ntype HostWork =\n | { readonly _tag: \"call\"; readonly queued: QueuedHostCall }\n | { readonly _tag: \"limit\" };\n\ntype HostDispatchError =\n | CodeExecutionTimeoutError\n | CodeOutputLimitError\n | CodeExecutionProtocolError\n | CodeHostCallLimitError;\n\n/** Reserved global names the harness owns inside the dynamic worker. */\nconst reservedHarnessGlobals = new Set([\"console\"]);\n\nexport interface DynamicWorkerCodeExecutorOptions {\n /** The `worker_loader` binding. */\n readonly loader: WorkerLoader;\n /** Compatibility date for dynamic workers; defaults to `2025-05-01`. */\n readonly compatibilityDate?: string | undefined;\n}\n\nconst makeExecute = (\n options: DynamicWorkerCodeExecutorOptions,\n clock: Clock.Clock,\n): CodeExecutorExecute =>\n Effect.fn(\"DynamicWorkerCodeExecutor.execute\")(function* (request: CodeExecutionRequest) {\n if (request.network._tag !== \"NetworkDisabled\") {\n return yield* CodeExecutorUnsupportedError.make({\n implementation: dynamicWorkerImplementation,\n feature: \"network\",\n message:\n \"The Dynamic Worker executor denies all egress with globalOutbound: null; an allowlist is not supported in the first slice\",\n });\n }\n const sourceBytes = utf8ByteLength(request.source);\n\n if (sourceBytes > request.limits.maxSourceBytes) {\n return yield* CodeSourceError.make({\n implementation: dynamicWorkerImplementation,\n reason: \"oversized\",\n message: `Source is ${sourceBytes} bytes; the request allows ${request.limits.maxSourceBytes}`,\n });\n }\n for (const namespace of request.namespaces) {\n if (reservedHarnessGlobals.has(namespace.name)) {\n return yield* CodeExecutorUnsupportedError.make({\n implementation: dynamicWorkerImplementation,\n feature: \"namespaces\",\n message: `Namespace ${namespace.name} collides with a harness binding`,\n });\n }\n }\n const host = yield* CodeExecutionHost;\n\n // This synchronous clock access is confined to callbacks that must compute a timeout\n // immediately. The Clock service remains the authority, so tests and hosts can replace it.\n const startedAt = clock.monotonicTimeNanosUnsafe();\n const passDeadline = startedAt + Duration.toNanosUnsafe(request.limits.maxWallTime);\n\n const remainingPassWallTime = (): Duration.Duration => {\n const now = clock.monotonicTimeNanosUnsafe();\n\n return Duration.nanos(passDeadline > now ? passDeadline - now : 0n);\n };\n\n let issuedHostCalls = 0;\n let passOpen = true;\n const queuedHostCalls: Array<QueuedHostCall> = [];\n let passFailure: HostDispatchError | undefined;\n\n const failPass = (error: HostDispatchError): void => {\n if (passFailure === undefined) passFailure = error;\n };\n\n const rejectQueuedHostCalls = (reason: Error): void => {\n for (const queued of queuedHostCalls.splice(0)) {\n queued.reject(reason);\n }\n };\n\n const queue = yield* Queue.unbounded<HostWork>();\n\n const deliverHostOutcome = (\n queued: QueuedHostCall,\n outcome: CodeHostCallResult,\n ): Effect.Effect<void, CodeExecutionProtocolError | CodeOutputLimitError> =>\n Effect.gen(function* () {\n const decoded = decodeHostCallResult(outcome);\n\n if (Option.isNone(decoded)) {\n const error = CodeExecutionProtocolError.make({\n implementation: dynamicWorkerImplementation,\n message: \"The execution host returned a value outside the CodeHostCallResult schema\",\n });\n\n failPass(error);\n\n return yield* error;\n }\n const encoded = encodeHostResultPayload(decoded.value);\n\n if (encoded === undefined || encoded.resultBytes > request.limits.maxHostCallResultBytes) {\n const error = CodeOutputLimitError.make({\n implementation: dynamicWorkerImplementation,\n surface: \"host-call-result\",\n limit: request.limits.maxHostCallResultBytes,\n observed: encoded?.resultBytes ?? 0,\n logs: [],\n });\n\n failPass(error);\n\n return yield* error;\n }\n const normalizedPayload = decodeJsonPayload(encoded.encodedPayload);\n\n if (Option.isNone(normalizedPayload)) {\n const error = CodeExecutionProtocolError.make({\n implementation: dynamicWorkerImplementation,\n message: \"The execution host returned a result that could not cross the JSON boundary\",\n });\n\n failPass(error);\n\n return yield* error;\n }\n queued.resolve(\n decoded.value._tag === \"CodeHostCallSuccess\"\n ? { _tag: \"CodeHostCallSuccess\", value: normalizedPayload.value }\n : { _tag: \"CodeHostCallFailure\", error: normalizedPayload.value },\n );\n });\n\n // Workers RPC into the loader isolate cannot settle on the fiber blocked\n // in `entrypoint.run()`. A Scope-owned sibling fiber keeps that\n // independence while inheriting the pass Context and dying with the Scope.\n const serveHostCalls = Effect.gen(function* () {\n while (true) {\n const work = yield* Queue.take(queue);\n\n if (work._tag === \"limit\") {\n const error = CodeHostCallLimitError.make({\n implementation: dynamicWorkerImplementation,\n limit: request.limits.maxHostCalls,\n logs: [],\n });\n\n failPass(error);\n\n return yield* error;\n }\n const queued = work.queued;\n\n yield* host.call(queued.call).pipe(\n Effect.timeoutOrElse({\n duration: remainingPassWallTime(),\n orElse: () => {\n const error = CodeExecutionTimeoutError.make({\n implementation: dynamicWorkerImplementation,\n kind: \"wall-clock\",\n maxWallTime: request.limits.maxWallTime,\n logs: [],\n });\n\n failPass(error);\n\n return error;\n },\n }),\n Effect.flatMap((outcome) => deliverHostOutcome(queued, outcome)),\n Effect.tapError(() =>\n Effect.sync(() => queued.reject(new Error(\"Code Mode host call failed\"))),\n ),\n Effect.onInterrupt(() =>\n Effect.sync(() => queued.reject(new Error(\"Code Mode pass is closing\"))),\n ),\n );\n }\n });\n\n const concurrency = request.limits.maxHostCallConcurrency ?? 4;\n\n const server = yield* Effect.all(\n Array.from({ length: concurrency }, () => serveHostCalls),\n { concurrency, discard: true },\n ).pipe(Effect.andThen(Effect.never), Effect.forkScoped);\n\n const dispatch = (hostCall: unknown): Promise<unknown> => {\n if (!passOpen) {\n return Promise.reject(new Error(\"Code Mode pass is closing\"));\n }\n issuedHostCalls += 1;\n if (issuedHostCalls > request.limits.maxHostCalls) {\n const error = CodeHostCallLimitError.make({\n implementation: dynamicWorkerImplementation,\n limit: request.limits.maxHostCalls,\n logs: [],\n });\n\n failPass(error);\n Queue.offerUnsafe(queue, { _tag: \"limit\" });\n\n return Promise.reject(new Error(\"host-call limit exceeded\"));\n }\n const decoded = decodeHostCall(hostCall);\n\n if (Option.isNone(decoded)) {\n return Promise.reject(new TypeError(\"host calls must match the CodeHostCall schema\"));\n }\n\n return new Promise((resolve, reject) => {\n const queued = { call: decoded.value, resolve, reject };\n\n queuedHostCalls.push(queued);\n Queue.offerUnsafe(queue, { _tag: \"call\", queued });\n });\n };\n\n const closeAdmission = Effect.sync(() => {\n passOpen = false;\n rejectQueuedHostCalls(new Error(\"Code Mode pass is closing\"));\n });\n\n yield* Effect.addFinalizer(() => closeAdmission.pipe(Effect.andThen(Fiber.interrupt(server))));\n\n // No `allowExperimental`: the runtime only accepts it when the CALLING\n // worker carries the `experimental` compatibility flag, which deployed\n // consumers cannot set — the option would reject every pass in\n // production. The harness needs no experimental runtime features.\n const workerCode: WorkerLoaderWorkerCode = {\n compatibilityDate: options.compatibilityDate ?? \"2025-05-01\",\n mainModule: \"harness.js\",\n modules: {\n \"harness.js\": HARNESS_MODULE,\n \"program.js\": `export default (\\n${request.source}\\n);`,\n },\n env: {\n CODE_MODE_PASS: encodeHarnessPassConfig({\n namespaces: request.namespaces.map((namespace) => ({\n name: namespace.name,\n methods: namespace.methods,\n })),\n limits: {\n maxLogBytes: request.limits.maxLogBytes,\n maxResultBytes: request.limits.maxResultBytes,\n maxHostCalls: request.limits.maxHostCalls,\n maxHostCallArgumentBytes: request.limits.maxHostCallArgumentBytes,\n },\n }),\n },\n globalOutbound: null,\n ...(request.limits.cpuMillis === undefined\n ? {}\n : {\n limits: {\n cpuMs: request.limits.cpuMillis,\n subRequests: request.limits.maxHostCalls + 8,\n },\n }),\n };\n\n const worker = yield* Effect.acquireRelease(\n Effect.try({\n try: () => options.loader.load(workerCode),\n catch: (cause) => {\n const text = safeCauseMessage(cause, \"The Worker Loader failed without a diagnostic\");\n\n // Blame the program's source ONLY on a genuine compile diagnostic;\n // any other load rejection is an infrastructure start failure, not\n // the model's fault (see classifyWorkerFailure for the same split).\n if (/syntaxerror|failed to (compile|parse)/i.test(text)) {\n return CodeSourceError.make({\n implementation: dynamicWorkerImplementation,\n reason: \"invalid\",\n message: text.slice(0, 8_000),\n });\n }\n\n return CodeExecutorStartError.make({\n implementation: dynamicWorkerImplementation,\n message: `The Worker Loader rejected the pass: ${text}`.slice(0, 8_000),\n cause,\n });\n },\n }),\n disposeRpcHandle,\n );\n\n const entrypoint = yield* Effect.acquireRelease(\n Effect.try({\n try: () => worker.getEntrypoint<CodeModeHarnessEntrypoint>(),\n catch: (cause) => classifyWorkerFailure(cause, request.limits.maxWallTime),\n }),\n disposeRpcHandle,\n );\n\n const rpc = Effect.tryPromise({\n try: () => entrypoint.run(new CodeModePassHostTarget(dispatch)),\n catch: (cause) => classifyWorkerFailure(cause, request.limits.maxWallTime),\n });\n\n const exit = yield* Effect.raceFirst(\n rpc.pipe(\n Effect.timeoutOrElse({\n duration: remainingPassWallTime(),\n orElse: () =>\n CodeExecutionTimeoutError.make({\n implementation: dynamicWorkerImplementation,\n kind: \"wall-clock\",\n maxWallTime: request.limits.maxWallTime,\n logs: [],\n }),\n }),\n ),\n Fiber.join(server),\n ).pipe(Effect.exit);\n\n yield* closeAdmission;\n yield* Fiber.interrupt(server);\n if (passFailure !== undefined) {\n return yield* passFailure;\n }\n if (Exit.isFailure(exit)) {\n return yield* Effect.failCause(exit.cause);\n }\n const raw = exit.value;\n const finishedAt = clock.monotonicTimeNanosUnsafe();\n\n const outcome = decodeHarnessOutcome(raw);\n\n if (Option.isNone(outcome)) {\n return yield* CodeExecutionProtocolError.make({\n implementation: dynamicWorkerImplementation,\n message: \"The dynamic worker returned a value outside the harness envelope schema\",\n });\n }\n switch (outcome.value._tag) {\n case \"completed\": {\n return CodeExecutionResult.make({\n implementation: dynamicWorkerImplementation,\n value: outcome.value.value,\n logs: outcome.value.logs,\n resourceUse: CodeExecutionResourceUse.make({\n wallTime: Duration.nanos(finishedAt > startedAt ? finishedAt - startedAt : 0n),\n hostCalls: outcome.value.hostCalls,\n logBytes: outcome.value.logBytes,\n resultBytes: outcome.value.resultBytes,\n }),\n });\n }\n case \"source-not-a-function\": {\n return yield* CodeSourceError.make({\n implementation: dynamicWorkerImplementation,\n reason: \"not-a-function\",\n message: `The source expression evaluated to ${outcome.value.actual}; it must evaluate to one async function`,\n });\n }\n case \"program-failed\": {\n return yield* CodeProgramFailedError.make({\n implementation: dynamicWorkerImplementation,\n reason: outcome.value.reason,\n thrown: outcome.value.thrown,\n message: outcome.value.message.slice(0, 8_000),\n logs: outcome.value.logs,\n });\n }\n case \"log-limit\": {\n return yield* CodeOutputLimitError.make({\n implementation: dynamicWorkerImplementation,\n surface: \"logs\",\n limit: request.limits.maxLogBytes,\n observed: outcome.value.observed,\n logs: outcome.value.logs,\n });\n }\n case \"argument-limit\": {\n return yield* CodeOutputLimitError.make({\n implementation: dynamicWorkerImplementation,\n surface: \"host-call-argument\",\n limit: request.limits.maxHostCallArgumentBytes,\n observed: outcome.value.observed,\n logs: outcome.value.logs,\n });\n }\n case \"result-limit\": {\n return yield* CodeOutputLimitError.make({\n implementation: dynamicWorkerImplementation,\n surface: \"result\",\n limit: request.limits.maxResultBytes,\n observed: outcome.value.observed,\n logs: outcome.value.logs,\n });\n }\n case \"host-call-limit\": {\n return yield* CodeHostCallLimitError.make({\n implementation: dynamicWorkerImplementation,\n limit: request.limits.maxHostCalls,\n logs: outcome.value.logs,\n });\n }\n case \"protocol\": {\n return yield* CodeExecutionProtocolError.make({\n implementation: dynamicWorkerImplementation,\n message: outcome.value.message.slice(0, 8_000),\n });\n }\n }\n });\n\n/**\n * Expected worker-level failures map into the typed union with bounded\n * diagnostics; anything unrecognized stays a start/termination error rather\n * than a fabricated program result.\n */\nconst classifyWorkerFailure = (\n cause: unknown,\n maxWallTime: Duration.Duration,\n):\n | CodeExecutionTimeoutError\n | CodeExecutorTerminatedError\n | CodeExecutorStartError\n | CodeSourceError => {\n const text = safeCauseDiagnostic(cause, \"[unserializable worker failure]\");\n\n // `WorkerLoader.load()` is lazy, so a module-compile error in the generated\n // program surfaces here at first use. Blame the program's source ONLY on a\n // genuine compile diagnostic (a `SyntaxError` or an explicit compile\n // failure) — the fixed harness is valid, so the fault is in program.js. A\n // bare \"failed to start Worker\" without a compile diagnostic is an\n // infrastructure start failure, not the model's fault, so it must NOT be\n // misclassified as a source error.\n if (/syntaxerror|failed to (compile|parse)/i.test(text)) {\n return CodeSourceError.make({\n implementation: dynamicWorkerImplementation,\n reason: \"invalid\",\n message: text.slice(0, 8_000),\n });\n }\n if (/cpu/i.test(text)) {\n return CodeExecutionTimeoutError.make({\n implementation: dynamicWorkerImplementation,\n kind: \"cpu\",\n maxWallTime,\n logs: [],\n });\n }\n if (/failed to start worker/i.test(text)) {\n return CodeExecutorStartError.make({\n implementation: dynamicWorkerImplementation,\n message: text.slice(0, 8_000),\n cause,\n });\n }\n\n return CodeExecutorTerminatedError.make({\n implementation: dynamicWorkerImplementation,\n message: text.slice(0, 8_000),\n });\n};\n\n/** Layer building the Dynamic Worker `CodeExecutor` from resolved bindings. */\nexport const dynamicWorkerCodeExecutorLayer = (\n options: DynamicWorkerCodeExecutorOptions,\n): Layer.Layer<CodeExecutor> =>\n Layer.effect(\n CodeExecutor,\n Effect.gen(function* () {\n const clock = yield* Clock.Clock;\n\n return CodeExecutor.of({ execute: makeExecute(options, clock) });\n }),\n );\n\n/** Assemble Code Mode handlers with the isolated Dynamic Worker executor. */\nexport const CloudflareCodeMode = {\n /**\n * Provide the selected tool handlers at construction, where Code Mode captures them.\n * Their errors and remaining dependencies stay visible. The definition still owns the\n * allowlist and limits; the runtime supplies the live Tool broker for each scoped pass.\n */\n layer: <A, E, R, Handlers, HandlerError, HandlerRequirements>(\n definition: { readonly handlers: Layer.Layer<A, E, R> },\n options: DynamicWorkerCodeExecutorOptions & {\n readonly handlers: Layer.Layer<Handlers, HandlerError, HandlerRequirements>;\n },\n ) =>\n definition.handlers.pipe(\n Layer.provide(options.handlers),\n Layer.provide(dynamicWorkerCodeExecutorLayer(options)),\n ),\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,8BAA8B,sBAAsB,KAAK;CACpE,WAAW;CACX,UAAU;AACZ,CAAC;;;;;;;;AAiBD,IAAM,yBAAN,cAAqC,UAAsC;CACzE;CAEA,YAAY,UAAmD;EAC7D,MAAM;EACN,KAAKA,YAAY;CACnB;CAEA,KAAK,UAAqC;EACxC,OAAO,KAAKA,UAAU,QAAQ;CAChC;AACF;;;;;;;;AASA,MAAM,iBAAiB,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgJjC,MAAM,cAAc,OAAO,MAAM,OAAO,OAAO,MAAM,OAAO,YAAY,KAAS,CAAC,CAAC,CAAC,CAAC,MACnF,OAAO,YAAY,IAAK,CAC1B;AAEA,MAAM,mBAAmB,OAAO,aAAa,aAAa;CACxD,OAAO,OAAO;CACd,MAAM;CACN,WAAW,OAAO;CAClB,UAAU,OAAO;CACjB,aAAa,OAAO;AACtB,CAAC;AAED,MAAM,sBAAsB,OAAO,aAAa,yBAAyB,EACvE,QAAQ,OAAO,OACjB,CAAC;AAED,MAAM,uBAAuB,OAAO,aAAa,kBAAkB;CACjE,QAAQ,OAAO,SAAS;EAAC;EAAS;EAAY;CAAiB,CAAC;CAChE,QAAQ,OAAO;CACf,SAAS,OAAO;CAChB,MAAM;AACR,CAAC;AAED,MAAM,kBAAkB,OAAO,aAAa,aAAa;CACvD,UAAU,OAAO;CACjB,MAAM;AACR,CAAC;AAED,MAAM,uBAAuB,OAAO,aAAa,kBAAkB;CACjE,UAAU,OAAO;CACjB,MA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AAE,SAAS,YAAY,SAAS,KAAK,EAAE,CAAC;AACjE,CAAC,CACH;;AAGF,MAAa,qBAAqB;;;;;;AAMhC,QACE,YACA,YAIA,WAAW,SAAS,KAClB,MAAM,QAAQ,QAAQ,QAAQ,GAC9B,MAAM,QAAQ,+BAA+B,OAAO,CAAC,CACvD,EACJ"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Context, Schema } from "effect";
|
|
2
|
+
declare namespace CloudflareConfig_d_exports {
|
|
3
|
+
export { AdmissionLimitExceeded, CLOUDFLARE_DATABASE_CAP_BYTES, CLOUDFLARE_RUNTIME_DEFAULTS, CloudflareAdmissionLimitsValue, CloudflareDurableRuntimeConfig, CloudflareDurableRuntimeConfigValue, CloudflarePlatformConfigError, DEFAULT_MAX_DATABASE_BYTES };
|
|
4
|
+
}
|
|
5
|
+
declare const CloudflarePlatformConfigError_base: Schema.Class<CloudflarePlatformConfigError, Schema.TaggedStruct<"CloudflarePlatformConfigError", {
|
|
6
|
+
readonly message: Schema.String;
|
|
7
|
+
readonly cause: Schema.optionalKey<Schema.Defect>;
|
|
8
|
+
}>, import("effect/Cause").YieldableError>;
|
|
9
|
+
/** The supplied Cloudflare durable runtime configuration failed validation (DEPLOY-003). */
|
|
10
|
+
declare class CloudflarePlatformConfigError extends CloudflarePlatformConfigError_base {}
|
|
11
|
+
declare const AdmissionLimitExceeded_base: Schema.Class<AdmissionLimitExceeded, Schema.TaggedStruct<"AdmissionLimitExceeded", {
|
|
12
|
+
readonly limit: Schema.Literals<readonly ["queue-depth", "input-bytes", "database-bytes"]>;
|
|
13
|
+
readonly actual: Schema.Int;
|
|
14
|
+
readonly maximum: Schema.Int;
|
|
15
|
+
}>, import("effect/Cause").YieldableError>;
|
|
16
|
+
/**
|
|
17
|
+
* An admission was refused by a host resource limit BEFORE any ledger row existed
|
|
18
|
+
* (deployment spec §8, DEPLOY-007: "Admission has explicit bounded quota and overload
|
|
19
|
+
* behavior... a typed rejection"). This is the DC analogue of `NodeDurableHost`'s
|
|
20
|
+
* `AdmissionClosed` host gate: the port surface stays untouched, the refusal happens in the
|
|
21
|
+
* Thread Object's submit entry point before `DurableAgentRuntime.submit` runs, and
|
|
22
|
+
* nothing was admitted or written.
|
|
23
|
+
*/
|
|
24
|
+
declare class AdmissionLimitExceeded extends AdmissionLimitExceeded_base {
|
|
25
|
+
get message(): string;
|
|
26
|
+
}
|
|
27
|
+
/** The platform's hard per-Object database cap (10 GB, developers.cloudflare.com limits). */
|
|
28
|
+
declare const CLOUDFLARE_DATABASE_CAP_BYTES = 10000000000;
|
|
29
|
+
/** Default database-size admission ceiling: a 1 GB safety margin under the platform cap. */
|
|
30
|
+
declare const DEFAULT_MAX_DATABASE_BYTES = 9000000000;
|
|
31
|
+
declare const CloudflareAdmissionLimitsValue_base: Schema.Class<CloudflareAdmissionLimitsValue, Schema.Struct<{
|
|
32
|
+
/** Maximum nonterminal Submissions per Thread lane before new admissions refuse. */
|
|
33
|
+
readonly maxQueueDepthPerLane: Schema.Int;
|
|
34
|
+
/** Maximum encoded input bytes; never above the storage per-value bound. */
|
|
35
|
+
readonly maxInputBytes: Schema.Int;
|
|
36
|
+
/** Maximum `ctx.storage.sql.databaseSize` at admission; stays under the 10 GB platform cap. */
|
|
37
|
+
readonly maxDatabaseBytes: Schema.Int;
|
|
38
|
+
}>, {}>;
|
|
39
|
+
/**
|
|
40
|
+
* Explicit bounded admission quotas checked by the Thread Object BEFORE admission
|
|
41
|
+
* (exit gate "resource limits are checked before admission").
|
|
42
|
+
*/
|
|
43
|
+
declare class CloudflareAdmissionLimitsValue extends CloudflareAdmissionLimitsValue_base {}
|
|
44
|
+
declare const CloudflareDurableRuntimeConfigValue_base: Schema.Class<CloudflareDurableRuntimeConfigValue, Schema.Struct<{
|
|
45
|
+
readonly deploymentId: Schema.brand<Schema.NonEmptyString, "@effect-agent/thread/DeploymentId">;
|
|
46
|
+
/** Head of the minted producer identity `{producerPrefix}:{threadId}`. */
|
|
47
|
+
readonly producerPrefix: Schema.NonEmptyString;
|
|
48
|
+
/** Submission ownership lease duration (D5); fences work across Object incarnations. */
|
|
49
|
+
readonly ownershipLeaseDuration: Schema.Int;
|
|
50
|
+
/** Base delay of the alarm re-arm backoff when a pass makes no progress. */
|
|
51
|
+
readonly alarmBackoffBase: Schema.Int;
|
|
52
|
+
/** Ceiling of the alarm re-arm backoff. */
|
|
53
|
+
readonly alarmBackoffCap: Schema.Int;
|
|
54
|
+
/**
|
|
55
|
+
* The maintenance-pass scan cadence and the ceiling of every re-arm delay: nonterminal
|
|
56
|
+
* work is revisited at least this often (wake/scan pairing, persistence §14).
|
|
57
|
+
*/
|
|
58
|
+
readonly wakeScanInterval: Schema.Int;
|
|
59
|
+
/** `awaitSettlement` ledger re-check cadence when no wake arrives. */
|
|
60
|
+
readonly settlementPollInterval: Schema.Int;
|
|
61
|
+
/** Worker ownership-lease renewal cadence during an active Attempt. */
|
|
62
|
+
readonly leaseRenewalInterval: Schema.Int;
|
|
63
|
+
/** Active-Run abort-intent poll cadence. */
|
|
64
|
+
readonly abortPollInterval: Schema.Int;
|
|
65
|
+
/** Canonical observation poll cadence of the Durable Object store. */
|
|
66
|
+
readonly observationPollInterval: Schema.Int;
|
|
67
|
+
/** Per-value byte bound; must stay under the platform's 2 MB SQLite value limit. */
|
|
68
|
+
readonly maxStoredValueBytes: Schema.Int;
|
|
69
|
+
/** Opt-in full payload/digest-chain audit while opening the store. */
|
|
70
|
+
readonly verifyOnOpen: Schema.Boolean;
|
|
71
|
+
readonly limits: typeof CloudflareAdmissionLimitsValue;
|
|
72
|
+
}>, {}>;
|
|
73
|
+
/**
|
|
74
|
+
* Validated Cloudflare durable runtime configuration. The producer identity of one
|
|
75
|
+
* Thread Object is `{producerPrefix}:{threadId}` — stable across incarnations of
|
|
76
|
+
* the same deployment, distinct across deployments — and producer-epoch fencing (not the
|
|
77
|
+
* producer name) remains the correctness authority (DUR-006).
|
|
78
|
+
*/
|
|
79
|
+
declare class CloudflareDurableRuntimeConfigValue extends CloudflareDurableRuntimeConfigValue_base {}
|
|
80
|
+
declare const CloudflareDurableRuntimeConfig_base: Context.ServiceClass<CloudflareDurableRuntimeConfig, "@effect-agent/platform-cloudflare/CloudflareDurableRuntimeConfig", CloudflareDurableRuntimeConfigValue>;
|
|
81
|
+
/** Explicit configuration authority for the assembled Cloudflare durable runtime. */
|
|
82
|
+
declare class CloudflareDurableRuntimeConfig extends CloudflareDurableRuntimeConfig_base {}
|
|
83
|
+
/** Documented production defaults applied by `ThreadObject.layer`. */
|
|
84
|
+
declare const CLOUDFLARE_RUNTIME_DEFAULTS: {
|
|
85
|
+
readonly ownershipLeaseDuration: number;
|
|
86
|
+
readonly alarmBackoffBase: 100;
|
|
87
|
+
readonly alarmBackoffCap: 5000;
|
|
88
|
+
readonly wakeScanInterval: 1000;
|
|
89
|
+
readonly settlementPollInterval: 500;
|
|
90
|
+
readonly leaseRenewalInterval: 10000;
|
|
91
|
+
readonly abortPollInterval: 500;
|
|
92
|
+
readonly observationPollInterval: 25;
|
|
93
|
+
readonly maxStoredValueBytes: 1900000;
|
|
94
|
+
readonly verifyOnOpen: false;
|
|
95
|
+
readonly maxQueueDepthPerLane: 256;
|
|
96
|
+
readonly maxInputBytes: 1900000;
|
|
97
|
+
readonly maxDatabaseBytes: 9000000000;
|
|
98
|
+
};
|
|
99
|
+
//#endregion
|
|
100
|
+
export { CloudflareConfig_d_exports as a, CloudflarePlatformConfigError as c, CloudflareAdmissionLimitsValue as i, DEFAULT_MAX_DATABASE_BYTES as l, CLOUDFLARE_DATABASE_CAP_BYTES as n, CloudflareDurableRuntimeConfig as o, CLOUDFLARE_RUNTIME_DEFAULTS as r, CloudflareDurableRuntimeConfigValue as s, AdmissionLimitExceeded as t };
|
|
101
|
+
//# sourceMappingURL=CloudflareConfig-f3CqTel1.d.mts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { c as CloudflarePlatformConfigError, i as CloudflareAdmissionLimitsValue, l as DEFAULT_MAX_DATABASE_BYTES, n as CLOUDFLARE_DATABASE_CAP_BYTES, o as CloudflareDurableRuntimeConfig, r as CLOUDFLARE_RUNTIME_DEFAULTS, s as CloudflareDurableRuntimeConfigValue, t as AdmissionLimitExceeded } from "./CloudflareConfig-f3CqTel1.mjs";
|
|
2
|
+
export { AdmissionLimitExceeded, CLOUDFLARE_DATABASE_CAP_BYTES, CLOUDFLARE_RUNTIME_DEFAULTS, CloudflareAdmissionLimitsValue, CloudflareDurableRuntimeConfig, CloudflareDurableRuntimeConfigValue, CloudflarePlatformConfigError, DEFAULT_MAX_DATABASE_BYTES };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { DEFAULT_OWNERSHIP_LEASE_DURATION } from "@effect-agent/thread/SubmissionLedger";
|
|
3
|
+
import { Context, Duration, Schema } from "effect";
|
|
4
|
+
import { DeploymentId } from "@effect-agent/thread/Records";
|
|
5
|
+
import { DEFAULT_MAX_STORED_VALUE_BYTES } from "@effect-agent/storage-cloudflare/DoStorageConfig";
|
|
6
|
+
//#region src/CloudflareConfig.ts
|
|
7
|
+
var CloudflareConfig_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
AdmissionLimitExceeded: () => AdmissionLimitExceeded,
|
|
9
|
+
CLOUDFLARE_DATABASE_CAP_BYTES: () => CLOUDFLARE_DATABASE_CAP_BYTES,
|
|
10
|
+
CLOUDFLARE_RUNTIME_DEFAULTS: () => CLOUDFLARE_RUNTIME_DEFAULTS,
|
|
11
|
+
CloudflareAdmissionLimitsValue: () => CloudflareAdmissionLimitsValue,
|
|
12
|
+
CloudflareDurableRuntimeConfig: () => CloudflareDurableRuntimeConfig,
|
|
13
|
+
CloudflareDurableRuntimeConfigValue: () => CloudflareDurableRuntimeConfigValue,
|
|
14
|
+
CloudflarePlatformConfigError: () => CloudflarePlatformConfigError,
|
|
15
|
+
DEFAULT_MAX_DATABASE_BYTES: () => DEFAULT_MAX_DATABASE_BYTES
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Schema-validated configuration for the Cloudflare durable runtime (deployment spec §4:
|
|
19
|
+
* decoded once during Layer construction, exposed as a typed service; DEPLOY-003). Every
|
|
20
|
+
* cadence is in milliseconds; every bound is finite and checked before any resource opens.
|
|
21
|
+
*/
|
|
22
|
+
const PositiveMillis = Schema.Int.check(Schema.isGreaterThan(0));
|
|
23
|
+
const NonNegativeMillis = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
|
|
24
|
+
/** The supplied Cloudflare durable runtime configuration failed validation (DEPLOY-003). */
|
|
25
|
+
var CloudflarePlatformConfigError = class extends Schema.TaggedError()("CloudflarePlatformConfigError", {
|
|
26
|
+
message: Schema.String,
|
|
27
|
+
cause: Schema.optionalKey(Schema.Defect())
|
|
28
|
+
}) {};
|
|
29
|
+
/**
|
|
30
|
+
* An admission was refused by a host resource limit BEFORE any ledger row existed
|
|
31
|
+
* (deployment spec §8, DEPLOY-007: "Admission has explicit bounded quota and overload
|
|
32
|
+
* behavior... a typed rejection"). This is the DC analogue of `NodeDurableHost`'s
|
|
33
|
+
* `AdmissionClosed` host gate: the port surface stays untouched, the refusal happens in the
|
|
34
|
+
* Thread Object's submit entry point before `DurableAgentRuntime.submit` runs, and
|
|
35
|
+
* nothing was admitted or written.
|
|
36
|
+
*/
|
|
37
|
+
var AdmissionLimitExceeded = class extends Schema.TaggedError()("AdmissionLimitExceeded", {
|
|
38
|
+
limit: Schema.Literals([
|
|
39
|
+
"queue-depth",
|
|
40
|
+
"input-bytes",
|
|
41
|
+
"database-bytes"
|
|
42
|
+
]),
|
|
43
|
+
actual: Schema.Int,
|
|
44
|
+
maximum: Schema.Int
|
|
45
|
+
}) {
|
|
46
|
+
get message() {
|
|
47
|
+
return `Admission refused before any ledger row existed: ${this.limit} ${this.actual} exceeds the configured maximum ${this.maximum}. Accepted work is unaffected; retry after the lane drains or raise the limit (DEPLOY-007).`;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
/** The platform's hard per-Object database cap (10 GB, developers.cloudflare.com limits). */
|
|
51
|
+
const CLOUDFLARE_DATABASE_CAP_BYTES = 1e10;
|
|
52
|
+
/** Default database-size admission ceiling: a 1 GB safety margin under the platform cap. */
|
|
53
|
+
const DEFAULT_MAX_DATABASE_BYTES = 9e9;
|
|
54
|
+
/**
|
|
55
|
+
* Explicit bounded admission quotas checked by the Thread Object BEFORE admission
|
|
56
|
+
* (exit gate "resource limits are checked before admission").
|
|
57
|
+
*/
|
|
58
|
+
var CloudflareAdmissionLimitsValue = class extends Schema.Class("@effect-agent/platform-cloudflare/CloudflareAdmissionLimitsValue")({
|
|
59
|
+
/** Maximum nonterminal Submissions per Thread lane before new admissions refuse. */
|
|
60
|
+
maxQueueDepthPerLane: Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(1e5)),
|
|
61
|
+
/** Maximum encoded input bytes; never above the storage per-value bound. */
|
|
62
|
+
maxInputBytes: Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(2e6)),
|
|
63
|
+
/** Maximum `ctx.storage.sql.databaseSize` at admission; stays under the 10 GB platform cap. */
|
|
64
|
+
maxDatabaseBytes: Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(CLOUDFLARE_DATABASE_CAP_BYTES))
|
|
65
|
+
}) {};
|
|
66
|
+
/**
|
|
67
|
+
* Validated Cloudflare durable runtime configuration. The producer identity of one
|
|
68
|
+
* Thread Object is `{producerPrefix}:{threadId}` — stable across incarnations of
|
|
69
|
+
* the same deployment, distinct across deployments — and producer-epoch fencing (not the
|
|
70
|
+
* producer name) remains the correctness authority (DUR-006).
|
|
71
|
+
*/
|
|
72
|
+
var CloudflareDurableRuntimeConfigValue = class extends Schema.Class("@effect-agent/platform-cloudflare/CloudflareDurableRuntimeConfigValue")({
|
|
73
|
+
deploymentId: DeploymentId,
|
|
74
|
+
/** Head of the minted producer identity `{producerPrefix}:{threadId}`. */
|
|
75
|
+
producerPrefix: Schema.NonEmptyString.check(Schema.isMaxLength(256)),
|
|
76
|
+
/** Submission ownership lease duration (D5); fences work across Object incarnations. */
|
|
77
|
+
ownershipLeaseDuration: PositiveMillis,
|
|
78
|
+
/** Base delay of the alarm re-arm backoff when a pass makes no progress. */
|
|
79
|
+
alarmBackoffBase: PositiveMillis,
|
|
80
|
+
/** Ceiling of the alarm re-arm backoff. */
|
|
81
|
+
alarmBackoffCap: PositiveMillis,
|
|
82
|
+
/**
|
|
83
|
+
* The maintenance-pass scan cadence and the ceiling of every re-arm delay: nonterminal
|
|
84
|
+
* work is revisited at least this often (wake/scan pairing, persistence §14).
|
|
85
|
+
*/
|
|
86
|
+
wakeScanInterval: PositiveMillis,
|
|
87
|
+
/** `awaitSettlement` ledger re-check cadence when no wake arrives. */
|
|
88
|
+
settlementPollInterval: PositiveMillis,
|
|
89
|
+
/** Worker ownership-lease renewal cadence during an active Attempt. */
|
|
90
|
+
leaseRenewalInterval: PositiveMillis,
|
|
91
|
+
/** Active-Run abort-intent poll cadence. */
|
|
92
|
+
abortPollInterval: PositiveMillis,
|
|
93
|
+
/** Canonical observation poll cadence of the Durable Object store. */
|
|
94
|
+
observationPollInterval: NonNegativeMillis,
|
|
95
|
+
/** Per-value byte bound; must stay under the platform's 2 MB SQLite value limit. */
|
|
96
|
+
maxStoredValueBytes: Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(2e6)),
|
|
97
|
+
/** Opt-in full payload/digest-chain audit while opening the store. */
|
|
98
|
+
verifyOnOpen: Schema.Boolean,
|
|
99
|
+
limits: CloudflareAdmissionLimitsValue
|
|
100
|
+
}) {};
|
|
101
|
+
/** Explicit configuration authority for the assembled Cloudflare durable runtime. */
|
|
102
|
+
var CloudflareDurableRuntimeConfig = class extends Context.Service()("@effect-agent/platform-cloudflare/CloudflareDurableRuntimeConfig") {};
|
|
103
|
+
/** Documented production defaults applied by `ThreadObject.layer`. */
|
|
104
|
+
const CLOUDFLARE_RUNTIME_DEFAULTS = {
|
|
105
|
+
ownershipLeaseDuration: Duration.toMillis(DEFAULT_OWNERSHIP_LEASE_DURATION),
|
|
106
|
+
alarmBackoffBase: 100,
|
|
107
|
+
alarmBackoffCap: 5e3,
|
|
108
|
+
wakeScanInterval: 1e3,
|
|
109
|
+
settlementPollInterval: 500,
|
|
110
|
+
leaseRenewalInterval: 1e4,
|
|
111
|
+
abortPollInterval: 500,
|
|
112
|
+
observationPollInterval: 25,
|
|
113
|
+
maxStoredValueBytes: DEFAULT_MAX_STORED_VALUE_BYTES,
|
|
114
|
+
verifyOnOpen: false,
|
|
115
|
+
maxQueueDepthPerLane: 256,
|
|
116
|
+
maxInputBytes: DEFAULT_MAX_STORED_VALUE_BYTES,
|
|
117
|
+
maxDatabaseBytes: DEFAULT_MAX_DATABASE_BYTES
|
|
118
|
+
};
|
|
119
|
+
//#endregion
|
|
120
|
+
export { AdmissionLimitExceeded, CLOUDFLARE_DATABASE_CAP_BYTES, CLOUDFLARE_RUNTIME_DEFAULTS, CloudflareAdmissionLimitsValue, CloudflareDurableRuntimeConfig, CloudflareDurableRuntimeConfigValue, CloudflarePlatformConfigError, DEFAULT_MAX_DATABASE_BYTES, CloudflareConfig_exports as t };
|
|
121
|
+
|
|
122
|
+
//# sourceMappingURL=CloudflareConfig.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudflareConfig.mjs","names":[],"sources":["../src/CloudflareConfig.ts"],"sourcesContent":["import { DEFAULT_MAX_STORED_VALUE_BYTES } from \"@effect-agent/storage-cloudflare/DoStorageConfig\";\nimport { DeploymentId } from \"@effect-agent/thread/Records\";\nimport { DEFAULT_OWNERSHIP_LEASE_DURATION } from \"@effect-agent/thread/SubmissionLedger\";\nimport { Context, Duration, Schema } from \"effect\";\n\n/**\n * Schema-validated configuration for the Cloudflare durable runtime (deployment spec §4:\n * decoded once during Layer construction, exposed as a typed service; DEPLOY-003). Every\n * cadence is in milliseconds; every bound is finite and checked before any resource opens.\n */\n\nconst PositiveMillis = Schema.Int.check(Schema.isGreaterThan(0));\nconst NonNegativeMillis = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));\n\n/** The supplied Cloudflare durable runtime configuration failed validation (DEPLOY-003). */\nexport class CloudflarePlatformConfigError extends Schema.TaggedError<CloudflarePlatformConfigError>()(\n \"CloudflarePlatformConfigError\",\n {\n message: Schema.String,\n cause: Schema.optionalKey(Schema.Defect()),\n },\n) {}\n\n/**\n * An admission was refused by a host resource limit BEFORE any ledger row existed\n * (deployment spec §8, DEPLOY-007: \"Admission has explicit bounded quota and overload\n * behavior... a typed rejection\"). This is the DC analogue of `NodeDurableHost`'s\n * `AdmissionClosed` host gate: the port surface stays untouched, the refusal happens in the\n * Thread Object's submit entry point before `DurableAgentRuntime.submit` runs, and\n * nothing was admitted or written.\n */\nexport class AdmissionLimitExceeded extends Schema.TaggedError<AdmissionLimitExceeded>()(\n \"AdmissionLimitExceeded\",\n {\n limit: Schema.Literals([\"queue-depth\", \"input-bytes\", \"database-bytes\"]),\n actual: Schema.Int,\n maximum: Schema.Int,\n },\n) {\n override get message() {\n return (\n `Admission refused before any ledger row existed: ${this.limit} ${this.actual} exceeds ` +\n `the configured maximum ${this.maximum}. Accepted work is unaffected; retry after the ` +\n \"lane drains or raise the limit (DEPLOY-007).\"\n );\n }\n}\n\n/** The platform's hard per-Object database cap (10 GB, developers.cloudflare.com limits). */\nexport const CLOUDFLARE_DATABASE_CAP_BYTES = 10_000_000_000;\n\n/** Default database-size admission ceiling: a 1 GB safety margin under the platform cap. */\nexport const DEFAULT_MAX_DATABASE_BYTES = 9_000_000_000;\n\n/**\n * Explicit bounded admission quotas checked by the Thread Object BEFORE admission\n * (exit gate \"resource limits are checked before admission\").\n */\nexport class CloudflareAdmissionLimitsValue extends Schema.Class<CloudflareAdmissionLimitsValue>(\n \"@effect-agent/platform-cloudflare/CloudflareAdmissionLimitsValue\",\n)({\n /** Maximum nonterminal Submissions per Thread lane before new admissions refuse. */\n maxQueueDepthPerLane: Schema.Int.check(\n Schema.isGreaterThan(0),\n Schema.isLessThanOrEqualTo(100_000),\n ),\n /** Maximum encoded input bytes; never above the storage per-value bound. */\n maxInputBytes: Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(2_000_000)),\n /** Maximum `ctx.storage.sql.databaseSize` at admission; stays under the 10 GB platform cap. */\n maxDatabaseBytes: Schema.Int.check(\n Schema.isGreaterThan(0),\n Schema.isLessThanOrEqualTo(CLOUDFLARE_DATABASE_CAP_BYTES),\n ),\n}) {}\n\n/**\n * Validated Cloudflare durable runtime configuration. The producer identity of one\n * Thread Object is `{producerPrefix}:{threadId}` — stable across incarnations of\n * the same deployment, distinct across deployments — and producer-epoch fencing (not the\n * producer name) remains the correctness authority (DUR-006).\n */\nexport class CloudflareDurableRuntimeConfigValue extends Schema.Class<CloudflareDurableRuntimeConfigValue>(\n \"@effect-agent/platform-cloudflare/CloudflareDurableRuntimeConfigValue\",\n)({\n deploymentId: DeploymentId,\n /** Head of the minted producer identity `{producerPrefix}:{threadId}`. */\n producerPrefix: Schema.NonEmptyString.check(Schema.isMaxLength(256)),\n /** Submission ownership lease duration (D5); fences work across Object incarnations. */\n ownershipLeaseDuration: PositiveMillis,\n /** Base delay of the alarm re-arm backoff when a pass makes no progress. */\n alarmBackoffBase: PositiveMillis,\n /** Ceiling of the alarm re-arm backoff. */\n alarmBackoffCap: PositiveMillis,\n /**\n * The maintenance-pass scan cadence and the ceiling of every re-arm delay: nonterminal\n * work is revisited at least this often (wake/scan pairing, persistence §14).\n */\n wakeScanInterval: PositiveMillis,\n /** `awaitSettlement` ledger re-check cadence when no wake arrives. */\n settlementPollInterval: PositiveMillis,\n /** Worker ownership-lease renewal cadence during an active Attempt. */\n leaseRenewalInterval: PositiveMillis,\n /** Active-Run abort-intent poll cadence. */\n abortPollInterval: PositiveMillis,\n /** Canonical observation poll cadence of the Durable Object store. */\n observationPollInterval: NonNegativeMillis,\n /** Per-value byte bound; must stay under the platform's 2 MB SQLite value limit. */\n maxStoredValueBytes: Schema.Int.check(\n Schema.isGreaterThan(0),\n Schema.isLessThanOrEqualTo(2_000_000),\n ),\n /** Opt-in full payload/digest-chain audit while opening the store. */\n verifyOnOpen: Schema.Boolean,\n limits: CloudflareAdmissionLimitsValue,\n}) {}\n\n/** Explicit configuration authority for the assembled Cloudflare durable runtime. */\nexport class CloudflareDurableRuntimeConfig extends Context.Service<\n CloudflareDurableRuntimeConfig,\n CloudflareDurableRuntimeConfigValue\n>()(\"@effect-agent/platform-cloudflare/CloudflareDurableRuntimeConfig\") {}\n\n/** Documented production defaults applied by `ThreadObject.layer`. */\nexport const CLOUDFLARE_RUNTIME_DEFAULTS = {\n ownershipLeaseDuration: Duration.toMillis(DEFAULT_OWNERSHIP_LEASE_DURATION),\n alarmBackoffBase: 100,\n alarmBackoffCap: 5_000,\n wakeScanInterval: 1_000,\n settlementPollInterval: 500,\n leaseRenewalInterval: 10_000,\n abortPollInterval: 500,\n observationPollInterval: 25,\n maxStoredValueBytes: DEFAULT_MAX_STORED_VALUE_BYTES,\n verifyOnOpen: false,\n maxQueueDepthPerLane: 256,\n maxInputBytes: DEFAULT_MAX_STORED_VALUE_BYTES,\n maxDatabaseBytes: DEFAULT_MAX_DATABASE_BYTES,\n} as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAWA,MAAM,iBAAiB,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CAAC;AAC/D,MAAM,oBAAoB,OAAO,IAAI,MAAM,OAAO,uBAAuB,CAAC,CAAC;;AAG3E,IAAa,gCAAb,cAAmD,OAAO,YAA2C,CAAC,CACpG,iCACA;CACE,SAAS,OAAO;CAChB,OAAO,OAAO,YAAY,OAAO,OAAO,CAAC;AAC3C,CACF,CAAC,CAAC,CAAC;;;;;;;;;AAUH,IAAa,yBAAb,cAA4C,OAAO,YAAoC,CAAC,CACtF,0BACA;CACE,OAAO,OAAO,SA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nB,yBAAyB;CACzB,qBAAqB;CACrB,cAAc;CACd,sBAAsB;CACtB,eAAe;CACf,kBAAkB;AACpB"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { Principal } from "@effect-agent/thread/SubmissionLedger";
|
|
2
|
+
import { Context, Effect, Layer } from "effect";
|
|
3
|
+
import * as Memory from "@effect-agent/core/Memory";
|
|
4
|
+
import * as MemoryNamespace from "@effect-agent/core/MemoryNamespace";
|
|
5
|
+
import { MemoryRecallLimits } from "@effect-agent/core/MemoryReference";
|
|
6
|
+
import { MemoryAccess } from "@effect-agent/core/MemoryRevalidation";
|
|
7
|
+
import { MemoryDocument, MemoryKey, MemoryMutationFailpoint, MemoryReader, MemoryStorageError, MemoryWrite, MemoryWriter } from "@effect-agent/core/MemoryStore";
|
|
8
|
+
import { MemoryIndexSearch, SemanticMemoryProfile } from "@effect-agent/core/SemanticMemoryIndex";
|
|
9
|
+
import { SemanticCandidateLimits } from "@effect-agent/core/SemanticMemoryRevalidation";
|
|
10
|
+
import { DoMemoryStorageLimits } from "@effect-agent/storage-cloudflare/DoMemoryStore";
|
|
11
|
+
import { MemoryOwnerAuthorizer, MemoryOwnerIdentity, MemoryRpcError, MemoryRpcLimits } from "@effect-agent/storage-cloudflare/MemoryProtocol";
|
|
12
|
+
import { DurableObject, DurableObjectState, WorkerEnvironment } from "effect-cf";
|
|
13
|
+
declare namespace CloudflareMemory_d_exports {
|
|
14
|
+
export { CloudflareMemoryClient, MemoryObject, MemoryObjectClass, MemoryObjectInstance, MemoryObjectNamespace, MemoryObjectRpc, cloudflareMemoryWriterLayer, memoryObjectName };
|
|
15
|
+
}
|
|
16
|
+
interface MemoryObjectRpc extends Rpc.DurableObjectBranded {
|
|
17
|
+
memory(encoded: string): Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
declare const MemoryObjectNamespace_base: Context.ServiceClass<MemoryObjectNamespace, "@effect-agent/platform-cloudflare/MemoryObjectNamespace", {
|
|
20
|
+
readonly namespace: DurableObjectNamespace<MemoryObjectRpc>;
|
|
21
|
+
}>;
|
|
22
|
+
declare class MemoryObjectNamespace extends MemoryObjectNamespace_base {}
|
|
23
|
+
/** Namespace version and identity are already canonicalized by MemoryNamespace. */
|
|
24
|
+
declare const memoryObjectName: (namespace: MemoryNamespace.Any) => string;
|
|
25
|
+
declare const CloudflareMemoryClient: {
|
|
26
|
+
/** Bind access and principal using the MemoryObjectNamespace supplied by the application. */
|
|
27
|
+
make: <Namespace extends MemoryNamespace.Any>(access: MemoryAccess<Namespace>, principal: string & import("effect/Brand").Brand<"@effect-agent/thread/Principal">, rpcLimits?: MemoryRpcLimits | undefined) => Effect.Effect<{
|
|
28
|
+
get: (key: MemoryKey<Namespace>) => Effect.Effect<MemoryDocument<Namespace> | null, import("@effect-agent/core/MemoryStore").MemoryConflict | import("@effect-agent/core/SemanticMemoryIndex").MemoryIndexError | import("@effect-agent/core/MemoryStore").MemoryMutationFailure | import("@effect-agent/core/MemoryStore").MemoryOperationConflict | import("@effect-agent/core/MemoryReference").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core/MemoryStore").MemoryWithdrawn | import("@effect-agent/core/SemanticMemoryRevalidation").SemanticMemoryError, never>;
|
|
29
|
+
recall: (lookup: {
|
|
30
|
+
readonly _tag: "Found";
|
|
31
|
+
readonly passages: readonly import("@effect-agent/core/MemoryReference").MemoryPassage[];
|
|
32
|
+
} | {
|
|
33
|
+
readonly _tag: "NoMatch";
|
|
34
|
+
} | {
|
|
35
|
+
readonly _tag: "Unavailable";
|
|
36
|
+
readonly message: string;
|
|
37
|
+
} | {
|
|
38
|
+
readonly _tag: "InsufficientFreshness";
|
|
39
|
+
readonly message: string;
|
|
40
|
+
}, limits: MemoryRecallLimits, estimateTokens?: ((text: string) => number) | undefined) => Effect.Effect<Memory.RecalledMemory, import("@effect-agent/core/MemoryStore").MemoryConflict | import("@effect-agent/core/SemanticMemoryIndex").MemoryIndexError | import("@effect-agent/core/MemoryStore").MemoryMutationFailure | import("@effect-agent/core/MemoryStore").MemoryOperationConflict | import("@effect-agent/core/MemoryReference").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core/MemoryStore").MemoryWithdrawn | import("@effect-agent/core/SemanticMemoryRevalidation").SemanticMemoryError, never>;
|
|
41
|
+
revalidate: (lookup: {
|
|
42
|
+
readonly _tag: "Found";
|
|
43
|
+
readonly passages: readonly import("@effect-agent/core/MemoryReference").MemoryPassage[];
|
|
44
|
+
} | {
|
|
45
|
+
readonly _tag: "NoMatch";
|
|
46
|
+
} | {
|
|
47
|
+
readonly _tag: "Unavailable";
|
|
48
|
+
readonly message: string;
|
|
49
|
+
} | {
|
|
50
|
+
readonly _tag: "InsufficientFreshness";
|
|
51
|
+
readonly message: string;
|
|
52
|
+
}, limits: MemoryRecallLimits) => Effect.Effect<{
|
|
53
|
+
readonly _tag: "Found";
|
|
54
|
+
readonly passages: readonly import("@effect-agent/core/MemoryReference").MemoryPassage[];
|
|
55
|
+
} | {
|
|
56
|
+
readonly _tag: "NoMatch";
|
|
57
|
+
} | {
|
|
58
|
+
readonly _tag: "Unavailable";
|
|
59
|
+
readonly message: string;
|
|
60
|
+
} | {
|
|
61
|
+
readonly _tag: "InsufficientFreshness";
|
|
62
|
+
readonly message: string;
|
|
63
|
+
}, import("@effect-agent/core/MemoryStore").MemoryConflict | import("@effect-agent/core/SemanticMemoryIndex").MemoryIndexError | import("@effect-agent/core/MemoryStore").MemoryMutationFailure | import("@effect-agent/core/MemoryStore").MemoryOperationConflict | import("@effect-agent/core/MemoryReference").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core/MemoryStore").MemoryWithdrawn | import("@effect-agent/core/SemanticMemoryRevalidation").SemanticMemoryError, never>;
|
|
64
|
+
revalidateSemantic: (found: MemoryIndexSearch<Namespace>, profile: SemanticMemoryProfile, limits: SemanticCandidateLimits) => Effect.Effect<import("@effect-agent/core/SemanticMemoryRevalidation").SemanticCandidateResult, import("@effect-agent/core/MemoryStore").MemoryConflict | import("@effect-agent/core/SemanticMemoryIndex").MemoryIndexError | import("@effect-agent/core/MemoryStore").MemoryMutationFailure | import("@effect-agent/core/MemoryStore").MemoryOperationConflict | import("@effect-agent/core/MemoryReference").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core/MemoryStore").MemoryWithdrawn | import("@effect-agent/core/SemanticMemoryRevalidation").SemanticMemoryError, never>;
|
|
65
|
+
change: (write: MemoryWrite<Namespace>) => Effect.Effect<MemoryDocument<Namespace>, import("@effect-agent/core/MemoryStore").MemoryConflict | import("@effect-agent/core/SemanticMemoryIndex").MemoryIndexError | import("@effect-agent/core/MemoryStore").MemoryMutationFailure | import("@effect-agent/core/MemoryStore").MemoryOperationConflict | import("@effect-agent/core/MemoryReference").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core/MemoryStore").MemoryWithdrawn | import("@effect-agent/core/SemanticMemoryRevalidation").SemanticMemoryError, never>;
|
|
66
|
+
}, MemoryRpcError, MemoryObjectNamespace>;
|
|
67
|
+
/** Use a resolved Worker or Durable Object binding without manual service provisioning. */
|
|
68
|
+
fromBinding: <Namespace extends MemoryNamespace.Any>(binding: DurableObjectNamespace<MemoryObjectRpc>, options: {
|
|
69
|
+
readonly access: MemoryAccess<Namespace>;
|
|
70
|
+
readonly principal: Principal;
|
|
71
|
+
readonly rpcLimits?: MemoryRpcLimits;
|
|
72
|
+
}) => Effect.Effect<{
|
|
73
|
+
get: (key: MemoryKey<Namespace>) => Effect.Effect<MemoryDocument<Namespace> | null, import("@effect-agent/core/MemoryStore").MemoryConflict | import("@effect-agent/core/SemanticMemoryIndex").MemoryIndexError | import("@effect-agent/core/MemoryStore").MemoryMutationFailure | import("@effect-agent/core/MemoryStore").MemoryOperationConflict | import("@effect-agent/core/MemoryReference").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core/MemoryStore").MemoryWithdrawn | import("@effect-agent/core/SemanticMemoryRevalidation").SemanticMemoryError, never>;
|
|
74
|
+
recall: (lookup: {
|
|
75
|
+
readonly _tag: "Found";
|
|
76
|
+
readonly passages: readonly import("@effect-agent/core/MemoryReference").MemoryPassage[];
|
|
77
|
+
} | {
|
|
78
|
+
readonly _tag: "NoMatch";
|
|
79
|
+
} | {
|
|
80
|
+
readonly _tag: "Unavailable";
|
|
81
|
+
readonly message: string;
|
|
82
|
+
} | {
|
|
83
|
+
readonly _tag: "InsufficientFreshness";
|
|
84
|
+
readonly message: string;
|
|
85
|
+
}, limits: MemoryRecallLimits, estimateTokens?: ((text: string) => number) | undefined) => Effect.Effect<Memory.RecalledMemory, import("@effect-agent/core/MemoryStore").MemoryConflict | import("@effect-agent/core/SemanticMemoryIndex").MemoryIndexError | import("@effect-agent/core/MemoryStore").MemoryMutationFailure | import("@effect-agent/core/MemoryStore").MemoryOperationConflict | import("@effect-agent/core/MemoryReference").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core/MemoryStore").MemoryWithdrawn | import("@effect-agent/core/SemanticMemoryRevalidation").SemanticMemoryError, never>;
|
|
86
|
+
revalidate: (lookup: {
|
|
87
|
+
readonly _tag: "Found";
|
|
88
|
+
readonly passages: readonly import("@effect-agent/core/MemoryReference").MemoryPassage[];
|
|
89
|
+
} | {
|
|
90
|
+
readonly _tag: "NoMatch";
|
|
91
|
+
} | {
|
|
92
|
+
readonly _tag: "Unavailable";
|
|
93
|
+
readonly message: string;
|
|
94
|
+
} | {
|
|
95
|
+
readonly _tag: "InsufficientFreshness";
|
|
96
|
+
readonly message: string;
|
|
97
|
+
}, limits: MemoryRecallLimits) => Effect.Effect<{
|
|
98
|
+
readonly _tag: "Found";
|
|
99
|
+
readonly passages: readonly import("@effect-agent/core/MemoryReference").MemoryPassage[];
|
|
100
|
+
} | {
|
|
101
|
+
readonly _tag: "NoMatch";
|
|
102
|
+
} | {
|
|
103
|
+
readonly _tag: "Unavailable";
|
|
104
|
+
readonly message: string;
|
|
105
|
+
} | {
|
|
106
|
+
readonly _tag: "InsufficientFreshness";
|
|
107
|
+
readonly message: string;
|
|
108
|
+
}, import("@effect-agent/core/MemoryStore").MemoryConflict | import("@effect-agent/core/SemanticMemoryIndex").MemoryIndexError | import("@effect-agent/core/MemoryStore").MemoryMutationFailure | import("@effect-agent/core/MemoryStore").MemoryOperationConflict | import("@effect-agent/core/MemoryReference").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core/MemoryStore").MemoryWithdrawn | import("@effect-agent/core/SemanticMemoryRevalidation").SemanticMemoryError, never>;
|
|
109
|
+
revalidateSemantic: (found: MemoryIndexSearch<Namespace>, profile: SemanticMemoryProfile, limits: SemanticCandidateLimits) => Effect.Effect<import("@effect-agent/core/SemanticMemoryRevalidation").SemanticCandidateResult, import("@effect-agent/core/MemoryStore").MemoryConflict | import("@effect-agent/core/SemanticMemoryIndex").MemoryIndexError | import("@effect-agent/core/MemoryStore").MemoryMutationFailure | import("@effect-agent/core/MemoryStore").MemoryOperationConflict | import("@effect-agent/core/MemoryReference").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core/MemoryStore").MemoryWithdrawn | import("@effect-agent/core/SemanticMemoryRevalidation").SemanticMemoryError, never>;
|
|
110
|
+
change: (write: MemoryWrite<Namespace>) => Effect.Effect<MemoryDocument<Namespace>, import("@effect-agent/core/MemoryStore").MemoryConflict | import("@effect-agent/core/SemanticMemoryIndex").MemoryIndexError | import("@effect-agent/core/MemoryStore").MemoryMutationFailure | import("@effect-agent/core/MemoryStore").MemoryOperationConflict | import("@effect-agent/core/MemoryReference").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core/MemoryStore").MemoryWithdrawn | import("@effect-agent/core/SemanticMemoryRevalidation").SemanticMemoryError, never>;
|
|
111
|
+
}, MemoryRpcError, never>;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Optional activity-processor destination. Keeps domain write errors intact; transport,
|
|
115
|
+
* authorization and deadline failures become the existing MemoryStorageError contract.
|
|
116
|
+
* Receipts remain authoritative, including after caller interruption or lost replies.
|
|
117
|
+
*/
|
|
118
|
+
declare const cloudflareMemoryWriterLayer: (access: MemoryAccess, principal: Principal, limits?: MemoryRpcLimits) => Layer.Layer<MemoryWriter, MemoryRpcError, MemoryObjectNamespace>;
|
|
119
|
+
type OwnerServices = MemoryReader | MemoryWriter | MemoryOwnerAuthorizer | MemoryOwnerIdentity;
|
|
120
|
+
interface MemoryObjectInstance extends InstanceType<DurableObject.DurableObjectClass<Record<never, never>, OwnerServices>> {
|
|
121
|
+
memory(encoded: string): Promise<string>;
|
|
122
|
+
}
|
|
123
|
+
interface MemoryObjectClass {
|
|
124
|
+
new (ctx: globalThis.DurableObjectState, env: Cloudflare.Env): MemoryObjectInstance;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Dedicated SQLite owner, independent of Thread lifetimes. The host binds authorization
|
|
128
|
+
* after restoring its namespace definition from MemoryOwnerIdentity. Do not retain
|
|
129
|
+
* cleanup-scoped resources in the host Layer; it lives for the DO incarnation.
|
|
130
|
+
*/
|
|
131
|
+
declare const makeMemoryObject: <E>(host: Layer.Layer<MemoryOwnerAuthorizer, E, MemoryOwnerIdentity | DurableObjectState.DurableObjectState | WorkerEnvironment>, options?: {
|
|
132
|
+
readonly storageLimits?: DoMemoryStorageLimits;
|
|
133
|
+
readonly rpcLimits?: MemoryRpcLimits;
|
|
134
|
+
readonly failpoints?: Layer.Layer<MemoryMutationFailpoint, never, DurableObjectState.DurableObjectState>;
|
|
135
|
+
}) => MemoryObjectClass;
|
|
136
|
+
declare const MemoryObject: {
|
|
137
|
+
/** Build the SQLite Durable Object class with the application's owner authorization Layer. */
|
|
138
|
+
make: typeof makeMemoryObject;
|
|
139
|
+
};
|
|
140
|
+
//#endregion
|
|
141
|
+
export { CloudflareMemoryClient, MemoryObject, MemoryObjectClass, MemoryObjectInstance, MemoryObjectNamespace, MemoryObjectRpc, cloudflareMemoryWriterLayer, memoryObjectName, CloudflareMemory_d_exports as t };
|
|
142
|
+
//# sourceMappingURL=CloudflareMemory.d.mts.map
|