@effect-agent/platform-cloudflare 0.1.0-beta.39 → 0.1.0-beta.41

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/index.d.mts CHANGED
@@ -1,10 +1,11 @@
1
- import { a as ThreadObjectRpc, i as ThreadObjectNamespace, n as DurableObjectContext, o as threadNamespaceFromEnv, r as ThreadObjectIdentity, s as threadNamespaceLayer, t as CloudflareBindingError } from "./bindings-C00ZfjsX.mjs";
1
+ import { CloudflareBrowser, CloudflareBrowserOptions } from "./browser-quick-action.mjs";
2
+ import { a as ThreadObjectRpc, i as ThreadObjectNamespace, n as DurableObjectContext, o as threadNamespaceFromEnv, r as ThreadObjectIdentity, s as threadNamespaceLayer, t as CloudflareBindingError } from "./bindings-BrVEOkfe.mjs";
2
3
  import { CloudflareSchedulingClient, ScheduleAlarmProtocolError, ScheduleOwnerIdentity, ScheduleOwnerNamespace, ScheduleOwnerObjectClass, ScheduleOwnerObjectInstance, ScheduleOwnerObjectRpc, ScheduleOwnerProtocolError, makeScheduleOwnerObjectClass } from "./scheduling.mjs";
3
4
  import { CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, SubscriptionAlarmProtocolError, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionObjectClass, SubscriptionPartitionObjectInstance, SubscriptionPartitionObjectRpc, SubscriptionPartitionProtocolError, makeSubscriptionPartitionObjectClass, sourcePartitionName, validateCloudflareSubscriptionLimits } from "./subscriptions.mjs";
4
5
  import { Context, Crypto, Effect, Layer, Option, Schema, Scope } from "effect";
5
- import { DoStorageFailpoint, DoStorageFailpointHandler, DoStorageInitializationError, PortRequest, PortResponse, ThreadPortTransport } from "@effect-agent/storage-cloudflare";
6
- import { AbortCommand, AbortIntent, AdmissionConflict, AgentRegistration, AppendConflict, ApprovalConflict, ApprovalDecisionCommand, ApprovalDecisionIntent, CanonicalRecordEnvelope, CanonicalSequence, DefinitionDigests, DigestError, DurableAgentRuntime, DurableBindingFailure, DurableRuntimeConfig, DurableRuntimeFailpoint, DurableRuntimeFailpointError, DurableRuntimeFailpointHandler, DurableSubmitAgent, DurableSubmitOptions, DurableWorkerFailure, FenceRejected, IntegrityReport, JoinedToHost, LedgerError, ObligationReport, ObligationThresholds, OperationAuthorizerService, OperationDenied, OwnershipLost, PreparedInputAdmission, Receipt, RecoveryExplanation, RecoveryReport, ResolvedBinding, RetryCommand, RetryRefused, RunJournalError, ScheduledInputAdmission, Settlement, SettlementConflict, SubmissionLedger, ThreadNotMaterialized, ThreadStore, ThreadStoreError, ToolReconciler, UnknownResolutionCommand, UnknownResolutionConflict, UnknownResolutionIntent, WakeScheduler } from "@effect-agent/thread";
7
- import { AgentInputError, ThreadId } from "@effect-agent/core";
6
+ import { DoMemoryStorageLimits, DoStorageFailpoint, DoStorageFailpointHandler, DoStorageInitializationError, MemoryOwnerAuthorizer, MemoryOwnerIdentity, MemoryRpcError, MemoryRpcLimits, PortRequest, PortResponse, ThreadPortTransport } from "@effect-agent/storage-cloudflare";
7
+ import { AbortCommand, AbortIntent, AdmissionConflict, AgentRegistration, AppendConflict, ApprovalConflict, ApprovalDecisionCommand, ApprovalDecisionIntent, CanonicalRecordEnvelope, CanonicalSequence, DefinitionDigests, DigestError, DurableAgentRuntime, DurableBindingFailure, DurableRuntimeConfig, DurableRuntimeFailpoint, DurableRuntimeFailpointError, DurableRuntimeFailpointHandler, DurableSubmitAgent, DurableSubmitOptions, DurableWorkerFailure, FenceRejected, IntegrityReport, JoinedToHost, LedgerError, ObligationReport, ObligationThresholds, OperationAuthorizerService, OperationDenied, OwnershipLost, PreparedInputAdmission, Principal, Receipt, RecoveryExplanation, RecoveryReport, ResolvedBinding, RetryCommand, RetryRefused, RunJournalError, ScheduledInputAdmission, Settlement, SettlementConflict, SubmissionLedger, ThreadNotMaterialized, ThreadStore, ThreadStoreError, ToolReconciler, UnknownResolutionCommand, UnknownResolutionConflict, UnknownResolutionIntent, WakeScheduler } from "@effect-agent/thread";
8
+ import { AgentInputError, MemoryAccess, MemoryDocument, MemoryIndexSearch, MemoryMutationFailpoint, MemoryNamespace, MemoryReader, MemoryRecallLimits, MemoryStorageError, MemoryWrite, MemoryWriter, SemanticCandidateLimits, SemanticMemoryProfile, ThreadId } from "@effect-agent/core";
8
9
  import { RunContextPreparation, RunCostEstimator, RunToolAuthorization, RunToolFailureObserver } from "@effect-agent/engine";
9
10
  import { DurableObject, DurableObjectState as DurableObjectState$1, WorkerEnvironment } from "effect-cf";
10
11
  import { CodeExecutor, SandboxImplementation } from "@effect-agent/sandbox";
@@ -348,7 +349,18 @@ declare const layerConfig: (options: CloudflareDurableRuntimeOptions) => Layer.L
348
349
  * Tool, Schema, and model requirements remain visible until satisfied by Layer composition.
349
350
  * Use Layer.unwrap for registration values that need effectful application setup.
350
351
  */
351
- declare const layer: <const Entries extends ReadonlyArray<AgentRegistration>>(registrations: Entries) => Layer.Layer<CloudflareDurableRuntimeServices, DigestError | DoStorageInitializationError, DurableObjectContext | ThreadObjectNamespace | Exclude<[Entries[number]] extends [never] ? never : Entries[number] extends (infer T) ? T extends Entries[number] ? T extends AgentRegistration<infer A extends import("@effect-agent/thread").ExecutableAgentBinding> ? import("@effect-agent/thread").DurableWorkerRequirements<A> : never : never : never, import("effect/Scope").Scope> | CloudflareBootstrapServices>;
352
+ declare const layer: <const Entries extends ReadonlyArray<AgentRegistration>>(registrations: Entries) => Layer.Layer<CloudflareDurableRuntimeServices, DigestError | DoStorageInitializationError, DurableObjectContext | ThreadObjectNamespace | Exclude<[Entries[number]] extends [never] ? never : Entries[number] extends (infer T) ? T extends Entries[number] ? T extends {
353
+ readonly agent: infer A extends import("@effect-agent/thread").ExecutableAgentBinding;
354
+ } ? import("@effect-agent/thread").DurableWorkerRequirements<A> : T extends {
355
+ readonly agent: infer D extends import("@effect-agent/core").Definition<Schema.Top, Schema.Top, unknown, import("effect/unstable/ai/Toolkit").Any, import("@effect-agent/core").RunDispositionDeclaration<never, Schema.Top> | undefined, unknown> & {
356
+ readonly instructions: import("@effect-agent/core").InstructionSource<never, unknown, unknown>;
357
+ readonly inputPrompt?: import("@effect-agent/core").InputPromptSource<never, unknown, unknown> | undefined;
358
+ };
359
+ readonly model: infer M extends import("@effect-agent/thread").ExecutableAgentBinding["model"];
360
+ } ? import("@effect-agent/thread").DurableWorkerRequirements<{
361
+ readonly definition: D;
362
+ readonly model: M;
363
+ }> : never : never : never, import("effect/Scope").Scope> | CloudflareBootstrapServices>;
352
364
  //#endregion
