@effect-agent/platform-cloudflare 0.1.0-beta.40 → 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
@@ -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,18 @@ 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>;
353
364
  //#endregion
354
365
  //#region src/client.d.ts
355
366
  /** Truncate a diagnostic string to the host protocol's bounded length. */
@@ -503,13 +514,13 @@ declare const encodeUnknownResolutionCommand: (input: UnknownResolutionCommand,
503
514
  readonly author: string;
504
515
  readonly reason: string;
505
516
  readonly resolution: {
517
+ readonly _tag: "SafeToRetry";
518
+ } | {
506
519
  readonly _tag: "CompletedWithResult";
507
520
  readonly result: Schema.Json;
508
521
  readonly isFailure: boolean;
509
522
  } | {
510
523
  readonly _tag: "NeverHappened";
511
- } | {
512
- readonly _tag: "SafeToRetry";
513
524
  } | {
514
525
  readonly _tag: "AbortSubmission";
515
526
  };
@@ -584,14 +595,6 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
584
595
  readonly createdAt: string;
585
596
  readonly deploymentId: string;
586
597
  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
598
  readonly _tag: "AbortRequested";
596
599
  readonly submissionId: string;
597
600
  readonly author: string;
@@ -801,6 +804,37 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
801
804
  readonly childPrincipal: string;
802
805
  readonly childIdempotencyKey: string;
803
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;
830
+ } | {
831
+ readonly _tag: "SubagentStarted";
832
+ readonly runId: string;
833
+ readonly toolCallId: string;
834
+ readonly childThreadId: string;
835
+ readonly childSubmissionId: string;
836
+ readonly childReceiptId: string;
837
+ readonly childRunId: string;
804
838
  } | {
805
839
  readonly _tag: "SubagentJoined";
806
840
  readonly runId: string;
@@ -832,6 +866,7 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
832
866
  readonly childInputDigest: string;
833
867
  readonly grantDigest: string;
834
868
  readonly toolCallAllowance?: number | undefined;
869
+ readonly policy?: Schema.Json | undefined;
835
870
  } | {
836
871
  readonly _tag: "RepairAnnotated";
837
872
  readonly reason: string;
@@ -871,13 +906,13 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
871
906
  readonly author: string;
872
907
  readonly reason: string;
873
908
  readonly resolution: {
909
+ readonly _tag: "SafeToRetry";
910
+ } | {
874
911
  readonly _tag: "CompletedWithResult";
875
912
  readonly result: Schema.Json;
876
913
  readonly isFailure: boolean;
877
914
  } | {
878
915
  readonly _tag: "NeverHappened";
879
- } | {
880
- readonly _tag: "SafeToRetry";
881
916
  } | {
882
917
  readonly _tag: "AbortSubmission";
883
918
  };
@@ -926,6 +961,17 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
926
961
  readonly threadId: string;
927
962
  readonly actualEpoch: number;
928
963
  readonly attemptedEpoch: number;
964
+ } | {
965
+ readonly _tag: "DurableAlarmError";
966
+ readonly operation: string;
967
+ readonly message: string;
968
+ readonly cause?: Schema.Json | undefined;
969
+ } | {
970
+ readonly _tag: "OperationDenied";
971
+ readonly operation: "abort" | "awaitSettlement" | "explain" | "observe" | "resolveApproval" | "resolveUnknown" | "retry" | "scanObligations" | "verify" | "wake";
972
+ readonly reason: string;
973
+ readonly threadId?: string | undefined;
974
+ readonly submissionId?: string | undefined;
929
975
  } | {
930
976
  readonly _tag: "HostProtocolError";
931
977
  readonly message: string;
@@ -953,17 +999,6 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
953
999
  readonly limit: "database-bytes" | "input-bytes" | "queue-depth";
954
1000
  readonly actual: number;
955
1001
  readonly maximum: number;
956
- } | {
957
- readonly _tag: "DurableAlarmError";
958
- readonly operation: string;
959
- readonly message: string;
960
- readonly cause?: Schema.Json | undefined;
961
- } | {
962
- readonly _tag: "OperationDenied";
963
- readonly operation: "abort" | "awaitSettlement" | "explain" | "observe" | "resolveApproval" | "resolveUnknown" | "retry" | "scanObligations" | "verify" | "wake";
964
- readonly reason: string;
965
- readonly threadId?: string | undefined;
966
- readonly submissionId?: string | undefined;
967
1002
  };
