@effect-agent/storage-cloudflare 0.1.0-beta.114 → 0.1.0-beta.116
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/DoMessageDeliveryStore.mjs +1 -1
- package/dist/{DoStorageVersion-Db6fjP-I.d.mts → DoStorageVersion-DJwZzqel.d.mts} +2 -2
- package/dist/DoStorageVersion.d.mts +1 -1
- package/dist/DoStorageVersion.mjs +2 -2
- package/dist/DoSubmissionLedger.mjs +63 -3
- package/dist/DoSubmissionLedger.mjs.map +1 -1
- package/dist/DoThreadStore.mjs +1 -1
- package/dist/PortProtocol.d.mts +746 -165
- package/dist/PortProtocol.mjs +15 -2
- package/dist/PortProtocol.mjs.map +1 -1
- package/dist/PortRouting.d.mts +2 -2
- package/dist/PortRouting.mjs +23 -1
- package/dist/PortRouting.mjs.map +1 -1
- package/dist/{do-journal-BeHu8_Bh.mjs → do-journal-D65Iuln6.mjs} +97 -35
- package/dist/do-journal-D65Iuln6.mjs.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/{migrations-DZKTNU88.mjs → migrations-Br6QqMIf.mjs} +19 -4
- package/dist/migrations-Br6QqMIf.mjs.map +1 -0
- package/package.json +1 -1
- package/src/DoSubmissionLedger.ts +136 -2
- package/src/PortProtocol.ts +27 -0
- package/src/PortRouting.ts +66 -0
- package/src/internal/do-journal.ts +143 -33
- package/src/internal/migrations.ts +18 -1
- package/dist/do-journal-BeHu8_Bh.mjs.map +0 -1
- package/dist/migrations-DZKTNU88.mjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
2
|
import { DoStorageConfig } from "./DoStorageConfig.mjs";
|
|
3
3
|
import { DoStorageFailpoint } from "./DoStorageFailpoint.mjs";
|
|
4
|
-
import { a as initializeDoJournal } from "./do-journal-
|
|
4
|
+
import { a as initializeDoJournal } from "./do-journal-D65Iuln6.mjs";
|
|
5
5
|
import { Effect, Layer } from "effect";
|
|
6
6
|
import { MessageDeliveryError, MessageDeliveryStore } from "effect-agent/message-delivery";
|
|
7
7
|
import { SqlMessageDeliveryTransaction, makeSqlMessageDeliveryStore } from "effect-agent/sql-message-delivery-store";
|
|
@@ -3,10 +3,10 @@ import "effect/unstable/sql/SqlClient";
|
|
|
3
3
|
import { SqliteMigrator } from "@effect/sql-sqlite-do";
|
|
4
4
|
//#region src/internal/migrations.d.ts
|
|
5
5
|
/** The current storage version recorded in `effect_agent_meta`. */
|
|
6
|
-
declare const CurrentDoStorageVersion =
|
|
6
|
+
declare const CurrentDoStorageVersion = 9;
|
|
7
7
|
declare namespace DoStorageVersion_d_exports {
|
|
8
8
|
export { CurrentDoStorageVersion };
|
|
9
9
|
}
|
|
10
10
|
//#endregion
|
|
11
11
|
export { CurrentDoStorageVersion as n, DoStorageVersion_d_exports as t };
|
|
12
|
-
//# sourceMappingURL=DoStorageVersion-
|
|
12
|
+
//# sourceMappingURL=DoStorageVersion-DJwZzqel.d.mts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as CurrentDoStorageVersion } from "./DoStorageVersion-
|
|
1
|
+
import { n as CurrentDoStorageVersion } from "./DoStorageVersion-DJwZzqel.mjs";
|
|
2
2
|
export { CurrentDoStorageVersion };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import { t as CurrentDoStorageVersion } from "./migrations-
|
|
2
|
+
import { t as CurrentDoStorageVersion } from "./migrations-Br6QqMIf.mjs";
|
|
3
3
|
//#region src/DoStorageVersion.ts
|
|
4
|
-
var DoStorageVersion_exports = /* @__PURE__ */ __exportAll({ CurrentDoStorageVersion: () =>
|
|
4
|
+
var DoStorageVersion_exports = /* @__PURE__ */ __exportAll({ CurrentDoStorageVersion: () => 9 });
|
|
5
5
|
//#endregion
|
|
6
6
|
export { CurrentDoStorageVersion, DoStorageVersion_exports as t };
|
|
7
7
|
|
|
@@ -2,7 +2,7 @@ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
|
2
2
|
import { DoStorageConfig } from "./DoStorageConfig.mjs";
|
|
3
3
|
import { DoStorageFailpoint } from "./DoStorageFailpoint.mjs";
|
|
4
4
|
import { DoLedgerError, DoStorageCorruptionError, DoStorageError } from "./DoStorageError.mjs";
|
|
5
|
-
import { a as initializeDoJournal, i as decodeRows } from "./do-journal-
|
|
5
|
+
import { a as initializeDoJournal, i as decodeRows } from "./do-journal-D65Iuln6.mjs";
|
|
6
6
|
import { storageConfigLayer, storageFailpointLayer } from "./DoThreadStore.mjs";
|
|
7
7
|
import { Clock, Context, Crypto, DateTime, Effect, Layer, Option, Schema, Stream } from "effect";
|
|
8
8
|
import * as SqlClientService from "effect/unstable/sql/SqlClient";
|
|
@@ -12,7 +12,7 @@ import { ApprovalDecision, CanonicalSequence, DefinitionDigests, Digest, Persist
|
|
|
12
12
|
import { ThreadStoreDiagnostic } from "effect-agent/thread-store";
|
|
13
13
|
import { BrowserCrypto } from "@effect/platform-browser";
|
|
14
14
|
import { InputMessage } from "effect-agent/messaging";
|
|
15
|
-
import { AbortCommand, AbortIntent, AbortIntentRequest, AdmissionAdmitted, AdmissionConflict, AdmissionFence, AdmissionGroup, AdmissionNotAdmitted, AdmissionPolicyError, AdmissionRequest, AdmissionResult, ApprovalConflict, ApprovalDecisionCommand, ApprovalDecisionIntent, AttachChildToReservationRequest, BeginChildBudgetReleaseRequest, ChildAttachmentSnapshot, ChildBudgetReservationRequest, ChildBudgetReservationSnapshot, ChildReservationConflict, ChildReservationStatus, ChildSettledNotification, Claim, ClaimJoiningRequest, ClaimRequest, InputAppliedMarker, JoinSnapshot, JoinedToHost, JoiningClaim, LedgerCapabilities, LedgerError, MarkInputAppliedRequest, MarkJoinedRequest, MarkReadyRequest, MarkUnknownRequest, OwnershipLost, OwnershipRenewal, OwnershipSnapshot, ParentLinkage, QueueSequence, RecoverySnapshot, RecoverySnapshotRequest, ReleaseChildBudgetRequest, ReleaseOwnershipRequest, RenewOwnershipRequest, ReservedChildBudget, ReservedSettlement, RevertJoiningRequest, Settlement, SettlementConflict, SettlementFinalization, SettlementReservation, SettlementReservationSnapshot, SubmissionAdmissionFence, SubmissionLedger, SubmissionLookup, SubmissionLookupByKey, SubmissionSnapshot, SubmissionState, SubmissionWorkItem, SuspendRequest, SuspensionReason, SuspensionSnapshot, UnknownResolution, UnknownResolutionCommand, UnknownResolutionConflict, UnknownResolutionIntent, settlementFailureFromRecord, submissionAbortRecordId } from "effect-agent/submission-ledger";
|
|
15
|
+
import { AbortCommand, AbortIntent, AbortIntentRequest, AdmissionAdmitted, AdmissionConflict, AdmissionFence, AdmissionGroup, AdmissionNotAdmitted, AdmissionPolicyError, AdmissionRequest, AdmissionResult, ApprovalConflict, ApprovalDecisionCommand, ApprovalDecisionIntent, AttachChildToReservationRequest, BeginChildBudgetReleaseRequest, ChildAttachmentSnapshot, ChildBudgetReservationRequest, ChildBudgetReservationSnapshot, ChildReservationConflict, ChildReservationStatus, ChildSettledNotification, Claim, ClaimJoiningRequest, ClaimRequest, InputAppliedMarker, JoinSnapshot, JoinedToHost, JoiningClaim, LedgerCapabilities, LedgerError, MarkInputAppliedRequest, MarkJoinedRequest, MarkReadyRequest, MarkUnknownRequest, OwnershipLost, OwnershipRenewal, OwnershipSnapshot, ParentLinkage, QueueSequence, RecoverySnapshot, RecoverySnapshotRequest, ReleaseChildBudgetRequest, ReleaseOwnershipRequest, RenewOwnershipRequest, ReservedChildBudget, ReservedSettlement, RevertJoiningRequest, Settlement, SettlementConflict, SettlementFinalization, SettlementReservation, SettlementReservationSnapshot, SubmissionAdmissionFence, SubmissionLedger, SubmissionLookup, SubmissionLookupByKey, SubmissionSnapshot, SubmissionState, SubmissionWorkItem, SuspendRequest, SuspensionReason, SuspensionSnapshot, UnknownResolution, UnknownResolutionCommand, UnknownResolutionConflict, UnknownResolutionIntent, WorkerLedgerState, WorkerStopCommand, settlementFailureFromRecord, submissionAbortRecordId, workerTerminalFromRecord } from "effect-agent/submission-ledger";
|
|
16
16
|
//#region src/DoSubmissionLedger.ts
|
|
17
17
|
var DoSubmissionLedger_exports = /* @__PURE__ */ __exportAll({
|
|
18
18
|
ledgerLayer: () => ledgerLayer,
|
|
@@ -593,6 +593,10 @@ const makeServices = Effect.fn("DoSubmissionLedger.makeServices")(function* () {
|
|
|
593
593
|
replayed: true
|
|
594
594
|
}).pipe(Effect.mapError(internalFailure(operation)));
|
|
595
595
|
}
|
|
596
|
+
if ((yield* sql`SELECT thread_id FROM effect_agent_worker_stops WHERE thread_id = ${validated.threadId}`.pipe(Effect.mapError(sqlFailure(operation)))).length > 0) return yield* AdmissionPolicyError.make({
|
|
597
|
+
reason: "refused",
|
|
598
|
+
code: "worker-stopped"
|
|
599
|
+
});
|
|
596
600
|
const firstRows = yield* sql`
|
|
597
601
|
SELECT worker_admission_json FROM effect_agent_submissions
|
|
598
602
|
WHERE thread_id=${validated.threadId} ORDER BY queue_sequence LIMIT 1
|
|
@@ -1012,6 +1016,7 @@ const makeServices = Effect.fn("DoSubmissionLedger.makeServices")(function* () {
|
|
|
1012
1016
|
if (reservation.value.outcome === "failed" !== (settlementFailure !== void 0)) return yield* corruptionFailure(operation, "effect_agent_settlement_reservations", validated.submissionId, "The reserved outcome and canonical failure diagnostic disagree.");
|
|
1013
1017
|
return {
|
|
1014
1018
|
reservation: reservation.value,
|
|
1019
|
+
reservationRecord,
|
|
1015
1020
|
settlementFailure
|
|
1016
1021
|
};
|
|
1017
1022
|
});
|
|
@@ -1052,10 +1057,27 @@ const makeServices = Effect.fn("DoSubmissionLedger.makeServices")(function* () {
|
|
|
1052
1057
|
}
|
|
1053
1058
|
const settlement = yield* inWriteTransaction(operation, Effect.gen(function* () {
|
|
1054
1059
|
const state = yield* validateFinalization(validated, yield* readReservation(operation, validated.submissionId));
|
|
1055
|
-
const { reservation, settlementFailure } = state;
|
|
1060
|
+
const { reservation, reservationRecord, settlementFailure } = state;
|
|
1056
1061
|
const submission = yield* requireSubmission(operation, validated.submissionId);
|
|
1057
1062
|
if (submission.state === "settled") return yield* replayFinalization(validated, submission, state);
|
|
1058
1063
|
const now = yield* currentInstant;
|
|
1064
|
+
const terminal = submission.worker_admission_json === null ? void 0 : workerTerminalFromRecord(yield* decodeSubmissionSnapshot(operation, submission), reservationRecord);
|
|
1065
|
+
if (terminal !== void 0) {
|
|
1066
|
+
if ((terminal === "completed" ? yield* sql`SELECT submission_id FROM effect_agent_submissions
|
|
1067
|
+
WHERE thread_id = ${submission.thread_id} AND queue_sequence > ${submission.queue_sequence}
|
|
1068
|
+
AND queue_sequence = (SELECT MAX(queue_sequence) FROM effect_agent_submissions WHERE thread_id = ${submission.thread_id})
|
|
1069
|
+
AND (joined_host_submission_id IS NULL OR joined_host_submission_id <> ${submission.submission_id}
|
|
1070
|
+
OR input_applied_record_id IS NULL) LIMIT 1`.pipe(Effect.mapError(sqlFailure(operation))) : []).length === 0) {
|
|
1071
|
+
yield* sql`INSERT OR IGNORE INTO effect_agent_worker_stops (thread_id, terminal)
|
|
1072
|
+
VALUES (${submission.thread_id}, ${terminal})`.pipe(Effect.mapError(sqlFailure(operation)));
|
|
1073
|
+
yield* sql`INSERT OR IGNORE INTO effect_agent_abort_intents (submission_id, author, reason, requested_at)
|
|
1074
|
+
SELECT submission_id, ${submission.principal}, ${`Worker assignment ${terminal}`}, ${now.iso}
|
|
1075
|
+
FROM effect_agent_submissions WHERE thread_id = ${submission.thread_id} AND state <> 'settled'
|
|
1076
|
+
AND submission_id <> ${submission.submission_id}
|
|
1077
|
+
AND (joined_host_submission_id IS NULL OR joined_host_submission_id <> ${submission.submission_id}
|
|
1078
|
+
OR input_applied_record_id IS NULL)`.pipe(Effect.mapError(sqlFailure(operation)));
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1059
1081
|
yield* sql`
|
|
1060
1082
|
UPDATE effect_agent_submissions
|
|
1061
1083
|
SET state = 'settled', settled_outcome = ${reservation.outcome}
|
|
@@ -1082,6 +1104,41 @@ const makeServices = Effect.fn("DoSubmissionLedger.makeServices")(function* () {
|
|
|
1082
1104
|
yield* hitFailpoint("ledger:finalize-settlement:after", operation);
|
|
1083
1105
|
return settlement;
|
|
1084
1106
|
});
|
|
1107
|
+
const inspectWorker = Effect.fn("DoSubmissionLedger.inspectWorker")(function* (threadId) {
|
|
1108
|
+
const operation = "inspect worker";
|
|
1109
|
+
return yield* sql.withTransaction(Effect.gen(function* () {
|
|
1110
|
+
const read = Effect.fnUntraced(function* (active) {
|
|
1111
|
+
const rows = yield* sql`SELECT ${sql.literal(SUBMISSION_COLUMNS)} FROM effect_agent_submissions
|
|
1112
|
+
WHERE thread_id = ${threadId} ${active ? sql`AND state <> 'settled'` : sql``}
|
|
1113
|
+
ORDER BY queue_sequence ${active ? sql`ASC` : sql`DESC`} LIMIT 1`.pipe(Effect.mapError(sqlFailure(operation)));
|
|
1114
|
+
const decoded = yield* decodeSubmissionRows(operation, threadId, rows);
|
|
1115
|
+
return decoded[0] === void 0 ? null : yield* decodeSubmissionSnapshot(operation, decoded[0]);
|
|
1116
|
+
});
|
|
1117
|
+
const latest = yield* read(false);
|
|
1118
|
+
const active = yield* read(true);
|
|
1119
|
+
const stops = yield* sql`SELECT terminal FROM effect_agent_worker_stops WHERE thread_id = ${threadId}`.pipe(Effect.mapError(sqlFailure(operation)));
|
|
1120
|
+
return yield* Schema.decodeUnknownEffect(Schema.toType(WorkerLedgerState))({
|
|
1121
|
+
latest,
|
|
1122
|
+
active,
|
|
1123
|
+
stopped: stops.length > 0,
|
|
1124
|
+
...stops[0] === void 0 || stops[0].terminal === null ? {} : { terminal: stops[0].terminal }
|
|
1125
|
+
}).pipe(Effect.mapError(internalFailure(operation)));
|
|
1126
|
+
})).pipe(Effect.catchTag("SqlError", (cause) => sqlFailure(operation)(cause)));
|
|
1127
|
+
});
|
|
1128
|
+
const stopWorker = Effect.fn("DoSubmissionLedger.stopWorker")(function* (request) {
|
|
1129
|
+
const operation = "ledger stop worker";
|
|
1130
|
+
const validated = yield* Schema.decodeEffect(WorkerStopCommand)(request).pipe(Effect.mapError(internalFailure(operation)));
|
|
1131
|
+
return yield* inWriteTransaction(operation, Effect.gen(function* () {
|
|
1132
|
+
const now = yield* currentInstant;
|
|
1133
|
+
yield* sql`INSERT OR IGNORE INTO effect_agent_worker_stops (thread_id) VALUES (${validated.threadId})`.pipe(Effect.mapError(sqlFailure(operation)));
|
|
1134
|
+
yield* sql`INSERT OR IGNORE INTO effect_agent_abort_intents (submission_id, author, reason, requested_at)
|
|
1135
|
+
SELECT submission_id, ${validated.author}, 'Worker owner stopped the worker', ${now.iso}
|
|
1136
|
+
FROM effect_agent_submissions WHERE thread_id = ${validated.threadId} AND state <> 'settled'`.pipe(Effect.mapError(sqlFailure(operation)));
|
|
1137
|
+
return (yield* sql`SELECT o.submission_id FROM effect_agent_submission_ownership o
|
|
1138
|
+
JOIN effect_agent_submissions s ON s.submission_id = o.submission_id
|
|
1139
|
+
WHERE s.thread_id = ${validated.threadId} AND s.state <> 'settled'`.pipe(Effect.mapError(sqlFailure(operation)))).length;
|
|
1140
|
+
}));
|
|
1141
|
+
});
|
|
1085
1142
|
const requestAbort = Effect.fn("DoSubmissionLedger.requestAbort")(function* (request) {
|
|
1086
1143
|
const operation = "ledger request abort";
|
|
1087
1144
|
const validated = yield* Schema.decodeEffect(Schema.toType(AbortCommand))(request).pipe(Effect.mapError(internalFailure(operation)));
|
|
@@ -1142,6 +1199,7 @@ const makeServices = Effect.fn("DoSubmissionLedger.makeServices")(function* () {
|
|
|
1142
1199
|
message: `Host submission ${validated.hostSubmissionId} does not belong to thread ${validated.threadId}.`
|
|
1143
1200
|
});
|
|
1144
1201
|
yield* requireOwnership(operation, host, validated.ownershipToken);
|
|
1202
|
+
if ((yield* sql`SELECT thread_id FROM effect_agent_worker_stops WHERE thread_id = ${validated.threadId}`.pipe(Effect.mapError(sqlFailure(operation)))).length > 0) return [];
|
|
1145
1203
|
const laterRows = yield* sql`
|
|
1146
1204
|
SELECT ${sql.literal(SUBMISSION_COLUMNS)}
|
|
1147
1205
|
FROM effect_agent_submissions
|
|
@@ -1845,6 +1903,8 @@ const makeServices = Effect.fn("DoSubmissionLedger.makeServices")(function* () {
|
|
|
1845
1903
|
reserveSettlement,
|
|
1846
1904
|
finalizeSettlement,
|
|
1847
1905
|
requestAbort,
|
|
1906
|
+
stopWorker,
|
|
1907
|
+
inspectWorker,
|
|
1848
1908
|
claimJoining,
|
|
1849
1909
|
markJoined,
|
|
1850
1910
|
revertJoining,
|