@agent-native/core-corpus 0.216.0 → 0.218.0
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/corpus/README.md +1 -1
- package/corpus/templates/analytics/.agents/skills/session-replay/SKILL.md +61 -1
- package/corpus/templates/analytics/AGENTS.md +1 -1
- package/corpus/templates/analytics/CHANGELOG.md +3 -0
- package/corpus/templates/analytics/actions/get-session-replay-summary.ts +9 -65
- package/corpus/templates/analytics/actions/list-event-catalog.ts +1 -1
- package/corpus/templates/analytics/actions/list-session-outputs.ts +40 -0
- package/corpus/templates/analytics/actions/list-session-recordings.ts +17 -4
- package/corpus/templates/analytics/actions/view-screen.ts +29 -3
- package/corpus/templates/analytics/app/components/layout/Sidebar.tsx +38 -167
- package/corpus/templates/analytics/app/i18n/en-US.ts +27 -0
- package/corpus/templates/analytics/app/pages/sessions/EventCatalogPage.tsx +18 -1
- package/corpus/templates/analytics/app/pages/sessions/SessionDetailPage.tsx +3 -1
- package/corpus/templates/analytics/app/pages/sessions/SessionOutputs.tsx +197 -0
- package/corpus/templates/analytics/app/pages/sessions/SessionsTriagePage.tsx +114 -4
- package/corpus/templates/analytics/changelog/2026-10-15-sessions-can-find-people-who-made-a-slides-deck-but-didn-t-p.md +6 -0
- package/corpus/templates/analytics/changelog/2026-10-16-owned-and-shared-chats-appear-in-separate-history-sections.md +6 -0
- package/corpus/templates/analytics/changelog/2026-10-16-the-activation-funnel-counts-visitors-who-decline-analytics-.md +6 -0
- package/corpus/templates/analytics/server/db/schema.ts +67 -0
- package/corpus/templates/analytics/server/lib/canonical-first-party-dashboard-repair.ts +9 -0
- package/corpus/templates/analytics/server/lib/first-party-analytics.ts +28 -22
- package/corpus/templates/analytics/server/lib/first-party-metric-catalog.ts +36 -1
- package/corpus/templates/analytics/server/lib/output-outcomes.ts +712 -0
- package/corpus/templates/analytics/server/lib/replay-origins.ts +33 -0
- package/corpus/templates/analytics/server/lib/session-event-index.ts +20 -0
- package/corpus/templates/analytics/server/lib/session-performance.ts +6 -40
- package/corpus/templates/analytics/server/lib/session-recording-associations.ts +30 -1
- package/corpus/templates/analytics/server/lib/session-replay-triage.ts +99 -0
- package/corpus/templates/analytics/server/lib/session-replay.ts +45 -31
- package/corpus/templates/analytics/server/lib/sessions-triage-lab.ts +8 -2
- package/corpus/templates/analytics/server/plugins/db.ts +46 -0
- package/corpus/templates/analytics/shared/output-use.ts +205 -0
- package/corpus/templates/analytics/shared/session-events.ts +6 -0
- package/corpus/templates/assets/CHANGELOG.md +6 -0
- package/corpus/templates/assets/app/components/layout/Sidebar.tsx +51 -117
- package/corpus/templates/assets/changelog/2026-10-16-owned-and-shared-chats-appear-in-separate-history-sections.md +6 -0
- package/corpus/templates/brain/app/components/layout/Sidebar.tsx +34 -101
- package/corpus/templates/brain/app/routes/sources.tsx +1 -1
- package/corpus/templates/brain/vitest.config.ts +7 -0
- package/corpus/templates/calendar/CHANGELOG.md +12 -0
- package/corpus/templates/calendar/actions/create-event.ts +2 -4
- package/corpus/templates/calendar/actions/update-event.ts +35 -6
- package/corpus/templates/calendar/app/pages/BookingLinksPage.tsx +1 -1
- package/corpus/templates/calendar/changelog/2026-10-16-booking-links-show-localized-visibility-badges.md +6 -0
- package/corpus/templates/calendar/changelog/2026-10-21-solo-events-avoid-notification-approval.md +6 -0
- package/corpus/templates/chat/app/components/layout/Sidebar.tsx +62 -101
- package/corpus/templates/clips/CHANGELOG.md +7 -20
- package/corpus/templates/clips/app/components/meetings/share-meeting-dialog.tsx +20 -77
- package/corpus/templates/clips/app/components/player/share-dialog.tsx +63 -90
- package/corpus/templates/clips/app/components/sharing/share-test-support.tsx +180 -0
- package/corpus/templates/clips/app/components/sharing/share-ui.tsx +5 -584
- package/corpus/templates/clips/changelog/2026-10-16-share-dialogs-make-it-easier-to-see-who-has-access-and-manag.md +6 -0
- package/corpus/templates/clips/changelog/2026-10-21-share-panels-describe-general-access-in-a-sentence.md +6 -0
- package/corpus/templates/community/qr/package.json +1 -1
- package/corpus/templates/content/.agents/skills/document-editing/references/databases.md +6 -3
- package/corpus/templates/content/CHANGELOG.md +10 -0
- package/corpus/templates/content/actions/_browser-document-save-attempt.ts +23 -1
- package/corpus/templates/content/actions/_builder-cms-blob-custody.ts +467 -0
- package/corpus/templates/content/actions/_builder-cms-execution-lease.ts +17 -0
- package/corpus/templates/content/actions/_builder-cms-intent-lookup.ts +5 -0
- package/corpus/templates/content/actions/_builder-cms-read-client.ts +881 -21
- package/corpus/templates/content/actions/_builder-cms-write-adapter.ts +28 -2
- package/corpus/templates/content/actions/_builder-cms-write-client.ts +109 -11
- package/corpus/templates/content/actions/_builder-docs-client.ts +1 -0
- package/corpus/templates/content/actions/_builder-private-blob.test-fixture.ts +90 -0
- package/corpus/templates/content/actions/_builder-source-execution-guard.ts +48 -0
- package/corpus/templates/content/actions/_content-save-outcomes.ts +5 -0
- package/corpus/templates/content/actions/_database-source-utils.ts +290 -8
- package/corpus/templates/content/actions/_database-utils.ts +93 -7
- package/corpus/templates/content/actions/_database-view-setup.ts +21 -2
- package/corpus/templates/content/actions/_delete-content-space.ts +8 -1
- package/corpus/templates/content/actions/_github-source-freshness.ts +30 -4
- package/corpus/templates/content/actions/add-content-database-source-field-property.ts +23 -6
- package/corpus/templates/content/actions/cancel-prepared-builder-source-update.ts +110 -26
- package/corpus/templates/content/actions/change-content-database-source-role.ts +51 -7
- package/corpus/templates/content/actions/delete-document.ts +41 -3
- package/corpus/templates/content/actions/disconnect-content-database-source.ts +68 -2
- package/corpus/templates/content/actions/disconnect-local-folder-source.ts +33 -2
- package/corpus/templates/content/actions/execute-builder-source-execution.ts +900 -140
- package/corpus/templates/content/actions/get-document.ts +2 -0
- package/corpus/templates/content/actions/permanently-delete-document.ts +6 -0
- package/corpus/templates/content/actions/prepare-builder-source-execution.ts +155 -13
- package/corpus/templates/content/actions/prepare-builder-source-review.ts +299 -73
- package/corpus/templates/content/actions/set-live-body-switch.ts +45 -0
- package/corpus/templates/content/actions/update-document.ts +139 -20
- package/corpus/templates/content/actions/validate-builder-source-execution.ts +135 -26
- package/corpus/templates/content/app/components/editor/CommentsSidebar.tsx +119 -30
- package/corpus/templates/content/app/components/editor/DocumentEditor.tsx +56 -13
- package/corpus/templates/content/app/components/editor/SuggestionText.tsx +18 -3
- package/corpus/templates/content/app/components/editor/VisualEditor.tsx +89 -22
- package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +23 -0
- package/corpus/templates/content/app/components/editor/database/GitHubSourceStatusLine.tsx +27 -2
- package/corpus/templates/content/app/components/editor/database/ListItemLayout.tsx +32 -8
- package/corpus/templates/content/app/components/editor/database/ListItemRow.tsx +27 -2
- package/corpus/templates/content/app/components/editor/database-sources/BuilderSourceReviewDialog.tsx +1 -0
- package/corpus/templates/content/app/components/editor/extensions/SuggestionHighlight.ts +383 -34
- package/corpus/templates/content/app/components/editor/suggestions/draft-session.ts +31 -0
- package/corpus/templates/content/app/components/editor/suggestions/presentation-rebase.ts +82 -4
- package/corpus/templates/content/app/global.css +31 -0
- package/corpus/templates/content/app/hooks/use-content-database.ts +40 -2
- package/corpus/templates/content/app/hooks/use-documents.ts +14 -0
- package/corpus/templates/content/app/i18n-data.ts +1 -0
- package/corpus/templates/content/changelog/2026-10-16-accepting-a-suggestion-on-a-page-that-changed-since-it-was-s.md +6 -0
- package/corpus/templates/content/changelog/2026-10-17-builder-content-avoids-retrying-a-write-when-builder-accepte.md +6 -0
- package/corpus/templates/content/changelog/2026-10-18-link-a-new-collection-to-a-github-folder-from-its-sources.md +1 -1
- package/corpus/templates/content/changelog/2026-10-20-builder-content-sync-keeps-read-and-write-status-accurate-wh.md +6 -0
- package/corpus/templates/content/changelog/2026-10-20-suggested-edits-that-add-remove-split-or-merge-paragraphs-li.md +6 -0
- package/corpus/templates/content/changelog/2026-10-21-list-rows-can-show-each-pages-first-lines.md +6 -0
- package/corpus/templates/content/changelog/2026-10-22-a-collection-linked-to-a-big-github-folder-fills-faster-and-p.md +6 -0
- package/corpus/templates/content/docs/product/capabilities/content.source.adapters.md +29 -0
- package/corpus/templates/content/parity/matrix.md +42 -42
- package/corpus/templates/content/parity/matrix.ts +3 -1
- package/corpus/templates/content/server/db/schema.ts +20 -0
- package/corpus/templates/content/server/lib/content-trash-purge.ts +15 -1
- package/corpus/templates/content/server/lib/live-body-writer.ts +138 -26
- package/corpus/templates/content/server/live-copy/binding.ts +31 -0
- package/corpus/templates/content/server/live-copy/bounded-task.d.ts +6 -0
- package/corpus/templates/content/server/live-copy/exec-db.ts +1 -0
- package/corpus/templates/content/server/live-copy/holds.ts +59 -0
- package/corpus/templates/content/server/live-copy/persist.ts +656 -0
- package/corpus/templates/content/server/live-copy/switch.ts +136 -0
- package/corpus/templates/content/server/live-copy/task-names.ts +4 -0
- package/corpus/templates/content/server/live-copy/tasks.ts +183 -0
- package/corpus/templates/content/server/live-copy/write-cause.ts +85 -0
- package/corpus/templates/content/server/live-copy/write.ts +85 -0
- package/corpus/templates/content/server/plugins/builder-private-payload-cleanup.ts +22 -0
- package/corpus/templates/content/server/plugins/collab.ts +3 -0
- package/corpus/templates/content/server/plugins/db.ts +28 -0
- package/corpus/templates/content/shared/api.ts +30 -1
- package/corpus/templates/content/shared/database-item-layout.ts +54 -22
- package/corpus/templates/content/shared/document-intent-merge.ts +16 -9
- package/corpus/templates/content/shared/og-description.ts +258 -36
- package/corpus/templates/content/shared/suggestion-diff.ts +23 -6
- package/corpus/templates/content/shared/suggestion-formatting.ts +44 -14
- package/corpus/templates/content/shared/suggestion-text.ts +20 -5
- package/corpus/templates/design/.agents/skills/design-templates/SKILL.md +5 -1
- package/corpus/templates/design/.generated/bridge/shader-runtime.generated.ts +25 -4
- package/corpus/templates/design/CHANGELOG.md +5 -0
- package/corpus/templates/design/actions/get-getting-started.ts +53 -0
- package/corpus/templates/design/app/components/design/DesignCanvas.tsx +10 -0
- package/corpus/templates/design/app/components/design/bridge/native-shader-runtime.bridge.ts +132 -79
- package/corpus/templates/design/app/components/design/bridge/native-source-provider.ts +268 -130
- package/corpus/templates/design/app/components/design/bridge/native-worker-scene-host.ts +122 -42
- package/corpus/templates/design/app/components/design/bridge/shader-runtime.bridge.ts +41 -4
- package/corpus/templates/design/app/components/design/design-canvas/text-content-change-result.ts +46 -12
- package/corpus/templates/design/app/components/home/DesignHomeLibrary.tsx +15 -8
- package/corpus/templates/design/app/components/layout/GettingStarted.tsx +50 -0
- package/corpus/templates/design/app/components/layout/Sidebar.tsx +3 -0
- package/corpus/templates/design/app/components/templates/DesignTemplateGrid.tsx +163 -0
- package/corpus/templates/design/app/components/templates/DesignTemplateLibrary.tsx +65 -78
- package/corpus/templates/design/app/components/templates/TemplatePreview.tsx +6 -2
- package/corpus/templates/design/app/global.css +6 -0
- package/corpus/templates/design/app/i18n/en-US.ts +17 -0
- package/corpus/templates/design/app/lib/canvas-load-outcome.ts +147 -0
- package/corpus/templates/design/app/lib/canvas-outcome-tracking.ts +531 -0
- package/corpus/templates/design/app/lib/canvas-style-kind.ts +50 -0
- package/corpus/templates/design/app/pages/DesignSystems.tsx +1 -1
- package/corpus/templates/design/app/pages/Index.tsx +28 -67
- package/corpus/templates/design/app/pages/design-editor/commands/commit-visual-styles.ts +86 -29
- package/corpus/templates/design/app/pages/design-editor/commands/save-file-content.ts +38 -3
- package/corpus/templates/design/app/pages/design-editor/domains/use-editor-core.ts +9 -0
- package/corpus/templates/design/app/pages/design-editor/domains/use-editor-files-and-saving.ts +2 -0
- package/corpus/templates/design/changelog/2026-10-16-design-pages-use-localized-visibility-badges-and-a-shared-ow.md +6 -0
- package/corpus/templates/design/changelog/2026-10-21-a-getting-started-checklist-at-the-bottom-of-the-sidebar-tra.md +6 -0
- package/corpus/templates/design/changelog/2026-10-21-templates-now-open-a-read-only-preview-from-the-card-and-the.md +6 -0
- package/corpus/templates/design/changelog/2026-10-22-collapsed-shader-layers-no-longer-interrupt-other-shaders-on.md +6 -0
- package/corpus/templates/design/changelog/2026-10-22-shader-fills-keep-rendering-when-other-screen-content-cannot.md +6 -0
- package/corpus/templates/design/scripts/design-export-validation/export-baseline.json +24 -0
- package/corpus/templates/design/server/lib/getting-started.ts +267 -0
- package/corpus/templates/design/server/plugins/getting-started.ts +5 -0
- package/corpus/templates/design/shared/design-template-presets/analytics-dashboard.ts +127 -0
- package/corpus/templates/design/shared/design-template-presets/design-studio.ts +98 -0
- package/corpus/templates/design/shared/design-template-presets/messaging-app.ts +101 -0
- package/corpus/templates/design/shared/design-template-presets/project-tasks.ts +120 -0
- package/corpus/templates/design/shared/design-template-presets.ts +8 -0
- package/corpus/templates/dispatch/CHANGELOG.md +4 -0
- package/corpus/templates/dispatch/app/i18n-data.ts +75 -0
- package/corpus/templates/dispatch/changelog/2026-10-21-owned-and-shared-chats-appear-in-separate-history-sections.md +6 -0
- package/corpus/templates/factory/app/components/layout/Sidebar.tsx +34 -100
- package/corpus/templates/forms/app/pages/FormsListPage.tsx +1 -1
- package/corpus/templates/forms/server/plugins/agent-chat.ts +1 -1
- package/corpus/templates/plan/CHANGELOG.md +6 -0
- package/corpus/templates/plan/app/components/layout/Sidebar.tsx +34 -109
- package/corpus/templates/plan/changelog/2026-10-16-owned-and-shared-chats-appear-in-separate-history-sections.md +6 -0
- package/corpus/templates/slides/CHANGELOG.md +7 -0
- package/corpus/templates/slides/actions/delete-deck.ts +7 -0
- package/corpus/templates/slides/app/components/deck/DeckCard.tsx +1 -1
- package/corpus/templates/slides/app/components/design-system/DesignSystemCard.tsx +1 -1
- package/corpus/templates/slides/app/pages/Index.tsx +7 -2
- package/corpus/templates/slides/changelog/2026-10-16-deck-lists-use-the-shared-ownership-filter-and-visibility-ba.md +6 -0
- package/corpus/templates/slides/changelog/2026-10-21-connected-deck-deletion-requires-approval.md +6 -0
- package/corpus/templates/slides/scripts/edit-fidelity/client-action.ts +61 -0
- package/corpus/templates/slides/scripts/edit-fidelity/run.ts +10 -0
- package/package.json +1 -1
- package/corpus/templates/chat/app/lib/sidebar-thread-state.ts +0 -29
- package/corpus/templates/slides/app/components/deck/DeckFilterMenu.tsx +0 -83
|
@@ -15,6 +15,7 @@ import { z } from "zod";
|
|
|
15
15
|
|
|
16
16
|
import { getDb, schema } from "../server/db/index.js";
|
|
17
17
|
import { parseDocumentHideFromSearch } from "../server/lib/documents.js";
|
|
18
|
+
import { liveBodyWriterGate } from "../server/lib/live-body-writer.js";
|
|
18
19
|
import { favoriteDocumentIds } from "./_content-favorites.js";
|
|
19
20
|
import {
|
|
20
21
|
getDatabaseByDocumentId,
|
|
@@ -427,6 +428,7 @@ export default defineAction({
|
|
|
427
428
|
bodyRevision: doc.bodyRevision,
|
|
428
429
|
collabContentRevision:
|
|
429
430
|
doc.collabBodyRevision === doc.bodyRevision ? revision : null,
|
|
431
|
+
writePath: (await liveBodyWriterGate(doc.id)).writePath,
|
|
430
432
|
contentHash: documentContentHash(doc.content ?? ""),
|
|
431
433
|
description: doc.description,
|
|
432
434
|
icon: doc.icon,
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
authorizedTrashDocumentIds,
|
|
11
11
|
hashTrashScopeToken,
|
|
12
12
|
} from "../server/lib/content-trash-purge.js";
|
|
13
|
+
import { cleanupBuilderPrivatePayload } from "./_builder-cms-blob-custody.js";
|
|
13
14
|
import {
|
|
14
15
|
deleteTrashedDocumentSubtree,
|
|
15
16
|
PermanentDeleteScopeChangedError,
|
|
@@ -72,6 +73,7 @@ export default defineAction({
|
|
|
72
73
|
"Permanent deletion requires a current reviewed exact plan for this Trash item",
|
|
73
74
|
{ errorCode: "stale_scope", statusCode: 409 },
|
|
74
75
|
);
|
|
76
|
+
const deletedBlobReferences = new Set<string>();
|
|
75
77
|
let deleted: string[];
|
|
76
78
|
try {
|
|
77
79
|
deleted = await db.transaction(async (tx) => {
|
|
@@ -86,6 +88,7 @@ export default defineAction({
|
|
|
86
88
|
transactionDb,
|
|
87
89
|
id,
|
|
88
90
|
access.resource.ownerEmail as string,
|
|
91
|
+
deletedBlobReferences,
|
|
89
92
|
items.map((item) => ({
|
|
90
93
|
documentId: item.documentId,
|
|
91
94
|
expectedTrashedAt: item.expectedTrashedAt,
|
|
@@ -114,6 +117,9 @@ export default defineAction({
|
|
|
114
117
|
});
|
|
115
118
|
throw error;
|
|
116
119
|
}
|
|
120
|
+
for (const reference of deletedBlobReferences) {
|
|
121
|
+
await cleanupBuilderPrivatePayload(reference, "deleted document source");
|
|
122
|
+
}
|
|
117
123
|
await writeAppState("refresh-signal", { ts: Date.now() });
|
|
118
124
|
return {
|
|
119
125
|
success: true,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defineAction } from "@agent-native/core/action";
|
|
1
|
+
import { defineAction, fail } from "@agent-native/core/action";
|
|
2
2
|
import { assertAccess } from "@agent-native/core/sharing";
|
|
3
|
-
import { eq } from "drizzle-orm";
|
|
3
|
+
import { and, eq, isNull } from "drizzle-orm";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
|
|
6
6
|
import { getDb, schema } from "../server/db/index.js";
|
|
@@ -8,7 +8,17 @@ import type {
|
|
|
8
8
|
ContentDatabaseResponse,
|
|
9
9
|
PrepareBuilderSourceExecutionRequest,
|
|
10
10
|
} from "../shared/api.js";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
builderExecutionPayloadReference,
|
|
13
|
+
cleanupBuilderPrivatePayload,
|
|
14
|
+
enqueueBuilderPrivatePayloadCleanup,
|
|
15
|
+
readBuilderExecutionPayload,
|
|
16
|
+
storeBuilderExecutionPayload,
|
|
17
|
+
} from "./_builder-cms-blob-custody.js";
|
|
18
|
+
import {
|
|
19
|
+
buildBuilderCmsExecutionPlan,
|
|
20
|
+
validateBuilderCmsExecutionDryRun,
|
|
21
|
+
} from "./_builder-cms-write-adapter.js";
|
|
12
22
|
import { claimBuilderSourceExecutionGate } from "./_builder-source-execution-claim.js";
|
|
13
23
|
import { shouldPreserveBuilderExecution } from "./_builder-source-execution-preservation.js";
|
|
14
24
|
import { createBuilderSourceTiming } from "./_builder-source-timings.js";
|
|
@@ -89,6 +99,12 @@ export default defineAction({
|
|
|
89
99
|
idempotencyKey: plan.idempotencyKey,
|
|
90
100
|
now,
|
|
91
101
|
});
|
|
102
|
+
let nextReference: string | null = null;
|
|
103
|
+
let previousReference: string | null = null;
|
|
104
|
+
let attemptedPayloadJson: string | null = null;
|
|
105
|
+
let observedPayloadJson: string | null | undefined;
|
|
106
|
+
let replacementCommitted = false;
|
|
107
|
+
let replacementPrepared = false;
|
|
92
108
|
try {
|
|
93
109
|
await db.transaction(async (tx) => {
|
|
94
110
|
const [existing] = await tx
|
|
@@ -96,6 +112,7 @@ export default defineAction({
|
|
|
96
112
|
.from(schema.contentDatabaseSourceExecutions)
|
|
97
113
|
.where(eq(schema.contentDatabaseSourceExecutions.id, executionId))
|
|
98
114
|
.limit(1);
|
|
115
|
+
observedPayloadJson = existing?.payloadJson ?? null;
|
|
99
116
|
|
|
100
117
|
const preserve =
|
|
101
118
|
existing &&
|
|
@@ -105,19 +122,105 @@ export default defineAction({
|
|
|
105
122
|
});
|
|
106
123
|
|
|
107
124
|
if (existing && !preserve) {
|
|
108
|
-
await
|
|
125
|
+
const storedPayload = await readBuilderExecutionPayload({
|
|
126
|
+
payloadJson: existing.payloadJson,
|
|
127
|
+
binding: {
|
|
128
|
+
ownerEmail: database.ownerEmail,
|
|
129
|
+
sourceId: source.id,
|
|
130
|
+
changeSetId: changeSet.id,
|
|
131
|
+
executionId: existing.id,
|
|
132
|
+
idempotencyKey: plan.idempotencyKey,
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
const existingDryRun = validateBuilderCmsExecutionDryRun({
|
|
136
|
+
storedPayload,
|
|
137
|
+
plan,
|
|
138
|
+
now,
|
|
139
|
+
}).dryRun;
|
|
140
|
+
if (existingDryRun?.status === "stale") {
|
|
141
|
+
fail(
|
|
142
|
+
"Builder execution changed since this change was reviewed. Refresh and review it again.",
|
|
143
|
+
{
|
|
144
|
+
errorCode: "builder_execution_stale",
|
|
145
|
+
statusCode: 409,
|
|
146
|
+
details: { mismatches: existingDryRun.mismatches },
|
|
147
|
+
},
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const payloadJson = await storeBuilderExecutionPayload({
|
|
152
|
+
payload: plan.payload as unknown as Record<string, unknown>,
|
|
153
|
+
binding: {
|
|
154
|
+
ownerEmail: database.ownerEmail,
|
|
155
|
+
sourceId: source.id,
|
|
156
|
+
changeSetId: changeSet.id,
|
|
157
|
+
executionId: existing.id,
|
|
158
|
+
idempotencyKey: plan.idempotencyKey,
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
attemptedPayloadJson = payloadJson;
|
|
162
|
+
nextReference = builderExecutionPayloadReference(payloadJson);
|
|
163
|
+
previousReference = builderExecutionPayloadReference(
|
|
164
|
+
existing.payloadJson,
|
|
165
|
+
);
|
|
166
|
+
const [updated] = await tx
|
|
109
167
|
.update(schema.contentDatabaseSourceExecutions)
|
|
110
168
|
.set({
|
|
111
169
|
state: plan.state,
|
|
112
170
|
summary: plan.summary,
|
|
113
|
-
payloadJson
|
|
171
|
+
payloadJson,
|
|
172
|
+
attemptToken: null,
|
|
114
173
|
lastError: plan.lastError,
|
|
115
174
|
updatedAt: now,
|
|
116
175
|
})
|
|
117
176
|
.where(
|
|
118
|
-
|
|
177
|
+
and(
|
|
178
|
+
eq(schema.contentDatabaseSourceExecutions.id, existing.id),
|
|
179
|
+
eq(
|
|
180
|
+
schema.contentDatabaseSourceExecutions.payloadJson,
|
|
181
|
+
existing.payloadJson,
|
|
182
|
+
),
|
|
183
|
+
eq(
|
|
184
|
+
schema.contentDatabaseSourceExecutions.state,
|
|
185
|
+
existing.state,
|
|
186
|
+
),
|
|
187
|
+
existing.attemptToken
|
|
188
|
+
? eq(
|
|
189
|
+
schema.contentDatabaseSourceExecutions.attemptToken,
|
|
190
|
+
existing.attemptToken,
|
|
191
|
+
)
|
|
192
|
+
: isNull(
|
|
193
|
+
schema.contentDatabaseSourceExecutions.attemptToken,
|
|
194
|
+
),
|
|
195
|
+
),
|
|
196
|
+
)
|
|
197
|
+
.returning({ id: schema.contentDatabaseSourceExecutions.id });
|
|
198
|
+
if (!updated) {
|
|
199
|
+
fail("Builder execution changed during prepare.", {
|
|
200
|
+
errorCode: "builder_execution_changed",
|
|
201
|
+
statusCode: 409,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
if (previousReference && previousReference !== nextReference) {
|
|
205
|
+
await enqueueBuilderPrivatePayloadCleanup(
|
|
206
|
+
tx as unknown as ReturnType<typeof getDb>,
|
|
207
|
+
previousReference,
|
|
119
208
|
);
|
|
209
|
+
}
|
|
210
|
+
replacementPrepared = true;
|
|
120
211
|
} else if (!existing) {
|
|
212
|
+
const payloadJson = await storeBuilderExecutionPayload({
|
|
213
|
+
payload: plan.payload as unknown as Record<string, unknown>,
|
|
214
|
+
binding: {
|
|
215
|
+
ownerEmail: database.ownerEmail,
|
|
216
|
+
sourceId: source.id,
|
|
217
|
+
changeSetId: changeSet.id,
|
|
218
|
+
executionId,
|
|
219
|
+
idempotencyKey: plan.idempotencyKey,
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
attemptedPayloadJson = payloadJson;
|
|
223
|
+
nextReference = builderExecutionPayloadReference(payloadJson);
|
|
121
224
|
await tx.insert(schema.contentDatabaseSourceExecutions).values({
|
|
122
225
|
id: executionId,
|
|
123
226
|
ownerEmail: database.ownerEmail,
|
|
@@ -128,11 +231,12 @@ export default defineAction({
|
|
|
128
231
|
state: plan.state,
|
|
129
232
|
idempotencyKey: plan.idempotencyKey,
|
|
130
233
|
summary: plan.summary,
|
|
131
|
-
payloadJson
|
|
234
|
+
payloadJson,
|
|
132
235
|
lastError: plan.lastError,
|
|
133
236
|
createdAt: now,
|
|
134
237
|
updatedAt: now,
|
|
135
238
|
});
|
|
239
|
+
replacementPrepared = true;
|
|
136
240
|
}
|
|
137
241
|
|
|
138
242
|
if (!preserve) {
|
|
@@ -142,13 +246,51 @@ export default defineAction({
|
|
|
142
246
|
.where(eq(schema.contentDatabaseSources.id, source.id));
|
|
143
247
|
}
|
|
144
248
|
});
|
|
249
|
+
replacementCommitted = replacementPrepared;
|
|
145
250
|
} catch (error) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
251
|
+
let winner: { id: string; payloadJson: string } | null | undefined;
|
|
252
|
+
try {
|
|
253
|
+
[winner] = await db
|
|
254
|
+
.select({
|
|
255
|
+
id: schema.contentDatabaseSourceExecutions.id,
|
|
256
|
+
payloadJson: schema.contentDatabaseSourceExecutions.payloadJson,
|
|
257
|
+
})
|
|
258
|
+
.from(schema.contentDatabaseSourceExecutions)
|
|
259
|
+
.where(eq(schema.contentDatabaseSourceExecutions.id, executionId))
|
|
260
|
+
.limit(1);
|
|
261
|
+
} catch {
|
|
262
|
+
// Inconclusive readback retains both refs.
|
|
263
|
+
}
|
|
264
|
+
if (winner?.payloadJson === attemptedPayloadJson) {
|
|
265
|
+
replacementCommitted = true;
|
|
266
|
+
} else if (winner) {
|
|
267
|
+
if (nextReference) {
|
|
268
|
+
await cleanupBuilderPrivatePayload(
|
|
269
|
+
nextReference,
|
|
270
|
+
"uncommitted prepared execution",
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
// Only a row another prepare changed is a won race to reuse; an
|
|
274
|
+
// unchanged row means this prepare's own failure must surface.
|
|
275
|
+
if (
|
|
276
|
+
observedPayloadJson === undefined ||
|
|
277
|
+
winner.payloadJson === observedPayloadJson
|
|
278
|
+
) {
|
|
279
|
+
throw error;
|
|
280
|
+
}
|
|
281
|
+
} else {
|
|
282
|
+
throw error;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (
|
|
286
|
+
replacementCommitted &&
|
|
287
|
+
previousReference &&
|
|
288
|
+
previousReference !== nextReference
|
|
289
|
+
) {
|
|
290
|
+
await cleanupBuilderPrivatePayload(
|
|
291
|
+
previousReference,
|
|
292
|
+
"superseded prepared execution",
|
|
293
|
+
);
|
|
152
294
|
}
|
|
153
295
|
timing.record("gate_preparation_and_dry_run_validation", gateStartedAt);
|
|
154
296
|
|