@effect-agent/platform-cloudflare 0.1.0-beta.9 → 0.1.0-beta.91
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/Alarm.d.mts +188 -0
- package/dist/Alarm.mjs +451 -0
- package/dist/Alarm.mjs.map +1 -0
- package/dist/BrowserRestCapture.d.mts +35 -0
- package/dist/BrowserRestCapture.mjs +238 -0
- package/dist/BrowserRestCapture.mjs.map +1 -0
- package/dist/BrowserRestCrawl.d.mts +17 -0
- package/dist/BrowserRestCrawl.mjs +244 -0
- package/dist/BrowserRestCrawl.mjs.map +1 -0
- package/dist/CloudflareAiGateway.d.mts +64 -0
- package/dist/CloudflareAiGateway.mjs +70 -0
- package/dist/CloudflareAiGateway.mjs.map +1 -0
- package/dist/CloudflareBindings.d.mts +115 -0
- package/dist/CloudflareBindings.mjs +113 -0
- package/dist/CloudflareBindings.mjs.map +1 -0
- package/dist/CloudflareBrowser-DV6kya1H.mjs +495 -0
- package/dist/CloudflareBrowser-DV6kya1H.mjs.map +1 -0
- package/dist/CloudflareBrowser-Doe1M7R5.d.mts +80 -0
- package/dist/CloudflareBrowser.d.mts +2 -0
- package/dist/CloudflareBrowser.mjs +2 -0
- package/dist/CloudflareCodeMode.d.mts +44 -0
- package/dist/CloudflareCodeMode.mjs +616 -0
- package/dist/CloudflareCodeMode.mjs.map +1 -0
- package/dist/CloudflareConfig-f3CqTel1.d.mts +101 -0
- package/dist/CloudflareConfig.d.mts +2 -0
- package/dist/CloudflareConfig.mjs +122 -0
- package/dist/CloudflareConfig.mjs.map +1 -0
- package/dist/CloudflareMemory.d.mts +142 -0
- package/dist/CloudflareMemory.mjs +202 -0
- package/dist/CloudflareMemory.mjs.map +1 -0
- package/dist/CloudflareScheduling.d.mts +52 -0
- package/dist/CloudflareScheduling.mjs +396 -0
- package/dist/CloudflareScheduling.mjs.map +1 -0
- package/dist/CloudflareSubscriptions.d.mts +87 -0
- package/dist/CloudflareSubscriptions.mjs +530 -0
- package/dist/CloudflareSubscriptions.mjs.map +1 -0
- package/dist/CloudflareThreadClient.d.mts +1496 -0
- package/dist/CloudflareThreadClient.mjs +382 -0
- package/dist/CloudflareThreadClient.mjs.map +1 -0
- package/dist/InteractiveBrowser-DUE_m12-.d.mts +161 -0
- package/dist/InteractiveBrowser-DupDtfw2.mjs +1169 -0
- package/dist/InteractiveBrowser-DupDtfw2.mjs.map +1 -0
- package/dist/InteractiveBrowser.d.mts +2 -0
- package/dist/InteractiveBrowser.mjs +2 -0
- package/dist/ProtectedBrowser.d.mts +123 -0
- package/dist/ProtectedBrowser.mjs +1135 -0
- package/dist/ProtectedBrowser.mjs.map +1 -0
- package/dist/ThreadObject-CIbmXZCY.d.mts +812 -0
- package/dist/ThreadObject-DvRG0dDz.mjs +835 -0
- package/dist/ThreadObject-DvRG0dDz.mjs.map +1 -0
- package/dist/ThreadObject.d.mts +2 -0
- package/dist/ThreadObject.mjs +3 -0
- package/dist/WakeScheduler.d.mts +23 -0
- package/dist/WakeScheduler.mjs +57 -0
- package/dist/WakeScheduler.mjs.map +1 -0
- package/dist/boundary-BguazVkh.mjs +42 -0
- package/dist/boundary-BguazVkh.mjs.map +1 -0
- package/dist/index.d.mts +13 -1548
- package/dist/index.mjs +13 -1636
- package/dist/prepared-admission-DU0_T-ev.mjs +73 -0
- package/dist/prepared-admission-DU0_T-ev.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/package.json +1 -53
- package/src/Alarm.ts +973 -0
- package/src/BrowserRestCapture.ts +477 -0
- package/src/BrowserRestCrawl.ts +540 -0
- package/src/CloudflareAiGateway.ts +170 -0
- package/src/CloudflareBindings.ts +199 -0
- package/src/CloudflareBrowser.ts +15 -0
- package/src/{code-mode-executor.ts → CloudflareCodeMode.ts} +372 -204
- package/src/{config.ts → CloudflareConfig.ts} +9 -8
- package/src/CloudflareMemory.ts +420 -0
- package/src/CloudflareScheduling.ts +747 -0
- package/src/CloudflareSubscriptions.ts +1041 -0
- package/src/CloudflareThreadClient.ts +809 -0
- package/src/InteractiveBrowser.ts +2354 -0
- package/src/ProtectedBrowser.ts +9 -0
- package/src/ThreadObject.ts +1179 -0
- package/src/{wake-scheduler.ts → WakeScheduler.ts} +32 -26
- package/src/index.ts +12 -23
- package/src/internal/boundary.ts +55 -0
- package/src/internal/browser-quick-action.ts +857 -0
- package/src/internal/browser-session-lifecycle.ts +160 -0
- package/src/internal/layers.ts +751 -0
- package/src/internal/message-delivery.ts +152 -0
- package/src/internal/prepared-admission.ts +116 -0
- package/src/internal/progress-wait.ts +121 -0
- package/src/internal/transport.ts +44 -0
- package/src/protected-browser/binding.ts +313 -0
- package/src/protected-browser/host.ts +344 -0
- package/src/protected-browser/inspect-frame.ts +125 -0
- package/src/protected-browser/native.ts +445 -0
- package/src/protected-browser/policy.ts +821 -0
- package/dist/index.mjs.map +0 -1
- package/src/alarm.ts +0 -334
- package/src/bindings.ts +0 -145
- package/src/client.ts +0 -646
- package/src/conversation-object.ts +0 -768
- package/src/layers.ts +0 -376
- package/src/transport.ts +0 -38
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { Clock, Context, Effect, Layer, Schema } from "effect";
|
|
3
|
+
import { Principal } from "effect-agent/submission-ledger";
|
|
4
|
+
import { DurableObject, DurableObjectState, RpcTargets } from "effect-cf";
|
|
5
|
+
import { defaultDoMemoryStorageLimits, doMemoryStoreLayerWithFailpoints } from "@effect-agent/storage-cloudflare/do-memory-store";
|
|
6
|
+
import { MemoryOwnerIdentity, MemoryOwnerRequest, MemoryOwnerResponse, MemoryRpcError, MemoryRpcLimits, decodeMemoryWire, defaultMemoryRpcLimits, encodeMemoryWire, handleMemoryOwnerRequest } from "@effect-agent/storage-cloudflare/memory-protocol";
|
|
7
|
+
import * as Memory from "effect-agent/memory";
|
|
8
|
+
import * as MemoryNamespace from "effect-agent/memory-namespace";
|
|
9
|
+
import { MemoryNamespaceAddress } from "effect-agent/memory-namespace";
|
|
10
|
+
import { MemoryRecallLimits } from "effect-agent/memory-reference";
|
|
11
|
+
import { MemoryAccess } from "effect-agent/memory-revalidation";
|
|
12
|
+
import { MemoryDocument, MemoryKey, MemoryMutationFailpoint, MemoryStorageError, MemoryWriter } from "effect-agent/memory-store";
|
|
13
|
+
import "effect-agent/semantic-memory-index";
|
|
14
|
+
import "effect-agent/semantic-memory-revalidation";
|
|
15
|
+
//#region src/CloudflareMemory.ts
|
|
16
|
+
var CloudflareMemory_exports = /* @__PURE__ */ __exportAll({
|
|
17
|
+
CloudflareMemoryClient: () => CloudflareMemoryClient,
|
|
18
|
+
MemoryObject: () => MemoryObject,
|
|
19
|
+
MemoryObjectNamespace: () => MemoryObjectNamespace,
|
|
20
|
+
cloudflareMemoryWriterLayer: () => cloudflareMemoryWriterLayer,
|
|
21
|
+
memoryObjectName: () => memoryObjectName
|
|
22
|
+
});
|
|
23
|
+
var MemoryObjectNamespace = class extends Context.Service()("@effect-agent/platform-cloudflare/MemoryObjectNamespace") {};
|
|
24
|
+
/** Namespace version and identity are already canonicalized by MemoryNamespace. */
|
|
25
|
+
const memoryObjectName = (namespace) => namespace.address;
|
|
26
|
+
/**
|
|
27
|
+
* Effect-native, host-bound memory client. Recall revalidates the entire admitted lookup
|
|
28
|
+
* in one RPC and renders it locally. No retries or per-source splitting occur here.
|
|
29
|
+
* Interrupted callers stop waiting; the owner has its own deadline. A timed-out write
|
|
30
|
+
* may have committed: reconcile by sending the identical operation ID and command.
|
|
31
|
+
*/
|
|
32
|
+
const makeMemoryClient = Effect.fn("CloudflareMemoryClient.make")(function* (access, principal, rpcLimits = defaultMemoryRpcLimits) {
|
|
33
|
+
const validated = yield* Schema.decodeEffect(MemoryRpcLimits)(rpcLimits).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
|
|
34
|
+
const bound = yield* Schema.decodeUnknownEffect(MemoryAccess.Wire)(access).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
|
|
35
|
+
principal = yield* Schema.decodeEffect(Principal)(principal).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
|
|
36
|
+
const { namespace } = yield* MemoryObjectNamespace;
|
|
37
|
+
const call = Effect.fn("CloudflareMemoryClient.call")(function* (request) {
|
|
38
|
+
const decoded = yield* Schema.decodeEffect(MemoryOwnerRequest)(request).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
|
|
39
|
+
const encoded = yield* encodeMemoryWire(MemoryOwnerRequest, decoded, validated.maxRequestBytes);
|
|
40
|
+
const unavailable = (cause) => {
|
|
41
|
+
const error = MemoryRpcError.make({ reason: "unavailable" });
|
|
42
|
+
error.cause = cause;
|
|
43
|
+
return error;
|
|
44
|
+
};
|
|
45
|
+
const address = memoryObjectName(bound.namespace);
|
|
46
|
+
const target = yield* RpcTargets.get(namespace, address, () => namespace.get(namespace.idFromName(address))).pipe(Effect.mapError(unavailable));
|
|
47
|
+
const raw = yield* Effect.tryPromise({
|
|
48
|
+
try: () => target.memory(encoded),
|
|
49
|
+
catch: unavailable
|
|
50
|
+
}).pipe(Effect.tapCause(() => RpcTargets.invalidate(target)));
|
|
51
|
+
const response = yield* decodeMemoryWire(MemoryOwnerResponse, raw, validated.maxResponseBytes);
|
|
52
|
+
if (response._tag === "Failed") return yield* response.failure;
|
|
53
|
+
if (!MemoryNamespace.equals(response.access.namespace, bound.namespace) || response.access.scope !== bound.scope) return yield* MemoryRpcError.make({ reason: "protocol" });
|
|
54
|
+
return response;
|
|
55
|
+
});
|
|
56
|
+
const withinDeadline = (effect, timeoutMillis) => effect.pipe(Effect.timeoutOrElse({
|
|
57
|
+
duration: timeoutMillis,
|
|
58
|
+
orElse: () => Effect.fail(MemoryRpcError.make({ reason: "timeout" }))
|
|
59
|
+
}));
|
|
60
|
+
const revalidate = Effect.fn("CloudflareMemoryClient.revalidate")(function* (lookup, limits) {
|
|
61
|
+
limits = yield* Schema.decodeEffect(MemoryRecallLimits)(limits).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
|
|
62
|
+
const timeoutMillis = Math.min(validated.timeoutMillis, limits.timeoutMillis);
|
|
63
|
+
return yield* Effect.gen(function* () {
|
|
64
|
+
const response = yield* call({
|
|
65
|
+
_tag: "Revalidate",
|
|
66
|
+
version: 1,
|
|
67
|
+
access: bound,
|
|
68
|
+
principal,
|
|
69
|
+
lookup,
|
|
70
|
+
limits,
|
|
71
|
+
deadlineMillis: (yield* Clock.currentTimeMillis) + timeoutMillis
|
|
72
|
+
});
|
|
73
|
+
if (response._tag !== "Lookup") return yield* MemoryRpcError.make({ reason: "protocol" });
|
|
74
|
+
return response.lookup;
|
|
75
|
+
}).pipe((effect) => withinDeadline(effect, timeoutMillis));
|
|
76
|
+
});
|
|
77
|
+
const change = Effect.fn("CloudflareMemoryClient.change")(function* (write) {
|
|
78
|
+
if (!MemoryNamespace.equals(write.key.namespace, bound.namespace)) return yield* MemoryRpcError.make({ reason: "denied" });
|
|
79
|
+
return yield* Effect.gen(function* () {
|
|
80
|
+
const response = yield* call({
|
|
81
|
+
_tag: "Change",
|
|
82
|
+
version: 1,
|
|
83
|
+
access: bound,
|
|
84
|
+
principal,
|
|
85
|
+
write,
|
|
86
|
+
deadlineMillis: (yield* Clock.currentTimeMillis) + validated.timeoutMillis
|
|
87
|
+
});
|
|
88
|
+
if (response._tag !== "Changed" || response.document.key.id !== write.key.id) return yield* MemoryRpcError.make({ reason: "protocol" });
|
|
89
|
+
return yield* MemoryDocument.restore(access.namespace, response.document);
|
|
90
|
+
}).pipe((effect) => withinDeadline(effect, validated.timeoutMillis));
|
|
91
|
+
});
|
|
92
|
+
/**
|
|
93
|
+
* Read one exact current document in one owner RPC. Null means absent; withdrawals return
|
|
94
|
+
* tombstones. Denial, unavailable storage and deadlines fail typed, never become absence.
|
|
95
|
+
* Reads begun after an acknowledged write observe it or a later revision. The owner checks
|
|
96
|
+
* exact-key authority and active document scopes; source-dependent provenance policy remains
|
|
97
|
+
* application-owned. No extraction, job draining, embedding, discovery or rendering occurs.
|
|
98
|
+
*/
|
|
99
|
+
const get = Effect.fn("CloudflareMemoryClient.get")(function* (key) {
|
|
100
|
+
const decodedKey = yield* Schema.decodeUnknownEffect(MemoryKey.Wire)(key).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
|
|
101
|
+
if (!MemoryNamespace.equals(decodedKey.namespace, bound.namespace)) return yield* MemoryRpcError.make({ reason: "denied" });
|
|
102
|
+
return yield* Effect.gen(function* () {
|
|
103
|
+
const response = yield* call({
|
|
104
|
+
_tag: "Get",
|
|
105
|
+
version: 1,
|
|
106
|
+
access: bound,
|
|
107
|
+
principal,
|
|
108
|
+
key: decodedKey,
|
|
109
|
+
deadlineMillis: (yield* Clock.currentTimeMillis) + validated.timeoutMillis
|
|
110
|
+
});
|
|
111
|
+
if (response._tag !== "Document" || !MemoryNamespace.equals(response.key.namespace, bound.namespace) || response.key.id !== decodedKey.id) return yield* MemoryRpcError.make({ reason: "protocol" });
|
|
112
|
+
if (response.document === null) return null;
|
|
113
|
+
if (response.document.key.id !== decodedKey.id || response.document.source.id !== decodedKey.id || response.document._tag === "ActiveMemoryDocument" && !response.document.scopes.includes(bound.scope)) return yield* MemoryRpcError.make({ reason: "protocol" });
|
|
114
|
+
yield* encodeMemoryWire(MemoryDocument.Wire, response.document, validated.maxSourceBytes);
|
|
115
|
+
return yield* MemoryDocument.restore(access.namespace, response.document);
|
|
116
|
+
}).pipe((effect) => withinDeadline(effect, validated.timeoutMillis));
|
|
117
|
+
});
|
|
118
|
+
const revalidateSemantic = Effect.fn("CloudflareMemoryClient.revalidateSemantic")(function* (found, profile, limits) {
|
|
119
|
+
return yield* Effect.gen(function* () {
|
|
120
|
+
const response = yield* call({
|
|
121
|
+
_tag: "RevalidateSemantic",
|
|
122
|
+
version: 1,
|
|
123
|
+
access: bound,
|
|
124
|
+
principal,
|
|
125
|
+
found,
|
|
126
|
+
profile,
|
|
127
|
+
limits,
|
|
128
|
+
deadlineMillis: (yield* Clock.currentTimeMillis) + validated.timeoutMillis
|
|
129
|
+
});
|
|
130
|
+
if (response._tag !== "Semantic") return yield* MemoryRpcError.make({ reason: "protocol" });
|
|
131
|
+
return response.result;
|
|
132
|
+
}).pipe((effect) => withinDeadline(effect, validated.timeoutMillis));
|
|
133
|
+
});
|
|
134
|
+
return {
|
|
135
|
+
get,
|
|
136
|
+
recall: Effect.fn("CloudflareMemoryClient.recall")(function* (lookup, limits, estimateTokens) {
|
|
137
|
+
return yield* Memory.recall([{
|
|
138
|
+
id: "memory",
|
|
139
|
+
essential: true,
|
|
140
|
+
read: revalidate(lookup, limits)
|
|
141
|
+
}], limits, estimateTokens);
|
|
142
|
+
}),
|
|
143
|
+
revalidate,
|
|
144
|
+
revalidateSemantic,
|
|
145
|
+
change
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
const CloudflareMemoryClient = {
|
|
149
|
+
/** Bind access and principal using the MemoryObjectNamespace supplied by the application. */
|
|
150
|
+
make: makeMemoryClient,
|
|
151
|
+
/** Use a resolved Worker or Durable Object binding without manual service provisioning. */
|
|
152
|
+
fromBinding: Effect.fn("CloudflareMemoryClient.fromBinding")(function* (binding, options) {
|
|
153
|
+
return yield* makeMemoryClient(options.access, options.principal, options.rpcLimits).pipe(Effect.provideService(MemoryObjectNamespace, { namespace: binding }));
|
|
154
|
+
})
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Optional activity-processor destination. Keeps domain write errors intact; transport,
|
|
158
|
+
* authorization and deadline failures become the existing MemoryStorageError contract.
|
|
159
|
+
* Receipts remain authoritative, including after caller interruption or lost replies.
|
|
160
|
+
*/
|
|
161
|
+
const cloudflareMemoryWriterLayer = (access, principal, limits = defaultMemoryRpcLimits) => Layer.effect(MemoryWriter, Effect.gen(function* () {
|
|
162
|
+
const client = yield* CloudflareMemoryClient.make(access, principal, limits);
|
|
163
|
+
return MemoryWriter.fromAdapter({ change: (write) => client.change(write).pipe(Effect.catchTag("MemoryRpcError", (error) => Effect.fail(MemoryStorageError.make({
|
|
164
|
+
operation: `memory RPC ${error.reason}`,
|
|
165
|
+
reason: error.reason === "unavailable" || error.reason === "timeout" ? "unavailable" : "invalid-input"
|
|
166
|
+
}))), Effect.catchTag([
|
|
167
|
+
"MemoryRecallError",
|
|
168
|
+
"MemoryIndexError",
|
|
169
|
+
"SemanticMemoryError"
|
|
170
|
+
], () => Effect.fail(MemoryStorageError.make({
|
|
171
|
+
operation: "memory RPC response",
|
|
172
|
+
reason: "corrupt"
|
|
173
|
+
})))) });
|
|
174
|
+
}));
|
|
175
|
+
/**
|
|
176
|
+
* Dedicated SQLite owner, independent of Thread lifetimes. The host binds authorization
|
|
177
|
+
* after restoring its namespace definition from MemoryOwnerIdentity. Do not retain
|
|
178
|
+
* cleanup-scoped resources in the host Layer; it lives for the DO incarnation.
|
|
179
|
+
*/
|
|
180
|
+
const makeMemoryObject = (host, options = {}) => {
|
|
181
|
+
const identity = Layer.effect(MemoryOwnerIdentity, Effect.gen(function* () {
|
|
182
|
+
const state = yield* DurableObjectState.DurableObjectState;
|
|
183
|
+
const address = yield* Schema.decodeUnknownEffect(MemoryNamespaceAddress)(state.raw.id.name).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "denied" })));
|
|
184
|
+
return { namespace: MemoryNamespace.Any.make({ address }) };
|
|
185
|
+
}));
|
|
186
|
+
const store = Layer.unwrap(Effect.map(DurableObjectState.DurableObjectState, (state) => doMemoryStoreLayerWithFailpoints(state.raw.storage, options.storageLimits ?? defaultDoMemoryStorageLimits))).pipe(Layer.provide(options.failpoints ?? MemoryMutationFailpoint.layer));
|
|
187
|
+
const application = Layer.merge(store, host).pipe(Layer.provideMerge(identity));
|
|
188
|
+
const runtime = Layer.effectContext(Effect.gen(function* () {
|
|
189
|
+
const state = yield* DurableObjectState.DurableObjectState;
|
|
190
|
+
const scope = yield* Effect.scope;
|
|
191
|
+
yield* Schema.decodeEffect(MemoryRpcLimits)(options.rpcLimits ?? defaultMemoryRpcLimits).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: "protocol" })));
|
|
192
|
+
return yield* state.blockConcurrencyWhile(Layer.buildWithScope(application, scope));
|
|
193
|
+
}));
|
|
194
|
+
return DurableObject.make(runtime, { rpc: { memory: (encoded) => handleMemoryOwnerRequest(encoded, options.rpcLimits) } });
|
|
195
|
+
};
|
|
196
|
+
const MemoryObject = {
|
|
197
|
+
/** Build the SQLite Durable Object class with the application's owner authorization Layer. */
|
|
198
|
+
make: makeMemoryObject };
|
|
199
|
+
//#endregion
|
|
200
|
+
export { CloudflareMemoryClient, MemoryObject, MemoryObjectNamespace, cloudflareMemoryWriterLayer, memoryObjectName, CloudflareMemory_exports as t };
|
|
201
|
+
|
|
202
|
+
//# sourceMappingURL=CloudflareMemory.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudflareMemory.mjs","names":["EffectCfDurableObject"],"sources":["../src/CloudflareMemory.ts"],"sourcesContent":["import {\n type DoMemoryStorageLimits,\n defaultDoMemoryStorageLimits,\n doMemoryStoreLayerWithFailpoints,\n} from \"@effect-agent/storage-cloudflare/do-memory-store\";\nimport {\n type MemoryOwnerAuthorizer,\n decodeMemoryWire,\n defaultMemoryRpcLimits,\n encodeMemoryWire,\n handleMemoryOwnerRequest,\n MemoryOwnerIdentity,\n MemoryOwnerRequest,\n MemoryOwnerResponse,\n MemoryRpcError,\n MemoryRpcLimits,\n type MemoryOwnerFailure,\n} from \"@effect-agent/storage-cloudflare/memory-protocol\";\nimport { Clock, Context, Effect, Layer, Schema } from \"effect\";\nimport * as Memory from \"effect-agent/memory\";\nimport * as MemoryNamespace from \"effect-agent/memory-namespace\";\nimport { MemoryNamespaceAddress } from \"effect-agent/memory-namespace\";\nimport { type MemoryLookup, MemoryRecallLimits } from \"effect-agent/memory-reference\";\nimport { MemoryAccess } from \"effect-agent/memory-revalidation\";\nimport {\n type MemoryReader,\n type MemoryWrite,\n MemoryKey,\n MemoryDocument,\n MemoryMutationFailpoint,\n MemoryStorageError,\n MemoryWriter,\n} from \"effect-agent/memory-store\";\nimport {\n type MemoryIndexSearch,\n type SemanticMemoryProfile,\n} from \"effect-agent/semantic-memory-index\";\nimport { type SemanticCandidateLimits } from \"effect-agent/semantic-memory-revalidation\";\nimport { Principal } from \"effect-agent/submission-ledger\";\nimport {\n DurableObject as EffectCfDurableObject,\n DurableObjectState,\n RpcTargets,\n type WorkerEnvironment,\n} from \"effect-cf\";\n\nexport interface MemoryObjectRpc extends Rpc.DurableObjectBranded {\n memory(encoded: string): Promise<string>;\n}\n\nexport class MemoryObjectNamespace extends Context.Service<\n MemoryObjectNamespace,\n {\n readonly namespace: DurableObjectNamespace<MemoryObjectRpc>;\n }\n>()(\"@effect-agent/platform-cloudflare/MemoryObjectNamespace\") {}\n\n/** Namespace version and identity are already canonicalized by MemoryNamespace. */\nexport const memoryObjectName = (namespace: MemoryNamespace.Any): string => namespace.address;\n\n/**\n * Effect-native, host-bound memory client. Recall revalidates the entire admitted lookup\n * in one RPC and renders it locally. No retries or per-source splitting occur here.\n * Interrupted callers stop waiting; the owner has its own deadline. A timed-out write\n * may have committed: reconcile by sending the identical operation ID and command.\n */\nconst makeMemoryClient = Effect.fn(\"CloudflareMemoryClient.make\")(function* <\n Namespace extends MemoryNamespace.Any,\n>(\n access: MemoryAccess<Namespace>,\n principal: Principal,\n rpcLimits: MemoryRpcLimits = defaultMemoryRpcLimits,\n) {\n const validated = yield* Schema.decodeEffect(MemoryRpcLimits)(rpcLimits).pipe(\n Effect.mapError(() => MemoryRpcError.make({ reason: \"protocol\" })),\n );\n\n const bound = yield* Schema.decodeUnknownEffect(MemoryAccess.Wire)(access).pipe(\n Effect.mapError(() => MemoryRpcError.make({ reason: \"protocol\" })),\n );\n\n principal = yield* Schema.decodeEffect(Principal)(principal).pipe(\n Effect.mapError(() => MemoryRpcError.make({ reason: \"protocol\" })),\n );\n const { namespace } = yield* MemoryObjectNamespace;\n\n const call = Effect.fn(\"CloudflareMemoryClient.call\")(function* (request: MemoryOwnerRequest) {\n const decoded = yield* Schema.decodeEffect(MemoryOwnerRequest)(request).pipe(\n Effect.mapError(() => MemoryRpcError.make({ reason: \"protocol\" })),\n );\n\n const encoded = yield* encodeMemoryWire(MemoryOwnerRequest, decoded, validated.maxRequestBytes);\n\n const unavailable = (cause: unknown) => {\n const error = MemoryRpcError.make({ reason: \"unavailable\" });\n\n error.cause = cause;\n\n return error;\n };\n\n const address = memoryObjectName(bound.namespace);\n\n const target = yield* RpcTargets.get(namespace, address, () =>\n namespace.get(namespace.idFromName(address)),\n ).pipe(Effect.mapError(unavailable));\n\n const raw = yield* Effect.tryPromise({\n try: () => target.memory(encoded),\n catch: unavailable,\n }).pipe(Effect.tapCause(() => RpcTargets.invalidate(target)));\n\n const response = yield* decodeMemoryWire(MemoryOwnerResponse, raw, validated.maxResponseBytes);\n\n if (response._tag === \"Failed\") return yield* response.failure;\n if (\n !MemoryNamespace.equals(response.access.namespace, bound.namespace) ||\n response.access.scope !== bound.scope\n )\n return yield* MemoryRpcError.make({ reason: \"protocol\" });\n\n return response;\n });\n\n const withinDeadline = <A, E, R>(effect: Effect.Effect<A, E, R>, timeoutMillis: number) =>\n effect.pipe(\n Effect.timeoutOrElse({\n duration: timeoutMillis,\n orElse: () => Effect.fail(MemoryRpcError.make({ reason: \"timeout\" })),\n }),\n );\n\n const revalidate = Effect.fn(\"CloudflareMemoryClient.revalidate\")(function* (\n lookup: MemoryLookup,\n limits: MemoryRecallLimits,\n ) {\n limits = yield* Schema.decodeEffect(MemoryRecallLimits)(limits).pipe(\n Effect.mapError(() => MemoryRpcError.make({ reason: \"protocol\" })),\n );\n const timeoutMillis = Math.min(validated.timeoutMillis, limits.timeoutMillis);\n\n return yield* Effect.gen(function* () {\n const response = yield* call({\n _tag: \"Revalidate\",\n version: 1,\n access: bound,\n principal,\n lookup,\n limits,\n deadlineMillis: (yield* Clock.currentTimeMillis) + timeoutMillis,\n });\n\n if (response._tag !== \"Lookup\") return yield* MemoryRpcError.make({ reason: \"protocol\" });\n\n return response.lookup;\n }).pipe((effect) => withinDeadline(effect, timeoutMillis));\n });\n\n const change = Effect.fn(\"CloudflareMemoryClient.change\")(function* (\n write: MemoryWrite<Namespace>,\n ) {\n if (!MemoryNamespace.equals(write.key.namespace, bound.namespace))\n return yield* MemoryRpcError.make({ reason: \"denied\" });\n\n return yield* Effect.gen(function* () {\n const response = yield* call({\n _tag: \"Change\",\n version: 1,\n access: bound,\n principal,\n write,\n deadlineMillis: (yield* Clock.currentTimeMillis) + validated.timeoutMillis,\n });\n\n if (response._tag !== \"Changed\" || response.document.key.id !== write.key.id)\n return yield* MemoryRpcError.make({ reason: \"protocol\" });\n\n return yield* MemoryDocument.restore(access.namespace, response.document);\n }).pipe((effect) => withinDeadline(effect, validated.timeoutMillis));\n });\n\n /**\n * Read one exact current document in one owner RPC. Null means absent; withdrawals return\n * tombstones. Denial, unavailable storage and deadlines fail typed, never become absence.\n * Reads begun after an acknowledged write observe it or a later revision. The owner checks\n * exact-key authority and active document scopes; source-dependent provenance policy remains\n * application-owned. No extraction, job draining, embedding, discovery or rendering occurs.\n */\n const get = Effect.fn(\"CloudflareMemoryClient.get\")(function* (key: MemoryKey<Namespace>) {\n const decodedKey = yield* Schema.decodeUnknownEffect(MemoryKey.Wire)(key).pipe(\n Effect.mapError(() => MemoryRpcError.make({ reason: \"protocol\" })),\n );\n\n if (!MemoryNamespace.equals(decodedKey.namespace, bound.namespace))\n return yield* MemoryRpcError.make({ reason: \"denied\" });\n\n return yield* Effect.gen(function* () {\n const response = yield* call({\n _tag: \"Get\",\n version: 1,\n access: bound,\n principal,\n key: decodedKey,\n deadlineMillis: (yield* Clock.currentTimeMillis) + validated.timeoutMillis,\n });\n\n if (\n response._tag !== \"Document\" ||\n !MemoryNamespace.equals(response.key.namespace, bound.namespace) ||\n response.key.id !== decodedKey.id\n )\n return yield* MemoryRpcError.make({ reason: \"protocol\" });\n if (response.document === null) return null;\n if (\n response.document.key.id !== decodedKey.id ||\n response.document.source.id !== decodedKey.id ||\n (response.document._tag === \"ActiveMemoryDocument\" &&\n !response.document.scopes.includes(bound.scope))\n )\n return yield* MemoryRpcError.make({ reason: \"protocol\" });\n\n yield* encodeMemoryWire(MemoryDocument.Wire, response.document, validated.maxSourceBytes);\n\n return yield* MemoryDocument.restore(access.namespace, response.document);\n }).pipe((effect) => withinDeadline(effect, validated.timeoutMillis));\n });\n\n const revalidateSemantic = Effect.fn(\"CloudflareMemoryClient.revalidateSemantic\")(function* (\n found: MemoryIndexSearch<Namespace>,\n profile: SemanticMemoryProfile,\n limits: SemanticCandidateLimits,\n ) {\n return yield* Effect.gen(function* () {\n const response = yield* call({\n _tag: \"RevalidateSemantic\",\n version: 1,\n access: bound,\n principal,\n found,\n profile,\n limits,\n deadlineMillis: (yield* Clock.currentTimeMillis) + validated.timeoutMillis,\n });\n\n if (response._tag !== \"Semantic\") return yield* MemoryRpcError.make({ reason: \"protocol\" });\n\n return response.result;\n }).pipe((effect) => withinDeadline(effect, validated.timeoutMillis));\n });\n\n /**\n * Revalidate in one owner RPC, then render whole passages within the caller's budget.\n * The bound source is essential: unavailable/stale results and matches that cannot fit\n * fail instead of silently producing empty context. No-match remains successful.\n * The single outcome has sourceId \"memory\". No embedding or candidate search is performed.\n * Use revalidate with Memory.recall for multiple readers sharing one output budget.\n */\n const recall = Effect.fn(\"CloudflareMemoryClient.recall\")(function* (\n lookup: MemoryLookup,\n limits: MemoryRecallLimits,\n estimateTokens?: (text: string) => number,\n ) {\n return yield* Memory.recall(\n [{ id: \"memory\", essential: true, read: revalidate(lookup, limits) }],\n limits,\n estimateTokens,\n );\n });\n\n return { get, recall, revalidate, revalidateSemantic, change };\n});\n\nexport const CloudflareMemoryClient = {\n /** Bind access and principal using the MemoryObjectNamespace supplied by the application. */\n make: makeMemoryClient,\n /** Use a resolved Worker or Durable Object binding without manual service provisioning. */\n fromBinding: Effect.fn(\"CloudflareMemoryClient.fromBinding\")(function* <\n Namespace extends MemoryNamespace.Any,\n >(\n binding: DurableObjectNamespace<MemoryObjectRpc>,\n options: {\n readonly access: MemoryAccess<Namespace>;\n readonly principal: Principal;\n readonly rpcLimits?: MemoryRpcLimits;\n },\n ) {\n return yield* makeMemoryClient(options.access, options.principal, options.rpcLimits).pipe(\n Effect.provideService(MemoryObjectNamespace, { namespace: binding }),\n );\n }),\n};\n\n/**\n * Optional activity-processor destination. Keeps domain write errors intact; transport,\n * authorization and deadline failures become the existing MemoryStorageError contract.\n * Receipts remain authoritative, including after caller interruption or lost replies.\n */\nexport const cloudflareMemoryWriterLayer = (\n access: MemoryAccess,\n principal: Principal,\n limits: MemoryRpcLimits = defaultMemoryRpcLimits,\n) =>\n Layer.effect(\n MemoryWriter,\n Effect.gen(function* () {\n const client = yield* CloudflareMemoryClient.make(access, principal, limits);\n\n return MemoryWriter.fromAdapter({\n change: (write) =>\n client.change(write).pipe(\n Effect.catchTag(\"MemoryRpcError\", (error) =>\n Effect.fail(\n MemoryStorageError.make({\n operation: `memory RPC ${error.reason}`,\n reason:\n error.reason === \"unavailable\" || error.reason === \"timeout\"\n ? \"unavailable\"\n : \"invalid-input\",\n }),\n ),\n ),\n Effect.catchTag([\"MemoryRecallError\", \"MemoryIndexError\", \"SemanticMemoryError\"], () =>\n Effect.fail(\n MemoryStorageError.make({ operation: \"memory RPC response\", reason: \"corrupt\" }),\n ),\n ),\n ),\n });\n }),\n );\n\ntype OwnerServices = MemoryReader | MemoryWriter | MemoryOwnerAuthorizer | MemoryOwnerIdentity;\n\nexport interface MemoryObjectInstance extends InstanceType<\n EffectCfDurableObject.DurableObjectClass<Record<never, never>, OwnerServices>\n> {\n memory(encoded: string): Promise<string>;\n}\n\nexport interface MemoryObjectClass {\n new (ctx: globalThis.DurableObjectState, env: Cloudflare.Env): MemoryObjectInstance;\n}\n\n/**\n * Dedicated SQLite owner, independent of Thread lifetimes. The host binds authorization\n * after restoring its namespace definition from MemoryOwnerIdentity. Do not retain\n * cleanup-scoped resources in the host Layer; it lives for the DO incarnation.\n */\nconst makeMemoryObject = <E>(\n host: Layer.Layer<\n MemoryOwnerAuthorizer,\n E,\n MemoryOwnerIdentity | DurableObjectState.DurableObjectState | WorkerEnvironment\n >,\n options: {\n readonly storageLimits?: DoMemoryStorageLimits;\n readonly rpcLimits?: MemoryRpcLimits;\n readonly failpoints?: Layer.Layer<\n MemoryMutationFailpoint,\n never,\n DurableObjectState.DurableObjectState\n >;\n } = {},\n): MemoryObjectClass => {\n const identity = Layer.effect(\n MemoryOwnerIdentity,\n Effect.gen(function* () {\n const state = yield* DurableObjectState.DurableObjectState;\n\n const address = yield* Schema.decodeUnknownEffect(MemoryNamespaceAddress)(\n state.raw.id.name,\n ).pipe(Effect.mapError(() => MemoryRpcError.make({ reason: \"denied\" })));\n\n return { namespace: MemoryNamespace.Any.make({ address }) };\n }),\n );\n\n const store = Layer.unwrap(\n Effect.map(DurableObjectState.DurableObjectState, (state) =>\n doMemoryStoreLayerWithFailpoints(\n state.raw.storage,\n options.storageLimits ?? defaultDoMemoryStorageLimits,\n ),\n ),\n ).pipe(Layer.provide(options.failpoints ?? MemoryMutationFailpoint.layer));\n\n const application = Layer.merge(store, host).pipe(Layer.provideMerge(identity));\n\n const runtime: Layer.Layer<\n OwnerServices,\n E | MemoryOwnerFailure,\n DurableObjectState.DurableObjectState | WorkerEnvironment\n > = Layer.effectContext(\n Effect.gen(function* () {\n const state = yield* DurableObjectState.DurableObjectState;\n const scope = yield* Effect.scope;\n\n yield* Schema.decodeEffect(MemoryRpcLimits)(options.rpcLimits ?? defaultMemoryRpcLimits).pipe(\n Effect.mapError(() => MemoryRpcError.make({ reason: \"protocol\" })),\n );\n\n return yield* state.blockConcurrencyWhile(Layer.buildWithScope(application, scope));\n }),\n );\n\n const rpc = { memory: (encoded: string) => handleMemoryOwnerRequest(encoded, options.rpcLimits) };\n\n return EffectCfDurableObject.make<\n OwnerServices,\n E | MemoryOwnerFailure,\n never,\n never,\n typeof rpc\n >(runtime, { rpc });\n};\n\nexport const MemoryObject = {\n /** Build the SQLite Durable Object class with the application's owner authorization Layer. */\n make: makeMemoryObject,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAkDA,IAAa,wBAAb,cAA2C,QAAQ,QAKjD,CAAC,CAAC,yDAAyD,CAAC,CAAC,CAAC;;AAGhE,MAAa,oBAAoB,cAA2C,UAAU;;;;;;;AAQtF,MAAM,mBAAmB,OAAO,GAAG,6BAA6B,CAAC,CAAC,WAGhE,QACA,WACA,YAA6B,wBAC7B;CACA,MAAM,YAAY,OAAO,OAAO,aAAa,eAAe,CAAC,CAAC,SAAS,CAAC,CAAC,KACvE,OAAO,eAAe,eAAe,KAAK,EAAE,QAAQ,WAAW,CAAC,CAAC,CACnE;CAEA,MAAM,QAAQ,OAAO,OAAO,oBAAoB,aAAa,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,KACzE,OAAO,eAAe,eAAe,KAAK,EAAE,QAAQ,WAAW,CAAC,CAAC,CACnE;CAEA,YAAY,OAAO,OAAO,aAAa,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,KAC3D,OAAO,eAAe,eAAe,KAAK,EAAE,QAAQ,WAAW,CAAC,CAAC,CACnE;CACA,MAAM,EAAE,cAAc,OAAO;CAE7B,MAAM,OAAO,OAAO,GAAG,6BAA6B,CAAC,CAAC,WAAW,SAA6B;EAC5F,MAAM,UAAU,OAAO,OAAO,aAAa,kBAAkB,CAAC,CAAC,OAAO,CAAC,CAAC,KACtE,OAAO,eAAe,eAAe,KAAK,EAAE,QAAQ,WAAW,CAAC,CAAC,CACnE;EAEA,MAAM,UAAU,OAAO,iBAAiB,oBAAoB,SAAS,UAAU,eAAe;EAE9F,MAAM,eAAe,UAAmB;GACtC,MAAM,QAAQ,eAAe,KAAK,EAAE,QAAQ,cAAc,CAAC;GAE3D,MAAM,QAAQ;GAEd,OAAO;EACT;EAEA,MAAM,UAAU,i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AO,IAAI,mBAAmB,qBAAqB,UACjD,iCACE,MAAM,IAAI,SACV,QAAQ,iBAAiB,4BAC3B,CACF,CACF,CAAC,CAAC,KAAK,MAAM,QAAQ,QAAQ,cAAc,wBAAwB,KAAK,CAAC;CAEzE,MAAM,cAAc,MAAM,MAAM,OAAO,IAAI,CAAC,CAAC,KAAK,MAAM,aAAa,QAAQ,CAAC;CAE9E,MAAM,UAIF,MAAM,cACR,OAAO,IAAI,aAAa;EACtB,MAAM,QAAQ,OAAO,mBAAmB;EACxC,MAAM,QAAQ,OAAO,OAAO;EAE5B,OAAO,OAAO,aAAa,eAAe,CAAC,CAAC,QAAQ,aAAa,sBAAsB,CAAC,CAAC,KACvF,OAAO,eAAe,eAAe,KAAK,EAAE,QAAQ,WAAW,CAAC,CAAC,CACnE;EAEA,OAAO,OAAO,MAAM,sBAAsB,MAAM,eAAe,aAAa,KAAK,CAAC;CACpF,CAAC,CACH;CAIA,OAAOA,cAAsB,KAM3B,SAAS,EAAE,KAAA,EARC,SAAS,YAAoB,yBAAyB,SAAS,QAAQ,SAAS,EAQ/E,EAAE,CAAC;AACpB;AAEA,MAAa,eAAe;;AAE1B,MAAM,iBACR"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ThreadObjectNamespace } from "./CloudflareBindings.mjs";
|
|
2
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
3
|
+
import { DurableObject, DurableObjectAlarm, DurableObjectState as DurableObjectState$1, WorkerEnvironment } from "effect-cf";
|
|
4
|
+
import { DoScheduleAlarmControl } from "@effect-agent/storage-cloudflare/do-schedule-store";
|
|
5
|
+
import { ScheduleAuthorizer, ScheduleFailpointError, ScheduleOwner, ScheduleStorageError, SchedulingLimits } from "effect-agent/schedule";
|
|
6
|
+
import { ScheduleDriver, Scheduling } from "effect-agent/scheduling";
|
|
7
|
+
declare namespace CloudflareScheduling_d_exports {
|
|
8
|
+
export { CloudflareSchedulingClient, ScheduleAlarmProtocolError, ScheduleOwnerIdentity, ScheduleOwnerNamespace, ScheduleOwnerObjectClass, ScheduleOwnerObjectInstance, ScheduleOwnerObjectRpc, ScheduleOwnerProtocolError, makeScheduleOwnerObjectClass, scheduleAlarmHandler };
|
|
9
|
+
}
|
|
10
|
+
declare const ScheduleAlarmProtocolError_base: Schema.Class<ScheduleAlarmProtocolError, Schema.TaggedStruct<"ScheduleAlarmProtocolError", {
|
|
11
|
+
readonly message: Schema.String;
|
|
12
|
+
}>, import("effect/Cause").YieldableError>;
|
|
13
|
+
declare class ScheduleAlarmProtocolError extends ScheduleAlarmProtocolError_base {}
|
|
14
|
+
declare const ScheduleOwnerProtocolError_base: Schema.Class<ScheduleOwnerProtocolError, Schema.TaggedStruct<"ScheduleOwnerProtocolError", {
|
|
15
|
+
readonly message: Schema.String;
|
|
16
|
+
}>, import("effect/Cause").YieldableError>;
|
|
17
|
+
declare class ScheduleOwnerProtocolError extends ScheduleOwnerProtocolError_base {}
|
|
18
|
+
interface ScheduleOwnerObjectRpc extends Rpc.DurableObjectBranded {
|
|
19
|
+
schedule(encoded: unknown): Promise<unknown>;
|
|
20
|
+
}
|
|
21
|
+
declare const ScheduleOwnerNamespace_base: Context.ServiceClass<ScheduleOwnerNamespace, "@effect-agent/platform-cloudflare/ScheduleOwnerNamespace", {
|
|
22
|
+
readonly namespace: DurableObjectNamespace<ScheduleOwnerObjectRpc>;
|
|
23
|
+
}>;
|
|
24
|
+
declare class ScheduleOwnerNamespace extends ScheduleOwnerNamespace_base {}
|
|
25
|
+
/** Provides the same authorized management service as NodeScheduling.layer. */
|
|
26
|
+
declare class CloudflareSchedulingClient {
|
|
27
|
+
static readonly layer: Layer.Layer<Scheduling, never, ScheduleOwnerNamespace>;
|
|
28
|
+
}
|
|
29
|
+
declare const ScheduleOwnerIdentity_base: Context.ServiceClass<ScheduleOwnerIdentity, "@effect-agent/platform-cloudflare/ScheduleOwnerIdentity", {
|
|
30
|
+
readonly owner: ScheduleOwner;
|
|
31
|
+
}>;
|
|
32
|
+
declare class ScheduleOwnerIdentity extends ScheduleOwnerIdentity_base {}
|
|
33
|
+
type ScheduleRuntimeServices = Scheduling | ScheduleDriver | DoScheduleAlarmControl | ScheduleOwnerIdentity | DurableObjectAlarm.DurableObjectAlarm;
|
|
34
|
+
/** @internal The complete native alarm operation, including its event deadline. */
|
|
35
|
+
declare const scheduleAlarmHandler: (limits: SchedulingLimits) => Effect.Effect<void, ScheduleAlarmProtocolError | ScheduleFailpointError | ScheduleStorageError | import("effect/Cause").TimeoutError | DurableObjectAlarm.DurableObjectAlarmError, DoScheduleAlarmControl | DurableObjectAlarm.DurableObjectAlarm | ScheduleDriver | ScheduleOwnerIdentity>;
|
|
36
|
+
interface ScheduleOwnerObjectInstance extends InstanceType<DurableObject.DurableObjectClass<Record<never, never>, ScheduleRuntimeServices>> {
|
|
37
|
+
schedule(encoded: unknown): Promise<unknown>;
|
|
38
|
+
alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void;
|
|
39
|
+
}
|
|
40
|
+
interface ScheduleOwnerObjectClass {
|
|
41
|
+
new (ctx: DurableObjectState, env: Cloudflare.Env): ScheduleOwnerObjectInstance;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The host Layer supplies authorization and routing and is cached for the object incarnation.
|
|
45
|
+
* Cloudflare eviction does not guarantee its finalizers run. Do not acquire resources requiring
|
|
46
|
+
* cleanup in this Layer; acquire them inside scoped `manage` / `prepare` operations instead.
|
|
47
|
+
* Native services belong to effect-cf; the database and alarm runtime remain instance-owned.
|
|
48
|
+
*/
|
|
49
|
+
declare const makeScheduleOwnerObjectClass: <E>(host: Layer.Layer<ScheduleAuthorizer | ThreadObjectNamespace, E, DurableObjectState$1.DurableObjectState | WorkerEnvironment | ScheduleOwnerIdentity>, limits?: SchedulingLimits) => ScheduleOwnerObjectClass;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { CloudflareSchedulingClient, ScheduleAlarmProtocolError, ScheduleOwnerIdentity, ScheduleOwnerNamespace, ScheduleOwnerObjectClass, ScheduleOwnerObjectInstance, ScheduleOwnerObjectRpc, ScheduleOwnerProtocolError, makeScheduleOwnerObjectClass, scheduleAlarmHandler, CloudflareScheduling_d_exports as t };
|
|
52
|
+
//# sourceMappingURL=CloudflareScheduling.d.mts.map
|