@effect-agent/storage-cloudflare 0.1.0-beta.47 → 0.1.0-beta.49

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.
@@ -9,6 +9,8 @@ declare const DoMemoryStorageLimits_base: Schema.Class<DoMemoryStorageLimits, Sc
9
9
  readonly maxStorageBytes: Schema.Int;
10
10
  readonly maxDocuments: Schema.Int;
11
11
  readonly maxReceipts: Schema.Int;
12
+ readonly reservedWithdrawalBytes: Schema.optional<Schema.Natural>;
13
+ readonly reservedWithdrawalReceipts: Schema.optional<Schema.Natural>;
12
14
  }>, {}>;
13
15
  declare class DoMemoryStorageLimits extends DoMemoryStorageLimits_base {}
14
16
  declare const defaultDoMemoryStorageLimits: DoMemoryStorageLimits;
@@ -16,6 +18,9 @@ declare const defaultDoMemoryStorageLimits: DoMemoryStorageLimits;
16
18
  * Local memory only, without Thread tables. Keep one SQL client per owner and pass the
17
19
  * full storage handle: sql-only handles cannot provide atomic receipts and revisions.
18
20
  * Byte limits conservatively count encoded rows, not SQLite page/index overhead.
21
+ * Optional withdrawal reserves default to zero and stay within hard byte/receipt limits.
22
+ * Ordinary Put cannot consume them. Deploy exclusively upgraded writers before relying
23
+ * on reserves; the SQL accounting migration preserves older writers and their receipts.
19
24
  */
20
25
  declare const doMemoryStoreLayerWithFailpoints: (storage: NonNullable<SqliteClient.SqliteClientConfig["storage"]>, limits?: DoMemoryStorageLimits) => Layer.Layer<import("@effect-agent/core/MemoryStore").MemoryReader | import("@effect-agent/core/MemoryStore").MemoryWriter, import("@effect-agent/thread/SqlMemoryStore").SqliteMemoryInitializationError, MemoryMutationFailpoint>;
21
26
  declare const doMemoryStoreLayer: (storage: NonNullable<SqliteClient.SqliteClientConfig["storage"]>, limits?: DoMemoryStorageLimits) => Layer.Layer<import("@effect-agent/core/MemoryStore").MemoryReader | import("@effect-agent/core/MemoryStore").MemoryWriter, import("@effect-agent/thread/SqlMemoryStore").SqliteMemoryInitializationError, never>;
@@ -26,7 +26,9 @@ var DoMemoryStorageLimits = class extends Schema.Class("@effect-agent/storage-cl
26
26
  maxReceipts: Schema.Int.check(Schema.isBetween({
27
27
  minimum: 1,
28
28
  maximum: 1e6
29
- }))
29
+ })),
30
+ reservedWithdrawalBytes: Schema.optional(Schema.Natural),
31
+ reservedWithdrawalReceipts: Schema.optional(Schema.Natural)
30
32
  }) {};
