Graine AI

SDK reference

Every public function, property, hook, listener and type of Graine's in-app SDKs — React Native, iOS, Android, Flutter, Kotlin Multiplatform and the website loader — with what each is for, signatures, parameters, return values, errors and threading: one complete page per platform, and pages by topic that compare the platforms.

Everything your app can call, read or listen to, on every platform: what it is for, the exact signature, each parameter with its type, default and limits, what comes back (every field, with a real example), when it resolves, every error it can raise and why, what else it does, and which thread it runs on.

Your platform, every symbol

One complete page per SDK, for release 0.8.0. Each is grouped by use case — the same rows as Use cases by SDK, from installing to going live — then events, errors and the lower-level building blocks, and ends with every public symbol from A to Z. Every function, property, event, error and type opens with one sentence on when you use it.

The pages below compare the platforms topic by topic, with every platform's spelling side by side.

How to read it

  • On the topic pages, one tab per platform, always in this order: React Native · iOS · Android · Flutter · Kotlin Multiplatform · Website. Choose yours once — every tab on these pages follows your choice.
  • Under the tabs, in this order where they apply: Parameters (type, required, default, limits), Returns (each field and a JSON example), When it resolves, Errors (each code and why), What happens (side effects), and an example.
  • JSON shows a real value as it arrives. Every platform's type has the same fields, in its own spelling — Types says how dates and enums look in each language.
  • A dash in a tab or a table cell means that platform does not have it.

Kotlin Multiplatform

The Kotlin Multiplatform SDK is one API in shared code over the iOS and Android SDKs: it follows the same contract, and each call does the same work there. Its views (the chat, the call screen and the bar) are in ai.graine:inapp-kmp-compose, for Compose Multiplatform. Its guide: Kotlin Multiplatform.

The platforms

PlatformPackageVersionStart it onceThenRuns on
React Native@graineai/inapp-react-native, and @graineai/inapp-react-native-calls for native calls0.42.0 · calls 0.3.0<GraineProvider> at the roothooks, or the client from useGraineClient()The JavaScript thread
iOSGraineInApp (Swift package)0.8.0GraineInApp.configure(GraineConfig(…)) at launchGraineInApp.sharedThe main thread
Androidai.graine:inapp-android0.8.0GraineInApp.init(application, GraineConfig(…)) in Application.onCreateGraineInApp.get()The main thread
Fluttergraine_inapp0.8.0GraineInApp.init(GraineConfig(…)) before runAppGraineInApp.instanceThe UI isolate
Kotlin Multiplatformai.graine:inapp-kmp, and ai.graine:inapp-kmp-compose for its views0.8.0Graine.configure(GraineConfig(…)) at launchGraineAny thread; suspending calls never block the main thread
WebsiteThe loader script1.2.0GraineAgent.load(…)GraineAgentThe page

Calling anything before start-up is a programming error, said loudly: iOS stops with a message, Android throws IllegalStateException, Flutter throws StateError, Kotlin Multiplatform throws IllegalStateException, and a React Native hook outside <GraineProvider> throws unless you called setDefaultClient(client) once at start-up. The website loader buffers what you call before load() and applies it when the widget exists. To ask first: Graine.isConfigured (Kotlin Multiplatform) or GraineInApp.maybeInstance (Flutter, null before init).

Several agents. A website runs one agent at a time and switches between them: GraineAgent.load() with another agent takes the one on the page off and resolves true once the new one is on it, the visitor still signed in. GraineAgent.switchesAgents is true on a loader that does this (1.2.0 and later). See Different agents on different pages.

Installing each SDK, and the options it takes when it starts, are on its own page: React Native, iOS, Android, Flutter, Kotlin Multiplatform, Website and Any other platform.

A result and a failure, per platform

The same call — reading what the agent remembers — in each platform's idiom:

try {
  const memories = await client.memories();          // Promise<GraineMemory[]>
} catch (e) {
  if (e instanceof GraineError) console.warn(e.code, e.message);
}

A promise; a failure rejects it with a GraineError.

Every error carries a code — the same words on every platform — and a sentence for whoever has to fix it. The codes, their HTTP statuses and their fixes are on Errors.

Several agents (the multi-agent API)

An app can run several agents, each with its own publishable key, and choose one per screen — the guide is Use more than one agent in your app. These are the functions that name them.

<GraineProvider baseUrl="https://www.graine.ai" publishableKey="pk_live_sales…" storage={AsyncStorage}>   {/* one provider per agent */}
  <PlansScreens />                                                                                    {/* hooks use the nearest provider */}
</GraineProvider>
 
client.dispose(): void                         // a client you made yourself: end its conversation, stop sharing the device
client.conversation: "chat" | "call" | null    // the conversation this agent holds, if any
 
// The calls package names its agents:
GraineCalls.configure({ displayName, agents: Record<string, { publishableKey: string; baseUrl?: string }> }): Promise<void>
GraineCalls.configure(name: string, options: { publishableKey: string; baseUrl?: string }): Promise<void>
GraineCalls.agents: string[]
GraineCalls.startCall({ reason?, variables?, agent? }): Promise<string | null>

React Native has no names for in-app agents: each GraineProvider is one agent's client, and the providers share the customer, the screen and the line; with the same storage, the install ID and memory choice too. A conversation another agent ended closes with the reason another_agent.

