@agent-native/core 0.164.11 → 0.164.15
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/calendar/.agents/skills/event-management/SKILL.md +84 -0
- package/corpus/templates/calendar/AGENTS.md +5 -0
- package/corpus/templates/calendar/actions/delete-event.ts +1 -1
- package/corpus/templates/calendar/actions/delete-events.ts +508 -0
- package/corpus/templates/calendar/actions/event-action-helpers.ts +1 -1
- package/corpus/templates/calendar/actions/list-events.ts +53 -0
- package/corpus/templates/calendar/changelog/2026-08-18-the-agent-can-now-remove-many-meetings-at-once-such-as-every.md +6 -0
- package/corpus/templates/calendar/server/lib/event-weekday.ts +112 -0
- package/corpus/templates/content/actions/_database-source-utils.ts +25 -2
- package/corpus/templates/content/actions/_database-utils.ts +2 -0
- package/corpus/templates/content/actions/_local-folder-source.ts +186 -2
- package/corpus/templates/content/actions/connect-local-folder-source.ts +23 -8
- package/corpus/templates/content/actions/disconnect-local-folder-source.ts +3 -3
- package/corpus/templates/content/actions/resolve-local-folder-conflict.ts +2 -2
- package/corpus/templates/content/actions/sync-local-folder-source.ts +130 -12
- package/corpus/templates/content/app/components/LocalFolderLiveSync.tsx +77 -0
- package/corpus/templates/content/app/components/editor/DocumentEditor.tsx +354 -8
- package/corpus/templates/content/app/components/editor/DocumentToolbar.tsx +23 -1
- package/corpus/templates/content/app/components/editor/VisualEditor.tsx +78 -1
- package/corpus/templates/content/app/components/editor/database/sidebar.tsx +36 -0
- package/corpus/templates/content/app/components/editor/local-source-write-state.ts +52 -0
- package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +244 -6
- package/corpus/templates/content/app/components/sidebar/local-source-hierarchy.ts +189 -0
- package/corpus/templates/content/app/hooks/use-create-page.ts +26 -4
- package/corpus/templates/content/app/hooks/use-documents.ts +83 -0
- package/corpus/templates/content/app/i18n-data.ts +79 -0
- package/corpus/templates/content/app/lib/desktop-content-files.ts +57 -1
- package/corpus/templates/content/app/lib/local-content-source-files.ts +210 -34
- package/corpus/templates/content/app/lib/local-folder-live-sync.ts +191 -0
- package/corpus/templates/content/app/root.tsx +2 -1
- package/corpus/templates/content/app/routes/_app.local-files.tsx +103 -38
- package/corpus/templates/content/docs/product/capabilities/content.source.file-folder.md +2 -2
- package/corpus/templates/content/docs/product/features/content.feature.bring-your-local-work.md +3 -3
- package/corpus/templates/content/docs/product/roadmap.md +2 -2
- package/corpus/templates/content/docs/solutions/2026-08-18-content-navigation-coherence-shape.md +482 -0
- package/corpus/templates/content/shared/api.ts +25 -0
- package/corpus/templates/factory/AGENTS.md +2 -1
- package/corpus/templates/factory/actions/get-factory-graph-version.ts +69 -0
- package/corpus/templates/factory/actions/list-factory-graph-versions.ts +82 -0
- package/corpus/templates/factory/actions/restore-factory-graph-version.ts +163 -0
- package/corpus/templates/factory/actions/save-factory-graph.ts +93 -60
- package/corpus/templates/factory/app/components/factory/FactoryHistoryView.tsx +709 -0
- package/corpus/templates/factory/app/components/factory/FactoryInspector.tsx +62 -2
- package/corpus/templates/factory/app/components/ui/alert-dialog.tsx +1 -0
- package/corpus/templates/factory/app/i18n/en-US.ts +43 -0
- package/corpus/templates/factory/app/routes/factory.tsx +115 -15
- package/corpus/templates/factory/server/plugins/agent-chat.ts +3 -1
- package/dist/app-config/auth.d.ts +4 -0
- package/dist/app-config/auth.js +7 -0
- package/dist/app-config/schema.d.ts +3 -0
- package/dist/app-config/schema.js +2 -0
- package/dist/cli/code-agent-executor.js +6 -1
- package/dist/cli/code-agent-mcp-config.d.ts +2 -2
- package/dist/cli/code-agent-mcp-config.js +34 -9
- package/dist/client/org/OrgSwitcher.js +8 -4
- package/dist/collab/awareness.d.ts +2 -2
- package/dist/collab/routes.d.ts +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/mcp-client/config.d.ts +11 -0
- package/dist/mcp-client/config.js +33 -26
- package/dist/notifications/routes.d.ts +3 -3
- package/dist/observability/routes.d.ts +3 -3
- package/dist/progress/routes.d.ts +1 -1
- package/dist/resources/handlers.d.ts +2 -2
- package/dist/secrets/routes.d.ts +9 -9
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/dist/server/auth.js +15 -1
- package/dist/server/realtime-token.d.ts +1 -1
- package/docs/content/actions-access-control.mdx +136 -2
- package/docs/content/actions-agent-tools.mdx +101 -0
- package/docs/content/actions-defining.mdx +2 -2
- package/docs/content/audit-log.mdx +1 -1
- package/docs/content/authentication.mdx +1 -1
- package/docs/content/cloudflare.mdx +43 -0
- package/docs/content/creating-templates.mdx +1 -1
- package/docs/content/deploy-an-app.mdx +109 -0
- package/docs/content/deployment-environment-variables.mdx +101 -0
- package/docs/content/deployment.mdx +125 -792
- package/docs/content/docs-components.mdx +2 -2
- package/docs/content/environment-variables.mdx +41 -41
- package/docs/content/file-uploads.mdx +74 -40
- package/docs/content/harness-agents.mdx +2 -2
- package/docs/content/internationalization.mdx +61 -65
- package/docs/content/key-concepts.mdx +3 -3
- package/docs/content/multi-app-workspace.mdx +2 -2
- package/docs/content/netlify.mdx +47 -0
- package/docs/content/node-docker.mdx +138 -0
- package/docs/content/organizations-teams-permissions.mdx +5 -5
- package/docs/content/other-platforms.mdx +27 -0
- package/docs/content/ssr-caching.mdx +45 -0
- package/docs/content/template-assets-developers.mdx +2 -2
- package/docs/content/template-chat-developers.mdx +2 -2
- package/docs/content/template-content-developers.mdx +2 -2
- package/docs/content/{local-file-mode.mdx → template-content-local-files.mdx} +2 -1
- package/docs/content/template-content-sync.mdx +2 -2
- package/docs/content/toolkit-agent-ux.mdx +1 -1
- package/docs/content/toolkit-resources.mdx +2 -2
- package/docs/content/updating-ui-in-production.mdx +35 -0
- package/docs/content/vercel.mdx +38 -0
- package/docs/content/what-is-agent-native.mdx +1 -1
- package/docs/content/workspace-deployment.mdx +350 -0
- package/package.json +1 -1
- package/docs/content/agents.mdx +0 -9
- package/docs/content/database.mdx +0 -317
- package/docs/content/human-approval.mdx +0 -156
|
@@ -19,7 +19,13 @@ import { ensureDocumentsFilesMembership } from "./_content-files.js";
|
|
|
19
19
|
import { resolveContentSpaceAccess } from "./_content-space-access.js";
|
|
20
20
|
import { provisionContentSpaces } from "./_content-spaces.js";
|
|
21
21
|
import { lockDatabaseMemberships } from "./_database-membership-lock.js";
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
LOCAL_FOLDER_SOURCE_TYPE,
|
|
24
|
+
localFolderObservedRevision,
|
|
25
|
+
localFolderSourceFileIdentity,
|
|
26
|
+
localFolderSourceIdentityFromMetadata,
|
|
27
|
+
normalizeLocalFolderSourceIdentity,
|
|
28
|
+
} from "./_local-folder-source.js";
|
|
23
29
|
|
|
24
30
|
const MAX_SOURCE_FILES = 500;
|
|
25
31
|
const MAX_SOURCE_FILE_BYTES = 2 * 1024 * 1024;
|
|
@@ -75,13 +81,28 @@ function sourceValues(args: {
|
|
|
75
81
|
title: string;
|
|
76
82
|
hash: string;
|
|
77
83
|
metadataHash: string;
|
|
84
|
+
workingCopyId: string;
|
|
85
|
+
bridgeFileIdentity?: string;
|
|
78
86
|
}) {
|
|
87
|
+
const observedRevision = localFolderObservedRevision({
|
|
88
|
+
contentHash: args.hash,
|
|
89
|
+
metadataHash: args.metadataHash,
|
|
90
|
+
});
|
|
79
91
|
return JSON.stringify({
|
|
80
92
|
relativePath: args.path,
|
|
81
93
|
extension: args.path.toLowerCase().endsWith(".mdx") ? ".mdx" : ".md",
|
|
82
94
|
title: args.title,
|
|
83
95
|
contentHash: args.hash,
|
|
84
96
|
metadataHash: args.metadataHash,
|
|
97
|
+
observedRevision,
|
|
98
|
+
sourceFileIdentity: localFolderSourceFileIdentity({
|
|
99
|
+
workingCopyId: args.workingCopyId,
|
|
100
|
+
relativePath: args.path,
|
|
101
|
+
observedRevision,
|
|
102
|
+
}),
|
|
103
|
+
...(args.bridgeFileIdentity
|
|
104
|
+
? { bridgeFileIdentity: args.bridgeFileIdentity }
|
|
105
|
+
: {}),
|
|
85
106
|
});
|
|
86
107
|
}
|
|
87
108
|
|
|
@@ -142,9 +163,19 @@ export default defineAction({
|
|
|
142
163
|
.refine((value) => Object.keys(value).length <= MAX_SOURCE_FILES, {
|
|
143
164
|
message: `Sync is limited to ${MAX_SOURCE_FILES} files.`,
|
|
144
165
|
}),
|
|
166
|
+
fileIdentities: z.record(z.string(), z.string().min(1).max(256)).optional(),
|
|
167
|
+
observedRevisions: z
|
|
168
|
+
.record(z.string(), z.string().regex(/^[a-f0-9]{64}$/i))
|
|
169
|
+
.optional(),
|
|
145
170
|
dryRun: z.boolean().optional().default(false),
|
|
146
171
|
}),
|
|
147
|
-
run: async ({
|
|
172
|
+
run: async ({
|
|
173
|
+
sourceId,
|
|
174
|
+
files,
|
|
175
|
+
fileIdentities = {},
|
|
176
|
+
observedRevisions,
|
|
177
|
+
dryRun,
|
|
178
|
+
}) => {
|
|
148
179
|
const userEmail = getRequestUserEmail();
|
|
149
180
|
if (!userEmail) throw new Error("no authenticated user");
|
|
150
181
|
const builderPaths = Object.keys(files).filter(isBuilderMdxSourcePath);
|
|
@@ -154,6 +185,15 @@ export default defineAction({
|
|
|
154
185
|
);
|
|
155
186
|
}
|
|
156
187
|
const entries = normalizedEntries(files);
|
|
188
|
+
if (observedRevisions) {
|
|
189
|
+
for (const [filePath, content] of entries) {
|
|
190
|
+
if (observedRevisions[filePath] !== contentHash(content)) {
|
|
191
|
+
throw new Error(
|
|
192
|
+
`Local file revision changed while reading "${filePath}"`,
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
157
197
|
const db = getDb();
|
|
158
198
|
const [target] = await db
|
|
159
199
|
.select({
|
|
@@ -263,6 +303,12 @@ export default defineAction({
|
|
|
263
303
|
|
|
264
304
|
const metadata = parseJson(target.source.metadataJson);
|
|
265
305
|
const policy = truthPolicy(metadata.truthPolicy);
|
|
306
|
+
const localIdentity =
|
|
307
|
+
localFolderSourceIdentityFromMetadata(metadata.localIdentity) ??
|
|
308
|
+
normalizeLocalFolderSourceIdentity({
|
|
309
|
+
connectionId: target.source.sourceTable,
|
|
310
|
+
label: target.source.sourceName,
|
|
311
|
+
});
|
|
266
312
|
const now = new Date().toISOString();
|
|
267
313
|
const created: Array<{ id: string; path: string; title: string }> = [];
|
|
268
314
|
const updated: Array<{ id: string; path: string; title: string }> = [];
|
|
@@ -271,16 +317,42 @@ export default defineAction({
|
|
|
271
317
|
const conflicts: Array<{ id: string; path: string; title: string }> = [];
|
|
272
318
|
const outbound: Array<{ id: string; path: string; title: string }> = [];
|
|
273
319
|
|
|
274
|
-
const buildPlans = (snapshot: Awaited<ReturnType<typeof loadSnapshot>>) =>
|
|
275
|
-
|
|
276
|
-
|
|
320
|
+
const buildPlans = (snapshot: Awaited<ReturnType<typeof loadSnapshot>>) => {
|
|
321
|
+
const rowByBridgeIdentity = new Map<
|
|
322
|
+
string,
|
|
323
|
+
(typeof snapshot.storedRows)[number]
|
|
324
|
+
>();
|
|
325
|
+
for (const row of snapshot.storedRows) {
|
|
326
|
+
const values = parseJson(row.sourceValuesJson);
|
|
327
|
+
if (typeof values.bridgeFileIdentity === "string") {
|
|
328
|
+
rowByBridgeIdentity.set(values.bridgeFileIdentity, row);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return valid.map((file, index) => {
|
|
333
|
+
const directPathRow = snapshot.rowByPath.get(file.path);
|
|
334
|
+
const incomingBridgeFileIdentity = fileIdentities[file.path];
|
|
335
|
+
const identityRow = incomingBridgeFileIdentity
|
|
336
|
+
? rowByBridgeIdentity.get(incomingBridgeFileIdentity)
|
|
337
|
+
: undefined;
|
|
338
|
+
const incomingHash = contentHash(file.content);
|
|
339
|
+
const pathRow = directPathRow ?? identityRow;
|
|
340
|
+
const explicitId =
|
|
341
|
+
file.id && localIdentity.workingCopy.kind === "temporary"
|
|
342
|
+
? opaqueId("content_local_file", `${sourceId}:${file.id}`)
|
|
343
|
+
: file.id;
|
|
277
344
|
const id =
|
|
278
|
-
|
|
345
|
+
explicitId ??
|
|
279
346
|
pathRow?.documentId ??
|
|
280
347
|
opaqueId("content_local_file", `${sourceId}:${file.path}`);
|
|
281
348
|
const existing = snapshot.documentById.get(id);
|
|
282
349
|
const previousRow = snapshot.rowByDocumentId.get(id) ?? pathRow;
|
|
283
350
|
const previousValues = parseJson(previousRow?.sourceValuesJson);
|
|
351
|
+
const bridgeFileIdentity =
|
|
352
|
+
incomingBridgeFileIdentity ??
|
|
353
|
+
(typeof previousValues.bridgeFileIdentity === "string"
|
|
354
|
+
? previousValues.bridgeFileIdentity
|
|
355
|
+
: undefined);
|
|
284
356
|
const previousHash =
|
|
285
357
|
typeof previousValues.contentHash === "string"
|
|
286
358
|
? previousValues.contentHash
|
|
@@ -289,7 +361,6 @@ export default defineAction({
|
|
|
289
361
|
typeof previousValues.metadataHash === "string"
|
|
290
362
|
? previousValues.metadataHash
|
|
291
363
|
: null;
|
|
292
|
-
const incomingHash = contentHash(file.content);
|
|
293
364
|
const incomingMetadataHash = metadataHash(file);
|
|
294
365
|
const localHash = existing ? contentHash(existing.content) : null;
|
|
295
366
|
const localMetadataHash = existing ? metadataHash(existing) : null;
|
|
@@ -332,8 +403,10 @@ export default defineAction({
|
|
|
332
403
|
conflict,
|
|
333
404
|
keepContent,
|
|
334
405
|
applyIncoming,
|
|
406
|
+
bridgeFileIdentity,
|
|
335
407
|
};
|
|
336
408
|
});
|
|
409
|
+
};
|
|
337
410
|
|
|
338
411
|
let plans = buildPlans(initialSnapshot);
|
|
339
412
|
const initialDocumentIds = new Set(plans.map((plan) => plan.id));
|
|
@@ -348,7 +421,7 @@ export default defineAction({
|
|
|
348
421
|
unchanged.length = 0;
|
|
349
422
|
conflicts.length = 0;
|
|
350
423
|
outbound.length = 0;
|
|
351
|
-
for (const row of missingRows) {
|
|
424
|
+
for (const row of policy === "source_primary" ? [] : missingRows) {
|
|
352
425
|
const values = parseJson(row.sourceValuesJson);
|
|
353
426
|
const path = String(values.relativePath ?? row.sourceDisplayKey ?? "");
|
|
354
427
|
const document = snapshot.documentById.get(row.documentId);
|
|
@@ -375,7 +448,8 @@ export default defineAction({
|
|
|
375
448
|
} else if (
|
|
376
449
|
plan.applyIncoming ||
|
|
377
450
|
plan.existing.title !== plan.file.title ||
|
|
378
|
-
plan.existing.sourcePath !== plan.file.path
|
|
451
|
+
plan.existing.sourcePath !== plan.file.path ||
|
|
452
|
+
plan.existing.sourceRootPath !== target.source.sourceTable
|
|
379
453
|
) {
|
|
380
454
|
updated.push({
|
|
381
455
|
id: plan.id,
|
|
@@ -518,7 +592,7 @@ export default defineAction({
|
|
|
518
592
|
sourceMode: "local-files",
|
|
519
593
|
sourceKind: "file",
|
|
520
594
|
sourcePath: plan.file.path,
|
|
521
|
-
sourceRootPath: target.source.
|
|
595
|
+
sourceRootPath: target.source.sourceTable,
|
|
522
596
|
sourceUpdatedAt: now,
|
|
523
597
|
visibility: target.database.orgId ? "org" : "private",
|
|
524
598
|
createdAt: now,
|
|
@@ -526,7 +600,8 @@ export default defineAction({
|
|
|
526
600
|
});
|
|
527
601
|
} else if (
|
|
528
602
|
plan.applyIncoming ||
|
|
529
|
-
plan.existing.sourcePath !== plan.file.path
|
|
603
|
+
plan.existing.sourcePath !== plan.file.path ||
|
|
604
|
+
plan.existing.sourceRootPath !== target.source.sourceTable
|
|
530
605
|
) {
|
|
531
606
|
await tx
|
|
532
607
|
.insert(schema.documentVersions)
|
|
@@ -557,7 +632,7 @@ export default defineAction({
|
|
|
557
632
|
sourceMode: "local-files",
|
|
558
633
|
sourceKind: "file",
|
|
559
634
|
sourcePath: plan.file.path,
|
|
560
|
-
sourceRootPath: target.source.
|
|
635
|
+
sourceRootPath: target.source.sourceTable,
|
|
561
636
|
sourceUpdatedAt: now,
|
|
562
637
|
updatedAt: now,
|
|
563
638
|
})
|
|
@@ -647,6 +722,8 @@ export default defineAction({
|
|
|
647
722
|
title: plan.file.title,
|
|
648
723
|
hash: plan.incomingHash,
|
|
649
724
|
metadataHash: plan.incomingMetadataHash,
|
|
725
|
+
workingCopyId: localIdentity.workingCopy.id,
|
|
726
|
+
bridgeFileIdentity: plan.bridgeFileIdentity,
|
|
650
727
|
}),
|
|
651
728
|
provenance: "trusted local-folder bridge",
|
|
652
729
|
syncState: "linked",
|
|
@@ -670,6 +747,47 @@ export default defineAction({
|
|
|
670
747
|
.where(eq(schema.contentDatabaseSourceRows.id, rowId));
|
|
671
748
|
}
|
|
672
749
|
for (const row of missingRows) {
|
|
750
|
+
if (policy === "source_primary") {
|
|
751
|
+
await tx
|
|
752
|
+
.delete(schema.contentDatabaseSourceRows)
|
|
753
|
+
.where(eq(schema.contentDatabaseSourceRows.id, row.id));
|
|
754
|
+
const [remainingSourceRow] = await tx
|
|
755
|
+
.select({ id: schema.contentDatabaseSourceRows.id })
|
|
756
|
+
.from(schema.contentDatabaseSourceRows)
|
|
757
|
+
.where(
|
|
758
|
+
eq(
|
|
759
|
+
schema.contentDatabaseSourceRows.databaseItemId,
|
|
760
|
+
row.databaseItemId,
|
|
761
|
+
),
|
|
762
|
+
)
|
|
763
|
+
.limit(1);
|
|
764
|
+
if (!remainingSourceRow) {
|
|
765
|
+
await tx
|
|
766
|
+
.delete(schema.contentDatabaseItems)
|
|
767
|
+
.where(eq(schema.contentDatabaseItems.id, row.databaseItemId));
|
|
768
|
+
await tx
|
|
769
|
+
.update(schema.documents)
|
|
770
|
+
.set({
|
|
771
|
+
sourceMode: null,
|
|
772
|
+
sourceKind: null,
|
|
773
|
+
sourcePath: null,
|
|
774
|
+
sourceRootPath: null,
|
|
775
|
+
sourceUpdatedAt: now,
|
|
776
|
+
updatedAt: now,
|
|
777
|
+
})
|
|
778
|
+
.where(
|
|
779
|
+
and(
|
|
780
|
+
eq(schema.documents.id, row.documentId),
|
|
781
|
+
eq(schema.documents.spaceId, targetSpaceId),
|
|
782
|
+
eq(
|
|
783
|
+
schema.documents.sourceRootPath,
|
|
784
|
+
target.source.sourceTable,
|
|
785
|
+
),
|
|
786
|
+
),
|
|
787
|
+
);
|
|
788
|
+
}
|
|
789
|
+
continue;
|
|
790
|
+
}
|
|
673
791
|
const values = parseJson(row.sourceValuesJson);
|
|
674
792
|
const path = String(
|
|
675
793
|
values.relativePath ?? row.sourceDisplayKey ?? row.sourceRowId,
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
|
|
4
|
+
import { getDesktopContentFiles } from "../lib/desktop-content-files";
|
|
5
|
+
import { syncLiveLocalFolder } from "../lib/local-folder-live-sync";
|
|
6
|
+
import { connectTemporaryLocalFolder } from "../lib/local-folder-live-sync";
|
|
7
|
+
|
|
8
|
+
const RECONCILE_DELAY_MS = 120;
|
|
9
|
+
|
|
10
|
+
export function LocalFolderLiveSync() {
|
|
11
|
+
const queryClient = useQueryClient();
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const desktop = getDesktopContentFiles();
|
|
15
|
+
if (!desktop?.onChange || !desktop.subscribeChanges) return;
|
|
16
|
+
const timers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
17
|
+
let active = true;
|
|
18
|
+
|
|
19
|
+
const reconcile = (folderId: string) => {
|
|
20
|
+
const current = timers.get(folderId);
|
|
21
|
+
if (current) clearTimeout(current);
|
|
22
|
+
timers.set(
|
|
23
|
+
folderId,
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
timers.delete(folderId);
|
|
26
|
+
void desktop
|
|
27
|
+
.getFolder({ folderId })
|
|
28
|
+
.then(async (folderResult) => {
|
|
29
|
+
if (!folderResult.ok) return { synced: false as const };
|
|
30
|
+
await connectTemporaryLocalFolder(folderResult.folder);
|
|
31
|
+
return syncLiveLocalFolder(folderId);
|
|
32
|
+
})
|
|
33
|
+
.then((outcome) => {
|
|
34
|
+
if (!active || !outcome.synced) return;
|
|
35
|
+
queryClient.invalidateQueries({
|
|
36
|
+
queryKey: ["action", "list-documents"],
|
|
37
|
+
});
|
|
38
|
+
queryClient.invalidateQueries({
|
|
39
|
+
queryKey: ["action", "get-document"],
|
|
40
|
+
});
|
|
41
|
+
queryClient.invalidateQueries({
|
|
42
|
+
queryKey: ["action", "get-content-database"],
|
|
43
|
+
});
|
|
44
|
+
})
|
|
45
|
+
.catch(() => {
|
|
46
|
+
// A later watcher event or ordinary launch reconciliation retries.
|
|
47
|
+
});
|
|
48
|
+
}, RECONCILE_DELAY_MS),
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const removeListener = desktop.onChange((event) =>
|
|
53
|
+
reconcile(event.folderId),
|
|
54
|
+
);
|
|
55
|
+
const reconcileAll = () =>
|
|
56
|
+
void desktop.getFolder().then((result) => {
|
|
57
|
+
if (!active || !result.ok) return;
|
|
58
|
+
for (const folder of result.folders ?? [result.folder]) {
|
|
59
|
+
if (!folder.id) continue;
|
|
60
|
+
void desktop.subscribeChanges?.({ folderId: folder.id });
|
|
61
|
+
reconcile(folder.id);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
reconcileAll();
|
|
65
|
+
const boundedReconciliation = window.setInterval(reconcileAll, 5_000);
|
|
66
|
+
|
|
67
|
+
return () => {
|
|
68
|
+
active = false;
|
|
69
|
+
window.clearInterval(boundedReconciliation);
|
|
70
|
+
removeListener();
|
|
71
|
+
for (const timer of timers.values()) clearTimeout(timer);
|
|
72
|
+
timers.clear();
|
|
73
|
+
};
|
|
74
|
+
}, [queryClient]);
|
|
75
|
+
|
|
76
|
+
return null;
|
|
77
|
+
}
|