353
365
  //#region src/client.d.ts
354
366
  /** Truncate a diagnostic string to the host protocol's bounded length. */
@@ -792,6 +804,29 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
792
804
  readonly childPrincipal: string;
793
805
  readonly childIdempotencyKey: string;
794
806
  readonly toolCallAllowance?: number | undefined;
807
+ readonly policy?: Schema.Json | undefined;
808
+ readonly budget?: {
809
+ readonly caps: {
810
+ readonly maxTotalChildInvocations?: number | undefined;
811
+ readonly maxConcurrentChildren?: number | undefined;
812
+ readonly maxTurns?: number | undefined;
813
+ readonly maxToolCalls?: number | undefined;
814
+ readonly maxDurationMillis?: number | undefined;
815
+ readonly maxInputTokens?: number | undefined;
816
+ readonly maxOutputTokens?: number | undefined;
817
+ readonly maxCostMicrousd?: number | undefined;
818
+ readonly maxResultBytes?: number | undefined;
819
+ };
820
+ readonly allocation: {
821
+ readonly turns: number;
822
+ readonly toolCalls: number;
823
+ readonly durationMillis: number;
824
+ readonly inputTokens: number;
825
+ readonly outputTokens: number;
826
+ readonly costMicrousd: number;
827
+ readonly resultBytes: number;
828
+ };
829
+ } | undefined;
795
830
  } | {
796
831
  readonly _tag: "SubagentStarted";
797
832
  readonly runId: string;
@@ -831,6 +866,7 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
831
866
  readonly childInputDigest: string;
832
867
  readonly grantDigest: string;
833
868
  readonly toolCallAllowance?: number | undefined;
869
+ readonly policy?: Schema.Json | undefined;
834
870
  } | {
835
871
  readonly _tag: "RepairAnnotated";
836
872
  readonly reason: string;
@@ -925,6 +961,11 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
925
961
  readonly threadId: string;
926
962
  readonly actualEpoch: number;
927
963
  readonly attemptedEpoch: number;
964
+ } | {
965
+ readonly _tag: "DurableAlarmError";
966
+ readonly operation: string;
967
+ readonly message: string;
968
+ readonly cause?: Schema.Json | undefined;
928
969
  } | {
929
970
  readonly _tag: "OperationDenied";
930
971
  readonly operation: "abort" | "awaitSettlement" | "explain" | "observe" | "resolveApproval" | "resolveUnknown" | "retry" | "scanObligations" | "verify" | "wake";
@@ -932,28 +973,15 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
932
973
  readonly threadId?: string | undefined;
933
974
  readonly submissionId?: string | undefined;
934
975
  } | {
935
- readonly _tag: "AgentInputError";
976
+ readonly _tag: "HostProtocolError";
936
977
  readonly message: string;
937
978
  } | {
938
- readonly _tag: "DigestError";
979
+ readonly _tag: "AgentInputError";
939
980
  readonly message: string;
940
- readonly cause?: Schema.Json | undefined;
941
- } | {
942
- readonly _tag: "DurableRuntimeFailpointError";
943
- readonly location: "abort:after-intent" | "approval:after-request-append" | "approval:after-suspend" | "claim:after-claim" | "compaction:after-canonical-append" | "input:after-canonical-append" | "join:after-canonical-append" | "join:after-claim" | "policy:after-reservation-append" | "policy:before-reservation-append" | "resolve:after-intent" | "run:after-start-append" | "run:before-start-append" | "step:after-step-append" | "subagent:after-admit" | "subagent:after-child-abort-intent" | "subagent:after-child-ready" | "subagent:after-join-append" | "subagent:after-release" | "subagent:after-release-pending" | "subagent:after-request-append" | "subagent:after-reserve" | "subagent:after-sibling-settle" | "subagent:after-start-append" | "subagent:after-suspend" | "submit:after-admit" | "submit:after-materialize" | "terminalize:after-canonical-append" | "terminalize:after-reserve" | "tools:after-prepared-append" | "tools:before-prepared-append" | "turn:after-canonical-append" | "turn:after-response-append" | "turn:after-results-append";
944
- } | {
945
- readonly _tag: "AdmissionLimitExceeded";
946
- readonly limit: "database-bytes" | "input-bytes" | "queue-depth";
947
- readonly actual: number;
948
- readonly maximum: number;
949
981
  } | {
950
- readonly _tag: "DurableAlarmError";
951
- readonly operation: string;
982
+ readonly _tag: "DigestError";
952
983
  readonly message: string;
953
984
  readonly cause?: Schema.Json | undefined;
954
- } | {
955
- readonly _tag: "HostProtocolError";
956
- readonly message: string;
957
985
  } | {
958
986
  readonly _tag: "ApprovalConflict";
959
987
  readonly submissionId: string;
@@ -963,6 +991,14 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
963
991
  readonly _tag: "UnknownResolutionConflict";
964
992
  readonly submissionId: string;
965
993
  readonly toolCallId: string;
994
+ } | {
995
+ readonly _tag: "DurableRuntimeFailpointError";
996
+ readonly location: "abort:after-intent" | "approval:after-request-append" | "approval:after-suspend" | "claim:after-claim" | "compaction:after-canonical-append" | "input:after-canonical-append" | "join:after-canonical-append" | "join:after-claim" | "policy:after-reservation-append" | "policy:before-reservation-append" | "resolve:after-intent" | "run:after-start-append" | "run:before-start-append" | "step:after-step-append" | "subagent:after-admit" | "subagent:after-child-abort-intent" | "subagent:after-child-ready" | "subagent:after-join-append" | "subagent:after-release" | "subagent:after-release-pending" | "subagent:after-request-append" | "subagent:after-reserve" | "subagent:after-sibling-settle" | "subagent:after-start-append" | "subagent:after-suspend" | "submit:after-admit" | "submit:after-materialize" | "terminalize:after-canonical-append" | "terminalize:after-reserve" | "tools:after-prepared-append" | "tools:before-prepared-append" | "turn:after-canonical-append" | "turn:after-response-append" | "turn:after-results-append";
997
+ } | {
998
+ readonly _tag: "AdmissionLimitExceeded";
999
+ readonly limit: "database-bytes" | "input-bytes" | "queue-depth";
1000
+ readonly actual: number;
1001
+ readonly maximum: number;
966
1002
  };
967
1003
  }, Schema.SchemaError, never>;
968
1004
  declare const decodeHostResponse: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => Effect.Effect<AbortRecorded | ApprovalRecorded | HostFailed | ObservedPage | ProgressCancelled | ProgressObserved | SettlementReached | SubmitSucceeded | UnknownResolutionRecorded, Schema.SchemaError, never>;
@@ -1012,6 +1048,15 @@ declare const CloudflareThreadClient_base: Context.ServiceClass<CloudflareThread
1012
1048
  }>;
1013
1049
  /** Worker-side client over the Thread Object namespace (DEPLOY-010). */