31
33
  const defaultDoMemoryStorageLimits = DoMemoryStorageLimits.make({
32
34
  maxRowBytes: 19e5,
@@ -38,6 +40,9 @@ const defaultDoMemoryStorageLimits = DoMemoryStorageLimits.make({
38
40
  * Local memory only, without Thread tables. Keep one SQL client per owner and pass the
39
41
  * full storage handle: sql-only handles cannot provide atomic receipts and revisions.
40
42
  * Byte limits conservatively count encoded rows, not SQLite page/index overhead.
43
+ * Optional withdrawal reserves default to zero and stay within hard byte/receipt limits.
44
+ * Ordinary Put cannot consume them. Deploy exclusively upgraded writers before relying
45
+ * on reserves; the SQL accounting migration preserves older writers and their receipts.
41
46
  */
42
47
  const doMemoryStoreLayerWithFailpoints = (storage, limits = defaultDoMemoryStorageLimits) => Layer.unwrap(Schema.decodeUnknownEffect(DoMemoryStorageLimits)(limits).pipe(Effect.mapError(() => MemoryStorageError.make({
43
48
  operation: "memory storage limits",
@@ -1 +1 @@
1
- {"version":3,"file":"DoMemoryStore.mjs","names":[],"sources":["../src/DoMemoryStore.ts"],"sourcesContent":["import { MemoryStorageError, MemoryMutationFailpoint } from \"@effect-agent/core/MemoryStore\";\nimport {\n memoryStoreLayerWithFailpoints,\n SqlMemoryLimits,\n} from \"@effect-agent/thread/SqlMemoryStore\";\nimport { SqliteClient } from \"@effect/sql-sqlite-do\";\nimport { Effect, Layer, Schema } from \"effect\";\n\nexport class DoMemoryStorageLimits extends Schema.Class<DoMemoryStorageLimits>(\n \"@effect-agent/storage-cloudflare/DoMemoryStorageLimits\",\n)({\n maxRowBytes: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 1_900_000 })),\n maxStorageBytes: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 536_870_912 })),\n maxDocuments: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100_000 })),\n maxReceipts: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 1_000_000 })),\n}) {}\n\nexport const defaultDoMemoryStorageLimits = DoMemoryStorageLimits.make({\n maxRowBytes: 1_900_000,\n maxStorageBytes: 536_870_912,\n maxDocuments: 10_000,\n maxReceipts: 100_000,\n});\n\n/**\n * Local memory only, without Thread tables. Keep one SQL client per owner and pass the\n * full storage handle: sql-only handles cannot provide atomic receipts and revisions.\n * Byte limits conservatively count encoded rows, not SQLite page/index overhead.\n */\nexport const doMemoryStoreLayerWithFailpoints = (\n storage: NonNullable<SqliteClient.SqliteClientConfig[\"storage\"]>,\n limits: DoMemoryStorageLimits = defaultDoMemoryStorageLimits,\n) =>\n Layer.unwrap(\n Schema.decodeUnknownEffect(DoMemoryStorageLimits)(limits).pipe(\n Effect.mapError(() =>\n MemoryStorageError.make({ operation: \"memory storage limits\", reason: \"invalid-input\" }),\n ),\n Effect.map((validated) =>\n memoryStoreLayerWithFailpoints.pipe(\n Layer.provide(Layer.succeed(SqlMemoryLimits, validated)),\n Layer.provide(SqliteClient.layer({ storage })),\n ),\n ),\n ),\n );\n\nexport const doMemoryStoreLayer = (\n storage: NonNullable<SqliteClient.SqliteClientConfig[\"storage\"]>,\n limits: DoMemoryStorageLimits = defaultDoMemoryStorageLimits,\n) =>\n doMemoryStoreLayerWithFailpoints(storage, limits).pipe(\n Layer.provide(MemoryMutationFailpoint.layer),\n );\n"],"mappings":";;;;;;;;;;;;AAQA,IAAa,wBAAb,cAA2C,OAAO,MAChD,wDACF,CAAC,CAAC;CACA,aAAa,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAG,SAAS;CAAU,CAAC,CAAC;CAClF,iBAAiB,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAG,SAAS;CAAY,CAAC,CAAC;CACxF,cAAc,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAG,SAAS;CAAQ,CAAC,CAAC;CACjF,aAAa,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAG,SAAS;CAAU,CAAC,CAAC;AACpF,CAAC,CAAC,CAAC,CAAC;AAEJ,MAAa,+BAA+B,sBAAsB,KAAK;CACrE,aAAa;CACb,iBAAiB;CACjB,cAAc;CACd,aAAa;AACf,CAAC;;;;;;AAOD,MAAa,oCACX,SACA,SAAgC,iCAEhC,MAAM,OACJ,OAAO,oBAAoB,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC,KACxD,OAAO,eACL,mBAAmB,KAAK;CAAE,WAAW;CAAyB,QAAQ;AAAgB,CAAC,CACzF,GACA,OAAO,KAAK,cACV,+BAA+B,KAC7B,MAAM,QAAQ,MAAM,QAAQ,iBAAiB,SAAS,CAAC,GACvD,MAAM,QAAQ,aAAa,MAAM,EAAE,QAAQ,CAAC,CAAC,CAC/C,CACF,CACF,CACF;AAEF,MAAa,sBACX,SACA,SAAgC,iCAEhC,iCAAiC,SAAS,MAAM,CAAC,CAAC,KAChD,MAAM,QAAQ,wBAAwB,KAAK,CAC7C"}
1
+ {"version":3,"file":"DoMemoryStore.mjs","names":[],"sources":["../src/DoMemoryStore.ts"],"sourcesContent":["import { MemoryStorageError, MemoryMutationFailpoint } from \"@effect-agent/core/MemoryStore\";\nimport {\n memoryStoreLayerWithFailpoints,\n SqlMemoryLimits,\n} from \"@effect-agent/thread/SqlMemoryStore\";\nimport { SqliteClient } from \"@effect/sql-sqlite-do\";\nimport { Effect, Layer, Schema } from \"effect\";\n\nexport class DoMemoryStorageLimits extends Schema.Class<DoMemoryStorageLimits>(\n \"@effect-agent/storage-cloudflare/DoMemoryStorageLimits\",\n)({\n maxRowBytes: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 1_900_000 })),\n maxStorageBytes: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 536_870_912 })),\n maxDocuments: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100_000 })),\n maxReceipts: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 1_000_000 })),\n reservedWithdrawalBytes: Schema.optional(Schema.Natural),\n reservedWithdrawalReceipts: Schema.optional(Schema.Natural),\n}) {}\n\nexport const defaultDoMemoryStorageLimits = DoMemoryStorageLimits.make({\n maxRowBytes: 1_900_000,\n maxStorageBytes: 536_870_912,\n maxDocuments: 10_000,\n maxReceipts: 100_000,\n});\n\n/**\n * Local memory only, without Thread tables. Keep one SQL client per owner and pass the\n * full storage handle: sql-only handles cannot provide atomic receipts and revisions.\n * Byte limits conservatively count encoded rows, not SQLite page/index overhead.\n * Optional withdrawal reserves default to zero and stay within hard byte/receipt limits.\n * Ordinary Put cannot consume them. Deploy exclusively upgraded writers before relying\n * on reserves; the SQL accounting migration preserves older writers and their receipts.\n */\nexport const doMemoryStoreLayerWithFailpoints = (\n storage: NonNullable<SqliteClient.SqliteClientConfig[\"storage\"]>,\n limits: DoMemoryStorageLimits = defaultDoMemoryStorageLimits,\n) =>\n Layer.unwrap(\n Schema.decodeUnknownEffect(DoMemoryStorageLimits)(limits).pipe(\n Effect.mapError(() =>\n MemoryStorageError.make({ operation: \"memory storage limits\", reason: \"invalid-input\" }),\n ),\n Effect.map((validated) =>\n memoryStoreLayerWithFailpoints.pipe(\n Layer.provide(Layer.succeed(SqlMemoryLimits, validated)),\n Layer.provide(SqliteClient.layer({ storage })),\n ),\n ),\n ),\n );\n\nexport const doMemoryStoreLayer = (\n storage: NonNullable<SqliteClient.SqliteClientConfig[\"storage\"]>,\n limits: DoMemoryStorageLimits = defaultDoMemoryStorageLimits,\n) =>\n doMemoryStoreLayerWithFailpoints(storage, limits).pipe(\n Layer.provide(MemoryMutationFailpoint.layer),\n );\n"],"mappings":";;;;;;;;;;;;AAQA,IAAa,wBAAb,cAA2C,OAAO,MAChD,wDACF,CAAC,CAAC;CACA,aAAa,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAG,SAAS;CAAU,CAAC,CAAC;CAClF,iBAAiB,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAG,SAAS;CAAY,CAAC,CAAC;CACxF,cAAc,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAG,SAAS;CAAQ,CAAC,CAAC;CACjF,aAAa,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAG,SAAS;CAAU,CAAC,CAAC;CAClF,yBAAyB,OAAO,SAAS,OAAO,OAAO;CACvD,4BAA4B,OAAO,SAAS,OAAO,OAAO;AAC5D,CAAC,CAAC,CAAC,CAAC;AAEJ,MAAa,+BAA+B,sBAAsB,KAAK;CACrE,aAAa;CACb,iBAAiB;CACjB,cAAc;CACd,aAAa;AACf,CAAC;;;;;;;;;AAUD,MAAa,oCACX,SACA,SAAgC,iCAEhC,MAAM,OACJ,OAAO,oBAAoB,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC,KACxD,OAAO,eACL,mBAAmB,KAAK;CAAE,WAAW;CAAyB,QAAQ;AAAgB,CAAC,CACzF,GACA,OAAO,KAAK,cACV,+BAA+B,KAC7B,MAAM,QAAQ,MAAM,QAAQ,iBAAiB,SAAS,CAAC,GACvD,MAAM,QAAQ,aAAa,MAAM,EAAE,QAAQ,CAAC,CAAC,CAC/C,CACF,CACF,CACF;AAEF,MAAa,sBACX,SACA,SAAgC,iCAEhC,iCAAiC,SAAS,MAAM,CAAC,CAAC,KAChD,MAAM,QAAQ,wBAAwB,KAAK,CAC7C"}
@@ -2,13 +2,13 @@ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { DoStorageConfig } from "./DoStorageConfig.mjs";
3
3
  import { DoLedgerError, DoStorageCorruptionError, DoStorageError } from "./DoStorageError.mjs";
4
4
  import { DoStorageFailpoint } from "./DoStorageFailpoint.mjs";
5
- import { i as storageFailpointLayer, o as decodeRows, r as storageConfigLayer, s as initializeDoJournal } from "./DoThreadStore-D9ebIYPv.mjs";
5
+ import { i as storageFailpointLayer, o as decodeRows, r as storageConfigLayer, s as initializeDoJournal } from "./DoThreadStore-D00TdRAa.mjs";
6
6
  import { SqliteClient } from "@effect/sql-sqlite-do";
7
7
  import { Clock, Context, Crypto, DateTime, Effect, Layer, Option, Schema, Stream } from "effect";
8
8
  import * as SqlClientService from "effect/unstable/sql/SqlClient";
9
9
  import { ApprovalDecision, CanonicalSequence, DefinitionDigests, Digest, PersistedJson, ProducerEpoch, RecordEnvelope, SettlementOutcome } from "@effect-agent/thread/Records";
10
10
  import { EMPTY_TAIL_DIGEST } from "@effect-agent/thread/Digest";
11
- import { AbortCommand, AbortIntent, AdmissionAdmitted, AdmissionConflict, AdmissionNotAdmitted, AdmissionRequest, AdmissionResult, ApprovalConflict, ApprovalDecisionCommand, ApprovalDecisionIntent, AttachChildToReservationRequest, BeginChildBudgetReleaseRequest, ChildAttachmentSnapshot, ChildBudgetReservationRequest, ChildBudgetReservationSnapshot, ChildReservationConflict, ChildReservationStatus, ChildSettledNotification, Claim, ClaimJoiningRequest, ClaimRequest, InputAppliedMarker, JoinSnapshot, JoinedToHost, JoiningClaim, LedgerCapabilities, LedgerError, MarkInputAppliedRequest, MarkJoinedRequest, MarkReadyRequest, MarkUnknownRequest, OwnershipLost, OwnershipRenewal, OwnershipSnapshot, ParentLinkage, QueueSequence, RecoverySnapshot, RecoverySnapshotRequest, ReleaseChildBudgetRequest, ReleaseOwnershipRequest, RenewOwnershipRequest, ReservedChildBudget, ReservedSettlement, RevertJoiningRequest, Settlement, SettlementConflict, SettlementFinalization, SettlementReservation, SettlementReservationSnapshot, SubmissionLedger, SubmissionLookup, SubmissionLookupByKey, SubmissionSnapshot, SubmissionState, SuspendRequest, SuspensionReason, SuspensionSnapshot, UnknownResolution, UnknownResolutionCommand, UnknownResolutionConflict, UnknownResolutionIntent, settlementFailureFromRecord, submissionAbortRecordId } from "@effect-agent/thread/SubmissionLedger";
11
+ import { AbortCommand, AbortIntent, AbortIntentRequest, AdmissionAdmitted, AdmissionConflict, AdmissionNotAdmitted, AdmissionRequest, AdmissionResult, ApprovalConflict, ApprovalDecisionCommand, ApprovalDecisionIntent, AttachChildToReservationRequest, BeginChildBudgetReleaseRequest, ChildAttachmentSnapshot, ChildBudgetReservationRequest, ChildBudgetReservationSnapshot, ChildReservationConflict, ChildReservationStatus, ChildSettledNotification, Claim, ClaimJoiningRequest, ClaimRequest, InputAppliedMarker, JoinSnapshot, JoinedToHost, JoiningClaim, LedgerCapabilities, LedgerError, MarkInputAppliedRequest, MarkJoinedRequest, MarkReadyRequest, MarkUnknownRequest, OwnershipLost, OwnershipRenewal, OwnershipSnapshot, ParentLinkage, QueueSequence, RecoverySnapshot, RecoverySnapshotRequest, ReleaseChildBudgetRequest, ReleaseOwnershipRequest, RenewOwnershipRequest, ReservedChildBudget, ReservedSettlement, RevertJoiningRequest, Settlement, SettlementConflict, SettlementFinalization, SettlementReservation, SettlementReservationSnapshot, SubmissionLedger, SubmissionLookup, SubmissionLookupByKey, SubmissionSnapshot, SubmissionState, SuspendRequest, SuspensionReason, SuspensionSnapshot, UnknownResolution, UnknownResolutionCommand, UnknownResolutionConflict, UnknownResolutionIntent, settlementFailureFromRecord, submissionAbortRecordId } from "@effect-agent/thread/SubmissionLedger";
12
12
  import { BrowserCrypto } from "@effect/platform-browser";
13
13
  //#region src/DoSubmissionLedger.ts
14
14
  var DoSubmissionLedger_exports = /* @__PURE__ */ __exportAll({
@@ -117,6 +117,14 @@ var AbortIntentRow = class extends Schema.Class("AbortIntentRow")({
117
117
  canonical_record_id: Schema.NullOr(BoundedIdentifier)
118
118
  }) {};
119
119
  var MaxQueueSequenceRow = class extends Schema.Class("MaxQueueSequenceRow")({ max_queue_sequence: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)) }) {};
120
+ var AbortIntentLookupRow = class extends Schema.Class("AbortIntentLookupRow")({
121
+ submission_id: BoundedIdentifier,
122
+ abort_submission_id: Schema.NullOr(BoundedIdentifier),
123
+ author: Schema.NullOr(BoundedIdentifier),
124
+ reason: Schema.NullOr(BoundedStoredText),
125
+ requested_at: Schema.NullOr(BoundedTimestamp),
126
+ canonical_record_id: Schema.NullOr(BoundedIdentifier)
127
+ }) {};
120
128
  var CanonicalRecordIdRow = class extends Schema.Class("CanonicalRecordIdRow")({ record_id: BoundedIdentifier }) {};
121
129
  const SUBMISSION_COLUMNS = `
122
130
  submission_id,
@@ -1555,6 +1563,42 @@ const makeServices = Effect.fn("DoSubmissionLedger.makeServices")(function* () {
1555
1563
  })];
1556
1564
  });
1557
1565
  const scanNonterminal = Stream.paginate(void 0, scanPage);
1566
+ const readAbortIntentForSubmission = Effect.fn("DoSubmissionLedger.readAbortIntentForSubmission")(function* (request) {
1567
+ const operation = "ledger read abort intent";
1568
+ const validated = yield* Schema.decodeUnknownEffect(Schema.toType(AbortIntentRequest))(request).pipe(Effect.mapError(internalFailure(operation)));
1569
+ const recordId = submissionAbortRecordId(validated.submissionId);
1570
+ const rows = yield* sql`
1571
+ SELECT
1572
+ submission.submission_id,
1573
+ abort.submission_id AS abort_submission_id,
1574
+ abort.author,
1575
+ abort.reason,
1576
+ abort.requested_at,
1577
+ canonical.record_id AS canonical_record_id
1578
+ FROM effect_agent_submissions AS submission
1579
+ LEFT JOIN effect_agent_abort_intents AS abort
1580
+ ON abort.submission_id = submission.submission_id
1581
+ LEFT JOIN effect_agent_canonical_records AS canonical
1582
+ ON canonical.thread_id = submission.thread_id
1583
+ AND canonical.record_id = ${recordId}
1584
+ WHERE submission.submission_id = ${validated.submissionId}
1585
+ `.pipe(Effect.mapError(sqlFailure(operation)));
1586
+ const decoded = yield* decodeRows(Schema.Array(AbortIntentLookupRow), "effect_agent_abort_intents", validated.submissionId, rows).pipe(Effect.mapError(internalFailure(operation)));
1587
+ if (decoded.length === 0) return yield* LedgerError.make({
1588
+ operation,
1589
+ message: `Unknown submission ${validated.submissionId}.`
1590
+ });
1591
+ if (decoded.length !== 1) return yield* corruptionFailure(operation, "effect_agent_abort_intents", validated.submissionId, "An abort intent lookup returned more than one row.");
1592
+ const row = decoded[0];
1593
+ if (row.abort_submission_id === null) return void 0;
1594
+ return yield* decodeAbortIntent({
1595
+ submissionId: row.abort_submission_id,
1596
+ author: row.author,
1597
+ reason: row.reason,
1598
+ requestedAt: row.requested_at,
1599
+ ...row.canonical_record_id === null ? {} : { canonicalRecordId: row.canonical_record_id }
1600
+ }).pipe(Effect.mapError((error) => corruptionFailure(operation, "effect_agent_abort_intents", validated.submissionId, error.message)));
1601
+ });
1558
1602
  const loadRecoverySnapshot = Effect.fn("DoSubmissionLedger.loadRecoverySnapshot")(function* (request) {
1559
1603
  const operation = "ledger load recovery snapshot";
1560
1604
  const validated = yield* Schema.decodeUnknownEffect(Schema.toType(RecoverySnapshotRequest))(request).pipe(Effect.mapError(internalFailure(operation)));
@@ -1696,7 +1740,8 @@ const makeServices = Effect.fn("DoSubmissionLedger.makeServices")(function* () {
1696
1740
  beginChildBudgetRelease,
1697
1741
  releaseChildBudget,
1698
1742
  scanNonterminal,
1699
- loadRecoverySnapshot
1743
+ loadRecoverySnapshot,
1744
+ readAbortIntent: readAbortIntentForSubmission
1700
1745
  }));
1701
1746
  });
1702
1747
  /**