@effect-agent/platform-cloudflare 0.1.0-beta.80 → 0.1.0-beta.82
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 +4 -3
- package/dist/Alarm.mjs +18 -21
- package/dist/Alarm.mjs.map +1 -1
- package/dist/CloudflareThreadClient.d.mts +28 -28
- package/dist/{ThreadObject-DGkXv41C.mjs → ThreadObject-BpwkEc5E.mjs} +2 -2
- package/dist/{ThreadObject-DGkXv41C.mjs.map → ThreadObject-BpwkEc5E.mjs.map} +1 -1
- package/dist/{ThreadObject-3uDpKfB3.d.mts → ThreadObject-bML6jTHl.d.mts} +30 -30
- package/dist/ThreadObject.d.mts +1 -1
- package/dist/ThreadObject.mjs +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/Alarm.ts +37 -23
|
@@ -8,6 +8,7 @@ import { DurableAgentRuntime, DurableRuntimeConfig, RecoveryReport } from "@effe
|
|
|
8
8
|
import { AdmissionPolicyError, LedgerError, OwnershipLost, SettlementConflict, SubmissionLedger, SubmissionSnapshot } from "@effect-agent/thread/SubmissionLedger";
|
|
9
9
|
import { ThreadProjectionMaintenance } from "@effect-agent/thread/ThreadProjectionMaintenance";
|
|
10
10
|
import { Context, Crypto, Effect, Layer, Option, Schema, Scope } from "effect";
|
|
11
|
+
import { SqlClient } from "effect/unstable/sql/SqlClient";
|
|
11
12
|
import { DurableObject, DurableObjectState as DurableObjectState$1, WorkerEnvironment } from "effect-cf";
|
|
12
13
|
import { DigestError } from "@effect-agent/thread/Digest";
|
|
13
14
|
import { DurableRuntimeFailpoint, DurableRuntimeFailpointError, DurableRuntimeFailpointHandler } from "@effect-agent/thread/DurableFailpoint";
|
|
@@ -23,7 +24,6 @@ import { DoStorageFailpoint, DoStorageFailpointHandler } from "@effect-agent/sto
|
|
|
23
24
|
import { DoStorageInitializationError } from "@effect-agent/storage-cloudflare/DoThreadStore";
|
|
24
25
|
import { MessageDeliveryError, MessageDeliveryStore } from "@effect-agent/thread/MessageDelivery";
|
|
25
26
|
import { ToolReconciler } from "@effect-agent/thread/ToolReconciler";
|
|
26
|
-
import { SqlClient } from "effect/unstable/sql/SqlClient";
|
|
27
27
|
//#region src/internal/progress-wait.d.ts
|
|
28
28
|
declare const ProgressWaitRegistry_base: Context.ServiceClass<ProgressWaitRegistry, "@effect-agent/platform-cloudflare/ProgressWaitRegistry", {
|
|
29
29
|
/** Register a Scope-owned cancellation signal, observing any early cancel tombstone. */
|
|
@@ -348,13 +348,13 @@ declare const encodeAdminResponse: (input: AdminFailed | ExplainedRecovery | Obl
|
|
|
348
348
|
readonly author: string;
|
|
349
349
|
readonly reason: string;
|
|
350
350
|
readonly resolution: {
|
|
351
|
+
readonly _tag: "SafeToRetry";
|
|
352
|
+
} | {
|
|
351
353
|
readonly _tag: "CompletedWithResult";
|
|
352
354
|
readonly result: Schema.Json;
|
|
353
355
|
readonly isFailure: boolean;
|
|
354
356
|
} | {
|
|
355
357
|
readonly _tag: "NeverHappened";
|
|
356
|
-
} | {
|
|
357
|
-
readonly _tag: "SafeToRetry";
|
|
358
358
|
} | {
|
|
359
359
|
readonly _tag: "AbortSubmission";
|
|
360
360
|
};
|
|
@@ -694,22 +694,26 @@ declare const encodeAdminResponse: (input: AdminFailed | ExplainedRecovery | Obl
|
|
|
694
694
|
} | {
|
|
695
695
|
readonly _tag: "AdminFailed";
|
|
696
696
|
readonly failure: {
|
|
697
|
-
readonly _tag: "
|
|
697
|
+
readonly _tag: "AdmissionPolicyError";
|
|
698
|
+
readonly reason: "occupied" | "refused" | "unavailable";
|
|
699
|
+
readonly code: string;
|
|
700
|
+
} | {
|
|
701
|
+
readonly _tag: "SettlementConflict";
|
|
702
|
+
readonly submissionId: string;
|
|
703
|
+
readonly existingOutcome: "aborted" | "completed" | "failed";
|
|
704
|
+
} | {
|
|
705
|
+
readonly _tag: "LedgerError";
|
|
698
706
|
readonly operation: string;
|
|
699
707
|
readonly message: string;
|
|
700
708
|
readonly cause?: Schema.Json | undefined;
|
|
701
709
|
} | {
|
|
702
|
-
readonly _tag: "
|
|
703
|
-
readonly message: string;
|
|
704
|
-
} | {
|
|
705
|
-
readonly _tag: "LedgerError";
|
|
710
|
+
readonly _tag: "ThreadStoreError";
|
|
706
711
|
readonly operation: string;
|
|
707
712
|
readonly message: string;
|
|
708
713
|
readonly cause?: Schema.Json | undefined;
|
|
709
714
|
} | {
|
|
710
|
-
readonly _tag: "
|
|
711
|
-
readonly
|
|
712
|
-
readonly code: string;
|
|
715
|
+
readonly _tag: "ThreadNotMaterialized";
|
|
716
|
+
readonly threadId: string;
|
|
713
717
|
} | {
|
|
714
718
|
readonly _tag: "AppendConflict";
|
|
715
719
|
readonly threadId: string;
|
|
@@ -717,26 +721,11 @@ declare const encodeAdminResponse: (input: AdminFailed | ExplainedRecovery | Obl
|
|
|
717
721
|
readonly reason: "batch-digest" | "record-identity" | "tail";
|
|
718
722
|
readonly actualTailSequence?: number | undefined;
|
|
719
723
|
readonly actualTailDigest?: string | undefined;
|
|
720
|
-
} | {
|
|
721
|
-
readonly _tag: "DigestError";
|
|
722
|
-
readonly message: string;
|
|
723
|
-
readonly cause?: Schema.Json | undefined;
|
|
724
|
-
} | {
|
|
725
|
-
readonly _tag: "DurableRuntimeFailpointError";
|
|
726
|
-
readonly location: "abort:after-intent" | "approval:after-request-append" | "approval:after-suspend" | "checkpoint:after-save" | "checkpoint:before-save" | "claim:after-claim" | "compaction:after-canonical-append" | "compaction:before-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" | "subagent:before-join-append" | "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" | "worker:after-completion-append" | "worker:after-origin-append" | "worker:after-report-append" | "worker:after-report-delivery" | "worker:after-source-append" | "worker:after-subtree-append" | "worker:before-completion-append" | "worker:before-origin-append" | "worker:before-report-append" | "worker:before-report-delivery" | "worker:before-source-append" | "worker:before-subtree-append";
|
|
727
724
|
} | {
|
|
728
725
|
readonly _tag: "FenceRejected";
|
|
729
726
|
readonly threadId: string;
|
|
730
727
|
readonly actualEpoch: number;
|
|
731
728
|
readonly attemptedEpoch: number;
|
|
732
|
-
} | {
|
|
733
|
-
readonly _tag: "ThreadNotMaterialized";
|
|
734
|
-
readonly threadId: string;
|
|
735
|
-
} | {
|
|
736
|
-
readonly _tag: "ThreadStoreError";
|
|
737
|
-
readonly operation: string;
|
|
738
|
-
readonly message: string;
|
|
739
|
-
readonly cause?: Schema.Json | undefined;
|
|
740
729
|
} | {
|
|
741
730
|
readonly _tag: "OperationDenied";
|
|
742
731
|
readonly operation: "abort" | "awaitSettlement" | "explain" | "observe" | "resolveApproval" | "resolveUnknown" | "retry" | "scanObligations" | "verify" | "wake";
|
|
@@ -744,9 +733,12 @@ declare const encodeAdminResponse: (input: AdminFailed | ExplainedRecovery | Obl
|
|
|
744
733
|
readonly threadId?: string | undefined;
|
|
745
734
|
readonly submissionId?: string | undefined;
|
|
746
735
|
} | {
|
|
747
|
-
readonly _tag: "
|
|
748
|
-
readonly
|
|
749
|
-
readonly
|
|
736
|
+
readonly _tag: "DigestError";
|
|
737
|
+
readonly message: string;
|
|
738
|
+
readonly cause?: Schema.Json | undefined;
|
|
739
|
+
} | {
|
|
740
|
+
readonly _tag: "DurableRuntimeFailpointError";
|
|
741
|
+
readonly location: "abort:after-intent" | "approval:after-request-append" | "approval:after-suspend" | "checkpoint:after-save" | "checkpoint:before-save" | "claim:after-claim" | "compaction:after-canonical-append" | "compaction:before-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" | "subagent:before-join-append" | "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" | "worker:after-completion-append" | "worker:after-origin-append" | "worker:after-report-append" | "worker:after-report-delivery" | "worker:after-source-append" | "worker:after-subtree-append" | "worker:before-completion-append" | "worker:before-origin-append" | "worker:before-report-append" | "worker:before-report-delivery" | "worker:before-source-append" | "worker:before-subtree-append";
|
|
750
742
|
} | {
|
|
751
743
|
readonly _tag: "OwnershipLost";
|
|
752
744
|
readonly submissionId: string;
|
|
@@ -755,6 +747,14 @@ declare const encodeAdminResponse: (input: AdminFailed | ExplainedRecovery | Obl
|
|
|
755
747
|
readonly _tag: "RunJournalError";
|
|
756
748
|
readonly message: string;
|
|
757
749
|
readonly cause?: Schema.Json | undefined;
|
|
750
|
+
} | {
|
|
751
|
+
readonly _tag: "DurableAlarmError";
|
|
752
|
+
readonly operation: string;
|
|
753
|
+
readonly message: string;
|
|
754
|
+
readonly cause?: Schema.Json | undefined;
|
|
755
|
+
} | {
|
|
756
|
+
readonly _tag: "HostProtocolError";
|
|
757
|
+
readonly message: string;
|
|
758
758
|
} | {
|
|
759
759
|
readonly _tag: "RetryRefused";
|
|
760
760
|
readonly submissionId: string;
|
|
@@ -813,4 +813,4 @@ interface Class<EventServices = never> {
|
|
|
813
813
|
declare const make: <ApplicationServices, ApplicationError, EventServices = never, EventLayerError = never>(applicationLayer: Layer.Layer<CloudflareDurableRuntimeServices | ApplicationServices, ApplicationError, CloudflareBootstrapServices | DurableObjectState$1.DurableObjectState | WorkerEnvironment | DurableObjectContext | ThreadObjectNamespace>, options: Options<ApplicationServices, EventServices, EventLayerError>) => Class<ApplicationServices | EventServices>;
|
|
814
814
|
//#endregion
|
|
815
815
|
export { ThreadPublicationOptions as A, portCall as C, CloudflareDurableRuntimeOptions as D, CloudflareDurableRuntimeInitializationError as E, layerConfig as M, layerHostConfig as N, CloudflareDurableRuntimeServices as O, layerInHost as P, make as S, CloudflareBootstrapServices as T, decodeAdminVerifyRequest as _, AdminVerifyRequest as a, encodeAdminResponse as b, Instance as c, RetryExecuted as d, ThreadObject_d_exports as f, decodeAdminResponse as g, decodeAdminExplainRequest as h, AdminResponse as i, layer as j, ThreadObjectPorts as k, ObligationsScanned as l, VerifiedIntegrity as m, AdminFailed as n, Class as o, ThreadRpcOperation as p, AdminFailure as r, ExplainedRecovery as s, AdminExplainRequest as t, Options as u, decodeObligationThresholds as v, submit as w, handleRpc as x, decodeRetryCommand as y };
|
|
816
|
-
//# sourceMappingURL=ThreadObject-
|
|
816
|
+
//# sourceMappingURL=ThreadObject-bML6jTHl.d.mts.map
|
package/dist/ThreadObject.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as ThreadPublicationOptions, C as portCall, D as CloudflareDurableRuntimeOptions, E as CloudflareDurableRuntimeInitializationError, M as layerConfig, N as layerHostConfig, O as CloudflareDurableRuntimeServices, P as layerInHost, S as make, T as CloudflareBootstrapServices, _ as decodeAdminVerifyRequest, a as AdminVerifyRequest, b as encodeAdminResponse, c as Instance, d as RetryExecuted, g as decodeAdminResponse, h as decodeAdminExplainRequest, i as AdminResponse, j as layer, k as ThreadObjectPorts, l as ObligationsScanned, m as VerifiedIntegrity, n as AdminFailed, o as Class, p as ThreadRpcOperation, r as AdminFailure, s as ExplainedRecovery, t as AdminExplainRequest, u as Options, v as decodeObligationThresholds, w as submit, x as handleRpc, y as decodeRetryCommand } from "./ThreadObject-
|
|
1
|
+
import { A as ThreadPublicationOptions, C as portCall, D as CloudflareDurableRuntimeOptions, E as CloudflareDurableRuntimeInitializationError, M as layerConfig, N as layerHostConfig, O as CloudflareDurableRuntimeServices, P as layerInHost, S as make, T as CloudflareBootstrapServices, _ as decodeAdminVerifyRequest, a as AdminVerifyRequest, b as encodeAdminResponse, c as Instance, d as RetryExecuted, g as decodeAdminResponse, h as decodeAdminExplainRequest, i as AdminResponse, j as layer, k as ThreadObjectPorts, l as ObligationsScanned, m as VerifiedIntegrity, n as AdminFailed, o as Class, p as ThreadRpcOperation, r as AdminFailure, s as ExplainedRecovery, t as AdminExplainRequest, u as Options, v as decodeObligationThresholds, w as submit, x as handleRpc, y as decodeRetryCommand } from "./ThreadObject-bML6jTHl.mjs";
|
|
2
2
|
export { AdminExplainRequest, AdminFailed, AdminFailure, AdminResponse, AdminVerifyRequest, type CloudflareBootstrapServices as BootstrapServices, Class, ExplainedRecovery, type CloudflareDurableRuntimeInitializationError as InitializationError, Instance, ObligationsScanned, Options, type ThreadPublicationOptions as PublicationOptions, RetryExecuted, type CloudflareDurableRuntimeOptions as RuntimeOptions, type CloudflareDurableRuntimeServices as Services, ThreadObjectPorts, ThreadRpcOperation, VerifiedIntegrity, decodeAdminExplainRequest, decodeAdminResponse, decodeAdminVerifyRequest, decodeObligationThresholds, decodeRetryCommand, encodeAdminResponse, handleRpc, layer, layerConfig, layerHostConfig, layerInHost, make, portCall, submit };
|
package/dist/ThreadObject.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "./CloudflareThreadClient.mjs";
|
|
2
|
-
import { C as layer, E as layerInHost, S as ThreadObjectPorts, T as layerHostConfig, _ as encodeAdminResponse, a as AdminVerifyRequest, b as portCall, c as RetryExecuted, d as VerifiedIntegrity, f as decodeAdminExplainRequest, g as decodeRetryCommand, h as decodeObligationThresholds, i as AdminResponse, m as decodeAdminVerifyRequest, n as AdminFailed, o as ExplainedRecovery, p as decodeAdminResponse, r as AdminFailure, s as ObligationsScanned, t as AdminExplainRequest, u as ThreadRpcOperation, v as handleRpc, w as layerConfig, x as submit, y as make } from "./ThreadObject-
|
|
2
|
+
import { C as layer, E as layerInHost, S as ThreadObjectPorts, T as layerHostConfig, _ as encodeAdminResponse, a as AdminVerifyRequest, b as portCall, c as RetryExecuted, d as VerifiedIntegrity, f as decodeAdminExplainRequest, g as decodeRetryCommand, h as decodeObligationThresholds, i as AdminResponse, m as decodeAdminVerifyRequest, n as AdminFailed, o as ExplainedRecovery, p as decodeAdminResponse, r as AdminFailure, s as ObligationsScanned, t as AdminExplainRequest, u as ThreadRpcOperation, v as handleRpc, w as layerConfig, x as submit, y as make } from "./ThreadObject-BpwkEc5E.mjs";
|
|
3
3
|
export { AdminExplainRequest, AdminFailed, AdminFailure, AdminResponse, AdminVerifyRequest, ExplainedRecovery, ObligationsScanned, RetryExecuted, ThreadObjectPorts, ThreadRpcOperation, VerifiedIntegrity, decodeAdminExplainRequest, decodeAdminResponse, decodeAdminVerifyRequest, decodeObligationThresholds, decodeRetryCommand, encodeAdminResponse, handleRpc, layer, layerConfig, layerHostConfig, layerInHost, make, portCall, submit };
|
package/dist/index.d.mts
CHANGED
|
@@ -8,6 +8,6 @@ import { t as CloudflareMemory_d_exports } from "./CloudflareMemory.mjs";
|
|
|
8
8
|
import { t as CloudflareScheduling_d_exports } from "./CloudflareScheduling.mjs";
|
|
9
9
|
import { t as CloudflareSubscriptions_d_exports } from "./CloudflareSubscriptions.mjs";
|
|
10
10
|
import { t as CloudflareThreadClient_d_exports } from "./CloudflareThreadClient.mjs";
|
|
11
|
-
import { f as ThreadObject_d_exports } from "./ThreadObject-
|
|
11
|
+
import { f as ThreadObject_d_exports } from "./ThreadObject-bML6jTHl.mjs";
|
|
12
12
|
import { t as WakeScheduler_d_exports } from "./WakeScheduler.mjs";
|
|
13
13
|
export { Alarm_d_exports as Alarm, CloudflareAiGateway_d_exports as CloudflareAiGateway, CloudflareBindings_d_exports as CloudflareBindings, CloudflareBrowser_d_exports as CloudflareBrowser, CloudflareCodeMode_d_exports as CloudflareCodeMode, CloudflareConfig_d_exports as CloudflareConfig, CloudflareMemory_d_exports as CloudflareMemory, CloudflareScheduling_d_exports as CloudflareScheduling, CloudflareSubscriptions_d_exports as CloudflareSubscriptions, CloudflareThreadClient_d_exports as CloudflareThreadClient, ThreadObject_d_exports as ThreadObject, WakeScheduler_d_exports as WakeScheduler };
|
package/dist/index.mjs
CHANGED
|
@@ -8,6 +8,6 @@ import { t as CloudflareThreadClient_exports } from "./CloudflareThreadClient.mj
|
|
|
8
8
|
import { t as CloudflareScheduling_exports } from "./CloudflareScheduling.mjs";
|
|
9
9
|
import { t as CloudflareSubscriptions_exports } from "./CloudflareSubscriptions.mjs";
|
|
10
10
|
import { t as WakeScheduler_exports } from "./WakeScheduler.mjs";
|
|
11
|
-
import { l as ThreadObject_exports } from "./ThreadObject-
|
|
11
|
+
import { l as ThreadObject_exports } from "./ThreadObject-BpwkEc5E.mjs";
|
|
12
12
|
import { t as CloudflareAiGateway_exports } from "./CloudflareAiGateway.mjs";
|
|
13
13
|
export { Alarm_exports as Alarm, CloudflareAiGateway_exports as CloudflareAiGateway, CloudflareBindings_exports as CloudflareBindings, CloudflareBrowser_exports as CloudflareBrowser, CloudflareCodeMode_exports as CloudflareCodeMode, CloudflareConfig_exports as CloudflareConfig, CloudflareMemory_exports as CloudflareMemory, CloudflareScheduling_exports as CloudflareScheduling, CloudflareSubscriptions_exports as CloudflareSubscriptions, CloudflareThreadClient_exports as CloudflareThreadClient, ThreadObject_exports as ThreadObject, WakeScheduler_exports as WakeScheduler };
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@effect-agent/platform-cloudflare","version":"0.1.0-beta.
|
|
1
|
+
{"name":"@effect-agent/platform-cloudflare","version":"0.1.0-beta.82","dependencies":{"@effect-agent/core":"0.1.0-beta.82","@effect-agent/engine":"0.1.0-beta.82","@effect-agent/sandbox":"0.1.0-beta.82","@effect-agent/storage-cloudflare":"0.1.0-beta.82","@effect-agent/thread":"0.1.0-beta.82","@effect/platform-browser":"4.0.0-rc.112","@effect/sql-sqlite-do":"4.0.0-rc.112"},"devDependencies":{"@cloudflare/puppeteer":"1.1.0","@cloudflare/vitest-pool-workers":"0.21.3","@cloudflare/workers-types":"5.20260825.1","@effect-agent/capabilities":"0.1.0-beta.82","@effect-agent/testing":"0.1.0-beta.82","@effect/platform-node":"4.0.0-rc.112","@effect/sql-d1":"4.0.0-rc.112","@effect/vitest":"4.0.0-rc.112","effect":"4.0.0-rc.112","effect-cf":"0.40.0","esbuild":"0.28.1","miniflare":"5.20260811.1-alpha","typescript":"7.0.2","vite-plus":"0.3.0","vitest":"4.1.11"},"peerDependencies":{"@cloudflare/puppeteer":"^1.1.0","effect":"^4.0.0-rc.112","effect-cf":"^0.40.0"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./Alarm":{"types":"./dist/Alarm.d.mts","default":"./dist/Alarm.mjs"},"./BrowserRestCapture":{"types":"./dist/BrowserRestCapture.d.mts","default":"./dist/BrowserRestCapture.mjs"},"./BrowserRestCrawl":{"types":"./dist/BrowserRestCrawl.d.mts","default":"./dist/BrowserRestCrawl.mjs"},"./CloudflareBindings":{"types":"./dist/CloudflareBindings.d.mts","default":"./dist/CloudflareBindings.mjs"},"./CloudflareBrowser":{"types":"./dist/CloudflareBrowser.d.mts","default":"./dist/CloudflareBrowser.mjs"},"./CloudflareCodeMode":{"types":"./dist/CloudflareCodeMode.d.mts","default":"./dist/CloudflareCodeMode.mjs"},"./CloudflareConfig":{"types":"./dist/CloudflareConfig.d.mts","default":"./dist/CloudflareConfig.mjs"},"./CloudflareMemory":{"types":"./dist/CloudflareMemory.d.mts","default":"./dist/CloudflareMemory.mjs"},"./CloudflareScheduling":{"types":"./dist/CloudflareScheduling.d.mts","default":"./dist/CloudflareScheduling.mjs"},"./CloudflareSubscriptions":{"types":"./dist/CloudflareSubscriptions.d.mts","default":"./dist/CloudflareSubscriptions.mjs"},"./CloudflareThreadClient":{"types":"./dist/CloudflareThreadClient.d.mts","default":"./dist/CloudflareThreadClient.mjs"},"./InteractiveBrowser":{"types":"./dist/InteractiveBrowser.d.mts","default":"./dist/InteractiveBrowser.mjs"},"./ProtectedBrowser":{"types":"./dist/ProtectedBrowser.d.mts","default":"./dist/ProtectedBrowser.mjs"},"./ThreadObject":{"types":"./dist/ThreadObject.d.mts","default":"./dist/ThreadObject.mjs"},"./WakeScheduler":{"types":"./dist/WakeScheduler.d.mts","default":"./dist/WakeScheduler.mjs"},"./CloudflareAiGateway":{"types":"./dist/CloudflareAiGateway.d.mts","default":"./dist/CloudflareAiGateway.mjs"}},"description":"Cloudflare Layer assembly for Effect Agent: Durable Objects and Browser Run adapters.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/danieljvdm/effect-agent.git","directory":"packages/platform-cloudflare"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json"},"peerDependenciesMeta":{"@cloudflare/puppeteer":{"optional":true}}}
|
package/src/Alarm.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
Semaphore,
|
|
29
29
|
Stream,
|
|
30
30
|
} from "effect";
|
|
31
|
+
import { SqlClient } from "effect/unstable/sql/SqlClient";
|
|
31
32
|
|
|
32
33
|
import { DurableObjectContext } from "./CloudflareBindings.ts";
|
|
33
34
|
import { CloudflareDurableRuntimeConfig } from "./CloudflareConfig.ts";
|
|
@@ -64,6 +65,25 @@ const alarmFailure =
|
|
|
64
65
|
cause,
|
|
65
66
|
});
|
|
66
67
|
|
|
68
|
+
// SQL and raw KV/alarm operations share one physical SQLite transaction. Reserve its
|
|
69
|
+
// connection for each short storage operation, never around a mutation or snapshot body.
|
|
70
|
+
const makeStorageOperation = Effect.map(
|
|
71
|
+
SqlClient,
|
|
72
|
+
(sql) =>
|
|
73
|
+
<A>(operation: string, execute: () => Promise<A>) =>
|
|
74
|
+
Effect.flatMap(Effect.serviceOption(sql.transactionService), (current) => {
|
|
75
|
+
const body = Effect.uninterruptible(
|
|
76
|
+
Effect.tryPromise({ try: execute, catch: alarmFailure(operation) }),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
return current._tag === "Some"
|
|
80
|
+
? body
|
|
81
|
+
: Effect.scoped(
|
|
82
|
+
Effect.andThen(sql.reserve.pipe(Effect.mapError(alarmFailure(operation))), body),
|
|
83
|
+
);
|
|
84
|
+
}),
|
|
85
|
+
);
|
|
86
|
+
|
|
67
87
|
/** `ctx.storage` alarm slot as an Effect service; storage is truth, never a memory field. */
|
|
68
88
|
export class DurableAlarmService extends Context.Service<
|
|
69
89
|
DurableAlarmService,
|
|
@@ -97,7 +117,7 @@ export class DurableAlarmService extends Context.Service<
|
|
|
97
117
|
readonly cancel: Effect.Effect<void, DurableAlarmError>;
|
|
98
118
|
}
|
|
99
119
|
>()("@effect-agent/platform-cloudflare/DurableAlarmService") {
|
|
100
|
-
static readonly layer: Layer.Layer<DurableAlarmService, never, DurableObjectContext> =
|
|
120
|
+
static readonly layer: Layer.Layer<DurableAlarmService, never, DurableObjectContext | SqlClient> =
|
|
101
121
|
Layer.effect(DurableAlarmService)(
|
|
102
122
|
Effect.gen(function* () {
|
|
103
123
|
const { ctx } = yield* DurableObjectContext;
|
|
@@ -108,28 +128,26 @@ export class DurableAlarmService extends Context.Service<
|
|
|
108
128
|
*/
|
|
109
129
|
const runningPasses = yield* Ref.make(0);
|
|
110
130
|
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}).pipe(
|
|
131
|
+
const storageOperation = yield* makeStorageOperation;
|
|
132
|
+
|
|
133
|
+
const scheduled = storageOperation("get alarm", () => ctx.storage.getAlarm()).pipe(
|
|
115
134
|
Effect.map((deadline) =>
|
|
116
135
|
deadline === null ? Option.none<number>() : Option.some(deadline),
|
|
117
136
|
),
|
|
118
137
|
);
|
|
119
138
|
|
|
120
139
|
const scheduleAt = (epochMillis: number) =>
|
|
121
|
-
|
|
122
|
-
try: () => ctx.storage.setAlarm(epochMillis),
|
|
123
|
-
catch: alarmFailure("set alarm"),
|
|
124
|
-
});
|
|
140
|
+
storageOperation("set alarm", () => ctx.storage.setAlarm(epochMillis));
|
|
125
141
|
|
|
126
142
|
const ensureScheduledBy = (epochMillis: number) =>
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
143
|
+
storageOperation("ensure alarm", () =>
|
|
144
|
+
ctx.storage.transaction(async (transaction) => {
|
|
145
|
+
const existing = await transaction.getAlarm();
|
|
146
|
+
|
|
147
|
+
if (existing === null || existing > epochMillis) {
|
|
148
|
+
await transaction.setAlarm(epochMillis);
|
|
149
|
+
}
|
|
150
|
+
}),
|
|
133
151
|
);
|
|
134
152
|
|
|
135
153
|
const armNow = Clock.currentTimeMillis.pipe(
|
|
@@ -146,10 +164,7 @@ export class DurableAlarmService extends Context.Service<
|
|
|
146
164
|
Effect.ensuring(Ref.update(runningPasses, (passes) => passes - 1)),
|
|
147
165
|
);
|
|
148
166
|
|
|
149
|
-
const cancel =
|
|
150
|
-
try: () => ctx.storage.deleteAlarm(),
|
|
151
|
-
catch: alarmFailure("delete alarm"),
|
|
152
|
-
});
|
|
167
|
+
const cancel = storageOperation("delete alarm", () => ctx.storage.deleteAlarm());
|
|
153
168
|
|
|
154
169
|
return DurableAlarmService.of({
|
|
155
170
|
scheduled,
|
|
@@ -404,8 +419,7 @@ export class ThreadMutationGate extends Context.Service<
|
|
|
404
419
|
const generationGate = yield* Semaphore.make(1);
|
|
405
420
|
const minimumAlarmDelay = Math.max(1, Math.ceil(config.alarmBackoffBase / 2));
|
|
406
421
|
|
|
407
|
-
const runTransaction =
|
|
408
|
-
Effect.tryPromise({ try: transaction, catch: alarmFailure(operation) });
|
|
422
|
+
const runTransaction = yield* makeStorageOperation;
|
|
409
423
|
|
|
410
424
|
const beginMutation = Effect.fn("ThreadMaintenance.beginMutation")(function* () {
|
|
411
425
|
yield* failpoint.hit("maintenance:dirty:before");
|
|
@@ -508,6 +522,7 @@ export class ThreadMaintenance extends Context.Service<
|
|
|
508
522
|
| ThreadMaintenanceFailpoint
|
|
509
523
|
| CloudflareDurableRuntimeConfig
|
|
510
524
|
| DurableObjectContext
|
|
525
|
+
| SqlClient
|
|
511
526
|
> = Layer.effect(ThreadMaintenance)(
|
|
512
527
|
Effect.gen(function* () {
|
|
513
528
|
const runtime = yield* DurableAgentRuntime;
|
|
@@ -549,8 +564,7 @@ export class ThreadMaintenance extends Context.Service<
|
|
|
549
564
|
const maintenancePassGate = yield* Semaphore.make(1);
|
|
550
565
|
const minimumAlarmDelay = Math.max(1, Math.ceil(config.alarmBackoffBase / 2));
|
|
551
566
|
|
|
552
|
-
const runTransaction =
|
|
553
|
-
Effect.tryPromise({ try: transaction, catch: alarmFailure(operation) });
|
|
567
|
+
const runTransaction = yield* makeStorageOperation;
|
|
554
568
|
|
|
555
569
|
const ensureAlarm = Effect.fn("ThreadMaintenance.ensureAlarm")(function* () {
|
|
556
570
|
yield* failpoint.hit("maintenance:ensure:before");
|