@tano.page/workbench 0.14.0 → 0.16.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 (248) hide show
  1. package/package.json +50 -16
  2. package/src/App.vue +82 -752
  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/agent-identities.ts +1 -97
  17. package/src/assistant/agent-task-context.ts +1 -54
  18. package/src/assistant/attachments.ts +1 -1
  19. package/src/assistant/completion.ts +1 -61
  20. package/src/assistant/components/AssistantChangeList.vue +98 -21
  21. package/src/assistant/components/AssistantPanel.vue +425 -8
  22. package/src/assistant/components/PluginToolProposalCard.vue +235 -0
  23. package/src/assistant/connection-actions.ts +237 -0
  24. package/src/assistant/document-mentions.ts +1 -33
  25. package/src/assistant/engine.ts +1 -532
  26. package/src/assistant/execution.ts +6 -33
  27. package/src/assistant/files.ts +5 -13
  28. package/src/assistant/hash.ts +1 -4
  29. package/src/assistant/inbox.ts +1 -148
  30. package/src/assistant/language.ts +10 -37
  31. package/src/assistant/mention-autocomplete.ts +69 -0
  32. package/src/assistant/plugin-bridge-builder.ts +146 -0
  33. package/src/assistant/prompts.ts +1 -58
  34. package/src/assistant/proposal-actions.ts +336 -0
  35. package/src/assistant/results.ts +20 -86
  36. package/src/assistant/store.ts +167 -327
  37. package/src/assistant/structures.ts +1 -155
  38. package/src/assistant/tasks.ts +8 -96
  39. package/src/assistant/tool-rules.ts +1 -7
  40. package/src/assistant/workspace-bridge.ts +1 -1
  41. package/src/composables/use-document-actions.ts +38 -20
  42. package/src/composables/use-file-tree-controller.ts +7 -12
  43. package/src/composables/use-workbench-help.ts +177 -0
  44. package/src/composables/use-workbench-history.ts +2 -4
  45. package/src/composables/use-workbench-lifecycle.ts +249 -0
  46. package/src/composables/use-workbench-modals.ts +6 -1
  47. package/src/composables/use-workbench-outline.ts +0 -5
  48. package/src/composables/use-workbench-settings.ts +185 -0
  49. package/src/composables/use-workbench-shortcuts.ts +40 -1021
  50. package/src/composables/use-workbench-views.ts +325 -0
  51. package/src/data-tables/data-tables.ts +1 -2
  52. package/src/documents/components/DocumentActionMenu.vue +279 -0
  53. package/src/documents/components/DocumentHistoryPanel.vue +3 -1
  54. package/src/documents/components/DocumentInspector.vue +168 -0
  55. package/src/documents/components/DocumentPane.vue +482 -0
  56. package/src/documents/description-merge.ts +1 -9
  57. package/src/features.ts +1 -0
  58. package/src/files/components/FileMetadataPanel.vue +49 -15
  59. package/src/fonts/Inter-Latin-Italic.woff2 +0 -0
  60. package/src/fonts/Inter-Latin.woff2 +0 -0
  61. package/src/fonts/TanoUISansSC-Bold.woff2 +0 -0
  62. package/src/fonts/TanoUISansSC-Medium.woff2 +0 -0
  63. package/src/fonts/TanoUISansSC-Regular.woff2 +0 -0
  64. package/src/help/help-milestones.ts +3 -5
  65. package/src/i18n/locale-catalogs.ts +7 -6
  66. package/src/i18n/locale-registry.ts +8 -6
  67. package/src/i18n/locales/de-DE.json +371 -3
  68. package/src/i18n/locales/en-US.json +371 -2
  69. package/src/i18n/locales/es-ES.json +371 -3
  70. package/src/i18n/locales/ja-JP.json +370 -2
  71. package/src/i18n/locales/zh-TW.json +370 -2
  72. package/src/mail/components/MailAccountDialog.vue +450 -0
  73. package/src/mail/components/MailComposerDialog.vue +326 -0
  74. package/src/mail/components/MailProviderIcon.vue +30 -0
  75. package/src/mail/components/MailWorkspaceView.vue +821 -0
  76. package/src/mail/components/SidebarMail.vue +134 -0
  77. package/src/mail/mail-avatar.ts +17 -0
  78. package/src/mail/mail-bridge.ts +68 -0
  79. package/src/mail/mail-calendar.ts +208 -0
  80. package/src/mail/mail-markdown.ts +195 -0
  81. package/src/mail/types.ts +226 -0
  82. package/src/objects/components/ObjectDetailModal.vue +1001 -0
  83. package/src/objects/content-references.ts +6 -56
  84. package/src/objects/wiki-links.ts +1 -48
  85. package/src/objects/workspace-objects.ts +3 -4
  86. package/src/plan-sync/types.ts +6 -3
  87. package/src/plans/calendar-interaction.ts +194 -0
  88. package/src/plans/calendar.ts +65 -9
  89. package/src/plans/components/CalendarAgendaView.vue +165 -0
  90. package/src/plans/components/CalendarDayPopover.vue +172 -39
  91. package/src/plans/components/CalendarFilterBar.vue +128 -0
  92. package/src/plans/components/CalendarMonthView.vue +224 -0
  93. package/src/plans/components/CalendarQuickCreateDialog.vue +269 -0
  94. package/src/plans/components/CalendarTimelineView.vue +517 -0
  95. package/src/plans/components/CalendarTopbarControls.vue +101 -0
  96. package/src/plans/components/CalendarView.vue +264 -748
  97. package/src/plans/components/CalendarYearView.vue +138 -0
  98. package/src/plans/components/PlanArchiveDialog.vue +295 -0
  99. package/src/plans/components/PlanConnectionsDialog.vue +1 -1
  100. package/src/plans/components/PlanDateField.vue +6 -4
  101. package/src/plans/components/PlanDetailPanel.vue +227 -32
  102. package/src/plans/components/PlanEventList.vue +16 -4
  103. package/src/plans/components/SidebarPlan.vue +22 -15
  104. package/src/plans/components/TaskRepeatControls.vue +169 -30
  105. package/src/plans/components/calendar-shared.css +192 -0
  106. package/src/plans/composables/use-calendar-interactions.ts +396 -0
  107. package/src/plans/composables/use-calendar-scroll.ts +420 -0
  108. package/src/plans/local-reminders.ts +149 -0
  109. package/src/plans/personal-plans.ts +10 -1
  110. package/src/plans/plan-date.ts +8 -1
  111. package/src/plans/plan-migration.ts +95 -0
  112. package/src/plans/recurrence.ts +95 -0
  113. package/src/plans/task-repeat.ts +8 -8
  114. package/src/plans/timeline-layout.ts +92 -0
  115. package/src/plugins/assistant-bridge.ts +520 -0
  116. package/src/plugins/attachment-reader.ts +3 -1
  117. package/src/plugins/cache-storage.ts +42 -2
  118. package/src/plugins/components/PluginAutomations.vue +3 -3
  119. package/src/plugins/components/PluginCatalogBrowser.vue +17 -8
  120. package/src/plugins/components/PluginChangeSummary.vue +16 -3
  121. package/src/plugins/components/PluginConnections.vue +1 -1
  122. package/src/plugins/components/PluginCustomView.vue +2 -2
  123. package/src/plugins/components/PluginDetailPage.vue +136 -57
  124. package/src/plugins/components/PluginDeveloperArea.vue +192 -0
  125. package/src/plugins/components/PluginDocumentSlot.vue +63 -0
  126. package/src/plugins/components/PluginExplorer.vue +21 -25
  127. package/src/plugins/components/PluginImportDialog.vue +410 -0
  128. package/src/plugins/components/PluginInstaller.vue +273 -288
  129. package/src/plugins/components/PluginListItem.vue +3 -0
  130. package/src/plugins/components/PluginMaintenance.vue +37 -34
  131. package/src/plugins/components/PluginRepositoryStorage.vue +4 -2
  132. package/src/plugins/components/PluginRuntimePanel.vue +3 -3
  133. package/src/plugins/components/PluginSettingsForm.vue +112 -0
  134. package/src/plugins/components/PluginStatusBar.vue +161 -0
  135. package/src/plugins/components/PluginSurface.vue +18 -6
  136. package/src/plugins/components/PluginUiDialog.vue +452 -0
  137. package/src/plugins/components/PluginsTabPage.vue +61 -0
  138. package/src/plugins/components/plugin-center.css +5 -0
  139. package/src/plugins/data.ts +9 -86
  140. package/src/plugins/editor-plugin-adapters.ts +169 -0
  141. package/src/plugins/excalidraw/bundle.tano-plugin.json +1 -1
  142. package/src/plugins/excalidraw/manifest.json +12 -1
  143. package/src/plugins/host.ts +662 -43
  144. package/src/plugins/native.ts +2 -10
  145. package/src/plugins/overlay-mapping.ts +125 -0
  146. package/src/plugins/packages.ts +73 -1
  147. package/src/plugins/plugin-data.ts +2 -3
  148. package/src/plugins/plugin-permissions.ts +57 -0
  149. package/src/plugins/plugin-rpc-router.ts +558 -0
  150. package/src/plugins/plugin-sdk.ts +1 -94
  151. package/src/plugins/plugin-ui-dialogs.ts +167 -0
  152. package/src/plugins/policy.ts +53 -3
  153. package/src/plugins/presentation-preview/bundle.tano-plugin.json +1 -1
  154. package/src/plugins/presentation-preview/manifest.json +2 -1
  155. package/src/plugins/queries.ts +1 -73
  156. package/src/plugins/sandbox.ts +15 -1
  157. package/src/plugins/use-plugin-actions.ts +67 -20
  158. package/src/plugins/user-plugins.ts +254 -0
  159. package/src/plugins/view-header.ts +2 -7
  160. package/src/plugins/word-preview/bundle.tano-plugin.json +1 -1
  161. package/src/plugins/word-preview/manifest.json +13 -1
  162. package/src/plugins/workbench.ts +175 -2
  163. package/src/plugins/worker.js +105 -8
  164. package/src/plugins/workspace-plugin-runtime.ts +23 -7
  165. package/src/plugins/workspace-plugins.ts +212 -21
  166. package/src/runtime.ts +103 -4
  167. package/src/settings/components/SettingsAppearancePage.vue +46 -0
  168. package/src/settings/components/SettingsDocumentsPage.vue +0 -1
  169. package/src/settings/components/SettingsPanel.vue +8 -3
  170. package/src/settings/components/WorkbenchSettings.vue +20 -7
  171. package/src/settings/components/settings-context.ts +1 -1
  172. package/src/settings/components/settings-search.ts +2 -3
  173. package/src/settings/settings-tab.ts +1 -0
  174. package/src/shell/command-palette.ts +3 -3
  175. package/src/shell/components/EditorToolbar.vue +8 -9
  176. package/src/shell/components/EditorTools.vue +1 -5
  177. package/src/shell/components/PaneTopbar.vue +393 -0
  178. package/src/shell/components/SelectionToolbar.vue +0 -2
  179. package/src/shell/components/SidebarNavigation.vue +22 -2
  180. package/src/shell/components/WorkbenchContextMenus.vue +58 -34
  181. package/src/shell/components/WorkbenchModals.vue +47 -62
  182. package/src/shell/components/WorkbenchPanes.vue +371 -1342
  183. package/src/shell/components/WorkbenchSidebar.vue +486 -0
  184. package/src/shell/components/WorkspaceBreadcrumb.vue +6 -14
  185. package/src/shell/components/WorkspaceViewSwitcher.vue +12 -7
  186. package/src/shell/pane-registry.ts +69 -0
  187. package/src/shell/use-surface-dismissal.ts +219 -0
  188. package/src/shell/use-workbench-commands.ts +599 -0
  189. package/src/shell/use-workbench-keybindings.ts +337 -0
  190. package/src/shell/use-workbench.ts +531 -1153
  191. package/src/shell/workbench-async-components.ts +14 -5
  192. package/src/shell/workbench-context.ts +30 -3
  193. package/src/stores/mail.ts +414 -0
  194. package/src/stores/plan-sync.ts +2 -1
  195. package/src/stores/plans.ts +2 -9
  196. package/src/stores/workspace-document-io.ts +807 -0
  197. package/src/stores/workspace-file-ops.ts +1 -1
  198. package/src/stores/workspace-knowledge.ts +2 -114
  199. package/src/stores/workspace-lifecycle.ts +459 -0
  200. package/src/stores/workspace-plugins-state.ts +254 -259
  201. package/src/stores/workspace-session.ts +287 -0
  202. package/src/stores/workspace-tabs-layout.ts +6 -44
  203. package/src/stores/workspace-types.ts +50 -0
  204. package/src/stores/workspace.ts +184 -1363
  205. package/src/styles/agent-diff-modals.css +0 -7
  206. package/src/styles/dark-theme.css +3 -3
  207. package/src/styles/inspector.css +0 -59
  208. package/src/styles/layout-themes.css +346 -0
  209. package/src/styles/mail.css +1568 -0
  210. package/src/styles/mobile.css +2 -2
  211. package/src/styles/recent-and-media.css +0 -17
  212. package/src/styles/theme-contract.css +3 -3
  213. package/src/styles/workbench-shell.css +110 -17
  214. package/src/styles/workspace-states.css +9 -33
  215. package/src/styles.css +0 -1
  216. package/src/tabs/components/DesktopTabs.vue +19 -14
  217. package/src/tabs/components/NewTabPicker.vue +10 -4
  218. package/src/tabs/tab-label.ts +0 -1
  219. package/src/windows/AuxiliaryWindows.vue +2 -2
  220. package/src/windows/use-window-event-bridge.ts +152 -0
  221. package/src/workspace/components/TemplateLibrary.vue +1 -1
  222. package/src/workspace/components/WorkspaceGeneralSettings.vue +0 -13
  223. package/src/workspace/components/WorkspaceIconPicker.vue +30 -7
  224. package/src/workspace/components/WorkspacePickerMenu.vue +317 -0
  225. package/src/workspace/workspace-comments.ts +11 -151
  226. package/src/workspace/workspace-welcome.ts +1 -1
  227. package/src/assistant/locales/de-DE.json +0 -126
  228. package/src/assistant/locales/en-US.json +0 -126
  229. package/src/assistant/locales/es-ES.json +0 -126
  230. package/src/assistant/locales/ja-JP.json +0 -126
  231. package/src/assistant/locales/zh-CN.json +0 -126
  232. package/src/assistant/locales/zh-TW.json +0 -126
  233. package/src/assistant/task-prompts.json +0 -39
  234. package/src/documents/components/FormulaMenu.vue +0 -50
  235. package/src/files/components/FileDatabasePage.vue +0 -152
  236. package/src/files/components/FolderHomeIcon.vue +0 -12
  237. package/src/objects/components/ObjectDatabasePage.vue +0 -100
  238. package/src/objects/components/ObjectPanel.vue +0 -554
  239. package/src/plans/components/PersonalPlanDialog.vue +0 -105
  240. package/src/shell/components/WorkspaceViewPage.vue +0 -127
  241. package/src/shell/components/WorkspaceViewTab.vue +0 -24
  242. package/src/styles/object-panel.css +0 -163
  243. package/src/workspace/components/GitInspectionPanel.vue +0 -35
  244. package/src/workspace/components/WorkspaceSyncPanel.vue +0 -50
  245. package/src/workspace/welcome-slogans.ts +0 -11
  246. package/src/workspace/workspace-git.ts +0 -35
  247. package/src/workspace/workspace-sync.ts +0 -46
  248. package/src/workspace/workspace-views.ts +0 -48
