hostlet 0.0.0-stage → 0.1.0-alpha.2
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 +233 -2
- package/bin/hostlet.js +61 -0
- package/console/app/api.js +1223 -0
- package/console/app/boot.js +165 -0
- package/console/app/cards.js +222 -0
- package/console/app/compose-quote.js +127 -0
- package/console/app/config-form.js +727 -0
- package/console/app/document-drafts.js +62 -0
- package/console/app/document-tools.mjs +67 -0
- package/console/app/documents.js +106 -0
- package/console/app/pages.js +6483 -0
- package/console/app/plugins.js +509 -0
- package/console/app/preview-tools.js +172 -0
- package/console/app/reference-labels.js +118 -0
- package/console/app/selection.js +372 -0
- package/console/app/store.js +57 -0
- package/console/app/text-anchor.js +26 -0
- package/console/app/topic-local.js +322 -0
- package/console/app/topic-nav.js +414 -0
- package/console/app/topic-status.js +109 -0
- package/console/app/views.js +43 -0
- package/console/apple-touch-icon.png +0 -0
- package/console/avatars/agy.svg +34 -0
- package/console/avatars/alhena.svg +36 -0
- package/console/avatars/castor.svg +38 -0
- package/console/avatars/claude.svg +34 -0
- package/console/avatars/codex.svg +34 -0
- package/console/avatars/devin.svg +34 -0
- package/console/avatars/echo.svg +34 -0
- package/console/avatars/kimi.svg +33 -0
- package/console/avatars/opencode.svg +33 -0
- package/console/avatars/pinion.svg +34 -0
- package/console/avatars/sprocket.svg +34 -0
- package/console/avatars/vela.svg +44 -0
- package/console/avatars/wasat.svg +38 -0
- package/console/clients/agy.svg +1 -0
- package/console/clients/claude.svg +1 -0
- package/console/clients/codex.svg +1 -0
- package/console/clients/devin.svg +1 -0
- package/console/clients/kimi.svg +1 -0
- package/console/clients/opencode.svg +1 -0
- package/console/favicon.ico +0 -0
- package/console/favicon.svg +16 -0
- package/console/index.html +99 -0
- package/console/pdl/engine/README.md +13 -0
- package/console/pdl/engine/anchor.js +195 -0
- package/console/pdl/engine/core.js +1340 -0
- package/console/pdl/engine/frame.js +1252 -0
- package/console/pdl/engine/i18n.js +67 -0
- package/console/pdl/engine/pdl-check.js +102 -0
- package/console/pdl/engine/pdl-doc.js +353 -0
- package/console/pdl/engine/pdl-view.js +280 -0
- package/console/pdl/engine/pdl.js +1064 -0
- package/console/pdl/engine/platform.js +18 -0
- package/console/pdl/engine/proj.js +279 -0
- package/console/pdl/engine/theme.js +176 -0
- package/console/pdl/engine/tree.js +171 -0
- package/console/pdl/engine/units.js +546 -0
- package/console/pdl/library/README.md +28 -0
- package/console/pdl/library/blocks.js +1512 -0
- package/console/pdl/library/buttons.js +86 -0
- package/console/pdl/library/capsules.js +130 -0
- package/console/pdl/library/charts.js +287 -0
- package/console/pdl/library/code.js +98 -0
- package/console/pdl/library/css/base.css +12 -0
- package/console/pdl/library/css/blocks.css +98 -0
- package/console/pdl/library/css/capsules.css +42 -0
- package/console/pdl/library/css/catalog-page.css +24 -0
- package/console/pdl/library/css/chat.css +100 -0
- package/console/pdl/library/css/composer-top.css +145 -0
- package/console/pdl/library/css/controls.css +195 -0
- package/console/pdl/library/css/drag.css +29 -0
- package/console/pdl/library/css/edit-layout.css +93 -0
- package/console/pdl/library/css/floating-window.css +30 -0
- package/console/pdl/library/css/hover.css +50 -0
- package/console/pdl/library/css/label-search.css +37 -0
- package/console/pdl/library/css/layers.css +43 -0
- package/console/pdl/library/css/library-parts.css +33 -0
- package/console/pdl/library/css/library.css +117 -0
- package/console/pdl/library/css/member-select.css +34 -0
- package/console/pdl/library/css/message.css +72 -0
- package/console/pdl/library/css/page.css +104 -0
- package/console/pdl/library/css/parts.css +338 -0
- package/console/pdl/library/css/responsive.css +40 -0
- package/console/pdl/library/css/roles.css +28 -0
- package/console/pdl/library/css/rows.css +231 -0
- package/console/pdl/library/css/settings-rows.css +37 -0
- package/console/pdl/library/css/shell.css +59 -0
- package/console/pdl/library/css/stream.css +296 -0
- package/console/pdl/library/css/theme-calculator.css +18 -0
- package/console/pdl/library/css/thumb-choice.css +69 -0
- package/console/pdl/library/css/tweaks.css +16 -0
- package/console/pdl/library/css/widgets.css +211 -0
- package/console/pdl/library/css/workbench.css +59 -0
- package/console/pdl/library/feedback.js +83 -0
- package/console/pdl/library/floating-window.mjs +100 -0
- package/console/pdl/library/fold.js +238 -0
- package/console/pdl/library/format.js +53 -0
- package/console/pdl/library/frames.js +123 -0
- package/console/pdl/library/icons.js +165 -0
- package/console/pdl/library/identity.js +149 -0
- package/console/pdl/library/inputs.js +801 -0
- package/console/pdl/library/label-search.js +214 -0
- package/console/pdl/library/markdown-text.js +115 -0
- package/console/pdl/library/markdown.js +150 -0
- package/console/pdl/library/media-viewer.js +293 -0
- package/console/pdl/library/member-select.mjs +32 -0
- package/console/pdl/library/message.js +105 -0
- package/console/pdl/library/motion.js +56 -0
- package/console/pdl/library/overlays.js +165 -0
- package/console/pdl/library/page.js +142 -0
- package/console/pdl/library/plugin-form.js +154 -0
- package/console/pdl/library/registry.js +198 -0
- package/console/pdl/library/rows.js +523 -0
- package/console/pdl/library/shell.js +151 -0
- package/console/pdl/library/stream.js +58 -0
- package/console/pdl/library/tabs.js +259 -0
- package/console/pdl/library/theme-calculator.js +300 -0
- package/console/pdl/library/widgets.js +114 -0
- package/console/pdl/load-order.json +74 -0
- package/console/pdl/platform/README.md +3 -0
- package/console/pdl/platform/rich-markdown.mjs +17 -0
- package/console/pdl/platform/web-links.js +26 -0
- package/console/pdl/platform/web.js +80 -0
- package/console/sdk-browser/mentions.d.mts +16 -0
- package/console/sdk-browser/mentions.mjs +84 -0
- package/console/theme/assets.js +21 -0
- package/console/theme/theme.json +9417 -0
- package/console/theme/tokens.json +444 -0
- package/dist/core/a2a.d.ts +288 -0
- package/dist/core/a2a.js +2197 -0
- package/dist/core/address.d.ts +34 -0
- package/dist/core/address.js +33 -0
- package/dist/core/approval-inputs.d.ts +17 -0
- package/dist/core/approval-inputs.js +70 -0
- package/dist/core/archive.d.ts +19 -0
- package/dist/core/archive.js +135 -0
- package/dist/core/attachments.d.ts +17 -0
- package/dist/core/attachments.js +143 -0
- package/dist/core/blocked-handoffs.d.ts +132 -0
- package/dist/core/blocked-handoffs.js +349 -0
- package/dist/core/config-schema.d.ts +124 -0
- package/dist/core/config-schema.js +192 -0
- package/dist/core/config.d.ts +117 -0
- package/dist/core/config.js +638 -0
- package/dist/core/disk-usage.d.ts +26 -0
- package/dist/core/disk-usage.js +83 -0
- package/dist/core/documents.d.ts +9 -0
- package/dist/core/documents.js +48 -0
- package/dist/core/entry.d.ts +316 -0
- package/dist/core/entry.js +711 -0
- package/dist/core/home.d.ts +76 -0
- package/dist/core/home.js +449 -0
- package/dist/core/i18n.d.ts +36 -0
- package/dist/core/i18n.js +458 -0
- package/dist/core/instances.d.ts +224 -0
- package/dist/core/instances.js +1272 -0
- package/dist/core/members.d.ts +190 -0
- package/dist/core/members.js +358 -0
- package/dist/core/mentions.d.ts +12 -0
- package/dist/core/mentions.js +49 -0
- package/dist/core/messages.d.ts +876 -0
- package/dist/core/messages.js +916 -0
- package/dist/core/notices.d.ts +88 -0
- package/dist/core/notices.js +54 -0
- package/dist/core/ops.d.ts +117 -0
- package/dist/core/ops.js +146 -0
- package/dist/core/package.d.ts +2 -0
- package/dist/core/package.js +14 -0
- package/dist/core/parts.d.ts +25 -0
- package/dist/core/parts.js +119 -0
- package/dist/core/plugins/catalog.d.ts +14 -0
- package/dist/core/plugins/catalog.js +54 -0
- package/dist/core/plugins/external.d.ts +7 -0
- package/dist/core/plugins/external.js +921 -0
- package/dist/core/plugins/index.d.ts +5 -0
- package/dist/core/plugins/index.js +51 -0
- package/dist/core/plugins/npm.d.ts +12 -0
- package/dist/core/plugins/npm.js +99 -0
- package/dist/core/plugins/plugin-manifest.d.ts +12 -0
- package/dist/core/plugins/plugin-manifest.js +231 -0
- package/dist/core/push.d.ts +22 -0
- package/dist/core/push.js +63 -0
- package/dist/core/resource.d.ts +77 -0
- package/dist/core/resource.js +48 -0
- package/dist/core/spawn.d.ts +12 -0
- package/dist/core/spawn.js +30 -0
- package/dist/core/storage-inventory.d.ts +118 -0
- package/dist/core/storage-inventory.js +279 -0
- package/dist/core/storage.d.ts +45 -0
- package/dist/core/storage.js +602 -0
- package/dist/core/store.d.ts +15 -0
- package/dist/core/store.js +33 -0
- package/dist/core/topic-index.d.ts +19 -0
- package/dist/core/topic-index.js +70 -0
- package/dist/core/topic-ops.d.ts +139 -0
- package/dist/core/topic-ops.js +507 -0
- package/dist/core/topic-status.d.ts +32 -0
- package/dist/core/topic-status.js +105 -0
- package/dist/core/topics.d.ts +327 -0
- package/dist/core/topics.js +786 -0
- package/dist/core/turn-clients.d.ts +1 -0
- package/dist/core/turn-clients.js +5 -0
- package/dist/core/types.d.ts +2866 -0
- package/dist/core/types.js +166 -0
- package/dist/core/util.d.ts +10 -0
- package/dist/core/util.js +47 -0
- package/dist/main.d.ts +12 -0
- package/dist/main.js +82 -0
- package/dist/plugins/adapter-acp/index.d.ts +3 -0
- package/dist/plugins/adapter-acp/index.js +57 -0
- package/dist/plugins/adapter-acp/plugin.yaml +100 -0
- package/dist/plugins/adapter-agy/command.d.ts +9 -0
- package/dist/plugins/adapter-agy/command.js +34 -0
- package/dist/plugins/adapter-agy/index.d.ts +5 -0
- package/dist/plugins/adapter-agy/index.js +65 -0
- package/dist/plugins/adapter-agy/quota.d.ts +2 -0
- package/dist/plugins/adapter-agy/quota.js +155 -0
- package/dist/plugins/adapter-agy/terminal.d.ts +6 -0
- package/dist/plugins/adapter-agy/terminal.js +132 -0
- package/dist/plugins/adapter-agy/version.d.ts +9 -0
- package/dist/plugins/adapter-agy/version.js +17 -0
- package/dist/plugins/adapter-claude/index.d.ts +43 -0
- package/dist/plugins/adapter-claude/index.js +412 -0
- package/dist/plugins/adapter-claude/quota.d.ts +14 -0
- package/dist/plugins/adapter-claude/quota.js +103 -0
- package/dist/plugins/adapter-codex/index.d.ts +4 -0
- package/dist/plugins/adapter-codex/index.js +688 -0
- package/dist/plugins/adapter-codex/responses-model.d.ts +9 -0
- package/dist/plugins/adapter-codex/responses-model.js +82 -0
- package/dist/plugins/adapter-kimi/index.d.ts +4 -0
- package/dist/plugins/adapter-kimi/index.js +51 -0
- package/dist/plugins/adapter-kimi/quota.d.ts +3 -0
- package/dist/plugins/adapter-kimi/quota.js +171 -0
- package/dist/plugins/adapter-opencode/index.d.ts +12 -0
- package/dist/plugins/adapter-opencode/index.js +64 -0
- package/dist/plugins/annotations/console/cards.css +189 -0
- package/dist/plugins/annotations/console/cards.mjs +439 -0
- package/dist/plugins/annotations/console/pdl.json +52 -0
- package/dist/plugins/annotations/console/view.mjs +241 -0
- package/dist/plugins/annotations/console/window.mjs +219 -0
- package/dist/plugins/annotations/followups.d.ts +51 -0
- package/dist/plugins/annotations/followups.js +112 -0
- package/dist/plugins/annotations/index.d.ts +3 -0
- package/dist/plugins/annotations/index.js +298 -0
- package/dist/plugins/annotations/plugin.yaml +3 -0
- package/dist/plugins/ask-choice/index.d.ts +9 -0
- package/dist/plugins/ask-choice/index.js +24 -0
- package/dist/plugins/ask-choice/plugin.yaml +2 -0
- package/dist/plugins/background/index.d.ts +2 -0
- package/dist/plugins/background/index.js +398 -0
- package/dist/plugins/background/plugin.yaml +7 -0
- package/dist/plugins/builtin.json +37 -0
- package/dist/plugins/cards/console/pdl.json +516 -0
- package/dist/plugins/cards/console/view.mjs +67 -0
- package/dist/plugins/cards/index.d.ts +8 -0
- package/dist/plugins/cards/index.js +627 -0
- package/dist/plugins/cards/plugin.yaml +3 -0
- package/dist/plugins/console/browser.d.ts +2 -0
- package/dist/plugins/console/browser.js +115 -0
- package/dist/plugins/console/console/pdl.json +38 -0
- package/dist/plugins/console/console/view.mjs +26 -0
- package/dist/plugins/console/index.d.ts +4 -0
- package/dist/plugins/console/index.js +94 -0
- package/dist/plugins/console/picker.d.ts +2 -0
- package/dist/plugins/console/picker.js +48 -0
- package/dist/plugins/console/plugin.yaml +3 -0
- package/dist/plugins/console/topic-view.d.ts +3 -0
- package/dist/plugins/console/topic-view.js +388 -0
- package/dist/plugins/handoff/index.d.ts +2 -0
- package/dist/plugins/handoff/index.js +147 -0
- package/dist/plugins/handoff/plugin.yaml +8 -0
- package/dist/plugins/host-api/index.d.ts +7 -0
- package/dist/plugins/host-api/index.js +310 -0
- package/dist/plugins/host-api/plugin.yaml +2 -0
- package/dist/plugins/host-api/signing.d.ts +63 -0
- package/dist/plugins/host-api/signing.js +427 -0
- package/dist/plugins/host-api/skills/host-ops/SKILL.md +28 -0
- package/dist/plugins/host-api/skills/hostlet-plugin-dev/SKILL.md +38 -0
- package/dist/plugins/inbox/index.d.ts +15 -0
- package/dist/plugins/inbox/index.js +161 -0
- package/dist/plugins/inbox/plugin.yaml +2 -0
- package/dist/plugins/keys/account-directories.d.ts +18 -0
- package/dist/plugins/keys/account-directories.js +86 -0
- package/dist/plugins/keys/account-storage.d.ts +18 -0
- package/dist/plugins/keys/account-storage.js +112 -0
- package/dist/plugins/keys/console/pdl.json +710 -0
- package/dist/plugins/keys/console/view.mjs +619 -0
- package/dist/plugins/keys/index.d.ts +7 -0
- package/dist/plugins/keys/index.js +842 -0
- package/dist/plugins/keys/login-link.d.ts +2 -0
- package/dist/plugins/keys/login-link.js +15 -0
- package/dist/plugins/keys/plugin.yaml +3 -0
- package/dist/plugins/keys/quota-history.d.ts +91 -0
- package/dist/plugins/keys/quota-history.js +420 -0
- package/dist/plugins/mcp/console/pdl.json +412 -0
- package/dist/plugins/mcp/console/view.mjs +207 -0
- package/dist/plugins/mcp/index.d.ts +7 -0
- package/dist/plugins/mcp/index.js +494 -0
- package/dist/plugins/mcp/plugin.yaml +3 -0
- package/dist/plugins/member-health/index.d.ts +2 -0
- package/dist/plugins/member-health/index.js +478 -0
- package/dist/plugins/member-health/plugin.yaml +2 -0
- package/dist/plugins/memory/capabilities.d.ts +10 -0
- package/dist/plugins/memory/capabilities.js +70 -0
- package/dist/plugins/memory/console/pdl.json +459 -0
- package/dist/plugins/memory/console/view.mjs +254 -0
- package/dist/plugins/memory/corpus.d.ts +60 -0
- package/dist/plugins/memory/corpus.js +521 -0
- package/dist/plugins/memory/engines/fts-tree-diversity.d.ts +8 -0
- package/dist/plugins/memory/engines/fts-tree-diversity.js +49 -0
- package/dist/plugins/memory/engines/fts-tree-text.d.ts +12 -0
- package/dist/plugins/memory/engines/fts-tree-text.js +93 -0
- package/dist/plugins/memory/engines/fts-tree.d.ts +4 -0
- package/dist/plugins/memory/engines/fts-tree.js +387 -0
- package/dist/plugins/memory/engines/search.d.ts +9 -0
- package/dist/plugins/memory/engines/search.js +35 -0
- package/dist/plugins/memory/index.d.ts +3 -0
- package/dist/plugins/memory/index.js +465 -0
- package/dist/plugins/memory/notes.d.ts +22 -0
- package/dist/plugins/memory/notes.js +140 -0
- package/dist/plugins/memory/plugin.yaml +23 -0
- package/dist/plugins/model-profiles/index.d.ts +2 -0
- package/dist/plugins/model-profiles/index.js +919 -0
- package/dist/plugins/model-profiles/plugin.yaml +13 -0
- package/dist/plugins/model-profiles/review-source.d.ts +11 -0
- package/dist/plugins/model-profiles/review-source.js +640 -0
- package/dist/plugins/model-profiles/rules.d.ts +132 -0
- package/dist/plugins/model-profiles/rules.js +767 -0
- package/dist/plugins/model-profiles/skills/model-profile/SKILL.md +60 -0
- package/dist/plugins/model-profiles/sources.d.ts +61 -0
- package/dist/plugins/model-profiles/sources.js +375 -0
- package/dist/plugins/model-profiles/storage.d.ts +104 -0
- package/dist/plugins/model-profiles/storage.js +352 -0
- package/dist/plugins/model-profiles/types.d.ts +187 -0
- package/dist/plugins/model-profiles/types.js +12 -0
- package/dist/plugins/model-profiles/wakeup.d.ts +29 -0
- package/dist/plugins/model-profiles/wakeup.js +390 -0
- package/dist/plugins/models/index.d.ts +2 -0
- package/dist/plugins/models/index.js +63 -0
- package/dist/plugins/models/plugin.yaml +8 -0
- package/dist/plugins/ops/collector.d.ts +22 -0
- package/dist/plugins/ops/collector.js +48 -0
- package/dist/plugins/ops/config.d.ts +11 -0
- package/dist/plugins/ops/config.js +13 -0
- package/dist/plugins/ops/console/pdl.json +676 -0
- package/dist/plugins/ops/console/view.mjs +700 -0
- package/dist/plugins/ops/index.d.ts +3 -0
- package/dist/plugins/ops/index.js +20 -0
- package/dist/plugins/ops/journal.d.ts +7 -0
- package/dist/plugins/ops/journal.js +109 -0
- package/dist/plugins/ops/metrics.d.ts +3 -0
- package/dist/plugins/ops/metrics.js +81 -0
- package/dist/plugins/ops/plugin.yaml +63 -0
- package/dist/plugins/ops/samples.d.ts +54 -0
- package/dist/plugins/ops/samples.js +100 -0
- package/dist/plugins/ops/trace.d.ts +3 -0
- package/dist/plugins/ops/trace.js +104 -0
- package/dist/plugins/ops/usage.d.ts +2 -0
- package/dist/plugins/ops/usage.js +152 -0
- package/dist/plugins/plans/acceptance.d.ts +284 -0
- package/dist/plugins/plans/acceptance.js +247 -0
- package/dist/plugins/plans/blocked.d.ts +25 -0
- package/dist/plugins/plans/blocked.js +66 -0
- package/dist/plugins/plans/console/pdl.json +639 -0
- package/dist/plugins/plans/console/view.d.mts +2 -0
- package/dist/plugins/plans/console/view.mjs +855 -0
- package/dist/plugins/plans/dependencies.d.ts +5 -0
- package/dist/plugins/plans/dependencies.js +21 -0
- package/dist/plugins/plans/index.d.ts +72 -0
- package/dist/plugins/plans/index.js +2057 -0
- package/dist/plugins/plans/plugin.yaml +44 -0
- package/dist/plugins/plans/progress.d.ts +82 -0
- package/dist/plugins/plans/progress.js +516 -0
- package/dist/plugins/prompt/index.d.ts +8 -0
- package/dist/plugins/prompt/index.js +361 -0
- package/dist/plugins/prompt/plugin.yaml +2 -0
- package/dist/plugins/recovery/console/pdl.json +50 -0
- package/dist/plugins/recovery/console/view.mjs +46 -0
- package/dist/plugins/recovery/index.d.ts +9 -0
- package/dist/plugins/recovery/index.js +454 -0
- package/dist/plugins/recovery/plugin.yaml +9 -0
- package/dist/plugins/recovery/probe.d.ts +11 -0
- package/dist/plugins/recovery/probe.js +128 -0
- package/dist/plugins/restart/console/pdl.json +112 -0
- package/dist/plugins/restart/console/view.mjs +85 -0
- package/dist/plugins/restart/index.d.ts +10 -0
- package/dist/plugins/restart/index.js +669 -0
- package/dist/plugins/restart/plugin.yaml +9 -0
- package/dist/plugins/restart/scope.d.ts +6 -0
- package/dist/plugins/restart/scope.js +44 -0
- package/dist/plugins/schedule/console/pdl.json +696 -0
- package/dist/plugins/schedule/console/view.mjs +398 -0
- package/dist/plugins/schedule/events.d.ts +76 -0
- package/dist/plugins/schedule/events.js +158 -0
- package/dist/plugins/schedule/index.d.ts +32 -0
- package/dist/plugins/schedule/index.js +1199 -0
- package/dist/plugins/schedule/plugin.yaml +26 -0
- package/dist/plugins/schedule/when.d.ts +14 -0
- package/dist/plugins/schedule/when.js +83 -0
- package/dist/plugins/sessions/console/pdl.json +259 -0
- package/dist/plugins/sessions/console/view.mjs +355 -0
- package/dist/plugins/sessions/index.d.ts +3 -0
- package/dist/plugins/sessions/index.js +126 -0
- package/dist/plugins/sessions/participants.d.ts +28 -0
- package/dist/plugins/sessions/participants.js +83 -0
- package/dist/plugins/sessions/plugin.yaml +3 -0
- package/dist/plugins/signals/console/pdl.json +802 -0
- package/dist/plugins/signals/console/view.mjs +284 -0
- package/dist/plugins/signals/content.d.ts +31 -0
- package/dist/plugins/signals/content.js +151 -0
- package/dist/plugins/signals/index.d.ts +2 -0
- package/dist/plugins/signals/index.js +601 -0
- package/dist/plugins/signals/plugin.yaml +32 -0
- package/dist/plugins/signals/skills/signal-sources/SKILL.md +27 -0
- package/dist/plugins/skills/console/pdl.json +254 -0
- package/dist/plugins/skills/console/view.mjs +204 -0
- package/dist/plugins/skills/index.d.ts +11 -0
- package/dist/plugins/skills/index.js +567 -0
- package/dist/plugins/skills/install.d.ts +69 -0
- package/dist/plugins/skills/install.js +265 -0
- package/dist/plugins/skills/plugin.yaml +24 -0
- package/dist/plugins/skills/safety-scan.d.ts +17 -0
- package/dist/plugins/skills/safety-scan.js +78 -0
- package/dist/plugins/skills/skills/skill-ops/SKILL.md +29 -0
- package/dist/plugins/terminal/console/pdl.json +115 -0
- package/dist/plugins/terminal/console/view.mjs +178 -0
- package/dist/plugins/terminal/index.d.ts +3 -0
- package/dist/plugins/terminal/index.js +204 -0
- package/dist/plugins/terminal/plugin.yaml +2 -0
- package/dist/plugins/tools/index.d.ts +3 -0
- package/dist/plugins/tools/index.js +458 -0
- package/dist/plugins/tools/plugin.yaml +2 -0
- package/dist/plugins/tools/token.d.ts +61 -0
- package/dist/plugins/tools/token.js +179 -0
- package/dist/plugins/topic-tools/index.d.ts +9 -0
- package/dist/plugins/topic-tools/index.js +29 -0
- package/dist/plugins/topic-tools/plugin.yaml +2 -0
- package/dist/plugins/topic-tools/skills/topic-tidy/SKILL.md +108 -0
- package/dist/plugins/works/console/pdl.json +120 -0
- package/dist/plugins/works/console/view.mjs +91 -0
- package/dist/plugins/works/document-words.d.ts +50 -0
- package/dist/plugins/works/document-words.js +27 -0
- package/dist/plugins/works/editors.d.ts +3 -0
- package/dist/plugins/works/editors.js +162 -0
- package/dist/plugins/works/events.d.ts +58 -0
- package/dist/plugins/works/events.js +82 -0
- package/dist/plugins/works/files.d.ts +23 -0
- package/dist/plugins/works/files.js +53 -0
- package/dist/plugins/works/index.d.ts +9 -0
- package/dist/plugins/works/index.js +1088 -0
- package/dist/plugins/works/plugin.yaml +9 -0
- package/dist/plugins/works/preview.d.ts +10 -0
- package/dist/plugins/works/preview.js +30 -0
- package/dist/plugins/works/project.d.ts +3 -0
- package/dist/plugins/works/project.js +245 -0
- package/dist/plugins/works/resource.d.ts +28 -0
- package/dist/plugins/works/resource.js +71 -0
- package/dist/plugins/works/retention.d.ts +36 -0
- package/dist/plugins/works/retention.js +295 -0
- package/dist/plugins/works/skills/works-ops/SKILL.md +14 -0
- package/dist/plugins/works/viewers.d.ts +13 -0
- package/dist/plugins/works/viewers.js +87 -0
- package/dist/plugins/works/web/anchors.js +94 -0
- package/dist/plugins/works/web/document-edit.js +245 -0
- package/dist/plugins/works/web/preview-bridge.js +142 -0
- package/dist/plugins/works/web/reading-position.js +74 -0
- package/dist/plugins/works/web/view.html +1118 -0
- package/dist/runtime/runtime.d.ts +210 -0
- package/dist/runtime/runtime.js +338 -0
- package/dist/sdk/adapter-kit.d.ts +1 -0
- package/dist/sdk/adapter-kit.js +1 -0
- package/dist/sdk/client.d.ts +163 -0
- package/dist/sdk/client.js +43 -0
- package/dist/sdk/contracts.d.ts +1263 -0
- package/dist/sdk/contracts.js +1 -0
- package/dist/sdk/index.d.ts +57 -0
- package/dist/sdk/index.js +27 -0
- package/dist/sdk/source-choice.d.ts +40 -0
- package/dist/sdk/source-choice.js +217 -0
- package/dist/sdk/topic-text.d.ts +5 -0
- package/dist/sdk/topic-text.js +26 -0
- package/dist/sdk/transport.d.ts +12 -0
- package/dist/sdk/transport.js +34 -0
- package/node_modules/@hostlet/adapter-kit/dist/acp.d.ts +88 -0
- package/node_modules/@hostlet/adapter-kit/dist/acp.js +674 -0
- package/node_modules/@hostlet/adapter-kit/dist/command.d.ts +18 -0
- package/node_modules/@hostlet/adapter-kit/dist/command.js +39 -0
- package/node_modules/@hostlet/adapter-kit/dist/index.d.ts +8 -0
- package/node_modules/@hostlet/adapter-kit/dist/index.js +6 -0
- package/node_modules/@hostlet/adapter-kit/dist/models.d.ts +29 -0
- package/node_modules/@hostlet/adapter-kit/dist/models.js +108 -0
- package/node_modules/@hostlet/adapter-kit/dist/quota.d.ts +3 -0
- package/node_modules/@hostlet/adapter-kit/dist/quota.js +4 -0
- package/node_modules/@hostlet/adapter-kit/dist/rpc.d.ts +29 -0
- package/node_modules/@hostlet/adapter-kit/dist/rpc.js +84 -0
- package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.d.ts +5 -0
- package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.js +37 -0
- package/node_modules/@hostlet/adapter-kit/package.json +16 -0
- package/node_modules/@hostlet/platform/dist/desktop.d.ts +16 -0
- package/node_modules/@hostlet/platform/dist/desktop.js +276 -0
- package/node_modules/@hostlet/platform/dist/files.d.ts +24 -0
- package/node_modules/@hostlet/platform/dist/files.js +113 -0
- package/node_modules/@hostlet/platform/dist/index.d.ts +6 -0
- package/node_modules/@hostlet/platform/dist/index.js +4 -0
- package/node_modules/@hostlet/platform/dist/paths.d.ts +4 -0
- package/node_modules/@hostlet/platform/dist/paths.js +9 -0
- package/node_modules/@hostlet/platform/dist/process.d.ts +45 -0
- package/node_modules/@hostlet/platform/dist/process.js +297 -0
- package/node_modules/@hostlet/platform/package.json +14 -0
- package/package.json +60 -4
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
import { hash } from 'node:crypto';
|
|
2
|
+
import { existsSync, lstatSync, readFileSync, unlinkSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
6
|
+
import { commandLine, commandText, startRpc, stopRpc } from '@hostlet/adapter-kit';
|
|
7
|
+
import { errorText, HttpError, ltext, object, readJson, sourceChoiceOf, sourceChoices, startChild, writeDocuments, writeJson } from 'hostlet/sdk';
|
|
8
|
+
const validName = (name) => /^[a-zA-Z0-9_-]+$/.test(name);
|
|
9
|
+
const targetOf = (s) => s.url ?? commandText([s.command ?? '', ...(s.args ?? [])]);
|
|
10
|
+
const orderedPairs = (values = {}) => Object.keys(values).sort().map((key) => [key, values[key]]);
|
|
11
|
+
function stdioTarget(text) {
|
|
12
|
+
const [command, ...args] = commandLine(text, '');
|
|
13
|
+
if (!command)
|
|
14
|
+
throw new HttpError(400, '启动命令需要包含程序名或路径');
|
|
15
|
+
return { command, args };
|
|
16
|
+
}
|
|
17
|
+
const pairs = (text = '') => Object.fromEntries(text.split(/\r?\n/).map((line) => line.trim()).filter(Boolean).map((line) => {
|
|
18
|
+
const at = line.indexOf('=');
|
|
19
|
+
if (at <= 0)
|
|
20
|
+
throw new HttpError(400, '环境变量和请求头要逐行写成 名字=值');
|
|
21
|
+
return [line.slice(0, at).trim(), line.slice(at + 1).trim()];
|
|
22
|
+
}));
|
|
23
|
+
/**
|
|
24
|
+
* MCP servers from outside the host: the owner lists them once and every member's CLI is handed the ones that are
|
|
25
|
+
* switched on when its instance starts. The host does not connect to them itself.
|
|
26
|
+
*/
|
|
27
|
+
export function mcpPlugin(home) {
|
|
28
|
+
return {
|
|
29
|
+
name: 'mcp',
|
|
30
|
+
title: '外部 MCP 服务',
|
|
31
|
+
about: '你加进来的 MCP 服务,实例启动时交给成员的 CLI 去连。',
|
|
32
|
+
group: '给成员的工具',
|
|
33
|
+
needs: ['entry', 'tools', 'topics', 'members', 'cards', 'push'],
|
|
34
|
+
start(ctx) {
|
|
35
|
+
ctx.hook('topic.records', () => '.mcp.json');
|
|
36
|
+
const { sender } = ctx.get('members').register(ctx, { name: '外部 MCP 服务', handle: 'mcp', icon: 'net', color: { primary: '#687889' } });
|
|
37
|
+
const entry = ctx.get('entry');
|
|
38
|
+
const tools = ctx.get('tools');
|
|
39
|
+
const topics = ctx.get('topics');
|
|
40
|
+
ctx.effect(ctx.get('push').forward('mcp.changed'));
|
|
41
|
+
const changed = (change) => ctx.runtime.emit('mcp.changed', change);
|
|
42
|
+
const secretsFile = home.path('secrets', 'mcp.json');
|
|
43
|
+
const doc = (topic, filename = 'mcp.json') => topic ? join(topic.dir, filename) : home.path('plugins', 'mcp', filename);
|
|
44
|
+
const list = (topic) => readJson(doc(topic), []);
|
|
45
|
+
const writeDoc = (topic, name, value) => {
|
|
46
|
+
const path = doc(topic, name);
|
|
47
|
+
if (topic && lstatSync(path, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
48
|
+
throw new HttpError(409, 'MCP 配置和来源选择需要保存在主题自己的文件里');
|
|
49
|
+
}
|
|
50
|
+
writeJson(path, value);
|
|
51
|
+
};
|
|
52
|
+
const topicPrefix = (id) => `topic:${id}:`;
|
|
53
|
+
const secretKey = (name, id) => id ? topicPrefix(id) + name : name;
|
|
54
|
+
const secrets = () => (existsSync(secretsFile) ? JSON.parse(readFileSync(secretsFile, 'utf8')) : {});
|
|
55
|
+
const versionOf = ({ server, topicId }, kept) => {
|
|
56
|
+
const { url, command, args, enabled } = server;
|
|
57
|
+
const credentials = kept[secretKey(server.name, topicId)];
|
|
58
|
+
return `sha256:${hash('sha256', JSON.stringify([url, command, args ?? [], enabled, orderedPairs(credentials?.headers), orderedPairs(credentials?.env)]))}`;
|
|
59
|
+
};
|
|
60
|
+
const writeSecrets = (all) => {
|
|
61
|
+
writeDocuments(home, [{ path: secretsFile, value: all, mode: 0o600 }]);
|
|
62
|
+
};
|
|
63
|
+
const dropSecrets = (matches, kept = secrets()) => {
|
|
64
|
+
const keys = Object.keys(kept).filter(matches);
|
|
65
|
+
if (keys.length) {
|
|
66
|
+
for (const key of keys)
|
|
67
|
+
delete kept[key];
|
|
68
|
+
writeSecrets(kept);
|
|
69
|
+
}
|
|
70
|
+
return kept;
|
|
71
|
+
};
|
|
72
|
+
const activeTopics = new Set(topics.list().map((topic) => topic.id));
|
|
73
|
+
dropSecrets((key) => key.startsWith('topic:') && !activeTopics.has(key.split(':')[1]));
|
|
74
|
+
// Reserve the distributed service names even when their registrars are switched off.
|
|
75
|
+
const platformNames = () => new Set(['hostlet', 'plans', ...tools.servers().map((s) => s.server)]);
|
|
76
|
+
const managed = (server, topic, kind) => ({ kind, path: doc(topic), topicId: topic?.id, server });
|
|
77
|
+
const choiceDoc = (topic) => doc(topic, 'mcp-sources.json');
|
|
78
|
+
const storeChoices = (topic, decisions) => {
|
|
79
|
+
if (Object.keys(decisions).length)
|
|
80
|
+
writeDoc(topic, 'mcp-sources.json', decisions);
|
|
81
|
+
else if (lstatSync(choiceDoc(topic), { throwIfNoEntry: false }))
|
|
82
|
+
unlinkSync(choiceDoc(topic));
|
|
83
|
+
};
|
|
84
|
+
const readNative = (topic) => {
|
|
85
|
+
const path = join(topic.dir, '.mcp.json');
|
|
86
|
+
const entries = new Map();
|
|
87
|
+
if (!existsSync(path))
|
|
88
|
+
return { entries };
|
|
89
|
+
try {
|
|
90
|
+
const data = JSON.parse(readFileSync(path, 'utf8'));
|
|
91
|
+
const servers = data?.mcpServers ?? {};
|
|
92
|
+
if (!servers || typeof servers !== 'object' || Array.isArray(servers))
|
|
93
|
+
return { entries, warning: `无法读取 ${path} 的 mcpServers 对象` };
|
|
94
|
+
for (const [name, definition] of Object.entries(servers)) {
|
|
95
|
+
if (!definition || typeof definition !== 'object' || Array.isArray(definition))
|
|
96
|
+
continue;
|
|
97
|
+
const native = definition;
|
|
98
|
+
if (typeof native.url === 'string' || typeof native.command === 'string')
|
|
99
|
+
entries.set(name, { kind: 'native', path, definition: native });
|
|
100
|
+
}
|
|
101
|
+
return { entries };
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return { entries, warning: `无法读取 ${path} 的 JSON` };
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const sourceLabel = (source) => ({ topic: '本主题', ancestor: '上级主题', global: '全局', native: '客户端原生' }[source.kind]);
|
|
108
|
+
const sourceInfo = (source) => {
|
|
109
|
+
if (source.kind !== 'native') {
|
|
110
|
+
const { description, headers, env } = source.server;
|
|
111
|
+
return { kind: source.kind, path: source.path, topicId: source.topicId, target: targetOf(source.server), description,
|
|
112
|
+
...(headers?.length && { headers }), ...(env?.length && { env }) };
|
|
113
|
+
}
|
|
114
|
+
const { url, command } = source.definition;
|
|
115
|
+
const parsed = typeof url === 'string' && URL.canParse(url) ? new URL(url) : undefined;
|
|
116
|
+
const target = parsed ? parsed.origin + parsed.pathname
|
|
117
|
+
: typeof command === 'string' ? command : '客户端配置';
|
|
118
|
+
return { kind: source.kind, path: source.path, target };
|
|
119
|
+
};
|
|
120
|
+
const describeSource = (source) => {
|
|
121
|
+
const { path, target } = sourceInfo(source);
|
|
122
|
+
return `${sourceLabel(source)} ${path}(${target})`;
|
|
123
|
+
};
|
|
124
|
+
const describeVersion = (version) => version ? `\n上游版本 ${version.slice(0, 19)}` : '';
|
|
125
|
+
const mcpConflict = (name, local, upstream, upstreamVersion) => ({
|
|
126
|
+
key: name,
|
|
127
|
+
kind: local.kind === 'native' ? 'native' : 'topic',
|
|
128
|
+
name,
|
|
129
|
+
localPath: local.path,
|
|
130
|
+
upstream: upstream.path,
|
|
131
|
+
upstreamVersion,
|
|
132
|
+
choices: ['keep-local', 'use-upstream'],
|
|
133
|
+
title: ltext('host.notice.mcp.sourceTitle', { name }),
|
|
134
|
+
body: ltext('host.notice.mcp.sourceDetails', {
|
|
135
|
+
local: describeSource(local), upstream: describeSource(upstream), version: upstreamVersion.slice(0, 19),
|
|
136
|
+
}),
|
|
137
|
+
});
|
|
138
|
+
const sourcesFor = (topic) => {
|
|
139
|
+
const platform = platformNames();
|
|
140
|
+
const above = new Map();
|
|
141
|
+
for (const parent of [...topics.path(topic.id).slice(0, -1).reverse(), undefined]) {
|
|
142
|
+
for (const server of list(parent))
|
|
143
|
+
if (validName(server.name) && !platform.has(server.name) && !above.has(server.name)) {
|
|
144
|
+
above.set(server.name, managed(server, parent, parent ? 'ancestor' : 'global'));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const own = new Map(list(topic).filter((s) => validName(s.name) && !platform.has(s.name)).map((s) => [s.name, managed(s, topic, 'topic')]));
|
|
148
|
+
const { entries: native, warning } = readNative(topic);
|
|
149
|
+
const decisions = readJson(choiceDoc(topic), {});
|
|
150
|
+
const kept = secrets();
|
|
151
|
+
const sources = [];
|
|
152
|
+
for (const name of new Set([...own.keys(), ...above.keys()])) {
|
|
153
|
+
const upstream = above.get(name);
|
|
154
|
+
const local = own.get(name) ?? (upstream && native.get(name));
|
|
155
|
+
const upstreamVersion = local && upstream ? versionOf(upstream, kept) : undefined;
|
|
156
|
+
const conflict = local && upstream && upstreamVersion ? mcpConflict(name, local, upstream, upstreamVersion) : undefined;
|
|
157
|
+
const choice = conflict ? sourceChoiceOf(conflict, decisions) : null;
|
|
158
|
+
const effective = (choice === 'use-upstream' ? upstream : local ?? upstream);
|
|
159
|
+
const on = topics.uses(topic.id, `mcp:${name}`, effective.kind === 'native' ? upstream.server.enabled : effective.server.enabled);
|
|
160
|
+
sources.push({ name, local, upstream, upstreamVersion, effective, choice, on });
|
|
161
|
+
}
|
|
162
|
+
return { sources, decisions, warning, own, kept };
|
|
163
|
+
};
|
|
164
|
+
const mcpConflictFor = (source) => source.local && source.upstream && source.upstreamVersion
|
|
165
|
+
? mcpConflict(source.name, source.local, source.upstream, source.upstreamVersion)
|
|
166
|
+
: undefined;
|
|
167
|
+
const cleanSecrets = (topic, { own, kept }) => {
|
|
168
|
+
const scope = topicPrefix(topic.id);
|
|
169
|
+
return dropSecrets((key) => key.startsWith(scope) && !own.has(key.slice(scope.length)), kept);
|
|
170
|
+
};
|
|
171
|
+
const readSources = (topic) => {
|
|
172
|
+
const state = sourcesFor(topic);
|
|
173
|
+
// An unreadable native file is not evidence that the owner moved it away.
|
|
174
|
+
return {
|
|
175
|
+
conflicts: state.sources.flatMap((source) => {
|
|
176
|
+
const conflict = mcpConflictFor(source);
|
|
177
|
+
return conflict ? [conflict] : [];
|
|
178
|
+
}),
|
|
179
|
+
decisions: state.decisions,
|
|
180
|
+
partial: !!state.warning,
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
const sources = sourceChoices(ctx, {
|
|
184
|
+
sender,
|
|
185
|
+
label: 'MCP',
|
|
186
|
+
read: readSources,
|
|
187
|
+
store: storeChoices,
|
|
188
|
+
chosen: (topic, conflict, choice) => changed({ name: conflict.name, topicId: topic.id, kind: 'selected', choice }),
|
|
189
|
+
});
|
|
190
|
+
const serversFor = (topicId) => {
|
|
191
|
+
const topic = topics.get(topicId);
|
|
192
|
+
if (!topic || topic.deletedAt)
|
|
193
|
+
return { servers: [] };
|
|
194
|
+
const selection = sourcesFor(topic);
|
|
195
|
+
const kept = selection.kept;
|
|
196
|
+
const servers = [];
|
|
197
|
+
const native = [];
|
|
198
|
+
for (const { name, effective, on } of selection.sources) {
|
|
199
|
+
if (effective.kind === 'native') {
|
|
200
|
+
native.push([name, effective.definition]);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (!on)
|
|
204
|
+
continue;
|
|
205
|
+
const { server: s, topicId: id } = effective;
|
|
206
|
+
const credentials = kept[secretKey(name, id)];
|
|
207
|
+
servers.push({
|
|
208
|
+
name,
|
|
209
|
+
external: true,
|
|
210
|
+
...(s.url ? { url: s.url, headers: credentials?.headers ?? {} } : { command: s.command ?? '', args: s.args ?? [], env: credentials?.env ?? {} }),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
const files = native.length ? hash('sha256', JSON.stringify(native.sort(([a], [b]) => a.localeCompare(b)))) : undefined;
|
|
214
|
+
return { servers, files };
|
|
215
|
+
};
|
|
216
|
+
ctx.hook('topic.caps', ({ topicId }) => {
|
|
217
|
+
const topic = topics.get(topicId);
|
|
218
|
+
if (!topic || topic.deletedAt)
|
|
219
|
+
return [];
|
|
220
|
+
return sourcesFor(topic).sources.map(({ name, effective, upstream }) => {
|
|
221
|
+
const managed = effective.kind === 'native' ? upstream.server : effective.server;
|
|
222
|
+
return { id: `mcp:${name}`, title: name, about: managed.description || targetOf(managed), group: '外部 MCP 服务', default: managed.enabled };
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
ctx.note('session.mcp', { title: '这个主题选用的外部 MCP 服务', when: '按主题开关和来源选择下发(纯只读)' });
|
|
226
|
+
ctx.hook('session.mcp', ({ topicId }) => serversFor(topicId).servers);
|
|
227
|
+
ctx.note('session.input', { title: '客户端原生 .mcp.json 同名配置的只读指纹', when: '本主题存在生效的原生 MCP 覆盖时(参与 tools 维度刷新)' });
|
|
228
|
+
ctx.hook('session.input', ({ topicId }) => {
|
|
229
|
+
const { files } = serversFor(topicId);
|
|
230
|
+
return files ? { tools: files } : undefined;
|
|
231
|
+
});
|
|
232
|
+
ctx.note('session.prepare', { title: '核对外部 MCP 同名来源卡并清理失效密钥与选择', when: '仅在真正拉起或重启实例前执行' });
|
|
233
|
+
ctx.hook('session.prepare', async ({ topicId }) => {
|
|
234
|
+
const topic = topics.get(topicId);
|
|
235
|
+
if (!topic || topic.deletedAt)
|
|
236
|
+
return;
|
|
237
|
+
cleanSecrets(topic, sourcesFor(topic));
|
|
238
|
+
await sources.refresh(topic);
|
|
239
|
+
});
|
|
240
|
+
ctx.note('turn.init', { title: '核对被本地覆盖的上游 MCP 同名版本卡', when: '主题开始新回合时(不改变回合文本)' });
|
|
241
|
+
ctx.hook('turn.init', async ({ topicId, append }) => {
|
|
242
|
+
if (append)
|
|
243
|
+
return undefined;
|
|
244
|
+
const topic = topics.get(topicId);
|
|
245
|
+
if (!topic || topic.deletedAt)
|
|
246
|
+
return undefined;
|
|
247
|
+
cleanSecrets(topic, sourcesFor(topic));
|
|
248
|
+
await sources.refresh(topic);
|
|
249
|
+
return undefined;
|
|
250
|
+
});
|
|
251
|
+
ctx.on('topic.updated', ({ topic, capsChanged }) => {
|
|
252
|
+
for (const { id, on } of capsChanged ?? []) {
|
|
253
|
+
if (id.startsWith('mcp:'))
|
|
254
|
+
changed({ name: id.slice('mcp:'.length), topicId: topic.id, kind: 'overridden', on });
|
|
255
|
+
}
|
|
256
|
+
if (!topic.deletedAt)
|
|
257
|
+
return;
|
|
258
|
+
dropSecrets((key) => key.startsWith(topicPrefix(topic.id)));
|
|
259
|
+
});
|
|
260
|
+
// Values of env and headers are never sent back: only their names.
|
|
261
|
+
// Only the tool list is cached. The connection (including its credentials) is hashed as the lookup key.
|
|
262
|
+
const cachedTools = (server, kept) => home.storage.cacheFile('mcp-tools', [server.name, server.url, server.command, server.args, kept]);
|
|
263
|
+
/** Connect the way a member's client would, ask what tools there are, and leave. */
|
|
264
|
+
const probe = async (server, kept) => {
|
|
265
|
+
const hello = { protocolVersion: '2025-03-26', capabilities: {}, clientInfo: { name: 'hostlet', version: '0.1.0' } };
|
|
266
|
+
const read = (result) => (Array.isArray(result?.tools) ? result.tools : []).map((tool) => ({
|
|
267
|
+
name: String(tool.name),
|
|
268
|
+
description: String(tool.description ?? ''),
|
|
269
|
+
...(tool.inputSchema && typeof tool.inputSchema === 'object' ? { inputSchema: tool.inputSchema } : {}),
|
|
270
|
+
}));
|
|
271
|
+
if (server.url) {
|
|
272
|
+
let session;
|
|
273
|
+
const call = async (method, params, id) => {
|
|
274
|
+
const res = await fetch(server.url, {
|
|
275
|
+
method: 'POST', signal: AbortSignal.timeout(20_000),
|
|
276
|
+
headers: { 'content-type': 'application/json', accept: 'application/json, text/event-stream', ...(session ? { 'mcp-session-id': session } : {}), ...kept.headers },
|
|
277
|
+
body: JSON.stringify({ jsonrpc: '2.0', ...(id ? { id } : {}), method, params }),
|
|
278
|
+
});
|
|
279
|
+
if (!res.ok)
|
|
280
|
+
throw new Error(`${res.status} ${res.statusText}`);
|
|
281
|
+
session = res.headers.get('mcp-session-id') ?? session;
|
|
282
|
+
if (!id)
|
|
283
|
+
return undefined;
|
|
284
|
+
const text = await res.text();
|
|
285
|
+
const message = JSON.parse(/^data: (.+)$/m.exec(text)?.[1] ?? text);
|
|
286
|
+
if (message.error)
|
|
287
|
+
throw new Error(message.error.message ?? '服务报错');
|
|
288
|
+
return message.result;
|
|
289
|
+
};
|
|
290
|
+
await call('initialize', hello, 1);
|
|
291
|
+
await call('notifications/initialized', {});
|
|
292
|
+
return read(await call('tools/list', {}, 2));
|
|
293
|
+
}
|
|
294
|
+
const peer = startRpc(server.command ?? '', server.args ?? [], { cwd: tmpdir(), env: { ...process.env, ...kept.env }, tagged: true, startChild, onNotification() { }, onRequest: (id) => peer.reject(id, 'not available') });
|
|
295
|
+
try {
|
|
296
|
+
const gone = peer.child.exited.then(({ code, stderr }) => { throw new Error(`它退出了(code ${code})${stderr ? `:${stderr.trim().split('\n').at(-1)}` : ''}`); });
|
|
297
|
+
const asked = (async () => {
|
|
298
|
+
await peer.request('initialize', hello, 20_000);
|
|
299
|
+
peer.notify('notifications/initialized', {});
|
|
300
|
+
return read(await peer.request('tools/list', {}, 20_000));
|
|
301
|
+
})();
|
|
302
|
+
return await Promise.race([asked, gone]);
|
|
303
|
+
}
|
|
304
|
+
finally {
|
|
305
|
+
await stopRpc(peer, true);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
/** The topics that say for themselves whether they use a server; all others follow its default. */
|
|
309
|
+
const topicsOf = (prefix, name) => topics.list().filter((topic) => `${prefix}:${name}` in topic.caps)
|
|
310
|
+
.map((topic) => ({ id: topic.id, title: topics.path(topic.id).map((x) => x.title).join(' › '), on: topic.caps[`${prefix}:${name}`] }));
|
|
311
|
+
const sourcesOf = (list) => {
|
|
312
|
+
const seen = new Map();
|
|
313
|
+
for (const item of list)
|
|
314
|
+
seen.set(item.source.core ? 'core' : item.source.plugin ? `plugin:${item.source.plugin}` : `title:${item.source.title}`, item.source);
|
|
315
|
+
return [...seen.values()];
|
|
316
|
+
};
|
|
317
|
+
ctx.effect(entry.group('mcp', '宿主和外部 MCP 服务、工具清单和默认开关'));
|
|
318
|
+
const name = { type: 'string', description: 'MCP 服务的名字' };
|
|
319
|
+
const id = { type: 'string', description: '主题编号' };
|
|
320
|
+
const saveFields = {
|
|
321
|
+
name, target: { type: 'string', description: '服务地址或启动命令。含空格的程序路径或参数各自用引号括起。' },
|
|
322
|
+
description: { type: 'string', description: '服务的用途' },
|
|
323
|
+
env: { type: 'string', secret: true, format: 'key-value-lines', title: '环境变量或请求头', description: '每行一个名字和值。HTTP 服务使用请求头,命令使用环境变量。' },
|
|
324
|
+
toggle: { type: 'boolean', description: '只改默认开关时填写' },
|
|
325
|
+
};
|
|
326
|
+
const needTopic = (id) => {
|
|
327
|
+
const topic = topics.get(id);
|
|
328
|
+
if (!topic || topic.deletedAt)
|
|
329
|
+
throw new HttpError(404, '没有这个主题');
|
|
330
|
+
return topic;
|
|
331
|
+
};
|
|
332
|
+
const save = (input, topic) => {
|
|
333
|
+
const name = input.name.trim();
|
|
334
|
+
if (!validName(name))
|
|
335
|
+
throw new HttpError(400, '名字只能用字母、数字、- 和 _');
|
|
336
|
+
if (platformNames().has(name))
|
|
337
|
+
throw new HttpError(400, `${name} 是平台自己的服务名,换一个`);
|
|
338
|
+
const all = list(topic);
|
|
339
|
+
const existing = all.find((s) => s.name === name);
|
|
340
|
+
const scope = topic ? { name, topicId: topic.id } : { name };
|
|
341
|
+
const { toggle } = input;
|
|
342
|
+
if (toggle !== undefined) {
|
|
343
|
+
if (!existing)
|
|
344
|
+
throw new HttpError(404, '没有这个服务');
|
|
345
|
+
if (existing.enabled === toggle)
|
|
346
|
+
return;
|
|
347
|
+
writeDoc(topic, 'mcp.json', all.map((s) => (s.name === name ? { ...s, enabled: toggle } : s)));
|
|
348
|
+
changed({ ...scope, kind: 'switched', on: toggle });
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
const target = input.target?.trim() ?? '';
|
|
352
|
+
if (!target)
|
|
353
|
+
throw new HttpError(400, '填它的地址(http 开头)或启动命令');
|
|
354
|
+
const http = /^https?:\/\//.test(target);
|
|
355
|
+
// An edit may keep this source's values. An inherited definition has its own credentials.
|
|
356
|
+
const previous = secrets();
|
|
357
|
+
const key = secretKey(name, topic?.id);
|
|
358
|
+
const kept = input.env === undefined && existing ? previous[key] ?? {} : undefined;
|
|
359
|
+
const env = http ? {} : kept?.env ?? pairs(input.env);
|
|
360
|
+
const headers = http ? kept?.headers ?? pairs(input.env) : {};
|
|
361
|
+
const description = input.description?.trim() ?? existing?.description;
|
|
362
|
+
const saved = {
|
|
363
|
+
name, ...(description ? { description } : {}), enabled: existing?.enabled ?? true,
|
|
364
|
+
...(http ? { url: target, headers: Object.keys(headers) } : { ...stdioTarget(target), env: Object.keys(env) }),
|
|
365
|
+
};
|
|
366
|
+
const credentials = http ? { headers } : { env };
|
|
367
|
+
if (isDeepStrictEqual(existing, saved) && isDeepStrictEqual(previous[key], credentials))
|
|
368
|
+
return;
|
|
369
|
+
writeSecrets({ ...previous, [key]: credentials });
|
|
370
|
+
try {
|
|
371
|
+
writeDoc(topic, 'mcp.json', existing ? all.map((s) => (s.name === name ? saved : s)) : [...all, saved]);
|
|
372
|
+
}
|
|
373
|
+
catch (error) {
|
|
374
|
+
writeSecrets(previous);
|
|
375
|
+
throw error;
|
|
376
|
+
}
|
|
377
|
+
if (!topic && existing)
|
|
378
|
+
cachedTools(existing, previous[key] ?? {}).discard();
|
|
379
|
+
changed({ ...scope, kind: existing ? 'updated' : 'added' });
|
|
380
|
+
};
|
|
381
|
+
const remove = (name, topic) => {
|
|
382
|
+
const all = list(topic);
|
|
383
|
+
const existing = all.find((s) => s.name === name);
|
|
384
|
+
const key = secretKey(name, topic?.id);
|
|
385
|
+
const { [key]: gone, ...rest } = secrets();
|
|
386
|
+
writeDoc(topic, 'mcp.json', all.filter((s) => s.name !== name));
|
|
387
|
+
if (gone)
|
|
388
|
+
writeSecrets(rest);
|
|
389
|
+
if (!topic && existing)
|
|
390
|
+
cachedTools(existing, gone ?? {}).discard();
|
|
391
|
+
if (existing)
|
|
392
|
+
changed({ name, ...(topic ? { topicId: topic.id } : {}), kind: 'removed' });
|
|
393
|
+
};
|
|
394
|
+
ctx.effect(entry.op({
|
|
395
|
+
name: 'mcp.list', about: '列出宿主和外部 MCP 服务、已知的工具和各主题的开关。',
|
|
396
|
+
http: ['GET', '/api/mcp'], agent: true,
|
|
397
|
+
run(_args, caller) {
|
|
398
|
+
const kept = secrets();
|
|
399
|
+
const platform = platformNames();
|
|
400
|
+
return {
|
|
401
|
+
host: tools.servers(caller.member ? caller.topicId : undefined).map((s) => ({ ...s, sources: sourcesOf(s.tools), topics: topicsOf('tools', s.server) })),
|
|
402
|
+
external: list().filter((s) => !platform.has(s.name)).map((s) => ({ ...s, target: targetOf(s), tools: cachedTools(s, kept[s.name] ?? {}).read(), topics: topicsOf('mcp', s.name) })),
|
|
403
|
+
};
|
|
404
|
+
},
|
|
405
|
+
}));
|
|
406
|
+
ctx.effect(entry.op({
|
|
407
|
+
name: 'mcp.probe', about: '连接一次 MCP 服务(外部或平台内置)并验证它的工具清单。',
|
|
408
|
+
input: object({ name }, ['name']), http: ['POST', '/api/mcp/:name/probe'],
|
|
409
|
+
async run({ name }) {
|
|
410
|
+
const server = platformNames().has(name) ? undefined : list().find((s) => s.name === name);
|
|
411
|
+
if (server) {
|
|
412
|
+
const kept = secrets()[name] ?? {};
|
|
413
|
+
try {
|
|
414
|
+
return { tools: await cachedTools(server, kept).refresh(() => probe(server, kept)) };
|
|
415
|
+
}
|
|
416
|
+
catch (problem) {
|
|
417
|
+
throw new HttpError(400, `没连上:${errorText(problem)}`);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (tools.servers().some((s) => s.server === name)) {
|
|
421
|
+
try {
|
|
422
|
+
return { tools: await tools.probe(name) };
|
|
423
|
+
}
|
|
424
|
+
catch (problem) {
|
|
425
|
+
throw new HttpError(400, `没连上:${errorText(problem)}`);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
throw new HttpError(404, '没有这个服务');
|
|
429
|
+
},
|
|
430
|
+
}));
|
|
431
|
+
ctx.effect(entry.op({
|
|
432
|
+
name: 'mcp.save', about: '添加或编辑外部 MCP 服务,或改它的默认开关。',
|
|
433
|
+
input: object(saveFields, ['name']),
|
|
434
|
+
http: ['POST', '/api/mcp'], agent: 'approve',
|
|
435
|
+
validate: ({ env }) => { if (env !== undefined)
|
|
436
|
+
pairs(env); },
|
|
437
|
+
approval: ({ name }) => ({ title: '保存外部 MCP 服务', target: name }),
|
|
438
|
+
run: (input) => save(input),
|
|
439
|
+
}));
|
|
440
|
+
ctx.effect(entry.op({
|
|
441
|
+
name: 'mcp.remove', about: '删除一个外部 MCP 服务及其环境变量或请求头。',
|
|
442
|
+
input: object({ name }, ['name']),
|
|
443
|
+
http: ['DELETE', '/api/mcp/:name'], agent: 'approve',
|
|
444
|
+
approval: ({ name }) => ({
|
|
445
|
+
title: '删除外部 MCP 服务', target: name, risk: '同时删除该服务的环境变量或请求头',
|
|
446
|
+
}),
|
|
447
|
+
run: ({ name }) => remove(name),
|
|
448
|
+
}));
|
|
449
|
+
ctx.effect(entry.op({
|
|
450
|
+
name: 'mcp.topic_save', about: '在这个主题添加、编辑或移除外部 MCP 服务。',
|
|
451
|
+
input: object({ id, ...saveFields, remove: { type: 'boolean', description: '删除这个主题自己的服务' } }, ['id', 'name']),
|
|
452
|
+
http: ['POST', '/api/topics/:id/mcp'], agent: 'approve', topic: 'id',
|
|
453
|
+
validate: ({ env }) => { if (env !== undefined)
|
|
454
|
+
pairs(env); },
|
|
455
|
+
approval: ({ name, remove }) => ({ title: remove ? '移除本主题的 MCP 服务' : '保存本主题的 MCP 服务', target: name }),
|
|
456
|
+
async run({ id, remove: removing, ...input }) {
|
|
457
|
+
const topic = needTopic(id);
|
|
458
|
+
if (topic.archivedAt !== null)
|
|
459
|
+
throw new HttpError(409, '主题已归档');
|
|
460
|
+
if (removing)
|
|
461
|
+
remove(input.name.trim(), topic);
|
|
462
|
+
else
|
|
463
|
+
save(input, topic);
|
|
464
|
+
cleanSecrets(topic, sourcesFor(topic));
|
|
465
|
+
await sources.refresh(topic);
|
|
466
|
+
},
|
|
467
|
+
}));
|
|
468
|
+
ctx.effect(entry.op({
|
|
469
|
+
name: 'mcp.conflict', about: '为这个主题选择本地或上游的同名 MCP 服务。',
|
|
470
|
+
input: object({ id, name, choice: { type: ['string', 'null'], enum: ['keep-local', 'use-upstream', null] }, upstreamVersion: { type: 'string', description: '来源卡中显示的上游版本' } }, ['id', 'name', 'choice']),
|
|
471
|
+
http: ['POST', '/api/topics/:id/mcp/conflict'], topic: 'id',
|
|
472
|
+
async run({ id, name, choice, upstreamVersion }) {
|
|
473
|
+
await sources.choose(needTopic(id), name, choice, upstreamVersion);
|
|
474
|
+
},
|
|
475
|
+
}));
|
|
476
|
+
ctx.effect(entry.op({
|
|
477
|
+
name: 'mcp.topic_sources', about: '查看这个主题各个外部 MCP 服务的生效来源、本地来源和上游来源。',
|
|
478
|
+
input: object({ id }, ['id']), http: ['GET', '/api/topics/:id/mcp/sources'], agent: true, topic: 'id',
|
|
479
|
+
run({ id }) {
|
|
480
|
+
const { sources, warning } = sourcesFor(needTopic(id));
|
|
481
|
+
return {
|
|
482
|
+
sources: sources.map(({ name, effective, local, upstream, upstreamVersion, choice, on }) => ({
|
|
483
|
+
name, effective: sourceInfo(effective), local: local ? sourceInfo(local) : null, upstream: upstream ? sourceInfo(upstream) : null, upstreamVersion, choice, on,
|
|
484
|
+
text: [local && describeSource(local), upstream && describeSource(upstream)].filter(Boolean).join('\n') + describeVersion(upstreamVersion),
|
|
485
|
+
state: effective.kind === 'native' ? '客户端原生' : on ? `使用${sourceLabel(effective)}` : '停用',
|
|
486
|
+
})),
|
|
487
|
+
...(warning ? { warning } : {}),
|
|
488
|
+
};
|
|
489
|
+
},
|
|
490
|
+
}));
|
|
491
|
+
},
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
export default mcpPlugin;
|