@agent-native/core 0.84.0 → 0.84.2

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.
Files changed (152) hide show
  1. package/corpus/README.md +1 -1
  2. package/corpus/core/CHANGELOG.md +13 -0
  3. package/corpus/core/docs/content/evals.mdx +34 -12
  4. package/corpus/core/docs/content/locales/ar-SA/evals.mdx +7 -0
  5. package/corpus/core/docs/content/locales/de-DE/evals.mdx +8 -0
  6. package/corpus/core/docs/content/locales/es-ES/evals.mdx +8 -0
  7. package/corpus/core/docs/content/locales/fr-FR/evals.mdx +8 -0
  8. package/corpus/core/docs/content/locales/hi-IN/evals.mdx +8 -0
  9. package/corpus/core/docs/content/locales/ja-JP/evals.mdx +7 -0
  10. package/corpus/core/docs/content/locales/ko-KR/evals.mdx +7 -0
  11. package/corpus/core/docs/content/locales/pt-BR/evals.mdx +8 -0
  12. package/corpus/core/docs/content/locales/zh-CN/evals.mdx +7 -0
  13. package/corpus/core/docs/content/locales/zh-TW/evals.mdx +7 -0
  14. package/corpus/core/docs/design/durable-agent-runs.md +34 -35
  15. package/corpus/core/package.json +1 -1
  16. package/corpus/core/src/agent/engine/builder-engine.ts +81 -9
  17. package/corpus/core/src/agent/run-manager.ts +8 -7
  18. package/corpus/core/src/cli/design-connect.ts +175 -0
  19. package/corpus/core/src/cli/skills.ts +5 -7
  20. package/corpus/core/src/client/AgentPanel.tsx +8 -0
  21. package/corpus/core/src/client/MultiTabAssistantChat.tsx +4 -1
  22. package/corpus/core/src/client/agent-chat-adapter.ts +45 -15
  23. package/corpus/core/src/client/sse-event-processor.ts +31 -4
  24. package/corpus/core/src/eval/define-eval.ts +4 -1
  25. package/corpus/core/src/eval/report.ts +23 -8
  26. package/corpus/core/src/eval/runner.ts +41 -6
  27. package/corpus/core/src/eval/types.ts +11 -0
  28. package/corpus/core/src/templates/workspace-core/.agents/skills/reliable-mutations/SKILL.md +15 -17
  29. package/corpus/templates/content/AGENTS.md +9 -2
  30. package/corpus/templates/content/actions/_database-row-batch.ts +230 -0
  31. package/corpus/templates/content/actions/_database-utils.ts +17 -9
  32. package/corpus/templates/content/actions/_notion-action-utils.ts +26 -0
  33. package/corpus/templates/content/actions/connect-notion-status.ts +13 -4
  34. package/corpus/templates/content/actions/create-and-link-notion-page.ts +23 -0
  35. package/corpus/templates/content/actions/delete-database-items.ts +55 -0
  36. package/corpus/templates/content/actions/delete-document.ts +4 -4
  37. package/corpus/templates/content/actions/disconnect-notion.ts +16 -0
  38. package/corpus/templates/content/actions/duplicate-database-item.ts +1 -1
  39. package/corpus/templates/content/actions/duplicate-database-items.ts +191 -0
  40. package/corpus/templates/content/actions/link-notion-page.ts +10 -7
  41. package/corpus/templates/content/actions/list-notion-links.ts +3 -4
  42. package/corpus/templates/content/actions/pull-notion-page.ts +7 -9
  43. package/corpus/templates/content/actions/push-notion-page.ts +7 -9
  44. package/corpus/templates/content/actions/refresh-notion-sync-status.ts +24 -0
  45. package/corpus/templates/content/actions/resolve-notion-sync-conflict.ts +23 -0
  46. package/corpus/templates/content/actions/search-notion-pages.ts +67 -0
  47. package/corpus/templates/content/actions/unlink-notion-page.ts +23 -0
  48. package/corpus/templates/content/app/components/editor/DocumentDatabase.tsx +27 -34
  49. package/corpus/templates/content/app/components/editor/DocumentEditor.tsx +16 -13
  50. package/corpus/templates/content/app/components/editor/DocumentToolbar.tsx +10 -10
  51. package/corpus/templates/content/app/components/editor/NotionConflictBanner.tsx +1 -1
  52. package/corpus/templates/content/app/components/editor/NotionSyncBar.tsx +18 -9
  53. package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +27 -34
  54. package/corpus/templates/content/app/components/editor/database/navigation-state.ts +10 -4
  55. package/corpus/templates/content/app/components/sidebar/NotionButton.tsx +32 -17
  56. package/corpus/templates/content/app/hooks/use-content-database.ts +35 -0
  57. package/corpus/templates/content/app/hooks/use-notion.ts +108 -99
  58. package/corpus/templates/content/package.json +3 -0
  59. package/corpus/templates/content/parity/README.md +69 -0
  60. package/corpus/templates/content/parity/eval-scenarios.ts +118 -0
  61. package/corpus/templates/content/parity/exceptions.allowlist.ts +17 -0
  62. package/corpus/templates/content/parity/matrix.md +28 -0
  63. package/corpus/templates/content/parity/matrix.ts +606 -0
  64. package/corpus/templates/content/parity/matrix.types.ts +42 -0
  65. package/corpus/templates/content/parity/parity-evals.eval.ts +4 -0
  66. package/corpus/templates/content/parity/render-matrix.ts +90 -0
  67. package/corpus/templates/content/parity/scenario-to-eval.ts +57 -0
  68. package/corpus/templates/content/shared/api.ts +11 -0
  69. package/corpus/templates/design/actions/apply-motion-edit.ts +50 -18
  70. package/corpus/templates/design/actions/get-motion-timeline.ts +4 -14
  71. package/corpus/templates/design/app/components/design/DesignCanvas.tsx +156 -12
  72. package/corpus/templates/design/app/components/design/MotionDock.tsx +2 -3
  73. package/corpus/templates/design/app/components/design/MultiScreenCanvas.tsx +217 -75
  74. package/corpus/templates/design/app/components/design/QuestionFlow.tsx +39 -39
  75. package/corpus/templates/design/app/components/design/bridge/editor-chrome.bridge.ts +558 -37
  76. package/corpus/templates/design/app/components/design/bridge/hit-test.bridge.ts +75 -3
  77. package/corpus/templates/design/app/components/design/types.ts +13 -0
  78. package/corpus/templates/design/app/components/layout/Layout.tsx +1 -0
  79. package/corpus/templates/design/app/i18n/zh-TW.ts +17 -0
  80. package/corpus/templates/design/app/i18n-data.ts +245 -0
  81. package/corpus/templates/design/app/pages/DesignEditor.tsx +762 -153
  82. package/corpus/templates/design/changelog/2026-06-30-copying-or-dragging-screen-elements-onto-the-infinite-canvas.md +6 -0
  83. package/corpus/templates/design/changelog/2026-06-30-design-questions-now-use-tighter-editor-typography-and-contr.md +6 -0
  84. package/corpus/templates/design/changelog/2026-06-30-element-drags-can-be-cancelled-with-escape-before-they-commi.md +6 -0
  85. package/corpus/templates/design/changelog/2026-06-30-pending-visual-style-edits-now-warn-before-you-leave-the-edi.md +6 -0
  86. package/corpus/templates/design/changelog/2026-06-30-visual-style-drags-stay-live-while-pending-edits-can-be-appl.md +6 -0
  87. package/corpus/templates/design/changelog/2026-07-01-design-chat-no-longer-shows-a-redundant-context-tab-above-the-composer.md +6 -0
  88. package/corpus/templates/design/changelog/2026-07-01-motion-track-creation-no-longer-fails-in-local-editors.md +6 -0
  89. package/corpus/templates/design/server/plugins/db.ts +10 -0
  90. package/dist/agent/engine/builder-engine.d.ts.map +1 -1
  91. package/dist/agent/engine/builder-engine.js +61 -10
  92. package/dist/agent/engine/builder-engine.js.map +1 -1
  93. package/dist/agent/run-manager.d.ts +8 -7
  94. package/dist/agent/run-manager.d.ts.map +1 -1
  95. package/dist/agent/run-manager.js +8 -7
  96. package/dist/agent/run-manager.js.map +1 -1
  97. package/dist/cli/design-connect.d.ts +2 -0
  98. package/dist/cli/design-connect.d.ts.map +1 -1
  99. package/dist/cli/design-connect.js +140 -0
  100. package/dist/cli/design-connect.js.map +1 -1
  101. package/dist/cli/skills.d.ts.map +1 -1
  102. package/dist/cli/skills.js +5 -7
  103. package/dist/cli/skills.js.map +1 -1
  104. package/dist/client/AgentPanel.d.ts +5 -1
  105. package/dist/client/AgentPanel.d.ts.map +1 -1
  106. package/dist/client/AgentPanel.js +4 -4
  107. package/dist/client/AgentPanel.js.map +1 -1
  108. package/dist/client/MultiTabAssistantChat.d.ts +3 -1
  109. package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
  110. package/dist/client/MultiTabAssistantChat.js +2 -2
  111. package/dist/client/MultiTabAssistantChat.js.map +1 -1
  112. package/dist/client/agent-chat-adapter.d.ts.map +1 -1
  113. package/dist/client/agent-chat-adapter.js +37 -14
  114. package/dist/client/agent-chat-adapter.js.map +1 -1
  115. package/dist/client/sse-event-processor.d.ts +14 -1
  116. package/dist/client/sse-event-processor.d.ts.map +1 -1
  117. package/dist/client/sse-event-processor.js +21 -5
  118. package/dist/client/sse-event-processor.js.map +1 -1
  119. package/dist/collab/routes.d.ts +1 -1
  120. package/dist/eval/define-eval.d.ts.map +1 -1
  121. package/dist/eval/define-eval.js +2 -1
  122. package/dist/eval/define-eval.js.map +1 -1
  123. package/dist/eval/report.d.ts.map +1 -1
  124. package/dist/eval/report.js +19 -4
  125. package/dist/eval/report.js.map +1 -1
  126. package/dist/eval/runner.d.ts.map +1 -1
  127. package/dist/eval/runner.js +38 -6
  128. package/dist/eval/runner.js.map +1 -1
  129. package/dist/eval/types.d.ts +11 -0
  130. package/dist/eval/types.d.ts.map +1 -1
  131. package/dist/eval/types.js.map +1 -1
  132. package/dist/file-upload/actions/upload-image.d.ts +2 -2
  133. package/dist/observability/routes.d.ts +2 -2
  134. package/dist/progress/routes.d.ts +1 -1
  135. package/dist/resources/handlers.d.ts +3 -3
  136. package/dist/server/transcribe-voice.d.ts +1 -1
  137. package/dist/templates/workspace-core/.agents/skills/reliable-mutations/SKILL.md +15 -17
  138. package/docs/content/evals.mdx +34 -12
  139. package/docs/content/locales/ar-SA/evals.mdx +7 -0
  140. package/docs/content/locales/de-DE/evals.mdx +8 -0
  141. package/docs/content/locales/es-ES/evals.mdx +8 -0
  142. package/docs/content/locales/fr-FR/evals.mdx +8 -0
  143. package/docs/content/locales/hi-IN/evals.mdx +8 -0
  144. package/docs/content/locales/ja-JP/evals.mdx +7 -0
  145. package/docs/content/locales/ko-KR/evals.mdx +7 -0
  146. package/docs/content/locales/pt-BR/evals.mdx +8 -0
  147. package/docs/content/locales/zh-CN/evals.mdx +7 -0
  148. package/docs/content/locales/zh-TW/evals.mdx +7 -0
  149. package/docs/design/durable-agent-runs.md +34 -35
  150. package/package.json +1 -1
  151. package/src/templates/workspace-core/.agents/skills/reliable-mutations/SKILL.md +15 -17
  152. package/corpus/templates/content/server/routes/api/notion/disconnect.post.ts +0 -12
