@npcify/vue 0.1.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 ADDED
@@ -0,0 +1,90 @@
1
+ # @npcify/vue
2
+
3
+ Vue 3.5 or later integration for Npcify characters. The `NpcifyCanvas` component mounts
4
+ `@npcify/web`, resizes its canvas, and cleans up rendering and conversations when
5
+ removed. Both local WebGL and protected server rendering are supported.
6
+
7
+ ```sh
8
+ npm install @npcify/vue
9
+ ```
10
+
11
+ Use this example in `App.vue` in your existing Vue project:
12
+
13
+ ```vue
14
+ <template>
15
+ <NpcifyCanvas :options="config" @ready="handleReady" @error="reportError"
16
+ style="height: 480px" />
17
+ <button :disabled="!npcify || started" @click="start">Start conversation</button>
18
+ <div>
19
+ <button v-for="(option, index) in replies" :key="index" @click="reply(option.label)">
20
+ {{ option.label }}
21
+ </button>
22
+ </div>
23
+ <p role="status">{{ status }}</p>
24
+ </template>
25
+
26
+ <script setup>
27
+ import { ref, shallowRef } from 'vue'
28
+ import { NpcifyCanvas } from '@npcify/vue'
29
+
30
+ const config = {
31
+ baseUrl: 'https://api.npcify.ai',
32
+ characterId: '<character-id>',
33
+ apiKey: '<paste-your-scoped-api-key>',
34
+ serverRendering: false,
35
+ }
36
+ const npcify = shallowRef(null)
37
+ const started = ref(false)
38
+ const replies = ref([])
39
+ const status = ref('')
40
+ const reportError = (error) => { status.value = error.message }
41
+ const handleReady = (client) => {
42
+ npcify.value = client
43
+ client.onOptionsReady(({ options }) => { replies.value = options })
44
+ }
45
+ const start = async () => {
46
+ started.value = true
47
+ status.value = ''
48
+ try {
49
+ await npcify.value.unlockAudio()
50
+ await npcify.value.createConversation()
51
+ } catch (error) {
52
+ reportError(error)
53
+ started.value = false
54
+ }
55
+ }
56
+ const reply = async (label) => {
57
+ replies.value = []
58
+ try { await npcify.value.sendMessage(label) }
59
+ catch (error) { reportError(error) }
60
+ }
61
+ </script>
62
+ ```
63
+
64
+ ## Component API
65
+
66
+ - `options`: `baseUrl`, `characterId`, `apiKey`, `serverRendering`, and optional
67
+ `assetProfile` (`original` or `web-optimized-v1`). See Export → Web SDK for the
68
+ character's configuration. These are JavaScript props, never HTML attributes.
69
+ - `@ready="handler"` and `@error="handler"` events expose the SDK and errors.
70
+ - `class`/`style` (React: `className`/`style`) customize the outer div. It defaults
71
+ to 100% width and 480px height. Give it a nonzero height.
72
+
73
+ Changing a configuration field replaces the SDK instance with a fresh canvas.
74
+ Register conversation callbacks on each ready event, and clear any application
75
+ state that belongs to the previous character when changing configuration.
76
+ Equivalent configuration values do not restart the renderer. Pending loads are
77
+ disposed when they finish after unmount; obsolete ready/error callbacks are
78
+ suppressed. Mounting does not start a conversation or request audio permission.
79
+ Start conversations from a user gesture, as shown above.
80
+
81
+ The component is safe to render on the server; browser loading starts after
82
+ mount. Vue refs that store an SDK instance should use `shallowRef` so the renderer is not deeply proxied.
83
+
84
+ Create a scoped key in Export → API keys. Browser keys are visible to visitors;
85
+ keep character scopes narrow and use your own backend when a key must stay
86
+ private. API use is billed to the key owner. Rotation and scope changes revoke
87
+ live conversation connections; downloaded assets retain their existing lifetime.
88
+
89
+ See [@npcify/web](https://www.npmjs.com/package/@npcify/web) for the underlying SDK,
90
+ conversation methods, rendering modes, and deployment requirements.
@@ -0,0 +1,29 @@
1
+ import * as vue from 'vue';
2
+ import { PropType } from 'vue';
3
+ import { MountNpcifyOptions, Npcify } from '@npcify/web';
4
+ export { Npcify, NpcifyView } from '@npcify/web';
5
+
6
+ type NpcifyOptions = Omit<MountNpcifyOptions, 'canvas' | 'onError'>;
7
+
8
+ /** Sized container; options are component props and never DOM attributes. */
9
+ declare const NpcifyCanvas: vue.DefineComponent<vue.ExtractPropTypes<{
10
+ options: {
11
+ type: PropType<NpcifyOptions>;
12
+ required: true;
13
+ };
14
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
15
+ [key: string]: any;
16
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
17
+ ready: (_npcify: Npcify) => true;
18
+ error: (_error: Error) => true;
19
+ }, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
20
+ options: {
21
+ type: PropType<NpcifyOptions>;
22
+ required: true;
23
+ };
24
+ }>> & Readonly<{
25
+ onReady?: ((_npcify: Npcify) => any) | undefined;
26
+ onError?: ((_error: Error) => any) | undefined;
27
+ }>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
28
+
29
+ export { NpcifyCanvas, type NpcifyOptions };
package/dist/index.js ADDED
@@ -0,0 +1,96 @@
1
+ // src/index.ts
2
+ import {
3
+ defineComponent,
4
+ h,
5
+ onMounted,
6
+ onBeforeUnmount,
7
+ ref,
8
+ watch
9
+ } from "vue";
10
+
11
+ // ../framework-bindings/lifecycle.ts
12
+ import { mountNpcify } from "@npcify/web";
13
+ var attachCharacter = function(host, options, callbacks) {
14
+ const canvas = document.createElement("canvas");
15
+ canvas.style.cssText = "display:block;width:100%;height:100%;touch-action:none";
16
+ host.append(canvas);
17
+ let active = true;
18
+ let dispose;
19
+ const report = (value) => {
20
+ const error = value instanceof Error ? value : new Error(String(value));
21
+ if (active) {
22
+ if (callbacks.onError) {
23
+ callbacks.onError(error);
24
+ } else {
25
+ console.error(error);
26
+ }
27
+ }
28
+ };
29
+ void mountNpcify({ ...options, canvas, onError: report }).then(async (view) => {
30
+ if (!active) {
31
+ await view.dispose();
32
+ return;
33
+ }
34
+ dispose = () => view.dispose();
35
+ callbacks.onReady?.(view.npcify);
36
+ }).catch(report);
37
+ return () => {
38
+ active = false;
39
+ canvas.remove();
40
+ void dispose?.().catch((error) => console.error(error));
41
+ dispose = void 0;
42
+ };
43
+ };
44
+
45
+ // src/index.ts
46
+ import { Npcify } from "@npcify/web";
47
+ var NpcifyCanvas = defineComponent({
48
+ name: "NpcifyCanvas",
49
+ inheritAttrs: false,
50
+ props: {
51
+ options: { type: Object, required: true }
52
+ },
53
+ emits: {
54
+ ready: (_npcify) => true,
55
+ error: (_error) => true
56
+ },
57
+ setup(props, { attrs, emit }) {
58
+ const host = ref(null);
59
+ let cleanup;
60
+ onMounted(() => {
61
+ watch(
62
+ [
63
+ () => props.options.baseUrl,
64
+ () => props.options.characterId,
65
+ () => props.options.apiKey,
66
+ () => props.options.serverRendering,
67
+ () => props.options.assetProfile
68
+ ],
69
+ () => {
70
+ cleanup?.();
71
+ if (host.value) {
72
+ cleanup = attachCharacter(
73
+ host.value,
74
+ { ...props.options },
75
+ {
76
+ onReady: (npcify) => emit("ready", npcify),
77
+ onError: (error) => emit("error", error)
78
+ }
79
+ );
80
+ }
81
+ },
82
+ { immediate: true }
83
+ );
84
+ });
85
+ onBeforeUnmount(() => cleanup?.());
86
+ return () => h("div", {
87
+ ...attrs,
88
+ ref: host,
89
+ style: [{ width: "100%", height: "480px" }, attrs.style]
90
+ });
91
+ }
92
+ });
93
+ export {
94
+ Npcify,
95
+ NpcifyCanvas
96
+ };
@@ -0,0 +1,48 @@
1
+ <template>
2
+ <NpcifyCanvas :options="config" @ready="handleReady" @error="reportError"
3
+ style="height: 480px" />
4
+ <button :disabled="!npcify || started" @click="start">Start conversation</button>
5
+ <div>
6
+ <button v-for="(option, index) in replies" :key="index" @click="reply(option.label)">
7
+ {{ option.label }}
8
+ </button>
9
+ </div>
10
+ <p role="status">{{ status }}</p>
11
+ </template>
12
+
13
+ <script setup>
14
+ import { ref, shallowRef } from 'vue'
15
+ import { NpcifyCanvas } from '@npcify/vue'
16
+
17
+ const config = {
18
+ baseUrl: 'https://api.npcify.ai',
19
+ characterId: '<character-id>',
20
+ apiKey: '<paste-your-scoped-api-key>',
21
+ serverRendering: false,
22
+ }
23
+ const npcify = shallowRef(null)
24
+ const started = ref(false)
25
+ const replies = ref([])
26
+ const status = ref('')
27
+ const reportError = (error) => { status.value = error.message }
28
+ const handleReady = (client) => {
29
+ npcify.value = client
30
+ client.onOptionsReady(({ options }) => { replies.value = options })
31
+ }
32
+ const start = async () => {
33
+ started.value = true
34
+ status.value = ''
35
+ try {
36
+ await npcify.value.unlockAudio()
37
+ await npcify.value.createConversation()
38
+ } catch (error) {
39
+ reportError(error)
40
+ started.value = false
41
+ }
42
+ }
43
+ const reply = async (label) => {
44
+ replies.value = []
45
+ try { await npcify.value.sendMessage(label) }
46
+ catch (error) { reportError(error) }
47
+ }
48
+ </script>
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@npcify/vue",
3
+ "version": "0.1.0",
4
+ "description": "Vue components for Npcify characters and conversations",
5
+ "type": "module",
6
+ "license": "UNLICENSED",
7
+ "homepage": "https://npcify.ai",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "examples"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public",
23
+ "registry": "https://registry.npmjs.org/"
24
+ },
25
+ "dependencies": {
26
+ "@npcify/web": "^0.1.0"
27
+ },
28
+ "peerDependencies": {
29
+ "vue": "^3.5.0"
30
+ },
31
+ "devDependencies": {
32
+ "tsup": "^8.5.0",
33
+ "typescript": "^5.9.3",
34
+ "vitest": "^4.0.0",
35
+ "jsdom": "^27.0.0",
36
+ "vue": "^3.5.39"
37
+ },
38
+ "scripts": {
39
+ "build": "tsup",
40
+ "typecheck": "tsc --noEmit",
41
+ "test": "vitest run"
42
+ }
43
+ }