@graineai/inapp-react-native 0.27.4 → 0.27.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/INTEGRATION.md
CHANGED
|
@@ -389,6 +389,46 @@ nowhere. Save is what pushes the catalogue to the agent.
|
|
|
389
389
|
|
|
390
390
|
---
|
|
391
391
|
|
|
392
|
+
### The contract, exactly
|
|
393
|
+
|
|
394
|
+
Four rules decide what the agent can do and what the customer is told. Each
|
|
395
|
+
one has bitten a real integration.
|
|
396
|
+
|
|
397
|
+
**Registration is per mounted screen.** `useGraineAction` registers the
|
|
398
|
+
handler when the component mounts and unregisters it when it unmounts, so the
|
|
399
|
+
agent is offered only what the screen in front of the customer can actually
|
|
400
|
+
do. Register in the screen that performs the action, not at the root — an
|
|
401
|
+
action registered at the root is offered on every screen, including the ones
|
|
402
|
+
where it makes no sense, and the agent will call it there.
|
|
403
|
+
|
|
404
|
+
**`availableActions` narrows; omitting it is the default you want.**
|
|
405
|
+
On `useGraineScreen`, leave it out and every action registered on the mounted
|
|
406
|
+
screen is offered. Pass a list to offer a subset. Pass `[]` to offer
|
|
407
|
+
*nothing* — say that deliberately, for a read-only screen. It can only ever
|
|
408
|
+
narrow: an action the dashboard never declared is not callable whatever
|
|
409
|
+
appears here, and the server enforces that, not this field. (Before 0.27.3
|
|
410
|
+
the SDK could send `[]` by accident while handlers were still registering,
|
|
411
|
+
which disarmed the agent for the whole screen; it now sends `[]` only when
|
|
412
|
+
you wrote `[]`.)
|
|
413
|
+
|
|
414
|
+
**A handler has six seconds.** `ACTION_DEADLINE_MS`. Return promptly — do
|
|
415
|
+
the slow part after you have answered. A handler that has not resolved by
|
|
416
|
+
then is answered as a timeout on the runtime side, and the agent tells the
|
|
417
|
+
customer it was *not* done rather than guessing. A handler that throws is
|
|
418
|
+
answered as `error` for the same reason.
|
|
419
|
+
|
|
420
|
+
**The status is what the customer is told.** `{ status: "ok" }` makes the
|
|
421
|
+
agent say it is done, so return it only when it is. `{ status: "refused",
|
|
422
|
+
message }` is often the most useful answer you can give — "this field is
|
|
423
|
+
locked after submission" — and the agent passes the reason on. `message` is
|
|
424
|
+
for the agent, which decides how to phrase it, not text read to the customer.
|
|
425
|
+
|
|
426
|
+
**Where it all ends up.** Every call the agent makes lands in Call History
|
|
427
|
+
with the app's answer beside it — "Ran set_ring (state: off) → ok" or
|
|
428
|
+
"→ refused: …" — on the timeline against the turn it happened in, and in the
|
|
429
|
+
execution log. A refusal there is the moment a customer was told something
|
|
430
|
+
that did not happen, which is exactly the row a product team wants to find.
|
|
431
|
+
|
|
392
432
|
## Step 4b — Show them where, and draw them things
|
|
393
433
|
|
|
394
434
|
### Pointing at something on screen
|
|
@@ -727,7 +767,7 @@ is not happening, and the table says which.
|
|
|
727
767
|
|
|
728
768
|
| Wait | What it is | When it is paid | Typical |
|
|
729
769
|
|---|---|---|---|
|
|
730
|
-
| Page load | The voice engine is a page in a WebView | **Before the tap** — `GraineFab`
|
|
770
|
+
| Page load | The voice engine is a page in a WebView | **Before the tap** — `GraineFab` mounts the engine on open; a custom bar mounts `GraineVoiceLauncher` at launch with `active={false}` and flips it on open (0.27.5) | ~4s, hidden |
|
|
731
771
|
| Mint + REGISTER | A 120-second SIP credential, then registration on the SBC | **Before the tap**, re-warmed as it nears expiry | ~1.6s, hidden |
|
|
732
772
|
| Microphone | The OS permission prompt, first time only | At the tap | 0 once granted |
|
|
733
773
|
| INVITE → answer | The call itself | At the tap | ~0.3s |
|
|
@@ -1037,6 +1077,7 @@ told to ignore).
|
|
|
1037
1077
|
| `onMicDenied` | `(reason) => void` | `NotAllowedError` is a refusal; `NotFoundError` is a device with no usable microphone. Different sentences for a customer. |
|
|
1038
1078
|
| `onError` | `(message) => void` | Voice could not be set up at all — key rejected, agent not enabled for apps, no network. Without this the launcher renders nothing and you cannot tell why. |
|
|
1039
1079
|
| `children` | `(api) => ReactNode` | Receives `{ connected, connecting, muted, start, end, setMuted }`. |
|
|
1080
|
+
| `active` | `boolean` | Default `true`. Mount early with `false` so the engine page loads before the customer needs it (it registers nothing while idle); flip to `true` when your UI opens — with `autoStart` that places the call, without it it warms the registration so the tap is instant. Back to `false` ends a live call. (0.27.5) |
|
|
1040
1081
|
|
|
1041
1082
|
**The launcher owns the connection.** It asks for the microphone, resolves the
|
|
1042
1083
|
session, holds the socket and relays your screen, actions and events onto it. So
|
|
@@ -9,6 +9,7 @@ export interface GraineVoiceLauncherProps {
|
|
|
9
9
|
}) => void;
|
|
10
10
|
webView: React.ComponentType<any>;
|
|
11
11
|
autoStart?: boolean;
|
|
12
|
+
active?: boolean;
|
|
12
13
|
onCaption?: (c: {
|
|
13
14
|
role: string;
|
|
14
15
|
text: string;
|
|
@@ -32,4 +33,4 @@ export interface GraineVoiceApi {
|
|
|
32
33
|
end: () => void;
|
|
33
34
|
setMuted: (m: boolean) => void;
|
|
34
35
|
}
|
|
35
|
-
export declare function GraineVoiceLauncher({ webView: WebView, autoStart, transport, onTransport, onCaption, onCallState, onMicDenied, onError, onEnded, children, }: GraineVoiceLauncherProps): React.JSX.Element;
|
|
36
|
+
export declare function GraineVoiceLauncher({ webView: WebView, autoStart, active, transport, onTransport, onCaption, onCallState, onMicDenied, onError, onEnded, children, }: GraineVoiceLauncherProps): React.JSX.Element;
|
|
@@ -3,10 +3,13 @@ import { useCallback, useEffect, useRef, useState } from "react";
|
|
|
3
3
|
import { AppState, View } from "react-native";
|
|
4
4
|
import { useGraineAgent } from "./index.js";
|
|
5
5
|
import { requestMicrophonePermission } from "./permissions.js";
|
|
6
|
-
export function GraineVoiceLauncher({ webView: WebView, autoStart = false, transport, onTransport, onCaption, onCallState, onMicDenied, onError, onEnded, children, }) {
|
|
6
|
+
export function GraineVoiceLauncher({ webView: WebView, autoStart = false, active = true, transport, onTransport, onCaption, onCallState, onMicDenied, onError, onEnded, children, }) {
|
|
7
7
|
const { client, appearance } = useGraineAgent();
|
|
8
8
|
const ref = useRef(null);
|
|
9
9
|
const startedRef = useRef(false);
|
|
10
|
+
const activeRef = useRef(active);
|
|
11
|
+
activeRef.current = active;
|
|
12
|
+
const mountedIdleRef = useRef(!active);
|
|
10
13
|
const [connected, setConnected] = useState(false);
|
|
11
14
|
const [connecting, setConnecting] = useState(false);
|
|
12
15
|
const [muted, setMutedState] = useState(false);
|
|
@@ -113,7 +116,7 @@ export function GraineVoiceLauncher({ webView: WebView, autoStart = false, trans
|
|
|
113
116
|
case "graine:ready":
|
|
114
117
|
setReady(true);
|
|
115
118
|
pushContext();
|
|
116
|
-
if ((autoStart || pendingStartRef.current) && !startedRef.current) {
|
|
119
|
+
if ((autoStart || pendingStartRef.current) && !startedRef.current && activeRef.current) {
|
|
117
120
|
pendingStartRef.current = false;
|
|
118
121
|
startedRef.current = true;
|
|
119
122
|
void beginCall();
|
|
@@ -180,6 +183,33 @@ export function GraineVoiceLauncher({ webView: WebView, autoStart = false, trans
|
|
|
180
183
|
}, [post]),
|
|
181
184
|
};
|
|
182
185
|
useEffect(() => () => { post({ type: "graine:end-call" }); }, [post]);
|
|
186
|
+
const activeSeenRef = useRef(null);
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
const first = activeSeenRef.current === null;
|
|
189
|
+
activeSeenRef.current = active;
|
|
190
|
+
if (active) {
|
|
191
|
+
if (autoStart) {
|
|
192
|
+
if (startedRef.current)
|
|
193
|
+
return;
|
|
194
|
+
if (ready) {
|
|
195
|
+
startedRef.current = true;
|
|
196
|
+
void beginCall();
|
|
197
|
+
}
|
|
198
|
+
else
|
|
199
|
+
pendingStartRef.current = true;
|
|
200
|
+
}
|
|
201
|
+
else if (!first) {
|
|
202
|
+
post({ type: "graine:warm" });
|
|
203
|
+
}
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (first)
|
|
207
|
+
return;
|
|
208
|
+
if (startedRef.current || pendingStartRef.current)
|
|
209
|
+
post({ type: "graine:end-call" });
|
|
210
|
+
startedRef.current = false;
|
|
211
|
+
pendingStartRef.current = false;
|
|
212
|
+
}, [active]);
|
|
183
213
|
useEffect(() => {
|
|
184
214
|
let last = AppState.currentState;
|
|
185
215
|
let pending = null;
|
|
@@ -211,6 +241,7 @@ export function GraineVoiceLauncher({ webView: WebView, autoStart = false, trans
|
|
|
211
241
|
const effectiveTransport = transport ?? (appearance?.audioTransport === "rtc" ? "rtc" : "ws");
|
|
212
242
|
const src = `${client.opts.baseUrl.replace(/\/$/, "")}/embed/${voiceAgentId}` +
|
|
213
243
|
`?mode=voice&branding=0&embed=1&transport=${effectiveTransport}` +
|
|
244
|
+
(mountedIdleRef.current ? "&idle=1" : "") +
|
|
214
245
|
`&pk=${encodeURIComponent(client.opts.publishableKey)}` +
|
|
215
246
|
(appearance?.accent ? `&accent=${encodeURIComponent(String(appearance.accent).replace("#", ""))}` : "");
|
|
216
247
|
return (_jsxs(_Fragment, { children: [_jsx(View, { style: { position: "absolute", width: 1, height: 1, opacity: 0, bottom: 0, left: 0 }, pointerEvents: "none", children: _jsx(WebView, { ref: ref, source: { uri: src }, originWhitelist: ["*"], javaScriptEnabled: true, domStorageEnabled: true, allowsInlineMediaPlayback: true, mediaPlaybackRequiresUserAction: false, mediaCapturePermissionGrantType: "grant", onMessage: onMessage, style: { width: 1, height: 1, backgroundColor: "transparent" } }) }), children?.(api)] }));
|
package/package.json
CHANGED