[SDK] Swap moderation to @bsky.app/sdk and move labeler config to Client statics (#11383)

This commit is contained in:
Samuel Newman
2026-08-13 22:26:21 +03:00
committed by GitHub
parent dc31e7fd12
commit 59d2bf09d7
138 changed files with 601 additions and 416 deletions
+34 -9
View File
@@ -1,8 +1,12 @@
import {AtpAgent, BSKY_LABELER_DID} from '@atproto/api'
import {type AtpAgent, BSKY_LABELER_DID} from '@atproto/api'
import {type Client} from '@atproto/lex'
import {IS_TEST_USER} from '#/lib/constants'
import {account as accountStorage} from '#/storage'
import {configureAdditionalModerationAuthorities} from './additional-moderation-authorities'
import {
configureAdditionalModerationAuthorities,
configureGlobalAppLabelers,
} from './additional-moderation-authorities'
import {type SessionAccount} from './types'
/**
@@ -26,6 +30,29 @@ export function readLabelers(did: string): string[] | undefined {
}
}
/**
* Apply an account's labeler subscriptions without duplicating the globally
* redacted Bluesky moderation authority.
*
* The Bluesky DID is filtered out because it already flows through the global
* `appLabelers`, which lex and the agent both emit with a `;redact` suffix.
* Listing it per-subscription would add a second, non-redacting entry for the
* same authority.
*
* Writes to the agent rather than the client: the agent-level fetch handler is
* what stamps `atproto-accept-labelers` on the requests the wrapping clients
* issue, so setting them here reaches every appview read. The bundle rework
* moves this to `appviewClient.setLabelers` once the agent is gone.
*/
export function applyLabelersToClient(
agent: AtpAgent,
subscribedDids: string[],
) {
agent.configureLabelersHeader(
subscribedDids.filter(did => did !== BSKY_LABELER_DID),
)
}
export function configureModerationForGuest() {
// This global mutation is *only* OK because this code is only relevant for testing.
// Don't add any other global behavior here!
@@ -39,7 +66,7 @@ export function configureModerationForGuest() {
* in the same tick, before any request goes out.
*/
export function configureModerationForAccount(
agent: AtpAgent,
bundle: {agent: AtpAgent; appviewClient?: Client},
account: SessionAccount,
) {
// This global mutation is *only* OK because this code is only relevant for testing.
@@ -47,15 +74,13 @@ export function configureModerationForAccount(
switchToBskyAppLabeler()
if (IS_TEST_USER(account.handle)) {
// Test accounts may briefly use the production authority while this resolves.
void trySwitchToTestAppLabeler(agent)
void trySwitchToTestAppLabeler(bundle.agent)
}
// The code below is actually relevant to production (and isn't global).
const labelerDids = readLabelers(account.did)
if (labelerDids) {
agent.configureLabelersHeader(
labelerDids.filter(did => did !== BSKY_LABELER_DID),
)
applyLabelersToClient(bundle.agent, labelerDids)
} else {
// If there are no headers in the storage, we'll not send them on the initial requests.
// If we wanted to fix this, we could block on the preferences query here.
@@ -65,7 +90,7 @@ export function configureModerationForAccount(
}
function switchToBskyAppLabeler() {
AtpAgent.configure({appLabelers: [BSKY_LABELER_DID]})
configureGlobalAppLabelers([BSKY_LABELER_DID])
}
/** Resolve and install the test environment's moderation authority. */
@@ -77,6 +102,6 @@ async function trySwitchToTestAppLabeler(agent: AtpAgent) {
)?.data.did
if (did) {
console.warn('USING TEST ENV MODERATION')
AtpAgent.configure({appLabelers: [did]})
configureGlobalAppLabelers([did])
}
}