hostlet 0.0.0-stage → 0.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +233 -2
- package/bin/hostlet.js +61 -0
- package/console/app/api.js +1223 -0
- package/console/app/boot.js +165 -0
- package/console/app/cards.js +222 -0
- package/console/app/compose-quote.js +127 -0
- package/console/app/config-form.js +727 -0
- package/console/app/document-drafts.js +62 -0
- package/console/app/document-tools.mjs +67 -0
- package/console/app/documents.js +106 -0
- package/console/app/pages.js +6483 -0
- package/console/app/plugins.js +509 -0
- package/console/app/preview-tools.js +172 -0
- package/console/app/reference-labels.js +118 -0
- package/console/app/selection.js +372 -0
- package/console/app/store.js +57 -0
- package/console/app/text-anchor.js +26 -0
- package/console/app/topic-local.js +322 -0
- package/console/app/topic-nav.js +414 -0
- package/console/app/topic-status.js +109 -0
- package/console/app/views.js +43 -0
- package/console/apple-touch-icon.png +0 -0
- package/console/avatars/agy.svg +34 -0
- package/console/avatars/alhena.svg +36 -0
- package/console/avatars/castor.svg +38 -0
- package/console/avatars/claude.svg +34 -0
- package/console/avatars/codex.svg +34 -0
- package/console/avatars/devin.svg +34 -0
- package/console/avatars/echo.svg +34 -0
- package/console/avatars/kimi.svg +33 -0
- package/console/avatars/opencode.svg +33 -0
- package/console/avatars/pinion.svg +34 -0
- package/console/avatars/sprocket.svg +34 -0
- package/console/avatars/vela.svg +44 -0
- package/console/avatars/wasat.svg +38 -0
- package/console/clients/agy.svg +1 -0
- package/console/clients/claude.svg +1 -0
- package/console/clients/codex.svg +1 -0
- package/console/clients/devin.svg +1 -0
- package/console/clients/kimi.svg +1 -0
- package/console/clients/opencode.svg +1 -0
- package/console/favicon.ico +0 -0
- package/console/favicon.svg +16 -0
- package/console/index.html +99 -0
- package/console/pdl/engine/README.md +13 -0
- package/console/pdl/engine/anchor.js +195 -0
- package/console/pdl/engine/core.js +1340 -0
- package/console/pdl/engine/frame.js +1252 -0
- package/console/pdl/engine/i18n.js +67 -0
- package/console/pdl/engine/pdl-check.js +102 -0
- package/console/pdl/engine/pdl-doc.js +353 -0
- package/console/pdl/engine/pdl-view.js +280 -0
- package/console/pdl/engine/pdl.js +1064 -0
- package/console/pdl/engine/platform.js +18 -0
- package/console/pdl/engine/proj.js +279 -0
- package/console/pdl/engine/theme.js +176 -0
- package/console/pdl/engine/tree.js +171 -0
- package/console/pdl/engine/units.js +546 -0
- package/console/pdl/library/README.md +28 -0
- package/console/pdl/library/blocks.js +1512 -0
- package/console/pdl/library/buttons.js +86 -0
- package/console/pdl/library/capsules.js +130 -0
- package/console/pdl/library/charts.js +287 -0
- package/console/pdl/library/code.js +98 -0
- package/console/pdl/library/css/base.css +12 -0
- package/console/pdl/library/css/blocks.css +98 -0
- package/console/pdl/library/css/capsules.css +42 -0
- package/console/pdl/library/css/catalog-page.css +24 -0
- package/console/pdl/library/css/chat.css +100 -0
- package/console/pdl/library/css/composer-top.css +145 -0
- package/console/pdl/library/css/controls.css +195 -0
- package/console/pdl/library/css/drag.css +29 -0
- package/console/pdl/library/css/edit-layout.css +93 -0
- package/console/pdl/library/css/floating-window.css +30 -0
- package/console/pdl/library/css/hover.css +50 -0
- package/console/pdl/library/css/label-search.css +37 -0
- package/console/pdl/library/css/layers.css +43 -0
- package/console/pdl/library/css/library-parts.css +33 -0
- package/console/pdl/library/css/library.css +117 -0
- package/console/pdl/library/css/member-select.css +34 -0
- package/console/pdl/library/css/message.css +72 -0
- package/console/pdl/library/css/page.css +104 -0
- package/console/pdl/library/css/parts.css +338 -0
- package/console/pdl/library/css/responsive.css +40 -0
- package/console/pdl/library/css/roles.css +28 -0
- package/console/pdl/library/css/rows.css +231 -0
- package/console/pdl/library/css/settings-rows.css +37 -0
- package/console/pdl/library/css/shell.css +59 -0
- package/console/pdl/library/css/stream.css +296 -0
- package/console/pdl/library/css/theme-calculator.css +18 -0
- package/console/pdl/library/css/thumb-choice.css +69 -0
- package/console/pdl/library/css/tweaks.css +16 -0
- package/console/pdl/library/css/widgets.css +211 -0
- package/console/pdl/library/css/workbench.css +59 -0
- package/console/pdl/library/feedback.js +83 -0
- package/console/pdl/library/floating-window.mjs +100 -0
- package/console/pdl/library/fold.js +238 -0
- package/console/pdl/library/format.js +53 -0
- package/console/pdl/library/frames.js +123 -0
- package/console/pdl/library/icons.js +165 -0
- package/console/pdl/library/identity.js +149 -0
- package/console/pdl/library/inputs.js +801 -0
- package/console/pdl/library/label-search.js +214 -0
- package/console/pdl/library/markdown-text.js +115 -0
- package/console/pdl/library/markdown.js +150 -0
- package/console/pdl/library/media-viewer.js +293 -0
- package/console/pdl/library/member-select.mjs +32 -0
- package/console/pdl/library/message.js +105 -0
- package/console/pdl/library/motion.js +56 -0
- package/console/pdl/library/overlays.js +165 -0
- package/console/pdl/library/page.js +142 -0
- package/console/pdl/library/plugin-form.js +154 -0
- package/console/pdl/library/registry.js +198 -0
- package/console/pdl/library/rows.js +523 -0
- package/console/pdl/library/shell.js +151 -0
- package/console/pdl/library/stream.js +58 -0
- package/console/pdl/library/tabs.js +259 -0
- package/console/pdl/library/theme-calculator.js +300 -0
- package/console/pdl/library/widgets.js +114 -0
- package/console/pdl/load-order.json +74 -0
- package/console/pdl/platform/README.md +3 -0
- package/console/pdl/platform/rich-markdown.mjs +17 -0
- package/console/pdl/platform/web-links.js +26 -0
- package/console/pdl/platform/web.js +80 -0
- package/console/sdk-browser/mentions.d.mts +16 -0
- package/console/sdk-browser/mentions.mjs +84 -0
- package/console/theme/assets.js +21 -0
- package/console/theme/theme.json +9417 -0
- package/console/theme/tokens.json +444 -0
- package/dist/core/a2a.d.ts +288 -0
- package/dist/core/a2a.js +2197 -0
- package/dist/core/address.d.ts +34 -0
- package/dist/core/address.js +33 -0
- package/dist/core/approval-inputs.d.ts +17 -0
- package/dist/core/approval-inputs.js +70 -0
- package/dist/core/archive.d.ts +19 -0
- package/dist/core/archive.js +135 -0
- package/dist/core/attachments.d.ts +17 -0
- package/dist/core/attachments.js +143 -0
- package/dist/core/blocked-handoffs.d.ts +132 -0
- package/dist/core/blocked-handoffs.js +349 -0
- package/dist/core/config-schema.d.ts +124 -0
- package/dist/core/config-schema.js +192 -0
- package/dist/core/config.d.ts +117 -0
- package/dist/core/config.js +638 -0
- package/dist/core/disk-usage.d.ts +26 -0
- package/dist/core/disk-usage.js +83 -0
- package/dist/core/documents.d.ts +9 -0
- package/dist/core/documents.js +48 -0
- package/dist/core/entry.d.ts +316 -0
- package/dist/core/entry.js +711 -0
- package/dist/core/home.d.ts +76 -0
- package/dist/core/home.js +449 -0
- package/dist/core/i18n.d.ts +36 -0
- package/dist/core/i18n.js +458 -0
- package/dist/core/instances.d.ts +224 -0
- package/dist/core/instances.js +1272 -0
- package/dist/core/members.d.ts +190 -0
- package/dist/core/members.js +358 -0
- package/dist/core/mentions.d.ts +12 -0
- package/dist/core/mentions.js +49 -0
- package/dist/core/messages.d.ts +876 -0
- package/dist/core/messages.js +916 -0
- package/dist/core/notices.d.ts +88 -0
- package/dist/core/notices.js +54 -0
- package/dist/core/ops.d.ts +117 -0
- package/dist/core/ops.js +146 -0
- package/dist/core/package.d.ts +2 -0
- package/dist/core/package.js +14 -0
- package/dist/core/parts.d.ts +25 -0
- package/dist/core/parts.js +119 -0
- package/dist/core/plugins/catalog.d.ts +14 -0
- package/dist/core/plugins/catalog.js +54 -0
- package/dist/core/plugins/external.d.ts +7 -0
- package/dist/core/plugins/external.js +921 -0
- package/dist/core/plugins/index.d.ts +5 -0
- package/dist/core/plugins/index.js +51 -0
- package/dist/core/plugins/npm.d.ts +12 -0
- package/dist/core/plugins/npm.js +99 -0
- package/dist/core/plugins/plugin-manifest.d.ts +12 -0
- package/dist/core/plugins/plugin-manifest.js +231 -0
- package/dist/core/push.d.ts +22 -0
- package/dist/core/push.js +63 -0
- package/dist/core/resource.d.ts +77 -0
- package/dist/core/resource.js +48 -0
- package/dist/core/spawn.d.ts +12 -0
- package/dist/core/spawn.js +30 -0
- package/dist/core/storage-inventory.d.ts +118 -0
- package/dist/core/storage-inventory.js +279 -0
- package/dist/core/storage.d.ts +45 -0
- package/dist/core/storage.js +602 -0
- package/dist/core/store.d.ts +15 -0
- package/dist/core/store.js +33 -0
- package/dist/core/topic-index.d.ts +19 -0
- package/dist/core/topic-index.js +70 -0
- package/dist/core/topic-ops.d.ts +139 -0
- package/dist/core/topic-ops.js +507 -0
- package/dist/core/topic-status.d.ts +32 -0
- package/dist/core/topic-status.js +105 -0
- package/dist/core/topics.d.ts +327 -0
- package/dist/core/topics.js +786 -0
- package/dist/core/turn-clients.d.ts +1 -0
- package/dist/core/turn-clients.js +5 -0
- package/dist/core/types.d.ts +2866 -0
- package/dist/core/types.js +166 -0
- package/dist/core/util.d.ts +10 -0
- package/dist/core/util.js +47 -0
- package/dist/main.d.ts +12 -0
- package/dist/main.js +82 -0
- package/dist/plugins/adapter-acp/index.d.ts +3 -0
- package/dist/plugins/adapter-acp/index.js +57 -0
- package/dist/plugins/adapter-acp/plugin.yaml +100 -0
- package/dist/plugins/adapter-agy/command.d.ts +9 -0
- package/dist/plugins/adapter-agy/command.js +34 -0
- package/dist/plugins/adapter-agy/index.d.ts +5 -0
- package/dist/plugins/adapter-agy/index.js +65 -0
- package/dist/plugins/adapter-agy/quota.d.ts +2 -0
- package/dist/plugins/adapter-agy/quota.js +155 -0
- package/dist/plugins/adapter-agy/terminal.d.ts +6 -0
- package/dist/plugins/adapter-agy/terminal.js +132 -0
- package/dist/plugins/adapter-agy/version.d.ts +9 -0
- package/dist/plugins/adapter-agy/version.js +17 -0
- package/dist/plugins/adapter-claude/index.d.ts +43 -0
- package/dist/plugins/adapter-claude/index.js +412 -0
- package/dist/plugins/adapter-claude/quota.d.ts +14 -0
- package/dist/plugins/adapter-claude/quota.js +103 -0
- package/dist/plugins/adapter-codex/index.d.ts +4 -0
- package/dist/plugins/adapter-codex/index.js +688 -0
- package/dist/plugins/adapter-codex/responses-model.d.ts +9 -0
- package/dist/plugins/adapter-codex/responses-model.js +82 -0
- package/dist/plugins/adapter-kimi/index.d.ts +4 -0
- package/dist/plugins/adapter-kimi/index.js +51 -0
- package/dist/plugins/adapter-kimi/quota.d.ts +3 -0
- package/dist/plugins/adapter-kimi/quota.js +171 -0
- package/dist/plugins/adapter-opencode/index.d.ts +12 -0
- package/dist/plugins/adapter-opencode/index.js +64 -0
- package/dist/plugins/annotations/console/cards.css +189 -0
- package/dist/plugins/annotations/console/cards.mjs +439 -0
- package/dist/plugins/annotations/console/pdl.json +52 -0
- package/dist/plugins/annotations/console/view.mjs +241 -0
- package/dist/plugins/annotations/console/window.mjs +219 -0
- package/dist/plugins/annotations/followups.d.ts +51 -0
- package/dist/plugins/annotations/followups.js +112 -0
- package/dist/plugins/annotations/index.d.ts +3 -0
- package/dist/plugins/annotations/index.js +298 -0
- package/dist/plugins/annotations/plugin.yaml +3 -0
- package/dist/plugins/ask-choice/index.d.ts +9 -0
- package/dist/plugins/ask-choice/index.js +24 -0
- package/dist/plugins/ask-choice/plugin.yaml +2 -0
- package/dist/plugins/background/index.d.ts +2 -0
- package/dist/plugins/background/index.js +398 -0
- package/dist/plugins/background/plugin.yaml +7 -0
- package/dist/plugins/builtin.json +37 -0
- package/dist/plugins/cards/console/pdl.json +516 -0
- package/dist/plugins/cards/console/view.mjs +67 -0
- package/dist/plugins/cards/index.d.ts +8 -0
- package/dist/plugins/cards/index.js +627 -0
- package/dist/plugins/cards/plugin.yaml +3 -0
- package/dist/plugins/console/browser.d.ts +2 -0
- package/dist/plugins/console/browser.js +115 -0
- package/dist/plugins/console/console/pdl.json +38 -0
- package/dist/plugins/console/console/view.mjs +26 -0
- package/dist/plugins/console/index.d.ts +4 -0
- package/dist/plugins/console/index.js +94 -0
- package/dist/plugins/console/picker.d.ts +2 -0
- package/dist/plugins/console/picker.js +48 -0
- package/dist/plugins/console/plugin.yaml +3 -0
- package/dist/plugins/console/topic-view.d.ts +3 -0
- package/dist/plugins/console/topic-view.js +388 -0
- package/dist/plugins/handoff/index.d.ts +2 -0
- package/dist/plugins/handoff/index.js +147 -0
- package/dist/plugins/handoff/plugin.yaml +8 -0
- package/dist/plugins/host-api/index.d.ts +7 -0
- package/dist/plugins/host-api/index.js +310 -0
- package/dist/plugins/host-api/plugin.yaml +2 -0
- package/dist/plugins/host-api/signing.d.ts +63 -0
- package/dist/plugins/host-api/signing.js +427 -0
- package/dist/plugins/host-api/skills/host-ops/SKILL.md +28 -0
- package/dist/plugins/host-api/skills/hostlet-plugin-dev/SKILL.md +38 -0
- package/dist/plugins/inbox/index.d.ts +15 -0
- package/dist/plugins/inbox/index.js +161 -0
- package/dist/plugins/inbox/plugin.yaml +2 -0
- package/dist/plugins/keys/account-directories.d.ts +18 -0
- package/dist/plugins/keys/account-directories.js +86 -0
- package/dist/plugins/keys/account-storage.d.ts +18 -0
- package/dist/plugins/keys/account-storage.js +112 -0
- package/dist/plugins/keys/console/pdl.json +710 -0
- package/dist/plugins/keys/console/view.mjs +619 -0
- package/dist/plugins/keys/index.d.ts +7 -0
- package/dist/plugins/keys/index.js +842 -0
- package/dist/plugins/keys/login-link.d.ts +2 -0
- package/dist/plugins/keys/login-link.js +15 -0
- package/dist/plugins/keys/plugin.yaml +3 -0
- package/dist/plugins/keys/quota-history.d.ts +91 -0
- package/dist/plugins/keys/quota-history.js +420 -0
- package/dist/plugins/mcp/console/pdl.json +412 -0
- package/dist/plugins/mcp/console/view.mjs +207 -0
- package/dist/plugins/mcp/index.d.ts +7 -0
- package/dist/plugins/mcp/index.js +494 -0
- package/dist/plugins/mcp/plugin.yaml +3 -0
- package/dist/plugins/member-health/index.d.ts +2 -0
- package/dist/plugins/member-health/index.js +478 -0
- package/dist/plugins/member-health/plugin.yaml +2 -0
- package/dist/plugins/memory/capabilities.d.ts +10 -0
- package/dist/plugins/memory/capabilities.js +70 -0
- package/dist/plugins/memory/console/pdl.json +459 -0
- package/dist/plugins/memory/console/view.mjs +254 -0
- package/dist/plugins/memory/corpus.d.ts +60 -0
- package/dist/plugins/memory/corpus.js +521 -0
- package/dist/plugins/memory/engines/fts-tree-diversity.d.ts +8 -0
- package/dist/plugins/memory/engines/fts-tree-diversity.js +49 -0
- package/dist/plugins/memory/engines/fts-tree-text.d.ts +12 -0
- package/dist/plugins/memory/engines/fts-tree-text.js +93 -0
- package/dist/plugins/memory/engines/fts-tree.d.ts +4 -0
- package/dist/plugins/memory/engines/fts-tree.js +387 -0
- package/dist/plugins/memory/engines/search.d.ts +9 -0
- package/dist/plugins/memory/engines/search.js +35 -0
- package/dist/plugins/memory/index.d.ts +3 -0
- package/dist/plugins/memory/index.js +465 -0
- package/dist/plugins/memory/notes.d.ts +22 -0
- package/dist/plugins/memory/notes.js +140 -0
- package/dist/plugins/memory/plugin.yaml +23 -0
- package/dist/plugins/model-profiles/index.d.ts +2 -0
- package/dist/plugins/model-profiles/index.js +919 -0
- package/dist/plugins/model-profiles/plugin.yaml +13 -0
- package/dist/plugins/model-profiles/review-source.d.ts +11 -0
- package/dist/plugins/model-profiles/review-source.js +640 -0
- package/dist/plugins/model-profiles/rules.d.ts +132 -0
- package/dist/plugins/model-profiles/rules.js +767 -0
- package/dist/plugins/model-profiles/skills/model-profile/SKILL.md +60 -0
- package/dist/plugins/model-profiles/sources.d.ts +61 -0
- package/dist/plugins/model-profiles/sources.js +375 -0
- package/dist/plugins/model-profiles/storage.d.ts +104 -0
- package/dist/plugins/model-profiles/storage.js +352 -0
- package/dist/plugins/model-profiles/types.d.ts +187 -0
- package/dist/plugins/model-profiles/types.js +12 -0
- package/dist/plugins/model-profiles/wakeup.d.ts +29 -0
- package/dist/plugins/model-profiles/wakeup.js +390 -0
- package/dist/plugins/models/index.d.ts +2 -0
- package/dist/plugins/models/index.js +63 -0
- package/dist/plugins/models/plugin.yaml +8 -0
- package/dist/plugins/ops/collector.d.ts +22 -0
- package/dist/plugins/ops/collector.js +48 -0
- package/dist/plugins/ops/config.d.ts +11 -0
- package/dist/plugins/ops/config.js +13 -0
- package/dist/plugins/ops/console/pdl.json +676 -0
- package/dist/plugins/ops/console/view.mjs +700 -0
- package/dist/plugins/ops/index.d.ts +3 -0
- package/dist/plugins/ops/index.js +20 -0
- package/dist/plugins/ops/journal.d.ts +7 -0
- package/dist/plugins/ops/journal.js +109 -0
- package/dist/plugins/ops/metrics.d.ts +3 -0
- package/dist/plugins/ops/metrics.js +81 -0
- package/dist/plugins/ops/plugin.yaml +63 -0
- package/dist/plugins/ops/samples.d.ts +54 -0
- package/dist/plugins/ops/samples.js +100 -0
- package/dist/plugins/ops/trace.d.ts +3 -0
- package/dist/plugins/ops/trace.js +104 -0
- package/dist/plugins/ops/usage.d.ts +2 -0
- package/dist/plugins/ops/usage.js +152 -0
- package/dist/plugins/plans/acceptance.d.ts +284 -0
- package/dist/plugins/plans/acceptance.js +247 -0
- package/dist/plugins/plans/blocked.d.ts +25 -0
- package/dist/plugins/plans/blocked.js +66 -0
- package/dist/plugins/plans/console/pdl.json +639 -0
- package/dist/plugins/plans/console/view.d.mts +2 -0
- package/dist/plugins/plans/console/view.mjs +855 -0
- package/dist/plugins/plans/dependencies.d.ts +5 -0
- package/dist/plugins/plans/dependencies.js +21 -0
- package/dist/plugins/plans/index.d.ts +72 -0
- package/dist/plugins/plans/index.js +2057 -0
- package/dist/plugins/plans/plugin.yaml +44 -0
- package/dist/plugins/plans/progress.d.ts +82 -0
- package/dist/plugins/plans/progress.js +516 -0
- package/dist/plugins/prompt/index.d.ts +8 -0
- package/dist/plugins/prompt/index.js +361 -0
- package/dist/plugins/prompt/plugin.yaml +2 -0
- package/dist/plugins/recovery/console/pdl.json +50 -0
- package/dist/plugins/recovery/console/view.mjs +46 -0
- package/dist/plugins/recovery/index.d.ts +9 -0
- package/dist/plugins/recovery/index.js +454 -0
- package/dist/plugins/recovery/plugin.yaml +9 -0
- package/dist/plugins/recovery/probe.d.ts +11 -0
- package/dist/plugins/recovery/probe.js +128 -0
- package/dist/plugins/restart/console/pdl.json +112 -0
- package/dist/plugins/restart/console/view.mjs +85 -0
- package/dist/plugins/restart/index.d.ts +10 -0
- package/dist/plugins/restart/index.js +669 -0
- package/dist/plugins/restart/plugin.yaml +9 -0
- package/dist/plugins/restart/scope.d.ts +6 -0
- package/dist/plugins/restart/scope.js +44 -0
- package/dist/plugins/schedule/console/pdl.json +696 -0
- package/dist/plugins/schedule/console/view.mjs +398 -0
- package/dist/plugins/schedule/events.d.ts +76 -0
- package/dist/plugins/schedule/events.js +158 -0
- package/dist/plugins/schedule/index.d.ts +32 -0
- package/dist/plugins/schedule/index.js +1199 -0
- package/dist/plugins/schedule/plugin.yaml +26 -0
- package/dist/plugins/schedule/when.d.ts +14 -0
- package/dist/plugins/schedule/when.js +83 -0
- package/dist/plugins/sessions/console/pdl.json +259 -0
- package/dist/plugins/sessions/console/view.mjs +355 -0
- package/dist/plugins/sessions/index.d.ts +3 -0
- package/dist/plugins/sessions/index.js +126 -0
- package/dist/plugins/sessions/participants.d.ts +28 -0
- package/dist/plugins/sessions/participants.js +83 -0
- package/dist/plugins/sessions/plugin.yaml +3 -0
- package/dist/plugins/signals/console/pdl.json +802 -0
- package/dist/plugins/signals/console/view.mjs +284 -0
- package/dist/plugins/signals/content.d.ts +31 -0
- package/dist/plugins/signals/content.js +151 -0
- package/dist/plugins/signals/index.d.ts +2 -0
- package/dist/plugins/signals/index.js +601 -0
- package/dist/plugins/signals/plugin.yaml +32 -0
- package/dist/plugins/signals/skills/signal-sources/SKILL.md +27 -0
- package/dist/plugins/skills/console/pdl.json +254 -0
- package/dist/plugins/skills/console/view.mjs +204 -0
- package/dist/plugins/skills/index.d.ts +11 -0
- package/dist/plugins/skills/index.js +567 -0
- package/dist/plugins/skills/install.d.ts +69 -0
- package/dist/plugins/skills/install.js +265 -0
- package/dist/plugins/skills/plugin.yaml +24 -0
- package/dist/plugins/skills/safety-scan.d.ts +17 -0
- package/dist/plugins/skills/safety-scan.js +78 -0
- package/dist/plugins/skills/skills/skill-ops/SKILL.md +29 -0
- package/dist/plugins/terminal/console/pdl.json +115 -0
- package/dist/plugins/terminal/console/view.mjs +178 -0
- package/dist/plugins/terminal/index.d.ts +3 -0
- package/dist/plugins/terminal/index.js +204 -0
- package/dist/plugins/terminal/plugin.yaml +2 -0
- package/dist/plugins/tools/index.d.ts +3 -0
- package/dist/plugins/tools/index.js +458 -0
- package/dist/plugins/tools/plugin.yaml +2 -0
- package/dist/plugins/tools/token.d.ts +61 -0
- package/dist/plugins/tools/token.js +179 -0
- package/dist/plugins/topic-tools/index.d.ts +9 -0
- package/dist/plugins/topic-tools/index.js +29 -0
- package/dist/plugins/topic-tools/plugin.yaml +2 -0
- package/dist/plugins/topic-tools/skills/topic-tidy/SKILL.md +108 -0
- package/dist/plugins/works/console/pdl.json +120 -0
- package/dist/plugins/works/console/view.mjs +91 -0
- package/dist/plugins/works/document-words.d.ts +50 -0
- package/dist/plugins/works/document-words.js +27 -0
- package/dist/plugins/works/editors.d.ts +3 -0
- package/dist/plugins/works/editors.js +162 -0
- package/dist/plugins/works/events.d.ts +58 -0
- package/dist/plugins/works/events.js +82 -0
- package/dist/plugins/works/files.d.ts +23 -0
- package/dist/plugins/works/files.js +53 -0
- package/dist/plugins/works/index.d.ts +9 -0
- package/dist/plugins/works/index.js +1088 -0
- package/dist/plugins/works/plugin.yaml +9 -0
- package/dist/plugins/works/preview.d.ts +10 -0
- package/dist/plugins/works/preview.js +30 -0
- package/dist/plugins/works/project.d.ts +3 -0
- package/dist/plugins/works/project.js +245 -0
- package/dist/plugins/works/resource.d.ts +28 -0
- package/dist/plugins/works/resource.js +71 -0
- package/dist/plugins/works/retention.d.ts +36 -0
- package/dist/plugins/works/retention.js +295 -0
- package/dist/plugins/works/skills/works-ops/SKILL.md +14 -0
- package/dist/plugins/works/viewers.d.ts +13 -0
- package/dist/plugins/works/viewers.js +87 -0
- package/dist/plugins/works/web/anchors.js +94 -0
- package/dist/plugins/works/web/document-edit.js +245 -0
- package/dist/plugins/works/web/preview-bridge.js +142 -0
- package/dist/plugins/works/web/reading-position.js +74 -0
- package/dist/plugins/works/web/view.html +1118 -0
- package/dist/runtime/runtime.d.ts +210 -0
- package/dist/runtime/runtime.js +338 -0
- package/dist/sdk/adapter-kit.d.ts +1 -0
- package/dist/sdk/adapter-kit.js +1 -0
- package/dist/sdk/client.d.ts +163 -0
- package/dist/sdk/client.js +43 -0
- package/dist/sdk/contracts.d.ts +1263 -0
- package/dist/sdk/contracts.js +1 -0
- package/dist/sdk/index.d.ts +57 -0
- package/dist/sdk/index.js +27 -0
- package/dist/sdk/source-choice.d.ts +40 -0
- package/dist/sdk/source-choice.js +217 -0
- package/dist/sdk/topic-text.d.ts +5 -0
- package/dist/sdk/topic-text.js +26 -0
- package/dist/sdk/transport.d.ts +12 -0
- package/dist/sdk/transport.js +34 -0
- package/node_modules/@hostlet/adapter-kit/dist/acp.d.ts +88 -0
- package/node_modules/@hostlet/adapter-kit/dist/acp.js +674 -0
- package/node_modules/@hostlet/adapter-kit/dist/command.d.ts +18 -0
- package/node_modules/@hostlet/adapter-kit/dist/command.js +39 -0
- package/node_modules/@hostlet/adapter-kit/dist/index.d.ts +8 -0
- package/node_modules/@hostlet/adapter-kit/dist/index.js +6 -0
- package/node_modules/@hostlet/adapter-kit/dist/models.d.ts +29 -0
- package/node_modules/@hostlet/adapter-kit/dist/models.js +108 -0
- package/node_modules/@hostlet/adapter-kit/dist/quota.d.ts +3 -0
- package/node_modules/@hostlet/adapter-kit/dist/quota.js +4 -0
- package/node_modules/@hostlet/adapter-kit/dist/rpc.d.ts +29 -0
- package/node_modules/@hostlet/adapter-kit/dist/rpc.js +84 -0
- package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.d.ts +5 -0
- package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.js +37 -0
- package/node_modules/@hostlet/adapter-kit/package.json +16 -0
- package/node_modules/@hostlet/platform/dist/desktop.d.ts +16 -0
- package/node_modules/@hostlet/platform/dist/desktop.js +276 -0
- package/node_modules/@hostlet/platform/dist/files.d.ts +24 -0
- package/node_modules/@hostlet/platform/dist/files.js +113 -0
- package/node_modules/@hostlet/platform/dist/index.d.ts +6 -0
- package/node_modules/@hostlet/platform/dist/index.js +4 -0
- package/node_modules/@hostlet/platform/dist/paths.d.ts +4 -0
- package/node_modules/@hostlet/platform/dist/paths.js +9 -0
- package/node_modules/@hostlet/platform/dist/process.d.ts +45 -0
- package/node_modules/@hostlet/platform/dist/process.js +297 -0
- package/node_modules/@hostlet/platform/package.json +14 -0
- package/package.json +60 -4
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Plugin } from '../runtime/runtime.ts';
|
|
2
|
+
import type { Home } from './home.ts';
|
|
3
|
+
import type { LText } from './i18n.ts';
|
|
4
|
+
import type { Sender } from './types.ts';
|
|
5
|
+
interface NoticeActionLabel {
|
|
6
|
+
label: string;
|
|
7
|
+
labelI18n?: LText;
|
|
8
|
+
}
|
|
9
|
+
export type NoticeField = {
|
|
10
|
+
name: string;
|
|
11
|
+
label: string;
|
|
12
|
+
labelI18n?: LText;
|
|
13
|
+
} & ({
|
|
14
|
+
options: {
|
|
15
|
+
value: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}[];
|
|
18
|
+
check?: never;
|
|
19
|
+
} | {
|
|
20
|
+
check: true;
|
|
21
|
+
options?: never;
|
|
22
|
+
});
|
|
23
|
+
export type NoticeAction = NoticeActionLabel & ({
|
|
24
|
+
open: string;
|
|
25
|
+
method?: never;
|
|
26
|
+
path?: never;
|
|
27
|
+
body?: never;
|
|
28
|
+
danger?: never;
|
|
29
|
+
confirm?: never;
|
|
30
|
+
} | {
|
|
31
|
+
open?: never;
|
|
32
|
+
method: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
33
|
+
path: string;
|
|
34
|
+
body?: Record<string, unknown>;
|
|
35
|
+
danger?: boolean;
|
|
36
|
+
confirm?: {
|
|
37
|
+
title: string;
|
|
38
|
+
titleI18n?: LText;
|
|
39
|
+
text: string;
|
|
40
|
+
textI18n?: LText;
|
|
41
|
+
ok?: string;
|
|
42
|
+
okI18n?: LText;
|
|
43
|
+
fields?: NoticeField[];
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* Something the host or a plugin tells the owner, outside any topic: a plugin was updated, an install ended, a
|
|
48
|
+
* client has a new version. A notice can be cleared by hand. The console can also clear an informational notice
|
|
49
|
+
* after opening its destination. Whoever sent it may give it a key and take it back by that key.
|
|
50
|
+
*/
|
|
51
|
+
export interface Notice {
|
|
52
|
+
id: string;
|
|
53
|
+
from: Sender;
|
|
54
|
+
text: string;
|
|
55
|
+
/** Structured localizable form of `text` so historical notices re-render immediately when switching language. */
|
|
56
|
+
i18n?: LText;
|
|
57
|
+
/**
|
|
58
|
+
* Where acting on it happens, as an address. Everything that can be referred to has one, the same that is in the
|
|
59
|
+
* console's address bar: `chat-<topic>`, `chat-<topic>/<message>`, `plugins/<name>`, `skills/<name>`, `mcp/<name>`,
|
|
60
|
+
* a page (`memory`, `members`, `keys` …). A web address (http…) is somewhere else.
|
|
61
|
+
*/
|
|
62
|
+
open?: string;
|
|
63
|
+
actions?: NoticeAction[];
|
|
64
|
+
key?: string;
|
|
65
|
+
at: number;
|
|
66
|
+
}
|
|
67
|
+
export interface Notices {
|
|
68
|
+
/** With a key, replaces the notice that has that key, keeping its id. */
|
|
69
|
+
add(input: Omit<Notice, 'id' | 'at'>): Notice;
|
|
70
|
+
list(): Notice[];
|
|
71
|
+
/** With an observed timestamp, clears only the version that was shown. */
|
|
72
|
+
remove(id: string, at?: number): void;
|
|
73
|
+
removeKey(key: string): void;
|
|
74
|
+
clear(): void;
|
|
75
|
+
}
|
|
76
|
+
declare module '../runtime/runtime.ts' {
|
|
77
|
+
interface Services {
|
|
78
|
+
notices: Notices;
|
|
79
|
+
}
|
|
80
|
+
interface Events {
|
|
81
|
+
/** Notices dismissed by the owner through remove or clear (not withdrawn by their producer via removeKey). */
|
|
82
|
+
'notice.dismissed': {
|
|
83
|
+
notices: readonly Notice[];
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export declare function noticesPlugin(home: Home): Plugin;
|
|
88
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { object } from "./ops.js";
|
|
2
|
+
import { newId, readJson, writeJson } from "./util.js";
|
|
3
|
+
export function noticesPlugin(home) {
|
|
4
|
+
return {
|
|
5
|
+
name: 'notices',
|
|
6
|
+
core: true,
|
|
7
|
+
needs: ['push', 'entry'],
|
|
8
|
+
start(ctx) {
|
|
9
|
+
const file = home.path('plugins', 'notices', 'notices.json');
|
|
10
|
+
let all = readJson(file, []);
|
|
11
|
+
const write = (next) => {
|
|
12
|
+
all = next;
|
|
13
|
+
writeJson(file, all);
|
|
14
|
+
ctx.get('push').send('notices.changed', {});
|
|
15
|
+
};
|
|
16
|
+
const notices = {
|
|
17
|
+
add(input) {
|
|
18
|
+
const previous = input.key ? all.find((n) => n.key === input.key) : undefined;
|
|
19
|
+
const notice = { ...input, id: previous?.id ?? newId('ntc'), at: Math.max(Date.now(), (previous?.at ?? 0) + 1) };
|
|
20
|
+
write([...all.filter((n) => !input.key || n.key !== input.key), notice]);
|
|
21
|
+
return notice;
|
|
22
|
+
},
|
|
23
|
+
list: () => all,
|
|
24
|
+
remove(id, at) {
|
|
25
|
+
const removed = all.filter((notice) => notice.id === id && (at === undefined || notice.at === at));
|
|
26
|
+
if (!removed.length)
|
|
27
|
+
return;
|
|
28
|
+
write(all.filter((notice) => !removed.includes(notice)));
|
|
29
|
+
ctx.runtime.emit('notice.dismissed', { notices: removed });
|
|
30
|
+
},
|
|
31
|
+
removeKey(key) {
|
|
32
|
+
if (all.some((n) => n.key === key))
|
|
33
|
+
write(all.filter((n) => n.key !== key));
|
|
34
|
+
},
|
|
35
|
+
clear() {
|
|
36
|
+
if (!all.length)
|
|
37
|
+
return;
|
|
38
|
+
const removed = all;
|
|
39
|
+
write([]);
|
|
40
|
+
ctx.runtime.emit('notice.dismissed', { notices: removed });
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
ctx.provide('notices', notices);
|
|
44
|
+
const entry = ctx.get('entry');
|
|
45
|
+
ctx.effect(entry.op({ name: 'channel.notices', about: '查看宿主的通知。', http: ['GET', '/api/notices'], agent: true, run: () => notices.list() }));
|
|
46
|
+
ctx.effect(entry.op({
|
|
47
|
+
name: 'channel.notice_remove', about: '按编号清掉一条通知。带 at 时仅清掉当时看到的版本。',
|
|
48
|
+
input: object({ id: { type: 'string', description: '通知编号' }, at: { type: 'integer', description: '看到的通知时间戳' } }, ['id']),
|
|
49
|
+
http: ['DELETE', '/api/notices/:id'], run: ({ id, at }) => notices.remove(id, at),
|
|
50
|
+
}));
|
|
51
|
+
ctx.effect(entry.op({ name: 'channel.notices_clear', about: '清掉全部通知。', http: ['DELETE', '/api/notices'], run: () => notices.clear() }));
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the host can be asked to do is declared once (`entry.op`). The parts of that which only compute are here:
|
|
3
|
+
* checking arguments against a declaration, making the arguments of an HTTP request, and the OpenAPI document.
|
|
4
|
+
*/
|
|
5
|
+
/** The part of JSON Schema the declarations use. Anything else in a schema is carried along and not checked. */
|
|
6
|
+
type Type = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
|
|
7
|
+
export interface Schema {
|
|
8
|
+
/** One type, or several the value may be one of (`['boolean', 'null']`). */
|
|
9
|
+
type?: Type | readonly Type[];
|
|
10
|
+
title?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
properties?: Record<string, Schema>;
|
|
13
|
+
required?: readonly string[];
|
|
14
|
+
additionalProperties?: boolean | Schema;
|
|
15
|
+
enum?: readonly unknown[];
|
|
16
|
+
const?: unknown;
|
|
17
|
+
oneOf?: readonly Schema[];
|
|
18
|
+
items?: Schema;
|
|
19
|
+
/** A member's @ handle on the way in, an id when the operation runs. */
|
|
20
|
+
member?: true;
|
|
21
|
+
/** A field a person fills in through the console. */
|
|
22
|
+
secret?: true;
|
|
23
|
+
[more: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
type ObjectSchema<P, R> = {
|
|
26
|
+
type: 'object';
|
|
27
|
+
properties: P;
|
|
28
|
+
required: R;
|
|
29
|
+
additionalProperties: false;
|
|
30
|
+
};
|
|
31
|
+
/** An object with these fields and no others. */
|
|
32
|
+
export declare function object(): ObjectSchema<{}, []>;
|
|
33
|
+
export declare function object<const P extends Record<string, Schema>>(properties: P): ObjectSchema<P, []>;
|
|
34
|
+
export declare function object<const P extends Record<string, Schema>, const R extends readonly (keyof P & string)[]>(properties: P, required: R): ObjectSchema<P, R>;
|
|
35
|
+
export declare const array: <const S extends Schema>(items: S) => {
|
|
36
|
+
type: "array";
|
|
37
|
+
items: S;
|
|
38
|
+
};
|
|
39
|
+
type RequiredBy<S> = S extends {
|
|
40
|
+
required: readonly (infer K)[];
|
|
41
|
+
} ? K : never;
|
|
42
|
+
type Fields<P extends Record<string, Schema>, Required> = {
|
|
43
|
+
-readonly [K in keyof P as K extends Required ? K : never]: FromSchema<P[K]>;
|
|
44
|
+
} & {
|
|
45
|
+
-readonly [K in keyof P as K extends Required ? never : K]?: FromSchema<P[K]>;
|
|
46
|
+
};
|
|
47
|
+
type ValueOf<T, S> = T extends 'string' ? string : T extends 'number' | 'integer' ? number : T extends 'boolean' ? boolean : T extends 'null' ? null : T extends 'array' ? S extends {
|
|
48
|
+
items: infer I extends Schema;
|
|
49
|
+
} ? FromSchema<I>[] : unknown[] : T extends 'object' ? (S extends {
|
|
50
|
+
properties: infer P extends Record<string, Schema>;
|
|
51
|
+
} ? Fields<P, RequiredBy<S>> : S extends {
|
|
52
|
+
additionalProperties: infer V extends Schema;
|
|
53
|
+
} ? Record<string, FromSchema<V>> : S extends {
|
|
54
|
+
patternProperties: {
|
|
55
|
+
'.*': infer V extends Schema;
|
|
56
|
+
};
|
|
57
|
+
} ? Record<string, FromSchema<V>> : Record<string, unknown>) : unknown;
|
|
58
|
+
type ChoiceValue<S, O extends Schema> = O extends {
|
|
59
|
+
type: unknown;
|
|
60
|
+
} ? FromSchema<O> : S extends {
|
|
61
|
+
properties: infer P extends Record<string, Schema>;
|
|
62
|
+
} ? Fields<P, RequiredBy<S> | RequiredBy<O>> : FromSchema<O>;
|
|
63
|
+
/** The type of a value described by a literal operation schema. */
|
|
64
|
+
export type FromSchema<S extends Schema> = S extends {
|
|
65
|
+
const: infer C;
|
|
66
|
+
} ? C : S extends {
|
|
67
|
+
enum: readonly (infer E)[];
|
|
68
|
+
} ? E : S extends {
|
|
69
|
+
oneOf: readonly (infer O extends Schema)[];
|
|
70
|
+
} ? ChoiceValue<S, O> : S extends {
|
|
71
|
+
anyOf: readonly (infer O extends Schema)[];
|
|
72
|
+
} ? ChoiceValue<S, O> : S extends {
|
|
73
|
+
type: readonly (infer T)[];
|
|
74
|
+
} ? ValueOf<T, S> : S extends {
|
|
75
|
+
type: infer T;
|
|
76
|
+
} ? ValueOf<T, S> : unknown;
|
|
77
|
+
/** What is wrong with a value against a schema, in words: the first thing found. Nothing when it fits. */
|
|
78
|
+
export declare function check(schema: Schema, value: unknown, at?: string, forMember?: boolean): string | undefined;
|
|
79
|
+
/** Resolve handles where the declaration asks for them. Leave other values for the schema check. */
|
|
80
|
+
export declare function memberArgs({ member, properties, items }: Schema, value: unknown, idOf: (handle: string) => string): unknown;
|
|
81
|
+
/**
|
|
82
|
+
* The arguments of an HTTP request: what is in the address after `?` (text there is made the number or boolean
|
|
83
|
+
* the declaration asks for), then the JSON body, then the parameters in the path.
|
|
84
|
+
*/
|
|
85
|
+
export declare function httpArgs(schema: Schema, params: Record<string, string>, query: URLSearchParams, body: unknown): Record<string, unknown>;
|
|
86
|
+
/** What a declaration says about the topic an operation is done to (see `Op` in entry.ts). */
|
|
87
|
+
export interface TopicArg {
|
|
88
|
+
topic?: string;
|
|
89
|
+
reach?: 'own' | 'below' | 'any';
|
|
90
|
+
named?: true;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The arguments as a member is shown them. The topic an operation is done to is the member's own, so that argument
|
|
94
|
+
* is not there; where the declaration lets a member point further, it is there and says how far. Member fields
|
|
95
|
+
* say to use an @ handle.
|
|
96
|
+
*/
|
|
97
|
+
export declare function memberInput({ member, secret: _secret, ...input }: Schema, { topic, reach, named }?: TopicArg): Schema;
|
|
98
|
+
export type HttpBinding = readonly [method: string, pattern: string];
|
|
99
|
+
/** What of a declaration the document needs. */
|
|
100
|
+
export interface Described {
|
|
101
|
+
name: string;
|
|
102
|
+
about: string;
|
|
103
|
+
input: Schema;
|
|
104
|
+
output?: Schema;
|
|
105
|
+
sdk?: true;
|
|
106
|
+
http: HttpBinding;
|
|
107
|
+
agent?: true | 'approve';
|
|
108
|
+
}
|
|
109
|
+
/** The OpenAPI 3.1 document of the declared operations. Its schemas are JSON Schema, so the declarations go in as they are. */
|
|
110
|
+
export declare function openapi(groups: {
|
|
111
|
+
name: string;
|
|
112
|
+
about: string;
|
|
113
|
+
}[], ops: Described[], info: {
|
|
114
|
+
title: string;
|
|
115
|
+
version: string;
|
|
116
|
+
}): Record<string, unknown>;
|
|
117
|
+
export {};
|
package/dist/core/ops.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the host can be asked to do is declared once (`entry.op`). The parts of that which only compute are here:
|
|
3
|
+
* checking arguments against a declaration, making the arguments of an HTTP request, and the OpenAPI document.
|
|
4
|
+
*/
|
|
5
|
+
export function object(properties = {}, required = []) {
|
|
6
|
+
return { type: 'object', properties, required, additionalProperties: false };
|
|
7
|
+
}
|
|
8
|
+
export const array = (items) => ({ type: 'array', items });
|
|
9
|
+
const NAMES = { string: '一段文字', number: '数字', integer: '整数', boolean: 'true 或 false', object: '对象', array: '数组', null: 'null' };
|
|
10
|
+
const fits = (type, value) => type === 'null' ? value === null
|
|
11
|
+
: type === 'array' ? Array.isArray(value)
|
|
12
|
+
: type === 'object' ? typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
13
|
+
: type === 'integer' ? Number.isInteger(value)
|
|
14
|
+
: type === 'number' ? typeof value === 'number' && Number.isFinite(value)
|
|
15
|
+
: typeof value === type;
|
|
16
|
+
/** What is wrong with a value against a schema, in words: the first thing found. Nothing when it fits. */
|
|
17
|
+
export function check(schema, value, at = '', forMember = false) {
|
|
18
|
+
const where = at || '参数';
|
|
19
|
+
if (forMember && schema.secret)
|
|
20
|
+
return `${where} 是密钥。可用 fill 请机主在控制台的审批卡里填写`;
|
|
21
|
+
const types = schema.type ? [schema.type].flat() : [];
|
|
22
|
+
if (types.length && !types.some((type) => fits(type, value)))
|
|
23
|
+
return `${where} 要是${types.map((type) => NAMES[type]).join('或 ')}`;
|
|
24
|
+
if (schema.enum && !schema.enum.includes(value))
|
|
25
|
+
return `${where} 只能是 ${schema.enum.map((one) => JSON.stringify(one)).join('、')}`;
|
|
26
|
+
if (Array.isArray(value) && schema.items) {
|
|
27
|
+
for (const [i, item] of value.entries()) {
|
|
28
|
+
const problem = check(schema.items, item, `${at}[${i}]`, forMember);
|
|
29
|
+
if (problem)
|
|
30
|
+
return problem;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (!types.includes('object') || !fits('object', value))
|
|
34
|
+
return undefined;
|
|
35
|
+
const given = value;
|
|
36
|
+
const known = schema.properties ?? {};
|
|
37
|
+
const name = (key) => (at ? `${at}.${key}` : key);
|
|
38
|
+
for (const key of schema.required ?? [])
|
|
39
|
+
if (!Object.hasOwn(given, key) || given[key] === undefined)
|
|
40
|
+
return `缺少 ${name(key)}`;
|
|
41
|
+
for (const [key, one] of Object.entries(given)) {
|
|
42
|
+
if (one === undefined)
|
|
43
|
+
continue;
|
|
44
|
+
const field = Object.hasOwn(known, key) ? known[key] : schema.additionalProperties;
|
|
45
|
+
if (typeof field === 'object') {
|
|
46
|
+
const problem = check(field, one, name(key), forMember);
|
|
47
|
+
if (problem)
|
|
48
|
+
return problem;
|
|
49
|
+
}
|
|
50
|
+
else if (field === false) {
|
|
51
|
+
const fields = Object.keys(known).filter((key) => !forMember || !known[key]?.secret);
|
|
52
|
+
return `没有 ${name(key)} 这个参数${fields.length ? `(有的是:${fields.join('、')})` : '(它不带参数)'}`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
/** Resolve handles where the declaration asks for them. Leave other values for the schema check. */
|
|
58
|
+
export function memberArgs({ member, properties, items }, value, idOf) {
|
|
59
|
+
if (member && typeof value === 'string')
|
|
60
|
+
return idOf(value);
|
|
61
|
+
if (items && Array.isArray(value))
|
|
62
|
+
return value.map((one) => memberArgs(items, one, idOf));
|
|
63
|
+
if (properties && value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
64
|
+
return Object.fromEntries(Object.entries(value).map(([key, one]) => {
|
|
65
|
+
const field = properties[key];
|
|
66
|
+
return [key, field ? memberArgs(field, one, idOf) : one];
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The arguments of an HTTP request: what is in the address after `?` (text there is made the number or boolean
|
|
73
|
+
* the declaration asks for), then the JSON body, then the parameters in the path.
|
|
74
|
+
*/
|
|
75
|
+
export function httpArgs(schema, params, query, body) {
|
|
76
|
+
const asked = {};
|
|
77
|
+
for (const [key, text] of query) {
|
|
78
|
+
const type = schema.properties?.[key]?.type;
|
|
79
|
+
asked[key] = (type === 'number' || type === 'integer') && text.trim() && !Number.isNaN(Number(text)) ? Number(text)
|
|
80
|
+
: type === 'boolean' && (text === 'true' || text === 'false') ? text === 'true'
|
|
81
|
+
: text;
|
|
82
|
+
}
|
|
83
|
+
if (body !== undefined && (typeof body !== 'object' || body === null || Array.isArray(body) || Buffer.isBuffer(body)))
|
|
84
|
+
throw new Error('请求体要是一个 JSON 对象');
|
|
85
|
+
return { ...asked, ...body, ...params };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The arguments as a member is shown them. The topic an operation is done to is the member's own, so that argument
|
|
89
|
+
* is not there; where the declaration lets a member point further, it is there and says how far. Member fields
|
|
90
|
+
* say to use an @ handle.
|
|
91
|
+
*/
|
|
92
|
+
export function memberInput({ member, secret: _secret, ...input }, { topic, reach, named } = {}) {
|
|
93
|
+
if (member)
|
|
94
|
+
input.description = [input.description, '成员的 @ 名,比如 @kimi'].filter(Boolean).join('。');
|
|
95
|
+
if (input.items)
|
|
96
|
+
input.items = memberInput(input.items);
|
|
97
|
+
if (input.properties) {
|
|
98
|
+
const properties = input.properties;
|
|
99
|
+
if (input.required)
|
|
100
|
+
input.required = input.required.filter((key) => !properties[key]?.secret);
|
|
101
|
+
input.properties = Object.fromEntries(Object.entries(properties).filter(([, field]) => !field.secret).map(([key, field]) => [key, memberInput(field)]));
|
|
102
|
+
}
|
|
103
|
+
const arg = topic ? input.properties?.[topic] : undefined;
|
|
104
|
+
if (!topic || !arg)
|
|
105
|
+
return input;
|
|
106
|
+
const required = (input.required ?? []).filter((key) => key !== topic || (reach && named));
|
|
107
|
+
if (!reach)
|
|
108
|
+
return { ...input, properties: Object.fromEntries(Object.entries(input.properties).filter(([key]) => key !== topic)), required };
|
|
109
|
+
const how = [
|
|
110
|
+
named ? '' : '不填就是你所在的主题',
|
|
111
|
+
reach === 'own' ? '可直接操作你所在的主题。其他主题要人批准,用 host_invoke 带 why 提请' : '',
|
|
112
|
+
reach === 'below' ? '可直接操作你所在的主题和它下面的主题。范围之外要人批准,用 host_invoke 带 why 提请' : '',
|
|
113
|
+
];
|
|
114
|
+
return { ...input, properties: { ...input.properties, [topic]: { ...arg, description: [arg.description, ...how].filter(Boolean).join(';') } }, required };
|
|
115
|
+
}
|
|
116
|
+
/** The OpenAPI 3.1 document of the declared operations. Its schemas are JSON Schema, so the declarations go in as they are. */
|
|
117
|
+
export function openapi(groups, ops, info) {
|
|
118
|
+
const paths = {};
|
|
119
|
+
for (const op of ops) {
|
|
120
|
+
const [method, pattern] = op.http;
|
|
121
|
+
const inPath = pattern.split('/').filter((part) => part.startsWith(':')).map((part) => part.slice(1));
|
|
122
|
+
const rest = Object.entries(op.input.properties ?? {}).filter(([key]) => !inPath.includes(key));
|
|
123
|
+
const required = (op.input.required ?? []).filter((key) => !inPath.includes(key));
|
|
124
|
+
const inQuery = method === 'GET' || method === 'DELETE';
|
|
125
|
+
(paths[pattern.replace(/:([^/]+)/g, '{$1}')] ??= {})[method.toLowerCase()] = {
|
|
126
|
+
operationId: op.name,
|
|
127
|
+
tags: [op.name.split('.')[0]],
|
|
128
|
+
summary: op.about,
|
|
129
|
+
...(op.agent ? { 'x-agent': op.agent } : {}),
|
|
130
|
+
...(op.sdk ? { 'x-sdk': true } : {}),
|
|
131
|
+
parameters: [
|
|
132
|
+
...inPath.map((key) => ({ name: key, in: 'path', required: true, schema: op.input.properties?.[key] ?? { type: 'string' } })),
|
|
133
|
+
...(inQuery ? rest.map(([key, schema]) => ({ name: key, in: 'query', required: required.includes(key), schema })) : []),
|
|
134
|
+
],
|
|
135
|
+
...(!inQuery && rest.length ? { requestBody: { required: required.length > 0, content: { 'application/json': { schema: { type: 'object', properties: Object.fromEntries(rest), required, additionalProperties: false } } } } } : {}),
|
|
136
|
+
responses: {
|
|
137
|
+
200: {
|
|
138
|
+
description: '结果,JSON',
|
|
139
|
+
...(op.output ? { content: { 'application/json': { schema: op.output } } } : {}),
|
|
140
|
+
},
|
|
141
|
+
400: { description: '参数不对,或这件事现在做不了:{ error }' },
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return { openapi: '3.1.0', info, tags: groups.map(({ name, about }) => ({ name, description: about })), paths };
|
|
146
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
/** Find the assets of a dependency even when it only exports its entry point. */
|
|
5
|
+
export function packageRoot(name, from) {
|
|
6
|
+
let dir = dirname(createRequire(from).resolve(name));
|
|
7
|
+
while (!existsSync(join(dir, 'package.json'))) {
|
|
8
|
+
const parent = dirname(dir);
|
|
9
|
+
if (parent === dir)
|
|
10
|
+
throw new Error(`Could not locate package.json for ${name}`);
|
|
11
|
+
dir = parent;
|
|
12
|
+
}
|
|
13
|
+
return dir;
|
|
14
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { InstanceEvent, Part } from './types.ts';
|
|
2
|
+
export declare function cleanExternalText(text: string): string;
|
|
3
|
+
/** Normalize external text before storing or projecting it. Keep the rest of the message in order. */
|
|
4
|
+
export declare function cleanIncomingParts(parts: Part[], external: boolean): Part[];
|
|
5
|
+
export declare const EXCERPT_MARK = "[external excerpt]";
|
|
6
|
+
/** All text-only readers write each excerpt as a single line of JSON after the ordinary body. */
|
|
7
|
+
export declare function withExcerpts(message: {
|
|
8
|
+
parts: Part[];
|
|
9
|
+
}, body: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Put one event of a turn into the parts of its reply, in the order things arrived. Returns which part changed
|
|
12
|
+
* and, when text only grew, by what; nothing for events that are not content.
|
|
13
|
+
*/
|
|
14
|
+
export declare function foldEvent(parts: Part[], event: InstanceEvent, startText?: boolean): {
|
|
15
|
+
index: number;
|
|
16
|
+
delta?: string;
|
|
17
|
+
} | undefined;
|
|
18
|
+
/** What a reply says: its text pieces, without the thinking and the tool calls between them. */
|
|
19
|
+
export declare const textOf: (parts: Part[]) => string;
|
|
20
|
+
/** A history row needs a count, while the execution view can read the original steps. */
|
|
21
|
+
export declare function stepSummary(parts: Part[]): {
|
|
22
|
+
count: number;
|
|
23
|
+
tools: number;
|
|
24
|
+
failed: number;
|
|
25
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { stripVTControlCharacters } from 'node:util';
|
|
2
|
+
export function cleanExternalText(text) {
|
|
3
|
+
return stripVTControlCharacters(text).replace(/\r\n?|[\u2028\u2029]/gu, '\n')
|
|
4
|
+
.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F\p{Bidi_Control}\u200B\u2063\u206A-\u206F\uFEFF]/gu, '');
|
|
5
|
+
}
|
|
6
|
+
function shorten(text, limit) {
|
|
7
|
+
const points = [...text.slice(0, limit * 2 + 1)];
|
|
8
|
+
return points.length <= limit ? text : points.slice(0, limit - 1).join('') + '…';
|
|
9
|
+
}
|
|
10
|
+
function fitBytes(text, limit) {
|
|
11
|
+
const bytes = Buffer.from(text);
|
|
12
|
+
if (bytes.length <= limit)
|
|
13
|
+
return text;
|
|
14
|
+
const ellipsis = '…';
|
|
15
|
+
let end = limit - Buffer.byteLength(ellipsis);
|
|
16
|
+
if (end < 0)
|
|
17
|
+
return '';
|
|
18
|
+
while ((bytes[end] & 0xc0) === 0x80)
|
|
19
|
+
end--;
|
|
20
|
+
return bytes.toString('utf8', 0, end) + ellipsis;
|
|
21
|
+
}
|
|
22
|
+
function excerptLabel(text) {
|
|
23
|
+
return typeof text === 'string' ? shorten(cleanExternalText(text).replace(/\s+/gu, ' ').trim(), 160) : '';
|
|
24
|
+
}
|
|
25
|
+
function excerptUrl(value) {
|
|
26
|
+
const limit = 2048;
|
|
27
|
+
if (typeof value !== 'string' || value.length > limit)
|
|
28
|
+
return;
|
|
29
|
+
const url = URL.parse(value);
|
|
30
|
+
if (url && (url.protocol === 'https:' || url.protocol === 'http:') &&
|
|
31
|
+
!url.username && !url.password && url.href.length <= limit && cleanExternalText(value) === value)
|
|
32
|
+
return url.href;
|
|
33
|
+
}
|
|
34
|
+
/** Normalize external text before storing or projecting it. Keep the rest of the message in order. */
|
|
35
|
+
export function cleanIncomingParts(parts, external) {
|
|
36
|
+
let remaining = 2500, excerpts = 0;
|
|
37
|
+
return parts.flatMap((part) => {
|
|
38
|
+
if (part.type !== 'excerpt') {
|
|
39
|
+
return [external && part.type === 'text' ? { ...part, text: cleanExternalText(part.text) } : part];
|
|
40
|
+
}
|
|
41
|
+
if (!remaining || excerpts >= 10 || typeof part.text !== 'string')
|
|
42
|
+
return [];
|
|
43
|
+
const text = fitBytes(shorten(cleanExternalText(part.text).trim(), 500), remaining);
|
|
44
|
+
if (!text)
|
|
45
|
+
return [];
|
|
46
|
+
remaining -= Buffer.byteLength(text);
|
|
47
|
+
excerpts++;
|
|
48
|
+
const title = excerptLabel(part.title), author = excerptLabel(part.author), url = excerptUrl(part.url);
|
|
49
|
+
return [{ type: 'excerpt', text, ...(title && { title }), ...(author && { author }), ...(url && { url }) }];
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export const EXCERPT_MARK = '[external excerpt]';
|
|
53
|
+
/** All text-only readers write each excerpt as a single line of JSON after the ordinary body. */
|
|
54
|
+
export function withExcerpts(message, body) {
|
|
55
|
+
const quotes = message.parts.flatMap((part) => part.type === 'excerpt'
|
|
56
|
+
? [EXCERPT_MARK + ' ' + JSON.stringify({ title: part.title, author: part.author, url: part.url, text: part.text })]
|
|
57
|
+
: []);
|
|
58
|
+
return quotes.length ? [body, ...quotes].join('\n') : body;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Put one event of a turn into the parts of its reply, in the order things arrived. Returns which part changed
|
|
62
|
+
* and, when text only grew, by what; nothing for events that are not content.
|
|
63
|
+
*/
|
|
64
|
+
export function foldEvent(parts, event, startText = false) {
|
|
65
|
+
switch (event.type) {
|
|
66
|
+
case 'text':
|
|
67
|
+
case 'thinking': {
|
|
68
|
+
if (!event.delta)
|
|
69
|
+
return undefined;
|
|
70
|
+
const last = parts.at(-1);
|
|
71
|
+
if (!startText && last?.type === event.type) {
|
|
72
|
+
last.text += event.delta;
|
|
73
|
+
return { index: parts.length - 1, delta: event.delta };
|
|
74
|
+
}
|
|
75
|
+
// Keep the whitespace inside a piece, without starting one for whitespace alone.
|
|
76
|
+
const text = event.delta.replace(/^\s+/, '');
|
|
77
|
+
if (!text)
|
|
78
|
+
return undefined;
|
|
79
|
+
parts.push({ type: event.type, text });
|
|
80
|
+
return { index: parts.length - 1 };
|
|
81
|
+
}
|
|
82
|
+
case 'tool': {
|
|
83
|
+
let index = parts.findIndex((p) => p.type === 'tool' && p.id === event.id);
|
|
84
|
+
if (index < 0)
|
|
85
|
+
index = parts.push({ type: 'tool', id: event.id, name: event.name ?? 'tool', status: 'running' }) - 1;
|
|
86
|
+
const part = parts[index];
|
|
87
|
+
if (event.name)
|
|
88
|
+
part.name = event.name;
|
|
89
|
+
if (event.agent)
|
|
90
|
+
part.agent = true;
|
|
91
|
+
if (event.input !== undefined)
|
|
92
|
+
part.input = event.input;
|
|
93
|
+
if (event.output !== undefined)
|
|
94
|
+
part.output = event.output;
|
|
95
|
+
if (event.phase === 'end')
|
|
96
|
+
part.status = event.failed ? 'failed' : 'done';
|
|
97
|
+
return { index };
|
|
98
|
+
}
|
|
99
|
+
default:
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** What a reply says: its text pieces, without the thinking and the tool calls between them. */
|
|
104
|
+
export const textOf = (parts) => parts.flatMap((p) => p.type === 'text' ? [p.text.trim()] : []).filter(Boolean).join('\n\n');
|
|
105
|
+
/** A history row needs a count, while the execution view can read the original steps. */
|
|
106
|
+
export function stepSummary(parts) {
|
|
107
|
+
let count = 0, tools = 0, failed = 0;
|
|
108
|
+
for (const part of parts) {
|
|
109
|
+
if (part.type === 'thinking')
|
|
110
|
+
count++;
|
|
111
|
+
if (part.type === 'tool') {
|
|
112
|
+
count++;
|
|
113
|
+
tools++;
|
|
114
|
+
if (part.status === 'failed')
|
|
115
|
+
failed++;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return { count, tools, failed };
|
|
119
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface CatalogEntry {
|
|
2
|
+
package: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function pluginCatalog(addresses: string[]): Promise<({
|
|
7
|
+
address: string;
|
|
8
|
+
plugins: CatalogEntry[];
|
|
9
|
+
error?: undefined;
|
|
10
|
+
} | {
|
|
11
|
+
address: string;
|
|
12
|
+
plugins: never[];
|
|
13
|
+
error: string;
|
|
14
|
+
})[]>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { isNpmPackage } from "./npm.js";
|
|
2
|
+
const CATALOG_LIMIT = 1024 * 1024;
|
|
3
|
+
async function readCatalog(address) {
|
|
4
|
+
const url = new URL(address);
|
|
5
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password) {
|
|
6
|
+
throw new Error('目录源必须是没有内嵌凭据的 HTTP 或 HTTPS 地址');
|
|
7
|
+
}
|
|
8
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(10_000), headers: { accept: 'application/json' } });
|
|
9
|
+
if (!response.ok || !response.body)
|
|
10
|
+
throw new Error(`目录请求失败(HTTP ${response.status})`);
|
|
11
|
+
const reader = response.body.getReader();
|
|
12
|
+
const chunks = [];
|
|
13
|
+
let size = 0;
|
|
14
|
+
try {
|
|
15
|
+
for (;;) {
|
|
16
|
+
const { done, value } = await reader.read();
|
|
17
|
+
if (done)
|
|
18
|
+
break;
|
|
19
|
+
size += value.byteLength;
|
|
20
|
+
if (size > CATALOG_LIMIT)
|
|
21
|
+
throw new Error('插件目录超过 1 MiB');
|
|
22
|
+
chunks.push(value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
await reader.cancel().catch(() => { });
|
|
27
|
+
}
|
|
28
|
+
const data = JSON.parse(Buffer.concat(chunks, size).toString('utf8'));
|
|
29
|
+
if (!data || typeof data !== 'object' || !('plugins' in data) || !Array.isArray(data.plugins)) {
|
|
30
|
+
throw new Error('需要包含 plugins 列表的 JSON 目录');
|
|
31
|
+
}
|
|
32
|
+
const plugins = new Map();
|
|
33
|
+
for (const item of data.plugins) {
|
|
34
|
+
if (!item || !isNpmPackage(item.package) || plugins.has(item.package))
|
|
35
|
+
continue;
|
|
36
|
+
const { name, description } = item;
|
|
37
|
+
plugins.set(item.package, {
|
|
38
|
+
package: item.package,
|
|
39
|
+
...(typeof name === 'string' && name.trim() ? { name: name.trim().slice(0, 160) } : {}),
|
|
40
|
+
...(typeof description === 'string' && description.trim() ? { description: description.trim().slice(0, 500) } : {}),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return Array.from(plugins.values());
|
|
44
|
+
}
|
|
45
|
+
export function pluginCatalog(addresses) {
|
|
46
|
+
return Promise.all(Array.from(new Set(addresses), async (address) => {
|
|
47
|
+
try {
|
|
48
|
+
return { address, plugins: await readCatalog(address) };
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
return { address, plugins: [], error: error instanceof Error ? error.message : '目录请求失败' };
|
|
52
|
+
}
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Home } from '../home.ts';
|
|
2
|
+
import type { Plugin, Runtime } from '../../runtime/runtime.ts';
|
|
3
|
+
/** Owns the registry of shipped and installed packages. Mutations use the host's plugin change queue. */
|
|
4
|
+
export declare function pluginPackages(home: Home, runtime: Runtime): {
|
|
5
|
+
plugin: Plugin;
|
|
6
|
+
load: (extra?: readonly Plugin[], root?: string) => Promise<string[]>;
|
|
7
|
+
};
|