@npcify/react 0.4.1 → 0.7.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 +11 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +59 -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,13 @@ 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.
|
|
85
|
+
- Sight: call `startSight()` on the ready SDK after the conversation starts to
|
|
86
|
+
let the character see the player's camera, and `stopSight()` to close it.
|
|
87
|
+
`sightState` is `'unavailable'` until the owner turns sight on in the Sight
|
|
88
|
+
tab. See the `@npcify/web` README (Sight).
|
|
79
89
|
- `onReady(npcify)` and `onError(error)` callbacks expose the SDK and errors.
|
|
80
90
|
- `class`/`style` (React: `className`/`style`) customize the outer div. It defaults
|
|
81
91
|
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, InputMode, InputModeError, ListeningOptions, ListeningState, LoadCharacterOptions, Npcify, NpcifyCharacter, NpcifyView, PushToTalkOptions, 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,7 +59,10 @@ import {
|
|
|
49
59
|
NpcifyCharacter,
|
|
50
60
|
createCharacter,
|
|
51
61
|
loadCharacter,
|
|
62
|
+
DEFAULT_VARIANT_KEY,
|
|
63
|
+
NUDE_VARIANT_KEY,
|
|
52
64
|
InputModeError,
|
|
65
|
+
SightError,
|
|
53
66
|
SpeechInputError,
|
|
54
67
|
bindPushToTalk
|
|
55
68
|
} from "@npcify/web";
|
|
@@ -61,24 +74,39 @@ var NpcifyCanvas = function({
|
|
|
61
74
|
...attributes
|
|
62
75
|
}) {
|
|
63
76
|
const host = useRef(null);
|
|
77
|
+
const attached = useRef(null);
|
|
64
78
|
const callbacks = useRef({ onReady, onError });
|
|
79
|
+
const latestMemoryIdentifier = useRef(options.memoryIdentifier);
|
|
80
|
+
latestMemoryIdentifier.current = options.memoryIdentifier;
|
|
65
81
|
useEffect(() => {
|
|
66
82
|
callbacks.current = { onReady, onError };
|
|
67
83
|
}, [onReady, onError]);
|
|
68
|
-
const {
|
|
84
|
+
const {
|
|
85
|
+
baseUrl,
|
|
86
|
+
characterId,
|
|
87
|
+
apiKey,
|
|
88
|
+
apiToken,
|
|
89
|
+
serverRendering,
|
|
90
|
+
assetProfile,
|
|
91
|
+
normalizeIdleOrientation,
|
|
92
|
+
memoryIdentifier
|
|
93
|
+
} = options;
|
|
69
94
|
const inputModes = options.inputModes?.join(",");
|
|
70
95
|
useEffect(() => {
|
|
71
96
|
if (!host.current) {
|
|
72
97
|
return;
|
|
73
98
|
}
|
|
74
|
-
|
|
99
|
+
const handle = attachCharacter(
|
|
75
100
|
host.current,
|
|
76
101
|
{
|
|
77
102
|
baseUrl,
|
|
78
103
|
characterId,
|
|
79
104
|
apiKey,
|
|
105
|
+
apiToken,
|
|
80
106
|
serverRendering,
|
|
81
107
|
assetProfile,
|
|
108
|
+
normalizeIdleOrientation,
|
|
109
|
+
memoryIdentifier: latestMemoryIdentifier.current,
|
|
82
110
|
inputModes: inputModes ? inputModes.split(",") : void 0
|
|
83
111
|
},
|
|
84
112
|
{
|
|
@@ -92,7 +120,24 @@ var NpcifyCanvas = function({
|
|
|
92
120
|
}
|
|
93
121
|
}
|
|
94
122
|
);
|
|
95
|
-
|
|
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]);
|
|
96
141
|
return createElement("div", {
|
|
97
142
|
...attributes,
|
|
98
143
|
ref: host,
|
|
@@ -101,10 +146,13 @@ var NpcifyCanvas = function({
|
|
|
101
146
|
};
|
|
102
147
|
export {
|
|
103
148
|
Character,
|
|
149
|
+
DEFAULT_VARIANT_KEY,
|
|
104
150
|
InputModeError,
|
|
151
|
+
NUDE_VARIANT_KEY,
|
|
105
152
|
Npcify,
|
|
106
153
|
NpcifyCanvas,
|
|
107
154
|
NpcifyCharacter,
|
|
155
|
+
SightError,
|
|
108
156
|
SpeechInputError,
|
|
109
157
|
bindPushToTalk,
|
|
110
158
|
createCharacter,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@npcify/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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.7.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": "^18.3.0 || ^19.0.0"
|