Move rumination speech under parent control
This commit is contained in:
parent
9944076e7b
commit
d154aabc69
13 changed files with 374 additions and 22 deletions
|
|
@ -75,6 +75,22 @@ const deliveryReceiptSchema = z.object({
|
|||
previewHash: z.string().trim().min(1).optional(),
|
||||
}).strict();
|
||||
|
||||
const candidateDeliveryTargetSchema = z.object({
|
||||
mode: z.enum(["channel", "owner_dm"]).default("channel"),
|
||||
channelId: z.string().trim().min(1).optional(),
|
||||
replyToMessageId: z.string().trim().min(1).optional(),
|
||||
personaName: z.string().trim().min(1).optional(),
|
||||
personaAvatarUrl: z.string().trim().min(1).optional(),
|
||||
}).strict().superRefine((delivery, context) => {
|
||||
if (delivery.mode === "channel" && !delivery.channelId) {
|
||||
context.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Channel candidate interventions must include a channelId delivery target.",
|
||||
path: ["channelId"],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const distilledMemorySchema = z.object({
|
||||
memoryId: nonEmptyStringSchema,
|
||||
kind: z.enum(["distilled_seam", "identity_seam", "project_seam", "room_observation", "dream_residue"]),
|
||||
|
|
@ -159,6 +175,7 @@ const candidateInterventionSchema = z.object({
|
|||
target: thoughtTargetSchema.optional(),
|
||||
summary: boundedTextSchema,
|
||||
draft: boundedTextSchema,
|
||||
deliveryTarget: candidateDeliveryTargetSchema.optional(),
|
||||
priority: z.number().min(0).max(1).default(0.5),
|
||||
mustEventuallyShare: z.boolean().default(false),
|
||||
createdAt: timestampSchema,
|
||||
|
|
@ -416,6 +433,11 @@ export const voidSelfStateOperationSchema = z.discriminatedUnion("operation", [
|
|||
retiredAt: timestampSchema,
|
||||
reason: z.string().trim().min(1).max(1000),
|
||||
}).strict(),
|
||||
z.object({
|
||||
operation: z.literal("mark_candidate_intervention_spoken"),
|
||||
interventionId: nonEmptyStringSchema,
|
||||
receipt: deliveryReceiptSchema,
|
||||
}).strict(),
|
||||
z.object({
|
||||
operation: z.literal("upsert_agency_pressure"),
|
||||
pressure: agencyPressureSchema,
|
||||
|
|
|
|||
|
|
@ -180,6 +180,9 @@ function applyTypedOperation(
|
|||
case "retire_candidate_intervention":
|
||||
retireCandidateIntervention(state.candidateInterventions, operation);
|
||||
return;
|
||||
case "mark_candidate_intervention_spoken":
|
||||
markCandidateInterventionSpoken(state, operation);
|
||||
return;
|
||||
case "upsert_agency_pressure":
|
||||
upsertBy(state.agencyPressure.pressures, operation.pressure, (entry) => entry.pressureId);
|
||||
state.agencyPressure.pressures = state.agencyPressure.pressures
|
||||
|
|
@ -309,6 +312,28 @@ function retireCandidateIntervention(
|
|||
candidates.updatedAt = operation.retiredAt;
|
||||
}
|
||||
|
||||
function markCandidateInterventionSpoken(
|
||||
state: VoidSelfStateTypedProjection,
|
||||
operation: Extract<VoidSelfStateOperation, { operation: "mark_candidate_intervention_spoken" }>,
|
||||
): void {
|
||||
upsertBy(state.speechReceipts.recentReceipts, operation.receipt, (entry) => entry.receiptKey);
|
||||
state.speechReceipts.recentReceipts = state.speechReceipts.recentReceipts
|
||||
.sort((left, right) => left.sentAt.localeCompare(right.sentAt))
|
||||
.slice(-24);
|
||||
state.speechReceipts.updatedAt = operation.receipt.sentAt;
|
||||
closeCasesForReceipt(state.moderationCursor, operation.receipt);
|
||||
|
||||
for (const intervention of state.candidateInterventions.interventions) {
|
||||
if (intervention.interventionId !== operation.interventionId) {
|
||||
continue;
|
||||
}
|
||||
intervention.status = "spoken";
|
||||
intervention.spokenAt = operation.receipt.sentAt;
|
||||
intervention.updatedAt = operation.receipt.sentAt;
|
||||
}
|
||||
state.candidateInterventions.updatedAt = operation.receipt.sentAt;
|
||||
}
|
||||
|
||||
function upsertBy<T>(entries: T[], value: T, keyOf: (value: T) => string): void {
|
||||
const key = keyOf(value);
|
||||
const index = entries.findIndex((entry) => keyOf(entry) === key);
|
||||
|
|
|
|||
Loading…
Reference in a new issue