migrate RichText to the SDK and resolve facets via the appview

The two RichText classes are not mutually assignable - `UnicodeString` has a
private field and the SDK brands `did`/`uri` as template literal types - so
every producer and consumer of a RichText instance has to move in one step.

`detectFacets` now takes a lex client instead of the legacy agent, which is
what removes the last hard agent dependency from these files. Handle
resolution is an appview job, so the appview client is threaded in: through
`useAppviewClient` in the hooks and dialogs, and through a new
`appviewClient` option on `apilib.post` (Composer already had the client to
hand). The rest of the post pipeline still writes through the agent.

Facet feature checks move from the `AppBskyRichtextFacet` validators to the
generated `#/lexicons` schemas, matching how the rest of the app narrows
lexicon types.

Display sinks still read facets off `@atproto/api` view types, which are the
same lexicon but typed with plain strings. `asSdkFacets` widens them at those
call sites and goes away once the view types come from the SDK too.
This commit is contained in:
Samuel Newman
2026-08-03 22:33:04 +03:00
parent dbffcce821
commit 2beb63fb2d
44 changed files with 200 additions and 123 deletions
@@ -12,7 +12,7 @@ import {
View,
} from 'react-native'
import {type PasteEventPayload, TextInputWrapper} from 'expo-paste-input'
import {AppBskyRichtextFacet, RichText} from '@atproto/api'
import {RichText} from '@bsky.app/sdk/richtext'
import {useLingui} from '@lingui/react/macro'
import {IMAGE_SIZE_CONFIG_POSTS} from '#/lib/constants'
@@ -27,6 +27,8 @@ import {
import {atoms as a, useAlf} from '#/alf'
import {normalizeTextStyles} from '#/alf/typography'
import {IS_ANDROID} from '#/env'
import {app} from '#/lexicons'
import * as bsky from '#/types/bsky'
import {Autocomplete} from './mobile/Autocomplete'
import {type TextInputProps} from './TextInput.types'
@@ -88,7 +90,7 @@ export function TextInput({
if (newRt.facets) {
for (const facet of newRt.facets) {
for (const feature of facet.features) {
if (AppBskyRichtextFacet.isLink(feature)) {
if (bsky.isType(app.bsky.richtext.facet.link, feature)) {
if (isUriImage(feature.uri)) {
const res = await downloadAndResize({
uri: feature.uri,
@@ -1,5 +1,5 @@
import {type TextInput} from 'react-native'
import {type RichText} from '@atproto/api'
import {type RichText} from '@bsky.app/sdk/richtext'
export type TextInputRef = {
focus: () => void
@@ -8,7 +8,7 @@ import {
} from 'react'
import {StyleSheet, View} from 'react-native'
import Animated, {FadeIn, FadeOut} from 'react-native-reanimated'
import {AppBskyRichtextFacet, RichText} from '@atproto/api'
import {RichText} from '@bsky.app/sdk/richtext'
import {Trans} from '@lingui/react/macro'
import {getSchema} from '@tiptap/core'
import {Document} from '@tiptap/extension-document'
@@ -40,6 +40,8 @@ import {normalizeTextStyles} from '#/alf/typography'
import {type Emoji} from '#/components/EmojiPicker'
import {Portal} from '#/components/Portal'
import {Text} from '#/components/Typography'
import {app} from '#/lexicons'
import * as bsky from '#/types/bsky'
import {type TextInputProps} from './TextInput.types'
import {type AutocompleteRef, createSuggestion} from './web/Autocomplete'
import {LinkDecorator} from './web/LinkDecorator'
@@ -265,7 +267,7 @@ export function TextInput({
if (newRt.facets) {
for (const facet of newRt.facets) {
for (const feature of facet.features) {
if (AppBskyRichtextFacet.isLink(feature)) {
if (bsky.isType(app.bsky.richtext.facet.link, feature)) {
nextDetectedUris.set(feature.uri, {facet, rt: newRt})
}
}
@@ -1,8 +1,10 @@
import {type AppBskyRichtextFacet, type RichText} from '@atproto/api'
import {type RichText} from '@bsky.app/sdk/richtext'
import {type app} from '#/lexicons'
export type LinkFacetMatch = {
rt: RichText
facet: AppBskyRichtextFacet.Main
facet: app.bsky.richtext.facet.Main
}
export function suggestLinkCardUri(