hostlet 0.0.0-stage → 0.1.0-alpha.1
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 +916 -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 +130 -0
- package/dist/plugins/model-profiles/rules.js +729 -0
- package/dist/plugins/model-profiles/skills/model-profile/SKILL.md +59 -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 +84 -0
- package/dist/plugins/model-profiles/storage.js +315 -0
- package/dist/plugins/model-profiles/types.d.ts +179 -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 +455 -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 +270 -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,190 @@
|
|
|
1
|
+
import type { Ctx, Plugin } from '../runtime/runtime.ts';
|
|
2
|
+
import type { Home } from './home.ts';
|
|
3
|
+
import { type FromSchema } from './ops.ts';
|
|
4
|
+
import type { ConfigField } from './config-schema.ts';
|
|
5
|
+
import type { Member, Message, Sender } from './types.ts';
|
|
6
|
+
declare const memberOutput: {
|
|
7
|
+
type: "object";
|
|
8
|
+
properties: {
|
|
9
|
+
readonly persona: {
|
|
10
|
+
readonly type: "boolean";
|
|
11
|
+
readonly const: true;
|
|
12
|
+
readonly description: "插件成员声明为对话身份时为 true";
|
|
13
|
+
};
|
|
14
|
+
readonly icon: {
|
|
15
|
+
readonly type: "string";
|
|
16
|
+
readonly description: "插件成员声明的头像图形,控制台图标库里的图形名";
|
|
17
|
+
};
|
|
18
|
+
readonly suggest: {
|
|
19
|
+
readonly type: "boolean";
|
|
20
|
+
readonly const: false;
|
|
21
|
+
readonly description: "插件成员声明不出现在机主输入框的 @ 候选里时为 false;成员行首 @ 它仍然有效";
|
|
22
|
+
};
|
|
23
|
+
readonly needsHandling: {
|
|
24
|
+
readonly type: "boolean";
|
|
25
|
+
readonly const: true;
|
|
26
|
+
readonly description: "插件成员发出待处理输入时为 true";
|
|
27
|
+
};
|
|
28
|
+
readonly canReceive: {
|
|
29
|
+
readonly type: "boolean";
|
|
30
|
+
};
|
|
31
|
+
readonly id: {
|
|
32
|
+
readonly type: "string";
|
|
33
|
+
};
|
|
34
|
+
readonly kind: {
|
|
35
|
+
readonly type: "string";
|
|
36
|
+
readonly enum: readonly ["agent", "person", "plugin"];
|
|
37
|
+
};
|
|
38
|
+
readonly name: {
|
|
39
|
+
readonly type: "string";
|
|
40
|
+
};
|
|
41
|
+
readonly handle: {
|
|
42
|
+
readonly type: "string";
|
|
43
|
+
};
|
|
44
|
+
readonly adapter: {
|
|
45
|
+
readonly type: "string";
|
|
46
|
+
};
|
|
47
|
+
readonly options: {
|
|
48
|
+
readonly type: "object";
|
|
49
|
+
};
|
|
50
|
+
readonly key: {
|
|
51
|
+
readonly type: "string";
|
|
52
|
+
};
|
|
53
|
+
readonly env: {
|
|
54
|
+
readonly type: "object";
|
|
55
|
+
readonly additionalProperties: {
|
|
56
|
+
readonly type: "string";
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
readonly color: {
|
|
60
|
+
readonly type: readonly ["string", "object"];
|
|
61
|
+
readonly properties: {
|
|
62
|
+
readonly primary: {
|
|
63
|
+
readonly type: "string";
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
readonly required: readonly ["primary"];
|
|
67
|
+
readonly additionalProperties: false;
|
|
68
|
+
};
|
|
69
|
+
readonly avatarPath: {
|
|
70
|
+
readonly type: "string";
|
|
71
|
+
};
|
|
72
|
+
readonly enabled: {
|
|
73
|
+
readonly type: "boolean";
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
required: readonly ["id", "kind", "name", "handle", "adapter", "options", "enabled", "canReceive"];
|
|
77
|
+
additionalProperties: false;
|
|
78
|
+
};
|
|
79
|
+
type MemberProfile = Omit<FromSchema<typeof memberOutput>, 'canReceive'>;
|
|
80
|
+
/** The person the host belongs to: a name members see, and the @ name they address. */
|
|
81
|
+
declare const ownerOutput: {
|
|
82
|
+
type: "object";
|
|
83
|
+
properties: {
|
|
84
|
+
readonly name: {
|
|
85
|
+
readonly type: "string";
|
|
86
|
+
};
|
|
87
|
+
readonly handle: {
|
|
88
|
+
readonly type: "string";
|
|
89
|
+
};
|
|
90
|
+
readonly avatarPath: {
|
|
91
|
+
readonly type: "string";
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
required: readonly ["name", "handle"];
|
|
95
|
+
additionalProperties: false;
|
|
96
|
+
};
|
|
97
|
+
export type Owner = FromSchema<typeof ownerOutput>;
|
|
98
|
+
type PictureEdit = {
|
|
99
|
+
avatarPng?: string | null;
|
|
100
|
+
};
|
|
101
|
+
type OwnerEdit = Pick<Owner, 'name' | 'handle'> & PictureEdit;
|
|
102
|
+
type MemberEdit = Omit<Partial<Member>, 'env'> & Pick<Member, 'name'> & PictureEdit & {
|
|
103
|
+
env?: Record<string, string> | null;
|
|
104
|
+
};
|
|
105
|
+
type Identity = Pick<MemberProfile, 'name' | 'handle' | 'color' | 'avatarPath' | 'persona' | 'icon' | 'suggest' | 'needsHandling'>;
|
|
106
|
+
export type PluginDelivery = {
|
|
107
|
+
message: Message;
|
|
108
|
+
credential: string;
|
|
109
|
+
};
|
|
110
|
+
export type PluginMemberAttachment = {
|
|
111
|
+
name: string;
|
|
112
|
+
data: Uint8Array;
|
|
113
|
+
};
|
|
114
|
+
export type PluginMemberRegistration = Omit<Identity, 'needsHandling'> & {
|
|
115
|
+
namespace?: string;
|
|
116
|
+
/** Route unaddressed messages from this identity as conversation input. */
|
|
117
|
+
needsHandling?: boolean;
|
|
118
|
+
/** Resolving acknowledges delivery. Keep the credential to reply after the receive call. */
|
|
119
|
+
receive?: (delivery: PluginDelivery) => void | Promise<void>;
|
|
120
|
+
};
|
|
121
|
+
export type PluginMemberSend = Pick<Message, 'topicId' | 'content' | 'visibility' | 'threadable'> & {
|
|
122
|
+
targets?: string[];
|
|
123
|
+
replyTo?: string;
|
|
124
|
+
thread?: string;
|
|
125
|
+
attachments?: readonly PluginMemberAttachment[];
|
|
126
|
+
parts?: Message['parts'];
|
|
127
|
+
};
|
|
128
|
+
export type PluginMemberReply = {
|
|
129
|
+
credential: string;
|
|
130
|
+
content: string;
|
|
131
|
+
/** Supply the parsed recipients of an incoming reply, including an empty list when nobody was mentioned. */
|
|
132
|
+
targets?: string[];
|
|
133
|
+
attachments?: readonly PluginMemberAttachment[];
|
|
134
|
+
};
|
|
135
|
+
export interface PluginMember {
|
|
136
|
+
readonly id: string;
|
|
137
|
+
readonly sender: {
|
|
138
|
+
readonly kind: 'member';
|
|
139
|
+
readonly id: string;
|
|
140
|
+
};
|
|
141
|
+
send(input: PluginMemberSend): {
|
|
142
|
+
message: Message;
|
|
143
|
+
targets: string[];
|
|
144
|
+
};
|
|
145
|
+
reply(input: PluginMemberReply): Message;
|
|
146
|
+
}
|
|
147
|
+
/** The id of the person the host belongs to. */
|
|
148
|
+
export declare const OWNER_ID = "owner";
|
|
149
|
+
/** Member identities and their declared delivery capabilities. */
|
|
150
|
+
export interface Members {
|
|
151
|
+
owner(): Owner;
|
|
152
|
+
setOwner(owner: OwnerEdit): Owner;
|
|
153
|
+
ownerPicture(file: string): Buffer | undefined;
|
|
154
|
+
/** Agents and plugin-provided identities. */
|
|
155
|
+
list(): MemberProfile[];
|
|
156
|
+
/** The people. Today that is the owner alone. */
|
|
157
|
+
people(): Member[];
|
|
158
|
+
/** Any channel identity, including stopped plugin members. */
|
|
159
|
+
get(id: string): MemberProfile | undefined;
|
|
160
|
+
/** Whether this identity declares delivery, even while stopped. */
|
|
161
|
+
acceptsDelivery(id: string): boolean;
|
|
162
|
+
/** Whether this identity may receive a message now. */
|
|
163
|
+
canReceive(id: string): boolean;
|
|
164
|
+
receiver(id: string): PluginMemberRegistration['receive'];
|
|
165
|
+
isRegisteredSender(sender: Sender): boolean;
|
|
166
|
+
/** The active plugin context which registered this channel identity may receive its private submission. */
|
|
167
|
+
ownsSender(plugin: Ctx, id: string): boolean;
|
|
168
|
+
register(ctx: Ctx, declaration: PluginMemberRegistration): PluginMember;
|
|
169
|
+
save(member: MemberEdit): MemberProfile;
|
|
170
|
+
remove(id: string): void;
|
|
171
|
+
}
|
|
172
|
+
declare module '../runtime/runtime.ts' {
|
|
173
|
+
interface Services {
|
|
174
|
+
members: Members;
|
|
175
|
+
}
|
|
176
|
+
interface Hooks {
|
|
177
|
+
/** Options a plugin adds to a member's form, kept with the member's other options (a threshold of its own, say). */
|
|
178
|
+
'member.options': [{
|
|
179
|
+
adapter: string;
|
|
180
|
+
}, ConfigField[]];
|
|
181
|
+
}
|
|
182
|
+
interface Events {
|
|
183
|
+
'members.changed': {
|
|
184
|
+
id: string;
|
|
185
|
+
removed?: boolean;
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
export declare function membersPlugin(home: Home): Plugin;
|
|
190
|
+
export {};
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { extname } from 'node:path';
|
|
4
|
+
import { configOwnership } from "./config.js";
|
|
5
|
+
import { HANDLED, HttpError } from "./entry.js";
|
|
6
|
+
import { array, object } from "./ops.js";
|
|
7
|
+
import { memberSchema } from "./types.js";
|
|
8
|
+
import { newId, readJson, writeJson } from "./util.js";
|
|
9
|
+
const { name, handle, avatarPath, color, enabled } = memberSchema.properties;
|
|
10
|
+
const avatarPngInput = { type: ['string', 'null'], description: '方形 PNG 的 Base64,最长边 256 像素;null 清除,省略则保留' };
|
|
11
|
+
const avatarBodyLimit = 512 * 1024;
|
|
12
|
+
const memberOutput = object({
|
|
13
|
+
...memberSchema.properties,
|
|
14
|
+
persona: { type: 'boolean', const: true, description: '插件成员声明为对话身份时为 true' },
|
|
15
|
+
icon: { type: 'string', description: '插件成员声明的头像图形,控制台图标库里的图形名' },
|
|
16
|
+
suggest: { type: 'boolean', const: false, description: '插件成员声明不出现在机主输入框的 @ 候选里时为 false;成员行首 @ 它仍然有效' },
|
|
17
|
+
needsHandling: { type: 'boolean', const: true, description: '插件成员发出待处理输入时为 true' },
|
|
18
|
+
canReceive: { type: 'boolean' },
|
|
19
|
+
}, [...memberSchema.required, 'canReceive']);
|
|
20
|
+
/** The person the host belongs to: a name members see, and the @ name they address. */
|
|
21
|
+
const ownerOutput = object({ name, handle, avatarPath }, ['name', 'handle']);
|
|
22
|
+
const iconSuffix = /\.(?:png|svg|jpe?g|gif|webp|avif|ico)$/;
|
|
23
|
+
function validateAppearance(input) {
|
|
24
|
+
if (typeof input.color === 'object' && !/^#[\da-f]{6}$/i.test(input.color.primary))
|
|
25
|
+
throw new Error('成员主题色需要六位十六进制色值');
|
|
26
|
+
if (input.avatarPath && !/^\/(?!\/)[\p{L}\p{N}._~%/-]+$/u.test(input.avatarPath))
|
|
27
|
+
throw new Error('头像需要本地控制台的资源路径');
|
|
28
|
+
}
|
|
29
|
+
/** The console crops the chosen picture before sending it. Only the small PNG lives in the profile. */
|
|
30
|
+
function profilePicture(png) {
|
|
31
|
+
if (png.length > 400_000)
|
|
32
|
+
throw new Error('头像图片太大');
|
|
33
|
+
const bytes = Buffer.from(png, 'base64');
|
|
34
|
+
const side = bytes.length >= 45 ? bytes.readUInt32BE(16) : 0;
|
|
35
|
+
if (!side || side > 256 || bytes.readUInt32BE(20) !== side ||
|
|
36
|
+
bytes.toString('hex', 0, 16) !== '89504e470d0a1a0a0000000d49484452' ||
|
|
37
|
+
bytes.toString('hex', bytes.length - 12) !== '0000000049454e44ae426082' || bytes.toString('base64') !== png) {
|
|
38
|
+
throw new Error('头像需要是最大 256 像素的正方形 PNG');
|
|
39
|
+
}
|
|
40
|
+
return { file: createHash('sha256').update(bytes).digest('hex') + '.png', bytes, png };
|
|
41
|
+
}
|
|
42
|
+
function withPicture(member, picture) {
|
|
43
|
+
if (picture)
|
|
44
|
+
member.avatarPath = `/api/members/${encodeURIComponent(member.id)}/avatar/${picture.file}`;
|
|
45
|
+
return { member, picture };
|
|
46
|
+
}
|
|
47
|
+
function sendPicture(res, bytes) {
|
|
48
|
+
if (!bytes)
|
|
49
|
+
throw new HttpError(404, '没有这张头像');
|
|
50
|
+
res.writeHead(200, { 'content-type': 'image/png', 'content-length': bytes.length, 'x-content-type-options': 'nosniff', 'cache-control': 'private, no-cache' }).end(bytes);
|
|
51
|
+
return HANDLED;
|
|
52
|
+
}
|
|
53
|
+
/** The id of the person the host belongs to. */
|
|
54
|
+
export const OWNER_ID = 'owner';
|
|
55
|
+
export function membersPlugin(home) {
|
|
56
|
+
return {
|
|
57
|
+
name: 'members',
|
|
58
|
+
core: true,
|
|
59
|
+
needs: ['config', 'entry'],
|
|
60
|
+
start(ctx) {
|
|
61
|
+
const config = configOwnership(ctx.get('config'));
|
|
62
|
+
const membersFile = home.path('members.json');
|
|
63
|
+
const pluginMembersFile = home.path('plugin-members.json');
|
|
64
|
+
const iconsDir = home.path('member-icons');
|
|
65
|
+
const ownerAvatarFile = home.path('owner-avatar.json');
|
|
66
|
+
const readAll = () => readJson(membersFile, []).map(({ avatarPng, ...member }) => withPicture({ ...member, kind: 'agent' }, avatarPng ? profilePicture(avatarPng) : undefined));
|
|
67
|
+
let profiles = readAll();
|
|
68
|
+
const find = (id) => profiles.find(({ member }) => member.id === id);
|
|
69
|
+
const registered = new Map();
|
|
70
|
+
const pluginProfile = (stored, enabled = registered.has(stored.id)) => {
|
|
71
|
+
const { avatarPng, ...override } = stored.override ?? {};
|
|
72
|
+
const member = {
|
|
73
|
+
id: stored.id, kind: 'plugin', adapter: '', options: {}, enabled,
|
|
74
|
+
...stored.identity, ...override,
|
|
75
|
+
};
|
|
76
|
+
if (avatarPng === null)
|
|
77
|
+
delete member.avatarPath;
|
|
78
|
+
return { stored, profile: withPicture(member, avatarPng ? profilePicture(avatarPng) : undefined) };
|
|
79
|
+
};
|
|
80
|
+
const plugins = new Map(readJson(pluginMembersFile, []).map((stored) => [stored.id, pluginProfile(stored)]));
|
|
81
|
+
const writePlugin = (stored, enabled) => {
|
|
82
|
+
const next = pluginProfile(stored, enabled);
|
|
83
|
+
if (JSON.stringify(plugins.get(stored.id)?.stored) !== JSON.stringify(stored)) {
|
|
84
|
+
const records = new Map([...plugins].map(([id, value]) => [id, value.stored]));
|
|
85
|
+
records.set(stored.id, stored);
|
|
86
|
+
writeJson(pluginMembersFile, [...records.values()]);
|
|
87
|
+
}
|
|
88
|
+
plugins.set(stored.id, next);
|
|
89
|
+
return next.profile.member;
|
|
90
|
+
};
|
|
91
|
+
const list = () => [
|
|
92
|
+
...profiles.map(({ member }) => member),
|
|
93
|
+
...[...plugins.values()].map(({ profile }) => profile.member),
|
|
94
|
+
];
|
|
95
|
+
const saveIcon = (path) => {
|
|
96
|
+
const suffix = extname(path).toLowerCase();
|
|
97
|
+
if (!iconSuffix.test(suffix))
|
|
98
|
+
throw new Error('插件成员图标需要是图片文件');
|
|
99
|
+
const bytes = readFileSync(path);
|
|
100
|
+
const file = createHash('sha256').update(bytes).digest('hex') + suffix;
|
|
101
|
+
const out = home.path('member-icons', file);
|
|
102
|
+
if (!existsSync(out)) {
|
|
103
|
+
mkdirSync(iconsDir, { recursive: true });
|
|
104
|
+
writeFileSync(out, bytes);
|
|
105
|
+
}
|
|
106
|
+
return '/member-icons/' + file;
|
|
107
|
+
};
|
|
108
|
+
const readPicture = () => {
|
|
109
|
+
const png = readJson(ownerAvatarFile, null);
|
|
110
|
+
return png ? profilePicture(png) : null;
|
|
111
|
+
};
|
|
112
|
+
let picture = readPicture();
|
|
113
|
+
const write = (next) => {
|
|
114
|
+
// Write the image and the settings together. Only the image URL belongs in public member data.
|
|
115
|
+
writeJson(membersFile, next.map(({ member, picture }) => {
|
|
116
|
+
if (!picture)
|
|
117
|
+
return member;
|
|
118
|
+
const { avatarPath: _path, ...identity } = member;
|
|
119
|
+
return { ...identity, avatarPng: picture.png };
|
|
120
|
+
}));
|
|
121
|
+
profiles = next;
|
|
122
|
+
};
|
|
123
|
+
ctx.effect(config.declare({ scope: 'settings', owner: 'core', fields: [{ key: 'owner.name', kind: 'string', default: '用户', managedBy: 'members.owner_set', label: { default: '你的名字', translations: { zh: '你的名字', en: 'Your name' } }, description: { default: '你的名字。成员在主题里看到的就是它。在「成员」页里改。', translations: { zh: '你的名字。成员在主题里看到的就是它。在「成员」页里改。', en: 'Your display name shown to members in topics. Edit on the Members page.' } } }] }));
|
|
124
|
+
ctx.effect(config.declare({ scope: 'settings', owner: 'core', fields: [{ key: 'owner.handle', kind: 'string', default: 'me', managedBy: 'members.owner_set', label: { default: '你的 @ 名', translations: { zh: '你的 @ 名', en: 'Your handle' } }, description: { default: '你的 @ 名。成员在回复里行首写 @它 就是找你,你会在收件箱里看到。在「成员」页里改。', translations: { zh: '你的 @ 名。成员在回复里行首写 @它 就是找你,你会在收件箱里看到。在「成员」页里改。', en: 'Your @ handle. Members start a line with @handle to reach you in the inbox. Edit on the Members page.' } } }] }));
|
|
125
|
+
const clean = (handle) => handle.trim().replace(/^@/, '').replace(/\s+/g, '-').toLowerCase();
|
|
126
|
+
const owner = () => ({
|
|
127
|
+
name: config.get('settings', 'owner.name'), handle: config.get('settings', 'owner.handle'),
|
|
128
|
+
...(picture && { avatarPath: '/api/owner/avatar/' + picture.file }),
|
|
129
|
+
});
|
|
130
|
+
const people = () => [{ id: OWNER_ID, kind: 'person', ...owner(), adapter: '', options: {}, enabled: true }];
|
|
131
|
+
const get = (id) => plugins.get(id)?.profile.member ?? find(id)?.member ?? people().find((m) => m.id === id);
|
|
132
|
+
const checkHandle = (handle, id) => {
|
|
133
|
+
if (!handle)
|
|
134
|
+
throw new Error('@ 名不能为空');
|
|
135
|
+
const taken = [...list(), ...people()].find((m) => m.handle === handle && m.id !== id);
|
|
136
|
+
if (taken?.id === OWNER_ID)
|
|
137
|
+
throw new Error(`@${handle} 是你自己的 @ 名,换一个`);
|
|
138
|
+
if (taken)
|
|
139
|
+
throw new Error(`@${handle} 已经是「${taken.name}」的 @ 名,换一个`);
|
|
140
|
+
};
|
|
141
|
+
const service = {
|
|
142
|
+
owner,
|
|
143
|
+
ownerPicture: (file) => picture?.file === file ? picture.bytes : undefined,
|
|
144
|
+
people,
|
|
145
|
+
setOwner(input) {
|
|
146
|
+
const name = input.name.trim();
|
|
147
|
+
const handle = clean(input.handle);
|
|
148
|
+
if (!name || !handle)
|
|
149
|
+
throw new Error('名字和 @ 名都不能为空');
|
|
150
|
+
const taken = list().find((m) => m.handle === handle);
|
|
151
|
+
if (taken)
|
|
152
|
+
throw new Error(`@${handle} 已经是「${taken.name}」的 @ 名,换一个`);
|
|
153
|
+
if (input.avatarPng !== undefined) {
|
|
154
|
+
const next = input.avatarPng === null ? null : profilePicture(input.avatarPng);
|
|
155
|
+
if (input.avatarPng === null)
|
|
156
|
+
rmSync(ownerAvatarFile, { force: true });
|
|
157
|
+
else
|
|
158
|
+
writeJson(ownerAvatarFile, input.avatarPng);
|
|
159
|
+
picture = next;
|
|
160
|
+
}
|
|
161
|
+
config.set('settings', 'owner.name', name);
|
|
162
|
+
config.set('settings', 'owner.handle', handle);
|
|
163
|
+
return owner();
|
|
164
|
+
},
|
|
165
|
+
list,
|
|
166
|
+
get,
|
|
167
|
+
acceptsDelivery: (id) => plugins.get(id)?.stored.receives ?? get(id) !== undefined,
|
|
168
|
+
canReceive: (id) => plugins.has(id) ? registered.get(id)?.receive !== undefined : get(id)?.enabled === true,
|
|
169
|
+
receiver: (id) => registered.get(id)?.receive,
|
|
170
|
+
isRegisteredSender: (sender) => registered.get(sender.id)?.sender === sender,
|
|
171
|
+
ownsSender: (plugin, id) => registered.get(id)?.plugin === plugin,
|
|
172
|
+
register(plugin, { namespace, receive, needsHandling, name, handle: declaredHandle, avatarPath: declaredAvatar, color, persona, icon, suggest }) {
|
|
173
|
+
const owner = ctx.runtime.ownerOf(plugin);
|
|
174
|
+
if (namespace !== undefined && !/^[\p{L}\p{N}._-]+$/u.test(namespace))
|
|
175
|
+
throw new Error('插件成员 namespace 需要使用字母、数字、点、下划线或连字符');
|
|
176
|
+
const id = namespace === undefined ? owner.name : owner.name + ':' + namespace;
|
|
177
|
+
if (registered.has(id) || id === OWNER_ID || find(id))
|
|
178
|
+
throw new Error(`成员编号已存在:${id}`);
|
|
179
|
+
validateAppearance({ avatarPath: declaredAvatar, color });
|
|
180
|
+
const handle = clean(declaredHandle);
|
|
181
|
+
const previous = plugins.get(id)?.stored;
|
|
182
|
+
checkHandle(previous?.override?.handle ?? handle, id);
|
|
183
|
+
const avatarPath = declaredAvatar ?? (owner.icon && saveIcon(owner.icon));
|
|
184
|
+
const identity = {
|
|
185
|
+
name: name.trim(), handle, ...(color !== undefined && { color }), ...(avatarPath && { avatarPath }),
|
|
186
|
+
...(persona === true && { persona }), ...(icon && { icon }), ...(suggest === false && { suggest }),
|
|
187
|
+
...(needsHandling === true && { needsHandling }),
|
|
188
|
+
};
|
|
189
|
+
if (!identity.name || !handle)
|
|
190
|
+
throw new Error('名字和 @ 名都不能为空');
|
|
191
|
+
const sender = Object.freeze({ kind: 'member', id });
|
|
192
|
+
// Each registration gets a fresh callback, even if plugin code reuses the same function after reload.
|
|
193
|
+
const active = { plugin, sender, receive: receive && ((input) => receive(input)) };
|
|
194
|
+
writePlugin({ id, identity, receives: receive !== undefined, override: previous?.override }, true);
|
|
195
|
+
registered.set(id, active);
|
|
196
|
+
plugin.effect(() => {
|
|
197
|
+
registered.delete(id);
|
|
198
|
+
const { profile } = plugins.get(id);
|
|
199
|
+
profile.member = { ...profile.member, enabled: false };
|
|
200
|
+
ctx.runtime.emit('members.changed', { id });
|
|
201
|
+
});
|
|
202
|
+
ctx.runtime.emit('members.changed', { id });
|
|
203
|
+
return Object.freeze({
|
|
204
|
+
id, sender,
|
|
205
|
+
send({ topicId, content, targets, replyTo, thread, visibility, attachments, parts, threadable }) {
|
|
206
|
+
return plugin.get('a2a').send({ topicId, from: sender, content, targets, replyTo, thread, visibility, attachments, parts, threadable });
|
|
207
|
+
},
|
|
208
|
+
reply({ credential, content, targets, attachments }) {
|
|
209
|
+
return plugin.get('a2a').replyToDelivery(sender, credential, content, targets, attachments);
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
save({ id, adapter, avatarPng, env: envInput, ...input }) {
|
|
214
|
+
validateAppearance(input);
|
|
215
|
+
if (envInput !== undefined && envInput !== null) {
|
|
216
|
+
if (Array.isArray(envInput) || typeof envInput !== 'object')
|
|
217
|
+
throw new HttpError(400, '成员环境变量需要是对象');
|
|
218
|
+
for (const [key, value] of Object.entries(envInput)) {
|
|
219
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key))
|
|
220
|
+
throw new HttpError(400, `环境变量名无效:${key}`);
|
|
221
|
+
if (typeof value !== 'string')
|
|
222
|
+
throw new HttpError(400, `环境变量 ${key} 的值需要是字符串模板`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const provided = id === undefined ? undefined : plugins.get(id);
|
|
226
|
+
if (provided) {
|
|
227
|
+
const name = input.name.trim();
|
|
228
|
+
const handle = clean(input.handle ?? provided.profile.member.handle);
|
|
229
|
+
if (!name)
|
|
230
|
+
throw new Error('名字不能为空');
|
|
231
|
+
checkHandle(handle, provided.stored.id);
|
|
232
|
+
const override = {
|
|
233
|
+
...provided.stored.override,
|
|
234
|
+
name: name === provided.stored.identity.name ? undefined : name,
|
|
235
|
+
handle: handle === provided.stored.identity.handle ? undefined : handle,
|
|
236
|
+
...(input.color !== undefined && { color: input.color }),
|
|
237
|
+
...(avatarPng !== undefined && { avatarPng }),
|
|
238
|
+
};
|
|
239
|
+
const member = writePlugin({ ...provided.stored, override });
|
|
240
|
+
ctx.runtime.emit('members.changed', { id: member.id });
|
|
241
|
+
return member;
|
|
242
|
+
}
|
|
243
|
+
if (!adapter)
|
|
244
|
+
throw new Error('请选择适配器');
|
|
245
|
+
const handle = clean(input.handle ?? input.name);
|
|
246
|
+
const existing = id ? find(id) : undefined;
|
|
247
|
+
checkHandle(handle, existing?.member.id);
|
|
248
|
+
const member = {
|
|
249
|
+
id: existing?.member.id ?? newId('mem'),
|
|
250
|
+
options: {},
|
|
251
|
+
enabled: true,
|
|
252
|
+
...existing?.member,
|
|
253
|
+
...input,
|
|
254
|
+
adapter,
|
|
255
|
+
kind: 'agent',
|
|
256
|
+
handle,
|
|
257
|
+
};
|
|
258
|
+
if (envInput !== undefined) {
|
|
259
|
+
if (envInput === null || !Object.keys(envInput).length)
|
|
260
|
+
delete member.env;
|
|
261
|
+
else
|
|
262
|
+
member.env = envInput;
|
|
263
|
+
}
|
|
264
|
+
let picture = existing?.picture;
|
|
265
|
+
if (avatarPng === null) {
|
|
266
|
+
delete member.avatarPath;
|
|
267
|
+
picture = undefined;
|
|
268
|
+
}
|
|
269
|
+
else if (avatarPng !== undefined) {
|
|
270
|
+
picture = profilePicture(avatarPng);
|
|
271
|
+
}
|
|
272
|
+
else if (input.avatarPath !== undefined && input.avatarPath !== existing?.member.avatarPath) {
|
|
273
|
+
picture = undefined;
|
|
274
|
+
}
|
|
275
|
+
if (!member.key)
|
|
276
|
+
delete member.key;
|
|
277
|
+
const profile = withPicture(member, picture);
|
|
278
|
+
write(existing ? profiles.map((p) => p === existing ? profile : p) : [...profiles, profile]);
|
|
279
|
+
ctx.runtime.emit('members.changed', { id: member.id });
|
|
280
|
+
return member;
|
|
281
|
+
},
|
|
282
|
+
remove(id) {
|
|
283
|
+
if (plugins.has(id))
|
|
284
|
+
throw new HttpError(409, '插件成员由插件管理');
|
|
285
|
+
write(profiles.filter(({ member }) => member.id !== id));
|
|
286
|
+
ctx.runtime.emit('members.changed', { id, removed: true });
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
ctx.provide('members', service);
|
|
290
|
+
const entry = ctx.get('entry');
|
|
291
|
+
ctx.effect(entry.group('members', '成员、适配器、宿主所属人的 @ 名、人设和共同规则'));
|
|
292
|
+
const memberId = { type: 'string', member: true };
|
|
293
|
+
const memberLabel = (id) => {
|
|
294
|
+
const member = service.get(id);
|
|
295
|
+
return member ? `${member.name}(@${member.handle})` : id;
|
|
296
|
+
};
|
|
297
|
+
ctx.effect(entry.op({
|
|
298
|
+
name: 'members.list', workload: 'local', about: '列出成员的 @ 名、名字、适配器和启用状态。',
|
|
299
|
+
output: array(memberOutput), sdk: true,
|
|
300
|
+
http: ['GET', '/api/members'], agent: true,
|
|
301
|
+
run: () => service.list().map((member) => ({ ...member, canReceive: service.canReceive(member.id) })),
|
|
302
|
+
text: (list) => list.map((m) => `@${m.handle}(${m.name})${m.adapter ? '· ' + m.adapter : ''}${m.enabled ? '' : ' · 已停用'}`).join('\n'),
|
|
303
|
+
}));
|
|
304
|
+
ctx.effect(entry.op({
|
|
305
|
+
name: 'members.save', about: '添加成员,或指定 id 来保存已有成员的设置。',
|
|
306
|
+
input: object({
|
|
307
|
+
id: { ...memberId, description: '要修改的成员,新增时省略' },
|
|
308
|
+
name: { type: 'string', description: '成员的显示名' },
|
|
309
|
+
handle: { type: 'string', description: '成员用来接收 @ 点名的别名' },
|
|
310
|
+
adapter: { type: 'string', description: '所用适配器的名字' },
|
|
311
|
+
options: { type: 'object', description: '适配器的选项' },
|
|
312
|
+
env: { type: ['object', 'null'], description: '成员专属环境变量模板,支持 ${name} 引用系统可见配置或宿主环境变量' },
|
|
313
|
+
key: { type: 'string', description: '所选 API 密钥或客户端账号的编号,留空使用本机默认登录' },
|
|
314
|
+
color: { ...color, description: '成员的主题色(primary)或固定文字颜色' },
|
|
315
|
+
avatarPath: { ...avatarPath, description: '成员头像在本地控制台的资源路径' },
|
|
316
|
+
avatarPng: avatarPngInput,
|
|
317
|
+
enabled: { ...enabled, description: '是否启用' },
|
|
318
|
+
}, ['name']),
|
|
319
|
+
http: ['POST', '/api/members'], agent: 'approve', loosen: 'owner', maxBody: avatarBodyLimit,
|
|
320
|
+
approval: ({ id, name, adapter }) => ({
|
|
321
|
+
title: id ? '修改成员设置' : '添加成员',
|
|
322
|
+
target: id ? memberLabel(id) : name,
|
|
323
|
+
...(adapter && { impact: `使用适配器 ${adapter}` }),
|
|
324
|
+
}),
|
|
325
|
+
run: (args) => service.save({ ...args, env: args.env }),
|
|
326
|
+
}));
|
|
327
|
+
ctx.effect(entry.route('GET', '/api/members/:id/avatar/:file', ({ params, res }) => {
|
|
328
|
+
const id = params.id;
|
|
329
|
+
const picture = (plugins.get(id)?.profile ?? find(id))?.picture;
|
|
330
|
+
return sendPicture(res, picture && picture.file === params.file ? picture.bytes : undefined);
|
|
331
|
+
}));
|
|
332
|
+
ctx.effect(entry.files('/member-icons/', iconsDir, { userContent: true }));
|
|
333
|
+
ctx.effect(entry.op({
|
|
334
|
+
name: 'members.remove', about: '移除一个成员并停止它正在跑的回合。',
|
|
335
|
+
input: object({ id: memberId }, ['id']),
|
|
336
|
+
http: ['DELETE', '/api/members/:id'], agent: 'approve', loosen: 'owner',
|
|
337
|
+
approval: ({ id }) => ({
|
|
338
|
+
title: '移除成员', target: memberLabel(id),
|
|
339
|
+
risk: '该成员将无法继续参与主题,正在运行的回合会停止',
|
|
340
|
+
}),
|
|
341
|
+
run: ({ id }) => service.remove(id),
|
|
342
|
+
}));
|
|
343
|
+
ctx.effect(entry.op({
|
|
344
|
+
name: 'members.owner', about: '查看宿主所属人的名字、@ 名和头像。',
|
|
345
|
+
output: ownerOutput, sdk: true,
|
|
346
|
+
http: ['GET', '/api/owner'], agent: true, run: () => service.owner(),
|
|
347
|
+
}));
|
|
348
|
+
ctx.effect(entry.op({
|
|
349
|
+
name: 'members.owner_set', about: '设置自己的名字、@ 名和头像。',
|
|
350
|
+
input: object({ name, handle, avatarPng: avatarPngInput }, ['name', 'handle']),
|
|
351
|
+
http: ['PUT', '/api/owner'],
|
|
352
|
+
maxBody: avatarBodyLimit,
|
|
353
|
+
run: (args) => service.setOwner(args),
|
|
354
|
+
}));
|
|
355
|
+
ctx.effect(entry.route('GET', '/api/owner/avatar/:file', ({ params, res }) => sendPicture(res, service.ownerPicture(params.file))));
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface Handle {
|
|
2
|
+
memberId: string;
|
|
3
|
+
/** Lowercase, without the `@`. */
|
|
4
|
+
handle: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const MENTION_MARK = "\u2063";
|
|
7
|
+
export declare function stripMentionMarks(text: string): string;
|
|
8
|
+
/** Member ids addressed (at line starts; with `anywhere`, wherever they stand), in order of appearance, without repeats. */
|
|
9
|
+
export declare function findMentions(text: string, handles: readonly Handle[], { anywhere, markedOnly }?: {
|
|
10
|
+
anywhere?: boolean;
|
|
11
|
+
markedOnly?: boolean;
|
|
12
|
+
}): string[];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outside fenced code blocks, a member can address one or more `@handle`s at the start of a line,
|
|
3
|
+
* after any quote or list markers. The longest handle wins and must end on a token boundary.
|
|
4
|
+
* Prose ends the sequence of routing targets for that line.
|
|
5
|
+
*
|
|
6
|
+
* A person's mentions use `markedOnly`: they can appear anywhere in prose outside a word (`name@host`),
|
|
7
|
+
* and the handle must end in the marker inserted by the composer.
|
|
8
|
+
*/
|
|
9
|
+
import { mentionLineStart, parseLeadingMentions } from '../../console/sdk-browser/mentions.mjs';
|
|
10
|
+
export const MENTION_MARK = '\u2063';
|
|
11
|
+
export function stripMentionMarks(text) {
|
|
12
|
+
return text.replaceAll(MENTION_MARK, '');
|
|
13
|
+
}
|
|
14
|
+
const WORD = /[a-z0-9_]/;
|
|
15
|
+
const longestFirst = (a, b) => b.handle.length - a.handle.length;
|
|
16
|
+
/** Member ids addressed (at line starts; with `anywhere`, wherever they stand), in order of appearance, without repeats. */
|
|
17
|
+
export function findMentions(text, handles, { anywhere = false, markedOnly = false } = {}) {
|
|
18
|
+
if (!text)
|
|
19
|
+
return [];
|
|
20
|
+
if (!anywhere && !markedOnly)
|
|
21
|
+
return parseLeadingMentions(text, handles).targets;
|
|
22
|
+
const byLength = [...handles].sort(longestFirst);
|
|
23
|
+
const found = new Set();
|
|
24
|
+
const body = markedOnly ? text : text.replace(/```[\s\S]*?```/g, '');
|
|
25
|
+
let fenced = false;
|
|
26
|
+
for (const raw of body.split(/\r?\n/)) {
|
|
27
|
+
const line = raw.slice(mentionLineStart(raw)).toLowerCase();
|
|
28
|
+
if (markedOnly && line.startsWith('```')) {
|
|
29
|
+
fenced = !fenced;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (fenced)
|
|
33
|
+
continue;
|
|
34
|
+
const prose = line.replace(markedOnly ? /(?<!`)(`+)(?!`).*?(?<!`)\1(?!`)/g : /`[^`]*`/g, ' ');
|
|
35
|
+
for (let at = prose.indexOf('@'); at >= 0; at = prose.indexOf('@', at + 1)) {
|
|
36
|
+
if (at > 0 && WORD.test(prose.charAt(at - 1)))
|
|
37
|
+
continue;
|
|
38
|
+
const hit = byLength.find((h) => {
|
|
39
|
+
if (!prose.startsWith(h.handle, at + 1))
|
|
40
|
+
return false;
|
|
41
|
+
const after = prose.charAt(at + 1 + h.handle.length);
|
|
42
|
+
return markedOnly ? after === MENTION_MARK : !/[a-z0-9_-]/.test(after);
|
|
43
|
+
});
|
|
44
|
+
if (hit)
|
|
45
|
+
found.add(hit.memberId);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return [...found];
|
|
49
|
+
}
|