@songsid/agend 2.4.0-beta.13 → 2.4.0-beta.14
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-endpoint.js +28 -6
- package/dist/agent-endpoint.js.map +1 -1
- package/dist/backend/claude-code.d.ts +9 -0
- package/dist/backend/claude-code.js +60 -4
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/grok.js +11 -0
- package/dist/backend/grok.js.map +1 -1
- package/dist/backend/types.d.ts +3 -0
- package/dist/backend/types.js.map +1 -1
- package/dist/backend-availability.d.ts +1 -16
- package/dist/backend-availability.js +2 -91
- package/dist/backend-availability.js.map +1 -1
- package/dist/backend-version-static.d.ts +15 -0
- package/dist/backend-version-static.js +95 -0
- package/dist/backend-version-static.js.map +1 -0
- package/dist/build-provenance.json +1 -1
- package/dist/channel/adapters/telegram.js +3 -1
- package/dist/channel/adapters/telegram.js.map +1 -1
- package/dist/channel/mcp-server.js +18 -1
- package/dist/channel/mcp-server.js.map +1 -1
- package/dist/channel/tool-router.d.ts +4 -0
- package/dist/channel/tool-router.js +43 -19
- package/dist/channel/tool-router.js.map +1 -1
- package/dist/classic-channel-manager.d.ts +3 -0
- package/dist/classic-channel-manager.js +18 -0
- package/dist/classic-channel-manager.js.map +1 -1
- package/dist/classic-cli-guard.d.ts +66 -0
- package/dist/classic-cli-guard.js +209 -0
- package/dist/classic-cli-guard.js.map +1 -0
- package/dist/cli-audited.js +7 -5
- package/dist/cli-audited.js.map +1 -1
- package/dist/config-validator.js +3 -0
- package/dist/config-validator.js.map +1 -1
- package/dist/contact-auth-api.d.ts +16 -0
- package/dist/contact-auth-api.js +78 -0
- package/dist/contact-auth-api.js.map +1 -0
- package/dist/contact-auth-files.d.ts +6 -0
- package/dist/contact-auth-files.js +29 -0
- package/dist/contact-auth-files.js.map +1 -0
- package/dist/contact-auth-policy.d.ts +75 -0
- package/dist/contact-auth-policy.js +23 -0
- package/dist/contact-auth-policy.js.map +1 -0
- package/dist/contact-auth-service.d.ts +32 -0
- package/dist/contact-auth-service.js +99 -0
- package/dist/contact-auth-service.js.map +1 -0
- package/dist/contact-auth-store.d.ts +75 -0
- package/dist/contact-auth-store.js +295 -0
- package/dist/contact-auth-store.js.map +1 -0
- package/dist/contact-auth-types.d.ts +170 -0
- package/dist/contact-auth-types.js +7 -0
- package/dist/contact-auth-types.js.map +1 -0
- package/dist/daemon.d.ts +8 -0
- package/dist/daemon.js +93 -4
- package/dist/daemon.js.map +1 -1
- package/dist/delivery-outbox.d.ts +6 -0
- package/dist/delivery-outbox.js +19 -0
- package/dist/delivery-outbox.js.map +1 -1
- package/dist/fleet-manager.d.ts +40 -0
- package/dist/fleet-manager.js +429 -22
- package/dist/fleet-manager.js.map +1 -1
- package/dist/general-knowledge/skills/concepts/SKILL.md +18 -0
- package/dist/general-knowledge/skills/credential-profiles/SKILL.md +5 -0
- package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +28 -0
- package/dist/general-knowledge/skills/hub/SKILL.md +6 -0
- package/dist/hub/audit/index.d.ts +3 -1
- package/dist/hub/audit/index.js +35 -3
- package/dist/hub/audit/index.js.map +1 -1
- package/dist/hub/catalog.d.ts +8 -0
- package/dist/hub/catalog.js +39 -4
- package/dist/hub/catalog.js.map +1 -1
- package/dist/hub/compose/server.d.ts +2 -0
- package/dist/hub/compose/server.js +11 -1
- package/dist/hub/compose/server.js.map +1 -1
- package/dist/hub/directory/directory.js +5 -2
- package/dist/hub/directory/directory.js.map +1 -1
- package/dist/hub/directory/types.d.ts +5 -1
- package/dist/hub/directory/types.js.map +1 -1
- package/dist/hub/group-policy/resources.d.ts +1 -1
- package/dist/hub/http/compose.d.ts +2 -0
- package/dist/hub/http/compose.js +123 -6
- package/dist/hub/http/compose.js.map +1 -1
- package/dist/hub/http/deps.d.ts +2 -0
- package/dist/hub/http/schema.js +6 -1
- package/dist/hub/http/schema.js.map +1 -1
- package/dist/hub/invitations.js +15 -7
- package/dist/hub/invitations.js.map +1 -1
- package/dist/hub/roles/cutover-inventory.d.ts +3 -0
- package/dist/hub/roles/cutover-inventory.js +20 -4
- package/dist/hub/roles/cutover-inventory.js.map +1 -1
- package/dist/hub/roles/cutover-marker.d.ts +18 -2
- package/dist/hub/roles/cutover-marker.js +6 -2
- package/dist/hub/roles/cutover-marker.js.map +1 -1
- package/dist/hub/room-agent-discovery-model.d.ts +29 -0
- package/dist/hub/room-agent-discovery-model.js +33 -0
- package/dist/hub/room-agent-discovery-model.js.map +1 -0
- package/dist/hub/room-agent-discovery.d.ts +14 -0
- package/dist/hub/room-agent-discovery.js +65 -0
- package/dist/hub/room-agent-discovery.js.map +1 -0
- package/dist/hub/room-agent-requests.d.ts +71 -0
- package/dist/hub/room-agent-requests.js +377 -0
- package/dist/hub/room-agent-requests.js.map +1 -0
- package/dist/hub/rooms/directory.d.ts +13 -0
- package/dist/hub/rooms/directory.js +12 -3
- package/dist/hub/rooms/directory.js.map +1 -1
- package/dist/hub/rooms/schema.d.ts +5 -0
- package/dist/hub/rooms/schema.js +9 -0
- package/dist/hub/rooms/schema.js.map +1 -1
- package/dist/hub/rooms/service.d.ts +43 -19
- package/dist/hub/rooms/service.js +67 -11
- package/dist/hub/rooms/service.js.map +1 -1
- package/dist/hub/rooms/types.d.ts +1 -1
- package/dist/instance-lifecycle.d.ts +3 -1
- package/dist/instance-lifecycle.js +4 -1
- package/dist/instance-lifecycle.js.map +1 -1
- package/dist/locale.js +28 -4
- package/dist/locale.js.map +1 -1
- package/dist/needs-you-hub.d.ts +1 -0
- package/dist/needs-you-hub.js +6 -0
- package/dist/needs-you-hub.js.map +1 -1
- package/dist/needs-you.d.ts +10 -2
- package/dist/needs-you.js.map +1 -1
- package/dist/outbound-handlers.d.ts +9 -0
- package/dist/outbound-handlers.js +46 -10
- package/dist/outbound-handlers.js.map +1 -1
- package/dist/runtime-cli-install.js +7 -7
- package/dist/runtime-cli-install.js.map +1 -1
- package/dist/topic-commands.d.ts +1 -1
- package/dist/topic-commands.js +4 -6
- package/dist/topic-commands.js.map +1 -1
- package/dist/ui/agent-details-settings.js +7 -5
- package/dist/ui/contact-auth-client.js +48 -0
- package/dist/ui/contact-auth-strings.js +164 -0
- package/dist/ui/contact-authorizations.js +125 -0
- package/dist/ui/contact-needs.js +84 -0
- package/dist/ui/contact-permissions.js +193 -0
- package/dist/ui/contact-ticket-badge.js +54 -0
- package/dist/ui/hub-client.js +30 -7
- package/dist/ui/hub-invitations.js +5 -1
- package/dist/ui/hub-room-new.js +10 -3
- package/dist/ui/hub-room-owner-requests-strings.js +114 -0
- package/dist/ui/hub-room-owner-requests.js +264 -0
- package/dist/ui/hub-room-pins.js +43 -0
- package/dist/ui/hub-room-settings.js +11 -2
- package/dist/ui/hub-room-strings.js +3 -0
- package/dist/ui/hub-room-thread.js +47 -5
- package/dist/ui/panel-chat.js +2 -0
- package/dist/ui/panel-details.js +2 -0
- package/dist/ui/panel-fleet.js +3 -2
- package/dist/ui/panel-hub.js +7 -1
- package/dist/ui/panel-needs.js +5 -1
- package/dist/ui/panel-settings.js +3 -0
- package/dist/ui/shared/app-route.js +1 -1
- package/dist/ui/shared/app-shell.js +2 -0
- package/dist/ui/shared/app-stream.js +3 -1
- package/dist/ui/shared/app.css +31 -0
- package/dist/ui/shared/chat-quote.js +26 -2
- package/dist/ui/shared/chat-thread.js +6 -2
- package/dist/ui/shared/hub-rooms-u2.css +22 -0
- package/dist/ui/shared/text-undo.js +17 -3
- package/dist/web-api.d.ts +9 -0
- package/dist/web-api.js +55 -3
- package/dist/web-api.js.map +1 -1
- package/dist/web-chat-history.d.ts +5 -0
- package/dist/web-chat-history.js +26 -0
- package/dist/web-chat-history.js.map +1 -1
- package/dist/web-reply-files.d.ts +1 -0
- package/dist/web-reply-files.js +2 -0
- package/dist/web-reply-files.js.map +1 -1
- package/dist/web-shell-routes.d.ts +1 -1
- package/dist/web-shell-routes.js +2 -1
- package/dist/web-shell-routes.js.map +1 -1
- package/package.json +1 -1
package/dist/fleet-manager.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { withHubRoomReplyWarning } from "./hub-room-reply-warning.js";
|
|
2
|
+
import { ContactAuthService } from "./contact-auth-service.js";
|
|
3
|
+
import { stageContactFiles } from "./contact-auth-files.js";
|
|
4
|
+
import { ContactPermissionsSchema, sameContactPerson } from "./contact-auth-policy.js";
|
|
5
|
+
import { CLASSIC_RESTRICTED_TOOLS } from "./contact-auth-types.js";
|
|
2
6
|
import { hubSharingNoticeText } from "./hub-sharing-notice.js";
|
|
3
7
|
import { hubPageSharingSettings } from "./hub-page-sharing-settings.js";
|
|
4
8
|
import { replyPreviews } from "./reply-preview-spec.js";
|
|
@@ -354,8 +358,8 @@ import { agyLegacyAgentsFile, danglingSymlink, migrateAgyAgentsFile } from "./ba
|
|
|
354
358
|
import { claudeConfigDirFor, claudeProjectKey } from "./backend/claude-code.js";
|
|
355
359
|
import { sharedRolloutIndex } from "./rollout-index.js";
|
|
356
360
|
import { TASK_BOARD_ON_NOTICE, dashboardRefusalIn, taskBoardOffIn, taskBoardSwitchedOn } from "./dashboard-permissions.js";
|
|
357
|
-
import { mayUseTool, resolveToolSet, scheduleOpRefusal, toolForIpcType, toolRefusedMessage, } from "./tool-permissions.js";
|
|
358
|
-
import { authorizeSession, decideWebGate, loadOrCreateWebToken, readSessionCookies, readWebToken, sessionCookieUpgrade } from "./web-auth.js";
|
|
361
|
+
import { mayUseTool, toolsFor, resolveToolSet, scheduleOpRefusal, toolForIpcType, toolRefusedMessage, } from "./tool-permissions.js";
|
|
362
|
+
import { authorizeSession, decideWebGate, evaluateWebRequest, loadOrCreateWebToken, readSessionCookies, readWebToken, sessionCookieUpgrade } from "./web-auth.js";
|
|
359
363
|
import { takeAssetVersion, warmAssetVersion } from "./web-asset-version.js";
|
|
360
364
|
import { bypassesWebGate, handleAuthRequest, serveGuestRefusedPage, serveSigninPage } from "./auth-api.js";
|
|
361
365
|
import { isWebPageNavigation } from "./web-shell-routes.js";
|
|
@@ -366,7 +370,7 @@ import { DeviceLoginRequests } from "./web-device-login.js";
|
|
|
366
370
|
import { findSigninKnownEntry, addSigninKnownDevice } from "./web-signin-device.js";
|
|
367
371
|
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";
|
|
368
372
|
import { evaluateSettingsRole } from "./authority/settings-role.js";
|
|
369
|
-
import { authorityNow, evaluateWebAuthority, HOST_OPERATOR, VERIFIED_SESSION_HOURS, webAuthorityPolicy } from "./authority/web-authority.js";
|
|
373
|
+
import { authorityNow, classifyWebPeer, evaluateWebAuthority, HOST_OPERATOR, VERIFIED_SESSION_HOURS, webAuthorityPolicy } from "./authority/web-authority.js";
|
|
370
374
|
import { AuthorityStateStore, namedLinkLastTurnedOff } from "./authority/authority-state.js";
|
|
371
375
|
import { SessionAuthorizations } from "./authority/session-authorizations.js";
|
|
372
376
|
import { SessionAuthorizationRequests } from "./web-session-authorization.js";
|
|
@@ -1412,7 +1416,8 @@ export class FleetManager {
|
|
|
1412
1416
|
if (this.paneManager)
|
|
1413
1417
|
return this.paneManager;
|
|
1414
1418
|
const store = windowsAgentsFor(this, this.runtimeWindowsExecutor());
|
|
1415
|
-
const allowed = (name, tool) =>
|
|
1419
|
+
const allowed = (name, tool) => (!this.classicContactRestricted(name) || CLASSIC_RESTRICTED_TOOLS.includes(tool))
|
|
1420
|
+
&& nativePaneToolAvailable(tool) && mayUseTool(resolveToolSet(this.fleetConfig?.instances[name], name), tool)
|
|
1416
1421
|
&& !dashboardRefusalIn(this.fleetConfig, name, tool);
|
|
1417
1422
|
return this.paneManager = new NativePaneManager({
|
|
1418
1423
|
home: this.dataDir, store, config: name => this.fleetConfig?.instances[name],
|
|
@@ -5698,6 +5703,15 @@ export class FleetManager {
|
|
|
5698
5703
|
if (row)
|
|
5699
5704
|
for (const name of new Set([row.sourceInstance, row.targetInstance]))
|
|
5700
5705
|
this.observeWorkingState(name, "obligations");
|
|
5706
|
+
const badge = row?.payload.contactTicket;
|
|
5707
|
+
const ticket = badge?.id ? outbox.contactAuthorizations.get(badge.id) : undefined;
|
|
5708
|
+
if (ticket && ticket.deliveryId === row?.deliveryId) {
|
|
5709
|
+
const state = event.state === "delivered" ? "delivered" : ["failed", "uncertain", "cancelled", "reconciliation_pending"].includes(event.state ?? "") ? "unknown" : "approved";
|
|
5710
|
+
for (const instance of new Set([ticket.source, ticket.target])) {
|
|
5711
|
+
this.webChatHistory?.updateContactTicket(instance, ticket.id, state);
|
|
5712
|
+
this.emitSseEvent("contact-auth", { instance, ticketId: ticket.id, revision: ticket.revision });
|
|
5713
|
+
}
|
|
5714
|
+
}
|
|
5701
5715
|
}
|
|
5702
5716
|
this.scheduleDeliveryOutboxPump();
|
|
5703
5717
|
this.wakeCoordinator?.kick();
|
|
@@ -5804,6 +5818,305 @@ export class FleetManager {
|
|
|
5804
5818
|
this.trafficMemo = { atMs: nowMs, value: { now, items, delegations } };
|
|
5805
5819
|
return this.trafficMemo.value;
|
|
5806
5820
|
}
|
|
5821
|
+
contactRoom(name) { return this.classicChannels?.getAll?.().find(room => room.instanceName === name); }
|
|
5822
|
+
classicContactRestricted(instance) { return this.contactRoom(instance)?.restrictedMode === true; }
|
|
5823
|
+
inheritContactOrigin(source, target) {
|
|
5824
|
+
const service = this.contactService();
|
|
5825
|
+
if (service.host.legacyClassic?.(source))
|
|
5826
|
+
return;
|
|
5827
|
+
const origin = service.origin(source);
|
|
5828
|
+
if (origin)
|
|
5829
|
+
service.host.store.inheritOrigin(target, { ...origin, chain: [...origin.chain, target] });
|
|
5830
|
+
}
|
|
5831
|
+
contactAdapter(name) {
|
|
5832
|
+
const id = this.contactRoom(name)?.adapterId ?? this.getInstanceAdapterId(name);
|
|
5833
|
+
return id ? this.adapters.get(id) ?? this.worlds.get(id)?.adapter ?? null : null;
|
|
5834
|
+
}
|
|
5835
|
+
/** Called only with SDK input at the Classic ingress, never agent-supplied routing metadata. */
|
|
5836
|
+
recordClassicContactInput(instance, msg, adapter) {
|
|
5837
|
+
const room = this.contactRoom(instance);
|
|
5838
|
+
if (room?.restrictedMode !== true || msg.isBotMessage || msg.chatId !== room.channelId
|
|
5839
|
+
|| (room.adapterId && room.adapterId !== adapter.id) || msg.adapterId !== adapter.id)
|
|
5840
|
+
return;
|
|
5841
|
+
const nativeThread = msg.transportThreadId ?? msg.threadId;
|
|
5842
|
+
const thread = nativeThread && nativeThread !== room.channelId && nativeThread.length <= 128
|
|
5843
|
+
&& !/[\r\n\x00]/.test(nativeThread) ? nativeThread : undefined;
|
|
5844
|
+
const fileIds = (msg.attachments ?? []).map(file => file.fileId)
|
|
5845
|
+
.filter(id => typeof id === "string" && id.length > 0 && id.length <= 4096).slice(0, 20);
|
|
5846
|
+
this.contactService().host.store.recordRoomContext(instance, { ...(thread ? { threadId: thread } : {}), fileIds }, this.contactGeneration(instance));
|
|
5847
|
+
}
|
|
5848
|
+
restrictedClassicRouting(instance) {
|
|
5849
|
+
const room = this.contactRoom(instance);
|
|
5850
|
+
if (room?.restrictedMode !== true)
|
|
5851
|
+
return undefined;
|
|
5852
|
+
const adapter = this.contactAdapter(instance);
|
|
5853
|
+
if (!adapter)
|
|
5854
|
+
throw Error("Restricted room adapter is unavailable");
|
|
5855
|
+
const context = this.contactService().host.store.roomContext(instance, this.contactGeneration(instance));
|
|
5856
|
+
return { adapterId: adapter.id, chatId: room.channelId, ...(context.threadId ? { threadId: context.threadId } : {}) };
|
|
5857
|
+
}
|
|
5858
|
+
async prepareContactFiles(instance, paths) {
|
|
5859
|
+
if (this.contactRoom(instance)?.restrictedMode !== true || paths.length === 0)
|
|
5860
|
+
return undefined;
|
|
5861
|
+
const incarnation = this.contactGeneration(instance), home = realpathSync(getAgendHome());
|
|
5862
|
+
const inbox = join(home, "workspaces", instance, "inbox");
|
|
5863
|
+
const lease = await stageContactFiles(paths, home, inbox);
|
|
5864
|
+
if (this.contactGeneration(instance) !== incarnation) {
|
|
5865
|
+
await lease.dispose();
|
|
5866
|
+
throw Error("Room identity changed before attachment delivery");
|
|
5867
|
+
}
|
|
5868
|
+
return lease;
|
|
5869
|
+
}
|
|
5870
|
+
async downloadRoomAttachment(instance, fileId) {
|
|
5871
|
+
const route = this.restrictedClassicRouting(instance);
|
|
5872
|
+
if (!route)
|
|
5873
|
+
throw Error("This is not a restricted Classic room");
|
|
5874
|
+
const incarnation = this.contactGeneration(instance), store = this.contactService().host.store;
|
|
5875
|
+
if (!store.roomContext(instance, incarnation).fileIds.includes(fileId))
|
|
5876
|
+
throw Error("This attachment was not received in this room");
|
|
5877
|
+
const adapter = this.contactAdapter(instance);
|
|
5878
|
+
if (!adapter)
|
|
5879
|
+
throw Error("Restricted room adapter is unavailable");
|
|
5880
|
+
const file = await adapter.downloadAttachment(fileId);
|
|
5881
|
+
const home = realpathSync(getAgendHome()), scratch = join(home, "workspaces", instance, "inbox", "room-scratch");
|
|
5882
|
+
const copied = await snapshotReplyFile(file, scratch, randomBytes(16).toString("hex"), {
|
|
5883
|
+
stateDir: home, allowedRoots: [join(home, "inbox")], maxFileBytes: 20 * 1024 * 1024, maxDirBytes: 400 * 1024 * 1024,
|
|
5884
|
+
});
|
|
5885
|
+
if (!copied.ok)
|
|
5886
|
+
throw Error("The room attachment could not be copied safely");
|
|
5887
|
+
if (this.contactGeneration(instance) !== incarnation) {
|
|
5888
|
+
try {
|
|
5889
|
+
unlinkSync(copied.path);
|
|
5890
|
+
}
|
|
5891
|
+
catch { /* our snapshot only */ }
|
|
5892
|
+
throw Error("Room identity changed during attachment download");
|
|
5893
|
+
}
|
|
5894
|
+
return copied.path;
|
|
5895
|
+
}
|
|
5896
|
+
configureClassicRestriction(name, daemon) {
|
|
5897
|
+
const room = this.contactRoom(name);
|
|
5898
|
+
if (!room)
|
|
5899
|
+
return;
|
|
5900
|
+
const guarded = daemon;
|
|
5901
|
+
if (room.restrictedMode !== true) {
|
|
5902
|
+
guarded.setClassicRestriction?.({ mode: "legacy", roomTools: { publicRead: true, allowedMcpTools: [] } });
|
|
5903
|
+
return;
|
|
5904
|
+
}
|
|
5905
|
+
const policy = this.contactService().host.store.policy(name, this.contactGeneration(name));
|
|
5906
|
+
guarded.setClassicRestriction?.({ mode: room.restrictedMode === true ? "restricted" : "legacy",
|
|
5907
|
+
roomTools: policy.roomTools, policyRevision: policy.revision });
|
|
5908
|
+
}
|
|
5909
|
+
contactGeneration(name) {
|
|
5910
|
+
// Reuse the existing durable incarnation fence: replacement/retarget rotates it,
|
|
5911
|
+
// while an ordinary pause or daemon restart must not strand an approved request.
|
|
5912
|
+
const incarnation = this.hubAgentToken(name);
|
|
5913
|
+
if (!incarnation)
|
|
5914
|
+
throw Error("unavailable");
|
|
5915
|
+
return incarnation;
|
|
5916
|
+
}
|
|
5917
|
+
contactAdminOf(name, actor) {
|
|
5918
|
+
if (actor.platform === "host" && actor.adapterId === "host" && actor.userId === "operator")
|
|
5919
|
+
return true;
|
|
5920
|
+
const adapter = this.contactAdapter(name);
|
|
5921
|
+
if (!adapter || actor.adapterId !== adapter.id || actor.platform !== adapter.type)
|
|
5922
|
+
return false;
|
|
5923
|
+
return this.isFleetAdmin(actor.userId, adapter.id)
|
|
5924
|
+
|| (!!this.contactRoom(name) && this.classicChannels?.isAdmin(actor.userId) === true);
|
|
5925
|
+
}
|
|
5926
|
+
contactService() {
|
|
5927
|
+
this.ensureDeliveryOutbox();
|
|
5928
|
+
return new ContactAuthService({ store: this.deliveryOutbox.contactAuthorizations,
|
|
5929
|
+
restricted: name => this.contactRoom(name)?.restrictedMode === true,
|
|
5930
|
+
legacyClassic: name => !!this.contactRoom(name) && this.contactRoom(name)?.restrictedMode !== true,
|
|
5931
|
+
adminOf: (name, actor) => this.contactAdminOf(name, actor),
|
|
5932
|
+
defaultApprovers: name => {
|
|
5933
|
+
const adapter = this.contactAdapter(name);
|
|
5934
|
+
if (!adapter || (adapter.type !== "discord" && adapter.type !== "telegram"))
|
|
5935
|
+
return [];
|
|
5936
|
+
return (this.adminListOf(adapter.id) ?? []).map(userId => ({ platform: adapter.type, adapterId: adapter.id, userId, label: userId }));
|
|
5937
|
+
},
|
|
5938
|
+
generation: name => this.contactGeneration(name),
|
|
5939
|
+
hubRestricted: name => this.hubContactRestricted(name),
|
|
5940
|
+
delivered: ticket => !!ticket.deliveryId && this.deliveryOutbox.get(ticket.deliveryId)?.state === "delivered",
|
|
5941
|
+
deliveryState: ticket => ticket.deliveryId ? this.deliveryOutbox.get(ticket.deliveryId)?.state : undefined,
|
|
5942
|
+
admit: (request, ticketId) => {
|
|
5943
|
+
const payload = { ...request.payload, contactTicket: { id: ticketId, state: "delivered" } };
|
|
5944
|
+
const admitted = this.deliveryOutbox.admit({ operationId: request.operationId,
|
|
5945
|
+
sourceKey: `contact:${ticketId}`, sourceInstance: request.source,
|
|
5946
|
+
sourceDaemonBootId: this.getDaemonBootId(request.source) ?? request.sourceGeneration,
|
|
5947
|
+
targetInstance: request.target, targetSession: String(request.payload.targetSession ?? request.target),
|
|
5948
|
+
kind: String(request.payload.type ?? "fleet_inbound"), correlationId: request.correlationId,
|
|
5949
|
+
payload, forwards: request.forwards });
|
|
5950
|
+
this.scheduleDeliveryOutboxPump();
|
|
5951
|
+
return admitted.delivery.deliveryId;
|
|
5952
|
+
},
|
|
5953
|
+
changed: (instance, ticketId) => {
|
|
5954
|
+
const revision = this.deliveryOutbox.contactAuthorizations.policy(instance).revision;
|
|
5955
|
+
const ticket = ticketId ? this.deliveryOutbox.contactAuthorizations.get(ticketId) : undefined;
|
|
5956
|
+
if (ticket) {
|
|
5957
|
+
this.emitSseEvent("message", { instance: ticket.source, role: "status", sender: "AgEnD", ts: new Date().toISOString(),
|
|
5958
|
+
text: t(ticket.state === "pending" ? "contact.held" : ticket.state === "approved" ? "contact.approved" : "contact.updated"),
|
|
5959
|
+
contactTicket: { id: ticket.id, state: ticket.state } });
|
|
5960
|
+
if (ticket.state === "approved")
|
|
5961
|
+
this.emitSseEvent("message", { instance: ticket.target, role: "user",
|
|
5962
|
+
sender: ticket.source, text: ticket.message, ts: new Date().toISOString(), contactTicket: { id: ticket.id, state: "approved" } });
|
|
5963
|
+
}
|
|
5964
|
+
this.emitSseEvent("contact-auth", { instance, ...(ticketId ? { ticketId } : {}), revision });
|
|
5965
|
+
this.needsYou?.poke();
|
|
5966
|
+
this.emitSseEvent("needs", { items: this.needsYouItems() });
|
|
5967
|
+
},
|
|
5968
|
+
});
|
|
5969
|
+
}
|
|
5970
|
+
contactDeliveryCurrent(row) {
|
|
5971
|
+
const badge = row.payload.contactTicket;
|
|
5972
|
+
if (!badge)
|
|
5973
|
+
return true;
|
|
5974
|
+
if (typeof badge.id !== "string")
|
|
5975
|
+
return false;
|
|
5976
|
+
const service = this.contactService(), ticket = service.host.store.get(badge.id);
|
|
5977
|
+
return !!ticket && ticket.deliveryId === row.deliveryId && ticket.source === row.sourceInstance && ticket.target === row.targetInstance
|
|
5978
|
+
&& !!ticket.decidedBy && service.canManage(ticket.target, ticket.decidedBy)
|
|
5979
|
+
&& Date.parse(ticket.expiresAt) > Date.now()
|
|
5980
|
+
&& ticket.sourceGeneration === this.contactGeneration(ticket.source)
|
|
5981
|
+
&& ticket.targetGeneration === this.contactGeneration(ticket.target)
|
|
5982
|
+
&& !this.hubContactRestricted(ticket.source);
|
|
5983
|
+
}
|
|
5984
|
+
contactPermissions(name, actor) {
|
|
5985
|
+
const service = this.contactService(), room = this.contactRoom(name);
|
|
5986
|
+
const canManage = service.canManage(name, actor), canSetMode = !!room && this.contactAdminOf(name, actor);
|
|
5987
|
+
if (!canManage && !canSetMode)
|
|
5988
|
+
throw Error("forbidden");
|
|
5989
|
+
if (!this.webChatOwner(name))
|
|
5990
|
+
throw Error("not-found");
|
|
5991
|
+
const store = service.host.store, policy = store.policy(name, this.contactGeneration(name));
|
|
5992
|
+
const daemon = this.daemons.get(name);
|
|
5993
|
+
const backend = room ? this.classicChannels.getBackendByInstance(name, this.fleetConfig?.defaults?.backend) : this.fleetConfig?.instances[name]?.backend ?? "unknown";
|
|
5994
|
+
const nativeGuard = daemon?.classicNativeGuard?.() ?? { state: "not-covered", backend, reason: "Native guard is not loaded in this build", impactComplete: false };
|
|
5995
|
+
const removedTools = room ? [...toolsFor(resolveToolSet(this.fleetConfig?.instances[name], name))]
|
|
5996
|
+
.filter(tool => !CLASSIC_RESTRICTED_TOOLS.includes(tool)) : [];
|
|
5997
|
+
return { instance: name, revision: policy.revision, classicRoom: !!room,
|
|
5998
|
+
mode: room?.restrictedMode === true ? "restricted" : "legacy", approvers: service.approvers(name),
|
|
5999
|
+
eligibleApprovers: service.host.defaultApprovers(name),
|
|
6000
|
+
inheritedApprovers: policy.approvers === undefined,
|
|
6001
|
+
nativeGuard,
|
|
6002
|
+
canManage, canSetMode, suggestRestricted: !!room && room.restrictedMode !== true && !store.suggestionDismissed(name),
|
|
6003
|
+
roomTools: { ...policy.roomTools, wouldDisable: [...new Set([...removedTools, ...(nativeGuard.wouldDisable ?? [])])] }, grants: policy.grants, history: store.histories(name, this.contactGeneration(name)),
|
|
6004
|
+
...(service.needsApplication(name) ? { originRestriction: { active: true,
|
|
6005
|
+
reason: !service.origin(name) || service.origin(name)?.kind === "unknown" ? "unknown-origin" : "earlier-non-admin", resetSupported: false } } : {}) };
|
|
6006
|
+
}
|
|
6007
|
+
contactActor(req, url) {
|
|
6008
|
+
const verdict = evaluateWebRequest(req, url, this.webToken, this.webSessions, { touch: false });
|
|
6009
|
+
if (verdict.kind !== "allow" || verdict.via !== "session" || verdict.session.tier !== "admin")
|
|
6010
|
+
return null;
|
|
6011
|
+
const result = this.webAuthority({ session: verdict.session, gateway: !!gatewayRequestContext(req),
|
|
6012
|
+
peer: gatewayRequestContext(req) ? (gatewayRequestContext(req)?.named ? "named_link" : "quick_link") : classifyWebPeer(req) });
|
|
6013
|
+
const actor = result.authority.kind === "web-verified" ? result.authority.actor : null;
|
|
6014
|
+
if (!actor)
|
|
6015
|
+
return null;
|
|
6016
|
+
if (actor.adapter_id === "host" && actor.user_id === "operator")
|
|
6017
|
+
return { platform: "host", adapterId: "host", userId: "operator", label: "Operator" };
|
|
6018
|
+
const adapter = this.adapters.get(actor.adapter_id);
|
|
6019
|
+
if (!adapter || (adapter.type !== "discord" && adapter.type !== "telegram"))
|
|
6020
|
+
return null;
|
|
6021
|
+
return { platform: adapter.type, adapterId: actor.adapter_id, userId: actor.user_id, label: actor.user_id };
|
|
6022
|
+
}
|
|
6023
|
+
writeContactPermissions(name, raw, actor) {
|
|
6024
|
+
const parsed = ContactPermissionsSchema.safeParse(raw);
|
|
6025
|
+
if (!parsed.success)
|
|
6026
|
+
throw Error("invalid-request");
|
|
6027
|
+
const input = parsed.data, before = this.contactPermissions(name, actor), store = this.contactService().host.store;
|
|
6028
|
+
if ((input.approvers || input.grants) && !before.canManage)
|
|
6029
|
+
throw Error("forbidden");
|
|
6030
|
+
if (input.approvers?.some(person => !before.eligibleApprovers.some(allowed => sameContactPerson(person, allowed))))
|
|
6031
|
+
throw Error("invalid-approver");
|
|
6032
|
+
if ((input.mode || input.roomTools) && !before.canSetMode)
|
|
6033
|
+
throw Error("forbidden");
|
|
6034
|
+
if (input.grants?.some(grant => grant.target !== name || !this.webChatOwner(grant.source)
|
|
6035
|
+
|| Date.parse(grant.expiresAt) <= Date.now()))
|
|
6036
|
+
throw Error("invalid-grant");
|
|
6037
|
+
// Configuration does not prove an external MCP's account independence. Preserve a conservative warning.
|
|
6038
|
+
if (input.roomTools)
|
|
6039
|
+
input.roomTools.allowedMcpTools = input.roomTools.allowedMcpTools.map(tool => ({ ...tool,
|
|
6040
|
+
usesOwnerAccount: true, accountWarning: t("contact.mcpAccountWarning") }));
|
|
6041
|
+
if (input.revision !== before.revision)
|
|
6042
|
+
throw Error("conflict");
|
|
6043
|
+
// Mode persists in the existing Classic configuration; absent historical fields remain legacy.
|
|
6044
|
+
if (input.mode) {
|
|
6045
|
+
if (input.mode === "restricted" && before.mode !== "restricted")
|
|
6046
|
+
store.inheritOrigin(name, { kind: "unknown", people: [], receiptIds: [], chain: [name] });
|
|
6047
|
+
this.classicChannels.setRestrictedMode(name, input.mode === "restricted");
|
|
6048
|
+
}
|
|
6049
|
+
const policy = store.writePolicy(name, input, actor, instance => this.contactGeneration(instance));
|
|
6050
|
+
const daemon = this.daemons.get(name);
|
|
6051
|
+
daemon?.setClassicRestriction?.({ mode: this.contactRoom(name)?.restrictedMode === true ? "restricted" : "legacy",
|
|
6052
|
+
roomTools: policy.roomTools, policyRevision: policy.revision });
|
|
6053
|
+
this.emitSseEvent("contact-auth", { instance: name, revision: policy.revision });
|
|
6054
|
+
this.needsYou?.poke();
|
|
6055
|
+
this.emitSseEvent("needs", { items: this.needsYouItems() });
|
|
6056
|
+
return this.contactPermissions(name, actor);
|
|
6057
|
+
}
|
|
6058
|
+
contactAuthorization(id, actor) {
|
|
6059
|
+
const service = this.contactService(), ticket = service.host.store.get(id);
|
|
6060
|
+
if (!ticket)
|
|
6061
|
+
throw Error("not-found");
|
|
6062
|
+
return service.view(ticket, actor);
|
|
6063
|
+
}
|
|
6064
|
+
contactAuthorizations(actor, filter) {
|
|
6065
|
+
const service = this.contactService(), page = service.host.store.list({ ...filter, status: undefined });
|
|
6066
|
+
return { ...page, items: page.items.flatMap(ticket => {
|
|
6067
|
+
try {
|
|
6068
|
+
const view = service.view(ticket, actor);
|
|
6069
|
+
if (filter.status && view.state !== filter.status)
|
|
6070
|
+
return [];
|
|
6071
|
+
if (filter.person && !view.origin.people.some(person => JSON.stringify([person.platform, person.adapterId, person.userId]) === filter.person))
|
|
6072
|
+
return [];
|
|
6073
|
+
return [view];
|
|
6074
|
+
}
|
|
6075
|
+
catch {
|
|
6076
|
+
return [];
|
|
6077
|
+
}
|
|
6078
|
+
}) };
|
|
6079
|
+
}
|
|
6080
|
+
decideContactAuthorization(id, decision, actor) {
|
|
6081
|
+
return this.contactService().decide(id, decision, actor);
|
|
6082
|
+
}
|
|
6083
|
+
contactNeeds(actor) {
|
|
6084
|
+
const service = this.contactService();
|
|
6085
|
+
const pending = service.host.store.pending()
|
|
6086
|
+
.filter(ticket => { try {
|
|
6087
|
+
return service.view(ticket, actor).canDecide;
|
|
6088
|
+
}
|
|
6089
|
+
catch {
|
|
6090
|
+
return false;
|
|
6091
|
+
} }).map(ticket => ({
|
|
6092
|
+
id: `contact:${ticket.id}`, type: "contact", reason: "contact_request", instance: ticket.target,
|
|
6093
|
+
since: Date.parse(ticket.createdAt), detail: "", contactTicket: { id: ticket.id, source: ticket.source, target: ticket.target },
|
|
6094
|
+
}));
|
|
6095
|
+
return [...pending, ...(this.classicChannels?.getAll() ?? []).filter(room => room.restrictedMode !== true
|
|
6096
|
+
&& !service.host.store.suggestionDismissed(room.instanceName) && this.contactAdminOf(room.instanceName, actor))
|
|
6097
|
+
.map(room => ({ id: `contact-suggest:${room.instanceName}`, type: "contact",
|
|
6098
|
+
reason: "contact_restricted_suggestion", instance: room.instanceName,
|
|
6099
|
+
since: Date.parse(room.createdAt) || 0, detail: "", contactSuggestion: { instance: room.instanceName } }))];
|
|
6100
|
+
}
|
|
6101
|
+
contactSuggestions() {
|
|
6102
|
+
const rooms = this.classicChannels?.getAll().filter(room => room.restrictedMode !== true) ?? [];
|
|
6103
|
+
const store = this.contactService().host.store;
|
|
6104
|
+
const pending = store.pending().map(ticket => ({ id: `contact:${ticket.id}`, type: "contact",
|
|
6105
|
+
reason: "contact_request", instance: ticket.target, owner: this.getAdapterForInstance(ticket.target)?.id,
|
|
6106
|
+
since: Date.parse(ticket.createdAt), detail: "", contactTicket: { id: ticket.id, source: ticket.source, target: ticket.target } }));
|
|
6107
|
+
return [...pending, ...rooms.filter(room => !store.suggestionDismissed(room.instanceName)).map(room => ({
|
|
6108
|
+
id: `contact-suggest:${room.instanceName}`, type: "contact", reason: "contact_restricted_suggestion",
|
|
6109
|
+
instance: room.instanceName, owner: this.getAdapterForInstance(room.instanceName)?.id,
|
|
6110
|
+
since: Date.parse(room.createdAt) || 0, detail: t("contact.suggest"), contactSuggestion: { instance: room.instanceName },
|
|
6111
|
+
}))];
|
|
6112
|
+
}
|
|
6113
|
+
acknowledgeContactSuggestion(instance, actor) {
|
|
6114
|
+
if (!this.contactAdminOf(instance, actor) || !this.contactRoom(instance))
|
|
6115
|
+
throw Error("forbidden");
|
|
6116
|
+
this.contactService().host.store.dismissSuggestion(instance);
|
|
6117
|
+
this.emitSseEvent("needs", { items: this.needsYouItems() });
|
|
6118
|
+
this.needsYou?.poke();
|
|
6119
|
+
}
|
|
5807
6120
|
/** Synchronous SQLite admission; the caller may acknowledge only after this returns. */
|
|
5808
6121
|
admitDurableDelivery(input) {
|
|
5809
6122
|
const bindingHold = this.generalLocationDeliveryHold(input.targetInstance);
|
|
@@ -5817,6 +6130,24 @@ export class FleetManager {
|
|
|
5817
6130
|
if (!currentSourceBootId || !sourceDaemonBootId || currentSourceBootId !== sourceDaemonBootId) {
|
|
5818
6131
|
throw new Error("Source daemon generation is no longer current; outcome is unknown");
|
|
5819
6132
|
}
|
|
6133
|
+
const service = this.contactService();
|
|
6134
|
+
const metadata = input.payload.meta;
|
|
6135
|
+
const requestKind = metadata?.request_kind;
|
|
6136
|
+
const authorizationDeliveryId = service.requireApplication({ operationId: input.operationId, source: input.sourceInstance, target: input.targetInstance,
|
|
6137
|
+
verb: input.kind === "broadcast" ? "broadcast" : requestKind === "task" ? "delegate_task" : requestKind === "query" ? "request_information"
|
|
6138
|
+
: requestKind === "report" ? "report_result" : "send_to_instance",
|
|
6139
|
+
message: String(input.payload.content ?? ""), correlationId: input.correlationId,
|
|
6140
|
+
correlationExplicit: input.correlationExplicit ?? true,
|
|
6141
|
+
resultRecipient: input.sourceInstance, payload: input.payload, forwards: input.forwards });
|
|
6142
|
+
if (authorizationDeliveryId) {
|
|
6143
|
+
const delivery = outbox.get(authorizationDeliveryId);
|
|
6144
|
+
if (!delivery)
|
|
6145
|
+
throw Error("Authorized delivery is unavailable");
|
|
6146
|
+
return { deliveryId: delivery.deliveryId, state: delivery.state, duplicate: true, kind: delivery.kind };
|
|
6147
|
+
}
|
|
6148
|
+
const inheritedOrigin = service.origin(input.sourceInstance);
|
|
6149
|
+
if (inheritedOrigin && !service.host.legacyClassic?.(input.sourceInstance))
|
|
6150
|
+
service.host.store.inheritOrigin(input.targetInstance, { ...inheritedOrigin, chain: [...inheritedOrigin.chain, input.targetInstance] });
|
|
5820
6151
|
const sourceKey = `mcp:${input.sourceInstance}:${input.operationId}:${input.targetInstance}:${input.targetSession ?? ""}:${input.kind}`;
|
|
5821
6152
|
const admitted = outbox.admit({ ...input, sourceDaemonBootId, sourceKey });
|
|
5822
6153
|
if (admitted.inserted)
|
|
@@ -6354,11 +6685,15 @@ export class FleetManager {
|
|
|
6354
6685
|
};
|
|
6355
6686
|
sent = await this.deliverToInstance(target, payload, {
|
|
6356
6687
|
isCrossInstance: true,
|
|
6688
|
+
stillCurrent: () => this.contactDeliveryCurrent(claimed),
|
|
6357
6689
|
waitForIdle: claimed.kind !== "steer",
|
|
6358
6690
|
noInlineWake: this.deliveryWorkerMode(target) !== "off",
|
|
6359
6691
|
});
|
|
6360
6692
|
}
|
|
6361
6693
|
if (!sent) {
|
|
6694
|
+
if (payload.contactTicket && !this.contactDeliveryCurrent(claimed)) {
|
|
6695
|
+
outbox.cancelUnsubmittedContact(claimed.deliveryId, "Contact approval became stale before input");
|
|
6696
|
+
}
|
|
6362
6697
|
const current = outbox.get(claimed.deliveryId);
|
|
6363
6698
|
if (current?.state === "delivering") {
|
|
6364
6699
|
outbox.retryBeforeBegin(claimed.deliveryId, claimed.targetDaemonBootId, claimed.attemptNo, "delivery was cancelled before target IPC handoff", Math.min(60_000, 1_000 * 2 ** Math.min(attempt - 1, 6)));
|
|
@@ -6396,8 +6731,8 @@ export class FleetManager {
|
|
|
6396
6731
|
}
|
|
6397
6732
|
const meta = claimed.payload.meta && typeof claimed.payload.meta === "object" ? claimed.payload.meta : {};
|
|
6398
6733
|
const task = await this.nativeInstanceRuntime().execute(target, { ...claimed.payload, requestId: deliveryId, meta: { ...meta, from_instance: claimed.sourceInstance, correlation_id: claimed.correlationId } }, {
|
|
6399
|
-
stillCurrent: () => !this.shuttingDown,
|
|
6400
|
-
beforeStart: () => { if (outbox.begin(deliveryId, targetDaemonBootId, attemptNo) !== "begun")
|
|
6734
|
+
stillCurrent: () => !this.shuttingDown && this.contactDeliveryCurrent(claimed),
|
|
6735
|
+
beforeStart: () => { if (!this.contactDeliveryCurrent(claimed) || outbox.begin(deliveryId, targetDaemonBootId, attemptNo) !== "begun")
|
|
6401
6736
|
throw new Error("Windows delivery attempt is no longer current"); begun = true; },
|
|
6402
6737
|
});
|
|
6403
6738
|
const outcome = task.outcomeConfirmed === false ? "uncertain" : task.status === "completed" ? "delivered" : "failed";
|
|
@@ -6415,6 +6750,8 @@ export class FleetManager {
|
|
|
6415
6750
|
const reason = error instanceof Error ? error.message : String(error);
|
|
6416
6751
|
if (begun)
|
|
6417
6752
|
outbox.complete(deliveryId, targetDaemonBootId, attemptNo, "uncertain", reason);
|
|
6753
|
+
else if (claimed.payload.contactTicket && !this.contactDeliveryCurrent(claimed))
|
|
6754
|
+
outbox.cancelUnsubmittedContact(deliveryId, "Contact approval became stale before input");
|
|
6418
6755
|
else
|
|
6419
6756
|
outbox.retryBeforeBegin(deliveryId, targetDaemonBootId, attemptNo, reason, 5000);
|
|
6420
6757
|
this.logger.warn({ target, deliveryId, err: reason }, "Windows durable delivery did not complete");
|
|
@@ -8511,6 +8848,26 @@ export class FleetManager {
|
|
|
8511
8848
|
return payload;
|
|
8512
8849
|
const row = this.deliveryOutbox.createHumanReceipt({ targetInstance: instanceName, originalBody,
|
|
8513
8850
|
origin: { ...origin }, inputKind: String(payload.type), managerBootId: this.managerBootId });
|
|
8851
|
+
const contactStore = this.deliveryOutbox.contactAuthorizations;
|
|
8852
|
+
if (this.contactRoom(instanceName)?.restrictedMode === true && !contactStore)
|
|
8853
|
+
throw Error("Contact origin storage unavailable");
|
|
8854
|
+
if (contactStore && (this.contactRoom(instanceName)?.restrictedMode === true || contactStore.origin(instanceName))) {
|
|
8855
|
+
const authority = origin.authority;
|
|
8856
|
+
const actor = origin.platform === "web" ? (authority?.kind === "web-verified" ? authority.actor : null)
|
|
8857
|
+
: { adapter_id: origin.adapter_id, user_id: origin.user_id };
|
|
8858
|
+
const adapter = actor?.adapter_id ? this.adapters.get(actor.adapter_id) : undefined;
|
|
8859
|
+
const platform = origin.platform === "web" ? adapter?.type : origin.platform;
|
|
8860
|
+
const person = actor?.adapter_id && actor.user_id
|
|
8861
|
+
&& (platform === "discord" || platform === "telegram" || (actor.adapter_id === "host" && actor.user_id === "operator"))
|
|
8862
|
+
? { platform: actor.adapter_id === "host" ? "host" : platform,
|
|
8863
|
+
adapterId: actor.adapter_id, userId: actor.user_id, label: origin.username ?? actor.user_id } : undefined;
|
|
8864
|
+
contactStore.inheritOrigin(instanceName, { kind: person ? "human" : "unknown", people: person ? [person] : [],
|
|
8865
|
+
receiptIds: [row.message_id], chain: [instanceName] });
|
|
8866
|
+
if (this.contactRoom(instanceName)?.restrictedMode === true && (!person || !this.contactAdminOf(instanceName, person))
|
|
8867
|
+
&& typeof payload.content === "string" && (payload.type === "fleet_inbound" || payload.type === "steer")) {
|
|
8868
|
+
payload = { ...payload, content: `${t(person ? "contact.originNonAdmin" : "contact.originUnknown")}\n\n${payload.content}` };
|
|
8869
|
+
}
|
|
8870
|
+
}
|
|
8514
8871
|
// #1939 §7: each ordinary verified web message, for the S1 beta to watch. No text, cookie or session id: the handle.
|
|
8515
8872
|
const authority = origin.authority;
|
|
8516
8873
|
if (authority?.kind === "web-verified" && authority.actor && authority.session) {
|
|
@@ -8955,8 +9312,7 @@ export class FleetManager {
|
|
|
8955
9312
|
await this.handleTipsSlash(data, adapterId);
|
|
8956
9313
|
}
|
|
8957
9314
|
else if (data.command === "status") {
|
|
8958
|
-
// Admin-gated
|
|
8959
|
-
// instance's cost and IPC health.
|
|
9315
|
+
// Admin-gated, like the topic path: use the shared fleet instance table.
|
|
8960
9316
|
if (!this.isFleetAdmin(data.userId, adapterId)) {
|
|
8961
9317
|
await data.respond(t("cmd.admin_required", "/status"));
|
|
8962
9318
|
return;
|
|
@@ -14879,6 +15235,8 @@ export class FleetManager {
|
|
|
14879
15235
|
}
|
|
14880
15236
|
const channelName = msg.username || chatId;
|
|
14881
15237
|
if (requestedBackend) {
|
|
15238
|
+
// Advisory before the new-room policy is persisted, including direct /start BACKEND.
|
|
15239
|
+
await msgAdapter?.sendText(chatId, this.getClassicStartWarning(requestedBackend));
|
|
14882
15240
|
// handleClassicStart binds the instance to this adapter authoritatively.
|
|
14883
15241
|
const reply = await this.handleClassicStart(chatId, channelName, msg.userId, undefined, msg.adapterId, requestedBackend);
|
|
14884
15242
|
await msgAdapter?.sendText(chatId, reply);
|
|
@@ -15387,6 +15745,9 @@ export class FleetManager {
|
|
|
15387
15745
|
}
|
|
15388
15746
|
}
|
|
15389
15747
|
checkToolPermission(sink, instanceName, tool) {
|
|
15748
|
+
if (this.classicChannels?.getAll?.().some(room => room.instanceName === instanceName && room.restrictedMode === true) && !CLASSIC_RESTRICTED_TOOLS.includes(tool)) {
|
|
15749
|
+
return { allowed: false, message: "This Classic room is restricted. This tool is not in its room tool allowance." };
|
|
15750
|
+
}
|
|
15390
15751
|
if (isCanvasWorkerTool(tool))
|
|
15391
15752
|
return { allowed: false, message: CANVAS_WORKER_EXPERIMENTAL_MESSAGE }; // #2799: removed
|
|
15392
15753
|
const profile = resolveToolSet(this.fleetConfig?.instances[instanceName], instanceName);
|
|
@@ -15482,7 +15843,7 @@ export class FleetManager {
|
|
|
15482
15843
|
return;
|
|
15483
15844
|
}
|
|
15484
15845
|
// #2305: a reaction to a web chat message is the web chat's own (any fleet, web-only included): never an adapter's.
|
|
15485
|
-
if (tool === "react" && typeof args.message_id === "string" && isWebMessageId(args.message_id)) {
|
|
15846
|
+
if (tool === "react" && !this.classicChannels?.getAll?.().some(room => room.instanceName === instanceName && room.restrictedMode === true) && typeof args.message_id === "string" && isWebMessageId(args.message_id)) {
|
|
15486
15847
|
// The socket's own instance, never a session name the caller wrote itself (as checkToolPermission: it was not
|
|
15487
15848
|
// identified) — a channel tool's call from a daemon carries none anyway (#2310 review).
|
|
15488
15849
|
const r = await this.reactToWebMessage(instanceName, args.message_id, args.emoji);
|
|
@@ -15502,9 +15863,29 @@ export class FleetManager {
|
|
|
15502
15863
|
: "Channel adapters are not ready — retry shortly");
|
|
15503
15864
|
return;
|
|
15504
15865
|
}
|
|
15866
|
+
const restrictedRoute = this.restrictedClassicRouting(instanceName);
|
|
15867
|
+
const restrictedIncarnation = restrictedRoute ? this.contactGeneration(instanceName) : undefined;
|
|
15868
|
+
const restrictedBoot = restrictedRoute ? this.getDaemonBootId(instanceName) : undefined;
|
|
15869
|
+
if (restrictedRoute && Array.isArray(args.previews) && args.previews.length) {
|
|
15870
|
+
respond(null, "File previews are not available in restricted rooms; use the room's own attachments");
|
|
15871
|
+
return;
|
|
15872
|
+
}
|
|
15873
|
+
let replyBookkeeping = Promise.resolve();
|
|
15874
|
+
const restrictedExtras = restrictedRoute ? {
|
|
15875
|
+
prepareFiles: (paths) => this.prepareContactFiles(instanceName, paths),
|
|
15876
|
+
replyFinished: () => replyBookkeeping,
|
|
15877
|
+
downloadAttachment: (id) => this.downloadRoomAttachment(instanceName, id),
|
|
15878
|
+
beforeSend: () => {
|
|
15879
|
+
const current = this.restrictedClassicRouting(instanceName);
|
|
15880
|
+
if (!current || current.adapterId !== restrictedRoute.adapterId || current.chatId !== restrictedRoute.chatId
|
|
15881
|
+
|| current.threadId !== restrictedRoute.threadId || this.contactGeneration(instanceName) !== restrictedIncarnation
|
|
15882
|
+
|| this.getDaemonBootId(instanceName) !== restrictedBoot)
|
|
15883
|
+
throw Error("Restricted room route changed before delivery");
|
|
15884
|
+
},
|
|
15885
|
+
} : {};
|
|
15505
15886
|
// Resolve threadId: use sender's topic_id if sender is a known fleet instance,
|
|
15506
15887
|
// fall back to general topic if sender is unknown, or IPC owner if no sender.
|
|
15507
|
-
const senderInstanceName = senderSessionName && this.fleetConfig?.instances[senderSessionName]
|
|
15888
|
+
const senderInstanceName = !restrictedRoute && senderSessionName && this.fleetConfig?.instances[senderSessionName]
|
|
15508
15889
|
? senderSessionName
|
|
15509
15890
|
: null;
|
|
15510
15891
|
const routingConfig = senderInstanceName
|
|
@@ -15516,9 +15897,9 @@ export class FleetManager {
|
|
|
15516
15897
|
// ids are scoped to that bot/world; routing a secondary-world id through the
|
|
15517
15898
|
// primary adapter produces a 404. Instance binding remains the compatibility
|
|
15518
15899
|
// fallback for older daemons and calls without a live/persisted context.
|
|
15519
|
-
const contextAdapterId = typeof msg.adapterId === "string" && msg.adapterId
|
|
15900
|
+
const contextAdapterId = restrictedRoute?.adapterId ?? (typeof msg.adapterId === "string" && msg.adapterId
|
|
15520
15901
|
? msg.adapterId
|
|
15521
|
-
: undefined;
|
|
15902
|
+
: undefined);
|
|
15522
15903
|
const contextWorld = contextAdapterId ? this.worlds.get(contextAdapterId) : undefined;
|
|
15523
15904
|
if (contextAdapterId && !contextWorld) {
|
|
15524
15905
|
respond(null, `Adapter world unavailable: ${contextAdapterId}`);
|
|
@@ -15552,6 +15933,14 @@ export class FleetManager {
|
|
|
15552
15933
|
threadId = undefined;
|
|
15553
15934
|
}
|
|
15554
15935
|
}
|
|
15936
|
+
if (restrictedRoute) {
|
|
15937
|
+
args.chat_id = restrictedRoute.chatId;
|
|
15938
|
+
threadId = restrictedRoute.threadId;
|
|
15939
|
+
if (threadId)
|
|
15940
|
+
args.thread_id = threadId;
|
|
15941
|
+
else
|
|
15942
|
+
delete args.thread_id;
|
|
15943
|
+
}
|
|
15555
15944
|
// Reply dedup: retries land here when the agent was told a send failed
|
|
15556
15945
|
// (daemon budget elapsed, shell tool killed) while the adapter send was
|
|
15557
15946
|
// still in flight and about to succeed. One real send, everyone gets its
|
|
@@ -15668,7 +16057,8 @@ export class FleetManager {
|
|
|
15668
16057
|
&& this.landedInOwnChannel(instanceName, replyAdapterId, result);
|
|
15669
16058
|
}
|
|
15670
16059
|
catch { /* not known: not the channel's (fail closed), and the bookkeeping below still runs */ }
|
|
15671
|
-
|
|
16060
|
+
replyBookkeeping = this.afterReplyRouted(instanceName, args, senderSessionName, buttonsView, inChannel, replyAdapterId ? { adapterId: replyAdapterId, result } : undefined, replyIdentity, result)
|
|
16061
|
+
.catch(err => { this.logger.warn({ err, instanceName }, "Reply bookkeeping failed after confirmed delivery"); });
|
|
15672
16062
|
}
|
|
15673
16063
|
catch (err) {
|
|
15674
16064
|
this.logger.warn({ err, instanceName }, "Reply delivered but post-delivery bookkeeping failed");
|
|
@@ -15683,7 +16073,7 @@ export class FleetManager {
|
|
|
15683
16073
|
});
|
|
15684
16074
|
}
|
|
15685
16075
|
};
|
|
15686
|
-
if (routeToolCall(outAdapter, tool, args, threadId, respondAndRecord, replySet ? { replyButtons: replySet.callbacks, ...(replySet.poll ? { replyPoll: replySet.poll } : {}) } : {})) {
|
|
16076
|
+
if (routeToolCall(outAdapter, tool, args, threadId, respondAndRecord, { ...restrictedExtras, ...(replySet ? { replyButtons: replySet.callbacks, ...(replySet.poll ? { replyPoll: replySet.poll } : {}) } : {}) })) {
|
|
15687
16077
|
return;
|
|
15688
16078
|
}
|
|
15689
16079
|
if (replySet)
|
|
@@ -15694,7 +16084,7 @@ export class FleetManager {
|
|
|
15694
16084
|
return;
|
|
15695
16085
|
}
|
|
15696
16086
|
// Route standard channel tools (reply, react, edit_message, download_attachment)
|
|
15697
|
-
if (routeToolCall(outAdapter, tool, args, threadId, respond)) {
|
|
16087
|
+
if (routeToolCall(outAdapter, tool, args, threadId, respond, restrictedExtras)) {
|
|
15698
16088
|
return;
|
|
15699
16089
|
}
|
|
15700
16090
|
if (handler) {
|
|
@@ -16487,6 +16877,10 @@ export class FleetManager {
|
|
|
16487
16877
|
if (op !== "list") {
|
|
16488
16878
|
const profile = resolveToolSet(this.fleetConfig?.instances[caller], caller);
|
|
16489
16879
|
const existing = op === "create" ? null : scheduler.get(args.id);
|
|
16880
|
+
const effectiveTarget = requestedTarget?.trim() || existing?.target || caller;
|
|
16881
|
+
if ((op === "create" || op === "update") && effectiveTarget !== caller && this.contactService().needsApplication(caller)) {
|
|
16882
|
+
throw new ToolNotPermittedError("Scheduled peer contact needs approval. Use a contact application instead; this conversation's origin remains restricted.");
|
|
16883
|
+
}
|
|
16490
16884
|
const refusal = scheduleOpRefusal(profile, caller, op, { requestedTarget, existing });
|
|
16491
16885
|
if (refusal) {
|
|
16492
16886
|
this.logger.warn({ instance: caller, profile, op, target: requestedTarget ?? existing?.target, scheduleId: args.id }, "tool-permissions: schedule op refused");
|
|
@@ -20183,6 +20577,7 @@ export class FleetManager {
|
|
|
20183
20577
|
return owner !== undefined && this.worlds.has(owner) ? owner : undefined;
|
|
20184
20578
|
};
|
|
20185
20579
|
this.needsYou = new NeedsYouHub({
|
|
20580
|
+
contactSuggestions: () => this.contactSuggestions(),
|
|
20186
20581
|
dataDir: this.dataDir,
|
|
20187
20582
|
now: () => Date.now(),
|
|
20188
20583
|
mono: () => performance.now(),
|
|
@@ -24221,7 +24616,9 @@ export class FleetManager {
|
|
|
24221
24616
|
const installable = new Set(Object.keys(BACKEND_INSTALLATION_INFO));
|
|
24222
24617
|
const candidates = new Set([...installed, ...configured, ...installable]);
|
|
24223
24618
|
const unsupported = [];
|
|
24619
|
+
const details = [];
|
|
24224
24620
|
const choices = [...candidates].sort().flatMap(backend => {
|
|
24621
|
+
const label = backend === "claude-code" ? "Claude" : BACKEND_LABELS[backend] ?? backend;
|
|
24225
24622
|
const flow = LOGIN_FLOWS[backend];
|
|
24226
24623
|
const remoteLogin = !!flow && flow.remoteLogin !== "unsupported";
|
|
24227
24624
|
const isInstalled = installed.has(backend);
|
|
@@ -24231,11 +24628,13 @@ export class FleetManager {
|
|
|
24231
24628
|
status.push(t("login.status_configured"));
|
|
24232
24629
|
if (!isInstalled && installable.has(backend)) {
|
|
24233
24630
|
status.push(t(remoteLogin ? "login.status_install_then_auth" : "login.status_install"));
|
|
24234
|
-
|
|
24631
|
+
details.push(`${label} · ${status.join(" · ")}`);
|
|
24632
|
+
return [{ action: backend, label }];
|
|
24235
24633
|
}
|
|
24236
24634
|
if (remoteLogin && isInstalled) {
|
|
24237
24635
|
status.push(t("login.status_auth"));
|
|
24238
|
-
|
|
24636
|
+
details.push(`${label} · ${status.join(" · ")}`);
|
|
24637
|
+
return [{ action: backend, label }];
|
|
24239
24638
|
}
|
|
24240
24639
|
status.push(t("login.status_unsupported"));
|
|
24241
24640
|
unsupported.push({ backend, flow, status });
|
|
@@ -24269,7 +24668,7 @@ export class FleetManager {
|
|
|
24269
24668
|
adapterId: chat.adapterId,
|
|
24270
24669
|
chatId: chat.chatId,
|
|
24271
24670
|
threadId: chat.threadId,
|
|
24272
|
-
message: `${t("login.choose_backend")}\n${t("fleet.label_line", fleetLabel(this.fleetConfig))}`,
|
|
24671
|
+
message: `${t("login.choose_backend")}\n${t("fleet.label_line", fleetLabel(this.fleetConfig))}\n\n${details.join("\n")}`,
|
|
24273
24672
|
choices,
|
|
24274
24673
|
expiredText: t("buttons.stale"),
|
|
24275
24674
|
});
|
|
@@ -25317,6 +25716,7 @@ export class FleetManager {
|
|
|
25317
25716
|
cards: m.cards,
|
|
25318
25717
|
posts: m.posts, // #2281: kept beside the row, never broadcast (not a row field)
|
|
25319
25718
|
reserved: m.reserved, // #1774: an agent reply's place, taken when it was sent
|
|
25719
|
+
contactTicket: m.contactTicket,
|
|
25320
25720
|
});
|
|
25321
25721
|
// A sending page's own id for its pending bubble rides on the live copy only: never recorded, never replayed.
|
|
25322
25722
|
const clientId = typeof data.clientId === "string" ? data.clientId : "";
|
|
@@ -26228,6 +26628,9 @@ export class FleetManager {
|
|
|
26228
26628
|
// #1085: a Telegram forum ClassicBot is keyed by chat id (threadId), but the
|
|
26229
26629
|
// reply context must carry the topic the message was really asked in.
|
|
26230
26630
|
const replyThreadId = msg.transportThreadId ?? msg.threadId;
|
|
26631
|
+
const contactAdapter = this.worlds.get(msg.adapterId ?? "")?.adapter;
|
|
26632
|
+
if (contactAdapter)
|
|
26633
|
+
this.recordClassicContactInput(instanceName, msg, contactAdapter);
|
|
26231
26634
|
// Resolve the channel/adapter from the instance itself so per-channel context
|
|
26232
26635
|
// config is correct even for a same-channel second bot.
|
|
26233
26636
|
const ctxAdapterId = this.classicChannels?.getAdapterIdByInstance(instanceName);
|
|
@@ -28596,6 +28999,10 @@ export class FleetManager {
|
|
|
28596
28999
|
return undefined;
|
|
28597
29000
|
return t("classic.backend_not_installed", backend, installation.binary, installation.install);
|
|
28598
29001
|
}
|
|
29002
|
+
/** Coverage is not proven before launch; disclose the fallback without blocking an unsupported CLI. */
|
|
29003
|
+
getClassicStartWarning(backend) {
|
|
29004
|
+
return [t("classic.restricted_start_notice"), this.getMissingBackendWarning(backend)].filter(Boolean).join("\n\n");
|
|
29005
|
+
}
|
|
28599
29006
|
/** Handle Discord's required static slash choice, warning before a likely startup failure. */
|
|
28600
29007
|
async handleClassicStartSlash(data, adapterId) {
|
|
28601
29008
|
return withSpawnHoldReply(text => data.respond(text), () => this.handleClassicStartSlashCore(data, adapterId));
|
|
@@ -28616,7 +29023,7 @@ export class FleetManager {
|
|
|
28616
29023
|
await data.respond(blocker);
|
|
28617
29024
|
return;
|
|
28618
29025
|
}
|
|
28619
|
-
const warning = this.
|
|
29026
|
+
const warning = this.getClassicStartWarning(requestedBackend);
|
|
28620
29027
|
// Keep the deferred ephemeral response useful even if daemon startup later
|
|
28621
29028
|
// fails because the executable is absent. This is advisory, not a gate.
|
|
28622
29029
|
if (warning)
|
|
@@ -28670,8 +29077,8 @@ export class FleetManager {
|
|
|
28670
29077
|
this.pendingClassicStarts.set(nonce, pending);
|
|
28671
29078
|
try {
|
|
28672
29079
|
pending.messageId = data.respondChoices
|
|
28673
|
-
? await data.respondChoices(t("classic.choose_backend")
|
|
28674
|
-
: await adapter.promptUser(data.channelId, t("classic.choose_backend")
|
|
29080
|
+
? await data.respondChoices(`${t("classic.choose_backend")}\n\n${t("classic.restricted_start_notice")}`, choices)
|
|
29081
|
+
: await adapter.promptUser(data.channelId, `${t("classic.choose_backend")}\n\n${t("classic.restricted_start_notice")}`, choices);
|
|
28675
29082
|
}
|
|
28676
29083
|
catch (err) {
|
|
28677
29084
|
// A menu transport failure should not make /start unusable: consume the
|
|
@@ -28712,7 +29119,7 @@ export class FleetManager {
|
|
|
28712
29119
|
?? this.classicChannels?.getDefaults().backend
|
|
28713
29120
|
?? this.fleetConfig?.defaults?.backend
|
|
28714
29121
|
?? "claude-code";
|
|
28715
|
-
const warning = this.
|
|
29122
|
+
const warning = this.getClassicStartWarning(effectiveBackend);
|
|
28716
29123
|
// Show the warning before starting so it survives a missing-binary startup
|
|
28717
29124
|
// failure. The selected backend is still attempted as requested.
|
|
28718
29125
|
if (warning)
|