@effect-agent/storage-cloudflare 0.1.0-beta.77 → 0.1.0-beta.78

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.
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { Clock, Context, Effect, Schema } from "effect";
3
- import { MemoryConflict, MemoryDocument, MemoryMutationFailure, MemoryOperationConflict, MemoryStorageError, MemoryWithdrawn, MemoryWrite, MemoryWriter } from "@effect-agent/core/MemoryStore";
3
+ import { MemoryConflict, MemoryDocument, MemoryKey, MemoryMutationFailure, MemoryOperationConflict, MemoryReader, MemoryStorageError, MemoryWithdrawn, MemoryWrite, MemoryWriter } from "@effect-agent/core/MemoryStore";
4
4
  import { Principal } from "@effect-agent/thread/SubmissionLedger";
5
5
  import * as MemoryNamespace from "@effect-agent/core/MemoryNamespace";
6
6
  import { MemoryLookup, MemoryRecallError, MemoryRecallLimits } from "@effect-agent/core/MemoryReference";
@@ -68,6 +68,10 @@ const ChangeRequest = Schema.TaggedStruct("Change", {
68
68
  ...RequestFields,
69
69
  write: MemoryWrite.Wire
70
70
  });
71
+ const GetRequest = Schema.TaggedStruct("Get", {
72
+ ...RequestFields,
73
+ key: MemoryKey.Wire
74
+ });
71
75
  const SemanticRequest = Schema.TaggedStruct("RevalidateSemantic", {
72
76
  ...RequestFields,
73
77
  found: MemoryIndexSearch.Wire,
@@ -77,7 +81,8 @@ const SemanticRequest = Schema.TaggedStruct("RevalidateSemantic", {
77
81
  const MemoryOwnerRequest = Schema.Union([
78
82
  RevalidateRequest,
79
83
  ChangeRequest,
80
- SemanticRequest
84
+ SemanticRequest,
85
+ GetRequest
81
86
  ]);
82
87
  const MemoryOwnerFailure = Schema.Union([
83
88
  MemoryRpcError,
@@ -90,22 +95,36 @@ const MemoryOwnerFailure = Schema.Union([
90
95
  MemoryIndexError,
91
96
  SemanticMemoryError
92
97
  ]);
98
+ const LookupResponse = Schema.TaggedStruct("Lookup", {
99
+ access: MemoryAccess.Wire,
100
+ lookup: MemoryLookup
101
+ });
102
+ const ChangedResponse = Schema.TaggedStruct("Changed", {
103
+ access: MemoryAccess.Wire,
104
+ document: MemoryDocument.Wire
105
+ });
106
+ const SemanticResponse = Schema.TaggedStruct("Semantic", {
107
+ access: MemoryAccess.Wire,
108
+ result: SemanticCandidateResult
109
+ });
110
+ const DocumentResponse = Schema.TaggedStruct("Document", {
111
+ access: MemoryAccess.Wire,
112
+ key: MemoryKey.Wire,
113
+ document: Schema.NullOr(MemoryDocument.Wire)
114
+ });
115
+ const FailedResponse = Schema.TaggedStruct("Failed", { failure: MemoryOwnerFailure });
93
116
  const MemoryOwnerResponse = Schema.Union([
94
- Schema.TaggedStruct("Lookup", {
95
- access: MemoryAccess.Wire,
96
- lookup: MemoryLookup
97
- }),
98
- Schema.TaggedStruct("Changed", {
99
- access: MemoryAccess.Wire,
100
- document: MemoryDocument.Wire
101
- }),
102
- Schema.TaggedStruct("Semantic", {
103
- access: MemoryAccess.Wire,
104
- result: SemanticCandidateResult
105
- }),
106
- Schema.TaggedStruct("Failed", { failure: MemoryOwnerFailure })
117
+ LookupResponse,
118
+ ChangedResponse,
119
+ SemanticResponse,
120
+ DocumentResponse,
121
+ FailedResponse
107
122
  ]);
108
- /** Fail-closed application policy. Authorize the namespace, principal, scope, and full command. */
123
+ /**
124
+ * Fail-closed application policy. Authorize the namespace, principal, scope, and full command.
125
+ * Get requires exact-key authority, including application source/provenance checks where needed.
126
+ * Possession of a key or scope is not authorization, including for absent or withdrawn documents.
127
+ */
109
128
  var MemoryOwnerAuthorizer = class extends Context.Service()("@effect-agent/storage-cloudflare/MemoryOwnerAuthorizer") {};
110
129
  /** Canonical namespace derived from this object's idFromName identity, never its request. */
111
130
  var MemoryOwnerIdentity = class extends Context.Service()("@effect-agent/storage-cloudflare/MemoryOwnerIdentity") {};
@@ -120,17 +139,35 @@ const encodeMemoryWire = Effect.fn("encodeMemoryWire")(function* (schema, value,
120
139
  if (encoded.length > maxBytes || memoryWireBytes(encoded) > maxBytes) return yield* MemoryRpcError.make({ reason: "budget" });
121
140
  return encoded;
122
141
  });
123
- /** One local read per distinct candidate source, with no per-document network calls. */
142
+ /** One local read for Get, or per distinct candidate source. No discovery or background work. */
124
143
  const handleMemoryOwnerRequest = Effect.fn("MemoryOwner.handleRequest")(function* (raw, limits = defaultMemoryRpcLimits) {
125
144
  const result = yield* Effect.gen(function* () {
126
145
  limits = yield* Schema.decodeUnknownEffect(MemoryRpcLimits)(limits).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
127
146
  const request = yield* decodeMemoryWire(MemoryOwnerRequest, raw, limits.maxRequestBytes);
128
147
  const { namespace } = yield* MemoryOwnerIdentity;
129
- if (!MemoryNamespace.equals(namespace, request.access.namespace) || request._tag === "Change" && !MemoryNamespace.equals(namespace, request.write.key.namespace) || request._tag === "RevalidateSemantic" && request.found.candidates.some((candidate) => !MemoryNamespace.equals(namespace, candidate.key.namespace))) return yield* MemoryRpcError.make({ reason: "denied" });
148
+ if (!MemoryNamespace.equals(namespace, request.access.namespace) || request._tag === "Get" && !MemoryNamespace.equals(namespace, request.key.namespace) || request._tag === "Change" && !MemoryNamespace.equals(namespace, request.write.key.namespace) || request._tag === "RevalidateSemantic" && request.found.candidates.some((candidate) => !MemoryNamespace.equals(namespace, candidate.key.namespace))) return yield* MemoryRpcError.make({ reason: "denied" });
130
149
  const remaining = Math.min(limits.timeoutMillis, request.deadlineMillis - (yield* Clock.currentTimeMillis));
131
150
  if (remaining <= 0) return yield* MemoryRpcError.make({ reason: "timeout" });
132
151
  return yield* Effect.gen(function* () {
133
152
  yield* (yield* MemoryOwnerAuthorizer).authorize(request);
153
+ if (request._tag === "Get") {
154
+ const current = yield* (yield* MemoryReader).get(request.key);
155
+ const document = current === null ? null : yield* MemoryDocument.restore(namespace, current);
156
+ if (document !== null) {
157
+ if (document.key.id !== request.key.id || document.source.id !== request.key.id) return yield* MemoryStorageError.make({
158
+ operation: "validate memory read identity",
159
+ reason: "corrupt"
160
+ });
161
+ if (document._tag === "ActiveMemoryDocument" && !document.scopes.includes(request.access.scope)) return yield* MemoryRpcError.make({ reason: "denied" });
162
+ yield* encodeMemoryWire(MemoryDocument.Wire, document, limits.maxSourceBytes);
163
+ }
164
+ return {
165
+ _tag: "Document",
166
+ access: request.access,
167
+ key: request.key,
168
+ document
169
+ };
170
+ }
134
171
  if (request._tag === "Change") {
135
172
  const writer = yield* MemoryWriter;
136
173
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryProtocol.mjs","names":[],"sources":["../src/MemoryProtocol.ts"],"sourcesContent":["import * as MemoryNamespace from \"@effect-agent/core/MemoryNamespace\";\nimport {\n MemoryLookup,\n MemoryRecallError,\n MemoryRecallLimits,\n} from \"@effect-agent/core/MemoryReference\";\nimport { MemoryAccess, revalidateMemoryLookup } from \"@effect-agent/core/MemoryRevalidation\";\nimport { type MemoryReader } from \"@effect-agent/core/MemoryStore\";\nimport {\n MemoryConflict,\n MemoryDocument,\n MemoryMutationFailure,\n MemoryOperationConflict,\n MemoryStorageError,\n MemoryWithdrawn,\n MemoryWrite,\n MemoryWriter,\n} from \"@effect-agent/core/MemoryStore\";\nimport {\n MemoryIndexSearch,\n MemoryIndexError,\n SemanticMemoryProfile,\n} from \"@effect-agent/core/SemanticMemoryIndex\";\nimport {\n SemanticMemoryError,\n SemanticCandidateLimits,\n SemanticCandidateResult,\n revalidateSemanticMemoryCandidates,\n} from \"@effect-agent/core/SemanticMemoryRevalidation\";\nimport { Principal } from \"@effect-agent/thread/SubmissionLedger\";\nimport { Clock, Context, Effect, Schema } from \"effect\";\n\nexport class MemoryRpcError extends Schema.TaggedError<MemoryRpcError>()(\"MemoryRpcError\", {\n reason: Schema.Literals([\"denied\", \"protocol\", \"budget\", \"timeout\", \"unavailable\"]),\n}) {}\n\nexport class MemoryRpcLimits extends Schema.Class<MemoryRpcLimits>(\n \"@effect-agent/storage-cloudflare/MemoryRpcLimits\",\n)({\n maxRequestBytes: Schema.Int.check(Schema.isBetween({ minimum: 256, maximum: 4_194_304 })),\n maxResponseBytes: Schema.Int.check(Schema.isBetween({ minimum: 256, maximum: 16_777_216 })),\n maxSourceBytes: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 67_108_864 })),\n maxSources: MemoryRecallLimits.fields.maxSources,\n timeoutMillis: MemoryRecallLimits.fields.timeoutMillis,\n}) {}\n\nexport const defaultMemoryRpcLimits = MemoryRpcLimits.make({\n maxRequestBytes: 1_048_576,\n maxResponseBytes: 4_194_304,\n maxSourceBytes: 16_777_216,\n maxSources: 16,\n timeoutMillis: 10_000,\n});\n\nconst RequestFields = {\n version: Schema.Literal(1),\n access: MemoryAccess.Wire,\n /** Host-authenticated identity, never copied from model input. The owner still authorizes it. */\n principal: Principal,\n deadlineMillis: Schema.Finite.check(Schema.isGreaterThanOrEqualTo(0)),\n};\n\nconst RevalidateRequest = Schema.TaggedStruct(\"Revalidate\", {\n ...RequestFields,\n lookup: MemoryLookup,\n limits: MemoryRecallLimits,\n});\n\nconst ChangeRequest = Schema.TaggedStruct(\"Change\", { ...RequestFields, write: MemoryWrite.Wire });\n\nconst SemanticRequest: Schema.TaggedStruct<\n \"RevalidateSemantic\",\n typeof RequestFields & {\n readonly found: typeof MemoryIndexSearch.Wire;\n readonly profile: typeof SemanticMemoryProfile;\n readonly limits: typeof SemanticCandidateLimits;\n }\n> = Schema.TaggedStruct(\"RevalidateSemantic\", {\n ...RequestFields,\n found: MemoryIndexSearch.Wire,\n profile: SemanticMemoryProfile,\n limits: SemanticCandidateLimits,\n});\n\nexport const MemoryOwnerRequest: Schema.Union<\n [typeof RevalidateRequest, typeof ChangeRequest, typeof SemanticRequest]\n> = Schema.Union([RevalidateRequest, ChangeRequest, SemanticRequest]);\n\nexport type MemoryOwnerRequest = typeof MemoryOwnerRequest.Type;\n\nexport const MemoryOwnerFailure = Schema.Union([\n MemoryRpcError,\n MemoryStorageError,\n MemoryRecallError,\n MemoryConflict,\n MemoryWithdrawn,\n MemoryOperationConflict,\n MemoryMutationFailure,\n MemoryIndexError,\n SemanticMemoryError,\n]);\n\nexport type MemoryOwnerFailure = typeof MemoryOwnerFailure.Type;\n\nexport const MemoryOwnerResponse = Schema.Union([\n Schema.TaggedStruct(\"Lookup\", { access: MemoryAccess.Wire, lookup: MemoryLookup }),\n Schema.TaggedStruct(\"Changed\", { access: MemoryAccess.Wire, document: MemoryDocument.Wire }),\n Schema.TaggedStruct(\"Semantic\", { access: MemoryAccess.Wire, result: SemanticCandidateResult }),\n Schema.TaggedStruct(\"Failed\", { failure: MemoryOwnerFailure }),\n]);\n\nexport type MemoryOwnerResponse = typeof MemoryOwnerResponse.Type;\n\n/** Fail-closed application policy. Authorize the namespace, principal, scope, and full command. */\nexport class MemoryOwnerAuthorizer extends Context.Service<\n MemoryOwnerAuthorizer,\n {\n readonly authorize: (request: MemoryOwnerRequest) => Effect.Effect<void, MemoryRpcError>;\n }\n>()(\"@effect-agent/storage-cloudflare/MemoryOwnerAuthorizer\") {}\n\n/** Canonical namespace derived from this object's idFromName identity, never its request. */\nexport class MemoryOwnerIdentity extends Context.Service<\n MemoryOwnerIdentity,\n {\n readonly namespace: MemoryNamespace.Any;\n }\n>()(\"@effect-agent/storage-cloudflare/MemoryOwnerIdentity\") {}\n\nexport const memoryWireBytes = (text: string): number => new TextEncoder().encode(text).byteLength;\n\nexport const decodeMemoryWire = Effect.fn(\"decodeMemoryWire\")(function* <A, I>(\n schema: Schema.Codec<A, I, never>,\n raw: unknown,\n maxBytes: number,\n) {\n const text = yield* Schema.decodeUnknownEffect(Schema.String)(raw).pipe(\n Effect.mapError(() => MemoryRpcError.make({ reason: \"protocol\" })),\n );\n\n if (text.length > maxBytes || memoryWireBytes(text) > maxBytes)\n return yield* MemoryRpcError.make({ reason: \"budget\" });\n\n return yield* Schema.decodeEffect(Schema.fromJsonString(schema))(text).pipe(\n Effect.mapError(() => MemoryRpcError.make({ reason: \"protocol\" })),\n );\n});\n\nexport const encodeMemoryWire = Effect.fn(\"encodeMemoryWire\")(function* <A, I>(\n schema: Schema.Codec<A, I, never, never>,\n value: A,\n maxBytes: number,\n) {\n const encoded = yield* Schema.encodeEffect(Schema.fromJsonString(schema))(value).pipe(\n Effect.mapError(() => MemoryRpcError.make({ reason: \"protocol\" })),\n );\n\n if (encoded.length > maxBytes || memoryWireBytes(encoded) > maxBytes)\n return yield* MemoryRpcError.make({ reason: \"budget\" });\n\n return encoded;\n});\n\n/** One local read per distinct candidate source, with no per-document network calls. */\nexport const handleMemoryOwnerRequest = Effect.fn(\"MemoryOwner.handleRequest\")(function* (\n raw: unknown,\n limits: MemoryRpcLimits = defaultMemoryRpcLimits,\n): Effect.fn.Return<\n string,\n never,\n MemoryOwnerIdentity | MemoryOwnerAuthorizer | MemoryReader | MemoryWriter\n> {\n const result = yield* Effect.gen(function* (): Effect.fn.Return<\n MemoryOwnerResponse,\n MemoryOwnerFailure,\n MemoryOwnerIdentity | MemoryOwnerAuthorizer | MemoryReader | MemoryWriter\n > {\n limits = yield* Schema.decodeUnknownEffect(MemoryRpcLimits)(limits).pipe(\n Effect.mapError(() => MemoryRpcError.make({ reason: \"protocol\" })),\n );\n const request = yield* decodeMemoryWire(MemoryOwnerRequest, raw, limits.maxRequestBytes);\n const { namespace } = yield* MemoryOwnerIdentity;\n\n if (\n !MemoryNamespace.equals(namespace, request.access.namespace) ||\n (request._tag === \"Change\" &&\n !MemoryNamespace.equals(namespace, request.write.key.namespace)) ||\n (request._tag === \"RevalidateSemantic\" &&\n request.found.candidates.some(\n (candidate) => !MemoryNamespace.equals(namespace, candidate.key.namespace),\n ))\n )\n return yield* MemoryRpcError.make({ reason: \"denied\" });\n\n const remaining = Math.min(\n limits.timeoutMillis,\n request.deadlineMillis - (yield* Clock.currentTimeMillis),\n );\n\n if (remaining <= 0) return yield* MemoryRpcError.make({ reason: \"timeout\" });\n\n return yield* Effect.gen(function* (): Effect.fn.Return<\n MemoryOwnerResponse,\n MemoryOwnerFailure,\n MemoryOwnerAuthorizer | MemoryReader | MemoryWriter\n > {\n const authorizer = yield* MemoryOwnerAuthorizer;\n\n yield* authorizer.authorize(request);\n if (request._tag === \"Change\") {\n const writer = yield* MemoryWriter;\n\n return {\n _tag: \"Changed\",\n access: request.access,\n document: yield* writer.change(request.write),\n };\n }\n if (request._tag === \"RevalidateSemantic\") {\n if (\n new Set(request.found.candidates.map((candidate) => candidate.key.id)).size >\n limits.maxSources\n )\n return yield* MemoryRpcError.make({ reason: \"budget\" });\n\n const result = yield* revalidateSemanticMemoryCandidates(\n request.found,\n request.access,\n request.profile,\n {\n ...request.limits,\n maxSourceBytes: Math.min(\n limits.maxSourceBytes,\n request.limits.maxSourceBytes ?? 16_777_216,\n ),\n maxOutputBytes: Math.min(\n limits.maxResponseBytes,\n request.limits.maxOutputBytes ?? 16_777_216,\n ),\n },\n );\n\n return { _tag: \"Semantic\", access: request.access, result };\n }\n\n const count =\n request.lookup._tag === \"Found\"\n ? new Set(request.lookup.passages.map((passage) => passage.source.id)).size\n : 0;\n\n if (count > Math.min(limits.maxSources, request.limits.maxSources))\n return yield* MemoryRpcError.make({ reason: \"budget\" });\n\n const lookup = yield* revalidateMemoryLookup(request.lookup, request.access, {\n maxSourceBytes: limits.maxSourceBytes,\n maxInputBytes: Math.min(limits.maxSourceBytes, request.limits.maxInputBytes ?? 16_777_216),\n });\n\n return { _tag: \"Lookup\", access: request.access, lookup };\n }).pipe(\n Effect.scoped,\n Effect.timeoutOrElse({\n duration: remaining,\n orElse: () => Effect.fail(MemoryRpcError.make({ reason: \"timeout\" })),\n }),\n );\n }).pipe(\n Effect.flatMap((response) =>\n encodeMemoryWire(MemoryOwnerResponse, response, limits.maxResponseBytes),\n ),\n Effect.result,\n );\n\n if (result._tag === \"Success\") return result.success;\n\n return yield* encodeMemoryWire(\n MemoryOwnerResponse,\n {\n _tag: \"Failed\",\n failure: result.failure,\n },\n limits.maxResponseBytes,\n ).pipe(\n Effect.catch(() =>\n Schema.encodeEffect(Schema.fromJsonString(MemoryOwnerResponse))({\n _tag: \"Failed\",\n failure: MemoryRpcError.make({ reason: \"budget\" }),\n }).pipe(Effect.orDie),\n ),\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,iBAAb,cAAoC,OAAO,YAA4B,CAAC,CAAC,kBAAkB,EACzF,QAAQ,OAAO,SAAS;CAAC;CAAU;CAAY;CAAU;CAAW;AAAa,CAAC,EACpF,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAa,kBAAb,cAAqC,OAAO,MAC1C,kDACF,CAAC,CAAC;CACA,iBAAiB,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAK,SAAS;CAAU,CAAC,CAAC;CACxF,kBAAkB,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAK,SAAS;CAAW,CAAC,CAAC;CAC1F,gBAAgB,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAG,SAAS;CAAW,CAAC,CAAC;CACtF,YAAY,mBAAmB,OAAO;CACtC,eAAe,mBAAmB,OAAO;AAC3C,CAAC,CAAC,CAAC,CAAC;AAEJ,MAAa,yBAAyB,gBAAgB,KAAK;CACzD,iBAAiB;CACjB,kBAAkB;CAClB,gBAAgB;CAChB,YAAY;CACZ,eAAe;AACjB,CAAC;AAED,MAAM,gBAAgB;CACpB,SAAS,OAAO,QAAQ,CAAC;CACzB,QAAQ,aAAa;;CAErB,WAAW;CACX,gBAAgB,OAAO,OAAO,MAAM,OAAO,uBAAuB,CAAC,CAAC;AACtE;AAEA,MAAM,oBAAoB,OAAO,aAAa,cAAc;CAC1D,GAAG;CACH,QAAQ;CACR,QAAQ;AACV,CAAC;AAED,MAAM,gBAAgB,OAAO,aAAa,UAAU;CAAE,GAAG;CAAe,OAAO,YAAY;AAAK,CAAC;AAEjG,MAAM,kBAOF,OAAO,aAAa,sBAAsB;CAC5C,GAAG;CACH,OAAO,kBA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C,CACH;CACF,CAAC,CAAC,CAAC,KACD,OAAO,SAAS,aACd,iBAAiB,qBAAqB,UAAU,OAAO,gBAAgB,CACzE,GACA,OAAO,MACT;CAEA,IAAI,OAAO,SAAS,WAAW,OAAO,OAAO;CAE7C,OAAO,OAAO,iBACZ,qBACA;EACE,MAAM;EACN,SAAS,OAAO;CAClB,GACA,OAAO,gBACT,CAAC,CAAC,KACA,OAAO,YACL,OAAO,aAAa,OAAO,eAAe,mBAAmB,CAAC,CAAC,CAAC;EAC9D,MAAM;EACN,SAAS,eAAe,KAAK,EAAE,QAAQ,SAAS,CAAC;CACnD,CAAC,CAAC,CAAC,KAAK,OAAO,KAAK,CACtB,CACF;AACF,CAAC"}
1
+ {"version":3,"file":"MemoryProtocol.mjs","names":[],"sources":["../src/MemoryProtocol.ts"],"sourcesContent":["import * as MemoryNamespace from \"@effect-agent/core/MemoryNamespace\";\nimport {\n MemoryLookup,\n MemoryRecallError,\n MemoryRecallLimits,\n} from \"@effect-agent/core/MemoryReference\";\nimport { MemoryAccess, revalidateMemoryLookup } from \"@effect-agent/core/MemoryRevalidation\";\nimport {\n MemoryKey,\n MemoryReader,\n MemoryConflict,\n MemoryDocument,\n MemoryMutationFailure,\n MemoryOperationConflict,\n MemoryStorageError,\n MemoryWithdrawn,\n MemoryWrite,\n MemoryWriter,\n} from \"@effect-agent/core/MemoryStore\";\nimport {\n MemoryIndexSearch,\n MemoryIndexError,\n SemanticMemoryProfile,\n} from \"@effect-agent/core/SemanticMemoryIndex\";\nimport {\n SemanticMemoryError,\n SemanticCandidateLimits,\n SemanticCandidateResult,\n revalidateSemanticMemoryCandidates,\n} from \"@effect-agent/core/SemanticMemoryRevalidation\";\nimport { Principal } from \"@effect-agent/thread/SubmissionLedger\";\nimport { Clock, Context, Effect, Schema } from \"effect\";\n\nexport class MemoryRpcError extends Schema.TaggedError<MemoryRpcError>()(\"MemoryRpcError\", {\n reason: Schema.Literals([\"denied\", \"protocol\", \"budget\", \"timeout\", \"unavailable\"]),\n}) {}\n\nexport class MemoryRpcLimits extends Schema.Class<MemoryRpcLimits>(\n \"@effect-agent/storage-cloudflare/MemoryRpcLimits\",\n)({\n maxRequestBytes: Schema.Int.check(Schema.isBetween({ minimum: 256, maximum: 4_194_304 })),\n maxResponseBytes: Schema.Int.check(Schema.isBetween({ minimum: 256, maximum: 16_777_216 })),\n maxSourceBytes: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 67_108_864 })),\n maxSources: MemoryRecallLimits.fields.maxSources,\n timeoutMillis: MemoryRecallLimits.fields.timeoutMillis,\n}) {}\n\nexport const defaultMemoryRpcLimits = MemoryRpcLimits.make({\n maxRequestBytes: 1_048_576,\n maxResponseBytes: 4_194_304,\n maxSourceBytes: 16_777_216,\n maxSources: 16,\n timeoutMillis: 10_000,\n});\n\nconst RequestFields = {\n version: Schema.Literal(1),\n access: MemoryAccess.Wire,\n /** Host-authenticated identity, never copied from model input. The owner still authorizes it. */\n principal: Principal,\n deadlineMillis: Schema.Finite.check(Schema.isGreaterThanOrEqualTo(0)),\n};\n\nconst RevalidateRequest = Schema.TaggedStruct(\"Revalidate\", {\n ...RequestFields,\n lookup: MemoryLookup,\n limits: MemoryRecallLimits,\n});\n\nconst ChangeRequest = Schema.TaggedStruct(\"Change\", { ...RequestFields, write: MemoryWrite.Wire });\n\nconst GetRequest = Schema.TaggedStruct(\"Get\", { ...RequestFields, key: MemoryKey.Wire });\n\nconst SemanticRequest: Schema.TaggedStruct<\n \"RevalidateSemantic\",\n typeof RequestFields & {\n readonly found: typeof MemoryIndexSearch.Wire;\n readonly profile: typeof SemanticMemoryProfile;\n readonly limits: typeof SemanticCandidateLimits;\n }\n> = Schema.TaggedStruct(\"RevalidateSemantic\", {\n ...RequestFields,\n found: MemoryIndexSearch.Wire,\n profile: SemanticMemoryProfile,\n limits: SemanticCandidateLimits,\n});\n\nexport const MemoryOwnerRequest: Schema.Union<\n [typeof RevalidateRequest, typeof ChangeRequest, typeof SemanticRequest, typeof GetRequest]\n> = Schema.Union([RevalidateRequest, ChangeRequest, SemanticRequest, GetRequest]);\n\nexport type MemoryOwnerRequest = typeof MemoryOwnerRequest.Type;\n\nexport const MemoryOwnerFailure = Schema.Union([\n MemoryRpcError,\n MemoryStorageError,\n MemoryRecallError,\n MemoryConflict,\n MemoryWithdrawn,\n MemoryOperationConflict,\n MemoryMutationFailure,\n MemoryIndexError,\n SemanticMemoryError,\n]);\n\nexport type MemoryOwnerFailure = typeof MemoryOwnerFailure.Type;\n\nconst LookupResponse = Schema.TaggedStruct(\"Lookup\", {\n access: MemoryAccess.Wire,\n lookup: MemoryLookup,\n});\n\nconst ChangedResponse = Schema.TaggedStruct(\"Changed\", {\n access: MemoryAccess.Wire,\n document: MemoryDocument.Wire,\n});\n\nconst SemanticResponse = Schema.TaggedStruct(\"Semantic\", {\n access: MemoryAccess.Wire,\n result: SemanticCandidateResult,\n});\n\nconst DocumentResponse = Schema.TaggedStruct(\"Document\", {\n access: MemoryAccess.Wire,\n key: MemoryKey.Wire,\n document: Schema.NullOr(MemoryDocument.Wire),\n});\n\nconst FailedResponse = Schema.TaggedStruct(\"Failed\", { failure: MemoryOwnerFailure });\n\nexport const MemoryOwnerResponse: Schema.Union<\n [\n typeof LookupResponse,\n typeof ChangedResponse,\n typeof SemanticResponse,\n typeof DocumentResponse,\n typeof FailedResponse,\n ]\n> = Schema.Union([\n LookupResponse,\n ChangedResponse,\n SemanticResponse,\n DocumentResponse,\n FailedResponse,\n]);\n\nexport type MemoryOwnerResponse = typeof MemoryOwnerResponse.Type;\n\n/**\n * Fail-closed application policy. Authorize the namespace, principal, scope, and full command.\n * Get requires exact-key authority, including application source/provenance checks where needed.\n * Possession of a key or scope is not authorization, including for absent or withdrawn documents.\n */\nexport class MemoryOwnerAuthorizer extends Context.Service<\n MemoryOwnerAuthorizer,\n {\n readonly authorize: (request: MemoryOwnerRequest) => Effect.Effect<void, MemoryRpcError>;\n }\n>()(\"@effect-agent/storage-cloudflare/MemoryOwnerAuthorizer\") {}\n\n/** Canonical namespace derived from this object's idFromName identity, never its request. */\nexport class MemoryOwnerIdentity extends Context.Service<\n MemoryOwnerIdentity,\n {\n readonly namespace: MemoryNamespace.Any;\n }\n>()(\"@effect-agent/storage-cloudflare/MemoryOwnerIdentity\") {}\n\nexport const memoryWireBytes = (text: string): number => new TextEncoder().encode(text).byteLength;\n\nexport const decodeMemoryWire = Effect.fn(\"decodeMemoryWire\")(function* <A, I>(\n schema: Schema.Codec<A, I, never>,\n raw: unknown,\n maxBytes: number,\n) {\n const text = yield* Schema.decodeUnknownEffect(Schema.String)(raw).pipe(\n Effect.mapError(() => MemoryRpcError.make({ reason: \"protocol\" })),\n );\n\n if (text.length > maxBytes || memoryWireBytes(text) > maxBytes)\n return yield* MemoryRpcError.make({ reason: \"budget\" });\n\n return yield* Schema.decodeEffect(Schema.fromJsonString(schema))(text).pipe(\n Effect.mapError(() => MemoryRpcError.make({ reason: \"protocol\" })),\n );\n});\n\nexport const encodeMemoryWire = Effect.fn(\"encodeMemoryWire\")(function* <A, I>(\n schema: Schema.Codec<A, I, never, never>,\n value: A,\n maxBytes: number,\n) {\n const encoded = yield* Schema.encodeEffect(Schema.fromJsonString(schema))(value).pipe(\n Effect.mapError(() => MemoryRpcError.make({ reason: \"protocol\" })),\n );\n\n if (encoded.length > maxBytes || memoryWireBytes(encoded) > maxBytes)\n return yield* MemoryRpcError.make({ reason: \"budget\" });\n\n return encoded;\n});\n\n/** One local read for Get, or per distinct candidate source. No discovery or background work. */\nexport const handleMemoryOwnerRequest = Effect.fn(\"MemoryOwner.handleRequest\")(function* (\n raw: unknown,\n limits: MemoryRpcLimits = defaultMemoryRpcLimits,\n): Effect.fn.Return<\n string,\n never,\n MemoryOwnerIdentity | MemoryOwnerAuthorizer | MemoryReader | MemoryWriter\n> {\n const result = yield* Effect.gen(function* (): Effect.fn.Return<\n MemoryOwnerResponse,\n MemoryOwnerFailure,\n MemoryOwnerIdentity | MemoryOwnerAuthorizer | MemoryReader | MemoryWriter\n > {\n limits = yield* Schema.decodeUnknownEffect(MemoryRpcLimits)(limits).pipe(\n Effect.mapError(() => MemoryRpcError.make({ reason: \"protocol\" })),\n );\n const request = yield* decodeMemoryWire(MemoryOwnerRequest, raw, limits.maxRequestBytes);\n const { namespace } = yield* MemoryOwnerIdentity;\n\n if (\n !MemoryNamespace.equals(namespace, request.access.namespace) ||\n (request._tag === \"Get\" && !MemoryNamespace.equals(namespace, request.key.namespace)) ||\n (request._tag === \"Change\" &&\n !MemoryNamespace.equals(namespace, request.write.key.namespace)) ||\n (request._tag === \"RevalidateSemantic\" &&\n request.found.candidates.some(\n (candidate) => !MemoryNamespace.equals(namespace, candidate.key.namespace),\n ))\n )\n return yield* MemoryRpcError.make({ reason: \"denied\" });\n\n const remaining = Math.min(\n limits.timeoutMillis,\n request.deadlineMillis - (yield* Clock.currentTimeMillis),\n );\n\n if (remaining <= 0) return yield* MemoryRpcError.make({ reason: \"timeout\" });\n\n return yield* Effect.gen(function* (): Effect.fn.Return<\n MemoryOwnerResponse,\n MemoryOwnerFailure,\n MemoryOwnerAuthorizer | MemoryReader | MemoryWriter\n > {\n const authorizer = yield* MemoryOwnerAuthorizer;\n\n yield* authorizer.authorize(request);\n if (request._tag === \"Get\") {\n const reader = yield* MemoryReader;\n const current = yield* reader.get(request.key);\n\n const document =\n current === null ? null : yield* MemoryDocument.restore(namespace, current);\n\n if (document !== null) {\n if (document.key.id !== request.key.id || document.source.id !== request.key.id)\n return yield* MemoryStorageError.make({\n operation: \"validate memory read identity\",\n reason: \"corrupt\",\n });\n if (\n document._tag === \"ActiveMemoryDocument\" &&\n !document.scopes.includes(request.access.scope)\n )\n return yield* MemoryRpcError.make({ reason: \"denied\" });\n\n yield* encodeMemoryWire(MemoryDocument.Wire, document, limits.maxSourceBytes);\n }\n\n return { _tag: \"Document\", access: request.access, key: request.key, document };\n }\n if (request._tag === \"Change\") {\n const writer = yield* MemoryWriter;\n\n return {\n _tag: \"Changed\",\n access: request.access,\n document: yield* writer.change(request.write),\n };\n }\n if (request._tag === \"RevalidateSemantic\") {\n if (\n new Set(request.found.candidates.map((candidate) => candidate.key.id)).size >\n limits.maxSources\n )\n return yield* MemoryRpcError.make({ reason: \"budget\" });\n\n const result = yield* revalidateSemanticMemoryCandidates(\n request.found,\n request.access,\n request.profile,\n {\n ...request.limits,\n maxSourceBytes: Math.min(\n limits.maxSourceBytes,\n request.limits.maxSourceBytes ?? 16_777_216,\n ),\n maxOutputBytes: Math.min(\n limits.maxResponseBytes,\n request.limits.maxOutputBytes ?? 16_777_216,\n ),\n },\n );\n\n return { _tag: \"Semantic\", access: request.access, result };\n }\n\n const count =\n request.lookup._tag === \"Found\"\n ? new Set(request.lookup.passages.map((passage) => passage.source.id)).size\n : 0;\n\n if (count > Math.min(limits.maxSources, request.limits.maxSources))\n return yield* MemoryRpcError.make({ reason: \"budget\" });\n\n const lookup = yield* revalidateMemoryLookup(request.lookup, request.access, {\n maxSourceBytes: limits.maxSourceBytes,\n maxInputBytes: Math.min(limits.maxSourceBytes, request.limits.maxInputBytes ?? 16_777_216),\n });\n\n return { _tag: \"Lookup\", access: request.access, lookup };\n }).pipe(\n Effect.scoped,\n Effect.timeoutOrElse({\n duration: remaining,\n orElse: () => Effect.fail(MemoryRpcError.make({ reason: \"timeout\" })),\n }),\n );\n }).pipe(\n Effect.flatMap((response) =>\n encodeMemoryWire(MemoryOwnerResponse, response, limits.maxResponseBytes),\n ),\n Effect.result,\n );\n\n if (result._tag === \"Success\") return result.success;\n\n return yield* encodeMemoryWire(\n MemoryOwnerResponse,\n {\n _tag: \"Failed\",\n failure: result.failure,\n },\n limits.maxResponseBytes,\n ).pipe(\n Effect.catch(() =>\n Schema.encodeEffect(Schema.fromJsonString(MemoryOwnerResponse))({\n _tag: \"Failed\",\n failure: MemoryRpcError.make({ reason: \"budget\" }),\n }).pipe(Effect.orDie),\n ),\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAiCA,IAAa,iBAAb,cA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