@songsid/agend 2.4.0-beta.21 → 2.4.0-beta.23
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-whats-new.js +6 -0
- package/dist/agent-whats-new.js.map +1 -1
- package/dist/auth-api.d.ts +2 -0
- package/dist/auth-api.js +5 -2
- package/dist/auth-api.js.map +1 -1
- package/dist/authority/web-authority.d.ts +17 -3
- package/dist/authority/web-authority.js +56 -3
- package/dist/authority/web-authority.js.map +1 -1
- package/dist/backend/claude-code.js +3 -0
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/cache-ledger.d.ts +23 -21
- package/dist/cache-ledger.js +70 -6
- package/dist/cache-ledger.js.map +1 -1
- package/dist/cache-prices.d.ts +8 -6
- package/dist/cache-prices.js +12 -5
- package/dist/cache-prices.js.map +1 -1
- package/dist/cache-service.d.ts +9 -5
- package/dist/cache-service.js +202 -50
- package/dist/cache-service.js.map +1 -1
- package/dist/channel/mcp-tools.js +8 -1
- package/dist/channel/mcp-tools.js.map +1 -1
- package/dist/classic-channel-manager.d.ts +1 -1
- package/dist/classic-channel-manager.js +2 -2
- package/dist/classic-channel-manager.js.map +1 -1
- package/dist/cli-audited.js +2 -1
- package/dist/cli-audited.js.map +1 -1
- package/dist/cli.js +4 -1
- package/dist/cli.js.map +1 -1
- package/dist/contact-auth-api.js +3 -1
- package/dist/contact-auth-api.js.map +1 -1
- package/dist/contact-auth-policy.js +1 -1
- package/dist/contact-auth-policy.js.map +1 -1
- package/dist/contact-auth-service.js +8 -2
- package/dist/contact-auth-service.js.map +1 -1
- package/dist/contact-auth-store.d.ts +31 -2
- package/dist/contact-auth-store.js +106 -12
- package/dist/contact-auth-store.js.map +1 -1
- package/dist/contact-auth-types.d.ts +3 -2
- package/dist/contact-auth-types.js.map +1 -1
- package/dist/contact-change-proposals.d.ts +18 -1
- package/dist/contact-change-proposals.js +41 -6
- package/dist/contact-change-proposals.js.map +1 -1
- package/dist/contact-state-view.d.ts +103 -0
- package/dist/contact-state-view.js +80 -0
- package/dist/contact-state-view.js.map +1 -0
- package/dist/daemon.d.ts +31 -0
- package/dist/daemon.js +149 -2
- package/dist/daemon.js.map +1 -1
- package/dist/delivery-outbox.d.ts +10 -0
- package/dist/delivery-outbox.js +21 -0
- package/dist/delivery-outbox.js.map +1 -1
- package/dist/fleet-manager.d.ts +183 -15
- package/dist/fleet-manager.js +628 -96
- package/dist/fleet-manager.js.map +1 -1
- package/dist/general-knowledge/skills/admin/SKILL.md +52 -0
- package/dist/general-knowledge/skills/concepts/SKILL.md +14 -17
- package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +6 -3
- package/dist/general-knowledge/skills/hub/SKILL.md +12 -4
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +54 -9
- package/dist/general-knowledge/skills/worker-collaboration/SKILL.md +1 -1
- package/dist/general-role.d.ts +1 -1
- package/dist/general-role.js +1 -0
- package/dist/general-role.js.map +1 -1
- package/dist/hub/agent-pictures-model.d.ts +128 -0
- package/dist/hub/agent-pictures-model.js +43 -4
- package/dist/hub/agent-pictures-model.js.map +1 -1
- package/dist/hub/agent-pictures.d.ts +14 -2
- package/dist/hub/agent-pictures.js +65 -12
- package/dist/hub/agent-pictures.js.map +1 -1
- package/dist/hub/client.d.ts +2 -0
- package/dist/hub/client.js +14 -2
- package/dist/hub/client.js.map +1 -1
- package/dist/hub/compose/member.d.ts +6 -2
- package/dist/hub/compose/member.js +19 -6
- package/dist/hub/compose/member.js.map +1 -1
- package/dist/hub/compose/server.d.ts +5 -5
- package/dist/hub/compose/server.js +6 -3
- package/dist/hub/compose/server.js.map +1 -1
- package/dist/hub/group-policy/resources.d.ts +1 -1
- package/dist/hub/http/compose.d.ts +3 -0
- package/dist/hub/http/compose.js +14 -7
- package/dist/hub/http/compose.js.map +1 -1
- package/dist/hub/http/deps.d.ts +1 -0
- package/dist/hub/http/schema.js +2 -1
- package/dist/hub/http/schema.js.map +1 -1
- package/dist/hub/init/text.js +1 -1
- package/dist/hub/mcp/policy.d.ts +1 -1
- package/dist/hub/member/agent-pictures.d.ts +34 -1
- package/dist/hub/member/agent-pictures.js +80 -9
- package/dist/hub/member/agent-pictures.js.map +1 -1
- package/dist/hub/member/room-ask.d.ts +22 -1
- package/dist/hub/member/room-ask.js +99 -5
- package/dist/hub/member/room-ask.js.map +1 -1
- package/dist/hub/member/room-asker-store.d.ts +48 -0
- package/dist/hub/member/room-asker-store.js +181 -0
- package/dist/hub/member/room-asker-store.js.map +1 -0
- package/dist/hub/protocol.d.ts +152 -0
- package/dist/hub/protocol.js +6 -1
- package/dist/hub/protocol.js.map +1 -1
- package/dist/hub/question-close-model.d.ts +17 -0
- package/dist/hub/question-close-model.js +7 -0
- package/dist/hub/question-close-model.js.map +1 -0
- package/dist/hub/representative.d.ts +15 -0
- package/dist/hub/representative.js +64 -1
- package/dist/hub/representative.js.map +1 -1
- package/dist/hub/room-asker-identity-model.d.ts +53 -0
- package/dist/hub/room-asker-identity-model.js +14 -0
- package/dist/hub/room-asker-identity-model.js.map +1 -0
- package/dist/hub/room-asker-identity.d.ts +22 -0
- package/dist/hub/room-asker-identity.js +43 -0
- package/dist/hub/room-asker-identity.js.map +1 -0
- package/dist/hub/rooms/agents.js +16 -0
- package/dist/hub/rooms/agents.js.map +1 -1
- package/dist/hub/rooms/asker-identity.d.ts +21 -0
- package/dist/hub/rooms/asker-identity.js +86 -0
- package/dist/hub/rooms/asker-identity.js.map +1 -0
- package/dist/hub/rooms/direct-view.js +1 -0
- package/dist/hub/rooms/direct-view.js.map +1 -1
- package/dist/hub/rooms/office.d.ts +18 -0
- package/dist/hub/rooms/office.js +3 -1
- package/dist/hub/rooms/office.js.map +1 -1
- package/dist/hub/rooms/service.d.ts +6 -0
- package/dist/hub/rooms/service.js +19 -0
- package/dist/hub/rooms/service.js.map +1 -1
- package/dist/hub/rooms/types.d.ts +1 -1
- package/dist/hub/rooms.d.ts +3 -0
- package/dist/hub/rooms.js +27 -1
- package/dist/hub/rooms.js.map +1 -1
- package/dist/hub/server.js +12 -2
- package/dist/hub/server.js.map +1 -1
- package/dist/hub/types.d.ts +3 -2
- package/dist/hub-character-plan.d.ts +47 -0
- package/dist/hub-character-plan.js +70 -0
- package/dist/hub-character-plan.js.map +1 -0
- package/dist/hub-contact-windows.d.ts +13 -1
- package/dist/hub-contact-windows.js +35 -2
- package/dist/hub-contact-windows.js.map +1 -1
- package/dist/hub-picture-reduce.d.ts +21 -1
- package/dist/hub-picture-reduce.js +65 -13
- package/dist/hub-picture-reduce.js.map +1 -1
- package/dist/hub-picture-worker.js +12 -4
- package/dist/hub-picture-worker.js.map +1 -1
- package/dist/human-delivery-receipts.d.ts +12 -2
- package/dist/human-delivery-receipts.js +19 -4
- package/dist/human-delivery-receipts.js.map +1 -1
- package/dist/instructions.d.ts +1 -1
- package/dist/instructions.js +1 -1
- package/dist/instructions.js.map +1 -1
- package/dist/locale.js +367 -275
- package/dist/locale.js.map +1 -1
- package/dist/ls-rows.d.ts +2 -0
- package/dist/ls-rows.js.map +1 -1
- package/dist/needs-you.d.ts +4 -0
- package/dist/needs-you.js +3 -2
- package/dist/needs-you.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 +8 -0
- package/dist/outbound-handlers.js +56 -7
- package/dist/outbound-handlers.js.map +1 -1
- package/dist/outbound-schemas.d.ts +2 -1
- package/dist/outbound-schemas.js +3 -2
- package/dist/outbound-schemas.js.map +1 -1
- package/dist/public-web-gateway.js +18 -0
- package/dist/public-web-gateway.js.map +1 -1
- package/dist/reply-buttons-controller.d.ts +2 -1
- package/dist/reply-buttons-controller.js +1 -1
- package/dist/reply-buttons-controller.js.map +1 -1
- package/dist/runtime-cli-install.js +4 -4
- package/dist/runtime-cli-install.js.map +1 -1
- package/dist/tips.js +3 -3
- package/dist/tool-permissions.js +1 -1
- package/dist/tool-permissions.js.map +1 -1
- package/dist/ui/accounts-keepalive.js +2 -1
- package/dist/ui/agent-export-strings.js +1 -1
- package/dist/ui/agent-page-strings.js +5 -5
- package/dist/ui/chat-activity.js +2 -1
- package/dist/ui/chat-pins.js +2 -1
- package/dist/ui/claude-credentials.js +2 -1
- package/dist/ui/contact-auth-client.js +2 -2
- package/dist/ui/contact-auth-strings.js +28 -17
- package/dist/ui/contact-authorizations.js +6 -4
- package/dist/ui/contact-needs.js +6 -1
- package/dist/ui/contact-permissions.js +6 -4
- package/dist/ui/contact-tool-groups.js +1 -1
- package/dist/ui/contact-verify-need.js +46 -0
- package/dist/ui/fleet-cache.js +7 -6
- package/dist/ui/fleet-canvas.js +1 -1
- package/dist/ui/fleet-office-card.js +26 -2
- package/dist/ui/fleet-office-layout.js +2 -2
- package/dist/ui/fleet-office-skin.js +26 -6
- package/dist/ui/fleet-office-view.js +32 -0
- package/dist/ui/fleet-office-zones.js +22 -9
- package/dist/ui/fleet-office.js +92 -29
- package/dist/ui/fleet-org.js +9 -4
- package/dist/ui/fleet-tab-icons.js +19 -0
- package/dist/ui/fleet-task-activity.js +2 -1
- package/dist/ui/fleet-task-common.js +2 -2
- package/dist/ui/fleet-task-view.js +2 -1
- package/dist/ui/fleet-usage.js +8 -7
- package/dist/ui/hub-admin-overview.js +3 -2
- package/dist/ui/hub-agent-intro.js +2 -1
- package/dist/ui/hub-assistant-admin.js +2 -1
- package/dist/ui/hub-chat-strings.js +1 -1
- package/dist/ui/hub-directory-notices.js +2 -1
- package/dist/ui/hub-enrolment-code.js +2 -1
- package/dist/ui/hub-my-agents-strings.js +2 -2
- package/dist/ui/hub-my-agents.js +3 -2
- package/dist/ui/hub-quick-pairing.js +2 -1
- package/dist/ui/hub-role-audit.js +2 -1
- package/dist/ui/hub-role-forms.js +3 -2
- package/dist/ui/hub-role-view.js +3 -2
- package/dist/ui/hub-roles.js +2 -1
- package/dist/ui/hub-room-agent-strings.js +2 -1
- package/dist/ui/hub-room-list.js +2 -1
- package/dist/ui/hub-room-office.js +70 -2
- package/dist/ui/hub-room-owner-requests.js +2 -1
- package/dist/ui/hub-room-pins.js +2 -1
- package/dist/ui/hub-room-presence.js +5 -0
- package/dist/ui/hub-room-strings.js +2 -2
- package/dist/ui/hub-room-thread.js +1 -1
- package/dist/ui/log-row.js +4 -3
- package/dist/ui/office-share-dialog.js +2 -1
- package/dist/ui/office-share-page.js +2 -1
- package/dist/ui/page-share-dialog.js +3 -2
- package/dist/ui/panel-chat.js +2 -1
- package/dist/ui/panel-details.js +2 -1
- package/dist/ui/panel-fleet.js +15 -10
- package/dist/ui/panel-hub.js +2 -1
- package/dist/ui/panel-log.js +3 -3
- package/dist/ui/panel-needs.js +31 -3
- package/dist/ui/panel-notices.js +2 -1
- package/dist/ui/panel-runtimes.js +4 -3
- package/dist/ui/panel-windows-cli.js +3 -2
- package/dist/ui/runtime-cli-install.js +3 -2
- package/dist/ui/runtime-update-status.js +1 -1
- package/dist/ui/settings-access-strings.js +1 -1
- package/dist/ui/settings-appearance.js +2 -1
- package/dist/ui/settings-guests.js +4 -3
- package/dist/ui/settings-hub-member-address.js +2 -1
- package/dist/ui/settings-hub-setup-strings.js +1 -1
- package/dist/ui/settings-hub-setup.js +2 -1
- package/dist/ui/settings-hub-web-address.js +2 -1
- package/dist/ui/settings-hub.js +2 -1
- package/dist/ui/settings-layout.js +2 -2
- package/dist/ui/settings-named-test.js +16 -16
- package/dist/ui/settings-public-session-strings.js +2 -2
- package/dist/ui/settings-revoke-strings.js +1 -1
- package/dist/ui/settings-shared-strings.js +2 -2
- package/dist/ui/settings-strings.js +40 -40
- package/dist/ui/settings-update.js +2 -1
- package/dist/ui/settings-web-authority.js +2 -1
- package/dist/ui/shared/agent-sheet.js +2 -1
- package/dist/ui/shared/app-session.js +4 -3
- package/dist/ui/shared/app-shell.js +7 -3
- package/dist/ui/shared/app.css +60 -11
- package/dist/ui/shared/chat-strings.js +8 -8
- package/dist/ui/shared/chat-time.js +7 -4
- package/dist/ui/shared/clock-text.js +57 -0
- package/dist/ui/shared/device-roles.js +6 -5
- package/dist/ui/shared/instance-nav.js +31 -2
- package/dist/ui/shared/usage-dialog.js +2 -1
- package/dist/ui/shared/view-strings.js +13 -9
- package/dist/ui/shared/web-authorize.js +3 -2
- package/dist/ui/subagent-row.js +2 -1
- package/dist/web-api.d.ts +15 -2
- package/dist/web-api.js +62 -13
- package/dist/web-api.js.map +1 -1
- package/dist/web-login.d.ts +6 -1
- package/dist/web-login.js +8 -3
- package/dist/web-login.js.map +1 -1
- package/dist/web-session-authorization.d.ts +3 -0
- package/dist/web-session-authorization.js +1 -1
- package/dist/web-session-authorization.js.map +1 -1
- package/package.json +1 -1
package/dist/fleet-manager.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { prepareContactChange } from "./contact-change-proposals.js";
|
|
1
|
+
import { prepareContactChange, shortContactTicketId } from "./contact-change-proposals.js";
|
|
2
|
+
import { contactStateView, ownContactRequestsView } from "./contact-state-view.js";
|
|
2
3
|
import { detectMonitoringPlatform } from './host-monitoring-defaults.js';
|
|
3
4
|
import { SharedDefaultAdoption } from "./shared-default-adoption.js";
|
|
4
5
|
import { scopedDefaultModel } from "./model-defaults.js";
|
|
@@ -23,6 +24,7 @@ import { ContactAuthService } from "./contact-auth-service.js";
|
|
|
23
24
|
import { stageContactFiles } from "./contact-auth-files.js";
|
|
24
25
|
import { ContactOriginClearSchema, ContactPermissionsSchema, sameContactPerson } from "./contact-auth-policy.js";
|
|
25
26
|
import { CLASSIC_RESTRICTED_TOOLS } from "./contact-auth-types.js";
|
|
27
|
+
import { contactPersonKey, normalizeContactPersonKey } from "./contact-auth-store.js";
|
|
26
28
|
import { hubSharingNoticeText } from "./hub-sharing-notice.js";
|
|
27
29
|
import { hubPageSharingSettings } from "./hub-page-sharing-settings.js";
|
|
28
30
|
import { replyPreviews } from "./reply-preview-spec.js";
|
|
@@ -49,7 +51,7 @@ import { loginNoticeMode, normalizeNoticeDelivery, setNoticeMode } from "./notic
|
|
|
49
51
|
import { DEFAULT_REPLY_TRIGGERS } from "./reply-triggers.js";
|
|
50
52
|
import { WorkingRecoveryCoordinator, WORKING_RECOVERY_KIND, buildWorkingRecoveryPrompt } from "./working-recovery.js";
|
|
51
53
|
import { PUBLIC_TUNNEL_TOKEN_ENV, PUBLIC_TUNNEL_TOKEN_HINT, normalizePublicTunnelToken } from "./public-tunnel-config.js";
|
|
52
|
-
import { humanOwnerObjectId, webHumanOrigin } from "./human-delivery-receipts.js";
|
|
54
|
+
import { humanOwnerObjectId, webHumanOrigin, isWebSessionIdentity } from "./human-delivery-receipts.js";
|
|
53
55
|
import { SettingsBaselines } from "./settings-baseline.js";
|
|
54
56
|
import { hubPilotTrustSettings } from "./hub-pilot-trust-settings.js";
|
|
55
57
|
import { hubMembershipSettings } from "./hub-membership-settings.js";
|
|
@@ -280,7 +282,8 @@ import { ThemeStore } from "./web-theme-store.js";
|
|
|
280
282
|
import { OfficeStore, OfficeWriteLimiter } from "./web-office-store.js";
|
|
281
283
|
import { WebPinStore } from "./web-pin-store.js";
|
|
282
284
|
import { OfficeSkinStore } from "./web-office-skins.js";
|
|
283
|
-
import { OfficeActs } from "./web-office-acts.js";
|
|
285
|
+
import { OfficeActs, officeMembers } from "./web-office-acts.js";
|
|
286
|
+
import { characterPlan, ownCharacter } from "./hub-character-plan.js";
|
|
284
287
|
import { OFFICE_PACK_TOOLS, OfficePackTools } from "./web-office-pack-tools.js";
|
|
285
288
|
import { WebAppearance } from "./web-appearance.js";
|
|
286
289
|
import { effectiveAppearanceLimits } from "./web-appearance-limits.js";
|
|
@@ -393,7 +396,7 @@ import { DeviceLoginRequests } from "./web-device-login.js";
|
|
|
393
396
|
import { findSigninKnownEntry, addSigninKnownDevice } from "./web-signin-device.js";
|
|
394
397
|
import { adminKey, HOST_ADMIN_KEY, isOutsideLinkOwner, OUTSIDE_LINK_OWNER, OUTSIDE_LINK_RETRY_MS, OUTSIDE_OWN_CLOSES, outsideDuration, outsideTimer, TOTP_SIGNIN_OVER_PUBLIC_LINK, TOTP_STEP_SECONDS, WEB_REMOTE_ACCESS_FILE, WebRemoteAccess } from "./web-remote-access.js";
|
|
395
398
|
import { evaluateSettingsRole } from "./authority/settings-role.js";
|
|
396
|
-
import { authorityNow, classifyWebPeer, evaluateWebAuthority, HOST_OPERATOR, VERIFIED_SESSION_HOURS, webAuthorityPolicy } from "./authority/web-authority.js";
|
|
399
|
+
import { authorityNow, classifyWebPeer, evaluateGuestIdentity, evaluateWebAuthority, HOST_OPERATOR, VERIFIED_SESSION_HOURS, webAuthorityPolicy } from "./authority/web-authority.js";
|
|
397
400
|
import { AuthorityStateStore, namedLinkLastTurnedOff } from "./authority/authority-state.js";
|
|
398
401
|
import { SessionAuthorizations } from "./authority/session-authorizations.js";
|
|
399
402
|
import { SessionAuthorizationRequests } from "./web-session-authorization.js";
|
|
@@ -635,6 +638,7 @@ function callbackPrefix(callbackData) {
|
|
|
635
638
|
}
|
|
636
639
|
const CLASSIC_BACKEND_SELECTION_TIMEOUT_MS = 60_000;
|
|
637
640
|
const CLASSIC_BACKEND_CALLBACK_PREFIX = "classic-backend:";
|
|
641
|
+
const CLASSIC_MODE_CALLBACK_PREFIX = "classic-mode:";
|
|
638
642
|
const MODEL_SELECT_CALLBACK_PREFIX = "model-select:";
|
|
639
643
|
const EFFORT_SELECT_CALLBACK_PREFIX = "effort-select:";
|
|
640
644
|
const BACKEND_SELECT_CALLBACK_PREFIX = "backend-select:";
|
|
@@ -657,6 +661,13 @@ const KIRO_MIGRATE_CALLBACK_PREFIX = "kiro-migrate:";
|
|
|
657
661
|
/** M-3140: Update now on a Hub-recommended-version notice in General ("hub-update:" + 32 hex + ":update" = 50 bytes). */
|
|
658
662
|
const HUB_UPDATE_CALLBACK_PREFIX = "hub-update:";
|
|
659
663
|
const HUB_SHARING_CALLBACK_PREFIX = "hub-share:";
|
|
664
|
+
/** M-3680: a held contact request's card in General ("contact-ticket:" + 32 hex + ":approve" = 55 bytes, under Telegram's 64). */
|
|
665
|
+
const CONTACT_TICKET_PREFIX = "contact-ticket:";
|
|
666
|
+
/** How many requests' cards are remembered (one card per request; a decided one is forgotten at once). */
|
|
667
|
+
const HELD_CARDS_KEPT = 512;
|
|
668
|
+
/** A held request's card, retired after it was decided elsewhere (the dashboard, Needs you, another card) or closed. */
|
|
669
|
+
const heldCardOutcome = (state) => t(state === "approved" ? "contactHeld.approvedElsewhere"
|
|
670
|
+
: state === "declined" ? "contactHeld.declinedElsewhere" : state === "expired" ? "contactHeld.expired" : "contactHeld.closed");
|
|
660
671
|
const HUB_FLEET_UPDATE_CALLBACK_PREFIX = "hub-fleet-update:";
|
|
661
672
|
const KIRO_RECONCILE_CALLBACK_PREFIX = "kiro-reconcile:";
|
|
662
673
|
/** #2692: a fleet admin's Approve / Reject on an agent's pending skin-pack change, in General. */
|
|
@@ -2798,6 +2809,7 @@ export class FleetManager {
|
|
|
2798
2809
|
scratchDir: agent => isSafeInstanceDirName(agent) ? join(this.dataDir, "workspaces", agent, "hub-files") : null },
|
|
2799
2810
|
attachReports: (handler, failed) => { this.hubReports = handler; this.hubDeliveryFailed = failed; },
|
|
2800
2811
|
attachPrivateQuestions: read => { this.hubPrivateQuestions = read; },
|
|
2812
|
+
attachQuestionSettled: read => { this.hubQuestionSettled = read; },
|
|
2801
2813
|
attachReacts: handler => { this.hubReacts = handler; },
|
|
2802
2814
|
},
|
|
2803
2815
|
attachAgentIntro: port => { this.hubAgentIntro = port; },
|
|
@@ -2823,7 +2835,7 @@ export class FleetManager {
|
|
|
2823
2835
|
: this.getInstanceAdapterId(agent) === actor.adapter_id && this.isFleetAdmin(actor.user_id, actor.adapter_id),
|
|
2824
2836
|
}, caller.agent, receiptId),
|
|
2825
2837
|
attachExposures: api => this.attachHubMemberExposures(api),
|
|
2826
|
-
attachAttention: (read, retry) => this.attachHubExecutionAttention(read, retry),
|
|
2838
|
+
attachAttention: (read, retry, close) => this.attachHubExecutionAttention(read, retry, close),
|
|
2827
2839
|
updates: { idle: () => this.hubUpdateIdle(), busy: () => !!this.webUpdateOwned || isUpdateInProgress(this.dataDir),
|
|
2828
2840
|
canInstall: () => this.hubUpdateCanInstall(), launch: (row, control) => this.launchHubUpdate(row, control),
|
|
2829
2841
|
active: id => this.hubUpdateOwned?.id === id, outcome: row => this.hubUpdateOutcome(row), notify: n => this.recordHubUpdateNotice(n) },
|
|
@@ -2987,7 +2999,53 @@ export class FleetManager {
|
|
|
2987
2999
|
portrait = { key: person ? `card:${person}` : `agent-card:${own}`, load: () => cardPicture({ dataDir: this.dataDir, themeStore: this.themeStore }, name, "portrait") };
|
|
2988
3000
|
}
|
|
2989
3001
|
catch { /* unreadable: no pictures */ }
|
|
2990
|
-
|
|
3002
|
+
let character = null;
|
|
3003
|
+
try {
|
|
3004
|
+
character = this.hubCharacterSource(name);
|
|
3005
|
+
}
|
|
3006
|
+
catch { /* unreadable offices or packs: no character */ }
|
|
3007
|
+
return { disc, portrait, character };
|
|
3008
|
+
}
|
|
3009
|
+
/**
|
|
3010
|
+
* M-3533 R2c: the agent's own character (hub-character-plan.ts ownCharacter): the set its owner gave it by name in
|
|
3011
|
+
* the first of these offices (their own order) holding it, else in the "All" office's pack. The key is that pack's version
|
|
3012
|
+
* and the set's name: a changed pack, set or office changes it; the pictures are read and cut only then.
|
|
3013
|
+
*/
|
|
3014
|
+
hubCharacterSource(name) {
|
|
3015
|
+
const list = this.officeStore.list();
|
|
3016
|
+
if (!list.readable)
|
|
3017
|
+
return null;
|
|
3018
|
+
let chart = null;
|
|
3019
|
+
const holds = (office, agent) => {
|
|
3020
|
+
if (!office.members.length)
|
|
3021
|
+
return true;
|
|
3022
|
+
if (office.members.includes(agent))
|
|
3023
|
+
return true;
|
|
3024
|
+
if (!office.members.some(m => m.startsWith("team:")))
|
|
3025
|
+
return false;
|
|
3026
|
+
chart ??= (() => { const c = this.orgChart(); return { names: Object.keys(c.instances), teams: c.teams }; })();
|
|
3027
|
+
return officeMembers({ members: [...office.members] }, chart).includes(agent);
|
|
3028
|
+
};
|
|
3029
|
+
const hit = ownCharacter({ offices: list.offices, autoSkin: list.autoSkin ?? null, holds, pack: id => this.officeSkins.pack(id) }, name);
|
|
3030
|
+
if (!hit)
|
|
3031
|
+
return null;
|
|
3032
|
+
const sha = this.officeSkins.list().packs.find(p => p.id === hit.packId)?.sha;
|
|
3033
|
+
if (!sha)
|
|
3034
|
+
return null;
|
|
3035
|
+
return { key: `${hit.packId}@${sha}:${hit.set}`, load: () => {
|
|
3036
|
+
const pack = this.officeSkins.pack(hit.packId), files = this.officeSkins.get(hit.packId)?.files;
|
|
3037
|
+
const plan = pack && files ? characterPlan(pack.characters[hit.set]) : null;
|
|
3038
|
+
if (!plan)
|
|
3039
|
+
return null;
|
|
3040
|
+
const pictures = new Map();
|
|
3041
|
+
for (const src of plan.sources) {
|
|
3042
|
+
const id = files[src], bytes = id ? this.officeSkins.picture(hit.packId, id) : null;
|
|
3043
|
+
if (!bytes)
|
|
3044
|
+
return null;
|
|
3045
|
+
pictures.set(src, bytes);
|
|
3046
|
+
}
|
|
3047
|
+
return { plan, pictures };
|
|
3048
|
+
} };
|
|
2991
3049
|
}
|
|
2992
3050
|
/** The actual launch target, including Classic's own effective backend/folder; never aliases a room to a Fleet topic. */
|
|
2993
3051
|
hubAgentConfig(agent) {
|
|
@@ -3250,7 +3308,80 @@ export class FleetManager {
|
|
|
3250
3308
|
contactWindows() {
|
|
3251
3309
|
return this.hubContactWindows ??= new HubContactWindows(join(this.dataDir, "hub-contact-windows.json"));
|
|
3252
3310
|
}
|
|
3253
|
-
|
|
3311
|
+
/**
|
|
3312
|
+
* M-3660: each agent's running Hub answer turn as its daemon tells it (re-told on every connect): a correlation id, or
|
|
3313
|
+
* null for "confirmed none". An agent missing here is unknown (this fleet has not heard from its daemon since it
|
|
3314
|
+
* started): nothing settled lifts its windows then — they hold until the daemon says (Prism #4420 P2-1).
|
|
3315
|
+
*/
|
|
3316
|
+
hubAnswerTurns = new Map();
|
|
3317
|
+
/**
|
|
3318
|
+
* M-3660: the agent's daemon is about to write a Hub question into its idle pane: the answer turn's window opens (none for
|
|
3319
|
+
* a share that opted out). A window that cannot be saved still holds in memory: fail closed.
|
|
3320
|
+
*/
|
|
3321
|
+
hubQuestionInput(agent, correlationId, contactLimit = true) {
|
|
3322
|
+
this.hubAnswerTurns.set(agent, correlationId);
|
|
3323
|
+
if (!contactLimit)
|
|
3324
|
+
return;
|
|
3325
|
+
try {
|
|
3326
|
+
this.contactWindows().begin(agent, correlationId);
|
|
3327
|
+
}
|
|
3328
|
+
catch (err) {
|
|
3329
|
+
this.logger.warn({ err, agent }, "Hub contact window could not be saved; it holds until this fleet restarts or it expires");
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
/** M-3660: that answer turn is over (its idle edge, or the next turn's write): the window closes, whatever came of it. */
|
|
3333
|
+
hubQuestionTurnEnded(agent, correlationId) {
|
|
3334
|
+
if (this.hubAnswerTurns.get(agent) === correlationId)
|
|
3335
|
+
this.hubAnswerTurns.set(agent, null);
|
|
3336
|
+
try {
|
|
3337
|
+
this.contactWindows().answered(agent, correlationId);
|
|
3338
|
+
}
|
|
3339
|
+
catch (err) {
|
|
3340
|
+
this.logger.warn({ err, agent }, "Hub contact window could not be closed; it will expire");
|
|
3341
|
+
}
|
|
3342
|
+
}
|
|
3343
|
+
/**
|
|
3344
|
+
* M-3660: what the daemon says on (re)connect — the turn it is answering now, or none. A lost hub_question_input or
|
|
3345
|
+
* hub_question_turn_ended (a stale connection, a fleet or daemon restart) is made good here: with no turn running every
|
|
3346
|
+
* window of the agent ends; with one, that one holds and the rest end.
|
|
3347
|
+
*/
|
|
3348
|
+
hubQuestionTurnState(agent, correlationId, contactLimit = true) {
|
|
3349
|
+
try {
|
|
3350
|
+
this.contactWindows().closeAgent(agent, correlationId ?? undefined);
|
|
3351
|
+
}
|
|
3352
|
+
catch (err) {
|
|
3353
|
+
this.logger.warn({ err, agent }, "Hub contact windows could not be reconciled; they will expire");
|
|
3354
|
+
}
|
|
3355
|
+
if (correlationId)
|
|
3356
|
+
this.hubQuestionInput(agent, correlationId, contactLimit);
|
|
3357
|
+
else
|
|
3358
|
+
this.hubAnswerTurns.set(agent, null);
|
|
3359
|
+
}
|
|
3360
|
+
/** M-3660: a daemon's Hub turn signal (from its current connection). "unknown" (an unreadable turn record) changes nothing. */
|
|
3361
|
+
hubTurnSignal(agent, msg) {
|
|
3362
|
+
const cid = typeof msg.correlationId === "string" && /^hub-[A-Za-z0-9-]+$/.test(msg.correlationId) ? msg.correlationId : null;
|
|
3363
|
+
if (msg.type === "hub_question_turn_state") {
|
|
3364
|
+
if (msg.unknown !== true && (cid || msg.correlationId === null))
|
|
3365
|
+
this.hubQuestionTurnState(agent, cid, msg.contactLimit !== false);
|
|
3366
|
+
}
|
|
3367
|
+
else if (cid && msg.type === "hub_question_input")
|
|
3368
|
+
this.hubQuestionInput(agent, cid, msg.contactLimit !== false);
|
|
3369
|
+
else if (cid && msg.type === "hub_question_turn_ended")
|
|
3370
|
+
this.hubQuestionTurnEnded(agent, cid);
|
|
3371
|
+
}
|
|
3372
|
+
/** M-3660: the agent's daemon has told this fleet its current turn, and it is not this question (unknown is never "none"). */
|
|
3373
|
+
hubAnswerTurnKnownNone(agent, correlationId) {
|
|
3374
|
+
return this.hubAnswerTurns.has(agent) && this.hubAnswerTurns.get(agent) !== correlationId;
|
|
3375
|
+
}
|
|
3376
|
+
/** M-3660: a settled question lifts its window only outside its own running answer turn; inside it, the turn's end does. */
|
|
3377
|
+
hubSettledOutsideTurn() {
|
|
3378
|
+
const settled = this.hubQuestionSettled;
|
|
3379
|
+
return settled ? (agent, correlationId) => this.hubAnswerTurnKnownNone(agent, correlationId) && settled(agent, correlationId) : undefined;
|
|
3380
|
+
}
|
|
3381
|
+
/** M-3660: the member side's "this question is no longer being answered" reader (null: no member service attached). */
|
|
3382
|
+
hubQuestionSettled = null;
|
|
3383
|
+
hubContactRestricted(agent) { return this.contactWindows().restricted(agent, this.hubSettledOutsideTurn()); }
|
|
3384
|
+
hubContactQuestion(agent) { return this.contactWindows().restrictingQuestion(agent, this.hubSettledOutsideTurn()); }
|
|
3254
3385
|
/**
|
|
3255
3386
|
* M-3313 (#4145 for the Hub): what a Hub question or room notification hands the agent, with this fleet's sign-in
|
|
3256
3387
|
* access token hidden (exact match, as a chat's). The live one is taken back and replaced, and the sign-in's chat told.
|
|
@@ -3305,6 +3436,9 @@ export class FleetManager {
|
|
|
3305
3436
|
};
|
|
3306
3437
|
if (input.roomContextGeneration)
|
|
3307
3438
|
ipcMeta.hub_room_context_generation = input.roomContextGeneration;
|
|
3439
|
+
// M-3660: the share's opt-out travels with the question; its daemon's hub_question_input then opens no window.
|
|
3440
|
+
if (input.contactLimit === false)
|
|
3441
|
+
ipcMeta.hub_contact_limit = "off";
|
|
3308
3442
|
const result = await this.deliverToInstance(input.agent, { type: "fleet_inbound", targetSession: input.agent, content: this.screenHubText(input.text), meta: ipcMeta }, { isCrossInstance: true, stillCurrent: input.stillCurrent, beforeInput: async () => {
|
|
3309
3443
|
const classic = this.isClassicInstance(input.agent);
|
|
3310
3444
|
// A busy Classic room must finish its public turn first; never force a private question into that turn's queue.
|
|
@@ -3323,9 +3457,9 @@ export class FleetManager {
|
|
|
3323
3457
|
return false;
|
|
3324
3458
|
this.classicPrivacy().begin(input.agent, input.correlationId);
|
|
3325
3459
|
}
|
|
3326
|
-
//
|
|
3327
|
-
|
|
3328
|
-
|
|
3460
|
+
// M-3660: the window covers only the turn that answers the question. The agent's daemon (Classic rooms' too)
|
|
3461
|
+
// writes it only into an idle pane, as a turn of its own, and says so just before the write (hub_question_input),
|
|
3462
|
+
// so a question waiting behind another turn — or never written — opens nothing.
|
|
3329
3463
|
return input.stillCurrent();
|
|
3330
3464
|
} });
|
|
3331
3465
|
return result !== false;
|
|
@@ -3453,7 +3587,8 @@ export class FleetManager {
|
|
|
3453
3587
|
if (!result)
|
|
3454
3588
|
return null;
|
|
3455
3589
|
return result.then(outcome => {
|
|
3456
|
-
|
|
3590
|
+
// M-3660: an accepted answer inside its own running answer turn does not lift it: the turn's end does.
|
|
3591
|
+
if (outcome.ok && this.hubAnswerTurnKnownNone(input.caller, input.correlationId)) {
|
|
3457
3592
|
try {
|
|
3458
3593
|
this.contactWindows().answered(input.caller, input.correlationId);
|
|
3459
3594
|
}
|
|
@@ -3742,6 +3877,7 @@ export class FleetManager {
|
|
|
3742
3877
|
signInKeepAlive = null;
|
|
3743
3878
|
hubExecutionAttention = null;
|
|
3744
3879
|
/** M-3632: the member's "Try again" for a held Hub question (null while no member runs). */
|
|
3880
|
+
hubHeldClose = null;
|
|
3745
3881
|
hubHeldRetry = null;
|
|
3746
3882
|
missedOfflineStore = null;
|
|
3747
3883
|
configHistory = null;
|
|
@@ -4860,7 +4996,7 @@ export class FleetManager {
|
|
|
4860
4996
|
} };
|
|
4861
4997
|
}
|
|
4862
4998
|
/**
|
|
4863
|
-
* alpha.2 (M-2300; #2973's agent requests,
|
|
4999
|
+
* alpha.2 (M-2300; #2973's agent requests, a colleague's §6): on a fleet with no chat connection there is no General to
|
|
4864
5000
|
* post an agent's Windows request in — it waited for `agend settings confirm` on the host. Its owner (decision
|
|
4865
5001
|
* 28c2d3a3: the `agend web --code` session on this computer, web-verified) now sees and decides it from the web's
|
|
4866
5002
|
* Needs you. The authority is asked from the request each time, and again at execution by the store (`current`):
|
|
@@ -5955,6 +6091,8 @@ export class FleetManager {
|
|
|
5955
6091
|
const badge = row?.payload.contactTicket;
|
|
5956
6092
|
const ticket = badge?.id ? outbox.contactAuthorizations.get(badge.id) : undefined;
|
|
5957
6093
|
if (ticket && ticket.deliveryId === row?.deliveryId) {
|
|
6094
|
+
// M-3716: the approval notice waits for this delivery to settle.
|
|
6095
|
+
queueMicrotask(() => this.sweepContactAuthorizationOutcomes());
|
|
5958
6096
|
const state = event.state === "delivered" ? "delivered" : ["failed", "uncertain", "cancelled", "reconciliation_pending"].includes(event.state ?? "") ? "unknown" : "approved";
|
|
5959
6097
|
for (const instance of new Set([ticket.source, ticket.target])) {
|
|
5960
6098
|
this.webChatHistory?.updateContactTicket(instance, ticket.id, state);
|
|
@@ -6164,14 +6302,30 @@ export class FleetManager {
|
|
|
6164
6302
|
throw Error("unavailable");
|
|
6165
6303
|
return incarnation;
|
|
6166
6304
|
}
|
|
6305
|
+
/** Eligible connections share a platform; the current Fleet-admin gate still decides each user's role. */
|
|
6306
|
+
contactAdminAdapterIds(adapter) {
|
|
6307
|
+
const channels = this.fleetConfig?.channels ?? (this.fleetConfig?.channel ? [this.fleetConfig.channel] : []);
|
|
6308
|
+
return [...new Set([adapter.id, ...channels.filter(ch => ch.type === adapter.type).map(ch => ch.id ?? ch.type)])];
|
|
6309
|
+
}
|
|
6310
|
+
/** Contact permissions identify a person by platform/user; sibling bot connections do not create new people. */
|
|
6311
|
+
contactDefaultApprovers(name) {
|
|
6312
|
+
const adapter = this.contactAdapter(name);
|
|
6313
|
+
if (!adapter || (adapter.type !== "discord" && adapter.type !== "telegram"))
|
|
6314
|
+
return [];
|
|
6315
|
+
const people = this.contactAdminAdapterIds(adapter).flatMap(id => (this.adminListOf(id) ?? []).map(userId => ({
|
|
6316
|
+
platform: adapter.type, adapterId: id, userId, label: userId
|
|
6317
|
+
})));
|
|
6318
|
+
return [...new Map(people.map(person => [contactPersonKey(person), person])).values()];
|
|
6319
|
+
}
|
|
6167
6320
|
contactAdminOf(name, actor) {
|
|
6168
6321
|
if (actor.platform === "host" && actor.adapterId === "host" && actor.userId === "operator")
|
|
6169
6322
|
return true;
|
|
6170
6323
|
const adapter = this.contactAdapter(name);
|
|
6171
|
-
if (!adapter || actor.
|
|
6324
|
+
if (!adapter || actor.platform !== adapter.type)
|
|
6172
6325
|
return false;
|
|
6173
|
-
|
|
6174
|
-
|
|
6326
|
+
if (this.contactAdminAdapterIds(adapter).some(id => this.isFleetAdmin(actor.userId, id)))
|
|
6327
|
+
return true;
|
|
6328
|
+
return !!this.contactRoom(name) && this.classicChannels?.isAdmin(actor.userId) === true;
|
|
6175
6329
|
}
|
|
6176
6330
|
contactService() {
|
|
6177
6331
|
this.ensureDeliveryOutbox();
|
|
@@ -6179,12 +6333,7 @@ export class FleetManager {
|
|
|
6179
6333
|
restricted: name => this.contactRoom(name)?.restrictedMode === true,
|
|
6180
6334
|
legacyClassic: name => !!this.contactRoom(name) && this.contactRoom(name)?.restrictedMode !== true,
|
|
6181
6335
|
adminOf: (name, actor) => this.contactAdminOf(name, actor),
|
|
6182
|
-
defaultApprovers: name =>
|
|
6183
|
-
const adapter = this.contactAdapter(name);
|
|
6184
|
-
if (!adapter || (adapter.type !== "discord" && adapter.type !== "telegram"))
|
|
6185
|
-
return [];
|
|
6186
|
-
return (this.adminListOf(adapter.id) ?? []).map(userId => ({ platform: adapter.type, adapterId: adapter.id, userId, label: userId }));
|
|
6187
|
-
},
|
|
6336
|
+
defaultApprovers: name => this.contactDefaultApprovers(name),
|
|
6188
6337
|
generation: name => this.contactGeneration(name),
|
|
6189
6338
|
hubRestricted: name => this.hubContactRestricted(name),
|
|
6190
6339
|
delivered: ticket => !!ticket.deliveryId && this.deliveryOutbox.get(ticket.deliveryId)?.state === "delivered",
|
|
@@ -6213,6 +6362,15 @@ export class FleetManager {
|
|
|
6213
6362
|
sender: ticket.source, text: ticket.message, ts: new Date().toISOString(), contactTicket: { id: ticket.id, state: "approved" } });
|
|
6214
6363
|
}
|
|
6215
6364
|
this.emitSseEvent("contact-auth", { instance, ...(ticketId ? { ticketId } : {}), revision });
|
|
6365
|
+
// M-3680: a card never stands in the way of the hold (or a decision) that called this.
|
|
6366
|
+
if (ticket) {
|
|
6367
|
+
try {
|
|
6368
|
+
this.syncHeldTicketCard(ticket);
|
|
6369
|
+
}
|
|
6370
|
+
catch (err) {
|
|
6371
|
+
this.logger?.warn?.({ err: err?.message, ticket: ticket.id }, "Held contact request card failed");
|
|
6372
|
+
}
|
|
6373
|
+
}
|
|
6216
6374
|
this.needsYou?.poke();
|
|
6217
6375
|
this.emitSseEvent("needs", { items: this.needsYouItems() });
|
|
6218
6376
|
},
|
|
@@ -6340,6 +6498,26 @@ export class FleetManager {
|
|
|
6340
6498
|
return this.contactPermissions(name, actor);
|
|
6341
6499
|
}
|
|
6342
6500
|
/** General can propose only. The platform callback supplies the human actor. */
|
|
6501
|
+
/** M-3693: what contact permissions hold now, for General (read-only; no write, no identity computed here). */
|
|
6502
|
+
contactState(agent) {
|
|
6503
|
+
const store = this.contactService().host.store;
|
|
6504
|
+
const names = [...new Set([...Object.keys(this.fleetConfig?.instances ?? {}), ...(this.classicChannels?.getAll?.() ?? []).map(room => room.instanceName)])];
|
|
6505
|
+
return contactStateView({
|
|
6506
|
+
store, names: () => names, now: () => Date.now(), generation: n => this.contactGeneration(n),
|
|
6507
|
+
label: n => this.fleetConfig?.instances[n]?.display_name || this.contactRoom(n)?.displayName || n,
|
|
6508
|
+
roomMode: n => { const room = this.contactRoom(n); return room ? room.restrictedMode ? "restricted" : "legacy" : undefined; },
|
|
6509
|
+
}, agent ? { agent } : {});
|
|
6510
|
+
}
|
|
6511
|
+
/** M-3716: the caller's OWN held requests (delivery_status { held_requests: true }); the caller is the authenticated agent. */
|
|
6512
|
+
ownContactRequests(agent) {
|
|
6513
|
+
const outbox = this.deliveryOutbox;
|
|
6514
|
+
if (!outbox?.isOpen)
|
|
6515
|
+
return { requests: [], note: "Contact requests are unavailable right now." };
|
|
6516
|
+
return ownContactRequestsView(outbox.contactAuthorizations.requestsBy(agent), {
|
|
6517
|
+
label: n => this.fleetConfig?.instances[n]?.display_name || this.contactRoom(n)?.displayName || n,
|
|
6518
|
+
delivery: ticket => ticket.deliveryId ? outbox.get(ticket.deliveryId)?.state : undefined,
|
|
6519
|
+
});
|
|
6520
|
+
}
|
|
6343
6521
|
async requestContactChange(requester, raw, callerCurrent) {
|
|
6344
6522
|
if (!callerCurrent() || this.fleetConfig?.instances[requester]?.general_topic !== true)
|
|
6345
6523
|
throw Error("general-only");
|
|
@@ -6426,6 +6604,123 @@ export class FleetManager {
|
|
|
6426
6604
|
await this.retireNonceButtons(entry, entry.messageId ?? data.messageId, text);
|
|
6427
6605
|
return true;
|
|
6428
6606
|
}
|
|
6607
|
+
/**
|
|
6608
|
+
* M-3680 (the user, 11-25): a fleet agent's send held for approval reaches an administrator in General on the target's
|
|
6609
|
+
* Discord or Telegram, as a card with Approve once / Decline — until then a held request had no chat path (the live
|
|
6610
|
+
* Needs you message lists it without buttons). One card per request. Whoever clicks must be one who may decide it
|
|
6611
|
+
* (ContactAuthService.view(...).canDecide, read at the click); the decision is theirs, never the bot's. A request decided
|
|
6612
|
+
* anywhere else (the web, another card) retires its card. #4448 (R21079937): a ClassicBot room's request to a fleet agent
|
|
6613
|
+
* gets the same card, in the General of the target's connection; a room's request to anything else gets none.
|
|
6614
|
+
*/
|
|
6615
|
+
/** Requests whose card was posted or tried: forgotten when the request is decided, and at most HELD_CARDS_KEPT. */
|
|
6616
|
+
heldTicketCards;
|
|
6617
|
+
syncHeldTicketCard(ticket) {
|
|
6618
|
+
const posted = (this.heldTicketCards ??= new Set());
|
|
6619
|
+
if (ticket.state !== "pending") {
|
|
6620
|
+
posted.delete(ticket.id);
|
|
6621
|
+
for (const [nonce, entry] of [...(this.pendingNonceButtons ?? [])]) {
|
|
6622
|
+
if (entry.prefix !== CONTACT_TICKET_PREFIX || entry.contactTicketId !== ticket.id)
|
|
6623
|
+
continue;
|
|
6624
|
+
this.pendingNonceButtons.delete(nonce);
|
|
6625
|
+
if (entry.timer)
|
|
6626
|
+
clearTimeout(entry.timer);
|
|
6627
|
+
// #4438 review: a card still being posted has no message yet; postHeldTicketCard retires it once it has one.
|
|
6628
|
+
if (entry.messageId)
|
|
6629
|
+
void this.retireNonceButtons(entry, entry.messageId, heldCardOutcome(ticket.state));
|
|
6630
|
+
}
|
|
6631
|
+
return;
|
|
6632
|
+
}
|
|
6633
|
+
// A fleet agent's send, or (R21079937, 11-25: a room's request was in no list and had no card) a ClassicBot room's send
|
|
6634
|
+
// to a fleet agent — the card goes to the General of the TARGET's connection either way (postHeldTicketCard).
|
|
6635
|
+
const room = !this.fleetConfig?.instances[ticket.source] && !!this.contactRoom(ticket.source);
|
|
6636
|
+
if (posted.has(ticket.id) || (!this.fleetConfig?.instances[ticket.source] && !room) || (room && !this.fleetConfig?.instances[ticket.target]))
|
|
6637
|
+
return;
|
|
6638
|
+
posted.add(ticket.id);
|
|
6639
|
+
for (const old of posted) {
|
|
6640
|
+
if (posted.size <= HELD_CARDS_KEPT)
|
|
6641
|
+
break;
|
|
6642
|
+
posted.delete(old);
|
|
6643
|
+
}
|
|
6644
|
+
void this.postHeldTicketCard(ticket).catch((err) => this.logger?.warn?.({ err: err?.message, ticket: ticket.id }, "Could not post a held contact request to General"));
|
|
6645
|
+
}
|
|
6646
|
+
async postHeldTicketCard(ticket) {
|
|
6647
|
+
const adapter = this.contactAdapter(ticket.target);
|
|
6648
|
+
if (!adapter || (adapter.type !== "discord" && adapter.type !== "telegram"))
|
|
6649
|
+
return;
|
|
6650
|
+
const routes = Object.keys(this.fleetConfig?.instances ?? {}).flatMap(n => {
|
|
6651
|
+
const route = this.settingsGeneralRoute(n, adapter.type, new Set());
|
|
6652
|
+
return route && route.adapterId === adapter.id && route.adapter === adapter ? [{ name: n, ...route }] : [];
|
|
6653
|
+
});
|
|
6654
|
+
if (routes.length !== 1) {
|
|
6655
|
+
this.logger.info({ ticket: ticket.id, routes: routes.length }, "No single General for a held contact request's card");
|
|
6656
|
+
return;
|
|
6657
|
+
}
|
|
6658
|
+
// A ClassicBot room by its own name (its display name, else its channel's), as Fleet lists it.
|
|
6659
|
+
const route = routes[0], label = (n) => this.fleetConfig?.instances[n]?.display_name || this.contactRoom(n)?.displayName || this.contactRoom(n)?.name || n;
|
|
6660
|
+
const shortId = /^R[a-f0-9]{8}-/.test(ticket.id) ? ticket.id.slice(0, 9) : ticket.id;
|
|
6661
|
+
const left = Date.parse(ticket.expiresAt) - Date.now();
|
|
6662
|
+
const text = ticket.message.length > 300 ? `${ticket.message.slice(0, 299)}…` : ticket.message;
|
|
6663
|
+
const posting = this.postNonceButtonPromptOrThrow({ prefix: CONTACT_TICKET_PREFIX, alertType: "clear_confirm", instanceName: route.name,
|
|
6664
|
+
adapter: route.adapter, adapterId: route.adapterId, chatId: route.chatId, threadId: route.topic,
|
|
6665
|
+
message: [t("contactHeld.title", label(ticket.source), label(ticket.target)), `> ${text.replace(/\n+/g, " ")}`,
|
|
6666
|
+
t("contactHeld.meta", shortId, ticket.verb, left < 2 * 3_600_000 ? t("contactHeld.minutes", Math.max(1, Math.round(left / 60_000))) : t("contactHeld.hours", Math.round(left / 3_600_000))),
|
|
6667
|
+
t("contactHeld.hint")].join("\n"),
|
|
6668
|
+
choices: [{ action: "approve", label: t("contactHeld.approve") }, { action: "decline", label: t("contactHeld.decline") }],
|
|
6669
|
+
expiredText: t("contactHeld.expired"), timeoutMs: Math.max(60_000, Math.min(left, 24 * 3_600_000)),
|
|
6670
|
+
extra: { contactTicketId: ticket.id } });
|
|
6671
|
+
// The entry is armed before the platform answers (postNonceButtonPromptOrThrow sets it synchronously).
|
|
6672
|
+
const entry = [...this.pendingNonceButtons.values()].find(e => e.prefix === CONTACT_TICKET_PREFIX && e.contactTicketId === ticket.id);
|
|
6673
|
+
const nonce = await posting;
|
|
6674
|
+
// #4438 review: decided elsewhere, or expired, while the card was being posted — it had no message to retire then; it
|
|
6675
|
+
// has one now. A card still armed for a request still waiting stays.
|
|
6676
|
+
if (!entry?.messageId)
|
|
6677
|
+
return;
|
|
6678
|
+
const fresh = this.contactService().host.store.get(ticket.id), armed = this.pendingNonceButtons.get(nonce) === entry;
|
|
6679
|
+
if (armed && fresh?.state === "pending")
|
|
6680
|
+
return;
|
|
6681
|
+
if (armed) {
|
|
6682
|
+
this.pendingNonceButtons.delete(nonce);
|
|
6683
|
+
if (entry.timer)
|
|
6684
|
+
clearTimeout(entry.timer);
|
|
6685
|
+
}
|
|
6686
|
+
await this.retireNonceButtons(entry, entry.messageId, !fresh || fresh.state === "pending" ? t("contactHeld.expired") : heldCardOutcome(fresh.state));
|
|
6687
|
+
}
|
|
6688
|
+
async handleContactTicketCallback(data, adapterId, adapter) {
|
|
6689
|
+
if (!data.callbackData.startsWith(CONTACT_TICKET_PREFIX))
|
|
6690
|
+
return false;
|
|
6691
|
+
const person = data.userId && adapter && this.adapters.get(adapterId) === adapter && adapter.id === adapterId
|
|
6692
|
+
&& (adapter.type === "discord" || adapter.type === "telegram") && data.userId !== adapter.getBotUserId?.()
|
|
6693
|
+
? { platform: adapter.type, adapterId, userId: data.userId, label: data.username || data.userId } : null;
|
|
6694
|
+
const service = this.contactService();
|
|
6695
|
+
const mayDecide = (entry) => {
|
|
6696
|
+
const ticket = person && entry.contactTicketId ? service.host.store.get(entry.contactTicketId) : undefined;
|
|
6697
|
+
try {
|
|
6698
|
+
return !!ticket && !!person && service.view(ticket, person).canDecide;
|
|
6699
|
+
}
|
|
6700
|
+
catch {
|
|
6701
|
+
return false;
|
|
6702
|
+
}
|
|
6703
|
+
};
|
|
6704
|
+
const claimed = this.consumeNonceCallback(CONTACT_TICKET_PREFIX, /^contact-ticket:([0-9a-f]{32}):(approve|decline)$/, data, adapterId, adapter, undefined, (_user, entry) => !!entry.messageId && !this.webPromptClicks.has(data) && mayDecide(entry));
|
|
6705
|
+
if (claimed === null)
|
|
6706
|
+
return false;
|
|
6707
|
+
if (claimed === "consumed")
|
|
6708
|
+
return true;
|
|
6709
|
+
const { entry, action } = claimed;
|
|
6710
|
+
const ticket = entry.contactTicketId ? service.host.store.get(entry.contactTicketId) : undefined;
|
|
6711
|
+
let text = t("contactHeld.closed");
|
|
6712
|
+
if (ticket?.state === "pending" && person) {
|
|
6713
|
+
try {
|
|
6714
|
+
const decided = this.decideContactAuthorization(ticket.id, { revision: ticket.revision, decision: action === "approve" ? "approve-once" : "decline" }, person);
|
|
6715
|
+
text = t(decided.state === "approved" ? "contactHeld.approved" : "contactHeld.declined", person.label);
|
|
6716
|
+
}
|
|
6717
|
+
catch {
|
|
6718
|
+
text = t("contactHeld.failed");
|
|
6719
|
+
}
|
|
6720
|
+
}
|
|
6721
|
+
await this.retireNonceButtons(entry, entry.messageId ?? data.messageId, text);
|
|
6722
|
+
return true;
|
|
6723
|
+
}
|
|
6429
6724
|
contactAuthorization(id, actor) {
|
|
6430
6725
|
const service = this.contactService(), ticket = service.host.store.get(id);
|
|
6431
6726
|
if (!ticket)
|
|
@@ -6439,7 +6734,7 @@ export class FleetManager {
|
|
|
6439
6734
|
const view = service.view(ticket, actor);
|
|
6440
6735
|
if (filter.status && view.state !== filter.status)
|
|
6441
6736
|
return [];
|
|
6442
|
-
if (filter.person && !view.origin.people.some(person =>
|
|
6737
|
+
if (filter.person && !view.origin.people.some(person => contactPersonKey(person) === normalizeContactPersonKey(filter.person ?? "")))
|
|
6443
6738
|
return [];
|
|
6444
6739
|
return [view];
|
|
6445
6740
|
}
|
|
@@ -6457,14 +6752,30 @@ export class FleetManager {
|
|
|
6457
6752
|
if (!outbox?.isOpen || this.shuttingDown)
|
|
6458
6753
|
return;
|
|
6459
6754
|
try {
|
|
6460
|
-
outbox.contactAuthorizations.notifyOutcomes(ticket => {
|
|
6461
|
-
|
|
6462
|
-
|
|
6755
|
+
outbox.contactAuthorizations.notifyOutcomes((ticket, outcome) => {
|
|
6756
|
+
if (outcome === "declined" || outcome === "expired") {
|
|
6757
|
+
outbox.admitSystemNotice(ticket.source, `contact-outcome:${ticket.id}`, t(outcome === "declined" ? "contact.noticeDeclined" : "contact.noticeExpired", ticket.id, ticket.target));
|
|
6758
|
+
return;
|
|
6759
|
+
}
|
|
6760
|
+
// M-3716 (the user, 11-25): the requester learns who approved it, when, and whether the target has it.
|
|
6761
|
+
const by = ticket.decidedBy, when = ticket.decidedAt ? `${ticket.decidedAt.slice(0, 16).replace("T", " ")} UTC` : "";
|
|
6762
|
+
const who = !by ? "?" : by.platform === "host" ? t("contactProposal.host")
|
|
6763
|
+
: `${by.label}${getLocale() === "zh-TW" ? "(" : " ("}${by.platform === "discord" ? "Discord" : "Telegram"}${getLocale() === "zh-TW" ? ")" : ")"}`;
|
|
6764
|
+
outbox.admitSystemNotice(ticket.source, `contact-approval:${ticket.id}`, t(`contact.noticeApproved_${outcome}`, shortContactTicketId(ticket.id), ticket.target, who, when));
|
|
6765
|
+
}, ticket => ticket.deliveryId ? outbox.get(ticket.deliveryId)?.state : undefined);
|
|
6463
6766
|
}
|
|
6464
6767
|
catch (err) {
|
|
6465
6768
|
this.logger.error({ err }, "Contact outcome notice sweep failed; durable state will retry");
|
|
6466
6769
|
}
|
|
6467
6770
|
}
|
|
6771
|
+
/**
|
|
6772
|
+
* M-3710: how many contact requests wait, and since when — no ids, people or text. Needs you tells an admin session with
|
|
6773
|
+
* no verified person behind it (contactActor null) that they exist, so a request is never silently missing there.
|
|
6774
|
+
*/
|
|
6775
|
+
contactPendingCount() {
|
|
6776
|
+
const pending = this.contactService().host.store.pending();
|
|
6777
|
+
return { count: pending.length, since: pending.reduce((at, ticket) => Math.min(at, Date.parse(ticket.createdAt) || at), Date.now()) };
|
|
6778
|
+
}
|
|
6468
6779
|
contactNeeds(actor) {
|
|
6469
6780
|
const service = this.contactService();
|
|
6470
6781
|
const pending = service.host.store.pending()
|
|
@@ -6600,7 +6911,7 @@ export class FleetManager {
|
|
|
6600
6911
|
if (!item.authority || !state)
|
|
6601
6912
|
return item;
|
|
6602
6913
|
const authority = this.receiptAuthorityNow(item.authority, state);
|
|
6603
|
-
return { ...item, authority, ...(authority.downgraded ? { source_instance: "human:web:unknown" } : {}) };
|
|
6914
|
+
return { ...item, authority, ...(authority.downgraded && !isWebSessionIdentity(item.origin?.web_identity) ? { source_instance: "human:web:unknown" } : {}) };
|
|
6604
6915
|
};
|
|
6605
6916
|
// #1641: a sender that sees only `queued` cannot tell "next in line" from "the target is stuck": say which.
|
|
6606
6917
|
return {
|
|
@@ -7545,6 +7856,15 @@ export class FleetManager {
|
|
|
7545
7856
|
clearUpdateMarker(this.dataDir);
|
|
7546
7857
|
}
|
|
7547
7858
|
// ── ArchiverContext bridge ────────────────────────────────────────────
|
|
7859
|
+
/** M-3674: the last turn another agent started for `name` (the delivery outbox), ISO or null; never throws. */
|
|
7860
|
+
lastAgentTurnOf(name) {
|
|
7861
|
+
try {
|
|
7862
|
+
return this.deliveryOutbox?.lastAgentTurn(name) ?? null;
|
|
7863
|
+
}
|
|
7864
|
+
catch {
|
|
7865
|
+
return null;
|
|
7866
|
+
}
|
|
7867
|
+
}
|
|
7548
7868
|
lastActivityMs(name) {
|
|
7549
7869
|
return this.lastActivity.get(name) ?? 0;
|
|
7550
7870
|
}
|
|
@@ -9320,10 +9640,11 @@ export class FleetManager {
|
|
|
9320
9640
|
throw Error("Contact origin storage unavailable");
|
|
9321
9641
|
if (contactStore && (this.contactRoom(instanceName)?.restrictedMode === true || contactStore.origin(instanceName))) {
|
|
9322
9642
|
const authority = origin.authority;
|
|
9323
|
-
const
|
|
9643
|
+
const identity = origin.platform === "web" && isWebSessionIdentity(origin.web_identity) ? origin.web_identity : undefined;
|
|
9644
|
+
const actor = origin.platform === "web" ? identity ?? (authority?.kind === "web-verified" ? authority.actor : null)
|
|
9324
9645
|
: { adapter_id: origin.adapter_id, user_id: origin.user_id };
|
|
9325
9646
|
const adapter = actor?.adapter_id ? this.adapters.get(actor.adapter_id) : undefined;
|
|
9326
|
-
const platform = origin.platform === "web" ? adapter?.type : origin.platform;
|
|
9647
|
+
const platform = origin.platform === "web" ? identity?.platform ?? adapter?.type : origin.platform;
|
|
9327
9648
|
const person = actor?.adapter_id && actor.user_id
|
|
9328
9649
|
&& (platform === "discord" || platform === "telegram" || (actor.adapter_id === "host" && actor.user_id === "operator"))
|
|
9329
9650
|
? { platform: actor.adapter_id === "host" ? "host" : platform,
|
|
@@ -9519,6 +9840,16 @@ export class FleetManager {
|
|
|
9519
9840
|
isFleetAdmin(userId, adapterId) {
|
|
9520
9841
|
return this.adminGate(userId, adapterId) === "ok";
|
|
9521
9842
|
}
|
|
9843
|
+
/**
|
|
9844
|
+
* Free mode at /start is the fleet-admin allowlist of the adapter that owns the room (adminGate).
|
|
9845
|
+
* A ClassicBot admin (`classicBot.yaml` admin_users) is not enough. A stub with no fleet and no worlds
|
|
9846
|
+
* is not an admin: the menu offers Restricted only.
|
|
9847
|
+
*/
|
|
9848
|
+
canChooseFreeMode(userId, adapterId) {
|
|
9849
|
+
if (!this.fleetConfig && !this.worlds)
|
|
9850
|
+
return false;
|
|
9851
|
+
return this.adminGate(userId, adapterId) === "ok";
|
|
9852
|
+
}
|
|
9522
9853
|
/** Whether this adapter has any fleet admin at all (an empty allowlist means the admin commands are off). */
|
|
9523
9854
|
hasFleetAdmins(adapterId) {
|
|
9524
9855
|
return (this.adminListOf(adapterId)?.length ?? 0) > 0;
|
|
@@ -12470,7 +12801,8 @@ export class FleetManager {
|
|
|
12470
12801
|
// guest there) — most guests are not on the host's network. Its closing withdraws that audience (revokeAudience).
|
|
12471
12802
|
const open = this.publicWebLink?.openSignin() ?? null;
|
|
12472
12803
|
// One code per account (a new one replaces only its own); at the cap, refused — never another guest's evicted.
|
|
12473
|
-
|
|
12804
|
+
// M-3651: private — the account's DM, else this slash command's ephemeral answer, else withdrawn (below): verified at sign-in.
|
|
12805
|
+
const login = codes.issue({ epoch: tokenEpoch(token), audiences: ["local", ...(open ? [open.exposureId] : [])], private: true,
|
|
12474
12806
|
recipient: { adapterId: owner.adapterId, userId: owner.userId, ...(ask.username ? { username: ask.username } : {}) } });
|
|
12475
12807
|
if (!login) {
|
|
12476
12808
|
await say(t("web.guest_busy"));
|
|
@@ -12639,7 +12971,7 @@ export class FleetManager {
|
|
|
12639
12971
|
const current = () => !this.shuttingDown && this.webToken === token && this.adapters.get(account.adapterId) === adapter
|
|
12640
12972
|
&& this.guestRevokes === revokes && (this.guestAccountRevokes.get(key) ?? 0) === accountRevokes && this.guestSignInAllowed(account)
|
|
12641
12973
|
&& (!viaLink || linkOpen()) && this.returningDevices.current(device, tokenEpoch(token));
|
|
12642
|
-
const issued = codes.issue({ epoch: tokenEpoch(token), recipient: account, audiences: [viaLink ? input.exposureId : "local"] });
|
|
12974
|
+
const issued = codes.issue({ epoch: tokenEpoch(token), recipient: account, audiences: [viaLink ? input.exposureId : "local"], private: true }); // M-3651: by DM only (withdrawn otherwise)
|
|
12643
12975
|
if (!issued)
|
|
12644
12976
|
return { kind: "limited", retryAfterMs: 60_000 }; // the guests' cap: never someone's evicted
|
|
12645
12977
|
this.guestCodeInFlight.add(key);
|
|
@@ -14780,6 +15112,11 @@ export class FleetManager {
|
|
|
14780
15112
|
if (this.instanceIpcClients.get(name) === ipc && typeof msg.generation === "string" && typeof msg.turn === "string")
|
|
14781
15113
|
void this.hubRoomOwed?.turnEnded(name, msg.generation, msg.turn).catch(err => this.logger.warn({ err }, "Hub room completion notice held"));
|
|
14782
15114
|
}
|
|
15115
|
+
else if (msg.type === "hub_question_input" || msg.type === "hub_question_turn_ended" || msg.type === "hub_question_turn_state") {
|
|
15116
|
+
// M-3660: only the instance's current daemon speaks for its pane's turns.
|
|
15117
|
+
if (this.instanceIpcClients.get(name) === ipc)
|
|
15118
|
+
this.hubTurnSignal(name, msg);
|
|
15119
|
+
}
|
|
14783
15120
|
else if (msg.type === "hub_room_input") {
|
|
14784
15121
|
if (this.instanceIpcClients.get(name) === ipc && typeof msg.correlationId === "string" && typeof msg.generation === "string")
|
|
14785
15122
|
this.hubRoomInput?.(msg.correlationId, name, msg.generation);
|
|
@@ -15732,11 +16069,14 @@ export class FleetManager {
|
|
|
15732
16069
|
}
|
|
15733
16070
|
const channelName = msg.username || chatId;
|
|
15734
16071
|
if (requestedBackend) {
|
|
15735
|
-
//
|
|
15736
|
-
await
|
|
15737
|
-
|
|
15738
|
-
|
|
15739
|
-
|
|
16072
|
+
// The backend is only half of /start. The room waits for Restricted or Free.
|
|
16073
|
+
await this.beginClassicModeSelection({
|
|
16074
|
+
command: "start",
|
|
16075
|
+
channelId: chatId,
|
|
16076
|
+
channelName,
|
|
16077
|
+
userId: msg.userId,
|
|
16078
|
+
respond: async (reply) => (await msgAdapter?.sendText(chatId, reply))?.messageId,
|
|
16079
|
+
}, msgAdapter ?? undefined, requestedBackend, msg.adapterId);
|
|
15740
16080
|
}
|
|
15741
16081
|
else if (msgAdapter) {
|
|
15742
16082
|
await this.beginClassicBackendSelection({
|
|
@@ -20794,6 +21134,8 @@ export class FleetManager {
|
|
|
20794
21134
|
return true;
|
|
20795
21135
|
if (await this.handleContactChangeCallback(data, adapterId, adapter))
|
|
20796
21136
|
return true;
|
|
21137
|
+
if (await this.handleContactTicketCallback(data, adapterId, adapter))
|
|
21138
|
+
return true;
|
|
20797
21139
|
if (await this.handleSettingsChangeCallback(data, adapterId, adapter))
|
|
20798
21140
|
return true;
|
|
20799
21141
|
if (await this.handleKiroMigrateCallback(data, adapterId, adapter))
|
|
@@ -20828,6 +21170,8 @@ export class FleetManager {
|
|
|
20828
21170
|
return true;
|
|
20829
21171
|
if (await this.handleClassicBackendSelection(data))
|
|
20830
21172
|
return true;
|
|
21173
|
+
if (await this.handleClassicModeSelection(data))
|
|
21174
|
+
return true;
|
|
20831
21175
|
if (await this.handleModelSelection(data, adapterId))
|
|
20832
21176
|
return true;
|
|
20833
21177
|
if (await this.handleEffortSelection(data, adapterId))
|
|
@@ -20869,16 +21213,27 @@ export class FleetManager {
|
|
|
20869
21213
|
needsYouItems() {
|
|
20870
21214
|
return this.needsYou?.webItems() ?? [];
|
|
20871
21215
|
}
|
|
20872
|
-
/** Enabled member composition supplies
|
|
20873
|
-
attachHubExecutionAttention(read, retry = null) {
|
|
21216
|
+
/** Enabled member composition supplies held-work readers and explicit owner retry/close operations. */
|
|
21217
|
+
attachHubExecutionAttention(read, retry = null, close = undefined) {
|
|
20874
21218
|
this.hubExecutionAttention = read;
|
|
20875
21219
|
this.hubHeldRetry = read ? retry : null;
|
|
21220
|
+
this.hubHeldClose = read ? close ?? null : null;
|
|
20876
21221
|
this.needsYou?.poke();
|
|
20877
21222
|
}
|
|
20878
21223
|
/**
|
|
20879
21224
|
* M-3632: Needs you → "Try again" on held Hub work (`hub:hold:<row>`). The question goes back through the member's whole
|
|
20880
21225
|
* hand-off, including the Hub's begin lease; nothing is delivered without it.
|
|
20881
21226
|
*/
|
|
21227
|
+
async closeHubHeld(itemId, actor) {
|
|
21228
|
+
const item = this.hubExecutionAttention?.().find(i => `hub:${i.id}` === itemId && i.kind === "hold");
|
|
21229
|
+
if (!item || !this.hubHeldClose)
|
|
21230
|
+
return { status: 404, code: "not-found" };
|
|
21231
|
+
if (!this.contactAdminOf(item.agent, actor))
|
|
21232
|
+
return { status: 403, code: "forbidden" };
|
|
21233
|
+
const code = await this.hubHeldClose(item.id);
|
|
21234
|
+
this.needsYou?.poke();
|
|
21235
|
+
return { status: code === "closed" || code === "answered" ? 200 : code === "not-found" ? 404 : 503, code };
|
|
21236
|
+
}
|
|
20882
21237
|
retryHubHeld(itemId) {
|
|
20883
21238
|
const id = itemId.startsWith("hub:") ? itemId.slice(4) : itemId;
|
|
20884
21239
|
if (!this.hubHeldRetry || !id.startsWith("hold:"))
|
|
@@ -21784,9 +22139,26 @@ export class FleetManager {
|
|
|
21784
22139
|
* #1939 S1: the design's §3 for one web request (authority/web-authority.ts), with this fleet's admins, policy and
|
|
21785
22140
|
* token; `instance` once the body has named it. Observe only: receipts record it, no agent acts on it yet.
|
|
21786
22141
|
*/
|
|
22142
|
+
/** A signed-in account is recognizable before verification; this supplies no action authority. */
|
|
22143
|
+
webSessionIdentity(session) {
|
|
22144
|
+
const owner = session.owner;
|
|
22145
|
+
if (owner) {
|
|
22146
|
+
const adapter = this.adapters.get(owner.adapterId) ?? this.worlds?.get(owner.adapterId)?.adapter;
|
|
22147
|
+
const channels = this.fleetConfig?.channels ?? (this.fleetConfig?.channel ? [this.fleetConfig.channel] : []);
|
|
22148
|
+
const platform = adapter?.type ?? channels.find(channel => (channel.id ?? channel.type) === owner.adapterId)?.type;
|
|
22149
|
+
if (platform !== "discord" && platform !== "telegram")
|
|
22150
|
+
return;
|
|
22151
|
+
return Object.freeze({ platform, adapter_id: owner.adapterId, user_id: owner.userId, session_handle: session.handle });
|
|
22152
|
+
}
|
|
22153
|
+
if (session.tier === "admin" && (session.host === true || session.remote === "totp") && this.isWebOnlyFleet()) {
|
|
22154
|
+
return Object.freeze({ platform: "host", adapter_id: "host", user_id: "operator", session_handle: session.handle });
|
|
22155
|
+
}
|
|
22156
|
+
return;
|
|
22157
|
+
}
|
|
21787
22158
|
webAuthority(input) {
|
|
21788
22159
|
const state = this.webAuthorityState();
|
|
21789
|
-
|
|
22160
|
+
// M-3651: a guest's session is asked only whether it is its account, verified (`web-guest`, identity only).
|
|
22161
|
+
return (input.session?.tier === "guest" ? evaluateGuestIdentity : evaluateWebAuthority)({
|
|
21790
22162
|
session: input.session, gateway: input.gateway, peer: input.peer,
|
|
21791
22163
|
tokenEpoch: this.webToken ? tokenEpoch(this.webToken) : null,
|
|
21792
22164
|
...(input.instance !== undefined ? { target: { adapterId: this.getInstanceAdapterId(input.instance) } } : {}),
|
|
@@ -21824,6 +22196,42 @@ export class FleetManager {
|
|
|
21824
22196
|
return { ok: false, refusal: check.refusal };
|
|
21825
22197
|
const live = new Set(this.webSessions?.list(undefined, () => true).map(r => r.handle) ?? []);
|
|
21826
22198
|
store.prune(a => a.epoch === state.epoch && now <= Math.min(a.until, a.authorizedAt + policy.maxSessionMs) && live.has(a.handle));
|
|
22199
|
+
const authorized = store.authorize(session.handle, session.owner, now, state.epoch, now + policy.maxSessionMs, peer);
|
|
22200
|
+
// M-3710: Needs you is projected per session — this one now sees the contact requests it may decide, not just their count.
|
|
22201
|
+
try {
|
|
22202
|
+
this.emitSseEvent("needs", { items: this.needsYouItems() });
|
|
22203
|
+
}
|
|
22204
|
+
catch (err) {
|
|
22205
|
+
this.logger.warn({ err: err?.message }, "Needs you refresh after a web authorization failed");
|
|
22206
|
+
}
|
|
22207
|
+
return { ok: true, ...authorized };
|
|
22208
|
+
}
|
|
22209
|
+
/** M-3651 (auth-api's /auth/session): until when this guest session is verified as its account now; null when it is not. */
|
|
22210
|
+
guestVerifiedUntil(req, session) {
|
|
22211
|
+
if (session.tier !== "guest")
|
|
22212
|
+
return null;
|
|
22213
|
+
const v = this.webSessionAuthorization({ session, gateway: !!gatewayRequestContext(req), peer: webPeerOf(req) });
|
|
22214
|
+
return v.state === "verified" ? v.until : null;
|
|
22215
|
+
}
|
|
22216
|
+
/**
|
|
22217
|
+
* M-3651: a guest session that signed in with a code AgEnD delivered privately to its own account — recorded as that
|
|
22218
|
+
* account's authorization of it, judged by evaluateGuestIdentity (the switch, the links, "Only this computer", the token):
|
|
22219
|
+
* its messages then carry `web-guest`, who it is and never more. Only at sign-in: a guest is never sent a Confirm card.
|
|
22220
|
+
*/
|
|
22221
|
+
authorizeGuestSession(session, peer, gateway) {
|
|
22222
|
+
const store = this.sessionAuthorizationStore();
|
|
22223
|
+
const state = this.webAuthorityState(), now = Date.now(), policy = webAuthorityPolicy(this.fleetConfig?.web);
|
|
22224
|
+
if (!store || !session.owner || session.tier !== "guest")
|
|
22225
|
+
return { ok: false, refusal: !store ? "disabled" : "no_account" };
|
|
22226
|
+
const check = evaluateGuestIdentity({
|
|
22227
|
+
session, gateway, peer, tokenEpoch: this.webToken ? tokenEpoch(this.webToken) : null, isAdmin: () => false,
|
|
22228
|
+
authorization: { handle: session.handle, owner: session.owner, authorizedAt: now, until: now + policy.maxSessionMs, epoch: state.epoch },
|
|
22229
|
+
policy: { ...policy, enabled: state.enabled, loopbackOnly: state.loopbackOnly, namedLink: state.namedLink, quickLink: state.quickLink }, epoch: state.epoch, now,
|
|
22230
|
+
});
|
|
22231
|
+
if (check.refusal)
|
|
22232
|
+
return { ok: false, refusal: check.refusal };
|
|
22233
|
+
const live = new Set(this.webSessions?.list(undefined, () => true).map(r => r.handle) ?? []);
|
|
22234
|
+
store.prune(a => a.epoch === state.epoch && now <= Math.min(a.until, a.authorizedAt + policy.maxSessionMs) && live.has(a.handle));
|
|
21827
22235
|
return { ok: true, ...store.authorize(session.handle, session.owner, now, state.epoch, now + policy.maxSessionMs, peer) };
|
|
21828
22236
|
}
|
|
21829
22237
|
/**
|
|
@@ -21834,15 +22242,17 @@ export class FleetManager {
|
|
|
21834
22242
|
* at once, with Not me (noteAuthorized). Re-verifying once that authorization has run out still takes the card.
|
|
21835
22243
|
*/
|
|
21836
22244
|
authorizeSignedInSession(session, peer, gateway) {
|
|
21837
|
-
if (session.tier !== "admin" || !session.owner || session.host)
|
|
22245
|
+
if ((session.tier !== "admin" && session.tier !== "guest") || !session.owner || session.host)
|
|
21838
22246
|
return;
|
|
21839
|
-
|
|
22247
|
+
// M-3651: a guest's private code verifies who it is (web-guest), never an admin's authority.
|
|
22248
|
+
const r = session.tier === "guest" ? this.authorizeGuestSession(session, peer, gateway) : this.authorizeWebSession(session, peer, gateway);
|
|
21840
22249
|
if (!r.ok) {
|
|
21841
22250
|
this.logger.info({ handle: session.handle, refusal: r.refusal }, "Web session signed in with a private code, not verified");
|
|
21842
22251
|
return;
|
|
21843
22252
|
}
|
|
21844
22253
|
this.logger.info({ handle: session.handle, durable: r.durable }, "Web session verified at sign-in (a private code)");
|
|
21845
|
-
void this.sessionAuthorizationRequests().noteAuthorized({ handle: session.handle, owner: session.owner, label: session.label, peer, until: Math.min(r.authorization.until, session.absoluteExpiry)
|
|
22254
|
+
void this.sessionAuthorizationRequests().noteAuthorized({ handle: session.handle, owner: session.owner, label: session.label, peer, until: Math.min(r.authorization.until, session.absoluteExpiry),
|
|
22255
|
+
...(session.tier === "guest" ? { guest: true } : {}) })
|
|
21846
22256
|
.catch(err => this.logger.warn({ err: err?.message }, "Web sign-in notice failed"));
|
|
21847
22257
|
}
|
|
21848
22258
|
/**
|
|
@@ -22487,7 +22897,10 @@ export class FleetManager {
|
|
|
22487
22897
|
return this.authorizationRequests;
|
|
22488
22898
|
const adapterOf = (adapterId) => this.adapters.get(adapterId) ?? this.worlds.get(adapterId)?.adapter;
|
|
22489
22899
|
// The host's clock, with its zone: the person may read the DM on a phone in another one.
|
|
22490
|
-
|
|
22900
|
+
// M-3730: zh-TW is a 24-hour clock (2026/11/25 00:19:00 [GMT+8]), never 上午12:19; English is unchanged.
|
|
22901
|
+
const when = (ms) => getLocale() === "zh-TW"
|
|
22902
|
+
? new Date(ms).toLocaleString("zh-TW", { year: "numeric", month: "numeric", day: "numeric", hour: "2-digit", minute: "2-digit", second: "2-digit", hourCycle: "h23", timeZoneName: "short" })
|
|
22903
|
+
: new Date(ms).toLocaleString(undefined, { timeZoneName: "short" });
|
|
22491
22904
|
const quickHost = () => { try {
|
|
22492
22905
|
const u = this.publicWebLink?.openSignin()?.url;
|
|
22493
22906
|
return u ? new URL(u).host : "?";
|
|
@@ -22549,7 +22962,7 @@ export class FleetManager {
|
|
|
22549
22962
|
text: {
|
|
22550
22963
|
ask: (c) => t("web_auth.card_ask", c.label, where(c.peer), when(c.askedAt), when(c.until)),
|
|
22551
22964
|
confirmed: (c) => t("web_auth.card_confirmed", c.label, where(c.peer), when(c.until)),
|
|
22552
|
-
signedIn: (c) => t("web_auth.signed_in", c.label, where(c.peer), when(c.until)),
|
|
22965
|
+
signedIn: (c) => t(c.guest ? "web_auth.signed_in_guest" : "web_auth.signed_in", c.label, where(c.peer), when(c.until)),
|
|
22553
22966
|
signedInHint: () => t("web_auth.signed_in_hint"),
|
|
22554
22967
|
denied: (c) => t("web_auth.card_denied", c.label),
|
|
22555
22968
|
expired: (c) => t("web_auth.card_expired", c.label),
|
|
@@ -22683,7 +23096,7 @@ export class FleetManager {
|
|
|
22683
23096
|
// #1827: a /steer or /btw reaches the agent as the web person who wrote it.
|
|
22684
23097
|
chatId: this.getGroupIdForInstance(instance) || "", messageId: newWebMessageId(),
|
|
22685
23098
|
username: opts.person?.name ?? WEB_NAME_FALLBACK, userId: opts.person?.userId ?? WEB_NAME_FALLBACK,
|
|
22686
|
-
threadId: topicId != null ? String(topicId) : undefined, adapterId: this.getAdapterForInstance(instance)?.id ?? "", source: "web", humanOrigin: webHumanOrigin(true, opts.authority),
|
|
23099
|
+
threadId: topicId != null ? String(topicId) : undefined, adapterId: this.getAdapterForInstance(instance)?.id ?? "", source: "web", humanOrigin: webHumanOrigin(true, opts.authority, opts.identity),
|
|
22687
23100
|
...(opts.guest ? { webGuest: true } : {}), // #2855: a guest's /steer or /btw reaches the agent as a guest's
|
|
22688
23101
|
};
|
|
22689
23102
|
};
|
|
@@ -29982,11 +30395,30 @@ export class FleetManager {
|
|
|
29982
30395
|
return undefined;
|
|
29983
30396
|
return t("classic.backend_not_installed", backend, installation.binary, installation.install);
|
|
29984
30397
|
}
|
|
29985
|
-
/**
|
|
29986
|
-
|
|
29987
|
-
|
|
30398
|
+
/** Discord buttons when the interaction can draw them; otherwise the adapter's own chooser. Never the backend select. */
|
|
30399
|
+
classicModePoster(data, adapter) {
|
|
30400
|
+
if (data.respondButtons)
|
|
30401
|
+
return (text, choices) => data.respondButtons(text, choices);
|
|
30402
|
+
if (adapter?.promptUser)
|
|
30403
|
+
return (text, choices) => adapter.promptUser(data.channelId, text, choices);
|
|
30404
|
+
return undefined;
|
|
29988
30405
|
}
|
|
29989
|
-
/**
|
|
30406
|
+
/** Where the finished start (and a hold notice) lands: the Discord interaction, or the Telegram menu message. */
|
|
30407
|
+
classicStartComplete(data, adapter) {
|
|
30408
|
+
if (data.retireButtons)
|
|
30409
|
+
return async (text) => { await data.retireButtons(text); };
|
|
30410
|
+
return async (text, messageId) => {
|
|
30411
|
+
if (messageId && adapter?.editMessageRemoveButtons) {
|
|
30412
|
+
try {
|
|
30413
|
+
await adapter.editMessageRemoveButtons(data.channelId, messageId, text);
|
|
30414
|
+
return;
|
|
30415
|
+
}
|
|
30416
|
+
catch { /* fall back to a new message */ }
|
|
30417
|
+
}
|
|
30418
|
+
await data.respond(text);
|
|
30419
|
+
};
|
|
30420
|
+
}
|
|
30421
|
+
/** Handle Discord's required static slash choice. The room waits for the mode menu. */
|
|
29990
30422
|
async handleClassicStartSlash(data, adapterId) {
|
|
29991
30423
|
return withSpawnHoldReply(text => data.respond(text), () => this.handleClassicStartSlashCore(data, adapterId));
|
|
29992
30424
|
}
|
|
@@ -30006,15 +30438,10 @@ export class FleetManager {
|
|
|
30006
30438
|
await data.respond(blocker);
|
|
30007
30439
|
return;
|
|
30008
30440
|
}
|
|
30009
|
-
|
|
30010
|
-
|
|
30011
|
-
// fails because the executable is absent. This is advisory, not a gate.
|
|
30012
|
-
if (warning)
|
|
30013
|
-
await data.respond(warning);
|
|
30014
|
-
const reply = await this.handleClassicStart(data.channelId, data.channelName, data.userId, data.guildId, adapterId, requestedBackend);
|
|
30015
|
-
await data.respond(warning ? `${warning}\n\n${reply}` : reply);
|
|
30441
|
+
// A missing binary is advisory and stays on the mode menu. The room is not created yet.
|
|
30442
|
+
await this.beginClassicModeSelection(data, undefined, requestedBackend, adapterId);
|
|
30016
30443
|
}
|
|
30017
|
-
/** Present platform-native backend choices
|
|
30444
|
+
/** Present platform-native backend choices. A choice opens the mode menu; a timeout or a failed menu creates nothing. */
|
|
30018
30445
|
async beginClassicBackendSelection(data, adapter) {
|
|
30019
30446
|
const adapterId = adapter.id;
|
|
30020
30447
|
const blocker = this.validateClassicStart(data.channelId, data.userId, data.guildId, adapterId);
|
|
@@ -30027,18 +30454,7 @@ export class FleetManager {
|
|
|
30027
30454
|
id: `${CLASSIC_BACKEND_CALLBACK_PREFIX}${nonce}:${choice.id}`,
|
|
30028
30455
|
label: `${this.isBackendInstalled(choice.id) ? "✅" : "❌"} ${choice.label}`,
|
|
30029
30456
|
}));
|
|
30030
|
-
const complete = data
|
|
30031
|
-
? async (text) => { await data.respond(text); }
|
|
30032
|
-
: async (text, messageId) => {
|
|
30033
|
-
if (messageId && adapter.editMessageRemoveButtons) {
|
|
30034
|
-
try {
|
|
30035
|
-
await adapter.editMessageRemoveButtons(data.channelId, messageId, text);
|
|
30036
|
-
return;
|
|
30037
|
-
}
|
|
30038
|
-
catch { /* fall back to a new message */ }
|
|
30039
|
-
}
|
|
30040
|
-
await data.respond(text);
|
|
30041
|
-
};
|
|
30457
|
+
const complete = this.classicStartComplete(data, adapter);
|
|
30042
30458
|
const timer = setTimeout(() => {
|
|
30043
30459
|
// Timeout: cancel the selection — do NOT fall back to default.
|
|
30044
30460
|
const p = this.pendingClassicStarts.get(nonce);
|
|
@@ -30050,27 +30466,38 @@ export class FleetManager {
|
|
|
30050
30466
|
timer.unref?.();
|
|
30051
30467
|
const pending = {
|
|
30052
30468
|
channelId: data.channelId,
|
|
30053
|
-
channelName: data.channelName,
|
|
30469
|
+
channelName: data.channelName || data.channelId,
|
|
30054
30470
|
userId: data.userId,
|
|
30055
30471
|
guildId: data.guildId,
|
|
30056
30472
|
adapterId,
|
|
30057
30473
|
timer,
|
|
30058
30474
|
complete,
|
|
30475
|
+
phase: "backend",
|
|
30476
|
+
showMenu: this.classicModePoster(data, adapter),
|
|
30059
30477
|
};
|
|
30060
30478
|
this.pendingClassicStarts.set(nonce, pending);
|
|
30061
30479
|
try {
|
|
30480
|
+
const prompt = t("classic.choose_backend");
|
|
30062
30481
|
pending.messageId = data.respondChoices
|
|
30063
|
-
? await data.respondChoices(
|
|
30064
|
-
: await adapter.promptUser(data.channelId,
|
|
30482
|
+
? await data.respondChoices(prompt, choices)
|
|
30483
|
+
: await adapter.promptUser(data.channelId, prompt, choices);
|
|
30065
30484
|
}
|
|
30066
30485
|
catch (err) {
|
|
30067
|
-
//
|
|
30068
|
-
|
|
30069
|
-
this.
|
|
30070
|
-
await this.finishClassicBackendSelection(nonce);
|
|
30486
|
+
// No silent default backend and no silent Restricted room.
|
|
30487
|
+
this.logger.warn({ err, channelId: data.channelId, adapterId }, "Classic backend menu failed; nothing created");
|
|
30488
|
+
await this.cancelClassicPending(nonce, t("classic.backend_menu_failed"));
|
|
30071
30489
|
}
|
|
30072
30490
|
}
|
|
30073
|
-
/**
|
|
30491
|
+
/** Drop a pending /start without creating a room. */
|
|
30492
|
+
async cancelClassicPending(nonce, text) {
|
|
30493
|
+
const pending = this.pendingClassicStarts.get(nonce);
|
|
30494
|
+
if (!pending)
|
|
30495
|
+
return;
|
|
30496
|
+
this.pendingClassicStarts.delete(nonce);
|
|
30497
|
+
clearTimeout(pending.timer);
|
|
30498
|
+
await pending.complete(text, pending.messageId);
|
|
30499
|
+
}
|
|
30500
|
+
/** Consume a backend click. Returns true for every classic-backend id, including a stale one. */
|
|
30074
30501
|
async handleClassicBackendSelection(data) {
|
|
30075
30502
|
if (!data.callbackData.startsWith(CLASSIC_BACKEND_CALLBACK_PREFIX))
|
|
30076
30503
|
return false;
|
|
@@ -30078,11 +30505,12 @@ export class FleetManager {
|
|
|
30078
30505
|
if (!match)
|
|
30079
30506
|
return true;
|
|
30080
30507
|
const pending = this.pendingClassicStarts.get(match[1]);
|
|
30081
|
-
if (!pending)
|
|
30508
|
+
if (!pending || pending.phase === "mode")
|
|
30082
30509
|
return true;
|
|
30083
30510
|
// Telegram keyboards are visible to everyone in a group. Only the user who
|
|
30084
|
-
// issued /start may consume the pending selection.
|
|
30085
|
-
|
|
30511
|
+
// issued /start may consume the pending selection. No user id fails closed:
|
|
30512
|
+
// choosing the backend is part of creating the room.
|
|
30513
|
+
if (!data.userId || data.userId !== pending.userId)
|
|
30086
30514
|
return true;
|
|
30087
30515
|
const callbackChannelId = data.threadId ?? data.chatId;
|
|
30088
30516
|
if (callbackChannelId !== pending.channelId && data.chatId !== pending.channelId)
|
|
@@ -30090,25 +30518,125 @@ export class FleetManager {
|
|
|
30090
30518
|
await this.finishClassicBackendSelection(match[1], match[2]);
|
|
30091
30519
|
return true;
|
|
30092
30520
|
}
|
|
30093
|
-
/**
|
|
30521
|
+
/** The backend is chosen. Retire that menu and ask for the mode. Nothing is registered here. */
|
|
30094
30522
|
async finishClassicBackendSelection(nonce, backend) {
|
|
30095
30523
|
const pending = this.pendingClassicStarts.get(nonce);
|
|
30096
|
-
if (!pending)
|
|
30524
|
+
if (!pending || pending.phase === "mode")
|
|
30097
30525
|
return;
|
|
30098
30526
|
this.pendingClassicStarts.delete(nonce);
|
|
30099
30527
|
clearTimeout(pending.timer);
|
|
30100
|
-
|
|
30101
|
-
|
|
30102
|
-
|
|
30103
|
-
|
|
30104
|
-
|
|
30105
|
-
const
|
|
30106
|
-
|
|
30107
|
-
|
|
30108
|
-
|
|
30109
|
-
|
|
30110
|
-
|
|
30111
|
-
await
|
|
30528
|
+
if (!isSelectableClassicBackend(backend)) {
|
|
30529
|
+
await pending.complete(t("classic.backend_required"), pending.messageId);
|
|
30530
|
+
return;
|
|
30531
|
+
}
|
|
30532
|
+
// The grant can be revoked while the backend menu is up. Do not offer a mode, or create a room, after that.
|
|
30533
|
+
const blocker = this.validateClassicStart(pending.channelId, pending.userId, pending.guildId, pending.adapterId);
|
|
30534
|
+
if (blocker) {
|
|
30535
|
+
await pending.complete(blocker, pending.messageId);
|
|
30536
|
+
return;
|
|
30537
|
+
}
|
|
30538
|
+
await pending.complete(t("classic.backend_chosen", backend), pending.messageId);
|
|
30539
|
+
await this.openClassicModeMenu(pending, backend);
|
|
30540
|
+
}
|
|
30541
|
+
/** After a backend is known (slash, `/start BACKEND`, or a backend click). The room waits for a mode click. */
|
|
30542
|
+
async beginClassicModeSelection(data, adapter, backend, adapterId) {
|
|
30543
|
+
const ownerId = adapterId ?? adapter?.id;
|
|
30544
|
+
const blocker = this.validateClassicStart(data.channelId, data.userId, data.guildId, ownerId);
|
|
30545
|
+
if (blocker) {
|
|
30546
|
+
await data.respond(blocker);
|
|
30547
|
+
return;
|
|
30548
|
+
}
|
|
30549
|
+
await this.openClassicModeMenu({
|
|
30550
|
+
channelId: data.channelId,
|
|
30551
|
+
channelName: data.channelName || data.channelId,
|
|
30552
|
+
userId: data.userId,
|
|
30553
|
+
guildId: data.guildId,
|
|
30554
|
+
adapterId: ownerId,
|
|
30555
|
+
complete: this.classicStartComplete(data, adapter),
|
|
30556
|
+
showMenu: this.classicModePoster(data, adapter),
|
|
30557
|
+
}, backend);
|
|
30558
|
+
}
|
|
30559
|
+
/** For a fleet admin, Free is first and labeled recommended. Restricted stays a button.
|
|
30560
|
+
* Anyone else sees only Restricted. Either way the room waits for a tap. */
|
|
30561
|
+
async openClassicModeMenu(origin, backend) {
|
|
30562
|
+
const free = this.canChooseFreeMode(origin.userId, origin.adapterId);
|
|
30563
|
+
const missing = this.getMissingBackendWarning(backend);
|
|
30564
|
+
const prompt = [missing, t(free ? "classic.choose_mode" : "classic.choose_mode_fixed")].filter(Boolean).join("\n\n");
|
|
30565
|
+
if (!origin.showMenu) {
|
|
30566
|
+
await origin.complete(t("classic.mode_menu_failed"));
|
|
30567
|
+
return;
|
|
30568
|
+
}
|
|
30569
|
+
const nonce = randomBytes(6).toString("hex");
|
|
30570
|
+
const restrictedChoice = {
|
|
30571
|
+
id: `${CLASSIC_MODE_CALLBACK_PREFIX}${nonce}:restricted`,
|
|
30572
|
+
label: t("classic.mode_restricted"),
|
|
30573
|
+
};
|
|
30574
|
+
const choices = free
|
|
30575
|
+
? [{ id: `${CLASSIC_MODE_CALLBACK_PREFIX}${nonce}:free`, label: t("classic.mode_free_recommended") }, restrictedChoice]
|
|
30576
|
+
: [restrictedChoice];
|
|
30577
|
+
const timer = setTimeout(() => {
|
|
30578
|
+
const pending = this.pendingClassicStarts.get(nonce);
|
|
30579
|
+
if (!pending)
|
|
30580
|
+
return;
|
|
30581
|
+
this.pendingClassicStarts.delete(nonce);
|
|
30582
|
+
pending.complete(t("classic.mode_selection_expired"), pending.messageId).catch(() => { });
|
|
30583
|
+
}, CLASSIC_BACKEND_SELECTION_TIMEOUT_MS);
|
|
30584
|
+
timer.unref?.();
|
|
30585
|
+
const pending = {
|
|
30586
|
+
channelId: origin.channelId,
|
|
30587
|
+
channelName: origin.channelName || origin.channelId,
|
|
30588
|
+
userId: origin.userId,
|
|
30589
|
+
guildId: origin.guildId,
|
|
30590
|
+
adapterId: origin.adapterId,
|
|
30591
|
+
timer,
|
|
30592
|
+
complete: origin.complete,
|
|
30593
|
+
phase: "mode",
|
|
30594
|
+
backend,
|
|
30595
|
+
showMenu: origin.showMenu,
|
|
30596
|
+
};
|
|
30597
|
+
this.pendingClassicStarts.set(nonce, pending);
|
|
30598
|
+
try {
|
|
30599
|
+
pending.messageId = await origin.showMenu(prompt, choices);
|
|
30600
|
+
}
|
|
30601
|
+
catch (err) {
|
|
30602
|
+
this.logger.warn({ err, channelId: origin.channelId, adapterId: origin.adapterId }, "Classic mode menu failed; nothing created");
|
|
30603
|
+
await this.cancelClassicPending(nonce, t("classic.mode_menu_failed"));
|
|
30604
|
+
}
|
|
30605
|
+
}
|
|
30606
|
+
/** Consume a mode click. A Free click from anyone else is ignored and the menu stays up. */
|
|
30607
|
+
async handleClassicModeSelection(data) {
|
|
30608
|
+
if (!data.callbackData.startsWith(CLASSIC_MODE_CALLBACK_PREFIX))
|
|
30609
|
+
return false;
|
|
30610
|
+
const match = data.callbackData.match(/^classic-mode:([0-9a-f]+):(restricted|free)$/);
|
|
30611
|
+
if (!match)
|
|
30612
|
+
return true;
|
|
30613
|
+
const pending = this.pendingClassicStarts.get(match[1]);
|
|
30614
|
+
if (!pending || pending.phase !== "mode")
|
|
30615
|
+
return true;
|
|
30616
|
+
// Same identity rule as the backend click. A missing user id must not settle
|
|
30617
|
+
// Restricted or Free, including Free opened by a fleet admin.
|
|
30618
|
+
if (!data.userId || data.userId !== pending.userId)
|
|
30619
|
+
return true;
|
|
30620
|
+
const callbackChannelId = data.threadId ?? data.chatId;
|
|
30621
|
+
if (callbackChannelId !== pending.channelId && data.chatId !== pending.channelId)
|
|
30622
|
+
return true;
|
|
30623
|
+
if (match[2] === "free" && !this.canChooseFreeMode(pending.userId, pending.adapterId)) {
|
|
30624
|
+
data.ack?.(t("classic.mode_free_admin_only"));
|
|
30625
|
+
return true;
|
|
30626
|
+
}
|
|
30627
|
+
await this.finishClassicModeSelection(match[1], match[2] === "restricted");
|
|
30628
|
+
return true;
|
|
30629
|
+
}
|
|
30630
|
+
/** Claim the mode choice and create the room. A second click or the timeout finds nothing. */
|
|
30631
|
+
async finishClassicModeSelection(nonce, restricted) {
|
|
30632
|
+
const pending = this.pendingClassicStarts.get(nonce);
|
|
30633
|
+
if (!pending || pending.phase !== "mode" || !pending.backend)
|
|
30634
|
+
return;
|
|
30635
|
+
this.pendingClassicStarts.delete(nonce);
|
|
30636
|
+
clearTimeout(pending.timer);
|
|
30637
|
+
const missing = this.getMissingBackendWarning(pending.backend);
|
|
30638
|
+
const reply = await withSpawnHoldReply(text => pending.complete(text, pending.messageId), () => this.handleClassicStart(pending.channelId, pending.channelName, pending.userId, pending.guildId, pending.adapterId, pending.backend, restricted));
|
|
30639
|
+
await pending.complete(missing ? `${missing}\n\n${reply}` : reply, pending.messageId);
|
|
30112
30640
|
}
|
|
30113
30641
|
/** Start a classic channel instance with lightweight config */
|
|
30114
30642
|
async startClassicInstance(instanceName, backend, preTaskCommand, model, autoPauseAfter, transition, execution) {
|
|
@@ -30158,7 +30686,7 @@ export class FleetManager {
|
|
|
30158
30686
|
await this.startInstance(instanceName, config, topicMode, "classic", false, transition);
|
|
30159
30687
|
}
|
|
30160
30688
|
/** Handle /start slash command — register classic channel */
|
|
30161
|
-
async handleClassicStart(channelId, channelName, userId, guildId, adapterId, backend) {
|
|
30689
|
+
async handleClassicStart(channelId, channelName, userId, guildId, adapterId, backend, restricted = true) {
|
|
30162
30690
|
const blocker = this.validateClassicStart(channelId, userId, guildId, adapterId);
|
|
30163
30691
|
if (blocker)
|
|
30164
30692
|
return blocker;
|
|
@@ -30168,7 +30696,7 @@ export class FleetManager {
|
|
|
30168
30696
|
const instanceName = classicChannels.deriveInstanceName(channelName || channelId, channelId, adapterId);
|
|
30169
30697
|
clearPausedMarker(this.getInstanceDir(instanceName));
|
|
30170
30698
|
const selectedBackend = isSelectableClassicBackend(backend) ? backend : undefined;
|
|
30171
|
-
classicChannels.register(channelId, adapterId, instanceName, channelName || channelId, userId, selectedBackend);
|
|
30699
|
+
classicChannels.register(channelId, adapterId, instanceName, channelName || channelId, userId, selectedBackend, restricted);
|
|
30172
30700
|
// Bind this classic instance to the bot that started it (authoritative), so
|
|
30173
30701
|
// replies/cancel go out through that bot even though every same-guild bot
|
|
30174
30702
|
// also sees the channel's messages.
|
|
@@ -33446,6 +33974,8 @@ export class FleetManager {
|
|
|
33446
33974
|
// User activity is persisted by the daemon, so both the board and
|
|
33447
33975
|
// auto-pause retain an accurate age across fleet restarts.
|
|
33448
33976
|
lastActivity,
|
|
33977
|
+
// M-3674: the last turn another agent started (lastActivity is a person's side).
|
|
33978
|
+
lastAgentTurn: inst.classic ? null : this.lastAgentTurnOf(inst.name),
|
|
33449
33979
|
currentTask,
|
|
33450
33980
|
idle: this.getInstanceIdle(inst.name),
|
|
33451
33981
|
...this.instancePresentation(inst.name),
|
|
@@ -33901,7 +34431,7 @@ export class FleetManager {
|
|
|
33901
34431
|
model: nativeConfig.model || "default", model_source: nativeConfig.model ? "instance" : "cli-default",
|
|
33902
34432
|
status: agent && runtime ? runtime.status(name) : "crashed", state: agent && runtime ? runtime.execution(name) : null, execution_state: agent && runtime ? runtime.execution(name) : null,
|
|
33903
34433
|
interaction: null, interaction_summary: null, context_pct: null, cost: null,
|
|
33904
|
-
last_reply: this.webChatHistory.lastAgentReply(name) ?? undefined,
|
|
34434
|
+
last_reply: this.webChatHistory.lastAgentReply(name) ?? undefined, last_agent_turn: this.lastAgentTurnOf(name) ?? undefined,
|
|
33905
34435
|
avatar: avatarFor({ name, displayName: display_name }),
|
|
33906
34436
|
capabilities: { chat: true, settings: true, pause: true, cancel: true, teams: true, schedules: true, delegation: true, mcp: nativeProviderMcpSupported(backend), channels: false, terminal: false, attachments: false, usage: false, send_while_busy: false },
|
|
33907
34437
|
...(!agent ? { runtime_error: "Windows profile is missing or invalid; restore its saved conversation before using this instance" }
|
|
@@ -33987,6 +34517,8 @@ export class FleetManager {
|
|
|
33987
34517
|
// #3008 G2: a web-only fleet's General (the agent its owner ticked) — the sidebar pins it first.
|
|
33988
34518
|
...(this.isWebOnlyFleet() && this.fleetConfig?.instances[name]?.general_topic === true ? { general: true } : {}),
|
|
33989
34519
|
last_reply: this.webChatHistory.lastAgentReply(name) ?? undefined, // #2179: its last reply to a person (ISO)
|
|
34520
|
+
// M-3674: its last turn another agent started (a message from another instance it took up), beside last_reply.
|
|
34521
|
+
last_agent_turn: this.lastAgentTurnOf(name) ?? undefined,
|
|
33990
34522
|
// #2855: its last reply that reached the channel — the only reply time a guest's sidebar gets (guestStatus).
|
|
33991
34523
|
last_reply_channel: this.webChatHistory.lastAgentReply(name, { channel: true }) ?? undefined,
|
|
33992
34524
|
// #2855: the web commands a guest may run here — the table's "anyone" cells for this channel (guestWebCommands);
|