modularob-connectors 0.0.0-stage → 0.6.7

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 (188) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +217 -2
  3. package/README.zh.md +218 -0
  4. package/client.js +1577 -0
  5. package/cordis.patch.yml +3 -0
  6. package/docs/PUBLISHING.md +53 -0
  7. package/icon.svg +8 -0
  8. package/index.js +135 -0
  9. package/lib/api.js +194 -0
  10. package/lib/cli.js +144 -0
  11. package/lib/obsidian.js +735 -0
  12. package/lib/profile-model.js +305 -0
  13. package/lib/profile.js +131 -0
  14. package/lib/skills.js +273 -0
  15. package/lib/tool.js +122 -0
  16. package/lib/update.js +268 -0
  17. package/lib/vendor/yaml/LICENSE +13 -0
  18. package/lib/vendor/yaml/dist/cli.d.ts +8 -0
  19. package/lib/vendor/yaml/dist/cli.mjs +201 -0
  20. package/lib/vendor/yaml/dist/compose/compose-collection.d.ts +11 -0
  21. package/lib/vendor/yaml/dist/compose/compose-collection.js +90 -0
  22. package/lib/vendor/yaml/dist/compose/compose-doc.d.ts +7 -0
  23. package/lib/vendor/yaml/dist/compose/compose-doc.js +45 -0
  24. package/lib/vendor/yaml/dist/compose/compose-node.d.ts +29 -0
  25. package/lib/vendor/yaml/dist/compose/compose-node.js +112 -0
  26. package/lib/vendor/yaml/dist/compose/compose-scalar.d.ts +5 -0
  27. package/lib/vendor/yaml/dist/compose/compose-scalar.js +88 -0
  28. package/lib/vendor/yaml/dist/compose/composer.d.ts +63 -0
  29. package/lib/vendor/yaml/dist/compose/composer.js +224 -0
  30. package/lib/vendor/yaml/dist/compose/resolve-block-map.d.ts +6 -0
  31. package/lib/vendor/yaml/dist/compose/resolve-block-map.js +117 -0
  32. package/lib/vendor/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
  33. package/lib/vendor/yaml/dist/compose/resolve-block-scalar.js +200 -0
  34. package/lib/vendor/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
  35. package/lib/vendor/yaml/dist/compose/resolve-block-seq.js +51 -0
  36. package/lib/vendor/yaml/dist/compose/resolve-end.d.ts +6 -0
  37. package/lib/vendor/yaml/dist/compose/resolve-end.js +39 -0
  38. package/lib/vendor/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
  39. package/lib/vendor/yaml/dist/compose/resolve-flow-collection.js +209 -0
  40. package/lib/vendor/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
  41. package/lib/vendor/yaml/dist/compose/resolve-flow-scalar.js +228 -0
  42. package/lib/vendor/yaml/dist/compose/resolve-props.d.ts +23 -0
  43. package/lib/vendor/yaml/dist/compose/resolve-props.js +148 -0
  44. package/lib/vendor/yaml/dist/compose/util-contains-newline.d.ts +2 -0
  45. package/lib/vendor/yaml/dist/compose/util-contains-newline.js +36 -0
  46. package/lib/vendor/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
  47. package/lib/vendor/yaml/dist/compose/util-empty-scalar-position.js +28 -0
  48. package/lib/vendor/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
  49. package/lib/vendor/yaml/dist/compose/util-flow-indent-check.js +17 -0
  50. package/lib/vendor/yaml/dist/compose/util-map-includes.d.ts +4 -0
  51. package/lib/vendor/yaml/dist/compose/util-map-includes.js +15 -0
  52. package/lib/vendor/yaml/dist/doc/Document.d.ts +141 -0
  53. package/lib/vendor/yaml/dist/doc/Document.js +337 -0
  54. package/lib/vendor/yaml/dist/doc/anchors.d.ts +24 -0
  55. package/lib/vendor/yaml/dist/doc/anchors.js +76 -0
  56. package/lib/vendor/yaml/dist/doc/applyReviver.d.ts +9 -0
  57. package/lib/vendor/yaml/dist/doc/applyReviver.js +57 -0
  58. package/lib/vendor/yaml/dist/doc/createNode.d.ts +17 -0
  59. package/lib/vendor/yaml/dist/doc/createNode.js +90 -0
  60. package/lib/vendor/yaml/dist/doc/directives.d.ts +49 -0
  61. package/lib/vendor/yaml/dist/doc/directives.js +178 -0
  62. package/lib/vendor/yaml/dist/errors.d.ts +21 -0
  63. package/lib/vendor/yaml/dist/errors.js +62 -0
  64. package/lib/vendor/yaml/dist/index.d.ts +25 -0
  65. package/lib/vendor/yaml/dist/index.js +50 -0
  66. package/lib/vendor/yaml/dist/log.d.ts +3 -0
  67. package/lib/vendor/yaml/dist/log.js +19 -0
  68. package/lib/vendor/yaml/dist/nodes/Alias.d.ts +29 -0
  69. package/lib/vendor/yaml/dist/nodes/Alias.js +120 -0
  70. package/lib/vendor/yaml/dist/nodes/Collection.d.ts +73 -0
  71. package/lib/vendor/yaml/dist/nodes/Collection.js +151 -0
  72. package/lib/vendor/yaml/dist/nodes/Node.d.ts +53 -0
  73. package/lib/vendor/yaml/dist/nodes/Node.js +40 -0
  74. package/lib/vendor/yaml/dist/nodes/Pair.d.ts +22 -0
  75. package/lib/vendor/yaml/dist/nodes/Pair.js +39 -0
  76. package/lib/vendor/yaml/dist/nodes/Scalar.d.ts +47 -0
  77. package/lib/vendor/yaml/dist/nodes/Scalar.js +27 -0
  78. package/lib/vendor/yaml/dist/nodes/YAMLMap.d.ts +53 -0
  79. package/lib/vendor/yaml/dist/nodes/YAMLMap.js +147 -0
  80. package/lib/vendor/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
  81. package/lib/vendor/yaml/dist/nodes/YAMLSeq.js +115 -0
  82. package/lib/vendor/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
  83. package/lib/vendor/yaml/dist/nodes/addPairToJSMap.js +65 -0
  84. package/lib/vendor/yaml/dist/nodes/identity.d.ts +23 -0
  85. package/lib/vendor/yaml/dist/nodes/identity.js +53 -0
  86. package/lib/vendor/yaml/dist/nodes/toJS.d.ts +29 -0
  87. package/lib/vendor/yaml/dist/nodes/toJS.js +39 -0
  88. package/lib/vendor/yaml/dist/options.d.ts +350 -0
  89. package/lib/vendor/yaml/dist/parse/cst-scalar.d.ts +64 -0
  90. package/lib/vendor/yaml/dist/parse/cst-scalar.js +218 -0
  91. package/lib/vendor/yaml/dist/parse/cst-stringify.d.ts +8 -0
  92. package/lib/vendor/yaml/dist/parse/cst-stringify.js +63 -0
  93. package/lib/vendor/yaml/dist/parse/cst-visit.d.ts +39 -0
  94. package/lib/vendor/yaml/dist/parse/cst-visit.js +99 -0
  95. package/lib/vendor/yaml/dist/parse/cst.d.ts +109 -0
  96. package/lib/vendor/yaml/dist/parse/cst.js +112 -0
  97. package/lib/vendor/yaml/dist/parse/lexer.d.ts +87 -0
  98. package/lib/vendor/yaml/dist/parse/lexer.js +723 -0
  99. package/lib/vendor/yaml/dist/parse/line-counter.d.ts +22 -0
  100. package/lib/vendor/yaml/dist/parse/line-counter.js +41 -0
  101. package/lib/vendor/yaml/dist/parse/parser.d.ts +84 -0
  102. package/lib/vendor/yaml/dist/parse/parser.js +980 -0
  103. package/lib/vendor/yaml/dist/public-api.d.ts +44 -0
  104. package/lib/vendor/yaml/dist/public-api.js +107 -0
  105. package/lib/vendor/yaml/dist/schema/Schema.d.ts +17 -0
  106. package/lib/vendor/yaml/dist/schema/Schema.js +39 -0
  107. package/lib/vendor/yaml/dist/schema/common/map.d.ts +2 -0
  108. package/lib/vendor/yaml/dist/schema/common/map.js +19 -0
  109. package/lib/vendor/yaml/dist/schema/common/null.d.ts +4 -0
  110. package/lib/vendor/yaml/dist/schema/common/null.js +17 -0
  111. package/lib/vendor/yaml/dist/schema/common/seq.d.ts +2 -0
  112. package/lib/vendor/yaml/dist/schema/common/seq.js +19 -0
  113. package/lib/vendor/yaml/dist/schema/common/string.d.ts +2 -0
  114. package/lib/vendor/yaml/dist/schema/common/string.js +16 -0
  115. package/lib/vendor/yaml/dist/schema/core/bool.d.ts +4 -0
  116. package/lib/vendor/yaml/dist/schema/core/bool.js +21 -0
  117. package/lib/vendor/yaml/dist/schema/core/float.d.ts +4 -0
  118. package/lib/vendor/yaml/dist/schema/core/float.js +47 -0
  119. package/lib/vendor/yaml/dist/schema/core/int.d.ts +4 -0
  120. package/lib/vendor/yaml/dist/schema/core/int.js +42 -0
  121. package/lib/vendor/yaml/dist/schema/core/schema.d.ts +1 -0
  122. package/lib/vendor/yaml/dist/schema/core/schema.js +25 -0
  123. package/lib/vendor/yaml/dist/schema/json/schema.d.ts +2 -0
  124. package/lib/vendor/yaml/dist/schema/json/schema.js +64 -0
  125. package/lib/vendor/yaml/dist/schema/json-schema.d.ts +69 -0
  126. package/lib/vendor/yaml/dist/schema/tags.d.ts +48 -0
  127. package/lib/vendor/yaml/dist/schema/tags.js +99 -0
  128. package/lib/vendor/yaml/dist/schema/types.d.ts +92 -0
  129. package/lib/vendor/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
  130. package/lib/vendor/yaml/dist/schema/yaml-1.1/binary.js +70 -0
  131. package/lib/vendor/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
  132. package/lib/vendor/yaml/dist/schema/yaml-1.1/bool.js +29 -0
  133. package/lib/vendor/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
  134. package/lib/vendor/yaml/dist/schema/yaml-1.1/float.js +50 -0
  135. package/lib/vendor/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
  136. package/lib/vendor/yaml/dist/schema/yaml-1.1/int.js +76 -0
  137. package/lib/vendor/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
  138. package/lib/vendor/yaml/dist/schema/yaml-1.1/merge.js +71 -0
  139. package/lib/vendor/yaml/dist/schema/yaml-1.1/omap.d.ts +22 -0
  140. package/lib/vendor/yaml/dist/schema/yaml-1.1/omap.js +77 -0
  141. package/lib/vendor/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
  142. package/lib/vendor/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
  143. package/lib/vendor/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
  144. package/lib/vendor/yaml/dist/schema/yaml-1.1/schema.js +41 -0
  145. package/lib/vendor/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
  146. package/lib/vendor/yaml/dist/schema/yaml-1.1/set.js +96 -0
  147. package/lib/vendor/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
  148. package/lib/vendor/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
  149. package/lib/vendor/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
  150. package/lib/vendor/yaml/dist/stringify/foldFlowLines.js +151 -0
  151. package/lib/vendor/yaml/dist/stringify/stringify.d.ts +21 -0
  152. package/lib/vendor/yaml/dist/stringify/stringify.js +132 -0
  153. package/lib/vendor/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
  154. package/lib/vendor/yaml/dist/stringify/stringifyCollection.js +155 -0
  155. package/lib/vendor/yaml/dist/stringify/stringifyComment.d.ts +10 -0
  156. package/lib/vendor/yaml/dist/stringify/stringifyComment.js +24 -0
  157. package/lib/vendor/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
  158. package/lib/vendor/yaml/dist/stringify/stringifyDocument.js +87 -0
  159. package/lib/vendor/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
  160. package/lib/vendor/yaml/dist/stringify/stringifyNumber.js +27 -0
  161. package/lib/vendor/yaml/dist/stringify/stringifyPair.d.ts +3 -0
  162. package/lib/vendor/yaml/dist/stringify/stringifyPair.js +152 -0
  163. package/lib/vendor/yaml/dist/stringify/stringifyString.d.ts +9 -0
  164. package/lib/vendor/yaml/dist/stringify/stringifyString.js +338 -0
  165. package/lib/vendor/yaml/dist/test-events.d.ts +4 -0
  166. package/lib/vendor/yaml/dist/test-events.js +134 -0
  167. package/lib/vendor/yaml/dist/util.d.ts +16 -0
  168. package/lib/vendor/yaml/dist/util.js +28 -0
  169. package/lib/vendor/yaml/dist/visit.d.ts +102 -0
  170. package/lib/vendor/yaml/dist/visit.js +236 -0
  171. package/lib/vendor/yaml/package.json +97 -0
  172. package/locale/en.json +7 -0
  173. package/locale/zh.json +7 -0
  174. package/package.json +62 -4
  175. package/profile/VAULT.md +221 -0
  176. package/skills/LICENSE +21 -0
  177. package/skills/defuddle/SKILL.md +43 -0
  178. package/skills/json-canvas/SKILL.md +253 -0
  179. package/skills/json-canvas/references/EXAMPLES.md +329 -0
  180. package/skills/knap/SKILL.md +102 -0
  181. package/skills/obsidian-bases/SKILL.md +601 -0
  182. package/skills/obsidian-bases/references/FUNCTIONS_REFERENCE.md +173 -0
  183. package/skills/obsidian-cli/SKILL.md +141 -0
  184. package/skills/obsidian-headless/SKILL.md +79 -0
  185. package/skills/obsidian-markdown/SKILL.md +202 -0
  186. package/skills/obsidian-markdown/references/CALLOUTS.md +58 -0
  187. package/skills/obsidian-markdown/references/EMBEDS.md +70 -0
  188. package/skills/obsidian-markdown/references/PROPERTIES.md +63 -0