@@ -0,0 +1,16 @@
1
+ import { defineAction } from "@agent-native/core";
2
+ import { z } from "zod";
3
+
4
+ import { disconnectNotionForOwner } from "../server/lib/notion.js";
5
+ import { getCurrentNotionOwner } from "./_notion-action-utils.js";
6
+
7
+ export default defineAction({
8
+ description: "Disconnect the current user's Notion workspace.",
9
+ schema: z.object({}),
10
+ http: { method: "POST" },
11
+ run: async () => {
12
+ const owner = getCurrentNotionOwner();
13
+ const deleted = await disconnectNotionForOwner(owner);
14
+ return { success: true, deleted };
15
+ },
16
+ });
@@ -11,7 +11,7 @@ import { nanoid } from "./_property-utils.js";
11
11
 
12
12
  export default defineAction({
13
13
  description:
14
- "Duplicate a page row in a content database, including stored property values.",
14
+ "Duplicate exactly one page row in a content database, including stored property values. For two or more rows, use duplicate-database-items once instead of looping this action.",
15
15
  schema: z.object({
16
16
  itemId: z.string().optional().describe("Database item ID"),
17
17
  documentId: z.string().optional().describe("Database row document ID"),
@@ -0,0 +1,191 @@
1
+ import { defineAction } from "@agent-native/core";
2
+ import { writeAppState } from "@agent-native/core/application-state";
3
+ import { getRequestUserEmail } from "@agent-native/core/server/request-context";
4
+ import { assertAccess } from "@agent-native/core/sharing";
5
+ import { and, eq, gte, inArray, sql } from "drizzle-orm";
6
+
7
+ import { getDb, schema } from "../server/db/index.js";
8
+ import {
9
+ databaseRowBatchSchema,
10
+ resolveDatabaseRowsForBatch,
11
+ } from "./_database-row-batch.js";
12
+ import { getContentDatabaseResponse } from "./_database-utils.js";
13
+ import { nanoid } from "./_property-utils.js";
14
+
15
+ export default defineAction({
16
+ description:
17
+ "Duplicate multiple page rows in a content database in one atomic batch. Use this for two or more selected/named rows instead of looping duplicate-database-item.",
18
+ schema: databaseRowBatchSchema,
19
+ run: async (args) => {
20
+ const db = getDb();
21
+ const { database, rows } = await resolveDatabaseRowsForBatch(args);
22
+
23
+ await assertAccess("document", database.documentId, "editor");
24
+ for (const row of rows) {
25
+ await assertAccess("document", row.document.id, "viewer");
26
+ }
27
+
28
+ const sourceDocumentIds = rows.map((row) => row.document.id);
29
+ const sourceItemIds = rows.map((row) => row.item.id);
30
+ const now = new Date().toISOString();
31
+ const insertionPosition =
32
+ Math.max(...rows.map((row) => row.item.position)) + 1;
33
+ const currentUserEmail = getRequestUserEmail() ?? database.ownerEmail;
34
+
35
+ const values =
36
+ sourceDocumentIds.length > 0
37
+ ? await db
38
+ .select()
39
+ .from(schema.documentPropertyValues)
40
+ .where(
41
+ inArray(
42
+ schema.documentPropertyValues.documentId,
43
+ sourceDocumentIds,
44
+ ),
45
+ )
46
+ : [];
47
+ const valuesByDocumentId = new Map<
48
+ string,
49
+ Array<typeof schema.documentPropertyValues.$inferSelect>
50
+ >();
51
+ for (const value of values) {
52
+ const list = valuesByDocumentId.get(value.documentId) ?? [];
53
+ list.push(value);
54
+ valuesByDocumentId.set(value.documentId, list);
55
+ }
56
+
57
+ const inheritedShares = await db
58
+ .select({
59
+ principalType: schema.documentShares.principalType,
60
+ principalId: schema.documentShares.principalId,
61
+ role: schema.documentShares.role,
62
+ })
63
+ .from(schema.documentShares)
64
+ .where(eq(schema.documentShares.resourceId, database.documentId));
65
+
66
+ const duplicates = rows.map((row, index) => ({
67
+ sourceItemId: row.item.id,
68
+ sourceDocumentId: row.document.id,
69
+ duplicatedItemId: nanoid(),
70
+ duplicatedDocumentId: nanoid(),
71
+ position: insertionPosition + index,
72
+ row,
73
+ }));
74
+
75
+ await db.transaction(async (tx) => {
76
+ await tx
77
+ .update(schema.contentDatabaseItems)
78
+ .set({
79
+ position: sql`${schema.contentDatabaseItems.position} + ${duplicates.length}`,
80
+ updatedAt: now,
81
+ })
82
+ .where(
83
+ and(
84
+ eq(schema.contentDatabaseItems.databaseId, database.id),
85
+ gte(schema.contentDatabaseItems.position, insertionPosition),
86
+ ),
87
+ );
88
+
89
+ await tx
90
+ .update(schema.documents)
91
+ .set({
92
+ position: sql`${schema.documents.position} + ${duplicates.length}`,
93
+ updatedAt: now,
94
+ })
95
+ .where(
96
+ and(
97
+ eq(schema.documents.ownerEmail, database.ownerEmail),
98
+ eq(schema.documents.parentId, database.documentId),
99
+ gte(schema.documents.position, insertionPosition),
100
+ ),
101
+ );
102
+
103
+ await tx.insert(schema.documents).values(
104
+ duplicates.map((duplicate) => ({
105
+ id: duplicate.duplicatedDocumentId,
106
+ ownerEmail: duplicate.row.document.ownerEmail,
107
+ orgId: duplicate.row.document.orgId,
108
+ parentId: database.documentId,
109
+ title: `Copy of ${duplicate.row.document.title.trim() || "Untitled"}`,
110
+ content: duplicate.row.document.content,
111
+ icon: duplicate.row.document.icon,
112
+ position: duplicate.position,
113
+ isFavorite: 0,
114
+ hideFromSearch: duplicate.row.document.hideFromSearch,
115
+ visibility: duplicate.row.document.visibility,
116
+ createdAt: now,
117
+ updatedAt: now,
118
+ })),
119
+ );
120
+
121
+ await tx.insert(schema.contentDatabaseItems).values(
122
+ duplicates.map((duplicate) => ({
123
+ id: duplicate.duplicatedItemId,
124
+ ownerEmail: duplicate.row.item.ownerEmail,
125
+ orgId: duplicate.row.item.orgId,
126
+ databaseId: database.id,
127
+ documentId: duplicate.duplicatedDocumentId,
128
+ position: duplicate.position,
129
+ createdAt: now,
130
+ updatedAt: now,
131
+ })),
132
+ );
133
+
134
+ const duplicatedValues = duplicates.flatMap((duplicate) =>
135
+ (valuesByDocumentId.get(duplicate.sourceDocumentId) ?? []).map(
136
+ (value) => ({
137
+ id: nanoid(),
138
+ ownerEmail: duplicate.row.document.ownerEmail,
139
+ documentId: duplicate.duplicatedDocumentId,
140
+ propertyId: value.propertyId,
141
+ valueJson: value.valueJson,
142
+ createdAt: now,
143
+ updatedAt: now,
144
+ }),
145
+ ),
146
+ );
147
+ if (duplicatedValues.length > 0) {
148
+ await tx.insert(schema.documentPropertyValues).values(duplicatedValues);
149
+ }
150
+
151
+ if (inheritedShares.length > 0) {
152
+ await tx.insert(schema.documentShares).values(
153
+ duplicates.flatMap((duplicate) =>
154
+ inheritedShares.map((share) => ({
155
+ id: nanoid(),
156
+ resourceId: duplicate.duplicatedDocumentId,
157
+ principalType: share.principalType,
158
+ principalId: share.principalId,
159
+ role: share.role,
160
+ createdBy: currentUserEmail,
161
+ createdAt: now,
162
+ })),
163
+ ),
164
+ );
165
+ }
166
+ });
167
+
168
+ await writeAppState("refresh-signal", { ts: Date.now() });
169
+
170
+ return {
171
+ ...(await getContentDatabaseResponse(database.id)),
172
+ duplicatedItemId: duplicates[0]?.duplicatedItemId,
173
+ duplicatedDocumentId: duplicates[0]?.duplicatedDocumentId,
174
+ duplicatedItemIds: duplicates.map(
175
+ (duplicate) => duplicate.duplicatedItemId,
176
+ ),
177
+ duplicatedDocumentIds: duplicates.map(
178
+ (duplicate) => duplicate.duplicatedDocumentId,
179
+ ),
180
+ sourceItemIds,
181
+ sourceDocumentIds,
182
+ sourceToDuplicate: duplicates.map((duplicate) => ({
183
+ sourceItemId: duplicate.sourceItemId,
184
+ sourceDocumentId: duplicate.sourceDocumentId,
185
+ duplicatedItemId: duplicate.duplicatedItemId,
186
+ duplicatedDocumentId: duplicate.duplicatedDocumentId,
187
+ })),
188
+ duplicatedCount: duplicates.length,
189
+ };
190
+ },
191
+ });
@@ -1,8 +1,11 @@
1
1
  import { defineAction } from "@agent-native/core";
2
- import { getRequestUserEmail } from "@agent-native/core/server";
3
2
  import { z } from "zod";
4
3
 
5
4
  import { linkDocumentToNotionPage } from "../server/lib/notion-sync.js";
5
+ import {
6
+ getNotionDocumentOwner,
7
+ resolveDocumentId,
8
+ } from "./_notion-action-utils.js";
6
9
 
7
10
  export default defineAction({
8
11
  description: "Link a document to a Notion page for syncing.",
@@ -10,19 +13,19 @@ export default defineAction({
10
13
  documentId: z.string().optional().describe("Document ID (required)"),
11
14
  id: z.string().optional().describe("Alias for --documentId"),
12
15
  pageId: z.string().optional().describe("Notion page ID or URL (required)"),
16
+ pageIdOrUrl: z.string().optional().describe("Alias for --pageId"),
13
17
  url: z.string().optional().describe("Alias for --pageId"),
14
18
  }),
15
- http: false,
19
+ http: { method: "POST" },
16
20
  run: async (args) => {
17
- const owner = getRequestUserEmail();
18
- if (!owner) throw new Error("no authenticated user");
19
- const documentId = args.documentId || args.id;
20
- const pageIdOrUrl = args.pageId || args.url;
21
+ const documentId = resolveDocumentId(args);
22
+ const pageIdOrUrl = args.pageId || args.pageIdOrUrl || args.url;
21
23
 
22
- if (!documentId || !pageIdOrUrl) {
24
+ if (!pageIdOrUrl) {
23
25
  throw new Error("documentId and pageId are required");
24
26
  }
25
27
 
28
+ const owner = await getNotionDocumentOwner(documentId);
26
29
  return linkDocumentToNotionPage(owner, documentId, pageIdOrUrl);
27
30
  },
28
31
  });
@@ -1,16 +1,15 @@
1
1
  import { defineAction } from "@agent-native/core";
2
- import { getRequestUserEmail } from "@agent-native/core/server";
3
2
  import { z } from "zod";
4
3
 
5
4
  import { listNotionLinks } from "../server/lib/notion-sync.js";
5
+ import { getCurrentNotionOwner } from "./_notion-action-utils.js";
6
6
 
7
7
  export default defineAction({
8
8
  description: "List all documents linked to Notion pages.",
9
9
  schema: z.object({}),
10
- http: false,
10
+ http: { method: "GET" },
11
11
  run: async () => {
12
- const owner = getRequestUserEmail();
13
- if (!owner) throw new Error("no authenticated user");
12
+ const owner = getCurrentNotionOwner();
14
13
  return listNotionLinks(owner);
15
14
  },
16
15
  });
@@ -1,8 +1,11 @@
1
1
  import { defineAction } from "@agent-native/core";
2
- import { getRequestUserEmail } from "@agent-native/core/server";
3
2
  import { z } from "zod";
4
3
 
5
4
  import { pullDocumentFromNotion } from "../server/lib/notion-sync.js";
5
+ import {
6
+ getNotionDocumentOwner,
7
+ resolveDocumentId,
8
+ } from "./_notion-action-utils.js";
6
9
 
7
10
  export default defineAction({
8
11
  description: "Pull content from a linked Notion page into a local document.",
@@ -10,15 +13,10 @@ export default defineAction({
10
13
  documentId: z.string().optional().describe("Document ID (required)"),
11
14
  id: z.string().optional().describe("Alias for --documentId"),
12
15
  }),
13
- http: false,
16
+ http: { method: "POST" },
14
17
  run: async (args) => {
15
- const documentId = args.documentId || args.id;
16
- if (!documentId) {
17
- throw new Error("documentId is required");
18
- }
19
-
20
- const owner = getRequestUserEmail();
21
- if (!owner) throw new Error("no authenticated user");
18
+ const documentId = resolveDocumentId(args);
19
+ const owner = await getNotionDocumentOwner(documentId);
22
20
  return pullDocumentFromNotion(owner, documentId, true);
23
21
  },
24
22
  });
@@ -1,8 +1,11 @@
1
1
  import { defineAction } from "@agent-native/core";
2
- import { getRequestUserEmail } from "@agent-native/core/server";
3
2
  import { z } from "zod";
4
3
 
5
4
  import { pushDocumentToNotion } from "../server/lib/notion-sync.js";
5
+ import {
6
+ getNotionDocumentOwner,
7
+ resolveDocumentId,
8
+ } from "./_notion-action-utils.js";
6
9
 
7
10
  export default defineAction({
8
11
  description: "Push local document content to a linked Notion page.",
@@ -10,15 +13,10 @@ export default defineAction({
10
13
  documentId: z.string().optional().describe("Document ID (required)"),
11
14
  id: z.string().optional().describe("Alias for --documentId"),
12
15
  }),
13
- http: false,
16
+ http: { method: "POST" },
14
17
  run: async (args) => {
15
- const documentId = args.documentId || args.id;
16
- if (!documentId) {
17
- throw new Error("documentId is required");
18
- }
19
-
20
- const owner = getRequestUserEmail();
21
- if (!owner) throw new Error("no authenticated user");
18
+ const documentId = resolveDocumentId(args);
19
+ const owner = await getNotionDocumentOwner(documentId);
22
20
  return pushDocumentToNotion(owner, documentId);
23
21
  },
24
22
  });
@@ -0,0 +1,24 @@
1
+ import { defineAction } from "@agent-native/core";
2
+ import { z } from "zod";
3
+
4
+ import { refreshDocumentSyncStatus } from "../server/lib/notion-sync.js";
5
+ import {
6
+ getNotionDocumentOwner,
7
+ resolveDocumentId,
8
+ } from "./_notion-action-utils.js";
9
+
10
+ export default defineAction({
11
+ description: "Refresh Notion sync status for a linked Content document.",
12
+ schema: z.object({
13
+ documentId: z.string().optional().describe("Document ID (required)"),
14
+ id: z.string().optional().describe("Alias for --documentId"),
15
+ autoSync: z.boolean().optional(),
16
+ }),
17
+ run: async (args) => {
18
+ const documentId = resolveDocumentId(args);
19
+ const owner = await getNotionDocumentOwner(documentId);
20
+ return refreshDocumentSyncStatus(owner, documentId, {
21
+ autoSync: !!args.autoSync,
22
+ });
23
+ },
24
+ });
@@ -0,0 +1,23 @@
1
+ import { defineAction } from "@agent-native/core";
2
+ import { z } from "zod";
3
+
4
+ import { resolveDocumentSyncConflict } from "../server/lib/notion-sync.js";
5
+ import {
6
+ getNotionDocumentOwner,
7
+ resolveDocumentId,
8
+ } from "./_notion-action-utils.js";
9
+
10
+ export default defineAction({
11
+ description: "Resolve a Notion sync conflict by pulling or pushing.",
12
+ schema: z.object({
13
+ documentId: z.string().optional().describe("Document ID (required)"),
14
+ id: z.string().optional().describe("Alias for --documentId"),
15
+ direction: z.enum(["pull", "push"]),
16
+ }),
17
+ http: { method: "POST" },
18
+ run: async (args) => {
19
+ const documentId = resolveDocumentId(args);
20
+ const owner = await getNotionDocumentOwner(documentId);
21
+ return resolveDocumentSyncConflict(owner, documentId, args.direction);
22
+ },
23
+ });
@@ -0,0 +1,67 @@
1
+ import { defineAction } from "@agent-native/core";
2
+ import { z } from "zod";
3
+
4
+ import {
5
+ getNotionConnectionForOwner,
6
+ notionFetch,
7
+ } from "../server/lib/notion.js";
8
+ import type {
9
+ NotionSearchResponse,
10
+ NotionSearchResult,
11
+ } from "../shared/api.js";
12
+ import { getCurrentNotionOwner } from "./_notion-action-utils.js";
13
+
14
+ export default defineAction({
15
+ description: "Search connected Notion pages visible to the current user.",
16
+ schema: z.object({
17
+ query: z.string().default(""),
18
+ }),
19
+ http: { method: "GET" },
20
+ run: async ({ query }): Promise<NotionSearchResponse> => {
21
+ const owner = getCurrentNotionOwner();
22
+ const conn = await getNotionConnectionForOwner(owner);
23
+ if (!conn) {
24
+ throw new Error("Notion not connected");
25
+ }
26
+
27
+ const result = await notionFetch<{
28
+ results: Array<{
29
+ id: string;
30
+ object: string;
31
+ icon?: { type: string; emoji?: string } | null;
32
+ url?: string;
33
+ last_edited_time?: string;
34
+ properties?: Record<string, any>;
35
+ }>;
36
+ has_more: boolean;
37
+ }>("/search", conn.accessToken, {
38
+ method: "POST",
39
+ body: JSON.stringify({
40
+ query: query.trim(),
41
+ filter: { value: "page", property: "object" },
42
+ sort: { direction: "descending", timestamp: "last_edited_time" },
43
+ page_size: 20,
44
+ }),
45
+ });
46
+
47
+ const results: NotionSearchResult[] = result.results.map((page) => {
48
+ const titleProp = Object.values(page.properties || {}).find(
49
+ (value: any) => value?.type === "title",
50
+ ) as any;
51
+ const title =
52
+ (titleProp?.title || [])
53
+ .map((part: any) => part.plain_text || "")
54
+ .join("") || "Untitled";
55
+
56
+ return {
57
+ id: page.id,
58
+ title,
59
+ icon: page.icon?.type === "emoji" ? page.icon.emoji || null : null,
60
+ url: page.url || `https://notion.so/${page.id.replace(/-/g, "")}`,
61
+ lastEditedTime: page.last_edited_time || null,
62
+ };
63
+ });
64
+
65
+ return { results, hasMore: result.has_more };
66
+ },
67
+ });
@@ -0,0 +1,23 @@
1
+ import { defineAction } from "@agent-native/core";
2
+ import { z } from "zod";
3
+
4
+ import { unlinkDocumentFromNotion } from "../server/lib/notion-sync.js";
5
+ import {
6
+ getNotionDocumentOwner,
7
+ resolveDocumentId,
8
+ } from "./_notion-action-utils.js";
9
+
10
+ export default defineAction({
11
+ description: "Unlink a Content document from its Notion page.",
12
+ schema: z.object({
13
+ documentId: z.string().optional().describe("Document ID (required)"),
14
+ id: z.string().optional().describe("Alias for --documentId"),
15
+ }),
16
+ http: { method: "DELETE" },
17
+ run: async (args) => {
18
+ const documentId = resolveDocumentId(args);
19
+ const owner = await getNotionDocumentOwner(documentId);
20
+ await unlinkDocumentFromNotion(owner, documentId);
21
+ return { success: true };
22
+ },
23
+ });
@@ -143,8 +143,10 @@ import {
143
143
  useChangeContentDatabaseSourceRole,
144
144
  useContentDatabase,
145
145
  useContentDatabases,
146
+ useDeleteDatabaseItems,
146
147
  useDisconnectContentDatabaseSource,
147
148
  useDuplicateDatabaseItem,
149
+ useDuplicateDatabaseItems,
148
150
  useExecuteBuilderSourceBatch,
149
151
  useMoveDatabaseItem,
150
152
  usePrepareBuilderSourceReview,
@@ -2862,9 +2864,9 @@ function DatabaseTableView({
2862
2864
  const db = useDatabaseT();
2863
2865
  const queryClient = useQueryClient();
2864
2866
  const moveItem = useMoveDatabaseItem(databaseDocumentId);
2865
- const duplicateItem = useDuplicateDatabaseItem(databaseDocumentId);
2867
+ const duplicateItems = useDuplicateDatabaseItems(databaseDocumentId);
2866
2868
  const setProperty = useSetDocumentProperty(databaseDocumentId);
2867
- const deleteDocument = useDeleteDocument();
2869
+ const deleteItems = useDeleteDatabaseItems(databaseDocumentId);
2868
2870
  const [draggedItemId, setDraggedItemId] = useState<string | null>(null);
2869
2871
  const [dropTargetItemId, setDropTargetItemId] = useState<string | null>(null);
2870
2872
  const [draggedPropertyId, setDraggedPropertyId] = useState<string | null>(
@@ -3113,14 +3115,15 @@ function DatabaseTableView({
3113
3115
  async function deleteSelectedRows() {
3114
3116
  if (selectedItems.length === 0) return;
3115
3117
  const selectedSnapshot = selectedItems;
3116
- onClearSelection();
3117
3118
  setConfirmDeleteSelectedOpen(false);
3118
3119
 
3119
3120
  try {
3121
+ await deleteItems.mutateAsync({
3122
+ documentId: databaseDocumentId,
3123
+ itemIds: selectedSnapshot.map((item) => item.id),
3124
+ });
3125
+ onClearSelection();
3120
3126
  onDeletedPreviewItems(selectedSnapshot);
3121
- for (const item of selectedSnapshot) {
3122
- await deleteDocument.mutateAsync({ id: item.document.id });
3123
- }
3124
3127
  await queryClient.invalidateQueries({
3125
3128
  queryKey: [
3126
3129
  "action",
@@ -3144,22 +3147,11 @@ function DatabaseTableView({
3144
3147
  const selectedSnapshot = selectedItems;
3145
3148
  setIsDuplicatingSelected(true);
3146
3149
 
3147
- let duplicatedPreviewItem: ContentDatabaseItem | null = null;
3148
- let duplicatedCount = 0;
3149
- let failedCount = 0;
3150
-
3151
3150
  try {
3152
- for (const item of selectedSnapshot) {
3153
- try {
3154
- const response = await duplicateItem.mutateAsync({ itemId: item.id });
3155
- duplicatedCount += 1;
3156
- duplicatedPreviewItem =
3157
- databaseDuplicatedItemFromResponse(response) ??
3158
- duplicatedPreviewItem;
3159
- } catch {
3160
- failedCount += 1;
3161
- }
3162
- }
3151
+ const response = await duplicateItems.mutateAsync({
3152
+ documentId: databaseDocumentId,
3153
+ itemIds: selectedSnapshot.map((item) => item.id),
3154
+ });
3163
3155
 
3164
3156
  await queryClient.invalidateQueries({
3165
3157
  queryKey: [
@@ -3172,16 +3164,15 @@ function DatabaseTableView({
3172
3164
  queryKey: ["action", "list-documents"],
3173
3165
  });
3174
3166
 
3167
+ const duplicatedPreviewItem =
3168
+ databaseDuplicatedItemFromResponse(response);
3175
3169
  if (duplicatedPreviewItem) onPreview(duplicatedPreviewItem);
3176
- if (duplicatedCount > 0) onClearSelection();
3177
- if (failedCount > 0) {
3178
- toast.error(db("failedToDuplicateEverySelectedRow"), {
3179
- description:
3180
- duplicatedCount > 0
3181
- ? `${duplicatedCount} duplicated, ${failedCount} failed.`
3182
- : "No rows were duplicated.",
3183
- });
3184
- }
3170
+ onClearSelection();
3171
+ } catch (err) {
3172
+ toast.error(db("failedToDuplicateEverySelectedRow"), {
3173
+ description:
3174
+ err instanceof Error ? err.message : db("somethingWentWrong"),
3175
+ });
3185
3176
  } finally {
3186
3177
  setIsDuplicatingSelected(false);
3187
3178
  }
@@ -3240,9 +3231,11 @@ function DatabaseTableView({
3240
3231
  canEdit={canEdit}
3241
3232
  properties={bulkEditableProperties}
3242
3233
  duplicateDisabled={
3243
- isDuplicatingSelected || deleteDocument.isPending
3234
+ isDuplicatingSelected ||
3235
+ duplicateItems.isPending ||
3236
+ deleteItems.isPending
3244
3237
  }
3245
- deleteDisabled={deleteDocument.isPending}
3238
+ deleteDisabled={deleteItems.isPending}
3246
3239
  updateDisabled={setProperty.isPending}
3247
3240
  onClearSelection={onClearSelection}
3248
3241
  onSetPropertyValue={setSelectedPropertyValue}
@@ -3466,10 +3459,10 @@ function DatabaseTableView({
3466
3459
  </AlertDialogCancel>
3467
3460
  <AlertDialogAction
3468
3461
  className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
3469
- disabled={deleteDocument.isPending}
3462
+ disabled={deleteItems.isPending}
3470
3463
  onClick={() => void deleteSelectedRows()}
3471
3464
  >
3472
- {deleteDocument.isPending ? "Deleting..." : "Delete"}
3465
+ {deleteItems.isPending ? "Deleting..." : "Delete"}
3473
3466
  </AlertDialogAction>
3474
3467
  </AlertDialogFooter>
3475
3468
  </AlertDialogContent>
@@ -6,7 +6,6 @@ import {
6
6
  emailToName,
7
7
  useSession,
8
8
  useT,
9
- appApiPath,
10
9
  agentNativePath,
11
10
  type CollabUser,
12
11
  } from "@agent-native/core/client";
@@ -41,7 +40,11 @@ import {
41
40
  useUpdateDocument,
42
41
  } from "@/hooks/use-documents";
43
42
  import { useLocalStorage } from "@/hooks/use-local-storage";
44
- import { useDocumentSyncStatus } from "@/hooks/use-notion";
43
+ import {
44
+ documentSyncStatusQueryKey,
45
+ useDocumentSyncStatus,
46
+ usePushDocumentToNotion,
47
+ } from "@/hooks/use-notion";
45
48
  import {
46
49
  canWriteLinkedLocalSource,
47
50
  readDocumentFromLinkedLocalSource,
@@ -360,6 +363,7 @@ function DocumentEditorBody({ documentId, document }: DocumentEditorBodyProps) {
360
363
  useDocumentSyncStatus(canEdit && !isLocalFileDocument ? documentId : null, {
361
364
  autoSync,
362
365
  });
366
+ const pushDocumentToNotion = usePushDocumentToNotion(documentId);
363
367
  const [localTitle, setLocalTitle] = useState("");
364
368
  const [localContent, setLocalContent] = useState("");
365
369
  const [localContentUpdatedAt, setLocalContentUpdatedAt] = useState<
@@ -775,20 +779,18 @@ function DocumentEditorBody({ documentId, document }: DocumentEditorBodyProps) {
775
779
  // the debounce and the next save, reading the previous content.
776
780
  // Pulls remain driven by the polling refetch in useDocumentSyncStatus.
777
781
  if (autoSync) {
778
- const status = queryClient.getQueryData<DocumentSyncStatus>([
779
- "document-sync",
780
- documentId,
781
- ]);
782
+ const status = queryClient.getQueryData<DocumentSyncStatus>(
783
+ documentSyncStatusQueryKey(documentId, { autoSync }),
784
+ );
782
785
  if (status?.pageId && !status.hasConflict) {
783
786
  try {
784
- const res = await fetch(
785
- appApiPath(`/api/documents/${documentId}/notion/push`),
786
- { method: "POST" },
787
+ const next = await pushDocumentToNotion.mutateAsync({
788
+ documentId,
789
+ });
790
+ queryClient.setQueryData(
791
+ documentSyncStatusQueryKey(documentId, { autoSync }),
792
+ next,
787
793
  );
788
- if (res.ok) {
789
- const next = (await res.json()) as DocumentSyncStatus;
790
- queryClient.setQueryData(["document-sync", documentId], next);
791
- }
792
794
  } catch {
793
795
  // Non-fatal — next polling refetch will surface any error.
794
796
  }
@@ -803,6 +805,7 @@ function DocumentEditorBody({ documentId, document }: DocumentEditorBodyProps) {
803
805
  autoSync,
804
806
  isLinkedLocalSourceDocument,
805
807
  persistDocumentUpdates,
808
+ pushDocumentToNotion,
806
809
  queryClient,
807
810
  ],
808
811
  );