@raindrop-ai/browser-sdk
v0.1.10
Published
Minimal browser-safe SDK for Raindrop /v1/events
Maintainers
Keywords
Readme
@raindrop-ai/browser-sdk
Minimal browser-safe SDK for sending Raindrop events from frontend applications.
Build-injected application identity
Browsers cannot discover a server checkout or process environment. Inject application build metadata through public options: new Raindrop({ apiKey, appGit: { commitSha: APP_BUILD_SHA, branch: APP_BRANCH } }). Only full40/64-character SHA values are inferred from this typed option. branch and boolean commitDirty are optional; do not invent a clean/dirty state when the build does not know it. No Node imports, filesystem/process discovery, or metadata waits are added.
The SDK fills absent raindrop.app.commit_sha, raindrop.app.commit_dirty, and raindrop.app.branch properties. Caller properties—including null, empty, and opaque strings—win unchanged; partial finishes retain their initial identity unless explicitly overridden. Existing release/SDK fields are untouched. appGit: false disables defaults. detectBranch, sourceDirectory, and autoDetect do not enable Node discovery in a browser.
Valid configured SHA and branch strings retain their exact case and whitespace. Invalid or empty configured SHAs are omitted; existing raw per-event properties are still preserved exactly.
Install
pnpm add @raindrop-ai/browser-sdkUsage
import { Raindrop } from "@raindrop-ai/browser-sdk";
const raindrop = new Raindrop({
apiKey: process.env.RAINDROP_WRITE_KEY!,
});Projects
If your org has multiple projects, route events to a specific one by passing its slug as projectId:
const raindrop = new Raindrop({
apiKey: process.env.RAINDROP_WRITE_KEY!,
projectId: "support-prod",
});This sets the X-Raindrop-Project-Id header on every event. Omit it (or pass "default") to use your org's default Production project — the existing behavior. Single-project orgs need nothing new.
Delivery and errors
Every call (trackAi, trackAiPartial and its finish(), trackSignal,
identify) sends its request right away and resolves once it is settled.
Transient failures (408, 429, 5xx, network errors) are retried inside the call,
within timeoutMs. Calls never reject on a delivery failure: they resolve
with a result, and a request that is given up on also logs a rate-limited
warning.
const { eventIds, delivered, dropped, timedOut, status, error } = await raindrop.trackAi({
event: "chat",
userId: "user-123",
input: "hi",
});delivered is false after a permanent 4xx (never retried), exhausted
retries or the timeoutMs deadline. Finishing a partial event that carried
no input, output or attachments is still sent, with a warning. The result is
safe to ignore, and code
that awaited Promise<void> from trackSignal / identify keeps compiling.
Payload size limits
input / output are capped at 1,000,000 characters per field by default
and truncated with a ...[truncated by raindrop] marker before the request
body is serialized, so a multi-MB transcript costs the cap — not the payload —
on the main thread, and lands truncated instead of tripping the 1 MB ingest
limit. Tune via maxTextFieldChars. Every request also carries a finite
timeout (default 30s, tune via timeoutMs).
Notes
- This package is intentionally small and browser-safe.
- It has zero runtime dependencies.
