@songsid/agend 2.4.0-beta.1 → 2.4.0-beta.10
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/dist/agent-cli-instructions.md +4 -1
- package/dist/agent-cli.js +14 -2
- package/dist/agent-cli.js.map +1 -1
- package/dist/agent-endpoint.d.ts +3 -1
- package/dist/agent-endpoint.js +15 -3
- package/dist/agent-endpoint.js.map +1 -1
- package/dist/agent-token-header.d.ts +1 -1
- package/dist/agent-token-header.js +1 -1
- package/dist/app-message-origin.d.ts +2 -0
- package/dist/app-message-origin.js +3 -0
- package/dist/app-message-origin.js.map +1 -0
- package/dist/auth-api.d.ts +8 -0
- package/dist/auth-api.js +39 -1
- package/dist/auth-api.js.map +1 -1
- package/dist/authority/authority-state.d.ts +7 -0
- package/dist/authority/authority-state.js +17 -2
- package/dist/authority/authority-state.js.map +1 -1
- package/dist/authority/web-authority.d.ts +11 -1
- package/dist/authority/web-authority.js +11 -1
- package/dist/authority/web-authority.js.map +1 -1
- package/dist/backend/agy-model-switch.d.ts +22 -0
- package/dist/backend/agy-model-switch.js +62 -0
- package/dist/backend/agy-model-switch.js.map +1 -0
- package/dist/backend/antigravity.d.ts +9 -2
- package/dist/backend/antigravity.js +84 -9
- package/dist/backend/antigravity.js.map +1 -1
- package/dist/backend/claude-code.js +20 -5
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/cli-env-probe.js +1 -1
- package/dist/backend/cli-env-probe.js.map +1 -1
- package/dist/backend/cli-runtime-switch.d.ts +90 -0
- package/dist/backend/cli-runtime-switch.js +273 -0
- package/dist/backend/cli-runtime-switch.js.map +1 -0
- package/dist/backend/codex-footer-hints.d.ts +1 -0
- package/dist/backend/codex-footer-hints.js +15 -0
- package/dist/backend/codex-footer-hints.js.map +1 -1
- package/dist/backend/codex-model-switch.d.ts +41 -0
- package/dist/backend/codex-model-switch.js +170 -0
- package/dist/backend/codex-model-switch.js.map +1 -0
- package/dist/backend/codex.d.ts +6 -4
- package/dist/backend/codex.js +26 -9
- package/dist/backend/codex.js.map +1 -1
- package/dist/backend/credential-profile.js +1 -1
- package/dist/backend/credential-profile.js.map +1 -1
- package/dist/backend/grok-model-switch.d.ts +16 -0
- package/dist/backend/grok-model-switch.js +45 -0
- package/dist/backend/grok-model-switch.js.map +1 -0
- package/dist/backend/grok.js +1 -1
- package/dist/backend/grok.js.map +1 -1
- package/dist/backend/kiro.js +4 -4
- package/dist/backend/kiro.js.map +1 -1
- package/dist/backend/muse.d.ts +2 -0
- package/dist/backend/muse.js +7 -3
- package/dist/backend/muse.js.map +1 -1
- package/dist/backend/native-pane.js +1 -1
- package/dist/backend/native-pane.js.map +1 -1
- package/dist/backend/types.d.ts +2 -0
- package/dist/backend/types.js.map +1 -1
- package/dist/backend-availability.d.ts +22 -0
- package/dist/backend-availability.js +71 -2
- package/dist/backend-availability.js.map +1 -1
- package/dist/backend-signin-guide.js +1 -1
- package/dist/backend-signin-guide.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/channel/adapters/discord.d.ts +10 -0
- package/dist/channel/adapters/discord.js +35 -0
- package/dist/channel/adapters/discord.js.map +1 -1
- package/dist/channel/adapters/telegram.d.ts +2 -0
- package/dist/channel/adapters/telegram.js +3 -0
- package/dist/channel/adapters/telegram.js.map +1 -1
- package/dist/channel/mcp-server.js +10 -1
- package/dist/channel/mcp-server.js.map +1 -1
- package/dist/channel/mcp-tools.js +9 -1
- package/dist/channel/mcp-tools.js.map +1 -1
- package/dist/channel/tool-router.js +9 -2
- package/dist/channel/tool-router.js.map +1 -1
- package/dist/channel/types.d.ts +10 -0
- package/dist/classic-channel-manager.d.ts +1 -1
- package/dist/classic-channel-manager.js +1 -1
- package/dist/cli-audited.js +14 -13
- package/dist/cli-audited.js.map +1 -1
- package/dist/cli-capability.d.ts +3 -0
- package/dist/cli-capability.js.map +1 -1
- package/dist/cli-registry-check.js +1 -1
- package/dist/cli-registry-check.js.map +1 -1
- package/dist/cli-registry.d.ts +1 -0
- package/dist/cli-spec-antigravity.d.ts +1 -0
- package/dist/cli-spec-antigravity.js +3 -1
- package/dist/cli-spec-antigravity.js.map +1 -1
- package/dist/cli.js +8 -0
- package/dist/cli.js.map +1 -1
- package/dist/config-validator.js +18 -1
- package/dist/config-validator.js.map +1 -1
- package/dist/connect/control.d.ts +20 -0
- package/dist/connect/control.js +236 -0
- package/dist/connect/control.js.map +1 -0
- package/dist/connect/install.d.ts +13 -0
- package/dist/connect/install.js +12 -0
- package/dist/connect/install.js.map +1 -0
- package/dist/connect/mcp.d.ts +9 -0
- package/dist/connect/mcp.js +10 -0
- package/dist/connect/mcp.js.map +1 -0
- package/dist/connect/protocol.d.ts +38 -0
- package/dist/connect/protocol.js +36 -0
- package/dist/connect/protocol.js.map +1 -0
- package/dist/connect/service.d.ts +19 -0
- package/dist/connect/service.js +79 -0
- package/dist/connect/service.js.map +1 -0
- package/dist/connect/stdio-entry.d.ts +1 -0
- package/dist/connect/stdio-entry.js +6 -0
- package/dist/connect/stdio-entry.js.map +1 -0
- package/dist/connect/stdio.d.ts +5 -0
- package/dist/connect/stdio.js +33 -0
- package/dist/connect/stdio.js.map +1 -0
- package/dist/daemon.d.ts +64 -2
- package/dist/daemon.js +397 -31
- package/dist/daemon.js.map +1 -1
- package/dist/delivery-consumed-watch.d.ts +2 -0
- package/dist/delivery-consumed-watch.js +4 -1
- package/dist/delivery-consumed-watch.js.map +1 -1
- package/dist/dispatcher-liveness.d.ts +51 -1
- package/dist/dispatcher-liveness.js +92 -2
- package/dist/dispatcher-liveness.js.map +1 -1
- package/dist/event-log.d.ts +1 -1
- package/dist/event-log.js +1 -1
- package/dist/fleet-manager.d.ts +222 -6
- package/dist/fleet-manager.js +1271 -100
- package/dist/fleet-manager.js.map +1 -1
- package/dist/fleet-windows-runtime.js +4 -2
- package/dist/fleet-windows-runtime.js.map +1 -1
- package/dist/general-knowledge/skills/credential-profiles/SKILL.md +11 -1
- package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +10 -0
- package/dist/general-knowledge/skills/fleet-health/SKILL.md +18 -0
- package/dist/general-knowledge/skills/hub/SKILL.md +290 -24
- package/dist/general-knowledge/skills/model-discovery/SKILL.md +4 -0
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +118 -26
- package/dist/general-knowledge/skills/worker-collaboration/SKILL.md +2 -0
- package/dist/hub/admin-dashboard.d.ts +85 -0
- package/dist/hub/admin-dashboard.js +177 -0
- package/dist/hub/admin-dashboard.js.map +1 -0
- package/dist/hub/attachments/store.d.ts +2 -0
- package/dist/hub/attachments/store.js +6 -0
- package/dist/hub/attachments/store.js.map +1 -1
- package/dist/hub/audit/index.d.ts +2 -0
- package/dist/hub/audit/index.js +8 -0
- package/dist/hub/audit/index.js.map +1 -1
- package/dist/hub/buttons.js +3 -1
- package/dist/hub/buttons.js.map +1 -1
- package/dist/hub/catalog.d.ts +7 -4
- package/dist/hub/catalog.js +19 -10
- package/dist/hub/catalog.js.map +1 -1
- package/dist/hub/client.d.ts +13 -0
- package/dist/hub/client.js +85 -11
- package/dist/hub/client.js.map +1 -1
- package/dist/hub/compose/member.d.ts +22 -0
- package/dist/hub/compose/member.js +233 -18
- package/dist/hub/compose/member.js.map +1 -1
- package/dist/hub/compose/server.d.ts +13 -0
- package/dist/hub/compose/server.js +107 -14
- package/dist/hub/compose/server.js.map +1 -1
- package/dist/hub/display-name.d.ts +10 -0
- package/dist/hub/display-name.js +35 -0
- package/dist/hub/display-name.js.map +1 -0
- package/dist/hub/execution/service.d.ts +1 -0
- package/dist/hub/execution/service.js +1 -1
- package/dist/hub/execution/service.js.map +1 -1
- package/dist/hub/fleet-info.d.ts +12 -0
- package/dist/hub/fleet-info.js +14 -0
- package/dist/hub/fleet-info.js.map +1 -0
- package/dist/hub/fleet-update-model.d.ts +100 -0
- package/dist/hub/fleet-update-model.js +15 -0
- package/dist/hub/fleet-update-model.js.map +1 -0
- package/dist/hub/fleet-updates.d.ts +46 -0
- package/dist/hub/fleet-updates.js +282 -0
- package/dist/hub/fleet-updates.js.map +1 -0
- package/dist/hub/fleet-versions.d.ts +28 -0
- package/dist/hub/fleet-versions.js +80 -0
- package/dist/hub/fleet-versions.js.map +1 -0
- package/dist/hub/group-policy/admin-api.d.ts +1 -0
- package/dist/hub/group-policy/admin-api.js +10 -1
- package/dist/hub/group-policy/admin-api.js.map +1 -1
- package/dist/hub/group-policy/admin-control.d.ts +1 -0
- package/dist/hub/group-policy/admin-control.js +13 -4
- package/dist/hub/group-policy/admin-control.js.map +1 -1
- package/dist/hub/group-policy/admin-dto.d.ts +39 -1
- package/dist/hub/group-policy/admin-dto.js.map +1 -1
- package/dist/hub/group-policy/admin-facts.d.ts +4 -2
- package/dist/hub/group-policy/admin-facts.js +17 -2
- package/dist/hub/group-policy/admin-facts.js.map +1 -1
- package/dist/hub/group-policy/admin-impact.d.ts +36 -6
- package/dist/hub/group-policy/admin-impact.js +21 -7
- package/dist/hub/group-policy/admin-impact.js.map +1 -1
- package/dist/hub/group-policy/admin-inventory.d.ts +2 -0
- package/dist/hub/group-policy/admin-inventory.js +13 -4
- package/dist/hub/group-policy/admin-inventory.js.map +1 -1
- package/dist/hub/group-policy/admin-search.d.ts +2 -1
- package/dist/hub/group-policy/admin-search.js +56 -7
- package/dist/hub/group-policy/admin-search.js.map +1 -1
- package/dist/hub/group-policy/authorization.d.ts +2 -0
- package/dist/hub/group-policy/authorization.js +7 -2
- package/dist/hub/group-policy/authorization.js.map +1 -1
- package/dist/hub/group-policy/impact-inventory.d.ts +4 -1
- package/dist/hub/group-policy/impact-inventory.js +23 -2
- package/dist/hub/group-policy/impact-inventory.js.map +1 -1
- package/dist/hub/group-policy/model.d.ts +52 -1
- package/dist/hub/group-policy/model.js +20 -7
- package/dist/hub/group-policy/model.js.map +1 -1
- package/dist/hub/group-policy/resources.d.ts +2 -0
- package/dist/hub/group-policy/resources.js +12 -1
- package/dist/hub/group-policy/resources.js.map +1 -1
- package/dist/hub/group-policy/store.js +22 -3
- package/dist/hub/group-policy/store.js.map +1 -1
- package/dist/hub/group-policy/team-subjects.d.ts +16 -0
- package/dist/hub/group-policy/team-subjects.js +32 -0
- package/dist/hub/group-policy/team-subjects.js.map +1 -0
- package/dist/hub/http/compose.d.ts +2 -0
- package/dist/hub/http/compose.js +385 -32
- package/dist/hub/http/compose.js.map +1 -1
- package/dist/hub/http/core.js +27 -0
- package/dist/hub/http/core.js.map +1 -1
- package/dist/hub/http/deps.d.ts +13 -0
- package/dist/hub/http/schema.js +21 -1
- package/dist/hub/http/schema.js.map +1 -1
- package/dist/hub/join/client.js +75 -42
- package/dist/hub/join/client.js.map +1 -1
- package/dist/hub/join/service.d.ts +1 -1
- package/dist/hub/join/service.js.map +1 -1
- package/dist/hub/mcp/auth-schema.d.ts +7 -0
- package/dist/hub/mcp/auth-schema.js +31 -0
- package/dist/hub/mcp/auth-schema.js.map +1 -0
- package/dist/hub/mcp/auth.d.ts +89 -0
- package/dist/hub/mcp/auth.js +374 -0
- package/dist/hub/mcp/auth.js.map +1 -0
- package/dist/hub/mcp/catalog.d.ts +44 -0
- package/dist/hub/mcp/catalog.js +31 -0
- package/dist/hub/mcp/catalog.js.map +1 -0
- package/dist/hub/mcp/door-schema.d.ts +7 -0
- package/dist/hub/mcp/door-schema.js +20 -0
- package/dist/hub/mcp/door-schema.js.map +1 -0
- package/dist/hub/mcp/http.d.ts +25 -0
- package/dist/hub/mcp/http.js +259 -0
- package/dist/hub/mcp/http.js.map +1 -0
- package/dist/hub/mcp/policy.d.ts +65 -0
- package/dist/hub/mcp/policy.js +153 -0
- package/dist/hub/mcp/policy.js.map +1 -0
- package/dist/hub/mcp/server.d.ts +3 -0
- package/dist/hub/mcp/server.js +32 -0
- package/dist/hub/mcp/server.js.map +1 -0
- package/dist/hub/mcp/tools.d.ts +31 -0
- package/dist/hub/mcp/tools.js +176 -0
- package/dist/hub/mcp/tools.js.map +1 -0
- package/dist/hub/member/display-name.d.ts +9 -0
- package/dist/hub/member/display-name.js +71 -0
- package/dist/hub/member/display-name.js.map +1 -0
- package/dist/hub/member/exposure-api.d.ts +6 -0
- package/dist/hub/member/exposure-api.js +13 -6
- package/dist/hub/member/exposure-api.js.map +1 -1
- package/dist/hub/member/exposures.d.ts +4 -0
- package/dist/hub/member/exposures.js +20 -0
- package/dist/hub/member/exposures.js.map +1 -1
- package/dist/hub/member/pairing-api.js +3 -2
- package/dist/hub/member/pairing-api.js.map +1 -1
- package/dist/hub/member/recommendations.d.ts +37 -0
- package/dist/hub/member/recommendations.js +129 -0
- package/dist/hub/member/recommendations.js.map +1 -0
- package/dist/hub/member/room-ask.d.ts +65 -5
- package/dist/hub/member/room-ask.js +269 -24
- package/dist/hub/member/room-ask.js.map +1 -1
- package/dist/hub/member/room-mention-feedback.d.ts +44 -0
- package/dist/hub/member/room-mention-feedback.js +121 -0
- package/dist/hub/member/room-mention-feedback.js.map +1 -0
- package/dist/hub/member/room-notification.d.ts +9 -0
- package/dist/hub/member/room-notification.js +2 -0
- package/dist/hub/member/room-notification.js.map +1 -0
- package/dist/hub/member/room-post-answers.d.ts +46 -0
- package/dist/hub/member/room-post-answers.js +152 -0
- package/dist/hub/member/room-post-answers.js.map +1 -0
- package/dist/hub/member/room-post-receipt.d.ts +21 -0
- package/dist/hub/member/room-post-receipt.js +49 -0
- package/dist/hub/member/room-post-receipt.js.map +1 -0
- package/dist/hub/member/room-post.d.ts +103 -0
- package/dist/hub/member/room-post.js +231 -0
- package/dist/hub/member/room-post.js.map +1 -0
- package/dist/hub/member/updates.d.ts +92 -0
- package/dist/hub/member/updates.js +316 -0
- package/dist/hub/member/updates.js.map +1 -0
- package/dist/hub/pairing.d.ts +15 -1
- package/dist/hub/pairing.js +33 -2
- package/dist/hub/pairing.js.map +1 -1
- package/dist/hub/person-prefs.d.ts +22 -0
- package/dist/hub/person-prefs.js +34 -0
- package/dist/hub/person-prefs.js.map +1 -0
- package/dist/hub/personal/owner-host.d.ts +140 -0
- package/dist/hub/personal/owner-host.js +287 -0
- package/dist/hub/personal/owner-host.js.map +1 -0
- package/dist/hub/personal/refusals.d.ts +11 -0
- package/dist/hub/personal/refusals.js +33 -0
- package/dist/hub/personal/refusals.js.map +1 -0
- package/dist/hub/personal/runtime-host.d.ts +26 -0
- package/dist/hub/personal/runtime-host.js +51 -0
- package/dist/hub/personal/runtime-host.js.map +1 -0
- package/dist/hub/personal/schema.d.ts +4 -0
- package/dist/hub/personal/schema.js +54 -0
- package/dist/hub/personal/schema.js.map +1 -0
- package/dist/hub/personal/turns.d.ts +39 -0
- package/dist/hub/personal/turns.js +221 -0
- package/dist/hub/personal/turns.js.map +1 -0
- package/dist/hub/personal/types.d.ts +42 -0
- package/dist/hub/personal/types.js +2 -0
- package/dist/hub/personal/types.js.map +1 -0
- package/dist/hub/policy.d.ts +1 -1
- package/dist/hub/policy.js +2 -0
- package/dist/hub/policy.js.map +1 -1
- package/dist/hub/protocol.d.ts +701 -1
- package/dist/hub/protocol.js +103 -14
- package/dist/hub/protocol.js.map +1 -1
- package/dist/hub/published-version.d.ts +3 -0
- package/dist/hub/published-version.js +35 -0
- package/dist/hub/published-version.js.map +1 -0
- package/dist/hub/quota.js +3 -1
- package/dist/hub/quota.js.map +1 -1
- package/dist/hub/recommendation-model.d.ts +36 -0
- package/dist/hub/recommendation-model.js +9 -0
- package/dist/hub/recommendation-model.js.map +1 -0
- package/dist/hub/recommendations.d.ts +58 -0
- package/dist/hub/recommendations.js +211 -0
- package/dist/hub/recommendations.js.map +1 -0
- package/dist/hub/representative.d.ts +5 -0
- package/dist/hub/representative.js +6 -1
- package/dist/hub/representative.js.map +1 -1
- package/dist/hub/roles/admin-control.d.ts +29 -0
- package/dist/hub/roles/admin-control.js +187 -0
- package/dist/hub/roles/admin-control.js.map +1 -0
- package/dist/hub/roles/admin-types.d.ts +72 -0
- package/dist/hub/roles/admin-types.js +2 -0
- package/dist/hub/roles/admin-types.js.map +1 -0
- package/dist/hub/roles/allowed-list-control.d.ts +34 -0
- package/dist/hub/roles/allowed-list-control.js +179 -0
- package/dist/hub/roles/allowed-list-control.js.map +1 -0
- package/dist/hub/roles/allowed-list.d.ts +8 -0
- package/dist/hub/roles/allowed-list.js +49 -0
- package/dist/hub/roles/allowed-list.js.map +1 -0
- package/dist/hub/roles/audit-details.d.ts +144 -0
- package/dist/hub/roles/audit-details.js +26 -0
- package/dist/hub/roles/audit-details.js.map +1 -0
- package/dist/hub/roles/authority.d.ts +12 -0
- package/dist/hub/roles/authority.js +39 -3
- package/dist/hub/roles/authority.js.map +1 -1
- package/dist/hub/roles/change.d.ts +3 -1
- package/dist/hub/roles/change.js +7 -2
- package/dist/hub/roles/change.js.map +1 -1
- package/dist/hub/roles/clock.d.ts +3 -0
- package/dist/hub/roles/clock.js +1 -1
- package/dist/hub/roles/clock.js.map +1 -1
- package/dist/hub/roles/convert.js +1 -1
- package/dist/hub/roles/convert.js.map +1 -1
- package/dist/hub/roles/cutover-inventory.d.ts +2 -0
- package/dist/hub/roles/cutover-inventory.js +8 -1
- package/dist/hub/roles/cutover-inventory.js.map +1 -1
- package/dist/hub/roles/cutover.d.ts +2 -2
- package/dist/hub/roles/cutover.js +3 -4
- package/dist/hub/roles/cutover.js.map +1 -1
- package/dist/hub/roles/delegation.d.ts +4 -1
- package/dist/hub/roles/delegation.js +7 -2
- package/dist/hub/roles/delegation.js.map +1 -1
- package/dist/hub/roles/evaluate.d.ts +2 -1
- package/dist/hub/roles/evaluate.js +14 -0
- package/dist/hub/roles/evaluate.js.map +1 -1
- package/dist/hub/roles/expiry-effects.d.ts +8 -0
- package/dist/hub/roles/expiry-effects.js +50 -0
- package/dist/hub/roles/expiry-effects.js.map +1 -0
- package/dist/hub/roles/migrations.d.ts +7 -0
- package/dist/hub/roles/migrations.js +44 -0
- package/dist/hub/roles/migrations.js.map +1 -0
- package/dist/hub/roles/model.d.ts +25 -0
- package/dist/hub/roles/model.js +9 -3
- package/dist/hub/roles/model.js.map +1 -1
- package/dist/hub/roles/overview.d.ts +8 -0
- package/dist/hub/roles/overview.js +15 -0
- package/dist/hub/roles/overview.js.map +1 -0
- package/dist/hub/roles/resource-effects.d.ts +17 -0
- package/dist/hub/roles/resource-effects.js +62 -0
- package/dist/hub/roles/resource-effects.js.map +1 -0
- package/dist/hub/roles/review.d.ts +16 -0
- package/dist/hub/roles/review.js +42 -0
- package/dist/hub/roles/review.js.map +1 -0
- package/dist/hub/roles/writer.d.ts +14 -3
- package/dist/hub/roles/writer.js +64 -16
- package/dist/hub/roles/writer.js.map +1 -1
- package/dist/hub/room-context-model.d.ts +43 -0
- package/dist/hub/room-context-model.js +12 -0
- package/dist/hub/room-context-model.js.map +1 -0
- package/dist/hub/room-mention-feedback-model.d.ts +12 -0
- package/dist/hub/room-mention-feedback-model.js +12 -0
- package/dist/hub/room-mention-feedback-model.js.map +1 -0
- package/dist/hub/rooms/agents.d.ts +44 -10
- package/dist/hub/rooms/agents.js +277 -30
- package/dist/hub/rooms/agents.js.map +1 -1
- package/dist/hub/rooms/assistant.d.ts +1 -6
- package/dist/hub/rooms/assistant.js +7 -2
- package/dist/hub/rooms/assistant.js.map +1 -1
- package/dist/hub/rooms/automation.d.ts +24 -0
- package/dist/hub/rooms/automation.js +66 -0
- package/dist/hub/rooms/automation.js.map +1 -0
- package/dist/hub/rooms/buttons.d.ts +85 -0
- package/dist/hub/rooms/buttons.js +62 -0
- package/dist/hub/rooms/buttons.js.map +1 -0
- package/dist/hub/rooms/context-cursor.d.ts +18 -0
- package/dist/hub/rooms/context-cursor.js +61 -0
- package/dist/hub/rooms/context-cursor.js.map +1 -0
- package/dist/hub/rooms/context.d.ts +1 -1
- package/dist/hub/rooms/context.js +4 -4
- package/dist/hub/rooms/context.js.map +1 -1
- package/dist/hub/rooms/direct-view.d.ts +6 -2
- package/dist/hub/rooms/direct-view.js +3 -3
- package/dist/hub/rooms/direct-view.js.map +1 -1
- package/dist/hub/rooms/mentions.d.ts +15 -0
- package/dist/hub/rooms/mentions.js +43 -0
- package/dist/hub/rooms/mentions.js.map +1 -0
- package/dist/hub/rooms/post-replies.d.ts +23 -0
- package/dist/hub/rooms/post-replies.js +114 -0
- package/dist/hub/rooms/post-replies.js.map +1 -0
- package/dist/hub/rooms/schema.d.ts +9 -0
- package/dist/hub/rooms/schema.js +43 -0
- package/dist/hub/rooms/schema.js.map +1 -1
- package/dist/hub/rooms/service.d.ts +163 -4
- package/dist/hub/rooms/service.js +795 -25
- package/dist/hub/rooms/service.js.map +1 -1
- package/dist/hub/rooms/types.d.ts +29 -3
- package/dist/hub/rooms.d.ts +12 -2
- package/dist/hub/rooms.js +88 -18
- package/dist/hub/rooms.js.map +1 -1
- package/dist/hub/runtime.d.ts +1 -1
- package/dist/hub/runtime.js +17 -4
- package/dist/hub/runtime.js.map +1 -1
- package/dist/hub/server.d.ts +8 -1
- package/dist/hub/server.js +93 -7
- package/dist/hub/server.js.map +1 -1
- package/dist/hub/session-directory-transition.d.ts +2 -1
- package/dist/hub/session-directory-transition.js +10 -3
- package/dist/hub/session-directory-transition.js.map +1 -1
- package/dist/hub/sessions.d.ts +1 -1
- package/dist/hub/sessions.js +26 -4
- package/dist/hub/sessions.js.map +1 -1
- package/dist/hub/settings-commit.d.ts +32 -1
- package/dist/hub/settings-commit.js +11 -4
- package/dist/hub/settings-commit.js.map +1 -1
- package/dist/hub/settings-directory-ca.js +1 -1
- package/dist/hub/settings-directory-ca.js.map +1 -1
- package/dist/hub/settings-directory-control.js +7 -7
- package/dist/hub/settings-directory-control.js.map +1 -1
- package/dist/hub/settings-directory-http.d.ts +2 -0
- package/dist/hub/settings-directory-http.js +21 -6
- package/dist/hub/settings-directory-http.js.map +1 -1
- package/dist/hub/settings-directory-proof.d.ts +5 -1
- package/dist/hub/settings-directory-proof.js +49 -10
- package/dist/hub/settings-directory-proof.js.map +1 -1
- package/dist/hub/settings-directory-recovery.js +2 -1
- package/dist/hub/settings-directory-recovery.js.map +1 -1
- package/dist/hub/settings-directory-save.d.ts +2 -0
- package/dist/hub/settings-directory-save.js +9 -6
- package/dist/hub/settings-directory-save.js.map +1 -1
- package/dist/hub/sharing.js +2 -2
- package/dist/hub/sharing.js.map +1 -1
- package/dist/hub/socket.d.ts +1 -0
- package/dist/hub/socket.js +39 -2
- package/dist/hub/socket.js.map +1 -1
- package/dist/hub/teams/index.d.ts +8 -3
- package/dist/hub/teams/index.js +106 -31
- package/dist/hub/teams/index.js.map +1 -1
- package/dist/hub/teams/store.d.ts +5 -1
- package/dist/hub/teams/store.js +25 -2
- package/dist/hub/teams/store.js.map +1 -1
- package/dist/hub/teams/types.d.ts +19 -2
- package/dist/hub/types.d.ts +159 -5
- package/dist/hub-classic-private.d.ts +19 -0
- package/dist/hub-classic-private.js +64 -0
- package/dist/hub-classic-private.js.map +1 -0
- package/dist/hub-contact-windows.d.ts +11 -0
- package/dist/hub-contact-windows.js +56 -0
- package/dist/hub-contact-windows.js.map +1 -0
- package/dist/hub-pairing-summary.d.ts +1 -1
- package/dist/hub-room-conversation.d.ts +14 -0
- package/dist/hub-room-conversation.js +60 -0
- package/dist/hub-room-conversation.js.map +1 -0
- package/dist/hub-update-notice.d.ts +12 -0
- package/dist/hub-update-notice.js +35 -0
- package/dist/hub-update-notice.js.map +1 -0
- package/dist/human-delivery-receipts.js +8 -0
- package/dist/human-delivery-receipts.js.map +1 -1
- package/dist/instance-config-impact.js +3 -0
- package/dist/instance-config-impact.js.map +1 -1
- package/dist/instructions.js +3 -0
- package/dist/instructions.js.map +1 -1
- package/dist/locale.js +137 -24
- package/dist/locale.js.map +1 -1
- package/dist/login-controller.d.ts +19 -2
- package/dist/login-controller.js +26 -8
- package/dist/login-controller.js.map +1 -1
- package/dist/native-mcp.js +7 -5
- package/dist/native-mcp.js.map +1 -1
- package/dist/native-model-catalog.d.ts +15 -0
- package/dist/native-model-catalog.js +43 -3
- package/dist/native-model-catalog.js.map +1 -1
- package/dist/native-pane-lifecycle.js +3 -2
- package/dist/native-pane-lifecycle.js.map +1 -1
- package/dist/native-pane-tools.js +3 -0
- package/dist/native-pane-tools.js.map +1 -1
- package/dist/office-share-page.js +1 -1
- package/dist/office-share-page.js.map +1 -1
- package/dist/outbound-handlers.d.ts +14 -4
- package/dist/outbound-handlers.js +54 -1
- package/dist/outbound-handlers.js.map +1 -1
- package/dist/outbound-schemas.d.ts +17 -0
- package/dist/outbound-schemas.js +14 -0
- package/dist/outbound-schemas.js.map +1 -1
- package/dist/pane-port.d.ts +2 -0
- package/dist/public-web-gateway.js +152 -4
- package/dist/public-web-gateway.js.map +1 -1
- package/dist/queued-handoffs.d.ts +16 -4
- package/dist/queued-handoffs.js +18 -1
- package/dist/queued-handoffs.js.map +1 -1
- package/dist/quickstart-api.d.ts +0 -1
- package/dist/quickstart-api.js +8 -1
- package/dist/quickstart-api.js.map +1 -1
- package/dist/reply-dedup.js +3 -1
- package/dist/reply-dedup.js.map +1 -1
- package/dist/reply-preview-files.d.ts +38 -0
- package/dist/reply-preview-files.js +142 -0
- package/dist/reply-preview-files.js.map +1 -0
- package/dist/reply-preview-spec.d.ts +18 -0
- package/dist/reply-preview-spec.js +27 -0
- package/dist/reply-preview-spec.js.map +1 -0
- package/dist/runtime-api.js +10 -2
- package/dist/runtime-api.js.map +1 -1
- package/dist/runtime-build-info.js +1 -0
- package/dist/runtime-build-info.js.map +1 -1
- package/dist/runtime-cli-install.js +13 -10
- package/dist/runtime-cli-install.js.map +1 -1
- package/dist/runtime-cli.js +31 -5
- package/dist/runtime-cli.js.map +1 -1
- package/dist/runtime-client-store.d.ts +5 -0
- package/dist/runtime-client-store.js +28 -0
- package/dist/runtime-client-store.js.map +1 -1
- package/dist/runtime-client.d.ts +4 -0
- package/dist/runtime-client.js +33 -10
- package/dist/runtime-client.js.map +1 -1
- package/dist/runtime-coordinator.d.ts +4 -2
- package/dist/runtime-coordinator.js +33 -6
- package/dist/runtime-coordinator.js.map +1 -1
- package/dist/runtime-install.d.ts +6 -1
- package/dist/runtime-install.js +12 -4
- package/dist/runtime-install.js.map +1 -1
- package/dist/runtime-pane-native.js +3 -1
- package/dist/runtime-pane-native.js.map +1 -1
- package/dist/runtime-personal-answer-only-probe.d.ts +3 -0
- package/dist/runtime-personal-answer-only-probe.js +134 -0
- package/dist/runtime-personal-answer-only-probe.js.map +1 -0
- package/dist/runtime-personal-answer-only.d.ts +16 -0
- package/dist/runtime-personal-answer-only.js +54 -0
- package/dist/runtime-personal-answer-only.js.map +1 -0
- package/dist/runtime-personal-answer.d.ts +30 -0
- package/dist/runtime-personal-answer.js +124 -0
- package/dist/runtime-personal-answer.js.map +1 -0
- package/dist/runtime-personal-preflight.d.ts +8 -0
- package/dist/runtime-personal-preflight.js +103 -0
- package/dist/runtime-personal-preflight.js.map +1 -0
- package/dist/runtime-personal-profile.d.ts +40 -0
- package/dist/runtime-personal-profile.js +81 -0
- package/dist/runtime-personal-profile.js.map +1 -0
- package/dist/runtime-personal-protocol.d.ts +10 -0
- package/dist/runtime-personal-protocol.js +15 -0
- package/dist/runtime-personal-protocol.js.map +1 -0
- package/dist/runtime-personal-stage.d.ts +37 -0
- package/dist/runtime-personal-stage.js +167 -0
- package/dist/runtime-personal-stage.js.map +1 -0
- package/dist/runtime-protocol.d.ts +2 -0
- package/dist/settings-api.d.ts +15 -0
- package/dist/settings-api.js +210 -76
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-change.js +32 -5
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-effect.js +13 -2
- package/dist/settings-effect.js.map +1 -1
- package/dist/settings-http-confirmation.js +18 -44
- package/dist/settings-http-confirmation.js.map +1 -1
- package/dist/setup-form.js +10 -0
- package/dist/setup-form.js.map +1 -1
- package/dist/setup-i18n.js +2 -2
- package/dist/setup-i18n.js.map +1 -1
- package/dist/subagent-records.js +53 -11
- package/dist/subagent-records.js.map +1 -1
- package/dist/subagent-service.js +3 -1
- package/dist/subagent-service.js.map +1 -1
- package/dist/tmux-manager.d.ts +2 -0
- package/dist/tmux-manager.js +2 -0
- package/dist/tmux-manager.js.map +1 -1
- package/dist/tool-permissions.js +3 -0
- package/dist/tool-permissions.js.map +1 -1
- package/dist/tool-progress.d.ts +9 -0
- package/dist/tool-progress.js +141 -32
- package/dist/tool-progress.js.map +1 -1
- package/dist/transcript-needles.d.ts +4 -2
- package/dist/transcript-needles.js +35 -4
- package/dist/transcript-needles.js.map +1 -1
- package/dist/tunnel/lease.d.ts +14 -0
- package/dist/tunnel/lease.js +23 -0
- package/dist/tunnel/lease.js.map +1 -1
- package/dist/turn-reply-guard.d.ts +2 -2
- package/dist/turn-reply-guard.js +3 -3
- package/dist/turn-reply-guard.js.map +1 -1
- package/dist/types.d.ts +12 -2
- package/dist/ui/backend-signin.js +91 -22
- package/dist/ui/chat-activity-groups.js +41 -8
- package/dist/ui/chat-activity.js +5 -3
- package/dist/ui/chat-mentions.js +13 -0
- package/dist/ui/chat-msg-actions.js +3 -222
- package/dist/ui/chat-pins.js +106 -0
- package/dist/ui/chat-popout-header.js +2 -2
- package/dist/ui/chat-store.js +143 -7
- package/dist/ui/chat-tour.js +1 -1
- package/dist/ui/chat-workspace.js +3 -3
- package/dist/ui/fleet-canvas.js +14 -5
- package/dist/ui/fleet-office-carousel.d.ts +14 -0
- package/dist/ui/fleet-office-carousel.js +95 -0
- package/dist/ui/fleet-office-editor.js +6 -1
- package/dist/ui/fleet-office-model.js +2 -1
- package/dist/ui/fleet-office-skin.js +1 -1
- package/dist/ui/fleet-office-store.js +14 -2
- package/dist/ui/fleet-office-zones.js +50 -9
- package/dist/ui/fleet-office.js +203 -24
- package/dist/ui/fleet-tasks.js +1 -1
- package/dist/ui/host-install.js +5 -2
- package/dist/ui/hub-admin-overview.js +189 -0
- package/dist/ui/hub-admin-rooms.js +1 -1
- package/dist/ui/hub-agent-copy.js +6 -2
- package/dist/ui/hub-ai-apps-strings.js +6 -0
- package/dist/ui/hub-ai-apps.js +83 -0
- package/dist/ui/hub-chat-strings.js +7 -0
- package/dist/ui/hub-client.js +76 -5
- package/dist/ui/hub-directory-editor-strings.js +2 -2
- package/dist/ui/hub-directory-editor.js +1 -0
- package/dist/ui/hub-fleet-versions.js +393 -0
- package/dist/ui/hub-grant-picker.js +3 -37
- package/dist/ui/hub-group-policy.js +26 -13
- package/dist/ui/hub-group-strings.js +26 -17
- package/dist/ui/hub-join-steps.js +27 -15
- package/dist/ui/hub-owner-strings.js +2 -2
- package/dist/ui/hub-personal-agent-strings.js +246 -0
- package/dist/ui/hub-personal-agent.js +117 -0
- package/dist/ui/hub-policy-subjects.js +35 -0
- package/dist/ui/hub-quick-pairing.js +7 -2
- package/dist/ui/hub-role-audit.js +39 -0
- package/dist/ui/hub-role-forms.js +99 -0
- package/dist/ui/hub-role-notices.js +11 -0
- package/dist/ui/hub-role-view.js +86 -0
- package/dist/ui/hub-roles-strings.js +439 -0
- package/dist/ui/hub-roles.js +83 -0
- package/dist/ui/hub-room-agent-strings.js +28 -0
- package/dist/ui/hub-room-composer.js +19 -10
- package/dist/ui/hub-room-favorites.js +63 -5
- package/dist/ui/hub-room-list.js +4 -3
- package/dist/ui/hub-room-members-strings.js +2 -2
- package/dist/ui/hub-room-members.js +7 -4
- package/dist/ui/hub-room-notify.js +161 -0
- package/dist/ui/hub-room-search.js +126 -0
- package/dist/ui/hub-room-settings.js +6 -0
- package/dist/ui/hub-room-source-strings.js +17 -0
- package/dist/ui/hub-room-source.js +34 -0
- package/dist/ui/hub-room-strings.js +47 -1
- package/dist/ui/hub-room-thread.js +266 -41
- package/dist/ui/hub-room-unread.js +2 -1
- package/dist/ui/hub-strings.js +8 -0
- package/dist/ui/hub-subject-picker.js +58 -0
- package/dist/ui/hub-switcher.js +2 -2
- package/dist/ui/hub-teams-strings.js +10 -6
- package/dist/ui/hub-teams.js +56 -28
- package/dist/ui/hub-this-hub.js +2 -2
- package/dist/ui/hub-welcome.js +122 -75
- package/dist/ui/image-annotate.js +2 -283
- package/dist/ui/image-lightbox.js +2 -176
- package/dist/ui/image-zoom.js +2 -242
- package/dist/ui/model-picker.js +4 -1
- package/dist/ui/notice-hub-update.js +94 -0
- package/dist/ui/office-share-dialog.js +2 -2
- package/dist/ui/panel-chat.js +327 -28
- package/dist/ui/panel-details.js +3 -1
- package/dist/ui/panel-fleet.js +28 -7
- package/dist/ui/panel-hub.js +294 -99
- package/dist/ui/panel-log.js +4 -4
- package/dist/ui/panel-notices.js +3 -1
- package/dist/ui/panel-settings.js +45 -34
- package/dist/ui/preview-panel.js +3 -1
- package/dist/ui/reply-file-preview.js +64 -0
- package/dist/ui/runtime-commands.d.ts +2 -2
- package/dist/ui/runtime-commands.js +7 -4
- package/dist/ui/settings-access-overview.js +3 -3
- package/dist/ui/settings-appearance.js +7 -10
- package/dist/ui/settings-archive-files.js +109 -0
- package/dist/ui/settings-build-version.js +2 -2
- package/dist/ui/settings-catalog.js +22 -0
- package/dist/ui/settings-connector-strings.js +23 -0
- package/dist/ui/settings-connector.js +39 -0
- package/dist/ui/settings-guests-entries.js +16 -0
- package/dist/ui/settings-guests.js +57 -15
- package/dist/ui/settings-hub-connection.js +4 -5
- package/dist/ui/settings-hub-membership.js +6 -7
- package/dist/ui/settings-hub-section.js +2 -4
- package/dist/ui/settings-hub-setup.js +2 -1
- package/dist/ui/settings-hub-updates.js +67 -0
- package/dist/ui/settings-hub.js +30 -4
- package/dist/ui/settings-layout.js +10 -12
- package/dist/ui/settings-registry.js +18 -3
- package/dist/ui/settings-shared-strings.js +2 -0
- package/dist/ui/settings-strings.js +13 -2
- package/dist/ui/settings-update.js +11 -5
- package/dist/ui/settings-web-authority.js +7 -5
- package/dist/ui/shared/access-overview.css +1 -1
- package/dist/ui/shared/accounts-keepalive.css +1 -1
- package/dist/ui/shared/accounts.css +1 -1
- package/dist/ui/shared/agent-sheet.js +116 -0
- package/dist/ui/shared/agent-widget.js +1 -2
- package/dist/ui/shared/app-i18n.js +4 -0
- package/dist/ui/shared/app-nav.js +9 -5
- package/dist/ui/shared/app-prefs.js +9 -3
- package/dist/ui/shared/app-route.js +4 -2
- package/dist/ui/shared/app-shell.js +176 -21
- package/dist/ui/shared/app-store.js +1 -1
- package/dist/ui/shared/app-stream.js +6 -2
- package/dist/ui/shared/app-swipe.js +3 -1
- package/dist/ui/shared/app-themes.js +3 -5
- package/dist/ui/shared/app-update.js +90 -8
- package/dist/ui/shared/app.css +469 -203
- package/dist/ui/shared/app.js +1 -1
- package/dist/ui/shared/chat-composer.js +29 -5
- package/dist/ui/shared/chat-msg-actions.js +231 -0
- package/dist/ui/shared/chat-strings.js +19 -4
- package/dist/ui/shared/chat-thread.js +120 -17
- package/dist/ui/shared/chat-work-bar.css +118 -0
- package/dist/ui/shared/connector-prompt.d.ts +3 -0
- package/dist/ui/shared/connector-prompt.js +20 -0
- package/dist/ui/shared/hub-ai-apps.css +12 -0
- package/dist/ui/shared/hub-chat.css +58 -4
- package/dist/ui/shared/hub-groups.css +19 -15
- package/dist/ui/shared/hub-owner.css +118 -3
- package/dist/ui/shared/hub-roles.css +99 -0
- package/dist/ui/shared/hub-rooms-u2.css +34 -0
- package/dist/ui/shared/hub.css +23 -5
- package/dist/ui/shared/image-annotate.css +22 -3
- package/dist/ui/shared/image-annotate.js +415 -0
- package/dist/ui/shared/image-lightbox.js +218 -0
- package/dist/ui/shared/image-zoom.js +316 -0
- package/dist/ui/shared/instance-nav.js +120 -15
- package/dist/ui/shared/loading.css +1 -1
- package/dist/ui/shared/model-picker.css +32 -4
- package/dist/ui/shared/owner-css.js +1 -1
- package/dist/ui/shared/panel-view.js +7 -1
- package/dist/ui/shared/preview-panel-actions.js +1 -1
- package/dist/ui/shared/preview-panel.js +6 -2
- package/dist/ui/shared/reply-previews.css +4 -0
- package/dist/ui/shared/runtime-install.css +5 -0
- package/dist/ui/shared/settings-connector.css +7 -0
- package/dist/ui/shared/signin.js +27 -12
- package/dist/ui/shared/task-board.css +2 -2
- package/dist/ui/shared/theme.js +52 -0
- package/dist/ui/shared/tokens.css +27 -10
- package/dist/ui/shared/ui-icons.js +2 -0
- package/dist/ui/shared/ui-toast.js +4 -4
- package/dist/ui/shared/usage-dialog.js +113 -17
- package/dist/ui/shared/view-strings.js +26 -4
- package/dist/ui/shared/web-authorize.js +3 -3
- package/dist/ui/signin.html +4 -2
- package/dist/ui/structured-signin.js +64 -12
- package/dist/ui/web-terminal/terminal.css +1 -1
- package/dist/ui/workspace-panel.js +4 -3
- package/dist/update-dispatch.d.ts +8 -1
- package/dist/update-dispatch.js +16 -1
- package/dist/update-dispatch.js.map +1 -1
- package/dist/update-idle.d.ts +65 -0
- package/dist/update-idle.js +190 -0
- package/dist/update-idle.js.map +1 -0
- package/dist/update-launch.d.ts +1 -1
- package/dist/update-launch.js +9 -2
- package/dist/update-launch.js.map +1 -1
- package/dist/usage/i18n-keys.d.ts +1 -1
- package/dist/usage/i18n-keys.js +1 -1
- package/dist/usage/i18n-keys.js.map +1 -1
- package/dist/usage/profile-timeline.d.ts +2 -0
- package/dist/usage/profile-timeline.js +4 -0
- package/dist/usage/profile-timeline.js.map +1 -1
- package/dist/usage/providers.js +6 -6
- package/dist/usage/providers.js.map +1 -1
- package/dist/usage/quota-history.d.ts +1 -1
- package/dist/view-api.js +1 -1
- package/dist/view-api.js.map +1 -1
- package/dist/web-api.d.ts +9 -0
- package/dist/web-api.js +434 -188
- package/dist/web-api.js.map +1 -1
- package/dist/web-backend-login.d.ts +5 -1
- package/dist/web-backend-login.js +8 -2
- package/dist/web-backend-login.js.map +1 -1
- package/dist/web-chat-archive.d.ts +147 -0
- package/dist/web-chat-archive.js +530 -0
- package/dist/web-chat-archive.js.map +1 -0
- package/dist/web-chat-history.d.ts +76 -0
- package/dist/web-chat-history.js +145 -1
- package/dist/web-chat-history.js.map +1 -1
- package/dist/web-commands.d.ts +4 -3
- package/dist/web-commands.js +3 -2
- package/dist/web-commands.js.map +1 -1
- package/dist/web-guest-access.d.ts +3 -0
- package/dist/web-guest-access.js +6 -2
- package/dist/web-guest-access.js.map +1 -1
- package/dist/web-icons.js +3 -3
- package/dist/web-icons.js.map +1 -1
- package/dist/web-login.d.ts +7 -0
- package/dist/web-login.js +8 -1
- package/dist/web-login.js.map +1 -1
- package/dist/web-mentions.d.ts +2 -0
- package/dist/web-mentions.js +20 -0
- package/dist/web-mentions.js.map +1 -1
- package/dist/web-notices.d.ts +3 -0
- package/dist/web-notices.js +17 -2
- package/dist/web-notices.js.map +1 -1
- package/dist/web-office-store.d.ts +2 -0
- package/dist/web-office-store.js +15 -3
- package/dist/web-office-store.js.map +1 -1
- package/dist/web-pin-store.d.ts +58 -0
- package/dist/web-pin-store.js +170 -0
- package/dist/web-pin-store.js.map +1 -0
- package/dist/web-prefs.js +5 -1
- package/dist/web-prefs.js.map +1 -1
- package/dist/web-session-authorization.d.ts +24 -0
- package/dist/web-session-authorization.js +32 -0
- package/dist/web-session-authorization.js.map +1 -1
- package/dist/web-session.d.ts +6 -4
- package/dist/web-session.js +5 -3
- package/dist/web-session.js.map +1 -1
- package/dist/web-settings-patch.d.ts +24 -3
- package/dist/web-settings-patch.js +57 -1
- package/dist/web-settings-patch.js.map +1 -1
- package/dist/web-shell-routes.d.ts +1 -1
- package/dist/web-shell-routes.js +1 -1
- package/dist/web-shell-routes.js.map +1 -1
- package/dist/web-theme.js +2 -2
- package/dist/web-update.d.ts +15 -1
- package/dist/web-upload.d.ts +36 -0
- package/dist/web-upload.js +105 -5
- package/dist/web-upload.js.map +1 -1
- package/dist/windows-cli-api.d.ts +10 -7
- package/dist/windows-cli-api.js +13 -12
- package/dist/windows-cli-api.js.map +1 -1
- package/dist/windows-cli-worker.d.ts +10 -0
- package/dist/windows-cli-worker.js +109 -14
- package/dist/windows-cli-worker.js.map +1 -1
- package/dist/windows-cli.d.ts +10 -1
- package/dist/windows-cli.js +47 -13
- package/dist/windows-cli.js.map +1 -1
- package/package.json +1 -1
- package/templates/runtime-install/install.ps1 +24 -4
|
@@ -1,19 +1,79 @@
|
|
|
1
|
+
import { countChainStop } from "../admin-dashboard.js";
|
|
1
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import { HubCatalogService, exposureOf, readExposure } from "../catalog.js";
|
|
5
|
+
import { RoomPostReplies } from "./post-replies.js";
|
|
6
|
+
import { HubGrantSearch } from "../grant-search.js";
|
|
4
7
|
import { HubRoomAssistant } from "./assistant.js";
|
|
5
8
|
import { canCreateRoom } from "./admin.js";
|
|
6
9
|
import { HubRoomAgents } from "./agents.js";
|
|
7
10
|
import { personKeyString } from "../identity.js";
|
|
8
11
|
import { personFromString } from "../http/core.js";
|
|
9
12
|
import { uuid, plain, validated, HubProtocolError } from "../validation.js";
|
|
13
|
+
import { HUB_ROOM_POST_CAPABILITY, roomListSchema, roomPostSchema, roomMembersSchema, peopleSearchSchema } from "../protocol.js";
|
|
14
|
+
import { RoomAutomation } from "./automation.js";
|
|
15
|
+
import { resolveRoomMentions } from "./mentions.js";
|
|
16
|
+
import { RoomButtons } from "./buttons.js";
|
|
17
|
+
import { HUB_ROOM_REACT_CAPABILITY, roomReactSchema } from "../protocol.js";
|
|
18
|
+
import { replyButtonClickText } from "../../reply-buttons.js";
|
|
19
|
+
import { pollResultsText } from "../../reply-polls.js";
|
|
10
20
|
import { RoomDirectoryCandidates, rememberRoomPeople } from "./directory.js";
|
|
21
|
+
import { isInlineImage } from "../attachments/limits.js";
|
|
22
|
+
import { HUB_ROOM_MENTION_FEEDBACK_CAPABILITY } from "../room-mention-feedback-model.js";
|
|
23
|
+
import { personalMentionRefusals, recordPersonalMentionRefusals } from "../personal/refusals.js";
|
|
11
24
|
const label = plain(120).transform(s => s.trim()).refine(s => s.length > 0 && !/[\u0000-\u001f\u007f]/.test(s));
|
|
12
25
|
const personId = z.string().max(128).refine(s => /^[a-z][a-z0-9_-]{0,63}\/[a-f0-9-]{36}$/.test(s));
|
|
13
26
|
const createSchema = z.strictObject({ name: label, people: z.array(personId).max(100).default([]), teams: z.array(uuid).max(100).default([]),
|
|
14
27
|
groups: z.array(uuid).max(100).default([]), agents: z.array(uuid).max(64).default([]), assistant: z.boolean().default(false) });
|
|
15
|
-
|
|
16
|
-
|
|
28
|
+
// M-3125: a post carries up to 10 of the poster's own pending uploads in this room; with files the text may be empty.
|
|
29
|
+
const postSchema = z.strictObject({ text: plain(64 * 1024), mentions: z.array(z.string().max(128)).max(100).default([]),
|
|
30
|
+
replyTo: uuid.optional(), files: z.array(uuid).max(10).optional(), idempotencyKey: uuid })
|
|
31
|
+
.refine(b => b.text.trim().length > 0 || (b.files?.length ?? 0) > 0);
|
|
32
|
+
const groupFileView = (roomId, r) => ({ id: r.id, name: r.name, size: r.size, mime: r.mime, url: `/hub/v1/rooms/${roomId}/files/${r.id}` });
|
|
33
|
+
const clickSchema = z.strictObject({ setId: z.string().regex(/^[a-f0-9]{32}$/), index: z.number().int().min(0).max(9).optional(),
|
|
34
|
+
options: z.array(z.number().int().min(0).max(9)).max(10).optional(), idempotencyKey: uuid });
|
|
35
|
+
/** M-3127: one press per set — its click post's idempotency key, a UUID shape derived from the set id. */
|
|
36
|
+
const setKey = (setId) => { const h = createHash("sha256").update(`room-button:${setId}`).digest("hex"); return `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-8${h.slice(17, 20)}-${h.slice(20, 32)}`; };
|
|
37
|
+
/** M-3127 C: how many posts one search reads at most, and the most hits it returns. */
|
|
38
|
+
export const ROOM_SEARCH_SCAN = 2000, ROOM_SEARCH_LIMIT = 50, ROOM_SEARCH_PER_MINUTE = 30;
|
|
39
|
+
const fold = (s) => s.normalize("NFKC").toLowerCase();
|
|
40
|
+
/**
|
|
41
|
+
* M-3127 C: a hit's words — up to `width` characters around its first term, on whole characters, with every term's places
|
|
42
|
+
* in that snippet (`marks`: [start, end) ranges, merged). The page marks them; it never parses HTML.
|
|
43
|
+
*/
|
|
44
|
+
export function searchSnippet(text, terms, width = 120) {
|
|
45
|
+
const chars = [...text], lower = fold(text);
|
|
46
|
+
const first = Math.min(...terms.map(t => lower.indexOf(t)).filter(i => i >= 0), Number.MAX_SAFE_INTEGER);
|
|
47
|
+
// A code-unit index → a character index (an emoji is two units): count the characters before it.
|
|
48
|
+
const at = first === Number.MAX_SAFE_INTEGER ? 0 : [...text.slice(0, first)].length;
|
|
49
|
+
const start = Math.max(0, Math.min(at - Math.floor(width / 3), chars.length - width)), end = Math.min(chars.length, start + width);
|
|
50
|
+
const snippet = `${start > 0 ? "…" : ""}${chars.slice(start, end).join("").replace(/\s+/g, " ")}${end < chars.length ? "…" : ""}`;
|
|
51
|
+
const low = snippet.toLowerCase(), ranges = [];
|
|
52
|
+
for (const t of terms)
|
|
53
|
+
for (let i = low.indexOf(t); i !== -1 && ranges.length < 64; i = low.indexOf(t, i + Math.max(1, t.length)))
|
|
54
|
+
ranges.push([i, i + t.length]);
|
|
55
|
+
ranges.sort((a, b) => a[0] - b[0]);
|
|
56
|
+
const marks = [];
|
|
57
|
+
for (const r of ranges) {
|
|
58
|
+
const last = marks[marks.length - 1];
|
|
59
|
+
if (last && r[0] <= last[1])
|
|
60
|
+
last[1] = Math.max(last[1], r[1]);
|
|
61
|
+
else
|
|
62
|
+
marks.push([...r]);
|
|
63
|
+
}
|
|
64
|
+
return { snippet, marks };
|
|
65
|
+
}
|
|
66
|
+
const reactSchema = z.strictObject({ emoji: z.string().min(1).max(16), on: z.boolean() });
|
|
67
|
+
/** M-3127: the most distinct emoji one post carries. */
|
|
68
|
+
export const ROOM_REACTION_LIMIT = 12;
|
|
69
|
+
/** One emoji as a person picks it: one grapheme, a pictograph (ZWJ sequences, FE0F and skin tones kept), no controls. */
|
|
70
|
+
export function validRoomEmoji(s) {
|
|
71
|
+
if (typeof s !== "string" || s.length < 1 || s.length > 16 || /[\u0000-\u001f\u007f\s]/u.test(s))
|
|
72
|
+
return false;
|
|
73
|
+
if (!/\p{Extended_Pictographic}|\p{Regional_Indicator}/u.test(s))
|
|
74
|
+
return false;
|
|
75
|
+
return [...new Intl.Segmenter("en", { granularity: "grapheme" }).segment(s)].length === 1;
|
|
76
|
+
}
|
|
17
77
|
const patchSchema = z.strictObject({ name: label.optional(), allMention: z.boolean().optional(), historyForNew: z.enum(["since-join", "all"]).optional(), archived: z.boolean().optional(), assistant: z.boolean().optional() });
|
|
18
78
|
export class HubRoomRefusal extends Error {
|
|
19
79
|
status;
|
|
@@ -29,15 +89,39 @@ export class HubRoomRefusal extends Error {
|
|
|
29
89
|
/** People chat first; direct agent conversations remain in HubRoomsService. No timers or I/O on import. */
|
|
30
90
|
export class HubGroupRooms {
|
|
31
91
|
core;
|
|
92
|
+
appPosts;
|
|
32
93
|
listeners = new Set();
|
|
33
94
|
agents;
|
|
34
95
|
assistant;
|
|
96
|
+
postReplies;
|
|
35
97
|
directory;
|
|
98
|
+
automation;
|
|
99
|
+
/** M-3127 B: answers' buttons and polls; one timer for the next deadline (cleared by close()). */
|
|
100
|
+
buttons;
|
|
101
|
+
buttonsTimer = null;
|
|
102
|
+
buttonsClosed = false;
|
|
103
|
+
/** M-3127 C (Fable P3b): each person's recent searches (their times), for ROOM_SEARCH_PER_MINUTE. */
|
|
104
|
+
searches = new Map();
|
|
105
|
+
agentSearch;
|
|
106
|
+
agentReadBuckets = new Map();
|
|
36
107
|
constructor(core) {
|
|
37
108
|
this.core = core;
|
|
38
|
-
this.
|
|
109
|
+
this.appPosts = core.atomic(db => !!db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='hub_mcp_room_posts'").get());
|
|
110
|
+
this.postReplies = new RoomPostReplies(core);
|
|
111
|
+
this.automation = new RoomAutomation(() => core.now());
|
|
112
|
+
this.agentSearch = new HubGrantSearch(core);
|
|
113
|
+
this.agents = new HubRoomAgents(core, event => this.emit(event), post => this.projection(post), this.automation, (db, tx, post) => { this.agentMentions(db, tx, post); this.postReplies.enqueue(db, tx, post); }, id => { this.agentEffects(id); this.postReplies.wake(); });
|
|
39
114
|
this.assistant = new HubRoomAssistant(core, event => this.emit(event), post => this.projection(post));
|
|
40
115
|
this.directory = new RoomDirectoryCandidates(core);
|
|
116
|
+
this.buttons = new RoomButtons(core.deps.content, () => core.now());
|
|
117
|
+
this.agents.onAnswerButtons = (db, tx, d, b) => {
|
|
118
|
+
const ref = this.buttons.record(db, tx, d, b);
|
|
119
|
+
if (!ref)
|
|
120
|
+
return; // that set id is taken: no buttons on this answer, nothing opened
|
|
121
|
+
this.core.audit(tx, { requestId: d.id, actor: { kind: "local-host" }, action: b.poll ? "room.poll-opened" : "room.buttons-opened", result: "completed", roomId: d.room_id, messageId: d.reply_id, contentRef: ref });
|
|
122
|
+
queueMicrotask(() => this.armButtons());
|
|
123
|
+
};
|
|
124
|
+
this.armButtons();
|
|
41
125
|
}
|
|
42
126
|
has(id) { return this.core.atomic(db => !!db.prepare("SELECT 1 FROM hub_group_rooms WHERE id=?").get(id)); }
|
|
43
127
|
subscribe(listener) { this.listeners.add(listener); return () => this.listeners.delete(listener); }
|
|
@@ -47,7 +131,8 @@ export class HubGroupRooms {
|
|
|
47
131
|
return event.removedPerson === person;
|
|
48
132
|
return this.core.atomic(db => !!db.prepare("SELECT 1 FROM hub_room_members WHERE room_id=? AND kind='person' AND subject=?").get(event.roomId, person));
|
|
49
133
|
}
|
|
50
|
-
async close() { this.
|
|
134
|
+
async close() { this.buttonsClosed = true; if (this.buttonsTimer)
|
|
135
|
+
clearTimeout(this.buttonsTimer); this.buttonsTimer = null; this.listeners.clear(); this.directory.close(); this.agentSearch.close(); this.agentReadBuckets.clear(); this.assistant.close(); await this.agents.close(); await this.postReplies.close(); }
|
|
51
136
|
/** The direct-chat receiver shares this stream without changing its grant-backed delivery path. */
|
|
52
137
|
publish(event) { this.emit(event); }
|
|
53
138
|
/** C owns invitation checks; these synchronous effects remain on its current SQL transaction. */
|
|
@@ -129,20 +214,300 @@ export class HubGroupRooms {
|
|
|
129
214
|
}
|
|
130
215
|
maximum(db, id) { return db.prepare("SELECT COALESCE(MAX(sequence),0) AS n FROM hub_room_posts WHERE room_id=?").get(id).n; }
|
|
131
216
|
projection(row) {
|
|
132
|
-
const system = row.author_kind === "system" && ["room-created", "member-joined", "admin-joined"].includes(row.author_id)
|
|
217
|
+
const system = row.author_kind === "system" && ["room-created", "member-joined", "admin-joined", "poll-closed", "app-rate-limited"].includes(row.author_id)
|
|
133
218
|
? { kind: row.author_id, name: row.author_name } : undefined;
|
|
134
219
|
// Agent rows retain their owner-at-message in author_subject; a later exposure transfer must not relabel history.
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
220
|
+
const agent = row.author_kind === "agent" ? this.core.atomic(db => {
|
|
221
|
+
const e = readExposure(db, row.author_id);
|
|
222
|
+
return { owner: { name: this.name(db, row.author_subject) }, ...(e ? { agentKind: e.source_kind === "personal" ? "personal" : "fleet" } : {}) };
|
|
223
|
+
}) : undefined;
|
|
224
|
+
return { id: row.id, roomId: row.room_id, at: row.created_at, sequence: row.sequence, author: { kind: row.author_kind, id: row.author_id, name: row.author_name, ...agent, ...this.viaAuthor(row) },
|
|
225
|
+
...(system ? { system } : {}), ...this.agentMetadata(row), text: this.core.deps.content.get(row.content_ref)?.question ?? "", mentions: JSON.parse(row.mentions),
|
|
138
226
|
...(row.reply_to ? { replyTo: row.reply_to } : {}), ...(row.idempotency_key ? { idempotencyKey: row.idempotency_key } : {}),
|
|
139
|
-
...(row.stage ? { stage: row.stage } : {}), ...(row.answer_to ? { answerTo: row.answer_to } : {}),
|
|
227
|
+
...(row.stage ? { stage: row.stage } : {}), ...(row.answer_to ? { answerTo: row.answer_to } : {}), ...this.filesOf(row),
|
|
140
228
|
...this.core.atomic(db => {
|
|
141
229
|
const a = this.agents.progress(db, row.id), b = this.assistant.progress(db, row.id);
|
|
142
|
-
const
|
|
143
|
-
|
|
230
|
+
const total = (a?.total ?? 0) + (b?.total ?? 0), failed = (a?.failed ?? 0) + (b?.failed ?? 0), blocked = (a?.blocked ?? 0) + (b?.blocked ?? 0);
|
|
231
|
+
const ask = a || b ? { total, answered: (a?.answered ?? 0) + (b?.answered ?? 0), working: (a?.working ?? 0) + (b?.working ?? 0), later: (a?.later ?? 0) + (b?.later ?? 0),
|
|
232
|
+
...(failed ? { failed } : {}), ...(blocked ? { blocked } : {}),
|
|
233
|
+
...(total === 1 && (failed === 1 || blocked === 1) && (a?.reason || b?.reason) ? { reason: (a?.reason || b?.reason) } : {}) } : undefined;
|
|
234
|
+
// The retained parent records who asked when the answer was queued. Do not infer from this viewer or the
|
|
235
|
+
// delivery's owner: an agent can ask too, and an absent owner's via post uses its agent member as a fallback id.
|
|
236
|
+
const asker = row.answer_to ? db.prepare(`SELECT p.author_id AS id FROM hub_room_posts p
|
|
237
|
+
WHERE p.id=? AND p.room_id=? AND p.author_kind='person' AND NOT EXISTS
|
|
238
|
+
(SELECT 1 FROM hub_room_agent_operations op WHERE op.post_id=p.id AND op.member_id=p.author_id)`)
|
|
239
|
+
.get(row.answer_to, row.room_id) : undefined;
|
|
240
|
+
const reactions = this.reactions(db, row.id), buttons = row.author_kind === "agent" ? this.buttons.view(db, row.id, id => this.memberName(db, id)) : undefined;
|
|
241
|
+
return { ...(ask ? { ask } : {}), ...(asker ? { askedBy: asker.id } : {}), ...(this.assistant.warning(db, row.id) ? { warning: "assistant-unavailable" } : {}), ...(reactions.length ? { reactions } : {}), ...(buttons ? { buttons } : {}) };
|
|
144
242
|
}) };
|
|
145
243
|
}
|
|
244
|
+
/** M-3127: a post's reactions, each emoji in the order it first appeared, its members in the order they reacted. */
|
|
245
|
+
reactions(db, postId) {
|
|
246
|
+
const rows = db.prepare("SELECT emoji,member_id FROM hub_room_reactions WHERE post_id=? ORDER BY created_at,rowid").all(postId);
|
|
247
|
+
const out = new Map();
|
|
248
|
+
for (const r of rows)
|
|
249
|
+
out.set(r.emoji, [...(out.get(r.emoji) ?? []), r.member_id]);
|
|
250
|
+
return [...out].map(([emoji, members]) => ({ emoji, count: members.length, members }));
|
|
251
|
+
}
|
|
252
|
+
filesStore() { return this.core.deps.attachments ?? undefined; }
|
|
253
|
+
store() { const s = this.filesStore(); if (!s)
|
|
254
|
+
throw new HubProtocolError("incompatible"); return s; }
|
|
255
|
+
/** M-3125: a post's files, in order (none when the Hub has no attachment store). */
|
|
256
|
+
filesOf(row) {
|
|
257
|
+
const store = this.filesStore();
|
|
258
|
+
if (!store)
|
|
259
|
+
return {};
|
|
260
|
+
const refs = this.core.atomic(db => [...store.forMessage(db, row.id, "question"), ...store.forMessage(db, row.id, "answer")]);
|
|
261
|
+
return refs.length ? { files: refs.map(r => groupFileView(row.room_id, r)) } : {};
|
|
262
|
+
}
|
|
263
|
+
viaAuthor(row) {
|
|
264
|
+
return this.core.atomic(db => {
|
|
265
|
+
const app = this.appPosts ? db.prepare("SELECT app_id,app_name FROM hub_mcp_room_posts WHERE post_id=?").get(row.id) : undefined;
|
|
266
|
+
if (app)
|
|
267
|
+
return { via: { id: app.app_id, name: app.app_name, kind: "app" } };
|
|
268
|
+
const op = db.prepare("SELECT exposure_id,person_name,via_name FROM hub_room_agent_operations WHERE post_id=? AND receipt_id IS NOT NULL").get(row.id);
|
|
269
|
+
return op ? { name: op.person_name, via: { id: op.exposure_id, name: op.via_name, kind: "agent" } } : {};
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
agentMetadata(row) {
|
|
273
|
+
return this.core.atomic(db => {
|
|
274
|
+
const stop = db.prepare("SELECT source_id,reason,name,retry_at FROM hub_room_agent_stops WHERE post_id=?").get(row.id);
|
|
275
|
+
if (stop)
|
|
276
|
+
return { system: { kind: "agent-mention-stopped", reason: stop.reason, name: stop.name, sourceId: stop.source_id, ...(stop.retry_at !== null ? { retryAt: stop.retry_at } : {}) } };
|
|
277
|
+
return db.prepare("SELECT 1 FROM hub_room_agent_operations WHERE post_id=? AND receipt_id IS NULL").get(row.id) ? { proactive: true } : {};
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
stop(db, tx, source, reason, name = source.author_name, retryAt) {
|
|
281
|
+
const sourceAgent = db.prepare("SELECT exposure_id FROM hub_room_agent_operations WHERE post_id=?").get(source.id)?.exposure_id ?? source.author_id;
|
|
282
|
+
const coalesce = reason === "rate" ? JSON.stringify(["rate", source.room_id, sourceAgent, Math.ceil(retryAt / 60_000)]) : JSON.stringify([source.id, reason, name]);
|
|
283
|
+
if (db.prepare("SELECT 1 FROM hub_room_agent_stops WHERE coalesce_key=?").get(coalesce))
|
|
284
|
+
return;
|
|
285
|
+
const text = reason === "all" ? "Agents can't use @All agents. This message was not sent to other agents."
|
|
286
|
+
: reason === "ambiguous" ? `More than one member is named "${name}", so this mention was not delivered.`
|
|
287
|
+
: reason === "depth" ? "Agents have asked each other several times in a row, so this stops here. They can ask each other again after a person writes in the room."
|
|
288
|
+
: reason === "capacity" ? "The Hub is busy, so this mention was not delivered."
|
|
289
|
+
: `${name} is posting too often, so this mention was not delivered. It can try again after ${new Date(retryAt).toISOString()}.`;
|
|
290
|
+
const row = this.insert(db, tx, source.room_id, { kind: "system", id: "agent-mention-stopped", subject: "system", name }, text);
|
|
291
|
+
if (source.sequence !== undefined) {
|
|
292
|
+
const l = this.automation.lineage(db, source);
|
|
293
|
+
db.prepare("INSERT INTO hub_room_post_lineage VALUES(?,?,?,?,NULL)").run(row.id, l.root_id, l.depth, l.audience_sequence);
|
|
294
|
+
}
|
|
295
|
+
db.prepare("INSERT INTO hub_room_agent_stops VALUES(?,?,?,?,?,?)").run(row.id, source.id, reason, name, retryAt ?? null, coalesce);
|
|
296
|
+
countChainStop(db, reason, this.core.now());
|
|
297
|
+
this.core.audit(tx, { requestId: source.id, actor: { kind: "person", person: personFromString(source.author_subject) }, action: "room.agent-mention-stopped", result: "completed", roomId: source.room_id, messageId: row.id, contentRef: row.content_ref });
|
|
298
|
+
}
|
|
299
|
+
/** Both answers and proactive posts use this transaction, once, before any external delivery. */
|
|
300
|
+
agentMentions(db, tx, post) {
|
|
301
|
+
const operation = db.prepare("SELECT exposure_id,receipt_id FROM hub_room_agent_operations WHERE post_id=?").get(post.id);
|
|
302
|
+
const sourceId = operation?.exposure_id ?? post.author_id, onBehalf = !!operation?.receipt_id;
|
|
303
|
+
const source = db.prepare("SELECT * FROM hub_room_members WHERE room_id=? AND kind='agent' AND subject=? AND owner_at_join=?").get(post.room_id, sourceId, post.author_subject);
|
|
304
|
+
if (!source)
|
|
305
|
+
return;
|
|
306
|
+
const members = db.prepare("SELECT * FROM hub_room_members WHERE room_id=?").all(post.room_id).flatMap(m => {
|
|
307
|
+
if (m.kind === "person") {
|
|
308
|
+
const p = db.prepare("SELECT login_label FROM hub_people WHERE person=? UNION ALL SELECT login_label FROM hub_room_people WHERE person=? LIMIT 1").get(m.subject, m.subject);
|
|
309
|
+
return [{ ...m, name: this.name(db, m.subject), login: p?.login_label }];
|
|
310
|
+
}
|
|
311
|
+
const e = m.kind === "agent" ? readExposure(db, m.subject) : undefined;
|
|
312
|
+
return e && e.owner === m.owner_at_join ? [{ ...m, name: e.display_name }] : [];
|
|
313
|
+
});
|
|
314
|
+
const resolved = resolveRoomMentions(this.core.deps.content.get(post.content_ref)?.question ?? "", members, onBehalf ? "" : sourceId), accepted = [], refusedPersonal = [];
|
|
315
|
+
if (resolved.all && !onBehalf)
|
|
316
|
+
this.stop(db, tx, post, "all");
|
|
317
|
+
const targets = resolved.all && onBehalf ? members.filter(m => m.kind === "agent"
|
|
318
|
+
&& (readExposure(db, m.subject)?.source_kind !== "personal" || resolved.agents.includes(m.subject))).map(m => m.subject) : resolved.all ? [] : resolved.agents;
|
|
319
|
+
for (const name of resolved.ambiguous)
|
|
320
|
+
this.stop(db, tx, post, "ambiguous", name);
|
|
321
|
+
for (const target of [...resolved.people, ...targets]) {
|
|
322
|
+
const agent = targets.includes(target);
|
|
323
|
+
if (agent && readExposure(db, target)?.source_kind === "personal" && !onBehalf) {
|
|
324
|
+
refusedPersonal.push(readExposure(db, target).display_name);
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
const recipient = members.find(m => agent ? m.kind === "agent" && m.subject === target : m.kind === "person" && m.id === target);
|
|
328
|
+
if (recipient && db.prepare("SELECT joined_sequence FROM hub_room_members WHERE id=?").get(recipient.id).joined_sequence > this.automation.lineage(db, post).audience_sequence)
|
|
329
|
+
continue;
|
|
330
|
+
if (agent && db.prepare("SELECT COUNT(*) n FROM hub_room_deliveries WHERE state IN ('queued','sent')").get().n + accepted.filter(id => targets.includes(id)).length >= 4096) {
|
|
331
|
+
this.stop(db, tx, post, "capacity");
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
if (agent && this.automation.depth(db, post) >= 3) {
|
|
335
|
+
this.stop(db, tx, post, "depth");
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
const retryAt = this.automation.admit(db, post.room_id, sourceId);
|
|
339
|
+
if (retryAt !== null) {
|
|
340
|
+
this.stop(db, tx, post, "rate", post.author_name, retryAt);
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
accepted.push(target);
|
|
344
|
+
}
|
|
345
|
+
if (resolved.all && onBehalf)
|
|
346
|
+
accepted.push("all");
|
|
347
|
+
recordPersonalMentionRefusals(this.core, db, tx, post, sourceId, [...new Set(refusedPersonal)]);
|
|
348
|
+
db.prepare("UPDATE hub_room_posts SET mentions=? WHERE id=?").run(JSON.stringify(accepted), post.id);
|
|
349
|
+
this.agents.enqueue(db, tx, { ...post, mentions: JSON.stringify(accepted.filter(id => id !== "all")) }, source.id);
|
|
350
|
+
}
|
|
351
|
+
agentEffects(id) {
|
|
352
|
+
this.agents.publishQueued(id);
|
|
353
|
+
const rows = this.core.atomic(db => db.prepare("SELECT p.* FROM hub_room_agent_stops s JOIN hub_room_posts p ON p.id=s.post_id WHERE s.source_id=? ORDER BY p.sequence").all(id));
|
|
354
|
+
for (const row of rows)
|
|
355
|
+
this.emit({ type: "message.added", roomId: row.room_id, data: { roomId: row.room_id, message: this.projection(row) }, sequence: row.sequence });
|
|
356
|
+
}
|
|
357
|
+
async agentSource(exposureId, link) {
|
|
358
|
+
const current = () => this.core.live() && link.current();
|
|
359
|
+
if (!current())
|
|
360
|
+
throw new HubProtocolError("stale");
|
|
361
|
+
if (!["welcome-caps-v1", "room-ask-v1", HUB_ROOM_POST_CAPABILITY].every(f => link.features.has(f)))
|
|
362
|
+
throw new HubProtocolError("denied");
|
|
363
|
+
const owned = (db) => {
|
|
364
|
+
const e = readExposure(db, exposureId);
|
|
365
|
+
if (!e || e.owner !== personKeyString(link.owner) || e.fleet_id !== link.fleetId || exposureOf(e).state !== "published")
|
|
366
|
+
throw new HubProtocolError("denied");
|
|
367
|
+
return e;
|
|
368
|
+
};
|
|
369
|
+
this.core.atomic(owned);
|
|
370
|
+
const permit = await this.core.groupExposure(exposureId, null, { requestId: exposureId, current });
|
|
371
|
+
if (!await this.core.eligible(link.owner))
|
|
372
|
+
throw new HubProtocolError("denied");
|
|
373
|
+
const fence = { assertCurrent: () => { permit.assertCurrent(); if (!current())
|
|
374
|
+
throw new HubProtocolError("stale"); } };
|
|
375
|
+
const source = this.core.atomic(owned, fence);
|
|
376
|
+
return { source, fence };
|
|
377
|
+
}
|
|
378
|
+
async agentRooms(input, link) {
|
|
379
|
+
const body = validated(roomListSchema, input), { source, fence } = await this.agentSource(body.exposureId, link);
|
|
380
|
+
return this.core.atomic(db => {
|
|
381
|
+
this.agentRead(source.owner);
|
|
382
|
+
const rooms = this.agentRoomChoices(db, source.id, source.owner);
|
|
383
|
+
return { ok: true, exposureId: source.id, rooms: rooms.slice(0, 200), ...(rooms.length > 200 ? { truncated: true } : {}) };
|
|
384
|
+
}, fence);
|
|
385
|
+
}
|
|
386
|
+
agentRead(owner) {
|
|
387
|
+
const at = this.core.now();
|
|
388
|
+
for (const [key, b] of this.agentReadBuckets)
|
|
389
|
+
if (at < b.at || at - b.at >= 60_000)
|
|
390
|
+
this.agentReadBuckets.delete(key);
|
|
391
|
+
const b = this.agentReadBuckets.get(owner);
|
|
392
|
+
if (b ? b.count >= 30 : this.agentReadBuckets.size >= 1024)
|
|
393
|
+
throw new HubProtocolError("backpressure");
|
|
394
|
+
this.agentReadBuckets.set(owner, { at: b?.at ?? at, count: (b?.count ?? 0) + 1 });
|
|
395
|
+
}
|
|
396
|
+
async agentMembers(input, link) {
|
|
397
|
+
const body = validated(roomMembersSchema, input), { source, fence } = await this.agentSource(body.exposureId, link);
|
|
398
|
+
this.agentRead(source.owner);
|
|
399
|
+
return this.core.atomic(db => {
|
|
400
|
+
const rows = db.prepare(`SELECT r.id,r.name FROM hub_room_members m JOIN hub_group_rooms r ON r.id=m.room_id WHERE m.kind='agent' AND m.subject=? AND m.owner_at_join=? AND r.archived=0 AND r.assistant_for IS NULL AND (r.id=? OR r.name=?) ORDER BY r.id LIMIT 201`).all(source.id, source.owner, body.room, body.room);
|
|
401
|
+
const room = rows.find(r => r.id === body.room) ?? (rows.length === 1 ? rows[0] : undefined);
|
|
402
|
+
if (!room)
|
|
403
|
+
return rows.length ? { ok: false, code: "ambiguous-room", rooms: rows.slice(0, 200) } : { ok: false, code: "not-found" };
|
|
404
|
+
const members = db.prepare("SELECT * FROM hub_room_members WHERE room_id=? ORDER BY kind,id LIMIT 201").all(room.id).map(m => {
|
|
405
|
+
if (m.kind === "assistant")
|
|
406
|
+
return { id: "assistant", kind: m.kind, name: "Hub assistant", presence: this.assistant.presence(room.id) };
|
|
407
|
+
if (m.kind === "agent") {
|
|
408
|
+
const e = readExposure(db, m.subject);
|
|
409
|
+
return { id: m.subject, kind: m.kind, name: e?.display_name ?? m.subject, owner: { name: this.name(db, m.owner_at_join ?? "") }, ...this.agents.presence(m.subject) };
|
|
410
|
+
}
|
|
411
|
+
return { id: m.id, kind: m.kind, name: this.name(db, m.subject), presence: db.prepare("SELECT 1 FROM hub_sessions WHERE person=? AND state='active' AND expires_at>?").get(m.subject, this.core.now()) ? "online" : "offline" };
|
|
412
|
+
});
|
|
413
|
+
if (members.length > 200)
|
|
414
|
+
throw new HubProtocolError("backpressure");
|
|
415
|
+
return { ok: true, roomId: room.id, members };
|
|
416
|
+
}, fence);
|
|
417
|
+
}
|
|
418
|
+
async agentPeople(input, link) {
|
|
419
|
+
const body = validated(peopleSearchSchema, input), { source, fence } = await this.agentSource(body.exposureId, link);
|
|
420
|
+
this.agentRead(source.owner);
|
|
421
|
+
const current = async () => { fence.assertCurrent(); if (!await this.core.eligible(link.owner))
|
|
422
|
+
throw new HubProtocolError("denied"); fence.assertCurrent(); return { kind: "directory", person: link.owner, sessionId: `member:${source.owner}` }; };
|
|
423
|
+
const ctx = { requestId: randomUUID(), isCurrent: () => { try {
|
|
424
|
+
fence.assertCurrent();
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
catch {
|
|
428
|
+
return false;
|
|
429
|
+
} },
|
|
430
|
+
current, requirePerson: async () => (await current()).person, requireAdmin: async () => { throw new HubProtocolError("denied"); } };
|
|
431
|
+
const raw = await this.agentSearch.search(ctx, source.id, { exposureRevision: source.revision, kind: "person", q: body.q });
|
|
432
|
+
fence.assertCurrent();
|
|
433
|
+
const found = validated(z.discriminatedUnion("ok", [z.object({ ok: z.literal(true), people: z.array(z.object({ person: z.object({ realm: z.string(), objectId: uuid }), login: z.string(), displayName: z.string() })).max(20), truncated: z.boolean() }), z.object({ ok: z.literal(false), reason: z.string() })]), raw);
|
|
434
|
+
if (!found.ok)
|
|
435
|
+
return { ok: false, code: found.reason === "limited" ? "backpressure" : "unavailable" };
|
|
436
|
+
return { ok: true, people: found.people.map(p => ({ id: personKeyString(p.person), name: p.displayName, login: p.login })), truncated: found.truncated };
|
|
437
|
+
}
|
|
438
|
+
agentRoomChoices(db, exposure, owner) {
|
|
439
|
+
return db.prepare(`SELECT r.id,r.name FROM hub_room_members m JOIN hub_group_rooms r ON r.id=m.room_id
|
|
440
|
+
WHERE m.kind='agent' AND m.subject=? AND m.owner_at_join=? AND r.archived=0 AND r.assistant_for IS NULL ORDER BY r.name,r.id LIMIT 201`).all(exposure, owner);
|
|
441
|
+
}
|
|
442
|
+
async agentPost(input, link) {
|
|
443
|
+
const body = validated(roomPostSchema, input), { source, fence } = await this.agentSource(body.exposureId, link);
|
|
444
|
+
if (body.mentionFeedback && !link.features.has(HUB_ROOM_MENTION_FEEDBACK_CAPABILITY))
|
|
445
|
+
throw new HubProtocolError("incompatible");
|
|
446
|
+
const { mentionFeedback: _feedback, ...operation } = body;
|
|
447
|
+
const digest = createHash("sha256").update(JSON.stringify(operation)).digest("hex");
|
|
448
|
+
let added = false;
|
|
449
|
+
let refusedEffects;
|
|
450
|
+
const result = this.core.atomic((db, tx) => {
|
|
451
|
+
const old = db.prepare("SELECT * FROM hub_room_agent_operations WHERE exposure_id=? AND idempotency_key=?").get(source.id, body.idempotencyKey);
|
|
452
|
+
if (old) {
|
|
453
|
+
if (old.digest !== digest)
|
|
454
|
+
return { ok: false, code: "conflict" };
|
|
455
|
+
const member = db.prepare("SELECT * FROM hub_room_members WHERE room_id=? AND kind='agent' AND subject=? AND owner_at_join=?").get(old.room_id, source.id, source.owner);
|
|
456
|
+
const row = db.prepare("SELECT * FROM hub_room_posts WHERE id=?").get(old.post_id);
|
|
457
|
+
if (!member || member.id !== old.member_id || row.sequence < member.joined_sequence || old.owner !== source.owner || old.fleet_id !== source.fleet_id || this.room(db, old.room_id).archived)
|
|
458
|
+
return { ok: false, code: "denied" };
|
|
459
|
+
return { ok: true, roomId: old.room_id, messageId: old.post_id, at: old.at };
|
|
460
|
+
}
|
|
461
|
+
const matches = (byId) => db.prepare(`SELECT r.id,r.name FROM hub_room_members m JOIN hub_group_rooms r ON r.id=m.room_id
|
|
462
|
+
WHERE m.kind='agent' AND m.subject=? AND m.owner_at_join=? AND r.archived=0 AND r.assistant_for IS NULL AND ${byId ? "r.id" : "r.name"}=? ORDER BY r.id LIMIT 201`)
|
|
463
|
+
.all(source.id, source.owner, body.room);
|
|
464
|
+
const exact = matches(true)[0], named = exact ? [] : matches(false), room = exact ?? (named.length === 1 ? named[0] : undefined);
|
|
465
|
+
if (!room)
|
|
466
|
+
return named.length > 1 ? { ok: false, code: "ambiguous-room", rooms: named.slice(0, 200) } : { ok: false, code: "not-found" };
|
|
467
|
+
const membership = db.prepare("SELECT * FROM hub_room_members WHERE room_id=? AND kind='agent' AND subject=?").get(room.id, source.id);
|
|
468
|
+
if (body.onBehalfOf) {
|
|
469
|
+
const all = resolveRoomMentions(body.text, [], "").all;
|
|
470
|
+
if (all && !this.room(db, room.id).all_mention && !db.prepare("SELECT 1 FROM hub_room_members WHERE room_id=? AND kind='person' AND subject=? AND role='manager'").get(room.id, source.owner))
|
|
471
|
+
return { ok: false, code: "denied" };
|
|
472
|
+
}
|
|
473
|
+
const retryAt = this.automation.admit(db, room.id, source.id);
|
|
474
|
+
if (retryAt !== null) {
|
|
475
|
+
const prior = db.prepare("SELECT * FROM hub_room_posts WHERE room_id=? AND author_kind='agent' AND author_id=? AND stage IS NULL ORDER BY sequence DESC LIMIT 1").get(room.id, source.id);
|
|
476
|
+
const notice = prior ?? { id: `rate:${source.id}:${room.id}:${retryAt}`, room_id: room.id, author_id: source.id, author_name: source.display_name, author_subject: source.owner };
|
|
477
|
+
this.stop(db, tx, notice, "rate", source.display_name, retryAt);
|
|
478
|
+
refusedEffects = notice.id;
|
|
479
|
+
return { ok: false, code: "rate-limited", retryAt };
|
|
480
|
+
}
|
|
481
|
+
const humanName = body.onBehalfOf ? this.name(db, source.owner) : null;
|
|
482
|
+
const ownerMember = body.onBehalfOf ? db.prepare("SELECT id FROM hub_room_members WHERE room_id=? AND kind='person' AND subject=?").get(room.id, source.owner) : undefined;
|
|
483
|
+
const post = this.insert(db, tx, room.id, { kind: body.onBehalfOf ? "person" : "agent", id: body.onBehalfOf ? ownerMember?.id ?? membership.id : source.id,
|
|
484
|
+
subject: source.owner, name: body.onBehalfOf ? `${humanName} via ${source.display_name}` : source.display_name }, body.text);
|
|
485
|
+
db.prepare("INSERT INTO hub_room_agent_operations VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)").run(source.id, body.idempotencyKey, digest, body.room, room.id, post.id, source.owner, source.fleet_id, post.created_at, membership.id, body.onBehalfOf?.receiptId ?? null, humanName, body.onBehalfOf ? source.display_name : null);
|
|
486
|
+
if (body.onBehalfOf)
|
|
487
|
+
this.automation.onBehalf(db, post, source.owner, body.onBehalfOf.receiptId, source.id);
|
|
488
|
+
else
|
|
489
|
+
this.automation.proactive(db, post);
|
|
490
|
+
this.core.audit(tx, { requestId: post.id, actor: { kind: "person", person: link.owner }, action: "room.agent-post", result: "completed", roomId: room.id, messageId: post.id, exposureId: source.id, fleetId: link.fleetId, contentRef: post.content_ref });
|
|
491
|
+
this.agentMentions(db, tx, post);
|
|
492
|
+
added = true;
|
|
493
|
+
return { ok: true, roomId: room.id, messageId: post.id, at: post.created_at };
|
|
494
|
+
}, fence);
|
|
495
|
+
if (added && result.ok) {
|
|
496
|
+
const row = this.core.atomic(db => db.prepare("SELECT * FROM hub_room_posts WHERE id=?").get(result.messageId));
|
|
497
|
+
this.emit({ type: "message.added", roomId: row.room_id, data: { roomId: row.room_id, message: this.projection(row) }, sequence: row.sequence });
|
|
498
|
+
this.emit({ type: "unread.changed", roomId: row.room_id, data: { roomId: row.room_id } });
|
|
499
|
+
this.agentEffects(row.id);
|
|
500
|
+
this.agents.wake();
|
|
501
|
+
}
|
|
502
|
+
if (refusedEffects)
|
|
503
|
+
this.agentEffects(refusedEffects);
|
|
504
|
+
if (result.ok && body.mentionFeedback && link.features.has(HUB_ROOM_MENTION_FEEDBACK_CAPABILITY)) {
|
|
505
|
+
const mentionRefusals = personalMentionRefusals(this.core, result.messageId, body.exposureId);
|
|
506
|
+
if (mentionRefusals)
|
|
507
|
+
return { ...result, mentionRefusals };
|
|
508
|
+
}
|
|
509
|
+
return result;
|
|
510
|
+
}
|
|
146
511
|
insert(db, tx, roomId, author, text, mentions = [], key = null, digest = "", replyTo = null) {
|
|
147
512
|
const row = { id: randomUUID(), room_id: roomId, sequence: this.maximum(db, roomId) + 1, author_kind: author.kind, author_id: author.id,
|
|
148
513
|
author_subject: author.subject, author_name: author.name, content_ref: this.core.deps.content.put(tx, { question: text }), digest, mentions: JSON.stringify(mentions),
|
|
@@ -154,11 +519,11 @@ export class HubGroupRooms {
|
|
|
154
519
|
summary(db, room, member) {
|
|
155
520
|
const counts = db.prepare("SELECT kind,COUNT(*) AS n FROM hub_room_members WHERE room_id=? GROUP BY kind").all(room.id);
|
|
156
521
|
const floor = member.joined_sequence;
|
|
157
|
-
const last = db.prepare("SELECT * FROM hub_room_posts WHERE room_id=? AND sequence>=? AND (stage IS NULL OR stage='answered') AND (answer_to IS NULL OR EXISTS(SELECT 1 FROM hub_room_posts original WHERE original.id=hub_room_posts.answer_to AND original.sequence>=?)) ORDER BY sequence DESC LIMIT 1").get(room.id, floor, floor);
|
|
158
|
-
const unread = db.prepare("SELECT COUNT(*) AS n FROM hub_room_posts WHERE room_id=? AND sequence>=? AND sequence>? AND (author_kind<>'person' OR author_subject<>?) AND author_kind<>'system' AND (stage IS NULL OR stage='answered') AND (answer_to IS NULL OR EXISTS(SELECT 1 FROM hub_room_posts original WHERE original.id=hub_room_posts.answer_to AND original.sequence>=?))")
|
|
159
|
-
.get(room.id, floor, member.read_sequence, member.subject, floor).n;
|
|
160
|
-
const mentioned = !!db.prepare(`SELECT 1 FROM hub_room_posts p,json_each(p.mentions) j WHERE p.room_id=? AND p.sequence>=? AND p.sequence>?
|
|
161
|
-
AND p.author_subject<>? AND j.value IN (?,?) LIMIT 1`).get(room.id, floor, member.read_sequence, member.subject, member.id, member.subject);
|
|
522
|
+
const last = db.prepare("SELECT * FROM hub_room_posts WHERE room_id=? AND sequence>=? AND COALESCE((SELECT audience_sequence FROM hub_room_post_lineage l WHERE l.post_id=hub_room_posts.id),sequence)>=? AND (stage IS NULL OR stage='answered') AND (answer_to IS NULL OR EXISTS(SELECT 1 FROM hub_room_posts original WHERE original.id=hub_room_posts.answer_to AND original.sequence>=?)) ORDER BY sequence DESC LIMIT 1").get(room.id, floor, floor, floor);
|
|
523
|
+
const unread = db.prepare("SELECT COUNT(*) AS n FROM hub_room_posts WHERE room_id=? AND sequence>=? AND COALESCE((SELECT audience_sequence FROM hub_room_post_lineage l WHERE l.post_id=hub_room_posts.id),sequence)>=? AND sequence>? AND (author_kind<>'person' OR author_subject<>?) AND author_kind<>'system' AND (stage IS NULL OR stage='answered') AND (answer_to IS NULL OR EXISTS(SELECT 1 FROM hub_room_posts original WHERE original.id=hub_room_posts.answer_to AND original.sequence>=?))")
|
|
524
|
+
.get(room.id, floor, floor, member.read_sequence, member.subject, floor).n;
|
|
525
|
+
const mentioned = !!db.prepare(`SELECT 1 FROM hub_room_posts p,json_each(p.mentions) j WHERE p.room_id=? AND p.sequence>=? AND COALESCE((SELECT audience_sequence FROM hub_room_post_lineage l WHERE l.post_id=p.id),p.sequence)>=? AND p.sequence>?
|
|
526
|
+
AND (p.author_kind<>'person' OR p.author_subject<>?) AND j.value IN (?,?) LIMIT 1`).get(room.id, floor, floor, member.read_sequence, member.subject, member.id, member.subject);
|
|
162
527
|
const online = db.prepare(`SELECT COUNT(*) AS n FROM hub_room_members m WHERE m.room_id=? AND m.kind='person' AND EXISTS
|
|
163
528
|
(SELECT 1 FROM hub_sessions s WHERE s.person=m.subject AND s.state='active' AND s.expires_at>?)`).get(room.id, this.core.now()).n;
|
|
164
529
|
const projected = last ? this.projection(last) : undefined;
|
|
@@ -186,7 +551,8 @@ export class HubGroupRooms {
|
|
|
186
551
|
const me = await this.who(ctx);
|
|
187
552
|
this.agents.sweep();
|
|
188
553
|
return this.core.atomic(db => {
|
|
189
|
-
|
|
554
|
+
if (!ctx.application)
|
|
555
|
+
this.assistantRoom(db, me);
|
|
190
556
|
return { rooms: db.prepare("SELECT * FROM hub_room_members WHERE kind='person' AND subject=?").all(me)
|
|
191
557
|
.map(m => this.summary(db, this.room(db, m.room_id), m)).sort((a, b) => b.lastAt - a.lastAt),
|
|
192
558
|
me: { canCreateRooms: canCreateRoom(this.core, db, me), assistant: this.assistant.availability()?.enabled === true }, invitations: 0 };
|
|
@@ -336,14 +702,18 @@ export class HubGroupRooms {
|
|
|
336
702
|
if (m.kind === "agent") {
|
|
337
703
|
const e = readExposure(db, m.subject);
|
|
338
704
|
return { id: m.subject, kind: m.kind, name: e?.display_name ?? m.subject, role: m.role,
|
|
339
|
-
|
|
705
|
+
...(e ? { agentKind: e.source_kind === "personal" ? "personal" : "fleet" } : {}),
|
|
706
|
+
...(e?.answer_only === 1 ? { answerOnly: true } : {}), owner: { name: this.name(db, m.owner_at_join ?? "") }, ...this.agents.presence(m.subject), canAsk: canAsk.has(m.subject) };
|
|
340
707
|
}
|
|
341
708
|
return { id: m.id, kind: m.kind, name: this.name(db, m.subject), role: m.role,
|
|
342
709
|
signedIn: !!db.prepare("SELECT 1 FROM hub_people WHERE person=?").get(m.subject),
|
|
343
710
|
presence: db.prepare("SELECT 1 FROM hub_sessions WHERE person=? AND state='active' AND expires_at>?").get(m.subject, this.core.now()) ? "online" : "offline" };
|
|
344
711
|
});
|
|
345
|
-
|
|
346
|
-
|
|
712
|
+
// M-3125: the room takes people's files when this Hub stores files (the 1:1 chat's own attachments-v1 mark).
|
|
713
|
+
return { room: { ...this.summary(db, room, own), ...(this.filesStore() ? { features: ["attachments-v1"] } : {}) }, me: { id: own.id, role: own.role }, members,
|
|
714
|
+
settings: { allMention: room.all_mention === 1, historyForNew: room.history_for_new,
|
|
715
|
+
...(this.appPosts ? { aiApps: db.prepare("SELECT enabled FROM hub_mcp_room_policy WHERE room_id=?").get(id)?.enabled !== 0 } : {}),
|
|
716
|
+
...(members.some(m => m.kind === "assistant") ? { assistant: true } : {}) }, invited: [] };
|
|
347
717
|
}, { assertCurrent: () => { this.fence(ctx).assertCurrent(); for (const proof of directProofs)
|
|
348
718
|
proof.assertCurrent(); } });
|
|
349
719
|
}
|
|
@@ -495,6 +865,7 @@ export class HubGroupRooms {
|
|
|
495
865
|
throw new HubProtocolError("invalid");
|
|
496
866
|
const me = await this.who(ctx);
|
|
497
867
|
this.agents.sweep(id);
|
|
868
|
+
this.settleButtons();
|
|
498
869
|
return this.core.atomic(db => {
|
|
499
870
|
const member = this.member(db, id, me);
|
|
500
871
|
let until = Number.MAX_SAFE_INTEGER;
|
|
@@ -504,18 +875,23 @@ export class HubGroupRooms {
|
|
|
504
875
|
throw new HubRoomRefusal(404, "not-found");
|
|
505
876
|
until = row.sequence;
|
|
506
877
|
}
|
|
507
|
-
const rows = db.prepare("SELECT * FROM hub_room_posts WHERE room_id=? AND sequence>=? AND sequence<? AND (answer_to IS NULL OR EXISTS(SELECT 1 FROM hub_room_posts original WHERE original.id=hub_room_posts.answer_to AND original.sequence>=?)) ORDER BY sequence DESC LIMIT ?").all(id, member.joined_sequence, until, member.joined_sequence, limit + 1);
|
|
878
|
+
const rows = db.prepare("SELECT * FROM hub_room_posts WHERE room_id=? AND sequence>=? AND COALESCE((SELECT audience_sequence FROM hub_room_post_lineage l WHERE l.post_id=hub_room_posts.id),sequence)>=? AND sequence<? AND (answer_to IS NULL OR EXISTS(SELECT 1 FROM hub_room_posts original WHERE original.id=hub_room_posts.answer_to AND original.sequence>=?)) ORDER BY sequence DESC LIMIT ?").all(id, member.joined_sequence, member.joined_sequence, until, member.joined_sequence, limit + 1);
|
|
508
879
|
return { messages: rows.slice(0, limit).reverse().map(row => this.projection(row)), more: rows.length > limit };
|
|
509
880
|
}, this.fence(ctx));
|
|
510
881
|
}
|
|
511
882
|
async post(ctx, id, input) {
|
|
512
883
|
const body = validated(postSchema, input), me = await this.who(ctx);
|
|
513
|
-
const
|
|
884
|
+
const files = body.files ?? [];
|
|
885
|
+
const digest = createHash("sha256").update(JSON.stringify(files.length ? { text: body.text, mentions: body.mentions, replyTo: body.replyTo ?? null, files }
|
|
886
|
+
: { text: body.text, mentions: body.mentions, replyTo: body.replyTo ?? null })).digest("hex");
|
|
514
887
|
let added = false;
|
|
515
888
|
const row = this.core.atomic((db, tx) => {
|
|
516
889
|
const member = this.member(db, id, me), room = this.room(db, id);
|
|
517
890
|
if (room.archived)
|
|
518
891
|
throw new HubRoomRefusal(409, "archived");
|
|
892
|
+
if (ctx.application && (db.prepare("SELECT enabled FROM hub_mcp_room_policy WHERE room_id=?").get(id)?.enabled === 0
|
|
893
|
+
|| room.assistant_for || body.mentions.includes("all") || body.mentions.includes("assistant") || /@all\b/iu.test(body.text)))
|
|
894
|
+
throw new HubRoomRefusal(403, "denied");
|
|
519
895
|
if (body.mentions.includes("all") && !room.all_mention && member.role !== "manager")
|
|
520
896
|
throw new HubRoomRefusal(403, "all-mention-off");
|
|
521
897
|
const old = db.prepare("SELECT * FROM hub_room_posts WHERE room_id=? AND author_subject=? AND idempotency_key=?").get(id, me, body.idempotencyKey);
|
|
@@ -526,10 +902,22 @@ export class HubGroupRooms {
|
|
|
526
902
|
}
|
|
527
903
|
if (body.replyTo && !db.prepare("SELECT 1 FROM hub_room_posts WHERE id=? AND room_id=? AND sequence>=?").get(body.replyTo, id, member.joined_sequence))
|
|
528
904
|
throw new HubRoomRefusal(404, "not-found");
|
|
905
|
+
const refs = files.length ? this.store().pending(db, id, me, files) : [];
|
|
529
906
|
const post = this.insert(db, tx, id, { kind: "person", id: member.id, subject: me, name: this.name(db, me) }, body.text, body.mentions, body.idempotencyKey, digest, body.replyTo ?? null);
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
907
|
+
if (ctx.application)
|
|
908
|
+
db.prepare("INSERT INTO hub_mcp_room_posts VALUES(?,?,?)").run(post.id, ctx.application.id, ctx.application.name);
|
|
909
|
+
if (refs.length)
|
|
910
|
+
this.store().bindPost(db, refs, post.id);
|
|
911
|
+
if (ctx.application) {
|
|
912
|
+
if (!this.core.deps.content.bindMessage)
|
|
913
|
+
throw new HubProtocolError("unavailable");
|
|
914
|
+
this.core.deps.content.bindMessage(tx, post.content_ref, post.id);
|
|
915
|
+
}
|
|
916
|
+
this.core.audit(tx, { requestId: ctx.requestId, actor: { kind: "person", person: personFromString(me) }, action: "room.message", result: "completed", roomId: id, messageId: post.id, ...(ctx.application ? {} : { contentRef: post.content_ref }) });
|
|
917
|
+
this.automation.human(db, post);
|
|
918
|
+
this.agents.enqueue(db, tx, { ...post, mentions: JSON.stringify(body.mentions.filter(m => m !== "assistant")) }, member.id, ctx.application ? { asker: me, name: `${post.author_name} via ${ctx.application.name}`, text: body.text } : undefined);
|
|
919
|
+
if (!ctx.application)
|
|
920
|
+
this.assistant.enqueue(db, tx, post, member.id, room.assistant_for !== null);
|
|
533
921
|
added = true;
|
|
534
922
|
return post;
|
|
535
923
|
}, this.fence(ctx));
|
|
@@ -546,6 +934,386 @@ export class HubGroupRooms {
|
|
|
546
934
|
this.assistant.wake();
|
|
547
935
|
return message;
|
|
548
936
|
}
|
|
937
|
+
/** A quiet, coalesced line after the third rejected app post; no question or agent delivery. */
|
|
938
|
+
async appRateLimited(ctx, id) {
|
|
939
|
+
if (!ctx.application)
|
|
940
|
+
throw new HubProtocolError("denied");
|
|
941
|
+
const me = await this.who(ctx);
|
|
942
|
+
const post = this.core.atomic((db, tx) => {
|
|
943
|
+
this.member(db, id, me);
|
|
944
|
+
if (this.room(db, id).archived)
|
|
945
|
+
return null;
|
|
946
|
+
const now = this.core.now(), window = Math.floor(now / 60_000) * 60_000;
|
|
947
|
+
db.prepare("DELETE FROM hub_mcp_rate_notices WHERE person=? AND window<?").run(me, now - 60 * 60_000);
|
|
948
|
+
db.prepare("INSERT INTO hub_mcp_rate_notices VALUES(?,?,?,1,NULL) ON CONFLICT(person,room_id,window) DO UPDATE SET refused=refused+1").run(me, id, window);
|
|
949
|
+
const notice = db.prepare("SELECT refused,post_id FROM hub_mcp_rate_notices WHERE person=? AND room_id=? AND window=?").get(me, id, window);
|
|
950
|
+
if (notice.refused !== 3 || notice.post_id)
|
|
951
|
+
return null;
|
|
952
|
+
const name = this.name(db, me), row = this.insert(db, tx, id, { kind: "system", id: "app-rate-limited", subject: me, name }, `${name}'s AI app was slowed down.`);
|
|
953
|
+
db.prepare("UPDATE hub_mcp_rate_notices SET post_id=? WHERE person=? AND room_id=? AND window=?").run(row.id, me, id, window);
|
|
954
|
+
return row;
|
|
955
|
+
}, this.fence(ctx));
|
|
956
|
+
if (post)
|
|
957
|
+
this.emit({ type: "message.added", roomId: id, data: { roomId: id, message: this.projection(post) }, sequence: post.sequence });
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* M-3127: add or take back my reaction on a post I can see (since my joined_sequence; not a room line, not an answer
|
|
961
|
+
* still to come). Set semantics: adding twice or removing what is not there changes nothing and emits nothing.
|
|
962
|
+
*/
|
|
963
|
+
async react(ctx, id, postId, input) {
|
|
964
|
+
const body = validated(reactSchema, input), target = validated(uuid, postId);
|
|
965
|
+
if (!validRoomEmoji(body.emoji))
|
|
966
|
+
throw new HubProtocolError("invalid");
|
|
967
|
+
const me = await this.who(ctx);
|
|
968
|
+
const done = this.core.atomic(db => {
|
|
969
|
+
const member = this.member(db, id, me);
|
|
970
|
+
if (this.room(db, id).archived)
|
|
971
|
+
throw new HubRoomRefusal(409, "archived");
|
|
972
|
+
const post = this.visiblePost(db, id, member, target);
|
|
973
|
+
if (post.author_kind === "system" || post.stage && post.stage !== "answered")
|
|
974
|
+
throw new HubRoomRefusal(409, "invalid");
|
|
975
|
+
let changed;
|
|
976
|
+
if (body.on) {
|
|
977
|
+
const has = db.prepare("SELECT emoji FROM hub_room_reactions WHERE post_id=? GROUP BY emoji").all(post.id);
|
|
978
|
+
if (!has.some(r => r.emoji === body.emoji) && has.length >= ROOM_REACTION_LIMIT)
|
|
979
|
+
throw new HubRoomRefusal(409, "limit");
|
|
980
|
+
changed = db.prepare("INSERT OR IGNORE INTO hub_room_reactions(room_id,post_id,member_id,emoji,created_at) VALUES(?,?,?,?,?)").run(id, post.id, member.id, body.emoji, this.core.now()).changes > 0;
|
|
981
|
+
}
|
|
982
|
+
else
|
|
983
|
+
changed = db.prepare("DELETE FROM hub_room_reactions WHERE post_id=? AND member_id=? AND emoji=?").run(post.id, member.id, body.emoji).changes > 0;
|
|
984
|
+
return { post, changed, reactions: this.reactions(db, post.id) };
|
|
985
|
+
}, this.fence(ctx));
|
|
986
|
+
// The post as it now is, on the stream every open tab already reads (message.updated): no new event name.
|
|
987
|
+
if (done.changed)
|
|
988
|
+
this.emit({ type: "message.updated", roomId: id, data: { roomId: id, message: this.projection(done.post) }, sequence: done.post.sequence });
|
|
989
|
+
return { reactions: done.reactions };
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* M-3127: a post exactly as messages() shows it to `member` — since their joined_sequence, its lineage's audience floor
|
|
993
|
+
* too (Ridge, M-3118: the descendants of a question older than them stay hidden), and an answer only when its question
|
|
994
|
+
* is theirs to see. 404 otherwise.
|
|
995
|
+
*/
|
|
996
|
+
visiblePost(db, roomId, member, postId) {
|
|
997
|
+
const post = db.prepare("SELECT * FROM hub_room_posts WHERE id=? AND room_id=? AND sequence>=? AND COALESCE((SELECT audience_sequence FROM hub_room_post_lineage l WHERE l.post_id=hub_room_posts.id),sequence)>=?")
|
|
998
|
+
.get(postId, roomId, member.joined_sequence, member.joined_sequence);
|
|
999
|
+
if (!post || post.answer_to && !db.prepare("SELECT 1 FROM hub_room_posts WHERE id=? AND room_id=? AND sequence>=?").get(post.answer_to, roomId, member.joined_sequence))
|
|
1000
|
+
throw new HubRoomRefusal(404, "not-found");
|
|
1001
|
+
return post;
|
|
1002
|
+
}
|
|
1003
|
+
/** M-3127: a member's name as the room shows it (a person's display name, an agent's exposure name, the assistant). */
|
|
1004
|
+
memberName(db, memberId) {
|
|
1005
|
+
const m = db.prepare("SELECT * FROM hub_room_members WHERE id=?").get(memberId);
|
|
1006
|
+
if (!m)
|
|
1007
|
+
return "";
|
|
1008
|
+
if (m.kind === "person")
|
|
1009
|
+
return this.name(db, m.subject);
|
|
1010
|
+
if (m.kind === "assistant")
|
|
1011
|
+
return "Room assistant";
|
|
1012
|
+
return readExposure(db, m.subject)?.display_name ?? "";
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* M-3127 B: press an answer's button, or vote in its poll (the direct chat's body: { setId, index | options,
|
|
1016
|
+
* idempotencyKey }). Plain buttons: the question's asker only (403 not-asker), the first press wins, and it becomes the
|
|
1017
|
+
* asker's own room message — the button's label, replying to the answer, to that agent — delivered by the ordinary room
|
|
1018
|
+
* ask (the agent gets the click line). Polls: every person who can see it; a later vote replaces mine until it closes.
|
|
1019
|
+
*/
|
|
1020
|
+
async click(ctx, id, input) {
|
|
1021
|
+
const body = validated(clickSchema, input), me = await this.who(ctx);
|
|
1022
|
+
this.settleButtons();
|
|
1023
|
+
const done = this.core.atomic((db, tx) => {
|
|
1024
|
+
const member = this.member(db, id, me);
|
|
1025
|
+
if (this.room(db, id).archived)
|
|
1026
|
+
throw new HubRoomRefusal(409, "archived");
|
|
1027
|
+
const row = this.buttons.row(db, body.setId);
|
|
1028
|
+
if (!row || row.room_id !== id)
|
|
1029
|
+
throw new HubRoomRefusal(404, "not-found");
|
|
1030
|
+
const answer = this.visiblePost(db, id, member, row.post_id), b = this.buttons.choices(row);
|
|
1031
|
+
if (!b)
|
|
1032
|
+
throw new HubRoomRefusal(409, "expired");
|
|
1033
|
+
let picked;
|
|
1034
|
+
if (b.poll) {
|
|
1035
|
+
const o = body.options;
|
|
1036
|
+
if (body.index !== undefined || !o || o.some(i => i >= b.labels.length) || new Set(o).size !== o.length || !b.poll.multi && o.length !== 1)
|
|
1037
|
+
throw new HubProtocolError("invalid");
|
|
1038
|
+
picked = [...o].sort((x, y) => x - y);
|
|
1039
|
+
}
|
|
1040
|
+
else {
|
|
1041
|
+
if (body.options !== undefined || body.index === undefined || body.index >= b.labels.length)
|
|
1042
|
+
throw new HubProtocolError("invalid");
|
|
1043
|
+
picked = [body.index];
|
|
1044
|
+
}
|
|
1045
|
+
const digest = createHash("sha256").update(JSON.stringify([body.setId, !!b.poll, picked])).digest("hex");
|
|
1046
|
+
const dup = db.prepare("SELECT set_id,digest FROM hub_room_button_operations WHERE room_id=? AND member_id=? AND idempotency_key=?").get(id, member.id, body.idempotencyKey);
|
|
1047
|
+
if (dup) {
|
|
1048
|
+
if (dup.set_id !== body.setId || dup.digest !== digest)
|
|
1049
|
+
throw new HubRoomRefusal(409, "conflict");
|
|
1050
|
+
return { answer, click: null, changed: false };
|
|
1051
|
+
}
|
|
1052
|
+
if (row.state !== "open" || this.core.now() >= row.expires_at)
|
|
1053
|
+
throw new HubRoomRefusal(409, "expired");
|
|
1054
|
+
let click = null;
|
|
1055
|
+
if (!b.poll) {
|
|
1056
|
+
if (row.asker_member !== member.id)
|
|
1057
|
+
throw new HubRoomRefusal(403, "not-asker");
|
|
1058
|
+
const i = picked[0], label = b.labels[i], value = b.values?.[i] ?? label, name = this.name(db, me);
|
|
1059
|
+
// One click per set, whatever the browser's key: the set's own key makes a second press a conflict, not a post.
|
|
1060
|
+
const key = setKey(body.setId), clickDigest = createHash("sha256").update(JSON.stringify({ text: label, mentions: [answer.author_id], replyTo: answer.id })).digest("hex");
|
|
1061
|
+
click = this.insert(db, tx, id, { kind: "person", id: member.id, subject: me, name }, label, [answer.author_id], key, clickDigest, answer.id);
|
|
1062
|
+
this.core.audit(tx, { requestId: ctx.requestId, actor: { kind: "person", person: personFromString(me) }, action: "room.message", result: "completed", roomId: id, messageId: click.id, contentRef: click.content_ref });
|
|
1063
|
+
this.automation.human(db, click);
|
|
1064
|
+
if (db.prepare("SELECT 1 FROM hub_room_members WHERE room_id=? AND kind='agent' AND subject=?").get(id, answer.author_id))
|
|
1065
|
+
this.agents.enqueue(db, tx, click, member.id, { asker: me, name, text: replyButtonClickText({ label, value }) });
|
|
1066
|
+
db.prepare("UPDATE hub_room_buttons SET state='chosen',chosen_index=?,chosen_member=?,closed_at=?,revision=revision+1 WHERE id=? AND state='open'").run(i, member.id, this.core.now(), row.id);
|
|
1067
|
+
}
|
|
1068
|
+
else {
|
|
1069
|
+
db.prepare("INSERT INTO hub_room_votes(set_id,member_id,options,at) VALUES(?,?,?,?) ON CONFLICT(set_id,member_id) DO UPDATE SET options=excluded.options,at=excluded.at")
|
|
1070
|
+
.run(row.id, member.id, JSON.stringify(picked), this.core.now());
|
|
1071
|
+
db.prepare("UPDATE hub_room_buttons SET revision=revision+1 WHERE id=?").run(row.id);
|
|
1072
|
+
}
|
|
1073
|
+
db.prepare("INSERT INTO hub_room_button_operations VALUES(?,?,?,?,?)").run(id, member.id, body.idempotencyKey, body.setId, digest);
|
|
1074
|
+
return { answer, click, changed: true };
|
|
1075
|
+
}, this.fence(ctx));
|
|
1076
|
+
if (done.changed)
|
|
1077
|
+
this.emit({ type: "message.updated", roomId: id, data: { roomId: id, message: this.projection(done.answer) }, sequence: done.answer.sequence });
|
|
1078
|
+
if (done.click) {
|
|
1079
|
+
this.emit({ type: "message.added", roomId: id, data: { roomId: id, message: this.projection(done.click) }, sequence: done.click.sequence });
|
|
1080
|
+
this.emit({ type: "unread.changed", roomId: id, data: { roomId: id } });
|
|
1081
|
+
this.agents.publishQueued(done.click.id);
|
|
1082
|
+
this.agents.wake();
|
|
1083
|
+
}
|
|
1084
|
+
return { ok: true };
|
|
1085
|
+
}
|
|
1086
|
+
/** M-3127 B: the next open set's deadline, once; closes what is due and arms again (30 s after a failure). */
|
|
1087
|
+
armButtons(delay) {
|
|
1088
|
+
if (this.buttonsClosed || !this.core.live())
|
|
1089
|
+
return;
|
|
1090
|
+
if (this.buttonsTimer)
|
|
1091
|
+
clearTimeout(this.buttonsTimer);
|
|
1092
|
+
let wait = delay;
|
|
1093
|
+
if (wait === undefined) {
|
|
1094
|
+
const next = this.core.atomic(db => this.buttons.nextDeadline(db));
|
|
1095
|
+
if (next === null) {
|
|
1096
|
+
this.buttonsTimer = null;
|
|
1097
|
+
return;
|
|
1098
|
+
}
|
|
1099
|
+
wait = Math.max(0, next - this.core.now());
|
|
1100
|
+
}
|
|
1101
|
+
this.buttonsTimer = setTimeout(() => { this.buttonsTimer = null; try {
|
|
1102
|
+
this.closeDueButtons();
|
|
1103
|
+
this.armButtons();
|
|
1104
|
+
}
|
|
1105
|
+
catch {
|
|
1106
|
+
this.armButtons(30_000);
|
|
1107
|
+
} }, Math.min(wait, 2 ** 31 - 1));
|
|
1108
|
+
this.buttonsTimer.unref?.();
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* M-3127 B: sets past their deadline. Buttons expire. A poll closes: one room line (「投票結束」, in the poll's lineage —
|
|
1112
|
+
* Ridge: a system consequence, never a fresh human root) and the results delivered to the agent that asked it, on behalf
|
|
1113
|
+
* of that question's asker (the Fleet chat's [poll results]).
|
|
1114
|
+
*/
|
|
1115
|
+
closeDueButtons() {
|
|
1116
|
+
if (this.buttonsClosed || !this.core.live())
|
|
1117
|
+
return;
|
|
1118
|
+
const out = this.core.atomic((db, tx) => {
|
|
1119
|
+
const changed = [];
|
|
1120
|
+
for (const row of this.buttons.due(db)) {
|
|
1121
|
+
const b = this.buttons.choices(row), now = this.core.now();
|
|
1122
|
+
const answer = db.prepare("SELECT * FROM hub_room_posts WHERE id=?").get(row.post_id);
|
|
1123
|
+
if (!b?.poll || !answer) {
|
|
1124
|
+
db.prepare("UPDATE hub_room_buttons SET state='expired',closed_at=?,revision=revision+1 WHERE id=? AND state='open'").run(now, row.id);
|
|
1125
|
+
if (answer)
|
|
1126
|
+
changed.push({ answer, line: null });
|
|
1127
|
+
continue;
|
|
1128
|
+
}
|
|
1129
|
+
db.prepare("UPDATE hub_room_buttons SET state='closed',closed_at=?,revision=revision+1 WHERE id=? AND state='open'").run(now, row.id);
|
|
1130
|
+
const votes = this.buttons.votes(db, row.id);
|
|
1131
|
+
const ballots = votes.map(v => ({ voter: v.member_id, name: this.memberName(db, v.member_id), options: v.options, at: v.at }));
|
|
1132
|
+
const text = pollResultsText({ id: row.id, buttons: b.labels.map((label, i) => ({ label, value: b.values?.[i] ?? label })), createdAt: row.created_at, expiresAt: row.expires_at }, b.poll, ballots, now);
|
|
1133
|
+
// The room line says only that it closed (counts are on the poll; names only with showVoters, on the poll too).
|
|
1134
|
+
const line = this.insert(db, tx, row.room_id, { kind: "system", id: "poll-closed", subject: "system", name: answer.author_name }, `Poll closed · ${votes.length} voted`);
|
|
1135
|
+
const l = this.automation.lineage(db, answer);
|
|
1136
|
+
db.prepare("INSERT INTO hub_room_post_lineage VALUES(?,?,?,?,NULL)").run(line.id, l.root_id, l.depth, l.audience_sequence);
|
|
1137
|
+
db.prepare("UPDATE hub_room_buttons SET result_post=? WHERE id=?").run(line.id, row.id);
|
|
1138
|
+
const d = db.prepare("SELECT asker,asker_member FROM hub_room_deliveries WHERE id=?").get(row.delivery_id);
|
|
1139
|
+
const room = this.room(db, row.room_id);
|
|
1140
|
+
const agentHere = db.prepare("SELECT 1 FROM hub_room_members WHERE room_id=? AND kind='agent' AND subject=?").get(row.room_id, answer.author_id);
|
|
1141
|
+
const askerHere = d && db.prepare("SELECT 1 FROM hub_room_members WHERE id=? AND room_id=?").get(d.asker_member, row.room_id);
|
|
1142
|
+
if (d && agentHere && askerHere && !room.archived)
|
|
1143
|
+
this.agents.enqueue(db, tx, { ...line, mentions: JSON.stringify([answer.author_id]) }, d.asker_member, { asker: d.asker, name: "Poll results", text });
|
|
1144
|
+
this.core.audit(tx, { requestId: row.id, actor: { kind: "local-host" }, action: "room.poll-closed", result: "completed", roomId: row.room_id, messageId: line.id, contentRef: line.content_ref });
|
|
1145
|
+
changed.push({ answer, line });
|
|
1146
|
+
}
|
|
1147
|
+
return changed;
|
|
1148
|
+
});
|
|
1149
|
+
for (const { answer, line } of out) {
|
|
1150
|
+
this.emit({ type: "message.updated", roomId: answer.room_id, data: { roomId: answer.room_id, message: this.projection(answer) }, sequence: answer.sequence });
|
|
1151
|
+
if (line) {
|
|
1152
|
+
this.emit({ type: "message.added", roomId: line.room_id, data: { roomId: line.room_id, message: this.projection(line) }, sequence: line.sequence });
|
|
1153
|
+
this.agents.publishQueued(line.id);
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
if (out.some(x => x.line))
|
|
1157
|
+
this.agents.wake();
|
|
1158
|
+
}
|
|
1159
|
+
/**
|
|
1160
|
+
* M-3127 (agent reactions, on room-answer-buttons-v1): an agent's reaction (its `react`) to the room question it was asked — only on that delivery's
|
|
1161
|
+
* own question, from the Fleet and owner it went to, while the agent is still in the room. One reaction per agent and
|
|
1162
|
+
* post (a later one replaces it; "" takes it back), stored under the agent's membership; the post as it now is goes out
|
|
1163
|
+
* on the room stream (message.updated).
|
|
1164
|
+
*/
|
|
1165
|
+
async agentReact(input, link) {
|
|
1166
|
+
const body = validated(roomReactSchema, input);
|
|
1167
|
+
if (body.emoji !== "" && !validRoomEmoji(body.emoji))
|
|
1168
|
+
throw new HubProtocolError("invalid");
|
|
1169
|
+
if (!link.current() || !link.features.has(HUB_ROOM_REACT_CAPABILITY))
|
|
1170
|
+
throw new HubProtocolError("revoked");
|
|
1171
|
+
const done = this.core.atomic(db => {
|
|
1172
|
+
const d = db.prepare("SELECT * FROM hub_room_deliveries WHERE id=?").get(body.messageId);
|
|
1173
|
+
if (!d || d.fleet_id !== link.fleetId || d.owner !== personKeyString(link.owner) || d.room_id !== body.roomId || d.exposure_id !== body.exposureId)
|
|
1174
|
+
throw new HubProtocolError("denied");
|
|
1175
|
+
const room = this.room(db, d.room_id);
|
|
1176
|
+
if (room.archived)
|
|
1177
|
+
return { post: null, changed: false, archived: true }; // a result, never a broken member link
|
|
1178
|
+
if (!db.prepare("SELECT 1 FROM hub_room_members WHERE id=? AND room_id=? AND kind='agent' AND subject=?").get(d.agent_member, d.room_id, d.exposure_id))
|
|
1179
|
+
throw new HubProtocolError("revoked");
|
|
1180
|
+
const post = db.prepare("SELECT * FROM hub_room_posts WHERE id=? AND room_id=?").get(d.parent_id, d.room_id);
|
|
1181
|
+
if (!post)
|
|
1182
|
+
throw new HubProtocolError("not-found");
|
|
1183
|
+
// Under the agent as the room lists it (its exposure id: the members panel's id for an agent), so the page can name it.
|
|
1184
|
+
const who = d.exposure_id;
|
|
1185
|
+
const had = db.prepare("SELECT emoji FROM hub_room_reactions WHERE post_id=? AND member_id=?").all(post.id, who);
|
|
1186
|
+
if (had.length === (body.emoji ? 1 : 0) && (!body.emoji || had[0].emoji === body.emoji))
|
|
1187
|
+
return { post, changed: false };
|
|
1188
|
+
if (body.emoji && !had.some(r => r.emoji === body.emoji)
|
|
1189
|
+
&& db.prepare("SELECT COUNT(DISTINCT emoji) n FROM hub_room_reactions WHERE post_id=? AND member_id<>?").get(post.id, who).n >= ROOM_REACTION_LIMIT
|
|
1190
|
+
&& !(db.prepare("SELECT 1 FROM hub_room_reactions WHERE post_id=? AND emoji=?").get(post.id, body.emoji)))
|
|
1191
|
+
throw new HubProtocolError("invalid");
|
|
1192
|
+
db.prepare("DELETE FROM hub_room_reactions WHERE post_id=? AND member_id=?").run(post.id, who);
|
|
1193
|
+
if (body.emoji)
|
|
1194
|
+
db.prepare("INSERT INTO hub_room_reactions(room_id,post_id,member_id,emoji,created_at) VALUES(?,?,?,?,?)").run(d.room_id, post.id, who, body.emoji, this.core.now());
|
|
1195
|
+
return { post, changed: true };
|
|
1196
|
+
});
|
|
1197
|
+
if ("archived" in done)
|
|
1198
|
+
return { messageId: body.messageId, ok: false, code: "archived" };
|
|
1199
|
+
if (done.changed && done.post)
|
|
1200
|
+
this.emit({ type: "message.updated", roomId: done.post.room_id, data: { roomId: done.post.room_id, message: this.projection(done.post) }, sequence: done.post.sequence });
|
|
1201
|
+
return { messageId: body.messageId, ok: true };
|
|
1202
|
+
}
|
|
1203
|
+
/** A read or a press first closes what is already due (a suspended host's timer may be late): never a stale open poll. */
|
|
1204
|
+
settleButtons() {
|
|
1205
|
+
const next = this.core.atomic(db => this.buttons.nextDeadline(db));
|
|
1206
|
+
if (next !== null && next <= this.core.now()) {
|
|
1207
|
+
this.closeDueButtons();
|
|
1208
|
+
this.armButtons();
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* M-3127 C: messages with these words in the group rooms I am in, newest first — exactly what messages() would show me
|
|
1213
|
+
* (since my joined_sequence, the lineage floor, answered rows only, no room lines). The text is encrypted at rest and
|
|
1214
|
+
* retention deletes it, so there is no plaintext index: a bounded scan (ROOM_SEARCH_SCAN posts a request), and `cursor`
|
|
1215
|
+
* when more remain ("search older messages"). Every word must appear (NFKC, case-folded). ROOM_SEARCH_PER_MINUTE each.
|
|
1216
|
+
*/
|
|
1217
|
+
async search(ctx, q, limit = 20, cursor = null) {
|
|
1218
|
+
const query = typeof q === "string" ? q.trim() : "", n = typeof limit === "number" ? limit : Number(limit);
|
|
1219
|
+
const terms = [...new Set(fold(query).split(/\s+/).filter(Boolean))].slice(0, 8);
|
|
1220
|
+
if (query.length < 1 || query.length > 100 || !terms.length || !Number.isSafeInteger(n) || n < 1 || n > ROOM_SEARCH_LIMIT)
|
|
1221
|
+
throw new HubProtocolError("invalid");
|
|
1222
|
+
let after = null;
|
|
1223
|
+
if (cursor !== null && cursor !== undefined && cursor !== "") {
|
|
1224
|
+
const c = typeof cursor === "string" ? /^(\d{1,15})\.([a-f0-9-]{36})$/.exec(cursor) : null;
|
|
1225
|
+
if (!c)
|
|
1226
|
+
throw new HubProtocolError("invalid");
|
|
1227
|
+
after = { at: Number(c[1]), id: c[2] };
|
|
1228
|
+
}
|
|
1229
|
+
const me = await this.who(ctx);
|
|
1230
|
+
// A search reads and decrypts up to ROOM_SEARCH_SCAN posts on the event loop: at most ROOM_SEARCH_PER_MINUTE a minute
|
|
1231
|
+
// each (429 busy, the page says to try again in a moment). One person's map entry; old times drop on every call.
|
|
1232
|
+
const now = this.core.now(), recent = (this.searches.get(me) ?? []).filter(t => t > now - 60_000);
|
|
1233
|
+
if (recent.length >= ROOM_SEARCH_PER_MINUTE) {
|
|
1234
|
+
this.searches.set(me, recent);
|
|
1235
|
+
throw new HubRoomRefusal(429, "busy");
|
|
1236
|
+
}
|
|
1237
|
+
this.searches.set(me, [...recent, now]);
|
|
1238
|
+
if (this.searches.size > 10_000)
|
|
1239
|
+
for (const [k, v] of this.searches)
|
|
1240
|
+
if (!v.some(t => t > now - 60_000))
|
|
1241
|
+
this.searches.delete(k);
|
|
1242
|
+
{
|
|
1243
|
+
return this.core.atomic(db => {
|
|
1244
|
+
const rows = db.prepare(`SELECT p.*,r.name AS room_name FROM hub_room_posts p
|
|
1245
|
+
JOIN hub_room_members m ON m.room_id=p.room_id AND m.kind='person' AND m.subject=?
|
|
1246
|
+
JOIN hub_group_rooms r ON r.id=p.room_id
|
|
1247
|
+
WHERE p.sequence>=m.joined_sequence AND COALESCE((SELECT audience_sequence FROM hub_room_post_lineage l WHERE l.post_id=p.id),p.sequence)>=m.joined_sequence
|
|
1248
|
+
AND p.author_kind<>'system' AND (p.stage IS NULL OR p.stage='answered')
|
|
1249
|
+
AND (p.answer_to IS NULL OR EXISTS(SELECT 1 FROM hub_room_posts o WHERE o.id=p.answer_to AND o.sequence>=m.joined_sequence))
|
|
1250
|
+
AND (? IS NULL OR p.created_at<? OR p.created_at=? AND p.id<?)
|
|
1251
|
+
ORDER BY p.created_at DESC,p.id DESC LIMIT ?`).all(me, after?.at ?? null, after?.at ?? 0, after?.at ?? 0, after?.id ?? "", ROOM_SEARCH_SCAN);
|
|
1252
|
+
const hits = [];
|
|
1253
|
+
let last = null;
|
|
1254
|
+
for (const row of rows) {
|
|
1255
|
+
last = row;
|
|
1256
|
+
const text = this.core.deps.content.get(row.content_ref)?.question;
|
|
1257
|
+
if (!text)
|
|
1258
|
+
continue; // retention removed it
|
|
1259
|
+
const lower = fold(text);
|
|
1260
|
+
if (!terms.every(t => lower.includes(t)))
|
|
1261
|
+
continue;
|
|
1262
|
+
const author = this.projection(row).author;
|
|
1263
|
+
hits.push({ roomId: row.room_id, roomName: row.room_name, messageId: row.id, sequence: row.sequence, at: row.created_at,
|
|
1264
|
+
author: { kind: author.kind, name: author.name }, ...searchSnippet(text, terms) });
|
|
1265
|
+
if (hits.length >= n)
|
|
1266
|
+
break;
|
|
1267
|
+
}
|
|
1268
|
+
const more = !!last && (hits.length >= n ? last !== rows[rows.length - 1] || rows.length === ROOM_SEARCH_SCAN : rows.length === ROOM_SEARCH_SCAN);
|
|
1269
|
+
return { hits, ...(more && last ? { cursor: `${last.created_at}.${last.id}` } : {}) };
|
|
1270
|
+
}, this.fence(ctx));
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
/** M-3125: before any upload body is read — a member of a room that is not archived, and room in their pending budget. */
|
|
1274
|
+
async uploadAdmit(ctx, id, declaredBytes) {
|
|
1275
|
+
const me = await this.who(ctx), store = this.store();
|
|
1276
|
+
this.core.atomic(db => { this.member(db, id, me); if (this.room(db, id).archived)
|
|
1277
|
+
throw new HubRoomRefusal(409, "archived"); store.admit(db, { uploader: me }, declaredBytes); }, this.fence(ctx));
|
|
1278
|
+
}
|
|
1279
|
+
/** M-3125: a member's file for a later post in this room, pending one hour (as in a 1:1 chat). */
|
|
1280
|
+
async upload(ctx, id, name, bytes) {
|
|
1281
|
+
const me = await this.who(ctx), store = this.store();
|
|
1282
|
+
return this.core.atomic((db, tx) => {
|
|
1283
|
+
this.member(db, id, me);
|
|
1284
|
+
if (this.room(db, id).archived)
|
|
1285
|
+
throw new HubRoomRefusal(409, "archived");
|
|
1286
|
+
const ref = store.createUpload(db, { roomId: id, uploader: me, name, bytes });
|
|
1287
|
+
this.core.audit(tx, { requestId: ctx.requestId, actor: { kind: "person", person: personFromString(me) }, action: "file.upload", result: "allowed",
|
|
1288
|
+
reasonCode: `question:${ref.size}:${ref.mime}:${ref.sha256}`, contentRef: this.core.deps.content.put(tx, { question: ref.name }), roomId: id });
|
|
1289
|
+
return groupFileView(id, ref);
|
|
1290
|
+
}, this.fence(ctx));
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* M-3125: one of this room's files, for a current member: a file on a post they can see (at or after their join floor, the
|
|
1294
|
+
* room's history rule) or their own pending upload. Every read is audited.
|
|
1295
|
+
*/
|
|
1296
|
+
async download(ctx, id, fileId) {
|
|
1297
|
+
const me = await this.who(ctx), store = this.store(), now = this.core.now();
|
|
1298
|
+
return this.core.atomic((db, tx) => {
|
|
1299
|
+
const member = this.member(db, id, me), row = store.row(db, fileId);
|
|
1300
|
+
if (!row || row.room_id !== id)
|
|
1301
|
+
throw new HubProtocolError("not-found");
|
|
1302
|
+
// The listing's own visibility rule (Ridge, M-3118): the post at or after the floor, its lineage's audience at or after it, and the
|
|
1303
|
+
// post it answers too — a chained answer after a viewer joined does not reveal a hidden question's files, nor its own.
|
|
1304
|
+
const visible = row.state === "bound" && !!row.message_id && !!db.prepare(`SELECT 1 FROM hub_room_posts p WHERE p.id=? AND p.room_id=? AND p.sequence>=?
|
|
1305
|
+
AND (p.stage IS NULL OR p.stage='answered')
|
|
1306
|
+
AND COALESCE((SELECT audience_sequence FROM hub_room_post_lineage l WHERE l.post_id=p.id),p.sequence)>=?
|
|
1307
|
+
AND (p.answer_to IS NULL OR EXISTS(SELECT 1 FROM hub_room_posts o WHERE o.id=p.answer_to AND o.sequence>=?))`).get(row.message_id, id, member.joined_sequence, member.joined_sequence, member.joined_sequence);
|
|
1308
|
+
const own = row.state === "pending" && row.uploader === me && (row.expires_at ?? 0) > now;
|
|
1309
|
+
if (!own && !visible)
|
|
1310
|
+
throw new HubProtocolError("not-found");
|
|
1311
|
+
const bytes = store.read(db, row.sha256);
|
|
1312
|
+
this.core.audit(tx, { requestId: ctx.requestId, actor: { kind: "person", person: personFromString(me) }, action: "file.read", result: "allowed",
|
|
1313
|
+
reasonCode: `${row.direction}:${row.size}:${row.mime}:${row.sha256}`, ...(row.message_id ? { messageId: row.message_id } : {}), roomId: id });
|
|
1314
|
+
return { name: row.name, mime: row.mime, image: isInlineImage(row.mime), bytes };
|
|
1315
|
+
}, this.fence(ctx));
|
|
1316
|
+
}
|
|
549
1317
|
async markRead(ctx, id, upTo) {
|
|
550
1318
|
const target = validated(uuid, upTo), me = await this.who(ctx);
|
|
551
1319
|
this.core.atomic(db => {
|
|
@@ -568,6 +1336,8 @@ export class HubGroupRooms {
|
|
|
568
1336
|
if (!member || event.sequence !== undefined && event.sequence < member.joined_sequence)
|
|
569
1337
|
return null;
|
|
570
1338
|
const message = event.data.message;
|
|
1339
|
+
if (message && db.prepare("SELECT 1 FROM hub_room_post_lineage WHERE post_id=? AND audience_sequence<?").get(message.id, member.joined_sequence))
|
|
1340
|
+
return null;
|
|
571
1341
|
if (message?.answerTo && !db.prepare("SELECT 1 FROM hub_room_posts WHERE id=? AND room_id=? AND sequence>=?").get(message.answerTo, event.roomId, member.joined_sequence))
|
|
572
1342
|
return null;
|
|
573
1343
|
if (event.type === "unread.changed")
|