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,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything that can be referred to has an address: the part after `#` in the console's address bar. Whoever
|
|
3
|
+
* points at something (a notice, a row on a topic's page, a member writing to a person) uses these and nothing
|
|
4
|
+
* else, and the console goes there inside the page. The rule is written here once: the functions make addresses,
|
|
5
|
+
* the text tells members how to write them.
|
|
6
|
+
*/
|
|
7
|
+
export declare const address: {
|
|
8
|
+
topic: (topicId: string) => string;
|
|
9
|
+
message: (topicId: string, messageId: string) => string;
|
|
10
|
+
/** The address of a page. */
|
|
11
|
+
page: (name: string) => string;
|
|
12
|
+
/** An item on a page. */
|
|
13
|
+
item: (kind: string, name: string) => string;
|
|
14
|
+
};
|
|
15
|
+
declare module '../runtime/runtime.ts' {
|
|
16
|
+
interface Events {
|
|
17
|
+
/** The displayed name of these addresses changed; only the plugin that owns them says so. */
|
|
18
|
+
'address.changed': {
|
|
19
|
+
addresses: string[];
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
interface Hooks {
|
|
23
|
+
/** A short plain-text label for each requested address the reader can see. */
|
|
24
|
+
'address.labels': [{
|
|
25
|
+
addresses: ReadonlySet<string>;
|
|
26
|
+
memberId: string;
|
|
27
|
+
}, Record<string, string>];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export declare function addressRules(): string;
|
|
31
|
+
/** A Markdown link to an in-app address that fits on one list line. */
|
|
32
|
+
export declare function addressLink(target: string, title: string): string;
|
|
33
|
+
/** A topic link that fits on one Markdown list line. */
|
|
34
|
+
export declare function topicLink(topicId: string, title: string): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything that can be referred to has an address: the part after `#` in the console's address bar. Whoever
|
|
3
|
+
* points at something (a notice, a row on a topic's page, a member writing to a person) uses these and nothing
|
|
4
|
+
* else, and the console goes there inside the page. The rule is written here once: the functions make addresses,
|
|
5
|
+
* the text tells members how to write them.
|
|
6
|
+
*/
|
|
7
|
+
export const address = {
|
|
8
|
+
topic: (topicId) => `chat-${topicId}`,
|
|
9
|
+
message: (topicId, messageId) => `chat-${topicId}/${messageId}`,
|
|
10
|
+
/** The address of a page. */
|
|
11
|
+
page: (name) => name,
|
|
12
|
+
/** An item on a page. */
|
|
13
|
+
item: (kind, name) => `${kind}/${encodeURIComponent(name)}`,
|
|
14
|
+
};
|
|
15
|
+
export function addressRules() {
|
|
16
|
+
return [
|
|
17
|
+
'平台里的地址可以直接跳到对应的内容。',
|
|
18
|
+
'- 用 `#chat-<主题编号>` 打开主题,用 `#chat-<主题编号>/<消息编号>` 打开一条消息。编号可从主题说明和消息历史里查看。',
|
|
19
|
+
'- 用 `res:topic/<主题编号>/<路径>`、`res:ref/<引用编号>/<路径>` 或 `res:work/<主题编号>/<产物编号>` 打开主题文档、引用目录文件或产物。',
|
|
20
|
+
'- 用 `#trash` 打开垃圾桶,查看、恢复或清理已删除的主题。',
|
|
21
|
+
'- 用 `#<页面名>` 打开设置页,用 `#<页面名>/<条目名>` 打开其中一项。',
|
|
22
|
+
'在回复里可写成链接 `[说它是什么](#chat-top_xxx/msg_yyy)`。请使用实际看到的编号。',
|
|
23
|
+
].join('\n');
|
|
24
|
+
}
|
|
25
|
+
/** A Markdown link to an in-app address that fits on one list line. */
|
|
26
|
+
export function addressLink(target, title) {
|
|
27
|
+
const label = title.replaceAll('[', '[').replaceAll(']', ']').replace(/\s+/g, ' ').trim();
|
|
28
|
+
return `[${label}](#${target})`;
|
|
29
|
+
}
|
|
30
|
+
/** A topic link that fits on one Markdown list line. */
|
|
31
|
+
export function topicLink(topicId, title) {
|
|
32
|
+
return addressLink(address.topic(topicId), title);
|
|
33
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Schema } from './ops.ts';
|
|
2
|
+
import type { FillRequest } from './types.ts';
|
|
3
|
+
/** Rebuild just this operation's input schema for a proposal or its owner submission.
|
|
4
|
+
* The stored step always contains the original, public arguments. */
|
|
5
|
+
export declare function prepareInputs(schema: Schema, raw: unknown, requested: readonly FillRequest[], topic: string | undefined, dynamic: ((keys: string[]) => Schema | undefined) | undefined, values?: Record<string, string>): {
|
|
6
|
+
args: Record<string, unknown>;
|
|
7
|
+
schema: Schema;
|
|
8
|
+
inputs: ({
|
|
9
|
+
secret: boolean;
|
|
10
|
+
path: string;
|
|
11
|
+
label: string;
|
|
12
|
+
required: boolean;
|
|
13
|
+
} & {
|
|
14
|
+
format?: "key-value-lines" | undefined;
|
|
15
|
+
description?: string | undefined;
|
|
16
|
+
})[];
|
|
17
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ArgsError } from "./entry.js";
|
|
2
|
+
/** Rebuild just this operation's input schema for a proposal or its owner submission.
|
|
3
|
+
* The stored step always contains the original, public arguments. */
|
|
4
|
+
export function prepareInputs(schema, raw, requested, topic, dynamic, values) {
|
|
5
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
6
|
+
throw new ArgsError('操作参数须为对象');
|
|
7
|
+
const args = structuredClone(raw);
|
|
8
|
+
const projected = structuredClone(schema);
|
|
9
|
+
const inputs = [];
|
|
10
|
+
const paths = new Set();
|
|
11
|
+
for (const request of requested) {
|
|
12
|
+
const { path } = request;
|
|
13
|
+
if (!path.startsWith('/') || /~(?![01])/.test(path))
|
|
14
|
+
throw new ArgsError('补填路径使用 JSON Pointer,例如 /env');
|
|
15
|
+
const keys = path.slice(1).split('/').map((key) => key.replaceAll('~1', '/').replaceAll('~0', '~'));
|
|
16
|
+
if (keys[0] === topic || keys.some((key) => !key || ['__proto__', 'prototype', 'constructor'].includes(key))) {
|
|
17
|
+
throw new ArgsError('这条路径不能用于补填');
|
|
18
|
+
}
|
|
19
|
+
if (paths.has(path))
|
|
20
|
+
throw new ArgsError(`重复的补填字段 ${path}`);
|
|
21
|
+
paths.add(path);
|
|
22
|
+
let parent = projected;
|
|
23
|
+
let data = args;
|
|
24
|
+
for (const key of keys.slice(0, -1)) {
|
|
25
|
+
const child = parent.properties?.[key];
|
|
26
|
+
if (child?.type !== 'object' || child.secret)
|
|
27
|
+
throw new ArgsError(`不是声明的对象字段:${path}`);
|
|
28
|
+
if (!Object.hasOwn(data, key))
|
|
29
|
+
data[key] = {};
|
|
30
|
+
const next = data[key];
|
|
31
|
+
if (!next || typeof next !== 'object' || Array.isArray(next))
|
|
32
|
+
throw new ArgsError(`补填路径的上级不是对象:${path}`);
|
|
33
|
+
data = next;
|
|
34
|
+
parent = child;
|
|
35
|
+
}
|
|
36
|
+
const key = keys.at(-1);
|
|
37
|
+
const field = parent.properties?.[key] ?? dynamic?.(keys);
|
|
38
|
+
if (field?.type !== 'string' || field.member)
|
|
39
|
+
throw new ArgsError(`只能补填操作声明的文本或密钥字段:${path}`);
|
|
40
|
+
if (Object.hasOwn(data, key))
|
|
41
|
+
throw new ArgsError(`${path} 已经预填`);
|
|
42
|
+
const input = {
|
|
43
|
+
path, label: request.label?.trim() || field.title || key,
|
|
44
|
+
description: request.description?.trim() || field.description,
|
|
45
|
+
required: !!(request.required || parent.required?.includes(key)), secret: !!field.secret,
|
|
46
|
+
...(field.format === 'key-value-lines' && { format: 'key-value-lines' }),
|
|
47
|
+
};
|
|
48
|
+
inputs.push(input);
|
|
49
|
+
parent.properties = { ...parent.properties, [key]: field };
|
|
50
|
+
if (values === undefined) {
|
|
51
|
+
parent.required = parent.required?.filter((one) => one !== key);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if ('secret' in request && (request.secret !== input.secret || ('format' in request ? request.format : undefined) !== input.format)) {
|
|
55
|
+
throw new ArgsError(`${path} 的声明已变化,请重新提请`);
|
|
56
|
+
}
|
|
57
|
+
const value = Object.hasOwn(values, path) ? values[path] : undefined;
|
|
58
|
+
if (value === undefined || !value.trim()) {
|
|
59
|
+
if (input.required)
|
|
60
|
+
throw new ArgsError(`请填写「${input.label}」`);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
data[key] = value;
|
|
64
|
+
// All other fields retain their member-facing secret check.
|
|
65
|
+
parent.properties[key] = { ...field, secret: undefined };
|
|
66
|
+
}
|
|
67
|
+
if (values && Object.keys(values).some((key) => !paths.has(key)))
|
|
68
|
+
throw new ArgsError('提交含有卡上未声明的字段');
|
|
69
|
+
return { args, schema: projected, inputs };
|
|
70
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HttpError } from './entry.ts';
|
|
2
|
+
export declare const PLUGIN_ARCHIVE_LIMIT: number;
|
|
3
|
+
type Invalid = (message: string) => HttpError;
|
|
4
|
+
export declare function archivePath(name: string, invalid: Invalid): string[];
|
|
5
|
+
export declare const archiveMetadata: (parts: string[]) => boolean | undefined;
|
|
6
|
+
export declare function stripArchiveRoot<T extends {
|
|
7
|
+
parts: string[];
|
|
8
|
+
directory: boolean;
|
|
9
|
+
}>(entries: T[]): T[];
|
|
10
|
+
interface TarOptions {
|
|
11
|
+
label: string;
|
|
12
|
+
maxOutput: number;
|
|
13
|
+
maxEntries?: number;
|
|
14
|
+
skip?: (parts: string[]) => boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Extract a gzip-compressed ustar archive into an empty staging directory. */
|
|
17
|
+
export declare function extractTarGz(archive: Buffer, dir: string, { label, maxOutput, maxEntries, skip }: TarOptions): Promise<void>;
|
|
18
|
+
export declare function extractPluginArchive(archive: Buffer, dir: string): Promise<void>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { promisify } from 'node:util';
|
|
4
|
+
import { gunzip } from 'node:zlib';
|
|
5
|
+
import { isNativeFileName } from '#platform';
|
|
6
|
+
import { HttpError } from "./entry.js";
|
|
7
|
+
export const PLUGIN_ARCHIVE_LIMIT = 50 * 1024 * 1024;
|
|
8
|
+
const EXTRACTED_LIMIT = 256 * 1024 * 1024;
|
|
9
|
+
const BLOCK = 512;
|
|
10
|
+
const unzip = promisify(gunzip);
|
|
11
|
+
export function archivePath(name, invalid) {
|
|
12
|
+
const parts = name.split('/').filter((part) => part && part !== '.');
|
|
13
|
+
if (name.startsWith('/') || /[\\\p{Cc}]/u.test(name) ||
|
|
14
|
+
parts.some((part) => part === '..' || /^[A-Za-z]:/.test(part) || !isNativeFileName(part, { rejectDeviceNames: true }))) {
|
|
15
|
+
throw invalid(`路径越界或无效:${name}`);
|
|
16
|
+
}
|
|
17
|
+
return parts;
|
|
18
|
+
}
|
|
19
|
+
export const archiveMetadata = (parts) => parts[0] === '__MACOSX' || parts.at(-1)?.startsWith('._');
|
|
20
|
+
export function stripArchiveRoot(entries) {
|
|
21
|
+
const root = entries[0]?.parts[0];
|
|
22
|
+
if (!entries.every(({ parts, directory }) => parts[0] === root && (directory || parts.length > 1)))
|
|
23
|
+
return entries;
|
|
24
|
+
return entries.filter(({ parts }) => parts.length > 1).map((entry) => ({ ...entry, parts: entry.parts.slice(1) }));
|
|
25
|
+
}
|
|
26
|
+
const text = (buffer, start, end) => buffer.toString('utf8', start, end).split('\0', 1)[0];
|
|
27
|
+
function octal(buffer, start, end, invalid) {
|
|
28
|
+
const value = text(buffer, start, end).trim();
|
|
29
|
+
if (!/^[0-7]+$/.test(value))
|
|
30
|
+
throw invalid('tar 数值字段无效');
|
|
31
|
+
return parseInt(value, 8);
|
|
32
|
+
}
|
|
33
|
+
function paxPath(data) {
|
|
34
|
+
for (let offset = 0; offset < data.length;) {
|
|
35
|
+
const space = data.indexOf(32, offset);
|
|
36
|
+
if (space <= offset)
|
|
37
|
+
break;
|
|
38
|
+
const len = parseInt(data.toString('ascii', offset, space), 10);
|
|
39
|
+
if (!Number.isFinite(len) || len <= space - offset + 1 || offset + len > data.length)
|
|
40
|
+
break;
|
|
41
|
+
const record = data.toString('utf8', space + 1, offset + len - 1);
|
|
42
|
+
offset += len;
|
|
43
|
+
if (record.startsWith('path='))
|
|
44
|
+
return record.slice(5);
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
function tarEntries(tar, invalid, maxEntries) {
|
|
49
|
+
const entries = [];
|
|
50
|
+
let nextPath;
|
|
51
|
+
let count = 0;
|
|
52
|
+
for (let offset = 0; offset + BLOCK <= tar.length;) {
|
|
53
|
+
const header = tar.subarray(offset, offset + BLOCK);
|
|
54
|
+
if (header.every((byte) => byte === 0))
|
|
55
|
+
return entries;
|
|
56
|
+
const checksum = header.reduce((sum, byte, i) => sum + (i >= 148 && i < 156 ? 32 : byte), 0);
|
|
57
|
+
if (checksum !== octal(header, 148, 156, invalid))
|
|
58
|
+
throw invalid('tar 文件头校验失败');
|
|
59
|
+
const kind = header[156];
|
|
60
|
+
const size = octal(header, 124, 136, invalid);
|
|
61
|
+
const start = offset + BLOCK;
|
|
62
|
+
offset = start + Math.ceil(size / BLOCK) * BLOCK;
|
|
63
|
+
if (offset > tar.length)
|
|
64
|
+
throw invalid('tar 文件长度无效');
|
|
65
|
+
const body = tar.subarray(start, start + size);
|
|
66
|
+
// PAX ('x'/'g') and GNU LongName ('L') headers are emitted by macOS bsdtar, GNU tar and npm pack.
|
|
67
|
+
if (kind === 103)
|
|
68
|
+
continue;
|
|
69
|
+
if (kind === 120) {
|
|
70
|
+
nextPath = paxPath(body) ?? nextPath;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (kind === 76) {
|
|
74
|
+
nextPath = body.toString('utf8').replace(/\0.*$/s, '');
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (++count > maxEntries)
|
|
78
|
+
throw new HttpError(413, `tar 最多包含 ${maxEntries} 个条目`);
|
|
79
|
+
const directory = kind === 53; // '5' is a directory; '0' or NUL is a regular file.
|
|
80
|
+
if (!directory && kind !== 48 && kind !== 0)
|
|
81
|
+
throw invalid('tar 只支持普通文件和目录,不能包含链接或特殊文件');
|
|
82
|
+
const prefix = header.toString('ascii', 257, 263) === 'ustar\0' ? text(header, 345, 500) : '';
|
|
83
|
+
const filename = text(header, 0, 100);
|
|
84
|
+
const override = nextPath;
|
|
85
|
+
nextPath = undefined;
|
|
86
|
+
const names = override !== undefined ? [override] : [prefix, filename];
|
|
87
|
+
const parts = names.flatMap((name) => archivePath(name, invalid));
|
|
88
|
+
if ((!override && !filename) || (!directory && !parts.length))
|
|
89
|
+
throw invalid('tar 路径为空');
|
|
90
|
+
if (directory && size !== 0)
|
|
91
|
+
throw invalid('tar 文件长度无效');
|
|
92
|
+
if (parts.length && !archiveMetadata(parts))
|
|
93
|
+
entries.push({ parts, directory, mode: 0o644 | (octal(header, 100, 108, invalid) & 0o111), bytes: body });
|
|
94
|
+
}
|
|
95
|
+
throw invalid('tar 文件不完整');
|
|
96
|
+
}
|
|
97
|
+
/** Extract a gzip-compressed ustar archive into an empty staging directory. */
|
|
98
|
+
export async function extractTarGz(archive, dir, { label, maxOutput, maxEntries = Infinity, skip }) {
|
|
99
|
+
const invalid = (message) => new HttpError(400, `${label}:${message}`);
|
|
100
|
+
let tar;
|
|
101
|
+
try {
|
|
102
|
+
tar = await unzip(archive, { maxOutputLength: maxOutput });
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (error.code === 'ERR_BUFFER_TOO_LARGE')
|
|
106
|
+
throw new HttpError(413, `${label}解压后最多 ${maxOutput / 1024 / 1024} MiB`);
|
|
107
|
+
throw invalid('无法解压 gzip 文件');
|
|
108
|
+
}
|
|
109
|
+
const entries = stripArchiveRoot(tarEntries(tar, invalid, maxEntries));
|
|
110
|
+
try {
|
|
111
|
+
for (const entry of entries) {
|
|
112
|
+
if (skip?.(entry.parts))
|
|
113
|
+
continue;
|
|
114
|
+
const path = join(dir, ...entry.parts);
|
|
115
|
+
if (entry.directory)
|
|
116
|
+
mkdirSync(path, { recursive: true });
|
|
117
|
+
else {
|
|
118
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
119
|
+
writeFileSync(path, entry.bytes, { mode: entry.mode, flag: 'wx' });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (['EEXIST', 'EISDIR', 'ENOTDIR'].includes(error.code ?? ''))
|
|
125
|
+
throw invalid('tar 中有重复或冲突的文件路径');
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export function extractPluginArchive(archive, dir) {
|
|
130
|
+
return extractTarGz(archive, dir, {
|
|
131
|
+
label: '插件离线包',
|
|
132
|
+
maxOutput: EXTRACTED_LIMIT,
|
|
133
|
+
skip: (parts) => parts.length === 1 && parts[0].toLowerCase() === 'settings.json',
|
|
134
|
+
});
|
|
135
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface SavedAttachment {
|
|
2
|
+
path: string;
|
|
3
|
+
name: string;
|
|
4
|
+
size: number;
|
|
5
|
+
}
|
|
6
|
+
export interface AttachmentLocation {
|
|
7
|
+
file?: string;
|
|
8
|
+
url: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const MAX_ATTACHMENT_BYTES: number;
|
|
11
|
+
export declare const ATTACHMENT_RECORDS = ".attachment-refs";
|
|
12
|
+
export declare function attachmentLocation(topicId: string, dir: string, path: string): AttachmentLocation | undefined;
|
|
13
|
+
export declare function attachmentInputPath(dir: string, path: string): string;
|
|
14
|
+
/** Create a unique file exclusively, also reserving names already used by the other attachment source. */
|
|
15
|
+
export declare function writeExclusiveFile(dir: string, name: string, data: Uint8Array, write?: (fd: number, data: Uint8Array, offset: number, length: number) => number, reservedDir?: string): string;
|
|
16
|
+
export declare function saveAttachment(topicDir: string, name: string, data: Uint8Array): SavedAttachment;
|
|
17
|
+
export declare function referenceAttachment(topicDir: string, source: string): SavedAttachment;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { accessSync, closeSync, constants, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, rmSync, writeSync } from 'node:fs';
|
|
2
|
+
import { basename, isAbsolute, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { HttpError } from "./entry.js";
|
|
5
|
+
export const MAX_ATTACHMENT_BYTES = 100 * 1024 * 1024;
|
|
6
|
+
export const ATTACHMENT_RECORDS = '.attachment-refs';
|
|
7
|
+
const files = 'attachments';
|
|
8
|
+
function entry(path) { return lstatSync(path, { throwIfNoEntry: false }); }
|
|
9
|
+
function nameOf(path) {
|
|
10
|
+
const name = basename(path);
|
|
11
|
+
if (path === 'attachments/' + name && name && name !== '.' && name !== '..' && !/[\\\0]/.test(name))
|
|
12
|
+
return name;
|
|
13
|
+
}
|
|
14
|
+
function attachmentName(rawName) {
|
|
15
|
+
const cleaned = basename(String(rawName ?? '').replace(/\\/g, '/')).replace(/[\u0000-\u001f]/g, '');
|
|
16
|
+
return !cleaned.trim() || cleaned === '.' || cleaned === '..' ? 'file' : cleaned;
|
|
17
|
+
}
|
|
18
|
+
function byName(dir, folder, name) {
|
|
19
|
+
const parent = join(dir, folder);
|
|
20
|
+
if (!entry(parent)?.isDirectory())
|
|
21
|
+
return;
|
|
22
|
+
const path = join(parent, name);
|
|
23
|
+
if (entry(path)?.isFile())
|
|
24
|
+
return path;
|
|
25
|
+
}
|
|
26
|
+
function originalOf(dir, name) {
|
|
27
|
+
const record = byName(dir, ATTACHMENT_RECORDS, name);
|
|
28
|
+
if (!record)
|
|
29
|
+
return;
|
|
30
|
+
const original = JSON.parse(readFileSync(record, 'utf8'));
|
|
31
|
+
if (typeof original === 'string' && isAbsolute(original))
|
|
32
|
+
return original;
|
|
33
|
+
}
|
|
34
|
+
function originalStat(file) {
|
|
35
|
+
try {
|
|
36
|
+
const stat = entry(file);
|
|
37
|
+
// Keep the choice bound to one canonical path, even if a parent or the last component is replaced by a symlink.
|
|
38
|
+
if (!stat?.isFile() || realpathSync.native(file) !== file)
|
|
39
|
+
return;
|
|
40
|
+
accessSync(file, constants.R_OK);
|
|
41
|
+
return stat;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (['ENOENT', 'ENOTDIR', 'ELOOP', 'EACCES', 'EPERM'].includes(error.code ?? ''))
|
|
45
|
+
return;
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function attachmentLocation(topicId, dir, path) {
|
|
50
|
+
const name = nameOf(path);
|
|
51
|
+
if (!name)
|
|
52
|
+
return;
|
|
53
|
+
const original = originalOf(dir, name);
|
|
54
|
+
const file = original ? (originalStat(original) && original) : byName(dir, files, name);
|
|
55
|
+
return { file, url: '/api/topics/' + encodeURIComponent(topicId) + '/attachments/' + encodeURIComponent(name) };
|
|
56
|
+
}
|
|
57
|
+
export function attachmentInputPath(dir, path) {
|
|
58
|
+
const name = nameOf(path);
|
|
59
|
+
const original = name && originalOf(dir, name);
|
|
60
|
+
if (!original)
|
|
61
|
+
return join(dir, path);
|
|
62
|
+
return originalStat(original) ? original : '原件不可用';
|
|
63
|
+
}
|
|
64
|
+
/** Create a unique file exclusively, also reserving names already used by the other attachment source. */
|
|
65
|
+
export function writeExclusiveFile(dir, name, data, write = writeSync, reservedDir) {
|
|
66
|
+
const dot = name.lastIndexOf('.');
|
|
67
|
+
const [stem, ext] = dot > 0 ? [name.slice(0, dot), name.slice(dot)] : [name, ''];
|
|
68
|
+
let fd;
|
|
69
|
+
let file = name;
|
|
70
|
+
let target = join(dir, file);
|
|
71
|
+
for (let n = 1;; n++) {
|
|
72
|
+
file = n === 1 ? name : stem + ' (' + n + ')' + ext;
|
|
73
|
+
target = join(dir, file);
|
|
74
|
+
if (entry(target) || (reservedDir && entry(join(reservedDir, file))))
|
|
75
|
+
continue;
|
|
76
|
+
try {
|
|
77
|
+
fd = openSync(target, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL, 0o666);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (error.code === 'EEXIST')
|
|
82
|
+
continue;
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
let offset = 0;
|
|
88
|
+
while (offset < data.byteLength) {
|
|
89
|
+
offset += write(fd, data, offset, data.byteLength - offset);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
try {
|
|
94
|
+
closeSync(fd);
|
|
95
|
+
}
|
|
96
|
+
catch { }
|
|
97
|
+
rmSync(target, { force: true });
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
closeSync(fd);
|
|
101
|
+
return file;
|
|
102
|
+
}
|
|
103
|
+
function storeAttachment(topicDir, name, size, content, original) {
|
|
104
|
+
const root = realpathSync.native(topicDir);
|
|
105
|
+
const destination = join(root, original ? ATTACHMENT_RECORDS : files);
|
|
106
|
+
const other = join(root, original ? files : ATTACHMENT_RECORDS);
|
|
107
|
+
const found = entry(destination);
|
|
108
|
+
if (found && !found.isDirectory())
|
|
109
|
+
throw new HttpError(400, '主题附件目录无效');
|
|
110
|
+
if (!found)
|
|
111
|
+
mkdirSync(destination);
|
|
112
|
+
const alias = writeExclusiveFile(destination, attachmentName(name), content, undefined, entry(other)?.isDirectory() ? other : undefined);
|
|
113
|
+
return { path: 'attachments/' + alias, name: alias, size };
|
|
114
|
+
}
|
|
115
|
+
export function saveAttachment(topicDir, name, data) {
|
|
116
|
+
if (!(data instanceof Uint8Array))
|
|
117
|
+
throw new HttpError(400, '附件需要是二进制内容');
|
|
118
|
+
if (data.byteLength > MAX_ATTACHMENT_BYTES)
|
|
119
|
+
throw new HttpError(413, '太大了:一次最多 100 MB');
|
|
120
|
+
return storeAttachment(topicDir, name, data.byteLength, data, false);
|
|
121
|
+
}
|
|
122
|
+
export function referenceAttachment(topicDir, source) {
|
|
123
|
+
let selected;
|
|
124
|
+
try {
|
|
125
|
+
selected = source.startsWith('file:') ? fileURLToPath(source) : source;
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
throw new HttpError(400, '请选择本机文件');
|
|
129
|
+
}
|
|
130
|
+
if (!isAbsolute(selected) || selected.includes('\0'))
|
|
131
|
+
throw new HttpError(400, '请选择本机文件');
|
|
132
|
+
let original;
|
|
133
|
+
try {
|
|
134
|
+
original = realpathSync.native(selected);
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
throw new HttpError(404, '原件已移动或不可读');
|
|
138
|
+
}
|
|
139
|
+
const stat = originalStat(original);
|
|
140
|
+
if (!stat)
|
|
141
|
+
throw new HttpError(404, '原件已移动或不可读');
|
|
142
|
+
return storeAttachment(topicDir, basename(original), stat.size, Buffer.from(JSON.stringify(original)), true);
|
|
143
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { Ctx } from '../runtime/runtime.ts';
|
|
2
|
+
import { type PluginMember } from './members.ts';
|
|
3
|
+
import type { Message, Part, Sender } from './types.ts';
|
|
4
|
+
type Place = {
|
|
5
|
+
topicId: string;
|
|
6
|
+
messageId: string;
|
|
7
|
+
};
|
|
8
|
+
type State = 'pending' | 'returned' | 'resumed' | 'escalated' | 'handled';
|
|
9
|
+
type Visibility = Message['visibility'];
|
|
10
|
+
export interface BlockedHandoff {
|
|
11
|
+
id: string;
|
|
12
|
+
/** Opaque identity of the original addressed input. Null when there is no evidence of it. */
|
|
13
|
+
authority: string | null;
|
|
14
|
+
/** The original input address is included only for its readers. */
|
|
15
|
+
origin?: Place;
|
|
16
|
+
kind: 'reply' | 'post' | 'relay';
|
|
17
|
+
from: string;
|
|
18
|
+
sourceTopicId: string;
|
|
19
|
+
sourceMessageId?: string;
|
|
20
|
+
sourceThread?: string;
|
|
21
|
+
/** Selected originals when forwarding more than the current turn's message. */
|
|
22
|
+
sourceIds?: string[];
|
|
23
|
+
topicId: string;
|
|
24
|
+
thread?: string;
|
|
25
|
+
replyTo?: string;
|
|
26
|
+
/** Delivery was rejected for these recipients. Nobody is included in both lists. */
|
|
27
|
+
blocked: string[];
|
|
28
|
+
delivered: string[];
|
|
29
|
+
/** Original misses for which there is still no positive delivery or handling receipt. */
|
|
30
|
+
remaining: string[];
|
|
31
|
+
content: string;
|
|
32
|
+
visibility?: Visibility;
|
|
33
|
+
depth: number;
|
|
34
|
+
turnId?: string;
|
|
35
|
+
createdAt: number;
|
|
36
|
+
state: State;
|
|
37
|
+
/** A fresh delivery may be claimed. A repeated successful claim can still return its existing receipt. */
|
|
38
|
+
canResume: boolean;
|
|
39
|
+
receipt?: Place;
|
|
40
|
+
/** Actual recovery messages by recipient, including when other recipients still need a decision. */
|
|
41
|
+
receipts?: Record<string, Place>;
|
|
42
|
+
/** A human has taken over contact in this topic; these addresses alone do not prove which work was delivered. */
|
|
43
|
+
contacts?: Record<string, Place>;
|
|
44
|
+
}
|
|
45
|
+
type Attempt = Omit<BlockedHandoff, 'id' | 'createdAt' | 'state' | 'receipt' | 'receipts' | 'contacts' | 'remaining' | 'origin' | 'canResume'>;
|
|
46
|
+
type Delivery = {
|
|
47
|
+
from: Sender;
|
|
48
|
+
topicId: string;
|
|
49
|
+
content: string;
|
|
50
|
+
targets: string[];
|
|
51
|
+
visibility?: Visibility;
|
|
52
|
+
thread?: string;
|
|
53
|
+
replyTo?: string;
|
|
54
|
+
parts?: Part[];
|
|
55
|
+
requireRecipient: true;
|
|
56
|
+
};
|
|
57
|
+
export interface HandoffConsumer {
|
|
58
|
+
blockedHandoffs(topicId: string, viewerId: string): BlockedHandoff[];
|
|
59
|
+
claimBlockedHandoff(id: string, request: {
|
|
60
|
+
from: PluginMember['sender'];
|
|
61
|
+
viewerId: string;
|
|
62
|
+
memberId: string;
|
|
63
|
+
content?: string;
|
|
64
|
+
visibility?: Visibility;
|
|
65
|
+
}): Place | undefined;
|
|
66
|
+
returnBlockedHandoff(id: string, viewerId: string): Place | undefined;
|
|
67
|
+
resolveBlockedHandoff(id: string, viewerId: string, memberId?: string): void;
|
|
68
|
+
}
|
|
69
|
+
declare module '../runtime/runtime.ts' {
|
|
70
|
+
interface Events {
|
|
71
|
+
/** An active workflow may take responsibility synchronously, then use the persisted receipt. */
|
|
72
|
+
'a2a.handoffBlocked': {
|
|
73
|
+
id: string;
|
|
74
|
+
sourceTopicId: string;
|
|
75
|
+
topicId: string;
|
|
76
|
+
hold(): void;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export declare function blockedHandoffs(ctx: Ctx, ops: {
|
|
81
|
+
worksIn(topicId: string, memberId: string): boolean;
|
|
82
|
+
running(turnId: string): boolean;
|
|
83
|
+
send(input: Delivery, record: (message: Message) => void): Message;
|
|
84
|
+
setDepth(messageId: string, depth: number): void;
|
|
85
|
+
ack(memberId: string, receipt: Place): void;
|
|
86
|
+
received(message: Message): boolean;
|
|
87
|
+
}): {
|
|
88
|
+
originOf: (id: string | undefined) => string | null;
|
|
89
|
+
inherit(messageId: string, authority: string | null): void;
|
|
90
|
+
record(attempt: Attempt, sourceScope?: Visibility): string;
|
|
91
|
+
blockedHandoffs(topicId: string, viewerId: string): {
|
|
92
|
+
origin?: Place;
|
|
93
|
+
contacts?: {
|
|
94
|
+
[k: string]: Place;
|
|
95
|
+
} | undefined;
|
|
96
|
+
receipts?: {
|
|
97
|
+
[k: string]: Place;
|
|
98
|
+
} | undefined;
|
|
99
|
+
receipt?: Place | undefined;
|
|
100
|
+
canResume: boolean;
|
|
101
|
+
authority: string | null;
|
|
102
|
+
id: string;
|
|
103
|
+
kind: "reply" | "post" | "relay";
|
|
104
|
+
from: string;
|
|
105
|
+
sourceTopicId: string;
|
|
106
|
+
sourceMessageId?: string;
|
|
107
|
+
sourceThread?: string;
|
|
108
|
+
/** Selected originals when forwarding more than the current turn's message. */
|
|
109
|
+
sourceIds?: string[];
|
|
110
|
+
topicId: string;
|
|
111
|
+
thread?: string;
|
|
112
|
+
replyTo?: string;
|
|
113
|
+
/** Delivery was rejected for these recipients. Nobody is included in both lists. */
|
|
114
|
+
blocked: string[];
|
|
115
|
+
delivered: string[];
|
|
116
|
+
/** Original misses for which there is still no positive delivery or handling receipt. */
|
|
117
|
+
remaining: string[];
|
|
118
|
+
content: string;
|
|
119
|
+
visibility?: Visibility;
|
|
120
|
+
depth: number;
|
|
121
|
+
turnId?: string;
|
|
122
|
+
createdAt: number;
|
|
123
|
+
state: State;
|
|
124
|
+
}[];
|
|
125
|
+
claimBlockedHandoff: (id: string, { from, viewerId, memberId, content, visibility: requested }: Parameters<HandoffConsumer["claimBlockedHandoff"]>[1]) => {
|
|
126
|
+
topicId: string;
|
|
127
|
+
messageId: string;
|
|
128
|
+
} | undefined;
|
|
129
|
+
returnBlockedHandoff: (id: string, viewerId: string) => Place | undefined;
|
|
130
|
+
resolveBlockedHandoff: (id: string, viewerId: string, memberId?: string) => void;
|
|
131
|
+
};
|
|
132
|
+
export {};
|