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,454 @@
|
|
|
1
|
+
import { setTimeout as wait } from 'node:timers/promises';
|
|
2
|
+
import { address, errorText, ljoin, log, ltext, OWNER_ID, readJson, writeDocuments } from 'hostlet/sdk';
|
|
3
|
+
import { networkReachable, parseEndpoints } from "./probe.js";
|
|
4
|
+
const id = 'recovery';
|
|
5
|
+
const failPrefix = id + '.fail:';
|
|
6
|
+
const outageKey = id + '.outage';
|
|
7
|
+
const api = '/api/recovery';
|
|
8
|
+
const failureKey = (replyId) => failPrefix + replyId;
|
|
9
|
+
const markdownLabel = (text) => text.replace(/[\r\n]+/g, ' ').replace(/[[\]\\]/g, '\\$&');
|
|
10
|
+
const time = new Intl.DateTimeFormat(undefined, { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
|
|
11
|
+
const packs = {
|
|
12
|
+
zh: {
|
|
13
|
+
failure: '回复失败',
|
|
14
|
+
reason: '回复失败:{reason}',
|
|
15
|
+
retry: '重试',
|
|
16
|
+
outage: '网络不可达,{count} 条回复等待恢复。',
|
|
17
|
+
next: '下次检测时间 {time}',
|
|
18
|
+
checking: '正在检测网络',
|
|
19
|
+
probe: '立即检测',
|
|
20
|
+
retryAll: '全部重试',
|
|
21
|
+
cancel: '取消等待',
|
|
22
|
+
},
|
|
23
|
+
en: {
|
|
24
|
+
failure: 'Reply failed',
|
|
25
|
+
reason: 'Reply failed: {reason}',
|
|
26
|
+
retry: 'Retry',
|
|
27
|
+
outage: 'Network unreachable. {count} replies are waiting to retry.',
|
|
28
|
+
next: 'Next check at {time}',
|
|
29
|
+
checking: 'Checking connectivity',
|
|
30
|
+
probe: 'Check now',
|
|
31
|
+
retryAll: 'Retry all',
|
|
32
|
+
cancel: 'Stop waiting',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
export function recoveryPlugin(home, plugin, { probe = networkReachable, backoffMs = [15_000, 30_000, 60_000, 120_000], staggerMs = 500, } = {}) {
|
|
36
|
+
return {
|
|
37
|
+
name: id,
|
|
38
|
+
title: '异常恢复',
|
|
39
|
+
about: '提醒机主回复失败,网络恢复后在原回复重试。',
|
|
40
|
+
group: '宿主',
|
|
41
|
+
needs: ['a2a', 'entry', 'i18n', 'members', 'messages', 'notices', 'push', 'topics'],
|
|
42
|
+
start(ctx) {
|
|
43
|
+
ctx.effect(plugin.config.declare([
|
|
44
|
+
{
|
|
45
|
+
key: 'autoRetry', kind: 'boolean',
|
|
46
|
+
label: { default: '网络恢复后自动重试',
|
|
47
|
+
translations: { en: 'Retry automatically when network returns' } },
|
|
48
|
+
description: { default: '关闭后可在原回复上手动重试。',
|
|
49
|
+
translations: { en: 'When off, retry manually from the original reply.' } },
|
|
50
|
+
default: true,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
key: 'endpoints', kind: 'list',
|
|
54
|
+
label: { default: '网络探测地址',
|
|
55
|
+
translations: { en: 'Network probe endpoints' } },
|
|
56
|
+
description: { default: '可填 HTTP 或 HTTPS 地址,包括内网地址。清空后停用探测。',
|
|
57
|
+
translations: { en: 'HTTP or HTTPS endpoints, including internal addresses. Clear the list to disable probing.' } },
|
|
58
|
+
default: ['https://www.google.com/generate_204', 'https://api.openai.com', 'https://api.deepseek.com', 'https://1.1.1.1/cdn-cgi/trace'],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
key: 'probeTimeoutSeconds', kind: 'number',
|
|
62
|
+
label: { default: '单个地址的超时时间',
|
|
63
|
+
translations: { en: 'Timeout per endpoint' } },
|
|
64
|
+
description: { default: '每个网络探测地址最多等待多少秒,取值范围为 1 至 60 秒。',
|
|
65
|
+
translations: { en: 'Maximum seconds to wait for each network probe endpoint, from 1 to 60.' } },
|
|
66
|
+
minimum: 1, maximum: 60, default: 5, unit: 'seconds', integer: true, presets: [3, 5, 10, 15, 30],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
key: 'maxAutoRetries', kind: 'number',
|
|
70
|
+
label: { default: '单条回复的自动重试次数',
|
|
71
|
+
translations: { en: 'Automatic retries per reply' } },
|
|
72
|
+
description: { default: '设为 0 时,保留探测和手动重试。',
|
|
73
|
+
translations: { en: 'Set to 0 to keep probing and manual retry only.' } },
|
|
74
|
+
minimum: 0, default: 1, unit: 'count', integer: true, presets: [0, 1, 2, 3, 5],
|
|
75
|
+
},
|
|
76
|
+
]));
|
|
77
|
+
const a2a = ctx.get('a2a'), members = ctx.get('members'), topics = ctx.get('topics');
|
|
78
|
+
const messages = ctx.get('messages'), history = messages.forMember(OWNER_ID);
|
|
79
|
+
const notices = ctx.get('notices'), entry = ctx.get('entry'), i18n = ctx.get('i18n');
|
|
80
|
+
ctx.effect(i18n.register(id, packs));
|
|
81
|
+
ctx.effect(ctx.get('push').forward('recovery.changed'));
|
|
82
|
+
ctx.on('config.changed', ({ scope }) => { if (scope === 'plugin:recovery')
|
|
83
|
+
plugin.reload(); });
|
|
84
|
+
const settings = plugin.config.all();
|
|
85
|
+
const endpoints = parseEndpoints(Array.isArray(settings.endpoints) ? settings.endpoints : []);
|
|
86
|
+
const detects = settings.autoRetry === true && endpoints.length > 0;
|
|
87
|
+
const timeoutMs = Math.trunc(1000 * Math.min(60, Math.max(1, Number(settings.probeTimeoutSeconds) || 1)));
|
|
88
|
+
const maxRetries = Math.max(0, Math.floor(Number(settings.maxAutoRetries) || 0));
|
|
89
|
+
const file = home.path('plugins', id, 'pending.json');
|
|
90
|
+
const empty = { outage: false, lastProbeAt: null, items: [], retryCounts: {} };
|
|
91
|
+
const saved = home.checkOnly ? empty : readJson(file, empty);
|
|
92
|
+
const pending = new Map(saved.items.map((item) => [item.replyId, item]));
|
|
93
|
+
const retryCounts = new Map(Object.entries(saved.retryCounts));
|
|
94
|
+
const candidates = new Map();
|
|
95
|
+
let { outage, lastProbeAt, outageDismissed = false } = saved;
|
|
96
|
+
let nextProbeAt = null;
|
|
97
|
+
let step = 0, poll;
|
|
98
|
+
let checking;
|
|
99
|
+
let dispatching;
|
|
100
|
+
let stopped = false;
|
|
101
|
+
ctx.provide('recovery', {
|
|
102
|
+
waiting: (replyId, turnId) => (pending.get(replyId) ?? candidates.get(replyId))?.turnId === turnId,
|
|
103
|
+
});
|
|
104
|
+
const save = () => {
|
|
105
|
+
if (home.checkOnly)
|
|
106
|
+
return;
|
|
107
|
+
writeDocuments(home, [{ path: file, value: {
|
|
108
|
+
outage, ...(outageDismissed ? { outageDismissed: true } : {}), lastProbeAt, items: [...pending.values()], retryCounts: Object.fromEntries(retryCounts),
|
|
109
|
+
} }]);
|
|
110
|
+
ctx.runtime.emit('recovery.changed', {});
|
|
111
|
+
};
|
|
112
|
+
const status = (viewerId = OWNER_ID) => {
|
|
113
|
+
const visible = messages.forMember(viewerId);
|
|
114
|
+
return { outage, lastProbeAt, nextProbeAt, items: [...pending.values()].filter((item) => visible.get(item.replyId)) };
|
|
115
|
+
};
|
|
116
|
+
const mayRetry = (replyId) => detects && (retryCounts.get(replyId) ?? 0) < maxRetries;
|
|
117
|
+
const failedReply = (replyId) => {
|
|
118
|
+
const reply = history.get(replyId);
|
|
119
|
+
if (reply?.from.kind !== 'member' || reply.terminal?.status !== 'failed')
|
|
120
|
+
return;
|
|
121
|
+
const topic = topics.get(reply.topicId), member = members.get(reply.from.id);
|
|
122
|
+
if (!topic || topic.archivedAt !== null || topic.deletedAt !== null || !member?.enabled || !a2a.worksIn(topic.id, member.id))
|
|
123
|
+
return;
|
|
124
|
+
return reply;
|
|
125
|
+
};
|
|
126
|
+
const hasQueuedRetry = (topicId, replyId, turnId) => a2a.queuedRetries(topicId, OWNER_ID).some((retry) => retry.replyId === replyId && retry.turnId === turnId);
|
|
127
|
+
const current = (item) => failedReply(item.replyId)?.turnId === item.turnId
|
|
128
|
+
&& a2a.turns(item.topicId, { turnId: item.turnId })[0]?.failure === 'network';
|
|
129
|
+
const action = (key, path, body) => {
|
|
130
|
+
const labelI18n = ltext(id + '.' + key);
|
|
131
|
+
return { label: i18n.render(labelI18n), labelI18n, method: 'POST', path, ...(body ? { body } : {}) };
|
|
132
|
+
};
|
|
133
|
+
const individual = (item) => {
|
|
134
|
+
const i18nText = item.reason ? ltext(id + '.reason', { reason: item.reason }) : ltext(id + '.failure');
|
|
135
|
+
const path = '/api/topics/' + encodeURIComponent(item.topicId) + '/turns/' + encodeURIComponent(item.replyId) + '/retry';
|
|
136
|
+
notices.add({
|
|
137
|
+
key: failureKey(item.replyId), from: { kind: 'member', id: item.memberId },
|
|
138
|
+
text: i18n.render(i18nText), i18n: i18nText, open: address.message(item.topicId, item.replyId),
|
|
139
|
+
actions: [action('retry', path, { turnId: item.turnId })],
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
const outageActions = [action('probe', api + '/probe'), action('retryAll', api + '/retry-all'), action('cancel', api + '/cancel')];
|
|
143
|
+
const showOutage = () => {
|
|
144
|
+
if (outageDismissed)
|
|
145
|
+
return;
|
|
146
|
+
const links = [...pending.values()].map(({ topicId, memberId, replyId }) => {
|
|
147
|
+
const label = [topics.get(topicId)?.title ?? topicId, members.get(memberId)?.name ?? memberId].join(' · ');
|
|
148
|
+
return '- [' + markdownLabel(label) + '](#' + address.message(topicId, replyId) + ')';
|
|
149
|
+
}).join('\n');
|
|
150
|
+
const i18nText = ljoin([
|
|
151
|
+
ltext(outageKey, { count: pending.size }),
|
|
152
|
+
links,
|
|
153
|
+
nextProbeAt === null ? ltext(id + '.checking') : ltext(id + '.next', { time: time.format(nextProbeAt) }),
|
|
154
|
+
], '\n\n');
|
|
155
|
+
const text = i18n.render(i18nText);
|
|
156
|
+
if (notices.list().find((notice) => notice.key === outageKey)?.text === text)
|
|
157
|
+
return;
|
|
158
|
+
notices.add({ key: outageKey, from: { kind: 'system', id }, text, i18n: i18nText, actions: outageActions });
|
|
159
|
+
};
|
|
160
|
+
const clearPoll = () => {
|
|
161
|
+
clearTimeout(poll);
|
|
162
|
+
poll = undefined;
|
|
163
|
+
nextProbeAt = null;
|
|
164
|
+
};
|
|
165
|
+
const leaveOutage = () => {
|
|
166
|
+
outage = false;
|
|
167
|
+
outageDismissed = false;
|
|
168
|
+
step = 0;
|
|
169
|
+
clearPoll();
|
|
170
|
+
notices.removeKey(outageKey);
|
|
171
|
+
};
|
|
172
|
+
const persistPending = () => {
|
|
173
|
+
if (!pending.size)
|
|
174
|
+
leaveOutage();
|
|
175
|
+
save();
|
|
176
|
+
if (outage)
|
|
177
|
+
showOutage();
|
|
178
|
+
};
|
|
179
|
+
const abortProbe = () => {
|
|
180
|
+
checking?.control.abort();
|
|
181
|
+
checking = undefined;
|
|
182
|
+
};
|
|
183
|
+
const forget = (replyId, removeCount) => {
|
|
184
|
+
const probing = candidates.delete(replyId);
|
|
185
|
+
notices.removeKey(failureKey(replyId));
|
|
186
|
+
const removed = pending.delete(replyId);
|
|
187
|
+
const cleared = removeCount && retryCounts.delete(replyId);
|
|
188
|
+
if (removed || cleared)
|
|
189
|
+
persistPending();
|
|
190
|
+
else if (probing)
|
|
191
|
+
ctx.runtime.emit('recovery.changed', {});
|
|
192
|
+
};
|
|
193
|
+
const prune = () => {
|
|
194
|
+
let changed = false;
|
|
195
|
+
for (const [replyId, item] of candidates)
|
|
196
|
+
if (!current(item))
|
|
197
|
+
candidates.delete(replyId);
|
|
198
|
+
for (const [replyId, item] of pending) {
|
|
199
|
+
if (!current(item)) {
|
|
200
|
+
pending.delete(replyId);
|
|
201
|
+
changed = true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
for (const notice of notices.list()) {
|
|
205
|
+
if (!notice.key?.startsWith(failPrefix))
|
|
206
|
+
continue;
|
|
207
|
+
const reply = failedReply(notice.key.slice(failPrefix.length));
|
|
208
|
+
if (!reply?.turnId || reply.turnId !== notice.actions?.[0]?.body?.turnId || hasQueuedRetry(reply.topicId, reply.id, reply.turnId)) {
|
|
209
|
+
notices.removeKey(notice.key);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (changed)
|
|
213
|
+
persistPending();
|
|
214
|
+
};
|
|
215
|
+
const background = (task) => {
|
|
216
|
+
void task.catch((error) => log(id, errorText(error)));
|
|
217
|
+
};
|
|
218
|
+
const schedule = (delay) => {
|
|
219
|
+
nextProbeAt = Date.now() + delay;
|
|
220
|
+
poll = setTimeout(() => {
|
|
221
|
+
poll = undefined;
|
|
222
|
+
background(check());
|
|
223
|
+
}, delay).unref();
|
|
224
|
+
};
|
|
225
|
+
const retryAll = () => {
|
|
226
|
+
if (dispatching)
|
|
227
|
+
return dispatching.task;
|
|
228
|
+
if (!pending.size || stopped || home.checkOnly)
|
|
229
|
+
return Promise.resolve();
|
|
230
|
+
abortProbe();
|
|
231
|
+
leaveOutage();
|
|
232
|
+
save();
|
|
233
|
+
const groups = new Map();
|
|
234
|
+
for (const item of [...pending.values()].sort((a, b) => a.failedAt - b.failedAt)) {
|
|
235
|
+
const pair = item.topicId + ':' + item.memberId;
|
|
236
|
+
const group = groups.get(pair) ?? [];
|
|
237
|
+
group.push(item);
|
|
238
|
+
groups.set(pair, group);
|
|
239
|
+
}
|
|
240
|
+
const control = new AbortController(), { signal } = control;
|
|
241
|
+
const task = Promise.resolve().then(async () => {
|
|
242
|
+
for (const [index, group] of [...groups.values()].entries()) {
|
|
243
|
+
if (index > 0)
|
|
244
|
+
await wait(staggerMs, undefined, { signal, ref: false });
|
|
245
|
+
if (signal.aborted)
|
|
246
|
+
return;
|
|
247
|
+
for (const item of group) {
|
|
248
|
+
if (pending.get(item.replyId) !== item)
|
|
249
|
+
continue;
|
|
250
|
+
if (current(item)) {
|
|
251
|
+
try {
|
|
252
|
+
a2a.retry(item.topicId, item.replyId, item.turnId);
|
|
253
|
+
retryCounts.set(item.replyId, (retryCounts.get(item.replyId) ?? 0) + 1);
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
log(id, 'could not retry ' + item.replyId, errorText(error));
|
|
257
|
+
if (current(item))
|
|
258
|
+
individual(item);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
pending.delete(item.replyId);
|
|
262
|
+
save();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}).catch((error) => {
|
|
266
|
+
if (!signal.aborted)
|
|
267
|
+
throw error;
|
|
268
|
+
}).finally(() => {
|
|
269
|
+
if (dispatching?.control !== control)
|
|
270
|
+
return;
|
|
271
|
+
dispatching = undefined;
|
|
272
|
+
if (!stopped && candidates.size)
|
|
273
|
+
background(check());
|
|
274
|
+
});
|
|
275
|
+
dispatching = { control, task };
|
|
276
|
+
return task;
|
|
277
|
+
};
|
|
278
|
+
const check = () => {
|
|
279
|
+
if (checking)
|
|
280
|
+
return checking.task;
|
|
281
|
+
if (!endpoints.length || dispatching || stopped || home.checkOnly)
|
|
282
|
+
return Promise.resolve(null);
|
|
283
|
+
clearPoll();
|
|
284
|
+
const control = new AbortController(), { signal } = control;
|
|
285
|
+
const task = Promise.resolve().then(() => probe({ endpoints, timeoutMs, homeEnv: home.env, signal })).then((reachable) => {
|
|
286
|
+
if (signal.aborted)
|
|
287
|
+
return null;
|
|
288
|
+
lastProbeAt = Date.now();
|
|
289
|
+
for (const item of candidates.values()) {
|
|
290
|
+
if (!current(item))
|
|
291
|
+
continue;
|
|
292
|
+
if (pending.get(item.replyId)?.turnId !== item.turnId)
|
|
293
|
+
outageDismissed = false;
|
|
294
|
+
pending.set(item.replyId, item);
|
|
295
|
+
}
|
|
296
|
+
candidates.clear();
|
|
297
|
+
if (reachable) {
|
|
298
|
+
if (pending.size)
|
|
299
|
+
background(retryAll());
|
|
300
|
+
else
|
|
301
|
+
save();
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
outage = pending.size > 0;
|
|
305
|
+
if (outage)
|
|
306
|
+
schedule(backoffMs[Math.min(step++, backoffMs.length - 1)]);
|
|
307
|
+
persistPending();
|
|
308
|
+
}
|
|
309
|
+
return reachable;
|
|
310
|
+
}).finally(() => {
|
|
311
|
+
if (checking?.control !== control)
|
|
312
|
+
return;
|
|
313
|
+
checking = undefined;
|
|
314
|
+
if (outage && !poll) {
|
|
315
|
+
schedule(backoffMs[Math.min(step++, backoffMs.length - 1)]);
|
|
316
|
+
showOutage();
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
checking = { control, task };
|
|
320
|
+
if (outage)
|
|
321
|
+
showOutage();
|
|
322
|
+
return task;
|
|
323
|
+
};
|
|
324
|
+
const cancel = () => {
|
|
325
|
+
if (home.checkOnly)
|
|
326
|
+
return;
|
|
327
|
+
abortProbe();
|
|
328
|
+
dispatching?.control.abort();
|
|
329
|
+
dispatching = undefined;
|
|
330
|
+
candidates.clear();
|
|
331
|
+
leaveOutage();
|
|
332
|
+
for (const item of pending.values())
|
|
333
|
+
if (current(item))
|
|
334
|
+
individual(item);
|
|
335
|
+
pending.clear();
|
|
336
|
+
save();
|
|
337
|
+
};
|
|
338
|
+
const stop = () => {
|
|
339
|
+
if (stopped)
|
|
340
|
+
return;
|
|
341
|
+
stopped = true;
|
|
342
|
+
clearPoll();
|
|
343
|
+
abortProbe();
|
|
344
|
+
dispatching?.control.abort();
|
|
345
|
+
if (!home.checkOnly)
|
|
346
|
+
notices.removeKey(outageKey);
|
|
347
|
+
};
|
|
348
|
+
ctx.on('host.stopping', stop);
|
|
349
|
+
ctx.effect(stop);
|
|
350
|
+
ctx.effect(entry.group(id, '异常失败与网络恢复'));
|
|
351
|
+
ctx.effect(entry.op({
|
|
352
|
+
name: 'recovery.status', about: '查看网络恢复与等待重试的回复。',
|
|
353
|
+
http: ['GET', api], agent: true, run: (_args, caller) => status(caller.member?.id),
|
|
354
|
+
}));
|
|
355
|
+
ctx.effect(entry.op({
|
|
356
|
+
name: 'recovery.probe', about: '立即检测配置中的网络探测地址。',
|
|
357
|
+
http: ['POST', api + '/probe'], run: async () => ({ reachable: await check(), ...status() }),
|
|
358
|
+
}));
|
|
359
|
+
ctx.effect(entry.op({
|
|
360
|
+
name: 'recovery.retry_all', about: '原位重试等待恢复的回复。',
|
|
361
|
+
http: ['POST', api + '/retry-all'], run: async () => { await retryAll(); return status(); },
|
|
362
|
+
}));
|
|
363
|
+
ctx.effect(entry.op({
|
|
364
|
+
name: 'recovery.cancel', about: '停止等待网络恢复,将回复恢复为单条失败提醒。',
|
|
365
|
+
http: ['POST', api + '/cancel'], run: () => { cancel(); return status(); },
|
|
366
|
+
}));
|
|
367
|
+
if (home.checkOnly)
|
|
368
|
+
return;
|
|
369
|
+
ctx.note('turn.ended', {
|
|
370
|
+
title: '网络失败后探测并原位重试,未分类失败直接推送收件箱提醒',
|
|
371
|
+
when: '回合失败时(网络失败或未分类失败)',
|
|
372
|
+
});
|
|
373
|
+
ctx.on('turn.ended', ({ turn, message, discardedReplyId }) => {
|
|
374
|
+
if (stopped)
|
|
375
|
+
return;
|
|
376
|
+
if (turn.status === 'completed') {
|
|
377
|
+
forget(turn.replyId, true);
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
if (turn.status !== 'failed' || !message || message.seq === null || discardedReplyId)
|
|
381
|
+
return;
|
|
382
|
+
const item = {
|
|
383
|
+
topicId: turn.topicId, memberId: turn.memberId, replyId: turn.replyId, turnId: turn.id,
|
|
384
|
+
failedAt: turn.endedAt ?? Date.now(), reason: turn.error,
|
|
385
|
+
};
|
|
386
|
+
if (turn.failure === undefined) {
|
|
387
|
+
if (failedReply(item.replyId)?.turnId !== item.turnId)
|
|
388
|
+
return;
|
|
389
|
+
individual(item);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
if (turn.failure !== 'network' || !current(item))
|
|
393
|
+
return;
|
|
394
|
+
const eligible = mayRetry(item.replyId);
|
|
395
|
+
if (outage && eligible) {
|
|
396
|
+
if (pending.get(item.replyId)?.turnId !== item.turnId)
|
|
397
|
+
outageDismissed = false;
|
|
398
|
+
pending.set(item.replyId, item);
|
|
399
|
+
persistPending();
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (eligible) {
|
|
403
|
+
candidates.set(item.replyId, item);
|
|
404
|
+
ctx.runtime.emit('recovery.changed', {});
|
|
405
|
+
}
|
|
406
|
+
if (detects && (eligible || maxRetries === 0) && !dispatching)
|
|
407
|
+
background(check());
|
|
408
|
+
});
|
|
409
|
+
ctx.note('notice.dismissed', { title: '机主删除或清空断网汇总卡时持久化忽略状态,不再随轮询、重载或重启复活', when: '通知是断网汇总卡时' });
|
|
410
|
+
ctx.on('notice.dismissed', ({ notices: dismissed }) => {
|
|
411
|
+
if (dismissed.some((notice) => notice.key === outageKey) && !outageDismissed) {
|
|
412
|
+
outageDismissed = true;
|
|
413
|
+
save();
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
ctx.on('turn.retryQueued', ({ replyId }) => forget(replyId, false));
|
|
417
|
+
ctx.on('turn.started', ({ turn }) => forget(turn.messageId, false));
|
|
418
|
+
ctx.on('message.deleted', ({ id: replyId }) => forget(replyId, true));
|
|
419
|
+
ctx.on('members.changed', ({ id: memberId, removed }) => {
|
|
420
|
+
if (removed || !members.get(memberId)?.enabled)
|
|
421
|
+
prune();
|
|
422
|
+
});
|
|
423
|
+
const rosters = new Map(topics.all().map((topic) => [topic.id, topic.members]));
|
|
424
|
+
ctx.on('topic.updated', ({ topic }) => {
|
|
425
|
+
const previous = rosters.get(topic.id);
|
|
426
|
+
rosters.set(topic.id, topic.members);
|
|
427
|
+
if (topic.deletedAt !== null || topic.archivedAt !== null || previous !== topic.members)
|
|
428
|
+
prune();
|
|
429
|
+
});
|
|
430
|
+
const restore = () => {
|
|
431
|
+
prune();
|
|
432
|
+
for (const [replyId, item] of pending) {
|
|
433
|
+
if (mayRetry(replyId))
|
|
434
|
+
continue;
|
|
435
|
+
individual(item);
|
|
436
|
+
pending.delete(replyId);
|
|
437
|
+
}
|
|
438
|
+
if (pending.size) {
|
|
439
|
+
if (outage)
|
|
440
|
+
schedule(Math.min(1000, backoffMs[0]));
|
|
441
|
+
else
|
|
442
|
+
background(retryAll());
|
|
443
|
+
}
|
|
444
|
+
if (saved.items.length || saved.outage)
|
|
445
|
+
persistPending();
|
|
446
|
+
};
|
|
447
|
+
if (ctx.runtime.ready)
|
|
448
|
+
restore();
|
|
449
|
+
else
|
|
450
|
+
ctx.hook('host.ready', restore);
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
export default recoveryPlugin;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
pluginId: recovery
|
|
2
|
+
foundation: true
|
|
3
|
+
console: console/
|
|
4
|
+
name: 异常恢复
|
|
5
|
+
description:
|
|
6
|
+
default: 提醒未分类的回复失败,并在网络失败时探测汇总、恢复后原位重试。
|
|
7
|
+
translations:
|
|
8
|
+
zh: 提醒未分类的回复失败,并在网络失败时探测汇总、恢复后原位重试。
|
|
9
|
+
en: Alert on unclassified reply failures, and probe connectivity to retry network failures in place when it returns.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
2
|
+
export interface ProbeInput {
|
|
3
|
+
endpoints: readonly URL[];
|
|
4
|
+
timeoutMs: number;
|
|
5
|
+
homeEnv: Env;
|
|
6
|
+
signal: AbortSignal;
|
|
7
|
+
}
|
|
8
|
+
export declare function parseEndpoints(values: readonly unknown[]): URL[];
|
|
9
|
+
/** Resolve on the first usable source. Individual timeouts cover DNS, CONNECT and TLS as well as HEAD. */
|
|
10
|
+
export declare function networkReachable({ endpoints, timeoutMs, homeEnv, signal }: ProbeInput): Promise<boolean>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { once } from 'node:events';
|
|
2
|
+
import { request as httpRequest } from 'node:http';
|
|
3
|
+
import { request as httpsRequest } from 'node:https';
|
|
4
|
+
import { isIP } from 'node:net';
|
|
5
|
+
import { connect as tlsConnect } from 'node:tls';
|
|
6
|
+
function httpUrl(value) {
|
|
7
|
+
const url = new URL(value);
|
|
8
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:')
|
|
9
|
+
throw new Error('Expected an HTTP or HTTPS URL');
|
|
10
|
+
return url;
|
|
11
|
+
}
|
|
12
|
+
export function parseEndpoints(values) {
|
|
13
|
+
const endpoints = new Map();
|
|
14
|
+
for (const value of values) {
|
|
15
|
+
if (typeof value !== 'string')
|
|
16
|
+
continue;
|
|
17
|
+
try {
|
|
18
|
+
const url = httpUrl(value.trim());
|
|
19
|
+
url.hash = '';
|
|
20
|
+
endpoints.set(url.href, url);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// The list field accepts strings. Only URLs the probe can request count as sources.
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return [...endpoints.values()];
|
|
27
|
+
}
|
|
28
|
+
const defaultPort = (url) => url.protocol === 'https:' ? '443' : '80';
|
|
29
|
+
const hostname = (value) => value.toLowerCase().replace(/^\[|\]$|\.$/g, '');
|
|
30
|
+
function bypassProxy(url, noProxy) {
|
|
31
|
+
const host = hostname(url.hostname), port = url.port || defaultPort(url);
|
|
32
|
+
return noProxy.split(/[\s,]+/).filter(Boolean).some((rule) => {
|
|
33
|
+
if (rule === '*')
|
|
34
|
+
return true;
|
|
35
|
+
const withPort = /^(\[[^\]]+\]|[^:]+):(\d+)$/.exec(rule);
|
|
36
|
+
if (withPort && Number(withPort[2]) !== Number(port))
|
|
37
|
+
return false;
|
|
38
|
+
const pattern = hostname(withPort?.[1] ?? rule);
|
|
39
|
+
if (!pattern.startsWith('.') && !pattern.startsWith('*.'))
|
|
40
|
+
return pattern === host;
|
|
41
|
+
const suffix = pattern.replace(/^\*?\./, '');
|
|
42
|
+
return host === suffix || host.endsWith('.' + suffix);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function proxyFor(target, homeEnv) {
|
|
46
|
+
const value = (key) => {
|
|
47
|
+
const lower = key.toLowerCase();
|
|
48
|
+
return (process.env[key] ?? process.env[lower] ?? homeEnv[key] ?? homeEnv[lower])?.trim();
|
|
49
|
+
};
|
|
50
|
+
if (bypassProxy(target, value('NO_PROXY') ?? ''))
|
|
51
|
+
return;
|
|
52
|
+
const http = value('HTTP_PROXY');
|
|
53
|
+
const selected = target.protocol === 'https:' ? value('HTTPS_PROXY') ?? http : http;
|
|
54
|
+
if (!selected)
|
|
55
|
+
return;
|
|
56
|
+
const url = httpUrl(selected);
|
|
57
|
+
const auth = url.username || url.password
|
|
58
|
+
? 'Basic ' + Buffer.from(decodeURIComponent(url.username) + ':' + decodeURIComponent(url.password)).toString('base64')
|
|
59
|
+
: undefined;
|
|
60
|
+
url.username = '';
|
|
61
|
+
url.password = '';
|
|
62
|
+
return { url, auth };
|
|
63
|
+
}
|
|
64
|
+
const transport = (url) => url.protocol === 'https:' ? httpsRequest : httpRequest;
|
|
65
|
+
function head(url, signal, options = {}) {
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
const request = transport(url)(url, { method: 'HEAD', agent: false, signal, ...options }, (response) => {
|
|
68
|
+
response.destroy();
|
|
69
|
+
resolve();
|
|
70
|
+
});
|
|
71
|
+
request.once('error', reject);
|
|
72
|
+
request.end();
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function tunnel(proxy, authority, headers, signal) {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
const request = transport(proxy)(proxy, {
|
|
78
|
+
method: 'CONNECT', path: authority, headers: { ...headers, Host: authority }, agent: false, signal,
|
|
79
|
+
});
|
|
80
|
+
request.once('connect', (response, socket, buffered) => {
|
|
81
|
+
const status = response.statusCode ?? 0;
|
|
82
|
+
if (status < 200 || status >= 300) {
|
|
83
|
+
socket.destroy();
|
|
84
|
+
reject(new Error('Proxy refused the tunnel'));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (buffered.length)
|
|
88
|
+
socket.unshift(buffered);
|
|
89
|
+
resolve(socket);
|
|
90
|
+
});
|
|
91
|
+
request.once('error', reject);
|
|
92
|
+
request.end();
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async function probeTarget(target, homeEnv, signal) {
|
|
96
|
+
const proxy = proxyFor(target, homeEnv);
|
|
97
|
+
if (!proxy)
|
|
98
|
+
return head(target, signal);
|
|
99
|
+
const headers = proxy.auth ? { 'Proxy-Authorization': proxy.auth } : {};
|
|
100
|
+
if (target.protocol === 'http:') {
|
|
101
|
+
return head(proxy.url, signal, { path: target.origin + target.pathname + target.search, headers: { ...headers, Host: target.host } });
|
|
102
|
+
}
|
|
103
|
+
const socket = await tunnel(proxy.url, target.hostname + ':' + (target.port || defaultPort(target)), headers, signal);
|
|
104
|
+
const host = hostname(target.hostname);
|
|
105
|
+
const secure = tlsConnect({ socket, host, servername: isIP(host) ? undefined : host });
|
|
106
|
+
try {
|
|
107
|
+
await once(secure, 'secureConnect', { signal });
|
|
108
|
+
// The TLS socket already traverses the proxy. Supplying it bypasses the global agent.
|
|
109
|
+
await head(target, signal, { agent: undefined, createConnection: () => secure });
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
secure.destroy();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** Resolve on the first usable source. Individual timeouts cover DNS, CONNECT and TLS as well as HEAD. */
|
|
116
|
+
export async function networkReachable({ endpoints, timeoutMs, homeEnv, signal }) {
|
|
117
|
+
const remaining = new AbortController();
|
|
118
|
+
try {
|
|
119
|
+
await Promise.any(endpoints.map((target) => probeTarget(target, homeEnv, AbortSignal.any([signal, remaining.signal, AbortSignal.timeout(timeoutMs)]))));
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
remaining.abort();
|
|
127
|
+
}
|
|
128
|
+
}
|