package/client.js ADDED
@@ -0,0 +1,1577 @@
1
+ window.__ModuleLoader__.load({
2
+ id: 'modularob-connectors',
3
+ factory(require) {
4
+ const React = require('react')
5
+ const h = React.createElement
6
+ const { useEffect, useRef, useState } = React
7
+
8
+ const NS = 'modularobConnectors'
9
+ const API_PATH = '/modularob-connectors/api'
10
+
11
+ const API_URL = (() => {
12
+ try {
13
+ return new URL(API_PATH, window.location.href).toString()
14
+ } catch {
15
+ return API_PATH
16
+ }
17
+ })()
18
+
19
+ const en = {
20
+ 'side.label': 'ModularOB Connectors',
21
+ 'side.title': 'ModularOB Connectors',
22
+ 'vault.rowLabel': 'Obsidian vault',
23
+ 'vault.title': 'Vault used for this conversation',
24
+ 'vault.choose': 'Choose vault',
25
+ 'vault.loading': 'Loading…',
26
+ 'vault.none': 'No Obsidian vaults found.',
27
+ 'vault.loadFailed': 'Could not read Obsidian vaults.',
28
+ 'vault.failed': 'Could not change the Obsidian vault.',
29
+ 'vault.unavailable': 'Vault unavailable',
30
+ 'vault.stale': 'The previously selected vault is no longer registered. Choose another.',
31
+ 'vault.missing': 'missing',
32
+ 'vault.back': 'Back to Obsidian vault',
33
+ 'vault.clear': 'Clear vault selection',
34
+ 'action.retry': 'Retry',
35
+ 'profile.summary': 'Vault profile: {source} · {count} characters',
36
+ 'profile.bundled': 'bundled default',
37
+ 'profile.custom': 'customized',
38
+ 'profile.loading': 'Loading vault profile…',
39
+ 'profile.save': 'Save',
40
+ 'profile.saved': 'Vault profile saved.',
41
+ 'profile.saveFailed': 'Could not save the vault profile.',
42
+ 'profile.reset': 'Restore default',
43
+ 'profile.resetConfirm': 'Replace your edits with the default content?',
44
+ 'profile.restore': 'Restore',
45
+ 'profile.cancel': 'Cancel',
46
+ 'profile.restored': 'Default restored.',
47
+ 'profile.tooLong': 'The profile exceeds {max} characters.',
48
+ 'profile.loadFailed': 'Could not load the vault profile.',
49
+ 'profile.creation.target': 'New-note folder',
50
+ 'profile.creation.template': 'Default template',
51
+ 'profile.creation.templatePath': 'Template path',
52
+ 'profile.creation.templateFolder': 'Template folder',
53
+ 'profile.creation.notSet': 'Not set',
54
+ 'profile.creation.binding': 'When creating a note: write under {folder} using {template}.',
55
+ 'profile.chars': 'characters',
56
+ 'profile.tab.collections': 'Collections',
57
+ 'profile.tab.scopes': 'Path rules',
58
+ 'profile.tab.templates': 'Templates',
59
+ 'profile.tab.creation': 'Creation',
60
+ 'profile.tab.body': 'Body & workflow',
61
+ 'profile.tab.skills': 'SKILLS',
62
+ 'profile.tab.advanced': 'Advanced',
63
+ 'profile.skills.summary': 'Bundled skills · {enabled} of {total} enabled',
64
+ 'profile.skills.builtin': 'Bundled',
65
+ 'profile.skills.enabled': 'Enabled',
66
+ 'profile.skills.disabled': 'Disabled',
67
+ 'profile.skills.toggle': 'Enable',
68
+ 'profile.skills.note': 'Toggles take effect immediately; the next model step sees the updated skill catalog.',
69
+ 'profile.skills.saved': 'Skill setting applied.',
70
+ 'profile.skills.error': 'Could not load connector skills.',
71
+ 'profile.addCollection': 'Add collection',
72
+ 'profile.addScope': 'Add path rule',
73
+ 'profile.addTemplate': 'Add template',
74
+ 'profile.addSection': 'Add section',
75
+ 'profile.newCollection': 'New collection',
76
+ 'profile.newScope': 'New path rule',
77
+ 'profile.newTemplate': 'New template',
78
+ 'profile.newSection': 'New section',
79
+ 'profile.field.id': 'ID',
80
+ 'profile.field.title': 'Title',
81
+ 'profile.field.roots': 'Folders',
82
+ 'profile.field.aliases': 'Aliases',
83
+ 'profile.field.aliasesHelp': 'Separate aliases with commas.',
84
+ 'profile.field.fileTypes': 'File types',
85
+ 'profile.field.dateSource': 'Date source',
86
+ 'profile.field.dateFormat': 'Date format',
87
+ 'profile.field.dateProperty': 'Date property',
88
+ 'profile.field.paths': 'Paths',
89
+ 'profile.field.rules': 'Rules',
90
+ 'profile.field.templatePath': 'Template path',
91
+ 'profile.field.collection': 'Collection',
92
+ 'profile.field.collectionNone': 'None',
93
+ 'profile.field.defaultFolder': 'Default new-note folder',
94
+ 'profile.field.imageFolder': 'Image/attachment folder',
95
+ 'profile.field.defaultTemplate': 'Default template',
96
+ 'profile.field.scope': 'Path rule',
97
+ 'profile.field.heading': 'Section heading',
98
+ 'profile.date.none': 'Not used',
99
+ 'profile.date.filename': 'File name',
100
+ 'profile.date.frontmatter': 'Property',
101
+ 'profile.date.mtime': 'Modified time',
102
+ 'profile.selectFolder': 'Choose',
103
+ 'profile.vaultRoot': '/ (vault root)',
104
+ 'profile.folderTitle': 'Choose a folder',
105
+ 'profile.folderSearch': 'Search folders…',
106
+ 'profile.folderEmpty': 'No matching folder.',
107
+ 'profile.pickVaultFirst': 'Choose a validation vault first.',
108
+ 'profile.validationVault': 'Validation vault',
109
+ 'profile.validationVaultNone': 'No validation vault (syntax only)',
110
+ 'profile.enabled': 'Enabled',
111
+ 'profile.enabledTitle': 'Enable ModularOB Connectors',
112
+ 'profile.enabledOn': 'Connector enabled.',
113
+ 'profile.enabledOff': 'Connector disabled. The settings page stays available so you can re-enable it.',
114
+ 'profile.enabledFailed': 'Could not change the connector state.',
115
+ 'profile.update': 'Update',
116
+ 'profile.updating': 'Updating…',
117
+ 'profile.updateHint': 'Check GitHub and update the connector; personal settings are preserved.',
118
+ 'profile.updateLatest': 'Already up to date ({version}).',
119
+ 'profile.updateUnsupported': 'One-click update is unavailable for this install: {reason}',
120
+ 'profile.updateConfirm': 'Update to {latest}? The latest release tarball (or a pinned GitHub commit) replaces the plugin code; profile.md, state.json, and skills.json are preserved and backed up.',
121
+ 'profile.updateStarted': 'Update to {version} started; the page will refresh when it finishes.',
122
+ 'profile.updateMayHaveStarted': 'The update may have started; refresh the page shortly.',
123
+ 'profile.updateFailed': 'Could not check or apply the update.',
124
+ 'profile.activeNote': 'Read the active note',
125
+ 'profile.activeNoteFailed': 'Could not save the active-note setting.',
126
+ 'profile.sourceMode': 'Source',
127
+ 'profile.formMode': 'Form',
128
+ 'profile.sourceHint': 'Source mode edits the saved profile exactly. Switching back to the form reparses it.',
129
+ 'profile.sourceSaved': 'Source saved.',
130
+ 'profile.parseError': 'Could not parse the current profile:',
131
+ 'profile.unsaved': 'Unsaved changes',
132
+ 'profile.discardConfirm': 'Discard unsaved changes?',
133
+ 'profile.deleteConfirm': 'Delete “{name}”?',
134
+ 'profile.addPath': 'Add path',
135
+ 'profile.addRule': 'Add rule',
136
+ 'profile.remove': 'Remove',
137
+ 'profile.advancedHint': 'Unknown fields and parser warnings appear here. Use Source for the raw profile.',
138
+ }
139
+
140
+ const zh = {
141
+ 'side.label': 'ModularOB 连接器',
142
+ 'side.title': 'ModularOB 连接器',
143
+ 'vault.rowLabel': 'Obsidian 仓库',
144
+ 'vault.title': '当前对话使用的仓库',
145
+ 'vault.choose': '选择仓库',
146
+ 'vault.loading': '加载中…',
147
+ 'vault.none': '未找到 Obsidian 仓库。',
148
+ 'vault.loadFailed': '无法读取 Obsidian 仓库列表。',
149
+ 'vault.failed': '无法切换 Obsidian 仓库。',
150
+ 'vault.unavailable': '仓库不可用',
151
+ 'vault.stale': '之前选择的仓库已不在 Obsidian 中,请重新选择。',
152
+ 'vault.missing': '缺失',
153
+ 'vault.back': '返回 Obsidian 仓库',
154
+ 'vault.clear': '取消仓库选择',
155
+ 'action.retry': '重试',
156
+ 'profile.summary': '仓库说明:{source} · {count} 字符',
157
+ 'profile.bundled': '内置默认',
158
+ 'profile.custom': '已自定义',
159
+ 'profile.loading': '正在加载仓库说明…',
160
+ 'profile.save': '保存',
161
+ 'profile.saved': '仓库说明已保存。',
162
+ 'profile.saveFailed': '无法保存仓库说明。',
163
+ 'profile.reset': '恢复默认',
164
+ 'profile.resetConfirm': '用默认内容覆盖你的修改?',
165
+ 'profile.restore': '恢复',
166
+ 'profile.cancel': '取消',
167
+ 'profile.restored': '已恢复默认。',
168
+ 'profile.tooLong': '仓库说明超过 {max} 个字符。',
169
+ 'profile.loadFailed': '无法加载仓库说明。',
170
+ 'profile.creation.target': '新建目录',
171
+ 'profile.creation.template': '默认模板',
172
+ 'profile.creation.templatePath': '模板路径',
173
+ 'profile.creation.templateFolder': '模板所在目录',
174
+ 'profile.creation.notSet': '未设置',
175
+ 'profile.creation.binding': '新建笔记时:在 {folder} 下创建,使用 {template}。',
176
+ 'profile.chars': '字符',
177
+ 'profile.tab.collections': '资料类型',
178
+ 'profile.tab.scopes': '路径规则',
179
+ 'profile.tab.templates': '模板',
180
+ 'profile.tab.creation': '创建默认',
181
+ 'profile.tab.body': '正文 / 工作流',
182
+ 'profile.tab.skills': 'SKILLS',
183
+ 'profile.tab.advanced': '高级',
184
+ 'profile.skills.summary': '内置技能 · 已启用 {enabled} / {total}',
185
+ 'profile.skills.builtin': '内置',
186
+ 'profile.skills.enabled': '已启用',
187
+ 'profile.skills.disabled': '已关闭',
188
+ 'profile.skills.toggle': '启用',
189
+ 'profile.skills.note': '开关立即生效;下一条消息会使用新的技能列表。',
190
+ 'profile.skills.saved': '技能设置已生效。',
191
+ 'profile.skills.error': '无法加载连接器技能。',
192
+ 'profile.addCollection': '添加资料类型',
193
+ 'profile.addScope': '添加路径规则',
194
+ 'profile.addTemplate': '添加模板',
195
+ 'profile.addSection': '添加章节',
196
+ 'profile.newCollection': '新资料类型',
197
+ 'profile.newScope': '新路径规则',
198
+ 'profile.newTemplate': '新模板',
199
+ 'profile.newSection': '新章节',
200
+ 'profile.field.id': 'ID',
201
+ 'profile.field.title': '标题',
202
+ 'profile.field.roots': '目录',
203
+ 'profile.field.aliases': '别名',
204
+ 'profile.field.aliasesHelp': '多个别名用逗号分隔。',
205
+ 'profile.field.fileTypes': '文件类型',
206
+ 'profile.field.dateSource': '日期来源',
207
+ 'profile.field.dateFormat': '日期格式',
208
+ 'profile.field.dateProperty': '日期属性',
209
+ 'profile.field.paths': '路径',
210
+ 'profile.field.rules': '规则',
211
+ 'profile.field.templatePath': '模板路径',
212
+ 'profile.field.collection': '所属资料类型',
213
+ 'profile.field.collectionNone': '不关联',
214
+ 'profile.field.defaultFolder': '默认新建目录',
215
+ 'profile.field.imageFolder': '图片/附件目录',
216
+ 'profile.field.defaultTemplate': '默认模板',
217
+ 'profile.field.scope': '路径规则',
218
+ 'profile.field.heading': '章节标题',
219
+ 'profile.date.none': '不使用',
220
+ 'profile.date.filename': '文件名',
221
+ 'profile.date.frontmatter': '属性',
222
+ 'profile.date.mtime': '修改时间',
223
+ 'profile.selectFolder': '选择',
224
+ 'profile.vaultRoot': '/(仓库根目录)',
225
+ 'profile.folderTitle': '选择文件夹',
226
+ 'profile.folderSearch': '搜索文件夹…',
227
+ 'profile.folderEmpty': '没有匹配的文件夹。',
228
+ 'profile.pickVaultFirst': '请先选择“用于选择路径的仓库”。',
229
+ 'profile.validationVault': '用于选择路径的仓库',
230
+ 'profile.validationVaultNone': '未选择仓库(仅语法校验)',
231
+ 'profile.enabled': '启用',
232
+ 'profile.enabledTitle': '启用 ModularOB 连接器',
233
+ 'profile.enabledOn': '连接器已启用。',
234
+ 'profile.enabledOff': '连接器已关闭;设置页仍保留,可随时重新开启。',
235
+ 'profile.enabledFailed': '无法切换连接器状态。',
236
+ 'profile.update': '更新',
237
+ 'profile.updating': '更新中…',
238
+ 'profile.updateHint': '从 GitHub 检查并更新连接器;个人设置会保留。',
239
+ 'profile.updateLatest': '已是最新版本({version})。',
240
+ 'profile.updateUnsupported': '当前安装无法一键更新:{reason}',
241
+ 'profile.updateConfirm': '更新到 {latest}?将用最新 release 压缩包(或固定 GitHub 提交)替换插件代码;profile.md、state.json、skills.json 等个人设置会保留并备份。',
242
+ 'profile.updateStarted': '已开始更新到 {version};完成后页面会刷新。',
243
+ 'profile.updateMayHaveStarted': '更新可能已开始;请稍后刷新页面。',
244
+ 'profile.updateFailed': '检查或执行更新失败。',
245
+ 'profile.activeNote': '读取当前活动笔记',
246
+ 'profile.activeNoteFailed': '无法保存活动笔记设置。',
247
+ 'profile.sourceMode': '源码',
248
+ 'profile.formMode': '表单',
249
+ 'profile.sourceHint': '源码模式直接编辑已保存的 profile;切回表单会重新解析。',
250
+ 'profile.sourceSaved': '源码已保存。',
251
+ 'profile.parseError': '无法解析当前 profile:',
252
+ 'profile.unsaved': '有未保存修改',
253
+ 'profile.discardConfirm': '放弃未保存的修改?',
254
+ 'profile.deleteConfirm': '确定删除“{name}”?',
255
+ 'profile.addPath': '添加路径',
256
+ 'profile.addRule': '添加规则',
257
+ 'profile.remove': '删除',
258
+ 'profile.advancedHint': '这里显示未识别字段和解析警告;原始 profile 请用“源码”。',
259
+ }
260
+
261
+ const CSS = `
262
+ .dsoc-row { box-sizing:border-box; display:flex; align-items:center; gap:6px; width:auto; min-width:100%; height:34px; padding:0 8px; border:none; border-radius:var(--dsw-radius-md, 8px); background:transparent; color:var(--dsw-alias-label-primary); font-size:13px; line-height:20px; cursor:pointer; text-align:left; outline:none; }
263
+ .dsoc-row:hover, .dsoc-row:focus-visible { background:var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-2)); }
264
+ .dsoc-row-label { flex:0 0 auto; white-space:nowrap; }
265
+ .dsoc-row-value { flex:1 1 auto; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; text-align:right; color:var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary)); }
266
+ .dsoc-chevron { flex:0 0 auto; color:var(--dsw-alias-menu-icon, currentColor); }
267
+ .dsoc-row-logo { flex:0 0 auto; display:block; }
268
+ .dsoc-options { display:flex; flex-direction:column; max-height:180px; overflow-y:auto; overscroll-behavior:contain; }
269
+ .dsoc-divider { flex:none; height:1px; margin:4px 6px; background:var(--dsw-alias-border-l1); }
270
+ .dsoc-option--clear { color:var(--dsw-alias-label-secondary); }
271
+ .dsoc-clear-mark { flex:0 0 auto; }
272
+ .dsoc-model { display:inline-flex; align-items:center; gap:5px; min-width:0; }
273
+ .dsoc-model-logo { flex:0 0 auto; display:block; }
274
+ .dsoc-model-name { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
275
+ .dsoc-model-badge { flex:0 0 auto; padding:1px 5px; border-radius:999px; background:var(--dsw-alias-bg-layer-2); color:var(--dsw-alias-label-secondary); font-size:10px; line-height:1.4; }
276
+ .dsoc-pane { display:flex; flex-direction:column; }
277
+ .dsoc-option { display:flex; align-items:center; gap:8px; width:100%; min-height:34px; padding:0 8px; border:none; border-radius:var(--dsw-radius-md, 8px); background:transparent; color:var(--dsw-alias-label-primary); font-size:13px; line-height:20px; text-align:left; cursor:pointer; outline:none; }
278
+ .dsoc-option:hover, .dsoc-option:focus-visible { background:var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-2)); }
279
+ .dsoc-option:disabled { opacity:.55; cursor:default; }
280
+ .dsoc-option:disabled:hover { background:transparent; }
281
+ .dsoc-option-label { flex:1 1 auto; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
282
+ .dsoc-option-note { flex:0 0 auto; color:var(--dsw-alias-label-secondary); font-size:11px; }
283
+ .dsoc-check { flex:0 0 auto; color:var(--dsw-alias-brand-primary); }
284
+ .dsoc-note { padding:6px 8px; color:var(--dsw-alias-label-secondary); font-size:12px; }
285
+
286
+ .dsoc-cfg { display:flex; flex-direction:column; gap:10px; }
287
+ .dsoc-cfg-hint { margin:0; color:var(--dsw-alias-label-secondary); font-size:12px; line-height:1.55; }
288
+ .dsoc-cfg-text { box-sizing:border-box; width:100%; min-height:420px; resize:vertical; padding:10px 12px; border-radius:8px; border:1px solid var(--dsw-alias-border-l1); background:var(--dsw-alias-bg-base); color:var(--dsw-alias-label-primary); font-family:ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size:12px; line-height:1.55; }
289
+ .dsoc-cfg-text:focus-visible { outline:2px solid var(--dsw-alias-brand-primary); outline-offset:-1px; }
290
+ .dsoc-cfg-foot { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
291
+ .dsoc-cfg-meta { flex:1 1 auto; min-width:0; color:var(--dsw-alias-label-secondary); font-size:12px; }
292
+ .dsoc-cfg-notice { margin:0; font-size:12px; }
293
+ .dsoc-cfg-notice--error { color:var(--dsw-alias-state-error-primary); }
294
+ .dsoc-cfg-notice--success { color:var(--dsw-alias-state-success-primary); }
295
+ .dsoc-cfg-confirm { display:flex; align-items:center; gap:8px; flex-wrap:wrap; padding:8px 10px; border:1px solid var(--dsw-alias-state-warn-primary); border-radius:8px; }
296
+ .dsoc-btn { height:28px; padding:0 10px; border-radius:6px; border:1px solid var(--dsw-alias-border-l2); background:var(--dsw-alias-bg-layer-1); color:var(--dsw-alias-label-primary); font:inherit; font-size:12px; cursor:pointer; }
297
+ .dsoc-btn:hover { background:var(--dsw-alias-bg-layer-2); }
298
+ .dsoc-btn:disabled { opacity:.55; cursor:default; }
299
+ .dsoc-btn--primary { border-color:var(--dsw-alias-brand-primary); color:var(--dsw-alias-brand-primary); background:transparent; }
300
+ .dsoc-cfg-summary { color:var(--dsw-alias-label-secondary); font-size:12px; }
301
+
302
+ .dsoc-settings { display:flex; flex-direction:column; gap:10px; }
303
+ .dsoc-sticky { position:sticky; top:0; z-index:3; display:flex; flex-direction:column; gap:8px; background:var(--dsw-alias-bg-base); padding:2px 0 0; }
304
+ .dsoc-sticky .dsoc-tabbar { background:var(--dsw-alias-bg-base); }
305
+ .dsoc-settings-toolbar { display:flex; flex-wrap:wrap; align-items:center; gap:8px; }
306
+ .dsoc-settings-toolbar .dsoc-muted { flex:1 1 auto; min-width:100px; }
307
+ .dsoc-tabbar { display:flex; align-items:center; gap:4px; border-bottom:1px solid var(--dsw-alias-border-l1); }
308
+ .dsoc-tabs { display:flex; flex-wrap:wrap; align-items:center; gap:2px; flex:1 1 auto; }
309
+ .dsoc-tabs-status { margin-left:auto; padding:0 4px; font-size:11px; color:var(--dsw-alias-label-secondary); white-space:nowrap; }
310
+ .dsoc-tab { border:0; border-bottom:2px solid transparent; background:transparent; color:var(--dsw-alias-label-secondary); font:inherit; font-size:12px; padding:8px 10px; cursor:pointer; }
311
+ .dsoc-tab--active { color:var(--dsw-alias-label-primary); border-bottom-color:var(--dsw-alias-brand-primary); }
312
+ .dsoc-settings-content { display:flex; flex-direction:column; gap:10px; }
313
+ .dsoc-card { display:flex; flex-direction:column; gap:8px; min-width:0; padding:10px; border:1px solid var(--dsw-alias-border-l1); border-radius:8px; background:color-mix(in srgb, var(--dsw-alias-bg-base) 95%, var(--dsw-alias-label-primary) 5%); }
314
+ .dsoc-skill-summary { font-size:11px; color:var(--dsw-alias-label-secondary); }
315
+ .dsoc-skill-meta { display:flex; align-items:center; gap:6px; }
316
+ .dsoc-badge { padding:0 6px; border:1px solid var(--dsw-alias-border-l1); border-radius:999px; font-size:10px; line-height:16px; color:var(--dsw-alias-label-secondary); }
317
+ .dsoc-skill-desc { margin:0; color:var(--dsw-alias-label-secondary); font-size:12px; line-height:1.5; display:-webkit-box; -webkit-line-clamp:3; -webkit-box-orient:vertical; overflow:hidden; }
318
+ .dsoc-creation-summary { display:flex; flex-direction:column; gap:2px; padding-top:8px; border-top:1px solid var(--dsw-alias-border-l1); color:var(--dsw-alias-label-secondary); font-size:11px; }
319
+ .dsoc-card-grid { display:grid; grid-template-columns:repeat(2, minmax(0, 1fr)); gap:10px; align-items:start; }
320
+ .dsoc-card-list { display:flex; flex-direction:column; gap:10px; }
321
+ .dsoc-btn { white-space:nowrap; }
322
+ .dsoc-btn--small { flex:0 0 auto; min-width:48px; padding:0 8px; }
323
+ .dsoc-icon-btn { display:inline-flex; align-items:center; justify-content:center; width:30px; min-width:30px; height:30px; padding:0; }
324
+ .dsoc-icon-btn:hover { color:var(--dsw-alias-state-error-primary); }
325
+ .dsoc-card-head { display:flex; align-items:center; gap:8px; }
326
+ .dsoc-card-title { flex:1 1 auto; min-width:0; font-size:12px; font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
327
+ .dsoc-field { display:flex; flex-direction:column; gap:4px; min-width:0; }
328
+ .dsoc-field-label { font-size:11px; color:var(--dsw-alias-label-secondary); }
329
+ .dsoc-field-help { margin:0; font-size:11px; color:var(--dsw-alias-label-secondary); }
330
+ .dsoc-input, .dsoc-textarea, .dsoc-select { box-sizing:border-box; width:100%; min-width:0; padding:6px 8px; border-radius:6px; border:1px solid var(--dsw-alias-border-l1); background:var(--dsw-alias-bg-base); color:var(--dsw-alias-label-primary); font:inherit; font-size:12px; }
331
+ .dsoc-input, .dsoc-select { height:30px; }
332
+ .dsoc-textarea { min-height:70px; resize:vertical; }
333
+ .dsoc-textarea--rule { min-height:52px; }
334
+ .dsoc-textarea--body { min-height:140px; font-family:ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height:1.55; }
335
+ .dsoc-textarea--source { min-height:420px; font-family:ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height:1.55; }
336
+ .dsoc-input:focus-visible, .dsoc-textarea:focus-visible, .dsoc-select:focus-visible { outline:2px solid var(--dsw-alias-brand-primary); outline-offset:-1px; }
337
+ .dsoc-grid { display:grid; grid-template-columns:1fr 1fr; gap:10px; }
338
+ .dsoc-row-line { display:flex; align-items:center; gap:6px; min-width:0; }
339
+ .dsoc-row-line .dsoc-input, .dsoc-row-line .dsoc-textarea { flex:1 1 auto; }
340
+ .dsoc-row-line--top { align-items:flex-start; }
341
+ .dsoc-checkbox-row { display:flex; flex-wrap:wrap; gap:8px; }
342
+ .dsoc-check { display:inline-flex; align-items:center; gap:4px; font-size:12px; color:var(--dsw-alias-label-primary); }
343
+ .dsoc-check--inline { flex:0 0 auto; }
344
+ .dsoc-add { align-self:flex-start; border:1px dashed var(--dsw-alias-border-l2); border-radius:6px; background:transparent; color:var(--dsw-alias-label-secondary); font:inherit; font-size:12px; padding:6px 10px; cursor:pointer; }
345
+ .dsoc-add:hover { background:var(--dsw-alias-bg-layer-2); }
346
+ .dsoc-notice { margin:0; padding:6px 8px; border-radius:6px; font-size:12px; border:1px solid var(--dsw-alias-border-l1); }
347
+ .dsoc-notice--error { border-color:var(--dsw-alias-state-error-primary); color:var(--dsw-alias-state-error-primary); }
348
+ .dsoc-notice--success { border-color:var(--dsw-alias-state-success-primary); color:var(--dsw-alias-state-success-primary); }
349
+ .dsoc-modal { position:fixed; inset:0; z-index:1300; display:flex; align-items:center; justify-content:center; background:color-mix(in srgb, var(--dsw-alias-label-primary) 20%, transparent); }
350
+ .dsoc-modal-card { display:flex; flex-direction:column; gap:8px; width:min(520px, 90vw); max-height:70vh; padding:12px; border-radius:10px; border:1px solid var(--dsw-alias-border-l1); background:var(--dsw-alias-bg-overlay); box-shadow:var(--dsw-elevation-prominent, 0 10px 30px rgba(0,0,0,.25)); }
351
+ .dsoc-modal-list { display:flex; flex-direction:column; gap:2px; overflow:auto; }
352
+ .dsoc-modal-item { text-align:left; border:0; border-radius:6px; background:transparent; color:var(--dsw-alias-label-primary); font:inherit; font-size:12px; padding:7px 8px; cursor:pointer; }
353
+ .dsoc-modal-item:hover { background:var(--dsw-alias-bg-layer-2); }
354
+ .dsoc-select--compact { width:auto; max-width:220px; }
355
+ .dsoc-main-panel { box-sizing:border-box; height:100%; overflow:auto; padding:0 16px 16px; }
356
+ .dsoc-main-head { position:sticky; top:0; z-index:4; display:flex; align-items:center; gap:8px; height:48px; margin:0 -16px 10px; padding:0 16px; background:var(--dsw-alias-bg-base); border-bottom:1px solid var(--dsw-alias-border-l1); }
357
+ .dsoc-main-panel .dsoc-sticky { top:48px; }
358
+ .dsoc-main-title { font-size:16px; font-weight:600; }
359
+ @media (max-width: 1000px) { .dsoc-card-grid { grid-template-columns:1fr; } }
360
+ @media (max-width: 640px) { .dsoc-grid { grid-template-columns:1fr; } }
361
+
362
+ `
363
+
364
+ // Per-session vault selection shared by the menu row and the model label.
365
+ const selectionBySession = new Map()
366
+ const selectionListeners = new Set()
367
+
368
+ function publishSelection(sessionId, selectedId) {
369
+ if (typeof sessionId !== 'string' || typeof selectedId !== 'string') return
370
+ if (selectionBySession.get(sessionId) === selectedId) return
371
+ selectionBySession.set(sessionId, selectedId)
372
+ for (const listener of [...selectionListeners]) listener()
373
+ }
374
+
375
+ function subscribeSelection(listener) {
376
+ selectionListeners.add(listener)
377
+ return () => { selectionListeners.delete(listener) }
378
+ }
379
+
380
+ // The connector's master switch is shared by the settings panel, the menu
381
+ // row, and the trigger logo. The Host is authoritative; these stores only
382
+ // keep the mounted client surfaces in sync.
383
+ const connectorEnabledStore = { value: true, listeners: new Set() }
384
+
385
+ function setConnectorEnabled(value) {
386
+ const next = value !== false
387
+ if (connectorEnabledStore.value === next) return
388
+ connectorEnabledStore.value = next
389
+ for (const listener of [...connectorEnabledStore.listeners]) listener()
390
+ }
391
+
392
+ function useConnectorEnabled() {
393
+ const [value, setValue] = useState(connectorEnabledStore.value)
394
+ useEffect(() => {
395
+ const listener = () => setValue(connectorEnabledStore.value)
396
+ connectorEnabledStore.listeners.add(listener)
397
+ listener()
398
+ return () => { connectorEnabledStore.listeners.delete(listener) }
399
+ }, [])
400
+ return value
401
+ }
402
+
403
+ class ApiError extends Error {
404
+ constructor(code, message) {
405
+ super(message)
406
+ this.name = 'ApiError'
407
+ this.code = code
408
+ }
409
+ }
410
+
411
+ async function callApi(method, params) {
412
+ let response
413
+ try {
414
+ response = await fetch(API_URL, {
415
+ method: 'POST',
416
+ headers: { 'content-type': 'application/json' },
417
+ body: JSON.stringify({ method, params: params ?? {} }),
418
+ credentials: 'same-origin',
419
+ })
420
+ } catch {
421
+ throw new ApiError('offline', 'fetch-failed')
422
+ }
423
+ const raw = await response.text()
424
+ let body = null
425
+ try {
426
+ body = raw.length > 0 ? JSON.parse(raw) : null
427
+ } catch {
428
+ body = null
429
+ }
430
+ if (response.status === 401 || response.status === 403) {
431
+ throw new ApiError('unauthorized', body?.error?.message ?? 'unauthorized')
432
+ }
433
+ if (!response.ok) throw new ApiError(body?.error?.code ?? `http-${response.status}`, body?.error?.message ?? `HTTP ${response.status}`)
434
+ if (body === null || body.ok !== true) throw new ApiError(body?.error?.code ?? 'failed', body?.error?.message ?? 'request-failed')
435
+ return body.value
436
+ }
437
+
438
+ function Chevron({ direction }) {
439
+ return h('svg', {
440
+ viewBox: '0 0 16 16',
441
+ width: 12,
442
+ height: 12,
443
+ fill: 'none',
444
+ stroke: 'currentColor',
445
+ strokeWidth: 1.4,
446
+ strokeLinecap: 'round',
447
+ strokeLinejoin: 'round',
448
+ className: 'dsoc-chevron',
449
+ 'aria-hidden': true,
450
+ }, h('path', { d: direction === 'left' ? 'M10 3.5 5.5 8 10 12.5' : 'M6 3.5 10.5 8 6 12.5' }))
451
+ }
452
+
453
+ function Check() {
454
+ return h('svg', {
455
+ viewBox: '0 0 16 16',
456
+ width: 14,
457
+ height: 14,
458
+ fill: 'none',
459
+ stroke: 'currentColor',
460
+ strokeWidth: 1.8,
461
+ strokeLinecap: 'round',
462
+ strokeLinejoin: 'round',
463
+ className: 'dsoc-check',
464
+ 'aria-hidden': true,
465
+ }, h('path', { d: 'm3.2 8.4 3.1 3.1 6.5-6.8' }))
466
+ }
467
+
468
+ function ClearMark() {
469
+ return h('svg', {
470
+ viewBox: '0 0 16 16',
471
+ width: 12,
472
+ height: 12,
473
+ fill: 'none',
474
+ stroke: 'currentColor',
475
+ strokeWidth: 1.6,
476
+ strokeLinecap: 'round',
477
+ className: 'dsoc-clear-mark',
478
+ 'aria-hidden': true,
479
+ }, h('path', { d: 'm4 4 8 8M12 4l-8 8' }))
480
+ }
481
+
482
+ const LOGO_PATHS = [
483
+ 'm6.91927 14.5955c.64053-.1907 1.67255-.4839 2.85923-.5565-.71191-1.7968-.88376-3.3691-.74554-4.76905.15962-1.61678.72977-2.9662 1.28554-4.11442.1186-.24501.2326-.47313.3419-.69198.1549-.30984.3004-.60109.4365-.8953.2266-.48978.3948-.92231.4798-1.32416.0836-.39515.0841-.74806-.0148-1.08657-.099-.338982-.3093-.703864-.7093-1.1038132-.5222-.1353116-1.1017-.0165173-1.53613.3742922l-5.15591 4.638241c-.28758.25871-.47636.60929-.53406.99179l-.44455 2.94723c.69903.6179 2.42435 2.41414 3.47374 4.90644.09364.2224.1819.4505.26358.6838z',
484
+ 'm2.97347 10.3512c-.02431.1037-.05852.205-.10221.3024l-2.724986 6.0735c-.279882.6238-.15095061 1.3552.325357 1.8457l4.288349 4.4163c2.1899-3.2306 1.87062-6.2699.87032-8.6457-.75846-1.8013-1.90801-3.2112-2.65683-3.9922z',
485
+ 'm5.7507 23.5094c.07515.012.15135.0192.2281.0215.81383.0244 2.18251.0952 3.29249.2997.90551.1669 2.70051.6687 4.17761 1.1005 1.1271.3294 2.2886-.5707 2.4522-1.7336.1192-.8481.343-1.8075.7553-2.6869l-.0095.0033c-.6982-1.9471-1.5865-3.2044-2.5178-4.0073-.9284-.8004-1.928-1.1738-2.8932-1.3095-1.60474-.2257-3.07497.1961-4.00103.4682.55465 2.3107.38396 5.0295-1.48417 7.8441z',
486
+ 'm17.3708 19.3102c.9267-1.3985 1.5868-2.4862 1.9352-3.0758.1742-.295.1427-.6648-.0638-.9383-.5377-.7126-1.5666-2.1607-2.1272-3.5015-.5764-1.3785-.6624-3.51876-.6673-4.56119-.0019-.39626-.1275-.78328-.3726-1.09465l-3.3311-4.23183c-.0117.19075-.0392.37998-.0788.56747-.1109.52394-.32 1.04552-.5585 1.56101-.1398.30214-.3014.62583-.4646.95284-.1086.21764-.218.4368-.3222.652-.5385 1.11265-1.0397 2.32011-1.1797 3.73901-.1299 1.31514.0478 2.84484.8484 4.67094.1333.0113.2675.0262.4023.0452 1.1488.1615 2.3546.6115 3.4647 1.5685.9541.8226 1.8163 2.0012 2.5152 3.6463z',
487
+ ]
488
+
489
+ /** The connector logo shown at the left of the vault row once a vault is selected. */
490
+ function ObsidianLogo({ size = 16 }) {
491
+ return h('svg', {
492
+ viewBox: '0 0 22 24',
493
+ width: size,
494
+ height: Math.round(size * 24 / 22),
495
+ className: 'dsoc-row-logo',
496
+ 'aria-hidden': true,
497
+ focusable: false,
498
+ }, LOGO_PATHS.map((d, index) => h('path', { key: index, fill: '#A88BFA', d })))
499
+ }
500
+
501
+ /**
502
+ * The `conversation.input.model.options` row:
503
+ * root row → vault list, matching the native model menu's cell shape.
504
+ */
505
+ function VaultMenuRow(props) {
506
+ const { sessionId, t, dismiss, reportFailure } = props
507
+ const [phase, setPhase] = useState('loading')
508
+ const [vaults, setVaults] = useState([])
509
+ const [selectedId, setSelectedId] = useState('')
510
+ const [stale, setStale] = useState(false)
511
+ const [open, setOpen] = useState(false)
512
+ const [pending, setPending] = useState(false)
513
+ const alive = useRef(true)
514
+ const connectorEnabled = useConnectorEnabled()
515
+
516
+ const load = () => {
517
+ setPhase('loading')
518
+ return callApi('vaults', { sessionId })
519
+ .then((value) => {
520
+ if (!alive.current) return
521
+ setConnectorEnabled(value.enabled !== false)
522
+ setVaults(Array.isArray(value.vaults) ? value.vaults : [])
523
+ setSelectedId(typeof value.selectedId === 'string' ? value.selectedId : '')
524
+ setStale(value.stale === true)
525
+ setPhase('ready')
526
+ publishSelection(sessionId, typeof value.selectedId === 'string' ? value.selectedId : '')
527
+ })
528
+ .catch((error) => {
529
+ if (!alive.current) return
530
+ console.error('modularob-connectors: vault list failed', error)
531
+ setVaults([])
532
+ setSelectedId('')
533
+ setStale(false)
534
+ setPhase('error')
535
+ })
536
+ }
537
+
538
+ useEffect(() => {
539
+ alive.current = true
540
+ setOpen(false)
541
+ setPending(false)
542
+ void load()
543
+ return () => { alive.current = false }
544
+ }, [sessionId])
545
+
546
+ if (!connectorEnabled) return null
547
+
548
+ const selected = vaults.find(vault => vault.id === selectedId)
549
+ const value = (() => {
550
+ if (phase === 'loading') return t('vault.loading')
551
+ if (phase === 'error') return t('vault.loadFailed')
552
+ if (stale) return t('vault.unavailable')
553
+ if (selected !== undefined) return selected.label ?? selected.path
554
+ return t('vault.choose')
555
+ })()
556
+
557
+ const clearSelection = () => {
558
+ setPending(true)
559
+ callApi('clear', { sessionId })
560
+ .then(() => {
561
+ if (!alive.current) return
562
+ setSelectedId('')
563
+ setStale(false)
564
+ setPending(false)
565
+ setOpen(false)
566
+ publishSelection(sessionId, '')
567
+ dismiss()
568
+ })
569
+ .catch((error) => {
570
+ if (!alive.current) return
571
+ console.error('modularob-connectors: vault clear failed', error)
572
+ setPending(false)
573
+ reportFailure(t('vault.failed'))
574
+ })
575
+ }
576
+
577
+ const choose = (vault) => {
578
+ setPending(true)
579
+ callApi('select', { sessionId, vaultId: vault.id })
580
+ .then(() => {
581
+ if (!alive.current) return
582
+ setSelectedId(vault.id)
583
+ setStale(false)
584
+ setPending(false)
585
+ setOpen(false)
586
+ publishSelection(sessionId, vault.id)
587
+ dismiss()
588
+ })
589
+ .catch((error) => {
590
+ if (!alive.current) return
591
+ console.error('modularob-connectors: vault select failed', error)
592
+ setPending(false)
593
+ reportFailure(t('vault.failed'))
594
+ })
595
+ }
596
+
597
+ if (!open) {
598
+ return h('button', {
599
+ type: 'button',
600
+ role: 'menuitem',
601
+ className: 'dsoc-row',
602
+ title: selected !== undefined ? `${t('vault.title')}: ${selected.path}` : t('vault.title'),
603
+ 'aria-haspopup': 'menu',
604
+ 'aria-expanded': 'false',
605
+ onClick: () => {
606
+ setOpen(true)
607
+ if (phase === 'error') void load()
608
+ },
609
+ }, [
610
+ selected !== undefined ? h(ObsidianLogo, { key: 'logo', size: 16 }) : null,
611
+ h('span', { key: 'label', className: 'dsoc-row-label' }, t('vault.rowLabel')),
612
+ h('span', { key: 'value', className: 'dsoc-row-value' }, value),
613
+ h(Chevron, { key: 'chevron', direction: 'right' }),
614
+ ])
615
+ }
616
+
617
+ let body
618
+ if (phase === 'loading') {
619
+ body = h('div', { key: 'loading', className: 'dsoc-note' }, t('vault.loading'))
620
+ } else if (phase === 'error') {
621
+ body = h('button', { key: 'retry', type: 'button', role: 'menuitem', className: 'dsoc-option', onClick: () => void load() }, [
622
+ h('span', { key: 'label', className: 'dsoc-option-label' }, t('vault.loadFailed')),
623
+ h('span', { key: 'action', className: 'dsoc-option-note' }, t('action.retry')),
624
+ ])
625
+ } else if (vaults.length === 0) {
626
+ body = h('div', { key: 'none', className: 'dsoc-note' }, t('vault.none'))
627
+ } else {
628
+ body = vaults.map(vault => h('button', {
629
+ key: vault.id,
630
+ type: 'button',
631
+ role: 'menuitemradio',
632
+ 'aria-checked': vault.id === selectedId ? 'true' : 'false',
633
+ className: 'dsoc-option',
634
+ disabled: pending || vault.exists === false,
635
+ onClick: () => choose(vault),
636
+ }, [
637
+ h('span', { key: 'label', className: 'dsoc-option-label' }, vault.label ?? vault.path),
638
+ vault.id === selectedId ? h(Check, { key: 'check' }) : null,
639
+ vault.exists === false ? h('span', { key: 'missing', className: 'dsoc-option-note' }, t('vault.missing')) : null,
640
+ ]))
641
+ }
642
+
643
+ const children = [
644
+ h('button', {
645
+ key: 'back',
646
+ type: 'button',
647
+ role: 'menuitem',
648
+ className: 'dsoc-row',
649
+ title: t('vault.back'),
650
+ onClick: () => setOpen(false),
651
+ }, [
652
+ selected !== undefined ? h(ObsidianLogo, { key: 'logo', size: 16 }) : null,
653
+ h(Chevron, { key: 'chevron', direction: 'left' }),
654
+ h('span', { key: 'label', className: 'dsoc-row-label' }, t('vault.rowLabel')),
655
+ h('span', { key: 'value', className: 'dsoc-row-value' }, stale ? t('vault.unavailable') : selected?.label ?? ''),
656
+ ]),
657
+ ]
658
+ // The vault list scrolls inside a bounded area; the back row and the
659
+ // clear footer stay visible even with many vaults (the menu surface clips
660
+ // at its own max-height).
661
+ children.push(h('div', { key: 'options', className: 'dsoc-options' }, Array.isArray(body) ? body : [body]))
662
+ if (selectedId.length > 0 || stale) {
663
+ children.push(h('div', { key: 'clear-divider', className: 'dsoc-divider' }))
664
+ children.push(h('button', {
665
+ key: 'clear',
666
+ type: 'button',
667
+ role: 'menuitem',
668
+ className: 'dsoc-option dsoc-option--clear',
669
+ disabled: pending,
670
+ onClick: clearSelection,
671
+ }, [
672
+ h(ClearMark, { key: 'icon' }),
673
+ h('span', { key: 'label', className: 'dsoc-option-label' }, t('vault.clear')),
674
+ ]))
675
+ }
676
+ return h('div', { className: 'dsoc-pane', role: 'group', 'aria-label': t('vault.rowLabel') }, children)
677
+ }
678
+
679
+ /**
680
+ * The trigger's inline model label. The slot is single, so this renders the
681
+ * model name for every placement and adds the connector logo only in the
682
+ * composer trigger when the conversation has a selected vault.
683
+ */
684
+ function ModelLabel(props) {
685
+ const { model, placement, sessionId } = props
686
+ const [selectedId, setSelectedId] = useState(() => selectionBySession.get(sessionId) ?? '')
687
+ const connectorEnabled = useConnectorEnabled()
688
+
689
+ useEffect(() => {
690
+ if (placement !== 'trigger') return undefined
691
+ let alive = true
692
+ const cached = selectionBySession.get(sessionId)
693
+ if (cached !== undefined) setSelectedId(cached)
694
+ callApi('vaults', { sessionId })
695
+ .then((value) => {
696
+ if (!alive) return
697
+ setConnectorEnabled(value.enabled !== false)
698
+ const id = typeof value.selectedId === 'string' ? value.selectedId : ''
699
+ publishSelection(sessionId, id)
700
+ setSelectedId(id)
701
+ })
702
+ .catch(() => { /* the label stays without a logo */ })
703
+ const off = subscribeSelection(() => {
704
+ const next = selectionBySession.get(sessionId)
705
+ if (next !== undefined) setSelectedId(next)
706
+ })
707
+ return () => { alive = false; off() }
708
+ }, [sessionId, placement])
709
+
710
+ const name = h('span', { key: 'name', className: 'dsoc-model-name' }, model?.name ?? model?.id ?? '')
711
+ const badgeText = typeof model?.badge?.text === 'string' ? model.badge.text : ''
712
+ const badge = badgeText.length > 0
713
+ ? h('span', { key: 'badge', className: 'dsoc-model-badge' }, badgeText)
714
+ : null
715
+ const logo = connectorEnabled && placement === 'trigger' && selectedId.length > 0
716
+ ? h(ObsidianLogo, { key: 'logo', size: 14 })
717
+ : null
718
+ const children = placement === 'trigger'
719
+ ? [logo, badge, name]
720
+ : [name, badge]
721
+ return h('span', { className: 'dsoc-model' }, children)
722
+ }
723
+
724
+ const TABS = ['collections', 'scopes', 'templates', 'creation', 'body', 'skills', 'advanced']
725
+
726
+ function cloneModel(model) {
727
+ return JSON.parse(JSON.stringify(model))
728
+ }
729
+
730
+ function Field({ label, help, children }) {
731
+ return h('label', { className: 'dsoc-field' }, [
732
+ h('span', { key: 'label', className: 'dsoc-field-label' }, label),
733
+ ...Array.isArray(children) ? children : [children],
734
+ help ? h('span', { key: 'help', className: 'dsoc-field-help' }, help) : null,
735
+ ])
736
+ }
737
+
738
+ function TextField({ label, value, onChange, placeholder, help }) {
739
+ return h(Field, { label, help }, h('input', {
740
+ className: 'dsoc-input',
741
+ value: value ?? '',
742
+ placeholder: placeholder ?? '',
743
+ onChange: event => onChange(event.target.value),
744
+ }))
745
+ }
746
+
747
+ function SelectField({ label, value, onChange, options }) {
748
+ return h(Field, { label }, h('select', {
749
+ className: 'dsoc-select',
750
+ value: value ?? '',
751
+ onChange: event => onChange(event.target.value),
752
+ }, options.map(option => h('option', { key: option.value, value: option.value }, option.label))))
753
+ }
754
+
755
+ function SinglePathField({ t, label, value, onChange, onPick }) {
756
+ return h(Field, { label }, h('div', { className: 'dsoc-row-line' }, [
757
+ h('input', {
758
+ key: 'input',
759
+ className: 'dsoc-input',
760
+ value: value ?? '',
761
+ placeholder: 'Documents/...',
762
+ onChange: event => onChange(event.target.value),
763
+ }),
764
+ h('button', {
765
+ key: 'pick',
766
+ type: 'button',
767
+ className: 'dsoc-btn dsoc-btn--small',
768
+ onClick: () => onPick(path => onChange(path)),
769
+ }, t('profile.selectFolder')),
770
+ ]))
771
+ }
772
+
773
+ function TrashIcon({ size = 14 }) {
774
+ return h('svg', {
775
+ width: size,
776
+ height: size,
777
+ viewBox: '0 0 24 24',
778
+ fill: 'none',
779
+ stroke: 'currentColor',
780
+ strokeWidth: 1.8,
781
+ strokeLinecap: 'round',
782
+ strokeLinejoin: 'round',
783
+ 'aria-hidden': 'true',
784
+ focusable: 'false',
785
+ }, [
786
+ h('path', { key: 'lid', d: 'M3 6h18' }),
787
+ h('path', { key: 'top', d: 'M8 6V4a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v2' }),
788
+ h('path', { key: 'body', d: 'M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6' }),
789
+ h('path', { key: 'line1', d: 'M10 11v6' }),
790
+ h('path', { key: 'line2', d: 'M14 11v6' }),
791
+ ])
792
+ }
793
+
794
+ function PathRows({ t, label, values, onChange, onPick, placeholder, allowGlob }) {
795
+ const list = Array.isArray(values) ? values : []
796
+ const setAt = (index, value) => {
797
+ const next = [...list]
798
+ next[index] = value
799
+ onChange(next)
800
+ }
801
+ return h('div', { className: 'dsoc-field' }, [
802
+ h('span', { key: 'label', className: 'dsoc-field-label' }, label),
803
+ ...list.map((value, index) => h('div', { key: `path-${index}`, className: 'dsoc-row-line' }, [
804
+ h('input', {
805
+ key: 'input',
806
+ className: 'dsoc-input',
807
+ value,
808
+ placeholder: placeholder ?? (allowGlob ? 'Documents/**' : 'Documents/...'),
809
+ onChange: event => setAt(index, event.target.value),
810
+ }),
811
+ h('button', {
812
+ key: 'pick',
813
+ type: 'button',
814
+ className: 'dsoc-btn dsoc-btn--small',
815
+ onClick: () => onPick(path => setAt(index, allowGlob ? (path.length === 0 ? '**' : `${path}/**`) : path)),
816
+ }, t('profile.selectFolder')),
817
+ h('button', {
818
+ key: 'remove',
819
+ type: 'button',
820
+ className: 'dsoc-btn dsoc-btn--small dsoc-icon-btn',
821
+ title: t('profile.remove'),
822
+ 'aria-label': t('profile.remove'),
823
+ onClick: () => onChange(list.filter((_, item) => item !== index)),
824
+ }, h(TrashIcon, { key: 'icon' })),
825
+ ])),
826
+ h('button', {
827
+ key: 'add',
828
+ type: 'button',
829
+ className: 'dsoc-add',
830
+ onClick: () => onChange([...list, '']),
831
+ }, `+ ${t('profile.addPath')}`),
832
+ ])
833
+ }
834
+
835
+ function Card({ title, onRemove, removeLabel = 'Remove', children }) {
836
+ return h('section', { className: 'dsoc-card' }, [
837
+ h('header', { key: 'head', className: 'dsoc-card-head' }, [
838
+ h('span', { key: 'title', className: 'dsoc-card-title' }, title),
839
+ onRemove ? h('button', {
840
+ key: 'remove',
841
+ type: 'button',
842
+ className: 'dsoc-btn dsoc-btn--small dsoc-icon-btn',
843
+ title: removeLabel,
844
+ 'aria-label': removeLabel,
845
+ onClick: onRemove,
846
+ }, h(TrashIcon, { key: 'icon' })) : null,
847
+ ]),
848
+ ...Array.isArray(children) ? children : [children],
849
+ ])
850
+ }
851
+
852
+ function FolderPickerModal({ t, picker, onChoose, onClose }) {
853
+ const [query, setQuery] = useState('')
854
+ const folders = picker.folders ?? []
855
+ const filtered = query.trim().length === 0
856
+ ? folders
857
+ : folders.filter(folder => folder.toLowerCase().includes(query.trim().toLowerCase()))
858
+ return h('div', { className: 'dsoc-modal', role: 'dialog', 'aria-modal': 'true', 'aria-label': t('profile.selectFolder') }, [
859
+ h('div', { key: 'card', className: 'dsoc-modal-card' }, [
860
+ h('div', { key: 'head', className: 'dsoc-card-head' }, [
861
+ h('span', { key: 'title', className: 'dsoc-card-title' }, t('profile.folderTitle')),
862
+ h('button', { key: 'close', type: 'button', className: 'dsoc-btn dsoc-btn--small', onClick: onClose }, t('profile.cancel')),
863
+ ]),
864
+ h('input', {
865
+ key: 'search',
866
+ className: 'dsoc-input',
867
+ value: query,
868
+ placeholder: t('profile.folderSearch'),
869
+ 'aria-label': t('profile.folderSearch'),
870
+ onChange: event => setQuery(event.target.value),
871
+ }),
872
+ picker.loading
873
+ ? h('div', { key: 'loading', className: 'dsoc-muted' }, t('profile.loading'))
874
+ : h('div', { key: 'list', className: 'dsoc-modal-list' }, [
875
+ h('button', {
876
+ key: 'root',
877
+ type: 'button',
878
+ className: 'dsoc-modal-item',
879
+ onClick: () => onChoose(''),
880
+ }, t('profile.vaultRoot')),
881
+ ...filtered.map(folder => h('button', {
882
+ key: folder,
883
+ type: 'button',
884
+ className: 'dsoc-modal-item',
885
+ onClick: () => onChoose(folder),
886
+ }, folder)),
887
+ filtered.length === 0 ? h('div', { key: 'empty', className: 'dsoc-muted' }, t('profile.folderEmpty')) : null,
888
+ ]),
889
+ ]),
890
+ ])
891
+ }
892
+
893
+ function ProfileSettings(props) {
894
+ const { view = 'page', t } = props
895
+ const [phase, setPhase] = useState('loading')
896
+ const [payload, setPayload] = useState(null)
897
+ const [draft, setDraft] = useState(null)
898
+ const [tab, setTab] = useState('collections')
899
+ const [notice, setNotice] = useState(null)
900
+ const [pending, setPending] = useState(false)
901
+ const [dirty, setDirty] = useState(false)
902
+ const [sourceMode, setSourceMode] = useState(false)
903
+ const [sourceText, setSourceText] = useState('')
904
+ const [settings, setSettings] = useState({ activeNote: true, enabled: true })
905
+ const [vaults, setVaults] = useState([])
906
+ const [validationVaultId, setValidationVaultId] = useState('')
907
+ const [skillsData, setSkillsData] = useState(null)
908
+ const [skillsError, setSkillsError] = useState(false)
909
+ const [skillsPending, setSkillsPending] = useState(() => new Set())
910
+ const [updatePending, setUpdatePending] = useState(false)
911
+ const [picker, setPicker] = useState(null)
912
+ const alive = useRef(true)
913
+
914
+ const load = () => {
915
+ setPhase('loading')
916
+ return Promise.all([
917
+ callApi('profile.model.get'),
918
+ callApi('settings.get'),
919
+ callApi('vaults', { sessionId: '' }),
920
+ callApi('skills.list').catch(() => null),
921
+ ])
922
+ .then(([profileValue, settingsValue, vaultValue, skillsValue]) => {
923
+ if (!alive.current) return
924
+ setPayload(profileValue)
925
+ setDraft(profileValue.model === null ? null : cloneModel(profileValue.model))
926
+ setSettings(settingsValue)
927
+ setConnectorEnabled(settingsValue.enabled !== false)
928
+ if (skillsValue === null) setSkillsError(true)
929
+ else {
930
+ setSkillsData(skillsValue)
931
+ setSkillsError(false)
932
+ }
933
+ const list = Array.isArray(vaultValue.vaults) ? vaultValue.vaults : []
934
+ setVaults(list)
935
+ const first = list.find(vault => vault.exists) ?? list[0]
936
+ setValidationVaultId(first?.id ?? '')
937
+ if (profileValue.error !== null && profileValue.error !== undefined) {
938
+ setSourceMode(true)
939
+ setSourceText(profileValue.text ?? '')
940
+ }
941
+ setPhase('ready')
942
+ })
943
+ .catch(() => { if (alive.current) setPhase('error') })
944
+ }
945
+
946
+ useEffect(() => {
947
+ alive.current = true
948
+ void load()
949
+ return () => { alive.current = false }
950
+ }, [])
951
+
952
+ if (view === 'summary') {
953
+ return h('span', { className: 'dsoc-cfg-summary' }, payload === null
954
+ ? t('profile.loading')
955
+ : t('profile.summary', {
956
+ source: payload.source === 'custom' ? t('profile.custom') : t('profile.bundled'),
957
+ count: payload.charCount,
958
+ }))
959
+ }
960
+
961
+ if (phase === 'loading') return h('div', { className: 'dsoc-note' }, t('profile.loading'))
962
+ if (phase === 'error') {
963
+ return h('div', { className: 'dsoc-settings' }, [
964
+ h('p', { key: 'msg', className: 'dsoc-notice dsoc-notice--error' }, t('profile.loadFailed')),
965
+ h('button', { key: 'retry', type: 'button', className: 'dsoc-btn', onClick: () => void load() }, t('action.retry')),
966
+ ])
967
+ }
968
+
969
+ const update = (mutator) => {
970
+ setDraft(previous => {
971
+ if (previous === null) return previous
972
+ const next = cloneModel(previous)
973
+ mutator(next)
974
+ return next
975
+ })
976
+ setDirty(true)
977
+ setNotice(null)
978
+ }
979
+
980
+ const openPicker = (apply) => {
981
+ if (validationVaultId.length === 0) {
982
+ setNotice({ kind: 'error', text: t('profile.pickVaultFirst') })
983
+ return
984
+ }
985
+ setPicker({ folders: null, loading: true, apply })
986
+ callApi('vault.folders', { vaultId: validationVaultId })
987
+ .then(value => {
988
+ if (!alive.current) return
989
+ setPicker(previous => previous === null ? previous : ({ ...previous, folders: value.folders ?? [], loading: false }))
990
+ })
991
+ .catch(error => {
992
+ if (!alive.current) return
993
+ setPicker(null)
994
+ setNotice({ kind: 'error', text: error instanceof Error ? error.message : t('profile.loadFailed') })
995
+ })
996
+ }
997
+
998
+ const save = () => {
999
+ if (draft === null) return
1000
+ setPending(true)
1001
+ setNotice(null)
1002
+ callApi('profile.model.save', { model: draft })
1003
+ .then(value => {
1004
+ if (!alive.current) return
1005
+ if (value.saved === false) {
1006
+ setNotice({ kind: 'error', text: (value.errors ?? []).join(';') || t('profile.saveFailed') })
1007
+ return
1008
+ }
1009
+ setPayload(value)
1010
+ setDraft(value.model === null ? null : cloneModel(value.model))
1011
+ setDirty(false)
1012
+ setNotice({ kind: 'success', text: t('profile.saved') })
1013
+ })
1014
+ .catch(error => {
1015
+ if (!alive.current) return
1016
+ setNotice({ kind: 'error', text: error instanceof Error && error.message.length > 0 ? error.message : t('profile.saveFailed') })
1017
+ })
1018
+ .finally(() => { if (alive.current) setPending(false) })
1019
+ }
1020
+
1021
+ const saveSource = () => {
1022
+ setPending(true)
1023
+ setNotice(null)
1024
+ callApi('profile.set', { text: sourceText })
1025
+ .then(() => callApi('profile.model.get'))
1026
+ .then(value => {
1027
+ if (!alive.current) return
1028
+ setPayload(value)
1029
+ setDraft(value.model === null ? null : cloneModel(value.model))
1030
+ setDirty(false)
1031
+ setNotice({ kind: 'success', text: t('profile.sourceSaved') })
1032
+ })
1033
+ .catch(error => {
1034
+ if (!alive.current) return
1035
+ setNotice({ kind: 'error', text: error instanceof Error && error.message.length > 0 ? error.message : t('profile.saveFailed') })
1036
+ })
1037
+ .finally(() => { if (alive.current) setPending(false) })
1038
+ }
1039
+
1040
+ const toggleActiveNote = (enabled) => {
1041
+ const previous = settings.activeNote
1042
+ setSettings(value => ({ ...value, activeNote: enabled }))
1043
+ callApi('settings.set', { activeNote: enabled }).catch(() => {
1044
+ setSettings(value => ({ ...value, activeNote: previous }))
1045
+ setNotice({ kind: 'error', text: t('profile.activeNoteFailed') })
1046
+ })
1047
+ }
1048
+
1049
+ const runUpdate = () => {
1050
+ if (updatePending) return
1051
+ setUpdatePending(true)
1052
+ setNotice(null)
1053
+ let applying = false
1054
+ callApi('update.check')
1055
+ .then(info => {
1056
+ if (!alive.current) return null
1057
+ if (!info.supported) {
1058
+ setNotice({ kind: 'error', text: t('profile.updateUnsupported', { reason: info.reason ?? '' }) })
1059
+ return null
1060
+ }
1061
+ if (!info.updateAvailable) {
1062
+ setNotice({ kind: 'success', text: t('profile.updateLatest', { version: info.currentVersion }) })
1063
+ return null
1064
+ }
1065
+ if (!window.confirm(t('profile.updateConfirm', { latest: info.latestVersion }))) return null
1066
+ applying = true
1067
+ setNotice({ kind: 'success', text: t('profile.updateStarted', { version: info.latestVersion }) })
1068
+ return callApi('update.apply')
1069
+ })
1070
+ .then(result => {
1071
+ if (result === null || result === undefined || !alive.current) return
1072
+ setNotice({ kind: 'success', text: t('profile.updateStarted', { version: result.latestVersion ?? '' }) })
1073
+ setTimeout(() => { window.location.reload() }, 2500)
1074
+ })
1075
+ .catch(error => {
1076
+ if (!alive.current) return
1077
+ if (applying) {
1078
+ setNotice({ kind: 'error', text: t('profile.updateMayHaveStarted') })
1079
+ setTimeout(() => { window.location.reload() }, 5000)
1080
+ return
1081
+ }
1082
+ setNotice({ kind: 'error', text: error instanceof Error && error.message.length > 0 ? error.message : t('profile.updateFailed') })
1083
+ })
1084
+ .finally(() => { if (alive.current) setUpdatePending(false) })
1085
+ }
1086
+
1087
+ const toggleEnabled = (enabled) => {
1088
+ const previous = settings
1089
+ setSettings(value => ({ ...value, enabled }))
1090
+ callApi('settings.set', { enabled })
1091
+ .then(value => {
1092
+ if (!alive.current) return
1093
+ setSettings(value)
1094
+ setConnectorEnabled(value.enabled !== false)
1095
+ setNotice({
1096
+ kind: 'success',
1097
+ text: value.enabled === false ? t('profile.enabledOff') : t('profile.enabledOn'),
1098
+ })
1099
+ })
1100
+ .catch(error => {
1101
+ if (!alive.current) return
1102
+ setSettings(previous)
1103
+ setNotice({ kind: 'error', text: error instanceof Error && error.message.length > 0 ? error.message : t('profile.enabledFailed') })
1104
+ })
1105
+ }
1106
+
1107
+ const toggleSkill = (name, enabled) => {
1108
+ if (skillsPending.has(name)) return
1109
+ setSkillsPending(previous => new Set(previous).add(name))
1110
+ callApi('skills.setEnabled', { name, enabled })
1111
+ .then(value => {
1112
+ if (!alive.current) return
1113
+ setSkillsData(value)
1114
+ setNotice({ kind: 'success', text: t('profile.skills.saved') })
1115
+ })
1116
+ .catch(error => {
1117
+ if (!alive.current) return
1118
+ setNotice({ kind: 'error', text: error instanceof Error && error.message.length > 0 ? error.message : t('profile.skills.error') })
1119
+ })
1120
+ .finally(() => {
1121
+ if (!alive.current) return
1122
+ setSkillsPending(previous => {
1123
+ const next = new Set(previous)
1124
+ next.delete(name)
1125
+ return next
1126
+ })
1127
+ })
1128
+ }
1129
+
1130
+ const enterSource = () => {
1131
+ if (dirty && !window.confirm(t('profile.discardConfirm'))) return
1132
+ setDirty(false)
1133
+ setSourceMode(true)
1134
+ setSourceText(payload?.text ?? '')
1135
+ setNotice(null)
1136
+ }
1137
+
1138
+ const exitSource = () => {
1139
+ if (dirty && !window.confirm(t('profile.discardConfirm'))) return
1140
+ void load()
1141
+ setSourceMode(false)
1142
+ setNotice(null)
1143
+ }
1144
+
1145
+ const resetDefault = () => {
1146
+ if (!window.confirm(t('profile.resetConfirm'))) return
1147
+ setPending(true)
1148
+ callApi('profile.reset')
1149
+ .then(() => { setSourceMode(false); return load() })
1150
+ .then(() => { if (alive.current) setNotice({ kind: 'success', text: t('profile.restored') }) })
1151
+ .catch(() => { if (alive.current) setNotice({ kind: 'error', text: t('profile.saveFailed') }) })
1152
+ .finally(() => { if (alive.current) setPending(false) })
1153
+ }
1154
+
1155
+ const toolbar = h('div', { key: 'toolbar', className: 'dsoc-settings-toolbar' }, [
1156
+ h('span', { key: 'count', className: 'dsoc-muted' }, `${payload?.charCount ?? 0} / ${payload?.maxChars ?? 64000} ${t('profile.chars')}`),
1157
+ h('label', { key: 'enabled', className: 'dsoc-check dsoc-check--inline', title: t('profile.enabledTitle') }, [
1158
+ h('input', {
1159
+ type: 'checkbox',
1160
+ checked: settings.enabled !== false,
1161
+ onChange: event => toggleEnabled(event.target.checked),
1162
+ }),
1163
+ t('profile.enabled'),
1164
+ ]),
1165
+ h('label', { key: 'active', className: 'dsoc-check dsoc-check--inline' }, [
1166
+ h('input', {
1167
+ type: 'checkbox',
1168
+ checked: settings.activeNote !== false,
1169
+ onChange: event => toggleActiveNote(event.target.checked),
1170
+ }),
1171
+ t('profile.activeNote'),
1172
+ ]),
1173
+ h('select', {
1174
+ key: 'vault',
1175
+ className: 'dsoc-select dsoc-select--compact',
1176
+ value: validationVaultId,
1177
+ 'aria-label': t('profile.validationVault'),
1178
+ onChange: event => setValidationVaultId(event.target.value),
1179
+ }, [
1180
+ h('option', { key: 'none', value: '' }, t('profile.validationVaultNone')),
1181
+ ...vaults.filter(vault => vault.exists).map(vault => h('option', { key: vault.id, value: vault.id }, vault.label ?? vault.path)),
1182
+ ]),
1183
+ h('button', { key: 'update', type: 'button', className: 'dsoc-btn', disabled: Boolean(updatePending), title: t('profile.updateHint'), onClick: runUpdate }, updatePending ? t('profile.updating') : t('profile.update')),
1184
+ h('button', { key: 'source', type: 'button', className: 'dsoc-btn', onClick: sourceMode ? exitSource : enterSource }, sourceMode ? t('profile.formMode') : t('profile.sourceMode')),
1185
+ h('button', { key: 'reset', type: 'button', className: 'dsoc-btn', disabled: Boolean(pending), onClick: resetDefault }, t('profile.reset')),
1186
+ h('button', { key: 'save', type: 'button', className: 'dsoc-btn dsoc-btn--primary', disabled: Boolean(pending) || (!sourceMode && draft === null), onClick: sourceMode ? saveSource : save }, t('profile.save')),
1187
+ sourceMode && dirty ? h('span', { key: 'source-dirty', className: 'dsoc-tabs-status' }, t('profile.unsaved')) : null,
1188
+ ])
1189
+
1190
+ if (sourceMode) {
1191
+ return h('div', { className: 'dsoc-settings' }, [
1192
+ h('div', { key: 'sticky', className: 'dsoc-sticky' }, toolbar),
1193
+ payload?.error ? h('p', { key: 'parse', className: 'dsoc-notice dsoc-notice--error' }, `${t('profile.parseError')} ${payload.error}`) : null,
1194
+ notice !== null ? h('p', { key: 'notice', className: `dsoc-notice dsoc-notice--${notice.kind}` }, notice.text) : null,
1195
+ h('p', { key: 'hint', className: 'dsoc-field-help' }, t('profile.sourceHint')),
1196
+ h('textarea', {
1197
+ key: 'source',
1198
+ className: 'dsoc-textarea dsoc-textarea--source',
1199
+ value: sourceText,
1200
+ spellCheck: false,
1201
+ onChange: event => { setSourceText(event.target.value); setDirty(true) },
1202
+ }),
1203
+ ])
1204
+ }
1205
+
1206
+ if (draft === null) {
1207
+ return h('div', { className: 'dsoc-settings' }, [
1208
+ h('div', { key: 'sticky', className: 'dsoc-sticky' }, toolbar),
1209
+ h('p', { key: 'msg', className: 'dsoc-notice dsoc-notice--error' }, t('profile.parseError')),
1210
+ ])
1211
+ }
1212
+
1213
+ const tabButtons = h('div', { key: 'tabs', className: 'dsoc-tabbar' }, [
1214
+ h('div', { key: 'list', className: 'dsoc-tabs', role: 'tablist' }, TABS.map(name => h('button', {
1215
+ key: name,
1216
+ type: 'button',
1217
+ role: 'tab',
1218
+ 'aria-selected': tab === name ? 'true' : 'false',
1219
+ className: `dsoc-tab${tab === name ? ' dsoc-tab--active' : ''}`,
1220
+ onClick: () => setTab(name),
1221
+ }, t(`profile.tab.${name}`)))),
1222
+ dirty ? h('span', { key: 'dirty', className: 'dsoc-tabs-status' }, t('profile.unsaved')) : null,
1223
+ ])
1224
+
1225
+ const collectionCards = draft.collections.map((collection, index) => h(Card, {
1226
+ key: `collection-${index}`,
1227
+ title: collection.title || collection.id || t('profile.newCollection'),
1228
+ removeLabel: t('profile.remove'),
1229
+ onRemove: () => {
1230
+ if (!window.confirm(t('profile.deleteConfirm', { name: collection.title || collection.id }))) return
1231
+ update(next => { next.collections.splice(index, 1) })
1232
+ },
1233
+ }, [
1234
+ h('div', { key: 'grid', className: 'dsoc-grid' }, [
1235
+ h(TextField, { key: 'id', label: t('profile.field.id'), value: collection.id, onChange: value => update(next => { next.collections[index].id = value }) }),
1236
+ h(TextField, { key: 'title', label: t('profile.field.title'), value: collection.title, onChange: value => update(next => { next.collections[index].title = value }) }),
1237
+ ]),
1238
+ h(PathRows, {
1239
+ key: 'roots',
1240
+ t,
1241
+ label: t('profile.field.roots'),
1242
+ values: collection.roots,
1243
+ onChange: values => update(next => { next.collections[index].roots = values }),
1244
+ onPick: openPicker,
1245
+ }),
1246
+ h(TextField, {
1247
+ key: 'aliases',
1248
+ label: t('profile.field.aliases'),
1249
+ value: (collection.aliases ?? []).join(', '),
1250
+ placeholder: '日记, 日志, 每日笔记',
1251
+ help: t('profile.field.aliasesHelp'),
1252
+ onChange: value => update(next => { next.collections[index].aliases = value.split(/[,,]/).map(item => item.trim()).filter(Boolean) }),
1253
+ }),
1254
+ h(SelectField, {
1255
+ key: 'date-source',
1256
+ label: t('profile.field.dateSource'),
1257
+ value: collection.date?.source ?? '',
1258
+ onChange: value => update(next => { next.collections[index].date.source = value }),
1259
+ options: [
1260
+ { value: '', label: t('profile.date.none') },
1261
+ { value: 'filename', label: t('profile.date.filename') },
1262
+ { value: 'frontmatter', label: t('profile.date.frontmatter') },
1263
+ { value: 'mtime', label: t('profile.date.mtime') },
1264
+ ],
1265
+ }),
1266
+ collection.date?.source === 'filename' || collection.date?.source === 'frontmatter'
1267
+ ? h(TextField, {
1268
+ key: 'date-format',
1269
+ label: t('profile.field.dateFormat'),
1270
+ value: collection.date.format,
1271
+ placeholder: 'YYYY-MM-DD',
1272
+ onChange: value => update(next => { next.collections[index].date.format = value }),
1273
+ })
1274
+ : null,
1275
+ collection.date?.source === 'frontmatter'
1276
+ ? h(TextField, {
1277
+ key: 'date-property',
1278
+ label: t('profile.field.dateProperty'),
1279
+ value: collection.date.property,
1280
+ placeholder: 'data',
1281
+ onChange: value => update(next => { next.collections[index].date.property = value }),
1282
+ })
1283
+ : null,
1284
+ ]))
1285
+
1286
+ const scopeCards = draft.scopes.map((scope, index) => h(Card, {
1287
+ key: `scope-${index}`,
1288
+ title: `${t('profile.field.scope')} ${index + 1}`,
1289
+ removeLabel: t('profile.remove'),
1290
+ onRemove: () => {
1291
+ if (!window.confirm(t('profile.deleteConfirm', { name: `${t('profile.field.scope')} ${index + 1}` }))) return
1292
+ update(next => { next.scopes.splice(index, 1) })
1293
+ },
1294
+ }, [
1295
+ h(PathRows, {
1296
+ key: 'paths',
1297
+ t,
1298
+ label: t('profile.field.paths'),
1299
+ values: scope.paths,
1300
+ allowGlob: true,
1301
+ placeholder: 'Documents/Dailynote/**',
1302
+ onChange: values => update(next => { next.scopes[index].paths = values }),
1303
+ onPick: openPicker,
1304
+ }),
1305
+ h('label', { key: 'rules', className: 'dsoc-field' }, [
1306
+ h('span', { key: 'label', className: 'dsoc-field-label' }, t('profile.field.rules')),
1307
+ h('textarea', {
1308
+ className: 'dsoc-textarea',
1309
+ rows: 5,
1310
+ value: scope.rules ?? '',
1311
+ onChange: event => update(next => { next.scopes[index].rules = event.target.value }),
1312
+ }),
1313
+ ]),
1314
+ ]))
1315
+
1316
+ const templateCards = draft.templates.map((template, index) => h(Card, {
1317
+ key: `template-${index}`,
1318
+ title: template.title || template.id || t('profile.newTemplate'),
1319
+ removeLabel: t('profile.remove'),
1320
+ onRemove: () => {
1321
+ if (!window.confirm(t('profile.deleteConfirm', { name: template.title || template.id }))) return
1322
+ update(next => { next.templates.splice(index, 1) })
1323
+ },
1324
+ }, [
1325
+ h('div', { key: 'grid', className: 'dsoc-grid' }, [
1326
+ h(TextField, { key: 'id', label: t('profile.field.id'), value: template.id, onChange: value => update(next => { next.templates[index].id = value }) }),
1327
+ h(TextField, { key: 'title', label: t('profile.field.title'), value: template.title, onChange: value => update(next => { next.templates[index].title = value }) }),
1328
+ ]),
1329
+ h(SinglePathField, {
1330
+ key: 'path',
1331
+ t,
1332
+ label: t('profile.field.templatePath'),
1333
+ value: template.path,
1334
+ onChange: value => update(next => { next.templates[index].path = value }),
1335
+ onPick: openPicker,
1336
+ }),
1337
+ h(TextField, {
1338
+ key: 'aliases',
1339
+ label: t('profile.field.aliases'),
1340
+ value: (template.aliases ?? []).join(', '),
1341
+ onChange: value => update(next => { next.templates[index].aliases = value.split(/[,,]/).map(item => item.trim()).filter(Boolean) }),
1342
+ }),
1343
+ ]))
1344
+
1345
+ const creation = draft.creation ?? {}
1346
+ const defaultTemplate = draft.templates.find(template => template.id === creation.defaultTemplate)
1347
+ const templateFolder = defaultTemplate?.path
1348
+ ? (defaultTemplate.path.includes('/') ? defaultTemplate.path.split('/').slice(0, -1).join('/') : t('profile.vaultRoot'))
1349
+ : ''
1350
+ const creationSummary = h('div', { className: 'dsoc-creation-summary' }, [
1351
+ h('div', { key: 'binding' }, t('profile.creation.binding', {
1352
+ folder: creation.defaultFolder || t('profile.creation.notSet'),
1353
+ template: defaultTemplate?.title || t('profile.creation.notSet'),
1354
+ })),
1355
+ h('div', { key: 'path' }, `${t('profile.creation.templatePath')}: ${defaultTemplate?.path || t('profile.creation.notSet')}`),
1356
+ h('div', { key: 'folder' }, `${t('profile.creation.templateFolder')}: ${templateFolder || t('profile.creation.notSet')}`),
1357
+ ])
1358
+ const creationForm = h('div', { className: 'dsoc-grid' }, [
1359
+ h(SinglePathField, {
1360
+ key: 'default-folder',
1361
+ t,
1362
+ label: t('profile.field.defaultFolder'),
1363
+ value: creation.defaultFolder,
1364
+ onChange: value => update(next => { next.creation.defaultFolder = value }),
1365
+ onPick: openPicker,
1366
+ }),
1367
+ h(SinglePathField, {
1368
+ key: 'image-folder',
1369
+ t,
1370
+ label: t('profile.field.imageFolder'),
1371
+ value: creation.imageFolder,
1372
+ onChange: value => update(next => { next.creation.imageFolder = value }),
1373
+ onPick: openPicker,
1374
+ }),
1375
+ h(SelectField, {
1376
+ key: 'default-template',
1377
+ label: t('profile.field.defaultTemplate'),
1378
+ value: creation.defaultTemplate,
1379
+ onChange: value => update(next => { next.creation.defaultTemplate = value }),
1380
+ options: [
1381
+ { value: '', label: t('profile.field.collectionNone') },
1382
+ ...draft.templates.map(template => ({ value: template.id, label: `${template.title || template.id} — ${template.path}` })),
1383
+ ],
1384
+ }),
1385
+ ])
1386
+
1387
+ const bodyCards = draft.body.map((section, index) => h(Card, {
1388
+ key: `body-${index}`,
1389
+ title: section.heading || t('profile.newSection'),
1390
+ removeLabel: t('profile.remove'),
1391
+ onRemove: () => {
1392
+ if (!window.confirm(t('profile.deleteConfirm', { name: section.heading || t('profile.newSection') }))) return
1393
+ update(next => { next.body.splice(index, 1) })
1394
+ },
1395
+ }, [
1396
+ h('div', { key: 'head', className: 'dsoc-row-line' }, [
1397
+ h('input', {
1398
+ key: 'heading',
1399
+ className: 'dsoc-input',
1400
+ value: section.heading,
1401
+ placeholder: t('profile.field.heading'),
1402
+ onChange: event => update(next => { next.body[index].heading = event.target.value }),
1403
+ }),
1404
+ h('button', {
1405
+ key: 'up',
1406
+ type: 'button',
1407
+ className: 'dsoc-btn dsoc-btn--small',
1408
+ disabled: index === 0,
1409
+ onClick: () => update(next => {
1410
+ const previous = next.body[index - 1]
1411
+ next.body[index - 1] = next.body[index]
1412
+ next.body[index] = previous
1413
+ }),
1414
+ }, '↑'),
1415
+ h('button', {
1416
+ key: 'down',
1417
+ type: 'button',
1418
+ className: 'dsoc-btn dsoc-btn--small',
1419
+ disabled: index === draft.body.length - 1,
1420
+ onClick: () => update(next => {
1421
+ const following = next.body[index + 1]
1422
+ next.body[index + 1] = next.body[index]
1423
+ next.body[index] = following
1424
+ }),
1425
+ }, '↓'),
1426
+ ]),
1427
+ h('textarea', {
1428
+ key: 'content',
1429
+ className: 'dsoc-textarea dsoc-textarea--body',
1430
+ value: section.content,
1431
+ onChange: event => update(next => { next.body[index].content = event.target.value }),
1432
+ }),
1433
+ ]))
1434
+
1435
+ const skillCards = (skillsData?.skills ?? []).map(skill => h(Card, {
1436
+ key: `skill-${skill.name}`,
1437
+ title: skill.name,
1438
+ }, [
1439
+ h('div', { key: 'meta', className: 'dsoc-skill-meta' }, [
1440
+ h('span', { key: 'source', className: 'dsoc-badge' }, t('profile.skills.builtin')),
1441
+ h('span', { key: 'state', className: 'dsoc-muted' }, skill.enabled ? t('profile.skills.enabled') : t('profile.skills.disabled')),
1442
+ ]),
1443
+ h('p', { key: 'description', className: 'dsoc-skill-desc', title: skill.description }, skill.description),
1444
+ h('label', { key: 'toggle', className: 'dsoc-check dsoc-check--inline' }, [
1445
+ h('input', {
1446
+ type: 'checkbox',
1447
+ checked: skill.enabled,
1448
+ disabled: skillsPending.has(skill.name),
1449
+ onChange: event => toggleSkill(skill.name, event.target.checked),
1450
+ }),
1451
+ t('profile.skills.toggle'),
1452
+ ]),
1453
+ ]))
1454
+
1455
+ let content
1456
+ if (tab === 'collections') {
1457
+ content = [
1458
+ h('div', { key: 'grid', className: 'dsoc-card-grid' }, collectionCards),
1459
+ h('button', { key: 'add', type: 'button', className: 'dsoc-add', onClick: () => update(next => { next.collections.push({ id: '', title: '', roots: [''], aliases: [], date: { source: '', format: '', property: '' } }) }) }, `+ ${t('profile.addCollection')}`),
1460
+ ]
1461
+ } else if (tab === 'scopes') {
1462
+ content = [
1463
+ h('div', { key: 'grid', className: 'dsoc-card-grid' }, scopeCards),
1464
+ h('button', { key: 'add', type: 'button', className: 'dsoc-add', onClick: () => update(next => { next.scopes.push({ paths: [''], rules: '' }) }) }, `+ ${t('profile.addScope')}`),
1465
+ ]
1466
+ } else if (tab === 'templates') {
1467
+ content = [
1468
+ h('div', { key: 'grid', className: 'dsoc-card-grid' }, templateCards),
1469
+ h('button', { key: 'add', type: 'button', className: 'dsoc-add', onClick: () => update(next => { next.templates.push({ id: '', title: '', path: '', aliases: [] }) }) }, `+ ${t('profile.addTemplate')}`),
1470
+ ]
1471
+ } else if (tab === 'creation') {
1472
+ content = [h(Card, { key: 'creation', title: t('profile.tab.creation') }, [creationForm, creationSummary])]
1473
+ } else if (tab === 'body') {
1474
+ content = [
1475
+ h('div', { key: 'list', className: 'dsoc-card-list' }, bodyCards),
1476
+ h('button', { key: 'add', type: 'button', className: 'dsoc-add', onClick: () => update(next => { next.body.push({ heading: '', content: '' }) }) }, `+ ${t('profile.addSection')}`),
1477
+ ]
1478
+ } else if (tab === 'skills') {
1479
+ content = skillsError
1480
+ ? [h('p', { key: 'error', className: 'dsoc-notice dsoc-notice--error' }, t('profile.skills.error'))]
1481
+ : [
1482
+ h('p', { key: 'note', className: 'dsoc-field-help' }, t('profile.skills.note')),
1483
+ h('p', { key: 'summary', className: 'dsoc-skill-summary' }, t('profile.skills.summary', {
1484
+ enabled: skillsData?.enabledCount ?? 0,
1485
+ total: skillsData?.total ?? 7,
1486
+ })),
1487
+ h('div', { key: 'grid', className: 'dsoc-card-grid' }, skillCards),
1488
+ ]
1489
+ } else {
1490
+ content = [
1491
+ h('p', { key: 'hint', className: 'dsoc-field-help' }, t('profile.advancedHint')),
1492
+ ...(payload?.warnings ?? []).map((warning, index) => h('p', { key: `warning-${index}`, className: 'dsoc-muted' }, warning)),
1493
+ h('button', { key: 'source', type: 'button', className: 'dsoc-btn', onClick: enterSource }, t('profile.sourceMode')),
1494
+ ]
1495
+ }
1496
+
1497
+ return h('div', { className: 'dsoc-settings' }, [
1498
+ h('div', { key: 'sticky', className: 'dsoc-sticky' }, [toolbar, tabButtons]),
1499
+ notice !== null ? h('p', { key: 'notice', className: `dsoc-notice dsoc-notice--${notice.kind}` }, notice.text) : null,
1500
+ h('div', { key: 'content', className: 'dsoc-settings-content', role: 'tabpanel' }, content),
1501
+ picker !== null ? h(FolderPickerModal, {
1502
+ key: 'picker',
1503
+ t,
1504
+ picker,
1505
+ onChoose: path => {
1506
+ picker.apply(path)
1507
+ setPicker(null)
1508
+ },
1509
+ onClose: () => setPicker(null),
1510
+ }) : null,
1511
+ ])
1512
+ }
1513
+
1514
+ function ObsidianPanelIcon({ size = 18 }) {
1515
+ return h(ObsidianLogo, { size })
1516
+ }
1517
+
1518
+ function ConnectorMainPanel({ t }) {
1519
+ return h('div', { className: 'dsoc-main-panel' }, [
1520
+ h('div', { key: 'head', className: 'dsoc-main-head' }, [
1521
+ h(ObsidianLogo, { key: 'logo', size: 20 }),
1522
+ h('span', { key: 'title', className: 'dsoc-main-title' }, t('side.title')),
1523
+ ]),
1524
+ h(ProfileSettings, { key: 'settings', t, view: 'page' }),
1525
+ ])
1526
+ }
1527
+
1528
+ return {
1529
+ inject: ['slots', 'locale'],
1530
+ apply(ctx) {
1531
+ ctx.effect(() => {
1532
+ const element = document.createElement('style')
1533
+ element.setAttribute('data-dsh-plugin', 'modularob-connectors')
1534
+ element.textContent = CSS
1535
+ document.head.appendChild(element)
1536
+ return () => element.remove()
1537
+ }, 'modularob-connectors: styles')
1538
+
1539
+ ctx.effect(() => ctx.locale.register(NS, { en, zh }), 'modularob-connectors: locale')
1540
+ const translate = ctx.locale.bind(NS)
1541
+ const MainPanel = (props) => h(ConnectorMainPanel, { t: props.t ?? translate })
1542
+
1543
+ ctx.slots.inject('conversation.input.model.options', () => ctx.slots.register({
1544
+ name: 'conversation.input.model.options',
1545
+ id: 'modularob-vault',
1546
+ // Above the built-in agent-team row, directly under 推理等级.
1547
+ order: -10,
1548
+ locale: NS,
1549
+ }, VaultMenuRow))
1550
+
1551
+ ctx.slots.inject('conversation.input.model.label', () => ctx.slots.register({
1552
+ name: 'conversation.input.model.label',
1553
+ }, ModelLabel))
1554
+
1555
+ ctx.slots.inject('plugins.row.config', () => ctx.slots.register({
1556
+ name: 'plugins.row.config',
1557
+ key: 'modularob-connectors#modularob-connectors',
1558
+ locale: NS,
1559
+ }, ProfileSettings))
1560
+
1561
+ ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
1562
+ name: 'sidebar.panellist',
1563
+ id: 'modularob',
1564
+ order: 20,
1565
+ label: () => translate('side.label'),
1566
+ locale: NS,
1567
+ }, ObsidianPanelIcon))
1568
+
1569
+ ctx.slots.inject('main', () => ctx.slots.register({
1570
+ name: 'main',
1571
+ key: 'modularob',
1572
+ locale: NS,
1573
+ }, MainPanel))
1574
+ },
1575
+ }
1576
+ },
1577
+ })