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,355 @@
|
|
|
1
|
+
export default function (ui) {
|
|
2
|
+
const POPUP = 'hl.sessions.adopt';
|
|
3
|
+
const models = {}, actions = {}, inputs = {}, changes = {};
|
|
4
|
+
const t = ui.t;
|
|
5
|
+
const state = {
|
|
6
|
+
topicId: '', data: null, dirty: true, seq: 0,
|
|
7
|
+
selectionGen: 0, opSeq: 0, op: null,
|
|
8
|
+
memberId: '', cwd: '', cwdTouched: false, sessionId: '',
|
|
9
|
+
error: '',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function resetDraft() {
|
|
13
|
+
state.op = null;
|
|
14
|
+
state.cwd = '';
|
|
15
|
+
state.cwdTouched = false;
|
|
16
|
+
state.sessionId = '';
|
|
17
|
+
state.error = '';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function sameTopic(topicId) {
|
|
21
|
+
return !!topicId && HL.topic?.id === topicId && state.topicId === topicId;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function sameSelection(scope) {
|
|
25
|
+
return !!scope
|
|
26
|
+
&& sameTopic(scope.topicId)
|
|
27
|
+
&& !!S.popOn?.[POPUP]
|
|
28
|
+
&& state.selectionGen === scope.selectionGen;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function activeOp() {
|
|
32
|
+
return state.op && sameSelection(state.op) ? state.op : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function captureScope(kind, extra) {
|
|
36
|
+
const topicId = HL.topic?.id || '';
|
|
37
|
+
const member = currentMember(currentData());
|
|
38
|
+
return Object.assign({
|
|
39
|
+
seq: ++state.opSeq,
|
|
40
|
+
kind,
|
|
41
|
+
topicId,
|
|
42
|
+
selectionGen: state.selectionGen,
|
|
43
|
+
memberId: extra?.memberId ?? member?.id ?? '',
|
|
44
|
+
sessionId: extra?.sessionId ?? '',
|
|
45
|
+
}, extra || {});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function syncSelection(data) {
|
|
49
|
+
const members = data?.members || [];
|
|
50
|
+
if (!members.length) {
|
|
51
|
+
state.memberId = '';
|
|
52
|
+
state.selectionGen++;
|
|
53
|
+
resetDraft();
|
|
54
|
+
if (S.popOn?.[POPUP]) popClose(POPUP, true);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (!members.some(function (m) { return m.id === state.memberId; })) {
|
|
58
|
+
const preferred = data.found && members.some(function (m) { return m.id === data.found.memberId; })
|
|
59
|
+
? data.found.memberId
|
|
60
|
+
: members[0].id;
|
|
61
|
+
state.memberId = preferred;
|
|
62
|
+
}
|
|
63
|
+
if (!state.cwdTouched) {
|
|
64
|
+
const foundCwd = data.found && data.found.memberId === state.memberId ? data.found.cwd : '';
|
|
65
|
+
state.cwd = foundCwd || data.dirs?.[0] || '';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function load(topicId) {
|
|
70
|
+
if (!topicId || HL.topic?.id !== topicId) return;
|
|
71
|
+
const topicChanged = state.topicId !== topicId;
|
|
72
|
+
state.topicId = topicId;
|
|
73
|
+
state.dirty = false;
|
|
74
|
+
if (topicChanged) {
|
|
75
|
+
state.data = null;
|
|
76
|
+
state.memberId = '';
|
|
77
|
+
state.selectionGen++;
|
|
78
|
+
resetDraft();
|
|
79
|
+
if (S.popOn?.[POPUP]) popClose(POPUP, true);
|
|
80
|
+
}
|
|
81
|
+
const seq = ++state.seq;
|
|
82
|
+
return ui.request('GET', '/api/topics/' + encodeURIComponent(topicId) + '/sessions').then(function (data) {
|
|
83
|
+
if (seq !== state.seq || !sameTopic(topicId)) return;
|
|
84
|
+
state.data = data;
|
|
85
|
+
syncSelection(data);
|
|
86
|
+
render(true);
|
|
87
|
+
}, function (err) {
|
|
88
|
+
if (seq !== state.seq || !sameTopic(topicId)) return;
|
|
89
|
+
ui.fail(err);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function markDirty() {
|
|
94
|
+
state.dirty = true;
|
|
95
|
+
if (HL.topic && (ui.shown('run') || S.popOn?.[POPUP])) load(HL.topic.id);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function currentData() {
|
|
99
|
+
const id = HL.topic?.id || '';
|
|
100
|
+
return id && state.topicId === id ? state.data : null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function currentMember(data) {
|
|
104
|
+
const list = data?.members || [];
|
|
105
|
+
return list.find(function (m) { return m.id === state.memberId; }) || list[0] || null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function readInput(id, fallback) {
|
|
109
|
+
const el = document.getElementById(id);
|
|
110
|
+
return el ? el.value : fallback;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function finishOp(scope) {
|
|
114
|
+
if (state.op?.seq === scope.seq) state.op = null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function runFind(cwd) {
|
|
118
|
+
const id = HL.topic?.id, data = currentData(), member = currentMember(data);
|
|
119
|
+
if (!id || !member || !S.popOn?.[POPUP] || activeOp()) return;
|
|
120
|
+
const dir = String(cwd || '').trim();
|
|
121
|
+
state.cwd = dir;
|
|
122
|
+
state.cwdTouched = true;
|
|
123
|
+
if (!dir) {
|
|
124
|
+
state.error = t('needCwd');
|
|
125
|
+
render(true);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const scope = captureScope('find', { memberId: member.id });
|
|
129
|
+
state.error = '';
|
|
130
|
+
state.op = scope;
|
|
131
|
+
render(true);
|
|
132
|
+
return ui.request('POST', '/api/topics/' + encodeURIComponent(id) + '/sessions/find', { memberId: member.id, cwd: dir })
|
|
133
|
+
.then(function () {
|
|
134
|
+
finishOp(scope);
|
|
135
|
+
if (!sameSelection(scope)) return;
|
|
136
|
+
return load(scope.topicId);
|
|
137
|
+
}, function (err) {
|
|
138
|
+
finishOp(scope);
|
|
139
|
+
if (!sameSelection(scope)) return;
|
|
140
|
+
state.error = err?.message || String(err);
|
|
141
|
+
render(true);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function runAdopt(memberId, sessionId, fromInput) {
|
|
146
|
+
const id = HL.topic?.id;
|
|
147
|
+
if (!id || !memberId || !S.popOn?.[POPUP] || activeOp()) return;
|
|
148
|
+
const sid = String(sessionId || '').trim();
|
|
149
|
+
if (!sid) {
|
|
150
|
+
state.error = t('needId');
|
|
151
|
+
render(true);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const scope = captureScope(fromInput ? 'adoptInput' : 'adoptRow', { memberId, sessionId: sid });
|
|
155
|
+
state.error = '';
|
|
156
|
+
state.op = scope;
|
|
157
|
+
render(true);
|
|
158
|
+
return ui.request('POST', '/api/topics/' + encodeURIComponent(id) + '/sessions/adopt', { memberId, sessionId: sid })
|
|
159
|
+
.then(function () {
|
|
160
|
+
finishOp(scope);
|
|
161
|
+
if (sameSelection(scope)) {
|
|
162
|
+
state.sessionId = '';
|
|
163
|
+
state.error = '';
|
|
164
|
+
popClose(POPUP, true);
|
|
165
|
+
}
|
|
166
|
+
if (!sameTopic(scope.topicId)) return;
|
|
167
|
+
return load(scope.topicId);
|
|
168
|
+
}, function (err) {
|
|
169
|
+
finishOp(scope);
|
|
170
|
+
if (!sameSelection(scope)) return;
|
|
171
|
+
state.error = err?.message || String(err);
|
|
172
|
+
render(true);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
models.hlSessionsRun = function () {
|
|
177
|
+
const id = HL.topic?.id || '';
|
|
178
|
+
if (!id) return { visible: false };
|
|
179
|
+
if (state.topicId !== id || (state.dirty && ui.shown('run'))) load(id);
|
|
180
|
+
const data = currentData();
|
|
181
|
+
return { visible: !!(data && data.members.length) };
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
models.hlSessionsAdopt = function () {
|
|
185
|
+
const id = HL.topic?.id || '';
|
|
186
|
+
const data = currentData();
|
|
187
|
+
if (!id || !data || !data.members.length) return { visible: false };
|
|
188
|
+
const member = currentMember(data);
|
|
189
|
+
if (!member) return { visible: false };
|
|
190
|
+
const found = data.found && data.found.memberId === member.id ? data.found : null;
|
|
191
|
+
const op = activeOp();
|
|
192
|
+
const finding = op?.kind === 'find';
|
|
193
|
+
const adoptingInput = op?.kind === 'adoptInput';
|
|
194
|
+
const adoptingId = op?.kind === 'adoptRow' ? op.sessionId : '';
|
|
195
|
+
const busy = !!op;
|
|
196
|
+
const foundRows = found ? found.sessions.map(function (s) {
|
|
197
|
+
return {
|
|
198
|
+
id: 's:' + s.id,
|
|
199
|
+
title: s.title || s.id,
|
|
200
|
+
memberId: found.memberId,
|
|
201
|
+
sessionId: s.id,
|
|
202
|
+
sub: [s.title && s.id, s.cwd, s.updatedAt ? new Date(s.updatedAt).toLocaleString() : ''].filter(Boolean).join(' · '),
|
|
203
|
+
state: s.topicId ? t('inTopic', s.topicTitle || s.topicId) : s.held ? (s.held.pid ? t('heldPid', s.held.pid) : t('held')) : '',
|
|
204
|
+
canAdopt: !s.topicId,
|
|
205
|
+
busy: adoptingId === s.id,
|
|
206
|
+
disabled: busy,
|
|
207
|
+
};
|
|
208
|
+
}) : [];
|
|
209
|
+
const dirs = data.dirs || [];
|
|
210
|
+
return {
|
|
211
|
+
visible: true,
|
|
212
|
+
error: state.error,
|
|
213
|
+
busy,
|
|
214
|
+
finding,
|
|
215
|
+
adoptingInput,
|
|
216
|
+
memberIds: data.members.map(function (m) { return m.id; }),
|
|
217
|
+
memberId: member.id,
|
|
218
|
+
memberHint: member.sessionId ? t('hasSession', member.sessionId) : t('noSession'),
|
|
219
|
+
cwd: state.cwd,
|
|
220
|
+
cwdHelp: t('cwdHelp', member.name),
|
|
221
|
+
hasMultiDirs: dirs.length > 1,
|
|
222
|
+
hasFound: !!found,
|
|
223
|
+
foundRows,
|
|
224
|
+
foundEmpty: found ? t('foundEmpty', found.cwd) : '',
|
|
225
|
+
sessionId: state.sessionId,
|
|
226
|
+
idHelp: t('idHelp', member.name),
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
actions.hlSessOpen = function () {
|
|
231
|
+
const id = HL.topic?.id;
|
|
232
|
+
if (!id) return;
|
|
233
|
+
state.selectionGen++;
|
|
234
|
+
resetDraft();
|
|
235
|
+
const data = currentData();
|
|
236
|
+
if (data) syncSelection(data);
|
|
237
|
+
else load(id);
|
|
238
|
+
S.popOn[POPUP] = true;
|
|
239
|
+
render(true);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
changes.hlSessMember = function (e) {
|
|
243
|
+
const next = e.target?.value || '';
|
|
244
|
+
if (!next || next === state.memberId) return;
|
|
245
|
+
state.memberId = next;
|
|
246
|
+
state.selectionGen++;
|
|
247
|
+
state.op = null;
|
|
248
|
+
state.error = '';
|
|
249
|
+
state.sessionId = '';
|
|
250
|
+
const data = currentData();
|
|
251
|
+
if (data && !state.cwdTouched) {
|
|
252
|
+
const foundCwd = data.found && data.found.memberId === next ? data.found.cwd : '';
|
|
253
|
+
state.cwd = foundCwd || data.dirs?.[0] || '';
|
|
254
|
+
}
|
|
255
|
+
render(true);
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
inputs.hlSessCwdInput = function (e) {
|
|
259
|
+
state.cwd = e.target?.value || '';
|
|
260
|
+
state.cwdTouched = true;
|
|
261
|
+
};
|
|
262
|
+
changes.hlSessCwdInput = inputs.hlSessCwdInput;
|
|
263
|
+
|
|
264
|
+
actions.hlSessDirMenu = function (_d, el) {
|
|
265
|
+
const dirs = currentData()?.dirs || [];
|
|
266
|
+
if (!dirs.length) return;
|
|
267
|
+
const cur = readInput('hl-sess-cwd', state.cwd).trim();
|
|
268
|
+
S.menu = {
|
|
269
|
+
items: dirs.map(function (dir) {
|
|
270
|
+
return { label: dir, cur: dir === cur, act: ui.key('hlSessDirPick'), data: { dir } };
|
|
271
|
+
}),
|
|
272
|
+
};
|
|
273
|
+
menuAnchor(el);
|
|
274
|
+
render(true);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
actions.hlSessDirPick = function (d) {
|
|
278
|
+
const dir = d?.dir || '';
|
|
279
|
+
if (!dir) return;
|
|
280
|
+
state.cwd = dir;
|
|
281
|
+
state.cwdTouched = true;
|
|
282
|
+
state.error = '';
|
|
283
|
+
render(true);
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
actions.hlSessPickDir = function () {
|
|
287
|
+
if (!S.popOn?.[POPUP] || activeOp()) return;
|
|
288
|
+
const scope = captureScope('pickDir');
|
|
289
|
+
if (!scope.topicId || !scope.memberId) return;
|
|
290
|
+
hlDirPick(t('pickDir'), function (path) {
|
|
291
|
+
if (!path || !sameSelection(scope)) return;
|
|
292
|
+
runFind(path);
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
actions.hlSessFind = function () {
|
|
297
|
+
return runFind(readInput('hl-sess-cwd', state.cwd));
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
inputs.hlSessIdInput = function (e) {
|
|
301
|
+
state.sessionId = e.target?.value || '';
|
|
302
|
+
};
|
|
303
|
+
changes.hlSessIdInput = inputs.hlSessIdInput;
|
|
304
|
+
|
|
305
|
+
actions.hlSessAdoptInput = function () {
|
|
306
|
+
const member = currentMember(currentData());
|
|
307
|
+
if (!member) return;
|
|
308
|
+
const sid = readInput('hl-sess-id', state.sessionId);
|
|
309
|
+
state.sessionId = sid;
|
|
310
|
+
return runAdopt(member.id, sid, true);
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
actions.hlSessAdopt = function (d) {
|
|
314
|
+
return runAdopt(d.memberId, d.sessionId, false);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
actions.hlSessClear = function () {
|
|
318
|
+
const id = HL.topic?.id;
|
|
319
|
+
if (!id || !S.popOn?.[POPUP]) return;
|
|
320
|
+
const scope = captureScope('clear');
|
|
321
|
+
state.error = '';
|
|
322
|
+
return ui.request('DELETE', '/api/topics/' + encodeURIComponent(id) + '/sessions/found')
|
|
323
|
+
.then(function () {
|
|
324
|
+
if (!sameSelection(scope)) return;
|
|
325
|
+
return load(scope.topicId);
|
|
326
|
+
}, function (err) {
|
|
327
|
+
if (!sameSelection(scope)) return;
|
|
328
|
+
state.error = err?.message || String(err);
|
|
329
|
+
render(true);
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
return {
|
|
334
|
+
models, actions, inputs, changes,
|
|
335
|
+
events: {
|
|
336
|
+
'topic.updated': markDirty,
|
|
337
|
+
'instances.changed': markDirty,
|
|
338
|
+
},
|
|
339
|
+
update() {
|
|
340
|
+
const id = HL.topic?.id || '';
|
|
341
|
+
if (!id) {
|
|
342
|
+
state.selectionGen++;
|
|
343
|
+
resetDraft();
|
|
344
|
+
if (S.popOn?.[POPUP]) popClose(POPUP, true);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if ((ui.shown('run') || S.popOn?.[POPUP]) && (state.topicId !== id || state.dirty)) load(id);
|
|
348
|
+
},
|
|
349
|
+
dispose() {
|
|
350
|
+
state.selectionGen++;
|
|
351
|
+
resetDraft();
|
|
352
|
+
if (S.popOn?.[POPUP]) delete S.popOn[POPUP];
|
|
353
|
+
},
|
|
354
|
+
};
|
|
355
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { existsSync, statSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute } from 'node:path';
|
|
3
|
+
import { HttpError, object, OWNER_ID, requireTopic } from 'hostlet/sdk';
|
|
4
|
+
import { topicParticipants } from "./participants.js";
|
|
5
|
+
/** What was found is shown for this long; a session list goes stale as sessions are opened and closed elsewhere. */
|
|
6
|
+
const FOUND_MS = 10 * 60_000;
|
|
7
|
+
export const sessionsPlugin = {
|
|
8
|
+
name: 'sessions',
|
|
9
|
+
title: '接上已有会话',
|
|
10
|
+
about: '把成员的客户端在 Hostlet 外面已有的会话接进一个主题。之后在这个主题里叫它,就会在原会话里接着说。适配器需支持按目录列举和续接已有会话。',
|
|
11
|
+
group: '主题页',
|
|
12
|
+
needs: ['instances', 'members', 'topics', 'messages', 'entry', 'a2a'],
|
|
13
|
+
start(ctx) {
|
|
14
|
+
const instances = ctx.get('instances');
|
|
15
|
+
const members = ctx.get('members');
|
|
16
|
+
const topics = ctx.get('topics');
|
|
17
|
+
const messages = ctx.get('messages');
|
|
18
|
+
const entry = ctx.get('entry');
|
|
19
|
+
ctx.effect(entry.op({
|
|
20
|
+
name: 'channel.participants', about: '查看在一个主题里参与过的成员、会话与执行状态。',
|
|
21
|
+
input: object({ id: { type: 'string', description: '主题编号' } }, ['id']), http: ['GET', '/api/topics/:id/participants'], agent: true, topic: 'id', reach: 'any',
|
|
22
|
+
async run({ id }, caller) {
|
|
23
|
+
const history = messages.forMember(caller.member?.id ?? OWNER_ID);
|
|
24
|
+
const list = topicParticipants(ctx.runtime, requireTopic(topics, id).id);
|
|
25
|
+
return Promise.all(list.map(async (participant) => {
|
|
26
|
+
const last = participant.lastTurn;
|
|
27
|
+
const member = !participant.removed ? members.get(participant.memberId) : undefined;
|
|
28
|
+
const contextMark = member ? (await ctx.runtime.serial('member.contextMark', { member })).find(Boolean) : undefined;
|
|
29
|
+
return {
|
|
30
|
+
...participant,
|
|
31
|
+
...(last?.error && !history.get(last.replyId, { includeDeleted: true }) ? { lastTurn: { ...last, error: null } } : {}),
|
|
32
|
+
...(contextMark ? { contextMark } : {}),
|
|
33
|
+
};
|
|
34
|
+
}));
|
|
35
|
+
},
|
|
36
|
+
}));
|
|
37
|
+
/** Per topic: the sessions last looked for there, until one is taken or they are put away. */
|
|
38
|
+
const found = new Map();
|
|
39
|
+
const latestFind = new Map();
|
|
40
|
+
let findSeq = 0;
|
|
41
|
+
const able = () => {
|
|
42
|
+
const can = new Set(instances.adapters().filter(({ adapter }) => adapter.sessions).map(({ name }) => name));
|
|
43
|
+
return members.list().filter((m) => m.enabled && can.has(m.adapter));
|
|
44
|
+
};
|
|
45
|
+
const find = async (topicId, memberId, cwd) => {
|
|
46
|
+
if (!isAbsolute(cwd))
|
|
47
|
+
throw new Error('要写目录的完整路径');
|
|
48
|
+
if (!existsSync(cwd) || !statSync(cwd).isDirectory())
|
|
49
|
+
throw new Error(`没有这个目录:${cwd}`);
|
|
50
|
+
const seq = ++findSeq;
|
|
51
|
+
latestFind.set(topicId, { seq, memberId });
|
|
52
|
+
const sessions = await instances.sessions(memberId, cwd);
|
|
53
|
+
if (latestFind.get(topicId)?.seq === seq)
|
|
54
|
+
found.set(topicId, { memberId, cwd, at: Date.now(), sessions });
|
|
55
|
+
return { cwd, sessions };
|
|
56
|
+
};
|
|
57
|
+
const adopt = async (topicId, memberId, sessionId) => {
|
|
58
|
+
const looked = found.get(topicId);
|
|
59
|
+
const known = looked?.memberId === memberId ? looked.sessions.find((s) => s.id === sessionId.trim()) : undefined;
|
|
60
|
+
const taken = await instances.adopt(topicId, memberId, sessionId);
|
|
61
|
+
if (found.get(topicId)?.memberId === memberId)
|
|
62
|
+
found.delete(topicId);
|
|
63
|
+
if (latestFind.get(topicId)?.memberId === memberId)
|
|
64
|
+
latestFind.delete(topicId);
|
|
65
|
+
messages.publish({
|
|
66
|
+
topicId, from: { kind: 'system', id: '会话' },
|
|
67
|
+
content: [
|
|
68
|
+
`${members.get(memberId)?.name ?? '成员'} 接上了它在别处开的会话 ${taken.sessionId}${known?.title ? `「${known.title}」` : ''}:之后在这个主题里叫它,就是在那段会话里接着说。`,
|
|
69
|
+
...(taken.context ? [`它的上下文已经用了 ${Math.round((taken.context.used / taken.context.size) * 100)}%。`] : []),
|
|
70
|
+
...(taken.replaced ? [`它原来在这里的会话 ${taken.replaced} 还在客户端里,要换回去就按这个 id 再接一次。`] : []),
|
|
71
|
+
].join(''),
|
|
72
|
+
});
|
|
73
|
+
return taken;
|
|
74
|
+
};
|
|
75
|
+
const need = (id) => {
|
|
76
|
+
const topic = topics.get(id);
|
|
77
|
+
if (!topic || topic.deletedAt)
|
|
78
|
+
throw new HttpError(404, '没有这个 topic');
|
|
79
|
+
return topic;
|
|
80
|
+
};
|
|
81
|
+
const id = { type: 'string', description: '主题编号' };
|
|
82
|
+
const memberId = { type: 'string', description: '成员编号' };
|
|
83
|
+
ctx.effect(entry.op({
|
|
84
|
+
name: 'instances.sessions_list', about: '查看能接上已有会话的成员在这个主题的当前会话及最近找到的会话。',
|
|
85
|
+
input: object({ id }, ['id']), http: ['GET', '/api/topics/:id/sessions'], topic: 'id',
|
|
86
|
+
run({ id }) {
|
|
87
|
+
const topic = need(id);
|
|
88
|
+
const who = able();
|
|
89
|
+
const looked = found.get(topic.id);
|
|
90
|
+
const fresh = looked && Date.now() - looked.at < FOUND_MS && members.get(looked.memberId) ? looked : undefined;
|
|
91
|
+
return {
|
|
92
|
+
members: who.map((m) => ({ id: m.id, name: m.name, sessionId: instances.session(topic.id, m.id) ?? null })),
|
|
93
|
+
dirs: topics.refsOf(topic.id).map((r) => r.path),
|
|
94
|
+
...(fresh ? {
|
|
95
|
+
found: {
|
|
96
|
+
memberId: fresh.memberId,
|
|
97
|
+
cwd: fresh.cwd,
|
|
98
|
+
sessions: fresh.sessions.map((s) => ({
|
|
99
|
+
id: s.id, title: s.title, cwd: s.cwd, updatedAt: s.updatedAt,
|
|
100
|
+
topicId: s.topicId, topicTitle: s.topicId ? topics.get(s.topicId)?.title : undefined, held: s.held,
|
|
101
|
+
})),
|
|
102
|
+
},
|
|
103
|
+
} : {}),
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
}));
|
|
107
|
+
ctx.effect(entry.op({
|
|
108
|
+
name: 'instances.session_find', about: '列出成员的客户端在指定目录下已有的会话。',
|
|
109
|
+
input: object({ id, memberId, cwd: { type: 'string', description: '要查找的目录的完整路径' } }, ['id', 'memberId', 'cwd']),
|
|
110
|
+
http: ['POST', '/api/topics/:id/sessions/find'],
|
|
111
|
+
run: ({ id, memberId, cwd }) => find(need(id).id, memberId, cwd.trim()),
|
|
112
|
+
}));
|
|
113
|
+
ctx.effect(entry.op({
|
|
114
|
+
name: 'instances.session_adopt', about: '把客户端的一段已有会话接进主题,成员在这里继续用那段会话。',
|
|
115
|
+
input: object({ id, memberId, sessionId: { type: 'string', description: '客户端里的会话编号' } }, ['id', 'memberId', 'sessionId']),
|
|
116
|
+
http: ['POST', '/api/topics/:id/sessions/adopt'],
|
|
117
|
+
run: ({ id, memberId, sessionId }) => adopt(need(id).id, memberId, sessionId),
|
|
118
|
+
}));
|
|
119
|
+
ctx.effect(entry.op({
|
|
120
|
+
name: 'instances.session_found_clear', about: '收起这个主题里上次找到的会话列表。',
|
|
121
|
+
input: object({ id }, ['id']), http: ['DELETE', '/api/topics/:id/sessions/found'],
|
|
122
|
+
run({ id }) { latestFind.delete(id); found.delete(id); },
|
|
123
|
+
}));
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
export default sessionsPlugin;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ContextMark, InstanceInfo, Runtime, SessionEndReason, TurnSummary, Usage } from 'hostlet/sdk';
|
|
2
|
+
export type TopicParticipantState = 'running' | 'idle' | 'ended' | 'sealed';
|
|
3
|
+
export interface ParticipantSession {
|
|
4
|
+
sessionId: string | null;
|
|
5
|
+
kind: 'current' | 'previous' | 'unknown';
|
|
6
|
+
reason?: SessionEndReason;
|
|
7
|
+
turnCount: number;
|
|
8
|
+
firstAt: number;
|
|
9
|
+
lastAt: number;
|
|
10
|
+
}
|
|
11
|
+
export interface TopicParticipant {
|
|
12
|
+
memberId: string;
|
|
13
|
+
state: TopicParticipantState;
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
eligible: boolean;
|
|
16
|
+
removed?: boolean;
|
|
17
|
+
sessionId: string | null;
|
|
18
|
+
adopted: boolean;
|
|
19
|
+
instance: Pick<InstanceInfo, 'adapter' | 'pid' | 'startedAt' | 'lastUsedAt' | 'busy' | 'canAppend'> | null;
|
|
20
|
+
turnCount: number;
|
|
21
|
+
unreadCount: number;
|
|
22
|
+
usage: Usage | null;
|
|
23
|
+
contextMark?: ContextMark;
|
|
24
|
+
lastTurn: TurnSummary | null;
|
|
25
|
+
sessions: ParticipantSession[];
|
|
26
|
+
lastActiveAt: number;
|
|
27
|
+
}
|
|
28
|
+
export declare function topicParticipants(runtime: Runtime, topicId: string): TopicParticipant[];
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { OWNER_ID } from 'hostlet/sdk';
|
|
2
|
+
const participantOrder = { running: 0, idle: 1, ended: 2, sealed: 2 };
|
|
3
|
+
const sessionOrder = { current: 0, previous: 1, unknown: 2 };
|
|
4
|
+
export function topicParticipants(runtime, topicId) {
|
|
5
|
+
const a2a = runtime.get('a2a');
|
|
6
|
+
const instances = runtime.get('instances');
|
|
7
|
+
const members = runtime.get('members');
|
|
8
|
+
const liveTurns = new Map(a2a.live(topicId).map((turn) => [turn.memberId, turn]));
|
|
9
|
+
const sessions = new Map(instances.topicSessions(topicId).map((s) => [s.memberId, s]));
|
|
10
|
+
const ends = new Map(instances.sessionEnds(topicId).map((end) => [`${end.memberId}\0${end.sessionId}`, end.reason]));
|
|
11
|
+
const history = new Map();
|
|
12
|
+
for (const { memberId, turn, usage } of a2a.turnSummaries(topicId)) {
|
|
13
|
+
let saved = history.get(memberId);
|
|
14
|
+
if (!saved) {
|
|
15
|
+
saved = { latest: turn, groups: new Map(), usage: null };
|
|
16
|
+
history.set(memberId, saved);
|
|
17
|
+
}
|
|
18
|
+
const current = sessions.get(memberId)?.sessionId;
|
|
19
|
+
const sessionId = turn.sessionId || (turn.id === liveTurns.get(memberId)?.turnId ? current : null) || null;
|
|
20
|
+
if (current && current === turn.sessionId)
|
|
21
|
+
saved.usage ??= usage;
|
|
22
|
+
const lastAt = Math.max(turn.startedAt, turn.endedAt ?? 0);
|
|
23
|
+
const group = saved.groups.get(sessionId);
|
|
24
|
+
if (group) {
|
|
25
|
+
group.turnCount++;
|
|
26
|
+
group.firstAt = turn.startedAt;
|
|
27
|
+
group.lastAt = Math.max(group.lastAt, lastAt);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const kind = sessionId === null ? 'unknown' : sessionId === current ? 'current' : 'previous';
|
|
31
|
+
const reason = kind === 'previous' && sessionId !== null ? ends.get(`${memberId}\0${sessionId}`) : undefined;
|
|
32
|
+
saved.groups.set(sessionId, { sessionId, kind, ...(reason ? { reason } : {}), turnCount: 1, firstAt: turn.startedAt, lastAt });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const unread = new Map();
|
|
36
|
+
for (const { memberId } of a2a.pending({ topicId }))
|
|
37
|
+
unread.set(memberId, (unread.get(memberId) ?? 0) + 1);
|
|
38
|
+
const ids = new Set([...liveTurns.keys(), ...sessions.keys(), ...history.keys()]);
|
|
39
|
+
// The channel survives an index rebuild. Keep its repliers even after new sessions and turns are recorded.
|
|
40
|
+
for (const memberId of runtime.get('messages').repliers(topicId))
|
|
41
|
+
ids.add(memberId);
|
|
42
|
+
ids.delete(OWNER_ID);
|
|
43
|
+
const participants = [...ids].map((memberId) => {
|
|
44
|
+
const member = members.get(memberId);
|
|
45
|
+
const live = liveTurns.get(memberId);
|
|
46
|
+
const session = sessions.get(memberId);
|
|
47
|
+
const saved = history.get(memberId);
|
|
48
|
+
const current = session?.instance;
|
|
49
|
+
const sessionId = session?.sessionId ?? null;
|
|
50
|
+
const enabled = member?.enabled === true;
|
|
51
|
+
const lastTurn = saved?.latest ?? null;
|
|
52
|
+
const memberSessions = [...(saved?.groups.values() ?? [])];
|
|
53
|
+
if (session?.sessionId && !memberSessions.some((s) => s.kind === 'current')) {
|
|
54
|
+
memberSessions.push({
|
|
55
|
+
sessionId: session.sessionId, kind: 'current', turnCount: 0,
|
|
56
|
+
firstAt: session.updatedAt, lastAt: session.updatedAt,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
memberSessions.sort((a, b) => sessionOrder[a.kind] - sessionOrder[b.kind] || b.lastAt - a.lastAt || b.firstAt - a.firstAt
|
|
60
|
+
|| Buffer.compare(Buffer.from(a.sessionId ?? ''), Buffer.from(b.sessionId ?? '')));
|
|
61
|
+
const state = live || current?.busy ? 'running' : current ? 'idle' : session?.sealed ? 'sealed' : 'ended';
|
|
62
|
+
let usage = null;
|
|
63
|
+
if (sessionId) {
|
|
64
|
+
const context = current?.sessionId === sessionId ? current.context : undefined;
|
|
65
|
+
usage = live?.usage
|
|
66
|
+
?? saved?.usage
|
|
67
|
+
?? (context ? { contextUsed: context.used, contextSize: context.size } : null);
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
memberId, state, enabled, eligible: enabled && a2a.worksIn(topicId, memberId), ...(!member ? { removed: true } : {}),
|
|
71
|
+
sessionId, adopted: session?.adopted ?? false,
|
|
72
|
+
instance: current ? {
|
|
73
|
+
adapter: current.adapter, ...(current.pid !== undefined ? { pid: current.pid } : {}),
|
|
74
|
+
startedAt: current.startedAt, lastUsedAt: current.lastUsedAt, busy: current.busy, canAppend: current.canAppend,
|
|
75
|
+
} : null,
|
|
76
|
+
turnCount: memberSessions.reduce((total, s) => total + s.turnCount, 0),
|
|
77
|
+
unreadCount: unread.get(memberId) ?? 0, usage, lastTurn, sessions: memberSessions,
|
|
78
|
+
lastActiveAt: Math.max(lastTurn?.endedAt ?? lastTurn?.startedAt ?? 0, live?.startedAt ?? 0, session?.updatedAt ?? 0, current?.lastUsedAt ?? 0),
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
return participants.sort((a, b) => participantOrder[a.state] - participantOrder[b.state]
|
|
82
|
+
|| b.lastActiveAt - a.lastActiveAt || a.memberId.localeCompare(b.memberId));
|
|
83
|
+
}
|