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,349 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { address } from "./address.js";
|
|
3
|
+
import { OWNER_ID } from "./members.js";
|
|
4
|
+
import { relayBrief, visibleInTurn, visibleTo } from "./messages.js";
|
|
5
|
+
const digest = (value) => createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
6
|
+
const fact = (row) => ({
|
|
7
|
+
...JSON.parse(row.data), canResume: false, id: row.id, state: row.state, remaining: JSON.parse(row.remaining), ...(row.receipt && { receipt: JSON.parse(row.receipt) }),
|
|
8
|
+
});
|
|
9
|
+
export function blockedHandoffs(ctx, ops) {
|
|
10
|
+
const store = ctx.get('store');
|
|
11
|
+
const { db } = store, members = ctx.get('members'), messages = ctx.get('messages'), topics = ctx.get('topics');
|
|
12
|
+
db.exec(`
|
|
13
|
+
CREATE TABLE IF NOT EXISTS a2a_blocked_handoffs (
|
|
14
|
+
id TEXT PRIMARY KEY, source_topic TEXT NOT NULL, destination TEXT NOT NULL,
|
|
15
|
+
data TEXT NOT NULL, state TEXT NOT NULL, receipt TEXT, remaining TEXT NOT NULL
|
|
16
|
+
);
|
|
17
|
+
CREATE INDEX IF NOT EXISTS a2a_blocked_source ON a2a_blocked_handoffs (source_topic);
|
|
18
|
+
CREATE INDEX IF NOT EXISTS a2a_blocked_destination ON a2a_blocked_handoffs (destination);
|
|
19
|
+
CREATE INDEX IF NOT EXISTS a2a_blocked_pending ON a2a_blocked_handoffs (state) WHERE state = 'pending';
|
|
20
|
+
CREATE TABLE IF NOT EXISTS a2a_relay_origins (
|
|
21
|
+
message_id TEXT PRIMARY KEY, authority TEXT NOT NULL, action TEXT, handoff_id TEXT, used_at INTEGER,
|
|
22
|
+
UNIQUE(authority, action)
|
|
23
|
+
);
|
|
24
|
+
`);
|
|
25
|
+
const origin = db.prepare('SELECT authority FROM a2a_relay_origins WHERE message_id = ?');
|
|
26
|
+
const remember = db.prepare('INSERT OR IGNORE INTO a2a_relay_origins (message_id, authority) VALUES (?, ?)');
|
|
27
|
+
const used = db.prepare('SELECT handoff_id, message_id, used_at FROM a2a_relay_origins WHERE authority = ? AND action = ?');
|
|
28
|
+
const use = db.prepare('INSERT INTO a2a_relay_origins (message_id, authority, action, handoff_id, used_at) VALUES (?, ?, ?, ?, ?)');
|
|
29
|
+
const insert = db.prepare(`INSERT OR IGNORE INTO a2a_blocked_handoffs
|
|
30
|
+
(id, source_topic, destination, data, remaining, state) VALUES (?, ?, ?, ?, ?, 'pending')`);
|
|
31
|
+
const byId = db.prepare('SELECT id, data, state, receipt, remaining FROM a2a_blocked_handoffs WHERE id = ?');
|
|
32
|
+
const inTopic = db.prepare('SELECT id, data, state, receipt, remaining FROM a2a_blocked_handoffs WHERE source_topic = ? OR destination = ?');
|
|
33
|
+
const addressed = db.prepare("SELECT id, data, state, receipt, remaining FROM a2a_blocked_handoffs WHERE destination = ? AND state IN ('pending','returned','escalated')");
|
|
34
|
+
const refersTo = db.prepare(`SELECT id, data, state, receipt, remaining FROM a2a_blocked_handoffs
|
|
35
|
+
WHERE json_extract(data, '$.authority') = ? OR json_extract(data, '$.sourceMessageId') = ?
|
|
36
|
+
OR EXISTS (SELECT 1 FROM json_each(data, '$.sourceIds') WHERE value = ?)`);
|
|
37
|
+
const setRemaining = db.prepare('UPDATE a2a_blocked_handoffs SET remaining = ? WHERE id = ?');
|
|
38
|
+
const saveReceipts = db.prepare("UPDATE a2a_blocked_handoffs SET data = json_set(data, '$.receipts', json(?)) WHERE id = ?");
|
|
39
|
+
const saveContacts = db.prepare("UPDATE a2a_blocked_handoffs SET data = json_set(data, '$.contacts', json(?)) WHERE id = ?");
|
|
40
|
+
const pending = db.prepare("SELECT id, data, state, receipt, remaining FROM a2a_blocked_handoffs WHERE state = 'pending' ORDER BY rowid");
|
|
41
|
+
const update = db.prepare('UPDATE a2a_blocked_handoffs SET state = ?, receipt = ? WHERE id = ?');
|
|
42
|
+
const get = (id) => { const row = byId.get(id); return row && fact(row); };
|
|
43
|
+
const state = (h, next, receipt) => update.run(next, receipt ? JSON.stringify(receipt) : null, h.id);
|
|
44
|
+
const active = (topicId) => { const t = topics.get(topicId); return t && t.archivedAt === null && t.deletedAt === null; };
|
|
45
|
+
// A deleted source cannot be recovered from the independent copy of a rejected tool argument.
|
|
46
|
+
const current = (h) => active(h.sourceTopicId) && active(h.topicId)
|
|
47
|
+
&& (!h.authority || !!messages.stored(h.authority))
|
|
48
|
+
&& (!h.sourceMessageId || !!messages.stored(h.sourceMessageId)) && (h.sourceIds ?? []).every((id) => !!messages.stored(id));
|
|
49
|
+
const visible = (h, viewer) => (viewer === OWNER_ID || viewer === h.from || h.blocked.includes(viewer) || h.delivered.includes(viewer))
|
|
50
|
+
&& visibleTo(h.visibility, viewer)
|
|
51
|
+
&& ops.worksIn(viewer === h.from ? h.sourceTopicId : h.topicId, viewer)
|
|
52
|
+
&& (!h.sourceMessageId || !!messages.forMember(viewer).get(h.sourceMessageId))
|
|
53
|
+
&& (h.sourceIds ?? []).every((id) => !!messages.forMember(viewer).get(id));
|
|
54
|
+
// Unproven sends have no automatic continuation. Repeated failures can still be returned once.
|
|
55
|
+
const budget = (h) => h.authority ?? 'unproven:' + digest([h.from, h.sourceTopicId, h.sourceThread, h.visibility]);
|
|
56
|
+
const has = (h, action) => !!used.get(budget(h), action);
|
|
57
|
+
function originOf(id) {
|
|
58
|
+
// Existing addressed reply chains carry their own ancestry. Unquoted older sends don't.
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
while (id && !seen.has(id)) {
|
|
61
|
+
const row = origin.get(id);
|
|
62
|
+
if (row)
|
|
63
|
+
return row.authority.startsWith('unproven:') ? null : row.authority;
|
|
64
|
+
seen.add(id);
|
|
65
|
+
const m = messages.stored(id);
|
|
66
|
+
if (!m)
|
|
67
|
+
return null;
|
|
68
|
+
if (m.from.kind === 'system' || ['person', 'plugin'].includes(members.get(m.from.id)?.kind ?? ''))
|
|
69
|
+
return id;
|
|
70
|
+
const parent = m.replyTo && messages.stored(m.replyTo);
|
|
71
|
+
if (!parent || !parent.to.includes(m.from.id))
|
|
72
|
+
return null;
|
|
73
|
+
id = parent.id;
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const clearReceipt = (h) => {
|
|
78
|
+
if (h.receipt && (h.state === 'escalated' || h.state === 'returned')) {
|
|
79
|
+
const recipient = messages.stored(h.receipt.messageId)?.to[0];
|
|
80
|
+
if (recipient)
|
|
81
|
+
ops.ack(recipient, h.receipt);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const settle = (h, recipients, receipt) => {
|
|
85
|
+
const remaining = h.remaining.filter((id) => !recipients.includes(id));
|
|
86
|
+
setRemaining.run(JSON.stringify(remaining), h.id);
|
|
87
|
+
if (receipt) {
|
|
88
|
+
const receipts = { ...h.receipts };
|
|
89
|
+
for (const id of recipients)
|
|
90
|
+
receipts[id] = receipt;
|
|
91
|
+
saveReceipts.run(JSON.stringify(receipts), h.id);
|
|
92
|
+
}
|
|
93
|
+
return remaining;
|
|
94
|
+
};
|
|
95
|
+
const recordDelivery = (h, action, next, m) => {
|
|
96
|
+
use.run(m.id, budget(h), action, h.id, m.createdAt);
|
|
97
|
+
if (action !== 'owner')
|
|
98
|
+
ops.setDepth(m.id, h.depth);
|
|
99
|
+
const receipt = { topicId: m.topicId, messageId: m.id };
|
|
100
|
+
if (action === 'resume') {
|
|
101
|
+
clearReceipt(h);
|
|
102
|
+
if (settle(h, m.to, receipt).length)
|
|
103
|
+
next = 'pending';
|
|
104
|
+
}
|
|
105
|
+
state(h, next, receipt);
|
|
106
|
+
};
|
|
107
|
+
function claimBlockedHandoff(id, { from, viewerId, memberId, content, visibility: requested }) {
|
|
108
|
+
const h = get(id);
|
|
109
|
+
if (!h || !current(h) || !members.isRegisteredSender(from) || !visible(h, viewerId) || !h.blocked.includes(memberId))
|
|
110
|
+
return;
|
|
111
|
+
const grant = used.get(budget(h), 'resume');
|
|
112
|
+
if (grant) {
|
|
113
|
+
const m = grant.handoff_id === h.id ? messages.forMember(viewerId).get(grant.message_id) : undefined;
|
|
114
|
+
return m?.to.includes(memberId) ? { topicId: m.topicId, messageId: m.id } : undefined;
|
|
115
|
+
}
|
|
116
|
+
if (!h.remaining.includes(memberId) || h.contacts?.[memberId] || h.state === 'handled' || h.state === 'escalated' || !h.authority
|
|
117
|
+
|| members.get(memberId)?.kind === 'person' || !visibleTo(h.visibility, memberId)
|
|
118
|
+
|| !ops.worksIn(h.topicId, memberId) || !members.canReceive(memberId))
|
|
119
|
+
return;
|
|
120
|
+
const visibility = Array.isArray(requested) ? requested.filter((id) => visibleTo(h.visibility, id)) : h.visibility;
|
|
121
|
+
if (requested === 'shadow' || !visibleTo(visibility, memberId) || !visibleTo(visibility, viewerId))
|
|
122
|
+
return;
|
|
123
|
+
const parent = h.thread ? h.kind === 'reply' ? h.sourceMessageId : h.replyTo : undefined;
|
|
124
|
+
const replyTo = parent && messages.forMember(from.id).get(parent) ? parent : undefined;
|
|
125
|
+
const source = h.sourceTopicId !== h.topicId && h.sourceMessageId && messages.forMember(memberId).get(h.sourceMessageId);
|
|
126
|
+
const body = !content || content === h.content ? h.content : h.kind === 'reply' && replyTo ? content : content + '\n\n' + h.content;
|
|
127
|
+
const msg = ops.send({ from, topicId: h.topicId, content: body, targets: [memberId], requireRecipient: true,
|
|
128
|
+
visibility, ...(replyTo ? { replyTo } : { thread: h.thread }),
|
|
129
|
+
...(source ? { parts: [{ type: 'reference', dir: 'in', address: address.message(source.topicId, source.id),
|
|
130
|
+
title: topics.get(source.topicId).title }] } : {}),
|
|
131
|
+
}, (m) => recordDelivery(h, 'resume', 'resumed', m));
|
|
132
|
+
schedule();
|
|
133
|
+
return { topicId: msg.topicId, messageId: msg.id };
|
|
134
|
+
}
|
|
135
|
+
function resolveBlockedHandoff(id, viewerId, memberId) {
|
|
136
|
+
const h = get(id);
|
|
137
|
+
if (!h || !current(h) || !visible(h, viewerId) || h.state === 'handled')
|
|
138
|
+
return;
|
|
139
|
+
if (memberId ? !h.remaining.includes(memberId) : h.remaining.length > 1)
|
|
140
|
+
return;
|
|
141
|
+
store.tx(() => {
|
|
142
|
+
if (settle(h, memberId ? [memberId] : h.remaining).length)
|
|
143
|
+
return;
|
|
144
|
+
clearReceipt(h);
|
|
145
|
+
state(h, 'handled', h.state === 'resumed' ? h.receipt : undefined);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
const sender = { kind: 'system', id: 'a2a' };
|
|
149
|
+
function fallback(h) {
|
|
150
|
+
const input = h.authority && messages.stored(h.authority);
|
|
151
|
+
const assigned = input ? input.to.filter((id) => members.get(id)?.kind === 'agent') : [];
|
|
152
|
+
const eligible = (id) => members.canReceive(id) && ops.worksIn(h.sourceTopicId, id)
|
|
153
|
+
&& (h.visibility === 'shadow' ? id === h.from : visibleTo(h.visibility, id))
|
|
154
|
+
&& (id === h.from || !h.sourceMessageId || !!messages.forMember(id).get(h.sourceMessageId));
|
|
155
|
+
const responsible = assigned.length === 1 && eligible(assigned[0]) && !h.contacts?.[assigned[0]] ? assigned[0] : h.from;
|
|
156
|
+
const canReturn = eligible(responsible);
|
|
157
|
+
const alreadyReturned = used.get(budget(h), 'return');
|
|
158
|
+
// Several calls from the same turn all received their tool error. A repeated observation is not a new decision.
|
|
159
|
+
const previous = alreadyReturned && get(alreadyReturned.handoff_id);
|
|
160
|
+
const returned = alreadyReturned && messages.stored(alreadyReturned.message_id);
|
|
161
|
+
if (previous && (previous.id === h.id || h.turnId && previous.turnId === h.turnId
|
|
162
|
+
|| h.createdAt < alreadyReturned.used_at || returned && !ops.received(returned))) {
|
|
163
|
+
state(h, 'returned');
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (canReturn && !alreadyReturned && h.kind !== 'reply' && responsible === h.from) {
|
|
167
|
+
use.run(h.id, budget(h), 'return', h.id, Date.now());
|
|
168
|
+
state(h, 'returned');
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const escalate = !canReturn || !!alreadyReturned;
|
|
172
|
+
if (escalate && (!visible(h, OWNER_ID) || has(h, 'owner'))) {
|
|
173
|
+
state(h, 'returned');
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const names = h.remaining.map((id) => members.get(id)?.name ?? id).join('、');
|
|
177
|
+
const link = h.sourceMessageId ? ' [交办原处](#' + address.message(h.sourceTopicId, h.sourceMessageId) + ')' : '';
|
|
178
|
+
const contacted = h.remaining.filter((id) => h.contacts?.[id]).map((id) => members.get(id)?.name ?? id).join('、');
|
|
179
|
+
const content = escalate
|
|
180
|
+
? '接力仍然受阻。' + (members.get(h.from)?.name ?? h.from) + ' 未能交给 ' + names + '。请决定继续、转派或停止。' + link
|
|
181
|
+
: contacted ? '本主题里已有人联系了 ' + contacted + '。请在原交办核对送达情况,接回仍未办理的部分。' + link
|
|
182
|
+
: '接力深度已达上限,' + names + ' 没有收到交办。请接回这项工作,安排接续或说明需要机主决定的事项。' + link;
|
|
183
|
+
const recipient = escalate ? OWNER_ID : responsible;
|
|
184
|
+
ops.send({ from: sender, topicId: h.sourceTopicId, targets: [recipient], content: content + '\n' + relayBrief(h.content), requireRecipient: true,
|
|
185
|
+
thread: h.sourceThread, visibility: h.visibility,
|
|
186
|
+
}, (m) => recordDelivery(h, escalate ? 'owner' : 'return', escalate ? 'escalated' : 'returned', m));
|
|
187
|
+
}
|
|
188
|
+
function returnBlockedHandoff(id, viewerId) {
|
|
189
|
+
let h = get(id);
|
|
190
|
+
if (!h || !current(h) || !visible(h, viewerId))
|
|
191
|
+
return;
|
|
192
|
+
if (h.state === 'pending' && h.remaining.length) {
|
|
193
|
+
fallback(h);
|
|
194
|
+
h = get(id);
|
|
195
|
+
}
|
|
196
|
+
if ((h.state === 'escalated' || h.state === 'returned') && h.receipt && messages.forMember(viewerId).get(h.receipt.messageId))
|
|
197
|
+
return h.receipt;
|
|
198
|
+
}
|
|
199
|
+
let scheduled = false, stopped = false;
|
|
200
|
+
function schedule() {
|
|
201
|
+
if (scheduled || stopped || !ctx.runtime.ready)
|
|
202
|
+
return;
|
|
203
|
+
scheduled = true;
|
|
204
|
+
queueMicrotask(() => {
|
|
205
|
+
scheduled = false;
|
|
206
|
+
if (stopped)
|
|
207
|
+
return;
|
|
208
|
+
for (const row of pending.all()) {
|
|
209
|
+
const h = fact(row);
|
|
210
|
+
if (!current(h)) {
|
|
211
|
+
state(h, 'handled');
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (h.turnId && ops.running(h.turnId))
|
|
215
|
+
continue;
|
|
216
|
+
let held = false;
|
|
217
|
+
ctx.runtime.emit('a2a.handoffBlocked', { id: h.id, sourceTopicId: h.sourceTopicId, topicId: h.topicId, hold() { held = true; } });
|
|
218
|
+
if (!held && get(h.id)?.state === 'pending') {
|
|
219
|
+
try {
|
|
220
|
+
fallback(h);
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
ctx.runtime.onError('blocked handoff ' + h.id, error);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
ctx.effect(() => { stopped = true; });
|
|
230
|
+
ctx.on('host.stopping', () => { stopped = true; });
|
|
231
|
+
// A real human contact takes precedence over an automatic ping. Only a link to the work or
|
|
232
|
+
// a unique handoff in its own floor can also settle the delivery. The wording is immaterial.
|
|
233
|
+
const delivered = (m) => {
|
|
234
|
+
if (!m.to.length || m.from.kind !== 'member')
|
|
235
|
+
return;
|
|
236
|
+
const open = addressed.all(m.topicId).map(fact);
|
|
237
|
+
if (!open.length)
|
|
238
|
+
return;
|
|
239
|
+
const person = members.get(m.from.id)?.kind === 'person';
|
|
240
|
+
const inputId = !person && originOf(m.id);
|
|
241
|
+
const input = inputId ? messages.stored(inputId) : undefined;
|
|
242
|
+
const pushed = input?.from.kind === 'member' && members.get(input.from.id)?.kind === 'person' ? input : undefined;
|
|
243
|
+
const confirms = (h) => {
|
|
244
|
+
if (m.replyTo && (m.replyTo === h.receipt?.messageId || m.replyTo === h.sourceMessageId))
|
|
245
|
+
return true;
|
|
246
|
+
if (m.from.id === h.from && (pushed?.replyTo && pushed.replyTo === h.sourceMessageId && visibleTo(h.visibility, pushed.from.id)
|
|
247
|
+
|| m.content === h.content && inputId && inputId === h.authority))
|
|
248
|
+
return true;
|
|
249
|
+
const source = h.sourceMessageId && address.message(h.sourceTopicId, h.sourceMessageId);
|
|
250
|
+
return !!source && (m.content.includes('#' + source) || m.parts.some((p) => p.type === 'reference' && p.address === source));
|
|
251
|
+
};
|
|
252
|
+
const byFact = new Map();
|
|
253
|
+
for (const memberId of m.to) {
|
|
254
|
+
const candidates = open.filter((h) => h.remaining.includes(memberId) && visibleInTurn(m.visibility, memberId, h.visibility)
|
|
255
|
+
&& (!person || visible(h, m.from.id)));
|
|
256
|
+
const named = candidates.filter(confirms);
|
|
257
|
+
const matched = named.length || !person ? named : candidates.filter((h) => h.thread && m.thread === h.thread && (!m.replyTo || m.replyTo === h.thread || m.replyTo === h.sourceMessageId));
|
|
258
|
+
for (const h of candidates) {
|
|
259
|
+
const confirmed = matched.length === 1 && matched[0] === h;
|
|
260
|
+
if (!confirmed && (!person || h.contacts?.[memberId]))
|
|
261
|
+
continue;
|
|
262
|
+
const update = byFact.get(h) ?? { received: [], contacted: [] };
|
|
263
|
+
(confirmed ? update.received : update.contacted).push(memberId);
|
|
264
|
+
byFact.set(h, update);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (!byFact.size)
|
|
268
|
+
return;
|
|
269
|
+
const place = { topicId: m.topicId, messageId: m.id };
|
|
270
|
+
store.tx(() => {
|
|
271
|
+
for (const [h, { received, contacted }] of byFact) {
|
|
272
|
+
if (contacted.length) {
|
|
273
|
+
const contacts = { ...h.contacts };
|
|
274
|
+
for (const id of contacted)
|
|
275
|
+
contacts[id] = place;
|
|
276
|
+
saveContacts.run(JSON.stringify(contacts), h.id);
|
|
277
|
+
}
|
|
278
|
+
if (received.length && !settle(h, received, place).length) {
|
|
279
|
+
clearReceipt(h);
|
|
280
|
+
state(h, 'handled', place);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
schedule();
|
|
285
|
+
};
|
|
286
|
+
ctx.on('message.appended', ({ message }) => delivered(message));
|
|
287
|
+
ctx.on('message.changed', ({ message, tell }) => { if (tell.length)
|
|
288
|
+
delivered({ ...message, to: tell }); });
|
|
289
|
+
ctx.on('message.deleted', ({ id }) => {
|
|
290
|
+
for (const row of refersTo.all(id, id, id)) {
|
|
291
|
+
clearReceipt(fact(row));
|
|
292
|
+
db.prepare('DELETE FROM a2a_blocked_handoffs WHERE id = ?').run(row.id);
|
|
293
|
+
}
|
|
294
|
+
db.prepare('DELETE FROM a2a_relay_origins WHERE message_id = ? AND action IS NULL').run(id);
|
|
295
|
+
});
|
|
296
|
+
ctx.on('turn.ended', schedule);
|
|
297
|
+
ctx.on('members.changed', schedule);
|
|
298
|
+
ctx.on('topic.updated', ({ topic }) => {
|
|
299
|
+
if (topic.archivedAt === null && topic.deletedAt === null)
|
|
300
|
+
return;
|
|
301
|
+
for (const row of inTopic.all(topic.id, topic.id)) {
|
|
302
|
+
const h = fact(row);
|
|
303
|
+
if (h.state !== 'handled' && h.state !== 'resumed') {
|
|
304
|
+
clearReceipt(h);
|
|
305
|
+
state(h, 'handled');
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
ctx.hook('host.ready', schedule);
|
|
310
|
+
ctx.on('topic.purged', ({ topicIds }) => {
|
|
311
|
+
const ids = JSON.stringify(topicIds);
|
|
312
|
+
db.prepare('DELETE FROM a2a_blocked_handoffs WHERE source_topic IN (SELECT value FROM json_each(?)) OR destination IN (SELECT value FROM json_each(?))').run(ids, ids);
|
|
313
|
+
});
|
|
314
|
+
ctx.point('a2a.handoffBlocked', { title: '成员接力未送达', group: '投递', about: '工作流可在原发起授权内接续实际被拦的交办。', order: 51 });
|
|
315
|
+
return {
|
|
316
|
+
originOf,
|
|
317
|
+
inherit(messageId, authority) { if (authority)
|
|
318
|
+
remember.run(messageId, authority); },
|
|
319
|
+
record(attempt, sourceScope) {
|
|
320
|
+
const scopes = [attempt.visibility, sourceScope,
|
|
321
|
+
...(attempt.authority ? [messages.storedRouting(attempt.authority)?.visibility] : []),
|
|
322
|
+
...[attempt.sourceMessageId, ...(attempt.sourceIds ?? [])].flatMap((id) => id ? [messages.storedRouting(id)?.visibility] : []),
|
|
323
|
+
];
|
|
324
|
+
const group = scopes.find(Array.isArray);
|
|
325
|
+
const visibility = scopes.includes('shadow') ? 'shadow' : group?.filter((id) => scopes.every((scope) => visibleTo(scope, id))) ?? attempt.visibility;
|
|
326
|
+
const input = { ...attempt, visibility };
|
|
327
|
+
const id = 'handoff_' + digest([input.authority, input.kind, input.from, input.sourceTopicId, input.sourceMessageId,
|
|
328
|
+
input.sourceThread, input.topicId, input.thread, [...input.blocked].sort(), input.visibility, input.content]);
|
|
329
|
+
insert.run(id, input.sourceTopicId, input.topicId, JSON.stringify({ ...input, createdAt: Date.now() }), JSON.stringify(input.blocked));
|
|
330
|
+
schedule();
|
|
331
|
+
return id;
|
|
332
|
+
},
|
|
333
|
+
blockedHandoffs(topicId, viewerId) {
|
|
334
|
+
return inTopic.all(topicId, topicId).map(fact).filter((h) => current(h) && visible(h, viewerId)).map((h) => {
|
|
335
|
+
const input = h.authority && messages.forMember(viewerId).get(h.authority);
|
|
336
|
+
const canResume = h.authority !== null && (h.state === 'pending' || h.state === 'returned') && !has(h, 'resume')
|
|
337
|
+
&& h.remaining.some((id) => !h.contacts?.[id]);
|
|
338
|
+
const { receipt, receipts, contacts, ...details } = h;
|
|
339
|
+
const readable = (p) => !!messages.forMember(viewerId).get(p.messageId);
|
|
340
|
+
return { ...details, canResume, authority: h.authority && digest(['input', h.authority]),
|
|
341
|
+
...(receipt && readable(receipt) && { receipt }),
|
|
342
|
+
...(receipts && { receipts: Object.fromEntries(Object.entries(receipts).filter(([, p]) => readable(p))) }),
|
|
343
|
+
...(contacts && { contacts: Object.fromEntries(Object.entries(contacts).filter(([, p]) => readable(p))) }),
|
|
344
|
+
...(input && { origin: { topicId: input.topicId, messageId: input.id } }) };
|
|
345
|
+
});
|
|
346
|
+
},
|
|
347
|
+
claimBlockedHandoff, returnBlockedHandoff, resolveBlockedHandoff,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { Schema } from './ops.ts';
|
|
2
|
+
export type Scalar = string | number | boolean;
|
|
3
|
+
export type FieldValue = Scalar | string[];
|
|
4
|
+
export type ConfigRecord = Record<string, FieldValue>;
|
|
5
|
+
export type Setting = FieldValue | ConfigRecord[] | Record<string, string>;
|
|
6
|
+
export type RequiredWhen = {
|
|
7
|
+
key: string;
|
|
8
|
+
value: Scalar | Scalar[];
|
|
9
|
+
};
|
|
10
|
+
export type LocalizedText = string | {
|
|
11
|
+
default: string;
|
|
12
|
+
translations?: Record<string, string>;
|
|
13
|
+
};
|
|
14
|
+
export type ConfigUnit = 'days' | 'minutes' | 'seconds' | 'levels' | 'items' | 'count' | 'chars' | 'percent';
|
|
15
|
+
export type ConfigKind = 'string' | 'number' | 'url' | 'boolean' | 'select' | 'list' | 'member' | 'map' | 'secret' | 'records' | 'operation';
|
|
16
|
+
export interface ConfigOption {
|
|
17
|
+
value: string;
|
|
18
|
+
label: LocalizedText;
|
|
19
|
+
hint?: LocalizedText;
|
|
20
|
+
docsUrl?: string;
|
|
21
|
+
fill?: Record<string, string>;
|
|
22
|
+
allowedValues?: Record<string, string[]>;
|
|
23
|
+
}
|
|
24
|
+
export interface OperationRef {
|
|
25
|
+
method: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ConfigurationStep {
|
|
28
|
+
id: string;
|
|
29
|
+
label: string;
|
|
30
|
+
render: 'button' | 'polling';
|
|
31
|
+
resultRender?: 'img' | 'text' | 'status';
|
|
32
|
+
action: OperationRef;
|
|
33
|
+
next?: string;
|
|
34
|
+
rollback?: string;
|
|
35
|
+
cancel?: string;
|
|
36
|
+
timeout?: number;
|
|
37
|
+
}
|
|
38
|
+
export interface ConfigField {
|
|
39
|
+
key: string;
|
|
40
|
+
kind: ConfigKind;
|
|
41
|
+
label?: LocalizedText;
|
|
42
|
+
description?: LocalizedText;
|
|
43
|
+
default?: unknown;
|
|
44
|
+
visibility?: 'system' | 'private';
|
|
45
|
+
required?: boolean;
|
|
46
|
+
requiredWhen?: RequiredWhen;
|
|
47
|
+
readonly?: boolean;
|
|
48
|
+
hidden?: boolean;
|
|
49
|
+
minimum?: number;
|
|
50
|
+
maximum?: number;
|
|
51
|
+
integer?: boolean;
|
|
52
|
+
unit?: ConfigUnit;
|
|
53
|
+
presets?: number[];
|
|
54
|
+
inherited?: number;
|
|
55
|
+
options?: ConfigOption[];
|
|
56
|
+
suggestions?: ConfigOption[];
|
|
57
|
+
refreshAction?: string;
|
|
58
|
+
error?: LocalizedText;
|
|
59
|
+
recordFields?: ConfigField[];
|
|
60
|
+
recordPresets?: {
|
|
61
|
+
id: string;
|
|
62
|
+
label: LocalizedText;
|
|
63
|
+
value: Record<string, unknown>;
|
|
64
|
+
}[];
|
|
65
|
+
target?: string[];
|
|
66
|
+
actions?: ConfigurationStep[];
|
|
67
|
+
status?: OperationRef;
|
|
68
|
+
approvalRisk?: LocalizedText;
|
|
69
|
+
section?: string;
|
|
70
|
+
managedBy?: string;
|
|
71
|
+
/** Only a person saves it: a member may ask through `host.config_set`, but that card is settled only by the owner (never co-signed). */
|
|
72
|
+
ownerOnly?: boolean;
|
|
73
|
+
}
|
|
74
|
+
export type VariantTest = {
|
|
75
|
+
const: string;
|
|
76
|
+
} | {
|
|
77
|
+
enum: string[];
|
|
78
|
+
};
|
|
79
|
+
export interface ConfigurationVariants {
|
|
80
|
+
discriminator: string;
|
|
81
|
+
branches: {
|
|
82
|
+
id: string;
|
|
83
|
+
when: {
|
|
84
|
+
properties: Record<string, VariantTest>;
|
|
85
|
+
};
|
|
86
|
+
fields: string[];
|
|
87
|
+
}[];
|
|
88
|
+
}
|
|
89
|
+
export interface ConfigDeclaration {
|
|
90
|
+
scope: string;
|
|
91
|
+
owner: string;
|
|
92
|
+
source?: 'core' | 'builtin' | 'external';
|
|
93
|
+
title?: LocalizedText;
|
|
94
|
+
description?: LocalizedText;
|
|
95
|
+
visibility?: 'system' | 'private';
|
|
96
|
+
approvalRisk?: LocalizedText;
|
|
97
|
+
steps?: (string | {
|
|
98
|
+
text: LocalizedText;
|
|
99
|
+
mode?: string;
|
|
100
|
+
})[];
|
|
101
|
+
variants?: ConfigurationVariants;
|
|
102
|
+
fields: ConfigField[];
|
|
103
|
+
}
|
|
104
|
+
export interface ConfigSaveResult {
|
|
105
|
+
saved: true;
|
|
106
|
+
scope: string;
|
|
107
|
+
}
|
|
108
|
+
export declare function localizeText(text: LocalizedText | undefined, lang: string, fallback?: string): string;
|
|
109
|
+
export declare function effectiveVisibility(group: Pick<ConfigDeclaration, 'visibility'>, field: Pick<ConfigField, 'visibility'>): 'system' | 'private';
|
|
110
|
+
export declare function required(field: ConfigField, valueOf: (key: string) => unknown): boolean;
|
|
111
|
+
/** The same kinds are checked for declared defaults, preset rows and submitted configuration values. */
|
|
112
|
+
export declare function validateConfigValue(field: ConfigField, value: unknown, at: string): void;
|
|
113
|
+
export declare function validateConfigRecord(fields: ConfigField[], raw: unknown, at: string, complete: boolean): void;
|
|
114
|
+
/** Accepts typed JSON values as well as the string encoding used by operation-driven saves. */
|
|
115
|
+
export declare function decodeConfigValue(field: ConfigField, raw: unknown): unknown;
|
|
116
|
+
/**
|
|
117
|
+
* Validate the effective state produced by a batch, not each row in isolation. The two intentionally valid
|
|
118
|
+
* empty shapes are an untouched group and a disconnected operation target; everything else is checked strictly.
|
|
119
|
+
*/
|
|
120
|
+
export declare function validateBatchEffective(declaration: Pick<ConfigDeclaration, 'fields' | 'variants'>, existingValues: Record<string, unknown>, existingSecrets: Record<string, unknown>, updates: Record<string, unknown>, opts?: {
|
|
121
|
+
operationField?: ConfigField;
|
|
122
|
+
keys?: ReadonlySet<string>;
|
|
123
|
+
}): void;
|
|
124
|
+
export declare const localizedTextSchema: Schema;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
export function localizeText(text, lang, fallback = '') {
|
|
2
|
+
if (text === undefined)
|
|
3
|
+
return fallback;
|
|
4
|
+
if (typeof text === 'string')
|
|
5
|
+
return text;
|
|
6
|
+
return text.translations?.[lang] ?? text.default;
|
|
7
|
+
}
|
|
8
|
+
export function effectiveVisibility(group, field) {
|
|
9
|
+
return field.visibility ?? group.visibility ?? 'system';
|
|
10
|
+
}
|
|
11
|
+
export function required(field, valueOf) {
|
|
12
|
+
if (!field.requiredWhen)
|
|
13
|
+
return !!field.required;
|
|
14
|
+
const actual = valueOf(field.requiredWhen.key);
|
|
15
|
+
return actual !== undefined && [field.requiredWhen.value].flat().some((value) => String(value) === String(actual));
|
|
16
|
+
}
|
|
17
|
+
const MAP_KEY = /^[A-Za-z_][A-Za-z0-9_.-]*$/;
|
|
18
|
+
const empty = (value) => value === undefined || value === null || value === '';
|
|
19
|
+
/** The same kinds are checked for declared defaults, preset rows and submitted configuration values. */
|
|
20
|
+
export function validateConfigValue(field, value, at) {
|
|
21
|
+
const invalid = (expected) => { throw new Error(`${at} 需要${expected}`); };
|
|
22
|
+
switch (field.kind) {
|
|
23
|
+
case 'string':
|
|
24
|
+
case 'secret':
|
|
25
|
+
case 'member':
|
|
26
|
+
if (typeof value !== 'string')
|
|
27
|
+
invalid('文字');
|
|
28
|
+
break;
|
|
29
|
+
case 'number':
|
|
30
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
31
|
+
invalid('有效数字');
|
|
32
|
+
else if (field.minimum !== undefined && value < field.minimum)
|
|
33
|
+
invalid(`不小于 ${field.minimum} 的数字`);
|
|
34
|
+
else if (field.maximum !== undefined && value > field.maximum)
|
|
35
|
+
invalid(`不大于 ${field.maximum} 的数字`);
|
|
36
|
+
else if (field.integer && !Number.isInteger(value))
|
|
37
|
+
invalid('整数');
|
|
38
|
+
break;
|
|
39
|
+
case 'boolean':
|
|
40
|
+
if (typeof value !== 'boolean')
|
|
41
|
+
invalid(' true 或 false');
|
|
42
|
+
break;
|
|
43
|
+
case 'url':
|
|
44
|
+
if (typeof value !== 'string' || !URL.canParse(value) || !['http:', 'https:'].includes(new URL(value).protocol))
|
|
45
|
+
invalid(' HTTP 或 HTTPS 网址');
|
|
46
|
+
break;
|
|
47
|
+
case 'select':
|
|
48
|
+
if (!field.options?.some((option) => option.value === value))
|
|
49
|
+
invalid('选择清单中声明的值');
|
|
50
|
+
break;
|
|
51
|
+
case 'list':
|
|
52
|
+
if (!Array.isArray(value) || !value.every((item) => typeof item === 'string'))
|
|
53
|
+
invalid('字符串数组');
|
|
54
|
+
break;
|
|
55
|
+
case 'map':
|
|
56
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
57
|
+
invalid('键值均为字符串的对象');
|
|
58
|
+
for (const [key, item] of Object.entries(value)) {
|
|
59
|
+
if (!MAP_KEY.test(key))
|
|
60
|
+
invalid(`键名符合配置键规范的对象(${key} 无效)`);
|
|
61
|
+
if (typeof item !== 'string')
|
|
62
|
+
invalid('键值均为字符串的对象');
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
case 'records':
|
|
66
|
+
if (!Array.isArray(value))
|
|
67
|
+
invalid('记录数组');
|
|
68
|
+
value.forEach((row, i) => validateConfigRecord(field.recordFields ?? [], row, `${at}[${i}]`, true));
|
|
69
|
+
break;
|
|
70
|
+
case 'operation':
|
|
71
|
+
invalid('可保存的配置值,operation 本身不可写入');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export function validateConfigRecord(fields, raw, at, complete) {
|
|
75
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
76
|
+
throw new Error(`${at} 需要记录对象`);
|
|
77
|
+
const row = raw;
|
|
78
|
+
for (const key of Object.keys(row)) {
|
|
79
|
+
if (!fields.some((field) => field.key === key))
|
|
80
|
+
throw new Error(`${at} 没有声明字段 ${key}`);
|
|
81
|
+
}
|
|
82
|
+
for (const field of fields) {
|
|
83
|
+
const value = Object.hasOwn(row, field.key) ? row[field.key] : field.default;
|
|
84
|
+
if (value === undefined) {
|
|
85
|
+
if (complete && required(field, (key) => Object.hasOwn(row, key) ? row[key] : fields.find((one) => one.key === key)?.default))
|
|
86
|
+
throw new Error(`${at}.${field.key} 必填`);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (complete && required(field, (key) => Object.hasOwn(row, key) ? row[key] : fields.find((one) => one.key === key)?.default) && empty(value))
|
|
90
|
+
throw new Error(`${at}.${field.key} 必填`);
|
|
91
|
+
validateConfigValue(field, value, `${at}.${field.key}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** Accepts typed JSON values as well as the string encoding used by operation-driven saves. */
|
|
95
|
+
export function decodeConfigValue(field, raw) {
|
|
96
|
+
if (raw === null)
|
|
97
|
+
return null;
|
|
98
|
+
if (typeof raw !== 'string') {
|
|
99
|
+
validateConfigValue(field, raw, field.key);
|
|
100
|
+
return raw;
|
|
101
|
+
}
|
|
102
|
+
if (raw === '' && ['secret', 'url', 'string', 'member'].includes(field.kind))
|
|
103
|
+
return null;
|
|
104
|
+
let value = raw;
|
|
105
|
+
if (field.kind === 'number')
|
|
106
|
+
value = raw.trim() ? Number(raw) : NaN;
|
|
107
|
+
if (field.kind === 'boolean')
|
|
108
|
+
value = raw === 'true' ? true : raw === 'false' ? false : undefined;
|
|
109
|
+
if (field.kind === 'list' || field.kind === 'records' || field.kind === 'map') {
|
|
110
|
+
try {
|
|
111
|
+
value = JSON.parse(raw);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
throw new Error(`${field.key} 需要有效的 JSON`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
validateConfigValue(field, value, field.key);
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
function variantMatches(test, value) {
|
|
121
|
+
return 'const' in test ? value === test.const : Array.isArray(test.enum) && test.enum.includes(String(value));
|
|
122
|
+
}
|
|
123
|
+
function activeBranch(variants, effective) {
|
|
124
|
+
if (!variants)
|
|
125
|
+
return undefined;
|
|
126
|
+
const value = effective[variants.discriminator];
|
|
127
|
+
return variants.branches.find((branch) => {
|
|
128
|
+
const test = branch.when.properties[variants.discriminator];
|
|
129
|
+
return test && variantMatches(test, value);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Validate the effective state produced by a batch, not each row in isolation. The two intentionally valid
|
|
134
|
+
* empty shapes are an untouched group and a disconnected operation target; everything else is checked strictly.
|
|
135
|
+
*/
|
|
136
|
+
export function validateBatchEffective(declaration, existingValues, existingSecrets, updates, opts = {}) {
|
|
137
|
+
const fields = declaration.fields.filter((field) => field.kind !== 'operation');
|
|
138
|
+
const effective = {};
|
|
139
|
+
for (const field of fields) {
|
|
140
|
+
if (field.default !== undefined)
|
|
141
|
+
effective[field.key] = field.default;
|
|
142
|
+
const existing = field.kind === 'secret' ? existingSecrets[field.key] : existingValues[field.key];
|
|
143
|
+
if (existing !== undefined)
|
|
144
|
+
effective[field.key] = existing;
|
|
145
|
+
if (Object.hasOwn(updates, field.key)) {
|
|
146
|
+
if (updates[field.key] === null)
|
|
147
|
+
delete effective[field.key];
|
|
148
|
+
else
|
|
149
|
+
effective[field.key] = updates[field.key];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const { keys } = opts;
|
|
153
|
+
const checked = keys ? fields.filter((field) => keys.has(field.key)) : fields;
|
|
154
|
+
const unconfigured = checked.every((field) => {
|
|
155
|
+
if (field.default !== undefined)
|
|
156
|
+
return true;
|
|
157
|
+
if (field.kind === 'secret')
|
|
158
|
+
return empty(effective[field.key]);
|
|
159
|
+
return empty(effective[field.key]);
|
|
160
|
+
});
|
|
161
|
+
if (unconfigured)
|
|
162
|
+
return;
|
|
163
|
+
const target = opts.operationField?.target ?? [];
|
|
164
|
+
if (opts.operationField && target.length) {
|
|
165
|
+
const targetFields = target.map((key) => declaration.fields.find((field) => field.key === key)).filter((field) => !!field);
|
|
166
|
+
const disconnected = targetFields.every((field) => {
|
|
167
|
+
if (field.kind === 'secret')
|
|
168
|
+
return empty(effective[field.key]);
|
|
169
|
+
if (field.kind === 'string' && field.default === undefined)
|
|
170
|
+
return empty(effective[field.key]);
|
|
171
|
+
return true;
|
|
172
|
+
});
|
|
173
|
+
if (disconnected)
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const branch = activeBranch(declaration.variants, effective);
|
|
177
|
+
const claimed = new Set(declaration.variants?.branches.flatMap((one) => one.fields) ?? []);
|
|
178
|
+
const branchFields = new Set(branch?.fields ?? []);
|
|
179
|
+
for (const field of checked) {
|
|
180
|
+
if (declaration.variants && claimed.has(field.key) && !branchFields.has(field.key))
|
|
181
|
+
continue;
|
|
182
|
+
if (required(field, (key) => effective[key]) && empty(effective[field.key])) {
|
|
183
|
+
throw new Error(`${field.key} 必填`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
export const localizedTextSchema = {
|
|
188
|
+
type: ['string', 'object'],
|
|
189
|
+
properties: { default: { type: 'string' }, translations: { type: 'object', additionalProperties: { type: 'string' } } },
|
|
190
|
+
required: ['default'],
|
|
191
|
+
additionalProperties: false,
|
|
192
|
+
};
|