968
1003
  }, Schema.SchemaError, never>;
969
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>;
@@ -1162,13 +1197,13 @@ declare const encodeAdminResponse: (input: AdminFailed | ExplainedRecovery | Obl
1162
1197
  readonly author: string;
1163
1198
  readonly reason: string;
1164
1199
  readonly resolution: {
1165
- readonly _tag: "SafeToRetry";
1166
- } | {
1167
1200
  readonly _tag: "CompletedWithResult";
1168
1201
  readonly result: Schema.Json;
1169
1202
  readonly isFailure: boolean;
1170
1203
  } | {
1171
1204
  readonly _tag: "NeverHappened";
1205
+ } | {
1206
+ readonly _tag: "SafeToRetry";
1172
1207
  } | {
1173
1208
  readonly _tag: "AbortSubmission";
1174
1209
  };
@@ -1508,14 +1543,38 @@ declare const encodeAdminResponse: (input: AdminFailed | ExplainedRecovery | Obl
1508
1543
  } | {
1509
1544
  readonly _tag: "AdminFailed";
1510
1545
  readonly failure: {
1511
- readonly _tag: "SettlementConflict";
1546
+ readonly _tag: "OperationDenied";
1547
+ readonly operation: "abort" | "awaitSettlement" | "explain" | "observe" | "resolveApproval" | "resolveUnknown" | "retry" | "scanObligations" | "verify" | "wake";
1548
+ readonly reason: string;
1549
+ readonly threadId?: string | undefined;
1550
+ readonly submissionId?: string | undefined;
1551
+ } | {
1552
+ readonly _tag: "RetryRefused";
1512
1553
  readonly submissionId: string;
1513
- readonly existingOutcome: "aborted" | "completed" | "failed";
1554
+ readonly refusal: "await-approval-decision" | "await-unknown-resolution" | "settled";
1555
+ readonly decisionTag: string;
1556
+ readonly message: string;
1514
1557
  } | {
1515
1558
  readonly _tag: "LedgerError";
1516
1559
  readonly operation: string;
1517
1560
  readonly message: string;
1518
1561
  readonly cause?: Schema.Json | undefined;
1562
+ } | {
1563
+ readonly _tag: "RunJournalError";
1564
+ readonly message: string;
1565
+ readonly cause?: Schema.Json | undefined;
1566
+ } | {
1567
+ readonly _tag: "DigestError";
1568
+ readonly message: string;
1569
+ readonly cause?: Schema.Json | undefined;
1570
+ } | {
1571
+ readonly _tag: "OwnershipLost";
1572
+ readonly submissionId: string;
1573
+ readonly actualEpoch: number;
1574
+ } | {
1575
+ readonly _tag: "SettlementConflict";
1576
+ readonly submissionId: string;
1577
+ readonly existingOutcome: "aborted" | "completed" | "failed";
1519
1578
  } | {
1520
1579
  readonly _tag: "ThreadStoreError";
1521
1580
  readonly operation: string;
@@ -1536,30 +1595,6 @@ declare const encodeAdminResponse: (input: AdminFailed | ExplainedRecovery | Obl
1536
1595
  readonly threadId: string;
1537
1596
  readonly actualEpoch: number;
1538
1597
  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
1598
  } | {
1564
1599
  readonly _tag: "DurableRuntimeFailpointError";
1565
1600
  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 +1685,129 @@ declare const CloudflareCodeMode: {
1650
1685
  }) => Layer.Layer<A, E | HandlerError, Exclude<HandlerRequirements, CodeExecutor> | Exclude<Exclude<R, Handlers>, CodeExecutor>>;
1651
1686
  };
1652
1687
  //#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 };
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
+ };
1811
+ //#endregion
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 };
1654
1813
  //# 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";
@@ -1203,6 +1203,150 @@ const CloudflareCodeMode = {
1203
1203
  */
1204
1204
  layer: (definition, options) => definition.handlers.pipe(Layer.provide(options.handlers), Layer.provide(dynamicWorkerCodeExecutorLayer(options))) };
1205
1205
  //#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 };
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 };
1349
+ //#endregion
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 };
1207
1351
 
1208
1352
  //# sourceMappingURL=index.mjs.map