@npcify/react 0.2.0 → 0.3.0
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/README.md +6 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -3
- package/examples/App.jsx +21 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -68,8 +68,12 @@ export default function App() {
|
|
|
68
68
|
## Component API
|
|
69
69
|
|
|
70
70
|
- `options`: `baseUrl`, `characterId`, `apiKey`, `serverRendering`, and optional
|
|
71
|
-
`assetProfile` (`original` or `web-optimized-v1`)
|
|
72
|
-
|
|
71
|
+
`assetProfile` (`original` or `web-optimized-v1`) and `inputModes` (`'options'`,
|
|
72
|
+
`'text'`, `'voice'`). See Export → Web SDK for the character's configuration.
|
|
73
|
+
These are JavaScript props, never HTML attributes.
|
|
74
|
+
- Voice input: call `bindPushToTalk({ element })` on the ready SDK to talk while
|
|
75
|
+
the player holds a button or Space; the release sends the speech. See the
|
|
76
|
+
`@npcify/web` README (Voice input and input modes).
|
|
73
77
|
- `onReady(npcify)` and `onError(error)` callbacks expose the SDK and errors.
|
|
74
78
|
- `class`/`style` (React: `className`/`style`) customize the outer div. It defaults
|
|
75
79
|
to 100% width and 480px height. Give it a nonzero height.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HTMLAttributes, ReactElement } from 'react';
|
|
2
2
|
import { Npcify, MountNpcifyOptions } from '@npcify/web';
|
|
3
|
-
export { Character, CharacterAnimation, CharacterAnimationPlayOptions, CharacterAudio, CharacterDisposeOptions, CharacterExpressions, CharacterOptions, CharacterShadowOptions, CharacterSpeechState, CharacterTransformOptions, LoadCharacterOptions, Npcify, NpcifyCharacter, NpcifyView, createCharacter, loadCharacter } from '@npcify/web';
|
|
3
|
+
export { Character, CharacterAnimation, CharacterAnimationPlayOptions, CharacterAudio, CharacterDisposeOptions, CharacterExpressions, CharacterOptions, CharacterShadowOptions, CharacterSpeechState, CharacterTransformOptions, InputMode, InputModeError, ListeningOptions, ListeningState, LoadCharacterOptions, Npcify, NpcifyCharacter, NpcifyView, PushToTalkOptions, SpeechInputError, SpeechInputResult, TranscriptEvent, bindPushToTalk, createCharacter, loadCharacter } from '@npcify/web';
|
|
4
4
|
|
|
5
5
|
type NpcifyOptions = Omit<MountNpcifyOptions, 'canvas' | 'onError'>;
|
|
6
6
|
interface NpcifyCallbacks {
|
package/dist/index.js
CHANGED
|
@@ -48,7 +48,10 @@ import {
|
|
|
48
48
|
Npcify,
|
|
49
49
|
NpcifyCharacter,
|
|
50
50
|
createCharacter,
|
|
51
|
-
loadCharacter
|
|
51
|
+
loadCharacter,
|
|
52
|
+
InputModeError,
|
|
53
|
+
SpeechInputError,
|
|
54
|
+
bindPushToTalk
|
|
52
55
|
} from "@npcify/web";
|
|
53
56
|
var NpcifyCanvas = function({
|
|
54
57
|
options,
|
|
@@ -63,13 +66,21 @@ var NpcifyCanvas = function({
|
|
|
63
66
|
callbacks.current = { onReady, onError };
|
|
64
67
|
}, [onReady, onError]);
|
|
65
68
|
const { baseUrl, characterId, apiKey, serverRendering, assetProfile } = options;
|
|
69
|
+
const inputModes = options.inputModes?.join(",");
|
|
66
70
|
useEffect(() => {
|
|
67
71
|
if (!host.current) {
|
|
68
72
|
return;
|
|
69
73
|
}
|
|
70
74
|
return attachCharacter(
|
|
71
75
|
host.current,
|
|
72
|
-
{
|
|
76
|
+
{
|
|
77
|
+
baseUrl,
|
|
78
|
+
characterId,
|
|
79
|
+
apiKey,
|
|
80
|
+
serverRendering,
|
|
81
|
+
assetProfile,
|
|
82
|
+
inputModes: inputModes ? inputModes.split(",") : void 0
|
|
83
|
+
},
|
|
73
84
|
{
|
|
74
85
|
onReady: (npcify) => callbacks.current.onReady?.(npcify),
|
|
75
86
|
onError: (error) => {
|
|
@@ -81,7 +92,7 @@ var NpcifyCanvas = function({
|
|
|
81
92
|
}
|
|
82
93
|
}
|
|
83
94
|
);
|
|
84
|
-
}, [baseUrl, characterId, apiKey, serverRendering, assetProfile]);
|
|
95
|
+
}, [baseUrl, characterId, apiKey, serverRendering, assetProfile, inputModes]);
|
|
85
96
|
return createElement("div", {
|
|
86
97
|
...attributes,
|
|
87
98
|
ref: host,
|
|
@@ -90,9 +101,12 @@ var NpcifyCanvas = function({
|
|
|
90
101
|
};
|
|
91
102
|
export {
|
|
92
103
|
Character,
|
|
104
|
+
InputModeError,
|
|
93
105
|
Npcify,
|
|
94
106
|
NpcifyCanvas,
|
|
95
107
|
NpcifyCharacter,
|
|
108
|
+
SpeechInputError,
|
|
109
|
+
bindPushToTalk,
|
|
96
110
|
createCharacter,
|
|
97
111
|
loadCharacter
|
|
98
112
|
};
|
package/examples/App.jsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { useRef, useState } from 'react'
|
|
3
|
+
import { useEffect, useRef, useState } from 'react'
|
|
4
4
|
import { NpcifyCanvas } from '@npcify/react'
|
|
5
5
|
|
|
6
6
|
const config = {
|
|
@@ -12,14 +12,31 @@ const config = {
|
|
|
12
12
|
|
|
13
13
|
export default function App() {
|
|
14
14
|
const npcify = useRef(null)
|
|
15
|
+
const talk = useRef(null)
|
|
16
|
+
const unbindTalk = useRef(() => {})
|
|
17
|
+
const replyCount = useRef(0)
|
|
15
18
|
const [ready, setReady] = useState(false)
|
|
16
19
|
const [started, setStarted] = useState(false)
|
|
17
20
|
const [replies, setReplies] = useState([])
|
|
21
|
+
const [voice, setVoice] = useState(false)
|
|
22
|
+
const [listening, setListening] = useState('idle')
|
|
18
23
|
const [status, setStatus] = useState('')
|
|
19
24
|
const reportError = (error) => setStatus(error.message)
|
|
25
|
+
useEffect(() => { replyCount.current = replies.length }, [replies])
|
|
26
|
+
useEffect(() => () => unbindTalk.current(), [])
|
|
20
27
|
const handleReady = (client) => {
|
|
21
28
|
npcify.current = client
|
|
22
29
|
client.onOptionsReady(({ options }) => setReplies(options))
|
|
30
|
+
// Hold the button, or Space, to talk. The release sends the speech.
|
|
31
|
+
setVoice(client.inputModes.includes('voice'))
|
|
32
|
+
client.onListeningState(setListening)
|
|
33
|
+
client.onTranscript(({ text }) => setStatus(text))
|
|
34
|
+
unbindTalk.current = client.bindPushToTalk({
|
|
35
|
+
element: talk.current,
|
|
36
|
+
enabled: () => replyCount.current > 0,
|
|
37
|
+
onResult: ({ sent }) => { if (sent) setReplies([]) },
|
|
38
|
+
onError: reportError,
|
|
39
|
+
})
|
|
23
40
|
setReady(true)
|
|
24
41
|
}
|
|
25
42
|
const start = async () => {
|
|
@@ -46,6 +63,9 @@ export default function App() {
|
|
|
46
63
|
<div>{replies.map((option, index) => (
|
|
47
64
|
<button key={index} onClick={() => reply(option.label)}>{option.label}</button>
|
|
48
65
|
))}</div>
|
|
66
|
+
<button ref={talk} type="button" hidden={!voice} disabled={replies.length === 0}>
|
|
67
|
+
{listening === 'idle' ? 'Hold to talk' : listening === 'recognizing' ? 'Recognizing…' : 'Listening…'}
|
|
68
|
+
</button>
|
|
49
69
|
<p role="status">{status}</p>
|
|
50
70
|
</>
|
|
51
71
|
)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@npcify/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "React components for Npcify characters and conversations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"registry": "https://registry.npmjs.org/"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@npcify/web": "^0.
|
|
26
|
+
"@npcify/web": "^0.3.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": "^18.3.0 || ^19.0.0"
|