@sidurijs/body 1.0.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/LICENSE +190 -0
- package/README.md +56 -0
- package/dist/cubism-installer.d.ts +21 -0
- package/dist/cubism-installer.js +65 -0
- package/dist/cubism-installer.test.d.ts +1 -0
- package/dist/cubism-installer.test.js +35 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.js +177 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +257 -0
- package/organ-manifest.json +81 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or exemplary damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 VXNUS Creative Technology Studio
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @sidurijs/body
|
|
2
|
+
|
|
3
|
+
The canonical Body Organ for Siduri-X.
|
|
4
|
+
|
|
5
|
+
This organ acts as the embodiment state machine and experience adapter for visual avatars, supporting 2D Live2D Cubism (`.model3.json`) and 3D humanoid VRM (`.vrm`) models.
|
|
6
|
+
|
|
7
|
+
## Architecture & Responsibilities
|
|
8
|
+
|
|
9
|
+
In Siduri's decoupled organ architecture:
|
|
10
|
+
- **Backend / Organ layer (`@sidurijs/body`)**:
|
|
11
|
+
- Serves as the state machine tracking avatar state (`idle`, `speaking`, `acting`), current facial expressions (`neutral`, `happy`, `sad`, etc.), format detection (`live2d` / `vrm`), and trigger actions.
|
|
12
|
+
- Implements the `ExperienceAdapter` contract for approved `avatar` lifecycle events.
|
|
13
|
+
- Maintains model references (`modelPath`, `modelUrl`, `vrmOptions`) without requiring headless GPU or WebGL bindings on the backend server.
|
|
14
|
+
- **Frontend / Client layer (`apps/web` or custom UI)**:
|
|
15
|
+
- Consumes avatar state updates and renders either Live2D Cubism models or 3D humanoid VRM avatars via WebGL / Three.js (`AvatarCanvas`, `VRMRenderer`).
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Live2D
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { NeutralBodyOrgan, Live2DAdapter } from '@sidurijs/body';
|
|
23
|
+
|
|
24
|
+
// Instantiate with Live2D model URL or path
|
|
25
|
+
const body = new Live2DAdapter({
|
|
26
|
+
initialExpression: 'neutral',
|
|
27
|
+
modelUrl: '/assets/body/companion/model.model3.json',
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Update expression or actions
|
|
31
|
+
body.setExpression('happy');
|
|
32
|
+
body.speak('speech-1', 'Hello world');
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### VRM (3D Humanoid / VRoid)
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { VRMAdapter } from '@sidurijs/body';
|
|
39
|
+
|
|
40
|
+
const body = new VRMAdapter({
|
|
41
|
+
modelUrl: '/assets/body/companion/avatar.vrm',
|
|
42
|
+
vrm: {
|
|
43
|
+
specVersion: '1.0',
|
|
44
|
+
lookAtMode: 'camera',
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Third-Party Licensing & Runtime Downloads
|
|
50
|
+
|
|
51
|
+
### Live2D Cubism Notice
|
|
52
|
+
- **Proprietary Core**: Live2D Cubism Core (`live2dcubismcore.min.js`) is proprietary software of Live2D Inc. and cannot be bundled into public npm packages or git repositories under open-source licenses.
|
|
53
|
+
- **Runtime Downloading**: Clients download the official binary directly at runtime from Live2D's verified CDN. You can also programmatically acquire and verify the binary on the host via `downloadCubismCore({ targetDir: './public/live2d', verifyChecksum: true })`.
|
|
54
|
+
- **Indie vs. Commercial Use**: Royalty-free for indie / small-scale entities with annual revenue < 10,000,000 JPY (~$67,000 USD). Commercial publishers exceeding this threshold require a Publication License Agreement directly with Live2D Inc.
|
|
55
|
+
|
|
56
|
+
For details across all organs, see [Third-Party Organ Licensing Documentation](../../docs/third-party-organ-licensing.md).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface PinnedCubismAsset {
|
|
2
|
+
version: string;
|
|
3
|
+
filename: string;
|
|
4
|
+
url: string;
|
|
5
|
+
sha256: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Pinned official Live2D Cubism Core Web release with SHA-256 integrity digest.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_PINNED_CUBISM_CORE: PinnedCubismAsset;
|
|
11
|
+
export declare function computeFileSha256(filePath: string): Promise<string>;
|
|
12
|
+
export interface CubismInstallOptions {
|
|
13
|
+
targetDir: string;
|
|
14
|
+
asset?: PinnedCubismAsset;
|
|
15
|
+
verifyChecksum?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Downloads the official Live2D Cubism Core binary into the specified target directory.
|
|
19
|
+
* Preserves licensing by downloading directly on the user's host environment.
|
|
20
|
+
*/
|
|
21
|
+
export declare function downloadCubismCore(options: CubismInstallOptions): Promise<string>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_PINNED_CUBISM_CORE = void 0;
|
|
4
|
+
exports.computeFileSha256 = computeFileSha256;
|
|
5
|
+
exports.downloadCubismCore = downloadCubismCore;
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const promises_1 = require("node:stream/promises");
|
|
9
|
+
const node_crypto_1 = require("node:crypto");
|
|
10
|
+
/**
|
|
11
|
+
* Pinned official Live2D Cubism Core Web release with SHA-256 integrity digest.
|
|
12
|
+
*/
|
|
13
|
+
exports.DEFAULT_PINNED_CUBISM_CORE = {
|
|
14
|
+
version: '5-r.1',
|
|
15
|
+
filename: 'live2dcubismcore.min.js',
|
|
16
|
+
url: 'https://cubism.live2d.com/sdk-web/cubismcore/live2dcubismcore.min.js',
|
|
17
|
+
sha256: '25ae938cb4fe282ce189b357bcc97e603d1e1f7ec78bf04150d401c23cdc792f',
|
|
18
|
+
};
|
|
19
|
+
async function computeFileSha256(filePath) {
|
|
20
|
+
const hash = (0, node_crypto_1.createHash)('sha256');
|
|
21
|
+
const stream = (0, node_fs_1.createReadStream)(filePath);
|
|
22
|
+
for await (const chunk of stream) {
|
|
23
|
+
hash.update(chunk);
|
|
24
|
+
}
|
|
25
|
+
return hash.digest('hex').toLowerCase();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Downloads the official Live2D Cubism Core binary into the specified target directory.
|
|
29
|
+
* Preserves licensing by downloading directly on the user's host environment.
|
|
30
|
+
*/
|
|
31
|
+
async function downloadCubismCore(options) {
|
|
32
|
+
const asset = options.asset || exports.DEFAULT_PINNED_CUBISM_CORE;
|
|
33
|
+
const targetDir = options.targetDir;
|
|
34
|
+
const destPath = (0, node_path_1.join)(targetDir, asset.filename);
|
|
35
|
+
await node_fs_1.promises.mkdir(targetDir, { recursive: true });
|
|
36
|
+
if ((0, node_fs_1.existsSync)(destPath)) {
|
|
37
|
+
if (options.verifyChecksum && asset.sha256) {
|
|
38
|
+
const hash = await computeFileSha256(destPath);
|
|
39
|
+
if (hash.toLowerCase() === asset.sha256.toLowerCase()) {
|
|
40
|
+
return destPath;
|
|
41
|
+
}
|
|
42
|
+
// Corrupt or outdated, remove and re-download
|
|
43
|
+
await node_fs_1.promises.unlink(destPath).catch(() => { });
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return destPath;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const tmpPath = `${destPath}.tmp-${Date.now()}`;
|
|
50
|
+
const res = await fetch(asset.url);
|
|
51
|
+
if (!res.ok || !res.body) {
|
|
52
|
+
throw new Error(`Failed to download Live2D Cubism Core from ${asset.url}: HTTP ${res.status}`);
|
|
53
|
+
}
|
|
54
|
+
const writeStream = (0, node_fs_1.createWriteStream)(tmpPath);
|
|
55
|
+
await (0, promises_1.pipeline)(res.body, writeStream);
|
|
56
|
+
if (options.verifyChecksum && asset.sha256) {
|
|
57
|
+
const downloadedHash = await computeFileSha256(tmpPath);
|
|
58
|
+
if (downloadedHash.toLowerCase() !== asset.sha256.toLowerCase()) {
|
|
59
|
+
await node_fs_1.promises.unlink(tmpPath).catch(() => { });
|
|
60
|
+
throw new Error(`SHA-256 checksum mismatch for ${asset.filename}. Expected ${asset.sha256}, got ${downloadedHash}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
await node_fs_1.promises.rename(tmpPath, destPath);
|
|
64
|
+
return destPath;
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_fs_1 = require("node:fs");
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const node_os_1 = require("node:os");
|
|
6
|
+
const cubism_installer_1 = require("./cubism-installer");
|
|
7
|
+
describe('Live2D Cubism Core Runtime Installer & Verification', () => {
|
|
8
|
+
const testDir = (0, node_path_1.join)((0, node_os_1.tmpdir)(), `siduri-cubism-test-${Date.now()}`);
|
|
9
|
+
afterAll(() => {
|
|
10
|
+
(0, node_fs_1.rmSync)(testDir, { recursive: true, force: true });
|
|
11
|
+
});
|
|
12
|
+
test('DEFAULT_PINNED_CUBISM_CORE specifies official release metadata and sha256', () => {
|
|
13
|
+
expect(cubism_installer_1.DEFAULT_PINNED_CUBISM_CORE.filename).toBe('live2dcubismcore.min.js');
|
|
14
|
+
expect(cubism_installer_1.DEFAULT_PINNED_CUBISM_CORE.url).toContain('cubism.live2d.com');
|
|
15
|
+
expect(cubism_installer_1.DEFAULT_PINNED_CUBISM_CORE.sha256).toBe('25ae938cb4fe282ce189b357bcc97e603d1e1f7ec78bf04150d401c23cdc792f');
|
|
16
|
+
});
|
|
17
|
+
test('downloadCubismCore downloads and verifies official binary', async () => {
|
|
18
|
+
const destPath = await (0, cubism_installer_1.downloadCubismCore)({
|
|
19
|
+
targetDir: testDir,
|
|
20
|
+
verifyChecksum: true,
|
|
21
|
+
});
|
|
22
|
+
expect((0, node_fs_1.existsSync)(destPath)).toBe(true);
|
|
23
|
+
const hash = await (0, cubism_installer_1.computeFileSha256)(destPath);
|
|
24
|
+
expect(hash).toBe(cubism_installer_1.DEFAULT_PINNED_CUBISM_CORE.sha256);
|
|
25
|
+
const content = (0, node_fs_1.readFileSync)(destPath, 'utf-8');
|
|
26
|
+
expect(content).toContain('Live2D Cubism Core');
|
|
27
|
+
}, 30000);
|
|
28
|
+
test('downloadCubismCore re-uses already verified file without re-downloading', async () => {
|
|
29
|
+
const destPath = await (0, cubism_installer_1.downloadCubismCore)({
|
|
30
|
+
targetDir: testDir,
|
|
31
|
+
verifyChecksum: true,
|
|
32
|
+
});
|
|
33
|
+
expect((0, node_fs_1.existsSync)(destPath)).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { BodyOrgan, ExperienceAdapter, ExperienceEvent, ExperienceAdapterResult } from '@sidurijs/core';
|
|
2
|
+
export * from './cubism-installer';
|
|
3
|
+
export type BodyState = 'idle' | 'speaking' | 'acting';
|
|
4
|
+
export type AvatarFormat = 'live2d' | 'vrm' | 'auto';
|
|
5
|
+
export interface VRMModelOptions {
|
|
6
|
+
/** Target VRM standard specification version */
|
|
7
|
+
specVersion?: '0.x' | '1.0' | 'auto';
|
|
8
|
+
/** Default camera lookAt target behavior */
|
|
9
|
+
lookAtMode?: 'camera' | 'cursor' | 'head' | 'none';
|
|
10
|
+
/** Default resting humanoid pose identifier */
|
|
11
|
+
defaultPose?: string;
|
|
12
|
+
/** Custom blendshape preset map overrides */
|
|
13
|
+
expressionMapping?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
export interface BodySnapshot {
|
|
16
|
+
state: BodyState;
|
|
17
|
+
currentExpression: string;
|
|
18
|
+
format: 'live2d' | 'vrm' | 'unknown';
|
|
19
|
+
modelPath?: string;
|
|
20
|
+
modelUrl?: string;
|
|
21
|
+
lastSpeechId: string | null;
|
|
22
|
+
lastAction: string | null;
|
|
23
|
+
lastText?: string;
|
|
24
|
+
lastLanguage?: string;
|
|
25
|
+
vrmOptions?: VRMModelOptions;
|
|
26
|
+
updatedAt: number;
|
|
27
|
+
}
|
|
28
|
+
export interface NeutralBodyOrganConfig {
|
|
29
|
+
/** Avatar rendering provider */
|
|
30
|
+
provider?: 'live2d' | 'vrm' | 'none' | string;
|
|
31
|
+
/** Explicit format override (defaults to auto-detection from modelUrl/modelPath extension) */
|
|
32
|
+
format?: AvatarFormat;
|
|
33
|
+
initialExpression?: string;
|
|
34
|
+
modelPath?: string;
|
|
35
|
+
modelUrl?: string;
|
|
36
|
+
/** VRM-specific embodiment options */
|
|
37
|
+
vrm?: VRMModelOptions;
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
}
|
|
40
|
+
export type Live2DAdapterConfig = NeutralBodyOrganConfig;
|
|
41
|
+
export declare class NeutralBodyOrgan implements BodyOrgan, ExperienceAdapter {
|
|
42
|
+
readonly kind: "avatar";
|
|
43
|
+
currentExpression: string;
|
|
44
|
+
modelPath?: string;
|
|
45
|
+
modelUrl?: string;
|
|
46
|
+
format: 'live2d' | 'vrm' | 'unknown';
|
|
47
|
+
vrmOptions?: VRMModelOptions;
|
|
48
|
+
lastSpeechId: string | null;
|
|
49
|
+
lastAction: string | null;
|
|
50
|
+
lastText?: string;
|
|
51
|
+
lastLanguage?: string;
|
|
52
|
+
state: BodyState;
|
|
53
|
+
lastEvent: ExperienceEvent | null;
|
|
54
|
+
updatedAt: number;
|
|
55
|
+
constructor(config?: NeutralBodyOrganConfig);
|
|
56
|
+
private detectFormat;
|
|
57
|
+
setExpression(expression: string): void;
|
|
58
|
+
speak(speechId: string, text?: string, language?: string): void;
|
|
59
|
+
act(action: string): void;
|
|
60
|
+
completeAction(): void;
|
|
61
|
+
getSnapshot(): BodySnapshot;
|
|
62
|
+
handleEvent(event: ExperienceEvent): Promise<ExperienceAdapterResult>;
|
|
63
|
+
cleanup(): void;
|
|
64
|
+
}
|
|
65
|
+
export declare const Live2DAdapter: typeof NeutralBodyOrgan;
|
|
66
|
+
/** Specialized alias configured for VRM 3D humanoid models */
|
|
67
|
+
export declare class VRMAdapter extends NeutralBodyOrgan {
|
|
68
|
+
constructor(config?: NeutralBodyOrganConfig);
|
|
69
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.VRMAdapter = exports.Live2DAdapter = exports.NeutralBodyOrgan = void 0;
|
|
18
|
+
const core_1 = require("@sidurijs/core");
|
|
19
|
+
__exportStar(require("./cubism-installer"), exports);
|
|
20
|
+
class NeutralBodyOrgan {
|
|
21
|
+
kind = 'avatar';
|
|
22
|
+
currentExpression = 'neutral';
|
|
23
|
+
modelPath;
|
|
24
|
+
modelUrl;
|
|
25
|
+
format = 'unknown';
|
|
26
|
+
vrmOptions;
|
|
27
|
+
lastSpeechId = null;
|
|
28
|
+
lastAction = null;
|
|
29
|
+
lastText;
|
|
30
|
+
lastLanguage;
|
|
31
|
+
state = 'idle';
|
|
32
|
+
lastEvent = null;
|
|
33
|
+
updatedAt = Date.now();
|
|
34
|
+
constructor(config = {}) {
|
|
35
|
+
if (config.initialExpression) {
|
|
36
|
+
this.currentExpression = config.initialExpression;
|
|
37
|
+
}
|
|
38
|
+
if (config.modelPath) {
|
|
39
|
+
this.modelPath = config.modelPath;
|
|
40
|
+
}
|
|
41
|
+
if (config.modelUrl) {
|
|
42
|
+
this.modelUrl = config.modelUrl;
|
|
43
|
+
}
|
|
44
|
+
if (config.vrm) {
|
|
45
|
+
this.vrmOptions = { ...config.vrm };
|
|
46
|
+
}
|
|
47
|
+
// Resolve avatar format
|
|
48
|
+
this.format = this.detectFormat(config);
|
|
49
|
+
}
|
|
50
|
+
detectFormat(config) {
|
|
51
|
+
if (config.format && config.format !== 'auto') {
|
|
52
|
+
return config.format;
|
|
53
|
+
}
|
|
54
|
+
if (config.provider === 'vrm') {
|
|
55
|
+
return 'vrm';
|
|
56
|
+
}
|
|
57
|
+
if (config.provider === 'live2d') {
|
|
58
|
+
return 'live2d';
|
|
59
|
+
}
|
|
60
|
+
const ref = (this.modelPath || this.modelUrl || '').toLowerCase();
|
|
61
|
+
if (ref.endsWith('.vrm')) {
|
|
62
|
+
return 'vrm';
|
|
63
|
+
}
|
|
64
|
+
if (ref.endsWith('.model3.json') || ref.endsWith('.json')) {
|
|
65
|
+
return 'live2d';
|
|
66
|
+
}
|
|
67
|
+
return 'unknown';
|
|
68
|
+
}
|
|
69
|
+
setExpression(expression) {
|
|
70
|
+
this.currentExpression = expression;
|
|
71
|
+
this.updatedAt = Date.now();
|
|
72
|
+
}
|
|
73
|
+
speak(speechId, text, language) {
|
|
74
|
+
this.lastSpeechId = speechId;
|
|
75
|
+
this.lastText = text;
|
|
76
|
+
this.lastLanguage = language;
|
|
77
|
+
this.state = 'speaking';
|
|
78
|
+
this.updatedAt = Date.now();
|
|
79
|
+
}
|
|
80
|
+
act(action) {
|
|
81
|
+
this.lastAction = action;
|
|
82
|
+
this.state = 'acting';
|
|
83
|
+
this.updatedAt = Date.now();
|
|
84
|
+
}
|
|
85
|
+
completeAction() {
|
|
86
|
+
this.state = 'idle';
|
|
87
|
+
this.updatedAt = Date.now();
|
|
88
|
+
}
|
|
89
|
+
getSnapshot() {
|
|
90
|
+
return {
|
|
91
|
+
state: this.state,
|
|
92
|
+
currentExpression: this.currentExpression,
|
|
93
|
+
format: this.format,
|
|
94
|
+
modelPath: this.modelPath,
|
|
95
|
+
modelUrl: this.modelUrl,
|
|
96
|
+
lastSpeechId: this.lastSpeechId,
|
|
97
|
+
lastAction: this.lastAction,
|
|
98
|
+
lastText: this.lastText,
|
|
99
|
+
lastLanguage: this.lastLanguage,
|
|
100
|
+
vrmOptions: this.vrmOptions,
|
|
101
|
+
updatedAt: this.updatedAt,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
async handleEvent(event) {
|
|
105
|
+
const validation = (0, core_1.validateExperienceEvent)(event);
|
|
106
|
+
if (!validation.valid) {
|
|
107
|
+
return {
|
|
108
|
+
accepted: false,
|
|
109
|
+
eventId: event?.eventId || '',
|
|
110
|
+
lifecycle: 'FAILED',
|
|
111
|
+
error: validation.error,
|
|
112
|
+
reason: 'INVALID_EVENT_ENVELOPE',
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
if (event.kind !== 'avatar') {
|
|
116
|
+
return {
|
|
117
|
+
accepted: false,
|
|
118
|
+
eventId: event.eventId,
|
|
119
|
+
lifecycle: 'FAILED',
|
|
120
|
+
error: `Body adapter received incompatible event kind: ${event.kind}`,
|
|
121
|
+
reason: 'INCOMPATIBLE_EVENT_KIND',
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
if (event.approval !== 'APPROVED') {
|
|
125
|
+
return {
|
|
126
|
+
accepted: false,
|
|
127
|
+
eventId: event.eventId,
|
|
128
|
+
lifecycle: 'FAILED',
|
|
129
|
+
error: 'Event is not APPROVED',
|
|
130
|
+
reason: 'APPROVAL_REQUIRED',
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
this.lastEvent = event;
|
|
134
|
+
if (event.expression) {
|
|
135
|
+
this.setExpression(event.expression);
|
|
136
|
+
}
|
|
137
|
+
if (event.action) {
|
|
138
|
+
this.act(event.action);
|
|
139
|
+
}
|
|
140
|
+
if (event.text) {
|
|
141
|
+
this.lastText = event.text;
|
|
142
|
+
this.lastLanguage = event.language;
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
accepted: true,
|
|
146
|
+
eventId: event.eventId,
|
|
147
|
+
lifecycle: 'STARTED',
|
|
148
|
+
metadata: {
|
|
149
|
+
expression: this.currentExpression,
|
|
150
|
+
action: this.lastAction,
|
|
151
|
+
state: this.state,
|
|
152
|
+
format: this.format,
|
|
153
|
+
companionId: event.companionId,
|
|
154
|
+
correlationId: event.correlationId,
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
cleanup() {
|
|
159
|
+
this.state = 'idle';
|
|
160
|
+
this.lastEvent = null;
|
|
161
|
+
this.updatedAt = Date.now();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.NeutralBodyOrgan = NeutralBodyOrgan;
|
|
165
|
+
// Backward-compatible alias
|
|
166
|
+
exports.Live2DAdapter = NeutralBodyOrgan;
|
|
167
|
+
/** Specialized alias configured for VRM 3D humanoid models */
|
|
168
|
+
class VRMAdapter extends NeutralBodyOrgan {
|
|
169
|
+
constructor(config = {}) {
|
|
170
|
+
super({
|
|
171
|
+
provider: 'vrm',
|
|
172
|
+
format: 'vrm',
|
|
173
|
+
...config,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.VRMAdapter = VRMAdapter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_1 = require("./index");
|
|
4
|
+
describe('NeutralBodyOrgan', () => {
|
|
5
|
+
let organ;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
organ = new index_1.NeutralBodyOrgan();
|
|
8
|
+
});
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
organ.cleanup();
|
|
11
|
+
});
|
|
12
|
+
test('constructs with default or custom initial expression with zero external config', () => {
|
|
13
|
+
expect(organ.currentExpression).toBe('neutral');
|
|
14
|
+
expect(organ.state).toBe('idle');
|
|
15
|
+
expect(organ.lastSpeechId).toBeNull();
|
|
16
|
+
expect(organ.lastAction).toBeNull();
|
|
17
|
+
const customOrgan = new index_1.NeutralBodyOrgan({
|
|
18
|
+
initialExpression: 'happy',
|
|
19
|
+
modelPath: './assets/body/custom/model.model3.json',
|
|
20
|
+
modelUrl: '/assets/body/custom/model.model3.json',
|
|
21
|
+
});
|
|
22
|
+
expect(customOrgan.currentExpression).toBe('happy');
|
|
23
|
+
expect(customOrgan.modelPath).toBe('./assets/body/custom/model.model3.json');
|
|
24
|
+
expect(customOrgan.modelUrl).toBe('/assets/body/custom/model.model3.json');
|
|
25
|
+
const snapshot = customOrgan.getSnapshot();
|
|
26
|
+
expect(snapshot.modelPath).toBe('./assets/body/custom/model.model3.json');
|
|
27
|
+
expect(snapshot.modelUrl).toBe('/assets/body/custom/model.model3.json');
|
|
28
|
+
customOrgan.cleanup();
|
|
29
|
+
});
|
|
30
|
+
test('Live2DAdapter is exported as a compatible alias', () => {
|
|
31
|
+
const adapter = new index_1.Live2DAdapter();
|
|
32
|
+
expect(adapter).toBeInstanceOf(index_1.NeutralBodyOrgan);
|
|
33
|
+
adapter.cleanup();
|
|
34
|
+
});
|
|
35
|
+
test('tracks body state machine transitions locally', () => {
|
|
36
|
+
organ.setExpression('smile');
|
|
37
|
+
expect(organ.currentExpression).toBe('smile');
|
|
38
|
+
organ.speak('speech_101', 'Hello world', 'en');
|
|
39
|
+
expect(organ.lastSpeechId).toBe('speech_101');
|
|
40
|
+
expect(organ.lastText).toBe('Hello world');
|
|
41
|
+
expect(organ.lastLanguage).toBe('en');
|
|
42
|
+
expect(organ.state).toBe('speaking');
|
|
43
|
+
organ.act('wave_hand');
|
|
44
|
+
expect(organ.lastAction).toBe('wave_hand');
|
|
45
|
+
expect(organ.state).toBe('acting');
|
|
46
|
+
organ.completeAction();
|
|
47
|
+
expect(organ.state).toBe('idle');
|
|
48
|
+
const snapshot = organ.getSnapshot();
|
|
49
|
+
expect(snapshot.state).toBe('idle');
|
|
50
|
+
expect(snapshot.currentExpression).toBe('smile');
|
|
51
|
+
expect(snapshot.lastSpeechId).toBe('speech_101');
|
|
52
|
+
expect(snapshot.lastAction).toBe('wave_hand');
|
|
53
|
+
expect(snapshot.lastText).toBe('Hello world');
|
|
54
|
+
expect(snapshot.lastLanguage).toBe('en');
|
|
55
|
+
});
|
|
56
|
+
test('handleEvent processes valid approved avatar event', async () => {
|
|
57
|
+
const res = await organ.handleEvent({
|
|
58
|
+
eventId: 'evt-avatar-1',
|
|
59
|
+
companionId: 'companion-test',
|
|
60
|
+
responseId: 'resp-100',
|
|
61
|
+
correlationId: 'corr-100',
|
|
62
|
+
channel: 'public',
|
|
63
|
+
approval: 'APPROVED',
|
|
64
|
+
kind: 'avatar',
|
|
65
|
+
lifecycle: 'STARTED',
|
|
66
|
+
evidenceIds: [],
|
|
67
|
+
expression: 'surprised',
|
|
68
|
+
action: 'nod',
|
|
69
|
+
text: 'Affirmative.',
|
|
70
|
+
language: 'en',
|
|
71
|
+
createdAt: new Date().toISOString(),
|
|
72
|
+
});
|
|
73
|
+
expect(res.accepted).toBe(true);
|
|
74
|
+
expect(res.lifecycle).toBe('STARTED');
|
|
75
|
+
expect(res.metadata).toMatchObject({
|
|
76
|
+
expression: 'surprised',
|
|
77
|
+
action: 'nod',
|
|
78
|
+
state: 'acting',
|
|
79
|
+
companionId: 'companion-test',
|
|
80
|
+
correlationId: 'corr-100',
|
|
81
|
+
});
|
|
82
|
+
expect(organ.currentExpression).toBe('surprised');
|
|
83
|
+
expect(organ.lastAction).toBe('nod');
|
|
84
|
+
expect(organ.lastText).toBe('Affirmative.');
|
|
85
|
+
});
|
|
86
|
+
test('handleEvent rejects unapproved events or incompatible kinds', async () => {
|
|
87
|
+
const unapprovedRes = await organ.handleEvent({
|
|
88
|
+
eventId: 'evt-avatar-2',
|
|
89
|
+
companionId: 'companion-test',
|
|
90
|
+
responseId: 'resp-100',
|
|
91
|
+
correlationId: 'corr-100',
|
|
92
|
+
channel: 'public',
|
|
93
|
+
approval: 'STAGED',
|
|
94
|
+
kind: 'avatar',
|
|
95
|
+
lifecycle: 'STARTED',
|
|
96
|
+
evidenceIds: [],
|
|
97
|
+
createdAt: new Date().toISOString(),
|
|
98
|
+
});
|
|
99
|
+
expect(unapprovedRes.accepted).toBe(false);
|
|
100
|
+
expect(unapprovedRes.error).toContain('APPROVED');
|
|
101
|
+
const incompatibleRes = await organ.handleEvent({
|
|
102
|
+
eventId: 'evt-avatar-3',
|
|
103
|
+
companionId: 'companion-test',
|
|
104
|
+
responseId: 'resp-100',
|
|
105
|
+
correlationId: 'corr-100',
|
|
106
|
+
channel: 'public',
|
|
107
|
+
approval: 'APPROVED',
|
|
108
|
+
kind: 'voice',
|
|
109
|
+
lifecycle: 'STARTED',
|
|
110
|
+
evidenceIds: [],
|
|
111
|
+
createdAt: new Date().toISOString(),
|
|
112
|
+
});
|
|
113
|
+
expect(incompatibleRes.accepted).toBe(false);
|
|
114
|
+
expect(incompatibleRes.reason).toBe('INCOMPATIBLE_EVENT_KIND');
|
|
115
|
+
});
|
|
116
|
+
test('handleEvent rejects invalid envelope', async () => {
|
|
117
|
+
const invalidRes = await organ.handleEvent({});
|
|
118
|
+
expect(invalidRes.accepted).toBe(false);
|
|
119
|
+
expect(invalidRes.reason).toBe('INVALID_EVENT_ENVELOPE');
|
|
120
|
+
});
|
|
121
|
+
test('requires no open network sockets or transport listeners', () => {
|
|
122
|
+
// Verifies the object has no transport handles
|
|
123
|
+
expect(organ.wss).toBeUndefined();
|
|
124
|
+
expect(organ.vts).toBeUndefined();
|
|
125
|
+
expect(organ.clients).toBeUndefined();
|
|
126
|
+
});
|
|
127
|
+
test('handles sequential avatar events where latest valid event updates active state', async () => {
|
|
128
|
+
await organ.handleEvent({
|
|
129
|
+
eventId: 'evt-avatar-10',
|
|
130
|
+
companionId: 'companion-test',
|
|
131
|
+
responseId: 'resp-101',
|
|
132
|
+
correlationId: 'corr-101',
|
|
133
|
+
channel: 'public',
|
|
134
|
+
approval: 'APPROVED',
|
|
135
|
+
kind: 'avatar',
|
|
136
|
+
lifecycle: 'STARTED',
|
|
137
|
+
evidenceIds: [],
|
|
138
|
+
expression: 'happy',
|
|
139
|
+
action: 'wave',
|
|
140
|
+
createdAt: new Date().toISOString(),
|
|
141
|
+
});
|
|
142
|
+
expect(organ.currentExpression).toBe('happy');
|
|
143
|
+
expect(organ.lastAction).toBe('wave');
|
|
144
|
+
// Newer event arrives
|
|
145
|
+
await organ.handleEvent({
|
|
146
|
+
eventId: 'evt-avatar-11',
|
|
147
|
+
companionId: 'companion-test',
|
|
148
|
+
responseId: 'resp-102',
|
|
149
|
+
correlationId: 'corr-102',
|
|
150
|
+
channel: 'public',
|
|
151
|
+
approval: 'APPROVED',
|
|
152
|
+
kind: 'avatar',
|
|
153
|
+
lifecycle: 'STARTED',
|
|
154
|
+
evidenceIds: [],
|
|
155
|
+
expression: 'surprised',
|
|
156
|
+
action: 'nod',
|
|
157
|
+
createdAt: new Date().toISOString(),
|
|
158
|
+
});
|
|
159
|
+
expect(organ.currentExpression).toBe('surprised');
|
|
160
|
+
expect(organ.lastAction).toBe('nod');
|
|
161
|
+
});
|
|
162
|
+
test('speech synchronization sets speaking state and reset returns to idle', () => {
|
|
163
|
+
organ.speak('speech_v1', 'Konnichiwa', 'ja');
|
|
164
|
+
expect(organ.state).toBe('speaking');
|
|
165
|
+
expect(organ.lastSpeechId).toBe('speech_v1');
|
|
166
|
+
organ.completeAction();
|
|
167
|
+
expect(organ.state).toBe('idle');
|
|
168
|
+
});
|
|
169
|
+
test('handles unknown expressions and actions with graceful baseline fallbacks', () => {
|
|
170
|
+
organ.setExpression('unknown_custom_expression');
|
|
171
|
+
expect(organ.currentExpression).toBe('unknown_custom_expression');
|
|
172
|
+
organ.act('unknown_action');
|
|
173
|
+
expect(organ.lastAction).toBe('unknown_action');
|
|
174
|
+
expect(organ.state).toBe('acting');
|
|
175
|
+
organ.completeAction();
|
|
176
|
+
expect(organ.state).toBe('idle');
|
|
177
|
+
});
|
|
178
|
+
describe('VRM / 3D Embodiment Support (RFC)', () => {
|
|
179
|
+
test('auto-detects live2d format from .model3.json or .json extensions', () => {
|
|
180
|
+
const live2dOrgan = new index_1.NeutralBodyOrgan({
|
|
181
|
+
modelPath: './assets/body/avatar/model.model3.json',
|
|
182
|
+
});
|
|
183
|
+
expect(live2dOrgan.format).toBe('live2d');
|
|
184
|
+
expect(live2dOrgan.getSnapshot().format).toBe('live2d');
|
|
185
|
+
live2dOrgan.cleanup();
|
|
186
|
+
});
|
|
187
|
+
test('auto-detects vrm format from .vrm extension', () => {
|
|
188
|
+
const vrmOrgan = new index_1.NeutralBodyOrgan({
|
|
189
|
+
modelUrl: 'https://cdn.example.com/avatars/companion.vrm',
|
|
190
|
+
});
|
|
191
|
+
expect(vrmOrgan.format).toBe('vrm');
|
|
192
|
+
expect(vrmOrgan.getSnapshot().format).toBe('vrm');
|
|
193
|
+
vrmOrgan.cleanup();
|
|
194
|
+
});
|
|
195
|
+
test('respects explicit format override and provider setting', () => {
|
|
196
|
+
const explicitVrm = new index_1.NeutralBodyOrgan({
|
|
197
|
+
provider: 'vrm',
|
|
198
|
+
modelUrl: 'https://cdn.example.com/asset-without-extension',
|
|
199
|
+
});
|
|
200
|
+
expect(explicitVrm.format).toBe('vrm');
|
|
201
|
+
expect(explicitVrm.getSnapshot().format).toBe('vrm');
|
|
202
|
+
explicitVrm.cleanup();
|
|
203
|
+
const forcedFormat = new index_1.NeutralBodyOrgan({
|
|
204
|
+
format: 'live2d',
|
|
205
|
+
modelPath: './model.vrm',
|
|
206
|
+
});
|
|
207
|
+
expect(forcedFormat.format).toBe('live2d');
|
|
208
|
+
forcedFormat.cleanup();
|
|
209
|
+
});
|
|
210
|
+
test('VRMAdapter defaults provider and format to vrm and retains vrm options', () => {
|
|
211
|
+
const vrm = new index_1.VRMAdapter({
|
|
212
|
+
modelPath: './assets/avatar.vrm',
|
|
213
|
+
vrm: {
|
|
214
|
+
specVersion: '1.0',
|
|
215
|
+
lookAtMode: 'cursor',
|
|
216
|
+
defaultPose: 'idle_a',
|
|
217
|
+
expressionMapping: { joy: 'happy' },
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
expect(vrm).toBeInstanceOf(index_1.NeutralBodyOrgan);
|
|
221
|
+
expect(vrm.format).toBe('vrm');
|
|
222
|
+
expect(vrm.vrmOptions).toEqual({
|
|
223
|
+
specVersion: '1.0',
|
|
224
|
+
lookAtMode: 'cursor',
|
|
225
|
+
defaultPose: 'idle_a',
|
|
226
|
+
expressionMapping: { joy: 'happy' },
|
|
227
|
+
});
|
|
228
|
+
const snapshot = vrm.getSnapshot();
|
|
229
|
+
expect(snapshot.format).toBe('vrm');
|
|
230
|
+
expect(snapshot.vrmOptions?.lookAtMode).toBe('cursor');
|
|
231
|
+
expect(snapshot.vrmOptions?.specVersion).toBe('1.0');
|
|
232
|
+
vrm.cleanup();
|
|
233
|
+
});
|
|
234
|
+
test('handleEvent includes format in response metadata', async () => {
|
|
235
|
+
const vrm = new index_1.VRMAdapter({
|
|
236
|
+
modelPath: './avatar.vrm',
|
|
237
|
+
});
|
|
238
|
+
const res = await vrm.handleEvent({
|
|
239
|
+
eventId: 'evt-avatar-vrm-1',
|
|
240
|
+
companionId: 'companion-3d',
|
|
241
|
+
responseId: 'resp-200',
|
|
242
|
+
correlationId: 'corr-200',
|
|
243
|
+
channel: 'public',
|
|
244
|
+
approval: 'APPROVED',
|
|
245
|
+
kind: 'avatar',
|
|
246
|
+
lifecycle: 'STARTED',
|
|
247
|
+
evidenceIds: [],
|
|
248
|
+
expression: 'happy',
|
|
249
|
+
createdAt: new Date().toISOString(),
|
|
250
|
+
});
|
|
251
|
+
expect(res.accepted).toBe(true);
|
|
252
|
+
expect(res.metadata?.format).toBe('vrm');
|
|
253
|
+
expect(res.metadata?.expression).toBe('happy');
|
|
254
|
+
vrm.cleanup();
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sidurijs/body",
|
|
3
|
+
"organType": "body",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"displayName": "Body (Live2D & VRM Avatar State)",
|
|
6
|
+
"description": "Renderer-agnostic avatar expression and embodiment event adapter supporting Live2D (.model3.json) and VRM (.vrm)",
|
|
7
|
+
"entrypoint": "./dist/index.js",
|
|
8
|
+
"factory": "NeutralBodyOrgan",
|
|
9
|
+
"configKey": "body",
|
|
10
|
+
"configSchema": {
|
|
11
|
+
"type": "object",
|
|
12
|
+
"required": [
|
|
13
|
+
"provider"
|
|
14
|
+
],
|
|
15
|
+
"properties": {
|
|
16
|
+
"provider": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"enum": [
|
|
19
|
+
"live2d",
|
|
20
|
+
"vrm",
|
|
21
|
+
"none"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
"format": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"enum": [
|
|
27
|
+
"live2d",
|
|
28
|
+
"vrm",
|
|
29
|
+
"auto"
|
|
30
|
+
],
|
|
31
|
+
"default": "auto"
|
|
32
|
+
},
|
|
33
|
+
"initialExpression": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"default": "neutral"
|
|
36
|
+
},
|
|
37
|
+
"modelPath": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"description": "Path to local Live2D Cubism (.model3.json) or VRM (.vrm) model file"
|
|
40
|
+
},
|
|
41
|
+
"modelUrl": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"description": "Relative web or remote HTTP URL to Live2D Cubism (.model3.json) or VRM (.vrm) model file"
|
|
44
|
+
},
|
|
45
|
+
"vrm": {
|
|
46
|
+
"type": "object",
|
|
47
|
+
"properties": {
|
|
48
|
+
"specVersion": {
|
|
49
|
+
"type": "string",
|
|
50
|
+
"enum": [
|
|
51
|
+
"0.x",
|
|
52
|
+
"1.0",
|
|
53
|
+
"auto"
|
|
54
|
+
],
|
|
55
|
+
"default": "auto"
|
|
56
|
+
},
|
|
57
|
+
"lookAtMode": {
|
|
58
|
+
"type": "string",
|
|
59
|
+
"enum": [
|
|
60
|
+
"camera",
|
|
61
|
+
"cursor",
|
|
62
|
+
"head",
|
|
63
|
+
"none"
|
|
64
|
+
],
|
|
65
|
+
"default": "camera"
|
|
66
|
+
},
|
|
67
|
+
"defaultPose": {
|
|
68
|
+
"type": "string"
|
|
69
|
+
},
|
|
70
|
+
"expressionMapping": {
|
|
71
|
+
"type": "object"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"environment": [],
|
|
78
|
+
"services": [],
|
|
79
|
+
"database": null,
|
|
80
|
+
"healthCheck": null
|
|
81
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sidurijs/body",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc",
|
|
8
|
+
"dev": "tsc -w",
|
|
9
|
+
"test": "jest --config jest.config.json"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@sidurijs/core": "workspace:*"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/jest": "^30.0.0",
|
|
16
|
+
"@types/node": "^26.5.1",
|
|
17
|
+
"jest": "^30.5.1",
|
|
18
|
+
"ts-jest": "^29.4.12",
|
|
19
|
+
"typescript": "^5.9.3"
|
|
20
|
+
},
|
|
21
|
+
"description": "Body organ for embodiment, avatar expression state machine, and physical animation",
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/vxnus-studio/siduri-x",
|
|
26
|
+
"directory": "packages/organs/body"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=22.16.0"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"organ-manifest.json",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"import": "./dist/index.js",
|
|
44
|
+
"default": "./dist/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./organ-manifest.json": "./organ-manifest.json"
|
|
47
|
+
}
|
|
48
|
+
}
|