@yielded/agent-platform-cloudflare 0.1.0-beta.182 → 0.1.0-beta.183
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/CloudflareBindings.d.mts +6 -2
- package/dist/CloudflareBindings.mjs.map +1 -1
- package/dist/CloudflareScheduling.mjs +2 -2
- package/dist/CloudflareSubscriptions.mjs +2 -2
- package/dist/{CloudflareThreadClient-CEUjVwis.mjs → CloudflareThreadClient-CnvMXPmV.mjs} +17 -6
- package/dist/CloudflareThreadClient-CnvMXPmV.mjs.map +1 -0
- package/dist/{CloudflareThreadClient-B9ODixhk.d.mts → CloudflareThreadClient-DNsFhgVu.d.mts} +44 -38
- package/dist/CloudflareThreadClient.d.mts +1 -1
- package/dist/CloudflareThreadClient.mjs +1 -1
- package/dist/{ThreadObject-wS46Yxq3.d.mts → ThreadObject-BVoyFKHN.d.mts} +3 -3
- package/dist/{ThreadObject-vmc0jRTS.mjs → ThreadObject-Cr1CFWXb.mjs} +98 -60
- package/dist/ThreadObject-Cr1CFWXb.mjs.map +1 -0
- package/dist/ThreadObject.d.mts +1 -1
- package/dist/ThreadObject.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/{prepared-admission-C3uBqIz0.mjs → prepared-admission-w2Kq32_k.mjs} +2 -2
- package/dist/{prepared-admission-C3uBqIz0.mjs.map → prepared-admission-w2Kq32_k.mjs.map} +1 -1
- package/package.json +1 -1
- package/src/CloudflareBindings.ts +6 -2
- package/src/CloudflareThreadClient.ts +18 -4
- package/src/internal/live-text-protocol.ts +7 -0
- package/src/internal/live-text.ts +129 -91
- package/dist/CloudflareThreadClient-CEUjVwis.mjs.map +0 -1
- package/dist/ThreadObject-vmc0jRTS.mjs.map +0 -1
|
@@ -2,8 +2,8 @@ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
|
2
2
|
import { DurableAlarmError, DurableObjectContext, ThreadObjectIdentity, ThreadObjectNamespace, ThreadObjectPlacement, callThreadObject, threadNamespaceFromEnv } from "./CloudflareBindings.mjs";
|
|
3
3
|
import { AdmissionLimitExceeded, CLOUDFLARE_RUNTIME_DEFAULTS, CloudflareDurableRuntimeConfig, CloudflareDurableRuntimeConfigValue, CloudflarePlatformConfigError } from "./CloudflareConfig.mjs";
|
|
4
4
|
import { _ as Messages, a as ThreadMaintenance, b as Publication, c as ThreadMessageDelivery, d as ThreadPublication, g as Lifecycle, h as HostLaneId, l as ThreadMutationGate, m as publishCommitted, n as DurableAlarmService, o as ThreadMaintenanceAlarm, s as ThreadMaintenanceFailpoint, u as ThreadNativeMaintenance, v as Native, y as Projection } from "./Alarm-C257DCAJ.mjs";
|
|
5
|
-
import { B as encodeHostResponse, C as boundHostDiagnostic, D as decodeAwaitSettlementRequest, E as decodeAwaitProgressRequest, G as Frame, K as MAX_DELTA_LENGTH, M as decodeReceipt, N as decodeSubmitRequest, O as decodeCancelProgressRequest, P as decodeUnknownResolutionCommand, S as UnknownResolutionRecorded, T as decodeApprovalDecisionCommand, X as
|
|
6
|
-
import { t as cloudflarePreparedInputAdmissionLayer } from "./prepared-admission-
|
|
5
|
+
import { B as encodeHostResponse, C as boundHostDiagnostic, D as decodeAwaitSettlementRequest, E as decodeAwaitProgressRequest, G as Frame, K as MAX_DELTA_LENGTH, M as decodeReceipt, N as decodeSubmitRequest, O as decodeCancelProgressRequest, P as decodeUnknownResolutionCommand, Q as cloudflareCryptoLayer, S as UnknownResolutionRecorded, T as decodeApprovalDecisionCommand, X as Request, Y as Observation, Z as isBoundedEvent, _ as SettlementRecordReached, b as SubmitSucceeded, c as HostFailed, g as SettlementReached, h as ProgressObserved, j as decodeObservePageRequest, m as ProgressCancelled, n as ApprovalRecorded, o as CloudflareThreadClient, p as ObservedPage, t as AbortRecorded, u as HostProtocolError, v as SubmissionStatusResponse, w as decodeAbortCommand } from "./CloudflareThreadClient-CnvMXPmV.mjs";
|
|
6
|
+
import { t as cloudflarePreparedInputAdmissionLayer } from "./prepared-admission-w2Kq32_k.mjs";
|
|
7
7
|
import { cloudflareWakeSchedulerLayer } from "./WakeScheduler.mjs";
|
|
8
8
|
import { ThreadPortTransport, executePortRequest, makeLocalSubmissionLookup, portTransportFailure, routedMessageDeliveryStoreLayer, routedSettlementPublisherLayer, routedSubmissionLedgerLayer, routedThreadStoreLayer, routedWorkerAdmissionLayer } from "@yielded/agent-storage-cloudflare/port-routing";
|
|
9
9
|
import { compileRegistrations } from "@yielded/agent/agent-registration";
|
|
@@ -12,10 +12,11 @@ import { SubmissionId, ThreadId } from "@yielded/agent/identifiers";
|
|
|
12
12
|
import { AdmissionPolicyError, LedgerError, OwnershipLost, SettlementConflict, SubmissionLedger, SubmissionLookupByKey } from "@yielded/agent/submission-ledger";
|
|
13
13
|
import { ThreadProjectionMaintenance } from "@yielded/agent/thread-projection-maintenance";
|
|
14
14
|
import { WakeScheduler } from "@yielded/agent/wake-scheduler";
|
|
15
|
-
import { Cause, Clock, Context, Deferred, Duration, Effect, ErrorReporter, Exit,
|
|
15
|
+
import { Cause, Clock, Context, Deferred, Duration, Effect, ErrorReporter, Exit, Layer, Match, Option, Ref, Schema, Semaphore, Stream } from "effect";
|
|
16
16
|
import { DurableObject, DurableObjectAlarm, DurableObjectState, RpcTracing, WorkerEnvironment } from "effect-cf";
|
|
17
17
|
import { SqlClient } from "effect/sql/SqlClient";
|
|
18
18
|
import { PersistedJson, ProducerId } from "@yielded/agent/records";
|
|
19
|
+
import { RpcTarget } from "cloudflare:workers";
|
|
19
20
|
import { SqliteClient } from "@effect/sql-sqlite-do";
|
|
20
21
|
import { DigestError } from "@yielded/agent/digest";
|
|
21
22
|
import { DurableRuntimeFailpoint, DurableRuntimeFailpointError } from "@yielded/agent/durable-failpoint";
|
|
@@ -40,17 +41,31 @@ import { SqlStorageOwner } from "@yielded/agent/sql-storage-owner";
|
|
|
40
41
|
import { ToolReconciler } from "@yielded/agent/tool-reconciler";
|
|
41
42
|
import * as Response from "effect/ai/Response";
|
|
42
43
|
//#region src/internal/live-text.ts
|
|
44
|
+
var ObservationLifetime = class extends RpcTarget {
|
|
45
|
+
#close;
|
|
46
|
+
constructor(close) {
|
|
47
|
+
super();
|
|
48
|
+
this.#close = close;
|
|
49
|
+
}
|
|
50
|
+
[Symbol.dispose]() {
|
|
51
|
+
this.#close();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
43
54
|
/** One Object incarnation; owns drafts and subscriptions independently of RPC event scopes. */
|
|
44
55
|
var LiveTextHub = class LiveTextHub extends Context.Service()("@effect-agent/platform-cloudflare/LiveTextHub") {
|
|
45
56
|
static layer = Layer.effectContext(Effect.gen(function* () {
|
|
46
|
-
const owner = yield* Effect.scope;
|
|
47
57
|
const observers = /* @__PURE__ */ new Set();
|
|
48
58
|
const drafts = /* @__PURE__ */ new Map();
|
|
49
59
|
let length = 0;
|
|
60
|
+
let stopped = false;
|
|
50
61
|
let unavailable;
|
|
51
|
-
const encode = Schema.
|
|
62
|
+
const encode = Schema.encodeSync(Frame);
|
|
52
63
|
const encoder = new TextEncoder();
|
|
53
|
-
yield* Effect.addFinalizer(() => Effect.sync(() =>
|
|
64
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => {
|
|
65
|
+
stopped = true;
|
|
66
|
+
drafts.clear();
|
|
67
|
+
for (const observer of observers) observer.close();
|
|
68
|
+
}));
|
|
54
69
|
const fail = (attemptId) => {
|
|
55
70
|
const error = HostProtocolError.make({ message: "Provisional text exceeds its draft bounds or is invalid; read canonical records" });
|
|
56
71
|
unavailable = {
|
|
@@ -59,14 +74,11 @@ var LiveTextHub = class LiveTextHub extends Context.Service()("@effect-agent/pla
|
|
|
59
74
|
};
|
|
60
75
|
drafts.clear();
|
|
61
76
|
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
|
-
}
|
|
77
|
+
for (const observer of observers) observer.close(error);
|
|
67
78
|
return false;
|
|
68
79
|
};
|
|
69
80
|
const offerUnsafe = (event) => {
|
|
81
|
+
if (stopped) return false;
|
|
70
82
|
if (event._tag === "AttemptEnded" && event.attemptId === unavailable?.attemptId) unavailable = void 0;
|
|
71
83
|
if (unavailable !== void 0) return false;
|
|
72
84
|
if (!isBoundedEvent(event)) return event._tag === "AttemptEnded" ? false : fail(event.attemptId);
|
|
@@ -104,49 +116,57 @@ var LiveTextHub = class LiveTextHub extends Context.Service()("@effect-agent/pla
|
|
|
104
116
|
length -= draft.text.length;
|
|
105
117
|
}
|
|
106
118
|
}
|
|
107
|
-
for (const observer of observers)
|
|
108
|
-
if (observer.threadId !== event.threadId) continue;
|
|
109
|
-
if (!Queue.offerUnsafe(observer.queue, event)) observer.snapshot = true;
|
|
110
|
-
}
|
|
119
|
+
for (const observer of observers) if (observer.threadId === event.threadId) observer.offer(event);
|
|
111
120
|
return true;
|
|
112
121
|
};
|
|
113
122
|
const open = Effect.fnUntraced(function* (threadId) {
|
|
123
|
+
if (stopped) return yield* HostProtocolError.make({ message: "Provisional text owner is closed" });
|
|
114
124
|
if (unavailable !== void 0) return yield* unavailable.error;
|
|
115
125
|
if (threadId.length > 256 || observers.size >= 8) return yield* HostProtocolError.make({ message: "Provisional text observation capacity exceeded" });
|
|
116
|
-
const
|
|
117
|
-
|
|
126
|
+
const buffer = [];
|
|
127
|
+
let controller;
|
|
128
|
+
let pending;
|
|
129
|
+
let snapshotNeeded = true;
|
|
130
|
+
let streamId = "";
|
|
131
|
+
let sequence = 0;
|
|
132
|
+
let closed = false;
|
|
133
|
+
const dispose = () => {
|
|
134
|
+
closed = true;
|
|
135
|
+
buffer.length = 0;
|
|
136
|
+
pending = void 0;
|
|
137
|
+
observers.delete(observer);
|
|
138
|
+
};
|
|
118
139
|
const observer = {
|
|
119
140
|
threadId,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
141
|
+
offer(event) {
|
|
142
|
+
if (buffer.length === 32) snapshotNeeded = true;
|
|
143
|
+
else buffer.push(event);
|
|
144
|
+
flush();
|
|
145
|
+
},
|
|
146
|
+
close(error) {
|
|
147
|
+
if (closed) return;
|
|
148
|
+
dispose();
|
|
149
|
+
if (error === void 0) controller?.close();
|
|
150
|
+
else controller?.error(error);
|
|
151
|
+
}
|
|
124
152
|
};
|
|
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
153
|
const frame = (event) => ({
|
|
134
154
|
_tag: "Event",
|
|
135
155
|
schemaVersion: 1,
|
|
136
|
-
streamId
|
|
137
|
-
sequence: ++
|
|
156
|
+
streamId,
|
|
157
|
+
sequence: ++sequence,
|
|
138
158
|
event
|
|
139
159
|
});
|
|
140
160
|
const snapshot = function* () {
|
|
141
|
-
|
|
161
|
+
buffer.length = 0;
|
|
142
162
|
const current = Array.from(drafts.values()).filter((draft) => draft.start.threadId === threadId).map((draft) => ({ ...draft }));
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
163
|
+
snapshotNeeded = false;
|
|
164
|
+
streamId = crypto.randomUUID();
|
|
165
|
+
sequence = 0;
|
|
146
166
|
yield {
|
|
147
167
|
_tag: "Reset",
|
|
148
168
|
schemaVersion: 1,
|
|
149
|
-
streamId
|
|
169
|
+
streamId,
|
|
150
170
|
threadId,
|
|
151
171
|
sequence: 0
|
|
152
172
|
};
|
|
@@ -165,33 +185,51 @@ var LiveTextHub = class LiveTextHub extends Context.Service()("@effect-agent/pla
|
|
|
165
185
|
});
|
|
166
186
|
}
|
|
167
187
|
};
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
let pending;
|
|
177
|
-
const take = Queue.take(queue);
|
|
178
|
-
return Effect.succeed(Effect.gen(function* () {
|
|
179
|
-
for (;;) {
|
|
180
|
-
if (pending !== void 0) {
|
|
181
|
-
const next = pending.next();
|
|
182
|
-
if (!next.done && !observer.snapshot) return [yield* toBytes(next.value)];
|
|
188
|
+
const flush = () => {
|
|
189
|
+
if (closed || controller === void 0) return;
|
|
190
|
+
while (controller.desiredSize !== null && controller.desiredSize > 0) {
|
|
191
|
+
if (snapshotNeeded) pending = snapshot();
|
|
192
|
+
let value;
|
|
193
|
+
if (pending !== void 0) {
|
|
194
|
+
const next = pending.next();
|
|
195
|
+
if (next.done) {
|
|
183
196
|
pending = void 0;
|
|
184
|
-
}
|
|
185
|
-
const event = yield* take;
|
|
186
|
-
if (observer.snapshot || event === void 0) {
|
|
187
|
-
pending = snapshot();
|
|
188
197
|
continue;
|
|
189
198
|
}
|
|
190
|
-
|
|
199
|
+
value = next.value;
|
|
200
|
+
} else {
|
|
201
|
+
const event = buffer.shift();
|
|
202
|
+
if (event === void 0) return;
|
|
203
|
+
value = frame(event);
|
|
204
|
+
}
|
|
205
|
+
let json;
|
|
206
|
+
try {
|
|
207
|
+
json = JSON.stringify(encode(value));
|
|
208
|
+
} catch {
|
|
209
|
+
observer.close(HostProtocolError.make({ message: "Provisional text frame is invalid" }));
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const bytes = encoder.encode(json + "\n");
|
|
213
|
+
if (bytes.byteLength > 32768) {
|
|
214
|
+
observer.close(HostProtocolError.make({ message: "Provisional text frame exceeds its wire bound" }));
|
|
215
|
+
return;
|
|
191
216
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
217
|
+
controller.enqueue(bytes);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
const stream = new ReadableStream({
|
|
221
|
+
start(value) {
|
|
222
|
+
controller = value;
|
|
223
|
+
observers.add(observer);
|
|
224
|
+
flush();
|
|
225
|
+
},
|
|
226
|
+
pull: flush,
|
|
227
|
+
cancel: dispose
|
|
228
|
+
});
|
|
229
|
+
return Observation.make({
|
|
230
|
+
stream,
|
|
231
|
+
lifetime: new ObservationLifetime(() => observer.close())
|
|
232
|
+
});
|
|
195
233
|
});
|
|
196
234
|
return Context.make(LiveTextHub, { open }).pipe(Context.add(Publisher, { offerUnsafe }));
|
|
197
235
|
}));
|
|
@@ -1160,4 +1198,4 @@ const make = (applicationLayer, options) => {
|
|
|
1160
1198
|
//#endregion
|
|
1161
1199
|
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 };
|
|
1162
1200
|
|
|
1163
|
-
//# sourceMappingURL=ThreadObject-
|
|
1201
|
+
//# sourceMappingURL=ThreadObject-Cr1CFWXb.mjs.map
|