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,507 @@
|
|
|
1
|
+
import { topicOrder } from "./topic-index.js";
|
|
2
|
+
import { HttpError } from "./entry.js";
|
|
3
|
+
import { ltext } from "./i18n.js";
|
|
4
|
+
import { OWNER_ID } from "./members.js";
|
|
5
|
+
import { stripMentionMarks } from "./mentions.js";
|
|
6
|
+
import { array, object } from "./ops.js";
|
|
7
|
+
import { topicText } from "../sdk/topic-text.js";
|
|
8
|
+
import { draftRefSchema, refKey, requireTopic, SUMMARY_MAX_CHARS } from "./topics.js";
|
|
9
|
+
import { dirRefSchema as dirRef, isDirRef, isTopicRef, topicRefSchema as topicRef, topicSchema } from "./types.js";
|
|
10
|
+
/** Where a topic sits when it is under none. */
|
|
11
|
+
const ROOT = 'root';
|
|
12
|
+
const stringValue = { type: 'string' };
|
|
13
|
+
const numberValue = { type: 'number' };
|
|
14
|
+
const booleanValue = { type: 'boolean' };
|
|
15
|
+
const fields = topicSchema.properties;
|
|
16
|
+
const { archivedAt, view: topicView } = fields;
|
|
17
|
+
const editableTopic = {
|
|
18
|
+
title: fields.title, parentId: fields.parentId, tags: fields.tags, refs: fields.refs, pinned: fields.pinned, caps: fields.caps,
|
|
19
|
+
view: topicView,
|
|
20
|
+
// The tree log uses null for absent values, and undo restores them.
|
|
21
|
+
members: { ...fields.members, type: ['array', 'null'] }, defaultMember: { type: ['string', 'null'] },
|
|
22
|
+
archivedAt, deletedAt: fields.deletedAt,
|
|
23
|
+
};
|
|
24
|
+
export const topicOutput = { ...topicSchema, properties: { ...fields, ...editableTopic } };
|
|
25
|
+
const topicListOutput = array(object({ ...topicOutput.properties, unreadCount: { type: 'integer' } }, [...topicOutput.required, 'unreadCount']));
|
|
26
|
+
const topicName = { id: stringValue, title: stringValue };
|
|
27
|
+
const topicLink = object({ topicId: stringValue, title: stringValue, path: stringValue, summary: stringValue, archivedAt, note: stringValue }, ['topicId', 'title', 'path', 'summary', 'archivedAt']);
|
|
28
|
+
const topicAboutOutput = object({
|
|
29
|
+
topic: topicOutput, path: array(object(topicName, ['id', 'title'])),
|
|
30
|
+
level: { type: 'integer' }, maxDepth: numberValue, summary: stringValue,
|
|
31
|
+
above: array(object({ ...topicName, dir: stringValue, summary: stringValue, archivedAt }, ['id', 'title', 'dir', 'summary', 'archivedAt'])),
|
|
32
|
+
children: array(object(topicName, ['id', 'title'])),
|
|
33
|
+
refs: array(dirRef),
|
|
34
|
+
topicRefs: array(topicLink), referencedBy: array(topicLink),
|
|
35
|
+
}, ['topic', 'path', 'level', 'maxDepth', 'summary', 'above', 'children', 'refs', 'topicRefs', 'referencedBy']);
|
|
36
|
+
const topicCapsOutput = array(object({
|
|
37
|
+
id: stringValue, title: stringValue, about: stringValue, group: stringValue, default: booleanValue,
|
|
38
|
+
on: booleanValue, own: { type: ['boolean', 'null'] }, blockedByPlugin: booleanValue,
|
|
39
|
+
}, ['id', 'title', 'group', 'default', 'on', 'own']));
|
|
40
|
+
const treeLogOutput = array(object({
|
|
41
|
+
id: stringValue, at: numberValue, by: stringValue, topicId: stringValue,
|
|
42
|
+
before: object(editableTopic), after: object(editableTopic), affected: array(stringValue),
|
|
43
|
+
}, ['id', 'at', 'by', 'topicId', 'before', 'after']));
|
|
44
|
+
const SUMMARY_SOFT_CHARS = 1500;
|
|
45
|
+
const okOutput = object({ ok: { type: 'boolean', enum: [true] } }, ['ok']);
|
|
46
|
+
const summarySetOutput = object({
|
|
47
|
+
ok: { type: 'boolean', enum: [true] },
|
|
48
|
+
warning: { type: 'string', description: '超过建议字数上限时的提醒;摘要仍已保存' },
|
|
49
|
+
}, ['ok']);
|
|
50
|
+
/**
|
|
51
|
+
* The tree of topics as operations: what the console does to it and what members do to it are these, each
|
|
52
|
+
* declared once. A member does them to the topic it is in (or one under it, where that is said); the five it uses
|
|
53
|
+
* most are tools of the group `topics` as well.
|
|
54
|
+
*/
|
|
55
|
+
export function topicOps(ctx) {
|
|
56
|
+
const entry = ctx.get('entry');
|
|
57
|
+
const topics = ctx.get('topics');
|
|
58
|
+
const config = ctx.get('config');
|
|
59
|
+
const op = (decl) => ctx.effect(entry.op(decl));
|
|
60
|
+
const topicId = { type: 'string', description: '主题编号' };
|
|
61
|
+
op({ name: 'channel.drafts', about: '列出所有主题未发送的草稿。', http: ['GET', '/api/drafts'], run: () => topics.drafts() });
|
|
62
|
+
op({
|
|
63
|
+
name: 'channel.drafts_topic', about: '列出一个主题下未发送的草稿(至多一条)。',
|
|
64
|
+
input: object({ id: topicId }, ['id']), http: ['GET', '/api/topics/:id/drafts'], run: ({ id }) => topics.draftsOf(requireTopic(topics, id).id),
|
|
65
|
+
});
|
|
66
|
+
op({
|
|
67
|
+
name: 'channel.draft', about: '读取一个主题的草稿、发送目标、引用和版本号。',
|
|
68
|
+
input: object({ id: topicId }, ['id']),
|
|
69
|
+
http: ['GET', '/api/topics/:id/draft'], run: ({ id }) => topics.draft(requireTopic(topics, id).id),
|
|
70
|
+
});
|
|
71
|
+
op({
|
|
72
|
+
name: 'channel.draft_save', about: '按版本号保存一个主题的草稿、发送目标和引用,版本不同时返回已存的内容。',
|
|
73
|
+
input: object({
|
|
74
|
+
id: topicId,
|
|
75
|
+
revision: { type: 'integer', minimum: 0 },
|
|
76
|
+
text: { type: 'string' },
|
|
77
|
+
replyTo: { type: ['string', 'null'], description: '楼内回复目标消息编号' },
|
|
78
|
+
quote: { type: ['string', 'null'], description: '主线显式引用目标消息编号' },
|
|
79
|
+
refs: array(draftRefSchema),
|
|
80
|
+
}, ['id', 'revision']),
|
|
81
|
+
http: ['PUT', '/api/topics/:id/draft'],
|
|
82
|
+
run: ({ id, revision, text = '', replyTo = null, quote = null, refs = [] }) => topics.saveDraft(requireTopic(topics, id).id, revision, text, { replyTo, quote, refs }),
|
|
83
|
+
});
|
|
84
|
+
op({
|
|
85
|
+
name: 'channel.draft_clear', about: '清空一个主题的草稿。',
|
|
86
|
+
input: object({ id: topicId }, ['id']),
|
|
87
|
+
http: ['DELETE', '/api/topics/:id/draft'], run: ({ id }) => { topics.clearDraft(requireTopic(topics, id).id); },
|
|
88
|
+
});
|
|
89
|
+
const tool = (name) => ({ server: 'hostlet', name });
|
|
90
|
+
ctx.effect(entry.group('topics', '主题树、归档与垃圾桶,摘要、引用、能力开关、改动记录和撤销'));
|
|
91
|
+
const need = (id) => {
|
|
92
|
+
const found = topics.get(id);
|
|
93
|
+
if (!found || found.deletedAt !== null)
|
|
94
|
+
throw new HttpError(404, `没有这个主题:${id}`);
|
|
95
|
+
return found;
|
|
96
|
+
};
|
|
97
|
+
const pathText = (id) => topics.path(id).map((t) => t.title).join(' › ');
|
|
98
|
+
const topicLabel = (id) => {
|
|
99
|
+
const topic = topics.get(id);
|
|
100
|
+
return topic ? `「${topic.title}」(${id})` : id;
|
|
101
|
+
};
|
|
102
|
+
const nameOf = (id) => ctx.get('members').get(id)?.name ?? id;
|
|
103
|
+
const parentOf = (value) => (value === undefined ? undefined : value === ROOT || value === '' ? null : value);
|
|
104
|
+
const capsOf = async (id) => {
|
|
105
|
+
const contributed = (await ctx.runtime.serial('topic.caps', { topicId: id })).flat().filter((cap) => !cap.id.startsWith('plugin:'));
|
|
106
|
+
return [...new Map([...contributed, ...topics.pluginCaps()].map((cap) => [cap.id, cap])).values()];
|
|
107
|
+
};
|
|
108
|
+
const capOn = (id, cap) => !cap.blockedByPlugin && topics.uses(id, cap.id, cap.default);
|
|
109
|
+
/** What a topic has from where it sits in the tree: the directories it can work in and the capabilities that are on. */
|
|
110
|
+
const given = async (id) => new Map([
|
|
111
|
+
...topics.refsOf(id).map((ref) => [`dir:${ref.path}`, `目录 ${ref.path}`]),
|
|
112
|
+
...(await capsOf(id)).filter((cap) => capOn(id, cap)).map((cap) => [cap.id, `${cap.group} ${cap.title}`]),
|
|
113
|
+
]);
|
|
114
|
+
const only = (a, b) => [...a].filter(([key]) => !b.has(key)).map(([, label]) => label);
|
|
115
|
+
const lastTidy = new WeakMap();
|
|
116
|
+
const tidied = (topic, change, had) => {
|
|
117
|
+
// Remember the commit before any asynchronous capability lookup can let a later write pass it.
|
|
118
|
+
lastTidy.set(topic, change.id);
|
|
119
|
+
if (!had)
|
|
120
|
+
return ctx.runtime.emit('topic.tidied', { change });
|
|
121
|
+
return given(topic.id).then((has) => {
|
|
122
|
+
if (lastTidy.get(topic) !== change.id)
|
|
123
|
+
return;
|
|
124
|
+
ctx.runtime.emit('topic.tidied', { change, gained: only(has, had), lost: only(had, has) });
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
const id = { type: 'string', description: '主题编号' };
|
|
128
|
+
const strings = (description) => ({ type: 'array', items: { type: 'string' }, ...(description ? { description } : {}) });
|
|
129
|
+
const refsFrom = ({ refs, topicRefs }, prior = []) => {
|
|
130
|
+
const notes = new Map(prior.map((ref) => [refKey(ref), ref.note]));
|
|
131
|
+
const withNote = (ref) => ({ ...ref, note: notes.get(refKey(ref)) });
|
|
132
|
+
return [
|
|
133
|
+
...(refs ? refs.map((path) => withNote({ path })) : prior.filter(isDirRef)),
|
|
134
|
+
...(topicRefs ? topicRefs.map((topicId) => withNote({ topicId })) : prior.filter(isTopicRef)),
|
|
135
|
+
];
|
|
136
|
+
};
|
|
137
|
+
const navigationCursor = object({ rank: { type: 'integer' }, at: numberValue, id: stringValue }, ['rank', 'at', 'id']);
|
|
138
|
+
const navigationRow = (topic) => ({
|
|
139
|
+
topic, hasChildren: topic.archivedAt === null && topics.hasActiveChildren(topic.id),
|
|
140
|
+
});
|
|
141
|
+
op({
|
|
142
|
+
name: 'topics.navigation', about: '按父级读取有界的主题子级,或读取归档、查找结果、标签和指定主题的祖先。',
|
|
143
|
+
input: object({
|
|
144
|
+
view: { type: 'string', enum: ['tree', 'archive', 'search', 'recent', 'tags', 'lookup'] },
|
|
145
|
+
parents: array(object({ id: stringValue, cursor: navigationCursor }, ['id'])),
|
|
146
|
+
cursor: navigationCursor, q: stringValue, tag: stringValue, ids: strings(),
|
|
147
|
+
}),
|
|
148
|
+
http: ['POST', '/api/topics/navigation'], maxBody: 64 * 1024,
|
|
149
|
+
run({ view = 'tree', parents, cursor, q = '', tag = '', ids = [] }) {
|
|
150
|
+
const version = { ...topics.status.version(), treeVersion: topics.treeVersion() };
|
|
151
|
+
if (view === 'tags')
|
|
152
|
+
return { ...version, tags: topics.tags() };
|
|
153
|
+
if (view === 'lookup') {
|
|
154
|
+
const found = new Map();
|
|
155
|
+
for (const id of new Set(ids))
|
|
156
|
+
for (const topic of topics.path(id))
|
|
157
|
+
found.set(topic.id, topic);
|
|
158
|
+
return { ...version, items: [...found.values()].map(navigationRow) };
|
|
159
|
+
}
|
|
160
|
+
const wanted = parents ?? [{ id: '', cursor }];
|
|
161
|
+
if (wanted.length > 64)
|
|
162
|
+
throw new HttpError(400, '一次最多读取 64 个父级');
|
|
163
|
+
const pages = wanted.map(({ id, cursor }) => {
|
|
164
|
+
const key = cursor ? [cursor.rank, cursor.at, cursor.id] : null;
|
|
165
|
+
const page = topics.page(view, id, q.trim().toLowerCase(), tag, key && [...key], 81);
|
|
166
|
+
const items = page.slice(0, 80).map(navigationRow);
|
|
167
|
+
const last = page.length > 80 && items.at(-1);
|
|
168
|
+
const next = last ? topicOrder(last.topic, view) : null;
|
|
169
|
+
return { parent: id, items, next: next && { rank: next[0], at: next[1], id: next[2] } };
|
|
170
|
+
});
|
|
171
|
+
const ancestors = new Map();
|
|
172
|
+
if (view !== 'tree') {
|
|
173
|
+
for (const page of pages)
|
|
174
|
+
for (const row of page.items) {
|
|
175
|
+
for (const topic of topics.path(row.topic.id).slice(0, -1))
|
|
176
|
+
ancestors.set(topic.id, topic);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return { ...version, pages, ancestors: [...ancestors.values()].map(navigationRow),
|
|
180
|
+
...(view === 'tree' && wanted.some(({ id }) => !id) ? topics.navigationCounts() : {}) };
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
op({
|
|
184
|
+
name: 'topics.status', about: '读取主题路径及当前读者的稀疏状态快照。',
|
|
185
|
+
http: ['GET', '/api/topics/status'], run: () => topics.status.snapshot(),
|
|
186
|
+
});
|
|
187
|
+
op({
|
|
188
|
+
name: 'topics.list', workload: 'local', about: '查看整棵主题树,列出每个主题的标题、编号、标签和摘要第一行。',
|
|
189
|
+
output: topicListOutput, sdk: true,
|
|
190
|
+
http: ['GET', '/api/topics'], agent: true, tool: tool('topic_tree'),
|
|
191
|
+
run() {
|
|
192
|
+
const unread = ctx.get('a2a').unreadCounts(OWNER_ID);
|
|
193
|
+
return topics.list().map((topic) => ({ ...topic, unreadCount: unread.get(topic.id) ?? 0 }));
|
|
194
|
+
},
|
|
195
|
+
text(all) {
|
|
196
|
+
const lines = [];
|
|
197
|
+
const row = (t, label) => {
|
|
198
|
+
const summary = topics.summary(t.id).split(/\r?\n/)[0].slice(0, 120);
|
|
199
|
+
return `- ${label}(${t.id})${t.tags.length ? ` #${t.tags.join(' #')}` : ''}${summary ? ` — ${summary}` : ''}`;
|
|
200
|
+
};
|
|
201
|
+
const active = all.filter((t) => t.archivedAt === null);
|
|
202
|
+
const walk = (parent, depth) => active.filter((t) => t.parentId === parent).sort((a, b) => a.createdAt - b.createdAt).forEach((t) => {
|
|
203
|
+
lines.push(' '.repeat(depth) + row(t, t.title));
|
|
204
|
+
walk(t.id, depth + 1);
|
|
205
|
+
});
|
|
206
|
+
walk(null, 0);
|
|
207
|
+
const archived = all.filter((t) => t.archivedAt !== null);
|
|
208
|
+
if (archived.length)
|
|
209
|
+
lines.push('已归档', ...archived.map((t) => row(t, pathText(t.id))));
|
|
210
|
+
return lines.join('\n') || '(树上还没有主题)';
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
op({
|
|
214
|
+
name: 'topics.create', about: '开一个新主题。summary 是它的第一份摘要:它是干嘛的、要做成什么。',
|
|
215
|
+
input: object({
|
|
216
|
+
title: { type: 'string' }, parentId: { type: 'string', description: `放在哪个主题下面(主题编号);填 ${ROOT} 是顶层` },
|
|
217
|
+
refs: strings('它用到的、在别处的目录'), topicRefs: strings('它引用的其他主题编号'),
|
|
218
|
+
tags: strings(), summary: { type: 'string', description: '主题的用途和期望交付,作为第一份摘要' },
|
|
219
|
+
}),
|
|
220
|
+
output: topicOutput, sdk: true,
|
|
221
|
+
http: ['POST', '/api/topics'], agent: true, topic: 'parentId', reach: 'any', tool: tool('topic_create'),
|
|
222
|
+
run(args, caller) {
|
|
223
|
+
// A person may start one from a sentence, with no title yet; a member opens one for something it can name.
|
|
224
|
+
if (caller.member && !args.title?.trim())
|
|
225
|
+
throw new Error('要给新主题一个标题(title)');
|
|
226
|
+
return topics.create({
|
|
227
|
+
title: args.title, summary: args.summary, parentId: parentOf(args.parentId) ?? null, tags: args.tags, refs: refsFrom(args),
|
|
228
|
+
// Whoever opens a topic is who it falls to when something arrives there for nobody by name.
|
|
229
|
+
...(caller.member ? { defaultMember: caller.member.id } : {}),
|
|
230
|
+
}, caller.member?.id);
|
|
231
|
+
},
|
|
232
|
+
text: (made) => `已开主题「${pathText(made.id)}」,编号 ${made.id}。`,
|
|
233
|
+
});
|
|
234
|
+
op({
|
|
235
|
+
name: 'topics.get', workload: 'local', about: '一个主题本身:标题、在谁下面、标签、引用的目录、谁在里面干活、主题目录。',
|
|
236
|
+
input: object({ id }, ['id']), output: topicOutput, sdk: true,
|
|
237
|
+
http: ['GET', '/api/topics/:id'], agent: true, topic: 'id', reach: 'any',
|
|
238
|
+
run: (args) => need(args.id),
|
|
239
|
+
});
|
|
240
|
+
op({
|
|
241
|
+
name: 'topics.update', about: '可改主题的标题、父主题、标签、引用的目录、成员和视图布局(view)。移动时它下面的主题一起挪。',
|
|
242
|
+
input: object({
|
|
243
|
+
id, title: { type: 'string' }, parentId: { type: 'string', description: `放在哪个主题下面(主题编号),任何主题都行;填 ${ROOT} 是顶层` }, tags: strings(),
|
|
244
|
+
refs: strings('整份替换这个主题自己引用的目录'), topicRefs: strings('整份替换这个主题自己引用的主题编号'),
|
|
245
|
+
pinned: { type: 'boolean', description: '人在侧栏里把它置顶' },
|
|
246
|
+
members: { type: 'array', items: { type: 'string', member: true }, description: '在这个主题里干活的成员。空的就是所有成员' },
|
|
247
|
+
defaultMember: { type: 'string', member: true, description: '没点名的消息交给谁' },
|
|
248
|
+
view: {
|
|
249
|
+
type: ['object', 'null'],
|
|
250
|
+
description: '主题的呈现视图(如 { main: "files", panel: "chat" });传 null 恢复默认对话视图。',
|
|
251
|
+
properties: {
|
|
252
|
+
main: { type: 'string' },
|
|
253
|
+
panel: { type: 'string' },
|
|
254
|
+
tabs: strings(),
|
|
255
|
+
preset: { type: 'string' },
|
|
256
|
+
args: { type: 'object' },
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
}, ['id']),
|
|
260
|
+
output: topicOutput, sdk: true,
|
|
261
|
+
http: ['PATCH', '/api/topics/:id'], agent: true, topic: 'id', reach: 'below', tool: tool('topic_update'),
|
|
262
|
+
approval: ({ id, parentId }) => {
|
|
263
|
+
const parent = parentOf(parentId);
|
|
264
|
+
return {
|
|
265
|
+
title: '修改主题', target: topicLabel(id),
|
|
266
|
+
...(parent !== undefined ? { impact: `将主题放到${parent ? topicLabel(parent) + '下' : '顶层'}。移动时子主题随行,继承的引用和能力可能改变` } : {}),
|
|
267
|
+
};
|
|
268
|
+
},
|
|
269
|
+
async run({ id: which, title, parentId, refs, topicRefs, ...rest }, caller) {
|
|
270
|
+
const found = need(which);
|
|
271
|
+
const parent = parentOf(parentId);
|
|
272
|
+
const by = caller.member?.id;
|
|
273
|
+
const had = by && parent !== undefined && parent !== found.parentId ? await given(found.id) : undefined;
|
|
274
|
+
const { topic, change } = topics.updateWithChange(found.id, {
|
|
275
|
+
...rest, ...(title?.trim() ? { title } : {}), ...(parent !== undefined ? { parentId: parent } : {}),
|
|
276
|
+
...(refs || topicRefs ? { refs: refsFrom({ refs, topicRefs }, found.refs) } : {}),
|
|
277
|
+
}, by);
|
|
278
|
+
if (had && change?.after.parentId !== undefined)
|
|
279
|
+
await tidied(topic, change, had);
|
|
280
|
+
return topic;
|
|
281
|
+
},
|
|
282
|
+
text: (changed) => `已改:「${pathText(changed.id)}」。`,
|
|
283
|
+
});
|
|
284
|
+
for (const [name, label, about] of [
|
|
285
|
+
['archive', '归档', '归档一个主题和它下面活跃的主题。归档后可以浏览,宿主停止其中的回合、实例和后台任务。'],
|
|
286
|
+
['unarchive', '取消归档', '将主题和它下面同批归档的主题恢复为活跃。上级主题仍归档时须先恢复上级。'],
|
|
287
|
+
]) {
|
|
288
|
+
op({
|
|
289
|
+
name: `topics.${name}`, about,
|
|
290
|
+
output: topicOutput, sdk: true,
|
|
291
|
+
input: object({ id }, ['id']), http: ['POST', `/api/topics/:id/${name}`], agent: true, topic: 'id', reach: 'below', named: true,
|
|
292
|
+
targets: name === 'archive' ? ({ id }) => topics.archiveTargets(id).map((topic) => topic.id) : undefined,
|
|
293
|
+
approval: ({ id }) => {
|
|
294
|
+
const below = name === 'archive' ? topics.archiveTargets(id).slice(1) : [];
|
|
295
|
+
return {
|
|
296
|
+
title: `${label}主题`, target: topicLabel(id),
|
|
297
|
+
impact: name === 'archive'
|
|
298
|
+
? ['停止归档主题中的回合、实例和后台任务', below.length && `同时归档:${below.map((topic) => topicLabel(topic.id)).join('、')}`].filter(Boolean).join('\n')
|
|
299
|
+
: '将主题和同批归档的子主题恢复为活跃',
|
|
300
|
+
};
|
|
301
|
+
},
|
|
302
|
+
run({ id }, caller) {
|
|
303
|
+
const found = need(id);
|
|
304
|
+
const change = topics[name](id, caller.member?.id);
|
|
305
|
+
if (change && caller.member)
|
|
306
|
+
tidied(found, change);
|
|
307
|
+
return found;
|
|
308
|
+
},
|
|
309
|
+
text: (topic) => `已${label}:「${pathText(topic.id)}」。`,
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
op({
|
|
313
|
+
name: 'topics.remove', about: '把主题及其子主题移入垃圾桶。主题已在垃圾桶时重复执行也成功。可以在垃圾桶恢复,也可以用 topics.undo 撤销本批删除。',
|
|
314
|
+
input: object({ id }, ['id']),
|
|
315
|
+
output: object({ ...topicName, under: { type: 'integer' }, alreadyTrashed: { type: 'boolean', enum: [true] } }, ['id', 'title', 'under']), sdk: true,
|
|
316
|
+
http: ['DELETE', '/api/topics/:id'], agent: true, topic: 'id', reach: 'below', named: true,
|
|
317
|
+
approval: ({ id }) => ({
|
|
318
|
+
title: '删除主题', target: topicLabel(id),
|
|
319
|
+
impact: '将主题移入垃圾桶,可从垃圾桶恢复',
|
|
320
|
+
risk: '全部子主题会一并移入垃圾桶,相关回合、实例和后台任务将停止',
|
|
321
|
+
}),
|
|
322
|
+
run({ id }, caller) {
|
|
323
|
+
const found = topics.get(id);
|
|
324
|
+
if (!found)
|
|
325
|
+
throw new HttpError(404, `没有这个主题:${id}`);
|
|
326
|
+
const { title } = found;
|
|
327
|
+
if (found.deletedAt !== null)
|
|
328
|
+
return { id, title, under: 0, alreadyTrashed: true };
|
|
329
|
+
const change = topics.remove(id, caller.member?.id);
|
|
330
|
+
const under = change.affected.length - 1;
|
|
331
|
+
if (caller.member)
|
|
332
|
+
tidied(found, change);
|
|
333
|
+
return { id, title, under };
|
|
334
|
+
},
|
|
335
|
+
text({ title, under, alreadyTrashed }) {
|
|
336
|
+
if (alreadyTrashed)
|
|
337
|
+
return `「${title}」已在垃圾桶。`;
|
|
338
|
+
return `已删掉「${title}」${under ? `和它下面的 ${under} 个主题` : ''}。`;
|
|
339
|
+
},
|
|
340
|
+
});
|
|
341
|
+
op({
|
|
342
|
+
name: 'topics.trash', about: '列出垃圾桶里的主题,含原路径、同批删除的子主题数及到期时间。',
|
|
343
|
+
http: ['GET', '/api/trash'], agent: true, run: () => topics.trash(),
|
|
344
|
+
});
|
|
345
|
+
op({
|
|
346
|
+
name: 'topics.trash_preview', about: '在垃圾桶里只读预览主题的摘要和最近消息。',
|
|
347
|
+
input: object({ id }, ['id']), http: ['GET', '/api/trash/:id/preview'],
|
|
348
|
+
run({ id }, caller) {
|
|
349
|
+
const topic = topics.get(id);
|
|
350
|
+
if (!topic || topic.deletedAt === null)
|
|
351
|
+
throw new HttpError(404, '垃圾桶里没有这个主题');
|
|
352
|
+
return {
|
|
353
|
+
id, title: topic.title, summary: topics.summary(id),
|
|
354
|
+
originalPath: topics.path(id, true).map((part) => part.title).join(' › '),
|
|
355
|
+
messages: ctx.get('messages').forMember(caller.member?.id ?? OWNER_ID).page(id, { limit: 20 }).map(({ id, from, createdAt, content }) => ({
|
|
356
|
+
id, createdAt, who: from.kind === 'member' ? nameOf(from.id) : from.id, content: stripMentionMarks(content).slice(0, 4000),
|
|
357
|
+
})),
|
|
358
|
+
};
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
op({
|
|
362
|
+
name: 'topics.restore', about: '恢复垃圾桶里的主题及同批删除的后代。原位置不可用时恢复到顶层。',
|
|
363
|
+
input: object({ id }, ['id']), http: ['POST', '/api/trash/:id/restore'], agent: 'approve', topic: 'id', reach: 'any', named: true,
|
|
364
|
+
approval: ({ id }) => ({
|
|
365
|
+
title: '恢复主题', target: topicLabel(id), impact: '一并恢复同批删除的子主题。原位置不可用时放到顶层',
|
|
366
|
+
}),
|
|
367
|
+
run: ({ id }, caller) => topics.restore(id, caller.member?.id),
|
|
368
|
+
});
|
|
369
|
+
op({
|
|
370
|
+
name: 'topics.purge', about: '彻底删除垃圾桶里的一个主题及它在垃圾桶里的后代。此操作无法撤销。',
|
|
371
|
+
input: object({ id }, ['id']), http: ['DELETE', '/api/trash/:id'],
|
|
372
|
+
run: ({ id }) => ({ topicIds: topics.purge(id) }),
|
|
373
|
+
});
|
|
374
|
+
op({
|
|
375
|
+
name: 'topics.empty_trash', about: '彻底删除垃圾桶里的所有主题。此操作无法撤销。',
|
|
376
|
+
http: ['POST', '/api/trash/empty'], run: () => ({ topicIds: topics.emptyTrash() }),
|
|
377
|
+
});
|
|
378
|
+
// What the topics service knows about a topic, the HTTP way out; hooks read the same service in process.
|
|
379
|
+
op({
|
|
380
|
+
name: 'topics.about', about: '一个主题的全部说明:在树上的位置、摘要、上级主题的摘要、子主题、引用的目录、产物和主题目录。',
|
|
381
|
+
input: object({ id }, ['id']),
|
|
382
|
+
output: topicAboutOutput, sdk: true,
|
|
383
|
+
http: ['GET', '/api/topics/:id/about'], agent: true, topic: 'id', reach: 'any', tool: tool('topic_about'),
|
|
384
|
+
run: (args) => topics.describe(need(args.id).id),
|
|
385
|
+
text: async (about) => topicText(about, await ctx.runtime.serial('topic.context', { topicId: about.topic.id })),
|
|
386
|
+
});
|
|
387
|
+
op({
|
|
388
|
+
name: 'topics.caps', about: '一个主题可以启用或停用的东西(skill、MCP 服务、工具组和主题能力):每一项现在开没开(on),和这个主题自己说的(own,没说过是 null,跟着上面的主题)。',
|
|
389
|
+
input: object({ id }, ['id']), output: topicCapsOutput, sdk: true,
|
|
390
|
+
http: ['GET', '/api/topics/:id/caps'], agent: true, topic: 'id', reach: 'any',
|
|
391
|
+
async run(args) {
|
|
392
|
+
const found = need(args.id);
|
|
393
|
+
const caps = await capsOf(found.id);
|
|
394
|
+
return caps.map((cap) => ({ ...cap, on: capOn(found.id, cap), own: found.caps[cap.id] ?? null }));
|
|
395
|
+
},
|
|
396
|
+
});
|
|
397
|
+
op({
|
|
398
|
+
name: 'topics.cap_set', about: '在一个主题里启用或停用一项能力(id 用 topics.caps 里列的),它下面的主题跟着。on 填 null 是收回这个主题自己说的,重新跟着上面的主题。',
|
|
399
|
+
input: object({ topic: id, id: { type: 'string', description: '能力的编号,比如 plugin:travel、skill:review、tools:topics' }, on: { type: ['boolean', 'null'] } }, ['topic', 'id']),
|
|
400
|
+
output: topicOutput, sdk: true,
|
|
401
|
+
http: ['PUT', '/api/topics/:topic/caps'], agent: true, topic: 'topic',
|
|
402
|
+
run(args, caller) {
|
|
403
|
+
const found = need(args.topic);
|
|
404
|
+
if (args.id.startsWith('plugin:') && !topics.pluginCaps().some((cap) => cap.id === args.id)) {
|
|
405
|
+
throw new HttpError(400, '这个插件没有声明按主题开关');
|
|
406
|
+
}
|
|
407
|
+
const { [args.id]: _old, ...rest } = found.caps;
|
|
408
|
+
return topics.update(found.id, { caps: args.on === null || args.on === undefined ? rest : { ...rest, [args.id]: args.on } }, caller.member?.id);
|
|
409
|
+
},
|
|
410
|
+
});
|
|
411
|
+
const refFields = { id, path: { type: 'string', description: '目录的完整路径' }, topicId: id, note: stringValue };
|
|
412
|
+
const refFrom = ({ path, topicId, note }) => {
|
|
413
|
+
if (path !== undefined && topicId === undefined)
|
|
414
|
+
return { path, note };
|
|
415
|
+
if (topicId !== undefined && path === undefined)
|
|
416
|
+
return { topicId, note };
|
|
417
|
+
throw new Error('请在 path(目录)和 topicId(主题编号)中选填一个');
|
|
418
|
+
};
|
|
419
|
+
op({
|
|
420
|
+
name: 'topics.ref_add', about: '引用一个目录或另一个主题。path 和 topicId 选填一个,note 是备注。只有目录引用会继承给子主题。',
|
|
421
|
+
input: object(refFields, ['id']),
|
|
422
|
+
output: topicOutput, sdk: true,
|
|
423
|
+
http: ['POST', '/api/topics/:id/refs'], agent: true, topic: 'id', reach: 'own',
|
|
424
|
+
approval: ({ id, path, topicId }) => ({
|
|
425
|
+
title: '添加引用', target: topicLabel(id), impact: topicId ? `引用${topicLabel(topicId)}` : path,
|
|
426
|
+
}),
|
|
427
|
+
run(args, caller) {
|
|
428
|
+
const found = need(args.id);
|
|
429
|
+
const ref = refFrom(args);
|
|
430
|
+
const key = refKey(ref);
|
|
431
|
+
if (found.refs.some((r) => refKey(r) === key))
|
|
432
|
+
throw new Error(isDirRef(ref) ? '这个目录已经在了' : '这个主题已经引用了');
|
|
433
|
+
return topics.update(found.id, { refs: [...found.refs, ref] }, caller.member?.id);
|
|
434
|
+
},
|
|
435
|
+
});
|
|
436
|
+
op({
|
|
437
|
+
name: 'topics.ref_update', about: '更新本主题目录引用的实际路径,保留原来的引用编号。',
|
|
438
|
+
input: object({ id, refId: { type: 'string', description: '本主题目录引用的编号' }, path: refFields.path }, ['id', 'refId', 'path']),
|
|
439
|
+
output: topicOutput, sdk: true,
|
|
440
|
+
http: ['PATCH', '/api/topics/:id/refs/:refId'], agent: true, topic: 'id',
|
|
441
|
+
run({ id, refId, path }, caller) {
|
|
442
|
+
const found = need(id);
|
|
443
|
+
const ref = found.refs.filter(isDirRef).find((ref) => ref.refId === refId);
|
|
444
|
+
if (!ref)
|
|
445
|
+
throw new HttpError(404, '本主题没有这个目录引用');
|
|
446
|
+
const target = refKey({ path });
|
|
447
|
+
if (found.refs.some((other) => other !== ref && refKey(other) === target))
|
|
448
|
+
throw new Error('这个目录已经在了');
|
|
449
|
+
return topics.update(id, { refs: found.refs.map((other) => other === ref ? { ...ref, path } : other) }, caller.member?.id);
|
|
450
|
+
},
|
|
451
|
+
});
|
|
452
|
+
op({
|
|
453
|
+
name: 'topics.ref_remove', about: '去掉当前主题自己的目录或主题引用。path 和 topicId 选填一个。',
|
|
454
|
+
input: object(refFields, ['id']),
|
|
455
|
+
output: topicOutput, sdk: true,
|
|
456
|
+
http: ['POST', '/api/topics/:id/refs/remove'], agent: true, topic: 'id',
|
|
457
|
+
run(args, caller) {
|
|
458
|
+
const found = need(args.id);
|
|
459
|
+
const key = refKey(refFrom(args));
|
|
460
|
+
return topics.update(found.id, { refs: found.refs.filter((r) => refKey(r) !== key) }, caller.member?.id);
|
|
461
|
+
},
|
|
462
|
+
});
|
|
463
|
+
op({
|
|
464
|
+
name: 'topics.summary_set',
|
|
465
|
+
about: '整份替换一个主题的摘要(当前状态的快照,不是往后追加):只写用途、入口、稳定规则和当前卡点,不写进行中事项、待办安排或逐条进展;建议不超过 10 行或 1500 字,超过配置上限会拒绝保存。',
|
|
466
|
+
input: object({ id, text: { type: 'string' } }, ['id', 'text']),
|
|
467
|
+
output: summarySetOutput, sdk: true,
|
|
468
|
+
http: ['PUT', '/api/topics/:id/summary'], agent: true, topic: 'id', tool: tool('topic_summary'),
|
|
469
|
+
run(args, caller) {
|
|
470
|
+
const target = need(args.id);
|
|
471
|
+
const chars = args.text.trim().length;
|
|
472
|
+
const maxChars = config.get('settings', SUMMARY_MAX_CHARS);
|
|
473
|
+
if (chars > maxChars) {
|
|
474
|
+
throw new HttpError(400, `摘要过长(${chars} 字,上限 ${maxChars} 字):摘要是当前状态的快照,过程与历史进展请写进 RFC 或规划回执,精简后再保存。`, undefined, ltext('host.err.summaryTooLong', { chars, max: maxChars }));
|
|
475
|
+
}
|
|
476
|
+
topics.setSummary(target.id, args.text, caller.member?.id);
|
|
477
|
+
if (chars > SUMMARY_SOFT_CHARS) {
|
|
478
|
+
return {
|
|
479
|
+
ok: true,
|
|
480
|
+
warning: `摘要过长(${chars} 字,建议不超过 ${SUMMARY_SOFT_CHARS} 字):摘要是当前状态的快照,请把过程与历史进展挪到 RFC 或规划回执后精简重写。`,
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
return { ok: true };
|
|
484
|
+
},
|
|
485
|
+
text: (result) => (result?.warning ? `摘要已更新。提示:${result.warning}` : '摘要已更新。'),
|
|
486
|
+
});
|
|
487
|
+
op({
|
|
488
|
+
name: 'topics.log', about: '主题树最近的改动:谁、改了哪个主题的什么,每条有编号(撤销时用)。',
|
|
489
|
+
input: object({ limit: { type: 'number' } }), http: ['GET', '/api/tree/log'], agent: true,
|
|
490
|
+
output: treeLogOutput, sdk: true,
|
|
491
|
+
run: (args, caller) => topics.log(Math.min(args.limit ?? (caller.member ? 20 : 50), 200)),
|
|
492
|
+
text(log) {
|
|
493
|
+
// Who works in a topic is among what changes: said by @ name, as everything a member is told is.
|
|
494
|
+
const said = (part) => JSON.stringify(part, (_key, value) => { const member = typeof value === 'string' ? ctx.get('members').get(value) : undefined; return member ? `@${member.handle}` : value; });
|
|
495
|
+
return log.map((c) => `${c.id} ${new Date(c.at).toLocaleString()} ${nameOf(c.by)} 改了「${topics.get(c.topicId)?.title ?? c.topicId}」:${said(c.before)} → ${said(c.after)}`).join('\n') || '(没有改动)';
|
|
496
|
+
},
|
|
497
|
+
});
|
|
498
|
+
op({
|
|
499
|
+
name: 'topics.undo', about: '撤销主题树的一条改动(编号来自 topics.log)。按流水记录的批次恢复,范围外须提请审批。',
|
|
500
|
+
input: object({ id: { type: 'string', description: '改动的编号 chg_…' } }, ['id']), http: ['POST', '/api/tree/undo'], agent: true, reach: 'below',
|
|
501
|
+
output: okOutput, sdk: true,
|
|
502
|
+
approval: ({ id }) => ({ title: '撤销主题树改动', target: id, impact: '按流水记录撤销该批改动' }),
|
|
503
|
+
targets: ({ id }) => topics.undoTargets(id),
|
|
504
|
+
run: ({ id }, caller) => topics.undo(id, caller.member?.id),
|
|
505
|
+
text: () => '已撤销。',
|
|
506
|
+
});
|
|
507
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Ctx } from '../runtime/runtime.ts';
|
|
2
|
+
import type { Topic } from './types.ts';
|
|
3
|
+
export type TopicMetric = number | string[];
|
|
4
|
+
type Values = Record<string, TopicMetric>;
|
|
5
|
+
type Group = 'tree' | 'archive';
|
|
6
|
+
type Read = (ids?: ReadonlySet<string>) => ReadonlyMap<string, TopicMetric>;
|
|
7
|
+
type StatusSet = {
|
|
8
|
+
type: 'set';
|
|
9
|
+
path: string[];
|
|
10
|
+
group: Group;
|
|
11
|
+
values: Values;
|
|
12
|
+
replace?: true;
|
|
13
|
+
};
|
|
14
|
+
/** Sources own their data. This service orders their sparse snapshots and path changes on the console stream. */
|
|
15
|
+
export declare function makeTopicStatus(ctx: Ctx, pathOf: (id: string, includeDeleted?: boolean) => Topic[]): {
|
|
16
|
+
version: () => {
|
|
17
|
+
epoch: string;
|
|
18
|
+
seq: number;
|
|
19
|
+
};
|
|
20
|
+
snapshot: () => {
|
|
21
|
+
operations: StatusSet[];
|
|
22
|
+
epoch: string;
|
|
23
|
+
seq: number;
|
|
24
|
+
};
|
|
25
|
+
source(kind: string, load: Read): () => void;
|
|
26
|
+
set: (kind: string, id: string, value: TopicMetric) => void;
|
|
27
|
+
refresh(kind: string, id: string): void;
|
|
28
|
+
/** A change of display group and any resulting state writes share the prefix move's version. */
|
|
29
|
+
topology<T>(ids: string[], moving: string | undefined, write: () => T): T;
|
|
30
|
+
};
|
|
31
|
+
export type TopicStatus = ReturnType<typeof makeTopicStatus>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { newId } from "./util.js";
|
|
2
|
+
const nonempty = (metric) => Array.isArray(metric) ? metric.length !== 0 : metric !== 0;
|
|
3
|
+
/** Sources own their data. This service orders their sparse snapshots and path changes on the console stream. */
|
|
4
|
+
export function makeTopicStatus(ctx, pathOf) {
|
|
5
|
+
const push = ctx.get('push');
|
|
6
|
+
const epoch = newId('nav');
|
|
7
|
+
let seq = 0;
|
|
8
|
+
let batch;
|
|
9
|
+
const sources = new Map();
|
|
10
|
+
const version = () => ({ epoch, seq });
|
|
11
|
+
ctx.on('push.connected', ({ id }) => push.send('topic.status_ready', version(), id));
|
|
12
|
+
function publish(operations) {
|
|
13
|
+
if (!operations.length)
|
|
14
|
+
return;
|
|
15
|
+
if (batch) {
|
|
16
|
+
batch.push(...operations);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
seq++;
|
|
20
|
+
push.send('topic.status_changed', { ...version(), operations });
|
|
21
|
+
}
|
|
22
|
+
const groupOf = (topic) => topic.archivedAt === null ? 'tree' : 'archive';
|
|
23
|
+
const keys = (path) => path.map(({ id }) => id);
|
|
24
|
+
function read(ids) {
|
|
25
|
+
const data = new Map();
|
|
26
|
+
for (const [kind, load] of sources) {
|
|
27
|
+
for (const [id, value] of load(ids)) {
|
|
28
|
+
if (!nonempty(value) || (ids && !ids.has(id)))
|
|
29
|
+
continue;
|
|
30
|
+
let row = data.get(id);
|
|
31
|
+
if (!row) {
|
|
32
|
+
const path = pathOf(id);
|
|
33
|
+
if (!path.length)
|
|
34
|
+
continue;
|
|
35
|
+
row = { type: 'set', path: keys(path), group: groupOf(path.at(-1)), values: {} };
|
|
36
|
+
data.set(id, row);
|
|
37
|
+
}
|
|
38
|
+
row.values[kind] = value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return data;
|
|
42
|
+
}
|
|
43
|
+
function set(kind, id, value) {
|
|
44
|
+
const path = pathOf(id);
|
|
45
|
+
if (!path.length)
|
|
46
|
+
return;
|
|
47
|
+
publish([{ type: 'set', path: keys(path), group: groupOf(path.at(-1)), values: { [kind]: value } }]);
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
version,
|
|
51
|
+
snapshot: () => ({ ...version(), operations: [...read().values()] }),
|
|
52
|
+
source(kind, load) {
|
|
53
|
+
sources.set(kind, load);
|
|
54
|
+
if (ctx.runtime.ready)
|
|
55
|
+
for (const [id, value] of load())
|
|
56
|
+
set(kind, id, value);
|
|
57
|
+
return () => {
|
|
58
|
+
if (!sources.delete(kind) || !ctx.runtime.ready)
|
|
59
|
+
return;
|
|
60
|
+
for (const [id, value] of load())
|
|
61
|
+
if (nonempty(value))
|
|
62
|
+
set(kind, id, 0);
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
set,
|
|
66
|
+
refresh(kind, id) {
|
|
67
|
+
const load = sources.get(kind);
|
|
68
|
+
if (load)
|
|
69
|
+
set(kind, id, load(new Set([id])).get(id) ?? 0);
|
|
70
|
+
},
|
|
71
|
+
/** A change of display group and any resulting state writes share the prefix move's version. */
|
|
72
|
+
topology(ids, moving, write) {
|
|
73
|
+
const affected = new Set(ids);
|
|
74
|
+
const before = ids.length ? read(affected) : new Map();
|
|
75
|
+
const from = moving ? keys(pathOf(moving, true)) : [];
|
|
76
|
+
const previous = batch;
|
|
77
|
+
const pending = [];
|
|
78
|
+
batch = pending;
|
|
79
|
+
try {
|
|
80
|
+
const result = write();
|
|
81
|
+
const operations = [];
|
|
82
|
+
if (moving) {
|
|
83
|
+
const to = keys(pathOf(moving, true));
|
|
84
|
+
operations.push({ type: 'move', from, to });
|
|
85
|
+
}
|
|
86
|
+
operations.push(...pending);
|
|
87
|
+
if (ids.length) {
|
|
88
|
+
const after = read(affected);
|
|
89
|
+
for (const [id, row] of before) {
|
|
90
|
+
if (!after.has(id))
|
|
91
|
+
operations.push({ ...row, path: keys(pathOf(id, true)), values: {}, replace: true });
|
|
92
|
+
}
|
|
93
|
+
for (const row of after.values())
|
|
94
|
+
operations.push({ ...row, replace: true });
|
|
95
|
+
}
|
|
96
|
+
batch = previous;
|
|
97
|
+
publish(operations);
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
batch = previous;
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|