@tano.page/workbench 0.14.0 → 0.15.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.
Files changed (177) hide show
  1. package/package.json +21 -8
  2. package/src/App.vue +76 -17
  3. package/src/appearance/appearance.ts +14 -4
  4. package/src/appearance/components/ThemePresetPreview.vue +52 -8
  5. package/src/appearance/interface-font.ts +99 -0
  6. package/src/appearance/theme.ts +26 -10
  7. package/src/appearance/use-interface-font.ts +30 -0
  8. package/src/assets/mail-provider-icons/NOTICE.txt +27 -0
  9. package/src/assets/mail-provider-icons/aliyun-mail.svg +3 -0
  10. package/src/assets/mail-provider-icons/gmail.svg +1 -0
  11. package/src/assets/mail-provider-icons/icloud.svg +12 -0
  12. package/src/assets/mail-provider-icons/netease-126.svg +5 -0
  13. package/src/assets/mail-provider-icons/netease-163.svg +5 -0
  14. package/src/assets/mail-provider-icons/qq.svg +9 -0
  15. package/src/assets/mail-provider-icons/tencent-exmail.svg +4 -0
  16. package/src/assistant/components/AssistantChangeList.vue +98 -21
  17. package/src/assistant/components/AssistantPanel.vue +424 -7
  18. package/src/assistant/components/PluginToolProposalCard.vue +235 -0
  19. package/src/assistant/engine.ts +56 -3
  20. package/src/assistant/files.ts +5 -13
  21. package/src/assistant/inbox.ts +1 -148
  22. package/src/assistant/locales/de-DE.json +4 -1
  23. package/src/assistant/locales/en-US.json +4 -1
  24. package/src/assistant/locales/es-ES.json +4 -1
  25. package/src/assistant/locales/ja-JP.json +4 -1
  26. package/src/assistant/locales/zh-CN.json +4 -1
  27. package/src/assistant/locales/zh-TW.json +4 -1
  28. package/src/assistant/mention-autocomplete.ts +69 -0
  29. package/src/assistant/prompts.ts +7 -0
  30. package/src/assistant/results.ts +20 -86
  31. package/src/assistant/store.ts +319 -12
  32. package/src/assistant/structures.ts +7 -5
  33. package/src/assistant/tasks.ts +3 -5
  34. package/src/assistant/workspace-bridge.ts +1 -1
  35. package/src/composables/use-document-actions.ts +38 -20
  36. package/src/composables/use-file-tree-controller.ts +7 -12
  37. package/src/composables/use-workbench-history.ts +2 -4
  38. package/src/composables/use-workbench-modals.ts +6 -1
  39. package/src/composables/use-workbench-outline.ts +0 -5
  40. package/src/composables/use-workbench-shortcuts.ts +26 -22
  41. package/src/data-tables/data-tables.ts +1 -2
  42. package/src/documents/components/DocumentHistoryPanel.vue +3 -1
  43. package/src/features.ts +1 -0
  44. package/src/fonts/Inter-Latin-Italic.woff2 +0 -0
  45. package/src/fonts/Inter-Latin.woff2 +0 -0
  46. package/src/fonts/TanoUISansSC-Bold.woff2 +0 -0
  47. package/src/fonts/TanoUISansSC-Medium.woff2 +0 -0
  48. package/src/fonts/TanoUISansSC-Regular.woff2 +0 -0
  49. package/src/help/help-milestones.ts +3 -5
  50. package/src/i18n/locales/de-DE.json +349 -3
  51. package/src/i18n/locales/en-US.json +349 -2
  52. package/src/i18n/locales/es-ES.json +349 -3
  53. package/src/i18n/locales/ja-JP.json +348 -2
  54. package/src/i18n/locales/zh-TW.json +348 -2
  55. package/src/mail/components/MailAccountDialog.vue +449 -0
  56. package/src/mail/components/MailComposerDialog.vue +325 -0
  57. package/src/mail/components/MailProviderIcon.vue +30 -0
  58. package/src/mail/components/MailWorkspaceView.vue +820 -0
  59. package/src/mail/components/SidebarMail.vue +133 -0
  60. package/src/mail/mail-avatar.ts +17 -0
  61. package/src/mail/mail-bridge.ts +68 -0
  62. package/src/mail/mail-calendar.ts +208 -0
  63. package/src/mail/mail-markdown.ts +195 -0
  64. package/src/mail/types.ts +226 -0
  65. package/src/objects/components/ObjectDetailModal.vue +1001 -0
  66. package/src/objects/workspace-objects.ts +1 -1
  67. package/src/plan-sync/types.ts +6 -3
  68. package/src/plans/calendar-interaction.ts +194 -0
  69. package/src/plans/calendar.ts +63 -7
  70. package/src/plans/components/CalendarDayPopover.vue +172 -39
  71. package/src/plans/components/CalendarView.vue +1736 -276
  72. package/src/plans/components/PlanArchiveDialog.vue +295 -0
  73. package/src/plans/components/PlanDateField.vue +6 -4
  74. package/src/plans/components/PlanDetailPanel.vue +227 -32
  75. package/src/plans/components/PlanEventList.vue +16 -4
  76. package/src/plans/components/SidebarPlan.vue +22 -15
  77. package/src/plans/components/TaskRepeatControls.vue +169 -30
  78. package/src/plans/local-reminders.ts +149 -0
  79. package/src/plans/personal-plans.ts +10 -1
  80. package/src/plans/plan-date.ts +8 -1
  81. package/src/plans/plan-migration.ts +95 -0
  82. package/src/plans/recurrence.ts +95 -0
  83. package/src/plans/task-repeat.ts +8 -8
  84. package/src/plans/timeline-layout.ts +92 -0
  85. package/src/plugins/assistant-bridge.ts +520 -0
  86. package/src/plugins/attachment-reader.ts +3 -1
  87. package/src/plugins/cache-storage.ts +42 -2
  88. package/src/plugins/components/PluginAutomations.vue +3 -3
  89. package/src/plugins/components/PluginCatalogBrowser.vue +17 -8
  90. package/src/plugins/components/PluginChangeSummary.vue +16 -3
  91. package/src/plugins/components/PluginConnections.vue +1 -1
  92. package/src/plugins/components/PluginCustomView.vue +2 -2
  93. package/src/plugins/components/PluginDetailPage.vue +129 -54
  94. package/src/plugins/components/PluginDocumentSlot.vue +63 -0
  95. package/src/plugins/components/PluginExplorer.vue +15 -21
  96. package/src/plugins/components/PluginImportDialog.vue +410 -0
  97. package/src/plugins/components/PluginInstaller.vue +39 -145
  98. package/src/plugins/components/PluginListItem.vue +3 -0
  99. package/src/plugins/components/PluginMaintenance.vue +21 -6
  100. package/src/plugins/components/PluginRuntimePanel.vue +3 -3
  101. package/src/plugins/components/PluginSettingsForm.vue +111 -0
  102. package/src/plugins/components/PluginStatusBar.vue +161 -0
  103. package/src/plugins/components/PluginSurface.vue +18 -6
  104. package/src/plugins/components/PluginUiDialog.vue +452 -0
  105. package/src/plugins/excalidraw/bundle.tano-plugin.json +1 -1
  106. package/src/plugins/excalidraw/manifest.json +12 -1
  107. package/src/plugins/host.ts +662 -43
  108. package/src/plugins/native.ts +2 -10
  109. package/src/plugins/overlay-mapping.ts +125 -0
  110. package/src/plugins/packages.ts +73 -1
  111. package/src/plugins/plugin-permissions.ts +57 -0
  112. package/src/plugins/plugin-sdk.ts +174 -8
  113. package/src/plugins/policy.ts +53 -3
  114. package/src/plugins/presentation-preview/bundle.tano-plugin.json +1 -1
  115. package/src/plugins/presentation-preview/manifest.json +2 -1
  116. package/src/plugins/queries.ts +3 -1
  117. package/src/plugins/sandbox.ts +15 -1
  118. package/src/plugins/use-plugin-actions.ts +67 -20
  119. package/src/plugins/user-plugins.ts +254 -0
  120. package/src/plugins/word-preview/bundle.tano-plugin.json +1 -1
  121. package/src/plugins/word-preview/manifest.json +13 -1
  122. package/src/plugins/workbench.ts +175 -2
  123. package/src/plugins/worker.js +105 -8
  124. package/src/plugins/workspace-plugin-runtime.ts +23 -7
  125. package/src/plugins/workspace-plugins.ts +212 -21
  126. package/src/runtime.ts +101 -3
  127. package/src/settings/components/SettingsAppearancePage.vue +46 -0
  128. package/src/settings/components/SettingsDocumentsPage.vue +0 -1
  129. package/src/settings/components/settings-search.ts +2 -3
  130. package/src/shell/components/SidebarNavigation.vue +22 -2
  131. package/src/shell/components/WorkbenchContextMenus.vue +21 -8
  132. package/src/shell/components/WorkbenchModals.vue +27 -46
  133. package/src/shell/components/WorkbenchPanes.vue +267 -84
  134. package/src/shell/components/WorkspaceBreadcrumb.vue +6 -14
  135. package/src/shell/components/WorkspaceViewSwitcher.vue +12 -7
  136. package/src/shell/use-workbench.ts +116 -145
  137. package/src/shell/workbench-async-components.ts +14 -5
  138. package/src/stores/mail.ts +414 -0
  139. package/src/stores/plan-sync.ts +2 -1
  140. package/src/stores/plans.ts +2 -9
  141. package/src/stores/workspace-knowledge.ts +1 -113
  142. package/src/stores/workspace-plugins-state.ts +537 -14
  143. package/src/stores/workspace-tabs-layout.ts +5 -43
  144. package/src/stores/workspace.ts +69 -66
  145. package/src/styles/agent-diff-modals.css +0 -7
  146. package/src/styles/dark-theme.css +3 -3
  147. package/src/styles/inspector.css +0 -59
  148. package/src/styles/layout-themes.css +346 -0
  149. package/src/styles/mail.css +1568 -0
  150. package/src/styles/mobile.css +2 -2
  151. package/src/styles/recent-and-media.css +0 -17
  152. package/src/styles/theme-contract.css +3 -3
  153. package/src/styles/workbench-shell.css +110 -17
  154. package/src/styles/workspace-states.css +9 -33
  155. package/src/styles.css +1 -1
  156. package/src/tabs/components/DesktopTabs.vue +0 -3
  157. package/src/tabs/components/NewTabPicker.vue +10 -4
  158. package/src/tabs/tab-label.ts +0 -1
  159. package/src/workspace/components/WorkspaceGeneralSettings.vue +0 -13
  160. package/src/workspace/components/WorkspaceIconPicker.vue +28 -6
  161. package/src/workspace/workspace-comments.ts +11 -151
  162. package/src/workspace/workspace-welcome.ts +1 -1
  163. package/src/documents/components/FormulaMenu.vue +0 -50
  164. package/src/files/components/FileDatabasePage.vue +0 -152
  165. package/src/files/components/FolderHomeIcon.vue +0 -12
  166. package/src/objects/components/ObjectDatabasePage.vue +0 -100
  167. package/src/objects/components/ObjectPanel.vue +0 -554
  168. package/src/plans/components/PersonalPlanDialog.vue +0 -105
  169. package/src/shell/components/WorkspaceViewPage.vue +0 -127
  170. package/src/shell/components/WorkspaceViewTab.vue +0 -24
  171. package/src/styles/object-panel.css +0 -163
  172. package/src/workspace/components/GitInspectionPanel.vue +0 -35
  173. package/src/workspace/components/WorkspaceSyncPanel.vue +0 -50
  174. package/src/workspace/welcome-slogans.ts +0 -11
  175. package/src/workspace/workspace-git.ts +0 -35
  176. package/src/workspace/workspace-sync.ts +0 -46
  177. package/src/workspace/workspace-views.ts +0 -48