nameString, default "default". Trimmed; an empty name is the default agent
ReturnsThe agent: a full SDK instance. Every function on these pages works on it and goes to that agent's key — its session, chat, voice, actions, scheduling and memory requests
The default agentThe one configured without a name — else, in an app that named every agent, the first one configured. Views draw it unless handed another
Configuring againA name already configured returns that agent unchanged
ErrorsNone from configuring. Looking up a name never configured returns null (named, find, agent); Android's get(name) throws for one. React Native's startCall rejects for an agent configure did not name
Shared by all agentsWho the customer is (identify on any agent applies to all; identify(null) signs out everywhere), the install ID, the memory choice, the current screen, the call engine — and one conversation at a time
A view, for one agentReact NativeiOSAndroidFlutterKotlin Multiplatform
The barThe nearest provider'sGraineAgentBar(graine:)GraineAgentBarView.graineGraineAgentBar(app:)GraineAgentBar(agent =)
The chatThe nearest provider'sGraineChatView(graine:)GraineChatView.source = GraineInApp.get(name).chat, GraineChatActivity.open(context, agent)GraineChat(app:)GraineChat(agent =)
A callGraineCalls.startCall({ agent })calls.startCall(…, agent:)calls.startCall(…, agent =)GraineCalls.instance.startCall(…, agent:)Graine.calls.startCall(…, agent =)

The pages by topic

Every function, and where it is

Names differ slightly between platforms; the page shows each platform's own.

FunctionPage
configure(…, name), named, get(name), find, all, Graine.agent, Graine.agents, GraineCalls.configure({ agents }), switchesAgents — the multi-agent APISDK reference
identify, useGraineIdentifyIdentity and memory
setMemoryIdentity and memory
memoryEnabled, memoryChoiceIdentity and memory
installId, getInstallIdIdentity and memory
memories, useGraineMemoriesIdentity and memory
forgetMemoryIdentity and memory
identityChannel, getRawTraits, getIdentityIdentity and memory
chat, useGraineAgentChat
send, sendText, queuedTextsChat
newConversationChat
openChat, open(size:), chatSize, openedSize, GraineChat.open, GraineChatScreen — the window sizeChat
chatTurnRows, GraineChatRows, ChatRows — the rows a chat window draws (every SDK)Types
open, close, retry, clear, isConnected, isMuted, isAgentSpeaking, networkStateChat
clear, clearChat, reconnecting, failed, chatFailed, retry, upcomingCalls — the chat's state, emptying it, trying againChat
GraineChatView, GraineChatViewController, GraineChatActivity, GraineChatChat
useGraineSurface, GraineSurfaceChat
voice.start, end, setMuted, retry, attach, detachVoice
connected, phase, connectStage, quality, connectivity, captionsVoice
captionsOn, setCaptionsOn, clearCaptions — the captions switchVoice
useGraineReady, useGraineInit, session, useGraineTheme, themeTokens, tokens, Graine.theme, previewDesign, isAttached, attached, viewOpened, viewClosedVoice
GraineVoiceLauncherVoice
GraineAgentBar, GraineAgentBarView, GraineVoiceBar, GraineLauncherButton, GraineWidgetView, GraineEngineVoice
useGraineConnection, useKeyboardLift, useDraggablePlacement, useGraineVoice, useGraineLoaderVoice
The website engine's messagesVoice
calls.configure, your own call screen on Android (ACTION_SHOW, ACTION_ANSWER, EXTRA_CALL_ID, …)Calls
enableVoIPPushes, registerPushToken, onNewToken, handlePush, reportIncomingCallCalls
startCallCalls
callTransport, transport, transportFallbackReason, GraineCallTransport, GraineRTC.install — calls over WebRTCCalls
callBack, missedCall, dismissMissedCallCalls
answer, decline, end, setMuted, setSpeakerCalls
The call's state and snapshotCalls
onOutcome, onIncomingCall, outcomes, incomingCallsCalls
GraineCalls.attachCalls
schedulingRulesScheduling
scheduleCallScheduling
scheduledCallsScheduling
cancelScheduledCallScheduling
useGraineSchedulingScheduling
bookingAvailable, openBooking, presentBooking, GraineBooking.show, GraineBookingSheetScheduling
upcomingCalls, refreshUpcomingCalls, cancelUpcomingCallScheduling
setScreen, useGraineScreen, currentScreenScreen context and actions
updateField, removeField, clearScreen, useGraineFieldScreen context and actions
track, tap, reportEvent, noteInteraction, captureTap, graineTap, useGraineTap, useGraineTrack, GraineTouchCaptureScreen context and actions
getScreen, getVariables, getRecentEvents, getAvailableActions, setAppVersionScreen context and actions
setVariables, currentVariables, useGraineVariablesScreen context and actions
registerAction, registerDeferredAction, useGraineAction, checkActions, executeAction, defineAction, removeActionScreen context and actions
useGraineWidget, reopenComponent, answerWidget, answerComponent, submitWidget, pendingWidget, clearPendingWidget, present, presentPending, presentWidget, presentPendingWidgetScreen context and actions
useGraineHighlight, registerHighlightable, getHighlightables, highlightScreen context and actions
addMaskRule, Masking.addRule, GraineMasking.addRule, maskString, maskDeepScreen context and actions
friction, configureFrictionScreen context and actions
GraineListener, addListener, removeListener, Graine.eventsEvents and listeners
useGraineEvents, client.onEvents and listeners
GraineCallsListener, GraineCallListener, calls streamsEvents and listeners

On this page