@pambase/sdk-react
v0.1.0
Published
React hooks for the PAMbase platform — useIdentity, useContext, useMemories, useChat, and more.
Downloads
111
Maintainers
Readme
@pambase/sdk-react
React hooks for the PAMbase platform. A thin, typed layer over
@pambase/sdk with loading/error
state, request cancellation on unmount, and SSR-safety built in.
npm i @pambase/sdk-react react react-domThese are client hooks — the package ships with a
"use client"boundary, so the connection token must be provided from a client context. The token grants access to the user's memory; mint it server-side via the connect flow and pass it down deliberately.
Setup
Wrap your app (or a subtree) in the provider:
import { PAMbaseProvider } from "@pambase/sdk-react";
export function Providers({ token, children }: { token: string; children: React.ReactNode }) {
return (
<PAMbaseProvider baseUrl={process.env.NEXT_PUBLIC_PAMBASE_API_URL!} token={token}>
{children}
</PAMbaseProvider>
);
}Hooks
Queries (auto-fetch, cancel on unmount)
import { useIdentityBrief, useMemories, useContextBundle } from "@pambase/sdk-react";
function Companion() {
const brief = useIdentityBrief();
const notes = useMemories({ scope: "note" });
if (brief.isLoading) return <Spinner />;
if (brief.error) return <Error err={brief.error} />;
return <p>{brief.data?.brief}</p>;
}Available queries: useIdentity, useIdentityBrief, useConnection,
useContextBundle, useMemories, useRecall, useCatalog,
useUserScopes, useSchedules. Each returns { data, error, isLoading, isStale, refetch }.
Mutations
useRemember (write memory), useEmitSignal (emit a signal), useCreateSchedule, useCancelSchedule.
import { useRemember, useCreateSchedule, useCancelSchedule } from "@pambase/sdk-react";
function SaveHighlight() {
const { mutate, isLoading } = useRemember();
return (
<button
disabled={isLoading}
onClick={() => mutate({ content: "Highlighted: 'Backpressure is a system saying slow down.'", scope: "note.reading" })}
>
Save
</button>
);
}Mutations return { mutate, data, error, isLoading, reset }.
Streaming chat
import { useChat } from "@pambase/sdk-react";
function Chat() {
const { messages, send, stop, isStreaming } = useChat({ intent: "app.companion.turn" });
// messages: { role, content }[] — assistant deltas stream in live.
// call stop() to abort the current turn; the stream also aborts on unmount.
}The full core SDK (PAMbaseApp, buildConnectUrl, error classes, webhook helpers,
…) is re-exported for convenience.
License
MIT
