hostlet 0.0.0-stage → 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +233 -2
- package/bin/hostlet.js +61 -0
- package/console/app/api.js +1223 -0
- package/console/app/boot.js +165 -0
- package/console/app/cards.js +222 -0
- package/console/app/compose-quote.js +127 -0
- package/console/app/config-form.js +727 -0
- package/console/app/document-drafts.js +62 -0
- package/console/app/document-tools.mjs +67 -0
- package/console/app/documents.js +106 -0
- package/console/app/pages.js +6483 -0
- package/console/app/plugins.js +509 -0
- package/console/app/preview-tools.js +172 -0
- package/console/app/reference-labels.js +118 -0
- package/console/app/selection.js +372 -0
- package/console/app/store.js +57 -0
- package/console/app/text-anchor.js +26 -0
- package/console/app/topic-local.js +322 -0
- package/console/app/topic-nav.js +414 -0
- package/console/app/topic-status.js +109 -0
- package/console/app/views.js +43 -0
- package/console/apple-touch-icon.png +0 -0
- package/console/avatars/agy.svg +34 -0
- package/console/avatars/alhena.svg +36 -0
- package/console/avatars/castor.svg +38 -0
- package/console/avatars/claude.svg +34 -0
- package/console/avatars/codex.svg +34 -0
- package/console/avatars/devin.svg +34 -0
- package/console/avatars/echo.svg +34 -0
- package/console/avatars/kimi.svg +33 -0
- package/console/avatars/opencode.svg +33 -0
- package/console/avatars/pinion.svg +34 -0
- package/console/avatars/sprocket.svg +34 -0
- package/console/avatars/vela.svg +44 -0
- package/console/avatars/wasat.svg +38 -0
- package/console/clients/agy.svg +1 -0
- package/console/clients/claude.svg +1 -0
- package/console/clients/codex.svg +1 -0
- package/console/clients/devin.svg +1 -0
- package/console/clients/kimi.svg +1 -0
- package/console/clients/opencode.svg +1 -0
- package/console/favicon.ico +0 -0
- package/console/favicon.svg +16 -0
- package/console/index.html +99 -0
- package/console/pdl/engine/README.md +13 -0
- package/console/pdl/engine/anchor.js +195 -0
- package/console/pdl/engine/core.js +1340 -0
- package/console/pdl/engine/frame.js +1252 -0
- package/console/pdl/engine/i18n.js +67 -0
- package/console/pdl/engine/pdl-check.js +102 -0
- package/console/pdl/engine/pdl-doc.js +353 -0
- package/console/pdl/engine/pdl-view.js +280 -0
- package/console/pdl/engine/pdl.js +1064 -0
- package/console/pdl/engine/platform.js +18 -0
- package/console/pdl/engine/proj.js +279 -0
- package/console/pdl/engine/theme.js +176 -0
- package/console/pdl/engine/tree.js +171 -0
- package/console/pdl/engine/units.js +546 -0
- package/console/pdl/library/README.md +28 -0
- package/console/pdl/library/blocks.js +1512 -0
- package/console/pdl/library/buttons.js +86 -0
- package/console/pdl/library/capsules.js +130 -0
- package/console/pdl/library/charts.js +287 -0
- package/console/pdl/library/code.js +98 -0
- package/console/pdl/library/css/base.css +12 -0
- package/console/pdl/library/css/blocks.css +98 -0
- package/console/pdl/library/css/capsules.css +42 -0
- package/console/pdl/library/css/catalog-page.css +24 -0
- package/console/pdl/library/css/chat.css +100 -0
- package/console/pdl/library/css/composer-top.css +145 -0
- package/console/pdl/library/css/controls.css +195 -0
- package/console/pdl/library/css/drag.css +29 -0
- package/console/pdl/library/css/edit-layout.css +93 -0
- package/console/pdl/library/css/floating-window.css +30 -0
- package/console/pdl/library/css/hover.css +50 -0
- package/console/pdl/library/css/label-search.css +37 -0
- package/console/pdl/library/css/layers.css +43 -0
- package/console/pdl/library/css/library-parts.css +33 -0
- package/console/pdl/library/css/library.css +117 -0
- package/console/pdl/library/css/member-select.css +34 -0
- package/console/pdl/library/css/message.css +72 -0
- package/console/pdl/library/css/page.css +104 -0
- package/console/pdl/library/css/parts.css +338 -0
- package/console/pdl/library/css/responsive.css +40 -0
- package/console/pdl/library/css/roles.css +28 -0
- package/console/pdl/library/css/rows.css +231 -0
- package/console/pdl/library/css/settings-rows.css +37 -0
- package/console/pdl/library/css/shell.css +59 -0
- package/console/pdl/library/css/stream.css +296 -0
- package/console/pdl/library/css/theme-calculator.css +18 -0
- package/console/pdl/library/css/thumb-choice.css +69 -0
- package/console/pdl/library/css/tweaks.css +16 -0
- package/console/pdl/library/css/widgets.css +211 -0
- package/console/pdl/library/css/workbench.css +59 -0
- package/console/pdl/library/feedback.js +83 -0
- package/console/pdl/library/floating-window.mjs +100 -0
- package/console/pdl/library/fold.js +238 -0
- package/console/pdl/library/format.js +53 -0
- package/console/pdl/library/frames.js +123 -0
- package/console/pdl/library/icons.js +165 -0
- package/console/pdl/library/identity.js +149 -0
- package/console/pdl/library/inputs.js +801 -0
- package/console/pdl/library/label-search.js +214 -0
- package/console/pdl/library/markdown-text.js +115 -0
- package/console/pdl/library/markdown.js +150 -0
- package/console/pdl/library/media-viewer.js +293 -0
- package/console/pdl/library/member-select.mjs +32 -0
- package/console/pdl/library/message.js +105 -0
- package/console/pdl/library/motion.js +56 -0
- package/console/pdl/library/overlays.js +165 -0
- package/console/pdl/library/page.js +142 -0
- package/console/pdl/library/plugin-form.js +154 -0
- package/console/pdl/library/registry.js +198 -0
- package/console/pdl/library/rows.js +523 -0
- package/console/pdl/library/shell.js +151 -0
- package/console/pdl/library/stream.js +58 -0
- package/console/pdl/library/tabs.js +259 -0
- package/console/pdl/library/theme-calculator.js +300 -0
- package/console/pdl/library/widgets.js +114 -0
- package/console/pdl/load-order.json +74 -0
- package/console/pdl/platform/README.md +3 -0
- package/console/pdl/platform/rich-markdown.mjs +17 -0
- package/console/pdl/platform/web-links.js +26 -0
- package/console/pdl/platform/web.js +80 -0
- package/console/sdk-browser/mentions.d.mts +16 -0
- package/console/sdk-browser/mentions.mjs +84 -0
- package/console/theme/assets.js +21 -0
- package/console/theme/theme.json +9417 -0
- package/console/theme/tokens.json +444 -0
- package/dist/core/a2a.d.ts +288 -0
- package/dist/core/a2a.js +2197 -0
- package/dist/core/address.d.ts +34 -0
- package/dist/core/address.js +33 -0
- package/dist/core/approval-inputs.d.ts +17 -0
- package/dist/core/approval-inputs.js +70 -0
- package/dist/core/archive.d.ts +19 -0
- package/dist/core/archive.js +135 -0
- package/dist/core/attachments.d.ts +17 -0
- package/dist/core/attachments.js +143 -0
- package/dist/core/blocked-handoffs.d.ts +132 -0
- package/dist/core/blocked-handoffs.js +349 -0
- package/dist/core/config-schema.d.ts +124 -0
- package/dist/core/config-schema.js +192 -0
- package/dist/core/config.d.ts +117 -0
- package/dist/core/config.js +638 -0
- package/dist/core/disk-usage.d.ts +26 -0
- package/dist/core/disk-usage.js +83 -0
- package/dist/core/documents.d.ts +9 -0
- package/dist/core/documents.js +48 -0
- package/dist/core/entry.d.ts +316 -0
- package/dist/core/entry.js +711 -0
- package/dist/core/home.d.ts +76 -0
- package/dist/core/home.js +449 -0
- package/dist/core/i18n.d.ts +36 -0
- package/dist/core/i18n.js +458 -0
- package/dist/core/instances.d.ts +224 -0
- package/dist/core/instances.js +1272 -0
- package/dist/core/members.d.ts +190 -0
- package/dist/core/members.js +358 -0
- package/dist/core/mentions.d.ts +12 -0
- package/dist/core/mentions.js +49 -0
- package/dist/core/messages.d.ts +876 -0
- package/dist/core/messages.js +916 -0
- package/dist/core/notices.d.ts +88 -0
- package/dist/core/notices.js +54 -0
- package/dist/core/ops.d.ts +117 -0
- package/dist/core/ops.js +146 -0
- package/dist/core/package.d.ts +2 -0
- package/dist/core/package.js +14 -0
- package/dist/core/parts.d.ts +25 -0
- package/dist/core/parts.js +119 -0
- package/dist/core/plugins/catalog.d.ts +14 -0
- package/dist/core/plugins/catalog.js +54 -0
- package/dist/core/plugins/external.d.ts +7 -0
- package/dist/core/plugins/external.js +921 -0
- package/dist/core/plugins/index.d.ts +5 -0
- package/dist/core/plugins/index.js +51 -0
- package/dist/core/plugins/npm.d.ts +12 -0
- package/dist/core/plugins/npm.js +99 -0
- package/dist/core/plugins/plugin-manifest.d.ts +12 -0
- package/dist/core/plugins/plugin-manifest.js +231 -0
- package/dist/core/push.d.ts +22 -0
- package/dist/core/push.js +63 -0
- package/dist/core/resource.d.ts +77 -0
- package/dist/core/resource.js +48 -0
- package/dist/core/spawn.d.ts +12 -0
- package/dist/core/spawn.js +30 -0
- package/dist/core/storage-inventory.d.ts +118 -0
- package/dist/core/storage-inventory.js +279 -0
- package/dist/core/storage.d.ts +45 -0
- package/dist/core/storage.js +602 -0
- package/dist/core/store.d.ts +15 -0
- package/dist/core/store.js +33 -0
- package/dist/core/topic-index.d.ts +19 -0
- package/dist/core/topic-index.js +70 -0
- package/dist/core/topic-ops.d.ts +139 -0
- package/dist/core/topic-ops.js +507 -0
- package/dist/core/topic-status.d.ts +32 -0
- package/dist/core/topic-status.js +105 -0
- package/dist/core/topics.d.ts +327 -0
- package/dist/core/topics.js +786 -0
- package/dist/core/turn-clients.d.ts +1 -0
- package/dist/core/turn-clients.js +5 -0
- package/dist/core/types.d.ts +2866 -0
- package/dist/core/types.js +166 -0
- package/dist/core/util.d.ts +10 -0
- package/dist/core/util.js +47 -0
- package/dist/main.d.ts +12 -0
- package/dist/main.js +82 -0
- package/dist/plugins/adapter-acp/index.d.ts +3 -0
- package/dist/plugins/adapter-acp/index.js +57 -0
- package/dist/plugins/adapter-acp/plugin.yaml +100 -0
- package/dist/plugins/adapter-agy/command.d.ts +9 -0
- package/dist/plugins/adapter-agy/command.js +34 -0
- package/dist/plugins/adapter-agy/index.d.ts +5 -0
- package/dist/plugins/adapter-agy/index.js +65 -0
- package/dist/plugins/adapter-agy/quota.d.ts +2 -0
- package/dist/plugins/adapter-agy/quota.js +155 -0
- package/dist/plugins/adapter-agy/terminal.d.ts +6 -0
- package/dist/plugins/adapter-agy/terminal.js +132 -0
- package/dist/plugins/adapter-agy/version.d.ts +9 -0
- package/dist/plugins/adapter-agy/version.js +17 -0
- package/dist/plugins/adapter-claude/index.d.ts +43 -0
- package/dist/plugins/adapter-claude/index.js +412 -0
- package/dist/plugins/adapter-claude/quota.d.ts +14 -0
- package/dist/plugins/adapter-claude/quota.js +103 -0
- package/dist/plugins/adapter-codex/index.d.ts +4 -0
- package/dist/plugins/adapter-codex/index.js +688 -0
- package/dist/plugins/adapter-codex/responses-model.d.ts +9 -0
- package/dist/plugins/adapter-codex/responses-model.js +82 -0
- package/dist/plugins/adapter-kimi/index.d.ts +4 -0
- package/dist/plugins/adapter-kimi/index.js +51 -0
- package/dist/plugins/adapter-kimi/quota.d.ts +3 -0
- package/dist/plugins/adapter-kimi/quota.js +171 -0
- package/dist/plugins/adapter-opencode/index.d.ts +12 -0
- package/dist/plugins/adapter-opencode/index.js +64 -0
- package/dist/plugins/annotations/console/cards.css +189 -0
- package/dist/plugins/annotations/console/cards.mjs +439 -0
- package/dist/plugins/annotations/console/pdl.json +52 -0
- package/dist/plugins/annotations/console/view.mjs +241 -0
- package/dist/plugins/annotations/console/window.mjs +219 -0
- package/dist/plugins/annotations/followups.d.ts +51 -0
- package/dist/plugins/annotations/followups.js +112 -0
- package/dist/plugins/annotations/index.d.ts +3 -0
- package/dist/plugins/annotations/index.js +298 -0
- package/dist/plugins/annotations/plugin.yaml +3 -0
- package/dist/plugins/ask-choice/index.d.ts +9 -0
- package/dist/plugins/ask-choice/index.js +24 -0
- package/dist/plugins/ask-choice/plugin.yaml +2 -0
- package/dist/plugins/background/index.d.ts +2 -0
- package/dist/plugins/background/index.js +398 -0
- package/dist/plugins/background/plugin.yaml +7 -0
- package/dist/plugins/builtin.json +37 -0
- package/dist/plugins/cards/console/pdl.json +516 -0
- package/dist/plugins/cards/console/view.mjs +67 -0
- package/dist/plugins/cards/index.d.ts +8 -0
- package/dist/plugins/cards/index.js +627 -0
- package/dist/plugins/cards/plugin.yaml +3 -0
- package/dist/plugins/console/browser.d.ts +2 -0
- package/dist/plugins/console/browser.js +115 -0
- package/dist/plugins/console/console/pdl.json +38 -0
- package/dist/plugins/console/console/view.mjs +26 -0
- package/dist/plugins/console/index.d.ts +4 -0
- package/dist/plugins/console/index.js +94 -0
- package/dist/plugins/console/picker.d.ts +2 -0
- package/dist/plugins/console/picker.js +48 -0
- package/dist/plugins/console/plugin.yaml +3 -0
- package/dist/plugins/console/topic-view.d.ts +3 -0
- package/dist/plugins/console/topic-view.js +388 -0
- package/dist/plugins/handoff/index.d.ts +2 -0
- package/dist/plugins/handoff/index.js +147 -0
- package/dist/plugins/handoff/plugin.yaml +8 -0
- package/dist/plugins/host-api/index.d.ts +7 -0
- package/dist/plugins/host-api/index.js +310 -0
- package/dist/plugins/host-api/plugin.yaml +2 -0
- package/dist/plugins/host-api/signing.d.ts +63 -0
- package/dist/plugins/host-api/signing.js +427 -0
- package/dist/plugins/host-api/skills/host-ops/SKILL.md +28 -0
- package/dist/plugins/host-api/skills/hostlet-plugin-dev/SKILL.md +38 -0
- package/dist/plugins/inbox/index.d.ts +15 -0
- package/dist/plugins/inbox/index.js +161 -0
- package/dist/plugins/inbox/plugin.yaml +2 -0
- package/dist/plugins/keys/account-directories.d.ts +18 -0
- package/dist/plugins/keys/account-directories.js +86 -0
- package/dist/plugins/keys/account-storage.d.ts +18 -0
- package/dist/plugins/keys/account-storage.js +112 -0
- package/dist/plugins/keys/console/pdl.json +710 -0
- package/dist/plugins/keys/console/view.mjs +619 -0
- package/dist/plugins/keys/index.d.ts +7 -0
- package/dist/plugins/keys/index.js +842 -0
- package/dist/plugins/keys/login-link.d.ts +2 -0
- package/dist/plugins/keys/login-link.js +15 -0
- package/dist/plugins/keys/plugin.yaml +3 -0
- package/dist/plugins/keys/quota-history.d.ts +91 -0
- package/dist/plugins/keys/quota-history.js +420 -0
- package/dist/plugins/mcp/console/pdl.json +412 -0
- package/dist/plugins/mcp/console/view.mjs +207 -0
- package/dist/plugins/mcp/index.d.ts +7 -0
- package/dist/plugins/mcp/index.js +494 -0
- package/dist/plugins/mcp/plugin.yaml +3 -0
- package/dist/plugins/member-health/index.d.ts +2 -0
- package/dist/plugins/member-health/index.js +478 -0
- package/dist/plugins/member-health/plugin.yaml +2 -0
- package/dist/plugins/memory/capabilities.d.ts +10 -0
- package/dist/plugins/memory/capabilities.js +70 -0
- package/dist/plugins/memory/console/pdl.json +459 -0
- package/dist/plugins/memory/console/view.mjs +254 -0
- package/dist/plugins/memory/corpus.d.ts +60 -0
- package/dist/plugins/memory/corpus.js +521 -0
- package/dist/plugins/memory/engines/fts-tree-diversity.d.ts +8 -0
- package/dist/plugins/memory/engines/fts-tree-diversity.js +49 -0
- package/dist/plugins/memory/engines/fts-tree-text.d.ts +12 -0
- package/dist/plugins/memory/engines/fts-tree-text.js +93 -0
- package/dist/plugins/memory/engines/fts-tree.d.ts +4 -0
- package/dist/plugins/memory/engines/fts-tree.js +387 -0
- package/dist/plugins/memory/engines/search.d.ts +9 -0
- package/dist/plugins/memory/engines/search.js +35 -0
- package/dist/plugins/memory/index.d.ts +3 -0
- package/dist/plugins/memory/index.js +465 -0
- package/dist/plugins/memory/notes.d.ts +22 -0
- package/dist/plugins/memory/notes.js +140 -0
- package/dist/plugins/memory/plugin.yaml +23 -0
- package/dist/plugins/model-profiles/index.d.ts +2 -0
- package/dist/plugins/model-profiles/index.js +916 -0
- package/dist/plugins/model-profiles/plugin.yaml +13 -0
- package/dist/plugins/model-profiles/review-source.d.ts +11 -0
- package/dist/plugins/model-profiles/review-source.js +640 -0
- package/dist/plugins/model-profiles/rules.d.ts +130 -0
- package/dist/plugins/model-profiles/rules.js +729 -0
- package/dist/plugins/model-profiles/skills/model-profile/SKILL.md +59 -0
- package/dist/plugins/model-profiles/sources.d.ts +61 -0
- package/dist/plugins/model-profiles/sources.js +375 -0
- package/dist/plugins/model-profiles/storage.d.ts +84 -0
- package/dist/plugins/model-profiles/storage.js +315 -0
- package/dist/plugins/model-profiles/types.d.ts +179 -0
- package/dist/plugins/model-profiles/types.js +12 -0
- package/dist/plugins/model-profiles/wakeup.d.ts +29 -0
- package/dist/plugins/model-profiles/wakeup.js +390 -0
- package/dist/plugins/models/index.d.ts +2 -0
- package/dist/plugins/models/index.js +63 -0
- package/dist/plugins/models/plugin.yaml +8 -0
- package/dist/plugins/ops/collector.d.ts +22 -0
- package/dist/plugins/ops/collector.js +48 -0
- package/dist/plugins/ops/config.d.ts +11 -0
- package/dist/plugins/ops/config.js +13 -0
- package/dist/plugins/ops/console/pdl.json +676 -0
- package/dist/plugins/ops/console/view.mjs +700 -0
- package/dist/plugins/ops/index.d.ts +3 -0
- package/dist/plugins/ops/index.js +20 -0
- package/dist/plugins/ops/journal.d.ts +7 -0
- package/dist/plugins/ops/journal.js +109 -0
- package/dist/plugins/ops/metrics.d.ts +3 -0
- package/dist/plugins/ops/metrics.js +81 -0
- package/dist/plugins/ops/plugin.yaml +63 -0
- package/dist/plugins/ops/samples.d.ts +54 -0
- package/dist/plugins/ops/samples.js +100 -0
- package/dist/plugins/ops/trace.d.ts +3 -0
- package/dist/plugins/ops/trace.js +104 -0
- package/dist/plugins/ops/usage.d.ts +2 -0
- package/dist/plugins/ops/usage.js +152 -0
- package/dist/plugins/plans/acceptance.d.ts +284 -0
- package/dist/plugins/plans/acceptance.js +247 -0
- package/dist/plugins/plans/blocked.d.ts +25 -0
- package/dist/plugins/plans/blocked.js +66 -0
- package/dist/plugins/plans/console/pdl.json +639 -0
- package/dist/plugins/plans/console/view.d.mts +2 -0
- package/dist/plugins/plans/console/view.mjs +855 -0
- package/dist/plugins/plans/dependencies.d.ts +5 -0
- package/dist/plugins/plans/dependencies.js +21 -0
- package/dist/plugins/plans/index.d.ts +72 -0
- package/dist/plugins/plans/index.js +2057 -0
- package/dist/plugins/plans/plugin.yaml +44 -0
- package/dist/plugins/plans/progress.d.ts +82 -0
- package/dist/plugins/plans/progress.js +516 -0
- package/dist/plugins/prompt/index.d.ts +8 -0
- package/dist/plugins/prompt/index.js +361 -0
- package/dist/plugins/prompt/plugin.yaml +2 -0
- package/dist/plugins/recovery/console/pdl.json +50 -0
- package/dist/plugins/recovery/console/view.mjs +46 -0
- package/dist/plugins/recovery/index.d.ts +9 -0
- package/dist/plugins/recovery/index.js +454 -0
- package/dist/plugins/recovery/plugin.yaml +9 -0
- package/dist/plugins/recovery/probe.d.ts +11 -0
- package/dist/plugins/recovery/probe.js +128 -0
- package/dist/plugins/restart/console/pdl.json +112 -0
- package/dist/plugins/restart/console/view.mjs +85 -0
- package/dist/plugins/restart/index.d.ts +10 -0
- package/dist/plugins/restart/index.js +669 -0
- package/dist/plugins/restart/plugin.yaml +9 -0
- package/dist/plugins/restart/scope.d.ts +6 -0
- package/dist/plugins/restart/scope.js +44 -0
- package/dist/plugins/schedule/console/pdl.json +696 -0
- package/dist/plugins/schedule/console/view.mjs +398 -0
- package/dist/plugins/schedule/events.d.ts +76 -0
- package/dist/plugins/schedule/events.js +158 -0
- package/dist/plugins/schedule/index.d.ts +32 -0
- package/dist/plugins/schedule/index.js +1199 -0
- package/dist/plugins/schedule/plugin.yaml +26 -0
- package/dist/plugins/schedule/when.d.ts +14 -0
- package/dist/plugins/schedule/when.js +83 -0
- package/dist/plugins/sessions/console/pdl.json +259 -0
- package/dist/plugins/sessions/console/view.mjs +355 -0
- package/dist/plugins/sessions/index.d.ts +3 -0
- package/dist/plugins/sessions/index.js +126 -0
- package/dist/plugins/sessions/participants.d.ts +28 -0
- package/dist/plugins/sessions/participants.js +83 -0
- package/dist/plugins/sessions/plugin.yaml +3 -0
- package/dist/plugins/signals/console/pdl.json +802 -0
- package/dist/plugins/signals/console/view.mjs +284 -0
- package/dist/plugins/signals/content.d.ts +31 -0
- package/dist/plugins/signals/content.js +151 -0
- package/dist/plugins/signals/index.d.ts +2 -0
- package/dist/plugins/signals/index.js +601 -0
- package/dist/plugins/signals/plugin.yaml +32 -0
- package/dist/plugins/signals/skills/signal-sources/SKILL.md +27 -0
- package/dist/plugins/skills/console/pdl.json +254 -0
- package/dist/plugins/skills/console/view.mjs +204 -0
- package/dist/plugins/skills/index.d.ts +11 -0
- package/dist/plugins/skills/index.js +567 -0
- package/dist/plugins/skills/install.d.ts +69 -0
- package/dist/plugins/skills/install.js +265 -0
- package/dist/plugins/skills/plugin.yaml +24 -0
- package/dist/plugins/skills/safety-scan.d.ts +17 -0
- package/dist/plugins/skills/safety-scan.js +78 -0
- package/dist/plugins/skills/skills/skill-ops/SKILL.md +29 -0
- package/dist/plugins/terminal/console/pdl.json +115 -0
- package/dist/plugins/terminal/console/view.mjs +178 -0
- package/dist/plugins/terminal/index.d.ts +3 -0
- package/dist/plugins/terminal/index.js +204 -0
- package/dist/plugins/terminal/plugin.yaml +2 -0
- package/dist/plugins/tools/index.d.ts +3 -0
- package/dist/plugins/tools/index.js +455 -0
- package/dist/plugins/tools/plugin.yaml +2 -0
- package/dist/plugins/tools/token.d.ts +61 -0
- package/dist/plugins/tools/token.js +179 -0
- package/dist/plugins/topic-tools/index.d.ts +9 -0
- package/dist/plugins/topic-tools/index.js +29 -0
- package/dist/plugins/topic-tools/plugin.yaml +2 -0
- package/dist/plugins/topic-tools/skills/topic-tidy/SKILL.md +108 -0
- package/dist/plugins/works/console/pdl.json +120 -0
- package/dist/plugins/works/console/view.mjs +91 -0
- package/dist/plugins/works/document-words.d.ts +50 -0
- package/dist/plugins/works/document-words.js +27 -0
- package/dist/plugins/works/editors.d.ts +3 -0
- package/dist/plugins/works/editors.js +162 -0
- package/dist/plugins/works/events.d.ts +58 -0
- package/dist/plugins/works/events.js +82 -0
- package/dist/plugins/works/files.d.ts +23 -0
- package/dist/plugins/works/files.js +53 -0
- package/dist/plugins/works/index.d.ts +9 -0
- package/dist/plugins/works/index.js +1088 -0
- package/dist/plugins/works/plugin.yaml +9 -0
- package/dist/plugins/works/preview.d.ts +10 -0
- package/dist/plugins/works/preview.js +30 -0
- package/dist/plugins/works/project.d.ts +3 -0
- package/dist/plugins/works/project.js +245 -0
- package/dist/plugins/works/resource.d.ts +28 -0
- package/dist/plugins/works/resource.js +71 -0
- package/dist/plugins/works/retention.d.ts +36 -0
- package/dist/plugins/works/retention.js +295 -0
- package/dist/plugins/works/skills/works-ops/SKILL.md +14 -0
- package/dist/plugins/works/viewers.d.ts +13 -0
- package/dist/plugins/works/viewers.js +87 -0
- package/dist/plugins/works/web/anchors.js +94 -0
- package/dist/plugins/works/web/document-edit.js +245 -0
- package/dist/plugins/works/web/preview-bridge.js +142 -0
- package/dist/plugins/works/web/reading-position.js +74 -0
- package/dist/plugins/works/web/view.html +1118 -0
- package/dist/runtime/runtime.d.ts +210 -0
- package/dist/runtime/runtime.js +338 -0
- package/dist/sdk/adapter-kit.d.ts +1 -0
- package/dist/sdk/adapter-kit.js +1 -0
- package/dist/sdk/client.d.ts +163 -0
- package/dist/sdk/client.js +43 -0
- package/dist/sdk/contracts.d.ts +1263 -0
- package/dist/sdk/contracts.js +1 -0
- package/dist/sdk/index.d.ts +57 -0
- package/dist/sdk/index.js +27 -0
- package/dist/sdk/source-choice.d.ts +40 -0
- package/dist/sdk/source-choice.js +217 -0
- package/dist/sdk/topic-text.d.ts +5 -0
- package/dist/sdk/topic-text.js +26 -0
- package/dist/sdk/transport.d.ts +12 -0
- package/dist/sdk/transport.js +34 -0
- package/node_modules/@hostlet/adapter-kit/dist/acp.d.ts +88 -0
- package/node_modules/@hostlet/adapter-kit/dist/acp.js +674 -0
- package/node_modules/@hostlet/adapter-kit/dist/command.d.ts +18 -0
- package/node_modules/@hostlet/adapter-kit/dist/command.js +39 -0
- package/node_modules/@hostlet/adapter-kit/dist/index.d.ts +8 -0
- package/node_modules/@hostlet/adapter-kit/dist/index.js +6 -0
- package/node_modules/@hostlet/adapter-kit/dist/models.d.ts +29 -0
- package/node_modules/@hostlet/adapter-kit/dist/models.js +108 -0
- package/node_modules/@hostlet/adapter-kit/dist/quota.d.ts +3 -0
- package/node_modules/@hostlet/adapter-kit/dist/quota.js +4 -0
- package/node_modules/@hostlet/adapter-kit/dist/rpc.d.ts +29 -0
- package/node_modules/@hostlet/adapter-kit/dist/rpc.js +84 -0
- package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.d.ts +5 -0
- package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.js +37 -0
- package/node_modules/@hostlet/adapter-kit/package.json +16 -0
- package/node_modules/@hostlet/platform/dist/desktop.d.ts +16 -0
- package/node_modules/@hostlet/platform/dist/desktop.js +270 -0
- package/node_modules/@hostlet/platform/dist/files.d.ts +24 -0
- package/node_modules/@hostlet/platform/dist/files.js +113 -0
- package/node_modules/@hostlet/platform/dist/index.d.ts +6 -0
- package/node_modules/@hostlet/platform/dist/index.js +4 -0
- package/node_modules/@hostlet/platform/dist/paths.d.ts +4 -0
- package/node_modules/@hostlet/platform/dist/paths.js +9 -0
- package/node_modules/@hostlet/platform/dist/process.d.ts +45 -0
- package/node_modules/@hostlet/platform/dist/process.js +297 -0
- package/node_modules/@hostlet/platform/package.json +14 -0
- package/package.json +60 -4
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
/* The console runs the PDL fragments of enabled plugins. State and requests stay with their topic. */
|
|
2
|
+
'use strict';
|
|
3
|
+
const PLUG_HOST = {
|
|
4
|
+
currentTopic: 'hlPluginTopic', topics: 'hlPluginTopics', subtopics: 'hlPluginSubtopics',
|
|
5
|
+
members: 'hlPluginMembers', composer: 'hlPluginComposer'
|
|
6
|
+
};
|
|
7
|
+
const PLUGIN_PUBLIC = {
|
|
8
|
+
acts: ['openTopic', 'openMessage', 'openTab', 'composeQuote', 'insert', 'toast', 'copy', 'openUrl', 'open', 'close', 'dialog', 'plugin', 'plugSet', 'hlGo', 'topicSet'],
|
|
9
|
+
data: Object.keys(PLUG_HOST)
|
|
10
|
+
};
|
|
11
|
+
ENGINE_PARTS.pluginPublic = PLUGIN_PUBLIC;
|
|
12
|
+
S.plug = Object.create(null);
|
|
13
|
+
|
|
14
|
+
const PLUG_INDEX = new Map(), PLUG_ROUTES = new Map(), PLUG_CACHE = new Map(), PLUG_PENDING = new Map();
|
|
15
|
+
ENGINE_PARTS.pluginRoute = function (route) { return PLUG_ROUTES.get(route); };
|
|
16
|
+
let plugIndexRead = 0, plugBootIndex, plugReads = new Set(), plugProjected = new Set(), plugEvents, plugIndexTimer = null;
|
|
17
|
+
const PLUG_EVENTS = new Map();
|
|
18
|
+
let hlDocumentPlugins = {};
|
|
19
|
+
|
|
20
|
+
function hlPluginIndexRead() {
|
|
21
|
+
return Promise.all([hlFetch('GET', '/api/plugins'), hlFetch('GET', '/api/console/pdl')]);
|
|
22
|
+
}
|
|
23
|
+
function hlPluginIndexStart() {
|
|
24
|
+
return hlPluginIndexRead().then(function (snapshot) { plugBootIndex = snapshot; }, hlFail);
|
|
25
|
+
}
|
|
26
|
+
onStart('pdl', function () {
|
|
27
|
+
const snapshot = plugBootIndex;
|
|
28
|
+
plugBootIndex = null;
|
|
29
|
+
if (snapshot) return hlPluginIndexApply(...snapshot);
|
|
30
|
+
});
|
|
31
|
+
function hlPluginIndexRefresh() {
|
|
32
|
+
const read = ++plugIndexRead;
|
|
33
|
+
return hlPluginIndexRead().then(function (snapshot) {
|
|
34
|
+
if (read === plugIndexRead) return hlPluginIndexApply(...snapshot);
|
|
35
|
+
}, hlFail);
|
|
36
|
+
}
|
|
37
|
+
function hlPluginIndexRefreshSoon() {
|
|
38
|
+
if (plugIndexTimer) return;
|
|
39
|
+
plugIndexTimer = setTimeout(function () { plugIndexTimer = null; hlPluginIndexRefresh(); }, 100);
|
|
40
|
+
}
|
|
41
|
+
function hlPluginListen(es) {
|
|
42
|
+
plugEvents = es;
|
|
43
|
+
PLUG_INDEX.forEach(function (registration) {
|
|
44
|
+
for (const [event, listener] of registration.events || []) es.addEventListener(event, listener);
|
|
45
|
+
});
|
|
46
|
+
es.addEventListener('open', hlPluginIndexRefresh); /* Catch changes made while disconnected. */
|
|
47
|
+
es.addEventListener('plugin.changed', function (event) {
|
|
48
|
+
hlPluginIndexRefresh();
|
|
49
|
+
});
|
|
50
|
+
es.addEventListener('console.pdl.changed', hlPluginIndexRefreshSoon);
|
|
51
|
+
}
|
|
52
|
+
function hlPluginRejected(pk) {
|
|
53
|
+
return (PDL_SLOT_REJECTS[pk] || []).some(function (r) { return r.reason !== 'host'; });
|
|
54
|
+
}
|
|
55
|
+
function hlPluginClosePanel(id) {
|
|
56
|
+
const wasOpen = navTabs('panel').open;
|
|
57
|
+
rtClose('panel', id);
|
|
58
|
+
navTabs('panel').open = wasOpen;
|
|
59
|
+
}
|
|
60
|
+
function hlPluginRemove(pk, replacing) {
|
|
61
|
+
const registration = PLUG_INDEX.get(pk);
|
|
62
|
+
PLUG_INDEX.delete(pk);
|
|
63
|
+
registration.dispose?.();
|
|
64
|
+
pdlUnregister(pk);
|
|
65
|
+
VIEW_ENTRIES.forEach(function (view, id) {
|
|
66
|
+
if (view.plugin !== pk) return;
|
|
67
|
+
VIEW_ENTRIES.delete(id);
|
|
68
|
+
if (view.places.includes('panel') && !replacing) hlPluginClosePanel(id);
|
|
69
|
+
});
|
|
70
|
+
registration.routes.forEach(function (route) { PLUG_ROUTES.delete(route); delete PAGES[route]; });
|
|
71
|
+
PLUG_CACHE.forEach(function (read, key) {
|
|
72
|
+
if (read.plugin === pk) {
|
|
73
|
+
read.controller?.abort();
|
|
74
|
+
PLUG_CACHE.delete(key);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function hlPluginIndexApply(plugins, index) {
|
|
79
|
+
const starting = [], replacedPanel = [];
|
|
80
|
+
hlDocumentPlugins = index;
|
|
81
|
+
const main = HL.topic && hlEffectiveMain(), route = S.route;
|
|
82
|
+
const panel = HL.topic && hlTopicViewSpec()?.panel, panelWasAvailable = panel && hlPanelViewAllowed(panel);
|
|
83
|
+
const defaults = HL.topic && hlDefaultPanelTabs(HL.topic.id, main).join('\n');
|
|
84
|
+
HLP.plugins = plugins;
|
|
85
|
+
S.plugins = Object.fromEntries(plugins.map(function (p) {
|
|
86
|
+
return [p.name, { installed: true, on: p.state === 'started' || Object.hasOwn(index, p.name) }];
|
|
87
|
+
}));
|
|
88
|
+
PLUG_INDEX.forEach(function (registration, pk) {
|
|
89
|
+
if (index[pk]?.revision === registration.revision) return;
|
|
90
|
+
const replacing = !!index[pk];
|
|
91
|
+
if (replacing) VIEW_ENTRIES.forEach(function (view, id) {
|
|
92
|
+
if (view.plugin === pk && view.places.includes('panel') && rtHas('panel', id)) replacedPanel.push(id);
|
|
93
|
+
});
|
|
94
|
+
hlPluginRemove(pk, replacing);
|
|
95
|
+
});
|
|
96
|
+
Object.entries(index).forEach(function ([pk, frag]) {
|
|
97
|
+
if (PLUG_INDEX.has(pk)) return;
|
|
98
|
+
const conflict = Object.keys(frag.views || {}).find(function (id) { return Object.hasOwn(PDL_VIEWS, id); })
|
|
99
|
+
|| Object.keys(frag.rows || {}).find(function (id) { return Object.hasOwn(PDL_ROWS, id); })
|
|
100
|
+
|| (frag.topicViews || []).find(function (v) { return VIEW_ENTRIES.has(v.id); })?.id;
|
|
101
|
+
if (conflict) { hlReport('pdl', tc('hl.plugins.conflict', pk, conflict)); return; }
|
|
102
|
+
const registration = { revision: frag.revision, routes: [] };
|
|
103
|
+
PLUG_INDEX.set(pk, registration);
|
|
104
|
+
const tools = rtCfg('panel').tools;
|
|
105
|
+
const routes = new Set(Object.values(frag.views || {}).map(function (view) { return view.route; }).filter(Boolean));
|
|
106
|
+
const entries = (frag.topicViews || []).filter(function (v) { return tools && v.places.includes('panel'); }).map(function (v) {
|
|
107
|
+
const open = routes.has(v.id) ? { page: v.id, node: v.id } : { node: v.id };
|
|
108
|
+
return { id: 'panel.' + v.id, anchor: tools, at: 'inside', node: { title: v.title, icon: v.icon, open: open } };
|
|
109
|
+
});
|
|
110
|
+
const contribution = entries.length ? Object.assign({}, frag, { inserts: (frag.inserts || []).concat(entries) }) : frag;
|
|
111
|
+
pdlRegister(contribution, pk, S.plugins[pk]);
|
|
112
|
+
if (!PDL_PLUGIN_FRAGS[pk]) return;
|
|
113
|
+
const replacement = pdlReplaceConflict(pk);
|
|
114
|
+
if (replacement) {
|
|
115
|
+
hlPluginRemove(pk);
|
|
116
|
+
hlReport('pdl', tc('hl.plugins.replaceConflict', pk, replacement.by, replacement.type));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (frag.eager) starting.push(pdlPluginNeed(pk));
|
|
120
|
+
Object.entries(frag.views || {}).forEach(function ([id, view]) {
|
|
121
|
+
if (!view.route || PAGES[view.route]) return;
|
|
122
|
+
/* An item route is also the plugin's name in an address: #<route>/<item> must name the plugin it needs. */
|
|
123
|
+
if (view.item && view.route !== pk) { hlReport('pdl', tc('hl.plugins.itemRouteName', pk, view.route)); return; }
|
|
124
|
+
PLUG_ROUTES.set(view.route, { plugin: pk, space: view.space || 'workspace', item: !!view.item, panel: view.panel || '' });
|
|
125
|
+
PAGES[view.route] = function () { return pdlView(id); };
|
|
126
|
+
registration.routes.push(view.route);
|
|
127
|
+
});
|
|
128
|
+
(frag.topicViews || []).forEach(function (view) {
|
|
129
|
+
const target = view.view || view.id;
|
|
130
|
+
if (PDL_VIEWS[target]?.plugin !== pk) return;
|
|
131
|
+
const icon = frag.icons?.[view.icon] ? 'plugin:' + pk + '/' + view.icon : view.icon;
|
|
132
|
+
registerView({
|
|
133
|
+
...view, view: target, plugin: pk, icon: icon || 'file', entry: true,
|
|
134
|
+
available: function (topicId) { return hlPluginViewAvailable(pk, view, topicId); },
|
|
135
|
+
select: function (context) { return hlPluginSelect(view.id, context); }
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
replacedPanel.forEach(function (id) {
|
|
140
|
+
const view = VIEW_ENTRIES.get(id);
|
|
141
|
+
if (!view || !view.places.includes('panel')) hlPluginClosePanel(id);
|
|
142
|
+
});
|
|
143
|
+
if (HL.topic && route === 'chat' && (main !== hlEffectiveMain() || (panel && panelWasAvailable !== hlPanelViewAllowed(panel))
|
|
144
|
+
|| defaults !== hlDefaultPanelTabs(HL.topic.id, main).join('\n'))) hlPanelApplyTopic(HL.topic.id);
|
|
145
|
+
const routeBase = route?.split('/')[0], knownRoute = route && (PAGES[route] || PDL_PAGES[routeBase]?.routeItem || PLUG_ROUTES.get(routeBase)?.item);
|
|
146
|
+
if (route && !knownRoute) go(startRoute(), { address: true });
|
|
147
|
+
render(true);
|
|
148
|
+
if (starting.length) return Promise.all(starting);
|
|
149
|
+
}
|
|
150
|
+
ENGINE_PARTS.pluginLoad = function (pk) {
|
|
151
|
+
const registration = PLUG_INDEX.get(pk);
|
|
152
|
+
return hlFetch('GET', '/api/console/pdl/' + encodeURIComponent(pk)).catch(function (error) {
|
|
153
|
+
if (PLUG_INDEX.get(pk) === registration) {
|
|
154
|
+
hlPluginRemove(pk);
|
|
155
|
+
hlFail(error);
|
|
156
|
+
if (HL.topic && S.route === 'chat') hlPanelApplyTopic(HL.topic.id);
|
|
157
|
+
render(true);
|
|
158
|
+
}
|
|
159
|
+
return {};
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
function hlPluginViewAvailable(plugin, view, topicId) {
|
|
163
|
+
if (!plugOn(plugin) || hlPluginRejected(plugin)) return false;
|
|
164
|
+
if (view.localPage && !webLocalConsole()) return false;
|
|
165
|
+
if (view.activeTopic && (!hlTopic(topicId) || hlTopic(topicId).archivedAt != null)) return false;
|
|
166
|
+
if (!view.cap && !view.pluginCap) return true;
|
|
167
|
+
const caps = HL.about?.id === topicId ? HL.about?.caps || [] : [];
|
|
168
|
+
const path = hlTopicPath(topicId).reverse();
|
|
169
|
+
const uses = function (cap, fallback) {
|
|
170
|
+
if (!cap) return true;
|
|
171
|
+
const setting = path.find(function (t) { return Object.hasOwn(t.caps || {}, cap); });
|
|
172
|
+
return setting ? setting.caps[cap] : caps.find(function (c) { return c.id === cap; })?.on ?? fallback;
|
|
173
|
+
};
|
|
174
|
+
return uses(view.pluginCap, true) && uses(view.cap, false);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function hlViewShown(id) {
|
|
178
|
+
return S.route === id || (S.route === 'chat' && !!HL.topic &&
|
|
179
|
+
(hlEffectiveMain() === id || (!!S.panel && ENGINE_PARTS.tabVisible('panel').includes(id))));
|
|
180
|
+
}
|
|
181
|
+
function hlPluginRouteSelect(route, context) {
|
|
182
|
+
const pluginRoute = PLUG_ROUTES.get(route), registration = pluginRoute && PLUG_INDEX.get(pluginRoute.plugin);
|
|
183
|
+
if (!registration) return;
|
|
184
|
+
const nav = NAV.seq, live = function () { return NAV.seq === nav && S.route === route; };
|
|
185
|
+
const selectContext = Object.assign({}, context, { live: live });
|
|
186
|
+
return pdlPluginNeed(pluginRoute.plugin)?.then(function () {
|
|
187
|
+
if (!live()) return;
|
|
188
|
+
if (PLUG_INDEX.get(pluginRoute.plugin) === registration) registration.ui?.select?.(route, selectContext);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function hlPluginSelect(id, context) {
|
|
192
|
+
const view = VIEW_ENTRIES.get(id);
|
|
193
|
+
if (!view?.plugin) return;
|
|
194
|
+
const registration = PLUG_INDEX.get(view.plugin), topic = HL.topic;
|
|
195
|
+
return pdlPluginNeed(view.plugin)?.then(function () {
|
|
196
|
+
if (PLUG_INDEX.get(view.plugin) === registration && HL.topic === topic && hlViewShown(id)) registration.ui?.select?.(id, context);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/* An enabled plug-in's companion module is trusted code, like its host entry point. It owns its bindings and their lifetime. */
|
|
200
|
+
function hlPluginBind(pk, registration, module) {
|
|
201
|
+
const controller = new AbortController(), unbind = [], key = function (name) { return 'plugin:' + pk + '/' + name; };
|
|
202
|
+
let ownDialog;
|
|
203
|
+
const request = function (method, path, body) { return hlFetch(method, path, body, controller.signal); };
|
|
204
|
+
const ns = PDL_PLUGIN_FRAGS[pk]?.ns || pk;
|
|
205
|
+
const t = function (k) {
|
|
206
|
+
const rest = Array.prototype.slice.call(arguments, 1);
|
|
207
|
+
const pack = I18N[ns];
|
|
208
|
+
const hit = pack && (i18nLeaf(pack[i18nLang()] || {}, k) ?? i18nLeaf(pack.zh || {}, k));
|
|
209
|
+
return tc.apply(null, [hit != null ? ns + '.' + k : k].concat(rest));
|
|
210
|
+
};
|
|
211
|
+
const ui = module.default({
|
|
212
|
+
key: key, revision: registration.revision, signal: controller.signal, request: request, shown: hlViewShown, io: hlIoOn,
|
|
213
|
+
t: t, tText: tcText, lang: function () { return S.lang; },
|
|
214
|
+
pickFileSources: function (options) { return hlPickFileSources(options, controller.signal); },
|
|
215
|
+
refreshDraftPreview: hlPaintActiveDraft,
|
|
216
|
+
addDraftAttachment(input, attachment) {
|
|
217
|
+
const topic = hlComposerDraft();
|
|
218
|
+
if (topic && hlIsComposer(input)) hlAddDraftAttachment(topic, input, attachment);
|
|
219
|
+
},
|
|
220
|
+
registerSpans(provider) {
|
|
221
|
+
if (ENGINE_PARTS.spans) throw new Error('A span provider is already registered');
|
|
222
|
+
ENGINE_PARTS.spans = provider;
|
|
223
|
+
const release = function () { if (ENGINE_PARTS.spans === provider) delete ENGINE_PARTS.spans; };
|
|
224
|
+
unbind.push(release);
|
|
225
|
+
return release;
|
|
226
|
+
},
|
|
227
|
+
registerMeasurements(observers) {
|
|
228
|
+
if (ENGINE_PARTS.measurements) throw new Error('A measurement provider is already registered');
|
|
229
|
+
ENGINE_PARTS.measurements = observers;
|
|
230
|
+
const release = function () { if (ENGINE_PARTS.measurements === observers) delete ENGINE_PARTS.measurements; };
|
|
231
|
+
unbind.push(release);
|
|
232
|
+
return release;
|
|
233
|
+
},
|
|
234
|
+
registerMemberCredentials(read) {
|
|
235
|
+
if (ENGINE_PARTS.memberCredentials) throw new Error('A member credentials provider is already registered');
|
|
236
|
+
ENGINE_PARTS.memberCredentials = read;
|
|
237
|
+
unbind.push(() => { delete ENGINE_PARTS.memberCredentials; });
|
|
238
|
+
},
|
|
239
|
+
fail: function (error) { if (!controller.signal.aborted) hlFail(error); },
|
|
240
|
+
dialog: function (spec) {
|
|
241
|
+
if (controller.signal.aborted) return;
|
|
242
|
+
const lifetime = new AbortController(), openedSpec = Object.defineProperties({}, Object.getOwnPropertyDescriptors(spec));
|
|
243
|
+
openedSpec.signal = AbortSignal.any([controller.signal, lifetime.signal]);
|
|
244
|
+
dialog(openedSpec);
|
|
245
|
+
const opened = ownDialog = S.dialog;
|
|
246
|
+
return function dismiss() {
|
|
247
|
+
lifetime.abort();
|
|
248
|
+
if (S.dialog === opened) { S.dialog = null; render(true); }
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
registration.ui = ui;
|
|
253
|
+
[[VM, ui.models], [WHEN, ui.conditions], [A, ui.actions], [INPUTS, ui.inputs], [CHANGES, ui.changes]].forEach(function ([target, bindings]) {
|
|
254
|
+
Object.entries(bindings || {}).forEach(function ([id, fn]) {
|
|
255
|
+
const name = key(id);
|
|
256
|
+
target[name] = fn;
|
|
257
|
+
unbind.push(function () { delete target[name]; });
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
registration.events = Object.entries(ui.events || {}).map(function ([event, fn]) {
|
|
261
|
+
const listener = function (e) { fn(JSON.parse(e.data)); };
|
|
262
|
+
plugEvents?.addEventListener(event, listener);
|
|
263
|
+
return [event, listener];
|
|
264
|
+
});
|
|
265
|
+
registration.dispose = function () {
|
|
266
|
+
controller.abort();
|
|
267
|
+
for (const [event, listener] of registration.events) plugEvents?.removeEventListener(event, listener);
|
|
268
|
+
ui.dispose?.();
|
|
269
|
+
unbind.forEach(function (release) { release(); });
|
|
270
|
+
if (ownDialog && S.dialog === ownDialog) S.dialog = null;
|
|
271
|
+
};
|
|
272
|
+
return ui;
|
|
273
|
+
}
|
|
274
|
+
async function hlMountPlugin(pk, source) {
|
|
275
|
+
const registration = PLUG_INDEX.get(pk);
|
|
276
|
+
const url = URL.createObjectURL(new Blob([source], { type: 'text/javascript' }));
|
|
277
|
+
const module = await import(url).finally(function () { URL.revokeObjectURL(url); });
|
|
278
|
+
if (PLUG_INDEX.get(pk) === registration) hlPluginBind(pk, registration, module);
|
|
279
|
+
}
|
|
280
|
+
ENGINE_PARTS.pluginMount = hlMountPlugin;
|
|
281
|
+
onRender(function () { PLUG_INDEX.forEach(function (registration) { registration.ui?.update?.(); }); });
|
|
282
|
+
|
|
283
|
+
function hlPluginDraftPreview(input) {
|
|
284
|
+
for (const registration of PLUG_INDEX.values()) {
|
|
285
|
+
const text = registration.ui?.draftPreview?.(input);
|
|
286
|
+
if (typeof text === 'string' && text) return text;
|
|
287
|
+
}
|
|
288
|
+
return '';
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function plugTopicId() { return S.route === 'chat' ? HL.topic?.id || '' : ''; }
|
|
292
|
+
function plugState(pk, topicId) { return S.plug[pk]?.[topicId] || {}; }
|
|
293
|
+
function plugField(object, field) {
|
|
294
|
+
return field.split('.').reduce(function (value, key) { return value != null && Object.hasOwn(Object(value), key) ? value[key] : undefined; }, object);
|
|
295
|
+
}
|
|
296
|
+
function plugHost(source, input) {
|
|
297
|
+
const [name, ...path] = source.split('.');
|
|
298
|
+
const root = Object.hasOwn(PLUG_HOST, name) && vmRead(PLUG_HOST[name]);
|
|
299
|
+
return path.reduce(function (value, key) {
|
|
300
|
+
const field = key[0] === '@' ? plugField(input, key.slice(1)) : key;
|
|
301
|
+
return value != null && field != null && Object.hasOwn(Object(value), field) ? value[field] : undefined;
|
|
302
|
+
}, root);
|
|
303
|
+
}
|
|
304
|
+
function plugValue(v, state, input) {
|
|
305
|
+
if (typeof v !== 'string') return v;
|
|
306
|
+
if (v === 'host.origin') return location.origin;
|
|
307
|
+
if (v.startsWith('host:')) return plugHost(v.slice(5), input);
|
|
308
|
+
if (v.startsWith('state.')) return plugField(state, v.slice(6));
|
|
309
|
+
if (v[0] === '@') return plugField(input, v.slice(1));
|
|
310
|
+
return v;
|
|
311
|
+
}
|
|
312
|
+
function plugParams(bindings, state, input) {
|
|
313
|
+
return Object.fromEntries(Object.entries(bindings || {}).map(function ([key, v]) {
|
|
314
|
+
return [key, plugValue(v, state, input)];
|
|
315
|
+
}).filter(function ([, v]) { return v != null; }));
|
|
316
|
+
}
|
|
317
|
+
function plugCall(pk, request, query, body, signal) {
|
|
318
|
+
if (!/^[\w.-]+(?:\/[\w.-]+)*$/.test(request.path) || request.path.split('/').some(function (part) { return part === '.' || part === '..'; })
|
|
319
|
+
|| ['switch', 'reload'].includes(request.path)) {
|
|
320
|
+
return Promise.reject(new Error(tc('hl.plugins.relativePath')));
|
|
321
|
+
}
|
|
322
|
+
const params = new URLSearchParams(query).toString();
|
|
323
|
+
const path = '/api/plugins/' + encodeURIComponent(pk) + '/' + request.path + (params ? '?' + params : '');
|
|
324
|
+
return hlFetch(request.method || 'GET', path, body, signal);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/* Keep old data on screen while changing parameters. Unchanged rows keep their references. */
|
|
328
|
+
function plugMerge(was, value) {
|
|
329
|
+
if (was === value || !was || !value || typeof was !== 'object' || typeof value !== 'object') return value;
|
|
330
|
+
if (Array.isArray(was) !== Array.isArray(value)) return value;
|
|
331
|
+
const prior = Array.isArray(was) ? new Map(was.filter(function (row) { return row?.id != null; }).map(function (row) { return [row.id, row]; })) : null;
|
|
332
|
+
const next = prior ? value.map(function (row, i) { return plugMerge(row?.id == null ? was[i] : prior.get(row.id), row); })
|
|
333
|
+
: Object.fromEntries(Object.entries(value).map(function ([k, v]) { return [k, plugMerge(was[k], v)]; }));
|
|
334
|
+
const keys = Object.keys(next);
|
|
335
|
+
return keys.length === Object.keys(was).length && keys.every(function (k) { return Object.hasOwn(was, k) && was[k] === next[k]; }) ? was : next;
|
|
336
|
+
}
|
|
337
|
+
/* Auto-wrap plugin source arrays with unique row.id into pdlKeyed + pdlKeyedList (zero code for plugin authors). */
|
|
338
|
+
function plugKeyedArray(read, path, arr) {
|
|
339
|
+
if (!Array.isArray(arr) || !arr.length) return arr;
|
|
340
|
+
const ids = [], seen = new Set();
|
|
341
|
+
for (let i = 0; i < arr.length; i++) {
|
|
342
|
+
const row = arr[i];
|
|
343
|
+
if (!row || typeof row !== 'object' || row.id == null || row.id === '') return arr;
|
|
344
|
+
const id = String(row.id);
|
|
345
|
+
if (seen.has(id)) return arr;
|
|
346
|
+
seen.add(id);
|
|
347
|
+
ids.push(id);
|
|
348
|
+
}
|
|
349
|
+
const stores = read.stores || (read.stores = new Map());
|
|
350
|
+
let store = stores.get(path);
|
|
351
|
+
if (!store) {
|
|
352
|
+
store = pdlKeyed('plug:' + (read.key || read.plugin) + ':' + path);
|
|
353
|
+
stores.set(path, store);
|
|
354
|
+
}
|
|
355
|
+
for (let i = 0; i < arr.length; i++) store.set(ids[i], arr[i]);
|
|
356
|
+
store.keys().forEach(function (k) { if (!seen.has(k)) store.delete(k); });
|
|
357
|
+
return pdlKeyedList(ids, function (id) { return store.get(id); });
|
|
358
|
+
}
|
|
359
|
+
function plugWrapValue(read, value) {
|
|
360
|
+
if (Array.isArray(value)) return plugKeyedArray(read, '$', value);
|
|
361
|
+
if (value && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype) {
|
|
362
|
+
let wrapped = null;
|
|
363
|
+
for (const [k, v] of Object.entries(value)) {
|
|
364
|
+
if (Array.isArray(v)) {
|
|
365
|
+
const w = plugKeyedArray(read, k, v);
|
|
366
|
+
if (w !== v) {
|
|
367
|
+
if (!wrapped) wrapped = Object.assign({}, value);
|
|
368
|
+
wrapped[k] = w;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return wrapped || value;
|
|
373
|
+
}
|
|
374
|
+
return value;
|
|
375
|
+
}
|
|
376
|
+
function plugRead(read) {
|
|
377
|
+
read.controller?.abort();
|
|
378
|
+
const controller = read.controller = new AbortController();
|
|
379
|
+
read.sent = JSON.stringify(read.query);
|
|
380
|
+
read.dirty = false;
|
|
381
|
+
read.error = false;
|
|
382
|
+
return plugCall(read.plugin, read.request, read.query, undefined, controller.signal).then(function (value) {
|
|
383
|
+
if (!controller.signal.aborted) {
|
|
384
|
+
read.value = plugMerge(read.value, value);
|
|
385
|
+
read.wrapped = plugWrapValue(read, read.value);
|
|
386
|
+
}
|
|
387
|
+
}, function () {
|
|
388
|
+
if (!controller.signal.aborted) read.error = true;
|
|
389
|
+
}).then(function () { if (!controller.signal.aborted) render(true); });
|
|
390
|
+
}
|
|
391
|
+
function plugInvalidate(event, data) {
|
|
392
|
+
const topicId = data.topicId || data.topic?.id || data.turn?.topicId || data.message?.topicId;
|
|
393
|
+
let changed = false;
|
|
394
|
+
plugProjected.forEach(function (key) {
|
|
395
|
+
const read = PLUG_CACHE.get(key);
|
|
396
|
+
if (read?.events.includes(event) && (!topicId || !read.topicId || read.topicId === topicId)) {
|
|
397
|
+
read.dirty = true;
|
|
398
|
+
changed = true;
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
if (changed) hlDrawSoon();
|
|
402
|
+
}
|
|
403
|
+
beforeRender(function () { plugReads = pdlReadSet(); });
|
|
404
|
+
onRender(function () {
|
|
405
|
+
const current = new Set(), events = new Set();
|
|
406
|
+
plugReads.forEach(function (key) {
|
|
407
|
+
const read = PLUG_CACHE.get(key);
|
|
408
|
+
if (!read) return;
|
|
409
|
+
current.add(key);
|
|
410
|
+
read.events.forEach(function (event) { events.add(event); });
|
|
411
|
+
if (!plugProjected.has(key) || read.dirty || read.sent !== JSON.stringify(read.query)) plugRead(read);
|
|
412
|
+
});
|
|
413
|
+
plugProjected = current;
|
|
414
|
+
if (!plugEvents) return;
|
|
415
|
+
PLUG_EVENTS.forEach(function (listener, event) {
|
|
416
|
+
if (events.has(event)) return;
|
|
417
|
+
plugEvents.removeEventListener(event, listener);
|
|
418
|
+
PLUG_EVENTS.delete(event);
|
|
419
|
+
});
|
|
420
|
+
events.forEach(function (event) {
|
|
421
|
+
if (PLUG_EVENTS.has(event)) return;
|
|
422
|
+
const listener = function (e) { plugInvalidate(event, JSON.parse(e.data)); };
|
|
423
|
+
plugEvents.addEventListener(event, listener);
|
|
424
|
+
PLUG_EVENTS.set(event, listener);
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
VM.hlPluginTopic = function () { return hlTopic(plugTopicId()) || null; };
|
|
429
|
+
VM.hlPluginTopics = hlTopicCatalog;
|
|
430
|
+
VM.hlPluginMembers = function () { return hlIdentities().map(function (m) { return { ...hlWho(m), canReceive: m.canReceive === true }; }); };
|
|
431
|
+
VM.hlPluginComposer = function () { return { text: HL.topic?.text || HU.newText }; };
|
|
432
|
+
VM.hlPluginSubtopics = function () {
|
|
433
|
+
const id = plugTopicId(), children = HL.about?.id === id ? HL.about.about?.children || [] : [];
|
|
434
|
+
return Object.fromEntries(children.map(function (child) {
|
|
435
|
+
const t = hlTopicRef(child.id), path = hlNavPath(child.id), own = HL_NAV.state.own(path);
|
|
436
|
+
return [child.id, { id: child.id, title: child.title, alive: true, busy: !!own.running?.length,
|
|
437
|
+
asks: own.cards || 0, mentions: own.mentions || 0, lastActiveAt: t?.lastActiveAt }];
|
|
438
|
+
}));
|
|
439
|
+
};
|
|
440
|
+
VM.plugin = function (pk, sources, input) {
|
|
441
|
+
const topicId = plugTopicId(), state = plugState(pk, topicId);
|
|
442
|
+
const spec = hlTopicViewSpec(topicId);
|
|
443
|
+
if (topicId && spec?.args && VIEW_ENTRIES.get(spec.main)?.plugin === pk) input = Object.assign({}, spec.args, input);
|
|
444
|
+
const out = { input: input, state: state, load: '', pending: PLUG_PENDING.has(JSON.stringify([pk, topicId])) };
|
|
445
|
+
Object.entries(sources).forEach(function ([source, name]) {
|
|
446
|
+
if (name.startsWith('host:')) { out[source] = plugHost(name.slice(5), input); return; }
|
|
447
|
+
const request = PDL_PLUGIN_REQ[pk]?.[name];
|
|
448
|
+
if (!request || (request.method && request.method !== 'GET')) { out.load = 'error'; return; }
|
|
449
|
+
const args = Object.values(request.query || {}).filter(function (v) { return typeof v === 'string' && v[0] === '@'; });
|
|
450
|
+
const key = JSON.stringify([pk, topicId, name, args.map(function (v) { return plugValue(v, state, input); })]);
|
|
451
|
+
if (!PLUG_CACHE.has(key)) PLUG_CACHE.set(key, { key: key, plugin: pk, topicId: topicId, request: request, events: request.invalidateOn ?? ['topic.updated'] });
|
|
452
|
+
const read = PLUG_CACHE.get(key);
|
|
453
|
+
read.query = plugParams(request.query, state, input);
|
|
454
|
+
plugReads.add(key);
|
|
455
|
+
out[source] = read.wrapped !== undefined ? read.wrapped : read.value;
|
|
456
|
+
if (read.error) out.load = 'error';
|
|
457
|
+
else if (read.value === undefined && !out.load) out.load = 'loading';
|
|
458
|
+
});
|
|
459
|
+
return out;
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
async function plugWrite(pk, name, input) {
|
|
463
|
+
const topicId = plugTopicId(), route = S.route, state = plugState(pk, topicId);
|
|
464
|
+
const request = PDL_PLUGIN_REQ[pk]?.[name], registration = PLUG_INDEX.get(pk);
|
|
465
|
+
if (!request || !plugOn(pk)) return;
|
|
466
|
+
const key = JSON.stringify([pk, topicId]);
|
|
467
|
+
if (PLUG_PENDING.has(key)) return;
|
|
468
|
+
PLUG_PENDING.set(key, true);
|
|
469
|
+
render(true);
|
|
470
|
+
try {
|
|
471
|
+
const method = request.method || 'GET', hasBody = method !== 'GET' && method !== 'DELETE';
|
|
472
|
+
const result = await plugCall(pk, request, plugParams(request.query, state, input), hasBody ? (request.body ? plugParams(request.body, state, input) : input) : undefined);
|
|
473
|
+
if (PLUG_INDEX.get(pk) !== registration) return;
|
|
474
|
+
if (method !== 'GET') PLUG_CACHE.forEach(function (read) { if (read.plugin === pk && read.topicId === topicId) read.dirty = true; });
|
|
475
|
+
if (result.error) throw new Error(result.error);
|
|
476
|
+
if (result.message) toast(result.message);
|
|
477
|
+
for (const action of result.acts || [result]) {
|
|
478
|
+
if (topicId !== plugTopicId() || route !== S.route) break;
|
|
479
|
+
if (PLUGIN_PUBLIC.acts.includes(action.act)) await actFn(action.act)(action.args || {});
|
|
480
|
+
}
|
|
481
|
+
} finally {
|
|
482
|
+
PLUG_PENDING.delete(key);
|
|
483
|
+
render(true);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
A.plugin = function ({ plugin, request, ...input }) { return plugWrite(plugin, request, input).catch(hlFail); };
|
|
487
|
+
A.plugSet = function (d) {
|
|
488
|
+
if (!plugOn(d.plugin) || typeof d.k !== 'string') return;
|
|
489
|
+
const plugin = S.plug[d.plugin] ||= Object.create(null), topicId = plugTopicId();
|
|
490
|
+
const state = plugin[topicId] ||= Object.create(null);
|
|
491
|
+
state[d.k] = d.v;
|
|
492
|
+
render(true);
|
|
493
|
+
};
|
|
494
|
+
CHANGES.plugSet = INPUTS.plugSet = function (e) { A.plugSet(Object.assign(actionArgs(e.target), { v: e.target.value })); };
|
|
495
|
+
CHANGES.plugin = function (e) { return A.plugin(Object.assign(actionArgs(e.target), { v: e.target.value })); };
|
|
496
|
+
|
|
497
|
+
A.openTopic = function (d) {
|
|
498
|
+
if (typeof d.id !== 'string' || !/^[\w-]+$/.test(d.id)) return;
|
|
499
|
+
const address = 'chat-' + d.id + (d.mid ? '/' + d.mid : '');
|
|
500
|
+
return hlOpen(address);
|
|
501
|
+
};
|
|
502
|
+
A.openMessage = A.openTopic;
|
|
503
|
+
A.openTab = function (d) {
|
|
504
|
+
if (HL.topic && hlPanelViewAllowed(d.id) && d.id !== hlEffectiveMain()) ENGINE_PARTS.openTab('panel', d.id);
|
|
505
|
+
};
|
|
506
|
+
A.openUrl = function (d) {
|
|
507
|
+
const url = URL.parse(d.url);
|
|
508
|
+
if (url && /^https?:$/.test(url.protocol)) return webOpenExternal(url).catch(hlFail);
|
|
509
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/* The preview frame owns its DOM. The console supplies its verified resource and the usual document tools. */
|
|
2
|
+
'use strict';
|
|
3
|
+
const HL_PREVIEW_PAGES = new Map(), HL_PREVIEW_CHANNEL = 'hostlet-frame/v1';
|
|
4
|
+
let hlPreviewSelection, hlPendingPreview;
|
|
5
|
+
|
|
6
|
+
function hlPreviewMount(value) {
|
|
7
|
+
const url = URL.parse(value, location.origin);
|
|
8
|
+
const route = url?.origin === location.origin && /^\/p\/([^/]+)\/[^/]+\//.exec(url.pathname);
|
|
9
|
+
return route ? { url, topicId: route[1] } : null;
|
|
10
|
+
}
|
|
11
|
+
function hlPreviewFrame(key) {
|
|
12
|
+
return document.querySelector('iframe[data-frame-key="' + CSS.escape(key) + '"]');
|
|
13
|
+
}
|
|
14
|
+
function hlPreviewSlot(key) {
|
|
15
|
+
return document.querySelector('[data-document-frame="' + CSS.escape(key) + '"]');
|
|
16
|
+
}
|
|
17
|
+
function hlPreviewCurrentPage(page) {
|
|
18
|
+
const { frame } = page;
|
|
19
|
+
return HL_PREVIEW_PAGES.get(frame) === page && frame.src === page.src && hlFrameVisible(frame) && S.route === 'chat';
|
|
20
|
+
}
|
|
21
|
+
function hlPreviewRect(frame, rect) {
|
|
22
|
+
if (!rect || ![rect.left, rect.top, rect.right, rect.bottom].every(Number.isFinite)) return null;
|
|
23
|
+
const box = frame.getBoundingClientRect();
|
|
24
|
+
const left = Math.max(0, rect.left), top = Math.max(0, rect.top);
|
|
25
|
+
const right = Math.min(frame.clientWidth, rect.right), bottom = Math.min(frame.clientHeight, rect.bottom);
|
|
26
|
+
if (right <= left || bottom <= top) return null;
|
|
27
|
+
return new DOMRect(box.left + frame.clientLeft + left, box.top + frame.clientTop + top, right - left, bottom - top);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function hlPreviewPost(page, type, fields) { page.port.postMessage({ channel: HL_PREVIEW_CHANNEL, type, ...fields }); }
|
|
31
|
+
function hlPreviewReadSelection() {
|
|
32
|
+
const page = hlPreviewSelection;
|
|
33
|
+
if (!HL.topic || !page?.selection || !hlPreviewCurrentPage(page) || !page.source || hlTopic(HL.topic.id)?.archivedAt != null) return null;
|
|
34
|
+
const { text, prefix, suffix, rect: box } = page.selection, rect = hlPreviewRect(page.frame, box);
|
|
35
|
+
if (!rect) return null;
|
|
36
|
+
const { topicId, resource, title } = page.source;
|
|
37
|
+
return { block: page.frame.parentElement, rect, external: true, canAnnotate: hlTopic(topicId)?.archivedAt == null, ref: {
|
|
38
|
+
topicId: HL.topic.id, sourceTopicId: topicId, kind: 'selection', label: title, excerpt: text,
|
|
39
|
+
source: { resource, locator: { view: 'preview', text, prefix, suffix } }
|
|
40
|
+
} };
|
|
41
|
+
}
|
|
42
|
+
function hlPreviewClearSelection() {
|
|
43
|
+
if (!hlPreviewSelection) return;
|
|
44
|
+
hlPreviewPost(hlPreviewSelection, 'preview.clearSelection');
|
|
45
|
+
hlPreviewSelection.selection = null;
|
|
46
|
+
hlPreviewSelection = undefined;
|
|
47
|
+
hlSelectionSchedule();
|
|
48
|
+
}
|
|
49
|
+
function hlPreviewReadPayload(page, selection) {
|
|
50
|
+
if (!selection || typeof selection.text !== 'string' || !hlPreviewRect(page.frame, selection.rect)) return null;
|
|
51
|
+
const text = selection.text.trim().slice(0, 600);
|
|
52
|
+
if (!text) return null;
|
|
53
|
+
return { text, prefix: typeof selection.prefix === 'string' ? selection.prefix.slice(-48) : undefined,
|
|
54
|
+
suffix: typeof selection.suffix === 'string' ? selection.suffix.slice(0, 48) : undefined, rect: selection.rect };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function hlPreviewDetach(frame) {
|
|
58
|
+
const page = HL_PREVIEW_PAGES.get(frame);
|
|
59
|
+
if (!page) return;
|
|
60
|
+
if (hlPreviewSelection === page) { hlPreviewSelection = undefined; hlSelectionSchedule(); }
|
|
61
|
+
page.locating?.finish(false);
|
|
62
|
+
page.port.close();
|
|
63
|
+
HL_PREVIEW_PAGES.delete(frame);
|
|
64
|
+
}
|
|
65
|
+
function hlPreviewConnect(frame) {
|
|
66
|
+
hlPreviewDetach(frame);
|
|
67
|
+
if (!hlPreviewMount(frame.src)) { hlDocumentSync(); return; }
|
|
68
|
+
const { port1, port2 } = new MessageChannel();
|
|
69
|
+
const page = { frame, src: frame.src, port: port1, anchors: new EventTarget(), serial: 0 };
|
|
70
|
+
HL_PREVIEW_PAGES.set(frame, page);
|
|
71
|
+
port1.onmessage = ({ data }) => hlPreviewReceive(page, data);
|
|
72
|
+
frame.contentWindow.postMessage({ channel: HL_PREVIEW_CHANNEL, type: 'preview.connect' }, '*', [port2]);
|
|
73
|
+
hlDocumentSync();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function hlPreviewReceive(page, data) {
|
|
77
|
+
if (data?.channel !== HL_PREVIEW_CHANNEL || HL_PREVIEW_PAGES.get(page.frame) !== page) return;
|
|
78
|
+
if (data.type === 'preview.ready' && !page.source && typeof data.ticket === 'string' && data.ticket.length <= 8192 && typeof data.href === 'string') {
|
|
79
|
+
const mounted = hlPreviewMount(data.href);
|
|
80
|
+
if (!mounted) return;
|
|
81
|
+
try {
|
|
82
|
+
const source = await hlFetch('GET', '/api/topics/' + encodeURIComponent(mounted.topicId) + '/preview-source?ticket=' + encodeURIComponent(data.ticket));
|
|
83
|
+
if (HL_PREVIEW_PAGES.get(page.frame) !== page || page.source || source.path !== mounted.url.pathname) return;
|
|
84
|
+
page.source = { ...source, url: mounted.url.href };
|
|
85
|
+
hlDocumentSync();
|
|
86
|
+
if (hlPendingPreview?.key === page.frame.dataset.frameKey) {
|
|
87
|
+
const pending = hlPendingPreview;
|
|
88
|
+
hlCancelPreviewLocation();
|
|
89
|
+
pending.finish(pending.resource === source.resource && await hlPreviewGoto(page, pending.locator));
|
|
90
|
+
}
|
|
91
|
+
} catch (error) { console.debug('Preview source was not accepted:', error.message); }
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!page.source || !hlPreviewCurrentPage(page)) return;
|
|
95
|
+
if (data.type === 'preview.selection') {
|
|
96
|
+
page.selection = hlPreviewReadPayload(page, data.selection);
|
|
97
|
+
if (page.selection) hlPreviewSelection = page;
|
|
98
|
+
else if (hlPreviewSelection === page) hlPreviewSelection = undefined;
|
|
99
|
+
hlSelectionSchedule();
|
|
100
|
+
} else if (data.type === 'preview.anchorClick' && Array.isArray(data.ids)) {
|
|
101
|
+
page.anchorRect = data.rect;
|
|
102
|
+
page.anchors.dispatchEvent(new CustomEvent('activate', { detail: data.ids }));
|
|
103
|
+
} else if (data.type === 'preview.anchorPosition') {
|
|
104
|
+
page.anchorRect = data.rect;
|
|
105
|
+
page.anchors.dispatchEvent(new Event('move'));
|
|
106
|
+
} else if (data.type === 'preview.located' && page.locating?.id === data.id) {
|
|
107
|
+
page.locating.finish(data.found === true);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function hlPreviewFor(topicId, resource) {
|
|
112
|
+
return Array.from(HL_PREVIEW_PAGES.values()).find((page) => page.source?.topicId === topicId &&
|
|
113
|
+
page.source.resource === resource && hlPreviewCurrentPage(page));
|
|
114
|
+
}
|
|
115
|
+
function hlPreviewGoto(page, locator) {
|
|
116
|
+
if (!hlPreviewCurrentPage(page)) return false;
|
|
117
|
+
page.locating?.finish(false);
|
|
118
|
+
const id = ++page.serial;
|
|
119
|
+
return new Promise((resolve) => {
|
|
120
|
+
const timer = setTimeout(() => finish(false), 1800);
|
|
121
|
+
const finish = (found) => { clearTimeout(timer); page.locating = undefined; resolve(found); };
|
|
122
|
+
page.locating = { id, finish };
|
|
123
|
+
hlPreviewPost(page, 'preview.goto', { id, locator });
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function hlCancelPreviewLocation() {
|
|
127
|
+
if (!hlPendingPreview) return;
|
|
128
|
+
clearTimeout(hlPendingPreview.timer);
|
|
129
|
+
hlPendingPreview = undefined;
|
|
130
|
+
}
|
|
131
|
+
function hlOpenPreviewLocation(topicId, source, url, done, unavailable) {
|
|
132
|
+
const finish = (found) => {
|
|
133
|
+
if (HL.topic?.id !== topicId || S.route !== 'chat') return;
|
|
134
|
+
if (found) done?.();
|
|
135
|
+
else unavailable(tc('hl.selection.noSelection'));
|
|
136
|
+
};
|
|
137
|
+
const current = hlPreviewFor(topicId, source.resource);
|
|
138
|
+
if (current) return Promise.resolve(hlPreviewGoto(current, source.locator)).then(finish);
|
|
139
|
+
const key = hlPreviewShow(url);
|
|
140
|
+
if (!key) return finish(false);
|
|
141
|
+
const timer = setTimeout(() => { hlCancelPreviewLocation(); finish(false); }, 5000);
|
|
142
|
+
hlPendingPreview = { key, timer, finish, resource: source.resource, locator: source.locator };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function hlPreviewAdapter(page) {
|
|
146
|
+
const { topicId, resource } = page.source;
|
|
147
|
+
return {
|
|
148
|
+
anchors: {
|
|
149
|
+
set(items) {
|
|
150
|
+
const anchors = items.filter(({ locator }) => locator.view === 'preview');
|
|
151
|
+
const key = JSON.stringify(anchors);
|
|
152
|
+
if (key === page.paintKey) return;
|
|
153
|
+
page.paintKey = key;
|
|
154
|
+
hlPreviewPost(page, 'preview.anchors', { anchors });
|
|
155
|
+
},
|
|
156
|
+
rect: () => hlPreviewCurrentPage(page) && hlPreviewRect(page.frame, page.anchorRect),
|
|
157
|
+
listen: (event, handler, signal) => page.anchors.addEventListener(event, (e) => handler(e.detail), { signal }),
|
|
158
|
+
},
|
|
159
|
+
go(locator) {
|
|
160
|
+
if (locator.view === 'preview') return hlPreviewGoto(page, locator);
|
|
161
|
+
hlOpenSelectionSource(topicId, { resource, locator });
|
|
162
|
+
return true;
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
document.addEventListener('load', ({ target }) => {
|
|
168
|
+
if (target.matches?.('iframe[data-frame-key]') && hlPreviewSlot(target.dataset.frameKey)) hlPreviewConnect(target);
|
|
169
|
+
}, true);
|
|
170
|
+
onRender(() => {
|
|
171
|
+
for (const frame of HL_PREVIEW_PAGES.keys()) if (!frame.isConnected) hlPreviewDetach(frame);
|
|
172
|
+
});
|