@effect-agent/platform-cloudflare 0.1.0-beta.40 → 0.1.0-beta.42

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
@@ -3,9 +3,9 @@ import { a as ThreadObjectRpc, i as ThreadObjectNamespace, n as DurableObjectCon
3
3
  import { CloudflareSchedulingClient, ScheduleAlarmProtocolError, ScheduleOwnerIdentity, ScheduleOwnerNamespace, ScheduleOwnerObjectClass, ScheduleOwnerObjectInstance, ScheduleOwnerObjectRpc, ScheduleOwnerProtocolError, makeScheduleOwnerObjectClass } from "./scheduling.mjs";
4
4
  import { CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, SubscriptionAlarmProtocolError, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionObjectClass, SubscriptionPartitionObjectInstance, SubscriptionPartitionObjectRpc, SubscriptionPartitionProtocolError, makeSubscriptionPartitionObjectClass, sourcePartitionName, validateCloudflareSubscriptionLimits } from "./subscriptions.mjs";
5
5
  import { Context, Crypto, Effect, Layer, Option, Schema, Scope } from "effect";
6
- import { DoStorageFailpoint, DoStorageFailpointHandler, DoStorageInitializationError, 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, 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, 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";
9
9
  import { RunContextPreparation, RunCostEstimator, RunToolAuthorization, RunToolFailureObserver } from "@effect-agent/engine";
10
10
  import { DurableObject, DurableObjectState as DurableObjectState$1, WorkerEnvironment } from "effect-cf";
11
11
  import { CodeExecutor, SandboxImplementation } from "@effect-agent/sandbox";
@@ -349,7 +349,25 @@ declare const layerConfig: (options: CloudflareDurableRuntimeOptions) => Layer.L
349
349
  * Tool, Schema, and model requirements remain visible until satisfied by Layer composition.
350
350
  * Use Layer.unwrap for registration values that need effectful application setup.
351
351
  */
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 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>;
364
+ /**
365
+ * Assemble the durable runtime from already-resolved Agent Bindings.
366
+ * Use `ThreadObject.layer` to compile typed Agent registrations instead.
367
+ * Supply host services through `ThreadObject.make` or `ThreadObject.layerConfig` and
368
+ * the Durable Object context and namespace Layers when composing a custom host.
369
+ */
370
+ declare const layerFromBindings: (bindings: ReadonlyArray<ResolvedBinding>) => Layer.Layer<CloudflareDurableRuntimeServices, DoStorageInitializationError, DurableObjectContext | ThreadObjectNamespace | CloudflareBootstrapServices>;
353
371
  //#endregion
354
372
  //#region src/client.d.ts
355
373
  /** Truncate a diagnostic string to the host protocol's bounded length. */
@@ -503,13 +521,13 @@ declare const encodeUnknownResolutionCommand: (input: UnknownResolutionCommand,
503
521
  readonly author: string;
504
522
  readonly reason: string;
505
523
  readonly resolution: {
524
+ readonly _tag: "SafeToRetry";
525
+ } | {
506
526
  readonly _tag: "CompletedWithResult";
507
527
  readonly result: Schema.Json;
508
528
  readonly isFailure: boolean;
509
529
  } | {
510
530
  readonly _tag: "NeverHappened";
511
- } | {
512
- readonly _tag: "SafeToRetry";
513
531
  } | {
514
532
  readonly _tag: "AbortSubmission";
515
533
  };
@@ -584,14 +602,6 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
584
602
  readonly createdAt: string;
585
603
  readonly deploymentId: string;
586
604
  readonly payload: {
587
- readonly _tag: "SubagentStarted";
588
- readonly runId: string;
589
- readonly toolCallId: string;
590
- readonly childThreadId: string;
591
- readonly childSubmissionId: string;
592
- readonly childReceiptId: string;
593
- readonly childRunId: string;
594
- } | {
595
605
  readonly _tag: "AbortRequested";
596
606
  readonly submissionId: string;
597
607
  readonly author: string;
@@ -801,6 +811,37 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
801
811
  readonly childPrincipal: string;
802
812
  readonly childIdempotencyKey: string;
803
813
  readonly toolCallAllowance?: number | undefined;
814
+ readonly policy?: Schema.Json | undefined;
815
+ readonly budget?: {
816
+ readonly caps: {
817
+ readonly maxTotalChildInvocations?: number | undefined;
818
+ readonly maxConcurrentChildren?: number | undefined;
819
+ readonly maxTurns?: number | undefined;
820
+ readonly maxToolCalls?: number | undefined;
821
+ readonly maxDurationMillis?: number | undefined;
822
+ readonly maxInputTokens?: number | undefined;
823
+ readonly maxOutputTokens?: number | undefined;
824
+ readonly maxCostMicrousd?: number | undefined;
825
+ readonly maxResultBytes?: number | undefined;
826
+ };
827
+ readonly allocation: {
828
+ readonly turns: number;
829
+ readonly toolCalls: number;
830
+ readonly durationMillis: number;
831
+ readonly inputTokens: number;
832
+ readonly outputTokens: number;
833
+ readonly costMicrousd: number;
834
+ readonly resultBytes: number;
835
+ };
836
+ } | undefined;
837
+ } | {
838
+ readonly _tag: "SubagentStarted";
839
+ readonly runId: string;
840
+ readonly toolCallId: string;
841
+ readonly childThreadId: string;
842
+ readonly childSubmissionId: string;
843
+ readonly childReceiptId: string;
844
+ readonly childRunId: string;
804
845
  } | {
805
846
  readonly _tag: "SubagentJoined";
806
847
  readonly runId: string;
@@ -832,6 +873,7 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
832
873
  readonly childInputDigest: string;
833
874
  readonly grantDigest: string;
834
875
  readonly toolCallAllowance?: number | undefined;
876
+ readonly policy?: Schema.Json | undefined;
835
877
  } | {
836
878
  readonly _tag: "RepairAnnotated";
837
879
  readonly reason: string;
@@ -871,13 +913,13 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
871
913
  readonly author: string;
872
914
  readonly reason: string;
873
915
  readonly resolution: {
916
+ readonly _tag: "SafeToRetry";
917
+ } | {
874
918
  readonly _tag: "CompletedWithResult";
875
919
  readonly result: Schema.Json;
876
920
  readonly isFailure: boolean;
877
921
  } | {
878
922
  readonly _tag: "NeverHappened";
879
- } | {
880
- readonly _tag: "SafeToRetry";
881
923
  } | {
882
924
  readonly _tag: "AbortSubmission";
883
925
  };
@@ -887,6 +929,11 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
887
929
  } | {
888
930
  readonly _tag: "HostFailed";
889
931
  readonly failure: {
932
+ readonly _tag: "DurableAlarmError";
933
+ readonly operation: string;
934
+ readonly message: string;
935
+ readonly cause?: Schema.Json | undefined;
936
+ } | {
890
937
  readonly _tag: "AdmissionConflict";
891
938
  readonly threadId: string;
892
939
  readonly principal: string;
@@ -953,11 +1000,6 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
953
1000
  readonly limit: "database-bytes" | "input-bytes" | "queue-depth";
954
1001
  readonly actual: number;
955
1002
  readonly maximum: number;
956
- } | {
957
- readonly _tag: "DurableAlarmError";
958
- readonly operation: string;
959
- readonly message: string;
960
- readonly cause?: Schema.Json | undefined;
961
1003
  } | {
962
1004
  readonly _tag: "OperationDenied";
963
1005
  readonly operation: "abort" | "awaitSettlement" | "explain" | "observe" | "resolveApproval" | "resolveUnknown" | "retry" | "scanObligations" | "verify" | "wake";
@@ -1508,14 +1550,38 @@ declare const encodeAdminResponse: (input: AdminFailed | ExplainedRecovery | Obl
1508
1550
  } | {
1509
1551
  readonly _tag: "AdminFailed";
1510
1552
  readonly failure: {
1511
- readonly _tag: "SettlementConflict";
1553
+ readonly _tag: "OperationDenied";
1554
+ readonly operation: "abort" | "awaitSettlement" | "explain" | "observe" | "resolveApproval" | "resolveUnknown" | "retry" | "scanObligations" | "verify" | "wake";
1555
+ readonly reason: string;
1556
+ readonly threadId?: string | undefined;
1557
+ readonly submissionId?: string | undefined;
1558
+ } | {
1559
+ readonly _tag: "RetryRefused";
1512
1560
  readonly submissionId: string;
1513
- readonly existingOutcome: "aborted" | "completed" | "failed";
1561
+ readonly refusal: "await-approval-decision" | "await-unknown-resolution" | "settled";
1562
+ readonly decisionTag: string;
1563
+ readonly message: string;
1514
1564
  } | {
1515
1565
  readonly _tag: "LedgerError";
1516
1566
  readonly operation: string;
1517
1567
  readonly message: string;
1518
1568
  readonly cause?: Schema.Json | undefined;
1569
+ } | {
1570
+ readonly _tag: "RunJournalError";
1571
+ readonly message: string;
1572
+ readonly cause?: Schema.Json | undefined;
1573
+ } | {
1574
+ readonly _tag: "DigestError";
1575
+ readonly message: string;
1576
+ readonly cause?: Schema.Json | undefined;
1577
+ } | {
1578
+ readonly _tag: "OwnershipLost";
1579
+ readonly submissionId: string;
1580
+ readonly actualEpoch: number;
1581
+ } | {
1582
+ readonly _tag: "SettlementConflict";
1583
+ readonly submissionId: string;
1584
+ readonly existingOutcome: "aborted" | "completed" | "failed";
1519
1585
  } | {
1520
1586
  readonly _tag: "ThreadStoreError";
1521
1587
  readonly operation: string;
@@ -1536,30 +1602,6 @@ declare const encodeAdminResponse: (input: AdminFailed | ExplainedRecovery | Obl
1536
1602
  readonly threadId: string;
1537
1603
  readonly actualEpoch: number;
1538
1604
  readonly attemptedEpoch: number;
1539
- } | {
1540
- readonly _tag: "OperationDenied";
1541
- readonly operation: "abort" | "awaitSettlement" | "explain" | "observe" | "resolveApproval" | "resolveUnknown" | "retry" | "scanObligations" | "verify" | "wake";
1542
- readonly reason: string;
1543
- readonly threadId?: string | undefined;
1544
- readonly submissionId?: string | undefined;
1545
- } | {
1546
- readonly _tag: "RetryRefused";
1547
- readonly submissionId: string;
1548
- readonly refusal: "await-approval-decision" | "await-unknown-resolution" | "settled";
1549
- readonly decisionTag: string;
1550
- readonly message: string;
1551
- } | {
1552
- readonly _tag: "RunJournalError";
1553
- readonly message: string;
1554
- readonly cause?: Schema.Json | undefined;
1555
- } | {
1556
- readonly _tag: "DigestError";
1557
- readonly message: string;
1558
- readonly cause?: Schema.Json | undefined;
1559
- } | {
1560
- readonly _tag: "OwnershipLost";
1561
- readonly submissionId: string;
1562
- readonly actualEpoch: number;
1563
1605
  } | {
1564
1606
  readonly _tag: "DurableRuntimeFailpointError";
1565
1607
  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";
@@ -1650,5 +1692,129 @@ declare const CloudflareCodeMode: {
1650
1692
  }) => Layer.Layer<A, E | HandlerError, Exclude<HandlerRequirements, CodeExecutor> | Exclude<Exclude<R, Handlers>, CodeExecutor>>;
1651
1693
  };
1652
1694
  //#endregion
1653
- 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, 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 };
1695
+ //#region src/memory.d.ts
1696
+ interface MemoryObjectRpc extends Rpc.DurableObjectBranded {
1697
+ memory(encoded: string): Promise<string>;
1698
+ }
1699
+ declare const MemoryObjectNamespace_base: Context.ServiceClass<MemoryObjectNamespace, "@effect-agent/platform-cloudflare/MemoryObjectNamespace", {
1700
+ readonly namespace: DurableObjectNamespace<MemoryObjectRpc>;
1701
+ }>;
1702
+ declare class MemoryObjectNamespace extends MemoryObjectNamespace_base {}
1703
+ /** Namespace version and identity are already canonicalized by MemoryNamespace. */
1704
+ declare const memoryObjectName: (namespace: MemoryNamespace.Any) => string;
1705
+ declare const CloudflareMemoryClient: {
1706
+ /** Bind access and principal using the MemoryObjectNamespace supplied by the application. */
1707
+ make: <Namespace extends MemoryNamespace.Any>(access: MemoryAccess<Namespace>, principal: string & import("effect/Brand").Brand<"@effect-agent/thread/Principal">, rpcLimits?: MemoryRpcLimits | undefined) => Effect.Effect<{
1708
+ recall: (lookup: {
1709
+ readonly _tag: "Found";
1710
+ readonly passages: readonly import("@effect-agent/core").MemoryPassage[];
1711
+ } | {
1712
+ readonly _tag: "NoMatch";
1713
+ } | {
1714
+ readonly _tag: "Unavailable";
1715
+ readonly message: string;
1716
+ } | {
1717
+ readonly _tag: "InsufficientFreshness";
1718
+ readonly message: string;
1719
+ }, 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>;
1720
+ revalidate: (lookup: {
1721
+ readonly _tag: "Found";
1722
+ readonly passages: readonly import("@effect-agent/core").MemoryPassage[];
1723
+ } | {
1724
+ readonly _tag: "NoMatch";
1725
+ } | {
1726
+ readonly _tag: "Unavailable";
1727
+ readonly message: string;
1728
+ } | {
1729
+ readonly _tag: "InsufficientFreshness";
1730
+ readonly message: string;
1731
+ }, limits: MemoryRecallLimits) => Effect.Effect<{
1732
+ readonly _tag: "Found";
1733
+ readonly passages: readonly import("@effect-agent/core").MemoryPassage[];
1734
+ } | {
1735
+ readonly _tag: "NoMatch";
1736
+ } | {
1737
+ readonly _tag: "Unavailable";
1738
+ readonly message: string;
1739
+ } | {
1740
+ readonly _tag: "InsufficientFreshness";
1741
+ readonly message: string;
1742
+ }, 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>;
1743
+ 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>;
1744
+ 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>;
1745
+ }, MemoryRpcError, MemoryObjectNamespace>;
1746
+ /** Use a resolved Worker or Durable Object binding without manual service provisioning. */
1747
+ fromBinding: <Namespace extends MemoryNamespace.Any>(binding: DurableObjectNamespace<MemoryObjectRpc>, options: {
1748
+ readonly access: MemoryAccess<Namespace>;
1749
+ readonly principal: Principal;
1750
+ readonly rpcLimits?: MemoryRpcLimits;
1751
+ }) => Effect.Effect<{
1752
+ recall: (lookup: {
1753
+ readonly _tag: "Found";
1754
+ readonly passages: readonly import("@effect-agent/core").MemoryPassage[];
1755
+ } | {
1756
+ readonly _tag: "NoMatch";
1757
+ } | {
1758
+ readonly _tag: "Unavailable";
1759
+ readonly message: string;
1760
+ } | {
1761
+ readonly _tag: "InsufficientFreshness";
1762
+ readonly message: string;
1763
+ }, 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>;
1764
+ revalidate: (lookup: {
1765
+ readonly _tag: "Found";
1766
+ readonly passages: readonly import("@effect-agent/core").MemoryPassage[];
1767
+ } | {
1768
+ readonly _tag: "NoMatch";
1769
+ } | {
1770
+ readonly _tag: "Unavailable";
1771
+ readonly message: string;
1772
+ } | {
1773
+ readonly _tag: "InsufficientFreshness";
1774
+ readonly message: string;
1775
+ }, limits: MemoryRecallLimits) => Effect.Effect<{
1776
+ readonly _tag: "Found";
1777
+ readonly passages: readonly import("@effect-agent/core").MemoryPassage[];
1778
+ } | {
1779
+ readonly _tag: "NoMatch";
1780
+ } | {
1781
+ readonly _tag: "Unavailable";
1782
+ readonly message: string;
1783
+ } | {
1784
+ readonly _tag: "InsufficientFreshness";
1785
+ readonly message: string;
1786
+ }, 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>;
1787
+ 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>;
1788
+ 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>;
1789
+ }, MemoryRpcError, never>;
1790
+ };
1791
+ /**
1792
+ * Optional activity-processor destination. Keeps domain write errors intact; transport,
1793
+ * authorization and deadline failures become the existing MemoryStorageError contract.
1794
+ * Receipts remain authoritative, including after caller interruption or lost replies.
1795
+ */
1796
+ declare const cloudflareMemoryWriterLayer: (access: MemoryAccess, principal: Principal, limits?: MemoryRpcLimits) => Layer.Layer<MemoryWriter, MemoryRpcError, MemoryObjectNamespace>;
1797
+ type OwnerServices = MemoryReader | MemoryWriter | MemoryOwnerAuthorizer | MemoryOwnerIdentity;
1798
+ interface MemoryObjectInstance extends InstanceType<DurableObject.DurableObjectClass<Record<never, never>, OwnerServices>> {
1799
+ memory(encoded: string): Promise<string>;
1800
+ }
1801
+ interface MemoryObjectClass {
1802
+ new (ctx: globalThis.DurableObjectState, env: Cloudflare.Env): MemoryObjectInstance;
1803
+ }
1804
+ /**
1805
+ * Dedicated SQLite owner, independent of Thread lifetimes. The host binds authorization
1806
+ * after restoring its namespace definition from MemoryOwnerIdentity. Do not retain
1807
+ * cleanup-scoped resources in the host Layer; it lives for the DO incarnation.
1808
+ */
1809
+ declare const makeMemoryObject: <E>(host: Layer.Layer<MemoryOwnerAuthorizer, E, MemoryOwnerIdentity | DurableObjectState$1.DurableObjectState | WorkerEnvironment>, options?: {
1810
+ readonly storageLimits?: DoMemoryStorageLimits;
1811
+ readonly rpcLimits?: MemoryRpcLimits;
1812
+ readonly failpoints?: Layer.Layer<MemoryMutationFailpoint, never, DurableObjectState$1.DurableObjectState>;
1813
+ }) => MemoryObjectClass;
1814
+ declare const MemoryObject: {
1815
+ /** Build the SQLite Durable Object class with the application's owner authorization Layer. */
1816
+ make: typeof makeMemoryObject;
1817
+ };
1818
+ //#endregion
1819
+ 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, layerFromBindings, makeScheduleOwnerObjectClass, makeSubscriptionPartitionObjectClass, memoryObjectName, sourcePartitionName, threadNamespaceFromEnv, threadNamespaceLayer, threadPortTransportLayer, validateCloudflareSubscriptionLimits };
1654
1820
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -4,9 +4,9 @@ import { CloudflareSchedulingClient, ScheduleAlarmProtocolError, ScheduleOwnerId
4
4
  import { CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, SubscriptionAlarmProtocolError, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionProtocolError, makeSubscriptionPartitionObjectClass, sourcePartitionName, validateCloudflareSubscriptionLimits } from "./subscriptions.mjs";
5
5
  import { CloudflareBrowser } from "./browser-quick-action.mjs";
6
6
  import { Clock, Context, Deferred, Duration, Effect, Exit, Fiber, Layer, Option, PubSub, Queue, Ref, Schema, Stream } from "effect";
7
- import { ThreadPortTransport, decodePortRequest, encodePortResponse, executePortRequest, 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, ProducerId, RecoveryExplanation, RecoveryReport, RetryCommand, RetryRefused, RunJournalError, SettlementConflict, SubmissionLedger, SubmissionLookupByKey, ThreadNotMaterialized, ThreadRead, ThreadStore, ThreadStoreError, ToolReconciler, WakeScheduler, compileRegistrations, makeWakeSubscriptionHub, operationAuthorizerLayer } from "@effect-agent/thread";
9
- 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";
10
10
  import { CurrentToolFailureObserver, RunContextPreparationPassthrough, RunToolAuthorization, toolFailureObserverLayer } from "@effect-agent/engine";
11
11
  import { BrowserCrypto } from "@effect/platform-browser";
12
12
  import { SqliteClient } from "@effect/sql-sqlite-do";
@@ -226,7 +226,12 @@ const layerConfig = (options) => Layer.unwrap(Effect.gen(function* () {
226
226
  * Use Layer.unwrap for registration values that need effectful application setup.
227
227
  */
228
228
  const layer = (registrations) => Layer.unwrap(Effect.map(compileRegistrations(registrations), layerFromBindings));
229
- /** Internal assembly shared by registration compilation and low-level adapter fixtures. */
229
+ /**
230
+ * Assemble the durable runtime from already-resolved Agent Bindings.
231
+ * Use `ThreadObject.layer` to compile typed Agent registrations instead.
232
+ * Supply host services through `ThreadObject.make` or `ThreadObject.layerConfig` and
233
+ * the Durable Object context and namespace Layers when composing a custom host.
234
+ */
230
235
  const layerFromBindings = (bindings) => Layer.unwrap(Effect.gen(function* () {
231
236
  const { ctx } = yield* DurableObjectContext;
232
237
  const config = yield* CloudflareDurableRuntimeConfig;
@@ -1203,6 +1208,150 @@ const CloudflareCodeMode = {
1203
1208
  */
1204
1209
  layer: (definition, options) => definition.handlers.pipe(Layer.provide(options.handlers), Layer.provide(dynamicWorkerCodeExecutorLayer(options))) };
1205
1210
  //#endregion
1206
- export { AbortRecorded, AdmissionLimitExceeded, ApprovalRecorded, AwaitProgressRequest, CLOUDFLARE_DATABASE_CAP_BYTES, CLOUDFLARE_RUNTIME_DEFAULTS, CancelProgressRequest, CloudflareAdmissionLimitsValue, CloudflareBindingError, CloudflareBrowser, CloudflareCodeMode, 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 };
1211
+ //#region src/memory.ts
1212
+ var MemoryObjectNamespace = class extends Context.Service()("@effect-agent/platform-cloudflare/MemoryObjectNamespace") {};
1213
+ /** Namespace version and identity are already canonicalized by MemoryNamespace. */
1214
+ const memoryObjectName = (namespace) => namespace.address;
1215
+ /**
1216
+ * Effect-native, host-bound memory client. Recall revalidates the entire admitted lookup
1217
+ * in one RPC and renders it locally. No retries or per-source splitting occur here.
1218
+ * Interrupted callers stop waiting; the owner has its own deadline. A timed-out write
1219
+ * may have committed: reconcile by sending the identical operation ID and command.
1220
+ */
1221
+ const makeMemoryClient = Effect.fn("CloudflareMemoryClient.make")(function* (access, principal, rpcLimits = defaultMemoryRpcLimits) {
1222
+ const validated = yield* Schema.decodeUnknownEffect(MemoryRpcLimits)(rpcLimits).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
1223
+ const bound = yield* Schema.decodeUnknownEffect(MemoryAccess.Wire)(access).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
1224
+ principal = yield* Schema.decodeUnknownEffect(Principal)(principal).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
1225
+ const { namespace } = yield* MemoryObjectNamespace;
1226
+ const call = Effect.fn("CloudflareMemoryClient.call")(function* (request) {
1227
+ const decoded = yield* Schema.decodeUnknownEffect(MemoryOwnerRequest)(request).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
1228
+ const encoded = yield* encodeMemoryWire(MemoryOwnerRequest, decoded, validated.maxRequestBytes);
1229
+ const raw = yield* Effect.tryPromise({
1230
+ try: () => namespace.get(namespace.idFromName(memoryObjectName(bound.namespace))).memory(encoded),
1231
+ catch: () => MemoryRpcError.make({ reason: "unavailable" })
1232
+ });
1233
+ const response = yield* decodeMemoryWire(MemoryOwnerResponse, raw, validated.maxResponseBytes);
1234
+ if (response._tag === "Failed") return yield* response.failure;
1235
+ if (!MemoryNamespace.equals(response.access.namespace, bound.namespace) || response.access.scope !== bound.scope) return yield* MemoryRpcError.make({ reason: "protocol" });
1236
+ return response;
1237
+ });
1238
+ const withinDeadline = (effect, timeoutMillis) => effect.pipe(Effect.timeoutOrElse({
1239
+ duration: timeoutMillis,
1240
+ orElse: () => Effect.fail(MemoryRpcError.make({ reason: "timeout" }))
1241
+ }));
1242
+ const revalidate = Effect.fn("CloudflareMemoryClient.revalidate")(function* (lookup, limits) {
1243
+ limits = yield* Schema.decodeUnknownEffect(MemoryRecallLimits)(limits).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
1244
+ const timeoutMillis = Math.min(validated.timeoutMillis, limits.timeoutMillis);
1245
+ return yield* Effect.gen(function* () {
1246
+ const response = yield* call({
1247
+ _tag: "Revalidate",
1248
+ version: 1,
1249
+ access: bound,
1250
+ principal,
1251
+ lookup,
1252
+ limits,
1253
+ deadlineMillis: (yield* Clock.currentTimeMillis) + timeoutMillis
1254
+ });
1255
+ if (response._tag !== "Lookup") return yield* MemoryRpcError.make({ reason: "protocol" });
1256
+ return response.lookup;
1257
+ }).pipe((effect) => withinDeadline(effect, timeoutMillis));
1258
+ });
1259
+ const change = Effect.fn("CloudflareMemoryClient.change")(function* (write) {
1260
+ if (!MemoryNamespace.equals(write.key.namespace, bound.namespace)) return yield* MemoryRpcError.make({ reason: "denied" });
1261
+ return yield* Effect.gen(function* () {
1262
+ const response = yield* call({
1263
+ _tag: "Change",
1264
+ version: 1,
1265
+ access: bound,
1266
+ principal,
1267
+ write,
1268
+ deadlineMillis: (yield* Clock.currentTimeMillis) + validated.timeoutMillis
1269
+ });
1270
+ if (response._tag !== "Changed" || response.document.key.id !== write.key.id) return yield* MemoryRpcError.make({ reason: "protocol" });
1271
+ return yield* MemoryDocument.restore(access.namespace, response.document);
1272
+ }).pipe((effect) => withinDeadline(effect, validated.timeoutMillis));
1273
+ });
1274
+ const revalidateSemantic = Effect.fn("CloudflareMemoryClient.revalidateSemantic")(function* (found, profile, limits) {
1275
+ return yield* Effect.gen(function* () {
1276
+ const response = yield* call({
1277
+ _tag: "RevalidateSemantic",
1278
+ version: 1,
1279
+ access: bound,
1280
+ principal,
1281
+ found,
1282
+ profile,
1283
+ limits,
1284
+ deadlineMillis: (yield* Clock.currentTimeMillis) + validated.timeoutMillis
1285
+ });
1286
+ if (response._tag !== "Semantic") return yield* MemoryRpcError.make({ reason: "protocol" });
1287
+ return response.result;
1288
+ }).pipe((effect) => withinDeadline(effect, validated.timeoutMillis));
1289
+ });
1290
+ return {
1291
+ recall: Effect.fn("CloudflareMemoryClient.recall")(function* (lookup, limits, estimateTokens) {
1292
+ return yield* Memory.recall([{
1293
+ id: "memory",
1294
+ essential: true,
1295
+ read: revalidate(lookup, limits)
1296
+ }], limits, estimateTokens);
1297
+ }),
1298
+ revalidate,
1299
+ revalidateSemantic,
1300
+ change
1301
+ };
1302
+ });
1303
+ const CloudflareMemoryClient = {
1304
+ /** Bind access and principal using the MemoryObjectNamespace supplied by the application. */
1305
+ make: makeMemoryClient,
1306
+ /** Use a resolved Worker or Durable Object binding without manual service provisioning. */
1307
+ fromBinding: Effect.fn("CloudflareMemoryClient.fromBinding")(function* (binding, options) {
1308
+ return yield* makeMemoryClient(options.access, options.principal, options.rpcLimits).pipe(Effect.provideService(MemoryObjectNamespace, { namespace: binding }));
1309
+ })
1310
+ };
1311
+ /**
1312
+ * Optional activity-processor destination. Keeps domain write errors intact; transport,
1313
+ * authorization and deadline failures become the existing MemoryStorageError contract.
1314
+ * Receipts remain authoritative, including after caller interruption or lost replies.
1315
+ */
1316
+ const cloudflareMemoryWriterLayer = (access, principal, limits = defaultMemoryRpcLimits) => Layer.effect(MemoryWriter, Effect.gen(function* () {
1317
+ const client = yield* CloudflareMemoryClient.make(access, principal, limits);
1318
+ return MemoryWriter.fromAdapter({ change: (write) => client.change(write).pipe(Effect.catchTag("MemoryRpcError", (error) => Effect.fail(MemoryStorageError.make({
1319
+ operation: `memory RPC ${error.reason}`,
1320
+ reason: error.reason === "unavailable" || error.reason === "timeout" ? "unavailable" : "invalid-input"
1321
+ }))), Effect.catchTag([
1322
+ "MemoryRecallError",
1323
+ "MemoryIndexError",
1324
+ "SemanticMemoryError"
1325
+ ], () => Effect.fail(MemoryStorageError.make({
1326
+ operation: "memory RPC response",
1327
+ reason: "corrupt"
1328
+ })))) });
1329
+ }));
1330
+ /**
1331
+ * Dedicated SQLite owner, independent of Thread lifetimes. The host binds authorization
1332
+ * after restoring its namespace definition from MemoryOwnerIdentity. Do not retain
1333
+ * cleanup-scoped resources in the host Layer; it lives for the DO incarnation.
1334
+ */
1335
+ const makeMemoryObject = (host, options = {}) => {
1336
+ const identity = Layer.effect(MemoryOwnerIdentity, Effect.gen(function* () {
1337
+ const state = yield* DurableObjectState.DurableObjectState;
1338
+ const address = yield* Schema.decodeUnknownEffect(MemoryNamespaceAddress)(state.raw.id.name).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "denied" })));
1339
+ return { namespace: MemoryNamespace.Any.make({ address }) };
1340
+ }));
1341
+ const store = Layer.unwrap(Effect.map(DurableObjectState.DurableObjectState, (state) => doMemoryStoreLayerWithFailpoints(state.raw.storage, options.storageLimits ?? defaultDoMemoryStorageLimits))).pipe(Layer.provide(options.failpoints ?? MemoryMutationFailpoint.layer));
1342
+ const application = Layer.merge(store, host).pipe(Layer.provideMerge(identity));
1343
+ const runtime = Layer.effectContext(Effect.gen(function* () {
1344
+ const state = yield* DurableObjectState.DurableObjectState;
1345
+ const scope = yield* Effect.scope;
1346
+ yield* Schema.decodeUnknownEffect(MemoryRpcLimits)(options.rpcLimits ?? defaultMemoryRpcLimits).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
1347
+ return yield* state.blockConcurrencyWhile(Layer.buildWithScope(application, scope));
1348
+ }));
1349
+ return DurableObject.make(runtime, { rpc: { memory: (encoded) => handleMemoryOwnerRequest(encoded, options.rpcLimits) } });
1350
+ };
1351
+ const MemoryObject = {
1352
+ /** Build the SQLite Durable Object class with the application's owner authorization Layer. */
1353
+ make: makeMemoryObject };
1354
+ //#endregion
1355
+ 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, layerFromBindings, makeScheduleOwnerObjectClass, makeSubscriptionPartitionObjectClass, memoryObjectName, sourcePartitionName, threadNamespaceFromEnv, threadNamespaceLayer, threadPortTransportLayer, validateCloudflareSubscriptionLimits };
1207
1356
 
1208
1357
  //# sourceMappingURL=index.mjs.map