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.
- package/LICENSE +21 -0
- package/README.md +217 -2
- package/README.zh.md +218 -0
- package/client.js +1577 -0
- package/cordis.patch.yml +3 -0
- package/docs/PUBLISHING.md +53 -0
- package/icon.svg +8 -0
- package/index.js +135 -0
- package/lib/api.js +194 -0
- package/lib/cli.js +144 -0
- package/lib/obsidian.js +735 -0
- package/lib/profile-model.js +305 -0
- package/lib/profile.js +131 -0
- package/lib/skills.js +273 -0
- package/lib/tool.js +122 -0
- package/lib/update.js +268 -0
- package/lib/vendor/yaml/LICENSE +13 -0
- package/lib/vendor/yaml/dist/cli.d.ts +8 -0
- package/lib/vendor/yaml/dist/cli.mjs +201 -0
- package/lib/vendor/yaml/dist/compose/compose-collection.d.ts +11 -0
- package/lib/vendor/yaml/dist/compose/compose-collection.js +90 -0
- package/lib/vendor/yaml/dist/compose/compose-doc.d.ts +7 -0
- package/lib/vendor/yaml/dist/compose/compose-doc.js +45 -0
- package/lib/vendor/yaml/dist/compose/compose-node.d.ts +29 -0
- package/lib/vendor/yaml/dist/compose/compose-node.js +112 -0
- package/lib/vendor/yaml/dist/compose/compose-scalar.d.ts +5 -0
- package/lib/vendor/yaml/dist/compose/compose-scalar.js +88 -0
- package/lib/vendor/yaml/dist/compose/composer.d.ts +63 -0
- package/lib/vendor/yaml/dist/compose/composer.js +224 -0
- package/lib/vendor/yaml/dist/compose/resolve-block-map.d.ts +6 -0
- package/lib/vendor/yaml/dist/compose/resolve-block-map.js +117 -0
- package/lib/vendor/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
- package/lib/vendor/yaml/dist/compose/resolve-block-scalar.js +200 -0
- package/lib/vendor/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
- package/lib/vendor/yaml/dist/compose/resolve-block-seq.js +51 -0
- package/lib/vendor/yaml/dist/compose/resolve-end.d.ts +6 -0
- package/lib/vendor/yaml/dist/compose/resolve-end.js +39 -0
- package/lib/vendor/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
- package/lib/vendor/yaml/dist/compose/resolve-flow-collection.js +209 -0
- package/lib/vendor/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
- package/lib/vendor/yaml/dist/compose/resolve-flow-scalar.js +228 -0
- package/lib/vendor/yaml/dist/compose/resolve-props.d.ts +23 -0
- package/lib/vendor/yaml/dist/compose/resolve-props.js +148 -0
- package/lib/vendor/yaml/dist/compose/util-contains-newline.d.ts +2 -0
- package/lib/vendor/yaml/dist/compose/util-contains-newline.js +36 -0
- package/lib/vendor/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
- package/lib/vendor/yaml/dist/compose/util-empty-scalar-position.js +28 -0
- package/lib/vendor/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
- package/lib/vendor/yaml/dist/compose/util-flow-indent-check.js +17 -0
- package/lib/vendor/yaml/dist/compose/util-map-includes.d.ts +4 -0
- package/lib/vendor/yaml/dist/compose/util-map-includes.js +15 -0
- package/lib/vendor/yaml/dist/doc/Document.d.ts +141 -0
- package/lib/vendor/yaml/dist/doc/Document.js +337 -0
- package/lib/vendor/yaml/dist/doc/anchors.d.ts +24 -0
- package/lib/vendor/yaml/dist/doc/anchors.js +76 -0
- package/lib/vendor/yaml/dist/doc/applyReviver.d.ts +9 -0
- package/lib/vendor/yaml/dist/doc/applyReviver.js +57 -0
- package/lib/vendor/yaml/dist/doc/createNode.d.ts +17 -0
- package/lib/vendor/yaml/dist/doc/createNode.js +90 -0
- package/lib/vendor/yaml/dist/doc/directives.d.ts +49 -0
- package/lib/vendor/yaml/dist/doc/directives.js +178 -0
- package/lib/vendor/yaml/dist/errors.d.ts +21 -0
- package/lib/vendor/yaml/dist/errors.js +62 -0
- package/lib/vendor/yaml/dist/index.d.ts +25 -0
- package/lib/vendor/yaml/dist/index.js +50 -0
- package/lib/vendor/yaml/dist/log.d.ts +3 -0
- package/lib/vendor/yaml/dist/log.js +19 -0
- package/lib/vendor/yaml/dist/nodes/Alias.d.ts +29 -0
- package/lib/vendor/yaml/dist/nodes/Alias.js +120 -0
- package/lib/vendor/yaml/dist/nodes/Collection.d.ts +73 -0
- package/lib/vendor/yaml/dist/nodes/Collection.js +151 -0
- package/lib/vendor/yaml/dist/nodes/Node.d.ts +53 -0
- package/lib/vendor/yaml/dist/nodes/Node.js +40 -0
- package/lib/vendor/yaml/dist/nodes/Pair.d.ts +22 -0
- package/lib/vendor/yaml/dist/nodes/Pair.js +39 -0
- package/lib/vendor/yaml/dist/nodes/Scalar.d.ts +47 -0
- package/lib/vendor/yaml/dist/nodes/Scalar.js +27 -0
- package/lib/vendor/yaml/dist/nodes/YAMLMap.d.ts +53 -0
- package/lib/vendor/yaml/dist/nodes/YAMLMap.js +147 -0
- package/lib/vendor/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
- package/lib/vendor/yaml/dist/nodes/YAMLSeq.js +115 -0
- package/lib/vendor/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
- package/lib/vendor/yaml/dist/nodes/addPairToJSMap.js +65 -0
- package/lib/vendor/yaml/dist/nodes/identity.d.ts +23 -0
- package/lib/vendor/yaml/dist/nodes/identity.js +53 -0
- package/lib/vendor/yaml/dist/nodes/toJS.d.ts +29 -0
- package/lib/vendor/yaml/dist/nodes/toJS.js +39 -0
- package/lib/vendor/yaml/dist/options.d.ts +350 -0
- package/lib/vendor/yaml/dist/parse/cst-scalar.d.ts +64 -0
- package/lib/vendor/yaml/dist/parse/cst-scalar.js +218 -0
- package/lib/vendor/yaml/dist/parse/cst-stringify.d.ts +8 -0
- package/lib/vendor/yaml/dist/parse/cst-stringify.js +63 -0
- package/lib/vendor/yaml/dist/parse/cst-visit.d.ts +39 -0
- package/lib/vendor/yaml/dist/parse/cst-visit.js +99 -0
- package/lib/vendor/yaml/dist/parse/cst.d.ts +109 -0
- package/lib/vendor/yaml/dist/parse/cst.js +112 -0
- package/lib/vendor/yaml/dist/parse/lexer.d.ts +87 -0
- package/lib/vendor/yaml/dist/parse/lexer.js +723 -0
- package/lib/vendor/yaml/dist/parse/line-counter.d.ts +22 -0
- package/lib/vendor/yaml/dist/parse/line-counter.js +41 -0
- package/lib/vendor/yaml/dist/parse/parser.d.ts +84 -0
- package/lib/vendor/yaml/dist/parse/parser.js +980 -0
- package/lib/vendor/yaml/dist/public-api.d.ts +44 -0
- package/lib/vendor/yaml/dist/public-api.js +107 -0
- package/lib/vendor/yaml/dist/schema/Schema.d.ts +17 -0
- package/lib/vendor/yaml/dist/schema/Schema.js +39 -0
- package/lib/vendor/yaml/dist/schema/common/map.d.ts +2 -0
- package/lib/vendor/yaml/dist/schema/common/map.js +19 -0
- package/lib/vendor/yaml/dist/schema/common/null.d.ts +4 -0
- package/lib/vendor/yaml/dist/schema/common/null.js +17 -0
- package/lib/vendor/yaml/dist/schema/common/seq.d.ts +2 -0
- package/lib/vendor/yaml/dist/schema/common/seq.js +19 -0
- package/lib/vendor/yaml/dist/schema/common/string.d.ts +2 -0
- package/lib/vendor/yaml/dist/schema/common/string.js +16 -0
- package/lib/vendor/yaml/dist/schema/core/bool.d.ts +4 -0
- package/lib/vendor/yaml/dist/schema/core/bool.js +21 -0
- package/lib/vendor/yaml/dist/schema/core/float.d.ts +4 -0
- package/lib/vendor/yaml/dist/schema/core/float.js +47 -0
- package/lib/vendor/yaml/dist/schema/core/int.d.ts +4 -0
- package/lib/vendor/yaml/dist/schema/core/int.js +42 -0
- package/lib/vendor/yaml/dist/schema/core/schema.d.ts +1 -0
- package/lib/vendor/yaml/dist/schema/core/schema.js +25 -0
- package/lib/vendor/yaml/dist/schema/json/schema.d.ts +2 -0
- package/lib/vendor/yaml/dist/schema/json/schema.js +64 -0
- package/lib/vendor/yaml/dist/schema/json-schema.d.ts +69 -0
- package/lib/vendor/yaml/dist/schema/tags.d.ts +48 -0
- package/lib/vendor/yaml/dist/schema/tags.js +99 -0
- package/lib/vendor/yaml/dist/schema/types.d.ts +92 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/binary.js +70 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/bool.js +29 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/float.js +50 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/int.js +76 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/merge.js +71 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/omap.d.ts +22 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/omap.js +77 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/schema.js +41 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/set.js +96 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
- package/lib/vendor/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
- package/lib/vendor/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
- package/lib/vendor/yaml/dist/stringify/foldFlowLines.js +151 -0
- package/lib/vendor/yaml/dist/stringify/stringify.d.ts +21 -0
- package/lib/vendor/yaml/dist/stringify/stringify.js +132 -0
- package/lib/vendor/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
- package/lib/vendor/yaml/dist/stringify/stringifyCollection.js +155 -0
- package/lib/vendor/yaml/dist/stringify/stringifyComment.d.ts +10 -0
- package/lib/vendor/yaml/dist/stringify/stringifyComment.js +24 -0
- package/lib/vendor/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
- package/lib/vendor/yaml/dist/stringify/stringifyDocument.js +87 -0
- package/lib/vendor/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
- package/lib/vendor/yaml/dist/stringify/stringifyNumber.js +27 -0
- package/lib/vendor/yaml/dist/stringify/stringifyPair.d.ts +3 -0
- package/lib/vendor/yaml/dist/stringify/stringifyPair.js +152 -0
- package/lib/vendor/yaml/dist/stringify/stringifyString.d.ts +9 -0
- package/lib/vendor/yaml/dist/stringify/stringifyString.js +338 -0
- package/lib/vendor/yaml/dist/test-events.d.ts +4 -0
- package/lib/vendor/yaml/dist/test-events.js +134 -0
- package/lib/vendor/yaml/dist/util.d.ts +16 -0
- package/lib/vendor/yaml/dist/util.js +28 -0
- package/lib/vendor/yaml/dist/visit.d.ts +102 -0
- package/lib/vendor/yaml/dist/visit.js +236 -0
- package/lib/vendor/yaml/package.json +97 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +62 -4
- package/profile/VAULT.md +221 -0
- package/skills/LICENSE +21 -0
- package/skills/defuddle/SKILL.md +43 -0
- package/skills/json-canvas/SKILL.md +253 -0
- package/skills/json-canvas/references/EXAMPLES.md +329 -0
- package/skills/knap/SKILL.md +102 -0
- package/skills/obsidian-bases/SKILL.md +601 -0
- package/skills/obsidian-bases/references/FUNCTIONS_REFERENCE.md +173 -0
- package/skills/obsidian-cli/SKILL.md +141 -0
- package/skills/obsidian-headless/SKILL.md +79 -0
- package/skills/obsidian-markdown/SKILL.md +202 -0
- package/skills/obsidian-markdown/references/CALLOUTS.md +58 -0
- package/skills/obsidian-markdown/references/EMBEDS.md +70 -0
- package/skills/obsidian-markdown/references/PROPERTIES.md +63 -0
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Packaging and distribution
|
|
2
|
+
|
|
3
|
+
`modularob-connectors` is a public ESM DSH bundle with vendored YAML, no runtime dependencies and no install/prepare scripts. Keep its name consistent in package.json, cordis.patch.yml, the client module factory and plugin row key.
|
|
4
|
+
|
|
5
|
+
## Validate and publish
|
|
6
|
+
|
|
7
|
+
Run from the repository root:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm test
|
|
11
|
+
npm pack --cache /tmp/modularob-npm-cache --pack-destination /tmp
|
|
12
|
+
npm publish /tmp/modularob-connectors-0.6.7.tgz --access public --registry=https://registry.npmjs.org/
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Publishing requires an npm account authorized for this package (`npm login --registry=https://registry.npmjs.org/`). Never publish to a mirror. Confirm the official registry serves the intended version before announcing npm installation; mirrors may sync later.
|
|
16
|
+
|
|
17
|
+
Commit the tested files, then create the tag on that exact commit. Verify both the tag manifest and packed manifest have the same name/version before pushing:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
git show HEAD:package.json
|
|
21
|
+
git tag -a v0.6.7 -m 'Release 0.6.7'
|
|
22
|
+
git show v0.6.7:package.json
|
|
23
|
+
git push origin main refs/tags/v0.6.7
|
|
24
|
+
gh release create v0.6.7 /tmp/modularob-connectors-0.6.7.tgz --verify-tag --title v0.6.7 --notes-file /tmp/modularob-release-notes.md
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Historical tags v0.6.5 and v0.6.6 were one commit behind their corresponding package versions. `sh fix-tags.sh --check` checks the known local manifests and remote commit targets; `--apply` repairs only those two tags using leases against their observed remote objects, then re-reads the remote. It never deletes releases. Historical assets should be verified separately.
|
|
28
|
+
|
|
29
|
+
## CLI Commander integration
|
|
30
|
+
|
|
31
|
+
Maintain installer source here instead of editing Base64 by hand:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
node scripts/patch-cli-commander.mjs /path/to/vault/.obsidian/plugins/cli-commander /tmp/modularob-connectors-0.6.7.tgz
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
This backs up main.js, embeds both platform scripts, copies the tarball and embeds its SHA256 validation. Ship main.js and the tarball together. It does not alter data.json. Reload CLI Commander after applying.
|
|
38
|
+
|
|
39
|
+
The scripts install the bundled connector with no network. Without the tarball environment variable they try the exact npm version on npmmirror, then npm official. Registry settings and retry timeouts are process-local. They install the replacement before removing the legacy package; failed installation stops before starting DSH Web. No blanket `pnpm approve --all` is needed.
|
|
40
|
+
|
|
41
|
+
## Verify a clean installation
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
dsh plugin --profile web add modularob-connectors@0.6.7 --registry=https://registry.npmmirror.com/
|
|
45
|
+
# If the mirror is stale:
|
|
46
|
+
dsh plugin --profile web add modularob-connectors@0.6.7 --registry=https://registry.npmjs.org/
|
|
47
|
+
# Offline connector install, with DSH and pnpm already available:
|
|
48
|
+
dsh plugin --profile web add /absolute/path/modularob-connectors-0.6.7.tgz
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Restart DSH Web, confirm the connector row and vault picker load. For isolated validation, set HOME/DSH_HOME to a temporary directory rather than modifying a real profile.
|
|
52
|
+
|
|
53
|
+
Keep skills/LICENSE and the MIT license. The package must contain the vendored YAML distribution, client.js, index.js, lib, skills and references, locale, icon, cordis.patch.yml and profile/VAULT.md. Review the bundled default profile before release.
|
package/icon.svg
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" height="36" viewBox="0 0 36 36" width="36">
|
|
2
|
+
<g transform="translate(7 6)">
|
|
3
|
+
<path fill="#A88BFA" d="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"/>
|
|
4
|
+
<path fill="#A88BFA" d="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"/>
|
|
5
|
+
<path fill="#A88BFA" d="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"/>
|
|
6
|
+
<path fill="#A88BFA" d="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"/>
|
|
7
|
+
</g>
|
|
8
|
+
</svg>
|
package/index.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host half of the Obsidian connector.
|
|
3
|
+
*
|
|
4
|
+
* It discovers Obsidian vaults, stores the vault each conversation selects,
|
|
5
|
+
* registers the official connector skills, and exposes the one vault file tool
|
|
6
|
+
* plus the composer picker's authenticated API.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import path from 'node:path'
|
|
10
|
+
import { registerVaultApi } from './lib/api.js'
|
|
11
|
+
import { createObsidianService } from './lib/obsidian.js'
|
|
12
|
+
import { createProfileStore } from './lib/profile.js'
|
|
13
|
+
import { createSkillManager } from './lib/skills.js'
|
|
14
|
+
import { createUpdater } from './lib/update.js'
|
|
15
|
+
import { registerObsidianFileTool } from './lib/tool.js'
|
|
16
|
+
|
|
17
|
+
/** Bundle row id. */
|
|
18
|
+
export const name = 'modularob-connectors'
|
|
19
|
+
|
|
20
|
+
/** The vault file tool is the connector's model-facing surface. */
|
|
21
|
+
export const inject = ['tools']
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {import('@deepseek-ai/cordis').Context} ctx
|
|
25
|
+
* @param {unknown} config
|
|
26
|
+
*/
|
|
27
|
+
export function apply(ctx, config) {
|
|
28
|
+
const obsidian = createObsidianService(config)
|
|
29
|
+
const profile = createProfileStore()
|
|
30
|
+
const skillManager = createSkillManager(ctx, {
|
|
31
|
+
stateFile: path.join(path.dirname(obsidian.stateFile), 'skills.json'),
|
|
32
|
+
})
|
|
33
|
+
const updater = createUpdater({
|
|
34
|
+
getPluginManager: () => ctx.get('pluginManager'),
|
|
35
|
+
stateDir: path.dirname(obsidian.stateFile),
|
|
36
|
+
logger: ctx.logger,
|
|
37
|
+
})
|
|
38
|
+
// Active-note snapshots, refreshed once at the start of each turn.
|
|
39
|
+
const activeNotes = new Map()
|
|
40
|
+
let toolDispose = null
|
|
41
|
+
|
|
42
|
+
const syncTool = () => {
|
|
43
|
+
const enabled = obsidian.getPreferences().enabled
|
|
44
|
+
if (enabled && toolDispose === null) {
|
|
45
|
+
try {
|
|
46
|
+
toolDispose = registerObsidianFileTool(ctx, obsidian)
|
|
47
|
+
} catch (error) {
|
|
48
|
+
ctx.logger?.warn?.(`modularob-connectors: could not register the vault file tool: ${error instanceof Error ? error.message : String(error)}`)
|
|
49
|
+
}
|
|
50
|
+
} else if (!enabled && toolDispose !== null) {
|
|
51
|
+
toolDispose()
|
|
52
|
+
toolDispose = null
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
syncTool()
|
|
56
|
+
ctx.effect(() => () => {
|
|
57
|
+
if (toolDispose !== null) {
|
|
58
|
+
toolDispose()
|
|
59
|
+
toolDispose = null
|
|
60
|
+
}
|
|
61
|
+
}, 'modularob-connectors: vault file tool')
|
|
62
|
+
|
|
63
|
+
ctx.inject(['skills'], (skillCtx) => {
|
|
64
|
+
if (obsidian.getPreferences().enabled) skillManager.attach(skillCtx)
|
|
65
|
+
else skillManager.setSuspended(true)
|
|
66
|
+
ctx.effect(() => () => skillManager.dispose(), 'modularob-connectors: skills')
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
ctx.effect(() => obsidian.onPreferences(() => {
|
|
70
|
+
syncTool()
|
|
71
|
+
skillManager.setSuspended(!obsidian.getPreferences().enabled)
|
|
72
|
+
}), 'modularob-connectors: master switch')
|
|
73
|
+
|
|
74
|
+
ctx.inject(['systemPrompt'], (promptCtx) => {
|
|
75
|
+
promptCtx.effect(() => promptCtx.systemPrompt.context({
|
|
76
|
+
name: 'obsidian-vault',
|
|
77
|
+
order: 60,
|
|
78
|
+
// Vault names and paths are literal data, never prompt templates.
|
|
79
|
+
interpolate: false,
|
|
80
|
+
// Empty when the conversation has no explicit vault choice, so sessions
|
|
81
|
+
// that never use Obsidian stay untouched.
|
|
82
|
+
text: (context) => {
|
|
83
|
+
if (!obsidian.getPreferences().enabled) return ''
|
|
84
|
+
const sessionId = context?.agent?.id ?? context?.scope?.id
|
|
85
|
+
const base = obsidian.promptText(sessionId)
|
|
86
|
+
if (base.length === 0) return ''
|
|
87
|
+
if (!obsidian.getPreferences().activeNote) return base
|
|
88
|
+
const active = activeNotes.get(sessionId)
|
|
89
|
+
return typeof active?.path === 'string' && active.path.length > 0
|
|
90
|
+
? `${base}\nCurrent Obsidian active note: ${active.path}`
|
|
91
|
+
: base
|
|
92
|
+
},
|
|
93
|
+
}), 'modularob-connectors: vault context')
|
|
94
|
+
|
|
95
|
+
// The bundled flowtext profile, injected only for a conversation that has
|
|
96
|
+
// selected a vault. A section with an empty text is dropped by assembly, so
|
|
97
|
+
// sessions without a vault pay nothing.
|
|
98
|
+
promptCtx.effect(() => promptCtx.systemPrompt.section({
|
|
99
|
+
name: 'obsidian-vault-profile',
|
|
100
|
+
order: 70,
|
|
101
|
+
interpolate: false,
|
|
102
|
+
text: (context) => {
|
|
103
|
+
if (!obsidian.getPreferences().enabled) return ''
|
|
104
|
+
const sessionId = context?.agent?.id ?? context?.scope?.id
|
|
105
|
+
return obsidian.selectedVault(sessionId) === null ? '' : profile.text()
|
|
106
|
+
},
|
|
107
|
+
}), 'modularob-connectors: vault profile')
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
// Read the running app's active note once at the start of each turn. The
|
|
111
|
+
// prompt context above only reads this cache, so assembly stays synchronous.
|
|
112
|
+
ctx.on('agent/pre-step', async (payload, next) => {
|
|
113
|
+
if (!obsidian.getPreferences().enabled) return next()
|
|
114
|
+
const sessionId = payload?.agent?.id
|
|
115
|
+
const vault = obsidian.selectedVault(sessionId)
|
|
116
|
+
if (vault === null || !obsidian.getPreferences().activeNote) return next()
|
|
117
|
+
const cached = activeNotes.get(sessionId)
|
|
118
|
+
const failedRecently = cached?.path === null && Date.now() - cached.at < 30_000
|
|
119
|
+
if (!failedRecently && (payload.step <= 1 || cached === undefined || cached.vaultId !== vault.id)) {
|
|
120
|
+
try {
|
|
121
|
+
activeNotes.set(sessionId, { path: await obsidian.readActiveNote(vault), vaultId: vault.id, at: Date.now() })
|
|
122
|
+
} catch {
|
|
123
|
+
activeNotes.set(sessionId, { path: null, vaultId: vault.id, at: Date.now() })
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return next()
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
ctx.inject(['webServer', 'connection'], (webCtx) => {
|
|
130
|
+
webCtx.effect(
|
|
131
|
+
() => registerVaultApi(webCtx, obsidian, { connection: webCtx.connection, profile, skills: skillManager, updater }),
|
|
132
|
+
'modularob-connectors: vault api',
|
|
133
|
+
)
|
|
134
|
+
})
|
|
135
|
+
}
|
package/lib/api.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The composer vault picker's HTTP API.
|
|
3
|
+
*
|
|
4
|
+
* The route belongs to this plugin and admits each request with the harness
|
|
5
|
+
* connection service, so it accepts only the authenticated browser session
|
|
6
|
+
* that the `/api` bridge would accept. It lists Obsidian vaults and stores one
|
|
7
|
+
* conversation's choice.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { ObsidianError } from './obsidian.js'
|
|
11
|
+
import { ProfileError } from './profile.js'
|
|
12
|
+
import { SkillError } from './skills.js'
|
|
13
|
+
import { UpdateError } from './update.js'
|
|
14
|
+
|
|
15
|
+
export const API_PATH = '/modularob-connectors/api'
|
|
16
|
+
const MAX_BODY_BYTES = 512 * 1024
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {import('@deepseek-ai/cordis').Context} ctx - context carrying `webServer`.
|
|
20
|
+
* @param {ReturnType<import('./obsidian.js').createObsidianService>} obsidian
|
|
21
|
+
* @param {{connection: {admit: (request: {headers: unknown}) => {rejection?: 401 | 403}}, profile: ReturnType<import('./profile.js').createProfileStore>, skills: ReturnType<import('./skills.js').createSkillManager>, updater: ReturnType<import('./update.js').createUpdater>}} options
|
|
22
|
+
* @returns {() => void} route disposer.
|
|
23
|
+
*/
|
|
24
|
+
export function registerVaultApi(ctx, obsidian, options) {
|
|
25
|
+
const { connection, profile, skills, updater } = options
|
|
26
|
+
return ctx.webServer.register({
|
|
27
|
+
kind: 'exact',
|
|
28
|
+
path: API_PATH,
|
|
29
|
+
async handler(req, res) {
|
|
30
|
+
let admission
|
|
31
|
+
try {
|
|
32
|
+
admission = connection.admit({ headers: req.headers })
|
|
33
|
+
} catch {
|
|
34
|
+
sendJson(res, 401, { ok: false, error: { code: 'unauthorized', message: 'The browser session is not authenticated.' } })
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
if (admission.rejection === 401 || admission.rejection === 403) {
|
|
38
|
+
sendJson(res, admission.rejection, { ok: false, error: { code: 'unauthorized', message: 'The browser session is not authenticated.' } })
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
if (req.method !== 'POST') {
|
|
42
|
+
res.writeHead(405, { allow: 'POST', 'content-type': 'text/plain; charset=utf-8' })
|
|
43
|
+
res.end('Method not allowed')
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
let payload
|
|
47
|
+
try {
|
|
48
|
+
payload = await readJson(req)
|
|
49
|
+
} catch (error) {
|
|
50
|
+
const status = error !== null && typeof error === 'object' && 'status' in error ? Number(error.status) : 400
|
|
51
|
+
sendJson(res, status, { ok: false, error: { code: 'bad-request', message: error instanceof Error ? error.message : 'Invalid request.' } })
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
const method = payload !== null && typeof payload === 'object' ? payload.method : undefined
|
|
55
|
+
const params = payload !== null && typeof payload === 'object' && payload.params !== null && typeof payload.params === 'object'
|
|
56
|
+
? payload.params
|
|
57
|
+
: {}
|
|
58
|
+
try {
|
|
59
|
+
if (method === 'vaults') {
|
|
60
|
+
sendJson(res, 200, { ok: true, value: obsidian.list(params.sessionId) })
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
if (method === 'select') {
|
|
64
|
+
sendJson(res, 200, { ok: true, value: await obsidian.select(params.sessionId, params.vaultId) })
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
if (method === 'clear') {
|
|
68
|
+
sendJson(res, 200, { ok: true, value: await obsidian.clear(params.sessionId) })
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
if (method === 'profile.model.get') {
|
|
72
|
+
sendJson(res, 200, { ok: true, value: profile.model() })
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
if (method === 'profile.model.save') {
|
|
76
|
+
const errors = profile.validate(params.model)
|
|
77
|
+
if (errors.length > 0) {
|
|
78
|
+
sendJson(res, 200, { ok: true, value: { saved: false, errors } })
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
const value = await profile.saveModel(params.model)
|
|
82
|
+
sendJson(res, 200, { ok: true, value: { saved: true, ...value } })
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
if (method === 'profile.get') {
|
|
86
|
+
sendJson(res, 200, { ok: true, value: profile.describe() })
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
if (method === 'profile.set') {
|
|
90
|
+
sendJson(res, 200, { ok: true, value: await profile.set(params.text) })
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
if (method === 'profile.reset') {
|
|
94
|
+
sendJson(res, 200, { ok: true, value: await profile.reset() })
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
if (method === 'settings.get') {
|
|
98
|
+
sendJson(res, 200, { ok: true, value: obsidian.getPreferences() })
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
if (method === 'settings.set') {
|
|
102
|
+
if (typeof params.enabled === 'boolean') await obsidian.setEnabled(params.enabled)
|
|
103
|
+
if (typeof params.activeNote === 'boolean') await obsidian.setActiveNote(params.activeNote)
|
|
104
|
+
sendJson(res, 200, { ok: true, value: obsidian.getPreferences() })
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
if (method === 'vault.folders') {
|
|
108
|
+
sendJson(res, 200, { ok: true, value: await obsidian.listFolders(params.vaultId) })
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
if (method === 'skills.list') {
|
|
112
|
+
sendJson(res, 200, { ok: true, value: skills.list() })
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
if (method === 'skills.setEnabled') {
|
|
116
|
+
sendJson(res, 200, { ok: true, value: await skills.setEnabled(params.name, params.enabled) })
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
if (method === 'update.check') {
|
|
120
|
+
sendJson(res, 200, { ok: true, value: await updater.check() })
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
if (method === 'update.apply') {
|
|
124
|
+
sendJson(res, 200, { ok: true, value: await updater.apply() })
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
sendJson(res, 400, { ok: false, error: { code: 'unknown-method', message: `Unknown method: ${String(method)}` } })
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (error instanceof ObsidianError || error instanceof ProfileError || error instanceof SkillError || error instanceof UpdateError) {
|
|
130
|
+
sendJson(res, 200, { ok: false, error: { code: error.code, message: error.message } })
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
ctx.logger?.warn?.(`modularob-connectors: vault API failed: ${error instanceof Error ? error.message : String(error)}`)
|
|
134
|
+
sendJson(res, 500, { ok: false, error: { code: 'internal-error', message: 'The connector could not complete that request.' } })
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** @param {import('node:http').IncomingMessage} req */
|
|
141
|
+
function readJson(req) {
|
|
142
|
+
return new Promise((resolve, reject) => {
|
|
143
|
+
const chunks = []
|
|
144
|
+
let size = 0
|
|
145
|
+
let failed = false
|
|
146
|
+
req.on('data', (chunk) => {
|
|
147
|
+
if (failed) return
|
|
148
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)
|
|
149
|
+
size += buffer.length
|
|
150
|
+
if (size > MAX_BODY_BYTES) {
|
|
151
|
+
failed = true
|
|
152
|
+
const error = new Error('The request is too large.')
|
|
153
|
+
error.status = 413
|
|
154
|
+
reject(error)
|
|
155
|
+
req.destroy()
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
chunks.push(buffer)
|
|
159
|
+
})
|
|
160
|
+
req.on('end', () => {
|
|
161
|
+
if (failed) return
|
|
162
|
+
const text = Buffer.concat(chunks).toString('utf8').trim()
|
|
163
|
+
if (text.length === 0) {
|
|
164
|
+
resolve({})
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
resolve(JSON.parse(text))
|
|
169
|
+
} catch {
|
|
170
|
+
const error = new Error('The request body is not valid JSON.')
|
|
171
|
+
error.status = 400
|
|
172
|
+
reject(error)
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
req.on('error', (error) => {
|
|
176
|
+
if (!failed) reject(error)
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** @param {import('node:http').ServerResponse} res @param {number} status @param {unknown} value */
|
|
182
|
+
function sendJson(res, status, value) {
|
|
183
|
+
if (res.headersSent) {
|
|
184
|
+
res.end()
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
const body = JSON.stringify(value)
|
|
188
|
+
res.writeHead(status, {
|
|
189
|
+
'content-type': 'application/json; charset=utf-8',
|
|
190
|
+
'cache-control': 'no-store',
|
|
191
|
+
'content-length': Buffer.byteLength(body),
|
|
192
|
+
})
|
|
193
|
+
res.end(body)
|
|
194
|
+
}
|
package/lib/cli.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small subprocess helper for the one CLI call the connector makes: asking the
|
|
3
|
+
* running Obsidian app for its active file.
|
|
4
|
+
*
|
|
5
|
+
* Arguments are passed literally (no shell), output and runtime are bounded,
|
|
6
|
+
* and a missing executable resolves to null instead of throwing.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { spawn } from 'node:child_process'
|
|
10
|
+
import fs from 'node:fs'
|
|
11
|
+
import os from 'node:os'
|
|
12
|
+
import path from 'node:path'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Run one executable with literal arguments.
|
|
16
|
+
* @param {string} command
|
|
17
|
+
* @param {string[]} args
|
|
18
|
+
* @param {{cwd?: string, timeoutMs?: number, maxBytes?: number}} [options]
|
|
19
|
+
* @returns {Promise<{ok: boolean, code: number | null, stdout: string, stderr: string, timedOut: boolean}>}
|
|
20
|
+
*/
|
|
21
|
+
export function runCommand(command, args, options = {}) {
|
|
22
|
+
const { cwd, timeoutMs = 10_000, maxBytes = 256 * 1024 } = options
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
let child
|
|
25
|
+
try {
|
|
26
|
+
child = spawn(command, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true })
|
|
27
|
+
} catch (error) {
|
|
28
|
+
reject(error)
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
const out = []
|
|
32
|
+
const err = []
|
|
33
|
+
let outBytes = 0
|
|
34
|
+
let errBytes = 0
|
|
35
|
+
let timedOut = false
|
|
36
|
+
let settled = false
|
|
37
|
+
let timer = null
|
|
38
|
+
|
|
39
|
+
const stop = () => {
|
|
40
|
+
try {
|
|
41
|
+
child.kill('SIGTERM')
|
|
42
|
+
} catch {
|
|
43
|
+
// Already gone.
|
|
44
|
+
}
|
|
45
|
+
const force = setTimeout(() => {
|
|
46
|
+
try {
|
|
47
|
+
child.kill('SIGKILL')
|
|
48
|
+
} catch {
|
|
49
|
+
// Already gone.
|
|
50
|
+
}
|
|
51
|
+
}, 1200)
|
|
52
|
+
force.unref?.()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const consume = (chunk, target, kind) => {
|
|
56
|
+
if (settled) return
|
|
57
|
+
const remaining = maxBytes - (kind === 'out' ? outBytes : errBytes)
|
|
58
|
+
if (remaining <= 0) {
|
|
59
|
+
stop()
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
const buffer = Buffer.from(chunk)
|
|
63
|
+
const slice = buffer.length > remaining ? buffer.subarray(0, remaining) : buffer
|
|
64
|
+
if (buffer.length > remaining) stop()
|
|
65
|
+
target.push(slice)
|
|
66
|
+
if (kind === 'out') outBytes += slice.length
|
|
67
|
+
else errBytes += slice.length
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
child.stdout?.on('data', chunk => consume(chunk, out, 'out'))
|
|
71
|
+
child.stderr?.on('data', chunk => consume(chunk, err, 'err'))
|
|
72
|
+
child.on('error', (error) => {
|
|
73
|
+
if (settled) return
|
|
74
|
+
settled = true
|
|
75
|
+
if (timer !== null) clearTimeout(timer)
|
|
76
|
+
reject(error)
|
|
77
|
+
})
|
|
78
|
+
timer = setTimeout(() => {
|
|
79
|
+
timedOut = true
|
|
80
|
+
stop()
|
|
81
|
+
}, timeoutMs)
|
|
82
|
+
timer.unref?.()
|
|
83
|
+
child.on('close', (code) => {
|
|
84
|
+
if (settled) return
|
|
85
|
+
settled = true
|
|
86
|
+
if (timer !== null) clearTimeout(timer)
|
|
87
|
+
resolve({
|
|
88
|
+
ok: !timedOut && code === 0,
|
|
89
|
+
code,
|
|
90
|
+
stdout: Buffer.concat(out).toString('utf8'),
|
|
91
|
+
stderr: Buffer.concat(err).toString('utf8'),
|
|
92
|
+
timedOut,
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Find an executable on PATH or in common per-user bin directories.
|
|
100
|
+
* @param {string} command
|
|
101
|
+
* @param {string} [home]
|
|
102
|
+
* @returns {Promise<string | null>}
|
|
103
|
+
*/
|
|
104
|
+
export async function resolveCommand(command, home = os.homedir()) {
|
|
105
|
+
const name = typeof command === 'string' ? command.trim() : ''
|
|
106
|
+
if (name.length === 0) return null
|
|
107
|
+
if (name.includes('/') || name.includes('\\')) {
|
|
108
|
+
try {
|
|
109
|
+
fs.accessSync(name, fs.constants.X_OK)
|
|
110
|
+
return name
|
|
111
|
+
} catch {
|
|
112
|
+
return null
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
const found = await runCommand(process.platform === 'win32' ? 'where' : 'which', [name], {
|
|
117
|
+
timeoutMs: 5_000,
|
|
118
|
+
maxBytes: 8 * 1024,
|
|
119
|
+
})
|
|
120
|
+
if (found.ok) {
|
|
121
|
+
const first = found.stdout.split(/\r?\n/).map(line => line.trim()).find(Boolean)
|
|
122
|
+
if (first !== undefined) return first
|
|
123
|
+
}
|
|
124
|
+
} catch {
|
|
125
|
+
// Fall through to the candidate directories.
|
|
126
|
+
}
|
|
127
|
+
const candidates = [
|
|
128
|
+
'/usr/local/bin',
|
|
129
|
+
'/opt/homebrew/bin',
|
|
130
|
+
'/usr/bin',
|
|
131
|
+
'/bin',
|
|
132
|
+
path.join(home, '.local', 'bin'),
|
|
133
|
+
path.join(home, 'bin'),
|
|
134
|
+
].map(directory => path.join(directory, name))
|
|
135
|
+
for (const candidate of candidates) {
|
|
136
|
+
try {
|
|
137
|
+
fs.accessSync(candidate, fs.constants.X_OK)
|
|
138
|
+
return candidate
|
|
139
|
+
} catch {
|
|
140
|
+
// Try the next one.
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return null
|
|
144
|
+
}
|