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,398 @@
|
|
|
1
|
+
export default function (ui) {
|
|
2
|
+
const models = {}, actions = {}, inputs = {}, changes = {};
|
|
3
|
+
const tr = ui.t;
|
|
4
|
+
/* 日程: manage calendar events, timed tasks and see the selected day's finished runs. */
|
|
5
|
+
const HLS = { mode: store.get('schedMode', 'month'), anchor: Date.now(), day: '', days: {}, marks: [], highlights: [], shown: null, tasks: [], seen: '' };
|
|
6
|
+
function hlSchedYmd(d) { return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); }
|
|
7
|
+
function hlSchedDate(ymd) { const p = ymd.split('-'); return new Date(+p[0], +p[1] - 1, +p[2], 12); }
|
|
8
|
+
/* The days the calendar shows: the week, or the six weeks around the month, from a Monday on. */
|
|
9
|
+
function hlSchedSpan() {
|
|
10
|
+
const a = new Date(HLS.anchor), first = new Date(a.getFullYear(), a.getMonth(), HLS.mode === 'week' ? a.getDate() : 1, 12);
|
|
11
|
+
first.setDate(first.getDate() - (first.getDay() + 6) % 7);
|
|
12
|
+
return [first, new Date(first.getFullYear(), first.getMonth(), first.getDate() + (HLS.mode === 'week' ? 6 : 41), 12)];
|
|
13
|
+
}
|
|
14
|
+
/* Read what the page shows: the tasks, how much there is on each day in view, and the chosen day. A slower, older answer is dropped. */
|
|
15
|
+
let HLS_N = 0;
|
|
16
|
+
function hlSchedRead() {
|
|
17
|
+
const n = ++HLS_N, span = hlSchedSpan(), day = HLS.day || (HLS.day = hlSchedYmd(new Date()));
|
|
18
|
+
const only = hlSchedQuery();
|
|
19
|
+
return Promise.all([ui.request('GET', '/api/schedule/tasks?' + only.slice(1)), ui.request('GET', '/api/schedule/days?from=' + hlSchedYmd(span[0]) + '&to=' + hlSchedYmd(span[1]) + only), ui.request('GET', '/api/schedule/day?date=' + day + only)]).then(function (r) {
|
|
20
|
+
if (n !== HLS_N) return;
|
|
21
|
+
HLS.tasks = r[0]; HLS.days = {}; HLS.marks = []; HLS.highlights = []; HLS.shown = r[2];
|
|
22
|
+
r[1].forEach(function (d) {
|
|
23
|
+
HLS.days[d.date] = d;
|
|
24
|
+
const at = hlSchedDate(d.date).getTime();
|
|
25
|
+
for (let i = d.tasks; i > 0; i--) HLS.marks.push({ at: at });
|
|
26
|
+
if (d.events > 0) HLS.highlights.push({ at: at, count: d.events, span: d.span || 'single' });
|
|
27
|
+
});
|
|
28
|
+
render(true);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/* Something changed that this page may show (a task, a run, what became of one): read again, once for all that arrives together. */
|
|
32
|
+
let HLS_SOON = null;
|
|
33
|
+
/* The schedule is shown in two places: as a page of its own, and as a tab of the workbench beside a topic. */
|
|
34
|
+
function hlSchedChanged() {
|
|
35
|
+
if (ui.shown('schedule') && !HLS_SOON) HLS_SOON = setTimeout(function () { HLS_SOON = null; if (ui.shown('schedule')) hlSchedRead().catch(ui.fail); }, 200);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const wd = (n) => tr('wd' + n);
|
|
39
|
+
const taskTitle = (task) => task.about || task.op;
|
|
40
|
+
const taskTopic = (task) => task.topicId ? hlTopicRef(task.topicId)?.title || tr('deletedTopic') : '';
|
|
41
|
+
const goes = (item) => {
|
|
42
|
+
const go = item.open || item.ref || (item.topicId && hlTopicRef(item.topicId) ? 'chat-' + item.topicId : '');
|
|
43
|
+
return { go, canGo: !!go, goLabel: go && tr('goAddress', go) };
|
|
44
|
+
};
|
|
45
|
+
actions.hlSchedOpen = function ({ address }) {
|
|
46
|
+
return /^https?:/i.test(address) ? A.openUrl({ url: address }) : A.hlGo({ a: address });
|
|
47
|
+
};
|
|
48
|
+
/* Narrowing what is shown: by words and by the topic scope chosen in the label search. The host does the
|
|
49
|
+
narrowing, for the lists and the calendar's numbers alike. */
|
|
50
|
+
function hlSchedScope() {
|
|
51
|
+
const ls = labelSearchValue('schedule', { defaultScope: false });
|
|
52
|
+
return ((ls.conds || []).find(function (c) { return c.type === 'scope'; }) || {}).id || 'all';
|
|
53
|
+
}
|
|
54
|
+
function hlSchedQuery() {
|
|
55
|
+
const ls = labelSearchValue('schedule', { defaultScope: false }), q = (ls.q || '').trim(), scope = hlSchedScope();
|
|
56
|
+
const topic = scope !== 'all' && S.route === 'chat' && HL.topic ? HL.topic.id : '';
|
|
57
|
+
return (topic ? '&topic=' + encodeURIComponent(topic) + '&scope=' + encodeURIComponent(scope) : '') + (q ? '&q=' + encodeURIComponent(q) : '');
|
|
58
|
+
}
|
|
59
|
+
models.hlSchedule = function () {
|
|
60
|
+
const today = hlSchedYmd(new Date()), day = HLS.day || today, d = hlSchedDate(day), a = new Date(HLS.anchor), span = hlSchedSpan();
|
|
61
|
+
const ls = labelSearchValue('schedule', { defaultScope: false });
|
|
62
|
+
const runs = HLS.shown?.date === day ? HLS.shown.ran : [], narrowed = !!(hlSchedScope() !== 'all' || (ls.q || '').trim());
|
|
63
|
+
const dayEvents = HLS.shown?.date === day ? (HLS.shown.events || []) : [];
|
|
64
|
+
const formatArgs = (args) => args && typeof args === 'object' && Object.keys(args).length ? JSON.stringify(args, null, 2) : '';
|
|
65
|
+
const events = dayEvents.map(function (ev) {
|
|
66
|
+
const state = !ev.remind ? tr('evtNoRemind')
|
|
67
|
+
: ev.remindState === 'failed' ? tr('evtRemindFailed')
|
|
68
|
+
: ev.remindState === 'sent' ? tr('evtRemindSent')
|
|
69
|
+
: tr('evtRemindAt', hlSchedWhen(ev.remind.at));
|
|
70
|
+
return {
|
|
71
|
+
id: ev.id, rowKey: 'evt:' + ev.id, isEvent: true, isTask: false,
|
|
72
|
+
title: ev.title, event: ev, on: false, running: false,
|
|
73
|
+
bad: ev.remindState === 'failed', error: ev.remind?.error || '',
|
|
74
|
+
state: state,
|
|
75
|
+
sub: [tr('evtTag'), ev.spanText, ev.note, taskTopic(ev), ev.source].filter(Boolean).join(' · '),
|
|
76
|
+
...goes(ev),
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
const items = runs.map(function (r) {
|
|
80
|
+
const dueStr = (hlSchedYmd(new Date(r.due)) === day ? '' : hlSchedYmd(new Date(r.due)) + ' ') + hm(r.due);
|
|
81
|
+
const goInfo = goes(r);
|
|
82
|
+
const topicName = taskTopic(r);
|
|
83
|
+
const kv = [
|
|
84
|
+
r.about ? { k: tr('kvAbout'), v: r.about } : null,
|
|
85
|
+
{ k: tr('kvOp'), v: r.op },
|
|
86
|
+
topicName ? { k: tr('kvTopic'), v: topicName } : null,
|
|
87
|
+
{ k: tr('kvTime'), v: hlSchedWhen(r.at) },
|
|
88
|
+
r.late ? { k: tr('kvDue'), v: hlSchedWhen(r.due) } : null,
|
|
89
|
+
{ k: tr('kvTrigger'), v: tr(r.manual ? 'triggerManual' : 'triggerAuto') },
|
|
90
|
+
{ k: tr('kvStatus'), v: tr('out' + r.outcome) },
|
|
91
|
+
r.error ? { k: tr('kvError'), v: r.error } : null,
|
|
92
|
+
goInfo.go ? { k: tr('kvGo'), v: goInfo.go } : null,
|
|
93
|
+
].filter(Boolean);
|
|
94
|
+
return { id: r.id, at: r.at, key: r.id, title: hm(r.at) + ' ' + taskTitle(r), bad: r.outcome === 'failed',
|
|
95
|
+
state: tr('out' + r.outcome),
|
|
96
|
+
sub: [r.error, topicName, r.about && r.op, r.manual ? tr('manualRun') : '', r.late ? tr('lateRun', dueStr) : '', r.missed ? tr('missedRuns', r.missed) : ''].filter(Boolean).join(' · '),
|
|
97
|
+
kv: kv, argsText: formatArgs(r.args), ...goInfo };
|
|
98
|
+
}).sort(function (x, y) { return x.at - y.at; });
|
|
99
|
+
const dayHead = tr('dayTitle', d.getMonth() + 1, d.getDate(), wd(d.getDay())) + (day === today ? tr('todayTag') : '');
|
|
100
|
+
const taskRows = HLS.tasks.map(function (t) {
|
|
101
|
+
const running = !!t.running;
|
|
102
|
+
const error = !running && !t.enabled && t.last?.error;
|
|
103
|
+
const state = running ? tr('outrunning')
|
|
104
|
+
: t.enabled ? tr('waitingNext', hlSchedWhen(t.next))
|
|
105
|
+
: t.last ? tr('disabledLast', hlSchedWhen(t.last.at), tr('out' + t.last.outcome))
|
|
106
|
+
: tr('disabled');
|
|
107
|
+
return { id: t.id, rowKey: 'task:' + t.id, isEvent: false, isTask: true,
|
|
108
|
+
title: taskTitle(t), on: t.enabled, task: t,
|
|
109
|
+
running: running, bad: !!error, error: error,
|
|
110
|
+
state: state,
|
|
111
|
+
sub: [error, t.about && t.op, t.when.kind === 'once' ? tr('once') : t.rule, taskTopic(t)].filter(Boolean).join(' · '),
|
|
112
|
+
...goes(t) };
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
title: HLS.mode === 'week' ? tr('weekSpan', span[0].getMonth() + 1, span[0].getDate(), span[1].getMonth() + 1, span[1].getDate()) : tr('monthTitle', a.getFullYear(), a.getMonth() + 1),
|
|
116
|
+
mode: HLS.mode, modes: [{ v: 'week', label: tr('modeWeek') }, { v: 'month', label: tr('modeMonth') }],
|
|
117
|
+
search: { key: 'schedule', inputId: 'hl-sched-q', placeholder: tr('s04'), types: [], defaultScope: false },
|
|
118
|
+
calendar: { anchor: HLS.anchor, value: d.getTime(), today: Date.now(), mode: HLS.mode, marks: HLS.marks, highlights: HLS.highlights, act: ui.key('hlSchedDay'), args: {} },
|
|
119
|
+
dayTitle: dayHead + tr('dayRunsSuffix'),
|
|
120
|
+
items: items, hasItems: items.length > 0,
|
|
121
|
+
none: !items.length, noneText: tr(narrowed ? 'noneFiltered' : 'noneFinished'),
|
|
122
|
+
tasks: [...events, ...taskRows],
|
|
123
|
+
tasksEmpty: narrowed ? tr('tasksEmptyFiltered') : tr('tasksEmptyAll')
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
function hlSchedWhen(at) { const d = new Date(at), today = hlSchedYmd(new Date()) === hlSchedYmd(d); return today ? tr('whenToday', hm(at)) : tr('whenDate', d.getMonth() + 1, d.getDate(), hm(at)); }
|
|
127
|
+
changes.hlSchedMode = function (e) { const v = e.target.value; HLS.mode = v; store.set('schedMode', v); if (HLS.day) HLS.anchor = hlSchedDate(HLS.day).getTime(); hlSchedRead().catch(ui.fail); render(true); };
|
|
128
|
+
/* A day is chosen: its list is read. A day of the month before or after, chosen on the month's page, turns the page to it. */
|
|
129
|
+
actions.hlSchedDay = function (d) { const at = new Date(+d.v); HLS.day = hlSchedYmd(at); if (at.getMonth() !== new Date(HLS.anchor).getMonth() || HLS.mode === 'week') HLS.anchor = at.getTime(); hlSchedRead().catch(ui.fail); render(true); };
|
|
130
|
+
/* The page before or after (a month or a week), or back to today. */
|
|
131
|
+
actions.hlSchedMove = function (d) {
|
|
132
|
+
const a = new Date(HLS.anchor), by = +d.v;
|
|
133
|
+
if (!by) { HLS.anchor = Date.now(); HLS.day = hlSchedYmd(new Date()); }
|
|
134
|
+
else HLS.anchor = (HLS.mode === 'week' ? new Date(a.getFullYear(), a.getMonth(), a.getDate() + 7 * by, 12) : new Date(a.getFullYear(), a.getMonth() + by, 1, 12)).getTime();
|
|
135
|
+
hlSchedRead().catch(ui.fail); render(true);
|
|
136
|
+
};
|
|
137
|
+
actions.hlSchedToggle = function ({ id }, control) {
|
|
138
|
+
// The shared switch sets its checked state before invoking the action.
|
|
139
|
+
const enabled = control.getAttribute('aria-checked') === 'true';
|
|
140
|
+
return ui.request('PATCH', '/api/schedule/tasks/' + id, { enabled }).then(hlSchedChanged).catch(ui.fail);
|
|
141
|
+
};
|
|
142
|
+
actions.hlSchedRun = function (d) { ui.request('POST', '/api/schedule/tasks/' + d.id + '/run').then(hlSchedRead).catch(ui.fail); };
|
|
143
|
+
actions.hlSchedRemove = function (d) {
|
|
144
|
+
const t = HLS.tasks.find(function (x) { return x.id === d.id; }); if (!t) return;
|
|
145
|
+
ui.dialog({ title: tr('dlgDelTitle'), text: tr('dlgDelText', taskTitle(t)), ok: tr('delete'), on: function () { return hlSave(ui.request('DELETE', '/api/schedule/tasks/' + t.id).then(hlSchedRead)); } });
|
|
146
|
+
};
|
|
147
|
+
actions.hlSchedRunRemove = function (d) {
|
|
148
|
+
const r = (HLS.shown?.ran || []).find(function (x) { return x.id === d.id; }); if (!r) return;
|
|
149
|
+
ui.dialog({ title: tr('dlgDelRunTitle'), text: tr('dlgDelRunText', taskTitle(r)), ok: tr('delete'), on: function () { return hlSave(ui.request('DELETE', '/api/schedule/runs/' + r.id).then(hlSchedRead)); } });
|
|
150
|
+
};
|
|
151
|
+
const schedKinds = () => [['once', tr('once')], ['every', tr('kindEvery')], ['daily', tr('kindDaily')], ['weekly', tr('kindWeekly')]];
|
|
152
|
+
function hlSchedLocal(at) { const d = new Date(at), pad = (n) => String(n).padStart(2, '0'); return hlSchedYmd(d) + 'T' + pad(d.getHours()) + ':' + pad(d.getMinutes()); }
|
|
153
|
+
const remindPresets = () => [
|
|
154
|
+
['none', tr('evtRemindNone')],
|
|
155
|
+
['0', tr('evtRemindStart')],
|
|
156
|
+
['15', tr('evtRemind15m')],
|
|
157
|
+
['60', tr('evtRemind1h')],
|
|
158
|
+
['1440', tr('evtRemind1d')],
|
|
159
|
+
['custom', tr('evtRemindCustom')],
|
|
160
|
+
];
|
|
161
|
+
function eventRemindKey(cur) {
|
|
162
|
+
if (!cur?.remind) return 'none';
|
|
163
|
+
const b = cur.remind.beforeMinutes;
|
|
164
|
+
if (b === 0 || b === 15 || b === 60 || b === 1440) return String(b);
|
|
165
|
+
return 'custom';
|
|
166
|
+
}
|
|
167
|
+
function activeTopics() {
|
|
168
|
+
const topics = hlTopicCatalog().filter((t) => t.archivedAt == null).map((t) => [t.id, hlTopicPath(t.id).map((x) => x.title).join(' › ')]);
|
|
169
|
+
topics.sort((a, b) => a[1].localeCompare(b[1]));
|
|
170
|
+
return topics;
|
|
171
|
+
}
|
|
172
|
+
function tagPane(fields, pane) {
|
|
173
|
+
return pane ? fields.map(function (f) { return Object.assign({ pane: pane }, f); }) : fields;
|
|
174
|
+
}
|
|
175
|
+
function buildTaskSpec({ cur, carry = {}, topics, pane }) {
|
|
176
|
+
const w = cur?.when;
|
|
177
|
+
const held = function (id, fallback) { return carry[id] !== undefined ? carry[id] : fallback; };
|
|
178
|
+
const kind = held('hl-sch-kind', !w ? 'once' : w.kind === 'daily' ? (w.days ? 'weekly' : 'daily') : w.kind);
|
|
179
|
+
const bindings = cur?.key ? [] : [
|
|
180
|
+
{ id: 'hl-sch-op', label: tr('fldOp'), value: held('hl-sch-op', cur?.op || ''), req: true },
|
|
181
|
+
{ id: 'hl-sch-args', label: tr('fldArgs'), value: held('hl-sch-args', JSON.stringify(cur?.args ?? {}, null, 2)), area: true, mono: true, rows: 4 },
|
|
182
|
+
{ id: 'hl-sch-about', label: tr('fldAbout'), value: held('hl-sch-about', cur?.about || '') },
|
|
183
|
+
{ id: 'hl-sch-ref', label: tr('fldRef'), value: held('hl-sch-ref', cur?.ref || '') },
|
|
184
|
+
{ id: 'hl-sch-topic', label: tr('fldTopic'), value: held('hl-sch-topic', cur ? cur.topicId || '' : HL.topic?.id || ''), options: [['', tr('global')], ...topics] },
|
|
185
|
+
];
|
|
186
|
+
/* A new one-off: on the day chosen on the calendar when that is still to come, else an hour from now. */
|
|
187
|
+
const at = w && w.kind === 'once' ? hlSchedLocal(w.at) : HLS.day && HLS.day > hlSchedYmd(new Date()) ? HLS.day + 'T09:00' : hlSchedLocal(Date.now() + 3600000);
|
|
188
|
+
const hours = w && w.kind === 'every' && w.minutes % 60 === 0;
|
|
189
|
+
const when = kind === 'once' ? [{ id: 'hl-sch-at', label: tr('fldTime'), type: 'datetime-local', value: held('hl-sch-at', at), req: true }]
|
|
190
|
+
: kind === 'every' ? [{ id: 'hl-sch-n', label: tr('fldEvery'), type: 'number', min: 1, value: held('hl-sch-n', w && w.kind === 'every' ? String(hours ? w.minutes / 60 : w.minutes) : '60'), req: true }, { id: 'hl-sch-unit', label: tr('fldUnit'), options: [['1', tr('unitMin')], ['60', tr('unitHour')]], value: held('hl-sch-unit', hours ? '60' : '1'), help: tr(cur ? 'helpEveryEdit' : 'helpEveryNew') }]
|
|
191
|
+
: (kind === 'weekly' ? [1, 2, 3, 4, 5, 6, 0].map(function (n) { return { id: 'hl-sch-d' + n, check: tr('checkWeekday', wd(n)), checked: held('hl-sch-d' + n, !!(w && w.days && w.days.indexOf(n) >= 0)) }; }) : [])
|
|
192
|
+
.concat([{ id: 'hl-sch-time', label: tr('fldAtTime'), type: 'time', value: held('hl-sch-time', w && w.kind === 'daily' ? w.time : '09:00'), req: true, help: tr('helpTz') }]);
|
|
193
|
+
return {
|
|
194
|
+
when: when,
|
|
195
|
+
fields: tagPane([...bindings, { id: 'hl-sch-kind', label: tr('fldWhen'), options: schedKinds(), value: kind }, ...when], pane),
|
|
196
|
+
submit: function () {
|
|
197
|
+
const stop = function (why) { throw new Error(why); };
|
|
198
|
+
let rule, same = false; /* a rule that was not touched is not sent: the task keeps the time it is due next */
|
|
199
|
+
if (kind === 'once') { const v = val('hl-sch-at'), t = Date.parse(v); if (!t) return false; rule = { kind: 'once', at: t }; same = !!w && w.kind === 'once' && hlSchedLocal(w.at) === v; }
|
|
200
|
+
else if (kind === 'every') { const n = Number(val('hl-sch-n')) * Number(val('hl-sch-unit')); if (!(n >= 1)) return stop(tr('errInterval')); rule = { kind: 'every', minutes: n }; same = !!w && w.kind === 'every' && w.minutes === n; }
|
|
201
|
+
else {
|
|
202
|
+
const days = [0, 1, 2, 3, 4, 5, 6].filter(function (n) { const el = document.getElementById('hl-sch-d' + n); return el && el.checked; });
|
|
203
|
+
if (kind === 'weekly' && !days.length) return stop(tr('errWeekdays'));
|
|
204
|
+
rule = Object.assign({ kind: 'daily', time: val('hl-sch-time') }, kind === 'weekly' && days.length < 7 ? { days: days } : {});
|
|
205
|
+
same = !!w && w.kind === 'daily' && w.time === rule.time && JSON.stringify(w.days || null) === JSON.stringify(rule.days || null);
|
|
206
|
+
}
|
|
207
|
+
const body = same ? {} : { when: rule };
|
|
208
|
+
if (!cur?.key) {
|
|
209
|
+
const op = val('hl-sch-op');
|
|
210
|
+
if (!op) return stop(tr('errOp'));
|
|
211
|
+
let args;
|
|
212
|
+
try { args = JSON.parse(val('hl-sch-args') || '{}'); }
|
|
213
|
+
catch { return stop(tr('errArgs')); }
|
|
214
|
+
if (!args || typeof args !== 'object' || Array.isArray(args)) return stop(tr('errArgs'));
|
|
215
|
+
Object.assign(body, { op, args, about: val('hl-sch-about'), ref: val('hl-sch-ref'), topicId: val('hl-sch-topic') || null });
|
|
216
|
+
}
|
|
217
|
+
return hlSave((cur ? ui.request('PATCH', '/api/schedule/tasks/' + cur.id, body) : ui.request('POST', '/api/schedule/tasks', body)).then(function () { HLS.dialog = null; hlSchedChanged(); }));
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function buildEventSpec({ cur, carry = {}, topics, pane }) {
|
|
222
|
+
const held = function (id, fallback) { return carry[id] !== undefined ? carry[id] : fallback; };
|
|
223
|
+
const mode = held('hl-evt-mode', cur ? (cur.allDay ? 'allDay' : 'timed') : 'allDay');
|
|
224
|
+
const chosenDay = HLS.day || hlSchedYmd(new Date());
|
|
225
|
+
const initRemind = eventRemindKey(cur);
|
|
226
|
+
const remind = held('hl-evt-remind', initRemind);
|
|
227
|
+
const timeFields = mode === 'allDay'
|
|
228
|
+
? [
|
|
229
|
+
{ id: 'hl-evt-start-date', label: tr('fldStartDate'), type: 'date', value: held('hl-evt-start-date', cur?.allDay ? cur.startDate : chosenDay), req: true },
|
|
230
|
+
{ id: 'hl-evt-end-date', label: tr('fldEndDate'), type: 'date', value: held('hl-evt-end-date', cur?.allDay ? cur.endDate : chosenDay), req: true },
|
|
231
|
+
]
|
|
232
|
+
: [
|
|
233
|
+
{ id: 'hl-evt-start', label: tr('fldStartTime'), type: 'datetime-local', value: held('hl-evt-start', cur && !cur.allDay ? hlSchedLocal(cur.start) : chosenDay + 'T09:00'), req: true },
|
|
234
|
+
{ id: 'hl-evt-end', label: tr('fldEndTime'), type: 'datetime-local', value: held('hl-evt-end', cur && !cur.allDay ? hlSchedLocal(cur.end) : chosenDay + 'T10:00'), req: true },
|
|
235
|
+
];
|
|
236
|
+
const remindFields = remind === 'custom'
|
|
237
|
+
? [{ id: 'hl-evt-remind-at', label: tr('fldEvtRemindAt'), type: 'datetime-local', value: held('hl-evt-remind-at', cur?.remind ? hlSchedLocal(cur.remind.at) : chosenDay + 'T09:00'), req: true }]
|
|
238
|
+
: [];
|
|
239
|
+
return {
|
|
240
|
+
fields: tagPane([
|
|
241
|
+
{ id: 'hl-evt-title', label: tr('fldEvtTitle'), value: held('hl-evt-title', cur?.title || ''), req: true },
|
|
242
|
+
{ id: 'hl-evt-mode', label: tr('fldEvtMode'), options: [['allDay', tr('evtModeAllDay')], ['timed', tr('evtModeTimed')]], value: mode },
|
|
243
|
+
...timeFields,
|
|
244
|
+
{ id: 'hl-evt-remind', label: tr('fldEvtRemind'), options: remindPresets(), value: remind },
|
|
245
|
+
...remindFields,
|
|
246
|
+
{ id: 'hl-evt-topic', label: tr('fldTopic'), value: held('hl-evt-topic', cur ? cur.topicId || '' : HL.topic?.id || ''), options: [['', tr('global')], ...topics] },
|
|
247
|
+
{ id: 'hl-evt-ref', label: tr('fldRef'), value: held('hl-evt-ref', cur?.ref || '') },
|
|
248
|
+
{ id: 'hl-evt-note', label: tr('fldEvtNote'), value: held('hl-evt-note', cur?.note || ''), area: true, rows: 3 },
|
|
249
|
+
], pane),
|
|
250
|
+
submit: function () {
|
|
251
|
+
const stop = function (why) { throw new Error(why); };
|
|
252
|
+
const title = val('hl-evt-title').trim();
|
|
253
|
+
if (!title) return stop(tr('errEvtTitle'));
|
|
254
|
+
const body = {
|
|
255
|
+
title,
|
|
256
|
+
topicId: val('hl-evt-topic') || null,
|
|
257
|
+
ref: val('hl-evt-ref').trim(),
|
|
258
|
+
note: val('hl-evt-note').trim(),
|
|
259
|
+
};
|
|
260
|
+
if (mode === 'allDay') {
|
|
261
|
+
const startDate = val('hl-evt-start-date'), endDate = val('hl-evt-end-date') || startDate;
|
|
262
|
+
if (!startDate || !endDate || endDate < startDate) return stop(tr('errEvtDates'));
|
|
263
|
+
Object.assign(body, { allDay: true, startDate, endDate });
|
|
264
|
+
} else {
|
|
265
|
+
const start = Date.parse(val('hl-evt-start')), end = Date.parse(val('hl-evt-end'));
|
|
266
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || end < start) return stop(tr('errEvtTimes'));
|
|
267
|
+
Object.assign(body, { allDay: false, start, end });
|
|
268
|
+
}
|
|
269
|
+
const remindVal = val('hl-evt-remind');
|
|
270
|
+
const keepExistingRemind = cur && remindVal === initRemind && (remindVal !== 'custom' || hlSchedLocal(cur.remind.at) === val('hl-evt-remind-at'));
|
|
271
|
+
if (!keepExistingRemind) {
|
|
272
|
+
if (remindVal === 'none') {
|
|
273
|
+
if (cur?.remind) body.remind = null;
|
|
274
|
+
} else if (remindVal === 'custom') {
|
|
275
|
+
const at = Date.parse(val('hl-evt-remind-at'));
|
|
276
|
+
if (!Number.isFinite(at)) return stop(tr('errEvtRemindAt'));
|
|
277
|
+
body.remind = { at };
|
|
278
|
+
} else {
|
|
279
|
+
body.remind = { beforeMinutes: Number(remindVal) };
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return hlSave((cur ? ui.request('PATCH', '/api/schedule/events/' + cur.id, body) : ui.request('POST', '/api/schedule/events', body)).then(function () { HLS.dialog = null; hlSchedChanged(); }));
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function syncWeekdayChecks(when) {
|
|
287
|
+
setTimeout(function () {
|
|
288
|
+
when.forEach(function (f) { const el = f.check && document.getElementById(f.id); if (el) el.checked = !!f.checked; });
|
|
289
|
+
}, 0);
|
|
290
|
+
}
|
|
291
|
+
function hlSchedCreateDialog({ pane = 'event', carry = {} } = {}) {
|
|
292
|
+
if (!HL_TOPIC_CATALOG) return hlTopicCatalogRead().then(() => hlSchedCreateDialog({ pane, carry }), ui.fail);
|
|
293
|
+
const topics = activeTopics();
|
|
294
|
+
const evSpec = buildEventSpec({ carry, topics, pane: 'event' });
|
|
295
|
+
const taskSpec = buildTaskSpec({ carry, topics, pane: 'task' });
|
|
296
|
+
const panes = { cur: pane, items: [{ v: 'event', label: tr('paneEvent') }, { v: 'task', label: tr('paneTask') }] };
|
|
297
|
+
HLS.dialog = { kind: 'create' };
|
|
298
|
+
ui.dialog({
|
|
299
|
+
title: tr('dlgNewTitle'), ok: tr('create'), danger: false, wide: true,
|
|
300
|
+
panes: panes,
|
|
301
|
+
fields: [...evSpec.fields, ...taskSpec.fields],
|
|
302
|
+
on: function () { return panes.cur === 'task' ? taskSpec.submit() : evSpec.submit(); },
|
|
303
|
+
});
|
|
304
|
+
if (pane === 'task') syncWeekdayChecks(taskSpec.when);
|
|
305
|
+
}
|
|
306
|
+
function hlSchedForm({ task: cur, carry = {} }) {
|
|
307
|
+
if (!cur) return hlSchedCreateDialog({ pane: 'task', carry });
|
|
308
|
+
if (!HL_TOPIC_CATALOG) return hlTopicCatalogRead().then(() => hlSchedForm({ task: cur, carry }), ui.fail);
|
|
309
|
+
const spec = buildTaskSpec({ cur, carry, topics: activeTopics() });
|
|
310
|
+
HLS.dialog = { kind: 'task', task: cur };
|
|
311
|
+
ui.dialog({
|
|
312
|
+
title: tr('dlgEditTitle'), ok: tr('save'), danger: false, wide: true,
|
|
313
|
+
text: cur?.key ? taskTitle(cur) : '',
|
|
314
|
+
fields: spec.fields,
|
|
315
|
+
on: spec.submit,
|
|
316
|
+
});
|
|
317
|
+
syncWeekdayChecks(spec.when);
|
|
318
|
+
}
|
|
319
|
+
function hlSchedEventForm({ event: cur, carry = {} }) {
|
|
320
|
+
if (!cur) return hlSchedCreateDialog({ pane: 'event', carry });
|
|
321
|
+
if (!HL_TOPIC_CATALOG) return hlTopicCatalogRead().then(() => hlSchedEventForm({ event: cur, carry }), ui.fail);
|
|
322
|
+
const spec = buildEventSpec({ cur, carry, topics: activeTopics() });
|
|
323
|
+
HLS.dialog = { kind: 'event', event: cur };
|
|
324
|
+
ui.dialog({
|
|
325
|
+
title: tr('dlgEvtEditTitle'), ok: tr('save'), danger: false, wide: true,
|
|
326
|
+
fields: spec.fields,
|
|
327
|
+
on: spec.submit,
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
function collectDialogCarry() {
|
|
331
|
+
const carry = {};
|
|
332
|
+
(S.dialog?.fields || []).forEach(function (f) {
|
|
333
|
+
if (!f.id) return;
|
|
334
|
+
const el = document.getElementById(f.id);
|
|
335
|
+
if (el) carry[f.id] = el.type === 'checkbox' ? el.checked : el.value;
|
|
336
|
+
else if (f.check) carry[f.id] = !!f.checked;
|
|
337
|
+
else if (f.value !== undefined) carry[f.id] = f.value;
|
|
338
|
+
});
|
|
339
|
+
return carry;
|
|
340
|
+
}
|
|
341
|
+
actions.hlSchedNew = function () { hlSchedCreateDialog({}); };
|
|
342
|
+
actions.hlSchedEdit = hlSchedForm;
|
|
343
|
+
actions.hlSchedEventNew = function () { hlSchedCreateDialog({ pane: 'event' }); };
|
|
344
|
+
actions.hlSchedEventEdit = hlSchedEventForm;
|
|
345
|
+
actions.hlSchedEventRemove = function (d) {
|
|
346
|
+
const ev = (HLS.shown?.events || []).find(function (x) { return x.id === d.id; }); if (!ev) return;
|
|
347
|
+
ui.dialog({ title: tr('dlgEvtDelTitle'), text: tr('dlgEvtDelText', ev.title), ok: tr('delete'), on: function () { return hlSave(ui.request('DELETE', '/api/schedule/events/' + ev.id).then(hlSchedRead)); } });
|
|
348
|
+
};
|
|
349
|
+
document.addEventListener('change', function (e) {
|
|
350
|
+
const id = e.target?.id;
|
|
351
|
+
if (!S.dialog || !HLS.dialog) return;
|
|
352
|
+
if (id !== 'hl-sch-kind' && id !== 'hl-evt-mode' && id !== 'hl-evt-remind') return;
|
|
353
|
+
const carry = collectDialogCarry();
|
|
354
|
+
if (HLS.dialog.kind === 'create') hlSchedCreateDialog({ pane: S.dialog.panes?.cur || 'event', carry });
|
|
355
|
+
else if (HLS.dialog.kind === 'task') hlSchedForm({ task: HLS.dialog.task, carry });
|
|
356
|
+
else if (HLS.dialog.kind === 'event') hlSchedEventForm({ event: HLS.dialog.event, carry });
|
|
357
|
+
}, { signal: ui.signal });
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
let runTopic, runTasks = [], upcomingRead = 0;
|
|
361
|
+
function readUpcoming() {
|
|
362
|
+
if (!ui.shown('run')) return;
|
|
363
|
+
const topic = HL.topic, read = ++upcomingRead;
|
|
364
|
+
return ui.request('GET', '/api/schedule/tasks?topic=' + encodeURIComponent(topic.id)).catch(function () { return []; }).then(function (tasks) {
|
|
365
|
+
if (ui.signal.aborted || read !== upcomingRead || topic !== HL.topic || !ui.shown('run')) return;
|
|
366
|
+
runTasks = tasks.filter(function (task) { return task.topicId === topic.id && task.enabled; });
|
|
367
|
+
render(true);
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
function updateUpcoming() {
|
|
371
|
+
const topic = ui.shown('run') ? HL.topic : null;
|
|
372
|
+
if (topic === runTopic) return;
|
|
373
|
+
runTopic = topic;
|
|
374
|
+
runTasks = [];
|
|
375
|
+
if (topic) readUpcoming();
|
|
376
|
+
}
|
|
377
|
+
function update() {
|
|
378
|
+
updateUpcoming();
|
|
379
|
+
/* Start reads after the page or pane is visible. A model may also be sampled while it is being replaced. */
|
|
380
|
+
const seen = ui.shown('schedule') ? S.route + ':' + NAV.seq + ':' + hlSchedQuery() : '';
|
|
381
|
+
if (seen === HLS.seen) return;
|
|
382
|
+
HLS.seen = seen;
|
|
383
|
+
if (seen) hlSchedChanged();
|
|
384
|
+
}
|
|
385
|
+
models.hlScheduleRun = function () {
|
|
386
|
+
const tasks = (runTopic === HL.topic ? runTasks : []).map(function (task) {
|
|
387
|
+
return { id: task.id, title: taskTitle(task),
|
|
388
|
+
sub: [task.about && task.op, task.when.kind === 'once' ? '' : task.rule, tr('nextAt', hlSchedWhen(task.next))].filter(Boolean).join(' · '),
|
|
389
|
+
...goes(task) };
|
|
390
|
+
});
|
|
391
|
+
return { tasks: tasks, hasTasks: !!tasks.length };
|
|
392
|
+
};
|
|
393
|
+
return {
|
|
394
|
+
models, actions, changes, inputs, update,
|
|
395
|
+
events: { 'schedule.changed': function () { hlSchedChanged(); readUpcoming(); } },
|
|
396
|
+
dispose() { clearTimeout(HLS_SOON); }
|
|
397
|
+
};
|
|
398
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export interface EventReminder {
|
|
2
|
+
/** Millisecond timestamp when the reminder fires. */
|
|
3
|
+
at: number;
|
|
4
|
+
/** Optional minutes before event start when configured relatively. */
|
|
5
|
+
beforeMinutes?: number;
|
|
6
|
+
/** Optional topic message recipients (member IDs for agent-created events). */
|
|
7
|
+
targets?: string[];
|
|
8
|
+
/** Optional custom reminder text. */
|
|
9
|
+
content?: string;
|
|
10
|
+
/** Timestamp when the reminder was delivered (or skipped for archived topic). */
|
|
11
|
+
sentAt?: number;
|
|
12
|
+
/** Destination address opened by the reminder (e.g. message or event ref). */
|
|
13
|
+
open?: string;
|
|
14
|
+
/** Last delivery error, if sending failed. */
|
|
15
|
+
error?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface CalendarEvent {
|
|
18
|
+
id: string;
|
|
19
|
+
title: string;
|
|
20
|
+
note?: string;
|
|
21
|
+
allDay: boolean;
|
|
22
|
+
/** Inclusive YYYY-MM-DD when `allDay === true`. */
|
|
23
|
+
startDate?: string;
|
|
24
|
+
endDate?: string;
|
|
25
|
+
/** Millisecond timestamps when `allDay === false`. */
|
|
26
|
+
start?: number;
|
|
27
|
+
end?: number;
|
|
28
|
+
topicId?: string;
|
|
29
|
+
ref?: string;
|
|
30
|
+
/** Optional idempotency key for plugin/app/member upsert. */
|
|
31
|
+
key?: string;
|
|
32
|
+
/** Optional source plugin or app label. */
|
|
33
|
+
source?: string;
|
|
34
|
+
by: string;
|
|
35
|
+
remind?: EventReminder;
|
|
36
|
+
createdAt: number;
|
|
37
|
+
updatedAt: number;
|
|
38
|
+
}
|
|
39
|
+
export type EventSpan = {
|
|
40
|
+
allDay: true;
|
|
41
|
+
startDate: string;
|
|
42
|
+
endDate: string;
|
|
43
|
+
} | {
|
|
44
|
+
allDay: false;
|
|
45
|
+
start: number;
|
|
46
|
+
end: number;
|
|
47
|
+
};
|
|
48
|
+
export type DaySpanPos = 'single' | 'start' | 'mid' | 'end';
|
|
49
|
+
export declare function parseYmd(text: string): Date;
|
|
50
|
+
export declare function formatYmd(day: Date): string;
|
|
51
|
+
export declare function formatHm(at: number): string;
|
|
52
|
+
export interface EventSpanInput {
|
|
53
|
+
allDay?: boolean;
|
|
54
|
+
startDate?: string;
|
|
55
|
+
endDate?: string;
|
|
56
|
+
start?: number | string;
|
|
57
|
+
end?: number | string;
|
|
58
|
+
}
|
|
59
|
+
export declare function readEventSpan(input: EventSpanInput): EventSpan;
|
|
60
|
+
/** Local-time anchor for relative reminders: 09:00 on startDate for all-day events, exact start otherwise. */
|
|
61
|
+
export declare function eventAnchorStart(span: EventSpan): number;
|
|
62
|
+
export interface EventReminderInput {
|
|
63
|
+
at?: number | string;
|
|
64
|
+
beforeMinutes?: number;
|
|
65
|
+
targets?: string[];
|
|
66
|
+
content?: string;
|
|
67
|
+
}
|
|
68
|
+
export declare function readEventReminder(raw: EventReminderInput | null | undefined, span: EventSpan, now: number, opts?: {
|
|
69
|
+
allowPast?: boolean;
|
|
70
|
+
}): EventReminder | undefined;
|
|
71
|
+
export declare function eventCoversDay(event: CalendarEvent, ymd: string, dayStart: number, dayEnd: number): boolean;
|
|
72
|
+
export declare function eventOverlapsRange(event: CalendarEvent, fromYmd: string, toYmd: string, rangeStart: number, rangeEnd: number): boolean;
|
|
73
|
+
export declare function eventSpanPosition(event: CalendarEvent, ymd: string): DaySpanPos;
|
|
74
|
+
export declare function combineDaySpan(positions: DaySpanPos[]): DaySpanPos | undefined;
|
|
75
|
+
export declare function eventSortKey(event: CalendarEvent): number;
|
|
76
|
+
export declare function describeEventSpan(event: CalendarEvent): string;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { ArgsError } from 'hostlet/sdk';
|
|
2
|
+
const DAY_RE = /^(\d{4})-(\d\d)-(\d\d)$/;
|
|
3
|
+
const MINUTE = 60_000;
|
|
4
|
+
export function parseYmd(text) {
|
|
5
|
+
const parts = DAY_RE.exec(text);
|
|
6
|
+
if (!parts)
|
|
7
|
+
throw new ArgsError('日期要写成 YYYY-MM-DD');
|
|
8
|
+
const y = Number(parts[1]), m = Number(parts[2]), d = Number(parts[3]);
|
|
9
|
+
const day = new Date(y, m - 1, d);
|
|
10
|
+
if (day.getFullYear() !== y || day.getMonth() !== m - 1 || day.getDate() !== d) {
|
|
11
|
+
throw new ArgsError(`无效的日期:${text}`);
|
|
12
|
+
}
|
|
13
|
+
return day;
|
|
14
|
+
}
|
|
15
|
+
export function formatYmd(day) {
|
|
16
|
+
return [day.getFullYear(), String(day.getMonth() + 1).padStart(2, '0'), String(day.getDate()).padStart(2, '0')].join('-');
|
|
17
|
+
}
|
|
18
|
+
export function formatHm(at) {
|
|
19
|
+
const d = new Date(at);
|
|
20
|
+
return String(d.getHours()).padStart(2, '0') + ':' + String(d.getMinutes()).padStart(2, '0');
|
|
21
|
+
}
|
|
22
|
+
function parseTimestamp(raw, label) {
|
|
23
|
+
const value = typeof raw === 'string' ? Date.parse(raw) : typeof raw === 'number' ? raw : NaN;
|
|
24
|
+
if (!Number.isFinite(value))
|
|
25
|
+
throw new ArgsError(`${label}需要是毫秒时间戳或日期时间字符串`);
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
export function readEventSpan(input) {
|
|
29
|
+
const hasDate = input.startDate !== undefined || input.endDate !== undefined;
|
|
30
|
+
const hasTime = input.start !== undefined || input.end !== undefined;
|
|
31
|
+
const allDay = input.allDay ?? (hasDate && !hasTime);
|
|
32
|
+
if (allDay) {
|
|
33
|
+
if (hasTime)
|
|
34
|
+
throw new ArgsError('全天日程请使用 startDate / endDate,不要同时传 start / end');
|
|
35
|
+
if (typeof input.startDate !== 'string')
|
|
36
|
+
throw new ArgsError('全天日程必须提供 startDate(YYYY-MM-DD)');
|
|
37
|
+
parseYmd(input.startDate);
|
|
38
|
+
const endDate = input.endDate ?? input.startDate;
|
|
39
|
+
parseYmd(endDate);
|
|
40
|
+
if (endDate < input.startDate)
|
|
41
|
+
throw new ArgsError('结束日期不能早于开始日期');
|
|
42
|
+
return { allDay: true, startDate: input.startDate, endDate };
|
|
43
|
+
}
|
|
44
|
+
if (hasDate)
|
|
45
|
+
throw new ArgsError('精确时间段日程请使用 start / end,不要同时传 startDate / endDate');
|
|
46
|
+
if (input.start === undefined)
|
|
47
|
+
throw new ArgsError('请提供开始时间(start)或全天开始日期(startDate)');
|
|
48
|
+
const start = parseTimestamp(input.start, '开始时间');
|
|
49
|
+
const end = input.end === undefined ? start : parseTimestamp(input.end, '结束时间');
|
|
50
|
+
if (end < start)
|
|
51
|
+
throw new ArgsError('结束时间不能早于开始时间');
|
|
52
|
+
return { allDay: false, start, end };
|
|
53
|
+
}
|
|
54
|
+
/** Local-time anchor for relative reminders: 09:00 on startDate for all-day events, exact start otherwise. */
|
|
55
|
+
export function eventAnchorStart(span) {
|
|
56
|
+
if (!span.allDay)
|
|
57
|
+
return span.start;
|
|
58
|
+
const day = parseYmd(span.startDate);
|
|
59
|
+
return new Date(day.getFullYear(), day.getMonth(), day.getDate(), 9, 0).getTime();
|
|
60
|
+
}
|
|
61
|
+
export function readEventReminder(raw, span, now, opts) {
|
|
62
|
+
if (raw == null)
|
|
63
|
+
return undefined;
|
|
64
|
+
if (typeof raw !== 'object' || Array.isArray(raw))
|
|
65
|
+
throw new ArgsError('remind 需要是对象或 null');
|
|
66
|
+
let at;
|
|
67
|
+
let beforeMinutes;
|
|
68
|
+
if (raw.at !== undefined) {
|
|
69
|
+
at = parseTimestamp(raw.at, '提醒时间');
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
beforeMinutes = raw.beforeMinutes === undefined ? 0 : Number(raw.beforeMinutes);
|
|
73
|
+
if (!Number.isFinite(beforeMinutes) || beforeMinutes < 0) {
|
|
74
|
+
throw new ArgsError('提前提醒分钟数(beforeMinutes)须为不小于 0 的数字');
|
|
75
|
+
}
|
|
76
|
+
at = eventAnchorStart(span) - beforeMinutes * MINUTE;
|
|
77
|
+
}
|
|
78
|
+
if (!opts?.allowPast && at <= now) {
|
|
79
|
+
throw new ArgsError('提醒时间已经过了,请调整提醒时间或关闭提醒');
|
|
80
|
+
}
|
|
81
|
+
const content = typeof raw.content === 'string' && raw.content.trim() ? raw.content.trim() : undefined;
|
|
82
|
+
const targets = Array.isArray(raw.targets) && raw.targets.length ? raw.targets : undefined;
|
|
83
|
+
return {
|
|
84
|
+
at,
|
|
85
|
+
...(beforeMinutes !== undefined ? { beforeMinutes } : {}),
|
|
86
|
+
...(targets ? { targets } : {}),
|
|
87
|
+
...(content ? { content } : {}),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export function eventCoversDay(event, ymd, dayStart, dayEnd) {
|
|
91
|
+
if (event.allDay) {
|
|
92
|
+
return ymd >= event.startDate && ymd <= event.endDate;
|
|
93
|
+
}
|
|
94
|
+
const start = event.start;
|
|
95
|
+
const end = event.end ?? start;
|
|
96
|
+
return end === start ? (start >= dayStart && start < dayEnd) : (start < dayEnd && end > dayStart);
|
|
97
|
+
}
|
|
98
|
+
export function eventOverlapsRange(event, fromYmd, toYmd, rangeStart, rangeEnd) {
|
|
99
|
+
if (event.allDay) {
|
|
100
|
+
return event.startDate <= toYmd && event.endDate >= fromYmd;
|
|
101
|
+
}
|
|
102
|
+
const start = event.start;
|
|
103
|
+
const end = event.end ?? start;
|
|
104
|
+
return end === start ? (start >= rangeStart && start < rangeEnd) : (start < rangeEnd && end > rangeStart);
|
|
105
|
+
}
|
|
106
|
+
export function eventSpanPosition(event, ymd) {
|
|
107
|
+
let firstYmd;
|
|
108
|
+
let lastYmd;
|
|
109
|
+
if (event.allDay) {
|
|
110
|
+
firstYmd = event.startDate;
|
|
111
|
+
lastYmd = event.endDate;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
const start = event.start;
|
|
115
|
+
const end = event.end ?? start;
|
|
116
|
+
firstYmd = formatYmd(new Date(start));
|
|
117
|
+
lastYmd = end > start ? formatYmd(new Date(end - 1)) : firstYmd;
|
|
118
|
+
}
|
|
119
|
+
if (firstYmd === lastYmd)
|
|
120
|
+
return 'single';
|
|
121
|
+
if (ymd === firstYmd)
|
|
122
|
+
return 'start';
|
|
123
|
+
if (ymd === lastYmd)
|
|
124
|
+
return 'end';
|
|
125
|
+
return 'mid';
|
|
126
|
+
}
|
|
127
|
+
export function combineDaySpan(positions) {
|
|
128
|
+
if (!positions.length)
|
|
129
|
+
return undefined;
|
|
130
|
+
const hasPrev = positions.some((p) => p === 'mid' || p === 'end');
|
|
131
|
+
const hasNext = positions.some((p) => p === 'start' || p === 'mid');
|
|
132
|
+
if (hasPrev && hasNext)
|
|
133
|
+
return 'mid';
|
|
134
|
+
if (hasNext)
|
|
135
|
+
return 'start';
|
|
136
|
+
if (hasPrev)
|
|
137
|
+
return 'end';
|
|
138
|
+
return 'single';
|
|
139
|
+
}
|
|
140
|
+
export function eventSortKey(event) {
|
|
141
|
+
if (event.allDay)
|
|
142
|
+
return parseYmd(event.startDate).getTime();
|
|
143
|
+
return event.start;
|
|
144
|
+
}
|
|
145
|
+
export function describeEventSpan(event) {
|
|
146
|
+
if (event.allDay) {
|
|
147
|
+
return event.startDate === event.endDate ? event.startDate : `${event.startDate} ~ ${event.endDate}`;
|
|
148
|
+
}
|
|
149
|
+
const start = event.start;
|
|
150
|
+
const end = event.end ?? start;
|
|
151
|
+
const startDay = formatYmd(new Date(start));
|
|
152
|
+
const startHm = formatHm(start);
|
|
153
|
+
if (end === start)
|
|
154
|
+
return `${startDay} ${startHm}`;
|
|
155
|
+
const endDay = formatYmd(new Date(end));
|
|
156
|
+
const endHm = formatHm(end);
|
|
157
|
+
return startDay === endDay ? `${startDay} ${startHm} ~ ${endHm}` : `${startDay} ${startHm} ~ ${endDay} ${endHm}`;
|
|
158
|
+
}
|