[SDK] Migrate agent sugar to @bsky.app/sdk actions (#11382)

This commit is contained in:
Samuel Newman
2026-08-13 22:26:21 +03:00
committed by GitHub
parent a4f2811f39
commit dc31e7fd12
24 changed files with 520 additions and 389 deletions
+27 -37
View File
@@ -1,21 +1,19 @@
import {useCallback, useState} from 'react'
import {View} from 'react-native'
import {
type AppBskyActorDefs,
type AppBskyActorProfile,
type AppBskyGraphDefs,
AppBskyGraphStarterpack,
type Un$Typed,
} from '@atproto/api'
import {TID} from '@atproto/common-web'
import {type AtUriString} from '@atproto/syntax'
import {type Un$Typed} from '@atproto/lex'
import {type AtUriString, toDatetimeString} from '@atproto/syntax'
import {
overwriteSavedFeeds,
setInterestsPref,
upsertProfile,
} from '@bsky.app/sdk'
import {msg} from '@lingui/core/macro'
import {useLingui} from '@lingui/react'
import {Trans} from '@lingui/react/macro'
import {useQueryClient} from '@tanstack/react-query'
import {uploadBlob} from '#/lib/api'
import {toLegacyBlobRef} from '#/lib/api/legacy-blob'
import {
BSKY_APP_ACCOUNT_DID,
DISCOVER_SAVED_FEED,
@@ -28,7 +26,7 @@ import {useSetHasCheckedForStarterPack} from '#/state/preferences/used-starter-p
import {getAllListMembers} from '#/state/queries/list-members'
import {preferencesQueryKey} from '#/state/queries/preferences'
import {RQKEY as profileRQKey} from '#/state/queries/profile'
import {useAgent, useAppviewClient, usePdsClient} from '#/state/session'
import {useAppviewClient, usePdsClient} from '#/state/session'
import {useOnboardingDispatch} from '#/state/shell'
import {
useActiveStarterPack,
@@ -50,6 +48,7 @@ import {ArrowRight_Stroke2_Corner0_Rounded as ArrowRight} from '#/components/ico
import {Loader} from '#/components/Loader'
import {useAnalytics} from '#/analytics'
import {IS_WEB} from '#/env'
import {app} from '#/lexicons'
import * as bsky from '#/types/bsky'
import {ValuePropositionPager} from './ValuePropositionPager'
@@ -59,9 +58,8 @@ export function StepFinished() {
const onboardDispatch = useOnboardingDispatch()
const [saving, setSaving] = useState(false)
const queryClient = useQueryClient()
const agent = useAgent()
const appviewClient = useAppviewClient()
const pdsClient = usePdsClient()
const appviewClient = useAppviewClient()
const requestNotificationsPermission = useRequestNotificationsPermission()
const activeStarterPack = useActiveStarterPack()
const setActiveStarterPack = useSetActiveStarterPack()
@@ -71,15 +69,15 @@ export function StepFinished() {
const finishOnboarding = useCallback(async () => {
setSaving(true)
let starterPack: AppBskyGraphDefs.StarterPackView | undefined
let listItems: AppBskyGraphDefs.ListItemView[] | undefined
let starterPack: app.bsky.graph.defs.StarterPackView | undefined
let listItems: app.bsky.graph.defs.ListItemView[] | undefined
if (activeStarterPack?.uri) {
try {
const spRes = await agent.app.bsky.graph.getStarterPack({
starterPack: activeStarterPack.uri,
const spRes = await appviewClient.call(app.bsky.graph.getStarterPack, {
starterPack: activeStarterPack.uri as AtUriString,
})
starterPack = spRes.data.starterPack
starterPack = spRes.starterPack
} catch (e) {
logger.error('Failed to fetch starter pack', {safeMessage: e})
// don't tell the user, just get them through onboarding.
@@ -109,19 +107,15 @@ export function StepFinished() {
appviewClient,
[BSKY_APP_ACCOUNT_DID, ...(listItems?.map(i => i.subject.did) ?? [])],
starterPack
? // the starter pack view is still legacy-typed
{
uri: starterPack.uri as AtUriString,
cid: starterPack.cid,
}
? {uri: starterPack.uri, cid: starterPack.cid}
: undefined,
),
(async () => {
// Interests need to get saved first, then we can write the feeds to prefs
await agent.setInterestsPref({tags: selectedInterests})
await pdsClient.call(setInterestsPref, {tags: selectedInterests})
// Default feeds that every user should have pinned when landing in the app
const feedsToSave: AppBskyActorDefs.SavedFeed[] = [
const feedsToSave: app.bsky.actor.defs.SavedFeed[] = [
{
...DISCOVER_SAVED_FEED,
id: TID.nextStr(),
@@ -140,7 +134,7 @@ export function StepFinished() {
if (starterPack && starterPack.feeds?.length) {
feedsToSave.push(
...starterPack.feeds.map(f => ({
type: 'feed',
type: 'feed' as const,
value: f.uri,
pinned: true,
id: TID.nextStr(),
@@ -148,7 +142,7 @@ export function StepFinished() {
)
}
await agent.overwriteSavedFeeds(feedsToSave)
await pdsClient.call(overwriteSavedFeeds, feedsToSave)
})(),
(async () => {
const {imageUri, imageMime} = profileStepResults
@@ -157,13 +151,13 @@ export function StepFinished() {
? uploadBlob(pdsClient, imageUri, imageMime)
: undefined
await agent.upsertProfile(async existing => {
let next: Un$Typed<AppBskyActorProfile.Record> = existing ?? {}
await pdsClient.call(upsertProfile, async existing => {
let next: Un$Typed<app.bsky.actor.profile.Main> = existing ?? {}
if (blobPromise) {
const res = await blobPromise
if (res.blob) {
next.avatar = toLegacyBlobRef(res.blob)
next.avatar = res.blob
}
}
@@ -177,7 +171,7 @@ export function StepFinished() {
next.displayName = ''
if (!next.createdAt) {
next.createdAt = new Date().toISOString()
next.createdAt = toDatetimeString(new Date())
}
return next
})
@@ -204,7 +198,7 @@ export function StepFinished() {
queryKey: preferencesQueryKey,
}),
queryClient.invalidateQueries({
queryKey: profileRQKey(agent.session?.did ?? ''),
queryKey: profileRQKey(pdsClient.did ?? ''),
}),
]).catch(e => {
logger.error(e)
@@ -221,10 +215,7 @@ export function StepFinished() {
usedStarterPack: Boolean(starterPack),
starterPackName:
starterPack &&
bsky.dangerousIsType<AppBskyGraphStarterpack.Record>(
starterPack.record,
AppBskyGraphStarterpack.isRecord,
)
bsky.isType(app.bsky.graph.starterpack, starterPack.record)
? starterPack.record.name
: undefined,
starterPackCreator: starterPack?.creator.did,
@@ -242,9 +233,8 @@ export function StepFinished() {
}, [
ax,
queryClient,
agent,
appviewClient,
pdsClient,
appviewClient,
dispatch,
onboardDispatch,
activeStarterPack,
+5 -4
View File
@@ -1,5 +1,6 @@
import {useMemo, useState} from 'react'
import {type TextStyle, View, type ViewStyle} from 'react-native'
import {setInterestsPref} from '@bsky.app/sdk'
import {msg} from '@lingui/core/macro'
import {useLingui} from '@lingui/react'
import {Trans} from '@lingui/react/macro'
@@ -23,7 +24,7 @@ import {createGetSuggestedUsersForDiscoverQueryKey} from '#/state/queries/trendi
import {createGetSuggestedUsersForExploreQueryKey} from '#/state/queries/trending/useGetSuggestedUsersForExploreQuery'
import {createGetSuggestedUsersForSeeMoreQueryKey} from '#/state/queries/trending/useGetSuggestedUsersForSeeMoreQuery'
import {createSuggestedStarterPacksQueryKey} from '#/state/queries/useSuggestedStarterPacksQuery'
import {useAgent} from '#/state/session'
import {usePdsClient} from '#/state/session'
import {atoms as a, useGutters, useTheme} from '#/alf'
import {Admonition} from '#/components/Admonition'
import {Divider} from '#/components/Divider'
@@ -88,7 +89,7 @@ function Inner({
setIsSaving: (isSaving: boolean) => void
}) {
const {_} = useLingui()
const agent = useAgent()
const pdsClient = usePdsClient()
const qc = useQueryClient()
const interestsDisplayNames = useInterestsDisplayNames()
const preselectedInterests = useMemo(
@@ -110,7 +111,7 @@ function Inner({
setIsSaving(true)
try {
await agent.setInterestsPref({tags: interests})
await pdsClient.call(setInterestsPref, {tags: interests})
qc.setQueriesData(
{queryKey: preferencesQueryKey},
(old?: UsePreferencesQueryResponse) => {
@@ -157,7 +158,7 @@ function Inner({
setIsSaving(false)
}
}, 1500)
}, [_, agent, setIsSaving, qc, preselectedInterests])
}, [_, pdsClient, setIsSaving, qc, preselectedInterests])
const onChangeInterests = async (interests: string[]) => {
setInterests(interests)
+4 -3
View File
@@ -2,6 +2,7 @@ import {useState} from 'react'
import {Alert, LayoutAnimation, Linking, Pressable, View} from 'react-native'
import {useReducedMotion} from 'react-native-reanimated'
import {type AppBskyActorDefs, moderateProfile} from '@atproto/api'
import {removeNuxs} from '@bsky.app/sdk'
import {Trans, useLingui} from '@lingui/react/macro'
import {useNavigation} from '@react-navigation/native'
import {type NativeStackScreenProps} from '@react-navigation/native-stack'
@@ -21,7 +22,7 @@ import {clearStorage} from '#/state/persisted'
import {useModerationOpts} from '#/state/preferences/moderation-opts'
import {useDeleteActorDeclaration} from '#/state/queries/messages/actor-declaration'
import {useProfileQuery, useProfilesQuery} from '#/state/queries/profile'
import {useAgent} from '#/state/session'
import {usePdsClient} from '#/state/session'
import {type SessionAccount, useSession, useSessionApi} from '#/state/session'
import {useOnboardingDispatch} from '#/state/shell'
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
@@ -385,7 +386,7 @@ function ProfilePreview({
function DevOptions() {
const {t: l} = useLingui()
const agent = useAgent()
const pdsClient = usePdsClient()
const [override, setOverride] = useStorage(device, [
'policyUpdateDebugOverride',
])
@@ -560,7 +561,7 @@ function DevOptions() {
<Button
onPress={() => {
device.set([PolicyUpdate202508], false)
void agent.bskyAppRemoveNuxs([PolicyUpdate202508])
void pdsClient.call(removeNuxs, [PolicyUpdate202508])
Toast.show(`Done`, {
type: 'info',
})