@bty/feed_app-runtime-sdk
v0.0.8
Published
Runtime SDK for feed-app template: auth / AI capabilities, multi-environment bridge (native App / iframe / web).
Downloads
805
Keywords
Readme
@bty/feed_app-runtime-sdk
Runtime SDK for Feed-App pages.
It provides a small set of browser-safe APIs for reading host user context and calling the Feed-App AI gateway. The package has no root entry; import from the capability sub-entries directly.
Install
pnpm add @bty/feed_app-runtime-sdkUser
import {
getAuthTokenAsync,
getUserInfoAsync,
} from '@bty/feed_app-runtime-sdk/user'
const token = await getAuthTokenAsync()
const user = await getUserInfoAsync()getAuthTokenAsync() resolves to an auth token when the current host
environment can provide one. getUserInfoAsync() resolves to user information
or null.
Both APIs are safe to import during prerender or SSR. In a non-browser
environment they resolve to empty values instead of touching window.
AI
import { configureRuntime, openai } from '@bty/feed_app-runtime-sdk/ai'
configureRuntime({
apiBaseUrl: 'https://example.com',
})
const stream = await openai.chat.completions.create({
model: 'gpt-5.4',
messages: [{ role: 'user', content: 'Hello' }],
stream: true,
})
for await (const chunk of stream) {
const text = chunk.choices[0]?.delta?.content
if (text) {
console.log(text)
}
}The AI entry supports:
- OpenAI-compatible chat completions
- Anthropic-compatible messages
- Image generation
- Text-to-speech
- Video generation
AbortSignalcancellation- Structured AI errors
import {
AuthRequiredError,
RateLimitError,
openai,
} from '@bty/feed_app-runtime-sdk/ai'
try {
await openai.chat.completions.create({
model: 'gpt-5.4',
messages: [{ role: 'user', content: 'Hello' }],
})
} catch (error) {
if (error instanceof AuthRequiredError) {
// Ask the user to sign in.
} else if (error instanceof RateLimitError) {
// Show a rate limit message.
}
}React
import { useAuthToken, useUserInfo } from '@bty/feed_app-runtime-sdk/react'
export function App() {
const { token, loading: tokenLoading } = useAuthToken()
const { user } = useUserInfo()
return (
<main>
<p>{tokenLoading ? 'Loading...' : (user?.username ?? user?.nickname)}</p>
</main>
)
}For chat / image / TTS / video, call openai / anthropic from /ai directly
and wire your own loading / cancel / error state. Product-specific chat UX
varies enough that a generic hook tends to leak abstractions.
React is an optional peer dependency. Projects that do not import the /react
entry do not need to install React.
Published Files
The npm package publishes only built output and this README:
dist/**/*.jsdist/**/*.d.tsREADME.mdpackage.json
Source files and sourcemaps are not included in the npm tarball.