@@ -0,0 +1,520 @@
1
+ import {
2
+ pluginRecord,
3
+ validateAgainstPluginJsonSchema,
4
+ type AssistantProposal,
5
+ type AssistantRequest,
6
+ type AssistantTransport,
7
+ type AssistantWireMessage,
8
+ type ExecutablePluginManifest,
9
+ type PluginAiCompleteRequest,
10
+ type PluginAiCompleteResult,
11
+ type PluginAiStructuredRequest,
12
+ type PluginAiStructuredResult,
13
+ type PluginAssistantContextProviderDefinition,
14
+ type PluginAssistantToolDefinition,
15
+ type PluginJson,
16
+ } from '@tano/protocol';
17
+ import {
18
+ PLUGIN_UNTRUSTED_END,
19
+ PLUGIN_UNTRUSTED_START,
20
+ sanitizePluginBoundaryText,
21
+ wrapUntrustedPluginData,
22
+ } from '@tano/protocol/untrusted-data';
23
+ import { AssistantStream } from '../assistant/engine';
24
+ import type { PluginRuntimeState } from './host';
25
+ import type { InstalledObjectPlugin } from './workspace-plugins';
26
+
27
+ export {
28
+ PLUGIN_UNTRUSTED_END,
29
+ PLUGIN_UNTRUSTED_START,
30
+ sanitizePluginBoundaryText,
31
+ wrapUntrustedPluginData,
32
+ };
33
+
34
+ export interface ActivePluginAssistantEntry {
35
+ installation: InstalledObjectPlugin;
36
+ manifest: ExecutablePluginManifest;
37
+ runtime: PluginRuntimeState;
38
+ }
39
+
40
+ export interface CompiledPluginTool {
41
+ wireName: string;
42
+ pluginId: string;
43
+ pluginName: string;
44
+ tool: PluginAssistantToolDefinition;
45
+ }
46
+
47
+ export interface ActivePluginContextProvider {
48
+ key: string;
49
+ pluginId: string;
50
+ pluginName: string;
51
+ provider: PluginAssistantContextProviderDefinition;
52
+ }
53
+
54
+ export interface PluginAssistantContextBlock {
55
+ key: string;
56
+ pluginId: string;
57
+ pluginName: string;
58
+ providerId: string;
59
+ title: string;
60
+ content: string;
61
+ metadata?: PluginJson;
62
+ }
63
+
64
+ export function activeAssistantPlugins(
65
+ installed: readonly InstalledObjectPlugin[],
66
+ runtimeStates: readonly PluginRuntimeState[],
67
+ ): ActivePluginAssistantEntry[] {
68
+ const byId = new Map(runtimeStates.map(state => [state.id, state]));
69
+ const result: ActivePluginAssistantEntry[] = [];
70
+ for (const installation of installed) {
71
+ if (!installation.enabled || !installation.authorized) continue;
72
+ if (installation.manifest.manifestVersion !== 2) continue;
73
+ if (installation.scope === 'user' && installation.personalCodePolicy === 'block') continue;
74
+ const runtime = byId.get(installation.manifest.id);
75
+ if (!runtime || (runtime.status !== 'running' && runtime.status !== 'idle')) continue;
76
+ result.push({ installation, manifest: installation.manifest, runtime });
77
+ }
78
+ return result;
79
+ }
80
+
81
+ /** Permission intersection: User/Workspace readOnly ∩ Team personalCodePolicy ∩ Plugin manifest. */
82
+ export function canPluginToolExecute(
83
+ installation: InstalledObjectPlugin,
84
+ tool: PluginAssistantToolDefinition,
85
+ workspaceReadOnly: boolean,
86
+ ): boolean {
87
+ if (!installation.enabled || !installation.authorized) return false;
88
+ if (installation.scope === 'user' && installation.personalCodePolicy === 'block') return false;
89
+ if (tool.effect === 'write') {
90
+ if (workspaceReadOnly) return false;
91
+ if (installation.scope === 'user' && installation.personalCodePolicy === 'read-only') return false;
92
+ }
93
+ return true;
94
+ }
95
+
96
+ function stableWireHash(input: string): string {
97
+ let hash = 2166136261;
98
+ for (let i = 0; i < input.length; i++) {
99
+ hash ^= input.charCodeAt(i);
100
+ hash = Math.imul(hash, 16777619);
101
+ }
102
+ return (hash >>> 0).toString(36).slice(0, 6);
103
+ }
104
+
105
+ export function pluginAssistantWireName(pluginId: string, toolName: string): string {
106
+ const safePlugin = pluginId.replace(/[^a-zA-Z0-9_-]/g, '_');
107
+ const safeTool = toolName.replace(/[^a-zA-Z0-9_-]/g, '_');
108
+ const candidate = `plugin__${safePlugin}__${safeTool}`;
109
+ if (candidate.length <= 64) return candidate;
110
+ const suffix = stableWireHash(`${pluginId}:${toolName}`);
111
+ return `${candidate.slice(0, 57)}_${suffix}`;
112
+ }
113
+
114
+ export function describeInstalledPluginsForAssistant(
115
+ installed: readonly InstalledObjectPlugin[],
116
+ runtimeStates: readonly PluginRuntimeState[],
117
+ workspaceReadOnly: boolean,
118
+ ) {
119
+ const runtimeById = new Map(runtimeStates.map(state => [state.id, state]));
120
+ return installed
121
+ .filter(item => item.enabled)
122
+ .map(item => {
123
+ const runtime = runtimeById.get(item.manifest.id);
124
+ const manifest = item.manifest;
125
+ const executable =
126
+ manifest.manifestVersion === 2 &&
127
+ item.authorized &&
128
+ !(item.scope === 'user' && item.personalCodePolicy === 'block') &&
129
+ !!runtime &&
130
+ (runtime.status === 'running' || runtime.status === 'idle');
131
+ return {
132
+ id: manifest.id,
133
+ name: manifest.name,
134
+ description: manifest.description,
135
+ scope: item.scope,
136
+ objectTypes: manifest.objectTypes.map(objType => ({ type: objType.type, label: objType.label })),
137
+ ...(executable && manifest.manifestVersion === 2
138
+ ? {
139
+ commands: manifest.commands.map(cmd => ({ id: cmd.id, label: cmd.label })),
140
+ views: manifest.views.map(view => ({
141
+ id: view.id,
142
+ label: view.label,
143
+ location: view.location ?? 'panel',
144
+ })),
145
+ assistantTools: (manifest.assistantTools ?? [])
146
+ .filter(tool => canPluginToolExecute(item, tool, workspaceReadOnly))
147
+ .map(tool => ({
148
+ name: tool.name,
149
+ wireName: pluginAssistantWireName(manifest.id, tool.name),
150
+ label: tool.label,
151
+ description: tool.description,
152
+ effect: tool.effect,
153
+ })),
154
+ assistantContextProviders: (manifest.assistantContextProviders ?? []).map(provider => ({
155
+ id: provider.id,
156
+ label: provider.label,
157
+ description: provider.description,
158
+ })),
159
+ }
160
+ : {}),
161
+ };
162
+ });
163
+ }
164
+
165
+ export function listActivePluginContextProviders(
166
+ installed: readonly InstalledObjectPlugin[],
167
+ runtimeStates: readonly PluginRuntimeState[],
168
+ ): ActivePluginContextProvider[] {
169
+ const active = activeAssistantPlugins(installed, runtimeStates);
170
+ const providers: ActivePluginContextProvider[] = [];
171
+ for (const { manifest } of active) {
172
+ for (const provider of manifest.assistantContextProviders ?? []) {
173
+ providers.push({
174
+ key: `${manifest.id}:${provider.id}`,
175
+ pluginId: manifest.id,
176
+ pluginName: manifest.name,
177
+ provider,
178
+ });
179
+ }
180
+ }
181
+ return providers;
182
+ }
183
+
184
+ export function extractPluginContextMentions(
185
+ prompt: string,
186
+ providers: readonly ActivePluginContextProvider[],
187
+ selectedKeys: readonly string[] = [],
188
+ limit = 4,
189
+ ): ActivePluginContextProvider[] {
190
+ const chosen: ActivePluginContextProvider[] = [];
191
+ const seen = new Set<string>();
192
+ const add = (entry: ActivePluginContextProvider | undefined) => {
193
+ if (!entry || seen.has(entry.key) || chosen.length >= limit) return;
194
+ seen.add(entry.key);
195
+ chosen.push(entry);
196
+ };
197
+ for (const key of selectedKeys) {
198
+ add(providers.find(item => item.key === key));
199
+ }
200
+ const byKey = new Map(providers.map(item => [item.key.toLowerCase(), item]));
201
+ const byShortId = new Map<string, ActivePluginContextProvider[]>();
202
+ for (const item of providers) {
203
+ const id = item.provider.id.toLowerCase();
204
+ const list = byShortId.get(id) ?? [];
205
+ list.push(item);
206
+ byShortId.set(id, list);
207
+ }
208
+ const mentionPattern = /(?:^|[\s,,。;;((])@([a-z][a-z0-9._-]{0,79}(?::[a-z][a-z0-9_-]{0,31})?)/gi;
209
+ let match: RegExpExecArray | null;
210
+ while ((match = mentionPattern.exec(prompt)) !== null) {
211
+ const token = match[1]!.toLowerCase();
212
+ if (token.includes(':')) {
213
+ add(byKey.get(token));
214
+ } else {
215
+ const candidates = byShortId.get(token);
216
+ if (candidates?.length === 1) add(candidates[0]);
217
+ }
218
+ }
219
+ return chosen;
220
+ }
221
+
222
+ const effectTag: Record<PluginAssistantToolDefinition['effect'], string> = {
223
+ read: '[插件工具 · 只读]',
224
+ write: '[插件工具 · 写入,须经用户确认]',
225
+ external: '[插件工具 · 外部调用,须经用户确认]',
226
+ };
227
+
228
+ export interface PluginAssistantCapabilitySummary {
229
+ tools: {
230
+ pluginId: string;
231
+ pluginName: string;
232
+ tool: PluginAssistantToolDefinition;
233
+ wireName: string;
234
+ available: boolean;
235
+ blockedReason?: 'workspace-read-only' | 'team-read-only' | 'team-blocked';
236
+ }[];
237
+ contexts: ActivePluginContextProvider[];
238
+ blockedPersonalPluginCount: number;
239
+ readOnlyPersonalPluginCount: number;
240
+ }
241
+
242
+ /** Summarize active & policy-restricted plugin assistant capabilities for UI visibility. */
243
+ export function summarizePluginAssistantCapabilities(
244
+ installed: readonly InstalledObjectPlugin[],
245
+ runtimeStates: readonly PluginRuntimeState[],
246
+ workspaceReadOnly: boolean,
247
+ ): PluginAssistantCapabilitySummary {
248
+ const runtimeById = new Map(runtimeStates.map(state => [state.id, state]));
249
+ const tools: PluginAssistantCapabilitySummary['tools'] = [];
250
+ let blockedPersonalPluginCount = 0;
251
+ let readOnlyPersonalPluginCount = 0;
252
+
253
+ for (const installation of installed) {
254
+ if (!installation.enabled || !installation.authorized) continue;
255
+ if (installation.manifest.manifestVersion !== 2) continue;
256
+ if (installation.scope === 'user' && installation.personalCodePolicy === 'block') {
257
+ blockedPersonalPluginCount++;
258
+ for (const tool of installation.manifest.assistantTools ?? []) {
259
+ tools.push({
260
+ pluginId: installation.manifest.id,
261
+ pluginName: installation.manifest.name,
262
+ tool,
263
+ wireName: pluginAssistantWireName(installation.manifest.id, tool.name),
264
+ available: false,
265
+ blockedReason: 'team-blocked',
266
+ });
267
+ }
268
+ continue;
269
+ }
270
+ const runtime = runtimeById.get(installation.manifest.id);
271
+ if (!runtime || (runtime.status !== 'running' && runtime.status !== 'idle')) continue;
272
+ if (installation.scope === 'user' && installation.personalCodePolicy === 'read-only') {
273
+ readOnlyPersonalPluginCount++;
274
+ }
275
+ for (const tool of installation.manifest.assistantTools ?? []) {
276
+ const available = canPluginToolExecute(installation, tool, workspaceReadOnly);
277
+ const blockedReason = available
278
+ ? undefined
279
+ : installation.scope === 'user' && installation.personalCodePolicy === 'read-only'
280
+ ? 'team-read-only'
281
+ : 'workspace-read-only';
282
+ tools.push({
283
+ pluginId: installation.manifest.id,
284
+ pluginName: installation.manifest.name,
285
+ tool,
286
+ wireName: pluginAssistantWireName(installation.manifest.id, tool.name),
287
+ available,
288
+ ...(blockedReason ? { blockedReason } : {}),
289
+ });
290
+ }
291
+ }
292
+
293
+ return {
294
+ tools,
295
+ contexts: listActivePluginContextProviders(installed, runtimeStates),
296
+ blockedPersonalPluginCount,
297
+ readOnlyPersonalPluginCount,
298
+ };
299
+ }
300
+
301
+ export function compilePluginAssistantTools(
302
+ installed: readonly InstalledObjectPlugin[],
303
+ runtimeStates: readonly PluginRuntimeState[],
304
+ workspaceReadOnly: boolean,
305
+ ): {
306
+ tools: NonNullable<AssistantRequest['tools']>;
307
+ pluginTools: Map<string, CompiledPluginTool>;
308
+ hasAnyPlugin: boolean;
309
+ } {
310
+ const enabledPlugins = installed.filter(item => item.enabled);
311
+ const active = activeAssistantPlugins(installed, runtimeStates);
312
+ const tools: NonNullable<AssistantRequest['tools']> = [];
313
+ const pluginTools = new Map<string, CompiledPluginTool>();
314
+
315
+ if (enabledPlugins.length > 0) {
316
+ tools.push({
317
+ type: 'function',
318
+ function: {
319
+ name: 'inspect_plugins',
320
+ description: '只读查看当前工作区及用户级已启用插件的对象类型、命令、视图与助手工具列表。',
321
+ parameters: { type: 'object', properties: {}, required: [], additionalProperties: false },
322
+ },
323
+ });
324
+ }
325
+ if (enabledPlugins.length > 0 || runtimeStates.length > 0) {
326
+ tools.push({
327
+ type: 'function',
328
+ function: {
329
+ name: 'inspect_plugin_logs',
330
+ description: '只读查看指定已安装插件的当前运行状态与近期控制台/异常日志,用于排查插件运行问题。请先用 inspect_plugins 获取准确的 pluginId。',
331
+ parameters: {
332
+ type: 'object',
333
+ properties: {
334
+ pluginId: { type: 'string', description: '已安装插件 ID' },
335
+ limit: { type: 'integer', minimum: 1, maximum: 50, description: '返回最近日志条数(1–50,默认 20)' },
336
+ },
337
+ required: ['pluginId'],
338
+ additionalProperties: false,
339
+ },
340
+ },
341
+ });
342
+ }
343
+ const hasViews = active.some(entry => entry.manifest.views.length > 0);
344
+ if (hasViews) {
345
+ tools.push({
346
+ type: 'function',
347
+ function: {
348
+ name: 'open_plugin_view',
349
+ description: '打开指定已授权插件声明的视图(只读导航,不写入工作区内容)。请先用 inspect_plugins 获取准确的 pluginId 和 viewId。',
350
+ parameters: {
351
+ type: 'object',
352
+ properties: {
353
+ pluginId: { type: 'string', description: '插件 ID' },
354
+ viewId: { type: 'string', description: '视图 ID' },
355
+ },
356
+ required: ['pluginId', 'viewId'],
357
+ additionalProperties: false,
358
+ },
359
+ },
360
+ });
361
+ }
362
+
363
+ for (const { installation, manifest } of active) {
364
+ for (const tool of manifest.assistantTools ?? []) {
365
+ if (!canPluginToolExecute(installation, tool, workspaceReadOnly)) continue;
366
+ const wireName = pluginAssistantWireName(manifest.id, tool.name);
367
+ if (pluginTools.has(wireName)) continue;
368
+ pluginTools.set(wireName, {
369
+ wireName,
370
+ pluginId: manifest.id,
371
+ pluginName: manifest.name,
372
+ tool,
373
+ });
374
+ const parameters = JSON.parse(JSON.stringify(tool.parameters)) as Record<string, unknown>;
375
+ if (tool.effect !== 'read') {
376
+ const props = (parameters.properties as Record<string, unknown> | undefined) ?? {};
377
+ parameters.properties = {
378
+ ...props,
379
+ _reason: {
380
+ type: 'string',
381
+ description: '简明说明执行此插件操作的原因,供用户审阅确认。',
382
+ },
383
+ };
384
+ }
385
+ tools.push({
386
+ type: 'function',
387
+ function: {
388
+ name: wireName,
389
+ description: `${effectTag[tool.effect]} ${manifest.name} · ${tool.label}:${tool.description}`,
390
+ parameters,
391
+ },
392
+ });
393
+ }
394
+ }
395
+
396
+ return { tools, pluginTools, hasAnyPlugin: enabledPlugins.length > 0 };
397
+ }
398
+
399
+ export function createPluginToolProposal(options: {
400
+ workspaceId: string;
401
+ runId: string;
402
+ compiled: CompiledPluginTool;
403
+ rawArgs: Record<string, unknown>;
404
+ }): AssistantProposal {
405
+ const { workspaceId, runId, compiled, rawArgs } = options;
406
+ if (compiled.tool.effect === 'read') {
407
+ throw new Error('只读插件工具不需要生成审阅提案');
408
+ }
409
+ const cleanArgs: Record<string, unknown> = { ...rawArgs };
410
+ const rawReason = cleanArgs._reason;
411
+ delete cleanArgs._reason;
412
+ validateAgainstPluginJsonSchema(cleanArgs, compiled.tool.parameters);
413
+ const reason =
414
+ typeof rawReason === 'string' && rawReason.trim()
415
+ ? rawReason.trim().slice(0, 1000)
416
+ : `调用插件「${compiled.pluginName}」执行「${compiled.tool.label}」`;
417
+ const formattedArgs = JSON.stringify(cleanArgs, null, 2);
418
+ const displayPath = `${compiled.pluginName} · ${compiled.tool.label}`.slice(0, 200);
419
+ return {
420
+ id: crypto.randomUUID(),
421
+ runId,
422
+ workspaceId,
423
+ kind: 'plugin',
424
+ path: displayPath,
425
+ base: '',
426
+ content: formattedArgs,
427
+ reason,
428
+ status: 'ready',
429
+ preview: {
430
+ before: '',
431
+ after: formattedArgs,
432
+ diskHash: null,
433
+ path: displayPath,
434
+ },
435
+ pluginAction: {
436
+ pluginId: compiled.pluginId,
437
+ pluginName: compiled.pluginName,
438
+ toolName: compiled.tool.name,
439
+ label: compiled.tool.label,
440
+ effect: compiled.tool.effect,
441
+ },
442
+ };
443
+ }
444
+
445
+ function extractJsonText(raw: string): string {
446
+ const trimmed = raw.trim();
447
+ const fenced = trimmed.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i);
448
+ if (fenced) return fenced[1]!.trim();
449
+ const firstBrace = trimmed.indexOf('{');
450
+ const lastBrace = trimmed.lastIndexOf('}');
451
+ if (firstBrace >= 0 && lastBrace > firstBrace) {
452
+ return trimmed.slice(firstBrace, lastBrace + 1);
453
+ }
454
+ return trimmed;
455
+ }
456
+
457
+ /** Host-managed inference for tano.ai.complete / tano.ai.structured. Credentials never enter the sandbox. */
458
+ export async function runPluginAiCompletion(options: {
459
+ transport: AssistantTransport;
460
+ connectionId: string;
461
+ model: string;
462
+ request: PluginAiCompleteRequest | PluginAiStructuredRequest;
463
+ structured: boolean;
464
+ signal: AbortSignal;
465
+ }): Promise<PluginAiCompleteResult | PluginAiStructuredResult> {
466
+ const { transport, connectionId, model, request, structured, signal } = options;
467
+ const messages: AssistantWireMessage[] = [];
468
+ const systemParts: string[] = [];
469
+ if (request.system) systemParts.push(request.system);
470
+ if (structured) {
471
+ const schema = (request as PluginAiStructuredRequest).schema;
472
+ systemParts.push(
473
+ `你必须只返回一个合法的 JSON 对象(不要输出额外解释或 Markdown 围栏),且严格满足以下 JSON Schema:\n${JSON.stringify(schema)}`,
474
+ );
475
+ }
476
+ if (systemParts.length) {
477
+ messages.push({ role: 'system', content: systemParts.join('\n\n') });
478
+ }
479
+ messages.push({ role: 'user', content: request.prompt });
480
+
481
+ const stream = new AssistantStream(() => {});
482
+ await transport.request(
483
+ connectionId,
484
+ { model, messages },
485
+ signal,
486
+ bytes => {
487
+ signal.throwIfAborted();
488
+ stream.push(bytes);
489
+ },
490
+ );
491
+ signal.throwIfAborted();
492
+ stream.finish();
493
+ const rawText = stream.content.trim();
494
+ if (!rawText) throw new Error('模型未返回推理结果');
495
+ const usage = stream.usage.input || stream.usage.output ? { ...stream.usage } : undefined;
496
+ if (!structured) {
497
+ return {
498
+ text: rawText,
499
+ model,
500
+ ...(usage ? { usage } : {}),
501
+ };
502
+ }
503
+ const schema = (request as PluginAiStructuredRequest).schema;
504
+ let parsed: unknown;
505
+ try {
506
+ parsed = JSON.parse(extractJsonText(rawText));
507
+ } catch {
508
+ throw new Error('模型未返回合法的结构化 JSON 输出');
509
+ }
510
+ if (!pluginRecord(parsed)) {
511
+ throw new Error('结构化输出顶层必须为 JSON 对象');
512
+ }
513
+ validateAgainstPluginJsonSchema(parsed, schema);
514
+ return {
515
+ data: parsed,
516
+ rawText,
517
+ model,
518
+ ...(usage ? { usage } : {}),
519
+ };
520
+ }
@@ -1,4 +1,4 @@
1
- import { isWorkspaceInternalPath, isMarkdown, type Workspace } from '@tano/protocol';
1
+ import { isWorkspaceInternalPath, isMarkdown, matchesPluginPathScopes, type Workspace } from '@tano/protocol';
2
2
  import type { AttachmentService } from '../files/attachments';
3
3
 
4
4
  /** One bounded snapshot per workbench. A continuation can never mix file versions or instances. */
@@ -8,6 +8,8 @@ export class PluginAttachmentReader {
8
8
  async read(workspace: Workspace, params: Record<string, unknown>, service: AttachmentService | undefined, assertCurrent: () => void) {
9
9
  const file = workspace.files.find(file => file.id === params.fileId && file.kind === 'file');
10
10
  if (!file || isMarkdown(file.path) || isWorkspaceInternalPath(file.path)) throw new Error('附件不存在或不可访问');
11
+ const pathScopes = Array.isArray(params.pathScopes) ? (params.pathScopes as string[]) : undefined;
12
+ if (!matchesPluginPathScopes(file.path, pathScopes)) throw new Error('附件路径不在插件授权目录范围内');
11
13
  const offset = params.offset ?? 0;
12
14
  if (!Number.isSafeInteger(offset) || Number(offset) < 0 || Number(offset) % 18000 !== 0) throw new Error('附件分块位置无效');
13
15
  const key = JSON.stringify([workspace.id, params.queryScope, file.id, file.path, file.modified, file.size, file.contentHash]);
@@ -4,6 +4,8 @@ export interface PluginCacheEntry { integrity: string; pluginId: string; version
4
4
  export type PluginStorage = Pick<Storage, 'getItem' | 'setItem'> & Partial<Pick<Storage, 'removeItem'>>;
5
5
  const indexKey = 'tano.plugin-cache-index.v1';
6
6
  const packageKey = (integrity: string) => `tano.plugin-package.v1.${integrity}`;
7
+ const assetsKey = (integrity: string) => `tano.plugin-assets.v1.${integrity}`;
8
+ const idbAssetsKey = (integrity: string) => `assets:${integrity}`;
7
9
  let database: Promise<IDBDatabase> | undefined;
8
10
  const storageOperations = new WeakMap<PluginStorage, Promise<unknown>>();
9
11
  function serialize<T>(storage: PluginStorage, run: () => Promise<T>): Promise<T> {
@@ -44,6 +46,36 @@ export class PluginCacheStorage {
44
46
  if (this.indexed) return (await requestValue<string | undefined>((await openDatabase()).transaction('packages').objectStore('packages').get(integrity))) ?? this.storage.getItem(packageKey(integrity));
45
47
  return this.storage.getItem(packageKey(integrity));
46
48
  }
49
+ async getAssets(integrity: string): Promise<string | null> {
50
+ if (this.indexed) {
51
+ return (
52
+ (await requestValue<string | undefined>((await openDatabase()).transaction('packages').objectStore('packages').get(idbAssetsKey(integrity)))) ??
53
+ this.storage.getItem(assetsKey(integrity))
54
+ );
55
+ }
56
+ return this.storage.getItem(assetsKey(integrity));
57
+ }
58
+ putAssets(integrity: string, content: string) {
59
+ return this.indexed ? this.writeAssets(integrity, content) : serialize(this.storage, () => this.writeAssets(integrity, content));
60
+ }
61
+ private async writeAssets(integrity: string, content: string) {
62
+ if (this.indexed) {
63
+ const db = await openDatabase();
64
+ await new Promise<void>((resolve, reject) => {
65
+ const transaction = db.transaction(['packages'], 'readwrite');
66
+ transaction.objectStore('packages').put(content, idbAssetsKey(integrity));
67
+ transaction.oncomplete = () => resolve();
68
+ transaction.onabort = () => reject(transaction.error ?? new Error('设备存储空间不足,插件二进制资产未写入'));
69
+ });
70
+ this.storage.removeItem?.(assetsKey(integrity));
71
+ return;
72
+ }
73
+ try {
74
+ this.storage.setItem(assetsKey(integrity), content);
75
+ } catch {
76
+ throw new Error('设备存储空间不足,插件二进制资产未写入');
77
+ }
78
+ }
47
79
  put(entry: PluginCacheEntry, content: string) {
48
80
  return this.indexed ? this.write(entry, content) : serialize(this.storage, () => this.write(entry, content));
49
81
  }
@@ -81,10 +113,18 @@ export class PluginCacheStorage {
81
113
  const db = await openDatabase();
82
114
  await new Promise<void>((resolve, reject) => {
83
115
  const transaction = db.transaction(['packages', 'metadata'], 'readwrite');
84
- transaction.objectStore('packages').delete(integrity); transaction.objectStore('metadata').delete(integrity);
116
+ transaction.objectStore('packages').delete(integrity);
117
+ transaction.objectStore('packages').delete(idbAssetsKey(integrity));
118
+ transaction.objectStore('metadata').delete(integrity);
85
119
  transaction.oncomplete = () => resolve(); transaction.onabort = () => reject(transaction.error);
86
120
  });
87
121
  } else this.storage.setItem(indexKey, JSON.stringify((await this.entries()).filter(row => row.integrity !== integrity)));
88
- if (this.storage.removeItem) this.storage.removeItem(packageKey(integrity)); else this.storage.setItem(packageKey(integrity), '');
122
+ if (this.storage.removeItem) {
123
+ this.storage.removeItem(packageKey(integrity));
124
+ this.storage.removeItem(assetsKey(integrity));
125
+ } else {
126
+ this.storage.setItem(packageKey(integrity), '');
127
+ this.storage.setItem(assetsKey(integrity), '');
128
+ }
89
129
  }
90
130
  }
@@ -1,10 +1,11 @@
1
1
  <script setup lang="ts">
2
2
  import { uiLocale, t } from '../../i18n/i18n';
3
3
  import { computed, onScopeDispose, ref, shallowRef, watch } from 'vue';
4
- import { canonicalPluginJson, parsePluginAutomationJob, type PluginAutomationJob, type PluginAutomationRun, type PluginPermission } from '@tano/protocol';
4
+ import { canonicalPluginJson, parsePluginAutomationJob, type PluginAutomationJob, type PluginAutomationRun } from '@tano/protocol';
5
5
  import { useWorkbenchRuntime } from '../../runtime';
6
6
  import { useWorkspaceStore } from '../../stores/workspace';
7
7
  import { AutomationSubmissions } from '../automation-submissions';
8
+ import { pluginPermissionLabels as permissions } from '../plugin-permissions';
8
9
  import { assistantHash } from '../../assistant/hash';
9
10
  import PluginAutomationWebhook from './PluginAutomationWebhook.vue';
10
11
 
@@ -15,11 +16,10 @@ const editor = ref(false), jobId = ref(''), version = ref<string>(), pluginId =
15
16
  const label = ref(''), enabled = ref(true), schedule = ref('manual'), interval = ref(1440), payload = ref('{}'), approved = ref(false);
16
17
  const deleting = ref(''), pending = ref<Record<string, boolean>>({}), reviewed = ref(false);
17
18
  let controller = new AbortController(), timer: ReturnType<typeof setTimeout> | undefined;
18
- const plugins = computed(() => store.installedPlugins.filter(item => item.manifest.manifestVersion === 2 && item.manifest.automations?.length && item.rule?.mode !== 'disabled' && item.rule?.integrity));
19
+ const plugins = computed(() => store.installedPlugins.filter(item => item.scope !== 'user' && !item.system && item.manifest.manifestVersion === 2 && item.manifest.automations?.length && item.rule?.mode !== 'disabled' && item.rule?.integrity));
19
20
  const installation = computed(() => plugins.value.find(item => item.manifest.id === pluginId.value));
20
21
  const manifest = computed(() => installation.value?.manifest.manifestVersion === 2 ? installation.value.manifest : undefined);
21
22
  const canSave = computed(() => !!(approved.value && manifest.value?.automations?.some(item => item.id === automationId.value) && label.value.trim() && installation.value?.rule?.integrity));
22
- const permissions: Partial<Record<PluginPermission, string>> = { get 'documents.read'() { return t('读取文档'); }, get 'documents.write'() { return t('创建与修改文档'); }, get 'objects.read'() { return t('读取对象'); }, get 'objects.write'() { return t('创建与修改对象'); }, get 'relations.read'() { return t('读取关系'); }, get 'relations.write'() { return t('修改关系'); }, get network() { return t('访问指定网络来源'); }, get connections() { return t('使用单独授权的服务凭据'); } };
23
23
  const statuses: Record<PluginAutomationRun['status'], string> = { get queued() { return t('等待执行'); }, get running() { return t('执行中'); }, get succeeded() { return t('已完成'); }, get failed() { return t('失败'); }, get cancelled() { return t('已停止'); }, get uncertain() { return t('结果不确定'); }, get expired() { return t('已过期'); } };
24
24
  const date = (value: string | null) => value ? new Date(value).toLocaleString(uiLocale.value) : '—';
25
25
  const format = (value: unknown) => JSON.stringify(value, null, 2);