Skip to main content

PilotKit

Core container component, integrates Provider and Digital Human rendering, is the root component of all Widget components.

Basic Usage​

import {PilotKit, ControlPanel} from '@bdky/aaas-pilot-kit-react-widget';
import '@bdky/aaas-pilot-kit-react-widget/styles.css';

function App() {
return (
<PilotKit
token="your-token"
figureId="your-figure-id"
ttsPer="your-tts-per"
agentConfig={{
robotId: 'your-robot-id'
}}
>
<ControlPanel />
</PilotKit>
);
}

Using Ref​

Through ref you can access controller methods:

import {useRef} from 'react';
import {PilotKit, type IPilotKitRef} from '@bdky/aaas-pilot-kit-react-widget';
import '@bdky/aaas-pilot-kit-react-widget/styles.css';

function App() {
const pilotKitRef = useRef<IPilotKitRef>(null);

const handleSendMessage = () => {
pilotKitRef.current?.input('Hello');
};

const handleInterrupt = () => {
pilotKitRef.current?.interrupt();
};

return (
<PilotKit ref={pilotKitRef} {...props}>
<button onClick={handleSendMessage}>Send Message</button>
<button onClick={handleInterrupt}>Interrupt</button>
</PilotKit>
);
}

Props​

Required Properties​

PropertyTypeDescription
tokenstringAuthentication Token
figureIdstringDigital Human image ID
ttsPerstringTTS voice ID

Agent Configuration​

PropertyTypeDescription
agentConfig{robotId: string; token?: string}Agent configuration, one of agentService
agentServicetypeof BaseAgentServiceCustom AgentService class
agentConfig vs agentService
  • Use Baidu default Agent: Configure agentConfig
  • Use private Agent API: Provide custom agentService, see Custom AgentService

Behavior Configuration​

PropertyTypeDefault ValueDescription
prologuestring-Opening remarks, automatically broadcast after SDK ready
interruptiblebooleanfalseWhether to allow interruption of broadcasting
timeoutSecnumber120No operation timeout (seconds)
typeDelaynumber100Chinese typewriter effect delay (ms)
enTypeDelaynumber50English typewriter effect delay (ms)
minSplitLennumber10Streaming text minimum split length

Rendering Configuration​

PropertyTypeDefault ValueDescription
rendererMode'cloud-native' | 'standard''standard'Rendering mode
scaleXnumber1Horizontal scale
scaleYnumber1Vertical scale
translateXnumber0Horizontal offset
translateYnumber0Vertical offset

Internationalization Configuration​

PropertyTypeDefault ValueDescription
localestring'zh'UI interface language (v1.1.2+)
messagesPartial<I18nMessages>-Custom translation messages (v1.1.2+)

For detailed configuration, see Internationalization (i18n)

Style Properties​

PropertyTypeDescription
classNamestringCustom class name
styleCSSPropertiesCustom style
backgroundUrlstringBackground image URL
autoMountbooleanWhether to automatically mount, default true

Event Callbacks​

PropertyTypeDescription
onReady() => voidSDK ready
onNeedManualActivation() => voidNeeds manual activation (iOS iframe)
onAsrStart() => voidASR starts
onAsrMessage(payload) => voidASR recognition result
onRenderStart(payload) => voidStart broadcasting
onInactivity(payload) => voidUser inactivity timeout
onBusy(payload) => voidSystem busy
onInterrupt(payload) => voidBroadcasting interrupted
onConversationChange(payload) => voidConversation content changes
onIsRenderingChange(isRendering) => voidBroadcasting state changes
onReplyStart(payload) => voidReply starts
onTtft(payload) => voidFirst character latency metric
Event Payload Types

Event callback Payload type definitions are in React SDK Hooks documentation.

Ref Methods​

Through ref you can access the following methods:

MethodTypeDescription
input(text: string) => voidSend text input
mute(muted: boolean) => voidSet mute state
interrupt() => voidInterrupt current broadcasting
dispose() => voidDestroy instance
playPrologue() => voidBroadcast opening remarks
playFromFullText(text: string) => voidBroadcast complete text
playFromStreamText(text: string) => voidStream broadcast text
keepAlive() => voidKeep connection active
checkAudioDevice() => Promise<Result>Check audio device
activateManually() => Promise<void>Manual activation (iOS)
getIsReady() => booleanGet ready state
getIsMuted() => booleanGet mute state
getIsRendering() => booleanGet broadcasting state

Context​

PilotKit creates PilotKitContext internally, child components can access via usePilotKitContext:

import {usePilotKitContext} from '@bdky/aaas-pilot-kit-react-widget';
import '@bdky/aaas-pilot-kit-react-widget/styles.css';

function ChildComponent() {
const pilotKit = usePilotKitContext();

return (
<button onClick={() => pilotKit?.input('Hello')}>
Send Message
</button>
);
}

Style Customization​

CSS Class Names​

Class NameDescription
.apk-pilot-kitRoot container
.apk-pilot-kit__maskMask layer (children rendering position)

Background Image​

Use backgroundUrl to set background:

<PilotKit
backgroundUrl="https://example.com/background.jpg"
// ...
>