1014
1050
  declare class CloudflareThreadClient extends CloudflareThreadClient_base {
1051
+ /**
1052
+ * Assemble the client from a resolved namespace and the platform Crypto implementation.
1053
+ * rpcTracing is the binding name and remains opt-in. Caller authentication, principals,
1054
+ * idempotency keys, and definition digests are still explicit submission inputs.
1055
+ */
1056
+ static layerFromBinding(options: {
1057
+ readonly namespace: DurableObjectNamespace<ThreadObjectRpc>;
1058
+ readonly rpcTracing?: string;
1059
+ }): Layer.Layer<CloudflareThreadClient>;
1015
1060
  static readonly layer: Layer.Layer<CloudflareThreadClient, never, ThreadObjectNamespace | Crypto.Crypto>;
1016
1061
  }
1017
1062
  declare namespace thread_object_d_exports {
@@ -1626,6 +1671,143 @@ interface DynamicWorkerCodeExecutorOptions {
1626
1671
  }
1627
1672
  /** Layer building the Dynamic Worker `CodeExecutor` from resolved bindings. */
1628
1673
  declare const dynamicWorkerCodeExecutorLayer: (options: DynamicWorkerCodeExecutorOptions) => Layer.Layer<CodeExecutor>;
1674
+ /** Assemble Code Mode handlers with the isolated Dynamic Worker executor. */
1675
+ declare const CloudflareCodeMode: {
1676
+ /**
1677
+ * Provide the selected tool handlers at construction, where Code Mode captures them.
1678
+ * Their errors and remaining dependencies stay visible. The definition still owns the
1679
+ * allowlist and limits; the runtime supplies the live Tool broker for each scoped pass.
1680
+ */
1681
+ layer: <A, E, R, Handlers, HandlerError, HandlerRequirements>(definition: {
1682
+ readonly handlers: Layer.Layer<A, E, R>;
1683
+ }, options: DynamicWorkerCodeExecutorOptions & {
1684
+ readonly handlers: Layer.Layer<Handlers, HandlerError, HandlerRequirements>;
1685
+ }) => Layer.Layer<A, E | HandlerError, Exclude<HandlerRequirements, CodeExecutor> | Exclude<Exclude<R, Handlers>, CodeExecutor>>;
1686
+ };
1687
+ //#endregion
1688
+ //#region src/memory.d.ts
1689
+ interface MemoryObjectRpc extends Rpc.DurableObjectBranded {
1690
+ memory(encoded: string): Promise<string>;
1691
+ }
1692
+ declare const MemoryObjectNamespace_base: Context.ServiceClass<MemoryObjectNamespace, "@effect-agent/platform-cloudflare/MemoryObjectNamespace", {
1693
+ readonly namespace: DurableObjectNamespace<MemoryObjectRpc>;
1694
+ }>;
1695
+ declare class MemoryObjectNamespace extends MemoryObjectNamespace_base {}
1696
+ /** Namespace version and identity are already canonicalized by MemoryNamespace. */
1697
+ declare const memoryObjectName: (namespace: MemoryNamespace.Any) => string;
1698
+ declare const CloudflareMemoryClient: {
1699
+ /** Bind access and principal using the MemoryObjectNamespace supplied by the application. */
1700
+ make: <Namespace extends MemoryNamespace.Any>(access: MemoryAccess<Namespace>, principal: string & import("effect/Brand").Brand<"@effect-agent/thread/Principal">, rpcLimits?: MemoryRpcLimits | undefined) => Effect.Effect<{
1701
+ recall: (lookup: {
1702
+ readonly _tag: "Found";
1703
+ readonly passages: readonly import("@effect-agent/core").MemoryPassage[];
1704
+ } | {
1705
+ readonly _tag: "NoMatch";
1706
+ } | {
1707
+ readonly _tag: "Unavailable";
1708
+ readonly message: string;
1709
+ } | {
1710
+ readonly _tag: "InsufficientFreshness";
1711
+ readonly message: string;
1712
+ }, limits: MemoryRecallLimits, estimateTokens?: ((text: string) => number) | undefined) => Effect.Effect<import("@effect-agent/core").RecalledMemory, import("@effect-agent/core").MemoryConflict | import("@effect-agent/core").MemoryIndexError | import("@effect-agent/core").MemoryMutationFailure | import("@effect-agent/core").MemoryOperationConflict | import("@effect-agent/core").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core").MemoryWithdrawn | import("@effect-agent/core").SemanticMemoryError, never>;
1713
+ revalidate: (lookup: {
1714
+ readonly _tag: "Found";
1715
+ readonly passages: readonly import("@effect-agent/core").MemoryPassage[];
1716
+ } | {
1717
+ readonly _tag: "NoMatch";
1718
+ } | {
1719
+ readonly _tag: "Unavailable";
1720
+ readonly message: string;
1721
+ } | {
1722
+ readonly _tag: "InsufficientFreshness";
1723
+ readonly message: string;
1724
+ }, limits: MemoryRecallLimits) => Effect.Effect<{
1725
+ readonly _tag: "Found";
1726
+ readonly passages: readonly import("@effect-agent/core").MemoryPassage[];
1727
+ } | {
1728
+ readonly _tag: "NoMatch";
1729
+ } | {
1730
+ readonly _tag: "Unavailable";
1731
+ readonly message: string;
1732
+ } | {
1733
+ readonly _tag: "InsufficientFreshness";
1734
+ readonly message: string;
1735
+ }, import("@effect-agent/core").MemoryConflict | import("@effect-agent/core").MemoryIndexError | import("@effect-agent/core").MemoryMutationFailure | import("@effect-agent/core").MemoryOperationConflict | import("@effect-agent/core").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core").MemoryWithdrawn | import("@effect-agent/core").SemanticMemoryError, never>;
1736
+ revalidateSemantic: (found: MemoryIndexSearch<Namespace>, profile: SemanticMemoryProfile, limits: SemanticCandidateLimits) => Effect.Effect<import("@effect-agent/core").SemanticCandidateResult, import("@effect-agent/core").MemoryConflict | import("@effect-agent/core").MemoryIndexError | import("@effect-agent/core").MemoryMutationFailure | import("@effect-agent/core").MemoryOperationConflict | import("@effect-agent/core").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core").MemoryWithdrawn | import("@effect-agent/core").SemanticMemoryError, never>;
1737
+ change: (write: MemoryWrite<Namespace>) => Effect.Effect<MemoryDocument<Namespace>, import("@effect-agent/core").MemoryConflict | import("@effect-agent/core").MemoryIndexError | import("@effect-agent/core").MemoryMutationFailure | import("@effect-agent/core").MemoryOperationConflict | import("@effect-agent/core").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core").MemoryWithdrawn | import("@effect-agent/core").SemanticMemoryError, never>;
1738
+ }, MemoryRpcError, MemoryObjectNamespace>;
1739
+ /** Use a resolved Worker or Durable Object binding without manual service provisioning. */
1740
+ fromBinding: <Namespace extends MemoryNamespace.Any>(binding: DurableObjectNamespace<MemoryObjectRpc>, options: {
1741
+ readonly access: MemoryAccess<Namespace>;
1742
+ readonly principal: Principal;
1743
+ readonly rpcLimits?: MemoryRpcLimits;
1744
+ }) => Effect.Effect<{
1745
+ recall: (lookup: {
1746
+ readonly _tag: "Found";
1747
+ readonly passages: readonly import("@effect-agent/core").MemoryPassage[];
1748
+ } | {
1749
+ readonly _tag: "NoMatch";
1750
+ } | {
1751
+ readonly _tag: "Unavailable";
1752
+ readonly message: string;
1753
+ } | {
1754
+ readonly _tag: "InsufficientFreshness";
1755
+ readonly message: string;
1756
+ }, limits: MemoryRecallLimits, estimateTokens?: ((text: string) => number) | undefined) => Effect.Effect<import("@effect-agent/core").RecalledMemory, import("@effect-agent/core").MemoryConflict | import("@effect-agent/core").MemoryIndexError | import("@effect-agent/core").MemoryMutationFailure | import("@effect-agent/core").MemoryOperationConflict | import("@effect-agent/core").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core").MemoryWithdrawn | import("@effect-agent/core").SemanticMemoryError, never>;
1757
+ revalidate: (lookup: {
1758
+ readonly _tag: "Found";
1759
+ readonly passages: readonly import("@effect-agent/core").MemoryPassage[];
1760
+ } | {
1761
+ readonly _tag: "NoMatch";
1762
+ } | {
1763
+ readonly _tag: "Unavailable";
1764
+ readonly message: string;
1765
+ } | {
1766
+ readonly _tag: "InsufficientFreshness";
1767
+ readonly message: string;
1768
+ }, limits: MemoryRecallLimits) => Effect.Effect<{
1769
+ readonly _tag: "Found";
1770
+ readonly passages: readonly import("@effect-agent/core").MemoryPassage[];
1771
+ } | {
1772
+ readonly _tag: "NoMatch";
1773
+ } | {
1774
+ readonly _tag: "Unavailable";
1775
+ readonly message: string;
1776
+ } | {
1777
+ readonly _tag: "InsufficientFreshness";
1778
+ readonly message: string;
1779
+ }, import("@effect-agent/core").MemoryConflict | import("@effect-agent/core").MemoryIndexError | import("@effect-agent/core").MemoryMutationFailure | import("@effect-agent/core").MemoryOperationConflict | import("@effect-agent/core").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core").MemoryWithdrawn | import("@effect-agent/core").SemanticMemoryError, never>;
1780
+ revalidateSemantic: (found: MemoryIndexSearch<Namespace>, profile: SemanticMemoryProfile, limits: SemanticCandidateLimits) => Effect.Effect<import("@effect-agent/core").SemanticCandidateResult, import("@effect-agent/core").MemoryConflict | import("@effect-agent/core").MemoryIndexError | import("@effect-agent/core").MemoryMutationFailure | import("@effect-agent/core").MemoryOperationConflict | import("@effect-agent/core").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core").MemoryWithdrawn | import("@effect-agent/core").SemanticMemoryError, never>;
1781
+ change: (write: MemoryWrite<Namespace>) => Effect.Effect<MemoryDocument<Namespace>, import("@effect-agent/core").MemoryConflict | import("@effect-agent/core").MemoryIndexError | import("@effect-agent/core").MemoryMutationFailure | import("@effect-agent/core").MemoryOperationConflict | import("@effect-agent/core").MemoryRecallError | MemoryRpcError | MemoryStorageError | import("@effect-agent/core").MemoryWithdrawn | import("@effect-agent/core").SemanticMemoryError, never>;
1782
+ }, MemoryRpcError, never>;
1783
+ };
1784
+ /**
1785
+ * Optional activity-processor destination. Keeps domain write errors intact; transport,
1786
+ * authorization and deadline failures become the existing MemoryStorageError contract.
1787
+ * Receipts remain authoritative, including after caller interruption or lost replies.
1788
+ */
1789
+ declare const cloudflareMemoryWriterLayer: (access: MemoryAccess, principal: Principal, limits?: MemoryRpcLimits) => Layer.Layer<MemoryWriter, MemoryRpcError, MemoryObjectNamespace>;
1790
+ type OwnerServices = MemoryReader | MemoryWriter | MemoryOwnerAuthorizer | MemoryOwnerIdentity;
1791
+ interface MemoryObjectInstance extends InstanceType<DurableObject.DurableObjectClass<Record<never, never>, OwnerServices>> {
1792
+ memory(encoded: string): Promise<string>;
1793
+ }
1794
+ interface MemoryObjectClass {
1795
+ new (ctx: globalThis.DurableObjectState, env: Cloudflare.Env): MemoryObjectInstance;
1796
+ }
1797
+ /**
1798
+ * Dedicated SQLite owner, independent of Thread lifetimes. The host binds authorization
1799
+ * after restoring its namespace definition from MemoryOwnerIdentity. Do not retain
1800
+ * cleanup-scoped resources in the host Layer; it lives for the DO incarnation.
1801
+ */
1802
+ declare const makeMemoryObject: <E>(host: Layer.Layer<MemoryOwnerAuthorizer, E, MemoryOwnerIdentity | DurableObjectState$1.DurableObjectState | WorkerEnvironment>, options?: {
1803
+ readonly storageLimits?: DoMemoryStorageLimits;
1804
+ readonly rpcLimits?: MemoryRpcLimits;
1805
+ readonly failpoints?: Layer.Layer<MemoryMutationFailpoint, never, DurableObjectState$1.DurableObjectState>;
1806
+ }) => MemoryObjectClass;
1807
+ declare const MemoryObject: {
1808
+ /** Build the SQLite Durable Object class with the application's owner authorization Layer. */
1809
+ make: typeof makeMemoryObject;
1810
+ };
1629
1811
  //#endregion
1630
- export { AbortRecorded, AdmissionLimitExceeded, ApprovalRecorded, AwaitProgressRequest, CLOUDFLARE_DATABASE_CAP_BYTES, CLOUDFLARE_RUNTIME_DEFAULTS, CancelProgressRequest, ClientAbortFailure, ClientApprovalFailure, ClientAwaitFailure, ClientObserveFailure, ClientProgressFailure, ClientSubmitFailure, ClientUnknownFailure, CloudflareAdmissionLimitsValue, CloudflareBindingError, CloudflareDurableRuntimeConfig, CloudflareDurableRuntimeConfigValue, CloudflarePlatformConfigError, CloudflareSchedulingClient, CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, CloudflareThreadClient, DEFAULT_MAX_DATABASE_BYTES, DurableAlarmError, DurableAlarmService, DurableObjectContext, DynamicWorkerCodeExecutorOptions, HostFailed, HostFailure, HostProtocolError, HostResponse, MaintenancePassFailure, MaintenancePassReport, ObservePageRequest, ObservedPage, ProgressCancelled, ProgressObserved, ProgressWaitRegistry, ScheduleAlarmProtocolError, ScheduleOwnerIdentity, ScheduleOwnerNamespace, ScheduleOwnerObjectClass, ScheduleOwnerObjectInstance, ScheduleOwnerObjectRpc, ScheduleOwnerProtocolError, SettlementReached, SubmitRequest, SubmitSucceeded, SubscriptionAlarmProtocolError, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionObjectClass, SubscriptionPartitionObjectInstance, SubscriptionPartitionObjectRpc, SubscriptionPartitionProtocolError, ThreadClientError, ThreadMaintenance, ThreadMaintenanceFailpoint, ThreadMaintenanceFailpointHandler, ThreadMaintenanceFailpointLocation, thread_object_d_exports as ThreadObject, ThreadObjectIdentity, ThreadObjectNamespace, ThreadObjectPorts, ThreadObjectRpc, UnknownResolutionRecorded, boundHostDiagnostic, cloudflarePreparedInputAdmissionLayer, cloudflareScheduledInputAdmissionLayer, cloudflareWakeSchedulerLayer, decodeAbortCommand, decodeApprovalDecisionCommand, decodeAwaitProgressRequest, decodeCancelProgressRequest, decodeHostResponse, decodeObservePageRequest, decodeReceipt, decodeSubmitRequest, decodeUnknownResolutionCommand, disposeRpcHandle, dynamicWorkerCodeExecutorLayer, dynamicWorkerImplementation, encodeAbortCommand, encodeApprovalDecisionCommand, encodeAwaitProgressRequest, encodeCancelProgressRequest, encodeHostResponse, encodeObservePageRequest, encodeReceipt, encodeSubmitRequest, encodeUnknownResolutionCommand, makeScheduleOwnerObjectClass, makeSubscriptionPartitionObjectClass, sourcePartitionName, threadNamespaceFromEnv, threadNamespaceLayer, threadPortTransportLayer, validateCloudflareSubscriptionLimits };
1812
+ export { AbortRecorded, AdmissionLimitExceeded, ApprovalRecorded, AwaitProgressRequest, CLOUDFLARE_DATABASE_CAP_BYTES, CLOUDFLARE_RUNTIME_DEFAULTS, CancelProgressRequest, ClientAbortFailure, ClientApprovalFailure, ClientAwaitFailure, ClientObserveFailure, ClientProgressFailure, ClientSubmitFailure, ClientUnknownFailure, CloudflareAdmissionLimitsValue, CloudflareBindingError, CloudflareBrowser, type CloudflareBrowserOptions, CloudflareCodeMode, CloudflareDurableRuntimeConfig, CloudflareDurableRuntimeConfigValue, CloudflareMemoryClient, CloudflarePlatformConfigError, CloudflareSchedulingClient, CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, CloudflareThreadClient, DEFAULT_MAX_DATABASE_BYTES, DurableAlarmError, DurableAlarmService, DurableObjectContext, DynamicWorkerCodeExecutorOptions, HostFailed, HostFailure, HostProtocolError, HostResponse, MaintenancePassFailure, MaintenancePassReport, MemoryObject, MemoryObjectClass, MemoryObjectInstance, MemoryObjectNamespace, MemoryObjectRpc, ObservePageRequest, ObservedPage, ProgressCancelled, ProgressObserved, ProgressWaitRegistry, ScheduleAlarmProtocolError, ScheduleOwnerIdentity, ScheduleOwnerNamespace, ScheduleOwnerObjectClass, ScheduleOwnerObjectInstance, ScheduleOwnerObjectRpc, ScheduleOwnerProtocolError, SettlementReached, SubmitRequest, SubmitSucceeded, SubscriptionAlarmProtocolError, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionObjectClass, SubscriptionPartitionObjectInstance, SubscriptionPartitionObjectRpc, SubscriptionPartitionProtocolError, ThreadClientError, ThreadMaintenance, ThreadMaintenanceFailpoint, ThreadMaintenanceFailpointHandler, ThreadMaintenanceFailpointLocation, thread_object_d_exports as ThreadObject, ThreadObjectIdentity, ThreadObjectNamespace, ThreadObjectPorts, ThreadObjectRpc, UnknownResolutionRecorded, boundHostDiagnostic, cloudflareMemoryWriterLayer, cloudflarePreparedInputAdmissionLayer, cloudflareScheduledInputAdmissionLayer, cloudflareWakeSchedulerLayer, decodeAbortCommand, decodeApprovalDecisionCommand, decodeAwaitProgressRequest, decodeCancelProgressRequest, decodeHostResponse, decodeObservePageRequest, decodeReceipt, decodeSubmitRequest, decodeUnknownResolutionCommand, disposeRpcHandle, dynamicWorkerCodeExecutorLayer, dynamicWorkerImplementation, encodeAbortCommand, encodeApprovalDecisionCommand, encodeAwaitProgressRequest, encodeCancelProgressRequest, encodeHostResponse, encodeObservePageRequest, encodeReceipt, encodeSubmitRequest, encodeUnknownResolutionCommand, makeScheduleOwnerObjectClass, makeSubscriptionPartitionObjectClass, memoryObjectName, sourcePartitionName, threadNamespaceFromEnv, threadNamespaceLayer, threadPortTransportLayer, validateCloudflareSubscriptionLimits };
1631
1813
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1,11 +1,12 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
- import { $ as CloudflarePlatformConfigError, A as decodeUnknownResolutionCommand, B as DurableAlarmError, C as decodeApprovalDecisionCommand, D as decodeObservePageRequest, E as decodeHostResponse, F as encodeHostResponse, G as safeCauseDiagnostic, H as MaintenancePassReport, I as encodeObservePageRequest, J as CLOUDFLARE_DATABASE_CAP_BYTES, K as safeCauseMessage, L as encodeReceipt, M as encodeApprovalDecisionCommand, N as encodeAwaitProgressRequest, O as decodeReceipt, P as encodeCancelProgressRequest, Q as CloudflareDurableRuntimeConfigValue, R as encodeSubmitRequest, S as decodeAbortCommand, T as decodeCancelProgressRequest, U as ThreadMaintenance, V as DurableAlarmService, W as ThreadMaintenanceFailpoint, X as CloudflareAdmissionLimitsValue, Y as CLOUDFLARE_RUNTIME_DEFAULTS, Z as CloudflareDurableRuntimeConfig, _ as SubmitRequest, a as AwaitProgressRequest, at as threadNamespaceFromEnv, b as UnknownResolutionRecorded, c as HostFailed, d as HostResponse, et as DEFAULT_MAX_DATABASE_BYTES, f as ObservePageRequest, g as SettlementReached, h as ProgressObserved, i as ApprovalRecorded, it as ThreadObjectNamespace, j as encodeAbortCommand, k as decodeSubmitRequest, l as HostFailure, m as ProgressCancelled, n as cloudflareScheduledInputAdmissionLayer, nt as DurableObjectContext, o as CancelProgressRequest, ot as threadNamespaceLayer, p as ObservedPage, q as AdmissionLimitExceeded, r as AbortRecorded, rt as ThreadObjectIdentity, s as CloudflareThreadClient, t as cloudflarePreparedInputAdmissionLayer, tt as CloudflareBindingError, u as HostProtocolError, v as SubmitSucceeded, w as decodeAwaitProgressRequest, x as boundHostDiagnostic, y as ThreadClientError, z as encodeUnknownResolutionCommand } from "./prepared-admission-D5hQ-ofV.mjs";
2
+ import { $ as CloudflarePlatformConfigError, A as decodeUnknownResolutionCommand, B as DurableAlarmError, C as decodeApprovalDecisionCommand, D as decodeObservePageRequest, E as decodeHostResponse, F as encodeHostResponse, G as safeCauseDiagnostic, H as MaintenancePassReport, I as encodeObservePageRequest, J as CLOUDFLARE_DATABASE_CAP_BYTES, K as safeCauseMessage, L as encodeReceipt, M as encodeApprovalDecisionCommand, N as encodeAwaitProgressRequest, O as decodeReceipt, P as encodeCancelProgressRequest, Q as CloudflareDurableRuntimeConfigValue, R as encodeSubmitRequest, S as decodeAbortCommand, T as decodeCancelProgressRequest, U as ThreadMaintenance, V as DurableAlarmService, W as ThreadMaintenanceFailpoint, X as CloudflareAdmissionLimitsValue, Y as CLOUDFLARE_RUNTIME_DEFAULTS, Z as CloudflareDurableRuntimeConfig, _ as SubmitRequest, a as AwaitProgressRequest, at as threadNamespaceFromEnv, b as UnknownResolutionRecorded, c as HostFailed, d as HostResponse, et as DEFAULT_MAX_DATABASE_BYTES, f as ObservePageRequest, g as SettlementReached, h as ProgressObserved, i as ApprovalRecorded, it as ThreadObjectNamespace, j as encodeAbortCommand, k as decodeSubmitRequest, l as HostFailure, m as ProgressCancelled, n as cloudflareScheduledInputAdmissionLayer, nt as DurableObjectContext, o as CancelProgressRequest, ot as threadNamespaceLayer, p as ObservedPage, q as AdmissionLimitExceeded, r as AbortRecorded, rt as ThreadObjectIdentity, s as CloudflareThreadClient, t as cloudflarePreparedInputAdmissionLayer, tt as CloudflareBindingError, u as HostProtocolError, v as SubmitSucceeded, w as decodeAwaitProgressRequest, x as boundHostDiagnostic, y as ThreadClientError, z as encodeUnknownResolutionCommand } from "./prepared-admission-BKp_Upw2.mjs";
3
3
  import { CloudflareSchedulingClient, ScheduleAlarmProtocolError, ScheduleOwnerIdentity, ScheduleOwnerNamespace, ScheduleOwnerProtocolError, makeScheduleOwnerObjectClass } from "./scheduling.mjs";
4
4
  import { CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, SubscriptionAlarmProtocolError, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionProtocolError, makeSubscriptionPartitionObjectClass, sourcePartitionName, validateCloudflareSubscriptionLimits } from "./subscriptions.mjs";
5
+ import { CloudflareBrowser } from "./browser-quick-action.mjs";
5
6
  import { Clock, Context, Deferred, Duration, Effect, Exit, Fiber, Layer, Option, PubSub, Queue, Ref, Schema, Stream } from "effect";
6
- import { ThreadPortTransport, decodePortRequest, encodePortResponse, executePortRequest, portTransportFailure, routedSubmissionLedgerLayer, routedThreadStoreLayer, storageConfigLayer, storageFailpointLayer, submissionLedgerLayer, threadStoreLayer } from "@effect-agent/storage-cloudflare";
7
- import { AppendConflict, DigestError, DurableAgentRuntime, DurableRuntimeConfig, DurableRuntimeFailpoint, DurableRuntimeFailpointError, FenceRejected, IntegrityReport, LedgerError, ObligationReport, ObligationThresholds, OperationAuthorizationRequest, OperationAuthorizer, OperationDenied, OwnershipLost, PersistedJson, ProducerId, RecoveryExplanation, RecoveryReport, RetryCommand, RetryRefused, RunJournalError, SettlementConflict, SubmissionLedger, SubmissionLookupByKey, ThreadNotMaterialized, ThreadRead, ThreadStore, ThreadStoreError, ToolReconciler, WakeScheduler, compileRegistrations, makeWakeSubscriptionHub, operationAuthorizerLayer } from "@effect-agent/thread";
8
- import { SubmissionId, ThreadId } from "@effect-agent/core";
7
+ import { MemoryOwnerIdentity, MemoryOwnerRequest, MemoryOwnerResponse, MemoryRpcError, MemoryRpcLimits, ThreadPortTransport, decodeMemoryWire, decodePortRequest, defaultDoMemoryStorageLimits, defaultMemoryRpcLimits, doMemoryStoreLayerWithFailpoints, encodeMemoryWire, encodePortResponse, executePortRequest, handleMemoryOwnerRequest, portTransportFailure, routedSubmissionLedgerLayer, routedThreadStoreLayer, storageConfigLayer, storageFailpointLayer, submissionLedgerLayer, threadStoreLayer } from "@effect-agent/storage-cloudflare";
8
+ import { AppendConflict, DigestError, DurableAgentRuntime, DurableRuntimeConfig, DurableRuntimeFailpoint, DurableRuntimeFailpointError, FenceRejected, IntegrityReport, LedgerError, ObligationReport, ObligationThresholds, OperationAuthorizationRequest, OperationAuthorizer, OperationDenied, OwnershipLost, PersistedJson, Principal, ProducerId, RecoveryExplanation, RecoveryReport, RetryCommand, RetryRefused, RunJournalError, SettlementConflict, SubmissionLedger, SubmissionLookupByKey, ThreadNotMaterialized, ThreadRead, ThreadStore, ThreadStoreError, ToolReconciler, WakeScheduler, compileRegistrations, makeWakeSubscriptionHub, operationAuthorizerLayer } from "@effect-agent/thread";
9
+ import { Memory, MemoryAccess, MemoryDocument, MemoryMutationFailpoint, MemoryNamespace, MemoryNamespaceAddress, MemoryRecallLimits, MemoryStorageError, MemoryWriter, SubmissionId, ThreadId } from "@effect-agent/core";
9
10
  import { CurrentToolFailureObserver, RunContextPreparationPassthrough, RunToolAuthorization, toolFailureObserverLayer } from "@effect-agent/engine";
10
11
  import { BrowserCrypto } from "@effect/platform-browser";
11
12
  import { SqliteClient } from "@effect/sql-sqlite-do";
@@ -539,7 +540,8 @@ const effectCfPlatformLayer = (namespaceBinding, rpcTracing = false) => {
539
540
  });
