-
Notifications
You must be signed in to change notification settings - Fork 572
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add trending topic lex, wire in agent (#3250)
* add lex * add suggested as well * don't use uri format * codegen * tweak lex * wire in * add missing var * move * make auth optional * mount * add trending topics to server cfg (#3226) * add trending topics to server cfg * rename stuff * remove langs * make viewer nullable * recodegen * changeset again --------- Co-authored-by: dholms <[email protected]>
- Loading branch information
Showing
25 changed files
with
792 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@atproto/api": patch | ||
--- | ||
|
||
add trending topics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"lexicon": 1, | ||
"id": "app.bsky.unspecced.getTrendingTopics", | ||
"defs": { | ||
"main": { | ||
"type": "query", | ||
"description": "Get a list of trending topics", | ||
"parameters": { | ||
"type": "params", | ||
"properties": { | ||
"viewer": { | ||
"type": "string", | ||
"format": "did", | ||
"description": "DID of the account making the request (not included for public/unauthenticated queries). Used to boost followed accounts in ranking." | ||
}, | ||
"limit": { | ||
"type": "integer", | ||
"minimum": 1, | ||
"maximum": 25, | ||
"default": 10 | ||
} | ||
} | ||
}, | ||
"output": { | ||
"encoding": "application/json", | ||
"schema": { | ||
"type": "object", | ||
"required": ["topics", "suggested"], | ||
"properties": { | ||
"topics": { | ||
"type": "array", | ||
"items": { | ||
"type": "ref", | ||
"ref": "app.bsky.unspecced.defs#trendingTopic" | ||
} | ||
}, | ||
"suggested": { | ||
"type": "array", | ||
"items": { | ||
"type": "ref", | ||
"ref": "app.bsky.unspecced.defs#trendingTopic" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/api/src/client/types/app/bsky/unspecced/getTrendingTopics.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* GENERATED CODE - DO NOT MODIFY | ||
*/ | ||
import { HeadersMap, XRPCError } from '@atproto/xrpc' | ||
import { ValidationResult, BlobRef } from '@atproto/lexicon' | ||
import { isObj, hasProp } from '../../../../util' | ||
import { lexicons } from '../../../../lexicons' | ||
import { CID } from 'multiformats/cid' | ||
import * as AppBskyUnspeccedDefs from './defs' | ||
|
||
export interface QueryParams { | ||
/** DID of the account making the request (not included for public/unauthenticated queries). Used to boost followed accounts in ranking. */ | ||
viewer?: string | ||
limit?: number | ||
} | ||
|
||
export type InputSchema = undefined | ||
|
||
export interface OutputSchema { | ||
topics: AppBskyUnspeccedDefs.TrendingTopic[] | ||
suggested: AppBskyUnspeccedDefs.TrendingTopic[] | ||
[k: string]: unknown | ||
} | ||
|
||
export interface CallOptions { | ||
signal?: AbortSignal | ||
headers?: HeadersMap | ||
} | ||
|
||
export interface Response { | ||
success: boolean | ||
headers: HeadersMap | ||
data: OutputSchema | ||
} | ||
|
||
export function toKnownErr(e: any) { | ||
return e | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
packages/bsky/src/api/app/bsky/unspecced/getTrendingTopics.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { noUndefinedVals } from '@atproto/common' | ||
import AppContext from '../../../../context' | ||
import { Server } from '../../../../lexicon' | ||
import { | ||
createPipeline, | ||
HydrationFnInput, | ||
PresentationFnInput, | ||
RulesFnInput, | ||
SkeletonFnInput, | ||
} from '../../../../pipeline' | ||
import { HydrateCtx, Hydrator } from '../../../../hydration/hydrator' | ||
import { Views } from '../../../../views' | ||
import { QueryParams } from '../../../../lexicon/types/app/bsky/unspecced/getTrendingTopics' | ||
import AtpAgent from '@atproto/api' | ||
import { TrendingTopic } from '../../../../lexicon/types/app/bsky/unspecced/defs' | ||
import { InternalServerError } from '@atproto/xrpc-server' | ||
|
||
export default function (server: Server, ctx: AppContext) { | ||
const getTrendingTopics = createPipeline( | ||
skeleton, | ||
hydration, | ||
noBlocksOrMutes, | ||
presentation, | ||
) | ||
server.app.bsky.unspecced.getTrendingTopics({ | ||
auth: ctx.authVerifier.standardOptional, | ||
handler: async ({ auth, params, req }) => { | ||
const viewer = auth.credentials.iss | ||
const labelers = ctx.reqLabelers(req) | ||
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer }) | ||
const headers = noUndefinedVals({ | ||
'accept-language': req.headers['accept-language'], | ||
}) | ||
const { ...result } = await getTrendingTopics( | ||
{ ...params, hydrateCtx: hydrateCtx.copy({ viewer }), headers }, | ||
ctx, | ||
) | ||
return { | ||
encoding: 'application/json', | ||
body: result, | ||
} | ||
}, | ||
}) | ||
} | ||
|
||
const skeleton = async (input: SkeletonFnInput<Context, Params>) => { | ||
const { params, ctx } = input | ||
if (ctx.topicsAgent) { | ||
const res = await ctx.topicsAgent.app.bsky.unspecced.getTrendingTopics( | ||
{ | ||
viewer: params.viewer, | ||
}, | ||
{ | ||
headers: params.headers, | ||
}, | ||
) | ||
return res.data | ||
} else { | ||
throw new InternalServerError('Topics agent not available') | ||
} | ||
} | ||
|
||
const hydration = async ( | ||
_: HydrationFnInput<Context, Params, SkeletonState>, | ||
) => { | ||
return {} | ||
} | ||
|
||
const noBlocksOrMutes = ( | ||
input: RulesFnInput<Context, Params, SkeletonState>, | ||
) => { | ||
const { skeleton } = input | ||
return skeleton | ||
} | ||
|
||
const presentation = ( | ||
input: PresentationFnInput<Context, Params, SkeletonState>, | ||
) => { | ||
const { skeleton } = input | ||
return skeleton | ||
} | ||
|
||
type Context = { | ||
hydrator: Hydrator | ||
views: Views | ||
topicsAgent: AtpAgent | undefined | ||
} | ||
|
||
type Params = QueryParams & { | ||
hydrateCtx: HydrateCtx & { viewer: string | null } | ||
headers: Record<string, string> | ||
} | ||
|
||
type SkeletonState = { | ||
topics: TrendingTopic[] | ||
suggested: TrendingTopic[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.