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,284 @@
|
|
|
1
|
+
export default function (ui) {
|
|
2
|
+
const t = ui.t;
|
|
3
|
+
const endpoint = (op) => '/api/plugins/signals/' + op;
|
|
4
|
+
const signals = (id) => '/api/topics/' + encodeURIComponent(id) + '/signals';
|
|
5
|
+
const stateFor = (topicId) => (S.plug.signals ||= Object.create(null))[topicId] ||= Object.create(null);
|
|
6
|
+
const name = (id) => HL.members.find((member) => member.id === id)?.name ?? id;
|
|
7
|
+
const candidates = (topicId) => HL.members.filter((member) => member.enabled && member.kind === 'agent' && (!topicId || hlWorksHere(topicId)(member)));
|
|
8
|
+
const topicOptions = (except) => hlTopicCatalog().filter((topic) => topic.id !== except && topic.archivedAt == null)
|
|
9
|
+
.map((topic) => [topic.id, hlTopicPath(topic.id).map((step) => step.title).join(' › ')]);
|
|
10
|
+
|
|
11
|
+
const notesPath = (topicId) => '/api/topics/' + encodeURIComponent(topicId) + '/annotations';
|
|
12
|
+
let noteTarget, noteRead;
|
|
13
|
+
|
|
14
|
+
function updateNotes() {
|
|
15
|
+
const target = ui.shown('signals.inbox') && noteTarget;
|
|
16
|
+
if (noteRead?.resource === target?.resource) return;
|
|
17
|
+
noteRead?.controller.abort();
|
|
18
|
+
noteRead = undefined;
|
|
19
|
+
if (!target) return;
|
|
20
|
+
const controller = new AbortController(), { signal } = controller;
|
|
21
|
+
const read = noteRead = { ...target, controller };
|
|
22
|
+
const query = new URLSearchParams({ topicId: read.topicId, resource: read.resource });
|
|
23
|
+
let latest = 0;
|
|
24
|
+
async function reload() {
|
|
25
|
+
const request = ++latest;
|
|
26
|
+
let result;
|
|
27
|
+
try {
|
|
28
|
+
const { cards } = await hlFetch('GET', '/api/annotations?' + query, undefined, signal);
|
|
29
|
+
result = { cards: cards.filter((card) => card.kind === 'comment' && !card.locator), error: undefined };
|
|
30
|
+
} catch (error) {
|
|
31
|
+
result = { error: error.message };
|
|
32
|
+
}
|
|
33
|
+
if (signal.aborted || request !== latest) return;
|
|
34
|
+
Object.assign(read, result);
|
|
35
|
+
render(true);
|
|
36
|
+
}
|
|
37
|
+
hlDocumentListen('annotations.changed', ({ topicId }) => {
|
|
38
|
+
if (!topicId || topicId === read.topicId) reload();
|
|
39
|
+
}, signal);
|
|
40
|
+
hlDocumentListen('open', reload, signal);
|
|
41
|
+
reload();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function notesFor(item, inboxId) {
|
|
45
|
+
const notesOn = plugOn('annotations');
|
|
46
|
+
noteTarget = notesOn && item.resource ? { topicId: inboxId, resource: item.resource } : undefined;
|
|
47
|
+
const read = noteTarget && noteRead?.resource === noteTarget.resource ? noteRead : undefined;
|
|
48
|
+
const notes = (read?.cards ?? []).map((card) => {
|
|
49
|
+
const entry = card.entries[0];
|
|
50
|
+
return { id: card.id, entryId: entry.id, text: entry.body, stamp: entry.editedAt ?? entry.at,
|
|
51
|
+
editable: item.editable && !card.readOnly };
|
|
52
|
+
});
|
|
53
|
+
const notesHint = read?.error || (noteTarget && !read?.cards ? t('loadingNotes') : t('noNotes'));
|
|
54
|
+
return { notesOn, notes, notesHint };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function pick(topicId, id) {
|
|
58
|
+
Object.assign(stateFor(topicId), { selected: id, full: undefined, tab: 'items' });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function groupItems(items, topicId, inboxId) {
|
|
62
|
+
const day = new Date();
|
|
63
|
+
const today = day.setHours(0, 0, 0, 0);
|
|
64
|
+
const yesterday = day.setDate(day.getDate() - 1);
|
|
65
|
+
const groups = ['today', 'yesterday', 'earlier'].map((key) => ({ title: t(key), items: [] }));
|
|
66
|
+
for (const item of items) {
|
|
67
|
+
const group = item.at >= today ? 0 : item.at >= yesterday ? 1 : 2;
|
|
68
|
+
const topicLabel = item.itemTopicId === inboxId ? t('global') : item.itemTopicId !== topicId ? item.itemTopicTitle : undefined;
|
|
69
|
+
groups[group].items.push({ ...item, topicLabel });
|
|
70
|
+
}
|
|
71
|
+
return groups;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function itemDetail(item, inboxId, state) {
|
|
75
|
+
const media = item.media;
|
|
76
|
+
const pdf = media?.kind === 'pdf';
|
|
77
|
+
const full = state.full?.item === item.id && state.full.doc;
|
|
78
|
+
const reading = state.reading?.item === item.id;
|
|
79
|
+
const pool = candidates(inboxId);
|
|
80
|
+
return {
|
|
81
|
+
...item,
|
|
82
|
+
topicLabel: item.itemTopicId === inboxId ? t('global') : item.itemTopicTitle,
|
|
83
|
+
canRead: !!item.doc || item.editable, reading,
|
|
84
|
+
newTopicLabel: t(item.itemTopicId === inboxId ? 'newTopic' : 'newChild'),
|
|
85
|
+
dismissed: item.state === 'dismissed',
|
|
86
|
+
reader: full ? hlFileModel('0:' + full, inboxId) : null,
|
|
87
|
+
player: media && !pdf ? { id: item.id, kind: media.kind, src: media.url, label: item.title } : null,
|
|
88
|
+
pdf: pdf && media.url !== item.url ? media.url : null,
|
|
89
|
+
summaryLabel: item.digestBy ? name(item.digestBy) : t('noMember'),
|
|
90
|
+
summaryOptions: pool,
|
|
91
|
+
canSummarize: item.editable && pool.length > 0,
|
|
92
|
+
summaryPendingLabel: item.summaryPending && t('summaryPending', name(item.summaryPending)),
|
|
93
|
+
summaryAuthor: item.aiSummary && name(item.aiSummary.by),
|
|
94
|
+
...notesFor(item, inboxId),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function searchProps(key, showSources, scope, sources) {
|
|
99
|
+
return {
|
|
100
|
+
key,
|
|
101
|
+
inputId: showSources ? 'signals-search-sources' : 'signals-search-items',
|
|
102
|
+
placeholder: t(showSources ? 'searchSources' : 'searchItems'),
|
|
103
|
+
types: showSources ? [] : [
|
|
104
|
+
{ id: 'source', label: t('filterSource'), icon: 'inbox', values: sources.map((source) => ({
|
|
105
|
+
id: source.id, label: source.name, sub: scope === 'topic' ? undefined : source.topicTitle,
|
|
106
|
+
})) },
|
|
107
|
+
{ id: 'state', label: t('filterState'), icon: 'filter', values: [
|
|
108
|
+
{ id: 'new', label: t('stateNew') }, { id: 'marked', label: t('stateMarked') }, { id: 'dismissed', label: t('stateDismissed') },
|
|
109
|
+
] },
|
|
110
|
+
],
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function editSource(inboxId, source, group) {
|
|
115
|
+
if (!HL_TOPIC_CATALOG) return hlTopicCatalogRead().then(() => editSource(inboxId, source, group), ui.fail);
|
|
116
|
+
const moving = !!source;
|
|
117
|
+
ui.dialog({
|
|
118
|
+
title: t(moving ? 'moveSource' : 'addSource'), ok: tc(moving ? 'common.save' : 'common.add'),
|
|
119
|
+
fields: [
|
|
120
|
+
...(moving ? [] : [
|
|
121
|
+
{ id: 'signals-source-url', label: t('feedUrl'), req: true },
|
|
122
|
+
{ id: 'signals-source-name', label: t('feedName') },
|
|
123
|
+
]),
|
|
124
|
+
{ id: 'signals-source-topic', label: t('sourceTopic'), value: group === inboxId ? '' : group,
|
|
125
|
+
options: [['', t('global')], ...topicOptions(inboxId)] },
|
|
126
|
+
],
|
|
127
|
+
on: () => {
|
|
128
|
+
const target = val('signals-source-topic');
|
|
129
|
+
return hlSave(moving
|
|
130
|
+
? ui.request('PATCH', endpoint('sources/' + encodeURIComponent(source)), { topicId: target })
|
|
131
|
+
: ui.request('POST', signals(target || inboxId) + '/sources', { url: val('signals-source-url'), name: val('signals-source-name') }));
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
select(view, context) {
|
|
138
|
+
const { source, topicId } = context ?? {};
|
|
139
|
+
if (source?.surface === view && source.locator?.range?.detail) {
|
|
140
|
+
pick(topicId, source.target);
|
|
141
|
+
render(true);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
update: updateNotes,
|
|
145
|
+
dispose() { noteRead?.controller.abort(); },
|
|
146
|
+
models: {
|
|
147
|
+
workbench() {
|
|
148
|
+
const topicId = HL.topic.id;
|
|
149
|
+
const state = stateFor(topicId);
|
|
150
|
+
const tab = state.tab || 'items', showSources = tab === 'sources';
|
|
151
|
+
const key = `signals:${topicId}:${tab}`;
|
|
152
|
+
const allTopics = hlTopicViewSpec(topicId)?.args?.defaultScope === 'all';
|
|
153
|
+
const { q, conds } = labelSearchValue(key, { defaultScope: allTopics ? false : 'topic' });
|
|
154
|
+
const conditions = Object.fromEntries(conds.map(({ type, id }) => [type, id]));
|
|
155
|
+
const scope = conditions.scope ?? 'all';
|
|
156
|
+
Object.assign(state, {
|
|
157
|
+
scope, q: q.trim(), filter: showSources ? 'all' : conditions.state ?? 'all',
|
|
158
|
+
source: showSources ? undefined : conditions.source, manage: showSources || undefined,
|
|
159
|
+
});
|
|
160
|
+
const { inbox, load, pending } = VM.plugin('signals', { inbox: 'inbox' });
|
|
161
|
+
const item = inbox?.detail[0], inboxId = inbox?.inboxId;
|
|
162
|
+
const sources = inbox?.sourceOptions ?? [];
|
|
163
|
+
const management = showSources ? inbox?.management : undefined;
|
|
164
|
+
const detail = !showSources && item && item.id === state.selected ? itemDetail(item, inboxId, state) : null;
|
|
165
|
+
if (!detail) noteTarget = undefined;
|
|
166
|
+
return {
|
|
167
|
+
load, pending, tab, showSources, allTopics, inboxId, editable: inbox?.editable,
|
|
168
|
+
detailOpen: !showSources && !!state.selected,
|
|
169
|
+
detailMissing: !showSources && !!state.selected && !item && (load === 'error' || inbox?.selected === state.selected),
|
|
170
|
+
hasSources: sources.some((source) => (allTopics || source.topicId === topicId) && source.editable),
|
|
171
|
+
search: searchProps(key, showSources, scope, sources),
|
|
172
|
+
groups: showSources ? [] : groupItems(inbox?.items ?? [], topicId, inboxId),
|
|
173
|
+
sourceGroups: (inbox?.sourceGroups ?? []).map((group) => ({
|
|
174
|
+
...group,
|
|
175
|
+
title: group.global ? t('global') : group.title,
|
|
176
|
+
memberLabel: group.digestBy ? name(group.digestBy) : t('inheritMember'),
|
|
177
|
+
editable: group.editable && !group.global,
|
|
178
|
+
})),
|
|
179
|
+
detail,
|
|
180
|
+
trail: [{ label: t('items'), act: ui.key('closeItem') }, { label: detail?.title }],
|
|
181
|
+
management: management && {
|
|
182
|
+
...management,
|
|
183
|
+
schedule: { task: management.task, label: t('schedule'), empty: t('scheduleMissing') },
|
|
184
|
+
memberLabel: management.defaultMember ? name(management.defaultMember) : t('noMember'),
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
actions: {
|
|
190
|
+
selectItem({ id }) {
|
|
191
|
+
pick(HL.topic.id, id);
|
|
192
|
+
render(true);
|
|
193
|
+
},
|
|
194
|
+
closeItem() {
|
|
195
|
+
pick(HL.topic.id, undefined);
|
|
196
|
+
render(true);
|
|
197
|
+
},
|
|
198
|
+
async readItem({ item, topicId, refresh = false }) {
|
|
199
|
+
const here = HL.topic.id, state = stateFor(here);
|
|
200
|
+
const request = { item };
|
|
201
|
+
state.reading = request;
|
|
202
|
+
render(true);
|
|
203
|
+
try {
|
|
204
|
+
const { doc, topicId: owner } = await ui.request('POST', endpoint('read'), { id: topicId, item, mode: refresh ? 'refresh' : 'expand' });
|
|
205
|
+
if (HL.topic?.id !== here || state.selected !== item || state.tab !== 'items' || state.reading !== request) return;
|
|
206
|
+
if (owner === here) {
|
|
207
|
+
state.full = { item, doc };
|
|
208
|
+
if (refresh) hlFileRead('0:' + doc, true);
|
|
209
|
+
} else {
|
|
210
|
+
// Document annotations and quotes use the topic that owns the saved file.
|
|
211
|
+
await A.hlTopic({ id: owner, after() {
|
|
212
|
+
pick(owner, item);
|
|
213
|
+
stateFor(owner).full = { item, doc };
|
|
214
|
+
hlMainOpen(owner, 'signals.inbox');
|
|
215
|
+
} });
|
|
216
|
+
}
|
|
217
|
+
} catch (error) { ui.fail(error); }
|
|
218
|
+
finally {
|
|
219
|
+
if (state.reading === request) delete state.reading;
|
|
220
|
+
render(true);
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
async directDiscuss({ item, topicId }) {
|
|
224
|
+
try {
|
|
225
|
+
const result = await ui.request('POST', endpoint('direct-discuss'), { id: topicId, item });
|
|
226
|
+
return A.hlTopic({ id: result.topicId, after() {
|
|
227
|
+
hlMainOpen(result.topicId, 'chat');
|
|
228
|
+
A.composeQuote({ ...result.reference, topicId: result.topicId });
|
|
229
|
+
} });
|
|
230
|
+
} catch (error) { ui.fail(error); }
|
|
231
|
+
},
|
|
232
|
+
linkTopic({ item, topicId, inboxId }) {
|
|
233
|
+
const show = () => ui.dialog({ title: t('linkTopic'), ok: t('linkTopic'),
|
|
234
|
+
fields: [{ id: 'signals-link-topic', label: t('targetTopic'), req: true, options: [['', t('targetTopic')], ...topicOptions(inboxId)] }],
|
|
235
|
+
on: () => {
|
|
236
|
+
const target = val('signals-link-topic');
|
|
237
|
+
return target ? hlSave(plugWrite('signals', 'link', { id: topicId, item, topicId: target })) : false;
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
return HL_TOPIC_CATALOG ? show() : hlTopicCatalogRead().then(show, ui.fail);
|
|
241
|
+
},
|
|
242
|
+
setMember({ member, topicId }) {
|
|
243
|
+
const members = candidates(topicId).map((row) => row.id);
|
|
244
|
+
const label = t('topicMember');
|
|
245
|
+
ui.dialog({ title: label, ok: tc('common.save'), fields: [{ id: 'signals-member', label, value: member || '',
|
|
246
|
+
members, none: t('inheritMember') }],
|
|
247
|
+
on: () => {
|
|
248
|
+
const value = val('signals-member');
|
|
249
|
+
return hlSave(ui.request('POST', signals(topicId) + '/digest', { member: value }));
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
},
|
|
253
|
+
summarize({ item, topicId, member }) {
|
|
254
|
+
return plugWrite('signals', 'summarize', { id: topicId, item, member }).catch(ui.fail);
|
|
255
|
+
},
|
|
256
|
+
editNote({ item, topicId, inboxId, resource, note, entryId, text }) {
|
|
257
|
+
async function save(body) {
|
|
258
|
+
const path = notesPath(inboxId);
|
|
259
|
+
if (note) return ui.request('PATCH', path + '/' + encodeURIComponent(note) + '/entries/' + encodeURIComponent(entryId), { body });
|
|
260
|
+
const address = resource ?? (await ui.request('POST', endpoint('read'), { id: topicId, item, mode: 'preview' })).resource;
|
|
261
|
+
return ui.request('POST', path, { resource: address, body, kind: 'comment' });
|
|
262
|
+
}
|
|
263
|
+
ui.dialog({ title: t(note ? 'editNote' : 'addNote'), ok: tc('common.save'),
|
|
264
|
+
fields: [{ id: 'signals-note-text', label: t('notes'), area: true, rows: 6, req: true, value: text || '' }],
|
|
265
|
+
on: () => {
|
|
266
|
+
const value = val('signals-note-text');
|
|
267
|
+
return value.trim() ? hlSave(save(value)) : false;
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
},
|
|
271
|
+
removeNote({ inboxId, note }) {
|
|
272
|
+
return ui.request('DELETE', notesPath(inboxId) + '/' + encodeURIComponent(note)).catch(ui.fail);
|
|
273
|
+
},
|
|
274
|
+
refresh({ allTopics }) {
|
|
275
|
+
return ui.request('POST', endpoint('refresh'), allTopics ? {} : { id: HL.topic.id }).catch(ui.fail);
|
|
276
|
+
},
|
|
277
|
+
addSource({ inboxId }) { editSource(inboxId, undefined, inboxId); },
|
|
278
|
+
moveSource({ inboxId, id, topicId }) { editSource(inboxId, id, topicId); },
|
|
279
|
+
removeSource({ id, topicId }) {
|
|
280
|
+
return ui.request('DELETE', signals(topicId) + '/sources/' + encodeURIComponent(id)).catch(ui.fail);
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
declare const MEDIA_EXTENSIONS: {
|
|
2
|
+
video: RegExp;
|
|
3
|
+
audio: RegExp;
|
|
4
|
+
image: RegExp;
|
|
5
|
+
pdf: RegExp;
|
|
6
|
+
};
|
|
7
|
+
export type MediaKind = keyof typeof MEDIA_EXTENSIONS;
|
|
8
|
+
export type Media = {
|
|
9
|
+
kind: MediaKind;
|
|
10
|
+
url: string;
|
|
11
|
+
};
|
|
12
|
+
export interface FeedEntry {
|
|
13
|
+
title: string;
|
|
14
|
+
url: string;
|
|
15
|
+
originalUrl?: string;
|
|
16
|
+
/** What the feed says about it, without markup. */
|
|
17
|
+
text: string;
|
|
18
|
+
at: number;
|
|
19
|
+
body?: string;
|
|
20
|
+
media?: Media;
|
|
21
|
+
}
|
|
22
|
+
export declare function webUrl(input: string, base?: string): URL | undefined;
|
|
23
|
+
export declare function mediaOf(url: URL, type?: string, medium?: string): Media | undefined;
|
|
24
|
+
/** The entries of an RSS or Atom feed, with a plain preview and a Markdown body from the feed itself. */
|
|
25
|
+
export declare function readFeed(xml: string, feedUrl?: string): {
|
|
26
|
+
title: string;
|
|
27
|
+
entries: FeedEntry[];
|
|
28
|
+
};
|
|
29
|
+
/** Read ordinary HTML. The feed remains the reading source when the page cannot supply a body. */
|
|
30
|
+
export declare function fetchArticle(url: string): Promise<string | undefined>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
const BODY_BYTES = 64 * 1024;
|
|
2
|
+
const ARTICLE_BYTES = 2 * 1024 * 1024;
|
|
3
|
+
const MEDIA_EXTENSIONS = {
|
|
4
|
+
video: /\.(mp4|m4v|webm|mov|ogv|mpeg|mpg)$/i,
|
|
5
|
+
audio: /\.(mp3|m4a|aac|wav|flac|ogg|oga|opus)$/i,
|
|
6
|
+
image: /\.(avif|gif|heic|jpe?g|png|svg|webp)$/i,
|
|
7
|
+
pdf: /\.pdf$/i,
|
|
8
|
+
};
|
|
9
|
+
const ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ', mdash: '—' };
|
|
10
|
+
function entities(value) {
|
|
11
|
+
return value.replace(/&(amp|lt|gt|quot|apos|nbsp|mdash|#x[\da-f]+|#\d+);/gi, (entity, name) => {
|
|
12
|
+
const key = name.toLowerCase();
|
|
13
|
+
if (key[0] !== '#')
|
|
14
|
+
return ENTITIES[key];
|
|
15
|
+
const code = key[1] === 'x' ? parseInt(key.slice(2), 16) : Number(key.slice(1));
|
|
16
|
+
return code <= 0x10ffff ? String.fromCodePoint(code) : entity;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const xmlContent = (s) => s.split(/(<!\[CDATA\[[\s\S]*?\]\]>)/g)
|
|
20
|
+
.map((part, i) => i % 2 ? part.slice(9, -3) : entities(part)).join('');
|
|
21
|
+
const htmlTag = /<\/?[a-z][\w:-]*(?:\s[^>]*|\s*\/?)>/gi;
|
|
22
|
+
const visibleHtml = (s) => s.replace(/<!--[\s\S]*?-->|<(script|style)\b[^>]*>[\s\S]*?<\/\1\s*>/gi, '');
|
|
23
|
+
const plain = (s) => entities(visibleHtml(xmlContent(s)).replace(htmlTag, ' ')).replace(/\s+/g, ' ').trim();
|
|
24
|
+
const inside = (block, tag) => new RegExp(`<${tag}(?:\\s[^>]*)?>([\\s\\S]*?)</${tag}>`, 'i').exec(block)?.[1] ?? '';
|
|
25
|
+
const attributes = (s) => Object.fromEntries([...s.matchAll(/([\w:-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)].map(([, name, quoted, single]) => [name.toLowerCase(), entities(quoted ?? single)]));
|
|
26
|
+
export function webUrl(input, base) {
|
|
27
|
+
const url = URL.parse(input, base);
|
|
28
|
+
if (url?.protocol === 'http:' || url?.protocol === 'https:')
|
|
29
|
+
return url;
|
|
30
|
+
}
|
|
31
|
+
/** A quote-only entry can point to the article it quotes using HTML's cite attribute. */
|
|
32
|
+
function citedArticle(content, base) {
|
|
33
|
+
const quote = /^\s*<blockquote\b([^>]*)>/i.exec(xmlContent(content));
|
|
34
|
+
const cite = quote && attributes(quote[1]).cite;
|
|
35
|
+
return cite ? webUrl(cite, base)?.href : undefined;
|
|
36
|
+
}
|
|
37
|
+
function markdown(content, base) {
|
|
38
|
+
const html = visibleHtml(content);
|
|
39
|
+
const text = /<\/?[a-z][^>]*>/i.test(html) ? html.replace(/\s+/g, ' ') : html.replace(/\r\n?/g, '\n');
|
|
40
|
+
const body = entities(text
|
|
41
|
+
.replace(/<a\b([^>]*)>([\s\S]*?)<\/a\s*>/gi, (_tag, attrs, label) => {
|
|
42
|
+
const { href } = attributes(attrs);
|
|
43
|
+
const url = href && webUrl(href, base);
|
|
44
|
+
return url && label.trim() ? `[${label.trim()}](${url.href.replaceAll('&', '&')})` : label;
|
|
45
|
+
})
|
|
46
|
+
.replace(/<h([1-6])\b[^>]*>/gi, (_tag, level) => `\n\n${'#'.repeat(Number(level))} `)
|
|
47
|
+
.replace(/<blockquote\b[^>]*>(?:\s*<p\b[^>]*>)?/gi, '\n\n> ')
|
|
48
|
+
.replace(/<\/?(?:p|div|article|section|blockquote|ul|ol|pre|h[1-6])\b[^>]*>/gi, '\n\n')
|
|
49
|
+
.replace(/<li\b[^>]*>/gi, '\n- ')
|
|
50
|
+
.replace(/<br\b[^>]*>/gi, '\n')
|
|
51
|
+
.replace(/<\/?(?:b|strong)\b[^>]*>/gi, '**')
|
|
52
|
+
.replace(/<\/?(?:i|em)\b[^>]*>/gi, '*')
|
|
53
|
+
.replace(/<\/?code\b[^>]*>/gi, '`')
|
|
54
|
+
.replace(htmlTag, ''))
|
|
55
|
+
.replace(/[ \t]+\n|\n[ \t]+/g, '\n').replace(/\n{3,}/g, '\n\n').trim();
|
|
56
|
+
const bytes = Buffer.from(body);
|
|
57
|
+
let end = Math.min(BODY_BYTES, bytes.length);
|
|
58
|
+
while (end < bytes.length && (bytes[end] & 0xc0) === 0x80)
|
|
59
|
+
end--;
|
|
60
|
+
return bytes.toString('utf8', 0, end);
|
|
61
|
+
}
|
|
62
|
+
export function mediaOf(url, type = '', medium = '') {
|
|
63
|
+
const kinds = Object.keys(MEDIA_EXTENSIONS);
|
|
64
|
+
const mime = type.toLowerCase().split(';')[0].trim();
|
|
65
|
+
const kind = kinds.find((key) => (key === 'pdf' ? mime === 'application/pdf' : mime.startsWith(key + '/')) || medium.toLowerCase() === key)
|
|
66
|
+
?? kinds.find((key) => MEDIA_EXTENSIONS[key].test(url.pathname));
|
|
67
|
+
if (kind)
|
|
68
|
+
return { kind, url: url.href };
|
|
69
|
+
}
|
|
70
|
+
function feedMedia(block, url, feedUrl) {
|
|
71
|
+
for (const [, tag, attrs] of block.matchAll(/<(enclosure|media:content|link)\b([^>]*)>/gi)) {
|
|
72
|
+
const { url: src, href, type, medium, rel } = attributes(attrs);
|
|
73
|
+
const link = tag.toLowerCase() === 'link';
|
|
74
|
+
const value = link ? rel?.toLowerCase() === 'enclosure' && href : src;
|
|
75
|
+
const enclosure = value && webUrl(value, feedUrl ?? url.href);
|
|
76
|
+
if (!enclosure)
|
|
77
|
+
continue;
|
|
78
|
+
const media = mediaOf(enclosure, type, medium);
|
|
79
|
+
if (media)
|
|
80
|
+
return media;
|
|
81
|
+
}
|
|
82
|
+
return mediaOf(url);
|
|
83
|
+
}
|
|
84
|
+
/** The entries of an RSS or Atom feed, with a plain preview and a Markdown body from the feed itself. */
|
|
85
|
+
export function readFeed(xml, feedUrl) {
|
|
86
|
+
const blocks = xml.match(/<(item|entry)[\s>][\s\S]*?<\/\1>/gi);
|
|
87
|
+
if (!blocks && !/<(rss|feed|rdf:RDF)[\s>]/i.test(xml))
|
|
88
|
+
throw new Error('不是 RSS 或 Atom');
|
|
89
|
+
const head = blocks ? xml.slice(0, xml.indexOf(blocks[0])) : xml;
|
|
90
|
+
const entries = [];
|
|
91
|
+
for (const block of blocks ?? []) {
|
|
92
|
+
const links = [...block.matchAll(/<link\b([^>]*)\/?>(?:([^<]*)<\/link>)?/gi)]
|
|
93
|
+
.map(([, attrs, text]) => {
|
|
94
|
+
const { href, rel } = attributes(attrs);
|
|
95
|
+
return { href, rel, text };
|
|
96
|
+
});
|
|
97
|
+
const atom = links.find((link) => link.rel?.toLowerCase() === 'alternate')
|
|
98
|
+
?? links.find((link) => link.href && !link.rel) ?? links.find((link) => link.href);
|
|
99
|
+
const url = atom?.href ?? plain(links[0]?.text ?? '');
|
|
100
|
+
const parsed = url && webUrl(url, feedUrl);
|
|
101
|
+
if (!parsed)
|
|
102
|
+
continue;
|
|
103
|
+
const link = /^https?:\/\//i.test(url) ? url : parsed.href;
|
|
104
|
+
const when = Date.parse(plain(inside(block, 'pubDate') || inside(block, 'published') || inside(block, 'updated') || inside(block, 'dc:date')));
|
|
105
|
+
const [encoded, content, description, summary] = ['content:encoded', 'content', 'description', 'summary'].map((tag) => inside(block, tag));
|
|
106
|
+
const originalUrl = encoded || content ? undefined : citedArticle(description || summary || '', link);
|
|
107
|
+
entries.push({
|
|
108
|
+
title: plain(inside(block, 'title')) || link, url: link, at: Number.isNaN(when) ? Date.now() : when,
|
|
109
|
+
text: plain(description || summary || content || encoded || '').slice(0, 600),
|
|
110
|
+
body: markdown(xmlContent(encoded || content || description || summary || ''), link),
|
|
111
|
+
media: feedMedia(block, parsed, feedUrl),
|
|
112
|
+
...(originalUrl && { originalUrl }),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
title: plain(inside(head, 'title')),
|
|
117
|
+
entries,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/** Read ordinary HTML. The feed remains the reading source when the page cannot supply a body. */
|
|
121
|
+
export async function fetchArticle(url) {
|
|
122
|
+
if (!webUrl(url))
|
|
123
|
+
return;
|
|
124
|
+
const res = await fetch(url, {
|
|
125
|
+
signal: AbortSignal.timeout(8_000), headers: { 'user-agent': 'hostlet-signals', accept: 'text/html, application/xhtml+xml' },
|
|
126
|
+
});
|
|
127
|
+
const type = res.headers.get('content-type')?.split(';', 1)[0]?.trim().toLowerCase();
|
|
128
|
+
if (!res.ok || !res.body || (type !== 'text/html' && type !== 'application/xhtml+xml')) {
|
|
129
|
+
await res.body?.cancel();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const reader = res.body.getReader(), decode = new TextDecoder();
|
|
133
|
+
let bytes = 0, html = '';
|
|
134
|
+
while (true) {
|
|
135
|
+
const { done, value } = await reader.read();
|
|
136
|
+
if (done)
|
|
137
|
+
break;
|
|
138
|
+
const remaining = ARTICLE_BYTES - bytes;
|
|
139
|
+
html += decode.decode(value.subarray(0, remaining), { stream: true });
|
|
140
|
+
bytes += value.byteLength;
|
|
141
|
+
if (bytes >= ARTICLE_BYTES) {
|
|
142
|
+
await reader.cancel();
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
html += decode.decode();
|
|
147
|
+
const cleaned = visibleHtml(html).replace(/<(nav|footer|aside|form|noscript|template|svg)\b[^>]*>[\s\S]*?<\/\1\s*>/gi, '');
|
|
148
|
+
const body = inside(cleaned, 'body') || cleaned;
|
|
149
|
+
const main = inside(body, 'main') || body;
|
|
150
|
+
return markdown(inside(main, 'article') || main, res.url) || undefined;
|
|
151
|
+
}
|