@agent-native/core 0.102.2 → 0.103.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/core/CHANGELOG.md +6 -0
- package/corpus/core/docs/content/local-file-mode.mdx +99 -489
- package/corpus/core/docs/content/locales/ar-SA/local-file-mode.mdx +35 -490
- package/corpus/core/docs/content/locales/ar-SA/template-content.mdx +10 -24
- package/corpus/core/docs/content/locales/de-DE/local-file-mode.mdx +37 -491
- package/corpus/core/docs/content/locales/de-DE/template-content.mdx +10 -24
- package/corpus/core/docs/content/locales/es-ES/local-file-mode.mdx +35 -493
- package/corpus/core/docs/content/locales/es-ES/template-content.mdx +10 -24
- package/corpus/core/docs/content/locales/fr-FR/local-file-mode.mdx +38 -491
- package/corpus/core/docs/content/locales/fr-FR/template-content.mdx +10 -24
- package/corpus/core/docs/content/locales/hi-IN/local-file-mode.mdx +33 -492
- package/corpus/core/docs/content/locales/hi-IN/template-content.mdx +10 -24
- package/corpus/core/docs/content/locales/ja-JP/local-file-mode.mdx +36 -492
- package/corpus/core/docs/content/locales/ja-JP/template-content.mdx +10 -24
- package/corpus/core/docs/content/locales/ko-KR/local-file-mode.mdx +35 -490
- package/corpus/core/docs/content/locales/ko-KR/template-content.mdx +10 -24
- package/corpus/core/docs/content/locales/pt-BR/local-file-mode.mdx +35 -493
- package/corpus/core/docs/content/locales/pt-BR/template-content.mdx +10 -24
- package/corpus/core/docs/content/locales/zh-CN/local-file-mode.mdx +31 -489
- package/corpus/core/docs/content/locales/zh-CN/template-content.mdx +9 -24
- package/corpus/core/docs/content/locales/zh-TW/local-file-mode.mdx +31 -489
- package/corpus/core/docs/content/locales/zh-TW/template-content.mdx +9 -24
- package/corpus/core/docs/content/template-content.mdx +26 -42
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/cli/content-local.ts +86 -18
- package/corpus/core/src/cli/index.ts +2 -2
- package/corpus/core/src/cli/skills-content/content-skill.ts +36 -25
- package/corpus/core/src/cli/skills.ts +47 -13
- package/corpus/core/src/local-artifacts/index.ts +65 -0
- package/corpus/templates/assets/app/components/library/GenerationPresetsPanel.tsx +325 -0
- package/corpus/templates/assets/app/hooks/use-navigation-state.ts +12 -0
- package/corpus/templates/assets/app/i18n/zh-TW.ts +21 -0
- package/corpus/templates/assets/app/i18n-data.ts +215 -0
- package/corpus/templates/assets/app/routes/brand-kits.$id.tsx +19 -479
- package/corpus/templates/assets/app/routes/brand-kits.$id_.presets.$presetId.tsx +1 -1
- package/corpus/templates/assets/app/routes/brand-kits.$id_.settings.tsx +446 -0
- package/corpus/templates/clips/app/components/editor/editor-layout.tsx +12 -2
- package/corpus/templates/clips/app/components/player/settings-panel.tsx +30 -12
- package/corpus/templates/clips/app/components/player/video-player.tsx +5 -1
- package/corpus/templates/clips/app/components/recorder/microphone-visualizer.tsx +22 -3
- package/corpus/templates/clips/app/i18n/ar-SA.ts +3 -2
- package/corpus/templates/clips/app/i18n/de-DE.ts +4 -2
- package/corpus/templates/clips/app/i18n/en-US.ts +3 -2
- package/corpus/templates/clips/app/i18n/es-ES.ts +4 -2
- package/corpus/templates/clips/app/i18n/fr-FR.ts +3 -2
- package/corpus/templates/clips/app/i18n/hi-IN.ts +3 -2
- package/corpus/templates/clips/app/i18n/ja-JP.ts +4 -1
- package/corpus/templates/clips/app/i18n/ko-KR.ts +3 -2
- package/corpus/templates/clips/app/i18n/pt-BR.ts +4 -2
- package/corpus/templates/clips/app/i18n/zh-CN.ts +3 -2
- package/corpus/templates/clips/app/i18n/zh-TW.ts +3 -2
- package/corpus/templates/clips/app/routes/r.$recordingId.tsx +27 -1
- package/corpus/templates/clips/server/lib/share-password.ts +6 -3
- package/corpus/templates/content/.agents/skills/content/SKILL.md +26 -39
- package/corpus/templates/content/AGENTS.md +25 -30
- package/corpus/templates/content/actions/_builder-docs-client.ts +23 -0
- package/corpus/templates/content/actions/_content-database-source-adapters.ts +21 -3
- package/corpus/templates/content/actions/_content-files.ts +338 -0
- package/corpus/templates/content/actions/_content-space-access.ts +135 -0
- package/corpus/templates/content/actions/_content-spaces.ts +640 -0
- package/corpus/templates/content/actions/_database-source-utils.ts +90 -7
- package/corpus/templates/content/actions/_database-utils.ts +7 -1
- package/corpus/templates/content/actions/_local-file-documents.ts +0 -9
- package/corpus/templates/content/actions/_local-folder-source.ts +53 -0
- package/corpus/templates/content/actions/_property-utils.ts +9 -4
- package/corpus/templates/content/actions/add-database-item.ts +108 -65
- package/corpus/templates/content/actions/backfill-content-files.ts +22 -0
- package/corpus/templates/content/actions/connect-local-folder-source.ts +221 -0
- package/corpus/templates/content/actions/create-content-database.ts +129 -3
- package/corpus/templates/content/actions/create-document.ts +65 -55
- package/corpus/templates/content/actions/create-inline-content-database.ts +6 -1
- package/corpus/templates/content/actions/delete-content-database.ts +3 -0
- package/corpus/templates/content/actions/delete-document.ts +7 -11
- package/corpus/templates/content/actions/disconnect-local-folder-source.ts +175 -0
- package/corpus/templates/content/actions/duplicate-database-item.ts +10 -0
- package/corpus/templates/content/actions/duplicate-database-items.ts +13 -0
- package/corpus/templates/content/actions/edit-document.ts +2 -28
- package/corpus/templates/content/actions/ensure-content-spaces.ts +26 -0
- package/corpus/templates/content/actions/export-content-source.ts +47 -9
- package/corpus/templates/content/actions/get-document.ts +0 -14
- package/corpus/templates/content/actions/import-content-source.ts +43 -3
- package/corpus/templates/content/actions/list-content-spaces.ts +103 -0
- package/corpus/templates/content/actions/list-documents.ts +12 -9
- package/corpus/templates/content/actions/move-document.ts +3 -14
- package/corpus/templates/content/actions/pull-document.ts +0 -23
- package/corpus/templates/content/actions/remove-local-file-source.ts +50 -29
- package/corpus/templates/content/actions/resolve-local-folder-conflict.ts +442 -0
- package/corpus/templates/content/actions/reveal-local-source-file.ts +6 -17
- package/corpus/templates/content/actions/search-documents.ts +0 -34
- package/corpus/templates/content/actions/share-local-file-document.ts +25 -1
- package/corpus/templates/content/actions/submit-content-database-form.ts +12 -0
- package/corpus/templates/content/actions/sync-local-folder-source.ts +731 -0
- package/corpus/templates/content/actions/sync-manifest-local-folder-source.ts +123 -0
- package/corpus/templates/content/actions/update-content-database-view.ts +10 -1
- package/corpus/templates/content/actions/update-document.ts +0 -15
- package/corpus/templates/content/actions/view-screen.ts +2 -50
- package/corpus/templates/content/app/components/editor/SlashCommandMenu.tsx +76 -62
- package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +70 -22
- package/corpus/templates/content/app/components/editor/database/grouping.ts +2 -1
- package/corpus/templates/content/app/components/editor/database/settings.tsx +23 -20
- package/corpus/templates/content/app/components/editor/database/shared.tsx +2 -0
- package/corpus/templates/content/app/components/editor/database/sidebar.tsx +330 -0
- package/corpus/templates/content/app/components/editor/database/types.ts +1 -0
- package/corpus/templates/content/app/components/editor/database/view-config.ts +3 -1
- package/corpus/templates/content/app/components/layout/Layout.tsx +25 -1
- package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +209 -113
- package/corpus/templates/content/app/components/sidebar/select-content-space.ts +31 -0
- package/corpus/templates/content/app/hooks/use-content-database.ts +16 -0
- package/corpus/templates/content/app/hooks/use-content-spaces.ts +39 -0
- package/corpus/templates/content/app/i18n/zh-TW.ts +11 -0
- package/corpus/templates/content/app/i18n-data.ts +75 -0
- package/corpus/templates/content/app/routes/_app.local-files.tsx +174 -65
- package/corpus/templates/content/changelog/2026-07-16-content-callouts-can-now-be-reviewed-and-published-to-builder.md +6 -0
- package/corpus/templates/content/changelog/2026-07-16-heading-5-and-heading-6-are-available-from-the-editor-slash-.md +6 -0
- package/corpus/templates/content/changelog/2026-07-16-organize-every-workspace-through-a-customizable-files-databa.md +6 -0
- package/corpus/templates/content/parity/matrix.md +2 -1
- package/corpus/templates/content/parity/matrix.ts +37 -1
- package/corpus/templates/content/scripts/dev-database.mjs +7 -5
- package/corpus/templates/content/server/db/schema.ts +113 -40
- package/corpus/templates/content/server/lib/document-context.ts +15 -1
- package/corpus/templates/content/server/lib/notion-sync.ts +6 -0
- package/corpus/templates/content/server/plugins/db.ts +153 -0
- package/corpus/templates/content/shared/api.ts +17 -3
- package/corpus/templates/content/shared/builder-mdx.ts +163 -16
- package/corpus/templates/design/.agents/skills/design-templates/SKILL.md +59 -0
- package/corpus/templates/design/AGENTS.md +6 -1
- package/corpus/templates/design/actions/create-design-from-template.ts +19 -7
- package/corpus/templates/design/actions/list-design-templates.ts +69 -21
- package/corpus/templates/design/actions/navigate.ts +2 -2
- package/corpus/templates/design/actions/view-screen.ts +15 -2
- package/corpus/templates/design/agent-native.app-skill.json +5 -0
- package/corpus/templates/design/app/components/editor/PromptDialog.tsx +281 -56
- package/corpus/templates/design/app/components/templates/TemplatePreview.tsx +14 -2
- package/corpus/templates/design/app/hooks/use-navigation-state.ts +3 -2
- package/corpus/templates/design/app/i18n/zh-TW.ts +3 -3
- package/corpus/templates/design/app/i18n-data.ts +21 -2
- package/corpus/templates/design/app/i18n-template-feature.ts +218 -10
- package/corpus/templates/design/app/pages/Index.tsx +195 -24
- package/corpus/templates/design/app/pages/Templates.tsx +144 -55
- package/corpus/templates/design/app/pages/design-editor/generation-prompt-directives.ts +12 -1
- package/corpus/templates/design/changelog/2026-07-14-templates-now-appear-in-the-new-design-picker-with-previews-.md +6 -0
- package/corpus/templates/design/changelog/2026-07-15-templates-now-open-immediately-after-copying-even-while-the-.md +6 -0
- package/corpus/templates/design/server/plugins/agent-chat.ts +1 -1
- package/corpus/templates/mail/AGENTS.md +23 -18
- package/corpus/templates/mail/actions/bulk-archive.ts +32 -28
- package/corpus/templates/mail/actions/mark-read.ts +131 -20
- package/corpus/templates/mail/actions/mark-thread-read.ts +1 -1
- package/corpus/templates/mail/actions/move-email.ts +30 -24
- package/corpus/templates/mail/actions/send-email.ts +73 -68
- package/corpus/templates/mail/changelog/2026-07-15-unread-inbox-cleanup-now-completes-reliably.md +6 -0
- package/corpus/templates/mail/server/handlers/emails.ts +218 -209
- package/corpus/templates/mail/server/lib/bulk-mark-read.ts +30 -0
- package/corpus/templates/mail/server/lib/email-state.ts +198 -113
- package/corpus/templates/mail/server/lib/google-auth.ts +218 -25
- package/corpus/templates/mail/server/lib/jobs.ts +69 -74
- package/corpus/templates/mail/server/lib/local-email-store.ts +265 -0
- package/corpus/templates/mail/server/plugins/agent-chat.ts +6 -0
- package/dist/cli/content-local.d.ts +1 -0
- package/dist/cli/content-local.d.ts.map +1 -1
- package/dist/cli/content-local.js +75 -17
- package/dist/cli/content-local.js.map +1 -1
- package/dist/cli/index.js +2 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/skills-content/content-skill.d.ts +1 -1
- package/dist/cli/skills-content/content-skill.d.ts.map +1 -1
- package/dist/cli/skills-content/content-skill.js +36 -25
- package/dist/cli/skills-content/content-skill.js.map +1 -1
- package/dist/cli/skills.d.ts.map +1 -1
- package/dist/cli/skills.js +47 -14
- package/dist/cli/skills.js.map +1 -1
- package/dist/collab/awareness.d.ts +2 -2
- package/dist/collab/awareness.d.ts.map +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/local-artifacts/index.d.ts +10 -0
- package/dist/local-artifacts/index.d.ts.map +1 -1
- package/dist/local-artifacts/index.js +39 -0
- package/dist/local-artifacts/index.js.map +1 -1
- package/dist/notifications/routes.d.ts +1 -1
- package/dist/observability/routes.d.ts +5 -5
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/secrets/routes.d.ts +9 -9
- package/docs/content/local-file-mode.mdx +99 -489
- package/docs/content/locales/ar-SA/local-file-mode.mdx +35 -490
- package/docs/content/locales/ar-SA/template-content.mdx +10 -24
- package/docs/content/locales/de-DE/local-file-mode.mdx +37 -491
- package/docs/content/locales/de-DE/template-content.mdx +10 -24
- package/docs/content/locales/es-ES/local-file-mode.mdx +35 -493
- package/docs/content/locales/es-ES/template-content.mdx +10 -24
- package/docs/content/locales/fr-FR/local-file-mode.mdx +38 -491
- package/docs/content/locales/fr-FR/template-content.mdx +10 -24
- package/docs/content/locales/hi-IN/local-file-mode.mdx +33 -492
- package/docs/content/locales/hi-IN/template-content.mdx +10 -24
- package/docs/content/locales/ja-JP/local-file-mode.mdx +36 -492
- package/docs/content/locales/ja-JP/template-content.mdx +10 -24
- package/docs/content/locales/ko-KR/local-file-mode.mdx +35 -490
- package/docs/content/locales/ko-KR/template-content.mdx +10 -24
- package/docs/content/locales/pt-BR/local-file-mode.mdx +35 -493
- package/docs/content/locales/pt-BR/template-content.mdx +10 -24
- package/docs/content/locales/zh-CN/local-file-mode.mdx +31 -489
- package/docs/content/locales/zh-CN/template-content.mdx +9 -24
- package/docs/content/locales/zh-TW/local-file-mode.mdx +31 -489
- package/docs/content/locales/zh-TW/template-content.mdx +9 -24
- package/docs/content/template-content.mdx +26 -42
- package/package.json +1 -1
- package/corpus/templates/assets/app/components/library/EditLibraryDialog.tsx +0 -126
|
@@ -3,37 +3,148 @@ import { writeAppState } from "@agent-native/core/application-state";
|
|
|
3
3
|
import { getRequestUserEmail } from "@agent-native/core/server";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
|
|
6
|
-
import { markRead } from "../server/lib/email-state.js";
|
|
6
|
+
import { markAllLocalUnreadRead, markRead } from "../server/lib/email-state.js";
|
|
7
7
|
import {
|
|
8
8
|
gmailBatchModifyByAccount,
|
|
9
9
|
isConnected,
|
|
10
|
+
markAllUnreadReadForAccount,
|
|
10
11
|
} from "../server/lib/google-auth.js";
|
|
11
12
|
|
|
13
|
+
export const MARK_READ_DESCRIPTION =
|
|
14
|
+
'Mark explicit email IDs as read/unread, or use scope "all-unread" once to mark every unread message in one account read while preserving excluded thread IDs. Never loop mark-thread-read for broad cleanup.';
|
|
15
|
+
|
|
12
16
|
export default defineAction({
|
|
13
|
-
description:
|
|
14
|
-
schema: z
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
description: MARK_READ_DESCRIPTION,
|
|
18
|
+
schema: z
|
|
19
|
+
.object({
|
|
20
|
+
id: z.string().optional().describe("Email ID(s), comma-separated"),
|
|
21
|
+
unread: z.coerce
|
|
22
|
+
.boolean()
|
|
23
|
+
.optional()
|
|
24
|
+
.describe("Set to true to mark explicit IDs unread instead of read"),
|
|
25
|
+
accountEmail: z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.describe(
|
|
29
|
+
'Exact connected account; required when scope is "all-unread"',
|
|
30
|
+
),
|
|
31
|
+
accountEmails: z
|
|
32
|
+
.string()
|
|
33
|
+
.optional()
|
|
34
|
+
.describe(
|
|
35
|
+
"Per-id account emails, comma-separated and positionally matched to --id (bulk UI calls only)",
|
|
36
|
+
),
|
|
37
|
+
scope: z
|
|
38
|
+
.enum(["all-unread"])
|
|
39
|
+
.optional()
|
|
40
|
+
.describe(
|
|
41
|
+
'Mark every unread message in accountEmail read in one verified action; mutually exclusive with "id"',
|
|
42
|
+
),
|
|
43
|
+
excludeThreadIds: z
|
|
44
|
+
.string()
|
|
45
|
+
.optional()
|
|
46
|
+
.describe(
|
|
47
|
+
'Thread IDs to leave unread, comma-separated; valid only with scope "all-unread"',
|
|
48
|
+
),
|
|
49
|
+
})
|
|
50
|
+
.superRefine((args, ctx) => {
|
|
51
|
+
const hasIds = Boolean(args.id?.trim());
|
|
52
|
+
const hasScope = Boolean(args.scope);
|
|
53
|
+
if (hasIds === hasScope) {
|
|
54
|
+
ctx.addIssue({
|
|
55
|
+
code: "custom",
|
|
56
|
+
message: 'Provide exactly one of "id" or "scope"',
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (hasScope && !args.accountEmail?.trim()) {
|
|
60
|
+
ctx.addIssue({
|
|
61
|
+
code: "custom",
|
|
62
|
+
path: ["accountEmail"],
|
|
63
|
+
message: 'accountEmail is required for scope "all-unread"',
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (hasScope && args.accountEmails) {
|
|
67
|
+
ctx.addIssue({
|
|
68
|
+
code: "custom",
|
|
69
|
+
path: ["accountEmails"],
|
|
70
|
+
message: 'accountEmails cannot be used with scope "all-unread"',
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (hasScope && args.unread === true) {
|
|
74
|
+
ctx.addIssue({
|
|
75
|
+
code: "custom",
|
|
76
|
+
path: ["unread"],
|
|
77
|
+
message: 'scope "all-unread" can only mark messages read',
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (hasIds && args.excludeThreadIds) {
|
|
81
|
+
ctx.addIssue({
|
|
82
|
+
code: "custom",
|
|
83
|
+
path: ["excludeThreadIds"],
|
|
84
|
+
message: "excludeThreadIds can only be used with bulk scope",
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}),
|
|
31
88
|
run: async (args) => {
|
|
32
89
|
const ids = args.id
|
|
33
90
|
?.split(",")
|
|
34
91
|
.map((s) => s.trim())
|
|
35
92
|
.filter(Boolean);
|
|
36
|
-
|
|
93
|
+
const hasIds = Boolean(ids?.length);
|
|
94
|
+
const hasScope = args.scope === "all-unread";
|
|
95
|
+
if (hasIds === hasScope) {
|
|
96
|
+
throw new Error('Provide exactly one of "id" or "scope"');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (hasScope) {
|
|
100
|
+
if (!args.accountEmail?.trim()) {
|
|
101
|
+
throw new Error('accountEmail is required for scope "all-unread"');
|
|
102
|
+
}
|
|
103
|
+
if (args.accountEmails) {
|
|
104
|
+
throw new Error('accountEmails cannot be used with scope "all-unread"');
|
|
105
|
+
}
|
|
106
|
+
if (args.unread === true) {
|
|
107
|
+
throw new Error('scope "all-unread" can only mark messages read');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const ownerEmail = getRequestUserEmail();
|
|
111
|
+
if (!ownerEmail) throw new Error("no authenticated user");
|
|
112
|
+
const excludeThreadIds = (args.excludeThreadIds ?? "")
|
|
113
|
+
.split(",")
|
|
114
|
+
.map((value) => value.trim())
|
|
115
|
+
.filter(Boolean);
|
|
116
|
+
const input = {
|
|
117
|
+
ownerEmail,
|
|
118
|
+
accountEmail: args.accountEmail.trim(),
|
|
119
|
+
excludeThreadIds,
|
|
120
|
+
};
|
|
121
|
+
let result;
|
|
122
|
+
try {
|
|
123
|
+
result = (await isConnected(ownerEmail))
|
|
124
|
+
? await markAllUnreadReadForAccount(input)
|
|
125
|
+
: await markAllLocalUnreadRead(input);
|
|
126
|
+
} finally {
|
|
127
|
+
// A provider verification read can fail after Gmail accepted the
|
|
128
|
+
// mutation. Always make the UI discard its pre-mutation list cache.
|
|
129
|
+
await writeAppState("refresh-signal", { ts: Date.now() });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (!result.verificationComplete) {
|
|
133
|
+
const verificationDetail = result.verificationError
|
|
134
|
+
? `verification failed: ${result.verificationError}`
|
|
135
|
+
: `${result.unexpectedUnreadMessages} unexpected unread messages remain`;
|
|
136
|
+
const error = new Error(
|
|
137
|
+
`Bulk mark-read incomplete for ${result.accountEmail}: matched ${result.matchedMessages}, excluded ${result.excludedMessages}, changed ${result.changedMessages}; ${result.failures.length} failed and ${verificationDetail}`,
|
|
138
|
+
) as Error & { details?: typeof result };
|
|
139
|
+
error.details = result;
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (!ids || ids.length === 0) {
|
|
146
|
+
throw new Error('Provide exactly one of "id" or "scope"');
|
|
147
|
+
}
|
|
37
148
|
const isRead = args.unread !== true;
|
|
38
149
|
|
|
39
150
|
const ownerEmail = getRequestUserEmail();
|
|
@@ -7,7 +7,7 @@ import { markThreadRead } from "../server/lib/email-state.js";
|
|
|
7
7
|
|
|
8
8
|
export default defineAction({
|
|
9
9
|
description:
|
|
10
|
-
|
|
10
|
+
'Mark one conversation thread as read or unread. For broad unread cleanup across many threads, call mark-read once with scope "all-unread" instead of looping this action.',
|
|
11
11
|
schema: z.object({
|
|
12
12
|
threadId: z.string().describe("Thread ID to mark read/unread"),
|
|
13
13
|
unread: z.coerce
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { defineAction } from "@agent-native/core";
|
|
2
2
|
import { writeAppState } from "@agent-native/core/application-state";
|
|
3
3
|
import { getRequestUserEmail } from "@agent-native/core/server";
|
|
4
|
-
import { getUserSetting, putUserSetting } from "@agent-native/core/settings";
|
|
5
4
|
import { z } from "zod";
|
|
6
5
|
|
|
7
6
|
import {
|
|
@@ -10,6 +9,11 @@ import {
|
|
|
10
9
|
gmailModifyThread,
|
|
11
10
|
} from "../server/lib/google-api.js";
|
|
12
11
|
import { isConnected } from "../server/lib/google-auth.js";
|
|
12
|
+
import {
|
|
13
|
+
readLocalEmails,
|
|
14
|
+
withLocalEmailMutationLock,
|
|
15
|
+
writeLocalEmails,
|
|
16
|
+
} from "../server/lib/local-email-store.js";
|
|
13
17
|
import { getAccessTokens } from "./helpers.js";
|
|
14
18
|
|
|
15
19
|
type GmailLabel = { id?: string; name?: string };
|
|
@@ -80,31 +84,33 @@ export default defineAction({
|
|
|
80
84
|
if (!ownerEmail) throw new Error("no authenticated user");
|
|
81
85
|
|
|
82
86
|
if (!(await isConnected(ownerEmail))) {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
const changed = await withLocalEmailMutationLock(ownerEmail, async () => {
|
|
88
|
+
const emails = await readLocalEmails(ownerEmail);
|
|
89
|
+
const idSet = new Set(ids);
|
|
90
|
+
const targetThreads = new Set<string>();
|
|
91
|
+
for (const email of emails) {
|
|
92
|
+
if (idSet.has(email.id))
|
|
93
|
+
targetThreads.add(email.threadId || email.id);
|
|
94
|
+
}
|
|
91
95
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
96
|
+
let changed = 0;
|
|
97
|
+
const updated = emails.map((email) => {
|
|
98
|
+
if (!targetThreads.has(email.threadId || email.id)) return email;
|
|
99
|
+
changed++;
|
|
100
|
+
const labelIds = new Set<string>(email.labelIds ?? []);
|
|
101
|
+
labelIds.delete("inbox");
|
|
102
|
+
if (args.removeLabel) labelIds.delete(args.removeLabel);
|
|
103
|
+
labelIds.add(targetLabel);
|
|
104
|
+
return {
|
|
105
|
+
...email,
|
|
106
|
+
isArchived: true,
|
|
107
|
+
labelIds: [...labelIds],
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
await writeLocalEmails(ownerEmail, updated);
|
|
112
|
+
return changed;
|
|
105
113
|
});
|
|
106
|
-
|
|
107
|
-
await putUserSetting(ownerEmail, "local-emails", { emails: updated });
|
|
108
114
|
await writeAppState("refresh-signal", { ts: Date.now() });
|
|
109
115
|
return `Moved ${changed} local email(s) to ${targetLabel}`;
|
|
110
116
|
}
|
|
@@ -3,7 +3,7 @@ import { emit } from "@agent-native/core/event-bus";
|
|
|
3
3
|
import { setOAuthDisplayName } from "@agent-native/core/oauth-tokens";
|
|
4
4
|
import { getRequestUserEmail } from "@agent-native/core/server";
|
|
5
5
|
import { getAppProductionUrl } from "@agent-native/core/server";
|
|
6
|
-
import { getUserSetting
|
|
6
|
+
import { getUserSetting } from "@agent-native/core/settings";
|
|
7
7
|
import { nanoid } from "nanoid";
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
|
|
@@ -20,6 +20,11 @@ import {
|
|
|
20
20
|
invalidateListCacheForOwner,
|
|
21
21
|
setAccountDisplayName,
|
|
22
22
|
} from "../server/lib/google-auth.js";
|
|
23
|
+
import {
|
|
24
|
+
readLocalEmails,
|
|
25
|
+
withLocalEmailMutationLock,
|
|
26
|
+
writeLocalEmails,
|
|
27
|
+
} from "../server/lib/local-email-store.js";
|
|
23
28
|
import {
|
|
24
29
|
bodyToHtml,
|
|
25
30
|
buildRawEmail,
|
|
@@ -154,73 +159,73 @@ export default defineAction({
|
|
|
154
159
|
|
|
155
160
|
const accounts = await getAccessTokens();
|
|
156
161
|
if (accounts.length === 0) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
`thread-${nanoid(8)}
|
|
165
|
-
:
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
:
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
162
|
+
return withLocalEmailMutationLock(ownerEmail, async () => {
|
|
163
|
+
const emails = await readLocalEmails(ownerEmail);
|
|
164
|
+
const newEmail = {
|
|
165
|
+
id: `msg-${nanoid(8)}`,
|
|
166
|
+
threadId: args.replyToId
|
|
167
|
+
? (emails.find((e: any) => e.id === args.replyToId)?.threadId ??
|
|
168
|
+
`thread-${nanoid(8)}`)
|
|
169
|
+
: `thread-${nanoid(8)}`,
|
|
170
|
+
from: { name: settings.name, email: settings.email },
|
|
171
|
+
to: args.to.split(",").map((value) => {
|
|
172
|
+
const trimmed = value.trim();
|
|
173
|
+
return { name: trimmed, email: trimmed };
|
|
174
|
+
}),
|
|
175
|
+
...(args.cc
|
|
176
|
+
? {
|
|
177
|
+
cc: args.cc.split(",").map((value) => {
|
|
178
|
+
const trimmed = value.trim();
|
|
179
|
+
return { name: trimmed, email: trimmed };
|
|
180
|
+
}),
|
|
181
|
+
}
|
|
182
|
+
: {}),
|
|
183
|
+
...(args.bcc
|
|
184
|
+
? {
|
|
185
|
+
bcc: args.bcc.split(",").map((value) => {
|
|
186
|
+
const trimmed = value.trim();
|
|
187
|
+
return { name: trimmed, email: trimmed };
|
|
188
|
+
}),
|
|
189
|
+
}
|
|
190
|
+
: {}),
|
|
191
|
+
subject: args.subject,
|
|
192
|
+
snippet: markdownPreviewSnippet(args.body),
|
|
193
|
+
body: args.body,
|
|
194
|
+
bodyHtml: bodyToHtml(args.body),
|
|
195
|
+
date: new Date().toISOString(),
|
|
196
|
+
isRead: true,
|
|
197
|
+
isStarred: false,
|
|
198
|
+
isSent: true,
|
|
199
|
+
isArchived: false,
|
|
200
|
+
isTrashed: false,
|
|
201
|
+
labelIds: ["sent"],
|
|
202
|
+
...(resolvedAttachments.length > 0
|
|
203
|
+
? {
|
|
204
|
+
attachments: resolvedAttachments.map((att) => ({
|
|
205
|
+
id: att.filename,
|
|
206
|
+
filename: att.originalName,
|
|
207
|
+
mimeType: att.mimeType,
|
|
208
|
+
size: att.size,
|
|
209
|
+
url: att.url,
|
|
210
|
+
})),
|
|
211
|
+
}
|
|
212
|
+
: {}),
|
|
213
|
+
};
|
|
214
|
+
emails.push(newEmail);
|
|
215
|
+
await writeLocalEmails(ownerEmail, emails);
|
|
216
|
+
try {
|
|
217
|
+
emit(
|
|
218
|
+
"mail.message.sent",
|
|
219
|
+
{
|
|
220
|
+
messageId: newEmail.id,
|
|
221
|
+
to: args.to,
|
|
222
|
+
subject: args.subject,
|
|
223
|
+
},
|
|
224
|
+
{ owner: ownerEmail },
|
|
225
|
+
);
|
|
226
|
+
} catch {}
|
|
227
|
+
return JSON.stringify(newEmail, null, 2);
|
|
228
|
+
});
|
|
224
229
|
}
|
|
225
230
|
|
|
226
231
|
let selectedToken = accounts[0].accessToken;
|