@@ -0,0 +1,133 @@
1
+ <script setup lang="ts">
2
+ import { onMounted } from 'vue';
3
+ import {
4
+ Archive,
5
+ FileText,
6
+ Folder,
7
+ Inbox,
8
+ PenSquare,
9
+ Plus,
10
+ RefreshCw,
11
+ Send,
12
+ Settings2,
13
+ Star,
14
+ Trash2,
15
+ } from 'lucide-vue-next';
16
+ import { t } from '../../i18n/i18n';
17
+ import { useMailStore } from '../../stores/mail';
18
+
19
+ const emit = defineEmits<{ openMail: [] }>();
20
+ const mail = useMailStore();
21
+
22
+ onMounted(() => {
23
+ void mail.init();
24
+ });
25
+
26
+ function folderIcon(specialUse: string | null) {
27
+ switch (specialUse) {
28
+ case 'inbox':
29
+ return Inbox;
30
+ case 'sent':
31
+ return Send;
32
+ case 'drafts':
33
+ return FileText;
34
+ case 'trash':
35
+ return Trash2;
36
+ case 'archive':
37
+ return Archive;
38
+ case 'flagged':
39
+ return Star;
40
+ default:
41
+ return Folder;
42
+ }
43
+ }
44
+
45
+ async function pickFolder(folderId: string) {
46
+ emit('openMail');
47
+ await mail.selectFolder(folderId);
48
+ }
49
+
50
+ function compose() {
51
+ emit('openMail');
52
+ mail.openComposer();
53
+ }
54
+
55
+ function openAccounts() {
56
+ emit('openMail');
57
+ mail.accountDialogOpen = true;
58
+ }
59
+ </script>
60
+
61
+ <template>
62
+ <div class="sidebar-mail">
63
+ <!-- View-level actions live on the view's own header row (VSCode-style). -->
64
+ <div class="sidebar-mail-head">
65
+ <button
66
+ v-if="mail.accounts.length"
67
+ type="button"
68
+ class="sidebar-mail-row sidebar-mail-compose"
69
+ @click="compose"
70
+ >
71
+ <PenSquare :size="15" />
72
+ <span>{{ t('写邮件') }}</span>
73
+ </button>
74
+ <span v-else class="sidebar-mail-title">{{ t('邮箱') }}</span>
75
+ <button
76
+ type="button"
77
+ class="icon-button sidebar-mail-head-icon"
78
+ :aria-label="t('管理邮箱账号')"
79
+ :data-tooltip="t('管理邮箱账号')"
80
+ @click="openAccounts"
81
+ >
82
+ <Settings2 :size="15" />
83
+ </button>
84
+ </div>
85
+
86
+ <div v-if="!mail.accounts.length" class="sidebar-mail-empty">
87
+ <button type="button" class="sidebar-mail-row sidebar-mail-connect" @click="openAccounts">
88
+ <Plus :size="15" />
89
+ <span>{{ t('连接第一个邮箱') }}</span>
90
+ </button>
91
+ </div>
92
+
93
+ <div v-else class="sidebar-mail-tree">
94
+ <section v-for="account in mail.accounts" :key="account.id" class="sidebar-mail-account">
95
+ <header class="sidebar-mail-account-head" :title="account.email">
96
+ <span class="sidebar-mail-account-name">{{ account.label || account.email }}</span>
97
+ <button
98
+ type="button"
99
+ class="icon-button sidebar-mail-sync"
100
+ :class="{ busy: mail.syncingAccountId === account.id }"
101
+ :aria-label="t('同步此邮箱')"
102
+ :data-tooltip="t('同步此邮箱')"
103
+ :disabled="mail.syncingAccountId === account.id"
104
+ @click="mail.syncAccount(account.id)"
105
+ >
106
+ <RefreshCw :size="13" :class="{ spinning: mail.syncingAccountId === account.id }" />
107
+ </button>
108
+ </header>
109
+
110
+ <ul class="sidebar-mail-folder-list">
111
+ <li
112
+ v-for="folder in mail.foldersByAccount.get(account.id) ?? []"
113
+ :key="folder.id"
114
+ >
115
+ <button
116
+ type="button"
117
+ class="sidebar-mail-row sidebar-mail-folder"
118
+ :class="{ active: mail.selectedFolderId === folder.id, unread: folder.unreadCount > 0 }"
119
+ :aria-current="mail.selectedFolderId === folder.id ? 'page' : undefined"
120
+ @click="pickFolder(folder.id)"
121
+ >
122
+ <component :is="folderIcon(folder.specialUse)" :size="15" />
123
+ <span class="sidebar-mail-folder-name">{{ folder.displayName }}</span>
124
+ <span v-if="folder.unreadCount > 0" class="sidebar-mail-count">
125
+ {{ folder.unreadCount > 999 ? '999+' : folder.unreadCount }}
126
+ </span>
127
+ </button>
128
+ </li>
129
+ </ul>
130
+ </section>
131
+ </div>
132
+ </div>
133
+ </template>
@@ -0,0 +1,17 @@
1
+ // SPDX-License-Identifier: MIT
2
+ import type { MailAddress } from './types';
3
+
4
+ /** First visible character of a sender, upper-cased for Latin names. */
5
+ export function senderInitial(addr: MailAddress | undefined): string {
6
+ const source = (addr?.name || addr?.address || '?').trim().replace(/^["'<(]+/, '');
7
+ const first = Array.from(source)[0] ?? '?';
8
+ return first.toLocaleUpperCase();
9
+ }
10
+
11
+ /** Stable hue per address so the same sender keeps the same (muted) tint. */
12
+ export function avatarHue(addr: MailAddress | undefined): number {
13
+ const key = (addr?.address || addr?.name || '').toLowerCase();
14
+ let hash = 0;
15
+ for (let i = 0; i < key.length; i++) hash = (hash * 31 + key.charCodeAt(i)) | 0;
16
+ return Math.abs(hash) % 360;
17
+ }
@@ -0,0 +1,68 @@
1
+ // SPDX-License-Identifier: MIT
2
+ import { nativeInvoke as invoke } from '../platform/native-bridge';
3
+ import type {
4
+ MailAccount,
5
+ MailAccountInput,
6
+ MailCacheStats,
7
+ MailCredentials,
8
+ MailDownloadedAttachment,
9
+ MailDraft,
10
+ MailFilter,
11
+ MailFlagsPatch,
12
+ MailFolder,
13
+ MailMessageDetail,
14
+ MailMessageSummary,
15
+ MailPreset,
16
+ MailSendRequest,
17
+ MailSendResult,
18
+ MailSyncSummary,
19
+ MailTestResult,
20
+ } from './types';
21
+
22
+ export const mailBridge = {
23
+ presetsList: () => invoke<MailPreset[]>('mail_presets_list'),
24
+ accountsList: () => invoke<MailAccount[]>('mail_accounts_list'),
25
+ accountTest: (input: MailAccountInput, credentials: MailCredentials) =>
26
+ invoke<MailTestResult>('mail_account_test', { input, credentials }),
27
+ accountSave: (input: MailAccountInput, credentials?: MailCredentials) =>
28
+ invoke<MailAccount>('mail_account_save', { input, credentials: credentials ?? null }),
29
+ accountRemove: (accountId: string) => invoke<void>('mail_account_remove', { accountId }),
30
+ foldersList: (accountId?: string) =>
31
+ invoke<MailFolder[]>('mail_folders_list', { accountId: accountId ?? null }),
32
+ syncAccount: (accountId: string) => invoke<MailSyncSummary>('mail_sync_account', { accountId }),
33
+ syncFolder: (folderId: string) => invoke<MailSyncSummary>('mail_sync_folder', { folderId }),
34
+ messagesList: (folderId: string, options?: { limit?: number; offset?: number; filter?: MailFilter }) =>
35
+ invoke<MailMessageSummary[]>('mail_messages_list', {
36
+ folderId,
37
+ limit: options?.limit ?? 60,
38
+ offset: options?.offset ?? 0,
39
+ filter: options?.filter && options.filter !== 'all' ? options.filter : null,
40
+ }),
41
+ messagesSearch: (query: string, accountId?: string, limit = 60) =>
42
+ invoke<MailMessageSummary[]>('mail_messages_search', {
43
+ accountId: accountId ?? null,
44
+ query,
45
+ limit,
46
+ }),
47
+ messageGet: (messageId: string, forceRefresh = false) =>
48
+ invoke<MailMessageDetail>('mail_message_get', { messageId, forceRefresh }),
49
+ updateFlags: (messageId: string, patch: MailFlagsPatch) =>
50
+ invoke<MailMessageDetail>('mail_message_flags_update', { messageId, patch }),
51
+ moveMessage: (messageId: string, targetFolderId: string) =>
52
+ invoke<void>('mail_message_move', { messageId, targetFolderId }),
53
+ updateInvite: (inviteId: string, importedObjectId?: string | null, rsvpStatus?: string | null) =>
54
+ invoke<void>('mail_invite_update', {
55
+ inviteId,
56
+ importedObjectId: importedObjectId ?? null,
57
+ rsvpStatus: rsvpStatus ?? null,
58
+ }),
59
+ downloadAttachment: (attachmentId: string) =>
60
+ invoke<MailDownloadedAttachment>('mail_attachment_download', { attachmentId }),
61
+ sendMail: (request: MailSendRequest) => invoke<MailSendResult>('mail_send', { request }),
62
+ cacheStats: () => invoke<MailCacheStats>('mail_cache_stats'),
63
+ cacheClear: () => invoke<MailCacheStats>('mail_cache_clear'),
64
+ draftsList: (accountId?: string) =>
65
+ invoke<MailDraft[]>('mail_drafts_list', { accountId: accountId ?? null }),
66
+ draftSave: (draft: MailDraft) => invoke<MailDraft>('mail_draft_save', { draft }),
67
+ draftDelete: (draftId: string) => invoke<void>('mail_draft_delete', { draftId }),
68
+ };
@@ -0,0 +1,208 @@
1
+ // SPDX-License-Identifier: MIT
2
+ import type { WorkspaceObject } from '@tano/protocol';
3
+ import type { ObjectRecord } from '../objects/workspace-objects';
4
+ import { parseCalendar } from '../plan-sync/ical';
5
+ import { itemProperties } from '../plan-sync/types';
6
+ import { hasEventTime } from '../plans/calendar';
7
+ import {
8
+ formatMailAddressList,
9
+ type MailCalendarInvite,
10
+ type MailMessageDetail,
11
+ type RsvpResponseStatus,
12
+ } from './types';
13
+
14
+ export interface ParsedInvitePreview {
15
+ summary: string;
16
+ start?: string;
17
+ end?: string;
18
+ allDay?: boolean;
19
+ description: string;
20
+ organizerEmail: string | null;
21
+ conflicts: ObjectRecord[];
22
+ }
23
+
24
+ export function extractOrganizerEmail(rawIcs: string): string | null {
25
+ const unfolded = rawIcs.replace(/\r?\n[ \t]/g, '');
26
+ const match = unfolded.match(/^ORGANIZER[^:\r\n]*:(?:mailto:)?([^\r\n\s;]+)/im);
27
+ return match?.[1]?.trim() || null;
28
+ }
29
+
30
+ export function parseInvitePreview(
31
+ invite: MailCalendarInvite,
32
+ existingRecords: readonly ObjectRecord[],
33
+ ): ParsedInvitePreview {
34
+ const organizerEmail = extractOrganizerEmail(invite.rawIcs);
35
+ try {
36
+ const parsed = parseCalendar(invite.rawIcs, 'calendar');
37
+ const first = parsed.items[0]?.value;
38
+ if (first) {
39
+ const conflicts = findOverlappingEvents(existingRecords, first.start, first.end);
40
+ return {
41
+ summary: first.name || invite.summary,
42
+ start: first.start,
43
+ end: first.end,
44
+ allDay: first.allDay,
45
+ description: first.description,
46
+ organizerEmail,
47
+ conflicts,
48
+ };
49
+ }
50
+ } catch {
51
+ // Fall back to lightweight header metadata when the ICS lacks optional VTIMEZONE definitions.
52
+ }
53
+ return {
54
+ summary: invite.summary || '日历邀请',
55
+ description: '',
56
+ organizerEmail,
57
+ conflicts: [],
58
+ };
59
+ }
60
+
61
+ export function findOverlappingEvents(
62
+ records: readonly ObjectRecord[],
63
+ startIso?: string,
64
+ endIso?: string,
65
+ ): ObjectRecord[] {
66
+ if (!startIso || !endIso) return [];
67
+ const start = Date.parse(startIso);
68
+ const end = Date.parse(endIso);
69
+ if (!Number.isFinite(start) || !Number.isFinite(end) || end <= start) return [];
70
+ return records.filter((record) => {
71
+ if (record.object.archived || !hasEventTime(record)) return false;
72
+ const from = Date.parse(String(record.object.properties.start));
73
+ const to = Date.parse(String(record.object.properties.end));
74
+ return from < end && to > start;
75
+ });
76
+ }
77
+
78
+ export function buildEventDraftFromInvite(
79
+ invite: MailCalendarInvite,
80
+ detail: MailMessageDetail,
81
+ existingRecords: readonly ObjectRecord[],
82
+ ): Pick<WorkspaceObject, 'type' | 'name' | 'description' | 'archived' | 'properties'> {
83
+ const preview = parseInvitePreview(invite, existingRecords);
84
+ const sourceNote = [
85
+ `来源邮件:${detail.summary.subject}`,
86
+ `发件人:${formatMailAddressList(detail.summary.from)}`,
87
+ detail.summary.messageId ? `Message-ID: ${detail.summary.messageId}` : '',
88
+ ]
89
+ .filter(Boolean)
90
+ .join('\n');
91
+ const description = [preview.description.trim(), sourceNote].filter(Boolean).join('\n\n').slice(0, 18_000);
92
+ const properties = itemProperties(
93
+ {
94
+ name: preview.summary,
95
+ description,
96
+ start: preview.start,
97
+ end: preview.end,
98
+ allDay: preview.allDay,
99
+ archived: false,
100
+ },
101
+ 'calendar',
102
+ );
103
+ return {
104
+ type: 'event',
105
+ name: preview.summary.slice(0, 200),
106
+ description,
107
+ archived: false,
108
+ properties,
109
+ };
110
+ }
111
+
112
+ export function buildPlanDraftFromEmail(
113
+ detail: MailMessageDetail,
114
+ mode: 'calendar' | 'todo',
115
+ now = new Date(),
116
+ ): Pick<WorkspaceObject, 'type' | 'name' | 'description' | 'archived' | 'properties'> {
117
+ const name = (detail.summary.subject || '来自邮件的事项').slice(0, 200);
118
+ const excerpt = (detail.textBody || detail.summary.snippet || '').trim().slice(0, 3000);
119
+ const description = [
120
+ `发件人:${formatMailAddressList(detail.summary.from)}`,
121
+ detail.summary.messageId ? `Message-ID: ${detail.summary.messageId}` : '',
122
+ excerpt,
123
+ ]
124
+ .filter(Boolean)
125
+ .join('\n\n');
126
+
127
+ if (mode === 'todo') {
128
+ const today = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`;
129
+ return {
130
+ type: 'event',
131
+ name,
132
+ description,
133
+ archived: false,
134
+ properties: {
135
+ due: today,
136
+ checkable: true,
137
+ completed: false,
138
+ },
139
+ };
140
+ }
141
+
142
+ const start = new Date(now.getTime());
143
+ start.setMinutes(0, 0, 0);
144
+ start.setHours(start.getHours() + 1);
145
+ const end = new Date(start.getTime() + 60 * 60 * 1000);
146
+ return {
147
+ type: 'event',
148
+ name,
149
+ description,
150
+ archived: false,
151
+ properties: {
152
+ start: start.toISOString(),
153
+ end: end.toISOString(),
154
+ checkable: false,
155
+ completed: false,
156
+ },
157
+ };
158
+ }
159
+
160
+ /**
161
+ * Generates an RFC 5546 iTIP `METHOD:REPLY` VCALENDAR payload so the desktop client
162
+ * can send a real calendar RSVP through the user's own SMTP server.
163
+ */
164
+ export function buildRsvpReplyIcs(
165
+ rawIcs: string,
166
+ attendeeEmail: string,
167
+ attendeeName: string,
168
+ status: RsvpResponseStatus,
169
+ now = new Date(),
170
+ ): string {
171
+ const unfolded = rawIcs.replace(/\r?\n[ \t]/g, '');
172
+ const pick = (prop: string) => {
173
+ const m = unfolded.match(new RegExp(`^(${prop}(?:;[^:\\r\\n]*)?:[^\\r\\n]+)$`, 'im'));
174
+ return m?.[1]?.trim() ?? '';
175
+ };
176
+ const uidLine = pick('UID') || `UID:tano-${crypto.randomUUID()}`;
177
+ const dtstartLine = pick('DTSTART');
178
+ const dtendLine = pick('DTEND');
179
+ const summaryLine = pick('SUMMARY') || 'SUMMARY:Meeting';
180
+ const organizerLine = pick('ORGANIZER');
181
+ const sequenceLine = pick('SEQUENCE');
182
+ const stamp = now.toISOString().replace(/[-:]/g, '').replace(/\.\d{3}Z$/, 'Z');
183
+ const safeCn = attendeeName.replace(/["\r\n;,:]/g, ' ').trim();
184
+ const attendeeLine = safeCn
185
+ ? `ATTENDEE;CN="${safeCn}";PARTSTAT=${status}:mailto:${attendeeEmail}`
186
+ : `ATTENDEE;PARTSTAT=${status}:mailto:${attendeeEmail}`;
187
+
188
+ return [
189
+ 'BEGIN:VCALENDAR',
190
+ 'PRODID:-//Tano//Desktop Mail//EN',
191
+ 'VERSION:2.0',
192
+ 'METHOD:REPLY',
193
+ 'BEGIN:VEVENT',
194
+ uidLine,
195
+ `DTSTAMP:${stamp}`,
196
+ dtstartLine,
197
+ dtendLine,
198
+ summaryLine,
199
+ organizerLine,
200
+ sequenceLine,
201
+ attendeeLine,
202
+ 'END:VEVENT',
203
+ 'END:VCALENDAR',
204
+ '',
205
+ ]
206
+ .filter((line, index, all) => line.length > 0 || index === all.length - 1)
207
+ .join('\r\n');
208
+ }
@@ -0,0 +1,195 @@
1
+ // SPDX-License-Identifier: MIT
2
+ import { formatMailAddressList, type MailMessageDetail } from './types';
3
+
4
+ function escapeYaml(value: string): string {
5
+ return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\r?\n/g, ' ')}"`;
6
+ }
7
+
8
+ function escapeHtml(value: string): string {
9
+ return value
10
+ .replace(/&/g, '&amp;')
11
+ .replace(/</g, '&lt;')
12
+ .replace(/>/g, '&gt;')
13
+ .replace(/"/g, '&quot;');
14
+ }
15
+
16
+ export function safeMailDocumentPath(detail: MailMessageDetail, folderPrefix = ''): string {
17
+ const date = new Date((detail.summary.dateTs || Math.floor(Date.now() / 1000)) * 1000);
18
+ const day = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
19
+ const cleanedSubject = (detail.summary.subject || '无主题邮件')
20
+ .replace(/[<>:"/\\|?*\u0000-\u001f]/g, ' ')
21
+ .replace(/\s+/g, ' ')
22
+ .trim()
23
+ .slice(0, 64);
24
+ const filename = `${day} ${cleanedSubject || '邮件'}.md`;
25
+ const prefix = folderPrefix.replace(/^\/+|\/+$/g, '');
26
+ return prefix ? `${prefix}/${filename}` : filename;
27
+ }
28
+
29
+ export function emailToMarkdownDocument(
30
+ detail: MailMessageDetail,
31
+ importedAttachments: readonly { filename: string; relativePath: string }[] = [],
32
+ ): string {
33
+ const sentAt = detail.summary.dateTs
34
+ ? new Date(detail.summary.dateTs * 1000).toISOString()
35
+ : new Date().toISOString();
36
+ const from = formatMailAddressList(detail.summary.from);
37
+ const to = formatMailAddressList(detail.summary.to);
38
+ const cc = formatMailAddressList(detail.cc);
39
+
40
+ const frontmatter = [
41
+ '---',
42
+ `title: ${escapeYaml(detail.summary.subject || '无主题邮件')}`,
43
+ 'source: mail',
44
+ `date: ${escapeYaml(sentAt)}`,
45
+ `mail_from: ${escapeYaml(from)}`,
46
+ `mail_to: ${escapeYaml(to)}`,
47
+ ...(cc ? [`mail_cc: ${escapeYaml(cc)}`] : []),
48
+ ...(detail.summary.messageId ? [`mail_message_id: ${escapeYaml(detail.summary.messageId)}`] : []),
49
+ '---',
50
+ ].join('\n');
51
+
52
+ const body = (detail.textBody || stripHtmlToPlain(detail.htmlSanitized) || detail.summary.snippet).trim();
53
+ const headerLines = [
54
+ `# ${detail.summary.subject || '无主题邮件'}`,
55
+ '',
56
+ `- **发件人**:${from || '未知'}`,
57
+ `- **收件人**:${to || '未知'}`,
58
+ ...(cc ? [`- **抄送**:${cc}`] : []),
59
+ `- **时间**:${new Date(sentAt).toLocaleString('zh-CN')}`,
60
+ ];
61
+
62
+ const attachmentSection = importedAttachments.length
63
+ ? [
64
+ '',
65
+ '## 附件',
66
+ '',
67
+ ...importedAttachments.map((item) => `- [${item.filename}](${encodeURI(item.relativePath)})`),
68
+ ]
69
+ : [];
70
+
71
+ return `${frontmatter}\n\n${headerLines.join('\n')}\n\n---\n\n${body}\n${attachmentSection.join('\n')}\n`;
72
+ }
73
+
74
+ /**
75
+ * Converts lightweight Markdown from the mail composer into clean, email-client-safe HTML.
76
+ */
77
+ export function markdownToEmailHtml(markdown: string): string {
78
+ const lines = markdown.replace(/\r\n/g, '\n').split('\n');
79
+ const blocks: string[] = [];
80
+ let inList = false;
81
+
82
+ const closeList = () => {
83
+ if (inList) {
84
+ blocks.push('</ul>');
85
+ inList = false;
86
+ }
87
+ };
88
+
89
+ for (const rawLine of lines) {
90
+ const line = rawLine.trimEnd();
91
+ if (!line.trim()) {
92
+ closeList();
93
+ continue;
94
+ }
95
+ const heading = line.match(/^(#{1,3})\s+(.+)$/);
96
+ if (heading) {
97
+ closeList();
98
+ const level = heading[1]!.length;
99
+ blocks.push(`<h${level} style="margin:14px 0 8px;line-height:1.4;">${renderInline(heading[2]!)}</h${level}>`);
100
+ continue;
101
+ }
102
+ const bullet = line.match(/^[-*]\s+(.+)$/);
103
+ if (bullet) {
104
+ if (!inList) {
105
+ blocks.push('<ul style="margin:8px 0;padding-left:20px;">');
106
+ inList = true;
107
+ }
108
+ blocks.push(`<li style="margin:4px 0;">${renderInline(bullet[1]!)}</li>`);
109
+ continue;
110
+ }
111
+ const quote = line.match(/^>\s?(.*)$/);
112
+ if (quote) {
113
+ closeList();
114
+ blocks.push(
115
+ `<blockquote style="margin:8px 0;padding:4px 12px;border-left:3px solid #d0d5dd;color:#475467;">${renderInline(quote[1]!)}</blockquote>`,
116
+ );
117
+ continue;
118
+ }
119
+ closeList();
120
+ blocks.push(`<p style="margin:8px 0;line-height:1.65;">${renderInline(line)}</p>`);
121
+ }
122
+ closeList();
123
+
124
+ return `<!doctype html><html><body style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI','PingFang SC',sans-serif;font-size:14px;color:#1f2328;line-height:1.65;">${blocks.join('')}</body></html>`;
125
+ }
126
+
127
+ function renderInline(text: string): string {
128
+ let out = escapeHtml(text);
129
+ out = out.replace(/`([^`]+)`/g, '<code style="background:#f3f4f6;padding:1px 4px;border-radius:4px;">$1</code>');
130
+ out = out.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
131
+ out = out.replace(/\*([^*]+)\*/g, '<em>$1</em>');
132
+ out = out.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>');
133
+ return out;
134
+ }
135
+
136
+ /**
137
+ * Builds the sandboxed `<iframe srcdoc>` content for rendering sanitized HTML emails.
138
+ * Remote images remain blocked unless `allowRemoteImages` is explicitly toggled on for the message.
139
+ */
140
+ export function buildSandboxedEmailSrcdoc(sanitizedHtml: string, allowRemoteImages: boolean): string {
141
+ const rendered = allowRemoteImages
142
+ ? sanitizedHtml.replace(/\bdata-tano-remote-src="(https?:\/\/[^"]+)"/gi, 'src="$1"')
143
+ : sanitizedHtml;
144
+ const csp = allowRemoteImages
145
+ ? "default-src 'none'; img-src data: https: http:; style-src 'unsafe-inline';"
146
+ : "default-src 'none'; img-src data:; style-src 'unsafe-inline';";
147
+ return `<!doctype html>
148
+ <html>
149
+ <head>
150
+ <meta charset="utf-8" />
151
+ <meta http-equiv="Content-Security-Policy" content="${csp}" />
152
+ <base target="_blank" />
153
+ <style>
154
+ html, body {
155
+ margin: 0;
156
+ padding: 16px;
157
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
158
+ font-size: 14px;
159
+ line-height: 1.65;
160
+ color: #1f2328;
161
+ background: #ffffff;
162
+ word-break: break-word;
163
+ overflow-wrap: anywhere;
164
+ }
165
+ img { max-width: 100%; height: auto; }
166
+ table { max-width: 100%; border-collapse: collapse; }
167
+ blockquote {
168
+ margin: 8px 0;
169
+ padding: 4px 12px;
170
+ border-left: 3px solid #d0d5dd;
171
+ color: #57606a;
172
+ }
173
+ a { color: #3b5bdb; }
174
+ pre, code {
175
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
176
+ white-space: pre-wrap;
177
+ }
178
+ </style>
179
+ </head>
180
+ <body>${rendered}</body>
181
+ </html>`;
182
+ }
183
+
184
+ function stripHtmlToPlain(html: string): string {
185
+ return html
186
+ .replace(/<br\s*\/?>/gi, '\n')
187
+ .replace(/<\/(p|div|li|tr|h[1-6])>/gi, '\n')
188
+ .replace(/<[^>]+>/g, '')
189
+ .replace(/&nbsp;/g, ' ')
190
+ .replace(/&amp;/g, '&')
191
+ .replace(/&lt;/g, '<')
192
+ .replace(/&gt;/g, '>')
193
+ .replace(/\n{3,}/g, '\n\n')
194
+ .trim();
195
+ }