@hmcs/sdk 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/README.md +30 -0
- package/dist/app.cjs +63 -0
- package/dist/app.js +63 -0
- package/dist/assets.cjs +52 -0
- package/dist/assets.js +52 -0
- package/dist/audio.cjs +159 -0
- package/dist/audio.js +159 -0
- package/dist/commands.cjs +298 -0
- package/dist/commands.d.ts +852 -0
- package/dist/commands.js +296 -0
- package/dist/coordinates.cjs +69 -0
- package/dist/coordinates.js +69 -0
- package/dist/displays.cjs +38 -0
- package/dist/displays.js +38 -0
- package/dist/effects.cjs +50 -0
- package/dist/effects.js +50 -0
- package/dist/entities.cjs +249 -0
- package/dist/entities.js +249 -0
- package/dist/host.cjs +297 -0
- package/dist/host.js +294 -0
- package/dist/index.cjs +98 -0
- package/dist/index.d.ts +2612 -0
- package/dist/index.js +17 -0
- package/dist/mods.cjs +207 -0
- package/dist/mods.js +207 -0
- package/dist/preferences.cjs +90 -0
- package/dist/preferences.js +90 -0
- package/dist/settings.cjs +46 -0
- package/dist/settings.js +46 -0
- package/dist/shadowPanel.cjs +46 -0
- package/dist/shadowPanel.js +46 -0
- package/dist/signals.cjs +158 -0
- package/dist/signals.js +158 -0
- package/dist/speech.cjs +48 -0
- package/dist/speech.js +48 -0
- package/dist/utils.cjs +13 -0
- package/dist/utils.js +11 -0
- package/dist/vrm.cjs +469 -0
- package/dist/vrm.js +466 -0
- package/dist/webviews.cjs +310 -0
- package/dist/webviews.js +302 -0
- package/package.json +61 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { coordinates } from './coordinates.js';
|
|
2
|
+
export { displays } from './displays.js';
|
|
3
|
+
export { audio } from './audio.js';
|
|
4
|
+
export { effects } from './effects.js';
|
|
5
|
+
export { HomunculusApiError, HomunculusStreamError, host } from './host.js';
|
|
6
|
+
export { preferences } from './preferences.js';
|
|
7
|
+
export { settings } from './settings.js';
|
|
8
|
+
export { shadowPanel } from './shadowPanel.js';
|
|
9
|
+
export { Vrm, VrmEventSource, repeat } from './vrm.js';
|
|
10
|
+
export { speech } from './speech.js';
|
|
11
|
+
export { Webview, isWebviewSourceHtml, isWebviewSourceInfoHtml, isWebviewSourceInfoLocal, isWebviewSourceInfoUrl, isWebviewSourceLocal, isWebviewSourceUrl, webviewSource } from './webviews.js';
|
|
12
|
+
export { signals } from './signals.js';
|
|
13
|
+
export { entities } from './entities.js';
|
|
14
|
+
export { app } from './app.js';
|
|
15
|
+
export { mods } from './mods.js';
|
|
16
|
+
export { assets } from './assets.js';
|
|
17
|
+
export { sleep } from './utils.js';
|
package/dist/mods.cjs
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var host = require('./host.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Mod management namespace for executing commands defined in mod packages.
|
|
7
|
+
*
|
|
8
|
+
* Provides functions to run on-demand scripts from installed mods,
|
|
9
|
+
* with support for passing arguments, stdin data, configuring timeouts,
|
|
10
|
+
* and real-time NDJSON streaming of command output.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Execute a command and collect the result
|
|
15
|
+
* const result = await mods.executeCommand({ command: "greet" });
|
|
16
|
+
* console.log(result.stdout);
|
|
17
|
+
*
|
|
18
|
+
* // Stream command output in real-time
|
|
19
|
+
* for await (const event of mods.streamCommand({ command: "build" })) {
|
|
20
|
+
* if (event.type === "stdout") console.log(event.data);
|
|
21
|
+
* if (event.type === "stderr") console.error(event.data);
|
|
22
|
+
* if (event.type === "exit") console.log("Exit code:", event.exitCode);
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
exports.mods = void 0;
|
|
27
|
+
(function (mods) {
|
|
28
|
+
/**
|
|
29
|
+
* List all loaded mods and their metadata.
|
|
30
|
+
*
|
|
31
|
+
* Returns summary information for every mod discovered at startup,
|
|
32
|
+
* including available bin commands and registered asset IDs.
|
|
33
|
+
*
|
|
34
|
+
* @returns Array of mod information objects
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // List all installed mods
|
|
39
|
+
* const allMods = await mods.list();
|
|
40
|
+
* console.log(`${allMods.length} mods installed`);
|
|
41
|
+
*
|
|
42
|
+
* // Find mods with bin commands
|
|
43
|
+
* const withCommands = allMods.filter(m => m.commands.length > 0);
|
|
44
|
+
*
|
|
45
|
+
* // Get assets from a specific mod
|
|
46
|
+
* const elmer = allMods.find(m => m.name === "elmer");
|
|
47
|
+
* if (elmer) {
|
|
48
|
+
* console.log("Elmer assets:", Object.keys(elmer.assets));
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
async function list() {
|
|
53
|
+
const response = await host.host.get(host.host.createUrl("mods"));
|
|
54
|
+
return await response.json();
|
|
55
|
+
}
|
|
56
|
+
mods.list = list;
|
|
57
|
+
/**
|
|
58
|
+
* Get detailed information about a specific mod by name.
|
|
59
|
+
*
|
|
60
|
+
* @param modName - The mod package name
|
|
61
|
+
* @returns Mod information
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const elmer = await mods.get("elmer");
|
|
66
|
+
* console.log(`${elmer.name}@${elmer.version}`);
|
|
67
|
+
* console.log("Commands:", elmer.commands);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
async function get(modName) {
|
|
71
|
+
const response = await host.host.get(host.host.createUrl(`mods/${modName}`));
|
|
72
|
+
return await response.json();
|
|
73
|
+
}
|
|
74
|
+
mods.get = get;
|
|
75
|
+
function toRequestBody(request) {
|
|
76
|
+
return {
|
|
77
|
+
command: request.command,
|
|
78
|
+
args: request.args,
|
|
79
|
+
stdin: request.stdin,
|
|
80
|
+
timeoutMs: request.timeoutMs,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function toCommandEvent(raw) {
|
|
84
|
+
switch (raw.type) {
|
|
85
|
+
case "stdout":
|
|
86
|
+
return { type: "stdout", data: raw.data ?? "" };
|
|
87
|
+
case "stderr":
|
|
88
|
+
return { type: "stderr", data: raw.data ?? "" };
|
|
89
|
+
case "exit":
|
|
90
|
+
return {
|
|
91
|
+
type: "exit",
|
|
92
|
+
exitCode: raw.code ?? null,
|
|
93
|
+
timedOut: raw.timedOut ?? false,
|
|
94
|
+
signal: raw.signal,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Execute a mod command with real-time NDJSON streaming output.
|
|
100
|
+
*
|
|
101
|
+
* Returns an async generator that yields {@link CommandEvent} objects
|
|
102
|
+
* as the command produces output. The last event is always an `exit` event.
|
|
103
|
+
*
|
|
104
|
+
* @param request - Command execution parameters
|
|
105
|
+
* @param signal - Optional AbortSignal for cancellation
|
|
106
|
+
* @returns An async generator yielding command events
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* // Stream output from a long-running build
|
|
111
|
+
* for await (const event of mods.streamCommand({ command: "build" })) {
|
|
112
|
+
* switch (event.type) {
|
|
113
|
+
* case "stdout": console.log(event.data); break;
|
|
114
|
+
* case "stderr": console.error(event.data); break;
|
|
115
|
+
* case "exit": console.log("Done, exit code:", event.exitCode); break;
|
|
116
|
+
* }
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
async function* streamCommand(request, signal) {
|
|
121
|
+
const stream = host.host.postStream(host.host.createUrl("commands/execute"), toRequestBody(request), signal);
|
|
122
|
+
for await (const raw of stream) {
|
|
123
|
+
yield toCommandEvent(raw);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
mods.streamCommand = streamCommand;
|
|
127
|
+
/**
|
|
128
|
+
* Execute a mod command and collect the full result.
|
|
129
|
+
*
|
|
130
|
+
* This is a convenience wrapper around {@link streamCommand} that buffers
|
|
131
|
+
* all output and returns a single {@link CommandResult}.
|
|
132
|
+
*
|
|
133
|
+
* @param request - Command execution parameters
|
|
134
|
+
* @param signal - Optional AbortSignal for cancellation
|
|
135
|
+
* @returns The collected command result with exit code, stdout, and stderr
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* // Simple execution
|
|
140
|
+
* const result = await mods.executeCommand({ command: "build" });
|
|
141
|
+
*
|
|
142
|
+
* // With arguments
|
|
143
|
+
* const result = await mods.executeCommand({
|
|
144
|
+
* command: "compile",
|
|
145
|
+
* args: ["--target", "es2020"],
|
|
146
|
+
* });
|
|
147
|
+
*
|
|
148
|
+
* // With stdin data and custom timeout
|
|
149
|
+
* const result = await mods.executeCommand({
|
|
150
|
+
* command: "transform",
|
|
151
|
+
* stdin: JSON.stringify({ input: "data" }),
|
|
152
|
+
* timeoutMs: 60000,
|
|
153
|
+
* });
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
async function executeCommand(request, signal) {
|
|
157
|
+
const stdoutLines = [];
|
|
158
|
+
const stderrLines = [];
|
|
159
|
+
let exitCode = null;
|
|
160
|
+
let timedOut = false;
|
|
161
|
+
let exitSignal;
|
|
162
|
+
for await (const event of streamCommand(request, signal)) {
|
|
163
|
+
switch (event.type) {
|
|
164
|
+
case "stdout":
|
|
165
|
+
stdoutLines.push(event.data);
|
|
166
|
+
break;
|
|
167
|
+
case "stderr":
|
|
168
|
+
stderrLines.push(event.data);
|
|
169
|
+
break;
|
|
170
|
+
case "exit":
|
|
171
|
+
exitCode = event.exitCode;
|
|
172
|
+
timedOut = event.timedOut;
|
|
173
|
+
exitSignal = event.signal;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
exitCode,
|
|
179
|
+
timedOut,
|
|
180
|
+
signal: exitSignal,
|
|
181
|
+
stdout: stdoutLines.join("\n"),
|
|
182
|
+
stderr: stderrLines.join("\n"),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
mods.executeCommand = executeCommand;
|
|
186
|
+
/**
|
|
187
|
+
* Returns all registered mod menu items.
|
|
188
|
+
*
|
|
189
|
+
* Menu items are declared in each mod's `package.json` under the
|
|
190
|
+
* `homunculus.menus` field and collected at startup.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* import { mods } from "@hmcs/sdk";
|
|
195
|
+
*
|
|
196
|
+
* const menuItems = await mods.menus();
|
|
197
|
+
* for (const item of menuItems) {
|
|
198
|
+
* console.log(`${item.modName}: ${item.text}`);
|
|
199
|
+
* }
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
async function menus() {
|
|
203
|
+
const response = await host.host.get(host.host.createUrl("mods/menus"));
|
|
204
|
+
return await response.json();
|
|
205
|
+
}
|
|
206
|
+
mods.menus = menus;
|
|
207
|
+
})(exports.mods || (exports.mods = {}));
|
package/dist/mods.js
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { host } from './host.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Mod management namespace for executing commands defined in mod packages.
|
|
5
|
+
*
|
|
6
|
+
* Provides functions to run on-demand scripts from installed mods,
|
|
7
|
+
* with support for passing arguments, stdin data, configuring timeouts,
|
|
8
|
+
* and real-time NDJSON streaming of command output.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Execute a command and collect the result
|
|
13
|
+
* const result = await mods.executeCommand({ command: "greet" });
|
|
14
|
+
* console.log(result.stdout);
|
|
15
|
+
*
|
|
16
|
+
* // Stream command output in real-time
|
|
17
|
+
* for await (const event of mods.streamCommand({ command: "build" })) {
|
|
18
|
+
* if (event.type === "stdout") console.log(event.data);
|
|
19
|
+
* if (event.type === "stderr") console.error(event.data);
|
|
20
|
+
* if (event.type === "exit") console.log("Exit code:", event.exitCode);
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
var mods;
|
|
25
|
+
(function (mods) {
|
|
26
|
+
/**
|
|
27
|
+
* List all loaded mods and their metadata.
|
|
28
|
+
*
|
|
29
|
+
* Returns summary information for every mod discovered at startup,
|
|
30
|
+
* including available bin commands and registered asset IDs.
|
|
31
|
+
*
|
|
32
|
+
* @returns Array of mod information objects
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* // List all installed mods
|
|
37
|
+
* const allMods = await mods.list();
|
|
38
|
+
* console.log(`${allMods.length} mods installed`);
|
|
39
|
+
*
|
|
40
|
+
* // Find mods with bin commands
|
|
41
|
+
* const withCommands = allMods.filter(m => m.commands.length > 0);
|
|
42
|
+
*
|
|
43
|
+
* // Get assets from a specific mod
|
|
44
|
+
* const elmer = allMods.find(m => m.name === "elmer");
|
|
45
|
+
* if (elmer) {
|
|
46
|
+
* console.log("Elmer assets:", Object.keys(elmer.assets));
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
async function list() {
|
|
51
|
+
const response = await host.get(host.createUrl("mods"));
|
|
52
|
+
return await response.json();
|
|
53
|
+
}
|
|
54
|
+
mods.list = list;
|
|
55
|
+
/**
|
|
56
|
+
* Get detailed information about a specific mod by name.
|
|
57
|
+
*
|
|
58
|
+
* @param modName - The mod package name
|
|
59
|
+
* @returns Mod information
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const elmer = await mods.get("elmer");
|
|
64
|
+
* console.log(`${elmer.name}@${elmer.version}`);
|
|
65
|
+
* console.log("Commands:", elmer.commands);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
async function get(modName) {
|
|
69
|
+
const response = await host.get(host.createUrl(`mods/${modName}`));
|
|
70
|
+
return await response.json();
|
|
71
|
+
}
|
|
72
|
+
mods.get = get;
|
|
73
|
+
function toRequestBody(request) {
|
|
74
|
+
return {
|
|
75
|
+
command: request.command,
|
|
76
|
+
args: request.args,
|
|
77
|
+
stdin: request.stdin,
|
|
78
|
+
timeoutMs: request.timeoutMs,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function toCommandEvent(raw) {
|
|
82
|
+
switch (raw.type) {
|
|
83
|
+
case "stdout":
|
|
84
|
+
return { type: "stdout", data: raw.data ?? "" };
|
|
85
|
+
case "stderr":
|
|
86
|
+
return { type: "stderr", data: raw.data ?? "" };
|
|
87
|
+
case "exit":
|
|
88
|
+
return {
|
|
89
|
+
type: "exit",
|
|
90
|
+
exitCode: raw.code ?? null,
|
|
91
|
+
timedOut: raw.timedOut ?? false,
|
|
92
|
+
signal: raw.signal,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Execute a mod command with real-time NDJSON streaming output.
|
|
98
|
+
*
|
|
99
|
+
* Returns an async generator that yields {@link CommandEvent} objects
|
|
100
|
+
* as the command produces output. The last event is always an `exit` event.
|
|
101
|
+
*
|
|
102
|
+
* @param request - Command execution parameters
|
|
103
|
+
* @param signal - Optional AbortSignal for cancellation
|
|
104
|
+
* @returns An async generator yielding command events
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* // Stream output from a long-running build
|
|
109
|
+
* for await (const event of mods.streamCommand({ command: "build" })) {
|
|
110
|
+
* switch (event.type) {
|
|
111
|
+
* case "stdout": console.log(event.data); break;
|
|
112
|
+
* case "stderr": console.error(event.data); break;
|
|
113
|
+
* case "exit": console.log("Done, exit code:", event.exitCode); break;
|
|
114
|
+
* }
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
async function* streamCommand(request, signal) {
|
|
119
|
+
const stream = host.postStream(host.createUrl("commands/execute"), toRequestBody(request), signal);
|
|
120
|
+
for await (const raw of stream) {
|
|
121
|
+
yield toCommandEvent(raw);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
mods.streamCommand = streamCommand;
|
|
125
|
+
/**
|
|
126
|
+
* Execute a mod command and collect the full result.
|
|
127
|
+
*
|
|
128
|
+
* This is a convenience wrapper around {@link streamCommand} that buffers
|
|
129
|
+
* all output and returns a single {@link CommandResult}.
|
|
130
|
+
*
|
|
131
|
+
* @param request - Command execution parameters
|
|
132
|
+
* @param signal - Optional AbortSignal for cancellation
|
|
133
|
+
* @returns The collected command result with exit code, stdout, and stderr
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* // Simple execution
|
|
138
|
+
* const result = await mods.executeCommand({ command: "build" });
|
|
139
|
+
*
|
|
140
|
+
* // With arguments
|
|
141
|
+
* const result = await mods.executeCommand({
|
|
142
|
+
* command: "compile",
|
|
143
|
+
* args: ["--target", "es2020"],
|
|
144
|
+
* });
|
|
145
|
+
*
|
|
146
|
+
* // With stdin data and custom timeout
|
|
147
|
+
* const result = await mods.executeCommand({
|
|
148
|
+
* command: "transform",
|
|
149
|
+
* stdin: JSON.stringify({ input: "data" }),
|
|
150
|
+
* timeoutMs: 60000,
|
|
151
|
+
* });
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
async function executeCommand(request, signal) {
|
|
155
|
+
const stdoutLines = [];
|
|
156
|
+
const stderrLines = [];
|
|
157
|
+
let exitCode = null;
|
|
158
|
+
let timedOut = false;
|
|
159
|
+
let exitSignal;
|
|
160
|
+
for await (const event of streamCommand(request, signal)) {
|
|
161
|
+
switch (event.type) {
|
|
162
|
+
case "stdout":
|
|
163
|
+
stdoutLines.push(event.data);
|
|
164
|
+
break;
|
|
165
|
+
case "stderr":
|
|
166
|
+
stderrLines.push(event.data);
|
|
167
|
+
break;
|
|
168
|
+
case "exit":
|
|
169
|
+
exitCode = event.exitCode;
|
|
170
|
+
timedOut = event.timedOut;
|
|
171
|
+
exitSignal = event.signal;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
exitCode,
|
|
177
|
+
timedOut,
|
|
178
|
+
signal: exitSignal,
|
|
179
|
+
stdout: stdoutLines.join("\n"),
|
|
180
|
+
stderr: stderrLines.join("\n"),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
mods.executeCommand = executeCommand;
|
|
184
|
+
/**
|
|
185
|
+
* Returns all registered mod menu items.
|
|
186
|
+
*
|
|
187
|
+
* Menu items are declared in each mod's `package.json` under the
|
|
188
|
+
* `homunculus.menus` field and collected at startup.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* import { mods } from "@hmcs/sdk";
|
|
193
|
+
*
|
|
194
|
+
* const menuItems = await mods.menus();
|
|
195
|
+
* for (const item of menuItems) {
|
|
196
|
+
* console.log(`${item.modName}: ${item.text}`);
|
|
197
|
+
* }
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
async function menus() {
|
|
201
|
+
const response = await host.get(host.createUrl("mods/menus"));
|
|
202
|
+
return await response.json();
|
|
203
|
+
}
|
|
204
|
+
mods.menus = menus;
|
|
205
|
+
})(mods || (mods = {}));
|
|
206
|
+
|
|
207
|
+
export { mods };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var host = require('./host.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Preferences API namespace for persistent data storage and user settings.
|
|
7
|
+
*
|
|
8
|
+
* Provides a key-value store for saving and loading application data that persists
|
|
9
|
+
* across sessions.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* await preferences.save('user-settings', { theme: 'dark', volume: 0.8 });
|
|
14
|
+
* const settings = await preferences.load<{ theme: string; volume: number }>('user-settings');
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
exports.preferences = void 0;
|
|
18
|
+
(function (preferences) {
|
|
19
|
+
/**
|
|
20
|
+
* List all saved preference keys.
|
|
21
|
+
*
|
|
22
|
+
* Returns an array of key names that have been stored.
|
|
23
|
+
* Use {@link preferences.load} to retrieve the value for a specific key.
|
|
24
|
+
*
|
|
25
|
+
* @returns Array of preference key names
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const keys = await preferences.list();
|
|
30
|
+
* console.log(`${keys.length} preferences stored`);
|
|
31
|
+
*
|
|
32
|
+
* // Load all preferences
|
|
33
|
+
* for (const key of keys) {
|
|
34
|
+
* const value = await preferences.load(key);
|
|
35
|
+
* console.log(`${key}:`, value);
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
async function list() {
|
|
40
|
+
const response = await host.host.get(host.host.createUrl("preferences"));
|
|
41
|
+
return await response.json();
|
|
42
|
+
}
|
|
43
|
+
preferences.list = list;
|
|
44
|
+
/**
|
|
45
|
+
* Loads a value from the preference store with type safety.
|
|
46
|
+
*
|
|
47
|
+
* Returns `undefined` if the key does not exist.
|
|
48
|
+
*
|
|
49
|
+
* @template V - The expected type of the stored value
|
|
50
|
+
* @param key - The unique identifier for the stored data
|
|
51
|
+
* @returns A promise that resolves to the deserialized value, or `undefined` if the key does not exist
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const username = await preferences.load<string>('username');
|
|
56
|
+
* if (username !== null) {
|
|
57
|
+
* console.log(`Hello, ${username}`);
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
async function load(key) {
|
|
62
|
+
try {
|
|
63
|
+
const response = await host.host.get(host.host.createUrl(`preferences/${key}`));
|
|
64
|
+
return await response.json();
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
if (e instanceof host.HomunculusApiError && e.statusCode === 404) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
throw e;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
preferences.load = load;
|
|
74
|
+
/**
|
|
75
|
+
* Saves a value to the preference store with automatic serialization.
|
|
76
|
+
*
|
|
77
|
+
* @template V - The type of the value being saved
|
|
78
|
+
* @param key - The unique identifier for storing the data
|
|
79
|
+
* @param value - The data to save (must be JSON-serializable)
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* await preferences.save('username', 'Alice');
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
async function save(key, value) {
|
|
87
|
+
await host.host.put(host.host.createUrl(`preferences/${key}`), value);
|
|
88
|
+
}
|
|
89
|
+
preferences.save = save;
|
|
90
|
+
})(exports.preferences || (exports.preferences = {}));
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { host, HomunculusApiError } from './host.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Preferences API namespace for persistent data storage and user settings.
|
|
5
|
+
*
|
|
6
|
+
* Provides a key-value store for saving and loading application data that persists
|
|
7
|
+
* across sessions.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* await preferences.save('user-settings', { theme: 'dark', volume: 0.8 });
|
|
12
|
+
* const settings = await preferences.load<{ theme: string; volume: number }>('user-settings');
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
var preferences;
|
|
16
|
+
(function (preferences) {
|
|
17
|
+
/**
|
|
18
|
+
* List all saved preference keys.
|
|
19
|
+
*
|
|
20
|
+
* Returns an array of key names that have been stored.
|
|
21
|
+
* Use {@link preferences.load} to retrieve the value for a specific key.
|
|
22
|
+
*
|
|
23
|
+
* @returns Array of preference key names
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const keys = await preferences.list();
|
|
28
|
+
* console.log(`${keys.length} preferences stored`);
|
|
29
|
+
*
|
|
30
|
+
* // Load all preferences
|
|
31
|
+
* for (const key of keys) {
|
|
32
|
+
* const value = await preferences.load(key);
|
|
33
|
+
* console.log(`${key}:`, value);
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
async function list() {
|
|
38
|
+
const response = await host.get(host.createUrl("preferences"));
|
|
39
|
+
return await response.json();
|
|
40
|
+
}
|
|
41
|
+
preferences.list = list;
|
|
42
|
+
/**
|
|
43
|
+
* Loads a value from the preference store with type safety.
|
|
44
|
+
*
|
|
45
|
+
* Returns `undefined` if the key does not exist.
|
|
46
|
+
*
|
|
47
|
+
* @template V - The expected type of the stored value
|
|
48
|
+
* @param key - The unique identifier for the stored data
|
|
49
|
+
* @returns A promise that resolves to the deserialized value, or `undefined` if the key does not exist
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const username = await preferences.load<string>('username');
|
|
54
|
+
* if (username !== null) {
|
|
55
|
+
* console.log(`Hello, ${username}`);
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
async function load(key) {
|
|
60
|
+
try {
|
|
61
|
+
const response = await host.get(host.createUrl(`preferences/${key}`));
|
|
62
|
+
return await response.json();
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
if (e instanceof HomunculusApiError && e.statusCode === 404) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
throw e;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
preferences.load = load;
|
|
72
|
+
/**
|
|
73
|
+
* Saves a value to the preference store with automatic serialization.
|
|
74
|
+
*
|
|
75
|
+
* @template V - The type of the value being saved
|
|
76
|
+
* @param key - The unique identifier for storing the data
|
|
77
|
+
* @param value - The data to save (must be JSON-serializable)
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* await preferences.save('username', 'Alice');
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
async function save(key, value) {
|
|
85
|
+
await host.put(host.createUrl(`preferences/${key}`), value);
|
|
86
|
+
}
|
|
87
|
+
preferences.save = save;
|
|
88
|
+
})(preferences || (preferences = {}));
|
|
89
|
+
|
|
90
|
+
export { preferences };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var host = require('./host.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Settings API namespace for controlling application-level configuration.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const currentFps = await settings.fps();
|
|
11
|
+
* await settings.setFps(30);
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
exports.settings = void 0;
|
|
15
|
+
(function (settings) {
|
|
16
|
+
/**
|
|
17
|
+
* Gets the current frame rate (FPS).
|
|
18
|
+
*
|
|
19
|
+
* @returns A promise that resolves to the current FPS value
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const fps = await settings.fps();
|
|
24
|
+
* console.log(`Current FPS: ${fps}`);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
async function fps() {
|
|
28
|
+
const response = await host.host.get(host.host.createUrl("settings/fps"));
|
|
29
|
+
return Number(await response.json());
|
|
30
|
+
}
|
|
31
|
+
settings.fps = fps;
|
|
32
|
+
/**
|
|
33
|
+
* Sets the frame rate (FPS). Persists and applies immediately.
|
|
34
|
+
*
|
|
35
|
+
* @param fps - The target frame rate in frames per second (1-120)
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* await settings.setFps(30);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
async function setFps(fps) {
|
|
43
|
+
await host.host.put(host.host.createUrl("settings/fps"), { fps });
|
|
44
|
+
}
|
|
45
|
+
settings.setFps = setFps;
|
|
46
|
+
})(exports.settings || (exports.settings = {}));
|
package/dist/settings.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { host } from './host.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Settings API namespace for controlling application-level configuration.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const currentFps = await settings.fps();
|
|
9
|
+
* await settings.setFps(30);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
var settings;
|
|
13
|
+
(function (settings) {
|
|
14
|
+
/**
|
|
15
|
+
* Gets the current frame rate (FPS).
|
|
16
|
+
*
|
|
17
|
+
* @returns A promise that resolves to the current FPS value
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const fps = await settings.fps();
|
|
22
|
+
* console.log(`Current FPS: ${fps}`);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
async function fps() {
|
|
26
|
+
const response = await host.get(host.createUrl("settings/fps"));
|
|
27
|
+
return Number(await response.json());
|
|
28
|
+
}
|
|
29
|
+
settings.fps = fps;
|
|
30
|
+
/**
|
|
31
|
+
* Sets the frame rate (FPS). Persists and applies immediately.
|
|
32
|
+
*
|
|
33
|
+
* @param fps - The target frame rate in frames per second (1-120)
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* await settings.setFps(30);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
async function setFps(fps) {
|
|
41
|
+
await host.put(host.createUrl("settings/fps"), { fps });
|
|
42
|
+
}
|
|
43
|
+
settings.setFps = setFps;
|
|
44
|
+
})(settings || (settings = {}));
|
|
45
|
+
|
|
46
|
+
export { settings };
|