@yielded/agent-platform-cloudflare 0.1.0-beta.167 → 0.1.0-beta.169
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-B0ODr1NE.mjs → Alarm-BMEAZo3p.mjs} +261 -159
- package/dist/Alarm-BMEAZo3p.mjs.map +1 -0
- package/dist/Alarm.d.mts +29 -36
- package/dist/Alarm.mjs +2 -2
- package/dist/BrowserCredentials-C5IWfi7f.d.mts +91 -0
- package/dist/BrowserCredentials.d.mts +2 -91
- package/dist/BrowserRestCapture.mjs +3 -3
- package/dist/BrowserRestCapture.mjs.map +1 -1
- package/dist/BrowserRestCrawl.mjs +6 -6
- package/dist/BrowserRestCrawl.mjs.map +1 -1
- package/dist/{BrowserSession-RfIzxGCH.mjs → BrowserSession-BfNmyayH.mjs} +5 -5
- package/dist/BrowserSession-BfNmyayH.mjs.map +1 -0
- package/dist/{BrowserSession-B969Xg-2.d.mts → BrowserSession-Bx0V1-6_.d.mts} +6 -3
- package/dist/BrowserSession.d.mts +1 -1
- package/dist/BrowserSession.mjs +2 -2
- package/dist/BrowserUse-Bc2JdLW2.mjs +1528 -0
- package/dist/BrowserUse-Bc2JdLW2.mjs.map +1 -0
- package/dist/BrowserUse.d.mts +83 -0
- package/dist/BrowserUse.mjs +2 -0
- package/dist/CloudflareBindings.d.mts +8 -1
- package/dist/CloudflareBindings.mjs +2 -2
- package/dist/CloudflareBindings.mjs.map +1 -1
- package/dist/{CloudflareBrowser-5an6m-Qb.mjs → CloudflareBrowser-Vt8qTdYW.mjs} +11 -13
- package/dist/CloudflareBrowser-Vt8qTdYW.mjs.map +1 -0
- package/dist/CloudflareBrowser.mjs +1 -1
- package/dist/CloudflareCodeMode.mjs +1 -1
- package/dist/CloudflareCodeMode.mjs.map +1 -1
- package/dist/{CloudflareConfig-qDrRLofL.d.mts → CloudflareConfig-C9MvPbX8.d.mts} +9 -11
- package/dist/CloudflareConfig.d.mts +1 -1
- package/dist/CloudflareConfig.mjs +9 -12
- package/dist/CloudflareConfig.mjs.map +1 -1
- package/dist/CloudflareMemory.d.mts +3 -25
- package/dist/CloudflareMemory.mjs +33 -31
- package/dist/CloudflareMemory.mjs.map +1 -1
- package/dist/CloudflareScheduling.mjs +8 -15
- package/dist/CloudflareScheduling.mjs.map +1 -1
- package/dist/CloudflareSubscriptions.mjs +9 -16
- package/dist/CloudflareSubscriptions.mjs.map +1 -1
- package/dist/CloudflareThreadClient-CLZpN9zU.mjs +588 -0
- package/dist/CloudflareThreadClient-CLZpN9zU.mjs.map +1 -0
- package/dist/CloudflareThreadClient-QsVzLGGZ.d.mts +2033 -0
- package/dist/CloudflareThreadClient.d.mts +2 -1796
- package/dist/CloudflareThreadClient.mjs +2 -382
- package/dist/{InteractiveBrowser-BbG3kGA9.mjs → InteractiveBrowser-LdKzQeLR.mjs} +18 -19
- package/dist/InteractiveBrowser-LdKzQeLR.mjs.map +1 -0
- package/dist/InteractiveBrowser.mjs +1 -1
- package/dist/{ThreadObject-BcfXbzSO.d.mts → ThreadObject-7s5XnlH-.d.mts} +103 -79
- package/dist/{ThreadObject-DHjrnlX4.mjs → ThreadObject-CgXZMlr4.mjs} +265 -66
- package/dist/ThreadObject-CgXZMlr4.mjs.map +1 -0
- package/dist/ThreadObject.d.mts +2 -2
- package/dist/ThreadObject.mjs +2 -3
- package/dist/WakeScheduler.d.mts +6 -5
- package/dist/WakeScheduler.mjs +15 -11
- package/dist/WakeScheduler.mjs.map +1 -1
- package/dist/index.d.mts +7 -6
- package/dist/index.mjs +7 -6
- package/dist/page-function-CmUCcyNP.mjs +11 -0
- package/dist/page-function-CmUCcyNP.mjs.map +1 -0
- package/dist/{prepared-admission-DMX5p9dC.mjs → prepared-admission-B61A7y6O.mjs} +3 -3
- package/dist/{prepared-admission-DMX5p9dC.mjs.map → prepared-admission-B61A7y6O.mjs.map} +1 -1
- package/package.json +1 -1
- package/src/Alarm.ts +512 -279
- package/src/BrowserRestCapture.ts +2 -2
- package/src/BrowserRestCrawl.ts +10 -14
- package/src/BrowserSession.ts +10 -2
- package/src/BrowserUse.ts +1591 -0
- package/src/CloudflareBindings.ts +13 -4
- package/src/CloudflareCodeMode.ts +1 -1
- package/src/CloudflareConfig.ts +9 -12
- package/src/CloudflareMemory.ts +21 -28
- package/src/CloudflareScheduling.ts +7 -15
- package/src/CloudflareSubscriptions.ts +11 -20
- package/src/CloudflareThreadClient.ts +289 -9
- package/src/InteractiveBrowser.ts +325 -323
- package/src/ThreadObject.ts +172 -52
- package/src/WakeScheduler.ts +29 -18
- package/src/index.ts +1 -0
- package/src/internal/browser-dom.ts +886 -0
- package/src/internal/browser-file-selection.ts +8 -1
- package/src/internal/browser-jev-dom.ts +362 -0
- package/src/internal/browser-quick-action.ts +7 -8
- package/src/internal/browser-session-lifecycle.ts +2 -5
- package/src/internal/crypto.ts +41 -0
- package/src/internal/due-queue.ts +5 -69
- package/src/internal/layers.ts +100 -17
- package/src/internal/live-text-protocol.ts +51 -0
- package/src/internal/live-text.ts +256 -0
- package/src/internal/page-function.ts +12 -0
- package/src/internal/prepared-admission.ts +1 -1
- package/src/internal/progress-wait.ts +19 -24
- package/src/internal/transport.ts +1 -1
- package/dist/Alarm-B0ODr1NE.mjs.map +0 -1
- package/dist/BrowserSession-RfIzxGCH.mjs.map +0 -1
- package/dist/CloudflareBrowser-5an6m-Qb.mjs.map +0 -1
- package/dist/CloudflareThreadClient.mjs.map +0 -1
- package/dist/InteractiveBrowser-BbG3kGA9.mjs.map +0 -1
- package/dist/ThreadObject-DHjrnlX4.mjs.map +0 -1
|
@@ -1,40 +1,183 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
2
|
import { DurableObjectContext, ThreadObjectIdentity, ThreadObjectNamespace, ThreadObjectPlacement, callThreadObject, threadNamespaceFromEnv } from "./CloudflareBindings.mjs";
|
|
3
3
|
import { AdmissionLimitExceeded, CLOUDFLARE_RUNTIME_DEFAULTS, CloudflareDurableRuntimeConfig, CloudflareDurableRuntimeConfigValue, CloudflarePlatformConfigError } from "./CloudflareConfig.mjs";
|
|
4
|
-
import { _ as
|
|
5
|
-
import {
|
|
6
|
-
import { t as cloudflarePreparedInputAdmissionLayer } from "./prepared-admission-
|
|
4
|
+
import { _ as Lifecycle, b as Projection, c as ThreadMaintenanceFailpoint, d as ThreadNativeMaintenance, f as ThreadPublication, g as HostLaneId, h as publishCommitted, l as ThreadMessageDelivery, n as DurableAlarmError, o as ThreadMaintenance, r as DurableAlarmService, s as ThreadMaintenanceAlarm, u as ThreadMutationGate, v as Messages, x as Publication, y as Native } from "./Alarm-BMEAZo3p.mjs";
|
|
5
|
+
import { A as decodeSubmitRequest, C as decodeAbortCommand, E as decodeCancelProgressRequest, G as Request, H as MAX_DELTA_LENGTH, I as encodeHostResponse, K as isBoundedEvent, O as decodeObservePageRequest, S as boundHostDiagnostic, T as decodeAwaitProgressRequest, V as Frame, _ as SubmissionStatusResponse, a as CloudflareThreadClient, f as ObservedPage, g as SettlementRecordReached, h as SettlementReached, j as decodeUnknownResolutionCommand, k as decodeReceipt, l as HostProtocolError, m as ProgressObserved, n as ApprovalRecorded, p as ProgressCancelled, q as cloudflareCryptoLayer, s as HostFailed, t as AbortRecorded, w as decodeApprovalDecisionCommand, x as UnknownResolutionRecorded, y as SubmitSucceeded } from "./CloudflareThreadClient-CLZpN9zU.mjs";
|
|
6
|
+
import { t as cloudflarePreparedInputAdmissionLayer } from "./prepared-admission-B61A7y6O.mjs";
|
|
7
7
|
import { cloudflareWakeSchedulerLayer } from "./WakeScheduler.mjs";
|
|
8
|
+
import { ThreadPortTransport, executePortRequest, makeLocalSubmissionLookup, portTransportFailure, routedMessageDeliveryStoreLayer, routedSettlementPublisherLayer, routedSubmissionLedgerLayer, routedThreadStoreLayer, routedWorkerAdmissionLayer } from "@yielded/agent-storage-cloudflare/port-routing";
|
|
8
9
|
import { compileRegistrations } from "@yielded/agent/agent-registration";
|
|
9
|
-
import { ApprovalSuspensionError, DurableAgentRuntime, DurableRuntimeConfig, RecoveryReport } from "@yielded/agent/durable-agent-runtime";
|
|
10
|
+
import { ApprovalSuspensionError, DurableAgentRuntime, DurableRuntimeConfig, RecoveryBlocked, RecoveryReport } from "@yielded/agent/durable-agent-runtime";
|
|
10
11
|
import { SubmissionId, ThreadId } from "@yielded/agent/identifiers";
|
|
11
12
|
import { AdmissionPolicyError, LedgerError, OwnershipLost, SettlementConflict, SubmissionLedger, SubmissionLookupByKey } from "@yielded/agent/submission-ledger";
|
|
12
13
|
import { ThreadProjectionMaintenance } from "@yielded/agent/thread-projection-maintenance";
|
|
13
14
|
import { WakeScheduler } from "@yielded/agent/wake-scheduler";
|
|
14
|
-
import { Cause, Clock, Context, Deferred, Duration, Effect, ErrorReporter, Exit, Layer, Match, Option, Ref, Schema, Semaphore, Stream } from "effect";
|
|
15
|
-
import { DurableObject, DurableObjectState, RpcTracing, WorkerEnvironment } from "effect-cf";
|
|
15
|
+
import { Cause, Clock, Context, Deferred, Duration, Effect, ErrorReporter, Exit, Layer, Match, Option, Queue, Ref, Schema, Scope, Semaphore, Stream } from "effect";
|
|
16
|
+
import { DurableObject, DurableObjectAlarm, DurableObjectState, RpcTracing, WorkerEnvironment } from "effect-cf";
|
|
16
17
|
import { SqlClient } from "effect/sql/SqlClient";
|
|
17
18
|
import { PersistedJson, ProducerId } from "@yielded/agent/records";
|
|
18
|
-
import { BrowserCrypto } from "@effect/platform-browser";
|
|
19
19
|
import { SqliteClient } from "@effect/sql-sqlite-do";
|
|
20
20
|
import { DigestError } from "@yielded/agent/digest";
|
|
21
21
|
import { DurableRuntimeFailpoint, DurableRuntimeFailpointError } from "@yielded/agent/durable-failpoint";
|
|
22
22
|
import { OperationAuthorizationRequest, OperationAuthorizer, OperationDenied, operationAuthorizerLayer } from "@yielded/agent/operation-authorizer";
|
|
23
|
-
import { AppendConflict,
|
|
23
|
+
import { AppendConflict, AppendResult, ThreadNotMaterialized, ThreadRead, ThreadStore, ThreadStoreError } from "@yielded/agent/thread-store";
|
|
24
|
+
import { Publisher } from "@yielded/agent/provisional-text";
|
|
24
25
|
import { LedgerLookupResult, PortFailed, PortProtocolError, PortSucceeded, decodePortRequest, encodePortResponse } from "@yielded/agent-storage-cloudflare/port-protocol";
|
|
25
26
|
import { IntegrityReport, ObligationReport, ObligationThresholds, RecoveryExplanation, RetryCommand, RetryRefused } from "@yielded/agent/admin";
|
|
26
27
|
import { RunJournalError } from "@yielded/agent/run-journal";
|
|
28
|
+
import { WorkDiscoveryUnavailable } from "@yielded/agent/thread-work";
|
|
27
29
|
import { doMessageDeliveryStoreLayer } from "@yielded/agent-storage-cloudflare/do-message-delivery-store";
|
|
28
30
|
import "@yielded/agent-storage-cloudflare/do-storage-failpoint";
|
|
29
31
|
import { submissionLedgerLayer } from "@yielded/agent-storage-cloudflare/do-submission-ledger";
|
|
30
32
|
import { sqlOwnerLayer, storageConfigLayer, storageFailpointLayer, threadStoreLayer } from "@yielded/agent-storage-cloudflare/do-thread-store";
|
|
31
|
-
import { ThreadPortTransport, executePortRequest, makeLocalSubmissionLookup, portTransportFailure, routedMessageDeliveryStoreLayer, routedSubmissionLedgerLayer, routedThreadStoreLayer, routedWorkerAdmissionLayer } from "@yielded/agent-storage-cloudflare/port-routing";
|
|
32
33
|
import { SqlStorageProgress, SqlStorageProgressError } from "@yielded/agent-storage-sql/sql-storage-progress";
|
|
33
34
|
import { LifecyclePublicationError, LifecyclePublicationFact, drainLifecyclePublications, lifecyclePublicationLayer } from "@yielded/agent/lifecycle-publication";
|
|
34
35
|
import { MessageDeliveryDriver, MessageDeliveryError, MessageDeliveryStore } from "@yielded/agent/message-delivery";
|
|
35
36
|
import { CurrentToolFailureObserver, RunContextPreparationPassthrough, RunToolAuthorization, toolFailureObserverLayer } from "@yielded/agent/run-options";
|
|
37
|
+
import { StorageOwner, layer } from "@yielded/agent/run-storage";
|
|
38
|
+
import { SettlementPublisher, validatePublication } from "@yielded/agent/settlement-publisher";
|
|
36
39
|
import { SqlStorageOwner } from "@yielded/agent/sql-memory-store";
|
|
37
40
|
import { ToolReconciler } from "@yielded/agent/tool-reconciler";
|
|
41
|
+
import * as Response from "effect/ai/Response";
|
|
42
|
+
//#region src/internal/live-text.ts
|
|
43
|
+
/** One Object incarnation; owns drafts and subscriptions independently of RPC event scopes. */
|
|
44
|
+
var LiveTextHub = class LiveTextHub extends Context.Service()("@effect-agent/platform-cloudflare/LiveTextHub") {
|
|
45
|
+
static layer = Layer.effectContext(Effect.gen(function* () {
|
|
46
|
+
const owner = yield* Effect.scope;
|
|
47
|
+
const observers = /* @__PURE__ */ new Set();
|
|
48
|
+
const drafts = /* @__PURE__ */ new Map();
|
|
49
|
+
let length = 0;
|
|
50
|
+
let unavailable;
|
|
51
|
+
const encode = Schema.encodeEffect(Schema.fromJsonString(Frame));
|
|
52
|
+
const encoder = new TextEncoder();
|
|
53
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => drafts.clear()));
|
|
54
|
+
const fail = (attemptId) => {
|
|
55
|
+
const error = HostProtocolError.make({ message: "Provisional text exceeds its draft bounds or is invalid; read canonical records" });
|
|
56
|
+
unavailable = {
|
|
57
|
+
error,
|
|
58
|
+
attemptId
|
|
59
|
+
};
|
|
60
|
+
drafts.clear();
|
|
61
|
+
length = 0;
|
|
62
|
+
for (const observer of observers) {
|
|
63
|
+
observer.snapshot = true;
|
|
64
|
+
Queue.failCauseUnsafe(observer.queue, Cause.fail(error));
|
|
65
|
+
Queue.shutdownUnsafe(observer.queue);
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
};
|
|
69
|
+
const offerUnsafe = (event) => {
|
|
70
|
+
if (event._tag === "AttemptEnded" && event.attemptId === unavailable?.attemptId) unavailable = void 0;
|
|
71
|
+
if (unavailable !== void 0) return false;
|
|
72
|
+
if (!isBoundedEvent(event)) return event._tag === "AttemptEnded" ? false : fail(event.attemptId);
|
|
73
|
+
if (event._tag === "Text") {
|
|
74
|
+
const key = JSON.stringify([
|
|
75
|
+
event.threadId,
|
|
76
|
+
event.submissionId,
|
|
77
|
+
event.attemptId,
|
|
78
|
+
event.runId,
|
|
79
|
+
event.turnId,
|
|
80
|
+
event.generation,
|
|
81
|
+
event.part.id
|
|
82
|
+
]);
|
|
83
|
+
const draft = drafts.get(key);
|
|
84
|
+
if (event.part.type === "text-start") {
|
|
85
|
+
if (draft !== void 0 || drafts.size >= 32) return fail(event.attemptId);
|
|
86
|
+
drafts.set(key, {
|
|
87
|
+
start: event,
|
|
88
|
+
text: "",
|
|
89
|
+
ended: false
|
|
90
|
+
});
|
|
91
|
+
} else {
|
|
92
|
+
if (draft === void 0) return false;
|
|
93
|
+
if (draft.ended) return fail(event.attemptId);
|
|
94
|
+
if (event.part.type === "text-delta") {
|
|
95
|
+
if (length + event.part.delta.length > 2097152) return fail(event.attemptId);
|
|
96
|
+
draft.text += event.part.delta;
|
|
97
|
+
length += event.part.delta.length;
|
|
98
|
+
} else draft.ended = true;
|
|
99
|
+
}
|
|
100
|
+
} else for (const [key, draft] of drafts) {
|
|
101
|
+
const start = draft.start;
|
|
102
|
+
if (start.threadId === event.threadId && start.submissionId === event.submissionId && start.attemptId === event.attemptId && (event._tag === "AttemptEnded" || start.runId === event.runId && start.turnId === event.turnId && start.generation === event.generation)) {
|
|
103
|
+
drafts.delete(key);
|
|
104
|
+
length -= draft.text.length;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
for (const observer of observers) {
|
|
108
|
+
if (observer.threadId !== event.threadId) continue;
|
|
109
|
+
if (!Queue.offerUnsafe(observer.queue, event)) observer.snapshot = true;
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
};
|
|
113
|
+
const open = Effect.fnUntraced(function* (threadId) {
|
|
114
|
+
if (unavailable !== void 0) return yield* unavailable.error;
|
|
115
|
+
if (threadId.length > 256 || observers.size >= 8) return yield* HostProtocolError.make({ message: "Provisional text observation capacity exceeded" });
|
|
116
|
+
const scope = yield* Scope.fork(owner);
|
|
117
|
+
const queue = yield* Queue.dropping(32);
|
|
118
|
+
const observer = {
|
|
119
|
+
threadId,
|
|
120
|
+
queue,
|
|
121
|
+
snapshot: true,
|
|
122
|
+
streamId: "",
|
|
123
|
+
sequence: 0
|
|
124
|
+
};
|
|
125
|
+
const close = Scope.close(scope, Exit.void);
|
|
126
|
+
yield* Scope.addFinalizer(scope, Effect.sync(() => {
|
|
127
|
+
observer.snapshot = true;
|
|
128
|
+
observers.delete(observer);
|
|
129
|
+
Queue.shutdownUnsafe(queue);
|
|
130
|
+
}));
|
|
131
|
+
observers.add(observer);
|
|
132
|
+
Queue.offerUnsafe(queue, void 0);
|
|
133
|
+
const frame = (event) => ({
|
|
134
|
+
_tag: "Event",
|
|
135
|
+
schemaVersion: 1,
|
|
136
|
+
streamId: observer.streamId,
|
|
137
|
+
sequence: ++observer.sequence,
|
|
138
|
+
event
|
|
139
|
+
});
|
|
140
|
+
const snapshot = function* () {
|
|
141
|
+
while (Queue.sizeUnsafe(queue) > 0) Queue.takeUnsafe(queue);
|
|
142
|
+
const current = Array.from(drafts.values()).filter((draft) => draft.start.threadId === threadId).map((draft) => ({ ...draft }));
|
|
143
|
+
observer.snapshot = false;
|
|
144
|
+
observer.streamId = crypto.randomUUID();
|
|
145
|
+
observer.sequence = 0;
|
|
146
|
+
yield {
|
|
147
|
+
_tag: "Reset",
|
|
148
|
+
schemaVersion: 1,
|
|
149
|
+
streamId: observer.streamId,
|
|
150
|
+
threadId,
|
|
151
|
+
sequence: 0
|
|
152
|
+
};
|
|
153
|
+
for (const draft of current) {
|
|
154
|
+
yield frame(draft.start);
|
|
155
|
+
for (let offset = 0; offset < draft.text.length; offset += MAX_DELTA_LENGTH) yield frame({
|
|
156
|
+
...draft.start,
|
|
157
|
+
part: Response.makePart("text-delta", {
|
|
158
|
+
id: draft.start.part.id,
|
|
159
|
+
delta: draft.text.slice(offset, offset + MAX_DELTA_LENGTH)
|
|
160
|
+
})
|
|
161
|
+
});
|
|
162
|
+
if (draft.ended) yield frame({
|
|
163
|
+
...draft.start,
|
|
164
|
+
part: Response.makePart("text-end", { id: draft.start.part.id })
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
const toBytes = Effect.fnUntraced(function* (value) {
|
|
169
|
+
const json = yield* encode(value).pipe(Effect.mapError(() => HostProtocolError.make({ message: "Provisional text frame is invalid" })));
|
|
170
|
+
const bytes = encoder.encode(json + "\n");
|
|
171
|
+
if (bytes.byteLength > 32768) return yield* HostProtocolError.make({ message: "Provisional text frame exceeds its wire bound" });
|
|
172
|
+
return bytes;
|
|
173
|
+
});
|
|
174
|
+
const frames = Stream.fromEffectRepeat(Queue.take(queue)).pipe(Stream.flatMap((event) => observer.snapshot || event === void 0 ? Stream.fromIterable(snapshot(), { chunkSize: 1 }).pipe(Stream.takeWhile(() => !observer.snapshot)) : Stream.succeed(frame(event))), Stream.mapEffect(toBytes), Stream.ensuring(close));
|
|
175
|
+
return yield* Stream.toReadableStreamEffect(frames);
|
|
176
|
+
});
|
|
177
|
+
return Context.make(LiveTextHub, { open }).pipe(Context.add(Publisher, { offerUnsafe }));
|
|
178
|
+
}));
|
|
179
|
+
};
|
|
180
|
+
//#endregion
|
|
38
181
|
//#region src/internal/message-delivery.ts
|
|
39
182
|
/** Every write prearms its owner; the delivery due index owns its recovery deadline. */
|
|
40
183
|
const guardedMessageDeliveryStoreLayer = Layer.effect(MessageDeliveryStore, Effect.gen(function* () {
|
|
@@ -116,23 +259,20 @@ var ProgressWaitRegistry = class ProgressWaitRegistry extends Context.Service()(
|
|
|
116
259
|
else next.set(waiterId, active);
|
|
117
260
|
return next;
|
|
118
261
|
});
|
|
119
|
-
const subscribe = Effect.
|
|
262
|
+
const subscribe = Effect.fnUntraced(function* (waiterId) {
|
|
120
263
|
const deferred = yield* Deferred.make();
|
|
121
264
|
yield* Effect.addFinalizer(() => remove(waiterId, deferred));
|
|
122
|
-
return {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
}).pipe(Effect.map(({ cancelled, deferred }) => cancelled ? Effect.void : Deferred.await(deferred))));
|
|
135
|
-
const cancel = Effect.fn("ProgressWaitRegistry.cancel")(function* (waiterId) {
|
|
265
|
+
return (yield* Ref.modify(registrations, (current) => {
|
|
266
|
+
const existing = current.get(waiterId);
|
|
267
|
+
const next = new Map(current);
|
|
268
|
+
if (existing === "cancelled") return [true, current];
|
|
269
|
+
const active = new Set(existing ?? []);
|
|
270
|
+
active.add(deferred);
|
|
271
|
+
next.set(waiterId, active);
|
|
272
|
+
return [false, next];
|
|
273
|
+
})) ? Effect.void : Deferred.await(deferred);
|
|
274
|
+
});
|
|
275
|
+
const cancel = Effect.fnUntraced(function* (waiterId) {
|
|
136
276
|
const waiters = yield* Ref.modify(registrations, (current) => {
|
|
137
277
|
const existing = current.get(waiterId);
|
|
138
278
|
if (existing === "cancelled") return [[], current];
|
|
@@ -176,7 +316,7 @@ var ProgressWaitRegistry = class ProgressWaitRegistry extends Context.Service()(
|
|
|
176
316
|
const threadPortTransportLayer = Layer.effect(ThreadPortTransport)(Effect.gen(function* () {
|
|
177
317
|
const namespace = yield* ThreadObjectNamespace;
|
|
178
318
|
const { rpcTracing } = namespace;
|
|
179
|
-
return ThreadPortTransport.of({ call: Effect.
|
|
319
|
+
return ThreadPortTransport.of({ call: Effect.fnUntraced(function* (threadId, request) {
|
|
180
320
|
const traceArgs = rpcTracing === void 0 ? [] : yield* RpcTracing.withRpcTraceContext([]);
|
|
181
321
|
return yield* callThreadObject(threadId, (target) => target.portCall(request, ...traceArgs), (cause) => portTransportFailure(threadId, cause)).pipe(Effect.provideService(ThreadObjectNamespace, namespace));
|
|
182
322
|
}, (effect, threadId) => rpcTracing === void 0 ? Effect.withSpan(effect, "CloudflarePortTransport.call", { attributes: { threadId } }) : RpcTracing.withRpcClientSpan(effect, rpcTracing, "portCall")) });
|
|
@@ -196,11 +336,9 @@ const decodeProducerId = Schema.decodeUnknownEffect(ProducerId);
|
|
|
196
336
|
const configFromOptions = (options) => decodeConfigValue({
|
|
197
337
|
deploymentId: options.deploymentId,
|
|
198
338
|
producerPrefix: options.producerPrefix,
|
|
199
|
-
ownershipLeaseDuration: options.ownershipLeaseDuration ?? CLOUDFLARE_RUNTIME_DEFAULTS.ownershipLeaseDuration,
|
|
200
339
|
alarmBackoffBase: options.alarmBackoffBase ?? CLOUDFLARE_RUNTIME_DEFAULTS.alarmBackoffBase,
|
|
201
340
|
alarmBackoffCap: options.alarmBackoffCap ?? CLOUDFLARE_RUNTIME_DEFAULTS.alarmBackoffCap,
|
|
202
341
|
settlementPollInterval: options.settlementPollInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.settlementPollInterval,
|
|
203
|
-
leaseRenewalInterval: options.leaseRenewalInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.leaseRenewalInterval,
|
|
204
342
|
abortPollInterval: options.abortPollInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.abortPollInterval,
|
|
205
343
|
observationPollInterval: options.observationPollInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.observationPollInterval,
|
|
206
344
|
projectionDispatchTimeoutMillis: options.projectionDispatchTimeoutMillis ?? CLOUDFLARE_RUNTIME_DEFAULTS.projectionDispatchTimeoutMillis,
|
|
@@ -236,10 +374,9 @@ const runtimeConfigLayer = (options, producerId) => Layer.unwrap(Effect.gen(func
|
|
|
236
374
|
deploymentId: config.deploymentId,
|
|
237
375
|
producerId,
|
|
238
376
|
settlementPollInterval: Duration.millis(config.settlementPollInterval),
|
|
239
|
-
leaseRenewalInterval: Duration.millis(config.leaseRenewalInterval),
|
|
240
377
|
abortPollInterval: Duration.millis(config.abortPollInterval),
|
|
241
378
|
...options.estimateCostMicrousd === void 0 ? {} : { estimateCostMicrousd: options.estimateCostMicrousd }
|
|
242
|
-
}),
|
|
379
|
+
}), cloudflareCryptoLayer, LiveTextHub.layer, storageFailpointLayer({
|
|
243
380
|
storage: ctx.storage,
|
|
244
381
|
failpoint: options.storageFailpoint?.(ctx)
|
|
245
382
|
}), options.runtimeFailpoint === void 0 ? DurableRuntimeFailpoint.layer : Layer.succeed(DurableRuntimeFailpoint, { hit: options.runtimeFailpoint(ctx) }), options.maintenanceFailpoint === void 0 ? ThreadMaintenanceFailpoint.layer : Layer.succeed(ThreadMaintenanceFailpoint, { hit: options.maintenanceFailpoint(ctx) }), options.toolReconciler ?? ToolReconciler.uncertain, options.operationAuthorizer === void 0 ? Layer.empty : operationAuthorizerLayer(options.operationAuthorizer), options.toolFailureObserver === void 0 ? Layer.succeed(CurrentToolFailureObserver, void 0) : toolFailureObserverLayer(options.toolFailureObserver), RunContextPreparationPassthrough, RunToolAuthorization.allowAll);
|
|
@@ -256,7 +393,10 @@ const layerConfig = (options) => Layer.unwrap(Effect.gen(function* () {
|
|
|
256
393
|
return Layer.mergeAll(runtimeConfigLayer(options, producerId), Layer.succeed(ThreadObjectIdentity, {
|
|
257
394
|
threadId,
|
|
258
395
|
producerId
|
|
259
|
-
}), Layer.succeed(ThreadObjectPlacement, {
|
|
396
|
+
}), Layer.succeed(ThreadObjectPlacement, {
|
|
397
|
+
threadId,
|
|
398
|
+
ownsThread: (target) => target === threadId
|
|
399
|
+
}));
|
|
260
400
|
}));
|
|
261
401
|
/**
|
|
262
402
|
* Configuration for an application Object owning several logical Threads. The producer is
|
|
@@ -275,7 +415,7 @@ const layerHostConfig = (options, ownsThread) => Layer.unwrap(Effect.gen(functio
|
|
|
275
415
|
* Use Layer.unwrap for registration values that need effectful application setup.
|
|
276
416
|
*/
|
|
277
417
|
const registeredLayer = (registrations, options = {}) => Layer.unwrap(Effect.map(compileRegistrations(registrations), (bindings) => boundLayer(bindings, options)));
|
|
278
|
-
function layer(registrations, options = {}) {
|
|
418
|
+
function layer$1(registrations, options = {}) {
|
|
279
419
|
return registeredLayer(registrations, options);
|
|
280
420
|
}
|
|
281
421
|
/**
|
|
@@ -291,11 +431,11 @@ function layerInHost(application, options = {}) {
|
|
|
291
431
|
const sharedLayer = (application, options = {}) => Layer.unwrap(Effect.gen(function* () {
|
|
292
432
|
const { ctx } = yield* DurableObjectContext;
|
|
293
433
|
const config = yield* CloudflareDurableRuntimeConfig;
|
|
294
|
-
const
|
|
434
|
+
const placement = yield* ThreadObjectPlacement;
|
|
435
|
+
const { ownsThread } = placement;
|
|
295
436
|
const storageOptions = {
|
|
296
437
|
storage: ctx.storage,
|
|
297
438
|
observationPollInterval: config.observationPollInterval,
|
|
298
|
-
ownershipLeaseDuration: config.ownershipLeaseDuration,
|
|
299
439
|
maxStoredValueBytes: config.maxStoredValueBytes,
|
|
300
440
|
verifyOnOpen: config.verifyOnOpen
|
|
301
441
|
};
|
|
@@ -342,6 +482,8 @@ const sharedLayer = (application, options = {}) => Layer.unwrap(Effect.gen(funct
|
|
|
342
482
|
const localPorts = options.publication === void 0 && options.projection === void 0 && options.hostLanesForMutation === void 0 && options.lifecyclePublication === void 0 ? rawLocalPorts : Layer.effectContext(Effect.gen(function* () {
|
|
343
483
|
const store = yield* ThreadStore;
|
|
344
484
|
const ledger = yield* SubmissionLedger;
|
|
485
|
+
const storageOwner = yield* StorageOwner;
|
|
486
|
+
const settlementPublisher = yield* SettlementPublisher;
|
|
345
487
|
const mutations = yield* ThreadMutationGate;
|
|
346
488
|
const index = yield* ThreadProjectionMaintenance;
|
|
347
489
|
const publish = yield* Effect.context();
|
|
@@ -379,7 +521,18 @@ const sharedLayer = (application, options = {}) => Layer.unwrap(Effect.gen(funct
|
|
|
379
521
|
cause
|
|
380
522
|
})), Effect.flatMap((lanes) => observeIntent(body, invalidatesRecovery, lanes)));
|
|
381
523
|
const stopWorker = ledger.stopWorker;
|
|
382
|
-
return Context.make(ThreadStore, observedStore).pipe(Context.add(
|
|
524
|
+
return Context.make(ThreadStore, observedStore).pipe(Context.add(StorageOwner, storageOwner), Context.add(SettlementPublisher, { publish: (input) => Effect.gen(function* () {
|
|
525
|
+
const { request } = yield* validatePublication(input);
|
|
526
|
+
return yield* mutations.withMutation(sourceCommits.withPermit(settlementPublisher.publish(request).pipe(Effect.tap((result) => result.replayed ? Effect.void : index.applyCommitted(request.append, AppendResult.make({
|
|
527
|
+
firstSequence: result.tailSequence,
|
|
528
|
+
lastSequence: result.tailSequence,
|
|
529
|
+
replayed: false
|
|
530
|
+
})).pipe(Effect.catchCause((cause) => Cause.hasInterrupts(cause) ? Effect.interrupt : Effect.logError("Thread projection deferred after settlement publication", cause)))))).pipe(Effect.tap(() => afterCommit)), { lanes: [...options.projection === void 0 ? [] : [Projection], ...options.lifecyclePublication === void 0 ? [] : [Lifecycle]] }).pipe(Effect.catchTag("DurableAlarmError", (cause) => ThreadStoreError.make({
|
|
531
|
+
operation: "prearm settlement publication",
|
|
532
|
+
message: cause.message,
|
|
533
|
+
cause
|
|
534
|
+
})));
|
|
535
|
+
}) }), Context.add(SubmissionLedger, {
|
|
383
536
|
...ledger,
|
|
384
537
|
...options.hostLanesForMutation === void 0 ? {} : { admit: (request) => observeMutation({
|
|
385
538
|
_tag: "Admission",
|
|
@@ -412,9 +565,9 @@ const sharedLayer = (application, options = {}) => Layer.unwrap(Effect.gen(funct
|
|
|
412
565
|
lookupSubmission: (submissionId) => lookupSubmission(submissionId).pipe(Effect.provide(local))
|
|
413
566
|
});
|
|
414
567
|
})).pipe(Layer.provide(localPorts), Layer.provide(messageStore), Layer.provide(wakes));
|
|
415
|
-
const routedPorts = Layer.mergeAll(routedSubmissionLedgerLayer({ ownsThread }), routedThreadStoreLayer({ ownsThread }), routedWorkerAdmissionLayer({ ownsThread })).pipe(Layer.provide(localPorts), Layer.provide(threadPortTransportLayer));
|
|
568
|
+
const routedPorts = Layer.mergeAll(Layer.effect(StorageOwner, StorageOwner), routedSubmissionLedgerLayer({ ownsThread }), routedSettlementPublisherLayer({ ownsThread }), routedThreadStoreLayer({ ownsThread }), routedWorkerAdmissionLayer({ ownsThread })).pipe(Layer.provide(localPorts), Layer.provide(threadPortTransportLayer));
|
|
416
569
|
const routedMessages = routedMessageDeliveryStoreLayer({ ownsThread }).pipe(Layer.provide(messageStore), Layer.provide(threadPortTransportLayer));
|
|
417
|
-
const runtimeStack = application.pipe(Layer.provide(cloudflarePreparedInputAdmissionLayer.pipe(Layer.provide(CloudflareThreadClient.layer))), Layer.provideMerge(routedMessages), Layer.provideMerge(routedPorts), Layer.provideMerge(wakes), Layer.provideMerge(base), Layer.provideMerge(portsEndpointLayer));
|
|
570
|
+
const runtimeStack = application.pipe(Layer.provideMerge(layer()), Layer.provide(cloudflarePreparedInputAdmissionLayer.pipe(Layer.provide(CloudflareThreadClient.layer))), Layer.provideMerge(routedMessages), Layer.provideMerge(routedPorts), Layer.provideMerge(wakes), Layer.provideMerge(base), Layer.provideMerge(portsEndpointLayer));
|
|
418
571
|
const maintenanceRuntime = options.lifecyclePublication === void 0 ? runtimeStack : Layer.merge(runtimeStack, Layer.effect(ThreadNativeMaintenance)(Effect.gen(function* () {
|
|
419
572
|
const previous = yield* ThreadNativeMaintenance;
|
|
420
573
|
const storage = (yield* ThreadStore).lifecyclePublications;
|
|
@@ -434,7 +587,14 @@ const sharedLayer = (application, options = {}) => Layer.unwrap(Effect.gen(funct
|
|
|
434
587
|
run: storage === void 0 ? Effect.fail(failure("Native lifecycle storage unavailable")) : drainLifecyclePublications(storage).pipe(Effect.provide(context), Effect.mapError(failure), Effect.andThen(deadline))
|
|
435
588
|
}] };
|
|
436
589
|
})).pipe(Layer.provide(rawLocalPorts), Layer.provide(options.lifecyclePublication.pipe(Layer.provide(rawLocalPorts))), Layer.provide(runtimeStack)));
|
|
437
|
-
return Layer.mergeAll(maintenanceRuntime, ThreadMaintenance.layer.pipe(Layer.provide(options.recoveryEvents ?? Layer.empty), Layer.provide(
|
|
590
|
+
return Layer.mergeAll(maintenanceRuntime, ThreadMaintenance.layer.pipe(Layer.provide(options.recoveryEvents ?? Layer.empty), Layer.provide(Layer.effect(ThreadNativeMaintenance)(Effect.gen(function* () {
|
|
591
|
+
const previous = yield* ThreadNativeMaintenance;
|
|
592
|
+
const runtime = yield* DurableAgentRuntime;
|
|
593
|
+
return {
|
|
594
|
+
lanes: previous.lanes,
|
|
595
|
+
...placement.threadId === void 0 ? {} : { singleThreadRuntime: runtime }
|
|
596
|
+
};
|
|
597
|
+
}))), Layer.provide(maintenanceRuntime), Layer.provide(messageRecovery)), portsEndpointLayer, routedMessages, messageRecovery).pipe(Layer.provideMerge(sourceProgress), Layer.provideMerge(publication), Layer.provideMerge(projection), Layer.provideMerge(sourceOwner), Layer.provideMerge(ThreadMutationGate.layer), Layer.provideMerge(infrastructure));
|
|
438
598
|
}));
|
|
439
599
|
//#endregion
|
|
440
600
|
//#region src/ThreadObject.ts
|
|
@@ -450,6 +610,7 @@ var ThreadObject_exports = /* @__PURE__ */ __exportAll({
|
|
|
450
610
|
ThreadObjectPorts: () => ThreadObjectPorts,
|
|
451
611
|
ThreadRpcOperation: () => ThreadRpcOperation,
|
|
452
612
|
VerifiedIntegrity: () => VerifiedIntegrity,
|
|
613
|
+
alarms: () => alarms,
|
|
453
614
|
decodeAdminExplainRequest: () => decodeAdminExplainRequest,
|
|
454
615
|
decodeAdminResponse: () => decodeAdminResponse,
|
|
455
616
|
decodeAdminVerifyRequest: () => decodeAdminVerifyRequest,
|
|
@@ -457,7 +618,7 @@ var ThreadObject_exports = /* @__PURE__ */ __exportAll({
|
|
|
457
618
|
decodeRetryCommand: () => decodeRetryCommand,
|
|
458
619
|
encodeAdminResponse: () => encodeAdminResponse,
|
|
459
620
|
handleRpc: () => handleRpc,
|
|
460
|
-
layer: () => layer,
|
|
621
|
+
layer: () => layer$1,
|
|
461
622
|
layerConfig: () => layerConfig,
|
|
462
623
|
layerHostConfig: () => layerHostConfig,
|
|
463
624
|
layerInHost: () => layerInHost,
|
|
@@ -476,15 +637,27 @@ const isMutatingPortRequest = (request) => {
|
|
|
476
637
|
case "LedgerRecordChildSettled":
|
|
477
638
|
case "StoreMaterialize":
|
|
478
639
|
case "StoreAppend":
|
|
640
|
+
case "StoreWorkRebuild":
|
|
641
|
+
case "StoreRangeSeal":
|
|
642
|
+
case "StoreRangeArchive":
|
|
643
|
+
case "SettlementPublish":
|
|
479
644
|
case "MessageDeliveryComplete": return true;
|
|
480
645
|
case "LedgerInspectWorker":
|
|
481
646
|
case "LedgerLookup":
|
|
482
647
|
case "LedgerResolveAdmission":
|
|
648
|
+
case "LedgerFundingOwner":
|
|
483
649
|
case "StoreReadPage":
|
|
650
|
+
case "StoreReadPrompt":
|
|
651
|
+
case "StoreReadExecution":
|
|
652
|
+
case "StoreWorkPage":
|
|
484
653
|
case "StoreInspectTail":
|
|
485
654
|
case "StoreReadIdentity":
|
|
486
655
|
case "StoreCountPeerMessages":
|
|
487
656
|
case "StoreExport":
|
|
657
|
+
case "StoreRangePage":
|
|
658
|
+
case "StoreRangeVerify":
|
|
659
|
+
case "StoreVerification":
|
|
660
|
+
case "StoreWorkerCapacity":
|
|
488
661
|
case "MessageDeliveryList": return false;
|
|
489
662
|
}
|
|
490
663
|
return false;
|
|
@@ -515,7 +688,7 @@ const utf8Bytes = (value) => new TextEncoder().encode(JSON.stringify(value)).len
|
|
|
515
688
|
* exempt: its accepted-work obligation already exists, and returning the original Receipt
|
|
516
689
|
* consumes no new quota. Refusals are typed `AdmissionLimitExceeded` and nothing is written.
|
|
517
690
|
*/
|
|
518
|
-
const gateAdmissionLimits = Effect.
|
|
691
|
+
const gateAdmissionLimits = Effect.fnUntraced(function* (threadId, request) {
|
|
519
692
|
const config = yield* CloudflareDurableRuntimeConfig;
|
|
520
693
|
const ledger = yield* SubmissionLedger;
|
|
521
694
|
const { ctx } = yield* DurableObjectContext;
|
|
@@ -555,30 +728,32 @@ const passthroughSubmitAgent = (agentId) => ({ definition: {
|
|
|
555
728
|
input: PersistedJson
|
|
556
729
|
} });
|
|
557
730
|
/** A physical owner may hold other Threads; an addressed request cannot act on their IDs. */
|
|
558
|
-
const lookupAddressedSubmission = Effect.
|
|
731
|
+
const lookupAddressedSubmission = Effect.fnUntraced(function* (submissionId) {
|
|
559
732
|
const { threadId } = yield* ThreadObjectIdentity;
|
|
560
733
|
const submission = yield* (yield* ThreadObjectPorts).lookupSubmission(submissionId);
|
|
561
734
|
if (Option.isSome(submission) && submission.value.threadId !== threadId) return yield* HostProtocolError.make({ message: "The Submission belongs to another Thread" });
|
|
562
735
|
return submission;
|
|
563
736
|
});
|
|
564
|
-
const requireSubmissionThread = Effect.
|
|
737
|
+
const requireSubmissionThread = Effect.fnUntraced(function* (submissionId) {
|
|
565
738
|
const submission = yield* lookupAddressedSubmission(submissionId);
|
|
566
739
|
if (Option.isNone(submission)) return yield* LedgerError.make({
|
|
567
740
|
operation: "addressed Submission lookup",
|
|
568
741
|
message: "The addressed Thread has no such Submission"
|
|
569
742
|
});
|
|
570
743
|
});
|
|
571
|
-
const requireReceiptThread = Effect.
|
|
744
|
+
const requireReceiptThread = Effect.fnUntraced(function* (threadId) {
|
|
572
745
|
if (threadId !== (yield* ThreadObjectIdentity).threadId) return yield* HostProtocolError.make({ message: "The Receipt belongs to another Thread" });
|
|
573
746
|
});
|
|
574
747
|
const requirePortThread = (request) => {
|
|
575
748
|
switch (request._tag) {
|
|
749
|
+
case "SettlementPublish": return requireReceiptThread(request.request.append.threadId).pipe(Effect.andThen(requireSubmissionThread(request.request.submissionId)));
|
|
576
750
|
case "MessageDeliveryComplete": return requireReceiptThread(request.key.ownerThreadId);
|
|
577
751
|
case "MessageDeliveryList": return requireReceiptThread(request.request.ownerThreadId);
|
|
578
752
|
case "LedgerLookup": return request.request._tag === "SubmissionLookupById" ? lookupAddressedSubmission(request.request.submissionId).pipe(Effect.asVoid) : requireReceiptThread(request.request.threadId);
|
|
579
753
|
case "LedgerMarkReady":
|
|
580
754
|
case "LedgerRequestAbort": return requireSubmissionThread(request.request.submissionId);
|
|
581
755
|
case "LedgerRecordChildSettled": return requireSubmissionThread(request.request.parentSubmissionId);
|
|
756
|
+
case "LedgerFundingOwner": return requireReceiptThread(request.request.threadId).pipe(Effect.andThen(requireSubmissionThread(request.request.submissionId)));
|
|
582
757
|
case "LedgerInspectWorker":
|
|
583
758
|
case "LedgerStopWorker":
|
|
584
759
|
case "WorkerAdmit":
|
|
@@ -587,22 +762,33 @@ const requirePortThread = (request) => {
|
|
|
587
762
|
case "StoreMaterialize":
|
|
588
763
|
case "StoreAppend":
|
|
589
764
|
case "StoreReadPage":
|
|
765
|
+
case "StoreReadPrompt":
|
|
766
|
+
case "StoreReadExecution":
|
|
590
767
|
case "StoreInspectTail":
|
|
591
768
|
case "StoreReadIdentity":
|
|
592
769
|
case "StoreCountPeerMessages":
|
|
593
|
-
case "StoreExport":
|
|
770
|
+
case "StoreExport":
|
|
771
|
+
case "StoreWorkPage":
|
|
772
|
+
case "StoreWorkRebuild":
|
|
773
|
+
case "StoreRangePage":
|
|
774
|
+
case "StoreRangeSeal":
|
|
775
|
+
case "StoreRangeArchive":
|
|
776
|
+
case "StoreRangeVerify":
|
|
777
|
+
case "StoreVerification":
|
|
778
|
+
case "StoreWorkerCapacity": return requireReceiptThread(request.request.threadId);
|
|
594
779
|
}
|
|
595
780
|
};
|
|
596
781
|
/**
|
|
597
782
|
* Admit an already Schema-decoded request to a logical Thread in this physical owner.
|
|
598
783
|
* Custom hosts validate local placement before calling this Effect and provide their same
|
|
599
|
-
* runtime
|
|
784
|
+
* runtime, maintenance and alarm instances. The native endpoint uses this path too: queue limits,
|
|
600
785
|
* idempotent receipts and the pre-admission generation/alarm commit have one owner.
|
|
601
786
|
*/
|
|
602
|
-
const submit = Effect.
|
|
787
|
+
const submit = Effect.fnUntraced(function* (threadId, request) {
|
|
603
788
|
if (!(yield* ThreadObjectPlacement).ownsThread(threadId)) return yield* HostProtocolError.make({ message: "The Thread belongs to another Object" });
|
|
604
789
|
const mutations = yield* ThreadMutationGate;
|
|
605
790
|
const runtime = yield* DurableAgentRuntime;
|
|
791
|
+
const alarm = yield* DurableAlarmService;
|
|
606
792
|
yield* gateAdmissionLimits(threadId, request);
|
|
607
793
|
return yield* mutations.withMutation(runtime.submit(passthroughSubmitAgent(request.agentId), request.inputPayload, {
|
|
608
794
|
threadId,
|
|
@@ -613,11 +799,12 @@ const submit = Effect.fn("ThreadObject.submit")(function* (threadId, request) {
|
|
|
613
799
|
...request.workerAdmission === void 0 ? {} : { workerAdmission: request.workerAdmission },
|
|
614
800
|
...request.messageAdmission === void 0 ? {} : { messageAdmission: request.messageAdmission },
|
|
615
801
|
definitions: request.definitions
|
|
616
|
-
}).pipe(Effect.tap(() => publishCommitted)));
|
|
802
|
+
}).pipe(alarm.withHintsDeferred, Effect.tap(() => publishCommitted)));
|
|
617
803
|
});
|
|
618
804
|
const submitEndpoint = (encoded) => decodeSubmitRequest(encoded).pipe(Effect.mapError(protocolFailure("The submit request could not be decoded")), Effect.flatMap((request) => Effect.gen(function* () {
|
|
619
805
|
const identity = yield* ThreadObjectIdentity;
|
|
620
806
|
const receipt = yield* submit(identity.threadId, request);
|
|
807
|
+
if ((yield* DurableObjectAlarm.ScheduleConfiguration).dispatchAfterEvent === true) yield* (yield* DurableAlarmService).scheduleNow.pipe(Effect.catch((error) => Effect.logWarning("Post-admission maintenance hint failed", error)));
|
|
621
808
|
return SubmitSucceeded.make({ receipt });
|
|
622
809
|
})), respond, Effect.flatMap(encodeResponse));
|
|
623
810
|
const submissionStatusEndpoint = (encoded) => decodeReceipt(encoded).pipe(Effect.mapError(protocolFailure("The receipt could not be decoded")), Effect.flatMap((receipt) => Effect.gen(function* () {
|
|
@@ -631,16 +818,22 @@ const submissionStatusEndpoint = (encoded) => decodeReceipt(encoded).pipe(Effect
|
|
|
631
818
|
const runtime = yield* DurableAgentRuntime;
|
|
632
819
|
return SubmissionStatusResponse.make({ status: yield* runtime.submissionStatus(receipt) });
|
|
633
820
|
})), respond, Effect.flatMap(encodeResponse));
|
|
634
|
-
const awaitSettlementEndpoint = (encoded) => decodeReceipt(encoded).pipe(Effect.mapError(protocolFailure("The receipt could not be decoded")), Effect.flatMap((receipt) => Effect.gen(function* () {
|
|
635
|
-
|
|
821
|
+
const awaitSettlementEndpoint = (encoded, includeRecord = false) => decodeReceipt(encoded).pipe(Effect.mapError(protocolFailure("The receipt could not be decoded")), Effect.flatMap((receipt) => Effect.gen(function* () {
|
|
822
|
+
const authorizer = yield* OperationAuthorizer;
|
|
823
|
+
yield* authorizer.authorize(OperationAuthorizationRequest.make({
|
|
636
824
|
operation: "awaitSettlement",
|
|
637
825
|
threadId: receipt.threadId,
|
|
638
826
|
submissionId: receipt.submissionId
|
|
639
827
|
}));
|
|
828
|
+
if (includeRecord) yield* authorizer.authorize(OperationAuthorizationRequest.make({
|
|
829
|
+
operation: "observe",
|
|
830
|
+
threadId: receipt.threadId
|
|
831
|
+
}));
|
|
640
832
|
yield* requireReceiptThread(receipt.threadId);
|
|
641
833
|
yield* requireSubmissionThread(receipt.submissionId);
|
|
642
|
-
const
|
|
643
|
-
return
|
|
834
|
+
const runtime = yield* DurableAgentRuntime;
|
|
835
|
+
if (includeRecord) return SettlementRecordReached.make({ record: yield* runtime.awaitSettlementRecord(receipt) });
|
|
836
|
+
return SettlementReached.make({ settlement: yield* runtime.awaitSettlement(receipt) });
|
|
644
837
|
})), respond, Effect.flatMap(encodeResponse));
|
|
645
838
|
const awaitProgressEndpoint = (encoded) => decodeAwaitProgressRequest(encoded).pipe(Effect.mapError(protocolFailure("The progress request could not be decoded")), Effect.flatMap((request) => Effect.gen(function* () {
|
|
646
839
|
const identity = yield* ThreadObjectIdentity;
|
|
@@ -671,6 +864,14 @@ const observePageEndpoint = (encoded) => decodeObservePageRequest(encoded).pipe(
|
|
|
671
864
|
})));
|
|
672
865
|
return ObservedPage.make({ records: [...records] });
|
|
673
866
|
})), respond, Effect.flatMap(encodeResponse));
|
|
867
|
+
const watchTextEndpoint = (encoded) => Schema.decodeUnknownEffect(Request)(encoded).pipe(Effect.mapError(protocolFailure("The provisional text request could not be decoded")), Effect.flatMap(() => Effect.gen(function* () {
|
|
868
|
+
const { threadId } = yield* ThreadObjectIdentity;
|
|
869
|
+
yield* (yield* OperationAuthorizer).authorize(OperationAuthorizationRequest.make({
|
|
870
|
+
operation: "observe",
|
|
871
|
+
threadId
|
|
872
|
+
}));
|
|
873
|
+
return yield* (yield* LiveTextHub).open(threadId);
|
|
874
|
+
})), Effect.catch((failure) => encodeResponse(HostFailed.make({ failure }))));
|
|
674
875
|
const abortEndpoint = (encoded) => decodeAbortCommand(encoded).pipe(Effect.mapError(protocolFailure("The abort command could not be decoded")), Effect.flatMap((command) => Effect.gen(function* () {
|
|
675
876
|
yield* (yield* OperationAuthorizer).authorize(OperationAuthorizationRequest.make({
|
|
676
877
|
operation: "abort",
|
|
@@ -722,10 +923,11 @@ const AdminFailure = Schema.Union([
|
|
|
722
923
|
ThreadStoreError,
|
|
723
924
|
ThreadNotMaterialized,
|
|
724
925
|
AppendConflict,
|
|
725
|
-
FenceRejected,
|
|
726
926
|
DurableRuntimeFailpointError,
|
|
727
927
|
DurableAlarmError,
|
|
728
|
-
HostProtocolError
|
|
928
|
+
HostProtocolError,
|
|
929
|
+
RecoveryBlocked,
|
|
930
|
+
WorkDiscoveryUnavailable
|
|
729
931
|
]);
|
|
730
932
|
var ExplainedRecovery = class extends Schema.TaggedClass("@effect-agent/platform-cloudflare/ExplainedRecovery")("ExplainedRecovery", { explanations: Schema.Array(RecoveryExplanation).check(Schema.isMaxLength(1024)) }) {};
|
|
731
933
|
var VerifiedIntegrity = class extends Schema.TaggedClass("@effect-agent/platform-cloudflare/VerifiedIntegrity")("VerifiedIntegrity", { report: IntegrityReport }) {};
|
|
@@ -821,8 +1023,10 @@ const ThreadRpcOperation = Schema.Literals([
|
|
|
821
1023
|
"submitEncoded",
|
|
822
1024
|
"submissionStatusEncoded",
|
|
823
1025
|
"awaitSettlementEncoded",
|
|
1026
|
+
"awaitSettlementRecordEncoded",
|
|
824
1027
|
"awaitProgressEncoded",
|
|
825
1028
|
"cancelProgressEncoded",
|
|
1029
|
+
"watchTextEncoded",
|
|
826
1030
|
"observePage",
|
|
827
1031
|
"abortEncoded",
|
|
828
1032
|
"resolveApprovalEncoded",
|
|
@@ -834,8 +1038,10 @@ const threadRpc = {
|
|
|
834
1038
|
submitEncoded: submitEndpoint,
|
|
835
1039
|
submissionStatusEncoded: submissionStatusEndpoint,
|
|
836
1040
|
awaitSettlementEncoded: awaitSettlementEndpoint,
|
|
1041
|
+
awaitSettlementRecordEncoded: (encoded) => awaitSettlementEndpoint(encoded, true),
|
|
837
1042
|
awaitProgressEncoded: awaitProgressEndpoint,
|
|
838
1043
|
cancelProgressEncoded: cancelProgressEndpoint,
|
|
1044
|
+
watchTextEncoded: watchTextEndpoint,
|
|
839
1045
|
observePage: observePageEndpoint,
|
|
840
1046
|
abortEncoded: abortEndpoint,
|
|
841
1047
|
resolveApprovalEncoded: resolveApprovalEndpoint,
|
|
@@ -850,7 +1056,7 @@ const threadRpc = {
|
|
|
850
1056
|
* The producer comes from the actual runtime configuration, never from caller input. These
|
|
851
1057
|
* guards supplement the existing current model/Tool and operation authorization policies.
|
|
852
1058
|
*/
|
|
853
|
-
const handleRpc = Effect.
|
|
1059
|
+
const handleRpc = Effect.fnUntraced(function* (threadId, operation, encoded) {
|
|
854
1060
|
if (!(yield* ThreadObjectPlacement).ownsThread(threadId)) return yield* HostProtocolError.make({ message: "The Thread belongs to another Object" });
|
|
855
1061
|
const { producerId } = yield* DurableRuntimeConfig;
|
|
856
1062
|
return yield* threadRpc[operation](encoded).pipe(Effect.provideService(ThreadObjectIdentity, {
|
|
@@ -858,9 +1064,8 @@ const handleRpc = Effect.fn("ThreadObject.handleRpc")(function* (threadId, opera
|
|
|
858
1064
|
producerId
|
|
859
1065
|
}));
|
|
860
1066
|
});
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
});
|
|
1067
|
+
/** Compose with application registrations on a shared physical object. */
|
|
1068
|
+
const alarms = ThreadMaintenanceAlarm.handlers({ "@yielded/agent/thread-maintenance": () => Effect.flatMap(ThreadMaintenance, (maintenance) => Effect.asVoid(maintenance.pass)) });
|
|
864
1069
|
const gateEndpoint = Effect.gen(function* () {
|
|
865
1070
|
yield* (yield* ThreadMaintenance).ensureAlarm;
|
|
866
1071
|
});
|
|
@@ -917,21 +1122,15 @@ const make = (applicationLayer, options) => {
|
|
|
917
1122
|
retryEncoded: (encoded) => retryEndpoint(encoded),
|
|
918
1123
|
obligationsEncoded: (encoded) => obligationsEndpoint(encoded)
|
|
919
1124
|
};
|
|
920
|
-
|
|
1125
|
+
return DurableObject.make(runtime, {
|
|
921
1126
|
...options.rpcTracing === true ? { rpcTracing: { service: options.namespaceBinding } } : {},
|
|
922
1127
|
...options.eventLayer === void 0 ? {} : { eventLayer: options.eventLayer },
|
|
923
1128
|
initialize: Effect.void,
|
|
924
1129
|
rpc,
|
|
925
|
-
|
|
1130
|
+
alarms: options.alarms === void 0 ? alarms : DurableObjectAlarm.mergeAll(options.alarms, alarms)
|
|
926
1131
|
});
|
|
927
|
-
class ThreadObject extends EffectCfThreadObject {
|
|
928
|
-
alarm(alarmInfo) {
|
|
929
|
-
return super.alarm?.(alarmInfo);
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
return ThreadObject;
|
|
933
1132
|
};
|
|
934
1133
|
//#endregion
|
|
935
|
-
export {
|
|
1134
|
+
export { ThreadObjectPorts as C, layerInHost as D, layerHostConfig as E, submit as S, layerConfig as T, decodeRetryCommand as _, AdminVerifyRequest as a, make as b, RetryExecuted as c, VerifiedIntegrity as d, alarms as f, decodeObligationThresholds as g, decodeAdminVerifyRequest as h, AdminResponse as i, ThreadObject_exports as l, decodeAdminResponse as m, AdminFailed as n, ExplainedRecovery as o, decodeAdminExplainRequest as p, AdminFailure as r, ObligationsScanned as s, AdminExplainRequest as t, ThreadRpcOperation as u, encodeAdminResponse as v, layer$1 as w, portCall as x, handleRpc as y };
|
|
936
1135
|
|
|
937
|
-
//# sourceMappingURL=ThreadObject-
|
|
1136
|
+
//# sourceMappingURL=ThreadObject-CgXZMlr4.mjs.map
|