@npcify/react 0.5.0 → 0.7.1
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 +7 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +57 -11
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -68,7 +68,10 @@ 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`)
|
|
71
|
+
`assetProfile` (`original` or `web-optimized-v1`), `memoryIdentifier` (player
|
|
72
|
+
memory identifier when **SDK Player Memory** is enabled in **Export → Web SDK**;
|
|
73
|
+
leave empty or `null` to share the character owner's **Dashboard → Memory**
|
|
74
|
+
bucket, and update in place without remounting the canvas), and `inputModes` (`'options'`,
|
|
72
75
|
`'text'`, `'voice'`; `'voice'` needs the character's voice input, which the
|
|
73
76
|
owner turns on in the STT tab). See Export → Web SDK for the character's
|
|
74
77
|
configuration.
|
|
@@ -76,6 +79,9 @@ export default function App() {
|
|
|
76
79
|
- Voice input: call `bindPushToTalk({ element })` on the ready SDK to talk while
|
|
77
80
|
the player holds a button or Space; the release sends the speech. See the
|
|
78
81
|
`@npcify/web` README (Voice input and input modes).
|
|
82
|
+
- Typing: call `notifyUserTyping(true)` on the ready SDK from your text
|
|
83
|
+
field's `input` event, so that the character looks at the player while
|
|
84
|
+
they type.
|
|
79
85
|
- Sight: call `startSight()` on the ready SDK after the conversation starts to
|
|
80
86
|
let the character see the player's camera, and `stopSight()` to close it.
|
|
81
87
|
`sightState` is `'unavailable'` until the owner turns sight on in the Sight
|
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, InputMode, InputModeError, ListeningOptions, ListeningState, LoadCharacterOptions, Npcify, NpcifyCharacter, NpcifyView, PushToTalkOptions, SightError, SightObservationEvent, SightOptions, SightState, SpeechInputError, SpeechInputResult, TranscriptEvent, bindPushToTalk, createCharacter, loadCharacter } from '@npcify/web';
|
|
3
|
+
export { AvatarVariantSummary, Character, CharacterAnimation, CharacterAnimationPlayOptions, CharacterAudio, CharacterDisposeOptions, CharacterExpressions, CharacterOptions, CharacterShadowOptions, CharacterSpeechState, CharacterTransformOptions, CharacterVariantChangeEvent, DEFAULT_VARIANT_KEY, InputMode, InputModeError, ListeningOptions, ListeningState, LoadCharacterOptions, NUDE_VARIANT_KEY, Npcify, NpcifyCharacter, NpcifyEventMap, NpcifyEventName, NpcifyView, PushToTalkOptions, SightError, SightObservationEvent, SightOptions, SightState, SpeechInputError, SpeechInputResult, StagingToolCall, StagingToolCallResult, TranscriptEvent, VariantChangeEvent, 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
|
@@ -9,13 +9,16 @@ import {
|
|
|
9
9
|
} from "react";
|
|
10
10
|
|
|
11
11
|
// ../framework-bindings/lifecycle.ts
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
mountNpcify
|
|
14
|
+
} from "@npcify/web";
|
|
13
15
|
var attachCharacter = function(host, options, callbacks) {
|
|
14
16
|
const canvas = document.createElement("canvas");
|
|
15
17
|
canvas.style.cssText = "display:block;width:100%;height:100%;touch-action:none";
|
|
16
18
|
host.append(canvas);
|
|
17
19
|
let active = true;
|
|
18
|
-
let
|
|
20
|
+
let mountedView;
|
|
21
|
+
let latestMemoryIdentifier = options.memoryIdentifier;
|
|
19
22
|
const report = (value) => {
|
|
20
23
|
const error = value instanceof Error ? value : new Error(String(value));
|
|
21
24
|
if (active) {
|
|
@@ -31,14 +34,21 @@ var attachCharacter = function(host, options, callbacks) {
|
|
|
31
34
|
await view.dispose();
|
|
32
35
|
return;
|
|
33
36
|
}
|
|
34
|
-
|
|
37
|
+
mountedView = view;
|
|
38
|
+
view.setMemoryIdentifier(latestMemoryIdentifier);
|
|
35
39
|
callbacks.onReady?.(view.npcify);
|
|
36
40
|
}).catch(report);
|
|
37
|
-
return
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
return {
|
|
42
|
+
setMemoryIdentifier: (memoryIdentifier) => {
|
|
43
|
+
latestMemoryIdentifier = memoryIdentifier;
|
|
44
|
+
mountedView?.setMemoryIdentifier(memoryIdentifier);
|
|
45
|
+
},
|
|
46
|
+
dispose: () => {
|
|
47
|
+
active = false;
|
|
48
|
+
canvas.remove();
|
|
49
|
+
void mountedView?.dispose().catch((error) => console.error(error));
|
|
50
|
+
mountedView = void 0;
|
|
51
|
+
}
|
|
42
52
|
};
|
|
43
53
|
};
|
|
44
54
|
|
|
@@ -49,6 +59,8 @@ import {
|
|
|
49
59
|
NpcifyCharacter,
|
|
50
60
|
createCharacter,
|
|
51
61
|
loadCharacter,
|
|
62
|
+
DEFAULT_VARIANT_KEY,
|
|
63
|
+
NUDE_VARIANT_KEY,
|
|
52
64
|
InputModeError,
|
|
53
65
|
SightError,
|
|
54
66
|
SpeechInputError,
|
|
@@ -62,24 +74,39 @@ var NpcifyCanvas = function({
|
|
|
62
74
|
...attributes
|
|
63
75
|
}) {
|
|
64
76
|
const host = useRef(null);
|
|
77
|
+
const attached = useRef(null);
|
|
65
78
|
const callbacks = useRef({ onReady, onError });
|
|
79
|
+
const latestMemoryIdentifier = useRef(options.memoryIdentifier);
|
|
80
|
+
latestMemoryIdentifier.current = options.memoryIdentifier;
|
|
66
81
|
useEffect(() => {
|
|
67
82
|
callbacks.current = { onReady, onError };
|
|
68
83
|
}, [onReady, onError]);
|
|
69
|
-
const {
|
|
84
|
+
const {
|
|
85
|
+
baseUrl,
|
|
86
|
+
characterId,
|
|
87
|
+
apiKey,
|
|
88
|
+
apiToken,
|
|
89
|
+
serverRendering,
|
|
90
|
+
assetProfile,
|
|
91
|
+
normalizeIdleOrientation,
|
|
92
|
+
memoryIdentifier
|
|
93
|
+
} = options;
|
|
70
94
|
const inputModes = options.inputModes?.join(",");
|
|
71
95
|
useEffect(() => {
|
|
72
96
|
if (!host.current) {
|
|
73
97
|
return;
|
|
74
98
|
}
|
|
75
|
-
|
|
99
|
+
const handle = attachCharacter(
|
|
76
100
|
host.current,
|
|
77
101
|
{
|
|
78
102
|
baseUrl,
|
|
79
103
|
characterId,
|
|
80
104
|
apiKey,
|
|
105
|
+
apiToken,
|
|
81
106
|
serverRendering,
|
|
82
107
|
assetProfile,
|
|
108
|
+
normalizeIdleOrientation,
|
|
109
|
+
memoryIdentifier: latestMemoryIdentifier.current,
|
|
83
110
|
inputModes: inputModes ? inputModes.split(",") : void 0
|
|
84
111
|
},
|
|
85
112
|
{
|
|
@@ -93,7 +120,24 @@ var NpcifyCanvas = function({
|
|
|
93
120
|
}
|
|
94
121
|
}
|
|
95
122
|
);
|
|
96
|
-
|
|
123
|
+
attached.current = handle;
|
|
124
|
+
return () => {
|
|
125
|
+
attached.current = null;
|
|
126
|
+
handle.dispose();
|
|
127
|
+
};
|
|
128
|
+
}, [
|
|
129
|
+
baseUrl,
|
|
130
|
+
characterId,
|
|
131
|
+
apiKey,
|
|
132
|
+
apiToken,
|
|
133
|
+
serverRendering,
|
|
134
|
+
assetProfile,
|
|
135
|
+
normalizeIdleOrientation,
|
|
136
|
+
inputModes
|
|
137
|
+
]);
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
attached.current?.setMemoryIdentifier(memoryIdentifier);
|
|
140
|
+
}, [memoryIdentifier]);
|
|
97
141
|
return createElement("div", {
|
|
98
142
|
...attributes,
|
|
99
143
|
ref: host,
|
|
@@ -102,7 +146,9 @@ var NpcifyCanvas = function({
|
|
|
102
146
|
};
|
|
103
147
|
export {
|
|
104
148
|
Character,
|
|
149
|
+
DEFAULT_VARIANT_KEY,
|
|
105
150
|
InputModeError,
|
|
151
|
+
NUDE_VARIANT_KEY,
|
|
106
152
|
Npcify,
|
|
107
153
|
NpcifyCanvas,
|
|
108
154
|
NpcifyCharacter,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@npcify/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
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.7.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": "^18.3.0 || ^19.0.0"
|