540
541
  }));
541
542
  const namespace = Layer.effect(ThreadObjectNamespace)(Effect.gen(function* () {
542
- const binding = yield* threadNamespaceFromEnv(yield* WorkerEnvironment, namespaceBinding);
543
+ const env = yield* WorkerEnvironment;
544
+ const binding = yield* threadNamespaceFromEnv(env, namespaceBinding);
543
545
  return ThreadObjectNamespace.of({
544
546
  namespace: binding,
545
547
  ...rpcTracing === true ? { rpcTracing: namespaceBinding } : {}
@@ -781,7 +783,7 @@ export default class CodeModeHarness extends WorkerEntrypoint {
781
783
  }
782
784
  }
783
785
  `;
784
- const BoundedLogs = Schema.Array(Schema.String.check(Schema.isMaxLength(16 * 1024))).check(Schema.isMaxLength(4096));
786
+ const BoundedLogs = Schema.Array(Schema.String.check(Schema.isMaxLength(16384))).check(Schema.isMaxLength(4096));
785
787
  const HarnessCompleted = Schema.TaggedStruct("completed", {
786
788
  value: Schema.Json,
787
789
  logs: BoundedLogs,
@@ -1192,7 +1194,159 @@ const dynamicWorkerCodeExecutorLayer = (options) => Layer.effect(CodeExecutor, E
1192
1194
  const clock = yield* Clock.Clock;
1193
1195
  return CodeExecutor.of({ execute: makeExecute(options, clock) });
1194
1196
  }));
1197
+ /** Assemble Code Mode handlers with the isolated Dynamic Worker executor. */
1198
+ const CloudflareCodeMode = {
1199
+ /**
1200
+ * Provide the selected tool handlers at construction, where Code Mode captures them.
1201
+ * Their errors and remaining dependencies stay visible. The definition still owns the
1202
+ * allowlist and limits; the runtime supplies the live Tool broker for each scoped pass.
1203
+ */
1204
+ layer: (definition, options) => definition.handlers.pipe(Layer.provide(options.handlers), Layer.provide(dynamicWorkerCodeExecutorLayer(options))) };
1205
+ //#endregion
1206
+ //#region src/memory.ts
1207
+ var MemoryObjectNamespace = class extends Context.Service()("@effect-agent/platform-cloudflare/MemoryObjectNamespace") {};
1208
+ /** Namespace version and identity are already canonicalized by MemoryNamespace. */
1209
+ const memoryObjectName = (namespace) => namespace.address;
1210
+ /**
1211
+ * Effect-native, host-bound memory client. Recall revalidates the entire admitted lookup
1212
+ * in one RPC and renders it locally. No retries or per-source splitting occur here.
1213
+ * Interrupted callers stop waiting; the owner has its own deadline. A timed-out write
1214
+ * may have committed: reconcile by sending the identical operation ID and command.
1215
+ */
1216
+ const makeMemoryClient = Effect.fn("CloudflareMemoryClient.make")(function* (access, principal, rpcLimits = defaultMemoryRpcLimits) {
1217
+ const validated = yield* Schema.decodeUnknownEffect(MemoryRpcLimits)(rpcLimits).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
1218
+ const bound = yield* Schema.decodeUnknownEffect(MemoryAccess.Wire)(access).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
1219
+ principal = yield* Schema.decodeUnknownEffect(Principal)(principal).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
1220
+ const { namespace } = yield* MemoryObjectNamespace;
1221
+ const call = Effect.fn("CloudflareMemoryClient.call")(function* (request) {
1222
+ const decoded = yield* Schema.decodeUnknownEffect(MemoryOwnerRequest)(request).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
1223
+ const encoded = yield* encodeMemoryWire(MemoryOwnerRequest, decoded, validated.maxRequestBytes);
1224
+ const raw = yield* Effect.tryPromise({
1225
+ try: () => namespace.get(namespace.idFromName(memoryObjectName(bound.namespace))).memory(encoded),
1226
+ catch: () => MemoryRpcError.make({ reason: "unavailable" })
1227
+ });
1228
+ const response = yield* decodeMemoryWire(MemoryOwnerResponse, raw, validated.maxResponseBytes);
1229
+ if (response._tag === "Failed") return yield* response.failure;
1230
+ if (!MemoryNamespace.equals(response.access.namespace, bound.namespace) || response.access.scope !== bound.scope) return yield* MemoryRpcError.make({ reason: "protocol" });
1231
+ return response;
1232
+ });
1233
+ const withinDeadline = (effect, timeoutMillis) => effect.pipe(Effect.timeoutOrElse({
1234
+ duration: timeoutMillis,
1235
+ orElse: () => Effect.fail(MemoryRpcError.make({ reason: "timeout" }))
1236
+ }));
1237
+ const revalidate = Effect.fn("CloudflareMemoryClient.revalidate")(function* (lookup, limits) {
1238
+ limits = yield* Schema.decodeUnknownEffect(MemoryRecallLimits)(limits).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
1239
+ const timeoutMillis = Math.min(validated.timeoutMillis, limits.timeoutMillis);
1240
+ return yield* Effect.gen(function* () {
1241
+ const response = yield* call({
1242
+ _tag: "Revalidate",
1243
+ version: 1,
1244
+ access: bound,
1245
+ principal,
1246
+ lookup,
1247
+ limits,
1248
+ deadlineMillis: (yield* Clock.currentTimeMillis) + timeoutMillis
1249
+ });
1250
+ if (response._tag !== "Lookup") return yield* MemoryRpcError.make({ reason: "protocol" });
1251
+ return response.lookup;
1252
+ }).pipe((effect) => withinDeadline(effect, timeoutMillis));
1253
+ });
1254
+ const change = Effect.fn("CloudflareMemoryClient.change")(function* (write) {
1255
+ if (!MemoryNamespace.equals(write.key.namespace, bound.namespace)) return yield* MemoryRpcError.make({ reason: "denied" });
1256
+ return yield* Effect.gen(function* () {
1257
+ const response = yield* call({
1258
+ _tag: "Change",
1259
+ version: 1,
1260
+ access: bound,
1261
+ principal,
1262
+ write,
1263
+ deadlineMillis: (yield* Clock.currentTimeMillis) + validated.timeoutMillis
1264
+ });
1265
+ if (response._tag !== "Changed" || response.document.key.id !== write.key.id) return yield* MemoryRpcError.make({ reason: "protocol" });
1266
+ return yield* MemoryDocument.restore(access.namespace, response.document);
1267
+ }).pipe((effect) => withinDeadline(effect, validated.timeoutMillis));
1268
+ });
1269
+ const revalidateSemantic = Effect.fn("CloudflareMemoryClient.revalidateSemantic")(function* (found, profile, limits) {
1270
+ return yield* Effect.gen(function* () {
1271
+ const response = yield* call({
1272
+ _tag: "RevalidateSemantic",
1273
+ version: 1,
1274
+ access: bound,
1275
+ principal,
1276
+ found,
1277
+ profile,
1278
+ limits,
1279
+ deadlineMillis: (yield* Clock.currentTimeMillis) + validated.timeoutMillis
1280
+ });
1281
+ if (response._tag !== "Semantic") return yield* MemoryRpcError.make({ reason: "protocol" });
1282
+ return response.result;
1283
+ }).pipe((effect) => withinDeadline(effect, validated.timeoutMillis));
1284
+ });
1285
+ return {
1286
+ recall: Effect.fn("CloudflareMemoryClient.recall")(function* (lookup, limits, estimateTokens) {
1287
+ return yield* Memory.recall([{
1288
+ id: "memory",
1289
+ essential: true,
1290
+ read: revalidate(lookup, limits)
1291
+ }], limits, estimateTokens);
1292
+ }),
1293
+ revalidate,
1294
+ revalidateSemantic,
1295
+ change
1296
+ };
1297
+ });
1298
+ const CloudflareMemoryClient = {
1299
+ /** Bind access and principal using the MemoryObjectNamespace supplied by the application. */
1300
+ make: makeMemoryClient,
1301
+ /** Use a resolved Worker or Durable Object binding without manual service provisioning. */
1302
+ fromBinding: Effect.fn("CloudflareMemoryClient.fromBinding")(function* (binding, options) {
1303
+ return yield* makeMemoryClient(options.access, options.principal, options.rpcLimits).pipe(Effect.provideService(MemoryObjectNamespace, { namespace: binding }));
1304
+ })
1305
+ };
1306
+ /**
1307
+ * Optional activity-processor destination. Keeps domain write errors intact; transport,
1308
+ * authorization and deadline failures become the existing MemoryStorageError contract.
1309
+ * Receipts remain authoritative, including after caller interruption or lost replies.
1310
+ */
1311
+ const cloudflareMemoryWriterLayer = (access, principal, limits = defaultMemoryRpcLimits) => Layer.effect(MemoryWriter, Effect.gen(function* () {
1312
+ const client = yield* CloudflareMemoryClient.make(access, principal, limits);
1313
+ return MemoryWriter.fromAdapter({ change: (write) => client.change(write).pipe(Effect.catchTag("MemoryRpcError", (error) => Effect.fail(MemoryStorageError.make({
1314
+ operation: `memory RPC ${error.reason}`,
1315
+ reason: error.reason === "unavailable" || error.reason === "timeout" ? "unavailable" : "invalid-input"
1316
+ }))), Effect.catchTag([
1317
+ "MemoryRecallError",
1318
+ "MemoryIndexError",
1319
+ "SemanticMemoryError"
1320
+ ], () => Effect.fail(MemoryStorageError.make({
1321
+ operation: "memory RPC response",
1322
+ reason: "corrupt"
1323
+ })))) });
1324
+ }));
1325
+ /**
1326
+ * Dedicated SQLite owner, independent of Thread lifetimes. The host binds authorization
1327
+ * after restoring its namespace definition from MemoryOwnerIdentity. Do not retain
1328
+ * cleanup-scoped resources in the host Layer; it lives for the DO incarnation.
1329
+ */
1330
+ const makeMemoryObject = (host, options = {}) => {
1331
+ const identity = Layer.effect(MemoryOwnerIdentity, Effect.gen(function* () {
1332
+ const state = yield* DurableObjectState.DurableObjectState;
1333
+ const address = yield* Schema.decodeUnknownEffect(MemoryNamespaceAddress)(state.raw.id.name).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "denied" })));
1334
+ return { namespace: MemoryNamespace.Any.make({ address }) };
1335
+ }));
1336
+ const store = Layer.unwrap(Effect.map(DurableObjectState.DurableObjectState, (state) => doMemoryStoreLayerWithFailpoints(state.raw.storage, options.storageLimits ?? defaultDoMemoryStorageLimits))).pipe(Layer.provide(options.failpoints ?? MemoryMutationFailpoint.layer));
1337
+ const application = Layer.merge(store, host).pipe(Layer.provideMerge(identity));
1338
+ const runtime = Layer.effectContext(Effect.gen(function* () {
1339
+ const state = yield* DurableObjectState.DurableObjectState;
1340
+ const scope = yield* Effect.scope;
1341
+ yield* Schema.decodeUnknownEffect(MemoryRpcLimits)(options.rpcLimits ?? defaultMemoryRpcLimits).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
1342
+ return yield* state.blockConcurrencyWhile(Layer.buildWithScope(application, scope));
1343
+ }));
1344
+ return DurableObject.make(runtime, { rpc: { memory: (encoded) => handleMemoryOwnerRequest(encoded, options.rpcLimits) } });
1345
+ };
1346
+ const MemoryObject = {
1347
+ /** Build the SQLite Durable Object class with the application's owner authorization Layer. */
1348
+ make: makeMemoryObject };
1195
1349
  //#endregion
1196
- export { AbortRecorded, AdmissionLimitExceeded, ApprovalRecorded, AwaitProgressRequest, CLOUDFLARE_DATABASE_CAP_BYTES, CLOUDFLARE_RUNTIME_DEFAULTS, CancelProgressRequest, CloudflareAdmissionLimitsValue, CloudflareBindingError, CloudflareDurableRuntimeConfig, CloudflareDurableRuntimeConfigValue, CloudflarePlatformConfigError, CloudflareSchedulingClient, CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, CloudflareThreadClient, DEFAULT_MAX_DATABASE_BYTES, DurableAlarmError, DurableAlarmService, DurableObjectContext, HostFailed, HostFailure, HostProtocolError, HostResponse, MaintenancePassReport, ObservePageRequest, ObservedPage, ProgressCancelled, ProgressObserved, ProgressWaitRegistry, ScheduleAlarmProtocolError, ScheduleOwnerIdentity, ScheduleOwnerNamespace, ScheduleOwnerProtocolError, SettlementReached, SubmitRequest, SubmitSucceeded, SubscriptionAlarmProtocolError, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionProtocolError, ThreadClientError, ThreadMaintenance, ThreadMaintenanceFailpoint, thread_object_exports as ThreadObject, ThreadObjectIdentity, ThreadObjectNamespace, ThreadObjectPorts, UnknownResolutionRecorded, boundHostDiagnostic, cloudflarePreparedInputAdmissionLayer, cloudflareScheduledInputAdmissionLayer, cloudflareWakeSchedulerLayer, decodeAbortCommand, decodeApprovalDecisionCommand, decodeAwaitProgressRequest, decodeCancelProgressRequest, decodeHostResponse, decodeObservePageRequest, decodeReceipt, decodeSubmitRequest, decodeUnknownResolutionCommand, disposeRpcHandle, dynamicWorkerCodeExecutorLayer, dynamicWorkerImplementation, encodeAbortCommand, encodeApprovalDecisionCommand, encodeAwaitProgressRequest, encodeCancelProgressRequest, encodeHostResponse, encodeObservePageRequest, encodeReceipt, encodeSubmitRequest, encodeUnknownResolutionCommand, makeScheduleOwnerObjectClass, makeSubscriptionPartitionObjectClass, sourcePartitionName, threadNamespaceFromEnv, threadNamespaceLayer, threadPortTransportLayer, validateCloudflareSubscriptionLimits };
1350
+ export { AbortRecorded, AdmissionLimitExceeded, ApprovalRecorded, AwaitProgressRequest, CLOUDFLARE_DATABASE_CAP_BYTES, CLOUDFLARE_RUNTIME_DEFAULTS, CancelProgressRequest, CloudflareAdmissionLimitsValue, CloudflareBindingError, CloudflareBrowser, CloudflareCodeMode, CloudflareDurableRuntimeConfig, CloudflareDurableRuntimeConfigValue, CloudflareMemoryClient, CloudflarePlatformConfigError, CloudflareSchedulingClient, CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, CloudflareThreadClient, DEFAULT_MAX_DATABASE_BYTES, DurableAlarmError, DurableAlarmService, DurableObjectContext, HostFailed, HostFailure, HostProtocolError, HostResponse, MaintenancePassReport, MemoryObject, MemoryObjectNamespace, ObservePageRequest, ObservedPage, ProgressCancelled, ProgressObserved, ProgressWaitRegistry, ScheduleAlarmProtocolError, ScheduleOwnerIdentity, ScheduleOwnerNamespace, ScheduleOwnerProtocolError, SettlementReached, SubmitRequest, SubmitSucceeded, SubscriptionAlarmProtocolError, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionProtocolError, ThreadClientError, ThreadMaintenance, ThreadMaintenanceFailpoint, thread_object_exports as ThreadObject, ThreadObjectIdentity, ThreadObjectNamespace, ThreadObjectPorts, UnknownResolutionRecorded, boundHostDiagnostic, cloudflareMemoryWriterLayer, cloudflarePreparedInputAdmissionLayer, cloudflareScheduledInputAdmissionLayer, cloudflareWakeSchedulerLayer, decodeAbortCommand, decodeApprovalDecisionCommand, decodeAwaitProgressRequest, decodeCancelProgressRequest, decodeHostResponse, decodeObservePageRequest, decodeReceipt, decodeSubmitRequest, decodeUnknownResolutionCommand, disposeRpcHandle, dynamicWorkerCodeExecutorLayer, dynamicWorkerImplementation, encodeAbortCommand, encodeApprovalDecisionCommand, encodeAwaitProgressRequest, encodeCancelProgressRequest, encodeHostResponse, encodeObservePageRequest, encodeReceipt, encodeSubmitRequest, encodeUnknownResolutionCommand, makeScheduleOwnerObjectClass, makeSubscriptionPartitionObjectClass, memoryObjectName, sourcePartitionName, threadNamespaceFromEnv, threadNamespaceLayer, threadPortTransportLayer, validateCloudflareSubscriptionLimits };
1197
1351
 
1198
1352
  //# sourceMappingURL=index.mjs.map